@sinch/functions-runtime 0.7.3 → 0.7.4
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.
|
@@ -31261,8 +31261,8 @@ ${canonicalizedResource}`;
|
|
|
31261
31261
|
}
|
|
31262
31262
|
return true;
|
|
31263
31263
|
};
|
|
31264
|
-
var getHeader = (
|
|
31265
|
-
return Array.isArray(
|
|
31264
|
+
var getHeader = (headerValue2) => {
|
|
31265
|
+
return Array.isArray(headerValue2) ? headerValue2[0] : headerValue2;
|
|
31266
31266
|
};
|
|
31267
31267
|
}
|
|
31268
31268
|
});
|
|
@@ -57144,7 +57144,7 @@ var require_websocket = __commonJS({
|
|
|
57144
57144
|
var http3 = __require("http");
|
|
57145
57145
|
var net = __require("net");
|
|
57146
57146
|
var tls = __require("tls");
|
|
57147
|
-
var { randomBytes
|
|
57147
|
+
var { randomBytes, createHash: createHash2 } = __require("crypto");
|
|
57148
57148
|
var { Duplex, Readable: Readable3 } = __require("stream");
|
|
57149
57149
|
var { URL: URL3 } = __require("url");
|
|
57150
57150
|
var PerMessageDeflate = require_permessage_deflate();
|
|
@@ -57671,7 +57671,7 @@ var require_websocket = __commonJS({
|
|
|
57671
57671
|
}
|
|
57672
57672
|
}
|
|
57673
57673
|
const defaultPort = isSecure ? 443 : 80;
|
|
57674
|
-
const key =
|
|
57674
|
+
const key = randomBytes(16).toString("base64");
|
|
57675
57675
|
const request = isSecure ? https3.request : http3.request;
|
|
57676
57676
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
57677
57677
|
let perMessageDeflate;
|
|
@@ -63040,7 +63040,6 @@ function installStdioRedaction() {
|
|
|
63040
63040
|
// ../runtime-shared/dist/security/voice-signature.js
|
|
63041
63041
|
import { createHash, createHmac as createHmac2, timingSafeEqual as timingSafeEqual3 } from "crypto";
|
|
63042
63042
|
var VOICE_TIMESTAMP_SKEW_MS = 5 * 60 * 1e3;
|
|
63043
|
-
var VOICE_MISSING_SECRET_WARNING = "Voice v2 webhook not verified: VOICE_SERVICE_SECRET is not set. Deploying sets it from the voice service; redeploy to turn verification on";
|
|
63044
63043
|
var AUTHORIZATION_PATTERN = /^service\s+([^:\s]+):(\S+)$/i;
|
|
63045
63044
|
function fail(reason) {
|
|
63046
63045
|
return { valid: false, reason };
|
|
@@ -63090,10 +63089,6 @@ function validateVoiceSignature(request, options) {
|
|
|
63090
63089
|
}
|
|
63091
63090
|
return { valid: true };
|
|
63092
63091
|
}
|
|
63093
|
-
var warnedMissingSecret = false;
|
|
63094
|
-
function resetVoiceSignatureWarning() {
|
|
63095
|
-
warnedMissingSecret = false;
|
|
63096
|
-
}
|
|
63097
63092
|
function verifyVoiceWebhook(request, options) {
|
|
63098
63093
|
if (!shouldValidateWebhook(options.mode, options.isDevelopment)) {
|
|
63099
63094
|
return { valid: true };
|
|
@@ -63101,11 +63096,7 @@ function verifyVoiceWebhook(request, options) {
|
|
|
63101
63096
|
const env = options.env ?? process.env;
|
|
63102
63097
|
const serviceSecret = env.VOICE_SERVICE_SECRET;
|
|
63103
63098
|
if (!serviceSecret) {
|
|
63104
|
-
|
|
63105
|
-
warnedMissingSecret = true;
|
|
63106
|
-
console.warn(`[SECURITY] ${VOICE_MISSING_SECRET_WARNING}`);
|
|
63107
|
-
}
|
|
63108
|
-
return { valid: true };
|
|
63099
|
+
return fail("VOICE_SERVICE_SECRET is not set");
|
|
63109
63100
|
}
|
|
63110
63101
|
return validateVoiceSignature(request, {
|
|
63111
63102
|
serviceSecret,
|
|
@@ -63114,6 +63105,50 @@ function verifyVoiceWebhook(request, options) {
|
|
|
63114
63105
|
});
|
|
63115
63106
|
}
|
|
63116
63107
|
|
|
63108
|
+
// ../runtime-shared/dist/security/conversation-signature.js
|
|
63109
|
+
import { createHmac as createHmac3, timingSafeEqual as timingSafeEqual4 } from "crypto";
|
|
63110
|
+
var SIGNATURE_HEADER = "x-sinch-webhook-signature";
|
|
63111
|
+
var NONCE_HEADER = "x-sinch-webhook-signature-nonce";
|
|
63112
|
+
var TIMESTAMP_HEADER = "x-sinch-webhook-signature-timestamp";
|
|
63113
|
+
function fail2(reason) {
|
|
63114
|
+
return { valid: false, reason };
|
|
63115
|
+
}
|
|
63116
|
+
function headerValue(headers, name) {
|
|
63117
|
+
const value = headers[name];
|
|
63118
|
+
return Array.isArray(value) ? value[0] : value;
|
|
63119
|
+
}
|
|
63120
|
+
function verifyConversationWebhook(request, options) {
|
|
63121
|
+
if (!shouldValidateWebhook(options.mode, options.isDevelopment)) {
|
|
63122
|
+
return { valid: true };
|
|
63123
|
+
}
|
|
63124
|
+
const env = options.env ?? process.env;
|
|
63125
|
+
const secret = env.CONVERSATION_WEBHOOK_SECRET;
|
|
63126
|
+
if (!secret) {
|
|
63127
|
+
return fail2("CONVERSATION_WEBHOOK_SECRET is not set");
|
|
63128
|
+
}
|
|
63129
|
+
const signature = headerValue(request.headers, SIGNATURE_HEADER);
|
|
63130
|
+
if (!signature) {
|
|
63131
|
+
return fail2(`${SIGNATURE_HEADER} header is missing`);
|
|
63132
|
+
}
|
|
63133
|
+
const nonce = headerValue(request.headers, NONCE_HEADER);
|
|
63134
|
+
if (!nonce) {
|
|
63135
|
+
return fail2(`${NONCE_HEADER} header is missing`);
|
|
63136
|
+
}
|
|
63137
|
+
const timestamp = headerValue(request.headers, TIMESTAMP_HEADER);
|
|
63138
|
+
if (!timestamp) {
|
|
63139
|
+
return fail2(`${TIMESTAMP_HEADER} header is missing`);
|
|
63140
|
+
}
|
|
63141
|
+
if (request.rawBody === void 0) {
|
|
63142
|
+
return fail2("raw body unavailable");
|
|
63143
|
+
}
|
|
63144
|
+
const expected = createHmac3("sha256", secret).update(`${request.rawBody}.${nonce}.${timestamp}`, "utf8").digest();
|
|
63145
|
+
const received = Buffer.from(signature, "base64");
|
|
63146
|
+
if (received.length !== expected.length || !timingSafeEqual4(received, expected)) {
|
|
63147
|
+
return fail2("signature mismatch");
|
|
63148
|
+
}
|
|
63149
|
+
return { valid: true };
|
|
63150
|
+
}
|
|
63151
|
+
|
|
63117
63152
|
// ../runtime-shared/dist/sinch/index.js
|
|
63118
63153
|
var import_sdk_core = __toESM(require_dist11(), 1);
|
|
63119
63154
|
function createSinchClients() {
|
|
@@ -63325,6 +63360,7 @@ function getFaviconSvg() {
|
|
|
63325
63360
|
var VOICE_V1_CALLBACKS = ["ice", "ace", "pie", "dice", "notify"];
|
|
63326
63361
|
var NOTIFICATION_EVENTS = ["dice", "notify"];
|
|
63327
63362
|
var VOICE_WEBHOOK_HANDLER = "voiceWebhook";
|
|
63363
|
+
var CONVERSATION_WEBHOOK_HANDLER = "conversationWebhook";
|
|
63328
63364
|
var VOICE_EVENT_PREFIX = "call.";
|
|
63329
63365
|
function isVoiceV1Callback(functionName) {
|
|
63330
63366
|
return VOICE_V1_CALLBACKS.includes(functionName);
|
|
@@ -63338,10 +63374,12 @@ function isVoiceEvent(event) {
|
|
|
63338
63374
|
function isVoiceWebhook(body) {
|
|
63339
63375
|
return isVoiceEvent(body?.event);
|
|
63340
63376
|
}
|
|
63377
|
+
var TUNNEL_VOICE_SIGNED_PATH_ENV = "SINCH_TUNNEL_VOICE_SIGNED_PATH";
|
|
63341
63378
|
function buildVoiceSignedRequest(req) {
|
|
63379
|
+
const registered = process.env.SINCH_TUNNEL === "true" ? process.env[TUNNEL_VOICE_SIGNED_PATH_ENV] : void 0;
|
|
63342
63380
|
return {
|
|
63343
63381
|
method: req.method,
|
|
63344
|
-
path: req.originalUrl.split("?")[0] || "/",
|
|
63382
|
+
path: registered || req.originalUrl.split("?")[0] || "/",
|
|
63345
63383
|
contentType: req.headers["content-type"],
|
|
63346
63384
|
timestamp: req.headers["x-timestamp"],
|
|
63347
63385
|
authorization: req.headers.authorization,
|
|
@@ -63771,14 +63809,6 @@ function setupRequestHandler(app, options = {}) {
|
|
|
63771
63809
|
return;
|
|
63772
63810
|
}
|
|
63773
63811
|
}
|
|
63774
|
-
if (functionName === "conversationWebhook" && sinchClients.validateConversationWebhook) {
|
|
63775
|
-
const isValid = sinchClients.validateConversationWebhook(req.headers, req.body);
|
|
63776
|
-
if (!isValid) {
|
|
63777
|
-
logger("[SECURITY] Conversation webhook signature validation failed");
|
|
63778
|
-
res.status(401).json({ error: "Invalid webhook signature" });
|
|
63779
|
-
return;
|
|
63780
|
-
}
|
|
63781
|
-
}
|
|
63782
63812
|
}
|
|
63783
63813
|
if (functionName === VOICE_WEBHOOK_HANDLER && isVoiceWebhook(req.body)) {
|
|
63784
63814
|
const verdict = verifyVoiceWebhook(buildVoiceSignedRequest(req), {
|
|
@@ -63791,6 +63821,14 @@ function setupRequestHandler(app, options = {}) {
|
|
|
63791
63821
|
return;
|
|
63792
63822
|
}
|
|
63793
63823
|
}
|
|
63824
|
+
if (functionName === CONVERSATION_WEBHOOK_HANDLER) {
|
|
63825
|
+
const verdict = verifyConversationWebhook({ headers: req.headers, rawBody: req.rawBody }, { mode: protectionMode, isDevelopment: isDev });
|
|
63826
|
+
if (!verdict.valid) {
|
|
63827
|
+
logger(`[SECURITY] Conversation webhook signature validation failed: ${verdict.reason}`);
|
|
63828
|
+
res.status(401).json({ error: "Invalid webhook signature" });
|
|
63829
|
+
return;
|
|
63830
|
+
}
|
|
63831
|
+
}
|
|
63794
63832
|
onRequestStart({ functionName, req });
|
|
63795
63833
|
const context = buildContext(req);
|
|
63796
63834
|
const request = {
|
|
@@ -67389,7 +67427,7 @@ function createResponsesWsSession(apiKey, baseUrl, factory2 = (key, url2) => new
|
|
|
67389
67427
|
cleanup();
|
|
67390
67428
|
resolve(result2);
|
|
67391
67429
|
};
|
|
67392
|
-
const
|
|
67430
|
+
const fail3 = (err) => {
|
|
67393
67431
|
cleanup();
|
|
67394
67432
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
67395
67433
|
};
|
|
@@ -67398,14 +67436,14 @@ function createResponsesWsSession(apiKey, baseUrl, factory2 = (key, url2) => new
|
|
|
67398
67436
|
clearTimeout(activeTimeout);
|
|
67399
67437
|
activeTimeout = setTimeout(() => {
|
|
67400
67438
|
failed = true;
|
|
67401
|
-
|
|
67439
|
+
fail3(new Error(`realtimeAgent: voice-relay provider WS ${label}`));
|
|
67402
67440
|
ws.close();
|
|
67403
67441
|
}, ms);
|
|
67404
67442
|
};
|
|
67405
67443
|
let producing = false;
|
|
67406
67444
|
activeOnEvent = (event) => {
|
|
67407
67445
|
if (event["type"] === "error") {
|
|
67408
|
-
|
|
67446
|
+
fail3(new Error(`realtimeAgent: voice-relay provider WS reported an error: ${JSON.stringify(event["error"] ?? event)}`));
|
|
67409
67447
|
return;
|
|
67410
67448
|
}
|
|
67411
67449
|
if (!producing && (event["type"] === "response.output_text.delta" || event["type"] === "response.output_item.added")) {
|
|
@@ -67417,7 +67455,7 @@ function createResponsesWsSession(apiKey, baseUrl, factory2 = (key, url2) => new
|
|
|
67417
67455
|
if (result2)
|
|
67418
67456
|
done(result2);
|
|
67419
67457
|
} catch (err) {
|
|
67420
|
-
|
|
67458
|
+
fail3(err);
|
|
67421
67459
|
}
|
|
67422
67460
|
};
|
|
67423
67461
|
armTimeout(FIRST_OUTPUT_TIMEOUT_MS, "no output started");
|
|
@@ -72458,8 +72496,8 @@ utils_default.reduceDescriptors(AxiosHeaders.prototype, ({ value }, key) => {
|
|
|
72458
72496
|
let mapped = key[0].toUpperCase() + key.slice(1);
|
|
72459
72497
|
return {
|
|
72460
72498
|
get: () => value,
|
|
72461
|
-
set(
|
|
72462
|
-
this[mapped] =
|
|
72499
|
+
set(headerValue2) {
|
|
72500
|
+
this[mapped] = headerValue2;
|
|
72463
72501
|
}
|
|
72464
72502
|
};
|
|
72465
72503
|
});
|
|
@@ -76141,7 +76179,6 @@ var {
|
|
|
76141
76179
|
|
|
76142
76180
|
// src/tunnel/webhook-config.ts
|
|
76143
76181
|
var import_sdk_core2 = __toESM(require_dist11(), 1);
|
|
76144
|
-
import { randomBytes } from "crypto";
|
|
76145
76182
|
import fs4 from "fs";
|
|
76146
76183
|
import path5 from "path";
|
|
76147
76184
|
var SINCH_FN_URL_PATTERN = /\.fn(-\w+)?\.sinch\.(?:com|io)/;
|
|
@@ -76205,20 +76242,15 @@ async function configureConversationWebhooks(webhookUrl, config) {
|
|
|
76205
76242
|
config.conversationWebhookId = deployedWebhook.id;
|
|
76206
76243
|
config.originalTarget = deployedWebhook.target;
|
|
76207
76244
|
}
|
|
76208
|
-
const hmacSecret = randomBytes(32).toString("hex");
|
|
76209
|
-
process.env.CONVERSATION_WEBHOOK_SECRET = hmacSecret;
|
|
76210
|
-
resetSinchClients();
|
|
76211
|
-
configureSecretRedaction(process.env);
|
|
76212
76245
|
await sinchClient.conversation.webhooks.update({
|
|
76213
76246
|
webhook_id: deployedWebhook.id,
|
|
76214
76247
|
webhookUpdateRequestBody: {
|
|
76215
|
-
target: webhookUrl
|
|
76216
|
-
secret: hmacSecret
|
|
76248
|
+
target: webhookUrl
|
|
76217
76249
|
},
|
|
76218
|
-
update_mask: ["target"
|
|
76250
|
+
update_mask: ["target"]
|
|
76219
76251
|
});
|
|
76220
76252
|
console.log(`\u2705 Updated Conversation webhook to tunnel: ${webhookUrl}`);
|
|
76221
|
-
console.log("\u{1F512}
|
|
76253
|
+
console.log("\u{1F512} Conversation webhook secret left as deployed");
|
|
76222
76254
|
console.log("\u{1F4AC} Send a message to your Conversation app to test!");
|
|
76223
76255
|
} catch (error) {
|
|
76224
76256
|
console.log(
|
|
@@ -76261,8 +76293,6 @@ async function cleanupConversationWebhook(config) {
|
|
|
76261
76293
|
console.log(`\u{1F504} Restored webhook target to: ${restoreTarget}`);
|
|
76262
76294
|
config.conversationWebhookId = void 0;
|
|
76263
76295
|
config.originalTarget = void 0;
|
|
76264
|
-
delete process.env.CONVERSATION_WEBHOOK_SECRET;
|
|
76265
|
-
resetSinchClients();
|
|
76266
76296
|
} catch (error) {
|
|
76267
76297
|
console.log(
|
|
76268
76298
|
"\u26A0\uFE0F Could not restore Conversation webhook:",
|
|
@@ -76713,14 +76743,14 @@ var TunnelClient = class {
|
|
|
76713
76743
|
timestampPart = ENCODING[t % 32] + timestampPart;
|
|
76714
76744
|
t = Math.floor(t / 32);
|
|
76715
76745
|
}
|
|
76716
|
-
const
|
|
76717
|
-
crypto.getRandomValues(
|
|
76746
|
+
const randomBytes = new Uint8Array(10);
|
|
76747
|
+
crypto.getRandomValues(randomBytes);
|
|
76718
76748
|
let randomPart = "";
|
|
76719
76749
|
for (let i = 0; i < 10; i++) {
|
|
76720
|
-
const byte =
|
|
76750
|
+
const byte = randomBytes[i];
|
|
76721
76751
|
randomPart += ENCODING[byte >> 3];
|
|
76722
76752
|
if (randomPart.length < 16) {
|
|
76723
|
-
randomPart += ENCODING[(byte & 7) << 2 | (i + 1 < 10 ?
|
|
76753
|
+
randomPart += ENCODING[(byte & 7) << 2 | (i + 1 < 10 ? randomBytes[i + 1] >> 6 : 0)];
|
|
76724
76754
|
}
|
|
76725
76755
|
}
|
|
76726
76756
|
randomPart = randomPart.substring(0, 16);
|
|
@@ -76948,8 +76978,10 @@ var TunnelClient = class {
|
|
|
76948
76978
|
]);
|
|
76949
76979
|
}
|
|
76950
76980
|
async configureVoiceWebhooks() {
|
|
76981
|
+
const voiceWebhookUrl = this.buildTunnelUrl();
|
|
76982
|
+
process.env[TUNNEL_VOICE_SIGNED_PATH_ENV] = new URL(voiceWebhookUrl).pathname;
|
|
76951
76983
|
await configureVoiceServiceWebhook(
|
|
76952
|
-
|
|
76984
|
+
voiceWebhookUrl,
|
|
76953
76985
|
process.env,
|
|
76954
76986
|
globalThis.fetch,
|
|
76955
76987
|
this.webhookConfig
|
|
@@ -77036,6 +77068,7 @@ var TunnelClient = class {
|
|
|
77036
77068
|
async disconnect() {
|
|
77037
77069
|
this.shuttingDown = true;
|
|
77038
77070
|
delete process.env[TUNNEL_PUBLIC_URL_ENV];
|
|
77071
|
+
delete process.env[TUNNEL_VOICE_SIGNED_PATH_ENV];
|
|
77039
77072
|
this.stopHeartbeat();
|
|
77040
77073
|
this.streams.closeAll("Tunnel client shutting down");
|
|
77041
77074
|
if (this.ws) {
|
|
@@ -77680,10 +77713,9 @@ export {
|
|
|
77680
77713
|
safeCut,
|
|
77681
77714
|
installStdioRedaction,
|
|
77682
77715
|
VOICE_TIMESTAMP_SKEW_MS,
|
|
77683
|
-
VOICE_MISSING_SECRET_WARNING,
|
|
77684
77716
|
validateVoiceSignature,
|
|
77685
|
-
resetVoiceSignatureWarning,
|
|
77686
77717
|
verifyVoiceWebhook,
|
|
77718
|
+
verifyConversationWebhook,
|
|
77687
77719
|
getSinchClients,
|
|
77688
77720
|
resetSinchClients,
|
|
77689
77721
|
getLandingPageHtml,
|
|
@@ -77691,9 +77723,11 @@ export {
|
|
|
77691
77723
|
VOICE_V1_CALLBACKS,
|
|
77692
77724
|
NOTIFICATION_EVENTS,
|
|
77693
77725
|
VOICE_WEBHOOK_HANDLER,
|
|
77726
|
+
CONVERSATION_WEBHOOK_HANDLER,
|
|
77694
77727
|
isVoiceV1Callback,
|
|
77695
77728
|
isNotificationEvent,
|
|
77696
77729
|
isVoiceWebhook,
|
|
77730
|
+
TUNNEL_VOICE_SIGNED_PATH_ENV,
|
|
77697
77731
|
buildVoiceSignedRequest,
|
|
77698
77732
|
extractFunctionName,
|
|
77699
77733
|
generateRequestId,
|
|
@@ -78051,4 +78085,4 @@ serve-static/index.js:
|
|
|
78051
78085
|
* MIT Licensed
|
|
78052
78086
|
*)
|
|
78053
78087
|
*/
|
|
78054
|
-
//# sourceMappingURL=chunk-
|
|
78088
|
+
//# sourceMappingURL=chunk-ZM72YQUN.js.map
|