@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.
@@ -1,73 +1,36 @@
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.TwilioVerifyProvider = void 0;
40
- var node_module_1 = require("node:module");
41
- var api_1 = require("@terreno/api");
42
- var PERMANENT_CODES = new Set([60200, 60202, 60203]);
43
- var TRANSIENT_CODES = new Set([20429]);
44
- var CONFIG_CODES = new Set([20003, 20404]);
45
- var TWILIO_VERIFY_CONSOLE_BASE = "https://console.twilio.com/us1/develop/verify/services";
46
- var nodeRequire = (0, node_module_1.createRequire)(__filename);
47
- var resolveCredentials = function (options) {
48
- var _a, _b, _c;
49
- var accountSid = (_a = options === null || options === void 0 ? void 0 : options.accountSid) !== null && _a !== void 0 ? _a : process.env.TWILIO_ACCOUNT_SID;
50
- var authToken = (_b = options === null || options === void 0 ? void 0 : options.authToken) !== null && _b !== void 0 ? _b : process.env.TWILIO_AUTH_TOKEN;
51
- var verifyServiceSid = (_c = options === null || options === void 0 ? void 0 : options.verifyServiceSid) !== null && _c !== void 0 ? _c : process.env.TWILIO_VERIFY_SERVICE_SID;
4
+ const node_module_1 = require("node:module");
5
+ const api_1 = require("@terreno/api");
6
+ const PERMANENT_CODES = new Set([60200, 60202, 60203]);
7
+ const TRANSIENT_CODES = new Set([20429]);
8
+ const CONFIG_CODES = new Set([20003, 20404]);
9
+ const TWILIO_VERIFY_CONSOLE_BASE = "https://console.twilio.com/us1/develop/verify/services";
10
+ const nodeRequire = (0, node_module_1.createRequire)(__filename);
11
+ const resolveCredentials = (options) => {
12
+ const accountSid = options?.accountSid ?? process.env.TWILIO_ACCOUNT_SID;
13
+ const authToken = options?.authToken ?? process.env.TWILIO_AUTH_TOKEN;
14
+ const verifyServiceSid = options?.verifyServiceSid ?? process.env.TWILIO_VERIFY_SERVICE_SID;
52
15
  if (!accountSid || !authToken) {
53
16
  throw new Error("TwilioVerifyProvider requires TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN or matching constructor options");
54
17
  }
55
18
  if (!verifyServiceSid) {
56
19
  throw new Error("TwilioVerifyProvider requires TWILIO_VERIFY_SERVICE_SID or a verifyServiceSid constructor option");
57
20
  }
58
- return { accountSid: accountSid, authToken: authToken, verifyServiceSid: verifyServiceSid };
21
+ return { accountSid, authToken, verifyServiceSid };
59
22
  };
60
- var loadTwilio = function () {
23
+ const loadTwilio = () => {
61
24
  try {
62
25
  // Optional peer — keep `twilio` out of core dependencies.
63
26
  return nodeRequire("twilio");
64
27
  }
65
- catch (_a) {
28
+ catch {
66
29
  throw new Error("TwilioVerifyProvider requires optional peer dependency twilio. " +
67
30
  "Install it with: bun add twilio");
68
31
  }
69
32
  };
70
- var checkErrorForStatus = function (status) {
33
+ const checkErrorForStatus = (status) => {
71
34
  if (status === "approved") {
72
35
  return undefined;
73
36
  }
@@ -76,22 +39,22 @@ var checkErrorForStatus = function (status) {
76
39
  }
77
40
  return status;
78
41
  };
79
- var twilioErrorFields = function (error) {
42
+ const twilioErrorFields = (error) => {
80
43
  if (!error || typeof error !== "object") {
81
44
  return {
82
45
  message: error instanceof Error ? error.message : "Twilio Verify request failed",
83
- payload: { error: error },
46
+ payload: { error },
84
47
  };
85
48
  }
86
- var raw = error;
87
- var code = typeof raw.code === "number" ? raw.code : undefined;
88
- var status = typeof raw.status === "number" ? raw.status : undefined;
89
- var message = typeof raw.message === "string" && raw.message.length > 0
49
+ const raw = error;
50
+ const code = typeof raw.code === "number" ? raw.code : undefined;
51
+ const status = typeof raw.status === "number" ? raw.status : undefined;
52
+ const message = typeof raw.message === "string" && raw.message.length > 0
90
53
  ? raw.message
91
54
  : error instanceof Error
92
55
  ? error.message
93
56
  : "Twilio Verify request failed";
94
- var payload = { message: message };
57
+ const payload = { message };
95
58
  if (code !== undefined) {
96
59
  payload.code = code;
97
60
  }
@@ -101,9 +64,9 @@ var twilioErrorFields = function (error) {
101
64
  if (typeof raw.moreInfo === "string") {
102
65
  payload.moreInfo = raw.moreInfo;
103
66
  }
104
- return { code: code, message: message, payload: payload, status: status };
67
+ return { code, message, payload, status };
105
68
  };
106
- var classifyTwilioVerifyFailure = function (fields) {
69
+ const classifyTwilioVerifyFailure = (fields) => {
107
70
  if (fields.code !== undefined && PERMANENT_CODES.has(fields.code)) {
108
71
  return { errorClass: "permanent", errorCode: String(fields.code) };
109
72
  }
@@ -116,7 +79,7 @@ var classifyTwilioVerifyFailure = function (fields) {
116
79
  if (fields.status === 429 || (fields.status !== undefined && fields.status >= 500)) {
117
80
  return {
118
81
  errorClass: "transient",
119
- errorCode: fields.code !== undefined ? String(fields.code) : "twilio-".concat(fields.status),
82
+ errorCode: fields.code !== undefined ? String(fields.code) : `twilio-${fields.status}`,
120
83
  };
121
84
  }
122
85
  if (fields.code !== undefined) {
@@ -124,89 +87,64 @@ var classifyTwilioVerifyFailure = function (fields) {
124
87
  }
125
88
  return { errorClass: "transient", errorCode: "twilio-network" };
126
89
  };
127
- var failedStartResult = function (error) {
128
- var fields = twilioErrorFields(error);
129
- var _a = classifyTwilioVerifyFailure(fields), errorClass = _a.errorClass, errorCode = _a.errorCode;
90
+ const failedStartResult = (error) => {
91
+ const fields = twilioErrorFields(error);
92
+ const { errorClass, errorCode } = classifyTwilioVerifyFailure(fields);
130
93
  if (errorClass === "config") {
131
- api_1.logger.error("[comms:twilio-verify] ".concat(errorCode, ": ").concat(fields.message));
94
+ api_1.logger.error(`[comms:twilio-verify] ${errorCode}: ${fields.message}`);
132
95
  }
133
96
  return {
134
97
  accepted: false,
135
98
  error: fields.message,
136
- errorClass: errorClass,
137
- errorCode: errorCode,
99
+ errorClass,
100
+ errorCode,
138
101
  isPermanentFailure: errorClass === "permanent",
139
102
  metadata: { twilioError: fields.payload },
140
103
  };
141
104
  };
142
- var TwilioVerifyProvider = /** @class */ (function () {
143
- function TwilioVerifyProvider(options) {
144
- this.id = "twilio-verify";
145
- var _a = resolveCredentials(options), accountSid = _a.accountSid, authToken = _a.authToken, verifyServiceSid = _a.verifyServiceSid;
105
+ class TwilioVerifyProvider {
106
+ id = "twilio-verify";
107
+ client;
108
+ verifyServiceSid;
109
+ constructor(options) {
110
+ const { accountSid, authToken, verifyServiceSid } = resolveCredentials(options);
146
111
  this.verifyServiceSid = verifyServiceSid;
147
- if (options === null || options === void 0 ? void 0 : options.client) {
112
+ if (options?.client) {
148
113
  this.client = options.client;
149
114
  return;
150
115
  }
151
116
  this.client = loadTwilio()(accountSid, authToken);
152
117
  }
153
- TwilioVerifyProvider.prototype.startVerification = function (options) {
154
- return __awaiter(this, void 0, void 0, function () {
155
- var created, error_1;
156
- var _this = this;
157
- return __generator(this, function (_a) {
158
- switch (_a.label) {
159
- case 0:
160
- _a.trys.push([0, 2, , 3]);
161
- return [4 /*yield*/, (0, api_1.withApiErrorHandling)(function () {
162
- return _this.client.verify.v2
163
- .services(_this.verifyServiceSid)
164
- .verifications.create({ channel: options.channel, to: options.to });
165
- }, { apiName: "twilio-verify", operation: "startVerification" })];
166
- case 1:
167
- created = _a.sent();
168
- return [2 /*return*/, {
169
- accepted: true,
170
- metadata: { consoleUrl: "".concat(TWILIO_VERIFY_CONSOLE_BASE, "/").concat(this.verifyServiceSid) },
171
- providerMessageId: created.sid,
172
- }];
173
- case 2:
174
- error_1 = _a.sent();
175
- return [2 /*return*/, failedStartResult(error_1)];
176
- case 3: return [2 /*return*/];
177
- }
178
- });
179
- });
180
- };
181
- TwilioVerifyProvider.prototype.checkVerification = function (options) {
182
- return __awaiter(this, void 0, void 0, function () {
183
- var checked, error, error_2, fields;
184
- var _this = this;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0:
188
- _a.trys.push([0, 2, , 3]);
189
- return [4 /*yield*/, (0, api_1.withApiErrorHandling)(function () {
190
- return _this.client.verify.v2
191
- .services(_this.verifyServiceSid)
192
- .verificationChecks.create({ code: options.code, to: options.to });
193
- }, { apiName: "twilio-verify", operation: "checkVerification" })];
194
- case 1:
195
- checked = _a.sent();
196
- error = checkErrorForStatus(checked.status);
197
- if (error === undefined) {
198
- return [2 /*return*/, { valid: true }];
199
- }
200
- return [2 /*return*/, { error: error, valid: false }];
201
- case 2:
202
- error_2 = _a.sent();
203
- fields = twilioErrorFields(error_2);
204
- return [2 /*return*/, { error: fields.message, valid: false }];
205
- case 3: return [2 /*return*/];
206
- }
207
- });
208
- });
209
- };
210
- return TwilioVerifyProvider;
211
- }());
118
+ async startVerification(options) {
119
+ try {
120
+ const created = await (0, api_1.withApiErrorHandling)(() => this.client.verify.v2
121
+ .services(this.verifyServiceSid)
122
+ .verifications.create({ channel: options.channel, to: options.to }), { apiName: "twilio-verify", operation: "startVerification" });
123
+ return {
124
+ accepted: true,
125
+ metadata: { consoleUrl: `${TWILIO_VERIFY_CONSOLE_BASE}/${this.verifyServiceSid}` },
126
+ providerMessageId: created.sid,
127
+ };
128
+ }
129
+ catch (error) {
130
+ return failedStartResult(error);
131
+ }
132
+ }
133
+ async checkVerification(options) {
134
+ try {
135
+ const checked = await (0, api_1.withApiErrorHandling)(() => this.client.verify.v2
136
+ .services(this.verifyServiceSid)
137
+ .verificationChecks.create({ code: options.code, to: options.to }), { apiName: "twilio-verify", operation: "checkVerification" });
138
+ const error = checkErrorForStatus(checked.status);
139
+ if (error === undefined) {
140
+ return { valid: true };
141
+ }
142
+ return { error, valid: false };
143
+ }
144
+ catch (error) {
145
+ const fields = twilioErrorFields(error);
146
+ return { error: fields.message, valid: false };
147
+ }
148
+ }
149
+ }
212
150
  exports.TwilioVerifyProvider = TwilioVerifyProvider;
package/dist/commsApp.js CHANGED
@@ -1,53 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommsApp = exports.getCommsService = void 0;
4
- var api_1 = require("@terreno/api");
5
- var commsService_1 = require("./commsService");
6
- var pushToken_1 = require("./models/pushToken");
7
- var commsDashboard_1 = require("./routes/commsDashboard");
8
- var pushTokens_1 = require("./routes/pushTokens");
9
- var sendgridWebhooks_1 = require("./webhooks/sendgridWebhooks");
10
- var twilioWebhooks_1 = require("./webhooks/twilioWebhooks");
11
- var registeredCommsService;
12
- var getCommsService = function () {
4
+ const api_1 = require("@terreno/api");
5
+ const commsService_1 = require("./commsService");
6
+ const pushToken_1 = require("./models/pushToken");
7
+ const commsDashboard_1 = require("./routes/commsDashboard");
8
+ const pushTokens_1 = require("./routes/pushTokens");
9
+ const sendgridWebhooks_1 = require("./webhooks/sendgridWebhooks");
10
+ const twilioWebhooks_1 = require("./webhooks/twilioWebhooks");
11
+ let registeredCommsService;
12
+ const getCommsService = () => {
13
13
  if (!registeredCommsService) {
14
14
  throw new api_1.APIError({ status: 500, title: "CommsApp is not registered" });
15
15
  }
16
16
  return registeredCommsService;
17
17
  };
18
18
  exports.getCommsService = getCommsService;
19
- var CommsApp = /** @class */ (function () {
20
- function CommsApp(options) {
21
- this.options = options !== null && options !== void 0 ? options : {};
19
+ class CommsApp {
20
+ service;
21
+ options;
22
+ constructor(options) {
23
+ this.options = options ?? {};
22
24
  this.service = new commsService_1.CommsService(this.options);
23
25
  }
24
- CommsApp.prototype.register = function (app, openApi) {
25
- var _a;
26
- var basePath = (_a = this.options.basePath) !== null && _a !== void 0 ? _a : "/comms";
26
+ register(app, openApi) {
27
+ const basePath = this.options.basePath ?? "/comms";
27
28
  registeredCommsService = this.service;
28
29
  // Atomic push-token registration depends on the unique token index to reject concurrent
29
30
  // claims, so build it explicitly instead of relying on Mongoose autoIndex being enabled.
30
- void pushToken_1.PushToken.init().catch(function (error) {
31
- api_1.logger.error("[comms] Failed to build PushToken indexes; concurrent token registration cannot be " +
32
- "rejected safely until the unique token index exists: ".concat(String(error)));
31
+ void pushToken_1.PushToken.init().catch((error) => {
32
+ api_1.logger.error(`[comms] Failed to build PushToken indexes; concurrent token registration cannot be ` +
33
+ `rejected safely until the unique token index exists: ${String(error)}`);
33
34
  });
34
- (0, pushTokens_1.addPushTokenRoutes)(app, { basePath: "".concat(basePath, "/pushTokens"), openApi: openApi });
35
- (0, commsDashboard_1.addCommsDashboardRoutes)(app, { basePath: basePath, openApi: openApi, service: this.service });
35
+ (0, pushTokens_1.addPushTokenRoutes)(app, { basePath: `${basePath}/pushTokens`, openApi });
36
+ (0, commsDashboard_1.addCommsDashboardRoutes)(app, { basePath, openApi, service: this.service });
36
37
  (0, twilioWebhooks_1.maybeRegisterTwilioCommsWebhooks)({
37
- basePath: basePath,
38
+ basePath,
38
39
  publicUrl: this.options.webhookPublicUrl,
39
40
  service: this.service,
40
41
  sms: this.options.sms,
41
42
  webhooks: this.options.webhooks,
42
43
  });
43
44
  (0, sendgridWebhooks_1.maybeRegisterSendGridCommsWebhooks)({
44
- basePath: basePath,
45
+ basePath,
45
46
  mail: this.options.mail,
46
47
  service: this.service,
47
48
  webhooks: this.options.webhooks,
48
49
  });
49
- };
50
- CommsApp.prototype.adminContribution = function () {
50
+ }
51
+ adminContribution() {
51
52
  return {
52
53
  customScreens: [
53
54
  {
@@ -57,7 +58,6 @@ var CommsApp = /** @class */ (function () {
57
58
  },
58
59
  ],
59
60
  };
60
- };
61
- return CommsApp;
62
- }());
61
+ }
62
+ }
63
63
  exports.CommsApp = CommsApp;
@@ -4,21 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildCommsMessageMatch = exports.defaultStatsRange = exports.parseRetryManyLimit = exports.parseCommsListPagination = exports.parseCommsListFilters = void 0;
7
- var api_1 = require("@terreno/api");
8
- var luxon_1 = require("luxon");
9
- var mongoose_1 = __importDefault(require("mongoose"));
10
- var DEFAULT_LIMIT = 20;
11
- var MAX_LIMIT = 100;
12
- var DEFAULT_STATS_DAYS = 7;
13
- var escapeRegex = function (value) { return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); };
14
- var queryString = function (value) {
7
+ const api_1 = require("@terreno/api");
8
+ const luxon_1 = require("luxon");
9
+ const mongoose_1 = __importDefault(require("mongoose"));
10
+ const DEFAULT_LIMIT = 20;
11
+ const MAX_LIMIT = 100;
12
+ const DEFAULT_STATS_DAYS = 7;
13
+ const escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14
+ const queryString = (value) => {
15
15
  if (typeof value !== "string") {
16
16
  return undefined;
17
17
  }
18
- var trimmed = value.trim();
18
+ const trimmed = value.trim();
19
19
  return trimmed.length > 0 ? trimmed : undefined;
20
20
  };
21
- var parseCommsListFilters = function (source) { return ({
21
+ const parseCommsListFilters = (source) => ({
22
22
  channel: queryString(source.channel),
23
23
  endDate: queryString(source.endDate),
24
24
  errorClass: queryString(source.errorClass),
@@ -31,38 +31,37 @@ var parseCommsListFilters = function (source) { return ({
31
31
  templateId: queryString(source.templateId),
32
32
  to: queryString(source.to),
33
33
  userId: queryString(source.userId),
34
- }); };
34
+ });
35
35
  exports.parseCommsListFilters = parseCommsListFilters;
36
- var parseCommsListPagination = function (source) {
37
- var _a, _b;
38
- var page = Math.max(1, Number.parseInt(String((_a = source.page) !== null && _a !== void 0 ? _a : ""), 10) || 1);
39
- var limit = Math.min(MAX_LIMIT, Math.max(1, Number.parseInt(String((_b = source.limit) !== null && _b !== void 0 ? _b : ""), 10) || DEFAULT_LIMIT));
40
- return { limit: limit, page: page, skip: (page - 1) * limit };
36
+ const parseCommsListPagination = (source) => {
37
+ const page = Math.max(1, Number.parseInt(String(source.page ?? ""), 10) || 1);
38
+ const limit = Math.min(MAX_LIMIT, Math.max(1, Number.parseInt(String(source.limit ?? ""), 10) || DEFAULT_LIMIT));
39
+ return { limit, page, skip: (page - 1) * limit };
41
40
  };
42
41
  exports.parseCommsListPagination = parseCommsListPagination;
43
- var parseRetryManyLimit = function (value) {
44
- var parsed = Number.parseInt(String(value !== null && value !== void 0 ? value : ""), 10);
42
+ const parseRetryManyLimit = (value) => {
43
+ const parsed = Number.parseInt(String(value ?? ""), 10);
45
44
  if (Number.isNaN(parsed)) {
46
45
  return MAX_LIMIT;
47
46
  }
48
47
  return Math.min(MAX_LIMIT, Math.max(1, parsed));
49
48
  };
50
49
  exports.parseRetryManyLimit = parseRetryManyLimit;
51
- var parseIsoDate = function (value, field) {
52
- var parsed = luxon_1.DateTime.fromISO(value, { zone: "utc" });
50
+ const parseIsoDate = (value, field) => {
51
+ const parsed = luxon_1.DateTime.fromISO(value, { zone: "utc" });
53
52
  if (!parsed.isValid) {
54
- throw new api_1.APIError({ status: 400, title: "Invalid ".concat(field, " format") });
53
+ throw new api_1.APIError({ status: 400, title: `Invalid ${field} format` });
55
54
  }
56
55
  return parsed;
57
56
  };
58
57
  /** @internal */
59
- var defaultStatsRange = function () {
60
- var endDate = luxon_1.DateTime.utc();
61
- return { endDate: endDate, startDate: endDate.minus({ days: DEFAULT_STATS_DAYS }) };
58
+ const defaultStatsRange = () => {
59
+ const endDate = luxon_1.DateTime.utc();
60
+ return { endDate, startDate: endDate.minus({ days: DEFAULT_STATS_DAYS }) };
62
61
  };
63
62
  exports.defaultStatsRange = defaultStatsRange;
64
- var buildCommsMessageMatch = function (filters, options) {
65
- var match = {
63
+ const buildCommsMessageMatch = (filters, options) => {
64
+ const match = {
66
65
  deleted: { $ne: true },
67
66
  };
68
67
  if (filters.channel) {
@@ -98,10 +97,10 @@ var buildCommsMessageMatch = function (filters, options) {
98
97
  }
99
98
  match.retriedFromId = new mongoose_1.default.Types.ObjectId(filters.retriedFromId);
100
99
  }
101
- var start = filters.startDate ? parseIsoDate(filters.startDate, "startDate") : undefined;
102
- var end = filters.endDate ? parseIsoDate(filters.endDate, "endDate") : undefined;
103
- if ((options === null || options === void 0 ? void 0 : options.applyDefaultStatsRange) && !start && !end) {
104
- var range = (0, exports.defaultStatsRange)();
100
+ let start = filters.startDate ? parseIsoDate(filters.startDate, "startDate") : undefined;
101
+ let end = filters.endDate ? parseIsoDate(filters.endDate, "endDate") : undefined;
102
+ if (options?.applyDefaultStatsRange && !start && !end) {
103
+ const range = (0, exports.defaultStatsRange)();
105
104
  start = range.startDate;
106
105
  end = range.endDate;
107
106
  }
@@ -118,15 +117,15 @@ var buildCommsMessageMatch = function (filters, options) {
118
117
  }
119
118
  }
120
119
  if (filters.q) {
121
- var escaped = escapeRegex(filters.q);
122
- var clauses = [
120
+ const escaped = escapeRegex(filters.q);
121
+ const clauses = [
123
122
  { subject: { $options: "i", $regex: escaped } },
124
123
  { error: { $options: "i", $regex: escaped } },
125
124
  { to: { $options: "i", $regex: escaped } },
126
125
  ];
127
- var last4 = filters.q.replace(/\s/g, "");
126
+ const last4 = filters.q.replace(/\s/g, "");
128
127
  if (/^[A-Za-z0-9]{4}$/.test(last4)) {
129
- clauses.push({ to: { $options: "i", $regex: "".concat(escapeRegex(last4), "$") } });
128
+ clauses.push({ to: { $options: "i", $regex: `${escapeRegex(last4)}$` } });
130
129
  }
131
130
  match.$or = clauses;
132
131
  }
@@ -1,24 +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
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.serializeCommsMessage = exports.throwRetryBlock = exports.evaluateRetryBlock = void 0;
15
- var api_1 = require("@terreno/api");
16
- var luxon_1 = require("luxon");
17
- var COMMS_RETRY_NOT_RETRYABLE = "comms-retry-not-retryable";
18
- var COMMS_RETRY_PAYLOAD_EXPIRED = "comms-retry-payload-expired";
19
- var COMMS_RETRY_CHANNEL_UNCONFIGURED = "comms-retry-channel-unconfigured";
20
- var RETRYABLE_STATUSES = new Set(["bounced", "failed"]);
21
- var isPayloadPresent = function (message) {
4
+ const api_1 = require("@terreno/api");
5
+ const luxon_1 = require("luxon");
6
+ const COMMS_RETRY_NOT_RETRYABLE = "comms-retry-not-retryable";
7
+ const COMMS_RETRY_PAYLOAD_EXPIRED = "comms-retry-payload-expired";
8
+ const COMMS_RETRY_CHANNEL_UNCONFIGURED = "comms-retry-channel-unconfigured";
9
+ const RETRYABLE_STATUSES = new Set(["bounced", "failed"]);
10
+ const isPayloadPresent = (message) => {
22
11
  if (message.payload === undefined || message.payload === null) {
23
12
  return false;
24
13
  }
@@ -27,8 +16,7 @@ var isPayloadPresent = function (message) {
27
16
  }
28
17
  return true;
29
18
  };
30
- var evaluateRetryBlock = function (_a) {
31
- var isChannelConfigured = _a.isChannelConfigured, message = _a.message;
19
+ const evaluateRetryBlock = ({ isChannelConfigured, message, }) => {
32
20
  if (message.channel === "verification") {
33
21
  return {
34
22
  code: COMMS_RETRY_NOT_RETRYABLE,
@@ -62,7 +50,7 @@ var evaluateRetryBlock = function (_a) {
62
50
  return undefined;
63
51
  };
64
52
  exports.evaluateRetryBlock = evaluateRetryBlock;
65
- var throwRetryBlock = function (block) {
53
+ const throwRetryBlock = (block) => {
66
54
  throw new api_1.APIError({
67
55
  code: block.code,
68
56
  status: 400,
@@ -70,9 +58,13 @@ var throwRetryBlock = function (block) {
70
58
  });
71
59
  };
72
60
  exports.throwRetryBlock = throwRetryBlock;
73
- var serializeCommsMessage = function (message, isChannelConfigured) {
74
- var json = message.toJSON();
75
- var block = (0, exports.evaluateRetryBlock)({ isChannelConfigured: isChannelConfigured, message: message });
76
- return __assign(__assign({}, json), { retryable: !block, retryDisabledReason: block === null || block === void 0 ? void 0 : block.title });
61
+ const serializeCommsMessage = (message, isChannelConfigured) => {
62
+ const json = message.toJSON();
63
+ const block = (0, exports.evaluateRetryBlock)({ isChannelConfigured, message });
64
+ return {
65
+ ...json,
66
+ retryable: !block,
67
+ retryDisabledReason: block?.title,
68
+ };
77
69
  };
78
70
  exports.serializeCommsMessage = serializeCommsMessage;