@comicrelief/lambda-wrapper 1.10.1 → 1.10.2

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