@madewithremy/admin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -0
- package/dist/index.d.ts +5050 -0
- package/dist/index.js +1674 -0
- package/dist/index.js.map +1 -0
- package/dist/prod.js +5261 -0
- package/package.json +61 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1674 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/ctx.ts
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
|
|
11
|
+
// src/config.ts
|
|
12
|
+
var WORKSPACE_DIR = process.env["WORKSPACE_DIR"] || "/home/vercel-sandbox/workspace";
|
|
13
|
+
|
|
14
|
+
// src/parseJsonConfig.ts
|
|
15
|
+
import JSON5 from "json5";
|
|
16
|
+
function msg(err) {
|
|
17
|
+
return err instanceof Error ? err.message : String(err);
|
|
18
|
+
}
|
|
19
|
+
function parseJsonConfig(raw) {
|
|
20
|
+
let strictError;
|
|
21
|
+
try {
|
|
22
|
+
return { ok: true, value: JSON.parse(raw), repaired: false };
|
|
23
|
+
} catch (err) {
|
|
24
|
+
strictError = msg(err);
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return {
|
|
28
|
+
ok: true,
|
|
29
|
+
value: JSON5.parse(raw),
|
|
30
|
+
repaired: true,
|
|
31
|
+
error: strictError
|
|
32
|
+
};
|
|
33
|
+
} catch (err) {
|
|
34
|
+
return { ok: false, error: msg(err), notFound: false };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/ctx.ts
|
|
39
|
+
var DEFAULT_BASE_URL = "https://api.mindstudio.ai";
|
|
40
|
+
function loadWorkspaceAppId(workspaceDir = WORKSPACE_DIR) {
|
|
41
|
+
const manifestPath = path.join(workspaceDir, "mindstudio.json");
|
|
42
|
+
let raw;
|
|
43
|
+
try {
|
|
44
|
+
raw = fs.readFileSync(manifestPath, "utf-8");
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (err.code === "ENOENT") {
|
|
47
|
+
throw new Error(`mindstudio.json not found at ${manifestPath}`);
|
|
48
|
+
}
|
|
49
|
+
throw new Error(`Failed to read mindstudio.json: ${err.message}`);
|
|
50
|
+
}
|
|
51
|
+
const result = parseJsonConfig(raw);
|
|
52
|
+
if (!result.ok) {
|
|
53
|
+
throw new Error(`Failed to parse mindstudio.json: ${result.error}`);
|
|
54
|
+
}
|
|
55
|
+
if (!result.value.appId) {
|
|
56
|
+
throw new Error("mindstudio.json exists but has no appId");
|
|
57
|
+
}
|
|
58
|
+
return result.value.appId;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/ops/analytics.ts
|
|
62
|
+
var analytics_exports = {};
|
|
63
|
+
__export(analytics_exports, {
|
|
64
|
+
aiSources: () => aiSources,
|
|
65
|
+
batch: () => batch,
|
|
66
|
+
crawlers: () => crawlers,
|
|
67
|
+
live: () => live,
|
|
68
|
+
map: () => map,
|
|
69
|
+
query: () => query,
|
|
70
|
+
sources: () => sources
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// src/errors.ts
|
|
74
|
+
var AdminApiError = class extends Error {
|
|
75
|
+
constructor(method, path3, status, body) {
|
|
76
|
+
super(`API ${method} ${path3} returned ${status}: ${JSON.stringify(body)}`);
|
|
77
|
+
this.method = method;
|
|
78
|
+
this.path = path3;
|
|
79
|
+
this.status = status;
|
|
80
|
+
this.body = body;
|
|
81
|
+
this.name = "AdminApiError";
|
|
82
|
+
}
|
|
83
|
+
method;
|
|
84
|
+
path;
|
|
85
|
+
status;
|
|
86
|
+
body;
|
|
87
|
+
};
|
|
88
|
+
var AdminTimeoutError = class extends Error {
|
|
89
|
+
constructor(label, timeoutMs) {
|
|
90
|
+
super(`${label} timed out after ${timeoutMs / 1e3}s`);
|
|
91
|
+
this.name = "AdminTimeoutError";
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/http.ts
|
|
96
|
+
var REQUEST_TIMEOUT_MS = 3e4;
|
|
97
|
+
var REPORT_TIMEOUT_MS = 6e4;
|
|
98
|
+
function seg(value) {
|
|
99
|
+
return encodeURIComponent(String(value));
|
|
100
|
+
}
|
|
101
|
+
function qs(params) {
|
|
102
|
+
const search2 = new URLSearchParams();
|
|
103
|
+
for (const [key, value] of Object.entries(params)) {
|
|
104
|
+
if (value === void 0 || value === null) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
search2.set(key, String(value));
|
|
108
|
+
}
|
|
109
|
+
const text = search2.toString();
|
|
110
|
+
return text ? `?${text}` : "";
|
|
111
|
+
}
|
|
112
|
+
function authHeaders(ctx) {
|
|
113
|
+
return {
|
|
114
|
+
Authorization: `Bearer ${ctx.apiKey}`,
|
|
115
|
+
"Content-Type": "application/json"
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function readBody(res) {
|
|
119
|
+
if (res.status === 204) {
|
|
120
|
+
return { ok: true, status: 204 };
|
|
121
|
+
}
|
|
122
|
+
const text = await res.text().catch(() => "");
|
|
123
|
+
if (!text.trim()) {
|
|
124
|
+
return { ok: true, status: res.status };
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(text);
|
|
128
|
+
} catch {
|
|
129
|
+
return { raw: text };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function fetchWithTimeout(url, init, timeoutMs, label) {
|
|
133
|
+
try {
|
|
134
|
+
return await fetch(url, {
|
|
135
|
+
...init,
|
|
136
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
137
|
+
});
|
|
138
|
+
} catch (err) {
|
|
139
|
+
if (err?.name === "TimeoutError") {
|
|
140
|
+
throw new AdminTimeoutError(label, timeoutMs);
|
|
141
|
+
}
|
|
142
|
+
throw err;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async function call(ctx, method, apiPath, body, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
146
|
+
const res = await fetchWithTimeout(
|
|
147
|
+
`${ctx.baseUrl}${apiPath}`,
|
|
148
|
+
{
|
|
149
|
+
method,
|
|
150
|
+
headers: authHeaders(ctx),
|
|
151
|
+
...body ? { body: JSON.stringify(body) } : {}
|
|
152
|
+
},
|
|
153
|
+
timeoutMs,
|
|
154
|
+
`API ${method} ${apiPath}`
|
|
155
|
+
);
|
|
156
|
+
if (!res.ok) {
|
|
157
|
+
throw new AdminApiError(method, apiPath, res.status, await readBody(res));
|
|
158
|
+
}
|
|
159
|
+
return readBody(res);
|
|
160
|
+
}
|
|
161
|
+
async function tryCall(ctx, method, apiPath) {
|
|
162
|
+
const res = await fetchWithTimeout(
|
|
163
|
+
`${ctx.baseUrl}${apiPath}`,
|
|
164
|
+
{ method, headers: authHeaders(ctx) },
|
|
165
|
+
REQUEST_TIMEOUT_MS,
|
|
166
|
+
`API ${method} ${apiPath}`
|
|
167
|
+
);
|
|
168
|
+
return { ok: res.ok, status: res.status, body: await readBody(res) };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/ops/analytics.ts
|
|
172
|
+
function query(ctx, body) {
|
|
173
|
+
return call(
|
|
174
|
+
ctx,
|
|
175
|
+
"POST",
|
|
176
|
+
`/_internal/v2/apps/${ctx.appId}/insights/query`,
|
|
177
|
+
body
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function batch(ctx, queries) {
|
|
181
|
+
return call(
|
|
182
|
+
ctx,
|
|
183
|
+
"POST",
|
|
184
|
+
`/_internal/v2/apps/${ctx.appId}/insights/query-batch`,
|
|
185
|
+
{ queries }
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function sources(ctx, params = {}) {
|
|
189
|
+
return call(
|
|
190
|
+
ctx,
|
|
191
|
+
"GET",
|
|
192
|
+
`/_internal/v2/apps/${ctx.appId}/insights/sources${qs(params)}`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
function map(ctx, params = {}) {
|
|
196
|
+
return call(
|
|
197
|
+
ctx,
|
|
198
|
+
"GET",
|
|
199
|
+
`/_internal/v2/apps/${ctx.appId}/insights/map${qs(params)}`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
function live(ctx) {
|
|
203
|
+
return call(
|
|
204
|
+
ctx,
|
|
205
|
+
"GET",
|
|
206
|
+
`/_internal/v2/apps/${ctx.appId}/insights/live`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
function aiSources(ctx, params = {}) {
|
|
210
|
+
return call(
|
|
211
|
+
ctx,
|
|
212
|
+
"GET",
|
|
213
|
+
`/_internal/v2/apps/${ctx.appId}/insights/ai-sources${qs(params)}`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function crawlers(ctx, params) {
|
|
217
|
+
const { kind, ...rest } = params;
|
|
218
|
+
return call(
|
|
219
|
+
ctx,
|
|
220
|
+
"GET",
|
|
221
|
+
`/_internal/v2/apps/${ctx.appId}/insights/crawlers/${seg(kind)}${qs(rest)}`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/ops/crashes.ts
|
|
226
|
+
var crashes_exports = {};
|
|
227
|
+
__export(crashes_exports, {
|
|
228
|
+
get: () => get,
|
|
229
|
+
list: () => list,
|
|
230
|
+
occurrences: () => occurrences,
|
|
231
|
+
stats: () => stats
|
|
232
|
+
});
|
|
233
|
+
function list(ctx, params = {}) {
|
|
234
|
+
return call(
|
|
235
|
+
ctx,
|
|
236
|
+
"GET",
|
|
237
|
+
`/_internal/v2/apps/${ctx.appId}/frontend-errors${qs(params)}`
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
function occurrences(ctx, fingerprint, params = {}) {
|
|
241
|
+
return call(
|
|
242
|
+
ctx,
|
|
243
|
+
"GET",
|
|
244
|
+
`/_internal/v2/apps/${ctx.appId}/frontend-errors/${seg(fingerprint)}/events${qs(params)}`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
function get(ctx, eventId) {
|
|
248
|
+
return call(
|
|
249
|
+
ctx,
|
|
250
|
+
"GET",
|
|
251
|
+
`/_internal/v2/apps/${ctx.appId}/frontend-errors/events/${seg(eventId)}`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
function stats(ctx, params = {}) {
|
|
255
|
+
return call(
|
|
256
|
+
ctx,
|
|
257
|
+
"GET",
|
|
258
|
+
`/_internal/v2/apps/${ctx.appId}/frontend-errors/metrics/summary${qs(params)}`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/ops/cron.ts
|
|
263
|
+
var cron_exports = {};
|
|
264
|
+
__export(cron_exports, {
|
|
265
|
+
list: () => list2,
|
|
266
|
+
run: () => run
|
|
267
|
+
});
|
|
268
|
+
function list2(ctx, params = {}) {
|
|
269
|
+
return call(
|
|
270
|
+
ctx,
|
|
271
|
+
"GET",
|
|
272
|
+
`/_internal/v2/apps/${ctx.appId}/cron/overview${qs(params)}`
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
function run(ctx, route) {
|
|
276
|
+
return call(
|
|
277
|
+
ctx,
|
|
278
|
+
"POST",
|
|
279
|
+
`/_internal/v2/apps/${ctx.appId}/cron/${seg(route)}/run`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/ops/data.ts
|
|
284
|
+
var data_exports = {};
|
|
285
|
+
__export(data_exports, {
|
|
286
|
+
liftFromDev: () => liftFromDev,
|
|
287
|
+
liftFromLive: () => liftFromLive
|
|
288
|
+
});
|
|
289
|
+
function liftFromDev(ctx) {
|
|
290
|
+
return call(
|
|
291
|
+
ctx,
|
|
292
|
+
"POST",
|
|
293
|
+
`/_internal/v2/apps/${ctx.appId}/manage/lift-dev-to-live`,
|
|
294
|
+
{ confirm: true }
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
function liftFromLive(ctx, params = {}) {
|
|
298
|
+
return call(
|
|
299
|
+
ctx,
|
|
300
|
+
"POST",
|
|
301
|
+
`/_internal/v2/apps/${ctx.appId}/manage/lift-live-to-dev`,
|
|
302
|
+
{ confirm: true, ...params.truncate ? { mode: "truncate" } : {} }
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/ops/dataSources.ts
|
|
307
|
+
var dataSources_exports = {};
|
|
308
|
+
__export(dataSources_exports, {
|
|
309
|
+
DEFAULT_WAIT_TIMEOUT_MS: () => DEFAULT_WAIT_TIMEOUT_MS,
|
|
310
|
+
addDocument: () => addDocument,
|
|
311
|
+
configGet: () => configGet,
|
|
312
|
+
configSet: () => configSet,
|
|
313
|
+
deleteSource: () => deleteSource,
|
|
314
|
+
documents: () => documents,
|
|
315
|
+
drop: () => drop,
|
|
316
|
+
list: () => list3,
|
|
317
|
+
promote: () => promote,
|
|
318
|
+
revectorize: () => revectorize,
|
|
319
|
+
rm: () => rm,
|
|
320
|
+
search: () => search,
|
|
321
|
+
summarize: () => summarize,
|
|
322
|
+
waitForIngest: () => waitForIngest
|
|
323
|
+
});
|
|
324
|
+
import { createHash } from "crypto";
|
|
325
|
+
|
|
326
|
+
// src/sleep.ts
|
|
327
|
+
function sleep(ms) {
|
|
328
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/upload.ts
|
|
332
|
+
async function uploadDirect(upload, bytes, filename) {
|
|
333
|
+
const form = new FormData();
|
|
334
|
+
for (const [key, value] of Object.entries(upload.uploadFields)) {
|
|
335
|
+
form.append(key, value);
|
|
336
|
+
}
|
|
337
|
+
const view2 = new Uint8Array(
|
|
338
|
+
bytes.buffer,
|
|
339
|
+
bytes.byteOffset,
|
|
340
|
+
bytes.byteLength
|
|
341
|
+
);
|
|
342
|
+
form.append("file", new Blob([view2]), filename);
|
|
343
|
+
const res = await fetch(upload.uploadUrl, { method: "POST", body: form });
|
|
344
|
+
if (!res.ok) {
|
|
345
|
+
const detail = await res.text().catch(() => "");
|
|
346
|
+
throw new Error(
|
|
347
|
+
`Upload of "${filename}" failed: ${res.status} ${res.statusText}${detail ? ` \u2014 ${detail.slice(0, 300)}` : ""}`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/ops/dataSources.ts
|
|
353
|
+
var DEFAULT_WAIT_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
354
|
+
var POLL_MS = 3e3;
|
|
355
|
+
function base(appId) {
|
|
356
|
+
return `/_internal/v2/apps/${appId}/datasources`;
|
|
357
|
+
}
|
|
358
|
+
var summarize = (d) => ({
|
|
359
|
+
id: d.id,
|
|
360
|
+
filename: d.filename,
|
|
361
|
+
status: d.status,
|
|
362
|
+
chunks: d.chunkCount,
|
|
363
|
+
pages: d.pageCount,
|
|
364
|
+
...d.errorMessage ? { error: d.errorMessage } : {}
|
|
365
|
+
});
|
|
366
|
+
async function addDocument(ctx, params) {
|
|
367
|
+
const { slug, filename, content, metadata, onProgress } = params;
|
|
368
|
+
const contentHash = createHash("sha256").update(content).digest("hex");
|
|
369
|
+
const token = await call(
|
|
370
|
+
ctx,
|
|
371
|
+
"POST",
|
|
372
|
+
`${base(ctx.appId)}/upload-token`,
|
|
373
|
+
{
|
|
374
|
+
slug,
|
|
375
|
+
filename,
|
|
376
|
+
contentHash,
|
|
377
|
+
...metadata ? { metadata } : {}
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
if (token.alreadyCurrent) {
|
|
381
|
+
onProgress?.(`${filename}: unchanged, skipped`);
|
|
382
|
+
return { filename, skipped: true, document: token.document };
|
|
383
|
+
}
|
|
384
|
+
onProgress?.(
|
|
385
|
+
`${filename}: uploading ${(content.length / 1024 / 1024).toFixed(1)}MB\u2026`
|
|
386
|
+
);
|
|
387
|
+
await uploadDirect(token.upload, content, filename);
|
|
388
|
+
const confirmed = await call(
|
|
389
|
+
ctx,
|
|
390
|
+
"POST",
|
|
391
|
+
`${base(ctx.appId)}/documents`,
|
|
392
|
+
{
|
|
393
|
+
slug,
|
|
394
|
+
filename,
|
|
395
|
+
contentHash,
|
|
396
|
+
contentType: token.contentType,
|
|
397
|
+
size: content.length,
|
|
398
|
+
...metadata ? { metadata } : {}
|
|
399
|
+
}
|
|
400
|
+
);
|
|
401
|
+
return {
|
|
402
|
+
filename,
|
|
403
|
+
skipped: false,
|
|
404
|
+
queued: confirmed.queued,
|
|
405
|
+
document: confirmed.document
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
async function waitForIngest(ctx, params) {
|
|
409
|
+
const { slug, documentIds, onProgress } = params;
|
|
410
|
+
const timeoutMs = params.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS;
|
|
411
|
+
if (documentIds.length === 0) {
|
|
412
|
+
return { status: "up-to-date", documents: [] };
|
|
413
|
+
}
|
|
414
|
+
const wanted = new Set(documentIds);
|
|
415
|
+
const start = Date.now();
|
|
416
|
+
for (; ; ) {
|
|
417
|
+
const { documents: docs } = await call(
|
|
418
|
+
ctx,
|
|
419
|
+
"GET",
|
|
420
|
+
`${base(ctx.appId)}/documents?slug=${encodeURIComponent(slug)}`
|
|
421
|
+
);
|
|
422
|
+
const tracked = (docs ?? []).filter((d) => wanted.has(d.id));
|
|
423
|
+
const pending = tracked.filter((d) => d.status === "processing");
|
|
424
|
+
const failed = tracked.filter((d) => d.status === "error");
|
|
425
|
+
if (pending.length === 0) {
|
|
426
|
+
return {
|
|
427
|
+
status: failed.length ? "error" : "done",
|
|
428
|
+
documents: tracked.map(summarize)
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
if (Date.now() - start > timeoutMs) {
|
|
432
|
+
return {
|
|
433
|
+
status: "timeout",
|
|
434
|
+
documents: tracked.map(summarize),
|
|
435
|
+
error: `Timed out after ${Math.round(timeoutMs / 1e3)}s with ${pending.length} document(s) still processing`
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
onProgress?.(
|
|
439
|
+
`ingesting\u2026 ${tracked.length - pending.length}/${tracked.length} done (${Math.round(
|
|
440
|
+
(Date.now() - start) / 1e3
|
|
441
|
+
)}s)`
|
|
442
|
+
);
|
|
443
|
+
await sleep(POLL_MS);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function documents(ctx, params) {
|
|
447
|
+
return call(
|
|
448
|
+
ctx,
|
|
449
|
+
"GET",
|
|
450
|
+
`${base(ctx.appId)}/documents${qs({ slug: params.slug, candidate: params.candidate || void 0 })}`
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
function list3(ctx) {
|
|
454
|
+
return call(ctx, "GET", base(ctx.appId));
|
|
455
|
+
}
|
|
456
|
+
function search(ctx, params) {
|
|
457
|
+
const {
|
|
458
|
+
slug,
|
|
459
|
+
query: query3,
|
|
460
|
+
topK,
|
|
461
|
+
mode,
|
|
462
|
+
filter,
|
|
463
|
+
maxPerDocument,
|
|
464
|
+
highlight,
|
|
465
|
+
candidate,
|
|
466
|
+
retrieval
|
|
467
|
+
} = params;
|
|
468
|
+
return call(
|
|
469
|
+
ctx,
|
|
470
|
+
"POST",
|
|
471
|
+
`${base(ctx.appId)}/search`,
|
|
472
|
+
{
|
|
473
|
+
slug,
|
|
474
|
+
query: query3,
|
|
475
|
+
...topK ? { topK } : {},
|
|
476
|
+
...mode ? { mode } : {},
|
|
477
|
+
...filter ? { filter } : {},
|
|
478
|
+
...maxPerDocument !== void 0 ? { maxPerDocument } : {},
|
|
479
|
+
...highlight ? { highlight: true } : {},
|
|
480
|
+
...candidate ? { candidate: true } : {},
|
|
481
|
+
...retrieval && Object.keys(retrieval).length ? { retrieval } : {}
|
|
482
|
+
}
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
function configGet(ctx, slug) {
|
|
486
|
+
return call(
|
|
487
|
+
ctx,
|
|
488
|
+
"GET",
|
|
489
|
+
`${base(ctx.appId)}/config?slug=${encodeURIComponent(slug)}`
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
function configSet(ctx, params) {
|
|
493
|
+
const { slug, ingest, retrieval } = params;
|
|
494
|
+
return call(
|
|
495
|
+
ctx,
|
|
496
|
+
"POST",
|
|
497
|
+
`${base(ctx.appId)}/config`,
|
|
498
|
+
{
|
|
499
|
+
slug,
|
|
500
|
+
...ingest ? { ingest } : {},
|
|
501
|
+
...retrieval ? { retrieval } : {}
|
|
502
|
+
}
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
function revectorize(ctx, params) {
|
|
506
|
+
const { slug, ingest } = params;
|
|
507
|
+
return call(
|
|
508
|
+
ctx,
|
|
509
|
+
"POST",
|
|
510
|
+
`${base(ctx.appId)}/revectorize`,
|
|
511
|
+
{
|
|
512
|
+
slug,
|
|
513
|
+
...ingest ? { ingest } : {}
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
function promote(ctx, params) {
|
|
518
|
+
return call(
|
|
519
|
+
ctx,
|
|
520
|
+
"POST",
|
|
521
|
+
`${base(ctx.appId)}/promote`,
|
|
522
|
+
{
|
|
523
|
+
slug: params.slug,
|
|
524
|
+
...params.force ? { force: true } : {}
|
|
525
|
+
}
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
function drop(ctx, params) {
|
|
529
|
+
return call(
|
|
530
|
+
ctx,
|
|
531
|
+
"POST",
|
|
532
|
+
`${base(ctx.appId)}/versions/drop`,
|
|
533
|
+
{
|
|
534
|
+
slug: params.slug,
|
|
535
|
+
...params.version !== void 0 ? { version: params.version } : {}
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
function rm(ctx, params) {
|
|
540
|
+
return call(
|
|
541
|
+
ctx,
|
|
542
|
+
"POST",
|
|
543
|
+
`${base(ctx.appId)}/documents/delete`,
|
|
544
|
+
{
|
|
545
|
+
slug: params.slug,
|
|
546
|
+
documentId: params.documentId
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
function deleteSource(ctx, slug) {
|
|
551
|
+
return call(
|
|
552
|
+
ctx,
|
|
553
|
+
"POST",
|
|
554
|
+
`${base(ctx.appId)}/delete`,
|
|
555
|
+
{ slug }
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// src/ops/db.ts
|
|
560
|
+
var db_exports = {};
|
|
561
|
+
__export(db_exports, {
|
|
562
|
+
query: () => query2
|
|
563
|
+
});
|
|
564
|
+
function query2(ctx, sql) {
|
|
565
|
+
return call(
|
|
566
|
+
ctx,
|
|
567
|
+
"POST",
|
|
568
|
+
`/_internal/v2/apps/${ctx.appId}/db/query`,
|
|
569
|
+
{ queries: [{ sql }] }
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// src/ops/diagnostics.ts
|
|
574
|
+
var diagnostics_exports = {};
|
|
575
|
+
__export(diagnostics_exports, {
|
|
576
|
+
fetchReport: () => fetchReport,
|
|
577
|
+
getLiveReleaseId: () => getLiveReleaseId,
|
|
578
|
+
getRelease: () => getRelease
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// src/ops/releases.ts
|
|
582
|
+
var releases_exports = {};
|
|
583
|
+
__export(releases_exports, {
|
|
584
|
+
byCommit: () => byCommit,
|
|
585
|
+
dashboardLive: () => dashboardLive,
|
|
586
|
+
get: () => get2,
|
|
587
|
+
list: () => list4,
|
|
588
|
+
waitForCommit: () => waitForCommit
|
|
589
|
+
});
|
|
590
|
+
function list4(ctx, params = {}) {
|
|
591
|
+
return call(
|
|
592
|
+
ctx,
|
|
593
|
+
"GET",
|
|
594
|
+
`/_internal/v2/apps/${ctx.appId}/releases${qs({ limit: params.limit })}`
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
function get2(ctx, releaseId) {
|
|
598
|
+
return call(
|
|
599
|
+
ctx,
|
|
600
|
+
"GET",
|
|
601
|
+
`/_internal/v2/apps/${ctx.appId}/releases/${seg(releaseId)}`
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
function byCommit(ctx, commitSha) {
|
|
605
|
+
return tryCall(
|
|
606
|
+
ctx,
|
|
607
|
+
"GET",
|
|
608
|
+
`/_internal/v2/apps/${ctx.appId}/releases/by-commit/${seg(commitSha)}`
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
async function dashboardLive(ctx) {
|
|
612
|
+
const dashboard = await call(
|
|
613
|
+
ctx,
|
|
614
|
+
"GET",
|
|
615
|
+
`/_internal/v2/apps/${ctx.appId}/dashboard`
|
|
616
|
+
);
|
|
617
|
+
return dashboard.liveRelease;
|
|
618
|
+
}
|
|
619
|
+
function buildFailureReason(release) {
|
|
620
|
+
const log = Array.isArray(release.buildLog) ? release.buildLog : [];
|
|
621
|
+
const errors = log.filter(
|
|
622
|
+
(entry) => entry?.phase === "error" && typeof entry.message === "string"
|
|
623
|
+
);
|
|
624
|
+
return errors.length ? errors[errors.length - 1].message : null;
|
|
625
|
+
}
|
|
626
|
+
function summarizeRelease(release) {
|
|
627
|
+
const summary2 = {
|
|
628
|
+
releaseId: release.id,
|
|
629
|
+
commitSha: release.commitSha,
|
|
630
|
+
branch: release.branch ?? null,
|
|
631
|
+
status: release.status,
|
|
632
|
+
buildDurationMs: release.buildDurationMs ?? null,
|
|
633
|
+
publishedAt: release.publishedAt ?? null,
|
|
634
|
+
...release.previewUrl ? { previewUrl: release.previewUrl } : {}
|
|
635
|
+
};
|
|
636
|
+
if (release.status !== "failed") {
|
|
637
|
+
return summary2;
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
...summary2,
|
|
641
|
+
error: buildFailureReason(release) ?? "Build failed (no error entry in the build log)"
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
var POLL_MS2 = 3e3;
|
|
645
|
+
var RESOLVE_GRACE_MS = 3e4;
|
|
646
|
+
var DEFAULT_TIMEOUT_MS = 3e5;
|
|
647
|
+
async function waitForCommit(ctx, params) {
|
|
648
|
+
const { commitSha, onProgress } = params;
|
|
649
|
+
const timeoutMs = params.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
650
|
+
const shortSha = commitSha.slice(0, 8);
|
|
651
|
+
const start = Date.now();
|
|
652
|
+
let release;
|
|
653
|
+
while (true) {
|
|
654
|
+
const r = await byCommit(ctx, commitSha);
|
|
655
|
+
if (r.ok) {
|
|
656
|
+
release = r.body;
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
if (r.status !== 404) {
|
|
660
|
+
throw new Error(
|
|
661
|
+
`Failed to resolve release for ${shortSha}: HTTP ${r.status} ${JSON.stringify(r.body)}`
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
if (Date.now() - start > RESOLVE_GRACE_MS) {
|
|
665
|
+
return {
|
|
666
|
+
outcome: "not_found",
|
|
667
|
+
error: `No release created for commit ${commitSha} within ${RESOLVE_GRACE_MS / 1e3}s \u2014 either the push hasn't registered yet or this SHA never produced a build`
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
onProgress?.(`waiting for release to be created for ${shortSha}\u2026`);
|
|
671
|
+
await sleep(POLL_MS2);
|
|
672
|
+
}
|
|
673
|
+
const SUCCESS = /* @__PURE__ */ new Set(["live", "preview"]);
|
|
674
|
+
while (true) {
|
|
675
|
+
if (SUCCESS.has(release.status)) {
|
|
676
|
+
return {
|
|
677
|
+
outcome: release.status,
|
|
678
|
+
release,
|
|
679
|
+
summary: summarizeRelease(release)
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
if (release.status === "failed") {
|
|
683
|
+
return { outcome: "failed", release, summary: summarizeRelease(release) };
|
|
684
|
+
}
|
|
685
|
+
if (release.status === "superseded") {
|
|
686
|
+
return {
|
|
687
|
+
outcome: "superseded",
|
|
688
|
+
release,
|
|
689
|
+
summary: summarizeRelease(release)
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
if (Date.now() - start > timeoutMs) {
|
|
693
|
+
return {
|
|
694
|
+
outcome: "timeout",
|
|
695
|
+
release,
|
|
696
|
+
summary: summarizeRelease(release),
|
|
697
|
+
error: `Timed out after ${timeoutMs / 1e3}s (last status: ${release.status})`
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
onProgress?.(
|
|
701
|
+
`${release.status}\u2026 (${Math.round((Date.now() - start) / 1e3)}s)`
|
|
702
|
+
);
|
|
703
|
+
await sleep(POLL_MS2);
|
|
704
|
+
const r = await byCommit(ctx, commitSha);
|
|
705
|
+
if (r.ok) {
|
|
706
|
+
release = r.body;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// src/ops/diagnostics.ts
|
|
712
|
+
async function getLiveReleaseId(ctx) {
|
|
713
|
+
const live2 = await dashboardLive(ctx);
|
|
714
|
+
return live2?.id ?? null;
|
|
715
|
+
}
|
|
716
|
+
function getRelease(ctx, releaseId) {
|
|
717
|
+
return call(
|
|
718
|
+
ctx,
|
|
719
|
+
"GET",
|
|
720
|
+
`/_internal/v2/apps/${ctx.appId}/releases/${seg(releaseId)}`
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
async function fetchReport(url) {
|
|
724
|
+
const res = await fetchWithTimeout(
|
|
725
|
+
url,
|
|
726
|
+
{},
|
|
727
|
+
REPORT_TIMEOUT_MS,
|
|
728
|
+
"Lighthouse report fetch"
|
|
729
|
+
);
|
|
730
|
+
if (!res.ok) {
|
|
731
|
+
throw new Error(`Failed to fetch Lighthouse report: HTTP ${res.status}`);
|
|
732
|
+
}
|
|
733
|
+
return res.json();
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// src/ops/domains.ts
|
|
737
|
+
var domains_exports = {};
|
|
738
|
+
__export(domains_exports, {
|
|
739
|
+
check: () => check,
|
|
740
|
+
customAdd: () => customAdd,
|
|
741
|
+
customCheck: () => customCheck,
|
|
742
|
+
customList: () => customList,
|
|
743
|
+
customRemove: () => customRemove,
|
|
744
|
+
customRetry: () => customRetry,
|
|
745
|
+
findHostname: () => findHostname,
|
|
746
|
+
get: () => get3,
|
|
747
|
+
set: () => set
|
|
748
|
+
});
|
|
749
|
+
function get3(ctx) {
|
|
750
|
+
return call(
|
|
751
|
+
ctx,
|
|
752
|
+
"GET",
|
|
753
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-subdomain`
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
function set(ctx, subdomain) {
|
|
757
|
+
return call(
|
|
758
|
+
ctx,
|
|
759
|
+
"POST",
|
|
760
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-subdomain`,
|
|
761
|
+
{ subdomain }
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
function check(ctx, subdomain) {
|
|
765
|
+
return call(
|
|
766
|
+
ctx,
|
|
767
|
+
"POST",
|
|
768
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-subdomain/check-availability`,
|
|
769
|
+
{ subdomain }
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
function customList(ctx) {
|
|
773
|
+
return call(
|
|
774
|
+
ctx,
|
|
775
|
+
"GET",
|
|
776
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-domains`
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
function customAdd(ctx, hostname) {
|
|
780
|
+
return call(
|
|
781
|
+
ctx,
|
|
782
|
+
"POST",
|
|
783
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-domains`,
|
|
784
|
+
{ hostname }
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
function customCheck(ctx, hostname) {
|
|
788
|
+
return call(
|
|
789
|
+
ctx,
|
|
790
|
+
"POST",
|
|
791
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-domains/check-domain`,
|
|
792
|
+
{ hostname }
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
async function findHostname(ctx, hostname) {
|
|
796
|
+
const wanted = hostname.toLowerCase();
|
|
797
|
+
const res = await customList(ctx);
|
|
798
|
+
const entry = (res.hostnames ?? []).find(
|
|
799
|
+
(h) => typeof h.hostname === "string" && h.hostname === wanted
|
|
800
|
+
);
|
|
801
|
+
if (!entry) {
|
|
802
|
+
throw new Error(`No custom domain "${hostname}" found on this app`);
|
|
803
|
+
}
|
|
804
|
+
return { id: entry.id, entry };
|
|
805
|
+
}
|
|
806
|
+
async function customRemove(ctx, hostname) {
|
|
807
|
+
const { id } = await findHostname(ctx, hostname);
|
|
808
|
+
return call(
|
|
809
|
+
ctx,
|
|
810
|
+
"POST",
|
|
811
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-domains/${seg(id)}/delete`
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
async function customRetry(ctx, hostname) {
|
|
815
|
+
const { id } = await findHostname(ctx, hostname);
|
|
816
|
+
return call(
|
|
817
|
+
ctx,
|
|
818
|
+
"POST",
|
|
819
|
+
`/_internal/v2/apps/${ctx.appId}/settings/custom-domains/${seg(id)}/retry`
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// src/ops/email.ts
|
|
824
|
+
var email_exports = {};
|
|
825
|
+
__export(email_exports, {
|
|
826
|
+
addDomain: () => addDomain,
|
|
827
|
+
batch: () => batch2,
|
|
828
|
+
batches: () => batches,
|
|
829
|
+
checkDomain: () => checkDomain,
|
|
830
|
+
get: () => get4,
|
|
831
|
+
inbox: () => inbox,
|
|
832
|
+
list: () => list5,
|
|
833
|
+
listDomains: () => listDomains,
|
|
834
|
+
removeDomain: () => removeDomain,
|
|
835
|
+
stats: () => stats2,
|
|
836
|
+
suppress: () => suppress,
|
|
837
|
+
suppressions: () => suppressions,
|
|
838
|
+
unsuppress: () => unsuppress,
|
|
839
|
+
verifyDomain: () => verifyDomain
|
|
840
|
+
});
|
|
841
|
+
var DOMAIN_BASES = {
|
|
842
|
+
sending: "outbound-email-domains",
|
|
843
|
+
inbound: "email-domains"
|
|
844
|
+
};
|
|
845
|
+
function domainsPath(ctx, direction) {
|
|
846
|
+
return `/_internal/v2/apps/${ctx.appId}/settings/${DOMAIN_BASES[direction]}`;
|
|
847
|
+
}
|
|
848
|
+
async function resolveDomainId(ctx, direction, domain) {
|
|
849
|
+
const { domains } = await call(
|
|
850
|
+
ctx,
|
|
851
|
+
"GET",
|
|
852
|
+
domainsPath(ctx, direction)
|
|
853
|
+
);
|
|
854
|
+
const wanted = domain.trim().toLowerCase();
|
|
855
|
+
const match = (domains ?? []).find(
|
|
856
|
+
(d) => d.domain.toLowerCase() === wanted
|
|
857
|
+
);
|
|
858
|
+
if (!match) {
|
|
859
|
+
const known = (domains ?? []).map((d) => d.domain);
|
|
860
|
+
throw new Error(
|
|
861
|
+
`No ${direction} domain "${domain}" on this app.` + (known.length ? ` Registered: ${known.join(", ")}` : "")
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
return match.id;
|
|
865
|
+
}
|
|
866
|
+
function list5(ctx, params = {}) {
|
|
867
|
+
return call(
|
|
868
|
+
ctx,
|
|
869
|
+
"GET",
|
|
870
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/messages${qs(params)}`
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
function get4(ctx, messageId) {
|
|
874
|
+
return call(
|
|
875
|
+
ctx,
|
|
876
|
+
"GET",
|
|
877
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/messages/${seg(messageId)}`
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
function stats2(ctx, params = {}) {
|
|
881
|
+
return call(
|
|
882
|
+
ctx,
|
|
883
|
+
"GET",
|
|
884
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/summary${qs(params)}`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
function batches(ctx, params = {}) {
|
|
888
|
+
return call(
|
|
889
|
+
ctx,
|
|
890
|
+
"GET",
|
|
891
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/batches${qs(params)}`
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
function batch2(ctx, batchId) {
|
|
895
|
+
return call(
|
|
896
|
+
ctx,
|
|
897
|
+
"GET",
|
|
898
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/batches/${seg(batchId)}`
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
function suppressions(ctx, params = {}) {
|
|
902
|
+
return call(
|
|
903
|
+
ctx,
|
|
904
|
+
"GET",
|
|
905
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/suppressions${qs(params)}`
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
function suppress(ctx, email) {
|
|
909
|
+
return call(
|
|
910
|
+
ctx,
|
|
911
|
+
"POST",
|
|
912
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/suppressions/add`,
|
|
913
|
+
{ email }
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
function unsuppress(ctx, email) {
|
|
917
|
+
return call(
|
|
918
|
+
ctx,
|
|
919
|
+
"POST",
|
|
920
|
+
`/_internal/v2/apps/${ctx.appId}/outbound-email/suppressions/remove`,
|
|
921
|
+
{ email }
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
function inbox(ctx, params = {}) {
|
|
925
|
+
return call(
|
|
926
|
+
ctx,
|
|
927
|
+
"GET",
|
|
928
|
+
`/_internal/v2/apps/${ctx.appId}/inbox${qs(params)}`
|
|
929
|
+
);
|
|
930
|
+
}
|
|
931
|
+
function listDomains(ctx, direction) {
|
|
932
|
+
return call(ctx, "GET", domainsPath(ctx, direction));
|
|
933
|
+
}
|
|
934
|
+
function checkDomain(ctx, direction, domain) {
|
|
935
|
+
return call(ctx, "POST", `${domainsPath(ctx, direction)}/check-domain`, {
|
|
936
|
+
domain
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
function addDomain(ctx, direction, domain) {
|
|
940
|
+
return call(ctx, "POST", domainsPath(ctx, direction), {
|
|
941
|
+
domain
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
async function verifyDomain(ctx, direction, domain) {
|
|
945
|
+
const id = await resolveDomainId(ctx, direction, domain);
|
|
946
|
+
return call(
|
|
947
|
+
ctx,
|
|
948
|
+
"POST",
|
|
949
|
+
`${domainsPath(ctx, direction)}/${seg(id)}/retry`
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
async function removeDomain(ctx, direction, domain) {
|
|
953
|
+
const id = await resolveDomainId(ctx, direction, domain);
|
|
954
|
+
return call(
|
|
955
|
+
ctx,
|
|
956
|
+
"POST",
|
|
957
|
+
`${domainsPath(ctx, direction)}/${seg(id)}/delete`
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// src/ops/files.ts
|
|
962
|
+
var files_exports = {};
|
|
963
|
+
__export(files_exports, {
|
|
964
|
+
fetchBytes: () => fetchBytes,
|
|
965
|
+
ls: () => ls,
|
|
966
|
+
put: () => put,
|
|
967
|
+
remove: () => remove,
|
|
968
|
+
sign: () => sign,
|
|
969
|
+
stat: () => stat,
|
|
970
|
+
summary: () => summary
|
|
971
|
+
});
|
|
972
|
+
import path2 from "path";
|
|
973
|
+
import { createHash as createHash2 } from "crypto";
|
|
974
|
+
async function put(ctx, params) {
|
|
975
|
+
const { content, store, access, filename } = params;
|
|
976
|
+
const key = params.key || `${createHash2("sha256").update(content).digest("hex")}${filename ? path2.extname(filename) : ""}`;
|
|
977
|
+
const cacheControl = params.cacheControl || (!params.key && access === "public" ? "public, max-age=31536000, immutable" : void 0);
|
|
978
|
+
const presign = await call(
|
|
979
|
+
ctx,
|
|
980
|
+
"POST",
|
|
981
|
+
`/_internal/v2/apps/${ctx.appId}/file-storage/upload-url`,
|
|
982
|
+
{
|
|
983
|
+
store,
|
|
984
|
+
access,
|
|
985
|
+
key,
|
|
986
|
+
maxSize: content.length,
|
|
987
|
+
...params.contentType ? { contentType: params.contentType } : {},
|
|
988
|
+
...cacheControl ? { cacheControl } : {}
|
|
989
|
+
}
|
|
990
|
+
);
|
|
991
|
+
params.onProgress?.(
|
|
992
|
+
`uploading ${(content.length / 1024 / 1024).toFixed(1)}MB\u2026`
|
|
993
|
+
);
|
|
994
|
+
await uploadDirect(
|
|
995
|
+
{ uploadUrl: presign.uploadUrl, uploadFields: presign.uploadFields },
|
|
996
|
+
content,
|
|
997
|
+
filename ?? key
|
|
998
|
+
);
|
|
999
|
+
return { key: presign.key, url: presign.url };
|
|
1000
|
+
}
|
|
1001
|
+
function sign(ctx, ref, ttlSeconds) {
|
|
1002
|
+
return call(
|
|
1003
|
+
ctx,
|
|
1004
|
+
"GET",
|
|
1005
|
+
`/_internal/v2/apps/${ctx.appId}/file-storage/url${qs({ ...ref, ttl: ttlSeconds })}`
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
async function fetchBytes(ctx, ref) {
|
|
1009
|
+
const { url } = await sign(
|
|
1010
|
+
ctx,
|
|
1011
|
+
ref,
|
|
1012
|
+
ref.access === "private" ? 60 : void 0
|
|
1013
|
+
);
|
|
1014
|
+
const res = await fetch(url);
|
|
1015
|
+
if (!res.ok) {
|
|
1016
|
+
throw new Error(`Download failed: ${res.status} ${res.statusText}`);
|
|
1017
|
+
}
|
|
1018
|
+
return {
|
|
1019
|
+
bytes: Buffer.from(await res.arrayBuffer()),
|
|
1020
|
+
contentType: res.headers.get("content-type")
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
function stat(ctx, ref) {
|
|
1024
|
+
return call(
|
|
1025
|
+
ctx,
|
|
1026
|
+
"GET",
|
|
1027
|
+
`/_internal/v2/apps/${ctx.appId}/file-storage/metadata${qs(ref)}`
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
function ls(ctx, params) {
|
|
1031
|
+
return call(
|
|
1032
|
+
ctx,
|
|
1033
|
+
"GET",
|
|
1034
|
+
`/_internal/v2/apps/${ctx.appId}/file-storage${qs(params)}`
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
function summary(ctx) {
|
|
1038
|
+
return call(
|
|
1039
|
+
ctx,
|
|
1040
|
+
"GET",
|
|
1041
|
+
`/_internal/v2/apps/${ctx.appId}/file-storage/summary`
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
function remove(ctx, ref) {
|
|
1045
|
+
return call(
|
|
1046
|
+
ctx,
|
|
1047
|
+
"POST",
|
|
1048
|
+
`/_internal/v2/apps/${ctx.appId}/file-storage/delete`,
|
|
1049
|
+
{ store: ref.store, access: ref.access, keys: [ref.key] }
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/ops/issues.ts
|
|
1054
|
+
var issues_exports = {};
|
|
1055
|
+
__export(issues_exports, {
|
|
1056
|
+
close: () => close,
|
|
1057
|
+
comment: () => comment,
|
|
1058
|
+
create: () => create,
|
|
1059
|
+
del: () => del,
|
|
1060
|
+
edit: () => edit,
|
|
1061
|
+
get: () => get5,
|
|
1062
|
+
list: () => list6,
|
|
1063
|
+
reopen: () => reopen
|
|
1064
|
+
});
|
|
1065
|
+
function list6(ctx, params = {}) {
|
|
1066
|
+
return call(
|
|
1067
|
+
ctx,
|
|
1068
|
+
"GET",
|
|
1069
|
+
`/_internal/v2/apps/${ctx.appId}/issues${qs(params)}`
|
|
1070
|
+
);
|
|
1071
|
+
}
|
|
1072
|
+
function get5(ctx, number) {
|
|
1073
|
+
return call(
|
|
1074
|
+
ctx,
|
|
1075
|
+
"GET",
|
|
1076
|
+
`/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}`
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
function create(ctx, params) {
|
|
1080
|
+
const requestBody = {
|
|
1081
|
+
title: params.title,
|
|
1082
|
+
authorKind: "agent"
|
|
1083
|
+
};
|
|
1084
|
+
if (params.body !== void 0) {
|
|
1085
|
+
requestBody.body = params.body;
|
|
1086
|
+
}
|
|
1087
|
+
if (params.kind !== void 0) {
|
|
1088
|
+
requestBody.kind = params.kind;
|
|
1089
|
+
}
|
|
1090
|
+
return call(
|
|
1091
|
+
ctx,
|
|
1092
|
+
"POST",
|
|
1093
|
+
`/_internal/v2/apps/${ctx.appId}/issues`,
|
|
1094
|
+
requestBody
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
function comment(ctx, number, body) {
|
|
1098
|
+
return call(
|
|
1099
|
+
ctx,
|
|
1100
|
+
"POST",
|
|
1101
|
+
`/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/comments`,
|
|
1102
|
+
{ body, authorKind: "agent" }
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
function close(ctx, number) {
|
|
1106
|
+
return call(
|
|
1107
|
+
ctx,
|
|
1108
|
+
"POST",
|
|
1109
|
+
`/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/update`,
|
|
1110
|
+
{ status: "closed", authorKind: "agent" }
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
function reopen(ctx, number) {
|
|
1114
|
+
return call(
|
|
1115
|
+
ctx,
|
|
1116
|
+
"POST",
|
|
1117
|
+
`/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/update`,
|
|
1118
|
+
{ status: "open", authorKind: "agent" }
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
function edit(ctx, number, params) {
|
|
1122
|
+
const requestBody = { authorKind: "agent" };
|
|
1123
|
+
if (params.title !== void 0) {
|
|
1124
|
+
requestBody.title = params.title;
|
|
1125
|
+
}
|
|
1126
|
+
if (params.body !== void 0) {
|
|
1127
|
+
requestBody.body = params.body;
|
|
1128
|
+
}
|
|
1129
|
+
if (params.kind !== void 0) {
|
|
1130
|
+
requestBody.kind = params.kind;
|
|
1131
|
+
}
|
|
1132
|
+
if (params.status !== void 0) {
|
|
1133
|
+
requestBody.status = params.status;
|
|
1134
|
+
}
|
|
1135
|
+
return call(
|
|
1136
|
+
ctx,
|
|
1137
|
+
"POST",
|
|
1138
|
+
`/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/update`,
|
|
1139
|
+
requestBody
|
|
1140
|
+
);
|
|
1141
|
+
}
|
|
1142
|
+
function del(ctx, number) {
|
|
1143
|
+
return call(
|
|
1144
|
+
ctx,
|
|
1145
|
+
"POST",
|
|
1146
|
+
`/_internal/v2/apps/${ctx.appId}/issues/${seg(number)}/delete`
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// src/ops/jewels.ts
|
|
1151
|
+
var jewels_exports = {};
|
|
1152
|
+
__export(jewels_exports, {
|
|
1153
|
+
JEWEL_RUN_TIMEOUT_MS: () => JEWEL_RUN_TIMEOUT_MS,
|
|
1154
|
+
dryrun: () => dryrun,
|
|
1155
|
+
exportSummary: () => exportSummary,
|
|
1156
|
+
getRun: () => getRun,
|
|
1157
|
+
grade: () => grade,
|
|
1158
|
+
overview: () => overview,
|
|
1159
|
+
pair: () => pair,
|
|
1160
|
+
pairs: () => pairs,
|
|
1161
|
+
queue: () => queue,
|
|
1162
|
+
resolve: () => resolve,
|
|
1163
|
+
runs: () => runs,
|
|
1164
|
+
timeseries: () => timeseries,
|
|
1165
|
+
train: () => train
|
|
1166
|
+
});
|
|
1167
|
+
var JEWEL_RUN_TIMEOUT_MS = 6e5;
|
|
1168
|
+
function overview(ctx, params = {}) {
|
|
1169
|
+
return call(
|
|
1170
|
+
ctx,
|
|
1171
|
+
"GET",
|
|
1172
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/overview${qs(params)}`
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
function timeseries(ctx, params = {}) {
|
|
1176
|
+
return call(
|
|
1177
|
+
ctx,
|
|
1178
|
+
"GET",
|
|
1179
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/timeseries${qs(params)}`
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
function pairs(ctx, params = {}) {
|
|
1183
|
+
return call(
|
|
1184
|
+
ctx,
|
|
1185
|
+
"GET",
|
|
1186
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/pairs${qs(params)}`
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
function pair(ctx, pairId) {
|
|
1190
|
+
return call(
|
|
1191
|
+
ctx,
|
|
1192
|
+
"GET",
|
|
1193
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/pairs/${seg(pairId)}`
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
function queue(ctx, params = {}) {
|
|
1197
|
+
return call(
|
|
1198
|
+
ctx,
|
|
1199
|
+
"GET",
|
|
1200
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/queue${qs(params)}`
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
function resolve(ctx, params) {
|
|
1204
|
+
const body = {
|
|
1205
|
+
itemId: params.itemId,
|
|
1206
|
+
action: params.action
|
|
1207
|
+
};
|
|
1208
|
+
if (params.input !== void 0) {
|
|
1209
|
+
body.input = params.input;
|
|
1210
|
+
}
|
|
1211
|
+
return call(
|
|
1212
|
+
ctx,
|
|
1213
|
+
"POST",
|
|
1214
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/queue/resolve`,
|
|
1215
|
+
body,
|
|
1216
|
+
JEWEL_RUN_TIMEOUT_MS
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
function dryrun(ctx, params) {
|
|
1220
|
+
return call(
|
|
1221
|
+
ctx,
|
|
1222
|
+
"POST",
|
|
1223
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/${seg(params.methodId)}/dryrun`,
|
|
1224
|
+
{ subject: params.subject },
|
|
1225
|
+
JEWEL_RUN_TIMEOUT_MS
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
function exportSummary(ctx, params) {
|
|
1229
|
+
return call(
|
|
1230
|
+
ctx,
|
|
1231
|
+
"GET",
|
|
1232
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/export${qs(params)}`,
|
|
1233
|
+
void 0,
|
|
1234
|
+
JEWEL_RUN_TIMEOUT_MS
|
|
1235
|
+
);
|
|
1236
|
+
}
|
|
1237
|
+
function train(ctx, params) {
|
|
1238
|
+
return call(
|
|
1239
|
+
ctx,
|
|
1240
|
+
"POST",
|
|
1241
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/train`,
|
|
1242
|
+
{ methodId: params.methodId },
|
|
1243
|
+
JEWEL_RUN_TIMEOUT_MS
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
function runs(ctx, params = {}) {
|
|
1247
|
+
return call(
|
|
1248
|
+
ctx,
|
|
1249
|
+
"GET",
|
|
1250
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/training-runs${qs(params)}`
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
function getRun(ctx, runId) {
|
|
1254
|
+
return call(
|
|
1255
|
+
ctx,
|
|
1256
|
+
"GET",
|
|
1257
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/training-runs/${seg(runId)}`
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
function grade(ctx, runId) {
|
|
1261
|
+
return call(
|
|
1262
|
+
ctx,
|
|
1263
|
+
"POST",
|
|
1264
|
+
`/_internal/v2/apps/${ctx.appId}/jewels/training-runs/${seg(runId)}/grade`,
|
|
1265
|
+
void 0,
|
|
1266
|
+
JEWEL_RUN_TIMEOUT_MS
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// src/ops/methods.ts
|
|
1271
|
+
var methods_exports = {};
|
|
1272
|
+
__export(methods_exports, {
|
|
1273
|
+
invoke: () => invoke,
|
|
1274
|
+
list: () => list7
|
|
1275
|
+
});
|
|
1276
|
+
async function list7(ctx) {
|
|
1277
|
+
const dashboard = await call(
|
|
1278
|
+
ctx,
|
|
1279
|
+
"GET",
|
|
1280
|
+
`/_internal/v2/apps/${ctx.appId}/dashboard`
|
|
1281
|
+
);
|
|
1282
|
+
const release = dashboard.liveRelease;
|
|
1283
|
+
if (!release) {
|
|
1284
|
+
throw new Error("No live release \u2014 publish first.");
|
|
1285
|
+
}
|
|
1286
|
+
return release.methods ?? [];
|
|
1287
|
+
}
|
|
1288
|
+
function invoke(ctx, params) {
|
|
1289
|
+
const { methodId, input, impersonate } = params;
|
|
1290
|
+
const useImpersonate = impersonate !== void 0 && (impersonate.roles !== void 0 || impersonate.userId !== void 0);
|
|
1291
|
+
const apiPath = useImpersonate ? `/_internal/v2/apps/${ctx.appId}/methods/${seg(methodId)}/invoke-as` : `/_internal/v2/apps/${ctx.appId}/methods/${seg(methodId)}/invoke`;
|
|
1292
|
+
const body = useImpersonate ? { input, impersonate } : { input };
|
|
1293
|
+
return call(ctx, "POST", apiPath, body);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// src/ops/prerender.ts
|
|
1297
|
+
var prerender_exports = {};
|
|
1298
|
+
__export(prerender_exports, {
|
|
1299
|
+
invalidate: () => invalidate,
|
|
1300
|
+
pages: () => pages,
|
|
1301
|
+
view: () => view
|
|
1302
|
+
});
|
|
1303
|
+
function pages(ctx, params = {}) {
|
|
1304
|
+
return call(
|
|
1305
|
+
ctx,
|
|
1306
|
+
"GET",
|
|
1307
|
+
`/_internal/v2/apps/${ctx.appId}/prerender/pages${qs(params)}`
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
function view(ctx, params) {
|
|
1311
|
+
return call(
|
|
1312
|
+
ctx,
|
|
1313
|
+
"GET",
|
|
1314
|
+
`/_internal/v2/apps/${ctx.appId}/prerender/pages/view${qs({ path: params.path })}`
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
function invalidate(ctx, params = {}) {
|
|
1318
|
+
const body = {};
|
|
1319
|
+
if (params.paths !== void 0 && params.paths.length > 0) {
|
|
1320
|
+
body.paths = params.paths;
|
|
1321
|
+
}
|
|
1322
|
+
return call(
|
|
1323
|
+
ctx,
|
|
1324
|
+
"POST",
|
|
1325
|
+
`/_internal/v2/apps/${ctx.appId}/prerender/invalidate`,
|
|
1326
|
+
body
|
|
1327
|
+
);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
// src/ops/requests.ts
|
|
1331
|
+
var requests_exports = {};
|
|
1332
|
+
__export(requests_exports, {
|
|
1333
|
+
get: () => get6,
|
|
1334
|
+
list: () => list8,
|
|
1335
|
+
statsForMethod: () => statsForMethod,
|
|
1336
|
+
statsSummary: () => statsSummary
|
|
1337
|
+
});
|
|
1338
|
+
function list8(ctx, params = {}) {
|
|
1339
|
+
return call(
|
|
1340
|
+
ctx,
|
|
1341
|
+
"GET",
|
|
1342
|
+
`/_internal/v2/apps/${ctx.appId}/requests${qs(params)}`
|
|
1343
|
+
);
|
|
1344
|
+
}
|
|
1345
|
+
function get6(ctx, requestId) {
|
|
1346
|
+
return call(
|
|
1347
|
+
ctx,
|
|
1348
|
+
"GET",
|
|
1349
|
+
`/_internal/v2/apps/${ctx.appId}/requests/${seg(requestId)}`
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
function statsSummary(ctx, params = {}) {
|
|
1353
|
+
return call(
|
|
1354
|
+
ctx,
|
|
1355
|
+
"GET",
|
|
1356
|
+
`/_internal/v2/apps/${ctx.appId}/metrics/summary${qs(params)}`
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
function statsForMethod(ctx, methodId, params = {}) {
|
|
1360
|
+
return call(
|
|
1361
|
+
ctx,
|
|
1362
|
+
"GET",
|
|
1363
|
+
`/_internal/v2/apps/${ctx.appId}/metrics/methods/${seg(methodId)}${qs(params)}`
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
// src/ops/secrets.ts
|
|
1368
|
+
var secrets_exports = {};
|
|
1369
|
+
__export(secrets_exports, {
|
|
1370
|
+
del: () => del2,
|
|
1371
|
+
get: () => get7,
|
|
1372
|
+
list: () => list9,
|
|
1373
|
+
set: () => set2
|
|
1374
|
+
});
|
|
1375
|
+
function list9(ctx) {
|
|
1376
|
+
return call(
|
|
1377
|
+
ctx,
|
|
1378
|
+
"GET",
|
|
1379
|
+
`/_internal/v2/apps/${ctx.appId}/secrets`
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1382
|
+
function get7(ctx, key) {
|
|
1383
|
+
return call(
|
|
1384
|
+
ctx,
|
|
1385
|
+
"GET",
|
|
1386
|
+
`/_internal/v2/apps/${ctx.appId}/secrets/${seg(key)}`
|
|
1387
|
+
);
|
|
1388
|
+
}
|
|
1389
|
+
function set2(ctx, key, params) {
|
|
1390
|
+
const body = {};
|
|
1391
|
+
if ("devValue" in params) {
|
|
1392
|
+
body.devValue = params.devValue;
|
|
1393
|
+
}
|
|
1394
|
+
if ("prodValue" in params) {
|
|
1395
|
+
body.prodValue = params.prodValue;
|
|
1396
|
+
}
|
|
1397
|
+
return call(
|
|
1398
|
+
ctx,
|
|
1399
|
+
"PUT",
|
|
1400
|
+
`/_internal/v2/apps/${ctx.appId}/secrets/${seg(key)}`,
|
|
1401
|
+
body
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
function del2(ctx, key) {
|
|
1405
|
+
return call(
|
|
1406
|
+
ctx,
|
|
1407
|
+
"DELETE",
|
|
1408
|
+
`/_internal/v2/apps/${ctx.appId}/secrets/${seg(key)}`
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// src/ops/settings.ts
|
|
1413
|
+
var settings_exports = {};
|
|
1414
|
+
__export(settings_exports, {
|
|
1415
|
+
getSettings: () => getSettings,
|
|
1416
|
+
updateSettings: () => updateSettings
|
|
1417
|
+
});
|
|
1418
|
+
function getSettings(ctx) {
|
|
1419
|
+
return call(
|
|
1420
|
+
ctx,
|
|
1421
|
+
"GET",
|
|
1422
|
+
`/_internal/v2/apps/${ctx.appId}/settings/v2`
|
|
1423
|
+
).then((res) => res.settings ?? {});
|
|
1424
|
+
}
|
|
1425
|
+
function updateSettings(ctx, partial) {
|
|
1426
|
+
return call(
|
|
1427
|
+
ctx,
|
|
1428
|
+
"POST",
|
|
1429
|
+
`/_internal/v2/apps/${ctx.appId}/settings/v2`,
|
|
1430
|
+
partial
|
|
1431
|
+
).then((res) => res.settings ?? {});
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// src/ops/users.ts
|
|
1435
|
+
var users_exports = {};
|
|
1436
|
+
__export(users_exports, {
|
|
1437
|
+
createApiKey: () => createApiKey,
|
|
1438
|
+
list: () => list10,
|
|
1439
|
+
revokeApiKey: () => revokeApiKey,
|
|
1440
|
+
setRole: () => setRole
|
|
1441
|
+
});
|
|
1442
|
+
function list10(ctx, params = {}) {
|
|
1443
|
+
return call(
|
|
1444
|
+
ctx,
|
|
1445
|
+
"GET",
|
|
1446
|
+
`/_internal/v2/apps/${ctx.appId}/users${qs(params)}`
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
function setRole(ctx, userId, role) {
|
|
1450
|
+
return call(
|
|
1451
|
+
ctx,
|
|
1452
|
+
"POST",
|
|
1453
|
+
`/_internal/v2/apps/${ctx.appId}/users/${seg(userId)}/roles`,
|
|
1454
|
+
{ roles: [role] }
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1457
|
+
function createApiKey(ctx, userId) {
|
|
1458
|
+
return call(
|
|
1459
|
+
ctx,
|
|
1460
|
+
"POST",
|
|
1461
|
+
`/_internal/v2/apps/${ctx.appId}/users/${seg(userId)}/api-key`
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
function revokeApiKey(ctx, userId) {
|
|
1465
|
+
return call(
|
|
1466
|
+
ctx,
|
|
1467
|
+
"DELETE",
|
|
1468
|
+
`/_internal/v2/apps/${ctx.appId}/users/${seg(userId)}/api-key`
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// src/ops/voice.ts
|
|
1473
|
+
var voice_exports = {};
|
|
1474
|
+
__export(voice_exports, {
|
|
1475
|
+
numbersBuy: () => numbersBuy,
|
|
1476
|
+
numbersList: () => numbersList,
|
|
1477
|
+
numbersRelease: () => numbersRelease,
|
|
1478
|
+
numbersSearch: () => numbersSearch,
|
|
1479
|
+
numbersSetName: () => numbersSetName,
|
|
1480
|
+
sessionsGet: () => sessionsGet,
|
|
1481
|
+
sessionsList: () => sessionsList,
|
|
1482
|
+
settingsGet: () => settingsGet,
|
|
1483
|
+
settingsSet: () => settingsSet
|
|
1484
|
+
});
|
|
1485
|
+
function normalizeE164(input) {
|
|
1486
|
+
const stripped = input.replace(/[\s().-]/g, "");
|
|
1487
|
+
if (/^\d{10}$/.test(stripped)) {
|
|
1488
|
+
return `+1${stripped}`;
|
|
1489
|
+
}
|
|
1490
|
+
if (/^1\d{10}$/.test(stripped)) {
|
|
1491
|
+
return `+${stripped}`;
|
|
1492
|
+
}
|
|
1493
|
+
return stripped;
|
|
1494
|
+
}
|
|
1495
|
+
function numbersList(ctx) {
|
|
1496
|
+
return call(
|
|
1497
|
+
ctx,
|
|
1498
|
+
"GET",
|
|
1499
|
+
`/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers`
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
function numbersSearch(ctx, params) {
|
|
1503
|
+
return call(
|
|
1504
|
+
ctx,
|
|
1505
|
+
"POST",
|
|
1506
|
+
`/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers/search`,
|
|
1507
|
+
{
|
|
1508
|
+
areaCode: params.areaCode,
|
|
1509
|
+
locality: params.locality,
|
|
1510
|
+
administrativeArea: params.administrativeArea,
|
|
1511
|
+
limit: params.limit
|
|
1512
|
+
}
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
function numbersBuy(ctx, params) {
|
|
1516
|
+
return call(
|
|
1517
|
+
ctx,
|
|
1518
|
+
"POST",
|
|
1519
|
+
`/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers`,
|
|
1520
|
+
{
|
|
1521
|
+
phoneNumber: params.phoneNumber,
|
|
1522
|
+
locality: params.locality,
|
|
1523
|
+
administrativeArea: params.administrativeArea,
|
|
1524
|
+
monthlyCost: params.monthlyCost
|
|
1525
|
+
}
|
|
1526
|
+
);
|
|
1527
|
+
}
|
|
1528
|
+
async function findNumberId(ctx, e164) {
|
|
1529
|
+
const normalized = normalizeE164(e164);
|
|
1530
|
+
const res = await numbersList(ctx);
|
|
1531
|
+
const entry = (res.numbers ?? []).find((n) => n.e164 === normalized);
|
|
1532
|
+
if (!entry) {
|
|
1533
|
+
throw new Error(`No phone number "${e164}" on this app`);
|
|
1534
|
+
}
|
|
1535
|
+
return entry.id;
|
|
1536
|
+
}
|
|
1537
|
+
async function numbersRelease(ctx, e164) {
|
|
1538
|
+
const id = await findNumberId(ctx, e164);
|
|
1539
|
+
return call(
|
|
1540
|
+
ctx,
|
|
1541
|
+
"POST",
|
|
1542
|
+
`/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers/${seg(id)}/release`
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
async function numbersSetName(ctx, e164, displayName) {
|
|
1546
|
+
const id = await findNumberId(ctx, e164);
|
|
1547
|
+
return call(
|
|
1548
|
+
ctx,
|
|
1549
|
+
"POST",
|
|
1550
|
+
`/_internal/v2/apps/${ctx.appId}/settings/voice-phone-numbers/${seg(id)}/display-name`,
|
|
1551
|
+
{ displayName }
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
function sessionsList(ctx, params = {}) {
|
|
1555
|
+
return call(
|
|
1556
|
+
ctx,
|
|
1557
|
+
"GET",
|
|
1558
|
+
`/_internal/v2/apps/${ctx.appId}/voice-sessions${qs(params)}`
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
function sessionsGet(ctx, sessionId) {
|
|
1562
|
+
return call(
|
|
1563
|
+
ctx,
|
|
1564
|
+
"GET",
|
|
1565
|
+
`/_internal/v2/apps/${ctx.appId}/voice-sessions/${seg(sessionId)}`
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1568
|
+
function settingsGet(ctx) {
|
|
1569
|
+
return call(
|
|
1570
|
+
ctx,
|
|
1571
|
+
"GET",
|
|
1572
|
+
`/_internal/v2/apps/${ctx.appId}/voice-settings`
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
function settingsSet(ctx, params) {
|
|
1576
|
+
return call(
|
|
1577
|
+
ctx,
|
|
1578
|
+
"PUT",
|
|
1579
|
+
`/_internal/v2/apps/${ctx.appId}/voice-settings`,
|
|
1580
|
+
{
|
|
1581
|
+
maxConcurrentSessions: params.maxConcurrentSessions,
|
|
1582
|
+
maxConcurrentSessionsPerVisitor: params.maxConcurrentSessionsPerVisitor,
|
|
1583
|
+
maxSessionDurationSecs: params.maxSessionDurationSecs
|
|
1584
|
+
}
|
|
1585
|
+
);
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// src/client.ts
|
|
1589
|
+
function bindOps(ops, ctx) {
|
|
1590
|
+
const bound = {};
|
|
1591
|
+
for (const [name, value] of Object.entries(ops)) {
|
|
1592
|
+
if (typeof value === "function") {
|
|
1593
|
+
bound[name] = (...args) => value(ctx, ...args);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
return bound;
|
|
1597
|
+
}
|
|
1598
|
+
function resolveOptions(options) {
|
|
1599
|
+
const apiKey = options.apiKey ?? process.env["MINDSTUDIO_API_KEY"] ?? "";
|
|
1600
|
+
if (!apiKey) {
|
|
1601
|
+
throw new Error(
|
|
1602
|
+
"No API key: pass { apiKey } to createAdminClient or set MINDSTUDIO_API_KEY"
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
return {
|
|
1606
|
+
apiKey,
|
|
1607
|
+
// loadWorkspaceAppId throws its own precise message if there's no
|
|
1608
|
+
// mindstudio.json to fall back to.
|
|
1609
|
+
appId: options.appId ?? loadWorkspaceAppId(),
|
|
1610
|
+
baseUrl: options.baseUrl ?? process.env["API_BASE_URL"] ?? DEFAULT_BASE_URL
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function buildClient(ctx) {
|
|
1614
|
+
return {
|
|
1615
|
+
/** The resolved context this client is bound to. */
|
|
1616
|
+
context: ctx,
|
|
1617
|
+
/** A sibling client for another app, sharing credentials. */
|
|
1618
|
+
forApp(appId) {
|
|
1619
|
+
return buildClient({ ...ctx, appId });
|
|
1620
|
+
},
|
|
1621
|
+
analytics: bindOps(analytics_exports, ctx),
|
|
1622
|
+
crashes: bindOps(crashes_exports, ctx),
|
|
1623
|
+
cron: bindOps(cron_exports, ctx),
|
|
1624
|
+
data: bindOps(data_exports, ctx),
|
|
1625
|
+
dataSources: bindOps(dataSources_exports, ctx),
|
|
1626
|
+
db: bindOps(db_exports, ctx),
|
|
1627
|
+
diagnostics: bindOps(diagnostics_exports, ctx),
|
|
1628
|
+
domains: bindOps(domains_exports, ctx),
|
|
1629
|
+
email: {
|
|
1630
|
+
...bindOps(email_exports, ctx),
|
|
1631
|
+
// Hand-bound: these are generic over the direction ('sending' |
|
|
1632
|
+
// 'inbound') and bindOps' mapped type would erase the generic,
|
|
1633
|
+
// collapsing every result to the cross-direction union.
|
|
1634
|
+
listDomains: (direction) => listDomains(ctx, direction),
|
|
1635
|
+
checkDomain: (direction, domain) => checkDomain(ctx, direction, domain),
|
|
1636
|
+
addDomain: (direction, domain) => addDomain(ctx, direction, domain),
|
|
1637
|
+
verifyDomain: (direction, domain) => verifyDomain(ctx, direction, domain),
|
|
1638
|
+
removeDomain: (direction, domain) => removeDomain(ctx, direction, domain)
|
|
1639
|
+
},
|
|
1640
|
+
files: bindOps(files_exports, ctx),
|
|
1641
|
+
issues: bindOps(issues_exports, ctx),
|
|
1642
|
+
jewels: bindOps(jewels_exports, ctx),
|
|
1643
|
+
methods: bindOps(methods_exports, ctx),
|
|
1644
|
+
prerender: bindOps(prerender_exports, ctx),
|
|
1645
|
+
releases: bindOps(releases_exports, ctx),
|
|
1646
|
+
requests: bindOps(requests_exports, ctx),
|
|
1647
|
+
secrets: bindOps(secrets_exports, ctx),
|
|
1648
|
+
settings: bindOps(settings_exports, ctx),
|
|
1649
|
+
users: bindOps(users_exports, ctx),
|
|
1650
|
+
voice: bindOps(voice_exports, ctx)
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
function createAdminClient(options = {}) {
|
|
1654
|
+
return buildClient(resolveOptions(options));
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
// src/index.ts
|
|
1658
|
+
var _default;
|
|
1659
|
+
var admin = new Proxy({}, {
|
|
1660
|
+
get(_, prop, receiver) {
|
|
1661
|
+
_default ??= createAdminClient();
|
|
1662
|
+
const value = Reflect.get(_default, prop, _default);
|
|
1663
|
+
return typeof value === "function" ? value.bind(_default) : value;
|
|
1664
|
+
}
|
|
1665
|
+
});
|
|
1666
|
+
var index_default = admin;
|
|
1667
|
+
export {
|
|
1668
|
+
AdminApiError,
|
|
1669
|
+
AdminTimeoutError,
|
|
1670
|
+
admin,
|
|
1671
|
+
createAdminClient,
|
|
1672
|
+
index_default as default
|
|
1673
|
+
};
|
|
1674
|
+
//# sourceMappingURL=index.js.map
|