Skip to content

Commit

Permalink
Refactor shallot out to separate modules (#203)
Browse files Browse the repository at this point in the history
* Refactor shallot out to separate modules

* Fix style issues
  • Loading branch information
baileytincher authored Apr 30, 2021
1 parent 80fc22f commit d794529
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 187 deletions.
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Become a sponsor and we'll add your logo to our README and link to you on our we
- [Jeff Taylor-Chang](https://github.com/jtaylorchang)
- [Bailey Tincher](https://github.com/baileytincher)


## License

`@actually-colab/editor` is [BUSL-1.1 licensed](https://github.com/actually-colab/editor/blob/main/LICENSE)
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"add:types": "yarn add --dev file:../types"
},
"dependencies": {
"@shallot/aws": "^1.0.6",
"@shallot/aws-websocket-wrapper": "^1.0.7",
"@shallot/http-error-handler": "^1.0.2",
"@shallot/rest-wrapper": "^1.1.3",
"aws-sdk": "^2.842.0",
Expand All @@ -38,7 +40,6 @@
"knex": "^0.21.17",
"nodemailer": "^6.5.0",
"pg": "^8.5.1",
"shallot": "^1.2.2",
"uuid": "^8.3.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion server/src/authorizer/lambda-authorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
import { DUser } from '@actually-colab/editor-types';

import { getUserFromBearerToken } from './token';
import { ShallotAWS } from 'shallot';
import ShallotAWS from '@shallot/aws';

const generatePolicy = (
principalId: string,
Expand Down
10 changes: 6 additions & 4 deletions server/src/socket/cell/create-cell.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { DCell } from '@actually-colab/editor-types';
import type { DCell, DUser } from '@actually-colab/editor-types';

import createHttpError from 'http-errors';

import ShallotSocketWrapper, {
ShallotRawHandler,
TShallotSocketEvent,
} from '../middleware/wrapper';
} from '@shallot/aws-websocket-wrapper';
import ShallotSocketAuthorizer from '../middleware/custom/authorizer';

import { broadcastToNotebook } from '../client-management';
import { getActiveSessionById } from '../../db/pgsql/models/ActiveSession';
Expand All @@ -22,7 +23,8 @@ type TCreateCellEvent = TShallotSocketEvent<
undefined,
undefined,
undefined,
TCreateCellEventBody
TCreateCellEventBody,
DUser
>;

const _handler: ShallotRawHandler<TCreateCellEvent> = async ({
Expand Down Expand Up @@ -55,4 +57,4 @@ const _handler: ShallotRawHandler<TCreateCellEvent> = async ({

export const handler = ShallotSocketWrapper(_handler, undefined, {
HttpErrorHandlerOpts: { catchAllErrors: true },
});
}).use(ShallotSocketAuthorizer());
10 changes: 6 additions & 4 deletions server/src/socket/cell/edit-cell.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { DCell } from '@actually-colab/editor-types';
import type { DCell, DUser } from '@actually-colab/editor-types';

import createHttpError from 'http-errors';

import ShallotSocketWrapper, {
ShallotRawHandler,
TShallotSocketEvent,
} from '../middleware/wrapper';
} from '@shallot/aws-websocket-wrapper';
import ShallotSocketAuthorizer from '../middleware/custom/authorizer';

import { broadcastToNotebook } from '../client-management';

Expand All @@ -24,7 +25,8 @@ type TEditCellEvent = TShallotSocketEvent<
undefined,
undefined,
undefined,
TEditCellEventBody
TEditCellEventBody,
DUser
>;

const _handler: ShallotRawHandler<TEditCellEvent> = async ({ requestContext, body }) => {
Expand Down Expand Up @@ -68,4 +70,4 @@ const _handler: ShallotRawHandler<TEditCellEvent> = async ({ requestContext, bod

export const handler = ShallotSocketWrapper(_handler, undefined, {
HttpErrorHandlerOpts: { catchAllErrors: true },
});
}).use(ShallotSocketAuthorizer());
10 changes: 6 additions & 4 deletions server/src/socket/cell/lock-cell.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DCell } from '@actually-colab/editor-types';
import { DCell, DUser } from '@actually-colab/editor-types';

import createHttpError from 'http-errors';

import ShallotSocketWrapper, {
ShallotRawHandler,
TShallotSocketEvent,
} from '../middleware/wrapper';
} from '@shallot/aws-websocket-wrapper';
import ShallotSocketAuthorizer from '../middleware/custom/authorizer';

import { broadcastToNotebook } from '../client-management';

Expand All @@ -23,7 +24,8 @@ type TLockCellEvent = TShallotSocketEvent<
undefined,
undefined,
undefined,
TLockCellEventBody
TLockCellEventBody,
DUser
>;

const _handler: ShallotRawHandler<TLockCellEvent> = async ({ requestContext, body }) => {
Expand Down Expand Up @@ -53,4 +55,4 @@ const _handler: ShallotRawHandler<TLockCellEvent> = async ({ requestContext, bod

export const handler = ShallotSocketWrapper(_handler, undefined, {
HttpErrorHandlerOpts: { catchAllErrors: true },
});
}).use(ShallotSocketAuthorizer());
10 changes: 6 additions & 4 deletions server/src/socket/cell/unlock-cell.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DCell } from '@actually-colab/editor-types';
import { DCell, DUser } from '@actually-colab/editor-types';

import createHttpError from 'http-errors';

import ShallotSocketWrapper, {
ShallotRawHandler,
TShallotSocketEvent,
} from '../middleware/wrapper';
} from '@shallot/aws-websocket-wrapper';
import ShallotSocketAuthorizer from '../middleware/custom/authorizer';

import { broadcastToNotebook } from '../client-management';

Expand All @@ -23,7 +24,8 @@ type TUnlockCellEvent = TShallotSocketEvent<
undefined,
undefined,
undefined,
TUnlockCellEventBody
TUnlockCellEventBody,
DUser
>;

const _handler: ShallotRawHandler<TUnlockCellEvent> = async ({
Expand Down Expand Up @@ -56,4 +58,4 @@ const _handler: ShallotRawHandler<TUnlockCellEvent> = async ({

export const handler = ShallotSocketWrapper(_handler, undefined, {
HttpErrorHandlerOpts: { catchAllErrors: true },
});
}).use(ShallotSocketAuthorizer());
10 changes: 6 additions & 4 deletions server/src/socket/cell/update-output.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { OOutput } from '@actually-colab/editor-types';
import type { DUser, OOutput } from '@actually-colab/editor-types';

import createHttpError from 'http-errors';

import ShallotSocketWrapper, {
ShallotRawHandler,
TShallotSocketEvent,
} from '../middleware/wrapper';
} from '@shallot/aws-websocket-wrapper';
import ShallotSocketAuthorizer from '../middleware/custom/authorizer';

import { broadcastToNotebook } from '../client-management';

Expand All @@ -22,7 +23,8 @@ type TUpdateOutputEvent = TShallotSocketEvent<
undefined,
undefined,
undefined,
TUpdateOutputEventBody
TUpdateOutputEventBody,
DUser
>;

const _handler: ShallotRawHandler<TUpdateOutputEvent> = async ({
Expand Down Expand Up @@ -57,4 +59,4 @@ const _handler: ShallotRawHandler<TUpdateOutputEvent> = async ({

export const handler = ShallotSocketWrapper(_handler, undefined, {
HttpErrorHandlerOpts: { catchAllErrors: true },
});
}).use(ShallotSocketAuthorizer());
10 changes: 6 additions & 4 deletions server/src/socket/chat/send-chat.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { DCell } from '@actually-colab/editor-types';
import type { DCell, DUser } from '@actually-colab/editor-types';

import createHttpError from 'http-errors';

import ShallotSocketWrapper, {
ShallotRawHandler,
TShallotSocketEvent,
} from '../middleware/wrapper';
} from '@shallot/aws-websocket-wrapper';
import ShallotSocketAuthorizer from '../middleware/custom/authorizer';

import { broadcastToNotebook } from '../client-management';

Expand All @@ -22,7 +23,8 @@ type TSendChatEvent = TShallotSocketEvent<
undefined,
undefined,
undefined,
TSendChatEventBody
TSendChatEventBody,
DUser
>;

const _handler: ShallotRawHandler<TSendChatEvent> = async ({ requestContext, body }) => {
Expand Down Expand Up @@ -51,4 +53,4 @@ const _handler: ShallotRawHandler<TSendChatEvent> = async ({ requestContext, bod

export const handler = ShallotSocketWrapper(_handler, undefined, {
HttpErrorHandlerOpts: { catchAllErrors: true },
});
}).use(ShallotSocketAuthorizer());
11 changes: 5 additions & 6 deletions server/src/socket/middleware/custom/authorizer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ShallotMiddlewareWithOptions } from 'shallot/dist/aws/core';
import type { APIGatewayProxyResult } from 'aws-lambda';
import { DUser } from '@actually-colab/editor-types';
import type { ShallotAWSMiddlewareWithOptions } from '@shallot/aws';
import type { TShallotSocketEvent } from '@shallot/aws-websocket-wrapper';

import HttpError from 'http-errors';
import { APIGatewayWebSocketEvent } from '../wrapper';
import { getUserFromConnectionId } from '../../../authorizer/token';
import { forceDisconnect } from '../../client-management';

Expand All @@ -11,9 +11,8 @@ import { forceDisconnect } from '../../client-management';
*
* @param config optional object to pass config options
*/
const ShallotSocketAuthorizer: ShallotMiddlewareWithOptions<
APIGatewayWebSocketEvent,
APIGatewayProxyResult
const ShallotSocketAuthorizer: ShallotAWSMiddlewareWithOptions<
TShallotSocketEvent<unknown, unknown, unknown, unknown, DUser>
> = () => ({
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
before: async ({ event }) => {
Expand Down
44 changes: 0 additions & 44 deletions server/src/socket/middleware/custom/json-body-parser.ts

This file was deleted.

Loading

0 comments on commit d794529

Please sign in to comment.