@crvouga/mockingbird-service-odx 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-2SNMHFRT.js → chunk-IEY2O2J5.js} +3 -2
- package/dist/{chunk-2SNMHFRT.js.map → chunk-IEY2O2J5.js.map} +2 -2
- package/dist/{chunk-ALB2VJMU.js → chunk-VMVVOBJN.js} +2292 -98
- package/dist/chunk-VMVVOBJN.js.map +7 -0
- 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-ALB2VJMU.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
|
}
|
|
@@ -1095,6 +1097,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1095
1097
|
});
|
|
1096
1098
|
};
|
|
1097
1099
|
|
|
1100
|
+
// ../../ui/dist/reset.js
|
|
1101
|
+
var CSS_RESET = `*,
|
|
1102
|
+
*::before,
|
|
1103
|
+
*::after {
|
|
1104
|
+
box-sizing: border-box;
|
|
1105
|
+
margin: 0;
|
|
1106
|
+
padding: 0;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
* {
|
|
1110
|
+
scrollbar-width: thin;
|
|
1111
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
*::-webkit-scrollbar {
|
|
1115
|
+
width: 12px;
|
|
1116
|
+
height: 12px;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
*::-webkit-scrollbar-track,
|
|
1120
|
+
*::-webkit-scrollbar-corner {
|
|
1121
|
+
background: Canvas;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
*::-webkit-scrollbar-thumb {
|
|
1125
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1126
|
+
border: 3px solid Canvas;
|
|
1127
|
+
border-radius: 999px;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
html {
|
|
1131
|
+
hanging-punctuation: first allow-end last;
|
|
1132
|
+
-webkit-text-size-adjust: none;
|
|
1133
|
+
text-size-adjust: none;
|
|
1134
|
+
tab-size: 4;
|
|
1135
|
+
font-family:
|
|
1136
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1137
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1138
|
+
font-size: 16px;
|
|
1139
|
+
line-height: 1.5;
|
|
1140
|
+
-webkit-font-smoothing: antialiased;
|
|
1141
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1142
|
+
text-rendering: optimizeLegibility;
|
|
1143
|
+
-webkit-tap-highlight-color: transparent;
|
|
1144
|
+
scroll-behavior: smooth;
|
|
1145
|
+
background: Canvas;
|
|
1146
|
+
color: CanvasText;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
body {
|
|
1150
|
+
min-height: 100svh;
|
|
1151
|
+
line-height: 1.5;
|
|
1152
|
+
background: Canvas;
|
|
1153
|
+
color: CanvasText;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
h1 {
|
|
1157
|
+
font-size: 2em;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
h2 {
|
|
1161
|
+
font-size: 1.5em;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
h3 {
|
|
1165
|
+
font-size: 1.17em;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
h4 {
|
|
1169
|
+
font-size: 1em;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
h5 {
|
|
1173
|
+
font-size: 0.83em;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
h6 {
|
|
1177
|
+
font-size: 0.67em;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
h1,
|
|
1181
|
+
h2,
|
|
1182
|
+
h3,
|
|
1183
|
+
h4,
|
|
1184
|
+
h5,
|
|
1185
|
+
h6 {
|
|
1186
|
+
font-weight: 700;
|
|
1187
|
+
line-height: 1.2;
|
|
1188
|
+
text-wrap: balance;
|
|
1189
|
+
overflow-wrap: break-word;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
p,
|
|
1193
|
+
li,
|
|
1194
|
+
figcaption,
|
|
1195
|
+
dd,
|
|
1196
|
+
dt,
|
|
1197
|
+
blockquote {
|
|
1198
|
+
overflow-wrap: break-word;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
p,
|
|
1202
|
+
li,
|
|
1203
|
+
figcaption,
|
|
1204
|
+
blockquote {
|
|
1205
|
+
text-wrap: pretty;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
ul,
|
|
1209
|
+
ol,
|
|
1210
|
+
menu {
|
|
1211
|
+
list-style: none;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
a {
|
|
1215
|
+
color: inherit;
|
|
1216
|
+
text-decoration: underline;
|
|
1217
|
+
text-decoration-thickness: 1px;
|
|
1218
|
+
text-underline-offset: 0.15em;
|
|
1219
|
+
text-decoration-skip-ink: auto;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
b,
|
|
1223
|
+
strong {
|
|
1224
|
+
font-weight: 700;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
small {
|
|
1228
|
+
font-size: 0.875em;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
code,
|
|
1232
|
+
kbd,
|
|
1233
|
+
samp,
|
|
1234
|
+
pre {
|
|
1235
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1236
|
+
font-size: 1em;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
sub,
|
|
1240
|
+
sup {
|
|
1241
|
+
font-size: 75%;
|
|
1242
|
+
line-height: 0;
|
|
1243
|
+
position: relative;
|
|
1244
|
+
vertical-align: baseline;
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
sub {
|
|
1248
|
+
bottom: -0.25em;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
sup {
|
|
1252
|
+
top: -0.5em;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
abbr[title] {
|
|
1256
|
+
text-decoration: underline dotted;
|
|
1257
|
+
text-underline-offset: 0.15em;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
mark {
|
|
1261
|
+
background: Mark;
|
|
1262
|
+
color: MarkText;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
hr {
|
|
1266
|
+
height: 0;
|
|
1267
|
+
border: 0;
|
|
1268
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1269
|
+
color: inherit;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
img,
|
|
1273
|
+
picture,
|
|
1274
|
+
video,
|
|
1275
|
+
canvas {
|
|
1276
|
+
display: block;
|
|
1277
|
+
max-width: 100%;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
img,
|
|
1281
|
+
video {
|
|
1282
|
+
height: auto;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
svg {
|
|
1286
|
+
overflow: hidden;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
iframe {
|
|
1290
|
+
border: 0;
|
|
1291
|
+
max-width: 100%;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
table {
|
|
1295
|
+
border-collapse: collapse;
|
|
1296
|
+
border-spacing: 0;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
fieldset {
|
|
1300
|
+
border: 0;
|
|
1301
|
+
min-inline-size: 0;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
legend {
|
|
1305
|
+
padding: 0;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
button,
|
|
1309
|
+
input,
|
|
1310
|
+
select,
|
|
1311
|
+
textarea,
|
|
1312
|
+
optgroup {
|
|
1313
|
+
font: inherit;
|
|
1314
|
+
letter-spacing: inherit;
|
|
1315
|
+
color: inherit;
|
|
1316
|
+
margin: 0;
|
|
1317
|
+
vertical-align: middle;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
button,
|
|
1321
|
+
input[type="button"],
|
|
1322
|
+
input[type="submit"],
|
|
1323
|
+
input[type="reset"] {
|
|
1324
|
+
appearance: none;
|
|
1325
|
+
background: none;
|
|
1326
|
+
border: 0;
|
|
1327
|
+
padding: 0;
|
|
1328
|
+
cursor: pointer;
|
|
1329
|
+
text-align: center;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
input,
|
|
1333
|
+
textarea,
|
|
1334
|
+
select {
|
|
1335
|
+
background-color: Canvas;
|
|
1336
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1337
|
+
border-radius: 0;
|
|
1338
|
+
padding: 0.5em 0.65em;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
input[type="checkbox"],
|
|
1342
|
+
input[type="radio"],
|
|
1343
|
+
input[type="range"],
|
|
1344
|
+
input[type="file"],
|
|
1345
|
+
input[type="color"],
|
|
1346
|
+
input[type="button"],
|
|
1347
|
+
input[type="submit"],
|
|
1348
|
+
input[type="reset"],
|
|
1349
|
+
input[type="image"],
|
|
1350
|
+
input[type="hidden"] {
|
|
1351
|
+
background: none;
|
|
1352
|
+
border: 0;
|
|
1353
|
+
padding: 0;
|
|
1354
|
+
border-radius: 0;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
input[type="checkbox"],
|
|
1358
|
+
input[type="radio"] {
|
|
1359
|
+
accent-color: CanvasText;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
input[type="search"] {
|
|
1363
|
+
appearance: none;
|
|
1364
|
+
background-color: Canvas;
|
|
1365
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1369
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1370
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1371
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1372
|
+
-webkit-appearance: none;
|
|
1373
|
+
display: none;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
input[type="number"] {
|
|
1377
|
+
appearance: textfield;
|
|
1378
|
+
background-color: Canvas;
|
|
1379
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1383
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1384
|
+
-webkit-appearance: none;
|
|
1385
|
+
margin: 0;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
textarea {
|
|
1389
|
+
resize: vertical;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
::placeholder {
|
|
1393
|
+
opacity: 1;
|
|
1394
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
:focus-visible {
|
|
1398
|
+
outline: 2px solid CanvasText;
|
|
1399
|
+
outline-offset: 2px;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
:focus:not(:focus-visible) {
|
|
1403
|
+
outline: none;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
:disabled,
|
|
1407
|
+
[disabled] {
|
|
1408
|
+
cursor: default;
|
|
1409
|
+
opacity: 0.6;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
label,
|
|
1413
|
+
summary,
|
|
1414
|
+
select,
|
|
1415
|
+
[role="button"] {
|
|
1416
|
+
cursor: pointer;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
summary {
|
|
1420
|
+
display: list-item;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
details {
|
|
1424
|
+
display: block;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
dialog {
|
|
1428
|
+
margin: auto;
|
|
1429
|
+
padding: 1rem;
|
|
1430
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1431
|
+
background: Canvas;
|
|
1432
|
+
color: CanvasText;
|
|
1433
|
+
max-width: calc(100vw - 2rem);
|
|
1434
|
+
max-height: calc(100svh - 2rem);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
dialog:not([open]) {
|
|
1438
|
+
display: none;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
::backdrop {
|
|
1442
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
[hidden] {
|
|
1446
|
+
display: none !important;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
::selection {
|
|
1450
|
+
background: Highlight;
|
|
1451
|
+
color: HighlightText;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1455
|
+
*,
|
|
1456
|
+
*::before,
|
|
1457
|
+
*::after {
|
|
1458
|
+
animation-duration: 0.01ms !important;
|
|
1459
|
+
animation-iteration-count: 1 !important;
|
|
1460
|
+
transition-duration: 0.01ms !important;
|
|
1461
|
+
scroll-behavior: auto !important;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
@media (pointer: coarse) {
|
|
1466
|
+
input,
|
|
1467
|
+
select,
|
|
1468
|
+
textarea {
|
|
1469
|
+
font-size: max(16px, 1em);
|
|
1470
|
+
}
|
|
1471
|
+
}`;
|
|
1472
|
+
|
|
1473
|
+
// ../core/dist/admin-client.js
|
|
1474
|
+
function isRecord2(value) {
|
|
1475
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1476
|
+
}
|
|
1477
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1478
|
+
const clip = (value, max) => {
|
|
1479
|
+
if (typeof value !== "string")
|
|
1480
|
+
return null;
|
|
1481
|
+
const trimmed = value.trim();
|
|
1482
|
+
if (trimmed === "")
|
|
1483
|
+
return null;
|
|
1484
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1485
|
+
};
|
|
1486
|
+
const httpUrl = (value) => {
|
|
1487
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1488
|
+
return null;
|
|
1489
|
+
try {
|
|
1490
|
+
const url = new URL(value);
|
|
1491
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1492
|
+
return null;
|
|
1493
|
+
return url.href;
|
|
1494
|
+
} catch {
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
const hexColor = (value) => {
|
|
1499
|
+
if (typeof value !== "string")
|
|
1500
|
+
return null;
|
|
1501
|
+
const raw = value.trim();
|
|
1502
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1503
|
+
};
|
|
1504
|
+
const hostname = (value) => {
|
|
1505
|
+
try {
|
|
1506
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1507
|
+
} catch {
|
|
1508
|
+
return value;
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
host.replaceChildren();
|
|
1512
|
+
host.hidden = true;
|
|
1513
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1514
|
+
return;
|
|
1515
|
+
const row = catalog[service];
|
|
1516
|
+
if (!isRecord2(row))
|
|
1517
|
+
return;
|
|
1518
|
+
const vendor = clip(row.vendor, 80);
|
|
1519
|
+
const website = httpUrl(row.website);
|
|
1520
|
+
const guide = httpUrl(row.guide);
|
|
1521
|
+
const docs = httpUrl(row.docs);
|
|
1522
|
+
const logo = httpUrl(row.logo);
|
|
1523
|
+
const color = hexColor(row.color);
|
|
1524
|
+
const description = clip(row.description, 280);
|
|
1525
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1526
|
+
return;
|
|
1527
|
+
const add = (node) => {
|
|
1528
|
+
host.append(node);
|
|
1529
|
+
return node;
|
|
1530
|
+
};
|
|
1531
|
+
if (logo !== null) {
|
|
1532
|
+
const img = doc.createElement("img");
|
|
1533
|
+
img.alt = "";
|
|
1534
|
+
img.src = logo;
|
|
1535
|
+
img.width = 16;
|
|
1536
|
+
img.height = 16;
|
|
1537
|
+
img.decoding = "async";
|
|
1538
|
+
img.referrerPolicy = "no-referrer";
|
|
1539
|
+
if (color !== null)
|
|
1540
|
+
img.style.borderColor = color;
|
|
1541
|
+
add(img);
|
|
1542
|
+
}
|
|
1543
|
+
const name = doc.createElement("span");
|
|
1544
|
+
name.className = "vendor-name";
|
|
1545
|
+
name.textContent = vendor;
|
|
1546
|
+
if (description !== null)
|
|
1547
|
+
name.title = description;
|
|
1548
|
+
add(name);
|
|
1549
|
+
const sep = () => {
|
|
1550
|
+
const node = doc.createElement("span");
|
|
1551
|
+
node.className = "vendor-sep";
|
|
1552
|
+
node.setAttribute("aria-hidden", "true");
|
|
1553
|
+
node.textContent = "\xB7";
|
|
1554
|
+
return node;
|
|
1555
|
+
};
|
|
1556
|
+
const link = (href, label, title) => {
|
|
1557
|
+
const node = doc.createElement("a");
|
|
1558
|
+
node.className = "vendor-link";
|
|
1559
|
+
node.href = href;
|
|
1560
|
+
node.target = "_blank";
|
|
1561
|
+
node.rel = "noopener noreferrer";
|
|
1562
|
+
node.referrerPolicy = "no-referrer";
|
|
1563
|
+
node.textContent = label;
|
|
1564
|
+
node.title = title;
|
|
1565
|
+
return node;
|
|
1566
|
+
};
|
|
1567
|
+
if (website !== null) {
|
|
1568
|
+
add(sep());
|
|
1569
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1570
|
+
}
|
|
1571
|
+
if (guide !== null) {
|
|
1572
|
+
add(sep());
|
|
1573
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1574
|
+
}
|
|
1575
|
+
if (docs !== null) {
|
|
1576
|
+
add(sep());
|
|
1577
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1578
|
+
}
|
|
1579
|
+
host.removeAttribute("hidden");
|
|
1580
|
+
host.hidden = false;
|
|
1581
|
+
}
|
|
1582
|
+
function startAdminBrand(env) {
|
|
1583
|
+
const requested = env.params.get("brands");
|
|
1584
|
+
let brandsUrl = env.brandsUrl;
|
|
1585
|
+
if (requested) {
|
|
1586
|
+
try {
|
|
1587
|
+
const url = new URL(requested, env.location.href);
|
|
1588
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1589
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1590
|
+
brandsUrl = url.href;
|
|
1591
|
+
} catch {
|
|
1592
|
+
brandsUrl = env.brandsUrl;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
const vendorHost = env.$("vendor");
|
|
1596
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1597
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1598
|
+
if (vendorHost === null)
|
|
1599
|
+
return;
|
|
1600
|
+
env.fetch(brandsUrl, {
|
|
1601
|
+
headers: { accept: "application/json" },
|
|
1602
|
+
signal: AbortSignal.timeout(5e3)
|
|
1603
|
+
}).then(async (response) => {
|
|
1604
|
+
if (!response.ok)
|
|
1605
|
+
return null;
|
|
1606
|
+
const catalog = await response.json();
|
|
1607
|
+
return catalog;
|
|
1608
|
+
}).then((catalog) => {
|
|
1609
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1610
|
+
}).catch(() => {
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
function faultPresetList(value) {
|
|
1614
|
+
if (!isRecord2(value))
|
|
1615
|
+
throw new Error("Fault presets response was not an object");
|
|
1616
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1617
|
+
return { presets: [] };
|
|
1618
|
+
}
|
|
1619
|
+
if (!Array.isArray(value.presets))
|
|
1620
|
+
throw new Error("Fault presets response was not a list");
|
|
1621
|
+
return {
|
|
1622
|
+
presets: value.presets.flatMap((item) => {
|
|
1623
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1624
|
+
return [];
|
|
1625
|
+
return [{ name: item.name }];
|
|
1626
|
+
})
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
function bootAdmin(config) {
|
|
1630
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1631
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1632
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1633
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1634
|
+
const readJson2 = (text2) => {
|
|
1635
|
+
const value = JSON.parse(text2);
|
|
1636
|
+
return value;
|
|
1637
|
+
};
|
|
1638
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1639
|
+
switch (char) {
|
|
1640
|
+
case "&":
|
|
1641
|
+
return "&";
|
|
1642
|
+
case "<":
|
|
1643
|
+
return "<";
|
|
1644
|
+
case ">":
|
|
1645
|
+
return ">";
|
|
1646
|
+
case '"':
|
|
1647
|
+
return """;
|
|
1648
|
+
default:
|
|
1649
|
+
return "'";
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
const el = (id, kind) => {
|
|
1653
|
+
const node = document.getElementById(id);
|
|
1654
|
+
if (!(node instanceof kind))
|
|
1655
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1656
|
+
return node;
|
|
1657
|
+
};
|
|
1658
|
+
const errorMessage = (data, fallback) => {
|
|
1659
|
+
if (!isRecord2(data))
|
|
1660
|
+
return fallback;
|
|
1661
|
+
const error = data.error;
|
|
1662
|
+
if (!isRecord2(error) || typeof error.message !== "string" || error.message === "") {
|
|
1663
|
+
return fallback;
|
|
1664
|
+
}
|
|
1665
|
+
return error.message;
|
|
1666
|
+
};
|
|
1667
|
+
const requireList = (value, label) => {
|
|
1668
|
+
if (value === void 0 || value === null)
|
|
1669
|
+
return [];
|
|
1670
|
+
if (!Array.isArray(value))
|
|
1671
|
+
throw new Error(`${label} was not a list`);
|
|
1672
|
+
return value;
|
|
1673
|
+
};
|
|
1674
|
+
const state = {
|
|
1675
|
+
namespace: "default",
|
|
1676
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1677
|
+
view: "overview",
|
|
1678
|
+
collection: "",
|
|
1679
|
+
shape: null,
|
|
1680
|
+
route: null,
|
|
1681
|
+
editing: null
|
|
1682
|
+
};
|
|
1683
|
+
const standard = new Set(config.standardRoutes);
|
|
1684
|
+
const banner = el("banner", HTMLElement);
|
|
1685
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1686
|
+
keyInput.value = state.key;
|
|
1687
|
+
const params = new URLSearchParams(location.search);
|
|
1688
|
+
const queryKey = params.get("key");
|
|
1689
|
+
if (queryKey) {
|
|
1690
|
+
state.key = queryKey;
|
|
1691
|
+
keyInput.value = state.key;
|
|
1692
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1693
|
+
params.delete("key");
|
|
1694
|
+
const next = params.toString();
|
|
1695
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1696
|
+
}
|
|
1697
|
+
const queryNamespace = params.get("namespace");
|
|
1698
|
+
if (queryNamespace)
|
|
1699
|
+
state.namespace = queryNamespace;
|
|
1700
|
+
const showError = (error) => {
|
|
1701
|
+
banner.textContent = error instanceof Error ? error.message : String(error);
|
|
1702
|
+
banner.classList.add("show");
|
|
1703
|
+
};
|
|
1704
|
+
const clearError = () => {
|
|
1705
|
+
banner.classList.remove("show");
|
|
1706
|
+
};
|
|
1707
|
+
const api = async (method, path, body) => {
|
|
1708
|
+
const headers = { accept: "application/json" };
|
|
1709
|
+
if (state.key !== "")
|
|
1710
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1711
|
+
if (state.namespace !== "")
|
|
1712
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1713
|
+
if (body !== void 0)
|
|
1714
|
+
headers["content-type"] = "application/json";
|
|
1715
|
+
const init = { method, headers };
|
|
1716
|
+
if (body !== void 0)
|
|
1717
|
+
init.body = JSON.stringify(body);
|
|
1718
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1719
|
+
const text2 = await response.text();
|
|
1720
|
+
let data = null;
|
|
1721
|
+
if (text2 !== "") {
|
|
1722
|
+
try {
|
|
1723
|
+
data = readJson2(text2);
|
|
1724
|
+
} catch {
|
|
1725
|
+
data = { raw: text2 };
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
if (response.status === 401) {
|
|
1729
|
+
keyInput.focus();
|
|
1730
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1731
|
+
}
|
|
1732
|
+
if (!response.ok) {
|
|
1733
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1734
|
+
}
|
|
1735
|
+
return data;
|
|
1736
|
+
};
|
|
1737
|
+
const originGet = async (path) => {
|
|
1738
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1739
|
+
if (!response.ok)
|
|
1740
|
+
throw new Error(`${response.status} ${path}`);
|
|
1741
|
+
const value = await response.json();
|
|
1742
|
+
return value;
|
|
1743
|
+
};
|
|
1744
|
+
const panelApi = {
|
|
1745
|
+
get: (path) => api("GET", path),
|
|
1746
|
+
send: (method, path, body) => api(method, path, body),
|
|
1747
|
+
namespace: () => state.namespace
|
|
1748
|
+
};
|
|
1749
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1750
|
+
const setTheme = (theme) => {
|
|
1751
|
+
if (theme)
|
|
1752
|
+
document.documentElement.dataset.theme = theme;
|
|
1753
|
+
else
|
|
1754
|
+
delete document.documentElement.dataset.theme;
|
|
1755
|
+
};
|
|
1756
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1757
|
+
if (storedTheme)
|
|
1758
|
+
setTheme(storedTheme);
|
|
1759
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1760
|
+
const current = document.documentElement.dataset.theme;
|
|
1761
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1762
|
+
const next = dark ? "light" : "dark";
|
|
1763
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
1764
|
+
setTheme(next);
|
|
1765
|
+
});
|
|
1766
|
+
const show = (view) => {
|
|
1767
|
+
state.view = view;
|
|
1768
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
1769
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1770
|
+
continue;
|
|
1771
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
1772
|
+
}
|
|
1773
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
1774
|
+
if (!(section instanceof HTMLElement))
|
|
1775
|
+
continue;
|
|
1776
|
+
section.hidden = section.id !== `view-${view}`;
|
|
1777
|
+
}
|
|
1778
|
+
};
|
|
1779
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
1780
|
+
const target = event.target;
|
|
1781
|
+
if (!(target instanceof Element))
|
|
1782
|
+
return;
|
|
1783
|
+
const button = target.closest("button[data-view]");
|
|
1784
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1785
|
+
return;
|
|
1786
|
+
const view = button.dataset.view;
|
|
1787
|
+
if (view === void 0)
|
|
1788
|
+
return;
|
|
1789
|
+
show(view);
|
|
1790
|
+
refresh().catch(showError);
|
|
1791
|
+
});
|
|
1792
|
+
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>`;
|
|
1793
|
+
const table = (columns, rows) => {
|
|
1794
|
+
if (rows.length === 0)
|
|
1795
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
1796
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
1797
|
+
const body = rows.map((row) => {
|
|
1798
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
1799
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
1800
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
1801
|
+
}).join("");
|
|
1802
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
1803
|
+
};
|
|
1804
|
+
const preview = (value) => {
|
|
1805
|
+
const text2 = JSON.stringify(value) ?? "null";
|
|
1806
|
+
return esc(text2.length > 180 ? `${text2.slice(0, 180)}\u2026` : text2);
|
|
1807
|
+
};
|
|
1808
|
+
const when = (epoch) => {
|
|
1809
|
+
const date = new Date(epoch);
|
|
1810
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
1811
|
+
};
|
|
1812
|
+
const clockCard = (epoch) => {
|
|
1813
|
+
const date = new Date(epoch);
|
|
1814
|
+
if (Number.isNaN(date.getTime()))
|
|
1815
|
+
return esc(String(epoch));
|
|
1816
|
+
const iso = date.toISOString();
|
|
1817
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
1818
|
+
};
|
|
1819
|
+
const decodeClock = (value) => {
|
|
1820
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
1821
|
+
throw new Error("Clock response was not a clock");
|
|
1822
|
+
}
|
|
1823
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
1824
|
+
};
|
|
1825
|
+
const decodeField = (value) => {
|
|
1826
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
1827
|
+
return void 0;
|
|
1828
|
+
}
|
|
1829
|
+
const field = {
|
|
1830
|
+
name: value.name,
|
|
1831
|
+
kind: value.kind,
|
|
1832
|
+
optional: value.optional === true
|
|
1833
|
+
};
|
|
1834
|
+
if (typeof value.description === "string")
|
|
1835
|
+
field.description = value.description;
|
|
1836
|
+
if (Array.isArray(value.fields)) {
|
|
1837
|
+
field.fields = value.fields.flatMap((item) => {
|
|
1838
|
+
const child = decodeField(item);
|
|
1839
|
+
return child === void 0 ? [] : [child];
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
return field;
|
|
1843
|
+
};
|
|
1844
|
+
const decodeCollection = (value) => {
|
|
1845
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
1846
|
+
return void 0;
|
|
1847
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
1848
|
+
const field = decodeField(item);
|
|
1849
|
+
return field === void 0 ? [] : [field];
|
|
1850
|
+
}) : [];
|
|
1851
|
+
const collection = {
|
|
1852
|
+
name: value.name,
|
|
1853
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
1854
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
1855
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
1856
|
+
fields
|
|
1857
|
+
};
|
|
1858
|
+
if (typeof value.description === "string")
|
|
1859
|
+
collection.description = value.description;
|
|
1860
|
+
return collection;
|
|
1861
|
+
};
|
|
1862
|
+
const decodeState = (value) => {
|
|
1863
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
1864
|
+
throw new Error("State response has no collection list");
|
|
1865
|
+
}
|
|
1866
|
+
return {
|
|
1867
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
1868
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
1869
|
+
collections: value.collections.flatMap((item) => {
|
|
1870
|
+
const collection = decodeCollection(item);
|
|
1871
|
+
return collection === void 0 ? [] : [collection];
|
|
1872
|
+
})
|
|
1873
|
+
};
|
|
1874
|
+
};
|
|
1875
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
1876
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
1877
|
+
return [];
|
|
1878
|
+
return [
|
|
1879
|
+
{
|
|
1880
|
+
id: item.id,
|
|
1881
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
1882
|
+
value: item.value,
|
|
1883
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
1884
|
+
}
|
|
1885
|
+
];
|
|
1886
|
+
});
|
|
1887
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
1888
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
1889
|
+
if (!isRecord2(item))
|
|
1890
|
+
return [];
|
|
1891
|
+
return [
|
|
1892
|
+
{
|
|
1893
|
+
at: textOf(item.at),
|
|
1894
|
+
method: textOf(item.method),
|
|
1895
|
+
path: textOf(item.path),
|
|
1896
|
+
status: textOf(item.status),
|
|
1897
|
+
durationMs: textOf(item.durationMs),
|
|
1898
|
+
operationId: textOf(item.operationId)
|
|
1899
|
+
}
|
|
1900
|
+
];
|
|
1901
|
+
});
|
|
1902
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
1903
|
+
if (!isRecord2(item))
|
|
1904
|
+
return [];
|
|
1905
|
+
return [
|
|
1906
|
+
{
|
|
1907
|
+
id: textOf(item.id),
|
|
1908
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
1909
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
1910
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
1911
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
1912
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
1913
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
1914
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
1915
|
+
}
|
|
1916
|
+
];
|
|
1917
|
+
});
|
|
1918
|
+
const loadNamespaces = async () => {
|
|
1919
|
+
const data = await api("GET", "/namespaces");
|
|
1920
|
+
const select = el("namespace", HTMLSelectElement);
|
|
1921
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
1922
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
1923
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
1924
|
+
if (!names.includes(state.namespace))
|
|
1925
|
+
names.unshift(state.namespace);
|
|
1926
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
1927
|
+
select.value = state.namespace;
|
|
1928
|
+
};
|
|
1929
|
+
const renderOverview = async () => {
|
|
1930
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
1931
|
+
originGet("/health"),
|
|
1932
|
+
api("GET", "/state"),
|
|
1933
|
+
api("GET", "/clock"),
|
|
1934
|
+
api("GET", "/requests?limit=8")
|
|
1935
|
+
]);
|
|
1936
|
+
if (!isRecord2(health))
|
|
1937
|
+
throw new Error("Health response was not an object");
|
|
1938
|
+
const decoded = decodeState(shape);
|
|
1939
|
+
state.shape = decoded;
|
|
1940
|
+
const time = decodeClock(clock);
|
|
1941
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
1942
|
+
{
|
|
1943
|
+
k: "Service",
|
|
1944
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
1945
|
+
},
|
|
1946
|
+
{
|
|
1947
|
+
k: "Status",
|
|
1948
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
1949
|
+
},
|
|
1950
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
1951
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
1952
|
+
{
|
|
1953
|
+
k: "Records",
|
|
1954
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
1955
|
+
},
|
|
1956
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
1957
|
+
]);
|
|
1958
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
1959
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
1960
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
1961
|
+
{
|
|
1962
|
+
label: "Status",
|
|
1963
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
1964
|
+
},
|
|
1965
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
1966
|
+
], decodeJournal(journal));
|
|
1967
|
+
};
|
|
1968
|
+
const schemaChips = (collection) => {
|
|
1969
|
+
if (collection.fields.length === 0) {
|
|
1970
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
1971
|
+
}
|
|
1972
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
1973
|
+
};
|
|
1974
|
+
const renderState = async () => {
|
|
1975
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
1976
|
+
state.shape = shape;
|
|
1977
|
+
const host = el("collections", HTMLElement);
|
|
1978
|
+
if (shape.collections.length === 0) {
|
|
1979
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
1980
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
1981
|
+
el("records", HTMLElement).innerHTML = "";
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1984
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
1985
|
+
const first = shape.collections[0];
|
|
1986
|
+
if (first === void 0)
|
|
1987
|
+
return;
|
|
1988
|
+
state.collection = first.name;
|
|
1989
|
+
}
|
|
1990
|
+
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("");
|
|
1991
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
1992
|
+
if (selected === void 0)
|
|
1993
|
+
return;
|
|
1994
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
1995
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
1996
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
1997
|
+
el("records", HTMLElement).innerHTML = table([
|
|
1998
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
1999
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
2000
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
2001
|
+
], decodeRecords(page));
|
|
2002
|
+
};
|
|
2003
|
+
const renderClock = async () => {
|
|
2004
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2005
|
+
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>`;
|
|
2006
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2007
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2008
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2009
|
+
};
|
|
2010
|
+
const renderFaults = async () => {
|
|
2011
|
+
const [faults, presets] = await Promise.all([
|
|
2012
|
+
api("GET", "/faults"),
|
|
2013
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2014
|
+
]);
|
|
2015
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2016
|
+
const current = select.value;
|
|
2017
|
+
const list = faultPresetList(presets).presets;
|
|
2018
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2019
|
+
select.value = current;
|
|
2020
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2021
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2022
|
+
{
|
|
2023
|
+
label: "Match",
|
|
2024
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2025
|
+
},
|
|
2026
|
+
{
|
|
2027
|
+
label: "Effect",
|
|
2028
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
2029
|
+
}
|
|
2030
|
+
], decodeFaults(faults));
|
|
2031
|
+
};
|
|
2032
|
+
const renderJournal = async () => {
|
|
2033
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2034
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2035
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
2036
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2037
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2038
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2039
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2040
|
+
], decodeJournal(journal));
|
|
2041
|
+
};
|
|
2042
|
+
const renderRoutes = async () => {
|
|
2043
|
+
const data = await api("GET", "/");
|
|
2044
|
+
if (!isRecord2(data))
|
|
2045
|
+
throw new Error("Route list was not an object");
|
|
2046
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2047
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2048
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2049
|
+
const parts = route.split(" ");
|
|
2050
|
+
const method = parts[0] ?? "";
|
|
2051
|
+
const path = parts.slice(1).join(" ");
|
|
2052
|
+
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>`;
|
|
2053
|
+
}).join("");
|
|
2054
|
+
};
|
|
2055
|
+
const renderers = {
|
|
2056
|
+
overview: renderOverview,
|
|
2057
|
+
state: renderState,
|
|
2058
|
+
clock: renderClock,
|
|
2059
|
+
faults: renderFaults,
|
|
2060
|
+
journal: renderJournal,
|
|
2061
|
+
routes: renderRoutes
|
|
2062
|
+
};
|
|
2063
|
+
async function refresh() {
|
|
2064
|
+
clearError();
|
|
2065
|
+
const render = renderers[state.view];
|
|
2066
|
+
if (render)
|
|
2067
|
+
await render();
|
|
2068
|
+
}
|
|
2069
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2070
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2071
|
+
refresh().catch(showError);
|
|
2072
|
+
});
|
|
2073
|
+
keyInput.addEventListener("change", () => {
|
|
2074
|
+
state.key = keyInput.value.trim();
|
|
2075
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2076
|
+
refresh().catch(showError);
|
|
2077
|
+
});
|
|
2078
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2079
|
+
refresh().catch(showError);
|
|
2080
|
+
});
|
|
2081
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2082
|
+
const target = event.target;
|
|
2083
|
+
if (!(target instanceof Element))
|
|
2084
|
+
return;
|
|
2085
|
+
const button = target.closest("[data-collection]");
|
|
2086
|
+
if (!(button instanceof HTMLElement))
|
|
2087
|
+
return;
|
|
2088
|
+
const collection = button.dataset.collection;
|
|
2089
|
+
if (collection === void 0)
|
|
2090
|
+
return;
|
|
2091
|
+
state.collection = collection;
|
|
2092
|
+
renderState().catch(showError);
|
|
2093
|
+
});
|
|
2094
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2095
|
+
const target = event.target;
|
|
2096
|
+
if (!(target instanceof Element))
|
|
2097
|
+
return;
|
|
2098
|
+
const row = target.closest("[data-id]");
|
|
2099
|
+
if (!(row instanceof HTMLElement))
|
|
2100
|
+
return;
|
|
2101
|
+
const id = row.dataset.id;
|
|
2102
|
+
if (id === void 0)
|
|
2103
|
+
return;
|
|
2104
|
+
openEditor(id).catch(showError);
|
|
2105
|
+
});
|
|
2106
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2107
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2108
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2109
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2110
|
+
async function openEditor(id) {
|
|
2111
|
+
state.editing = id;
|
|
2112
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2113
|
+
editorId.value = id ?? "";
|
|
2114
|
+
editorId.readOnly = id !== null;
|
|
2115
|
+
editorDelete.hidden = id === null;
|
|
2116
|
+
if (id) {
|
|
2117
|
+
const record = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2118
|
+
if (!isRecord2(record))
|
|
2119
|
+
throw new Error("Record response was not an object");
|
|
2120
|
+
editorValue.value = JSON.stringify(record.value, null, 2) ?? "";
|
|
2121
|
+
} else {
|
|
2122
|
+
editorValue.value = "{\n \n}";
|
|
2123
|
+
}
|
|
2124
|
+
editor.showModal();
|
|
2125
|
+
}
|
|
2126
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2127
|
+
openEditor(null).catch(showError);
|
|
2128
|
+
});
|
|
2129
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2130
|
+
const submitter = event.submitter;
|
|
2131
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2132
|
+
return;
|
|
2133
|
+
event.preventDefault();
|
|
2134
|
+
let value;
|
|
2135
|
+
try {
|
|
2136
|
+
value = readJson2(editorValue.value);
|
|
2137
|
+
} catch {
|
|
2138
|
+
showError(new Error("Value is not JSON"));
|
|
2139
|
+
return;
|
|
2140
|
+
}
|
|
2141
|
+
const id = editorId.value.trim();
|
|
2142
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2143
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2144
|
+
request.then(() => {
|
|
2145
|
+
editor.close();
|
|
2146
|
+
return renderState();
|
|
2147
|
+
}).catch(showError);
|
|
2148
|
+
});
|
|
2149
|
+
editorDelete.addEventListener("click", () => {
|
|
2150
|
+
const id = state.editing;
|
|
2151
|
+
if (!id)
|
|
2152
|
+
return;
|
|
2153
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2154
|
+
editor.close();
|
|
2155
|
+
return renderState();
|
|
2156
|
+
}).catch(showError);
|
|
2157
|
+
});
|
|
2158
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2159
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2160
|
+
continue;
|
|
2161
|
+
button.addEventListener("click", () => {
|
|
2162
|
+
const raw = button.dataset.advance;
|
|
2163
|
+
if (raw === void 0)
|
|
2164
|
+
return;
|
|
2165
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2169
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2170
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2171
|
+
});
|
|
2172
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2173
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2174
|
+
});
|
|
2175
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2176
|
+
event.preventDefault();
|
|
2177
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2178
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2179
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2180
|
+
});
|
|
2181
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2182
|
+
event.preventDefault();
|
|
2183
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2184
|
+
if (preset !== "") {
|
|
2185
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2189
|
+
if (!Number.isFinite(status)) {
|
|
2190
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2194
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2195
|
+
api("POST", "/faults", {
|
|
2196
|
+
status,
|
|
2197
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2198
|
+
...method !== "" ? { method } : {}
|
|
2199
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2200
|
+
});
|
|
2201
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2202
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2203
|
+
});
|
|
2204
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2205
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2206
|
+
});
|
|
2207
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2208
|
+
const target = event.target;
|
|
2209
|
+
if (!(target instanceof Element))
|
|
2210
|
+
return;
|
|
2211
|
+
const button = target.closest("[data-route]");
|
|
2212
|
+
if (!(button instanceof HTMLElement))
|
|
2213
|
+
return;
|
|
2214
|
+
const route = button.dataset.route;
|
|
2215
|
+
if (route === void 0)
|
|
2216
|
+
return;
|
|
2217
|
+
state.route = route;
|
|
2218
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2219
|
+
const method = route.split(" ")[0] ?? "";
|
|
2220
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2221
|
+
});
|
|
2222
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2223
|
+
event.preventDefault();
|
|
2224
|
+
const send = async () => {
|
|
2225
|
+
if (state.route === null)
|
|
2226
|
+
throw new Error("Choose a route first");
|
|
2227
|
+
const parts = state.route.split(" ");
|
|
2228
|
+
const method = parts[0];
|
|
2229
|
+
const path = parts.slice(1).join(" ");
|
|
2230
|
+
if (method === void 0)
|
|
2231
|
+
throw new Error("Choose a route first");
|
|
2232
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2233
|
+
let body;
|
|
2234
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2235
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2236
|
+
try {
|
|
2237
|
+
body = readJson2(routeBody.value);
|
|
2238
|
+
} catch {
|
|
2239
|
+
throw new Error("Body is not JSON");
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
const data = await api(method, concrete, body);
|
|
2243
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2244
|
+
};
|
|
2245
|
+
send().catch(showError);
|
|
2246
|
+
});
|
|
2247
|
+
const decodePanel = (value) => {
|
|
2248
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2249
|
+
return void 0;
|
|
2250
|
+
}
|
|
2251
|
+
const panel = {
|
|
2252
|
+
id: value.id,
|
|
2253
|
+
title: value.title,
|
|
2254
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2255
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2256
|
+
};
|
|
2257
|
+
if (typeof value.script === "string")
|
|
2258
|
+
panel.script = value.script;
|
|
2259
|
+
return panel;
|
|
2260
|
+
};
|
|
2261
|
+
const mountPanels = (panels) => {
|
|
2262
|
+
const nav = el("nav", HTMLElement);
|
|
2263
|
+
const views = el("views", HTMLElement);
|
|
2264
|
+
for (const panel of panels) {
|
|
2265
|
+
const button = document.createElement("button");
|
|
2266
|
+
button.type = "button";
|
|
2267
|
+
button.dataset.view = panel.id;
|
|
2268
|
+
button.textContent = panel.title;
|
|
2269
|
+
nav.append(button);
|
|
2270
|
+
const section = document.createElement("section");
|
|
2271
|
+
section.className = "view";
|
|
2272
|
+
section.id = `view-${panel.id}`;
|
|
2273
|
+
section.hidden = true;
|
|
2274
|
+
const title = document.createElement("h2");
|
|
2275
|
+
title.textContent = panel.title;
|
|
2276
|
+
const lede = document.createElement("p");
|
|
2277
|
+
lede.className = "lede";
|
|
2278
|
+
lede.textContent = panel.description;
|
|
2279
|
+
const body = document.createElement("div");
|
|
2280
|
+
body.className = "panel-body";
|
|
2281
|
+
body.id = `panel-${panel.id}`;
|
|
2282
|
+
body.innerHTML = panel.html;
|
|
2283
|
+
section.append(title, lede, body);
|
|
2284
|
+
views.append(section);
|
|
2285
|
+
if (panel.script === void 0)
|
|
2286
|
+
continue;
|
|
2287
|
+
try {
|
|
2288
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2289
|
+
if (!isPanelScript(compiled))
|
|
2290
|
+
throw new Error("panel script did not compile");
|
|
2291
|
+
compiled(body, panelApi);
|
|
2292
|
+
} catch (error) {
|
|
2293
|
+
const note = document.createElement("p");
|
|
2294
|
+
note.className = "banner show";
|
|
2295
|
+
note.textContent = error instanceof Error ? error.message : String(error);
|
|
2296
|
+
body.append(note);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
startAdminBrand({
|
|
2301
|
+
document,
|
|
2302
|
+
$: (id) => document.getElementById(id),
|
|
2303
|
+
params,
|
|
2304
|
+
location: { href: location.href, origin: location.origin },
|
|
2305
|
+
fetch,
|
|
2306
|
+
brandsUrl: config.brandsUrl
|
|
2307
|
+
});
|
|
2308
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2309
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2310
|
+
const decoded = decodePanel(panel);
|
|
2311
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2312
|
+
});
|
|
2313
|
+
mountPanels(panels);
|
|
2314
|
+
return refresh();
|
|
2315
|
+
}).catch(showError);
|
|
2316
|
+
}
|
|
2317
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2318
|
+
var adminClientSource = (config) => {
|
|
2319
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2320
|
+
return `<script>
|
|
2321
|
+
${clientPrelude}
|
|
2322
|
+
bootAdmin(${payload});
|
|
2323
|
+
</script>`;
|
|
2324
|
+
};
|
|
2325
|
+
|
|
2326
|
+
// ../core/dist/surface.js
|
|
2327
|
+
var defineMock = (runtime) => runtime;
|
|
2328
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2329
|
+
"GET /",
|
|
2330
|
+
"POST /reset",
|
|
2331
|
+
"GET /namespaces",
|
|
2332
|
+
"GET /clock",
|
|
2333
|
+
"POST /clock",
|
|
2334
|
+
"GET /faults",
|
|
2335
|
+
"POST /faults",
|
|
2336
|
+
"DELETE /faults",
|
|
2337
|
+
"POST /snapshots",
|
|
2338
|
+
"POST /snapshots/:id/restore",
|
|
2339
|
+
"DELETE /snapshots/:id",
|
|
2340
|
+
"GET /timeline",
|
|
2341
|
+
"POST /checkpoints",
|
|
2342
|
+
"POST /branches/:name",
|
|
2343
|
+
"POST /branches/:name/checkout",
|
|
2344
|
+
"GET /requests",
|
|
2345
|
+
"DELETE /requests",
|
|
2346
|
+
"GET /metrics",
|
|
2347
|
+
"DELETE /metrics",
|
|
2348
|
+
"GET /credentials",
|
|
2349
|
+
"PUT /credentials",
|
|
2350
|
+
"DELETE /credentials",
|
|
2351
|
+
"GET /state",
|
|
2352
|
+
"GET /state/:collection",
|
|
2353
|
+
"GET /state/:collection/:id",
|
|
2354
|
+
"POST /state/:collection",
|
|
2355
|
+
"PUT /state/:collection/:id",
|
|
2356
|
+
"PATCH /state/:collection/:id",
|
|
2357
|
+
"DELETE /state/:collection/:id",
|
|
2358
|
+
"GET /ui",
|
|
2359
|
+
"GET /ui/",
|
|
2360
|
+
"GET /ui/manifest"
|
|
2361
|
+
];
|
|
2362
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2363
|
+
var assertAdminUi = (ui) => {
|
|
2364
|
+
if (!ui?.panels)
|
|
2365
|
+
return;
|
|
2366
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2367
|
+
for (const panel of ui.panels) {
|
|
2368
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2369
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2370
|
+
}
|
|
2371
|
+
if (seen.has(panel.id))
|
|
2372
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2373
|
+
seen.add(panel.id);
|
|
2374
|
+
if (panel.title.trim() === "")
|
|
2375
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2378
|
+
|
|
2379
|
+
// ../core/dist/admin-ui.js
|
|
2380
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2381
|
+
switch (char) {
|
|
2382
|
+
case "&":
|
|
2383
|
+
return "&";
|
|
2384
|
+
case "<":
|
|
2385
|
+
return "<";
|
|
2386
|
+
case ">":
|
|
2387
|
+
return ">";
|
|
2388
|
+
case '"':
|
|
2389
|
+
return """;
|
|
2390
|
+
default:
|
|
2391
|
+
return "'";
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2395
|
+
var renderAdminDocument = (service) => {
|
|
2396
|
+
const name = escapeHtml(service);
|
|
2397
|
+
const script = adminClientSource({
|
|
2398
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2399
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2400
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2401
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2402
|
+
service
|
|
2403
|
+
});
|
|
2404
|
+
return `<!DOCTYPE html>
|
|
2405
|
+
<html lang="en">
|
|
2406
|
+
<head>
|
|
2407
|
+
<meta charset="utf-8">
|
|
2408
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2409
|
+
<meta name="color-scheme" content="light dark">
|
|
2410
|
+
<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">
|
|
2411
|
+
<title>${name} admin</title>
|
|
2412
|
+
<style>
|
|
2413
|
+
${CSS_RESET}
|
|
2414
|
+
:root {
|
|
2415
|
+
color-scheme: light;
|
|
2416
|
+
--bg: #fafafa;
|
|
2417
|
+
--bg-elev: #ffffff;
|
|
2418
|
+
--bg-muted: #f4f4f5;
|
|
2419
|
+
--bg-inset: #f4f4f5;
|
|
2420
|
+
--line: #dedee3;
|
|
2421
|
+
--line-strong: #c4c4cc;
|
|
2422
|
+
--ink: #18181b;
|
|
2423
|
+
--muted: #62626b;
|
|
2424
|
+
--faint: #71717a;
|
|
2425
|
+
--accent: #27272a;
|
|
2426
|
+
--accent-ink: #ffffff;
|
|
2427
|
+
--accent-soft: #f4f4f5;
|
|
2428
|
+
--ok: #166534;
|
|
2429
|
+
--ok-soft: #f0fdf4;
|
|
2430
|
+
--warn: #a16207;
|
|
2431
|
+
--warn-soft: #fefce8;
|
|
2432
|
+
--err: #a82d32;
|
|
2433
|
+
--err-soft: #fef2f2;
|
|
2434
|
+
--shadow: none;
|
|
2435
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2436
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2437
|
+
--radius: 10px;
|
|
2438
|
+
--header: 56px;
|
|
2439
|
+
--nav: 200px;
|
|
2440
|
+
}
|
|
2441
|
+
:root[data-theme="dark"] {
|
|
2442
|
+
color-scheme: dark;
|
|
2443
|
+
--bg: #111113;
|
|
2444
|
+
--bg-elev: #19191c;
|
|
2445
|
+
--bg-muted: #242428;
|
|
2446
|
+
--bg-inset: #111113;
|
|
2447
|
+
--line: #36363c;
|
|
2448
|
+
--line-strong: #52525b;
|
|
2449
|
+
--ink: #f4f4f5;
|
|
2450
|
+
--muted: #a9a9b2;
|
|
2451
|
+
--faint: #71717a;
|
|
2452
|
+
--accent: #e4e4e7;
|
|
2453
|
+
--accent-ink: #18181b;
|
|
2454
|
+
--accent-soft: #242428;
|
|
2455
|
+
--ok: #86efac;
|
|
2456
|
+
--ok-soft: #14241b;
|
|
2457
|
+
--warn: #fde68a;
|
|
2458
|
+
--warn-soft: #2a2410;
|
|
2459
|
+
--err: #ffaaaa;
|
|
2460
|
+
--err-soft: #2c1516;
|
|
2461
|
+
--shadow: none;
|
|
2462
|
+
}
|
|
2463
|
+
@media (prefers-color-scheme: dark) {
|
|
2464
|
+
:root:not([data-theme="light"]) {
|
|
2465
|
+
color-scheme: dark;
|
|
2466
|
+
--bg: #111113;
|
|
2467
|
+
--bg-elev: #19191c;
|
|
2468
|
+
--bg-muted: #242428;
|
|
2469
|
+
--bg-inset: #111113;
|
|
2470
|
+
--line: #36363c;
|
|
2471
|
+
--line-strong: #52525b;
|
|
2472
|
+
--ink: #f4f4f5;
|
|
2473
|
+
--muted: #a9a9b2;
|
|
2474
|
+
--faint: #71717a;
|
|
2475
|
+
--accent: #e4e4e7;
|
|
2476
|
+
--accent-ink: #18181b;
|
|
2477
|
+
--accent-soft: #242428;
|
|
2478
|
+
--ok: #86efac;
|
|
2479
|
+
--ok-soft: #14241b;
|
|
2480
|
+
--warn: #fde68a;
|
|
2481
|
+
--warn-soft: #2a2410;
|
|
2482
|
+
--err: #ffaaaa;
|
|
2483
|
+
--err-soft: #2c1516;
|
|
2484
|
+
--shadow: none;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2488
|
+
html { height: 100%; }
|
|
2489
|
+
body {
|
|
2490
|
+
margin: 0;
|
|
2491
|
+
min-height: 100%;
|
|
2492
|
+
display: flex;
|
|
2493
|
+
flex-direction: column;
|
|
2494
|
+
font-family: var(--sans);
|
|
2495
|
+
background: var(--bg);
|
|
2496
|
+
color: var(--ink);
|
|
2497
|
+
line-height: 1.45;
|
|
2498
|
+
padding-left: env(safe-area-inset-left);
|
|
2499
|
+
padding-right: env(safe-area-inset-right);
|
|
2500
|
+
-webkit-text-size-adjust: 100%;
|
|
2501
|
+
}
|
|
2502
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2503
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2504
|
+
header.top {
|
|
2505
|
+
position: sticky; top: 0; z-index: 5;
|
|
2506
|
+
display: flex; align-items: center; gap: 12px;
|
|
2507
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2508
|
+
background: var(--bg-elev);
|
|
2509
|
+
border-bottom: 1px solid var(--line);
|
|
2510
|
+
min-width: 0; max-width: 100%;
|
|
2511
|
+
}
|
|
2512
|
+
.brand {
|
|
2513
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2514
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2515
|
+
}
|
|
2516
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2517
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2518
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2519
|
+
.vendor {
|
|
2520
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2521
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2522
|
+
}
|
|
2523
|
+
.vendor[hidden] { display: none; }
|
|
2524
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2525
|
+
.vendor img {
|
|
2526
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2527
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2528
|
+
}
|
|
2529
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2530
|
+
.vendor-sep { color: var(--faint); }
|
|
2531
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2532
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2533
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2534
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2535
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2536
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2537
|
+
padding: 7px 8px; min-height: 36px;
|
|
2538
|
+
}
|
|
2539
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2540
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2541
|
+
background: var(--bg-elev);
|
|
2542
|
+
}
|
|
2543
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2544
|
+
.btn-quiet { background: transparent; }
|
|
2545
|
+
.btn-danger { color: var(--err); }
|
|
2546
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2547
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2548
|
+
.layout {
|
|
2549
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2550
|
+
flex: 1 0 auto; min-width: 0;
|
|
2551
|
+
}
|
|
2552
|
+
nav.side {
|
|
2553
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2554
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2555
|
+
background: var(--bg-elev);
|
|
2556
|
+
}
|
|
2557
|
+
nav.side button {
|
|
2558
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2559
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2560
|
+
}
|
|
2561
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2562
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2563
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2564
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2565
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2566
|
+
.card {
|
|
2567
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2568
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2569
|
+
}
|
|
2570
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2571
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2572
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2573
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2574
|
+
.collection {
|
|
2575
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2576
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2577
|
+
}
|
|
2578
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2579
|
+
.collection small { display: block; color: var(--faint); }
|
|
2580
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2581
|
+
.chip {
|
|
2582
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2583
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2584
|
+
}
|
|
2585
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2586
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2587
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2588
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2589
|
+
tr.clickable { cursor: pointer; }
|
|
2590
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2591
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2592
|
+
pre {
|
|
2593
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2594
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2595
|
+
}
|
|
2596
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2597
|
+
.banner {
|
|
2598
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2599
|
+
background: var(--err-soft); color: var(--err);
|
|
2600
|
+
}
|
|
2601
|
+
.banner.show { display: block; }
|
|
2602
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2603
|
+
dialog {
|
|
2604
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2605
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2606
|
+
}
|
|
2607
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2608
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2609
|
+
textarea {
|
|
2610
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2611
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2612
|
+
font-family: var(--mono); font-size: 12px;
|
|
2613
|
+
}
|
|
2614
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2615
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2616
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2617
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2618
|
+
.status-2 { color: var(--ok); }
|
|
2619
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2620
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2621
|
+
.route {
|
|
2622
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2623
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2624
|
+
}
|
|
2625
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2626
|
+
@media (max-width: 800px) {
|
|
2627
|
+
header.top {
|
|
2628
|
+
align-items: stretch; flex-direction: column;
|
|
2629
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2630
|
+
}
|
|
2631
|
+
input, select, textarea { font-size: 16px; }
|
|
2632
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2633
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2634
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2635
|
+
nav.side {
|
|
2636
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2637
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2638
|
+
padding: 8px;
|
|
2639
|
+
}
|
|
2640
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2641
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2642
|
+
main { padding: 14px; }
|
|
2643
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2644
|
+
thead { display: none; }
|
|
2645
|
+
tr {
|
|
2646
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2647
|
+
background: var(--bg-elev); min-width: 0;
|
|
2648
|
+
}
|
|
2649
|
+
td {
|
|
2650
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2651
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2652
|
+
}
|
|
2653
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2654
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2655
|
+
.route button { grid-column: 1 / -1; }
|
|
2656
|
+
}
|
|
2657
|
+
</style>
|
|
2658
|
+
</head>
|
|
2659
|
+
<body>
|
|
2660
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2661
|
+
<header class="top">
|
|
2662
|
+
<div class="brand">
|
|
2663
|
+
<div class="brand-id">
|
|
2664
|
+
<strong>${name}</strong>
|
|
2665
|
+
<span>Admin</span>
|
|
2666
|
+
</div>
|
|
2667
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2668
|
+
</div>
|
|
2669
|
+
<div class="controls">
|
|
2670
|
+
<label class="field">Namespace
|
|
2671
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2672
|
+
</label>
|
|
2673
|
+
<label class="field">Admin key
|
|
2674
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2675
|
+
</label>
|
|
2676
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2677
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2678
|
+
</div>
|
|
2679
|
+
</header>
|
|
2680
|
+
<div class="layout">
|
|
2681
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2682
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2683
|
+
<button type="button" data-view="state">State</button>
|
|
2684
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2685
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2686
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2687
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2688
|
+
</nav>
|
|
2689
|
+
<main id="views">
|
|
2690
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2691
|
+
<section class="view" id="view-overview">
|
|
2692
|
+
<h2>Overview</h2>
|
|
2693
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2694
|
+
<div class="grid" id="overview-cards"></div>
|
|
2695
|
+
<h3>Recent requests</h3>
|
|
2696
|
+
<div id="overview-requests"></div>
|
|
2697
|
+
</section>
|
|
2698
|
+
<section class="view" id="view-state" hidden>
|
|
2699
|
+
<h2>State</h2>
|
|
2700
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2701
|
+
<div class="split">
|
|
2702
|
+
<div id="collections"></div>
|
|
2703
|
+
<div>
|
|
2704
|
+
<div id="schema"></div>
|
|
2705
|
+
<div class="row-actions">
|
|
2706
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2707
|
+
</div>
|
|
2708
|
+
<div id="records"></div>
|
|
2709
|
+
</div>
|
|
2710
|
+
</div>
|
|
2711
|
+
</section>
|
|
2712
|
+
<section class="view" id="view-clock" hidden>
|
|
2713
|
+
<h2>Clock</h2>
|
|
2714
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
2715
|
+
<div class="card" id="clock-readout"></div>
|
|
2716
|
+
<div class="row-actions">
|
|
2717
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
2718
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
2719
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
2720
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
2721
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
2722
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
2723
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
2724
|
+
</div>
|
|
2725
|
+
<form id="clock-set" class="row-actions">
|
|
2726
|
+
<label class="field">Set instant
|
|
2727
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
2728
|
+
</label>
|
|
2729
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
2730
|
+
</form>
|
|
2731
|
+
</section>
|
|
2732
|
+
<section class="view" id="view-faults" hidden>
|
|
2733
|
+
<h2>Faults</h2>
|
|
2734
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
2735
|
+
<form id="fault-form" class="card stack">
|
|
2736
|
+
<label class="field">Preset
|
|
2737
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
2738
|
+
</label>
|
|
2739
|
+
<label class="field">Status
|
|
2740
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
2741
|
+
</label>
|
|
2742
|
+
<label class="field">Path prefix
|
|
2743
|
+
<input id="fault-path" placeholder="/v1">
|
|
2744
|
+
</label>
|
|
2745
|
+
<label class="field">Method
|
|
2746
|
+
<input id="fault-method" placeholder="GET">
|
|
2747
|
+
</label>
|
|
2748
|
+
<div class="dialog-actions">
|
|
2749
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
2750
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
2751
|
+
</div>
|
|
2752
|
+
</form>
|
|
2753
|
+
<div id="fault-list"></div>
|
|
2754
|
+
</section>
|
|
2755
|
+
<section class="view" id="view-journal" hidden>
|
|
2756
|
+
<h2>Journal</h2>
|
|
2757
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
2758
|
+
<div class="row-actions">
|
|
2759
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
2760
|
+
</div>
|
|
2761
|
+
<div id="journal"></div>
|
|
2762
|
+
</section>
|
|
2763
|
+
<section class="view" id="view-routes" hidden>
|
|
2764
|
+
<h2>Routes</h2>
|
|
2765
|
+
<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>
|
|
2766
|
+
<div id="route-list"></div>
|
|
2767
|
+
<form id="route-form" class="card stack">
|
|
2768
|
+
<strong id="route-title">Select a route</strong>
|
|
2769
|
+
<label class="field">JSON body
|
|
2770
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
2771
|
+
</label>
|
|
2772
|
+
<div class="dialog-actions">
|
|
2773
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
2774
|
+
</div>
|
|
2775
|
+
<pre id="route-result">Response will show here.</pre>
|
|
2776
|
+
</form>
|
|
2777
|
+
</section>
|
|
2778
|
+
</main>
|
|
2779
|
+
</div>
|
|
2780
|
+
</div>
|
|
2781
|
+
<dialog id="editor">
|
|
2782
|
+
<form method="dialog" id="editor-form">
|
|
2783
|
+
<strong id="editor-title">Record</strong>
|
|
2784
|
+
<label class="field">Id
|
|
2785
|
+
<input id="editor-id" required>
|
|
2786
|
+
</label>
|
|
2787
|
+
<label class="field">JSON value
|
|
2788
|
+
<textarea id="editor-value"></textarea>
|
|
2789
|
+
</label>
|
|
2790
|
+
<div class="dialog-actions">
|
|
2791
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
2792
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
2793
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
2794
|
+
</div>
|
|
2795
|
+
</form>
|
|
2796
|
+
</dialog>
|
|
2797
|
+
${script}
|
|
2798
|
+
</body>
|
|
2799
|
+
</html>`;
|
|
2800
|
+
};
|
|
2801
|
+
var htmlResponse = (body) => new Response(body, {
|
|
2802
|
+
status: 200,
|
|
2803
|
+
headers: {
|
|
2804
|
+
"content-type": "text/html; charset=utf-8",
|
|
2805
|
+
"cache-control": "no-store"
|
|
2806
|
+
}
|
|
2807
|
+
});
|
|
2808
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
2809
|
+
status: 200,
|
|
2810
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
2811
|
+
});
|
|
2812
|
+
var adminUiRoutes = (service, ui) => {
|
|
2813
|
+
const shell = () => renderAdminDocument(service);
|
|
2814
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
2815
|
+
return {
|
|
2816
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
2817
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
2818
|
+
"GET /ui/manifest": () => json2({
|
|
2819
|
+
service,
|
|
2820
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
2821
|
+
id: panel.id,
|
|
2822
|
+
title: panel.title,
|
|
2823
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
2824
|
+
html: panel.html,
|
|
2825
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
2826
|
+
}))
|
|
2827
|
+
})
|
|
2828
|
+
};
|
|
2829
|
+
};
|
|
2830
|
+
|
|
1098
2831
|
// ../../openapi/metadata/dist/types.js
|
|
1099
2832
|
var EXTENSION_KEYS = {
|
|
1100
2833
|
operation: "x-mockingbird",
|
|
@@ -1107,11 +2840,11 @@ var EXTENSION_KEYS = {
|
|
|
1107
2840
|
};
|
|
1108
2841
|
|
|
1109
2842
|
// ../../openapi/metadata/dist/read.js
|
|
1110
|
-
var
|
|
2843
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1111
2844
|
var extensionOf = (holder, key) => holder[key];
|
|
1112
2845
|
var operationMetadata = (operation) => {
|
|
1113
2846
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
1114
|
-
const ext =
|
|
2847
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
1115
2848
|
const supported = ext.supported ?? true;
|
|
1116
2849
|
const parity = ext.parity ?? {};
|
|
1117
2850
|
return {
|
|
@@ -1147,9 +2880,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
1147
2880
|
this.name = "OperationRegistryError";
|
|
1148
2881
|
}
|
|
1149
2882
|
};
|
|
1150
|
-
var verifyOperations = (
|
|
2883
|
+
var verifyOperations = (document3, handlers) => {
|
|
1151
2884
|
const problems = [];
|
|
1152
|
-
const operations = listOperations(
|
|
2885
|
+
const operations = listOperations(document3);
|
|
1153
2886
|
const seen = /* @__PURE__ */ new Set();
|
|
1154
2887
|
for (const operation of operations) {
|
|
1155
2888
|
if (seen.has(operation.operationId))
|
|
@@ -1258,8 +2991,442 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1258
2991
|
});
|
|
1259
2992
|
};
|
|
1260
2993
|
|
|
2994
|
+
// ../core/dist/state-view.js
|
|
2995
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
2996
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
2997
|
+
var SAMPLE = 25;
|
|
2998
|
+
var WALK_LIMIT = 1e4;
|
|
2999
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3000
|
+
var fail = (status, message2) => ({ ok: false, status, message: message2 });
|
|
3001
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3002
|
+
var kindOf = (value) => {
|
|
3003
|
+
if (value === null)
|
|
3004
|
+
return "null";
|
|
3005
|
+
if (Array.isArray(value))
|
|
3006
|
+
return "array";
|
|
3007
|
+
switch (typeof value) {
|
|
3008
|
+
case "string":
|
|
3009
|
+
return "string";
|
|
3010
|
+
case "number":
|
|
3011
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3012
|
+
case "boolean":
|
|
3013
|
+
return "boolean";
|
|
3014
|
+
case "object":
|
|
3015
|
+
return "object";
|
|
3016
|
+
default:
|
|
3017
|
+
return "unknown";
|
|
3018
|
+
}
|
|
3019
|
+
};
|
|
3020
|
+
var humanize = (name) => {
|
|
3021
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3022
|
+
if (words === "")
|
|
3023
|
+
return name;
|
|
3024
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3025
|
+
};
|
|
3026
|
+
var jsonValue = (value) => {
|
|
3027
|
+
if (value === void 0)
|
|
3028
|
+
return fail(400, "value is required");
|
|
3029
|
+
try {
|
|
3030
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3031
|
+
} catch {
|
|
3032
|
+
return fail(400, "value must be JSON");
|
|
3033
|
+
}
|
|
3034
|
+
};
|
|
3035
|
+
var ctorName = (value) => {
|
|
3036
|
+
const ctor = value.constructor;
|
|
3037
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3038
|
+
};
|
|
3039
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3040
|
+
var discoverCollections = (root) => {
|
|
3041
|
+
const found = [];
|
|
3042
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3043
|
+
const visit = (value, depth) => {
|
|
3044
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3045
|
+
return;
|
|
3046
|
+
if (value === null || typeof value !== "object")
|
|
3047
|
+
return;
|
|
3048
|
+
if (seen.has(value))
|
|
3049
|
+
return;
|
|
3050
|
+
seen.add(value);
|
|
3051
|
+
if (value instanceof Collection) {
|
|
3052
|
+
found.push(value);
|
|
3053
|
+
return;
|
|
3054
|
+
}
|
|
3055
|
+
if (value instanceof Map) {
|
|
3056
|
+
for (const child of value.values())
|
|
3057
|
+
visit(child, depth + 1);
|
|
3058
|
+
return;
|
|
3059
|
+
}
|
|
3060
|
+
if (value instanceof Set) {
|
|
3061
|
+
for (const child of value.values())
|
|
3062
|
+
visit(child, depth + 1);
|
|
3063
|
+
return;
|
|
3064
|
+
}
|
|
3065
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3066
|
+
return;
|
|
3067
|
+
if (Array.isArray(value)) {
|
|
3068
|
+
const cap = Math.min(value.length, 32);
|
|
3069
|
+
for (let i = 0; i < cap; i++)
|
|
3070
|
+
visit(value[i], depth + 1);
|
|
3071
|
+
return;
|
|
3072
|
+
}
|
|
3073
|
+
let children;
|
|
3074
|
+
try {
|
|
3075
|
+
children = Object.values(value);
|
|
3076
|
+
} catch {
|
|
3077
|
+
return;
|
|
3078
|
+
}
|
|
3079
|
+
for (const child of children)
|
|
3080
|
+
visit(child, depth + 1);
|
|
3081
|
+
};
|
|
3082
|
+
visit(root, 0);
|
|
3083
|
+
return found;
|
|
3084
|
+
};
|
|
3085
|
+
var storedNames = (sqlite, namespace) => {
|
|
3086
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3087
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3088
|
+
return [...records, ...sequences].map((row) => row.name);
|
|
3089
|
+
};
|
|
3090
|
+
var blankAccum = (name) => ({
|
|
3091
|
+
name,
|
|
3092
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3093
|
+
present: 0,
|
|
3094
|
+
nested: /* @__PURE__ */ new Map()
|
|
3095
|
+
});
|
|
3096
|
+
var absorb = (accum, value) => {
|
|
3097
|
+
const kind = kindOf(value);
|
|
3098
|
+
accum.kinds.add(kind);
|
|
3099
|
+
accum.present++;
|
|
3100
|
+
if (!isRecord4(value))
|
|
3101
|
+
return;
|
|
3102
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3103
|
+
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
3104
|
+
absorb(nested, child);
|
|
3105
|
+
accum.nested.set(key, nested);
|
|
3106
|
+
}
|
|
3107
|
+
};
|
|
3108
|
+
var finishField = (accum, samples) => {
|
|
3109
|
+
const kinds = [...accum.kinds];
|
|
3110
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3111
|
+
const field = {
|
|
3112
|
+
name: accum.name,
|
|
3113
|
+
kind,
|
|
3114
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3115
|
+
};
|
|
3116
|
+
if (accum.nested.size > 0) {
|
|
3117
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3118
|
+
}
|
|
3119
|
+
return field;
|
|
3120
|
+
};
|
|
3121
|
+
var inferFields = (records) => {
|
|
3122
|
+
if (records.length === 0)
|
|
3123
|
+
return [];
|
|
3124
|
+
const sample = records.slice(0, SAMPLE);
|
|
3125
|
+
const objects = sample.filter((record) => isRecord4(record.value));
|
|
3126
|
+
if (objects.length === 0) {
|
|
3127
|
+
const kinds = new Set(sample.map((record) => kindOf(record.value)));
|
|
3128
|
+
const list = [...kinds];
|
|
3129
|
+
return [
|
|
3130
|
+
{
|
|
3131
|
+
name: "(value)",
|
|
3132
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3133
|
+
optional: false
|
|
3134
|
+
}
|
|
3135
|
+
];
|
|
3136
|
+
}
|
|
3137
|
+
const root = /* @__PURE__ */ new Map();
|
|
3138
|
+
for (const record of objects) {
|
|
3139
|
+
for (const [key, value] of Object.entries(record.value)) {
|
|
3140
|
+
const accum = root.get(key) ?? blankAccum(key);
|
|
3141
|
+
absorb(accum, value);
|
|
3142
|
+
root.set(key, accum);
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3146
|
+
};
|
|
3147
|
+
var mergeFields = (declared, inferred) => {
|
|
3148
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3149
|
+
for (const field of inferred)
|
|
3150
|
+
byName.set(field.name, field);
|
|
3151
|
+
const ordered = [];
|
|
3152
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3153
|
+
for (const field of declared ?? []) {
|
|
3154
|
+
const found = byName.get(field.name);
|
|
3155
|
+
seen.add(field.name);
|
|
3156
|
+
if (!found) {
|
|
3157
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3158
|
+
continue;
|
|
3159
|
+
}
|
|
3160
|
+
ordered.push({
|
|
3161
|
+
...found,
|
|
3162
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3163
|
+
optional: field.optional || found.optional,
|
|
3164
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3165
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3166
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
3169
|
+
for (const field of inferred) {
|
|
3170
|
+
if (!seen.has(field.name))
|
|
3171
|
+
ordered.push(field);
|
|
3172
|
+
}
|
|
3173
|
+
return ordered;
|
|
3174
|
+
};
|
|
3175
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3176
|
+
var readRecord = (collection, id) => {
|
|
3177
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3178
|
+
const row = rows.find((entry) => entry.id === id);
|
|
3179
|
+
return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
|
|
3180
|
+
};
|
|
3181
|
+
var inspectState = (scope) => {
|
|
3182
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3183
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3184
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3185
|
+
declared.set(declaration.name, declaration);
|
|
3186
|
+
}
|
|
3187
|
+
const names = new Set(declared.keys());
|
|
3188
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3189
|
+
names.add(name);
|
|
3190
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3191
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3192
|
+
names.add(collection.collectionName);
|
|
3193
|
+
}
|
|
3194
|
+
const collections = [];
|
|
3195
|
+
for (const name of names) {
|
|
3196
|
+
if (!COLLECTION_NAME.test(name))
|
|
3197
|
+
continue;
|
|
3198
|
+
const declaration = declared.get(name);
|
|
3199
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3200
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
|
|
3201
|
+
const inferred = inferFields(records);
|
|
3202
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3203
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3204
|
+
collections.push({
|
|
3205
|
+
name,
|
|
3206
|
+
label: declaration?.label ?? humanize(name),
|
|
3207
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3208
|
+
count: collection.count(),
|
|
3209
|
+
source,
|
|
3210
|
+
fields,
|
|
3211
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
3214
|
+
const order = /* @__PURE__ */ new Map();
|
|
3215
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3216
|
+
order.set(item.name, index);
|
|
3217
|
+
collections.sort((a, b) => {
|
|
3218
|
+
const left = order.get(a.name);
|
|
3219
|
+
const right = order.get(b.name);
|
|
3220
|
+
if (left !== void 0 && right !== void 0)
|
|
3221
|
+
return left - right;
|
|
3222
|
+
if (left !== void 0)
|
|
3223
|
+
return -1;
|
|
3224
|
+
if (right !== void 0)
|
|
3225
|
+
return 1;
|
|
3226
|
+
return a.name.localeCompare(b.name);
|
|
3227
|
+
});
|
|
3228
|
+
return {
|
|
3229
|
+
namespace: scope.namespace,
|
|
3230
|
+
storageNamespace: scope.storageNamespace,
|
|
3231
|
+
collections
|
|
3232
|
+
};
|
|
3233
|
+
};
|
|
3234
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3235
|
+
if (!COLLECTION_NAME.test(name))
|
|
3236
|
+
return fail(400, "collection name is not allowed");
|
|
3237
|
+
const limit = query.limit ?? 50;
|
|
3238
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3239
|
+
return fail(400, "limit must be an integer from 1 to 200");
|
|
3240
|
+
}
|
|
3241
|
+
const order = query.order ?? "newest";
|
|
3242
|
+
if (order !== "newest" && order !== "oldest")
|
|
3243
|
+
return fail(400, 'order must be "newest" or "oldest"');
|
|
3244
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3245
|
+
const rows = collection.list({ order }).filter((row) => {
|
|
3246
|
+
if (query.after === void 0)
|
|
3247
|
+
return true;
|
|
3248
|
+
return order === "newest" ? row.seq < query.after : row.seq > query.after;
|
|
3249
|
+
});
|
|
3250
|
+
const slice = rows.slice(0, limit);
|
|
3251
|
+
const last = slice.at(-1);
|
|
3252
|
+
return {
|
|
3253
|
+
ok: true,
|
|
3254
|
+
value: {
|
|
3255
|
+
collection: name,
|
|
3256
|
+
count: collection.count(),
|
|
3257
|
+
records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
|
|
3258
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3259
|
+
}
|
|
3260
|
+
};
|
|
3261
|
+
};
|
|
3262
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3263
|
+
var readStateRecord = (scope, name, id) => {
|
|
3264
|
+
if (!COLLECTION_NAME.test(name))
|
|
3265
|
+
return fail(400, "collection name is not allowed");
|
|
3266
|
+
if (!RECORD_ID.test(id))
|
|
3267
|
+
return fail(400, "record id is not allowed");
|
|
3268
|
+
const record = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3269
|
+
return record ? { ok: true, value: record } : fail(404, `no record ${id} in ${name}`);
|
|
3270
|
+
};
|
|
3271
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
|
|
3272
|
+
var createStateRecord = (scope, name, input) => {
|
|
3273
|
+
if (!COLLECTION_NAME.test(name))
|
|
3274
|
+
return fail(400, "collection name is not allowed");
|
|
3275
|
+
const parsed = jsonValue(input.value);
|
|
3276
|
+
if (!parsed.ok)
|
|
3277
|
+
return parsed;
|
|
3278
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3279
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3280
|
+
const checked = requireId(id);
|
|
3281
|
+
if (!checked.ok)
|
|
3282
|
+
return checked;
|
|
3283
|
+
if (collection.has(checked.value))
|
|
3284
|
+
return fail(409, `record ${checked.value} already exists`);
|
|
3285
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3286
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3287
|
+
};
|
|
3288
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3289
|
+
if (!COLLECTION_NAME.test(name))
|
|
3290
|
+
return fail(400, "collection name is not allowed");
|
|
3291
|
+
const checked = requireId(id);
|
|
3292
|
+
if (!checked.ok)
|
|
3293
|
+
return checked;
|
|
3294
|
+
const parsed = jsonValue(value);
|
|
3295
|
+
if (!parsed.ok)
|
|
3296
|
+
return parsed;
|
|
3297
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3298
|
+
if (!collection.has(checked.value))
|
|
3299
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3300
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3301
|
+
if (!stored)
|
|
3302
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3303
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3304
|
+
};
|
|
3305
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3306
|
+
const current = readStateRecord(scope, name, id);
|
|
3307
|
+
if (!current.ok)
|
|
3308
|
+
return current;
|
|
3309
|
+
const parsed = jsonValue(value);
|
|
3310
|
+
if (!parsed.ok)
|
|
3311
|
+
return parsed;
|
|
3312
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3313
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3314
|
+
};
|
|
3315
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3316
|
+
if (!COLLECTION_NAME.test(name))
|
|
3317
|
+
return fail(400, "collection name is not allowed");
|
|
3318
|
+
const checked = requireId(id);
|
|
3319
|
+
if (!checked.ok)
|
|
3320
|
+
return checked;
|
|
3321
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3322
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
|
|
3323
|
+
};
|
|
3324
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3325
|
+
status,
|
|
3326
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3327
|
+
});
|
|
3328
|
+
var adminError2 = (status, message2) => json3(status, { error: { type: "mockingbird_admin", message: message2 } });
|
|
3329
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3330
|
+
var integerParam = (value) => {
|
|
3331
|
+
if (value === null)
|
|
3332
|
+
return void 0;
|
|
3333
|
+
if (!/^-?\d+$/.test(value))
|
|
3334
|
+
return "bad";
|
|
3335
|
+
return Number(value);
|
|
3336
|
+
};
|
|
3337
|
+
var stateAdminRoutes = (routes) => {
|
|
3338
|
+
const open = (namespace) => {
|
|
3339
|
+
try {
|
|
3340
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3341
|
+
} catch (error) {
|
|
3342
|
+
return fail(400, error instanceof Error ? error.message : String(error));
|
|
3343
|
+
}
|
|
3344
|
+
};
|
|
3345
|
+
const wrote = (namespace) => {
|
|
3346
|
+
routes.afterWrite?.(namespace);
|
|
3347
|
+
};
|
|
3348
|
+
return {
|
|
3349
|
+
"GET /state": ({ namespace }) => {
|
|
3350
|
+
const scope = open(namespace);
|
|
3351
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3352
|
+
},
|
|
3353
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3354
|
+
const scope = open(namespace);
|
|
3355
|
+
if (!scope.ok)
|
|
3356
|
+
return fromResult(scope, 200);
|
|
3357
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3358
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3359
|
+
if (limit === "bad")
|
|
3360
|
+
return adminError2(400, "limit: expected an integer");
|
|
3361
|
+
if (after === "bad")
|
|
3362
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3363
|
+
const order = url.searchParams.get("order");
|
|
3364
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3365
|
+
...limit !== void 0 ? { limit } : {},
|
|
3366
|
+
...after !== void 0 ? { after } : {},
|
|
3367
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3368
|
+
}), 200);
|
|
3369
|
+
},
|
|
3370
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3371
|
+
const scope = open(namespace);
|
|
3372
|
+
if (!scope.ok)
|
|
3373
|
+
return fromResult(scope, 200);
|
|
3374
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3375
|
+
},
|
|
3376
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3377
|
+
const scope = open(namespace);
|
|
3378
|
+
if (!scope.ok)
|
|
3379
|
+
return fromResult(scope, 201);
|
|
3380
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
3381
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3382
|
+
}
|
|
3383
|
+
const id = body.id;
|
|
3384
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3385
|
+
return adminError2(400, "id must be a string");
|
|
3386
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3387
|
+
...typeof id === "string" ? { id } : {},
|
|
3388
|
+
value: body.value
|
|
3389
|
+
});
|
|
3390
|
+
if (created.ok)
|
|
3391
|
+
wrote(namespace);
|
|
3392
|
+
return fromResult(created, 201);
|
|
3393
|
+
},
|
|
3394
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3395
|
+
const scope = open(namespace);
|
|
3396
|
+
if (!scope.ok)
|
|
3397
|
+
return fromResult(scope, 200);
|
|
3398
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3399
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3400
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3401
|
+
if (replaced.ok)
|
|
3402
|
+
wrote(namespace);
|
|
3403
|
+
return fromResult(replaced, 200);
|
|
3404
|
+
},
|
|
3405
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3406
|
+
const scope = open(namespace);
|
|
3407
|
+
if (!scope.ok)
|
|
3408
|
+
return fromResult(scope, 200);
|
|
3409
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3410
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3411
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3412
|
+
if (patched.ok)
|
|
3413
|
+
wrote(namespace);
|
|
3414
|
+
return fromResult(patched, 200);
|
|
3415
|
+
},
|
|
3416
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3417
|
+
const scope = open(namespace);
|
|
3418
|
+
if (!scope.ok)
|
|
3419
|
+
return fromResult(scope, 200);
|
|
3420
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3421
|
+
if (removed.ok)
|
|
3422
|
+
wrote(namespace);
|
|
3423
|
+
return fromResult(removed, 200);
|
|
3424
|
+
}
|
|
3425
|
+
};
|
|
3426
|
+
};
|
|
3427
|
+
|
|
1261
3428
|
// ../core/dist/version.js
|
|
1262
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3429
|
+
var PACKAGE_VERSION = true ? "1.5.0" : UNRELEASED_VERSION;
|
|
1263
3430
|
|
|
1264
3431
|
// ../core/dist/signing.js
|
|
1265
3432
|
var encoder = new TextEncoder();
|
|
@@ -1594,11 +3761,11 @@ var createWebhookHub = (options) => {
|
|
|
1594
3761
|
};
|
|
1595
3762
|
return hub;
|
|
1596
3763
|
};
|
|
1597
|
-
var
|
|
1598
|
-
var
|
|
1599
|
-
var
|
|
3764
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
3765
|
+
var adminError3 = (status, message2) => json4(status, { error: { type: "mockingbird_admin", message: message2 } });
|
|
3766
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1600
3767
|
var parseEndpoint = (value) => {
|
|
1601
|
-
if (!
|
|
3768
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
1602
3769
|
return "each endpoint needs a url";
|
|
1603
3770
|
try {
|
|
1604
3771
|
new URL(value.url);
|
|
@@ -1615,18 +3782,18 @@ var parseEndpoint = (value) => {
|
|
|
1615
3782
|
const events = value.events ?? value.enabledEvents;
|
|
1616
3783
|
if (Array.isArray(events))
|
|
1617
3784
|
endpoint.events = events.map(String);
|
|
1618
|
-
if (
|
|
3785
|
+
if (isRecord5(value.tags)) {
|
|
1619
3786
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
1620
3787
|
}
|
|
1621
3788
|
if (typeof value.account === "string")
|
|
1622
3789
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
1623
|
-
if (
|
|
3790
|
+
if (isRecord5(value.headers)) {
|
|
1624
3791
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
1625
3792
|
}
|
|
1626
3793
|
return endpoint;
|
|
1627
3794
|
};
|
|
1628
3795
|
var webhookAdminRoutes = (hub) => ({
|
|
1629
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
3796
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
1630
3797
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
1631
3798
|
const type = url.searchParams.get("type");
|
|
1632
3799
|
return type === null || d.type === type;
|
|
@@ -1634,51 +3801,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
1634
3801
|
}),
|
|
1635
3802
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
1636
3803
|
const type = url.searchParams.get("type");
|
|
1637
|
-
return
|
|
3804
|
+
return json4(200, {
|
|
1638
3805
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
1639
3806
|
});
|
|
1640
3807
|
},
|
|
1641
3808
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
1642
3809
|
const replayed = await hub.replay(params.id);
|
|
1643
|
-
return replayed ?
|
|
3810
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
1644
3811
|
},
|
|
1645
3812
|
"POST /webhooks/flush": async () => {
|
|
1646
3813
|
await hub.flush();
|
|
1647
|
-
return
|
|
3814
|
+
return json4(200, { status: "ok" });
|
|
1648
3815
|
},
|
|
1649
3816
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
1650
|
-
if (!
|
|
1651
|
-
return
|
|
3817
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
3818
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
1652
3819
|
}
|
|
1653
3820
|
const fault = { mode: body.mode };
|
|
1654
3821
|
if (typeof body.count === "number")
|
|
1655
3822
|
fault.count = body.count;
|
|
1656
3823
|
hub.fault(namespace, fault);
|
|
1657
|
-
return
|
|
3824
|
+
return json4(201, { namespace, ...fault });
|
|
1658
3825
|
},
|
|
1659
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
3826
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
1660
3827
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
1661
3828
|
...rest,
|
|
1662
3829
|
secret: secret ? "(set)" : null
|
|
1663
3830
|
}))
|
|
1664
3831
|
}),
|
|
1665
3832
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
1666
|
-
const list = Array.isArray(body) ? body :
|
|
3833
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
1667
3834
|
if (!Array.isArray(list))
|
|
1668
|
-
return
|
|
3835
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
1669
3836
|
const parsed = [];
|
|
1670
3837
|
for (const each of list) {
|
|
1671
3838
|
const endpoint = parseEndpoint(each);
|
|
1672
3839
|
if (typeof endpoint === "string")
|
|
1673
|
-
return
|
|
3840
|
+
return adminError3(400, endpoint);
|
|
1674
3841
|
parsed.push(endpoint);
|
|
1675
3842
|
}
|
|
1676
3843
|
const set = hub.setEndpoints(namespace, parsed);
|
|
1677
|
-
return
|
|
3844
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
1678
3845
|
},
|
|
1679
3846
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
1680
3847
|
hub.setEndpoints(namespace, []);
|
|
1681
|
-
return
|
|
3848
|
+
return json4(200, { status: "ok" });
|
|
1682
3849
|
}
|
|
1683
3850
|
});
|
|
1684
3851
|
var parsePayload = (message2) => {
|
|
@@ -1733,8 +3900,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
1733
3900
|
this.name = "TypeError";
|
|
1734
3901
|
}
|
|
1735
3902
|
};
|
|
1736
|
-
var operationMatcher = (
|
|
1737
|
-
const matchers = listOperations(
|
|
3903
|
+
var operationMatcher = (document3) => {
|
|
3904
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
1738
3905
|
operationId: operation.operationId,
|
|
1739
3906
|
method: operation.method.toUpperCase(),
|
|
1740
3907
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -1743,6 +3910,7 @@ var operationMatcher = (document2) => {
|
|
|
1743
3910
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
1744
3911
|
};
|
|
1745
3912
|
var createRuntime = (options) => {
|
|
3913
|
+
assertAdminUi(options.adminUi);
|
|
1746
3914
|
const sqlite = bootSqlite(options.sqlite);
|
|
1747
3915
|
const clock = options.clock ?? createClock();
|
|
1748
3916
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -1828,10 +3996,10 @@ var createRuntime = (options) => {
|
|
|
1828
3996
|
const ensureBranch = (namespace, branch2, at) => {
|
|
1829
3997
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
1830
3998
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
1831
|
-
const
|
|
3999
|
+
const history2 = timeline(namespace);
|
|
1832
4000
|
if (branch2 === "main") {
|
|
1833
4001
|
if (at !== void 0) {
|
|
1834
|
-
const point =
|
|
4002
|
+
const point = history2.checkout("main", at);
|
|
1835
4003
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
1836
4004
|
captured.set(namespace, point.value.snapshot);
|
|
1837
4005
|
rng.setState(point.value.rngState);
|
|
@@ -1844,10 +4012,10 @@ var createRuntime = (options) => {
|
|
|
1844
4012
|
return namespace;
|
|
1845
4013
|
}
|
|
1846
4014
|
const storage = physicalBranch(namespace, branch2);
|
|
1847
|
-
if (!
|
|
4015
|
+
if (!history2.hasBranch(branch2)) {
|
|
1848
4016
|
if (at === void 0)
|
|
1849
|
-
|
|
1850
|
-
const point =
|
|
4017
|
+
history2.commit(capture(namespace));
|
|
4018
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
1851
4019
|
const branchRng = createRng(options.seed ?? 0);
|
|
1852
4020
|
if (point)
|
|
1853
4021
|
branchRng.setState(point.value.rngState);
|
|
@@ -1856,8 +4024,8 @@ var createRuntime = (options) => {
|
|
|
1856
4024
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1857
4025
|
if (point)
|
|
1858
4026
|
captured.set(storage, point.value.snapshot);
|
|
1859
|
-
} else if (at !== void 0 &&
|
|
1860
|
-
const point =
|
|
4027
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
4028
|
+
const point = history2.checkout(branch2, at);
|
|
1861
4029
|
if (!instances.has(storage)) {
|
|
1862
4030
|
const branchRng = createRng(options.seed ?? 0);
|
|
1863
4031
|
branchRng.setState(point.value.rngState);
|
|
@@ -1868,7 +4036,7 @@ var createRuntime = (options) => {
|
|
|
1868
4036
|
captured.set(storage, point.value.snapshot);
|
|
1869
4037
|
} else {
|
|
1870
4038
|
if (!instances.has(storage)) {
|
|
1871
|
-
const point =
|
|
4039
|
+
const point = history2.head(branch2);
|
|
1872
4040
|
const branchRng = createRng(options.seed ?? 0);
|
|
1873
4041
|
if (point)
|
|
1874
4042
|
branchRng.setState(point.value.rngState);
|
|
@@ -1892,8 +4060,8 @@ var createRuntime = (options) => {
|
|
|
1892
4060
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
1893
4061
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
1894
4062
|
const branchName = checkoutOptions.branch ?? "main";
|
|
1895
|
-
const
|
|
1896
|
-
const point =
|
|
4063
|
+
const history2 = timeline(namespace);
|
|
4064
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
1897
4065
|
const storage = ensureBranch(namespace, branchName);
|
|
1898
4066
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1899
4067
|
captured.set(storage, point.value.snapshot);
|
|
@@ -1943,12 +4111,25 @@ var createRuntime = (options) => {
|
|
|
1943
4111
|
instance(name);
|
|
1944
4112
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
1945
4113
|
captured.set(name, from);
|
|
1946
|
-
const
|
|
1947
|
-
if (
|
|
1948
|
-
|
|
4114
|
+
const history2 = timelines.get(name);
|
|
4115
|
+
if (history2)
|
|
4116
|
+
history2.commit(capture(name), { branch: "main" });
|
|
1949
4117
|
else
|
|
1950
4118
|
timeline(name);
|
|
1951
4119
|
};
|
|
4120
|
+
const declarationsFor = (namespace) => {
|
|
4121
|
+
const declared = options.state;
|
|
4122
|
+
if (!declared)
|
|
4123
|
+
return [];
|
|
4124
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
4125
|
+
};
|
|
4126
|
+
const stateScope = (namespace) => ({
|
|
4127
|
+
sqlite,
|
|
4128
|
+
namespace,
|
|
4129
|
+
storageNamespace: storageNamespace(namespace),
|
|
4130
|
+
root: instance(namespace),
|
|
4131
|
+
declarations: declarationsFor(namespace)
|
|
4132
|
+
});
|
|
1952
4133
|
const runtime = {
|
|
1953
4134
|
name: options.name,
|
|
1954
4135
|
sqlite,
|
|
@@ -1987,6 +4168,7 @@ var createRuntime = (options) => {
|
|
|
1987
4168
|
branch,
|
|
1988
4169
|
checkout,
|
|
1989
4170
|
timeline,
|
|
4171
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
1990
4172
|
fetch: async (incoming) => {
|
|
1991
4173
|
let request = incoming;
|
|
1992
4174
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -2160,10 +4342,10 @@ var createRuntime = (options) => {
|
|
|
2160
4342
|
},
|
|
2161
4343
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
2162
4344
|
inspect: (name) => {
|
|
2163
|
-
const
|
|
4345
|
+
const history2 = timeline(name);
|
|
2164
4346
|
return {
|
|
2165
|
-
branches:
|
|
2166
|
-
checkpoints:
|
|
4347
|
+
branches: history2.branches(),
|
|
4348
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
2167
4349
|
id,
|
|
2168
4350
|
branch: branchName,
|
|
2169
4351
|
parent,
|
|
@@ -2178,13 +4360,22 @@ var createRuntime = (options) => {
|
|
|
2178
4360
|
} : {},
|
|
2179
4361
|
routes: {
|
|
2180
4362
|
...credentialRoutes(credentials),
|
|
2181
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
2182
4363
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
2183
|
-
...options.admin?.(runtime) ?? {}
|
|
4364
|
+
...options.admin?.(runtime) ?? {},
|
|
4365
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4366
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4367
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4368
|
+
...stateAdminRoutes({
|
|
4369
|
+
open: stateScope,
|
|
4370
|
+
afterWrite: (namespace) => {
|
|
4371
|
+
checkpoint(namespace, "main");
|
|
4372
|
+
}
|
|
4373
|
+
}),
|
|
4374
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
2184
4375
|
},
|
|
2185
4376
|
adminKey: options.adminKey
|
|
2186
4377
|
});
|
|
2187
|
-
return runtime;
|
|
4378
|
+
return defineMock(runtime);
|
|
2188
4379
|
};
|
|
2189
4380
|
var mutableResponse = (response) => {
|
|
2190
4381
|
try {
|
|
@@ -2248,9 +4439,12 @@ var credentialRoutes = (registry) => ({
|
|
|
2248
4439
|
}
|
|
2249
4440
|
});
|
|
2250
4441
|
var presetRoutes = (presets, runtime) => ({
|
|
2251
|
-
"GET /faults/presets": () =>
|
|
2252
|
-
|
|
2253
|
-
|
|
4442
|
+
"GET /faults/presets": () => {
|
|
4443
|
+
const body = {
|
|
4444
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4445
|
+
};
|
|
4446
|
+
return adminJson(200, body);
|
|
4447
|
+
},
|
|
2254
4448
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
2255
4449
|
const name = params.name;
|
|
2256
4450
|
if (!presets[name])
|
|
@@ -2426,7 +4620,7 @@ var labElement = (labId, element) => ({
|
|
|
2426
4620
|
});
|
|
2427
4621
|
|
|
2428
4622
|
// src/generated/openapi.ts
|
|
2429
|
-
var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Optimal DX partner API (Mockingbird subset)","description":"Stateful mock of the Optimal DX (ODX) partner API our backend calls: partner labs and their\\nbiomarker elements, practice patients (create, update, delete, partner link, search), lab\\nresults (structured and HL7 v2 ORU imports), the Functional Health Report (JSON or PDF), and\\nwebhook registrations whose signing keys verify the PatientTest webhooks the mock posts.\\nODX publishes no spec; the contract is hand-authored from our consumer's wire shapes. The\\nvendor was retired 2026-07-22 but queue paths still call it while the consumer app's PDF flag (\`acme-pdf-enabled\`) is off.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from optimal.dx.service.ts / optimal.dx.types.ts, the webhook guard and DTO (odx-signature.guard.ts, odx-webhook-data.dto.ts) and the QA harness (packages/qa odx-client.ts)."}},"servers":[{"url":"https://odxinstanceresource.azure-api.net/{partner}","description":"The partner segment is your account's slug.","variables":{"partner":{"default":"acme"}}}],"security":[{"apiKey":[]}],"paths":{"/v1/partner/labs":{"get":{"operationId":"ListPartnerLabs","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Labs this partner can import from","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Lab"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/elements/{labId}":{"parameters":[{"name":"labId","in":"path","required":true,"schema":{"type":"string","enum":["1","2","3","999"]}}],"get":{"operationId":"ListElements","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The lab's biomarker elements (with the codes HL7 OBX-3 is mapped by)","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/LabElement"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient":{"parameters":[{"$ref":"#/components/parameters/PracticeId"}],"post":{"operationId":"CreatePatient","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientRequest"}}}},"responses":{"200":{"description":"Created patient","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Patient"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/practice/{practiceId}/patient/{patientId}":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"put":{"operationId":"UpdatePatient","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientRequest"}}}},"responses":{"200":{"description":"Updated patient","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Patient"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"operationId":"DeletePatient","description":"Used by the QA harness teardown (via the send-odx-api-request dev tool).","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"204":{"description":"Deleted"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/partner/{localUserId}":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"},{"name":"localUserId","in":"path","required":true,"description":"Our user id, stored as the patient's partner (external) id.","schema":{"type":"string","pattern":"^[0-9]{1,9}$"}}],"post":{"operationId":"LinkPartnerUser","description":"Our client posts the literal body \`false\`.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"boolean"}}}},"responses":{"200":{"description":"Linked","content":{"application/json":{"schema":{"type":"boolean"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patients":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"name":"email","in":"query","schema":{"type":"string","enum":["ada@example.com","nobody@example.com"]}},{"name":"firstName","in":"query","schema":{"type":"string","enum":["Ada","Grace"]}},{"name":"lastName","in":"query","schema":{"type":"string","enum":["Lovelace","Hopper"]}},{"name":"dateOfBirth","in":"query","schema":{"type":"string","enum":["1985-12-10","1906-12-09"]}}],"get":{"operationId":"ListPatients","description":"All patients, or a search when any filter is given (404 when nothing matches).","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Matching patients","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Patient"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/testresults":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"post":{"operationId":"CreateTestResults","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestResultsRequest"}}}},"responses":{"200":{"description":"The imported patient test","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientTest"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/test":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"post":{"operationId":"CreatePatientTest","description":"Import an HL7 v2 ORU^R01 message; OBX-3 codes map to elements by their elementReferences.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Hl7Request"}}}},"responses":{"200":{"description":"The imported patient test","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientTest"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/test/{patientTestId}":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"},{"name":"patientTestId","in":"path","required":true,"schema":{"type":"string","description":"Ids are assigned sequentially from 700001 (parity walks reuse them).","enum":["700001","700002","999999"]}}],"put":{"operationId":"UpdatePatientTest","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Hl7Request"}}}},"responses":{"200":{"description":"The re-imported patient test","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientTest"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/tests":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"get":{"operationId":"ListPatientTests","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The patient's tests, oldest first","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/PatientTest"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/reports/FunctionalHealthReport":{"post":{"operationId":"GenerateFunctionalHealthReport","description":"\`outputType: Json\` answers the report as JSON; \`Pdf\` answers application/pdf bytes.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReportRequest"}}}},"responses":{"200":{"description":"The report","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Report"}},"application/pdf":{"schema":{"type":"string","format":"binary"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/webhooks":{"get":{"operationId":"ListWebhooks","description":"Our webhook guard calls this on every inbound webhook to fetch the signing key.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Registered webhooks, with their signing keys","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Webhook"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/webhook":{"post":{"operationId":"RegisterWebhook","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookRequest"}}}},"responses":{"200":{"description":"Registered","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Webhook"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/webhook/{partnerWebhookId}":{"parameters":[{"name":"partnerWebhookId","in":"path","required":true,"schema":{"type":"string","description":"Ids are assigned sequentially from 1.","enum":["1","2","999999"]}}],"put":{"operationId":"UpdateWebhook","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookRequest"}}}},"responses":{"200":{"description":"Updated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Webhook"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}},"components":{"securitySchemes":{"apiKey":{"type":"apiKey","in":"header","name":"ApiKey"}},"parameters":{"PracticeId":{"name":"practiceId","in":"path","required":true,"description":"OPTIMAL_PRACTICE_ID. Parity walks use one fixed practice.","schema":{"type":"string","enum":["3f0c0c43-7d2b-4b8e-9a50-9c1f0c6c0001"]}},"PatientId":{"name":"patientId","in":"path","required":true,"schema":{"type":"string","description":"Ids are assigned sequentially from 100001 (parity walks reuse them).","enum":["100001","100002","999999"]}}},"responses":{"Unauthorized":{"description":"Missing or invalid ApiKey (Azure API Management's answer)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Unknown patient, test, lab or webhook","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"ValidationProblem":{"description":"ASP.NET validation problem details","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","description":"\`{Message}\` (ODX), \`{statusCode, message}\` (API Management) or ASP.NET problem details.","properties":{"Message":{"type":"string"},"message":{"type":"string"},"statusCode":{"type":"integer"},"type":{"type":"string"},"title":{"type":"string"},"status":{"type":"integer"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}},"Lab":{"type":"object","required":["labId","name"],"properties":{"labId":{"type":"integer"},"name":{"type":"string"},"isCurrentLab":{"type":"boolean"}}},"LabElement":{"type":"object","required":["labId","elementId","elementName","elementReferences"],"properties":{"labId":{"type":"integer"},"elementId":{"type":"integer"},"elementName":{"type":"string"},"elementGenderType":{"type":"string"},"cuUnit":{"type":"string"},"siUnit":{"type":"string"},"cuToSiConversionFactor":{"type":"number"},"elementReferences":{"type":"array","items":{"type":"object","required":["elementCode","elementName"],"properties":{"elementCode":{"type":"string"},"elementName":{"type":"string"}}}}}},"PatientRequest":{"type":"object","required":["firstName","lastName","gender","email"],"properties":{"firstName":{"type":"string","minLength":1,"maxLength":60,"enum":["Ada","Grace","Katherine"]},"lastName":{"type":"string","minLength":1,"maxLength":60,"enum":["Lovelace","Hopper","Johnson"]},"nickname":{"type":["string","null"],"maxLength":60},"dateOfBirth":{"type":["string","null"],"enum":["1985-12-10","1906-12-09",null]},"gender":{"type":"string","enum":["Male","Female"]},"email":{"type":"string","enum":["ada@example.com","grace@example.com"]},"userId":{"type":"string","maxLength":40},"workspaceId":{"type":"integer","minimum":0,"maximum":10}}},"Patient":{"type":"object","required":["patientId","practiceId","firstName","lastName","gender","email","createdDate","lastUpdatedDate"],"properties":{"patientId":{"type":"integer"},"practiceId":{"type":"string"},"createdDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"lastUpdatedDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"userTitle":{"type":["string","null"]},"userFirstName":{"type":["string","null"]},"userLastName":{"type":["string","null"]},"firstName":{"type":"string"},"lastName":{"type":"string"},"nickname":{"type":["string","null"]},"dateOfBirth":{"type":["string","null"]},"gender":{"type":"string"},"homePhone":{"type":["string","null"]},"workPhone":{"type":["string","null"]},"mobile":{"type":["string","null"]},"email":{"type":"string"},"address":{"type":["string","null"]},"address2":{"type":["string","null"]},"address3":{"type":["string","null"]},"city":{"type":["string","null"]},"province":{"type":["string","null"]},"postalCode":{"type":["string","null"]},"country":{"type":["string","null"]},"userId":{"type":["string","null"]},"workspaceId":{"type":"integer"}}},"TestResultsRequest":{"type":"object","required":["labProfileId","labId","testDate","unitType","results"],"properties":{"labProfileId":{"type":"integer","enum":[1,2]},"labId":{"type":"string","enum":["1","2"]},"testDate":{"type":"string","enum":["2025-01-15T00:00:00.000Z","2025-06-15T00:00:00.000Z"]},"unitType":{"type":"string","enum":["ConventionalUS","SI"]},"userId":{"type":"string","maxLength":40},"menstrualPhase":{"type":"string","enum":["Unknown","Follicular","Ovulation","Luteal","PostMenopausal"]},"isFasting":{"type":"boolean"},"results":{"type":"array","maxItems":5,"items":{"type":"object","required":["elementId"],"properties":{"elementId":{"type":"integer","enum":[494,496,506,537,999]},"value":{"type":"number","minimum":0,"maximum":500},"comparison":{"type":["string","null"],"enum":["<",">","",null]},"observationDateTime":{"type":"string","maxLength":40}}}}}},"Hl7Request":{"type":"object","required":["labProfileId","labId","testDate","unitType","hl7"],"properties":{"labProfileId":{"type":"integer","enum":[1,2]},"labId":{"type":"integer","enum":[1,2,999]},"testDate":{"type":"string","enum":["2025-01-15T00:00:00.000Z","2025-06-15T00:00:00.000Z"]},"unitType":{"type":"string","enum":["ConventionalUS","SI"]},"userId":{"type":"string","maxLength":40},"externalReference":{"type":["string","null"],"maxLength":60},"externalMessageControlId":{"type":["string","null"],"maxLength":60},"externalPatientTestId":{"type":["string","null"],"maxLength":60},"menstrualPhase":{"type":"string","enum":["Unknown","Follicular","Ovulation","Luteal","PostMenopausal"]},"isFasting":{"type":"boolean"},"hl7":{"type":"string","enum":["MSH|^~\\\\&|LAB|AHA|ACME|ACME|20250115000000||ORU^R01|BL-001|P|2.3\\rPID|1||E2E-1||Test^Patient||19800101|M\\rOBR|1|||^^^Acme|||20250115\\rOBX|1|NM|1751-7^Albumin||4.2|g/dL|3.5-5.5|N|||F|||20250115\\rOBX|2|NM|2160-0^Creatinine||1.1|mg/dL|0.6-1.3|N|||F|||20250115\\r","MSH|^~\\\\&|LAB|AHA|ACME|ACME|20250615000000||ORU^R01|IM-001|P|2.3\\rPID|1||E2E-1||Test^Patient||19800101|F\\rOBR|1|||^^^Acme|||20250615\\rOBX|1|NM|30522-7^hs-CRP||<0.2|mg/L|0-3|N|||F|||20250615\\rOBX|2|NM|ZZZ-1^Unmapped Marker||12|U/L||N|||F|||20250615\\r","not an hl7 message"]}}},"PatientTestElement":{"type":"object","required":["elementId","elementName","unit","comparison"],"properties":{"elementValue":{"type":"number"},"comparison":{"type":"string"},"unit":{"type":"string"},"elementId":{"type":"integer"},"elementName":{"type":"string"},"optimalRangeLow":{"type":"number"},"optimalRangeHigh":{"type":"number"},"standardRangeLow":{"type":"number"},"standardRangeHigh":{"type":"number"}}},"PatientTest":{"type":"object","required":["patientTestId","patientId","labProfileId","testDate","unitType","createdDate","lastUpdatedDate","practiceId","labId","results","menstrualPhase","isFasting"],"properties":{"patientTestId":{"type":"integer"},"patientId":{"type":"integer"},"labProfileId":{"type":"integer"},"testDate":{"type":"string"},"unitType":{"type":"string"},"createdDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"lastUpdatedDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"userId":{"type":["string","null"]},"practiceId":{"type":"string"},"labId":{"type":"integer"},"externalReference":{"type":["string","null"]},"externalMessageControlId":{"type":["string","null"]},"externalPatientTestId":{"type":["string","null"]},"results":{"type":"array","items":{"$ref":"#/components/schemas/PatientTestElement"}},"importLogs":{"type":["array","null"],"items":{"type":"object","properties":{"observationIdentifier":{"type":["string","null"]},"observationIdentifierText":{"type":["string","null"]},"status":{"type":["string","null"]}}}},"menstrualPhase":{"type":"string"},"isFasting":{"type":"boolean"}}},"ReportRequest":{"type":"object","required":["patientTestId","patientId","outputType"],"properties":{"patientTestId":{"type":"integer","enum":[700001,999999]},"patientId":{"type":"integer","enum":[100001,999999]},"unitType":{"type":"string","enum":["ConventionalUS"]},"practiceId":{"type":"string","enum":["3f0c0c43-7d2b-4b8e-9a50-9c1f0c6c0001"]},"outputType":{"type":"string","enum":["Json","Pdf","Xml"]},"theme":{"type":"string","enum":["Acme"]},"themeId":{"type":"integer","enum":[21]},"recipientId":{"type":"string","enum":["15","0"]},"cultureCode":{"type":"string","enum":["en-US"]},"reports":{"type":"array","maxItems":3,"items":{"type":"string","enum":["1","2","3"]}},"addMarginForBinding":{"type":"boolean"},"userId":{"type":"string","maxLength":40}}},"Report":{"type":"object","required":["metadata","labs","elements","sections"],"properties":{"metadata":{"type":"object","required":["practiceId","patientId","patientTestId","recipient","reports","unitType"],"properties":{"practiceId":{"type":"string"},"patientId":{"type":"integer"},"patientTestId":{"type":"integer"},"recipient":{"type":"string"},"reports":{"type":"array","items":{"type":"string"}},"unitType":{"type":"string"}}},"labs":{"type":"array","items":{"$ref":"#/components/schemas/Lab"}},"elements":{"type":"array","items":{"$ref":"#/components/schemas/PatientTestElement"}},"sections":{"type":"array","items":{"type":"object","required":["name","reports"],"properties":{"name":{"type":"string"},"reports":{"type":"array","items":{"type":"object","required":["reportId","name","content"],"properties":{"reportId":{"type":"integer"},"name":{"type":"string"},"content":{"type":"object"}}}}}}}}},"WebhookRequest":{"type":"object","required":["entityEvents","webhookUrl"],"properties":{"entityEvents":{"type":"object","required":["PatientTest"],"properties":{"PatientTest":{"type":"array","minItems":1,"items":{"type":"string","enum":["Created","Updated","Deleted"]}}}},"webhookUrl":{"type":"string","enum":["https://backend.example.test/odx/webhook","https://staging.example.test/odx/webhook"]}}},"Webhook":{"type":"object","required":["partnerWebhookId","signingKey","createDate","entityEvents","webhookUrl"],"properties":{"partnerWebhookId":{"type":"integer"},"signingKey":{"type":"string","x-mockingbird-volatile":{"kind":"token"}},"createDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"entityEvents":{"type":"object","properties":{"PatientTest":{"type":"array","items":{"type":"string"}}}},"webhookUrl":{"type":"string"}}}}}}`);
|
|
4623
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Optimal DX partner API (Mockingbird subset)","description":"Stateful mock of the Optimal DX (ODX) partner API our backend calls: partner labs and their\\nbiomarker elements, practice patients (create, update, delete, partner link, search), lab\\nresults (structured and HL7 v2 ORU imports), the Functional Health Report (JSON or PDF), and\\nwebhook registrations whose signing keys verify the PatientTest webhooks the mock posts.\\nODX publishes no spec; the contract is hand-authored from our consumer's wire shapes. The\\nvendor was retired 2026-07-22 but queue paths still call it while the consumer app's PDF flag (\`acme-pdf-enabled\`) is off.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from optimal.dx.service.ts / optimal.dx.types.ts, the webhook guard and DTO (odx-signature.guard.ts, odx-webhook-data.dto.ts) and the QA harness (packages/qa odx-client.ts)."}},"servers":[{"url":"https://odxinstanceresource.azure-api.net/{partner}","description":"The partner segment is your account's slug.","variables":{"partner":{"default":"acme"}}}],"security":[{"apiKey":[]}],"paths":{"/v1/partner/labs":{"get":{"operationId":"ListPartnerLabs","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Labs this partner can import from","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Lab"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/elements/{labId}":{"parameters":[{"name":"labId","in":"path","required":true,"schema":{"type":"string","enum":["1","2","3","999"]}}],"get":{"operationId":"ListElements","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The lab's biomarker elements (with the codes HL7 OBX-3 is mapped by)","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/LabElement"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient":{"parameters":[{"$ref":"#/components/parameters/PracticeId"}],"post":{"operationId":"CreatePatient","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientRequest"}}}},"responses":{"200":{"description":"Created patient","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Patient"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/practice/{practiceId}/patient/{patientId}":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"put":{"operationId":"UpdatePatient","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientRequest"}}}},"responses":{"200":{"description":"Updated patient","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Patient"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}},"delete":{"operationId":"DeletePatient","description":"Used by the QA harness teardown (via the send-odx-api-request dev tool).","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"204":{"description":"Deleted"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/partner/{localUserId}":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"},{"name":"localUserId","in":"path","required":true,"description":"Our user id, stored as the patient's partner (external) id.","schema":{"type":"string","pattern":"^[0-9]{1,9}$"}}],"post":{"operationId":"LinkPartnerUser","description":"Our client posts the literal body \`false\`.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"boolean"}}}},"responses":{"200":{"description":"Linked","content":{"application/json":{"schema":{"type":"boolean"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patients":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"name":"email","in":"query","schema":{"type":"string","enum":["ada@example.com","nobody@example.com"]}},{"name":"firstName","in":"query","schema":{"type":"string","enum":["Ada","Grace"]}},{"name":"lastName","in":"query","schema":{"type":"string","enum":["Lovelace","Hopper"]}},{"name":"dateOfBirth","in":"query","schema":{"type":"string","enum":["1985-12-10","1906-12-09"]}}],"get":{"operationId":"ListPatients","description":"All patients, or a search when any filter is given (404 when nothing matches).","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Matching patients","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Patient"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/testresults":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"post":{"operationId":"CreateTestResults","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TestResultsRequest"}}}},"responses":{"200":{"description":"The imported patient test","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientTest"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/test":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"post":{"operationId":"CreatePatientTest","description":"Import an HL7 v2 ORU^R01 message; OBX-3 codes map to elements by their elementReferences.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Hl7Request"}}}},"responses":{"200":{"description":"The imported patient test","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientTest"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/test/{patientTestId}":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"},{"name":"patientTestId","in":"path","required":true,"schema":{"type":"string","description":"Ids are assigned sequentially from 700001 (parity walks reuse them).","enum":["700001","700002","999999"]}}],"put":{"operationId":"UpdatePatientTest","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Hl7Request"}}}},"responses":{"200":{"description":"The re-imported patient test","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatientTest"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/practice/{practiceId}/patient/{patientId}/tests":{"parameters":[{"$ref":"#/components/parameters/PracticeId"},{"$ref":"#/components/parameters/PatientId"}],"get":{"operationId":"ListPatientTests","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"The patient's tests, oldest first","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/PatientTest"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/reports/FunctionalHealthReport":{"post":{"operationId":"GenerateFunctionalHealthReport","description":"\`outputType: Json\` answers the report as JSON; \`Pdf\` answers application/pdf bytes.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ReportRequest"}}}},"responses":{"200":{"description":"The report","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Report"}},"application/pdf":{"schema":{"type":"string","format":"binary"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}},"/v1/webhooks":{"get":{"operationId":"ListWebhooks","description":"Our webhook guard calls this on every inbound webhook to fetch the signing key.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Registered webhooks, with their signing keys","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Webhook"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/webhook":{"post":{"operationId":"RegisterWebhook","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookRequest"}}}},"responses":{"200":{"description":"Registered","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Webhook"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/v1/webhook/{partnerWebhookId}":{"parameters":[{"name":"partnerWebhookId","in":"path","required":true,"schema":{"type":"string","description":"Ids are assigned sequentially from 1.","enum":["1","2","999999"]}}],"put":{"operationId":"UpdateWebhook","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookRequest"}}}},"responses":{"200":{"description":"Updated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Webhook"}}}},"400":{"$ref":"#/components/responses/ValidationProblem"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}},"components":{"securitySchemes":{"apiKey":{"type":"apiKey","in":"header","name":"ApiKey"}},"parameters":{"PracticeId":{"name":"practiceId","in":"path","required":true,"description":"OPTIMAL_PRACTICE_ID. Parity walks use one fixed practice.","schema":{"type":"string","enum":["3f0c0c43-7d2b-4b8e-9a50-9c1f0c6c0001"]}},"PatientId":{"name":"patientId","in":"path","required":true,"schema":{"type":"string","description":"Ids are assigned sequentially from 100001 (parity walks reuse them).","enum":["100001","100002","999999"]}}},"responses":{"Unauthorized":{"description":"Missing or invalid ApiKey (Azure API Management's answer)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Unknown patient, test, lab or webhook","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"ValidationProblem":{"description":"ASP.NET validation problem details","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","description":"\`{Message}\` (ODX), \`{statusCode, message}\` (API Management) or ASP.NET problem details.","properties":{"Message":{"type":"string"},"message":{"type":"string"},"statusCode":{"type":"integer"},"type":{"type":"string"},"title":{"type":"string"},"status":{"type":"integer"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}},"Lab":{"type":"object","required":["labId","name"],"properties":{"labId":{"type":"integer"},"name":{"type":"string"},"isCurrentLab":{"type":"boolean"}}},"LabElement":{"type":"object","required":["labId","elementId","elementName","elementReferences"],"properties":{"labId":{"type":"integer"},"elementId":{"type":"integer"},"elementName":{"type":"string"},"elementGenderType":{"type":"string"},"cuUnit":{"type":"string"},"siUnit":{"type":"string"},"cuToSiConversionFactor":{"type":"number"},"elementReferences":{"type":"array","items":{"type":"object","required":["elementCode","elementName"],"properties":{"elementCode":{"type":"string"},"elementName":{"type":"string"}}}}}},"PatientRequest":{"type":"object","required":["firstName","lastName","gender","email"],"properties":{"firstName":{"type":"string","minLength":1,"maxLength":60,"enum":["Ada","Grace","Katherine"]},"lastName":{"type":"string","minLength":1,"maxLength":60,"enum":["Lovelace","Hopper","Johnson"]},"nickname":{"type":["string","null"],"maxLength":60},"dateOfBirth":{"type":["string","null"],"enum":["1985-12-10","1906-12-09",null]},"gender":{"type":"string","enum":["Male","Female"]},"email":{"type":"string","enum":["ada@example.com","grace@example.com"]},"userId":{"type":"string","maxLength":40},"workspaceId":{"type":"integer","minimum":0,"maximum":10}}},"Patient":{"type":"object","required":["patientId","practiceId","firstName","lastName","gender","email","createdDate","lastUpdatedDate"],"properties":{"patientId":{"type":"integer"},"practiceId":{"type":"string"},"createdDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"lastUpdatedDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"userTitle":{"type":["string","null"]},"userFirstName":{"type":["string","null"]},"userLastName":{"type":["string","null"]},"firstName":{"type":"string"},"lastName":{"type":"string"},"nickname":{"type":["string","null"]},"dateOfBirth":{"type":["string","null"]},"gender":{"type":"string"},"homePhone":{"type":["string","null"]},"workPhone":{"type":["string","null"]},"mobile":{"type":["string","null"]},"email":{"type":"string"},"address":{"type":["string","null"]},"address2":{"type":["string","null"]},"address3":{"type":["string","null"]},"city":{"type":["string","null"]},"province":{"type":["string","null"]},"postalCode":{"type":["string","null"]},"country":{"type":["string","null"]},"userId":{"type":["string","null"]},"workspaceId":{"type":"integer"}}},"TestResultsRequest":{"type":"object","required":["labProfileId","labId","testDate","unitType","results"],"properties":{"labProfileId":{"type":"integer","enum":[1,2]},"labId":{"type":"string","enum":["1","2"]},"testDate":{"type":"string","enum":["2025-01-15T00:00:00.000Z","2025-06-15T00:00:00.000Z"]},"unitType":{"type":"string","enum":["ConventionalUS","SI"]},"userId":{"type":"string","maxLength":40},"menstrualPhase":{"type":"string","enum":["Unknown","Follicular","Ovulation","Luteal","PostMenopausal"]},"isFasting":{"type":"boolean"},"results":{"type":"array","maxItems":5,"items":{"type":"object","required":["elementId"],"properties":{"elementId":{"type":"integer","enum":[494,496,506,537,999]},"value":{"type":"number","minimum":0,"maximum":500},"comparison":{"type":["string","null"],"enum":["<",">","",null]},"observationDateTime":{"type":"string","maxLength":40}}}}}},"Hl7Request":{"type":"object","required":["labProfileId","labId","testDate","unitType","hl7"],"properties":{"labProfileId":{"type":"integer","enum":[1,2]},"labId":{"type":"integer","enum":[1,2,999]},"testDate":{"type":"string","enum":["2025-01-15T00:00:00.000Z","2025-06-15T00:00:00.000Z"]},"unitType":{"type":"string","enum":["ConventionalUS","SI"]},"userId":{"type":"string","maxLength":40},"externalReference":{"type":["string","null"],"maxLength":60},"externalMessageControlId":{"type":["string","null"],"maxLength":60},"externalPatientTestId":{"type":["string","null"],"maxLength":60},"menstrualPhase":{"type":"string","enum":["Unknown","Follicular","Ovulation","Luteal","PostMenopausal"]},"isFasting":{"type":"boolean"},"hl7":{"type":"string","enum":["MSH|^~\\\\&|LAB|AHA|ACME|ACME|20250115000000||ORU^R01|BL-001|P|2.3\\rPID|1||E2E-1||Test^Patient||19800101|M\\rOBR|1|||^^^Acme|||20250115\\rOBX|1|NM|1751-7^Albumin||4.2|g/dL|3.5-5.5|N|||F|||20250115\\rOBX|2|NM|2160-0^Creatinine||1.1|mg/dL|0.6-1.3|N|||F|||20250115\\r","MSH|^~\\\\&|LAB|AHA|ACME|ACME|20250615000000||ORU^R01|IM-001|P|2.3\\rPID|1||E2E-1||Test^Patient||19800101|F\\rOBR|1|||^^^Acme|||20250615\\rOBX|1|NM|30522-7^hs-CRP||<0.2|mg/L|0-3|N|||F|||20250615\\rOBX|2|NM|ZZZ-1^Unmapped Marker||12|U/L||N|||F|||20250615\\r","not an hl7 message"]}}},"PatientTestElement":{"type":"object","required":["elementId","elementName","unit","comparison"],"properties":{"elementValue":{"type":"number"},"comparison":{"type":"string"},"unit":{"type":"string"},"elementId":{"type":"integer"},"elementName":{"type":"string"},"optimalRangeLow":{"type":"number"},"optimalRangeHigh":{"type":"number"},"standardRangeLow":{"type":"number"},"standardRangeHigh":{"type":"number"}}},"PatientTest":{"type":"object","required":["patientTestId","patientId","labProfileId","testDate","unitType","createdDate","lastUpdatedDate","practiceId","labId","results","menstrualPhase","isFasting"],"properties":{"patientTestId":{"type":"integer"},"patientId":{"type":"integer"},"labProfileId":{"type":"integer"},"testDate":{"type":"string"},"unitType":{"type":"string"},"createdDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"lastUpdatedDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"userId":{"type":["string","null"]},"practiceId":{"type":"string"},"labId":{"type":"integer"},"externalReference":{"type":["string","null"]},"externalMessageControlId":{"type":["string","null"]},"externalPatientTestId":{"type":["string","null"]},"results":{"type":"array","items":{"$ref":"#/components/schemas/PatientTestElement"}},"importLogs":{"type":["array","null"],"items":{"type":"object","properties":{"observationIdentifier":{"type":["string","null"]},"observationIdentifierText":{"type":["string","null"]},"status":{"type":["string","null"]}}}},"menstrualPhase":{"type":"string"},"isFasting":{"type":"boolean"}}},"ReportRequest":{"type":"object","required":["patientTestId","patientId","outputType"],"properties":{"patientTestId":{"type":"integer","enum":[700001,999999]},"patientId":{"type":"integer","enum":[100001,999999]},"unitType":{"type":"string","enum":["ConventionalUS"]},"practiceId":{"type":"string","enum":["3f0c0c43-7d2b-4b8e-9a50-9c1f0c6c0001"]},"outputType":{"type":"string","enum":["Json","Pdf","Xml"]},"theme":{"type":"string","enum":["Acme"]},"themeId":{"type":"integer","enum":[21]},"recipientId":{"type":"string","enum":["15","0"]},"cultureCode":{"type":"string","enum":["en-US"]},"reports":{"type":"array","maxItems":3,"items":{"type":"string","enum":["1","2","3"]}},"addMarginForBinding":{"type":"boolean"},"userId":{"type":"string","maxLength":40}}},"Report":{"type":"object","required":["metadata","labs","elements","sections"],"properties":{"metadata":{"type":"object","required":["practiceId","patientId","patientTestId","recipient","reports","unitType"],"properties":{"practiceId":{"type":"string"},"patientId":{"type":"integer"},"patientTestId":{"type":"integer"},"recipient":{"type":"string"},"reports":{"type":"array","items":{"type":"string"}},"unitType":{"type":"string"}}},"labs":{"type":"array","items":{"$ref":"#/components/schemas/Lab"}},"elements":{"type":"array","items":{"$ref":"#/components/schemas/PatientTestElement"}},"sections":{"type":"array","items":{"type":"object","required":["name","reports"],"properties":{"name":{"type":"string"},"reports":{"type":"array","items":{"type":"object","required":["reportId","name","content"],"properties":{"reportId":{"type":"integer"},"name":{"type":"string"},"content":{"type":"object"}}}}}}}}},"WebhookRequest":{"type":"object","required":["entityEvents","webhookUrl"],"properties":{"entityEvents":{"type":"object","required":["PatientTest"],"properties":{"PatientTest":{"type":"array","minItems":1,"items":{"type":"string","enum":["Created","Updated","Deleted"]}}}},"webhookUrl":{"type":"string","enum":["https://backend.example.test/odx/webhook","https://staging.example.test/odx/webhook"]}}},"Webhook":{"type":"object","required":["partnerWebhookId","signingKey","createDate","entityEvents","webhookUrl"],"properties":{"partnerWebhookId":{"type":"integer"},"signingKey":{"type":"string","x-mockingbird-volatile":{"kind":"token"}},"createDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"entityEvents":{"type":"object","properties":{"PatientTest":{"type":"array","items":{"type":"string"}}}},"webhookUrl":{"type":"string"}}}}}}`);
|
|
2430
4624
|
var operationIds = ["ListPartnerLabs", "ListElements", "CreatePatient", "UpdatePatient", "DeletePatient", "LinkPartnerUser", "ListPatients", "CreateTestResults", "CreatePatientTest", "UpdatePatientTest", "ListPatientTests", "GenerateFunctionalHealthReport", "ListWebhooks", "RegisterWebhook", "UpdateWebhook"];
|
|
2431
4625
|
var supportedOperationIds = ["ListPartnerLabs", "ListElements", "CreatePatient", "UpdatePatient", "DeletePatient", "LinkPartnerUser", "ListPatients", "CreateTestResults", "CreatePatientTest", "UpdatePatientTest", "ListPatientTests", "GenerateFunctionalHealthReport", "ListWebhooks", "RegisterWebhook", "UpdateWebhook"];
|
|
2432
4626
|
|
|
@@ -2762,41 +4956,41 @@ var ODX_PRESETS = {
|
|
|
2762
4956
|
webhook: { mode: "drop" }
|
|
2763
4957
|
}
|
|
2764
4958
|
};
|
|
2765
|
-
var
|
|
2766
|
-
var
|
|
2767
|
-
var
|
|
4959
|
+
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
4960
|
+
var adminError4 = (status, message2) => json5(status, { error: { type: "mockingbird_admin", message: message2 } });
|
|
4961
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2768
4962
|
var EVENTS = ["Created", "Updated", "Deleted"];
|
|
2769
4963
|
var SIGNATURES = ["valid", "short", "bad"];
|
|
2770
4964
|
var adminRoutes = (runtime) => ({
|
|
2771
|
-
"GET /patients": ({ namespace }) =>
|
|
2772
|
-
"GET /tests": ({ namespace }) =>
|
|
4965
|
+
"GET /patients": ({ namespace }) => json5(200, { patients: runtime.instance(namespace).patients() }),
|
|
4966
|
+
"GET /tests": ({ namespace }) => json5(200, {
|
|
2773
4967
|
// Results are the mock's own output; no HL7 (PHI) is ever stored.
|
|
2774
4968
|
tests: runtime.instance(namespace).tests()
|
|
2775
4969
|
}),
|
|
2776
4970
|
"POST /tests/:id/webhook": ({ params, body, namespace }) => {
|
|
2777
|
-
const input =
|
|
4971
|
+
const input = isRecord6(body) ? body : {};
|
|
2778
4972
|
const eventType = String(input.eventType ?? "Updated");
|
|
2779
4973
|
const signature = String(input.signature ?? "valid");
|
|
2780
4974
|
if (!EVENTS.includes(eventType))
|
|
2781
|
-
return
|
|
4975
|
+
return adminError4(400, "eventType must be Created, Updated or Deleted");
|
|
2782
4976
|
if (!SIGNATURES.includes(signature))
|
|
2783
|
-
return
|
|
4977
|
+
return adminError4(400, "signature must be valid, short or bad");
|
|
2784
4978
|
const event = runtime.instance(namespace).emit(params.id, eventType, signature);
|
|
2785
|
-
return event ?
|
|
4979
|
+
return event ? json5(202, event) : adminError4(404, `no patient test ${params.id}`);
|
|
2786
4980
|
},
|
|
2787
4981
|
"DELETE /tests/:id": ({ params, namespace }) => {
|
|
2788
4982
|
const event = runtime.instance(namespace).emit(params.id, "Deleted");
|
|
2789
|
-
return event ?
|
|
4983
|
+
return event ? json5(200, event) : adminError4(404, `no patient test ${params.id}`);
|
|
2790
4984
|
},
|
|
2791
|
-
"GET /settings": ({ namespace }) =>
|
|
4985
|
+
"GET /settings": ({ namespace }) => json5(200, runtime.instance(namespace).state.current()),
|
|
2792
4986
|
"PUT /settings": ({ body, namespace }) => {
|
|
2793
|
-
if (!
|
|
4987
|
+
if (!isRecord6(body)) return adminError4(400, "expected a JSON object");
|
|
2794
4988
|
const patch = {};
|
|
2795
4989
|
if (body.apiKeys !== void 0) {
|
|
2796
|
-
if (!Array.isArray(body.apiKeys)) return
|
|
4990
|
+
if (!Array.isArray(body.apiKeys)) return adminError4(400, "apiKeys: string[]");
|
|
2797
4991
|
patch.apiKeys = body.apiKeys.map(String);
|
|
2798
4992
|
}
|
|
2799
|
-
return
|
|
4993
|
+
return json5(200, runtime.instance(namespace).state.update(patch));
|
|
2800
4994
|
}
|
|
2801
4995
|
});
|
|
2802
4996
|
var createRuntime2 = (options = {}) => {
|
|
@@ -2821,7 +5015,7 @@ var createRuntime2 = (options = {}) => {
|
|
|
2821
5015
|
let sequence = 0;
|
|
2822
5016
|
const runtime = createRuntime({
|
|
2823
5017
|
name: ODX_NAMESPACE,
|
|
2824
|
-
document,
|
|
5018
|
+
document: document2,
|
|
2825
5019
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
2826
5020
|
...options.clock ? { clock: options.clock } : {},
|
|
2827
5021
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -2875,9 +5069,9 @@ var problem = (errors) => jsonRes(400, {
|
|
|
2875
5069
|
status: 400,
|
|
2876
5070
|
errors
|
|
2877
5071
|
});
|
|
2878
|
-
var
|
|
5072
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2879
5073
|
var text = (value) => typeof value === "string" ? value : typeof value === "number" ? String(value) : null;
|
|
2880
|
-
var jsonBody = (context) => context.body.kind === "json" &&
|
|
5074
|
+
var jsonBody = (context) => context.body.kind === "json" && isRecord7(context.body.value) ? context.body.value : void 0;
|
|
2881
5075
|
var dotnetDate = (value) => {
|
|
2882
5076
|
const raw = text(value);
|
|
2883
5077
|
if (!raw) return null;
|
|
@@ -2926,7 +5120,7 @@ var OdxAPI = class {
|
|
|
2926
5120
|
UpdateWebhook: (context) => this.saveWebhook(context, context.params.partnerWebhookId)
|
|
2927
5121
|
});
|
|
2928
5122
|
this.service = createService({
|
|
2929
|
-
document,
|
|
5123
|
+
document: document2,
|
|
2930
5124
|
handlers,
|
|
2931
5125
|
sqlite,
|
|
2932
5126
|
namespace,
|
|
@@ -3106,7 +5300,7 @@ var OdxAPI = class {
|
|
|
3106
5300
|
const results = [];
|
|
3107
5301
|
const importLogs = [];
|
|
3108
5302
|
for (const raw of body.results) {
|
|
3109
|
-
const item =
|
|
5303
|
+
const item = isRecord7(raw) ? raw : {};
|
|
3110
5304
|
const element = ELEMENTS.find((e) => e.elementId === item.elementId);
|
|
3111
5305
|
if (!element || typeof item.value !== "number") {
|
|
3112
5306
|
importLogs.push({
|
|
@@ -3217,7 +5411,7 @@ var OdxAPI = class {
|
|
|
3217
5411
|
if (id !== void 0 && !existing) return message(404, "Webhook not found.");
|
|
3218
5412
|
const body = jsonBody(context);
|
|
3219
5413
|
const url = text(body?.webhookUrl);
|
|
3220
|
-
const events =
|
|
5414
|
+
const events = isRecord7(body?.entityEvents) ? body.entityEvents.PatientTest : void 0;
|
|
3221
5415
|
const errors = {};
|
|
3222
5416
|
let valid = false;
|
|
3223
5417
|
try {
|
|
@@ -3254,7 +5448,7 @@ var publicPatient = ({ partnerUserId: _partner, ...patient }) => patient;
|
|
|
3254
5448
|
export {
|
|
3255
5449
|
LABS,
|
|
3256
5450
|
ELEMENTS,
|
|
3257
|
-
document,
|
|
5451
|
+
document2 as document,
|
|
3258
5452
|
operationIds,
|
|
3259
5453
|
supportedOperationIds,
|
|
3260
5454
|
parseObservations,
|
|
@@ -3268,4 +5462,4 @@ export {
|
|
|
3268
5462
|
apiKeyCredential,
|
|
3269
5463
|
OdxAPI
|
|
3270
5464
|
};
|
|
3271
|
-
//# sourceMappingURL=chunk-
|
|
5465
|
+
//# sourceMappingURL=chunk-VMVVOBJN.js.map
|