-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.js
More file actions
75 lines (65 loc) · 2.44 KB
/
Copy pathmodels.js
File metadata and controls
75 lines (65 loc) · 2.44 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
const { inspect } = require('node:util');
/**
* Validated routing metadata, constructed only after envelope validation.
* @typedef {Object} Envelope
* @property {string} type
* @property {*} tenantId
* @property {*} correlationId
* @property {number} channel
* @property {number} mode
* @property {number|undefined} ttlSeconds
* @property {string} encryptedDeliveryContext
*/
/**
* Provider-neutral delivery request. Message text is never rewritten.
* @typedef {Object} DispatchRequest
* @property {string} destination
* @property {string} message
* @property {string} channel
* @property {string} messageId
* @property {*} correlationId
* @property {*} locale
*/
class DeliveryContext {
constructor({ nonce, phoneNumber, message, extension, locale, riskContext }) {
this.nonce = nonce;
this.phoneNumber = phoneNumber;
this.message = message;
this.extension = extension;
this.locale = locale;
this.riskContext = riskContext;
}
static fromPayload(payload) {
return payload && typeof payload === 'object' && !Array.isArray(payload)
? new DeliveryContext(payload) : null;
}
get isComplete() {
return [this.nonce, this.phoneNumber, this.message]
.every(value => typeof value === 'string' && value.trim().length > 0);
}
[inspect.custom]() { return '[DeliveryContext]'; }
}
// Adapter-normalized result for outcome mapping, not a public HTTP response.
class ParsedResponse {
/**
* @param {Object} fields
* @param {boolean} fields.success
* @param {number} fields.providerHttpStatus
* @param {string|null} [fields.providerMessageId]
* @param {string|null} [fields.providerStatusName]
* @param {string|null} [fields.providerStatusCode]
* @param {string|null} [fields.providerStatusDescription]
*/
constructor({ success, providerHttpStatus, providerMessageId = null,
providerStatusName = null, providerStatusCode = null, providerStatusDescription = null }) {
this.success = success;
this.providerHttpStatus = providerHttpStatus;
this.providerMessageId = providerMessageId;
this.providerStatusName = providerStatusName;
this.providerStatusCode = providerStatusCode;
this.providerStatusDescription = providerStatusDescription;
}
[inspect.custom]() { return '[ParsedResponse]'; }
}
module.exports = { DeliveryContext, ParsedResponse };