@terreno/comms 57.2.0 → 57.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +58 -0
  2. package/dist/adapters/expoPush.d.ts +54 -0
  3. package/dist/adapters/expoPush.js +400 -0
  4. package/dist/adapters/sendgrid.d.ts +3 -0
  5. package/dist/adapters/sendgrid.js +7 -1
  6. package/dist/adapters/twilioSms.d.ts +36 -0
  7. package/dist/adapters/twilioSms.js +232 -0
  8. package/dist/adapters/twilioVerify.d.ts +44 -0
  9. package/dist/adapters/twilioVerify.js +212 -0
  10. package/dist/commsApp.d.ts +4 -1
  11. package/dist/commsApp.js +28 -2
  12. package/dist/commsQuery.d.ts +30 -0
  13. package/dist/commsQuery.js +134 -0
  14. package/dist/commsRetry.d.ts +16 -0
  15. package/dist/commsRetry.js +79 -0
  16. package/dist/commsService.d.ts +11 -4
  17. package/dist/commsService.js +217 -47
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +3 -1
  20. package/dist/routes/commsDashboard.d.ts +11 -0
  21. package/dist/routes/commsDashboard.js +414 -0
  22. package/dist/templates.d.ts +9 -0
  23. package/dist/templates.js +34 -1
  24. package/dist/types.d.ts +11 -0
  25. package/dist/webhooks/sendgridWebhooks.d.ts +16 -0
  26. package/dist/webhooks/sendgridWebhooks.js +251 -0
  27. package/dist/webhooks/twilioWebhooks.d.ts +18 -0
  28. package/dist/webhooks/twilioWebhooks.js +175 -0
  29. package/package.json +26 -5
  30. package/src/adapters/expoPush.test.ts +585 -0
  31. package/src/adapters/expoPush.ts +304 -0
  32. package/src/adapters/sendgrid.ts +8 -0
  33. package/src/adapters/twilioSms.test.ts +374 -0
  34. package/src/adapters/twilioSms.ts +237 -0
  35. package/src/adapters/twilioVerify.test.ts +207 -0
  36. package/src/adapters/twilioVerify.ts +227 -0
  37. package/src/commsApp.test.ts +13 -0
  38. package/src/commsApp.ts +38 -3
  39. package/src/commsQuery.test.ts +165 -0
  40. package/src/commsQuery.ts +162 -0
  41. package/src/commsRetry.ts +87 -0
  42. package/src/commsService.test.ts +68 -0
  43. package/src/commsService.ts +177 -20
  44. package/src/index.ts +9 -2
  45. package/src/routes/commsDashboard.test.ts +310 -0
  46. package/src/routes/commsDashboard.ts +327 -0
  47. package/src/templates.test.ts +63 -1
  48. package/src/templates.ts +47 -0
  49. package/src/tests/bunSetup.ts +8 -0
  50. package/src/types.ts +13 -0
  51. package/src/webhooks/sendgridWebhooks.test.ts +520 -0
  52. package/src/webhooks/sendgridWebhooks.ts +166 -0
  53. package/src/webhooks/twilioWebhooks.test.ts +352 -0
  54. package/src/webhooks/twilioWebhooks.ts +154 -0
  55. package/dist/routes/commsExplorer.d.ts +0 -7
  56. package/dist/routes/commsExplorer.js +0 -147
  57. package/src/routes/commsExplorer.ts +0 -114
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.maybeRegisterSendGridCommsWebhooks = exports.registerSendGridCommsWebhooks = void 0;
51
+ var api_1 = require("@terreno/api");
52
+ var sendgrid_1 = require("../adapters/sendgrid");
53
+ var commsMessage_1 = require("../models/commsMessage");
54
+ var eventString = function (value) {
55
+ return typeof value === "string" ? value : "";
56
+ };
57
+ var escapeRegex = function (value) {
58
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
59
+ };
60
+ var storedProviderMessageId = function (sgMessageId) { return __awaiter(void 0, void 0, void 0, function () {
61
+ var prefix, exact, prefixed;
62
+ var _a, _b;
63
+ return __generator(this, function (_c) {
64
+ switch (_c.label) {
65
+ case 0:
66
+ prefix = (_a = sgMessageId.split(".")[0]) !== null && _a !== void 0 ? _a : sgMessageId;
67
+ if (!prefix) {
68
+ return [2 /*return*/, sgMessageId];
69
+ }
70
+ return [4 /*yield*/, commsMessage_1.CommsMessage.findOneOrNone({ providerMessageId: prefix })];
71
+ case 1:
72
+ exact = _c.sent();
73
+ if (exact === null || exact === void 0 ? void 0 : exact.providerMessageId) {
74
+ return [2 /*return*/, exact.providerMessageId];
75
+ }
76
+ return [4 /*yield*/, commsMessage_1.CommsMessage.findOneOrNone({
77
+ providerMessageId: new RegExp("^".concat(escapeRegex(prefix))),
78
+ })];
79
+ case 2:
80
+ prefixed = _c.sent();
81
+ return [2 /*return*/, (_b = prefixed === null || prefixed === void 0 ? void 0 : prefixed.providerMessageId) !== null && _b !== void 0 ? _b : prefix];
82
+ }
83
+ });
84
+ }); };
85
+ var applySendGridEvent = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ var type, providerMessageId, reason, email, isSoft, optOut;
87
+ var event = _b.event, service = _b.service;
88
+ return __generator(this, function (_c) {
89
+ switch (_c.label) {
90
+ case 0:
91
+ type = eventString(event.event);
92
+ return [4 /*yield*/, storedProviderMessageId(eventString(event.sg_message_id))];
93
+ case 1:
94
+ providerMessageId = _c.sent();
95
+ reason = eventString(event.reason);
96
+ email = eventString(event.email);
97
+ if (!(type === "delivered")) return [3 /*break*/, 3];
98
+ return [4 /*yield*/, service.recordDeliveryEvent({
99
+ channel: "mail",
100
+ providerMessageId: providerMessageId,
101
+ raw: event,
102
+ status: "delivered",
103
+ })];
104
+ case 2:
105
+ _c.sent();
106
+ return [2 /*return*/];
107
+ case 3:
108
+ if (!(type === "open")) return [3 /*break*/, 5];
109
+ return [4 /*yield*/, service.recordDeliveryEvent({
110
+ channel: "mail",
111
+ providerMessageId: providerMessageId,
112
+ raw: event,
113
+ status: "opened",
114
+ })];
115
+ case 4:
116
+ _c.sent();
117
+ return [2 /*return*/];
118
+ case 5:
119
+ if (!(type === "bounce")) return [3 /*break*/, 7];
120
+ isSoft = eventString(event.type) === "blocked";
121
+ return [4 /*yield*/, service.recordDeliveryEvent({
122
+ channel: "mail",
123
+ errorClass: isSoft ? "transient" : "permanent",
124
+ errorCode: reason || (isSoft ? "deferred" : "bounce"),
125
+ providerMessageId: providerMessageId,
126
+ raw: event,
127
+ status: "bounced",
128
+ })];
129
+ case 6:
130
+ _c.sent();
131
+ return [2 /*return*/];
132
+ case 7:
133
+ if (!(type === "dropped")) return [3 /*break*/, 9];
134
+ return [4 /*yield*/, service.recordDeliveryEvent({
135
+ channel: "mail",
136
+ errorClass: "permanent",
137
+ errorCode: reason || "dropped",
138
+ providerMessageId: providerMessageId,
139
+ raw: event,
140
+ status: "failed",
141
+ })];
142
+ case 8:
143
+ _c.sent();
144
+ return [2 /*return*/];
145
+ case 9:
146
+ if (!(type === "spamreport" || type === "unsubscribe" || type === "group_unsubscribe")) return [3 /*break*/, 11];
147
+ optOut = {
148
+ channel: "mail",
149
+ provider: "sendgrid",
150
+ raw: event,
151
+ reason: type,
152
+ to: email,
153
+ };
154
+ return [4 /*yield*/, service.recordOptOut(optOut)];
155
+ case 10:
156
+ _c.sent();
157
+ _c.label = 11;
158
+ case 11: return [2 /*return*/];
159
+ }
160
+ });
161
+ }); };
162
+ var registerSendGridCommsWebhooks = function (_a) {
163
+ var basePath = _a.basePath, publicKey = _a.publicKey, service = _a.service, webhooks = _a.webhooks;
164
+ webhooks.route({
165
+ handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
166
+ var body_1, body_1_1, item, event_1, eventId, claimResult, error_1, e_1_1;
167
+ var e_1, _c;
168
+ var body = _b.body;
169
+ return __generator(this, function (_d) {
170
+ switch (_d.label) {
171
+ case 0:
172
+ if (!Array.isArray(body)) {
173
+ return [2 /*return*/];
174
+ }
175
+ _d.label = 1;
176
+ case 1:
177
+ _d.trys.push([1, 10, 11, 12]);
178
+ body_1 = __values(body), body_1_1 = body_1.next();
179
+ _d.label = 2;
180
+ case 2:
181
+ if (!!body_1_1.done) return [3 /*break*/, 9];
182
+ item = body_1_1.value;
183
+ if (!item || typeof item !== "object" || Array.isArray(item)) {
184
+ return [3 /*break*/, 8];
185
+ }
186
+ event_1 = item;
187
+ eventId = eventString(event_1.sg_event_id);
188
+ if (!eventId) {
189
+ return [3 /*break*/, 8];
190
+ }
191
+ return [4 /*yield*/, webhooks.claim({ eventId: eventId, source: "sendgrid" })];
192
+ case 3:
193
+ claimResult = _d.sent();
194
+ if (claimResult === "duplicate") {
195
+ return [3 /*break*/, 8];
196
+ }
197
+ _d.label = 4;
198
+ case 4:
199
+ _d.trys.push([4, 6, , 8]);
200
+ return [4 /*yield*/, applySendGridEvent({ event: event_1, service: service })];
201
+ case 5:
202
+ _d.sent();
203
+ return [3 /*break*/, 8];
204
+ case 6:
205
+ error_1 = _d.sent();
206
+ return [4 /*yield*/, webhooks.release({ eventId: eventId, source: "sendgrid" })];
207
+ case 7:
208
+ _d.sent();
209
+ throw error_1;
210
+ case 8:
211
+ body_1_1 = body_1.next();
212
+ return [3 /*break*/, 2];
213
+ case 9: return [3 /*break*/, 12];
214
+ case 10:
215
+ e_1_1 = _d.sent();
216
+ e_1 = { error: e_1_1 };
217
+ return [3 /*break*/, 12];
218
+ case 11:
219
+ try {
220
+ if (body_1_1 && !body_1_1.done && (_c = body_1.return)) _c.call(body_1);
221
+ }
222
+ finally { if (e_1) throw e_1.error; }
223
+ return [7 /*endfinally*/];
224
+ case 12: return [2 /*return*/];
225
+ }
226
+ });
227
+ }); },
228
+ path: "".concat(basePath, "/webhooks/sendgrid"),
229
+ source: "sendgrid",
230
+ verify: (0, api_1.sendgridEventSignature)({ publicKey: publicKey }),
231
+ });
232
+ };
233
+ exports.registerSendGridCommsWebhooks = registerSendGridCommsWebhooks;
234
+ var maybeRegisterSendGridCommsWebhooks = function (_a) {
235
+ var basePath = _a.basePath, mail = _a.mail, service = _a.service, webhooks = _a.webhooks;
236
+ if (!webhooks || !(mail instanceof sendgrid_1.SendGridMailProvider)) {
237
+ return;
238
+ }
239
+ var publicKey = mail.getWebhookVerificationKey();
240
+ if (!publicKey) {
241
+ api_1.logger.error("[comms] Skipping SendGrid webhook routes; set webhookVerificationKey or SENDGRID_WEBHOOK_VERIFICATION_KEY");
242
+ return;
243
+ }
244
+ (0, exports.registerSendGridCommsWebhooks)({
245
+ basePath: basePath,
246
+ publicKey: publicKey,
247
+ service: service,
248
+ webhooks: webhooks,
249
+ });
250
+ };
251
+ exports.maybeRegisterSendGridCommsWebhooks = maybeRegisterSendGridCommsWebhooks;
@@ -0,0 +1,18 @@
1
+ import { type WebhooksApp } from "@terreno/api";
2
+ import type { CommsService } from "../commsService";
3
+ export declare const registerTwilioCommsWebhooks: ({ authToken, basePath, publicUrl, service, webhooks, }: {
4
+ authToken: string;
5
+ basePath: string;
6
+ publicUrl: string;
7
+ service: CommsService;
8
+ webhooks: WebhooksApp;
9
+ }) => void;
10
+ export declare const maybeRegisterTwilioCommsWebhooks: ({ basePath, publicUrl, service, sms, webhooks, }: {
11
+ basePath: string;
12
+ publicUrl?: string;
13
+ service: CommsService;
14
+ sms?: {
15
+ id: string;
16
+ };
17
+ webhooks?: WebhooksApp;
18
+ }) => void;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.maybeRegisterTwilioCommsWebhooks = exports.registerTwilioCommsWebhooks = void 0;
40
+ var api_1 = require("@terreno/api");
41
+ var twilioSms_1 = require("../adapters/twilioSms");
42
+ var formString = function (body, key) {
43
+ if (!body || typeof body !== "object") {
44
+ return "";
45
+ }
46
+ var value = body[key];
47
+ return typeof value === "string" ? value : "";
48
+ };
49
+ var inboundKeyword = function (body) {
50
+ var _a;
51
+ var keyword = (_a = body.trim().split(/\s+/)[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
52
+ if (keyword === "STOP") {
53
+ return "sms-stop";
54
+ }
55
+ if (keyword === "START") {
56
+ return "sms-start";
57
+ }
58
+ return undefined;
59
+ };
60
+ var mapStatus = function (messageStatus, errorCode) {
61
+ if (messageStatus === "delivered") {
62
+ return { status: "delivered" };
63
+ }
64
+ if (messageStatus === "undelivered" || messageStatus === "failed") {
65
+ return {
66
+ errorClass: errorCode === "21610" ? "permanent" : "transient",
67
+ errorCode: errorCode || undefined,
68
+ status: "failed",
69
+ };
70
+ }
71
+ return undefined;
72
+ };
73
+ var registerTwilioCommsWebhooks = function (_a) {
74
+ var authToken = _a.authToken, basePath = _a.basePath, publicUrl = _a.publicUrl, service = _a.service, webhooks = _a.webhooks;
75
+ var statusPath = "".concat(basePath, "/webhooks/twilio/status");
76
+ var inboundPath = "".concat(basePath, "/webhooks/twilio/inbound");
77
+ var statusUrl = "".concat(publicUrl).concat(statusPath);
78
+ var inboundUrl = "".concat(publicUrl).concat(inboundPath);
79
+ webhooks.route({
80
+ eventId: function (req) {
81
+ var sid = formString(req.body, "MessageSid");
82
+ var status = formString(req.body, "MessageStatus");
83
+ return status ? "".concat(sid, ":").concat(status) : sid;
84
+ },
85
+ handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
86
+ var messageStatus, mapped;
87
+ var body = _b.body;
88
+ return __generator(this, function (_c) {
89
+ switch (_c.label) {
90
+ case 0:
91
+ messageStatus = formString(body, "MessageStatus");
92
+ mapped = mapStatus(messageStatus, formString(body, "ErrorCode"));
93
+ if (!mapped) {
94
+ return [2 /*return*/];
95
+ }
96
+ return [4 /*yield*/, service.recordDeliveryEvent({
97
+ channel: "sms",
98
+ errorClass: mapped.errorClass,
99
+ errorCode: mapped.errorCode,
100
+ providerMessageId: formString(body, "MessageSid"),
101
+ raw: body,
102
+ status: mapped.status,
103
+ })];
104
+ case 1:
105
+ _c.sent();
106
+ return [2 /*return*/];
107
+ }
108
+ });
109
+ }); },
110
+ path: statusPath,
111
+ source: "twilio-status",
112
+ verify: (0, api_1.twilioSignature)({ authToken: authToken, url: statusUrl }),
113
+ });
114
+ webhooks.route({
115
+ eventId: function (req) {
116
+ var _a;
117
+ var sid = formString(req.body, "SmsSid") || formString(req.body, "MessageSid");
118
+ var keyword = (_a = inboundKeyword(formString(req.body, "Body"))) !== null && _a !== void 0 ? _a : "inbound";
119
+ return "".concat(sid, ":").concat(keyword);
120
+ },
121
+ handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
122
+ var reason;
123
+ var body = _b.body;
124
+ return __generator(this, function (_c) {
125
+ switch (_c.label) {
126
+ case 0:
127
+ reason = inboundKeyword(formString(body, "Body"));
128
+ if (!reason) {
129
+ return [2 /*return*/];
130
+ }
131
+ return [4 /*yield*/, service.recordOptOut({
132
+ channel: "sms",
133
+ provider: "twilio",
134
+ raw: body,
135
+ reason: reason,
136
+ to: formString(body, "From"),
137
+ })];
138
+ case 1:
139
+ _c.sent();
140
+ return [2 /*return*/];
141
+ }
142
+ });
143
+ }); },
144
+ path: inboundPath,
145
+ source: "twilio-inbound",
146
+ verify: (0, api_1.twilioSignature)({ authToken: authToken, url: inboundUrl }),
147
+ });
148
+ };
149
+ exports.registerTwilioCommsWebhooks = registerTwilioCommsWebhooks;
150
+ var maybeRegisterTwilioCommsWebhooks = function (_a) {
151
+ var _b, _c;
152
+ var basePath = _a.basePath, publicUrl = _a.publicUrl, service = _a.service, sms = _a.sms, webhooks = _a.webhooks;
153
+ if (!webhooks || !(sms instanceof twilioSms_1.TwilioSmsProvider)) {
154
+ return;
155
+ }
156
+ var authToken = sms.getAuthToken();
157
+ if (!authToken) {
158
+ api_1.logger.error("[comms] Skipping Twilio webhook routes; auth token is missing");
159
+ return;
160
+ }
161
+ var resolvedPublicUrl = ((_c = (_b = publicUrl !== null && publicUrl !== void 0 ? publicUrl : process.env.PUBLIC_API_URL) !== null && _b !== void 0 ? _b : process.env.COMMS_WEBHOOK_PUBLIC_URL) !== null && _c !== void 0 ? _c : "").replace(/\/$/, "");
162
+ if (!resolvedPublicUrl) {
163
+ api_1.logger.error("[comms] Skipping Twilio webhook routes; set webhookPublicUrl, PUBLIC_API_URL, or COMMS_WEBHOOK_PUBLIC_URL");
164
+ return;
165
+ }
166
+ sms.applyDefaultStatusCallbackUrl("".concat(resolvedPublicUrl).concat(basePath, "/webhooks/twilio/status"));
167
+ (0, exports.registerTwilioCommsWebhooks)({
168
+ authToken: authToken,
169
+ basePath: basePath,
170
+ publicUrl: resolvedPublicUrl,
171
+ service: service,
172
+ webhooks: webhooks,
173
+ });
174
+ };
175
+ exports.maybeRegisterTwilioCommsWebhooks = maybeRegisterTwilioCommsWebhooks;
package/package.json CHANGED
@@ -4,13 +4,14 @@
4
4
  "url": "https://github.com/FlourishHealth/terreno/issues"
