@creator.co/wapi 1.2.2 → 1.2.3

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 (55) hide show
  1. package/.eslintrc.cjs +29 -22
  2. package/.github/workflows/npmpublish.yml +1 -1
  3. package/.github/workflows/prs.yml +1 -1
  4. package/index.ts +12 -10
  5. package/jest.config.ts +19 -19
  6. package/package.json +1 -1
  7. package/src/API/Request.ts +17 -35
  8. package/src/API/Response.ts +24 -42
  9. package/src/API/Utils.ts +5 -7
  10. package/src/BaseEvent/EventProcessor.ts +16 -24
  11. package/src/BaseEvent/Process.ts +7 -12
  12. package/src/BaseEvent/Transaction.ts +25 -43
  13. package/src/Config/Configuration.ts +8 -14
  14. package/src/Config/EnvironmentVar.ts +10 -20
  15. package/src/Crypto/Crypto.ts +10 -10
  16. package/src/Crypto/JWT.ts +4 -10
  17. package/src/Globals.ts +19 -25
  18. package/src/Logger/Logger.ts +36 -51
  19. package/src/Mailer/Mailer.ts +19 -31
  20. package/src/Publisher/Publisher.ts +7 -12
  21. package/src/Server/RouteResolver.ts +5 -6
  22. package/src/Server/Router.ts +7 -12
  23. package/src/Server/lib/ContainerServer.ts +5 -5
  24. package/src/Server/lib/Server.ts +26 -38
  25. package/src/Server/lib/container/GenericHandler.ts +8 -13
  26. package/src/Server/lib/container/GenericHandlerEvent.ts +21 -35
  27. package/src/Server/lib/container/HealthHandler.ts +2 -2
  28. package/src/Server/lib/container/Proxy.ts +26 -38
  29. package/src/Server/lib/container/Utils.ts +2 -2
  30. package/src/Validation/Validator.ts +6 -6
  31. package/tests/API/Request.test.ts +107 -111
  32. package/tests/API/Response.test.ts +86 -91
  33. package/tests/API/Utils.test.ts +64 -64
  34. package/tests/BaseEvent/EventProcessor.test.ts +68 -84
  35. package/tests/BaseEvent/Process.test.ts +11 -11
  36. package/tests/BaseEvent/Transaction.test.ts +44 -53
  37. package/tests/Config/Config.test.ts +50 -50
  38. package/tests/Config/EnvironmentVar.test.ts +50 -59
  39. package/tests/Crypto/Crypto.test.ts +20 -22
  40. package/tests/Crypto/JWT.test.ts +40 -40
  41. package/tests/Logger/Logger.test.ts +24 -36
  42. package/tests/Mailer/Mailer.test.ts +21 -29
  43. package/tests/Publisher/Publisher.test.ts +18 -18
  44. package/tests/Server/RouteResolver.test.ts +56 -59
  45. package/tests/Server/Router.test.ts +16 -16
  46. package/tests/Server/lib/ContainerServer.test.ts +83 -85
  47. package/tests/Server/lib/Server.test.ts +4 -4
  48. package/tests/Server/lib/container/GenericHandler.test.ts +31 -41
  49. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +35 -36
  50. package/tests/Server/lib/container/HealthHandler.test.ts +7 -7
  51. package/tests/Server/lib/container/Proxy.test.ts +66 -79
  52. package/tests/Server/lib/container/Utils.test.ts +16 -17
  53. package/tests/Test.utils.ts +9 -9
  54. package/tests/Validation/Validator.test.ts +28 -40
  55. package/tests/main.test.ts +2 -2
@@ -1,62 +1,62 @@
1
- import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm"
2
- import { mockClient } from "aws-sdk-client-mock"
3
- import { expect } from "chai"
1
+ import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
2
+ import { mockClient } from 'aws-sdk-client-mock'
3
+ import { expect } from 'chai'
4
4
 
