@sinch/functions-runtime 0.5.0 → 0.5.2
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/bin/sinch-runtime.js +34 -1974
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/chunk-KKZKLUQ5.js +44611 -0
- package/dist/chunk-KKZKLUQ5.js.map +1 -0
- package/dist/index.js +98 -3776
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,1970 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __sinchCreateRequire } from 'node:module';
|
|
3
|
+
const require = __sinchCreateRequire(import.meta.url);
|
|
4
|
+
import {
|
|
5
|
+
TunnelClient,
|
|
6
|
+
buildBaseContext,
|
|
7
|
+
createApp,
|
|
8
|
+
createCacheClient,
|
|
9
|
+
createSinchRuntime,
|
|
10
|
+
createStorageClient,
|
|
11
|
+
getSinchClients,
|
|
12
|
+
installWebSocketHandlers,
|
|
13
|
+
isVoiceCallback,
|
|
14
|
+
secretsLoader,
|
|
15
|
+
setupRequestHandler
|
|
16
|
+
} from "../chunk-KKZKLUQ5.js";
|
|
2
17
|
|
|
3
18
|
// src/bin/sinch-runtime.ts
|
|
4
|
-
import
|
|
5
|
-
import { createRequire as createRequire3 } from "module";
|
|
6
|
-
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
7
|
-
import fs5 from "fs";
|
|
8
|
-
|
|
9
|
-
// ../runtime-shared/dist/ai/connect-agent.js
|
|
10
|
-
var AgentProvider;
|
|
11
|
-
(function(AgentProvider2) {
|
|
12
|
-
AgentProvider2["Sinch"] = "sinch";
|
|
13
|
-
AgentProvider2["ElevenLabs"] = "elevenlabs";
|
|
14
|
-
})(AgentProvider || (AgentProvider = {}));
|
|
15
|
-
|
|
16
|
-
// ../runtime-shared/dist/host/middleware.js
|
|
19
|
+
import path from "path";
|
|
17
20
|
import { createRequire } from "module";
|
|
18
|
-
var requireCjs = createRequire(import.meta.url);
|
|
19
|
-
var defaultOptions = {
|
|
20
|
-
limit: "10mb",
|
|
21
|
-
allowJson5: true,
|
|
22
|
-
camelCase: {
|
|
23
|
-
deep: true,
|
|
24
|
-
stopPaths: ["custom", "applicationkey"],
|
|
25
|
-
exclude: []
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var SPECIAL_CASES = {
|
|
29
|
-
callid: "callId",
|
|
30
|
-
applicationkey: "applicationKey",
|
|
31
|
-
callbackurl: "callbackUrl",
|
|
32
|
-
clinumber: "cliNumber",
|
|
33
|
-
menuResult: "menuResult",
|
|
34
|
-
userid: "userId",
|
|
35
|
-
username: "userName",
|
|
36
|
-
callleg: "callLeg",
|
|
37
|
-
conferenceid: "conferenceId",
|
|
38
|
-
participantid: "participantId"
|
|
39
|
-
};
|
|
40
|
-
function toCamelCase(str) {
|
|
41
|
-
if (!str)
|
|
42
|
-
return str;
|
|
43
|
-
if (str.includes("_") || str.includes("-")) {
|
|
44
|
-
return str.replace(/[-_]([a-z])/g, (_, char) => char.toUpperCase());
|
|
45
|
-
}
|
|
46
|
-
if (/[a-z][A-Z]/.test(str)) {
|
|
47
|
-
return str;
|
|
48
|
-
}
|
|
49
|
-
const lower = str.toLowerCase();
|
|
50
|
-
if (SPECIAL_CASES[lower]) {
|
|
51
|
-
return SPECIAL_CASES[lower];
|
|
52
|
-
}
|
|
53
|
-
return str;
|
|
54
|
-
}
|
|
55
|
-
function transformKeys(obj, options = {}) {
|
|
56
|
-
const { stopPaths = [], exclude = [], deep = true } = options;
|
|
57
|
-
if (obj === null || obj === void 0) {
|
|
58
|
-
return obj;
|
|
59
|
-
}
|
|
60
|
-
if (Array.isArray(obj)) {
|
|
61
|
-
return deep ? obj.map((item) => transformKeys(item, options)) : obj;
|
|
62
|
-
}
|
|
63
|
-
if (typeof obj !== "object") {
|
|
64
|
-
return obj;
|
|
65
|
-
}
|
|
66
|
-
const result = {};
|
|
67
|
-
const DANGEROUS_KEYS = ["__proto__", "constructor", "prototype"];
|
|
68
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
69
|
-
if (DANGEROUS_KEYS.includes(key)) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
let newKey = key;
|
|
73
|
-
let shouldTransformValue = deep;
|
|
74
|
-
const isExcluded = exclude.some((pattern) => {
|
|
75
|
-
if (pattern instanceof RegExp) {
|
|
76
|
-
return pattern.test(key);
|
|
77
|
-
}
|
|
78
|
-
return pattern === key;
|
|
79
|
-
});
|
|
80
|
-
if (!isExcluded) {
|
|
81
|
-
newKey = toCamelCase(key);
|
|
82
|
-
}
|
|
83
|
-
if (DANGEROUS_KEYS.includes(newKey)) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (stopPaths.includes(newKey)) {
|
|
87
|
-
shouldTransformValue = false;
|
|
88
|
-
}
|
|
89
|
-
result[newKey] = shouldTransformValue ? transformKeys(value, options) : value;
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
function parseJson(text, allowJson5 = true) {
|
|
94
|
-
if (!text || typeof text !== "string") {
|
|
95
|
-
return {};
|
|
96
|
-
}
|
|
97
|
-
const trimmed = text.trim();
|
|
98
|
-
if (!trimmed) {
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
return JSON.parse(trimmed);
|
|
103
|
-
} catch (e) {
|
|
104
|
-
if (!allowJson5) {
|
|
105
|
-
throw new Error(`Invalid JSON: ${e.message}`);
|
|
106
|
-
}
|
|
107
|
-
try {
|
|
108
|
-
const cleaned = trimmed.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").replace(/,(\s*[}\]])/g, "$1");
|
|
109
|
-
return JSON.parse(cleaned);
|
|
110
|
-
} catch (e2) {
|
|
111
|
-
throw new Error(`Invalid JSON/JSON5: ${e.message}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function createLenientJsonParser(options = {}) {
|
|
116
|
-
const opts = { ...defaultOptions, ...options };
|
|
117
|
-
return function lenientJsonParser(req, res, next) {
|
|
118
|
-
if (req.body && typeof req.body === "object" && !Buffer.isBuffer(req.body)) {
|
|
119
|
-
if (!req._keysTransformed) {
|
|
120
|
-
const VOICE_EVENTS = ["ice", "ace", "pie", "dice", "notify"];
|
|
121
|
-
const isVoice = req.body.event && VOICE_EVENTS.includes(req.body.event);
|
|
122
|
-
if (isVoice) {
|
|
123
|
-
req.body = transformKeys(req.body, opts.camelCase);
|
|
124
|
-
}
|
|
125
|
-
req._keysTransformed = true;
|
|
126
|
-
}
|
|
127
|
-
return next();
|
|
128
|
-
}
|
|
129
|
-
let raw = "";
|
|
130
|
-
if (typeof req.body === "string") {
|
|
131
|
-
raw = req.body;
|
|
132
|
-
req.rawBody = raw;
|
|
133
|
-
} else if (Buffer.isBuffer(req.body)) {
|
|
134
|
-
raw = req.body.toString("utf8");
|
|
135
|
-
req.rawBody = raw;
|
|
136
|
-
} else {
|
|
137
|
-
req.body = {};
|
|
138
|
-
return next();
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
let parsed = parseJson(raw, opts.allowJson5);
|
|
142
|
-
const VOICE_EVENTS = ["ice", "ace", "pie", "dice", "notify"];
|
|
143
|
-
const evt = parsed && typeof parsed === "object" && "event" in parsed ? parsed.event : null;
|
|
144
|
-
const isVoice = typeof evt === "string" && VOICE_EVENTS.includes(evt);
|
|
145
|
-
if (isVoice) {
|
|
146
|
-
parsed = transformKeys(parsed, opts.camelCase);
|
|
147
|
-
}
|
|
148
|
-
req._keysTransformed = true;
|
|
149
|
-
req.body = parsed;
|
|
150
|
-
next();
|
|
151
|
-
} catch (error) {
|
|
152
|
-
res.status(400).json({
|
|
153
|
-
error: "Invalid JSON in request body",
|
|
154
|
-
message: error.message,
|
|
155
|
-
hint: opts.allowJson5 ? "This endpoint accepts JSON and JSON5 (comments and trailing commas allowed)" : "This endpoint requires strict JSON format"
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
function setupJsonParsing(app, options = {}) {
|
|
161
|
-
const express = requireCjs("express");
|
|
162
|
-
app.use(express.text({
|
|
163
|
-
type: ["application/json", "application/*+json", "text/json"],
|
|
164
|
-
limit: options.limit || "10mb"
|
|
165
|
-
}));
|
|
166
|
-
app.use(createLenientJsonParser(options));
|
|
167
|
-
return app;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// ../runtime-shared/dist/auth/basic-auth.js
|
|
171
|
-
import { timingSafeEqual } from "crypto";
|
|
172
|
-
function validateBasicAuth(authHeader, expectedKey, expectedSecret) {
|
|
173
|
-
if (!authHeader) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
if (!authHeader.toLowerCase().startsWith("basic ")) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
const decoded = Buffer.from(authHeader.slice(6), "base64").toString("utf-8");
|
|
180
|
-
const colonIndex = decoded.indexOf(":");
|
|
181
|
-
if (colonIndex === -1) {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
const providedKey = decoded.slice(0, colonIndex);
|
|
185
|
-
const providedSecret = decoded.slice(colonIndex + 1);
|
|
186
|
-
const expectedKeyBuf = Buffer.from(expectedKey);
|
|
187
|
-
const providedKeyBuf = Buffer.from(providedKey);
|
|
188
|
-
const expectedSecretBuf = Buffer.from(expectedSecret);
|
|
189
|
-
const providedSecretBuf = Buffer.from(providedSecret);
|
|
190
|
-
const keyMatch = expectedKeyBuf.length === providedKeyBuf.length && timingSafeEqual(expectedKeyBuf, providedKeyBuf);
|
|
191
|
-
const secretMatch = expectedSecretBuf.length === providedSecretBuf.length && timingSafeEqual(expectedSecretBuf, providedSecretBuf);
|
|
192
|
-
return keyMatch && secretMatch;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// ../runtime-shared/dist/security/index.js
|
|
196
|
-
function shouldValidateWebhook(mode, isDevelopment) {
|
|
197
|
-
const normalizedMode = (mode || "deploy").toLowerCase();
|
|
198
|
-
switch (normalizedMode) {
|
|
199
|
-
case "never":
|
|
200
|
-
return false;
|
|
201
|
-
case "always":
|
|
202
|
-
return true;
|
|
203
|
-
case "deploy":
|
|
204
|
-
default:
|
|
205
|
-
return !isDevelopment;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
var VALID_MODES = ["never", "deploy", "always"];
|
|
209
|
-
function getProtectionMode(config) {
|
|
210
|
-
const envValue = process.env.WEBHOOK_PROTECTION ?? process.env.PROTECT_VOICE_CALLBACKS;
|
|
211
|
-
if (envValue) {
|
|
212
|
-
const normalized = envValue.toLowerCase();
|
|
213
|
-
if (VALID_MODES.includes(normalized)) {
|
|
214
|
-
return normalized;
|
|
215
|
-
}
|
|
216
|
-
console.warn(`[SECURITY] Unknown WEBHOOK_PROTECTION value "${envValue}", defaulting to "deploy"`);
|
|
217
|
-
return "deploy";
|
|
218
|
-
}
|
|
219
|
-
const configValue = config?.WebhookProtection ?? config?.webhookProtection ?? config?.ProtectVoiceCallbacks ?? config?.protectVoiceCallbacks;
|
|
220
|
-
if (typeof configValue === "string") {
|
|
221
|
-
const normalized = configValue.toLowerCase();
|
|
222
|
-
if (VALID_MODES.includes(normalized)) {
|
|
223
|
-
return normalized;
|
|
224
|
-
}
|
|
225
|
-
console.warn(`[SECURITY] Unknown webhook protection value "${configValue}", defaulting to "deploy"`);
|
|
226
|
-
return "deploy";
|
|
227
|
-
}
|
|
228
|
-
return "deploy";
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// ../runtime-shared/dist/sinch/index.js
|
|
232
|
-
import { SinchClient, validateAuthenticationHeader, ConversationCallbackWebhooks } from "@sinch/sdk-core";
|
|
233
|
-
function createSinchClients() {
|
|
234
|
-
const clients = {};
|
|
235
|
-
const hasCredentials = process.env.PROJECT_ID && process.env.PROJECT_ID_API_KEY && process.env.PROJECT_ID_API_SECRET;
|
|
236
|
-
if (process.env.CONVERSATION_WEBHOOK_SECRET) {
|
|
237
|
-
const callbackProcessor = new ConversationCallbackWebhooks(process.env.CONVERSATION_WEBHOOK_SECRET);
|
|
238
|
-
clients.validateConversationWebhook = (headers, body) => {
|
|
239
|
-
try {
|
|
240
|
-
const result = callbackProcessor.validateAuthenticationHeader(headers, body);
|
|
241
|
-
console.log("[SINCH] Conversation webhook validation:", result ? "VALID" : "INVALID");
|
|
242
|
-
return result;
|
|
243
|
-
} catch (error) {
|
|
244
|
-
console.error("[SINCH] Conversation validation error:", error instanceof Error ? error.message : error);
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
if (!hasCredentials) {
|
|
250
|
-
return clients;
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
const sinchClient = new SinchClient({
|
|
254
|
-
projectId: process.env.PROJECT_ID,
|
|
255
|
-
keyId: process.env.PROJECT_ID_API_KEY,
|
|
256
|
-
keySecret: process.env.PROJECT_ID_API_SECRET
|
|
257
|
-
});
|
|
258
|
-
if (process.env.CONVERSATION_APP_ID) {
|
|
259
|
-
clients.conversation = sinchClient.conversation;
|
|
260
|
-
console.log("[SINCH] Conversation API initialized");
|
|
261
|
-
}
|
|
262
|
-
if (process.env.VOICE_APPLICATION_KEY && process.env.VOICE_APPLICATION_SECRET) {
|
|
263
|
-
const voiceClient = new SinchClient({
|
|
264
|
-
projectId: process.env.PROJECT_ID,
|
|
265
|
-
keyId: process.env.PROJECT_ID_API_KEY,
|
|
266
|
-
keySecret: process.env.PROJECT_ID_API_SECRET,
|
|
267
|
-
applicationKey: process.env.VOICE_APPLICATION_KEY,
|
|
268
|
-
applicationSecret: process.env.VOICE_APPLICATION_SECRET
|
|
269
|
-
});
|
|
270
|
-
clients.voice = voiceClient.voice;
|
|
271
|
-
console.log("[SINCH] Voice API initialized with application credentials");
|
|
272
|
-
}
|
|
273
|
-
if (process.env.SMS_SERVICE_PLAN_ID) {
|
|
274
|
-
clients.sms = sinchClient.sms;
|
|
275
|
-
console.log("[SINCH] SMS API initialized");
|
|
276
|
-
}
|
|
277
|
-
if (process.env.ENABLE_NUMBERS_API === "true") {
|
|
278
|
-
clients.numbers = sinchClient.numbers;
|
|
279
|
-
console.log("[SINCH] Numbers API initialized");
|
|
280
|
-
}
|
|
281
|
-
} catch (error) {
|
|
282
|
-
console.error("[SINCH] Failed to initialize Sinch clients:", error.message);
|
|
283
|
-
return {};
|
|
284
|
-
}
|
|
285
|
-
if (process.env.VOICE_APPLICATION_KEY && process.env.VOICE_APPLICATION_SECRET) {
|
|
286
|
-
clients.validateWebhookSignature = (requestData) => {
|
|
287
|
-
console.log("[SINCH] Validating Voice webhook signature");
|
|
288
|
-
try {
|
|
289
|
-
const result = validateAuthenticationHeader(process.env.VOICE_APPLICATION_KEY, process.env.VOICE_APPLICATION_SECRET, requestData.headers, requestData.body, requestData.path, requestData.method);
|
|
290
|
-
console.log("[SINCH] Validation result:", result ? "VALID" : "INVALID");
|
|
291
|
-
return result;
|
|
292
|
-
} catch (error) {
|
|
293
|
-
console.error("[SINCH] Validation error:", error.message);
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
return clients;
|
|
299
|
-
}
|
|
300
|
-
var cachedClients = null;
|
|
301
|
-
function getSinchClients() {
|
|
302
|
-
if (!cachedClients) {
|
|
303
|
-
cachedClients = createSinchClients();
|
|
304
|
-
}
|
|
305
|
-
return cachedClients;
|
|
306
|
-
}
|
|
307
|
-
function resetSinchClients() {
|
|
308
|
-
cachedClients = null;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// ../runtime-shared/dist/host/app.js
|
|
312
|
-
import { createRequire as createRequire2 } from "module";
|
|
313
21
|
import { pathToFileURL } from "url";
|
|
314
|
-
import * as nodePath from "path";
|
|
315
|
-
import * as nodeFs from "fs";
|
|
316
|
-
var requireCjs2 = createRequire2(import.meta.url);
|
|
317
|
-
var LANDING_PAGE_HTML = `<!DOCTYPE html>
|
|
318
|
-
<html lang="en">
|
|
319
|
-
<head>
|
|
320
|
-
<meta charset="UTF-8">
|
|
321
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
322
|
-
<title>Sinch Function</title>
|
|
323
|
-
<link rel="icon" type="image/svg+xml" href="/favicon.ico">
|
|
324
|
-
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap" rel="stylesheet">
|
|
325
|
-
<style>
|
|
326
|
-
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
327
|
-
body { font-family: "DM Sans", Arial, sans-serif; min-height: 100vh; overflow: hidden; background: #ffffff; }
|
|
328
|
-
#gradient-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 0; }
|
|
329
|
-
.content { position: relative; z-index: 10; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem; mix-blend-mode: difference; }
|
|
330
|
-
.icon-wrapper { width: 120px; height: 120px; margin-bottom: 2rem; animation: float 6s ease-in-out infinite; }
|
|
331
|
-
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
|
|
332
|
-
.icon-wrapper svg { width: 100%; height: 100%; fill: white; }
|
|
333
|
-
.title { font-size: clamp(32px, 6vw, 56px); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; color: white; text-align: center; max-width: 600px; margin-bottom: 1.5rem; }
|
|
334
|
-
.status { display: inline-flex; align-items: center; gap: 0.75rem; font-size: 18px; font-weight: 500; color: white; opacity: 0.9; }
|
|
335
|
-
.status-dot { width: 10px; height: 10px; background: white; border-radius: 50%; position: relative; }
|
|
336
|
-
.status-dot::before { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid white; animation: ripple 2s ease-out infinite; }
|
|
337
|
-
@keyframes ripple { 0% { transform: scale(1); opacity: 0.6; } 100% { transform: scale(2); opacity: 0; } }
|
|
338
|
-
footer { position: fixed; bottom: 0; left: 0; right: 0; padding: 1.5rem 2rem; text-align: center; z-index: 10; mix-blend-mode: difference; }
|
|
339
|
-
.footer-content { display: flex; align-items: center; justify-content: center; gap: 0.5rem; font-size: 13px; color: white; opacity: 0.7; }
|
|
340
|
-
.footer-content svg { height: 16px; width: auto; fill: white; }
|
|
341
|
-
@media (prefers-reduced-motion: reduce) { .icon-wrapper { animation: none; } .status-dot::before { animation: none; display: none; } }
|
|
342
|
-
</style>
|
|
343
|
-
</head>
|
|
344
|
-
<body>
|
|
345
|
-
<canvas id="gradient-canvas"></canvas>
|
|
346
|
-
<div class="content">
|
|
347
|
-
<div class="icon-wrapper">
|
|
348
|
-
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
|
349
|
-
<path d="M0 0 C20.93144435 -0.58142901 39.09496106 1.50604372 55.875 15.5625 C66.82790249 26.17665293 72.53226475 40.66646351 74.60546875 55.56640625 C74.87588186 58.00035983 74.87588186 58.00035983 76 60 C76.96454894 67.72509952 77.18355452 75.52548686 77.39453125 83.30078125 C77.46339082 85.43557289 77.53307981 87.57033791 77.60351562 89.70507812 C77.70976411 92.99051459 77.81152568 96.27576582 77.89868164 99.56176758 C78.52393733 129.23731142 78.52393733 129.23731142 88 157 C88.35578125 157.67804688 88.7115625 158.35609375 89.078125 159.0546875 C94.76089061 168.37922543 104.94901494 170.48725373 115 173 C115 182.57 115 192.14 115 202 C112.69 202.37125 110.38 202.7425 108 203.125 C99.905737 204.67003153 95.0680161 206.8924082 90.109375 213.53125 C83.71376381 223.52775152 81.23188184 234.44421869 79.9609375 246.09765625 C79.87667007 246.86579147 79.79240265 247.6339267 79.70558167 248.42533875 C78.67925596 258.36255872 78.32712705 268.3341428 77.9375 278.3125 C76.56010435 312.28921394 76.56010435 312.28921394 74.25 321.5 C74.0744458 322.21430176 73.8988916 322.92860352 73.71801758 323.66455078 C69.36621237 340.7251508 62.22279512 355.52722574 46.7734375 364.97265625 C31.08266768 373.31391199 17.46036093 374.45648002 0 374 C0 362.78 0 351.56 0 340 C4.95 339.67 9.9 339.34 15 339 C21.41425661 337.54221441 27.40557289 335.94604143 32 331 C41.96653782 315.14896379 41.37732492 296.30175799 42 278.25 C44.29042973 212.3198731 44.29042973 212.3198731 64.91015625 190 C66.29780265 187.98880883 66.29780265 187.98880883 65.37890625 185.48046875 C64.05564488 183.10009772 62.69232678 181.32846483 60.875 179.3125 C43.91950219 157.82609672 43.67363702 127.5168667 42.25390625 101.43359375 C42.19595886 100.36962875 42.13801147 99.30566376 42.07830811 98.2094574 C41.84407978 93.84466467 41.61402719 89.47975805 41.39819336 85.11401367 C40.99015593 64.27717646 40.99015593 64.27717646 32.98828125 45.5234375 C32 44 32 44 32 42 C31.42121094 41.71253906 30.84242188 41.42507813 30.24609375 41.12890625 C28.83602338 40.42019262 27.43139326 39.70043581 26.03515625 38.96484375 C25.38417969 38.62582031 24.73320313 38.28679687 24.0625 37.9375 C23.41410156 37.59589844 22.76570312 37.25429688 22.09765625 36.90234375 C15.27203813 33.966184 7.11372705 34.47424847 0 34 C0 22.78 0 11.56 0 0 Z" transform="translate(654,325)"/>
|
|
350
|
-
<path d="M0 0 C3.444375 0.04125 6.88875 0.0825 10.4375 0.125 C10.4375 11.345 10.4375 22.565 10.4375 34.125 C7.83875 34.2075 5.24 34.29 2.5625 34.375 C-7.18272292 34.85729903 -15.63749007 36.71684985 -22.5625 44.125 C-31.49595906 57.5251886 -31.12984766 74.21365918 -31.625 89.6875 C-34.18432686 164.24320576 -34.18432686 164.24320576 -54.375 183.4765625 C-55.74969183 185.03433577 -55.74969183 185.03433577 -55.515625 186.95703125 C-54.17099734 190.0155081 -52.28807488 192.49561568 -50.3125 195.1875 C-32.54496946 220.15391355 -32.63824135 251.51444506 -31.51293945 280.92919922 C-31.08045868 292.11365858 -30.51897291 303.08447592 -28.5625 314.125 C-28.43262695 314.88192139 -28.30275391 315.63884277 -28.16894531 316.41870117 C-26.61388783 323.91215705 -23.50529382 330.13896804 -17.1875 334.5625 C-8.59143743 340.04835084 0.27828442 339.49004903 10.4375 340.125 C10.4375 351.345 10.4375 362.565 10.4375 374.125 C-11.03507606 374.69006779 -28.20349315 372.92712593 -45.375 358.5625 C-68.63112564 336.25560398 -67.21470802 299.23895394 -68.0625 269.5625 C-68.59361144 237.84268541 -68.59361144 237.84268541 -82.5625 210.125 C-89.22872268 204.50037462 -95.95018781 203.27807805 -104.5625 201.125 C-104.5625 191.885 -104.5625 182.645 -104.5625 173.125 C-102.0875 172.444375 -99.6125 171.76375 -97.0625 171.0625 C-88.61410179 168.53529591 -83.39407037 165.21504609 -78.3125 157.875 C-77.69451944 156.64176126 -77.11369297 155.38950152 -76.5625 154.125 C-76.05783203 152.97451172 -76.05783203 152.97451172 -75.54296875 151.80078125 C-70.10324087 138.17090127 -68.58488302 123.17691663 -68.1328125 108.6171875 C-68.0590342 106.55597377 -67.98479985 104.49477633 -67.91015625 102.43359375 C-67.79799647 99.2401961 -67.68897443 96.04681123 -67.58837891 92.85302734 C-67.22538737 81.52946225 -66.65494051 70.32073083 -65.13671875 59.0859375 C-64.95793686 57.75983963 -64.95793686 57.75983963 -64.77554321 56.4069519 C-62.24372342 39.06207822 -55.12155189 23.04594995 -40.9609375 12.1171875 C-28.07509054 3.53900119 -15.33988115 -0.26186367 0 0 Z" transform="translate(359.5625,324.875)"/>
|
|
351
|
-
<path d="M0 0 C9.89334431 8.68950817 14.30034619 23.01452361 15.24373245 35.79419899 C15.49099471 41.77148785 15.42334062 47.74978768 15.37109375 53.73046875 C15.36548489 55.63859724 15.36122091 57.54673011 15.35823059 59.4548645 C15.34688325 64.42950786 15.31750548 69.40388024 15.28411865 74.37841797 C15.25319735 79.47359555 15.23967854 84.56881775 15.22460938 89.6640625 C15.19262409 99.62643911 15.13994121 109.58854505 15.078125 119.55078125 C3.528125 119.55078125 -8.021875 119.55078125 -19.921875 119.55078125 C-19.97085938 114.4203125 -20.01984375 109.28984375 -20.0703125 104.00390625 C-20.10574492 100.73175245 -20.14173112 97.45962313 -20.1796875 94.1875 C-20.23973228 89.00671097 -20.29785091 83.82595572 -20.34375 78.64501953 C-20.38093086 74.46275871 -20.42737419 70.28068941 -20.47993851 66.09859467 C-20.49830992 64.51204578 -20.51347972 62.92545612 -20.52521896 61.3388443 C-20.22141003 42.05064114 -20.22141003 42.05064114 -28.921875 25.55078125 C-33.2097739 21.98892101 -37.29807009 19.87523153 -42.921875 19.55078125 C-43.79714844 19.48890625 -44.67242188 19.42703125 -45.57421875 19.36328125 C-54.66067243 18.98906437 -62.9621186 20.4280254 -69.859375 26.73828125 C-76.14726535 33.73487866 -78.0525657 41.92333342 -78.12719727 51.07324219 C-78.13709686 51.82485123 -78.14699646 52.57646027 -78.15719604 53.35084534 C-78.18871966 55.82891721 -78.21353223 58.30700823 -78.23828125 60.78515625 C-78.25885867 62.50580334 -78.27985536 64.22644545 -78.30125427 65.94708252 C-78.35639351 70.47125217 -78.40583867 74.99546682 -78.45410156 79.51971436 C-78.51321858 84.95049451 -78.57940167 90.38119259 -78.64440155 95.81190491 C-78.74230855 104.0581468 -78.83123469 112.30444185 -78.921875 120.55078125 C-90.801875 120.55078125 -102.681875 120.55078125 -114.921875 120.55078125 C-114.921875 77.65078125 -114.921875 34.75078125 -114.921875 -9.44921875 C-103.701875 -9.44921875 -92.481875 -9.44921875 -80.921875 -9.44921875 C-79.96000569 -5.60174152 -79.61528473 -2.14754023 -79.359375 1.80078125 C-79.27558594 3.0640625 -79.19179688 4.32734375 -79.10546875 5.62890625 C-79.04488281 6.593125 -78.98429688 7.55734375 -78.921875 8.55078125 C-78.48875 7.72578125 -78.055625 6.90078125 -77.609375 6.05078125 C-71.50314599 -3.01214812 -59.57220635 -8.76116827 -49.16015625 -11.05859375 C-31.06340614 -13.24155516 -14.8555768 -11.20207112 0 0 Z" transform="translate(613.921875,481.44921875)"/>
|
|
352
|
-
<path d="M0 0 C1.53906801 1.53906801 1.16955456 2.91263628 1.1875 5.0625 C1.1451715 9.92322255 0.65815533 14.68227908 0.0625 19.5 C-0.02427002 20.20648682 -0.11104004 20.91297363 -0.20043945 21.64086914 C-0.86920125 26.7384025 -0.86920125 26.7384025 -2 29 C-2.96808594 28.84144531 -3.93617188 28.68289063 -4.93359375 28.51953125 C-9.31081865 27.89956204 -13.64601408 27.74275212 -18.0625 27.6875 C-18.83916016 27.65849609 -19.61582031 27.62949219 -20.41601562 27.59960938 C-25.75566236 27.54083257 -28.83098013 28.36372264 -33 32 C-37.31404494 38.3211768 -37.31404494 38.3211768 -37 53 C-25.78 53 -14.56 53 -3 53 C-3 62.57 -3 72.14 -3 82 C-14.55 82 -26.1 82 -38 82 C-38 115 -38 148 -38 182 C-49.55 182 -61.1 182 -73 182 C-73 149 -73 116 -73 82 C-79.93 82 -86.86 82 -94 82 C-94 72.43 -94 62.86 -94 53 C-87.07 53 -80.14 53 -73 53 C-73.04125 50.6075 -73.0825 48.215 -73.125 45.75 C-73.17827085 31.60875021 -70.96095372 19.48048613 -61.0078125 8.81640625 C-54.5981324 3.0177657 -47.30019677 0.02408307 -39 -2 C-38.37625488 -2.17200928 -37.75250977 -2.34401855 -37.10986328 -2.52124023 C-25.33848182 -5.19234404 -11.53065338 -2.96722147 0 0 Z" transform="translate(486,419)"/>
|
|
353
|
-
</svg>
|
|
354
|
-
</div>
|
|
355
|
-
<h1 class="title">Your function is ready for traffic</h1>
|
|
356
|
-
<div class="status"><span class="status-dot"></span>Running</div>
|
|
357
|
-
</div>
|
|
358
|
-
<footer>
|
|
359
|
-
<div class="footer-content">
|
|
360
|
-
Powered by
|
|
361
|
-
<svg viewBox="0 0 93 48" xmlns="http://www.w3.org/2000/svg">
|
|
362
|
-
<path d="M92.298 25.271a17.167 17.167 0 0 1-.814 5.312c-1.51 4.734-5.27 8.678-10.06 10.549-5.64 2.202-12.252 1.416-18.624-2.21l-4.649-2.67a16.424 16.424 0 0 1-3.563 3.064l-14.817 8.679-.027.015v-7.501l.027-.014 22.29-13.057a16.017 16.017 0 0 1-.713 3.206l4.656 2.65c5.95 3.386 10.388 2.85 13.065 1.806 2.991-1.167 5.323-3.59 6.245-6.483.692-2.15.679-4.467-.04-6.609-.955-2.88-3.319-5.275-6.324-6.41-2.688-1.014-7.132-1.494-13.04 1.962L29.7 38.747l-.043.028c-4.017 2.35-8.14 3.556-12.065 3.58a18.162 18.162 0 0 1-6.53-1.145C6.247 39.396 2.44 35.498.874 30.783A17.116 17.116 0 0 1 .81 20.166c1.51-4.733 5.272-8.676 10.063-10.548 5.64-2.202 12.252-1.416 18.623 2.212l4.649 2.67a16.377 16.377 0 0 1 3.563-3.067l.281-.163 1.726-1.011-7.37-4.197A3.238 3.238 0 0 1 35.551.437l10.591 6.06L56.52.457a3.238 3.238 0 0 1 3.27 5.588l-29.528 17.05c.132-1.017.36-2.019.683-2.992l-4.656-2.65c-5.946-3.383-10.384-2.847-13.061-1.803-2.991 1.167-5.325 3.59-6.247 6.481a10.623 10.623 0 0 0 .039 6.608c.956 2.882 3.321 5.277 6.324 6.41 2.689 1.012 7.136 1.495 13.042-1.966l36.256-21.208c4.017-2.349 8.14-3.555 12.067-3.579a18.112 18.112 0 0 1 6.53 1.145c4.812 1.813 8.62 5.712 10.187 10.426a17.23 17.23 0 0 1 .872 5.304Z"/>
|
|
363
|
-
</svg>
|
|
364
|
-
</div>
|
|
365
|
-
</footer>
|
|
366
|
-
<script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js"}}</script>
|
|
367
|
-
<script type="module">
|
|
368
|
-
import * as THREE from 'three';
|
|
369
|
-
const COLORS={yellow:new THREE.Color(0xFFBE3C),green:new THREE.Color(0x059688),blue:new THREE.Color(0x3AA7EA),red:new THREE.Color(0xEF5858)};
|
|
370
|
-
const vertexShader=\`varying vec2 vUv;void main(){vUv=uv;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}\`;
|
|
371
|
-
const fragmentShader=\`uniform float uTime;uniform vec2 uResolution;uniform vec3 uColor1;uniform vec3 uColor2;uniform vec3 uColor3;uniform vec3 uColor4;varying vec2 vUv;vec3 mod289(vec3 x){return x-floor(x*(1.0/289.0))*289.0;}vec4 mod289(vec4 x){return x-floor(x*(1.0/289.0))*289.0;}vec4 permute(vec4 x){return mod289(((x*34.0)+1.0)*x);}vec4 taylorInvSqrt(vec4 r){return 1.79284291400159-0.85373472095314*r;}float snoise(vec3 v){const vec2 C=vec2(1.0/6.0,1.0/3.0);const vec4 D=vec4(0.0,0.5,1.0,2.0);vec3 i=floor(v+dot(v,C.yyy));vec3 x0=v-i+dot(i,C.xxx);vec3 g=step(x0.yzx,x0.xyz);vec3 l=1.0-g;vec3 i1=min(g.xyz,l.zxy);vec3 i2=max(g.xyz,l.zxy);vec3 x1=x0-i1+C.xxx;vec3 x2=x0-i2+C.yyy;vec3 x3=x0-D.yyy;i=mod289(i);vec4 p=permute(permute(permute(i.z+vec4(0.0,i1.z,i2.z,1.0))+i.y+vec4(0.0,i1.y,i2.y,1.0))+i.x+vec4(0.0,i1.x,i2.x,1.0));float n_=0.142857142857;vec3 ns=n_*D.wyz-D.xzx;vec4 j=p-49.0*floor(p*ns.z*ns.z);vec4 x_=floor(j*ns.z);vec4 y_=floor(j-7.0*x_);vec4 x=x_*ns.x+ns.yyyy;vec4 y=y_*ns.x+ns.yyyy;vec4 h=1.0-abs(x)-abs(y);vec4 b0=vec4(x.xy,y.xy);vec4 b1=vec4(x.zw,y.zw);vec4 s0=floor(b0)*2.0+1.0;vec4 s1=floor(b1)*2.0+1.0;vec4 sh=-step(h,vec4(0.0));vec4 a0=b0.xzyw+s0.xzyw*sh.xxyy;vec4 a1=b1.xzyw+s1.xzyw*sh.zzww;vec3 p0=vec3(a0.xy,h.x);vec3 p1=vec3(a0.zw,h.y);vec3 p2=vec3(a1.xy,h.z);vec3 p3=vec3(a1.zw,h.w);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;vec4 m=max(0.6-vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);m=m*m;return 42.0*dot(m*m,vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));}float metaball(vec2 p,vec2 center,float radius){float d=length(p-center);return radius/(d*d+0.0001);}void main(){vec2 uv=vUv;vec2 aspect=vec2(uResolution.x/uResolution.y,1.0);vec2 p=(uv-0.5)*aspect;float time=uTime*0.15;vec2 blob1=vec2(0.6*sin(time*0.7+snoise(vec3(time*0.2,0.0,0.0))),0.5*cos(time*0.5+snoise(vec3(0.0,time*0.2,0.0))));vec2 blob2=vec2(0.55*cos(time*0.6+1.5+snoise(vec3(time*0.15,1.0,0.0))),0.6*sin(time*0.8+2.0+snoise(vec3(1.0,time*0.15,0.0))));vec2 blob3=vec2(0.7*sin(time*0.5+3.0+snoise(vec3(time*0.1,2.0,0.0))),0.5*cos(time*0.7+1.0+snoise(vec3(2.0,time*0.1,0.0))));vec2 blob4=vec2(0.55*cos(time*0.8+4.5+snoise(vec3(time*0.12,3.0,0.0))),0.65*sin(time*0.6+0.5+snoise(vec3(3.0,time*0.12,0.0))));float size1=0.16+0.04*sin(time*1.2);float size2=0.14+0.03*cos(time*1.5);float size3=0.18+0.05*sin(time*0.9);float size4=0.12+0.04*cos(time*1.1);float m1=metaball(p,blob1,size1);float m2=metaball(p,blob2,size2);float m3=metaball(p,blob3,size3);float m4=metaball(p,blob4,size4);float field=m1+m2+m3+m4;float noise=snoise(vec3(p*3.0,time*0.3))*0.15;field+=noise;vec3 color=vec3(0.0);float total=m1+m2+m3+m4+0.0001;color+=uColor1*(m1/total);color+=uColor2*(m2/total);color+=uColor3*(m3/total);color+=uColor4*(m4/total);float gradientNoise=snoise(vec3(uv*2.0,time*0.1));color+=gradientNoise*0.05;float threshold=0.8;float edge=smoothstep(threshold-0.3,threshold+0.5,field);vec3 bg1=mix(uColor1,uColor3,uv.y)*0.6+0.4;vec3 bg2=mix(uColor2,uColor4,uv.x)*0.6+0.4;vec3 background=mix(bg1,bg2,0.5+0.5*sin(time*0.2));vec3 finalColor=mix(background,color,edge);float vignette=1.0-length(uv-0.5)*0.5;finalColor*=vignette;finalColor=pow(finalColor,vec3(0.95));gl_FragColor=vec4(finalColor,1.0);}\`;
|
|
372
|
-
class GradientAnimation{constructor(){this.canvas=document.getElementById('gradient-canvas');this.scene=new THREE.Scene();this.camera=new THREE.OrthographicCamera(-1,1,1,-1,0,1);this.renderer=new THREE.WebGLRenderer({canvas:this.canvas,antialias:true,alpha:false});this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2));this.renderer.setSize(window.innerWidth,window.innerHeight);this.uniforms={uTime:{value:0},uResolution:{value:new THREE.Vector2(window.innerWidth,window.innerHeight)},uColor1:{value:COLORS.yellow},uColor2:{value:COLORS.green},uColor3:{value:COLORS.blue},uColor4:{value:COLORS.red}};const geometry=new THREE.PlaneGeometry(2,2);const material=new THREE.ShaderMaterial({vertexShader,fragmentShader,uniforms:this.uniforms});this.mesh=new THREE.Mesh(geometry,material);this.scene.add(this.mesh);window.addEventListener('resize',this.onResize.bind(this));this.animate();}onResize(){this.renderer.setSize(window.innerWidth,window.innerHeight);this.uniforms.uResolution.value.set(window.innerWidth,window.innerHeight);}animate(){this.uniforms.uTime.value+=0.016;this.renderer.render(this.scene,this.camera);requestAnimationFrame(this.animate.bind(this));}}
|
|
373
|
-
new GradientAnimation();
|
|
374
|
-
</script>
|
|
375
|
-
</body>
|
|
376
|
-
</html>`;
|
|
377
|
-
function getLandingPageHtml() {
|
|
378
|
-
return LANDING_PAGE_HTML;
|
|
379
|
-
}
|
|
380
|
-
var FAVICON_SVG = `<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
|
381
|
-
<rect width="1024" height="1024" fill="#3AA7EA"/>
|
|
382
|
-
<path fill="white" d="M0 0 C20.93144435 -0.58142901 39.09496106 1.50604372 55.875 15.5625 C66.82790249 26.17665293 72.53226475 40.66646351 74.60546875 55.56640625 C74.87588186 58.00035983 74.87588186 58.00035983 76 60 C76.96454894 67.72509952 77.18355452 75.52548686 77.39453125 83.30078125 C77.46339082 85.43557289 77.53307981 87.57033791 77.60351562 89.70507812 C77.70976411 92.99051459 77.81152568 96.27576582 77.89868164 99.56176758 C78.52393733 129.23731142 78.52393733 129.23731142 88 157 C88.35578125 157.67804688 88.7115625 158.35609375 89.078125 159.0546875 C94.76089061 168.37922543 104.94901494 170.48725373 115 173 C115 182.57 115 192.14 115 202 C112.69 202.37125 110.38 202.7425 108 203.125 C99.905737 204.67003153 95.0680161 206.8924082 90.109375 213.53125 C83.71376381 223.52775152 81.23188184 234.44421869 79.9609375 246.09765625 C79.87667007 246.86579147 79.79240265 247.6339267 79.70558167 248.42533875 C78.67925596 258.36255872 78.32712705 268.3341428 77.9375 278.3125 C76.56010435 312.28921394 76.56010435 312.28921394 74.25 321.5 C74.0744458 322.21430176 73.8988916 322.92860352 73.71801758 323.66455078 C69.36621237 340.7251508 62.22279512 355.52722574 46.7734375 364.97265625 C31.08266768 373.31391199 17.46036093 374.45648002 0 374 C0 362.78 0 351.56 0 340 C4.95 339.67 9.9 339.34 15 339 C21.41425661 337.54221441 27.40557289 335.94604143 32 331 C41.96653782 315.14896379 41.37732492 296.30175799 42 278.25 C44.29042973 212.3198731 44.29042973 212.3198731 64.91015625 190 C66.29780265 187.98880883 66.29780265 187.98880883 65.37890625 185.48046875 C64.05564488 183.10009772 62.69232678 181.32846483 60.875 179.3125 C43.91950219 157.82609672 43.67363702 127.5168667 42.25390625 101.43359375 C42.19595886 100.36962875 42.13801147 99.30566376 42.07830811 98.2094574 C41.84407978 93.84466467 41.61402719 89.47975805 41.39819336 85.11401367 C40.99015593 64.27717646 40.99015593 64.27717646 32.98828125 45.5234375 C32 44 32 44 32 42 C31.42121094 41.71253906 30.84242188 41.42507813 30.24609375 41.12890625 C28.83602338 40.42019262 27.43139326 39.70043581 26.03515625 38.96484375 C25.38417969 38.62582031 24.73320313 38.28679687 24.0625 37.9375 C23.41410156 37.59589844 22.76570312 37.25429688 22.09765625 36.90234375 C15.27203813 33.966184 7.11372705 34.47424847 0 34 C0 22.78 0 11.56 0 0 Z" transform="translate(654,325)"/>
|
|
383
|
-
<path fill="white" d="M0 0 C3.444375 0.04125 6.88875 0.0825 10.4375 0.125 C10.4375 11.345 10.4375 22.565 10.4375 34.125 C7.83875 34.2075 5.24 34.29 2.5625 34.375 C-7.18272292 34.85729903 -15.63749007 36.71684985 -22.5625 44.125 C-31.49595906 57.5251886 -31.12984766 74.21365918 -31.625 89.6875 C-34.18432686 164.24320576 -34.18432686 164.24320576 -54.375 183.4765625 C-55.74969183 185.03433577 -55.74969183 185.03433577 -55.515625 186.95703125 C-54.17099734 190.0155081 -52.28807488 192.49561568 -50.3125 195.1875 C-32.54496946 220.15391355 -32.63824135 251.51444506 -31.51293945 280.92919922 C-31.08045868 292.11365858 -30.51897291 303.08447592 -28.5625 314.125 C-28.43262695 314.88192139 -28.30275391 315.63884277 -28.16894531 316.41870117 C-26.61388783 323.91215705 -23.50529382 330.13896804 -17.1875 334.5625 C-8.59143743 340.04835084 0.27828442 339.49004903 10.4375 340.125 C10.4375 351.345 10.4375 362.565 10.4375 374.125 C-11.03507606 374.69006779 -28.20349315 372.92712593 -45.375 358.5625 C-68.63112564 336.25560398 -67.21470802 299.23895394 -68.0625 269.5625 C-68.59361144 237.84268541 -68.59361144 237.84268541 -82.5625 210.125 C-89.22872268 204.50037462 -95.95018781 203.27807805 -104.5625 201.125 C-104.5625 191.885 -104.5625 182.645 -104.5625 173.125 C-102.0875 172.444375 -99.6125 171.76375 -97.0625 171.0625 C-88.61410179 168.53529591 -83.39407037 165.21504609 -78.3125 157.875 C-77.69451944 156.64176126 -77.11369297 155.38950152 -76.5625 154.125 C-76.05783203 152.97451172 -76.05783203 152.97451172 -75.54296875 151.80078125 C-70.10324087 138.17090127 -68.58488302 123.17691663 -68.1328125 108.6171875 C-68.0590342 106.55597377 -67.98479985 104.49477633 -67.91015625 102.43359375 C-67.79799647 99.2401961 -67.68897443 96.04681123 -67.58837891 92.85302734 C-67.22538737 81.52946225 -66.65494051 70.32073083 -65.13671875 59.0859375 C-64.95793686 57.75983963 -64.95793686 57.75983963 -64.77554321 56.4069519 C-62.24372342 39.06207822 -55.12155189 23.04594995 -40.9609375 12.1171875 C-28.07509054 3.53900119 -15.33988115 -0.26186367 0 0 Z" transform="translate(359.5625,324.875)"/>
|
|
384
|
-
<path fill="white" d="M0 0 C9.89334431 8.68950817 14.30034619 23.01452361 15.24373245 35.79419899 C15.49099471 41.77148785 15.42334062 47.74978768 15.37109375 53.73046875 C15.36548489 55.63859724 15.36122091 57.54673011 15.35823059 59.4548645 C15.34688325 64.42950786 15.31750548 69.40388024 15.28411865 74.37841797 C15.25319735 79.47359555 15.23967854 84.56881775 15.22460938 89.6640625 C15.19262409 99.62643911 15.13994121 109.58854505 15.078125 119.55078125 C3.528125 119.55078125 -8.021875 119.55078125 -19.921875 119.55078125 C-19.97085938 114.4203125 -20.01984375 109.28984375 -20.0703125 104.00390625 C-20.10574492 100.73175245 -20.14173112 97.45962313 -20.1796875 94.1875 C-20.23973228 89.00671097 -20.29785091 83.82595572 -20.34375 78.64501953 C-20.38093086 74.46275871 -20.42737419 70.28068941 -20.47993851 66.09859467 C-20.49830992 64.51204578 -20.51347972 62.92545612 -20.52521896 61.3388443 C-20.22141003 42.05064114 -20.22141003 42.05064114 -28.921875 25.55078125 C-33.2097739 21.98892101 -37.29807009 19.87523153 -42.921875 19.55078125 C-43.79714844 19.48890625 -44.67242188 19.42703125 -45.57421875 19.36328125 C-54.66067243 18.98906437 -62.9621186 20.4280254 -69.859375 26.73828125 C-76.14726535 33.73487866 -78.0525657 41.92333342 -78.12719727 51.07324219 C-78.13709686 51.82485123 -78.14699646 52.57646027 -78.15719604 53.35084534 C-78.18871966 55.82891721 -78.21353223 58.30700823 -78.23828125 60.78515625 C-78.25885867 62.50580334 -78.27985536 64.22644545 -78.30125427 65.94708252 C-78.35639351 70.47125217 -78.40583867 74.99546682 -78.45410156 79.51971436 C-78.51321858 84.95049451 -78.57940167 90.38119259 -78.64440155 95.81190491 C-78.74230855 104.0581468 -78.83123469 112.30444185 -78.921875 120.55078125 C-90.801875 120.55078125 -102.681875 120.55078125 -114.921875 120.55078125 C-114.921875 77.65078125 -114.921875 34.75078125 -114.921875 -9.44921875 C-103.701875 -9.44921875 -92.481875 -9.44921875 -80.921875 -9.44921875 C-79.96000569 -5.60174152 -79.61528473 -2.14754023 -79.359375 1.80078125 C-79.27558594 3.0640625 -79.19179688 4.32734375 -79.10546875 5.62890625 C-79.04488281 6.593125 -78.98429688 7.55734375 -78.921875 8.55078125 C-78.48875 7.72578125 -78.055625 6.90078125 -77.609375 6.05078125 C-71.50314599 -3.01214812 -59.57220635 -8.76116827 -49.16015625 -11.05859375 C-31.06340614 -13.24155516 -14.8555768 -11.20207112 0 0 Z" transform="translate(613.921875,481.44921875)"/>
|
|
385
|
-
<path fill="white" d="M0 0 C1.53906801 1.53906801 1.16955456 2.91263628 1.1875 5.0625 C1.1451715 9.92322255 0.65815533 14.68227908 0.0625 19.5 C-0.02427002 20.20648682 -0.11104004 20.91297363 -0.20043945 21.64086914 C-0.86920125 26.7384025 -0.86920125 26.7384025 -2 29 C-2.96808594 28.84144531 -3.93617188 28.68289063 -4.93359375 28.51953125 C-9.31081865 27.89956204 -13.64601408 27.74275212 -18.0625 27.6875 C-18.83916016 27.65849609 -19.61582031 27.62949219 -20.41601562 27.59960938 C-25.75566236 27.54083257 -28.83098013 28.36372264 -33 32 C-37.31404494 38.3211768 -37.31404494 38.3211768 -37 53 C-25.78 53 -14.56 53 -3 53 C-3 62.57 -3 72.14 -3 82 C-14.55 82 -26.1 82 -38 82 C-38 115 -38 148 -38 182 C-49.55 182 -61.1 182 -73 182 C-73 149 -73 116 -73 82 C-79.93 82 -86.86 82 -94 82 C-94 72.43 -94 62.86 -94 53 C-87.07 53 -80.14 53 -73 53 C-73.04125 50.6075 -73.0825 48.215 -73.125 45.75 C-73.17827085 31.60875021 -70.96095372 19.48048613 -61.0078125 8.81640625 C-54.5981324 3.0177657 -47.30019677 0.02408307 -39 -2 C-38.37625488 -2.17200928 -37.75250977 -2.34401855 -37.10986328 -2.52124023 C-25.33848182 -5.19234404 -11.53065338 -2.96722147 0 0 Z" transform="translate(486,419)"/>
|
|
386
|
-
</svg>`;
|
|
387
|
-
function getFaviconSvg() {
|
|
388
|
-
return FAVICON_SVG;
|
|
389
|
-
}
|
|
390
|
-
var VOICE_CALLBACKS = ["ice", "ace", "pie", "dice", "notify"];
|
|
391
|
-
var NOTIFICATION_EVENTS = ["dice", "notify"];
|
|
392
|
-
function isVoiceCallback(functionName) {
|
|
393
|
-
return VOICE_CALLBACKS.includes(functionName);
|
|
394
|
-
}
|
|
395
|
-
function isNotificationEvent(functionName) {
|
|
396
|
-
return NOTIFICATION_EVENTS.includes(functionName);
|
|
397
|
-
}
|
|
398
|
-
function extractFunctionName(path7, body) {
|
|
399
|
-
if (body?.event && isVoiceCallback(body.event)) {
|
|
400
|
-
return body.event;
|
|
401
|
-
}
|
|
402
|
-
const pathname = path7.split("?")[0];
|
|
403
|
-
const segments = pathname.split("/").filter((s) => s && s !== "*");
|
|
404
|
-
if (segments.length === 1 && isVoiceCallback(segments[0])) {
|
|
405
|
-
return segments[0];
|
|
406
|
-
}
|
|
407
|
-
if (segments.length >= 2 && segments[0] === "webhook") {
|
|
408
|
-
return `${segments[1]}Webhook`;
|
|
409
|
-
}
|
|
410
|
-
if (segments.length === 1 && segments[0] === "webhook") {
|
|
411
|
-
return "webhook";
|
|
412
|
-
}
|
|
413
|
-
return segments[segments.length - 1] || "default";
|
|
414
|
-
}
|
|
415
|
-
function generateRequestId() {
|
|
416
|
-
return `req_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
417
|
-
}
|
|
418
|
-
function findFunctionPath() {
|
|
419
|
-
const fs6 = requireCjs2("fs");
|
|
420
|
-
const distPath = nodePath.join(process.cwd(), "dist", "function.js");
|
|
421
|
-
const rootPath = nodePath.join(process.cwd(), "function.js");
|
|
422
|
-
if (fs6.existsSync(distPath)) {
|
|
423
|
-
return distPath;
|
|
424
|
-
}
|
|
425
|
-
return rootPath;
|
|
426
|
-
}
|
|
427
|
-
function formatSvamlResponse(result, functionName) {
|
|
428
|
-
if (!result || typeof result !== "object") {
|
|
429
|
-
throw new Error(`Voice callback ${functionName} must return a valid SVAML object`);
|
|
430
|
-
}
|
|
431
|
-
const svaml = result;
|
|
432
|
-
if (!svaml.action && !svaml.instructions) {
|
|
433
|
-
throw new Error(`Voice callback ${functionName} must return SVAML with an action or instructions`);
|
|
434
|
-
}
|
|
435
|
-
if (!svaml.instructions) {
|
|
436
|
-
svaml.instructions = [];
|
|
437
|
-
}
|
|
438
|
-
return {
|
|
439
|
-
statusCode: 200,
|
|
440
|
-
headers: { "Content-Type": "application/json" },
|
|
441
|
-
body: svaml
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
function formatCustomResponse(result) {
|
|
445
|
-
if (!result || typeof result !== "object") {
|
|
446
|
-
return {
|
|
447
|
-
statusCode: 200,
|
|
448
|
-
headers: { "Content-Type": "application/json" },
|
|
449
|
-
body: result
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
const response = result;
|
|
453
|
-
if (!response.statusCode) {
|
|
454
|
-
return {
|
|
455
|
-
statusCode: 200,
|
|
456
|
-
headers: { "Content-Type": "application/json" },
|
|
457
|
-
body: result
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
return {
|
|
461
|
-
statusCode: response.statusCode,
|
|
462
|
-
headers: response.headers,
|
|
463
|
-
body: response.body
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
function validateVoiceRequest(body) {
|
|
467
|
-
if (!body || typeof body !== "object") {
|
|
468
|
-
return {
|
|
469
|
-
valid: false,
|
|
470
|
-
error: "Missing request body",
|
|
471
|
-
expectedEvents: [...VOICE_CALLBACKS]
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
const data = body;
|
|
475
|
-
if (!data.event) {
|
|
476
|
-
return {
|
|
477
|
-
valid: false,
|
|
478
|
-
error: "Missing event type in request body",
|
|
479
|
-
expectedEvents: [...VOICE_CALLBACKS]
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
if (!data.callId) {
|
|
483
|
-
return {
|
|
484
|
-
valid: false,
|
|
485
|
-
error: "Missing callId in request body"
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
return { valid: true };
|
|
489
|
-
}
|
|
490
|
-
var noOpCache = {
|
|
491
|
-
set: async () => {
|
|
492
|
-
},
|
|
493
|
-
get: async () => null,
|
|
494
|
-
has: async () => false,
|
|
495
|
-
delete: async () => false,
|
|
496
|
-
extend: async () => false,
|
|
497
|
-
keys: async () => [],
|
|
498
|
-
getMany: async () => ({})
|
|
499
|
-
};
|
|
500
|
-
var noOpStorage = {
|
|
501
|
-
write: async () => {
|
|
502
|
-
},
|
|
503
|
-
read: async () => Buffer.alloc(0),
|
|
504
|
-
list: async () => [],
|
|
505
|
-
exists: async () => false,
|
|
506
|
-
delete: async () => {
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
function buildBaseContext(req, config = {}) {
|
|
510
|
-
return {
|
|
511
|
-
requestId: req?.headers?.["x-request-id"] || generateRequestId(),
|
|
512
|
-
host: req?.headers?.["host"],
|
|
513
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
514
|
-
env: process.env,
|
|
515
|
-
config: {
|
|
516
|
-
projectId: config.projectId || "unknown",
|
|
517
|
-
functionName: config.functionName || "unknown",
|
|
518
|
-
environment: config.environment || "development",
|
|
519
|
-
variables: config.variables
|
|
520
|
-
},
|
|
521
|
-
cache: noOpCache,
|
|
522
|
-
storage: noOpStorage,
|
|
523
|
-
database: "",
|
|
524
|
-
assets: (filename) => {
|
|
525
|
-
const filePath = nodePath.join(process.cwd(), "assets", filename);
|
|
526
|
-
return nodeFs.promises.readFile(filePath, "utf-8");
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
async function handleVoiceCallback(functionName, userFunction, context, callbackData, logger) {
|
|
531
|
-
const handler = userFunction[functionName];
|
|
532
|
-
if (!handler || typeof handler !== "function") {
|
|
533
|
-
if (functionName === "ice") {
|
|
534
|
-
throw new Error(`Voice callback 'ice' not found \u2014 export an ice() function in function.ts`);
|
|
535
|
-
}
|
|
536
|
-
if (logger) {
|
|
537
|
-
logger(`${functionName.toUpperCase()} callback not implemented \u2014 returning 200`);
|
|
538
|
-
}
|
|
539
|
-
return { statusCode: 200, body: {}, headers: {} };
|
|
540
|
-
}
|
|
541
|
-
let result;
|
|
542
|
-
switch (functionName) {
|
|
543
|
-
case "ice":
|
|
544
|
-
result = await handler?.(context, callbackData);
|
|
545
|
-
break;
|
|
546
|
-
case "ace":
|
|
547
|
-
result = await handler?.(context, callbackData);
|
|
548
|
-
break;
|
|
549
|
-
case "pie":
|
|
550
|
-
result = await handler?.(context, callbackData);
|
|
551
|
-
break;
|
|
552
|
-
case "dice":
|
|
553
|
-
result = await handler?.(context, callbackData);
|
|
554
|
-
break;
|
|
555
|
-
case "notify":
|
|
556
|
-
result = await handler?.(context, callbackData);
|
|
557
|
-
break;
|
|
558
|
-
default:
|
|
559
|
-
throw new Error(`Unknown voice callback: ${functionName}`);
|
|
560
|
-
}
|
|
561
|
-
if (logger) {
|
|
562
|
-
logger("Function result:", result);
|
|
563
|
-
}
|
|
564
|
-
if (isNotificationEvent(functionName)) {
|
|
565
|
-
if (logger) {
|
|
566
|
-
logger(`${functionName.toUpperCase()} callback completed`);
|
|
567
|
-
}
|
|
568
|
-
return {
|
|
569
|
-
statusCode: 200,
|
|
570
|
-
headers: { "Content-Type": "application/json" },
|
|
571
|
-
body: {}
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
return formatSvamlResponse(result, functionName);
|
|
575
|
-
}
|
|
576
|
-
async function handleCustomEndpoint(functionName, userFunction, context, request, logger) {
|
|
577
|
-
let handler = userFunction[functionName];
|
|
578
|
-
if ((!handler || typeof handler !== "function") && functionName === "default") {
|
|
579
|
-
handler = userFunction["home"];
|
|
580
|
-
}
|
|
581
|
-
if (!handler || typeof handler !== "function") {
|
|
582
|
-
const available = Object.keys(userFunction).filter((k) => typeof userFunction[k] === "function");
|
|
583
|
-
const pathHint = functionName.endsWith("Webhook") ? `/webhook/${functionName.replace("Webhook", "")}` : `/${functionName}`;
|
|
584
|
-
throw new Error(`No export '${functionName}' found for path ${pathHint}. Available exports: [${available.join(", ")}]. Custom endpoints require a named export matching the last path segment.`);
|
|
585
|
-
}
|
|
586
|
-
const result = await handler(context, request);
|
|
587
|
-
if (logger) {
|
|
588
|
-
logger("Function result:", result);
|
|
589
|
-
}
|
|
590
|
-
return formatCustomResponse(result);
|
|
591
|
-
}
|
|
592
|
-
function createApp(options = {}) {
|
|
593
|
-
const express = requireCjs2("express");
|
|
594
|
-
const app = express();
|
|
595
|
-
const staticDir = options.staticDir ?? (nodeFs.existsSync("./public") ? "./public" : void 0);
|
|
596
|
-
if (staticDir) {
|
|
597
|
-
app.use(express.static(staticDir, {
|
|
598
|
-
index: false,
|
|
599
|
-
// Don't serve index.html for /, we handle that below
|
|
600
|
-
dotfiles: "ignore"
|
|
601
|
-
}));
|
|
602
|
-
}
|
|
603
|
-
const jsonOptions = options.jsonParsingOptions || {
|
|
604
|
-
limit: "10mb",
|
|
605
|
-
allowJson5: true,
|
|
606
|
-
camelCase: {
|
|
607
|
-
deep: true,
|
|
608
|
-
stopPaths: ["custom"],
|
|
609
|
-
exclude: []
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
setupJsonParsing(app, jsonOptions);
|
|
613
|
-
app.use(express.urlencoded({ extended: true, limit: "10mb" }));
|
|
614
|
-
return app;
|
|
615
|
-
}
|
|
616
|
-
function createSinchRuntime() {
|
|
617
|
-
const result = {
|
|
618
|
-
startupHandlers: [],
|
|
619
|
-
wsHandlers: /* @__PURE__ */ new Map()
|
|
620
|
-
};
|
|
621
|
-
const runtime = {
|
|
622
|
-
onStartup(handler) {
|
|
623
|
-
result.startupHandlers.push(handler);
|
|
624
|
-
},
|
|
625
|
-
onWebSocket(path7, handler) {
|
|
626
|
-
const normalizedPath = path7.startsWith("/") ? path7 : `/${path7}`;
|
|
627
|
-
result.wsHandlers.set(normalizedPath, handler);
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
return { runtime, result };
|
|
631
|
-
}
|
|
632
|
-
function installWebSocketHandlers(server, wsHandlers, logger = console.log) {
|
|
633
|
-
if (wsHandlers.size === 0)
|
|
634
|
-
return;
|
|
635
|
-
const { WebSocketServer } = requireCjs2("ws");
|
|
636
|
-
const wss = new WebSocketServer({ noServer: true });
|
|
637
|
-
server.on("upgrade", (req, socket, head) => {
|
|
638
|
-
const pathname = new URL(req.url || "/", `http://${req.headers.host}`).pathname;
|
|
639
|
-
const handler = wsHandlers.get(pathname);
|
|
640
|
-
if (handler) {
|
|
641
|
-
logger(`[WS] Upgrade request for ${pathname}`);
|
|
642
|
-
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
643
|
-
handler(ws, req);
|
|
644
|
-
});
|
|
645
|
-
} else {
|
|
646
|
-
logger(`[WS] No handler for ${pathname} \u2014 rejecting upgrade`);
|
|
647
|
-
socket.destroy();
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
logger(`[WS] WebSocket endpoints registered: ${[...wsHandlers.keys()].join(", ")}`);
|
|
651
|
-
}
|
|
652
|
-
function setupRequestHandler(app, options = {}) {
|
|
653
|
-
const { loadUserFunction = async () => {
|
|
654
|
-
const functionPath = findFunctionPath();
|
|
655
|
-
const functionUrl = pathToFileURL(functionPath).href;
|
|
656
|
-
const module = await import(functionUrl);
|
|
657
|
-
return module.default || module;
|
|
658
|
-
}, buildContext = buildBaseContext, logger = console.log, landingPageEnabled = true, authConfig, authKey, authSecret, onRequestStart = () => {
|
|
659
|
-
}, onRequestEnd = () => {
|
|
660
|
-
} } = options;
|
|
661
|
-
app.use("/{*splat}", async (req, res) => {
|
|
662
|
-
const startTime = Date.now();
|
|
663
|
-
if ((req.method === "GET" || req.method === "HEAD") && req.originalUrl === "/favicon.ico") {
|
|
664
|
-
const svg = getFaviconSvg();
|
|
665
|
-
res.type("image/svg+xml").send(svg);
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
if (req.method === "GET" && req.originalUrl === "/" && landingPageEnabled) {
|
|
669
|
-
const acceptHeader = req.headers.accept || "";
|
|
670
|
-
if (acceptHeader.includes("text/html")) {
|
|
671
|
-
const html = getLandingPageHtml();
|
|
672
|
-
res.type("html").send(html);
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
if (req.method === "GET" && req.originalUrl === "/" && !landingPageEnabled) {
|
|
677
|
-
const indexPath = nodePath.join(process.cwd(), "public", "index.html");
|
|
678
|
-
if (nodeFs.existsSync(indexPath)) {
|
|
679
|
-
res.type("html").sendFile(indexPath);
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
try {
|
|
684
|
-
const functionName = extractFunctionName(req.originalUrl, req.body);
|
|
685
|
-
logger(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${req.method} ${req.path} -> ${functionName}`);
|
|
686
|
-
if (authConfig && authKey && authSecret) {
|
|
687
|
-
const needsAuth = authConfig === "*" || Array.isArray(authConfig) && authConfig.includes(functionName);
|
|
688
|
-
if (needsAuth) {
|
|
689
|
-
const isValid = validateBasicAuth(req.headers.authorization, authKey, authSecret);
|
|
690
|
-
if (!isValid) {
|
|
691
|
-
logger(`[AUTH] Rejected unauthorized request to ${functionName}`);
|
|
692
|
-
res.status(401).set("WWW-Authenticate", 'Basic realm="sinch-function"').json({ error: "Unauthorized" });
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
const protectionMode = getProtectionMode();
|
|
698
|
-
const isDev = process.env.NODE_ENV !== "production" && process.env.ASPNETCORE_ENVIRONMENT !== "Production";
|
|
699
|
-
if (shouldValidateWebhook(protectionMode, isDev)) {
|
|
700
|
-
const sinchClients = getSinchClients();
|
|
701
|
-
if (isVoiceCallback(functionName) && sinchClients.validateWebhookSignature) {
|
|
702
|
-
const rawBody = req.rawBody ?? JSON.stringify(req.body);
|
|
703
|
-
const isValid = sinchClients.validateWebhookSignature({
|
|
704
|
-
method: req.method,
|
|
705
|
-
path: req.path,
|
|
706
|
-
headers: req.headers,
|
|
707
|
-
body: rawBody
|
|
708
|
-
});
|
|
709
|
-
if (!isValid) {
|
|
710
|
-
logger("[SECURITY] Voice webhook signature validation failed");
|
|
711
|
-
res.status(401).json({ error: "Invalid webhook signature" });
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
if (functionName === "conversationWebhook" && sinchClients.validateConversationWebhook) {
|
|
716
|
-
const isValid = sinchClients.validateConversationWebhook(req.headers, req.body);
|
|
717
|
-
if (!isValid) {
|
|
718
|
-
logger("[SECURITY] Conversation webhook signature validation failed");
|
|
719
|
-
res.status(401).json({ error: "Invalid webhook signature" });
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
onRequestStart({ functionName, req });
|
|
725
|
-
const context = buildContext(req);
|
|
726
|
-
const userFunction = await Promise.resolve(loadUserFunction());
|
|
727
|
-
let response;
|
|
728
|
-
if (isVoiceCallback(functionName)) {
|
|
729
|
-
const validation = validateVoiceRequest(req.body);
|
|
730
|
-
if (!validation.valid) {
|
|
731
|
-
res.status(400).json({
|
|
732
|
-
error: validation.error,
|
|
733
|
-
...validation.expectedEvents && { expectedEvents: validation.expectedEvents }
|
|
734
|
-
});
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
response = await handleVoiceCallback(functionName, userFunction, context, req.body, logger);
|
|
738
|
-
} else {
|
|
739
|
-
const request = {
|
|
740
|
-
method: req.method,
|
|
741
|
-
path: req.path,
|
|
742
|
-
query: req.query,
|
|
743
|
-
headers: req.headers,
|
|
744
|
-
body: req.body,
|
|
745
|
-
params: req.params
|
|
746
|
-
};
|
|
747
|
-
response = await handleCustomEndpoint(functionName, userFunction, context, request, logger);
|
|
748
|
-
}
|
|
749
|
-
res.status(response.statusCode);
|
|
750
|
-
if (response.headers) {
|
|
751
|
-
for (const [key, value] of Object.entries(response.headers)) {
|
|
752
|
-
res.setHeader(key, value);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
const contentType = response.headers?.["Content-Type"];
|
|
756
|
-
const isJsonContent = contentType?.includes("application/json");
|
|
757
|
-
const isHtmlContent = contentType?.includes("text/html");
|
|
758
|
-
if (response.body === void 0) {
|
|
759
|
-
res.end();
|
|
760
|
-
} else if (isJsonContent) {
|
|
761
|
-
res.json(response.body);
|
|
762
|
-
} else if (isHtmlContent) {
|
|
763
|
-
res.send(String(response.body));
|
|
764
|
-
} else {
|
|
765
|
-
res.send(response.body);
|
|
766
|
-
}
|
|
767
|
-
const duration = Date.now() - startTime;
|
|
768
|
-
logger(`[${(/* @__PURE__ */ new Date()).toISOString()}] Response sent: ${response.statusCode} (${duration}ms)`);
|
|
769
|
-
onRequestEnd({
|
|
770
|
-
functionName,
|
|
771
|
-
req,
|
|
772
|
-
response,
|
|
773
|
-
duration,
|
|
774
|
-
statusCode: response.statusCode
|
|
775
|
-
});
|
|
776
|
-
} catch (error) {
|
|
777
|
-
const duration = Date.now() - startTime;
|
|
778
|
-
logger("Function execution error:", {
|
|
779
|
-
error: error.message,
|
|
780
|
-
stack: error.stack,
|
|
781
|
-
function: extractFunctionName(req.originalUrl, req.body)
|
|
782
|
-
});
|
|
783
|
-
res.status(500).json({
|
|
784
|
-
error: "Internal server error",
|
|
785
|
-
message: error.message,
|
|
786
|
-
...process.env.NODE_ENV === "development" && { stack: error.stack }
|
|
787
|
-
});
|
|
788
|
-
onRequestEnd({
|
|
789
|
-
functionName: extractFunctionName(req.originalUrl, req.body),
|
|
790
|
-
req,
|
|
791
|
-
error,
|
|
792
|
-
duration,
|
|
793
|
-
statusCode: 500
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// ../runtime-shared/dist/ai/elevenlabs/state.js
|
|
800
|
-
var ElevenLabsStateManager = class {
|
|
801
|
-
state = {
|
|
802
|
-
isConfigured: false
|
|
803
|
-
};
|
|
804
|
-
/**
|
|
805
|
-
* Get the current state
|
|
806
|
-
*/
|
|
807
|
-
getState() {
|
|
808
|
-
return { ...this.state };
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Check if ElevenLabs is configured
|
|
812
|
-
*/
|
|
813
|
-
isConfigured() {
|
|
814
|
-
return this.state.isConfigured;
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Update state with auto-configuration results
|
|
818
|
-
*/
|
|
819
|
-
setConfigured(data) {
|
|
820
|
-
this.state = {
|
|
821
|
-
...data,
|
|
822
|
-
isConfigured: true,
|
|
823
|
-
configuredAt: /* @__PURE__ */ new Date()
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Clear the configuration state
|
|
828
|
-
*/
|
|
829
|
-
clear() {
|
|
830
|
-
this.state = {
|
|
831
|
-
isConfigured: false
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Get the phone number ID for making calls
|
|
836
|
-
*/
|
|
837
|
-
getPhoneNumberId() {
|
|
838
|
-
return this.state.phoneNumberId;
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Get the SIP address for connecting to the agent
|
|
842
|
-
*/
|
|
843
|
-
getSipAddress() {
|
|
844
|
-
return this.state.sipAddress;
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Get the configured agent ID
|
|
848
|
-
*/
|
|
849
|
-
getAgentId() {
|
|
850
|
-
return this.state.agentId;
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
var ElevenLabsState = new ElevenLabsStateManager();
|
|
854
|
-
|
|
855
|
-
// ../runtime-shared/dist/utils/templateRender.js
|
|
856
22
|
import fs from "fs";
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
// ../runtime-shared/dist/utils/functionLoader.js
|
|
864
|
-
import path3 from "path";
|
|
865
|
-
|
|
866
|
-
// src/cache/local.ts
|
|
867
|
-
var globalCache = /* @__PURE__ */ new Map();
|
|
868
|
-
var LocalCache = class {
|
|
869
|
-
cache;
|
|
870
|
-
constructor() {
|
|
871
|
-
this.cache = globalCache;
|
|
872
|
-
}
|
|
873
|
-
async set(key, value, ttlSeconds = 3600) {
|
|
874
|
-
this.cache.set(key, {
|
|
875
|
-
value,
|
|
876
|
-
expiresAt: Date.now() + ttlSeconds * 1e3
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
async get(key) {
|
|
880
|
-
const item = this.cache.get(key);
|
|
881
|
-
if (!item || Date.now() > item.expiresAt) {
|
|
882
|
-
this.cache.delete(key);
|
|
883
|
-
return null;
|
|
884
|
-
}
|
|
885
|
-
return item.value;
|
|
886
|
-
}
|
|
887
|
-
async has(key) {
|
|
888
|
-
const value = await this.get(key);
|
|
889
|
-
return value !== null;
|
|
890
|
-
}
|
|
891
|
-
async delete(key) {
|
|
892
|
-
return this.cache.delete(key);
|
|
893
|
-
}
|
|
894
|
-
async extend(key, additionalSeconds) {
|
|
895
|
-
const item = this.cache.get(key);
|
|
896
|
-
if (!item || Date.now() > item.expiresAt) {
|
|
897
|
-
return false;
|
|
898
|
-
}
|
|
899
|
-
item.expiresAt += additionalSeconds * 1e3;
|
|
900
|
-
return true;
|
|
901
|
-
}
|
|
902
|
-
async keys(pattern = "*") {
|
|
903
|
-
const allKeys = Array.from(this.cache.keys());
|
|
904
|
-
const now = Date.now();
|
|
905
|
-
for (const key of allKeys) {
|
|
906
|
-
const item = this.cache.get(key);
|
|
907
|
-
if (item && now > item.expiresAt) {
|
|
908
|
-
this.cache.delete(key);
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
const validKeys = Array.from(this.cache.keys());
|
|
912
|
-
if (pattern === "*") {
|
|
913
|
-
return validKeys;
|
|
914
|
-
}
|
|
915
|
-
const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
|
|
916
|
-
return validKeys.filter((key) => regex.test(key));
|
|
917
|
-
}
|
|
918
|
-
async getMany(keys) {
|
|
919
|
-
const results = {};
|
|
920
|
-
for (const key of keys) {
|
|
921
|
-
results[key] = await this.get(key);
|
|
922
|
-
}
|
|
923
|
-
return results;
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Clear all entries from the cache
|
|
927
|
-
* (Utility method for testing)
|
|
928
|
-
*/
|
|
929
|
-
async clear() {
|
|
930
|
-
this.cache.clear();
|
|
931
|
-
}
|
|
932
|
-
/**
|
|
933
|
-
* Get the number of entries in the cache
|
|
934
|
-
* (Utility method for debugging)
|
|
935
|
-
*/
|
|
936
|
-
get size() {
|
|
937
|
-
return this.cache.size;
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
function createCacheClient(_projectId, _functionName) {
|
|
941
|
-
return new LocalCache();
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
// src/storage/local.ts
|
|
945
|
-
import * as fs3 from "fs/promises";
|
|
946
|
-
import * as path4 from "path";
|
|
947
|
-
var LocalStorage = class {
|
|
948
|
-
baseDir;
|
|
949
|
-
constructor(baseDir) {
|
|
950
|
-
this.baseDir = baseDir ?? path4.join(process.cwd(), ".sinch", "storage");
|
|
951
|
-
}
|
|
952
|
-
resolvePath(key) {
|
|
953
|
-
const sanitized = key.replace(/^\/+/, "").replace(/\.\./g, "_");
|
|
954
|
-
return path4.join(this.baseDir, sanitized);
|
|
955
|
-
}
|
|
956
|
-
async write(key, data) {
|
|
957
|
-
const filePath = this.resolvePath(key);
|
|
958
|
-
await fs3.mkdir(path4.dirname(filePath), { recursive: true });
|
|
959
|
-
await fs3.writeFile(filePath, data);
|
|
960
|
-
}
|
|
961
|
-
async read(key) {
|
|
962
|
-
const filePath = this.resolvePath(key);
|
|
963
|
-
return fs3.readFile(filePath);
|
|
964
|
-
}
|
|
965
|
-
async list(prefix) {
|
|
966
|
-
const results = [];
|
|
967
|
-
await this.walkDir(this.baseDir, "", results);
|
|
968
|
-
if (prefix) {
|
|
969
|
-
return results.filter((f) => f.startsWith(prefix));
|
|
970
|
-
}
|
|
971
|
-
return results;
|
|
972
|
-
}
|
|
973
|
-
async exists(key) {
|
|
974
|
-
const filePath = this.resolvePath(key);
|
|
975
|
-
try {
|
|
976
|
-
await fs3.access(filePath);
|
|
977
|
-
return true;
|
|
978
|
-
} catch {
|
|
979
|
-
return false;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
async delete(key) {
|
|
983
|
-
const filePath = this.resolvePath(key);
|
|
984
|
-
await fs3.rm(filePath, { force: true });
|
|
985
|
-
}
|
|
986
|
-
async walkDir(dir, relative, results) {
|
|
987
|
-
let entries;
|
|
988
|
-
try {
|
|
989
|
-
entries = await fs3.readdir(dir, { withFileTypes: true });
|
|
990
|
-
} catch {
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
for (const entry of entries) {
|
|
994
|
-
const rel = relative ? `${relative}/${entry.name}` : entry.name;
|
|
995
|
-
if (entry.isDirectory()) {
|
|
996
|
-
await this.walkDir(path4.join(dir, entry.name), rel, results);
|
|
997
|
-
} else {
|
|
998
|
-
results.push(rel);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
};
|
|
1003
|
-
function createStorageClient(baseDir) {
|
|
1004
|
-
return new LocalStorage(baseDir);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
// src/secrets/index.ts
|
|
1008
|
-
import fs4 from "fs";
|
|
1009
|
-
import path5 from "path";
|
|
1010
|
-
import os from "os";
|
|
1011
|
-
import crypto2 from "crypto";
|
|
1012
|
-
|
|
1013
|
-
// src/secrets/keychain.ts
|
|
1014
|
-
import { execFile, spawn } from "child_process";
|
|
1015
|
-
import { promisify } from "util";
|
|
1016
|
-
var execFileAsync = promisify(execFile);
|
|
1017
|
-
function b64(value) {
|
|
1018
|
-
return Buffer.from(value, "utf8").toString("base64");
|
|
1019
|
-
}
|
|
1020
|
-
function psParam(name, value) {
|
|
1021
|
-
return `$${name} = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${b64(value)}'));`;
|
|
1022
|
-
}
|
|
1023
|
-
var WIN32_CRED_READ_SCRIPT = `
|
|
1024
|
-
Add-Type -TypeDefinition @'
|
|
1025
|
-
using System;
|
|
1026
|
-
using System.Runtime.InteropServices;
|
|
1027
|
-
public class CredManager {
|
|
1028
|
-
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
|
|
1029
|
-
private struct CREDENTIAL {
|
|
1030
|
-
public int Flags;
|
|
1031
|
-
public int Type;
|
|
1032
|
-
public IntPtr TargetName;
|
|
1033
|
-
public IntPtr Comment;
|
|
1034
|
-
public long LastWritten;
|
|
1035
|
-
public int CredentialBlobSize;
|
|
1036
|
-
public IntPtr CredentialBlob;
|
|
1037
|
-
public int Persist;
|
|
1038
|
-
public int AttributeCount;
|
|
1039
|
-
public IntPtr Attributes;
|
|
1040
|
-
public IntPtr TargetAlias;
|
|
1041
|
-
public IntPtr UserName;
|
|
1042
|
-
}
|
|
1043
|
-
[DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
|
|
1044
|
-
private static extern bool CredReadW(string target, int type, int flags, out IntPtr cred);
|
|
1045
|
-
[DllImport("advapi32.dll")]
|
|
1046
|
-
private static extern void CredFree(IntPtr cred);
|
|
1047
|
-
public static string Read(string target) {
|
|
1048
|
-
IntPtr credPtr;
|
|
1049
|
-
if (!CredReadW(target, 1, 0, out credPtr)) return null;
|
|
1050
|
-
try {
|
|
1051
|
-
CREDENTIAL c = (CREDENTIAL)Marshal.PtrToStructure(credPtr, typeof(CREDENTIAL));
|
|
1052
|
-
if (c.CredentialBlobSize > 0 && c.CredentialBlob != IntPtr.Zero)
|
|
1053
|
-
return Marshal.PtrToStringUni(c.CredentialBlob, c.CredentialBlobSize / 2);
|
|
1054
|
-
return "";
|
|
1055
|
-
} finally { CredFree(credPtr); }
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
'@
|
|
1059
|
-
$r = [CredManager]::Read($target)
|
|
1060
|
-
if ($r -ne $null) { [Console]::Write($r) }
|
|
1061
|
-
else { exit 1 }
|
|
1062
|
-
`;
|
|
1063
|
-
var WIN32_CRED_WRITE_SCRIPT = `
|
|
1064
|
-
Add-Type -TypeDefinition @'
|
|
1065
|
-
using System;
|
|
1066
|
-
using System.Runtime.InteropServices;
|
|
1067
|
-
using System.Text;
|
|
1068
|
-
public class CredWriter {
|
|
1069
|
-
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
|
|
1070
|
-
private struct CREDENTIAL {
|
|
1071
|
-
public int Flags;
|
|
1072
|
-
public int Type;
|
|
1073
|
-
public string TargetName;
|
|
1074
|
-
public string Comment;
|
|
1075
|
-
public long LastWritten;
|
|
1076
|
-
public int CredentialBlobSize;
|
|
1077
|
-
public IntPtr CredentialBlob;
|
|
1078
|
-
public int Persist;
|
|
1079
|
-
public int AttributeCount;
|
|
1080
|
-
public IntPtr Attributes;
|
|
1081
|
-
public string TargetAlias;
|
|
1082
|
-
public string UserName;
|
|
1083
|
-
}
|
|
1084
|
-
[DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
|
|
1085
|
-
private static extern bool CredWriteW(ref CREDENTIAL cred, int flags);
|
|
1086
|
-
public static bool Write(string target, string password) {
|
|
1087
|
-
byte[] blob = Encoding.Unicode.GetBytes(password);
|
|
1088
|
-
CREDENTIAL c = new CREDENTIAL();
|
|
1089
|
-
c.Type = 1;
|
|
1090
|
-
c.TargetName = target;
|
|
1091
|
-
c.CredentialBlobSize = blob.Length;
|
|
1092
|
-
c.CredentialBlob = Marshal.AllocHGlobal(blob.Length);
|
|
1093
|
-
Marshal.Copy(blob, 0, c.CredentialBlob, blob.Length);
|
|
1094
|
-
c.Persist = 2;
|
|
1095
|
-
try { return CredWriteW(ref c, 0); }
|
|
1096
|
-
finally { Marshal.FreeHGlobal(c.CredentialBlob); }
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
'@
|
|
1100
|
-
if (-not [CredWriter]::Write($target, $password)) { exit 1 }
|
|
1101
|
-
`;
|
|
1102
|
-
var WIN32_CRED_DELETE_SCRIPT = `
|
|
1103
|
-
Add-Type -TypeDefinition @'
|
|
1104
|
-
using System;
|
|
1105
|
-
using System.Runtime.InteropServices;
|
|
1106
|
-
public class CredDeleter {
|
|
1107
|
-
[DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
|
|
1108
|
-
private static extern bool CredDeleteW(string target, int type, int flags);
|
|
1109
|
-
public static bool Delete(string target) { return CredDeleteW(target, 1, 0); }
|
|
1110
|
-
}
|
|
1111
|
-
'@
|
|
1112
|
-
if (-not [CredDeleter]::Delete($target)) { exit 1 }
|
|
1113
|
-
`;
|
|
1114
|
-
function winTarget(service, account) {
|
|
1115
|
-
return `${service}/${account}`;
|
|
1116
|
-
}
|
|
1117
|
-
var windowsKeychain = {
|
|
1118
|
-
async getPassword(service, account) {
|
|
1119
|
-
try {
|
|
1120
|
-
const params = psParam("target", winTarget(service, account));
|
|
1121
|
-
const { stdout } = await execFileAsync(
|
|
1122
|
-
"powershell.exe",
|
|
1123
|
-
["-NoProfile", "-NonInteractive", "-Command", params + WIN32_CRED_READ_SCRIPT],
|
|
1124
|
-
{ timeout: 15e3, windowsHide: true }
|
|
1125
|
-
);
|
|
1126
|
-
return stdout;
|
|
1127
|
-
} catch {
|
|
1128
|
-
return null;
|
|
1129
|
-
}
|
|
1130
|
-
},
|
|
1131
|
-
async setPassword(service, account, password) {
|
|
1132
|
-
const params = psParam("target", winTarget(service, account)) + psParam("password", password);
|
|
1133
|
-
await execFileAsync(
|
|
1134
|
-
"powershell.exe",
|
|
1135
|
-
["-NoProfile", "-NonInteractive", "-Command", params + WIN32_CRED_WRITE_SCRIPT],
|
|
1136
|
-
{ timeout: 15e3, windowsHide: true }
|
|
1137
|
-
);
|
|
1138
|
-
},
|
|
1139
|
-
async deletePassword(service, account) {
|
|
1140
|
-
try {
|
|
1141
|
-
const params = psParam("target", winTarget(service, account));
|
|
1142
|
-
await execFileAsync(
|
|
1143
|
-
"powershell.exe",
|
|
1144
|
-
["-NoProfile", "-NonInteractive", "-Command", params + WIN32_CRED_DELETE_SCRIPT],
|
|
1145
|
-
{ timeout: 15e3, windowsHide: true }
|
|
1146
|
-
);
|
|
1147
|
-
return true;
|
|
1148
|
-
} catch {
|
|
1149
|
-
return false;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
};
|
|
1153
|
-
var macKeychain = {
|
|
1154
|
-
async getPassword(service, account) {
|
|
1155
|
-
try {
|
|
1156
|
-
const { stdout } = await execFileAsync(
|
|
1157
|
-
"security",
|
|
1158
|
-
["find-generic-password", "-s", service, "-a", account, "-w"],
|
|
1159
|
-
{ timeout: 15e3 }
|
|
1160
|
-
);
|
|
1161
|
-
return stdout.trimEnd();
|
|
1162
|
-
} catch {
|
|
1163
|
-
return null;
|
|
1164
|
-
}
|
|
1165
|
-
},
|
|
1166
|
-
async setPassword(service, account, password) {
|
|
1167
|
-
await execFileAsync(
|
|
1168
|
-
"security",
|
|
1169
|
-
["add-generic-password", "-U", "-s", service, "-a", account, "-w", password],
|
|
1170
|
-
{ timeout: 15e3 }
|
|
1171
|
-
);
|
|
1172
|
-
},
|
|
1173
|
-
async deletePassword(service, account) {
|
|
1174
|
-
try {
|
|
1175
|
-
await execFileAsync(
|
|
1176
|
-
"security",
|
|
1177
|
-
["delete-generic-password", "-s", service, "-a", account],
|
|
1178
|
-
{ timeout: 15e3 }
|
|
1179
|
-
);
|
|
1180
|
-
return true;
|
|
1181
|
-
} catch {
|
|
1182
|
-
return false;
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
function debugKeychain(op, err) {
|
|
1187
|
-
if (!process.env.DEBUG?.includes("sinch:keychain")) return;
|
|
1188
|
-
const e = err;
|
|
1189
|
-
const stderr = e.stderr?.toString() ?? "";
|
|
1190
|
-
const code = e.code ?? e.exitCode ?? "?";
|
|
1191
|
-
const message = e.message ?? String(err);
|
|
1192
|
-
console.debug(`[keychain] secret-tool ${op} failed (code=${code}): ${stderr || message}`);
|
|
1193
|
-
}
|
|
1194
|
-
var linuxKeychain = {
|
|
1195
|
-
async getPassword(service, account) {
|
|
1196
|
-
try {
|
|
1197
|
-
const { stdout } = await execFileAsync(
|
|
1198
|
-
"secret-tool",
|
|
1199
|
-
["lookup", "service", service, "account", account],
|
|
1200
|
-
{ timeout: 15e3 }
|
|
1201
|
-
);
|
|
1202
|
-
return stdout.trimEnd();
|
|
1203
|
-
} catch (err) {
|
|
1204
|
-
debugKeychain("lookup", err);
|
|
1205
|
-
return null;
|
|
1206
|
-
}
|
|
1207
|
-
},
|
|
1208
|
-
// secret-tool reads password from stdin (avoids exposing it in process args)
|
|
1209
|
-
async setPassword(service, account, password) {
|
|
1210
|
-
const child = spawn(
|
|
1211
|
-
"secret-tool",
|
|
1212
|
-
["store", "--label", `${service}/${account}`, "service", service, "account", account],
|
|
1213
|
-
{ stdio: ["pipe", "pipe", "pipe"] }
|
|
1214
|
-
);
|
|
1215
|
-
let stderr = "";
|
|
1216
|
-
child.stderr?.on("data", (chunk) => {
|
|
1217
|
-
stderr += chunk.toString();
|
|
1218
|
-
});
|
|
1219
|
-
child.stdin.write(password);
|
|
1220
|
-
child.stdin.end();
|
|
1221
|
-
await new Promise((resolve, reject) => {
|
|
1222
|
-
child.on("close", (code) => {
|
|
1223
|
-
if (code === 0) {
|
|
1224
|
-
resolve();
|
|
1225
|
-
} else {
|
|
1226
|
-
const err = Object.assign(
|
|
1227
|
-
new Error(
|
|
1228
|
-
`secret-tool store failed (exit ${code})${stderr ? ": " + stderr.trim() : ""}`
|
|
1229
|
-
),
|
|
1230
|
-
{ stderr, exitCode: code }
|
|
1231
|
-
);
|
|
1232
|
-
debugKeychain("store", err);
|
|
1233
|
-
reject(err);
|
|
1234
|
-
}
|
|
1235
|
-
});
|
|
1236
|
-
child.on("error", (err) => {
|
|
1237
|
-
debugKeychain("store", err);
|
|
1238
|
-
reject(err);
|
|
1239
|
-
});
|
|
1240
|
-
});
|
|
1241
|
-
},
|
|
1242
|
-
async deletePassword(service, account) {
|
|
1243
|
-
try {
|
|
1244
|
-
await execFileAsync(
|
|
1245
|
-
"secret-tool",
|
|
1246
|
-
["clear", "service", service, "account", account],
|
|
1247
|
-
{ timeout: 15e3 }
|
|
1248
|
-
);
|
|
1249
|
-
return true;
|
|
1250
|
-
} catch (err) {
|
|
1251
|
-
debugKeychain("clear", err);
|
|
1252
|
-
return false;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
};
|
|
1256
|
-
function getBackend() {
|
|
1257
|
-
switch (process.platform) {
|
|
1258
|
-
case "win32":
|
|
1259
|
-
return windowsKeychain;
|
|
1260
|
-
case "darwin":
|
|
1261
|
-
return macKeychain;
|
|
1262
|
-
default:
|
|
1263
|
-
return linuxKeychain;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
var backend = getBackend();
|
|
1267
|
-
async function getPassword(service, account) {
|
|
1268
|
-
return backend.getPassword(service, account);
|
|
1269
|
-
}
|
|
1270
|
-
async function setPassword(service, account, password) {
|
|
1271
|
-
return backend.setPassword(service, account, password);
|
|
1272
|
-
}
|
|
1273
|
-
async function deletePassword(service, account) {
|
|
1274
|
-
return backend.deletePassword(service, account);
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
// src/secrets/index.ts
|
|
1278
|
-
var SecretsLoader = class {
|
|
1279
|
-
SERVICE_NAME = "sinch-cli";
|
|
1280
|
-
username = os.userInfo().username;
|
|
1281
|
-
/**
|
|
1282
|
-
* Load secrets from OS keychain for variables declared in .env
|
|
1283
|
-
* Only loads secrets that have empty values in .env (security best practice)
|
|
1284
|
-
*/
|
|
1285
|
-
async loadFromKeychain() {
|
|
1286
|
-
if (process.env.NODE_ENV === "production") {
|
|
1287
|
-
return false;
|
|
1288
|
-
}
|
|
1289
|
-
try {
|
|
1290
|
-
const envPath = path5.join(process.cwd(), ".env");
|
|
1291
|
-
if (!fs4.existsSync(envPath)) {
|
|
1292
|
-
console.debug("[Secrets] No .env file found, skipping keychain load");
|
|
1293
|
-
return false;
|
|
1294
|
-
}
|
|
1295
|
-
const envContent = fs4.readFileSync(envPath, "utf8");
|
|
1296
|
-
const envLines = envContent.replace(/\r\n/g, "\n").split("\n");
|
|
1297
|
-
const secretsToLoad = [];
|
|
1298
|
-
envLines.forEach((line) => {
|
|
1299
|
-
const trimmedLine = line.replace(/\r$/, "").trim();
|
|
1300
|
-
if (trimmedLine && !trimmedLine.startsWith("#")) {
|
|
1301
|
-
const equalIndex = trimmedLine.indexOf("=");
|
|
1302
|
-
if (equalIndex !== -1) {
|
|
1303
|
-
const envKey = trimmedLine.substring(0, equalIndex).trim();
|
|
1304
|
-
const envValue = trimmedLine.substring(equalIndex + 1).trim();
|
|
1305
|
-
if (envKey && envValue === "" && !process.env[envKey]) {
|
|
1306
|
-
secretsToLoad.push(envKey);
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
});
|
|
1311
|
-
if (secretsToLoad.length === 0) {
|
|
1312
|
-
console.debug("[Secrets] No empty variables found in .env");
|
|
1313
|
-
return false;
|
|
1314
|
-
}
|
|
1315
|
-
let secretsLoaded = 0;
|
|
1316
|
-
if (secretsToLoad.includes("PROJECT_ID_API_SECRET")) {
|
|
1317
|
-
let apiSecret = await getPassword(this.SERVICE_NAME, `${this.username}-keySecret`);
|
|
1318
|
-
let fromPlaintext = false;
|
|
1319
|
-
if (!apiSecret) {
|
|
1320
|
-
apiSecret = this.readProfilePlaintext("keySecretPlaintext");
|
|
1321
|
-
fromPlaintext = !!apiSecret;
|
|
1322
|
-
}
|
|
1323
|
-
if (apiSecret) {
|
|
1324
|
-
process.env.PROJECT_ID_API_SECRET = apiSecret;
|
|
1325
|
-
if (fromPlaintext) {
|
|
1326
|
-
this.warnPlaintext("PROJECT_ID_API_SECRET");
|
|
1327
|
-
} else {
|
|
1328
|
-
console.log("\u2705 Loaded PROJECT_ID_API_SECRET from secure storage");
|
|
1329
|
-
}
|
|
1330
|
-
secretsLoaded++;
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
if (secretsToLoad.includes("VOICE_APPLICATION_SECRET")) {
|
|
1334
|
-
const applicationKey = process.env.VOICE_APPLICATION_KEY || this.getApplicationKeyFromConfig();
|
|
1335
|
-
let appSecret = null;
|
|
1336
|
-
let fromPlaintext = false;
|
|
1337
|
-
if (applicationKey) {
|
|
1338
|
-
appSecret = await getPassword(this.SERVICE_NAME, applicationKey);
|
|
1339
|
-
}
|
|
1340
|
-
if (!appSecret) {
|
|
1341
|
-
appSecret = this.readProfilePlaintext("applicationSecretPlaintext");
|
|
1342
|
-
fromPlaintext = !!appSecret;
|
|
1343
|
-
}
|
|
1344
|
-
if (appSecret) {
|
|
1345
|
-
process.env.VOICE_APPLICATION_SECRET = appSecret;
|
|
1346
|
-
if (fromPlaintext) {
|
|
1347
|
-
this.warnPlaintext("VOICE_APPLICATION_SECRET");
|
|
1348
|
-
} else {
|
|
1349
|
-
console.log("\u2705 Loaded VOICE_APPLICATION_SECRET from secure storage");
|
|
1350
|
-
}
|
|
1351
|
-
secretsLoaded++;
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
const customSecretNames = secretsToLoad.filter(
|
|
1355
|
-
(secretName) => secretName !== "PROJECT_ID_API_SECRET" && secretName !== "VOICE_APPLICATION_SECRET"
|
|
1356
|
-
);
|
|
1357
|
-
const customSecrets = await this.loadCustomSecrets(customSecretNames);
|
|
1358
|
-
for (const secretName of Object.keys(customSecrets)) {
|
|
1359
|
-
console.log(`\u2705 Loaded ${secretName} from secure storage`);
|
|
1360
|
-
secretsLoaded++;
|
|
1361
|
-
}
|
|
1362
|
-
if (secretsLoaded === 0) {
|
|
1363
|
-
const probe = await this.probeKeychain();
|
|
1364
|
-
if (!probe.ok) {
|
|
1365
|
-
console.warn(`\u26A0\uFE0F Keychain unreachable: ${probe.reason}`);
|
|
1366
|
-
if (probe.hint) console.warn(` ${probe.hint}`);
|
|
1367
|
-
console.warn(" Sinch CLI may have stored credentials in plaintext config instead.");
|
|
1368
|
-
console.warn(" Run `sinch auth status` to verify, or re-run `sinch auth login`.");
|
|
1369
|
-
} else {
|
|
1370
|
-
console.log("\u2139\uFE0F No secrets found in secure storage for declared variables");
|
|
1371
|
-
console.log("\u{1F4A1} To configure Sinch auth: sinch auth login");
|
|
1372
|
-
console.log("\u{1F4A1} To add custom secrets: sinch secrets add <KEY> <VALUE>");
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
return secretsLoaded > 0;
|
|
1376
|
-
} catch (error) {
|
|
1377
|
-
console.error("[Secrets] Unexpected error:", error.message);
|
|
1378
|
-
console.log("\u{1F4A1} To manage secrets manually, use: sinch secrets");
|
|
1379
|
-
return false;
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Helper to get application key from sinch.json
|
|
1384
|
-
*/
|
|
1385
|
-
getApplicationKeyFromConfig() {
|
|
1386
|
-
try {
|
|
1387
|
-
const sinchJsonPath = path5.join(process.cwd(), "sinch.json");
|
|
1388
|
-
if (fs4.existsSync(sinchJsonPath)) {
|
|
1389
|
-
const sinchConfig = JSON.parse(fs4.readFileSync(sinchJsonPath, "utf8"));
|
|
1390
|
-
return sinchConfig.voiceAppId || sinchConfig.applicationKey || null;
|
|
1391
|
-
}
|
|
1392
|
-
} catch (error) {
|
|
1393
|
-
console.debug("[Secrets] Could not read sinch.json:", error.message);
|
|
1394
|
-
}
|
|
1395
|
-
return null;
|
|
1396
|
-
}
|
|
1397
|
-
/**
|
|
1398
|
-
* Helper to get function name from sinch.json
|
|
1399
|
-
*/
|
|
1400
|
-
getFunctionNameFromConfig() {
|
|
1401
|
-
try {
|
|
1402
|
-
const sinchJsonPath = path5.join(process.cwd(), "sinch.json");
|
|
1403
|
-
if (fs4.existsSync(sinchJsonPath)) {
|
|
1404
|
-
const sinchConfig = JSON.parse(fs4.readFileSync(sinchJsonPath, "utf8"));
|
|
1405
|
-
return sinchConfig.name || null;
|
|
1406
|
-
}
|
|
1407
|
-
} catch (error) {
|
|
1408
|
-
console.debug("[Secrets] Could not read sinch.json:", error.message);
|
|
1409
|
-
}
|
|
1410
|
-
return null;
|
|
1411
|
-
}
|
|
1412
|
-
/**
|
|
1413
|
-
* Read a plaintext credential field from the active CLI profile.
|
|
1414
|
-
* Scoped to the canonical pair (keySecretPlaintext, applicationSecretPlaintext)
|
|
1415
|
-
* that sinch-cli writes when the OS keychain is unreachable. See
|
|
1416
|
-
* sinch-cli/src/lib/credentials.ts store() for the writer side.
|
|
1417
|
-
*/
|
|
1418
|
-
readProfilePlaintext(field) {
|
|
1419
|
-
try {
|
|
1420
|
-
const home = os.homedir();
|
|
1421
|
-
const metaPath = path5.join(home, ".sinch", "config.json");
|
|
1422
|
-
let activeProfile = "default";
|
|
1423
|
-
if (fs4.existsSync(metaPath)) {
|
|
1424
|
-
const meta = JSON.parse(fs4.readFileSync(metaPath, "utf8"));
|
|
1425
|
-
if (typeof meta.activeProfile === "string" && meta.activeProfile) {
|
|
1426
|
-
activeProfile = meta.activeProfile;
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
if (/[\\/]/.test(activeProfile) || activeProfile.includes("..")) {
|
|
1430
|
-
return null;
|
|
1431
|
-
}
|
|
1432
|
-
const profilePath = path5.join(home, ".sinch", "profiles", `${activeProfile}.json`);
|
|
1433
|
-
if (!fs4.existsSync(profilePath)) return null;
|
|
1434
|
-
const profile = JSON.parse(fs4.readFileSync(profilePath, "utf8"));
|
|
1435
|
-
const value = profile[field];
|
|
1436
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
1437
|
-
} catch (err) {
|
|
1438
|
-
console.debug("[Secrets] Could not read plaintext profile fallback:", String(err));
|
|
1439
|
-
return null;
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* Active write/read/delete round-trip to verify the OS keychain is reachable.
|
|
1444
|
-
* Used to distinguish "keychain works but no entries stored" from "keychain
|
|
1445
|
-
* unreachable" so error messages can be specific. Cost: 3 secret-tool /
|
|
1446
|
-
* security / PowerShell invocations, only when no secrets were loaded.
|
|
1447
|
-
*/
|
|
1448
|
-
async probeKeychain() {
|
|
1449
|
-
const sentinelAccount = `__sinch_probe_${crypto2.randomUUID()}`;
|
|
1450
|
-
const sentinelValue = crypto2.randomUUID();
|
|
1451
|
-
try {
|
|
1452
|
-
await setPassword(this.SERVICE_NAME, sentinelAccount, sentinelValue);
|
|
1453
|
-
} catch (err) {
|
|
1454
|
-
return {
|
|
1455
|
-
ok: false,
|
|
1456
|
-
reason: `write failed (${err instanceof Error ? err.message : String(err)})`,
|
|
1457
|
-
hint: this.platformHint()
|
|
1458
|
-
};
|
|
1459
|
-
}
|
|
1460
|
-
let readBack = null;
|
|
1461
|
-
try {
|
|
1462
|
-
readBack = await getPassword(this.SERVICE_NAME, sentinelAccount);
|
|
1463
|
-
} catch {
|
|
1464
|
-
}
|
|
1465
|
-
try {
|
|
1466
|
-
await deletePassword(this.SERVICE_NAME, sentinelAccount);
|
|
1467
|
-
} catch {
|
|
1468
|
-
}
|
|
1469
|
-
if (readBack !== sentinelValue) {
|
|
1470
|
-
return {
|
|
1471
|
-
ok: false,
|
|
1472
|
-
reason: "write reported success but value cannot be read back",
|
|
1473
|
-
hint: this.platformHint()
|
|
1474
|
-
};
|
|
1475
|
-
}
|
|
1476
|
-
return { ok: true };
|
|
1477
|
-
}
|
|
1478
|
-
platformHint() {
|
|
1479
|
-
if (process.platform === "linux") {
|
|
1480
|
-
return 'On Linux/WSL: sudo apt install libsecret-tools gnome-keyring dbus-x11 && eval "$(gnome-keyring-daemon --start --components=secrets)"';
|
|
1481
|
-
}
|
|
1482
|
-
if (process.platform === "darwin") {
|
|
1483
|
-
return "On macOS: unlock the login keychain (Keychain Access app) and retry";
|
|
1484
|
-
}
|
|
1485
|
-
return "On Windows: ensure Credential Manager is accessible from this user session";
|
|
1486
|
-
}
|
|
1487
|
-
warnPlaintext(envVar) {
|
|
1488
|
-
console.warn(
|
|
1489
|
-
`\u26A0\uFE0F Loaded ${envVar} from plaintext config (~/.sinch/profiles/<active>.json) \u2014 keychain unavailable.`
|
|
1490
|
-
);
|
|
1491
|
-
console.warn(` ${this.platformHint()}`);
|
|
1492
|
-
}
|
|
1493
|
-
/**
|
|
1494
|
-
* Load custom secrets added via the 'sinch secrets' command
|
|
1495
|
-
*/
|
|
1496
|
-
async loadCustomSecrets(secretNames = []) {
|
|
1497
|
-
const secrets = {};
|
|
1498
|
-
if (process.env.NODE_ENV === "production") {
|
|
1499
|
-
return secrets;
|
|
1500
|
-
}
|
|
1501
|
-
try {
|
|
1502
|
-
const functionName = this.getFunctionNameFromConfig();
|
|
1503
|
-
for (const secretName of secretNames) {
|
|
1504
|
-
const value = functionName && await getPassword(this.SERVICE_NAME, `${functionName}-${secretName}`) || await getPassword(this.SERVICE_NAME, `custom-${secretName}`);
|
|
1505
|
-
if (value) {
|
|
1506
|
-
secrets[secretName] = value;
|
|
1507
|
-
process.env[secretName] = value;
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
} catch (error) {
|
|
1511
|
-
console.debug("[Secrets] Could not load custom secrets:", error.message);
|
|
1512
|
-
}
|
|
1513
|
-
return secrets;
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* Check if the native keychain is available.
|
|
1517
|
-
* Always true — no native npm deps required. The underlying OS tool
|
|
1518
|
-
* (secret-tool, security, CredManager) may still be absent, in which
|
|
1519
|
-
* case getPassword() silently returns null per credential.
|
|
1520
|
-
*/
|
|
1521
|
-
async isAvailable() {
|
|
1522
|
-
return true;
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
|
-
var secretsLoader = new SecretsLoader();
|
|
1526
|
-
|
|
1527
|
-
// src/tunnel/index.ts
|
|
1528
|
-
import WebSocket from "ws";
|
|
1529
|
-
import axios from "axios";
|
|
1530
|
-
|
|
1531
|
-
// src/tunnel/webhook-config.ts
|
|
1532
|
-
import { SinchClient as SinchClient2 } from "@sinch/sdk-core";
|
|
1533
|
-
import { randomBytes } from "crypto";
|
|
1534
|
-
var SINCH_FN_URL_PATTERN = /\.fn(-\w+)?\.sinch\.com/;
|
|
1535
|
-
function isOurWebhook(target) {
|
|
1536
|
-
return !!target && SINCH_FN_URL_PATTERN.test(target);
|
|
1537
|
-
}
|
|
1538
|
-
function isTunnelUrl(target) {
|
|
1539
|
-
return !!target && target.includes("tunnel.fn");
|
|
1540
|
-
}
|
|
1541
|
-
async function configureConversationWebhooks(webhookUrl, config) {
|
|
1542
|
-
try {
|
|
1543
|
-
const conversationAppId = process.env.CONVERSATION_APP_ID;
|
|
1544
|
-
const projectId = process.env.PROJECT_ID;
|
|
1545
|
-
const keyId = process.env.PROJECT_ID_API_KEY;
|
|
1546
|
-
const keySecret = process.env.PROJECT_ID_API_SECRET;
|
|
1547
|
-
if (!conversationAppId || !projectId || !keyId || !keySecret) {
|
|
1548
|
-
console.log("\u{1F4A1} Conversation API not fully configured - skipping webhook setup");
|
|
1549
|
-
return;
|
|
1550
|
-
}
|
|
1551
|
-
console.log(`\u{1F4AC} Conversation webhook URL: ${webhookUrl}`);
|
|
1552
|
-
const sinchClient = new SinchClient2({
|
|
1553
|
-
projectId,
|
|
1554
|
-
keyId,
|
|
1555
|
-
keySecret
|
|
1556
|
-
});
|
|
1557
|
-
const webhooksResult = await sinchClient.conversation.webhooks.list({
|
|
1558
|
-
app_id: conversationAppId
|
|
1559
|
-
});
|
|
1560
|
-
const existingWebhooks = webhooksResult.webhooks || [];
|
|
1561
|
-
const deployedWebhook = existingWebhooks.find(
|
|
1562
|
-
(w) => isOurWebhook(w.target)
|
|
1563
|
-
);
|
|
1564
|
-
if (!deployedWebhook || !deployedWebhook.id) {
|
|
1565
|
-
console.log("\u26A0\uFE0F No deployed webhook found \u2014 deploy first");
|
|
1566
|
-
return;
|
|
1567
|
-
}
|
|
1568
|
-
config.conversationWebhookId = deployedWebhook.id;
|
|
1569
|
-
config.originalTarget = deployedWebhook.target;
|
|
1570
|
-
const hmacSecret = randomBytes(32).toString("hex");
|
|
1571
|
-
process.env.CONVERSATION_WEBHOOK_SECRET = hmacSecret;
|
|
1572
|
-
resetSinchClients();
|
|
1573
|
-
await sinchClient.conversation.webhooks.update({
|
|
1574
|
-
webhook_id: deployedWebhook.id,
|
|
1575
|
-
webhookUpdateRequestBody: {
|
|
1576
|
-
target: webhookUrl,
|
|
1577
|
-
secret: hmacSecret
|
|
1578
|
-
},
|
|
1579
|
-
update_mask: ["target", "secret"]
|
|
1580
|
-
});
|
|
1581
|
-
console.log(`\u2705 Updated Conversation webhook to tunnel: ${webhookUrl}`);
|
|
1582
|
-
console.log("\u{1F512} HMAC secret configured for webhook signature validation");
|
|
1583
|
-
console.log("\u{1F4AC} Send a message to your Conversation app to test!");
|
|
1584
|
-
} catch (error) {
|
|
1585
|
-
console.log("\u26A0\uFE0F Could not configure Conversation webhooks:", error instanceof Error ? error.message : error);
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
async function cleanupConversationWebhook(config) {
|
|
1589
|
-
if (!config.conversationWebhookId) return;
|
|
1590
|
-
try {
|
|
1591
|
-
const conversationAppId = process.env.CONVERSATION_APP_ID;
|
|
1592
|
-
const projectId = process.env.PROJECT_ID;
|
|
1593
|
-
const keyId = process.env.PROJECT_ID_API_KEY;
|
|
1594
|
-
const keySecret = process.env.PROJECT_ID_API_SECRET;
|
|
1595
|
-
if (!conversationAppId || !projectId || !keyId || !keySecret) return;
|
|
1596
|
-
const sinchClient = new SinchClient2({
|
|
1597
|
-
projectId,
|
|
1598
|
-
keyId,
|
|
1599
|
-
keySecret
|
|
1600
|
-
});
|
|
1601
|
-
let restoreTarget = config.originalTarget;
|
|
1602
|
-
if (!restoreTarget || isTunnelUrl(restoreTarget)) {
|
|
1603
|
-
const functionName = process.env.FUNCTION_NAME || process.env.FUNCTION_ID;
|
|
1604
|
-
if (functionName) {
|
|
1605
|
-
restoreTarget = `https://${functionName}.fn-dev.sinch.com/webhook/conversation`;
|
|
1606
|
-
console.log(`\u{1F527} Derived restore target from env: ${restoreTarget}`);
|
|
1607
|
-
} else {
|
|
1608
|
-
console.log("\u26A0\uFE0F Cannot restore webhook \u2014 no FUNCTION_NAME or FUNCTION_ID available");
|
|
1609
|
-
return;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
await sinchClient.conversation.webhooks.update({
|
|
1613
|
-
webhook_id: config.conversationWebhookId,
|
|
1614
|
-
webhookUpdateRequestBody: {
|
|
1615
|
-
target: restoreTarget
|
|
1616
|
-
},
|
|
1617
|
-
update_mask: ["target"]
|
|
1618
|
-
});
|
|
1619
|
-
console.log(`\u{1F504} Restored webhook target to: ${restoreTarget}`);
|
|
1620
|
-
config.conversationWebhookId = void 0;
|
|
1621
|
-
config.originalTarget = void 0;
|
|
1622
|
-
delete process.env.CONVERSATION_WEBHOOK_SECRET;
|
|
1623
|
-
resetSinchClients();
|
|
1624
|
-
} catch (error) {
|
|
1625
|
-
console.log("\u26A0\uFE0F Could not restore Conversation webhook:", error instanceof Error ? error.message : error);
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
async function configureElevenLabs() {
|
|
1629
|
-
try {
|
|
1630
|
-
const agentId = process.env.ELEVENLABS_AGENT_ID;
|
|
1631
|
-
const apiKey = process.env.ELEVENLABS_API_KEY;
|
|
1632
|
-
if (!agentId || !apiKey) {
|
|
1633
|
-
console.log("\u{1F4A1} ElevenLabs not fully configured - skipping auto-configuration");
|
|
1634
|
-
return;
|
|
1635
|
-
}
|
|
1636
|
-
void apiKey;
|
|
1637
|
-
console.log("\u{1F916} ElevenLabs auto-configuration enabled");
|
|
1638
|
-
console.log(` Agent ID: ${agentId}`);
|
|
1639
|
-
} catch (error) {
|
|
1640
|
-
console.log("\u26A0\uFE0F Could not configure ElevenLabs:", error instanceof Error ? error.message : error);
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
// src/tunnel/index.ts
|
|
1645
|
-
var TUNNEL_GATEWAY_DEFAULT = "https://tunnel.fn.sinch.com";
|
|
1646
|
-
var TunnelClient = class {
|
|
1647
|
-
ws = null;
|
|
1648
|
-
tunnelUrl = null;
|
|
1649
|
-
tunnelId = null;
|
|
1650
|
-
isConnected = false;
|
|
1651
|
-
reconnectAttempts = 0;
|
|
1652
|
-
maxReconnectAttempts = 10;
|
|
1653
|
-
reconnectDelay = 5e3;
|
|
1654
|
-
heartbeatInterval = null;
|
|
1655
|
-
localPort;
|
|
1656
|
-
webhookConfig = {};
|
|
1657
|
-
welcomeResolver = null;
|
|
1658
|
-
constructor(localPort = 3e3) {
|
|
1659
|
-
this.localPort = localPort;
|
|
1660
|
-
}
|
|
1661
|
-
getTunnelGatewayUrl() {
|
|
1662
|
-
const explicitUrl = process.env.TUNNEL_GATEWAY_URL;
|
|
1663
|
-
if (explicitUrl) {
|
|
1664
|
-
return explicitUrl;
|
|
1665
|
-
}
|
|
1666
|
-
return TUNNEL_GATEWAY_DEFAULT;
|
|
1667
|
-
}
|
|
1668
|
-
generateTunnelId() {
|
|
1669
|
-
const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
1670
|
-
const timestamp = Date.now();
|
|
1671
|
-
let timestampPart = "";
|
|
1672
|
-
let t = timestamp;
|
|
1673
|
-
for (let i = 0; i < 10; i++) {
|
|
1674
|
-
timestampPart = ENCODING[t % 32] + timestampPart;
|
|
1675
|
-
t = Math.floor(t / 32);
|
|
1676
|
-
}
|
|
1677
|
-
const randomBytes2 = new Uint8Array(10);
|
|
1678
|
-
crypto.getRandomValues(randomBytes2);
|
|
1679
|
-
let randomPart = "";
|
|
1680
|
-
for (let i = 0; i < 10; i++) {
|
|
1681
|
-
const byte = randomBytes2[i];
|
|
1682
|
-
randomPart += ENCODING[byte >> 3];
|
|
1683
|
-
if (randomPart.length < 16) {
|
|
1684
|
-
randomPart += ENCODING[(byte & 7) << 2 | (i + 1 < 10 ? randomBytes2[i + 1] >> 6 : 0)];
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
randomPart = randomPart.substring(0, 16);
|
|
1688
|
-
return timestampPart + randomPart;
|
|
1689
|
-
}
|
|
1690
|
-
async connect() {
|
|
1691
|
-
if (process.env.SINCH_TUNNEL !== "true") {
|
|
1692
|
-
console.log("Tunnel is disabled (set SINCH_TUNNEL=true to enable)");
|
|
1693
|
-
return;
|
|
1694
|
-
}
|
|
1695
|
-
const gatewayUrl = this.getTunnelGatewayUrl();
|
|
1696
|
-
this.tunnelId = this.generateTunnelId();
|
|
1697
|
-
const gatewayUri = new URL(gatewayUrl);
|
|
1698
|
-
const wsUrl = new URL(gatewayUrl);
|
|
1699
|
-
wsUrl.protocol = gatewayUri.protocol === "https:" ? "wss:" : "ws:";
|
|
1700
|
-
wsUrl.pathname = "/ws";
|
|
1701
|
-
wsUrl.searchParams.set("tunnel", this.tunnelId);
|
|
1702
|
-
const tunnelEndpoint = wsUrl.toString();
|
|
1703
|
-
console.log(`Connecting to tunnel gateway at ${tunnelEndpoint}...`);
|
|
1704
|
-
try {
|
|
1705
|
-
this.ws = new WebSocket(tunnelEndpoint);
|
|
1706
|
-
const welcomePromise = new Promise((resolve, reject) => {
|
|
1707
|
-
this.welcomeResolver = resolve;
|
|
1708
|
-
setTimeout(() => reject(new Error("Timed out waiting for welcome message")), 1e4);
|
|
1709
|
-
});
|
|
1710
|
-
this.ws.on("open", () => {
|
|
1711
|
-
this.isConnected = true;
|
|
1712
|
-
this.reconnectAttempts = 0;
|
|
1713
|
-
console.log("WebSocket connected, waiting for welcome message...");
|
|
1714
|
-
});
|
|
1715
|
-
this.ws.on("message", async (data) => {
|
|
1716
|
-
try {
|
|
1717
|
-
const message = JSON.parse(data.toString());
|
|
1718
|
-
await this.handleMessage(message);
|
|
1719
|
-
} catch (error) {
|
|
1720
|
-
console.error("Error processing tunnel message:", error);
|
|
1721
|
-
}
|
|
1722
|
-
});
|
|
1723
|
-
this.ws.on("close", async () => {
|
|
1724
|
-
this.isConnected = false;
|
|
1725
|
-
console.log("Tunnel connection closed");
|
|
1726
|
-
this.stopHeartbeat();
|
|
1727
|
-
this.scheduleReconnect();
|
|
1728
|
-
});
|
|
1729
|
-
this.ws.on("error", (error) => {
|
|
1730
|
-
console.error("Tunnel connection error:", error.message);
|
|
1731
|
-
});
|
|
1732
|
-
await welcomePromise;
|
|
1733
|
-
if (!this.tunnelUrl) {
|
|
1734
|
-
throw new Error("Did not receive tunnel URL from gateway");
|
|
1735
|
-
}
|
|
1736
|
-
console.log("Tunnel connected successfully!");
|
|
1737
|
-
this.startHeartbeat();
|
|
1738
|
-
await this.configureWebhooks();
|
|
1739
|
-
} catch (error) {
|
|
1740
|
-
console.error("Failed to establish tunnel connection:", error.message);
|
|
1741
|
-
this.scheduleReconnect();
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
async handleMessage(message) {
|
|
1745
|
-
switch (message.type) {
|
|
1746
|
-
case "welcome":
|
|
1747
|
-
this.handleWelcomeMessage(message);
|
|
1748
|
-
break;
|
|
1749
|
-
case "request":
|
|
1750
|
-
await this.handleRequest(message);
|
|
1751
|
-
break;
|
|
1752
|
-
case "ping":
|
|
1753
|
-
this.sendPong();
|
|
1754
|
-
break;
|
|
1755
|
-
}
|
|
1756
|
-
}
|
|
1757
|
-
/**
|
|
1758
|
-
* Build a full tunnel URL with optional sub-path and tunnel query param.
|
|
1759
|
-
* e.g. buildTunnelUrl('/webhook/conversation') →
|
|
1760
|
-
* https://tunnel.fn.sinch.com/ingress/webhook/conversation?tunnel=01KKT...
|
|
1761
|
-
*/
|
|
1762
|
-
buildTunnelUrl(path7) {
|
|
1763
|
-
const base = this.tunnelUrl.replace(/\/$/, "");
|
|
1764
|
-
return `${base}${path7 || ""}?tunnel=${this.tunnelId}`;
|
|
1765
|
-
}
|
|
1766
|
-
handleWelcomeMessage(message) {
|
|
1767
|
-
this.tunnelId = message.tunnelId || null;
|
|
1768
|
-
this.tunnelUrl = message.publicUrl || null;
|
|
1769
|
-
console.log(`Received welcome: tunnelId=${this.tunnelId}`);
|
|
1770
|
-
if (this.welcomeResolver) {
|
|
1771
|
-
this.welcomeResolver(true);
|
|
1772
|
-
this.welcomeResolver = null;
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
async handleRequest(message) {
|
|
1776
|
-
const verbose = process.env.VERBOSE === "true";
|
|
1777
|
-
console.log(`Forwarding ${message.method} request to ${message.path}`);
|
|
1778
|
-
if (verbose && message.body) {
|
|
1779
|
-
console.log(` \u2190 Request body: ${message.body.substring(0, 2e3)}`);
|
|
1780
|
-
}
|
|
1781
|
-
try {
|
|
1782
|
-
const localUrl = `http://localhost:${this.localPort}${message.path}${message.query || ""}`;
|
|
1783
|
-
const axiosConfig = {
|
|
1784
|
-
method: message.method,
|
|
1785
|
-
url: localUrl,
|
|
1786
|
-
headers: {}
|
|
1787
|
-
};
|
|
1788
|
-
if (message.headers) {
|
|
1789
|
-
axiosConfig.headers = { ...message.headers };
|
|
1790
|
-
}
|
|
1791
|
-
if (message.body) {
|
|
1792
|
-
axiosConfig.data = message.body;
|
|
1793
|
-
}
|
|
1794
|
-
const response = await axios(axiosConfig);
|
|
1795
|
-
const headers = {};
|
|
1796
|
-
for (const [key, value] of Object.entries(response.headers)) {
|
|
1797
|
-
if (value) {
|
|
1798
|
-
const normalizedKey = key.toLowerCase() === "content-type" ? "Content-Type" : key.toLowerCase() === "content-length" ? "Content-Length" : key;
|
|
1799
|
-
headers[normalizedKey] = String(value);
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
if (!headers["Content-Type"] && response.data) {
|
|
1803
|
-
headers["Content-Type"] = "application/json";
|
|
1804
|
-
}
|
|
1805
|
-
const body = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
|
|
1806
|
-
const responseMessage = {
|
|
1807
|
-
type: "response",
|
|
1808
|
-
id: message.id,
|
|
1809
|
-
statusCode: response.status,
|
|
1810
|
-
headers,
|
|
1811
|
-
body
|
|
1812
|
-
};
|
|
1813
|
-
if (verbose) {
|
|
1814
|
-
console.log(` \u2192 Response ${response.status}: ${body.substring(0, 2e3)}`);
|
|
1815
|
-
}
|
|
1816
|
-
this.ws?.send(JSON.stringify(responseMessage));
|
|
1817
|
-
} catch (error) {
|
|
1818
|
-
console.error(`Error forwarding request: ${error.message} (${error.response?.status || "no response"})`);
|
|
1819
|
-
if (verbose && error.response?.data) {
|
|
1820
|
-
console.error(` \u2192 Error body: ${typeof error.response.data === "string" ? error.response.data : JSON.stringify(error.response.data)}`.substring(0, 2e3));
|
|
1821
|
-
}
|
|
1822
|
-
const errorResponse = {
|
|
1823
|
-
type: "response",
|
|
1824
|
-
id: message.id,
|
|
1825
|
-
statusCode: error.response?.status || 502,
|
|
1826
|
-
headers: { "Content-Type": "text/plain" },
|
|
1827
|
-
body: "Error forwarding request to local server"
|
|
1828
|
-
};
|
|
1829
|
-
this.ws?.send(JSON.stringify(errorResponse));
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
sendPong() {
|
|
1833
|
-
const pongMessage = { type: "pong" };
|
|
1834
|
-
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
1835
|
-
this.ws.send(JSON.stringify(pongMessage));
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
startHeartbeat() {
|
|
1839
|
-
this.heartbeatInterval = setInterval(() => {
|
|
1840
|
-
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
1841
|
-
const pingMessage = { type: "ping" };
|
|
1842
|
-
this.ws.send(JSON.stringify(pingMessage));
|
|
1843
|
-
}
|
|
1844
|
-
}, 3e4);
|
|
1845
|
-
}
|
|
1846
|
-
stopHeartbeat() {
|
|
1847
|
-
if (this.heartbeatInterval) {
|
|
1848
|
-
clearInterval(this.heartbeatInterval);
|
|
1849
|
-
this.heartbeatInterval = null;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Configure all webhooks (Voice, Conversation, ElevenLabs)
|
|
1854
|
-
*/
|
|
1855
|
-
async configureWebhooks() {
|
|
1856
|
-
const hasNewFormat = "AUTO_CONFIGURE" in process.env;
|
|
1857
|
-
const autoEnabled = process.env.AUTO_CONFIGURE === "true";
|
|
1858
|
-
const sinchServices = (process.env.SINCH_SERVICES ?? "").split(",").map((s) => s.trim());
|
|
1859
|
-
const autoConfigVoice = hasNewFormat ? autoEnabled && sinchServices.includes("voice") : process.env.AUTO_CONFIGURE_VOICE !== "false" && !!process.env.VOICE_APPLICATION_KEY;
|
|
1860
|
-
const autoConfigConversation = hasNewFormat ? autoEnabled && sinchServices.includes("conversation") : process.env.AUTO_CONFIGURE_CONVERSATION !== "false" && !!process.env.CONVERSATION_APP_ID;
|
|
1861
|
-
if (autoConfigVoice && process.env.VOICE_APPLICATION_KEY) {
|
|
1862
|
-
await this.configureVoiceWebhooks();
|
|
1863
|
-
}
|
|
1864
|
-
if (autoConfigConversation && process.env.CONVERSATION_APP_ID) {
|
|
1865
|
-
await configureConversationWebhooks(this.buildTunnelUrl("/webhook/conversation"), this.webhookConfig);
|
|
1866
|
-
}
|
|
1867
|
-
if (process.env.ELEVENLABS_AUTO_CONFIGURE === "true") {
|
|
1868
|
-
await configureElevenLabs();
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* Cleanup webhooks on disconnect
|
|
1873
|
-
*/
|
|
1874
|
-
async cleanupWebhooks() {
|
|
1875
|
-
await cleanupConversationWebhook(this.webhookConfig);
|
|
1876
|
-
}
|
|
1877
|
-
async configureVoiceWebhooks() {
|
|
1878
|
-
try {
|
|
1879
|
-
const appKey = process.env.VOICE_APPLICATION_KEY;
|
|
1880
|
-
const appSecret = process.env.VOICE_APPLICATION_SECRET;
|
|
1881
|
-
if (!appKey || !appSecret) {
|
|
1882
|
-
console.log("\u{1F4A1} Voice API not configured - skipping phone number display");
|
|
1883
|
-
return;
|
|
1884
|
-
}
|
|
1885
|
-
try {
|
|
1886
|
-
const updateUrl = `https://callingapi.sinch.com/v1/configuration/callbacks/applications/${appKey}/`;
|
|
1887
|
-
const auth = Buffer.from(`${appKey}:${appSecret}`).toString("base64");
|
|
1888
|
-
await axios.post(
|
|
1889
|
-
updateUrl,
|
|
1890
|
-
{
|
|
1891
|
-
url: {
|
|
1892
|
-
primary: this.buildTunnelUrl(),
|
|
1893
|
-
fallback: null
|
|
1894
|
-
}
|
|
1895
|
-
},
|
|
1896
|
-
{
|
|
1897
|
-
headers: {
|
|
1898
|
-
Authorization: `Basic ${auth}`,
|
|
1899
|
-
"Content-Type": "application/json"
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
);
|
|
1903
|
-
console.log("\u2705 Updated voice webhook URL");
|
|
1904
|
-
} catch (error) {
|
|
1905
|
-
console.log("\u26A0\uFE0F Could not update webhook URL:", error.message);
|
|
1906
|
-
}
|
|
1907
|
-
try {
|
|
1908
|
-
const listUrl = `https://callingapi.sinch.com/v1/configuration/numbers/`;
|
|
1909
|
-
const auth = Buffer.from(`${appKey}:${appSecret}`).toString("base64");
|
|
1910
|
-
const response = await axios.get(listUrl, {
|
|
1911
|
-
headers: {
|
|
1912
|
-
Authorization: `Basic ${auth}`
|
|
1913
|
-
}
|
|
1914
|
-
});
|
|
1915
|
-
const numbers = response.data?.numbers || [];
|
|
1916
|
-
const appNumbers = numbers.filter((n) => n.applicationkey === appKey);
|
|
1917
|
-
if (appNumbers.length > 0) {
|
|
1918
|
-
console.log("\u{1F4F1} Test Phone Numbers:");
|
|
1919
|
-
appNumbers.forEach((num) => {
|
|
1920
|
-
console.log(` \u260E\uFE0F ${num.number}`);
|
|
1921
|
-
});
|
|
1922
|
-
console.log("\u{1F4A1} Call any of these numbers to test your voice function!");
|
|
1923
|
-
} else {
|
|
1924
|
-
console.log("\u26A0\uFE0F No phone numbers assigned to this application yet");
|
|
1925
|
-
console.log("\u{1F4A1} Add numbers at https://dashboard.sinch.com/voice/apps");
|
|
1926
|
-
}
|
|
1927
|
-
} catch (error) {
|
|
1928
|
-
console.log("\u{1F4A1} Could not fetch phone numbers:", error.message);
|
|
1929
|
-
}
|
|
1930
|
-
} catch (error) {
|
|
1931
|
-
console.log("\u{1F4A1} Could not fetch phone numbers (Voice API may not be configured)");
|
|
1932
|
-
}
|
|
1933
|
-
}
|
|
1934
|
-
scheduleReconnect() {
|
|
1935
|
-
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
1936
|
-
console.error("Max reconnection attempts reached. Giving up.");
|
|
1937
|
-
return;
|
|
1938
|
-
}
|
|
1939
|
-
this.reconnectAttempts++;
|
|
1940
|
-
const delay = Math.min(this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1), 3e4);
|
|
1941
|
-
console.log(`Attempting to reconnect in ${delay / 1e3} seconds...`);
|
|
1942
|
-
setTimeout(() => this.connect(), delay);
|
|
1943
|
-
}
|
|
1944
|
-
async disconnect() {
|
|
1945
|
-
this.stopHeartbeat();
|
|
1946
|
-
await this.cleanupWebhooks();
|
|
1947
|
-
if (this.ws) {
|
|
1948
|
-
this.ws.close();
|
|
1949
|
-
this.ws = null;
|
|
1950
|
-
}
|
|
1951
|
-
this.isConnected = false;
|
|
1952
|
-
}
|
|
1953
|
-
getTunnelUrl() {
|
|
1954
|
-
if (!this.tunnelUrl || !this.tunnelId) return null;
|
|
1955
|
-
return this.buildTunnelUrl();
|
|
1956
|
-
}
|
|
1957
|
-
getIsConnected() {
|
|
1958
|
-
return this.isConnected;
|
|
1959
|
-
}
|
|
1960
|
-
};
|
|
1961
|
-
|
|
1962
|
-
// src/bin/sinch-runtime.ts
|
|
1963
|
-
var requireCjs3 = createRequire3(import.meta.url);
|
|
1964
|
-
function findFunctionPath3() {
|
|
1965
|
-
const distPath = path6.join(process.cwd(), "dist", "function.js");
|
|
1966
|
-
const rootPath = path6.join(process.cwd(), "function.js");
|
|
1967
|
-
if (fs5.existsSync(distPath)) {
|
|
23
|
+
var requireCjs = createRequire(import.meta.url);
|
|
24
|
+
function findFunctionPath() {
|
|
25
|
+
const distPath = path.join(process.cwd(), "dist", "function.js");
|
|
26
|
+
const rootPath = path.join(process.cwd(), "function.js");
|
|
27
|
+
if (fs.existsSync(distPath)) {
|
|
1968
28
|
return distPath;
|
|
1969
29
|
}
|
|
1970
30
|
return rootPath;
|
|
@@ -1977,7 +37,7 @@ function loadRuntimeConfig() {
|
|
|
1977
37
|
};
|
|
1978
38
|
}
|
|
1979
39
|
var storage = createStorageClient();
|
|
1980
|
-
var databasePath =
|
|
40
|
+
var databasePath = path.join(process.cwd(), ".sinch", "data", "app.db");
|
|
1981
41
|
function buildLocalContext(req, runtimeConfig) {
|
|
1982
42
|
const baseContext = buildBaseContext(req);
|
|
1983
43
|
const cache = createCacheClient();
|
|
@@ -2013,12 +73,12 @@ function displayStartupInfo(config, verbose, _port) {
|
|
|
2013
73
|
function displayEnvironmentVariables() {
|
|
2014
74
|
console.log("\nEnvironment Variables:");
|
|
2015
75
|
try {
|
|
2016
|
-
const envPath =
|
|
2017
|
-
if (!
|
|
76
|
+
const envPath = path.join(process.cwd(), ".env");
|
|
77
|
+
if (!fs.existsSync(envPath)) {
|
|
2018
78
|
console.log(" (no .env file found)");
|
|
2019
79
|
return;
|
|
2020
80
|
}
|
|
2021
|
-
const envContent =
|
|
81
|
+
const envContent = fs.readFileSync(envPath, "utf8");
|
|
2022
82
|
const envLines = envContent.split("\n");
|
|
2023
83
|
const variables = [];
|
|
2024
84
|
const secrets = [];
|
|
@@ -2077,9 +137,9 @@ function displayApplicationCredentials() {
|
|
|
2077
137
|
}
|
|
2078
138
|
async function displayDetectedFunctions(port) {
|
|
2079
139
|
try {
|
|
2080
|
-
const functionPath =
|
|
2081
|
-
if (!
|
|
2082
|
-
const functionUrl =
|
|
140
|
+
const functionPath = findFunctionPath();
|
|
141
|
+
if (!fs.existsSync(functionPath)) return;
|
|
142
|
+
const functionUrl = pathToFileURL(functionPath).href;
|
|
2083
143
|
const module = await import(functionUrl);
|
|
2084
144
|
const userFunction = module.default || module;
|
|
2085
145
|
const functions = Object.keys(userFunction).filter((k) => typeof userFunction[k] === "function");
|
|
@@ -2099,14 +159,14 @@ async function main() {
|
|
|
2099
159
|
const portArg = args.indexOf("--port");
|
|
2100
160
|
const port = portArg !== -1 ? parseInt(args[portArg + 1], 10) : parseInt(process.env.PORT || "3000", 10);
|
|
2101
161
|
try {
|
|
2102
|
-
const dotenv =
|
|
162
|
+
const dotenv = requireCjs("dotenv");
|
|
2103
163
|
dotenv.config({ path: ".env.development" });
|
|
2104
164
|
dotenv.config();
|
|
2105
165
|
} catch {
|
|
2106
166
|
}
|
|
2107
167
|
await secretsLoader.loadFromKeychain();
|
|
2108
|
-
|
|
2109
|
-
|
|
168
|
+
fs.mkdirSync(path.join(process.cwd(), ".sinch", "storage"), { recursive: true });
|
|
169
|
+
fs.mkdirSync(path.join(process.cwd(), ".sinch", "data"), { recursive: true });
|
|
2110
170
|
const config = loadRuntimeConfig();
|
|
2111
171
|
const staticDir = process.env.STATIC_DIR;
|
|
2112
172
|
const landingPageEnabled = process.env.LANDING_PAGE_ENABLED !== "false";
|
|
@@ -2115,8 +175,8 @@ async function main() {
|
|
|
2115
175
|
const authSecret = process.env.PROJECT_ID_API_SECRET;
|
|
2116
176
|
let userAuthConfig;
|
|
2117
177
|
const loadUserFunction = async () => {
|
|
2118
|
-
const functionPath =
|
|
2119
|
-
const functionUrl =
|
|
178
|
+
const functionPath = findFunctionPath();
|
|
179
|
+
const functionUrl = pathToFileURL(functionPath).href;
|
|
2120
180
|
const module = await import(functionUrl);
|
|
2121
181
|
if (userAuthConfig === void 0) {
|
|
2122
182
|
userAuthConfig = module.auth || module.default?.auth;
|
|
@@ -2128,7 +188,7 @@ async function main() {
|
|
|
2128
188
|
};
|
|
2129
189
|
await loadUserFunction();
|
|
2130
190
|
let setupResult;
|
|
2131
|
-
const rawModule = await import(
|
|
191
|
+
const rawModule = await import(pathToFileURL(findFunctionPath()).href);
|
|
2132
192
|
const setupFn = rawModule.setup || rawModule.default?.setup;
|
|
2133
193
|
if (typeof setupFn === "function") {
|
|
2134
194
|
const { runtime, result } = createSinchRuntime();
|