@openclaw/sms 2026.10.10-beta.5 → 2026.11.5-beta.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/dist/.setup/{media-BIjSnGTm.mjs → media-BF6-nsm2.mjs} +17 -34
- package/dist/.setup/{runtime-BBlPgBIF.mjs → runtime-A8rnEOmw.mjs} +1 -2
- package/dist/.setup/{secret-contract-B2P_lFGm.mjs → secret-contract-BTxRnkG1.mjs} +1 -2
- package/dist/.setup/{twilio-BvmfwtSb.mjs → twilio-07yIWayE.mjs} +42 -95
- package/dist/.source-module-urls/795a0e3f2ca7aa49f58abd6277a5075ff6437cd84711eea7629da8f4ff8f2b43.json +1 -1
- package/dist/api.js +1 -1
- package/dist/channel-plugin-api.js +295 -388
- package/dist/configured-state.js +1 -2
- package/dist/index.js +1 -2
- package/dist/secret-contract-api.js +1 -1
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as getSmsRuntime } from "./runtime-
|
|
2
|
-
import { h as assertSmsCredentialOwnerAvailable, n as TWILIO_MMS_MAX_BYTES } from "./twilio-
|
|
1
|
+
import { t as getSmsRuntime } from "./runtime-A8rnEOmw.mjs";
|
|
2
|
+
import { h as assertSmsCredentialOwnerAvailable, n as TWILIO_MMS_MAX_BYTES } from "./twilio-07yIWayE.mjs";
|
|
3
3
|
import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
|
|
4
4
|
import { resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
@@ -9,7 +9,7 @@ import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
|
|
|
9
9
|
import { MediaFetchError, unlinkIfExists } from "openclaw/plugin-sdk/media-runtime";
|
|
10
10
|
import { createHostedOutboundMediaStore, resolveHostedOutboundMediaRequest, resolveOutboundMediaAccess } from "openclaw/plugin-sdk/outbound-media";
|
|
11
11
|
import { isTransientNetworkError } from "openclaw/plugin-sdk/retry-runtime";
|
|
12
|
-
|
|
12
|
+
// extensions/sms/src/media.ts
|
|
13
13
|
const TWILIO_API_HOSTNAME = "api.twilio.com";
|
|
14
14
|
const TWILIO_MEDIA_PATH_RE = /^\/2010-04-01\/Accounts\/([^/]+)\/Messages\/([^/]+)\/Media\/(ME[0-9a-fA-F]{32})$/u;
|
|
15
15
|
const TWILIO_MEDIA_TOTAL_TIMEOUT_MS = 6e4;
|
|
@@ -149,7 +149,6 @@ async function prepareHostedSmsMedia(params) {
|
|
|
149
149
|
});
|
|
150
150
|
const store = getHostedSmsMediaStore(params.account.accountId);
|
|
151
151
|
const captionByteLength = params.captionByteLength ?? 0;
|
|
152
|
-
if (!Number.isSafeInteger(captionByteLength) || captionByteLength < 0) throw new Error("MMS caption byte length must be a non-negative integer.");
|
|
153
152
|
const aggregateMediaBudget = TWILIO_MMS_IMAGE_MAX_BYTES - captionByteLength - 1;
|
|
154
153
|
if (aggregateMediaBudget < 1) throw new Error("Twilio MMS caption leaves no room for an attachment below 5,000,000 bytes.");
|
|
155
154
|
const stagedUrl = new URL(await store.prepareUrl({
|
|
@@ -157,32 +156,20 @@ async function prepareHostedSmsMedia(params) {
|
|
|
157
156
|
routePath: route.localRoutePath,
|
|
158
157
|
publicBaseUrl: route.publicBaseUrl,
|
|
159
158
|
maxBytes: Math.min(params.account.mediaMaxBytes ?? aggregateMediaBudget, aggregateMediaBudget),
|
|
160
|
-
mediaAccess: resolveOutboundMediaAccess(params)
|
|
159
|
+
mediaAccess: resolveOutboundMediaAccess(params),
|
|
160
|
+
validateBeforePersist: (media) => {
|
|
161
|
+
const contentType = media.contentType?.split(";", 1)[0]?.trim().toLowerCase();
|
|
162
|
+
if (!contentType || !Object.hasOwn(TWILIO_MMS_EXTENSION_BY_TYPE, contentType)) throw new Error(`Twilio MMS does not support media type ${contentType || "unknown content type"}.`);
|
|
163
|
+
if (captionByteLength > 0 && TWILIO_MMS_MEDIA_ONLY_TYPES.has(contentType)) throw new Error(`Twilio MMS media type ${contentType} must be sent without a caption.`);
|
|
164
|
+
const maxBytes = TWILIO_MMS_LARGE_MEDIA_TYPES.has(contentType) ? TWILIO_MMS_IMAGE_MAX_BYTES : TWILIO_MMS_OTHER_MAX_BYTES;
|
|
165
|
+
if (media.buffer.byteLength > maxBytes) throw new Error(`Twilio MMS media exceeds the ${maxBytes.toLocaleString("en-US")} byte limit for ${contentType}.`);
|
|
166
|
+
if (media.buffer.byteLength + captionByteLength >= TWILIO_MMS_IMAGE_MAX_BYTES) throw new Error("Twilio MMS attachment and caption must total less than 5,000,000 bytes.");
|
|
167
|
+
}
|
|
161
168
|
}));
|
|
162
169
|
const id = stagedUrl.pathname.split("/").at(-1) ?? "";
|
|
163
170
|
const token = stagedUrl.searchParams.get("token");
|
|
164
171
|
if (!SMS_OUTBOUND_MEDIA_ID_RE.test(id) || !token) throw new Error("Hosted MMS media URL could not be prepared.");
|
|
165
172
|
const cleanup = () => store.delete(id);
|
|
166
|
-
const entry = await store.read(id);
|
|
167
|
-
if (!entry) throw new Error("Hosted MMS media expired before it could be sent.");
|
|
168
|
-
const contentType = entry.metadata.contentType?.split(";", 1)[0]?.trim().toLowerCase();
|
|
169
|
-
if (!contentType || !Object.hasOwn(TWILIO_MMS_EXTENSION_BY_TYPE, contentType)) {
|
|
170
|
-
await cleanup();
|
|
171
|
-
throw new Error(`Twilio MMS does not support media type ${contentType || "unknown content type"}.`);
|
|
172
|
-
}
|
|
173
|
-
if (captionByteLength > 0 && TWILIO_MMS_MEDIA_ONLY_TYPES.has(contentType)) {
|
|
174
|
-
await cleanup();
|
|
175
|
-
throw new Error(`Twilio MMS media type ${contentType} must be sent without a caption.`);
|
|
176
|
-
}
|
|
177
|
-
const maxBytes = TWILIO_MMS_LARGE_MEDIA_TYPES.has(contentType) ? TWILIO_MMS_IMAGE_MAX_BYTES : TWILIO_MMS_OTHER_MAX_BYTES;
|
|
178
|
-
if (entry.metadata.byteLength > maxBytes) {
|
|
179
|
-
await cleanup();
|
|
180
|
-
throw new Error(`Twilio MMS media exceeds the ${maxBytes.toLocaleString("en-US")} byte limit for ${contentType || "unknown content type"}.`);
|
|
181
|
-
}
|
|
182
|
-
if (entry.metadata.byteLength + captionByteLength >= TWILIO_MMS_IMAGE_MAX_BYTES) {
|
|
183
|
-
await cleanup();
|
|
184
|
-
throw new Error("Twilio MMS attachment and caption must total less than 5,000,000 bytes.");
|
|
185
|
-
}
|
|
186
173
|
const tokenParam = `${SMS_OUTBOUND_MEDIA_TOKEN_PARAM_PREFIX}_${id}`;
|
|
187
174
|
const querySeparator = route.publicSearch ? "&" : "?";
|
|
188
175
|
return {
|
|
@@ -235,19 +222,16 @@ async function materializeSmsInboundMedia(params) {
|
|
|
235
222
|
const savedPaths = [];
|
|
236
223
|
const cleanup = createInboundMediaCleanup(savedPaths);
|
|
237
224
|
const declaredUnavailableCount = params.msg.unavailableMediaCount ?? 0;
|
|
238
|
-
|
|
239
|
-
body:
|
|
225
|
+
const withoutMedia = (count) => ({
|
|
226
|
+
body: count > 0 ? inboundMediaUnavailableBody(params.msg.body, count) : params.msg.body,
|
|
240
227
|
media: [],
|
|
241
228
|
cleanup
|
|
242
|
-
};
|
|
229
|
+
});
|
|
230
|
+
if (params.msg.media.length === 0) return withoutMedia(declaredUnavailableCount);
|
|
243
231
|
const callbackAccountSid = params.msg.accountSid;
|
|
244
232
|
if (!callbackAccountSid || callbackAccountSid !== params.account.accountSid) {
|
|
245
233
|
params.log?.warn?.(`Refused Twilio MMS attachments for ${params.msg.messageSid}: webhook account mismatch`);
|
|
246
|
-
return
|
|
247
|
-
body: inboundMediaUnavailableBody(params.msg.body, declaredUnavailableCount + params.msg.media.length),
|
|
248
|
-
media: [],
|
|
249
|
-
cleanup
|
|
250
|
-
};
|
|
234
|
+
return withoutMedia(declaredUnavailableCount + params.msg.media.length);
|
|
251
235
|
}
|
|
252
236
|
let remainingBytes = TWILIO_MMS_MAX_BYTES;
|
|
253
237
|
let unavailableCount = declaredUnavailableCount;
|
|
@@ -367,5 +351,4 @@ async function tryHandleHostedSmsMediaRequest(req, res, accountId = "default") {
|
|
|
367
351
|
res.end(body);
|
|
368
352
|
return true;
|
|
369
353
|
}
|
|
370
|
-
//#endregion
|
|
371
354
|
export { materializeSmsInboundMedia, prepareHostedSmsMedia, tryHandleHostedSmsMediaRequest };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
|
|
2
|
-
|
|
2
|
+
// extensions/sms/src/runtime.ts
|
|
3
3
|
const { setRuntime: setSmsRuntime, getRuntime: getSmsRuntime } = createPluginRuntimeStore({
|
|
4
4
|
pluginId: "sms",
|
|
5
5
|
errorMessage: "SMS runtime not initialized - plugin not registered"
|
|
6
6
|
});
|
|
7
|
-
//#endregion
|
|
8
7
|
export { setSmsRuntime as n, getSmsRuntime as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { collectConditionalChannelFieldAssignments, createChannelSecretContract, hasOwnProperty } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
|
|
2
|
-
|
|
2
|
+
// extensions/sms/src/secret-contract.ts
|
|
3
3
|
const DEFAULT_ACCOUNT_ID = "default";
|
|
4
4
|
function hasTopLevelSmsAccount(channel) {
|
|
5
5
|
return [
|
|
@@ -38,5 +38,4 @@ const channelSecrets = createChannelSecretContract({
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
const { secretTargetRegistryEntries, collectRuntimeConfigAssignments } = channelSecrets;
|
|
41
|
-
//#endregion
|
|
42
41
|
export { collectRuntimeConfigAssignments as n, secretTargetRegistryEntries as r, channelSecrets as t };
|
|
@@ -9,7 +9,6 @@ import { isIP } from "node:net";
|
|
|
9
9
|
import { fetchWithSsrFGuard, isBlockedHostnameOrIp } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
10
10
|
import { createHmac } from "node:crypto";
|
|
11
11
|
import * as querystring from "node:querystring";
|
|
12
|
-
import { captureEffectAuthority } from "openclaw/plugin-sdk/fetch-runtime";
|
|
13
12
|
import { redactToolPayloadText } from "openclaw/plugin-sdk/logging-core";
|
|
14
13
|
import { readResponseTextPrefix, readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
|
|
15
14
|
import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
|
|
@@ -17,7 +16,7 @@ import { safeParseJson } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
|
17
16
|
import { readRequestBodyWithLimit } from "openclaw/plugin-sdk/webhook-ingress";
|
|
18
17
|
import { assertSecretOwnerAvailable } from "openclaw/plugin-sdk/channel-secret-owner-runtime";
|
|
19
18
|
import { getRuntimeConfigSnapshot } from "openclaw/plugin-sdk/runtime-config-snapshot";
|
|
20
|
-
|
|
19
|
+
// extensions/sms/src/phone.ts
|
|
21
20
|
function normalizeSmsPhoneNumber(raw) {
|
|
22
21
|
const trimmed = raw.trim().replace(/^(?:sms|twilio-sms):/i, "").trim();
|
|
23
22
|
if (!trimmed) return "";
|
|
@@ -31,8 +30,7 @@ function normalizeSmsAllowFrom(raw) {
|
|
|
31
30
|
if (raw.trim() === "*") return "*";
|
|
32
31
|
return normalizeSmsPhoneNumber(raw);
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
//#region extensions/sms/src/public-webhook-url.ts
|
|
33
|
+
// extensions/sms/src/public-webhook-url.ts
|
|
36
34
|
const SMS_STATUS_CALLBACK_MAX_LENGTH = 4e3;
|
|
37
35
|
const SMS_STATUS_CALLBACK_READ_TIMEOUT_MS = 5e3;
|
|
38
36
|
const TWILIO_READ_TIMEOUT_MIN_MS = 100;
|
|
@@ -98,8 +96,7 @@ function resolveTwilioStatusCallbackUrl(publicWebhookUrl) {
|
|
|
98
96
|
if (callbackUrl.length > SMS_STATUS_CALLBACK_MAX_LENGTH) return "";
|
|
99
97
|
return callbackUrl;
|
|
100
98
|
}
|
|
101
|
-
|
|
102
|
-
//#region extensions/sms/src/accounts.ts
|
|
99
|
+
// extensions/sms/src/accounts.ts
|
|
103
100
|
const CHANNEL_ID = "sms";
|
|
104
101
|
const DEFAULT_WEBHOOK_PATH = "/webhooks/sms";
|
|
105
102
|
const DEFAULT_TEXT_CHUNK_LIMIT = 1500;
|
|
@@ -200,8 +197,7 @@ function inspectSmsAccount(cfg, accountId) {
|
|
|
200
197
|
function isSmsAccountConfigured(account) {
|
|
201
198
|
return Boolean(account.accountSid && account.authToken && (account.fromNumber || account.messagingServiceSid));
|
|
202
199
|
}
|
|
203
|
-
|
|
204
|
-
//#region extensions/sms/src/credential-availability.ts
|
|
200
|
+
// extensions/sms/src/credential-availability.ts
|
|
205
201
|
function assertSmsCredentialOwnerAvailable(account) {
|
|
206
202
|
assertSecretOwnerAvailable("account", `sms:${account.accountId}`);
|
|
207
203
|
const runtimeConfig = getRuntimeConfigSnapshot();
|
|
@@ -209,8 +205,7 @@ function assertSmsCredentialOwnerAvailable(account) {
|
|
|
209
205
|
const current = resolveSmsAccount(runtimeConfig, account.accountId);
|
|
210
206
|
if (current.accountSid !== account.accountSid || current.authToken !== account.authToken) throw new Error(`SMS credentials changed for ${account.accountId}; retry the operation.`);
|
|
211
207
|
}
|
|
212
|
-
|
|
213
|
-
//#region extensions/sms/src/twilio.ts
|
|
208
|
+
// extensions/sms/src/twilio.ts
|
|
214
209
|
const TWILIO_ACCOUNTS_URL = "https://api.twilio.com/2010-04-01/Accounts";
|
|
215
210
|
const TWILIO_MESSAGING_URL = "https://messaging.twilio.com/v1";
|
|
216
211
|
const TWILIO_API_HOSTNAME = "api.twilio.com";
|
|
@@ -238,14 +233,6 @@ function firstStringish(value) {
|
|
|
238
233
|
if (typeof first === "string") return first;
|
|
239
234
|
return typeof first === "number" ? String(first) : "";
|
|
240
235
|
}
|
|
241
|
-
function parseTwilioApiError(text) {
|
|
242
|
-
const record = asNullableObjectRecord(safeParseJson(text));
|
|
243
|
-
if (!record) return {};
|
|
244
|
-
return {
|
|
245
|
-
code: typeof record.code === "number" ? record.code : void 0,
|
|
246
|
-
message: typeof record.message === "string" ? record.message : void 0
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
236
|
function parseTwilioSuccessPayload(text) {
|
|
250
237
|
if (!text.trim()) return {};
|
|
251
238
|
let parsed;
|
|
@@ -263,49 +250,27 @@ function parseTwilioSuccessPayload(text) {
|
|
|
263
250
|
status: typeof record.status === "string" ? record.status : void 0
|
|
264
251
|
};
|
|
265
252
|
}
|
|
266
|
-
function requestSearch(req) {
|
|
267
|
-
return URL.parse(req.url ?? "/", "http://localhost")?.search ?? "";
|
|
268
|
-
}
|
|
269
|
-
function stripUrlFragment(url) {
|
|
270
|
-
const hashIndex = url.indexOf("#");
|
|
271
|
-
return hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
272
|
-
}
|
|
273
253
|
function resolveTwilioWebhookSignatureUrl(params) {
|
|
274
|
-
const
|
|
254
|
+
const hashIndex = params.publicWebhookUrl.indexOf("#");
|
|
255
|
+
const signatureBaseUrl = hashIndex === -1 ? params.publicWebhookUrl : params.publicWebhookUrl.slice(0, hashIndex);
|
|
275
256
|
if (signatureBaseUrl.includes("?")) return signatureBaseUrl;
|
|
276
|
-
const search =
|
|
257
|
+
const search = URL.parse(params.req.url ?? "/", "http://localhost")?.search ?? "";
|
|
277
258
|
if (!search) return signatureBaseUrl;
|
|
278
259
|
return `${signatureBaseUrl}${search}`;
|
|
279
260
|
}
|
|
280
261
|
var TwilioSmsApiError = class extends Error {
|
|
281
262
|
constructor(httpStatus, responseText, operation = "send") {
|
|
282
263
|
const redactedResponseText = redactToolPayloadText(responseText);
|
|
283
|
-
const
|
|
284
|
-
const detail =
|
|
264
|
+
const record = asNullableObjectRecord(safeParseJson(redactedResponseText));
|
|
265
|
+
const detail = typeof record?.message === "string" ? record.message : redactedResponseText || "unknown";
|
|
285
266
|
super(`Twilio SMS ${operation} failed (${httpStatus}): ${detail}`);
|
|
286
267
|
this.name = "TwilioSmsApiError";
|
|
287
|
-
this.httpStatus = httpStatus;
|
|
288
|
-
this.responseText = redactedResponseText;
|
|
289
|
-
this.twilioCode = parsed.code;
|
|
290
268
|
}
|
|
291
269
|
};
|
|
292
|
-
function parseTwilioFormBody(body) {
|
|
293
|
-
const parsed = querystring.parse(body);
|
|
294
|
-
const out = {};
|
|
295
|
-
for (const [key, value] of Object.entries(parsed)) out[key] = firstString(value);
|
|
296
|
-
return out;
|
|
297
|
-
}
|
|
298
|
-
function computeTwilioSignature(params) {
|
|
299
|
-
const data = params.url + Object.keys(params.form).toSorted().map((key) => `${key}${params.form[key] ?? ""}`).join("");
|
|
300
|
-
return createHmac("sha1", params.authToken).update(data).digest("base64");
|
|
301
|
-
}
|
|
302
270
|
function verifyTwilioSignature(params) {
|
|
303
271
|
if (!params.signature || !params.url || !params.authToken) return false;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
authToken: params.authToken,
|
|
307
|
-
form: params.form
|
|
308
|
-
}));
|
|
272
|
+
const data = params.url + Object.keys(params.form).toSorted().map((key) => `${key}${params.form[key] ?? ""}`).join("");
|
|
273
|
+
return safeEqualSecret(params.signature, createHmac("sha1", params.authToken).update(data).digest("base64"));
|
|
309
274
|
}
|
|
310
275
|
function parseTwilioInboundFrom(raw) {
|
|
311
276
|
const trimmed = raw.trim();
|
|
@@ -359,11 +324,15 @@ function resolveTwilioMessageSid(form) {
|
|
|
359
324
|
return firstTrimmedString(form.MessageSid) || firstTrimmedString(form.SmsSid) || firstTrimmedString(form.SmsMessageSid);
|
|
360
325
|
}
|
|
361
326
|
async function readTwilioWebhookForm(req) {
|
|
362
|
-
|
|
327
|
+
const body = await readRequestBodyWithLimit(req, {
|
|
363
328
|
maxBytes: WEBHOOK_BODY_LIMIT_BYTES,
|
|
364
329
|
timeoutMs: WEBHOOK_BODY_TIMEOUT_MS,
|
|
365
330
|
destroyOnLimit: false
|
|
366
|
-
})
|
|
331
|
+
});
|
|
332
|
+
const parsed = querystring.parse(body);
|
|
333
|
+
const out = {};
|
|
334
|
+
for (const [key, value] of Object.entries(parsed)) out[key] = firstString(value);
|
|
335
|
+
return out;
|
|
367
336
|
}
|
|
368
337
|
const TWIML_CONTENT_TYPE = "text/xml; charset=utf-8";
|
|
369
338
|
function respondTwiml(res, statusCode, body = "") {
|
|
@@ -374,14 +343,11 @@ function respondTwiml(res, statusCode, body = "") {
|
|
|
374
343
|
function basicAuthHeader(account) {
|
|
375
344
|
return `Basic ${Buffer.from(`${account.accountSid}:${account.authToken}`).toString("base64")}`;
|
|
376
345
|
}
|
|
377
|
-
function appendTruncatedResponseSuffix(text) {
|
|
378
|
-
return `${text.trimEnd()}${TRUNCATED_RESPONSE_SUFFIX}`;
|
|
379
|
-
}
|
|
380
346
|
async function readTwilioApiResponseText(response) {
|
|
381
347
|
const maxBytes = response.ok ? TWILIO_API_SUCCESS_BODY_LIMIT_BYTES : TWILIO_API_ERROR_BODY_LIMIT_BYTES;
|
|
382
348
|
if (!response.ok) {
|
|
383
349
|
const prefix = await readResponseTextPrefix(response, maxBytes);
|
|
384
|
-
return prefix.truncated ?
|
|
350
|
+
return prefix.truncated ? `${prefix.text.trimEnd()}${TRUNCATED_RESPONSE_SUFFIX}` : prefix.text;
|
|
385
351
|
}
|
|
386
352
|
const body = await readResponseWithLimit(response, maxBytes, { onOverflow: ({ size, maxBytes: limit }) => /* @__PURE__ */ new Error(`Twilio SMS API response body too large: ${size} bytes (limit: ${limit} bytes)`) });
|
|
387
353
|
return new TextDecoder().decode(body);
|
|
@@ -404,32 +370,23 @@ async function requestTwilioApi(params) {
|
|
|
404
370
|
authorization: basicAuthHeader(params.account)
|
|
405
371
|
}
|
|
406
372
|
};
|
|
407
|
-
let
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
373
|
+
let requestDispatched = false;
|
|
374
|
+
const { response, release } = await fetchWithSsrFGuard({
|
|
375
|
+
url: url.toString(),
|
|
376
|
+
init,
|
|
377
|
+
beforeRequest: () => {
|
|
378
|
+
if (requestDispatched) {
|
|
379
|
+
assertSmsCredentialOwnerAvailable(params.account);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
assertTwilioRequestCredentialsAvailable(params.account);
|
|
383
|
+
requestDispatched = true;
|
|
384
|
+
},
|
|
385
|
+
auditContext: "sms-twilio-api",
|
|
386
|
+
policy: { allowedHostnames: [params.api === "accounts" ? TWILIO_API_HOSTNAME : TWILIO_MESSAGING_HOSTNAME] },
|
|
387
|
+
requireHttps: true,
|
|
388
|
+
timeoutMs: params.timeoutMs ?? TWILIO_API_TIMEOUT_MS
|
|
413
389
|
});
|
|
414
|
-
else {
|
|
415
|
-
let requestDispatched = false;
|
|
416
|
-
({response, release} = await fetchWithSsrFGuard({
|
|
417
|
-
url: url.toString(),
|
|
418
|
-
init,
|
|
419
|
-
beforeRequest: () => {
|
|
420
|
-
if (requestDispatched) {
|
|
421
|
-
assertSmsCredentialOwnerAvailable(params.account);
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
assertTwilioRequestCredentialsAvailable(params.account);
|
|
425
|
-
requestDispatched = true;
|
|
426
|
-
},
|
|
427
|
-
auditContext: "sms-twilio-api",
|
|
428
|
-
policy: { allowedHostnames: [params.api === "accounts" ? TWILIO_API_HOSTNAME : TWILIO_MESSAGING_HOSTNAME] },
|
|
429
|
-
requireHttps: true,
|
|
430
|
-
timeoutMs: params.timeoutMs ?? TWILIO_API_TIMEOUT_MS
|
|
431
|
-
}));
|
|
432
|
-
}
|
|
433
390
|
let ok;
|
|
434
391
|
let status;
|
|
435
392
|
let text;
|
|
@@ -437,14 +394,13 @@ async function requestTwilioApi(params) {
|
|
|
437
394
|
({ok, status} = response);
|
|
438
395
|
text = await readTwilioApiResponseText(response);
|
|
439
396
|
} finally {
|
|
440
|
-
|
|
397
|
+
await release();
|
|
441
398
|
}
|
|
442
399
|
if (!ok) throw new TwilioSmsApiError(status, text, params.operation);
|
|
443
400
|
return text;
|
|
444
401
|
}
|
|
445
402
|
function parseTwilioIncomingPhoneNumber(record) {
|
|
446
403
|
return {
|
|
447
|
-
sid: firstTrimmedString(record.sid),
|
|
448
404
|
phoneNumber: firstTrimmedString(record.phone_number ?? record.phoneNumber),
|
|
449
405
|
smsUrl: firstTrimmedString(record.sms_url ?? record.smsUrl),
|
|
450
406
|
smsMethod: firstTrimmedString(record.sms_method ?? record.smsMethod),
|
|
@@ -456,10 +412,7 @@ function parseTwilioMessageLogEntry(record) {
|
|
|
456
412
|
sid: firstTrimmedString(record.sid),
|
|
457
413
|
direction: firstTrimmedString(record.direction),
|
|
458
414
|
status: firstTrimmedString(record.status),
|
|
459
|
-
to: firstTrimmedString(record.to),
|
|
460
|
-
from: firstTrimmedString(record.from),
|
|
461
415
|
errorCode: firstStringish(record.error_code ?? record.errorCode).trim(),
|
|
462
|
-
body: firstString(record.body),
|
|
463
416
|
dateCreated: firstTrimmedString(record.date_created ?? record.dateCreated),
|
|
464
417
|
dateSent: firstTrimmedString(record.date_sent ?? record.dateSent)
|
|
465
418
|
};
|
|
@@ -478,15 +431,13 @@ function parseTwilioListPayload(text, key, parseEntry) {
|
|
|
478
431
|
return items.filter(isRecord).map(parseEntry);
|
|
479
432
|
}
|
|
480
433
|
async function listTwilioIncomingPhoneNumbers(params) {
|
|
481
|
-
const query = new URLSearchParams();
|
|
482
|
-
if (params.phoneNumber) query.set("PhoneNumber", params.phoneNumber);
|
|
434
|
+
const query = new URLSearchParams({ PhoneNumber: params.phoneNumber });
|
|
483
435
|
return parseTwilioListPayload(await requestTwilioApi({
|
|
484
436
|
account: params.account,
|
|
485
437
|
path: "/IncomingPhoneNumbers.json",
|
|
486
438
|
api: "accounts",
|
|
487
439
|
query,
|
|
488
440
|
operation: "phone-number lookup",
|
|
489
|
-
fetchImpl: params.fetchImpl,
|
|
490
441
|
timeoutMs: params.timeoutMs
|
|
491
442
|
}), "incoming_phone_numbers", parseTwilioIncomingPhoneNumber);
|
|
492
443
|
}
|
|
@@ -496,7 +447,6 @@ async function retrieveTwilioMessagingService(params) {
|
|
|
496
447
|
path: `/Services/${encodeURIComponent(params.serviceSid)}`,
|
|
497
448
|
api: "messaging",
|
|
498
449
|
operation: "messaging-service lookup",
|
|
499
|
-
fetchImpl: params.fetchImpl,
|
|
500
450
|
timeoutMs: params.timeoutMs
|
|
501
451
|
});
|
|
502
452
|
const parsed = safeParseJson(text);
|
|
@@ -504,17 +454,16 @@ async function retrieveTwilioMessagingService(params) {
|
|
|
504
454
|
return parseTwilioMessagingService(parsed);
|
|
505
455
|
}
|
|
506
456
|
async function listTwilioMessages(params) {
|
|
507
|
-
const query = new URLSearchParams(
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
457
|
+
const query = new URLSearchParams({
|
|
458
|
+
To: params.to,
|
|
459
|
+
PageSize: "3"
|
|
460
|
+
});
|
|
511
461
|
return parseTwilioListPayload(await requestTwilioApi({
|
|
512
462
|
account: params.account,
|
|
513
463
|
path: "/Messages.json",
|
|
514
464
|
api: "accounts",
|
|
515
465
|
query,
|
|
516
466
|
operation: "message lookup",
|
|
517
|
-
fetchImpl: params.fetchImpl,
|
|
518
467
|
timeoutMs: params.timeoutMs
|
|
519
468
|
}), "messages", parseTwilioMessageLogEntry);
|
|
520
469
|
}
|
|
@@ -542,8 +491,7 @@ async function sendSmsViaTwilio(params) {
|
|
|
542
491
|
account: params.account,
|
|
543
492
|
path: "/Messages.json",
|
|
544
493
|
api: "accounts",
|
|
545
|
-
init
|
|
546
|
-
fetchImpl: params.fetchImpl
|
|
494
|
+
init
|
|
547
495
|
}));
|
|
548
496
|
const sid = payload.sid?.trim();
|
|
549
497
|
if (!sid) throw new Error("Twilio SMS send response did not include a Message SID.");
|
|
@@ -554,5 +502,4 @@ async function sendSmsViaTwilio(params) {
|
|
|
554
502
|
...payload.status?.trim() ? { status: payload.status.trim() } : {}
|
|
555
503
|
};
|
|
556
504
|
}
|
|
557
|
-
//#endregion
|
|
558
505
|
export { normalizeSmsAllowFrom as C, looksLikeSmsPhoneNumber as S, isSmsAccountConfigured as _, listTwilioIncomingPhoneNumbers as a, resolveSmsAccount as b, resolveTwilioInboundSender as c, respondTwiml as d, retrieveTwilioMessagingService as f, inspectSmsAccount as g, assertSmsCredentialOwnerAvailable as h, buildTwilioInboundMessage as i, resolveTwilioMessageSid as l, verifyTwilioSignature as m, TWILIO_MMS_MAX_BYTES as n, listTwilioMessages as o, sendSmsViaTwilio as p, TWIML_CONTENT_TYPE as r, readTwilioWebhookForm as s, TWILIO_MESSAGE_BODY_MAX_LENGTH as t, resolveTwilioWebhookSignatureUrl as u, listSmsAccountIds as v, normalizeSmsPhoneNumber as w, resolveTwilioStatusCallbackUrl as x, resolveDefaultSmsAccountId as y };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"entries":[{"output":"api.js","source":"extensions/sms/api.ts"},{"output":"channel-plugin-api.js","source":"extensions/sms/channel-plugin-api.ts"},{"output":"configured-state.js","source":"extensions/sms/configured-state.ts"},{"output":"index.js","source":"extensions/sms/index.ts"},{"output":"secret-contract-api.js","source":"extensions/sms/secret-contract-api.ts"}],"chunks":[{"output":".setup/media-
|
|
1
|
+
{"version":3,"entries":[{"output":"api.js","source":"extensions/sms/api.ts"},{"output":"channel-plugin-api.js","source":"extensions/sms/channel-plugin-api.ts"},{"output":"configured-state.js","source":"extensions/sms/configured-state.ts"},{"output":"index.js","source":"extensions/sms/index.ts"},{"output":"secret-contract-api.js","source":"extensions/sms/secret-contract-api.ts"}],"chunks":[{"output":".setup/media-BF6-nsm2.mjs","sha256":"07c35be9a1b24339461d37b732b6f528382d20978d585347bb9c4ead05584f03","facadeSource":"extensions/sms/src/media.ts","sources":["extensions/sms/src/media.ts"]},{"output":".setup/runtime-A8rnEOmw.mjs","sha256":"c5421ac4c7b4a75bc7ecbc7c36ec291ca5fea32a88a3ee73d827805382709472","facadeSource":null,"sources":["extensions/sms/src/runtime.ts"]},{"output":".setup/secret-contract-BTxRnkG1.mjs","sha256":"41e6a81aa4b92fa9cc308365fd1b39f027966a6405817436e05ece5a86101289","facadeSource":null,"sources":["extensions/sms/src/secret-contract.ts"]},{"output":".setup/twilio-07yIWayE.mjs","sha256":"9273a6d10235c495f227ddc60d048943993b7caf377ce61f4544f9a29e826b3d","facadeSource":null,"sources":["extensions/sms/src/accounts.ts","extensions/sms/src/credential-availability.ts","extensions/sms/src/phone.ts","extensions/sms/src/public-webhook-url.ts","extensions/sms/src/twilio.ts"]},{"output":"api.js","sha256":"0af2cd7c6d77163e5a4b5db6d0a330cee812d376309fc5100549c96cfb418095","facadeSource":"extensions/sms/api.ts","sources":[]},{"output":"channel-plugin-api.js","sha256":"4611df19ace50e59be191fecfd82cd0ec2fcb5693b9b4871fa9b220f46cbb6d5","facadeSource":"extensions/sms/channel-plugin-api.ts","sources":["extensions/sms/src/channel.ts","extensions/sms/src/config-schema.ts","extensions/sms/src/delivery-observations.ts","extensions/sms/src/gateway.ts","extensions/sms/src/inbound.ts","extensions/sms/src/ingress-spool.ts","extensions/sms/src/send.ts","extensions/sms/src/status.ts","extensions/sms/src/webhook.ts"]},{"output":"configured-state.js","sha256":"e994ab7f874fa87b8fe6ebf177c463524d6eb38b18ce39c81782317ba58d0e33","facadeSource":"extensions/sms/configured-state.ts","sources":["extensions/sms/configured-state.ts"]},{"output":"index.js","sha256":"409b8e41876eb5f13f405dae29989f6208bc6dd05a3a3edca4c045694ed03f08","facadeSource":"extensions/sms/index.ts","sources":["extensions/sms/index.ts"]},{"output":"secret-contract-api.js","sha256":"52f719be12576c4abb7161253c960de8b5001fc164f5e69f7228e57c29a5aed2","facadeSource":"extensions/sms/secret-contract-api.ts","sources":[]}],"unrenderedSources":["extensions/sms/api.ts","extensions/sms/channel-plugin-api.ts","extensions/sms/secret-contract-api.ts"]}
|
package/dist/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as getSmsRuntime, n as setSmsRuntime } from "./.setup/runtime-
|
|
1
|
+
export { t as getSmsRuntime, n as setSmsRuntime } from "./.setup/runtime-A8rnEOmw.mjs";
|