@creator.co/wapi 1.2.5 → 1.2.6
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/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +6 -1
- package/dist/src/API/Request.d.ts +45 -82
- package/dist/src/API/Request.js +49 -77
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.d.ts +94 -163
- package/dist/src/API/Response.js +101 -161
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/API/Utils.d.ts +21 -42
- package/dist/src/API/Utils.js +22 -43
- package/dist/src/API/Utils.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
- package/dist/src/BaseEvent/EventProcessor.js +30 -38
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.d.ts +20 -43
- package/dist/src/BaseEvent/Process.js +16 -27
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +94 -2
- package/dist/src/BaseEvent/Transaction.js +49 -4
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Config/Configuration.d.ts +48 -66
- package/dist/src/Config/Configuration.js +25 -42
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.d.ts +30 -57
- package/dist/src/Config/EnvironmentVar.js +28 -41
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +17 -35
- package/dist/src/Crypto/Crypto.js +12 -21
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.d.ts +21 -32
- package/dist/src/Crypto/JWT.js +14 -22
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Globals.d.ts +26 -94
- package/dist/src/Globals.js +26 -95
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.d.ts +82 -105
- package/dist/src/Logger/Logger.js +111 -136
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +39 -75
- package/dist/src/Mailer/Mailer.js +36 -65
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.d.ts +17 -25
- package/dist/src/Publisher/Publisher.js +21 -32
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.d.ts +14 -22
- package/dist/src/Server/RouteResolver.js +21 -34
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +72 -51
- package/dist/src/Server/Router.js +8 -17
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
- package/dist/src/Server/lib/ContainerServer.js +13 -28
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.d.ts +17 -32
- package/dist/src/Server/lib/Server.js +18 -28
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
- package/dist/src/Server/lib/container/GenericHandler.js +16 -3
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
- package/dist/src/Server/lib/container/Proxy.js +49 -50
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.d.ts +6 -10
- package/dist/src/Server/lib/container/Utils.js +6 -10
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.d.ts +9 -13
- package/dist/src/Validation/Validator.js +8 -12
- package/dist/src/Validation/Validator.js.map +1 -1
- package/index.ts +15 -0
- package/package.json +6 -1
- package/src/API/Request.ts +66 -84
- package/src/API/Response.ts +144 -203
- package/src/API/Utils.ts +28 -44
- package/src/BaseEvent/EventProcessor.ts +52 -77
- package/src/BaseEvent/Process.ts +27 -52
- package/src/BaseEvent/Transaction.ts +100 -10
- package/src/Config/Configuration.ts +59 -76
- package/src/Config/EnvironmentVar.ts +39 -62
- package/src/Crypto/Crypto.ts +20 -36
- package/src/Crypto/JWT.ts +31 -35
- package/src/Globals.ts +28 -96
- package/src/Logger/Logger.ts +141 -160
- package/src/Mailer/Mailer.ts +43 -76
- package/src/Publisher/Publisher.ts +31 -40
- package/src/Server/RouteResolver.ts +31 -52
- package/src/Server/Router.ts +75 -54
- package/src/Server/lib/ContainerServer.ts +20 -32
- package/src/Server/lib/Server.ts +19 -34
- package/src/Server/lib/container/GenericHandler.ts +17 -3
- package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
- package/src/Server/lib/container/HealthHandler.ts +6 -0
- package/src/Server/lib/container/Proxy.ts +37 -57
- package/src/Server/lib/container/Utils.ts +7 -10
- package/src/Validation/Validator.ts +11 -13
- package/tests/API/Response.test.ts +55 -56
- package/tests/BaseEvent/EventProcessor.test.ts +49 -50
- package/tests/BaseEvent/Process.test.ts +2 -2
- package/tests/BaseEvent/Transaction.test.ts +48 -49
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Publisher/Publisher.test.ts +3 -3
- package/tests/Server/lib/ContainerServer.test.ts +21 -22
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
- package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
- package/tests/Server/lib/container/Proxy.test.ts +37 -35
- package/tsconfig.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { expect as j_expect } from '@jest/globals'
|
|
2
1
|
import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
3
|
-
import { expect } from 'chai'
|
|
2
|
+
import { expect as c_expect } from 'chai'
|
|
4
3
|
import * as request from 'supertest'
|
|
5
4
|
|
|
6
5
|
import Globals from '../../../../src/Globals'
|
|
@@ -25,21 +24,21 @@ describe('Proxy configs', () => {
|
|
|
25
24
|
const proxy = new Proxy({ routes: [] }, async () => {})
|
|
26
25
|
await proxy.load()
|
|
27
26
|
await proxy.unload('Error')
|
|
28
|
-
|
|
27
|
+
expect(mockExit).toBeCalledWith(1)
|
|
29
28
|
})
|
|
30
29
|
|
|
31
30
|
test('Simple port config', async () => {
|
|
32
31
|
const proxy = new Proxy({ routes: [], port: 56562 }, async () => {})
|
|
33
32
|
await proxy.load()
|
|
34
33
|
await proxy.unload()
|
|
35
|
-
|
|
34
|
+
expect(mockExit).toBeCalledWith(0)
|
|
36
35
|
})
|
|
37
36
|
|
|
38
37
|
test('Simple timeout config', async () => {
|
|
39
38
|
const proxy = new Proxy({ routes: [], timeout: 1000 }, async () => {})
|
|
40
39
|
await proxy.load()
|
|
41
40
|
await proxy.unload()
|
|
42
|
-
|
|
41
|
+
expect(mockExit).toBeCalledWith(0)
|
|
43
42
|
})
|
|
44
43
|
|
|
45
44
|
test('Simple cors config', async () => {
|
|
@@ -56,7 +55,7 @@ describe('Proxy configs', () => {
|
|
|
56
55
|
)
|
|
57
56
|
await proxy.load()
|
|
58
57
|
await proxy.unload()
|
|
59
|
-
|
|
58
|
+
expect(mockExit).toBeCalledWith(0)
|
|
60
59
|
})
|
|
61
60
|
|
|
62
61
|
test('Empty cors config', async () => {
|
|
@@ -69,7 +68,7 @@ describe('Proxy configs', () => {
|
|
|
69
68
|
)
|
|
70
69
|
await proxy.load()
|
|
71
70
|
await proxy.unload()
|
|
72
|
-
|
|
71
|
+
expect(mockExit).toBeCalledWith(0)
|
|
73
72
|
})
|
|
74
73
|
})
|
|
75
74
|
|
|
@@ -91,8 +90,8 @@ describe('Proxy behaviour', () => {
|
|
|
91
90
|
const proxy = new Proxy({ routes: [] }, async () => {})
|
|
92
91
|
await proxy.load()
|
|
93
92
|
await Promise.all([proxy.unload('Error'), proxy.unload('Error')])
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
94
|
+
expect(mockExit).toBeCalledWith(1)
|
|
96
95
|
})
|
|
97
96
|
})
|
|
98
97
|
|
|
@@ -128,19 +127,19 @@ describe('Proxy routing', () => {
|
|
|
128
127
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
129
128
|
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
130
129
|
.expect(200)
|
|
131
|
-
|
|
130
|
+
c_expect(res.text).to.be.equals('Healthy!')
|
|
132
131
|
// Generic handler
|
|
133
132
|
const resG = await request(defaultUrl)
|
|
134
133
|
.get(`/abc`)
|
|
135
134
|
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
136
135
|
.expect(200)
|
|
137
|
-
|
|
136
|
+
c_expect(resG.body).to.be.deep.equals({ name: '123' })
|
|
138
137
|
// Expected count
|
|
139
|
-
|
|
138
|
+
c_expect(count).to.be.equals(1)
|
|
140
139
|
// Unload
|
|
141
140
|
await proxy.unload('Error')
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
142
|
+
expect(mockExit).toBeCalledWith(1)
|
|
144
143
|
})
|
|
145
144
|
|
|
146
145
|
test('Proxy on custom port', async () => {
|
|
@@ -163,19 +162,19 @@ describe('Proxy routing', () => {
|
|
|
163
162
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
164
163
|
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
165
164
|
.expect(200)
|
|
166
|
-
|
|
165
|
+
c_expect(res.text).to.be.equals('Healthy!')
|
|
167
166
|
// Generic handler
|
|
168
167
|
const resG = await request(url)
|
|
169
168
|
.get(`/abc`)
|
|
170
169
|
.expect('Content-Type', 'application/json; charset=utf-8')
|
|
171
170
|
.expect(200)
|
|
172
|
-
|
|
171
|
+
c_expect(resG.body).to.be.deep.equals({ name: '123' })
|
|
173
172
|
// Expected count
|
|
174
|
-
|
|
173
|
+
c_expect(count).to.be.equals(1)
|
|
175
174
|
// Unload
|
|
176
175
|
await proxy.unload()
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
177
|
+
expect(mockExit).toBeCalledWith(0)
|
|
179
178
|
})
|
|
180
179
|
|
|
181
180
|
test('Proxy does timeout', async () => {
|
|
@@ -199,7 +198,7 @@ describe('Proxy routing', () => {
|
|
|
199
198
|
.get(Globals.Listener_HTTP_DefaultHealthCheckRoute)
|
|
200
199
|
.expect('Content-Type', 'text/html; charset=utf-8')
|
|
201
200
|
.expect(200)
|
|
202
|
-
|
|
201
|
+
c_expect(res.text).to.be.equals('Healthy!')
|
|
203
202
|
// Generic handler
|
|
204
203
|
let err: any = null
|
|
205
204
|
try {
|
|
@@ -210,13 +209,13 @@ describe('Proxy routing', () => {
|
|
|
210
209
|
} catch (e) {
|
|
211
210
|
err = e
|
|
212
211
|
}
|
|
213
|
-
|
|
212
|
+
c_expect(err?.message).to.be.equals('socket hang up')
|
|
214
213
|
// Expected count
|
|
215
|
-
|
|
214
|
+
c_expect(count).to.be.equals(1)
|
|
216
215
|
// Unload
|
|
217
216
|
await proxy.unload('Error')
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
218
|
+
expect(mockExit).toBeCalledWith(1)
|
|
220
219
|
//
|
|
221
220
|
return new Promise(resolve => {
|
|
222
221
|
setTimeout(resolve, timeout * 2)
|
|
@@ -244,21 +243,24 @@ describe('Proxy routing', () => {
|
|
|
244
243
|
)
|
|
245
244
|
await proxy.load()
|
|
246
245
|
// White-listed header is allowed
|
|
247
|
-
const resWH = await request(defaultUrl).options(`/abc`).set('Authorization', 123).expect(204)
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
const resWH = await request(defaultUrl).options(`/abc`).set('Authorization', '123').expect(204)
|
|
247
|
+
c_expect(resWH.header['access-control-allow-origin']).to.equal('*')
|
|
248
|
+
c_expect(resWH.header['access-control-allow-credentials']).to.equal('true')
|
|
249
|
+
c_expect(resWH.header['access-control-allow-headers']).to.equal('Authorization')
|
|
251
250
|
// Non white-listed header is allowed
|
|
252
|
-
const resNWH = await request(defaultUrl)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
251
|
+
const resNWH = await request(defaultUrl)
|
|
252
|
+
.options(`/abc`)
|
|
253
|
+
.set('2Authorization2', '123')
|
|
254
|
+
.expect(204)
|
|
255
|
+
c_expect(resNWH.header['access-control-allow-origin']).to.equal('*')
|
|
256
|
+
c_expect(resNWH.header['access-control-allow-credentials']).to.equal('true')
|
|
257
|
+
c_expect(resNWH.header['access-control-allow-headers']).to.equal('Authorization')
|
|
256
258
|
// Expected count
|
|
257
|
-
|
|
259
|
+
c_expect(count).to.be.equals(0)
|
|
258
260
|
// Unload
|
|
259
261
|
await proxy.unload()
|
|
260
|
-
|
|
261
|
-
|
|
262
|
+
expect(mockExit).toHaveBeenCalledTimes(1)
|
|
263
|
+
expect(mockExit).toBeCalledWith(0)
|
|
262
264
|
})
|
|
263
265
|
})
|
|
264
266
|
|
package/tsconfig.json
CHANGED