@crvouga/mockingbird-service-aha 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -2
- package/dist/{chunk-7QJZ3SXP.js → chunk-35HPZJ35.js} +2331 -137
- package/dist/chunk-35HPZJ35.js.map +7 -0
- package/dist/{chunk-H6DPSSMR.js → chunk-V4KS27E5.js} +3 -2
- package/dist/{chunk-H6DPSSMR.js.map → chunk-V4KS27E5.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-7QJZ3SXP.js.map +0 -7
|
@@ -38,30 +38,30 @@ var createClock = (source = Date.now) => {
|
|
|
38
38
|
var Collection = class {
|
|
39
39
|
sqlite;
|
|
40
40
|
namespace;
|
|
41
|
-
|
|
42
|
-
constructor(sqlite, namespace,
|
|
41
|
+
collectionName;
|
|
42
|
+
constructor(sqlite, namespace, collectionName) {
|
|
43
43
|
this.sqlite = sqlite;
|
|
44
44
|
this.namespace = namespace;
|
|
45
|
-
this.
|
|
45
|
+
this.collectionName = collectionName;
|
|
46
46
|
}
|
|
47
47
|
bumpCollectionSeq() {
|
|
48
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.
|
|
48
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_sequences WHERE namespace = ? AND name = ? AND kind = 'collection'").get(this.namespace, this.collectionName);
|
|
49
49
|
const next = (row?.value ?? 0) + 1;
|
|
50
50
|
this.sqlite.prepare(`INSERT INTO mockingbird_sequences (namespace, name, kind, value) VALUES (?, ?, 'collection', ?)
|
|
51
|
-
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.
|
|
51
|
+
ON CONFLICT(namespace, name, kind) DO UPDATE SET value = excluded.value`).run(this.namespace, this.collectionName, next);
|
|
52
52
|
return next;
|
|
53
53
|
}
|
|
54
54
|
nextSequence() {
|
|
55
55
|
return this.sqlite.transaction(() => this.bumpCollectionSeq());
|
|
56
56
|
}
|
|
57
57
|
get(id) {
|
|
58
|
-
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
58
|
+
const row = this.sqlite.prepare("SELECT value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
59
59
|
if (!row)
|
|
60
60
|
return void 0;
|
|
61
61
|
return JSON.parse(row.value).value;
|
|
62
62
|
}
|
|
63
63
|
has(id) {
|
|
64
|
-
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
64
|
+
const row = this.sqlite.prepare("SELECT 1 AS ok FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
65
65
|
return row !== void 0;
|
|
66
66
|
}
|
|
67
67
|
/** Insert a new record, assigning it the next sequence number. */
|
|
@@ -71,32 +71,32 @@ var Collection = class {
|
|
|
71
71
|
const stored = { seq, value };
|
|
72
72
|
this.sqlite.prepare(`INSERT INTO mockingbird_records (namespace, collection, id, seq, value)
|
|
73
73
|
VALUES (?, ?, ?, ?, ?)
|
|
74
|
-
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.
|
|
74
|
+
ON CONFLICT(namespace, collection, id) DO UPDATE SET seq = excluded.seq, value = excluded.value`).run(this.namespace, this.collectionName, id, seq, JSON.stringify(stored));
|
|
75
75
|
return stored;
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
/** Replace an existing record's value, keeping its position. */
|
|
79
79
|
update(id, value) {
|
|
80
80
|
return this.sqlite.transaction(() => {
|
|
81
|
-
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.
|
|
81
|
+
const row = this.sqlite.prepare("SELECT seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").get(this.namespace, this.collectionName, id);
|
|
82
82
|
if (!row)
|
|
83
83
|
return void 0;
|
|
84
84
|
const stored = { seq: row.seq, value };
|
|
85
|
-
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.
|
|
85
|
+
this.sqlite.prepare("UPDATE mockingbird_records SET value = ? WHERE namespace = ? AND collection = ? AND id = ?").run(JSON.stringify(stored), this.namespace, this.collectionName, id);
|
|
86
86
|
return stored;
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
delete(id) {
|
|
90
|
-
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.
|
|
90
|
+
const result = this.sqlite.prepare("DELETE FROM mockingbird_records WHERE namespace = ? AND collection = ? AND id = ?").run(this.namespace, this.collectionName, id);
|
|
91
91
|
return result.changes > 0;
|
|
92
92
|
}
|
|
93
93
|
/** How many records the collection holds, without reading them. */
|
|
94
94
|
count() {
|
|
95
|
-
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.
|
|
95
|
+
const row = this.sqlite.prepare("SELECT COUNT(*) AS n FROM mockingbird_records WHERE namespace = ? AND collection = ?").get(this.namespace, this.collectionName);
|
|
96
96
|
return Number(row?.n ?? 0);
|
|
97
97
|
}
|
|
98
98
|
list(options = {}) {
|
|
99
|
-
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.
|
|
99
|
+
const rows = this.sqlite.prepare("SELECT id, seq, value FROM mockingbird_records WHERE namespace = ? AND collection = ?").all(this.namespace, this.collectionName);
|
|
100
100
|
const out = [];
|
|
101
101
|
for (const row of rows) {
|
|
102
102
|
const stored = JSON.parse(row.value);
|
|
@@ -353,16 +353,18 @@ var createControlPlane = (context) => {
|
|
|
353
353
|
uptimeMs: context.wallNow() - context.startedAt,
|
|
354
354
|
clock: context.clock.state(),
|
|
355
355
|
namespaces: context.namespaces().length,
|
|
356
|
+
adminUi: `${ADMIN_PREFIX}/ui`,
|
|
356
357
|
...context.describe()
|
|
357
358
|
});
|
|
358
359
|
}
|
|
359
360
|
if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
|
|
360
361
|
return void 0;
|
|
361
362
|
}
|
|
362
|
-
|
|
363
|
+
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
364
|
+
const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
|
|
365
|
+
if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
|
|
363
366
|
return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
|
|
364
367
|
}
|
|
365
|
-
const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
|
|
366
368
|
for (const route of routes) {
|
|
367
369
|
if (route.method !== request.method)
|
|
368
370
|
continue;
|
|
@@ -531,10 +533,10 @@ var OpenAPIReferenceError = class extends Error {
|
|
|
531
533
|
};
|
|
532
534
|
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
533
535
|
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
534
|
-
var resolveRef = (
|
|
536
|
+
var resolveRef = (document3, ref) => {
|
|
535
537
|
if (!ref.startsWith("#/"))
|
|
536
538
|
throw new OpenAPIReferenceError(ref);
|
|
537
|
-
let cursor =
|
|
539
|
+
let cursor = document3;
|
|
538
540
|
for (const raw of ref.slice(2).split("/")) {
|
|
539
541
|
const segment = unescapePointer(raw);
|
|
540
542
|
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
@@ -546,14 +548,14 @@ var resolveRef = (document2, ref) => {
|
|
|
546
548
|
throw new OpenAPIReferenceError(ref);
|
|
547
549
|
return cursor;
|
|
548
550
|
};
|
|
549
|
-
var deref = (
|
|
551
|
+
var deref = (document3, value) => {
|
|
550
552
|
let current = value;
|
|
551
553
|
const seen = /* @__PURE__ */ new Set();
|
|
552
554
|
while (isReference(current)) {
|
|
553
555
|
if (seen.has(current.$ref))
|
|
554
556
|
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
555
557
|
seen.add(current.$ref);
|
|
556
|
-
current = resolveRef(
|
|
558
|
+
current = resolveRef(document3, current.$ref);
|
|
557
559
|
}
|
|
558
560
|
return current;
|
|
559
561
|
};
|
|
@@ -571,36 +573,36 @@ var HTTP_METHODS = [
|
|
|
571
573
|
];
|
|
572
574
|
|
|
573
575
|
// ../../openapi/core/dist/document.js
|
|
574
|
-
var mergeParameters = (
|
|
576
|
+
var mergeParameters = (document3, item, own) => {
|
|
575
577
|
const merged = /* @__PURE__ */ new Map();
|
|
576
578
|
for (const raw of item.parameters ?? []) {
|
|
577
|
-
const parameter = deref(
|
|
579
|
+
const parameter = deref(document3, raw);
|
|
578
580
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
579
581
|
}
|
|
580
582
|
for (const raw of own ?? []) {
|
|
581
|
-
const parameter = deref(
|
|
583
|
+
const parameter = deref(document3, raw);
|
|
582
584
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
583
585
|
}
|
|
584
586
|
return [...merged.values()];
|
|
585
587
|
};
|
|
586
|
-
var listOperations = (
|
|
588
|
+
var listOperations = (document3) => {
|
|
587
589
|
const operations = [];
|
|
588
|
-
for (const [path, item] of Object.entries(
|
|
590
|
+
for (const [path, item] of Object.entries(document3.paths)) {
|
|
589
591
|
for (const method of HTTP_METHODS) {
|
|
590
592
|
const operation = item[method];
|
|
591
593
|
if (operation?.operationId === void 0)
|
|
592
594
|
continue;
|
|
593
595
|
const responses = {};
|
|
594
596
|
for (const [status, response] of Object.entries(operation.responses)) {
|
|
595
|
-
responses[status] = deref(
|
|
597
|
+
responses[status] = deref(document3, response);
|
|
596
598
|
}
|
|
597
599
|
operations.push({
|
|
598
600
|
operationId: operation.operationId,
|
|
599
601
|
method,
|
|
600
602
|
path,
|
|
601
603
|
operation,
|
|
602
|
-
parameters: mergeParameters(
|
|
603
|
-
requestBody: operation.requestBody === void 0 ? void 0 : deref(
|
|
604
|
+
parameters: mergeParameters(document3, item, operation.parameters),
|
|
605
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
|
|
604
606
|
responses
|
|
605
607
|
});
|
|
606
608
|
}
|
|
@@ -609,7 +611,7 @@ var listOperations = (document2) => {
|
|
|
609
611
|
};
|
|
610
612
|
|
|
611
613
|
// ../../openapi/core/dist/schema.js
|
|
612
|
-
var resolveSchema = (
|
|
614
|
+
var resolveSchema = (document3, schema) => {
|
|
613
615
|
let current = schema;
|
|
614
616
|
const seen = /* @__PURE__ */ new Set();
|
|
615
617
|
while (typeof current.$ref === "string") {
|
|
@@ -618,7 +620,7 @@ var resolveSchema = (document2, schema) => {
|
|
|
618
620
|
break;
|
|
619
621
|
seen.add(ref);
|
|
620
622
|
const { $ref: _ignored, ...siblings } = current;
|
|
621
|
-
const target = resolveRef(
|
|
623
|
+
const target = resolveRef(document3, ref);
|
|
622
624
|
current = { ...target, ...siblings };
|
|
623
625
|
}
|
|
624
626
|
if (current.nullable === true) {
|
|
@@ -689,71 +691,71 @@ var FORMAT_PATTERNS = {
|
|
|
689
691
|
ipv4: /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/
|
|
690
692
|
};
|
|
691
693
|
var graphemeLength = (value) => [...value].length;
|
|
692
|
-
var validateValue = (
|
|
694
|
+
var validateValue = (document3, schema, value, path = []) => {
|
|
693
695
|
const errors = [];
|
|
694
|
-
const s = resolveSchema(
|
|
695
|
-
const
|
|
696
|
+
const s = resolveSchema(document3, schema);
|
|
697
|
+
const fail2 = (message) => errors.push({ path, message });
|
|
696
698
|
const actual = jsonTypeOf(value);
|
|
697
699
|
if (actual === "undefined") {
|
|
698
|
-
|
|
700
|
+
fail2("value is undefined");
|
|
699
701
|
return errors;
|
|
700
702
|
}
|
|
701
703
|
const types = schemaTypes(s);
|
|
702
704
|
if (types.length > 0) {
|
|
703
705
|
const ok = types.some((t) => t === actual || t === "number" && actual === "integer");
|
|
704
706
|
if (!ok) {
|
|
705
|
-
|
|
707
|
+
fail2(`expected type ${types.join("|")}, got ${actual}`);
|
|
706
708
|
return errors;
|
|
707
709
|
}
|
|
708
710
|
}
|
|
709
711
|
if (s.enum && !(value === null && types.includes("null")) && !s.enum.some((candidate) => deepEqual(candidate, value))) {
|
|
710
|
-
|
|
712
|
+
fail2("value not in enum");
|
|
711
713
|
}
|
|
712
714
|
if (s.const !== void 0 && !deepEqual(s.const, value))
|
|
713
|
-
|
|
715
|
+
fail2("value does not equal const");
|
|
714
716
|
if (typeof value === "string") {
|
|
715
717
|
const length = graphemeLength(value);
|
|
716
718
|
if (s.minLength !== void 0 && length < s.minLength)
|
|
717
|
-
|
|
719
|
+
fail2(`length ${length} < minLength ${s.minLength}`);
|
|
718
720
|
if (s.maxLength !== void 0 && length > s.maxLength)
|
|
719
|
-
|
|
721
|
+
fail2(`length ${length} > maxLength ${s.maxLength}`);
|
|
720
722
|
if (s.pattern !== void 0) {
|
|
721
723
|
try {
|
|
722
724
|
if (!new RegExp(s.pattern, "u").test(value))
|
|
723
|
-
|
|
725
|
+
fail2(`does not match pattern ${s.pattern}`);
|
|
724
726
|
} catch {
|
|
725
727
|
}
|
|
726
728
|
}
|
|
727
729
|
if (s.format !== void 0) {
|
|
728
730
|
const pattern = FORMAT_PATTERNS[s.format];
|
|
729
731
|
if (pattern && !pattern.test(value))
|
|
730
|
-
|
|
732
|
+
fail2(`does not match format ${s.format}`);
|
|
731
733
|
}
|
|
732
734
|
}
|
|
733
735
|
if (typeof value === "number") {
|
|
734
736
|
if (s.minimum !== void 0 && value < s.minimum)
|
|
735
|
-
|
|
737
|
+
fail2(`${value} < minimum ${s.minimum}`);
|
|
736
738
|
if (s.maximum !== void 0 && value > s.maximum)
|
|
737
|
-
|
|
739
|
+
fail2(`${value} > maximum ${s.maximum}`);
|
|
738
740
|
if (s.exclusiveMinimum !== void 0 && value <= s.exclusiveMinimum)
|
|
739
|
-
|
|
741
|
+
fail2(`${value} <= exclusiveMinimum ${s.exclusiveMinimum}`);
|
|
740
742
|
if (s.exclusiveMaximum !== void 0 && value >= s.exclusiveMaximum)
|
|
741
|
-
|
|
743
|
+
fail2(`${value} >= exclusiveMaximum ${s.exclusiveMaximum}`);
|
|
742
744
|
if (s.multipleOf !== void 0 && Math.abs(value / s.multipleOf - Math.round(value / s.multipleOf)) > 1e-9) {
|
|
743
|
-
|
|
745
|
+
fail2(`${value} is not a multiple of ${s.multipleOf}`);
|
|
744
746
|
}
|
|
745
747
|
}
|
|
746
748
|
if (Array.isArray(value)) {
|
|
747
749
|
if (s.minItems !== void 0 && value.length < s.minItems)
|
|
748
|
-
|
|
750
|
+
fail2(`${value.length} items < minItems ${s.minItems}`);
|
|
749
751
|
if (s.maxItems !== void 0 && value.length > s.maxItems)
|
|
750
|
-
|
|
752
|
+
fail2(`${value.length} items > maxItems ${s.maxItems}`);
|
|
751
753
|
if (s.uniqueItems && value.some((item, i) => value.slice(0, i).some((prev) => deepEqual(prev, item))))
|
|
752
|
-
|
|
754
|
+
fail2("items are not unique");
|
|
753
755
|
value.forEach((item, i) => {
|
|
754
756
|
const itemSchema = s.prefixItems?.[i] ?? s.items;
|
|
755
757
|
if (itemSchema)
|
|
756
|
-
errors.push(...validateValue(
|
|
758
|
+
errors.push(...validateValue(document3, itemSchema, item, [...path, i]));
|
|
757
759
|
});
|
|
758
760
|
}
|
|
759
761
|
if (actual === "object") {
|
|
@@ -761,41 +763,41 @@ var validateValue = (document2, schema, value, path = []) => {
|
|
|
761
763
|
const keys = Object.keys(record2);
|
|
762
764
|
for (const name of s.required ?? [])
|
|
763
765
|
if (!(name in record2))
|
|
764
|
-
|
|
766
|
+
fail2(`missing required property ${name}`);
|
|
765
767
|
if (s.minProperties !== void 0 && keys.length < s.minProperties)
|
|
766
|
-
|
|
768
|
+
fail2(`${keys.length} properties < minProperties ${s.minProperties}`);
|
|
767
769
|
if (s.maxProperties !== void 0 && keys.length > s.maxProperties)
|
|
768
|
-
|
|
770
|
+
fail2(`${keys.length} properties > maxProperties ${s.maxProperties}`);
|
|
769
771
|
for (const key2 of keys) {
|
|
770
772
|
const property = s.properties?.[key2];
|
|
771
773
|
if (property) {
|
|
772
|
-
errors.push(...validateValue(
|
|
774
|
+
errors.push(...validateValue(document3, property, record2[key2], [...path, key2]));
|
|
773
775
|
continue;
|
|
774
776
|
}
|
|
775
777
|
if (s.additionalProperties === false)
|
|
776
|
-
|
|
778
|
+
fail2(`unexpected property ${key2}`);
|
|
777
779
|
else if (typeof s.additionalProperties === "object") {
|
|
778
|
-
errors.push(...validateValue(
|
|
780
|
+
errors.push(...validateValue(document3, s.additionalProperties, record2[key2], [...path, key2]));
|
|
779
781
|
}
|
|
780
782
|
if (s.propertyNames) {
|
|
781
|
-
const nameErrors = validateValue(
|
|
783
|
+
const nameErrors = validateValue(document3, s.propertyNames, key2, [...path, key2]);
|
|
782
784
|
if (nameErrors.length > 0)
|
|
783
|
-
|
|
785
|
+
fail2(`property name ${key2} is invalid: ${nameErrors[0]?.message}`);
|
|
784
786
|
}
|
|
785
787
|
}
|
|
786
788
|
}
|
|
787
789
|
if (s.allOf)
|
|
788
790
|
for (const branch of s.allOf)
|
|
789
|
-
errors.push(...validateValue(
|
|
790
|
-
if (s.anyOf && !s.anyOf.some((branch) => validateValue(
|
|
791
|
-
|
|
791
|
+
errors.push(...validateValue(document3, branch, value, path));
|
|
792
|
+
if (s.anyOf && !s.anyOf.some((branch) => validateValue(document3, branch, value).length === 0))
|
|
793
|
+
fail2("matches no anyOf branch");
|
|
792
794
|
if (s.oneOf) {
|
|
793
|
-
const matches2 = s.oneOf.filter((branch) => validateValue(
|
|
795
|
+
const matches2 = s.oneOf.filter((branch) => validateValue(document3, branch, value).length === 0).length;
|
|
794
796
|
if (matches2 !== 1)
|
|
795
|
-
|
|
797
|
+
fail2(`matches ${matches2} oneOf branches, expected exactly 1`);
|
|
796
798
|
}
|
|
797
|
-
if (s.not && validateValue(
|
|
798
|
-
|
|
799
|
+
if (s.not && validateValue(document3, s.not, value).length === 0)
|
|
800
|
+
fail2("matches forbidden `not` schema");
|
|
799
801
|
return errors;
|
|
800
802
|
};
|
|
801
803
|
|
|
@@ -1387,6 +1389,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1387
1389
|
});
|
|
1388
1390
|
};
|
|
1389
1391
|
|
|
1392
|
+
// ../../ui/dist/reset.js
|
|
1393
|
+
var CSS_RESET = `*,
|
|
1394
|
+
*::before,
|
|
1395
|
+
*::after {
|
|
1396
|
+
box-sizing: border-box;
|
|
1397
|
+
margin: 0;
|
|
1398
|
+
padding: 0;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
* {
|
|
1402
|
+
scrollbar-width: thin;
|
|
1403
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
*::-webkit-scrollbar {
|
|
1407
|
+
width: 12px;
|
|
1408
|
+
height: 12px;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
*::-webkit-scrollbar-track,
|
|
1412
|
+
*::-webkit-scrollbar-corner {
|
|
1413
|
+
background: Canvas;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
*::-webkit-scrollbar-thumb {
|
|
1417
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1418
|
+
border: 3px solid Canvas;
|
|
1419
|
+
border-radius: 999px;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
html {
|
|
1423
|
+
hanging-punctuation: first allow-end last;
|
|
1424
|
+
-webkit-text-size-adjust: none;
|
|
1425
|
+
text-size-adjust: none;
|
|
1426
|
+
tab-size: 4;
|
|
1427
|
+
font-family:
|
|
1428
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1429
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1430
|
+
font-size: 16px;
|
|
1431
|
+
line-height: 1.5;
|
|
1432
|
+
-webkit-font-smoothing: antialiased;
|
|
1433
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1434
|
+
text-rendering: optimizeLegibility;
|
|
1435
|
+
-webkit-tap-highlight-color: transparent;
|
|
1436
|
+
scroll-behavior: smooth;
|
|
1437
|
+
background: Canvas;
|
|
1438
|
+
color: CanvasText;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
body {
|
|
1442
|
+
min-height: 100svh;
|
|
1443
|
+
line-height: 1.5;
|
|
1444
|
+
background: Canvas;
|
|
1445
|
+
color: CanvasText;
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
h1 {
|
|
1449
|
+
font-size: 2em;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
h2 {
|
|
1453
|
+
font-size: 1.5em;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
h3 {
|
|
1457
|
+
font-size: 1.17em;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
h4 {
|
|
1461
|
+
font-size: 1em;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
h5 {
|
|
1465
|
+
font-size: 0.83em;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
h6 {
|
|
1469
|
+
font-size: 0.67em;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
h1,
|
|
1473
|
+
h2,
|
|
1474
|
+
h3,
|
|
1475
|
+
h4,
|
|
1476
|
+
h5,
|
|
1477
|
+
h6 {
|
|
1478
|
+
font-weight: 700;
|
|
1479
|
+
line-height: 1.2;
|
|
1480
|
+
text-wrap: balance;
|
|
1481
|
+
overflow-wrap: break-word;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
p,
|
|
1485
|
+
li,
|
|
1486
|
+
figcaption,
|
|
1487
|
+
dd,
|
|
1488
|
+
dt,
|
|
1489
|
+
blockquote {
|
|
1490
|
+
overflow-wrap: break-word;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
p,
|
|
1494
|
+
li,
|
|
1495
|
+
figcaption,
|
|
1496
|
+
blockquote {
|
|
1497
|
+
text-wrap: pretty;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
ul,
|
|
1501
|
+
ol,
|
|
1502
|
+
menu {
|
|
1503
|
+
list-style: none;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
a {
|
|
1507
|
+
color: inherit;
|
|
1508
|
+
text-decoration: underline;
|
|
1509
|
+
text-decoration-thickness: 1px;
|
|
1510
|
+
text-underline-offset: 0.15em;
|
|
1511
|
+
text-decoration-skip-ink: auto;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
b,
|
|
1515
|
+
strong {
|
|
1516
|
+
font-weight: 700;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
small {
|
|
1520
|
+
font-size: 0.875em;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
code,
|
|
1524
|
+
kbd,
|
|
1525
|
+
samp,
|
|
1526
|
+
pre {
|
|
1527
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1528
|
+
font-size: 1em;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
sub,
|
|
1532
|
+
sup {
|
|
1533
|
+
font-size: 75%;
|
|
1534
|
+
line-height: 0;
|
|
1535
|
+
position: relative;
|
|
1536
|
+
vertical-align: baseline;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
sub {
|
|
1540
|
+
bottom: -0.25em;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
sup {
|
|
1544
|
+
top: -0.5em;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
abbr[title] {
|
|
1548
|
+
text-decoration: underline dotted;
|
|
1549
|
+
text-underline-offset: 0.15em;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
mark {
|
|
1553
|
+
background: Mark;
|
|
1554
|
+
color: MarkText;
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
hr {
|
|
1558
|
+
height: 0;
|
|
1559
|
+
border: 0;
|
|
1560
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1561
|
+
color: inherit;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
img,
|
|
1565
|
+
picture,
|
|
1566
|
+
video,
|
|
1567
|
+
canvas {
|
|
1568
|
+
display: block;
|
|
1569
|
+
max-width: 100%;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
img,
|
|
1573
|
+
video {
|
|
1574
|
+
height: auto;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
svg {
|
|
1578
|
+
overflow: hidden;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
iframe {
|
|
1582
|
+
border: 0;
|
|
1583
|
+
max-width: 100%;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
table {
|
|
1587
|
+
border-collapse: collapse;
|
|
1588
|
+
border-spacing: 0;
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
fieldset {
|
|
1592
|
+
border: 0;
|
|
1593
|
+
min-inline-size: 0;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
legend {
|
|
1597
|
+
padding: 0;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
button,
|
|
1601
|
+
input,
|
|
1602
|
+
select,
|
|
1603
|
+
textarea,
|
|
1604
|
+
optgroup {
|
|
1605
|
+
font: inherit;
|
|
1606
|
+
letter-spacing: inherit;
|
|
1607
|
+
color: inherit;
|
|
1608
|
+
margin: 0;
|
|
1609
|
+
vertical-align: middle;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
button,
|
|
1613
|
+
input[type="button"],
|
|
1614
|
+
input[type="submit"],
|
|
1615
|
+
input[type="reset"] {
|
|
1616
|
+
appearance: none;
|
|
1617
|
+
background: none;
|
|
1618
|
+
border: 0;
|
|
1619
|
+
padding: 0;
|
|
1620
|
+
cursor: pointer;
|
|
1621
|
+
text-align: center;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
input,
|
|
1625
|
+
textarea,
|
|
1626
|
+
select {
|
|
1627
|
+
background-color: Canvas;
|
|
1628
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1629
|
+
border-radius: 0;
|
|
1630
|
+
padding: 0.5em 0.65em;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
input[type="checkbox"],
|
|
1634
|
+
input[type="radio"],
|
|
1635
|
+
input[type="range"],
|
|
1636
|
+
input[type="file"],
|
|
1637
|
+
input[type="color"],
|
|
1638
|
+
input[type="button"],
|
|
1639
|
+
input[type="submit"],
|
|
1640
|
+
input[type="reset"],
|
|
1641
|
+
input[type="image"],
|
|
1642
|
+
input[type="hidden"] {
|
|
1643
|
+
background: none;
|
|
1644
|
+
border: 0;
|
|
1645
|
+
padding: 0;
|
|
1646
|
+
border-radius: 0;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
input[type="checkbox"],
|
|
1650
|
+
input[type="radio"] {
|
|
1651
|
+
accent-color: CanvasText;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
input[type="search"] {
|
|
1655
|
+
appearance: none;
|
|
1656
|
+
background-color: Canvas;
|
|
1657
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1661
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1662
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1663
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1664
|
+
-webkit-appearance: none;
|
|
1665
|
+
display: none;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
input[type="number"] {
|
|
1669
|
+
appearance: textfield;
|
|
1670
|
+
background-color: Canvas;
|
|
1671
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1675
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1676
|
+
-webkit-appearance: none;
|
|
1677
|
+
margin: 0;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
textarea {
|
|
1681
|
+
resize: vertical;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
::placeholder {
|
|
1685
|
+
opacity: 1;
|
|
1686
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
:focus-visible {
|
|
1690
|
+
outline: 2px solid CanvasText;
|
|
1691
|
+
outline-offset: 2px;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
:focus:not(:focus-visible) {
|
|
1695
|
+
outline: none;
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
:disabled,
|
|
1699
|
+
[disabled] {
|
|
1700
|
+
cursor: default;
|
|
1701
|
+
opacity: 0.6;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
label,
|
|
1705
|
+
summary,
|
|
1706
|
+
select,
|
|
1707
|
+
[role="button"] {
|
|
1708
|
+
cursor: pointer;
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
summary {
|
|
1712
|
+
display: list-item;
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
details {
|
|
1716
|
+
display: block;
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
dialog {
|
|
1720
|
+
margin: auto;
|
|
1721
|
+
padding: 1rem;
|
|
1722
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1723
|
+
background: Canvas;
|
|
1724
|
+
color: CanvasText;
|
|
1725
|
+
max-width: calc(100vw - 2rem);
|
|
1726
|
+
max-height: calc(100svh - 2rem);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
dialog:not([open]) {
|
|
1730
|
+
display: none;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
::backdrop {
|
|
1734
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
[hidden] {
|
|
1738
|
+
display: none !important;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
::selection {
|
|
1742
|
+
background: Highlight;
|
|
1743
|
+
color: HighlightText;
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1747
|
+
*,
|
|
1748
|
+
*::before,
|
|
1749
|
+
*::after {
|
|
1750
|
+
animation-duration: 0.01ms !important;
|
|
1751
|
+
animation-iteration-count: 1 !important;
|
|
1752
|
+
transition-duration: 0.01ms !important;
|
|
1753
|
+
scroll-behavior: auto !important;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
@media (pointer: coarse) {
|
|
1758
|
+
input,
|
|
1759
|
+
select,
|
|
1760
|
+
textarea {
|
|
1761
|
+
font-size: max(16px, 1em);
|
|
1762
|
+
}
|
|
1763
|
+
}`;
|
|
1764
|
+
|
|
1765
|
+
// ../core/dist/admin-client.js
|
|
1766
|
+
function isRecord2(value) {
|
|
1767
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1768
|
+
}
|
|
1769
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1770
|
+
const clip = (value, max) => {
|
|
1771
|
+
if (typeof value !== "string")
|
|
1772
|
+
return null;
|
|
1773
|
+
const trimmed = value.trim();
|
|
1774
|
+
if (trimmed === "")
|
|
1775
|
+
return null;
|
|
1776
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1777
|
+
};
|
|
1778
|
+
const httpUrl = (value) => {
|
|
1779
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1780
|
+
return null;
|
|
1781
|
+
try {
|
|
1782
|
+
const url = new URL(value);
|
|
1783
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1784
|
+
return null;
|
|
1785
|
+
return url.href;
|
|
1786
|
+
} catch {
|
|
1787
|
+
return null;
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
const hexColor = (value) => {
|
|
1791
|
+
if (typeof value !== "string")
|
|
1792
|
+
return null;
|
|
1793
|
+
const raw = value.trim();
|
|
1794
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1795
|
+
};
|
|
1796
|
+
const hostname = (value) => {
|
|
1797
|
+
try {
|
|
1798
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1799
|
+
} catch {
|
|
1800
|
+
return value;
|
|
1801
|
+
}
|
|
1802
|
+
};
|
|
1803
|
+
host.replaceChildren();
|
|
1804
|
+
host.hidden = true;
|
|
1805
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1806
|
+
return;
|
|
1807
|
+
const row = catalog[service];
|
|
1808
|
+
if (!isRecord2(row))
|
|
1809
|
+
return;
|
|
1810
|
+
const vendor = clip(row.vendor, 80);
|
|
1811
|
+
const website = httpUrl(row.website);
|
|
1812
|
+
const guide = httpUrl(row.guide);
|
|
1813
|
+
const docs = httpUrl(row.docs);
|
|
1814
|
+
const logo = httpUrl(row.logo);
|
|
1815
|
+
const color = hexColor(row.color);
|
|
1816
|
+
const description = clip(row.description, 280);
|
|
1817
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1818
|
+
return;
|
|
1819
|
+
const add = (node) => {
|
|
1820
|
+
host.append(node);
|
|
1821
|
+
return node;
|
|
1822
|
+
};
|
|
1823
|
+
if (logo !== null) {
|
|
1824
|
+
const img = doc.createElement("img");
|
|
1825
|
+
img.alt = "";
|
|
1826
|
+
img.src = logo;
|
|
1827
|
+
img.width = 16;
|
|
1828
|
+
img.height = 16;
|
|
1829
|
+
img.decoding = "async";
|
|
1830
|
+
img.referrerPolicy = "no-referrer";
|
|
1831
|
+
if (color !== null)
|
|
1832
|
+
img.style.borderColor = color;
|
|
1833
|
+
add(img);
|
|
1834
|
+
}
|
|
1835
|
+
const name = doc.createElement("span");
|
|
1836
|
+
name.className = "vendor-name";
|
|
1837
|
+
name.textContent = vendor;
|
|
1838
|
+
if (description !== null)
|
|
1839
|
+
name.title = description;
|
|
1840
|
+
add(name);
|
|
1841
|
+
const sep = () => {
|
|
1842
|
+
const node = doc.createElement("span");
|
|
1843
|
+
node.className = "vendor-sep";
|
|
1844
|
+
node.setAttribute("aria-hidden", "true");
|
|
1845
|
+
node.textContent = "\xB7";
|
|
1846
|
+
return node;
|
|
1847
|
+
};
|
|
1848
|
+
const link = (href, label, title) => {
|
|
1849
|
+
const node = doc.createElement("a");
|
|
1850
|
+
node.className = "vendor-link";
|
|
1851
|
+
node.href = href;
|
|
1852
|
+
node.target = "_blank";
|
|
1853
|
+
node.rel = "noopener noreferrer";
|
|
1854
|
+
node.referrerPolicy = "no-referrer";
|
|
1855
|
+
node.textContent = label;
|
|
1856
|
+
node.title = title;
|
|
1857
|
+
return node;
|
|
1858
|
+
};
|
|
1859
|
+
if (website !== null) {
|
|
1860
|
+
add(sep());
|
|
1861
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1862
|
+
}
|
|
1863
|
+
if (guide !== null) {
|
|
1864
|
+
add(sep());
|
|
1865
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1866
|
+
}
|
|
1867
|
+
if (docs !== null) {
|
|
1868
|
+
add(sep());
|
|
1869
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1870
|
+
}
|
|
1871
|
+
host.removeAttribute("hidden");
|
|
1872
|
+
host.hidden = false;
|
|
1873
|
+
}
|
|
1874
|
+
function startAdminBrand(env) {
|
|
1875
|
+
const requested = env.params.get("brands");
|
|
1876
|
+
let brandsUrl = env.brandsUrl;
|
|
1877
|
+
if (requested) {
|
|
1878
|
+
try {
|
|
1879
|
+
const url = new URL(requested, env.location.href);
|
|
1880
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1881
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1882
|
+
brandsUrl = url.href;
|
|
1883
|
+
} catch {
|
|
1884
|
+
brandsUrl = env.brandsUrl;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
const vendorHost = env.$("vendor");
|
|
1888
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1889
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1890
|
+
if (vendorHost === null)
|
|
1891
|
+
return;
|
|
1892
|
+
env.fetch(brandsUrl, {
|
|
1893
|
+
headers: { accept: "application/json" },
|
|
1894
|
+
signal: AbortSignal.timeout(5e3)
|
|
1895
|
+
}).then(async (response) => {
|
|
1896
|
+
if (!response.ok)
|
|
1897
|
+
return null;
|
|
1898
|
+
const catalog = await response.json();
|
|
1899
|
+
return catalog;
|
|
1900
|
+
}).then((catalog) => {
|
|
1901
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1902
|
+
}).catch(() => {
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
function faultPresetList(value) {
|
|
1906
|
+
if (!isRecord2(value))
|
|
1907
|
+
throw new Error("Fault presets response was not an object");
|
|
1908
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1909
|
+
return { presets: [] };
|
|
1910
|
+
}
|
|
1911
|
+
if (!Array.isArray(value.presets))
|
|
1912
|
+
throw new Error("Fault presets response was not a list");
|
|
1913
|
+
return {
|
|
1914
|
+
presets: value.presets.flatMap((item) => {
|
|
1915
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1916
|
+
return [];
|
|
1917
|
+
return [{ name: item.name }];
|
|
1918
|
+
})
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
function bootAdmin(config) {
|
|
1922
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1923
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1924
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1925
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1926
|
+
const readJson2 = (text) => {
|
|
1927
|
+
const value = JSON.parse(text);
|
|
1928
|
+
return value;
|
|
1929
|
+
};
|
|
1930
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1931
|
+
switch (char) {
|
|
1932
|
+
case "&":
|
|
1933
|
+
return "&";
|
|
1934
|
+
case "<":
|
|
1935
|
+
return "<";
|
|
1936
|
+
case ">":
|
|
1937
|
+
return ">";
|
|
1938
|
+
case '"':
|
|
1939
|
+
return """;
|
|
1940
|
+
default:
|
|
1941
|
+
return "'";
|
|
1942
|
+
}
|
|
1943
|
+
});
|
|
1944
|
+
const el = (id, kind) => {
|
|
1945
|
+
const node = document.getElementById(id);
|
|
1946
|
+
if (!(node instanceof kind))
|
|
1947
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1948
|
+
return node;
|
|
1949
|
+
};
|
|
1950
|
+
const errorMessage = (data, fallback) => {
|
|
1951
|
+
if (!isRecord2(data))
|
|
1952
|
+
return fallback;
|
|
1953
|
+
const error2 = data.error;
|
|
1954
|
+
if (!isRecord2(error2) || typeof error2.message !== "string" || error2.message === "") {
|
|
1955
|
+
return fallback;
|
|
1956
|
+
}
|
|
1957
|
+
return error2.message;
|
|
1958
|
+
};
|
|
1959
|
+
const requireList = (value, label) => {
|
|
1960
|
+
if (value === void 0 || value === null)
|
|
1961
|
+
return [];
|
|
1962
|
+
if (!Array.isArray(value))
|
|
1963
|
+
throw new Error(`${label} was not a list`);
|
|
1964
|
+
return value;
|
|
1965
|
+
};
|
|
1966
|
+
const state = {
|
|
1967
|
+
namespace: "default",
|
|
1968
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1969
|
+
view: "overview",
|
|
1970
|
+
collection: "",
|
|
1971
|
+
shape: null,
|
|
1972
|
+
route: null,
|
|
1973
|
+
editing: null
|
|
1974
|
+
};
|
|
1975
|
+
const standard = new Set(config.standardRoutes);
|
|
1976
|
+
const banner = el("banner", HTMLElement);
|
|
1977
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1978
|
+
keyInput.value = state.key;
|
|
1979
|
+
const params = new URLSearchParams(location.search);
|
|
1980
|
+
const queryKey = params.get("key");
|
|
1981
|
+
if (queryKey) {
|
|
1982
|
+
state.key = queryKey;
|
|
1983
|
+
keyInput.value = state.key;
|
|
1984
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1985
|
+
params.delete("key");
|
|
1986
|
+
const next = params.toString();
|
|
1987
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1988
|
+
}
|
|
1989
|
+
const queryNamespace = params.get("namespace");
|
|
1990
|
+
if (queryNamespace)
|
|
1991
|
+
state.namespace = queryNamespace;
|
|
1992
|
+
const showError = (error2) => {
|
|
1993
|
+
banner.textContent = error2 instanceof Error ? error2.message : String(error2);
|
|
1994
|
+
banner.classList.add("show");
|
|
1995
|
+
};
|
|
1996
|
+
const clearError = () => {
|
|
1997
|
+
banner.classList.remove("show");
|
|
1998
|
+
};
|
|
1999
|
+
const api = async (method, path, body) => {
|
|
2000
|
+
const headers = { accept: "application/json" };
|
|
2001
|
+
if (state.key !== "")
|
|
2002
|
+
headers[config.adminKeyHeader] = state.key;
|
|
2003
|
+
if (state.namespace !== "")
|
|
2004
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
2005
|
+
if (body !== void 0)
|
|
2006
|
+
headers["content-type"] = "application/json";
|
|
2007
|
+
const init = { method, headers };
|
|
2008
|
+
if (body !== void 0)
|
|
2009
|
+
init.body = JSON.stringify(body);
|
|
2010
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
2011
|
+
const text = await response.text();
|
|
2012
|
+
let data = null;
|
|
2013
|
+
if (text !== "") {
|
|
2014
|
+
try {
|
|
2015
|
+
data = readJson2(text);
|
|
2016
|
+
} catch {
|
|
2017
|
+
data = { raw: text };
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
if (response.status === 401) {
|
|
2021
|
+
keyInput.focus();
|
|
2022
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
2023
|
+
}
|
|
2024
|
+
if (!response.ok) {
|
|
2025
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
2026
|
+
}
|
|
2027
|
+
return data;
|
|
2028
|
+
};
|
|
2029
|
+
const originGet = async (path) => {
|
|
2030
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
2031
|
+
if (!response.ok)
|
|
2032
|
+
throw new Error(`${response.status} ${path}`);
|
|
2033
|
+
const value = await response.json();
|
|
2034
|
+
return value;
|
|
2035
|
+
};
|
|
2036
|
+
const panelApi = {
|
|
2037
|
+
get: (path) => api("GET", path),
|
|
2038
|
+
send: (method, path, body) => api(method, path, body),
|
|
2039
|
+
namespace: () => state.namespace
|
|
2040
|
+
};
|
|
2041
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
2042
|
+
const setTheme = (theme) => {
|
|
2043
|
+
if (theme)
|
|
2044
|
+
document.documentElement.dataset.theme = theme;
|
|
2045
|
+
else
|
|
2046
|
+
delete document.documentElement.dataset.theme;
|
|
2047
|
+
};
|
|
2048
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
2049
|
+
if (storedTheme)
|
|
2050
|
+
setTheme(storedTheme);
|
|
2051
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
2052
|
+
const current = document.documentElement.dataset.theme;
|
|
2053
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
2054
|
+
const next = dark ? "light" : "dark";
|
|
2055
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
2056
|
+
setTheme(next);
|
|
2057
|
+
});
|
|
2058
|
+
const show = (view) => {
|
|
2059
|
+
state.view = view;
|
|
2060
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
2061
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2062
|
+
continue;
|
|
2063
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
2064
|
+
}
|
|
2065
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
2066
|
+
if (!(section instanceof HTMLElement))
|
|
2067
|
+
continue;
|
|
2068
|
+
section.hidden = section.id !== `view-${view}`;
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
2072
|
+
const target = event.target;
|
|
2073
|
+
if (!(target instanceof Element))
|
|
2074
|
+
return;
|
|
2075
|
+
const button = target.closest("button[data-view]");
|
|
2076
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2077
|
+
return;
|
|
2078
|
+
const view = button.dataset.view;
|
|
2079
|
+
if (view === void 0)
|
|
2080
|
+
return;
|
|
2081
|
+
show(view);
|
|
2082
|
+
refresh().catch(showError);
|
|
2083
|
+
});
|
|
2084
|
+
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>`;
|
|
2085
|
+
const table = (columns, rows) => {
|
|
2086
|
+
if (rows.length === 0)
|
|
2087
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
2088
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
2089
|
+
const body = rows.map((row) => {
|
|
2090
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
2091
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
2092
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
2093
|
+
}).join("");
|
|
2094
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
2095
|
+
};
|
|
2096
|
+
const preview = (value) => {
|
|
2097
|
+
const text = JSON.stringify(value) ?? "null";
|
|
2098
|
+
return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
|
|
2099
|
+
};
|
|
2100
|
+
const when = (epoch) => {
|
|
2101
|
+
const date = new Date(epoch);
|
|
2102
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
2103
|
+
};
|
|
2104
|
+
const clockCard = (epoch) => {
|
|
2105
|
+
const date = new Date(epoch);
|
|
2106
|
+
if (Number.isNaN(date.getTime()))
|
|
2107
|
+
return esc(String(epoch));
|
|
2108
|
+
const iso = date.toISOString();
|
|
2109
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
2110
|
+
};
|
|
2111
|
+
const decodeClock = (value) => {
|
|
2112
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
2113
|
+
throw new Error("Clock response was not a clock");
|
|
2114
|
+
}
|
|
2115
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
2116
|
+
};
|
|
2117
|
+
const decodeField = (value) => {
|
|
2118
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
2119
|
+
return void 0;
|
|
2120
|
+
}
|
|
2121
|
+
const field = {
|
|
2122
|
+
name: value.name,
|
|
2123
|
+
kind: value.kind,
|
|
2124
|
+
optional: value.optional === true
|
|
2125
|
+
};
|
|
2126
|
+
if (typeof value.description === "string")
|
|
2127
|
+
field.description = value.description;
|
|
2128
|
+
if (Array.isArray(value.fields)) {
|
|
2129
|
+
field.fields = value.fields.flatMap((item) => {
|
|
2130
|
+
const child = decodeField(item);
|
|
2131
|
+
return child === void 0 ? [] : [child];
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
return field;
|
|
2135
|
+
};
|
|
2136
|
+
const decodeCollection = (value) => {
|
|
2137
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
2138
|
+
return void 0;
|
|
2139
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
2140
|
+
const field = decodeField(item);
|
|
2141
|
+
return field === void 0 ? [] : [field];
|
|
2142
|
+
}) : [];
|
|
2143
|
+
const collection = {
|
|
2144
|
+
name: value.name,
|
|
2145
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
2146
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
2147
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
2148
|
+
fields
|
|
2149
|
+
};
|
|
2150
|
+
if (typeof value.description === "string")
|
|
2151
|
+
collection.description = value.description;
|
|
2152
|
+
return collection;
|
|
2153
|
+
};
|
|
2154
|
+
const decodeState = (value) => {
|
|
2155
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
2156
|
+
throw new Error("State response has no collection list");
|
|
2157
|
+
}
|
|
2158
|
+
return {
|
|
2159
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
2160
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
2161
|
+
collections: value.collections.flatMap((item) => {
|
|
2162
|
+
const collection = decodeCollection(item);
|
|
2163
|
+
return collection === void 0 ? [] : [collection];
|
|
2164
|
+
})
|
|
2165
|
+
};
|
|
2166
|
+
};
|
|
2167
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
2168
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
2169
|
+
return [];
|
|
2170
|
+
return [
|
|
2171
|
+
{
|
|
2172
|
+
id: item.id,
|
|
2173
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
2174
|
+
value: item.value,
|
|
2175
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
2176
|
+
}
|
|
2177
|
+
];
|
|
2178
|
+
});
|
|
2179
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
2180
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
2181
|
+
if (!isRecord2(item))
|
|
2182
|
+
return [];
|
|
2183
|
+
return [
|
|
2184
|
+
{
|
|
2185
|
+
at: textOf(item.at),
|
|
2186
|
+
method: textOf(item.method),
|
|
2187
|
+
path: textOf(item.path),
|
|
2188
|
+
status: textOf(item.status),
|
|
2189
|
+
durationMs: textOf(item.durationMs),
|
|
2190
|
+
operationId: textOf(item.operationId)
|
|
2191
|
+
}
|
|
2192
|
+
];
|
|
2193
|
+
});
|
|
2194
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
2195
|
+
if (!isRecord2(item))
|
|
2196
|
+
return [];
|
|
2197
|
+
return [
|
|
2198
|
+
{
|
|
2199
|
+
id: textOf(item.id),
|
|
2200
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
2201
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
2202
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
2203
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
2204
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
2205
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
2206
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
2207
|
+
}
|
|
2208
|
+
];
|
|
2209
|
+
});
|
|
2210
|
+
const loadNamespaces = async () => {
|
|
2211
|
+
const data = await api("GET", "/namespaces");
|
|
2212
|
+
const select = el("namespace", HTMLSelectElement);
|
|
2213
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
2214
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
2215
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
2216
|
+
if (!names.includes(state.namespace))
|
|
2217
|
+
names.unshift(state.namespace);
|
|
2218
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
2219
|
+
select.value = state.namespace;
|
|
2220
|
+
};
|
|
2221
|
+
const renderOverview = async () => {
|
|
2222
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
2223
|
+
originGet("/health"),
|
|
2224
|
+
api("GET", "/state"),
|
|
2225
|
+
api("GET", "/clock"),
|
|
2226
|
+
api("GET", "/requests?limit=8")
|
|
2227
|
+
]);
|
|
2228
|
+
if (!isRecord2(health))
|
|
2229
|
+
throw new Error("Health response was not an object");
|
|
2230
|
+
const decoded = decodeState(shape);
|
|
2231
|
+
state.shape = decoded;
|
|
2232
|
+
const time = decodeClock(clock);
|
|
2233
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
2234
|
+
{
|
|
2235
|
+
k: "Service",
|
|
2236
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
2237
|
+
},
|
|
2238
|
+
{
|
|
2239
|
+
k: "Status",
|
|
2240
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
2241
|
+
},
|
|
2242
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
2243
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
2244
|
+
{
|
|
2245
|
+
k: "Records",
|
|
2246
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
2247
|
+
},
|
|
2248
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
2249
|
+
]);
|
|
2250
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
2251
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2252
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2253
|
+
{
|
|
2254
|
+
label: "Status",
|
|
2255
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
2256
|
+
},
|
|
2257
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
2258
|
+
], decodeJournal(journal));
|
|
2259
|
+
};
|
|
2260
|
+
const schemaChips = (collection) => {
|
|
2261
|
+
if (collection.fields.length === 0) {
|
|
2262
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
2263
|
+
}
|
|
2264
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
2265
|
+
};
|
|
2266
|
+
const renderState = async () => {
|
|
2267
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
2268
|
+
state.shape = shape;
|
|
2269
|
+
const host = el("collections", HTMLElement);
|
|
2270
|
+
if (shape.collections.length === 0) {
|
|
2271
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
2272
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
2273
|
+
el("records", HTMLElement).innerHTML = "";
|
|
2274
|
+
return;
|
|
2275
|
+
}
|
|
2276
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
2277
|
+
const first = shape.collections[0];
|
|
2278
|
+
if (first === void 0)
|
|
2279
|
+
return;
|
|
2280
|
+
state.collection = first.name;
|
|
2281
|
+
}
|
|
2282
|
+
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("");
|
|
2283
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
2284
|
+
if (selected === void 0)
|
|
2285
|
+
return;
|
|
2286
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
2287
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
2288
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
2289
|
+
el("records", HTMLElement).innerHTML = table([
|
|
2290
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
2291
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
2292
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
2293
|
+
], decodeRecords(page));
|
|
2294
|
+
};
|
|
2295
|
+
const renderClock = async () => {
|
|
2296
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2297
|
+
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>`;
|
|
2298
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2299
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2300
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2301
|
+
};
|
|
2302
|
+
const renderFaults = async () => {
|
|
2303
|
+
const [faults, presets] = await Promise.all([
|
|
2304
|
+
api("GET", "/faults"),
|
|
2305
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2306
|
+
]);
|
|
2307
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2308
|
+
const current = select.value;
|
|
2309
|
+
const list = faultPresetList(presets).presets;
|
|
2310
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2311
|
+
select.value = current;
|
|
2312
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2313
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2314
|
+
{
|
|
2315
|
+
label: "Match",
|
|
2316
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2317
|
+
},
|
|
2318
|
+
{
|
|
2319
|
+
label: "Effect",
|
|
2320
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
2321
|
+
}
|
|
2322
|
+
], decodeFaults(faults));
|
|
2323
|
+
};
|
|
2324
|
+
const renderJournal = async () => {
|
|
2325
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2326
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2327
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
2328
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2329
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2330
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2331
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2332
|
+
], decodeJournal(journal));
|
|
2333
|
+
};
|
|
2334
|
+
const renderRoutes = async () => {
|
|
2335
|
+
const data = await api("GET", "/");
|
|
2336
|
+
if (!isRecord2(data))
|
|
2337
|
+
throw new Error("Route list was not an object");
|
|
2338
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2339
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2340
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2341
|
+
const parts = route.split(" ");
|
|
2342
|
+
const method = parts[0] ?? "";
|
|
2343
|
+
const path = parts.slice(1).join(" ");
|
|
2344
|
+
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>`;
|
|
2345
|
+
}).join("");
|
|
2346
|
+
};
|
|
2347
|
+
const renderers = {
|
|
2348
|
+
overview: renderOverview,
|
|
2349
|
+
state: renderState,
|
|
2350
|
+
clock: renderClock,
|
|
2351
|
+
faults: renderFaults,
|
|
2352
|
+
journal: renderJournal,
|
|
2353
|
+
routes: renderRoutes
|
|
2354
|
+
};
|
|
2355
|
+
async function refresh() {
|
|
2356
|
+
clearError();
|
|
2357
|
+
const render = renderers[state.view];
|
|
2358
|
+
if (render)
|
|
2359
|
+
await render();
|
|
2360
|
+
}
|
|
2361
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2362
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2363
|
+
refresh().catch(showError);
|
|
2364
|
+
});
|
|
2365
|
+
keyInput.addEventListener("change", () => {
|
|
2366
|
+
state.key = keyInput.value.trim();
|
|
2367
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2368
|
+
refresh().catch(showError);
|
|
2369
|
+
});
|
|
2370
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2371
|
+
refresh().catch(showError);
|
|
2372
|
+
});
|
|
2373
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2374
|
+
const target = event.target;
|
|
2375
|
+
if (!(target instanceof Element))
|
|
2376
|
+
return;
|
|
2377
|
+
const button = target.closest("[data-collection]");
|
|
2378
|
+
if (!(button instanceof HTMLElement))
|
|
2379
|
+
return;
|
|
2380
|
+
const collection = button.dataset.collection;
|
|
2381
|
+
if (collection === void 0)
|
|
2382
|
+
return;
|
|
2383
|
+
state.collection = collection;
|
|
2384
|
+
renderState().catch(showError);
|
|
2385
|
+
});
|
|
2386
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2387
|
+
const target = event.target;
|
|
2388
|
+
if (!(target instanceof Element))
|
|
2389
|
+
return;
|
|
2390
|
+
const row = target.closest("[data-id]");
|
|
2391
|
+
if (!(row instanceof HTMLElement))
|
|
2392
|
+
return;
|
|
2393
|
+
const id = row.dataset.id;
|
|
2394
|
+
if (id === void 0)
|
|
2395
|
+
return;
|
|
2396
|
+
openEditor(id).catch(showError);
|
|
2397
|
+
});
|
|
2398
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2399
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2400
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2401
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2402
|
+
async function openEditor(id) {
|
|
2403
|
+
state.editing = id;
|
|
2404
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2405
|
+
editorId.value = id ?? "";
|
|
2406
|
+
editorId.readOnly = id !== null;
|
|
2407
|
+
editorDelete.hidden = id === null;
|
|
2408
|
+
if (id) {
|
|
2409
|
+
const record2 = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2410
|
+
if (!isRecord2(record2))
|
|
2411
|
+
throw new Error("Record response was not an object");
|
|
2412
|
+
editorValue.value = JSON.stringify(record2.value, null, 2) ?? "";
|
|
2413
|
+
} else {
|
|
2414
|
+
editorValue.value = "{\n \n}";
|
|
2415
|
+
}
|
|
2416
|
+
editor.showModal();
|
|
2417
|
+
}
|
|
2418
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2419
|
+
openEditor(null).catch(showError);
|
|
2420
|
+
});
|
|
2421
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2422
|
+
const submitter = event.submitter;
|
|
2423
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2424
|
+
return;
|
|
2425
|
+
event.preventDefault();
|
|
2426
|
+
let value;
|
|
2427
|
+
try {
|
|
2428
|
+
value = readJson2(editorValue.value);
|
|
2429
|
+
} catch {
|
|
2430
|
+
showError(new Error("Value is not JSON"));
|
|
2431
|
+
return;
|
|
2432
|
+
}
|
|
2433
|
+
const id = editorId.value.trim();
|
|
2434
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2435
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2436
|
+
request.then(() => {
|
|
2437
|
+
editor.close();
|
|
2438
|
+
return renderState();
|
|
2439
|
+
}).catch(showError);
|
|
2440
|
+
});
|
|
2441
|
+
editorDelete.addEventListener("click", () => {
|
|
2442
|
+
const id = state.editing;
|
|
2443
|
+
if (!id)
|
|
2444
|
+
return;
|
|
2445
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2446
|
+
editor.close();
|
|
2447
|
+
return renderState();
|
|
2448
|
+
}).catch(showError);
|
|
2449
|
+
});
|
|
2450
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2451
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2452
|
+
continue;
|
|
2453
|
+
button.addEventListener("click", () => {
|
|
2454
|
+
const raw = button.dataset.advance;
|
|
2455
|
+
if (raw === void 0)
|
|
2456
|
+
return;
|
|
2457
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2461
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2462
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2463
|
+
});
|
|
2464
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2465
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2466
|
+
});
|
|
2467
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2468
|
+
event.preventDefault();
|
|
2469
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2470
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2471
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2472
|
+
});
|
|
2473
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2474
|
+
event.preventDefault();
|
|
2475
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2476
|
+
if (preset !== "") {
|
|
2477
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2478
|
+
return;
|
|
2479
|
+
}
|
|
2480
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2481
|
+
if (!Number.isFinite(status)) {
|
|
2482
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2483
|
+
return;
|
|
2484
|
+
}
|
|
2485
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2486
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2487
|
+
api("POST", "/faults", {
|
|
2488
|
+
status,
|
|
2489
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2490
|
+
...method !== "" ? { method } : {}
|
|
2491
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2492
|
+
});
|
|
2493
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2494
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2495
|
+
});
|
|
2496
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2497
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2498
|
+
});
|
|
2499
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2500
|
+
const target = event.target;
|
|
2501
|
+
if (!(target instanceof Element))
|
|
2502
|
+
return;
|
|
2503
|
+
const button = target.closest("[data-route]");
|
|
2504
|
+
if (!(button instanceof HTMLElement))
|
|
2505
|
+
return;
|
|
2506
|
+
const route = button.dataset.route;
|
|
2507
|
+
if (route === void 0)
|
|
2508
|
+
return;
|
|
2509
|
+
state.route = route;
|
|
2510
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2511
|
+
const method = route.split(" ")[0] ?? "";
|
|
2512
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2513
|
+
});
|
|
2514
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2515
|
+
event.preventDefault();
|
|
2516
|
+
const send = async () => {
|
|
2517
|
+
if (state.route === null)
|
|
2518
|
+
throw new Error("Choose a route first");
|
|
2519
|
+
const parts = state.route.split(" ");
|
|
2520
|
+
const method = parts[0];
|
|
2521
|
+
const path = parts.slice(1).join(" ");
|
|
2522
|
+
if (method === void 0)
|
|
2523
|
+
throw new Error("Choose a route first");
|
|
2524
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key2) => prompt(`Value for ${key2}`) || "");
|
|
2525
|
+
let body;
|
|
2526
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2527
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2528
|
+
try {
|
|
2529
|
+
body = readJson2(routeBody.value);
|
|
2530
|
+
} catch {
|
|
2531
|
+
throw new Error("Body is not JSON");
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
const data = await api(method, concrete, body);
|
|
2535
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2536
|
+
};
|
|
2537
|
+
send().catch(showError);
|
|
2538
|
+
});
|
|
2539
|
+
const decodePanel = (value) => {
|
|
2540
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2541
|
+
return void 0;
|
|
2542
|
+
}
|
|
2543
|
+
const panel = {
|
|
2544
|
+
id: value.id,
|
|
2545
|
+
title: value.title,
|
|
2546
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2547
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2548
|
+
};
|
|
2549
|
+
if (typeof value.script === "string")
|
|
2550
|
+
panel.script = value.script;
|
|
2551
|
+
return panel;
|
|
2552
|
+
};
|
|
2553
|
+
const mountPanels = (panels) => {
|
|
2554
|
+
const nav = el("nav", HTMLElement);
|
|
2555
|
+
const views = el("views", HTMLElement);
|
|
2556
|
+
for (const panel of panels) {
|
|
2557
|
+
const button = document.createElement("button");
|
|
2558
|
+
button.type = "button";
|
|
2559
|
+
button.dataset.view = panel.id;
|
|
2560
|
+
button.textContent = panel.title;
|
|
2561
|
+
nav.append(button);
|
|
2562
|
+
const section = document.createElement("section");
|
|
2563
|
+
section.className = "view";
|
|
2564
|
+
section.id = `view-${panel.id}`;
|
|
2565
|
+
section.hidden = true;
|
|
2566
|
+
const title = document.createElement("h2");
|
|
2567
|
+
title.textContent = panel.title;
|
|
2568
|
+
const lede = document.createElement("p");
|
|
2569
|
+
lede.className = "lede";
|
|
2570
|
+
lede.textContent = panel.description;
|
|
2571
|
+
const body = document.createElement("div");
|
|
2572
|
+
body.className = "panel-body";
|
|
2573
|
+
body.id = `panel-${panel.id}`;
|
|
2574
|
+
body.innerHTML = panel.html;
|
|
2575
|
+
section.append(title, lede, body);
|
|
2576
|
+
views.append(section);
|
|
2577
|
+
if (panel.script === void 0)
|
|
2578
|
+
continue;
|
|
2579
|
+
try {
|
|
2580
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2581
|
+
if (!isPanelScript(compiled))
|
|
2582
|
+
throw new Error("panel script did not compile");
|
|
2583
|
+
compiled(body, panelApi);
|
|
2584
|
+
} catch (error2) {
|
|
2585
|
+
const note = document.createElement("p");
|
|
2586
|
+
note.className = "banner show";
|
|
2587
|
+
note.textContent = error2 instanceof Error ? error2.message : String(error2);
|
|
2588
|
+
body.append(note);
|
|
2589
|
+
}
|
|
2590
|
+
}
|
|
2591
|
+
};
|
|
2592
|
+
startAdminBrand({
|
|
2593
|
+
document,
|
|
2594
|
+
$: (id) => document.getElementById(id),
|
|
2595
|
+
params,
|
|
2596
|
+
location: { href: location.href, origin: location.origin },
|
|
2597
|
+
fetch,
|
|
2598
|
+
brandsUrl: config.brandsUrl
|
|
2599
|
+
});
|
|
2600
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2601
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2602
|
+
const decoded = decodePanel(panel);
|
|
2603
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2604
|
+
});
|
|
2605
|
+
mountPanels(panels);
|
|
2606
|
+
return refresh();
|
|
2607
|
+
}).catch(showError);
|
|
2608
|
+
}
|
|
2609
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2610
|
+
var adminClientSource = (config) => {
|
|
2611
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2612
|
+
return `<script>
|
|
2613
|
+
${clientPrelude}
|
|
2614
|
+
bootAdmin(${payload});
|
|
2615
|
+
</script>`;
|
|
2616
|
+
};
|
|
2617
|
+
|
|
2618
|
+
// ../core/dist/surface.js
|
|
2619
|
+
var defineMock = (runtime) => runtime;
|
|
2620
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2621
|
+
"GET /",
|
|
2622
|
+
"POST /reset",
|
|
2623
|
+
"GET /namespaces",
|
|
2624
|
+
"GET /clock",
|
|
2625
|
+
"POST /clock",
|
|
2626
|
+
"GET /faults",
|
|
2627
|
+
"POST /faults",
|
|
2628
|
+
"DELETE /faults",
|
|
2629
|
+
"POST /snapshots",
|
|
2630
|
+
"POST /snapshots/:id/restore",
|
|
2631
|
+
"DELETE /snapshots/:id",
|
|
2632
|
+
"GET /timeline",
|
|
2633
|
+
"POST /checkpoints",
|
|
2634
|
+
"POST /branches/:name",
|
|
2635
|
+
"POST /branches/:name/checkout",
|
|
2636
|
+
"GET /requests",
|
|
2637
|
+
"DELETE /requests",
|
|
2638
|
+
"GET /metrics",
|
|
2639
|
+
"DELETE /metrics",
|
|
2640
|
+
"GET /credentials",
|
|
2641
|
+
"PUT /credentials",
|
|
2642
|
+
"DELETE /credentials",
|
|
2643
|
+
"GET /state",
|
|
2644
|
+
"GET /state/:collection",
|
|
2645
|
+
"GET /state/:collection/:id",
|
|
2646
|
+
"POST /state/:collection",
|
|
2647
|
+
"PUT /state/:collection/:id",
|
|
2648
|
+
"PATCH /state/:collection/:id",
|
|
2649
|
+
"DELETE /state/:collection/:id",
|
|
2650
|
+
"GET /ui",
|
|
2651
|
+
"GET /ui/",
|
|
2652
|
+
"GET /ui/manifest"
|
|
2653
|
+
];
|
|
2654
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2655
|
+
var assertAdminUi = (ui) => {
|
|
2656
|
+
if (!ui?.panels)
|
|
2657
|
+
return;
|
|
2658
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2659
|
+
for (const panel of ui.panels) {
|
|
2660
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2661
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2662
|
+
}
|
|
2663
|
+
if (seen.has(panel.id))
|
|
2664
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2665
|
+
seen.add(panel.id);
|
|
2666
|
+
if (panel.title.trim() === "")
|
|
2667
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
|
|
2671
|
+
// ../core/dist/admin-ui.js
|
|
2672
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2673
|
+
switch (char) {
|
|
2674
|
+
case "&":
|
|
2675
|
+
return "&";
|
|
2676
|
+
case "<":
|
|
2677
|
+
return "<";
|
|
2678
|
+
case ">":
|
|
2679
|
+
return ">";
|
|
2680
|
+
case '"':
|
|
2681
|
+
return """;
|
|
2682
|
+
default:
|
|
2683
|
+
return "'";
|
|
2684
|
+
}
|
|
2685
|
+
});
|
|
2686
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2687
|
+
var renderAdminDocument = (service) => {
|
|
2688
|
+
const name = escapeHtml(service);
|
|
2689
|
+
const script = adminClientSource({
|
|
2690
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2691
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2692
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2693
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2694
|
+
service
|
|
2695
|
+
});
|
|
2696
|
+
return `<!DOCTYPE html>
|
|
2697
|
+
<html lang="en">
|
|
2698
|
+
<head>
|
|
2699
|
+
<meta charset="utf-8">
|
|
2700
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2701
|
+
<meta name="color-scheme" content="light dark">
|
|
2702
|
+
<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">
|
|
2703
|
+
<title>${name} admin</title>
|
|
2704
|
+
<style>
|
|
2705
|
+
${CSS_RESET}
|
|
2706
|
+
:root {
|
|
2707
|
+
color-scheme: light;
|
|
2708
|
+
--bg: #fafafa;
|
|
2709
|
+
--bg-elev: #ffffff;
|
|
2710
|
+
--bg-muted: #f4f4f5;
|
|
2711
|
+
--bg-inset: #f4f4f5;
|
|
2712
|
+
--line: #dedee3;
|
|
2713
|
+
--line-strong: #c4c4cc;
|
|
2714
|
+
--ink: #18181b;
|
|
2715
|
+
--muted: #62626b;
|
|
2716
|
+
--faint: #71717a;
|
|
2717
|
+
--accent: #27272a;
|
|
2718
|
+
--accent-ink: #ffffff;
|
|
2719
|
+
--accent-soft: #f4f4f5;
|
|
2720
|
+
--ok: #166534;
|
|
2721
|
+
--ok-soft: #f0fdf4;
|
|
2722
|
+
--warn: #a16207;
|
|
2723
|
+
--warn-soft: #fefce8;
|
|
2724
|
+
--err: #a82d32;
|
|
2725
|
+
--err-soft: #fef2f2;
|
|
2726
|
+
--shadow: none;
|
|
2727
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2728
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2729
|
+
--radius: 10px;
|
|
2730
|
+
--header: 56px;
|
|
2731
|
+
--nav: 200px;
|
|
2732
|
+
}
|
|
2733
|
+
:root[data-theme="dark"] {
|
|
2734
|
+
color-scheme: dark;
|
|
2735
|
+
--bg: #111113;
|
|
2736
|
+
--bg-elev: #19191c;
|
|
2737
|
+
--bg-muted: #242428;
|
|
2738
|
+
--bg-inset: #111113;
|
|
2739
|
+
--line: #36363c;
|
|
2740
|
+
--line-strong: #52525b;
|
|
2741
|
+
--ink: #f4f4f5;
|
|
2742
|
+
--muted: #a9a9b2;
|
|
2743
|
+
--faint: #71717a;
|
|
2744
|
+
--accent: #e4e4e7;
|
|
2745
|
+
--accent-ink: #18181b;
|
|
2746
|
+
--accent-soft: #242428;
|
|
2747
|
+
--ok: #86efac;
|
|
2748
|
+
--ok-soft: #14241b;
|
|
2749
|
+
--warn: #fde68a;
|
|
2750
|
+
--warn-soft: #2a2410;
|
|
2751
|
+
--err: #ffaaaa;
|
|
2752
|
+
--err-soft: #2c1516;
|
|
2753
|
+
--shadow: none;
|
|
2754
|
+
}
|
|
2755
|
+
@media (prefers-color-scheme: dark) {
|
|
2756
|
+
:root:not([data-theme="light"]) {
|
|
2757
|
+
color-scheme: dark;
|
|
2758
|
+
--bg: #111113;
|
|
2759
|
+
--bg-elev: #19191c;
|
|
2760
|
+
--bg-muted: #242428;
|
|
2761
|
+
--bg-inset: #111113;
|
|
2762
|
+
--line: #36363c;
|
|
2763
|
+
--line-strong: #52525b;
|
|
2764
|
+
--ink: #f4f4f5;
|
|
2765
|
+
--muted: #a9a9b2;
|
|
2766
|
+
--faint: #71717a;
|
|
2767
|
+
--accent: #e4e4e7;
|
|
2768
|
+
--accent-ink: #18181b;
|
|
2769
|
+
--accent-soft: #242428;
|
|
2770
|
+
--ok: #86efac;
|
|
2771
|
+
--ok-soft: #14241b;
|
|
2772
|
+
--warn: #fde68a;
|
|
2773
|
+
--warn-soft: #2a2410;
|
|
2774
|
+
--err: #ffaaaa;
|
|
2775
|
+
--err-soft: #2c1516;
|
|
2776
|
+
--shadow: none;
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2780
|
+
html { height: 100%; }
|
|
2781
|
+
body {
|
|
2782
|
+
margin: 0;
|
|
2783
|
+
min-height: 100%;
|
|
2784
|
+
display: flex;
|
|
2785
|
+
flex-direction: column;
|
|
2786
|
+
font-family: var(--sans);
|
|
2787
|
+
background: var(--bg);
|
|
2788
|
+
color: var(--ink);
|
|
2789
|
+
line-height: 1.45;
|
|
2790
|
+
padding-left: env(safe-area-inset-left);
|
|
2791
|
+
padding-right: env(safe-area-inset-right);
|
|
2792
|
+
-webkit-text-size-adjust: 100%;
|
|
2793
|
+
}
|
|
2794
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2795
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2796
|
+
header.top {
|
|
2797
|
+
position: sticky; top: 0; z-index: 5;
|
|
2798
|
+
display: flex; align-items: center; gap: 12px;
|
|
2799
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2800
|
+
background: var(--bg-elev);
|
|
2801
|
+
border-bottom: 1px solid var(--line);
|
|
2802
|
+
min-width: 0; max-width: 100%;
|
|
2803
|
+
}
|
|
2804
|
+
.brand {
|
|
2805
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2806
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2807
|
+
}
|
|
2808
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2809
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2810
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2811
|
+
.vendor {
|
|
2812
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2813
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2814
|
+
}
|
|
2815
|
+
.vendor[hidden] { display: none; }
|
|
2816
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2817
|
+
.vendor img {
|
|
2818
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2819
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2820
|
+
}
|
|
2821
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2822
|
+
.vendor-sep { color: var(--faint); }
|
|
2823
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2824
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2825
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2826
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2827
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2828
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2829
|
+
padding: 7px 8px; min-height: 36px;
|
|
2830
|
+
}
|
|
2831
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2832
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2833
|
+
background: var(--bg-elev);
|
|
2834
|
+
}
|
|
2835
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2836
|
+
.btn-quiet { background: transparent; }
|
|
2837
|
+
.btn-danger { color: var(--err); }
|
|
2838
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2839
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2840
|
+
.layout {
|
|
2841
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2842
|
+
flex: 1 0 auto; min-width: 0;
|
|
2843
|
+
}
|
|
2844
|
+
nav.side {
|
|
2845
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2846
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2847
|
+
background: var(--bg-elev);
|
|
2848
|
+
}
|
|
2849
|
+
nav.side button {
|
|
2850
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2851
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2852
|
+
}
|
|
2853
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2854
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2855
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2856
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2857
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2858
|
+
.card {
|
|
2859
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2860
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2861
|
+
}
|
|
2862
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2863
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2864
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2865
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2866
|
+
.collection {
|
|
2867
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2868
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2869
|
+
}
|
|
2870
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2871
|
+
.collection small { display: block; color: var(--faint); }
|
|
2872
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2873
|
+
.chip {
|
|
2874
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2875
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2876
|
+
}
|
|
2877
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2878
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2879
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2880
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2881
|
+
tr.clickable { cursor: pointer; }
|
|
2882
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2883
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2884
|
+
pre {
|
|
2885
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2886
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2887
|
+
}
|
|
2888
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2889
|
+
.banner {
|
|
2890
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2891
|
+
background: var(--err-soft); color: var(--err);
|
|
2892
|
+
}
|
|
2893
|
+
.banner.show { display: block; }
|
|
2894
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2895
|
+
dialog {
|
|
2896
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2897
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2898
|
+
}
|
|
2899
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2900
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2901
|
+
textarea {
|
|
2902
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2903
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2904
|
+
font-family: var(--mono); font-size: 12px;
|
|
2905
|
+
}
|
|
2906
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2907
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2908
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2909
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2910
|
+
.status-2 { color: var(--ok); }
|
|
2911
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2912
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2913
|
+
.route {
|
|
2914
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2915
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2916
|
+
}
|
|
2917
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2918
|
+
@media (max-width: 800px) {
|
|
2919
|
+
header.top {
|
|
2920
|
+
align-items: stretch; flex-direction: column;
|
|
2921
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2922
|
+
}
|
|
2923
|
+
input, select, textarea { font-size: 16px; }
|
|
2924
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2925
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2926
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2927
|
+
nav.side {
|
|
2928
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2929
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2930
|
+
padding: 8px;
|
|
2931
|
+
}
|
|
2932
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2933
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2934
|
+
main { padding: 14px; }
|
|
2935
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2936
|
+
thead { display: none; }
|
|
2937
|
+
tr {
|
|
2938
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2939
|
+
background: var(--bg-elev); min-width: 0;
|
|
2940
|
+
}
|
|
2941
|
+
td {
|
|
2942
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2943
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2944
|
+
}
|
|
2945
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2946
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2947
|
+
.route button { grid-column: 1 / -1; }
|
|
2948
|
+
}
|
|
2949
|
+
</style>
|
|
2950
|
+
</head>
|
|
2951
|
+
<body>
|
|
2952
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2953
|
+
<header class="top">
|
|
2954
|
+
<div class="brand">
|
|
2955
|
+
<div class="brand-id">
|
|
2956
|
+
<strong>${name}</strong>
|
|
2957
|
+
<span>Admin</span>
|
|
2958
|
+
</div>
|
|
2959
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2960
|
+
</div>
|
|
2961
|
+
<div class="controls">
|
|
2962
|
+
<label class="field">Namespace
|
|
2963
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2964
|
+
</label>
|
|
2965
|
+
<label class="field">Admin key
|
|
2966
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2967
|
+
</label>
|
|
2968
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2969
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2970
|
+
</div>
|
|
2971
|
+
</header>
|
|
2972
|
+
<div class="layout">
|
|
2973
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2974
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2975
|
+
<button type="button" data-view="state">State</button>
|
|
2976
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2977
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2978
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2979
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2980
|
+
</nav>
|
|
2981
|
+
<main id="views">
|
|
2982
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2983
|
+
<section class="view" id="view-overview">
|
|
2984
|
+
<h2>Overview</h2>
|
|
2985
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2986
|
+
<div class="grid" id="overview-cards"></div>
|
|
2987
|
+
<h3>Recent requests</h3>
|
|
2988
|
+
<div id="overview-requests"></div>
|
|
2989
|
+
</section>
|
|
2990
|
+
<section class="view" id="view-state" hidden>
|
|
2991
|
+
<h2>State</h2>
|
|
2992
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2993
|
+
<div class="split">
|
|
2994
|
+
<div id="collections"></div>
|
|
2995
|
+
<div>
|
|
2996
|
+
<div id="schema"></div>
|
|
2997
|
+
<div class="row-actions">
|
|
2998
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2999
|
+
</div>
|
|
3000
|
+
<div id="records"></div>
|
|
3001
|
+
</div>
|
|
3002
|
+
</div>
|
|
3003
|
+
</section>
|
|
3004
|
+
<section class="view" id="view-clock" hidden>
|
|
3005
|
+
<h2>Clock</h2>
|
|
3006
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
3007
|
+
<div class="card" id="clock-readout"></div>
|
|
3008
|
+
<div class="row-actions">
|
|
3009
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
3010
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
3011
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
3012
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
3013
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
3014
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
3015
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
3016
|
+
</div>
|
|
3017
|
+
<form id="clock-set" class="row-actions">
|
|
3018
|
+
<label class="field">Set instant
|
|
3019
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
3020
|
+
</label>
|
|
3021
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
3022
|
+
</form>
|
|
3023
|
+
</section>
|
|
3024
|
+
<section class="view" id="view-faults" hidden>
|
|
3025
|
+
<h2>Faults</h2>
|
|
3026
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
3027
|
+
<form id="fault-form" class="card stack">
|
|
3028
|
+
<label class="field">Preset
|
|
3029
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
3030
|
+
</label>
|
|
3031
|
+
<label class="field">Status
|
|
3032
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
3033
|
+
</label>
|
|
3034
|
+
<label class="field">Path prefix
|
|
3035
|
+
<input id="fault-path" placeholder="/v1">
|
|
3036
|
+
</label>
|
|
3037
|
+
<label class="field">Method
|
|
3038
|
+
<input id="fault-method" placeholder="GET">
|
|
3039
|
+
</label>
|
|
3040
|
+
<div class="dialog-actions">
|
|
3041
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
3042
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
3043
|
+
</div>
|
|
3044
|
+
</form>
|
|
3045
|
+
<div id="fault-list"></div>
|
|
3046
|
+
</section>
|
|
3047
|
+
<section class="view" id="view-journal" hidden>
|
|
3048
|
+
<h2>Journal</h2>
|
|
3049
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
3050
|
+
<div class="row-actions">
|
|
3051
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
3052
|
+
</div>
|
|
3053
|
+
<div id="journal"></div>
|
|
3054
|
+
</section>
|
|
3055
|
+
<section class="view" id="view-routes" hidden>
|
|
3056
|
+
<h2>Routes</h2>
|
|
3057
|
+
<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>
|
|
3058
|
+
<div id="route-list"></div>
|
|
3059
|
+
<form id="route-form" class="card stack">
|
|
3060
|
+
<strong id="route-title">Select a route</strong>
|
|
3061
|
+
<label class="field">JSON body
|
|
3062
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
3063
|
+
</label>
|
|
3064
|
+
<div class="dialog-actions">
|
|
3065
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
3066
|
+
</div>
|
|
3067
|
+
<pre id="route-result">Response will show here.</pre>
|
|
3068
|
+
</form>
|
|
3069
|
+
</section>
|
|
3070
|
+
</main>
|
|
3071
|
+
</div>
|
|
3072
|
+
</div>
|
|
3073
|
+
<dialog id="editor">
|
|
3074
|
+
<form method="dialog" id="editor-form">
|
|
3075
|
+
<strong id="editor-title">Record</strong>
|
|
3076
|
+
<label class="field">Id
|
|
3077
|
+
<input id="editor-id" required>
|
|
3078
|
+
</label>
|
|
3079
|
+
<label class="field">JSON value
|
|
3080
|
+
<textarea id="editor-value"></textarea>
|
|
3081
|
+
</label>
|
|
3082
|
+
<div class="dialog-actions">
|
|
3083
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
3084
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
3085
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
3086
|
+
</div>
|
|
3087
|
+
</form>
|
|
3088
|
+
</dialog>
|
|
3089
|
+
${script}
|
|
3090
|
+
</body>
|
|
3091
|
+
</html>`;
|
|
3092
|
+
};
|
|
3093
|
+
var htmlResponse = (body) => new Response(body, {
|
|
3094
|
+
status: 200,
|
|
3095
|
+
headers: {
|
|
3096
|
+
"content-type": "text/html; charset=utf-8",
|
|
3097
|
+
"cache-control": "no-store"
|
|
3098
|
+
}
|
|
3099
|
+
});
|
|
3100
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
3101
|
+
status: 200,
|
|
3102
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3103
|
+
});
|
|
3104
|
+
var adminUiRoutes = (service, ui) => {
|
|
3105
|
+
const shell = () => renderAdminDocument(service);
|
|
3106
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
3107
|
+
return {
|
|
3108
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
3109
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
3110
|
+
"GET /ui/manifest": () => json2({
|
|
3111
|
+
service,
|
|
3112
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
3113
|
+
id: panel.id,
|
|
3114
|
+
title: panel.title,
|
|
3115
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
3116
|
+
html: panel.html,
|
|
3117
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
3118
|
+
}))
|
|
3119
|
+
})
|
|
3120
|
+
};
|
|
3121
|
+
};
|
|
3122
|
+
|
|
1390
3123
|
// ../../openapi/metadata/dist/types.js
|
|
1391
3124
|
var EXTENSION_KEYS = {
|
|
1392
3125
|
operation: "x-mockingbird",
|
|
@@ -1399,11 +3132,11 @@ var EXTENSION_KEYS = {
|
|
|
1399
3132
|
};
|
|
1400
3133
|
|
|
1401
3134
|
// ../../openapi/metadata/dist/read.js
|
|
1402
|
-
var
|
|
3135
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1403
3136
|
var extensionOf = (holder, key2) => holder[key2];
|
|
1404
3137
|
var operationMetadata = (operation) => {
|
|
1405
3138
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
1406
|
-
const ext =
|
|
3139
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
1407
3140
|
const supported = ext.supported ?? true;
|
|
1408
3141
|
const parity = ext.parity ?? {};
|
|
1409
3142
|
return {
|
|
@@ -1523,9 +3256,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
1523
3256
|
this.name = "OperationRegistryError";
|
|
1524
3257
|
}
|
|
1525
3258
|
};
|
|
1526
|
-
var verifyOperations = (
|
|
3259
|
+
var verifyOperations = (document3, handlers) => {
|
|
1527
3260
|
const problems = [];
|
|
1528
|
-
const operations = listOperations(
|
|
3261
|
+
const operations = listOperations(document3);
|
|
1529
3262
|
const seen = /* @__PURE__ */ new Set();
|
|
1530
3263
|
for (const operation of operations) {
|
|
1531
3264
|
if (seen.has(operation.operationId))
|
|
@@ -1634,8 +3367,442 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1634
3367
|
});
|
|
1635
3368
|
};
|
|
1636
3369
|
|
|
3370
|
+
// ../core/dist/state-view.js
|
|
3371
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
3372
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
3373
|
+
var SAMPLE = 25;
|
|
3374
|
+
var WALK_LIMIT = 1e4;
|
|
3375
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3376
|
+
var fail = (status, message) => ({ ok: false, status, message });
|
|
3377
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3378
|
+
var kindOf = (value) => {
|
|
3379
|
+
if (value === null)
|
|
3380
|
+
return "null";
|
|
3381
|
+
if (Array.isArray(value))
|
|
3382
|
+
return "array";
|
|
3383
|
+
switch (typeof value) {
|
|
3384
|
+
case "string":
|
|
3385
|
+
return "string";
|
|
3386
|
+
case "number":
|
|
3387
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3388
|
+
case "boolean":
|
|
3389
|
+
return "boolean";
|
|
3390
|
+
case "object":
|
|
3391
|
+
return "object";
|
|
3392
|
+
default:
|
|
3393
|
+
return "unknown";
|
|
3394
|
+
}
|
|
3395
|
+
};
|
|
3396
|
+
var humanize = (name) => {
|
|
3397
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3398
|
+
if (words === "")
|
|
3399
|
+
return name;
|
|
3400
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3401
|
+
};
|
|
3402
|
+
var jsonValue = (value) => {
|
|
3403
|
+
if (value === void 0)
|
|
3404
|
+
return fail(400, "value is required");
|
|
3405
|
+
try {
|
|
3406
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3407
|
+
} catch {
|
|
3408
|
+
return fail(400, "value must be JSON");
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
var ctorName = (value) => {
|
|
3412
|
+
const ctor = value.constructor;
|
|
3413
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3414
|
+
};
|
|
3415
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3416
|
+
var discoverCollections = (root) => {
|
|
3417
|
+
const found = [];
|
|
3418
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3419
|
+
const visit = (value, depth) => {
|
|
3420
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3421
|
+
return;
|
|
3422
|
+
if (value === null || typeof value !== "object")
|
|
3423
|
+
return;
|
|
3424
|
+
if (seen.has(value))
|
|
3425
|
+
return;
|
|
3426
|
+
seen.add(value);
|
|
3427
|
+
if (value instanceof Collection) {
|
|
3428
|
+
found.push(value);
|
|
3429
|
+
return;
|
|
3430
|
+
}
|
|
3431
|
+
if (value instanceof Map) {
|
|
3432
|
+
for (const child of value.values())
|
|
3433
|
+
visit(child, depth + 1);
|
|
3434
|
+
return;
|
|
3435
|
+
}
|
|
3436
|
+
if (value instanceof Set) {
|
|
3437
|
+
for (const child of value.values())
|
|
3438
|
+
visit(child, depth + 1);
|
|
3439
|
+
return;
|
|
3440
|
+
}
|
|
3441
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3442
|
+
return;
|
|
3443
|
+
if (Array.isArray(value)) {
|
|
3444
|
+
const cap = Math.min(value.length, 32);
|
|
3445
|
+
for (let i = 0; i < cap; i++)
|
|
3446
|
+
visit(value[i], depth + 1);
|
|
3447
|
+
return;
|
|
3448
|
+
}
|
|
3449
|
+
let children;
|
|
3450
|
+
try {
|
|
3451
|
+
children = Object.values(value);
|
|
3452
|
+
} catch {
|
|
3453
|
+
return;
|
|
3454
|
+
}
|
|
3455
|
+
for (const child of children)
|
|
3456
|
+
visit(child, depth + 1);
|
|
3457
|
+
};
|
|
3458
|
+
visit(root, 0);
|
|
3459
|
+
return found;
|
|
3460
|
+
};
|
|
3461
|
+
var storedNames = (sqlite, namespace) => {
|
|
3462
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3463
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3464
|
+
return [...records, ...sequences].map((row) => row.name);
|
|
3465
|
+
};
|
|
3466
|
+
var blankAccum = (name) => ({
|
|
3467
|
+
name,
|
|
3468
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3469
|
+
present: 0,
|
|
3470
|
+
nested: /* @__PURE__ */ new Map()
|
|
3471
|
+
});
|
|
3472
|
+
var absorb = (accum, value) => {
|
|
3473
|
+
const kind = kindOf(value);
|
|
3474
|
+
accum.kinds.add(kind);
|
|
3475
|
+
accum.present++;
|
|
3476
|
+
if (!isRecord4(value))
|
|
3477
|
+
return;
|
|
3478
|
+
for (const [key2, child] of Object.entries(value)) {
|
|
3479
|
+
const nested = accum.nested.get(key2) ?? blankAccum(key2);
|
|
3480
|
+
absorb(nested, child);
|
|
3481
|
+
accum.nested.set(key2, nested);
|
|
3482
|
+
}
|
|
3483
|
+
};
|
|
3484
|
+
var finishField = (accum, samples) => {
|
|
3485
|
+
const kinds = [...accum.kinds];
|
|
3486
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3487
|
+
const field = {
|
|
3488
|
+
name: accum.name,
|
|
3489
|
+
kind,
|
|
3490
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3491
|
+
};
|
|
3492
|
+
if (accum.nested.size > 0) {
|
|
3493
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3494
|
+
}
|
|
3495
|
+
return field;
|
|
3496
|
+
};
|
|
3497
|
+
var inferFields = (records) => {
|
|
3498
|
+
if (records.length === 0)
|
|
3499
|
+
return [];
|
|
3500
|
+
const sample = records.slice(0, SAMPLE);
|
|
3501
|
+
const objects = sample.filter((record2) => isRecord4(record2.value));
|
|
3502
|
+
if (objects.length === 0) {
|
|
3503
|
+
const kinds = new Set(sample.map((record2) => kindOf(record2.value)));
|
|
3504
|
+
const list = [...kinds];
|
|
3505
|
+
return [
|
|
3506
|
+
{
|
|
3507
|
+
name: "(value)",
|
|
3508
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3509
|
+
optional: false
|
|
3510
|
+
}
|
|
3511
|
+
];
|
|
3512
|
+
}
|
|
3513
|
+
const root = /* @__PURE__ */ new Map();
|
|
3514
|
+
for (const record2 of objects) {
|
|
3515
|
+
for (const [key2, value] of Object.entries(record2.value)) {
|
|
3516
|
+
const accum = root.get(key2) ?? blankAccum(key2);
|
|
3517
|
+
absorb(accum, value);
|
|
3518
|
+
root.set(key2, accum);
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3522
|
+
};
|
|
3523
|
+
var mergeFields = (declared, inferred) => {
|
|
3524
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3525
|
+
for (const field of inferred)
|
|
3526
|
+
byName.set(field.name, field);
|
|
3527
|
+
const ordered = [];
|
|
3528
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3529
|
+
for (const field of declared ?? []) {
|
|
3530
|
+
const found = byName.get(field.name);
|
|
3531
|
+
seen.add(field.name);
|
|
3532
|
+
if (!found) {
|
|
3533
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3534
|
+
continue;
|
|
3535
|
+
}
|
|
3536
|
+
ordered.push({
|
|
3537
|
+
...found,
|
|
3538
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3539
|
+
optional: field.optional || found.optional,
|
|
3540
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3541
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3542
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3543
|
+
});
|
|
3544
|
+
}
|
|
3545
|
+
for (const field of inferred) {
|
|
3546
|
+
if (!seen.has(field.name))
|
|
3547
|
+
ordered.push(field);
|
|
3548
|
+
}
|
|
3549
|
+
return ordered;
|
|
3550
|
+
};
|
|
3551
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3552
|
+
var readRecord = (collection, id) => {
|
|
3553
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3554
|
+
const row = rows.find((entry) => entry.id === id);
|
|
3555
|
+
return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
|
|
3556
|
+
};
|
|
3557
|
+
var inspectState = (scope) => {
|
|
3558
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3559
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3560
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3561
|
+
declared.set(declaration.name, declaration);
|
|
3562
|
+
}
|
|
3563
|
+
const names = new Set(declared.keys());
|
|
3564
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3565
|
+
names.add(name);
|
|
3566
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3567
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3568
|
+
names.add(collection.collectionName);
|
|
3569
|
+
}
|
|
3570
|
+
const collections = [];
|
|
3571
|
+
for (const name of names) {
|
|
3572
|
+
if (!COLLECTION_NAME.test(name))
|
|
3573
|
+
continue;
|
|
3574
|
+
const declaration = declared.get(name);
|
|
3575
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3576
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
|
|
3577
|
+
const inferred = inferFields(records);
|
|
3578
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3579
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3580
|
+
collections.push({
|
|
3581
|
+
name,
|
|
3582
|
+
label: declaration?.label ?? humanize(name),
|
|
3583
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3584
|
+
count: collection.count(),
|
|
3585
|
+
source,
|
|
3586
|
+
fields,
|
|
3587
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3588
|
+
});
|
|
3589
|
+
}
|
|
3590
|
+
const order = /* @__PURE__ */ new Map();
|
|
3591
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3592
|
+
order.set(item.name, index);
|
|
3593
|
+
collections.sort((a, b) => {
|
|
3594
|
+
const left = order.get(a.name);
|
|
3595
|
+
const right = order.get(b.name);
|
|
3596
|
+
if (left !== void 0 && right !== void 0)
|
|
3597
|
+
return left - right;
|
|
3598
|
+
if (left !== void 0)
|
|
3599
|
+
return -1;
|
|
3600
|
+
if (right !== void 0)
|
|
3601
|
+
return 1;
|
|
3602
|
+
return a.name.localeCompare(b.name);
|
|
3603
|
+
});
|
|
3604
|
+
return {
|
|
3605
|
+
namespace: scope.namespace,
|
|
3606
|
+
storageNamespace: scope.storageNamespace,
|
|
3607
|
+
collections
|
|
3608
|
+
};
|
|
3609
|
+
};
|
|
3610
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3611
|
+
if (!COLLECTION_NAME.test(name))
|
|
3612
|
+
return fail(400, "collection name is not allowed");
|
|
3613
|
+
const limit = query.limit ?? 50;
|
|
3614
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3615
|
+
return fail(400, "limit must be an integer from 1 to 200");
|
|
3616
|
+
}
|
|
3617
|
+
const order = query.order ?? "newest";
|
|
3618
|
+
if (order !== "newest" && order !== "oldest")
|
|
3619
|
+
return fail(400, 'order must be "newest" or "oldest"');
|
|
3620
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3621
|
+
const rows = collection.list({ order }).filter((row) => {
|
|
3622
|
+
if (query.after === void 0)
|
|
3623
|
+
return true;
|
|
3624
|
+
return order === "newest" ? row.seq < query.after : row.seq > query.after;
|
|
3625
|
+
});
|
|
3626
|
+
const slice = rows.slice(0, limit);
|
|
3627
|
+
const last = slice.at(-1);
|
|
3628
|
+
return {
|
|
3629
|
+
ok: true,
|
|
3630
|
+
value: {
|
|
3631
|
+
collection: name,
|
|
3632
|
+
count: collection.count(),
|
|
3633
|
+
records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
|
|
3634
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3635
|
+
}
|
|
3636
|
+
};
|
|
3637
|
+
};
|
|
3638
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3639
|
+
var readStateRecord = (scope, name, id) => {
|
|
3640
|
+
if (!COLLECTION_NAME.test(name))
|
|
3641
|
+
return fail(400, "collection name is not allowed");
|
|
3642
|
+
if (!RECORD_ID.test(id))
|
|
3643
|
+
return fail(400, "record id is not allowed");
|
|
3644
|
+
const record2 = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3645
|
+
return record2 ? { ok: true, value: record2 } : fail(404, `no record ${id} in ${name}`);
|
|
3646
|
+
};
|
|
3647
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
|
|
3648
|
+
var createStateRecord = (scope, name, input) => {
|
|
3649
|
+
if (!COLLECTION_NAME.test(name))
|
|
3650
|
+
return fail(400, "collection name is not allowed");
|
|
3651
|
+
const parsed = jsonValue(input.value);
|
|
3652
|
+
if (!parsed.ok)
|
|
3653
|
+
return parsed;
|
|
3654
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3655
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3656
|
+
const checked = requireId(id);
|
|
3657
|
+
if (!checked.ok)
|
|
3658
|
+
return checked;
|
|
3659
|
+
if (collection.has(checked.value))
|
|
3660
|
+
return fail(409, `record ${checked.value} already exists`);
|
|
3661
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3662
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3663
|
+
};
|
|
3664
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3665
|
+
if (!COLLECTION_NAME.test(name))
|
|
3666
|
+
return fail(400, "collection name is not allowed");
|
|
3667
|
+
const checked = requireId(id);
|
|
3668
|
+
if (!checked.ok)
|
|
3669
|
+
return checked;
|
|
3670
|
+
const parsed = jsonValue(value);
|
|
3671
|
+
if (!parsed.ok)
|
|
3672
|
+
return parsed;
|
|
3673
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3674
|
+
if (!collection.has(checked.value))
|
|
3675
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3676
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3677
|
+
if (!stored)
|
|
3678
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3679
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3680
|
+
};
|
|
3681
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3682
|
+
const current = readStateRecord(scope, name, id);
|
|
3683
|
+
if (!current.ok)
|
|
3684
|
+
return current;
|
|
3685
|
+
const parsed = jsonValue(value);
|
|
3686
|
+
if (!parsed.ok)
|
|
3687
|
+
return parsed;
|
|
3688
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3689
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3690
|
+
};
|
|
3691
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3692
|
+
if (!COLLECTION_NAME.test(name))
|
|
3693
|
+
return fail(400, "collection name is not allowed");
|
|
3694
|
+
const checked = requireId(id);
|
|
3695
|
+
if (!checked.ok)
|
|
3696
|
+
return checked;
|
|
3697
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3698
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
|
|
3699
|
+
};
|
|
3700
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3701
|
+
status,
|
|
3702
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3703
|
+
});
|
|
3704
|
+
var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
|
|
3705
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3706
|
+
var integerParam = (value) => {
|
|
3707
|
+
if (value === null)
|
|
3708
|
+
return void 0;
|
|
3709
|
+
if (!/^-?\d+$/.test(value))
|
|
3710
|
+
return "bad";
|
|
3711
|
+
return Number(value);
|
|
3712
|
+
};
|
|
3713
|
+
var stateAdminRoutes = (routes) => {
|
|
3714
|
+
const open = (namespace) => {
|
|
3715
|
+
try {
|
|
3716
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3717
|
+
} catch (error2) {
|
|
3718
|
+
return fail(400, error2 instanceof Error ? error2.message : String(error2));
|
|
3719
|
+
}
|
|
3720
|
+
};
|
|
3721
|
+
const wrote = (namespace) => {
|
|
3722
|
+
routes.afterWrite?.(namespace);
|
|
3723
|
+
};
|
|
3724
|
+
return {
|
|
3725
|
+
"GET /state": ({ namespace }) => {
|
|
3726
|
+
const scope = open(namespace);
|
|
3727
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3728
|
+
},
|
|
3729
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3730
|
+
const scope = open(namespace);
|
|
3731
|
+
if (!scope.ok)
|
|
3732
|
+
return fromResult(scope, 200);
|
|
3733
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3734
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3735
|
+
if (limit === "bad")
|
|
3736
|
+
return adminError2(400, "limit: expected an integer");
|
|
3737
|
+
if (after === "bad")
|
|
3738
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3739
|
+
const order = url.searchParams.get("order");
|
|
3740
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3741
|
+
...limit !== void 0 ? { limit } : {},
|
|
3742
|
+
...after !== void 0 ? { after } : {},
|
|
3743
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3744
|
+
}), 200);
|
|
3745
|
+
},
|
|
3746
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3747
|
+
const scope = open(namespace);
|
|
3748
|
+
if (!scope.ok)
|
|
3749
|
+
return fromResult(scope, 200);
|
|
3750
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3751
|
+
},
|
|
3752
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3753
|
+
const scope = open(namespace);
|
|
3754
|
+
if (!scope.ok)
|
|
3755
|
+
return fromResult(scope, 201);
|
|
3756
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
3757
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3758
|
+
}
|
|
3759
|
+
const id = body.id;
|
|
3760
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3761
|
+
return adminError2(400, "id must be a string");
|
|
3762
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3763
|
+
...typeof id === "string" ? { id } : {},
|
|
3764
|
+
value: body.value
|
|
3765
|
+
});
|
|
3766
|
+
if (created.ok)
|
|
3767
|
+
wrote(namespace);
|
|
3768
|
+
return fromResult(created, 201);
|
|
3769
|
+
},
|
|
3770
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3771
|
+
const scope = open(namespace);
|
|
3772
|
+
if (!scope.ok)
|
|
3773
|
+
return fromResult(scope, 200);
|
|
3774
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3775
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3776
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3777
|
+
if (replaced.ok)
|
|
3778
|
+
wrote(namespace);
|
|
3779
|
+
return fromResult(replaced, 200);
|
|
3780
|
+
},
|
|
3781
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3782
|
+
const scope = open(namespace);
|
|
3783
|
+
if (!scope.ok)
|
|
3784
|
+
return fromResult(scope, 200);
|
|
3785
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3786
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3787
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3788
|
+
if (patched.ok)
|
|
3789
|
+
wrote(namespace);
|
|
3790
|
+
return fromResult(patched, 200);
|
|
3791
|
+
},
|
|
3792
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3793
|
+
const scope = open(namespace);
|
|
3794
|
+
if (!scope.ok)
|
|
3795
|
+
return fromResult(scope, 200);
|
|
3796
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3797
|
+
if (removed.ok)
|
|
3798
|
+
wrote(namespace);
|
|
3799
|
+
return fromResult(removed, 200);
|
|
3800
|
+
}
|
|
3801
|
+
};
|
|
3802
|
+
};
|
|
3803
|
+
|
|
1637
3804
|
// ../core/dist/version.js
|
|
1638
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3805
|
+
var PACKAGE_VERSION = true ? "1.5.0" : UNRELEASED_VERSION;
|
|
1639
3806
|
|
|
1640
3807
|
// ../core/dist/signing.js
|
|
1641
3808
|
var encoder = new TextEncoder();
|
|
@@ -1978,11 +4145,11 @@ var createWebhookHub = (options) => {
|
|
|
1978
4145
|
};
|
|
1979
4146
|
return hub;
|
|
1980
4147
|
};
|
|
1981
|
-
var
|
|
1982
|
-
var
|
|
1983
|
-
var
|
|
4148
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
4149
|
+
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
4150
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1984
4151
|
var parseEndpoint = (value) => {
|
|
1985
|
-
if (!
|
|
4152
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
1986
4153
|
return "each endpoint needs a url";
|
|
1987
4154
|
try {
|
|
1988
4155
|
new URL(value.url);
|
|
@@ -1999,18 +4166,18 @@ var parseEndpoint = (value) => {
|
|
|
1999
4166
|
const events = value.events ?? value.enabledEvents;
|
|
2000
4167
|
if (Array.isArray(events))
|
|
2001
4168
|
endpoint.events = events.map(String);
|
|
2002
|
-
if (
|
|
4169
|
+
if (isRecord5(value.tags)) {
|
|
2003
4170
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
2004
4171
|
}
|
|
2005
4172
|
if (typeof value.account === "string")
|
|
2006
4173
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
2007
|
-
if (
|
|
4174
|
+
if (isRecord5(value.headers)) {
|
|
2008
4175
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
2009
4176
|
}
|
|
2010
4177
|
return endpoint;
|
|
2011
4178
|
};
|
|
2012
4179
|
var webhookAdminRoutes = (hub) => ({
|
|
2013
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
4180
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
2014
4181
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
2015
4182
|
const type = url.searchParams.get("type");
|
|
2016
4183
|
return type === null || d.type === type;
|
|
@@ -2018,51 +4185,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
2018
4185
|
}),
|
|
2019
4186
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
2020
4187
|
const type = url.searchParams.get("type");
|
|
2021
|
-
return
|
|
4188
|
+
return json4(200, {
|
|
2022
4189
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
2023
4190
|
});
|
|
2024
4191
|
},
|
|
2025
4192
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
2026
4193
|
const replayed = await hub.replay(params.id);
|
|
2027
|
-
return replayed ?
|
|
4194
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
2028
4195
|
},
|
|
2029
4196
|
"POST /webhooks/flush": async () => {
|
|
2030
4197
|
await hub.flush();
|
|
2031
|
-
return
|
|
4198
|
+
return json4(200, { status: "ok" });
|
|
2032
4199
|
},
|
|
2033
4200
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
2034
|
-
if (!
|
|
2035
|
-
return
|
|
4201
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
4202
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
2036
4203
|
}
|
|
2037
4204
|
const fault = { mode: body.mode };
|
|
2038
4205
|
if (typeof body.count === "number")
|
|
2039
4206
|
fault.count = body.count;
|
|
2040
4207
|
hub.fault(namespace, fault);
|
|
2041
|
-
return
|
|
4208
|
+
return json4(201, { namespace, ...fault });
|
|
2042
4209
|
},
|
|
2043
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
4210
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
2044
4211
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
2045
4212
|
...rest,
|
|
2046
4213
|
secret: secret ? "(set)" : null
|
|
2047
4214
|
}))
|
|
2048
4215
|
}),
|
|
2049
4216
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
2050
|
-
const list = Array.isArray(body) ? body :
|
|
4217
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
2051
4218
|
if (!Array.isArray(list))
|
|
2052
|
-
return
|
|
4219
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
2053
4220
|
const parsed = [];
|
|
2054
4221
|
for (const each of list) {
|
|
2055
4222
|
const endpoint = parseEndpoint(each);
|
|
2056
4223
|
if (typeof endpoint === "string")
|
|
2057
|
-
return
|
|
4224
|
+
return adminError3(400, endpoint);
|
|
2058
4225
|
parsed.push(endpoint);
|
|
2059
4226
|
}
|
|
2060
4227
|
const set = hub.setEndpoints(namespace, parsed);
|
|
2061
|
-
return
|
|
4228
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
2062
4229
|
},
|
|
2063
4230
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
2064
4231
|
hub.setEndpoints(namespace, []);
|
|
2065
|
-
return
|
|
4232
|
+
return json4(200, { status: "ok" });
|
|
2066
4233
|
}
|
|
2067
4234
|
});
|
|
2068
4235
|
var parsePayload = (message) => {
|
|
@@ -2117,8 +4284,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
2117
4284
|
this.name = "TypeError";
|
|
2118
4285
|
}
|
|
2119
4286
|
};
|
|
2120
|
-
var operationMatcher = (
|
|
2121
|
-
const matchers = listOperations(
|
|
4287
|
+
var operationMatcher = (document3) => {
|
|
4288
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
2122
4289
|
operationId: operation.operationId,
|
|
2123
4290
|
method: operation.method.toUpperCase(),
|
|
2124
4291
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -2127,6 +4294,7 @@ var operationMatcher = (document2) => {
|
|
|
2127
4294
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
2128
4295
|
};
|
|
2129
4296
|
var createRuntime = (options) => {
|
|
4297
|
+
assertAdminUi(options.adminUi);
|
|
2130
4298
|
const sqlite = bootSqlite(options.sqlite);
|
|
2131
4299
|
const clock = options.clock ?? createClock();
|
|
2132
4300
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -2212,10 +4380,10 @@ var createRuntime = (options) => {
|
|
|
2212
4380
|
const ensureBranch = (namespace, branch2, at) => {
|
|
2213
4381
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
2214
4382
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
2215
|
-
const
|
|
4383
|
+
const history2 = timeline(namespace);
|
|
2216
4384
|
if (branch2 === "main") {
|
|
2217
4385
|
if (at !== void 0) {
|
|
2218
|
-
const point =
|
|
4386
|
+
const point = history2.checkout("main", at);
|
|
2219
4387
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
2220
4388
|
captured.set(namespace, point.value.snapshot);
|
|
2221
4389
|
rng.setState(point.value.rngState);
|
|
@@ -2228,10 +4396,10 @@ var createRuntime = (options) => {
|
|
|
2228
4396
|
return namespace;
|
|
2229
4397
|
}
|
|
2230
4398
|
const storage = physicalBranch(namespace, branch2);
|
|
2231
|
-
if (!
|
|
4399
|
+
if (!history2.hasBranch(branch2)) {
|
|
2232
4400
|
if (at === void 0)
|
|
2233
|
-
|
|
2234
|
-
const point =
|
|
4401
|
+
history2.commit(capture(namespace));
|
|
4402
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
2235
4403
|
const branchRng = createRng(options.seed ?? 0);
|
|
2236
4404
|
if (point)
|
|
2237
4405
|
branchRng.setState(point.value.rngState);
|
|
@@ -2240,8 +4408,8 @@ var createRuntime = (options) => {
|
|
|
2240
4408
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
2241
4409
|
if (point)
|
|
2242
4410
|
captured.set(storage, point.value.snapshot);
|
|
2243
|
-
} else if (at !== void 0 &&
|
|
2244
|
-
const point =
|
|
4411
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
4412
|
+
const point = history2.checkout(branch2, at);
|
|
2245
4413
|
if (!instances.has(storage)) {
|
|
2246
4414
|
const branchRng = createRng(options.seed ?? 0);
|
|
2247
4415
|
branchRng.setState(point.value.rngState);
|
|
@@ -2252,7 +4420,7 @@ var createRuntime = (options) => {
|
|
|
2252
4420
|
captured.set(storage, point.value.snapshot);
|
|
2253
4421
|
} else {
|
|
2254
4422
|
if (!instances.has(storage)) {
|
|
2255
|
-
const point =
|
|
4423
|
+
const point = history2.head(branch2);
|
|
2256
4424
|
const branchRng = createRng(options.seed ?? 0);
|
|
2257
4425
|
if (point)
|
|
2258
4426
|
branchRng.setState(point.value.rngState);
|
|
@@ -2276,8 +4444,8 @@ var createRuntime = (options) => {
|
|
|
2276
4444
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
2277
4445
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
2278
4446
|
const branchName = checkoutOptions.branch ?? "main";
|
|
2279
|
-
const
|
|
2280
|
-
const point =
|
|
4447
|
+
const history2 = timeline(namespace);
|
|
4448
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
2281
4449
|
const storage = ensureBranch(namespace, branchName);
|
|
2282
4450
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
2283
4451
|
captured.set(storage, point.value.snapshot);
|
|
@@ -2327,12 +4495,25 @@ var createRuntime = (options) => {
|
|
|
2327
4495
|
instance(name);
|
|
2328
4496
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
2329
4497
|
captured.set(name, from);
|
|
2330
|
-
const
|
|
2331
|
-
if (
|
|
2332
|
-
|
|
4498
|
+
const history2 = timelines.get(name);
|
|
4499
|
+
if (history2)
|
|
4500
|
+
history2.commit(capture(name), { branch: "main" });
|
|
2333
4501
|
else
|
|
2334
4502
|
timeline(name);
|
|
2335
4503
|
};
|
|
4504
|
+
const declarationsFor = (namespace) => {
|
|
4505
|
+
const declared = options.state;
|
|
4506
|
+
if (!declared)
|
|
4507
|
+
return [];
|
|
4508
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
4509
|
+
};
|
|
4510
|
+
const stateScope = (namespace) => ({
|
|
4511
|
+
sqlite,
|
|
4512
|
+
namespace,
|
|
4513
|
+
storageNamespace: storageNamespace(namespace),
|
|
4514
|
+
root: instance(namespace),
|
|
4515
|
+
declarations: declarationsFor(namespace)
|
|
4516
|
+
});
|
|
2336
4517
|
const runtime = {
|
|
2337
4518
|
name: options.name,
|
|
2338
4519
|
sqlite,
|
|
@@ -2371,6 +4552,7 @@ var createRuntime = (options) => {
|
|
|
2371
4552
|
branch,
|
|
2372
4553
|
checkout,
|
|
2373
4554
|
timeline,
|
|
4555
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
2374
4556
|
fetch: async (incoming) => {
|
|
2375
4557
|
let request = incoming;
|
|
2376
4558
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -2544,10 +4726,10 @@ var createRuntime = (options) => {
|
|
|
2544
4726
|
},
|
|
2545
4727
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
2546
4728
|
inspect: (name) => {
|
|
2547
|
-
const
|
|
4729
|
+
const history2 = timeline(name);
|
|
2548
4730
|
return {
|
|
2549
|
-
branches:
|
|
2550
|
-
checkpoints:
|
|
4731
|
+
branches: history2.branches(),
|
|
4732
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
2551
4733
|
id,
|
|
2552
4734
|
branch: branchName,
|
|
2553
4735
|
parent,
|
|
@@ -2562,13 +4744,22 @@ var createRuntime = (options) => {
|
|
|
2562
4744
|
} : {},
|
|
2563
4745
|
routes: {
|
|
2564
4746
|
...credentialRoutes(credentials),
|
|
2565
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
2566
4747
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
2567
|
-
...options.admin?.(runtime) ?? {}
|
|
4748
|
+
...options.admin?.(runtime) ?? {},
|
|
4749
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4750
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4751
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4752
|
+
...stateAdminRoutes({
|
|
4753
|
+
open: stateScope,
|
|
4754
|
+
afterWrite: (namespace) => {
|
|
4755
|
+
checkpoint(namespace, "main");
|
|
4756
|
+
}
|
|
4757
|
+
}),
|
|
4758
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
2568
4759
|
},
|
|
2569
4760
|
adminKey: options.adminKey
|
|
2570
4761
|
});
|
|
2571
|
-
return runtime;
|
|
4762
|
+
return defineMock(runtime);
|
|
2572
4763
|
};
|
|
2573
4764
|
var mutableResponse = (response) => {
|
|
2574
4765
|
try {
|
|
@@ -2632,9 +4823,12 @@ var credentialRoutes = (registry) => ({
|
|
|
2632
4823
|
}
|
|
2633
4824
|
});
|
|
2634
4825
|
var presetRoutes = (presets, runtime) => ({
|
|
2635
|
-
"GET /faults/presets": () =>
|
|
2636
|
-
|
|
2637
|
-
|
|
4826
|
+
"GET /faults/presets": () => {
|
|
4827
|
+
const body = {
|
|
4828
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4829
|
+
};
|
|
4830
|
+
return adminJson(200, body);
|
|
4831
|
+
},
|
|
2638
4832
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
2639
4833
|
const name = params.name;
|
|
2640
4834
|
if (!presets[name])
|
|
@@ -2645,7 +4839,7 @@ var presetRoutes = (presets, runtime) => ({
|
|
|
2645
4839
|
});
|
|
2646
4840
|
|
|
2647
4841
|
// src/generated/openapi.ts
|
|
2648
|
-
var
|
|
4842
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"AHA (Advanced Health Academy) partner API (Mockingbird subset)","description":"Stateful mock of the AHA at-home phlebotomy partner API: create-or-update order and cancel.\\nThe vendor has no pull API; order state reaches the partner only as inbound webhooks, which\\nthe mock emits from admin transitions (see the README). Hand-authored from the consumer's\\nwire shapes (the vendor publishes no spec).\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from aha.service.ts, aha.types.ts (zod request/response schemas) and aha.lab-provider.ts. Success responses come in one of two envelopes (raw, or {success, data}) because our two clients disagree (G-A1); the mock serves either."}},"servers":[{"url":"https://stage-api.mobileaha.com"}],"security":[{"hmacKey":[],"hmacTimestamp":[],"hmacSignature":[]},{"legacyKey":[]}],"paths":{"/v1/{partner}/create-order":{"post":{"operationId":"CreateOrder","description":"Create an order, or update it when partner_order_id already exists (the same order_number is returned). Honors X-Idempotency-Key.","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"$ref":"#/components/parameters/Partner"},{"$ref":"#/components/parameters/IdempotencyKey"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderBody"}}}},"responses":{"200":{"description":"Order created or updated (raw or wrapped envelope, per namespace setting)","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/CreateOrderResponse"},{"$ref":"#/components/schemas/WrappedCreateOrderResponse"}]}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"401":{"description":"Missing or invalid authentication","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Idempotency key reused with a different request, or still in flight","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"429":{"description":"Rate limited","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"500":{"description":"Server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}},"/v1/{partner}/cancel":{"post":{"operationId":"CancelOrder","description":"Cancel an order by partner_order_id. The mock also accepts the AHA order_number here, because our lab-provider client sends it in that field (G-A1).","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"parameters":[{"$ref":"#/components/parameters/Partner"},{"$ref":"#/components/parameters/IdempotencyKey"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelOrderBody"}}}},"responses":{"200":{"description":"Cancel outcome (raw or wrapped envelope; status ERROR when not cancellable)","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/CancelOrderResponse"},{"$ref":"#/components/schemas/WrappedCancelOrderResponse"}]}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"401":{"description":"Missing or invalid authentication","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"404":{"description":"Unknown partner order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Idempotency key reused with a different request, or still in flight","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"429":{"description":"Rate limited","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"500":{"description":"Server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}}},"components":{"securitySchemes":{"hmacKey":{"type":"apiKey","in":"header","name":"X-API-KEY"},"hmacTimestamp":{"type":"apiKey","in":"header","name":"X-TIMESTAMP","description":"Unix epoch milliseconds."},"hmacSignature":{"type":"apiKey","in":"header","name":"X-SIGNATURE","description":"base64(HMAC-SHA256(apiSecret, \\"<apiKey>:<path>:<timestamp>\\"))."},"legacyKey":{"type":"apiKey","in":"header","name":"X-Acme-Auth-Key","description":"Legacy mode (AHA_USE_LEGACY_AUTH=true), sent with X-API-Version 1.0. The real header embeds the partner's name (\`X-<Partner>-Auth-Key\`); the mock accepts any partner name."}},"parameters":{"Partner":{"name":"partner","in":"path","required":true,"description":"The partner segment AHA assigns your account (its slug), e.g. \`acme\`.","schema":{"type":"string","pattern":"^[A-Za-z0-9_-]{1,64}$","examples":["acme"]}},"IdempotencyKey":{"name":"X-Idempotency-Key","in":"header","required":false,"description":"Sent by the lab-provider client; the same key and body replays the stored response.","schema":{"type":"string","pattern":"^[A-Za-z0-9:_.-]{1,128}$"}}},"schemas":{"TestCode":{"type":"object","required":["test_code","test_description"],"properties":{"test_code":{"type":"string","minLength":1,"maxLength":64},"test_description":{"type":"string","maxLength":200}}},"CreateOrderBody":{"type":"object","required":["partner_order_id","patient_first_name","patient_id","patient_last_name","biological_sex","patient_dob","patient_phone_number","patient_address_line1","patient_city","patient_state","patient_zipcode","service_type","npi","ordering_physician","test_codes"],"properties":{"partner_order_id":{"type":"string","minLength":1,"maxLength":64},"patient_first_name":{"type":"string","minLength":1,"maxLength":60},"patient_id":{"type":"string","minLength":1,"maxLength":64},"patient_middle_initial":{"type":"string","maxLength":5},"patient_last_name":{"type":"string","minLength":1,"maxLength":60},"biological_sex":{"type":"string","enum":["Male","Female","Non-binary"]},"patient_dob":{"type":"string","description":"YYYY-MM-DD","maxLength":10},"patient_phone_number":{"type":"string","description":"10 digits from AhaService; the lab-provider client may send +1XXXXXXXXXX.","maxLength":20},"patient_email_address":{"type":"string","maxLength":120},"patient_address_line1":{"type":"string","minLength":1,"maxLength":120},"patient_address_line2":{"type":"string","maxLength":120},"patient_city":{"type":"string","minLength":1,"maxLength":60},"patient_state":{"type":"string","minLength":1,"maxLength":20},"patient_zipcode":{"type":"string","minLength":1,"maxLength":10},"service_type":{"type":"string","enum":["Full Service","Draw Only","Pickup Only"]},"preferred_schedule_date":{"type":"string","description":"YYYY-MM-DD","maxLength":10},"preferred_schedule_time":{"type":"string","description":"HH:MM","maxLength":8},"patient_timezone":{"type":"string","description":"IANA zone, e.g. America/New_York","maxLength":64},"npi":{"type":"string","minLength":1,"maxLength":20},"ordering_physician":{"type":"string","minLength":1,"maxLength":120},"test_codes":{"type":"array","maxItems":20,"items":{"$ref":"#/components/schemas/TestCode"}}}},"CancelOrderBody":{"type":"object","required":["partner_order_id","notes"],"properties":{"partner_order_id":{"type":"string","minLength":1,"maxLength":64,"x-mockingbird-resource-ref":{"type":"order","missing":"AC-999999999"}},"notes":{"type":"array","maxItems":5,"items":{"type":"object","required":["note_type","notes"],"properties":{"note_type":{"type":"string","enum":["CANCELLATION"]},"notes":{"type":"string","maxLength":500}}}}}},"CreateOrderResponse":{"type":"object","required":["content","message","status"],"properties":{"content":{"type":"object","required":["partner_order_id","order_number"],"properties":{"partner_order_id":{"type":"string","x-mockingbird-resource":{"type":"order","identity":true}},"order_number":{"type":"string","x-mockingbird-volatile":{"kind":"id"}}}},"message":{"type":"string"},"status":{"type":"string","enum":["SUCCESS","ERROR"]}}},"WrappedCreateOrderResponse":{"type":"object","required":["success","data"],"properties":{"success":{"type":"boolean"},"data":{"$ref":"#/components/schemas/CreateOrderResponse"}}},"CancelOrderResponse":{"type":"object","required":["message","status"],"properties":{"message":{"type":"string"},"status":{"type":"string","enum":["SUCCESS","ERROR"]}}},"WrappedCancelOrderResponse":{"type":"object","required":["success","data"],"properties":{"success":{"type":"boolean"},"data":{"$ref":"#/components/schemas/CancelOrderResponse"}}},"ErrorBody":{"type":"object","required":["status","message"],"properties":{"status":{"type":"string","enum":["ERROR"]},"message":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}}}}`);
|
|
2649
4843
|
var operationIds = ["CreateOrder", "CancelOrder"];
|
|
2650
4844
|
var supportedOperationIds = ["CreateOrder", "CancelOrder"];
|
|
2651
4845
|
|
|
@@ -2830,13 +5024,13 @@ var AHA_PRESETS = {
|
|
|
2830
5024
|
webhook: { mode: "drop" }
|
|
2831
5025
|
}
|
|
2832
5026
|
};
|
|
2833
|
-
var
|
|
2834
|
-
var
|
|
2835
|
-
var
|
|
5027
|
+
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
5028
|
+
var adminError4 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
|
|
5029
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2836
5030
|
var parseAutoSchedule = (value) => {
|
|
2837
5031
|
if (value === null) return null;
|
|
2838
5032
|
if (typeof value === "number" && value >= 0) return { afterMs: value };
|
|
2839
|
-
if (!
|
|
5033
|
+
if (!isRecord6(value) || typeof value.afterMs !== "number" || value.afterMs < 0) {
|
|
2840
5034
|
return "autoSchedule must be {afterMs, leadMs?}, a number of ms, or null";
|
|
2841
5035
|
}
|
|
2842
5036
|
if (value.leadMs !== void 0 && typeof value.leadMs !== "number") return "leadMs: number";
|
|
@@ -2849,7 +5043,7 @@ var parseCredentials = (value) => {
|
|
|
2849
5043
|
if (!Array.isArray(value)) return "credentials: [{apiKey, apiSecret?}]";
|
|
2850
5044
|
const out = [];
|
|
2851
5045
|
for (const each of value) {
|
|
2852
|
-
if (!
|
|
5046
|
+
if (!isRecord6(each) || typeof each.apiKey !== "string") return "each credential needs apiKey";
|
|
2853
5047
|
out.push({
|
|
2854
5048
|
apiKey: each.apiKey,
|
|
2855
5049
|
...typeof each.apiSecret === "string" ? { apiSecret: each.apiSecret } : {}
|
|
@@ -2865,10 +5059,10 @@ var visible = (settings) => ({
|
|
|
2865
5059
|
}))
|
|
2866
5060
|
});
|
|
2867
5061
|
var adminRoutes = (runtime) => ({
|
|
2868
|
-
"GET /orders": ({ namespace }) =>
|
|
5062
|
+
"GET /orders": ({ namespace }) => json5(200, { orders: runtime.instance(namespace).orders() }),
|
|
2869
5063
|
"POST /orders/:partnerOrderId/transition": ({ params, body, namespace }) => {
|
|
2870
|
-
if (!
|
|
2871
|
-
return
|
|
5064
|
+
if (!isRecord6(body) || typeof body.status !== "string") {
|
|
5065
|
+
return adminError4(
|
|
2872
5066
|
400,
|
|
2873
5067
|
'expected {"status": "<AHA status>", "drawStatus"?, "scheduledAt"?, "timeZone"?}'
|
|
2874
5068
|
);
|
|
@@ -2881,50 +5075,50 @@ var adminRoutes = (runtime) => ({
|
|
|
2881
5075
|
if (typeof body.timeZone === "string") input.timeZone = body.timeZone;
|
|
2882
5076
|
try {
|
|
2883
5077
|
const moved = runtime.instance(namespace).transition(params.partnerOrderId, input);
|
|
2884
|
-
return moved ?
|
|
5078
|
+
return moved ? json5(200, moved) : adminError4(404, `no order ${params.partnerOrderId}`);
|
|
2885
5079
|
} catch (err) {
|
|
2886
|
-
if (err instanceof RangeError) return
|
|
5080
|
+
if (err instanceof RangeError) return adminError4(400, err.message);
|
|
2887
5081
|
throw err;
|
|
2888
5082
|
}
|
|
2889
5083
|
},
|
|
2890
|
-
"GET /settings": ({ namespace }) =>
|
|
5084
|
+
"GET /settings": ({ namespace }) => json5(200, visible(runtime.instance(namespace).state.current())),
|
|
2891
5085
|
"PUT /settings": ({ body, namespace }) => {
|
|
2892
|
-
if (!
|
|
5086
|
+
if (!isRecord6(body)) return adminError4(400, "expected a JSON object");
|
|
2893
5087
|
const patch = {};
|
|
2894
5088
|
if (body.envelope !== void 0) {
|
|
2895
5089
|
if (body.envelope !== "raw" && body.envelope !== "wrapped")
|
|
2896
|
-
return
|
|
5090
|
+
return adminError4(400, 'envelope: "raw" | "wrapped"');
|
|
2897
5091
|
patch.envelope = body.envelope;
|
|
2898
5092
|
}
|
|
2899
5093
|
if (body.credentials !== void 0) {
|
|
2900
5094
|
const parsed = parseCredentials(body.credentials);
|
|
2901
|
-
if (typeof parsed === "string") return
|
|
5095
|
+
if (typeof parsed === "string") return adminError4(400, parsed);
|
|
2902
5096
|
patch.credentials = parsed;
|
|
2903
5097
|
}
|
|
2904
5098
|
for (const flag of ["allowLegacy", "cancelWebhook"]) {
|
|
2905
5099
|
if (body[flag] !== void 0) {
|
|
2906
|
-
if (typeof body[flag] !== "boolean") return
|
|
5100
|
+
if (typeof body[flag] !== "boolean") return adminError4(400, `${flag}: boolean`);
|
|
2907
5101
|
patch[flag] = body[flag];
|
|
2908
5102
|
}
|
|
2909
5103
|
}
|
|
2910
5104
|
if (body.timestampToleranceMs !== void 0) {
|
|
2911
5105
|
if (typeof body.timestampToleranceMs !== "number")
|
|
2912
|
-
return
|
|
5106
|
+
return adminError4(400, "timestampToleranceMs: number");
|
|
2913
5107
|
patch.timestampToleranceMs = body.timestampToleranceMs;
|
|
2914
5108
|
}
|
|
2915
5109
|
if (body.defaultTimeZone !== void 0) {
|
|
2916
5110
|
if (typeof body.defaultTimeZone !== "string")
|
|
2917
|
-
return
|
|
5111
|
+
return adminError4(400, "defaultTimeZone: IANA zone");
|
|
2918
5112
|
patch.defaultTimeZone = body.defaultTimeZone;
|
|
2919
5113
|
}
|
|
2920
5114
|
if (body.autoSchedule !== void 0) {
|
|
2921
5115
|
const parsed = parseAutoSchedule(body.autoSchedule);
|
|
2922
|
-
if (typeof parsed === "string") return
|
|
5116
|
+
if (typeof parsed === "string") return adminError4(400, parsed);
|
|
2923
5117
|
patch.autoSchedule = parsed;
|
|
2924
5118
|
}
|
|
2925
|
-
return
|
|
5119
|
+
return json5(200, visible(runtime.instance(namespace).state.update(patch)));
|
|
2926
5120
|
},
|
|
2927
|
-
"POST /tick": ({ namespace }) =>
|
|
5121
|
+
"POST /tick": ({ namespace }) => json5(200, { applied: runtime.instance(namespace).tick() })
|
|
2928
5122
|
});
|
|
2929
5123
|
var createRuntime2 = (options = {}) => {
|
|
2930
5124
|
const { retryDelaysMs, fetch: send, ...endpoint } = options.webhooks ?? { url: "" };
|
|
@@ -2936,7 +5130,7 @@ var createRuntime2 = (options = {}) => {
|
|
|
2936
5130
|
});
|
|
2937
5131
|
const runtime = createRuntime({
|
|
2938
5132
|
name: AHA_NAMESPACE,
|
|
2939
|
-
document,
|
|
5133
|
+
document: document2,
|
|
2940
5134
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
2941
5135
|
...options.clock ? { clock: options.clock } : {},
|
|
2942
5136
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -3053,7 +5247,7 @@ var AhaAPI = class {
|
|
|
3053
5247
|
CancelOrder: (context) => this.idempotent(context, () => this.cancelOrder(context))
|
|
3054
5248
|
});
|
|
3055
5249
|
this.service = createService({
|
|
3056
|
-
document,
|
|
5250
|
+
document: document2,
|
|
3057
5251
|
handlers,
|
|
3058
5252
|
sqlite,
|
|
3059
5253
|
namespace,
|
|
@@ -3312,7 +5506,7 @@ var AhaAPI = class {
|
|
|
3312
5506
|
};
|
|
3313
5507
|
|
|
3314
5508
|
export {
|
|
3315
|
-
document,
|
|
5509
|
+
document2 as document,
|
|
3316
5510
|
operationIds,
|
|
3317
5511
|
supportedOperationIds,
|
|
3318
5512
|
ORDER_STATUSES,
|
|
@@ -3328,4 +5522,4 @@ export {
|
|
|
3328
5522
|
apiKeyCredential,
|
|
3329
5523
|
AhaAPI
|
|
3330
5524
|
};
|
|
3331
|
-
//# sourceMappingURL=chunk-
|
|
5525
|
+
//# sourceMappingURL=chunk-35HPZJ35.js.map
|