Document Viewers (#79)

* Recording document views

* Add 'views' to document response

* Basic displaying of document views, probably want it more sublte than this? But hey, lets get it in there

* Bigly improves. RESTful > RPC

* Display of who's viewed doc

* Add Popover, add Scrollable, move views store

* Working server tests 💁

* Document Stars (#81)

* Added: Starred documents

* UI is dumb but functionality works

* Star now displayed inline in title

* Optimistic rendering

* Documents Endpoints (#85)

* More seeds, documents.list endpoint

* Upgrade deprecated middleware

* document.viewers, specs

* Add documents.starred
Add request specs for star / unstar endpoints

* Basic /starred page

* Remove comment

* Fixed double layout
This commit is contained in:
Tom Moor 2017-06-25 17:21:33 -07:00 committed by GitHub
parent 1fa473b271
commit 52765d9d1d
66 changed files with 1629 additions and 460 deletions

View File

@ -5,12 +5,15 @@
1. Install dependencies with `yarn`
1. Register a Slack app at https://api.slack.com/apps
1. Copy the file `.env.sample` to `.env` and fill out the keys
1. Run DB migrations `./node_modules/.bin/sequelize db:migrate`
1. Start the server `yarn start`
1. Run DB migrations `yarn run sequelize -- db:migrate`
1. Start the development server `yarn start`
## Ideas
## Migrations
- Create sharable private URLs for notes
- Settings
- Enable :emoji: autoconvert
Sequelize is used to create and run migrations, for example:
```
yarn run sequelize -- migration:create
yarn run sequelize -- db:migrate
```

View File

@ -0,0 +1,10 @@
// @flow
import styled from 'styled-components';
const Avatar = styled.img`
width: 24px;
height: 24px;
border-radius: 50%;
`;
export default Avatar;

View File

@ -0,0 +1,3 @@
// @flow
import Avatar from './Avatar';
export default Avatar;

View File

@ -20,8 +20,8 @@ const DocumentLink = styled(Link)`
border-radius: 8px;
border: 2px solid transparent;
max-height: 50vh;
min-width: 100%;
overflow: hidden;
width: 100%;
&:hover,
&:active,

View File

@ -0,0 +1,41 @@
// @flow
import { observable, action } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { User } from 'types';
type View = {
user: User,
count: number,
};
class DocumentViewersStore {
documentId: string;
@observable viewers: Array<View>;
@observable isFetching: boolean;
@action fetchViewers = async () => {
this.isFetching = true;
try {
const res = await client.get(
'/views.list',
{
id: this.documentId,
},
{ cache: true }
);
invariant(res && res.data, 'Data should be available');
this.viewers = res.data.users;
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
constructor(documentId: string) {
this.documentId = documentId;
}
}
export default DocumentViewersStore;

View File

@ -0,0 +1,76 @@
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import Popover from 'components/Popover';
import styled from 'styled-components';
import DocumentViewers from './components/DocumentViewers';
import DocumentViewersStore from './DocumentViewersStore';
import { Flex } from 'reflexbox';
const Container = styled(Flex)`
font-size: 13px;
user-select: none;
a {
color: #ccc;
&:hover {
color: #aaa;
}
}
`;
type Props = {
documentId: string,
count: number,
};
@observer class DocumentViews extends Component {
anchor: HTMLElement;
store: DocumentViewersStore;
props: Props;
state: {
opened: boolean,
};
state = {};
constructor(props: Props) {
super(props);
this.store = new DocumentViewersStore(props.documentId);
}
openPopover = () => {
this.setState({ opened: true });
};
closePopover = () => {
this.setState({ opened: false });
};
setRef = (ref: HTMLElement) => {
this.anchor = ref;
};
render() {
return (
<Container align="center">
<a ref={this.setRef} onClick={this.openPopover}>
Viewed
{' '}
{this.props.count}
{' '}
{this.props.count === 1 ? 'time' : 'times'}
</a>
{this.state.opened &&
<Popover anchor={this.anchor} onClose={this.closePopover}>
<DocumentViewers
onMount={this.store.fetchViewers}
viewers={this.store.viewers}
/>
</Popover>}
</Container>
);
}
}
export default DocumentViews;

View File

@ -0,0 +1,55 @@
// @flow
import React, { Component } from 'react';
import { Flex } from 'reflexbox';
import styled from 'styled-components';
import map from 'lodash/map';
import Avatar from 'components/Avatar';
import Scrollable from 'components/Scrollable';
type Props = {
viewers: Array<Object>,
onMount: Function,
};
const List = styled.ul`
list-style: none;
font-size: 13px;
margin: -4px 0;
padding: 0;
li {
padding: 4px 0;
}
`;
const UserName = styled.span`
padding-left: 8px;
`;
class DocumentViewers extends Component {
props: Props;
componentDidMount() {
this.props.onMount();
}
render() {
return (
<Scrollable>
<List>
{map(this.props.viewers, view => (
<li key={view.user.id}>
<Flex align="center">
<Avatar src={view.user.avatarUrl} />
{' '}
<UserName>{view.user.name}</UserName>
</Flex>
</li>
))}
</List>
</Scrollable>
);
}
}
export default DocumentViewers;

View File

@ -0,0 +1,3 @@
// @flow
import DocumentViewers from './DocumentViewers';
export default DocumentViewers;

View File

@ -0,0 +1,3 @@
// @flow
import DocumentViews from './DocumentViews';
export default DocumentViews;

View File

@ -1,13 +1,14 @@
// @flow
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { Editor, Plain } from 'slate';
import classnames from 'classnames/bind';
import type { Document, State, Editor as EditorType } from './types';
import ClickablePadding from './components/ClickablePadding';
import Toolbar from './components/Toolbar';
import schema from './schema';
import Markdown from './serializer';
import createSchema from './schema';
import createPlugins from './plugins';
import styles from './Editor.scss';
@ -18,8 +19,11 @@ type Props = {
onChange: Function,
onSave: Function,
onCancel: Function,
onStar: Function,
onUnstar: Function,
onImageUploadStart: Function,
onImageUploadStop: Function,
starred: boolean,
readOnly: boolean,
};
@ -28,10 +32,10 @@ type KeyData = {
key: string,
};
@observer
export default class MarkdownEditor extends Component {
@observer class MarkdownEditor extends Component {
props: Props;
editor: EditorType;
schema: Object;
plugins: Array<Object>;
state: {
@ -41,6 +45,10 @@ export default class MarkdownEditor extends Component {
constructor(props: Props) {
super(props);
this.schema = createSchema({
onStar: props.onStar,
onUnstar: props.onUnstar,
});
this.plugins = createPlugins({
onImageUploadStart: props.onImageUploadStart,
onImageUploadStop: props.onImageUploadStop,
@ -53,6 +61,10 @@ export default class MarkdownEditor extends Component {
}
}
getChildContext() {
return { starred: this.props.starred };
}
onChange = (state: State) => {
this.setState({ state });
};
@ -103,10 +115,11 @@ export default class MarkdownEditor extends Component {
<ClickablePadding onClick={this.focusAtStart} />}
<Toolbar state={this.state.state} onChange={this.onChange} />
<Editor
key={this.props.starred}
ref={ref => (this.editor = ref)}
placeholder="Start with a title…"
className={cx(styles.editor, { readOnly: this.props.readOnly })}
schema={schema}
schema={this.schema}
plugins={this.plugins}
state={this.state.state}
onChange={this.onChange}
@ -121,3 +134,9 @@ export default class MarkdownEditor extends Component {
);
};
}
MarkdownEditor.childContextTypes = {
starred: PropTypes.bool,
};
export default MarkdownEditor;

View File

@ -1,7 +1,10 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import _ from 'lodash';
import slug from 'slug';
import StarIcon from 'components/Icon/StarIcon';
import type { Node, Editor } from '../types';
import styles from '../Editor.scss';
@ -10,23 +13,53 @@ type Props = {
placeholder?: boolean,
parent: Node,
node: Node,
onStar?: Function,
onUnstar?: Function,
editor: Editor,
readOnly: boolean,
component?: string,
};
export default function Heading({
parent,
placeholder,
node,
editor,
readOnly,
children,
component = 'h1',
}: Props) {
type Context = {
starred?: boolean,
};
const StyledStar = styled(StarIcon)`
top: 3px;
position: relative;
margin-left: 4px;
opacity: ${props => (props.solid ? 1 : 0.25)};
transition: opacity 100ms ease-in-out;
&:hover {
opacity: 1;
}
svg {
width: 28px;
height: 28px;
}
`;
function Heading(
{
parent,
placeholder,
node,
editor,
onStar,
onUnstar,
readOnly,
children,
component = 'h1',
}: Props,
{ starred }: Context
) {
const firstHeading = parent.nodes.first() === node;
const showPlaceholder = placeholder && firstHeading && !node.text;
const slugish = readOnly && _.escape(`${component}-${slug(node.text)}`);
const slugish = _.escape(`${component}-${slug(node.text)}`);
const showStar = readOnly && !!onStar;
const showHash = readOnly && !!slugish && !showStar;
const Component = component;
return (
@ -36,8 +69,16 @@ export default function Heading({
<span className={styles.placeholder}>
{editor.props.placeholder}
</span>}
{slugish &&
{showHash &&
<a name={slugish} className={styles.anchor} href={`#${slugish}`}>#</a>}
{showStar && starred && <a onClick={onUnstar}><StyledStar solid /></a>}
{showStar && !starred && <a onClick={onStar}><StyledStar /></a>}
</Component>
);
}
Heading.contextTypes = {
starred: PropTypes.bool,
};
export default Heading;

View File

@ -12,15 +12,12 @@ import MarkdownShortcuts from './plugins/MarkdownShortcuts';
const onlyInCode = node => node.type === 'code';
type CreatePluginsOptions = {
type Options = {
onImageUploadStart: Function,
onImageUploadStop: Function,
};
const createPlugins = ({
onImageUploadStart,
onImageUploadStop,
}: CreatePluginsOptions) => {
const createPlugins = ({ onImageUploadStart, onImageUploadStop }: Options) => {
return [
PasteLinkify({
type: 'link',

View File

@ -8,87 +8,98 @@ import Heading from './components/Heading';
import type { Props, Node, Transform } from './types';
import styles from './Editor.scss';
const schema = {
marks: {
bold: (props: Props) => <strong>{props.children}</strong>,
code: (props: Props) => <code>{props.children}</code>,
italic: (props: Props) => <em>{props.children}</em>,
underlined: (props: Props) => <u>{props.children}</u>,
deleted: (props: Props) => <del>{props.children}</del>,
added: (props: Props) => <mark>{props.children}</mark>,
},
nodes: {
paragraph: (props: Props) => <p>{props.children}</p>,
'block-quote': (props: Props) => <blockquote>{props.children}</blockquote>,
'horizontal-rule': (props: Props) => <hr />,
'bulleted-list': (props: Props) => <ul>{props.children}</ul>,
'ordered-list': (props: Props) => <ol>{props.children}</ol>,
'todo-list': (props: Props) => (
<ul className={styles.todoList}>{props.children}</ul>
),
table: (props: Props) => <table>{props.children}</table>,
'table-row': (props: Props) => <tr>{props.children}</tr>,
'table-head': (props: Props) => <th>{props.children}</th>,
'table-cell': (props: Props) => <td>{props.children}</td>,
code: Code,
image: Image,
link: Link,
'list-item': ListItem,
heading1: (props: Props) => <Heading placeholder {...props} />,
heading2: (props: Props) => <Heading component="h2" {...props} />,
heading3: (props: Props) => <Heading component="h3" {...props} />,
heading4: (props: Props) => <Heading component="h4" {...props} />,
heading5: (props: Props) => <Heading component="h5" {...props} />,
heading6: (props: Props) => <Heading component="h6" {...props} />,
},
rules: [
// ensure first node is a heading
{
match: (node: Node) => {
return node.kind === 'document';
},
validate: (document: Node) => {
const firstNode = document.nodes.first();
return firstNode && firstNode.type === 'heading1' ? null : firstNode;
},
normalize: (transform: Transform, document: Node, firstNode: Node) => {
transform.setBlock({ type: 'heading1' });
},
},
// remove any marks in first heading
{
match: (node: Node) => {
return node.kind === 'heading1';
},
validate: (heading: Node) => {
const hasMarks = heading.getMarks().isEmpty();
const hasInlines = heading.getInlines().isEmpty();
return !(hasMarks && hasInlines);
},
normalize: (transform: Transform, heading: Node) => {
transform.unwrapInlineByKey(heading.key);
heading.getMarks().forEach(mark => {
heading.nodes.forEach(textNode => {
if (textNode.kind === 'text') {
transform.removeMarkByKey(
textNode.key,
0,
textNode.text.length,
mark
);
}
});
});
return transform;
},
},
],
type Options = {
onStar: Function,
onUnstar: Function,
};
export default schema;
const createSchema = ({ onStar, onUnstar }: Options) => {
return {
marks: {
bold: (props: Props) => <strong>{props.children}</strong>,
code: (props: Props) => <code>{props.children}</code>,
italic: (props: Props) => <em>{props.children}</em>,
underlined: (props: Props) => <u>{props.children}</u>,
deleted: (props: Props) => <del>{props.children}</del>,
added: (props: Props) => <mark>{props.children}</mark>,
},
nodes: {
paragraph: (props: Props) => <p>{props.children}</p>,
'block-quote': (props: Props) => (
<blockquote>{props.children}</blockquote>
),
'horizontal-rule': (props: Props) => <hr />,
'bulleted-list': (props: Props) => <ul>{props.children}</ul>,
'ordered-list': (props: Props) => <ol>{props.children}</ol>,
'todo-list': (props: Props) => (
<ul className={styles.todoList}>{props.children}</ul>
),
table: (props: Props) => <table>{props.children}</table>,
'table-row': (props: Props) => <tr>{props.children}</tr>,
'table-head': (props: Props) => <th>{props.children}</th>,
'table-cell': (props: Props) => <td>{props.children}</td>,
code: Code,
image: Image,
link: Link,
'list-item': ListItem,
heading1: (props: Props) => (
<Heading placeholder onStar={onStar} onUnstar={onUnstar} {...props} />
),
heading2: (props: Props) => <Heading component="h2" {...props} />,
heading3: (props: Props) => <Heading component="h3" {...props} />,
heading4: (props: Props) => <Heading component="h4" {...props} />,
heading5: (props: Props) => <Heading component="h5" {...props} />,
heading6: (props: Props) => <Heading component="h6" {...props} />,
},
rules: [
// ensure first node is a heading
{
match: (node: Node) => {
return node.kind === 'document';
},
validate: (document: Node) => {
const firstNode = document.nodes.first();
return firstNode && firstNode.type === 'heading1' ? null : firstNode;
},
normalize: (transform: Transform, document: Node, firstNode: Node) => {
transform.setBlock({ type: 'heading1' });
},
},
// remove any marks in first heading
{
match: (node: Node) => {
return node.kind === 'heading1';
},
validate: (heading: Node) => {
const hasMarks = heading.getMarks().isEmpty();
const hasInlines = heading.getInlines().isEmpty();
return !(hasMarks && hasInlines);
},
normalize: (transform: Transform, heading: Node) => {
transform.unwrapInlineByKey(heading.key);
heading.getMarks().forEach(mark => {
heading.nodes.forEach(textNode => {
if (textNode.kind === 'text') {
transform.removeMarkByKey(
textNode.key,
0,
textNode.text.length,
mark
);
}
});
});
return transform;
},
},
],
};
};
export default createSchema;

View File

@ -0,0 +1,43 @@
// @flow
import React from 'react';
import Icon from './Icon';
import type { Props } from './Icon';
export default function StarIcon(props: Props & { solid?: boolean }) {
let icon;
if (props.solid) {
icon = (
<svg
fill="#000000"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M0 0h24v24H0z" fill="none" />
<path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z" />
<path d="M0 0h24v24H0z" fill="none" />
</svg>
);
} else {
icon = (
<svg
fill="#000000"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M22 9.24l-7.19-.62L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21 12 17.27 18.18 21l-1.63-7.03L22 9.24zM12 15.4l-3.76 2.27 1-4.28-3.32-2.88 4.38-.38L12 6.1l1.71 4.04 4.38.38-3.32 2.88 1 4.28L12 15.4z" />
<path d="M0 0h24v24H0z" fill="none" />
</svg>
);
}
return (
<Icon {...props}>
{icon}
</Icon>
);
}

View File

@ -0,0 +1,65 @@
// @flow
import React from 'react';
import BoundlessPopover from 'boundless-popover';
import styled, { keyframes } from 'styled-components';
const fadeIn = keyframes`
from {
opacity: 0;
}
50% {
opacity: 1;
}
`;
const StyledPopover = styled(BoundlessPopover)`
animation: ${fadeIn} 150ms ease-in-out;
display: flex;
flex-direction: column;
line-height: 0;
position: absolute;
top: 0;
left: 0;
z-index: 9999;
svg {
height: 16px;
width: 16px;
position: absolute;
polygon:first-child {
fill: rgba(0,0,0,.075);
}
polygon {
fill: #FFF;
}
}
`;
const Dialog = styled.div`
outline: none;
background: #FFF;
box-shadow: 0 0 0 1px rgba(0,0,0,.05), 0 8px 16px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.1);
border-radius: 4px;
line-height: 1.5;
padding: 16px;
margin-top: 14px;
min-width: 200px;
min-height: 150px;
`;
export const Preset = BoundlessPopover.preset;
export default function Popover(props: Object) {
return (
<StyledPopover
dialogComponent={Dialog}
closeOnOutsideScroll
closeOnOutsideFocus
closeOnEscKey
{...props}
/>
);
}

View File

@ -0,0 +1,4 @@
// @flow
import Popover from './Popover';
export { Preset } from './Popover';
export default Popover;

View File

@ -6,7 +6,7 @@ import type { User } from 'types';
import { Flex } from 'reflexbox';
const Container = styled(Flex)`
margin-bottom: 30px;
justify-content: space-between;
color: #ccc;
font-size: 13px;
`;
@ -31,6 +31,7 @@ class PublishingInfo extends Component {
createdBy: User,
updatedAt: string,
updatedBy: User,
views?: number,
};
render() {
@ -52,7 +53,9 @@ class PublishingInfo extends Component {
&nbsp;and&nbsp;
{this.props.createdBy.id !== this.props.updatedBy.id &&
` ${this.props.updatedBy.name} `}
modified {moment(this.props.updatedAt).fromNow()}
modified
{' '}
{moment(this.props.updatedAt).fromNow()}
</span>
: null}
</span>

View File

@ -0,0 +1,19 @@
// @flow
import React, { Component } from 'react';
import styled from 'styled-components';
const Scroll = styled.div`
height: 100%;
overflow-y: auto;
overflow-x: hidden;
transform: translateZ(0);
-webkit-overflow-scrolling: touch;
`;
class Scrollable extends Component {
render() {
return <Scroll {...this.props} />;
}
}
export default Scrollable;

View File

@ -0,0 +1,3 @@
// @flow
import Scrollable from './Scrollable';
export default Scrollable;

View File

@ -22,6 +22,7 @@ import 'styles/hljs-github-gist.scss';
import Home from 'scenes/Home';
import Dashboard from 'scenes/Dashboard';
import Starred from 'scenes/Starred';
import Collection from 'scenes/Collection';
import Document from 'scenes/Document';
import Search from 'scenes/Search';
@ -99,6 +100,7 @@ render(
<Layout>
<Switch>
<Route exact path="/dashboard" component={Dashboard} />
<Route exact path="/starred" component={Starred} />
<Route exact path="/collections/:id" component={Collection} />
<Route exact path="/d/:id" component={Document} />

View File

@ -18,9 +18,10 @@ class CollectionStore {
invariant(res && res.data, 'Data should be available');
const { data } = res;
if (data.type === 'atlas') this.redirectUrl = data.documents[0].url;
if (data.type === 'atlas') this.redirectUrl = data.recentDocuments[0].url;
else throw new Error('TODO code up non-atlas collections');
} catch (e) {
console.log(e);
this.redirectUrl = notFoundUrl();
}
this.isFetching = false;

View File

@ -13,6 +13,7 @@ import Menu from './components/Menu';
import Editor from 'components/Editor';
import { HeaderAction, SaveAction } from 'components/Layout';
import PublishingInfo from 'components/PublishingInfo';
import DocumentViews from 'components/DocumentViews';
import PreviewLoading from 'components/PreviewLoading';
import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle';
@ -58,9 +59,11 @@ type Props = {
this.store.newDocument = false;
this.store.fetchDocument();
}
this.store.viewDocument();
}
componentWillUnmout() {
componentWillUnmount() {
this.props.ui.clearActiveCollection();
}
@ -94,17 +97,10 @@ type Props = {
render() {
const isNew = this.props.newDocument || this.props.newChildDocument;
const isEditing = this.props.match.params.edit;
/*const title = (
<Breadcrumbs
document={this.store.document}
pathToDocument={this.store.pathToDocument}
/>
);*/
const titleText = this.store.document && get(this.store, 'document.title');
const actions = (
<Flex>
<Flex align="center">
<HeaderAction>
{isEditing
? <SaveAction
@ -114,14 +110,14 @@ type Props = {
/>
: <a onClick={this.onEdit}>Edit</a>}
</HeaderAction>
{!isEditing &&
<Menu store={this.store} document={this.store.document} />}
</Flex>
);
return (
<Container>
<Actions>{actions}</Actions>
<Container flex column>
<PagePadding auto justify="center">
<PageTitle title={titleText} />
<Prompt
@ -134,14 +130,6 @@ type Props = {
</CenteredContent>}
{this.store.document &&
<DocumentContainer>
{!isEditing &&
<PublishingInfo
collaborators={this.store.document.collaborators}
createdAt={this.store.document.createdAt}
createdBy={this.store.document.createdBy}
updatedAt={this.store.document.updatedAt}
updatedBy={this.store.document.updatedBy}
/>}
<Editor
text={this.store.document.text}
onImageUploadStart={this.onImageUploadStart}
@ -149,15 +137,44 @@ type Props = {
onChange={this.store.updateText}
onSave={this.onSave}
onCancel={this.onCancel}
onStar={this.store.starDocument}
onUnstar={this.store.unstarDocument}
starred={this.store.document.starred}
readOnly={!isEditing}
/>
</DocumentContainer>}
</PagePadding>
{this.store.document &&
<Meta align="center" readOnly={!isEditing}>
{!isEditing &&
<PublishingInfo
collaborators={this.store.document.collaborators}
createdAt={this.store.document.createdAt}
createdBy={this.store.document.createdBy}
updatedAt={this.store.document.updatedAt}
updatedBy={this.store.document.updatedBy}
/>}
{!isEditing &&
<DocumentViews
count={this.store.document.views}
documentId={this.store.document.id}
/>}
{actions}
</Meta>}
</Container>
);
}
}
const Meta = styled(Flex)`
justify-content: ${props => (props.readOnly ? 'space-between' : 'flex-end')};
align-items: flex-start;
width: 100%;
position: absolute;
top: 0;
padding: 10px 20px;
`;
const Container = styled(Flex)`
position: relative;
width: 100%;
@ -165,12 +182,7 @@ const Container = styled(Flex)`
const PagePadding = styled(Flex)`
padding: 80px 20px;
`;
const Actions = styled(Flex)`
position: absolute;
top: 0;
right: 20px;
position: relative;
`;
const DocumentContainer = styled.div`

View File

@ -74,6 +74,36 @@ class DocumentStore {
/* Actions */
@action starDocument = async () => {
this.document.starred = true;
try {
await client.post('/documents.star', {
id: this.documentId,
});
} catch (e) {
this.document.starred = false;
console.error('Something went wrong');
}
};
@action unstarDocument = async () => {
this.document.starred = false;
try {
await client.post('/documents.unstar', {
id: this.documentId,
});
} catch (e) {
this.document.starred = true;
console.error('Something went wrong');
}
};
@action viewDocument = async () => {
await client.post('/views.create', {
id: this.documentId,
});
};
@action fetchDocument = async () => {
this.isFetching = true;

View File

@ -0,0 +1,38 @@
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import styled from 'styled-components';
import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle';
import DocumentList from 'components/DocumentList';
import StarredStore from './StarredStore';
const Container = styled(CenteredContent)`
width: 100%;
padding: 16px;
`;
@observer class Starred extends Component {
store: StarredStore;
constructor() {
super();
this.store = new StarredStore();
}
componentDidMount() {
this.store.fetchDocuments();
}
render() {
return (
<Container column auto>
<PageTitle title="Starred" />
<h1>Starred</h1>
<DocumentList documents={this.store.documents} />
</Container>
);
}
}
export default Starred;

View File

@ -0,0 +1,29 @@
// @flow
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import type { Document } from 'types';
class StarredDocumentsStore {
@observable documents: Array<Document> = [];
@observable isFetching = false;
@action fetchDocuments = async () => {
this.isFetching = true;
try {
const res = await client.get('/documents.starred');
invariant(res && res.data, 'res or res.data missing');
const { data } = res;
runInAction('update state after fetching data', () => {
this.documents = data;
});
} catch (e) {
console.error('Something went wrong');
}
this.isFetching = false;
};
}
export default StarredDocumentsStore;

View File

@ -0,0 +1,3 @@
// @flow
import Starred from './Starred';
export default Starred;

View File

@ -26,12 +26,15 @@ export type Document = {
html: string,
id: string,
private: boolean,
starred: boolean,
views: number,
team: string,
text: string,
title: string,
updatedAt: string,
updatedBy: User,
url: string,
views: number,
};
export type Pagination = {

View File

@ -4,6 +4,10 @@ export function homeUrl(): string {
return '/dashboard';
}
export function starredUrl(): string {
return '/starred';
}
export function newCollectionUrl(): string {
return '/collections/new';
}

View File

@ -18,7 +18,7 @@
"sequelize:migrate": "sequelize db:migrate",
"test": "npm run test:frontend && npm run test:server",
"test:frontend": "jest",
"test:server": "jest --config=server/.jest-config --runInBand",
"test:server": "jest --config=server/.jestconfig.json --runInBand",
"precommit": "lint-staged"
},
"lint-staged": {
@ -77,6 +77,7 @@
"babel-regenerator-runtime": "6.5.0",
"bcrypt": "^0.8.7",
"boundless-arrow-key-navigation": "^1.0.4",
"boundless-popover": "^1.0.4",
"bugsnag": "^1.7.0",
"classnames": "2.2.3",
"cross-env": "1.0.7",
@ -108,11 +109,11 @@
"json-loader": "0.5.4",
"jsonwebtoken": "7.0.1",
"koa": "^2.2.0",
"koa-bodyparser": "2.0.1",
"koa-bodyparser": "4.2.0",
"koa-compress": "2.0.0",
"koa-connect": "1.0.0",
"koa-convert": "1.2.0",
"koa-helmet": "1.0.0",
"koa-helmet": "3.2.0",
"koa-jwt": "^3.2.1",
"koa-logger": "^2.0.1",
"koa-mount": "^3.0.0",
@ -189,4 +190,4 @@
"react-addons-test-utils": "^15.3.1",
"react-test-renderer": "^15.3.1"
}
}
}

View File

@ -1,6 +1,7 @@
{
"verbose": true,
"testPathDirs": [
"rootDir": "..",
"roots": [
"<rootDir>/server"
],
"setupFiles": [

View File

@ -1,9 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`#auth.login should login with email 1`] = `
Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
"name": "User 1",
"username": "user1"
"username": "user1",
}
`;
@ -12,7 +14,7 @@ Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
"name": "User 1",
"username": "user1"
"username": "user1",
}
`;
@ -21,7 +23,7 @@ Object {
"error": "validation_error",
"message": "username/email is required",
"ok": false,
"status": 400
"status": 400,
}
`;
@ -30,7 +32,7 @@ Object {
"error": "validation_error",
"message": "username/email is required",
"ok": false,
"status": 400
"status": 400,
}
`;
@ -39,7 +41,7 @@ Object {
"error": "validation_error",
"message": "username/email is required",
"ok": false,
"status": 400
"status": 400,
}
`;
@ -48,7 +50,7 @@ Object {
"error": "validation_error",
"message": "name is required",
"ok": false,
"status": 400
"status": 400,
}
`;
@ -57,7 +59,7 @@ Object {
"error": "user_exists_with_email",
"message": "User already exists with this email",
"ok": false,
"status": 400
"status": 400,
}
`;
@ -66,7 +68,7 @@ Object {
"error": "user_exists_with_username",
"message": "User already exists with this username",
"ok": false,
"status": 400
"status": 400,
}
`;
@ -75,6 +77,6 @@ Object {
"error": "validation_error",
"message": "email is invalid",
"ok": false,
"status": 400
"status": 400,
}
`;

View File

@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`#documents.list should require authentication 1`] = `
Object {
"error": "authentication_required",
"message": "Authentication required",
"ok": false,
"status": 401,
}
`;
exports[`#documents.star should require authentication 1`] = `
Object {
"error": "authentication_required",
"message": "Authentication required",
"ok": false,
"status": 401,
}
`;
exports[`#documents.starred should require authentication 1`] = `
Object {
"error": "authentication_required",
"message": "Authentication required",
"ok": false,
"status": 401,
}
`;
exports[`#documents.unstar should require authentication 1`] = `
Object {
"error": "authentication_required",
"message": "Authentication required",
"ok": false,
"status": 401,
}
`;
exports[`#documents.viewed should require authentication 1`] = `
Object {
"error": "authentication_required",
"message": "Authentication required",
"ok": false,
"status": 401,
}
`;

View File

@ -1,9 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`#user.info should require authentication 1`] = `
Object {
"error": "authentication_required",
"message": "Authentication required",
"ok": false,
"status": 401
"status": 401,
}
`;
@ -13,9 +15,9 @@ Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
"name": "User 1",
"username": "user1"
"username": "user1",
},
"ok": true,
"status": 200
"status": 200,
}
`;

View File

@ -1,12 +1,11 @@
import TestServer from 'fetch-test-server';
import app from '..';
import { flushdb, sequelize, seed } from '../test/support';
import { flushdb, seed } from '../test/support';
const server = new TestServer(app.callback());
beforeEach(flushdb);
afterAll(() => server.close());
afterAll(() => sequelize.close());
describe('#auth.signup', async () => {
it('should signup a new user', async () => {

View File

@ -1,46 +1,84 @@
// @flow
import Router from 'koa-router';
import httpErrors from 'http-errors';
import isUUID from 'validator/lib/isUUID';
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
import auth from './middlewares/authentication';
import pagination from './middlewares/pagination';
import { presentDocument } from '../presenters';
import { Document, Collection } from '../models';
import { Document, Collection, Star, View } from '../models';
const router = new Router();
const getDocumentForId = async id => {
try {
let document;
if (isUUID(id)) {
document = await Document.findOne({
where: {
id,
},
});
} else if (id.match(URL_REGEX)) {
document = await Document.findOne({
where: {
urlId: id.match(URL_REGEX)[1],
},
});
} else {
throw httpErrors.NotFound();
}
return document;
} catch (e) {
// Invalid UUID
throw httpErrors.NotFound();
}
};
router.post('documents.list', auth(), pagination(), async ctx => {
let { sort = 'updatedAt', direction } = ctx.body;
if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user;
const documents = await Document.findAll({
where: { teamId: user.teamId },
order: [[sort, direction]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
});
let data = await Promise.all(documents.map(doc => presentDocument(ctx, doc)));
ctx.body = {
pagination: ctx.state.pagination,
data,
};
});
router.post('documents.viewed', auth(), pagination(), async ctx => {
let { sort = 'updatedAt', direction } = ctx.body;
if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user;
const views = await View.findAll({
where: { userId: user.id },
order: [[sort, direction]],
include: [{ model: Document }],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
});
let data = await Promise.all(
views.map(view => presentDocument(ctx, view.document))
);
ctx.body = {
pagination: ctx.state.pagination,
data,
};
});
router.post('documents.starred', auth(), pagination(), async ctx => {
let { sort = 'updatedAt', direction } = ctx.body;
if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user;
const views = await Star.findAll({
where: { userId: user.id },
order: [[sort, direction]],
include: [{ model: Document }],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
});
let data = await Promise.all(
views.map(view => presentDocument(ctx, view.document))
);
ctx.body = {
pagination: ctx.state.pagination,
data,
};
});
// FIXME: This really needs specs :/
router.post('documents.info', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const document = await getDocumentForId(id);
const document = await Document.findById(id);
if (!document) throw httpErrors.NotFound();
@ -52,20 +90,14 @@ router.post('documents.info', auth(), async ctx => {
if (document.teamId !== user.teamId) {
throw httpErrors.NotFound();
}
ctx.body = {
data: await presentDocument(ctx, document, {
includeCollection: true,
includeCollaborators: true,
}),
};
} else {
ctx.body = {
data: await presentDocument(ctx, document, {
includeCollaborators: true,
}),
};
}
ctx.body = {
data: await presentDocument(ctx, document, {
includeCollection: document.private,
includeCollaborators: true,
}),
};
});
router.post('documents.search', auth(), async ctx => {
@ -94,6 +126,34 @@ router.post('documents.search', auth(), async ctx => {
};
});
router.post('documents.star', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = await ctx.state.user;
const document = await Document.findById(id);
if (!document || document.teamId !== user.teamId)
throw httpErrors.BadRequest();
await Star.findOrCreate({
where: { documentId: document.id, userId: user.id },
});
});
router.post('documents.unstar', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = await ctx.state.user;
const document = await Document.findById(id);
if (!document || document.teamId !== user.teamId)
throw httpErrors.BadRequest();
await Star.destroy({
where: { documentId: document.id, userId: user.id },
});
});
router.post('documents.create', auth(), async ctx => {
const { collection, title, text, parentDocument, index } = ctx.body;
ctx.assertPresent(collection, 'collection is required');
@ -154,7 +214,7 @@ router.post('documents.update', auth(), async ctx => {
ctx.assertPresent(title || text, 'title or text is required');
const user = ctx.state.user;
const document = await getDocumentForId(id);
const document = await Document.findById(id);
if (!document || document.teamId !== user.teamId) throw httpErrors.NotFound();
@ -186,13 +246,13 @@ router.post('documents.move', auth(), async ctx => {
if (index) ctx.assertPositiveInteger(index, 'index must be an integer (>=0)');
const user = ctx.state.user;
const document = await getDocumentForId(id);
const document = await Document.findById(id);
if (!document || document.teamId !== user.teamId) throw httpErrors.NotFound();
// Set parent document
if (parentDocument) {
const parent = await getDocumentForId(parentDocument);
const parent = await Document.findById(parentDocument);
if (parent.atlasId !== document.atlasId)
throw httpErrors.BadRequest(
'Invalid parentDocument (must be same collection)'
@ -226,7 +286,7 @@ router.post('documents.delete', auth(), async ctx => {
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await getDocumentForId(id);
const document = await Document.findById(id);
const collection = await Collection.findById(document.atlasId);
if (!document || document.teamId !== user.teamId)
@ -240,7 +300,7 @@ router.post('documents.delete', auth(), async ctx => {
);
}
// Delete all chilren
// Delete all children
try {
await collection.deleteDocument(document);
} catch (e) {

View File

@ -0,0 +1,158 @@
import TestServer from 'fetch-test-server';
import app from '..';
import { View, Star } from '../models';
import { flushdb, seed } from '../test/support';
const server = new TestServer(app.callback());
beforeEach(flushdb);
afterAll(() => server.close());
describe('#documents.list', async () => {
it('should return documents', async () => {
const { user, document } = await seed();
const res = await server.post('/api/documents.list', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(2);
expect(body.data[0].id).toEqual(document.id);
});
it('should allow changing sort direction', async () => {
const { user, document } = await seed();
const res = await server.post('/api/documents.list', {
body: { token: user.getJwtToken(), direction: 'ASC' },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data[1].id).toEqual(document.id);
});
it('should require authentication', async () => {
const res = await server.post('/api/documents.list');
const body = await res.json();
expect(res.status).toEqual(401);
expect(body).toMatchSnapshot();
});
});
describe('#documents.viewed', async () => {
it('should return empty result if no views', async () => {
const { user } = await seed();
const res = await server.post('/api/documents.viewed', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(0);
});
it('should return recently viewed documents', async () => {
const { user, document } = await seed();
await View.increment({ documentId: document.id, userId: user.id });
const res = await server.post('/api/documents.viewed', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].id).toEqual(document.id);
});
it('should require authentication', async () => {
const res = await server.post('/api/documents.viewed');
const body = await res.json();
expect(res.status).toEqual(401);
expect(body).toMatchSnapshot();
});
});
describe('#documents.starred', async () => {
it('should return empty result if no stars', async () => {
const { user } = await seed();
const res = await server.post('/api/documents.starred', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(0);
});
it('should return starred documents', async () => {
const { user, document } = await seed();
await Star.create({ documentId: document.id, userId: user.id });
const res = await server.post('/api/documents.starred', {
body: { token: user.getJwtToken() },
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
expect(body.data[0].id).toEqual(document.id);
});
it('should require authentication', async () => {
const res = await server.post('/api/documents.starred');
const body = await res.json();
expect(res.status).toEqual(401);
expect(body).toMatchSnapshot();
});
});
describe('#documents.star', async () => {
it('should star the document', async () => {
const { user, document } = await seed();
const res = await server.post('/api/documents.star', {
body: { token: user.getJwtToken(), id: document.id },
});
const stars = await Star.findAll();
expect(res.status).toEqual(200);
expect(stars.length).toEqual(1);
expect(stars[0].documentId).toEqual(document.id);
});
it('should require authentication', async () => {
const res = await server.post('/api/documents.star');
const body = await res.json();
expect(res.status).toEqual(401);
expect(body).toMatchSnapshot();
});
});
describe('#documents.unstar', async () => {
it('should unstar the document', async () => {
const { user, document } = await seed();
await Star.create({ documentId: document.id, userId: user.id });
const res = await server.post('/api/documents.unstar', {
body: { token: user.getJwtToken(), id: document.id },
});
const stars = await Star.findAll();
expect(res.status).toEqual(200);
expect(stars.length).toEqual(0);
});
it('should require authentication', async () => {
const res = await server.post('/api/documents.star');
const body = await res.json();
expect(res.status).toEqual(401);
expect(body).toMatchSnapshot();
});
});

View File

@ -8,6 +8,7 @@ import auth from './auth';
import user from './user';
import collections from './collections';
import documents from './documents';
import views from './views';
import hooks from './hooks';
import apiKeys from './apiKeys';
@ -59,6 +60,7 @@ router.use('/', auth.routes());
router.use('/', user.routes());
router.use('/', collections.routes());
router.use('/', documents.routes());
router.use('/', views.routes());
router.use('/', hooks.routes());
router.use('/', apiKeys.routes());

View File

@ -9,7 +9,6 @@ const server = new TestServer(app.callback());
beforeEach(flushdb);
afterAll(() => server.close());
afterAll(() => sequelize.close());
describe('#user.info', async () => {
it('should return known user', async () => {

52
server/api/views.js Normal file
View File

@ -0,0 +1,52 @@
// @flow
import Router from 'koa-router';
import httpErrors from 'http-errors';
import auth from './middlewares/authentication';
import { presentView } from '../presenters';
import { View, Document } from '../models';
const router = new Router();
router.post('views.list', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const views = await View.findAll({
where: {
documentId: id,
},
order: [['updatedAt', 'DESC']],
});
// Collectiones
let users = [];
let count = 0;
await Promise.all(
views.map(async view => {
count = view.count;
return users.push(await presentView(ctx, view));
})
);
ctx.body = {
data: {
users,
count,
},
};
});
router.post('views.create', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await Document.findById(id);
if (!document || document.teamId !== user.teamId)
throw httpErrors.BadRequest();
await View.increment({ documentId: document.id, userId: user.id });
});
export default router;

View File

@ -4,7 +4,7 @@
"dialect": "postgres"
},
"test": {
"use_env_variable": "DATABASE_URL",
"use_env_variable": "DATABASE_URL_TEST",
"dialect": "postgres"
},
"production": {

View File

@ -1,5 +1,5 @@
import compress from 'koa-compress';
import helmet from 'koa-helmet';
import { contentSecurityPolicy } from 'koa-helmet';
import logger from 'koa-logger';
import mount from 'koa-mount';
import Koa from 'koa';
@ -72,7 +72,7 @@ app.use(mount('/api', api));
app.use(mount(routes));
app.use(
helmet.csp({
contentSecurityPolicy({
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'", "'unsafe-inline'"],

View File

@ -1,5 +1,3 @@
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
queryInterface.createTable('apiKeys', {
@ -41,6 +39,6 @@ module.exports = {
},
down: function(queryInterface, Sequelize) {
queryInterface.createTable('apiKeys');
queryInterface.dropTable('apiKeys');
},
};

View File

@ -0,0 +1,40 @@
module.exports = {
up: function(queryInterface, Sequelize) {
queryInterface.createTable('views', {
id: {
type: Sequelize.UUID,
allowNull: false,
primaryKey: true,
},
documentId: {
type: Sequelize.UUID,
allowNull: false,
},
userId: {
type: Sequelize.UUID,
allowNull: false,
},
count: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 1,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
},
});
queryInterface.addIndex('views', ['documentId', 'userId'], {
indicesType: 'UNIQUE',
});
},
down: function(queryInterface, Sequelize) {
queryInterface.removeIndex('views', ['documentId', 'userId']);
queryInterface.dropTable('views');
},
};

View File

@ -0,0 +1,35 @@
module.exports = {
up: function(queryInterface, Sequelize) {
queryInterface.createTable('stars', {
id: {
type: Sequelize.UUID,
allowNull: false,
primaryKey: true,
},
documentId: {
type: Sequelize.UUID,
allowNull: false,
},
userId: {
type: Sequelize.UUID,
allowNull: false,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
},
});
queryInterface.addIndex('stars', ['documentId', 'userId'], {
indicesType: 'UNIQUE',
});
},
down: function(queryInterface, Sequelize) {
queryInterface.removeIndex('stars', ['documentId', 'userId']);
queryInterface.dropTable('stars');
},
};

View File

@ -1,8 +1,8 @@
import { DataTypes, sequelize } from '../sequelize';
import randomstring from 'randomstring';
const Team = sequelize.define(
'team',
const ApiKey = sequelize.define(
'apiKeys',
{
id: {
type: DataTypes.UUID,
@ -30,4 +30,4 @@ const Team = sequelize.define(
}
);
export default Team;
export default ApiKey;

View File

@ -2,8 +2,8 @@
import slug from 'slug';
import randomstring from 'randomstring';
import { DataTypes, sequelize } from '../sequelize';
import _ from 'lodash';
import Document from './Document';
import _ from 'lodash';
slug.defaults.mode = 'rfc3986';
@ -54,6 +54,14 @@ const Collection = sequelize.define(
await collection.save();
},
},
classMethods: {
associate: models => {
Collection.hasMany(models.Document, {
as: 'documents',
foreignKey: 'atlasId',
});
},
},
instanceMethods: {
getUrl() {
// const slugifiedName = slug(this.name);
@ -173,6 +181,4 @@ const Collection = sequelize.define(
}
);
Collection.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' });
export default Collection;

View File

@ -2,21 +2,24 @@
import slug from 'slug';
import _ from 'lodash';
import randomstring from 'randomstring';
import isUUID from 'validator/lib/isUUID';
import { DataTypes, sequelize } from '../sequelize';
import { convertToMarkdown } from '../../frontend/utils/markdown';
import { truncateMarkdown } from '../utils/truncate';
import User from './User';
import Revision from './Revision';
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
slug.defaults.mode = 'rfc3986';
const slugify = text =>
slug(text, {
remove: /[.]/g,
});
const createRevision = async doc => {
const createRevision = doc => {
// Create revision of the current (latest)
await Revision.create({
return Revision.create({
title: doc.title,
text: doc.text,
html: doc.html,
@ -26,10 +29,13 @@ const createRevision = async doc => {
});
};
const documentBeforeSave = async doc => {
const createUrlId = doc => {
return (doc.urlId = doc.urlId || randomstring.generate(10));
};
const beforeSave = async doc => {
doc.html = convertToMarkdown(doc.text);
doc.preview = truncateMarkdown(doc.text, 160);
doc.revisionCount += 1;
// Collaborators
@ -65,7 +71,6 @@ const Document = sequelize.define(
html: DataTypes.TEXT,
preview: DataTypes.TEXT,
revisionCount: { type: DataTypes.INTEGER, defaultValue: 0 },
parentDocumentId: DataTypes.UUID,
createdById: {
type: DataTypes.UUID,
@ -86,13 +91,11 @@ const Document = sequelize.define(
{
paranoid: true,
hooks: {
beforeValidate: doc => {
doc.urlId = doc.urlId || randomstring.generate(10);
},
beforeCreate: documentBeforeSave,
beforeUpdate: documentBeforeSave,
afterCreate: async doc => await createRevision(doc),
afterUpdate: async doc => await createRevision(doc),
beforeValidate: createUrlId,
beforeCreate: beforeSave,
beforeUpdate: beforeSave,
afterCreate: createRevision,
afterUpdate: createRevision,
},
instanceMethods: {
getUrl() {
@ -110,34 +113,47 @@ const Document = sequelize.define(
};
},
},
classMethods: {
associate: models => {
Document.belongsTo(models.User);
},
findById: async id => {
if (isUUID(id)) {
return Document.findOne({
where: { id },
});
} else if (id.match(URL_REGEX)) {
return Document.findOne({
where: {
urlId: id.match(URL_REGEX)[1],
},
});
}
},
searchForUser: (user, query, options = {}) => {
const limit = options.limit || 15;
const offset = options.offset || 0;
const sql = `
SELECT * FROM documents
WHERE "searchVector" @@ plainto_tsquery('english', :query) AND
"teamId" = '${user.teamId}'::uuid AND
"deletedAt" IS NULL
ORDER BY ts_rank(documents."searchVector", plainto_tsquery('english', :query)) DESC
LIMIT :limit OFFSET :offset;
`;
return sequelize.query(sql, {
replacements: {
query,
limit,
offset,
},
model: Document,
});
},
},
}
);
Document.belongsTo(User);
Document.searchForUser = async (user, query, options = {}) => {
const limit = options.limit || 15;
const offset = options.offset || 0;
const sql = `
SELECT * FROM documents
WHERE "searchVector" @@ plainto_tsquery('english', :query) AND
"teamId" = '${user.teamId}'::uuid AND
"deletedAt" IS NULL
ORDER BY ts_rank(documents."searchVector", plainto_tsquery('english', :query)) DESC
LIMIT :limit OFFSET :offset;
`;
const documents = await sequelize.query(sql, {
replacements: {
query,
limit,
offset,
},
model: Document,
});
return documents;
};
export default Document;

23
server/models/Star.js Normal file
View File

@ -0,0 +1,23 @@
// @flow
import { DataTypes, sequelize } from '../sequelize';
const Star = sequelize.define(
'star',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
},
{
classMethods: {
associate: models => {
Star.belongsTo(models.Document);
Star.belongsTo(models.User);
},
},
}
);
export default Star;

View File

@ -1,7 +1,5 @@
import { DataTypes, sequelize } from '../sequelize';
import Collection from './Collection';
import Document from './Document';
import User from './User';
const Team = sequelize.define(
'team',
@ -16,6 +14,13 @@ const Team = sequelize.define(
slackData: DataTypes.JSONB,
},
{
classMethods: {
associate: models => {
Team.hasMany(models.Collection, { as: 'atlases' });
Team.hasMany(models.Document, { as: 'documents' });
Team.hasMany(models.User, { as: 'users' });
},
},
instanceMethods: {
async createFirstCollection(userId) {
const atlas = await Collection.create({
@ -37,8 +42,4 @@ const Team = sequelize.define(
}
);
Team.hasMany(Collection, { as: 'atlases' });
Team.hasMany(Document, { as: 'documents' });
Team.hasMany(User, { as: 'users' });
export default Team;

View File

@ -26,6 +26,14 @@ const User = sequelize.define(
jwtSecret: encryptedFields.vault('jwtSecret'),
},
{
classMethods: {
associate: models => {
User.hasMany(models.ApiKey, { as: 'apiKeys' });
User.hasMany(models.Collection, { as: 'collections' });
User.hasMany(models.Document, { as: 'documents' });
User.hasMany(models.View, { as: 'views' });
},
},
instanceMethods: {
getJwtToken() {
return JWT.sign({ id: this.id }, this.jwtSecret);

View File

@ -3,7 +3,6 @@ import { User } from '.';
import { flushdb, sequelize } from '../test/support';
beforeEach(flushdb);
afterAll(() => sequelize.close());
it('should set JWT secret and password digest', async () => {
const user = User.build({

35
server/models/View.js Normal file
View File

@ -0,0 +1,35 @@
// @flow
import { DataTypes, sequelize } from '../sequelize';
const View = sequelize.define(
'view',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
count: {
type: DataTypes.INTEGER,
defaultValue: 1,
},
},
{
classMethods: {
associate: models => {
View.belongsTo(models.Document);
View.belongsTo(models.User);
},
increment: async where => {
const [model, created] = await View.findOrCreate({ where });
if (!created) {
model.count += 1;
model.save();
}
return model;
},
},
}
);
export default View;

View File

@ -1,8 +1,29 @@
// @flow
import User from './User';
import Team from './Team';
import Collection from './Collection';
import Document from './Document';
import Revision from './Revision';
import ApiKey from './ApiKey';
import View from './View';
import Star from './Star';
export { User, Team, Collection, Document, Revision, ApiKey };
const models = {
User,
Team,
Collection,
Document,
Revision,
ApiKey,
View,
Star,
};
// based on https://github.com/sequelize/express-example/blob/master/models/index.js
Object.keys(models).forEach(modelName => {
if ('associate' in models[modelName]) {
models[modelName].associate(models);
}
});
export { User, Team, Collection, Document, Revision, ApiKey, View, Star };

View File

@ -1,17 +1,19 @@
exports[`test presents a user 1`] = `
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`presents a user 1`] = `
Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "123",
"name": "Test User",
"username": "testuser"
"username": "testuser",
}
`;
exports[`test presents a user without slack data 1`] = `
exports[`presents a user without slack data 1`] = `
Object {
"avatarUrl": null,
"id": "123",
"name": "Test User",
"username": "testuser"
"username": "testuser",
}
`;

View File

@ -0,0 +1,9 @@
function present(ctx, key) {
return {
id: key.id,
name: key.name,
secret: key.secret,
};
}
export default present;

View File

@ -0,0 +1,46 @@
import _ from 'lodash';
import { Document } from '../models';
import presentDocument from './document';
async function present(ctx, collection, includeRecentDocuments = false) {
ctx.cache.set(collection.id, collection);
const data = {
id: collection.id,
url: collection.getUrl(),
name: collection.name,
description: collection.description,
type: collection.type,
createdAt: collection.createdAt,
updatedAt: collection.updatedAt,
};
if (collection.type === 'atlas')
data.navigationTree = collection.navigationTree;
if (includeRecentDocuments) {
const documents = await Document.findAll({
where: {
atlasId: collection.id,
},
limit: 10,
order: [['updatedAt', 'DESC']],
});
const recentDocuments = [];
await Promise.all(
documents.map(async document => {
recentDocuments.push(
await presentDocument(ctx, document, {
includeCollaborators: true,
})
);
})
);
data.recentDocuments = _.orderBy(recentDocuments, ['updatedAt'], ['desc']);
}
return data;
}
export default present;

View File

@ -1,27 +1,17 @@
import _ from 'lodash';
import { Document, Collection, User } from './models';
import { Collection, Star, User, View } from '../models';
import presentUser from './user';
import presentCollection from './collection';
import presentUser from './presenters/user';
export { presentUser };
export async function presentTeam(ctx, team) {
ctx.cache.set(team.id, team);
return {
id: team.id,
name: team.name,
};
}
export async function presentDocument(ctx, document, options) {
async function present(ctx, document, options) {
options = {
includeCollection: true,
includeCollaborators: true,
includeViews: true,
...options,
};
ctx.cache.set(document.id, document);
const userId = ctx.state.user.id;
const data = {
id: document.id,
url: document.getUrl(),
@ -38,6 +28,16 @@ export async function presentDocument(ctx, document, options) {
collaborators: [],
};
data.starred = !!await Star.findOne({
where: { documentId: document.id, userId },
});
if (options.includeViews) {
data.views = await View.sum('count', {
where: { documentId: document.id },
});
}
if (options.includeCollection) {
data.collection = await ctx.cache.get(document.atlasId, async () => {
const collection =
@ -77,56 +77,4 @@ export async function presentDocument(ctx, document, options) {
return data;
}
export async function presentCollection(
ctx,
collection,
includeRecentDocuments = false
) {
ctx.cache.set(collection.id, collection);
const data = {
id: collection.id,
url: collection.getUrl(),
name: collection.name,
description: collection.description,
type: collection.type,
createdAt: collection.createdAt,
updatedAt: collection.updatedAt,
};
if (collection.type === 'atlas') {
data.documents = await collection.getDocumentsStructure();
}
if (includeRecentDocuments) {
const documents = await Document.findAll({
where: {
atlasId: collection.id,
},
limit: 10,
order: [['updatedAt', 'DESC']],
});
const recentDocuments = [];
await Promise.all(
documents.map(async document => {
recentDocuments.push(
await presentDocument(ctx, document, {
includeCollaborators: true,
})
);
})
);
data.recentDocuments = _.orderBy(recentDocuments, ['updatedAt'], ['desc']);
}
return data;
}
export function presentApiKey(ctx, key) {
return {
id: key.id,
name: key.name,
secret: key.secret,
};
}
export default present;

View File

@ -0,0 +1,16 @@
// @flow
import presentUser from './user';
import presentView from './view';
import presentDocument from './document';
import presentCollection from './collection';
import presentApiKey from './apiKey';
import presentTeam from './team';
export {
presentUser,
presentView,
presentDocument,
presentCollection,
presentApiKey,
presentTeam,
};

10
server/presenters/team.js Normal file
View File

@ -0,0 +1,10 @@
function present(ctx, team) {
ctx.cache.set(team.id, team);
return {
id: team.id,
name: team.name,
};
}
export default present;

View File

@ -1,7 +1,7 @@
// @flow
import User from '../models/User';
async function presentUser(ctx: Object, user: User) {
function present(ctx: Object, user: User) {
ctx.cache.set(user.id, user);
return {
@ -12,4 +12,4 @@ async function presentUser(ctx: Object, user: User) {
};
}
export default presentUser;
export default present;

18
server/presenters/view.js Normal file
View File

@ -0,0 +1,18 @@
// @flow
import { View, User } from '../models';
import { presentUser } from '../presenters';
async function present(ctx: Object, view: View) {
let data = {
count: view.count,
user: undefined,
};
const user = await ctx.cache.get(
view.userId,
async () => await User.findById(view.userId)
);
data.user = await presentUser(ctx, user);
return data;
}
export default present;

View File

@ -1,8 +1,10 @@
// @flow
import Sequelize from 'sequelize';
import EncryptedField from 'sequelize-encrypted';
import debug from 'debug';
const secretKey = process.env.SEQUELIZE_SECRET;
export const encryptedFields = EncryptedField(Sequelize, secretKey);
export const DataTypes = Sequelize;

View File

@ -21,9 +21,7 @@ function runMigrations() {
path: './server/migrations',
},
});
return umzug.up().then(() => {
return sequelize.close();
});
return umzug.up();
}
runMigrations();

View File

@ -1,4 +1,5 @@
import { User } from '../models';
// @flow
import { User, Document, Collection, Team } from '../models';
import { sequelize } from '../sequelize';
export function flushdb() {
@ -6,23 +7,61 @@ export function flushdb() {
const tables = Object.keys(sequelize.models).map(model =>
sql.quoteTable(sequelize.models[model].getTableName())
);
const query = `TRUNCATE ${tables.join(', ')} CASCADE`;
const query = `TRUNCATE ${tables.join(', ')} CASCADE`;
return sequelize.query(query);
}
const seed = async () => {
await User.create({
const team = await Team.create({
id: '86fde1d4-0050-428f-9f0b-0bf77f8bdf61',
name: 'Team',
slackId: 'T2399UF2P',
slackData: {
id: 'T2399UF2P',
},
});
const user = await User.create({
id: '86fde1d4-0050-428f-9f0b-0bf77f8bdf61',
email: 'user1@example.com',
username: 'user1',
name: 'User 1',
password: 'test123!',
slackId: '123',
teamId: team.id,
slackId: 'U2399UF2P',
slackData: {
id: 'U2399UF2P',
image_192: 'http://example.com/avatar.png',
},
});
const collection = await Collection.create({
id: '86fde1d4-0050-428f-9f0b-0bf77f8bdf61',
name: 'Collection',
urlId: 'collection',
teamId: team.id,
creatorId: user.id,
type: 'atlas',
});
const document = await Document.create({
parentDocumentId: null,
atlasId: collection.id,
teamId: collection.teamId,
userId: collection.creatorId,
lastModifiedById: collection.creatorId,
createdById: collection.creatorId,
title: 'Introduction',
text: '# Introduction\n\nLets get started...',
});
return {
user,
collection,
document,
team,
};
};
export { seed, sequelize };

282
yarn.lock
View File

@ -1094,10 +1094,39 @@ boundless-arrow-key-navigation@^1.0.4:
boundless-utils-omit-keys "^1.0.4"
boundless-utils-uuid "^1.0.4"
boundless-dialog@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/boundless-dialog/-/boundless-dialog-1.0.4.tgz#630717ba82f5dd1f7b9a07e6aeedbe511630d42a"
dependencies:
boundless-portal "^1.0.4"
boundless-utils-omit-keys "^1.0.4"
classnames "^2.1.5"
boundless-popover@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/boundless-popover/-/boundless-popover-1.0.4.tgz#20d0d36ffbb20247425ac4271e521c43f7beb90e"
dependencies:
boundless-dialog "^1.0.4"
boundless-portal "^1.0.4"
boundless-utils-omit-keys "^1.0.4"
boundless-utils-transform-property "^1.0.4"
classnames "^2.1.5"
boundless-portal@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/boundless-portal/-/boundless-portal-1.0.4.tgz#d2bec81a20d3c47428f3da8d0d19c8e778f72768"
dependencies:
boundless-utils-omit-keys "^1.0.4"
boundless-utils-uuid "^1.0.4"
boundless-utils-omit-keys@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/boundless-utils-omit-keys/-/boundless-utils-omit-keys-1.0.4.tgz#95b9bb03e0a80ff26d8a3c95c1ed5e95daf8465b"
boundless-utils-transform-property@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/boundless-utils-transform-property/-/boundless-utils-transform-property-1.0.4.tgz#048dad7bfd95eda9fb4cd744f3a7a936a2b705bc"
boundless-utils-uuid@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/boundless-utils-uuid/-/boundless-utils-uuid-1.0.4.tgz#d125a0d45cf79fac84e517ea549765a4bbe1ebb6"
@ -1451,7 +1480,7 @@ clap@^1.0.9:
dependencies:
chalk "^1.1.3"
classnames@2.2.3:
classnames@2.2.3, classnames@^2.1.5:
version "2.2.3"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.3.tgz#551b774b6762a0c0a997187f7ba4f1d603961ac5"
@ -1541,13 +1570,14 @@ clone@^1.0.0, clone@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.2.tgz#260b7a99ebb1edfe247538175f783243cb19d149"
co-body@~3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/co-body/-/co-body-3.1.0.tgz#1d8b2fc8b30faa4df5643d8243a6caab631387ba"
co-body@^5.1.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/co-body/-/co-body-5.1.1.tgz#d97781d1e3344ba4a820fd1806bddf8341505236"
dependencies:
qs "~4.0.0"
raw-body "~2.1.2"
type-is "~1.6.6"
inflation "^2.0.0"
qs "^6.4.0"
raw-body "^2.2.0"
type-is "^1.6.14"
co@^4.6.0:
version "4.6.0"
@ -1691,12 +1721,12 @@ connect-timeout@~1.6.2:
ms "0.7.1"
on-headers "~1.0.0"
connect@3.4.1:
version "3.4.1"
resolved "https://registry.yarnpkg.com/connect/-/connect-3.4.1.tgz#a21361d3f4099ef761cda6dc4a973bb1ebb0a34d"
connect@3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/connect/-/connect-3.6.2.tgz#694e8d20681bfe490282c8ab886be98f09f42fe7"
dependencies:
debug "~2.2.0"
finalhandler "0.4.1"
debug "2.6.7"
finalhandler "1.0.3"
parseurl "~1.3.1"
utils-merge "1.0.0"
@ -1769,9 +1799,9 @@ content-disposition@~0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.1.tgz#87476c6a67c8daa87e32e87616df883ba7fb071b"
content-security-policy-builder@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/content-security-policy-builder/-/content-security-policy-builder-1.0.0.tgz#11fd40c5cc298a6c725a35f9acf71e82ab5d3243"
content-security-policy-builder@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/content-security-policy-builder/-/content-security-policy-builder-1.1.0.tgz#d91f1b076236c119850c7dee9924bf55e05772b3"
dependencies:
dashify "^0.2.0"
@ -1813,7 +1843,7 @@ cookies@~0.7.0:
depd "~1.1.0"
keygrip "~1.0.1"
copy-to@~2.0.1:
copy-to@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/copy-to/-/copy-to-2.0.1.tgz#2680fbb8068a48d08656b6098092bdafc906f4a5"
@ -2089,6 +2119,10 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"
dasherize@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dasherize/-/dasherize-2.0.0.tgz#6d809c9cd0cf7bb8952d80fc84fa13d47ddb1308"
dashify@^0.2.0:
version "0.2.2"
resolved "https://registry.yarnpkg.com/dashify/-/dashify-0.2.2.tgz#6a07415a01c91faf4a32e38d9dfba71f61cb20fe"
@ -2132,6 +2166,12 @@ debug@*, debug@2.2.0, debug@^2.1.1, debug@^2.2.0, debug@~2.2.0:
dependencies:
ms "0.7.1"
debug@2.6.7:
version "2.6.7"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.7.tgz#92bad1f6d05bbb6bba22cca88bcd0ec894c2861e"
dependencies:
ms "2.0.0"
debug@^2.3.2, debug@^2.6.1, debug@^2.6.3:
version "2.6.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.4.tgz#7586a9b3c39741c0282ae33445c4e8ac74734fe0"
@ -2440,6 +2480,10 @@ emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
encodeurl@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20"
encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
@ -2904,6 +2948,10 @@ expand-tilde@^1.2.1, expand-tilde@^1.2.2:
dependencies:
os-homedir "^1.0.1"
expect-ct@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/expect-ct/-/expect-ct-0.1.0.tgz#52735678de18530890d8d7b95f0ac63640958094"
exports-loader@0.6.3:
version "0.6.3"
resolved "https://registry.yarnpkg.com/exports-loader/-/exports-loader-0.6.3.tgz#57dc78917f709b96f247fa91e69b554c855013c8"
@ -3069,13 +3117,16 @@ finalhandler@0.4.0:
on-finished "~2.3.0"
unpipe "~1.0.0"
finalhandler@0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-0.4.1.tgz#85a17c6c59a94717d262d61230d4b0ebe3d4a14d"
finalhandler@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.0.3.tgz#ef47e77950e999780e86022a560e3217e0d0cc89"
dependencies:
debug "~2.2.0"
debug "2.6.7"
encodeurl "~1.0.1"
escape-html "~1.0.3"
on-finished "~2.3.0"
parseurl "~1.3.1"
statuses "~1.3.1"
unpipe "~1.0.0"
find-index@^0.1.1:
@ -3207,11 +3258,9 @@ form-data@~2.1.1:
combined-stream "^1.0.5"
mime-types "^2.1.12"
frameguard@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/frameguard/-/frameguard-1.1.0.tgz#e5de5e3ecb17ff84b697300b0e0d748a7d09047b"
dependencies:
lodash.isstring "4.0.1"
frameguard@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/frameguard/-/frameguard-3.0.0.tgz#7bcad469ee7b96e91d12ceb3959c78235a9272e9"
fresh@0.3.0:
version "0.3.0"
@ -3695,32 +3744,32 @@ header-case@^1.0.0:
no-case "^2.2.0"
upper-case "^1.1.3"
helmet-csp@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/helmet-csp/-/helmet-csp-1.1.0.tgz#558b23003fe786ff498d959e96ef2a91ecb35c82"
helmet-csp@2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/helmet-csp/-/helmet-csp-2.4.0.tgz#7e53a157167a0645aadd7177d12ae6c605c1842e"
dependencies:
camelize "1.0.0"
content-security-policy-builder "1.0.0"
lodash.assign "4.0.4"
lodash.isfunction "3.0.8"
lodash.reduce "4.2.0"
lodash.some "4.2.0"
platform "1.3.1"
content-security-policy-builder "1.1.0"
dasherize "2.0.0"
lodash.reduce "4.6.0"
platform "1.3.3"
helmet@^1.0.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/helmet/-/helmet-1.3.0.tgz#e1b59c5484f7ac081a48cc7634139b4ec38cf8b5"
helmet@^3.6.1:
version "3.6.1"
resolved "https://registry.yarnpkg.com/helmet/-/helmet-3.6.1.tgz#91f3aa7fa4c94671595fb568dfd8c28489a388be"
dependencies:
connect "3.4.1"
connect "3.6.2"
dns-prefetch-control "0.1.0"
dont-sniff-mimetype "1.0.0"
frameguard "1.1.0"
helmet-csp "1.1.0"
expect-ct "0.1.0"
frameguard "3.0.0"
helmet-csp "2.4.0"
hide-powered-by "1.0.0"
hpkp "1.1.0"
hsts "1.0.0"
hpkp "2.0.0"
hsts "2.0.0"
ienoopen "1.0.0"
nocache "1.0.0"
nocache "2.0.0"
referrer-policy "1.1.0"
x-xss-protection "1.0.0"
hide-powered-by@1.0.0:
@ -3768,13 +3817,13 @@ hosted-git-info@^2.1.4:
version "2.1.5"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.1.5.tgz#0ba81d90da2e25ab34a332e6ec77936e1598118b"
hpkp@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/hpkp/-/hpkp-1.1.0.tgz#77bdff1f331847fb9f40839d00a45032baed4df4"
hpkp@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/hpkp/-/hpkp-2.0.0.tgz#10e142264e76215a5d30c44ec43de64dee6d1672"
hsts@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hsts/-/hsts-1.0.0.tgz#98e1039ef7aba554057b6b0e32584c0b1143a414"
hsts@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/hsts/-/hsts-2.0.0.tgz#a52234c6070decf214b2b6b70bb144d07e4776c7"
dependencies:
core-util-is "1.0.2"
@ -3895,6 +3944,10 @@ iconv-lite@0.4.13, iconv-lite@~0.4.13:
version "0.4.13"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
iconv-lite@0.4.15:
version "0.4.15"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.15.tgz#fe265a218ac6a57cfe854927e9d04c19825eddeb"
icss-replace-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.0.2.tgz#cb0b6054eb3af6edc9ab1d62d01933e2d4c8bfa5"
@ -3982,6 +4035,10 @@ infinity-agent@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/infinity-agent/-/infinity-agent-2.0.3.tgz#45e0e2ff7a9eb030b27d62b74b3744b7a7ac4216"
inflation@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/inflation/-/inflation-2.0.0.tgz#8b417e47c28f925a45133d914ca1fd389107f30f"
inflection@^1.6.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.10.0.tgz#5bffcb1197ad3e81050f8e17e21668087ee9eb2f"
@ -4853,12 +4910,12 @@ klaw@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.0.tgz#8857bfbc1d824badf13d3d0241d8bbe46fb12f73"
koa-bodyparser@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/koa-bodyparser/-/koa-bodyparser-2.0.1.tgz#f9ba408eb946e257cfce17daf8c765c58755de72"
koa-bodyparser@4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/koa-bodyparser/-/koa-bodyparser-4.2.0.tgz#bce6e08bc65f8709b6d1faa9411c7f0d8938aa54"
dependencies:
co-body "~3.1.0"
copy-to "~2.0.1"
co-body "^5.1.0"
copy-to "^2.0.1"
koa-compose@^3.0.0:
version "3.1.0"
@ -4894,11 +4951,11 @@ koa-convert@1.2.0, koa-convert@^1.2.0:
co "^4.6.0"
koa-compose "^3.0.0"
koa-helmet@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/koa-helmet/-/koa-helmet-1.0.0.tgz#065d19ef41717298701367eac02d318230858d8d"
koa-helmet@3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/koa-helmet/-/koa-helmet-3.2.0.tgz#5b5e43f48dea894891c2b29990eb075eacf40197"
dependencies:
helmet "^1.0.1"
helmet "^3.6.1"
koa-is-json@^1.0.0:
version "1.0.0"
@ -5151,7 +5208,7 @@ lodash._basecopy@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36"
lodash._baseeach@^4.0.0, lodash._baseeach@~4.1.0:
lodash._baseeach@~4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/lodash._baseeach/-/lodash._baseeach-4.1.3.tgz#ca4984edc849c237b283fbe2ea7cf76d37fc9d67"
@ -5163,16 +5220,12 @@ lodash._baseget@^3.0.0:
version "3.7.2"
resolved "https://registry.yarnpkg.com/lodash._baseget/-/lodash._baseget-3.7.2.tgz#1b6ae1d5facf3c25532350a13c1197cb8bb674f4"
lodash._baseiteratee@^4.0.0, lodash._baseiteratee@~4.7.0:
lodash._baseiteratee@~4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash._baseiteratee/-/lodash._baseiteratee-4.7.0.tgz#34a9b5543572727c3db2e78edae3c0e9e66bd102"
dependencies:
lodash._stringtopath "~4.8.0"
lodash._basereduce@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._basereduce/-/lodash._basereduce-3.0.2.tgz#13fb98fbde162083a0c967f0605c32acfbb270b2"
lodash._basetostring@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz#d1861d877f824a52f669832dcaf3ee15566a07d5"
@ -5240,13 +5293,6 @@ lodash._topath@^3.0.0:
dependencies:
lodash.isarray "^3.0.0"
lodash.assign@4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.0.4.tgz#9d34aa2c7763e6f7dd7c25808d41813f3da09313"
dependencies:
lodash.keys "^4.0.0"
lodash.rest "^4.0.0"
lodash.assign@^3.0.0, lodash.assign@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-3.2.0.tgz#3ce9f0234b4b2223e296b8fa0ac1fee8ebca64fa"
@ -5350,10 +5396,6 @@ lodash.isempty@^4.2.1:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e"
lodash.isfunction@3.0.8:
version "3.0.8"
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.8.tgz#4db709fc81bc4a8fd7127a458a5346c5cdce2c6b"
lodash.isnil@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isnil/-/lodash.isnil-4.0.0.tgz#49e28cd559013458c814c5479d3c663a21bfaa6c"
@ -5362,7 +5404,7 @@ lodash.isplainobject@^4.0.4, lodash.isplainobject@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
lodash.isstring@4.0.1, lodash.isstring@^4.0.1:
lodash.isstring@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
@ -5374,10 +5416,6 @@ lodash.keys@^3.0.0, lodash.keys@^3.1.2:
lodash.isarguments "^3.0.0"
lodash.isarray "^3.0.0"
lodash.keys@^4.0.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-4.2.0.tgz#a08602ac12e4fb83f91fc1fb7a360a4d9ba35205"
lodash.map@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3"
@ -5417,15 +5455,7 @@ lodash.range@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/lodash.range/-/lodash.range-3.2.0.tgz#f461e588f66683f7eadeade513e38a69a565a15d"
lodash.reduce@4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.reduce/-/lodash.reduce-4.2.0.tgz#ff50805bd84104229106c92cf050417d5c73d025"
dependencies:
lodash._baseeach "^4.0.0"
lodash._baseiteratee "^4.0.0"
lodash._basereduce "^3.0.0"
lodash.reduce@^4.4.0:
lodash.reduce@4.6.0, lodash.reduce@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.reduce/-/lodash.reduce-4.6.0.tgz#f1ab6b839299ad48f784abbf476596f03b914d3b"
@ -5433,21 +5463,10 @@ lodash.reject@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.reject/-/lodash.reject-4.6.0.tgz#80d6492dc1470864bbf583533b651f42a9f52415"
lodash.rest@^4.0.0:
version "4.0.5"
resolved "https://registry.yarnpkg.com/lodash.rest/-/lodash.rest-4.0.5.tgz#954ef75049262038c96d1fc98b28fdaf9f0772aa"
lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
lodash.some@4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.some/-/lodash.some-4.2.0.tgz#cb44c3b0d375d56031da17a29b61e886b1e1c9f9"
dependencies:
lodash._baseeach "^4.0.0"
lodash._baseiteratee "^4.0.0"
lodash.some@^4.4.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.some/-/lodash.some-4.6.0.tgz#1bb9f314ef6b8baded13b549169b2a945eb68e4d"
@ -5741,12 +5760,22 @@ miller-rabin@^4.0.0:
version "1.24.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.24.0.tgz#e2d13f939f0016c6e4e9ad25a8652f126c467f0c"
mime-types@^2.0.7, mime-types@^2.1.11, mime-types@^2.1.12, mime-types@~2.1.11, mime-types@~2.1.6, mime-types@~2.1.7, mime-types@~2.1.9:
mime-db@~1.27.0:
version "1.27.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.27.0.tgz#820f572296bbd20ec25ed55e5b5de869e5436eb1"
mime-types@^2.0.7, mime-types@^2.1.11, mime-types@~2.1.11, mime-types@~2.1.7:
version "2.1.12"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.12.tgz#152ba256777020dd4663f54c2e7bc26381e71729"
dependencies:
mime-db "~1.24.0"
mime-types@^2.1.12, mime-types@~2.1.15, mime-types@~2.1.6, mime-types@~2.1.9:
version "2.1.15"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.15.tgz#a4ebf5064094569237b8cf70046776d09fc92aed"
dependencies:
mime-db "~1.27.0"
mime@1.2.x, mime@^1.2.11:
version "1.2.11"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.2.11.tgz#58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10"
@ -5840,6 +5869,10 @@ ms@0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.3.tgz#708155a5e44e33f5fd0fc53e81d0d40a91be1fff"
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
multiparty@3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/multiparty/-/multiparty-3.3.2.tgz#35de6804dc19643e5249f3d3e3bdc6c8ce301d3f"
@ -5907,9 +5940,9 @@ no-case@^2.2.0:
dependencies:
lower-case "^1.1.1"
nocache@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/nocache/-/nocache-1.0.0.tgz#32065ef85f6e62a014542c2b2baf11bb3704df21"
nocache@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/nocache/-/nocache-2.0.0.tgz#202b48021a0c4cbde2df80de15a17443c8b43980"
node-dev@3.1.0:
version "3.1.0"
@ -6622,9 +6655,9 @@ pkg-up@^1.0.0:
dependencies:
find-up "^1.0.0"
platform@1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.1.tgz#492210892335bd3131c0a08dda2d93ec3543e423"
platform@1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.3.tgz#646c77011899870b6a0903e75e997e8e51da7461"
pluralize@^1.2.1:
version "1.2.1"
@ -7019,18 +7052,18 @@ q@^1.1.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.4.1.tgz#55705bcd93c5f3673530c2c2cbc0c2b3addc286e"
qs@4.0.0, qs@~4.0.0:
qs@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-4.0.0.tgz#c31d9b74ec27df75e543a86c78728ed8d4623607"
qs@^6.4.0, qs@~6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"
qs@~6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.1.tgz#ce03c5ff0935bc1d9d69a9f14cbd18e568d67625"
qs@~6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"
query-string@^4.1.0, query-string@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
@ -7071,6 +7104,14 @@ range-parser@^1.0.3, range-parser@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.0.3.tgz#6872823535c692e2c2a0103826afd82c2e0ff175"
raw-body@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.2.0.tgz#994976cf6a5096a41162840492f0bdc5d6e7fb96"
dependencies:
bytes "2.4.0"
iconv-lite "0.4.15"
unpipe "1.0.0"
raw-body@~2.1.2:
version "2.1.7"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.1.7.tgz#adfeace2e4fb3098058014d08c072dcc59758774"
@ -7348,6 +7389,10 @@ reduce-function-call@^1.0.1:
dependencies:
balanced-match "~0.1.0"
referrer-policy@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/referrer-policy/-/referrer-policy-1.1.0.tgz#35774eb735bf50fb6c078e83334b472350207d79"
reflexbox@^2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/reflexbox/-/reflexbox-2.2.3.tgz#9b9ce983dbe677cebf3a94cf2c50b8157f50c0d1"
@ -8083,6 +8128,10 @@ statuses@~1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.2.1.tgz#dded45cc18256d51ed40aec142489d5c61026d28"
statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
stdout-stream@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/stdout-stream/-/stdout-stream-1.4.0.tgz#a2c7c8587e54d9427ea9edb3ac3f2cd522df378b"
@ -8510,13 +8559,20 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"
type-is@^1.5.5, type-is@~1.6.6:
type-is@^1.5.5:
version "1.6.13"
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.13.tgz#6e83ba7bc30cd33a7bb0b7fb00737a2085bf9d08"
dependencies:
media-typer "0.3.0"
mime-types "~2.1.11"
type-is@^1.6.14, type-is@~1.6.6:
version "1.6.15"
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
dependencies:
media-typer "0.3.0"
mime-types "~2.1.15"
type-of@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/type-of/-/type-of-2.0.1.tgz#e72a1741896568e9f628378d816d6912f7f23972"