@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.
Files changed (153) hide show
  1. package/.github/workflows/npmpublish.yml +1 -1
  2. package/README.md +216 -5
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/jest.config.js +1 -1
  6. package/dist/jest.config.js.map +1 -1
  7. package/dist/package.json +13 -2
  8. package/dist/src/API/Request.d.ts +45 -82
  9. package/dist/src/API/Request.js +49 -77
  10. package/dist/src/API/Request.js.map +1 -1
  11. package/dist/src/API/Response.d.ts +94 -163
  12. package/dist/src/API/Response.js +101 -161
  13. package/dist/src/API/Response.js.map +1 -1
  14. package/dist/src/API/Utils.d.ts +21 -42
  15. package/dist/src/API/Utils.js +22 -43
  16. package/dist/src/API/Utils.js.map +1 -1
  17. package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
  18. package/dist/src/BaseEvent/EventProcessor.js +30 -38
  19. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  20. package/dist/src/BaseEvent/Process.d.ts +20 -43
  21. package/dist/src/BaseEvent/Process.js +16 -27
  22. package/dist/src/BaseEvent/Process.js.map +1 -1
  23. package/dist/src/BaseEvent/Transaction.d.ts +104 -2
  24. package/dist/src/BaseEvent/Transaction.js +196 -41
  25. package/dist/src/BaseEvent/Transaction.js.map +1 -1
  26. package/dist/src/Config/Configuration.d.ts +48 -66
  27. package/dist/src/Config/Configuration.js +25 -42
  28. package/dist/src/Config/Configuration.js.map +1 -1
  29. package/dist/src/Config/EnvironmentVar.d.ts +30 -57
  30. package/dist/src/Config/EnvironmentVar.js +28 -41
  31. package/dist/src/Config/EnvironmentVar.js.map +1 -1
  32. package/dist/src/Crypto/Crypto.d.ts +17 -35
  33. package/dist/src/Crypto/Crypto.js +12 -21
  34. package/dist/src/Crypto/Crypto.js.map +1 -1
  35. package/dist/src/Crypto/JWT.d.ts +21 -32
  36. package/dist/src/Crypto/JWT.js +14 -22
  37. package/dist/src/Crypto/JWT.js.map +1 -1
  38. package/dist/src/Database/Database.d.ts +18 -0
  39. package/dist/src/Database/Database.js +18 -0
  40. package/dist/src/Database/Database.js.map +1 -0
  41. package/dist/src/Database/DatabaseManager.d.ts +32 -0
  42. package/dist/src/Database/DatabaseManager.js +50 -0
  43. package/dist/src/Database/DatabaseManager.js.map +1 -0
  44. package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
  45. package/dist/src/Database/DatabaseTransaction.js +183 -0
  46. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  47. package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
  48. package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
  49. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
  50. package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
  51. package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
  52. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
  53. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
  54. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
  55. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  56. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
  57. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
  58. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  59. package/dist/src/Globals.d.ts +26 -94
  60. package/dist/src/Globals.js +26 -95
  61. package/dist/src/Globals.js.map +1 -1
  62. package/dist/src/Logger/Logger.d.ts +82 -105
  63. package/dist/src/Logger/Logger.js +111 -136
  64. package/dist/src/Logger/Logger.js.map +1 -1
  65. package/dist/src/Mailer/Mailer.d.ts +39 -75
  66. package/dist/src/Mailer/Mailer.js +36 -65
  67. package/dist/src/Mailer/Mailer.js.map +1 -1
  68. package/dist/src/Publisher/Publisher.d.ts +17 -25
  69. package/dist/src/Publisher/Publisher.js +21 -32
  70. package/dist/src/Publisher/Publisher.js.map +1 -1
  71. package/dist/src/Server/RouteResolver.d.ts +14 -22
  72. package/dist/src/Server/RouteResolver.js +21 -34
  73. package/dist/src/Server/RouteResolver.js.map +1 -1
  74. package/dist/src/Server/Router.d.ts +72 -51
  75. package/dist/src/Server/Router.js +8 -17
  76. package/dist/src/Server/Router.js.map +1 -1
  77. package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
  78. package/dist/src/Server/lib/ContainerServer.js +13 -28
  79. package/dist/src/Server/lib/ContainerServer.js.map +1 -1
  80. package/dist/src/Server/lib/Server.d.ts +17 -32
  81. package/dist/src/Server/lib/Server.js +18 -28
  82. package/dist/src/Server/lib/Server.js.map +1 -1
  83. package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
  84. package/dist/src/Server/lib/container/GenericHandler.js +16 -3
  85. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
  86. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
  87. package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
  88. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  89. package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
  90. package/dist/src/Server/lib/container/HealthHandler.js +6 -0
  91. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
  92. package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
  93. package/dist/src/Server/lib/container/Proxy.js +52 -52
  94. package/dist/src/Server/lib/container/Proxy.js.map +1 -1
  95. package/dist/src/Server/lib/container/Utils.d.ts +6 -10
  96. package/dist/src/Server/lib/container/Utils.js +6 -10
  97. package/dist/src/Server/lib/container/Utils.js.map +1 -1
  98. package/dist/src/Validation/Validator.d.ts +9 -13
  99. package/dist/src/Validation/Validator.js +8 -12
  100. package/dist/src/Validation/Validator.js.map +1 -1
  101. package/index.ts +15 -0
  102. package/jest.config.ts +1 -1
  103. package/package.json +13 -2
  104. package/src/API/Request.ts +66 -84
  105. package/src/API/Response.ts +144 -203
  106. package/src/API/Utils.ts +28 -44
  107. package/src/BaseEvent/EventProcessor.ts +52 -77
  108. package/src/BaseEvent/Process.ts +27 -52
  109. package/src/BaseEvent/Transaction.ts +147 -27
  110. package/src/Config/Configuration.ts +59 -76
  111. package/src/Config/EnvironmentVar.ts +39 -62
  112. package/src/Crypto/Crypto.ts +20 -36
  113. package/src/Crypto/JWT.ts +31 -35
  114. package/src/Database/Database.ts +19 -0
  115. package/src/Database/DatabaseManager.ts +51 -0
  116. package/src/Database/DatabaseTransaction.ts +118 -0
  117. package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
  118. package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
  119. package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
  120. package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
  121. package/src/Database/types.d.ts +49 -0
  122. package/src/Globals.ts +28 -96
  123. package/src/Logger/Logger.ts +141 -160
  124. package/src/Mailer/Mailer.ts +43 -76
  125. package/src/Publisher/Publisher.ts +31 -40
  126. package/src/Server/RouteResolver.ts +31 -52
  127. package/src/Server/Router.ts +75 -54
  128. package/src/Server/lib/ContainerServer.ts +20 -32
  129. package/src/Server/lib/Server.ts +19 -34
  130. package/src/Server/lib/container/GenericHandler.ts +17 -3
  131. package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
  132. package/src/Server/lib/container/HealthHandler.ts +6 -0
  133. package/src/Server/lib/container/Proxy.ts +39 -58
  134. package/src/Server/lib/container/Utils.ts +7 -10
  135. package/src/Validation/Validator.ts +11 -13
  136. package/tests/API/Response.test.ts +55 -56
  137. package/tests/BaseEvent/EventProcessor.test.ts +49 -50
  138. package/tests/BaseEvent/Process.test.ts +2 -2
  139. package/tests/BaseEvent/Transaction.test.ts +102 -44
  140. package/tests/Config/Config.test.ts +27 -27
  141. package/tests/Config/EnvironmentVar.test.ts +54 -18
  142. package/tests/Database/DatabaseManager.test.ts +55 -0
  143. package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
  144. package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
  145. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
  146. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
  147. package/tests/Publisher/Publisher.test.ts +3 -3
  148. package/tests/Server/lib/ContainerServer.test.ts +21 -22
  149. package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
  150. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
  151. package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
  152. package/tests/Server/lib/container/Proxy.test.ts +37 -35
  153. package/tsconfig.json +6 -1