5
- import Configuration from "../../src/Config/Configuration"
6
- import { SampleConfig, SampleConfigSchema } from "../Test.utils"
5
+ import Configuration from '../../src/Config/Configuration'
6
+ import { SampleConfig, SampleConfigSchema } from '../Test.utils'
7
7
 
8
8
  const SSMMock = mockClient(SSMClient)
9
- const config = new Configuration<SampleConfigSchema>(SampleConfig, "my-prefix")
9
+ const config = new Configuration<SampleConfigSchema>(SampleConfig, 'my-prefix')
10
10
  describe(`Optional remote environment`, () => {
11
11
  // reset mock
12
12
  beforeEach(() => {
13
13
  SSMMock.reset()
14
- config["resetCache"]()
14
+ config['resetCache']()
15
15
  })
16
16
 
17
- test("Does not accept sync get", async () => {
17
+ test('Does not accept sync get', async () => {
18
18
  let err = null
19
19
  try {
20
20
  // @ts-ignore
21
- config.get("TOKEN_SECRET")
21
+ config.get('TOKEN_SECRET')
22
22
  } catch (e) {
23
23
  err = e
24
24
  }
25
25
  expect(err).is.not.null
26
- expect(err?.["message"]).is.not.null
26
+ expect(err?.['message']).is.not.null
27
27
  })
28
28
 
29
- test("Optional value with null value", async () => {
29
+ test('Optional value with null value', async () => {
30
30
  SSMMock.on(GetParameterCommand).resolves({
31
31
  Parameter: {
32
32
  Value: undefined,
33
33
  },
34
34
  })
35
- const token = await config.asyncGet("TOKEN_SECRET_FALSY")
35
+ const token = await config.asyncGet('TOKEN_SECRET_FALSY')
36
36
  expect(token).is.undefined
37
37
  })
38
38
 
39
- test("Optional value with empty response", async () => {
39
+ test('Optional value with empty response', async () => {
40
40
  SSMMock.on(GetParameterCommand).resolves({})
41
- const token = await config.asyncGet("TOKEN_SECRET_FALSY")
41
+ const token = await config.asyncGet('TOKEN_SECRET_FALSY')
42
42
  expect(token).is.undefined
43
43
  })
44
44
 
45
- test("Optional value with valid response", async () => {
46
- const value = "abc"
45
+ test('Optional value with valid response', async () => {
46
+ const value = 'abc'
47
47
  SSMMock.on(GetParameterCommand).resolves({
48
48
  Parameter: {
49
49
  Value: value,
50
50
  },
51
51
  })
52
- const token = await config.asyncGet("TOKEN_SECRET_FALSY")
52
+ const token = await config.asyncGet('TOKEN_SECRET_FALSY')
53
53
  expect(token).is.not.undefined
54
54
  expect(token).to.be.equals(value)
55
55
  })
56
56
 
57
- test("Optional value rejection", async () => {
58
- SSMMock.on(GetParameterCommand).rejects(new Error("failed!"))
59
- const token = await config.asyncGet("TOKEN_SECRET_FALSY")
57
+ test('Optional value rejection', async () => {
58
+ SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
59
+ const token = await config.asyncGet('TOKEN_SECRET_FALSY')
60
60
  expect(token).is.undefined
61
61
  })
62
62
  })
@@ -65,22 +65,22 @@ describe(`Required remote environment`, () => {
65
65
  // reset mock
66
66
  beforeEach(() => {
67
67
  SSMMock.reset()
68
- config["resetCache"]()
68
+ config['resetCache']()
69
69
  })
70
70
 
71
- test("Does not accept sync get", async () => {
71
+ test('Does not accept sync get', async () => {
72
72
  let err = null
73
73
  try {
74
74
  // @ts-ignore
75
- config.get("TOKEN_SECRET")
75
+ config.get('TOKEN_SECRET')
76
76
  } catch (e) {
77
77
  err = e
78
78
  }
79
79
  expect(err).is.not.null
80
- expect(err?.["message"]).is.not.null
80
+ expect(err?.['message']).is.not.null
81
81
  })
82
82
 
83
- test("Required value with null value", async () => {
83
+ test('Required value with null value', async () => {
84
84
  SSMMock.on(GetParameterCommand).resolves({
85
85
  Parameter: {
86
86
  Value: undefined,
@@ -88,80 +88,80 @@ describe(`Required remote environment`, () => {
88
88
  })
89
89
  let err = null
90
90
  try {
91
- await config.asyncGet("TOKEN_SECRET")
91
+ await config.asyncGet('TOKEN_SECRET')
92
92
  } catch (e) {
93
93
  err = e
94
94
  }
95
95
  expect(err).is.not.null
96
- expect(err?.["message"]).is.not.null
96
+ expect(err?.['message']).is.not.null
97
97
  })
98
98
 
99
- test("Required value with empty response", async () => {
99
+ test('Required value with empty response', async () => {
100
100
  SSMMock.on(GetParameterCommand).resolves({})
101
101
  let err = null
102
102
  try {
103
- await config.asyncGet("TOKEN_SECRET")
103
+ await config.asyncGet('TOKEN_SECRET')
104
104
  } catch (e) {
105
105
  err = e
106
106
  }
107
107
  expect(err).is.not.null
108
- expect(err?.["message"]).is.not.null
108
+ expect(err?.['message']).is.not.null
109
109
  })
110
110
 
111
- test("Required value with valid response", async () => {
112
- const value = "abc"
111
+ test('Required value with valid response', async () => {
112
+ const value = 'abc'
113
113
  SSMMock.on(GetParameterCommand).resolves({
114
114
  Parameter: {
115
115
  Value: value,
116
116
  },
117
117
  })
118
- const token = await config.asyncGet("TOKEN_SECRET")
118
+ const token = await config.asyncGet('TOKEN_SECRET')
119
119
  expect(token).is.not.undefined
120
120
  expect(token).to.be.equals(value)
121
121
  })
122
122
 
123
- test("Required value rejection", async () => {
124
- SSMMock.on(GetParameterCommand).rejects(new Error("failed!"))
123
+ test('Required value rejection', async () => {
124
+ SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
125
125
  let err = null
126
126
  try {
127
- await config.asyncGet("TOKEN_SECRET")
127
+ await config.asyncGet('TOKEN_SECRET')
128
128
  } catch (e) {
129
129
  err = e
130
130
  }
131
131
  expect(err).is.not.null
132
- expect(err?.["message"]).is.not.null
132
+ expect(err?.['message']).is.not.null
133
133
  })
134
134
  })
135
135
 
136
136
  describe(`Optional local environment`, () => {
137
137
  beforeEach(() => {
138
- config["resetCache"]()
138
+ config['resetCache']()
139
139
  })
140
140
 
141
- test("Optional value with null value", async () => {
142
- const token = config.get("PATH123")
141
+ test('Optional value with null value', async () => {
142
+ const token = config.get('PATH123')
143
143
  expect(token).is.undefined
144
144
  })
145
145
  })
146
146
 
147
147
  describe(`Required local environment`, () => {
148
148
  beforeEach(() => {
149
- config["resetCache"]()
149
+ config['resetCache']()
150
150
  })
151
151
 
152
- test("Required value with null value", async () => {
152
+ test('Required value with null value', async () => {
153
153
  let err = null
154
154
  try {
155
- config.get("PATH_FALSY")
155
+ config.get('PATH_FALSY')
156
156
  } catch (e) {
157
157
  err = e
158
158
  }
159
159
  expect(err).is.not.null
160
- expect(err?.["message"]).is.not.null
160
+ expect(err?.['message']).is.not.null
161
161
  })
162
162
 
163
- test("Required value with valid response", async () => {
164
- const key = "PATH"
163
+ test('Required value with valid response', async () => {
164
+ const key = 'PATH'
165
165
  const v = config.get(key)
166
166
  expect(v).is.not.null
167
167
  expect(v).to.be.equals(process.env[key])
@@ -169,9 +169,9 @@ describe(`Required local environment`, () => {
169
169
  })
170
170
 
171
171
  describe(`Caching test`, () => {
172
- test("Does cache previous fetched value", async () => {
173
- const value = "123"
174
- const key = "TOKEN_SECRET"
172
+ test('Does cache previous fetched value', async () => {
173
+ const value = '123'
174
+ const key = 'TOKEN_SECRET'
175
175
  // initial fetch
176
176
  SSMMock.on(GetParameterCommand).resolves({
177
177
  Parameter: {
@@ -183,7 +183,7 @@ describe(`Caching test`, () => {
183
183
  expect(v).to.be.equals(value)
184
184
  // subsequent fetch
185
185
  SSMMock.reset()
186
- SSMMock.on(GetParameterCommand).rejects(new Error("failed!"))
186
+ SSMMock.on(GetParameterCommand).rejects(new Error('failed!'))
187
187
  const v2 = await config.asyncGet(key)
188
188
  expect(v2).is.not.null
189
189
  expect(v2).to.be.equals(value)
@@ -1,14 +1,9 @@
1
- import {
2
- SecretsManagerClient,
3
- GetSecretValueCommand,
4
- } from "@aws-sdk/client-secrets-manager"
5
- import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm"
6
- import { mockClient } from "aws-sdk-client-mock"
7
- import { expect } from "chai"
8
-
9
- import EnvironmentVar, {
10
- EnvironmentType,
11
- } from "../../src/Config/EnvironmentVar"
1
+ import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'
2
+ import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
3
+ import { mockClient } from 'aws-sdk-client-mock'
4
+ import { expect } from 'chai'
5
+
6
+ import EnvironmentVar, { EnvironmentType } from '../../src/Config/EnvironmentVar'
12
7
 
13
8
  const SSMMock = mockClient(SSMClient)
14
9
  const SecretsManagerMock = mockClient(SecretsManagerClient)
@@ -20,7 +15,7 @@ function testRemoteEnv(mock, type, command) {
20
15
  mock.reset()
21
16
  })
22
17
 
23
- test("Does not accept sync resolve", async () => {
18
+ test('Does not accept sync resolve', async () => {
24
19
  mock.on(command).resolves({
25
20
  Parameter: {
26
21
  Value: undefined,
@@ -28,35 +23,35 @@ function testRemoteEnv(mock, type, command) {
28
23
  })
29
24
  let err = null
30
25
  try {
31
- const env = new EnvironmentVar("abc", type, true)
26
+ const env = new EnvironmentVar('abc', type, true)
32
27
  env.syncResolve()
33
28
  } catch (e) {
34
29
  err = e
35
30
  }
36
31
  expect(err).is.not.null
37
- expect(err?.["message"]).is.not.null
32
+ expect(err?.['message']).is.not.null
38
33
  })
39
34
 
40
- test("Optional value with null value", async () => {
35
+ test('Optional value with null value', async () => {
41
36
  mock.on(command).resolves({
42
37
  Parameter: {
43
38
  Value: undefined,
44
39
  },
45
40
  })
46
- const env = new EnvironmentVar("abc", type, true)
41
+ const env = new EnvironmentVar('abc', type, true)
47
42
  const token = await env.resolve()
48
43
  expect(token).is.undefined
49
44
  })
50
45
 
51
- test("Optional value with empty response", async () => {
46
+ test('Optional value with empty response', async () => {
52
47
  mock.on(command).resolves({})
53
- const env = new EnvironmentVar("abc", type, true)
48
+ const env = new EnvironmentVar('abc', type, true)
54
49
  const token = await env.resolve()
55
50
  expect(token).is.undefined
56
51
  })
57
52
 
58
- test("Optional value with valid response", async () => {
59
- const value = "abc"
53
+ test('Optional value with valid response', async () => {
54
+ const value = 'abc'
60
55
  mock.on(command).resolves({
61
56
  Parameter: {
62
57
  Value: value,
@@ -68,9 +63,9 @@ function testRemoteEnv(mock, type, command) {
68
63
  expect(token).to.be.equals(value)
69
64
  })
70
65
 
71
- test("Optional value rejection", async () => {
72
- const value = "abc"
73
- mock.on(command).rejects(new Error("failed!"))
66
+ test('Optional value rejection', async () => {
67
+ const value = 'abc'
68
+ mock.on(command).rejects(new Error('failed!'))
74
69
  const env = new EnvironmentVar(value, type, true)
75
70
  const token = await env.resolve()
76
71
  expect(token).is.undefined
@@ -83,7 +78,7 @@ function testRemoteEnv(mock, type, command) {
83
78
  mock.reset()
84
79
  })
85
80
 
86
- test("Does not accept sync resolve", async () => {
81
+ test('Does not accept sync resolve', async () => {
87
82
  mock.on(command).resolves({
88
83
  Parameter: {
89
84
  Value: undefined,
@@ -91,16 +86,16 @@ function testRemoteEnv(mock, type, command) {
91
86
  })
92
87
  let err = null
93
88
  try {
94
- const env = new EnvironmentVar("abc", type)
89
+ const env = new EnvironmentVar('abc', type)
95
90
  env.syncResolve()
96
91
  } catch (e) {
97
92
  err = e
98
93
  }
99
94
  expect(err).is.not.null
100
- expect(err?.["message"]).is.not.null
95
+ expect(err?.['message']).is.not.null
101
96
  })
102
97
 
103
- test("Required fails when null", async () => {
98
+ test('Required fails when null', async () => {
104
99
  mock.on(command).resolves({
105
100
  Parameter: {
106
101
  Value: undefined,
@@ -108,31 +103,31 @@ function testRemoteEnv(mock, type, command) {
108
103
  })
109
104
  let err = null
110
105
  try {
111
- const env = new EnvironmentVar("abc", type)
106
+ const env = new EnvironmentVar('abc', type)
112
107
  await env.resolve()
113
108
  } catch (e) {
114
109
  err = e
115
110
  }
116
111
  console.log(err)
117
112
  expect(err).is.not.null
118
- expect(err?.["message"]).is.not.null
113
+ expect(err?.['message']).is.not.null
119
114
  })
120
115
 
121
- test("Required fails when empty response", async () => {
116
+ test('Required fails when empty response', async () => {
122
117
  mock.on(command).resolves({})
123
118
  let err = null
124
119
  try {
125
- const env = new EnvironmentVar("abc", type)
120
+ const env = new EnvironmentVar('abc', type)
126
121
  await env.resolve()
127
122
  } catch (e) {
128
123
  err = e
129
124
  }
130
125
  expect(err).is.not.null
131
- expect(err?.["message"]).is.not.null
126
+ expect(err?.['message']).is.not.null
132
127
  })
133
128
 
134
- test("Required value with valid response", async () => {
135
- const value = "abc"
129
+ test('Required value with valid response', async () => {
130
+ const value = 'abc'
136
131
  mock.on(command).resolves({
137
132
  Parameter: {
138
133
  Value: value,
@@ -144,44 +139,40 @@ function testRemoteEnv(mock, type, command) {
144
139
  expect(token).to.be.equals(value)
145
140
  })
146
141
 
147
- test("Required value rejection", async () => {
148
- mock.on(command).rejects(new Error("failed!"))
142
+ test('Required value rejection', async () => {
143
+ mock.on(command).rejects(new Error('failed!'))
149
144
  let err = null
150
145
  try {
151
- const env = new EnvironmentVar("abc", type)
146
+ const env = new EnvironmentVar('abc', type)
152
147
  await env.resolve()
153
148
  } catch (e) {
154
149
  err = e
155
150
  }
156
151
  expect(err).is.not.null
157
- expect(err?.["message"]).is.not.null
152
+ expect(err?.['message']).is.not.null
158
153
  })
159
154
  })
160
155
  }
161
156
 
162
157
  /* Remote envs test */
163
158
  testRemoteEnv(SSMMock, EnvironmentType.PlainRemote, GetParameterCommand)
164
- testRemoteEnv(
165
- SecretsManagerMock,
166
- EnvironmentType.SecureRemote,
167
- GetSecretValueCommand,
168
- )
169
-
170
- describe("Optional Local environment", () => {
171
- test("Does accept async resolve", async () => {
172
- const env = new EnvironmentVar("PATH123", EnvironmentType.Local, true)
159
+ testRemoteEnv(SecretsManagerMock, EnvironmentType.SecureRemote, GetSecretValueCommand)
160
+
161
+ describe('Optional Local environment', () => {
162
+ test('Does accept async resolve', async () => {
163
+ const env = new EnvironmentVar('PATH123', EnvironmentType.Local, true)
173
164
  const v = await env.resolve()
174
165
  expect(v).is.undefined
175
166
  })
176
167
 
177
- test("Optional value with null value", async () => {
178
- const env = new EnvironmentVar("PATH123", EnvironmentType.Local, true)
168
+ test('Optional value with null value', async () => {
169
+ const env = new EnvironmentVar('PATH123', EnvironmentType.Local, true)
179
170
  const token = env.syncResolve()
180
171
  expect(token).is.undefined
181
172
  })
182
173
 
183
- test("Optional value with valid value", async () => {
184
- const key = "PATH"
174
+ test('Optional value with valid value', async () => {
175
+ const key = 'PATH'
185
176
  const env = new EnvironmentVar(key, EnvironmentType.Local, true)
186
177
  const token = env.syncResolve()
187
178
  expect(token).is.not.undefined
@@ -189,30 +180,30 @@ describe("Optional Local environment", () => {
189
180
  })
190
181
  })
191
182
 
192
- describe("Required local environment", () => {
193
- test("Does accept async resolve", async () => {
194
- const key = "PATH"
183
+ describe('Required local environment', () => {
184
+ test('Does accept async resolve', async () => {
185
+ const key = 'PATH'
195
186
  const env = new EnvironmentVar(key, EnvironmentType.Local)
196
187
  const v = await env.resolve()
197
188
  expect(v).is.not.null
198
189
  expect(v).to.be.equals(process.env[key])
199
190
  })
200
191
 
201
- test("Required fails when null", async () => {
192
+ test('Required fails when null', async () => {
202
193
  let err = null
203
194
  try {
204
- const env = new EnvironmentVar("PATH123", EnvironmentType.Local)
195
+ const env = new EnvironmentVar('PATH123', EnvironmentType.Local)
205
196
  env.syncResolve()
206
197
  } catch (e) {
207
198
  err = e
208
199
  }
209
200
  console.log(err)
210
201
  expect(err).is.not.null
211
- expect(err?.["message"]).is.not.null
202
+ expect(err?.['message']).is.not.null
212
203
  })
213
204
 
214
- test("Required value with valid value", async () => {
215
- const key = "PATH"
205
+ test('Required value with valid value', async () => {
206
+ const key = 'PATH'
216
207
  const env = new EnvironmentVar(key, EnvironmentType.Local)
217
208
  const v = env.syncResolve()
218
209
  expect(v).is.not.null
@@ -1,27 +1,27 @@
1
- import { DecryptCommand, EncryptCommand, KMSClient } from "@aws-sdk/client-kms"
2
- import { mockClient } from "aws-sdk-client-mock"
3
- import { expect } from "chai"
1
+ import { DecryptCommand, EncryptCommand, KMSClient } from '@aws-sdk/client-kms'
2
+ import { mockClient } from 'aws-sdk-client-mock'
3
+ import { expect } from 'chai'
4
4
 
5
- import Crypto from "../../src/Crypto/Crypto"
5
+ import Crypto from '../../src/Crypto/Crypto'
6
6
 
7
7
  const KMSMock = mockClient(KMSClient)
8
8
 
9
9
  function fakeEncryption(v) {
10
10
  const f = new TextEncoder().encode(v)
11
- return Buffer.from(f as any, "utf8").toString("hex")
11
+ return Buffer.from(f as any, 'utf8').toString('hex')
12
12
  }
13
13
  function fakeDecryption(v) {
14
14
  return new TextEncoder().encode(v)
15
15
  }
16
16
 
17
- describe("Encryption", () => {
17
+ describe('Encryption', () => {
18
18
  // reset mock
19
19
  beforeEach(() => {
20
20
  KMSMock.reset()
21
21
  })
22
22
 
23
- const provider = new Crypto("ca-central-1", "abc123")
24
- test("Encrypts json object", async () => {
23
+ const provider = new Crypto('ca-central-1', 'abc123')
24
+ test('Encrypts json object', async () => {
25
25
  const encryptionObj = { userID: 123 }
26
26
  KMSMock.on(EncryptCommand).resolves({
27
27
  CiphertextBlob: new TextEncoder().encode(JSON.stringify(encryptionObj)),
@@ -31,8 +31,8 @@ describe("Encryption", () => {
31
31
  expect(token).to.be.equals(fakeEncryption(JSON.stringify(encryptionObj)))
32
32
  })
33
33
 
34
- test("Encrypts string", async () => {
35
- const encryptionText = "Hello encryption!"
34
+ test('Encrypts string', async () => {
35
+ const encryptionText = 'Hello encryption!'
36
36
  KMSMock.on(EncryptCommand).resolves({
37
37
  CiphertextBlob: new TextEncoder().encode(encryptionText),
38
38
  })
@@ -41,35 +41,33 @@ describe("Encryption", () => {
41
41
  expect(token).to.be.equals(fakeEncryption(encryptionText))
42
42
  })
43
43
 
44
- test("Fails to encrypt a number", async () => {
44
+ test('Fails to encrypt a number', async () => {
45
45
  const encryptionText = 123
46
- KMSMock.on(EncryptCommand).rejects(new Error("failed"))
46
+ KMSMock.on(EncryptCommand).rejects(new Error('failed'))
47
47
  const token = await provider.encryptData(encryptionText)
48
48
  expect(token).is.null
49
49
  })
50
50
  })
51
51
 
52
- describe("Decryption", () => {
52
+ describe('Decryption', () => {
53
53
  // reset mock
54
54
  beforeEach(() => {
55
55
  KMSMock.reset()
56
56
  })
57
57
 
58
- const provider = new Crypto("ca-central-1", "abc123")
59
- test("Decrypts json object", async () => {
58
+ const provider = new Crypto('ca-central-1', 'abc123')
59
+ test('Decrypts json object', async () => {
60
60
  const encryptionObj = { userID: 123 }
61
61
  KMSMock.on(DecryptCommand).resolves({
62
62
  Plaintext: fakeDecryption(JSON.stringify(encryptionObj)),
63
63
  })
64
- const token = await provider.decryptData(
65
- fakeEncryption(JSON.stringify(encryptionObj)),
66
- )
64
+ const token = await provider.decryptData(fakeEncryption(JSON.stringify(encryptionObj)))
67
65
  expect(token).is.not.null
68
66
  expect(token).to.be.equals(JSON.stringify(encryptionObj))
69
67
  })
70
68
 
71
- test("Decrypts string", async () => {
72
- const encryptionText = "abc123"
69
+ test('Decrypts string', async () => {
70
+ const encryptionText = 'abc123'
73
71
  KMSMock.on(DecryptCommand).resolves({
74
72
  Plaintext: fakeDecryption(encryptionText),
75
73
  })
@@ -78,9 +76,9 @@ describe("Decryption", () => {
78
76
  expect(token).to.be.equals(encryptionText)
79
77
  })
80
78
 
81
- test("Fails to decrypt a number", async () => {
79
+ test('Fails to decrypt a number', async () => {
82
80
  const encryptionText = 123
83
- KMSMock.on(DecryptCommand).rejects(new Error("failed"))
81
+ KMSMock.on(DecryptCommand).rejects(new Error('failed'))
84
82
  // @ts-ignore
85
83
  const token = await provider.decryptData(encryptionText)
86
84
  expect(token).is.null