@crvouga/mockingbird-service-rxvortex 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -2
- package/dist/{chunk-DOSGPNKC.js → chunk-7IB3GSYU.js} +2339 -145
- package/dist/chunk-7IB3GSYU.js.map +7 -0
- package/dist/{chunk-6CZCXPHW.js → chunk-TPY3O7YZ.js} +3 -2
- package/dist/{chunk-6CZCXPHW.js.map → chunk-TPY3O7YZ.js.map} +2 -2
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +41 -3
- package/dist/index.js +1 -1
- package/dist/server.d.ts +73 -3
- package/dist/server.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-DOSGPNKC.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;
|
|
@@ -538,10 +540,10 @@ var OpenAPIReferenceError = class extends Error {
|
|
|
538
540
|
};
|
|
539
541
|
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
540
542
|
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
541
|
-
var resolveRef = (
|
|
543
|
+
var resolveRef = (document3, ref) => {
|
|
542
544
|
if (!ref.startsWith("#/"))
|
|
543
545
|
throw new OpenAPIReferenceError(ref);
|
|
544
|
-
let cursor =
|
|
546
|
+
let cursor = document3;
|
|
545
547
|
for (const raw of ref.slice(2).split("/")) {
|
|
546
548
|
const segment = unescapePointer(raw);
|
|
547
549
|
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
@@ -553,14 +555,14 @@ var resolveRef = (document2, ref) => {
|
|
|
553
555
|
throw new OpenAPIReferenceError(ref);
|
|
554
556
|
return cursor;
|
|
555
557
|
};
|
|
556
|
-
var deref = (
|
|
558
|
+
var deref = (document3, value) => {
|
|
557
559
|
let current = value;
|
|
558
560
|
const seen = /* @__PURE__ */ new Set();
|
|
559
561
|
while (isReference(current)) {
|
|
560
562
|
if (seen.has(current.$ref))
|
|
561
563
|
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
562
564
|
seen.add(current.$ref);
|
|
563
|
-
current = resolveRef(
|
|
565
|
+
current = resolveRef(document3, current.$ref);
|
|
564
566
|
}
|
|
565
567
|
return current;
|
|
566
568
|
};
|
|
@@ -578,36 +580,36 @@ var HTTP_METHODS = [
|
|
|
578
580
|
];
|
|
579
581
|
|
|
580
582
|
// ../../openapi/core/dist/document.js
|
|
581
|
-
var mergeParameters = (
|
|
583
|
+
var mergeParameters = (document3, item, own) => {
|
|
582
584
|
const merged = /* @__PURE__ */ new Map();
|
|
583
585
|
for (const raw of item.parameters ?? []) {
|
|
584
|
-
const parameter = deref(
|
|
586
|
+
const parameter = deref(document3, raw);
|
|
585
587
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
586
588
|
}
|
|
587
589
|
for (const raw of own ?? []) {
|
|
588
|
-
const parameter = deref(
|
|
590
|
+
const parameter = deref(document3, raw);
|
|
589
591
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
590
592
|
}
|
|
591
593
|
return [...merged.values()];
|
|
592
594
|
};
|
|
593
|
-
var listOperations = (
|
|
595
|
+
var listOperations = (document3) => {
|
|
594
596
|
const operations = [];
|
|
595
|
-
for (const [path, item] of Object.entries(
|
|
597
|
+
for (const [path, item] of Object.entries(document3.paths)) {
|
|
596
598
|
for (const method of HTTP_METHODS) {
|
|
597
599
|
const operation = item[method];
|
|
598
600
|
if (operation?.operationId === void 0)
|
|
599
601
|
continue;
|
|
600
602
|
const responses = {};
|
|
601
603
|
for (const [status, response] of Object.entries(operation.responses)) {
|
|
602
|
-
responses[status] = deref(
|
|
604
|
+
responses[status] = deref(document3, response);
|
|
603
605
|
}
|
|
604
606
|
operations.push({
|
|
605
607
|
operationId: operation.operationId,
|
|
606
608
|
method,
|
|
607
609
|
path,
|
|
608
610
|
operation,
|
|
609
|
-
parameters: mergeParameters(
|
|
610
|
-
requestBody: operation.requestBody === void 0 ? void 0 : deref(
|
|
611
|
+
parameters: mergeParameters(document3, item, operation.parameters),
|
|
612
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
|
|
611
613
|
responses
|
|
612
614
|
});
|
|
613
615
|
}
|
|
@@ -616,7 +618,7 @@ var listOperations = (document2) => {
|
|
|
616
618
|
};
|
|
617
619
|
|
|
618
620
|
// ../../openapi/core/dist/schema.js
|
|
619
|
-
var resolveSchema = (
|
|
621
|
+
var resolveSchema = (document3, schema) => {
|
|
620
622
|
let current = schema;
|
|
621
623
|
const seen = /* @__PURE__ */ new Set();
|
|
622
624
|
while (typeof current.$ref === "string") {
|
|
@@ -625,7 +627,7 @@ var resolveSchema = (document2, schema) => {
|
|
|
625
627
|
break;
|
|
626
628
|
seen.add(ref);
|
|
627
629
|
const { $ref: _ignored, ...siblings } = current;
|
|
628
|
-
const target = resolveRef(
|
|
630
|
+
const target = resolveRef(document3, ref);
|
|
629
631
|
current = { ...target, ...siblings };
|
|
630
632
|
}
|
|
631
633
|
if (current.nullable === true) {
|
|
@@ -696,71 +698,71 @@ var FORMAT_PATTERNS = {
|
|
|
696
698
|
ipv4: /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/
|
|
697
699
|
};
|
|
698
700
|
var graphemeLength = (value) => [...value].length;
|
|
699
|
-
var validateValue = (
|
|
701
|
+
var validateValue = (document3, schema, value, path = []) => {
|
|
700
702
|
const errors = [];
|
|
701
|
-
const s = resolveSchema(
|
|
702
|
-
const
|
|
703
|
+
const s = resolveSchema(document3, schema);
|
|
704
|
+
const fail2 = (message) => errors.push({ path, message });
|
|
703
705
|
const actual = jsonTypeOf(value);
|
|
704
706
|
if (actual === "undefined") {
|
|
705
|
-
|
|
707
|
+
fail2("value is undefined");
|
|
706
708
|
return errors;
|
|
707
709
|
}
|
|
708
710
|
const types = schemaTypes(s);
|
|
709
711
|
if (types.length > 0) {
|
|
710
712
|
const ok = types.some((t) => t === actual || t === "number" && actual === "integer");
|
|
711
713
|
if (!ok) {
|
|
712
|
-
|
|
714
|
+
fail2(`expected type ${types.join("|")}, got ${actual}`);
|
|
713
715
|
return errors;
|
|
714
716
|
}
|
|
715
717
|
}
|
|
716
718
|
if (s.enum && !(value === null && types.includes("null")) && !s.enum.some((candidate) => deepEqual(candidate, value))) {
|
|
717
|
-
|
|
719
|
+
fail2("value not in enum");
|
|
718
720
|
}
|
|
719
721
|
if (s.const !== void 0 && !deepEqual(s.const, value))
|
|
720
|
-
|
|
722
|
+
fail2("value does not equal const");
|
|
721
723
|
if (typeof value === "string") {
|
|
722
724
|
const length = graphemeLength(value);
|
|
723
725
|
if (s.minLength !== void 0 && length < s.minLength)
|
|
724
|
-
|
|
726
|
+
fail2(`length ${length} < minLength ${s.minLength}`);
|
|
725
727
|
if (s.maxLength !== void 0 && length > s.maxLength)
|
|
726
|
-
|
|
728
|
+
fail2(`length ${length} > maxLength ${s.maxLength}`);
|
|
727
729
|
if (s.pattern !== void 0) {
|
|
728
730
|
try {
|
|
729
731
|
if (!new RegExp(s.pattern, "u").test(value))
|
|
730
|
-
|
|
732
|
+
fail2(`does not match pattern ${s.pattern}`);
|
|
731
733
|
} catch {
|
|
732
734
|
}
|
|
733
735
|
}
|
|
734
736
|
if (s.format !== void 0) {
|
|
735
737
|
const pattern = FORMAT_PATTERNS[s.format];
|
|
736
738
|
if (pattern && !pattern.test(value))
|
|
737
|
-
|
|
739
|
+
fail2(`does not match format ${s.format}`);
|
|
738
740
|
}
|
|
739
741
|
}
|
|
740
742
|
if (typeof value === "number") {
|
|
741
743
|
if (s.minimum !== void 0 && value < s.minimum)
|
|
742
|
-
|
|
744
|
+
fail2(`${value} < minimum ${s.minimum}`);
|
|
743
745
|
if (s.maximum !== void 0 && value > s.maximum)
|
|
744
|
-
|
|
746
|
+
fail2(`${value} > maximum ${s.maximum}`);
|
|
745
747
|
if (s.exclusiveMinimum !== void 0 && value <= s.exclusiveMinimum)
|
|
746
|
-
|
|
748
|
+
fail2(`${value} <= exclusiveMinimum ${s.exclusiveMinimum}`);
|
|
747
749
|
if (s.exclusiveMaximum !== void 0 && value >= s.exclusiveMaximum)
|
|
748
|
-
|
|
750
|
+
fail2(`${value} >= exclusiveMaximum ${s.exclusiveMaximum}`);
|
|
749
751
|
if (s.multipleOf !== void 0 && Math.abs(value / s.multipleOf - Math.round(value / s.multipleOf)) > 1e-9) {
|
|
750
|
-
|
|
752
|
+
fail2(`${value} is not a multiple of ${s.multipleOf}`);
|
|
751
753
|
}
|
|
752
754
|
}
|
|
753
755
|
if (Array.isArray(value)) {
|
|
754
756
|
if (s.minItems !== void 0 && value.length < s.minItems)
|
|
755
|
-
|
|
757
|
+
fail2(`${value.length} items < minItems ${s.minItems}`);
|
|
756
758
|
if (s.maxItems !== void 0 && value.length > s.maxItems)
|
|
757
|
-
|
|
759
|
+
fail2(`${value.length} items > maxItems ${s.maxItems}`);
|
|
758
760
|
if (s.uniqueItems && value.some((item, i) => value.slice(0, i).some((prev) => deepEqual(prev, item))))
|
|
759
|
-
|
|
761
|
+
fail2("items are not unique");
|
|
760
762
|
value.forEach((item, i) => {
|
|
761
763
|
const itemSchema = s.prefixItems?.[i] ?? s.items;
|
|
762
764
|
if (itemSchema)
|
|
763
|
-
errors.push(...validateValue(
|
|
765
|
+
errors.push(...validateValue(document3, itemSchema, item, [...path, i]));
|
|
764
766
|
});
|
|
765
767
|
}
|
|
766
768
|
if (actual === "object") {
|
|
@@ -768,41 +770,41 @@ var validateValue = (document2, schema, value, path = []) => {
|
|
|
768
770
|
const keys = Object.keys(record2);
|
|
769
771
|
for (const name of s.required ?? [])
|
|
770
772
|
if (!(name in record2))
|
|
771
|
-
|
|
773
|
+
fail2(`missing required property ${name}`);
|
|
772
774
|
if (s.minProperties !== void 0 && keys.length < s.minProperties)
|
|
773
|
-
|
|
775
|
+
fail2(`${keys.length} properties < minProperties ${s.minProperties}`);
|
|
774
776
|
if (s.maxProperties !== void 0 && keys.length > s.maxProperties)
|
|
775
|
-
|
|
777
|
+
fail2(`${keys.length} properties > maxProperties ${s.maxProperties}`);
|
|
776
778
|
for (const key of keys) {
|
|
777
779
|
const property = s.properties?.[key];
|
|
778
780
|
if (property) {
|
|
779
|
-
errors.push(...validateValue(
|
|
781
|
+
errors.push(...validateValue(document3, property, record2[key], [...path, key]));
|
|
780
782
|
continue;
|
|
781
783
|
}
|
|
782
784
|
if (s.additionalProperties === false)
|
|
783
|
-
|
|
785
|
+
fail2(`unexpected property ${key}`);
|
|
784
786
|
else if (typeof s.additionalProperties === "object") {
|
|
785
|
-
errors.push(...validateValue(
|
|
787
|
+
errors.push(...validateValue(document3, s.additionalProperties, record2[key], [...path, key]));
|
|
786
788
|
}
|
|
787
789
|
if (s.propertyNames) {
|
|
788
|
-
const nameErrors = validateValue(
|
|
790
|
+
const nameErrors = validateValue(document3, s.propertyNames, key, [...path, key]);
|
|
789
791
|
if (nameErrors.length > 0)
|
|
790
|
-
|
|
792
|
+
fail2(`property name ${key} is invalid: ${nameErrors[0]?.message}`);
|
|
791
793
|
}
|
|
792
794
|
}
|
|
793
795
|
}
|
|
794
796
|
if (s.allOf)
|
|
795
797
|
for (const branch of s.allOf)
|
|
796
|
-
errors.push(...validateValue(
|
|
797
|
-
if (s.anyOf && !s.anyOf.some((branch) => validateValue(
|
|
798
|
-
|
|
798
|
+
errors.push(...validateValue(document3, branch, value, path));
|
|
799
|
+
if (s.anyOf && !s.anyOf.some((branch) => validateValue(document3, branch, value).length === 0))
|
|
800
|
+
fail2("matches no anyOf branch");
|
|
799
801
|
if (s.oneOf) {
|
|
800
|
-
const matches2 = s.oneOf.filter((branch) => validateValue(
|
|
802
|
+
const matches2 = s.oneOf.filter((branch) => validateValue(document3, branch, value).length === 0).length;
|
|
801
803
|
if (matches2 !== 1)
|
|
802
|
-
|
|
804
|
+
fail2(`matches ${matches2} oneOf branches, expected exactly 1`);
|
|
803
805
|
}
|
|
804
|
-
if (s.not && validateValue(
|
|
805
|
-
|
|
806
|
+
if (s.not && validateValue(document3, s.not, value).length === 0)
|
|
807
|
+
fail2("matches forbidden `not` schema");
|
|
806
808
|
return errors;
|
|
807
809
|
};
|
|
808
810
|
|
|
@@ -1334,6 +1336,1737 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1334
1336
|
});
|
|
1335
1337
|
};
|
|
1336
1338
|
|
|
1339
|
+
// ../../ui/dist/reset.js
|
|
1340
|
+
var CSS_RESET = `*,
|
|
1341
|
+
*::before,
|
|
1342
|
+
*::after {
|
|
1343
|
+
box-sizing: border-box;
|
|
1344
|
+
margin: 0;
|
|
1345
|
+
padding: 0;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
* {
|
|
1349
|
+
scrollbar-width: thin;
|
|
1350
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
*::-webkit-scrollbar {
|
|
1354
|
+
width: 12px;
|
|
1355
|
+
height: 12px;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
*::-webkit-scrollbar-track,
|
|
1359
|
+
*::-webkit-scrollbar-corner {
|
|
1360
|
+
background: Canvas;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
*::-webkit-scrollbar-thumb {
|
|
1364
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1365
|
+
border: 3px solid Canvas;
|
|
1366
|
+
border-radius: 999px;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
html {
|
|
1370
|
+
hanging-punctuation: first allow-end last;
|
|
1371
|
+
-webkit-text-size-adjust: none;
|
|
1372
|
+
text-size-adjust: none;
|
|
1373
|
+
tab-size: 4;
|
|
1374
|
+
font-family:
|
|
1375
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1376
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1377
|
+
font-size: 16px;
|
|
1378
|
+
line-height: 1.5;
|
|
1379
|
+
-webkit-font-smoothing: antialiased;
|
|
1380
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1381
|
+
text-rendering: optimizeLegibility;
|
|
1382
|
+
-webkit-tap-highlight-color: transparent;
|
|
1383
|
+
scroll-behavior: smooth;
|
|
1384
|
+
background: Canvas;
|
|
1385
|
+
color: CanvasText;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
body {
|
|
1389
|
+
min-height: 100svh;
|
|
1390
|
+
line-height: 1.5;
|
|
1391
|
+
background: Canvas;
|
|
1392
|
+
color: CanvasText;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
h1 {
|
|
1396
|
+
font-size: 2em;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
h2 {
|
|
1400
|
+
font-size: 1.5em;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
h3 {
|
|
1404
|
+
font-size: 1.17em;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
h4 {
|
|
1408
|
+
font-size: 1em;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
h5 {
|
|
1412
|
+
font-size: 0.83em;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
h6 {
|
|
1416
|
+
font-size: 0.67em;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
h1,
|
|
1420
|
+
h2,
|
|
1421
|
+
h3,
|
|
1422
|
+
h4,
|
|
1423
|
+
h5,
|
|
1424
|
+
h6 {
|
|
1425
|
+
font-weight: 700;
|
|
1426
|
+
line-height: 1.2;
|
|
1427
|
+
text-wrap: balance;
|
|
1428
|
+
overflow-wrap: break-word;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
p,
|
|
1432
|
+
li,
|
|
1433
|
+
figcaption,
|
|
1434
|
+
dd,
|
|
1435
|
+
dt,
|
|
1436
|
+
blockquote {
|
|
1437
|
+
overflow-wrap: break-word;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
p,
|
|
1441
|
+
li,
|
|
1442
|
+
figcaption,
|
|
1443
|
+
blockquote {
|
|
1444
|
+
text-wrap: pretty;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
ul,
|
|
1448
|
+
ol,
|
|
1449
|
+
menu {
|
|
1450
|
+
list-style: none;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
a {
|
|
1454
|
+
color: inherit;
|
|
1455
|
+
text-decoration: underline;
|
|
1456
|
+
text-decoration-thickness: 1px;
|
|
1457
|
+
text-underline-offset: 0.15em;
|
|
1458
|
+
text-decoration-skip-ink: auto;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
b,
|
|
1462
|
+
strong {
|
|
1463
|
+
font-weight: 700;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
small {
|
|
1467
|
+
font-size: 0.875em;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
code,
|
|
1471
|
+
kbd,
|
|
1472
|
+
samp,
|
|
1473
|
+
pre {
|
|
1474
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1475
|
+
font-size: 1em;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
sub,
|
|
1479
|
+
sup {
|
|
1480
|
+
font-size: 75%;
|
|
1481
|
+
line-height: 0;
|
|
1482
|
+
position: relative;
|
|
1483
|
+
vertical-align: baseline;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
sub {
|
|
1487
|
+
bottom: -0.25em;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
sup {
|
|
1491
|
+
top: -0.5em;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
abbr[title] {
|
|
1495
|
+
text-decoration: underline dotted;
|
|
1496
|
+
text-underline-offset: 0.15em;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
mark {
|
|
1500
|
+
background: Mark;
|
|
1501
|
+
color: MarkText;
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
hr {
|
|
1505
|
+
height: 0;
|
|
1506
|
+
border: 0;
|
|
1507
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1508
|
+
color: inherit;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
img,
|
|
1512
|
+
picture,
|
|
1513
|
+
video,
|
|
1514
|
+
canvas {
|
|
1515
|
+
display: block;
|
|
1516
|
+
max-width: 100%;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
img,
|
|
1520
|
+
video {
|
|
1521
|
+
height: auto;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
svg {
|
|
1525
|
+
overflow: hidden;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
iframe {
|
|
1529
|
+
border: 0;
|
|
1530
|
+
max-width: 100%;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
table {
|
|
1534
|
+
border-collapse: collapse;
|
|
1535
|
+
border-spacing: 0;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
fieldset {
|
|
1539
|
+
border: 0;
|
|
1540
|
+
min-inline-size: 0;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
legend {
|
|
1544
|
+
padding: 0;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
button,
|
|
1548
|
+
input,
|
|
1549
|
+
select,
|
|
1550
|
+
textarea,
|
|
1551
|
+
optgroup {
|
|
1552
|
+
font: inherit;
|
|
1553
|
+
letter-spacing: inherit;
|
|
1554
|
+
color: inherit;
|
|
1555
|
+
margin: 0;
|
|
1556
|
+
vertical-align: middle;
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
button,
|
|
1560
|
+
input[type="button"],
|
|
1561
|
+
input[type="submit"],
|
|
1562
|
+
input[type="reset"] {
|
|
1563
|
+
appearance: none;
|
|
1564
|
+
background: none;
|
|
1565
|
+
border: 0;
|
|
1566
|
+
padding: 0;
|
|
1567
|
+
cursor: pointer;
|
|
1568
|
+
text-align: center;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
input,
|
|
1572
|
+
textarea,
|
|
1573
|
+
select {
|
|
1574
|
+
background-color: Canvas;
|
|
1575
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1576
|
+
border-radius: 0;
|
|
1577
|
+
padding: 0.5em 0.65em;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
input[type="checkbox"],
|
|
1581
|
+
input[type="radio"],
|
|
1582
|
+
input[type="range"],
|
|
1583
|
+
input[type="file"],
|
|
1584
|
+
input[type="color"],
|
|
1585
|
+
input[type="button"],
|
|
1586
|
+
input[type="submit"],
|
|
1587
|
+
input[type="reset"],
|
|
1588
|
+
input[type="image"],
|
|
1589
|
+
input[type="hidden"] {
|
|
1590
|
+
background: none;
|
|
1591
|
+
border: 0;
|
|
1592
|
+
padding: 0;
|
|
1593
|
+
border-radius: 0;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
input[type="checkbox"],
|
|
1597
|
+
input[type="radio"] {
|
|
1598
|
+
accent-color: CanvasText;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
input[type="search"] {
|
|
1602
|
+
appearance: none;
|
|
1603
|
+
background-color: Canvas;
|
|
1604
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1608
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1609
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1610
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1611
|
+
-webkit-appearance: none;
|
|
1612
|
+
display: none;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
input[type="number"] {
|
|
1616
|
+
appearance: textfield;
|
|
1617
|
+
background-color: Canvas;
|
|
1618
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1622
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1623
|
+
-webkit-appearance: none;
|
|
1624
|
+
margin: 0;
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
textarea {
|
|
1628
|
+
resize: vertical;
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
::placeholder {
|
|
1632
|
+
opacity: 1;
|
|
1633
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
:focus-visible {
|
|
1637
|
+
outline: 2px solid CanvasText;
|
|
1638
|
+
outline-offset: 2px;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
:focus:not(:focus-visible) {
|
|
1642
|
+
outline: none;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
:disabled,
|
|
1646
|
+
[disabled] {
|
|
1647
|
+
cursor: default;
|
|
1648
|
+
opacity: 0.6;
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
label,
|
|
1652
|
+
summary,
|
|
1653
|
+
select,
|
|
1654
|
+
[role="button"] {
|
|
1655
|
+
cursor: pointer;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
summary {
|
|
1659
|
+
display: list-item;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
details {
|
|
1663
|
+
display: block;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
dialog {
|
|
1667
|
+
margin: auto;
|
|
1668
|
+
padding: 1rem;
|
|
1669
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1670
|
+
background: Canvas;
|
|
1671
|
+
color: CanvasText;
|
|
1672
|
+
max-width: calc(100vw - 2rem);
|
|
1673
|
+
max-height: calc(100svh - 2rem);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
dialog:not([open]) {
|
|
1677
|
+
display: none;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
::backdrop {
|
|
1681
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
[hidden] {
|
|
1685
|
+
display: none !important;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
::selection {
|
|
1689
|
+
background: Highlight;
|
|
1690
|
+
color: HighlightText;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1694
|
+
*,
|
|
1695
|
+
*::before,
|
|
1696
|
+
*::after {
|
|
1697
|
+
animation-duration: 0.01ms !important;
|
|
1698
|
+
animation-iteration-count: 1 !important;
|
|
1699
|
+
transition-duration: 0.01ms !important;
|
|
1700
|
+
scroll-behavior: auto !important;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
@media (pointer: coarse) {
|
|
1705
|
+
input,
|
|
1706
|
+
select,
|
|
1707
|
+
textarea {
|
|
1708
|
+
font-size: max(16px, 1em);
|
|
1709
|
+
}
|
|
1710
|
+
}`;
|
|
1711
|
+
|
|
1712
|
+
// ../core/dist/admin-client.js
|
|
1713
|
+
function isRecord2(value) {
|
|
1714
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1715
|
+
}
|
|
1716
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1717
|
+
const clip = (value, max) => {
|
|
1718
|
+
if (typeof value !== "string")
|
|
1719
|
+
return null;
|
|
1720
|
+
const trimmed = value.trim();
|
|
1721
|
+
if (trimmed === "")
|
|
1722
|
+
return null;
|
|
1723
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1724
|
+
};
|
|
1725
|
+
const httpUrl = (value) => {
|
|
1726
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1727
|
+
return null;
|
|
1728
|
+
try {
|
|
1729
|
+
const url = new URL(value);
|
|
1730
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1731
|
+
return null;
|
|
1732
|
+
return url.href;
|
|
1733
|
+
} catch {
|
|
1734
|
+
return null;
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
const hexColor = (value) => {
|
|
1738
|
+
if (typeof value !== "string")
|
|
1739
|
+
return null;
|
|
1740
|
+
const raw = value.trim();
|
|
1741
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1742
|
+
};
|
|
1743
|
+
const hostname = (value) => {
|
|
1744
|
+
try {
|
|
1745
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1746
|
+
} catch {
|
|
1747
|
+
return value;
|
|
1748
|
+
}
|
|
1749
|
+
};
|
|
1750
|
+
host.replaceChildren();
|
|
1751
|
+
host.hidden = true;
|
|
1752
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1753
|
+
return;
|
|
1754
|
+
const row = catalog[service];
|
|
1755
|
+
if (!isRecord2(row))
|
|
1756
|
+
return;
|
|
1757
|
+
const vendor = clip(row.vendor, 80);
|
|
1758
|
+
const website = httpUrl(row.website);
|
|
1759
|
+
const guide = httpUrl(row.guide);
|
|
1760
|
+
const docs = httpUrl(row.docs);
|
|
1761
|
+
const logo = httpUrl(row.logo);
|
|
1762
|
+
const color = hexColor(row.color);
|
|
1763
|
+
const description = clip(row.description, 280);
|
|
1764
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1765
|
+
return;
|
|
1766
|
+
const add = (node) => {
|
|
1767
|
+
host.append(node);
|
|
1768
|
+
return node;
|
|
1769
|
+
};
|
|
1770
|
+
if (logo !== null) {
|
|
1771
|
+
const img = doc.createElement("img");
|
|
1772
|
+
img.alt = "";
|
|
1773
|
+
img.src = logo;
|
|
1774
|
+
img.width = 16;
|
|
1775
|
+
img.height = 16;
|
|
1776
|
+
img.decoding = "async";
|
|
1777
|
+
img.referrerPolicy = "no-referrer";
|
|
1778
|
+
if (color !== null)
|
|
1779
|
+
img.style.borderColor = color;
|
|
1780
|
+
add(img);
|
|
1781
|
+
}
|
|
1782
|
+
const name = doc.createElement("span");
|
|
1783
|
+
name.className = "vendor-name";
|
|
1784
|
+
name.textContent = vendor;
|
|
1785
|
+
if (description !== null)
|
|
1786
|
+
name.title = description;
|
|
1787
|
+
add(name);
|
|
1788
|
+
const sep = () => {
|
|
1789
|
+
const node = doc.createElement("span");
|
|
1790
|
+
node.className = "vendor-sep";
|
|
1791
|
+
node.setAttribute("aria-hidden", "true");
|
|
1792
|
+
node.textContent = "\xB7";
|
|
1793
|
+
return node;
|
|
1794
|
+
};
|
|
1795
|
+
const link = (href, label, title) => {
|
|
1796
|
+
const node = doc.createElement("a");
|
|
1797
|
+
node.className = "vendor-link";
|
|
1798
|
+
node.href = href;
|
|
1799
|
+
node.target = "_blank";
|
|
1800
|
+
node.rel = "noopener noreferrer";
|
|
1801
|
+
node.referrerPolicy = "no-referrer";
|
|
1802
|
+
node.textContent = label;
|
|
1803
|
+
node.title = title;
|
|
1804
|
+
return node;
|
|
1805
|
+
};
|
|
1806
|
+
if (website !== null) {
|
|
1807
|
+
add(sep());
|
|
1808
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1809
|
+
}
|
|
1810
|
+
if (guide !== null) {
|
|
1811
|
+
add(sep());
|
|
1812
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1813
|
+
}
|
|
1814
|
+
if (docs !== null) {
|
|
1815
|
+
add(sep());
|
|
1816
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1817
|
+
}
|
|
1818
|
+
host.removeAttribute("hidden");
|
|
1819
|
+
host.hidden = false;
|
|
1820
|
+
}
|
|
1821
|
+
function startAdminBrand(env) {
|
|
1822
|
+
const requested = env.params.get("brands");
|
|
1823
|
+
let brandsUrl = env.brandsUrl;
|
|
1824
|
+
if (requested) {
|
|
1825
|
+
try {
|
|
1826
|
+
const url = new URL(requested, env.location.href);
|
|
1827
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1828
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1829
|
+
brandsUrl = url.href;
|
|
1830
|
+
} catch {
|
|
1831
|
+
brandsUrl = env.brandsUrl;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
const vendorHost = env.$("vendor");
|
|
1835
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1836
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1837
|
+
if (vendorHost === null)
|
|
1838
|
+
return;
|
|
1839
|
+
env.fetch(brandsUrl, {
|
|
1840
|
+
headers: { accept: "application/json" },
|
|
1841
|
+
signal: AbortSignal.timeout(5e3)
|
|
1842
|
+
}).then(async (response) => {
|
|
1843
|
+
if (!response.ok)
|
|
1844
|
+
return null;
|
|
1845
|
+
const catalog = await response.json();
|
|
1846
|
+
return catalog;
|
|
1847
|
+
}).then((catalog) => {
|
|
1848
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1849
|
+
}).catch(() => {
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
function faultPresetList(value) {
|
|
1853
|
+
if (!isRecord2(value))
|
|
1854
|
+
throw new Error("Fault presets response was not an object");
|
|
1855
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1856
|
+
return { presets: [] };
|
|
1857
|
+
}
|
|
1858
|
+
if (!Array.isArray(value.presets))
|
|
1859
|
+
throw new Error("Fault presets response was not a list");
|
|
1860
|
+
return {
|
|
1861
|
+
presets: value.presets.flatMap((item) => {
|
|
1862
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1863
|
+
return [];
|
|
1864
|
+
return [{ name: item.name }];
|
|
1865
|
+
})
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
function bootAdmin(config) {
|
|
1869
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1870
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1871
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1872
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1873
|
+
const readJson2 = (text) => {
|
|
1874
|
+
const value = JSON.parse(text);
|
|
1875
|
+
return value;
|
|
1876
|
+
};
|
|
1877
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1878
|
+
switch (char) {
|
|
1879
|
+
case "&":
|
|
1880
|
+
return "&";
|
|
1881
|
+
case "<":
|
|
1882
|
+
return "<";
|
|
1883
|
+
case ">":
|
|
1884
|
+
return ">";
|
|
1885
|
+
case '"':
|
|
1886
|
+
return """;
|
|
1887
|
+
default:
|
|
1888
|
+
return "'";
|
|
1889
|
+
}
|
|
1890
|
+
});
|
|
1891
|
+
const el = (id, kind) => {
|
|
1892
|
+
const node = document.getElementById(id);
|
|
1893
|
+
if (!(node instanceof kind))
|
|
1894
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1895
|
+
return node;
|
|
1896
|
+
};
|
|
1897
|
+
const errorMessage = (data, fallback) => {
|
|
1898
|
+
if (!isRecord2(data))
|
|
1899
|
+
return fallback;
|
|
1900
|
+
const error = data.error;
|
|
1901
|
+
if (!isRecord2(error) || typeof error.message !== "string" || error.message === "") {
|
|
1902
|
+
return fallback;
|
|
1903
|
+
}
|
|
1904
|
+
return error.message;
|
|
1905
|
+
};
|
|
1906
|
+
const requireList = (value, label) => {
|
|
1907
|
+
if (value === void 0 || value === null)
|
|
1908
|
+
return [];
|
|
1909
|
+
if (!Array.isArray(value))
|
|
1910
|
+
throw new Error(`${label} was not a list`);
|
|
1911
|
+
return value;
|
|
1912
|
+
};
|
|
1913
|
+
const state = {
|
|
1914
|
+
namespace: "default",
|
|
1915
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1916
|
+
view: "overview",
|
|
1917
|
+
collection: "",
|
|
1918
|
+
shape: null,
|
|
1919
|
+
route: null,
|
|
1920
|
+
editing: null
|
|
1921
|
+
};
|
|
1922
|
+
const standard = new Set(config.standardRoutes);
|
|
1923
|
+
const banner = el("banner", HTMLElement);
|
|
1924
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1925
|
+
keyInput.value = state.key;
|
|
1926
|
+
const params = new URLSearchParams(location.search);
|
|
1927
|
+
const queryKey = params.get("key");
|
|
1928
|
+
if (queryKey) {
|
|
1929
|
+
state.key = queryKey;
|
|
1930
|
+
keyInput.value = state.key;
|
|
1931
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1932
|
+
params.delete("key");
|
|
1933
|
+
const next = params.toString();
|
|
1934
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1935
|
+
}
|
|
1936
|
+
const queryNamespace = params.get("namespace");
|
|
1937
|
+
if (queryNamespace)
|
|
1938
|
+
state.namespace = queryNamespace;
|
|
1939
|
+
const showError = (error) => {
|
|
1940
|
+
banner.textContent = error instanceof Error ? error.message : String(error);
|
|
1941
|
+
banner.classList.add("show");
|
|
1942
|
+
};
|
|
1943
|
+
const clearError = () => {
|
|
1944
|
+
banner.classList.remove("show");
|
|
1945
|
+
};
|
|
1946
|
+
const api = async (method, path, body) => {
|
|
1947
|
+
const headers = { accept: "application/json" };
|
|
1948
|
+
if (state.key !== "")
|
|
1949
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1950
|
+
if (state.namespace !== "")
|
|
1951
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1952
|
+
if (body !== void 0)
|
|
1953
|
+
headers["content-type"] = "application/json";
|
|
1954
|
+
const init = { method, headers };
|
|
1955
|
+
if (body !== void 0)
|
|
1956
|
+
init.body = JSON.stringify(body);
|
|
1957
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1958
|
+
const text = await response.text();
|
|
1959
|
+
let data = null;
|
|
1960
|
+
if (text !== "") {
|
|
1961
|
+
try {
|
|
1962
|
+
data = readJson2(text);
|
|
1963
|
+
} catch {
|
|
1964
|
+
data = { raw: text };
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
if (response.status === 401) {
|
|
1968
|
+
keyInput.focus();
|
|
1969
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1970
|
+
}
|
|
1971
|
+
if (!response.ok) {
|
|
1972
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1973
|
+
}
|
|
1974
|
+
return data;
|
|
1975
|
+
};
|
|
1976
|
+
const originGet = async (path) => {
|
|
1977
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1978
|
+
if (!response.ok)
|
|
1979
|
+
throw new Error(`${response.status} ${path}`);
|
|
1980
|
+
const value = await response.json();
|
|
1981
|
+
return value;
|
|
1982
|
+
};
|
|
1983
|
+
const panelApi = {
|
|
1984
|
+
get: (path) => api("GET", path),
|
|
1985
|
+
send: (method, path, body) => api(method, path, body),
|
|
1986
|
+
namespace: () => state.namespace
|
|
1987
|
+
};
|
|
1988
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1989
|
+
const setTheme = (theme) => {
|
|
1990
|
+
if (theme)
|
|
1991
|
+
document.documentElement.dataset.theme = theme;
|
|
1992
|
+
else
|
|
1993
|
+
delete document.documentElement.dataset.theme;
|
|
1994
|
+
};
|
|
1995
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1996
|
+
if (storedTheme)
|
|
1997
|
+
setTheme(storedTheme);
|
|
1998
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1999
|
+
const current = document.documentElement.dataset.theme;
|
|
2000
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
2001
|
+
const next = dark ? "light" : "dark";
|
|
2002
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
2003
|
+
setTheme(next);
|
|
2004
|
+
});
|
|
2005
|
+
const show = (view) => {
|
|
2006
|
+
state.view = view;
|
|
2007
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
2008
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2009
|
+
continue;
|
|
2010
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
2011
|
+
}
|
|
2012
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
2013
|
+
if (!(section instanceof HTMLElement))
|
|
2014
|
+
continue;
|
|
2015
|
+
section.hidden = section.id !== `view-${view}`;
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
2019
|
+
const target = event.target;
|
|
2020
|
+
if (!(target instanceof Element))
|
|
2021
|
+
return;
|
|
2022
|
+
const button = target.closest("button[data-view]");
|
|
2023
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2024
|
+
return;
|
|
2025
|
+
const view = button.dataset.view;
|
|
2026
|
+
if (view === void 0)
|
|
2027
|
+
return;
|
|
2028
|
+
show(view);
|
|
2029
|
+
refresh().catch(showError);
|
|
2030
|
+
});
|
|
2031
|
+
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>`;
|
|
2032
|
+
const table = (columns, rows) => {
|
|
2033
|
+
if (rows.length === 0)
|
|
2034
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
2035
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
2036
|
+
const body = rows.map((row) => {
|
|
2037
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
2038
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
2039
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
2040
|
+
}).join("");
|
|
2041
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
2042
|
+
};
|
|
2043
|
+
const preview = (value) => {
|
|
2044
|
+
const text = JSON.stringify(value) ?? "null";
|
|
2045
|
+
return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
|
|
2046
|
+
};
|
|
2047
|
+
const when = (epoch) => {
|
|
2048
|
+
const date = new Date(epoch);
|
|
2049
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
2050
|
+
};
|
|
2051
|
+
const clockCard = (epoch) => {
|
|
2052
|
+
const date = new Date(epoch);
|
|
2053
|
+
if (Number.isNaN(date.getTime()))
|
|
2054
|
+
return esc(String(epoch));
|
|
2055
|
+
const iso = date.toISOString();
|
|
2056
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
2057
|
+
};
|
|
2058
|
+
const decodeClock = (value) => {
|
|
2059
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
2060
|
+
throw new Error("Clock response was not a clock");
|
|
2061
|
+
}
|
|
2062
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
2063
|
+
};
|
|
2064
|
+
const decodeField = (value) => {
|
|
2065
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
2066
|
+
return void 0;
|
|
2067
|
+
}
|
|
2068
|
+
const field = {
|
|
2069
|
+
name: value.name,
|
|
2070
|
+
kind: value.kind,
|
|
2071
|
+
optional: value.optional === true
|
|
2072
|
+
};
|
|
2073
|
+
if (typeof value.description === "string")
|
|
2074
|
+
field.description = value.description;
|
|
2075
|
+
if (Array.isArray(value.fields)) {
|
|
2076
|
+
field.fields = value.fields.flatMap((item) => {
|
|
2077
|
+
const child = decodeField(item);
|
|
2078
|
+
return child === void 0 ? [] : [child];
|
|
2079
|
+
});
|
|
2080
|
+
}
|
|
2081
|
+
return field;
|
|
2082
|
+
};
|
|
2083
|
+
const decodeCollection = (value) => {
|
|
2084
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
2085
|
+
return void 0;
|
|
2086
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
2087
|
+
const field = decodeField(item);
|
|
2088
|
+
return field === void 0 ? [] : [field];
|
|
2089
|
+
}) : [];
|
|
2090
|
+
const collection = {
|
|
2091
|
+
name: value.name,
|
|
2092
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
2093
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
2094
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
2095
|
+
fields
|
|
2096
|
+
};
|
|
2097
|
+
if (typeof value.description === "string")
|
|
2098
|
+
collection.description = value.description;
|
|
2099
|
+
return collection;
|
|
2100
|
+
};
|
|
2101
|
+
const decodeState = (value) => {
|
|
2102
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
2103
|
+
throw new Error("State response has no collection list");
|
|
2104
|
+
}
|
|
2105
|
+
return {
|
|
2106
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
2107
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
2108
|
+
collections: value.collections.flatMap((item) => {
|
|
2109
|
+
const collection = decodeCollection(item);
|
|
2110
|
+
return collection === void 0 ? [] : [collection];
|
|
2111
|
+
})
|
|
2112
|
+
};
|
|
2113
|
+
};
|
|
2114
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
2115
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
2116
|
+
return [];
|
|
2117
|
+
return [
|
|
2118
|
+
{
|
|
2119
|
+
id: item.id,
|
|
2120
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
2121
|
+
value: item.value,
|
|
2122
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
2123
|
+
}
|
|
2124
|
+
];
|
|
2125
|
+
});
|
|
2126
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
2127
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
2128
|
+
if (!isRecord2(item))
|
|
2129
|
+
return [];
|
|
2130
|
+
return [
|
|
2131
|
+
{
|
|
2132
|
+
at: textOf(item.at),
|
|
2133
|
+
method: textOf(item.method),
|
|
2134
|
+
path: textOf(item.path),
|
|
2135
|
+
status: textOf(item.status),
|
|
2136
|
+
durationMs: textOf(item.durationMs),
|
|
2137
|
+
operationId: textOf(item.operationId)
|
|
2138
|
+
}
|
|
2139
|
+
];
|
|
2140
|
+
});
|
|
2141
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
2142
|
+
if (!isRecord2(item))
|
|
2143
|
+
return [];
|
|
2144
|
+
return [
|
|
2145
|
+
{
|
|
2146
|
+
id: textOf(item.id),
|
|
2147
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
2148
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
2149
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
2150
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
2151
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
2152
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
2153
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
2154
|
+
}
|
|
2155
|
+
];
|
|
2156
|
+
});
|
|
2157
|
+
const loadNamespaces = async () => {
|
|
2158
|
+
const data = await api("GET", "/namespaces");
|
|
2159
|
+
const select = el("namespace", HTMLSelectElement);
|
|
2160
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
2161
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
2162
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
2163
|
+
if (!names.includes(state.namespace))
|
|
2164
|
+
names.unshift(state.namespace);
|
|
2165
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
2166
|
+
select.value = state.namespace;
|
|
2167
|
+
};
|
|
2168
|
+
const renderOverview = async () => {
|
|
2169
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
2170
|
+
originGet("/health"),
|
|
2171
|
+
api("GET", "/state"),
|
|
2172
|
+
api("GET", "/clock"),
|
|
2173
|
+
api("GET", "/requests?limit=8")
|
|
2174
|
+
]);
|
|
2175
|
+
if (!isRecord2(health))
|
|
2176
|
+
throw new Error("Health response was not an object");
|
|
2177
|
+
const decoded = decodeState(shape);
|
|
2178
|
+
state.shape = decoded;
|
|
2179
|
+
const time = decodeClock(clock);
|
|
2180
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
2181
|
+
{
|
|
2182
|
+
k: "Service",
|
|
2183
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
2184
|
+
},
|
|
2185
|
+
{
|
|
2186
|
+
k: "Status",
|
|
2187
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
2188
|
+
},
|
|
2189
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
2190
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
2191
|
+
{
|
|
2192
|
+
k: "Records",
|
|
2193
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
2194
|
+
},
|
|
2195
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
2196
|
+
]);
|
|
2197
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
2198
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2199
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2200
|
+
{
|
|
2201
|
+
label: "Status",
|
|
2202
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
2203
|
+
},
|
|
2204
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
2205
|
+
], decodeJournal(journal));
|
|
2206
|
+
};
|
|
2207
|
+
const schemaChips = (collection) => {
|
|
2208
|
+
if (collection.fields.length === 0) {
|
|
2209
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
2210
|
+
}
|
|
2211
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
2212
|
+
};
|
|
2213
|
+
const renderState = async () => {
|
|
2214
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
2215
|
+
state.shape = shape;
|
|
2216
|
+
const host = el("collections", HTMLElement);
|
|
2217
|
+
if (shape.collections.length === 0) {
|
|
2218
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
2219
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
2220
|
+
el("records", HTMLElement).innerHTML = "";
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
2224
|
+
const first = shape.collections[0];
|
|
2225
|
+
if (first === void 0)
|
|
2226
|
+
return;
|
|
2227
|
+
state.collection = first.name;
|
|
2228
|
+
}
|
|
2229
|
+
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("");
|
|
2230
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
2231
|
+
if (selected === void 0)
|
|
2232
|
+
return;
|
|
2233
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
2234
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
2235
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
2236
|
+
el("records", HTMLElement).innerHTML = table([
|
|
2237
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
2238
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
2239
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
2240
|
+
], decodeRecords(page));
|
|
2241
|
+
};
|
|
2242
|
+
const renderClock = async () => {
|
|
2243
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2244
|
+
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>`;
|
|
2245
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2246
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2247
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2248
|
+
};
|
|
2249
|
+
const renderFaults = async () => {
|
|
2250
|
+
const [faults, presets] = await Promise.all([
|
|
2251
|
+
api("GET", "/faults"),
|
|
2252
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2253
|
+
]);
|
|
2254
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2255
|
+
const current = select.value;
|
|
2256
|
+
const list = faultPresetList(presets).presets;
|
|
2257
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2258
|
+
select.value = current;
|
|
2259
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2260
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2261
|
+
{
|
|
2262
|
+
label: "Match",
|
|
2263
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2264
|
+
},
|
|
2265
|
+
{
|
|
2266
|
+
label: "Effect",
|
|
2267
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
2268
|
+
}
|
|
2269
|
+
], decodeFaults(faults));
|
|
2270
|
+
};
|
|
2271
|
+
const renderJournal = async () => {
|
|
2272
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2273
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2274
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
2275
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2276
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2277
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2278
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2279
|
+
], decodeJournal(journal));
|
|
2280
|
+
};
|
|
2281
|
+
const renderRoutes = async () => {
|
|
2282
|
+
const data = await api("GET", "/");
|
|
2283
|
+
if (!isRecord2(data))
|
|
2284
|
+
throw new Error("Route list was not an object");
|
|
2285
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2286
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2287
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2288
|
+
const parts = route.split(" ");
|
|
2289
|
+
const method = parts[0] ?? "";
|
|
2290
|
+
const path = parts.slice(1).join(" ");
|
|
2291
|
+
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>`;
|
|
2292
|
+
}).join("");
|
|
2293
|
+
};
|
|
2294
|
+
const renderers = {
|
|
2295
|
+
overview: renderOverview,
|
|
2296
|
+
state: renderState,
|
|
2297
|
+
clock: renderClock,
|
|
2298
|
+
faults: renderFaults,
|
|
2299
|
+
journal: renderJournal,
|
|
2300
|
+
routes: renderRoutes
|
|
2301
|
+
};
|
|
2302
|
+
async function refresh() {
|
|
2303
|
+
clearError();
|
|
2304
|
+
const render = renderers[state.view];
|
|
2305
|
+
if (render)
|
|
2306
|
+
await render();
|
|
2307
|
+
}
|
|
2308
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2309
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2310
|
+
refresh().catch(showError);
|
|
2311
|
+
});
|
|
2312
|
+
keyInput.addEventListener("change", () => {
|
|
2313
|
+
state.key = keyInput.value.trim();
|
|
2314
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2315
|
+
refresh().catch(showError);
|
|
2316
|
+
});
|
|
2317
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2318
|
+
refresh().catch(showError);
|
|
2319
|
+
});
|
|
2320
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2321
|
+
const target = event.target;
|
|
2322
|
+
if (!(target instanceof Element))
|
|
2323
|
+
return;
|
|
2324
|
+
const button = target.closest("[data-collection]");
|
|
2325
|
+
if (!(button instanceof HTMLElement))
|
|
2326
|
+
return;
|
|
2327
|
+
const collection = button.dataset.collection;
|
|
2328
|
+
if (collection === void 0)
|
|
2329
|
+
return;
|
|
2330
|
+
state.collection = collection;
|
|
2331
|
+
renderState().catch(showError);
|
|
2332
|
+
});
|
|
2333
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2334
|
+
const target = event.target;
|
|
2335
|
+
if (!(target instanceof Element))
|
|
2336
|
+
return;
|
|
2337
|
+
const row = target.closest("[data-id]");
|
|
2338
|
+
if (!(row instanceof HTMLElement))
|
|
2339
|
+
return;
|
|
2340
|
+
const id = row.dataset.id;
|
|
2341
|
+
if (id === void 0)
|
|
2342
|
+
return;
|
|
2343
|
+
openEditor(id).catch(showError);
|
|
2344
|
+
});
|
|
2345
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2346
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2347
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2348
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2349
|
+
async function openEditor(id) {
|
|
2350
|
+
state.editing = id;
|
|
2351
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2352
|
+
editorId.value = id ?? "";
|
|
2353
|
+
editorId.readOnly = id !== null;
|
|
2354
|
+
editorDelete.hidden = id === null;
|
|
2355
|
+
if (id) {
|
|
2356
|
+
const record2 = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2357
|
+
if (!isRecord2(record2))
|
|
2358
|
+
throw new Error("Record response was not an object");
|
|
2359
|
+
editorValue.value = JSON.stringify(record2.value, null, 2) ?? "";
|
|
2360
|
+
} else {
|
|
2361
|
+
editorValue.value = "{\n \n}";
|
|
2362
|
+
}
|
|
2363
|
+
editor.showModal();
|
|
2364
|
+
}
|
|
2365
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2366
|
+
openEditor(null).catch(showError);
|
|
2367
|
+
});
|
|
2368
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2369
|
+
const submitter = event.submitter;
|
|
2370
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2371
|
+
return;
|
|
2372
|
+
event.preventDefault();
|
|
2373
|
+
let value;
|
|
2374
|
+
try {
|
|
2375
|
+
value = readJson2(editorValue.value);
|
|
2376
|
+
} catch {
|
|
2377
|
+
showError(new Error("Value is not JSON"));
|
|
2378
|
+
return;
|
|
2379
|
+
}
|
|
2380
|
+
const id = editorId.value.trim();
|
|
2381
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2382
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2383
|
+
request.then(() => {
|
|
2384
|
+
editor.close();
|
|
2385
|
+
return renderState();
|
|
2386
|
+
}).catch(showError);
|
|
2387
|
+
});
|
|
2388
|
+
editorDelete.addEventListener("click", () => {
|
|
2389
|
+
const id = state.editing;
|
|
2390
|
+
if (!id)
|
|
2391
|
+
return;
|
|
2392
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2393
|
+
editor.close();
|
|
2394
|
+
return renderState();
|
|
2395
|
+
}).catch(showError);
|
|
2396
|
+
});
|
|
2397
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2398
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2399
|
+
continue;
|
|
2400
|
+
button.addEventListener("click", () => {
|
|
2401
|
+
const raw = button.dataset.advance;
|
|
2402
|
+
if (raw === void 0)
|
|
2403
|
+
return;
|
|
2404
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
2407
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2408
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2409
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2410
|
+
});
|
|
2411
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2412
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2413
|
+
});
|
|
2414
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2415
|
+
event.preventDefault();
|
|
2416
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2417
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2418
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2419
|
+
});
|
|
2420
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2421
|
+
event.preventDefault();
|
|
2422
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2423
|
+
if (preset !== "") {
|
|
2424
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2425
|
+
return;
|
|
2426
|
+
}
|
|
2427
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2428
|
+
if (!Number.isFinite(status)) {
|
|
2429
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2430
|
+
return;
|
|
2431
|
+
}
|
|
2432
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2433
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2434
|
+
api("POST", "/faults", {
|
|
2435
|
+
status,
|
|
2436
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2437
|
+
...method !== "" ? { method } : {}
|
|
2438
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2439
|
+
});
|
|
2440
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2441
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2442
|
+
});
|
|
2443
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2444
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2445
|
+
});
|
|
2446
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2447
|
+
const target = event.target;
|
|
2448
|
+
if (!(target instanceof Element))
|
|
2449
|
+
return;
|
|
2450
|
+
const button = target.closest("[data-route]");
|
|
2451
|
+
if (!(button instanceof HTMLElement))
|
|
2452
|
+
return;
|
|
2453
|
+
const route = button.dataset.route;
|
|
2454
|
+
if (route === void 0)
|
|
2455
|
+
return;
|
|
2456
|
+
state.route = route;
|
|
2457
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2458
|
+
const method = route.split(" ")[0] ?? "";
|
|
2459
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2460
|
+
});
|
|
2461
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2462
|
+
event.preventDefault();
|
|
2463
|
+
const send = async () => {
|
|
2464
|
+
if (state.route === null)
|
|
2465
|
+
throw new Error("Choose a route first");
|
|
2466
|
+
const parts = state.route.split(" ");
|
|
2467
|
+
const method = parts[0];
|
|
2468
|
+
const path = parts.slice(1).join(" ");
|
|
2469
|
+
if (method === void 0)
|
|
2470
|
+
throw new Error("Choose a route first");
|
|
2471
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2472
|
+
let body;
|
|
2473
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2474
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2475
|
+
try {
|
|
2476
|
+
body = readJson2(routeBody.value);
|
|
2477
|
+
} catch {
|
|
2478
|
+
throw new Error("Body is not JSON");
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
const data = await api(method, concrete, body);
|
|
2482
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2483
|
+
};
|
|
2484
|
+
send().catch(showError);
|
|
2485
|
+
});
|
|
2486
|
+
const decodePanel = (value) => {
|
|
2487
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2488
|
+
return void 0;
|
|
2489
|
+
}
|
|
2490
|
+
const panel = {
|
|
2491
|
+
id: value.id,
|
|
2492
|
+
title: value.title,
|
|
2493
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2494
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2495
|
+
};
|
|
2496
|
+
if (typeof value.script === "string")
|
|
2497
|
+
panel.script = value.script;
|
|
2498
|
+
return panel;
|
|
2499
|
+
};
|
|
2500
|
+
const mountPanels = (panels) => {
|
|
2501
|
+
const nav = el("nav", HTMLElement);
|
|
2502
|
+
const views = el("views", HTMLElement);
|
|
2503
|
+
for (const panel of panels) {
|
|
2504
|
+
const button = document.createElement("button");
|
|
2505
|
+
button.type = "button";
|
|
2506
|
+
button.dataset.view = panel.id;
|
|
2507
|
+
button.textContent = panel.title;
|
|
2508
|
+
nav.append(button);
|
|
2509
|
+
const section = document.createElement("section");
|
|
2510
|
+
section.className = "view";
|
|
2511
|
+
section.id = `view-${panel.id}`;
|
|
2512
|
+
section.hidden = true;
|
|
2513
|
+
const title = document.createElement("h2");
|
|
2514
|
+
title.textContent = panel.title;
|
|
2515
|
+
const lede = document.createElement("p");
|
|
2516
|
+
lede.className = "lede";
|
|
2517
|
+
lede.textContent = panel.description;
|
|
2518
|
+
const body = document.createElement("div");
|
|
2519
|
+
body.className = "panel-body";
|
|
2520
|
+
body.id = `panel-${panel.id}`;
|
|
2521
|
+
body.innerHTML = panel.html;
|
|
2522
|
+
section.append(title, lede, body);
|
|
2523
|
+
views.append(section);
|
|
2524
|
+
if (panel.script === void 0)
|
|
2525
|
+
continue;
|
|
2526
|
+
try {
|
|
2527
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2528
|
+
if (!isPanelScript(compiled))
|
|
2529
|
+
throw new Error("panel script did not compile");
|
|
2530
|
+
compiled(body, panelApi);
|
|
2531
|
+
} catch (error) {
|
|
2532
|
+
const note = document.createElement("p");
|
|
2533
|
+
note.className = "banner show";
|
|
2534
|
+
note.textContent = error instanceof Error ? error.message : String(error);
|
|
2535
|
+
body.append(note);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
};
|
|
2539
|
+
startAdminBrand({
|
|
2540
|
+
document,
|
|
2541
|
+
$: (id) => document.getElementById(id),
|
|
2542
|
+
params,
|
|
2543
|
+
location: { href: location.href, origin: location.origin },
|
|
2544
|
+
fetch,
|
|
2545
|
+
brandsUrl: config.brandsUrl
|
|
2546
|
+
});
|
|
2547
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2548
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2549
|
+
const decoded = decodePanel(panel);
|
|
2550
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2551
|
+
});
|
|
2552
|
+
mountPanels(panels);
|
|
2553
|
+
return refresh();
|
|
2554
|
+
}).catch(showError);
|
|
2555
|
+
}
|
|
2556
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2557
|
+
var adminClientSource = (config) => {
|
|
2558
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2559
|
+
return `<script>
|
|
2560
|
+
${clientPrelude}
|
|
2561
|
+
bootAdmin(${payload});
|
|
2562
|
+
</script>`;
|
|
2563
|
+
};
|
|
2564
|
+
|
|
2565
|
+
// ../core/dist/surface.js
|
|
2566
|
+
var defineMock = (runtime) => runtime;
|
|
2567
|
+
var STANDARD_ADMIN_ROUTES = [
|
|
2568
|
+
"GET /",
|
|
2569
|
+
"POST /reset",
|
|
2570
|
+
"GET /namespaces",
|
|
2571
|
+
"GET /clock",
|
|
2572
|
+
"POST /clock",
|
|
2573
|
+
"GET /faults",
|
|
2574
|
+
"POST /faults",
|
|
2575
|
+
"DELETE /faults",
|
|
2576
|
+
"POST /snapshots",
|
|
2577
|
+
"POST /snapshots/:id/restore",
|
|
2578
|
+
"DELETE /snapshots/:id",
|
|
2579
|
+
"GET /timeline",
|
|
2580
|
+
"POST /checkpoints",
|
|
2581
|
+
"POST /branches/:name",
|
|
2582
|
+
"POST /branches/:name/checkout",
|
|
2583
|
+
"GET /requests",
|
|
2584
|
+
"DELETE /requests",
|
|
2585
|
+
"GET /metrics",
|
|
2586
|
+
"DELETE /metrics",
|
|
2587
|
+
"GET /credentials",
|
|
2588
|
+
"PUT /credentials",
|
|
2589
|
+
"DELETE /credentials",
|
|
2590
|
+
"GET /state",
|
|
2591
|
+
"GET /state/:collection",
|
|
2592
|
+
"GET /state/:collection/:id",
|
|
2593
|
+
"POST /state/:collection",
|
|
2594
|
+
"PUT /state/:collection/:id",
|
|
2595
|
+
"PATCH /state/:collection/:id",
|
|
2596
|
+
"DELETE /state/:collection/:id",
|
|
2597
|
+
"GET /ui",
|
|
2598
|
+
"GET /ui/",
|
|
2599
|
+
"GET /ui/manifest"
|
|
2600
|
+
];
|
|
2601
|
+
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2602
|
+
var assertAdminUi = (ui) => {
|
|
2603
|
+
if (!ui?.panels)
|
|
2604
|
+
return;
|
|
2605
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2606
|
+
for (const panel of ui.panels) {
|
|
2607
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2608
|
+
throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2609
|
+
}
|
|
2610
|
+
if (seen.has(panel.id))
|
|
2611
|
+
throw new RangeError(`duplicate admin panel id ${panel.id}`);
|
|
2612
|
+
seen.add(panel.id);
|
|
2613
|
+
if (panel.title.trim() === "")
|
|
2614
|
+
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2615
|
+
}
|
|
2616
|
+
};
|
|
2617
|
+
|
|
2618
|
+
// ../core/dist/admin-ui.js
|
|
2619
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
2620
|
+
switch (char) {
|
|
2621
|
+
case "&":
|
|
2622
|
+
return "&";
|
|
2623
|
+
case "<":
|
|
2624
|
+
return "<";
|
|
2625
|
+
case ">":
|
|
2626
|
+
return ">";
|
|
2627
|
+
case '"':
|
|
2628
|
+
return """;
|
|
2629
|
+
default:
|
|
2630
|
+
return "'";
|
|
2631
|
+
}
|
|
2632
|
+
});
|
|
2633
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
2634
|
+
var renderAdminDocument = (service) => {
|
|
2635
|
+
const name = escapeHtml(service);
|
|
2636
|
+
const script = adminClientSource({
|
|
2637
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2638
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2639
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2640
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2641
|
+
service
|
|
2642
|
+
});
|
|
2643
|
+
return `<!DOCTYPE html>
|
|
2644
|
+
<html lang="en">
|
|
2645
|
+
<head>
|
|
2646
|
+
<meta charset="utf-8">
|
|
2647
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
2648
|
+
<meta name="color-scheme" content="light dark">
|
|
2649
|
+
<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">
|
|
2650
|
+
<title>${name} admin</title>
|
|
2651
|
+
<style>
|
|
2652
|
+
${CSS_RESET}
|
|
2653
|
+
:root {
|
|
2654
|
+
color-scheme: light;
|
|
2655
|
+
--bg: #fafafa;
|
|
2656
|
+
--bg-elev: #ffffff;
|
|
2657
|
+
--bg-muted: #f4f4f5;
|
|
2658
|
+
--bg-inset: #f4f4f5;
|
|
2659
|
+
--line: #dedee3;
|
|
2660
|
+
--line-strong: #c4c4cc;
|
|
2661
|
+
--ink: #18181b;
|
|
2662
|
+
--muted: #62626b;
|
|
2663
|
+
--faint: #71717a;
|
|
2664
|
+
--accent: #27272a;
|
|
2665
|
+
--accent-ink: #ffffff;
|
|
2666
|
+
--accent-soft: #f4f4f5;
|
|
2667
|
+
--ok: #166534;
|
|
2668
|
+
--ok-soft: #f0fdf4;
|
|
2669
|
+
--warn: #a16207;
|
|
2670
|
+
--warn-soft: #fefce8;
|
|
2671
|
+
--err: #a82d32;
|
|
2672
|
+
--err-soft: #fef2f2;
|
|
2673
|
+
--shadow: none;
|
|
2674
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2675
|
+
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
2676
|
+
--radius: 10px;
|
|
2677
|
+
--header: 56px;
|
|
2678
|
+
--nav: 200px;
|
|
2679
|
+
}
|
|
2680
|
+
:root[data-theme="dark"] {
|
|
2681
|
+
color-scheme: dark;
|
|
2682
|
+
--bg: #111113;
|
|
2683
|
+
--bg-elev: #19191c;
|
|
2684
|
+
--bg-muted: #242428;
|
|
2685
|
+
--bg-inset: #111113;
|
|
2686
|
+
--line: #36363c;
|
|
2687
|
+
--line-strong: #52525b;
|
|
2688
|
+
--ink: #f4f4f5;
|
|
2689
|
+
--muted: #a9a9b2;
|
|
2690
|
+
--faint: #71717a;
|
|
2691
|
+
--accent: #e4e4e7;
|
|
2692
|
+
--accent-ink: #18181b;
|
|
2693
|
+
--accent-soft: #242428;
|
|
2694
|
+
--ok: #86efac;
|
|
2695
|
+
--ok-soft: #14241b;
|
|
2696
|
+
--warn: #fde68a;
|
|
2697
|
+
--warn-soft: #2a2410;
|
|
2698
|
+
--err: #ffaaaa;
|
|
2699
|
+
--err-soft: #2c1516;
|
|
2700
|
+
--shadow: none;
|
|
2701
|
+
}
|
|
2702
|
+
@media (prefers-color-scheme: dark) {
|
|
2703
|
+
:root:not([data-theme="light"]) {
|
|
2704
|
+
color-scheme: dark;
|
|
2705
|
+
--bg: #111113;
|
|
2706
|
+
--bg-elev: #19191c;
|
|
2707
|
+
--bg-muted: #242428;
|
|
2708
|
+
--bg-inset: #111113;
|
|
2709
|
+
--line: #36363c;
|
|
2710
|
+
--line-strong: #52525b;
|
|
2711
|
+
--ink: #f4f4f5;
|
|
2712
|
+
--muted: #a9a9b2;
|
|
2713
|
+
--faint: #71717a;
|
|
2714
|
+
--accent: #e4e4e7;
|
|
2715
|
+
--accent-ink: #18181b;
|
|
2716
|
+
--accent-soft: #242428;
|
|
2717
|
+
--ok: #86efac;
|
|
2718
|
+
--ok-soft: #14241b;
|
|
2719
|
+
--warn: #fde68a;
|
|
2720
|
+
--warn-soft: #2a2410;
|
|
2721
|
+
--err: #ffaaaa;
|
|
2722
|
+
--err-soft: #2c1516;
|
|
2723
|
+
--shadow: none;
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2727
|
+
html { height: 100%; }
|
|
2728
|
+
body {
|
|
2729
|
+
margin: 0;
|
|
2730
|
+
min-height: 100%;
|
|
2731
|
+
display: flex;
|
|
2732
|
+
flex-direction: column;
|
|
2733
|
+
font-family: var(--sans);
|
|
2734
|
+
background: var(--bg);
|
|
2735
|
+
color: var(--ink);
|
|
2736
|
+
line-height: 1.45;
|
|
2737
|
+
padding-left: env(safe-area-inset-left);
|
|
2738
|
+
padding-right: env(safe-area-inset-right);
|
|
2739
|
+
-webkit-text-size-adjust: 100%;
|
|
2740
|
+
}
|
|
2741
|
+
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
2742
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
2743
|
+
header.top {
|
|
2744
|
+
position: sticky; top: 0; z-index: 5;
|
|
2745
|
+
display: flex; align-items: center; gap: 12px;
|
|
2746
|
+
min-height: var(--header); padding: 10px 16px;
|
|
2747
|
+
background: var(--bg-elev);
|
|
2748
|
+
border-bottom: 1px solid var(--line);
|
|
2749
|
+
min-width: 0; max-width: 100%;
|
|
2750
|
+
}
|
|
2751
|
+
.brand {
|
|
2752
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2753
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2754
|
+
}
|
|
2755
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2756
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2757
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2758
|
+
.vendor {
|
|
2759
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2760
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2761
|
+
}
|
|
2762
|
+
.vendor[hidden] { display: none; }
|
|
2763
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2764
|
+
.vendor img {
|
|
2765
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2766
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2767
|
+
}
|
|
2768
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2769
|
+
.vendor-sep { color: var(--faint); }
|
|
2770
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2771
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
2772
|
+
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
2773
|
+
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
2774
|
+
label.field input, label.field select, .controls input[type="password"] {
|
|
2775
|
+
background: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
|
|
2776
|
+
padding: 7px 8px; min-height: 36px;
|
|
2777
|
+
}
|
|
2778
|
+
.icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
|
|
2779
|
+
border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
|
|
2780
|
+
background: var(--bg-elev);
|
|
2781
|
+
}
|
|
2782
|
+
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
|
|
2783
|
+
.btn-quiet { background: transparent; }
|
|
2784
|
+
.btn-danger { color: var(--err); }
|
|
2785
|
+
/* minmax(0, 1fr): a 1fr column will not shrink below its content, so a long
|
|
2786
|
+
record or the full nav row would widen the page past the viewport. */
|
|
2787
|
+
.layout {
|
|
2788
|
+
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
2789
|
+
flex: 1 0 auto; min-width: 0;
|
|
2790
|
+
}
|
|
2791
|
+
nav.side {
|
|
2792
|
+
border-right: 1px solid var(--line); padding: 12px;
|
|
2793
|
+
display: flex; flex-direction: column; gap: 4px;
|
|
2794
|
+
background: var(--bg-elev);
|
|
2795
|
+
}
|
|
2796
|
+
nav.side button {
|
|
2797
|
+
text-align: left; border: 0; background: transparent; border-radius: 9px;
|
|
2798
|
+
padding: 9px 10px; min-height: 40px; color: var(--muted);
|
|
2799
|
+
}
|
|
2800
|
+
nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
|
|
2801
|
+
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
2802
|
+
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
2803
|
+
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
2804
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2805
|
+
.card {
|
|
2806
|
+
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
2807
|
+
padding: 14px 16px; box-shadow: var(--shadow);
|
|
2808
|
+
}
|
|
2809
|
+
.card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
|
|
2810
|
+
.card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
2811
|
+
.card .v .clock-time { font-size: 14px; color: var(--muted); }
|
|
2812
|
+
.split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
|
|
2813
|
+
.collection {
|
|
2814
|
+
width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
|
|
2815
|
+
border-radius: 10px; padding: 8px 10px; min-height: 44px;
|
|
2816
|
+
}
|
|
2817
|
+
.collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
|
|
2818
|
+
.collection small { display: block; color: var(--faint); }
|
|
2819
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
|
|
2820
|
+
.chip {
|
|
2821
|
+
font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
|
|
2822
|
+
border-radius: 999px; padding: 4px 8px;
|
|
2823
|
+
}
|
|
2824
|
+
.chip i { color: var(--faint); font-style: normal; }
|
|
2825
|
+
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2826
|
+
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2827
|
+
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
2828
|
+
tr.clickable { cursor: pointer; }
|
|
2829
|
+
tr.clickable:hover { background: var(--bg-muted); }
|
|
2830
|
+
pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
|
|
2831
|
+
pre {
|
|
2832
|
+
margin: 0; white-space: pre-wrap; word-break: break-word;
|
|
2833
|
+
background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
|
|
2834
|
+
}
|
|
2835
|
+
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
|
|
2836
|
+
.banner {
|
|
2837
|
+
display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
|
|
2838
|
+
background: var(--err-soft); color: var(--err);
|
|
2839
|
+
}
|
|
2840
|
+
.banner.show { display: block; }
|
|
2841
|
+
.empty { color: var(--muted); padding: 24px 8px; }
|
|
2842
|
+
dialog {
|
|
2843
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2844
|
+
color: var(--ink); width: min(640px, calc(100vw - 24px)); box-shadow: none;
|
|
2845
|
+
}
|
|
2846
|
+
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
2847
|
+
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
2848
|
+
textarea {
|
|
2849
|
+
width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
|
|
2850
|
+
border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
|
|
2851
|
+
font-family: var(--mono); font-size: 12px;
|
|
2852
|
+
}
|
|
2853
|
+
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
2854
|
+
.badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
|
|
2855
|
+
.badge.ok { background: var(--ok-soft); color: var(--ok); }
|
|
2856
|
+
.badge.warn { background: var(--warn-soft); color: var(--warn); }
|
|
2857
|
+
.status-2 { color: var(--ok); }
|
|
2858
|
+
.status-4, .status-5, .status-0 { color: var(--err); }
|
|
2859
|
+
.stack { display: flex; flex-direction: column; gap: 12px; }
|
|
2860
|
+
.route {
|
|
2861
|
+
display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
|
|
2862
|
+
padding: 8px 0; border-bottom: 1px solid var(--line);
|
|
2863
|
+
}
|
|
2864
|
+
.method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
|
|
2865
|
+
@media (max-width: 800px) {
|
|
2866
|
+
header.top {
|
|
2867
|
+
align-items: stretch; flex-direction: column;
|
|
2868
|
+
padding-top: max(10px, env(safe-area-inset-top));
|
|
2869
|
+
}
|
|
2870
|
+
input, select, textarea { font-size: 16px; }
|
|
2871
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
2872
|
+
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
2873
|
+
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
2874
|
+
nav.side {
|
|
2875
|
+
flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
|
|
2876
|
+
border-right: 0; border-bottom: 1px solid var(--line);
|
|
2877
|
+
padding: 8px;
|
|
2878
|
+
}
|
|
2879
|
+
nav.side button { white-space: nowrap; flex: none; }
|
|
2880
|
+
.split { grid-template-columns: minmax(0, 1fr); }
|
|
2881
|
+
main { padding: 14px; }
|
|
2882
|
+
table, thead, tbody, tr, th, td { display: block; }
|
|
2883
|
+
thead { display: none; }
|
|
2884
|
+
tr {
|
|
2885
|
+
border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px;
|
|
2886
|
+
background: var(--bg-elev); min-width: 0;
|
|
2887
|
+
}
|
|
2888
|
+
td {
|
|
2889
|
+
border: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px;
|
|
2890
|
+
min-width: 0; overflow-wrap: anywhere;
|
|
2891
|
+
}
|
|
2892
|
+
td::before { content: attr(data-label); color: var(--faint); font-size: 12px; flex: none; }
|
|
2893
|
+
.route { grid-template-columns: 72px 1fr; }
|
|
2894
|
+
.route button { grid-column: 1 / -1; }
|
|
2895
|
+
}
|
|
2896
|
+
</style>
|
|
2897
|
+
</head>
|
|
2898
|
+
<body>
|
|
2899
|
+
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
2900
|
+
<header class="top">
|
|
2901
|
+
<div class="brand">
|
|
2902
|
+
<div class="brand-id">
|
|
2903
|
+
<strong>${name}</strong>
|
|
2904
|
+
<span>Admin</span>
|
|
2905
|
+
</div>
|
|
2906
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
2907
|
+
</div>
|
|
2908
|
+
<div class="controls">
|
|
2909
|
+
<label class="field">Namespace
|
|
2910
|
+
<select id="namespace" aria-label="Namespace"></select>
|
|
2911
|
+
</label>
|
|
2912
|
+
<label class="field">Admin key
|
|
2913
|
+
<input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
|
|
2914
|
+
</label>
|
|
2915
|
+
<button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
|
|
2916
|
+
<button class="btn" id="refresh" type="button">Refresh</button>
|
|
2917
|
+
</div>
|
|
2918
|
+
</header>
|
|
2919
|
+
<div class="layout">
|
|
2920
|
+
<nav class="side" id="nav" aria-label="Admin sections">
|
|
2921
|
+
<button type="button" data-view="overview" aria-current="true">Overview</button>
|
|
2922
|
+
<button type="button" data-view="state">State</button>
|
|
2923
|
+
<button type="button" data-view="clock">Clock</button>
|
|
2924
|
+
<button type="button" data-view="faults">Faults</button>
|
|
2925
|
+
<button type="button" data-view="journal">Journal</button>
|
|
2926
|
+
<button type="button" data-view="routes">Routes</button>
|
|
2927
|
+
</nav>
|
|
2928
|
+
<main id="views">
|
|
2929
|
+
<p class="banner" id="banner" role="alert"></p>
|
|
2930
|
+
<section class="view" id="view-overview">
|
|
2931
|
+
<h2>Overview</h2>
|
|
2932
|
+
<p class="lede">Health, clock, and the collections this namespace is holding.</p>
|
|
2933
|
+
<div class="grid" id="overview-cards"></div>
|
|
2934
|
+
<h3>Recent requests</h3>
|
|
2935
|
+
<div id="overview-requests"></div>
|
|
2936
|
+
</section>
|
|
2937
|
+
<section class="view" id="view-state" hidden>
|
|
2938
|
+
<h2>State</h2>
|
|
2939
|
+
<p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
|
|
2940
|
+
<div class="split">
|
|
2941
|
+
<div id="collections"></div>
|
|
2942
|
+
<div>
|
|
2943
|
+
<div id="schema"></div>
|
|
2944
|
+
<div class="row-actions">
|
|
2945
|
+
<button class="btn-primary" id="new-record" type="button">New record</button>
|
|
2946
|
+
</div>
|
|
2947
|
+
<div id="records"></div>
|
|
2948
|
+
</div>
|
|
2949
|
+
</div>
|
|
2950
|
+
</section>
|
|
2951
|
+
<section class="view" id="view-clock" hidden>
|
|
2952
|
+
<h2>Clock</h2>
|
|
2953
|
+
<p class="lede">The clock every timestamp in this mock reads.</p>
|
|
2954
|
+
<div class="card" id="clock-readout"></div>
|
|
2955
|
+
<div class="row-actions">
|
|
2956
|
+
<button class="btn" type="button" data-advance="60000">+1m</button>
|
|
2957
|
+
<button class="btn" type="button" data-advance="900000">+15m</button>
|
|
2958
|
+
<button class="btn" type="button" data-advance="3600000">+1h</button>
|
|
2959
|
+
<button class="btn" type="button" data-advance="86400000">+1d</button>
|
|
2960
|
+
<button class="btn" type="button" data-advance="-3600000">\u22121h</button>
|
|
2961
|
+
<button class="btn" id="freeze" type="button">Freeze</button>
|
|
2962
|
+
<button class="btn-quiet" id="clock-reset" type="button">Reset</button>
|
|
2963
|
+
</div>
|
|
2964
|
+
<form id="clock-set" class="row-actions">
|
|
2965
|
+
<label class="field">Set instant
|
|
2966
|
+
<input id="clock-instant" type="text" placeholder="2026-01-01T00:00:00Z or epoch ms" size="32">
|
|
2967
|
+
</label>
|
|
2968
|
+
<button class="btn-primary" type="submit">Set</button>
|
|
2969
|
+
</form>
|
|
2970
|
+
</section>
|
|
2971
|
+
<section class="view" id="view-faults" hidden>
|
|
2972
|
+
<h2>Faults</h2>
|
|
2973
|
+
<p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
|
|
2974
|
+
<form id="fault-form" class="card stack">
|
|
2975
|
+
<label class="field">Preset
|
|
2976
|
+
<select id="fault-preset"><option value="">Custom rule</option></select>
|
|
2977
|
+
</label>
|
|
2978
|
+
<label class="field">Status
|
|
2979
|
+
<input id="fault-status" inputmode="numeric" placeholder="503">
|
|
2980
|
+
</label>
|
|
2981
|
+
<label class="field">Path prefix
|
|
2982
|
+
<input id="fault-path" placeholder="/v1">
|
|
2983
|
+
</label>
|
|
2984
|
+
<label class="field">Method
|
|
2985
|
+
<input id="fault-method" placeholder="GET">
|
|
2986
|
+
</label>
|
|
2987
|
+
<div class="dialog-actions">
|
|
2988
|
+
<button class="btn-primary" type="submit">Add fault</button>
|
|
2989
|
+
<button class="btn-danger" id="fault-clear" type="button">Clear all</button>
|
|
2990
|
+
</div>
|
|
2991
|
+
</form>
|
|
2992
|
+
<div id="fault-list"></div>
|
|
2993
|
+
</section>
|
|
2994
|
+
<section class="view" id="view-journal" hidden>
|
|
2995
|
+
<h2>Journal</h2>
|
|
2996
|
+
<p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
|
|
2997
|
+
<div class="row-actions">
|
|
2998
|
+
<button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
|
|
2999
|
+
</div>
|
|
3000
|
+
<div id="journal"></div>
|
|
3001
|
+
</section>
|
|
3002
|
+
<section class="view" id="view-routes" hidden>
|
|
3003
|
+
<h2>Routes</h2>
|
|
3004
|
+
<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>
|
|
3005
|
+
<div id="route-list"></div>
|
|
3006
|
+
<form id="route-form" class="card stack">
|
|
3007
|
+
<strong id="route-title">Select a route</strong>
|
|
3008
|
+
<label class="field">JSON body
|
|
3009
|
+
<textarea id="route-body" placeholder="{ }"></textarea>
|
|
3010
|
+
</label>
|
|
3011
|
+
<div class="dialog-actions">
|
|
3012
|
+
<button class="btn-primary" type="submit">Send</button>
|
|
3013
|
+
</div>
|
|
3014
|
+
<pre id="route-result">Response will show here.</pre>
|
|
3015
|
+
</form>
|
|
3016
|
+
</section>
|
|
3017
|
+
</main>
|
|
3018
|
+
</div>
|
|
3019
|
+
</div>
|
|
3020
|
+
<dialog id="editor">
|
|
3021
|
+
<form method="dialog" id="editor-form">
|
|
3022
|
+
<strong id="editor-title">Record</strong>
|
|
3023
|
+
<label class="field">Id
|
|
3024
|
+
<input id="editor-id" required>
|
|
3025
|
+
</label>
|
|
3026
|
+
<label class="field">JSON value
|
|
3027
|
+
<textarea id="editor-value"></textarea>
|
|
3028
|
+
</label>
|
|
3029
|
+
<div class="dialog-actions">
|
|
3030
|
+
<button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
|
|
3031
|
+
<button class="btn-quiet" type="submit" value="cancel">Cancel</button>
|
|
3032
|
+
<button class="btn-primary" type="submit" value="save">Save</button>
|
|
3033
|
+
</div>
|
|
3034
|
+
</form>
|
|
3035
|
+
</dialog>
|
|
3036
|
+
${script}
|
|
3037
|
+
</body>
|
|
3038
|
+
</html>`;
|
|
3039
|
+
};
|
|
3040
|
+
var htmlResponse = (body) => new Response(body, {
|
|
3041
|
+
status: 200,
|
|
3042
|
+
headers: {
|
|
3043
|
+
"content-type": "text/html; charset=utf-8",
|
|
3044
|
+
"cache-control": "no-store"
|
|
3045
|
+
}
|
|
3046
|
+
});
|
|
3047
|
+
var json2 = (body) => new Response(JSON.stringify(body), {
|
|
3048
|
+
status: 200,
|
|
3049
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3050
|
+
});
|
|
3051
|
+
var adminUiRoutes = (service, ui) => {
|
|
3052
|
+
const shell = () => renderAdminDocument(service);
|
|
3053
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
3054
|
+
return {
|
|
3055
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
3056
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
3057
|
+
"GET /ui/manifest": () => json2({
|
|
3058
|
+
service,
|
|
3059
|
+
panels: (ui?.panels ?? []).map((panel) => ({
|
|
3060
|
+
id: panel.id,
|
|
3061
|
+
title: panel.title,
|
|
3062
|
+
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
3063
|
+
html: panel.html,
|
|
3064
|
+
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
3065
|
+
}))
|
|
3066
|
+
})
|
|
3067
|
+
};
|
|
3068
|
+
};
|
|
3069
|
+
|
|
1337
3070
|
// ../../openapi/metadata/dist/types.js
|
|
1338
3071
|
var EXTENSION_KEYS = {
|
|
1339
3072
|
operation: "x-mockingbird",
|
|
@@ -1346,11 +3079,11 @@ var EXTENSION_KEYS = {
|
|
|
1346
3079
|
};
|
|
1347
3080
|
|
|
1348
3081
|
// ../../openapi/metadata/dist/read.js
|
|
1349
|
-
var
|
|
3082
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1350
3083
|
var extensionOf = (holder, key) => holder[key];
|
|
1351
3084
|
var operationMetadata = (operation) => {
|
|
1352
3085
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
1353
|
-
const ext =
|
|
3086
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
1354
3087
|
const supported = ext.supported ?? true;
|
|
1355
3088
|
const parity = ext.parity ?? {};
|
|
1356
3089
|
return {
|
|
@@ -1470,9 +3203,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
1470
3203
|
this.name = "OperationRegistryError";
|
|
1471
3204
|
}
|
|
1472
3205
|
};
|
|
1473
|
-
var verifyOperations = (
|
|
3206
|
+
var verifyOperations = (document3, handlers) => {
|
|
1474
3207
|
const problems = [];
|
|
1475
|
-
const operations = listOperations(
|
|
3208
|
+
const operations = listOperations(document3);
|
|
1476
3209
|
const seen = /* @__PURE__ */ new Set();
|
|
1477
3210
|
for (const operation of operations) {
|
|
1478
3211
|
if (seen.has(operation.operationId))
|
|
@@ -1581,8 +3314,442 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
|
|
|
1581
3314
|
});
|
|
1582
3315
|
};
|
|
1583
3316
|
|
|
3317
|
+
// ../core/dist/state-view.js
|
|
3318
|
+
var COLLECTION_NAME = /^[A-Za-z0-9_.@:-]{1,200}$/;
|
|
3319
|
+
var RECORD_ID = /^[^\s/]{1,256}$/;
|
|
3320
|
+
var SAMPLE = 25;
|
|
3321
|
+
var WALK_LIMIT = 1e4;
|
|
3322
|
+
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
3323
|
+
var fail = (status, message) => ({ ok: false, status, message });
|
|
3324
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3325
|
+
var kindOf = (value) => {
|
|
3326
|
+
if (value === null)
|
|
3327
|
+
return "null";
|
|
3328
|
+
if (Array.isArray(value))
|
|
3329
|
+
return "array";
|
|
3330
|
+
switch (typeof value) {
|
|
3331
|
+
case "string":
|
|
3332
|
+
return "string";
|
|
3333
|
+
case "number":
|
|
3334
|
+
return Number.isFinite(value) ? "number" : "unknown";
|
|
3335
|
+
case "boolean":
|
|
3336
|
+
return "boolean";
|
|
3337
|
+
case "object":
|
|
3338
|
+
return "object";
|
|
3339
|
+
default:
|
|
3340
|
+
return "unknown";
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
var humanize = (name) => {
|
|
3344
|
+
const words = name.replace(/[@:_-]+/g, " ").trim();
|
|
3345
|
+
if (words === "")
|
|
3346
|
+
return name;
|
|
3347
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
3348
|
+
};
|
|
3349
|
+
var jsonValue = (value) => {
|
|
3350
|
+
if (value === void 0)
|
|
3351
|
+
return fail(400, "value is required");
|
|
3352
|
+
try {
|
|
3353
|
+
return { ok: true, value: JSON.parse(JSON.stringify(value)) };
|
|
3354
|
+
} catch {
|
|
3355
|
+
return fail(400, "value must be JSON");
|
|
3356
|
+
}
|
|
3357
|
+
};
|
|
3358
|
+
var ctorName = (value) => {
|
|
3359
|
+
const ctor = value.constructor;
|
|
3360
|
+
return typeof ctor?.name === "string" ? ctor.name : "";
|
|
3361
|
+
};
|
|
3362
|
+
var isSqlite = (value) => "prepare" in value && typeof value.prepare === "function" && "transaction" in value;
|
|
3363
|
+
var discoverCollections = (root) => {
|
|
3364
|
+
const found = [];
|
|
3365
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3366
|
+
const visit = (value, depth) => {
|
|
3367
|
+
if (found.length + seen.size > WALK_LIMIT)
|
|
3368
|
+
return;
|
|
3369
|
+
if (value === null || typeof value !== "object")
|
|
3370
|
+
return;
|
|
3371
|
+
if (seen.has(value))
|
|
3372
|
+
return;
|
|
3373
|
+
seen.add(value);
|
|
3374
|
+
if (value instanceof Collection) {
|
|
3375
|
+
found.push(value);
|
|
3376
|
+
return;
|
|
3377
|
+
}
|
|
3378
|
+
if (value instanceof Map) {
|
|
3379
|
+
for (const child of value.values())
|
|
3380
|
+
visit(child, depth + 1);
|
|
3381
|
+
return;
|
|
3382
|
+
}
|
|
3383
|
+
if (value instanceof Set) {
|
|
3384
|
+
for (const child of value.values())
|
|
3385
|
+
visit(child, depth + 1);
|
|
3386
|
+
return;
|
|
3387
|
+
}
|
|
3388
|
+
if (depth > 6 || isSqlite(value) || SKIP_CTORS.has(ctorName(value)))
|
|
3389
|
+
return;
|
|
3390
|
+
if (Array.isArray(value)) {
|
|
3391
|
+
const cap = Math.min(value.length, 32);
|
|
3392
|
+
for (let i = 0; i < cap; i++)
|
|
3393
|
+
visit(value[i], depth + 1);
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
let children;
|
|
3397
|
+
try {
|
|
3398
|
+
children = Object.values(value);
|
|
3399
|
+
} catch {
|
|
3400
|
+
return;
|
|
3401
|
+
}
|
|
3402
|
+
for (const child of children)
|
|
3403
|
+
visit(child, depth + 1);
|
|
3404
|
+
};
|
|
3405
|
+
visit(root, 0);
|
|
3406
|
+
return found;
|
|
3407
|
+
};
|
|
3408
|
+
var storedNames = (sqlite, namespace) => {
|
|
3409
|
+
const records = sqlite.prepare("SELECT DISTINCT collection AS name FROM mockingbird_records WHERE namespace = ?").all(namespace);
|
|
3410
|
+
const sequences = sqlite.prepare("SELECT DISTINCT name FROM mockingbird_sequences WHERE namespace = ? AND kind = 'collection'").all(namespace);
|
|
3411
|
+
return [...records, ...sequences].map((row) => row.name);
|
|
3412
|
+
};
|
|
3413
|
+
var blankAccum = (name) => ({
|
|
3414
|
+
name,
|
|
3415
|
+
kinds: /* @__PURE__ */ new Set(),
|
|
3416
|
+
present: 0,
|
|
3417
|
+
nested: /* @__PURE__ */ new Map()
|
|
3418
|
+
});
|
|
3419
|
+
var absorb = (accum, value) => {
|
|
3420
|
+
const kind = kindOf(value);
|
|
3421
|
+
accum.kinds.add(kind);
|
|
3422
|
+
accum.present++;
|
|
3423
|
+
if (!isRecord4(value))
|
|
3424
|
+
return;
|
|
3425
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3426
|
+
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
3427
|
+
absorb(nested, child);
|
|
3428
|
+
accum.nested.set(key, nested);
|
|
3429
|
+
}
|
|
3430
|
+
};
|
|
3431
|
+
var finishField = (accum, samples) => {
|
|
3432
|
+
const kinds = [...accum.kinds];
|
|
3433
|
+
const kind = kinds.length === 1 ? kinds[0] : "unknown";
|
|
3434
|
+
const field = {
|
|
3435
|
+
name: accum.name,
|
|
3436
|
+
kind,
|
|
3437
|
+
optional: accum.present < samples || kinds.includes("null")
|
|
3438
|
+
};
|
|
3439
|
+
if (accum.nested.size > 0) {
|
|
3440
|
+
field.fields = [...accum.nested.values()].sort((a, b) => a.name.localeCompare(b.name)).map((child) => finishField(child, accum.present));
|
|
3441
|
+
}
|
|
3442
|
+
return field;
|
|
3443
|
+
};
|
|
3444
|
+
var inferFields = (records) => {
|
|
3445
|
+
if (records.length === 0)
|
|
3446
|
+
return [];
|
|
3447
|
+
const sample = records.slice(0, SAMPLE);
|
|
3448
|
+
const objects = sample.filter((record2) => isRecord4(record2.value));
|
|
3449
|
+
if (objects.length === 0) {
|
|
3450
|
+
const kinds = new Set(sample.map((record2) => kindOf(record2.value)));
|
|
3451
|
+
const list = [...kinds];
|
|
3452
|
+
return [
|
|
3453
|
+
{
|
|
3454
|
+
name: "(value)",
|
|
3455
|
+
kind: list.length === 1 ? list[0] : "unknown",
|
|
3456
|
+
optional: false
|
|
3457
|
+
}
|
|
3458
|
+
];
|
|
3459
|
+
}
|
|
3460
|
+
const root = /* @__PURE__ */ new Map();
|
|
3461
|
+
for (const record2 of objects) {
|
|
3462
|
+
for (const [key, value] of Object.entries(record2.value)) {
|
|
3463
|
+
const accum = root.get(key) ?? blankAccum(key);
|
|
3464
|
+
absorb(accum, value);
|
|
3465
|
+
root.set(key, accum);
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
return [...root.values()].sort((a, b) => a.name.localeCompare(b.name)).map((accum) => finishField(accum, objects.length));
|
|
3469
|
+
};
|
|
3470
|
+
var mergeFields = (declared, inferred) => {
|
|
3471
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3472
|
+
for (const field of inferred)
|
|
3473
|
+
byName.set(field.name, field);
|
|
3474
|
+
const ordered = [];
|
|
3475
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3476
|
+
for (const field of declared ?? []) {
|
|
3477
|
+
const found = byName.get(field.name);
|
|
3478
|
+
seen.add(field.name);
|
|
3479
|
+
if (!found) {
|
|
3480
|
+
ordered.push({ ...field, optional: field.optional });
|
|
3481
|
+
continue;
|
|
3482
|
+
}
|
|
3483
|
+
ordered.push({
|
|
3484
|
+
...found,
|
|
3485
|
+
kind: field.kind === "unknown" ? found.kind : field.kind,
|
|
3486
|
+
optional: field.optional || found.optional,
|
|
3487
|
+
...field.description !== void 0 ? { description: field.description } : {},
|
|
3488
|
+
...field.meta !== void 0 ? { meta: field.meta } : {},
|
|
3489
|
+
...field.fields !== void 0 ? { fields: mergeFields(field.fields, found.fields ?? []) } : {}
|
|
3490
|
+
});
|
|
3491
|
+
}
|
|
3492
|
+
for (const field of inferred) {
|
|
3493
|
+
if (!seen.has(field.name))
|
|
3494
|
+
ordered.push(field);
|
|
3495
|
+
}
|
|
3496
|
+
return ordered;
|
|
3497
|
+
};
|
|
3498
|
+
var collectionOf = (sqlite, namespace, name) => new Collection(sqlite, namespace, name);
|
|
3499
|
+
var readRecord = (collection, id) => {
|
|
3500
|
+
const rows = collection.list({ where: (_value, _seq) => true, order: "oldest" });
|
|
3501
|
+
const row = rows.find((entry) => entry.id === id);
|
|
3502
|
+
return row ? { id: row.id, seq: row.seq, value: row.value } : void 0;
|
|
3503
|
+
};
|
|
3504
|
+
var inspectState = (scope) => {
|
|
3505
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3506
|
+
for (const declaration of scope.declarations ?? []) {
|
|
3507
|
+
if (COLLECTION_NAME.test(declaration.name))
|
|
3508
|
+
declared.set(declaration.name, declaration);
|
|
3509
|
+
}
|
|
3510
|
+
const names = new Set(declared.keys());
|
|
3511
|
+
for (const name of storedNames(scope.sqlite, scope.storageNamespace))
|
|
3512
|
+
names.add(name);
|
|
3513
|
+
for (const collection of discoverCollections(scope.root)) {
|
|
3514
|
+
if (collection.namespace === scope.storageNamespace)
|
|
3515
|
+
names.add(collection.collectionName);
|
|
3516
|
+
}
|
|
3517
|
+
const collections = [];
|
|
3518
|
+
for (const name of names) {
|
|
3519
|
+
if (!COLLECTION_NAME.test(name))
|
|
3520
|
+
continue;
|
|
3521
|
+
const declaration = declared.get(name);
|
|
3522
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3523
|
+
const records = collection.list({ order: "newest" }).slice(0, SAMPLE).map((row) => ({ id: row.id, seq: row.seq, value: row.value }));
|
|
3524
|
+
const inferred = inferFields(records);
|
|
3525
|
+
const fields = mergeFields(declaration?.fields, inferred);
|
|
3526
|
+
const source = declaration && records.length > 0 ? "mixed" : declaration ? "declared" : "inferred";
|
|
3527
|
+
collections.push({
|
|
3528
|
+
name,
|
|
3529
|
+
label: declaration?.label ?? humanize(name),
|
|
3530
|
+
...declaration?.description !== void 0 ? { description: declaration.description } : {},
|
|
3531
|
+
count: collection.count(),
|
|
3532
|
+
source,
|
|
3533
|
+
fields,
|
|
3534
|
+
...declaration?.meta !== void 0 ? { meta: declaration.meta } : {}
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3537
|
+
const order = /* @__PURE__ */ new Map();
|
|
3538
|
+
for (const [index, item] of (scope.declarations ?? []).entries())
|
|
3539
|
+
order.set(item.name, index);
|
|
3540
|
+
collections.sort((a, b) => {
|
|
3541
|
+
const left = order.get(a.name);
|
|
3542
|
+
const right = order.get(b.name);
|
|
3543
|
+
if (left !== void 0 && right !== void 0)
|
|
3544
|
+
return left - right;
|
|
3545
|
+
if (left !== void 0)
|
|
3546
|
+
return -1;
|
|
3547
|
+
if (right !== void 0)
|
|
3548
|
+
return 1;
|
|
3549
|
+
return a.name.localeCompare(b.name);
|
|
3550
|
+
});
|
|
3551
|
+
return {
|
|
3552
|
+
namespace: scope.namespace,
|
|
3553
|
+
storageNamespace: scope.storageNamespace,
|
|
3554
|
+
collections
|
|
3555
|
+
};
|
|
3556
|
+
};
|
|
3557
|
+
var pageOf = (sqlite, storageNamespace, name, query) => {
|
|
3558
|
+
if (!COLLECTION_NAME.test(name))
|
|
3559
|
+
return fail(400, "collection name is not allowed");
|
|
3560
|
+
const limit = query.limit ?? 50;
|
|
3561
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 200) {
|
|
3562
|
+
return fail(400, "limit must be an integer from 1 to 200");
|
|
3563
|
+
}
|
|
3564
|
+
const order = query.order ?? "newest";
|
|
3565
|
+
if (order !== "newest" && order !== "oldest")
|
|
3566
|
+
return fail(400, 'order must be "newest" or "oldest"');
|
|
3567
|
+
const collection = collectionOf(sqlite, storageNamespace, name);
|
|
3568
|
+
const rows = collection.list({ order }).filter((row) => {
|
|
3569
|
+
if (query.after === void 0)
|
|
3570
|
+
return true;
|
|
3571
|
+
return order === "newest" ? row.seq < query.after : row.seq > query.after;
|
|
3572
|
+
});
|
|
3573
|
+
const slice = rows.slice(0, limit);
|
|
3574
|
+
const last = slice.at(-1);
|
|
3575
|
+
return {
|
|
3576
|
+
ok: true,
|
|
3577
|
+
value: {
|
|
3578
|
+
collection: name,
|
|
3579
|
+
count: collection.count(),
|
|
3580
|
+
records: slice.map((row) => ({ id: row.id, seq: row.seq, value: row.value })),
|
|
3581
|
+
next: rows.length > limit && last ? last.seq : null
|
|
3582
|
+
}
|
|
3583
|
+
};
|
|
3584
|
+
};
|
|
3585
|
+
var readStatePage = (scope, name, query = {}) => pageOf(scope.sqlite, scope.storageNamespace, name, query);
|
|
3586
|
+
var readStateRecord = (scope, name, id) => {
|
|
3587
|
+
if (!COLLECTION_NAME.test(name))
|
|
3588
|
+
return fail(400, "collection name is not allowed");
|
|
3589
|
+
if (!RECORD_ID.test(id))
|
|
3590
|
+
return fail(400, "record id is not allowed");
|
|
3591
|
+
const record2 = readRecord(collectionOf(scope.sqlite, scope.storageNamespace, name), id);
|
|
3592
|
+
return record2 ? { ok: true, value: record2 } : fail(404, `no record ${id} in ${name}`);
|
|
3593
|
+
};
|
|
3594
|
+
var requireId = (id) => RECORD_ID.test(id) ? { ok: true, value: id } : fail(400, "id must be a single path segment");
|
|
3595
|
+
var createStateRecord = (scope, name, input) => {
|
|
3596
|
+
if (!COLLECTION_NAME.test(name))
|
|
3597
|
+
return fail(400, "collection name is not allowed");
|
|
3598
|
+
const parsed = jsonValue(input.value);
|
|
3599
|
+
if (!parsed.ok)
|
|
3600
|
+
return parsed;
|
|
3601
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3602
|
+
const id = input.id ?? `${name}_${collection.nextSequence()}`;
|
|
3603
|
+
const checked = requireId(id);
|
|
3604
|
+
if (!checked.ok)
|
|
3605
|
+
return checked;
|
|
3606
|
+
if (collection.has(checked.value))
|
|
3607
|
+
return fail(409, `record ${checked.value} already exists`);
|
|
3608
|
+
const stored = collection.insert(checked.value, parsed.value);
|
|
3609
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3610
|
+
};
|
|
3611
|
+
var replaceStateRecord = (scope, name, id, value) => {
|
|
3612
|
+
if (!COLLECTION_NAME.test(name))
|
|
3613
|
+
return fail(400, "collection name is not allowed");
|
|
3614
|
+
const checked = requireId(id);
|
|
3615
|
+
if (!checked.ok)
|
|
3616
|
+
return checked;
|
|
3617
|
+
const parsed = jsonValue(value);
|
|
3618
|
+
if (!parsed.ok)
|
|
3619
|
+
return parsed;
|
|
3620
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3621
|
+
if (!collection.has(checked.value))
|
|
3622
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3623
|
+
const stored = collection.update(checked.value, parsed.value);
|
|
3624
|
+
if (!stored)
|
|
3625
|
+
return fail(404, `no record ${checked.value} in ${name}`);
|
|
3626
|
+
return { ok: true, value: { id: checked.value, seq: stored.seq, value: stored.value } };
|
|
3627
|
+
};
|
|
3628
|
+
var patchStateRecord = (scope, name, id, value) => {
|
|
3629
|
+
const current = readStateRecord(scope, name, id);
|
|
3630
|
+
if (!current.ok)
|
|
3631
|
+
return current;
|
|
3632
|
+
const parsed = jsonValue(value);
|
|
3633
|
+
if (!parsed.ok)
|
|
3634
|
+
return parsed;
|
|
3635
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
3636
|
+
return replaceStateRecord(scope, name, id, next);
|
|
3637
|
+
};
|
|
3638
|
+
var deleteStateRecord = (scope, name, id) => {
|
|
3639
|
+
if (!COLLECTION_NAME.test(name))
|
|
3640
|
+
return fail(400, "collection name is not allowed");
|
|
3641
|
+
const checked = requireId(id);
|
|
3642
|
+
if (!checked.ok)
|
|
3643
|
+
return checked;
|
|
3644
|
+
const collection = collectionOf(scope.sqlite, scope.storageNamespace, name);
|
|
3645
|
+
return collection.delete(checked.value) ? { ok: true, value: { id: checked.value } } : fail(404, `no record ${checked.value} in ${name}`);
|
|
3646
|
+
};
|
|
3647
|
+
var json3 = (status, body) => new Response(JSON.stringify(body), {
|
|
3648
|
+
status,
|
|
3649
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3650
|
+
});
|
|
3651
|
+
var adminError2 = (status, message) => json3(status, { error: { type: "mockingbird_admin", message } });
|
|
3652
|
+
var fromResult = (result, status) => result.ok ? json3(status, result.value) : adminError2(result.status, result.message);
|
|
3653
|
+
var integerParam = (value) => {
|
|
3654
|
+
if (value === null)
|
|
3655
|
+
return void 0;
|
|
3656
|
+
if (!/^-?\d+$/.test(value))
|
|
3657
|
+
return "bad";
|
|
3658
|
+
return Number(value);
|
|
3659
|
+
};
|
|
3660
|
+
var stateAdminRoutes = (routes) => {
|
|
3661
|
+
const open = (namespace) => {
|
|
3662
|
+
try {
|
|
3663
|
+
return { ok: true, value: routes.open(namespace) };
|
|
3664
|
+
} catch (error) {
|
|
3665
|
+
return fail(400, error instanceof Error ? error.message : String(error));
|
|
3666
|
+
}
|
|
3667
|
+
};
|
|
3668
|
+
const wrote = (namespace) => {
|
|
3669
|
+
routes.afterWrite?.(namespace);
|
|
3670
|
+
};
|
|
3671
|
+
return {
|
|
3672
|
+
"GET /state": ({ namespace }) => {
|
|
3673
|
+
const scope = open(namespace);
|
|
3674
|
+
return fromResult(scope.ok ? { ok: true, value: inspectState(scope.value) } : scope, 200);
|
|
3675
|
+
},
|
|
3676
|
+
"GET /state/:collection": ({ namespace, params, url }) => {
|
|
3677
|
+
const scope = open(namespace);
|
|
3678
|
+
if (!scope.ok)
|
|
3679
|
+
return fromResult(scope, 200);
|
|
3680
|
+
const limit = integerParam(url.searchParams.get("limit"));
|
|
3681
|
+
const after = integerParam(url.searchParams.get("after"));
|
|
3682
|
+
if (limit === "bad")
|
|
3683
|
+
return adminError2(400, "limit: expected an integer");
|
|
3684
|
+
if (after === "bad")
|
|
3685
|
+
return adminError2(400, "after: expected a sequence number");
|
|
3686
|
+
const order = url.searchParams.get("order");
|
|
3687
|
+
return fromResult(readStatePage(scope.value, params.collection ?? "", {
|
|
3688
|
+
...limit !== void 0 ? { limit } : {},
|
|
3689
|
+
...after !== void 0 ? { after } : {},
|
|
3690
|
+
...order === "newest" || order === "oldest" ? { order } : {}
|
|
3691
|
+
}), 200);
|
|
3692
|
+
},
|
|
3693
|
+
"GET /state/:collection/:id": ({ namespace, params }) => {
|
|
3694
|
+
const scope = open(namespace);
|
|
3695
|
+
if (!scope.ok)
|
|
3696
|
+
return fromResult(scope, 200);
|
|
3697
|
+
return fromResult(readStateRecord(scope.value, params.collection ?? "", params.id ?? ""), 200);
|
|
3698
|
+
},
|
|
3699
|
+
"POST /state/:collection": ({ namespace, params, body }) => {
|
|
3700
|
+
const scope = open(namespace);
|
|
3701
|
+
if (!scope.ok)
|
|
3702
|
+
return fromResult(scope, 201);
|
|
3703
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
3704
|
+
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
3705
|
+
}
|
|
3706
|
+
const id = body.id;
|
|
3707
|
+
if (id !== void 0 && typeof id !== "string")
|
|
3708
|
+
return adminError2(400, "id must be a string");
|
|
3709
|
+
const created = createStateRecord(scope.value, params.collection ?? "", {
|
|
3710
|
+
...typeof id === "string" ? { id } : {},
|
|
3711
|
+
value: body.value
|
|
3712
|
+
});
|
|
3713
|
+
if (created.ok)
|
|
3714
|
+
wrote(namespace);
|
|
3715
|
+
return fromResult(created, 201);
|
|
3716
|
+
},
|
|
3717
|
+
"PUT /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3718
|
+
const scope = open(namespace);
|
|
3719
|
+
if (!scope.ok)
|
|
3720
|
+
return fromResult(scope, 200);
|
|
3721
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3722
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3723
|
+
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3724
|
+
if (replaced.ok)
|
|
3725
|
+
wrote(namespace);
|
|
3726
|
+
return fromResult(replaced, 200);
|
|
3727
|
+
},
|
|
3728
|
+
"PATCH /state/:collection/:id": ({ namespace, params, body }) => {
|
|
3729
|
+
const scope = open(namespace);
|
|
3730
|
+
if (!scope.ok)
|
|
3731
|
+
return fromResult(scope, 200);
|
|
3732
|
+
if (!isRecord4(body) || !("value" in body))
|
|
3733
|
+
return adminError2(400, 'expected {"value": <json>}');
|
|
3734
|
+
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
3735
|
+
if (patched.ok)
|
|
3736
|
+
wrote(namespace);
|
|
3737
|
+
return fromResult(patched, 200);
|
|
3738
|
+
},
|
|
3739
|
+
"DELETE /state/:collection/:id": ({ namespace, params }) => {
|
|
3740
|
+
const scope = open(namespace);
|
|
3741
|
+
if (!scope.ok)
|
|
3742
|
+
return fromResult(scope, 200);
|
|
3743
|
+
const removed = deleteStateRecord(scope.value, params.collection ?? "", params.id ?? "");
|
|
3744
|
+
if (removed.ok)
|
|
3745
|
+
wrote(namespace);
|
|
3746
|
+
return fromResult(removed, 200);
|
|
3747
|
+
}
|
|
3748
|
+
};
|
|
3749
|
+
};
|
|
3750
|
+
|
|
1584
3751
|
// ../core/dist/version.js
|
|
1585
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3752
|
+
var PACKAGE_VERSION = true ? "1.6.0" : UNRELEASED_VERSION;
|
|
1586
3753
|
|
|
1587
3754
|
// ../core/dist/signing.js
|
|
1588
3755
|
var encoder = new TextEncoder();
|
|
@@ -1917,11 +4084,11 @@ var createWebhookHub = (options) => {
|
|
|
1917
4084
|
};
|
|
1918
4085
|
return hub;
|
|
1919
4086
|
};
|
|
1920
|
-
var
|
|
1921
|
-
var
|
|
1922
|
-
var
|
|
4087
|
+
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
4088
|
+
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
4089
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1923
4090
|
var parseEndpoint = (value) => {
|
|
1924
|
-
if (!
|
|
4091
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
1925
4092
|
return "each endpoint needs a url";
|
|
1926
4093
|
try {
|
|
1927
4094
|
new URL(value.url);
|
|
@@ -1938,18 +4105,18 @@ var parseEndpoint = (value) => {
|
|
|
1938
4105
|
const events = value.events ?? value.enabledEvents;
|
|
1939
4106
|
if (Array.isArray(events))
|
|
1940
4107
|
endpoint.events = events.map(String);
|
|
1941
|
-
if (
|
|
4108
|
+
if (isRecord5(value.tags)) {
|
|
1942
4109
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
1943
4110
|
}
|
|
1944
4111
|
if (typeof value.account === "string")
|
|
1945
4112
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
1946
|
-
if (
|
|
4113
|
+
if (isRecord5(value.headers)) {
|
|
1947
4114
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
1948
4115
|
}
|
|
1949
4116
|
return endpoint;
|
|
1950
4117
|
};
|
|
1951
4118
|
var webhookAdminRoutes = (hub) => ({
|
|
1952
|
-
"GET /webhooks": ({ url, namespace }) =>
|
|
4119
|
+
"GET /webhooks": ({ url, namespace }) => json4(200, {
|
|
1953
4120
|
deliveries: hub.deliveries(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((d) => {
|
|
1954
4121
|
const type = url.searchParams.get("type");
|
|
1955
4122
|
return type === null || d.type === type;
|
|
@@ -1957,51 +4124,51 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
1957
4124
|
}),
|
|
1958
4125
|
"GET /webhooks/events": ({ url, namespace }) => {
|
|
1959
4126
|
const type = url.searchParams.get("type");
|
|
1960
|
-
return
|
|
4127
|
+
return json4(200, {
|
|
1961
4128
|
events: hub.messages(url.searchParams.get("all") === "1" ? void 0 : namespace).filter((m) => type === null || m.type === type).map((m) => ({ ...m, payload: parsePayload(m) }))
|
|
1962
4129
|
});
|
|
1963
4130
|
},
|
|
1964
4131
|
"POST /webhooks/:id/replay": async ({ params }) => {
|
|
1965
4132
|
const replayed = await hub.replay(params.id);
|
|
1966
|
-
return replayed ?
|
|
4133
|
+
return replayed ? json4(200, replayed) : adminError3(404, `no delivery ${params.id}`);
|
|
1967
4134
|
},
|
|
1968
4135
|
"POST /webhooks/flush": async () => {
|
|
1969
4136
|
await hub.flush();
|
|
1970
|
-
return
|
|
4137
|
+
return json4(200, { status: "ok" });
|
|
1971
4138
|
},
|
|
1972
4139
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
1973
|
-
if (!
|
|
1974
|
-
return
|
|
4140
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
4141
|
+
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
1975
4142
|
}
|
|
1976
4143
|
const fault = { mode: body.mode };
|
|
1977
4144
|
if (typeof body.count === "number")
|
|
1978
4145
|
fault.count = body.count;
|
|
1979
4146
|
hub.fault(namespace, fault);
|
|
1980
|
-
return
|
|
4147
|
+
return json4(201, { namespace, ...fault });
|
|
1981
4148
|
},
|
|
1982
|
-
"GET /webhook-endpoints": ({ namespace }) =>
|
|
4149
|
+
"GET /webhook-endpoints": ({ namespace }) => json4(200, {
|
|
1983
4150
|
endpoints: hub.endpoints(namespace).map(({ secret, ...rest }) => ({
|
|
1984
4151
|
...rest,
|
|
1985
4152
|
secret: secret ? "(set)" : null
|
|
1986
4153
|
}))
|
|
1987
4154
|
}),
|
|
1988
4155
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
1989
|
-
const list = Array.isArray(body) ? body :
|
|
4156
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
1990
4157
|
if (!Array.isArray(list))
|
|
1991
|
-
return
|
|
4158
|
+
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
1992
4159
|
const parsed = [];
|
|
1993
4160
|
for (const each of list) {
|
|
1994
4161
|
const endpoint = parseEndpoint(each);
|
|
1995
4162
|
if (typeof endpoint === "string")
|
|
1996
|
-
return
|
|
4163
|
+
return adminError3(400, endpoint);
|
|
1997
4164
|
parsed.push(endpoint);
|
|
1998
4165
|
}
|
|
1999
4166
|
const set = hub.setEndpoints(namespace, parsed);
|
|
2000
|
-
return
|
|
4167
|
+
return json4(200, { endpoints: set.map((e) => ({ ...e, secret: e.secret ? "(set)" : null })) });
|
|
2001
4168
|
},
|
|
2002
4169
|
"DELETE /webhook-endpoints": ({ namespace }) => {
|
|
2003
4170
|
hub.setEndpoints(namespace, []);
|
|
2004
|
-
return
|
|
4171
|
+
return json4(200, { status: "ok" });
|
|
2005
4172
|
}
|
|
2006
4173
|
});
|
|
2007
4174
|
var parsePayload = (message) => {
|
|
@@ -2056,8 +4223,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
2056
4223
|
this.name = "TypeError";
|
|
2057
4224
|
}
|
|
2058
4225
|
};
|
|
2059
|
-
var operationMatcher = (
|
|
2060
|
-
const matchers = listOperations(
|
|
4226
|
+
var operationMatcher = (document3) => {
|
|
4227
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
2061
4228
|
operationId: operation.operationId,
|
|
2062
4229
|
method: operation.method.toUpperCase(),
|
|
2063
4230
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -2066,6 +4233,7 @@ var operationMatcher = (document2) => {
|
|
|
2066
4233
|
return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
|
|
2067
4234
|
};
|
|
2068
4235
|
var createRuntime = (options) => {
|
|
4236
|
+
assertAdminUi(options.adminUi);
|
|
2069
4237
|
const sqlite = bootSqlite(options.sqlite);
|
|
2070
4238
|
const clock = options.clock ?? createClock();
|
|
2071
4239
|
const rng = createRng(options.seed ?? 0);
|
|
@@ -2151,10 +4319,10 @@ var createRuntime = (options) => {
|
|
|
2151
4319
|
const ensureBranch = (namespace, branch2, at) => {
|
|
2152
4320
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
2153
4321
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
2154
|
-
const
|
|
4322
|
+
const history2 = timeline(namespace);
|
|
2155
4323
|
if (branch2 === "main") {
|
|
2156
4324
|
if (at !== void 0) {
|
|
2157
|
-
const point =
|
|
4325
|
+
const point = history2.checkout("main", at);
|
|
2158
4326
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
2159
4327
|
captured.set(namespace, point.value.snapshot);
|
|
2160
4328
|
rng.setState(point.value.rngState);
|
|
@@ -2167,10 +4335,10 @@ var createRuntime = (options) => {
|
|
|
2167
4335
|
return namespace;
|
|
2168
4336
|
}
|
|
2169
4337
|
const storage = physicalBranch(namespace, branch2);
|
|
2170
|
-
if (!
|
|
4338
|
+
if (!history2.hasBranch(branch2)) {
|
|
2171
4339
|
if (at === void 0)
|
|
2172
|
-
|
|
2173
|
-
const point =
|
|
4340
|
+
history2.commit(capture(namespace));
|
|
4341
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
2174
4342
|
const branchRng = createRng(options.seed ?? 0);
|
|
2175
4343
|
if (point)
|
|
2176
4344
|
branchRng.setState(point.value.rngState);
|
|
@@ -2179,8 +4347,8 @@ var createRuntime = (options) => {
|
|
|
2179
4347
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
2180
4348
|
if (point)
|
|
2181
4349
|
captured.set(storage, point.value.snapshot);
|
|
2182
|
-
} else if (at !== void 0 &&
|
|
2183
|
-
const point =
|
|
4350
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
4351
|
+
const point = history2.checkout(branch2, at);
|
|
2184
4352
|
if (!instances.has(storage)) {
|
|
2185
4353
|
const branchRng = createRng(options.seed ?? 0);
|
|
2186
4354
|
branchRng.setState(point.value.rngState);
|
|
@@ -2191,7 +4359,7 @@ var createRuntime = (options) => {
|
|
|
2191
4359
|
captured.set(storage, point.value.snapshot);
|
|
2192
4360
|
} else {
|
|
2193
4361
|
if (!instances.has(storage)) {
|
|
2194
|
-
const point =
|
|
4362
|
+
const point = history2.head(branch2);
|
|
2195
4363
|
const branchRng = createRng(options.seed ?? 0);
|
|
2196
4364
|
if (point)
|
|
2197
4365
|
branchRng.setState(point.value.rngState);
|
|
@@ -2215,8 +4383,8 @@ var createRuntime = (options) => {
|
|
|
2215
4383
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
2216
4384
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
2217
4385
|
const branchName = checkoutOptions.branch ?? "main";
|
|
2218
|
-
const
|
|
2219
|
-
const point =
|
|
4386
|
+
const history2 = timeline(namespace);
|
|
4387
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
2220
4388
|
const storage = ensureBranch(namespace, branchName);
|
|
2221
4389
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
2222
4390
|
captured.set(storage, point.value.snapshot);
|
|
@@ -2266,12 +4434,25 @@ var createRuntime = (options) => {
|
|
|
2266
4434
|
instance(name);
|
|
2267
4435
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
2268
4436
|
captured.set(name, from);
|
|
2269
|
-
const
|
|
2270
|
-
if (
|
|
2271
|
-
|
|
4437
|
+
const history2 = timelines.get(name);
|
|
4438
|
+
if (history2)
|
|
4439
|
+
history2.commit(capture(name), { branch: "main" });
|
|
2272
4440
|
else
|
|
2273
4441
|
timeline(name);
|
|
2274
4442
|
};
|
|
4443
|
+
const declarationsFor = (namespace) => {
|
|
4444
|
+
const declared = options.state;
|
|
4445
|
+
if (!declared)
|
|
4446
|
+
return [];
|
|
4447
|
+
return typeof declared === "function" ? declared(instance(namespace), namespace) : declared;
|
|
4448
|
+
};
|
|
4449
|
+
const stateScope = (namespace) => ({
|
|
4450
|
+
sqlite,
|
|
4451
|
+
namespace,
|
|
4452
|
+
storageNamespace: storageNamespace(namespace),
|
|
4453
|
+
root: instance(namespace),
|
|
4454
|
+
declarations: declarationsFor(namespace)
|
|
4455
|
+
});
|
|
2275
4456
|
const runtime = {
|
|
2276
4457
|
name: options.name,
|
|
2277
4458
|
sqlite,
|
|
@@ -2310,6 +4491,7 @@ var createRuntime = (options) => {
|
|
|
2310
4491
|
branch,
|
|
2311
4492
|
checkout,
|
|
2312
4493
|
timeline,
|
|
4494
|
+
state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
|
|
2313
4495
|
fetch: async (incoming) => {
|
|
2314
4496
|
let request = incoming;
|
|
2315
4497
|
const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
|
|
@@ -2483,10 +4665,10 @@ var createRuntime = (options) => {
|
|
|
2483
4665
|
},
|
|
2484
4666
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
2485
4667
|
inspect: (name) => {
|
|
2486
|
-
const
|
|
4668
|
+
const history2 = timeline(name);
|
|
2487
4669
|
return {
|
|
2488
|
-
branches:
|
|
2489
|
-
checkpoints:
|
|
4670
|
+
branches: history2.branches(),
|
|
4671
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
2490
4672
|
id,
|
|
2491
4673
|
branch: branchName,
|
|
2492
4674
|
parent,
|
|
@@ -2501,13 +4683,22 @@ var createRuntime = (options) => {
|
|
|
2501
4683
|
} : {},
|
|
2502
4684
|
routes: {
|
|
2503
4685
|
...credentialRoutes(credentials),
|
|
2504
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
2505
4686
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
2506
|
-
...options.admin?.(runtime) ?? {}
|
|
4687
|
+
...options.admin?.(runtime) ?? {},
|
|
4688
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4689
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4690
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
4691
|
+
...stateAdminRoutes({
|
|
4692
|
+
open: stateScope,
|
|
4693
|
+
afterWrite: (namespace) => {
|
|
4694
|
+
checkpoint(namespace, "main");
|
|
4695
|
+
}
|
|
4696
|
+
}),
|
|
4697
|
+
...adminUiRoutes(options.name, options.adminUi)
|
|
2507
4698
|
},
|
|
2508
4699
|
adminKey: options.adminKey
|
|
2509
4700
|
});
|
|
2510
|
-
return runtime;
|
|
4701
|
+
return defineMock(runtime);
|
|
2511
4702
|
};
|
|
2512
4703
|
var mutableResponse = (response) => {
|
|
2513
4704
|
try {
|
|
@@ -2571,9 +4762,12 @@ var credentialRoutes = (registry) => ({
|
|
|
2571
4762
|
}
|
|
2572
4763
|
});
|
|
2573
4764
|
var presetRoutes = (presets, runtime) => ({
|
|
2574
|
-
"GET /faults/presets": () =>
|
|
2575
|
-
|
|
2576
|
-
|
|
4765
|
+
"GET /faults/presets": () => {
|
|
4766
|
+
const body = {
|
|
4767
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4768
|
+
};
|
|
4769
|
+
return adminJson(200, body);
|
|
4770
|
+
},
|
|
2577
4771
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
2578
4772
|
const name = params.name;
|
|
2579
4773
|
if (!presets[name])
|
|
@@ -2584,7 +4778,7 @@ var presetRoutes = (presets, runtime) => ({
|
|
|
2584
4778
|
});
|
|
2585
4779
|
|
|
2586
4780
|
// src/generated/openapi.ts
|
|
2587
|
-
var document = JSON.parse(`{"openapi":"3.1.0","info":{"title":"RxVortex (Strive) pharmacy API (Mockingbird subset)","description":"Stateful mock subset of the RxVortex / Strive compounding-pharmacy API: client-credentials\\ntoken, order submit, status, cancel, lookup by sender order id (recovery), and the preset\\ncatalog. Hand-authored from the consumer's adapters (the vendor publishes no spec).\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from the wire shapes our consumer reads and writes (rxvortex-auth.service.ts, rxvortex-fulfillment.adapter.ts, rxvortex-live.client.ts)."}},"servers":[{"url":"https://sandbox.rxvortex.com"}],"security":[{"bearerAuth":[]}],"paths":{"/api/v1/generate-access-token":{"post":{"operationId":"GenerateAccessToken","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["client_id","client_secret"],"properties":{"client_id":{"type":"string","minLength":1,"maxLength":64},"client_secret":{"type":"string","minLength":1,"maxLength":64}}}}}},"responses":{"200":{"description":"Access token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TokenResponse"}}}},"401":{"description":"Bad credentials","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"422":{"description":"Validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}},"/api/v1/orders":{"post":{"operationId":"CreateOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderBody"}}}},"responses":{"200":{"description":"Order accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderResponse"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Duplicate sender_order_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"422":{"description":"Validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}},"/api/v1/orders/{orderId}":{"parameters":[{"name":"orderId","in":"path","required":true,"description":"The vendor order tracking id, or the sender order id (our payment id).","schema":{"type":"string","x-mockingbird-resource-ref":{"type":"order","missing":"RXV-00000000-MISSING"}}}],"get":{"operationId":"GetOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Order status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderStatus"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}},"delete":{"operationId":"CancelOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"200":{"description":"Cancelled","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Not cancellable in its current status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}},"/api/v1/preset-catalog-items":{"get":{"operationId":"ListPresetCatalogItems","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Preset catalog","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/CatalogItem"}}}}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}},"schemas":{"TokenResponse":{"type":"object","required":["access_token","token_type","expires_in"],"properties":{"access_token":{"type":"string","x-mockingbird-volatile":{"kind":"token"}},"token_type":{"type":"string","enum":["Bearer"]},"expires_in":{"type":"integer"}}},"Address":{"type":"object","required":["line1","city","state","postal_code","country"],"properties":{"line1":{"type":"string","minLength":1,"maxLength":80},"line2":{"type":"string","maxLength":80},"city":{"type":"string","minLength":1,"maxLength":40},"state":{"type":"string","pattern":"^[A-Z]{2}$"},"postal_code":{"type":"string","pattern":"^[0-9]{5}(-[0-9]{4})?$"},"country":{"type":"string","enum":["US"]}}},"Patient":{"type":"object","required":["sender_patient_id","first_name","last_name","dob","gender","email","phone","address"],"properties":{"sender_patient_id":{"type":"string","minLength":1,"maxLength":64},"first_name":{"type":"string","minLength":1,"maxLength":40},"last_name":{"type":"string","minLength":1,"maxLength":40},"dob":{"type":"string","pattern":"^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"},"gender":{"type":"string","enum":["male","female"]},"email":{"type":"string","format":"email","maxLength":120},"phone":{"type":"string","pattern":"^[0-9]{3}-[0-9]{3}-[0-9]{4}$"},"address":{"$ref":"#/components/schemas/Address"}}},"Prescriber":{"type":"object","required":["first_name","last_name","npi"],"properties":{"first_name":{"type":"string","minLength":1,"maxLength":40},"last_name":{"type":"string","minLength":1,"maxLength":40},"npi":{"type":"string","pattern":"^[0-9]{10}$"},"dea_number":{"type":"string","maxLength":20},"license_number":{"type":"string","maxLength":20},"license_state":{"type":"string","maxLength":2},"phone":{"type":"string","maxLength":20},"address":{"$ref":"#/components/schemas/Address"}}},"MedicationRequest":{"type":"object","required":["type","preset_catalog_id","sender_med_request_id","medication_name","quantity","quantity_units","days_supply_duration","refills","instructions"],"properties":{"type":{"type":"string","enum":["new"]},"preset_catalog_id":{"type":"string","x-mockingbird-resource-ref":{"type":"catalog_item","missing":"00000000-0000-4000-8000-000000000000"}},"sender_med_request_id":{"type":"string","minLength":1,"maxLength":64},"medication_name":{"type":"string","minLength":1,"maxLength":120},"medication_strength":{"type":"string","maxLength":60},"medication_form":{"type":"string","maxLength":40},"quantity":{"type":"number","exclusiveMinimum":0,"maximum":1000},"quantity_units":{"type":"string","enum":["mL","grams","each"]},"days_supply_duration":{"type":"integer","minimum":1,"maximum":365},"refills":{"type":"integer","minimum":0,"maximum":12},"instructions":{"type":"string","minLength":1,"maxLength":500},"note":{"type":"string","maxLength":1000},"authored_on_datetime":{"type":"string","maxLength":40},"clinical_difference":{"type":"string","maxLength":1000},"schedule_code":{"type":"string","enum":["2","3","4","5"]}}},"ClinicalList":{"type":"object","properties":{"has_known_allergies":{"type":"boolean"},"has_known_diseases":{"type":"boolean"},"has_known_medications":{"type":"boolean"},"entries":{"type":"array","maxItems":5,"items":{"type":"object","required":["description"],"properties":{"description":{"type":"string","maxLength":200}}}}}},"CreateOrderBody":{"type":"object","required":["patient","prescriber","order","medication_requests"],"properties":{"patient":{"$ref":"#/components/schemas/Patient"},"prescriber":{"$ref":"#/components/schemas/Prescriber"},"order":{"type":"object","required":["bill_to","ship_to","sender_order_id"],"properties":{"bill_to":{"type":"string","enum":["practice","patient"]},"ship_to":{"type":"string","enum":["patient","practice"]},"sender_order_id":{"type":"string","minLength":1,"maxLength":64}}},"medication_requests":{"type":"array","minItems":1,"maxItems":3,"items":{"$ref":"#/components/schemas/MedicationRequest"}},"clinical":{"type":"object","properties":{"allergies":{"$ref":"#/components/schemas/ClinicalList"},"diseases":{"$ref":"#/components/schemas/ClinicalList"},"medications":{"$ref":"#/components/schemas/ClinicalList"}}},"shipment":{"type":"object","properties":{"recipient_first_name":{"type":"string","maxLength":40},"recipient_last_name":{"type":"string","maxLength":40},"recipient_email":{"type":"string","maxLength":80},"recipient_phone":{"type":"string","maxLength":20},"address":{"$ref":"#/components/schemas/Address"}}}}},"CreateOrderResponse":{"type":"object","required":["success","message","order_tracking_id","sender_order_id","status"],"properties":{"success":{"type":"boolean"},"message":{"type":"string"},"order_tracking_id":{"type":"string","x-mockingbird-resource":{"type":"order","identity":true},"x-mockingbird-volatile":{"kind":"id"}},"sender_order_id":{"type":"string"},"status":{"type":"string"}}},"OrderStatus":{"type":"object","required":["order_tracking_id","tracking_id","orderReferenceID","sender_order_id","rxstatus","orderstatus","shipping_status","cancellable","created_at","updated_at"],"properties":{"order_tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"orderReferenceID":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"sender_order_id":{"type":"string"},"rxstatus":{"type":"string"},"orderstatus":{"type":"string"},"shipping_status":{"type":"string"},"delivered_date":{"type":["string","null"]},"trackingnumber":{"type":["string","null"]},"shippingservice":{"type":["string","null"]},"shippingcarrier":{"type":["string","null"]},"shipmenttrackingurl":{"type":["string","null"]},"cancellable":{"type":"boolean"},"created_at":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updated_at":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}},"CancelResponse":{"type":"object","required":["success","message","order_tracking_id","rxstatus"],"properties":{"success":{"type":"boolean"},"message":{"type":"string"},"order_tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"rxstatus":{"type":"string"}}},"CatalogItem":{"type":"object","required":["catalog_id","medication_name","status"],"properties":{"catalog_id":{"type":"string","x-mockingbird-resource":{"type":"catalog_item","identity":true}},"medication_name":{"type":"string"},"medication_strength":{"type":["string","null"]},"package_size":{"type":["string","null"]},"quantity":{"type":["number","null"]},"quantity_units":{"type":["string","null"]},"medication_form":{"type":["string","null"]},"route":{"type":["string","null"]},"states":{"type":"array","items":{"type":"string"}},"status":{"type":"string","enum":["active","inactive"]}}},"ErrorBody":{"type":"object","required":["message"],"properties":{"message":{"type":"string"},"success":{"type":"boolean"}}},"ValidationError":{"type":"object","required":["message","errors"],"properties":{"message":{"type":"string"},"errors":{"oneOf":[{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}},{"type":"array","items":{"type":"object"}}]}}}}}}`);
|
|
4781
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"RxVortex (Strive) pharmacy API (Mockingbird subset)","description":"Stateful mock subset of the RxVortex / Strive compounding-pharmacy API: client-credentials\\ntoken, order submit, status, cancel, lookup by sender order id (recovery), and the preset\\ncatalog. Hand-authored from the consumer's adapters (the vendor publishes no spec).\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from the wire shapes our consumer reads and writes (rxvortex-auth.service.ts, rxvortex-fulfillment.adapter.ts, rxvortex-live.client.ts)."}},"servers":[{"url":"https://sandbox.rxvortex.com"}],"security":[{"bearerAuth":[]}],"paths":{"/api/v1/generate-access-token":{"post":{"operationId":"GenerateAccessToken","security":[],"x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["client_id","client_secret"],"properties":{"client_id":{"type":"string","minLength":1,"maxLength":64},"client_secret":{"type":"string","minLength":1,"maxLength":64}}}}}},"responses":{"200":{"description":"Access token","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TokenResponse"}}}},"401":{"description":"Bad credentials","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"422":{"description":"Validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}},"/api/v1/orders":{"post":{"operationId":"CreateOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderBody"}}}},"responses":{"200":{"description":"Order accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateOrderResponse"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Duplicate sender_order_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"422":{"description":"Validation failed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}}}}},"/api/v1/orders/{orderId}":{"parameters":[{"name":"orderId","in":"path","required":true,"description":"The vendor order tracking id, or the sender order id (our payment id).","schema":{"type":"string","x-mockingbird-resource-ref":{"type":"order","missing":"RXV-00000000-MISSING"}}}],"get":{"operationId":"GetOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Order status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderStatus"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}},"delete":{"operationId":"CancelOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"responses":{"200":{"description":"Cancelled","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}},"409":{"description":"Not cancellable in its current status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}},"/api/v1/preset-catalog-items":{"get":{"operationId":"ListPresetCatalogItems","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Preset catalog","content":{"application/json":{"schema":{"type":"object","required":["data"],"properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/CatalogItem"}}}}}}},"401":{"description":"Unauthenticated","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorBody"}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"}},"schemas":{"TokenResponse":{"type":"object","required":["access_token","token_type","expires_in"],"properties":{"access_token":{"type":"string","x-mockingbird-volatile":{"kind":"token"}},"token_type":{"type":"string","enum":["Bearer"]},"expires_in":{"type":"integer"}}},"Address":{"type":"object","required":["line1","city","state","postal_code","country"],"properties":{"line1":{"type":"string","minLength":1,"maxLength":80},"line2":{"type":"string","maxLength":80},"city":{"type":"string","minLength":1,"maxLength":40},"state":{"type":"string","pattern":"^[A-Z]{2}$"},"postal_code":{"type":"string","pattern":"^[0-9]{5}(-[0-9]{4})?$"},"country":{"type":"string","enum":["US"]}}},"Patient":{"type":"object","required":["sender_patient_id","first_name","last_name","dob","gender","email","phone","address"],"properties":{"sender_patient_id":{"type":"string","minLength":1,"maxLength":64},"first_name":{"type":"string","minLength":1,"maxLength":40},"last_name":{"type":"string","minLength":1,"maxLength":40},"dob":{"type":"string","pattern":"^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$"},"gender":{"type":"string","enum":["male","female"]},"email":{"type":"string","format":"email","maxLength":120},"phone":{"type":"string","pattern":"^[0-9]{3}-[0-9]{3}-[0-9]{4}$"},"address":{"$ref":"#/components/schemas/Address"}}},"Prescriber":{"type":"object","required":["first_name","last_name","npi"],"properties":{"first_name":{"type":"string","minLength":1,"maxLength":40},"last_name":{"type":"string","minLength":1,"maxLength":40},"npi":{"type":"string","pattern":"^[0-9]{10}$"},"dea_number":{"type":"string","maxLength":20},"license_number":{"type":"string","maxLength":20},"license_state":{"type":"string","maxLength":2},"phone":{"type":"string","maxLength":20},"address":{"$ref":"#/components/schemas/Address"}}},"MedicationRequest":{"type":"object","required":["type","preset_catalog_id","sender_med_request_id","medication_name","quantity","quantity_units","days_supply_duration","refills","instructions"],"properties":{"type":{"type":"string","enum":["new"]},"preset_catalog_id":{"type":"string","x-mockingbird-resource-ref":{"type":"catalog_item","missing":"00000000-0000-4000-8000-000000000000"}},"sender_med_request_id":{"type":"string","minLength":1,"maxLength":64},"medication_name":{"type":"string","minLength":1,"maxLength":120},"medication_strength":{"type":"string","maxLength":60},"medication_form":{"type":"string","maxLength":40},"quantity":{"type":"number","exclusiveMinimum":0,"maximum":1000},"quantity_units":{"type":"string","enum":["mL","grams","each"]},"days_supply_duration":{"type":"integer","minimum":1,"maximum":365},"refills":{"type":"integer","minimum":0,"maximum":12},"instructions":{"type":"string","minLength":1,"maxLength":500},"note":{"type":"string","maxLength":1000},"authored_on_datetime":{"type":"string","maxLength":40},"clinical_difference":{"type":"string","maxLength":1000},"schedule_code":{"type":"string","enum":["2","3","4","5"]}}},"ClinicalList":{"type":"object","properties":{"has_known_allergies":{"type":"boolean"},"has_known_diseases":{"type":"boolean"},"has_known_medications":{"type":"boolean"},"entries":{"type":"array","maxItems":5,"items":{"type":"object","required":["description"],"properties":{"description":{"type":"string","maxLength":200}}}}}},"CreateOrderBody":{"type":"object","required":["patient","prescriber","order","medication_requests"],"properties":{"patient":{"$ref":"#/components/schemas/Patient"},"prescriber":{"$ref":"#/components/schemas/Prescriber"},"order":{"type":"object","required":["bill_to","ship_to","sender_order_id"],"properties":{"bill_to":{"type":"string","enum":["practice","patient"]},"ship_to":{"type":"string","enum":["patient","practice"]},"sender_order_id":{"type":"string","minLength":1,"maxLength":64}}},"medication_requests":{"type":"array","minItems":1,"maxItems":3,"items":{"$ref":"#/components/schemas/MedicationRequest"}},"clinical":{"type":"object","properties":{"allergies":{"$ref":"#/components/schemas/ClinicalList"},"diseases":{"$ref":"#/components/schemas/ClinicalList"},"medications":{"$ref":"#/components/schemas/ClinicalList"}}},"shipment":{"type":"object","properties":{"recipient_first_name":{"type":"string","maxLength":40},"recipient_last_name":{"type":"string","maxLength":40},"recipient_email":{"type":"string","maxLength":80},"recipient_phone":{"type":"string","maxLength":20},"address":{"$ref":"#/components/schemas/Address"}}}}},"CreateOrderResponse":{"type":"object","required":["success","message","order_tracking_id","sender_order_id","status"],"properties":{"success":{"type":"boolean"},"message":{"type":"string"},"order_tracking_id":{"type":"string","x-mockingbird-resource":{"type":"order","identity":true},"x-mockingbird-volatile":{"kind":"id"}},"sender_order_id":{"type":"string"},"status":{"type":"string"}}},"OrderStatus":{"type":"object","required":["order_tracking_id","tracking_id","orderReferenceID","sender_order_id","rxstatus","orderstatus","shipping_status","cancellable","created_at","updated_at"],"properties":{"order_tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"orderReferenceID":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"sender_order_id":{"type":"string"},"rxstatus":{"type":"string"},"orderstatus":{"type":"string"},"shipping_status":{"type":"string"},"delivered_date":{"type":["string","null"]},"trackingnumber":{"type":["string","null"]},"shippingservice":{"type":["string","null"]},"shippingcarrier":{"type":["string","null"]},"shipmenttrackingurl":{"type":["string","null"]},"cancellable":{"type":"boolean"},"created_at":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"updated_at":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}}}},"CancelResponse":{"type":"object","required":["success","message","order_tracking_id","rxstatus"],"properties":{"success":{"type":"boolean"},"message":{"type":"string"},"order_tracking_id":{"type":"string","x-mockingbird-volatile":{"kind":"id"}},"rxstatus":{"type":"string"}}},"CatalogItem":{"type":"object","required":["catalog_id","medication_name","status"],"properties":{"catalog_id":{"type":"string","x-mockingbird-resource":{"type":"catalog_item","identity":true}},"medication_name":{"type":"string"},"medication_strength":{"type":["string","null"]},"package_size":{"type":["string","null"]},"quantity":{"type":["number","null"]},"quantity_units":{"type":["string","null"]},"medication_form":{"type":["string","null"]},"route":{"type":["string","null"]},"states":{"type":"array","items":{"type":"string"}},"status":{"type":"string","enum":["active","inactive"]}}},"ErrorBody":{"type":"object","required":["message"],"properties":{"message":{"type":"string"},"success":{"type":"boolean"}}},"ValidationError":{"type":"object","required":["message","errors"],"properties":{"message":{"type":"string"},"errors":{"oneOf":[{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}},{"type":"array","items":{"type":"object"}}]}}}}}}`);
|
|
2588
4782
|
var operationIds = ["GenerateAccessToken", "CreateOrder", "GetOrder", "CancelOrder", "ListPresetCatalogItems"];
|
|
2589
4783
|
var supportedOperationIds = ["GenerateAccessToken", "CreateOrder", "GetOrder", "CancelOrder", "ListPresetCatalogItems"];
|
|
2590
4784
|
|
|
@@ -2671,7 +4865,7 @@ var DEFAULT_CATALOG = [
|
|
|
2671
4865
|
status: "inactive"
|
|
2672
4866
|
}
|
|
2673
4867
|
];
|
|
2674
|
-
var
|
|
4868
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2675
4869
|
var optionalString = (row, key) => {
|
|
2676
4870
|
const value = row[key];
|
|
2677
4871
|
if (value === void 0 || value === null) return null;
|
|
@@ -2679,7 +4873,7 @@ var optionalString = (row, key) => {
|
|
|
2679
4873
|
return value;
|
|
2680
4874
|
};
|
|
2681
4875
|
var parseCatalogItem = (value) => {
|
|
2682
|
-
if (!
|
|
4876
|
+
if (!isRecord6(value)) throw new Error("a catalog row must be an object");
|
|
2683
4877
|
const { catalog_id, medication_name, quantity, states, status } = value;
|
|
2684
4878
|
if (typeof catalog_id !== "string" || catalog_id.length === 0) {
|
|
2685
4879
|
throw new Error("catalog_id must be a non-empty string");
|
|
@@ -2714,7 +4908,7 @@ var parseCatalogItem = (value) => {
|
|
|
2714
4908
|
}
|
|
2715
4909
|
};
|
|
2716
4910
|
var parseCatalog = (value) => {
|
|
2717
|
-
const rows = Array.isArray(value) ? value :
|
|
4911
|
+
const rows = Array.isArray(value) ? value : isRecord6(value) ? value.data : void 0;
|
|
2718
4912
|
if (!Array.isArray(rows)) throw new Error("a catalog must be an array or {data: [...]}");
|
|
2719
4913
|
return rows.map(parseCatalogItem);
|
|
2720
4914
|
};
|
|
@@ -2870,12 +5064,12 @@ var RXVORTEX_PRESETS = {
|
|
|
2870
5064
|
webhook: { mode: "drop" }
|
|
2871
5065
|
}
|
|
2872
5066
|
};
|
|
2873
|
-
var
|
|
2874
|
-
var
|
|
2875
|
-
var
|
|
5067
|
+
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
5068
|
+
var adminError4 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
|
|
5069
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2876
5070
|
var parseAutoAdvance = (value) => {
|
|
2877
5071
|
if (value === null) return null;
|
|
2878
|
-
if (!
|
|
5072
|
+
if (!isRecord7(value)) return "autoAdvance must be {afterMs, path} or null";
|
|
2879
5073
|
if (typeof value.afterMs !== "number" || value.afterMs < 0)
|
|
2880
5074
|
return "autoAdvance.afterMs must be ms";
|
|
2881
5075
|
if (!Array.isArray(value.path) || value.path.some((s) => typeof s !== "string")) {
|
|
@@ -2884,10 +5078,10 @@ var parseAutoAdvance = (value) => {
|
|
|
2884
5078
|
return { afterMs: value.afterMs, path: value.path };
|
|
2885
5079
|
};
|
|
2886
5080
|
var adminRoutes = (runtime) => ({
|
|
2887
|
-
"GET /orders": ({ namespace }) =>
|
|
5081
|
+
"GET /orders": ({ namespace }) => json5(200, { orders: runtime.instance(namespace).orders() }),
|
|
2888
5082
|
"POST /orders/:id/transition": ({ params, body, namespace }) => {
|
|
2889
|
-
if (!
|
|
2890
|
-
return
|
|
5083
|
+
if (!isRecord7(body) || typeof body.to !== "string") {
|
|
5084
|
+
return adminError4(
|
|
2891
5085
|
400,
|
|
2892
5086
|
'expected {"to": "<vendor status>", "trackingnumber"?, "shippingcarrier"?}'
|
|
2893
5087
|
);
|
|
@@ -2900,61 +5094,61 @@ var adminRoutes = (runtime) => ({
|
|
|
2900
5094
|
...optional("shippingservice"),
|
|
2901
5095
|
...optional("delivered_date")
|
|
2902
5096
|
});
|
|
2903
|
-
return order ?
|
|
5097
|
+
return order ? json5(200, order) : adminError4(404, `no order ${params.id}`);
|
|
2904
5098
|
},
|
|
2905
|
-
"GET /catalog": ({ namespace }) =>
|
|
5099
|
+
"GET /catalog": ({ namespace }) => json5(200, { data: runtime.instance(namespace).state.catalogRows() }),
|
|
2906
5100
|
"PUT /catalog": ({ body, namespace }) => {
|
|
2907
|
-
const rows =
|
|
2908
|
-
if (!
|
|
2909
|
-
return
|
|
5101
|
+
const rows = isRecord7(body) ? body.items ?? body.data : void 0;
|
|
5102
|
+
if (!isRecord7(body) || !Array.isArray(rows)) {
|
|
5103
|
+
return adminError4(400, 'expected {"items": [{catalog_id, medication_name, \u2026}], "mode"?}');
|
|
2910
5104
|
}
|
|
2911
5105
|
const mode = body.mode ?? "replace";
|
|
2912
5106
|
if (mode !== "replace" && mode !== "merge") {
|
|
2913
|
-
return
|
|
5107
|
+
return adminError4(400, 'mode must be "replace" or "merge"');
|
|
2914
5108
|
}
|
|
2915
5109
|
let items;
|
|
2916
5110
|
try {
|
|
2917
5111
|
items = rows.map(parseCatalogItem);
|
|
2918
5112
|
} catch (error) {
|
|
2919
|
-
return
|
|
5113
|
+
return adminError4(400, `items: ${error.message}`);
|
|
2920
5114
|
}
|
|
2921
|
-
return
|
|
5115
|
+
return json5(200, { count: runtime.instance(namespace).state.putCatalog(items, mode) });
|
|
2922
5116
|
},
|
|
2923
|
-
"GET /settings": ({ namespace }) =>
|
|
5117
|
+
"GET /settings": ({ namespace }) => json5(200, runtime.instance(namespace).state.current()),
|
|
2924
5118
|
"PUT /settings": ({ body, namespace }) => {
|
|
2925
|
-
if (!
|
|
5119
|
+
if (!isRecord7(body)) return adminError4(400, "expected a JSON object");
|
|
2926
5120
|
const patch = {};
|
|
2927
5121
|
if (body.tokenTtlSeconds !== void 0) {
|
|
2928
5122
|
if (typeof body.tokenTtlSeconds !== "number")
|
|
2929
|
-
return
|
|
5123
|
+
return adminError4(400, "tokenTtlSeconds: number");
|
|
2930
5124
|
patch.tokenTtlSeconds = body.tokenTtlSeconds;
|
|
2931
5125
|
}
|
|
2932
5126
|
if (body.staticTokens !== void 0) {
|
|
2933
|
-
if (!Array.isArray(body.staticTokens)) return
|
|
5127
|
+
if (!Array.isArray(body.staticTokens)) return adminError4(400, "staticTokens: string[]");
|
|
2934
5128
|
patch.staticTokens = body.staticTokens.map(String);
|
|
2935
5129
|
}
|
|
2936
5130
|
if (body.clients !== void 0) {
|
|
2937
5131
|
if (!Array.isArray(body.clients))
|
|
2938
|
-
return
|
|
2939
|
-
patch.clients = body.clients.filter(
|
|
5132
|
+
return adminError4(400, "clients: [{client_id, client_secret}]");
|
|
5133
|
+
patch.clients = body.clients.filter(isRecord7).map((c) => ({
|
|
2940
5134
|
client_id: String(c.client_id),
|
|
2941
5135
|
client_secret: String(c.client_secret)
|
|
2942
5136
|
}));
|
|
2943
5137
|
}
|
|
2944
5138
|
if (body.autoAdvance !== void 0) {
|
|
2945
5139
|
const parsed = parseAutoAdvance(body.autoAdvance);
|
|
2946
|
-
if (typeof parsed === "string") return
|
|
5140
|
+
if (typeof parsed === "string") return adminError4(400, parsed);
|
|
2947
5141
|
patch.autoAdvance = parsed;
|
|
2948
5142
|
}
|
|
2949
5143
|
if (body.unknownPresets !== void 0) {
|
|
2950
5144
|
if (body.unknownPresets !== "reject" && body.unknownPresets !== "accept") {
|
|
2951
|
-
return
|
|
5145
|
+
return adminError4(400, 'unknownPresets: "reject" | "accept"');
|
|
2952
5146
|
}
|
|
2953
5147
|
patch.unknownPresets = body.unknownPresets;
|
|
2954
5148
|
}
|
|
2955
|
-
return
|
|
5149
|
+
return json5(200, runtime.instance(namespace).state.update(patch));
|
|
2956
5150
|
},
|
|
2957
|
-
"POST /tick": ({ namespace }) =>
|
|
5151
|
+
"POST /tick": ({ namespace }) => json5(200, { applied: runtime.instance(namespace).tick() })
|
|
2958
5152
|
});
|
|
2959
5153
|
var createRuntime2 = (options = {}) => {
|
|
2960
5154
|
const { retryDelaysMs, fetch: send, ...endpoint } = options.webhooks ?? { url: "" };
|
|
@@ -2966,7 +5160,7 @@ var createRuntime2 = (options = {}) => {
|
|
|
2966
5160
|
});
|
|
2967
5161
|
const runtime = createRuntime({
|
|
2968
5162
|
name: RXVORTEX_NAMESPACE,
|
|
2969
|
-
document,
|
|
5163
|
+
document: document2,
|
|
2970
5164
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
2971
5165
|
...options.clock ? { clock: options.clock } : {},
|
|
2972
5166
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -3098,7 +5292,7 @@ var RxVortexAPI = class {
|
|
|
3098
5292
|
ListPresetCatalogItems: () => jsonRes(200, { data: this.state.catalogRows() })
|
|
3099
5293
|
});
|
|
3100
5294
|
this.service = createService({
|
|
3101
|
-
document,
|
|
5295
|
+
document: document2,
|
|
3102
5296
|
handlers,
|
|
3103
5297
|
sqlite,
|
|
3104
5298
|
namespace,
|
|
@@ -3365,7 +5559,7 @@ var RxVortexAPI = class {
|
|
|
3365
5559
|
};
|
|
3366
5560
|
|
|
3367
5561
|
export {
|
|
3368
|
-
document,
|
|
5562
|
+
document2 as document,
|
|
3369
5563
|
operationIds,
|
|
3370
5564
|
supportedOperationIds,
|
|
3371
5565
|
CUSTOM_CREAM_ANCHOR_PRESET_ID,
|
|
@@ -3378,4 +5572,4 @@ export {
|
|
|
3378
5572
|
tokenCredential,
|
|
3379
5573
|
RxVortexAPI
|
|
3380
5574
|
};
|
|
3381
|
-
//# sourceMappingURL=chunk-
|
|
5575
|
+
//# sourceMappingURL=chunk-7IB3GSYU.js.map
|