@comicrelief/lambda-wrapper 1.10.2 → 2.0.0-beta.10

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 (89) hide show
  1. package/README.md +196 -50
  2. package/dist/core/DependencyAwareClass.d.ts +16 -0
  3. package/dist/core/DependencyAwareClass.d.ts.map +1 -0
  4. package/dist/core/DependencyAwareClass.js +20 -0
  5. package/dist/core/DependencyAwareClass.js.map +1 -0
  6. package/dist/core/DependencyInjection.d.ts +62 -0
  7. package/dist/core/DependencyInjection.d.ts.map +1 -0
  8. package/dist/core/DependencyInjection.js +105 -0
  9. package/dist/core/DependencyInjection.js.map +1 -0
  10. package/dist/core/LambdaWrapper.d.ts +73 -0
  11. package/dist/core/LambdaWrapper.d.ts.map +1 -0
  12. package/dist/core/LambdaWrapper.js +170 -0
  13. package/dist/core/LambdaWrapper.js.map +1 -0
  14. package/dist/core/config.d.ts +20 -0
  15. package/dist/core/config.d.ts.map +1 -0
  16. package/dist/core/config.js +21 -0
  17. package/dist/core/config.js.map +1 -0
  18. package/dist/index.d.ts +28 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +57 -143
  21. package/dist/index.js.map +1 -0
  22. package/dist/models/ResponseModel.d.ts +73 -0
  23. package/dist/models/ResponseModel.d.ts.map +1 -0
  24. package/dist/models/ResponseModel.js +100 -0
  25. package/dist/models/ResponseModel.js.map +1 -0
  26. package/dist/models/SQSMessageModel.d.ts +46 -0
  27. package/dist/models/SQSMessageModel.d.ts.map +1 -0
  28. package/dist/models/SQSMessageModel.js +65 -0
  29. package/dist/models/SQSMessageModel.js.map +1 -0
  30. package/dist/services/BaseConfigService.d.ts +101 -0
  31. package/dist/services/BaseConfigService.d.ts.map +1 -0
  32. package/dist/services/BaseConfigService.js +180 -0
  33. package/dist/services/BaseConfigService.js.map +1 -0
  34. package/dist/services/HTTPService.d.ts +29 -0
  35. package/dist/services/HTTPService.d.ts.map +1 -0
  36. package/dist/services/HTTPService.js +55 -0
  37. package/dist/services/HTTPService.js.map +1 -0
  38. package/dist/services/LoggerService.d.ts +102 -0
  39. package/dist/services/LoggerService.d.ts.map +1 -0
  40. package/dist/services/LoggerService.js +249 -0
  41. package/dist/services/LoggerService.js.map +1 -0
  42. package/dist/services/RequestService.d.ts +119 -0
  43. package/dist/services/RequestService.d.ts.map +1 -0
  44. package/dist/services/RequestService.js +293 -0
  45. package/dist/services/RequestService.js.map +1 -0
  46. package/dist/services/SQSService.d.ts +263 -0
  47. package/dist/services/SQSService.d.ts.map +1 -0
  48. package/dist/services/SQSService.js +411 -0
  49. package/dist/services/SQSService.js.map +1 -0
  50. package/dist/services/TimerService.d.ts +22 -0
  51. package/dist/services/TimerService.d.ts.map +1 -0
  52. package/dist/services/TimerService.js +40 -0
  53. package/dist/services/TimerService.js.map +1 -0
  54. package/dist/types/Status.d.ts +6 -0
  55. package/dist/types/Status.d.ts.map +1 -0
  56. package/dist/types/Status.js +3 -0
  57. package/dist/types/Status.js.map +1 -0
  58. package/dist/utils/LambdaTermination.d.ts +14 -0
  59. package/dist/utils/LambdaTermination.d.ts.map +1 -0
  60. package/dist/utils/LambdaTermination.js +23 -0
  61. package/dist/utils/LambdaTermination.js.map +1 -0
  62. package/dist/utils/PromisifiedDelay.d.ts +17 -0
  63. package/dist/utils/PromisifiedDelay.d.ts.map +1 -0
  64. package/dist/utils/PromisifiedDelay.js +48 -0
  65. package/dist/utils/PromisifiedDelay.js.map +1 -0
  66. package/package.json +36 -26
  67. package/.eslintrc.yml +0 -16
  68. package/.github/dependabot.yml +0 -11
  69. package/.github/workflows/main.yml +0 -74
  70. package/babel.config.js +0 -13
  71. package/dist/Config/Dependencies.js +0 -33
  72. package/dist/DependencyInjection/DependencyAware.class.js +0 -40
  73. package/dist/DependencyInjection/DependencyInjection.class.js +0 -115
  74. package/dist/Model/CloudEvent.model.js +0 -138
  75. package/dist/Model/Model.model.js +0 -39
  76. package/dist/Model/Response.model.js +0 -135
  77. package/dist/Model/SQS/MarketingPreference.constraints.json +0 -28
  78. package/dist/Model/SQS/MarketingPreference.model.js +0 -583
  79. package/dist/Model/SQS/Message.model.js +0 -92
  80. package/dist/Model/Status.model.js +0 -71
  81. package/dist/Service/BaseConfig.service.js +0 -204
  82. package/dist/Service/HTTP.service.js +0 -57
  83. package/dist/Service/Logger.service.js +0 -256
  84. package/dist/Service/Request.service.js +0 -294
  85. package/dist/Service/SQS.service.js +0 -367
  86. package/dist/Service/Timer.service.js +0 -46
  87. package/dist/Wrapper/LambdaTermination.js +0 -34
  88. package/dist/Wrapper/LambdaWrapper.js +0 -143
  89. package/dist/Wrapper/PromisifiedDelay.js +0 -55
