From e81605fb9d603bc70e44bb5e4eb0243745ec906a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 29 Dec 2020 13:05:55 -0800 Subject: [PATCH] ts: middlewares, emails, commands --- ...orter.test.js => documentImporter.test.ts} | 1 - ...ocumentImporter.js => documentImporter.ts} | 26 ++++++++++------- ...entMover.test.js => documentMover.test.ts} | 0 .../{documentMover.js => documentMover.ts} | 5 ++-- ...serInviter.test.js => userInviter.test.ts} | 0 .../{userInviter.js => userInviter.ts} | 29 ++++++++++++------- ...uspender.test.js => userSuspender.test.ts} | 0 .../{userSuspender.js => userSuspender.ts} | 21 +++++++------- ...ail.js => CollectionNotificationEmail.tsx} | 7 ++--- ...Email.js => DocumentNotificationEmail.tsx} | 7 ++--- .../{ExportEmail.js => ExportEmail.tsx} | 1 - .../{InviteEmail.js => InviteEmail.tsx} | 7 ++--- .../{SigninEmail.js => SigninEmail.tsx} | 13 ++++++--- .../{WelcomeEmail.js => WelcomeEmail.tsx} | 11 ++++--- .../emails/components/{Body.js => Body.tsx} | 7 +++-- .../components/{Button.js => Button.tsx} | 6 ++-- .../{EmailLayout.js => EmailLayout.tsx} | 3 +- .../{EmptySpace.js => EmptySpace.tsx} | 7 +++-- .../components/{Footer.js => Footer.tsx} | 7 +++-- .../components/{Header.js => Header.tsx} | 1 - .../components/{Heading.js => Heading.tsx} | 7 +++-- server/emails/{index.js => index.ts} | 1 - .../{apexRedirect.js => apexRedirect.ts} | 5 ++-- ...ication.test.js => authentication.test.ts} | 0 .../{authentication.js => authentication.ts} | 9 +++--- .../{errorHandling.js => errorHandling.ts} | 5 ++-- .../{methodOverride.js => methodOverride.ts} | 5 ++-- .../{validation.js => validation.ts} | 5 ++-- 28 files changed, 106 insertions(+), 90 deletions(-) rename server/commands/{documentImporter.test.js => documentImporter.test.ts} (99%) rename server/commands/{documentImporter.js => documentImporter.ts} (95%) rename server/commands/{documentMover.test.js => documentMover.test.ts} (100%) rename server/commands/{documentMover.js => documentMover.ts} (99%) rename server/commands/{userInviter.test.js => userInviter.test.ts} (100%) rename server/commands/{userInviter.js => userInviter.ts} (87%) rename server/commands/{userSuspender.test.js => userSuspender.test.ts} (100%) rename server/commands/{userSuspender.js => userSuspender.ts} (83%) rename server/emails/{CollectionNotificationEmail.js => CollectionNotificationEmail.tsx} (94%) rename server/emails/{DocumentNotificationEmail.js => DocumentNotificationEmail.tsx} (95%) rename server/emails/{ExportEmail.js => ExportEmail.tsx} (99%) rename server/emails/{InviteEmail.js => InviteEmail.tsx} (96%) rename server/emails/{SigninEmail.js => SigninEmail.tsx} (88%) rename server/emails/{WelcomeEmail.js => WelcomeEmail.tsx} (91%) rename server/emails/components/{Body.js => Body.tsx} (83%) rename server/emails/components/{Button.js => Button.tsx} (85%) rename server/emails/components/{EmailLayout.js => EmailLayout.tsx} (93%) rename server/emails/components/{EmptySpace.js => EmptySpace.tsx} (88%) rename server/emails/components/{Footer.js => Footer.tsx} (93%) rename server/emails/components/{Header.js => Header.tsx} (98%) rename server/emails/components/{Heading.js => Heading.tsx} (69%) rename server/emails/{index.js => index.ts} (99%) rename server/middlewares/{apexRedirect.js => apexRedirect.ts} (79%) rename server/middlewares/{authentication.test.js => authentication.test.ts} (100%) rename server/middlewares/{authentication.js => authentication.ts} (96%) rename server/middlewares/{errorHandling.js => errorHandling.ts} (94%) rename server/middlewares/{methodOverride.js => methodOverride.ts} (85%) rename server/middlewares/{validation.js => validation.ts} (91%) diff --git a/server/commands/documentImporter.test.js b/server/commands/documentImporter.test.ts similarity index 99% rename from server/commands/documentImporter.test.js rename to server/commands/documentImporter.test.ts index efd918219d..277c872563 100644 --- a/server/commands/documentImporter.test.js +++ b/server/commands/documentImporter.test.ts @@ -1,4 +1,3 @@ -// @flow import path from "path"; import File from "formidable/lib/file"; import { Attachment } from "../models"; diff --git a/server/commands/documentImporter.js b/server/commands/documentImporter.ts similarity index 95% rename from server/commands/documentImporter.js rename to server/commands/documentImporter.ts index a38dee6c83..956e434657 100644 --- a/server/commands/documentImporter.js +++ b/server/commands/documentImporter.ts @@ -1,4 +1,3 @@ -// @flow import fs from "fs"; import path from "path"; import File from "formidable/lib/file"; @@ -36,7 +35,7 @@ turndownService interface ImportableFile { type: string; - getMarkdown: (file: any) => Promise; + getMarkdown: ((file: any) => Promise); } const importMapping: ImportableFile[] = [ @@ -131,15 +130,20 @@ async function confluenceToMarkdown(file): Promise { return html.replace(/
/g, " \\n "); } -export default async function documentImporter({ - file, - user, - ip, -}: { - user: User, - file: File, - ip: string, -}): Promise<{ text: string, title: string }> { +export default async function documentImporter( + { + file, + user, + ip + }: { + user: User, + file: File, + ip: string + } +): Promise<{ + text: string, + title: string +}> { const fileInfo = importMapping.filter((item) => { if (item.type === file.type) { return true; diff --git a/server/commands/documentMover.test.js b/server/commands/documentMover.test.ts similarity index 100% rename from server/commands/documentMover.test.js rename to server/commands/documentMover.test.ts diff --git a/server/commands/documentMover.js b/server/commands/documentMover.ts similarity index 99% rename from server/commands/documentMover.js rename to server/commands/documentMover.ts index 2fa57012a8..7f07b27220 100644 --- a/server/commands/documentMover.js +++ b/server/commands/documentMover.ts @@ -1,4 +1,3 @@ -// @flow import { Document, Collection, User, Event } from "../models"; import { sequelize } from "../sequelize"; @@ -8,14 +7,14 @@ export default async function documentMover({ collectionId, parentDocumentId, index, - ip, + ip }: { user: User, document: Document, collectionId: string, parentDocumentId?: string, index?: number, - ip: string, + ip: string }) { let transaction; const result = { collections: [], documents: [] }; diff --git a/server/commands/userInviter.test.js b/server/commands/userInviter.test.ts similarity index 100% rename from server/commands/userInviter.test.js rename to server/commands/userInviter.test.ts diff --git a/server/commands/userInviter.js b/server/commands/userInviter.ts similarity index 87% rename from server/commands/userInviter.js rename to server/commands/userInviter.ts index 69ef57030e..96a743aa05 100644 --- a/server/commands/userInviter.js +++ b/server/commands/userInviter.ts @@ -1,19 +1,26 @@ -// @flow import { uniqBy } from "lodash"; import mailer from "../mailer"; import { User, Event, Team } from "../models"; -type Invite = { name: string, email: string }; +type Invite = { + name: string, + email: string +}; -export default async function userInviter({ - user, - invites, - ip, -}: { - user: User, - invites: Invite[], - ip: string, -}): Promise<{ sent: Invite[], users: User[] }> { +export default async function userInviter( + { + user, + invites, + ip + }: { + user: User, + invites: Invite[], + ip: string + } +): Promise<{ + sent: Invite[], + users: User[] +}> { const team = await Team.findByPk(user.teamId); // filter out empties and obvious non-emails diff --git a/server/commands/userSuspender.test.js b/server/commands/userSuspender.test.ts similarity index 100% rename from server/commands/userSuspender.test.js rename to server/commands/userSuspender.test.ts diff --git a/server/commands/userSuspender.js b/server/commands/userSuspender.ts similarity index 83% rename from server/commands/userSuspender.js rename to server/commands/userSuspender.ts index a86b180778..a091915596 100644 --- a/server/commands/userSuspender.js +++ b/server/commands/userSuspender.ts @@ -1,18 +1,19 @@ -// @flow import { Transaction } from "sequelize"; import { ValidationError } from "../errors"; import { User, Event, GroupUser } from "../models"; import { sequelize } from "../sequelize"; -export default async function userSuspender({ - user, - actorId, - ip, -}: { - user: User, - actorId: string, - ip: string, -}): Promise { +export default async function userSuspender( + { + user, + actorId, + ip + }: { + user: User, + actorId: string, + ip: string + } +): Promise { if (user.id === actorId) { throw new ValidationError("Unable to suspend the current user"); } diff --git a/server/emails/CollectionNotificationEmail.js b/server/emails/CollectionNotificationEmail.tsx similarity index 94% rename from server/emails/CollectionNotificationEmail.js rename to server/emails/CollectionNotificationEmail.tsx index 3989469f83..d29d2a9ff5 100644 --- a/server/emails/CollectionNotificationEmail.js +++ b/server/emails/CollectionNotificationEmail.tsx @@ -1,4 +1,3 @@ -// @flow import * as React from "react"; import { User, Collection } from "../models"; import Body from "./components/Body"; @@ -13,13 +12,13 @@ export type Props = { actor: User, collection: Collection, eventName: string, - unsubscribeUrl: string, + unsubscribeUrl: string }; export const collectionNotificationEmailText = ({ actor, collection, - eventName = "created", + eventName = "created" }: Props) => ` ${collection.name} @@ -32,7 +31,7 @@ export const CollectionNotificationEmail = ({ actor, collection, eventName = "created", - unsubscribeUrl, + unsubscribeUrl }: Props) => { return ( diff --git a/server/emails/DocumentNotificationEmail.js b/server/emails/DocumentNotificationEmail.tsx similarity index 95% rename from server/emails/DocumentNotificationEmail.js rename to server/emails/DocumentNotificationEmail.tsx index 00fdfa23c7..c683e2e07a 100644 --- a/server/emails/DocumentNotificationEmail.js +++ b/server/emails/DocumentNotificationEmail.tsx @@ -1,4 +1,3 @@ -// @flow import * as React from "react"; import { User, Document, Team, Collection } from "../models"; import Body from "./components/Body"; @@ -15,7 +14,7 @@ export type Props = { document: Document, collection: Collection, eventName: string, - unsubscribeUrl: string, + unsubscribeUrl: string }; export const documentNotificationEmailText = ({ @@ -23,7 +22,7 @@ export const documentNotificationEmailText = ({ team, document, collection, - eventName = "published", + eventName = "published" }: Props) => ` "${document.title}" ${eventName} @@ -38,7 +37,7 @@ export const DocumentNotificationEmail = ({ document, collection, eventName = "published", - unsubscribeUrl, + unsubscribeUrl }: Props) => { return ( diff --git a/server/emails/ExportEmail.js b/server/emails/ExportEmail.tsx similarity index 99% rename from server/emails/ExportEmail.js rename to server/emails/ExportEmail.tsx index df2bb2d437..b1610ef6ef 100644 --- a/server/emails/ExportEmail.js +++ b/server/emails/ExportEmail.tsx @@ -1,4 +1,3 @@ -// @flow import * as React from "react"; import Body from "./components/Body"; import Button from "./components/Button"; diff --git a/server/emails/InviteEmail.js b/server/emails/InviteEmail.tsx similarity index 96% rename from server/emails/InviteEmail.js rename to server/emails/InviteEmail.tsx index a293aa14cf..4bc2372f06 100644 --- a/server/emails/InviteEmail.js +++ b/server/emails/InviteEmail.tsx @@ -1,4 +1,3 @@ -// @flow import * as React from "react"; import Body from "./components/Body"; import Button from "./components/Button"; @@ -13,14 +12,14 @@ export type Props = { actorName: string, actorEmail: string, teamName: string, - teamUrl: string, + teamUrl: string }; export const inviteEmailText = ({ teamName, actorName, actorEmail, - teamUrl, + teamUrl }: Props) => ` Join ${teamName} on Outline @@ -33,7 +32,7 @@ export const InviteEmail = ({ teamName, actorName, actorEmail, - teamUrl, + teamUrl }: Props) => { return ( diff --git a/server/emails/SigninEmail.js b/server/emails/SigninEmail.tsx similarity index 88% rename from server/emails/SigninEmail.js rename to server/emails/SigninEmail.tsx index f9f736ecc2..1f8423f5ef 100644 --- a/server/emails/SigninEmail.js +++ b/server/emails/SigninEmail.tsx @@ -1,4 +1,3 @@ -// @flow import * as React from "react"; import Body from "./components/Body"; import Button from "./components/Button"; @@ -10,10 +9,13 @@ import Heading from "./components/Heading"; export type Props = { token: string, - teamUrl: string, + teamUrl: string }; -export const signinEmailText = ({ token, teamUrl }: Props) => ` +export const signinEmailText = ({ + token, + teamUrl +}: Props) => ` Use the link below to signin to Outline: ${process.env.URL}/auth/email.callback?token=${token} @@ -22,7 +24,10 @@ If your magic link expired you can request a new one from your team’s signin page at: ${teamUrl} `; -export const SigninEmail = ({ token, teamUrl }: Props) => { +export const SigninEmail = ({ + token, + teamUrl +}: Props) => { return (
diff --git a/server/emails/WelcomeEmail.js b/server/emails/WelcomeEmail.tsx similarity index 91% rename from server/emails/WelcomeEmail.js rename to server/emails/WelcomeEmail.tsx index 6745a8d886..35770d3450 100644 --- a/server/emails/WelcomeEmail.js +++ b/server/emails/WelcomeEmail.tsx @@ -1,4 +1,3 @@ -// @flow import * as React from "react"; import Body from "./components/Body"; import Button from "./components/Button"; @@ -9,10 +8,12 @@ import Header from "./components/Header"; import Heading from "./components/Heading"; export type Props = { - teamUrl: string, + teamUrl: string }; -export const welcomeEmailText = ({ teamUrl }: Props) => ` +export const welcomeEmailText = ({ + teamUrl +}: Props) => ` Welcome to Outline! Outline is a place for your team to build and share knowledge. @@ -24,7 +25,9 @@ You can also import existing Markdown documents by dragging and dropping them to ${teamUrl}/home `; -export const WelcomeEmail = ({ teamUrl }: Props) => { +export const WelcomeEmail = ({ + teamUrl +}: Props) => { return (
diff --git a/server/emails/components/Body.js b/server/emails/components/Body.tsx similarity index 83% rename from server/emails/components/Body.js rename to server/emails/components/Body.tsx index eef2ea4fb6..f24bf810f5 100644 --- a/server/emails/components/Body.js +++ b/server/emails/components/Body.tsx @@ -1,14 +1,15 @@ -// @flow import { Table, TBody, TR, TD } from "oy-vey"; import * as React from "react"; import EmptySpace from "./EmptySpace"; type Props = { - children: React.Node, + children: React.ReactNode }; -export default ({ children }: Props) => { +export default ({ + children +}: Props) => { return ( diff --git a/server/emails/components/Button.js b/server/emails/components/Button.tsx similarity index 85% rename from server/emails/components/Button.js rename to server/emails/components/Button.tsx index 812691d5e7..19033c7df8 100644 --- a/server/emails/components/Button.js +++ b/server/emails/components/Button.tsx @@ -1,7 +1,9 @@ -// @flow import * as React from "react"; -type Props = { href: string, children: React.Node }; +type Props = { + href: string, + children: React.ReactNode +}; export default (props: Props) => { const style = { diff --git a/server/emails/components/EmailLayout.js b/server/emails/components/EmailLayout.tsx similarity index 93% rename from server/emails/components/EmailLayout.js rename to server/emails/components/EmailLayout.tsx index 05cd84c77c..4f0b8c8e56 100644 --- a/server/emails/components/EmailLayout.js +++ b/server/emails/components/EmailLayout.tsx @@ -1,10 +1,9 @@ -// @flow import { Table, TBody, TR, TD } from "oy-vey"; import * as React from "react"; import theme from "../../../shared/styles/theme"; type Props = { - children: React.Node, + children: React.ReactNode }; export default (props: Props) => ( diff --git a/server/emails/components/EmptySpace.js b/server/emails/components/EmptySpace.tsx similarity index 88% rename from server/emails/components/EmptySpace.js rename to server/emails/components/EmptySpace.tsx index 6e9349119f..6bbe65af08 100644 --- a/server/emails/components/EmptySpace.js +++ b/server/emails/components/EmptySpace.tsx @@ -1,8 +1,11 @@ -// @flow import { Table, TBody, TR, TD } from "oy-vey"; import * as React from "react"; -const EmptySpace = ({ height }: { height?: number }) => { +const EmptySpace = ({ + height +}: { + height?: number +}) => { height = height || 16; const style = { lineHeight: `${height}px`, diff --git a/server/emails/components/Footer.js b/server/emails/components/Footer.tsx similarity index 93% rename from server/emails/components/Footer.js rename to server/emails/components/Footer.tsx index c54330ac97..d5e8998d5d 100644 --- a/server/emails/components/Footer.js +++ b/server/emails/components/Footer.tsx @@ -1,14 +1,15 @@ -// @flow import { Table, TBody, TR, TD } from "oy-vey"; import * as React from "react"; import theme from "../../../shared/styles/theme"; import { twitterUrl } from "../../../shared/utils/routeHelpers"; type Props = { - unsubscribeUrl?: string, + unsubscribeUrl?: string }; -export default ({ unsubscribeUrl }: Props) => { +export default ({ + unsubscribeUrl +}: Props) => { const footerStyle = { padding: "20px 0", borderTop: `1px solid ${theme.smokeDark}`, diff --git a/server/emails/components/Header.js b/server/emails/components/Header.tsx similarity index 98% rename from server/emails/components/Header.js rename to server/emails/components/Header.tsx index 940fdf22a9..fdea712368 100644 --- a/server/emails/components/Header.js +++ b/server/emails/components/Header.tsx @@ -1,4 +1,3 @@ -// @flow import { Table, TBody, TR, TD } from "oy-vey"; import * as React from "react"; import EmptySpace from "./EmptySpace"; diff --git a/server/emails/components/Heading.js b/server/emails/components/Heading.tsx similarity index 69% rename from server/emails/components/Heading.js rename to server/emails/components/Heading.tsx index 6138b2ac39..c5fa3cf9b3 100644 --- a/server/emails/components/Heading.js +++ b/server/emails/components/Heading.tsx @@ -1,4 +1,3 @@ -// @flow import * as React from "react"; const style = { @@ -7,10 +6,12 @@ const style = { }; type Props = { - children: React.Node, + children: React.ReactNode }; -export default ({ children }: Props) => ( +export default ({ + children +}: Props) => (

{children}

diff --git a/server/emails/index.js b/server/emails/index.ts similarity index 99% rename from server/emails/index.js rename to server/emails/index.ts index eb519d46a9..cc3a474f8a 100644 --- a/server/emails/index.js +++ b/server/emails/index.ts @@ -1,4 +1,3 @@ -// @flow import Koa from "koa"; import Router from "koa-router"; import { NotFoundError } from "../errors"; diff --git a/server/middlewares/apexRedirect.js b/server/middlewares/apexRedirect.ts similarity index 79% rename from server/middlewares/apexRedirect.js rename to server/middlewares/apexRedirect.ts index 992837ad02..5ad636c5cd 100644 --- a/server/middlewares/apexRedirect.js +++ b/server/middlewares/apexRedirect.ts @@ -1,10 +1,9 @@ -// @flow -import type { Context } from "koa"; +import { Context } from "koa"; export default function apexRedirect() { return async function apexRedirectMiddleware( ctx: Context, - next: () => Promise<*> + next: (() => Promise) ) { if (ctx.headers.host === "getoutline.com") { ctx.redirect(`https://www.${ctx.headers.host}${ctx.path}`); diff --git a/server/middlewares/authentication.test.js b/server/middlewares/authentication.test.ts similarity index 100% rename from server/middlewares/authentication.test.js rename to server/middlewares/authentication.test.ts diff --git a/server/middlewares/authentication.js b/server/middlewares/authentication.ts similarity index 96% rename from server/middlewares/authentication.js rename to server/middlewares/authentication.ts index 126221334b..8bd4a42589 100644 --- a/server/middlewares/authentication.js +++ b/server/middlewares/authentication.ts @@ -1,16 +1,17 @@ -// @flow import addMonths from "date-fns/add_months"; import JWT from "jsonwebtoken"; import { AuthenticationError, UserSuspendedError } from "../errors"; import { User, Event, Team, ApiKey } from "../models"; -import type { ContextWithState } from "../types"; +import { ContextWithState } from "../types"; import { getCookieDomain } from "../utils/domains"; import { getUserForJWT } from "../utils/jwt"; -export default function auth(options?: { required?: boolean } = {}) { +export default function auth(options?: { + required?: boolean +} = {}) { return async function authMiddleware( ctx: ContextWithState, - next: () => Promise + next: (() => Promise) ) { let token; diff --git a/server/middlewares/errorHandling.js b/server/middlewares/errorHandling.ts similarity index 94% rename from server/middlewares/errorHandling.js rename to server/middlewares/errorHandling.ts index d5a8985df8..419fc88ad1 100644 --- a/server/middlewares/errorHandling.js +++ b/server/middlewares/errorHandling.ts @@ -1,12 +1,11 @@ -// @flow -import { type Context } from "koa"; +import { Context } from "koa"; import { snakeCase } from "lodash"; import Sequelize from "sequelize"; export default function errorHandling() { return async function errorHandlingMiddleware( ctx: Context, - next: () => Promise<*> + next: (() => Promise) ) { try { await next(); diff --git a/server/middlewares/methodOverride.js b/server/middlewares/methodOverride.ts similarity index 85% rename from server/middlewares/methodOverride.js rename to server/middlewares/methodOverride.ts index 2ff5b48cfe..3357c0b70d 100644 --- a/server/middlewares/methodOverride.js +++ b/server/middlewares/methodOverride.ts @@ -1,11 +1,10 @@ -// @flow -import { type Context } from "koa"; +import { Context } from "koa"; import queryString from "query-string"; export default function methodOverride() { return async function methodOverrideMiddleware( ctx: Context, - next: () => Promise<*> + next: (() => Promise) ) { if (ctx.method === "POST") { // $FlowFixMe diff --git a/server/middlewares/validation.js b/server/middlewares/validation.ts similarity index 91% rename from server/middlewares/validation.js rename to server/middlewares/validation.ts index a46c376da2..4c3aefd809 100644 --- a/server/middlewares/validation.js +++ b/server/middlewares/validation.ts @@ -1,11 +1,10 @@ -// @flow -import { type Context } from "koa"; +import { Context } from "koa"; import validator from "validator"; import { validateColorHex } from "../../shared/utils/color"; import { ParamRequiredError, ValidationError } from "../errors"; export default function validation() { - return function validationMiddleware(ctx: Context, next: () => Promise<*>) { + return function validationMiddleware(ctx: Context, next: (() => Promise)) { ctx.assertPresent = (value, message) => { if (value === undefined || value === null || value === "") { throw new ParamRequiredError(message);