Repository navigation
Expand file tree
/
Copy pathdelivery.js
More file actions
49 lines (41 loc) · 1.54 KB
/
Copy pathdelivery.js
File metadata and controls
49 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const { inspect } = require('node:util');
class DeliveryContext {
constructor({ nonce, phoneNumber, message, otp, extension, locale, riskContext }) {
this.nonce = nonce;
this.phoneNumber = phoneNumber;
this.message = message;
this.otp = otp;
this.extension = extension;
this.locale = locale;
this.riskContext = riskContext;
Object.freeze(this);
}
static fromPayload(value) {
return value && typeof value === 'object' && !Array.isArray(value)
? new DeliveryContext(value) : null;
}
get isComplete() {
return [this.nonce, this.phoneNumber, this.message]
.every((value) => typeof value === 'string' && value.trim().length > 0)
&& (this.otp == null || typeof this.otp === 'string')
&& (this.riskContext == null
|| (typeof this.riskContext === 'object' && !Array.isArray(this.riskContext)));
}
[inspect.custom]() { return '[DeliveryContext]'; }
}
class OtpDelivery {
constructor({ phoneNumber, message, otp, channel, messageId, correlationId, locale, riskContext }) {
this.phoneNumber = phoneNumber;
this.message = message;
this.otp = otp;
this.channel = channel;
this.messageId = messageId;
this.correlationId = correlationId;
this.locale = locale;
this.riskContext = riskContext;
Object.freeze(this);
}
[inspect.custom]() { return '[OtpDelivery]'; }
}
module.exports = { DeliveryContext, OtpDelivery };