@@ -1,28 +0,0 @@
1
- {
2
- "campaign": {
3
- "presence": {
4
- "allowEmpty": false
5
- }
6
- },
7
- "transSource": {
8
- "presence": {
9
- "allowEmpty": false
10
- }
11
- },
12
- "transSourceUrl": {
13
- "presence": {
14
- "allowEmpty": false
15
- },
16
- "url": true
17
- },
18
- "transType": {
19
- "presence": {
20
- "allowEmpty": false
21
- }
22
- },
23
- "timestamp": {
24
- "presence": {
25
- "allowEmpty": false
26
- }
27
- }
28
- }
@@ -1,583 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.ERROR_TYPES = void 0;
7
- var _validate = _interopRequireDefault(require("validate.js"));
8
- var _Model = _interopRequireDefault(require("../Model.model"));
9
- var _Response = _interopRequireDefault(require("../Response.model"));
10
- var _MarketingPreferenceConstraints = _interopRequireDefault(require("./MarketingPreference.constraints.json"));
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- /* eslint-disable sonarjs/cognitive-complexity */
13
-
14
- // Define action specific error types
15
- const ERROR_TYPES = {
16
- VALIDATION_ERROR: new _Response.default({}, 400, 'required fields are missing')
17
- };
18
-
19
- /**
20
- * Marketing Preference
21
- */
22
- exports.ERROR_TYPES = ERROR_TYPES;
23
- class MarketingPreference extends _Model.default {
24
- /**
25
- * Message constructor
26
- *
27
- * @param data object
28
- */
29
- constructor(data = {}) {
30
- super();
31
- this.firstname = null;
32
- this.lastname = null;
33
- this.phone = null;
34
- this.mobile = null;
35
- this.address1 = null;
36
- this.address2 = null;
37
- this.address3 = null;
38
- this.town = null;
39
- this.postcode = null;
40
- this.country = null;
41
- this.campaign = '';
42
- this.transactionId = null;
43
- this.transSource = '';
44
- this.transSourceUrl = '';
45
- this.transType = 'prefs';
46
- this.email = null;
47
- this.permissionPost = null;
48
- this.permissionEmail = null;
49
- this.permissionPhone = null;
50
- this.permissionSMS = null;
51
- this.timestamp = null;
52
- this.instantiateFunctionWithDefinedValue('setFirstName', data.firstName);
53
- this.instantiateFunctionWithDefinedValue('setFirstName', data.firstname);
54
- this.instantiateFunctionWithDefinedValue('setLastName', data.lastName);
55
- this.instantiateFunctionWithDefinedValue('setLastName', data.lastname);
56
- this.instantiateFunctionWithDefinedValue('setPhone', data.phone);
57
- this.instantiateFunctionWithDefinedValue('setMobile', data.mobile);
58
- this.instantiateFunctionWithDefinedValue('setAddress1', data.address1);
59
- this.instantiateFunctionWithDefinedValue('setAddress2', data.address2);
60
- this.instantiateFunctionWithDefinedValue('setAddress3', data.address3);
61
- this.instantiateFunctionWithDefinedValue('setTown', data.town);
62
- this.instantiateFunctionWithDefinedValue('setPostcode', data.postcode);
63
- this.instantiateFunctionWithDefinedValue('setCountry', data.country);
64
- this.instantiateFunctionWithDefinedValue('setCampaign', data.campaign);
65
- this.instantiateFunctionWithDefinedValue('setTransactionId', data.transactionId);
66
- this.instantiateFunctionWithDefinedValue('setTransSource', data.transSource);
67
- this.instantiateFunctionWithDefinedValue('setTransSourceUrl', data.transSourceUrl);
68
- this.instantiateFunctionWithDefinedValue('setEmail', data.email);
69
- this.instantiateFunctionWithDefinedValue('setPermissionPost', data.permissionPost);
70
- this.instantiateFunctionWithDefinedValue('setPermissionEmail', data.permissionEmail);
71
- this.instantiateFunctionWithDefinedValue('setPermissionPhone', data.permissionPhone);
72
- this.instantiateFunctionWithDefinedValue('setPermissionSMS', data.permissionSMS);
73
- if (typeof data.timestamp !== 'undefined' && data.timestamp !== '' && data.timestamp !== null) {
74
- this.instantiateFunctionWithDefinedValue('setTimestamp', data.timestamp);
75
- } else {
76
- this.generateTimestamp();
77
- }
78
- }
79
-
80
- /**
81
- * Get First Name
82
- *
83
- * @returns {string|*}
84
- */
85
- getFirstName() {
86
- return this.firstname;
87
- }
88
-
89
- /**
90
- * Set First Name
91
- *
92
- * @param value string
93
- */
94
- setFirstName(value) {
95
- this.firstname = value;
96
- }
97
-
98
- /**
99
- * Get Last Name
100
- *
101
- * @returns {string|*}
102
- */
103
- getLastName() {
104
- return this.lastname;
105
- }
106
-
107
- /**
108
- * Set Last Name
109
- *
110
- * @param value string
111
- */
112
- setLastName(value) {
113
- this.lastname = value;
114
- }
115
-
116
- /**
117
- * Get phone
118
- *
119
- * @returns {string|*}
120
- */
121
- getPhone() {
122
- return this.phone;
123
- }
124
-
125
- /**
126
- * Set phone
127
- *
128
- * @param value string
129
- */
130
- setPhone(value) {
131
- this.phone = value;
132
- }
133
-
134
- /**
135
- * Get Mobile
136
- *
137
- * @returns {string|*}
138
- */
139
- getMobile() {
140
- return this.mobile;
141
- }
142
-
143
- /**
144
- * Set Mobile
145
- *
146
- * @param value string
147
- */
148
- setMobile(value) {
149
- this.mobile = value;
150
- }
151
-
152
- /**
153
- * Get Address Line 1
154
- *
155
- * @returns {string|*}
156
- */
157
- getAddress1() {
158
- return this.address1;
159
- }
160
-
161
- /**
162
- * Set Address Line 1
163
- *
164
- * @param value string
165
- */
166
- setAddress1(value) {
167
- this.address1 = value;
168
- }
169
-
170
- /**
171
- * Get Address Line 2
172
- *
173
- * @returns {string|*}
174
- */
175
- getAddress2() {
176
- return this.address2;
177
- }
178
-
179
- /**
180
- * Set Address Line 2
181
- *
182
- * @param value string
183
- */
184
- setAddress2(value) {
185
- this.address2 = typeof value === 'undefined' || value === '' ? null : value;
186
- }
187
-
188
- /**
189
- * Get Address Line 3
190
- *
191
- * @returns {string|*}
192
- */
193
- getAddress3() {
194
- return this.address3;
195
- }
196
-
197
- /**
198
- * Set Address Line 3
199
- *
200
- * @param value string
201
- */
202
- setAddress3(value) {
203
- this.address3 = typeof value === 'undefined' || value === '' ? null : value;
204
- }
205
-
206
- /**
207
- * Get Town
208
- *
209
- * @returns {string|*}
210
- */
211
- getTown() {
212
- return this.town;
213
- }
214
-
215
- /**
216
- * Set Town
217
- *
218
- * @param value string
219
- */
220
- setTown(value) {
221
- this.town = value;
222
- }
223
-
224
- /**
225
- * Get Postcode
226
- *
227
- * @returns {string|*}
228
- */
229
- getPostcode() {
230
- return this.postcode;
231
- }
232
-
233
- /**
234
- * Set Postcode
235
- *
236
- * @param value string
237
- */
238
- setPostcode(value) {
239
- this.postcode = value;
240
- }
241
-
242
- /**
243
- * Get Country
244
- *
245
- * @returns {string|*}
246
- */
247
- getCountry() {
248
- return this.country;
249
- }
250
-
251
- /**
252
- * Set Country
253
- *
254
- * @param value string
255
- */
256
- setCountry(value) {
257
- this.country = value;
258
- }
259
-
260
- /**
261
- * Get Campaign
262
- *
263
- * @returns {string|*}
264
- */
265
- getCampaign() {
266
- return this.campaign;
267
- }
268
-
269
- /**
270
- * Set Campaign
271
- *
272
- * @param value string
273
- */
274
- setCampaign(value) {
275
- this.campaign = value;
276
- }
277
-
278
- /**
279
- * Get Transaction Id
280
- *
281
- * @returns {string|*}
282
- */
283
- getTransactionId() {
284
- return this.transactionId;
285
- }
286
-
287
- /**
288
- * Set Transaction Id
289
- *
290
- * @param value string
291
- */
292
- setTransactionId(value) {
293
- this.transactionId = value;
294
- }
295
-
296
- /**
297
- * Get Transaction Source
298
- *
299
- * @returns {string|*}
300
- */
301
- getTransSource() {
302
- return this.transSource;
303
- }
304
-
305
- /**
306
- * Set Transaction Source
307
- *
308
- * @param value string
309
- */
310
- setTransSource(value) {
311
- this.transSource = value;
312
- }
313
-
314
- /**
315
- * Get Transaction Source URL
316
- *
317
- * @returns {string|*}
318
- */
319
- getTransSourceUrl() {
320
- return this.transSourceUrl;
321
- }
322
-
323
- /**
324
- * Set Transaction Source URL
325
- *
326
- * @param value string
327
- */
328
- setTransSourceUrl(value) {
329
- this.transSourceUrl = value;
330
- }
331
-
332
- /**
333
- * Get Transaction Type
334
- *
335
- * @returns {string|*}
336
- */
337
- getTransType() {
338
- return this.transType;
339
- }
340
-
341
- /**
342
- * Set Transaction Type
343
- *
344
- * @param value string
345
- */
346
- setTransType(value) {
347
- this.transType = value;
348
- }
349
-
350
- /**
351
- * Get Email
352
- *
353
- * @returns {string|*}
354
- */
355
- getEmail() {
356
- return this.email;
357
- }
358
-
359
- /**
360
- * Set Email
361
- *
362
- * @param value string
363
- */
364
- setEmail(value) {
365
- this.email = value;
366
- }
367
-
368
- /**
369
- * Get Email Permission
370
- *
371
- * @returns {string|*}
372
- */
373
- getPermissionEmail() {
374
- return this.permissionEmail;
375
- }
376
-
377
- /**
378
- * Set Email Permission
379
- *
380
- * @param value string
381
- */
382
- setPermissionEmail(value) {
383
- this.permissionEmail = typeof value === 'undefined' || value === '' ? null : value;
384
- }
385
-
386
- /**
387
- * Get Post Permission
388
- *
389
- * @returns {string|*}
390
- */
391
- getPermissionPost() {
392
- return this.permissionPost;
393
- }
394
-
395
- /**
396
- * Set Post Permission
397
- *
398
- * @param value string
399
- */
400
- setPermissionPost(value) {
401
- this.permissionPost = typeof value === 'undefined' || value === '' ? null : value;
402
- }
403
-
404
- /**
405
- * Get Phone Permission
406
- *
407
- * @returns {string|*}
408
- */
409
- getPermissionPhone() {
410
- return this.permissionPhone;
411
- }
412
-
413
- /**
414
- * Set Phone Permission
415
- *
416
- * @param value string
417
- */
418
- setPermissionPhone(value) {
419
- this.permissionPhone = typeof value === 'undefined' || value === '' ? null : value;
420
- }
421
-
422
- /**
423
- * Get SMS Permission
424
- *
425
- * @returns {string|*}
426
- */
427
- getPermissionSMS() {
428
- return this.permissionSMS;
429
- }
430
-
431
- /**
432
- * Set SMS Permission
433
- *
434
- * @param value string
435
- */
436
- setPermissionSMS(value) {
437
- this.permissionSMS = typeof value === 'undefined' || value === '' ? null : value;
438
- }
439
-
440
- /**
441
- * Get Timestamp
442
- *
443
- * @returns {string|*}
444
- */
445
- getTimestamp() {
446
- return this.timestamp;
447
- }
448
-
449
- /**
450
- * Set Timestamp
451
- *
452
- * @param value string
453
- */
454
- setTimestamp(value) {
455
- this.timestamp = value;
456
- }
457
-
458
- /**
459
- * Generate Timestamp
460
- */
461
- generateTimestamp() {
462
- this.timestamp = Math.floor(Date.now() / 1000);
463
- }
464
-
465
- /**
466
- * Get Base entity mappings
467
- *
468
- * @returns {object}
469
- */
470
- getEntityMappings() {
471
- return {
472
- firstname: this.getFirstName(),
473
- lastname: this.getLastName(),
474
- phone: this.getPhone(),
475
- mobile: this.getMobile(),
476
- address1: this.getAddress1(),
477
- address2: this.getAddress2(),
478
- address3: this.getAddress3(),
479
- town: this.getTown(),
480
- postcode: this.getPostcode(),
481
- country: this.getCountry(),
482
- campaign: this.getCampaign(),
483
- transactionId: this.getTransactionId(),
484
- transSource: this.getTransSource(),
485
- transSourceUrl: this.getTransSourceUrl(),
486
- transType: this.getTransType(),
487
- email: this.getEmail(),
488
- permissionEmail: this.getPermissionEmail(),
489
- permissionPost: this.getPermissionPost(),
490
- permissionPhone: this.getPermissionPhone(),
491
- permissionSMS: this.getPermissionSMS(),
492
- timestamp: this.getTimestamp()
493
- };
494
- }
495
-
496
- /**
497
- * Check if any permission is set
498
- *
499
- * @returns {boolean}
500
- */
501
- isPermissionSet() {
502
- return this.getPermissionEmail() !== null && this.getPermissionEmail() !== '' || this.getPermissionPost() !== null && this.getPermissionPost() !== '' || this.getPermissionPhone() !== null && this.getPermissionPhone() !== '' || this.getPermissionSMS() !== null && this.getPermissionSMS() !== '';
503
- }
504
-
505
- /**
506
- * Validate the model
507
- *
508
- * @returns {Promise<any>}
509
- */
510
- validate() {
511
- return new Promise((resolve, reject) => {
512
- const requestConstraintsClone = {
513
- ..._MarketingPreferenceConstraints.default
514
- };
515
- if (this.getPermissionEmail() !== null && this.getPermissionEmail() !== '' && this.getPermissionEmail() !== '0' && this.getPermissionEmail() !== 0 || this.getEmail()) {
516
- if (this.getEmail()) {
517
- requestConstraintsClone.email = {
518
- email: true
519
- };
520
- } else {
521
- requestConstraintsClone.email = {
522
- presence: {
523
- allowEmpty: false
524
- },
525
- email: true
526
- };
527
- }
528
- }
529
- // Update constraints if fields are not empty
530
- requestConstraintsClone.firstname = this.getFirstName() !== null && this.getFirstName() !== '' ? {
531
- format: {
532
- pattern: "[a-zA-Z.'-_ ]+",
533
- flags: 'i',
534
- message: 'can only contain alphabetical characters'
535
- }
536
- } : '';
537
- requestConstraintsClone.lastname = this.getLastName() !== null && this.getLastName() !== '' ? {
538
- format: {
539
- pattern: "[a-zA-Z.'-_ ]+",
540
- flags: 'i',
541
- message: 'can only contain alphabetical characters'
542
- }
543
- } : '';
544
- requestConstraintsClone.phone = this.getPhone() !== null && this.getPhone() !== '' ? {
545
- format: {
546
- pattern: '[0-9 ]+',
547
- flags: 'i',
548
- message: 'can only contain numerical characters'
549
- }
550
- } : '';
551
- requestConstraintsClone.mobile = this.getMobile() !== null && this.getMobile() !== '' ? {
552
- format: {
553
- pattern: '[0-9 ]+',
554
- flags: 'i',
555
- message: 'can only contain numerical characters'
556
- }
557
- } : '';
558
- requestConstraintsClone.address1 = this.getAddress1() !== null && this.getAddress1() !== '' ? {
559
- format: {
560
- pattern: "[a-zA-Z.'-_& ]+",
561
- flags: 'i',
562
- message: "can only contain alphanumeric characters and . ' - _ &"
563
- }
564
- } : '';
565
- requestConstraintsClone.country = this.getCountry() !== null && this.getCountry() !== '' ? {
566
- format: {
567
- pattern: "[a-zA-Z.'-_& ]+",
568
- flags: 'i',
569
- message: "can only contain alphabetical characters and . ' - _ &"
570
- }
571
- } : '';
572
- const validation = (0, _validate.default)(this.getEntityMappings(), requestConstraintsClone);
573
- if (typeof validation === 'undefined') {
574
- resolve();
575
- return;
576
- }
577
- const validationErrorResponse = ERROR_TYPES.VALIDATION_ERROR;
578
- validationErrorResponse.setBodyVariable('validation_errors', validation);
579
- reject(validationErrorResponse);
580
- });
581
- }
582
- }
583
- exports.default = MarketingPreference;
@@ -1,92 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _Model = _interopRequireDefault(require("../Model.model"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * Message Model
11
- */
12
- class Message extends _Model.default {
13
- /**
14
- * Message constructor
15
- *
16
- * @param message
17
- */
18
- constructor(message) {
19
- super();
20
- this.messageId = message.MessageId;
21
- this.receiptHandle = message.ReceiptHandle;
22
- this.body = JSON.parse(message.Body);
23
- this.forDeletion = false;
24
- this.metadata = {};
25
- }
26
-
27
- /**
28
- * Get Message ID
29
- *
30
- * @returns {*}
31
- */
32
- getMessageId() {
33
- return this.messageId;
34
- }
35
-
36
- /**
37
- * Get Receipt Handle
38
- *
39
- * @returns {*}
40
- */
41
- getReceiptHandle() {
42
- return this.receiptHandle;
43
- }
44
-
45
- /**
46
- * Get Body
47
- *
48
- * @returns {any | *}
49
- */
50
- getBody() {
51
- return this.body;
52
- }
53
-
54
- /**
55
- * Set for deletion status
56
- *
57
- * @param forDeletion
58
- */
59
- setForDeletion(forDeletion) {
60
- this.forDeletion = forDeletion;
61
- }
62
-
63
- /**
64
- * Whether message is for deletion
65
- *
66
- * @returns {boolean|*}
67
- */
68
- isForDeletion() {
69
- return this.forDeletion;
70
- }
71
-
72
- /**
73
- * Get all of the message metadata
74
- *
75
- * @returns {{}}
76
- */
77
- getMetaData() {
78
- return this.metadata;
79
- }
80
-
81
- /**
82
- * Set message metadata value
83
- *
84
- * @param key
85
- * @param value
86
- */
87
- setMetaData(key, value) {
88
- this.metadata[key] = value;
89
- return this;
90
- }
91
- }
92
- exports.default = Message;