@crvouga/mockingbird-service-google-maps 1.4.0 → 1.6.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-M5RVKYST.js → chunk-HLXAIBBZ.js} +2305 -111
- package/dist/chunk-HLXAIBBZ.js.map +7 -0
- package/dist/{chunk-EHDRYY6O.js → chunk-XCSYTELK.js} +3 -2
- package/dist/{chunk-EHDRYY6O.js.map → chunk-XCSYTELK.js.map} +2 -2
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/server.d.ts +73 -3
- package/dist/server.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-M5RVKYST.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 row2 = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.
|
|
48
|
+
const row2 = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.collectionName);
|
|
49
49
|
const next = (row2?.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 row2 = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
58
|
+
const row2 = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
59
59
|
if (!row2)
|
|
60
60
|
return void 0;
|
|
61
61
|
return JSON.parse(row2.value).value;
|
|
62
62
|
}
|
|
63
63
|
has(id) {
|
|
64
|
-
const row2 = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
64
|
+
const row2 = 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 row2 !== 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 row2 = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
81
|
+
const row2 = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
82
82
|
if (!row2)
|
|
83
83
|
return void 0;
|
|
84
84
|
const stored = { seq: row2.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 row2 = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.
|
|
95
|
+
const row2 = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.collectionName);
|
|
96
96
|
return Number(row2?.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 row2 of rows) {
|
|
102
102
|
const stored = JSON.parse(row2.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
|
}
|
|
@@ -1117,6 +1119,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1117
1119
|
});
|
|
1118
1120
|
};
|
|
1119
1121
|
|
|
1122
|
+
// ../../ui/dist/reset.js
|
|
1123
|
+
var CSS_RESET = `*,
|
|
1124
|
+
*::before,
|
|
1125
|
+
*::after {
|
|
1126
|
+
box-sizing: border-box;
|
|
1127
|
+
margin: 0;
|
|
1128
|
+
padding: 0;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
* {
|
|
1132
|
+
scrollbar-width: thin;
|
|
1133
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
*::-webkit-scrollbar {
|
|
1137
|
+
width: 12px;
|
|
1138
|
+
height: 12px;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
*::-webkit-scrollbar-track,
|
|
1142
|
+
*::-webkit-scrollbar-corner {
|
|
1143
|
+
background: Canvas;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
*::-webkit-scrollbar-thumb {
|
|
1147
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1148
|
+
border: 3px solid Canvas;
|
|
1149
|
+
border-radius: 999px;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
html {
|
|
1153
|
+
hanging-punctuation: first allow-end last;
|
|
1154
|
+
-webkit-text-size-adjust: none;
|
|
1155
|
+
text-size-adjust: none;
|
|
1156
|
+
tab-size: 4;
|
|
1157
|
+
font-family:
|
|
1158
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1159
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1160
|
+
font-size: 16px;
|
|
1161
|
+
line-height: 1.5;
|
|
1162
|
+
-webkit-font-smoothing: antialiased;
|
|
1163
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1164
|
+
text-rendering: optimizeLegibility;
|
|
1165
|
+
-webkit-tap-highlight-color: transparent;
|
|
1166
|
+
scroll-behavior: smooth;
|
|
1167
|
+
background: Canvas;
|
|
1168
|
+
color: CanvasText;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
body {
|
|
1172
|
+
min-height: 100svh;
|
|
1173
|
+
line-height: 1.5;
|
|
1174
|
+
background: Canvas;
|
|
1175
|
+
color: CanvasText;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
h1 {
|
|
1179
|
+
font-size: 2em;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
h2 {
|
|
1183
|
+
font-size: 1.5em;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
h3 {
|
|
1187
|
+
font-size: 1.17em;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
h4 {
|
|
1191
|
+
font-size: 1em;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
h5 {
|
|
1195
|
+
font-size: 0.83em;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
h6 {
|
|
1199
|
+
font-size: 0.67em;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
h1,
|
|
1203
|
+
h2,
|
|
1204
|
+
h3,
|
|
1205
|
+
h4,
|
|
1206
|
+
h5,
|
|
1207
|
+
h6 {
|
|
1208
|
+
font-weight: 700;
|
|
1209
|
+
line-height: 1.2;
|
|
1210
|
+
text-wrap: balance;
|
|
1211
|
+
overflow-wrap: break-word;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
p,
|
|
1215
|
+
li,
|
|
1216
|
+
figcaption,
|
|
1217
|
+
dd,
|
|
1218
|
+
dt,
|
|
1219
|
+
blockquote {
|
|
1220
|
+
overflow-wrap: break-word;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
p,
|
|
1224
|
+
li,
|
|
1225
|
+
figcaption,
|
|
1226
|
+
blockquote {
|
|
1227
|
+
text-wrap: pretty;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
ul,
|
|
1231
|
+
ol,
|
|
1232
|
+
menu {
|
|
1233
|
+
list-style: none;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
a {
|
|
1237
|
+
color: inherit;
|
|
1238
|
+
text-decoration: underline;
|
|
1239
|
+
text-decoration-thickness: 1px;
|
|
1240
|
+
text-underline-offset: 0.15em;
|
|
1241
|
+
text-decoration-skip-ink: auto;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
b,
|
|
1245
|
+
strong {
|
|
1246
|
+
font-weight: 700;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
small {
|
|
1250
|
+
font-size: 0.875em;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
code,
|
|
1254
|
+
kbd,
|
|
1255
|
+
samp,
|
|
1256
|
+
pre {
|
|
1257
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1258
|
+
font-size: 1em;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
sub,
|
|
1262
|
+
sup {
|
|
1263
|
+
font-size: 75%;
|
|
1264
|
+
line-height: 0;
|
|
1265
|
+
position: relative;
|
|
1266
|
+
vertical-align: baseline;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
sub {
|
|
1270
|
+
bottom: -0.25em;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
sup {
|
|
1274
|
+
top: -0.5em;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
abbr[title] {
|
|
1278
|
+
text-decoration: underline dotted;
|
|
1279
|
+
text-underline-offset: 0.15em;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
mark {
|
|
1283
|
+
background: Mark;
|
|
1284
|
+
color: MarkText;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
hr {
|
|
1288
|
+
height: 0;
|
|
1289
|
+
border: 0;
|
|
1290
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1291
|
+
color: inherit;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
img,
|
|
1295
|
+
picture,
|
|
1296
|
+
video,
|
|
1297
|
+
canvas {
|
|
1298
|
+
display: block;
|
|
1299
|
+
max-width: 100%;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
img,
|
|
1303
|
+
video {
|
|
1304
|
+
height: auto;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
svg {
|
|
1308
|
+
overflow: hidden;
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
iframe {
|
|
1312
|
+
border: 0;
|
|
1313
|
+
max-width: 100%;
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
table {
|
|
1317
|
+
border-collapse: collapse;
|
|
1318
|
+
border-spacing: 0;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
fieldset {
|
|
1322
|
+
border: 0;
|
|
1323
|
+
min-inline-size: 0;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
legend {
|
|
1327
|
+
padding: 0;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
button,
|
|
1331
|
+
input,
|
|
1332
|
+
select,
|
|
1333
|
+
textarea,
|
|
1334
|
+
optgroup {
|
|
1335
|
+
font: inherit;
|
|
1336
|
+
letter-spacing: inherit;
|
|
1337
|
+
color: inherit;
|
|
1338
|
+
margin: 0;
|
|
1339
|
+
vertical-align: middle;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
button,
|
|
1343
|
+
input[type="button"],
|
|
1344
|
+
input[type="submit"],
|
|
1345
|
+
input[type="reset"] {
|
|
1346
|
+
appearance: none;
|
|
1347
|
+
background: none;
|
|
1348
|
+
border: 0;
|
|
1349
|
+
padding: 0;
|
|
1350
|
+
cursor: pointer;
|
|
1351
|
+
text-align: center;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
input,
|
|
1355
|
+
textarea,
|
|
1356
|
+
select {
|
|
1357
|
+
background-color: Canvas;
|
|
1358
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1359
|
+
border-radius: 0;
|
|
1360
|
+
padding: 0.5em 0.65em;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
input[type="checkbox"],
|
|
1364
|
+
input[type="radio"],
|
|
1365
|
+
input[type="range"],
|
|
1366
|
+
input[type="file"],
|
|
1367
|
+
input[type="color"],
|
|
1368
|
+
input[type="button"],
|
|
1369
|
+
input[type="submit"],
|
|
1370
|
+
input[type="reset"],
|
|
1371
|
+
input[type="image"],
|
|
1372
|
+
input[type="hidden"] {
|
|
1373
|
+
background: none;
|
|
1374
|
+
border: 0;
|
|
1375
|
+
padding: 0;
|
|
1376
|
+
border-radius: 0;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
input[type="checkbox"],
|
|
1380
|
+
input[type="radio"] {
|
|
1381
|
+
accent-color: CanvasText;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
input[type="search"] {
|
|
1385
|
+
appearance: none;
|
|
1386
|
+
background-color: Canvas;
|
|
1387
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1391
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1392
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1393
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1394
|
+
-webkit-appearance: none;
|
|
1395
|
+
display: none;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
input[type="number"] {
|
|
1399
|
+
appearance: textfield;
|
|
1400
|
+
background-color: Canvas;
|
|
1401
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1405
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1406
|
+
-webkit-appearance: none;
|
|
1407
|
+
margin: 0;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
textarea {
|
|
1411
|
+
resize: vertical;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
::placeholder {
|
|
1415
|
+
opacity: 1;
|
|
1416
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
:focus-visible {
|
|
1420
|
+
outline: 2px solid CanvasText;
|
|
1421
|
+
outline-offset: 2px;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
:focus:not(:focus-visible) {
|
|
1425
|
+
outline: none;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
:disabled,
|
|
1429
|
+
[disabled] {
|
|
1430
|
+
cursor: default;
|
|
1431
|
+
opacity: 0.6;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
label,
|
|
1435
|
+
summary,
|
|
1436
|
+
select,
|
|
1437
|
+
[role="button"] {
|
|
1438
|
+
cursor: pointer;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
summary {
|
|
1442
|
+
display: list-item;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
details {
|
|
1446
|
+
display: block;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
dialog {
|
|
1450
|
+
margin: auto;
|
|
1451
|
+
padding: 1rem;
|
|
1452
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1453
|
+
background: Canvas;
|
|
1454
|
+
color: CanvasText;
|
|
1455
|
+
max-width: calc(100vw - 2rem);
|
|
1456
|
+
max-height: calc(100svh - 2rem);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
dialog:not([open]) {
|
|
1460
|
+
display: none;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
::backdrop {
|
|
1464
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
[hidden] {
|
|
1468
|
+
display: none !important;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
::selection {
|
|
1472
|
+
background: Highlight;
|
|
1473
|
+
color: HighlightText;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1477
|
+
*,
|
|
1478
|
+
*::before,
|
|
1479
|
+
*::after {
|
|
1480
|
+
animation-duration: 0.01ms !important;
|
|
1481
|
+
animation-iteration-count: 1 !important;
|
|
1482
|
+
transition-duration: 0.01ms !important;
|
|
1483
|
+
scroll-behavior: auto !important;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
@media (pointer: coarse) {
|
|
1488
|
+
input,
|
|
1489
|
+
select,
|
|
1490
|
+
textarea {
|
|
1491
|
+
font-size: max(16px, 1em);
|
|
1492
|
+
}
|
|
1493
|
+
}`;
|
|
1494
|
+
|
|
1495
|
+
// ../core/dist/admin-client.js
|
|
1496
|
+
function isRecord2(value) {
|
|
1497
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1498
|
+
}
|
|
1499
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1500
|
+
const clip = (value, max) => {
|
|
1501
|
+
if (typeof value !== "string")
|
|
1502
|
+
return null;
|
|
1503
|
+
const trimmed = value.trim();
|
|
1504
|
+
if (trimmed === "")
|
|
1505
|
+
return null;
|
|
1506
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1507
|
+
};
|
|
1508
|
+
const httpUrl = (value) => {
|
|
1509
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1510
|
+
return null;
|
|
1511
|
+
try {
|
|
1512
|
+
const url = new URL(value);
|
|
1513
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1514
|
+
return null;
|
|
1515
|
+
return url.href;
|
|
1516
|
+
} catch {
|
|
1517
|
+
return null;
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
const hexColor = (value) => {
|
|
1521
|
+
if (typeof value !== "string")
|
|
1522
|
+
return null;
|
|
1523
|
+
const raw = value.trim();
|
|
1524
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1525
|
+
};
|
|
1526
|
+
const hostname = (value) => {
|
|
1527
|
+
try {
|
|
1528
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1529
|
+
} catch {
|
|
1530
|
+
return value;
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
host.replaceChildren();
|
|
1534
|
+
host.hidden = true;
|
|
1535
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1536
|
+
return;
|
|
1537
|
+
const row2 = catalog[service];
|
|
1538
|
+
if (!isRecord2(row2))
|
|
1539
|
+
return;
|
|
1540
|
+
const vendor = clip(row2.vendor, 80);
|
|
1541
|
+
const website = httpUrl(row2.website);
|
|
1542
|
+
const guide = httpUrl(row2.guide);
|
|
1543
|
+
const docs = httpUrl(row2.docs);
|
|
1544
|
+
const logo = httpUrl(row2.logo);
|
|
1545
|
+
const color = hexColor(row2.color);
|
|
1546
|
+
const description = clip(row2.description, 280);
|
|
1547
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1548
|
+
return;
|
|
1549
|
+
const add = (node) => {
|
|
1550
|
+
host.append(node);
|
|
1551
|
+
return node;
|
|
1552
|
+
};
|
|
1553
|
+
if (logo !== null) {
|
|
1554
|
+
const img = doc.createElement("img");
|
|
1555
|
+
img.alt = "";
|
|
1556
|
+
img.src = logo;
|
|
1557
|
+
img.width = 16;
|
|
1558
|
+
img.height = 16;
|
|
1559
|
+
img.decoding = "async";
|
|
1560
|
+
img.referrerPolicy = "no-referrer";
|
|
1561
|
+
if (color !== null)
|
|
1562
|
+
img.style.borderColor = color;
|
|
1563
|
+
add(img);
|
|
1564
|
+
}
|
|
1565
|
+
const name = doc.createElement("span");
|
|
1566
|
+
name.className = "vendor-name";
|
|
1567
|
+
name.textContent = vendor;
|
|
1568
|
+
if (description !== null)
|
|
1569
|
+
name.title = description;
|
|
1570
|
+
add(name);
|
|
1571
|
+
const sep = () => {
|
|
1572
|
+
const node = doc.createElement("span");
|
|
1573
|
+
node.className = "vendor-sep";
|
|
1574
|
+
node.setAttribute("aria-hidden", "true");
|
|
1575
|
+
node.textContent = "\xB7";
|
|
1576
|
+
return node;
|
|
1577
|
+
};
|
|
1578
|
+
const link = (href, label, title) => {
|
|
1579
|
+
const node = doc.createElement("a");
|
|
1580
|
+
node.className = "vendor-link";
|
|
1581
|
+
node.href = href;
|
|
1582
|
+
node.target = "_blank";
|
|
1583
|
+
node.rel = "noopener noreferrer";
|
|
1584
|
+
node.referrerPolicy = "no-referrer";
|
|
1585
|
+
node.textContent = label;
|
|
1586
|
+
node.title = title;
|
|
1587
|
+
return node;
|
|
1588
|
+
};
|
|
1589
|
+
if (website !== null) {
|
|
1590
|
+
add(sep());
|
|
1591
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1592
|
+
}
|
|
1593
|
+
if (guide !== null) {
|
|
1594
|
+
add(sep());
|
|
1595
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1596
|
+
}
|
|
1597
|
+
if (docs !== null) {
|
|
1598
|
+
add(sep());
|
|
1599
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1600
|
+
}
|
|
1601
|
+
host.removeAttribute("hidden");
|
|
1602
|
+
host.hidden = false;
|
|
1603
|
+
}
|
|
1604
|
+
function startAdminBrand(env) {
|
|
1605
|
+
const requested = env.params.get("brands");
|
|
1606
|
+
let brandsUrl = env.brandsUrl;
|
|
1607
|
+
if (requested) {
|
|
1608
|
+
try {
|
|
1609
|
+
const url = new URL(requested, env.location.href);
|
|
1610
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1611
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1612
|
+
brandsUrl = url.href;
|
|
1613
|
+
} catch {
|
|
1614
|
+
brandsUrl = env.brandsUrl;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
const vendorHost = env.$("vendor");
|
|
1618
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1619
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1620
|
+
if (vendorHost === null)
|
|
1621
|
+
return;
|
|
1622
|
+
env.fetch(brandsUrl, {
|
|
1623
|
+
headers: { accept: "application/json" },
|
|
1624
|
+
signal: AbortSignal.timeout(5e3)
|
|
1625
|
+
}).then(async (response) => {
|
|
1626
|
+
if (!response.ok)
|
|
1627
|
+
return null;
|
|
1628
|
+
const catalog = await response.json();
|
|
1629
|
+
return catalog;
|
|
1630
|
+
}).then((catalog) => {
|
|
1631
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1632
|
+
}).catch(() => {
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1635
|
+
function faultPresetList(value) {
|
|
1636
|
+
if (!isRecord2(value))
|
|
1637
|
+
throw new Error("Fault presets response was not an object");
|
|
1638
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1639
|
+
return { presets: [] };
|
|
1640
|
+
}
|
|
1641
|
+
if (!Array.isArray(value.presets))
|
|
1642
|
+
throw new Error("Fault presets response was not a list");
|
|
1643
|
+
return {
|
|
1644
|
+
presets: value.presets.flatMap((item) => {
|
|
1645
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1646
|
+
return [];
|
|
1647
|
+
return [{ name: item.name }];
|
|
1648
|
+
})
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
function bootAdmin(config) {
|
|
1652
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1653
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1654
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1655
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1656
|
+
const readJson2 = (text2) => {
|
|
1657
|
+
const value = JSON.parse(text2);
|
|
1658
|
+
return value;
|
|
1659
|
+
};
|
|
1660
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1661
|
+
switch (char) {
|
|
1662
|
+
case "&":
|
|
1663
|
+
return "&";
|
|
1664
|
+
case "<":
|
|
1665
|
+
return "<";
|
|
1666
|
+
case ">":
|
|
1667
|
+
return ">";
|
|
1668
|
+
case '"':
|
|
1669
|
+
return """;
|
|
1670
|
+
default:
|
|
1671
|
+
return "'";
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
const el = (id, kind) => {
|
|
1675
|
+
const node = document.getElementById(id);
|
|
1676
|
+
if (!(node instanceof kind))
|
|
1677
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1678
|
+
return node;
|
|
1679
|
+
};
|
|
1680
|
+
const errorMessage = (data, fallback) => {
|
|
1681
|
+
if (!isRecord2(data))
|
|
1682
|
+
return fallback;
|
|
1683
|
+
const error = data.error;
|
|
1684
|
+
if (!isRecord2(error) || typeof error.message !== "string" || error.message === "") {
|
|
1685
|
+
return fallback;
|
|
1686
|
+
}
|
|
1687
|
+
return error.message;
|
|
1688
|
+
};
|
|
1689
|
+
const requireList = (value, label) => {
|
|
1690
|
+
if (value === void 0 || value === null)
|
|
1691
|
+
return [];
|
|
1692
|
+
if (!Array.isArray(value))
|
|
1693
|
+
throw new Error(`${label} was not a list`);
|
|
1694
|
+
return value;
|
|
1695
|
+
};
|
|
1696
|
+
const state = {
|
|
1697
|
+
namespace: "default",
|
|
1698
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1699
|
+
view: "overview",
|
|
1700
|
+
collection: "",
|
|
1701
|
+
shape: null,
|
|
1702
|
+
route: null,
|
|
1703
|
+
editing: null
|
|
1704
|
+
};
|
|
1705
|
+
const standard = new Set(config.standardRoutes);
|
|
1706
|
+
const banner = el("banner", HTMLElement);
|
|
1707
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1708
|
+
keyInput.value = state.key;
|
|
1709
|
+
const params = new URLSearchParams(location.search);
|
|
1710
|
+
const queryKey = params.get("key");
|
|
1711
|
+
if (queryKey) {
|
|
1712
|
+
state.key = queryKey;
|
|
1713
|
+
keyInput.value = state.key;
|
|
1714
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1715
|
+
params.delete("key");
|
|
1716
|
+
const next = params.toString();
|
|
1717
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1718
|
+
}
|
|
1719
|
+
const queryNamespace = params.get("namespace");
|
|
1720
|
+
if (queryNamespace)
|
|
1721
|
+
state.namespace = queryNamespace;
|
|
1722
|
+
const showError = (error) => {
|
|
1723
|
+
banner.textContent = error instanceof Error ? error.message : String(error);
|
|
1724
|
+
banner.classList.add("show");
|
|
1725
|
+
};
|
|
1726
|
+
const clearError = () => {
|
|
1727
|
+
banner.classList.remove("show");
|
|
1728
|
+
};
|
|
1729
|
+
const api = async (method, path, body) => {
|
|
1730
|
+
const headers = { accept: "application/json" };
|
|
1731
|
+
if (state.key !== "")
|
|
1732
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1733
|
+
if (state.namespace !== "")
|
|
1734
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1735
|
+
if (body !== void 0)
|
|
1736
|
+
headers["content-type"] = "application/json";
|
|
1737
|
+
const init = { method, headers };
|
|
1738
|
+
if (body !== void 0)
|
|
1739
|
+
init.body = JSON.stringify(body);
|
|
1740
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1741
|
+
const text2 = await response.text();
|
|
1742
|
+
let data = null;
|
|
1743
|
+
if (text2 !== "") {
|
|
1744
|
+
try {
|
|
1745
|
+
data = readJson2(text2);
|
|
1746
|
+
} catch {
|
|
1747
|
+
data = { raw: text2 };
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
if (response.status === 401) {
|
|
1751
|
+
keyInput.focus();
|
|
1752
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1753
|
+
}
|
|
1754
|
+
if (!response.ok) {
|
|
1755
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1756
|
+
}
|
|
1757
|
+
return data;
|
|
1758
|
+
};
|
|
1759
|
+
const originGet = async (path) => {
|
|
1760
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1761
|
+
if (!response.ok)
|
|
1762
|
+
throw new Error(`${response.status} ${path}`);
|
|
1763
|
+
const value = await response.json();
|
|
1764
|
+
return value;
|
|
1765
|
+
};
|
|
1766
|
+
const panelApi = {
|
|
1767
|
+
get: (path) => api("GET", path),
|
|
1768
|
+
send: (method, path, body) => api(method, path, body),
|
|
1769
|
+
namespace: () => state.namespace
|
|
1770
|
+
};
|
|
1771
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1772
|
+
const setTheme = (theme) => {
|
|
1773
|
+
if (theme)
|
|
1774
|
+
document.documentElement.dataset.theme = theme;
|
|
1775
|
+
else
|
|
1776
|
+
delete document.documentElement.dataset.theme;
|
|
1777
|
+
};
|
|
1778
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1779
|
+
if (storedTheme)
|
|
1780
|
+
setTheme(storedTheme);
|
|
1781
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1782
|
+
const current = document.documentElement.dataset.theme;
|
|
1783
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1784
|
+
const next = dark ? "light" : "dark";
|
|
1785
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
1786
|
+
setTheme(next);
|
|
1787
|
+
});
|
|
1788
|
+
const show = (view) => {
|
|
1789
|
+
state.view = view;
|
|
1790
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
1791
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1792
|
+
continue;
|
|
1793
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
1794
|
+
}
|
|
1795
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
1796
|
+
if (!(section instanceof HTMLElement))
|
|
1797
|
+
continue;
|
|
1798
|
+
section.hidden = section.id !== `view-${view}`;
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
1802
|
+
const target = event.target;
|
|
1803
|
+
if (!(target instanceof Element))
|
|
1804
|
+
return;
|
|
1805
|
+
const button = target.closest("button[data-view]");
|
|
1806
|
+
if (!(button instanceof HTMLButtonElement))
|
|
1807
|
+
return;
|
|
1808
|
+
const view = button.dataset.view;
|
|
1809
|
+
if (view === void 0)
|
|
1810
|
+
return;
|
|
1811
|
+
show(view);
|
|
1812
|
+
refresh().catch(showError);
|
|
1813
|
+
});
|
|
1814
|
+
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>`;
|
|
1815
|
+
const table = (columns, rows) => {
|
|
1816
|
+
if (rows.length === 0)
|
|
1817
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
1818
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
1819
|
+
const body = rows.map((row2) => {
|
|
1820
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row2)}</td>`).join("");
|
|
1821
|
+
const attrs = "attrs" in row2 && typeof row2.attrs === "string" ? row2.attrs : "";
|
|
1822
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
1823
|
+
}).join("");
|
|
1824
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
1825
|
+
};
|
|
1826
|
+
const preview = (value) => {
|
|
1827
|
+
const text2 = JSON.stringify(value) ?? "null";
|
|
1828
|
+
return esc(text2.length > 180 ? `${text2.slice(0, 180)}\u2026` : text2);
|
|
1829
|
+
};
|
|
1830
|
+
const when = (epoch) => {
|
|
1831
|
+
const date = new Date(epoch);
|
|
1832
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
1833
|
+
};
|
|
1834
|
+
const clockCard = (epoch) => {
|
|
1835
|
+
const date = new Date(epoch);
|
|
1836
|
+
if (Number.isNaN(date.getTime()))
|
|
1837
|
+
return esc(String(epoch));
|
|
1838
|
+
const iso = date.toISOString();
|
|
1839
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
1840
|
+
};
|
|
1841
|
+
const decodeClock = (value) => {
|
|
1842
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
1843
|
+
throw new Error("Clock response was not a clock");
|
|
1844
|
+
}
|
|
1845
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
1846
|
+
};
|
|
1847
|
+
const decodeField = (value) => {
|
|
1848
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
1849
|
+
return void 0;
|
|
1850
|
+
}
|
|
1851
|
+
const field = {
|
|
1852
|
+
name: value.name,
|
|
1853
|
+
kind: value.kind,
|
|
1854
|
+
optional: value.optional === true
|
|
1855
|
+
};
|
|
1856
|
+
if (typeof value.description === "string")
|
|
1857
|
+
field.description = value.description;
|
|
1858
|
+
if (Array.isArray(value.fields)) {
|
|
1859
|
+
field.fields = value.fields.flatMap((item) => {
|
|
1860
|
+
const child = decodeField(item);
|
|
1861
|
+
return child === void 0 ? [] : [child];
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
return field;
|
|
1865
|
+
};
|
|
1866
|
+
const decodeCollection = (value) => {
|
|
1867
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
1868
|
+
return void 0;
|
|
1869
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
1870
|
+
const field = decodeField(item);
|
|
1871
|
+
return field === void 0 ? [] : [field];
|
|
1872
|
+
}) : [];
|
|
1873
|
+
const collection = {
|
|
1874
|
+
name: value.name,
|
|
1875
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
1876
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
1877
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
1878
|
+
fields
|
|
1879
|
+
};
|
|
1880
|
+
if (typeof value.description === "string")
|
|
1881
|
+
collection.description = value.description;
|
|
1882
|
+
return collection;
|
|
1883
|
+
};
|
|
1884
|
+
const decodeState = (value) => {
|
|
1885
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
1886
|
+
throw new Error("State response has no collection list");
|
|
1887
|
+
}
|
|
1888
|
+
return {
|
|
1889
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
1890
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
1891
|
+
collections: value.collections.flatMap((item) => {
|
|
1892
|
+
const collection = decodeCollection(item);
|
|
1893
|
+
return collection === void 0 ? [] : [collection];
|
|
1894
|
+
})
|
|
1895
|
+
};
|
|
1896
|
+
};
|
|
1897
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
1898
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
1899
|
+
return [];
|
|
1900
|
+
return [
|
|
1901
|
+
{
|
|
1902
|
+
id: item.id,
|
|
1903
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
1904
|
+
value: item.value,
|
|
1905
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
1906
|
+
}
|
|
1907
|
+
];
|
|
1908
|
+
});
|
|
1909
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
1910
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
1911
|
+
if (!isRecord2(item))
|
|
1912
|
+
return [];
|
|
1913
|
+
return [
|
|
1914
|
+
{
|
|
1915
|
+
at: textOf(item.at),
|
|
1916
|
+
method: textOf(item.method),
|
|
1917
|
+
path: textOf(item.path),
|
|
1918
|
+
status: textOf(item.status),
|
|
1919
|
+
durationMs: textOf(item.durationMs),
|
|
1920
|
+
operationId: textOf(item.operationId)
|
|
1921
|
+
}
|
|
1922
|
+
];
|
|
1923
|
+
});
|
|
1924
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
1925
|
+
if (!isRecord2(item))
|
|
1926
|
+
return [];
|
|
1927
|
+
return [
|
|
1928
|
+
{
|
|
1929
|
+
id: textOf(item.id),
|
|
1930
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
1931
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
1932
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
1933
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
1934
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
1935
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
1936
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
1937
|
+
}
|
|
1938
|
+
];
|
|
1939
|
+
});
|
|
1940
|
+
const loadNamespaces = async () => {
|
|
1941
|
+
const data = await api("GET", "/namespaces");
|
|
1942
|
+
const select = el("namespace", HTMLSelectElement);
|
|
1943
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
1944
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
1945
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
1946
|
+
if (!names.includes(state.namespace))
|
|
1947
|
+
names.unshift(state.namespace);
|
|
1948
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
1949
|
+
select.value = state.namespace;
|
|
1950
|
+
};
|
|
1951
|
+
const renderOverview = async () => {
|
|
1952
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
1953
|
+
originGet("/health"),
|
|
1954
|
+
api("GET", "/state"),
|
|
1955
|
+
api("GET", "/clock"),
|
|
1956
|
+
api("GET", "/requests?limit=8")
|
|
1957
|
+
]);
|
|
1958
|
+
if (!isRecord2(health))
|
|
1959
|
+
throw new Error("Health response was not an object");
|
|
1960
|
+
const decoded = decodeState(shape);
|
|
1961
|
+
state.shape = decoded;
|
|
1962
|
+
const time = decodeClock(clock);
|
|
1963
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
1964
|
+
{
|
|
1965
|
+
k: "Service",
|
|
1966
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
1967
|
+
},
|
|
1968
|
+
{
|
|
1969
|
+
k: "Status",
|
|
1970
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
1971
|
+
},
|
|
1972
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
1973
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
1974
|
+
{
|
|
1975
|
+
k: "Records",
|
|
1976
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
1977
|
+
},
|
|
1978
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
1979
|
+
]);
|
|
1980
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
1981
|
+
{ label: "Method", cell: (row2) => esc(row2.method) },
|
|
1982
|
+
{ label: "Path", cell: (row2) => esc(row2.path) },
|
|
1983
|
+
{
|
|
1984
|
+
label: "Status",
|
|
1985
|
+
cell: (row2) => `<span class="status-${row2.status.charAt(0)}">${esc(row2.status)}</span>`
|
|
1986
|
+
},
|
|
1987
|
+
{ label: "Operation", cell: (row2) => esc(row2.operationId) }
|
|
1988
|
+
], decodeJournal(journal));
|
|
1989
|
+
};
|
|
1990
|
+
const schemaChips = (collection) => {
|
|
1991
|
+
if (collection.fields.length === 0) {
|
|
1992
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
1993
|
+
}
|
|
1994
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
1995
|
+
};
|
|
1996
|
+
const renderState = async () => {
|
|
1997
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
1998
|
+
state.shape = shape;
|
|
1999
|
+
const host = el("collections", HTMLElement);
|
|
2000
|
+
if (shape.collections.length === 0) {
|
|
2001
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
2002
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
2003
|
+
el("records", HTMLElement).innerHTML = "";
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
2007
|
+
const first = shape.collections[0];
|
|
2008
|
+
if (first === void 0)
|
|
2009
|
+
return;
|
|
2010
|
+
state.collection = first.name;
|
|
2011
|
+
}
|
|
2012
|
+
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("");
|
|
2013
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
2014
|
+
if (selected === void 0)
|
|
2015
|
+
return;
|
|
2016
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
2017
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
2018
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
2019
|
+
el("records", HTMLElement).innerHTML = table([
|
|
2020
|
+
{ label: "Id", cell: (row2) => `<code>${esc(row2.id)}</code>` },
|
|
2021
|
+
{ label: "Seq", cell: (row2) => esc(row2.seq) },
|
|
2022
|
+
{ label: "Value", cell: (row2) => preview(row2.value) }
|
|
2023
|
+
], decodeRecords(page));
|
|
2024
|
+
};
|
|
2025
|
+
const renderClock = async () => {
|
|
2026
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2027
|
+
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>`;
|
|
2028
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2029
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2030
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2031
|
+
};
|
|
2032
|
+
const renderFaults = async () => {
|
|
2033
|
+
const [faults, presets] = await Promise.all([
|
|
2034
|
+
api("GET", "/faults"),
|
|
2035
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2036
|
+
]);
|
|
2037
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2038
|
+
const current = select.value;
|
|
2039
|
+
const list = faultPresetList(presets).presets;
|
|
2040
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2041
|
+
select.value = current;
|
|
2042
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2043
|
+
{ label: "Id", cell: (row2) => esc(row2.id) },
|
|
2044
|
+
{
|
|
2045
|
+
label: "Match",
|
|
2046
|
+
cell: (row2) => esc([row2.method, row2.pathPrefix, row2.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2047
|
+
},
|
|
2048
|
+
{
|
|
2049
|
+
label: "Effect",
|
|
2050
|
+
cell: (row2) => esc(row2.status ?? row2.effect ?? (row2.drop ? "drop" : row2.latencyMs || ""))
|
|
2051
|
+
}
|
|
2052
|
+
], decodeFaults(faults));
|
|
2053
|
+
};
|
|
2054
|
+
const renderJournal = async () => {
|
|
2055
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2056
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2057
|
+
{ label: "When", cell: (row2) => esc(row2.at) },
|
|
2058
|
+
{ label: "Method", cell: (row2) => esc(row2.method) },
|
|
2059
|
+
{ label: "Path", cell: (row2) => esc(row2.path) },
|
|
2060
|
+
{ label: "Status", cell: (row2) => esc(row2.status) },
|
|
2061
|
+
{ label: "ms", cell: (row2) => esc(row2.durationMs) }
|
|
2062
|
+
], decodeJournal(journal));
|
|
2063
|
+
};
|
|
2064
|
+
const renderRoutes = async () => {
|
|
2065
|
+
const data = await api("GET", "/");
|
|
2066
|
+
if (!isRecord2(data))
|
|
2067
|
+
throw new Error("Route list was not an object");
|
|
2068
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2069
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2070
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2071
|
+
const parts = route.split(" ");
|
|
2072
|
+
const method = parts[0] ?? "";
|
|
2073
|
+
const path = parts.slice(1).join(" ");
|
|
2074
|
+
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>`;
|
|
2075
|
+
}).join("");
|
|
2076
|
+
};
|
|
2077
|
+
const renderers = {
|
|
2078
|
+
overview: renderOverview,
|
|
2079
|
+
state: renderState,
|
|
2080
|
+
clock: renderClock,
|
|
2081
|
+
faults: renderFaults,
|
|
2082
|
+
journal: renderJournal,
|
|
2083
|
+
routes: renderRoutes
|
|
2084
|
+
};
|
|
2085
|
+
async function refresh() {
|
|
2086
|
+
clearError();
|
|
2087
|
+
const render = renderers[state.view];
|
|
2088
|
+
if (render)
|
|
2089
|
+
await render();
|
|
2090
|
+
}
|
|
2091
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2092
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2093
|
+
refresh().catch(showError);
|
|
2094
|
+
});
|
|
2095
|
+
keyInput.addEventListener("change", () => {
|
|
2096
|
+
state.key = keyInput.value.trim();
|
|
2097
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2098
|
+
refresh().catch(showError);
|
|
2099
|
+
});
|
|
2100
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2101
|
+
refresh().catch(showError);
|
|
2102
|
+
});
|
|
2103
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2104
|
+
const target = event.target;
|
|
2105
|
+
if (!(target instanceof Element))
|
|
2106
|
+
return;
|
|
2107
|
+
const button = target.closest("[data-collection]");
|
|
2108
|
+
if (!(button instanceof HTMLElement))
|
|
2109
|
+
return;
|
|
2110
|
+
const collection = button.dataset.collection;
|
|
2111
|
+
if (collection === void 0)
|
|
2112
|
+
return;
|
|
2113
|
+
state.collection = collection;
|
|
2114
|
+
renderState().catch(showError);
|
|
2115
|
+
});
|
|
2116
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2117
|
+
const target = event.target;
|
|
2118
|
+
if (!(target instanceof Element))
|
|
2119
|
+
return;
|
|
2120
|
+
const row2 = target.closest("[data-id]");
|
|
2121
|
+
if (!(row2 instanceof HTMLElement))
|
|
2122
|
+
return;
|
|
2123
|
+
const id = row2.dataset.id;
|
|
2124
|
+
if (id === void 0)
|
|
2125
|
+
return;
|
|
2126
|
+
openEditor(id).catch(showError);
|
|
2127
|
+
});
|
|
2128
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2129
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2130
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2131
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2132
|
+
async function openEditor(id) {
|
|
2133
|
+
state.editing = id;
|
|
2134
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2135
|
+
editorId.value = id ?? "";
|
|
2136
|
+
editorId.readOnly = id !== null;
|
|
2137
|
+
editorDelete.hidden = id === null;
|
|
2138
|
+
if (id) {
|
|
2139
|
+
const record = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2140
|
+
if (!isRecord2(record))
|
|
2141
|
+
throw new Error("Record response was not an object");
|
|
2142
|
+
editorValue.value = JSON.stringify(record.value, null, 2) ?? "";
|
|
2143
|
+
} else {
|
|
2144
|
+
editorValue.value = "{\n \n}";
|
|
2145
|
+
}
|
|
2146
|
+
editor.showModal();
|
|
2147
|
+
}
|
|
2148
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2149
|
+
openEditor(null).catch(showError);
|
|
2150
|
+
});
|
|
2151
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2152
|
+
const submitter = event.submitter;
|
|
2153
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2154
|
+
return;
|
|
2155
|
+
event.preventDefault();
|
|
2156
|
+
let value;
|
|
2157
|
+
try {
|
|
2158
|
+
value = readJson2(editorValue.value);
|
|
2159
|
+
} catch {
|
|
2160
|
+
showError(new Error("Value is not JSON"));
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2163
|
+
const id = editorId.value.trim();
|
|
2164
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2165
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2166
|
+
request.then(() => {
|
|
2167
|
+
editor.close();
|
|
2168
|
+
return renderState();
|
|
2169
|
+
}).catch(showError);
|
|
2170
|
+
});
|
|
2171
|
+
editorDelete.addEventListener("click", () => {
|
|
2172
|
+
const id = state.editing;
|
|
2173
|
+
if (!id)
|
|
2174
|
+
return;
|
|
2175
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2176
|
+
editor.close();
|
|
2177
|
+
return renderState();
|
|
2178
|
+
}).catch(showError);
|
|
2179
|
+
});
|
|
2180
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2181
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2182
|
+
continue;
|
|
2183
|
+
button.addEventListener("click", () => {
|
|
2184
|
+
const raw = button.dataset.advance;
|
|
2185
|
+
if (raw === void 0)
|
|
2186
|
+
return;
|
|
2187
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2188
|
+
});
|
|
2189
|
+
}
|
|
2190
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2191
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2192
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2193
|
+
});
|
|
2194
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2195
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2196
|
+
});
|
|
2197
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2198
|
+
event.preventDefault();
|
|
2199
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2200
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2201
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2202
|
+
});
|
|
2203
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2204
|
+
event.preventDefault();
|
|
2205
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2206
|
+
if (preset !== "") {
|
|
2207
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2208
|
+
return;
|
|
2209
|
+
}
|
|
2210
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2211
|
+
if (!Number.isFinite(status)) {
|
|
2212
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2216
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2217
|
+
api("POST", "/faults", {
|
|
2218
|
+
status,
|
|
2219
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2220
|
+
...method !== "" ? { method } : {}
|
|
2221
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2222
|
+
});
|
|
2223
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2224
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2225
|
+
});
|
|
2226
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2227
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2228
|
+
});
|
|
2229
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2230
|
+
const target = event.target;
|
|
2231
|
+
if (!(target instanceof Element))
|
|
2232
|
+
return;
|
|
2233
|
+
const button = target.closest("[data-route]");
|
|
2234
|
+
if (!(button instanceof HTMLElement))
|
|
2235
|
+
return;
|
|
2236
|
+
const route = button.dataset.route;
|
|
2237
|
+
if (route === void 0)
|
|
2238
|
+
return;
|
|
2239
|
+
state.route = route;
|
|
2240
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2241
|
+
const method = route.split(" ")[0] ?? "";
|
|
2242
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2243
|
+
});
|
|
2244
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2245
|
+
event.preventDefault();
|
|
2246
|
+
const send = async () => {
|
|
2247
|
+
if (state.route === null)
|
|
2248
|
+
throw new Error("Choose a route first");
|
|
2249
|
+
const parts = state.route.split(" ");
|
|
2250
|
+
const method = parts[0];
|
|
2251
|
+
const path = parts.slice(1).join(" ");
|
|
2252
|
+
if (method === void 0)
|
|
2253
|
+
throw new Error("Choose a route first");
|
|
2254
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2255
|
+
let body;
|
|
2256
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2257
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2258
|
+
try {
|
|
2259
|
+
body = readJson2(routeBody.value);
|
|
2260
|
+
} catch {
|
|
2261
|
+
throw new Error("Body is not JSON");
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
const data = await api(method, concrete, body);
|
|
2265
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2266
|
+
};
|
|
2267
|
+
send().catch(showError);
|
|
2268
|
+
});
|
|
2269
|
+
const decodePanel = (value) => {
|
|
2270
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2271
|
+
return void 0;
|
|
2272
|
+
}
|
|
2273
|
+
const panel = {
|
|
2274
|
+
id: value.id,
|
|
2275
|
+
title: value.title,
|
|
2276
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2277
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2278
|
+
};
|
|
2279
|
+
if (typeof value.script === "string")
|
|
2280
|
+
panel.script = value.script;
|
|
2281
|
+
return panel;
|
|
2282
|
+
};
|
|
2283
|
+
const mountPanels = (panels) => {
|
|
2284
|
+
const nav = el("nav", HTMLElement);
|
|
2285
|
+
const views = el("views", HTMLElement);
|
|
2286
|
+
for (const panel of panels) {
|
|
2287
|
+
const button = document.createElement("button");
|
|
2288
|
+
button.type = "button";
|
|
2289
|
+
button.dataset.view = panel.id;
|
|
2290
|
+
button.textContent = panel.title;
|
|
2291
|
+
nav.append(button);
|
|
2292
|
+
const section = document.createElement("section");
|
|
2293
|
+
section.className = "view";
|
|
2294
|
+
section.id = `view-${panel.id}`;
|
|
2295
|
+
section.hidden = true;
|
|
2296
|
+
const title = document.createElement("h2");
|
|
2297
|
+
title.textContent = panel.title;
|
|
2298
|
+
const lede = document.createElement("p");
|
|
2299
|
+
lede.className = "lede";
|
|
2300
|
+
lede.textContent = panel.description;
|
|
2301
|
+
const body = document.createElement("div");
|
|
2302
|
+
body.className = "panel-body";
|
|
2303
|
+
body.id = `panel-${panel.id}`;
|
|
2304
|
+
body.innerHTML = panel.html;
|
|
2305
|
+
section.append(title, lede, body);
|
|
2306
|
+
views.append(section);
|
|
2307
|
+
if (panel.script === void 0)
|
|
2308
|
+
continue;
|
|
2309
|
+
try {
|
|
2310
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2311
|
+
if (!isPanelScript(compiled))
|
|
2312
|
+
throw new Error("panel script did not compile");
|
|
2313
|
+
compiled(body, panelApi);
|
|
2314
|
+
} catch (error) {
|
|
2315
|
+
const note = document.createElement("p");
|
|
2316
|
+
note.className = "banner show";
|
|
2317
|
+
note.textContent = error instanceof Error ? error.message : String(error);
|
|
2318
|
+
body.append(note);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
};
|
|
2322
|
+
startAdminBrand({
|
|
2323
|
+
document,
|
|
2324
|
+
$: (id) => document.getElementById(id),
|
|
2325
|
+
params,
|
|
2326
|
+
location: { href: location.href, origin: location.origin },
|
|
2327
|
+
fetch,
|
|
2328
|
+
brandsUrl: config.brandsUrl
|
|
2329
|
+
});
|
|
2330
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2331
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2332
|
+
const decoded = decodePanel(panel);
|
|
2333
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2334
|
+
});
|
|
2335
|
+
mountPanels(panels);
|
|
2336
|
+
return refresh();
|
|
2337
|
+
}).catch(showError);
|
|
2338
|
+
}
|
|
2339
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2340
|
+
var adminClientSource = (config) => {
|
|
2341
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2342
|
+
return `<script>
|
|
2343
|
+
${clientPrelude}
|
|
2344
|
+
bootAdmin(${payload});
|
|
2345
|
+
</script>`;
|
|
2346
|
+
};
|
|
2347
|
+
|
|
2348
|
+
// ../core/dist/surface.js
|
|
2349
|
+
var defineMock = (runtime) => runtime;
|
|
2350
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2351
|
+
"GET /",
|
|
2352
|
+
"POST /reset",
|
|
2353
|
+
"GET /namespaces",
|
|
2354
|
+
"GET /clock",
|
|
2355
|
+
"POST /clock",
|
|
2356
|
+
"GET /faults",
|
|
2357
|
+
"POST /faults",
|
|
2358
|
+
"DELETE /faults",
|
|
2359
|
+
"POST /snapshots",
|
|
2360
|
+
"POST /snapshots/:id/restore",
|
|
2361
|
+
"DELETE /snapshots/:id",
|
|
2362
|
+
"GET /timeline",
|
|
2363
|
+
"POST /checkpoints",
|
|
2364
|
+
"POST /branches/:name",
|
|
2365
|
+
"POST /branches/:name/checkout",
|
|
2366
|
+
"GET /requests",
|
|
2367
|
+
"DELETE /requests",
|
|
2368
|
+
"GET /metrics",
|
|
2369
|
+
"DELETE /metrics",
|
|
2370
|
+
"GET /credentials",
|
|
2371
|
+
"PUT /credentials",
|
|
2372
|
+
"DELETE /credentials",
|
|
2373
|
+
"GET /state",
|
|
2374
|
+
"GET /state/:collection",
|
|
2375
|
+
"GET /state/:collection/:id",
|
|
2376
|
+
"POST /state/:collection",
|
|
2377
|
+
"PUT /state/:collection/:id",
|
|
2378
|
+
"PATCH /state/:collection/:id",
|
|
2379
|
+
"DELETE /state/:collection/:id",
|
|
2380
|
+
"GET /ui",
|
|
2381
|
+
"GET /ui/",
|
|
2382
|
+
"GET /ui/manifest"
|
|
2383
|
+
];
|
|
2384
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2385
|
+
var assertAdminUi = (ui) => {
|
|
2386
|
+
if (!ui?.panels)
|
|
2387
|
+
return;
|
|
2388
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2389
|
+
for (const panel of ui.panels) {
|
|
2390
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2391
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2392
|
+
}
|
|
2393
|
+
if (seen.has(panel.id))
|
|
2394
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2395
|
+
seen.add(panel.id);
|
|
2396
|
+
if (panel.title.trim() === "")
|
|
2397
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2398
|
+
}
|
|
2399
|
+
};
|
|
2400
|
+
|
|
2401
|
+
// ../core/dist/admin-ui.js
|
|
2402
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2403
|
+
switch (char) {
|
|
2404
|
+
case "&":
|
|
2405
|
+
return "&";
|
|
2406
|
+
case "<":
|
|
2407
|
+
return "<";
|
|
2408
|
+
case ">":
|
|
2409
|
+
return ">";
|
|
2410
|
+
case '"':
|
|
2411
|
+
return """;
|
|
2412
|
+
default:
|
|
2413
|
+
return "'";
|
|
2414
|
+
}
|
|
2415
|
+
});
|
|
2416
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2417
|
+
var renderAdminDocument = (service) => {
|
|
2418
|
+
const name = escapeHtml(service);
|
|
2419
|
+
const script = adminClientSource({
|
|
2420
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2421
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2422
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2423
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2424
|
+
service
|
|
2425
|
+
});
|
|
2426
|
+
return `<!DOCTYPE html>
|
|
2427
|
+
<html lang="en">
|
|
2428
|
+
<head>
|
|
2429
|
+
<meta charset="utf-8">
|
|
2430
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2431
|
+
<meta name="color-scheme" content="light dark">
|
|
2432
|
+
<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">
|
|
2433
|
+
<title>${name} admin</title>
|
|
2434
|
+
<style>
|
|
2435
|
+
${CSS_RESET}
|
|
2436
|
+
:root {
|
|
2437
|
+
color-scheme: light;
|
|
2438
|
+
--bg: #fafafa;
|
|
2439
|
+
--bg-elev: #ffffff;
|
|
2440
|
+
--bg-muted: #f4f4f5;
|
|
2441
|
+
--bg-inset: #f4f4f5;
|
|
2442
|
+
--line: #dedee3;
|
|
2443
|
+
--line-strong: #c4c4cc;
|
|
2444
|
+
--ink: #18181b;
|
|
2445
|
+
--muted: #62626b;
|
|
2446
|
+
--faint: #71717a;
|
|
2447
|
+
--accent: #27272a;
|
|
2448
|
+
--accent-ink: #ffffff;
|
|
2449
|
+
--accent-soft: #f4f4f5;
|
|
2450
|
+
--ok: #166534;
|
|
2451
|
+
--ok-soft: #f0fdf4;
|
|
2452
|
+
--warn: #a16207;
|
|
2453
|
+
--warn-soft: #fefce8;
|
|
2454
|
+
--err: #a82d32;
|
|
2455
|
+
--err-soft: #fef2f2;
|
|
2456
|
+
--shadow: none;
|
|
2457
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2458
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2459
|
+
--radius: 10px;
|
|
2460
|
+
--header: 56px;
|
|
2461
|
+
--nav: 200px;
|
|
2462
|
+
}
|
|
2463
|
+
:root[data-theme="dark"] {
|
|
2464
|
+
color-scheme: dark;
|
|
2465
|
+
--bg: #111113;
|
|
2466
|
+
--bg-elev: #19191c;
|
|
2467
|
+
--bg-muted: #242428;
|
|
2468
|
+
--bg-inset: #111113;
|
|
2469
|
+
--line: #36363c;
|
|
2470
|
+
--line-strong: #52525b;
|
|
2471
|
+
--ink: #f4f4f5;
|
|
2472
|
+
--muted: #a9a9b2;
|
|
2473
|
+
--faint: #71717a;
|
|
2474
|
+
--accent: #e4e4e7;
|
|
2475
|
+
--accent-ink: #18181b;
|
|
2476
|
+
--accent-soft: #242428;
|
|
2477
|
+
--ok: #86efac;
|
|
2478
|
+
--ok-soft: #14241b;
|
|
2479
|
+
--warn: #fde68a;
|
|
2480
|
+
--warn-soft: #2a2410;
|
|
2481
|
+
--err: #ffaaaa;
|
|
2482
|
+
--err-soft: #2c1516;
|
|
2483
|
+
--shadow: none;
|
|
2484
|
+
}
|
|
2485
|
+
@media (prefers-color-scheme: dark) {
|
|
2486
|
+
:root:not([data-theme="light"]) {
|
|
2487
|
+
color-scheme: dark;
|
|
2488
|
+
--bg: #111113;
|
|
2489
|
+
--bg-elev: #19191c;
|
|
2490
|
+
--bg-muted: #242428;
|
|
2491
|
+
--bg-inset: #111113;
|
|
2492
|
+
--line: #36363c;
|
|
2493
|
+
--line-strong: #52525b;
|
|
2494
|
+
--ink: #f4f4f5;
|
|
2495
|
+
--muted: #a9a9b2;
|
|
2496
|
+
--faint: #71717a;
|
|
2497
|
+
--accent: #e4e4e7;
|
|
2498
|
+
--accent-ink: #18181b;
|
|
2499
|
+
--accent-soft: #242428;
|
|
2500
|
+
--ok: #86efac;
|
|
2501
|
+
--ok-soft: #14241b;
|
|
2502
|
+
--warn: #fde68a;
|
|
2503
|
+
--warn-soft: #2a2410;
|
|
2504
|
+
--err: #ffaaaa;
|
|
2505
|
+
--err-soft: #2c1516;
|
|
2506
|
+
--shadow: none;
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2510
|
+
html { height: 100%; }
|
|
2511
|
+
body {
|
|
2512
|
+
margin: 0;
|
|
2513
|
+
min-height: 100%;
|
|
2514
|
+
display: flex;
|
|
2515
|
+
flex-direction: column;
|
|
2516
|
+
font-family: var(--sans);
|
|
2517
|
+
background: var(--bg);
|
|
2518
|
+
color: var(--ink);
|
|
2519
|
+
line-height: 1.45;
|
|
2520
|
+
padding-left: env(safe-area-inset-left);
|
|
2521
|
+
padding-right: env(safe-area-inset-right);
|
|
2522
|
+
-webkit-text-size-adjust: 100%;
|
|
2523
|
+
}
|
|
2524
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2525
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2526
|
+
header.top {
|
|
2527
|
+
position: sticky; top: 0; z-index: 5;
|
|
2528
|
+
display: flex; align-items: center; gap: 12px;
|
|
2529
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2530
|
+
background: var(--bg-elev);
|
|
2531
|
+
border-bottom: 1px solid var(--line);
|
|
2532
|
+
min-width: 0; max-width: 100%;
|
|
2533
|
+
}
|
|
2534
|
+
.brand {
|
|
2535
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2536
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2537
|
+
}
|
|
2538
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2539
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2540
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2541
|
+
.vendor {
|
|
2542
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2543
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2544
|
+
}
|
|
2545
|
+
.vendor[hidden] { display: none; }
|
|
2546
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2547
|
+
.vendor img {
|
|
2548
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2549
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2550
|
+
}
|
|
2551
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2552
|
+
.vendor-sep { color: var(--faint); }
|
|
2553
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2554
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2555
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2556
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2557
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2558
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2559
|
+
padding: 7px 8px; min-height: 36px;
|
|
2560
|
+
}
|
|
2561
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2562
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2563
|
+
background: var(--bg-elev);
|
|
2564
|
+
}
|
|
2565
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2566
|
+
.btn-quiet { background: transparent; }
|
|
2567
|
+
.btn-danger { color: var(--err); }
|
|
2568
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2569
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2570
|
+
.layout {
|
|
2571
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2572
|
+
flex: 1 0 auto; min-width: 0;
|
|
2573
|
+
}
|
|
2574
|
+
nav.side {
|
|
2575
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2576
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2577
|
+
background: var(--bg-elev);
|
|
2578
|
+
}
|
|
2579
|
+
nav.side button {
|
|
2580
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2581
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2582
|
+
}
|
|
2583
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2584
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2585
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2586
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2587
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2588
|
+
.card {
|
|
2589
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2590
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2591
|
+
}
|
|
2592
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2593
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2594
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2595
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2596
|
+
.collection {
|
|
2597
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2598
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2599
|
+
}
|
|
2600
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2601
|
+
.collection small { display: block; color: var(--faint); }
|
|
2602
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2603
|
+
.chip {
|
|
2604
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2605
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2606
|
+
}
|
|
2607
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2608
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2609
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2610
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2611
|
+
tr.clickable { cursor: pointer; }
|
|
2612
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2613
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2614
|
+
pre {
|
|
2615
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2616
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2617
|
+
}
|
|
2618
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2619
|
+
.banner {
|
|
2620
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2621
|
+
background: var(--err-soft); color: var(--err);
|
|
2622
|
+
}
|
|
2623
|
+
.banner.show { display: block; }
|
|
2624
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2625
|
+
dialog {
|
|
2626
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2627
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2628
|
+
}
|
|
2629
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2630
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2631
|
+
textarea {
|
|
2632
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2633
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2634
|
+
font-family: var(--mono); font-size: 12px;
|
|
2635
|
+
}
|
|
2636
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2637
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2638
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2639
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2640
|
+
.status-2 { color: var(--ok); }
|
|
2641
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2642
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2643
|
+
.route {
|
|
2644
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2645
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2646
|
+
}
|
|
2647
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2648
|
+
@media (max-width: 800px) {
|
|
2649
|
+
header.top {
|
|
2650
|
+
align-items: stretch; flex-direction: column;
|
|
2651
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2652
|
+
}
|
|
2653
|
+
input, select, textarea { font-size: 16px; }
|
|
2654
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2655
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2656
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2657
|
+
nav.side {
|
|
2658
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2659
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2660
|
+
padding: 8px;
|
|
2661
|
+
}
|
|
2662
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2663
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2664
|
+
main { padding: 14px; }
|
|
2665
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2666
|
+
thead { display: none; }
|
|
2667
|
+
tr {
|
|
2668
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2669
|
+
background: var(--bg-elev); min-width: 0;
|
|
2670
|
+
}
|
|
2671
|
+
td {
|
|
2672
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2673
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2674
|
+
}
|
|
2675
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2676
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2677
|
+
.route button { grid-column: 1 / -1; }
|
|
2678
|
+
}
|
|
2679
|
+
</style>
|
|
2680
|
+
</head>
|
|
2681
|
+
<body>
|
|
2682
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2683
|
+
<header class="top">
|
|
2684
|
+
<div class="brand">
|
|
2685
|
+
<div class="brand-id">
|
|
2686
|
+
<strong>${name}</strong>
|
|
2687
|
+
<span>Admin</span>
|
|
2688
|
+
</div>
|
|
2689
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2690
|
+
</div>
|
|
2691
|
+
<div class="controls">
|
|
2692
|
+
<label class="field">Namespace
|
|
2693
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2694
|
+
</label>
|
|
2695
|
+
<label class="field">Admin key
|
|
2696
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2697
|
+
</label>
|
|
2698
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2699
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2700
|
+
</div>
|
|
2701
|
+
</header>
|
|
2702
|
+
<div class="layout">
|
|
2703
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2704
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2705
|
+
<button type="button" data-view="state">State</button>
|
|
2706
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2707
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2708
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2709
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2710
|
+
</nav>
|
|
2711
|
+
<main id="views">
|
|
2712
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2713
|
+
<section class="view" id="view-overview">
|
|
2714
|
+
<h2>Overview</h2>
|
|
2715
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2716
|
+
<div class="grid" id="overview-cards"></div>
|
|
2717
|
+
<h3>Recent requests</h3>
|
|
2718
|
+
<div id="overview-requests"></div>
|
|
2719
|
+
</section>
|
|
2720
|
+
<section class="view" id="view-state" hidden>
|
|
2721
|
+
<h2>State</h2>
|
|
2722
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2723
|
+
<div class="split">
|
|
2724
|
+
<div id="collections"></div>
|
|
2725
|
+
<div>
|
|
2726
|
+
<div id="schema"></div>
|
|
2727
|
+
<div class="row-actions">
|
|
2728
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2729
|
+
</div>
|
|
2730
|
+
<div id="records"></div>
|
|
2731
|
+
</div>
|
|
2732
|
+
</div>
|
|
2733
|
+
</section>
|
|
2734
|
+
<section class="view" id="view-clock" hidden>
|
|
2735
|
+
<h2>Clock</h2>
|
|
2736
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
2737
|
+
<div class="card" id="clock-readout"></div>
|
|
2738
|
+
<div class="row-actions">
|
|
2739
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
2740
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
2741
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
2742
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
2743
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
2744
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
2745
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
2746
|
+
</div>
|
|
2747
|
+
<form id="clock-set" class="row-actions">
|
|
2748
|
+
<label class="field">Set instant
|
|
2749
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
2750
|
+
</label>
|
|
2751
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
2752
|
+
</form>
|
|
2753
|
+
</section>
|
|
2754
|
+
<section class="view" id="view-faults" hidden>
|
|
2755
|
+
<h2>Faults</h2>
|
|
2756
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
2757
|
+
<form id="fault-form" class="card stack">
|
|
2758
|
+
<label class="field">Preset
|
|
2759
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
2760
|
+
</label>
|
|
2761
|
+
<label class="field">Status
|
|
2762
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
2763
|
+
</label>
|
|
2764
|
+
<label class="field">Path prefix
|
|
2765
|
+
<input id="fault-path" placeholder="/v1">
|
|
2766
|
+
</label>
|
|
2767
|
+
<label class="field">Method
|
|
2768
|
+
<input id="fault-method" placeholder="GET">
|
|
2769
|
+
</label>
|
|
2770
|
+
<div class="dialog-actions">
|
|
2771
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
2772
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
2773
|
+
</div>
|
|
2774
|
+
</form>
|
|
2775
|
+
<div id="fault-list"></div>
|
|
2776
|
+
</section>
|
|
2777
|
+
<section class="view" id="view-journal" hidden>
|
|
2778
|
+
<h2>Journal</h2>
|
|
2779
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
2780
|
+
<div class="row-actions">
|
|
2781
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
2782
|
+
</div>
|
|
2783
|
+
<div id="journal"></div>
|
|
2784
|
+
</section>
|
|
2785
|
+
<section class="view" id="view-routes" hidden>
|
|
2786
|
+
<h2>Routes</h2>
|
|
2787
|
+
<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>
|
|
2788
|
+
<div id="route-list"></div>
|
|
2789
|
+
<form id="route-form" class="card stack">
|
|
2790
|
+
<strong id="route-title">Select a route</strong>
|
|
2791
|
+
<label class="field">JSON body
|
|
2792
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
2793
|
+
</label>
|
|
2794
|
+
<div class="dialog-actions">
|
|
2795
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
2796
|
+
</div>
|
|
2797
|
+
<pre id="route-result">Response will show here.</pre>
|
|
2798
|
+
</form>
|
|
2799
|
+
</section>
|
|
2800
|
+
</main>
|
|
2801
|
+
</div>
|
|
2802
|
+
</div>
|
|
2803
|
+
<dialog id="editor">
|
|
2804
|
+
<form method="dialog" id="editor-form">
|
|
2805
|
+
<strong id="editor-title">Record</strong>
|
|
2806
|
+
<label class="field">Id
|
|
2807
|
+
<input id="editor-id" required>
|
|
2808
|
+
</label>
|
|
2809
|
+
<label class="field">JSON value
|
|
2810
|
+
<textarea id="editor-value"></textarea>
|
|
2811
|
+
</label>
|
|
2812
|
+
<div class="dialog-actions">
|
|
2813
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
2814
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
2815
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
2816
|
+
</div>
|
|
2817
|
+
</form>
|
|
2818
|
+
</dialog>
|
|
2819
|
+
${script}
|
|
2820
|
+
</body>
|
|
2821
|
+
</html>`;
|
|
2822
|
+
};
|
|
2823
|
+
var htmlResponse = (body) => new Response(body, {
|
|
2824
|
+
status: 200,
|
|
2825
|
+
headers: {
|
|
2826
|
+
"content-type": "text/html; charset=utf-8",
|
|
2827
|
+
"cache-control": "no-store"
|
|
2828
|
+
}
|
|
2829
|
+
});
|
|
2830
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
2831
|
+
status: 200,
|
|
2832
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
2833
|
+
});
|
|
2834
|
+
var adminUiRoutes = (service, ui) => {
|
|
2835
|
+
const shell = () => renderAdminDocument(service);
|
|
2836
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
2837
|
+
return {
|
|
2838
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
2839
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
2840
|
+
"GET /ui/manifest": () => json2({
|
|
2841
|
+
service,
|
|
2842
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
2843
|
+
id: panel.id,
|
|
2844
|
+
title: panel.title,
|
|
2845
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
2846
|
+
html: panel.html,
|
|
2847
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
2848
|
+
}))
|
|
2849
|
+
})
|
|
2850
|
+
};
|
|
2851
|
+
};
|
|
2852
|
+
|
|
1120
2853
|
// ../../openapi/metadata/dist/types.js
|
|
1121
2854
|
var EXTENSION_KEYS = {
|
|
1122
2855
|
operation: "x-mockingbird",
|
|
@@ -1129,11 +2862,11 @@ var EXTENSION_KEYS = {
|
|
|
1129
2862
|
};
|
|
1130
2863
|
|
|
1131
2864
|
// ../../openapi/metadata/dist/read.js
|
|
1132
|
-
var
|
|
2865
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1133
2866
|
var extensionOf = (holder, key) => holder[key];
|
|
1134
2867
|
var operationMetadata = (operation) => {
|
|
1135
2868
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
1136
|
-
const ext =
|
|
2869
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
1137
2870
|
const supported = ext.supported ?? true;
|
|
1138
2871
|
const parity = ext.parity ?? {};
|
|
1139
2872
|
return {
|
|
@@ -1169,9 +2902,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
1169
2902
|
this.name = "OperationRegistryError";
|
|
1170
2903
|
}
|
|
1171
2904
|
};
|
|
1172
|
-
var verifyOperations = (
|
|
2905
|
+
var verifyOperations = (document3, handlers) => {
|
|
1173
2906
|
const problems = [];
|
|
1174
|
-
const operations = listOperations(
|
|
2907
|
+
const operations = listOperations(document3);
|
|
1175
2908
|
const seen = /* @__PURE__ */ new Set();
|
|
1176
2909
|
for (const operation of operations) {
|
|
1177
2910
|
if (seen.has(operation.operationId))
|
|
@@ -1280,8 +3013,442 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1280
3013
|
});
|
|
1281
3014
|
};
|
|
1282
3015
|
|
|
3016
|
+
// ../core/dist/state-view.js
|
|
3017
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
3018
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
3019
|
+
var SAMPLE = 25;
|
|
3020
|
+
var WALK_LIMIT = 1e4;
|
|
3021
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3022
|
+
var fail = (status, message) => ({ ok: false, status, message });
|
|
3023
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3024
|
+
var kindOf = (value) => {
|
|
3025
|
+
if (value === null)
|
|
3026
|
+
return "null";
|
|
3027
|
+
if (Array.isArray(value))
|
|
3028
|
+
return "array";
|
|
3029
|
+
switch (typeof value) {
|
|
3030
|
+
case "string":
|
|
3031
|
+
return "string";
|
|
3032
|
+
case "number":
|
|
3033
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3034
|
+
case "boolean":
|
|
3035
|
+
return "boolean";
|
|
3036
|
+
case "object":
|
|
3037
|
+
return "object";
|
|
3038
|
+
default:
|
|
3039
|
+
return "unknown";
|
|
3040
|
+
}
|
|
3041
|
+
};
|
|
3042
|
+
var humanize = (name) => {
|
|
3043
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3044
|
+
if (words === "")
|
|
3045
|
+
return name;
|
|
3046
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3047
|
+
};
|
|
3048
|
+
var jsonValue = (value) => {
|
|
3049
|
+
if (value === void 0)
|
|
3050
|
+
return fail(400, "value is required");
|
|
3051
|
+
try {
|
|
3052
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3053
|
+
} catch {
|
|
3054
|
+
return fail(400, "value must be JSON");
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
3057
|
+
var ctorName = (value) => {
|
|
3058
|
+
const ctor = value.constructor;
|
|
3059
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3060
|
+
};
|
|
3061
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3062
|
+
var discoverCollections = (root) => {
|
|
3063
|
+
const found = [];
|
|
3064
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3065
|
+
const visit = (value, depth) => {
|
|
3066
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3067
|
+
return;
|
|
3068
|
+
if (value === null || typeof value !== "object")
|
|
3069
|
+
return;
|
|
3070
|
+
if (seen.has(value))
|
|
3071
|
+
return;
|
|
3072
|
+
seen.add(value);
|
|
3073
|
+
if (value instanceof Collection) {
|
|
3074
|
+
found.push(value);
|
|
3075
|
+
return;
|
|
3076
|
+
}
|
|
3077
|
+
if (value instanceof Map) {
|
|
3078
|
+
for (const child of value.values())
|
|
3079
|
+
visit(child, depth + 1);
|
|
3080
|
+
return;
|
|
3081
|
+
}
|
|
3082
|
+
if (value instanceof Set) {
|
|
3083
|
+
for (const child of value.values())
|
|
3084
|
+
visit(child, depth + 1);
|
|
3085
|
+
return;
|
|
3086
|
+
}
|
|
3087
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3088
|
+
return;
|
|
3089
|
+
if (Array.isArray(value)) {
|
|
3090
|
+
const cap = Math.min(value.length, 32);
|
|
3091
|
+
for (let i = 0; i < cap; i++)
|
|
3092
|
+
visit(value[i], depth + 1);
|
|
3093
|
+
return;
|
|
3094
|
+
}
|
|
3095
|
+
let children;
|
|
3096
|
+
try {
|
|
3097
|
+
children = Object.values(value);
|
|
3098
|
+
} catch {
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
for (const child of children)
|
|
3102
|
+
visit(child, depth + 1);
|
|
3103
|
+
};
|
|
3104
|
+
visit(root, 0);
|
|
3105
|
+
return found;
|
|
3106
|
+
};
|
|
3107
|
+
var storedNames = (sqlite, namespace) => {
|
|
3108
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3109
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3110
|
+
return [...records, ...sequences].map((row2) => row2.name);
|
|
3111
|
+
};
|
|
3112
|
+
var blankAccum = (name) => ({
|
|
3113
|
+
name,
|
|
3114
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3115
|
+
present: 0,
|
|
3116
|
+
nested: /* @__PURE__ */ new Map()
|
|
3117
|
+
});
|
|
3118
|
+
var absorb = (accum, value) => {
|
|
3119
|
+
const kind = kindOf(value);
|
|
3120
|
+
accum.kinds.add(kind);
|
|
3121
|
+
accum.present++;
|
|
3122
|
+
if (!isRecord4(value))
|
|
3123
|
+
return;
|
|
3124
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3125
|
+
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
3126
|
+
absorb(nested, child);
|
|
3127
|
+
accum.nested.set(key, nested);
|
|
3128
|
+
}
|
|
3129
|
+
};
|
|
3130
|
+
var finishField = (accum, samples) => {
|
|
3131
|
+
const kinds = [...accum.kinds];
|
|
3132
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3133
|
+
const field = {
|
|
3134
|
+
name: accum.name,
|
|
3135
|
+
kind,
|
|
3136
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3137
|
+
};
|
|
3138
|
+
if (accum.nested.size > 0) {
|
|
3139
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3140
|
+
}
|
|
3141
|
+
return field;
|
|
3142
|
+
};
|
|
3143
|
+
var inferFields = (records) => {
|
|
3144
|
+
if (records.length === 0)
|
|
3145
|
+
return [];
|
|
3146
|
+
const sample = records.slice(0, SAMPLE);
|
|
3147
|
+
const objects = sample.filter((record) => isRecord4(record.value));
|
|
3148
|
+
if (objects.length === 0) {
|
|
3149
|
+
const kinds = new Set(sample.map((record) => kindOf(record.value)));
|
|
3150
|
+
const list = [...kinds];
|
|
3151
|
+
return [
|
|
3152
|
+
{
|
|
3153
|
+
name: "(value)",
|
|
3154
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3155
|
+
optional: false
|
|
3156
|
+
}
|
|
3157
|
+
];
|
|
3158
|
+
}
|
|
3159
|
+
const root = /* @__PURE__ */ new Map();
|
|
3160
|
+
for (const record of objects) {
|
|
3161
|
+
for (const [key, value] of Object.entries(record.value)) {
|
|
3162
|
+
const accum = root.get(key) ?? blankAccum(key);
|
|
3163
|
+
absorb(accum, value);
|
|
3164
|
+
root.set(key, accum);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3168
|
+
};
|
|
3169
|
+
var mergeFields = (declared, inferred) => {
|
|
3170
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3171
|
+
for (const field of inferred)
|
|
3172
|
+
byName.set(field.name, field);
|
|
3173
|
+
const ordered = [];
|
|
3174
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3175
|
+
for (const field of declared ?? []) {
|
|
3176
|
+
const found = byName.get(field.name);
|
|
3177
|
+
seen.add(field.name);
|
|
3178
|
+
if (!found) {
|
|
3179
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3180
|
+
continue;
|
|
3181
|
+
}
|
|
3182
|
+
ordered.push({
|
|
3183
|
+
...found,
|
|
3184
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3185
|
+
optional: field.optional || found.optional,
|
|
3186
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3187
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3188
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3189
|
+
});
|
|
3190
|
+
}
|
|
3191
|
+
for (const field of inferred) {
|
|
3192
|
+
if (!seen.has(field.name))
|
|
3193
|
+
ordered.push(field);
|
|
3194
|
+
}
|
|
3195
|
+
return ordered;
|
|
3196
|
+
};
|
|
3197
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3198
|
+
var readRecord = (collection, id) => {
|
|
3199
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3200
|
+
const row2 = rows.find((entry) => entry.id === id);
|
|
3201
|
+
return row2 ? { id: row2.id, seq: row2.seq, value: row2.value } : void 0;
|
|
3202
|
+
};
|
|
3203
|
+
var inspectState = (scope) => {
|
|
3204
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3205
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3206
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3207
|
+
declared.set(declaration.name, declaration);
|
|
3208
|
+
}
|
|
3209
|
+
const names = new Set(declared.keys());
|
|
3210
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3211
|
+
names.add(name);
|
|
3212
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3213
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3214
|
+
names.add(collection.collectionName);
|
|
3215
|
+
}
|
|
3216
|
+
const collections = [];
|
|
3217
|
+
for (const name of names) {
|
|
3218
|
+
if (!COLLECTION_NAME.test(name))
|
|
3219
|
+
continue;
|
|
3220
|
+
const declaration = declared.get(name);
|
|
3221
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3222
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row2) => ({ id: row2.id, seq: row2.seq, value: row2.value }));
|
|
3223
|
+
const inferred = inferFields(records);
|
|
3224
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3225
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3226
|
+
collections.push({
|
|
3227
|
+
name,
|
|
3228
|
+
label: declaration?.label ?? humanize(name),
|
|
3229
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3230
|
+
count: collection.count(),
|
|
3231
|
+
source,
|
|
3232
|
+
fields,
|
|
3233
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
const order = /* @__PURE__ */ new Map();
|
|
3237
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3238
|
+
order.set(item.name, index);
|
|
3239
|
+
collections.sort((a, b) => {
|
|
3240
|
+
const left = order.get(a.name);
|
|
3241
|
+
const right = order.get(b.name);
|
|
3242
|
+
if (left !== void 0 && right !== void 0)
|
|
3243
|
+
return left - right;
|
|
3244
|
+
if (left !== void 0)
|
|
3245
|
+
return -1;
|
|
3246
|
+
if (right !== void 0)
|
|
3247
|
+
return 1;
|
|
3248
|
+
return a.name.localeCompare(b.name);
|
|
3249
|
+
});
|
|
3250
|
+
return {
|
|
3251
|
+
namespace: scope.namespace,
|
|
3252
|
+
storageNamespace: scope.storageNamespace,
|
|
3253
|
+
collections
|
|
3254
|
+
};
|
|
3255
|
+
};
|
|
3256
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3257
|
+
if (!COLLECTION_NAME.test(name))
|
|
3258
|
+
return fail(400, "collection name is not allowed");
|
|
3259
|
+
const limit = query.limit ?? 50;
|
|
3260
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3261
|
+
return fail(400, "limit must be an integer from 1 to 200");
|
|
3262
|
+
}
|
|
3263
|
+
const order = query.order ?? "newest";
|
|
3264
|
+
if (order !== "newest" && order !== "oldest")
|
|
3265
|
+
return fail(400, 'order must be "newest" or "oldest"');
|
|
3266
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3267
|
+
const rows = collection.list({ order }).filter((row2) => {
|
|
3268
|
+
if (query.after === void 0)
|
|
3269
|
+
return true;
|
|
3270
|
+
return order === "newest" ? row2.seq < query.after : row2.seq > query.after;
|
|
3271
|
+
});
|
|
3272
|
+
const slice = rows.slice(0, limit);
|
|
3273
|
+
const last = slice.at(-1);
|
|
3274
|
+
return {
|
|
3275
|
+
ok: true,
|
|
3276
|
+
value: {
|
|
3277
|
+
collection: name,
|
|
3278
|
+
count: collection.count(),
|
|
3279
|
+
records: slice.map((row2) => ({ id: row2.id, seq: row2.seq, value: row2.value })),
|
|
3280
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
};
|
|
3284
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3285
|
+
var readStateRecord = (scope, name, id) => {
|
|
3286
|
+
if (!COLLECTION_NAME.test(name))
|
|
3287
|
+
return fail(400, "collection name is not allowed");
|
|
3288
|
+
if (!RECORD_ID.test(id))
|
|
3289
|
+
return fail(400, "record id is not allowed");
|
|
3290
|
+
const record = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3291
|
+
return record ? { ok: true, value: record } : fail(404, `no record ${id} in ${name}`);
|
|
3292
|
+
};
|
|
3293
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
|
|
3294
|
+
var createStateRecord = (scope, name, input) => {
|
|
3295
|
+
if (!COLLECTION_NAME.test(name))
|
|
3296
|
+
return fail(400, "collection name is not allowed");
|
|
3297
|
+
const parsed = jsonValue(input.value);
|
|
3298
|
+
if (!parsed.ok)
|
|
3299
|
+
return parsed;
|
|
3300
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3301
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3302
|
+
const checked = requireId(id);
|
|
3303
|
+
if (!checked.ok)
|
|
3304
|
+
return checked;
|
|
3305
|
+
if (collection.has(checked.value))
|
|
3306
|
+
return fail(409, `record ${checked.value} already exists`);
|
|
3307
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3308
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3309
|
+
};
|
|
3310
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3311
|
+
if (!COLLECTION_NAME.test(name))
|
|
3312
|
+
return fail(400, "collection name is not allowed");
|
|
3313
|
+
const checked = requireId(id);
|
|
3314
|
+
if (!checked.ok)
|
|
3315
|
+
return checked;
|
|
3316
|
+
const parsed = jsonValue(value);
|
|
3317
|
+
if (!parsed.ok)
|
|
3318
|
+
return parsed;
|
|
3319
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3320
|
+
if (!collection.has(checked.value))
|
|
3321
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3322
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3323
|
+
if (!stored)
|
|
3324
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3325
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3326
|
+
};
|
|
3327
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3328
|
+
const current = readStateRecord(scope, name, id);
|
|
3329
|
+
if (!current.ok)
|
|
3330
|
+
return current;
|
|
3331
|
+
const parsed = jsonValue(value);
|
|
3332
|
+
if (!parsed.ok)
|
|
3333
|
+
return parsed;
|
|
3334
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3335
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3336
|
+
};
|
|
3337
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3338
|
+
if (!COLLECTION_NAME.test(name))
|
|
3339
|
+
return fail(400, "collection name is not allowed");
|
|
3340
|
+
const checked = requireId(id);
|
|
3341
|
+
if (!checked.ok)
|
|
3342
|
+
return checked;
|
|
3343
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3344
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
|
|
3345
|
+
};
|
|
3346
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3347
|
+
status,
|
|
3348
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3349
|
+
});
|
|
3350
|
+
var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
|
|
3351
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3352
|
+
var integerParam = (value) => {
|
|
3353
|
+
if (value === null)
|
|
3354
|
+
return void 0;
|
|
3355
|
+
if (!/^-?\d+$/.test(value))
|
|
3356
|
+
return "bad";
|
|
3357
|
+
return Number(value);
|
|
3358
|
+
};
|
|
3359
|
+
var stateAdminRoutes = (routes) => {
|
|
3360
|
+
const open = (namespace) => {
|
|
3361
|
+
try {
|
|
3362
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3363
|
+
} catch (error) {
|
|
3364
|
+
return fail(400, error instanceof Error ? error.message : String(error));
|
|
3365
|
+
}
|
|
3366
|
+
};
|
|
3367
|
+
const wrote = (namespace) => {
|
|
3368
|
+
routes.afterWrite?.(namespace);
|
|
3369
|
+
};
|
|
3370
|
+
return {
|
|
3371
|
+
"GET /state": ({ namespace }) => {
|
|
3372
|
+
const scope = open(namespace);
|
|
3373
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3374
|
+
},
|
|
3375
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3376
|
+
const scope = open(namespace);
|
|
3377
|
+
if (!scope.ok)
|
|
3378
|
+
return fromResult(scope, 200);
|
|
3379
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3380
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3381
|
+
if (limit === "bad")
|
|
3382
|
+
return adminError2(400, "limit: expected an integer");
|
|
3383
|
+
if (after === "bad")
|
|
3384
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3385
|
+
const order = url.searchParams.get("order");
|
|
3386
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3387
|
+
...limit !== void 0 ? { limit } : {},
|
|
3388
|
+
...after !== void 0 ? { after } : {},
|
|
3389
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3390
|
+
}), 200);
|
|
3391
|
+
},
|
|
3392
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3393
|
+
const scope = open(namespace);
|
|
3394
|
+
if (!scope.ok)
|
|
3395
|
+
return fromResult(scope, 200);
|
|
3396
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3397
|
+
},
|
|
3398
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3399
|
+
const scope = open(namespace);
|
|
3400
|
+
if (!scope.ok)
|
|
3401
|
+
return fromResult(scope, 201);
|
|
3402
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
3403
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3404
|
+
}
|
|
3405
|
+
const id = body.id;
|
|
3406
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3407
|
+
return adminError2(400, "id must be a string");
|
|
3408
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3409
|
+
...typeof id === "string" ? { id } : {},
|
|
3410
|
+
value: body.value
|
|
3411
|
+
});
|
|
3412
|
+
if (created.ok)
|
|
3413
|
+
wrote(namespace);
|
|
3414
|
+
return fromResult(created, 201);
|
|
3415
|
+
},
|
|
3416
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3417
|
+
const scope = open(namespace);
|
|
3418
|
+
if (!scope.ok)
|
|
3419
|
+
return fromResult(scope, 200);
|
|
3420
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3421
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3422
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3423
|
+
if (replaced.ok)
|
|
3424
|
+
wrote(namespace);
|
|
3425
|
+
return fromResult(replaced, 200);
|
|
3426
|
+
},
|
|
3427
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3428
|
+
const scope = open(namespace);
|
|
3429
|
+
if (!scope.ok)
|
|
3430
|
+
return fromResult(scope, 200);
|
|
3431
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3432
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3433
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3434
|
+
if (patched.ok)
|
|
3435
|
+
wrote(namespace);
|
|
3436
|
+
return fromResult(patched, 200);
|
|
3437
|
+
},
|
|
3438
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3439
|
+
const scope = open(namespace);
|
|
3440
|
+
if (!scope.ok)
|
|
3441
|
+
return fromResult(scope, 200);
|
|
3442
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3443
|
+
if (removed.ok)
|
|
3444
|
+
wrote(namespace);
|
|
3445
|
+
return fromResult(removed, 200);
|
|
3446
|
+
}
|
|
3447
|
+
};
|
|
3448
|
+
};
|
|
3449
|
+
|
|
1283
3450
|
// ../core/dist/version.js
|
|
1284
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3451
|
+
var PACKAGE_VERSION = true ? "1.6.0" : UNRELEASED_VERSION;
|
|
1285
3452
|
|
|
1286
3453
|
// ../core/dist/signing.js
|
|
1287
3454
|
var encoder = new TextEncoder();
|
|
@@ -1295,11 +3462,11 @@ var toBase64 = (bytes) => {
|
|
|
1295
3462
|
var fromBase64 = (value) => Uint8Array.from(atob(value), (char) => char.charCodeAt(0));
|
|
1296
3463
|
|
|
1297
3464
|
// ../core/dist/webhooks.js
|
|
1298
|
-
var
|
|
1299
|
-
var
|
|
1300
|
-
var
|
|
3465
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
3466
|
+
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
3467
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1301
3468
|
var parseEndpoint = (value) => {
|
|
1302
|
-
if (!
|
|
3469
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
1303
3470
|
return "each endpoint needs a url";
|
|
1304
3471
|
try {
|
|
1305
3472
|
new URL(value.url);
|
|
@@ -1316,18 +3483,18 @@ var parseEndpoint = (value) => {
|
|
|
1316
3483
|
const events = value.events ?? value.enabledEvents;
|
|
1317
3484
|
if (Array.isArray(events))
|
|
1318
3485
|
endpoint.events = events.map(String);
|
|
1319
|
-
if (
|
|
3486
|
+
if (isRecord5(value.tags)) {
|
|
1320
3487
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
1321
3488
|
}
|
|
1322
3489
|
if (typeof value.account === "string")
|
|
1323
3490
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
1324
|
-
if (
|
|
3491
|
+
if (isRecord5(value.headers)) {
|
|
1325
3492
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
1326
3493
|
}
|
|
1327
3494
|
return endpoint;
|
|
1328
3495
|
};
|
|
1329
3496
|
var webhookAdminRoutes = (hub) => ({
|
|
1330
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
3497
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
1331
3498
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
1332
3499
|
const type = url.searchParams.get("type");
|
|
1333
3500
|
return type === null || d.type === type;
|
|
@@ -1335,51 +3502,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
1335
3502
|
}),
|
|
1336
3503
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
1337
3504
|
const type = url.searchParams.get("type");
|
|
1338
|
-
return
|
|
3505
|
+
return json4(200, {
|
|
1339
3506
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
1340
3507
|
});
|
|
1341
3508
|
},
|
|
1342
3509
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
1343
3510
|
const replayed = await hub.replay(params.id);
|
|
1344
|
-
return replayed ?
|
|
3511
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
1345
3512
|
},
|
|
1346
3513
|
"POST /webhooks/flush": async () => {
|
|
1347
3514
|
await hub.flush();
|
|
1348
|
-
return
|
|
3515
|
+
return json4(200, { status: "ok" });
|
|
1349
3516
|
},
|
|
1350
3517
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
1351
|
-
if (!
|
|
1352
|
-
return
|
|
3518
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
3519
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
1353
3520
|
}
|
|
1354
3521
|
const fault = { mode: body.mode };
|
|
1355
3522
|
if (typeof body.count === "number")
|
|
1356
3523
|
fault.count = body.count;
|
|
1357
3524
|
hub.fault(namespace, fault);
|
|
1358
|
-
return
|
|
3525
|
+
return json4(201, { namespace, ...fault });
|
|
1359
3526
|
},
|
|
1360
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
3527
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
1361
3528
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
1362
3529
|
...rest,
|
|
1363
3530
|
secret: secret ? "(set)" : null
|
|
1364
3531
|
}))
|
|
1365
3532
|
}),
|
|
1366
3533
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
1367
|
-
const list = Array.isArray(body) ? body :
|
|
3534
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
1368
3535
|
if (!Array.isArray(list))
|
|
1369
|
-
return
|
|
3536
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
1370
3537
|
const parsed = [];
|
|
1371
3538
|
for (const each of list) {
|
|
1372
3539
|
const endpoint = parseEndpoint(each);
|
|
1373
3540
|
if (typeof endpoint === "string")
|
|
1374
|
-
return
|
|
3541
|
+
return adminError3(400, endpoint);
|
|
1375
3542
|
parsed.push(endpoint);
|
|
1376
3543
|
}
|
|
1377
3544
|
const set = hub.setEndpoints(namespace, parsed);
|
|
1378
|
-
return
|
|
3545
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
1379
3546
|
},
|
|
1380
3547
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
1381
3548
|
hub.setEndpoints(namespace, []);
|
|
1382
|
-
return
|
|
3549
|
+
return json4(200, { status: "ok" });
|
|
1383
3550
|
}
|
|
1384
3551
|
});
|
|
1385
3552
|
var parsePayload = (message) => {
|
|
@@ -1434,8 +3601,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
1434
3601
|
this.name = "TypeError";
|
|
1435
3602
|
}
|
|
1436
3603
|
};
|
|
1437
|
-
var operationMatcher = (
|
|
1438
|
-
const matchers = listOperations(
|
|
3604
|
+
var operationMatcher = (document3) => {
|
|
3605
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
1439
3606
|
operationId: operation.operationId,
|
|
1440
3607
|
method: operation.method.toUpperCase(),
|
|
1441
3608
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -1444,6 +3611,7 @@ var operationMatcher = (document2) => {
|
|
|
1444
3611
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
1445
3612
|
};
|
|
1446
3613
|
var createRuntime = (options) => {
|
|
3614
|
+
assertAdminUi(options.adminUi);
|
|
1447
3615
|
const sqlite = bootSqlite(options.sqlite);
|
|
1448
3616
|
const clock = options.clock ?? createClock();
|
|
1449
3617
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -1529,10 +3697,10 @@ var createRuntime = (options) => {
|
|
|
1529
3697
|
const ensureBranch = (namespace, branch2, at) => {
|
|
1530
3698
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
1531
3699
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
1532
|
-
const
|
|
3700
|
+
const history2 = timeline(namespace);
|
|
1533
3701
|
if (branch2 === "main") {
|
|
1534
3702
|
if (at !== void 0) {
|
|
1535
|
-
const point =
|
|
3703
|
+
const point = history2.checkout("main", at);
|
|
1536
3704
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
1537
3705
|
captured.set(namespace, point.value.snapshot);
|
|
1538
3706
|
rng.setState(point.value.rngState);
|
|
@@ -1545,10 +3713,10 @@ var createRuntime = (options) => {
|
|
|
1545
3713
|
return namespace;
|
|
1546
3714
|
}
|
|
1547
3715
|
const storage = physicalBranch(namespace, branch2);
|
|
1548
|
-
if (!
|
|
3716
|
+
if (!history2.hasBranch(branch2)) {
|
|
1549
3717
|
if (at === void 0)
|
|
1550
|
-
|
|
1551
|
-
const point =
|
|
3718
|
+
history2.commit(capture(namespace));
|
|
3719
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
1552
3720
|
const branchRng = createRng(options.seed ?? 0);
|
|
1553
3721
|
if (point)
|
|
1554
3722
|
branchRng.setState(point.value.rngState);
|
|
@@ -1557,8 +3725,8 @@ var createRuntime = (options) => {
|
|
|
1557
3725
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1558
3726
|
if (point)
|
|
1559
3727
|
captured.set(storage, point.value.snapshot);
|
|
1560
|
-
} else if (at !== void 0 &&
|
|
1561
|
-
const point =
|
|
3728
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
3729
|
+
const point = history2.checkout(branch2, at);
|
|
1562
3730
|
if (!instances.has(storage)) {
|
|
1563
3731
|
const branchRng = createRng(options.seed ?? 0);
|
|
1564
3732
|
branchRng.setState(point.value.rngState);
|
|
@@ -1569,7 +3737,7 @@ var createRuntime = (options) => {
|
|
|
1569
3737
|
captured.set(storage, point.value.snapshot);
|
|
1570
3738
|
} else {
|
|
1571
3739
|
if (!instances.has(storage)) {
|
|
1572
|
-
const point =
|
|
3740
|
+
const point = history2.head(branch2);
|
|
1573
3741
|
const branchRng = createRng(options.seed ?? 0);
|
|
1574
3742
|
if (point)
|
|
1575
3743
|
branchRng.setState(point.value.rngState);
|
|
@@ -1593,8 +3761,8 @@ var createRuntime = (options) => {
|
|
|
1593
3761
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
1594
3762
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
1595
3763
|
const branchName = checkoutOptions.branch ?? "main";
|
|
1596
|
-
const
|
|
1597
|
-
const point =
|
|
3764
|
+
const history2 = timeline(namespace);
|
|
3765
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
1598
3766
|
const storage = ensureBranch(namespace, branchName);
|
|
1599
3767
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1600
3768
|
captured.set(storage, point.value.snapshot);
|
|
@@ -1644,12 +3812,25 @@ var createRuntime = (options) => {
|
|
|
1644
3812
|
instance(name);
|
|
1645
3813
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
1646
3814
|
captured.set(name, from);
|
|
1647
|
-
const
|
|
1648
|
-
if (
|
|
1649
|
-
|
|
3815
|
+
const history2 = timelines.get(name);
|
|
3816
|
+
if (history2)
|
|
3817
|
+
history2.commit(capture(name), { branch: "main" });
|
|
1650
3818
|
else
|
|
1651
3819
|
timeline(name);
|
|
1652
3820
|
};
|
|
3821
|
+
const declarationsFor = (namespace) => {
|
|
3822
|
+
const declared = options.state;
|
|
3823
|
+
if (!declared)
|
|
3824
|
+
return [];
|
|
3825
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
3826
|
+
};
|
|
3827
|
+
const stateScope = (namespace) => ({
|
|
3828
|
+
sqlite,
|
|
3829
|
+
namespace,
|
|
3830
|
+
storageNamespace: storageNamespace(namespace),
|
|
3831
|
+
root: instance(namespace),
|
|
3832
|
+
declarations: declarationsFor(namespace)
|
|
3833
|
+
});
|
|
1653
3834
|
const runtime = {
|
|
1654
3835
|
name: options.name,
|
|
1655
3836
|
sqlite,
|
|
@@ -1688,6 +3869,7 @@ var createRuntime = (options) => {
|
|
|
1688
3869
|
branch,
|
|
1689
3870
|
checkout,
|
|
1690
3871
|
timeline,
|
|
3872
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
1691
3873
|
fetch: async (incoming) => {
|
|
1692
3874
|
let request = incoming;
|
|
1693
3875
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -1861,10 +4043,10 @@ var createRuntime = (options) => {
|
|
|
1861
4043
|
},
|
|
1862
4044
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
1863
4045
|
inspect: (name) => {
|
|
1864
|
-
const
|
|
4046
|
+
const history2 = timeline(name);
|
|
1865
4047
|
return {
|
|
1866
|
-
branches:
|
|
1867
|
-
checkpoints:
|
|
4048
|
+
branches: history2.branches(),
|
|
4049
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
1868
4050
|
id,
|
|
1869
4051
|
branch: branchName,
|
|
1870
4052
|
parent,
|
|
@@ -1879,13 +4061,22 @@ var createRuntime = (options) => {
|
|
|
1879
4061
|
} : {},
|
|
1880
4062
|
routes: {
|
|
1881
4063
|
...credentialRoutes(credentials),
|
|
1882
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
1883
4064
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
1884
|
-
...options.admin?.(runtime) ?? {}
|
|
4065
|
+
...options.admin?.(runtime) ?? {},
|
|
4066
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4067
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4068
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4069
|
+
...stateAdminRoutes({
|
|
4070
|
+
open: stateScope,
|
|
4071
|
+
afterWrite: (namespace) => {
|
|
4072
|
+
checkpoint(namespace, "main");
|
|
4073
|
+
}
|
|
4074
|
+
}),
|
|
4075
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
1885
4076
|
},
|
|
1886
4077
|
adminKey: options.adminKey
|
|
1887
4078
|
});
|
|
1888
|
-
return runtime;
|
|
4079
|
+
return defineMock(runtime);
|
|
1889
4080
|
};
|
|
1890
4081
|
var mutableResponse = (response) => {
|
|
1891
4082
|
try {
|
|
@@ -1949,9 +4140,12 @@ var credentialRoutes = (registry) => ({
|
|
|
1949
4140
|
}
|
|
1950
4141
|
});
|
|
1951
4142
|
var presetRoutes = (presets, runtime) => ({
|
|
1952
|
-
"GET /faults/presets": () =>
|
|
1953
|
-
|
|
1954
|
-
|
|
4143
|
+
"GET /faults/presets": () => {
|
|
4144
|
+
const body = {
|
|
4145
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4146
|
+
};
|
|
4147
|
+
return adminJson(200, body);
|
|
4148
|
+
},
|
|
1955
4149
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
1956
4150
|
const name = params.name;
|
|
1957
4151
|
if (!presets[name])
|
|
@@ -1962,7 +4156,7 @@ var presetRoutes = (presets, runtime) => ({
|
|
|
1962
4156
|
});
|
|
1963
4157
|
|
|
1964
4158
|
// src/generated/openapi.ts
|
|
1965
|
-
var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Google Places, Geocoding and Maps JavaScript API (Mockingbird subset)","description":"The Google Maps Platform surface our member app calls: Places Autocomplete, Place Details\\nand Find Place From Text (the legacy JSON web services), the Geocoding API, and the Maps\\nJavaScript API loader (\`/maps/api/js?libraries=places\`). Every web-service answer is HTTP 200\\nwith Google's \`status\` field; the mock resolves addresses from a QA corpus.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from Google's documented response shapes and the fields our consumer reads (address-autocomplete-native-rest.tsx, address-autocomplete-web.tsx, use-geocoded-address.ts). Google publishes no OpenAPI document for these endpoints."}},"servers":[{"url":"https://maps.googleapis.com"}],"paths":{"/maps/api/place/autocomplete/json":{"get":{"operationId":"PlaceAutocomplete","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"input","in":"query","required":true,"schema":{"type":"string","minLength":1,"maxLength":60,"examples":["1625 N Central","Phoenix","85004","4821 Maple Street Denver","200 N Spring St, Los Angeles","136 Murray"]}},{"name":"types","in":"query","schema":{"type":"string","enum":["address","geocode"]}},{"name":"components","in":"query","schema":{"type":"string","enum":["country:us","country:ca","country:us|country:ca"]}},{"$ref":"#/components/parameters/SessionToken"}],"responses":{"200":{"description":"Predictions, or a non-OK status (HTTP 200 either way)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AutocompleteResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/place/details/json":{"get":{"operationId":"PlaceDetails","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"place_id","in":"query","required":true,"schema":{"type":"string","minLength":1,"maxLength":200,"examples":["ChIJ5BKAwJuCB5951g03ZzrkHx9","ChIJE1ellR5XyWiy2lHIlJ5cls3","ChIJaWYsCINV1XBQQ97jO3pznpg","EieyJsIjoiNDgyMSBNYXBsZSBTdHJlZXQiLCJjIjoiRGVudmVyIiwicyI6IkNPIiwieiI6IjgwMjAyIiwibiI6IkRlbnZlciBDb3VudHkiLCJhIjozOS43NDc4OCwibyI6LTEwNC45OTQyNX0","ChIJdoesNotExist000000000"]}},{"name":"fields","in":"query","schema":{"type":"string","enum":["address_component","address_components","geometry","formatted_address,geometry","place_id,name,types","address_component,geometry,formatted_address"]}},{"$ref":"#/components/parameters/SessionToken"}],"responses":{"200":{"description":"The place, or a non-OK status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DetailsResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/geocode/json":{"get":{"operationId":"Geocode","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"address","in":"query","schema":{"type":"string","minLength":1,"maxLength":80,"examples":["1625 N Central Ave, Phoenix, AZ 85004","88 Greenwich St, New York, NY 10006","4821 Maple Street, Denver, CO 80202","85004","Phoenix, AZ","1625 N Central Ave"]}},{"name":"place_id","in":"query","schema":{"type":"string","examples":["ChIJ5BKAwJuCB5951g03ZzrkHx9"]}},{"name":"components","in":"query","schema":{"type":"string","enum":["postal_code:85004","postal_code:10006","postal_code:00000"]}}],"responses":{"200":{"description":"Geocoding results, or a non-OK status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GeocodeResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/place/findplacefromtext/json":{"get":{"operationId":"FindPlaceFromText","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"input","in":"query","required":true,"schema":{"type":"string","minLength":1,"maxLength":80,"examples":["1625 N Central Ave, Phoenix, AZ 85004","1625 N Central","Gilbert"]}},{"name":"inputtype","in":"query","required":true,"schema":{"type":"string","enum":["textquery","phonenumber"]}},{"name":"fields","in":"query","schema":{"type":"string","enum":["geometry","formatted_address,geometry","place_id,name","place_id"]}}],"responses":{"200":{"description":"Candidates, or a non-OK status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FindPlaceResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/js":{"get":{"operationId":"MapsJavaScriptApi","description":"The Maps JavaScript API loader. The mock serves a shim defining google.maps.places (AutocompleteService, PlacesService, AutocompleteSessionToken, PlacesServiceStatus) and google.maps.Geocoder, backed by the REST operations above.","x-mockingbird":{"supported":true,"parity":{"enabled":false,"reason":"A JavaScript program, not data: it is exercised by evaluating it in a fake window and driving our web client through it (google-maps.acceptance.test.ts)."}},"parameters":[{"name":"key","in":"query","schema":{"type":"string"}},{"name":"libraries","in":"query","schema":{"type":"string"}},{"name":"callback","in":"query","schema":{"type":"string"}},{"name":"v","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"The Maps JavaScript shim","content":{"text/javascript":{"schema":{"type":"string"}}}},"503":{"description":"Script unavailable (script_unavailable preset)","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/v1:validateAddress":{"servers":[{"url":"https://addressvalidation.googleapis.com"}],"post":{"operationId":"ValidateAddress","description":"Address Validation API v1 validateAddress, with USPS CASS data (\`enableUspsCass\`). A Google Cloud API: errors are HTTP 4xx/5xx with a \`google.rpc.Status\` envelope, and the key may also be sent as the \`X-Goog-Api-Key\` header. Responses are proto3 JSON (false booleans and empty lists omitted). Reference: https://developers.google.com/maps/documentation/address-validation/reference/rest/v1/TopLevel/validateAddress","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidateAddressRequest"}}}},"responses":{"200":{"description":"The validation result","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidateAddressResponse"}}}},"400":{"description":"INVALID_ARGUMENT (malformed request, unsupported region, invalid API key)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoogleApiError"}}}},"403":{"description":"PERMISSION_DENIED (missing key; address_validation_denied preset)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoogleApiError"}}}},"503":{"description":"UNAVAILABLE (address_validation_unavailable preset)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoogleApiError"}}}}}}}},"components":{"parameters":{"Key":{"name":"key","in":"query","required":true,"description":"The Google Maps Platform API key (\`PLACES_KEY\`); also the namespace credential.","schema":{"type":"string","minLength":1,"maxLength":40,"examples":["parity-key"]}},"SessionToken":{"name":"sessiontoken","in":"query","description":"Autocomplete session token (billing grouping); accepted and journaled as metadata.","schema":{"type":"string","format":"uuid"}}},"schemas":{"Status":{"type":"string","enum":["OK","ZERO_RESULTS","INVALID_REQUEST","OVER_QUERY_LIMIT","REQUEST_DENIED","UNKNOWN_ERROR","NOT_FOUND"]},"LatLng":{"type":"object","required":["lat","lng"],"properties":{"lat":{"type":"number"},"lng":{"type":"number"}}},"Viewport":{"type":"object","required":["northeast","southwest"],"properties":{"northeast":{"$ref":"#/components/schemas/LatLng"},"southwest":{"$ref":"#/components/schemas/LatLng"}}},"Geometry":{"type":"object","required":["location","viewport"],"properties":{"location":{"$ref":"#/components/schemas/LatLng"},"location_type":{"type":"string","enum":["ROOFTOP","RANGE_INTERPOLATED","GEOMETRIC_CENTER","APPROXIMATE"]},"viewport":{"$ref":"#/components/schemas/Viewport"}}},"AddressComponent":{"type":"object","required":["long_name","short_name","types"],"properties":{"long_name":{"type":"string"},"short_name":{"type":"string"},"types":{"type":"array","items":{"type":"string"}}}},"MatchedSubstring":{"type":"object","required":["length","offset"],"properties":{"length":{"type":"integer"},"offset":{"type":"integer"}}},"Prediction":{"type":"object","required":["description","place_id","reference","structured_formatting","terms","types","matched_substrings"],"properties":{"description":{"type":"string"},"matched_substrings":{"type":"array","items":{"$ref":"#/components/schemas/MatchedSubstring"}},"place_id":{"type":"string","x-mockingbird-resource":{"type":"place","identity":true}},"reference":{"type":"string"},"structured_formatting":{"type":"object","required":["main_text","secondary_text"],"properties":{"main_text":{"type":"string"},"main_text_matched_substrings":{"type":"array","items":{"$ref":"#/components/schemas/MatchedSubstring"}},"secondary_text":{"type":"string"}}},"terms":{"type":"array","items":{"type":"object","required":["offset","value"],"properties":{"offset":{"type":"integer"},"value":{"type":"string"}}}},"types":{"type":"array","items":{"type":"string"}}}},"PlaceResult":{"type":"object","description":"Only the fields requested with \`fields=\` are present.","properties":{"address_components":{"type":"array","items":{"$ref":"#/components/schemas/AddressComponent"}},"adr_address":{"type":"string"},"formatted_address":{"type":"string"},"geometry":{"$ref":"#/components/schemas/Geometry"},"name":{"type":"string"},"place_id":{"type":"string"},"reference":{"type":"string"},"types":{"type":"array","items":{"type":"string"}},"url":{"type":"string"},"utc_offset":{"type":"integer"},"vicinity":{"type":"string"}}},"AutocompleteResponse":{"type":"object","required":["predictions","status"],"properties":{"predictions":{"type":"array","items":{"$ref":"#/components/schemas/Prediction"}},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"DetailsResponse":{"type":"object","required":["html_attributions","status"],"properties":{"html_attributions":{"type":"array","items":{"type":"string"}},"result":{"$ref":"#/components/schemas/PlaceResult"},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"GeocodeResult":{"type":"object","required":["address_components","formatted_address","geometry","place_id","types"],"properties":{"address_components":{"type":"array","items":{"$ref":"#/components/schemas/AddressComponent"}},"formatted_address":{"type":"string"},"geometry":{"$ref":"#/components/schemas/Geometry"},"place_id":{"type":"string"},"types":{"type":"array","items":{"type":"string"}}}},"GeocodeResponse":{"type":"object","required":["results","status"],"properties":{"results":{"type":"array","items":{"$ref":"#/components/schemas/GeocodeResult"}},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"FindPlaceResponse":{"type":"object","required":["candidates","status"],"properties":{"candidates":{"type":"array","items":{"$ref":"#/components/schemas/PlaceResult"}},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"GoogleApiError":{"type":"object","required":["error"],"properties":{"error":{"type":"object","required":["code","message","status"],"properties":{"code":{"type":"integer"},"message":{"type":"string"},"status":{"type":"string"},"details":{"type":"array","items":{"type":"object"}}}}}},"PostalAddress":{"type":"object","description":"google.type.PostalAddress","properties":{"revision":{"type":"integer"},"regionCode":{"type":"string","examples":["US"]},"languageCode":{"type":"string"},"postalCode":{"type":"string","examples":["85004","10006","80202","90012","00000"]},"sortingCode":{"type":"string"},"administrativeArea":{"type":"string","examples":["AZ","NY","CO","CA"]},"locality":{"type":"string","examples":["Phoenix","New York","Denver","Los Angeles","Springfield"]},"sublocality":{"type":"string"},"addressLines":{"type":"array","maxItems":3,"items":{"type":"string","maxLength":80,"examples":["1625 N Central Ave","1625 North Central Avenue Building A","4821 Maple Street","N Central Ave","Apt 2"]}},"recipients":{"type":"array","items":{"type":"string"}},"organization":{"type":"string"}}},"ValidateAddressRequest":{"type":"object","required":["address"],"additionalProperties":false,"properties":{"address":{"$ref":"#/components/schemas/PostalAddress","examples":[{"regionCode":"US","addressLines":["1625 N Central Ave"],"locality":"Phoenix","administrativeArea":"AZ","postalCode":"85004"},{"regionCode":"US","addressLines":["4821 Maple Street"],"locality":"Denver","administrativeArea":"CO","postalCode":"80202"},{"regionCode":"US","addressLines":["N Central Ave"],"locality":"Phoenix","administrativeArea":"AZ","postalCode":"85004"},{"regionCode":"US","addressLines":["1625 N Central Ave, Phoenix, AZ 85004"]},{"regionCode":"US","addressLines":["12 Nowhere Rd"],"locality":"Springfield","administrativeArea":"ZZ","postalCode":"00000"}]},"previousResponseId":{"type":"string"},"enableUspsCass":{"type":"boolean"},"languageOptions":{"type":"object"},"sessionToken":{"type":"string"}}},"ValidationAddressComponent":{"type":"object","required":["componentName","componentType","confirmationLevel"],"properties":{"componentName":{"type":"object","required":["text"],"properties":{"text":{"type":"string"},"languageCode":{"type":"string"}}},"componentType":{"type":"string"},"confirmationLevel":{"type":"string","enum":["CONFIRMED","UNCONFIRMED_BUT_PLAUSIBLE","UNCONFIRMED_AND_SUSPICIOUS"]},"inferred":{"type":"boolean"},"spellCorrected":{"type":"boolean"},"replaced":{"type":"boolean"},"unexpected":{"type":"boolean"}}},"Granularity":{"type":"string","enum":["GRANULARITY_UNSPECIFIED","SUB_PREMISE","PREMISE","PREMISE_PROXIMITY","BLOCK","ROUTE","OTHER"]},"ValidationResult":{"type":"object","properties":{"verdict":{"type":"object","properties":{"inputGranularity":{"$ref":"#/components/schemas/Granularity"},"validationGranularity":{"$ref":"#/components/schemas/Granularity"},"geocodeGranularity":{"$ref":"#/components/schemas/Granularity"},"addressComplete":{"type":"boolean"},"hasUnconfirmedComponents":{"type":"boolean"},"hasInferredComponents":{"type":"boolean"},"hasReplacedComponents":{"type":"boolean"},"hasSpellCorrectedComponents":{"type":"boolean"},"possibleNextAction":{"type":"string","enum":["POSSIBLE_NEXT_ACTION_UNSPECIFIED","FIX","CONFIRM_ADD_SUBPREMISES","CONFIRM","ACCEPT"]}}},"address":{"type":"object","properties":{"formattedAddress":{"type":"string"},"postalAddress":{"$ref":"#/components/schemas/PostalAddress"},"addressComponents":{"type":"array","items":{"$ref":"#/components/schemas/ValidationAddressComponent"}},"missingComponentTypes":{"type":"array","items":{"type":"string"}},"unconfirmedComponentTypes":{"type":"array","items":{"type":"string"}},"unresolvedTokens":{"type":"array","items":{"type":"string"}}}},"geocode":{"type":"object","properties":{"location":{"type":"object","properties":{"latitude":{"type":"number"},"longitude":{"type":"number"}}},"placeId":{"type":"string"},"placeTypes":{"type":"array","items":{"type":"string"}}}},"uspsData":{"type":"object","properties":{"standardizedAddress":{"type":"object","properties":{"firstAddressLine":{"type":"string"},"secondAddressLine":{"type":"string"},"cityStateZipAddressLine":{"type":"string"},"city":{"type":"string"},"state":{"type":"string"},"zipCode":{"type":"string"},"zipCodeExtension":{"type":"string"}}},"dpvConfirmation":{"type":"string","enum":["Y","N","S","D"]},"dpvFootnote":{"type":"string"},"postOfficeCity":{"type":"string"},"postOfficeState":{"type":"string"},"errorMessage":{"type":"string"},"cassProcessed":{"type":"boolean"}}}}},"ValidateAddressResponse":{"type":"object","required":["result","responseId"],"properties":{"result":{"$ref":"#/components/schemas/ValidationResult"},"responseId":{"type":"string"}}}}}}`);
|
|
4159
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Google Places, Geocoding and Maps JavaScript API (Mockingbird subset)","description":"The Google Maps Platform surface our member app calls: Places Autocomplete, Place Details\\nand Find Place From Text (the legacy JSON web services), the Geocoding API, and the Maps\\nJavaScript API loader (\`/maps/api/js?libraries=places\`). Every web-service answer is HTTP 200\\nwith Google's \`status\` field; the mock resolves addresses from a QA corpus.\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from Google's documented response shapes and the fields our consumer reads (address-autocomplete-native-rest.tsx, address-autocomplete-web.tsx, use-geocoded-address.ts). Google publishes no OpenAPI document for these endpoints."}},"servers":[{"url":"https://maps.googleapis.com"}],"paths":{"/maps/api/place/autocomplete/json":{"get":{"operationId":"PlaceAutocomplete","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"input","in":"query","required":true,"schema":{"type":"string","minLength":1,"maxLength":60,"examples":["1625 N Central","Phoenix","85004","4821 Maple Street Denver","200 N Spring St, Los Angeles","136 Murray"]}},{"name":"types","in":"query","schema":{"type":"string","enum":["address","geocode"]}},{"name":"components","in":"query","schema":{"type":"string","enum":["country:us","country:ca","country:us|country:ca"]}},{"$ref":"#/components/parameters/SessionToken"}],"responses":{"200":{"description":"Predictions, or a non-OK status (HTTP 200 either way)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AutocompleteResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/place/details/json":{"get":{"operationId":"PlaceDetails","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"place_id","in":"query","required":true,"schema":{"type":"string","minLength":1,"maxLength":200,"examples":["ChIJ5BKAwJuCB5951g03ZzrkHx9","ChIJE1ellR5XyWiy2lHIlJ5cls3","ChIJaWYsCINV1XBQQ97jO3pznpg","EieyJsIjoiNDgyMSBNYXBsZSBTdHJlZXQiLCJjIjoiRGVudmVyIiwicyI6IkNPIiwieiI6IjgwMjAyIiwibiI6IkRlbnZlciBDb3VudHkiLCJhIjozOS43NDc4OCwibyI6LTEwNC45OTQyNX0","ChIJdoesNotExist000000000"]}},{"name":"fields","in":"query","schema":{"type":"string","enum":["address_component","address_components","geometry","formatted_address,geometry","place_id,name,types","address_component,geometry,formatted_address"]}},{"$ref":"#/components/parameters/SessionToken"}],"responses":{"200":{"description":"The place, or a non-OK status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DetailsResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/geocode/json":{"get":{"operationId":"Geocode","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"address","in":"query","schema":{"type":"string","minLength":1,"maxLength":80,"examples":["1625 N Central Ave, Phoenix, AZ 85004","88 Greenwich St, New York, NY 10006","4821 Maple Street, Denver, CO 80202","85004","Phoenix, AZ","1625 N Central Ave"]}},{"name":"place_id","in":"query","schema":{"type":"string","examples":["ChIJ5BKAwJuCB5951g03ZzrkHx9"]}},{"name":"components","in":"query","schema":{"type":"string","enum":["postal_code:85004","postal_code:10006","postal_code:00000"]}}],"responses":{"200":{"description":"Geocoding results, or a non-OK status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GeocodeResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/place/findplacefromtext/json":{"get":{"operationId":"FindPlaceFromText","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"},{"name":"input","in":"query","required":true,"schema":{"type":"string","minLength":1,"maxLength":80,"examples":["1625 N Central Ave, Phoenix, AZ 85004","1625 N Central","Gilbert"]}},{"name":"inputtype","in":"query","required":true,"schema":{"type":"string","enum":["textquery","phonenumber"]}},{"name":"fields","in":"query","schema":{"type":"string","enum":["geometry","formatted_address,geometry","place_id,name","place_id"]}}],"responses":{"200":{"description":"Candidates, or a non-OK status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/FindPlaceResponse"}}}},"500":{"description":"Google front-end failure (server_error preset)","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/maps/api/js":{"get":{"operationId":"MapsJavaScriptApi","description":"The Maps JavaScript API loader. The mock serves a shim defining google.maps.places (AutocompleteService, PlacesService, AutocompleteSessionToken, PlacesServiceStatus) and google.maps.Geocoder, backed by the REST operations above.","x-mockingbird":{"supported":true,"parity":{"enabled":false,"reason":"A JavaScript program, not data: it is exercised by evaluating it in a fake window and driving our web client through it (google-maps.acceptance.test.ts)."}},"parameters":[{"name":"key","in":"query","schema":{"type":"string"}},{"name":"libraries","in":"query","schema":{"type":"string"}},{"name":"callback","in":"query","schema":{"type":"string"}},{"name":"v","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"The Maps JavaScript shim","content":{"text/javascript":{"schema":{"type":"string"}}}},"503":{"description":"Script unavailable (script_unavailable preset)","content":{"text/plain":{"schema":{"type":"string"}}}}}}},"/v1:validateAddress":{"servers":[{"url":"https://addressvalidation.googleapis.com"}],"post":{"operationId":"ValidateAddress","description":"Address Validation API v1 validateAddress, with USPS CASS data (\`enableUspsCass\`). A Google Cloud API: errors are HTTP 4xx/5xx with a \`google.rpc.Status\` envelope, and the key may also be sent as the \`X-Goog-Api-Key\` header. Responses are proto3 JSON (false booleans and empty lists omitted). Reference: https://developers.google.com/maps/documentation/address-validation/reference/rest/v1/TopLevel/validateAddress","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"$ref":"#/components/parameters/Key"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidateAddressRequest"}}}},"responses":{"200":{"description":"The validation result","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidateAddressResponse"}}}},"400":{"description":"INVALID_ARGUMENT (malformed request, unsupported region, invalid API key)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoogleApiError"}}}},"403":{"description":"PERMISSION_DENIED (missing key; address_validation_denied preset)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoogleApiError"}}}},"503":{"description":"UNAVAILABLE (address_validation_unavailable preset)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/GoogleApiError"}}}}}}}},"components":{"parameters":{"Key":{"name":"key","in":"query","required":true,"description":"The Google Maps Platform API key (\`PLACES_KEY\`); also the namespace credential.","schema":{"type":"string","minLength":1,"maxLength":40,"examples":["parity-key"]}},"SessionToken":{"name":"sessiontoken","in":"query","description":"Autocomplete session token (billing grouping); accepted and journaled as metadata.","schema":{"type":"string","format":"uuid"}}},"schemas":{"Status":{"type":"string","enum":["OK","ZERO_RESULTS","INVALID_REQUEST","OVER_QUERY_LIMIT","REQUEST_DENIED","UNKNOWN_ERROR","NOT_FOUND"]},"LatLng":{"type":"object","required":["lat","lng"],"properties":{"lat":{"type":"number"},"lng":{"type":"number"}}},"Viewport":{"type":"object","required":["northeast","southwest"],"properties":{"northeast":{"$ref":"#/components/schemas/LatLng"},"southwest":{"$ref":"#/components/schemas/LatLng"}}},"Geometry":{"type":"object","required":["location","viewport"],"properties":{"location":{"$ref":"#/components/schemas/LatLng"},"location_type":{"type":"string","enum":["ROOFTOP","RANGE_INTERPOLATED","GEOMETRIC_CENTER","APPROXIMATE"]},"viewport":{"$ref":"#/components/schemas/Viewport"}}},"AddressComponent":{"type":"object","required":["long_name","short_name","types"],"properties":{"long_name":{"type":"string"},"short_name":{"type":"string"},"types":{"type":"array","items":{"type":"string"}}}},"MatchedSubstring":{"type":"object","required":["length","offset"],"properties":{"length":{"type":"integer"},"offset":{"type":"integer"}}},"Prediction":{"type":"object","required":["description","place_id","reference","structured_formatting","terms","types","matched_substrings"],"properties":{"description":{"type":"string"},"matched_substrings":{"type":"array","items":{"$ref":"#/components/schemas/MatchedSubstring"}},"place_id":{"type":"string","x-mockingbird-resource":{"type":"place","identity":true}},"reference":{"type":"string"},"structured_formatting":{"type":"object","required":["main_text","secondary_text"],"properties":{"main_text":{"type":"string"},"main_text_matched_substrings":{"type":"array","items":{"$ref":"#/components/schemas/MatchedSubstring"}},"secondary_text":{"type":"string"}}},"terms":{"type":"array","items":{"type":"object","required":["offset","value"],"properties":{"offset":{"type":"integer"},"value":{"type":"string"}}}},"types":{"type":"array","items":{"type":"string"}}}},"PlaceResult":{"type":"object","description":"Only the fields requested with \`fields=\` are present.","properties":{"address_components":{"type":"array","items":{"$ref":"#/components/schemas/AddressComponent"}},"adr_address":{"type":"string"},"formatted_address":{"type":"string"},"geometry":{"$ref":"#/components/schemas/Geometry"},"name":{"type":"string"},"place_id":{"type":"string"},"reference":{"type":"string"},"types":{"type":"array","items":{"type":"string"}},"url":{"type":"string"},"utc_offset":{"type":"integer"},"vicinity":{"type":"string"}}},"AutocompleteResponse":{"type":"object","required":["predictions","status"],"properties":{"predictions":{"type":"array","items":{"$ref":"#/components/schemas/Prediction"}},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"DetailsResponse":{"type":"object","required":["html_attributions","status"],"properties":{"html_attributions":{"type":"array","items":{"type":"string"}},"result":{"$ref":"#/components/schemas/PlaceResult"},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"GeocodeResult":{"type":"object","required":["address_components","formatted_address","geometry","place_id","types"],"properties":{"address_components":{"type":"array","items":{"$ref":"#/components/schemas/AddressComponent"}},"formatted_address":{"type":"string"},"geometry":{"$ref":"#/components/schemas/Geometry"},"place_id":{"type":"string"},"types":{"type":"array","items":{"type":"string"}}}},"GeocodeResponse":{"type":"object","required":["results","status"],"properties":{"results":{"type":"array","items":{"$ref":"#/components/schemas/GeocodeResult"}},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"FindPlaceResponse":{"type":"object","required":["candidates","status"],"properties":{"candidates":{"type":"array","items":{"$ref":"#/components/schemas/PlaceResult"}},"status":{"$ref":"#/components/schemas/Status"},"error_message":{"type":"string"}}},"GoogleApiError":{"type":"object","required":["error"],"properties":{"error":{"type":"object","required":["code","message","status"],"properties":{"code":{"type":"integer"},"message":{"type":"string"},"status":{"type":"string"},"details":{"type":"array","items":{"type":"object"}}}}}},"PostalAddress":{"type":"object","description":"google.type.PostalAddress","properties":{"revision":{"type":"integer"},"regionCode":{"type":"string","examples":["US"]},"languageCode":{"type":"string"},"postalCode":{"type":"string","examples":["85004","10006","80202","90012","00000"]},"sortingCode":{"type":"string"},"administrativeArea":{"type":"string","examples":["AZ","NY","CO","CA"]},"locality":{"type":"string","examples":["Phoenix","New York","Denver","Los Angeles","Springfield"]},"sublocality":{"type":"string"},"addressLines":{"type":"array","maxItems":3,"items":{"type":"string","maxLength":80,"examples":["1625 N Central Ave","1625 North Central Avenue Building A","4821 Maple Street","N Central Ave","Apt 2"]}},"recipients":{"type":"array","items":{"type":"string"}},"organization":{"type":"string"}}},"ValidateAddressRequest":{"type":"object","required":["address"],"additionalProperties":false,"properties":{"address":{"$ref":"#/components/schemas/PostalAddress","examples":[{"regionCode":"US","addressLines":["1625 N Central Ave"],"locality":"Phoenix","administrativeArea":"AZ","postalCode":"85004"},{"regionCode":"US","addressLines":["4821 Maple Street"],"locality":"Denver","administrativeArea":"CO","postalCode":"80202"},{"regionCode":"US","addressLines":["N Central Ave"],"locality":"Phoenix","administrativeArea":"AZ","postalCode":"85004"},{"regionCode":"US","addressLines":["1625 N Central Ave, Phoenix, AZ 85004"]},{"regionCode":"US","addressLines":["12 Nowhere Rd"],"locality":"Springfield","administrativeArea":"ZZ","postalCode":"00000"}]},"previousResponseId":{"type":"string"},"enableUspsCass":{"type":"boolean"},"languageOptions":{"type":"object"},"sessionToken":{"type":"string"}}},"ValidationAddressComponent":{"type":"object","required":["componentName","componentType","confirmationLevel"],"properties":{"componentName":{"type":"object","required":["text"],"properties":{"text":{"type":"string"},"languageCode":{"type":"string"}}},"componentType":{"type":"string"},"confirmationLevel":{"type":"string","enum":["CONFIRMED","UNCONFIRMED_BUT_PLAUSIBLE","UNCONFIRMED_AND_SUSPICIOUS"]},"inferred":{"type":"boolean"},"spellCorrected":{"type":"boolean"},"replaced":{"type":"boolean"},"unexpected":{"type":"boolean"}}},"Granularity":{"type":"string","enum":["GRANULARITY_UNSPECIFIED","SUB_PREMISE","PREMISE","PREMISE_PROXIMITY","BLOCK","ROUTE","OTHER"]},"ValidationResult":{"type":"object","properties":{"verdict":{"type":"object","properties":{"inputGranularity":{"$ref":"#/components/schemas/Granularity"},"validationGranularity":{"$ref":"#/components/schemas/Granularity"},"geocodeGranularity":{"$ref":"#/components/schemas/Granularity"},"addressComplete":{"type":"boolean"},"hasUnconfirmedComponents":{"type":"boolean"},"hasInferredComponents":{"type":"boolean"},"hasReplacedComponents":{"type":"boolean"},"hasSpellCorrectedComponents":{"type":"boolean"},"possibleNextAction":{"type":"string","enum":["POSSIBLE_NEXT_ACTION_UNSPECIFIED","FIX","CONFIRM_ADD_SUBPREMISES","CONFIRM","ACCEPT"]}}},"address":{"type":"object","properties":{"formattedAddress":{"type":"string"},"postalAddress":{"$ref":"#/components/schemas/PostalAddress"},"addressComponents":{"type":"array","items":{"$ref":"#/components/schemas/ValidationAddressComponent"}},"missingComponentTypes":{"type":"array","items":{"type":"string"}},"unconfirmedComponentTypes":{"type":"array","items":{"type":"string"}},"unresolvedTokens":{"type":"array","items":{"type":"string"}}}},"geocode":{"type":"object","properties":{"location":{"type":"object","properties":{"latitude":{"type":"number"},"longitude":{"type":"number"}}},"placeId":{"type":"string"},"placeTypes":{"type":"array","items":{"type":"string"}}}},"uspsData":{"type":"object","properties":{"standardizedAddress":{"type":"object","properties":{"firstAddressLine":{"type":"string"},"secondAddressLine":{"type":"string"},"cityStateZipAddressLine":{"type":"string"},"city":{"type":"string"},"state":{"type":"string"},"zipCode":{"type":"string"},"zipCodeExtension":{"type":"string"}}},"dpvConfirmation":{"type":"string","enum":["Y","N","S","D"]},"dpvFootnote":{"type":"string"},"postOfficeCity":{"type":"string"},"postOfficeState":{"type":"string"},"errorMessage":{"type":"string"},"cassProcessed":{"type":"boolean"}}}}},"ValidateAddressResponse":{"type":"object","required":["result","responseId"],"properties":{"result":{"$ref":"#/components/schemas/ValidationResult"},"responseId":{"type":"string"}}}}}}`);
|
|
1966
4160
|
var operationIds = ["PlaceAutocomplete", "PlaceDetails", "Geocode", "FindPlaceFromText", "MapsJavaScriptApi", "ValidateAddress"];
|
|
1967
4161
|
var supportedOperationIds = ["PlaceAutocomplete", "PlaceDetails", "Geocode", "FindPlaceFromText", "MapsJavaScriptApi", "ValidateAddress"];
|
|
1968
4162
|
|
|
@@ -3072,7 +5266,7 @@ var POSTAL_ADDRESS = /* @__PURE__ */ new Set([
|
|
|
3072
5266
|
var MAX_INPUT_LENGTH = 280;
|
|
3073
5267
|
var MAX_ADDRESS_LINES = 3;
|
|
3074
5268
|
var MAX_ADDRESS_LINE_LENGTH = 80;
|
|
3075
|
-
var
|
|
5269
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3076
5270
|
var optionalString = (value, field) => {
|
|
3077
5271
|
if (value === void 0 || value === null) return void 0;
|
|
3078
5272
|
if (typeof value !== "string") {
|
|
@@ -3084,7 +5278,7 @@ var optionalString = (value, field) => {
|
|
|
3084
5278
|
return trimmed ? trimmed : void 0;
|
|
3085
5279
|
};
|
|
3086
5280
|
var parseValidateRequest = (body) => {
|
|
3087
|
-
if (!
|
|
5281
|
+
if (!isRecord6(body)) throw new ValidationRequestError("Invalid JSON payload received.");
|
|
3088
5282
|
for (const key of Object.keys(body)) {
|
|
3089
5283
|
if (!TOP_LEVEL.has(key)) {
|
|
3090
5284
|
throw new ValidationRequestError(
|
|
@@ -3096,7 +5290,7 @@ var parseValidateRequest = (body) => {
|
|
|
3096
5290
|
if (address === void 0 || address === null) {
|
|
3097
5291
|
throw new ValidationRequestError("Address is missing from the request.");
|
|
3098
5292
|
}
|
|
3099
|
-
if (!
|
|
5293
|
+
if (!isRecord6(address)) {
|
|
3100
5294
|
throw new ValidationRequestError(
|
|
3101
5295
|
`Invalid value at 'address' (type.googleapis.com/google.type.PostalAddress), ${JSON.stringify(address)}`
|
|
3102
5296
|
);
|
|
@@ -3665,14 +5859,14 @@ var GOOGLE_MAPS_PRESETS = {
|
|
|
3665
5859
|
rules: [{ operationId: "MapsJavaScriptApi", status: 503, body: "Service Unavailable" }]
|
|
3666
5860
|
}
|
|
3667
5861
|
};
|
|
3668
|
-
var
|
|
3669
|
-
var
|
|
3670
|
-
var
|
|
5862
|
+
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
5863
|
+
var adminError4 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
|
|
5864
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3671
5865
|
var stringList = (value) => Array.isArray(value) && value.every((v) => typeof v === "string") ? value : void 0;
|
|
3672
5866
|
var parseValidation = (value, index) => {
|
|
3673
5867
|
if (value === void 0 || value === null) return void 0;
|
|
3674
5868
|
const at = `addresses[${index}].validation`;
|
|
3675
|
-
if (!
|
|
5869
|
+
if (!isRecord7(value)) return `${at} must be an object`;
|
|
3676
5870
|
const out = {};
|
|
3677
5871
|
const enums = [
|
|
3678
5872
|
["granularity", GRANULARITIES],
|
|
@@ -3706,7 +5900,7 @@ var parseValidation = (value, index) => {
|
|
|
3706
5900
|
return out;
|
|
3707
5901
|
};
|
|
3708
5902
|
var parseAddress = (value, index) => {
|
|
3709
|
-
if (!
|
|
5903
|
+
if (!isRecord7(value)) return `addresses[${index}] must be an object`;
|
|
3710
5904
|
for (const key of ["line1", "city", "state", "zip"]) {
|
|
3711
5905
|
if (typeof value[key] !== "string" || !value[key].trim()) {
|
|
3712
5906
|
return `addresses[${index}].${key} must be a non-empty string`;
|
|
@@ -3736,15 +5930,15 @@ var parseAddress = (value, index) => {
|
|
|
3736
5930
|
var adminRoutes = (runtime) => ({
|
|
3737
5931
|
"GET /corpus": ({ namespace }) => {
|
|
3738
5932
|
const api = runtime.instance(namespace);
|
|
3739
|
-
return
|
|
5933
|
+
return json5(200, {
|
|
3740
5934
|
addresses: api.corpus(),
|
|
3741
5935
|
custom: api.state.custom.count()
|
|
3742
5936
|
});
|
|
3743
5937
|
},
|
|
3744
5938
|
"PUT /corpus": ({ body, namespace }) => {
|
|
3745
|
-
const list = Array.isArray(body) ? body :
|
|
5939
|
+
const list = Array.isArray(body) ? body : isRecord7(body) ? body.addresses : void 0;
|
|
3746
5940
|
if (!Array.isArray(list)) {
|
|
3747
|
-
return
|
|
5941
|
+
return adminError4(
|
|
3748
5942
|
400,
|
|
3749
5943
|
'expected {"addresses": [{line1, city, state, zip, lat?, lng?, validation?}]}'
|
|
3750
5944
|
);
|
|
@@ -3752,37 +5946,37 @@ var adminRoutes = (runtime) => ({
|
|
|
3752
5946
|
const rows = [];
|
|
3753
5947
|
for (const [index, each] of list.entries()) {
|
|
3754
5948
|
const parsed = parseAddress(each, index);
|
|
3755
|
-
if (typeof parsed === "string") return
|
|
5949
|
+
if (typeof parsed === "string") return adminError4(400, parsed);
|
|
3756
5950
|
rows.push(parsed);
|
|
3757
5951
|
}
|
|
3758
5952
|
const api = runtime.instance(namespace);
|
|
3759
5953
|
api.state.replaceCustom(rows);
|
|
3760
|
-
return
|
|
5954
|
+
return json5(200, { custom: rows });
|
|
3761
5955
|
},
|
|
3762
5956
|
"DELETE /corpus": ({ namespace }) => {
|
|
3763
5957
|
runtime.instance(namespace).state.replaceCustom([]);
|
|
3764
|
-
return
|
|
5958
|
+
return json5(200, { status: "ok" });
|
|
3765
5959
|
},
|
|
3766
|
-
"GET /settings": ({ namespace }) =>
|
|
5960
|
+
"GET /settings": ({ namespace }) => json5(200, runtime.instance(namespace).state.current()),
|
|
3767
5961
|
"PUT /settings": ({ body, namespace }) => {
|
|
3768
|
-
if (!
|
|
5962
|
+
if (!isRecord7(body)) return adminError4(400, "expected a JSON object");
|
|
3769
5963
|
const patch = {};
|
|
3770
5964
|
if (body.keys !== void 0) {
|
|
3771
|
-
if (!Array.isArray(body.keys)) return
|
|
5965
|
+
if (!Array.isArray(body.keys)) return adminError4(400, "keys: string[]");
|
|
3772
5966
|
patch.keys = body.keys.map(String);
|
|
3773
5967
|
}
|
|
3774
5968
|
if (body.publicUrl !== void 0) {
|
|
3775
5969
|
if (body.publicUrl !== null && typeof body.publicUrl !== "string") {
|
|
3776
|
-
return
|
|
5970
|
+
return adminError4(400, "publicUrl: string | null");
|
|
3777
5971
|
}
|
|
3778
5972
|
patch.publicUrl = body.publicUrl;
|
|
3779
5973
|
}
|
|
3780
|
-
return
|
|
5974
|
+
return json5(200, runtime.instance(namespace).state.update(patch));
|
|
3781
5975
|
}
|
|
3782
5976
|
});
|
|
3783
5977
|
var createRuntime2 = (options = {}) => createRuntime({
|
|
3784
5978
|
name: GOOGLE_MAPS_NAMESPACE,
|
|
3785
|
-
document,
|
|
5979
|
+
document: document2,
|
|
3786
5980
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
3787
5981
|
...options.clock ? { clock: options.clock } : {},
|
|
3788
5982
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -3812,7 +6006,7 @@ var MISSING_API_KEY_MESSAGE = "The request is missing a valid API key.";
|
|
|
3812
6006
|
var INVALID_API_KEY_MESSAGE = "API key not valid. Please pass a valid API key.";
|
|
3813
6007
|
var keyCredential = (request) => new URL(request.url).searchParams.get("key") ?? request.headers.get("x-goog-api-key") ?? void 0;
|
|
3814
6008
|
var CORS = { "access-control-allow-origin": "*" };
|
|
3815
|
-
var
|
|
6009
|
+
var json6 = (body, status = 200) => new Response(JSON.stringify(body, null, 3), {
|
|
3816
6010
|
status,
|
|
3817
6011
|
headers: { "content-type": "application/json; charset=UTF-8", ...CORS }
|
|
3818
6012
|
});
|
|
@@ -3827,7 +6021,7 @@ var DEFAULT_MESSAGES = {
|
|
|
3827
6021
|
UNKNOWN_ERROR: "An unknown error occurred. Please try again.",
|
|
3828
6022
|
REQUEST_DENIED: INVALID_KEY_MESSAGE
|
|
3829
6023
|
};
|
|
3830
|
-
var apiError = (error) =>
|
|
6024
|
+
var apiError = (error) => json6({ error }, error.code);
|
|
3831
6025
|
var requestJson = (body) => {
|
|
3832
6026
|
if (body.kind === "json") return body.value;
|
|
3833
6027
|
if (body.kind === "empty") return {};
|
|
@@ -3862,7 +6056,7 @@ var GoogleMapsAPI = class {
|
|
|
3862
6056
|
ValidateAddress: (context) => this.validate(context)
|
|
3863
6057
|
});
|
|
3864
6058
|
this.service = createService({
|
|
3865
|
-
document,
|
|
6059
|
+
document: document2,
|
|
3866
6060
|
handlers,
|
|
3867
6061
|
sqlite,
|
|
3868
6062
|
namespace,
|
|
@@ -3892,7 +6086,7 @@ var GoogleMapsAPI = class {
|
|
|
3892
6086
|
return this.state.corpus();
|
|
3893
6087
|
}
|
|
3894
6088
|
status(operationId, status, message) {
|
|
3895
|
-
return
|
|
6089
|
+
return json6({
|
|
3896
6090
|
...EMPTY[operationId],
|
|
3897
6091
|
...message ? { error_message: message } : {},
|
|
3898
6092
|
status
|
|
@@ -3954,7 +6148,7 @@ var GoogleMapsAPI = class {
|
|
|
3954
6148
|
const outcome = validateAddress(request, this.state.corpus(), {
|
|
3955
6149
|
...dpvOverride ? { dpvOverride } : {}
|
|
3956
6150
|
});
|
|
3957
|
-
return annotateResponse(
|
|
6151
|
+
return annotateResponse(json6(outcome.body), {
|
|
3958
6152
|
ids: {
|
|
3959
6153
|
...outcome.rowId ? { addressRowId: outcome.rowId } : {},
|
|
3960
6154
|
verdict: outcome.verdictClass
|
|
@@ -3975,17 +6169,17 @@ var GoogleMapsAPI = class {
|
|
|
3975
6169
|
if (components !== void 0) {
|
|
3976
6170
|
const countries = components.split("|").map((c) => c.trim().toLowerCase()).filter((c) => c.startsWith("country:")).map((c) => c.slice("country:".length));
|
|
3977
6171
|
if (countries.length > 0 && !countries.includes("us")) {
|
|
3978
|
-
return this.noted(
|
|
6172
|
+
return this.noted(json6({ predictions: [], status: "ZERO_RESULTS" }), context);
|
|
3979
6173
|
}
|
|
3980
6174
|
}
|
|
3981
6175
|
const types = text(context.query.types);
|
|
3982
6176
|
let places = autocomplete(input, this.state.corpus());
|
|
3983
6177
|
if (types === "address") places = places.filter((p) => p.kind === "street_address");
|
|
3984
6178
|
if (places.length === 0) {
|
|
3985
|
-
return this.noted(
|
|
6179
|
+
return this.noted(json6({ predictions: [], status: "ZERO_RESULTS" }), context);
|
|
3986
6180
|
}
|
|
3987
6181
|
return this.noted(
|
|
3988
|
-
|
|
6182
|
+
json6({ predictions: places.map((p) => prediction(p, input)), status: "OK" }),
|
|
3989
6183
|
context,
|
|
3990
6184
|
places[0]
|
|
3991
6185
|
);
|
|
@@ -4004,7 +6198,7 @@ var GoogleMapsAPI = class {
|
|
|
4004
6198
|
const place = placeById(placeId, this.state.corpus());
|
|
4005
6199
|
if (!place) return this.noted(this.status("PlaceDetails", "NOT_FOUND"), context);
|
|
4006
6200
|
return this.noted(
|
|
4007
|
-
|
|
6201
|
+
json6({
|
|
4008
6202
|
html_attributions: [],
|
|
4009
6203
|
result: pickFields(placeResult(place), fields, "all"),
|
|
4010
6204
|
status: "OK"
|
|
@@ -4021,10 +6215,10 @@ var GoogleMapsAPI = class {
|
|
|
4021
6215
|
if (!address && !placeId && !zip) return this.status("Geocode", "INVALID_REQUEST");
|
|
4022
6216
|
const rows = this.state.corpus();
|
|
4023
6217
|
const place = placeId ? placeById(placeId, rows) : address ? geocode(address, rows) : geocode(zip, rows);
|
|
4024
|
-
if (!place) return this.noted(
|
|
6218
|
+
if (!place) return this.noted(json6({ results: [], status: "ZERO_RESULTS" }), context);
|
|
4025
6219
|
const full = placeResult(place);
|
|
4026
6220
|
return this.noted(
|
|
4027
|
-
|
|
6221
|
+
json6({
|
|
4028
6222
|
results: [
|
|
4029
6223
|
{
|
|
4030
6224
|
address_components: full.address_components,
|
|
@@ -4055,9 +6249,9 @@ var GoogleMapsAPI = class {
|
|
|
4055
6249
|
);
|
|
4056
6250
|
}
|
|
4057
6251
|
const place = inputtype === "textquery" ? findPlace(input, this.state.corpus()) : void 0;
|
|
4058
|
-
if (!place) return this.noted(
|
|
6252
|
+
if (!place) return this.noted(json6({ candidates: [], status: "ZERO_RESULTS" }), context);
|
|
4059
6253
|
return this.noted(
|
|
4060
|
-
|
|
6254
|
+
json6({ candidates: [pickFields(placeResult(place), fields, ["place_id"])], status: "OK" }),
|
|
4061
6255
|
context,
|
|
4062
6256
|
place
|
|
4063
6257
|
);
|
|
@@ -4081,7 +6275,7 @@ var GoogleMapsAPI = class {
|
|
|
4081
6275
|
};
|
|
4082
6276
|
|
|
4083
6277
|
export {
|
|
4084
|
-
document,
|
|
6278
|
+
document2 as document,
|
|
4085
6279
|
operationIds,
|
|
4086
6280
|
supportedOperationIds,
|
|
4087
6281
|
DEFAULT_CORPUS,
|
|
@@ -4100,4 +6294,4 @@ export {
|
|
|
4100
6294
|
keyCredential,
|
|
4101
6295
|
GoogleMapsAPI
|
|
4102
6296
|
};
|
|
4103
|
-
//# sourceMappingURL=chunk-
|
|
6297
|
+
//# sourceMappingURL=chunk-HLXAIBBZ.js.map
|