Merge pull request #417 from jorilallo/jori/lint
Lint rules and flow annotations for rest of the files
This commit is contained in:
commit
1d20a7ec7d
|
@ -0,0 +1 @@
|
||||||
|
server/migrations/*.js
|
|
@ -36,6 +36,7 @@
|
||||||
"prettier/prettier": [
|
"prettier/prettier": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
|
"printWidth": 80,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"singleQuote": true
|
"singleQuote": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
import Router from 'koa-router';
|
import Router from 'koa-router';
|
||||||
import httpErrors from 'http-errors';
|
import httpErrors from 'http-errors';
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
import Router from 'koa-router';
|
import Router from 'koa-router';
|
||||||
import httpErrors from 'http-errors';
|
import httpErrors from 'http-errors';
|
||||||
import { Document, User } from '../models';
|
import { Document, User } from '../models';
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
import bodyParser from 'koa-bodyparser';
|
import bodyParser from 'koa-bodyparser';
|
||||||
import Koa from 'koa';
|
import Koa from 'koa';
|
||||||
import Router from 'koa-router';
|
import Router from 'koa-router';
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
export default function apiWrapper(_options) {
|
// @flow
|
||||||
return async function apiWrapperMiddleware(ctx, next) {
|
import { type Context } from 'koa';
|
||||||
|
|
||||||
|
export default function apiWrapper() {
|
||||||
|
return async function apiWrapperMiddleware(
|
||||||
|
ctx: Context,
|
||||||
|
next: () => Promise<void>
|
||||||
|
) {
|
||||||
await next();
|
await next();
|
||||||
|
|
||||||
const ok = ctx.status < 400;
|
const ok = ctx.status < 400;
|
||||||
|
|
||||||
|
// $FlowFixMe
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
...ctx.body,
|
...ctx.body,
|
||||||
status: ctx.status,
|
status: ctx.status,
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
|
// @flow
|
||||||
import httpErrors from 'http-errors';
|
import httpErrors from 'http-errors';
|
||||||
import JWT from 'jsonwebtoken';
|
import JWT from 'jsonwebtoken';
|
||||||
|
import { type Context } from 'koa';
|
||||||
|
|
||||||
import { User, ApiKey } from '../../models';
|
import { User, ApiKey } from '../../models';
|
||||||
|
|
||||||
export default function auth({ require = true } = {}) {
|
export default function auth({ require = true }: { require?: boolean } = {}) {
|
||||||
return async function authMiddleware(ctx, next) {
|
return async function authMiddleware(
|
||||||
|
ctx: Context,
|
||||||
|
next: () => Promise<void>
|
||||||
|
) {
|
||||||
let token;
|
let token;
|
||||||
|
|
||||||
const authorizationHeader = ctx.request.get('authorization');
|
const authorizationHeader = ctx.request.get('authorization');
|
||||||
|
@ -25,6 +30,7 @@ export default function auth({ require = true } = {}) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// $FlowFixMe
|
||||||
} else if (ctx.body.token) {
|
} else if (ctx.body.token) {
|
||||||
token = ctx.body.token;
|
token = ctx.body.token;
|
||||||
} else if (ctx.request.query.token) {
|
} else if (ctx.request.query.token) {
|
||||||
|
@ -38,7 +44,7 @@ export default function auth({ require = true } = {}) {
|
||||||
if (token) {
|
if (token) {
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
if (token.match(/^[\w]{38}$/)) {
|
if (String(token).match(/^[\w]{38}$/)) {
|
||||||
// API key
|
// API key
|
||||||
let apiKey;
|
let apiKey;
|
||||||
try {
|
try {
|
||||||
|
@ -83,6 +89,7 @@ export default function auth({ require = true } = {}) {
|
||||||
|
|
||||||
ctx.state.token = token;
|
ctx.state.token = token;
|
||||||
ctx.state.user = user;
|
ctx.state.user = user;
|
||||||
|
// $FlowFixMe
|
||||||
ctx.cache[user.id] = user;
|
ctx.cache[user.id] = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
|
// @flow
|
||||||
import httpErrors from 'http-errors';
|
import httpErrors from 'http-errors';
|
||||||
import querystring from 'querystring';
|
import querystring from 'querystring';
|
||||||
|
import { type Context } from 'koa';
|
||||||
|
|
||||||
export default function pagination(options) {
|
export default function pagination(options?: Object) {
|
||||||
return async function paginationMiddleware(ctx, next) {
|
return async function paginationMiddleware(
|
||||||
|
ctx: Context,
|
||||||
|
next: () => Promise<void>
|
||||||
|
) {
|
||||||
const opts = {
|
const opts = {
|
||||||
defaultLimit: 15,
|
defaultLimit: 15,
|
||||||
maxLimit: 100,
|
maxLimit: 100,
|
||||||
|
@ -11,7 +16,9 @@ export default function pagination(options) {
|
||||||
|
|
||||||
let query = ctx.request.query;
|
let query = ctx.request.query;
|
||||||
let body = ctx.request.body;
|
let body = ctx.request.body;
|
||||||
|
// $FlowFixMe
|
||||||
let limit = parseInt(query.limit || body.limit, 10);
|
let limit = parseInt(query.limit || body.limit, 10);
|
||||||
|
// $FlowFixMe
|
||||||
let offset = parseInt(query.offset || body.offset, 10);
|
let offset = parseInt(query.offset || body.offset, 10);
|
||||||
limit = isNaN(limit) ? opts.defaultLimit : limit;
|
limit = isNaN(limit) ? opts.defaultLimit : limit;
|
||||||
offset = isNaN(offset) ? 0 : offset;
|
offset = isNaN(offset) ? 0 : offset;
|
||||||
|
@ -27,9 +34,13 @@ export default function pagination(options) {
|
||||||
offset: offset,
|
offset: offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// $FlowFixMe
|
||||||
query.limit = ctx.state.pagination.limit;
|
query.limit = ctx.state.pagination.limit;
|
||||||
|
// $FlowFixMe
|
||||||
query.offset = ctx.state.pagination.offset + query.limit;
|
query.offset = ctx.state.pagination.offset + query.limit;
|
||||||
ctx.state.pagination.nextPath = `/api${ctx.request.path}?${querystring.stringify(query)}`;
|
ctx.state.pagination.nextPath = `/api${
|
||||||
|
ctx.request.path
|
||||||
|
}?${querystring.stringify(query)}`;
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
import uuid from 'uuid';
|
import uuid from 'uuid';
|
||||||
import Router from 'koa-router';
|
import Router from 'koa-router';
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||||
import TestServer from 'fetch-test-server';
|
import TestServer from 'fetch-test-server';
|
||||||
|
|
||||||
import app from '..';
|
import app from '..';
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
// @flow
|
||||||
import httpErrors from 'http-errors';
|
import httpErrors from 'http-errors';
|
||||||
|
|
||||||
const apiError = (code, id, message) => {
|
const apiError = (code: number, id: string, message: string) => {
|
||||||
return httpErrors(code, message, { id });
|
return httpErrors(code, message, { id });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
// @flow
|
||||||
import queryString from 'query-string';
|
import queryString from 'query-string';
|
||||||
|
import { type Context } from 'koa';
|
||||||
|
|
||||||
export default function methodOverride(_options) {
|
export default function methodOverride() {
|
||||||
return async function methodOverrideMiddleware(ctx, next) {
|
return async function methodOverrideMiddleware(
|
||||||
|
ctx: Context,
|
||||||
|
next: () => Promise<void>
|
||||||
|
) {
|
||||||
if (ctx.method === 'POST') {
|
if (ctx.method === 'POST') {
|
||||||
|
// $FlowFixMe
|
||||||
ctx.body = ctx.request.body;
|
ctx.body = ctx.request.body;
|
||||||
} else if (ctx.method === 'GET') {
|
} else if (ctx.method === 'GET') {
|
||||||
ctx.method = 'POST'; // eslint-disable-line
|
ctx.method = 'POST'; // eslint-disable-line
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
export default function subdomainRedirect(options) {
|
// @flow
|
||||||
return async function subdomainRedirectMiddleware(ctx, next) {
|
import { type Context } from 'koa';
|
||||||
|
|
||||||
|
export default function subdomainRedirect() {
|
||||||
|
return async function subdomainRedirectMiddleware(
|
||||||
|
ctx: Context,
|
||||||
|
next: () => Promise<void>
|
||||||
|
) {
|
||||||
if (ctx.headers.host === 'getoutline.com') {
|
if (ctx.headers.host === 'getoutline.com') {
|
||||||
ctx.redirect(`https://www.${ctx.headers.host}${ctx.path}`);
|
ctx.redirect(`https://www.${ctx.headers.host}${ctx.path}`);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.createTable('teams', {
|
queryInterface.createTable('teams', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('documents', 'parentDocumentId', {
|
queryInterface.addColumn('documents', 'parentDocumentId', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addIndex('documents', ['urlId']);
|
queryInterface.addIndex('documents', ['urlId']);
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.createTable('revisions', {
|
queryInterface.createTable('revisions', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
const searchDocument = `
|
const searchDocument = `
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('atlases', 'creatorId', {
|
queryInterface.addColumn('atlases', 'creatorId', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('atlases', 'deletedAt', {
|
queryInterface.addColumn('atlases', 'deletedAt', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
// Remove old indeces
|
// Remove old indeces
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('documents', 'createdById', {
|
queryInterface.addColumn('documents', 'createdById', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('documents', 'collaboratorIds', {
|
queryInterface.addColumn('documents', 'collaboratorIds', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addColumn('atlases', 'urlId', {
|
queryInterface.addColumn('atlases', 'urlId', {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addIndex('revisions', ['documentId']);
|
queryInterface.addIndex('revisions', ['documentId']);
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: function(queryInterface, Sequelize) {
|
up: function(queryInterface, Sequelize) {
|
||||||
queryInterface.addIndex('apiKeys', ['secret', 'deletedAt']);
|
queryInterface.addIndex('apiKeys', ['secret', 'deletedAt']);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
import { DataTypes, sequelize } from '../sequelize';
|
import { DataTypes, sequelize } from '../sequelize';
|
||||||
import randomstring from 'randomstring';
|
import randomstring from 'randomstring';
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||||
import { flushdb, seed } from '../test/support';
|
import { flushdb, seed } from '../test/support';
|
||||||
|
|
||||||
beforeEach(flushdb);
|
beforeEach(flushdb);
|
||||||
|
|
|
@ -12,9 +12,7 @@ export default function About() {
|
||||||
</Helmet>
|
</Helmet>
|
||||||
<Hero>
|
<Hero>
|
||||||
<h1>About Outline</h1>
|
<h1>About Outline</h1>
|
||||||
<p>
|
<p>Just a proof of concept for multiple pages.</p>
|
||||||
Just a proof of concept for multiple pages.
|
|
||||||
</p>
|
|
||||||
</Hero>
|
</Hero>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,7 +13,8 @@ export default function Pricing() {
|
||||||
<Hero>
|
<Hero>
|
||||||
<h1>Pricing</h1>
|
<h1>Pricing</h1>
|
||||||
<p>
|
<p>
|
||||||
Explore Outline with a 14 day trial, free forever for teams smaller than 5.
|
Explore Outline with a 14 day trial, free forever for teams smaller
|
||||||
|
than 5.
|
||||||
</p>
|
</p>
|
||||||
</Hero>
|
</Hero>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
function present(ctx, key) {
|
// @flow
|
||||||
|
import { type Context } from 'koa';
|
||||||
|
import { ApiKey } from '../models';
|
||||||
|
|
||||||
|
function present(ctx: Context, key: ApiKey) {
|
||||||
return {
|
return {
|
||||||
id: key.id,
|
id: key.id,
|
||||||
name: key.name,
|
name: key.name,
|
||||||
|
|
|
@ -8,8 +8,8 @@ function present(ctx: Object, user: User) {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
name: user.name,
|
name: user.name,
|
||||||
avatarUrl: user.avatarUrl ||
|
avatarUrl:
|
||||||
(user.slackData ? user.slackData.image_192 : null),
|
user.avatarUrl || (user.slackData ? user.slackData.image_192 : null),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||||
import presentUser from './user';
|
import presentUser from './user';
|
||||||
|
|
||||||
import ctx from '../../__mocks__/ctx';
|
import ctx from '../../__mocks__/ctx';
|
||||||
|
|
||||||
it('presents a user', async () => {
|
it('presents a user', async () => {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// @flow
|
||||||
import redis from 'redis';
|
import redis from 'redis';
|
||||||
import redisLock from 'redis-lock';
|
import redisLock from 'redis-lock';
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,7 @@ const sheet = new ServerStyleSheet();
|
||||||
export default function renderpage(ctx: Object, children: React$Element<*>) {
|
export default function renderpage(ctx: Object, children: React$Element<*>) {
|
||||||
const html = ReactDOMServer.renderToString(
|
const html = ReactDOMServer.renderToString(
|
||||||
<StyleSheetManager sheet={sheet.instance}>
|
<StyleSheetManager sheet={sheet.instance}>
|
||||||
<Layout>
|
<Layout>{children}</Layout>
|
||||||
{children}
|
|
||||||
</Layout>
|
|
||||||
</StyleSheetManager>
|
</StyleSheetManager>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,10 @@ export default async () => {
|
||||||
'SECRET_KEY or URL env var is not set'
|
'SECRET_KEY or URL env var is not set'
|
||||||
);
|
);
|
||||||
const secret = process.env.SECRET_KEY.slice(0, 6) + process.env.URL;
|
const secret = process.env.SECRET_KEY.slice(0, 6) + process.env.URL;
|
||||||
const id = crypto.createHash('sha256').update(secret).digest('hex');
|
const id = crypto
|
||||||
|
.createHash('sha256')
|
||||||
|
.update(secret)
|
||||||
|
.digest('hex');
|
||||||
|
|
||||||
const [
|
const [
|
||||||
userCount,
|
userCount,
|
||||||
|
|
Reference in New Issue