Skip to content

Commit 8e6c8be

Browse files
committed
Switched 100% to Typescript!
- Typescript everywhere - Removed backpack - Added eslint - Added config module, not used fully yet - Redis still needs fixed on tests
1 parent d0e4015 commit 8e6c8be

33 files changed

+747
-2688
lines changed

.eslintrc.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// @ts-check
2+
3+
module.exports = {
4+
parser: '@typescript-eslint/parser',
5+
parserOptions: {
6+
project: './tsconfig.json',
7+
},
8+
extends: [
9+
// /!\ Order seems to matter
10+
11+
'plugin:@typescript-eslint/recommended',
12+
'plugin:prettier/recommended',
13+
'prettier/@typescript-eslint',
14+
15+
// Already done by Airbnb
16+
],
17+
plugins: ['@typescript-eslint'],
18+
19+
env: {
20+
es6: true,
21+
browser: true,
22+
node: true,
23+
jest: true,
24+
},
25+
globals: {
26+
// Jest Puppeteer, see https://github.com/smooth-code/jest-puppeteer/blob/v4.0.0/README.md#configure-eslint
27+
page: true,
28+
},
29+
30+
rules: {
31+
'no-console': 'off',
32+
'no-underscore-dangle': 'off',
33+
'no-prototype-builtins': 'off',
34+
'no-plusplus': 'off',
35+
'spaced-comment': 'off',
36+
37+
// See [no-return-assign should be configurable to ignore arrow-functions](https://github.com/eslint/eslint/issues/9471)
38+
'no-return-assign': 'off',
39+
40+
'import/no-extraneous-dependencies': 'off',
41+
'import/no-unresolved': 'off',
42+
'import/prefer-default-export': 'off',
43+
44+
'jsx-a11y/label-has-for': 'off',
45+
'jsx-a11y/label-has-associated-control': 'off',
46+
47+
'@typescript-eslint/indent': 'off',
48+
'@typescript-eslint/explicit-function-return-type': 'off',
49+
'@typescript-eslint/no-non-null-assertion': 'off',
50+
'@typescript-eslint/camelcase': 'off',
51+
'@typescript-eslint/class-name-casing': 'off',
52+
'@typescript-eslint/no-unused-vars': 'off',
53+
'@typescript-eslint/no-empty-interface': 'off',
54+
'@typescript-eslint/explicit-member-accessibility': 'off',
55+
'@typescript-eslint/no-explicit-any': 'off',
56+
'@typescript-eslint/ban-ts-ignore': 'off',
57+
},
58+
59+
overrides: [
60+
{
61+
files: ['*.test.ts', '*.test.tsx'],
62+
},
63+
{
64+
files: ['*.d.ts'],
65+
rules: {
66+
// FIXME Fix "TypeError: Cannot read property 'body' of null"
67+
// https://github.com/typescript-eslint/typescript-eslint/issues/420
68+
// https://github.com/eslint/eslint/issues/11464
69+
// https://github.com/eslint/eslint/issues/11440
70+
'no-useless-constructor': 'off',
71+
},
72+
},
73+
],
74+
};

.eslintrc.json

-9
This file was deleted.

.prettierrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"singleQuote": true,
3-
"trailingComma": "all"
4-
}
3+
"trailingComma": "all",
4+
"quoteProps": "consistent"
5+
}

app.js

-77
This file was deleted.

app.ts

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import express = require('express');
2+
import { getUserOrgs } from './src/github/getUserOrgs';
3+
import { getUser } from './src/github/getUser';
4+
import { getRepos } from './src/github/getRepos';
5+
import { getManagementApiToken } from './src/auth0/getManagementApiToken';
6+
import * as session from 'express-session';
7+
8+
import redis = require('redis');
9+
import dotenv = require('dotenv');
10+
import * as connectRedis from 'connect-redis';
11+
const RedisStore = connectRedis(session);
12+
const redisClient = redis.createClient();
13+
dotenv.config();
14+
15+
// Create a new Express app
16+
const app: express.Application = express();
17+
18+
// Logging
19+
import pino = require('pino');
20+
import expressPino = require('express-pino-logger');
21+
const logger = pino({ level: process.env.LOG_LEVEL || 'info' });
22+
const expressLogger = expressPino({ logger });
23+
app.use(expressLogger);
24+
25+
// Define middleware that validates incoming bearer tokens
26+
import jwt = require('express-jwt');
27+
import jwksRsa = require('jwks-rsa');
28+
import { ConfigService } from './src/config/config.service';
29+
30+
// Set up Auth0 configuration
31+
const config: ConfigService = new ConfigService(
32+
`${process.env.NODE_ENV || 'development'}.env`,
33+
);
34+
35+
const checkJwt = jwt({
36+
secret: jwksRsa.expressJwtSecret({
37+
cache: true,
38+
rateLimit: true,
39+
jwksRequestsPerMinute: 5,
40+
jwksUri: `https://${config.get('AUTH0_DOMAIN')}/.well-known/jwks.json`,
41+
}),
42+
43+
audience: config.get('AUTH0_AUDIENCE'),
44+
issuer: `https://${config.get('AUTH0_DOMAIN')}/`,
45+
algorithm: ['RS256'],
46+
});
47+
48+
// Use session https://github.com/expressjs/session
49+
const sess = {
50+
store: new RedisStore({ client: redisClient }),
51+
secret: 'I like Santa',
52+
cookie: {},
53+
resave: false,
54+
saveUninitialized: false,
55+
};
56+
if (app.get('env') === 'production') {
57+
app.set('trust proxy', 1); // trust first proxy
58+
// sess.cookie.secure = true; // serve secure cookies
59+
}
60+
app.use(session(sess));
61+
// End session code
62+
63+
// Get management token from Auth0
64+
let authToken;
65+
app.use(express.json());
66+
app.listen(3000, async () => {
67+
logger.info('App is ready');
68+
await getManagementApiToken().then(token => {
69+
authToken = token;
70+
});
71+
});
72+
73+
// Retrieve Org Information
74+
app.get('/orgs', checkJwt, async (req: any, res) => {
75+
if (!req.session.orgs) {
76+
const userId = req.user.sub.split('|')[1];
77+
const githubUser = await getUser(authToken, userId);
78+
const githubToken = githubUser.identities[0].access_token;
79+
const orgs = await getUserOrgs(githubToken);
80+
req.session.orgs = orgs;
81+
}
82+
req.log.info('Returning cached Github Orgs');
83+
res.send(req.session.orgs);
84+
});
85+
86+
// Receive Repo Information
87+
app.get('/orgs/repos', checkJwt, async (req: any, res) => {
88+
const userId = req.user.sub.split('|')[1];
89+
const githubUser = await getUser(authToken, userId);
90+
const githubToken = githubUser.identities[0].access_token;
91+
const repos = await getRepos(req.query.org, githubToken);
92+
res.send(repos);
93+
});
94+
95+
process.on('SIGINT', function() {
96+
redisClient.quit();
97+
});

backpack.config.js

-8
This file was deleted.

library/auth0/getManagementApiToken.js

-23
This file was deleted.

library/auth0/getManagementApiToken.test.js

-11
This file was deleted.

library/githubUser/getAuthToken.js

-18
This file was deleted.

library/githubUser/getAuthToken.test.js

-8
This file was deleted.

library/githubUser/getRepos.js

-46
This file was deleted.

0 commit comments

Comments
 (0)