@@ -1,5 +1,4 @@
1
- import { expect as j_expect } from '@jest/globals'
2
- import { expect } from 'chai'
1
+ import { expect as c_expect } from 'chai'
3
2
 
4
3
  import Response from '../../src/API/Response'
5
4
  import EventProcessor from '../../src/BaseEvent/EventProcessor'
@@ -19,23 +18,23 @@ describe('EventProcessor success invocation path', () => {
19
18
  )
20
19
  let count = 0
21
20
  const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
22
- expect(eventRecord).to.be.deep.equal(b)
21
+ c_expect(eventRecord).to.be.deep.equal(b)
23
22
  count++
24
23
  return Response.SuccessResponse(null)
25
24
  })
26
25
  // check resp
27
- expect(count).to.be.equals(2)
28
- expect(handlerResp).to.be.an.instanceof(Response)
26
+ c_expect(count).to.be.equals(2)
27
+ c_expect(handlerResp).to.be.an.instanceof(Response)
29
28
  if (handlerResp instanceof Response) {
30
- expect(handlerResp?.getBody()).to.be.deep.equal({
29
+ c_expect(handlerResp?.getBody()).to.be.deep.equal({
31
30
  transactionID: 'unknown',
32
31
  })
33
- expect(handlerResp.getCode()).to.be.equal(200)
32
+ c_expect(handlerResp.getCode()).to.be.equal(200)
34
33
  }
35
34
  // ctx
36
- j_expect(context.fail).not.toBeCalled()
37
- j_expect(context.done).not.toBeCalled()
38
- j_expect(context.succeed).not.toBeCalled()
35
+ expect(context.fail).not.toBeCalled()
36
+ expect(context.done).not.toBeCalled()
37
+ expect(context.succeed).not.toBeCalled()
39
38
  })