5
5
  },
6
6
  "dependencies": {
7
- "@terreno/api": "57.2.0",
7
+ "@terreno/api": "57.3.0",
8
+ "libphonenumber-js": "^1.13.8",
8
9
  "luxon": "^3.7.2"
9
10
  },
10
- "description": "Pluggable communications providers for Terreno backends",
11
+ "description": "Pluggable mail, SMS, push, and verification providers — part of Terreno, the batteries-included TypeScript framework for universal apps.",
11
12
  "devDependencies": {
12
13
  "@biomejs/biome": "^2.3.6",
13
- "@terreno/test": "57.2.0",
14
+ "@terreno/test": "57.3.0",
14
15
  "@types/bun": "^1.4.0",
15
16
  "@types/express": "^5.0.6",
16
17
  "@types/luxon": "^3.7.1",
@@ -24,9 +25,21 @@
24
25
  "types": "./dist/index.d.ts",
25
26
  "default": "./dist/index.js"
26
27
  },
28
+ "./adapters/expoPush": {
29
+ "types": "./dist/adapters/expoPush.d.ts",
30
+ "default": "./dist/adapters/expoPush.js"
31
+ },
27
32
  "./adapters/sendgrid": {
28
33
  "types": "./dist/adapters/sendgrid.d.ts",
29
34
  "default": "./dist/adapters/sendgrid.js"
35
+ },
36
+ "./adapters/twilioSms": {
37
+ "types": "./dist/adapters/twilioSms.d.ts",
38
+ "default": "./dist/adapters/twilioSms.js"
39
+ },
40
+ "./adapters/twilioVerify": {
41
+ "types": "./dist/adapters/twilioVerify.d.ts",
42
+ "default": "./dist/adapters/twilioVerify.js"
30
43
  }
31
44
  },
32
45
  "homepage": "https://github.com/FlourishHealth/terreno#readme",
@@ -42,11 +55,19 @@
42
55
  "name": "@terreno/comms",
43
56
  "peerDependencies": {
44
57
  "@sendgrid/mail": "^8.0.0",
45
- "mongoose": "^8.0.0 || ^9.0.0"
58
+ "expo-server-sdk": "^6.0.0",
59
+ "mongoose": "^8.0.0 || ^9.0.0",
60
+ "twilio": "^5.0.0"
46
61
  },
47
62
  "peerDependenciesMeta": {
48
63
  "@sendgrid/mail": {
49
64
  "optional": true
65
+ },
66
+ "expo-server-sdk": {
67
+ "optional": true
68
+ },
69
+ "twilio": {
70
+ "optional": true
50
71
  }
51
72
  },
52
73
  "publishConfig": {
@@ -68,5 +89,5 @@
68
89
  "test:coverage": "bun run ../scripts/check-coverage.ts"
69
90
  },
70
91
  "types": "dist/index.d.ts",
71
- "version": "57.2.0"
92
+ "version": "57.3.0"
72
93
  }