@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,89 +1,24 @@
|
|
|
1
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
|
-
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
3
|
exports.ExpoPushProvider = void 0;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
5
|
+
const api_1 = require("@terreno/api");
|
|
6
|
+
const nodeRequire = (0, node_module_1.createRequire)(__filename);
|
|
7
|
+
const DEFAULT_RECEIPT_POLL_DELAY_MS = 15 * 60 * 1000;
|
|
8
|
+
const resolveAccessToken = (options) => options?.accessToken ?? process.env.EXPO_ACCESS_TOKEN;
|
|
9
|
+
const loadExpoSdk = () => {
|
|
73
10
|
try {
|
|
74
11
|
// Optional peer — keep `expo-server-sdk` out of core dependencies.
|
|
75
12
|
return nodeRequire("expo-server-sdk");
|
|
76
13
|
}
|
|
77
|
-
catch
|
|
14
|
+
catch {
|
|
78
15
|
throw new Error("ExpoPushProvider requires optional peer dependency expo-server-sdk. " +
|
|
79
16
|
"Install it with: bun add expo-server-sdk");
|
|
80
17
|
}
|
|
81
18
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
};
|
|
86
|
-
var classifyExpoError = function (code) {
|
|
19
|
+
const defaultIsExpoPushToken = (token) => (token.startsWith("ExponentPushToken[") || token.startsWith("ExpoPushToken[")) &&
|
|
20
|
+
token.endsWith("]");
|
|
21
|
+
const classifyExpoError = (code) => {
|
|
87
22
|
if (code === "InvalidCredentials" || code === "MessageTooBig") {
|
|
88
23
|
return { errorClass: "config", errorCode: code };
|
|
89
24
|
}
|
|
@@ -93,30 +28,26 @@ var classifyExpoError = function (code) {
|
|
|
93
28
|
if (code === "MessageRateExceeded") {
|
|
94
29
|
return { errorClass: "transient", errorCode: code };
|
|
95
30
|
}
|
|
96
|
-
return { errorClass: "transient", errorCode: code
|
|
31
|
+
return { errorClass: "transient", errorCode: code ?? "expo-unknown" };
|
|
97
32
|
};
|
|
98
|
-
|
|
99
|
-
var error = _a.error, errorClass = _a.errorClass, errorCode = _a.errorCode;
|
|
33
|
+
const failedResult = ({ error, errorClass, errorCode, }) => {
|
|
100
34
|
if (errorClass === "config") {
|
|
101
|
-
api_1.logger.error(
|
|
35
|
+
api_1.logger.error(`[comms:expo] ${errorCode}: ${error}`);
|
|
102
36
|
}
|
|
103
37
|
return {
|
|
104
38
|
accepted: false,
|
|
105
|
-
error
|
|
106
|
-
errorClass
|
|
107
|
-
errorCode
|
|
39
|
+
error,
|
|
40
|
+
errorClass,
|
|
41
|
+
errorCode,
|
|
108
42
|
isPermanentFailure: errorClass === "permanent",
|
|
109
43
|
};
|
|
110
44
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
var ticketToResult = function (ticket) {
|
|
119
|
-
var _a, _b;
|
|
45
|
+
const invalidTokenResult = () => failedResult({
|
|
46
|
+
error: "Not an Expo push token",
|
|
47
|
+
errorClass: "permanent",
|
|
48
|
+
errorCode: "expo-invalid-token",
|
|
49
|
+
});
|
|
50
|
+
const ticketToResult = (ticket) => {
|
|
120
51
|
if (!ticket) {
|
|
121
52
|
return failedResult({
|
|
122
53
|
error: "Expo returned no ticket for this token",
|
|
@@ -127,274 +58,157 @@ var ticketToResult = function (ticket) {
|
|
|
127
58
|
if (ticket.status === "ok") {
|
|
128
59
|
return { accepted: true, providerMessageId: ticket.id };
|
|
129
60
|
}
|
|
130
|
-
|
|
61
|
+
const { errorClass, errorCode } = classifyExpoError(ticket.details?.error);
|
|
131
62
|
return failedResult({
|
|
132
|
-
error:
|
|
133
|
-
errorClass
|
|
134
|
-
errorCode
|
|
63
|
+
error: ticket.message ?? errorCode,
|
|
64
|
+
errorClass,
|
|
65
|
+
errorCode,
|
|
135
66
|
});
|
|
136
67
|
};
|
|
137
|
-
|
|
138
|
-
setTimeout(
|
|
68
|
+
const defaultScheduleReceiptPoll = (delayMs, run) => {
|
|
69
|
+
setTimeout(() => {
|
|
139
70
|
void run();
|
|
140
71
|
}, delayMs);
|
|
141
72
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
73
|
+
class ExpoPushProvider {
|
|
74
|
+
id = "expo";
|
|
75
|
+
client;
|
|
76
|
+
isExpoPushToken;
|
|
77
|
+
onDeadToken;
|
|
78
|
+
onDeliveryEvent;
|
|
79
|
+
receiptPollDelayMs;
|
|
80
|
+
scheduleReceiptPoll;
|
|
81
|
+
pendingReceipts = new Map();
|
|
82
|
+
constructor(options) {
|
|
83
|
+
this.onDeadToken = options?.onDeadToken;
|
|
84
|
+
this.onDeliveryEvent = options?.onDeliveryEvent;
|
|
85
|
+
this.receiptPollDelayMs = options?.receiptPollDelayMs ?? DEFAULT_RECEIPT_POLL_DELAY_MS;
|
|
86
|
+
this.scheduleReceiptPoll = options?.scheduleReceiptPoll ?? defaultScheduleReceiptPoll;
|
|
87
|
+
if (options?.client) {
|
|
152
88
|
this.client = options.client;
|
|
153
|
-
this.isExpoPushToken =
|
|
89
|
+
this.isExpoPushToken = options.isExpoPushToken ?? defaultIsExpoPushToken;
|
|
154
90
|
return;
|
|
155
91
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.client = new ExpoSdk.Expo(accessToken ? { accessToken
|
|
159
|
-
this.isExpoPushToken =
|
|
92
|
+
const ExpoSdk = loadExpoSdk();
|
|
93
|
+
const accessToken = resolveAccessToken(options);
|
|
94
|
+
this.client = new ExpoSdk.Expo(accessToken ? { accessToken } : {});
|
|
95
|
+
this.isExpoPushToken = options?.isExpoPushToken ?? ExpoSdk.Expo.isExpoPushToken;
|
|
160
96
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
validIndexes.push(index);
|
|
179
|
-
expoMessages.push({
|
|
180
|
-
badge: message.badge,
|
|
181
|
-
body: message.body,
|
|
182
|
-
data: message.data,
|
|
183
|
-
sound: message.sound,
|
|
184
|
-
title: message.title,
|
|
185
|
-
to: token,
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
if (expoMessages.length === 0) {
|
|
189
|
-
return [2 /*return*/, results.map(function (result) {
|
|
190
|
-
return result.errorCode === "pending" ? invalidTokenResult() : result;
|
|
191
|
-
})];
|
|
192
|
-
}
|
|
193
|
-
chunks = this.client.chunkPushNotifications(expoMessages);
|
|
194
|
-
cursor = 0;
|
|
195
|
-
newReceipts = [];
|
|
196
|
-
_loop_1 = function (chunk) {
|
|
197
|
-
var tickets, error_1, errorMessage, offset, tokenIndex;
|
|
198
|
-
return __generator(this, function (_c) {
|
|
199
|
-
switch (_c.label) {
|
|
200
|
-
case 0:
|
|
201
|
-
_c.trys.push([0, 2, , 3]);
|
|
202
|
-
return [4 /*yield*/, this_1.client.sendPushNotificationsAsync(chunk)];
|
|
203
|
-
case 1:
|
|
204
|
-
tickets = _c.sent();
|
|
205
|
-
return [3 /*break*/, 3];
|
|
206
|
-
case 2:
|
|
207
|
-
error_1 = _c.sent();
|
|
208
|
-
errorMessage = error_1 instanceof Error ? error_1.message : "Expo send failed";
|
|
209
|
-
for (offset = 0; offset < chunk.length; offset += 1) {
|
|
210
|
-
tokenIndex = validIndexes[cursor + offset];
|
|
211
|
-
if (tokenIndex === undefined) {
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
results[tokenIndex] = failedResult({
|
|
215
|
-
error: errorMessage,
|
|
216
|
-
errorClass: "transient",
|
|
217
|
-
errorCode: "expo-send-throw",
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
cursor += chunk.length;
|
|
221
|
-
return [2 /*return*/, "continue"];
|
|
222
|
-
case 3:
|
|
223
|
-
chunk.forEach(function (expoMessage, offset) {
|
|
224
|
-
var tokenIndex = validIndexes[cursor + offset];
|
|
225
|
-
if (tokenIndex === undefined) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
var result = ticketToResult(tickets[offset]);
|
|
229
|
-
results[tokenIndex] = result;
|
|
230
|
-
if (result.accepted && result.providerMessageId) {
|
|
231
|
-
_this.pendingReceipts.set(result.providerMessageId, String(expoMessage.to));
|
|
232
|
-
newReceipts.push(result.providerMessageId);
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
cursor += chunk.length;
|
|
236
|
-
return [2 /*return*/];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
this_1 = this;
|
|
241
|
-
_b.label = 1;
|
|
242
|
-
case 1:
|
|
243
|
-
_b.trys.push([1, 6, 7, 8]);
|
|
244
|
-
chunks_1 = __values(chunks), chunks_1_1 = chunks_1.next();
|
|
245
|
-
_b.label = 2;
|
|
246
|
-
case 2:
|
|
247
|
-
if (!!chunks_1_1.done) return [3 /*break*/, 5];
|
|
248
|
-
chunk = chunks_1_1.value;
|
|
249
|
-
return [5 /*yield**/, _loop_1(chunk)];
|
|
250
|
-
case 3:
|
|
251
|
-
_b.sent();
|
|
252
|
-
_b.label = 4;
|
|
253
|
-
case 4:
|
|
254
|
-
chunks_1_1 = chunks_1.next();
|
|
255
|
-
return [3 /*break*/, 2];
|
|
256
|
-
case 5: return [3 /*break*/, 8];
|
|
257
|
-
case 6:
|
|
258
|
-
e_1_1 = _b.sent();
|
|
259
|
-
e_1 = { error: e_1_1 };
|
|
260
|
-
return [3 /*break*/, 8];
|
|
261
|
-
case 7:
|
|
262
|
-
try {
|
|
263
|
-
if (chunks_1_1 && !chunks_1_1.done && (_a = chunks_1.return)) _a.call(chunks_1);
|
|
264
|
-
}
|
|
265
|
-
finally { if (e_1) throw e_1.error; }
|
|
266
|
-
return [7 /*endfinally*/];
|
|
267
|
-
case 8:
|
|
268
|
-
if (newReceipts.length > 0) {
|
|
269
|
-
this.scheduleReceiptPoll(this.receiptPollDelayMs, function () { return _this.pollReceipts(newReceipts); });
|
|
270
|
-
}
|
|
271
|
-
return [2 /*return*/, results.map(function (result) {
|
|
272
|
-
return result.errorCode === "pending"
|
|
273
|
-
? failedResult({
|
|
274
|
-
error: "Expo returned no ticket for this token",
|
|
275
|
-
errorClass: "transient",
|
|
276
|
-
errorCode: "expo-missing-ticket",
|
|
277
|
-
})
|
|
278
|
-
: result;
|
|
279
|
-
})];
|
|
280
|
-
}
|
|
97
|
+
async sendPush(message) {
|
|
98
|
+
const results = message.tokens.map((token) => this.isExpoPushToken(token) ? { accepted: false, errorCode: "pending" } : invalidTokenResult());
|
|
99
|
+
const validIndexes = [];
|
|
100
|
+
const expoMessages = [];
|
|
101
|
+
message.tokens.forEach((token, index) => {
|
|
102
|
+
if (!this.isExpoPushToken(token)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
validIndexes.push(index);
|
|
106
|
+
expoMessages.push({
|
|
107
|
+
badge: message.badge,
|
|
108
|
+
body: message.body,
|
|
109
|
+
data: message.data,
|
|
110
|
+
sound: message.sound,
|
|
111
|
+
title: message.title,
|
|
112
|
+
to: token,
|
|
281
113
|
});
|
|
282
114
|
});
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
try {
|
|
321
|
-
if (chunk_1_1 && !chunk_1_1.done && (_b = chunk_1.return)) _b.call(chunk_1);
|
|
322
|
-
}
|
|
323
|
-
finally { if (e_3) throw e_3.error; }
|
|
324
|
-
}
|
|
325
|
-
return [3 /*break*/, 8];
|
|
326
|
-
case 6: return [4 /*yield*/, Promise.all(Object.entries(receipts).map(function (_a) {
|
|
327
|
-
var _b = __read(_a, 2), receiptId = _b[0], receipt = _b[1];
|
|
328
|
-
return _this.applyReceipt(receiptId, receipt);
|
|
329
|
-
}))];
|
|
330
|
-
case 7:
|
|
331
|
-
_c.sent();
|
|
332
|
-
_c.label = 8;
|
|
333
|
-
case 8:
|
|
334
|
-
chunks_2_1 = chunks_2.next();
|
|
335
|
-
return [3 /*break*/, 2];
|
|
336
|
-
case 9: return [3 /*break*/, 12];
|
|
337
|
-
case 10:
|
|
338
|
-
e_2_1 = _c.sent();
|
|
339
|
-
e_2 = { error: e_2_1 };
|
|
340
|
-
return [3 /*break*/, 12];
|
|
341
|
-
case 11:
|
|
342
|
-
try {
|
|
343
|
-
if (chunks_2_1 && !chunks_2_1.done && (_a = chunks_2.return)) _a.call(chunks_2);
|
|
344
|
-
}
|
|
345
|
-
finally { if (e_2) throw e_2.error; }
|
|
346
|
-
return [7 /*endfinally*/];
|
|
347
|
-
case 12: return [2 /*return*/];
|
|
115
|
+
if (expoMessages.length === 0) {
|
|
116
|
+
return results.map((result) => result.errorCode === "pending" ? invalidTokenResult() : result);
|
|
117
|
+
}
|
|
118
|
+
const chunks = this.client.chunkPushNotifications(expoMessages);
|
|
119
|
+
let cursor = 0;
|
|
120
|
+
const newReceipts = [];
|
|
121
|
+
for (const chunk of chunks) {
|
|
122
|
+
let tickets;
|
|
123
|
+
try {
|
|
124
|
+
tickets = await this.client.sendPushNotificationsAsync(chunk);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const errorMessage = error instanceof Error ? error.message : "Expo send failed";
|
|
128
|
+
for (let offset = 0; offset < chunk.length; offset += 1) {
|
|
129
|
+
const tokenIndex = validIndexes[cursor + offset];
|
|
130
|
+
if (tokenIndex === undefined) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
results[tokenIndex] = failedResult({
|
|
134
|
+
error: errorMessage,
|
|
135
|
+
errorClass: "transient",
|
|
136
|
+
errorCode: "expo-send-throw",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
cursor += chunk.length;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
chunk.forEach((expoMessage, offset) => {
|
|
143
|
+
const tokenIndex = validIndexes[cursor + offset];
|
|
144
|
+
if (tokenIndex === undefined) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const result = ticketToResult(tickets[offset]);
|
|
148
|
+
results[tokenIndex] = result;
|
|
149
|
+
if (result.accepted && result.providerMessageId) {
|
|
150
|
+
this.pendingReceipts.set(result.providerMessageId, String(expoMessage.to));
|
|
151
|
+
newReceipts.push(result.providerMessageId);
|
|
348
152
|
}
|
|
349
153
|
});
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
_a = classifyExpoError((_b = receipt.details) === null || _b === void 0 ? void 0 : _b.error), errorClass = _a.errorClass, errorCode = _a.errorCode;
|
|
375
|
-
if (!this.onDeliveryEvent) return [3 /*break*/, 5];
|
|
376
|
-
return [4 /*yield*/, this.onDeliveryEvent({
|
|
377
|
-
channel: "push",
|
|
378
|
-
errorClass: errorClass,
|
|
379
|
-
errorCode: errorCode,
|
|
380
|
-
providerMessageId: receiptId,
|
|
381
|
-
raw: receipt,
|
|
382
|
-
status: "failed",
|
|
383
|
-
})];
|
|
384
|
-
case 4:
|
|
385
|
-
_c.sent();
|
|
386
|
-
_c.label = 5;
|
|
387
|
-
case 5:
|
|
388
|
-
if (!(token && errorClass === "permanent" && this.onDeadToken)) return [3 /*break*/, 7];
|
|
389
|
-
return [4 /*yield*/, this.onDeadToken(token)];
|
|
390
|
-
case 6:
|
|
391
|
-
_c.sent();
|
|
392
|
-
_c.label = 7;
|
|
393
|
-
case 7: return [2 /*return*/];
|
|
154
|
+
cursor += chunk.length;
|
|
155
|
+
}
|
|
156
|
+
if (newReceipts.length > 0) {
|
|
157
|
+
this.scheduleReceiptPoll(this.receiptPollDelayMs, () => this.pollReceipts(newReceipts));
|
|
158
|
+
}
|
|
159
|
+
return results.map((result) => result.errorCode === "pending"
|
|
160
|
+
? failedResult({
|
|
161
|
+
error: "Expo returned no ticket for this token",
|
|
162
|
+
errorClass: "transient",
|
|
163
|
+
errorCode: "expo-missing-ticket",
|
|
164
|
+
})
|
|
165
|
+
: result);
|
|
166
|
+
}
|
|
167
|
+
async pollReceipts(receiptIds) {
|
|
168
|
+
const chunks = this.client.chunkPushNotificationReceiptIds(receiptIds);
|
|
169
|
+
for (const chunk of chunks) {
|
|
170
|
+
let receipts;
|
|
171
|
+
try {
|
|
172
|
+
receipts = await this.client.getPushNotificationReceiptsAsync(chunk);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
api_1.logger.warn(`[comms:expo] Receipt poll failed: ${String(error)}`);
|
|
176
|
+
for (const receiptId of chunk) {
|
|
177
|
+
this.pendingReceipts.delete(receiptId);
|
|
394
178
|
}
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
await Promise.all(Object.entries(receipts).map(([receiptId, receipt]) => this.applyReceipt(receiptId, receipt)));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async applyReceipt(receiptId, receipt) {
|
|
185
|
+
const token = this.pendingReceipts.get(receiptId);
|
|
186
|
+
this.pendingReceipts.delete(receiptId);
|
|
187
|
+
if (receipt.status === "ok") {
|
|
188
|
+
if (this.onDeliveryEvent) {
|
|
189
|
+
await this.onDeliveryEvent({
|
|
190
|
+
channel: "push",
|
|
191
|
+
providerMessageId: receiptId,
|
|
192
|
+
raw: receipt,
|
|
193
|
+
status: "delivered",
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const { errorClass, errorCode } = classifyExpoError(receipt.details?.error);
|
|
199
|
+
if (this.onDeliveryEvent) {
|
|
200
|
+
await this.onDeliveryEvent({
|
|
201
|
+
channel: "push",
|
|
202
|
+
errorClass,
|
|
203
|
+
errorCode,
|
|
204
|
+
providerMessageId: receiptId,
|
|
205
|
+
raw: receipt,
|
|
206
|
+
status: "failed",
|
|
395
207
|
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
208
|
+
}
|
|
209
|
+
if (token && errorClass === "permanent" && this.onDeadToken) {
|
|
210
|
+
await this.onDeadToken(token);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
400
214
|
exports.ExpoPushProvider = ExpoPushProvider;
|