@crvouga/mockingbird-service-formbricks 1.3.0 → 1.5.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/CHANGELOG.md +14 -2
- package/dist/{chunk-JEJVVA5B.js → chunk-TNGXNIQB.js} +2295 -101
- package/dist/chunk-TNGXNIQB.js.map +7 -0
- package/dist/{chunk-RM4FNXU4.js → chunk-ZN5CKPD3.js} +3 -2
- package/dist/{chunk-RM4FNXU4.js.map → chunk-ZN5CKPD3.js.map} +2 -2
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/server.d.ts +73 -3
- package/dist/server.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-JEJVVA5B.js.map +0 -7
|
@@ -38,30 +38,30 @@ var createClock = (source = Date.now) => {
|
|
|
38
38
|
var Collection = class {
|
|
39
39
|
sqlite;
|
|
40
40
|
namespace;
|
|
41
|
-
|
|
42
|
-
constructor(sqlite, namespace,
|
|
41
|
+
collectionName;
|
|
42
|
+
constructor(sqlite, namespace, collectionName) {
|
|
43
43
|
this.sqlite = sqlite;
|
|
44
44
|
this.namespace = namespace;
|
|
45
|
-
this.
|
|
45
|
+
this.collectionName = collectionName;
|
|
46
46
|
}
|
|
47
47
|
bumpCollectionSeq() {
|
|
48
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.
|
|
48
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.collectionName);
|
|
49
49
|
const next = (row?.value ?? 0) + 1;
|
|
50
50
|
this.sqlite.prepare(`INSERT INTO mockingbird_sequences (namespace, name, kind, value) VALUES (?, ?, 'collection', ?)
|
|
51
|
-
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.
|
|
51
|
+
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.collectionName, next);
|
|
52
52
|
return next;
|
|
53
53
|
}
|
|
54
54
|
nextSequence() {
|
|
55
55
|
return this.sqlite.transaction(() => this.bumpCollectionSeq());
|
|
56
56
|
}
|
|
57
57
|
get(id) {
|
|
58
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
58
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
59
59
|
if (!row)
|
|
60
60
|
return void 0;
|
|
61
61
|
return JSON.parse(row.value).value;
|
|
62
62
|
}
|
|
63
63
|
has(id) {
|
|
64
|
-
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
64
|
+
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
65
65
|
return row !== void 0;
|
|
66
66
|
}
|
|
67
67
|
/** Insert a new record, assigning it the next sequence number. */
|
|
@@ -71,32 +71,32 @@ var Collection = class {
|
|
|
71
71
|
const stored = { seq, value };
|
|
72
72
|
this.sqlite.prepare(`INSERT INTO mockingbird_records (namespace, collection, id, seq, value)
|
|
73
73
|
VALUES (?, ?, ?, ?, ?)
|
|
74
|
-
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.
|
|
74
|
+
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.collectionName, id, seq, JSON.stringify(stored));
|
|
75
75
|
return stored;
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
/** Replace an existing record's value, keeping its position. */
|
|
79
79
|
update(id, value) {
|
|
80
80
|
return this.sqlite.transaction(() => {
|
|
81
|
-
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
81
|
+
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
82
82
|
if (!row)
|
|
83
83
|
return void 0;
|
|
84
84
|
const stored = { seq: row.seq, value };
|
|
85
|
-
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.
|
|
85
|
+
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.collectionName, id);
|
|
86
86
|
return stored;
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
delete(id) {
|
|
90
|
-
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.
|
|
90
|
+
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.collectionName, id);
|
|
91
91
|
return result.changes > 0;
|
|
92
92
|
}
|
|
93
93
|
/** How many records the collection holds, without reading them. */
|
|
94
94
|
count() {
|
|
95
|
-
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.
|
|
95
|
+
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.collectionName);
|
|
96
96
|
return Number(row?.n ?? 0);
|
|
97
97
|
}
|
|
98
98
|
list(options = {}) {
|
|
99
|
-
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.
|
|
99
|
+
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.collectionName);
|
|
100
100
|
const out = [];
|
|
101
101
|
for (const row of rows) {
|
|
102
102
|
const stored = JSON.parse(row.value);
|
|
@@ -353,16 +353,18 @@ var createControlPlane = (context) => {
|
|
|
353
353
|
uptimeMs: context.wallNow() - context.startedAt,
|
|
354
354
|
clock: context.clock.state(),
|
|
355
355
|
namespaces: context.namespaces().length,
|
|
356
|
+
adminUi: `${ADMIN_PREFIX}/ui`,
|
|
356
357
|
...context.describe()
|
|
357
358
|
});
|
|
358
359
|
}
|
|
359
360
|
if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
|
|
360
361
|
return void 0;
|
|
361
362
|
}
|
|
362
|
-
|
|
363
|
+
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
364
|
+
const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
|
|
365
|
+
if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
|
|
363
366
|
return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
|
|
364
367
|
}
|
|
365
|
-
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
366
368
|
for (const route of routes) {
|
|
367
369
|
if (route.method !== request.method)
|
|
368
370
|
continue;
|
|
@@ -531,10 +533,10 @@ var OpenAPIReferenceError = class extends Error {
|
|
|
531
533
|
};
|
|
532
534
|
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
533
535
|
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
534
|
-
var resolveRef = (
|
|
536
|
+
var resolveRef = (document3, ref) => {
|
|
535
537
|
if (!ref.startsWith("#/"))
|
|
536
538
|
throw new OpenAPIReferenceError(ref);
|
|
537
|
-
let cursor =
|
|
539
|
+
let cursor = document3;
|
|
538
540
|
for (const raw of ref.slice(2).split("/")) {
|
|
539
541
|
const segment = unescapePointer(raw);
|
|
540
542
|
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
@@ -546,14 +548,14 @@ var resolveRef = (document2, ref) => {
|
|
|
546
548
|
throw new OpenAPIReferenceError(ref);
|
|
547
549
|
return cursor;
|
|
548
550
|
};
|
|
549
|
-
var deref = (
|
|
551
|
+
var deref = (document3, value) => {
|
|
550
552
|
let current = value;
|
|
551
553
|
const seen = /* @__PURE__ */ new Set();
|
|
552
554
|
while (isReference(current)) {
|
|
553
555
|
if (seen.has(current.$ref))
|
|
554
556
|
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
555
557
|
seen.add(current.$ref);
|
|
556
|
-
current = resolveRef(
|
|
558
|
+
current = resolveRef(document3, current.$ref);
|
|
557
559
|
}
|
|
558
560
|
return current;
|
|
559
561
|
};
|
|
@@ -571,36 +573,36 @@ var HTTP_METHODS = [
|
|
|
571
573
|
];
|
|
572
574
|
|
|
573
575
|
// ../../openapi/core/dist/document.js
|
|
574
|
-
var mergeParameters = (
|
|
576
|
+
var mergeParameters = (document3, item, own) => {
|
|
575
577
|
const merged = /* @__PURE__ */ new Map();
|
|
576
578
|
for (const raw of item.parameters ?? []) {
|
|
577
|
-
const parameter = deref(
|
|
579
|
+
const parameter = deref(document3, raw);
|
|
578
580
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
579
581
|
}
|
|
580
582
|
for (const raw of own ?? []) {
|
|
581
|
-
const parameter = deref(
|
|
583
|
+
const parameter = deref(document3, raw);
|
|
582
584
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
583
585
|
}
|
|
584
586
|
return [...merged.values()];
|
|
585
587
|
};
|
|
586
|
-
var listOperations = (
|
|
588
|
+
var listOperations = (document3) => {
|
|
587
589
|
const operations = [];
|
|
588
|
-
for (const [path, item] of Object.entries(
|
|
590
|
+
for (const [path, item] of Object.entries(document3.paths)) {
|
|
589
591
|
for (const method of HTTP_METHODS) {
|
|
590
592
|
const operation = item[method];
|
|
591
593
|
if (operation?.operationId === void 0)
|
|
592
594
|
continue;
|
|
593
595
|
const responses = {};
|
|
594
596
|
for (const [status, response] of Object.entries(operation.responses)) {
|
|
595
|
-
responses[status] = deref(
|
|
597
|
+
responses[status] = deref(document3, response);
|
|
596
598
|
}
|
|
597
599
|
operations.push({
|
|
598
600
|
operationId: operation.operationId,
|
|
599
601
|
method,
|
|
600
602
|
path,
|
|
601
603
|
operation,
|
|
602
|
-
parameters: mergeParameters(
|
|
603
|
-
requestBody: operation.requestBody === void 0 ? void 0 : deref(
|
|
604
|
+
parameters: mergeParameters(document3, item, operation.parameters),
|
|
605
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
|
|
604
606
|
responses
|
|
605
607
|
});
|
|
606
608
|
}
|
|
@@ -1136,6 +1138,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1136
1138
|
});
|
|
1137
1139
|
};
|
|
1138
1140
|
|
|
1141
|
+
// ../../ui/dist/reset.js
|
|
1142
|
+
var CSS_RESET = `*,
|
|
1143
|
+
*::before,
|
|
1144
|
+
*::after {
|
|
1145
|
+
box-sizing: border-box;
|
|
1146
|
+
margin: 0;
|
|
1147
|
+
padding: 0;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
* {
|
|
1151
|
+
scrollbar-width: thin;
|
|
1152
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
*::-webkit-scrollbar {
|
|
1156
|
+
width: 12px;
|
|
1157
|
+
height: 12px;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
*::-webkit-scrollbar-track,
|
|
1161
|
+
*::-webkit-scrollbar-corner {
|
|
1162
|
+
background: Canvas;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
*::-webkit-scrollbar-thumb {
|
|
1166
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1167
|
+
border: 3px solid Canvas;
|
|
1168
|
+
border-radius: 999px;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
html {
|
|
1172
|
+
hanging-punctuation: first allow-end last;
|
|
1173
|
+
-webkit-text-size-adjust: none;
|
|
1174
|
+
text-size-adjust: none;
|
|
1175
|
+
tab-size: 4;
|
|
1176
|
+
font-family:
|
|
1177
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1178
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1179
|
+
font-size: 16px;
|
|
1180
|
+
line-height: 1.5;
|
|
1181
|
+
-webkit-font-smoothing: antialiased;
|
|
1182
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1183
|
+
text-rendering: optimizeLegibility;
|
|
1184
|
+
-webkit-tap-highlight-color: transparent;
|
|
1185
|
+
scroll-behavior: smooth;
|
|
1186
|
+
background: Canvas;
|
|
1187
|
+
color: CanvasText;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
body {
|
|
1191
|
+
min-height: 100svh;
|
|
1192
|
+
line-height: 1.5;
|
|
1193
|
+
background: Canvas;
|
|
1194
|
+
color: CanvasText;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
h1 {
|
|
1198
|
+
font-size: 2em;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
h2 {
|
|
1202
|
+
font-size: 1.5em;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
h3 {
|
|
1206
|
+
font-size: 1.17em;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
h4 {
|
|
1210
|
+
font-size: 1em;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
h5 {
|
|
1214
|
+
font-size: 0.83em;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
h6 {
|
|
1218
|
+
font-size: 0.67em;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
h1,
|
|
1222
|
+
h2,
|
|
1223
|
+
h3,
|
|
1224
|
+
h4,
|
|
1225
|
+
h5,
|
|
1226
|
+
h6 {
|
|
1227
|
+
font-weight: 700;
|
|
1228
|
+
line-height: 1.2;
|
|
1229
|
+
text-wrap: balance;
|
|
1230
|
+
overflow-wrap: break-word;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
p,
|
|
1234
|
+
li,
|
|
1235
|
+
figcaption,
|
|
1236
|
+
dd,
|
|
1237
|
+
dt,
|
|
1238
|
+
blockquote {
|
|
1239
|
+
overflow-wrap: break-word;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
p,
|
|
1243
|
+
li,
|
|
1244
|
+
figcaption,
|
|
1245
|
+
blockquote {
|
|
1246
|
+
text-wrap: pretty;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
ul,
|
|
1250
|
+
ol,
|
|
1251
|
+
menu {
|
|
1252
|
+
list-style: none;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
a {
|
|
1256
|
+
color: inherit;
|
|
1257
|
+
text-decoration: underline;
|
|
1258
|
+
text-decoration-thickness: 1px;
|
|
1259
|
+
text-underline-offset: 0.15em;
|
|
1260
|
+
text-decoration-skip-ink: auto;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
b,
|
|
1264
|
+
strong {
|
|
1265
|
+
font-weight: 700;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
small {
|
|
1269
|
+
font-size: 0.875em;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
code,
|
|
1273
|
+
kbd,
|
|
1274
|
+
samp,
|
|
1275
|
+
pre {
|
|
1276
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1277
|
+
font-size: 1em;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
sub,
|
|
1281
|
+
sup {
|
|
1282
|
+
font-size: 75%;
|
|
1283
|
+
line-height: 0;
|
|
1284
|
+
position: relative;
|
|
1285
|
+
vertical-align: baseline;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
sub {
|
|
1289
|
+
bottom: -0.25em;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
sup {
|
|
1293
|
+
top: -0.5em;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
abbr[title] {
|
|
1297
|
+
text-decoration: underline dotted;
|
|
1298
|
+
text-underline-offset: 0.15em;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
mark {
|
|
1302
|
+
background: Mark;
|
|
1303
|
+
color: MarkText;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
hr {
|
|
1307
|
+
height: 0;
|
|
1308
|
+
border: 0;
|
|
1309
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1310
|
+
color: inherit;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
img,
|
|
1314
|
+
picture,
|
|
1315
|
+
video,
|
|
1316
|
+
canvas {
|
|
1317
|
+
display: block;
|
|
1318
|
+
max-width: 100%;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
img,
|
|
1322
|
+
video {
|
|
1323
|
+
height: auto;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
svg {
|
|
1327
|
+
overflow: hidden;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
iframe {
|
|
1331
|
+
border: 0;
|
|
1332
|
+
max-width: 100%;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
table {
|
|
1336
|
+
border-collapse: collapse;
|
|
1337
|
+
border-spacing: 0;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
fieldset {
|
|
1341
|
+
border: 0;
|
|
1342
|
+
min-inline-size: 0;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
legend {
|
|
1346
|
+
padding: 0;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
button,
|
|
1350
|
+
input,
|
|
1351
|
+
select,
|
|
1352
|
+
textarea,
|
|
1353
|
+
optgroup {
|
|
1354
|
+
font: inherit;
|
|
1355
|
+
letter-spacing: inherit;
|
|
1356
|
+
color: inherit;
|
|
1357
|
+
margin: 0;
|
|
1358
|
+
vertical-align: middle;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
button,
|
|
1362
|
+
input[type="button"],
|
|
1363
|
+
input[type="submit"],
|
|
1364
|
+
input[type="reset"] {
|
|
1365
|
+
appearance: none;
|
|
1366
|
+
background: none;
|
|
1367
|
+
border: 0;
|
|
1368
|
+
padding: 0;
|
|
1369
|
+
cursor: pointer;
|
|
1370
|
+
text-align: center;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
input,
|
|
1374
|
+
textarea,
|
|
1375
|
+
select {
|
|
1376
|
+
background-color: Canvas;
|
|
1377
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1378
|
+
border-radius: 0;
|
|
1379
|
+
padding: 0.5em 0.65em;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
input[type="checkbox"],
|
|
1383
|
+
input[type="radio"],
|
|
1384
|
+
input[type="range"],
|
|
1385
|
+
input[type="file"],
|
|
1386
|
+
input[type="color"],
|
|
1387
|
+
input[type="button"],
|
|
1388
|
+
input[type="submit"],
|
|
1389
|
+
input[type="reset"],
|
|
1390
|
+
input[type="image"],
|
|
1391
|
+
input[type="hidden"] {
|
|
1392
|
+
background: none;
|
|
1393
|
+
border: 0;
|
|
1394
|
+
padding: 0;
|
|
1395
|
+
border-radius: 0;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
input[type="checkbox"],
|
|
1399
|
+
input[type="radio"] {
|
|
1400
|
+
accent-color: CanvasText;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
input[type="search"] {
|
|
1404
|
+
appearance: none;
|
|
1405
|
+
background-color: Canvas;
|
|
1406
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1410
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1411
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1412
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1413
|
+
-webkit-appearance: none;
|
|
1414
|
+
display: none;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
input[type="number"] {
|
|
1418
|
+
appearance: textfield;
|
|
1419
|
+
background-color: Canvas;
|
|
1420
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1424
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1425
|
+
-webkit-appearance: none;
|
|
1426
|
+
margin: 0;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
textarea {
|
|
1430
|
+
resize: vertical;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
::placeholder {
|
|
1434
|
+
opacity: 1;
|
|
1435
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
:focus-visible {
|
|
1439
|
+
outline: 2px solid CanvasText;
|
|
1440
|
+
outline-offset: 2px;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
:focus:not(:focus-visible) {
|
|
1444
|
+
outline: none;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
:disabled,
|
|
1448
|
+
[disabled] {
|
|
1449
|
+
cursor: default;
|
|
1450
|
+
opacity: 0.6;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
label,
|
|
1454
|
+
summary,
|
|
1455
|
+
select,
|
|
1456
|
+
[role="button"] {
|
|
1457
|
+
cursor: pointer;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
summary {
|
|
1461
|
+
display: list-item;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
details {
|
|
1465
|
+
display: block;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
dialog {
|
|
1469
|
+
margin: auto;
|
|
1470
|
+
padding: 1rem;
|
|
1471
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1472
|
+
background: Canvas;
|
|
1473
|
+
color: CanvasText;
|
|
1474
|
+
max-width: calc(100vw - 2rem);
|
|
1475
|
+
max-height: calc(100svh - 2rem);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
dialog:not([open]) {
|
|
1479
|
+
display: none;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
::backdrop {
|
|
1483
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
[hidden] {
|
|
1487
|
+
display: none !important;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
::selection {
|
|
1491
|
+
background: Highlight;
|
|
1492
|
+
color: HighlightText;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1496
|
+
*,
|
|
1497
|
+
*::before,
|
|
1498
|
+
*::after {
|
|
1499
|
+
animation-duration: 0.01ms !important;
|
|
1500
|
+
animation-iteration-count: 1 !important;
|
|
1501
|
+
transition-duration: 0.01ms !important;
|
|
1502
|
+
scroll-behavior: auto !important;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
@media (pointer: coarse) {
|
|
1507
|
+
input,
|
|
1508
|
+
select,
|
|
1509
|
+
textarea {
|
|
1510
|
+
font-size: max(16px, 1em);
|
|
1511
|
+
}
|
|
1512
|
+
}`;
|
|
1513
|
+
|
|
1514
|
+
// ../core/dist/admin-client.js
|
|
1515
|
+
function isRecord2(value) {
|
|
1516
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1517
|
+
}
|
|
1518
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1519
|
+
const clip = (value, max) => {
|
|
1520
|
+
if (typeof value !== "string")
|
|
1521
|
+
return null;
|
|
1522
|
+
const trimmed = value.trim();
|
|
1523
|
+
if (trimmed === "")
|
|
1524
|
+
return null;
|
|
1525
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1526
|
+
};
|
|
1527
|
+
const httpUrl = (value) => {
|
|
1528
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1529
|
+
return null;
|
|
1530
|
+
try {
|
|
1531
|
+
const url = new URL(value);
|
|
1532
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1533
|
+
return null;
|
|
1534
|
+
return url.href;
|
|
1535
|
+
} catch {
|
|
1536
|
+
return null;
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
const hexColor = (value) => {
|
|
1540
|
+
if (typeof value !== "string")
|
|
1541
|
+
return null;
|
|
1542
|
+
const raw = value.trim();
|
|
1543
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1544
|
+
};
|
|
1545
|
+
const hostname = (value) => {
|
|
1546
|
+
try {
|
|
1547
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1548
|
+
} catch {
|
|
1549
|
+
return value;
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
host.replaceChildren();
|
|
1553
|
+
host.hidden = true;
|
|
1554
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1555
|
+
return;
|
|
1556
|
+
const row = catalog[service];
|
|
1557
|
+
if (!isRecord2(row))
|
|
1558
|
+
return;
|
|
1559
|
+
const vendor = clip(row.vendor, 80);
|
|
1560
|
+
const website = httpUrl(row.website);
|
|
1561
|
+
const guide = httpUrl(row.guide);
|
|
1562
|
+
const docs = httpUrl(row.docs);
|
|
1563
|
+
const logo = httpUrl(row.logo);
|
|
1564
|
+
const color = hexColor(row.color);
|
|
1565
|
+
const description = clip(row.description, 280);
|
|
1566
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1567
|
+
return;
|
|
1568
|
+
const add = (node) => {
|
|
1569
|
+
host.append(node);
|
|
1570
|
+
return node;
|
|
1571
|
+
};
|
|
1572
|
+
if (logo !== null) {
|
|
1573
|
+
const img = doc.createElement("img");
|
|
1574
|
+
img.alt = "";
|
|
1575
|
+
img.src = logo;
|
|
1576
|
+
img.width = 16;
|
|
1577
|
+
img.height = 16;
|
|
1578
|
+
img.decoding = "async";
|
|
1579
|
+
img.referrerPolicy = "no-referrer";
|
|
1580
|
+
if (color !== null)
|
|
1581
|
+
img.style.borderColor = color;
|
|
1582
|
+
add(img);
|
|
1583
|
+
}
|
|
1584
|
+
const name = doc.createElement("span");
|
|
1585
|
+
name.className = "vendor-name";
|
|
1586
|
+
name.textContent = vendor;
|
|
1587
|
+
if (description !== null)
|
|
1588
|
+
name.title = description;
|
|
1589
|
+
add(name);
|
|
1590
|
+
const sep = () => {
|
|
1591
|
+
const node = doc.createElement("span");
|
|
1592
|
+
node.className = "vendor-sep";
|
|
1593
|
+
node.setAttribute("aria-hidden", "true");
|
|
1594
|
+
node.textContent = "\xB7";
|
|
1595
|
+
return node;
|
|
1596
|
+
};
|
|
1597
|
+
const link = (href, label, title) => {
|
|
1598
|
+
const node = doc.createElement("a");
|
|
1599
|
+
node.className = "vendor-link";
|
|
1600
|
+
node.href = href;
|
|
1601
|
+
node.target = "_blank";
|
|
1602
|
+
node.rel = "noopener noreferrer";
|
|
1603
|
+
node.referrerPolicy = "no-referrer";
|
|
1604
|
+
node.textContent = label;
|
|
1605
|
+
node.title = title;
|
|
1606
|
+
return node;
|
|
1607
|
+
};
|
|
1608
|
+
if (website !== null) {
|
|
1609
|
+
add(sep());
|
|
1610
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1611
|
+
}
|
|
1612
|
+
if (guide !== null) {
|
|
1613
|
+
add(sep());
|
|
1614
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1615
|
+
}
|
|
1616
|
+
if (docs !== null) {
|
|
1617
|
+
add(sep());
|
|
1618
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1619
|
+
}
|
|
1620
|
+
host.removeAttribute("hidden");
|
|
1621
|
+
host.hidden = false;
|
|
1622
|
+
}
|
|
1623
|
+
function startAdminBrand(env) {
|
|
1624
|
+
const requested = env.params.get("brands");
|
|
1625
|
+
let brandsUrl = env.brandsUrl;
|
|
1626
|
+
if (requested) {
|
|
1627
|
+
try {
|
|
1628
|
+
const url = new URL(requested, env.location.href);
|
|
1629
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1630
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1631
|
+
brandsUrl = url.href;
|
|
1632
|
+
} catch {
|
|
1633
|
+
brandsUrl = env.brandsUrl;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
const vendorHost = env.$("vendor");
|
|
1637
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1638
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1639
|
+
if (vendorHost === null)
|
|
1640
|
+
return;
|
|
1641
|
+
env.fetch(brandsUrl, {
|
|
1642
|
+
headers: { accept: "application/json" },
|
|
1643
|
+
signal: AbortSignal.timeout(5e3)
|
|
1644
|
+
}).then(async (response) => {
|
|
1645
|
+
if (!response.ok)
|
|
1646
|
+
return null;
|
|
1647
|
+
const catalog = await response.json();
|
|
1648
|
+
return catalog;
|
|
1649
|
+
}).then((catalog) => {
|
|
1650
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1651
|
+
}).catch(() => {
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
function faultPresetList(value) {
|
|
1655
|
+
if (!isRecord2(value))
|
|
1656
|
+
throw new Error("Fault presets response was not an object");
|
|
1657
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1658
|
+
return { presets: [] };
|
|
1659
|
+
}
|
|
1660
|
+
if (!Array.isArray(value.presets))
|
|
1661
|
+
throw new Error("Fault presets response was not a list");
|
|
1662
|
+
return {
|
|
1663
|
+
presets: value.presets.flatMap((item) => {
|
|
1664
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1665
|
+
return [];
|
|
1666
|
+
return [{ name: item.name }];
|
|
1667
|
+
})
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
function bootAdmin(config) {
|
|
1671
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1672
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1673
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1674
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1675
|
+
const readJson2 = (text) => {
|
|
1676
|
+
const value = JSON.parse(text);
|
|
1677
|
+
return value;
|
|
1678
|
+
};
|
|
1679
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1680
|
+
switch (char) {
|
|
1681
|
+
case "&":
|
|
1682
|
+
return "&";
|
|
1683
|
+
case "<":
|
|
1684
|
+
return "<";
|
|
1685
|
+
case ">":
|
|
1686
|
+
return ">";
|
|
1687
|
+
case '"':
|
|
1688
|
+
return """;
|
|
1689
|
+
default:
|
|
1690
|
+
return "'";
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
const el = (id, kind) => {
|
|
1694
|
+
const node = document.getElementById(id);
|
|
1695
|
+
if (!(node instanceof kind))
|
|
1696
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1697
|
+
return node;
|
|
1698
|
+
};
|
|
1699
|
+
const errorMessage = (data, fallback) => {
|
|
1700
|
+
if (!isRecord2(data))
|
|
1701
|
+
return fallback;
|
|
1702
|
+
const error2 = data.error;
|
|
1703
|
+
if (!isRecord2(error2) || typeof error2.message !== "string" || error2.message === "") {
|
|
1704
|
+
return fallback;
|
|
1705
|
+
}
|
|
1706
|
+
return error2.message;
|
|
1707
|
+
};
|
|
1708
|
+
const requireList = (value, label) => {
|
|
1709
|
+
if (value === void 0 || value === null)
|
|
1710
|
+
return [];
|
|
1711
|
+
if (!Array.isArray(value))
|
|
1712
|
+
throw new Error(`${label} was not a list`);
|
|
1713
|
+
return value;
|
|
1714
|
+
};
|
|
1715
|
+
const state = {
|
|
1716
|
+
namespace: "default",
|
|
1717
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1718
|
+
view: "overview",
|
|
1719
|
+
collection: "",
|
|
1720
|
+
shape: null,
|
|
1721
|
+
route: null,
|
|
1722
|
+
editing: null
|
|
1723
|
+
};
|
|
1724
|
+
const standard = new Set(config.standardRoutes);
|
|
1725
|
+
const banner = el("banner", HTMLElement);
|
|
1726
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1727
|
+
keyInput.value = state.key;
|
|
1728
|
+
const params = new URLSearchParams(location.search);
|
|
1729
|
+
const queryKey = params.get("key");
|
|
1730
|
+
if (queryKey) {
|
|
1731
|
+
state.key = queryKey;
|
|
1732
|
+
keyInput.value = state.key;
|
|
1733
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1734
|
+
params.delete("key");
|
|
1735
|
+
const next = params.toString();
|
|
1736
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1737
|
+
}
|
|
1738
|
+
const queryNamespace = params.get("namespace");
|
|
1739
|
+
if (queryNamespace)
|
|
1740
|
+
state.namespace = queryNamespace;
|
|
1741
|
+
const showError = (error2) => {
|
|
1742
|
+
banner.textContent = error2 instanceof Error ? error2.message : String(error2);
|
|
1743
|
+
banner.classList.add("show");
|
|
1744
|
+
};
|
|
1745
|
+
const clearError = () => {
|
|
1746
|
+
banner.classList.remove("show");
|
|
1747
|
+
};
|
|
1748
|
+
const api = async (method, path, body) => {
|
|
1749
|
+
const headers = { accept: "application/json" };
|
|
1750
|
+
if (state.key !== "")
|
|
1751
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1752
|
+
if (state.namespace !== "")
|
|
1753
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1754
|
+
if (body !== void 0)
|
|
1755
|
+
headers["content-type"] = "application/json";
|
|
1756
|
+
const init = { method, headers };
|
|
1757
|
+
if (body !== void 0)
|
|
1758
|
+
init.body = JSON.stringify(body);
|
|
1759
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1760
|
+
const text = await response.text();
|
|
1761
|
+
let data = null;
|
|
1762
|
+
if (text !== "") {
|
|
1763
|
+
try {
|
|
1764
|
+
data = readJson2(text);
|
|
1765
|
+
} catch {
|
|
1766
|
+
data = { raw: text };
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
if (response.status === 401) {
|
|
1770
|
+
keyInput.focus();
|
|
1771
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1772
|
+
}
|
|
1773
|
+
if (!response.ok) {
|
|
1774
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1775
|
+
}
|
|
1776
|
+
return data;
|
|
1777
|
+
};
|
|
1778
|
+
const originGet = async (path) => {
|
|
1779
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1780
|
+
if (!response.ok)
|
|
1781
|
+
throw new Error(`${response.status} ${path}`);
|
|
1782
|
+
const value = await response.json();
|
|
1783
|
+
return value;
|
|
1784
|
+
};
|
|
1785
|
+
const panelApi = {
|
|
1786
|
+
get: (path) => api("GET", path),
|
|
1787
|
+
send: (method, path, body) => api(method, path, body),
|
|
1788
|
+
namespace: () => state.namespace
|
|
1789
|
+
};
|
|
1790
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1791
|
+
const setTheme = (theme) => {
|
|
1792
|
+
if (theme)
|
|
1793
|
+
document.documentElement.dataset.theme = theme;
|
|
1794
|
+
else
|
|
1795
|
+
delete document.documentElement.dataset.theme;
|
|
1796
|
+
};
|
|
1797
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1798
|
+
if (storedTheme)
|
|
1799
|
+
setTheme(storedTheme);
|
|
1800
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1801
|
+
const current = document.documentElement.dataset.theme;
|
|
1802
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1803
|
+
const next = dark ? "light" : "dark";
|
|
1804
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
1805
|
+
setTheme(next);
|
|
1806
|
+
});
|
|
1807
|
+
const show = (view) => {
|
|
1808
|
+
state.view = view;
|
|
1809
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
1810
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1811
|
+
continue;
|
|
1812
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
1813
|
+
}
|
|
1814
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
1815
|
+
if (!(section instanceof HTMLElement))
|
|
1816
|
+
continue;
|
|
1817
|
+
section.hidden = section.id !== `view-${view}`;
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
1821
|
+
const target = event.target;
|
|
1822
|
+
if (!(target instanceof Element))
|
|
1823
|
+
return;
|
|
1824
|
+
const button = target.closest("button[data-view]");
|
|
1825
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1826
|
+
return;
|
|
1827
|
+
const view = button.dataset.view;
|
|
1828
|
+
if (view === void 0)
|
|
1829
|
+
return;
|
|
1830
|
+
show(view);
|
|
1831
|
+
refresh().catch(showError);
|
|
1832
|
+
});
|
|
1833
|
+
const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
|
|
1834
|
+
const table = (columns, rows) => {
|
|
1835
|
+
if (rows.length === 0)
|
|
1836
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
1837
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
1838
|
+
const body = rows.map((row) => {
|
|
1839
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
1840
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
1841
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
1842
|
+
}).join("");
|
|
1843
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
1844
|
+
};
|
|
1845
|
+
const preview = (value) => {
|
|
1846
|
+
const text = JSON.stringify(value) ?? "null";
|
|
1847
|
+
return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
|
|
1848
|
+
};
|
|
1849
|
+
const when = (epoch) => {
|
|
1850
|
+
const date = new Date(epoch);
|
|
1851
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
1852
|
+
};
|
|
1853
|
+
const clockCard = (epoch) => {
|
|
1854
|
+
const date = new Date(epoch);
|
|
1855
|
+
if (Number.isNaN(date.getTime()))
|
|
1856
|
+
return esc(String(epoch));
|
|
1857
|
+
const iso = date.toISOString();
|
|
1858
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
1859
|
+
};
|
|
1860
|
+
const decodeClock = (value) => {
|
|
1861
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
1862
|
+
throw new Error("Clock response was not a clock");
|
|
1863
|
+
}
|
|
1864
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
1865
|
+
};
|
|
1866
|
+
const decodeField = (value) => {
|
|
1867
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
1868
|
+
return void 0;
|
|
1869
|
+
}
|
|
1870
|
+
const field = {
|
|
1871
|
+
name: value.name,
|
|
1872
|
+
kind: value.kind,
|
|
1873
|
+
optional: value.optional === true
|
|
1874
|
+
};
|
|
1875
|
+
if (typeof value.description === "string")
|
|
1876
|
+
field.description = value.description;
|
|
1877
|
+
if (Array.isArray(value.fields)) {
|
|
1878
|
+
field.fields = value.fields.flatMap((item) => {
|
|
1879
|
+
const child = decodeField(item);
|
|
1880
|
+
return child === void 0 ? [] : [child];
|
|
1881
|
+
});
|
|
1882
|
+
}
|
|
1883
|
+
return field;
|
|
1884
|
+
};
|
|
1885
|
+
const decodeCollection = (value) => {
|
|
1886
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
1887
|
+
return void 0;
|
|
1888
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
1889
|
+
const field = decodeField(item);
|
|
1890
|
+
return field === void 0 ? [] : [field];
|
|
1891
|
+
}) : [];
|
|
1892
|
+
const collection = {
|
|
1893
|
+
name: value.name,
|
|
1894
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
1895
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
1896
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
1897
|
+
fields
|
|
1898
|
+
};
|
|
1899
|
+
if (typeof value.description === "string")
|
|
1900
|
+
collection.description = value.description;
|
|
1901
|
+
return collection;
|
|
1902
|
+
};
|
|
1903
|
+
const decodeState = (value) => {
|
|
1904
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
1905
|
+
throw new Error("State response has no collection list");
|
|
1906
|
+
}
|
|
1907
|
+
return {
|
|
1908
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
1909
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
1910
|
+
collections: value.collections.flatMap((item) => {
|
|
1911
|
+
const collection = decodeCollection(item);
|
|
1912
|
+
return collection === void 0 ? [] : [collection];
|
|
1913
|
+
})
|
|
1914
|
+
};
|
|
1915
|
+
};
|
|
1916
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
1917
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
1918
|
+
return [];
|
|
1919
|
+
return [
|
|
1920
|
+
{
|
|
1921
|
+
id: item.id,
|
|
1922
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
1923
|
+
value: item.value,
|
|
1924
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
1925
|
+
}
|
|
1926
|
+
];
|
|
1927
|
+
});
|
|
1928
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
1929
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
1930
|
+
if (!isRecord2(item))
|
|
1931
|
+
return [];
|
|
1932
|
+
return [
|
|
1933
|
+
{
|
|
1934
|
+
at: textOf(item.at),
|
|
1935
|
+
method: textOf(item.method),
|
|
1936
|
+
path: textOf(item.path),
|
|
1937
|
+
status: textOf(item.status),
|
|
1938
|
+
durationMs: textOf(item.durationMs),
|
|
1939
|
+
operationId: textOf(item.operationId)
|
|
1940
|
+
}
|
|
1941
|
+
];
|
|
1942
|
+
});
|
|
1943
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
1944
|
+
if (!isRecord2(item))
|
|
1945
|
+
return [];
|
|
1946
|
+
return [
|
|
1947
|
+
{
|
|
1948
|
+
id: textOf(item.id),
|
|
1949
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
1950
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
1951
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
1952
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
1953
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
1954
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
1955
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
1956
|
+
}
|
|
1957
|
+
];
|
|
1958
|
+
});
|
|
1959
|
+
const loadNamespaces = async () => {
|
|
1960
|
+
const data = await api("GET", "/namespaces");
|
|
1961
|
+
const select = el("namespace", HTMLSelectElement);
|
|
1962
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
1963
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
1964
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
1965
|
+
if (!names.includes(state.namespace))
|
|
1966
|
+
names.unshift(state.namespace);
|
|
1967
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
1968
|
+
select.value = state.namespace;
|
|
1969
|
+
};
|
|
1970
|
+
const renderOverview = async () => {
|
|
1971
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
1972
|
+
originGet("/health"),
|
|
1973
|
+
api("GET", "/state"),
|
|
1974
|
+
api("GET", "/clock"),
|
|
1975
|
+
api("GET", "/requests?limit=8")
|
|
1976
|
+
]);
|
|
1977
|
+
if (!isRecord2(health))
|
|
1978
|
+
throw new Error("Health response was not an object");
|
|
1979
|
+
const decoded = decodeState(shape);
|
|
1980
|
+
state.shape = decoded;
|
|
1981
|
+
const time = decodeClock(clock);
|
|
1982
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
1983
|
+
{
|
|
1984
|
+
k: "Service",
|
|
1985
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
k: "Status",
|
|
1989
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
1990
|
+
},
|
|
1991
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
1992
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
1993
|
+
{
|
|
1994
|
+
k: "Records",
|
|
1995
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
1996
|
+
},
|
|
1997
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
1998
|
+
]);
|
|
1999
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
2000
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2001
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2002
|
+
{
|
|
2003
|
+
label: "Status",
|
|
2004
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
2005
|
+
},
|
|
2006
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
2007
|
+
], decodeJournal(journal));
|
|
2008
|
+
};
|
|
2009
|
+
const schemaChips = (collection) => {
|
|
2010
|
+
if (collection.fields.length === 0) {
|
|
2011
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
2012
|
+
}
|
|
2013
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
2014
|
+
};
|
|
2015
|
+
const renderState = async () => {
|
|
2016
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
2017
|
+
state.shape = shape;
|
|
2018
|
+
const host = el("collections", HTMLElement);
|
|
2019
|
+
if (shape.collections.length === 0) {
|
|
2020
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
2021
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
2022
|
+
el("records", HTMLElement).innerHTML = "";
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
2026
|
+
const first = shape.collections[0];
|
|
2027
|
+
if (first === void 0)
|
|
2028
|
+
return;
|
|
2029
|
+
state.collection = first.name;
|
|
2030
|
+
}
|
|
2031
|
+
host.innerHTML = shape.collections.map((item) => `<button type="button" class="collection" data-collection="${esc(item.name)}" aria-current="${item.name === state.collection ? "true" : "false"}"><strong>${esc(item.label)}</strong><small>${esc(item.count)} \xB7 ${esc(item.source)}</small></button>`).join("");
|
|
2032
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
2033
|
+
if (selected === void 0)
|
|
2034
|
+
return;
|
|
2035
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
2036
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
2037
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
2038
|
+
el("records", HTMLElement).innerHTML = table([
|
|
2039
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
2040
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
2041
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
2042
|
+
], decodeRecords(page));
|
|
2043
|
+
};
|
|
2044
|
+
const renderClock = async () => {
|
|
2045
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2046
|
+
el("clock-readout", HTMLElement).innerHTML = `<div class="k">Now</div><div class="v">${esc(when(clock.now))}</div><p>${esc(clock.now)} ms \xB7 offset ${esc(clock.offsetMs)} ms ${clock.frozen ? "<span class='badge warn'>frozen</span>" : "<span class='badge ok'>live</span>"}</p>`;
|
|
2047
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2048
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2049
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2050
|
+
};
|
|
2051
|
+
const renderFaults = async () => {
|
|
2052
|
+
const [faults, presets] = await Promise.all([
|
|
2053
|
+
api("GET", "/faults"),
|
|
2054
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2055
|
+
]);
|
|
2056
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2057
|
+
const current = select.value;
|
|
2058
|
+
const list = faultPresetList(presets).presets;
|
|
2059
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2060
|
+
select.value = current;
|
|
2061
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2062
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2063
|
+
{
|
|
2064
|
+
label: "Match",
|
|
2065
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2066
|
+
},
|
|
2067
|
+
{
|
|
2068
|
+
label: "Effect",
|
|
2069
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
2070
|
+
}
|
|
2071
|
+
], decodeFaults(faults));
|
|
2072
|
+
};
|
|
2073
|
+
const renderJournal = async () => {
|
|
2074
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2075
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2076
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
2077
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2078
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2079
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2080
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2081
|
+
], decodeJournal(journal));
|
|
2082
|
+
};
|
|
2083
|
+
const renderRoutes = async () => {
|
|
2084
|
+
const data = await api("GET", "/");
|
|
2085
|
+
if (!isRecord2(data))
|
|
2086
|
+
throw new Error("Route list was not an object");
|
|
2087
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2088
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2089
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2090
|
+
const parts = route.split(" ");
|
|
2091
|
+
const method = parts[0] ?? "";
|
|
2092
|
+
const path = parts.slice(1).join(" ");
|
|
2093
|
+
return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}">Use</button></div>`;
|
|
2094
|
+
}).join("");
|
|
2095
|
+
};
|
|
2096
|
+
const renderers = {
|
|
2097
|
+
overview: renderOverview,
|
|
2098
|
+
state: renderState,
|
|
2099
|
+
clock: renderClock,
|
|
2100
|
+
faults: renderFaults,
|
|
2101
|
+
journal: renderJournal,
|
|
2102
|
+
routes: renderRoutes
|
|
2103
|
+
};
|
|
2104
|
+
async function refresh() {
|
|
2105
|
+
clearError();
|
|
2106
|
+
const render = renderers[state.view];
|
|
2107
|
+
if (render)
|
|
2108
|
+
await render();
|
|
2109
|
+
}
|
|
2110
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2111
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2112
|
+
refresh().catch(showError);
|
|
2113
|
+
});
|
|
2114
|
+
keyInput.addEventListener("change", () => {
|
|
2115
|
+
state.key = keyInput.value.trim();
|
|
2116
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2117
|
+
refresh().catch(showError);
|
|
2118
|
+
});
|
|
2119
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2120
|
+
refresh().catch(showError);
|
|
2121
|
+
});
|
|
2122
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2123
|
+
const target = event.target;
|
|
2124
|
+
if (!(target instanceof Element))
|
|
2125
|
+
return;
|
|
2126
|
+
const button = target.closest("[data-collection]");
|
|
2127
|
+
if (!(button instanceof HTMLElement))
|
|
2128
|
+
return;
|
|
2129
|
+
const collection = button.dataset.collection;
|
|
2130
|
+
if (collection === void 0)
|
|
2131
|
+
return;
|
|
2132
|
+
state.collection = collection;
|
|
2133
|
+
renderState().catch(showError);
|
|
2134
|
+
});
|
|
2135
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2136
|
+
const target = event.target;
|
|
2137
|
+
if (!(target instanceof Element))
|
|
2138
|
+
return;
|
|
2139
|
+
const row = target.closest("[data-id]");
|
|
2140
|
+
if (!(row instanceof HTMLElement))
|
|
2141
|
+
return;
|
|
2142
|
+
const id = row.dataset.id;
|
|
2143
|
+
if (id === void 0)
|
|
2144
|
+
return;
|
|
2145
|
+
openEditor(id).catch(showError);
|
|
2146
|
+
});
|
|
2147
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2148
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2149
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2150
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2151
|
+
async function openEditor(id) {
|
|
2152
|
+
state.editing = id;
|
|
2153
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2154
|
+
editorId.value = id ?? "";
|
|
2155
|
+
editorId.readOnly = id !== null;
|
|
2156
|
+
editorDelete.hidden = id === null;
|
|
2157
|
+
if (id) {
|
|
2158
|
+
const record = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2159
|
+
if (!isRecord2(record))
|
|
2160
|
+
throw new Error("Record response was not an object");
|
|
2161
|
+
editorValue.value = JSON.stringify(record.value, null, 2) ?? "";
|
|
2162
|
+
} else {
|
|
2163
|
+
editorValue.value = "{\n \n}";
|
|
2164
|
+
}
|
|
2165
|
+
editor.showModal();
|
|
2166
|
+
}
|
|
2167
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2168
|
+
openEditor(null).catch(showError);
|
|
2169
|
+
});
|
|
2170
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2171
|
+
const submitter = event.submitter;
|
|
2172
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2173
|
+
return;
|
|
2174
|
+
event.preventDefault();
|
|
2175
|
+
let value;
|
|
2176
|
+
try {
|
|
2177
|
+
value = readJson2(editorValue.value);
|
|
2178
|
+
} catch {
|
|
2179
|
+
showError(new Error("Value is not JSON"));
|
|
2180
|
+
return;
|
|
2181
|
+
}
|
|
2182
|
+
const id = editorId.value.trim();
|
|
2183
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2184
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2185
|
+
request.then(() => {
|
|
2186
|
+
editor.close();
|
|
2187
|
+
return renderState();
|
|
2188
|
+
}).catch(showError);
|
|
2189
|
+
});
|
|
2190
|
+
editorDelete.addEventListener("click", () => {
|
|
2191
|
+
const id = state.editing;
|
|
2192
|
+
if (!id)
|
|
2193
|
+
return;
|
|
2194
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2195
|
+
editor.close();
|
|
2196
|
+
return renderState();
|
|
2197
|
+
}).catch(showError);
|
|
2198
|
+
});
|
|
2199
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2200
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2201
|
+
continue;
|
|
2202
|
+
button.addEventListener("click", () => {
|
|
2203
|
+
const raw = button.dataset.advance;
|
|
2204
|
+
if (raw === void 0)
|
|
2205
|
+
return;
|
|
2206
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2210
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2211
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2212
|
+
});
|
|
2213
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2214
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2215
|
+
});
|
|
2216
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2217
|
+
event.preventDefault();
|
|
2218
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2219
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2220
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2221
|
+
});
|
|
2222
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2223
|
+
event.preventDefault();
|
|
2224
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2225
|
+
if (preset !== "") {
|
|
2226
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2227
|
+
return;
|
|
2228
|
+
}
|
|
2229
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2230
|
+
if (!Number.isFinite(status)) {
|
|
2231
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
2234
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2235
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2236
|
+
api("POST", "/faults", {
|
|
2237
|
+
status,
|
|
2238
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2239
|
+
...method !== "" ? { method } : {}
|
|
2240
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2241
|
+
});
|
|
2242
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2243
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2244
|
+
});
|
|
2245
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2246
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2247
|
+
});
|
|
2248
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2249
|
+
const target = event.target;
|
|
2250
|
+
if (!(target instanceof Element))
|
|
2251
|
+
return;
|
|
2252
|
+
const button = target.closest("[data-route]");
|
|
2253
|
+
if (!(button instanceof HTMLElement))
|
|
2254
|
+
return;
|
|
2255
|
+
const route = button.dataset.route;
|
|
2256
|
+
if (route === void 0)
|
|
2257
|
+
return;
|
|
2258
|
+
state.route = route;
|
|
2259
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2260
|
+
const method = route.split(" ")[0] ?? "";
|
|
2261
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2262
|
+
});
|
|
2263
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2264
|
+
event.preventDefault();
|
|
2265
|
+
const send = async () => {
|
|
2266
|
+
if (state.route === null)
|
|
2267
|
+
throw new Error("Choose a route first");
|
|
2268
|
+
const parts = state.route.split(" ");
|
|
2269
|
+
const method = parts[0];
|
|
2270
|
+
const path = parts.slice(1).join(" ");
|
|
2271
|
+
if (method === void 0)
|
|
2272
|
+
throw new Error("Choose a route first");
|
|
2273
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2274
|
+
let body;
|
|
2275
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2276
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2277
|
+
try {
|
|
2278
|
+
body = readJson2(routeBody.value);
|
|
2279
|
+
} catch {
|
|
2280
|
+
throw new Error("Body is not JSON");
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
const data = await api(method, concrete, body);
|
|
2284
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2285
|
+
};
|
|
2286
|
+
send().catch(showError);
|
|
2287
|
+
});
|
|
2288
|
+
const decodePanel = (value) => {
|
|
2289
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2290
|
+
return void 0;
|
|
2291
|
+
}
|
|
2292
|
+
const panel = {
|
|
2293
|
+
id: value.id,
|
|
2294
|
+
title: value.title,
|
|
2295
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2296
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2297
|
+
};
|
|
2298
|
+
if (typeof value.script === "string")
|
|
2299
|
+
panel.script = value.script;
|
|
2300
|
+
return panel;
|
|
2301
|
+
};
|
|
2302
|
+
const mountPanels = (panels) => {
|
|
2303
|
+
const nav = el("nav", HTMLElement);
|
|
2304
|
+
const views = el("views", HTMLElement);
|
|
2305
|
+
for (const panel of panels) {
|
|
2306
|
+
const button = document.createElement("button");
|
|
2307
|
+
button.type = "button";
|
|
2308
|
+
button.dataset.view = panel.id;
|
|
2309
|
+
button.textContent = panel.title;
|
|
2310
|
+
nav.append(button);
|
|
2311
|
+
const section = document.createElement("section");
|
|
2312
|
+
section.className = "view";
|
|
2313
|
+
section.id = `view-${panel.id}`;
|
|
2314
|
+
section.hidden = true;
|
|
2315
|
+
const title = document.createElement("h2");
|
|
2316
|
+
title.textContent = panel.title;
|
|
2317
|
+
const lede = document.createElement("p");
|
|
2318
|
+
lede.className = "lede";
|
|
2319
|
+
lede.textContent = panel.description;
|
|
2320
|
+
const body = document.createElement("div");
|
|
2321
|
+
body.className = "panel-body";
|
|
2322
|
+
body.id = `panel-${panel.id}`;
|
|
2323
|
+
body.innerHTML = panel.html;
|
|
2324
|
+
section.append(title, lede, body);
|
|
2325
|
+
views.append(section);
|
|
2326
|
+
if (panel.script === void 0)
|
|
2327
|
+
continue;
|
|
2328
|
+
try {
|
|
2329
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2330
|
+
if (!isPanelScript(compiled))
|
|
2331
|
+
throw new Error("panel script did not compile");
|
|
2332
|
+
compiled(body, panelApi);
|
|
2333
|
+
} catch (error2) {
|
|
2334
|
+
const note = document.createElement("p");
|
|
2335
|
+
note.className = "banner show";
|
|
2336
|
+
note.textContent = error2 instanceof Error ? error2.message : String(error2);
|
|
2337
|
+
body.append(note);
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
};
|
|
2341
|
+
startAdminBrand({
|
|
2342
|
+
document,
|
|
2343
|
+
$: (id) => document.getElementById(id),
|
|
2344
|
+
params,
|
|
2345
|
+
location: { href: location.href, origin: location.origin },
|
|
2346
|
+
fetch,
|
|
2347
|
+
brandsUrl: config.brandsUrl
|
|
2348
|
+
});
|
|
2349
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2350
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2351
|
+
const decoded = decodePanel(panel);
|
|
2352
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2353
|
+
});
|
|
2354
|
+
mountPanels(panels);
|
|
2355
|
+
return refresh();
|
|
2356
|
+
}).catch(showError);
|
|
2357
|
+
}
|
|
2358
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2359
|
+
var adminClientSource = (config) => {
|
|
2360
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2361
|
+
return `<script>
|
|
2362
|
+
${clientPrelude}
|
|
2363
|
+
bootAdmin(${payload});
|
|
2364
|
+
</script>`;
|
|
2365
|
+
};
|
|
2366
|
+
|
|
2367
|
+
// ../core/dist/surface.js
|
|
2368
|
+
var defineMock = (runtime) => runtime;
|
|
2369
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2370
|
+
"GET /",
|
|
2371
|
+
"POST /reset",
|
|
2372
|
+
"GET /namespaces",
|
|
2373
|
+
"GET /clock",
|
|
2374
|
+
"POST /clock",
|
|
2375
|
+
"GET /faults",
|
|
2376
|
+
"POST /faults",
|
|
2377
|
+
"DELETE /faults",
|
|
2378
|
+
"POST /snapshots",
|
|
2379
|
+
"POST /snapshots/:id/restore",
|
|
2380
|
+
"DELETE /snapshots/:id",
|
|
2381
|
+
"GET /timeline",
|
|
2382
|
+
"POST /checkpoints",
|
|
2383
|
+
"POST /branches/:name",
|
|
2384
|
+
"POST /branches/:name/checkout",
|
|
2385
|
+
"GET /requests",
|
|
2386
|
+
"DELETE /requests",
|
|
2387
|
+
"GET /metrics",
|
|
2388
|
+
"DELETE /metrics",
|
|
2389
|
+
"GET /credentials",
|
|
2390
|
+
"PUT /credentials",
|
|
2391
|
+
"DELETE /credentials",
|
|
2392
|
+
"GET /state",
|
|
2393
|
+
"GET /state/:collection",
|
|
2394
|
+
"GET /state/:collection/:id",
|
|
2395
|
+
"POST /state/:collection",
|
|
2396
|
+
"PUT /state/:collection/:id",
|
|
2397
|
+
"PATCH /state/:collection/:id",
|
|
2398
|
+
"DELETE /state/:collection/:id",
|
|
2399
|
+
"GET /ui",
|
|
2400
|
+
"GET /ui/",
|
|
2401
|
+
"GET /ui/manifest"
|
|
2402
|
+
];
|
|
2403
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2404
|
+
var assertAdminUi = (ui) => {
|
|
2405
|
+
if (!ui?.panels)
|
|
2406
|
+
return;
|
|
2407
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2408
|
+
for (const panel of ui.panels) {
|
|
2409
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2410
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2411
|
+
}
|
|
2412
|
+
if (seen.has(panel.id))
|
|
2413
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2414
|
+
seen.add(panel.id);
|
|
2415
|
+
if (panel.title.trim() === "")
|
|
2416
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2417
|
+
}
|
|
2418
|
+
};
|
|
2419
|
+
|
|
2420
|
+
// ../core/dist/admin-ui.js
|
|
2421
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2422
|
+
switch (char) {
|
|
2423
|
+
case "&":
|
|
2424
|
+
return "&";
|
|
2425
|
+
case "<":
|
|
2426
|
+
return "<";
|
|
2427
|
+
case ">":
|
|
2428
|
+
return ">";
|
|
2429
|
+
case '"':
|
|
2430
|
+
return """;
|
|
2431
|
+
default:
|
|
2432
|
+
return "'";
|
|
2433
|
+
}
|
|
2434
|
+
});
|
|
2435
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2436
|
+
var renderAdminDocument = (service) => {
|
|
2437
|
+
const name = escapeHtml(service);
|
|
2438
|
+
const script = adminClientSource({
|
|
2439
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2440
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2441
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2442
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2443
|
+
service
|
|
2444
|
+
});
|
|
2445
|
+
return `<!DOCTYPE html>
|
|
2446
|
+
<html lang="en">
|
|
2447
|
+
<head>
|
|
2448
|
+
<meta charset="utf-8">
|
|
2449
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2450
|
+
<meta name="color-scheme" content="light dark">
|
|
2451
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='2' fill='%2327272a'/%3E%3C/svg%3E">
|
|
2452
|
+
<title>${name} admin</title>
|
|
2453
|
+
<style>
|
|
2454
|
+
${CSS_RESET}
|
|
2455
|
+
:root {
|
|
2456
|
+
color-scheme: light;
|
|
2457
|
+
--bg: #fafafa;
|
|
2458
|
+
--bg-elev: #ffffff;
|
|
2459
|
+
--bg-muted: #f4f4f5;
|
|
2460
|
+
--bg-inset: #f4f4f5;
|
|
2461
|
+
--line: #dedee3;
|
|
2462
|
+
--line-strong: #c4c4cc;
|
|
2463
|
+
--ink: #18181b;
|
|
2464
|
+
--muted: #62626b;
|
|
2465
|
+
--faint: #71717a;
|
|
2466
|
+
--accent: #27272a;
|
|
2467
|
+
--accent-ink: #ffffff;
|
|
2468
|
+
--accent-soft: #f4f4f5;
|
|
2469
|
+
--ok: #166534;
|
|
2470
|
+
--ok-soft: #f0fdf4;
|
|
2471
|
+
--warn: #a16207;
|
|
2472
|
+
--warn-soft: #fefce8;
|
|
2473
|
+
--err: #a82d32;
|
|
2474
|
+
--err-soft: #fef2f2;
|
|
2475
|
+
--shadow: none;
|
|
2476
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2477
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2478
|
+
--radius: 10px;
|
|
2479
|
+
--header: 56px;
|
|
2480
|
+
--nav: 200px;
|
|
2481
|
+
}
|
|
2482
|
+
:root[data-theme="dark"] {
|
|
2483
|
+
color-scheme: dark;
|
|
2484
|
+
--bg: #111113;
|
|
2485
|
+
--bg-elev: #19191c;
|
|
2486
|
+
--bg-muted: #242428;
|
|
2487
|
+
--bg-inset: #111113;
|
|
2488
|
+
--line: #36363c;
|
|
2489
|
+
--line-strong: #52525b;
|
|
2490
|
+
--ink: #f4f4f5;
|
|
2491
|
+
--muted: #a9a9b2;
|
|
2492
|
+
--faint: #71717a;
|
|
2493
|
+
--accent: #e4e4e7;
|
|
2494
|
+
--accent-ink: #18181b;
|
|
2495
|
+
--accent-soft: #242428;
|
|
2496
|
+
--ok: #86efac;
|
|
2497
|
+
--ok-soft: #14241b;
|
|
2498
|
+
--warn: #fde68a;
|
|
2499
|
+
--warn-soft: #2a2410;
|
|
2500
|
+
--err: #ffaaaa;
|
|
2501
|
+
--err-soft: #2c1516;
|
|
2502
|
+
--shadow: none;
|
|
2503
|
+
}
|
|
2504
|
+
@media (prefers-color-scheme: dark) {
|
|
2505
|
+
:root:not([data-theme="light"]) {
|
|
2506
|
+
color-scheme: dark;
|
|
2507
|
+
--bg: #111113;
|
|
2508
|
+
--bg-elev: #19191c;
|
|
2509
|
+
--bg-muted: #242428;
|
|
2510
|
+
--bg-inset: #111113;
|
|
2511
|
+
--line: #36363c;
|
|
2512
|
+
--line-strong: #52525b;
|
|
2513
|
+
--ink: #f4f4f5;
|
|
2514
|
+
--muted: #a9a9b2;
|
|
2515
|
+
--faint: #71717a;
|
|
2516
|
+
--accent: #e4e4e7;
|
|
2517
|
+
--accent-ink: #18181b;
|
|
2518
|
+
--accent-soft: #242428;
|
|
2519
|
+
--ok: #86efac;
|
|
2520
|
+
--ok-soft: #14241b;
|
|
2521
|
+
--warn: #fde68a;
|
|
2522
|
+
--warn-soft: #2a2410;
|
|
2523
|
+
--err: #ffaaaa;
|
|
2524
|
+
--err-soft: #2c1516;
|
|
2525
|
+
--shadow: none;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2529
|
+
html { height: 100%; }
|
|
2530
|
+
body {
|
|
2531
|
+
margin: 0;
|
|
2532
|
+
min-height: 100%;
|
|
2533
|
+
display: flex;
|
|
2534
|
+
flex-direction: column;
|
|
2535
|
+
font-family: var(--sans);
|
|
2536
|
+
background: var(--bg);
|
|
2537
|
+
color: var(--ink);
|
|
2538
|
+
line-height: 1.45;
|
|
2539
|
+
padding-left: env(safe-area-inset-left);
|
|
2540
|
+
padding-right: env(safe-area-inset-right);
|
|
2541
|
+
-webkit-text-size-adjust: 100%;
|
|
2542
|
+
}
|
|
2543
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2544
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2545
|
+
header.top {
|
|
2546
|
+
position: sticky; top: 0; z-index: 5;
|
|
2547
|
+
display: flex; align-items: center; gap: 12px;
|
|
2548
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2549
|
+
background: var(--bg-elev);
|
|
2550
|
+
border-bottom: 1px solid var(--line);
|
|
2551
|
+
min-width: 0; max-width: 100%;
|
|
2552
|
+
}
|
|
2553
|
+
.brand {
|
|
2554
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2555
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2556
|
+
}
|
|
2557
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2558
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2559
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2560
|
+
.vendor {
|
|
2561
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2562
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2563
|
+
}
|
|
2564
|
+
.vendor[hidden] { display: none; }
|
|
2565
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2566
|
+
.vendor img {
|
|
2567
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2568
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2569
|
+
}
|
|
2570
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2571
|
+
.vendor-sep { color: var(--faint); }
|
|
2572
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2573
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2574
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2575
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2576
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2577
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2578
|
+
padding: 7px 8px; min-height: 36px;
|
|
2579
|
+
}
|
|
2580
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2581
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2582
|
+
background: var(--bg-elev);
|
|
2583
|
+
}
|
|
2584
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2585
|
+
.btn-quiet { background: transparent; }
|
|
2586
|
+
.btn-danger { color: var(--err); }
|
|
2587
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2588
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2589
|
+
.layout {
|
|
2590
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2591
|
+
flex: 1 0 auto; min-width: 0;
|
|
2592
|
+
}
|
|
2593
|
+
nav.side {
|
|
2594
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2595
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2596
|
+
background: var(--bg-elev);
|
|
2597
|
+
}
|
|
2598
|
+
nav.side button {
|
|
2599
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2600
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2601
|
+
}
|
|
2602
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2603
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2604
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2605
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2606
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2607
|
+
.card {
|
|
2608
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2609
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2610
|
+
}
|
|
2611
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2612
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2613
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2614
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2615
|
+
.collection {
|
|
2616
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2617
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2618
|
+
}
|
|
2619
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2620
|
+
.collection small { display: block; color: var(--faint); }
|
|
2621
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2622
|
+
.chip {
|
|
2623
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2624
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2625
|
+
}
|
|
2626
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2627
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2628
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2629
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2630
|
+
tr.clickable { cursor: pointer; }
|
|
2631
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2632
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2633
|
+
pre {
|
|
2634
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2635
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2636
|
+
}
|
|
2637
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2638
|
+
.banner {
|
|
2639
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2640
|
+
background: var(--err-soft); color: var(--err);
|
|
2641
|
+
}
|
|
2642
|
+
.banner.show { display: block; }
|
|
2643
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2644
|
+
dialog {
|
|
2645
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2646
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2647
|
+
}
|
|
2648
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2649
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2650
|
+
textarea {
|
|
2651
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2652
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2653
|
+
font-family: var(--mono); font-size: 12px;
|
|
2654
|
+
}
|
|
2655
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2656
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2657
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2658
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2659
|
+
.status-2 { color: var(--ok); }
|
|
2660
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2661
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2662
|
+
.route {
|
|
2663
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2664
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2665
|
+
}
|
|
2666
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2667
|
+
@media (max-width: 800px) {
|
|
2668
|
+
header.top {
|
|
2669
|
+
align-items: stretch; flex-direction: column;
|
|
2670
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2671
|
+
}
|
|
2672
|
+
input, select, textarea { font-size: 16px; }
|
|
2673
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2674
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2675
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2676
|
+
nav.side {
|
|
2677
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2678
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2679
|
+
padding: 8px;
|
|
2680
|
+
}
|
|
2681
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2682
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2683
|
+
main { padding: 14px; }
|
|
2684
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2685
|
+
thead { display: none; }
|
|
2686
|
+
tr {
|
|
2687
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2688
|
+
background: var(--bg-elev); min-width: 0;
|
|
2689
|
+
}
|
|
2690
|
+
td {
|
|
2691
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2692
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2693
|
+
}
|
|
2694
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2695
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2696
|
+
.route button { grid-column: 1 / -1; }
|
|
2697
|
+
}
|
|
2698
|
+
</style>
|
|
2699
|
+
</head>
|
|
2700
|
+
<body>
|
|
2701
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2702
|
+
<header class="top">
|
|
2703
|
+
<div class="brand">
|
|
2704
|
+
<div class="brand-id">
|
|
2705
|
+
<strong>${name}</strong>
|
|
2706
|
+
<span>Admin</span>
|
|
2707
|
+
</div>
|
|
2708
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2709
|
+
</div>
|
|
2710
|
+
<div class="controls">
|
|
2711
|
+
<label class="field">Namespace
|
|
2712
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2713
|
+
</label>
|
|
2714
|
+
<label class="field">Admin key
|
|
2715
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2716
|
+
</label>
|
|
2717
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2718
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2719
|
+
</div>
|
|
2720
|
+
</header>
|
|
2721
|
+
<div class="layout">
|
|
2722
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2723
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2724
|
+
<button type="button" data-view="state">State</button>
|
|
2725
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2726
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2727
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2728
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2729
|
+
</nav>
|
|
2730
|
+
<main id="views">
|
|
2731
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2732
|
+
<section class="view" id="view-overview">
|
|
2733
|
+
<h2>Overview</h2>
|
|
2734
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2735
|
+
<div class="grid" id="overview-cards"></div>
|
|
2736
|
+
<h3>Recent requests</h3>
|
|
2737
|
+
<div id="overview-requests"></div>
|
|
2738
|
+
</section>
|
|
2739
|
+
<section class="view" id="view-state" hidden>
|
|
2740
|
+
<h2>State</h2>
|
|
2741
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2742
|
+
<div class="split">
|
|
2743
|
+
<div id="collections"></div>
|
|
2744
|
+
<div>
|
|
2745
|
+
<div id="schema"></div>
|
|
2746
|
+
<div class="row-actions">
|
|
2747
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2748
|
+
</div>
|
|
2749
|
+
<div id="records"></div>
|
|
2750
|
+
</div>
|
|
2751
|
+
</div>
|
|
2752
|
+
</section>
|
|
2753
|
+
<section class="view" id="view-clock" hidden>
|
|
2754
|
+
<h2>Clock</h2>
|
|
2755
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
2756
|
+
<div class="card" id="clock-readout"></div>
|
|
2757
|
+
<div class="row-actions">
|
|
2758
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
2759
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
2760
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
2761
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
2762
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
2763
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
2764
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
2765
|
+
</div>
|
|
2766
|
+
<form id="clock-set" class="row-actions">
|
|
2767
|
+
<label class="field">Set instant
|
|
2768
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
2769
|
+
</label>
|
|
2770
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
2771
|
+
</form>
|
|
2772
|
+
</section>
|
|
2773
|
+
<section class="view" id="view-faults" hidden>
|
|
2774
|
+
<h2>Faults</h2>
|
|
2775
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
2776
|
+
<form id="fault-form" class="card stack">
|
|
2777
|
+
<label class="field">Preset
|
|
2778
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
2779
|
+
</label>
|
|
2780
|
+
<label class="field">Status
|
|
2781
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
2782
|
+
</label>
|
|
2783
|
+
<label class="field">Path prefix
|
|
2784
|
+
<input id="fault-path" placeholder="/v1">
|
|
2785
|
+
</label>
|
|
2786
|
+
<label class="field">Method
|
|
2787
|
+
<input id="fault-method" placeholder="GET">
|
|
2788
|
+
</label>
|
|
2789
|
+
<div class="dialog-actions">
|
|
2790
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
2791
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
2792
|
+
</div>
|
|
2793
|
+
</form>
|
|
2794
|
+
<div id="fault-list"></div>
|
|
2795
|
+
</section>
|
|
2796
|
+
<section class="view" id="view-journal" hidden>
|
|
2797
|
+
<h2>Journal</h2>
|
|
2798
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
2799
|
+
<div class="row-actions">
|
|
2800
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
2801
|
+
</div>
|
|
2802
|
+
<div id="journal"></div>
|
|
2803
|
+
</section>
|
|
2804
|
+
<section class="view" id="view-routes" hidden>
|
|
2805
|
+
<h2>Routes</h2>
|
|
2806
|
+
<p class="lede">Shared controls, plus any routes this mock adds. Extra routes are how a bespoke workflow shows up beside the default UI.</p>
|
|
2807
|
+
<div id="route-list"></div>
|
|
2808
|
+
<form id="route-form" class="card stack">
|
|
2809
|
+
<strong id="route-title">Select a route</strong>
|
|
2810
|
+
<label class="field">JSON body
|
|
2811
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
2812
|
+
</label>
|
|
2813
|
+
<div class="dialog-actions">
|
|
2814
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
2815
|
+
</div>
|
|
2816
|
+
<pre id="route-result">Response will show here.</pre>
|
|
2817
|
+
</form>
|
|
2818
|
+
</section>
|
|
2819
|
+
</main>
|
|
2820
|
+
</div>
|
|
2821
|
+
</div>
|
|
2822
|
+
<dialog id="editor">
|
|
2823
|
+
<form method="dialog" id="editor-form">
|
|
2824
|
+
<strong id="editor-title">Record</strong>
|
|
2825
|
+
<label class="field">Id
|
|
2826
|
+
<input id="editor-id" required>
|
|
2827
|
+
</label>
|
|
2828
|
+
<label class="field">JSON value
|
|
2829
|
+
<textarea id="editor-value"></textarea>
|
|
2830
|
+
</label>
|
|
2831
|
+
<div class="dialog-actions">
|
|
2832
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
2833
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
2834
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
2835
|
+
</div>
|
|
2836
|
+
</form>
|
|
2837
|
+
</dialog>
|
|
2838
|
+
${script}
|
|
2839
|
+
</body>
|
|
2840
|
+
</html>`;
|
|
2841
|
+
};
|
|
2842
|
+
var htmlResponse = (body) => new Response(body, {
|
|
2843
|
+
status: 200,
|
|
2844
|
+
headers: {
|
|
2845
|
+
"content-type": "text/html; charset=utf-8",
|
|
2846
|
+
"cache-control": "no-store"
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2849
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
2850
|
+
status: 200,
|
|
2851
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
2852
|
+
});
|
|
2853
|
+
var adminUiRoutes = (service, ui) => {
|
|
2854
|
+
const shell = () => renderAdminDocument(service);
|
|
2855
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
2856
|
+
return {
|
|
2857
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
2858
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
2859
|
+
"GET /ui/manifest": () => json2({
|
|
2860
|
+
service,
|
|
2861
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
2862
|
+
id: panel.id,
|
|
2863
|
+
title: panel.title,
|
|
2864
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
2865
|
+
html: panel.html,
|
|
2866
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
2867
|
+
}))
|
|
2868
|
+
})
|
|
2869
|
+
};
|
|
2870
|
+
};
|
|
2871
|
+
|
|
1139
2872
|
// ../../openapi/metadata/dist/types.js
|
|
1140
2873
|
var EXTENSION_KEYS = {
|
|
1141
2874
|
operation: "x-mockingbird",
|
|
@@ -1148,11 +2881,11 @@ var EXTENSION_KEYS = {
|
|
|
1148
2881
|
};
|
|
1149
2882
|
|
|
1150
2883
|
// ../../openapi/metadata/dist/read.js
|
|
1151
|
-
var
|
|
2884
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1152
2885
|
var extensionOf = (holder, key) => holder[key];
|
|
1153
2886
|
var operationMetadata = (operation) => {
|
|
1154
2887
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
1155
|
-
const ext =
|
|
2888
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
1156
2889
|
const supported = ext.supported ?? true;
|
|
1157
2890
|
const parity = ext.parity ?? {};
|
|
1158
2891
|
return {
|
|
@@ -1188,9 +2921,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
1188
2921
|
this.name = "OperationRegistryError";
|
|
1189
2922
|
}
|
|
1190
2923
|
};
|
|
1191
|
-
var verifyOperations = (
|
|
2924
|
+
var verifyOperations = (document3, handlers) => {
|
|
1192
2925
|
const problems = [];
|
|
1193
|
-
const operations = listOperations(
|
|
2926
|
+
const operations = listOperations(document3);
|
|
1194
2927
|
const seen = /* @__PURE__ */ new Set();
|
|
1195
2928
|
for (const operation of operations) {
|
|
1196
2929
|
if (seen.has(operation.operationId))
|
|
@@ -1299,8 +3032,442 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1299
3032
|
});
|
|
1300
3033
|
};
|
|
1301
3034
|
|
|
3035
|
+
// ../core/dist/state-view.js
|
|
3036
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
3037
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
3038
|
+
var SAMPLE = 25;
|
|
3039
|
+
var WALK_LIMIT = 1e4;
|
|
3040
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3041
|
+
var fail = (status, message) => ({ ok: false, status, message });
|
|
3042
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3043
|
+
var kindOf = (value) => {
|
|
3044
|
+
if (value === null)
|
|
3045
|
+
return "null";
|
|
3046
|
+
if (Array.isArray(value))
|
|
3047
|
+
return "array";
|
|
3048
|
+
switch (typeof value) {
|
|
3049
|
+
case "string":
|
|
3050
|
+
return "string";
|
|
3051
|
+
case "number":
|
|
3052
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3053
|
+
case "boolean":
|
|
3054
|
+
return "boolean";
|
|
3055
|
+
case "object":
|
|
3056
|
+
return "object";
|
|
3057
|
+
default:
|
|
3058
|
+
return "unknown";
|
|
3059
|
+
}
|
|
3060
|
+
};
|
|
3061
|
+
var humanize = (name) => {
|
|
3062
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3063
|
+
if (words === "")
|
|
3064
|
+
return name;
|
|
3065
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3066
|
+
};
|
|
3067
|
+
var jsonValue = (value) => {
|
|
3068
|
+
if (value === void 0)
|
|
3069
|
+
return fail(400, "value is required");
|
|
3070
|
+
try {
|
|
3071
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3072
|
+
} catch {
|
|
3073
|
+
return fail(400, "value must be JSON");
|
|
3074
|
+
}
|
|
3075
|
+
};
|
|
3076
|
+
var ctorName = (value) => {
|
|
3077
|
+
const ctor = value.constructor;
|
|
3078
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3079
|
+
};
|
|
3080
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3081
|
+
var discoverCollections = (root) => {
|
|
3082
|
+
const found = [];
|
|
3083
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3084
|
+
const visit = (value, depth) => {
|
|
3085
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3086
|
+
return;
|
|
3087
|
+
if (value === null || typeof value !== "object")
|
|
3088
|
+
return;
|
|
3089
|
+
if (seen.has(value))
|
|
3090
|
+
return;
|
|
3091
|
+
seen.add(value);
|
|
3092
|
+
if (value instanceof Collection) {
|
|
3093
|
+
found.push(value);
|
|
3094
|
+
return;
|
|
3095
|
+
}
|
|
3096
|
+
if (value instanceof Map) {
|
|
3097
|
+
for (const child of value.values())
|
|
3098
|
+
visit(child, depth + 1);
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
if (value instanceof Set) {
|
|
3102
|
+
for (const child of value.values())
|
|
3103
|
+
visit(child, depth + 1);
|
|
3104
|
+
return;
|
|
3105
|
+
}
|
|
3106
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3107
|
+
return;
|
|
3108
|
+
if (Array.isArray(value)) {
|
|
3109
|
+
const cap = Math.min(value.length, 32);
|
|
3110
|
+
for (let i = 0; i < cap; i++)
|
|
3111
|
+
visit(value[i], depth + 1);
|
|
3112
|
+
return;
|
|
3113
|
+
}
|
|
3114
|
+
let children;
|
|
3115
|
+
try {
|
|
3116
|
+
children = Object.values(value);
|
|
3117
|
+
} catch {
|
|
3118
|
+
return;
|
|
3119
|
+
}
|
|
3120
|
+
for (const child of children)
|
|
3121
|
+
visit(child, depth + 1);
|
|
3122
|
+
};
|
|
3123
|
+
visit(root, 0);
|
|
3124
|
+
return found;
|
|
3125
|
+
};
|
|
3126
|
+
var storedNames = (sqlite, namespace) => {
|
|
3127
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3128
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3129
|
+
return [...records, ...sequences].map((row) => row.name);
|
|
3130
|
+
};
|
|
3131
|
+
var blankAccum = (name) => ({
|
|
3132
|
+
name,
|
|
3133
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3134
|
+
present: 0,
|
|
3135
|
+
nested: /* @__PURE__ */ new Map()
|
|
3136
|
+
});
|
|
3137
|
+
var absorb = (accum, value) => {
|
|
3138
|
+
const kind = kindOf(value);
|
|
3139
|
+
accum.kinds.add(kind);
|
|
3140
|
+
accum.present++;
|
|
3141
|
+
if (!isRecord4(value))
|
|
3142
|
+
return;
|
|
3143
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3144
|
+
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
3145
|
+
absorb(nested, child);
|
|
3146
|
+
accum.nested.set(key, nested);
|
|
3147
|
+
}
|
|
3148
|
+
};
|
|
3149
|
+
var finishField = (accum, samples) => {
|
|
3150
|
+
const kinds = [...accum.kinds];
|
|
3151
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3152
|
+
const field = {
|
|
3153
|
+
name: accum.name,
|
|
3154
|
+
kind,
|
|
3155
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3156
|
+
};
|
|
3157
|
+
if (accum.nested.size > 0) {
|
|
3158
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3159
|
+
}
|
|
3160
|
+
return field;
|
|
3161
|
+
};
|
|
3162
|
+
var inferFields = (records) => {
|
|
3163
|
+
if (records.length === 0)
|
|
3164
|
+
return [];
|
|
3165
|
+
const sample = records.slice(0, SAMPLE);
|
|
3166
|
+
const objects = sample.filter((record) => isRecord4(record.value));
|
|
3167
|
+
if (objects.length === 0) {
|
|
3168
|
+
const kinds = new Set(sample.map((record) => kindOf(record.value)));
|
|
3169
|
+
const list = [...kinds];
|
|
3170
|
+
return [
|
|
3171
|
+
{
|
|
3172
|
+
name: "(value)",
|
|
3173
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3174
|
+
optional: false
|
|
3175
|
+
}
|
|
3176
|
+
];
|
|
3177
|
+
}
|
|
3178
|
+
const root = /* @__PURE__ */ new Map();
|
|
3179
|
+
for (const record of objects) {
|
|
3180
|
+
for (const [key, value] of Object.entries(record.value)) {
|
|
3181
|
+
const accum = root.get(key) ?? blankAccum(key);
|
|
3182
|
+
absorb(accum, value);
|
|
3183
|
+
root.set(key, accum);
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3187
|
+
};
|
|
3188
|
+
var mergeFields = (declared, inferred) => {
|
|
3189
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3190
|
+
for (const field of inferred)
|
|
3191
|
+
byName.set(field.name, field);
|
|
3192
|
+
const ordered = [];
|
|
3193
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3194
|
+
for (const field of declared ?? []) {
|
|
3195
|
+
const found = byName.get(field.name);
|
|
3196
|
+
seen.add(field.name);
|
|
3197
|
+
if (!found) {
|
|
3198
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3199
|
+
continue;
|
|
3200
|
+
}
|
|
3201
|
+
ordered.push({
|
|
3202
|
+
...found,
|
|
3203
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3204
|
+
optional: field.optional || found.optional,
|
|
3205
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3206
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3207
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3208
|
+
});
|
|
3209
|
+
}
|
|
3210
|
+
for (const field of inferred) {
|
|
3211
|
+
if (!seen.has(field.name))
|
|
3212
|
+
ordered.push(field);
|
|
3213
|
+
}
|
|
3214
|
+
return ordered;
|
|
3215
|
+
};
|
|
3216
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3217
|
+
var readRecord = (collection, id) => {
|
|
3218
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3219
|
+
const row = rows.find((entry) => entry.id === id);
|
|
3220
|
+
return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
|
|
3221
|
+
};
|
|
3222
|
+
var inspectState = (scope) => {
|
|
3223
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3224
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3225
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3226
|
+
declared.set(declaration.name, declaration);
|
|
3227
|
+
}
|
|
3228
|
+
const names = new Set(declared.keys());
|
|
3229
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3230
|
+
names.add(name);
|
|
3231
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3232
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3233
|
+
names.add(collection.collectionName);
|
|
3234
|
+
}
|
|
3235
|
+
const collections = [];
|
|
3236
|
+
for (const name of names) {
|
|
3237
|
+
if (!COLLECTION_NAME.test(name))
|
|
3238
|
+
continue;
|
|
3239
|
+
const declaration = declared.get(name);
|
|
3240
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3241
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
|
|
3242
|
+
const inferred = inferFields(records);
|
|
3243
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3244
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3245
|
+
collections.push({
|
|
3246
|
+
name,
|
|
3247
|
+
label: declaration?.label ?? humanize(name),
|
|
3248
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3249
|
+
count: collection.count(),
|
|
3250
|
+
source,
|
|
3251
|
+
fields,
|
|
3252
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3255
|
+
const order = /* @__PURE__ */ new Map();
|
|
3256
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3257
|
+
order.set(item.name, index);
|
|
3258
|
+
collections.sort((a, b) => {
|
|
3259
|
+
const left = order.get(a.name);
|
|
3260
|
+
const right = order.get(b.name);
|
|
3261
|
+
if (left !== void 0 && right !== void 0)
|
|
3262
|
+
return left - right;
|
|
3263
|
+
if (left !== void 0)
|
|
3264
|
+
return -1;
|
|
3265
|
+
if (right !== void 0)
|
|
3266
|
+
return 1;
|
|
3267
|
+
return a.name.localeCompare(b.name);
|
|
3268
|
+
});
|
|
3269
|
+
return {
|
|
3270
|
+
namespace: scope.namespace,
|
|
3271
|
+
storageNamespace: scope.storageNamespace,
|
|
3272
|
+
collections
|
|
3273
|
+
};
|
|
3274
|
+
};
|
|
3275
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3276
|
+
if (!COLLECTION_NAME.test(name))
|
|
3277
|
+
return fail(400, "collection name is not allowed");
|
|
3278
|
+
const limit = query.limit ?? 50;
|
|
3279
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3280
|
+
return fail(400, "limit must be an integer from 1 to 200");
|
|
3281
|
+
}
|
|
3282
|
+
const order = query.order ?? "newest";
|
|
3283
|
+
if (order !== "newest" && order !== "oldest")
|
|
3284
|
+
return fail(400, 'order must be "newest" or "oldest"');
|
|
3285
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3286
|
+
const rows = collection.list({ order }).filter((row) => {
|
|
3287
|
+
if (query.after === void 0)
|
|
3288
|
+
return true;
|
|
3289
|
+
return order === "newest" ? row.seq < query.after : row.seq > query.after;
|
|
3290
|
+
});
|
|
3291
|
+
const slice = rows.slice(0, limit);
|
|
3292
|
+
const last = slice.at(-1);
|
|
3293
|
+
return {
|
|
3294
|
+
ok: true,
|
|
3295
|
+
value: {
|
|
3296
|
+
collection: name,
|
|
3297
|
+
count: collection.count(),
|
|
3298
|
+
records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
|
|
3299
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3300
|
+
}
|
|
3301
|
+
};
|
|
3302
|
+
};
|
|
3303
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3304
|
+
var readStateRecord = (scope, name, id) => {
|
|
3305
|
+
if (!COLLECTION_NAME.test(name))
|
|
3306
|
+
return fail(400, "collection name is not allowed");
|
|
3307
|
+
if (!RECORD_ID.test(id))
|
|
3308
|
+
return fail(400, "record id is not allowed");
|
|
3309
|
+
const record = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3310
|
+
return record ? { ok: true, value: record } : fail(404, `no record ${id} in ${name}`);
|
|
3311
|
+
};
|
|
3312
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
|
|
3313
|
+
var createStateRecord = (scope, name, input) => {
|
|
3314
|
+
if (!COLLECTION_NAME.test(name))
|
|
3315
|
+
return fail(400, "collection name is not allowed");
|
|
3316
|
+
const parsed = jsonValue(input.value);
|
|
3317
|
+
if (!parsed.ok)
|
|
3318
|
+
return parsed;
|
|
3319
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3320
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3321
|
+
const checked = requireId(id);
|
|
3322
|
+
if (!checked.ok)
|
|
3323
|
+
return checked;
|
|
3324
|
+
if (collection.has(checked.value))
|
|
3325
|
+
return fail(409, `record ${checked.value} already exists`);
|
|
3326
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3327
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3328
|
+
};
|
|
3329
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3330
|
+
if (!COLLECTION_NAME.test(name))
|
|
3331
|
+
return fail(400, "collection name is not allowed");
|
|
3332
|
+
const checked = requireId(id);
|
|
3333
|
+
if (!checked.ok)
|
|
3334
|
+
return checked;
|
|
3335
|
+
const parsed = jsonValue(value);
|
|
3336
|
+
if (!parsed.ok)
|
|
3337
|
+
return parsed;
|
|
3338
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3339
|
+
if (!collection.has(checked.value))
|
|
3340
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3341
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3342
|
+
if (!stored)
|
|
3343
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3344
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3345
|
+
};
|
|
3346
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3347
|
+
const current = readStateRecord(scope, name, id);
|
|
3348
|
+
if (!current.ok)
|
|
3349
|
+
return current;
|
|
3350
|
+
const parsed = jsonValue(value);
|
|
3351
|
+
if (!parsed.ok)
|
|
3352
|
+
return parsed;
|
|
3353
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3354
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3355
|
+
};
|
|
3356
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3357
|
+
if (!COLLECTION_NAME.test(name))
|
|
3358
|
+
return fail(400, "collection name is not allowed");
|
|
3359
|
+
const checked = requireId(id);
|
|
3360
|
+
if (!checked.ok)
|
|
3361
|
+
return checked;
|
|
3362
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3363
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
|
|
3364
|
+
};
|
|
3365
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3366
|
+
status,
|
|
3367
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3368
|
+
});
|
|
3369
|
+
var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
|
|
3370
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3371
|
+
var integerParam = (value) => {
|
|
3372
|
+
if (value === null)
|
|
3373
|
+
return void 0;
|
|
3374
|
+
if (!/^-?\d+$/.test(value))
|
|
3375
|
+
return "bad";
|
|
3376
|
+
return Number(value);
|
|
3377
|
+
};
|
|
3378
|
+
var stateAdminRoutes = (routes) => {
|
|
3379
|
+
const open = (namespace) => {
|
|
3380
|
+
try {
|
|
3381
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3382
|
+
} catch (error2) {
|
|
3383
|
+
return fail(400, error2 instanceof Error ? error2.message : String(error2));
|
|
3384
|
+
}
|
|
3385
|
+
};
|
|
3386
|
+
const wrote = (namespace) => {
|
|
3387
|
+
routes.afterWrite?.(namespace);
|
|
3388
|
+
};
|
|
3389
|
+
return {
|
|
3390
|
+
"GET /state": ({ namespace }) => {
|
|
3391
|
+
const scope = open(namespace);
|
|
3392
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3393
|
+
},
|
|
3394
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3395
|
+
const scope = open(namespace);
|
|
3396
|
+
if (!scope.ok)
|
|
3397
|
+
return fromResult(scope, 200);
|
|
3398
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3399
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3400
|
+
if (limit === "bad")
|
|
3401
|
+
return adminError2(400, "limit: expected an integer");
|
|
3402
|
+
if (after === "bad")
|
|
3403
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3404
|
+
const order = url.searchParams.get("order");
|
|
3405
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3406
|
+
...limit !== void 0 ? { limit } : {},
|
|
3407
|
+
...after !== void 0 ? { after } : {},
|
|
3408
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3409
|
+
}), 200);
|
|
3410
|
+
},
|
|
3411
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3412
|
+
const scope = open(namespace);
|
|
3413
|
+
if (!scope.ok)
|
|
3414
|
+
return fromResult(scope, 200);
|
|
3415
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3416
|
+
},
|
|
3417
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3418
|
+
const scope = open(namespace);
|
|
3419
|
+
if (!scope.ok)
|
|
3420
|
+
return fromResult(scope, 201);
|
|
3421
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
3422
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3423
|
+
}
|
|
3424
|
+
const id = body.id;
|
|
3425
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3426
|
+
return adminError2(400, "id must be a string");
|
|
3427
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3428
|
+
...typeof id === "string" ? { id } : {},
|
|
3429
|
+
value: body.value
|
|
3430
|
+
});
|
|
3431
|
+
if (created.ok)
|
|
3432
|
+
wrote(namespace);
|
|
3433
|
+
return fromResult(created, 201);
|
|
3434
|
+
},
|
|
3435
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3436
|
+
const scope = open(namespace);
|
|
3437
|
+
if (!scope.ok)
|
|
3438
|
+
return fromResult(scope, 200);
|
|
3439
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3440
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3441
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3442
|
+
if (replaced.ok)
|
|
3443
|
+
wrote(namespace);
|
|
3444
|
+
return fromResult(replaced, 200);
|
|
3445
|
+
},
|
|
3446
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3447
|
+
const scope = open(namespace);
|
|
3448
|
+
if (!scope.ok)
|
|
3449
|
+
return fromResult(scope, 200);
|
|
3450
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3451
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3452
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3453
|
+
if (patched.ok)
|
|
3454
|
+
wrote(namespace);
|
|
3455
|
+
return fromResult(patched, 200);
|
|
3456
|
+
},
|
|
3457
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3458
|
+
const scope = open(namespace);
|
|
3459
|
+
if (!scope.ok)
|
|
3460
|
+
return fromResult(scope, 200);
|
|
3461
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3462
|
+
if (removed.ok)
|
|
3463
|
+
wrote(namespace);
|
|
3464
|
+
return fromResult(removed, 200);
|
|
3465
|
+
}
|
|
3466
|
+
};
|
|
3467
|
+
};
|
|
3468
|
+
|
|
1302
3469
|
// ../core/dist/version.js
|
|
1303
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3470
|
+
var PACKAGE_VERSION = true ? "1.5.0" : UNRELEASED_VERSION;
|
|
1304
3471
|
|
|
1305
3472
|
// ../core/dist/signing.js
|
|
1306
3473
|
var encoder = new TextEncoder();
|
|
@@ -1635,11 +3802,11 @@ var createWebhookHub = (options) => {
|
|
|
1635
3802
|
};
|
|
1636
3803
|
return hub;
|
|
1637
3804
|
};
|
|
1638
|
-
var
|
|
1639
|
-
var
|
|
1640
|
-
var
|
|
3805
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
3806
|
+
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
3807
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1641
3808
|
var parseEndpoint = (value) => {
|
|
1642
|
-
if (!
|
|
3809
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
1643
3810
|
return "each endpoint needs a url";
|
|
1644
3811
|
try {
|
|
1645
3812
|
new URL(value.url);
|
|
@@ -1656,18 +3823,18 @@ var parseEndpoint = (value) => {
|
|
|
1656
3823
|
const events = value.events ?? value.enabledEvents;
|
|
1657
3824
|
if (Array.isArray(events))
|
|
1658
3825
|
endpoint.events = events.map(String);
|
|
1659
|
-
if (
|
|
3826
|
+
if (isRecord5(value.tags)) {
|
|
1660
3827
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
1661
3828
|
}
|
|
1662
3829
|
if (typeof value.account === "string")
|
|
1663
3830
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
1664
|
-
if (
|
|
3831
|
+
if (isRecord5(value.headers)) {
|
|
1665
3832
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
1666
3833
|
}
|
|
1667
3834
|
return endpoint;
|
|
1668
3835
|
};
|
|
1669
3836
|
var webhookAdminRoutes = (hub) => ({
|
|
1670
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
3837
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
1671
3838
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
1672
3839
|
const type = url.searchParams.get("type");
|
|
1673
3840
|
return type === null || d.type === type;
|
|
@@ -1675,51 +3842,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
1675
3842
|
}),
|
|
1676
3843
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
1677
3844
|
const type = url.searchParams.get("type");
|
|
1678
|
-
return
|
|
3845
|
+
return json4(200, {
|
|
1679
3846
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
1680
3847
|
});
|
|
1681
3848
|
},
|
|
1682
3849
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
1683
3850
|
const replayed = await hub.replay(params.id);
|
|
1684
|
-
return replayed ?
|
|
3851
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
1685
3852
|
},
|
|
1686
3853
|
"POST /webhooks/flush": async () => {
|
|
1687
3854
|
await hub.flush();
|
|
1688
|
-
return
|
|
3855
|
+
return json4(200, { status: "ok" });
|
|
1689
3856
|
},
|
|
1690
3857
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
1691
|
-
if (!
|
|
1692
|
-
return
|
|
3858
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
3859
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
1693
3860
|
}
|
|
1694
3861
|
const fault = { mode: body.mode };
|
|
1695
3862
|
if (typeof body.count === "number")
|
|
1696
3863
|
fault.count = body.count;
|
|
1697
3864
|
hub.fault(namespace, fault);
|
|
1698
|
-
return
|
|
3865
|
+
return json4(201, { namespace, ...fault });
|
|
1699
3866
|
},
|
|
1700
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
3867
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
1701
3868
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
1702
3869
|
...rest,
|
|
1703
3870
|
secret: secret ? "(set)" : null
|
|
1704
3871
|
}))
|
|
1705
3872
|
}),
|
|
1706
3873
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
1707
|
-
const list = Array.isArray(body) ? body :
|
|
3874
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
1708
3875
|
if (!Array.isArray(list))
|
|
1709
|
-
return
|
|
3876
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
1710
3877
|
const parsed = [];
|
|
1711
3878
|
for (const each of list) {
|
|
1712
3879
|
const endpoint = parseEndpoint(each);
|
|
1713
3880
|
if (typeof endpoint === "string")
|
|
1714
|
-
return
|
|
3881
|
+
return adminError3(400, endpoint);
|
|
1715
3882
|
parsed.push(endpoint);
|
|
1716
3883
|
}
|
|
1717
3884
|
const set = hub.setEndpoints(namespace, parsed);
|
|
1718
|
-
return
|
|
3885
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
1719
3886
|
},
|
|
1720
3887
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
1721
3888
|
hub.setEndpoints(namespace, []);
|
|
1722
|
-
return
|
|
3889
|
+
return json4(200, { status: "ok" });
|
|
1723
3890
|
}
|
|
1724
3891
|
});
|
|
1725
3892
|
var parsePayload = (message) => {
|
|
@@ -1774,8 +3941,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
1774
3941
|
this.name = "TypeError";
|
|
1775
3942
|
}
|
|
1776
3943
|
};
|
|
1777
|
-
var operationMatcher = (
|
|
1778
|
-
const matchers = listOperations(
|
|
3944
|
+
var operationMatcher = (document3) => {
|
|
3945
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
1779
3946
|
operationId: operation.operationId,
|
|
1780
3947
|
method: operation.method.toUpperCase(),
|
|
1781
3948
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -1784,6 +3951,7 @@ var operationMatcher = (document2) => {
|
|
|
1784
3951
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
1785
3952
|
};
|
|
1786
3953
|
var createRuntime = (options) => {
|
|
3954
|
+
assertAdminUi(options.adminUi);
|
|
1787
3955
|
const sqlite = bootSqlite(options.sqlite);
|
|
1788
3956
|
const clock = options.clock ?? createClock();
|
|
1789
3957
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -1869,10 +4037,10 @@ var createRuntime = (options) => {
|
|
|
1869
4037
|
const ensureBranch = (namespace, branch2, at) => {
|
|
1870
4038
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
1871
4039
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
1872
|
-
const
|
|
4040
|
+
const history2 = timeline(namespace);
|
|
1873
4041
|
if (branch2 === "main") {
|
|
1874
4042
|
if (at !== void 0) {
|
|
1875
|
-
const point =
|
|
4043
|
+
const point = history2.checkout("main", at);
|
|
1876
4044
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
1877
4045
|
captured.set(namespace, point.value.snapshot);
|
|
1878
4046
|
rng.setState(point.value.rngState);
|
|
@@ -1885,10 +4053,10 @@ var createRuntime = (options) => {
|
|
|
1885
4053
|
return namespace;
|
|
1886
4054
|
}
|
|
1887
4055
|
const storage = physicalBranch(namespace, branch2);
|
|
1888
|
-
if (!
|
|
4056
|
+
if (!history2.hasBranch(branch2)) {
|
|
1889
4057
|
if (at === void 0)
|
|
1890
|
-
|
|
1891
|
-
const point =
|
|
4058
|
+
history2.commit(capture(namespace));
|
|
4059
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
1892
4060
|
const branchRng = createRng(options.seed ?? 0);
|
|
1893
4061
|
if (point)
|
|
1894
4062
|
branchRng.setState(point.value.rngState);
|
|
@@ -1897,8 +4065,8 @@ var createRuntime = (options) => {
|
|
|
1897
4065
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1898
4066
|
if (point)
|
|
1899
4067
|
captured.set(storage, point.value.snapshot);
|
|
1900
|
-
} else if (at !== void 0 &&
|
|
1901
|
-
const point =
|
|
4068
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
4069
|
+
const point = history2.checkout(branch2, at);
|
|
1902
4070
|
if (!instances.has(storage)) {
|
|
1903
4071
|
const branchRng = createRng(options.seed ?? 0);
|
|
1904
4072
|
branchRng.setState(point.value.rngState);
|
|
@@ -1909,7 +4077,7 @@ var createRuntime = (options) => {
|
|
|
1909
4077
|
captured.set(storage, point.value.snapshot);
|
|
1910
4078
|
} else {
|
|
1911
4079
|
if (!instances.has(storage)) {
|
|
1912
|
-
const point =
|
|
4080
|
+
const point = history2.head(branch2);
|
|
1913
4081
|
const branchRng = createRng(options.seed ?? 0);
|
|
1914
4082
|
if (point)
|
|
1915
4083
|
branchRng.setState(point.value.rngState);
|
|
@@ -1933,8 +4101,8 @@ var createRuntime = (options) => {
|
|
|
1933
4101
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
1934
4102
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
1935
4103
|
const branchName = checkoutOptions.branch ?? "main";
|
|
1936
|
-
const
|
|
1937
|
-
const point =
|
|
4104
|
+
const history2 = timeline(namespace);
|
|
4105
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
1938
4106
|
const storage = ensureBranch(namespace, branchName);
|
|
1939
4107
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1940
4108
|
captured.set(storage, point.value.snapshot);
|
|
@@ -1984,12 +4152,25 @@ var createRuntime = (options) => {
|
|
|
1984
4152
|
instance(name);
|
|
1985
4153
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
1986
4154
|
captured.set(name, from);
|
|
1987
|
-
const
|
|
1988
|
-
if (
|
|
1989
|
-
|
|
4155
|
+
const history2 = timelines.get(name);
|
|
4156
|
+
if (history2)
|
|
4157
|
+
history2.commit(capture(name), { branch: "main" });
|
|
1990
4158
|
else
|
|
1991
4159
|
timeline(name);
|
|
1992
4160
|
};
|
|
4161
|
+
const declarationsFor = (namespace) => {
|
|
4162
|
+
const declared = options.state;
|
|
4163
|
+
if (!declared)
|
|
4164
|
+
return [];
|
|
4165
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
4166
|
+
};
|
|
4167
|
+
const stateScope = (namespace) => ({
|
|
4168
|
+
sqlite,
|
|
4169
|
+
namespace,
|
|
4170
|
+
storageNamespace: storageNamespace(namespace),
|
|
4171
|
+
root: instance(namespace),
|
|
4172
|
+
declarations: declarationsFor(namespace)
|
|
4173
|
+
});
|
|
1993
4174
|
const runtime = {
|
|
1994
4175
|
name: options.name,
|
|
1995
4176
|
sqlite,
|
|
@@ -2028,6 +4209,7 @@ var createRuntime = (options) => {
|
|
|
2028
4209
|
branch,
|
|
2029
4210
|
checkout,
|
|
2030
4211
|
timeline,
|
|
4212
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
2031
4213
|
fetch: async (incoming) => {
|
|
2032
4214
|
let request = incoming;
|
|
2033
4215
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -2201,10 +4383,10 @@ var createRuntime = (options) => {
|
|
|
2201
4383
|
},
|
|
2202
4384
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
2203
4385
|
inspect: (name) => {
|
|
2204
|
-
const
|
|
4386
|
+
const history2 = timeline(name);
|
|
2205
4387
|
return {
|
|
2206
|
-
branches:
|
|
2207
|
-
checkpoints:
|
|
4388
|
+
branches: history2.branches(),
|
|
4389
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
2208
4390
|
id,
|
|
2209
4391
|
branch: branchName,
|
|
2210
4392
|
parent,
|
|
@@ -2219,13 +4401,22 @@ var createRuntime = (options) => {
|
|
|
2219
4401
|
} : {},
|
|
2220
4402
|
routes: {
|
|
2221
4403
|
...credentialRoutes(credentials),
|
|
2222
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
2223
4404
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
2224
|
-
...options.admin?.(runtime) ?? {}
|
|
4405
|
+
...options.admin?.(runtime) ?? {},
|
|
4406
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4407
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4408
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4409
|
+
...stateAdminRoutes({
|
|
4410
|
+
open: stateScope,
|
|
4411
|
+
afterWrite: (namespace) => {
|
|
4412
|
+
checkpoint(namespace, "main");
|
|
4413
|
+
}
|
|
4414
|
+
}),
|
|
4415
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
2225
4416
|
},
|
|
2226
4417
|
adminKey: options.adminKey
|
|
2227
4418
|
});
|
|
2228
|
-
return runtime;
|
|
4419
|
+
return defineMock(runtime);
|
|
2229
4420
|
};
|
|
2230
4421
|
var mutableResponse = (response) => {
|
|
2231
4422
|
try {
|
|
@@ -2289,9 +4480,12 @@ var credentialRoutes = (registry) => ({
|
|
|
2289
4480
|
}
|
|
2290
4481
|
});
|
|
2291
4482
|
var presetRoutes = (presets, runtime) => ({
|
|
2292
|
-
"GET /faults/presets": () =>
|
|
2293
|
-
|
|
2294
|
-
|
|
4483
|
+
"GET /faults/presets": () => {
|
|
4484
|
+
const body = {
|
|
4485
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4486
|
+
};
|
|
4487
|
+
return adminJson(200, body);
|
|
4488
|
+
},
|
|
2295
4489
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
2296
4490
|
const name = params.name;
|
|
2297
4491
|
if (!presets[name])
|
|
@@ -2302,7 +4496,7 @@ var presetRoutes = (presets, runtime) => ({
|
|
|
2302
4496
|
});
|
|
2303
4497
|
|
|
2304
4498
|
// src/generated/openapi.ts
|
|
2305
|
-
var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Formbricks client + management API (Mockingbird subset)","description":"Stateful mock subset of open-source Formbricks (6.x): the client environment state (surveys)\\nand response creation the JS SDK uses, the v1 management API for responses and surveys\\n(\`x-api-key\`), and the widget script the web SDK loads. Errors use Formbricks' v1\\n\`{code, message, details}\` shape (\`apps/web/app/lib/api/response.ts\`). Client routes take a\\nworkspace id or a legacy (pre-5) environment id in the path.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from upstream Formbricks 6.0.0 (https://github.com/formbricks/formbricks): apps/web/app/api/v1/client/[workspaceId]/environment, apps/web/app/api/v2/client/[workspaceId]/responses, apps/web/app/api/v1/management/{responses,surveys}, and the response pipeline's webhook body (apps/web/modules/response-pipeline). Docs: https://formbricks.com/docs"}},"servers":[{"url":"https://app.formbricks.com"}],"paths":{"/api/v1/client/{workspaceId}/environment":{"parameters":[{"$ref":"#/components/parameters/WorkspaceId"}],"get":{"operationId":"GetEnvironmentState","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The environment state the SDK caches (surveys, action classes, project)","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"object","required":["data","expiresAt"],"properties":{"data":{"type":"object","required":["surveys","actionClasses","project"],"properties":{"surveys":{"type":"array","items":{"$ref":"#/components/schemas/Survey"}},"actionClasses":{"type":"array","items":{"type":"object"}},"project":{"type":"object"}}},"expiresAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}}}}}}},"400":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v2/client/{workspaceId}/responses":{"parameters":[{"$ref":"#/components/parameters/WorkspaceId"}],"post":{"operationId":"CreateClientResponse","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["surveyId","finished","data"],"properties":{"surveyId":{"type":"string","x-mockingbird-resource-ref":{"type":"survey","missing":"czzzzzzzzzzzzzzzzzzzzzzzz"}},"finished":{"type":"boolean"},"data":{"$ref":"#/components/schemas/ResponseData"},"contactId":{"type":["string","null"]},"displayId":{"type":["string","null"]},"singleUseId":{"type":["string","null"]},"endingId":{"type":["string","null"]},"language":{"type":"string","maxLength":10},"variables":{"type":"object"},"ttc":{"type":"object","additionalProperties":{"type":"number"}},"meta":{"type":"object","properties":{"source":{"type":"string"},"url":{"type":"string"},"action":{"type":"string"},"pagePath":{"type":"string"},"utmSource":{"type":"string"}}}}}}}},"responses":{"200":{"description":"The created response's id","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"object","properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"response","identity":true}},"quotaFull":{"type":"boolean"}}}}}}}},"400":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/responses":{"get":{"operationId":"ListResponses","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"surveyId","in":"query","schema":{"type":"string","x-mockingbird-resource-ref":{"type":"survey","missing":"czzzzzzzzzzzzzzzzzzzzzzzz"}}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100}},{"name":"skip","in":"query","schema":{"type":"integer","minimum":0,"maximum":100}}],"responses":{"200":{"description":"Responses, newest first","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Response"}}}}}}},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/responses/{responseId}":{"parameters":[{"name":"responseId","in":"path","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"response","missing":"czzzzzzzzzzzzzzzzzzzzzzzy"}}}],"get":{"operationId":"GetResponse","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"One response","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Response"}}}}}},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/surveys":{"get":{"operationId":"ListSurveys","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","minimum":0,"maximum":100}}],"responses":{"200":{"description":"Surveys, most recently updated first","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Survey"}}}}}}},"401":{"$ref":"#/components/responses/Error"}}},"post":{"operationId":"CreateSurvey","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["workspaceId","name","blocks"],"properties":{"workspaceId":{"description":"A workspace id, or (as \`environmentId\`) a legacy environment id.","type":"string","enum":["cworkspace000000000000001","cenvironment0000000000001"]},"name":{"type":"string","minLength":1,"maxLength":80},"type":{"type":"string","enum":["app","link"]},"status":{"type":"string","enum":["draft","inProgress","paused","completed"]},"blocks":{"description":"The survey's blocks of elements. The legacy \`questions\` array (one element per block) is also accepted, but not together with \`blocks\`.","type":"array","minItems":1,"maxItems":3,"items":{"type":"object","required":["id","elements"],"properties":{"id":{"type":"string","minLength":1,"maxLength":30},"name":{"type":"string","maxLength":30},"elements":{"type":"array","minItems":1,"maxItems":3,"items":{"$ref":"#/components/schemas/Element"}}}}}}}}}},"responses":{"200":{"description":"The created survey","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Survey"}}}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/surveys/{surveyId}":{"parameters":[{"name":"surveyId","in":"path","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"survey","missing":"czzzzzzzzzzzzzzzzzzzzzzzz"}}}],"get":{"operationId":"GetSurvey","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"One survey","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Survey"}}}}}},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/js/formbricks.umd.cjs":{"get":{"operationId":"GetWidgetScript","description":"The widget bundle the web SDK loads; served as a no-op script.","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"A no-op script defining \`window.formbricks\`","content":{"application/javascript":{"schema":{"type":"string"}}}}}}}},"components":{"securitySchemes":{"apiKey":{"type":"apiKey","in":"header","name":"x-api-key"}},"parameters":{"WorkspaceId":{"name":"workspaceId","in":"path","required":true,"description":"A workspace id, or a legacy (pre-Formbricks-5) environment id.","schema":{"type":"string","enum":["cworkspace000000000000001","cenvironment0000000000001"]}}},"responses":{"Error":{"description":"Formbricks' v1 \`{code, message, details}\` error","content":{"application/json":{"schema":{"type":"object","required":["code","message","details"],"properties":{"code":{"type":"string","enum":["not_found","gone","bad_request","internal_server_error","unauthorized","method_not_allowed","not_authenticated","forbidden","too_many_requests","conflict","payload_too_large"]},"message":{"type":"string"},"details":{"type":"object"}}}}}}},"schemas":{"ResponseData":{"type":"object","maxProperties":5,"additionalProperties":{"anyOf":[{"type":"string","maxLength":60},{"type":"number"},{"type":"array","maxItems":3,"items":{"type":"string","maxLength":30}},{"type":"object","maxProperties":3,"additionalProperties":{"type":"string","maxLength":30}}]}},"Element":{"type":"object","required":["id","type","headline"],"properties":{"id":{"type":"string","minLength":1,"maxLength":30},"type":{"type":"string","enum":["openText","multipleChoiceSingle","multipleChoiceMulti","nps","rating","date","cta","consent"]},"headline":{"type":"object","required":["default"],"properties":{"default":{"type":"string","maxLength":80}}},"required":{"type":"boolean"},"inputType":{"type":"string","enum":["text","email","url","number","phone"]}}},"Survey":{"type":"object","required":["id","name","type","status"],"properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"survey","identity":true}},"name":{"type":"string"},"type":{"type":"string"},"status":{"type":"string"},"workspaceId":{"type":"string"},"environmentId":{"description":"The legacy environment id of the survey's workspace (v1 compatibility).","type":"string"},"questions":{"type":["array","object"]},"blocks":{"type":"array"},"createdAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updatedAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}},"Response":{"type":"object","required":["id","createdAt","updatedAt","surveyId","finished","data"],"properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"response","identity":true}},"createdAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updatedAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"surveyId":{"type":"string"},"displayId":{"type":["string","null"]},"contact":{"type":["object","null"],"properties":{"id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"userId":{"type":"string"}}},"contactAttributes":{"type":["object","null"]},"finished":{"type":"boolean"},"endingId":{"type":["string","null"]},"data":{"description":"An object, or (for some deployments) the same object as a JSON string.","type":["object","string"]},"variables":{"type":"object"},"ttc":{"type":"object"},"tags":{"type":"array"},"meta":{"type":"object"},"singleUseId":{"type":["string","null"]},"language":{"type":["string","null"]}}}}}}`);
|
|
4499
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Formbricks client + management API (Mockingbird subset)","description":"Stateful mock subset of open-source Formbricks (6.x): the client environment state (surveys)\\nand response creation the JS SDK uses, the v1 management API for responses and surveys\\n(\`x-api-key\`), and the widget script the web SDK loads. Errors use Formbricks' v1\\n\`{code, message, details}\` shape (\`apps/web/app/lib/api/response.ts\`). Client routes take a\\nworkspace id or a legacy (pre-5) environment id in the path.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from upstream Formbricks 6.0.0 (https://github.com/formbricks/formbricks): apps/web/app/api/v1/client/[workspaceId]/environment, apps/web/app/api/v2/client/[workspaceId]/responses, apps/web/app/api/v1/management/{responses,surveys}, and the response pipeline's webhook body (apps/web/modules/response-pipeline). Docs: https://formbricks.com/docs"}},"servers":[{"url":"https://app.formbricks.com"}],"paths":{"/api/v1/client/{workspaceId}/environment":{"parameters":[{"$ref":"#/components/parameters/WorkspaceId"}],"get":{"operationId":"GetEnvironmentState","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The environment state the SDK caches (surveys, action classes, project)","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"object","required":["data","expiresAt"],"properties":{"data":{"type":"object","required":["surveys","actionClasses","project"],"properties":{"surveys":{"type":"array","items":{"$ref":"#/components/schemas/Survey"}},"actionClasses":{"type":"array","items":{"type":"object"}},"project":{"type":"object"}}},"expiresAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}}}}}}},"400":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v2/client/{workspaceId}/responses":{"parameters":[{"$ref":"#/components/parameters/WorkspaceId"}],"post":{"operationId":"CreateClientResponse","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["surveyId","finished","data"],"properties":{"surveyId":{"type":"string","x-mockingbird-resource-ref":{"type":"survey","missing":"czzzzzzzzzzzzzzzzzzzzzzzz"}},"finished":{"type":"boolean"},"data":{"$ref":"#/components/schemas/ResponseData"},"contactId":{"type":["string","null"]},"displayId":{"type":["string","null"]},"singleUseId":{"type":["string","null"]},"endingId":{"type":["string","null"]},"language":{"type":"string","maxLength":10},"variables":{"type":"object"},"ttc":{"type":"object","additionalProperties":{"type":"number"}},"meta":{"type":"object","properties":{"source":{"type":"string"},"url":{"type":"string"},"action":{"type":"string"},"pagePath":{"type":"string"},"utmSource":{"type":"string"}}}}}}}},"responses":{"200":{"description":"The created response's id","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"object","properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"response","identity":true}},"quotaFull":{"type":"boolean"}}}}}}}},"400":{"$ref":"#/components/responses/Error"},"403":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/responses":{"get":{"operationId":"ListResponses","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"surveyId","in":"query","schema":{"type":"string","x-mockingbird-resource-ref":{"type":"survey","missing":"czzzzzzzzzzzzzzzzzzzzzzzz"}}},{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100}},{"name":"skip","in":"query","schema":{"type":"integer","minimum":0,"maximum":100}}],"responses":{"200":{"description":"Responses, newest first","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Response"}}}}}}},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/responses/{responseId}":{"parameters":[{"name":"responseId","in":"path","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"response","missing":"czzzzzzzzzzzzzzzzzzzzzzzy"}}}],"get":{"operationId":"GetResponse","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"One response","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Response"}}}}}},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/surveys":{"get":{"operationId":"ListSurveys","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"limit","in":"query","schema":{"type":"integer","minimum":1,"maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer","minimum":0,"maximum":100}}],"responses":{"200":{"description":"Surveys, most recently updated first","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Survey"}}}}}}},"401":{"$ref":"#/components/responses/Error"}}},"post":{"operationId":"CreateSurvey","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["workspaceId","name","blocks"],"properties":{"workspaceId":{"description":"A workspace id, or (as \`environmentId\`) a legacy environment id.","type":"string","enum":["cworkspace000000000000001","cenvironment0000000000001"]},"name":{"type":"string","minLength":1,"maxLength":80},"type":{"type":"string","enum":["app","link"]},"status":{"type":"string","enum":["draft","inProgress","paused","completed"]},"blocks":{"description":"The survey's blocks of elements. The legacy \`questions\` array (one element per block) is also accepted, but not together with \`blocks\`.","type":"array","minItems":1,"maxItems":3,"items":{"type":"object","required":["id","elements"],"properties":{"id":{"type":"string","minLength":1,"maxLength":30},"name":{"type":"string","maxLength":30},"elements":{"type":"array","minItems":1,"maxItems":3,"items":{"$ref":"#/components/schemas/Element"}}}}}}}}}},"responses":{"200":{"description":"The created survey","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Survey"}}}}}},"400":{"$ref":"#/components/responses/Error"},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/api/v1/management/surveys/{surveyId}":{"parameters":[{"name":"surveyId","in":"path","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"survey","missing":"czzzzzzzzzzzzzzzzzzzzzzzz"}}}],"get":{"operationId":"GetSurvey","security":[{"apiKey":[]}],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"One survey","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"$ref":"#/components/schemas/Survey"}}}}}},"401":{"$ref":"#/components/responses/Error"},"404":{"$ref":"#/components/responses/Error"}}}},"/js/formbricks.umd.cjs":{"get":{"operationId":"GetWidgetScript","description":"The widget bundle the web SDK loads; served as a no-op script.","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"A no-op script defining \`window.formbricks\`","content":{"application/javascript":{"schema":{"type":"string"}}}}}}}},"components":{"securitySchemes":{"apiKey":{"type":"apiKey","in":"header","name":"x-api-key"}},"parameters":{"WorkspaceId":{"name":"workspaceId","in":"path","required":true,"description":"A workspace id, or a legacy (pre-Formbricks-5) environment id.","schema":{"type":"string","enum":["cworkspace000000000000001","cenvironment0000000000001"]}}},"responses":{"Error":{"description":"Formbricks' v1 \`{code, message, details}\` error","content":{"application/json":{"schema":{"type":"object","required":["code","message","details"],"properties":{"code":{"type":"string","enum":["not_found","gone","bad_request","internal_server_error","unauthorized","method_not_allowed","not_authenticated","forbidden","too_many_requests","conflict","payload_too_large"]},"message":{"type":"string"},"details":{"type":"object"}}}}}}},"schemas":{"ResponseData":{"type":"object","maxProperties":5,"additionalProperties":{"anyOf":[{"type":"string","maxLength":60},{"type":"number"},{"type":"array","maxItems":3,"items":{"type":"string","maxLength":30}},{"type":"object","maxProperties":3,"additionalProperties":{"type":"string","maxLength":30}}]}},"Element":{"type":"object","required":["id","type","headline"],"properties":{"id":{"type":"string","minLength":1,"maxLength":30},"type":{"type":"string","enum":["openText","multipleChoiceSingle","multipleChoiceMulti","nps","rating","date","cta","consent"]},"headline":{"type":"object","required":["default"],"properties":{"default":{"type":"string","maxLength":80}}},"required":{"type":"boolean"},"inputType":{"type":"string","enum":["text","email","url","number","phone"]}}},"Survey":{"type":"object","required":["id","name","type","status"],"properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"survey","identity":true}},"name":{"type":"string"},"type":{"type":"string"},"status":{"type":"string"},"workspaceId":{"type":"string"},"environmentId":{"description":"The legacy environment id of the survey's workspace (v1 compatibility).","type":"string"},"questions":{"type":["array","object"]},"blocks":{"type":"array"},"createdAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updatedAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}},"Response":{"type":"object","required":["id","createdAt","updatedAt","surveyId","finished","data"],"properties":{"id":{"type":"string","x-mockingbird-resource":{"type":"response","identity":true}},"createdAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updatedAt":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"surveyId":{"type":"string"},"displayId":{"type":["string","null"]},"contact":{"type":["object","null"],"properties":{"id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"userId":{"type":"string"}}},"contactAttributes":{"type":["object","null"]},"finished":{"type":"boolean"},"endingId":{"type":["string","null"]},"data":{"description":"An object, or (for some deployments) the same object as a JSON string.","type":["object","string"]},"variables":{"type":"object"},"ttc":{"type":"object"},"tags":{"type":"array"},"meta":{"type":"object"},"singleUseId":{"type":["string","null"]},"language":{"type":["string","null"]}}}}}}`);
|
|
2306
4500
|
var operationIds = ["GetEnvironmentState", "CreateClientResponse", "ListResponses", "GetResponse", "ListSurveys", "CreateSurvey", "GetSurvey", "GetWidgetScript"];
|
|
2307
4501
|
var supportedOperationIds = ["GetEnvironmentState", "CreateClientResponse", "ListResponses", "GetResponse", "ListSurveys", "CreateSurvey", "GetSurvey", "GetWidgetScript"];
|
|
2308
4502
|
|
|
@@ -3271,24 +5465,24 @@ var FORMBRICKS_PRESETS = {
|
|
|
3271
5465
|
webhook: { mode: "reorder" }
|
|
3272
5466
|
}
|
|
3273
5467
|
};
|
|
3274
|
-
var
|
|
3275
|
-
var
|
|
3276
|
-
var
|
|
5468
|
+
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
5469
|
+
var adminError4 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
|
|
5470
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3277
5471
|
var adminRoutes = (runtime) => ({
|
|
3278
5472
|
"GET /responses": ({ url, namespace }) => {
|
|
3279
5473
|
const surveyId = url.searchParams.get("surveyId");
|
|
3280
|
-
return
|
|
5474
|
+
return json5(200, {
|
|
3281
5475
|
responses: runtime.instance(namespace).responses().filter((r) => surveyId === null || r.surveyId === surveyId)
|
|
3282
5476
|
});
|
|
3283
5477
|
},
|
|
3284
|
-
"GET /surveys": ({ namespace }) =>
|
|
5478
|
+
"GET /surveys": ({ namespace }) => json5(200, { surveys: runtime.instance(namespace).state.allSurveys() }),
|
|
3285
5479
|
"PUT /surveys": ({ body, namespace }) => {
|
|
3286
|
-
const list = Array.isArray(body) ? body :
|
|
3287
|
-
if (!Array.isArray(list)) return
|
|
5480
|
+
const list = Array.isArray(body) ? body : isRecord6(body) ? body.surveys : void 0;
|
|
5481
|
+
if (!Array.isArray(list)) return adminError4(400, "expected [survey] or {surveys: [survey]}");
|
|
3288
5482
|
const state = runtime.instance(namespace).state;
|
|
3289
5483
|
for (const [index, survey] of list.entries()) {
|
|
3290
|
-
if (!
|
|
3291
|
-
return
|
|
5484
|
+
if (!isRecord6(survey) || typeof survey.id !== "string" || typeof survey.name !== "string") {
|
|
5485
|
+
return adminError4(400, `surveys[${index}]: id and name are required`);
|
|
3292
5486
|
}
|
|
3293
5487
|
}
|
|
3294
5488
|
for (const survey of list) {
|
|
@@ -3301,22 +5495,22 @@ var adminRoutes = (runtime) => ({
|
|
|
3301
5495
|
workspaceId: owner ? state.resolveWorkspace(owner) ?? owner : null
|
|
3302
5496
|
});
|
|
3303
5497
|
}
|
|
3304
|
-
return
|
|
5498
|
+
return json5(200, { surveys: state.allSurveys().map((s) => s.id) });
|
|
3305
5499
|
},
|
|
3306
|
-
"GET /contacts": ({ namespace }) =>
|
|
5500
|
+
"GET /contacts": ({ namespace }) => json5(200, {
|
|
3307
5501
|
contacts: runtime.instance(namespace).state.contacts.list({ order: "oldest" }).map((row) => row.value)
|
|
3308
5502
|
}),
|
|
3309
5503
|
"PUT /contacts": ({ body, namespace }) => {
|
|
3310
|
-
const list = Array.isArray(body) ? body :
|
|
3311
|
-
if (!Array.isArray(list)) return
|
|
5504
|
+
const list = Array.isArray(body) ? body : isRecord6(body) ? body.contacts : void 0;
|
|
5505
|
+
if (!Array.isArray(list)) return adminError4(400, "expected [contact] or {contacts: [contact]}");
|
|
3312
5506
|
const state = runtime.instance(namespace).state;
|
|
3313
5507
|
for (const [index, contact] of list.entries()) {
|
|
3314
|
-
if (!
|
|
3315
|
-
return
|
|
5508
|
+
if (!isRecord6(contact) || typeof contact.id !== "string") {
|
|
5509
|
+
return adminError4(400, `contacts[${index}]: id is required`);
|
|
3316
5510
|
}
|
|
3317
5511
|
}
|
|
3318
5512
|
for (const contact of list) {
|
|
3319
|
-
const attributes =
|
|
5513
|
+
const attributes = isRecord6(contact.attributes) ? Object.fromEntries(Object.entries(contact.attributes).map(([k, v]) => [k, String(v)])) : {};
|
|
3320
5514
|
if (typeof contact.userId === "string") attributes.userId = contact.userId;
|
|
3321
5515
|
state.contacts.insert(contact.id, {
|
|
3322
5516
|
id: contact.id,
|
|
@@ -3324,14 +5518,14 @@ var adminRoutes = (runtime) => ({
|
|
|
3324
5518
|
attributes
|
|
3325
5519
|
});
|
|
3326
5520
|
}
|
|
3327
|
-
return
|
|
5521
|
+
return json5(200, { contacts: state.contacts.list({ order: "oldest" }).map((r) => r.value.id) });
|
|
3328
5522
|
},
|
|
3329
|
-
"GET /settings": ({ namespace }) =>
|
|
5523
|
+
"GET /settings": ({ namespace }) => json5(200, runtime.instance(namespace).state.current()),
|
|
3330
5524
|
"PUT /settings": ({ body, namespace }) => {
|
|
3331
|
-
if (!
|
|
5525
|
+
if (!isRecord6(body)) return adminError4(400, "expected a JSON object");
|
|
3332
5526
|
const patch = {};
|
|
3333
5527
|
if (Array.isArray(body.workspaces)) patch.workspaces = body.workspaces.map(String);
|
|
3334
|
-
if (
|
|
5528
|
+
if (isRecord6(body.legacyEnvironmentIds)) {
|
|
3335
5529
|
patch.legacyEnvironmentIds = Object.fromEntries(
|
|
3336
5530
|
Object.entries(body.legacyEnvironmentIds).map(([k, v]) => [k, String(v)])
|
|
3337
5531
|
);
|
|
@@ -3339,7 +5533,7 @@ var adminRoutes = (runtime) => ({
|
|
|
3339
5533
|
if (Array.isArray(body.apiKeys)) patch.apiKeys = body.apiKeys.map(String);
|
|
3340
5534
|
if (typeof body.webhookId === "string") patch.webhookId = body.webhookId;
|
|
3341
5535
|
if (typeof body.contactsEnabled === "boolean") patch.contactsEnabled = body.contactsEnabled;
|
|
3342
|
-
return
|
|
5536
|
+
return json5(200, runtime.instance(namespace).state.update(patch));
|
|
3343
5537
|
}
|
|
3344
5538
|
});
|
|
3345
5539
|
var formbricksCredential = (request) => {
|
|
@@ -3363,7 +5557,7 @@ var createRuntime2 = (options = {}) => {
|
|
|
3363
5557
|
});
|
|
3364
5558
|
const runtime = createRuntime({
|
|
3365
5559
|
name: FORMBRICKS_NAMESPACE,
|
|
3366
|
-
document,
|
|
5560
|
+
document: document2,
|
|
3367
5561
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
3368
5562
|
...options.clock ? { clock: options.clock } : {},
|
|
3369
5563
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -3643,7 +5837,7 @@ var FormbricksAPI = class {
|
|
|
3643
5837
|
})
|
|
3644
5838
|
});
|
|
3645
5839
|
this.service = createService({
|
|
3646
|
-
document,
|
|
5840
|
+
document: document2,
|
|
3647
5841
|
handlers,
|
|
3648
5842
|
sqlite,
|
|
3649
5843
|
namespace,
|
|
@@ -3990,7 +6184,7 @@ var FormbricksAPI = class {
|
|
|
3990
6184
|
};
|
|
3991
6185
|
|
|
3992
6186
|
export {
|
|
3993
|
-
document,
|
|
6187
|
+
document2 as document,
|
|
3994
6188
|
operationIds,
|
|
3995
6189
|
supportedOperationIds,
|
|
3996
6190
|
WORKSPACE_ID,
|
|
@@ -4006,4 +6200,4 @@ export {
|
|
|
4006
6200
|
formbricksError,
|
|
4007
6201
|
FormbricksAPI
|
|
4008
6202
|
};
|
|
4009
|
-
//# sourceMappingURL=chunk-
|
|
6203
|
+
//# sourceMappingURL=chunk-TNGXNIQB.js.map
|