40
39
 
41
40
  test('Simple success - do not decode', async () => {
@@ -50,23 +49,23 @@ describe('EventProcessor success invocation path', () => {
50
49
  )
51
50
  let count = 0
52
51
  const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
53
- expect(eventRecord).to.be.deep.equal(JSON.stringify(b))
52
+ c_expect(eventRecord).to.be.deep.equal(JSON.stringify(b))
54
53
  count++
55
54
  return Response.SuccessResponse(null)
56
55
  }, true)
57
56
  // check resp
58
- expect(count).to.be.equals(2)
59
- expect(handlerResp).to.be.an.instanceof(Response)
57
+ c_expect(count).to.be.equals(2)
58
+ c_expect(handlerResp).to.be.an.instanceof(Response)
60
59
  if (handlerResp instanceof Response) {
61
- expect(handlerResp?.getBody()).to.be.deep.equal({
60
+ c_expect(handlerResp?.getBody()).to.be.deep.equal({
62
61
  transactionID: 'unknown',
63
62
  })
64
- expect(handlerResp.getCode()).to.be.equal(200)
63
+ c_expect(handlerResp.getCode()).to.be.equal(200)
65
64
  }
66
65
  // ctx
67
- j_expect(context.fail).not.toBeCalled()
68
- j_expect(context.done).not.toBeCalled()
69
- j_expect(context.succeed).not.toBeCalled()
66
+ expect(context.fail).not.toBeCalled()
67
+ expect(context.done).not.toBeCalled()
68
+ expect(context.succeed).not.toBeCalled()
70
69
  })
71
70
  })
72
71
 
