@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.
Files changed (44) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.cjs +60 -0
  3. package/.github/workflows/npmpublish.yml +11 -0
  4. package/.github/workflows/prs.yml +13 -0
  5. package/dist/package-lock.json +2 -2
  6. package/dist/package.json +1 -1
  7. package/jest.config.ts +33 -0
  8. package/jest.smoke.config.ts +35 -0
  9. package/package.json +1 -1
  10. package/tests/API/Request.test.ts +273 -0
  11. package/tests/API/Response.test.ts +367 -0
  12. package/tests/API/Utils.test.ts +167 -0
  13. package/tests/BaseEvent/EventProcessor.test.ts +261 -0
  14. package/tests/BaseEvent/Process.test.ts +49 -0
  15. package/tests/BaseEvent/Transaction.test.ts +408 -0
  16. package/tests/Cache/Redis-client.test.ts +90 -0
  17. package/tests/Cache/Redis-cluster.test.ts +100 -0
  18. package/tests/Config/Config.test.ts +205 -0
  19. package/tests/Config/EnvironmentVar.test.ts +250 -0
  20. package/tests/Crypto/Crypto.test.ts +88 -0
  21. package/tests/Crypto/JWT.test.ts +92 -0
  22. package/tests/Database/DatabaseManager.test.ts +71 -0
  23. package/tests/Database/integrations/knex/KnexDatabase.test.ts +76 -0
  24. package/tests/Database/integrations/knex/KnexTransaction.test.ts +149 -0
  25. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  26. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  27. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  28. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  29. package/tests/Logger/Logger.test.ts +219 -0
  30. package/tests/Mailer/Mailer.test.ts +59 -0
  31. package/tests/Publisher/Publisher.test.ts +94 -0
  32. package/tests/Server/RouteResolver.test.ts +102 -0
  33. package/tests/Server/Router.test.ts +39 -0
  34. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  35. package/tests/Server/lib/Server.test.ts +12 -0
  36. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  37. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  38. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  39. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  40. package/tests/Server/lib/container/Utils.test.ts +47 -0
  41. package/tests/Test.utils.ts +74 -0
  42. package/tests/Validation/Validator.test.ts +76 -0
  43. package/tsconfig.json +26 -0
  44. package/tsconfig.smoke.json +26 -0
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ smoke-tests
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
+ }
@@ -0,0 +1,11 @@
1
+ name: NPM Publish
2
+ on:
3
+ push:
4
+ branches: [ "main", "gabe/tweaks" ]
5
+
6
+ jobs:
7
+ Publish:
8
+ uses: Creator-co/tool-github-workflows/.github/workflows/npm-publish.yml@main
9
+ secrets: inherit
10
+ with:
11
+ NODE_VERSION: "20.x"
@@ -0,0 +1,13 @@
1
+ name: PR Checks
2
+ on:
3
+ pull_request:
4
+ branches:
5
+ - master
6
+ - main
7
+
8
+ jobs:
9
+ Checks:
10
+ uses: Creator-co/tool-github-workflows/.github/workflows/prs-check.yml@main
11
+ secrets: inherit
12
+ with:
13
+ NODE_VERSION: "20.x"
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.7.1-alpha4",
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-alpha4",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.7.1-alpha4",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.7.1-alpha4",
3
+ "version": "1.7.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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 {}