@oddington/sdk 0.1.47 → 0.1.49
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/README.md +28 -36
- package/dist/browser.js +127 -226
- package/dist/index.js +3 -3
- package/dist/types/packages/sdk/src/public.d.ts +7 -4
- package/dist/types/shared/data-contract.d.ts +12 -48
- package/dist/types/shared/inbox-contract.d.ts +6 -36
- package/dist/types/shared/inbox-member-contract.d.ts +3 -5
- package/dist/types/shared/inbox-member-types.d.ts +7 -2
- package/dist/types/shared/inbox-records.d.ts +19 -0
- package/dist/types/shared/inbox-views.d.ts +6 -91
- package/dist/types/shared/record-selection.d.ts +0 -1
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -319,6 +319,11 @@ function validateRoutineSchemaValue(schema2, value, rejected) {
|
|
|
319
319
|
check(schema2, value, "$");
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
var RECORD_READ_INPUT_LIMIT = 1024 * 1024, RECORD_CAPTURE_OUTPUT_LIMIT = 25 * 1024 * 1024;
|
|
323
|
+
function validRecordRef(value) {
|
|
324
|
+
return typeof value == "string" && value.length <= 512 && /^[_a-zA-Z0-9][a-zA-Z0-9_-]*(\/[_a-zA-Z0-9][a-zA-Z0-9_-]*)+$/.test(value);
|
|
325
|
+
}
|
|
326
|
+
|
|
322
327
|
function validDropboxRootPath(value) {
|
|
323
328
|
return typeof value == "string" && value.length <= 2048 && value.startsWith("/") && !/[\\\x00-\x1f\x7f]/.test(value) && value.slice(1).split("/").every((segment) => segment.length > 0 && segment.trim() === segment && segment !== "." && segment !== "..");
|
|
324
329
|
}
|
|
@@ -449,12 +454,9 @@ function validateInboxFile(value) {
|
|
|
449
454
|
let size = natural(v.size, "file size");
|
|
450
455
|
return size > FILE_ORIGINAL_MAX_BYTES && fail("File exceeds supported size"), { id: fileId, name: name2, mediaType, size, sha256: v.sha256 };
|
|
451
456
|
}
|
|
452
|
-
function
|
|
453
|
-
let
|
|
454
|
-
|
|
455
|
-
return keys(field, ["label", "value"], "field"), { label: text(field.label, "field label"), value: text(field.value, "field value") };
|
|
456
|
-
});
|
|
457
|
-
return new Set(result2.map((field) => field.label)).size !== result2.length && fail("Duplicate field label"), result2;
|
|
457
|
+
function validateQualifiedRecordRef(value) {
|
|
458
|
+
let r = object(value, "Record reference");
|
|
459
|
+
return keys(r, ["repository", "ref"], "Record reference"), (!validDataRepositoryName(r.repository) || !validRecordRef(r.ref)) && fail("Invalid qualified Record reference"), { repository: r.repository, ref: r.ref };
|
|
458
460
|
}
|
|
459
461
|
function validateBlock(value) {
|
|
460
462
|
let b = object(serializable(value), "Block");
|
|
@@ -465,32 +467,14 @@ function validateBlock(value) {
|
|
|
465
467
|
let asks = distinctIds(b.asks, "Ask IDs");
|
|
466
468
|
return asks.some((ask) => !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(ask)) && fail("Invalid Ask ID"), { kind: "asks", problem: text(b.problem, "problem"), asks };
|
|
467
469
|
}
|
|
468
|
-
["record", "records", "files"].includes(b.kind) || fail("Unknown Block kind"), keys(b, ["kind", "label", "initiallyExpanded", ...b.kind === "record" ? ["record"
|
|
470
|
+
["record", "records", "files"].includes(b.kind) || fail("Unknown Block kind"), keys(b, ["kind", "label", "initiallyExpanded", ...b.kind === "record" ? ["record"] : b.kind === "records" ? ["records"] : ["files"]], "Block");
|
|
469
471
|
let label = text(b.label, "Block label");
|
|
470
472
|
b.initiallyExpanded !== void 0 && typeof b.initiallyExpanded != "boolean" && fail("Invalid initiallyExpanded");
|
|
471
|
-
let expanded = b.initiallyExpanded === void 0 ? {} : { initiallyExpanded: b.initiallyExpanded }
|
|
472
|
-
if (b.kind === "record") {
|
|
473
|
-
let r = object(b.record, "presented record");
|
|
474
|
-
return keys(r, ["ref", "title", "fields"], "presented record"), {
|
|
475
|
-
kind: "record",
|
|
476
|
-
label,
|
|
477
|
-
...target,
|
|
478
|
-
...expanded,
|
|
479
|
-
record: { ref: id(r.ref, "record reference"), title: text(r.title, "record title"), fields: fields2(r.fields) }
|
|
480
|
-
};
|
|
481
|
-
}
|
|
473
|
+
let expanded = b.initiallyExpanded === void 0 ? {} : { initiallyExpanded: b.initiallyExpanded };
|
|
474
|
+
if (b.kind === "record") return { kind: "record", label, record: validateQualifiedRecordRef(b.record), ...expanded };
|
|
482
475
|
if (b.kind === "records") {
|
|
483
|
-
let records = array(b.records, "records").map(
|
|
484
|
-
|
|
485
|
-
return keys(r, ["ref", "title", "description", "facts", "view"], "record summary"), {
|
|
486
|
-
ref: id(r.ref, "record reference"),
|
|
487
|
-
title: text(r.title, "record title"),
|
|
488
|
-
...r.description === void 0 ? {} : { description: text(r.description, "record description") },
|
|
489
|
-
...r.facts === void 0 ? {} : { facts: fields2(r.facts) },
|
|
490
|
-
...r.view === void 0 ? {} : { view: id(r.view, "row View target") }
|
|
491
|
-
};
|
|
492
|
-
});
|
|
493
|
-
return (!records.length || new Set(records.map((r) => r.ref)).size !== records.length) && fail("Empty or duplicate records"), { kind: "records", label, records, ...target, ...expanded };
|
|
476
|
+
let records = array(b.records, "records").map(validateQualifiedRecordRef);
|
|
477
|
+
return (!records.length || new Set(records.map((r) => JSON.stringify([r.repository, r.ref]))).size !== records.length) && fail("Empty or duplicate records"), { kind: "records", label, records, ...expanded };
|
|
494
478
|
}
|
|
495
479
|
let files3 = array(b.files, "files").map(validateInboxFile);
|
|
496
480
|
return (!files3.length || new Set(files3.map((file2) => file2.id)).size !== files3.length) && fail("Empty or duplicate files"), { kind: "files", label, files: files3, ...expanded };
|
|
@@ -621,26 +605,9 @@ function defineHandler(value) {
|
|
|
621
605
|
function respond(handler, input) {
|
|
622
606
|
return defineHandler(handler), handlerReference({ id: handler.id, input });
|
|
623
607
|
}
|
|
624
|
-
function recordRequirements(value) {
|
|
625
|
-
let source2 = object(value, "Record requirements");
|
|
626
|
-
keys(source2, ["repository", "records"], "Record requirements"), validDataRepositoryName(source2.repository) || fail("Invalid requirements repository");
|
|
627
|
-
let repository = source2.repository, records = array(source2.records, "required Records").map((entry) => {
|
|
628
|
-
let row = object(entry, "required Record");
|
|
629
|
-
keys(row, ["ref", "version"], "required Record");
|
|
630
|
-
let { ref } = validateRecordReference({ repository, ref: row.ref });
|
|
631
|
-
return (typeof row.version != "string" || !row.version.length || row.version.length > 512) && fail("Invalid required Record version"), { ref, version: row.version };
|
|
632
|
-
});
|
|
633
|
-
return new Set(records.map((record4) => record4.ref)).size !== records.length && fail("Duplicate required Record"), { repository, records };
|
|
634
|
-
}
|
|
635
|
-
function requireRecords(repository, records) {
|
|
636
|
-
return recordRequirements({ repository, records: array(records, "required Records").map((entry) => {
|
|
637
|
-
let record4 = object(entry, "Data Record");
|
|
638
|
-
return { ref: record4.$ref, version: record4.$version };
|
|
639
|
-
}) });
|
|
640
|
-
}
|
|
641
608
|
function question(value) {
|
|
642
609
|
let source2 = object(value, "question");
|
|
643
|
-
keys(source2, ["id", "to", "allowedResponders", "prompt", "instructions", "response", "handler"
|
|
610
|
+
keys(source2, ["id", "to", "allowedResponders", "prompt", "instructions", "response", "handler"], "question");
|
|
644
611
|
let to = personReference(source2.to, "question assignee"), allowedResponders = source2.allowedResponders === void 0 ? [to] : distinctPeople(source2.allowedResponders, "allowed responders");
|
|
645
612
|
return allowedResponders.includes(to) || fail("Allowed responders must include the assignee"), {
|
|
646
613
|
id: id(source2.id, "question ID"),
|
|
@@ -649,8 +616,7 @@ function question(value) {
|
|
|
649
616
|
prompt: text(source2.prompt, "question prompt"),
|
|
650
617
|
...source2.instructions === void 0 ? {} : { instructions: text(source2.instructions, "instructions") },
|
|
651
618
|
response: validateResponseDefinition(source2.response),
|
|
652
|
-
...Object.hasOwn(source2, "handler") ? { handler: handlerReference(source2.handler) } : {}
|
|
653
|
-
...Object.hasOwn(source2, "requirements") ? { requirements: recordRequirements(source2.requirements) } : {}
|
|
619
|
+
...Object.hasOwn(source2, "handler") ? { handler: handlerReference(source2.handler) } : {}
|
|
654
620
|
};
|
|
655
621
|
}
|
|
656
622
|
function presentation(source2) {
|
|
@@ -660,10 +626,6 @@ function presentation(source2) {
|
|
|
660
626
|
});
|
|
661
627
|
new Set(views.map((view) => view.id)).size !== views.length && fail("Duplicate view ID");
|
|
662
628
|
let body = source2.body === void 0 ? [] : array(source2.body, "body").map(validateBlock);
|
|
663
|
-
for (let block2 of body) {
|
|
664
|
-
let targets = block2.kind === "record" ? [block2.view] : block2.kind === "records" ? [block2.view, ...block2.records.map((record4) => record4.view)] : [];
|
|
665
|
-
for (let target of targets) target !== void 0 && !views.some((view) => view.id === target) && fail(`Unknown Block View target: ${target}`);
|
|
666
|
-
}
|
|
667
629
|
return { title: text(source2.title, "title"), description: text(source2.description, "description"), views, body };
|
|
668
630
|
}
|
|
669
631
|
function validatePublication(value) {
|
|
@@ -678,13 +640,13 @@ function validatePublication(value) {
|
|
|
678
640
|
"notifyImmediately",
|
|
679
641
|
...source2.kind === "ask" ? ["questions", "tags", "recordRefs"] : []
|
|
680
642
|
], "publication"), source2.notifyImmediately !== void 0 && typeof source2.notifyImmediately != "boolean" && fail("notifyImmediately must be a boolean");
|
|
681
|
-
let itemPresentation = { ...presentation(source2), ...source2.notifyImmediately === void 0 ? {} : { notifyImmediately: source2.notifyImmediately } }, linkedAsks = (itemPresentation.body ?? []).flatMap((
|
|
643
|
+
let itemPresentation = { ...presentation(source2), ...source2.notifyImmediately === void 0 ? {} : { notifyImmediately: source2.notifyImmediately } }, linkedAsks = (itemPresentation.body ?? []).flatMap((block) => block.kind === "asks" ? block.asks : []);
|
|
682
644
|
if (new Set(linkedAsks).size !== linkedAsks.length && fail("Ask belongs to more than one problem"), source2.kind === "digest") return {
|
|
683
645
|
kind: "digest",
|
|
684
646
|
...itemPresentation,
|
|
685
647
|
recipients: distinctPeople(source2.recipients, "digest recipients")
|
|
686
648
|
};
|
|
687
|
-
itemPresentation.body?.some((
|
|
649
|
+
itemPresentation.body?.some((block) => block.kind === "asks") && fail("Asks Blocks belong to Digests");
|
|
688
650
|
let questions = array(source2.questions === void 0 ? [] : source2.questions, "questions").map((value2) => question(value2));
|
|
689
651
|
new Set(questions.map((entry) => entry.id)).size !== questions.length && fail("Duplicate question ID");
|
|
690
652
|
let extra = source2.recipients === void 0 ? [] : distinctPeople(source2.recipients, "recipients", !1);
|
|
@@ -765,7 +727,7 @@ function createInboxPublisher(transport) {
|
|
|
765
727
|
var ROUTINE_DECLARATION_SCHEMA = "https://schemas.oddington.ai/routine/v1.json", ROUTINE_SOURCE_LIMITS = { files: 2e4, bytes: 256 * 1024 * 1024, declarationBytes: 64 * 1024 };
|
|
766
728
|
var invalid = (field) => {
|
|
767
729
|
throw new Error(`Invalid routine declaration: ${field}`);
|
|
768
|
-
}, object2 = (value,
|
|
730
|
+
}, object2 = (value, fields3, field) => ((!value || typeof value != "object" || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null || Reflect.ownKeys(value).some((key) => typeof key != "string" || !fields3.includes(key) || !Object.getOwnPropertyDescriptor(value, key).enumerable || !Object.hasOwn(Object.getOwnPropertyDescriptor(value, key), "value"))) && invalid(field), value), routineAlias = (value) => typeof value == "string" && /^[a-z][a-z0-9-]{0,62}$/.test(value), list = (value, field, allowed, qualified = !1) => value === void 0 ? [] : ((!Array.isArray(value) || value.length > 64 || value.some((item) => !(routineAlias(item) || qualified && typeof item == "string" && item.split("/").length === 2 && item.split("/").every(routineAlias)) || allowed && !allowed.includes(item)) || new Set(value).size !== value.length) && invalid(field), [...value].sort());
|
|
769
731
|
function routineAssetPattern(value) {
|
|
770
732
|
return typeof value == "string" && value.length <= 512 && !value.startsWith("/") && !value.includes("\\") && !value.includes(":") && value.split("/").every((part) => !!part && part !== "." && part !== ".." && /^[a-zA-Z0-9_.*-]+$/.test(part));
|
|
771
733
|
}
|
|
@@ -1321,11 +1283,6 @@ async function executeRoutineDefinition(definition, input, runtime) {
|
|
|
1321
1283
|
if (result2 !== void 0) return invalid3();
|
|
1322
1284
|
}
|
|
1323
1285
|
|
|
1324
|
-
var RECORD_READ_INPUT_LIMIT = 1024 * 1024, RECORD_CAPTURE_OUTPUT_LIMIT = 25 * 1024 * 1024;
|
|
1325
|
-
function validRecordRef(value) {
|
|
1326
|
-
return typeof value == "string" && value.length <= 512 && /^[_a-zA-Z0-9][a-zA-Z0-9_-]*(\/[_a-zA-Z0-9][a-zA-Z0-9_-]*)+$/.test(value);
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
1286
|
var fieldProblems = ["unknown", "missing", "invalid", "source_schema"], reasons = {
|
|
1330
1287
|
unknown: "unknown_field",
|
|
1331
1288
|
missing: "missing_field",
|
|
@@ -1431,6 +1388,9 @@ function explainDataValidation(error, message2, detail) {
|
|
|
1431
1388
|
return Object.assign(error, dataValidationMessageFacts({ code: error.code, message: typeof message2 == "string" ? message2 : "", detail })), error;
|
|
1432
1389
|
}
|
|
1433
1390
|
|
|
1391
|
+
function dataPublicationFailureMessage(detail) {
|
|
1392
|
+
return detail.preflight === "dirty_repository" ? `Data repository ${detail.repository} has existing changes. No Record files were changed. Use os data push ${detail.repository} or stash those Data changes with Git, then run the routine again.` : (detail.state === "commit" ? `Data commit ${detail.commit} remains in your checkout; its push is unconfirmed.` : detail.state === "files" ? "Your Record files were applied, but Git could not create their commit." : "Data publication needs Git preparation. No Record files were changed.") + ` Review git status and your branch and destination, then use os data push ${detail.repository}. Do not rerun the routine to recover this publication.`;
|
|
1393
|
+
}
|
|
1434
1394
|
var localDataPath = (value, repository) => typeof value == "string" && value.length <= 1024 && value.startsWith(`${repository}/`) && !value.includes("\\") && !/[\x00-\x1f\x7f]/.test(value) && value.split("/").every((part) => !!part && part !== "." && part !== ".."), localDataFile = (value, repository) => {
|
|
1435
1395
|
if (!value || typeof value != "object" || Array.isArray(value)) return !1;
|
|
1436
1396
|
let row = value;
|
|
@@ -1461,6 +1421,12 @@ function parseDataOperationDetail(value) {
|
|
|
1461
1421
|
throw new Error("Invalid Data operation detail");
|
|
1462
1422
|
return structuredClone(value);
|
|
1463
1423
|
}
|
|
1424
|
+
if (value && typeof value == "object" && !Array.isArray(value) && value.code === "local_data_publication_failed") {
|
|
1425
|
+
let row = value;
|
|
1426
|
+
if (Object.keys(row).sort().join(",") !== (row.state === "commit" ? "code,commit,repository,state" : Object.hasOwn(row, "preflight") ? "code,preflight,repository,state" : "code,repository,state") || Object.hasOwn(row, "preflight") && (row.state !== "unapplied" || row.preflight !== "dirty_repository") || typeof row.repository != "string" || !/^[a-z0-9][a-z0-9._-]{0,127}$/.test(row.repository) || row.repository.includes("..") || !["unapplied", "files", "commit"].includes(String(row.state)) || row.state === "commit" && (typeof row.commit != "string" || !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(row.commit)))
|
|
1427
|
+
throw new Error("Invalid Data publication detail");
|
|
1428
|
+
return structuredClone(value);
|
|
1429
|
+
}
|
|
1464
1430
|
return parseDataFailureDetail(value);
|
|
1465
1431
|
}
|
|
1466
1432
|
function dataRecordLimitMessage(detail) {
|
|
@@ -1472,7 +1438,7 @@ var DataOperationError = class extends Error {
|
|
|
1472
1438
|
let parsed = detail === void 0 ? void 0 : parseDataOperationDetail(detail);
|
|
1473
1439
|
if (parsed && ("reason" in parsed ? code !== "invalid_change" : parsed.code === "record_limit_exceeded" && code !== "capacity"))
|
|
1474
1440
|
throw new Error("Invalid Data operation detail");
|
|
1475
|
-
super(code === "capacity" && parsed && "code" in parsed && parsed.code === "record_limit_exceeded" ? dataRecordLimitMessage(parsed) : `Data operation failed: ${code}`);
|
|
1441
|
+
super(parsed && "code" in parsed && parsed.code === "local_data_publication_failed" ? dataPublicationFailureMessage(parsed) : code === "capacity" && parsed && "code" in parsed && parsed.code === "record_limit_exceeded" ? dataRecordLimitMessage(parsed) : `Data operation failed: ${code}`);
|
|
1476
1442
|
this.code = code;
|
|
1477
1443
|
this.retryable = retryable;
|
|
1478
1444
|
this.effect = effect;
|
|
@@ -1489,67 +1455,34 @@ var DataOperationError = class extends Error {
|
|
|
1489
1455
|
|
|
1490
1456
|
var invalid4 = () => {
|
|
1491
1457
|
throw new DataOperationError("invalid_query");
|
|
1492
|
-
},
|
|
1493
|
-
function
|
|
1494
|
-
return historyText(value) && value.length > 0 && new TextEncoder().encode(value).length <= 1024 && !/[\u0000-\u001f\u007f-\u009f]/.test(value) && !/^[0-9a-f]{40}$/i.test(value);
|
|
1495
|
-
}
|
|
1496
|
-
function historyProperties(value) {
|
|
1458
|
+
}, dataText = (value) => typeof value == "string" && !/[\u0000\uD800-\uDFFF]/u.test(value);
|
|
1459
|
+
function dataProperties(value) {
|
|
1497
1460
|
if (!value || typeof value != "object" || Array.isArray(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return invalid4();
|
|
1498
1461
|
let descriptors = Object.getOwnPropertyDescriptors(value);
|
|
1499
1462
|
return Reflect.ownKeys(value).some((key) => typeof key != "string" || !descriptors[key]?.enumerable || !Object.hasOwn(descriptors[key], "value")) ? invalid4() : descriptors;
|
|
1500
1463
|
}
|
|
1501
|
-
|
|
1502
|
-
function historyArray(value) {
|
|
1464
|
+
function dataArray(value) {
|
|
1503
1465
|
if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype) return invalid4();
|
|
1504
1466
|
let descriptors = Object.getOwnPropertyDescriptors(value);
|
|
1505
1467
|
if (Reflect.ownKeys(value).length !== value.length + 1) return invalid4();
|
|
1506
1468
|
let result2 = [];
|
|
1507
|
-
for (let
|
|
1508
|
-
let descriptor = descriptors[
|
|
1469
|
+
for (let index = 0; index < value.length; index++) {
|
|
1470
|
+
let descriptor = descriptors[index];
|
|
1509
1471
|
if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value")) return invalid4();
|
|
1510
1472
|
result2.push(descriptor.value);
|
|
1511
1473
|
}
|
|
1512
1474
|
return result2;
|
|
1513
1475
|
}
|
|
1514
|
-
function captureOptions(value, changes) {
|
|
1515
|
-
if (value === void 0) return {};
|
|
1516
|
-
let descriptors = historyProperties(value), result2 = {}, allowed = changes ? ["collections", "refs", "from", "through", "limit", "after"] : ["limit", "before"];
|
|
1517
|
-
if (Object.keys(descriptors).some((key) => !allowed.includes(key))) return invalid4();
|
|
1518
|
-
for (let key of allowed) {
|
|
1519
|
-
if (!Object.hasOwn(descriptors, key)) continue;
|
|
1520
|
-
let scalar = descriptors[key].value;
|
|
1521
|
-
if (key === "collections" || key === "refs") {
|
|
1522
|
-
let values = historyArray(scalar);
|
|
1523
|
-
if (!values.length || values.length > (key === "collections" ? 16 : 100) || !values.every(key === "collections" ? historyCollection : validRecordRef) || new Set(values).size !== values.length) return invalid4();
|
|
1524
|
-
result2[key] = values;
|
|
1525
|
-
} else if (key === "limit") {
|
|
1526
|
-
if (!Number.isInteger(scalar) || scalar < 1 || scalar > (changes ? 500 : 100)) return invalid4();
|
|
1527
|
-
result2.limit = scalar;
|
|
1528
|
-
} else {
|
|
1529
|
-
if (!(key === "after" ? historyCursor(scalar) : historyVersion(scalar))) return invalid4();
|
|
1530
|
-
result2[key] = scalar;
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
return result2;
|
|
1534
|
-
}
|
|
1535
|
-
var captureHistoryListOptions = (value) => captureOptions(value, !1), captureHistoryChangesOptions = (value) => captureOptions(value, !0);
|
|
1536
|
-
function captureHistoryInstant(value) {
|
|
1537
|
-
if (!historyText(value) || value.length > 1024) return invalid4();
|
|
1538
|
-
let match = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?([Zz]|([+-])(\d{2}):(\d{2}))$/.exec(value);
|
|
1539
|
-
if (!match) return invalid4();
|
|
1540
|
-
let [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number), days = new Date(Date.UTC(year, month, 0));
|
|
1541
|
-
return days.setUTCFullYear(year), year < 1 || month < 1 || month > 12 || day < 1 || day > days.getUTCDate() || hour > 23 || minute > 59 || second > 59 || Number(match[9] ?? 0) > 23 || Number(match[10] ?? 0) > 59 ? invalid4() : value;
|
|
1542
|
-
}
|
|
1543
1476
|
|
|
1544
1477
|
var invalid5 = () => {
|
|
1545
1478
|
throw new DataOperationError("invalid_query");
|
|
1546
1479
|
};
|
|
1547
1480
|
function captureRecordsSearchInput(query, options) {
|
|
1548
|
-
if (!
|
|
1481
|
+
if (!dataText(query)) return invalid5();
|
|
1549
1482
|
let length = [...query.trim()].length;
|
|
1550
1483
|
if (length < 1 || length > 256) return invalid5();
|
|
1551
1484
|
if (options === void 0) return { query };
|
|
1552
|
-
let descriptors =
|
|
1485
|
+
let descriptors = dataProperties(options);
|
|
1553
1486
|
if (Object.keys(descriptors).some((key) => !["collections", "limit"].includes(key))) return invalid5();
|
|
1554
1487
|
let captured = {};
|
|
1555
1488
|
if (Object.hasOwn(descriptors, "collections")) {
|
|
@@ -1558,7 +1491,7 @@ function captureRecordsSearchInput(query, options) {
|
|
|
1558
1491
|
let collections = [];
|
|
1559
1492
|
for (let index = 0; index < supplied.length; index++) {
|
|
1560
1493
|
let descriptor = Object.getOwnPropertyDescriptor(supplied, String(index));
|
|
1561
|
-
if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value") || !
|
|
1494
|
+
if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value") || !dataText(descriptor.value)) return invalid5();
|
|
1562
1495
|
collections.push(descriptor.value);
|
|
1563
1496
|
}
|
|
1564
1497
|
if (new Set(collections).size !== collections.length) return invalid5();
|
|
@@ -1575,7 +1508,7 @@ function captureRecordsSearchInput(query, options) {
|
|
|
1575
1508
|
function captureRecordsReadRefs(value) {
|
|
1576
1509
|
if (!Array.isArray(value) || value.length < 1 || value.length > 100)
|
|
1577
1510
|
throw new DataOperationError("invalid_query");
|
|
1578
|
-
let refs =
|
|
1511
|
+
let refs = dataArray(value);
|
|
1579
1512
|
if (!refs.every((ref) => validRecordRef(ref) && !/[\r\n]/.test(ref)) || new Set(refs).size !== refs.length)
|
|
1580
1513
|
throw new DataOperationError("invalid_query");
|
|
1581
1514
|
return refs;
|
|
@@ -1583,7 +1516,7 @@ function captureRecordsReadRefs(value) {
|
|
|
1583
1516
|
function captureRecordsReadOptions(value) {
|
|
1584
1517
|
if (value === void 0) return {};
|
|
1585
1518
|
try {
|
|
1586
|
-
|
|
1519
|
+
dataProperties(value);
|
|
1587
1520
|
} catch {
|
|
1588
1521
|
throw new DataOperationError("invalid_query");
|
|
1589
1522
|
}
|
|
@@ -1597,7 +1530,7 @@ function capture3(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
|
1597
1530
|
if (!value || typeof value != "object" || ancestors.has(value) || depth > 32) throw new DataOperationError("invalid_query");
|
|
1598
1531
|
ancestors.add(value);
|
|
1599
1532
|
try {
|
|
1600
|
-
return Array.isArray(value) ?
|
|
1533
|
+
return Array.isArray(value) ? dataArray(value).map((item) => capture3(item, ancestors, depth + 1)) : Object.fromEntries(Object.entries(dataProperties(value)).map(([key, descriptor]) => [key, capture3(descriptor.value, ancestors, depth + 1)]));
|
|
1601
1534
|
} finally {
|
|
1602
1535
|
ancestors.delete(value);
|
|
1603
1536
|
}
|
|
@@ -1607,13 +1540,13 @@ function captureRecordsAll(query, options) {
|
|
|
1607
1540
|
throw new DataOperationError("invalid_query");
|
|
1608
1541
|
};
|
|
1609
1542
|
try {
|
|
1610
|
-
let properties =
|
|
1543
|
+
let properties = dataProperties(options), maxRecords = properties.maxRecords?.value;
|
|
1611
1544
|
if (Object.keys(properties).join(",") !== "maxRecords" || !Number.isSafeInteger(maxRecords) || maxRecords < 1) return invalid9();
|
|
1612
|
-
let detached = capture3(query), selections =
|
|
1545
|
+
let detached = capture3(query), selections = dataProperties(detached);
|
|
1613
1546
|
if (Object.keys(selections).length < 1 || Object.keys(selections).length > 16) return invalid9();
|
|
1614
1547
|
for (let selection2 of Object.values(selections)) {
|
|
1615
|
-
let
|
|
1616
|
-
if (
|
|
1548
|
+
let fields3 = dataProperties(selection2.value);
|
|
1549
|
+
if (fields3.$ && Object.hasOwn(dataProperties(fields3.$.value), "after")) return invalid9();
|
|
1617
1550
|
}
|
|
1618
1551
|
return { query: detached, maxRecords };
|
|
1619
1552
|
} catch {
|
|
@@ -1631,7 +1564,7 @@ var DATA_REQUEST_LIMIT = 256 * 1024, LOCAL_DATA_CHANGE_REQUEST_LIMIT = 32 * 1024
|
|
|
1631
1564
|
};
|
|
1632
1565
|
function mapping(value) {
|
|
1633
1566
|
try {
|
|
1634
|
-
return
|
|
1567
|
+
return dataProperties(value), value;
|
|
1635
1568
|
} catch {
|
|
1636
1569
|
return invalidChange();
|
|
1637
1570
|
}
|
|
@@ -1651,8 +1584,8 @@ function captureDataDelete(record4) {
|
|
|
1651
1584
|
return !validRecordRef(identity.$ref) || typeof identity.$version != "string" || !identity.$version.length || identity.$version.length > 512 ? invalidChange() : { ref: identity.$ref, expectedVersion: identity.$version };
|
|
1652
1585
|
}
|
|
1653
1586
|
function captureDataUpdate(record4, set) {
|
|
1654
|
-
let identity = captureDataDelete(record4), input = mapping(set), { $body, ...
|
|
1655
|
-
return body && !validRecordBody($body) || !Object.keys(
|
|
1587
|
+
let identity = captureDataDelete(record4), input = mapping(set), { $body, ...fields3 } = input, body = Object.hasOwn(input, "$body");
|
|
1588
|
+
return body && !validRecordBody($body) || !Object.keys(fields3).length && !body || Object.keys(fields3).some((key) => key.startsWith("$") || ["id", "type"].includes(key)) ? invalidChange() : { ...identity, set: captureValue(fields3), ...body ? { body: $body } : {} };
|
|
1656
1589
|
}
|
|
1657
1590
|
function captureIdentities(value, update, allowEmpty = !0) {
|
|
1658
1591
|
if (!Array.isArray(value) || !allowEmpty && !value.length || value.length > 1e4) return invalidChange();
|
|
@@ -1671,7 +1604,7 @@ function captureDataCreate(value) {
|
|
|
1671
1604
|
let row = mapping(value);
|
|
1672
1605
|
if (!validRecordRef(row.$ref) || Object.keys(row).some((key) => key.startsWith("$") && !["$ref", "$filing", "$body"].includes(key)))
|
|
1673
1606
|
return invalidChange();
|
|
1674
|
-
let { $ref: ref, $filing, $body, ...
|
|
1607
|
+
let { $ref: ref, $filing, $body, ...fields3 } = row, body = Object.hasOwn(row, "$body");
|
|
1675
1608
|
if (body && !validRecordBody($body)) return invalidChange();
|
|
1676
1609
|
let filing;
|
|
1677
1610
|
if ($filing !== void 0) {
|
|
@@ -1680,7 +1613,7 @@ function captureDataCreate(value) {
|
|
|
1680
1613
|
return invalidChange();
|
|
1681
1614
|
filing = { ...components };
|
|
1682
1615
|
}
|
|
1683
|
-
return { ref, fields: captureValue(
|
|
1616
|
+
return { ref, fields: captureValue(fields3), ...filing ? { filing } : {}, ...body ? { body: $body } : {} };
|
|
1684
1617
|
}
|
|
1685
1618
|
function captureDataChanges(updatesValue, createsValue = [], deletesValue = []) {
|
|
1686
1619
|
let updates = captureDataUpdates(updatesValue, !0);
|
|
@@ -1688,9 +1621,9 @@ function captureDataChanges(updatesValue, createsValue = [], deletesValue = [])
|
|
|
1688
1621
|
let creates = createsValue.map((item) => {
|
|
1689
1622
|
let row = mapping(item);
|
|
1690
1623
|
if (Object.keys(row).some((key) => !["ref", "fields", "filing", "body"].includes(key)) || !Object.hasOwn(row, "ref") || !Object.hasOwn(row, "fields")) return invalidChange();
|
|
1691
|
-
let
|
|
1692
|
-
return Object.keys(
|
|
1693
|
-
...
|
|
1624
|
+
let fields3 = mapping(row.fields);
|
|
1625
|
+
return Object.keys(fields3).some((key) => key.startsWith("$")) ? invalidChange() : captureDataCreate({
|
|
1626
|
+
...fields3,
|
|
1694
1627
|
$ref: row.ref,
|
|
1695
1628
|
...Object.hasOwn(row, "filing") ? { $filing: row.filing } : {},
|
|
1696
1629
|
...Object.hasOwn(row, "body") ? { $body: row.body } : {}
|
|
@@ -1810,18 +1743,18 @@ function capture4(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
|
1810
1743
|
if (!value || typeof value != "object" || ancestors.has(value) || depth > 32) return invalid6();
|
|
1811
1744
|
ancestors.add(value);
|
|
1812
1745
|
try {
|
|
1813
|
-
return Array.isArray(value) ?
|
|
1746
|
+
return Array.isArray(value) ? dataArray(value).map((item) => capture4(item, ancestors, depth + 1)) : Object.fromEntries(Object.entries(dataProperties(value)).map(([key, descriptor]) => [key, capture4(descriptor.value, ancestors, depth + 1)]));
|
|
1814
1747
|
} finally {
|
|
1815
1748
|
ancestors.delete(value);
|
|
1816
1749
|
}
|
|
1817
1750
|
}
|
|
1818
1751
|
function recordPagination(queryRecords) {
|
|
1819
1752
|
function pages(query) {
|
|
1820
|
-
let captured = capture4(query), names = Object.keys(
|
|
1753
|
+
let captured = capture4(query), names = Object.keys(dataProperties(captured));
|
|
1821
1754
|
for (let name2 of names) {
|
|
1822
|
-
let selection2 =
|
|
1755
|
+
let selection2 = dataProperties(captured[name2]);
|
|
1823
1756
|
if (Object.hasOwn(selection2, "$")) {
|
|
1824
|
-
let options =
|
|
1757
|
+
let options = dataProperties(selection2.$.value);
|
|
1825
1758
|
if (Object.hasOwn(options, "after")) return invalid6();
|
|
1826
1759
|
}
|
|
1827
1760
|
}
|
|
@@ -1839,15 +1772,15 @@ function recordPagination(queryRecords) {
|
|
|
1839
1772
|
})), response2 = await queryRecords(request2), page;
|
|
1840
1773
|
try {
|
|
1841
1774
|
page = capture4(response2);
|
|
1842
|
-
let keys4 = Object.keys(
|
|
1775
|
+
let keys4 = Object.keys(dataProperties(page));
|
|
1843
1776
|
(keys4.length !== active2.length + 1 || keys4.some((key) => key !== "$meta" && !active2.includes(key))) && unavailable();
|
|
1844
1777
|
let meta = page.$meta;
|
|
1845
|
-
(Object.keys(
|
|
1778
|
+
(Object.keys(dataProperties(meta)).sort().join(",") !== "collections,version" || !text2(meta.version)) && unavailable(), version = meta.version, Object.keys(dataProperties(meta.collections)).some((key) => !active2.includes(key)) && unavailable();
|
|
1846
1779
|
for (let name2 of active2) {
|
|
1847
|
-
let records =
|
|
1848
|
-
(Object.keys(
|
|
1780
|
+
let records = dataArray(page[name2]), metadata = Object.hasOwn(meta.collections, name2) ? meta.collections[name2] : {};
|
|
1781
|
+
(Object.keys(dataProperties(metadata)).some((key) => key !== "count" && key !== "next") || Object.hasOwn(metadata, "next") && !text2(metadata.next)) && unavailable();
|
|
1849
1782
|
for (let record4 of records) {
|
|
1850
|
-
|
|
1783
|
+
dataProperties(record4);
|
|
1851
1784
|
let row = record4;
|
|
1852
1785
|
(!validRecordRef(row.$ref) || !text2(row.$version)) && unavailable();
|
|
1853
1786
|
}
|
|
@@ -1874,7 +1807,7 @@ function recordPagination(queryRecords) {
|
|
|
1874
1807
|
var genericData = {
|
|
1875
1808
|
repository(repository) {
|
|
1876
1809
|
async function send3(input) {
|
|
1877
|
-
let context = await resolveDataContext(), envelope = { repository, ...input }, changing = "operation" in input && ["changes.validate", "changes.apply"].includes(String(input.operation));
|
|
1810
|
+
let context = await resolveDataContext(), envelope = { repository, ...input }, changing = "operation" in input && ["changes.validate", "changes.apply", "changes.publish"].includes(String(input.operation));
|
|
1878
1811
|
if (checkDataRequestSize(envelope, "local" in context && changing ? LOCAL_DATA_CHANGE_REQUEST_LIMIT : DATA_REQUEST_LIMIT), "local" in context) return await context.local("data/query", envelope);
|
|
1879
1812
|
try {
|
|
1880
1813
|
let response2 = await fetch(context.url, {
|
|
@@ -1908,13 +1841,8 @@ var genericData = {
|
|
|
1908
1841
|
all: async (query, options) => send3({ operation: "records.all", ...captureRecordsAll(query, options) }),
|
|
1909
1842
|
search: async (query, options) => send3({ operation: "records.search", ...captureRecordsSearchInput(query, options) })
|
|
1910
1843
|
},
|
|
1911
|
-
history: {
|
|
1912
|
-
list: async (options) => send3({ operation: "history.list", options: captureHistoryListOptions(options) }),
|
|
1913
|
-
at: async (instant) => send3({ operation: "history.at", instant: captureHistoryInstant(instant) }),
|
|
1914
|
-
changes: async (options) => send3({ operation: "history.changes", options: captureHistoryChangesOptions(options) })
|
|
1915
|
-
},
|
|
1916
1844
|
changes() {
|
|
1917
|
-
let updates = [], creates = [], deletes = [], applyId, pending, confirmed, assertMutable = () => {
|
|
1845
|
+
let updates = [], creates = [], deletes = [], applyId, method, pending, confirmed, assertMutable = () => {
|
|
1918
1846
|
if (applyId) throw new DataOperationError("invalid_change", !1, "unapplied");
|
|
1919
1847
|
}, snapshot = (nextUpdates = updates, nextCreates = creates, nextDeletes = deletes) => {
|
|
1920
1848
|
let { updates: updates2, creates: creates2, deletes: deletes2 } = captureDataChanges(nextUpdates, nextCreates, nextDeletes), input = { updates: updates2, ...creates2.length ? { creates: creates2 } : {}, ...deletes2.length ? { deletes: deletes2 } : {} };
|
|
@@ -1924,6 +1852,29 @@ var genericData = {
|
|
|
1924
1852
|
...input,
|
|
1925
1853
|
applyId: applyId ?? "00000000-0000-4000-8000-000000000000"
|
|
1926
1854
|
}, LOCAL_DATA_CHANGE_REQUEST_LIMIT), input;
|
|
1855
|
+
}, write = (operation2) => {
|
|
1856
|
+
if (method && method !== operation2) return Promise.reject(new DataOperationError("invalid_change", !1, "unapplied"));
|
|
1857
|
+
if (confirmed) return Promise.resolve(structuredClone(confirmed));
|
|
1858
|
+
if (!pending) {
|
|
1859
|
+
let captured;
|
|
1860
|
+
try {
|
|
1861
|
+
captured = snapshot();
|
|
1862
|
+
} catch (error) {
|
|
1863
|
+
return Promise.reject(error);
|
|
1864
|
+
}
|
|
1865
|
+
method = operation2, applyId ??= routineTransport()?.key("data") ?? crypto.randomUUID(), pending = send3({ operation: operation2, ...captured, applyId }).then((result2) => (confirmed = structuredClone(result2), result2)).catch((error) => {
|
|
1866
|
+
throw error instanceof DataOperationError ? explainDataValidation(new DataOperationError(
|
|
1867
|
+
error.code,
|
|
1868
|
+
error.retryable,
|
|
1869
|
+
error.effect ?? (["unavailable", "apply_pending"].includes(error.code) ? "uncertain" : "unapplied"),
|
|
1870
|
+
error.component,
|
|
1871
|
+
error.detail
|
|
1872
|
+
), error.message, error.detail) : new DataOperationError("unavailable", !0, "uncertain");
|
|
1873
|
+
}).finally(() => {
|
|
1874
|
+
pending = void 0;
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
return pending.then((result2) => structuredClone(result2));
|
|
1927
1878
|
};
|
|
1928
1879
|
return {
|
|
1929
1880
|
create(record4) {
|
|
@@ -1944,29 +1895,8 @@ var genericData = {
|
|
|
1944
1895
|
async validate() {
|
|
1945
1896
|
await send3({ operation: "changes.validate", ...snapshot() });
|
|
1946
1897
|
},
|
|
1947
|
-
apply()
|
|
1948
|
-
|
|
1949
|
-
if (!pending) {
|
|
1950
|
-
let captured;
|
|
1951
|
-
try {
|
|
1952
|
-
captured = snapshot();
|
|
1953
|
-
} catch (error) {
|
|
1954
|
-
return Promise.reject(error);
|
|
1955
|
-
}
|
|
1956
|
-
applyId ??= routineTransport()?.key("data") ?? crypto.randomUUID(), pending = send3({ operation: "changes.apply", ...captured, applyId }).then((result2) => (confirmed = structuredClone(result2), result2)).catch((error) => {
|
|
1957
|
-
throw error instanceof DataOperationError ? explainDataValidation(new DataOperationError(
|
|
1958
|
-
error.code,
|
|
1959
|
-
error.retryable,
|
|
1960
|
-
error.effect ?? (["unavailable", "apply_pending"].includes(error.code) ? "uncertain" : "unapplied"),
|
|
1961
|
-
error.component,
|
|
1962
|
-
error.detail
|
|
1963
|
-
), error.message, error.detail) : new DataOperationError("unavailable", !0, "uncertain");
|
|
1964
|
-
}).finally(() => {
|
|
1965
|
-
pending = void 0;
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
return pending.then((result2) => structuredClone(result2));
|
|
1969
|
-
}
|
|
1898
|
+
apply: () => write("changes.apply"),
|
|
1899
|
+
publish: () => write("changes.publish")
|
|
1970
1900
|
};
|
|
1971
1901
|
}
|
|
1972
1902
|
};
|
|
@@ -2547,7 +2477,7 @@ function keys2(v, allowed, required = allowed) {
|
|
|
2547
2477
|
function text3(v) {
|
|
2548
2478
|
return typeof v == "string" && v.length > 0 && v.length <= 1024;
|
|
2549
2479
|
}
|
|
2550
|
-
function
|
|
2480
|
+
function fields2(v, nonempty = !1) {
|
|
2551
2481
|
let result2 = object3(v);
|
|
2552
2482
|
(nonempty && !Object.keys(result2).length || Object.keys(result2).some((k) => !text3(k))) && fail2("Invalid Airtable fields");
|
|
2553
2483
|
try {
|
|
@@ -2558,7 +2488,7 @@ function fields3(v, nonempty = !1) {
|
|
|
2558
2488
|
}
|
|
2559
2489
|
function record2(v) {
|
|
2560
2490
|
let r = object3(v);
|
|
2561
|
-
return (!recordId(r.id) || r.createdTime !== void 0 && (typeof r.createdTime != "string" || !Number.isFinite(Date.parse(r.createdTime)))) && fail2("Malformed Airtable record"), { id: r.id, ...r.createdTime === void 0 ? {} : { createdTime: r.createdTime }, fields:
|
|
2491
|
+
return (!recordId(r.id) || r.createdTime !== void 0 && (typeof r.createdTime != "string" || !Number.isFinite(Date.parse(r.createdTime)))) && fail2("Malformed Airtable record"), { id: r.id, ...r.createdTime === void 0 ? {} : { createdTime: r.createdTime }, fields: fields2(r.fields) };
|
|
2562
2492
|
}
|
|
2563
2493
|
function equal(a, b) {
|
|
2564
2494
|
if (a === b) return !0;
|
|
@@ -2674,10 +2604,10 @@ async function executeAirtableOperation(authority2, operation2, raw, options = {
|
|
|
2674
2604
|
mutation || fail2("Unsupported Airtable operation"), keys2(input, ["table", "records"]), (!Array.isArray(input.records) || !input.records.length || input.records.length > 10) && fail2("Invalid Airtable batch");
|
|
2675
2605
|
let kind = operation2.slice(8), ids = /* @__PURE__ */ new Set(), records = input.records.map((value) => {
|
|
2676
2606
|
let r = object3(value);
|
|
2677
|
-
if (keys2(r, kind === "create" ? ["fields"] : kind === "update" ? ["id", "expected", "set"] : ["id", "expected"]), kind === "create") return { fields:
|
|
2607
|
+
if (keys2(r, kind === "create" ? ["fields"] : kind === "update" ? ["id", "expected", "set"] : ["id", "expected"]), kind === "create") return { fields: fields2(r.fields, !0) };
|
|
2678
2608
|
(!recordId(r.id) || ids.has(r.id)) && fail2("Invalid Airtable batch record ID"), ids.add(r.id);
|
|
2679
|
-
let set = kind === "update" ?
|
|
2680
|
-
return set && Object.values(set).some((value2) => value2 === null) && fail2("Airtable guard null cannot be an update value"), { id: r.id, expected:
|
|
2609
|
+
let set = kind === "update" ? fields2(r.set, !0) : void 0;
|
|
2610
|
+
return set && Object.values(set).some((value2) => value2 === null) && fail2("Airtable guard null cannot be an update value"), { id: r.id, expected: fields2(r.expected), ...set ? { set } : {} };
|
|
2681
2611
|
});
|
|
2682
2612
|
for (let r of records) {
|
|
2683
2613
|
if (!("id" in r)) continue;
|
|
@@ -2929,37 +2859,49 @@ var source = {
|
|
|
2929
2859
|
}
|
|
2930
2860
|
};
|
|
2931
2861
|
|
|
2862
|
+
function parseInboxRecordRefs(value) {
|
|
2863
|
+
let refs = serializable(value);
|
|
2864
|
+
if (!Array.isArray(refs) || !refs.length || refs.length > 100) throw new Error("Invalid Record read");
|
|
2865
|
+
let result2 = refs.map(validateQualifiedRecordRef);
|
|
2866
|
+
if (new Set(result2.map(recordKey)).size !== result2.length) throw new Error("Duplicate Record reference");
|
|
2867
|
+
return result2;
|
|
2868
|
+
}
|
|
2869
|
+
var recordKey = ({ repository, ref }) => JSON.stringify([repository, ref]);
|
|
2870
|
+
function parseInboxRecords(value) {
|
|
2871
|
+
let result2 = serializable(value);
|
|
2872
|
+
if (!result2 || Object.keys(result2).join() !== "records" || !Array.isArray(result2.records) || result2.records.length > 100) throw new Error("Invalid Record result");
|
|
2873
|
+
for (let entry of result2.records)
|
|
2874
|
+
if (validateQualifiedRecordRef({ repository: entry.repository, ref: entry.ref }), Object.keys(entry).sort().join() !== "record,ref,repository,schema" || (entry.record === null ? entry.schema !== null : !entry.schema || entry.record.$ref !== entry.ref || typeof entry.record.$version != "string" || !Array.isArray(entry.schema.fields) || typeof entry.schema.name != "string"))
|
|
2875
|
+
throw new Error("Invalid current Record");
|
|
2876
|
+
if (new Set(result2.records.map(recordKey)).size !== result2.records.length) throw new Error("Duplicate current Record");
|
|
2877
|
+
return result2;
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2932
2880
|
var InboxOperationError = class extends Error {
|
|
2933
|
-
constructor(status, reason
|
|
2934
|
-
super(reason === "
|
|
2881
|
+
constructor(status, reason) {
|
|
2882
|
+
super(reason === "handler_unavailable" ? "Deploy the routine that owns this question\u2019s response handler." : reason === "conflict" ? "This question already has an accepted answer" : reason === "unavailable" ? "Inbox request unavailable. Retry the same action." : reason === "invalid_input" ? "Invalid Inbox request" : "Inbox access unavailable");
|
|
2935
2883
|
this.status = status;
|
|
2936
2884
|
this.reason = reason;
|
|
2937
|
-
this.requirementsRepository = requirementsRepository;
|
|
2938
2885
|
}
|
|
2939
2886
|
status;
|
|
2940
2887
|
reason;
|
|
2941
|
-
requirementsRepository;
|
|
2942
2888
|
};
|
|
2943
2889
|
function parseQuestionAvailability(value, available = !1) {
|
|
2944
2890
|
let state = object4(value);
|
|
2945
|
-
return keys3(state, ["unavailableReason"
|
|
2946
|
-
unavailableReason: state.unavailableReason,
|
|
2947
|
-
...state.unavailableReason === "records_need_attention" ? { requirementsRepository: state.requirementsRepository } : {}
|
|
2948
|
-
}) : (assert(!("requirementsRepository" in state)), {});
|
|
2891
|
+
return keys3(state, ["unavailableReason"], []), "unavailableReason" in state ? (assert(!available && state.unavailableReason === "handler_unavailable"), { unavailableReason: state.unavailableReason }) : {};
|
|
2949
2892
|
}
|
|
2950
2893
|
function questionAvailability(value, available = !1) {
|
|
2951
2894
|
return parseQuestionAvailability({
|
|
2952
|
-
..."unavailableReason" in value ? { unavailableReason: value.unavailableReason } : {}
|
|
2953
|
-
..."requirementsRepository" in value ? { requirementsRepository: value.requirementsRepository } : {}
|
|
2895
|
+
..."unavailableReason" in value ? { unavailableReason: value.unavailableReason } : {}
|
|
2954
2896
|
}, available);
|
|
2955
2897
|
}
|
|
2956
2898
|
function parseInboxUnavailableFailure(value, status) {
|
|
2957
2899
|
try {
|
|
2958
2900
|
if (status !== 503) return;
|
|
2959
2901
|
let envelope = object4(value);
|
|
2960
|
-
keys3(envelope, ["error", "unavailableReason"
|
|
2902
|
+
keys3(envelope, ["error", "unavailableReason"], ["error", "unavailableReason"]), assert(text4(envelope.error));
|
|
2961
2903
|
let state = questionAvailability(envelope);
|
|
2962
|
-
return new InboxOperationError(503, state.unavailableReason
|
|
2904
|
+
return new InboxOperationError(503, state.unavailableReason);
|
|
2963
2905
|
} catch {
|
|
2964
2906
|
return;
|
|
2965
2907
|
}
|
|
@@ -2973,6 +2915,7 @@ var operations = {
|
|
|
2973
2915
|
"items.list": [],
|
|
2974
2916
|
"questions.list": [],
|
|
2975
2917
|
"items.read": ["itemId"],
|
|
2918
|
+
"items.readRecords": ["itemId", "records"],
|
|
2976
2919
|
"items.see": ["itemId"],
|
|
2977
2920
|
"items.markDigestRead": ["itemId"],
|
|
2978
2921
|
"items.rename": ["itemId", "revision", "title"],
|
|
@@ -3069,48 +3012,6 @@ function responseDefinition(value) {
|
|
|
3069
3012
|
});
|
|
3070
3013
|
assert(suggestions.length <= 8 && new Set(refs).size === refs.length);
|
|
3071
3014
|
}
|
|
3072
|
-
function inboxFile(value) {
|
|
3073
|
-
validateInboxFile(value);
|
|
3074
|
-
}
|
|
3075
|
-
function fields4(value) {
|
|
3076
|
-
let labels = array2(value).map((value2) => {
|
|
3077
|
-
let field = object4(value2);
|
|
3078
|
-
return keys3(field, ["label", "value"]), assert(text4(field.label) && text4(field.value)), field.label;
|
|
3079
|
-
});
|
|
3080
|
-
assert(new Set(labels).size === labels.length);
|
|
3081
|
-
}
|
|
3082
|
-
function block(value) {
|
|
3083
|
-
let entry = object4(value);
|
|
3084
|
-
if (entry.kind === "rich-text") {
|
|
3085
|
-
keys3(entry, ["kind", "markdown"]), assert(text4(entry.markdown));
|
|
3086
|
-
return;
|
|
3087
|
-
}
|
|
3088
|
-
if (entry.kind === "asks") {
|
|
3089
|
-
keys3(entry, ["kind", "problem", "asks"]);
|
|
3090
|
-
let asks = array2(entry.asks);
|
|
3091
|
-
assert(text4(entry.problem) && asks.length > 0 && asks.every(id2) && new Set(asks).size === asks.length);
|
|
3092
|
-
return;
|
|
3093
|
-
}
|
|
3094
|
-
if (assert(["record", "records", "files"].includes(String(entry.kind))), keys3(
|
|
3095
|
-
entry,
|
|
3096
|
-
["kind", "label", "initiallyExpanded", ...entry.kind === "record" ? ["record", "view"] : entry.kind === "records" ? ["records", "view"] : ["files"]],
|
|
3097
|
-
["kind", "label", entry.kind === "record" ? "record" : entry.kind === "records" ? "records" : "files"]
|
|
3098
|
-
), assert(text4(entry.label) && (!("initiallyExpanded" in entry) || typeof entry.initiallyExpanded == "boolean") && (!("view" in entry) || text4(entry.view) && entry.view === entry.view.trim())), entry.kind === "record") {
|
|
3099
|
-
let record4 = object4(entry.record);
|
|
3100
|
-
keys3(record4, ["ref", "title", "fields"]), assert(text4(record4.ref) && record4.ref === record4.ref.trim() && text4(record4.title)), fields4(record4.fields);
|
|
3101
|
-
return;
|
|
3102
|
-
}
|
|
3103
|
-
if (entry.kind === "records") {
|
|
3104
|
-
let records = array2(entry.records), refs = records.map((value2) => {
|
|
3105
|
-
let record4 = object4(value2);
|
|
3106
|
-
return keys3(record4, ["ref", "title", "description", "facts", "view"], ["ref", "title"]), assert(text4(record4.ref) && record4.ref === record4.ref.trim() && text4(record4.title)), "description" in record4 && assert(text4(record4.description)), "facts" in record4 && fields4(record4.facts), "view" in record4 && assert(text4(record4.view) && record4.view === record4.view.trim()), record4.ref;
|
|
3107
|
-
});
|
|
3108
|
-
assert(records.length > 0 && new Set(refs).size === refs.length);
|
|
3109
|
-
return;
|
|
3110
|
-
}
|
|
3111
|
-
let files3 = array2(entry.files);
|
|
3112
|
-
files3.forEach(inboxFile), assert(files3.length > 0 && new Set(files3.map((value2) => object4(value2).id)).size === files3.length);
|
|
3113
|
-
}
|
|
3114
3015
|
function response(value) {
|
|
3115
3016
|
let answer = object4(value);
|
|
3116
3017
|
return assert(Object.keys(answer).every((key) => ["selection", "note"].includes(key))), typeof answer.selection == "string" ? assert(text4(answer.selection) && answer.selection === answer.selection.trim()) : recordReference(answer.selection), Object.hasOwn(answer, "note") && assert(text4(answer.note)), answer;
|
|
@@ -3120,9 +3021,9 @@ function parseInboxRequest(value) {
|
|
|
3120
3021
|
let envelope = object4(value);
|
|
3121
3022
|
assert(Object.keys(envelope).sort().join(",") === "input,operation"), assert(typeof envelope.operation == "string" && Object.hasOwn(operations, envelope.operation));
|
|
3122
3023
|
let operation2 = envelope.operation, input = { ...object4(envelope.input) }, required = operations[operation2];
|
|
3123
|
-
assert(required.every((key) => Object.hasOwn(input, key)) && Object.keys(input).every((key) => required.includes(key) || operation2 === "questions.searchRecords" && key === "selected" || (operation2 === "items.list" || operation2 === "questions.list") && key === "beforeNumber" || operation2 === "questions.list" && key === "routines")), operation2 === "questions.list" && (assert(Object.hasOwn(input, "routines")), assert(array2(input.routines).every(isAppRoutineName)));
|
|
3024
|
+
assert(required.every((key) => Object.hasOwn(input, key)) && Object.keys(input).every((key) => required.includes(key) || operation2 === "questions.answer" && key === "label" || operation2 === "questions.searchRecords" && key === "selected" || (operation2 === "items.list" || operation2 === "questions.list") && key === "beforeNumber" || operation2 === "questions.list" && key === "routines")), operation2 === "questions.list" && (assert(Object.hasOwn(input, "routines")), assert(array2(input.routines).every(isAppRoutineName)));
|
|
3124
3025
|
for (let key of ["itemId", "personId", "fileId"]) key in input && assert(id2(input[key]));
|
|
3125
|
-
return "revision" in input && assert(integer(input.revision)), "beforeNumber" in input && assert(integer(input.beforeNumber)), "questionId" in input && assert(text4(input.questionId) && input.questionId === input.questionId.trim()), "title" in input && assert(text4(input.title)), "lifecycle" in input && assert(input.lifecycle === "open" || input.lifecycle === "closed"), "query" in input && assert(text4(input.query, !0) && input.query.length <= 256), "selected" in input && recordReference(input.selected), "response" in input && response(input.response), assert(new TextEncoder().encode(JSON.stringify(envelope)).byteLength <= INBOX_INPUT_BYTES), "routines" in input && (input.routines = [...new Set(input.routines)]), { operation: operation2, input };
|
|
3026
|
+
return "revision" in input && assert(integer(input.revision)), "beforeNumber" in input && assert(integer(input.beforeNumber)), "questionId" in input && assert(text4(input.questionId) && input.questionId === input.questionId.trim()), "title" in input && assert(text4(input.title)), "lifecycle" in input && assert(input.lifecycle === "open" || input.lifecycle === "closed"), "query" in input && assert(text4(input.query, !0) && input.query.length <= 256), "records" in input && (input.records = parseInboxRecordRefs(input.records)), "selected" in input && recordReference(input.selected), "response" in input && response(input.response), "label" in input && assert(text4(input.label) && typeof input.response?.selection == "object"), assert(new TextEncoder().encode(JSON.stringify(envelope)).byteLength <= INBOX_INPUT_BYTES), "routines" in input && (input.routines = [...new Set(input.routines)]), { operation: operation2, input };
|
|
3126
3027
|
} catch {
|
|
3127
3028
|
throw new InboxOperationError(400, "invalid_input");
|
|
3128
3029
|
}
|
|
@@ -3136,7 +3037,7 @@ function parseInboxCurrent(value) {
|
|
|
3136
3037
|
}
|
|
3137
3038
|
function parseInboxItem(value) {
|
|
3138
3039
|
let item = object4(json(value));
|
|
3139
|
-
return assert(id2(item.id) && id2(item.workspaceId) && integer(item.number) && integer(item.revision) && integer(item.activityVersion, 0) && ["ask", "digest"].includes(String(item.kind)) && ["open", "closed"].includes(String(item.lifecycle)) && text4(item.title) && text4(item.description, !0) && text4(item.author) && date(item.publishedAt) && optionalDate(item.seenAt) && optionalDate(item.digestReadAt)), item.outcome !== null && assert(text4(object4(item.outcome).outcome)), "canonicalRoutineId" in item && assert(item.canonicalRoutineId === null || isAppRoutineName(item.canonicalRoutineId)), item.kind === "ask" ? askMetadata(item) : assert(!("tags" in item) && !("recordRefs" in item)), array2(item.body).forEach(
|
|
3040
|
+
return assert(id2(item.id) && id2(item.workspaceId) && integer(item.number) && integer(item.revision) && integer(item.activityVersion, 0) && ["ask", "digest"].includes(String(item.kind)) && ["open", "closed"].includes(String(item.lifecycle)) && text4(item.title) && text4(item.description, !0) && text4(item.author) && date(item.publishedAt) && optionalDate(item.seenAt) && optionalDate(item.digestReadAt)), item.outcome !== null && assert(text4(object4(item.outcome).outcome)), "canonicalRoutineId" in item && assert(item.canonicalRoutineId === null || isAppRoutineName(item.canonicalRoutineId)), item.kind === "ask" ? askMetadata(item) : assert(!("tags" in item) && !("recordRefs" in item)), array2(item.body).forEach(validateBlock), array2(item.views).forEach((value2) => {
|
|
3140
3041
|
let view = object4(value2);
|
|
3141
3042
|
assert(text4(view.id) && text4(view.view) && text4(view.implementation)), json(view.input);
|
|
3142
3043
|
}), array2(item.people).forEach((value2) => {
|
|
@@ -3144,7 +3045,7 @@ function parseInboxItem(value) {
|
|
|
3144
3045
|
assert(id2(person.id) && text4(person.name));
|
|
3145
3046
|
}), array2(item.questions).forEach((value2) => {
|
|
3146
3047
|
let question2 = object4(value2);
|
|
3147
|
-
if (assert(text4(question2.id) && id2(question2.to) && text4(question2.prompt) && (question2.instructions === null || text4(question2.instructions, !0)) && typeof question2.available == "boolean"), questionAvailability(question2, question2.available), assert(!("requirements" in question2) && !("handler" in question2)), responseDefinition(question2.response), assert(array2(question2.allowedResponders).every(id2)), question2.acceptedResponse !== null) {
|
|
3048
|
+
if (assert(text4(question2.id) && id2(question2.to) && text4(question2.prompt) && (question2.instructions === null || text4(question2.instructions, !0)) && typeof question2.available == "boolean"), questionAvailability(question2, question2.available), assert(!("requirements" in question2) && !("requirementsRepository" in question2) && !("handler" in question2)), responseDefinition(question2.response), assert(array2(question2.allowedResponders).every(id2)), question2.acceptedResponse !== null) {
|
|
3148
3049
|
let accepted = object4(question2.acceptedResponse);
|
|
3149
3050
|
assert(id2(accepted.id) && id2(accepted.userId) && date(accepted.acceptedAt)), response(accepted.response), accepted.label === null ? delete accepted.label : "label" in accepted && assert(text4(accepted.label)), "acceptanceOrder" in accepted && assert(integer(accepted.acceptanceOrder));
|
|
3150
3051
|
}
|
|
@@ -3177,7 +3078,7 @@ function parseAnswerableQuestion(value) {
|
|
|
3177
3078
|
let entry = object4(json(value));
|
|
3178
3079
|
keys3(
|
|
3179
3080
|
entry,
|
|
3180
|
-
["itemId", "number", "revision", "title", "inboxUrl", "questionId", "routine", "prompt", "response", "answerable", "tags", "recordRefs", "instructions", "unavailableReason"
|
|
3081
|
+
["itemId", "number", "revision", "title", "inboxUrl", "questionId", "routine", "prompt", "response", "answerable", "tags", "recordRefs", "instructions", "unavailableReason"],
|
|
3181
3082
|
["itemId", "number", "revision", "title", "inboxUrl", "questionId", "routine", "prompt", "response", "answerable"]
|
|
3182
3083
|
), assert(id2(entry.itemId) && integer(entry.number) && integer(entry.revision) && text4(entry.title) && text4(entry.inboxUrl));
|
|
3183
3084
|
let link = new URL(entry.inboxUrl), slug = link.hostname.slice(0, -13);
|
|
@@ -3207,6 +3108,7 @@ function parseInboxResult(operation2, value) {
|
|
|
3207
3108
|
let questions = array2(page.questions).map(parseAnswerableQuestion);
|
|
3208
3109
|
return assert(page.nextBeforeNumber === null || integer(page.nextBeforeNumber)), { questions, nextBeforeNumber: page.nextBeforeNumber };
|
|
3209
3110
|
}
|
|
3111
|
+
if (operation2 === "items.readRecords") return parseInboxRecords(value);
|
|
3210
3112
|
if (operation2 === "items.read") return parseInboxItem(value);
|
|
3211
3113
|
if (operation2 === "items.list") {
|
|
3212
3114
|
let page = object4(value), items = array2(page.items).map(parseInboxItem);
|
|
@@ -3798,8 +3700,7 @@ async function send2(operation2, input, resolved) {
|
|
|
3798
3700
|
);
|
|
3799
3701
|
if (response2.status !== 200) throw unavailable3();
|
|
3800
3702
|
let parsed = parseInboxResult(operation2, value);
|
|
3801
|
-
|
|
3802
|
-
return parsed;
|
|
3703
|
+
return check2(), parsed;
|
|
3803
3704
|
} catch (error) {
|
|
3804
3705
|
throw check2(), error instanceof InboxOperationError ? error : unavailable3();
|
|
3805
3706
|
}
|
|
@@ -3857,7 +3758,7 @@ async function send2(operation2, input, resolved) {
|
|
|
3857
3758
|
if (check(), operation2 === "current" && parsed.workspace.slug !== context.workspace) throw unavailable3();
|
|
3858
3759
|
if ("itemId" in envelope.input) {
|
|
3859
3760
|
let item = operation2 === "items.read" ? parsed : operation2 === "items.rename" || operation2 === "items.setLifecycle" || operation2 === "items.addRecipient" ? parsed.item : void 0;
|
|
3860
|
-
if (item && (item.id !== envelope.input.itemId || "revision" in envelope.input && item.revision !== envelope.input.revision) || operation2 === "items.addRecipient" && parsed.addedPersonId !== envelope.input.personId
|
|
3761
|
+
if (item && (item.id !== envelope.input.itemId || "revision" in envelope.input && item.revision !== envelope.input.revision) || operation2 === "items.addRecipient" && parsed.addedPersonId !== envelope.input.personId) throw unavailable3();
|
|
3861
3762
|
}
|
|
3862
3763
|
return parsed;
|
|
3863
3764
|
} catch (error) {
|
|
@@ -3893,6 +3794,7 @@ var inbox = {
|
|
|
3893
3794
|
beforeNumber = page.nextBeforeNumber;
|
|
3894
3795
|
} while (!0);
|
|
3895
3796
|
},
|
|
3797
|
+
readRecords: async (input) => await send2("items.readRecords", input),
|
|
3896
3798
|
read: async (itemId) => await send2("items.read", { itemId }),
|
|
3897
3799
|
see: async (itemId) => {
|
|
3898
3800
|
await send2("items.see", { itemId });
|
|
@@ -4799,7 +4701,7 @@ function validStep(step) {
|
|
|
4799
4701
|
}
|
|
4800
4702
|
function validLocalActivity(value) {
|
|
4801
4703
|
let paths = (value2) => Array.isArray(value2) && value2.every((path) => typeof path == "string" && path.length > 0 && path.length <= 4096 && !path.startsWith("/") && !path.includes("\\") && !path.split("/").some((part) => !part || part === "." || part === "..") && !/[\x00-\x1f\x7f]/.test(path));
|
|
4802
|
-
return value && only(value, "data,effects,git") && bounded2(value) && Array.isArray(value.data) && Array.isArray(value.effects) && value.data.every((item) => only(item, "repository,created,updated,deleted,failures,failure") && typeof item.repository == "string" && identifier.test(item.repository) && paths(item.created) && paths(item.updated) && paths(item.deleted) && (item.failures === void 0 || Array.isArray(item.failures) && item.failures.every((code) => typeof code == "string" && dataErrorCodes.has(code))) && (item.failure === void 0 || (() => {
|
|
4704
|
+
return value && only(value, "data,effects,git") && bounded2(value) && Array.isArray(value.data) && Array.isArray(value.effects) && value.data.every((item) => only(item, "repository,created,updated,deleted,failures,failure,publications") && typeof item.repository == "string" && identifier.test(item.repository) && (item.publications === void 0 || Array.isArray(item.publications) && item.publications.every((fact) => only(fact, "state,commit") && ["files", "commit", "published"].includes(fact.state) && (fact.state === "files" ? fact.commit === void 0 : typeof fact.commit == "string" && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(fact.commit)))) && paths(item.created) && paths(item.updated) && paths(item.deleted) && (item.failures === void 0 || Array.isArray(item.failures) && item.failures.every((code) => typeof code == "string" && dataErrorCodes.has(code))) && (item.failure === void 0 || (() => {
|
|
4803
4705
|
try {
|
|
4804
4706
|
return parseDataFailureDetail(item.failure), !0;
|
|
4805
4707
|
} catch {
|
|
@@ -5001,7 +4903,6 @@ export {
|
|
|
5001
4903
|
question,
|
|
5002
4904
|
recordBlock,
|
|
5003
4905
|
recordsBlock,
|
|
5004
|
-
requireRecords,
|
|
5005
4906
|
resolveAsk,
|
|
5006
4907
|
respond,
|
|
5007
4908
|
richTextBlock,
|