@crvouga/mockingbird-service-wholescripts 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-F4SR3IDU.js → chunk-UNARBOGB.js} +3 -2
- package/dist/{chunk-F4SR3IDU.js.map → chunk-UNARBOGB.js.map} +2 -2
- package/dist/{chunk-L6ET6K77.js → chunk-ZOKMHWCW.js} +2330 -136
- package/dist/chunk-ZOKMHWCW.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/server.d.ts +73 -3
- package/dist/server.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-L6ET6K77.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;
|
|
@@ -549,10 +551,10 @@ var OpenAPIReferenceError = class extends Error {
|
|
|
549
551
|
};
|
|
550
552
|
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
551
553
|
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
552
|
-
var resolveRef = (
|
|
554
|
+
var resolveRef = (document3, ref) => {
|
|
553
555
|
if (!ref.startsWith("#/"))
|
|
554
556
|
throw new OpenAPIReferenceError(ref);
|
|
555
|
-
let cursor =
|
|
557
|
+
let cursor = document3;
|
|
556
558
|
for (const raw of ref.slice(2).split("/")) {
|
|
557
559
|
const segment = unescapePointer(raw);
|
|
558
560
|
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
@@ -564,14 +566,14 @@ var resolveRef = (document2, ref) => {
|
|
|
564
566
|
throw new OpenAPIReferenceError(ref);
|
|
565
567
|
return cursor;
|
|
566
568
|
};
|
|
567
|
-
var deref = (
|
|
569
|
+
var deref = (document3, value) => {
|
|
568
570
|
let current = value;
|
|
569
571
|
const seen = /* @__PURE__ */ new Set();
|
|
570
572
|
while (isReference(current)) {
|
|
571
573
|
if (seen.has(current.$ref))
|
|
572
574
|
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
573
575
|
seen.add(current.$ref);
|
|
574
|
-
current = resolveRef(
|
|
576
|
+
current = resolveRef(document3, current.$ref);
|
|
575
577
|
}
|
|
576
578
|
return current;
|
|
577
579
|
};
|
|
@@ -589,36 +591,36 @@ var HTTP_METHODS = [
|
|
|
589
591
|
];
|
|
590
592
|
|
|
591
593
|
// ../../openapi/core/dist/document.js
|
|
592
|
-
var mergeParameters = (
|
|
594
|
+
var mergeParameters = (document3, item, own) => {
|
|
593
595
|
const merged = /* @__PURE__ */ new Map();
|
|
594
596
|
for (const raw of item.parameters ?? []) {
|
|
595
|
-
const parameter = deref(
|
|
597
|
+
const parameter = deref(document3, raw);
|
|
596
598
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
597
599
|
}
|
|
598
600
|
for (const raw of own ?? []) {
|
|
599
|
-
const parameter = deref(
|
|
601
|
+
const parameter = deref(document3, raw);
|
|
600
602
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
601
603
|
}
|
|
602
604
|
return [...merged.values()];
|
|
603
605
|
};
|
|
604
|
-
var listOperations = (
|
|
606
|
+
var listOperations = (document3) => {
|
|
605
607
|
const operations = [];
|
|
606
|
-
for (const [path, item] of Object.entries(
|
|
608
|
+
for (const [path, item] of Object.entries(document3.paths)) {
|
|
607
609
|
for (const method of HTTP_METHODS) {
|
|
608
610
|
const operation = item[method];
|
|
609
611
|
if (operation?.operationId === void 0)
|
|
610
612
|
continue;
|
|
611
613
|
const responses = {};
|
|
612
614
|
for (const [status, response] of Object.entries(operation.responses)) {
|
|
613
|
-
responses[status] = deref(
|
|
615
|
+
responses[status] = deref(document3, response);
|
|
614
616
|
}
|
|
615
617
|
operations.push({
|
|
616
618
|
operationId: operation.operationId,
|
|
617
619
|
method,
|
|
618
620
|
path,
|
|
619
621
|
operation,
|
|
620
|
-
parameters: mergeParameters(
|
|
621
|
-
requestBody: operation.requestBody === void 0 ? void 0 : deref(
|
|
622
|
+
parameters: mergeParameters(document3, item, operation.parameters),
|
|
623
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
|
|
622
624
|
responses
|
|
623
625
|
});
|
|
624
626
|
}
|
|
@@ -627,7 +629,7 @@ var listOperations = (document2) => {
|
|
|
627
629
|
};
|
|
628
630
|
|
|
629
631
|
// ../../openapi/core/dist/schema.js
|
|
630
|
-
var resolveSchema = (
|
|
632
|
+
var resolveSchema = (document3, schema) => {
|
|
631
633
|
let current = schema;
|
|
632
634
|
const seen = /* @__PURE__ */ new Set();
|
|
633
635
|
while (typeof current.$ref === "string") {
|
|
@@ -636,7 +638,7 @@ var resolveSchema = (document2, schema) => {
|
|
|
636
638
|
break;
|
|
637
639
|
seen.add(ref);
|
|
638
640
|
const { $ref: _ignored, ...siblings } = current;
|
|
639
|
-
const target = resolveRef(
|
|
641
|
+
const target = resolveRef(document3, ref);
|
|
640
642
|
current = { ...target, ...siblings };
|
|
641
643
|
}
|
|
642
644
|
if (current.nullable === true) {
|
|
@@ -707,71 +709,71 @@ var FORMAT_PATTERNS = {
|
|
|
707
709
|
ipv4: /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/
|
|
708
710
|
};
|
|
709
711
|
var graphemeLength = (value) => [...value].length;
|
|
710
|
-
var validateValue = (
|
|
712
|
+
var validateValue = (document3, schema, value, path = []) => {
|
|
711
713
|
const errors = [];
|
|
712
|
-
const s = resolveSchema(
|
|
713
|
-
const
|
|
714
|
+
const s = resolveSchema(document3, schema);
|
|
715
|
+
const fail2 = (message) => errors.push({ path, message });
|
|
714
716
|
const actual = jsonTypeOf(value);
|
|
715
717
|
if (actual === "undefined") {
|
|
716
|
-
|
|
718
|
+
fail2("value is undefined");
|
|
717
719
|
return errors;
|
|
718
720
|
}
|
|
719
721
|
const types = schemaTypes(s);
|
|
720
722
|
if (types.length > 0) {
|
|
721
723
|
const ok = types.some((t) => t === actual || t === "number" && actual === "integer");
|
|
722
724
|
if (!ok) {
|
|
723
|
-
|
|
725
|
+
fail2(`expected type ${types.join("|")}, got ${actual}`);
|
|
724
726
|
return errors;
|
|
725
727
|
}
|
|
726
728
|
}
|
|
727
729
|
if (s.enum && !(value === null && types.includes("null")) && !s.enum.some((candidate) => deepEqual(candidate, value))) {
|
|
728
|
-
|
|
730
|
+
fail2("value not in enum");
|
|
729
731
|
}
|
|
730
732
|
if (s.const !== void 0 && !deepEqual(s.const, value))
|
|
731
|
-
|
|
733
|
+
fail2("value does not equal const");
|
|
732
734
|
if (typeof value === "string") {
|
|
733
735
|
const length = graphemeLength(value);
|
|
734
736
|
if (s.minLength !== void 0 && length < s.minLength)
|
|
735
|
-
|
|
737
|
+
fail2(`length ${length} < minLength ${s.minLength}`);
|
|
736
738
|
if (s.maxLength !== void 0 && length > s.maxLength)
|
|
737
|
-
|
|
739
|
+
fail2(`length ${length} > maxLength ${s.maxLength}`);
|
|
738
740
|
if (s.pattern !== void 0) {
|
|
739
741
|
try {
|
|
740
742
|
if (!new RegExp(s.pattern, "u").test(value))
|
|
741
|
-
|
|
743
|
+
fail2(`does not match pattern ${s.pattern}`);
|
|
742
744
|
} catch {
|
|
743
745
|
}
|
|
744
746
|
}
|
|
745
747
|
if (s.format !== void 0) {
|
|
746
748
|
const pattern = FORMAT_PATTERNS[s.format];
|
|
747
749
|
if (pattern && !pattern.test(value))
|
|
748
|
-
|
|
750
|
+
fail2(`does not match format ${s.format}`);
|
|
749
751
|
}
|
|
750
752
|
}
|
|
751
753
|
if (typeof value === "number") {
|
|
752
754
|
if (s.minimum !== void 0 && value < s.minimum)
|
|
753
|
-
|
|
755
|
+
fail2(`${value} < minimum ${s.minimum}`);
|
|
754
756
|
if (s.maximum !== void 0 && value > s.maximum)
|
|
755
|
-
|
|
757
|
+
fail2(`${value} > maximum ${s.maximum}`);
|
|
756
758
|
if (s.exclusiveMinimum !== void 0 && value <= s.exclusiveMinimum)
|
|
757
|
-
|
|
759
|
+
fail2(`${value} <= exclusiveMinimum ${s.exclusiveMinimum}`);
|
|
758
760
|
if (s.exclusiveMaximum !== void 0 && value >= s.exclusiveMaximum)
|
|
759
|
-
|
|
761
|
+
fail2(`${value} >= exclusiveMaximum ${s.exclusiveMaximum}`);
|
|
760
762
|
if (s.multipleOf !== void 0 && Math.abs(value / s.multipleOf - Math.round(value / s.multipleOf)) > 1e-9) {
|
|
761
|
-
|
|
763
|
+
fail2(`${value} is not a multiple of ${s.multipleOf}`);
|
|
762
764
|
}
|
|
763
765
|
}
|
|
764
766
|
if (Array.isArray(value)) {
|
|
765
767
|
if (s.minItems !== void 0 && value.length < s.minItems)
|
|
766
|
-
|
|
768
|
+
fail2(`${value.length} items < minItems ${s.minItems}`);
|
|
767
769
|
if (s.maxItems !== void 0 && value.length > s.maxItems)
|
|
768
|
-
|
|
770
|
+
fail2(`${value.length} items > maxItems ${s.maxItems}`);
|
|
769
771
|
if (s.uniqueItems && value.some((item, i) => value.slice(0, i).some((prev) => deepEqual(prev, item))))
|
|
770
|
-
|
|
772
|
+
fail2("items are not unique");
|
|
771
773
|
value.forEach((item, i) => {
|
|
772
774
|
const itemSchema = s.prefixItems?.[i] ?? s.items;
|
|
773
775
|
if (itemSchema)
|
|
774
|
-
errors.push(...validateValue(
|
|
776
|
+
errors.push(...validateValue(document3, itemSchema, item, [...path, i]));
|
|
775
777
|
});
|
|
776
778
|
}
|
|
777
779
|
if (actual === "object") {
|
|
@@ -779,41 +781,41 @@ var validateValue = (document2, schema, value, path = []) => {
|
|
|
779
781
|
const keys = Object.keys(record2);
|
|
780
782
|
for (const name of s.required ?? [])
|
|
781
783
|
if (!(name in record2))
|
|
782
|
-
|
|
784
|
+
fail2(`missing required property ${name}`);
|
|
783
785
|
if (s.minProperties !== void 0 && keys.length < s.minProperties)
|
|
784
|
-
|
|
786
|
+
fail2(`${keys.length} properties < minProperties ${s.minProperties}`);
|
|
785
787
|
if (s.maxProperties !== void 0 && keys.length > s.maxProperties)
|
|
786
|
-
|
|
788
|
+
fail2(`${keys.length} properties > maxProperties ${s.maxProperties}`);
|
|
787
789
|
for (const key of keys) {
|
|
788
790
|
const property = s.properties?.[key];
|
|
789
791
|
if (property) {
|
|
790
|
-
errors.push(...validateValue(
|
|
792
|
+
errors.push(...validateValue(document3, property, record2[key], [...path, key]));
|
|
791
793
|
continue;
|
|
792
794
|
}
|
|
793
795
|
if (s.additionalProperties === false)
|
|
794
|
-
|
|
796
|
+
fail2(`unexpected property ${key}`);
|
|
795
797
|
else if (typeof s.additionalProperties === "object") {
|
|
796
|
-
errors.push(...validateValue(
|
|
798
|
+
errors.push(...validateValue(document3, s.additionalProperties, record2[key], [...path, key]));
|
|
797
799
|
}
|
|
798
800
|
if (s.propertyNames) {
|
|
799
|
-
const nameErrors = validateValue(
|
|
801
|
+
const nameErrors = validateValue(document3, s.propertyNames, key, [...path, key]);
|
|
800
802
|
if (nameErrors.length > 0)
|
|
801
|
-
|
|
803
|
+
fail2(`property name ${key} is invalid: ${nameErrors[0]?.message}`);
|
|
802
804
|
}
|
|
803
805
|
}
|
|
804
806
|
}
|
|
805
807
|
if (s.allOf)
|
|
806
808
|
for (const branch of s.allOf)
|
|
807
|
-
errors.push(...validateValue(
|
|
808
|
-
if (s.anyOf && !s.anyOf.some((branch) => validateValue(
|
|
809
|
-
|
|
809
|
+
errors.push(...validateValue(document3, branch, value, path));
|
|
810
|
+
if (s.anyOf && !s.anyOf.some((branch) => validateValue(document3, branch, value).length === 0))
|
|
811
|
+
fail2("matches no anyOf branch");
|
|
810
812
|
if (s.oneOf) {
|
|
811
|
-
const matches2 = s.oneOf.filter((branch) => validateValue(
|
|
813
|
+
const matches2 = s.oneOf.filter((branch) => validateValue(document3, branch, value).length === 0).length;
|
|
812
814
|
if (matches2 !== 1)
|
|
813
|
-
|
|
815
|
+
fail2(`matches ${matches2} oneOf branches, expected exactly 1`);
|
|
814
816
|
}
|
|
815
|
-
if (s.not && validateValue(
|
|
816
|
-
|
|
817
|
+
if (s.not && validateValue(document3, s.not, value).length === 0)
|
|
818
|
+
fail2("matches forbidden `not` schema");
|
|
817
819
|
return errors;
|
|
818
820
|
};
|
|
819
821
|
|
|
@@ -1326,6 +1328,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1326
1328
|
});
|
|
1327
1329
|
};
|
|
1328
1330
|
|
|
1331
|
+
// ../../ui/dist/reset.js
|
|
1332
|
+
var CSS_RESET = `*,
|
|
1333
|
+
*::before,
|
|
1334
|
+
*::after {
|
|
1335
|
+
box-sizing: border-box;
|
|
1336
|
+
margin: 0;
|
|
1337
|
+
padding: 0;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
* {
|
|
1341
|
+
scrollbar-width: thin;
|
|
1342
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
*::-webkit-scrollbar {
|
|
1346
|
+
width: 12px;
|
|
1347
|
+
height: 12px;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
*::-webkit-scrollbar-track,
|
|
1351
|
+
*::-webkit-scrollbar-corner {
|
|
1352
|
+
background: Canvas;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
*::-webkit-scrollbar-thumb {
|
|
1356
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1357
|
+
border: 3px solid Canvas;
|
|
1358
|
+
border-radius: 999px;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
html {
|
|
1362
|
+
hanging-punctuation: first allow-end last;
|
|
1363
|
+
-webkit-text-size-adjust: none;
|
|
1364
|
+
text-size-adjust: none;
|
|
1365
|
+
tab-size: 4;
|
|
1366
|
+
font-family:
|
|
1367
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1368
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1369
|
+
font-size: 16px;
|
|
1370
|
+
line-height: 1.5;
|
|
1371
|
+
-webkit-font-smoothing: antialiased;
|
|
1372
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1373
|
+
text-rendering: optimizeLegibility;
|
|
1374
|
+
-webkit-tap-highlight-color: transparent;
|
|
1375
|
+
scroll-behavior: smooth;
|
|
1376
|
+
background: Canvas;
|
|
1377
|
+
color: CanvasText;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
body {
|
|
1381
|
+
min-height: 100svh;
|
|
1382
|
+
line-height: 1.5;
|
|
1383
|
+
background: Canvas;
|
|
1384
|
+
color: CanvasText;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
h1 {
|
|
1388
|
+
font-size: 2em;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
h2 {
|
|
1392
|
+
font-size: 1.5em;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
h3 {
|
|
1396
|
+
font-size: 1.17em;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
h4 {
|
|
1400
|
+
font-size: 1em;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
h5 {
|
|
1404
|
+
font-size: 0.83em;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
h6 {
|
|
1408
|
+
font-size: 0.67em;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
h1,
|
|
1412
|
+
h2,
|
|
1413
|
+
h3,
|
|
1414
|
+
h4,
|
|
1415
|
+
h5,
|
|
1416
|
+
h6 {
|
|
1417
|
+
font-weight: 700;
|
|
1418
|
+
line-height: 1.2;
|
|
1419
|
+
text-wrap: balance;
|
|
1420
|
+
overflow-wrap: break-word;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
p,
|
|
1424
|
+
li,
|
|
1425
|
+
figcaption,
|
|
1426
|
+
dd,
|
|
1427
|
+
dt,
|
|
1428
|
+
blockquote {
|
|
1429
|
+
overflow-wrap: break-word;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
p,
|
|
1433
|
+
li,
|
|
1434
|
+
figcaption,
|
|
1435
|
+
blockquote {
|
|
1436
|
+
text-wrap: pretty;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
ul,
|
|
1440
|
+
ol,
|
|
1441
|
+
menu {
|
|
1442
|
+
list-style: none;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
a {
|
|
1446
|
+
color: inherit;
|
|
1447
|
+
text-decoration: underline;
|
|
1448
|
+
text-decoration-thickness: 1px;
|
|
1449
|
+
text-underline-offset: 0.15em;
|
|
1450
|
+
text-decoration-skip-ink: auto;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
b,
|
|
1454
|
+
strong {
|
|
1455
|
+
font-weight: 700;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
small {
|
|
1459
|
+
font-size: 0.875em;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
code,
|
|
1463
|
+
kbd,
|
|
1464
|
+
samp,
|
|
1465
|
+
pre {
|
|
1466
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1467
|
+
font-size: 1em;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
sub,
|
|
1471
|
+
sup {
|
|
1472
|
+
font-size: 75%;
|
|
1473
|
+
line-height: 0;
|
|
1474
|
+
position: relative;
|
|
1475
|
+
vertical-align: baseline;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
sub {
|
|
1479
|
+
bottom: -0.25em;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
sup {
|
|
1483
|
+
top: -0.5em;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
abbr[title] {
|
|
1487
|
+
text-decoration: underline dotted;
|
|
1488
|
+
text-underline-offset: 0.15em;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
mark {
|
|
1492
|
+
background: Mark;
|
|
1493
|
+
color: MarkText;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
hr {
|
|
1497
|
+
height: 0;
|
|
1498
|
+
border: 0;
|
|
1499
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1500
|
+
color: inherit;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
img,
|
|
1504
|
+
picture,
|
|
1505
|
+
video,
|
|
1506
|
+
canvas {
|
|
1507
|
+
display: block;
|
|
1508
|
+
max-width: 100%;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
img,
|
|
1512
|
+
video {
|
|
1513
|
+
height: auto;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
svg {
|
|
1517
|
+
overflow: hidden;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
iframe {
|
|
1521
|
+
border: 0;
|
|
1522
|
+
max-width: 100%;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
table {
|
|
1526
|
+
border-collapse: collapse;
|
|
1527
|
+
border-spacing: 0;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
fieldset {
|
|
1531
|
+
border: 0;
|
|
1532
|
+
min-inline-size: 0;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
legend {
|
|
1536
|
+
padding: 0;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
button,
|
|
1540
|
+
input,
|
|
1541
|
+
select,
|
|
1542
|
+
textarea,
|
|
1543
|
+
optgroup {
|
|
1544
|
+
font: inherit;
|
|
1545
|
+
letter-spacing: inherit;
|
|
1546
|
+
color: inherit;
|
|
1547
|
+
margin: 0;
|
|
1548
|
+
vertical-align: middle;
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
button,
|
|
1552
|
+
input[type="button"],
|
|
1553
|
+
input[type="submit"],
|
|
1554
|
+
input[type="reset"] {
|
|
1555
|
+
appearance: none;
|
|
1556
|
+
background: none;
|
|
1557
|
+
border: 0;
|
|
1558
|
+
padding: 0;
|
|
1559
|
+
cursor: pointer;
|
|
1560
|
+
text-align: center;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
input,
|
|
1564
|
+
textarea,
|
|
1565
|
+
select {
|
|
1566
|
+
background-color: Canvas;
|
|
1567
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1568
|
+
border-radius: 0;
|
|
1569
|
+
padding: 0.5em 0.65em;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
input[type="checkbox"],
|
|
1573
|
+
input[type="radio"],
|
|
1574
|
+
input[type="range"],
|
|
1575
|
+
input[type="file"],
|
|
1576
|
+
input[type="color"],
|
|
1577
|
+
input[type="button"],
|
|
1578
|
+
input[type="submit"],
|
|
1579
|
+
input[type="reset"],
|
|
1580
|
+
input[type="image"],
|
|
1581
|
+
input[type="hidden"] {
|
|
1582
|
+
background: none;
|
|
1583
|
+
border: 0;
|
|
1584
|
+
padding: 0;
|
|
1585
|
+
border-radius: 0;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
input[type="checkbox"],
|
|
1589
|
+
input[type="radio"] {
|
|
1590
|
+
accent-color: CanvasText;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
input[type="search"] {
|
|
1594
|
+
appearance: none;
|
|
1595
|
+
background-color: Canvas;
|
|
1596
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1600
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1601
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1602
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1603
|
+
-webkit-appearance: none;
|
|
1604
|
+
display: none;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
input[type="number"] {
|
|
1608
|
+
appearance: textfield;
|
|
1609
|
+
background-color: Canvas;
|
|
1610
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1614
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1615
|
+
-webkit-appearance: none;
|
|
1616
|
+
margin: 0;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
textarea {
|
|
1620
|
+
resize: vertical;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
::placeholder {
|
|
1624
|
+
opacity: 1;
|
|
1625
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
:focus-visible {
|
|
1629
|
+
outline: 2px solid CanvasText;
|
|
1630
|
+
outline-offset: 2px;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
:focus:not(:focus-visible) {
|
|
1634
|
+
outline: none;
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
:disabled,
|
|
1638
|
+
[disabled] {
|
|
1639
|
+
cursor: default;
|
|
1640
|
+
opacity: 0.6;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
label,
|
|
1644
|
+
summary,
|
|
1645
|
+
select,
|
|
1646
|
+
[role="button"] {
|
|
1647
|
+
cursor: pointer;
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
summary {
|
|
1651
|
+
display: list-item;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
details {
|
|
1655
|
+
display: block;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
dialog {
|
|
1659
|
+
margin: auto;
|
|
1660
|
+
padding: 1rem;
|
|
1661
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1662
|
+
background: Canvas;
|
|
1663
|
+
color: CanvasText;
|
|
1664
|
+
max-width: calc(100vw - 2rem);
|
|
1665
|
+
max-height: calc(100svh - 2rem);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
dialog:not([open]) {
|
|
1669
|
+
display: none;
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
::backdrop {
|
|
1673
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
[hidden] {
|
|
1677
|
+
display: none !important;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
::selection {
|
|
1681
|
+
background: Highlight;
|
|
1682
|
+
color: HighlightText;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1686
|
+
*,
|
|
1687
|
+
*::before,
|
|
1688
|
+
*::after {
|
|
1689
|
+
animation-duration: 0.01ms !important;
|
|
1690
|
+
animation-iteration-count: 1 !important;
|
|
1691
|
+
transition-duration: 0.01ms !important;
|
|
1692
|
+
scroll-behavior: auto !important;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
@media (pointer: coarse) {
|
|
1697
|
+
input,
|
|
1698
|
+
select,
|
|
1699
|
+
textarea {
|
|
1700
|
+
font-size: max(16px, 1em);
|
|
1701
|
+
}
|
|
1702
|
+
}`;
|
|
1703
|
+
|
|
1704
|
+
// ../core/dist/admin-client.js
|
|
1705
|
+
function isRecord2(value) {
|
|
1706
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1707
|
+
}
|
|
1708
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1709
|
+
const clip = (value, max) => {
|
|
1710
|
+
if (typeof value !== "string")
|
|
1711
|
+
return null;
|
|
1712
|
+
const trimmed = value.trim();
|
|
1713
|
+
if (trimmed === "")
|
|
1714
|
+
return null;
|
|
1715
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1716
|
+
};
|
|
1717
|
+
const httpUrl = (value) => {
|
|
1718
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1719
|
+
return null;
|
|
1720
|
+
try {
|
|
1721
|
+
const url = new URL(value);
|
|
1722
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1723
|
+
return null;
|
|
1724
|
+
return url.href;
|
|
1725
|
+
} catch {
|
|
1726
|
+
return null;
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
const hexColor = (value) => {
|
|
1730
|
+
if (typeof value !== "string")
|
|
1731
|
+
return null;
|
|
1732
|
+
const raw = value.trim();
|
|
1733
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1734
|
+
};
|
|
1735
|
+
const hostname = (value) => {
|
|
1736
|
+
try {
|
|
1737
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1738
|
+
} catch {
|
|
1739
|
+
return value;
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
host.replaceChildren();
|
|
1743
|
+
host.hidden = true;
|
|
1744
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1745
|
+
return;
|
|
1746
|
+
const row = catalog[service];
|
|
1747
|
+
if (!isRecord2(row))
|
|
1748
|
+
return;
|
|
1749
|
+
const vendor = clip(row.vendor, 80);
|
|
1750
|
+
const website = httpUrl(row.website);
|
|
1751
|
+
const guide = httpUrl(row.guide);
|
|
1752
|
+
const docs = httpUrl(row.docs);
|
|
1753
|
+
const logo = httpUrl(row.logo);
|
|
1754
|
+
const color = hexColor(row.color);
|
|
1755
|
+
const description = clip(row.description, 280);
|
|
1756
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1757
|
+
return;
|
|
1758
|
+
const add = (node) => {
|
|
1759
|
+
host.append(node);
|
|
1760
|
+
return node;
|
|
1761
|
+
};
|
|
1762
|
+
if (logo !== null) {
|
|
1763
|
+
const img = doc.createElement("img");
|
|
1764
|
+
img.alt = "";
|
|
1765
|
+
img.src = logo;
|
|
1766
|
+
img.width = 16;
|
|
1767
|
+
img.height = 16;
|
|
1768
|
+
img.decoding = "async";
|
|
1769
|
+
img.referrerPolicy = "no-referrer";
|
|
1770
|
+
if (color !== null)
|
|
1771
|
+
img.style.borderColor = color;
|
|
1772
|
+
add(img);
|
|
1773
|
+
}
|
|
1774
|
+
const name = doc.createElement("span");
|
|
1775
|
+
name.className = "vendor-name";
|
|
1776
|
+
name.textContent = vendor;
|
|
1777
|
+
if (description !== null)
|
|
1778
|
+
name.title = description;
|
|
1779
|
+
add(name);
|
|
1780
|
+
const sep = () => {
|
|
1781
|
+
const node = doc.createElement("span");
|
|
1782
|
+
node.className = "vendor-sep";
|
|
1783
|
+
node.setAttribute("aria-hidden", "true");
|
|
1784
|
+
node.textContent = "\xB7";
|
|
1785
|
+
return node;
|
|
1786
|
+
};
|
|
1787
|
+
const link = (href, label, title) => {
|
|
1788
|
+
const node = doc.createElement("a");
|
|
1789
|
+
node.className = "vendor-link";
|
|
1790
|
+
node.href = href;
|
|
1791
|
+
node.target = "_blank";
|
|
1792
|
+
node.rel = "noopener noreferrer";
|
|
1793
|
+
node.referrerPolicy = "no-referrer";
|
|
1794
|
+
node.textContent = label;
|
|
1795
|
+
node.title = title;
|
|
1796
|
+
return node;
|
|
1797
|
+
};
|
|
1798
|
+
if (website !== null) {
|
|
1799
|
+
add(sep());
|
|
1800
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1801
|
+
}
|
|
1802
|
+
if (guide !== null) {
|
|
1803
|
+
add(sep());
|
|
1804
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1805
|
+
}
|
|
1806
|
+
if (docs !== null) {
|
|
1807
|
+
add(sep());
|
|
1808
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1809
|
+
}
|
|
1810
|
+
host.removeAttribute("hidden");
|
|
1811
|
+
host.hidden = false;
|
|
1812
|
+
}
|
|
1813
|
+
function startAdminBrand(env) {
|
|
1814
|
+
const requested = env.params.get("brands");
|
|
1815
|
+
let brandsUrl = env.brandsUrl;
|
|
1816
|
+
if (requested) {
|
|
1817
|
+
try {
|
|
1818
|
+
const url = new URL(requested, env.location.href);
|
|
1819
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1820
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1821
|
+
brandsUrl = url.href;
|
|
1822
|
+
} catch {
|
|
1823
|
+
brandsUrl = env.brandsUrl;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
const vendorHost = env.$("vendor");
|
|
1827
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1828
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1829
|
+
if (vendorHost === null)
|
|
1830
|
+
return;
|
|
1831
|
+
env.fetch(brandsUrl, {
|
|
1832
|
+
headers: { accept: "application/json" },
|
|
1833
|
+
signal: AbortSignal.timeout(5e3)
|
|
1834
|
+
}).then(async (response) => {
|
|
1835
|
+
if (!response.ok)
|
|
1836
|
+
return null;
|
|
1837
|
+
const catalog = await response.json();
|
|
1838
|
+
return catalog;
|
|
1839
|
+
}).then((catalog) => {
|
|
1840
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1841
|
+
}).catch(() => {
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
function faultPresetList(value) {
|
|
1845
|
+
if (!isRecord2(value))
|
|
1846
|
+
throw new Error("Fault presets response was not an object");
|
|
1847
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1848
|
+
return { presets: [] };
|
|
1849
|
+
}
|
|
1850
|
+
if (!Array.isArray(value.presets))
|
|
1851
|
+
throw new Error("Fault presets response was not a list");
|
|
1852
|
+
return {
|
|
1853
|
+
presets: value.presets.flatMap((item) => {
|
|
1854
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1855
|
+
return [];
|
|
1856
|
+
return [{ name: item.name }];
|
|
1857
|
+
})
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
function bootAdmin(config) {
|
|
1861
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1862
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1863
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1864
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1865
|
+
const readJson2 = (text) => {
|
|
1866
|
+
const value = JSON.parse(text);
|
|
1867
|
+
return value;
|
|
1868
|
+
};
|
|
1869
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1870
|
+
switch (char) {
|
|
1871
|
+
case "&":
|
|
1872
|
+
return "&";
|
|
1873
|
+
case "<":
|
|
1874
|
+
return "<";
|
|
1875
|
+
case ">":
|
|
1876
|
+
return ">";
|
|
1877
|
+
case '"':
|
|
1878
|
+
return """;
|
|
1879
|
+
default:
|
|
1880
|
+
return "'";
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
const el = (id, kind) => {
|
|
1884
|
+
const node = document.getElementById(id);
|
|
1885
|
+
if (!(node instanceof kind))
|
|
1886
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1887
|
+
return node;
|
|
1888
|
+
};
|
|
1889
|
+
const errorMessage = (data, fallback) => {
|
|
1890
|
+
if (!isRecord2(data))
|
|
1891
|
+
return fallback;
|
|
1892
|
+
const error = data.error;
|
|
1893
|
+
if (!isRecord2(error) || typeof error.message !== "string" || error.message === "") {
|
|
1894
|
+
return fallback;
|
|
1895
|
+
}
|
|
1896
|
+
return error.message;
|
|
1897
|
+
};
|
|
1898
|
+
const requireList = (value, label) => {
|
|
1899
|
+
if (value === void 0 || value === null)
|
|
1900
|
+
return [];
|
|
1901
|
+
if (!Array.isArray(value))
|
|
1902
|
+
throw new Error(`${label} was not a list`);
|
|
1903
|
+
return value;
|
|
1904
|
+
};
|
|
1905
|
+
const state = {
|
|
1906
|
+
namespace: "default",
|
|
1907
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1908
|
+
view: "overview",
|
|
1909
|
+
collection: "",
|
|
1910
|
+
shape: null,
|
|
1911
|
+
route: null,
|
|
1912
|
+
editing: null
|
|
1913
|
+
};
|
|
1914
|
+
const standard = new Set(config.standardRoutes);
|
|
1915
|
+
const banner = el("banner", HTMLElement);
|
|
1916
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1917
|
+
keyInput.value = state.key;
|
|
1918
|
+
const params = new URLSearchParams(location.search);
|
|
1919
|
+
const queryKey = params.get("key");
|
|
1920
|
+
if (queryKey) {
|
|
1921
|
+
state.key = queryKey;
|
|
1922
|
+
keyInput.value = state.key;
|
|
1923
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1924
|
+
params.delete("key");
|
|
1925
|
+
const next = params.toString();
|
|
1926
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1927
|
+
}
|
|
1928
|
+
const queryNamespace = params.get("namespace");
|
|
1929
|
+
if (queryNamespace)
|
|
1930
|
+
state.namespace = queryNamespace;
|
|
1931
|
+
const showError = (error) => {
|
|
1932
|
+
banner.textContent = error instanceof Error ? error.message : String(error);
|
|
1933
|
+
banner.classList.add("show");
|
|
1934
|
+
};
|
|
1935
|
+
const clearError = () => {
|
|
1936
|
+
banner.classList.remove("show");
|
|
1937
|
+
};
|
|
1938
|
+
const api = async (method, path, body) => {
|
|
1939
|
+
const headers = { accept: "application/json" };
|
|
1940
|
+
if (state.key !== "")
|
|
1941
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1942
|
+
if (state.namespace !== "")
|
|
1943
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1944
|
+
if (body !== void 0)
|
|
1945
|
+
headers["content-type"] = "application/json";
|
|
1946
|
+
const init = { method, headers };
|
|
1947
|
+
if (body !== void 0)
|
|
1948
|
+
init.body = JSON.stringify(body);
|
|
1949
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1950
|
+
const text = await response.text();
|
|
1951
|
+
let data = null;
|
|
1952
|
+
if (text !== "") {
|
|
1953
|
+
try {
|
|
1954
|
+
data = readJson2(text);
|
|
1955
|
+
} catch {
|
|
1956
|
+
data = { raw: text };
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
if (response.status === 401) {
|
|
1960
|
+
keyInput.focus();
|
|
1961
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1962
|
+
}
|
|
1963
|
+
if (!response.ok) {
|
|
1964
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1965
|
+
}
|
|
1966
|
+
return data;
|
|
1967
|
+
};
|
|
1968
|
+
const originGet = async (path) => {
|
|
1969
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1970
|
+
if (!response.ok)
|
|
1971
|
+
throw new Error(`${response.status} ${path}`);
|
|
1972
|
+
const value = await response.json();
|
|
1973
|
+
return value;
|
|
1974
|
+
};
|
|
1975
|
+
const panelApi = {
|
|
1976
|
+
get: (path) => api("GET", path),
|
|
1977
|
+
send: (method, path, body) => api(method, path, body),
|
|
1978
|
+
namespace: () => state.namespace
|
|
1979
|
+
};
|
|
1980
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1981
|
+
const setTheme = (theme) => {
|
|
1982
|
+
if (theme)
|
|
1983
|
+
document.documentElement.dataset.theme = theme;
|
|
1984
|
+
else
|
|
1985
|
+
delete document.documentElement.dataset.theme;
|
|
1986
|
+
};
|
|
1987
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1988
|
+
if (storedTheme)
|
|
1989
|
+
setTheme(storedTheme);
|
|
1990
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1991
|
+
const current = document.documentElement.dataset.theme;
|
|
1992
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1993
|
+
const next = dark ? "light" : "dark";
|
|
1994
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
1995
|
+
setTheme(next);
|
|
1996
|
+
});
|
|
1997
|
+
const show = (view) => {
|
|
1998
|
+
state.view = view;
|
|
1999
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
2000
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2001
|
+
continue;
|
|
2002
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
2003
|
+
}
|
|
2004
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
2005
|
+
if (!(section instanceof HTMLElement))
|
|
2006
|
+
continue;
|
|
2007
|
+
section.hidden = section.id !== `view-${view}`;
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
2011
|
+
const target = event.target;
|
|
2012
|
+
if (!(target instanceof Element))
|
|
2013
|
+
return;
|
|
2014
|
+
const button = target.closest("button[data-view]");
|
|
2015
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2016
|
+
return;
|
|
2017
|
+
const view = button.dataset.view;
|
|
2018
|
+
if (view === void 0)
|
|
2019
|
+
return;
|
|
2020
|
+
show(view);
|
|
2021
|
+
refresh().catch(showError);
|
|
2022
|
+
});
|
|
2023
|
+
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>`;
|
|
2024
|
+
const table = (columns, rows) => {
|
|
2025
|
+
if (rows.length === 0)
|
|
2026
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
2027
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
2028
|
+
const body = rows.map((row) => {
|
|
2029
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
2030
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
2031
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
2032
|
+
}).join("");
|
|
2033
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
2034
|
+
};
|
|
2035
|
+
const preview = (value) => {
|
|
2036
|
+
const text = JSON.stringify(value) ?? "null";
|
|
2037
|
+
return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
|
|
2038
|
+
};
|
|
2039
|
+
const when = (epoch) => {
|
|
2040
|
+
const date = new Date(epoch);
|
|
2041
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
2042
|
+
};
|
|
2043
|
+
const clockCard = (epoch) => {
|
|
2044
|
+
const date = new Date(epoch);
|
|
2045
|
+
if (Number.isNaN(date.getTime()))
|
|
2046
|
+
return esc(String(epoch));
|
|
2047
|
+
const iso = date.toISOString();
|
|
2048
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
2049
|
+
};
|
|
2050
|
+
const decodeClock = (value) => {
|
|
2051
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
2052
|
+
throw new Error("Clock response was not a clock");
|
|
2053
|
+
}
|
|
2054
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
2055
|
+
};
|
|
2056
|
+
const decodeField = (value) => {
|
|
2057
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
2058
|
+
return void 0;
|
|
2059
|
+
}
|
|
2060
|
+
const field = {
|
|
2061
|
+
name: value.name,
|
|
2062
|
+
kind: value.kind,
|
|
2063
|
+
optional: value.optional === true
|
|
2064
|
+
};
|
|
2065
|
+
if (typeof value.description === "string")
|
|
2066
|
+
field.description = value.description;
|
|
2067
|
+
if (Array.isArray(value.fields)) {
|
|
2068
|
+
field.fields = value.fields.flatMap((item) => {
|
|
2069
|
+
const child = decodeField(item);
|
|
2070
|
+
return child === void 0 ? [] : [child];
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
return field;
|
|
2074
|
+
};
|
|
2075
|
+
const decodeCollection = (value) => {
|
|
2076
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
2077
|
+
return void 0;
|
|
2078
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
2079
|
+
const field = decodeField(item);
|
|
2080
|
+
return field === void 0 ? [] : [field];
|
|
2081
|
+
}) : [];
|
|
2082
|
+
const collection = {
|
|
2083
|
+
name: value.name,
|
|
2084
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
2085
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
2086
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
2087
|
+
fields
|
|
2088
|
+
};
|
|
2089
|
+
if (typeof value.description === "string")
|
|
2090
|
+
collection.description = value.description;
|
|
2091
|
+
return collection;
|
|
2092
|
+
};
|
|
2093
|
+
const decodeState = (value) => {
|
|
2094
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
2095
|
+
throw new Error("State response has no collection list");
|
|
2096
|
+
}
|
|
2097
|
+
return {
|
|
2098
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
2099
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
2100
|
+
collections: value.collections.flatMap((item) => {
|
|
2101
|
+
const collection = decodeCollection(item);
|
|
2102
|
+
return collection === void 0 ? [] : [collection];
|
|
2103
|
+
})
|
|
2104
|
+
};
|
|
2105
|
+
};
|
|
2106
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
2107
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
2108
|
+
return [];
|
|
2109
|
+
return [
|
|
2110
|
+
{
|
|
2111
|
+
id: item.id,
|
|
2112
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
2113
|
+
value: item.value,
|
|
2114
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
2115
|
+
}
|
|
2116
|
+
];
|
|
2117
|
+
});
|
|
2118
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
2119
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
2120
|
+
if (!isRecord2(item))
|
|
2121
|
+
return [];
|
|
2122
|
+
return [
|
|
2123
|
+
{
|
|
2124
|
+
at: textOf(item.at),
|
|
2125
|
+
method: textOf(item.method),
|
|
2126
|
+
path: textOf(item.path),
|
|
2127
|
+
status: textOf(item.status),
|
|
2128
|
+
durationMs: textOf(item.durationMs),
|
|
2129
|
+
operationId: textOf(item.operationId)
|
|
2130
|
+
}
|
|
2131
|
+
];
|
|
2132
|
+
});
|
|
2133
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
2134
|
+
if (!isRecord2(item))
|
|
2135
|
+
return [];
|
|
2136
|
+
return [
|
|
2137
|
+
{
|
|
2138
|
+
id: textOf(item.id),
|
|
2139
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
2140
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
2141
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
2142
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
2143
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
2144
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
2145
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
2146
|
+
}
|
|
2147
|
+
];
|
|
2148
|
+
});
|
|
2149
|
+
const loadNamespaces = async () => {
|
|
2150
|
+
const data = await api("GET", "/namespaces");
|
|
2151
|
+
const select = el("namespace", HTMLSelectElement);
|
|
2152
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
2153
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
2154
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
2155
|
+
if (!names.includes(state.namespace))
|
|
2156
|
+
names.unshift(state.namespace);
|
|
2157
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
2158
|
+
select.value = state.namespace;
|
|
2159
|
+
};
|
|
2160
|
+
const renderOverview = async () => {
|
|
2161
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
2162
|
+
originGet("/health"),
|
|
2163
|
+
api("GET", "/state"),
|
|
2164
|
+
api("GET", "/clock"),
|
|
2165
|
+
api("GET", "/requests?limit=8")
|
|
2166
|
+
]);
|
|
2167
|
+
if (!isRecord2(health))
|
|
2168
|
+
throw new Error("Health response was not an object");
|
|
2169
|
+
const decoded = decodeState(shape);
|
|
2170
|
+
state.shape = decoded;
|
|
2171
|
+
const time = decodeClock(clock);
|
|
2172
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
2173
|
+
{
|
|
2174
|
+
k: "Service",
|
|
2175
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
2176
|
+
},
|
|
2177
|
+
{
|
|
2178
|
+
k: "Status",
|
|
2179
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
2180
|
+
},
|
|
2181
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
2182
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
2183
|
+
{
|
|
2184
|
+
k: "Records",
|
|
2185
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
2186
|
+
},
|
|
2187
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
2188
|
+
]);
|
|
2189
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
2190
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2191
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2192
|
+
{
|
|
2193
|
+
label: "Status",
|
|
2194
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
2195
|
+
},
|
|
2196
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
2197
|
+
], decodeJournal(journal));
|
|
2198
|
+
};
|
|
2199
|
+
const schemaChips = (collection) => {
|
|
2200
|
+
if (collection.fields.length === 0) {
|
|
2201
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
2202
|
+
}
|
|
2203
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
2204
|
+
};
|
|
2205
|
+
const renderState = async () => {
|
|
2206
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
2207
|
+
state.shape = shape;
|
|
2208
|
+
const host = el("collections", HTMLElement);
|
|
2209
|
+
if (shape.collections.length === 0) {
|
|
2210
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
2211
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
2212
|
+
el("records", HTMLElement).innerHTML = "";
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
2216
|
+
const first = shape.collections[0];
|
|
2217
|
+
if (first === void 0)
|
|
2218
|
+
return;
|
|
2219
|
+
state.collection = first.name;
|
|
2220
|
+
}
|
|
2221
|
+
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("");
|
|
2222
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
2223
|
+
if (selected === void 0)
|
|
2224
|
+
return;
|
|
2225
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
2226
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
2227
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
2228
|
+
el("records", HTMLElement).innerHTML = table([
|
|
2229
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
2230
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
2231
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
2232
|
+
], decodeRecords(page));
|
|
2233
|
+
};
|
|
2234
|
+
const renderClock = async () => {
|
|
2235
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2236
|
+
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>`;
|
|
2237
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2238
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2239
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2240
|
+
};
|
|
2241
|
+
const renderFaults = async () => {
|
|
2242
|
+
const [faults, presets] = await Promise.all([
|
|
2243
|
+
api("GET", "/faults"),
|
|
2244
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2245
|
+
]);
|
|
2246
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2247
|
+
const current = select.value;
|
|
2248
|
+
const list = faultPresetList(presets).presets;
|
|
2249
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2250
|
+
select.value = current;
|
|
2251
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2252
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2253
|
+
{
|
|
2254
|
+
label: "Match",
|
|
2255
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2256
|
+
},
|
|
2257
|
+
{
|
|
2258
|
+
label: "Effect",
|
|
2259
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
2260
|
+
}
|
|
2261
|
+
], decodeFaults(faults));
|
|
2262
|
+
};
|
|
2263
|
+
const renderJournal = async () => {
|
|
2264
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2265
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2266
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
2267
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2268
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2269
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2270
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2271
|
+
], decodeJournal(journal));
|
|
2272
|
+
};
|
|
2273
|
+
const renderRoutes = async () => {
|
|
2274
|
+
const data = await api("GET", "/");
|
|
2275
|
+
if (!isRecord2(data))
|
|
2276
|
+
throw new Error("Route list was not an object");
|
|
2277
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2278
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2279
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2280
|
+
const parts = route.split(" ");
|
|
2281
|
+
const method = parts[0] ?? "";
|
|
2282
|
+
const path = parts.slice(1).join(" ");
|
|
2283
|
+
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>`;
|
|
2284
|
+
}).join("");
|
|
2285
|
+
};
|
|
2286
|
+
const renderers = {
|
|
2287
|
+
overview: renderOverview,
|
|
2288
|
+
state: renderState,
|
|
2289
|
+
clock: renderClock,
|
|
2290
|
+
faults: renderFaults,
|
|
2291
|
+
journal: renderJournal,
|
|
2292
|
+
routes: renderRoutes
|
|
2293
|
+
};
|
|
2294
|
+
async function refresh() {
|
|
2295
|
+
clearError();
|
|
2296
|
+
const render = renderers[state.view];
|
|
2297
|
+
if (render)
|
|
2298
|
+
await render();
|
|
2299
|
+
}
|
|
2300
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2301
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2302
|
+
refresh().catch(showError);
|
|
2303
|
+
});
|
|
2304
|
+
keyInput.addEventListener("change", () => {
|
|
2305
|
+
state.key = keyInput.value.trim();
|
|
2306
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2307
|
+
refresh().catch(showError);
|
|
2308
|
+
});
|
|
2309
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2310
|
+
refresh().catch(showError);
|
|
2311
|
+
});
|
|
2312
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2313
|
+
const target = event.target;
|
|
2314
|
+
if (!(target instanceof Element))
|
|
2315
|
+
return;
|
|
2316
|
+
const button = target.closest("[data-collection]");
|
|
2317
|
+
if (!(button instanceof HTMLElement))
|
|
2318
|
+
return;
|
|
2319
|
+
const collection = button.dataset.collection;
|
|
2320
|
+
if (collection === void 0)
|
|
2321
|
+
return;
|
|
2322
|
+
state.collection = collection;
|
|
2323
|
+
renderState().catch(showError);
|
|
2324
|
+
});
|
|
2325
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2326
|
+
const target = event.target;
|
|
2327
|
+
if (!(target instanceof Element))
|
|
2328
|
+
return;
|
|
2329
|
+
const row = target.closest("[data-id]");
|
|
2330
|
+
if (!(row instanceof HTMLElement))
|
|
2331
|
+
return;
|
|
2332
|
+
const id = row.dataset.id;
|
|
2333
|
+
if (id === void 0)
|
|
2334
|
+
return;
|
|
2335
|
+
openEditor(id).catch(showError);
|
|
2336
|
+
});
|
|
2337
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2338
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2339
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2340
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2341
|
+
async function openEditor(id) {
|
|
2342
|
+
state.editing = id;
|
|
2343
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2344
|
+
editorId.value = id ?? "";
|
|
2345
|
+
editorId.readOnly = id !== null;
|
|
2346
|
+
editorDelete.hidden = id === null;
|
|
2347
|
+
if (id) {
|
|
2348
|
+
const record2 = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2349
|
+
if (!isRecord2(record2))
|
|
2350
|
+
throw new Error("Record response was not an object");
|
|
2351
|
+
editorValue.value = JSON.stringify(record2.value, null, 2) ?? "";
|
|
2352
|
+
} else {
|
|
2353
|
+
editorValue.value = "{\n \n}";
|
|
2354
|
+
}
|
|
2355
|
+
editor.showModal();
|
|
2356
|
+
}
|
|
2357
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2358
|
+
openEditor(null).catch(showError);
|
|
2359
|
+
});
|
|
2360
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2361
|
+
const submitter = event.submitter;
|
|
2362
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2363
|
+
return;
|
|
2364
|
+
event.preventDefault();
|
|
2365
|
+
let value;
|
|
2366
|
+
try {
|
|
2367
|
+
value = readJson2(editorValue.value);
|
|
2368
|
+
} catch {
|
|
2369
|
+
showError(new Error("Value is not JSON"));
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
const id = editorId.value.trim();
|
|
2373
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2374
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2375
|
+
request.then(() => {
|
|
2376
|
+
editor.close();
|
|
2377
|
+
return renderState();
|
|
2378
|
+
}).catch(showError);
|
|
2379
|
+
});
|
|
2380
|
+
editorDelete.addEventListener("click", () => {
|
|
2381
|
+
const id = state.editing;
|
|
2382
|
+
if (!id)
|
|
2383
|
+
return;
|
|
2384
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2385
|
+
editor.close();
|
|
2386
|
+
return renderState();
|
|
2387
|
+
}).catch(showError);
|
|
2388
|
+
});
|
|
2389
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2390
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2391
|
+
continue;
|
|
2392
|
+
button.addEventListener("click", () => {
|
|
2393
|
+
const raw = button.dataset.advance;
|
|
2394
|
+
if (raw === void 0)
|
|
2395
|
+
return;
|
|
2396
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2400
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2401
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2402
|
+
});
|
|
2403
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2404
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2405
|
+
});
|
|
2406
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2407
|
+
event.preventDefault();
|
|
2408
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2409
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2410
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2411
|
+
});
|
|
2412
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2413
|
+
event.preventDefault();
|
|
2414
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2415
|
+
if (preset !== "") {
|
|
2416
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2420
|
+
if (!Number.isFinite(status)) {
|
|
2421
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2425
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2426
|
+
api("POST", "/faults", {
|
|
2427
|
+
status,
|
|
2428
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2429
|
+
...method !== "" ? { method } : {}
|
|
2430
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2431
|
+
});
|
|
2432
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2433
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2434
|
+
});
|
|
2435
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2436
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2437
|
+
});
|
|
2438
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2439
|
+
const target = event.target;
|
|
2440
|
+
if (!(target instanceof Element))
|
|
2441
|
+
return;
|
|
2442
|
+
const button = target.closest("[data-route]");
|
|
2443
|
+
if (!(button instanceof HTMLElement))
|
|
2444
|
+
return;
|
|
2445
|
+
const route = button.dataset.route;
|
|
2446
|
+
if (route === void 0)
|
|
2447
|
+
return;
|
|
2448
|
+
state.route = route;
|
|
2449
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2450
|
+
const method = route.split(" ")[0] ?? "";
|
|
2451
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2452
|
+
});
|
|
2453
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2454
|
+
event.preventDefault();
|
|
2455
|
+
const send = async () => {
|
|
2456
|
+
if (state.route === null)
|
|
2457
|
+
throw new Error("Choose a route first");
|
|
2458
|
+
const parts = state.route.split(" ");
|
|
2459
|
+
const method = parts[0];
|
|
2460
|
+
const path = parts.slice(1).join(" ");
|
|
2461
|
+
if (method === void 0)
|
|
2462
|
+
throw new Error("Choose a route first");
|
|
2463
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2464
|
+
let body;
|
|
2465
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2466
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2467
|
+
try {
|
|
2468
|
+
body = readJson2(routeBody.value);
|
|
2469
|
+
} catch {
|
|
2470
|
+
throw new Error("Body is not JSON");
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
const data = await api(method, concrete, body);
|
|
2474
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2475
|
+
};
|
|
2476
|
+
send().catch(showError);
|
|
2477
|
+
});
|
|
2478
|
+
const decodePanel = (value) => {
|
|
2479
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2480
|
+
return void 0;
|
|
2481
|
+
}
|
|
2482
|
+
const panel = {
|
|
2483
|
+
id: value.id,
|
|
2484
|
+
title: value.title,
|
|
2485
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2486
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2487
|
+
};
|
|
2488
|
+
if (typeof value.script === "string")
|
|
2489
|
+
panel.script = value.script;
|
|
2490
|
+
return panel;
|
|
2491
|
+
};
|
|
2492
|
+
const mountPanels = (panels) => {
|
|
2493
|
+
const nav = el("nav", HTMLElement);
|
|
2494
|
+
const views = el("views", HTMLElement);
|
|
2495
|
+
for (const panel of panels) {
|
|
2496
|
+
const button = document.createElement("button");
|
|
2497
|
+
button.type = "button";
|
|
2498
|
+
button.dataset.view = panel.id;
|
|
2499
|
+
button.textContent = panel.title;
|
|
2500
|
+
nav.append(button);
|
|
2501
|
+
const section = document.createElement("section");
|
|
2502
|
+
section.className = "view";
|
|
2503
|
+
section.id = `view-${panel.id}`;
|
|
2504
|
+
section.hidden = true;
|
|
2505
|
+
const title = document.createElement("h2");
|
|
2506
|
+
title.textContent = panel.title;
|
|
2507
|
+
const lede = document.createElement("p");
|
|
2508
|
+
lede.className = "lede";
|
|
2509
|
+
lede.textContent = panel.description;
|
|
2510
|
+
const body = document.createElement("div");
|
|
2511
|
+
body.className = "panel-body";
|
|
2512
|
+
body.id = `panel-${panel.id}`;
|
|
2513
|
+
body.innerHTML = panel.html;
|
|
2514
|
+
section.append(title, lede, body);
|
|
2515
|
+
views.append(section);
|
|
2516
|
+
if (panel.script === void 0)
|
|
2517
|
+
continue;
|
|
2518
|
+
try {
|
|
2519
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2520
|
+
if (!isPanelScript(compiled))
|
|
2521
|
+
throw new Error("panel script did not compile");
|
|
2522
|
+
compiled(body, panelApi);
|
|
2523
|
+
} catch (error) {
|
|
2524
|
+
const note = document.createElement("p");
|
|
2525
|
+
note.className = "banner show";
|
|
2526
|
+
note.textContent = error instanceof Error ? error.message : String(error);
|
|
2527
|
+
body.append(note);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
startAdminBrand({
|
|
2532
|
+
document,
|
|
2533
|
+
$: (id) => document.getElementById(id),
|
|
2534
|
+
params,
|
|
2535
|
+
location: { href: location.href, origin: location.origin },
|
|
2536
|
+
fetch,
|
|
2537
|
+
brandsUrl: config.brandsUrl
|
|
2538
|
+
});
|
|
2539
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2540
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2541
|
+
const decoded = decodePanel(panel);
|
|
2542
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2543
|
+
});
|
|
2544
|
+
mountPanels(panels);
|
|
2545
|
+
return refresh();
|
|
2546
|
+
}).catch(showError);
|
|
2547
|
+
}
|
|
2548
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2549
|
+
var adminClientSource = (config) => {
|
|
2550
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2551
|
+
return `<script>
|
|
2552
|
+
${clientPrelude}
|
|
2553
|
+
bootAdmin(${payload});
|
|
2554
|
+
</script>`;
|
|
2555
|
+
};
|
|
2556
|
+
|
|
2557
|
+
// ../core/dist/surface.js
|
|
2558
|
+
var defineMock = (runtime) => runtime;
|
|
2559
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2560
|
+
"GET /",
|
|
2561
|
+
"POST /reset",
|
|
2562
|
+
"GET /namespaces",
|
|
2563
|
+
"GET /clock",
|
|
2564
|
+
"POST /clock",
|
|
2565
|
+
"GET /faults",
|
|
2566
|
+
"POST /faults",
|
|
2567
|
+
"DELETE /faults",
|
|
2568
|
+
"POST /snapshots",
|
|
2569
|
+
"POST /snapshots/:id/restore",
|
|
2570
|
+
"DELETE /snapshots/:id",
|
|
2571
|
+
"GET /timeline",
|
|
2572
|
+
"POST /checkpoints",
|
|
2573
|
+
"POST /branches/:name",
|
|
2574
|
+
"POST /branches/:name/checkout",
|
|
2575
|
+
"GET /requests",
|
|
2576
|
+
"DELETE /requests",
|
|
2577
|
+
"GET /metrics",
|
|
2578
|
+
"DELETE /metrics",
|
|
2579
|
+
"GET /credentials",
|
|
2580
|
+
"PUT /credentials",
|
|
2581
|
+
"DELETE /credentials",
|
|
2582
|
+
"GET /state",
|
|
2583
|
+
"GET /state/:collection",
|
|
2584
|
+
"GET /state/:collection/:id",
|
|
2585
|
+
"POST /state/:collection",
|
|
2586
|
+
"PUT /state/:collection/:id",
|
|
2587
|
+
"PATCH /state/:collection/:id",
|
|
2588
|
+
"DELETE /state/:collection/:id",
|
|
2589
|
+
"GET /ui",
|
|
2590
|
+
"GET /ui/",
|
|
2591
|
+
"GET /ui/manifest"
|
|
2592
|
+
];
|
|
2593
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2594
|
+
var assertAdminUi = (ui) => {
|
|
2595
|
+
if (!ui?.panels)
|
|
2596
|
+
return;
|
|
2597
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2598
|
+
for (const panel of ui.panels) {
|
|
2599
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2600
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2601
|
+
}
|
|
2602
|
+
if (seen.has(panel.id))
|
|
2603
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2604
|
+
seen.add(panel.id);
|
|
2605
|
+
if (panel.title.trim() === "")
|
|
2606
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2607
|
+
}
|
|
2608
|
+
};
|
|
2609
|
+
|
|
2610
|
+
// ../core/dist/admin-ui.js
|
|
2611
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2612
|
+
switch (char) {
|
|
2613
|
+
case "&":
|
|
2614
|
+
return "&";
|
|
2615
|
+
case "<":
|
|
2616
|
+
return "<";
|
|
2617
|
+
case ">":
|
|
2618
|
+
return ">";
|
|
2619
|
+
case '"':
|
|
2620
|
+
return """;
|
|
2621
|
+
default:
|
|
2622
|
+
return "'";
|
|
2623
|
+
}
|
|
2624
|
+
});
|
|
2625
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2626
|
+
var renderAdminDocument = (service) => {
|
|
2627
|
+
const name = escapeHtml(service);
|
|
2628
|
+
const script = adminClientSource({
|
|
2629
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2630
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2631
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2632
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2633
|
+
service
|
|
2634
|
+
});
|
|
2635
|
+
return `<!DOCTYPE html>
|
|
2636
|
+
<html lang="en">
|
|
2637
|
+
<head>
|
|
2638
|
+
<meta charset="utf-8">
|
|
2639
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2640
|
+
<meta name="color-scheme" content="light dark">
|
|
2641
|
+
<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">
|
|
2642
|
+
<title>${name} admin</title>
|
|
2643
|
+
<style>
|
|
2644
|
+
${CSS_RESET}
|
|
2645
|
+
:root {
|
|
2646
|
+
color-scheme: light;
|
|
2647
|
+
--bg: #fafafa;
|
|
2648
|
+
--bg-elev: #ffffff;
|
|
2649
|
+
--bg-muted: #f4f4f5;
|
|
2650
|
+
--bg-inset: #f4f4f5;
|
|
2651
|
+
--line: #dedee3;
|
|
2652
|
+
--line-strong: #c4c4cc;
|
|
2653
|
+
--ink: #18181b;
|
|
2654
|
+
--muted: #62626b;
|
|
2655
|
+
--faint: #71717a;
|
|
2656
|
+
--accent: #27272a;
|
|
2657
|
+
--accent-ink: #ffffff;
|
|
2658
|
+
--accent-soft: #f4f4f5;
|
|
2659
|
+
--ok: #166534;
|
|
2660
|
+
--ok-soft: #f0fdf4;
|
|
2661
|
+
--warn: #a16207;
|
|
2662
|
+
--warn-soft: #fefce8;
|
|
2663
|
+
--err: #a82d32;
|
|
2664
|
+
--err-soft: #fef2f2;
|
|
2665
|
+
--shadow: none;
|
|
2666
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2667
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2668
|
+
--radius: 10px;
|
|
2669
|
+
--header: 56px;
|
|
2670
|
+
--nav: 200px;
|
|
2671
|
+
}
|
|
2672
|
+
:root[data-theme="dark"] {
|
|
2673
|
+
color-scheme: dark;
|
|
2674
|
+
--bg: #111113;
|
|
2675
|
+
--bg-elev: #19191c;
|
|
2676
|
+
--bg-muted: #242428;
|
|
2677
|
+
--bg-inset: #111113;
|
|
2678
|
+
--line: #36363c;
|
|
2679
|
+
--line-strong: #52525b;
|
|
2680
|
+
--ink: #f4f4f5;
|
|
2681
|
+
--muted: #a9a9b2;
|
|
2682
|
+
--faint: #71717a;
|
|
2683
|
+
--accent: #e4e4e7;
|
|
2684
|
+
--accent-ink: #18181b;
|
|
2685
|
+
--accent-soft: #242428;
|
|
2686
|
+
--ok: #86efac;
|
|
2687
|
+
--ok-soft: #14241b;
|
|
2688
|
+
--warn: #fde68a;
|
|
2689
|
+
--warn-soft: #2a2410;
|
|
2690
|
+
--err: #ffaaaa;
|
|
2691
|
+
--err-soft: #2c1516;
|
|
2692
|
+
--shadow: none;
|
|
2693
|
+
}
|
|
2694
|
+
@media (prefers-color-scheme: dark) {
|
|
2695
|
+
:root:not([data-theme="light"]) {
|
|
2696
|
+
color-scheme: dark;
|
|
2697
|
+
--bg: #111113;
|
|
2698
|
+
--bg-elev: #19191c;
|
|
2699
|
+
--bg-muted: #242428;
|
|
2700
|
+
--bg-inset: #111113;
|
|
2701
|
+
--line: #36363c;
|
|
2702
|
+
--line-strong: #52525b;
|
|
2703
|
+
--ink: #f4f4f5;
|
|
2704
|
+
--muted: #a9a9b2;
|
|
2705
|
+
--faint: #71717a;
|
|
2706
|
+
--accent: #e4e4e7;
|
|
2707
|
+
--accent-ink: #18181b;
|
|
2708
|
+
--accent-soft: #242428;
|
|
2709
|
+
--ok: #86efac;
|
|
2710
|
+
--ok-soft: #14241b;
|
|
2711
|
+
--warn: #fde68a;
|
|
2712
|
+
--warn-soft: #2a2410;
|
|
2713
|
+
--err: #ffaaaa;
|
|
2714
|
+
--err-soft: #2c1516;
|
|
2715
|
+
--shadow: none;
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2719
|
+
html { height: 100%; }
|
|
2720
|
+
body {
|
|
2721
|
+
margin: 0;
|
|
2722
|
+
min-height: 100%;
|
|
2723
|
+
display: flex;
|
|
2724
|
+
flex-direction: column;
|
|
2725
|
+
font-family: var(--sans);
|
|
2726
|
+
background: var(--bg);
|
|
2727
|
+
color: var(--ink);
|
|
2728
|
+
line-height: 1.45;
|
|
2729
|
+
padding-left: env(safe-area-inset-left);
|
|
2730
|
+
padding-right: env(safe-area-inset-right);
|
|
2731
|
+
-webkit-text-size-adjust: 100%;
|
|
2732
|
+
}
|
|
2733
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2734
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2735
|
+
header.top {
|
|
2736
|
+
position: sticky; top: 0; z-index: 5;
|
|
2737
|
+
display: flex; align-items: center; gap: 12px;
|
|
2738
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2739
|
+
background: var(--bg-elev);
|
|
2740
|
+
border-bottom: 1px solid var(--line);
|
|
2741
|
+
min-width: 0; max-width: 100%;
|
|
2742
|
+
}
|
|
2743
|
+
.brand {
|
|
2744
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2745
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2746
|
+
}
|
|
2747
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2748
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2749
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2750
|
+
.vendor {
|
|
2751
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2752
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2753
|
+
}
|
|
2754
|
+
.vendor[hidden] { display: none; }
|
|
2755
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2756
|
+
.vendor img {
|
|
2757
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2758
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2759
|
+
}
|
|
2760
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2761
|
+
.vendor-sep { color: var(--faint); }
|
|
2762
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2763
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2764
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2765
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2766
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2767
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2768
|
+
padding: 7px 8px; min-height: 36px;
|
|
2769
|
+
}
|
|
2770
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2771
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2772
|
+
background: var(--bg-elev);
|
|
2773
|
+
}
|
|
2774
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2775
|
+
.btn-quiet { background: transparent; }
|
|
2776
|
+
.btn-danger { color: var(--err); }
|
|
2777
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2778
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2779
|
+
.layout {
|
|
2780
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2781
|
+
flex: 1 0 auto; min-width: 0;
|
|
2782
|
+
}
|
|
2783
|
+
nav.side {
|
|
2784
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2785
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2786
|
+
background: var(--bg-elev);
|
|
2787
|
+
}
|
|
2788
|
+
nav.side button {
|
|
2789
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2790
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2791
|
+
}
|
|
2792
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2793
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2794
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2795
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2796
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2797
|
+
.card {
|
|
2798
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2799
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2800
|
+
}
|
|
2801
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2802
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2803
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2804
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2805
|
+
.collection {
|
|
2806
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2807
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2808
|
+
}
|
|
2809
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2810
|
+
.collection small { display: block; color: var(--faint); }
|
|
2811
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2812
|
+
.chip {
|
|
2813
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2814
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2815
|
+
}
|
|
2816
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2817
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2818
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2819
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2820
|
+
tr.clickable { cursor: pointer; }
|
|
2821
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2822
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2823
|
+
pre {
|
|
2824
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2825
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2826
|
+
}
|
|
2827
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2828
|
+
.banner {
|
|
2829
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2830
|
+
background: var(--err-soft); color: var(--err);
|
|
2831
|
+
}
|
|
2832
|
+
.banner.show { display: block; }
|
|
2833
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2834
|
+
dialog {
|
|
2835
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2836
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2837
|
+
}
|
|
2838
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2839
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2840
|
+
textarea {
|
|
2841
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2842
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2843
|
+
font-family: var(--mono); font-size: 12px;
|
|
2844
|
+
}
|
|
2845
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2846
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2847
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2848
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2849
|
+
.status-2 { color: var(--ok); }
|
|
2850
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2851
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2852
|
+
.route {
|
|
2853
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2854
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2855
|
+
}
|
|
2856
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2857
|
+
@media (max-width: 800px) {
|
|
2858
|
+
header.top {
|
|
2859
|
+
align-items: stretch; flex-direction: column;
|
|
2860
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2861
|
+
}
|
|
2862
|
+
input, select, textarea { font-size: 16px; }
|
|
2863
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2864
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2865
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2866
|
+
nav.side {
|
|
2867
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2868
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2869
|
+
padding: 8px;
|
|
2870
|
+
}
|
|
2871
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2872
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2873
|
+
main { padding: 14px; }
|
|
2874
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2875
|
+
thead { display: none; }
|
|
2876
|
+
tr {
|
|
2877
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2878
|
+
background: var(--bg-elev); min-width: 0;
|
|
2879
|
+
}
|
|
2880
|
+
td {
|
|
2881
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2882
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2883
|
+
}
|
|
2884
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2885
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2886
|
+
.route button { grid-column: 1 / -1; }
|
|
2887
|
+
}
|
|
2888
|
+
</style>
|
|
2889
|
+
</head>
|
|
2890
|
+
<body>
|
|
2891
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2892
|
+
<header class="top">
|
|
2893
|
+
<div class="brand">
|
|
2894
|
+
<div class="brand-id">
|
|
2895
|
+
<strong>${name}</strong>
|
|
2896
|
+
<span>Admin</span>
|
|
2897
|
+
</div>
|
|
2898
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2899
|
+
</div>
|
|
2900
|
+
<div class="controls">
|
|
2901
|
+
<label class="field">Namespace
|
|
2902
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2903
|
+
</label>
|
|
2904
|
+
<label class="field">Admin key
|
|
2905
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2906
|
+
</label>
|
|
2907
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2908
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2909
|
+
</div>
|
|
2910
|
+
</header>
|
|
2911
|
+
<div class="layout">
|
|
2912
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2913
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2914
|
+
<button type="button" data-view="state">State</button>
|
|
2915
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2916
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2917
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2918
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2919
|
+
</nav>
|
|
2920
|
+
<main id="views">
|
|
2921
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2922
|
+
<section class="view" id="view-overview">
|
|
2923
|
+
<h2>Overview</h2>
|
|
2924
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2925
|
+
<div class="grid" id="overview-cards"></div>
|
|
2926
|
+
<h3>Recent requests</h3>
|
|
2927
|
+
<div id="overview-requests"></div>
|
|
2928
|
+
</section>
|
|
2929
|
+
<section class="view" id="view-state" hidden>
|
|
2930
|
+
<h2>State</h2>
|
|
2931
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2932
|
+
<div class="split">
|
|
2933
|
+
<div id="collections"></div>
|
|
2934
|
+
<div>
|
|
2935
|
+
<div id="schema"></div>
|
|
2936
|
+
<div class="row-actions">
|
|
2937
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2938
|
+
</div>
|
|
2939
|
+
<div id="records"></div>
|
|
2940
|
+
</div>
|
|
2941
|
+
</div>
|
|
2942
|
+
</section>
|
|
2943
|
+
<section class="view" id="view-clock" hidden>
|
|
2944
|
+
<h2>Clock</h2>
|
|
2945
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
2946
|
+
<div class="card" id="clock-readout"></div>
|
|
2947
|
+
<div class="row-actions">
|
|
2948
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
2949
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
2950
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
2951
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
2952
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
2953
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
2954
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
2955
|
+
</div>
|
|
2956
|
+
<form id="clock-set" class="row-actions">
|
|
2957
|
+
<label class="field">Set instant
|
|
2958
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
2959
|
+
</label>
|
|
2960
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
2961
|
+
</form>
|
|
2962
|
+
</section>
|
|
2963
|
+
<section class="view" id="view-faults" hidden>
|
|
2964
|
+
<h2>Faults</h2>
|
|
2965
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
2966
|
+
<form id="fault-form" class="card stack">
|
|
2967
|
+
<label class="field">Preset
|
|
2968
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
2969
|
+
</label>
|
|
2970
|
+
<label class="field">Status
|
|
2971
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
2972
|
+
</label>
|
|
2973
|
+
<label class="field">Path prefix
|
|
2974
|
+
<input id="fault-path" placeholder="/v1">
|
|
2975
|
+
</label>
|
|
2976
|
+
<label class="field">Method
|
|
2977
|
+
<input id="fault-method" placeholder="GET">
|
|
2978
|
+
</label>
|
|
2979
|
+
<div class="dialog-actions">
|
|
2980
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
2981
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
2982
|
+
</div>
|
|
2983
|
+
</form>
|
|
2984
|
+
<div id="fault-list"></div>
|
|
2985
|
+
</section>
|
|
2986
|
+
<section class="view" id="view-journal" hidden>
|
|
2987
|
+
<h2>Journal</h2>
|
|
2988
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
2989
|
+
<div class="row-actions">
|
|
2990
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
2991
|
+
</div>
|
|
2992
|
+
<div id="journal"></div>
|
|
2993
|
+
</section>
|
|
2994
|
+
<section class="view" id="view-routes" hidden>
|
|
2995
|
+
<h2>Routes</h2>
|
|
2996
|
+
<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>
|
|
2997
|
+
<div id="route-list"></div>
|
|
2998
|
+
<form id="route-form" class="card stack">
|
|
2999
|
+
<strong id="route-title">Select a route</strong>
|
|
3000
|
+
<label class="field">JSON body
|
|
3001
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
3002
|
+
</label>
|
|
3003
|
+
<div class="dialog-actions">
|
|
3004
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
3005
|
+
</div>
|
|
3006
|
+
<pre id="route-result">Response will show here.</pre>
|
|
3007
|
+
</form>
|
|
3008
|
+
</section>
|
|
3009
|
+
</main>
|
|
3010
|
+
</div>
|
|
3011
|
+
</div>
|
|
3012
|
+
<dialog id="editor">
|
|
3013
|
+
<form method="dialog" id="editor-form">
|
|
3014
|
+
<strong id="editor-title">Record</strong>
|
|
3015
|
+
<label class="field">Id
|
|
3016
|
+
<input id="editor-id" required>
|
|
3017
|
+
</label>
|
|
3018
|
+
<label class="field">JSON value
|
|
3019
|
+
<textarea id="editor-value"></textarea>
|
|
3020
|
+
</label>
|
|
3021
|
+
<div class="dialog-actions">
|
|
3022
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
3023
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
3024
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
3025
|
+
</div>
|
|
3026
|
+
</form>
|
|
3027
|
+
</dialog>
|
|
3028
|
+
${script}
|
|
3029
|
+
</body>
|
|
3030
|
+
</html>`;
|
|
3031
|
+
};
|
|
3032
|
+
var htmlResponse = (body) => new Response(body, {
|
|
3033
|
+
status: 200,
|
|
3034
|
+
headers: {
|
|
3035
|
+
"content-type": "text/html; charset=utf-8",
|
|
3036
|
+
"cache-control": "no-store"
|
|
3037
|
+
}
|
|
3038
|
+
});
|
|
3039
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
3040
|
+
status: 200,
|
|
3041
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3042
|
+
});
|
|
3043
|
+
var adminUiRoutes = (service, ui) => {
|
|
3044
|
+
const shell = () => renderAdminDocument(service);
|
|
3045
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
3046
|
+
return {
|
|
3047
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
3048
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
3049
|
+
"GET /ui/manifest": () => json2({
|
|
3050
|
+
service,
|
|
3051
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
3052
|
+
id: panel.id,
|
|
3053
|
+
title: panel.title,
|
|
3054
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
3055
|
+
html: panel.html,
|
|
3056
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
3057
|
+
}))
|
|
3058
|
+
})
|
|
3059
|
+
};
|
|
3060
|
+
};
|
|
3061
|
+
|
|
1329
3062
|
// ../../openapi/metadata/dist/types.js
|
|
1330
3063
|
var EXTENSION_KEYS = {
|
|
1331
3064
|
operation: "x-mockingbird",
|
|
@@ -1338,11 +3071,11 @@ var EXTENSION_KEYS = {
|
|
|
1338
3071
|
};
|
|
1339
3072
|
|
|
1340
3073
|
// ../../openapi/metadata/dist/read.js
|
|
1341
|
-
var
|
|
3074
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1342
3075
|
var extensionOf = (holder, key) => holder[key];
|
|
1343
3076
|
var operationMetadata = (operation) => {
|
|
1344
3077
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
1345
|
-
const ext =
|
|
3078
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
1346
3079
|
const supported = ext.supported ?? true;
|
|
1347
3080
|
const parity = ext.parity ?? {};
|
|
1348
3081
|
return {
|
|
@@ -1452,9 +3185,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
1452
3185
|
this.name = "OperationRegistryError";
|
|
1453
3186
|
}
|
|
1454
3187
|
};
|
|
1455
|
-
var verifyOperations = (
|
|
3188
|
+
var verifyOperations = (document3, handlers) => {
|
|
1456
3189
|
const problems = [];
|
|
1457
|
-
const operations = listOperations(
|
|
3190
|
+
const operations = listOperations(document3);
|
|
1458
3191
|
const seen = /* @__PURE__ */ new Set();
|
|
1459
3192
|
for (const operation of operations) {
|
|
1460
3193
|
if (seen.has(operation.operationId))
|
|
@@ -1563,15 +3296,449 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1563
3296
|
});
|
|
1564
3297
|
};
|
|
1565
3298
|
|
|
3299
|
+
// ../core/dist/state-view.js
|
|
3300
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
3301
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
3302
|
+
var SAMPLE = 25;
|
|
3303
|
+
var WALK_LIMIT = 1e4;
|
|
3304
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3305
|
+
var fail = (status, message) => ({ ok: false, status, message });
|
|
3306
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3307
|
+
var kindOf = (value) => {
|
|
3308
|
+
if (value === null)
|
|
3309
|
+
return "null";
|
|
3310
|
+
if (Array.isArray(value))
|
|
3311
|
+
return "array";
|
|
3312
|
+
switch (typeof value) {
|
|
3313
|
+
case "string":
|
|
3314
|
+
return "string";
|
|
3315
|
+
case "number":
|
|
3316
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3317
|
+
case "boolean":
|
|
3318
|
+
return "boolean";
|
|
3319
|
+
case "object":
|
|
3320
|
+
return "object";
|
|
3321
|
+
default:
|
|
3322
|
+
return "unknown";
|
|
3323
|
+
}
|
|
3324
|
+
};
|
|
3325
|
+
var humanize = (name) => {
|
|
3326
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3327
|
+
if (words === "")
|
|
3328
|
+
return name;
|
|
3329
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3330
|
+
};
|
|
3331
|
+
var jsonValue = (value) => {
|
|
3332
|
+
if (value === void 0)
|
|
3333
|
+
return fail(400, "value is required");
|
|
3334
|
+
try {
|
|
3335
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3336
|
+
} catch {
|
|
3337
|
+
return fail(400, "value must be JSON");
|
|
3338
|
+
}
|
|
3339
|
+
};
|
|
3340
|
+
var ctorName = (value) => {
|
|
3341
|
+
const ctor = value.constructor;
|
|
3342
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3343
|
+
};
|
|
3344
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3345
|
+
var discoverCollections = (root) => {
|
|
3346
|
+
const found = [];
|
|
3347
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3348
|
+
const visit = (value, depth) => {
|
|
3349
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3350
|
+
return;
|
|
3351
|
+
if (value === null || typeof value !== "object")
|
|
3352
|
+
return;
|
|
3353
|
+
if (seen.has(value))
|
|
3354
|
+
return;
|
|
3355
|
+
seen.add(value);
|
|
3356
|
+
if (value instanceof Collection) {
|
|
3357
|
+
found.push(value);
|
|
3358
|
+
return;
|
|
3359
|
+
}
|
|
3360
|
+
if (value instanceof Map) {
|
|
3361
|
+
for (const child of value.values())
|
|
3362
|
+
visit(child, depth + 1);
|
|
3363
|
+
return;
|
|
3364
|
+
}
|
|
3365
|
+
if (value instanceof Set) {
|
|
3366
|
+
for (const child of value.values())
|
|
3367
|
+
visit(child, depth + 1);
|
|
3368
|
+
return;
|
|
3369
|
+
}
|
|
3370
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3371
|
+
return;
|
|
3372
|
+
if (Array.isArray(value)) {
|
|
3373
|
+
const cap = Math.min(value.length, 32);
|
|
3374
|
+
for (let i = 0; i < cap; i++)
|
|
3375
|
+
visit(value[i], depth + 1);
|
|
3376
|
+
return;
|
|
3377
|
+
}
|
|
3378
|
+
let children;
|
|
3379
|
+
try {
|
|
3380
|
+
children = Object.values(value);
|
|
3381
|
+
} catch {
|
|
3382
|
+
return;
|
|
3383
|
+
}
|
|
3384
|
+
for (const child of children)
|
|
3385
|
+
visit(child, depth + 1);
|
|
3386
|
+
};
|
|
3387
|
+
visit(root, 0);
|
|
3388
|
+
return found;
|
|
3389
|
+
};
|
|
3390
|
+
var storedNames = (sqlite, namespace) => {
|
|
3391
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3392
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3393
|
+
return [...records, ...sequences].map((row) => row.name);
|
|
3394
|
+
};
|
|
3395
|
+
var blankAccum = (name) => ({
|
|
3396
|
+
name,
|
|
3397
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3398
|
+
present: 0,
|
|
3399
|
+
nested: /* @__PURE__ */ new Map()
|
|
3400
|
+
});
|
|
3401
|
+
var absorb = (accum, value) => {
|
|
3402
|
+
const kind = kindOf(value);
|
|
3403
|
+
accum.kinds.add(kind);
|
|
3404
|
+
accum.present++;
|
|
3405
|
+
if (!isRecord4(value))
|
|
3406
|
+
return;
|
|
3407
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3408
|
+
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
3409
|
+
absorb(nested, child);
|
|
3410
|
+
accum.nested.set(key, nested);
|
|
3411
|
+
}
|
|
3412
|
+
};
|
|
3413
|
+
var finishField = (accum, samples) => {
|
|
3414
|
+
const kinds = [...accum.kinds];
|
|
3415
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3416
|
+
const field = {
|
|
3417
|
+
name: accum.name,
|
|
3418
|
+
kind,
|
|
3419
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3420
|
+
};
|
|
3421
|
+
if (accum.nested.size > 0) {
|
|
3422
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3423
|
+
}
|
|
3424
|
+
return field;
|
|
3425
|
+
};
|
|
3426
|
+
var inferFields = (records) => {
|
|
3427
|
+
if (records.length === 0)
|
|
3428
|
+
return [];
|
|
3429
|
+
const sample = records.slice(0, SAMPLE);
|
|
3430
|
+
const objects = sample.filter((record2) => isRecord4(record2.value));
|
|
3431
|
+
if (objects.length === 0) {
|
|
3432
|
+
const kinds = new Set(sample.map((record2) => kindOf(record2.value)));
|
|
3433
|
+
const list = [...kinds];
|
|
3434
|
+
return [
|
|
3435
|
+
{
|
|
3436
|
+
name: "(value)",
|
|
3437
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3438
|
+
optional: false
|
|
3439
|
+
}
|
|
3440
|
+
];
|
|
3441
|
+
}
|
|
3442
|
+
const root = /* @__PURE__ */ new Map();
|
|
3443
|
+
for (const record2 of objects) {
|
|
3444
|
+
for (const [key, value] of Object.entries(record2.value)) {
|
|
3445
|
+
const accum = root.get(key) ?? blankAccum(key);
|
|
3446
|
+
absorb(accum, value);
|
|
3447
|
+
root.set(key, accum);
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3451
|
+
};
|
|
3452
|
+
var mergeFields = (declared, inferred) => {
|
|
3453
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3454
|
+
for (const field of inferred)
|
|
3455
|
+
byName.set(field.name, field);
|
|
3456
|
+
const ordered = [];
|
|
3457
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3458
|
+
for (const field of declared ?? []) {
|
|
3459
|
+
const found = byName.get(field.name);
|
|
3460
|
+
seen.add(field.name);
|
|
3461
|
+
if (!found) {
|
|
3462
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3463
|
+
continue;
|
|
3464
|
+
}
|
|
3465
|
+
ordered.push({
|
|
3466
|
+
...found,
|
|
3467
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3468
|
+
optional: field.optional || found.optional,
|
|
3469
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3470
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3471
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
3474
|
+
for (const field of inferred) {
|
|
3475
|
+
if (!seen.has(field.name))
|
|
3476
|
+
ordered.push(field);
|
|
3477
|
+
}
|
|
3478
|
+
return ordered;
|
|
3479
|
+
};
|
|
3480
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3481
|
+
var readRecord = (collection, id) => {
|
|
3482
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3483
|
+
const row = rows.find((entry) => entry.id === id);
|
|
3484
|
+
return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
|
|
3485
|
+
};
|
|
3486
|
+
var inspectState = (scope) => {
|
|
3487
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3488
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3489
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3490
|
+
declared.set(declaration.name, declaration);
|
|
3491
|
+
}
|
|
3492
|
+
const names = new Set(declared.keys());
|
|
3493
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3494
|
+
names.add(name);
|
|
3495
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3496
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3497
|
+
names.add(collection.collectionName);
|
|
3498
|
+
}
|
|
3499
|
+
const collections = [];
|
|
3500
|
+
for (const name of names) {
|
|
3501
|
+
if (!COLLECTION_NAME.test(name))
|
|
3502
|
+
continue;
|
|
3503
|
+
const declaration = declared.get(name);
|
|
3504
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3505
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
|
|
3506
|
+
const inferred = inferFields(records);
|
|
3507
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3508
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3509
|
+
collections.push({
|
|
3510
|
+
name,
|
|
3511
|
+
label: declaration?.label ?? humanize(name),
|
|
3512
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3513
|
+
count: collection.count(),
|
|
3514
|
+
source,
|
|
3515
|
+
fields,
|
|
3516
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3517
|
+
});
|
|
3518
|
+
}
|
|
3519
|
+
const order = /* @__PURE__ */ new Map();
|
|
3520
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3521
|
+
order.set(item.name, index);
|
|
3522
|
+
collections.sort((a, b) => {
|
|
3523
|
+
const left = order.get(a.name);
|
|
3524
|
+
const right = order.get(b.name);
|
|
3525
|
+
if (left !== void 0 && right !== void 0)
|
|
3526
|
+
return left - right;
|
|
3527
|
+
if (left !== void 0)
|
|
3528
|
+
return -1;
|
|
3529
|
+
if (right !== void 0)
|
|
3530
|
+
return 1;
|
|
3531
|
+
return a.name.localeCompare(b.name);
|
|
3532
|
+
});
|
|
3533
|
+
return {
|
|
3534
|
+
namespace: scope.namespace,
|
|
3535
|
+
storageNamespace: scope.storageNamespace,
|
|
3536
|
+
collections
|
|
3537
|
+
};
|
|
3538
|
+
};
|
|
3539
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3540
|
+
if (!COLLECTION_NAME.test(name))
|
|
3541
|
+
return fail(400, "collection name is not allowed");
|
|
3542
|
+
const limit = query.limit ?? 50;
|
|
3543
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3544
|
+
return fail(400, "limit must be an integer from 1 to 200");
|
|
3545
|
+
}
|
|
3546
|
+
const order = query.order ?? "newest";
|
|
3547
|
+
if (order !== "newest" && order !== "oldest")
|
|
3548
|
+
return fail(400, 'order must be "newest" or "oldest"');
|
|
3549
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3550
|
+
const rows = collection.list({ order }).filter((row) => {
|
|
3551
|
+
if (query.after === void 0)
|
|
3552
|
+
return true;
|
|
3553
|
+
return order === "newest" ? row.seq < query.after : row.seq > query.after;
|
|
3554
|
+
});
|
|
3555
|
+
const slice = rows.slice(0, limit);
|
|
3556
|
+
const last = slice.at(-1);
|
|
3557
|
+
return {
|
|
3558
|
+
ok: true,
|
|
3559
|
+
value: {
|
|
3560
|
+
collection: name,
|
|
3561
|
+
count: collection.count(),
|
|
3562
|
+
records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
|
|
3563
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3564
|
+
}
|
|
3565
|
+
};
|
|
3566
|
+
};
|
|
3567
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3568
|
+
var readStateRecord = (scope, name, id) => {
|
|
3569
|
+
if (!COLLECTION_NAME.test(name))
|
|
3570
|
+
return fail(400, "collection name is not allowed");
|
|
3571
|
+
if (!RECORD_ID.test(id))
|
|
3572
|
+
return fail(400, "record id is not allowed");
|
|
3573
|
+
const record2 = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3574
|
+
return record2 ? { ok: true, value: record2 } : fail(404, `no record ${id} in ${name}`);
|
|
3575
|
+
};
|
|
3576
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
|
|
3577
|
+
var createStateRecord = (scope, name, input) => {
|
|
3578
|
+
if (!COLLECTION_NAME.test(name))
|
|
3579
|
+
return fail(400, "collection name is not allowed");
|
|
3580
|
+
const parsed = jsonValue(input.value);
|
|
3581
|
+
if (!parsed.ok)
|
|
3582
|
+
return parsed;
|
|
3583
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3584
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3585
|
+
const checked = requireId(id);
|
|
3586
|
+
if (!checked.ok)
|
|
3587
|
+
return checked;
|
|
3588
|
+
if (collection.has(checked.value))
|
|
3589
|
+
return fail(409, `record ${checked.value} already exists`);
|
|
3590
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3591
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3592
|
+
};
|
|
3593
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3594
|
+
if (!COLLECTION_NAME.test(name))
|
|
3595
|
+
return fail(400, "collection name is not allowed");
|
|
3596
|
+
const checked = requireId(id);
|
|
3597
|
+
if (!checked.ok)
|
|
3598
|
+
return checked;
|
|
3599
|
+
const parsed = jsonValue(value);
|
|
3600
|
+
if (!parsed.ok)
|
|
3601
|
+
return parsed;
|
|
3602
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3603
|
+
if (!collection.has(checked.value))
|
|
3604
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3605
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3606
|
+
if (!stored)
|
|
3607
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3608
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3609
|
+
};
|
|
3610
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3611
|
+
const current = readStateRecord(scope, name, id);
|
|
3612
|
+
if (!current.ok)
|
|
3613
|
+
return current;
|
|
3614
|
+
const parsed = jsonValue(value);
|
|
3615
|
+
if (!parsed.ok)
|
|
3616
|
+
return parsed;
|
|
3617
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3618
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3619
|
+
};
|
|
3620
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3621
|
+
if (!COLLECTION_NAME.test(name))
|
|
3622
|
+
return fail(400, "collection name is not allowed");
|
|
3623
|
+
const checked = requireId(id);
|
|
3624
|
+
if (!checked.ok)
|
|
3625
|
+
return checked;
|
|
3626
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3627
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
|
|
3628
|
+
};
|
|
3629
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3630
|
+
status,
|
|
3631
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3632
|
+
});
|
|
3633
|
+
var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
|
|
3634
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3635
|
+
var integerParam = (value) => {
|
|
3636
|
+
if (value === null)
|
|
3637
|
+
return void 0;
|
|
3638
|
+
if (!/^-?\d+$/.test(value))
|
|
3639
|
+
return "bad";
|
|
3640
|
+
return Number(value);
|
|
3641
|
+
};
|
|
3642
|
+
var stateAdminRoutes = (routes) => {
|
|
3643
|
+
const open = (namespace) => {
|
|
3644
|
+
try {
|
|
3645
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3646
|
+
} catch (error) {
|
|
3647
|
+
return fail(400, error instanceof Error ? error.message : String(error));
|
|
3648
|
+
}
|
|
3649
|
+
};
|
|
3650
|
+
const wrote = (namespace) => {
|
|
3651
|
+
routes.afterWrite?.(namespace);
|
|
3652
|
+
};
|
|
3653
|
+
return {
|
|
3654
|
+
"GET /state": ({ namespace }) => {
|
|
3655
|
+
const scope = open(namespace);
|
|
3656
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3657
|
+
},
|
|
3658
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3659
|
+
const scope = open(namespace);
|
|
3660
|
+
if (!scope.ok)
|
|
3661
|
+
return fromResult(scope, 200);
|
|
3662
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3663
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3664
|
+
if (limit === "bad")
|
|
3665
|
+
return adminError2(400, "limit: expected an integer");
|
|
3666
|
+
if (after === "bad")
|
|
3667
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3668
|
+
const order = url.searchParams.get("order");
|
|
3669
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3670
|
+
...limit !== void 0 ? { limit } : {},
|
|
3671
|
+
...after !== void 0 ? { after } : {},
|
|
3672
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3673
|
+
}), 200);
|
|
3674
|
+
},
|
|
3675
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3676
|
+
const scope = open(namespace);
|
|
3677
|
+
if (!scope.ok)
|
|
3678
|
+
return fromResult(scope, 200);
|
|
3679
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3680
|
+
},
|
|
3681
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3682
|
+
const scope = open(namespace);
|
|
3683
|
+
if (!scope.ok)
|
|
3684
|
+
return fromResult(scope, 201);
|
|
3685
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
3686
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3687
|
+
}
|
|
3688
|
+
const id = body.id;
|
|
3689
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3690
|
+
return adminError2(400, "id must be a string");
|
|
3691
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3692
|
+
...typeof id === "string" ? { id } : {},
|
|
3693
|
+
value: body.value
|
|
3694
|
+
});
|
|
3695
|
+
if (created.ok)
|
|
3696
|
+
wrote(namespace);
|
|
3697
|
+
return fromResult(created, 201);
|
|
3698
|
+
},
|
|
3699
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3700
|
+
const scope = open(namespace);
|
|
3701
|
+
if (!scope.ok)
|
|
3702
|
+
return fromResult(scope, 200);
|
|
3703
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3704
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3705
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3706
|
+
if (replaced.ok)
|
|
3707
|
+
wrote(namespace);
|
|
3708
|
+
return fromResult(replaced, 200);
|
|
3709
|
+
},
|
|
3710
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3711
|
+
const scope = open(namespace);
|
|
3712
|
+
if (!scope.ok)
|
|
3713
|
+
return fromResult(scope, 200);
|
|
3714
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3715
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3716
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3717
|
+
if (patched.ok)
|
|
3718
|
+
wrote(namespace);
|
|
3719
|
+
return fromResult(patched, 200);
|
|
3720
|
+
},
|
|
3721
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3722
|
+
const scope = open(namespace);
|
|
3723
|
+
if (!scope.ok)
|
|
3724
|
+
return fromResult(scope, 200);
|
|
3725
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3726
|
+
if (removed.ok)
|
|
3727
|
+
wrote(namespace);
|
|
3728
|
+
return fromResult(removed, 200);
|
|
3729
|
+
}
|
|
3730
|
+
};
|
|
3731
|
+
};
|
|
3732
|
+
|
|
1566
3733
|
// ../core/dist/version.js
|
|
1567
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3734
|
+
var PACKAGE_VERSION = true ? "1.5.0" : UNRELEASED_VERSION;
|
|
1568
3735
|
|
|
1569
3736
|
// ../core/dist/webhooks.js
|
|
1570
|
-
var
|
|
1571
|
-
var
|
|
1572
|
-
var
|
|
3737
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
3738
|
+
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
3739
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1573
3740
|
var parseEndpoint = (value) => {
|
|
1574
|
-
if (!
|
|
3741
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
1575
3742
|
return "each endpoint needs a url";
|
|
1576
3743
|
try {
|
|
1577
3744
|
new URL(value.url);
|
|
@@ -1588,18 +3755,18 @@ var parseEndpoint = (value) => {
|
|
|
1588
3755
|
const events = value.events ?? value.enabledEvents;
|
|
1589
3756
|
if (Array.isArray(events))
|
|
1590
3757
|
endpoint.events = events.map(String);
|
|
1591
|
-
if (
|
|
3758
|
+
if (isRecord5(value.tags)) {
|
|
1592
3759
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
1593
3760
|
}
|
|
1594
3761
|
if (typeof value.account === "string")
|
|
1595
3762
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
1596
|
-
if (
|
|
3763
|
+
if (isRecord5(value.headers)) {
|
|
1597
3764
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
1598
3765
|
}
|
|
1599
3766
|
return endpoint;
|
|
1600
3767
|
};
|
|
1601
3768
|
var webhookAdminRoutes = (hub) => ({
|
|
1602
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
3769
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
1603
3770
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
1604
3771
|
const type = url.searchParams.get("type");
|
|
1605
3772
|
return type === null || d.type === type;
|
|
@@ -1607,51 +3774,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
1607
3774
|
}),
|
|
1608
3775
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
1609
3776
|
const type = url.searchParams.get("type");
|
|
1610
|
-
return
|
|
3777
|
+
return json4(200, {
|
|
1611
3778
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
1612
3779
|
});
|
|
1613
3780
|
},
|
|
1614
3781
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
1615
3782
|
const replayed = await hub.replay(params.id);
|
|
1616
|
-
return replayed ?
|
|
3783
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
1617
3784
|
},
|
|
1618
3785
|
"POST /webhooks/flush": async () => {
|
|
1619
3786
|
await hub.flush();
|
|
1620
|
-
return
|
|
3787
|
+
return json4(200, { status: "ok" });
|
|
1621
3788
|
},
|
|
1622
3789
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
1623
|
-
if (!
|
|
1624
|
-
return
|
|
3790
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
3791
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
1625
3792
|
}
|
|
1626
3793
|
const fault = { mode: body.mode };
|
|
1627
3794
|
if (typeof body.count === "number")
|
|
1628
3795
|
fault.count = body.count;
|
|
1629
3796
|
hub.fault(namespace, fault);
|
|
1630
|
-
return
|
|
3797
|
+
return json4(201, { namespace, ...fault });
|
|
1631
3798
|
},
|
|
1632
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
3799
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
1633
3800
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
1634
3801
|
...rest,
|
|
1635
3802
|
secret: secret ? "(set)" : null
|
|
1636
3803
|
}))
|
|
1637
3804
|
}),
|
|
1638
3805
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
1639
|
-
const list = Array.isArray(body) ? body :
|
|
3806
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
1640
3807
|
if (!Array.isArray(list))
|
|
1641
|
-
return
|
|
3808
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
1642
3809
|
const parsed = [];
|
|
1643
3810
|
for (const each of list) {
|
|
1644
3811
|
const endpoint = parseEndpoint(each);
|
|
1645
3812
|
if (typeof endpoint === "string")
|
|
1646
|
-
return
|
|
3813
|
+
return adminError3(400, endpoint);
|
|
1647
3814
|
parsed.push(endpoint);
|
|
1648
3815
|
}
|
|
1649
3816
|
const set = hub.setEndpoints(namespace, parsed);
|
|
1650
|
-
return
|
|
3817
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
1651
3818
|
},
|
|
1652
3819
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
1653
3820
|
hub.setEndpoints(namespace, []);
|
|
1654
|
-
return
|
|
3821
|
+
return json4(200, { status: "ok" });
|
|
1655
3822
|
}
|
|
1656
3823
|
});
|
|
1657
3824
|
var parsePayload = (message) => {
|
|
@@ -1706,8 +3873,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
1706
3873
|
this.name = "TypeError";
|
|
1707
3874
|
}
|
|
1708
3875
|
};
|
|
1709
|
-
var operationMatcher = (
|
|
1710
|
-
const matchers = listOperations(
|
|
3876
|
+
var operationMatcher = (document3) => {
|
|
3877
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
1711
3878
|
operationId: operation.operationId,
|
|
1712
3879
|
method: operation.method.toUpperCase(),
|
|
1713
3880
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -1716,6 +3883,7 @@ var operationMatcher = (document2) => {
|
|
|
1716
3883
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
1717
3884
|
};
|
|
1718
3885
|
var createRuntime = (options) => {
|
|
3886
|
+
assertAdminUi(options.adminUi);
|
|
1719
3887
|
const sqlite = bootSqlite(options.sqlite);
|
|
1720
3888
|
const clock = options.clock ?? createClock();
|
|
1721
3889
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -1801,10 +3969,10 @@ var createRuntime = (options) => {
|
|
|
1801
3969
|
const ensureBranch = (namespace, branch2, at) => {
|
|
1802
3970
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
1803
3971
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
1804
|
-
const
|
|
3972
|
+
const history2 = timeline(namespace);
|
|
1805
3973
|
if (branch2 === "main") {
|
|
1806
3974
|
if (at !== void 0) {
|
|
1807
|
-
const point =
|
|
3975
|
+
const point = history2.checkout("main", at);
|
|
1808
3976
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
1809
3977
|
captured.set(namespace, point.value.snapshot);
|
|
1810
3978
|
rng.setState(point.value.rngState);
|
|
@@ -1817,10 +3985,10 @@ var createRuntime = (options) => {
|
|
|
1817
3985
|
return namespace;
|
|
1818
3986
|
}
|
|
1819
3987
|
const storage = physicalBranch(namespace, branch2);
|
|
1820
|
-
if (!
|
|
3988
|
+
if (!history2.hasBranch(branch2)) {
|
|
1821
3989
|
if (at === void 0)
|
|
1822
|
-
|
|
1823
|
-
const point =
|
|
3990
|
+
history2.commit(capture(namespace));
|
|
3991
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
1824
3992
|
const branchRng = createRng(options.seed ?? 0);
|
|
1825
3993
|
if (point)
|
|
1826
3994
|
branchRng.setState(point.value.rngState);
|
|
@@ -1829,8 +3997,8 @@ var createRuntime = (options) => {
|
|
|
1829
3997
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1830
3998
|
if (point)
|
|
1831
3999
|
captured.set(storage, point.value.snapshot);
|
|
1832
|
-
} else if (at !== void 0 &&
|
|
1833
|
-
const point =
|
|
4000
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
4001
|
+
const point = history2.checkout(branch2, at);
|
|
1834
4002
|
if (!instances.has(storage)) {
|
|
1835
4003
|
const branchRng = createRng(options.seed ?? 0);
|
|
1836
4004
|
branchRng.setState(point.value.rngState);
|
|
@@ -1841,7 +4009,7 @@ var createRuntime = (options) => {
|
|
|
1841
4009
|
captured.set(storage, point.value.snapshot);
|
|
1842
4010
|
} else {
|
|
1843
4011
|
if (!instances.has(storage)) {
|
|
1844
|
-
const point =
|
|
4012
|
+
const point = history2.head(branch2);
|
|
1845
4013
|
const branchRng = createRng(options.seed ?? 0);
|
|
1846
4014
|
if (point)
|
|
1847
4015
|
branchRng.setState(point.value.rngState);
|
|
@@ -1865,8 +4033,8 @@ var createRuntime = (options) => {
|
|
|
1865
4033
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
1866
4034
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
1867
4035
|
const branchName = checkoutOptions.branch ?? "main";
|
|
1868
|
-
const
|
|
1869
|
-
const point =
|
|
4036
|
+
const history2 = timeline(namespace);
|
|
4037
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
1870
4038
|
const storage = ensureBranch(namespace, branchName);
|
|
1871
4039
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
1872
4040
|
captured.set(storage, point.value.snapshot);
|
|
@@ -1916,12 +4084,25 @@ var createRuntime = (options) => {
|
|
|
1916
4084
|
instance(name);
|
|
1917
4085
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
1918
4086
|
captured.set(name, from);
|
|
1919
|
-
const
|
|
1920
|
-
if (
|
|
1921
|
-
|
|
4087
|
+
const history2 = timelines.get(name);
|
|
4088
|
+
if (history2)
|
|
4089
|
+
history2.commit(capture(name), { branch: "main" });
|
|
1922
4090
|
else
|
|
1923
4091
|
timeline(name);
|
|
1924
4092
|
};
|
|
4093
|
+
const declarationsFor = (namespace) => {
|
|
4094
|
+
const declared = options.state;
|
|
4095
|
+
if (!declared)
|
|
4096
|
+
return [];
|
|
4097
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
4098
|
+
};
|
|
4099
|
+
const stateScope = (namespace) => ({
|
|
4100
|
+
sqlite,
|
|
4101
|
+
namespace,
|
|
4102
|
+
storageNamespace: storageNamespace(namespace),
|
|
4103
|
+
root: instance(namespace),
|
|
4104
|
+
declarations: declarationsFor(namespace)
|
|
4105
|
+
});
|
|
1925
4106
|
const runtime = {
|
|
1926
4107
|
name: options.name,
|
|
1927
4108
|
sqlite,
|
|
@@ -1960,6 +4141,7 @@ var createRuntime = (options) => {
|
|
|
1960
4141
|
branch,
|
|
1961
4142
|
checkout,
|
|
1962
4143
|
timeline,
|
|
4144
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
1963
4145
|
fetch: async (incoming) => {
|
|
1964
4146
|
let request = incoming;
|
|
1965
4147
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -2133,10 +4315,10 @@ var createRuntime = (options) => {
|
|
|
2133
4315
|
},
|
|
2134
4316
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
2135
4317
|
inspect: (name) => {
|
|
2136
|
-
const
|
|
4318
|
+
const history2 = timeline(name);
|
|
2137
4319
|
return {
|
|
2138
|
-
branches:
|
|
2139
|
-
checkpoints:
|
|
4320
|
+
branches: history2.branches(),
|
|
4321
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
2140
4322
|
id,
|
|
2141
4323
|
branch: branchName,
|
|
2142
4324
|
parent,
|
|
@@ -2151,13 +4333,22 @@ var createRuntime = (options) => {
|
|
|
2151
4333
|
} : {},
|
|
2152
4334
|
routes: {
|
|
2153
4335
|
...credentialRoutes(credentials),
|
|
2154
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
2155
4336
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
2156
|
-
...options.admin?.(runtime) ?? {}
|
|
4337
|
+
...options.admin?.(runtime) ?? {},
|
|
4338
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4339
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4340
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4341
|
+
...stateAdminRoutes({
|
|
4342
|
+
open: stateScope,
|
|
4343
|
+
afterWrite: (namespace) => {
|
|
4344
|
+
checkpoint(namespace, "main");
|
|
4345
|
+
}
|
|
4346
|
+
}),
|
|
4347
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
2157
4348
|
},
|
|
2158
4349
|
adminKey: options.adminKey
|
|
2159
4350
|
});
|
|
2160
|
-
return runtime;
|
|
4351
|
+
return defineMock(runtime);
|
|
2161
4352
|
};
|
|
2162
4353
|
var mutableResponse = (response) => {
|
|
2163
4354
|
try {
|
|
@@ -2221,9 +4412,12 @@ var credentialRoutes = (registry) => ({
|
|
|
2221
4412
|
}
|
|
2222
4413
|
});
|
|
2223
4414
|
var presetRoutes = (presets, runtime) => ({
|
|
2224
|
-
"GET /faults/presets": () =>
|
|
2225
|
-
|
|
2226
|
-
|
|
4415
|
+
"GET /faults/presets": () => {
|
|
4416
|
+
const body = {
|
|
4417
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4418
|
+
};
|
|
4419
|
+
return adminJson(200, body);
|
|
4420
|
+
},
|
|
2227
4421
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
2228
4422
|
const name = params.name;
|
|
2229
4423
|
if (!presets[name])
|
|
@@ -2396,7 +4590,7 @@ var unitPrice = (catalog, sku) => {
|
|
|
2396
4590
|
};
|
|
2397
4591
|
|
|
2398
4592
|
// src/generated/openapi.ts
|
|
2399
|
-
var
|
|
4593
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Wholescripts supplement fulfilment API (Mockingbird subset)","description":"Stateful mock subset of the Wholescripts ordering API: the product and private-label\\n(MedPax) catalogs, order submit, status polling and cancel. Hand-authored from the\\nconsumers' zod schemas and clients (the vendor publishes no spec).\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from the wire shapes our consumers read and write (backend and EMR wholescripts.types.ts zod schemas, the supplement scheduler's Python client, adapter and mappers)."}},"servers":[{"url":"https://api.wholescripts.com"}],"security":[{"basicAuth":[]}],"paths":{"/api/Orders/PrivateLabelProductList":{"get":{"operationId":"GetPrivateLabelProductList","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Private-label (MedPax) catalog","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PrivateLabelProductList"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/ProductList":{"get":{"operationId":"GetProductList","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"instockonly","in":"query","required":false,"description":"\`true\` keeps only rows with quantity > 0 (the EMR sends it).","schema":{"type":"string","enum":["true","false"]}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":1000}},{"name":"search","in":"query","required":false,"description":"Case-insensitive match on name, SKU, MedPax SKU, brand or categories (the supplement scheduler).","schema":{"type":"string","maxLength":40}}],"responses":{"200":{"description":"Products","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Product"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/Submit":{"post":{"operationId":"SubmitOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderSubmitRequest"}}}},"responses":{"200":{"description":"Submit outcome. A rejected order (bad body, unknown SKU, payment failure) is still 200, with success false and the reason in msg.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderSubmitResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/Status":{"get":{"operationId":"GetOrderStatus","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"ordernum","in":"query","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"order","missing":"000000"}}}],"responses":{"200":{"description":"The order's status rows (empty for an unknown order number)","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/OrderStatus"}}}}},"400":{"description":"Missing ordernum","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AspNetError"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/Cancel":{"post":{"operationId":"CancelOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["OrderNumber"],"properties":{"OrderNumber":{"type":"string","x-mockingbird-resource-ref":{"type":"order","missing":"000000"}}}}}}},"responses":{"200":{"description":"Cancel outcome; success false when the order has progressed too far","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}},"400":{"description":"Missing OrderNumber","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}}}}}},"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic"}},"responses":{"Unauthorized":{"description":"Missing or wrong Basic credentials","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AspNetError"}}}}},"schemas":{"AspNetError":{"type":"object","required":["Message"],"properties":{"Message":{"type":"string"}}},"DefaultDosing":{"type":"object","required":["time","qty"],"properties":{"time":{"type":"string"},"qty":{"type":"number"}}},"MedPaxDetails":{"type":"object","required":["name","genericName","quantity","wholesalePrice","retailPrice"],"properties":{"name":{"type":"string"},"genericName":{"type":"string"},"quantity":{"type":"number"},"wholesalePrice":{"type":"number"},"retailPrice":{"type":"number"}}},"Product":{"type":"object","required":["productName","sku","medPaxSku","categories","retailPrice","upc","descriptionShort","brand","productImage","quantity","countUnit","wholesalePrice","supplementFactsHTML","defaultDosing"],"properties":{"productName":{"type":"string"},"sku":{"type":"string","x-mockingbird-resource":{"type":"sku","identity":true}},"medPaxSku":{"type":"string"},"categories":{"type":"string"},"retailPrice":{"type":"number"},"upc":{"type":"string"},"descriptionShort":{"type":"string"},"descriptionFull":{"type":"string"},"brand":{"type":"string"},"productImage":{"type":"string"},"quantity":{"type":"number"},"countUnit":{"type":"string"},"wholesalePrice":{"type":"number"},"supplementFactsHTML":{"type":"string"},"defaultDosing":{"type":"array","items":{"$ref":"#/components/schemas/DefaultDosing"}},"medPaxDetails":{"oneOf":[{"$ref":"#/components/schemas/MedPaxDetails"},{"type":"null"}]}}},"PrivateLabelProductList":{"type":"object","required":["privateLabelProducts","medPaxPills","privateLabelCartons"],"properties":{"privateLabelProducts":{"type":"array","items":{}},"medPaxPills":{"type":"array","items":{"type":"object","required":["sku","genericName","privateLabelName","quantity"],"properties":{"sku":{"type":"string","x-mockingbird-resource":{"type":"sku","identity":true}},"genericName":{"type":"string"},"privateLabelName":{"type":"string"},"quantity":{"type":"number"}}}},"privateLabelCartons":{"type":"array","items":{"type":"object","required":["sku","name","cartonImage","quantity"],"properties":{"sku":{"type":"string","x-mockingbird-resource":{"type":"sku","identity":true}},"name":{"type":"string"},"cartonImage":{"type":"string"},"quantity":{"type":"number"}}}}}},"MedPaxPill":{"type":"object","required":["Sku","Quantity","ItemTime"],"properties":{"productId":{"type":"string","maxLength":64},"Sku":{"type":"string","x-mockingbird-resource-ref":{"type":"sku","missing":"000000000000000000"}},"Quantity":{"type":"integer","minimum":1,"maximum":1000},"ItemTime":{"type":"string","enum":["AM","PM","AM with food","PM with food"]}}},"OrderItem":{"type":"object","required":["Sku","Quantity"],"properties":{"Sku":{"type":"string","x-mockingbird-resource-ref":{"type":"sku","missing":"000000000000000000"}},"Quantity":{"type":"integer","minimum":1,"maximum":1000},"MedPaxName":{"type":["string","null"],"maxLength":60},"MedPaxPills":{"type":["array","null"],"description":"The pills packed into one MedPax box. The vendor places boxes of at least 14 pills; the bound only keeps generated bodies small.","maxItems":30,"items":{"$ref":"#/components/schemas/MedPaxPill"}}}},"OrderSubmitRequest":{"type":"object","required":["ShippingAddress","Items","ShippingMethod"],"properties":{"ShippingAddress":{"type":"object","required":["FName","LName","Address1","City","State","Zip"],"properties":{"FName":{"type":"string","minLength":1,"maxLength":40},"LName":{"type":"string","minLength":1,"maxLength":40},"Address1":{"type":"string","minLength":1,"maxLength":80},"Address2":{"type":["string","null"],"maxLength":80},"City":{"type":"string","minLength":1,"maxLength":40},"State":{"type":"string","pattern":"^[A-Z]{2}$"},"Zip":{"type":"string","pattern":"^[0-9]{5}(-[0-9]{4})?$"},"Email":{"type":"string","format":"email","maxLength":120}}},"Notes":{"type":["string","null"],"maxLength":500},"Items":{"type":"array","minItems":1,"maxItems":4,"items":{"$ref":"#/components/schemas/OrderItem"}},"ShippingMethod":{"type":"string","minLength":1,"maxLength":40}}},"OrderSubmitResponse":{"type":"object","required":["orderNumber","success","msg"],"properties":{"orderNumber":{"type":"string","x-mockingbird-resource":{"type":"order","identity":true}},"success":{"type":"boolean"},"msg":{"type":"string"}}},"Tracking":{"type":"object","required":["trackingNumber","carrier"],"properties":{"trackingNumber":{"type":"string"},"carrier":{"type":"string"},"trackingUrl":{"type":"string"}}},"OrderStatus":{"type":"object","required":["orderNumber","orderDate","salesOrder","status","tracking","message","subTotal","shipMethod","shipCharge","discount","tax","serviceFee","orderTotal"],"properties":{"orderNumber":{"type":"string"},"orderDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"salesOrder":{"type":"string"},"status":{"type":"string"},"tracking":{"type":"array","items":{"$ref":"#/components/schemas/Tracking"}},"message":{"type":"string"},"subTotal":{"type":"number"},"shipMethod":{"type":"string"},"shipCharge":{"type":"number"},"discount":{"type":"number"},"tax":{"type":"number"},"serviceFee":{"type":"number"},"orderTotal":{"type":"number"}}},"CancelResponse":{"type":"object","required":["success","msg"],"properties":{"success":{"type":"boolean"},"msg":{"type":"string"}}}}}}`);
|
|
2400
4594
|
var operationIds = ["GetPrivateLabelProductList", "GetProductList", "SubmitOrder", "GetOrderStatus", "CancelOrder"];
|
|
2401
4595
|
var supportedOperationIds = ["GetPrivateLabelProductList", "GetProductList", "SubmitOrder", "GetOrderStatus", "CancelOrder"];
|
|
2402
4596
|
|
|
@@ -2471,12 +4665,12 @@ var WHOLESCRIPTS_PRESETS = {
|
|
|
2471
4665
|
rules: [{ status: 401, body: { Message: "Authorization has been denied for this request." } }]
|
|
2472
4666
|
}
|
|
2473
4667
|
};
|
|
2474
|
-
var
|
|
2475
|
-
var
|
|
2476
|
-
var
|
|
4668
|
+
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
4669
|
+
var adminError4 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
|
|
4670
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2477
4671
|
var parseAutoAdvance = (value) => {
|
|
2478
4672
|
if (value === null) return null;
|
|
2479
|
-
if (!
|
|
4673
|
+
if (!isRecord6(value)) return "autoAdvance must be {afterMs, path} or null";
|
|
2480
4674
|
if (typeof value.afterMs !== "number" || value.afterMs < 0)
|
|
2481
4675
|
return "autoAdvance.afterMs must be ms";
|
|
2482
4676
|
if (!Array.isArray(value.path) || value.path.some((s) => typeof s !== "string")) {
|
|
@@ -2485,10 +4679,10 @@ var parseAutoAdvance = (value) => {
|
|
|
2485
4679
|
return { afterMs: value.afterMs, path: value.path };
|
|
2486
4680
|
};
|
|
2487
4681
|
var adminRoutes = (runtime) => ({
|
|
2488
|
-
"GET /orders": ({ namespace }) =>
|
|
4682
|
+
"GET /orders": ({ namespace }) => json5(200, { orders: runtime.instance(namespace).orders() }),
|
|
2489
4683
|
"POST /orders/:id/transition": ({ params, body, namespace }) => {
|
|
2490
|
-
if (!
|
|
2491
|
-
return
|
|
4684
|
+
if (!isRecord6(body) || typeof body.to !== "string") {
|
|
4685
|
+
return adminError4(
|
|
2492
4686
|
400,
|
|
2493
4687
|
'expected {"to": "Pending|Processing|Complete|Cancelled|Error|\u2026", "trackingNumber"?, "carrier"?, "message"?}'
|
|
2494
4688
|
);
|
|
@@ -2501,42 +4695,42 @@ var adminRoutes = (runtime) => ({
|
|
|
2501
4695
|
...optional("trackingUrl"),
|
|
2502
4696
|
...optional("message")
|
|
2503
4697
|
});
|
|
2504
|
-
return order ?
|
|
4698
|
+
return order ? json5(200, order) : adminError4(404, `no order ${params.id}`);
|
|
2505
4699
|
},
|
|
2506
|
-
"GET /catalog": ({ namespace }) =>
|
|
4700
|
+
"GET /catalog": ({ namespace }) => json5(200, runtime.instance(namespace).state.catalog()),
|
|
2507
4701
|
"PUT /catalog": ({ body, namespace }) => {
|
|
2508
|
-
if (!
|
|
2509
|
-
return
|
|
4702
|
+
if (!isRecord6(body) || !Array.isArray(body.products) || !Array.isArray(body.medPaxPills) || !Array.isArray(body.privateLabelCartons)) {
|
|
4703
|
+
return adminError4(
|
|
2510
4704
|
400,
|
|
2511
4705
|
"expected {products: [...], medPaxPills: [...], privateLabelCartons: [...]}"
|
|
2512
4706
|
);
|
|
2513
4707
|
}
|
|
2514
|
-
return
|
|
4708
|
+
return json5(200, runtime.instance(namespace).state.replaceCatalog(body));
|
|
2515
4709
|
},
|
|
2516
|
-
"GET /settings": ({ namespace }) =>
|
|
4710
|
+
"GET /settings": ({ namespace }) => json5(200, runtime.instance(namespace).state.current()),
|
|
2517
4711
|
"PUT /settings": ({ body, namespace }) => {
|
|
2518
|
-
if (!
|
|
4712
|
+
if (!isRecord6(body)) return adminError4(400, "expected a JSON object");
|
|
2519
4713
|
const patch = {};
|
|
2520
4714
|
if (body.accounts !== void 0) {
|
|
2521
|
-
if (!Array.isArray(body.accounts)) return
|
|
2522
|
-
patch.accounts = body.accounts.filter(
|
|
4715
|
+
if (!Array.isArray(body.accounts)) return adminError4(400, "accounts: [{username, password}]");
|
|
4716
|
+
patch.accounts = body.accounts.filter(isRecord6).map((a) => ({
|
|
2523
4717
|
username: String(a.username),
|
|
2524
4718
|
password: String(a.password)
|
|
2525
4719
|
}));
|
|
2526
4720
|
}
|
|
2527
4721
|
if (body.autoAdvance !== void 0) {
|
|
2528
4722
|
const parsed = parseAutoAdvance(body.autoAdvance);
|
|
2529
|
-
if (typeof parsed === "string") return
|
|
4723
|
+
if (typeof parsed === "string") return adminError4(400, parsed);
|
|
2530
4724
|
patch.autoAdvance = parsed;
|
|
2531
4725
|
}
|
|
2532
|
-
return
|
|
4726
|
+
return json5(200, runtime.instance(namespace).state.update(patch));
|
|
2533
4727
|
},
|
|
2534
|
-
"POST /tick": ({ namespace }) =>
|
|
4728
|
+
"POST /tick": ({ namespace }) => json5(200, { applied: runtime.instance(namespace).tick() })
|
|
2535
4729
|
});
|
|
2536
4730
|
var createRuntime2 = (options = {}) => {
|
|
2537
4731
|
const runtime = createRuntime({
|
|
2538
4732
|
name: WHOLESCRIPTS_NAMESPACE,
|
|
2539
|
-
document,
|
|
4733
|
+
document: document2,
|
|
2540
4734
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
2541
4735
|
...options.clock ? { clock: options.clock } : {},
|
|
2542
4736
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -2628,7 +4822,7 @@ var WholescriptsAPI = class {
|
|
|
2628
4822
|
CancelOrder: (context) => this.cancel(context)
|
|
2629
4823
|
});
|
|
2630
4824
|
this.service = createService({
|
|
2631
|
-
document,
|
|
4825
|
+
document: document2,
|
|
2632
4826
|
handlers,
|
|
2633
4827
|
sqlite,
|
|
2634
4828
|
namespace,
|
|
@@ -2844,7 +5038,7 @@ var WholescriptsAPI = class {
|
|
|
2844
5038
|
export {
|
|
2845
5039
|
MEDPAX_BOX_SKU,
|
|
2846
5040
|
DEFAULT_CATALOG,
|
|
2847
|
-
document,
|
|
5041
|
+
document2 as document,
|
|
2848
5042
|
operationIds,
|
|
2849
5043
|
supportedOperationIds,
|
|
2850
5044
|
WHOLESCRIPTS_PRESETS,
|
|
@@ -2854,4 +5048,4 @@ export {
|
|
|
2854
5048
|
canonicalStatus,
|
|
2855
5049
|
WholescriptsAPI
|
|
2856
5050
|
};
|
|
2857
|
-
//# sourceMappingURL=chunk-
|
|
5051
|
+
//# sourceMappingURL=chunk-ZOKMHWCW.js.map
|