@terreno/comms 57.4.0 → 57.6.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.
- package/README.md +2 -2
- package/dist/adapters/console.js +48 -109
- package/dist/adapters/expoPush.js +159 -345
- package/dist/adapters/sendgrid.js +94 -164
- package/dist/adapters/twilioSms.js +96 -151
- package/dist/adapters/twilioVerify.js +70 -132
- package/dist/commsApp.js +27 -27
- package/dist/commsQuery.js +33 -34
- package/dist/commsRetry.js +17 -25
- package/dist/commsService.js +674 -1098
- package/dist/models/commsMessage.js +64 -172
- package/dist/models/pushToken.js +5 -5
- package/dist/routes/commsDashboard.js +174 -325
- package/dist/routes/pushTokens.js +122 -217
- package/dist/templates.js +27 -41
- package/dist/webhooks/sendgridWebhooks.js +109 -226
- package/dist/webhooks/twilioWebhooks.js +59 -117
- package/package.json +6 -6
- package/tsconfig.json +6 -20
|
@@ -1,85 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
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);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
};
|
|
74
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
4
|
};
|
|
77
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
6
|
exports.CommsMessage = void 0;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
+
const commsMessageSchema = new mongoose_1.default.Schema({
|
|
83
11
|
attemptCount: {
|
|
84
12
|
default: 0,
|
|
85
13
|
description: "Number of facade send attempts recorded on this row",
|
|
@@ -205,104 +133,68 @@ var commsMessageSchema = new mongoose_1.default.Schema({
|
|
|
205
133
|
},
|
|
206
134
|
}, { strict: "throw", toJSON: { virtuals: true }, toObject: { virtuals: true } });
|
|
207
135
|
commsMessageSchema.statics = {
|
|
208
|
-
appendAttempt
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
_b.sent();
|
|
240
|
-
return [3 /*break*/, 4];
|
|
241
|
-
case 3:
|
|
242
|
-
_a = _b.sent();
|
|
243
|
-
api_1.logger.warn("[comms] Failed to append communication attempt");
|
|
244
|
-
return [2 /*return*/, null];
|
|
245
|
-
case 4: return [4 /*yield*/, this.clearExpiredPayloads()];
|
|
246
|
-
case 5:
|
|
247
|
-
_b.sent();
|
|
248
|
-
return [2 /*return*/, document];
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
});
|
|
136
|
+
async appendAttempt(params) {
|
|
137
|
+
let document;
|
|
138
|
+
try {
|
|
139
|
+
document = await this.findOneOrNone({ _id: params.id });
|
|
140
|
+
if (!document) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
document.attempts = [...document.attempts, params.attempt];
|
|
144
|
+
document.attemptCount = document.attempts.length;
|
|
145
|
+
document.error = params.error;
|
|
146
|
+
document.errorClass = params.errorClass;
|
|
147
|
+
document.errorCode = params.errorCode;
|
|
148
|
+
document.lastAttemptAt = params.attempt.at;
|
|
149
|
+
document.providerMessageId = params.providerMessageId;
|
|
150
|
+
document.status = params.status;
|
|
151
|
+
if (params.metadata) {
|
|
152
|
+
document.metadata = { ...document.metadata, ...params.metadata };
|
|
153
|
+
document.markModified("metadata");
|
|
154
|
+
}
|
|
155
|
+
if (params.payload !== undefined) {
|
|
156
|
+
document.payload = params.payload;
|
|
157
|
+
document.payloadExpiresAt = params.payloadExpiresAt;
|
|
158
|
+
}
|
|
159
|
+
await document.save();
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
api_1.logger.warn("[comms] Failed to append communication attempt");
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
await this.clearExpiredPayloads();
|
|
166
|
+
return document;
|
|
252
167
|
},
|
|
253
|
-
clearExpiredPayloads
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return [4 /*yield*/, this.updateMany({ _id: { $in: expired.map(function (row) { return row._id; }) } }, { $unset: { payload: 1, payloadExpiresAt: 1 } })];
|
|
272
|
-
case 2:
|
|
273
|
-
result = _a.sent();
|
|
274
|
-
return [2 /*return*/, result.modifiedCount];
|
|
275
|
-
case 3:
|
|
276
|
-
error_1 = _a.sent();
|
|
277
|
-
api_1.logger.warn("[comms] Failed to clear expired payloads: ".concat(String(error_1)));
|
|
278
|
-
return [2 /*return*/, 0];
|
|
279
|
-
case 4: return [2 /*return*/];
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
});
|
|
168
|
+
async clearExpiredPayloads() {
|
|
169
|
+
try {
|
|
170
|
+
const expired = await this.find({
|
|
171
|
+
payload: { $exists: true },
|
|
172
|
+
payloadExpiresAt: { $lte: luxon_1.DateTime.utc().toJSDate() },
|
|
173
|
+
})
|
|
174
|
+
.select("_id")
|
|
175
|
+
.limit(50);
|
|
176
|
+
if (expired.length === 0) {
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
const result = await this.updateMany({ _id: { $in: expired.map((row) => row._id) } }, { $unset: { payload: 1, payloadExpiresAt: 1 } });
|
|
180
|
+
return result.modifiedCount;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
api_1.logger.warn(`[comms] Failed to clear expired payloads: ${String(error)}`);
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
283
186
|
},
|
|
284
|
-
logSend
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
case 2:
|
|
296
|
-
_a = _b.sent();
|
|
297
|
-
api_1.logger.warn("[comms] Failed to record communication send");
|
|
298
|
-
return [2 /*return*/, null];
|
|
299
|
-
case 3: return [4 /*yield*/, this.clearExpiredPayloads()];
|
|
300
|
-
case 4:
|
|
301
|
-
_b.sent();
|
|
302
|
-
return [2 /*return*/, created];
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
});
|
|
187
|
+
async logSend(params) {
|
|
188
|
+
let created;
|
|
189
|
+
try {
|
|
190
|
+
created = await this.create(params);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
api_1.logger.warn("[comms] Failed to record communication send");
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
await this.clearExpiredPayloads();
|
|
197
|
+
return created;
|
|
306
198
|
},
|
|
307
199
|
};
|
|
308
200
|
commsMessageSchema.plugin(api_1.createdUpdatedPlugin);
|
package/dist/models/pushToken.js
CHANGED
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PushToken = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
+
const pushTokenSchema = new mongoose_1.default.Schema({
|
|
11
11
|
active: {
|
|
12
12
|
default: true,
|
|
13
13
|
description: "Whether the device token is available for push delivery",
|
|
@@ -18,7 +18,7 @@ var pushTokenSchema = new mongoose_1.default.Schema({
|
|
|
18
18
|
type: String,
|
|
19
19
|
},
|
|
20
20
|
lastSeenAt: {
|
|
21
|
-
default:
|
|
21
|
+
default: () => luxon_1.DateTime.utc().toJSDate(),
|
|
22
22
|
description: "Most recent time the device token was registered",
|
|
23
23
|
required: true,
|
|
24
24
|
type: Date,
|