@dereekb/nestjs 13.11.18 → 13.12.1
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.
- package/discord/package.json +4 -4
- package/discord/src/lib/discord.api.spec.client.d.ts +20 -0
- package/eslint/index.cjs.js +148 -115
- package/eslint/index.esm.js +148 -115
- package/eslint/package.json +1 -1
- package/mailgun/package.json +6 -6
- package/openai/package.json +6 -6
- package/package.json +11 -4
- package/stripe/package.json +6 -6
- package/twilio/index.cjs.default.js +1 -0
- package/twilio/index.cjs.js +2184 -0
- package/twilio/index.cjs.mjs +2 -0
- package/twilio/index.d.ts +1 -0
- package/twilio/index.esm.js +2159 -0
- package/twilio/package.json +27 -0
- package/twilio/src/index.d.ts +1 -0
- package/twilio/src/lib/index.d.ts +8 -0
- package/twilio/src/lib/lookup/index.d.ts +4 -0
- package/twilio/src/lib/lookup/lookup.api.d.ts +7 -0
- package/twilio/src/lib/lookup/lookup.module.d.ts +7 -0
- package/twilio/src/lib/lookup/lookup.service.d.ts +39 -0
- package/twilio/src/lib/lookup/lookup.type.d.ts +37 -0
- package/twilio/src/lib/twilio.api.d.ts +13 -0
- package/twilio/src/lib/twilio.config.d.ts +71 -0
- package/twilio/src/lib/twilio.module.d.ts +17 -0
- package/twilio/src/lib/twilio.service.d.ts +91 -0
- package/twilio/src/lib/twilio.type.d.ts +53 -0
- package/twilio/src/lib/verify/index.d.ts +4 -0
- package/twilio/src/lib/verify/verify.api.d.ts +10 -0
- package/twilio/src/lib/verify/verify.config.d.ts +22 -0
- package/twilio/src/lib/verify/verify.module.d.ts +17 -0
- package/twilio/src/lib/verify/verify.service.d.ts +83 -0
- package/twilio/src/lib/webhook/index.d.ts +6 -0
- package/twilio/src/lib/webhook/webhook.twilio.config.d.ts +28 -0
- package/twilio/src/lib/webhook/webhook.twilio.controller.d.ts +9 -0
- package/twilio/src/lib/webhook/webhook.twilio.d.ts +68 -0
- package/twilio/src/lib/webhook/webhook.twilio.module.d.ts +22 -0
- package/twilio/src/lib/webhook/webhook.twilio.service.d.ts +21 -0
- package/twilio/src/lib/webhook/webhook.twilio.verify.d.ts +53 -0
- package/typeform/package.json +6 -6
- package/vapiai/package.json +6 -6
|
@@ -0,0 +1,2159 @@
|
|
|
1
|
+
import { Injectable, Inject, Logger, Module, Post, Req, Controller, ForbiddenException } from '@nestjs/common';
|
|
2
|
+
import { Twilio, validateRequest } from 'twilio';
|
|
3
|
+
import { performAsyncTasks, handlerFactory, handlerConfigurerFactory, handlerMappedSetFunctionFactory } from '@dereekb/util';
|
|
4
|
+
import { ConfigService, ConfigModule } from '@nestjs/config';
|
|
5
|
+
import { RawBody } from '@dereekb/nestjs';
|
|
6
|
+
|
|
7
|
+
function _class_call_check$e(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError("Cannot call a class as a function");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties$8(target, props) {
|
|
13
|
+
for(var i = 0; i < props.length; i++){
|
|
14
|
+
var descriptor = props[i];
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
+
descriptor.configurable = true;
|
|
17
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _create_class$8(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (staticProps) _defineProperties$8(Constructor, staticProps);
|
|
23
|
+
return Constructor;
|
|
24
|
+
}
|
|
25
|
+
function _define_property$b(obj, key, value) {
|
|
26
|
+
if (key in obj) {
|
|
27
|
+
Object.defineProperty(obj, key, {
|
|
28
|
+
value: value,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
obj[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
var TWILIO_ACCOUNT_SID_ENV_VAR = 'TWILIO_ACCOUNT_SID';
|
|
39
|
+
var TWILIO_AUTH_TOKEN_ENV_VAR = 'TWILIO_AUTH_TOKEN';
|
|
40
|
+
var TWILIO_API_KEY_SID_ENV_VAR = 'TWILIO_API_KEY_SID';
|
|
41
|
+
var TWILIO_API_KEY_SECRET_ENV_VAR = 'TWILIO_API_KEY_SECRET';
|
|
42
|
+
var TWILIO_PHONE_NUMBER_ENV_VAR = 'TWILIO_PHONE_NUMBER';
|
|
43
|
+
var TWILIO_MESSAGING_SERVICE_SID_ENV_VAR = 'TWILIO_MESSAGING_SERVICE_SID';
|
|
44
|
+
var TWILIO_STATUS_CALLBACK_URL_ENV_VAR = 'TWILIO_STATUS_CALLBACK_URL';
|
|
45
|
+
var TWILIO_SANDBOX_ENV_VAR = 'TWILIO_SANDBOX';
|
|
46
|
+
/**
|
|
47
|
+
* Configuration for {@link TwilioApi} and {@link TwilioService}.
|
|
48
|
+
*/ var TwilioServiceConfig = /*#__PURE__*/ function() {
|
|
49
|
+
function TwilioServiceConfig() {
|
|
50
|
+
_class_call_check$e(this, TwilioServiceConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Client credentials.
|
|
53
|
+
*/ _define_property$b(this, "twilio", void 0);
|
|
54
|
+
/**
|
|
55
|
+
* Outbound message defaults.
|
|
56
|
+
*/ _define_property$b(this, "messages", void 0);
|
|
57
|
+
}
|
|
58
|
+
_create_class$8(TwilioServiceConfig, null, [
|
|
59
|
+
{
|
|
60
|
+
key: "assertValidConfig",
|
|
61
|
+
value: function assertValidConfig(config) {
|
|
62
|
+
if (!config.twilio.accountSid) {
|
|
63
|
+
throw new Error('TwilioServiceConfig: TWILIO_ACCOUNT_SID is required.');
|
|
64
|
+
}
|
|
65
|
+
var hasAuthToken = Boolean(config.twilio.authToken);
|
|
66
|
+
var hasApiKey = Boolean(config.twilio.apiKeySid) && Boolean(config.twilio.apiKeySecret);
|
|
67
|
+
if (!hasAuthToken && !hasApiKey) {
|
|
68
|
+
throw new Error('TwilioServiceConfig: TWILIO_AUTH_TOKEN (or TWILIO_API_KEY_SID + TWILIO_API_KEY_SECRET) is required.');
|
|
69
|
+
}
|
|
70
|
+
if (!config.messages.defaultFrom && !config.messages.messagingServiceSid) {
|
|
71
|
+
throw new Error('TwilioServiceConfig: TWILIO_PHONE_NUMBER or TWILIO_MESSAGING_SERVICE_SID is required.');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]);
|
|
76
|
+
return TwilioServiceConfig;
|
|
77
|
+
}
|
|
78
|
+
();
|
|
79
|
+
|
|
80
|
+
function _type_of(obj) {
|
|
81
|
+
"@swc/helpers - typeof";
|
|
82
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
83
|
+
}
|
|
84
|
+
function __decorate(decorators, target, key, desc) {
|
|
85
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
86
|
+
if ((typeof Reflect === "undefined" ? "undefined" : _type_of(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
87
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
88
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
89
|
+
}
|
|
90
|
+
function __param(paramIndex, decorator) {
|
|
91
|
+
return function(target, key) {
|
|
92
|
+
decorator(target, key, paramIndex);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
96
|
+
var e = new Error(message);
|
|
97
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
function _class_call_check$d(instance, Constructor) {
|
|
101
|
+
if (!(instance instanceof Constructor)) {
|
|
102
|
+
throw new TypeError("Cannot call a class as a function");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function _define_property$a(obj, key, value) {
|
|
106
|
+
if (key in obj) {
|
|
107
|
+
Object.defineProperty(obj, key, {
|
|
108
|
+
value: value,
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
obj[key] = value;
|
|
115
|
+
}
|
|
116
|
+
return obj;
|
|
117
|
+
}
|
|
118
|
+
var TwilioApi = function TwilioApi(config) {
|
|
119
|
+
_class_call_check$d(this, TwilioApi);
|
|
120
|
+
_define_property$a(this, "config", void 0);
|
|
121
|
+
_define_property$a(this, "client", void 0);
|
|
122
|
+
this.config = config;
|
|
123
|
+
var _config_twilio = config.twilio, accountSid = _config_twilio.accountSid, authToken = _config_twilio.authToken, apiKeySid = _config_twilio.apiKeySid, apiKeySecret = _config_twilio.apiKeySecret;
|
|
124
|
+
var client;
|
|
125
|
+
if (apiKeySid && apiKeySecret) {
|
|
126
|
+
client = new Twilio(apiKeySid, apiKeySecret, {
|
|
127
|
+
accountSid: accountSid
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
client = new Twilio(accountSid, authToken);
|
|
131
|
+
}
|
|
132
|
+
this.client = client;
|
|
133
|
+
};
|
|
134
|
+
TwilioApi = __decorate([
|
|
135
|
+
Injectable(),
|
|
136
|
+
__param(0, Inject(TwilioServiceConfig))
|
|
137
|
+
], TwilioApi);
|
|
138
|
+
|
|
139
|
+
function _array_like_to_array(arr, len) {
|
|
140
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
141
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
142
|
+
return arr2;
|
|
143
|
+
}
|
|
144
|
+
function _array_with_holes(arr) {
|
|
145
|
+
if (Array.isArray(arr)) return arr;
|
|
146
|
+
}
|
|
147
|
+
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
|
|
148
|
+
try {
|
|
149
|
+
var info = gen[key](arg);
|
|
150
|
+
var value = info.value;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
reject(error);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (info.done) {
|
|
156
|
+
resolve(value);
|
|
157
|
+
} else {
|
|
158
|
+
Promise.resolve(value).then(_next, _throw);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function _async_to_generator$4(fn) {
|
|
162
|
+
return function() {
|
|
163
|
+
var self = this, args = arguments;
|
|
164
|
+
return new Promise(function(resolve, reject) {
|
|
165
|
+
var gen = fn.apply(self, args);
|
|
166
|
+
function _next(value) {
|
|
167
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
|
|
168
|
+
}
|
|
169
|
+
function _throw(err) {
|
|
170
|
+
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
|
|
171
|
+
}
|
|
172
|
+
_next(undefined);
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function _class_call_check$c(instance, Constructor) {
|
|
177
|
+
if (!(instance instanceof Constructor)) {
|
|
178
|
+
throw new TypeError("Cannot call a class as a function");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function _defineProperties$7(target, props) {
|
|
182
|
+
for(var i = 0; i < props.length; i++){
|
|
183
|
+
var descriptor = props[i];
|
|
184
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
185
|
+
descriptor.configurable = true;
|
|
186
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
187
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function _create_class$7(Constructor, protoProps, staticProps) {
|
|
191
|
+
if (protoProps) _defineProperties$7(Constructor.prototype, protoProps);
|
|
192
|
+
return Constructor;
|
|
193
|
+
}
|
|
194
|
+
function _define_property$9(obj, key, value) {
|
|
195
|
+
if (key in obj) {
|
|
196
|
+
Object.defineProperty(obj, key, {
|
|
197
|
+
value: value,
|
|
198
|
+
enumerable: true,
|
|
199
|
+
configurable: true,
|
|
200
|
+
writable: true
|
|
201
|
+
});
|
|
202
|
+
} else {
|
|
203
|
+
obj[key] = value;
|
|
204
|
+
}
|
|
205
|
+
return obj;
|
|
206
|
+
}
|
|
207
|
+
function _instanceof$1(left, right) {
|
|
208
|
+
"@swc/helpers - instanceof";
|
|
209
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
210
|
+
return !!right[Symbol.hasInstance](left);
|
|
211
|
+
} else {
|
|
212
|
+
return left instanceof right;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function _iterable_to_array_limit(arr, i) {
|
|
216
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
217
|
+
if (_i == null) return;
|
|
218
|
+
var _arr = [];
|
|
219
|
+
var _n = true;
|
|
220
|
+
var _d = false;
|
|
221
|
+
var _s, _e;
|
|
222
|
+
try {
|
|
223
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
224
|
+
_arr.push(_s.value);
|
|
225
|
+
if (i && _arr.length === i) break;
|
|
226
|
+
}
|
|
227
|
+
} catch (err) {
|
|
228
|
+
_d = true;
|
|
229
|
+
_e = err;
|
|
230
|
+
} finally{
|
|
231
|
+
try {
|
|
232
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
233
|
+
} finally{
|
|
234
|
+
if (_d) throw _e;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return _arr;
|
|
238
|
+
}
|
|
239
|
+
function _non_iterable_rest() {
|
|
240
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
241
|
+
}
|
|
242
|
+
function _object_spread$2(target) {
|
|
243
|
+
for(var i = 1; i < arguments.length; i++){
|
|
244
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
245
|
+
var ownKeys = Object.keys(source);
|
|
246
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
247
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
248
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
ownKeys.forEach(function(key) {
|
|
252
|
+
_define_property$9(target, key, source[key]);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return target;
|
|
256
|
+
}
|
|
257
|
+
function _sliced_to_array(arr, i) {
|
|
258
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
259
|
+
}
|
|
260
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
261
|
+
if (!o) return;
|
|
262
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
263
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
264
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
265
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
266
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
267
|
+
}
|
|
268
|
+
function _ts_generator$4(thisArg, body) {
|
|
269
|
+
var f, y, t, _ = {
|
|
270
|
+
label: 0,
|
|
271
|
+
sent: function() {
|
|
272
|
+
if (t[0] & 1) throw t[1];
|
|
273
|
+
return t[1];
|
|
274
|
+
},
|
|
275
|
+
trys: [],
|
|
276
|
+
ops: []
|
|
277
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
278
|
+
return d(g, "next", {
|
|
279
|
+
value: verb(0)
|
|
280
|
+
}), d(g, "throw", {
|
|
281
|
+
value: verb(1)
|
|
282
|
+
}), d(g, "return", {
|
|
283
|
+
value: verb(2)
|
|
284
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
285
|
+
value: function() {
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
}), g;
|
|
289
|
+
function verb(n) {
|
|
290
|
+
return function(v) {
|
|
291
|
+
return step([
|
|
292
|
+
n,
|
|
293
|
+
v
|
|
294
|
+
]);
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function step(op) {
|
|
298
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
299
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
300
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
301
|
+
if (y = 0, t) op = [
|
|
302
|
+
op[0] & 2,
|
|
303
|
+
t.value
|
|
304
|
+
];
|
|
305
|
+
switch(op[0]){
|
|
306
|
+
case 0:
|
|
307
|
+
case 1:
|
|
308
|
+
t = op;
|
|
309
|
+
break;
|
|
310
|
+
case 4:
|
|
311
|
+
_.label++;
|
|
312
|
+
return {
|
|
313
|
+
value: op[1],
|
|
314
|
+
done: false
|
|
315
|
+
};
|
|
316
|
+
case 5:
|
|
317
|
+
_.label++;
|
|
318
|
+
y = op[1];
|
|
319
|
+
op = [
|
|
320
|
+
0
|
|
321
|
+
];
|
|
322
|
+
continue;
|
|
323
|
+
case 7:
|
|
324
|
+
op = _.ops.pop();
|
|
325
|
+
_.trys.pop();
|
|
326
|
+
continue;
|
|
327
|
+
default:
|
|
328
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
329
|
+
_ = 0;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
333
|
+
_.label = op[1];
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
337
|
+
_.label = t[1];
|
|
338
|
+
t = op;
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
if (t && _.label < t[2]) {
|
|
342
|
+
_.label = t[2];
|
|
343
|
+
_.ops.push(op);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
if (t[2]) _.ops.pop();
|
|
347
|
+
_.trys.pop();
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
op = body.call(thisArg, _);
|
|
351
|
+
} catch (e) {
|
|
352
|
+
op = [
|
|
353
|
+
6,
|
|
354
|
+
e
|
|
355
|
+
];
|
|
356
|
+
y = 0;
|
|
357
|
+
} finally{
|
|
358
|
+
f = t = 0;
|
|
359
|
+
}
|
|
360
|
+
if (op[0] & 5) throw op[1];
|
|
361
|
+
return {
|
|
362
|
+
value: op[0] ? op[1] : void 0,
|
|
363
|
+
done: true
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Maximum number of concurrent SMS send requests issued by {@link TwilioService.sendBulkSms}.
|
|
369
|
+
*/ var DEFAULT_TWILIO_SEND_SMS_MAX_PARALLEL_TASKS = 5;
|
|
370
|
+
var TwilioService = /*#__PURE__*/ function() {
|
|
371
|
+
function TwilioService(twilioApi) {
|
|
372
|
+
_class_call_check$c(this, TwilioService);
|
|
373
|
+
_define_property$9(this, "logger", new Logger('TwilioService'));
|
|
374
|
+
_define_property$9(this, "_twilioApi", void 0);
|
|
375
|
+
this._twilioApi = twilioApi;
|
|
376
|
+
}
|
|
377
|
+
_create_class$7(TwilioService, [
|
|
378
|
+
{
|
|
379
|
+
key: "twilioApi",
|
|
380
|
+
get: function get() {
|
|
381
|
+
return this._twilioApi;
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
key: "sendSms",
|
|
386
|
+
value: /**
|
|
387
|
+
* Sends a single SMS through Twilio. Honors the configured sandbox flag.
|
|
388
|
+
*
|
|
389
|
+
* @param input - Recipient, body, and optional sender/callback/media overrides.
|
|
390
|
+
* @returns The result of the send attempt, including the Twilio Message SID on success.
|
|
391
|
+
*/ function sendSms(input) {
|
|
392
|
+
return _async_to_generator$4(function() {
|
|
393
|
+
var messages, isSandbox, result, _ref, _input_from, _ref1, _input_messagingServiceSid, _ref2, _input_statusCallback, from, messagingServiceSid, statusCallback, _input_mediaUrl, message, e, errorMessage;
|
|
394
|
+
return _ts_generator$4(this, function(_state) {
|
|
395
|
+
switch(_state.label){
|
|
396
|
+
case 0:
|
|
397
|
+
messages = this._twilioApi.config.messages;
|
|
398
|
+
isSandbox = messages.sandbox === true;
|
|
399
|
+
if (!isSandbox) return [
|
|
400
|
+
3,
|
|
401
|
+
1
|
|
402
|
+
];
|
|
403
|
+
result = {
|
|
404
|
+
sid: null,
|
|
405
|
+
to: input.to,
|
|
406
|
+
status: 'queued',
|
|
407
|
+
sandboxed: true
|
|
408
|
+
};
|
|
409
|
+
return [
|
|
410
|
+
3,
|
|
411
|
+
5
|
|
412
|
+
];
|
|
413
|
+
case 1:
|
|
414
|
+
from = (_ref = (_input_from = input.from) !== null && _input_from !== void 0 ? _input_from : messages.defaultFrom) !== null && _ref !== void 0 ? _ref : undefined;
|
|
415
|
+
messagingServiceSid = (_ref1 = (_input_messagingServiceSid = input.messagingServiceSid) !== null && _input_messagingServiceSid !== void 0 ? _input_messagingServiceSid : messages.messagingServiceSid) !== null && _ref1 !== void 0 ? _ref1 : undefined;
|
|
416
|
+
statusCallback = (_ref2 = (_input_statusCallback = input.statusCallback) !== null && _input_statusCallback !== void 0 ? _input_statusCallback : messages.defaultStatusCallback) !== null && _ref2 !== void 0 ? _ref2 : undefined;
|
|
417
|
+
_state.label = 2;
|
|
418
|
+
case 2:
|
|
419
|
+
_state.trys.push([
|
|
420
|
+
2,
|
|
421
|
+
4,
|
|
422
|
+
,
|
|
423
|
+
5
|
|
424
|
+
]);
|
|
425
|
+
return [
|
|
426
|
+
4,
|
|
427
|
+
this._twilioApi.client.messages.create(_object_spread$2({
|
|
428
|
+
to: input.to,
|
|
429
|
+
body: input.body
|
|
430
|
+
}, messagingServiceSid ? {
|
|
431
|
+
messagingServiceSid: messagingServiceSid
|
|
432
|
+
} : {
|
|
433
|
+
from: from
|
|
434
|
+
}, statusCallback ? {
|
|
435
|
+
statusCallback: statusCallback
|
|
436
|
+
} : {}, ((_input_mediaUrl = input.mediaUrl) === null || _input_mediaUrl === void 0 ? void 0 : _input_mediaUrl.length) ? {
|
|
437
|
+
mediaUrl: input.mediaUrl
|
|
438
|
+
} : {}))
|
|
439
|
+
];
|
|
440
|
+
case 3:
|
|
441
|
+
message = _state.sent();
|
|
442
|
+
result = {
|
|
443
|
+
sid: message.sid,
|
|
444
|
+
to: input.to,
|
|
445
|
+
status: message.status,
|
|
446
|
+
sandboxed: false
|
|
447
|
+
};
|
|
448
|
+
return [
|
|
449
|
+
3,
|
|
450
|
+
5
|
|
451
|
+
];
|
|
452
|
+
case 4:
|
|
453
|
+
e = _state.sent();
|
|
454
|
+
errorMessage = _instanceof$1(e, Error) ? e.message : String(e);
|
|
455
|
+
this.logger.error("Failed sending SMS to ".concat(input.to, ": ").concat(errorMessage));
|
|
456
|
+
result = {
|
|
457
|
+
sid: null,
|
|
458
|
+
to: input.to,
|
|
459
|
+
status: 'failed',
|
|
460
|
+
sandboxed: false,
|
|
461
|
+
error: errorMessage
|
|
462
|
+
};
|
|
463
|
+
return [
|
|
464
|
+
3,
|
|
465
|
+
5
|
|
466
|
+
];
|
|
467
|
+
case 5:
|
|
468
|
+
return [
|
|
469
|
+
2,
|
|
470
|
+
result
|
|
471
|
+
];
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}).call(this);
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
key: "sendBulkSms",
|
|
479
|
+
value: /**
|
|
480
|
+
* Sends a batch of SMS messages through Twilio with bounded parallelism. Failures are
|
|
481
|
+
* captured per-message and never reject the returned promise.
|
|
482
|
+
*
|
|
483
|
+
* @param inputs - Array of SMS send inputs, one per recipient.
|
|
484
|
+
* @param maxParallelTasks - Maximum concurrent Twilio requests in flight.
|
|
485
|
+
* @returns One {@link TwilioSendSmsResult} per input, in input order.
|
|
486
|
+
*/ function sendBulkSms(_0) {
|
|
487
|
+
return _async_to_generator$4(function(inputs) {
|
|
488
|
+
var _this, maxParallelTasks, results;
|
|
489
|
+
var _arguments = arguments;
|
|
490
|
+
return _ts_generator$4(this, function(_state) {
|
|
491
|
+
switch(_state.label){
|
|
492
|
+
case 0:
|
|
493
|
+
_this = this;
|
|
494
|
+
maxParallelTasks = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : DEFAULT_TWILIO_SEND_SMS_MAX_PARALLEL_TASKS;
|
|
495
|
+
return [
|
|
496
|
+
4,
|
|
497
|
+
performAsyncTasks(inputs, function(input) {
|
|
498
|
+
return _this.sendSms(input);
|
|
499
|
+
}, {
|
|
500
|
+
maxParallelTasks: maxParallelTasks,
|
|
501
|
+
throwError: false
|
|
502
|
+
})
|
|
503
|
+
];
|
|
504
|
+
case 1:
|
|
505
|
+
results = _state.sent().results;
|
|
506
|
+
return [
|
|
507
|
+
2,
|
|
508
|
+
results.map(function(param) {
|
|
509
|
+
var _param = _sliced_to_array(param, 2), result = _param[1];
|
|
510
|
+
return result;
|
|
511
|
+
})
|
|
512
|
+
];
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}).apply(this, arguments);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
]);
|
|
519
|
+
return TwilioService;
|
|
520
|
+
}();
|
|
521
|
+
TwilioService = __decorate([
|
|
522
|
+
Injectable(),
|
|
523
|
+
__param(0, Inject(TwilioApi))
|
|
524
|
+
], TwilioService);
|
|
525
|
+
|
|
526
|
+
function _class_call_check$b(instance, Constructor) {
|
|
527
|
+
if (!(instance instanceof Constructor)) {
|
|
528
|
+
throw new TypeError("Cannot call a class as a function");
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Factory that creates a {@link TwilioServiceConfig} from environment variables.
|
|
533
|
+
*
|
|
534
|
+
* @param configService - NestJS config service for reading environment variables.
|
|
535
|
+
* @returns A validated {@link TwilioServiceConfig}.
|
|
536
|
+
*/ function twilioServiceConfigFactory(configService) {
|
|
537
|
+
var config = {
|
|
538
|
+
twilio: {
|
|
539
|
+
accountSid: configService.get(TWILIO_ACCOUNT_SID_ENV_VAR),
|
|
540
|
+
authToken: configService.get(TWILIO_AUTH_TOKEN_ENV_VAR),
|
|
541
|
+
apiKeySid: configService.get(TWILIO_API_KEY_SID_ENV_VAR),
|
|
542
|
+
apiKeySecret: configService.get(TWILIO_API_KEY_SECRET_ENV_VAR)
|
|
543
|
+
},
|
|
544
|
+
messages: {
|
|
545
|
+
defaultFrom: configService.get(TWILIO_PHONE_NUMBER_ENV_VAR),
|
|
546
|
+
messagingServiceSid: configService.get(TWILIO_MESSAGING_SERVICE_SID_ENV_VAR),
|
|
547
|
+
defaultStatusCallback: configService.get(TWILIO_STATUS_CALLBACK_URL_ENV_VAR),
|
|
548
|
+
sandbox: configService.get(TWILIO_SANDBOX_ENV_VAR) === 'true'
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
TwilioServiceConfig.assertValidConfig(config);
|
|
552
|
+
return config;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* NestJS module that provides the {@link TwilioApi} and {@link TwilioService} for sending SMS
|
|
556
|
+
* via Twilio.
|
|
557
|
+
*
|
|
558
|
+
* Reads Twilio credentials and default sender configuration from environment variables.
|
|
559
|
+
*/ var TwilioModule = function TwilioModule() {
|
|
560
|
+
_class_call_check$b(this, TwilioModule);
|
|
561
|
+
};
|
|
562
|
+
TwilioModule = __decorate([
|
|
563
|
+
Module({
|
|
564
|
+
imports: [
|
|
565
|
+
ConfigModule
|
|
566
|
+
],
|
|
567
|
+
providers: [
|
|
568
|
+
{
|
|
569
|
+
provide: TwilioServiceConfig,
|
|
570
|
+
inject: [
|
|
571
|
+
ConfigService
|
|
572
|
+
],
|
|
573
|
+
useFactory: twilioServiceConfigFactory
|
|
574
|
+
},
|
|
575
|
+
TwilioApi,
|
|
576
|
+
TwilioService
|
|
577
|
+
],
|
|
578
|
+
exports: [
|
|
579
|
+
TwilioApi,
|
|
580
|
+
TwilioService
|
|
581
|
+
]
|
|
582
|
+
})
|
|
583
|
+
], TwilioModule);
|
|
584
|
+
|
|
585
|
+
function _class_call_check$a(instance, Constructor) {
|
|
586
|
+
if (!(instance instanceof Constructor)) {
|
|
587
|
+
throw new TypeError("Cannot call a class as a function");
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function _defineProperties$6(target, props) {
|
|
591
|
+
for(var i = 0; i < props.length; i++){
|
|
592
|
+
var descriptor = props[i];
|
|
593
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
594
|
+
descriptor.configurable = true;
|
|
595
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
596
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
function _create_class$6(Constructor, protoProps, staticProps) {
|
|
600
|
+
if (protoProps) _defineProperties$6(Constructor.prototype, protoProps);
|
|
601
|
+
return Constructor;
|
|
602
|
+
}
|
|
603
|
+
function _define_property$8(obj, key, value) {
|
|
604
|
+
if (key in obj) {
|
|
605
|
+
Object.defineProperty(obj, key, {
|
|
606
|
+
value: value,
|
|
607
|
+
enumerable: true,
|
|
608
|
+
configurable: true,
|
|
609
|
+
writable: true
|
|
610
|
+
});
|
|
611
|
+
} else {
|
|
612
|
+
obj[key] = value;
|
|
613
|
+
}
|
|
614
|
+
return obj;
|
|
615
|
+
}
|
|
616
|
+
var TwilioLookupApi = /*#__PURE__*/ function() {
|
|
617
|
+
function TwilioLookupApi(twilioApi) {
|
|
618
|
+
_class_call_check$a(this, TwilioLookupApi);
|
|
619
|
+
_define_property$8(this, "_twilioApi", void 0);
|
|
620
|
+
this._twilioApi = twilioApi;
|
|
621
|
+
}
|
|
622
|
+
_create_class$6(TwilioLookupApi, [
|
|
623
|
+
{
|
|
624
|
+
key: "twilioApi",
|
|
625
|
+
get: function get() {
|
|
626
|
+
return this._twilioApi;
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
key: "phoneNumbers",
|
|
631
|
+
get: function get() {
|
|
632
|
+
return this._twilioApi.client.lookups.v2.phoneNumbers;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
]);
|
|
636
|
+
return TwilioLookupApi;
|
|
637
|
+
}();
|
|
638
|
+
TwilioLookupApi = __decorate([
|
|
639
|
+
Injectable(),
|
|
640
|
+
__param(0, Inject(TwilioApi))
|
|
641
|
+
], TwilioLookupApi);
|
|
642
|
+
|
|
643
|
+
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
|
|
644
|
+
try {
|
|
645
|
+
var info = gen[key](arg);
|
|
646
|
+
var value = info.value;
|
|
647
|
+
} catch (error) {
|
|
648
|
+
reject(error);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (info.done) {
|
|
652
|
+
resolve(value);
|
|
653
|
+
} else {
|
|
654
|
+
Promise.resolve(value).then(_next, _throw);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function _async_to_generator$3(fn) {
|
|
658
|
+
return function() {
|
|
659
|
+
var self = this, args = arguments;
|
|
660
|
+
return new Promise(function(resolve, reject) {
|
|
661
|
+
var gen = fn.apply(self, args);
|
|
662
|
+
function _next(value) {
|
|
663
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
|
|
664
|
+
}
|
|
665
|
+
function _throw(err) {
|
|
666
|
+
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
|
|
667
|
+
}
|
|
668
|
+
_next(undefined);
|
|
669
|
+
});
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function _class_call_check$9(instance, Constructor) {
|
|
673
|
+
if (!(instance instanceof Constructor)) {
|
|
674
|
+
throw new TypeError("Cannot call a class as a function");
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function _defineProperties$5(target, props) {
|
|
678
|
+
for(var i = 0; i < props.length; i++){
|
|
679
|
+
var descriptor = props[i];
|
|
680
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
681
|
+
descriptor.configurable = true;
|
|
682
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
683
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function _create_class$5(Constructor, protoProps, staticProps) {
|
|
687
|
+
if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
|
|
688
|
+
return Constructor;
|
|
689
|
+
}
|
|
690
|
+
function _define_property$7(obj, key, value) {
|
|
691
|
+
if (key in obj) {
|
|
692
|
+
Object.defineProperty(obj, key, {
|
|
693
|
+
value: value,
|
|
694
|
+
enumerable: true,
|
|
695
|
+
configurable: true,
|
|
696
|
+
writable: true
|
|
697
|
+
});
|
|
698
|
+
} else {
|
|
699
|
+
obj[key] = value;
|
|
700
|
+
}
|
|
701
|
+
return obj;
|
|
702
|
+
}
|
|
703
|
+
function _instanceof(left, right) {
|
|
704
|
+
"@swc/helpers - instanceof";
|
|
705
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
706
|
+
return !!right[Symbol.hasInstance](left);
|
|
707
|
+
} else {
|
|
708
|
+
return left instanceof right;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function _ts_generator$3(thisArg, body) {
|
|
712
|
+
var f, y, t, _ = {
|
|
713
|
+
label: 0,
|
|
714
|
+
sent: function() {
|
|
715
|
+
if (t[0] & 1) throw t[1];
|
|
716
|
+
return t[1];
|
|
717
|
+
},
|
|
718
|
+
trys: [],
|
|
719
|
+
ops: []
|
|
720
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
721
|
+
return d(g, "next", {
|
|
722
|
+
value: verb(0)
|
|
723
|
+
}), d(g, "throw", {
|
|
724
|
+
value: verb(1)
|
|
725
|
+
}), d(g, "return", {
|
|
726
|
+
value: verb(2)
|
|
727
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
728
|
+
value: function() {
|
|
729
|
+
return this;
|
|
730
|
+
}
|
|
731
|
+
}), g;
|
|
732
|
+
function verb(n) {
|
|
733
|
+
return function(v) {
|
|
734
|
+
return step([
|
|
735
|
+
n,
|
|
736
|
+
v
|
|
737
|
+
]);
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function step(op) {
|
|
741
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
742
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
743
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
744
|
+
if (y = 0, t) op = [
|
|
745
|
+
op[0] & 2,
|
|
746
|
+
t.value
|
|
747
|
+
];
|
|
748
|
+
switch(op[0]){
|
|
749
|
+
case 0:
|
|
750
|
+
case 1:
|
|
751
|
+
t = op;
|
|
752
|
+
break;
|
|
753
|
+
case 4:
|
|
754
|
+
_.label++;
|
|
755
|
+
return {
|
|
756
|
+
value: op[1],
|
|
757
|
+
done: false
|
|
758
|
+
};
|
|
759
|
+
case 5:
|
|
760
|
+
_.label++;
|
|
761
|
+
y = op[1];
|
|
762
|
+
op = [
|
|
763
|
+
0
|
|
764
|
+
];
|
|
765
|
+
continue;
|
|
766
|
+
case 7:
|
|
767
|
+
op = _.ops.pop();
|
|
768
|
+
_.trys.pop();
|
|
769
|
+
continue;
|
|
770
|
+
default:
|
|
771
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
772
|
+
_ = 0;
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
776
|
+
_.label = op[1];
|
|
777
|
+
break;
|
|
778
|
+
}
|
|
779
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
780
|
+
_.label = t[1];
|
|
781
|
+
t = op;
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
if (t && _.label < t[2]) {
|
|
785
|
+
_.label = t[2];
|
|
786
|
+
_.ops.push(op);
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
if (t[2]) _.ops.pop();
|
|
790
|
+
_.trys.pop();
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
op = body.call(thisArg, _);
|
|
794
|
+
} catch (e) {
|
|
795
|
+
op = [
|
|
796
|
+
6,
|
|
797
|
+
e
|
|
798
|
+
];
|
|
799
|
+
y = 0;
|
|
800
|
+
} finally{
|
|
801
|
+
f = t = 0;
|
|
802
|
+
}
|
|
803
|
+
if (op[0] & 5) throw op[1];
|
|
804
|
+
return {
|
|
805
|
+
value: op[0] ? op[1] : void 0,
|
|
806
|
+
done: true
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
var TwilioLookupService = /*#__PURE__*/ function() {
|
|
811
|
+
function TwilioLookupService(twilioLookupApi) {
|
|
812
|
+
_class_call_check$9(this, TwilioLookupService);
|
|
813
|
+
_define_property$7(this, "logger", new Logger('TwilioLookupService'));
|
|
814
|
+
_define_property$7(this, "_twilioLookupApi", void 0);
|
|
815
|
+
this._twilioLookupApi = twilioLookupApi;
|
|
816
|
+
}
|
|
817
|
+
_create_class$5(TwilioLookupService, [
|
|
818
|
+
{
|
|
819
|
+
key: "twilioLookupApi",
|
|
820
|
+
get: function get() {
|
|
821
|
+
return this._twilioLookupApi;
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
key: "lookup",
|
|
826
|
+
value: /**
|
|
827
|
+
* Validates and normalizes a phone number via Twilio Lookup v2. Optionally returns carrier
|
|
828
|
+
* information when `includeCarrier` is set (additional Twilio charges apply).
|
|
829
|
+
*
|
|
830
|
+
* @param input - Phone number to look up plus optional carrier / country-code flags.
|
|
831
|
+
* @returns The lookup result, with `valid: false` when Twilio cannot resolve the number.
|
|
832
|
+
*/ function lookup(input) {
|
|
833
|
+
return _async_to_generator$3(function() {
|
|
834
|
+
var phoneNumberInstance, fetchInput, result, lookup, carrier, lti, e;
|
|
835
|
+
return _ts_generator$3(this, function(_state) {
|
|
836
|
+
switch(_state.label){
|
|
837
|
+
case 0:
|
|
838
|
+
phoneNumberInstance = this._twilioLookupApi.phoneNumbers(input.phoneNumber);
|
|
839
|
+
fetchInput = {};
|
|
840
|
+
if (input.includeCarrier) {
|
|
841
|
+
fetchInput.fields = 'line_type_intelligence';
|
|
842
|
+
}
|
|
843
|
+
if (input.countryCode) {
|
|
844
|
+
fetchInput.countryCode = input.countryCode;
|
|
845
|
+
}
|
|
846
|
+
_state.label = 1;
|
|
847
|
+
case 1:
|
|
848
|
+
_state.trys.push([
|
|
849
|
+
1,
|
|
850
|
+
3,
|
|
851
|
+
,
|
|
852
|
+
4
|
|
853
|
+
]);
|
|
854
|
+
return [
|
|
855
|
+
4,
|
|
856
|
+
phoneNumberInstance.fetch(fetchInput)
|
|
857
|
+
];
|
|
858
|
+
case 2:
|
|
859
|
+
lookup = _state.sent();
|
|
860
|
+
if (input.includeCarrier && lookup.lineTypeIntelligence) {
|
|
861
|
+
lti = lookup.lineTypeIntelligence;
|
|
862
|
+
carrier = {
|
|
863
|
+
carrierName: lti['carrier_name'],
|
|
864
|
+
type: lti['type'],
|
|
865
|
+
mobileCountryCode: lti['mobile_country_code'],
|
|
866
|
+
mobileNetworkCode: lti['mobile_network_code']
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
result = {
|
|
870
|
+
valid: Boolean(lookup.valid),
|
|
871
|
+
phoneNumber: lookup.phoneNumber,
|
|
872
|
+
countryCode: lookup.countryCode,
|
|
873
|
+
nationalFormat: lookup.nationalFormat,
|
|
874
|
+
carrier: carrier
|
|
875
|
+
};
|
|
876
|
+
return [
|
|
877
|
+
3,
|
|
878
|
+
4
|
|
879
|
+
];
|
|
880
|
+
case 3:
|
|
881
|
+
e = _state.sent();
|
|
882
|
+
this.logger.warn("Failed to lookup phone number ".concat(input.phoneNumber, ": ").concat(_instanceof(e, Error) ? e.message : String(e)));
|
|
883
|
+
result = {
|
|
884
|
+
valid: false,
|
|
885
|
+
phoneNumber: input.phoneNumber
|
|
886
|
+
};
|
|
887
|
+
return [
|
|
888
|
+
3,
|
|
889
|
+
4
|
|
890
|
+
];
|
|
891
|
+
case 4:
|
|
892
|
+
return [
|
|
893
|
+
2,
|
|
894
|
+
result
|
|
895
|
+
];
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
}).call(this);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
]);
|
|
902
|
+
return TwilioLookupService;
|
|
903
|
+
}();
|
|
904
|
+
TwilioLookupService = __decorate([
|
|
905
|
+
Injectable(),
|
|
906
|
+
__param(0, Inject(TwilioLookupApi))
|
|
907
|
+
], TwilioLookupService);
|
|
908
|
+
|
|
909
|
+
function _class_call_check$8(instance, Constructor) {
|
|
910
|
+
if (!(instance instanceof Constructor)) {
|
|
911
|
+
throw new TypeError("Cannot call a class as a function");
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* NestJS module that exposes Twilio Lookup v2 (phone validation, carrier info).
|
|
916
|
+
*
|
|
917
|
+
* Imports {@link TwilioModule} for the underlying Twilio client.
|
|
918
|
+
*/ var TwilioLookupModule = function TwilioLookupModule() {
|
|
919
|
+
_class_call_check$8(this, TwilioLookupModule);
|
|
920
|
+
};
|
|
921
|
+
TwilioLookupModule = __decorate([
|
|
922
|
+
Module({
|
|
923
|
+
imports: [
|
|
924
|
+
TwilioModule
|
|
925
|
+
],
|
|
926
|
+
providers: [
|
|
927
|
+
TwilioLookupApi,
|
|
928
|
+
TwilioLookupService
|
|
929
|
+
],
|
|
930
|
+
exports: [
|
|
931
|
+
TwilioLookupApi,
|
|
932
|
+
TwilioLookupService
|
|
933
|
+
]
|
|
934
|
+
})
|
|
935
|
+
], TwilioLookupModule);
|
|
936
|
+
|
|
937
|
+
function _class_call_check$7(instance, Constructor) {
|
|
938
|
+
if (!(instance instanceof Constructor)) {
|
|
939
|
+
throw new TypeError("Cannot call a class as a function");
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function _defineProperties$4(target, props) {
|
|
943
|
+
for(var i = 0; i < props.length; i++){
|
|
944
|
+
var descriptor = props[i];
|
|
945
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
946
|
+
descriptor.configurable = true;
|
|
947
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
948
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
function _create_class$4(Constructor, protoProps, staticProps) {
|
|
952
|
+
if (staticProps) _defineProperties$4(Constructor, staticProps);
|
|
953
|
+
return Constructor;
|
|
954
|
+
}
|
|
955
|
+
function _define_property$6(obj, key, value) {
|
|
956
|
+
if (key in obj) {
|
|
957
|
+
Object.defineProperty(obj, key, {
|
|
958
|
+
value: value,
|
|
959
|
+
enumerable: true,
|
|
960
|
+
configurable: true,
|
|
961
|
+
writable: true
|
|
962
|
+
});
|
|
963
|
+
} else {
|
|
964
|
+
obj[key] = value;
|
|
965
|
+
}
|
|
966
|
+
return obj;
|
|
967
|
+
}
|
|
968
|
+
var TWILIO_VERIFY_SERVICE_SID_ENV_VAR = 'TWILIO_VERIFY_SERVICE_SID';
|
|
969
|
+
/**
|
|
970
|
+
* Configuration for {@link TwilioVerifyApi} and {@link TwilioVerifyService}.
|
|
971
|
+
*/ var TwilioVerifyServiceConfig = /*#__PURE__*/ function() {
|
|
972
|
+
function TwilioVerifyServiceConfig() {
|
|
973
|
+
_class_call_check$7(this, TwilioVerifyServiceConfig);
|
|
974
|
+
_define_property$6(this, "twilioVerify", void 0);
|
|
975
|
+
}
|
|
976
|
+
_create_class$4(TwilioVerifyServiceConfig, null, [
|
|
977
|
+
{
|
|
978
|
+
key: "assertValidConfig",
|
|
979
|
+
value: function assertValidConfig(config) {
|
|
980
|
+
if (!config.twilioVerify.verifyServiceSid) {
|
|
981
|
+
throw new Error('TwilioVerifyServiceConfig: TWILIO_VERIFY_SERVICE_SID is required.');
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
]);
|
|
986
|
+
return TwilioVerifyServiceConfig;
|
|
987
|
+
}
|
|
988
|
+
();
|
|
989
|
+
|
|
990
|
+
function _class_call_check$6(instance, Constructor) {
|
|
991
|
+
if (!(instance instanceof Constructor)) {
|
|
992
|
+
throw new TypeError("Cannot call a class as a function");
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
function _defineProperties$3(target, props) {
|
|
996
|
+
for(var i = 0; i < props.length; i++){
|
|
997
|
+
var descriptor = props[i];
|
|
998
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
999
|
+
descriptor.configurable = true;
|
|
1000
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1001
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
function _create_class$3(Constructor, protoProps, staticProps) {
|
|
1005
|
+
if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
|
|
1006
|
+
return Constructor;
|
|
1007
|
+
}
|
|
1008
|
+
function _define_property$5(obj, key, value) {
|
|
1009
|
+
if (key in obj) {
|
|
1010
|
+
Object.defineProperty(obj, key, {
|
|
1011
|
+
value: value,
|
|
1012
|
+
enumerable: true,
|
|
1013
|
+
configurable: true,
|
|
1014
|
+
writable: true
|
|
1015
|
+
});
|
|
1016
|
+
} else {
|
|
1017
|
+
obj[key] = value;
|
|
1018
|
+
}
|
|
1019
|
+
return obj;
|
|
1020
|
+
}
|
|
1021
|
+
var TwilioVerifyApi = /*#__PURE__*/ function() {
|
|
1022
|
+
function TwilioVerifyApi(twilioApi, config) {
|
|
1023
|
+
_class_call_check$6(this, TwilioVerifyApi);
|
|
1024
|
+
_define_property$5(this, "_twilioApi", void 0);
|
|
1025
|
+
_define_property$5(this, "_config", void 0);
|
|
1026
|
+
this._twilioApi = twilioApi;
|
|
1027
|
+
this._config = config;
|
|
1028
|
+
}
|
|
1029
|
+
_create_class$3(TwilioVerifyApi, [
|
|
1030
|
+
{
|
|
1031
|
+
key: "twilioApi",
|
|
1032
|
+
get: function get() {
|
|
1033
|
+
return this._twilioApi;
|
|
1034
|
+
}
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
key: "verifyService",
|
|
1038
|
+
get: function get() {
|
|
1039
|
+
return this._twilioApi.client.verify.v2.services(this._config.twilioVerify.verifyServiceSid);
|
|
1040
|
+
}
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
key: "config",
|
|
1044
|
+
get: function get() {
|
|
1045
|
+
return this._config;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
]);
|
|
1049
|
+
return TwilioVerifyApi;
|
|
1050
|
+
}();
|
|
1051
|
+
TwilioVerifyApi = __decorate([
|
|
1052
|
+
Injectable(),
|
|
1053
|
+
__param(0, Inject(TwilioApi)),
|
|
1054
|
+
__param(1, Inject(TwilioVerifyServiceConfig))
|
|
1055
|
+
], TwilioVerifyApi);
|
|
1056
|
+
|
|
1057
|
+
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1058
|
+
try {
|
|
1059
|
+
var info = gen[key](arg);
|
|
1060
|
+
var value = info.value;
|
|
1061
|
+
} catch (error) {
|
|
1062
|
+
reject(error);
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (info.done) {
|
|
1066
|
+
resolve(value);
|
|
1067
|
+
} else {
|
|
1068
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
function _async_to_generator$2(fn) {
|
|
1072
|
+
return function() {
|
|
1073
|
+
var self = this, args = arguments;
|
|
1074
|
+
return new Promise(function(resolve, reject) {
|
|
1075
|
+
var gen = fn.apply(self, args);
|
|
1076
|
+
function _next(value) {
|
|
1077
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
|
|
1078
|
+
}
|
|
1079
|
+
function _throw(err) {
|
|
1080
|
+
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1081
|
+
}
|
|
1082
|
+
_next(undefined);
|
|
1083
|
+
});
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
function _class_call_check$5(instance, Constructor) {
|
|
1087
|
+
if (!(instance instanceof Constructor)) {
|
|
1088
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
function _defineProperties$2(target, props) {
|
|
1092
|
+
for(var i = 0; i < props.length; i++){
|
|
1093
|
+
var descriptor = props[i];
|
|
1094
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1095
|
+
descriptor.configurable = true;
|
|
1096
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1097
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
function _create_class$2(Constructor, protoProps, staticProps) {
|
|
1101
|
+
if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
|
|
1102
|
+
return Constructor;
|
|
1103
|
+
}
|
|
1104
|
+
function _define_property$4(obj, key, value) {
|
|
1105
|
+
if (key in obj) {
|
|
1106
|
+
Object.defineProperty(obj, key, {
|
|
1107
|
+
value: value,
|
|
1108
|
+
enumerable: true,
|
|
1109
|
+
configurable: true,
|
|
1110
|
+
writable: true
|
|
1111
|
+
});
|
|
1112
|
+
} else {
|
|
1113
|
+
obj[key] = value;
|
|
1114
|
+
}
|
|
1115
|
+
return obj;
|
|
1116
|
+
}
|
|
1117
|
+
function _object_spread$1(target) {
|
|
1118
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1119
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
1120
|
+
var ownKeys = Object.keys(source);
|
|
1121
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1122
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1123
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1124
|
+
}));
|
|
1125
|
+
}
|
|
1126
|
+
ownKeys.forEach(function(key) {
|
|
1127
|
+
_define_property$4(target, key, source[key]);
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
return target;
|
|
1131
|
+
}
|
|
1132
|
+
function _ts_generator$2(thisArg, body) {
|
|
1133
|
+
var f, y, t, _ = {
|
|
1134
|
+
label: 0,
|
|
1135
|
+
sent: function() {
|
|
1136
|
+
if (t[0] & 1) throw t[1];
|
|
1137
|
+
return t[1];
|
|
1138
|
+
},
|
|
1139
|
+
trys: [],
|
|
1140
|
+
ops: []
|
|
1141
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1142
|
+
return d(g, "next", {
|
|
1143
|
+
value: verb(0)
|
|
1144
|
+
}), d(g, "throw", {
|
|
1145
|
+
value: verb(1)
|
|
1146
|
+
}), d(g, "return", {
|
|
1147
|
+
value: verb(2)
|
|
1148
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1149
|
+
value: function() {
|
|
1150
|
+
return this;
|
|
1151
|
+
}
|
|
1152
|
+
}), g;
|
|
1153
|
+
function verb(n) {
|
|
1154
|
+
return function(v) {
|
|
1155
|
+
return step([
|
|
1156
|
+
n,
|
|
1157
|
+
v
|
|
1158
|
+
]);
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
function step(op) {
|
|
1162
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1163
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1164
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1165
|
+
if (y = 0, t) op = [
|
|
1166
|
+
op[0] & 2,
|
|
1167
|
+
t.value
|
|
1168
|
+
];
|
|
1169
|
+
switch(op[0]){
|
|
1170
|
+
case 0:
|
|
1171
|
+
case 1:
|
|
1172
|
+
t = op;
|
|
1173
|
+
break;
|
|
1174
|
+
case 4:
|
|
1175
|
+
_.label++;
|
|
1176
|
+
return {
|
|
1177
|
+
value: op[1],
|
|
1178
|
+
done: false
|
|
1179
|
+
};
|
|
1180
|
+
case 5:
|
|
1181
|
+
_.label++;
|
|
1182
|
+
y = op[1];
|
|
1183
|
+
op = [
|
|
1184
|
+
0
|
|
1185
|
+
];
|
|
1186
|
+
continue;
|
|
1187
|
+
case 7:
|
|
1188
|
+
op = _.ops.pop();
|
|
1189
|
+
_.trys.pop();
|
|
1190
|
+
continue;
|
|
1191
|
+
default:
|
|
1192
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1193
|
+
_ = 0;
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1197
|
+
_.label = op[1];
|
|
1198
|
+
break;
|
|
1199
|
+
}
|
|
1200
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1201
|
+
_.label = t[1];
|
|
1202
|
+
t = op;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
if (t && _.label < t[2]) {
|
|
1206
|
+
_.label = t[2];
|
|
1207
|
+
_.ops.push(op);
|
|
1208
|
+
break;
|
|
1209
|
+
}
|
|
1210
|
+
if (t[2]) _.ops.pop();
|
|
1211
|
+
_.trys.pop();
|
|
1212
|
+
continue;
|
|
1213
|
+
}
|
|
1214
|
+
op = body.call(thisArg, _);
|
|
1215
|
+
} catch (e) {
|
|
1216
|
+
op = [
|
|
1217
|
+
6,
|
|
1218
|
+
e
|
|
1219
|
+
];
|
|
1220
|
+
y = 0;
|
|
1221
|
+
} finally{
|
|
1222
|
+
f = t = 0;
|
|
1223
|
+
}
|
|
1224
|
+
if (op[0] & 5) throw op[1];
|
|
1225
|
+
return {
|
|
1226
|
+
value: op[0] ? op[1] : void 0,
|
|
1227
|
+
done: true
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
var TwilioVerifyService = /*#__PURE__*/ function() {
|
|
1232
|
+
function TwilioVerifyService(twilioVerifyApi) {
|
|
1233
|
+
_class_call_check$5(this, TwilioVerifyService);
|
|
1234
|
+
_define_property$4(this, "_twilioVerifyApi", void 0);
|
|
1235
|
+
this._twilioVerifyApi = twilioVerifyApi;
|
|
1236
|
+
}
|
|
1237
|
+
_create_class$2(TwilioVerifyService, [
|
|
1238
|
+
{
|
|
1239
|
+
key: "twilioVerifyApi",
|
|
1240
|
+
get: function get() {
|
|
1241
|
+
return this._twilioVerifyApi;
|
|
1242
|
+
}
|
|
1243
|
+
},
|
|
1244
|
+
{
|
|
1245
|
+
key: "startVerification",
|
|
1246
|
+
value: /**
|
|
1247
|
+
* Starts a verification for the given recipient. Twilio generates and dispatches the code.
|
|
1248
|
+
*
|
|
1249
|
+
* @param input - Recipient, optional channel override, optional locale and customCode.
|
|
1250
|
+
* @returns The Twilio verification record (status, channel, SID).
|
|
1251
|
+
*/ function startVerification(input) {
|
|
1252
|
+
return _async_to_generator$2(function() {
|
|
1253
|
+
var _ref, _input_channel, channel, verification, result;
|
|
1254
|
+
return _ts_generator$2(this, function(_state) {
|
|
1255
|
+
switch(_state.label){
|
|
1256
|
+
case 0:
|
|
1257
|
+
channel = (_ref = (_input_channel = input.channel) !== null && _input_channel !== void 0 ? _input_channel : this._twilioVerifyApi.config.twilioVerify.defaultChannel) !== null && _ref !== void 0 ? _ref : 'sms';
|
|
1258
|
+
return [
|
|
1259
|
+
4,
|
|
1260
|
+
this._twilioVerifyApi.verifyService.verifications.create(_object_spread$1({
|
|
1261
|
+
to: input.to,
|
|
1262
|
+
channel: channel
|
|
1263
|
+
}, input.locale ? {
|
|
1264
|
+
locale: input.locale
|
|
1265
|
+
} : {}, input.customCode ? {
|
|
1266
|
+
customCode: input.customCode
|
|
1267
|
+
} : {}))
|
|
1268
|
+
];
|
|
1269
|
+
case 1:
|
|
1270
|
+
verification = _state.sent();
|
|
1271
|
+
result = {
|
|
1272
|
+
sid: verification.sid,
|
|
1273
|
+
to: verification.to,
|
|
1274
|
+
channel: verification.channel,
|
|
1275
|
+
status: verification.status,
|
|
1276
|
+
valid: verification.valid
|
|
1277
|
+
};
|
|
1278
|
+
return [
|
|
1279
|
+
2,
|
|
1280
|
+
result
|
|
1281
|
+
];
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
}).call(this);
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
{
|
|
1288
|
+
key: "checkVerification",
|
|
1289
|
+
value: /**
|
|
1290
|
+
* Checks a previously-issued verification code.
|
|
1291
|
+
*
|
|
1292
|
+
* Returns `valid: true` only when Twilio reports the verification as `approved`.
|
|
1293
|
+
*
|
|
1294
|
+
* @param input - Recipient address and the submitted code.
|
|
1295
|
+
* @returns The verification-check result, with `valid` reflecting Twilio's `approved` status.
|
|
1296
|
+
*/ function checkVerification(input) {
|
|
1297
|
+
return _async_to_generator$2(function() {
|
|
1298
|
+
var check, status, result;
|
|
1299
|
+
return _ts_generator$2(this, function(_state) {
|
|
1300
|
+
switch(_state.label){
|
|
1301
|
+
case 0:
|
|
1302
|
+
return [
|
|
1303
|
+
4,
|
|
1304
|
+
this._twilioVerifyApi.verifyService.verificationChecks.create({
|
|
1305
|
+
to: input.to,
|
|
1306
|
+
code: input.code
|
|
1307
|
+
})
|
|
1308
|
+
];
|
|
1309
|
+
case 1:
|
|
1310
|
+
check = _state.sent();
|
|
1311
|
+
status = check.status;
|
|
1312
|
+
result = {
|
|
1313
|
+
sid: check.sid,
|
|
1314
|
+
to: check.to,
|
|
1315
|
+
status: status,
|
|
1316
|
+
valid: status === 'approved'
|
|
1317
|
+
};
|
|
1318
|
+
return [
|
|
1319
|
+
2,
|
|
1320
|
+
result
|
|
1321
|
+
];
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
}).call(this);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
]);
|
|
1328
|
+
return TwilioVerifyService;
|
|
1329
|
+
}();
|
|
1330
|
+
TwilioVerifyService = __decorate([
|
|
1331
|
+
Injectable(),
|
|
1332
|
+
__param(0, Inject(TwilioVerifyApi))
|
|
1333
|
+
], TwilioVerifyService);
|
|
1334
|
+
|
|
1335
|
+
function _class_call_check$4(instance, Constructor) {
|
|
1336
|
+
if (!(instance instanceof Constructor)) {
|
|
1337
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Factory that creates a {@link TwilioVerifyServiceConfig} from environment variables.
|
|
1342
|
+
*
|
|
1343
|
+
* @param configService - NestJS config service for reading environment variables.
|
|
1344
|
+
* @returns A validated {@link TwilioVerifyServiceConfig}.
|
|
1345
|
+
*/ function twilioVerifyServiceConfigFactory(configService) {
|
|
1346
|
+
var config = {
|
|
1347
|
+
twilioVerify: {
|
|
1348
|
+
verifyServiceSid: configService.get(TWILIO_VERIFY_SERVICE_SID_ENV_VAR)
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
TwilioVerifyServiceConfig.assertValidConfig(config);
|
|
1352
|
+
return config;
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* NestJS module that exposes Twilio Verify (OTP / 2FA) for starting verifications and
|
|
1356
|
+
* checking submitted codes.
|
|
1357
|
+
*
|
|
1358
|
+
* Imports {@link TwilioModule} for the underlying Twilio client.
|
|
1359
|
+
*/ var TwilioVerifyModule = function TwilioVerifyModule() {
|
|
1360
|
+
_class_call_check$4(this, TwilioVerifyModule);
|
|
1361
|
+
};
|
|
1362
|
+
TwilioVerifyModule = __decorate([
|
|
1363
|
+
Module({
|
|
1364
|
+
imports: [
|
|
1365
|
+
ConfigModule,
|
|
1366
|
+
TwilioModule
|
|
1367
|
+
],
|
|
1368
|
+
providers: [
|
|
1369
|
+
{
|
|
1370
|
+
provide: TwilioVerifyServiceConfig,
|
|
1371
|
+
inject: [
|
|
1372
|
+
ConfigService
|
|
1373
|
+
],
|
|
1374
|
+
useFactory: twilioVerifyServiceConfigFactory
|
|
1375
|
+
},
|
|
1376
|
+
TwilioVerifyApi,
|
|
1377
|
+
TwilioVerifyService
|
|
1378
|
+
],
|
|
1379
|
+
exports: [
|
|
1380
|
+
TwilioVerifyApi,
|
|
1381
|
+
TwilioVerifyService
|
|
1382
|
+
]
|
|
1383
|
+
})
|
|
1384
|
+
], TwilioVerifyModule);
|
|
1385
|
+
|
|
1386
|
+
function _define_property$3(obj, key, value) {
|
|
1387
|
+
if (key in obj) {
|
|
1388
|
+
Object.defineProperty(obj, key, {
|
|
1389
|
+
value: value,
|
|
1390
|
+
enumerable: true,
|
|
1391
|
+
configurable: true,
|
|
1392
|
+
writable: true
|
|
1393
|
+
});
|
|
1394
|
+
} else {
|
|
1395
|
+
obj[key] = value;
|
|
1396
|
+
}
|
|
1397
|
+
return obj;
|
|
1398
|
+
}
|
|
1399
|
+
function _object_spread(target) {
|
|
1400
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1401
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
1402
|
+
var ownKeys = Object.keys(source);
|
|
1403
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
1404
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
1405
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
1406
|
+
}));
|
|
1407
|
+
}
|
|
1408
|
+
ownKeys.forEach(function(key) {
|
|
1409
|
+
_define_property$3(target, key, source[key]);
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
return target;
|
|
1413
|
+
}
|
|
1414
|
+
function ownKeys(object, enumerableOnly) {
|
|
1415
|
+
var keys = Object.keys(object);
|
|
1416
|
+
if (Object.getOwnPropertySymbols) {
|
|
1417
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
1418
|
+
keys.push.apply(keys, symbols);
|
|
1419
|
+
}
|
|
1420
|
+
return keys;
|
|
1421
|
+
}
|
|
1422
|
+
function _object_spread_props(target, source) {
|
|
1423
|
+
source = source != null ? source : {};
|
|
1424
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
1425
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
1426
|
+
} else {
|
|
1427
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
1428
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
return target;
|
|
1432
|
+
}
|
|
1433
|
+
var twilioWebhookEventHandlerFactory = handlerFactory(function(x) {
|
|
1434
|
+
return x.type;
|
|
1435
|
+
});
|
|
1436
|
+
var twilioWebhookEventHandlerConfigurerFactory = handlerConfigurerFactory({
|
|
1437
|
+
configurerForAccessor: function configurerForAccessor(accessor) {
|
|
1438
|
+
// The `any` generics mirror the loose typing used by `openai`/`stripe` webhook configurers:
|
|
1439
|
+
// each `handle*` field is typed for a specific event subtype, but the underlying handler
|
|
1440
|
+
// set is keyed on the union type. The `any` widens the input position so the assignments
|
|
1441
|
+
// below type-check without per-field unsafe casts.
|
|
1442
|
+
var fnWithKey = handlerMappedSetFunctionFactory(accessor, function(x) {
|
|
1443
|
+
return x;
|
|
1444
|
+
});
|
|
1445
|
+
var configurer = _object_spread_props(_object_spread({}, accessor), {
|
|
1446
|
+
handleStatusCallback: fnWithKey('status'),
|
|
1447
|
+
handleIncomingMessage: fnWithKey('incoming')
|
|
1448
|
+
});
|
|
1449
|
+
return configurer;
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
function _class_call_check$3(instance, Constructor) {
|
|
1454
|
+
if (!(instance instanceof Constructor)) {
|
|
1455
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
function _define_property$2(obj, key, value) {
|
|
1459
|
+
if (key in obj) {
|
|
1460
|
+
Object.defineProperty(obj, key, {
|
|
1461
|
+
value: value,
|
|
1462
|
+
enumerable: true,
|
|
1463
|
+
configurable: true,
|
|
1464
|
+
writable: true
|
|
1465
|
+
});
|
|
1466
|
+
} else {
|
|
1467
|
+
obj[key] = value;
|
|
1468
|
+
}
|
|
1469
|
+
return obj;
|
|
1470
|
+
}
|
|
1471
|
+
var TWILIO_WEBHOOK_AUTH_TOKEN_ENV_VAR = 'TWILIO_WEBHOOK_AUTH_TOKEN';
|
|
1472
|
+
var TWILIO_WEBHOOK_BASE_URL_ENV_VAR = 'TWILIO_WEBHOOK_BASE_URL';
|
|
1473
|
+
var TWILIO_WEBHOOK_SKIP_VERIFY_ENV_VAR = 'TWILIO_WEBHOOK_SKIP_VERIFY';
|
|
1474
|
+
/**
|
|
1475
|
+
* Configuration for the Twilio webhook controller / service.
|
|
1476
|
+
*/ var TwilioWebhookServiceConfig = function TwilioWebhookServiceConfig() {
|
|
1477
|
+
_class_call_check$3(this, TwilioWebhookServiceConfig);
|
|
1478
|
+
_define_property$2(this, "twilioWebhook", void 0);
|
|
1479
|
+
}
|
|
1480
|
+
;
|
|
1481
|
+
|
|
1482
|
+
/**
|
|
1483
|
+
* Parses a `application/x-www-form-urlencoded` raw body into a plain `Record<string, string>`.
|
|
1484
|
+
*
|
|
1485
|
+
* Twilio's status callback and incoming-message webhooks use this content type by default.
|
|
1486
|
+
*
|
|
1487
|
+
* @param rawBody - The unparsed request body bytes.
|
|
1488
|
+
* @returns Form parameters as a flat string-keyed object.
|
|
1489
|
+
*/ function parseTwilioFormBody(rawBody) {
|
|
1490
|
+
var params = new URLSearchParams(rawBody.toString('utf8'));
|
|
1491
|
+
var out = {};
|
|
1492
|
+
params.forEach(function(value, key) {
|
|
1493
|
+
out[key] = value;
|
|
1494
|
+
});
|
|
1495
|
+
return out;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Builds the full URL Twilio used when computing the request signature. Twilio computes
|
|
1499
|
+
* the signature over the URL it called (including query string).
|
|
1500
|
+
*
|
|
1501
|
+
* @param req - Incoming Express request.
|
|
1502
|
+
* @param baseUrl - Optional explicit base URL (used when the server sits behind a proxy
|
|
1503
|
+
* and the request's `Host` header does not match the public URL).
|
|
1504
|
+
* @returns The full URL string Twilio would have signed.
|
|
1505
|
+
*/ function twilioWebhookRequestUrl(req, baseUrl) {
|
|
1506
|
+
var url;
|
|
1507
|
+
if (baseUrl) {
|
|
1508
|
+
var _req_originalUrl;
|
|
1509
|
+
var trimmed = baseUrl.replace(/\/$/, '');
|
|
1510
|
+
url = "".concat(trimmed).concat((_req_originalUrl = req.originalUrl) !== null && _req_originalUrl !== void 0 ? _req_originalUrl : req.url);
|
|
1511
|
+
} else {
|
|
1512
|
+
var _req_headers_xforwardedproto, _req_headers_xforwardedhost, _req_originalUrl1;
|
|
1513
|
+
var protocol = (_req_headers_xforwardedproto = req.headers['x-forwarded-proto']) !== null && _req_headers_xforwardedproto !== void 0 ? _req_headers_xforwardedproto : req.protocol;
|
|
1514
|
+
var host = (_req_headers_xforwardedhost = req.headers['x-forwarded-host']) !== null && _req_headers_xforwardedhost !== void 0 ? _req_headers_xforwardedhost : req.get('host');
|
|
1515
|
+
url = "".concat(protocol, "://").concat(host).concat((_req_originalUrl1 = req.originalUrl) !== null && _req_originalUrl1 !== void 0 ? _req_originalUrl1 : req.url);
|
|
1516
|
+
}
|
|
1517
|
+
return url;
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Creates a verifier that validates the `X-Twilio-Signature` header against the request body
|
|
1521
|
+
* using Twilio's HMAC-SHA1 signature scheme.
|
|
1522
|
+
*
|
|
1523
|
+
* @param config - Verification config (auth token, optional baseUrl, optional skip flag).
|
|
1524
|
+
* @returns A verifier function that, given a request and raw body, returns the validity
|
|
1525
|
+
* and parsed form params.
|
|
1526
|
+
*/ function twilioWebhookVerifier(config) {
|
|
1527
|
+
return function(req, rawBody) {
|
|
1528
|
+
var params = parseTwilioFormBody(rawBody);
|
|
1529
|
+
var valid;
|
|
1530
|
+
if (config.skip === true) {
|
|
1531
|
+
valid = true;
|
|
1532
|
+
} else {
|
|
1533
|
+
var _req_headers_xtwiliosignature;
|
|
1534
|
+
var signature = (_req_headers_xtwiliosignature = req.headers['x-twilio-signature']) !== null && _req_headers_xtwiliosignature !== void 0 ? _req_headers_xtwiliosignature : '';
|
|
1535
|
+
var url = twilioWebhookRequestUrl(req, config.baseUrl);
|
|
1536
|
+
valid = validateRequest(config.authToken, signature, url, params);
|
|
1537
|
+
}
|
|
1538
|
+
var result = {
|
|
1539
|
+
valid: valid,
|
|
1540
|
+
params: params
|
|
1541
|
+
};
|
|
1542
|
+
return result;
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1547
|
+
try {
|
|
1548
|
+
var info = gen[key](arg);
|
|
1549
|
+
var value = info.value;
|
|
1550
|
+
} catch (error) {
|
|
1551
|
+
reject(error);
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
if (info.done) {
|
|
1555
|
+
resolve(value);
|
|
1556
|
+
} else {
|
|
1557
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
function _async_to_generator$1(fn) {
|
|
1561
|
+
return function() {
|
|
1562
|
+
var self = this, args = arguments;
|
|
1563
|
+
return new Promise(function(resolve, reject) {
|
|
1564
|
+
var gen = fn.apply(self, args);
|
|
1565
|
+
function _next(value) {
|
|
1566
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
1567
|
+
}
|
|
1568
|
+
function _throw(err) {
|
|
1569
|
+
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1570
|
+
}
|
|
1571
|
+
_next(undefined);
|
|
1572
|
+
});
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
function _class_call_check$2(instance, Constructor) {
|
|
1576
|
+
if (!(instance instanceof Constructor)) {
|
|
1577
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
function _defineProperties$1(target, props) {
|
|
1581
|
+
for(var i = 0; i < props.length; i++){
|
|
1582
|
+
var descriptor = props[i];
|
|
1583
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1584
|
+
descriptor.configurable = true;
|
|
1585
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1586
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
function _create_class$1(Constructor, protoProps, staticProps) {
|
|
1590
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
1591
|
+
return Constructor;
|
|
1592
|
+
}
|
|
1593
|
+
function _define_property$1(obj, key, value) {
|
|
1594
|
+
if (key in obj) {
|
|
1595
|
+
Object.defineProperty(obj, key, {
|
|
1596
|
+
value: value,
|
|
1597
|
+
enumerable: true,
|
|
1598
|
+
configurable: true,
|
|
1599
|
+
writable: true
|
|
1600
|
+
});
|
|
1601
|
+
} else {
|
|
1602
|
+
obj[key] = value;
|
|
1603
|
+
}
|
|
1604
|
+
return obj;
|
|
1605
|
+
}
|
|
1606
|
+
function _ts_generator$1(thisArg, body) {
|
|
1607
|
+
var f, y, t, _ = {
|
|
1608
|
+
label: 0,
|
|
1609
|
+
sent: function() {
|
|
1610
|
+
if (t[0] & 1) throw t[1];
|
|
1611
|
+
return t[1];
|
|
1612
|
+
},
|
|
1613
|
+
trys: [],
|
|
1614
|
+
ops: []
|
|
1615
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1616
|
+
return d(g, "next", {
|
|
1617
|
+
value: verb(0)
|
|
1618
|
+
}), d(g, "throw", {
|
|
1619
|
+
value: verb(1)
|
|
1620
|
+
}), d(g, "return", {
|
|
1621
|
+
value: verb(2)
|
|
1622
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1623
|
+
value: function() {
|
|
1624
|
+
return this;
|
|
1625
|
+
}
|
|
1626
|
+
}), g;
|
|
1627
|
+
function verb(n) {
|
|
1628
|
+
return function(v) {
|
|
1629
|
+
return step([
|
|
1630
|
+
n,
|
|
1631
|
+
v
|
|
1632
|
+
]);
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
function step(op) {
|
|
1636
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1637
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1638
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1639
|
+
if (y = 0, t) op = [
|
|
1640
|
+
op[0] & 2,
|
|
1641
|
+
t.value
|
|
1642
|
+
];
|
|
1643
|
+
switch(op[0]){
|
|
1644
|
+
case 0:
|
|
1645
|
+
case 1:
|
|
1646
|
+
t = op;
|
|
1647
|
+
break;
|
|
1648
|
+
case 4:
|
|
1649
|
+
_.label++;
|
|
1650
|
+
return {
|
|
1651
|
+
value: op[1],
|
|
1652
|
+
done: false
|
|
1653
|
+
};
|
|
1654
|
+
case 5:
|
|
1655
|
+
_.label++;
|
|
1656
|
+
y = op[1];
|
|
1657
|
+
op = [
|
|
1658
|
+
0
|
|
1659
|
+
];
|
|
1660
|
+
continue;
|
|
1661
|
+
case 7:
|
|
1662
|
+
op = _.ops.pop();
|
|
1663
|
+
_.trys.pop();
|
|
1664
|
+
continue;
|
|
1665
|
+
default:
|
|
1666
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1667
|
+
_ = 0;
|
|
1668
|
+
continue;
|
|
1669
|
+
}
|
|
1670
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1671
|
+
_.label = op[1];
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1675
|
+
_.label = t[1];
|
|
1676
|
+
t = op;
|
|
1677
|
+
break;
|
|
1678
|
+
}
|
|
1679
|
+
if (t && _.label < t[2]) {
|
|
1680
|
+
_.label = t[2];
|
|
1681
|
+
_.ops.push(op);
|
|
1682
|
+
break;
|
|
1683
|
+
}
|
|
1684
|
+
if (t[2]) _.ops.pop();
|
|
1685
|
+
_.trys.pop();
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
op = body.call(thisArg, _);
|
|
1689
|
+
} catch (e) {
|
|
1690
|
+
op = [
|
|
1691
|
+
6,
|
|
1692
|
+
e
|
|
1693
|
+
];
|
|
1694
|
+
y = 0;
|
|
1695
|
+
} finally{
|
|
1696
|
+
f = t = 0;
|
|
1697
|
+
}
|
|
1698
|
+
if (op[0] & 5) throw op[1];
|
|
1699
|
+
return {
|
|
1700
|
+
value: op[0] ? op[1] : void 0,
|
|
1701
|
+
done: true
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
var TwilioWebhookService = /*#__PURE__*/ function() {
|
|
1706
|
+
function TwilioWebhookService(twilioApi, webhookConfig) {
|
|
1707
|
+
_class_call_check$2(this, TwilioWebhookService);
|
|
1708
|
+
var _webhookConfig_twilioWebhook_authToken;
|
|
1709
|
+
_define_property$1(this, "logger", new Logger('TwilioWebhookService'));
|
|
1710
|
+
_define_property$1(this, "_verifier", void 0);
|
|
1711
|
+
_define_property$1(this, "handler", twilioWebhookEventHandlerFactory());
|
|
1712
|
+
_define_property$1(this, "configure", twilioWebhookEventHandlerConfigurerFactory(this.handler));
|
|
1713
|
+
var authToken = (_webhookConfig_twilioWebhook_authToken = webhookConfig.twilioWebhook.authToken) !== null && _webhookConfig_twilioWebhook_authToken !== void 0 ? _webhookConfig_twilioWebhook_authToken : twilioApi.config.twilio.authToken;
|
|
1714
|
+
if (!authToken) {
|
|
1715
|
+
throw new Error('TwilioWebhookService: authToken is required (set TWILIO_AUTH_TOKEN or TWILIO_WEBHOOK_AUTH_TOKEN).');
|
|
1716
|
+
}
|
|
1717
|
+
this._verifier = twilioWebhookVerifier({
|
|
1718
|
+
authToken: authToken,
|
|
1719
|
+
baseUrl: webhookConfig.twilioWebhook.baseUrl,
|
|
1720
|
+
skip: webhookConfig.twilioWebhook.skipVerify
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
_create_class$1(TwilioWebhookService, [
|
|
1724
|
+
{
|
|
1725
|
+
key: "handleStatusCallback",
|
|
1726
|
+
value: function handleStatusCallback(req, rawBody) {
|
|
1727
|
+
return _async_to_generator$1(function() {
|
|
1728
|
+
var _this__verifier, valid, params, _params_AccountSid, event;
|
|
1729
|
+
return _ts_generator$1(this, function(_state) {
|
|
1730
|
+
switch(_state.label){
|
|
1731
|
+
case 0:
|
|
1732
|
+
_this__verifier = this._verifier(req, rawBody), valid = _this__verifier.valid, params = _this__verifier.params;
|
|
1733
|
+
if (!!valid) return [
|
|
1734
|
+
3,
|
|
1735
|
+
1
|
|
1736
|
+
];
|
|
1737
|
+
this.logger.warn('Received Twilio status callback with invalid signature.');
|
|
1738
|
+
return [
|
|
1739
|
+
3,
|
|
1740
|
+
3
|
|
1741
|
+
];
|
|
1742
|
+
case 1:
|
|
1743
|
+
event = {
|
|
1744
|
+
type: 'status',
|
|
1745
|
+
payload: {
|
|
1746
|
+
MessageSid: params['MessageSid'],
|
|
1747
|
+
MessageStatus: params['MessageStatus'],
|
|
1748
|
+
AccountSid: (_params_AccountSid = params['AccountSid']) !== null && _params_AccountSid !== void 0 ? _params_AccountSid : '',
|
|
1749
|
+
From: params['From'],
|
|
1750
|
+
To: params['To'],
|
|
1751
|
+
ApiVersion: params['ApiVersion'],
|
|
1752
|
+
ErrorCode: params['ErrorCode'],
|
|
1753
|
+
ErrorMessage: params['ErrorMessage'],
|
|
1754
|
+
raw: params
|
|
1755
|
+
}
|
|
1756
|
+
};
|
|
1757
|
+
return [
|
|
1758
|
+
4,
|
|
1759
|
+
this.dispatchEvent(event)
|
|
1760
|
+
];
|
|
1761
|
+
case 2:
|
|
1762
|
+
_state.sent();
|
|
1763
|
+
_state.label = 3;
|
|
1764
|
+
case 3:
|
|
1765
|
+
return [
|
|
1766
|
+
2
|
|
1767
|
+
];
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
}).call(this);
|
|
1771
|
+
}
|
|
1772
|
+
},
|
|
1773
|
+
{
|
|
1774
|
+
key: "handleIncomingMessage",
|
|
1775
|
+
value: function handleIncomingMessage(req, rawBody) {
|
|
1776
|
+
return _async_to_generator$1(function() {
|
|
1777
|
+
var _this__verifier, valid, params, _params_NumMedia, _params_AccountSid, _params_Body, numMedia, numSegments, mediaUrls, i, url, event;
|
|
1778
|
+
return _ts_generator$1(this, function(_state) {
|
|
1779
|
+
switch(_state.label){
|
|
1780
|
+
case 0:
|
|
1781
|
+
_this__verifier = this._verifier(req, rawBody), valid = _this__verifier.valid, params = _this__verifier.params;
|
|
1782
|
+
if (!!valid) return [
|
|
1783
|
+
3,
|
|
1784
|
+
1
|
|
1785
|
+
];
|
|
1786
|
+
this.logger.warn('Received Twilio incoming message with invalid signature.');
|
|
1787
|
+
return [
|
|
1788
|
+
3,
|
|
1789
|
+
3
|
|
1790
|
+
];
|
|
1791
|
+
case 1:
|
|
1792
|
+
numMedia = Number((_params_NumMedia = params['NumMedia']) !== null && _params_NumMedia !== void 0 ? _params_NumMedia : '0');
|
|
1793
|
+
numSegments = params['NumSegments'] !== undefined ? Number(params['NumSegments']) : undefined;
|
|
1794
|
+
mediaUrls = [];
|
|
1795
|
+
for(i = 0; i < numMedia; i++){
|
|
1796
|
+
url = params["MediaUrl".concat(i)];
|
|
1797
|
+
if (url) {
|
|
1798
|
+
mediaUrls.push(url);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
event = {
|
|
1802
|
+
type: 'incoming',
|
|
1803
|
+
payload: {
|
|
1804
|
+
MessageSid: params['MessageSid'],
|
|
1805
|
+
AccountSid: (_params_AccountSid = params['AccountSid']) !== null && _params_AccountSid !== void 0 ? _params_AccountSid : '',
|
|
1806
|
+
From: params['From'],
|
|
1807
|
+
To: params['To'],
|
|
1808
|
+
Body: (_params_Body = params['Body']) !== null && _params_Body !== void 0 ? _params_Body : '',
|
|
1809
|
+
NumMedia: numMedia,
|
|
1810
|
+
NumSegments: numSegments,
|
|
1811
|
+
FromCity: params['FromCity'],
|
|
1812
|
+
FromState: params['FromState'],
|
|
1813
|
+
FromZip: params['FromZip'],
|
|
1814
|
+
FromCountry: params['FromCountry'],
|
|
1815
|
+
mediaUrls: mediaUrls,
|
|
1816
|
+
raw: params
|
|
1817
|
+
}
|
|
1818
|
+
};
|
|
1819
|
+
return [
|
|
1820
|
+
4,
|
|
1821
|
+
this.dispatchEvent(event)
|
|
1822
|
+
];
|
|
1823
|
+
case 2:
|
|
1824
|
+
_state.sent();
|
|
1825
|
+
_state.label = 3;
|
|
1826
|
+
case 3:
|
|
1827
|
+
return [
|
|
1828
|
+
2
|
|
1829
|
+
];
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
}).call(this);
|
|
1833
|
+
}
|
|
1834
|
+
},
|
|
1835
|
+
{
|
|
1836
|
+
key: "dispatchEvent",
|
|
1837
|
+
value: function dispatchEvent(event) {
|
|
1838
|
+
return _async_to_generator$1(function() {
|
|
1839
|
+
var handled;
|
|
1840
|
+
return _ts_generator$1(this, function(_state) {
|
|
1841
|
+
switch(_state.label){
|
|
1842
|
+
case 0:
|
|
1843
|
+
return [
|
|
1844
|
+
4,
|
|
1845
|
+
this.handler(event)
|
|
1846
|
+
];
|
|
1847
|
+
case 1:
|
|
1848
|
+
handled = _state.sent();
|
|
1849
|
+
if (!handled) {
|
|
1850
|
+
this.logger.debug('Received unhandled Twilio webhook event of type "'.concat(event.type, '".'));
|
|
1851
|
+
}
|
|
1852
|
+
return [
|
|
1853
|
+
2
|
|
1854
|
+
];
|
|
1855
|
+
}
|
|
1856
|
+
});
|
|
1857
|
+
}).call(this);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
]);
|
|
1861
|
+
return TwilioWebhookService;
|
|
1862
|
+
}();
|
|
1863
|
+
TwilioWebhookService = __decorate([
|
|
1864
|
+
Injectable(),
|
|
1865
|
+
__param(0, Inject(TwilioApi)),
|
|
1866
|
+
__param(1, Inject(TwilioWebhookServiceConfig))
|
|
1867
|
+
], TwilioWebhookService);
|
|
1868
|
+
|
|
1869
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
1870
|
+
try {
|
|
1871
|
+
var info = gen[key](arg);
|
|
1872
|
+
var value = info.value;
|
|
1873
|
+
} catch (error) {
|
|
1874
|
+
reject(error);
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
if (info.done) {
|
|
1878
|
+
resolve(value);
|
|
1879
|
+
} else {
|
|
1880
|
+
Promise.resolve(value).then(_next, _throw);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
function _async_to_generator(fn) {
|
|
1884
|
+
return function() {
|
|
1885
|
+
var self = this, args = arguments;
|
|
1886
|
+
return new Promise(function(resolve, reject) {
|
|
1887
|
+
var gen = fn.apply(self, args);
|
|
1888
|
+
function _next(value) {
|
|
1889
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
1890
|
+
}
|
|
1891
|
+
function _throw(err) {
|
|
1892
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
1893
|
+
}
|
|
1894
|
+
_next(undefined);
|
|
1895
|
+
});
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
function _class_call_check$1(instance, Constructor) {
|
|
1899
|
+
if (!(instance instanceof Constructor)) {
|
|
1900
|
+
throw new TypeError("Cannot call a class as a function");
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
function _defineProperties(target, props) {
|
|
1904
|
+
for(var i = 0; i < props.length; i++){
|
|
1905
|
+
var descriptor = props[i];
|
|
1906
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
1907
|
+
descriptor.configurable = true;
|
|
1908
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
1909
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
1913
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
1914
|
+
return Constructor;
|
|
1915
|
+
}
|
|
1916
|
+
function _define_property(obj, key, value) {
|
|
1917
|
+
if (key in obj) {
|
|
1918
|
+
Object.defineProperty(obj, key, {
|
|
1919
|
+
value: value,
|
|
1920
|
+
enumerable: true,
|
|
1921
|
+
configurable: true,
|
|
1922
|
+
writable: true
|
|
1923
|
+
});
|
|
1924
|
+
} else {
|
|
1925
|
+
obj[key] = value;
|
|
1926
|
+
}
|
|
1927
|
+
return obj;
|
|
1928
|
+
}
|
|
1929
|
+
function _ts_generator(thisArg, body) {
|
|
1930
|
+
var f, y, t, _ = {
|
|
1931
|
+
label: 0,
|
|
1932
|
+
sent: function() {
|
|
1933
|
+
if (t[0] & 1) throw t[1];
|
|
1934
|
+
return t[1];
|
|
1935
|
+
},
|
|
1936
|
+
trys: [],
|
|
1937
|
+
ops: []
|
|
1938
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
1939
|
+
return d(g, "next", {
|
|
1940
|
+
value: verb(0)
|
|
1941
|
+
}), d(g, "throw", {
|
|
1942
|
+
value: verb(1)
|
|
1943
|
+
}), d(g, "return", {
|
|
1944
|
+
value: verb(2)
|
|
1945
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
1946
|
+
value: function() {
|
|
1947
|
+
return this;
|
|
1948
|
+
}
|
|
1949
|
+
}), g;
|
|
1950
|
+
function verb(n) {
|
|
1951
|
+
return function(v) {
|
|
1952
|
+
return step([
|
|
1953
|
+
n,
|
|
1954
|
+
v
|
|
1955
|
+
]);
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
function step(op) {
|
|
1959
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
1960
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
1961
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1962
|
+
if (y = 0, t) op = [
|
|
1963
|
+
op[0] & 2,
|
|
1964
|
+
t.value
|
|
1965
|
+
];
|
|
1966
|
+
switch(op[0]){
|
|
1967
|
+
case 0:
|
|
1968
|
+
case 1:
|
|
1969
|
+
t = op;
|
|
1970
|
+
break;
|
|
1971
|
+
case 4:
|
|
1972
|
+
_.label++;
|
|
1973
|
+
return {
|
|
1974
|
+
value: op[1],
|
|
1975
|
+
done: false
|
|
1976
|
+
};
|
|
1977
|
+
case 5:
|
|
1978
|
+
_.label++;
|
|
1979
|
+
y = op[1];
|
|
1980
|
+
op = [
|
|
1981
|
+
0
|
|
1982
|
+
];
|
|
1983
|
+
continue;
|
|
1984
|
+
case 7:
|
|
1985
|
+
op = _.ops.pop();
|
|
1986
|
+
_.trys.pop();
|
|
1987
|
+
continue;
|
|
1988
|
+
default:
|
|
1989
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
1990
|
+
_ = 0;
|
|
1991
|
+
continue;
|
|
1992
|
+
}
|
|
1993
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
1994
|
+
_.label = op[1];
|
|
1995
|
+
break;
|
|
1996
|
+
}
|
|
1997
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
1998
|
+
_.label = t[1];
|
|
1999
|
+
t = op;
|
|
2000
|
+
break;
|
|
2001
|
+
}
|
|
2002
|
+
if (t && _.label < t[2]) {
|
|
2003
|
+
_.label = t[2];
|
|
2004
|
+
_.ops.push(op);
|
|
2005
|
+
break;
|
|
2006
|
+
}
|
|
2007
|
+
if (t[2]) _.ops.pop();
|
|
2008
|
+
_.trys.pop();
|
|
2009
|
+
continue;
|
|
2010
|
+
}
|
|
2011
|
+
op = body.call(thisArg, _);
|
|
2012
|
+
} catch (e) {
|
|
2013
|
+
op = [
|
|
2014
|
+
6,
|
|
2015
|
+
e
|
|
2016
|
+
];
|
|
2017
|
+
y = 0;
|
|
2018
|
+
} finally{
|
|
2019
|
+
f = t = 0;
|
|
2020
|
+
}
|
|
2021
|
+
if (op[0] & 5) throw op[1];
|
|
2022
|
+
return {
|
|
2023
|
+
value: op[0] ? op[1] : void 0,
|
|
2024
|
+
done: true
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
var TwilioWebhookController = /*#__PURE__*/ function() {
|
|
2029
|
+
function TwilioWebhookController(twilioWebhookService) {
|
|
2030
|
+
_class_call_check$1(this, TwilioWebhookController);
|
|
2031
|
+
_define_property(this, "_twilioWebhookService", void 0);
|
|
2032
|
+
this._twilioWebhookService = twilioWebhookService;
|
|
2033
|
+
}
|
|
2034
|
+
_create_class(TwilioWebhookController, [
|
|
2035
|
+
{
|
|
2036
|
+
key: "handleStatus",
|
|
2037
|
+
value: function handleStatus(req, rawBody) {
|
|
2038
|
+
return _async_to_generator(function() {
|
|
2039
|
+
return _ts_generator(this, function(_state) {
|
|
2040
|
+
switch(_state.label){
|
|
2041
|
+
case 0:
|
|
2042
|
+
if (!rawBody) {
|
|
2043
|
+
throw new ForbiddenException('Missing request body.');
|
|
2044
|
+
}
|
|
2045
|
+
return [
|
|
2046
|
+
4,
|
|
2047
|
+
this._twilioWebhookService.handleStatusCallback(req, rawBody)
|
|
2048
|
+
];
|
|
2049
|
+
case 1:
|
|
2050
|
+
_state.sent();
|
|
2051
|
+
return [
|
|
2052
|
+
2
|
|
2053
|
+
];
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
}).call(this);
|
|
2057
|
+
}
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
key: "handleIncoming",
|
|
2061
|
+
value: function handleIncoming(req, rawBody) {
|
|
2062
|
+
return _async_to_generator(function() {
|
|
2063
|
+
return _ts_generator(this, function(_state) {
|
|
2064
|
+
switch(_state.label){
|
|
2065
|
+
case 0:
|
|
2066
|
+
if (!rawBody) {
|
|
2067
|
+
throw new ForbiddenException('Missing request body.');
|
|
2068
|
+
}
|
|
2069
|
+
return [
|
|
2070
|
+
4,
|
|
2071
|
+
this._twilioWebhookService.handleIncomingMessage(req, rawBody)
|
|
2072
|
+
];
|
|
2073
|
+
case 1:
|
|
2074
|
+
_state.sent();
|
|
2075
|
+
return [
|
|
2076
|
+
2
|
|
2077
|
+
];
|
|
2078
|
+
}
|
|
2079
|
+
});
|
|
2080
|
+
}).call(this);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
]);
|
|
2084
|
+
return TwilioWebhookController;
|
|
2085
|
+
}();
|
|
2086
|
+
__decorate([
|
|
2087
|
+
Post('status'),
|
|
2088
|
+
__param(0, Req()),
|
|
2089
|
+
__param(1, RawBody())
|
|
2090
|
+
], TwilioWebhookController.prototype, "handleStatus", null);
|
|
2091
|
+
__decorate([
|
|
2092
|
+
Post('incoming'),
|
|
2093
|
+
__param(0, Req()),
|
|
2094
|
+
__param(1, RawBody())
|
|
2095
|
+
], TwilioWebhookController.prototype, "handleIncoming", null);
|
|
2096
|
+
TwilioWebhookController = __decorate([
|
|
2097
|
+
Controller('/webhook/twilio'),
|
|
2098
|
+
__param(0, Inject(TwilioWebhookService))
|
|
2099
|
+
], TwilioWebhookController);
|
|
2100
|
+
|
|
2101
|
+
function _class_call_check(instance, Constructor) {
|
|
2102
|
+
if (!(instance instanceof Constructor)) {
|
|
2103
|
+
throw new TypeError("Cannot call a class as a function");
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Factory that creates a {@link TwilioWebhookServiceConfig} from environment variables.
|
|
2108
|
+
*
|
|
2109
|
+
* @param configService - NestJS config service for reading environment variables.
|
|
2110
|
+
* @returns A populated {@link TwilioWebhookServiceConfig}.
|
|
2111
|
+
*/ function twilioWebhookServiceConfigFactory(configService) {
|
|
2112
|
+
var config = {
|
|
2113
|
+
twilioWebhook: {
|
|
2114
|
+
authToken: configService.get(TWILIO_WEBHOOK_AUTH_TOKEN_ENV_VAR),
|
|
2115
|
+
baseUrl: configService.get(TWILIO_WEBHOOK_BASE_URL_ENV_VAR),
|
|
2116
|
+
skipVerify: configService.get(TWILIO_WEBHOOK_SKIP_VERIFY_ENV_VAR) === 'true'
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
return config;
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* NestJS module that handles incoming Twilio webhook requests at:
|
|
2123
|
+
* - `POST /webhook/twilio/status` (Message status callbacks)
|
|
2124
|
+
* - `POST /webhook/twilio/incoming` (Incoming SMS / MMS messages)
|
|
2125
|
+
*
|
|
2126
|
+
* Webhook bodies are verified against the X-Twilio-Signature header before dispatch.
|
|
2127
|
+
*
|
|
2128
|
+
* Requires the consuming application to register the raw-body middleware from
|
|
2129
|
+
* `@dereekb/nestjs` for the `/webhook/twilio` path so that signature verification can read
|
|
2130
|
+
* the unparsed form body.
|
|
2131
|
+
*/ var TwilioWebhookModule = function TwilioWebhookModule() {
|
|
2132
|
+
_class_call_check(this, TwilioWebhookModule);
|
|
2133
|
+
};
|
|
2134
|
+
TwilioWebhookModule = __decorate([
|
|
2135
|
+
Module({
|
|
2136
|
+
imports: [
|
|
2137
|
+
ConfigModule,
|
|
2138
|
+
TwilioModule
|
|
2139
|
+
],
|
|
2140
|
+
controllers: [
|
|
2141
|
+
TwilioWebhookController
|
|
2142
|
+
],
|
|
2143
|
+
providers: [
|
|
2144
|
+
{
|
|
2145
|
+
provide: TwilioWebhookServiceConfig,
|
|
2146
|
+
inject: [
|
|
2147
|
+
ConfigService
|
|
2148
|
+
],
|
|
2149
|
+
useFactory: twilioWebhookServiceConfigFactory
|
|
2150
|
+
},
|
|
2151
|
+
TwilioWebhookService
|
|
2152
|
+
],
|
|
2153
|
+
exports: [
|
|
2154
|
+
TwilioWebhookService
|
|
2155
|
+
]
|
|
2156
|
+
})
|
|
2157
|
+
], TwilioWebhookModule);
|
|
2158
|
+
|
|
2159
|
+
export { DEFAULT_TWILIO_SEND_SMS_MAX_PARALLEL_TASKS, TWILIO_ACCOUNT_SID_ENV_VAR, TWILIO_API_KEY_SECRET_ENV_VAR, TWILIO_API_KEY_SID_ENV_VAR, TWILIO_AUTH_TOKEN_ENV_VAR, TWILIO_MESSAGING_SERVICE_SID_ENV_VAR, TWILIO_PHONE_NUMBER_ENV_VAR, TWILIO_SANDBOX_ENV_VAR, TWILIO_STATUS_CALLBACK_URL_ENV_VAR, TWILIO_VERIFY_SERVICE_SID_ENV_VAR, TWILIO_WEBHOOK_AUTH_TOKEN_ENV_VAR, TWILIO_WEBHOOK_BASE_URL_ENV_VAR, TWILIO_WEBHOOK_SKIP_VERIFY_ENV_VAR, TwilioApi, TwilioLookupApi, TwilioLookupModule, TwilioLookupService, TwilioModule, TwilioService, TwilioServiceConfig, TwilioVerifyApi, TwilioVerifyModule, TwilioVerifyService, TwilioVerifyServiceConfig, TwilioWebhookController, TwilioWebhookModule, TwilioWebhookService, TwilioWebhookServiceConfig, parseTwilioFormBody, twilioServiceConfigFactory, twilioVerifyServiceConfigFactory, twilioWebhookEventHandlerConfigurerFactory, twilioWebhookEventHandlerFactory, twilioWebhookRequestUrl, twilioWebhookServiceConfigFactory, twilioWebhookVerifier };
|