Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesa integration #87

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ DISCORD_CALLBACK_URL=http://localhost:3000/auth/discord
# This should be a list of comma (,) separated Discord OAuth2 Redirect URLs
DISCORD_OAUTH_ORIGINS=http://localhost:3000

# Optional: Mesa namespace. Defaults to api
# MESA_NAMESPACE=api

# Optional: User Configurable

# The maximum amount of members a room can have (default 10)
Expand Down
259 changes: 43 additions & 216 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,241 +1,68 @@
/*
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
https://github.com/typescript-eslint/tslint-to-eslint-config

It represents the closest reasonable ESLint configuration to this
project's original TSLint configuration.

We recommend eventually switching this configuration to extend from
the recommended rulesets in typescript-eslint.
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md

Happy linting! 💖
*/
module.exports = {
root: true,
env: {
es6: true
'env': {
'es6': true,
'node': true
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
'extends': [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module'
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
plugins: [
'@typescript-eslint',
'@typescript-eslint/tslint',
'import',
'prefer-arrow'
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module'
},
'plugins': [
'@typescript-eslint'
],
rules: {
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': [
'error',
{
default: 'array-simple'
}
],
'@typescript-eslint/ban-types': [
'error',
{
types: {
Object: {
message: 'Avoid using the `Object` type. Did you mean `object`?'
},
Function: {
message: 'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.'
},
Boolean: {
message: 'Avoid using the `Boolean` type. Did you mean `boolean`?'
},
Number: {
message: 'Avoid using the `Number` type. Did you mean `number`?'
},
String: {
message: 'Avoid using the `String` type. Did you mean `string`?'
},
Symbol: {
message: 'Avoid using the `Symbol` type. Did you mean `symbol`?'
}
}
}
],
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
accessibility: 'explicit'
}
],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/indent': [
'error',
2,
{
FunctionDeclaration: {
parameters: 'first'
},
FunctionExpression: {
parameters: 'first'
}
}
],
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'none',
requireLast: true
},
singleline: {
delimiter: 'semi',
requireLast: false
}
}
],
'@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/quotes': [
'error',
'single'
],
'@typescript-eslint/semi': [
'rules': {
'indent': [
'error',
'never'
2
],
'@typescript-eslint/triple-slash-reference': [
'error',
{
path: 'always',
types: 'prefer-import',
lib: 'always'
}
'no-async-promise-executor': [
'off'
],
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unified-signatures': 'error',
'arrow-body-style': 'error',
'arrow-parens': [
'error',
'as-needed'
'@typescript-eslint/no-explicit-any': [
'off'
],
'brace-style': [
'error',
'1tbs'
'@typescript-eslint/explicit-module-boundary-types': [
'off'
],
'camelcase': 'off',
'@typescript-eslint/camelcase': 'off',
'comma-dangle': 'error',
'complexity': 'off',
'constructor-super': 'error',
'curly': [
'error',
'multi-or-nest'
'prefer-const': [
'error'
],
'eol-last': 'error',
'eqeqeq': [
'error',
'smart'
'nonblock-statement-body-position': [
'error', 'below'
],
'guard-for-in': 'error',
'id-blacklist': 'off',
'id-match': 'off',
'import/order': 'error',
'max-classes-per-file': [
'error',
1
'no-sequences': [
'error'
],
'new-parens': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-cond-assign': 'error',
'no-console': 'off',
'no-debugger': 'error',
'no-empty': 'error',
'no-eval': 'error',
'no-fallthrough': 'off',
'no-invalid-this': 'off',
'no-multiple-empty-lines': 'error',
'no-new-wrappers': 'error',
'no-shadow': [
'error',
{
hoist: 'all'
}
'eol-last': [
'error', 'always'
],
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-undef-init': 'error',
'no-underscore-dangle': 'off',
'no-unsafe-finally': 'error',
'no-unused-labels': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': [
'off',
'never'
'error', 'never'
],
'prefer-arrow/prefer-arrow-functions': 'error',
'prefer-const': 'error',
'quote-props': [
'error',
'consistent-as-needed'
'one-var-declaration-per-line': [
'error', 'always'
],
'radix': 'off',
'space-before-function-paren': [
'linebreak-style': [
'error',
{
anonymous: 'never',
asyncArrow: 'always',
named: 'never'
}
'unix'
],
'spaced-comment': [
'quotes': [
'error',
'always',
{
markers: [
'/'
]
}
'single'
],
'use-isnan': 'error',
'valid-typeof': 'off',
'@typescript-eslint/tslint/config': [
'semi': [
'error',
{
rules: {
'import-spacing': true,
'typedef': [
true,
'parameter'
],
'whitespace': [
true,
'check-branch',
'check-module',
'check-preblock'
]
}
}
'never'
]
}
}

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"start": "node dist",
"dev": "tsc-watch --compiler typescript/bin/tsc --onSuccess \"yarn start\"",
"build": "tsc",
"lint": "eslint src/**/*.ts{,x}"
"lint": "eslint src/**/*.ts"
},
"dependencies": {
"@cryb/mesa": "^1.4.3",
"axios": "^0.19.0",
"biguint-format": "^1.0.1",
"chance": "^1.0.18",
Expand Down Expand Up @@ -49,12 +50,9 @@
"@types/passport-discord": "^0.1.3",
"@types/passport-jwt": "^3.0.1",
"@types/ws": "^6.0.1",
"@typescript-eslint/eslint-plugin": "^2.32.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.32.0",
"@typescript-eslint/parser": "^2.32.0",
"eslint": "^7.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-prefer-arrow": "^1.2.1",
"@typescript-eslint/eslint-plugin": "^3.1.0",
"@typescript-eslint/parser": "^3.1.0",
"eslint": "^7.1.0",
"tsc-watch": "^2.2.1",
"tslint": "^5.20.1",
"typescript": "^3.5.3"
Expand Down
2 changes: 2 additions & 0 deletions src/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
mesa_namespace: process.env.MESA_NAMESPACE || 'api',

/**
* The amount of members a room needs to hit for a Portal (VM) to be created / queued (default 2)
*/
Expand Down
6 changes: 6 additions & 0 deletions src/config/dispatcher.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Dispatcher } from '@cryb/mesa'

import config from '../config/defaults'
import { getOptions } from './redis.config'

export default new Dispatcher(getOptions(), { namespace: config.mesa_namespace })
16 changes: 8 additions & 8 deletions src/config/passport.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const fetchUser = async (
) => new Promise<User>(async (resolve, reject) => {
try {
if (process.env.AUTH_BASE_URL) {
const { authorization } = req.headers,
token = authorization.split(' ')[1],
{ data: { resource } } = await axios.post(process.env.AUTH_BASE_URL, { token }),
user = new User(resource)
const { authorization } = req.headers
const token = authorization.split(' ')[1]
const { data: { resource } } = await axios.post(process.env.AUTH_BASE_URL, { token })
const user = new User(resource)

resolve(user)
} else {
passport.authenticate('jwt', { session: false }, (err, user: User) => {
passport.authenticate('jwt', { session: false }, async (err, user: User) => {
if (err)
return handleError(err, res)

Expand All @@ -64,9 +64,9 @@ const fetchUser = async (

export const authenticate = async (req: Request, res: Response, next: NextFunction) => {
try {
const user = await fetchUser(req, res, next),
endpoint = fetchEndpoint(req),
ban = await user.fetchBan()
const user = await fetchUser(req, res, next)
const endpoint = fetchEndpoint(req)
const ban = await user.fetchBan()

if (ban && BAN_SAFE_ENDPOINTS.includes(endpoint))
return handleError(UserBanned, res)
Expand Down
Loading