@@ -90,7 +89,7 @@ describe('EventProcessor failure invocation path', () => {
90
89
  err: any = null
91
90
  try {
92
91
  handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
93
- expect(eventRecord).to.be.deep.equal(b)
92
+ c_expect(eventRecord).to.be.deep.equal(b)
94
93
  count++
95
94
  return count == 1 ? Response.SuccessResponse(null) : Response.BadRequestResponse('Failed!')
96
95
  })
@@ -98,9 +97,9 @@ describe('EventProcessor failure invocation path', () => {
98
97
  err = e
99
98
  }
100
99
  // check resp
101
- expect(count).to.be.equals(2)
102
- expect(handlerResp).to.be.null
103
- expect(err).to.be.deep.equal(
100
+ c_expect(count).to.be.equals(2)
101
+ c_expect(handlerResp).to.be.null
102
+ c_expect(err).to.be.deep.equal(
104
103
  new Error(
105
104
  JSON.stringify({
106
105
  err: 'Failed!',
@@ -109,9 +108,9 @@ describe('EventProcessor failure invocation path', () => {
109
108
  )
110
109
  )
111
110
  // ctx
112
- j_expect(context.fail).not.toBeCalled()
113
- j_expect(context.done).not.toBeCalled()
114
- j_expect(context.succeed).not.toBeCalled()
111
+ expect(context.fail).not.toBeCalled()
112
+ expect(context.done).not.toBeCalled()
113
+ expect(context.succeed).not.toBeCalled()
115
114
  })
116
115
 
117
116
  test('Simple failure w/ null', async () => {
@@ -135,7 +134,7 @@ describe('EventProcessor failure invocation path', () => {
135
134
  handlerResp = await transaction.processEvent(
136
135
  // @ts-ignore
137
136
  async (transaction, eventRecord) => {
138
- expect(eventRecord).to.be.deep.equal(b)
137
+ c_expect(eventRecord).to.be.deep.equal(b)
139
138
  count++
140
139
  return null
141
140
  }
@@ -144,9 +143,9 @@ describe('EventProcessor failure invocation path', () => {
144
143
  err = e
145
144
  }
146
145
  // check resp
147
- expect(count).to.be.equals(1)
148
- expect(handlerResp).to.be.null
149
- expect(err).to.be.deep.equal(
146
+ c_expect(count).to.be.equals(1)
147
+ c_expect(handlerResp).to.be.null
148
+ c_expect(err).to.be.deep.equal(
150
149
  new Error(
151
150
  JSON.stringify({
152
151
  err: Globals.ErrorResponseInvalidServerResponse,
@@ -157,9 +156,9 @@ describe('EventProcessor failure invocation path', () => {
157
156
  )
158
157
  )
159
158
  // ctx
160
- j_expect(context.fail).not.toBeCalled()
161
- j_expect(context.done).not.toBeCalled()
162
- j_expect(context.succeed).not.toBeCalled()
159
+ expect(context.fail).not.toBeCalled()
160
+ expect(context.done).not.toBeCalled()
161
+ expect(context.succeed).not.toBeCalled()
163
162
  })
164
163
 
165
164
  test('Simple failure - allow failures', async () => {
@@ -175,19 +174,19 @@ describe('EventProcessor failure invocation path', () => {
175
174
  )
176
175
  let count = 0
177
176
  const handlerResp = await transaction.processEvent(async (transaction, eventRecord) => {
178
- expect(eventRecord).to.be.deep.equal(b)
177
+ c_expect(eventRecord).to.be.deep.equal(b)
179
178
  count++
180
179
  return count == 1 ? Response.SuccessResponse(null) : Response.BadRequestResponse('Failed!')
181
180
  })
182
181
  // check resp
183
- expect(count).to.be.equals(2)
184
- expect(handlerResp).to.be.deep.equal({
182
+ c_expect(count).to.be.equals(2)
183
+ c_expect(handlerResp).to.be.deep.equal({
185
184
  batchItemFailures: [{ itemIdentifier: '123' }],
186
185
  })
187
186
  // ctx
188
- j_expect(context.fail).not.toBeCalled()
189
- j_expect(context.done).not.toBeCalled()
190
- j_expect(context.succeed).not.toBeCalled()
187
+ expect(context.fail).not.toBeCalled()
188
+ expect(context.done).not.toBeCalled()
189
+ expect(context.succeed).not.toBeCalled()
191
190
  })
192
191
 
193
192
  test('Simple failure w/ null response - allow failures', async () => {
@@ -208,20 +207,20 @@ describe('EventProcessor failure invocation path', () => {
208
207
  const handlerResp = await transaction.processEvent(
209
208
  // @ts-ignore
210
209
  async (transaction, eventRecord) => {
211
- expect(eventRecord).to.be.deep.equal(b)
210
+ c_expect(eventRecord).to.be.deep.equal(b)
212
211
  count++
213
212
  return null
214
213
  }
215
214
  )
216
215
  // check resp
217
- expect(count).to.be.equals(2)
218
- expect(handlerResp).to.be.deep.equal({
216
+ c_expect(count).to.be.equals(2)
217
+ c_expect(handlerResp).to.be.deep.equal({
219
218
  batchItemFailures: [{ itemIdentifier: '456' }, { itemIdentifier: '123' }],
220
219
  })
221
220
  // ctx
222
- j_expect(context.fail).not.toBeCalled()
223
- j_expect(context.done).not.toBeCalled()
224
- j_expect(context.succeed).not.toBeCalled()
221
+ expect(context.fail).not.toBeCalled()
222
+ expect(context.done).not.toBeCalled()
223
+ expect(context.succeed).not.toBeCalled()
225
224
  })
226
225
 
227
226
  test('Simple failure no records', async () => {
@@ -242,9 +241,9 @@ describe('EventProcessor failure invocation path', () => {
242
241
  err = e
243
242
  }
244
243
  // check resp
245
- expect(count).to.be.equals(0)
246
- expect(handlerResp).to.be.null
247
- expect(err).to.be.deep.equal(
244
+ c_expect(count).to.be.equals(0)
245
+ c_expect(handlerResp).to.be.null
246
+ c_expect(err).to.be.deep.equal(
248
247
  new Error(
249
248
  JSON.stringify({
250
249
  err: Globals.ErrorResponseNoRecords,
@@ -253,9 +252,9 @@ describe('EventProcessor failure invocation path', () => {
253
252
  )
254
253
  )
255
254
  // ctx
256
- j_expect(context.fail).not.toBeCalled()
257
- j_expect(context.done).not.toBeCalled()
258
- j_expect(context.succeed).not.toBeCalled()
255
+ expect(context.fail).not.toBeCalled()
256
+ expect(context.done).not.toBeCalled()
257
+ expect(context.succeed).not.toBeCalled()
259
258
  })
260
259
  })
261
260
 
@@ -18,7 +18,7 @@ describe('Process success invocation path', () => {
18
18
  return new Promise(resolve => {
19
19
  setTimeout(() => {
20
20
  expect(count).to.be.equals(2)
21
- clearInterval(proc.interval)
21
+ clearInterval(proc.timeout)
22
22
  resolve(null)
23
23
  }, 250)
24
24
  })
@@ -39,7 +39,7 @@ describe('Process failure invocation path', () => {
39
39
  return new Promise(resolve => {
40
40
  setTimeout(() => {
41
41
  expect(count).to.be.equals(2)
42
- clearInterval(proc.interval)
42
+ clearInterval(proc.timeout)
43
43
  resolve(null)
44
44
  }, 250)
45
45
  })
@@ -1,8 +1,8 @@
1
- import { expect as j_expect } from '@jest/globals'
2
- import { expect } from 'chai'
1
+ import { expect as c_expect } from 'chai'
3
2
 
4
3
  import Response from '../../src/API/Response'
5
4
  import Transaction from '../../src/BaseEvent/Transaction'
5
+ import type { DbConfig } from '../../src/Database/types'
6
6
  import Globals from '../../src/Globals'
7
7
  import { defaultHeaders, emptyEvent, observableContext } from '../Test.utils'
8
8
 
@@ -15,11 +15,11 @@ describe('Transaction success invocation path', () => {
15
15
  return Response.SuccessResponse(b)
16
16
  })
17
17
  // check resp
18
- expect(handlerResp).to.be.null
18
+ c_expect(handlerResp).to.be.null
19
19
  // ctx
20
- j_expect(context.fail).not.toBeCalled()
21
- j_expect(context.done).not.toBeCalled()
22
- j_expect(context.succeed).toBeCalledWith({
20
+ expect(context.fail).not.toBeCalled()
21
+ expect(context.done).not.toBeCalled()
22
+ expect(context.succeed).toBeCalledWith({
23
23
  statusCode: 200,
24
24
  body: JSON.stringify(b),
25
25
  headers: defaultHeaders,
@@ -36,13 +36,13 @@ describe('Transaction success invocation path', () => {
36
36
  return Response.SuccessResponse(b)
37
37
  })
38
38
  // check resp
39
- expect(handlerResp).to.be.an.instanceof(Response)
40
- expect(handlerResp?.getBody()).to.be.deep.equals(b)
41
- expect(handlerResp?.getCode()).to.be.equals(200)
39
+ c_expect(handlerResp).to.be.an.instanceof(Response)
40
+ c_expect(handlerResp?.getBody()).to.be.deep.equals(b)
41
+ c_expect(handlerResp?.getCode()).to.be.equals(200)
42
42
  // ctx
43
- j_expect(context.fail).not.toBeCalled()
44
- j_expect(context.done).not.toBeCalled()
45
- j_expect(context.succeed).not.toBeCalled()
43
+ expect(context.fail).not.toBeCalled()
44
+ expect(context.done).not.toBeCalled()
45
+ expect(context.succeed).not.toBeCalled()
46
46
  })
47
47
  })
48
48
 
@@ -60,11 +60,11 @@ describe('Transaction error invocation path without response', () => {
60
60
  return null
61
61
  })
62
62
  // check resp
63
- expect(handlerResp).to.be.null
63
+ c_expect(handlerResp).to.be.null
64
64
  // ctx
65
- j_expect(context.fail).not.toBeCalled()
66
- j_expect(context.done).not.toBeCalled()
67
- j_expect(context.succeed).toBeCalledWith({
65
+ expect(context.fail).not.toBeCalled()
66
+ expect(context.done).not.toBeCalled()
67
+ expect(context.succeed).toBeCalledWith({
68
68
  statusCode: 400,
69
69
  body: JSON.stringify(b),
70
70
  headers: defaultHeaders,
@@ -92,13 +92,13 @@ describe('Transaction error invocation path without response', () => {
92
92
  return null
93
93
  })
94
94
  // check resp
95
- expect(handlerResp).to.be.an.instanceof(Response)
96
- expect(handlerResp?.getBody()).to.be.deep.equals(b)
97
- expect(handlerResp?.getCode()).to.be.equals(400)
95
+ c_expect(handlerResp).to.be.an.instanceof(Response)
96
+ c_expect(handlerResp?.getBody()).to.be.deep.equals(b)
97
+ c_expect(handlerResp?.getCode()).to.be.equals(400)
98
98
  // ctx
99
- j_expect(context.fail).not.toBeCalled()
100
- j_expect(context.done).not.toBeCalled()
101
- j_expect(context.succeed).not.toBeCalled()
99
+ expect(context.fail).not.toBeCalled()
100
+ expect(context.done).not.toBeCalled()
101
+ expect(context.succeed).not.toBeCalled()
102
102
  })
103
103
  })
104
104
 
@@ -117,11 +117,11 @@ describe('Transaction error invocation path with non-Response class response', (
117
117
  return b2
118
118
  })
119
119
  // check resp
120
- expect(handlerResp).to.be.null
120
+ c_expect(handlerResp).to.be.null
121
121
  // ctx
122
- j_expect(context.fail).not.toBeCalled()
123
- j_expect(context.done).not.toBeCalled()
124
- j_expect(context.succeed).toBeCalledWith({
122
+ expect(context.fail).not.toBeCalled()
123
+ expect(context.done).not.toBeCalled()
124
+ expect(context.succeed).toBeCalledWith({
125
125
  statusCode: 400,
126
126
  body: JSON.stringify(b),
127
127
  headers: defaultHeaders,
@@ -138,11 +138,11 @@ describe('Transaction error invocation path with non-Response class response', (
138
138
  return b2
139
139
  })
140
140
  // check resp
141
- expect(handlerResp).to.be.deep.equals(b2)
141
+ c_expect(handlerResp).to.be.deep.equals(b2)
142
142
  // ctx
143
- j_expect(context.fail).not.toBeCalled()
144
- j_expect(context.done).not.toBeCalled()
145
- j_expect(context.succeed).not.toBeCalled()
143
+ expect(context.fail).not.toBeCalled()
144
+ expect(context.done).not.toBeCalled()
145
+ expect(context.succeed).not.toBeCalled()
146
146
  })
147
147
  })
148
148
 
@@ -160,11 +160,11 @@ describe('Transaction error invocation path with exception', () => {
160
160
  throw new Error('Failed!')
161
161
  })
162
162
  // check resp
163
- expect(handlerResp).to.be.null
163
+ c_expect(handlerResp).to.be.null
164
164
  // ctx
165
- j_expect(context.fail).not.toBeCalled()
166
- j_expect(context.done).not.toBeCalled()
167
- j_expect(context.succeed).toBeCalledWith({
165
+ expect(context.fail).not.toBeCalled()
166
+ expect(context.done).not.toBeCalled()
167
+ expect(context.succeed).toBeCalledWith({
168
168
  statusCode: 400,
169
169
  body: JSON.stringify(b),
170
170
  headers: defaultHeaders,
@@ -186,12 +186,12 @@ describe('Transaction error invocation path with exception', () => {
186
186
  throw new Error('Failed!')
187
187
  })
188
188
  // check resp
189
- expect(handlerResp?.getBody()).to.be.deep.equals(b)
190
- expect(handlerResp?.getCode()).to.be.equals(400)
189
+ c_expect(handlerResp?.getBody()).to.be.deep.equals(b)
190
+ c_expect(handlerResp?.getCode()).to.be.equals(400)
191
191
  // ctx
192
- j_expect(context.fail).not.toBeCalled()
193
- j_expect(context.done).not.toBeCalled()
194
- j_expect(context.succeed).not.toBeCalled()
192
+ expect(context.fail).not.toBeCalled()
193
+ expect(context.done).not.toBeCalled()
194
+ expect(context.succeed).not.toBeCalled()
195
195
  })
196
196
 
197
197
  test('Transaction exception - sync return', async () => {
@@ -210,12 +210,70 @@ describe('Transaction error invocation path with exception', () => {
210
210
  err = e
211
211
  }
212
212
  // check resp
213
- expect(handlerResp).to.be.null
214
- expect(err).to.be.deep.equals(error)
213
+ c_expect(handlerResp).to.be.null
214
+ c_expect(err).to.be.deep.equals(error)
215
215
  // ctx
216
- j_expect(context.fail).not.toBeCalled()
217
- j_expect(context.done).not.toBeCalled()
218
- j_expect(context.succeed).not.toBeCalled()
216
+ expect(context.fail).not.toBeCalled()
217
+ expect(context.done).not.toBeCalled()
218
+ expect(context.succeed).not.toBeCalled()
219
+ })
220
+ })
221
+
222
+ describe('Transaction - db integration', () => {
223
+ const testResources = () => {
224
+ const mockTrans = {
225
+ select: jest.fn(),
226
+ closeSuccess: jest.fn(),
227
+ closeFailure: jest.fn(),
228
+ }
229
+ const mockCreate = jest.fn(
230
+ () => ({ transaction: () => new Promise(resolve => resolve(mockTrans)) }) as any
231
+ )
232
+
233
+ const transaction = new Transaction(emptyEvent(), observableContext())
234
+ transaction['databaseManager'] = {
235
+ create: mockCreate,
236
+ } as any
237
+
238
+ return {
239
+ transaction,
240
+ mockCreate,
241
+ mockTrans,
242
+ }
243
+ }
244
+
245
+ const config = { username: 'test' } as DbConfig<'knex'>
246
+
247
+ test('Transaction provides dbTransaction and calls closeSuccess', async () => {
248
+ const { mockCreate, mockTrans, transaction } = testResources()
249
+
250
+ await transaction.execute(async () => {
251
+ const knexTransaction = await transaction.getDbTransaction(config)
252
+
253
+ knexTransaction.select('name')
254
+
255
+ return Response.SuccessResponse(null)
256
+ })
257
+ expect(mockCreate).toBeCalledWith(config)
258
+ expect(mockTrans.select).toBeCalledWith('name')
259
+ expect(mockTrans.closeSuccess).toBeCalled()
260
+ })
261
+
262
+ test('Errored transaction calls closeFailure', async () => {
263
+ const { mockCreate, transaction, mockTrans } = testResources()
264
+
265
+ const ss = await transaction.execute(async () => {
266
+ const _ii = await transaction.getDbTransaction(config)
267
+ console.log('ii', _ii)
268
+ throw new Error('Something went wrong!')
269
+
270
+ return Response.SuccessResponse(null)
271
+ })
272
+
273
+ console.log(ss)
274
+
275
+ expect(mockCreate).toBeCalledWith(config)
276
+ expect(mockTrans.closeFailure).toBeCalled()
219
277
  })
220
278
  })
221
279
 
@@ -1,6 +1,6 @@
1
1
  import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
2
2
  import { mockClient } from 'aws-sdk-client-mock'
3
- import { expect } from 'chai'
3
+ import { expect as c_expect } from 'chai'
4
4
 
5
5
  import Configuration from '../../src/Config/Configuration'
6
6
  import { SampleConfig, SampleConfigSchema } from '../Test.utils'
@@ -22,8 +22,8 @@ describe(`Optional remote environment`, () => {
22
22
  } catch (e) {
23
23
  err = e
24
24
  }
25
- expect(err).is.not.null
26
- expect(err?.['message']).is.not.null
25
+ c_expect(err).is.not.null
26
+ c_expect(err?.['message']).is.not.null
27
27
  })
28
28
 
29
29
  test('Optional value with null value', async () => {
@@ -33,13 +33,13 @@ describe(`Optional remote environment`, () => {
33
33
  },
34
34
  })
35
35
  const token = await config.asyncGet('TOKEN_SECRET_FALSY')
36
- expect(token).is.undefined
36
+ c_expect(token).is.undefined
37
37
  })
38
38
 
39
39
  test('Optional value with empty response', async () => {
40
40
  SSMMock.on(GetParameterCommand).resolves({})
41
41
  const token = await config.asyncGet('TOKEN_SECRET_FALSY')
42
- expect(token).is.undefined
42
+ c_expect(token).is.undefined
43
43
  })
44
44
 
45
45
  test('Optional value with valid response', async () => {
@@ -50,14 +50,14 @@ describe(`Optional remote environment`, () => {
50
50
  },
51
51
  })
52
52
  const token = await config.asyncGet('TOKEN_SECRET_FALSY')
53
- expect(token).is.not.undefined
54
- expect(token).to.be.equals(value)
53
+ c_expect(token).is.not.undefined
54
+ c_expect(token).to.be.equals(value)
55
55
  })
56
56
 
57
57
  test('Optional value rejection', async () => {
58
58
  SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
59
59
  const token = await config.asyncGet('TOKEN_SECRET_FALSY')
60
- expect(token).is.undefined
60
+ c_expect(token).is.undefined
61
61
  })
62
62
  })
63
63
 
@@ -76,8 +76,8 @@ describe(`Required remote environment`, () => {
76
76
  } catch (e) {
77
77
  err = e
78
78
  }
79
- expect(err).is.not.null
80
- expect(err?.['message']).is.not.null
79
+ c_expect(err).is.not.null
80
+ c_expect(err?.['message']).is.not.null
81
81
  })
82
82
 
83
83
  test('Required value with null value', async () => {
@@ -92,8 +92,8 @@ describe(`Required remote environment`, () => {
92
92
  } catch (e) {
93
93
  err = e
94
94
  }
95
- expect(err).is.not.null
96
- expect(err?.['message']).is.not.null
95
+ c_expect(err).is.not.null
96
+ c_expect(err?.['message']).is.not.null
97
97
  })
98
98
 
99
99
  test('Required value with empty response', async () => {
@@ -104,8 +104,8 @@ describe(`Required remote environment`, () => {
104
104
  } catch (e) {
105
105
  err = e
106
106
  }
107
- expect(err).is.not.null
108
- expect(err?.['message']).is.not.null
107
+ c_expect(err).is.not.null
108
+ c_expect(err?.['message']).is.not.null
109
109
  })
110
110
 
111
111
  test('Required value with valid response', async () => {
@@ -116,8 +116,8 @@ describe(`Required remote environment`, () => {
116
116
  },
117
117
  })
118
118
  const token = await config.asyncGet('TOKEN_SECRET')
119
- expect(token).is.not.undefined
120
- expect(token).to.be.equals(value)
119
+ c_expect(token).is.not.undefined
120
+ c_expect(token).to.be.equals(value)
121
121
  })
122
122
 
123
123
  test('Required value rejection', async () => {
@@ -128,8 +128,8 @@ describe(`Required remote environment`, () => {
128
128
  } catch (e) {
129
129
  err = e
130
130
  }
131
- expect(err).is.not.null
132
- expect(err?.['message']).is.not.null
131
+ c_expect(err).is.not.null
132
+ c_expect(err?.['message']).is.not.null
133
133
  })
134
134
  })
135
135
 
@@ -140,7 +140,7 @@ describe(`Optional local environment`, () => {
140
140
 
141
141
  test('Optional value with null value', async () => {
142
142
  const token = config.get('PATH123')
143
- expect(token).is.undefined
143
+ c_expect(token).is.undefined
144
144
  })
145
145
  })
146
146
 
@@ -156,15 +156,15 @@ describe(`Required local environment`, () => {
156
156
  } catch (e) {
157
157
  err = e
158
158
  }
159
- expect(err).is.not.null
160
- expect(err?.['message']).is.not.null
159
+ c_expect(err).is.not.null
160
+ c_expect(err?.['message']).is.not.null
161
161
  })
162
162
 
163
163
  test('Required value with valid response', async () => {
164
164
  const key = 'PATH'
165
165
  const v = config.get(key)
166
- expect(v).is.not.null
167
- expect(v).to.be.equals(process.env[key])
166
+ c_expect(v).is.not.null
167
+ c_expect(v).to.be.equals(process.env[key])
168
168
  })
169
169
  })
170
170
 
@@ -179,14 +179,14 @@ describe(`Caching test`, () => {
179
179
  },
180
180
  })
181
181
  const v = await config.asyncGet(key)
182
- expect(v).is.not.null
183
- expect(v).to.be.equals(value)
182
+ c_expect(v).is.not.null
183
+ c_expect(v).to.be.equals(value)
184
184
  // subsequent fetch
185
185
  SSMMock.reset()
186
186
  SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
187
187
  const v2 = await config.asyncGet(key)
188
- expect(v2).is.not.null
189
- expect(v2).to.be.equals(value)
188
+ c_expect(v2).is.not.null
189
+ c_expect(v2).to.be.equals(value)
190
190
  })
191
191
  })
192
192