@creator.co/wapi 1.2.4 → 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/.github/workflows/npmpublish.yml +1 -1
- package/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +1 -1
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +13 -2
- 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 +104 -2
- package/dist/src/BaseEvent/Transaction.js +196 -41
- 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/Database/Database.d.ts +18 -0
- package/dist/src/Database/Database.js +18 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +32 -0
- package/dist/src/Database/DatabaseManager.js +50 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
- package/dist/src/Database/DatabaseTransaction.js +183 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- 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 +52 -52
- 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/jest.config.ts +1 -1
- package/package.json +13 -2
- 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 +147 -27
- 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/Database/Database.ts +19 -0
- package/src/Database/DatabaseManager.ts +51 -0
- package/src/Database/DatabaseTransaction.ts +118 -0
- package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
- package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
- package/src/Database/types.d.ts +49 -0
- 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 +39 -58
- 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 +102 -44
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Database/DatabaseManager.test.ts +55 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
- 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 +6 -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 { Request, Response } from 'express'
|
|
5
4
|
|
|
6
5
|
import Globals from '../../../../src/Globals'
|
|
@@ -28,11 +27,11 @@ describe('GenericHandler success invocation path', () => {
|
|
|
28
27
|
const resp = observableResponse()
|
|
29
28
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
30
29
|
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
c_expect(handlerResp).to.be.undefined
|
|
31
|
+
expect(resp.send).not.toBeCalled()
|
|
32
|
+
expect(resp.json).toBeCalledWith(JSON.parse(v.body))
|
|
33
|
+
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
34
|
+
expect(resp.header).not.toBeCalled()
|
|
36
35
|
})
|
|
37
36
|
|
|
38
37
|
test('Simple success w/ headers', async () => {
|
|
@@ -47,11 +46,11 @@ describe('GenericHandler success invocation path', () => {
|
|
|
47
46
|
const resp = observableResponse()
|
|
48
47
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
49
48
|
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
c_expect(handlerResp).to.be.undefined
|
|
50
|
+
expect(resp.send).not.toBeCalled()
|
|
51
|
+
expect(resp.json).toBeCalledWith(JSON.parse(v.body))
|
|
52
|
+
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
53
|
+
expect(resp.header).toBeCalledTimes(Object.keys(v.headers).length)
|
|
55
54
|
})
|
|
56
55
|
|
|
57
56
|
test('Simple success w/ null body', async () => {
|
|
@@ -65,11 +64,11 @@ describe('GenericHandler success invocation path', () => {
|
|
|
65
64
|
const resp = observableResponse()
|
|
66
65
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
67
66
|
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
c_expect(handlerResp).to.be.undefined
|
|
68
|
+
expect(resp.send).not.toBeCalled()
|
|
69
|
+
expect(resp.json).toBeCalledWith({})
|
|
70
|
+
expect(resp.status).toBeCalledWith(v.statusCode)
|
|
71
|
+
expect(resp.header).toBeCalledTimes(Object.keys(v.headers).length)
|
|
73
72
|
})
|
|
74
73
|
})
|
|
75
74
|
|
|
@@ -81,14 +80,14 @@ describe('GenericHandler failure invocation path', () => {
|
|
|
81
80
|
const resp = observableResponse()
|
|
82
81
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
83
82
|
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
c_expect(handlerResp).to.be.undefined
|
|
84
|
+
expect(resp.send).not.toBeCalled()
|
|
85
|
+
expect(resp.header).not.toBeCalled()
|
|
86
|
+
expect(resp.json).toBeCalledWith({
|
|
88
87
|
err: Globals.Resp_MSG_INVALIDRESP,
|
|
89
88
|
errCode: Globals.Resp_CODE_INVALIDRESP,
|
|
90
89
|
})
|
|
91
|
-
|
|
90
|
+
expect(resp.status).toBeCalledWith(Globals.Resp_STATUSCODE_INVALIDRESP)
|
|
92
91
|
})
|
|
93
92
|
|
|
94
93
|
test('Error response', async () => {
|
|
@@ -99,13 +98,13 @@ describe('GenericHandler failure invocation path', () => {
|
|
|
99
98
|
const resp = observableResponse()
|
|
100
99
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
101
100
|
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
c_expect(handlerResp).to.be.undefined
|
|
102
|
+
expect(resp.send).not.toBeCalled()
|
|
103
|
+
expect(resp.header).not.toBeCalled()
|
|
104
|
+
expect(resp.json).toBeCalledWith({
|
|
106
105
|
err,
|
|
107
106
|
})
|
|
108
|
-
|
|
107
|
+
expect(resp.status).toBeCalledWith(400)
|
|
109
108
|
})
|
|
110
109
|
|
|
111
110
|
test('Exception response', async () => {
|
|
@@ -116,15 +115,15 @@ describe('GenericHandler failure invocation path', () => {
|
|
|
116
115
|
const resp = observableResponse()
|
|
117
116
|
const handlerResp = await handler(<Request>(<unknown>{}), resp)
|
|
118
117
|
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
c_expect(handlerResp).to.be.undefined
|
|
119
|
+
expect(resp.send).not.toBeCalled()
|
|
120
|
+
expect(resp.header).not.toBeCalled()
|
|
121
|
+
expect(resp.json).toBeCalledWith({
|
|
123
122
|
...err,
|
|
124
123
|
err: Globals.Resp_MSG_EXCEPTION,
|
|
125
124
|
errCode: Globals.Resp_CODE_EXCEPTION,
|
|
126
125
|
})
|
|
127
|
-
|
|
126
|
+
expect(resp.status).toBeCalledWith(Globals.Resp_STATUSCODE_EXCEPTION)
|
|
128
127
|
})
|
|
129
128
|
})
|
|
130
129
|
|
|
@@ -17,7 +17,7 @@ describe('GenericHandlerEvent invocation paths', () => {
|
|
|
17
17
|
)
|
|
18
18
|
const resp = await event.invoke()
|
|
19
19
|
expect(resp).to.not.be.null
|
|
20
|
-
expect(resp.err).to.be.
|
|
20
|
+
expect(resp.err).to.be.undefined
|
|
21
21
|
expect(resp.data).to.be.equals('Success')
|
|
22
22
|
})
|
|
23
23
|
|
|
@@ -94,7 +94,7 @@ describe('GenericHandlerEvent event test', () => {
|
|
|
94
94
|
)
|
|
95
95
|
const resp = await event.invoke()
|
|
96
96
|
expect(resp).to.not.be.null
|
|
97
|
-
expect(resp.err).to.be.
|
|
97
|
+
expect(resp.err).to.be.undefined
|
|
98
98
|
expect(resp.data).to.be.equals('Success')
|
|
99
99
|
})
|
|
100
100
|
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { expect as
|
|
2
|
-
import { expect } from 'chai'
|
|
1
|
+
import { expect as c_expect } from 'chai'
|
|
3
2
|
import { Request, Response } from 'express'
|
|
4
3
|
|
|
5
4
|
import HealthHandler from '../../../../src/Server/lib/container/HealthHandler'
|
|
@@ -19,11 +18,11 @@ describe('HealthHandler invocation path', () => {
|
|
|
19
18
|
const resp = observableResponse()
|
|
20
19
|
const handlerResp = await HealthHandler(<Request>(<unknown>{}), resp)
|
|
21
20
|
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
c_expect(handlerResp).to.be.undefined
|
|
22
|
+
expect(resp.send).toBeCalledWith('Healthy!')
|
|
23
|
+
expect(resp.json).not.toBeCalled()
|
|
24
|
+
expect(resp.status).not.toBeCalled()
|
|
25
|
+
expect(resp.header).not.toBeCalled()
|
|
27
26
|
})
|
|
28
27
|
})
|
|
29
28
|
|
|
@@ -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
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"exclude": ["**/*.test.*", "**/__mocks__/*", "**/__tests__/*", "**/tests/*"],
|
|
2
|
+
"exclude": ["**/*.test.*", "**/__mocks__/*", "**/__tests__/*", "**/tests/*", "./dist/**/*"],
|
|
3
3
|
"compilerOptions": {
|
|
4
|
+
"lib": [
|
|
5
|
+
"es5",
|
|
6
|
+
"es6",
|
|
7
|
+
"dom"
|
|
8
|
+
],
|
|
4
9
|
"noImplicitAny": false,
|
|
5
10
|
"noEmitOnError": true,
|
|
6
11
|
"removeComments": false,
|