Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from ap2020/feature/update-eslint
- Loading branch information
Showing
47 changed files
with
2,187 additions
and
1,669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
{ | ||
"extends": ["@pizzacat83/eslint-config/typescript"], | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
"ecmaVersion": 2019 | ||
}, | ||
"env": { | ||
"jest": true | ||
}, | ||
"rules": { | ||
} | ||
"overrides": [ | ||
{ | ||
"files": "./**.js", | ||
"extends": ["@pizzacat83/eslint-config/nodeapp"] | ||
}, | ||
{ | ||
"files": "**.ts", | ||
"extends": ["@pizzacat83/eslint-config/typescript-nodeapp"], | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"env": { | ||
"jest": true | ||
}, | ||
"rules": { | ||
"import/no-unresolved": [ | ||
"error", | ||
{ | ||
"ignore": [ | ||
// aws-lambda and @types/aws-lambda is totally different and we only use the latter. | ||
// There's no problem not to have aws-lambda because we only use type information. | ||
"aws-lambda" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
const ignorePatterns = [ | ||
'/node_modules/', | ||
'<rootDir>/.webpack/', | ||
'<rootDir>/.dynamodb/', | ||
'<rootDir>/.vscode/', | ||
'/coverage/', | ||
'/node_modules/', | ||
'<rootDir>/.webpack/', | ||
'<rootDir>/.dynamodb/', | ||
'<rootDir>/.vscode/', | ||
'/coverage/', | ||
]; | ||
|
||
const notTestPatterns = [ | ||
'<rootDir>/src/lib/envvar/test.ts', | ||
'<rootDir>/src/lib/envvar/test.ts', | ||
]; | ||
|
||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', | ||
testPathIgnorePatterns: [ | ||
...ignorePatterns, | ||
...notTestPatterns, | ||
], | ||
collectCoverageFrom: [ | ||
'**/*.{js,ts}', | ||
'!**/*.test.{js,ts}' | ||
], | ||
coveragePathIgnorePatterns: [ | ||
...ignorePatterns, | ||
'<rootDir>/jest.config.js', | ||
'<rootDir>/.env.js', | ||
], | ||
setupFiles: [ | ||
'./test-utils/setup.ts', | ||
], | ||
moduleNameMapper: { | ||
"^@/(.+)": "<rootDir>/src/$1" | ||
}, | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', | ||
testPathIgnorePatterns: [ | ||
...ignorePatterns, | ||
...notTestPatterns, | ||
], | ||
collectCoverageFrom: [ | ||
'**/*.{js,ts}', | ||
'!**/*.test.{js,ts}', | ||
], | ||
coveragePathIgnorePatterns: [ | ||
...ignorePatterns, | ||
'<rootDir>/jest.config.js', | ||
'<rootDir>/.env.js', | ||
], | ||
setupFiles: [ | ||
'./test-utils/setup.ts', | ||
], | ||
moduleNameMapper: { | ||
'^@/(.+)': '<rootDir>/src/$1', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import AWS from "aws-sdk"; | ||
import AWS from 'aws-sdk'; | ||
|
||
export const db = new AWS.DynamoDB.DocumentClient( | ||
process.env.STAGE === 'prod' ? | ||
{} : | ||
{ | ||
region: 'localhost', | ||
endpoint: 'http://localhost:8000', | ||
}, | ||
process.env.STAGE === 'prod' ? | ||
{} : | ||
{ | ||
region: 'localhost', | ||
endpoint: 'http://localhost:8000', | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
// TODO: type keys | ||
|
||
export const envVarKeys = [ | ||
"aws/account-id", | ||
"user-agent", | ||
"utokyo-proxy/host", | ||
"utokyo-proxy/port", | ||
"utokyo-proxy/username", | ||
"utokyo-proxy/password", | ||
"slack/signing-secret", | ||
"slack/token/bot", | ||
"slack/channel/notify-others", | ||
"slack/channel/notify-temp", | ||
"slack/user_id/bot", | ||
'aws/account-id', | ||
'user-agent', | ||
'utokyo-proxy/host', | ||
'utokyo-proxy/port', | ||
'utokyo-proxy/username', | ||
'utokyo-proxy/password', | ||
'slack/signing-secret', | ||
'slack/token/bot', | ||
'slack/channel/notify-others', | ||
'slack/channel/notify-temp', | ||
'slack/user_id/bot', | ||
] as const; | ||
|
||
export type EnvVarKey = typeof envVarKeys[number]; | ||
|
||
export type EnvVar = { | ||
get<Key extends EnvVarKey>(key: Key): Promise<string>; | ||
get<Key extends EnvVarKey>(key: Key): Promise<string>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import envvarObj from '@/../.env.local.json' | ||
import { EnvVar, EnvVarKey } from './base'; | ||
import envvarObj from '@/../.env.local.json'; | ||
import type { EnvVar, EnvVarKey } from './base'; | ||
|
||
class EnvVarLocal implements EnvVar { | ||
envvars: Map<EnvVarKey, string> = new Map(Object.entries(envvarObj).map(([k, v]) => [k as EnvVarKey, v.toString()])); | ||
envvars: Map<EnvVarKey, string> = new Map(Object.entries(envvarObj).map(([k, v]) => [k as EnvVarKey, v.toString()])); | ||
|
||
get<Key extends EnvVarKey>(key: Key) { | ||
return Promise.resolve(this.envvars.get(key)); | ||
} | ||
get<Key extends EnvVarKey>(key: Key) { | ||
return Promise.resolve(this.envvars.get(key)); | ||
} | ||
} | ||
|
||
export const envvarLocal = new EnvVarLocal(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import AWS from 'aws-sdk'; | ||
import 'source-map-support/register'; | ||
import { EnvVar, EnvVarKey } from './base'; | ||
import type { EnvVar, EnvVarKey } from './base'; | ||
|
||
class EnvVarProd implements EnvVar { | ||
ssm = new AWS.SSM(); | ||
cache = new Map<EnvVarKey, Promise<string>>(); | ||
ssm = new AWS.SSM(); | ||
cache = new Map<EnvVarKey, Promise<string>>(); | ||
|
||
private async fetch(key: EnvVarKey): Promise<string> { | ||
const res = await this.ssm.getParameter({ | ||
Name: `/ap2020bot/${process.env.STAGE}/${key}`, | ||
WithDecryption: true, | ||
}).promise(); | ||
const value = res.Parameter.Value; | ||
return value; | ||
} | ||
private async fetch(key: EnvVarKey): Promise<string> { | ||
const res = await this.ssm.getParameter({ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
Name: `/ap2020bot/${process.env.STAGE}/${key}`, | ||
WithDecryption: true, | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
}).promise(); | ||
const value = res.Parameter.Value; | ||
return value; | ||
} | ||
|
||
async get(key: EnvVarKey): Promise<string> { | ||
if (this.cache.has(key)) { | ||
return this.cache.get(key); | ||
} | ||
const promise: Promise<string> = this.fetch(key); | ||
this.cache.set(key, promise); | ||
return promise; | ||
async get(key: EnvVarKey): Promise<string> { | ||
if (this.cache.has(key)) { | ||
return this.cache.get(key); | ||
} | ||
const promise: Promise<string> = this.fetch(key); | ||
this.cache.set(key, promise); | ||
return promise; | ||
} | ||
} | ||
|
||
export const envvarProd = new EnvVarProd(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { EnvVar, EnvVarKey } from './base'; | ||
import type { EnvVar, EnvVarKey } from './base'; | ||
|
||
class EnvVarTest implements EnvVar { | ||
envvars = new Map<EnvVarKey, string>(); | ||
envvars = new Map<EnvVarKey, string>(); | ||
|
||
init() { | ||
this.envvars.clear(); | ||
} | ||
init() { | ||
this.envvars.clear(); | ||
} | ||
|
||
set(key: EnvVarKey, value: string) { | ||
this.envvars.set(key, value); | ||
} | ||
set(key: EnvVarKey, value: string) { | ||
this.envvars.set(key, value); | ||
} | ||
|
||
get(key: EnvVarKey) { | ||
return Promise.resolve(this.envvars.get(key)); | ||
} | ||
get(key: EnvVarKey) { | ||
return Promise.resolve(this.envvars.get(key)); | ||
} | ||
} | ||
|
||
export const envvarTest = new EnvVarTest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { envvar } from "@/lib/envvar" | ||
import { SNSHandler } from "aws-lambda" | ||
import { SlackEvent, SlackSNSMessage } from "./types" | ||
import { envvar } from '@/lib/envvar'; | ||
import type { SNSHandler } from 'aws-lambda'; | ||
import type { SlackEvent, SlackSNSMessage } from './types'; | ||
|
||
export const getSlackEventTopicARN = async () => { | ||
return `arn:aws:sns:us-east-1:${await envvar.get('aws/account-id')}:ap2020bot-${process.env.STAGE}-slack-events` | ||
} | ||
export const getSlackEventTopicARN = async (): Promise<string> => | ||
`arn:aws:sns:us-east-1:${await envvar.get('aws/account-id')}:ap2020bot-${process.env.STAGE}-slack-events`; | ||
|
||
export const createHandler = <Event extends SlackEvent>(callback: ((message: SlackSNSMessage<Event>) => Promise<void>)): SNSHandler => { | ||
return async (snsEvent) => { | ||
const message = JSON.parse(snsEvent.Records[0].Sns.Message); | ||
export const createHandler = <Event extends SlackEvent>( | ||
callback: ((message: SlackSNSMessage<Event>) => Promise<void>), | ||
): SNSHandler => | ||
async (snsEvent) => { | ||
const message = JSON.parse(snsEvent.Records[0].Sns.Message) as SlackSNSMessage<Event>; | ||
await callback(message); | ||
} | ||
} | ||
}; |
Oops, something went wrong.