@crvouga/mockingbird-service-wholescripts 1.4.0 → 1.5.1
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 +16 -0
- package/dist/{chunk-LZG3C4TK.js → chunk-J3DC2RKQ.js} +1421 -617
- package/dist/chunk-J3DC2RKQ.js.map +7 -0
- package/dist/{chunk-ROFEEFHY.js → chunk-QDVD4IEA.js} +2 -2
- package/dist/cli.js +2 -2
- package/dist/index.js +1 -1
- package/dist/server.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-LZG3C4TK.js.map +0 -7
- /package/dist/{chunk-ROFEEFHY.js.map → chunk-QDVD4IEA.js.map} +0 -0
|
@@ -551,10 +551,10 @@ var OpenAPIReferenceError = class extends Error {
|
|
|
551
551
|
};
|
|
552
552
|
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
553
553
|
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
554
|
-
var resolveRef = (
|
|
554
|
+
var resolveRef = (document3, ref) => {
|
|
555
555
|
if (!ref.startsWith("#/"))
|
|
556
556
|
throw new OpenAPIReferenceError(ref);
|
|
557
|
-
let cursor =
|
|
557
|
+
let cursor = document3;
|
|
558
558
|
for (const raw of ref.slice(2).split("/")) {
|
|
559
559
|
const segment = unescapePointer(raw);
|
|
560
560
|
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
@@ -566,14 +566,14 @@ var resolveRef = (document2, ref) => {
|
|
|
566
566
|
throw new OpenAPIReferenceError(ref);
|
|
567
567
|
return cursor;
|
|
568
568
|
};
|
|
569
|
-
var deref = (
|
|
569
|
+
var deref = (document3, value) => {
|
|
570
570
|
let current = value;
|
|
571
571
|
const seen = /* @__PURE__ */ new Set();
|
|
572
572
|
while (isReference(current)) {
|
|
573
573
|
if (seen.has(current.$ref))
|
|
574
574
|
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
575
575
|
seen.add(current.$ref);
|
|
576
|
-
current = resolveRef(
|
|
576
|
+
current = resolveRef(document3, current.$ref);
|
|
577
577
|
}
|
|
578
578
|
return current;
|
|
579
579
|
};
|
|
@@ -591,36 +591,36 @@ var HTTP_METHODS = [
|
|
|
591
591
|
];
|
|
592
592
|
|
|
593
593
|
// ../../openapi/core/dist/document.js
|
|
594
|
-
var mergeParameters = (
|
|
594
|
+
var mergeParameters = (document3, item, own) => {
|
|
595
595
|
const merged = /* @__PURE__ */ new Map();
|
|
596
596
|
for (const raw of item.parameters ?? []) {
|
|
597
|
-
const parameter = deref(
|
|
597
|
+
const parameter = deref(document3, raw);
|
|
598
598
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
599
599
|
}
|
|
600
600
|
for (const raw of own ?? []) {
|
|
601
|
-
const parameter = deref(
|
|
601
|
+
const parameter = deref(document3, raw);
|
|
602
602
|
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
603
603
|
}
|
|
604
604
|
return [...merged.values()];
|
|
605
605
|
};
|
|
606
|
-
var listOperations = (
|
|
606
|
+
var listOperations = (document3) => {
|
|
607
607
|
const operations = [];
|
|
608
|
-
for (const [path, item] of Object.entries(
|
|
608
|
+
for (const [path, item] of Object.entries(document3.paths)) {
|
|
609
609
|
for (const method of HTTP_METHODS) {
|
|
610
610
|
const operation = item[method];
|
|
611
611
|
if (operation?.operationId === void 0)
|
|
612
612
|
continue;
|
|
613
613
|
const responses = {};
|
|
614
614
|
for (const [status, response] of Object.entries(operation.responses)) {
|
|
615
|
-
responses[status] = deref(
|
|
615
|
+
responses[status] = deref(document3, response);
|
|
616
616
|
}
|
|
617
617
|
operations.push({
|
|
618
618
|
operationId: operation.operationId,
|
|
619
619
|
method,
|
|
620
620
|
path,
|
|
621
621
|
operation,
|
|
622
|
-
parameters: mergeParameters(
|
|
623
|
-
requestBody: operation.requestBody === void 0 ? void 0 : deref(
|
|
622
|
+
parameters: mergeParameters(document3, item, operation.parameters),
|
|
623
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document3, operation.requestBody),
|
|
624
624
|
responses
|
|
625
625
|
});
|
|
626
626
|
}
|
|
@@ -629,7 +629,7 @@ var listOperations = (document2) => {
|
|
|
629
629
|
};
|
|
630
630
|
|
|
631
631
|
// ../../openapi/core/dist/schema.js
|
|
632
|
-
var resolveSchema = (
|
|
632
|
+
var resolveSchema = (document3, schema) => {
|
|
633
633
|
let current = schema;
|
|
634
634
|
const seen = /* @__PURE__ */ new Set();
|
|
635
635
|
while (typeof current.$ref === "string") {
|
|
@@ -638,7 +638,7 @@ var resolveSchema = (document2, schema) => {
|
|
|
638
638
|
break;
|
|
639
639
|
seen.add(ref);
|
|
640
640
|
const { $ref: _ignored, ...siblings } = current;
|
|
641
|
-
const target = resolveRef(
|
|
641
|
+
const target = resolveRef(document3, ref);
|
|
642
642
|
current = { ...target, ...siblings };
|
|
643
643
|
}
|
|
644
644
|
if (current.nullable === true) {
|
|
@@ -709,9 +709,9 @@ var FORMAT_PATTERNS = {
|
|
|
709
709
|
ipv4: /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/
|
|
710
710
|
};
|
|
711
711
|
var graphemeLength = (value) => [...value].length;
|
|
712
|
-
var validateValue = (
|
|
712
|
+
var validateValue = (document3, schema, value, path = []) => {
|
|
713
713
|
const errors = [];
|
|
714
|
-
const s = resolveSchema(
|
|
714
|
+
const s = resolveSchema(document3, schema);
|
|
715
715
|
const fail2 = (message) => errors.push({ path, message });
|
|
716
716
|
const actual = jsonTypeOf(value);
|
|
717
717
|
if (actual === "undefined") {
|
|
@@ -773,7 +773,7 @@ var validateValue = (document2, schema, value, path = []) => {
|
|
|
773
773
|
value.forEach((item, i) => {
|
|
774
774
|
const itemSchema = s.prefixItems?.[i] ?? s.items;
|
|
775
775
|
if (itemSchema)
|
|
776
|
-
errors.push(...validateValue(
|
|
776
|
+
errors.push(...validateValue(document3, itemSchema, item, [...path, i]));
|
|
777
777
|
});
|
|
778
778
|
}
|
|
779
779
|
if (actual === "object") {
|
|
@@ -789,16 +789,16 @@ var validateValue = (document2, schema, value, path = []) => {
|
|
|
789
789
|
for (const key of keys) {
|
|
790
790
|
const property = s.properties?.[key];
|
|
791
791
|
if (property) {
|
|
792
|
-
errors.push(...validateValue(
|
|
792
|
+
errors.push(...validateValue(document3, property, record2[key], [...path, key]));
|
|
793
793
|
continue;
|
|
794
794
|
}
|
|
795
795
|
if (s.additionalProperties === false)
|
|
796
796
|
fail2(`unexpected property ${key}`);
|
|
797
797
|
else if (typeof s.additionalProperties === "object") {
|
|
798
|
-
errors.push(...validateValue(
|
|
798
|
+
errors.push(...validateValue(document3, s.additionalProperties, record2[key], [...path, key]));
|
|
799
799
|
}
|
|
800
800
|
if (s.propertyNames) {
|
|
801
|
-
const nameErrors = validateValue(
|
|
801
|
+
const nameErrors = validateValue(document3, s.propertyNames, key, [...path, key]);
|
|
802
802
|
if (nameErrors.length > 0)
|
|
803
803
|
fail2(`property name ${key} is invalid: ${nameErrors[0]?.message}`);
|
|
804
804
|
}
|
|
@@ -806,15 +806,15 @@ var validateValue = (document2, schema, value, path = []) => {
|
|
|
806
806
|
}
|
|
807
807
|
if (s.allOf)
|
|
808
808
|
for (const branch of s.allOf)
|
|
809
|
-
errors.push(...validateValue(
|
|
810
|
-
if (s.anyOf && !s.anyOf.some((branch) => validateValue(
|
|
809
|
+
errors.push(...validateValue(document3, branch, value, path));
|
|
810
|
+
if (s.anyOf && !s.anyOf.some((branch) => validateValue(document3, branch, value).length === 0))
|
|
811
811
|
fail2("matches no anyOf branch");
|
|
812
812
|
if (s.oneOf) {
|
|
813
|
-
const matches2 = s.oneOf.filter((branch) => validateValue(
|
|
813
|
+
const matches2 = s.oneOf.filter((branch) => validateValue(document3, branch, value).length === 0).length;
|
|
814
814
|
if (matches2 !== 1)
|
|
815
815
|
fail2(`matches ${matches2} oneOf branches, expected exactly 1`);
|
|
816
816
|
}
|
|
817
|
-
if (s.not && validateValue(
|
|
817
|
+
if (s.not && validateValue(document3, s.not, value).length === 0)
|
|
818
818
|
fail2("matches forbidden `not` schema");
|
|
819
819
|
return errors;
|
|
820
820
|
};
|
|
@@ -1328,6 +1328,1232 @@ var clearNamespace = (sqlite, namespace) => {
|
|
|
1328
1328
|
});
|
|
1329
1329
|
};
|
|
1330
1330
|
|
|
1331
|
+
// ../../ui/dist/reset.js
|
|
1332
|
+
var CSS_RESET = `*,
|
|
1333
|
+
*::before,
|
|
1334
|
+
*::after {
|
|
1335
|
+
box-sizing: border-box;
|
|
1336
|
+
margin: 0;
|
|
1337
|
+
padding: 0;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
* {
|
|
1341
|
+
scrollbar-width: thin;
|
|
1342
|
+
scrollbar-color: color-mix(in srgb, CanvasText 35%, Canvas) Canvas;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
*::-webkit-scrollbar {
|
|
1346
|
+
width: 12px;
|
|
1347
|
+
height: 12px;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
*::-webkit-scrollbar-track,
|
|
1351
|
+
*::-webkit-scrollbar-corner {
|
|
1352
|
+
background: Canvas;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
*::-webkit-scrollbar-thumb {
|
|
1356
|
+
background: color-mix(in srgb, CanvasText 35%, Canvas);
|
|
1357
|
+
border: 3px solid Canvas;
|
|
1358
|
+
border-radius: 999px;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
html {
|
|
1362
|
+
hanging-punctuation: first allow-end last;
|
|
1363
|
+
-webkit-text-size-adjust: none;
|
|
1364
|
+
text-size-adjust: none;
|
|
1365
|
+
tab-size: 4;
|
|
1366
|
+
font-family:
|
|
1367
|
+
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
|
|
1368
|
+
"Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
|
|
1369
|
+
font-size: 16px;
|
|
1370
|
+
line-height: 1.5;
|
|
1371
|
+
-webkit-font-smoothing: antialiased;
|
|
1372
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1373
|
+
text-rendering: optimizeLegibility;
|
|
1374
|
+
-webkit-tap-highlight-color: transparent;
|
|
1375
|
+
scroll-behavior: smooth;
|
|
1376
|
+
background: Canvas;
|
|
1377
|
+
color: CanvasText;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
body {
|
|
1381
|
+
min-height: 100svh;
|
|
1382
|
+
line-height: 1.5;
|
|
1383
|
+
background: Canvas;
|
|
1384
|
+
color: CanvasText;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
h1 {
|
|
1388
|
+
font-size: 2em;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
h2 {
|
|
1392
|
+
font-size: 1.5em;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
h3 {
|
|
1396
|
+
font-size: 1.17em;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
h4 {
|
|
1400
|
+
font-size: 1em;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
h5 {
|
|
1404
|
+
font-size: 0.83em;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
h6 {
|
|
1408
|
+
font-size: 0.67em;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
h1,
|
|
1412
|
+
h2,
|
|
1413
|
+
h3,
|
|
1414
|
+
h4,
|
|
1415
|
+
h5,
|
|
1416
|
+
h6 {
|
|
1417
|
+
font-weight: 700;
|
|
1418
|
+
line-height: 1.2;
|
|
1419
|
+
text-wrap: balance;
|
|
1420
|
+
overflow-wrap: break-word;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
p,
|
|
1424
|
+
li,
|
|
1425
|
+
figcaption,
|
|
1426
|
+
dd,
|
|
1427
|
+
dt,
|
|
1428
|
+
blockquote {
|
|
1429
|
+
overflow-wrap: break-word;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
p,
|
|
1433
|
+
li,
|
|
1434
|
+
figcaption,
|
|
1435
|
+
blockquote {
|
|
1436
|
+
text-wrap: pretty;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
ul,
|
|
1440
|
+
ol,
|
|
1441
|
+
menu {
|
|
1442
|
+
list-style: none;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
a {
|
|
1446
|
+
color: inherit;
|
|
1447
|
+
text-decoration: underline;
|
|
1448
|
+
text-decoration-thickness: 1px;
|
|
1449
|
+
text-underline-offset: 0.15em;
|
|
1450
|
+
text-decoration-skip-ink: auto;
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
b,
|
|
1454
|
+
strong {
|
|
1455
|
+
font-weight: 700;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
small {
|
|
1459
|
+
font-size: 0.875em;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
code,
|
|
1463
|
+
kbd,
|
|
1464
|
+
samp,
|
|
1465
|
+
pre {
|
|
1466
|
+
font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1467
|
+
font-size: 1em;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
sub,
|
|
1471
|
+
sup {
|
|
1472
|
+
font-size: 75%;
|
|
1473
|
+
line-height: 0;
|
|
1474
|
+
position: relative;
|
|
1475
|
+
vertical-align: baseline;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
sub {
|
|
1479
|
+
bottom: -0.25em;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
sup {
|
|
1483
|
+
top: -0.5em;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
abbr[title] {
|
|
1487
|
+
text-decoration: underline dotted;
|
|
1488
|
+
text-underline-offset: 0.15em;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
mark {
|
|
1492
|
+
background: Mark;
|
|
1493
|
+
color: MarkText;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
hr {
|
|
1497
|
+
height: 0;
|
|
1498
|
+
border: 0;
|
|
1499
|
+
border-top: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1500
|
+
color: inherit;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
img,
|
|
1504
|
+
picture,
|
|
1505
|
+
video,
|
|
1506
|
+
canvas {
|
|
1507
|
+
display: block;
|
|
1508
|
+
max-width: 100%;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
img,
|
|
1512
|
+
video {
|
|
1513
|
+
height: auto;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
svg {
|
|
1517
|
+
overflow: hidden;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
iframe {
|
|
1521
|
+
border: 0;
|
|
1522
|
+
max-width: 100%;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
table {
|
|
1526
|
+
border-collapse: collapse;
|
|
1527
|
+
border-spacing: 0;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
fieldset {
|
|
1531
|
+
border: 0;
|
|
1532
|
+
min-inline-size: 0;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
legend {
|
|
1536
|
+
padding: 0;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
button,
|
|
1540
|
+
input,
|
|
1541
|
+
select,
|
|
1542
|
+
textarea,
|
|
1543
|
+
optgroup {
|
|
1544
|
+
font: inherit;
|
|
1545
|
+
letter-spacing: inherit;
|
|
1546
|
+
color: inherit;
|
|
1547
|
+
margin: 0;
|
|
1548
|
+
vertical-align: middle;
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
button,
|
|
1552
|
+
input[type="button"],
|
|
1553
|
+
input[type="submit"],
|
|
1554
|
+
input[type="reset"] {
|
|
1555
|
+
appearance: none;
|
|
1556
|
+
background: none;
|
|
1557
|
+
border: 0;
|
|
1558
|
+
padding: 0;
|
|
1559
|
+
cursor: pointer;
|
|
1560
|
+
text-align: center;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
input,
|
|
1564
|
+
textarea,
|
|
1565
|
+
select {
|
|
1566
|
+
background-color: Canvas;
|
|
1567
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1568
|
+
border-radius: 0;
|
|
1569
|
+
padding: 0.5em 0.65em;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
input[type="checkbox"],
|
|
1573
|
+
input[type="radio"],
|
|
1574
|
+
input[type="range"],
|
|
1575
|
+
input[type="file"],
|
|
1576
|
+
input[type="color"],
|
|
1577
|
+
input[type="button"],
|
|
1578
|
+
input[type="submit"],
|
|
1579
|
+
input[type="reset"],
|
|
1580
|
+
input[type="image"],
|
|
1581
|
+
input[type="hidden"] {
|
|
1582
|
+
background: none;
|
|
1583
|
+
border: 0;
|
|
1584
|
+
padding: 0;
|
|
1585
|
+
border-radius: 0;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
input[type="checkbox"],
|
|
1589
|
+
input[type="radio"] {
|
|
1590
|
+
accent-color: CanvasText;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
input[type="search"] {
|
|
1594
|
+
appearance: none;
|
|
1595
|
+
background-color: Canvas;
|
|
1596
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
input[type="search"]::-webkit-search-decoration,
|
|
1600
|
+
input[type="search"]::-webkit-search-cancel-button,
|
|
1601
|
+
input[type="search"]::-webkit-search-results-button,
|
|
1602
|
+
input[type="search"]::-webkit-search-results-decoration {
|
|
1603
|
+
-webkit-appearance: none;
|
|
1604
|
+
display: none;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
input[type="number"] {
|
|
1608
|
+
appearance: textfield;
|
|
1609
|
+
background-color: Canvas;
|
|
1610
|
+
border: 1px solid color-mix(in srgb, CanvasText 28%, transparent);
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
input[type="number"]::-webkit-inner-spin-button,
|
|
1614
|
+
input[type="number"]::-webkit-outer-spin-button {
|
|
1615
|
+
-webkit-appearance: none;
|
|
1616
|
+
margin: 0;
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
textarea {
|
|
1620
|
+
resize: vertical;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
::placeholder {
|
|
1624
|
+
opacity: 1;
|
|
1625
|
+
color: color-mix(in srgb, CanvasText 45%, transparent);
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
:focus-visible {
|
|
1629
|
+
outline: 2px solid CanvasText;
|
|
1630
|
+
outline-offset: 2px;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
:focus:not(:focus-visible) {
|
|
1634
|
+
outline: none;
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
:disabled,
|
|
1638
|
+
[disabled] {
|
|
1639
|
+
cursor: default;
|
|
1640
|
+
opacity: 0.6;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
label,
|
|
1644
|
+
summary,
|
|
1645
|
+
select,
|
|
1646
|
+
[role="button"] {
|
|
1647
|
+
cursor: pointer;
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
summary {
|
|
1651
|
+
display: list-item;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
details {
|
|
1655
|
+
display: block;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
dialog {
|
|
1659
|
+
margin: auto;
|
|
1660
|
+
padding: 1rem;
|
|
1661
|
+
border: 1px solid color-mix(in srgb, CanvasText 20%, transparent);
|
|
1662
|
+
background: Canvas;
|
|
1663
|
+
color: CanvasText;
|
|
1664
|
+
max-width: calc(100vw - 2rem);
|
|
1665
|
+
max-height: calc(100svh - 2rem);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
dialog:not([open]) {
|
|
1669
|
+
display: none;
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
::backdrop {
|
|
1673
|
+
background: color-mix(in srgb, CanvasText 40%, transparent);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
[hidden] {
|
|
1677
|
+
display: none !important;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
::selection {
|
|
1681
|
+
background: Highlight;
|
|
1682
|
+
color: HighlightText;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1686
|
+
*,
|
|
1687
|
+
*::before,
|
|
1688
|
+
*::after {
|
|
1689
|
+
animation-duration: 0.01ms !important;
|
|
1690
|
+
animation-iteration-count: 1 !important;
|
|
1691
|
+
transition-duration: 0.01ms !important;
|
|
1692
|
+
scroll-behavior: auto !important;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
@media (pointer: coarse) {
|
|
1697
|
+
input,
|
|
1698
|
+
select,
|
|
1699
|
+
textarea {
|
|
1700
|
+
font-size: max(16px, 1em);
|
|
1701
|
+
}
|
|
1702
|
+
}`;
|
|
1703
|
+
|
|
1704
|
+
// ../core/dist/admin-client.js
|
|
1705
|
+
function isRecord2(value) {
|
|
1706
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1707
|
+
}
|
|
1708
|
+
function mountAdminBrand(doc, host, service, catalog) {
|
|
1709
|
+
const clip = (value, max) => {
|
|
1710
|
+
if (typeof value !== "string")
|
|
1711
|
+
return null;
|
|
1712
|
+
const trimmed = value.trim();
|
|
1713
|
+
if (trimmed === "")
|
|
1714
|
+
return null;
|
|
1715
|
+
return trimmed.length > max ? trimmed.slice(0, max) : trimmed;
|
|
1716
|
+
};
|
|
1717
|
+
const httpUrl = (value) => {
|
|
1718
|
+
if (typeof value !== "string" || value.length > 2e3)
|
|
1719
|
+
return null;
|
|
1720
|
+
try {
|
|
1721
|
+
const url = new URL(value);
|
|
1722
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1723
|
+
return null;
|
|
1724
|
+
return url.href;
|
|
1725
|
+
} catch {
|
|
1726
|
+
return null;
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
const hexColor = (value) => {
|
|
1730
|
+
if (typeof value !== "string")
|
|
1731
|
+
return null;
|
|
1732
|
+
const raw = value.trim();
|
|
1733
|
+
return /^#[0-9a-fA-F]{3,8}$/.test(raw) ? raw : null;
|
|
1734
|
+
};
|
|
1735
|
+
const hostname = (value) => {
|
|
1736
|
+
try {
|
|
1737
|
+
return new URL(value).hostname.replace(/^www\./, "");
|
|
1738
|
+
} catch {
|
|
1739
|
+
return value;
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
host.replaceChildren();
|
|
1743
|
+
host.hidden = true;
|
|
1744
|
+
if (!isRecord2(catalog) || !Object.hasOwn(catalog, service))
|
|
1745
|
+
return;
|
|
1746
|
+
const row = catalog[service];
|
|
1747
|
+
if (!isRecord2(row))
|
|
1748
|
+
return;
|
|
1749
|
+
const vendor = clip(row.vendor, 80);
|
|
1750
|
+
const website = httpUrl(row.website);
|
|
1751
|
+
const guide = httpUrl(row.guide);
|
|
1752
|
+
const docs = httpUrl(row.docs);
|
|
1753
|
+
const logo = httpUrl(row.logo);
|
|
1754
|
+
const color = hexColor(row.color);
|
|
1755
|
+
const description = clip(row.description, 280);
|
|
1756
|
+
if (vendor === null || website === null && guide === null && docs === null)
|
|
1757
|
+
return;
|
|
1758
|
+
const add = (node) => {
|
|
1759
|
+
host.append(node);
|
|
1760
|
+
return node;
|
|
1761
|
+
};
|
|
1762
|
+
if (logo !== null) {
|
|
1763
|
+
const img = doc.createElement("img");
|
|
1764
|
+
img.alt = "";
|
|
1765
|
+
img.src = logo;
|
|
1766
|
+
img.width = 16;
|
|
1767
|
+
img.height = 16;
|
|
1768
|
+
img.decoding = "async";
|
|
1769
|
+
img.referrerPolicy = "no-referrer";
|
|
1770
|
+
if (color !== null)
|
|
1771
|
+
img.style.borderColor = color;
|
|
1772
|
+
add(img);
|
|
1773
|
+
}
|
|
1774
|
+
const name = doc.createElement("span");
|
|
1775
|
+
name.className = "vendor-name";
|
|
1776
|
+
name.textContent = vendor;
|
|
1777
|
+
if (description !== null)
|
|
1778
|
+
name.title = description;
|
|
1779
|
+
add(name);
|
|
1780
|
+
const sep = () => {
|
|
1781
|
+
const node = doc.createElement("span");
|
|
1782
|
+
node.className = "vendor-sep";
|
|
1783
|
+
node.setAttribute("aria-hidden", "true");
|
|
1784
|
+
node.textContent = "\xB7";
|
|
1785
|
+
return node;
|
|
1786
|
+
};
|
|
1787
|
+
const link = (href, label, title) => {
|
|
1788
|
+
const node = doc.createElement("a");
|
|
1789
|
+
node.className = "vendor-link";
|
|
1790
|
+
node.href = href;
|
|
1791
|
+
node.target = "_blank";
|
|
1792
|
+
node.rel = "noopener noreferrer";
|
|
1793
|
+
node.referrerPolicy = "no-referrer";
|
|
1794
|
+
node.textContent = label;
|
|
1795
|
+
node.title = title;
|
|
1796
|
+
return node;
|
|
1797
|
+
};
|
|
1798
|
+
if (website !== null) {
|
|
1799
|
+
add(sep());
|
|
1800
|
+
add(link(website, hostname(website), `${vendor} website`));
|
|
1801
|
+
}
|
|
1802
|
+
if (guide !== null) {
|
|
1803
|
+
add(sep());
|
|
1804
|
+
add(link(guide, "Docs", `Docs for ${vendor}`));
|
|
1805
|
+
}
|
|
1806
|
+
if (docs !== null) {
|
|
1807
|
+
add(sep());
|
|
1808
|
+
add(link(docs, "API", `${vendor} API reference`));
|
|
1809
|
+
}
|
|
1810
|
+
host.removeAttribute("hidden");
|
|
1811
|
+
host.hidden = false;
|
|
1812
|
+
}
|
|
1813
|
+
function startAdminBrand(env) {
|
|
1814
|
+
const requested = env.params.get("brands");
|
|
1815
|
+
let brandsUrl = env.brandsUrl;
|
|
1816
|
+
if (requested) {
|
|
1817
|
+
try {
|
|
1818
|
+
const url = new URL(requested, env.location.href);
|
|
1819
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1" || url.hostname === "[::1]" || url.origin === env.location.origin;
|
|
1820
|
+
if ((url.protocol === "https:" || url.protocol === "http:") && local)
|
|
1821
|
+
brandsUrl = url.href;
|
|
1822
|
+
} catch {
|
|
1823
|
+
brandsUrl = env.brandsUrl;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
const vendorHost = env.$("vendor");
|
|
1827
|
+
const brandRoot = env.document.querySelector("[data-mockingbird-admin]");
|
|
1828
|
+
const brandService = brandRoot?.getAttribute("data-service") || "";
|
|
1829
|
+
if (vendorHost === null)
|
|
1830
|
+
return;
|
|
1831
|
+
env.fetch(brandsUrl, {
|
|
1832
|
+
headers: { accept: "application/json" },
|
|
1833
|
+
signal: AbortSignal.timeout(5e3)
|
|
1834
|
+
}).then(async (response) => {
|
|
1835
|
+
if (!response.ok)
|
|
1836
|
+
return null;
|
|
1837
|
+
const catalog = await response.json();
|
|
1838
|
+
return catalog;
|
|
1839
|
+
}).then((catalog) => {
|
|
1840
|
+
mountAdminBrand(env.document, vendorHost, brandService, catalog);
|
|
1841
|
+
}).catch(() => {
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
function faultPresetList(value) {
|
|
1845
|
+
if (!isRecord2(value))
|
|
1846
|
+
throw new Error("Fault presets response was not an object");
|
|
1847
|
+
if (!Object.hasOwn(value, "presets") || value.presets === void 0 || value.presets === null) {
|
|
1848
|
+
return { presets: [] };
|
|
1849
|
+
}
|
|
1850
|
+
if (!Array.isArray(value.presets))
|
|
1851
|
+
throw new Error("Fault presets response was not a list");
|
|
1852
|
+
return {
|
|
1853
|
+
presets: value.presets.flatMap((item) => {
|
|
1854
|
+
if (!isRecord2(item) || typeof item.name !== "string")
|
|
1855
|
+
return [];
|
|
1856
|
+
return [{ name: item.name }];
|
|
1857
|
+
})
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
function bootAdmin(config) {
|
|
1861
|
+
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1862
|
+
const sources = ["declared", "inferred", "mixed"];
|
|
1863
|
+
const isFieldKind = (value) => typeof value === "string" && fieldKinds.some((kind) => kind === value);
|
|
1864
|
+
const isSource = (value) => typeof value === "string" && sources.some((source) => source === value);
|
|
1865
|
+
const readJson2 = (text) => {
|
|
1866
|
+
const value = JSON.parse(text);
|
|
1867
|
+
return value;
|
|
1868
|
+
};
|
|
1869
|
+
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => {
|
|
1870
|
+
switch (char) {
|
|
1871
|
+
case "&":
|
|
1872
|
+
return "&";
|
|
1873
|
+
case "<":
|
|
1874
|
+
return "<";
|
|
1875
|
+
case ">":
|
|
1876
|
+
return ">";
|
|
1877
|
+
case '"':
|
|
1878
|
+
return """;
|
|
1879
|
+
default:
|
|
1880
|
+
return "'";
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
const el = (id, kind) => {
|
|
1884
|
+
const node = document.getElementById(id);
|
|
1885
|
+
if (!(node instanceof kind))
|
|
1886
|
+
throw new Error(`admin shell is missing #${id}`);
|
|
1887
|
+
return node;
|
|
1888
|
+
};
|
|
1889
|
+
const errorMessage = (data, fallback) => {
|
|
1890
|
+
if (!isRecord2(data))
|
|
1891
|
+
return fallback;
|
|
1892
|
+
const error = data.error;
|
|
1893
|
+
if (!isRecord2(error) || typeof error.message !== "string" || error.message === "") {
|
|
1894
|
+
return fallback;
|
|
1895
|
+
}
|
|
1896
|
+
return error.message;
|
|
1897
|
+
};
|
|
1898
|
+
const requireList = (value, label) => {
|
|
1899
|
+
if (value === void 0 || value === null)
|
|
1900
|
+
return [];
|
|
1901
|
+
if (!Array.isArray(value))
|
|
1902
|
+
throw new Error(`${label} was not a list`);
|
|
1903
|
+
return value;
|
|
1904
|
+
};
|
|
1905
|
+
const state = {
|
|
1906
|
+
namespace: "default",
|
|
1907
|
+
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1908
|
+
view: "overview",
|
|
1909
|
+
collection: "",
|
|
1910
|
+
shape: null,
|
|
1911
|
+
route: null,
|
|
1912
|
+
editing: null
|
|
1913
|
+
};
|
|
1914
|
+
const standard = new Set(config.standardRoutes);
|
|
1915
|
+
const banner = el("banner", HTMLElement);
|
|
1916
|
+
const keyInput = el("admin-key", HTMLInputElement);
|
|
1917
|
+
keyInput.value = state.key;
|
|
1918
|
+
const params = new URLSearchParams(location.search);
|
|
1919
|
+
const queryKey = params.get("key");
|
|
1920
|
+
if (queryKey) {
|
|
1921
|
+
state.key = queryKey;
|
|
1922
|
+
keyInput.value = state.key;
|
|
1923
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
1924
|
+
params.delete("key");
|
|
1925
|
+
const next = params.toString();
|
|
1926
|
+
history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
|
|
1927
|
+
}
|
|
1928
|
+
const queryNamespace = params.get("namespace");
|
|
1929
|
+
if (queryNamespace)
|
|
1930
|
+
state.namespace = queryNamespace;
|
|
1931
|
+
const showError = (error) => {
|
|
1932
|
+
banner.textContent = error instanceof Error ? error.message : String(error);
|
|
1933
|
+
banner.classList.add("show");
|
|
1934
|
+
};
|
|
1935
|
+
const clearError = () => {
|
|
1936
|
+
banner.classList.remove("show");
|
|
1937
|
+
};
|
|
1938
|
+
const api = async (method, path, body) => {
|
|
1939
|
+
const headers = { accept: "application/json" };
|
|
1940
|
+
if (state.key !== "")
|
|
1941
|
+
headers[config.adminKeyHeader] = state.key;
|
|
1942
|
+
if (state.namespace !== "")
|
|
1943
|
+
headers["x-mockingbird-namespace"] = state.namespace;
|
|
1944
|
+
if (body !== void 0)
|
|
1945
|
+
headers["content-type"] = "application/json";
|
|
1946
|
+
const init = { method, headers };
|
|
1947
|
+
if (body !== void 0)
|
|
1948
|
+
init.body = JSON.stringify(body);
|
|
1949
|
+
const response = await fetch(config.adminPrefix + path, init);
|
|
1950
|
+
const text = await response.text();
|
|
1951
|
+
let data = null;
|
|
1952
|
+
if (text !== "") {
|
|
1953
|
+
try {
|
|
1954
|
+
data = readJson2(text);
|
|
1955
|
+
} catch {
|
|
1956
|
+
data = { raw: text };
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
if (response.status === 401) {
|
|
1960
|
+
keyInput.focus();
|
|
1961
|
+
throw new Error(errorMessage(data, "Admin key required"));
|
|
1962
|
+
}
|
|
1963
|
+
if (!response.ok) {
|
|
1964
|
+
throw new Error(errorMessage(data, `${response.status} ${method} ${path}`));
|
|
1965
|
+
}
|
|
1966
|
+
return data;
|
|
1967
|
+
};
|
|
1968
|
+
const originGet = async (path) => {
|
|
1969
|
+
const response = await fetch(path, { headers: { accept: "application/json" } });
|
|
1970
|
+
if (!response.ok)
|
|
1971
|
+
throw new Error(`${response.status} ${path}`);
|
|
1972
|
+
const value = await response.json();
|
|
1973
|
+
return value;
|
|
1974
|
+
};
|
|
1975
|
+
const panelApi = {
|
|
1976
|
+
get: (path) => api("GET", path),
|
|
1977
|
+
send: (method, path, body) => api(method, path, body),
|
|
1978
|
+
namespace: () => state.namespace
|
|
1979
|
+
};
|
|
1980
|
+
const isPanelScript = (value) => typeof value === "function";
|
|
1981
|
+
const setTheme = (theme) => {
|
|
1982
|
+
if (theme)
|
|
1983
|
+
document.documentElement.dataset.theme = theme;
|
|
1984
|
+
else
|
|
1985
|
+
delete document.documentElement.dataset.theme;
|
|
1986
|
+
};
|
|
1987
|
+
const storedTheme = localStorage.getItem("mockingbird-admin-theme");
|
|
1988
|
+
if (storedTheme)
|
|
1989
|
+
setTheme(storedTheme);
|
|
1990
|
+
el("theme", HTMLButtonElement).addEventListener("click", () => {
|
|
1991
|
+
const current = document.documentElement.dataset.theme;
|
|
1992
|
+
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
1993
|
+
const next = dark ? "light" : "dark";
|
|
1994
|
+
localStorage.setItem("mockingbird-admin-theme", next);
|
|
1995
|
+
setTheme(next);
|
|
1996
|
+
});
|
|
1997
|
+
const show = (view) => {
|
|
1998
|
+
state.view = view;
|
|
1999
|
+
for (const button of document.querySelectorAll("#nav button")) {
|
|
2000
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2001
|
+
continue;
|
|
2002
|
+
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false");
|
|
2003
|
+
}
|
|
2004
|
+
for (const section of document.querySelectorAll("main .view")) {
|
|
2005
|
+
if (!(section instanceof HTMLElement))
|
|
2006
|
+
continue;
|
|
2007
|
+
section.hidden = section.id !== `view-${view}`;
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
el("nav", HTMLElement).addEventListener("click", (event) => {
|
|
2011
|
+
const target = event.target;
|
|
2012
|
+
if (!(target instanceof Element))
|
|
2013
|
+
return;
|
|
2014
|
+
const button = target.closest("button[data-view]");
|
|
2015
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2016
|
+
return;
|
|
2017
|
+
const view = button.dataset.view;
|
|
2018
|
+
if (view === void 0)
|
|
2019
|
+
return;
|
|
2020
|
+
show(view);
|
|
2021
|
+
refresh().catch(showError);
|
|
2022
|
+
});
|
|
2023
|
+
const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
|
|
2024
|
+
const table = (columns, rows) => {
|
|
2025
|
+
if (rows.length === 0)
|
|
2026
|
+
return '<p class="empty">Nothing here yet.</p>';
|
|
2027
|
+
const head = `<tr>${columns.map((column) => `<th>${column.label}</th>`).join("")}</tr>`;
|
|
2028
|
+
const body = rows.map((row) => {
|
|
2029
|
+
const cells = columns.map((column) => `<td data-label="${column.label}">${column.cell(row)}</td>`).join("");
|
|
2030
|
+
const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
|
|
2031
|
+
return `<tr${attrs}>${cells}</tr>`;
|
|
2032
|
+
}).join("");
|
|
2033
|
+
return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
2034
|
+
};
|
|
2035
|
+
const preview = (value) => {
|
|
2036
|
+
const text = JSON.stringify(value) ?? "null";
|
|
2037
|
+
return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
|
|
2038
|
+
};
|
|
2039
|
+
const when = (epoch) => {
|
|
2040
|
+
const date = new Date(epoch);
|
|
2041
|
+
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
|
|
2042
|
+
};
|
|
2043
|
+
const clockCard = (epoch) => {
|
|
2044
|
+
const date = new Date(epoch);
|
|
2045
|
+
if (Number.isNaN(date.getTime()))
|
|
2046
|
+
return esc(String(epoch));
|
|
2047
|
+
const iso = date.toISOString();
|
|
2048
|
+
return `${esc(iso.slice(0, 10))}<span class="clock-time">${esc(iso.slice(11, 19))} UTC</span>`;
|
|
2049
|
+
};
|
|
2050
|
+
const decodeClock = (value) => {
|
|
2051
|
+
if (!isRecord2(value) || typeof value.now !== "number" || typeof value.offsetMs !== "number" || typeof value.frozen !== "boolean") {
|
|
2052
|
+
throw new Error("Clock response was not a clock");
|
|
2053
|
+
}
|
|
2054
|
+
return { now: value.now, offsetMs: value.offsetMs, frozen: value.frozen };
|
|
2055
|
+
};
|
|
2056
|
+
const decodeField = (value) => {
|
|
2057
|
+
if (!isRecord2(value) || typeof value.name !== "string" || !isFieldKind(value.kind)) {
|
|
2058
|
+
return void 0;
|
|
2059
|
+
}
|
|
2060
|
+
const field = {
|
|
2061
|
+
name: value.name,
|
|
2062
|
+
kind: value.kind,
|
|
2063
|
+
optional: value.optional === true
|
|
2064
|
+
};
|
|
2065
|
+
if (typeof value.description === "string")
|
|
2066
|
+
field.description = value.description;
|
|
2067
|
+
if (Array.isArray(value.fields)) {
|
|
2068
|
+
field.fields = value.fields.flatMap((item) => {
|
|
2069
|
+
const child = decodeField(item);
|
|
2070
|
+
return child === void 0 ? [] : [child];
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
return field;
|
|
2074
|
+
};
|
|
2075
|
+
const decodeCollection = (value) => {
|
|
2076
|
+
if (!isRecord2(value) || typeof value.name !== "string")
|
|
2077
|
+
return void 0;
|
|
2078
|
+
const fields = Array.isArray(value.fields) ? value.fields.flatMap((item) => {
|
|
2079
|
+
const field = decodeField(item);
|
|
2080
|
+
return field === void 0 ? [] : [field];
|
|
2081
|
+
}) : [];
|
|
2082
|
+
const collection = {
|
|
2083
|
+
name: value.name,
|
|
2084
|
+
label: typeof value.label === "string" ? value.label : value.name,
|
|
2085
|
+
count: typeof value.count === "number" ? value.count : 0,
|
|
2086
|
+
source: isSource(value.source) ? value.source : "inferred",
|
|
2087
|
+
fields
|
|
2088
|
+
};
|
|
2089
|
+
if (typeof value.description === "string")
|
|
2090
|
+
collection.description = value.description;
|
|
2091
|
+
return collection;
|
|
2092
|
+
};
|
|
2093
|
+
const decodeState = (value) => {
|
|
2094
|
+
if (!isRecord2(value) || !Array.isArray(value.collections)) {
|
|
2095
|
+
throw new Error("State response has no collection list");
|
|
2096
|
+
}
|
|
2097
|
+
return {
|
|
2098
|
+
namespace: typeof value.namespace === "string" ? value.namespace : state.namespace,
|
|
2099
|
+
storageNamespace: typeof value.storageNamespace === "string" ? value.storageNamespace : "",
|
|
2100
|
+
collections: value.collections.flatMap((item) => {
|
|
2101
|
+
const collection = decodeCollection(item);
|
|
2102
|
+
return collection === void 0 ? [] : [collection];
|
|
2103
|
+
})
|
|
2104
|
+
};
|
|
2105
|
+
};
|
|
2106
|
+
const decodeRecords = (value) => requireList(isRecord2(value) ? value.records : void 0, "Records").flatMap((item) => {
|
|
2107
|
+
if (!isRecord2(item) || typeof item.id !== "string")
|
|
2108
|
+
return [];
|
|
2109
|
+
return [
|
|
2110
|
+
{
|
|
2111
|
+
id: item.id,
|
|
2112
|
+
seq: typeof item.seq === "number" ? item.seq : 0,
|
|
2113
|
+
value: item.value,
|
|
2114
|
+
attrs: ` class="clickable" data-id="${esc(item.id)}"`
|
|
2115
|
+
}
|
|
2116
|
+
];
|
|
2117
|
+
});
|
|
2118
|
+
const textOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : "";
|
|
2119
|
+
const decodeJournal = (value) => requireList(isRecord2(value) ? value.requests : void 0, "Journal").flatMap((item) => {
|
|
2120
|
+
if (!isRecord2(item))
|
|
2121
|
+
return [];
|
|
2122
|
+
return [
|
|
2123
|
+
{
|
|
2124
|
+
at: textOf(item.at),
|
|
2125
|
+
method: textOf(item.method),
|
|
2126
|
+
path: textOf(item.path),
|
|
2127
|
+
status: textOf(item.status),
|
|
2128
|
+
durationMs: textOf(item.durationMs),
|
|
2129
|
+
operationId: textOf(item.operationId)
|
|
2130
|
+
}
|
|
2131
|
+
];
|
|
2132
|
+
});
|
|
2133
|
+
const decodeFaults = (value) => requireList(isRecord2(value) ? value.faults : void 0, "Faults").flatMap((item) => {
|
|
2134
|
+
if (!isRecord2(item))
|
|
2135
|
+
return [];
|
|
2136
|
+
return [
|
|
2137
|
+
{
|
|
2138
|
+
id: textOf(item.id),
|
|
2139
|
+
method: typeof item.method === "string" ? item.method : void 0,
|
|
2140
|
+
pathPrefix: typeof item.pathPrefix === "string" ? item.pathPrefix : void 0,
|
|
2141
|
+
operationId: typeof item.operationId === "string" ? item.operationId : void 0,
|
|
2142
|
+
status: typeof item.status === "number" ? item.status : void 0,
|
|
2143
|
+
effect: typeof item.effect === "string" ? item.effect : void 0,
|
|
2144
|
+
drop: typeof item.drop === "boolean" ? item.drop : void 0,
|
|
2145
|
+
latencyMs: typeof item.latencyMs === "number" ? item.latencyMs : void 0
|
|
2146
|
+
}
|
|
2147
|
+
];
|
|
2148
|
+
});
|
|
2149
|
+
const loadNamespaces = async () => {
|
|
2150
|
+
const data = await api("GET", "/namespaces");
|
|
2151
|
+
const select = el("namespace", HTMLSelectElement);
|
|
2152
|
+
const listed = requireList(isRecord2(data) ? data.namespaces : void 0, "Namespaces");
|
|
2153
|
+
const fallback = isRecord2(data) && typeof data.default === "string" && data.default !== "" ? data.default : "default";
|
|
2154
|
+
const names = (listed.length > 0 ? listed.map((name) => String(name)) : [fallback]).slice();
|
|
2155
|
+
if (!names.includes(state.namespace))
|
|
2156
|
+
names.unshift(state.namespace);
|
|
2157
|
+
select.innerHTML = names.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join("");
|
|
2158
|
+
select.value = state.namespace;
|
|
2159
|
+
};
|
|
2160
|
+
const renderOverview = async () => {
|
|
2161
|
+
const [health, shape, clock, journal] = await Promise.all([
|
|
2162
|
+
originGet("/health"),
|
|
2163
|
+
api("GET", "/state"),
|
|
2164
|
+
api("GET", "/clock"),
|
|
2165
|
+
api("GET", "/requests?limit=8")
|
|
2166
|
+
]);
|
|
2167
|
+
if (!isRecord2(health))
|
|
2168
|
+
throw new Error("Health response was not an object");
|
|
2169
|
+
const decoded = decodeState(shape);
|
|
2170
|
+
state.shape = decoded;
|
|
2171
|
+
const time = decodeClock(clock);
|
|
2172
|
+
el("overview-cards", HTMLElement).innerHTML = cards([
|
|
2173
|
+
{
|
|
2174
|
+
k: "Service",
|
|
2175
|
+
v: esc(typeof health.service === "string" && health.service !== "" ? health.service : config.service)
|
|
2176
|
+
},
|
|
2177
|
+
{
|
|
2178
|
+
k: "Status",
|
|
2179
|
+
v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
|
|
2180
|
+
},
|
|
2181
|
+
{ k: "Namespace", v: esc(state.namespace) },
|
|
2182
|
+
{ k: "Collections", v: String(decoded.collections.length) },
|
|
2183
|
+
{
|
|
2184
|
+
k: "Records",
|
|
2185
|
+
v: String(decoded.collections.reduce((sum, item) => sum + item.count, 0))
|
|
2186
|
+
},
|
|
2187
|
+
{ k: "Clock", v: clockCard(time.now) }
|
|
2188
|
+
]);
|
|
2189
|
+
el("overview-requests", HTMLElement).innerHTML = table([
|
|
2190
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2191
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2192
|
+
{
|
|
2193
|
+
label: "Status",
|
|
2194
|
+
cell: (row) => `<span class="status-${row.status.charAt(0)}">${esc(row.status)}</span>`
|
|
2195
|
+
},
|
|
2196
|
+
{ label: "Operation", cell: (row) => esc(row.operationId) }
|
|
2197
|
+
], decodeJournal(journal));
|
|
2198
|
+
};
|
|
2199
|
+
const schemaChips = (collection) => {
|
|
2200
|
+
if (collection.fields.length === 0) {
|
|
2201
|
+
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>';
|
|
2202
|
+
}
|
|
2203
|
+
return `<div class="chips">${collection.fields.map((field) => `<span class="chip">${esc(field.name)} <i>${esc(field.kind)}${field.optional ? "?" : ""}</i></span>`).join("")}</div>`;
|
|
2204
|
+
};
|
|
2205
|
+
const renderState = async () => {
|
|
2206
|
+
const shape = decodeState(await api("GET", "/state"));
|
|
2207
|
+
state.shape = shape;
|
|
2208
|
+
const host = el("collections", HTMLElement);
|
|
2209
|
+
if (shape.collections.length === 0) {
|
|
2210
|
+
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>';
|
|
2211
|
+
el("schema", HTMLElement).innerHTML = "";
|
|
2212
|
+
el("records", HTMLElement).innerHTML = "";
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
2216
|
+
const first = shape.collections[0];
|
|
2217
|
+
if (first === void 0)
|
|
2218
|
+
return;
|
|
2219
|
+
state.collection = first.name;
|
|
2220
|
+
}
|
|
2221
|
+
host.innerHTML = shape.collections.map((item) => `<button type="button" class="collection" data-collection="${esc(item.name)}" aria-current="${item.name === state.collection ? "true" : "false"}"><strong>${esc(item.label)}</strong><small>${esc(item.count)} \xB7 ${esc(item.source)}</small></button>`).join("");
|
|
2222
|
+
const selected = shape.collections.find((item) => item.name === state.collection);
|
|
2223
|
+
if (selected === void 0)
|
|
2224
|
+
return;
|
|
2225
|
+
const description = selected.description ? `<p class="lede">${esc(selected.description)}</p>` : "";
|
|
2226
|
+
el("schema", HTMLElement).innerHTML = `<h3>${esc(selected.label)}</h3>${description}${schemaChips(selected)}`;
|
|
2227
|
+
const page = await api("GET", `/state/${encodeURIComponent(state.collection)}?limit=50`);
|
|
2228
|
+
el("records", HTMLElement).innerHTML = table([
|
|
2229
|
+
{ label: "Id", cell: (row) => `<code>${esc(row.id)}</code>` },
|
|
2230
|
+
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
2231
|
+
{ label: "Value", cell: (row) => preview(row.value) }
|
|
2232
|
+
], decodeRecords(page));
|
|
2233
|
+
};
|
|
2234
|
+
const renderClock = async () => {
|
|
2235
|
+
const clock = decodeClock(await api("GET", "/clock"));
|
|
2236
|
+
el("clock-readout", HTMLElement).innerHTML = `<div class="k">Now</div><div class="v">${esc(when(clock.now))}</div><p>${esc(clock.now)} ms \xB7 offset ${esc(clock.offsetMs)} ms ${clock.frozen ? "<span class='badge warn'>frozen</span>" : "<span class='badge ok'>live</span>"}</p>`;
|
|
2237
|
+
const freeze = el("freeze", HTMLButtonElement);
|
|
2238
|
+
freeze.textContent = clock.frozen ? "Unfreeze" : "Freeze";
|
|
2239
|
+
freeze.dataset.frozen = clock.frozen ? "1" : "0";
|
|
2240
|
+
};
|
|
2241
|
+
const renderFaults = async () => {
|
|
2242
|
+
const [faults, presets] = await Promise.all([
|
|
2243
|
+
api("GET", "/faults"),
|
|
2244
|
+
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2245
|
+
]);
|
|
2246
|
+
const select = el("fault-preset", HTMLSelectElement);
|
|
2247
|
+
const current = select.value;
|
|
2248
|
+
const list = faultPresetList(presets).presets;
|
|
2249
|
+
select.innerHTML = `<option value="">Custom rule</option>${list.map((preset) => `<option value="${esc(preset.name)}">${esc(preset.name)}</option>`).join("")}`;
|
|
2250
|
+
select.value = current;
|
|
2251
|
+
el("fault-list", HTMLElement).innerHTML = table([
|
|
2252
|
+
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2253
|
+
{
|
|
2254
|
+
label: "Match",
|
|
2255
|
+
cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter((part) => Boolean(part)).join(" ") || "all")
|
|
2256
|
+
},
|
|
2257
|
+
{
|
|
2258
|
+
label: "Effect",
|
|
2259
|
+
cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || ""))
|
|
2260
|
+
}
|
|
2261
|
+
], decodeFaults(faults));
|
|
2262
|
+
};
|
|
2263
|
+
const renderJournal = async () => {
|
|
2264
|
+
const journal = await api("GET", "/requests?limit=100");
|
|
2265
|
+
el("journal", HTMLElement).innerHTML = table([
|
|
2266
|
+
{ label: "When", cell: (row) => esc(row.at) },
|
|
2267
|
+
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2268
|
+
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2269
|
+
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2270
|
+
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2271
|
+
], decodeJournal(journal));
|
|
2272
|
+
};
|
|
2273
|
+
const renderRoutes = async () => {
|
|
2274
|
+
const data = await api("GET", "/");
|
|
2275
|
+
if (!isRecord2(data))
|
|
2276
|
+
throw new Error("Route list was not an object");
|
|
2277
|
+
const routes = requireList(data.routes, "Routes").map((route) => String(route));
|
|
2278
|
+
el("route-list", HTMLElement).innerHTML = routes.map((route) => {
|
|
2279
|
+
const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
|
|
2280
|
+
const parts = route.split(" ");
|
|
2281
|
+
const method = parts[0] ?? "";
|
|
2282
|
+
const path = parts.slice(1).join(" ");
|
|
2283
|
+
return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}">Use</button></div>`;
|
|
2284
|
+
}).join("");
|
|
2285
|
+
};
|
|
2286
|
+
const renderers = {
|
|
2287
|
+
overview: renderOverview,
|
|
2288
|
+
state: renderState,
|
|
2289
|
+
clock: renderClock,
|
|
2290
|
+
faults: renderFaults,
|
|
2291
|
+
journal: renderJournal,
|
|
2292
|
+
routes: renderRoutes
|
|
2293
|
+
};
|
|
2294
|
+
async function refresh() {
|
|
2295
|
+
clearError();
|
|
2296
|
+
const render = renderers[state.view];
|
|
2297
|
+
if (render)
|
|
2298
|
+
await render();
|
|
2299
|
+
}
|
|
2300
|
+
el("namespace", HTMLSelectElement).addEventListener("change", () => {
|
|
2301
|
+
state.namespace = el("namespace", HTMLSelectElement).value;
|
|
2302
|
+
refresh().catch(showError);
|
|
2303
|
+
});
|
|
2304
|
+
keyInput.addEventListener("change", () => {
|
|
2305
|
+
state.key = keyInput.value.trim();
|
|
2306
|
+
sessionStorage.setItem("mockingbird-admin-key", state.key);
|
|
2307
|
+
refresh().catch(showError);
|
|
2308
|
+
});
|
|
2309
|
+
el("refresh", HTMLButtonElement).addEventListener("click", () => {
|
|
2310
|
+
refresh().catch(showError);
|
|
2311
|
+
});
|
|
2312
|
+
el("collections", HTMLElement).addEventListener("click", (event) => {
|
|
2313
|
+
const target = event.target;
|
|
2314
|
+
if (!(target instanceof Element))
|
|
2315
|
+
return;
|
|
2316
|
+
const button = target.closest("[data-collection]");
|
|
2317
|
+
if (!(button instanceof HTMLElement))
|
|
2318
|
+
return;
|
|
2319
|
+
const collection = button.dataset.collection;
|
|
2320
|
+
if (collection === void 0)
|
|
2321
|
+
return;
|
|
2322
|
+
state.collection = collection;
|
|
2323
|
+
renderState().catch(showError);
|
|
2324
|
+
});
|
|
2325
|
+
el("records", HTMLElement).addEventListener("click", (event) => {
|
|
2326
|
+
const target = event.target;
|
|
2327
|
+
if (!(target instanceof Element))
|
|
2328
|
+
return;
|
|
2329
|
+
const row = target.closest("[data-id]");
|
|
2330
|
+
if (!(row instanceof HTMLElement))
|
|
2331
|
+
return;
|
|
2332
|
+
const id = row.dataset.id;
|
|
2333
|
+
if (id === void 0)
|
|
2334
|
+
return;
|
|
2335
|
+
openEditor(id).catch(showError);
|
|
2336
|
+
});
|
|
2337
|
+
const editor = el("editor", HTMLDialogElement);
|
|
2338
|
+
const editorId = el("editor-id", HTMLInputElement);
|
|
2339
|
+
const editorValue = el("editor-value", HTMLTextAreaElement);
|
|
2340
|
+
const editorDelete = el("editor-delete", HTMLButtonElement);
|
|
2341
|
+
async function openEditor(id) {
|
|
2342
|
+
state.editing = id;
|
|
2343
|
+
el("editor-title", HTMLElement).textContent = id ? "Edit record" : "New record";
|
|
2344
|
+
editorId.value = id ?? "";
|
|
2345
|
+
editorId.readOnly = id !== null;
|
|
2346
|
+
editorDelete.hidden = id === null;
|
|
2347
|
+
if (id) {
|
|
2348
|
+
const record2 = await api("GET", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`);
|
|
2349
|
+
if (!isRecord2(record2))
|
|
2350
|
+
throw new Error("Record response was not an object");
|
|
2351
|
+
editorValue.value = JSON.stringify(record2.value, null, 2) ?? "";
|
|
2352
|
+
} else {
|
|
2353
|
+
editorValue.value = "{\n \n}";
|
|
2354
|
+
}
|
|
2355
|
+
editor.showModal();
|
|
2356
|
+
}
|
|
2357
|
+
el("new-record", HTMLButtonElement).addEventListener("click", () => {
|
|
2358
|
+
openEditor(null).catch(showError);
|
|
2359
|
+
});
|
|
2360
|
+
el("editor-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2361
|
+
const submitter = event.submitter;
|
|
2362
|
+
if (!(submitter instanceof HTMLButtonElement) || submitter.value !== "save")
|
|
2363
|
+
return;
|
|
2364
|
+
event.preventDefault();
|
|
2365
|
+
let value;
|
|
2366
|
+
try {
|
|
2367
|
+
value = readJson2(editorValue.value);
|
|
2368
|
+
} catch {
|
|
2369
|
+
showError(new Error("Value is not JSON"));
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
const id = editorId.value.trim();
|
|
2373
|
+
const path = `/state/${encodeURIComponent(state.collection)}`;
|
|
2374
|
+
const request = state.editing ? api("PUT", `${path}/${encodeURIComponent(id)}`, { value }) : api("POST", path, { id: id || void 0, value });
|
|
2375
|
+
request.then(() => {
|
|
2376
|
+
editor.close();
|
|
2377
|
+
return renderState();
|
|
2378
|
+
}).catch(showError);
|
|
2379
|
+
});
|
|
2380
|
+
editorDelete.addEventListener("click", () => {
|
|
2381
|
+
const id = state.editing;
|
|
2382
|
+
if (!id)
|
|
2383
|
+
return;
|
|
2384
|
+
api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
|
|
2385
|
+
editor.close();
|
|
2386
|
+
return renderState();
|
|
2387
|
+
}).catch(showError);
|
|
2388
|
+
});
|
|
2389
|
+
for (const button of document.querySelectorAll("[data-advance]")) {
|
|
2390
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2391
|
+
continue;
|
|
2392
|
+
button.addEventListener("click", () => {
|
|
2393
|
+
const raw = button.dataset.advance;
|
|
2394
|
+
if (raw === void 0)
|
|
2395
|
+
return;
|
|
2396
|
+
api("POST", "/clock", { advance: Number(raw) }).then(() => renderClock()).catch(showError);
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
el("freeze", HTMLButtonElement).addEventListener("click", () => {
|
|
2400
|
+
const frozen = el("freeze", HTMLButtonElement).dataset.frozen === "1";
|
|
2401
|
+
api("POST", "/clock", { freeze: !frozen }).then(() => renderClock()).catch(showError);
|
|
2402
|
+
});
|
|
2403
|
+
el("clock-reset", HTMLButtonElement).addEventListener("click", () => {
|
|
2404
|
+
api("POST", "/clock", { reset: true }).then(() => renderClock()).catch(showError);
|
|
2405
|
+
});
|
|
2406
|
+
el("clock-set", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2407
|
+
event.preventDefault();
|
|
2408
|
+
const raw = el("clock-instant", HTMLInputElement).value.trim();
|
|
2409
|
+
const set = /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2410
|
+
api("POST", "/clock", { set }).then(() => renderClock()).catch(showError);
|
|
2411
|
+
});
|
|
2412
|
+
el("fault-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2413
|
+
event.preventDefault();
|
|
2414
|
+
const preset = el("fault-preset", HTMLSelectElement).value;
|
|
2415
|
+
if (preset !== "") {
|
|
2416
|
+
api("POST", "/faults", { preset }).then(() => renderFaults()).catch(showError);
|
|
2417
|
+
return;
|
|
2418
|
+
}
|
|
2419
|
+
const status = Number(el("fault-status", HTMLInputElement).value);
|
|
2420
|
+
if (!Number.isFinite(status)) {
|
|
2421
|
+
showError(new Error("Status must be a number, or choose a preset"));
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
const path = el("fault-path", HTMLInputElement).value;
|
|
2425
|
+
const method = el("fault-method", HTMLInputElement).value;
|
|
2426
|
+
api("POST", "/faults", {
|
|
2427
|
+
status,
|
|
2428
|
+
...path !== "" ? { pathPrefix: path } : {},
|
|
2429
|
+
...method !== "" ? { method } : {}
|
|
2430
|
+
}).then(() => renderFaults()).catch(showError);
|
|
2431
|
+
});
|
|
2432
|
+
el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2433
|
+
api("DELETE", "/faults").then(() => renderFaults()).catch(showError);
|
|
2434
|
+
});
|
|
2435
|
+
el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
|
|
2436
|
+
api("DELETE", "/requests").then(() => renderJournal()).catch(showError);
|
|
2437
|
+
});
|
|
2438
|
+
el("route-list", HTMLElement).addEventListener("click", (event) => {
|
|
2439
|
+
const target = event.target;
|
|
2440
|
+
if (!(target instanceof Element))
|
|
2441
|
+
return;
|
|
2442
|
+
const button = target.closest("[data-route]");
|
|
2443
|
+
if (!(button instanceof HTMLElement))
|
|
2444
|
+
return;
|
|
2445
|
+
const route = button.dataset.route;
|
|
2446
|
+
if (route === void 0)
|
|
2447
|
+
return;
|
|
2448
|
+
state.route = route;
|
|
2449
|
+
el("route-title", HTMLElement).textContent = route;
|
|
2450
|
+
const method = route.split(" ")[0] ?? "";
|
|
2451
|
+
el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
|
|
2452
|
+
});
|
|
2453
|
+
el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
|
|
2454
|
+
event.preventDefault();
|
|
2455
|
+
const send = async () => {
|
|
2456
|
+
if (state.route === null)
|
|
2457
|
+
throw new Error("Choose a route first");
|
|
2458
|
+
const parts = state.route.split(" ");
|
|
2459
|
+
const method = parts[0];
|
|
2460
|
+
const path = parts.slice(1).join(" ");
|
|
2461
|
+
if (method === void 0)
|
|
2462
|
+
throw new Error("Choose a route first");
|
|
2463
|
+
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_match, key) => prompt(`Value for ${key}`) || "");
|
|
2464
|
+
let body;
|
|
2465
|
+
const routeBody = el("route-body", HTMLTextAreaElement);
|
|
2466
|
+
if (method !== "GET" && method !== "DELETE" && routeBody.value.trim() !== "") {
|
|
2467
|
+
try {
|
|
2468
|
+
body = readJson2(routeBody.value);
|
|
2469
|
+
} catch {
|
|
2470
|
+
throw new Error("Body is not JSON");
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
const data = await api(method, concrete, body);
|
|
2474
|
+
el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
|
|
2475
|
+
};
|
|
2476
|
+
send().catch(showError);
|
|
2477
|
+
});
|
|
2478
|
+
const decodePanel = (value) => {
|
|
2479
|
+
if (!isRecord2(value) || typeof value.id !== "string" || typeof value.title !== "string") {
|
|
2480
|
+
return void 0;
|
|
2481
|
+
}
|
|
2482
|
+
const panel = {
|
|
2483
|
+
id: value.id,
|
|
2484
|
+
title: value.title,
|
|
2485
|
+
description: typeof value.description === "string" ? value.description : "",
|
|
2486
|
+
html: typeof value.html === "string" ? value.html : ""
|
|
2487
|
+
};
|
|
2488
|
+
if (typeof value.script === "string")
|
|
2489
|
+
panel.script = value.script;
|
|
2490
|
+
return panel;
|
|
2491
|
+
};
|
|
2492
|
+
const mountPanels = (panels) => {
|
|
2493
|
+
const nav = el("nav", HTMLElement);
|
|
2494
|
+
const views = el("views", HTMLElement);
|
|
2495
|
+
for (const panel of panels) {
|
|
2496
|
+
const button = document.createElement("button");
|
|
2497
|
+
button.type = "button";
|
|
2498
|
+
button.dataset.view = panel.id;
|
|
2499
|
+
button.textContent = panel.title;
|
|
2500
|
+
nav.append(button);
|
|
2501
|
+
const section = document.createElement("section");
|
|
2502
|
+
section.className = "view";
|
|
2503
|
+
section.id = `view-${panel.id}`;
|
|
2504
|
+
section.hidden = true;
|
|
2505
|
+
const title = document.createElement("h2");
|
|
2506
|
+
title.textContent = panel.title;
|
|
2507
|
+
const lede = document.createElement("p");
|
|
2508
|
+
lede.className = "lede";
|
|
2509
|
+
lede.textContent = panel.description;
|
|
2510
|
+
const body = document.createElement("div");
|
|
2511
|
+
body.className = "panel-body";
|
|
2512
|
+
body.id = `panel-${panel.id}`;
|
|
2513
|
+
body.innerHTML = panel.html;
|
|
2514
|
+
section.append(title, lede, body);
|
|
2515
|
+
views.append(section);
|
|
2516
|
+
if (panel.script === void 0)
|
|
2517
|
+
continue;
|
|
2518
|
+
try {
|
|
2519
|
+
const compiled = new Function("root", "api", panel.script);
|
|
2520
|
+
if (!isPanelScript(compiled))
|
|
2521
|
+
throw new Error("panel script did not compile");
|
|
2522
|
+
compiled(body, panelApi);
|
|
2523
|
+
} catch (error) {
|
|
2524
|
+
const note = document.createElement("p");
|
|
2525
|
+
note.className = "banner show";
|
|
2526
|
+
note.textContent = error instanceof Error ? error.message : String(error);
|
|
2527
|
+
body.append(note);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
startAdminBrand({
|
|
2532
|
+
document,
|
|
2533
|
+
$: (id) => document.getElementById(id),
|
|
2534
|
+
params,
|
|
2535
|
+
location: { href: location.href, origin: location.origin },
|
|
2536
|
+
fetch,
|
|
2537
|
+
brandsUrl: config.brandsUrl
|
|
2538
|
+
});
|
|
2539
|
+
loadNamespaces().then(() => api("GET", "/ui/manifest")).then((manifest) => {
|
|
2540
|
+
const panels = requireList(isRecord2(manifest) ? manifest.panels : void 0, "Panels").flatMap((panel) => {
|
|
2541
|
+
const decoded = decodePanel(panel);
|
|
2542
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2543
|
+
});
|
|
2544
|
+
mountPanels(panels);
|
|
2545
|
+
return refresh();
|
|
2546
|
+
}).catch(showError);
|
|
2547
|
+
}
|
|
2548
|
+
var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
|
|
2549
|
+
var adminClientSource = (config) => {
|
|
2550
|
+
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2551
|
+
return `<script>
|
|
2552
|
+
${clientPrelude}
|
|
2553
|
+
bootAdmin(${payload});
|
|
2554
|
+
</script>`;
|
|
2555
|
+
};
|
|
2556
|
+
|
|
1331
2557
|
// ../core/dist/surface.js
|
|
1332
2558
|
var defineMock = (runtime) => runtime;
|
|
1333
2559
|
var STANDARD_ADMIN_ROUTES = [
|
|
@@ -1396,94 +2622,106 @@ var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
|
|
|
1396
2622
|
return "'";
|
|
1397
2623
|
}
|
|
1398
2624
|
});
|
|
2625
|
+
var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
|
|
1399
2626
|
var renderAdminDocument = (service) => {
|
|
1400
2627
|
const name = escapeHtml(service);
|
|
1401
|
-
const
|
|
2628
|
+
const script = adminClientSource({
|
|
2629
|
+
standardRoutes: STANDARD_ADMIN_ROUTES,
|
|
2630
|
+
adminPrefix: ADMIN_PREFIX,
|
|
2631
|
+
adminKeyHeader: ADMIN_KEY_HEADER,
|
|
2632
|
+
brandsUrl: ADMIN_BRANDS_URL,
|
|
2633
|
+
service
|
|
2634
|
+
});
|
|
1402
2635
|
return `<!DOCTYPE html>
|
|
1403
2636
|
<html lang="en">
|
|
1404
2637
|
<head>
|
|
1405
2638
|
<meta charset="utf-8">
|
|
1406
2639
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
1407
2640
|
<meta name="color-scheme" content="light dark">
|
|
1408
|
-
<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='
|
|
2641
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='2' fill='%2327272a'/%3E%3C/svg%3E">
|
|
1409
2642
|
<title>${name} admin</title>
|
|
1410
2643
|
<style>
|
|
2644
|
+
${CSS_RESET}
|
|
1411
2645
|
:root {
|
|
1412
2646
|
color-scheme: light;
|
|
1413
|
-
--bg: #
|
|
2647
|
+
--bg: #fafafa;
|
|
1414
2648
|
--bg-elev: #ffffff;
|
|
1415
|
-
--bg-muted: #
|
|
1416
|
-
--bg-inset: #
|
|
1417
|
-
--line: #
|
|
1418
|
-
--line-strong: #
|
|
1419
|
-
--ink: #
|
|
1420
|
-
--muted: #
|
|
1421
|
-
--faint: #
|
|
1422
|
-
--accent: #
|
|
1423
|
-
--accent-ink: #
|
|
1424
|
-
--accent-soft: #
|
|
1425
|
-
--ok: #
|
|
1426
|
-
--ok-soft: #
|
|
1427
|
-
--warn: #
|
|
1428
|
-
--warn-soft: #
|
|
1429
|
-
--err: #
|
|
1430
|
-
--err-soft: #
|
|
1431
|
-
--shadow:
|
|
1432
|
-
--sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
2649
|
+
--bg-muted: #f4f4f5;
|
|
2650
|
+
--bg-inset: #f4f4f5;
|
|
2651
|
+
--line: #dedee3;
|
|
2652
|
+
--line-strong: #c4c4cc;
|
|
2653
|
+
--ink: #18181b;
|
|
2654
|
+
--muted: #62626b;
|
|
2655
|
+
--faint: #71717a;
|
|
2656
|
+
--accent: #27272a;
|
|
2657
|
+
--accent-ink: #ffffff;
|
|
2658
|
+
--accent-soft: #f4f4f5;
|
|
2659
|
+
--ok: #166534;
|
|
2660
|
+
--ok-soft: #f0fdf4;
|
|
2661
|
+
--warn: #a16207;
|
|
2662
|
+
--warn-soft: #fefce8;
|
|
2663
|
+
--err: #a82d32;
|
|
2664
|
+
--err-soft: #fef2f2;
|
|
2665
|
+
--shadow: none;
|
|
2666
|
+
--sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
1433
2667
|
--mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
|
|
1434
|
-
--radius:
|
|
1435
|
-
--header:
|
|
1436
|
-
--nav:
|
|
2668
|
+
--radius: 10px;
|
|
2669
|
+
--header: 56px;
|
|
2670
|
+
--nav: 200px;
|
|
1437
2671
|
}
|
|
1438
2672
|
:root[data-theme="dark"] {
|
|
1439
2673
|
color-scheme: dark;
|
|
1440
|
-
--bg: #
|
|
1441
|
-
--bg-elev: #
|
|
1442
|
-
--bg-muted: #
|
|
1443
|
-
--bg-inset: #
|
|
1444
|
-
--line: #
|
|
1445
|
-
--line-strong: #
|
|
1446
|
-
--ink: #
|
|
1447
|
-
--muted: #
|
|
1448
|
-
--faint: #
|
|
1449
|
-
--accent: #
|
|
1450
|
-
--accent-ink: #
|
|
1451
|
-
--accent-soft: #
|
|
1452
|
-
--ok: #
|
|
1453
|
-
--ok-soft: #
|
|
1454
|
-
--warn: #
|
|
1455
|
-
--warn-soft: #
|
|
1456
|
-
--err: #
|
|
1457
|
-
--err-soft: #
|
|
1458
|
-
--shadow:
|
|
2674
|
+
--bg: #111113;
|
|
2675
|
+
--bg-elev: #19191c;
|
|
2676
|
+
--bg-muted: #242428;
|
|
2677
|
+
--bg-inset: #111113;
|
|
2678
|
+
--line: #36363c;
|
|
2679
|
+
--line-strong: #52525b;
|
|
2680
|
+
--ink: #f4f4f5;
|
|
2681
|
+
--muted: #a9a9b2;
|
|
2682
|
+
--faint: #71717a;
|
|
2683
|
+
--accent: #e4e4e7;
|
|
2684
|
+
--accent-ink: #18181b;
|
|
2685
|
+
--accent-soft: #242428;
|
|
2686
|
+
--ok: #86efac;
|
|
2687
|
+
--ok-soft: #14241b;
|
|
2688
|
+
--warn: #fde68a;
|
|
2689
|
+
--warn-soft: #2a2410;
|
|
2690
|
+
--err: #ffaaaa;
|
|
2691
|
+
--err-soft: #2c1516;
|
|
2692
|
+
--shadow: none;
|
|
1459
2693
|
}
|
|
1460
2694
|
@media (prefers-color-scheme: dark) {
|
|
1461
2695
|
:root:not([data-theme="light"]) {
|
|
1462
2696
|
color-scheme: dark;
|
|
1463
|
-
--bg: #
|
|
1464
|
-
--bg-elev: #
|
|
1465
|
-
--bg-muted: #
|
|
1466
|
-
--bg-inset: #
|
|
1467
|
-
--line: #
|
|
1468
|
-
--line-strong: #
|
|
1469
|
-
--ink: #
|
|
1470
|
-
--muted: #
|
|
1471
|
-
--faint: #
|
|
1472
|
-
--accent: #
|
|
1473
|
-
--accent-ink: #
|
|
1474
|
-
--accent-soft: #
|
|
1475
|
-
--ok: #
|
|
1476
|
-
--ok-soft: #
|
|
1477
|
-
--warn: #
|
|
1478
|
-
--warn-soft: #
|
|
1479
|
-
--err: #
|
|
1480
|
-
--err-soft: #
|
|
1481
|
-
--shadow:
|
|
2697
|
+
--bg: #111113;
|
|
2698
|
+
--bg-elev: #19191c;
|
|
2699
|
+
--bg-muted: #242428;
|
|
2700
|
+
--bg-inset: #111113;
|
|
2701
|
+
--line: #36363c;
|
|
2702
|
+
--line-strong: #52525b;
|
|
2703
|
+
--ink: #f4f4f5;
|
|
2704
|
+
--muted: #a9a9b2;
|
|
2705
|
+
--faint: #71717a;
|
|
2706
|
+
--accent: #e4e4e7;
|
|
2707
|
+
--accent-ink: #18181b;
|
|
2708
|
+
--accent-soft: #242428;
|
|
2709
|
+
--ok: #86efac;
|
|
2710
|
+
--ok-soft: #14241b;
|
|
2711
|
+
--warn: #fde68a;
|
|
2712
|
+
--warn-soft: #2a2410;
|
|
2713
|
+
--err: #ffaaaa;
|
|
2714
|
+
--err-soft: #2c1516;
|
|
2715
|
+
--shadow: none;
|
|
1482
2716
|
}
|
|
1483
2717
|
}
|
|
1484
|
-
|
|
1485
|
-
html
|
|
2718
|
+
/* Fill the viewport, then grow with the content so the background covers the scroll. */
|
|
2719
|
+
html { height: 100%; }
|
|
1486
2720
|
body {
|
|
2721
|
+
margin: 0;
|
|
2722
|
+
min-height: 100%;
|
|
2723
|
+
display: flex;
|
|
2724
|
+
flex-direction: column;
|
|
1487
2725
|
font-family: var(--sans);
|
|
1488
2726
|
background: var(--bg);
|
|
1489
2727
|
color: var(--ink);
|
|
@@ -1492,24 +2730,37 @@ var renderAdminDocument = (service) => {
|
|
|
1492
2730
|
padding-right: env(safe-area-inset-right);
|
|
1493
2731
|
-webkit-text-size-adjust: 100%;
|
|
1494
2732
|
}
|
|
1495
|
-
button, input, select, textarea { font: inherit; color: inherit; }
|
|
1496
|
-
button { cursor: pointer; }
|
|
1497
2733
|
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
1498
|
-
|
|
1499
|
-
* { scroll-behavior: auto !important; transition: none !important; }
|
|
1500
|
-
}
|
|
1501
|
-
.app { min-height: 100%; display: flex; flex-direction: column; }
|
|
2734
|
+
.app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
|
|
1502
2735
|
header.top {
|
|
1503
2736
|
position: sticky; top: 0; z-index: 5;
|
|
1504
2737
|
display: flex; align-items: center; gap: 12px;
|
|
1505
2738
|
min-height: var(--header); padding: 10px 16px;
|
|
1506
|
-
background:
|
|
2739
|
+
background: var(--bg-elev);
|
|
1507
2740
|
border-bottom: 1px solid var(--line);
|
|
1508
|
-
|
|
1509
|
-
}
|
|
1510
|
-
.brand {
|
|
1511
|
-
|
|
1512
|
-
|
|
2741
|
+
min-width: 0; max-width: 100%;
|
|
2742
|
+
}
|
|
2743
|
+
.brand {
|
|
2744
|
+
display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
|
|
2745
|
+
min-width: 0; max-width: 100%; margin-right: auto;
|
|
2746
|
+
}
|
|
2747
|
+
.brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
|
|
2748
|
+
.brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
|
|
2749
|
+
.brand-id span { color: var(--faint); font-size: 12px; }
|
|
2750
|
+
.vendor {
|
|
2751
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
|
|
2752
|
+
min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
|
|
2753
|
+
}
|
|
2754
|
+
.vendor[hidden] { display: none; }
|
|
2755
|
+
/* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
|
|
2756
|
+
.vendor img {
|
|
2757
|
+
width: 16px; height: 16px; padding: 2px; box-sizing: content-box;
|
|
2758
|
+
border-radius: 4px; border: 1px solid var(--line); background: #fff; object-fit: contain;
|
|
2759
|
+
}
|
|
2760
|
+
.vendor-name { color: var(--ink); font-weight: 600; }
|
|
2761
|
+
.vendor-sep { color: var(--faint); }
|
|
2762
|
+
.vendor-link { color: inherit; text-decoration: none; }
|
|
2763
|
+
.vendor-link:hover { color: var(--ink); text-decoration: underline; }
|
|
1513
2764
|
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
|
1514
2765
|
label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
|
|
1515
2766
|
label.field input, label.field select, .controls input[type="password"] {
|
|
@@ -1527,7 +2778,7 @@ var renderAdminDocument = (service) => {
|
|
|
1527
2778
|
record or the full nav row would widen the page past the viewport. */
|
|
1528
2779
|
.layout {
|
|
1529
2780
|
display: grid; grid-template-columns: var(--nav) minmax(0, 1fr);
|
|
1530
|
-
flex: 1
|
|
2781
|
+
flex: 1 0 auto; min-width: 0;
|
|
1531
2782
|
}
|
|
1532
2783
|
nav.side {
|
|
1533
2784
|
border-right: 1px solid var(--line); padding: 12px;
|
|
@@ -1542,7 +2793,7 @@ var renderAdminDocument = (service) => {
|
|
|
1542
2793
|
main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
|
|
1543
2794
|
.view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
|
|
1544
2795
|
.lede { margin: 0 0 16px; color: var(--muted); }
|
|
1545
|
-
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
2796
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
|
|
1546
2797
|
.card {
|
|
1547
2798
|
background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
|
|
1548
2799
|
padding: 14px 16px; box-shadow: var(--shadow);
|
|
@@ -1581,8 +2832,8 @@ var renderAdminDocument = (service) => {
|
|
|
1581
2832
|
.banner.show { display: block; }
|
|
1582
2833
|
.empty { color: var(--muted); padding: 24px 8px; }
|
|
1583
2834
|
dialog {
|
|
1584
|
-
border: 1px solid var(--line); border-radius:
|
|
1585
|
-
color: var(--ink); width: min(640px, calc(
|
|
2835
|
+
border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
|
|
2836
|
+
color: var(--ink); width: min(640px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: none;
|
|
1586
2837
|
}
|
|
1587
2838
|
dialog::backdrop { background: rgb(20 19 17 / 0.45); }
|
|
1588
2839
|
dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
|
|
@@ -1609,7 +2860,7 @@ var renderAdminDocument = (service) => {
|
|
|
1609
2860
|
padding-top: max(10px, env(safe-area-inset-top));
|
|
1610
2861
|
}
|
|
1611
2862
|
input, select, textarea { font-size: 16px; }
|
|
1612
|
-
.controls { width: 100%; }
|
|
2863
|
+
.brand, .vendor, .controls { width: 100%; }
|
|
1613
2864
|
label.field, label.field select, label.field input { flex: 1; min-width: 0; }
|
|
1614
2865
|
.layout { grid-template-columns: minmax(0, 1fr); }
|
|
1615
2866
|
nav.side {
|
|
@@ -1640,8 +2891,11 @@ var renderAdminDocument = (service) => {
|
|
|
1640
2891
|
<div class="app" data-service="${name}" data-mockingbird-admin>
|
|
1641
2892
|
<header class="top">
|
|
1642
2893
|
<div class="brand">
|
|
1643
|
-
<
|
|
1644
|
-
|
|
2894
|
+
<div class="brand-id">
|
|
2895
|
+
<strong>${name}</strong>
|
|
2896
|
+
<span>Admin</span>
|
|
2897
|
+
</div>
|
|
2898
|
+
<div class="vendor" id="vendor" hidden></div>
|
|
1645
2899
|
</div>
|
|
1646
2900
|
<div class="controls">
|
|
1647
2901
|
<label class="field">Namespace
|
|
@@ -1771,460 +3025,7 @@ var renderAdminDocument = (service) => {
|
|
|
1771
3025
|
</div>
|
|
1772
3026
|
</form>
|
|
1773
3027
|
</dialog>
|
|
1774
|
-
|
|
1775
|
-
(() => {
|
|
1776
|
-
const STANDARD = new Set(${standard})
|
|
1777
|
-
const state = {
|
|
1778
|
-
namespace: "default",
|
|
1779
|
-
key: sessionStorage.getItem("mockingbird-admin-key") || "",
|
|
1780
|
-
view: "overview",
|
|
1781
|
-
collection: "",
|
|
1782
|
-
shape: null,
|
|
1783
|
-
route: null,
|
|
1784
|
-
editing: null
|
|
1785
|
-
}
|
|
1786
|
-
const $ = (id) => document.getElementById(id)
|
|
1787
|
-
const banner = $("banner")
|
|
1788
|
-
const keyInput = $("admin-key")
|
|
1789
|
-
keyInput.value = state.key
|
|
1790
|
-
const params = new URLSearchParams(location.search)
|
|
1791
|
-
if (params.get("key")) {
|
|
1792
|
-
state.key = params.get("key")
|
|
1793
|
-
keyInput.value = state.key
|
|
1794
|
-
sessionStorage.setItem("mockingbird-admin-key", state.key)
|
|
1795
|
-
params.delete("key")
|
|
1796
|
-
const next = params.toString()
|
|
1797
|
-
history.replaceState(null, "", location.pathname + (next ? "?" + next : ""))
|
|
1798
|
-
}
|
|
1799
|
-
if (params.get("namespace")) state.namespace = params.get("namespace")
|
|
1800
|
-
|
|
1801
|
-
const showError = (error) => {
|
|
1802
|
-
banner.textContent = error instanceof Error ? error.message : String(error)
|
|
1803
|
-
banner.classList.add("show")
|
|
1804
|
-
}
|
|
1805
|
-
const clearError = () => banner.classList.remove("show")
|
|
1806
|
-
|
|
1807
|
-
async function originGet(path) {
|
|
1808
|
-
const response = await fetch(path, { headers: { accept: "application/json" } })
|
|
1809
|
-
if (!response.ok) throw new Error(response.status + " " + path)
|
|
1810
|
-
return response.json()
|
|
1811
|
-
}
|
|
1812
|
-
async function api(method, path, body) {
|
|
1813
|
-
const headers = { accept: "application/json" }
|
|
1814
|
-
if (state.key) headers["${ADMIN_KEY_HEADER}"] = state.key
|
|
1815
|
-
if (state.namespace) headers["x-mockingbird-namespace"] = state.namespace
|
|
1816
|
-
if (body !== undefined) headers["content-type"] = "application/json"
|
|
1817
|
-
const response = await fetch("${ADMIN_PREFIX}" + path, {
|
|
1818
|
-
method,
|
|
1819
|
-
headers,
|
|
1820
|
-
body: body === undefined ? undefined : JSON.stringify(body)
|
|
1821
|
-
})
|
|
1822
|
-
const text = await response.text()
|
|
1823
|
-
let data = null
|
|
1824
|
-
if (text) {
|
|
1825
|
-
try { data = JSON.parse(text) } catch { data = { raw: text } }
|
|
1826
|
-
}
|
|
1827
|
-
if (response.status === 401) {
|
|
1828
|
-
keyInput.focus()
|
|
1829
|
-
throw new Error((data && data.error && data.error.message) || "Admin key required")
|
|
1830
|
-
}
|
|
1831
|
-
if (!response.ok) {
|
|
1832
|
-
throw new Error((data && data.error && data.error.message) || (response.status + " " + method + " " + path))
|
|
1833
|
-
}
|
|
1834
|
-
return data
|
|
1835
|
-
}
|
|
1836
|
-
const panelApi = {
|
|
1837
|
-
get: (path) => api("GET", path),
|
|
1838
|
-
send: (method, path, body) => api(method, path, body),
|
|
1839
|
-
namespace: () => state.namespace
|
|
1840
|
-
}
|
|
1841
|
-
|
|
1842
|
-
function setTheme(theme) {
|
|
1843
|
-
if (theme) document.documentElement.dataset.theme = theme
|
|
1844
|
-
else delete document.documentElement.dataset.theme
|
|
1845
|
-
}
|
|
1846
|
-
const storedTheme = localStorage.getItem("mockingbird-admin-theme")
|
|
1847
|
-
if (storedTheme) setTheme(storedTheme)
|
|
1848
|
-
$("theme").addEventListener("click", () => {
|
|
1849
|
-
const current = document.documentElement.dataset.theme
|
|
1850
|
-
const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches
|
|
1851
|
-
const next = dark ? "light" : "dark"
|
|
1852
|
-
localStorage.setItem("mockingbird-admin-theme", next)
|
|
1853
|
-
setTheme(next)
|
|
1854
|
-
})
|
|
1855
|
-
|
|
1856
|
-
function show(view) {
|
|
1857
|
-
state.view = view
|
|
1858
|
-
for (const button of document.querySelectorAll("#nav button")) {
|
|
1859
|
-
button.setAttribute("aria-current", button.dataset.view === view ? "true" : "false")
|
|
1860
|
-
}
|
|
1861
|
-
for (const section of document.querySelectorAll("main .view")) {
|
|
1862
|
-
section.hidden = section.id !== "view-" + view
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
document.getElementById("nav").addEventListener("click", (event) => {
|
|
1866
|
-
const button = event.target.closest("button[data-view]")
|
|
1867
|
-
if (!button) return
|
|
1868
|
-
show(button.dataset.view)
|
|
1869
|
-
refresh().catch(showError)
|
|
1870
|
-
})
|
|
1871
|
-
|
|
1872
|
-
function cards(items) {
|
|
1873
|
-
return '<div class="grid">' + items.map((item) =>
|
|
1874
|
-
'<article class="card"><div class="k">' + item.k + '</div><div class="v">' + item.v + '</div></article>'
|
|
1875
|
-
).join("") + "</div>"
|
|
1876
|
-
}
|
|
1877
|
-
function table(columns, rows) {
|
|
1878
|
-
if (rows.length === 0) return '<p class="empty">Nothing here yet.</p>'
|
|
1879
|
-
const head = "<tr>" + columns.map((column) => "<th>" + column.label + "</th>").join("") + "</tr>"
|
|
1880
|
-
const body = rows.map((row) => "<tr" + (row.attrs || "") + ">" + columns.map((column) =>
|
|
1881
|
-
'<td data-label="' + column.label + '">' + column.cell(row) + "</td>"
|
|
1882
|
-
).join("") + "</tr>").join("")
|
|
1883
|
-
return "<table><thead>" + head + "</thead><tbody>" + body + "</tbody></table>"
|
|
1884
|
-
}
|
|
1885
|
-
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => ({
|
|
1886
|
-
"&": "&", "<": "<", ">": ">", '"': """, "'": "'"
|
|
1887
|
-
}[char]))
|
|
1888
|
-
const preview = (value) => {
|
|
1889
|
-
const text = JSON.stringify(value)
|
|
1890
|
-
return esc(text.length > 180 ? text.slice(0, 180) + "\u2026" : text)
|
|
1891
|
-
}
|
|
1892
|
-
const when = (epoch) => {
|
|
1893
|
-
const date = new Date(epoch)
|
|
1894
|
-
return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString()
|
|
1895
|
-
}
|
|
1896
|
-
const clockCard = (epoch) => {
|
|
1897
|
-
const date = new Date(epoch)
|
|
1898
|
-
if (Number.isNaN(date.getTime())) return esc(String(epoch))
|
|
1899
|
-
const iso = date.toISOString()
|
|
1900
|
-
return esc(iso.slice(0, 10)) + '<span class="clock-time">' + esc(iso.slice(11, 19)) + " UTC</span>"
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
async function loadNamespaces() {
|
|
1904
|
-
const data = await api("GET", "/namespaces")
|
|
1905
|
-
const select = $("namespace")
|
|
1906
|
-
const names = data.namespaces && data.namespaces.length ? data.namespaces : [data.default || "default"]
|
|
1907
|
-
if (!names.includes(state.namespace)) names.unshift(state.namespace)
|
|
1908
|
-
select.innerHTML = names.map((name) =>
|
|
1909
|
-
'<option value="' + esc(name) + '">' + esc(name) + "</option>"
|
|
1910
|
-
).join("")
|
|
1911
|
-
select.value = state.namespace
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
async function renderOverview() {
|
|
1915
|
-
const [health, shape, clock, journal] = await Promise.all([
|
|
1916
|
-
originGet("/health"),
|
|
1917
|
-
api("GET", "/state"),
|
|
1918
|
-
api("GET", "/clock"),
|
|
1919
|
-
api("GET", "/requests?limit=8")
|
|
1920
|
-
])
|
|
1921
|
-
state.shape = shape
|
|
1922
|
-
$("overview-cards").innerHTML = cards([
|
|
1923
|
-
{ k: "Service", v: esc(health.service || "${name}") },
|
|
1924
|
-
{ k: "Status", v: esc(health.status || "ok") },
|
|
1925
|
-
{ k: "Namespace", v: esc(state.namespace) },
|
|
1926
|
-
{ k: "Collections", v: String(shape.collections.length) },
|
|
1927
|
-
{ k: "Records", v: String(shape.collections.reduce((sum, item) => sum + item.count, 0)) },
|
|
1928
|
-
{ k: "Clock", v: clockCard(clock.now) }
|
|
1929
|
-
])
|
|
1930
|
-
const requests = (journal && journal.requests) || []
|
|
1931
|
-
$("overview-requests").innerHTML = table(
|
|
1932
|
-
[
|
|
1933
|
-
{ label: "Method", cell: (row) => esc(row.method) },
|
|
1934
|
-
{ label: "Path", cell: (row) => esc(row.path) },
|
|
1935
|
-
{ label: "Status", cell: (row) => '<span class="status-' + String(row.status).charAt(0) + '">' + esc(row.status) + "</span>" },
|
|
1936
|
-
{ label: "Operation", cell: (row) => esc(row.operationId || "") }
|
|
1937
|
-
],
|
|
1938
|
-
requests
|
|
1939
|
-
)
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
function schemaChips(collection) {
|
|
1943
|
-
if (!collection || collection.fields.length === 0) {
|
|
1944
|
-
return '<p class="empty">No fields yet. Add a record or declare the collection on the service.</p>'
|
|
1945
|
-
}
|
|
1946
|
-
return '<div class="chips">' + collection.fields.map((field) =>
|
|
1947
|
-
'<span class="chip">' + esc(field.name) + ' <i>' + esc(field.kind) + (field.optional ? "?" : "") + "</i></span>"
|
|
1948
|
-
).join("") + "</div>"
|
|
1949
|
-
}
|
|
1950
|
-
|
|
1951
|
-
async function renderState() {
|
|
1952
|
-
const shape = await api("GET", "/state")
|
|
1953
|
-
state.shape = shape
|
|
1954
|
-
const host = $("collections")
|
|
1955
|
-
if (shape.collections.length === 0) {
|
|
1956
|
-
host.innerHTML = '<p class="empty">This namespace has no collections yet.</p>'
|
|
1957
|
-
$("schema").innerHTML = ""
|
|
1958
|
-
$("records").innerHTML = ""
|
|
1959
|
-
return
|
|
1960
|
-
}
|
|
1961
|
-
if (!shape.collections.some((item) => item.name === state.collection)) {
|
|
1962
|
-
state.collection = shape.collections[0].name
|
|
1963
|
-
}
|
|
1964
|
-
host.innerHTML = shape.collections.map((item) =>
|
|
1965
|
-
'<button type="button" class="collection" data-collection="' + esc(item.name) + '" aria-current="' +
|
|
1966
|
-
(item.name === state.collection ? "true" : "false") + '"><strong>' + esc(item.label) +
|
|
1967
|
-
'</strong><small>' + esc(item.count) + " \xB7 " + esc(item.source) + "</small></button>"
|
|
1968
|
-
).join("")
|
|
1969
|
-
const selected = shape.collections.find((item) => item.name === state.collection)
|
|
1970
|
-
$("schema").innerHTML = "<h3>" + esc(selected.label) + "</h3>" +
|
|
1971
|
-
(selected.description ? "<p class=" + '"lede">' + esc(selected.description) + "</p>" : "") +
|
|
1972
|
-
schemaChips(selected)
|
|
1973
|
-
const page = await api("GET", "/state/" + encodeURIComponent(state.collection) + "?limit=50")
|
|
1974
|
-
const rows = page.records.map((record) => ({
|
|
1975
|
-
...record,
|
|
1976
|
-
attrs: ' class="clickable" data-id="' + esc(record.id) + '"'
|
|
1977
|
-
}))
|
|
1978
|
-
$("records").innerHTML = table(
|
|
1979
|
-
[
|
|
1980
|
-
{ label: "Id", cell: (row) => "<code>" + esc(row.id) + "</code>" },
|
|
1981
|
-
{ label: "Seq", cell: (row) => esc(row.seq) },
|
|
1982
|
-
{ label: "Value", cell: (row) => preview(row.value) }
|
|
1983
|
-
],
|
|
1984
|
-
rows
|
|
1985
|
-
)
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
async function renderClock() {
|
|
1989
|
-
const clock = await api("GET", "/clock")
|
|
1990
|
-
$("clock-readout").innerHTML = "<div class='k'>Now</div><div class='v'>" + esc(when(clock.now)) +
|
|
1991
|
-
"</div><p>" + esc(clock.now) + " ms \xB7 offset " + esc(clock.offsetMs) + " ms " +
|
|
1992
|
-
(clock.frozen ? "<span class='badge warn'>frozen</span>" : "<span class='badge ok'>live</span>") + "</p>"
|
|
1993
|
-
$("freeze").textContent = clock.frozen ? "Unfreeze" : "Freeze"
|
|
1994
|
-
$("freeze").dataset.frozen = clock.frozen ? "1" : "0"
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
async function renderFaults() {
|
|
1998
|
-
const [faults, presets] = await Promise.all([
|
|
1999
|
-
api("GET", "/faults"),
|
|
2000
|
-
api("GET", "/faults/presets").catch(() => ({ presets: [] }))
|
|
2001
|
-
])
|
|
2002
|
-
const select = $("fault-preset")
|
|
2003
|
-
const current = select.value
|
|
2004
|
-
const list = presets.presets || []
|
|
2005
|
-
select.innerHTML = '<option value="">Custom rule</option>' + list.map((preset) =>
|
|
2006
|
-
'<option value="' + esc(preset.name) + '">' + esc(preset.name) + "</option>"
|
|
2007
|
-
).join("")
|
|
2008
|
-
select.value = current
|
|
2009
|
-
const rules = faults.faults || []
|
|
2010
|
-
$("fault-list").innerHTML = table(
|
|
2011
|
-
[
|
|
2012
|
-
{ label: "Id", cell: (row) => esc(row.id) },
|
|
2013
|
-
{ label: "Match", cell: (row) => esc([row.method, row.pathPrefix, row.operationId].filter(Boolean).join(" ") || "all") },
|
|
2014
|
-
{ label: "Effect", cell: (row) => esc(row.status ?? row.effect ?? (row.drop ? "drop" : row.latencyMs || "")) }
|
|
2015
|
-
],
|
|
2016
|
-
rules
|
|
2017
|
-
)
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
async function renderJournal() {
|
|
2021
|
-
const journal = await api("GET", "/requests?limit=100")
|
|
2022
|
-
$("journal").innerHTML = table(
|
|
2023
|
-
[
|
|
2024
|
-
{ label: "When", cell: (row) => esc(row.at || "") },
|
|
2025
|
-
{ label: "Method", cell: (row) => esc(row.method) },
|
|
2026
|
-
{ label: "Path", cell: (row) => esc(row.path) },
|
|
2027
|
-
{ label: "Status", cell: (row) => esc(row.status) },
|
|
2028
|
-
{ label: "ms", cell: (row) => esc(row.durationMs) }
|
|
2029
|
-
],
|
|
2030
|
-
journal.requests || []
|
|
2031
|
-
)
|
|
2032
|
-
}
|
|
2033
|
-
|
|
2034
|
-
async function renderRoutes() {
|
|
2035
|
-
const data = await api("GET", "/")
|
|
2036
|
-
const routes = data.routes || []
|
|
2037
|
-
$("route-list").innerHTML = routes.map((route) => {
|
|
2038
|
-
const extra = STANDARD.has(route) ? "" : " <span class='badge'>extension</span>"
|
|
2039
|
-
return '<div class="route"><span class="method">' + esc(route.split(" ")[0]) +
|
|
2040
|
-
'</span><span>' + esc(route.split(" ").slice(1).join(" ")) + extra +
|
|
2041
|
-
'</span><button class="btn" type="button" data-route="' + esc(route) + '">Use</button></div>'
|
|
2042
|
-
}).join("")
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
const renderers = {
|
|
2046
|
-
overview: renderOverview,
|
|
2047
|
-
state: renderState,
|
|
2048
|
-
clock: renderClock,
|
|
2049
|
-
faults: renderFaults,
|
|
2050
|
-
journal: renderJournal,
|
|
2051
|
-
routes: renderRoutes
|
|
2052
|
-
}
|
|
2053
|
-
|
|
2054
|
-
async function refresh() {
|
|
2055
|
-
clearError()
|
|
2056
|
-
if (state.view in renderers) await renderers[state.view]()
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
$("namespace").addEventListener("change", () => {
|
|
2060
|
-
state.namespace = $("namespace").value
|
|
2061
|
-
refresh().catch(showError)
|
|
2062
|
-
})
|
|
2063
|
-
keyInput.addEventListener("change", () => {
|
|
2064
|
-
state.key = keyInput.value.trim()
|
|
2065
|
-
sessionStorage.setItem("mockingbird-admin-key", state.key)
|
|
2066
|
-
refresh().catch(showError)
|
|
2067
|
-
})
|
|
2068
|
-
$("refresh").addEventListener("click", () => refresh().catch(showError))
|
|
2069
|
-
|
|
2070
|
-
$("collections").addEventListener("click", (event) => {
|
|
2071
|
-
const button = event.target.closest("[data-collection]")
|
|
2072
|
-
if (!button) return
|
|
2073
|
-
state.collection = button.dataset.collection
|
|
2074
|
-
renderState().catch(showError)
|
|
2075
|
-
})
|
|
2076
|
-
$("records").addEventListener("click", (event) => {
|
|
2077
|
-
const row = event.target.closest("[data-id]")
|
|
2078
|
-
if (!row) return
|
|
2079
|
-
openEditor(row.dataset.id).catch(showError)
|
|
2080
|
-
})
|
|
2081
|
-
|
|
2082
|
-
const editor = $("editor")
|
|
2083
|
-
async function openEditor(id) {
|
|
2084
|
-
state.editing = id || null
|
|
2085
|
-
$("editor-title").textContent = id ? "Edit record" : "New record"
|
|
2086
|
-
$("editor-id").value = id || ""
|
|
2087
|
-
$("editor-id").readOnly = Boolean(id)
|
|
2088
|
-
$("editor-delete").hidden = !id
|
|
2089
|
-
if (id) {
|
|
2090
|
-
const record = await api("GET", "/state/" + encodeURIComponent(state.collection) + "/" + encodeURIComponent(id))
|
|
2091
|
-
$("editor-value").value = JSON.stringify(record.value, null, 2)
|
|
2092
|
-
} else {
|
|
2093
|
-
$("editor-value").value = "{\\n \\n}"
|
|
2094
|
-
}
|
|
2095
|
-
editor.showModal()
|
|
2096
|
-
}
|
|
2097
|
-
$("new-record").addEventListener("click", () => openEditor(null).catch(showError))
|
|
2098
|
-
$("editor-form").addEventListener("submit", (event) => {
|
|
2099
|
-
const submitter = event.submitter
|
|
2100
|
-
if (!submitter || submitter.value !== "save") return
|
|
2101
|
-
event.preventDefault()
|
|
2102
|
-
let value
|
|
2103
|
-
try { value = JSON.parse($("editor-value").value) }
|
|
2104
|
-
catch { showError(new Error("Value is not JSON")); return }
|
|
2105
|
-
const id = $("editor-id").value.trim()
|
|
2106
|
-
const path = "/state/" + encodeURIComponent(state.collection)
|
|
2107
|
-
const request = state.editing
|
|
2108
|
-
? api("PUT", path + "/" + encodeURIComponent(id), { value })
|
|
2109
|
-
: api("POST", path, { id: id || undefined, value })
|
|
2110
|
-
request.then(() => { editor.close(); return renderState() }).catch(showError)
|
|
2111
|
-
})
|
|
2112
|
-
$("editor-delete").addEventListener("click", () => {
|
|
2113
|
-
const id = state.editing
|
|
2114
|
-
if (!id) return
|
|
2115
|
-
api("DELETE", "/state/" + encodeURIComponent(state.collection) + "/" + encodeURIComponent(id))
|
|
2116
|
-
.then(() => { editor.close(); return renderState() })
|
|
2117
|
-
.catch(showError)
|
|
2118
|
-
})
|
|
2119
|
-
|
|
2120
|
-
document.querySelectorAll("[data-advance]").forEach((button) => {
|
|
2121
|
-
button.addEventListener("click", () => {
|
|
2122
|
-
api("POST", "/clock", { advance: Number(button.dataset.advance) }).then(renderClock).catch(showError)
|
|
2123
|
-
})
|
|
2124
|
-
})
|
|
2125
|
-
$("freeze").addEventListener("click", () => {
|
|
2126
|
-
const frozen = $("freeze").dataset.frozen === "1"
|
|
2127
|
-
api("POST", "/clock", { freeze: !frozen }).then(renderClock).catch(showError)
|
|
2128
|
-
})
|
|
2129
|
-
$("clock-reset").addEventListener("click", () => {
|
|
2130
|
-
api("POST", "/clock", { reset: true }).then(renderClock).catch(showError)
|
|
2131
|
-
})
|
|
2132
|
-
$("clock-set").addEventListener("submit", (event) => {
|
|
2133
|
-
event.preventDefault()
|
|
2134
|
-
const raw = $("clock-instant").value.trim()
|
|
2135
|
-
const set = /^-?\\d+$/.test(raw) ? Number(raw) : raw
|
|
2136
|
-
api("POST", "/clock", { set }).then(renderClock).catch(showError)
|
|
2137
|
-
})
|
|
2138
|
-
|
|
2139
|
-
$("fault-form").addEventListener("submit", (event) => {
|
|
2140
|
-
event.preventDefault()
|
|
2141
|
-
const preset = $("fault-preset").value
|
|
2142
|
-
const body = preset
|
|
2143
|
-
? { preset }
|
|
2144
|
-
: {
|
|
2145
|
-
status: Number($("fault-status").value),
|
|
2146
|
-
...($("fault-path").value ? { pathPrefix: $("fault-path").value } : {}),
|
|
2147
|
-
...($("fault-method").value ? { method: $("fault-method").value } : {})
|
|
2148
|
-
}
|
|
2149
|
-
if (!preset && !Number.isFinite(body.status)) {
|
|
2150
|
-
showError(new Error("Status must be a number, or choose a preset"))
|
|
2151
|
-
return
|
|
2152
|
-
}
|
|
2153
|
-
api("POST", "/faults", body).then(renderFaults).catch(showError)
|
|
2154
|
-
})
|
|
2155
|
-
$("fault-clear").addEventListener("click", () => api("DELETE", "/faults").then(renderFaults).catch(showError))
|
|
2156
|
-
$("journal-clear").addEventListener("click", () => api("DELETE", "/requests").then(renderJournal).catch(showError))
|
|
2157
|
-
|
|
2158
|
-
$("route-list").addEventListener("click", (event) => {
|
|
2159
|
-
const button = event.target.closest("[data-route]")
|
|
2160
|
-
if (!button) return
|
|
2161
|
-
state.route = button.dataset.route
|
|
2162
|
-
$("route-title").textContent = state.route
|
|
2163
|
-
const method = state.route.split(" ")[0]
|
|
2164
|
-
$("route-body").disabled = method === "GET" || method === "DELETE"
|
|
2165
|
-
})
|
|
2166
|
-
$("route-form").addEventListener("submit", async (event) => {
|
|
2167
|
-
event.preventDefault()
|
|
2168
|
-
if (!state.route) return showError(new Error("Choose a route first"))
|
|
2169
|
-
const [method, path] = [state.route.split(" ")[0], state.route.split(" ").slice(1).join(" ")]
|
|
2170
|
-
const concrete = path.replace(/:([A-Za-z0-9_]+)/g, (_, key) => prompt("Value for " + key) || "")
|
|
2171
|
-
let body
|
|
2172
|
-
if (method !== "GET" && method !== "DELETE" && $("route-body").value.trim()) {
|
|
2173
|
-
try { body = JSON.parse($("route-body").value) }
|
|
2174
|
-
catch { return showError(new Error("Body is not JSON")) }
|
|
2175
|
-
}
|
|
2176
|
-
try {
|
|
2177
|
-
const data = await api(method, concrete, body)
|
|
2178
|
-
$("route-result").textContent = JSON.stringify(data, null, 2)
|
|
2179
|
-
} catch (error) {
|
|
2180
|
-
showError(error)
|
|
2181
|
-
}
|
|
2182
|
-
})
|
|
2183
|
-
|
|
2184
|
-
function mountPanels(panels) {
|
|
2185
|
-
const nav = $("nav")
|
|
2186
|
-
const views = $("views")
|
|
2187
|
-
for (const panel of panels) {
|
|
2188
|
-
const button = document.createElement("button")
|
|
2189
|
-
button.type = "button"
|
|
2190
|
-
button.dataset.view = panel.id
|
|
2191
|
-
button.textContent = panel.title
|
|
2192
|
-
nav.append(button)
|
|
2193
|
-
const section = document.createElement("section")
|
|
2194
|
-
section.className = "view"
|
|
2195
|
-
section.id = "view-" + panel.id
|
|
2196
|
-
section.hidden = true
|
|
2197
|
-
const title = document.createElement("h2")
|
|
2198
|
-
title.textContent = panel.title
|
|
2199
|
-
const lede = document.createElement("p")
|
|
2200
|
-
lede.className = "lede"
|
|
2201
|
-
lede.textContent = panel.description || ""
|
|
2202
|
-
const body = document.createElement("div")
|
|
2203
|
-
body.className = "panel-body"
|
|
2204
|
-
body.id = "panel-" + panel.id
|
|
2205
|
-
body.innerHTML = panel.html || ""
|
|
2206
|
-
section.append(title, lede, body)
|
|
2207
|
-
views.append(section)
|
|
2208
|
-
if (panel.script) {
|
|
2209
|
-
try {
|
|
2210
|
-
const run = new Function("root", "api", panel.script)
|
|
2211
|
-
run(body, panelApi)
|
|
2212
|
-
} catch (error) {
|
|
2213
|
-
const note = document.createElement("p")
|
|
2214
|
-
note.className = "banner show"
|
|
2215
|
-
note.textContent = error instanceof Error ? error.message : String(error)
|
|
2216
|
-
body.append(note)
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
loadNamespaces()
|
|
2223
|
-
.then(() => api("GET", "/ui/manifest"))
|
|
2224
|
-
.then((manifest) => { mountPanels((manifest && manifest.panels) || []); return refresh() })
|
|
2225
|
-
.catch(showError)
|
|
2226
|
-
})()
|
|
2227
|
-
</script>
|
|
3028
|
+
${script}
|
|
2228
3029
|
</body>
|
|
2229
3030
|
</html>`;
|
|
2230
3031
|
};
|
|
@@ -2241,10 +3042,10 @@ var json2 = (body) => new Response(JSON.stringify(body), {
|
|
|
2241
3042
|
});
|
|
2242
3043
|
var adminUiRoutes = (service, ui) => {
|
|
2243
3044
|
const shell = () => renderAdminDocument(service);
|
|
2244
|
-
const
|
|
3045
|
+
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
2245
3046
|
return {
|
|
2246
|
-
"GET /ui": () => htmlResponse(
|
|
2247
|
-
"GET /ui/": () => htmlResponse(
|
|
3047
|
+
"GET /ui": () => htmlResponse(document3()),
|
|
3048
|
+
"GET /ui/": () => htmlResponse(document3()),
|
|
2248
3049
|
"GET /ui/manifest": () => json2({
|
|
2249
3050
|
service,
|
|
2250
3051
|
panels: (ui?.panels ?? []).map((panel) => ({
|
|
@@ -2270,11 +3071,11 @@ var EXTENSION_KEYS = {
|
|
|
2270
3071
|
};
|
|
2271
3072
|
|
|
2272
3073
|
// ../../openapi/metadata/dist/read.js
|
|
2273
|
-
var
|
|
3074
|
+
var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2274
3075
|
var extensionOf = (holder, key) => holder[key];
|
|
2275
3076
|
var operationMetadata = (operation) => {
|
|
2276
3077
|
const raw = extensionOf(operation, EXTENSION_KEYS.operation);
|
|
2277
|
-
const ext =
|
|
3078
|
+
const ext = isRecord3(raw) ? raw : {};
|
|
2278
3079
|
const supported = ext.supported ?? true;
|
|
2279
3080
|
const parity = ext.parity ?? {};
|
|
2280
3081
|
return {
|
|
@@ -2384,9 +3185,9 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
2384
3185
|
this.name = "OperationRegistryError";
|
|
2385
3186
|
}
|
|
2386
3187
|
};
|
|
2387
|
-
var verifyOperations = (
|
|
3188
|
+
var verifyOperations = (document3, handlers) => {
|
|
2388
3189
|
const problems = [];
|
|
2389
|
-
const operations = listOperations(
|
|
3190
|
+
const operations = listOperations(document3);
|
|
2390
3191
|
const seen = /* @__PURE__ */ new Set();
|
|
2391
3192
|
for (const operation of operations) {
|
|
2392
3193
|
if (seen.has(operation.operationId))
|
|
@@ -2502,7 +3303,7 @@ var SAMPLE = 25;
|
|
|
2502
3303
|
var WALK_LIMIT = 1e4;
|
|
2503
3304
|
var SKIP_CTORS = /* @__PURE__ */ new Set(["Hono", "HonoRequest", "Router"]);
|
|
2504
3305
|
var fail = (status, message) => ({ ok: false, status, message });
|
|
2505
|
-
var
|
|
3306
|
+
var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2506
3307
|
var kindOf = (value) => {
|
|
2507
3308
|
if (value === null)
|
|
2508
3309
|
return "null";
|
|
@@ -2601,7 +3402,7 @@ var absorb = (accum, value) => {
|
|
|
2601
3402
|
const kind = kindOf(value);
|
|
2602
3403
|
accum.kinds.add(kind);
|
|
2603
3404
|
accum.present++;
|
|
2604
|
-
if (!
|
|
3405
|
+
if (!isRecord4(value))
|
|
2605
3406
|
return;
|
|
2606
3407
|
for (const [key, child] of Object.entries(value)) {
|
|
2607
3408
|
const nested = accum.nested.get(key) ?? blankAccum(key);
|
|
@@ -2626,7 +3427,7 @@ var inferFields = (records) => {
|
|
|
2626
3427
|
if (records.length === 0)
|
|
2627
3428
|
return [];
|
|
2628
3429
|
const sample = records.slice(0, SAMPLE);
|
|
2629
|
-
const objects = sample.filter((record2) =>
|
|
3430
|
+
const objects = sample.filter((record2) => isRecord4(record2.value));
|
|
2630
3431
|
if (objects.length === 0) {
|
|
2631
3432
|
const kinds = new Set(sample.map((record2) => kindOf(record2.value)));
|
|
2632
3433
|
const list = [...kinds];
|
|
@@ -2813,7 +3614,7 @@ var patchStateRecord = (scope, name, id, value) => {
|
|
|
2813
3614
|
const parsed = jsonValue(value);
|
|
2814
3615
|
if (!parsed.ok)
|
|
2815
3616
|
return parsed;
|
|
2816
|
-
const next =
|
|
3617
|
+
const next = isRecord4(current.value.value) && isRecord4(parsed.value) ? { ...current.value.value, ...parsed.value } : parsed.value;
|
|
2817
3618
|
return replaceStateRecord(scope, name, id, next);
|
|
2818
3619
|
};
|
|
2819
3620
|
var deleteStateRecord = (scope, name, id) => {
|
|
@@ -2881,7 +3682,7 @@ var stateAdminRoutes = (routes) => {
|
|
|
2881
3682
|
const scope = open(namespace);
|
|
2882
3683
|
if (!scope.ok)
|
|
2883
3684
|
return fromResult(scope, 201);
|
|
2884
|
-
if (!
|
|
3685
|
+
if (!isRecord4(body) || !("value" in body)) {
|
|
2885
3686
|
return adminError2(400, 'expected {"id?": "<id>", "value": <json>}');
|
|
2886
3687
|
}
|
|
2887
3688
|
const id = body.id;
|
|
@@ -2899,7 +3700,7 @@ var stateAdminRoutes = (routes) => {
|
|
|
2899
3700
|
const scope = open(namespace);
|
|
2900
3701
|
if (!scope.ok)
|
|
2901
3702
|
return fromResult(scope, 200);
|
|
2902
|
-
if (!
|
|
3703
|
+
if (!isRecord4(body) || !("value" in body))
|
|
2903
3704
|
return adminError2(400, 'expected {"value": <json>}');
|
|
2904
3705
|
const replaced = replaceStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
2905
3706
|
if (replaced.ok)
|
|
@@ -2910,7 +3711,7 @@ var stateAdminRoutes = (routes) => {
|
|
|
2910
3711
|
const scope = open(namespace);
|
|
2911
3712
|
if (!scope.ok)
|
|
2912
3713
|
return fromResult(scope, 200);
|
|
2913
|
-
if (!
|
|
3714
|
+
if (!isRecord4(body) || !("value" in body))
|
|
2914
3715
|
return adminError2(400, 'expected {"value": <json>}');
|
|
2915
3716
|
const patched = patchStateRecord(scope.value, params.collection ?? "", params.id ?? "", body.value);
|
|
2916
3717
|
if (patched.ok)
|
|
@@ -2930,14 +3731,14 @@ var stateAdminRoutes = (routes) => {
|
|
|
2930
3731
|
};
|
|
2931
3732
|
|
|
2932
3733
|
// ../core/dist/version.js
|
|
2933
|
-
var PACKAGE_VERSION = true ? "1.
|
|
3734
|
+
var PACKAGE_VERSION = true ? "1.5.1" : UNRELEASED_VERSION;
|
|
2934
3735
|
|
|
2935
3736
|
// ../core/dist/webhooks.js
|
|
2936
3737
|
var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
2937
3738
|
var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
|
|
2938
|
-
var
|
|
3739
|
+
var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2939
3740
|
var parseEndpoint = (value) => {
|
|
2940
|
-
if (!
|
|
3741
|
+
if (!isRecord5(value) || typeof value.url !== "string")
|
|
2941
3742
|
return "each endpoint needs a url";
|
|
2942
3743
|
try {
|
|
2943
3744
|
new URL(value.url);
|
|
@@ -2954,12 +3755,12 @@ var parseEndpoint = (value) => {
|
|
|
2954
3755
|
const events = value.events ?? value.enabledEvents;
|
|
2955
3756
|
if (Array.isArray(events))
|
|
2956
3757
|
endpoint.events = events.map(String);
|
|
2957
|
-
if (
|
|
3758
|
+
if (isRecord5(value.tags)) {
|
|
2958
3759
|
endpoint.tags = Object.fromEntries(Object.entries(value.tags).map(([k, v]) => [k, String(v)]));
|
|
2959
3760
|
}
|
|
2960
3761
|
if (typeof value.account === "string")
|
|
2961
3762
|
endpoint.tags = { ...endpoint.tags, account: value.account };
|
|
2962
|
-
if (
|
|
3763
|
+
if (isRecord5(value.headers)) {
|
|
2963
3764
|
endpoint.headers = Object.fromEntries(Object.entries(value.headers).map(([k, v]) => [k, String(v)]));
|
|
2964
3765
|
}
|
|
2965
3766
|
return endpoint;
|
|
@@ -2986,7 +3787,7 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
2986
3787
|
return json4(200, { status: "ok" });
|
|
2987
3788
|
},
|
|
2988
3789
|
"POST /webhooks/faults": ({ body, namespace }) => {
|
|
2989
|
-
if (!
|
|
3790
|
+
if (!isRecord5(body) || !["duplicate", "reorder", "drop"].includes(String(body.mode))) {
|
|
2990
3791
|
return adminError3(400, "mode must be duplicate, reorder or drop");
|
|
2991
3792
|
}
|
|
2992
3793
|
const fault = { mode: body.mode };
|
|
@@ -3002,7 +3803,7 @@ var webhookAdminRoutes = (hub) => ({
|
|
|
3002
3803
|
}))
|
|
3003
3804
|
}),
|
|
3004
3805
|
"PUT /webhook-endpoints": ({ body, namespace }) => {
|
|
3005
|
-
const list = Array.isArray(body) ? body :
|
|
3806
|
+
const list = Array.isArray(body) ? body : isRecord5(body) ? body.endpoints : void 0;
|
|
3006
3807
|
if (!Array.isArray(list))
|
|
3007
3808
|
return adminError3(400, "expected [{url, secret?, events?}]");
|
|
3008
3809
|
const parsed = [];
|
|
@@ -3072,8 +3873,8 @@ var DroppedConnectionError = class extends TypeError {
|
|
|
3072
3873
|
this.name = "TypeError";
|
|
3073
3874
|
}
|
|
3074
3875
|
};
|
|
3075
|
-
var operationMatcher = (
|
|
3076
|
-
const matchers = listOperations(
|
|
3876
|
+
var operationMatcher = (document3) => {
|
|
3877
|
+
const matchers = listOperations(document3).map((operation) => ({
|
|
3077
3878
|
operationId: operation.operationId,
|
|
3078
3879
|
method: operation.method.toUpperCase(),
|
|
3079
3880
|
pattern: new RegExp(`^${operation.path.split("/").map((segment) => segment.startsWith("{") ? "[^/]+" : segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("/")}/?$`),
|
|
@@ -3168,10 +3969,10 @@ var createRuntime = (options) => {
|
|
|
3168
3969
|
const ensureBranch = (namespace, branch2, at) => {
|
|
3169
3970
|
if (!BRANCH_PATTERN2.test(branch2))
|
|
3170
3971
|
throw new RangeError(`branch must match ${BRANCH_PATTERN2}`);
|
|
3171
|
-
const
|
|
3972
|
+
const history2 = timeline(namespace);
|
|
3172
3973
|
if (branch2 === "main") {
|
|
3173
3974
|
if (at !== void 0) {
|
|
3174
|
-
const point =
|
|
3975
|
+
const point = history2.checkout("main", at);
|
|
3175
3976
|
restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
|
|
3176
3977
|
captured.set(namespace, point.value.snapshot);
|
|
3177
3978
|
rng.setState(point.value.rngState);
|
|
@@ -3184,10 +3985,10 @@ var createRuntime = (options) => {
|
|
|
3184
3985
|
return namespace;
|
|
3185
3986
|
}
|
|
3186
3987
|
const storage = physicalBranch(namespace, branch2);
|
|
3187
|
-
if (!
|
|
3988
|
+
if (!history2.hasBranch(branch2)) {
|
|
3188
3989
|
if (at === void 0)
|
|
3189
|
-
|
|
3190
|
-
const point =
|
|
3990
|
+
history2.commit(capture(namespace));
|
|
3991
|
+
const point = history2.fork(branch2, at === void 0 ? {} : { from: at });
|
|
3191
3992
|
const branchRng = createRng(options.seed ?? 0);
|
|
3192
3993
|
if (point)
|
|
3193
3994
|
branchRng.setState(point.value.rngState);
|
|
@@ -3196,8 +3997,8 @@ var createRuntime = (options) => {
|
|
|
3196
3997
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
3197
3998
|
if (point)
|
|
3198
3999
|
captured.set(storage, point.value.snapshot);
|
|
3199
|
-
} else if (at !== void 0 &&
|
|
3200
|
-
const point =
|
|
4000
|
+
} else if (at !== void 0 && history2.head(branch2)?.id !== at) {
|
|
4001
|
+
const point = history2.checkout(branch2, at);
|
|
3201
4002
|
if (!instances.has(storage)) {
|
|
3202
4003
|
const branchRng = createRng(options.seed ?? 0);
|
|
3203
4004
|
branchRng.setState(point.value.rngState);
|
|
@@ -3208,7 +4009,7 @@ var createRuntime = (options) => {
|
|
|
3208
4009
|
captured.set(storage, point.value.snapshot);
|
|
3209
4010
|
} else {
|
|
3210
4011
|
if (!instances.has(storage)) {
|
|
3211
|
-
const point =
|
|
4012
|
+
const point = history2.head(branch2);
|
|
3212
4013
|
const branchRng = createRng(options.seed ?? 0);
|
|
3213
4014
|
if (point)
|
|
3214
4015
|
branchRng.setState(point.value.rngState);
|
|
@@ -3232,8 +4033,8 @@ var createRuntime = (options) => {
|
|
|
3232
4033
|
const checkout = (checkpointId, checkoutOptions = {}) => {
|
|
3233
4034
|
const namespace = checkoutOptions.namespace ?? DEFAULT_NAMESPACE;
|
|
3234
4035
|
const branchName = checkoutOptions.branch ?? "main";
|
|
3235
|
-
const
|
|
3236
|
-
const point =
|
|
4036
|
+
const history2 = timeline(namespace);
|
|
4037
|
+
const point = history2.checkout(branchName, checkpointId);
|
|
3237
4038
|
const storage = ensureBranch(namespace, branchName);
|
|
3238
4039
|
restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
|
|
3239
4040
|
captured.set(storage, point.value.snapshot);
|
|
@@ -3283,9 +4084,9 @@ var createRuntime = (options) => {
|
|
|
3283
4084
|
instance(name);
|
|
3284
4085
|
restoreNamespace(sqlite, storageNamespace(name), from);
|
|
3285
4086
|
captured.set(name, from);
|
|
3286
|
-
const
|
|
3287
|
-
if (
|
|
3288
|
-
|
|
4087
|
+
const history2 = timelines.get(name);
|
|
4088
|
+
if (history2)
|
|
4089
|
+
history2.commit(capture(name), { branch: "main" });
|
|
3289
4090
|
else
|
|
3290
4091
|
timeline(name);
|
|
3291
4092
|
};
|
|
@@ -3514,10 +4315,10 @@ var createRuntime = (options) => {
|
|
|
3514
4315
|
},
|
|
3515
4316
|
release: (name, checkpointId) => timeline(name).release(checkpointId),
|
|
3516
4317
|
inspect: (name) => {
|
|
3517
|
-
const
|
|
4318
|
+
const history2 = timeline(name);
|
|
3518
4319
|
return {
|
|
3519
|
-
branches:
|
|
3520
|
-
checkpoints:
|
|
4320
|
+
branches: history2.branches(),
|
|
4321
|
+
checkpoints: history2.checkpoints().map(({ id, branch: branchName, parent, at }) => ({
|
|
3521
4322
|
id,
|
|
3522
4323
|
branch: branchName,
|
|
3523
4324
|
parent,
|
|
@@ -3532,11 +4333,11 @@ var createRuntime = (options) => {
|
|
|
3532
4333
|
} : {},
|
|
3533
4334
|
routes: {
|
|
3534
4335
|
...credentialRoutes(credentials),
|
|
3535
|
-
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
3536
4336
|
...options.webhooks ? webhookAdminRoutes(options.webhooks) : {},
|
|
3537
4337
|
...options.admin?.(runtime) ?? {},
|
|
3538
|
-
//
|
|
3539
|
-
//
|
|
4338
|
+
// Shell routes win a colliding key. Fault presets are one of them: the admin page
|
|
4339
|
+
// maps `presets`, and a service route must not replace that list with a record.
|
|
4340
|
+
...options.presets ? presetRoutes(options.presets, runtime) : {},
|
|
3540
4341
|
...stateAdminRoutes({
|
|
3541
4342
|
open: stateScope,
|
|
3542
4343
|
afterWrite: (namespace) => {
|
|
@@ -3611,9 +4412,12 @@ var credentialRoutes = (registry) => ({
|
|
|
3611
4412
|
}
|
|
3612
4413
|
});
|
|
3613
4414
|
var presetRoutes = (presets, runtime) => ({
|
|
3614
|
-
"GET /faults/presets": () =>
|
|
3615
|
-
|
|
3616
|
-
|
|
4415
|
+
"GET /faults/presets": () => {
|
|
4416
|
+
const body = {
|
|
4417
|
+
presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
|
|
4418
|
+
};
|
|
4419
|
+
return adminJson(200, body);
|
|
4420
|
+
},
|
|
3617
4421
|
"POST /faults/presets/:name": ({ params, body, namespace }) => {
|
|
3618
4422
|
const name = params.name;
|
|
3619
4423
|
if (!presets[name])
|
|
@@ -3786,7 +4590,7 @@ var unitPrice = (catalog, sku) => {
|
|
|
3786
4590
|
};
|
|
3787
4591
|
|
|
3788
4592
|
// src/generated/openapi.ts
|
|
3789
|
-
var
|
|
4593
|
+
var document2 = JSON.parse(`{"openapi":"3.1.0","info":{"title":"Wholescripts supplement fulfilment API (Mockingbird subset)","description":"Stateful mock subset of the Wholescripts ordering API: the product and private-label\\n(MedPax) catalogs, order submit, status polling and cancel. Hand-authored from the\\nconsumers' zod schemas and clients (the vendor publishes no spec).\\n","version":"1","x-mockingbird-upstream":{"note":"Hand-authored from the wire shapes our consumers read and write (backend and EMR wholescripts.types.ts zod schemas, the supplement scheduler's Python client, adapter and mappers)."}},"servers":[{"url":"https://api.wholescripts.com"}],"security":[{"basicAuth":[]}],"paths":{"/api/Orders/PrivateLabelProductList":{"get":{"operationId":"GetPrivateLabelProductList","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"responses":{"200":{"description":"Private-label (MedPax) catalog","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PrivateLabelProductList"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/ProductList":{"get":{"operationId":"GetProductList","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"instockonly","in":"query","required":false,"description":"\`true\` keeps only rows with quantity > 0 (the EMR sends it).","schema":{"type":"string","enum":["true","false"]}},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":1000}},{"name":"search","in":"query","required":false,"description":"Case-insensitive match on name, SKU, MedPax SKU, brand or categories (the supplement scheduler).","schema":{"type":"string","maxLength":40}}],"responses":{"200":{"description":"Products","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/Product"}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/Submit":{"post":{"operationId":"SubmitOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderSubmitRequest"}}}},"responses":{"200":{"description":"Submit outcome. A rejected order (bad body, unknown SKU, payment failure) is still 200, with success false and the reason in msg.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderSubmitResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/Status":{"get":{"operationId":"GetOrderStatus","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":true}},"parameters":[{"name":"ordernum","in":"query","required":true,"schema":{"type":"string","x-mockingbird-resource-ref":{"type":"order","missing":"000000"}}}],"responses":{"200":{"description":"The order's status rows (empty for an unknown order number)","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/OrderStatus"}}}}},"400":{"description":"Missing ordernum","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AspNetError"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}},"/api/Orders/Cancel":{"post":{"operationId":"CancelOrder","x-mockingbird":{"supported":true,"parity":{"enabled":true,"safe":false}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["OrderNumber"],"properties":{"OrderNumber":{"type":"string","x-mockingbird-resource-ref":{"type":"order","missing":"000000"}}}}}}},"responses":{"200":{"description":"Cancel outcome; success false when the order has progressed too far","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}},"400":{"description":"Missing OrderNumber","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"description":"Unknown order","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CancelResponse"}}}}}}}},"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic"}},"responses":{"Unauthorized":{"description":"Missing or wrong Basic credentials","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AspNetError"}}}}},"schemas":{"AspNetError":{"type":"object","required":["Message"],"properties":{"Message":{"type":"string"}}},"DefaultDosing":{"type":"object","required":["time","qty"],"properties":{"time":{"type":"string"},"qty":{"type":"number"}}},"MedPaxDetails":{"type":"object","required":["name","genericName","quantity","wholesalePrice","retailPrice"],"properties":{"name":{"type":"string"},"genericName":{"type":"string"},"quantity":{"type":"number"},"wholesalePrice":{"type":"number"},"retailPrice":{"type":"number"}}},"Product":{"type":"object","required":["productName","sku","medPaxSku","categories","retailPrice","upc","descriptionShort","brand","productImage","quantity","countUnit","wholesalePrice","supplementFactsHTML","defaultDosing"],"properties":{"productName":{"type":"string"},"sku":{"type":"string","x-mockingbird-resource":{"type":"sku","identity":true}},"medPaxSku":{"type":"string"},"categories":{"type":"string"},"retailPrice":{"type":"number"},"upc":{"type":"string"},"descriptionShort":{"type":"string"},"descriptionFull":{"type":"string"},"brand":{"type":"string"},"productImage":{"type":"string"},"quantity":{"type":"number"},"countUnit":{"type":"string"},"wholesalePrice":{"type":"number"},"supplementFactsHTML":{"type":"string"},"defaultDosing":{"type":"array","items":{"$ref":"#/components/schemas/DefaultDosing"}},"medPaxDetails":{"oneOf":[{"$ref":"#/components/schemas/MedPaxDetails"},{"type":"null"}]}}},"PrivateLabelProductList":{"type":"object","required":["privateLabelProducts","medPaxPills","privateLabelCartons"],"properties":{"privateLabelProducts":{"type":"array","items":{}},"medPaxPills":{"type":"array","items":{"type":"object","required":["sku","genericName","privateLabelName","quantity"],"properties":{"sku":{"type":"string","x-mockingbird-resource":{"type":"sku","identity":true}},"genericName":{"type":"string"},"privateLabelName":{"type":"string"},"quantity":{"type":"number"}}}},"privateLabelCartons":{"type":"array","items":{"type":"object","required":["sku","name","cartonImage","quantity"],"properties":{"sku":{"type":"string","x-mockingbird-resource":{"type":"sku","identity":true}},"name":{"type":"string"},"cartonImage":{"type":"string"},"quantity":{"type":"number"}}}}}},"MedPaxPill":{"type":"object","required":["Sku","Quantity","ItemTime"],"properties":{"productId":{"type":"string","maxLength":64},"Sku":{"type":"string","x-mockingbird-resource-ref":{"type":"sku","missing":"000000000000000000"}},"Quantity":{"type":"integer","minimum":1,"maximum":1000},"ItemTime":{"type":"string","enum":["AM","PM","AM with food","PM with food"]}}},"OrderItem":{"type":"object","required":["Sku","Quantity"],"properties":{"Sku":{"type":"string","x-mockingbird-resource-ref":{"type":"sku","missing":"000000000000000000"}},"Quantity":{"type":"integer","minimum":1,"maximum":1000},"MedPaxName":{"type":["string","null"],"maxLength":60},"MedPaxPills":{"type":["array","null"],"description":"The pills packed into one MedPax box. The vendor places boxes of at least 14 pills; the bound only keeps generated bodies small.","maxItems":30,"items":{"$ref":"#/components/schemas/MedPaxPill"}}}},"OrderSubmitRequest":{"type":"object","required":["ShippingAddress","Items","ShippingMethod"],"properties":{"ShippingAddress":{"type":"object","required":["FName","LName","Address1","City","State","Zip"],"properties":{"FName":{"type":"string","minLength":1,"maxLength":40},"LName":{"type":"string","minLength":1,"maxLength":40},"Address1":{"type":"string","minLength":1,"maxLength":80},"Address2":{"type":["string","null"],"maxLength":80},"City":{"type":"string","minLength":1,"maxLength":40},"State":{"type":"string","pattern":"^[A-Z]{2}$"},"Zip":{"type":"string","pattern":"^[0-9]{5}(-[0-9]{4})?$"},"Email":{"type":"string","format":"email","maxLength":120}}},"Notes":{"type":["string","null"],"maxLength":500},"Items":{"type":"array","minItems":1,"maxItems":4,"items":{"$ref":"#/components/schemas/OrderItem"}},"ShippingMethod":{"type":"string","minLength":1,"maxLength":40}}},"OrderSubmitResponse":{"type":"object","required":["orderNumber","success","msg"],"properties":{"orderNumber":{"type":"string","x-mockingbird-resource":{"type":"order","identity":true}},"success":{"type":"boolean"},"msg":{"type":"string"}}},"Tracking":{"type":"object","required":["trackingNumber","carrier"],"properties":{"trackingNumber":{"type":"string"},"carrier":{"type":"string"},"trackingUrl":{"type":"string"}}},"OrderStatus":{"type":"object","required":["orderNumber","orderDate","salesOrder","status","tracking","message","subTotal","shipMethod","shipCharge","discount","tax","serviceFee","orderTotal"],"properties":{"orderNumber":{"type":"string"},"orderDate":{"type":"string","x-mockingbird-volatile":{"kind":"timestamp"}},"salesOrder":{"type":"string"},"status":{"type":"string"},"tracking":{"type":"array","items":{"$ref":"#/components/schemas/Tracking"}},"message":{"type":"string"},"subTotal":{"type":"number"},"shipMethod":{"type":"string"},"shipCharge":{"type":"number"},"discount":{"type":"number"},"tax":{"type":"number"},"serviceFee":{"type":"number"},"orderTotal":{"type":"number"}}},"CancelResponse":{"type":"object","required":["success","msg"],"properties":{"success":{"type":"boolean"},"msg":{"type":"string"}}}}}}`);
|
|
3790
4594
|
var operationIds = ["GetPrivateLabelProductList", "GetProductList", "SubmitOrder", "GetOrderStatus", "CancelOrder"];
|
|
3791
4595
|
var supportedOperationIds = ["GetPrivateLabelProductList", "GetProductList", "SubmitOrder", "GetOrderStatus", "CancelOrder"];
|
|
3792
4596
|
|
|
@@ -3863,10 +4667,10 @@ var WHOLESCRIPTS_PRESETS = {
|
|
|
3863
4667
|
};
|
|
3864
4668
|
var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
|
|
3865
4669
|
var adminError4 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
|
|
3866
|
-
var
|
|
4670
|
+
var isRecord6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3867
4671
|
var parseAutoAdvance = (value) => {
|
|
3868
4672
|
if (value === null) return null;
|
|
3869
|
-
if (!
|
|
4673
|
+
if (!isRecord6(value)) return "autoAdvance must be {afterMs, path} or null";
|
|
3870
4674
|
if (typeof value.afterMs !== "number" || value.afterMs < 0)
|
|
3871
4675
|
return "autoAdvance.afterMs must be ms";
|
|
3872
4676
|
if (!Array.isArray(value.path) || value.path.some((s) => typeof s !== "string")) {
|
|
@@ -3877,7 +4681,7 @@ var parseAutoAdvance = (value) => {
|
|
|
3877
4681
|
var adminRoutes = (runtime) => ({
|
|
3878
4682
|
"GET /orders": ({ namespace }) => json5(200, { orders: runtime.instance(namespace).orders() }),
|
|
3879
4683
|
"POST /orders/:id/transition": ({ params, body, namespace }) => {
|
|
3880
|
-
if (!
|
|
4684
|
+
if (!isRecord6(body) || typeof body.to !== "string") {
|
|
3881
4685
|
return adminError4(
|
|
3882
4686
|
400,
|
|
3883
4687
|
'expected {"to": "Pending|Processing|Complete|Cancelled|Error|\u2026", "trackingNumber"?, "carrier"?, "message"?}'
|
|
@@ -3895,7 +4699,7 @@ var adminRoutes = (runtime) => ({
|
|
|
3895
4699
|
},
|
|
3896
4700
|
"GET /catalog": ({ namespace }) => json5(200, runtime.instance(namespace).state.catalog()),
|
|
3897
4701
|
"PUT /catalog": ({ body, namespace }) => {
|
|
3898
|
-
if (!
|
|
4702
|
+
if (!isRecord6(body) || !Array.isArray(body.products) || !Array.isArray(body.medPaxPills) || !Array.isArray(body.privateLabelCartons)) {
|
|
3899
4703
|
return adminError4(
|
|
3900
4704
|
400,
|
|
3901
4705
|
"expected {products: [...], medPaxPills: [...], privateLabelCartons: [...]}"
|
|
@@ -3905,11 +4709,11 @@ var adminRoutes = (runtime) => ({
|
|
|
3905
4709
|
},
|
|
3906
4710
|
"GET /settings": ({ namespace }) => json5(200, runtime.instance(namespace).state.current()),
|
|
3907
4711
|
"PUT /settings": ({ body, namespace }) => {
|
|
3908
|
-
if (!
|
|
4712
|
+
if (!isRecord6(body)) return adminError4(400, "expected a JSON object");
|
|
3909
4713
|
const patch = {};
|
|
3910
4714
|
if (body.accounts !== void 0) {
|
|
3911
4715
|
if (!Array.isArray(body.accounts)) return adminError4(400, "accounts: [{username, password}]");
|
|
3912
|
-
patch.accounts = body.accounts.filter(
|
|
4716
|
+
patch.accounts = body.accounts.filter(isRecord6).map((a) => ({
|
|
3913
4717
|
username: String(a.username),
|
|
3914
4718
|
password: String(a.password)
|
|
3915
4719
|
}));
|
|
@@ -3926,7 +4730,7 @@ var adminRoutes = (runtime) => ({
|
|
|
3926
4730
|
var createRuntime2 = (options = {}) => {
|
|
3927
4731
|
const runtime = createRuntime({
|
|
3928
4732
|
name: WHOLESCRIPTS_NAMESPACE,
|
|
3929
|
-
document,
|
|
4733
|
+
document: document2,
|
|
3930
4734
|
...options.sqlite ? { sqlite: options.sqlite } : {},
|
|
3931
4735
|
...options.clock ? { clock: options.clock } : {},
|
|
3932
4736
|
...options.seed !== void 0 ? { seed: options.seed } : {},
|
|
@@ -4018,7 +4822,7 @@ var WholescriptsAPI = class {
|
|
|
4018
4822
|
CancelOrder: (context) => this.cancel(context)
|
|
4019
4823
|
});
|
|
4020
4824
|
this.service = createService({
|
|
4021
|
-
document,
|
|
4825
|
+
document: document2,
|
|
4022
4826
|
handlers,
|
|
4023
4827
|
sqlite,
|
|
4024
4828
|
namespace,
|
|
@@ -4234,7 +5038,7 @@ var WholescriptsAPI = class {
|
|
|
4234
5038
|
export {
|
|
4235
5039
|
MEDPAX_BOX_SKU,
|
|
4236
5040
|
DEFAULT_CATALOG,
|
|
4237
|
-
document,
|
|
5041
|
+
document2 as document,
|
|
4238
5042
|
operationIds,
|
|
4239
5043
|
supportedOperationIds,
|
|
4240
5044
|
WHOLESCRIPTS_PRESETS,
|
|
@@ -4244,4 +5048,4 @@ export {
|
|
|
4244
5048
|
canonicalStatus,
|
|
4245
5049
|
WholescriptsAPI
|
|
4246
5050
|
};
|
|
4247
|
-
//# sourceMappingURL=chunk-
|
|
5051
|
+
//# sourceMappingURL=chunk-J3DC2RKQ.js.map
|