@creator.co/wapi 1.7.1-alpha4 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +3 -0
- package/.eslintrc.cjs +60 -0
- package/.github/workflows/npmpublish.yml +11 -0
- package/.github/workflows/prs.yml +13 -0
- package/dist/package-lock.json +2 -2
- package/dist/package.json +1 -1
- package/jest.config.ts +33 -0
- package/jest.smoke.config.ts +35 -0
- package/package.json +1 -1
- package/tests/API/Request.test.ts +273 -0
- package/tests/API/Response.test.ts +367 -0
- package/tests/API/Utils.test.ts +167 -0
- package/tests/BaseEvent/EventProcessor.test.ts +261 -0
- package/tests/BaseEvent/Process.test.ts +49 -0
- package/tests/BaseEvent/Transaction.test.ts +408 -0
- package/tests/Cache/Redis-client.test.ts +90 -0
- package/tests/Cache/Redis-cluster.test.ts +100 -0
- package/tests/Config/Config.test.ts +205 -0
- package/tests/Config/EnvironmentVar.test.ts +250 -0
- package/tests/Crypto/Crypto.test.ts +88 -0
- package/tests/Crypto/JWT.test.ts +92 -0
- package/tests/Database/DatabaseManager.test.ts +71 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +76 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +149 -0
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
- package/tests/Logger/Logger.test.ts +219 -0
- package/tests/Mailer/Mailer.test.ts +59 -0
- package/tests/Publisher/Publisher.test.ts +94 -0
- package/tests/Server/RouteResolver.test.ts +102 -0
- package/tests/Server/Router.test.ts +39 -0
- package/tests/Server/lib/ContainerServer.test.ts +531 -0
- package/tests/Server/lib/Server.test.ts +12 -0
- package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +268 -0
- package/tests/Server/lib/container/Utils.test.ts +47 -0
- package/tests/Test.utils.ts +74 -0
- package/tests/Validation/Validator.test.ts +76 -0
- package/tsconfig.json +26 -0
- package/tsconfig.smoke.json +26 -0
package/.eslintignore
ADDED
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-env node */
|
|
2
|
+
module.exports = {
|
|
3
|
+
extends: [
|
|
4
|
+
'eslint:recommended',
|
|
5
|
+
'plugin:@typescript-eslint/recommended',
|
|
6
|
+
'plugin:prettier/recommended',
|
|
7
|
+
'plugin:import/recommended',
|
|
8
|
+
'plugin:import/typescript',
|
|
9
|
+
],
|
|
10
|
+
parser: '@typescript-eslint/parser',
|
|
11
|
+
plugins: ['@typescript-eslint', 'prettier'],
|
|
12
|
+
root: true,
|
|
13
|
+
rules: {
|
|
14
|
+
'prettier/prettier': [
|
|
15
|
+
'error',
|
|
16
|
+
{
|
|
17
|
+
tabWidth: 2,
|
|
18
|
+
useTabs: false,
|
|
19
|
+
bracketSameLine: false,
|
|
20
|
+
semi: false,
|
|
21
|
+
arrowParens: 'avoid',
|
|
22
|
+
jsxSingleQuote: true,
|
|
23
|
+
printWidth: 100,
|
|
24
|
+
singleQuote: true,
|
|
25
|
+
quoteProps: 'as-needed',
|
|
26
|
+
htmlWhitespaceSensitivity: 'css',
|
|
27
|
+
proseWrap: 'preserve',
|
|
28
|
+
bracketSpacing: true,
|
|
29
|
+
embeddedLanguageFormatting: 'auto',
|
|
30
|
+
endOfLine: 'lf',
|
|
31
|
+
trailingComma: 'es5',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
'@typescript-eslint/ban-ts-comment': 0,
|
|
35
|
+
'@typescript-eslint/no-explicit-any': 0,
|
|
36
|
+
// turn on errors for missing imports
|
|
37
|
+
'import/no-unresolved': 'error',
|
|
38
|
+
// 'import/no-named-as-default-member': 'off',
|
|
39
|
+
'import/order': [
|
|
40
|
+
'error',
|
|
41
|
+
{
|
|
42
|
+
groups: [
|
|
43
|
+
'builtin', // Built-in imports (come from NodeJS native) go first
|
|
44
|
+
'external', // <- External imports
|
|
45
|
+
'internal', // <- Absolute imports
|
|
46
|
+
['sibling', 'parent'], // <- Relative imports, the sibling and parent types they can be mingled together
|
|
47
|
+
'index', // <- index imports
|
|
48
|
+
'unknown', // <- unknown
|
|
49
|
+
],
|
|
50
|
+
'newlines-between': 'always',
|
|
51
|
+
alphabetize: {
|
|
52
|
+
/* sort in ascending order. Options: ["ignore", "asc", "desc"] */
|
|
53
|
+
order: 'asc',
|
|
54
|
+
/* ignore case. Options: [true, false] */
|
|
55
|
+
caseInsensitive: true,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
}
|
package/dist/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.7.1
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@creator.co/wapi",
|
|
9
|
-
"version": "1.7.1
|
|
9
|
+
"version": "1.7.1",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-kms": "^3.556.0",
|
package/dist/package.json
CHANGED
package/jest.config.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Config } from '@jest/types'
|
|
2
|
+
/* eslint-env node */
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
preset: 'ts-jest',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
modulePathIgnorePatterns: ['smoke-tests'],
|
|
7
|
+
reporters: [
|
|
8
|
+
'default',
|
|
9
|
+
[
|
|
10
|
+
'jest-junit',
|
|
11
|
+
{
|
|
12
|
+
outputDirectory: 'coverage',
|
|
13
|
+
outputName: 'jest-junit.xml',
|
|
14
|
+
ancestorSeparator: ' › ',
|
|
15
|
+
uniqueOutputName: 'false',
|
|
16
|
+
suiteNameTemplate: '{filepath}',
|
|
17
|
+
classNameTemplate: '{classname}',
|
|
18
|
+
titleTemplate: '{title}',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
],
|
|
22
|
+
coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
|
|
23
|
+
collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
|
|
24
|
+
coverageThreshold: {
|
|
25
|
+
global: {
|
|
26
|
+
branches: 80,
|
|
27
|
+
functions: 80,
|
|
28
|
+
lines: 80,
|
|
29
|
+
statements: 80,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
export default config
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Config } from '@jest/types'
|
|
2
|
+
/* eslint-env node */
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
// ECMA suppport https://jestjs.io/docs/ecmascript-modules
|
|
6
|
+
transform: {},
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
reporters: [
|
|
10
|
+
'default',
|
|
11
|
+
[
|
|
12
|
+
'jest-junit',
|
|
13
|
+
{
|
|
14
|
+
outputDirectory: 'coverage',
|
|
15
|
+
outputName: 'jest-junit.xml',
|
|
16
|
+
ancestorSeparator: ' › ',
|
|
17
|
+
uniqueOutputName: 'false',
|
|
18
|
+
suiteNameTemplate: '{filepath}',
|
|
19
|
+
classNameTemplate: '{classname}',
|
|
20
|
+
titleTemplate: '{title}',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
],
|
|
24
|
+
coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
|
|
25
|
+
collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
|
|
26
|
+
coverageThreshold: {
|
|
27
|
+
global: {
|
|
28
|
+
branches: 80,
|
|
29
|
+
functions: 80,
|
|
30
|
+
lines: 80,
|
|
31
|
+
statements: 80,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
export default config
|
package/package.json
CHANGED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { APIGatewayEvent, Context } from 'aws-lambda'
|
|
2
|
+
import { expect } from 'chai'
|
|
3
|
+
|
|
4
|
+
import Request, { HttpMethod } from '../../src/API/Request'
|
|
5
|
+
import Logger from '../../src/Logger/Logger'
|
|
6
|
+
|
|
7
|
+
function newReq(event: any, context?: any) {
|
|
8
|
+
const logger = new Logger(
|
|
9
|
+
{
|
|
10
|
+
logLevel: 'DEBUG',
|
|
11
|
+
},
|
|
12
|
+
'123-456'
|
|
13
|
+
)
|
|
14
|
+
return new Request<any, any, any>(
|
|
15
|
+
<APIGatewayEvent>(<unknown>event),
|
|
16
|
+
<Context>context ? context : {},
|
|
17
|
+
logger
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('Request querystring', () => {
|
|
22
|
+
test('Null query string', () => {
|
|
23
|
+
const r = newReq({
|
|
24
|
+
queryStringParameters: null,
|
|
25
|
+
})
|
|
26
|
+
expect(r.containsQueryParam('123')).to.be.false
|
|
27
|
+
expect(r.getQueryParam('123')).to.be.null
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('Empty query string', () => {
|
|
31
|
+
const r = newReq({
|
|
32
|
+
queryStringParameters: {},
|
|
33
|
+
})
|
|
34
|
+
expect(r.containsQueryParam('123')).to.be.false
|
|
35
|
+
expect(r.getQueryParam('123')).to.be.null
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('Valid query string', () => {
|
|
39
|
+
const v = { '123': 'abc' }
|
|
40
|
+
const r = newReq({
|
|
41
|
+
queryStringParameters: v,
|
|
42
|
+
})
|
|
43
|
+
expect(r.containsQueryParam('123')).to.be.true
|
|
44
|
+
expect(r.getQueryParam('123')).to.be.equals('abc')
|
|
45
|
+
expect(r.getQueryParams()).to.be.deep.equal(v)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('Valid query string number', () => {
|
|
49
|
+
const r = newReq({
|
|
50
|
+
queryStringParameters: { '123': 456 },
|
|
51
|
+
})
|
|
52
|
+
expect(r.containsQueryParam('123')).to.be.true
|
|
53
|
+
expect(r.getQueryParam('123')).to.be.equals(456)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe('Request headers', () => {
|
|
58
|
+
test('Null headers', () => {
|
|
59
|
+
const r = newReq({ headers: null })
|
|
60
|
+
expect(r.getHeader('123')).to.be.null
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('Empty headers', () => {
|
|
64
|
+
const r = newReq({ headers: {} })
|
|
65
|
+
expect(r.getHeader('123')).to.be.null
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('Valid headers', () => {
|
|
69
|
+
const r = newReq({ headers: { '123': 'abc' } })
|
|
70
|
+
expect(r.getHeader('123')).to.be.equals('abc')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('Auth headers', () => {
|
|
74
|
+
const r = newReq({ headers: { Authorization: 'abc' } })
|
|
75
|
+
expect(r.getAuthorizationHeader()).to.be.equals('abc')
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
describe('Request context', () => {
|
|
80
|
+
test('Null context', () => {
|
|
81
|
+
const r = newReq({ requestContext: null })
|
|
82
|
+
expect(r.getContextParam('123')).to.be.null
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('Empty context', () => {
|
|
86
|
+
const r = newReq({ requestContext: {} })
|
|
87
|
+
expect(r.getContextParam('123')).to.be.null
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('Valid context', () => {
|
|
91
|
+
const r = newReq({
|
|
92
|
+
requestContext: { '123': 'abc' },
|
|
93
|
+
})
|
|
94
|
+
expect(r.getContextParam('123')).to.be.equals('abc')
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('Request path params', () => {
|
|
99
|
+
test('Null path params', () => {
|
|
100
|
+
const r = newReq({ pathParameters: null })
|
|
101
|
+
expect(r.containsPathParam('123')).to.be.false
|
|
102
|
+
expect(r.getPathParam('123')).to.be.null
|
|
103
|
+
expect(r.getPathParams()).to.be.null
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('Empty path params', () => {
|
|
107
|
+
const r = newReq({ pathParameters: {} })
|
|
108
|
+
expect(r.containsPathParam('123')).to.be.false
|
|
109
|
+
expect(r.getPathParam('123')).to.be.null
|
|
110
|
+
expect(r.getPathParams()).to.be.deep.equal({})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('Valid path params', () => {
|
|
114
|
+
const v = { '123': 'abc' }
|
|
115
|
+
const r = newReq({
|
|
116
|
+
pathParameters: v,
|
|
117
|
+
})
|
|
118
|
+
expect(r.containsPathParam('123')).to.be.true
|
|
119
|
+
expect(r.getPathParam('123')).to.be.equals('abc')
|
|
120
|
+
expect(r.getPathParams()).to.be.deep.equal(v)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('Valid path param number', () => {
|
|
124
|
+
const v = { '123': 456 }
|
|
125
|
+
const r = newReq({
|
|
126
|
+
pathParameters: v,
|
|
127
|
+
})
|
|
128
|
+
expect(r.containsPathParam('123')).to.be.true
|
|
129
|
+
expect(r.getPathParam('123')).to.be.equals(456)
|
|
130
|
+
expect(r.getPathParams()).to.be.deep.equal(v)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
test('Fix path params', () => {
|
|
134
|
+
const v = { '123': 'abc' }
|
|
135
|
+
const r = newReq({ pathParameters: null })
|
|
136
|
+
r.setFixedPathParams(
|
|
137
|
+
Object.keys(v).map(k => ({ name: k })),
|
|
138
|
+
['/'].concat(Object.values(v))
|
|
139
|
+
)
|
|
140
|
+
expect(r.containsPathParam('123')).to.be.true
|
|
141
|
+
expect(r.getPathParam('123')).to.be.equals('abc')
|
|
142
|
+
expect(r.getPathParams()).to.be.deep.equal(v)
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
describe('Request body', () => {
|
|
147
|
+
test('Null body', () => {
|
|
148
|
+
const r = newReq({ body: null })
|
|
149
|
+
expect(r.getBody()).to.be.null
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('Empty body', () => {
|
|
153
|
+
const r = newReq({ body: {} })
|
|
154
|
+
expect(r.getBody()).to.be.deep.equals({})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('Empty string body', () => {
|
|
158
|
+
const r = newReq({ body: '{}' })
|
|
159
|
+
expect(r.getBody()).to.be.deep.equals({})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('Broken json string body', () => {
|
|
163
|
+
const r = newReq({ body: '{name": "Joe"}' })
|
|
164
|
+
expect(r.getBody()).to.be.equals('{name": "Joe"}')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('Valid string body', () => {
|
|
168
|
+
const r = newReq({ body: '{"name": "Joe"}' })
|
|
169
|
+
expect(r.getBody()).to.be.deep.equals({
|
|
170
|
+
name: 'Joe',
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('Valid json body', () => {
|
|
175
|
+
const r = newReq({ body: { name: 'Joe' } })
|
|
176
|
+
expect(r.getBody()).to.be.deep.equals({
|
|
177
|
+
name: 'Joe',
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
describe('Request path/method', () => {
|
|
183
|
+
test('Null path/method', () => {
|
|
184
|
+
const r = newReq({
|
|
185
|
+
path: null,
|
|
186
|
+
httpMethod: null,
|
|
187
|
+
})
|
|
188
|
+
expect(r.getPath()).to.be.null
|
|
189
|
+
expect(r.getMethod.bind(r)).to.throw('Invalid HTTP method: null')
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
test('Empty path/method', () => {
|
|
193
|
+
const r = newReq({
|
|
194
|
+
path: '',
|
|
195
|
+
httpMethod: '',
|
|
196
|
+
})
|
|
197
|
+
expect(r.getPath()).to.be.a('string')
|
|
198
|
+
expect(r.getPath()).to.be.equals('')
|
|
199
|
+
expect(r.getMethod.bind(r)).to.throw('Invalid HTTP method: ')
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test('Valid method/path', () => {
|
|
203
|
+
const r = newReq({
|
|
204
|
+
path: '/root',
|
|
205
|
+
httpMethod: HttpMethod.GET,
|
|
206
|
+
})
|
|
207
|
+
expect(r.getPath()).to.be.a('string')
|
|
208
|
+
expect(r.getPath()).to.be.equals('/root')
|
|
209
|
+
expect(r.getMethod()).to.be.a('string')
|
|
210
|
+
expect(r.getMethod()).to.be.equals(HttpMethod.GET)
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('Case insensitive method', () => {
|
|
214
|
+
const r = newReq({
|
|
215
|
+
path: '/root',
|
|
216
|
+
httpMethod: 'poST',
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
expect(r.getMethod()).to.be.equals(HttpMethod.POST)
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
describe('Request ID', () => {
|
|
224
|
+
test('From context', () => {
|
|
225
|
+
const r = newReq({}, { awsRequestId: '123' })
|
|
226
|
+
expect(r.getRequestID()).to.not.be.null
|
|
227
|
+
expect(r.getRequestID()).to.be.equals('123')
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
test('From event', () => {
|
|
231
|
+
const r = newReq({
|
|
232
|
+
requestContext: { requestId: '123' },
|
|
233
|
+
})
|
|
234
|
+
expect(r.getRequestID()).to.not.be.null
|
|
235
|
+
expect(r.getRequestID()).to.be.equals('123')
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
test('unknown', () => {
|
|
239
|
+
const r = newReq({})
|
|
240
|
+
expect(r.getRequestID()).to.not.be.null
|
|
241
|
+
expect(r.getRequestID()).to.be.equals('unknown')
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
describe('Request origin IP', () => {
|
|
246
|
+
test('From context', () => {
|
|
247
|
+
const r = newReq({
|
|
248
|
+
requestContext: {
|
|
249
|
+
identity: { sourceIp: '127.0.0.1' },
|
|
250
|
+
},
|
|
251
|
+
})
|
|
252
|
+
expect(r.getOriginIP()).to.not.be.null
|
|
253
|
+
expect(r.getOriginIP()).to.be.equals('127.0.0.1')
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test('From header', () => {
|
|
257
|
+
const r = newReq({
|
|
258
|
+
headers: {
|
|
259
|
+
'X-Forwarded-For': '127.0.0.1',
|
|
260
|
+
},
|
|
261
|
+
})
|
|
262
|
+
expect(r.getOriginIP()).to.not.be.null
|
|
263
|
+
expect(r.getOriginIP()).to.be.equals('127.0.0.1')
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
test('unknown', () => {
|
|
267
|
+
const r = newReq({})
|
|
268
|
+
expect(r.getOriginIP()).to.not.be.null
|
|
269
|
+
expect(r.getOriginIP()).to.be.equals('unknown')
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
export {}
|