@composable-os/cli 0.1.0-beta.7 → 0.1.0-beta.9

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.
Files changed (64) hide show
  1. package/dist/accounts-D6N77JGP.js +44 -0
  2. package/dist/{blocks-HVTAQ5W2.js → blocks-4CA4PP3P.js} +4 -4
  3. package/dist/{chunk-X6I2LWB3.js → chunk-2MLAPQU7.js} +1471 -359
  4. package/dist/{chunk-2S7375SC.js → chunk-3MIEYXRY.js} +3 -301
  5. package/dist/chunk-56A6RJIU.js +1040 -0
  6. package/dist/chunk-7CQGMVDO.js +63 -0
  7. package/dist/{chunk-STJZJIRA.js → chunk-7O4F3NU4.js} +1039 -1380
  8. package/dist/chunk-7U3OZLTK.js +1370 -0
  9. package/dist/{chunk-ZRWF6QZS.js → chunk-DU6OIFOU.js} +1 -0
  10. package/dist/chunk-E4WCYTCT.js +347 -0
  11. package/dist/{chunk-E5JLTLRM.js → chunk-GYTEW66E.js} +1 -1
  12. package/dist/chunk-LPD2VR5M.js +284 -0
  13. package/dist/chunk-NDKVIG23.js +2641 -0
  14. package/dist/chunk-NSSUOI3Z.js +333 -0
  15. package/dist/chunk-OV3OFYPI.js +746 -0
  16. package/dist/{chunk-2P4AZTFL.js → chunk-P6YZMS3F.js} +11 -5
  17. package/dist/{chunk-Y7PQ7NIL.js → chunk-RFJOPI42.js} +138 -14
  18. package/dist/{chunk-VL62IMBN.js → chunk-RXRD34QW.js} +10 -8
  19. package/dist/{chunk-BEKL3CA2.js → chunk-STBMGUTM.js} +7065 -4580
  20. package/dist/chunk-VTQNOQGA.js +150 -0
  21. package/dist/chunk-XSE37HK5.js +426 -0
  22. package/dist/{chunk-MINQ46RU.js → chunk-Z52IX5WL.js} +257 -844
  23. package/dist/chunk-ZSR5H4O7.js +552 -0
  24. package/dist/{cli-XHC6QBQW.js → cli-7A5XHYML.js} +16 -9
  25. package/dist/{cli-BRSACHSG.js → cli-T6MJM7TU.js} +20 -8
  26. package/dist/cli.js +4 -4
  27. package/dist/{client-repo-G55G4OLV.js → client-repo-PC4ISVEZ.js} +4 -4
  28. package/dist/create.js +4 -4
  29. package/dist/{fields-64BQJA62.js → fields-L24XAIOA.js} +13 -11
  30. package/dist/invoke-TLYT6CFI.js +33 -0
  31. package/dist/order-IKQBUFCV.js +19 -0
  32. package/dist/{person-AZFEPZOE.js → person-DXEOOH2A.js} +9 -5
  33. package/dist/plan-on-sale-LRCK5MJG.js +24 -0
  34. package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
  35. package/dist/platform/migrations/0516_order_tax.sql +63 -0
  36. package/dist/platform/migrations/0520_publish_requests.sql +20 -0
  37. package/dist/platform/migrations/0530_subscriptions.sql +173 -0
  38. package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
  39. package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
  40. package/dist/platform/migrations/0533_allowances.sql +262 -0
  41. package/dist/platform/migrations/0560_recurring.sql +75 -0
  42. package/dist/platform/sdk/allowance.ts +508 -0
  43. package/dist/platform/sdk/capacity.ts +89 -0
  44. package/dist/platform/sdk/contract.ts +97 -1
  45. package/dist/platform/sdk/document.ts +161 -14
  46. package/dist/platform/sdk/field-types.ts +5 -0
  47. package/dist/platform/sdk/index.ts +3 -0
  48. package/dist/platform/sdk/manifest.ts +206 -5
  49. package/dist/platform/sdk/media.ts +62 -0
  50. package/dist/platform/sdk/recurring.ts +314 -0
  51. package/dist/platform/sdk/rich-text.ts +52 -4
  52. package/dist/platform/sdk/sellable.ts +120 -0
  53. package/dist/platform/sdk/states.ts +162 -1
  54. package/dist/platform/sdk/unique.ts +81 -0
  55. package/dist/run-BMSZKTN3.js +648 -0
  56. package/dist/run-GMQBAV6H.js +309 -0
  57. package/dist/{run-4JNFLYXV.js → run-TNHMG5RI.js} +51 -390
  58. package/dist/src-7DXXGZG2.js +38 -0
  59. package/dist/{src-J27WXNLY.js → src-BDG7PERB.js} +73 -1
  60. package/dist/visibility-XSBZTO66.js +33 -0
  61. package/package.json +2 -2
  62. package/dist/chunk-MAXLUQKB.js +0 -1287
  63. package/dist/invoke-5SR5ZWW7.js +0 -26
  64. package/dist/src-SSVOBH6L.js +0 -31
@@ -820,10 +820,10 @@ function mergeDefs(...defs) {
820
820
  function cloneDef(schema) {
821
821
  return mergeDefs(schema._zod.def);
822
822
  }
823
- function getElementAtPath(obj, path) {
824
- if (!path)
823
+ function getElementAtPath(obj, path2) {
824
+ if (!path2)
825
825
  return obj;
826
- return path.reduce((acc, key) => acc?.[key], obj);
826
+ return path2.reduce((acc, key) => acc?.[key], obj);
827
827
  }
828
828
  function promiseAllObject(promisesObj) {
829
829
  const keys = Object.keys(promisesObj);
@@ -1163,11 +1163,11 @@ function explicitlyAborted(x, startIndex = 0) {
1163
1163
  }
1164
1164
  return false;
1165
1165
  }
1166
- function prefixIssues(path, issues) {
1166
+ function prefixIssues(path2, issues) {
1167
1167
  return issues.map((iss) => {
1168
1168
  var _a3;
1169
1169
  (_a3 = iss).path ?? (_a3.path = []);
1170
- iss.path.unshift(path);
1170
+ iss.path.unshift(path2);
1171
1171
  return iss;
1172
1172
  });
1173
1173
  }
@@ -1629,16 +1629,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
1629
1629
  }
1630
1630
  function formatError(error62, mapper = (issue2) => issue2.message) {
1631
1631
  const fieldErrors = { _errors: [] };
1632
- const processError = (error63, path = []) => {
1632
+ const processError = (error63, path2 = []) => {
1633
1633
  for (const issue2 of error63.issues) {
1634
1634
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1635
- issue2.errors.map((issues) => processError({ issues }, [...path, ...issue2.path]));
1635
+ issue2.errors.map((issues) => processError({ issues }, [...path2, ...issue2.path]));
1636
1636
  } else if (issue2.code === "invalid_key") {
1637
- processError({ issues: issue2.issues }, [...path, ...issue2.path]);
1637
+ processError({ issues: issue2.issues }, [...path2, ...issue2.path]);
1638
1638
  } else if (issue2.code === "invalid_element") {
1639
- processError({ issues: issue2.issues }, [...path, ...issue2.path]);
1639
+ processError({ issues: issue2.issues }, [...path2, ...issue2.path]);
1640
1640
  } else {
1641
- const fullpath = [...path, ...issue2.path];
1641
+ const fullpath = [...path2, ...issue2.path];
1642
1642
  if (fullpath.length === 0) {
1643
1643
  fieldErrors._errors.push(mapper(issue2));
1644
1644
  } else {
@@ -1677,17 +1677,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
1677
1677
  }
1678
1678
  function treeifyError(error62, mapper = (issue2) => issue2.message) {
1679
1679
  const result = { errors: [] };
1680
- const processError = (error63, path = []) => {
1680
+ const processError = (error63, path2 = []) => {
1681
1681
  var _a3;
1682
1682
  for (const issue2 of error63.issues) {
1683
1683
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1684
- issue2.errors.map((issues) => processError({ issues }, [...path, ...issue2.path]));
1684
+ issue2.errors.map((issues) => processError({ issues }, [...path2, ...issue2.path]));
1685
1685
  } else if (issue2.code === "invalid_key") {
1686
- processError({ issues: issue2.issues }, [...path, ...issue2.path]);
1686
+ processError({ issues: issue2.issues }, [...path2, ...issue2.path]);
1687
1687
  } else if (issue2.code === "invalid_element") {
1688
- processError({ issues: issue2.issues }, [...path, ...issue2.path]);
1688
+ processError({ issues: issue2.issues }, [...path2, ...issue2.path]);
1689
1689
  } else {
1690
- const fullpath = [...path, ...issue2.path];
1690
+ const fullpath = [...path2, ...issue2.path];
1691
1691
  if (fullpath.length === 0) {
1692
1692
  result.errors.push(mapper(issue2));
1693
1693
  continue;
@@ -1726,8 +1726,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
1726
1726
  }
1727
1727
  function toDotPath(_path) {
1728
1728
  const segs = [];
1729
- const path = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1730
- for (const seg of path) {
1729
+ const path2 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1730
+ for (const seg of path2) {
1731
1731
  if (typeof seg === "number")
1732
1732
  segs.push(`[${seg}]`);
1733
1733
  else if (typeof seg === "symbol")
@@ -18865,13 +18865,13 @@ function resolveRef(ref, ctx) {
18865
18865
  if (!ref.startsWith("#")) {
18866
18866
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
18867
18867
  }
18868
- const path = ref.slice(1).split("/").filter(Boolean);
18869
- if (path.length === 0) {
18868
+ const path2 = ref.slice(1).split("/").filter(Boolean);
18869
+ if (path2.length === 0) {
18870
18870
  return ctx.rootSchema;
18871
18871
  }
18872
18872
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
18873
- if (path[0] === defsKey) {
18874
- const key = path[1] === void 0 ? void 0 : decodeJSONPointerSegment(path[1]);
18873
+ if (path2[0] === defsKey) {
18874
+ const key = path2[1] === void 0 ? void 0 : decodeJSONPointerSegment(path2[1]);
18875
18875
  if (!key || !ctx.defs[key]) {
18876
18876
  throw new Error(`Reference not found: ${ref}`);
18877
18877
  }
@@ -19720,6 +19720,330 @@ function date4(params) {
19720
19720
  return _coercedDate(ZodDate, params);
19721
19721
  }
19722
19722
 
19723
+ // ../sdk/src/allowance.ts
19724
+ var ALLOWANCE_PERIODS = ["total", "week", "month"];
19725
+ var ALLOWANCE_VALUES = ["used", "left"];
19726
+ var fieldName = external_exports.string().max(40);
19727
+ var path = external_exports.string().max(81);
19728
+ var stateValue = external_exports.string().min(1).max(100);
19729
+ var conditionSchema = external_exports.object({
19730
+ field: fieldName,
19731
+ in: external_exports.union([fieldName, external_exports.array(external_exports.string().max(200)).min(1).max(100)]).optional(),
19732
+ atLeast: external_exports.union([fieldName, external_exports.number()]).optional(),
19733
+ below: external_exports.union([fieldName, external_exports.number()]).optional()
19734
+ }).strict();
19735
+ var spendsOnSchema = external_exports.object({ object: path, when: external_exports.array(conditionSchema).max(10).optional() }).strict();
19736
+ var allowanceManifestSchema = external_exports.union([
19737
+ external_exports.object({
19738
+ holds: external_exports.object({
19739
+ person: fieldName,
19740
+ uses: fieldName,
19741
+ per: external_exports.union([external_exports.enum(ALLOWANCE_PERIODS), external_exports.object({ field: fieldName }).strict()]),
19742
+ spendsOn: external_exports.union([spendsOnSchema, external_exports.array(spendsOnSchema).min(1).max(8)]),
19743
+ from: fieldName.optional(),
19744
+ until: fieldName.optional(),
19745
+ live: external_exports.array(stateValue).min(1).max(20).optional(),
19746
+ zone: fieldName.optional(),
19747
+ emptyIsUnlimited: external_exports.boolean().optional()
19748
+ }).strict()
19749
+ }).strict(),
19750
+ external_exports.object({
19751
+ spends: external_exports.object({
19752
+ person: fieldName,
19753
+ holder: fieldName,
19754
+ spendIn: external_exports.array(stateValue).min(1).max(20),
19755
+ returnIn: external_exports.array(stateValue).max(20),
19756
+ at: path.optional(),
19757
+ copy: external_exports.record(fieldName, path).optional(),
19758
+ local: external_exports.object({
19759
+ weekday: fieldName.optional(),
19760
+ minute: fieldName.optional(),
19761
+ zone: path.optional()
19762
+ }).strict().optional(),
19763
+ movedFrom: external_exports.object({ field: fieldName, state: stateValue }).strict().optional(),
19764
+ paidBy: external_exports.array(path).min(1).max(20).optional()
19765
+ }).strict()
19766
+ }).strict()
19767
+ ]);
19768
+ function spendsOnList(holds) {
19769
+ return Array.isArray(holds.spendsOn) ? holds.spendsOn : [holds.spendsOn];
19770
+ }
19771
+ var DATES = /* @__PURE__ */ new Set(["date", "datetime"]);
19772
+ function hostFilledFields(spends) {
19773
+ return [
19774
+ ...Object.keys(spends.copy ?? {}),
19775
+ ...spends.local?.weekday ? [spends.local.weekday] : [],
19776
+ ...spends.local?.minute ? [spends.local.minute] : []
19777
+ ];
19778
+ }
19779
+ function spenderAllows(spends, spenderExtension, holderObject) {
19780
+ const holderExtension = holderObject.split(".")[0];
19781
+ if (holderExtension === spenderExtension) return true;
19782
+ return (spends.paidBy ?? []).some((p) => p === holderObject || p === holderExtension);
19783
+ }
19784
+ function customerWritable(m, name) {
19785
+ const object3 = m.objects[name];
19786
+ const out = new Set(object3?.customer?.write ?? []);
19787
+ if (object3?.customer?.field) out.add(object3.customer.field);
19788
+ for (const tool of Object.values(m.tools ?? {})) {
19789
+ for (const field of tool.customerFields?.[`${m.id}.${name}`] ?? []) out.add(field);
19790
+ }
19791
+ return out;
19792
+ }
19793
+ function checkObjectAllowance(m, name, object3, contract) {
19794
+ const allowance = object3.allowance;
19795
+ if (!allowance) return;
19796
+ const ap = `objects.${name}.allowance`;
19797
+ const fieldOf = (o, local) => Object.hasOwn(o.fields, local) ? o.fields[local] : void 0;
19798
+ const customerWrites = customerWritable(m, name);
19799
+ if (object3.customer?.field) customerWrites.delete(object3.customer.field);
19800
+ const ownObject = (target) => {
19801
+ const local = target.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : target.includes(".") ? void 0 : target;
19802
+ return local !== void 0 && Object.hasOwn(m.objects, local) ? [local, m.objects[local]] : void 0;
19803
+ };
19804
+ const states = new Set(
19805
+ object3.states ? (fieldOf(object3, object3.states.field)?.options ?? []).map((o) => o.value) : []
19806
+ );
19807
+ const notCustomerWritten = (local, p, what) => {
19808
+ if (customerWrites.has(local)) {
19809
+ contract(
19810
+ p,
19811
+ `"${local}" is ${what}, so a customer cannot write it (customer.write or a tool's customerFields)`
19812
+ );
19813
+ }
19814
+ };
19815
+ if ("holds" in allowance) {
19816
+ const h = allowance.holds;
19817
+ const hp = `${ap}.holds`;
19818
+ const person2 = fieldOf(object3, h.person);
19819
+ if (person2?.type !== "relation" || person2.many || person2.to !== "person") {
19820
+ contract(`${hp}.person`, `"${h.person}" must be a relation field (one record) to person`);
19821
+ }
19822
+ if (h.person !== object3.customer?.field) {
19823
+ notCustomerWritten(h.person, `${hp}.person`, "whose uses they are");
19824
+ }
19825
+ const uses = fieldOf(object3, h.uses);
19826
+ if (uses?.type !== "number" || uses.many) {
19827
+ contract(`${hp}.uses`, `"${h.uses}" must be a number field of ${name}`);
19828
+ }
19829
+ notCustomerWritten(h.uses, `${hp}.uses`, "the holder's uses");
19830
+ if (typeof h.per === "object") {
19831
+ const per = fieldOf(object3, h.per.field);
19832
+ const options = (per?.options ?? []).map((o) => o.value);
19833
+ if (per?.type !== "select" || per.many) {
19834
+ contract(`${hp}.per.field`, `"${h.per.field}" must be a select field of ${name}`);
19835
+ } else if (options.some((o) => !ALLOWANCE_PERIODS.includes(o)) || per.editableOptions) {
19836
+ contract(
19837
+ `${hp}.per.field`,
19838
+ `"${h.per.field}"'s options must be fixed and among ${ALLOWANCE_PERIODS.join(", ")}`
19839
+ );
19840
+ }
19841
+ notCustomerWritten(h.per.field, `${hp}.per.field`, "the holder's period");
19842
+ }
19843
+ for (const key of ["from", "until"]) {
19844
+ const local = h[key];
19845
+ if (local === void 0) continue;
19846
+ const field = fieldOf(object3, local);
19847
+ if (!field || !DATES.has(field.type) || field.many) {
19848
+ contract(`${hp}.${key}`, `"${local}" must be a date or datetime field of ${name}`);
19849
+ }
19850
+ notCustomerWritten(local, `${hp}.${key}`, `the holder's ${key} date`);
19851
+ }
19852
+ if (h.zone !== void 0) {
19853
+ const zone = fieldOf(object3, h.zone);
19854
+ if (zone?.type !== "timezone" || zone.many) {
19855
+ contract(`${hp}.zone`, `"${h.zone}" must be a timezone field of ${name}`);
19856
+ }
19857
+ notCustomerWritten(h.zone, `${hp}.zone`, "the holder's zone");
19858
+ }
19859
+ if (object3.states) {
19860
+ if (!h.live) {
19861
+ contract(`${hp}.live`, "A holder with states names the states it can be spent in (live)");
19862
+ }
19863
+ for (const state of h.live ?? []) {
19864
+ if (!states.has(state)) {
19865
+ contract(`${hp}.live`, `"${state}" is not an option of ${object3.states.field}`);
19866
+ }
19867
+ }
19868
+ } else if (h.live) {
19869
+ contract(`${hp}.live`, "live names states, and this object has none");
19870
+ }
19871
+ for (const reserved of ALLOWANCE_VALUES) {
19872
+ if (Object.hasOwn(object3.fields, reserved)) {
19873
+ contract(
19874
+ `objects.${name}.fields.${reserved}`,
19875
+ `"${reserved}" is a value the host adds to an allowance holder; rename the field`
19876
+ );
19877
+ }
19878
+ }
19879
+ spendsOnList(h).forEach((target, i) => {
19880
+ const sp2 = Array.isArray(h.spendsOn) ? `${hp}.spendsOn.${i}` : `${hp}.spendsOn`;
19881
+ const own2 = ownObject(target.object);
19882
+ if (!own2) {
19883
+ if (!target.object.includes(".") || target.object.startsWith(`${m.id}.`)) {
19884
+ contract(`${sp2}.object`, `"${target.object}" is not an object of this extension`);
19885
+ }
19886
+ return;
19887
+ }
19888
+ const [spenderName, spender] = own2;
19889
+ if (!spender.allowance || !("spends" in spender.allowance)) {
19890
+ contract(`${sp2}.object`, `${spenderName} must declare allowance.spends`);
19891
+ return;
19892
+ }
19893
+ const filledBy = new Set(hostFilledFields(spender.allowance.spends));
19894
+ (target.when ?? []).forEach((clause, j) => {
19895
+ const cp = `${sp2}.when.${j}`;
19896
+ const ops = ["in", "atLeast", "below"].filter((k) => clause[k] !== void 0);
19897
+ if (ops.length !== 1) {
19898
+ contract(cp, "A condition compares with exactly one of in, atLeast and below");
19899
+ }
19900
+ const field = fieldOf(spender, clause.field);
19901
+ if (!field || field.type === "formula") {
19902
+ contract(`${cp}.field`, `"${clause.field}" must be a field of ${spenderName}`);
19903
+ } else if (!filledBy.has(clause.field)) {
19904
+ contract(
19905
+ `${cp}.field`,
19906
+ `"${clause.field}" must be a field ${spenderName}'s host fills (its copy or local), so no caller sets what pays for it`
19907
+ );
19908
+ }
19909
+ if (typeof clause.in === "string" && !fieldOf(object3, clause.in)) {
19910
+ contract(`${cp}.in`, `"${clause.in}" is not a field of ${name}`);
19911
+ }
19912
+ if (typeof clause.in === "string") notCustomerWritten(clause.in, `${cp}.in`, "a limit");
19913
+ for (const bound of ["atLeast", "below"]) {
19914
+ const value = clause[bound];
19915
+ if (typeof value !== "string") continue;
19916
+ const limit = fieldOf(object3, value);
19917
+ if (limit?.type !== "number" || limit.many) {
19918
+ contract(`${cp}.${bound}`, `"${value}" must be a number field of ${name}`);
19919
+ }
19920
+ notCustomerWritten(value, `${cp}.${bound}`, "a limit");
19921
+ }
19922
+ });
19923
+ });
19924
+ return;
19925
+ }
19926
+ const s = allowance.spends;
19927
+ const sp = `${ap}.spends`;
19928
+ if (!object3.states) {
19929
+ contract(sp, "A spender declares states: it spends on entering a state");
19930
+ }
19931
+ const person = fieldOf(object3, s.person);
19932
+ if (person?.type !== "relation" || person.many || person.to !== "person") {
19933
+ contract(`${sp}.person`, `"${s.person}" must be a relation field (one record) to person`);
19934
+ }
19935
+ const holder = fieldOf(object3, s.holder);
19936
+ if (holder?.type !== "text" || holder.many) {
19937
+ contract(`${sp}.holder`, `"${s.holder}" must be a text field of ${name} (a holder's id)`);
19938
+ }
19939
+ const spendIn = new Set(s.spendIn);
19940
+ for (const [key, list2] of [
19941
+ ["spendIn", s.spendIn],
19942
+ ["returnIn", s.returnIn]
19943
+ ]) {
19944
+ for (const state of list2) {
19945
+ if (object3.states && !states.has(state)) {
19946
+ contract(`${sp}.${key}`, `"${state}" is not an option of ${object3.states.field}`);
19947
+ }
19948
+ if (key === "returnIn" && spendIn.has(state)) {
19949
+ contract(`${sp}.returnIn`, `"${state}" cannot both spend and return a use`);
19950
+ }
19951
+ }
19952
+ }
19953
+ const hop = (value, p) => {
19954
+ const [rel, target, extra] = value.split(".");
19955
+ if (extra !== void 0 || !rel || !target) {
19956
+ contract(p, `"${value}" must be a field of ${name} or one relation away (relation.field)`);
19957
+ return void 0;
19958
+ }
19959
+ const relation = fieldOf(object3, rel);
19960
+ if (relation?.type !== "relation" || relation.many || !relation.to) {
19961
+ contract(p, `"${rel}" must be a relation field (one record) of ${name}`);
19962
+ return void 0;
19963
+ }
19964
+ const other = ownObject(relation.to);
19965
+ if (!other) return null;
19966
+ const field = fieldOf(other[1], target);
19967
+ if (!field) contract(p, `"${target}" is not a field of ${other[0]}`);
19968
+ return field;
19969
+ };
19970
+ if (s.at !== void 0) {
19971
+ if (s.at.includes(".")) {
19972
+ const field = hop(s.at, `${sp}.at`);
19973
+ if (field && field.type !== "datetime") {
19974
+ contract(`${sp}.at`, `"${s.at}" must be a datetime field`);
19975
+ }
19976
+ } else {
19977
+ const field = fieldOf(object3, s.at);
19978
+ if (field?.type !== "datetime" || field.many) {
19979
+ contract(`${sp}.at`, `"${s.at}" must be a datetime field of ${name}`);
19980
+ }
19981
+ notCustomerWritten(s.at, `${sp}.at`, "the time a use is counted at");
19982
+ }
19983
+ }
19984
+ const filled = (local, p, type) => {
19985
+ const field = fieldOf(object3, local);
19986
+ if (!field || field.many || !field.readOnly || type && field.type !== type) {
19987
+ contract(
19988
+ p,
19989
+ `"${local}" must be a read-only ${type ? `${type} ` : ""}field of ${name}: the host fills it`
19990
+ );
19991
+ }
19992
+ };
19993
+ for (const [local, source] of Object.entries(s.copy ?? {})) {
19994
+ filled(local, `${sp}.copy.${local}`);
19995
+ if (!source.includes(".")) {
19996
+ contract(`${sp}.copy.${local}`, `"${source}" must be one relation away (relation.field)`);
19997
+ } else hop(source, `${sp}.copy.${local}`);
19998
+ }
19999
+ if (s.local) {
20000
+ if (s.local.weekday !== void 0) filled(s.local.weekday, `${sp}.local.weekday`, "number");
20001
+ if (s.local.minute !== void 0) filled(s.local.minute, `${sp}.local.minute`, "number");
20002
+ if (s.local.zone !== void 0) {
20003
+ if (s.local.zone.includes(".")) {
20004
+ const field = hop(s.local.zone, `${sp}.local.zone`);
20005
+ if (field && field.type !== "timezone") {
20006
+ contract(`${sp}.local.zone`, `"${s.local.zone}" must be a timezone field`);
20007
+ }
20008
+ } else {
20009
+ if (fieldOf(object3, s.local.zone)?.type !== "timezone") {
20010
+ contract(`${sp}.local.zone`, `"${s.local.zone}" must be a timezone field of ${name}`);
20011
+ }
20012
+ notCustomerWritten(s.local.zone, `${sp}.local.zone`, "the zone its local time is read in");
20013
+ }
20014
+ }
20015
+ }
20016
+ for (const [i, payer] of (s.paidBy ?? []).entries()) {
20017
+ if (!/^[a-z][a-z0-9]{1,29}(\.[a-z][a-z0-9]{0,29})?$/.test(payer)) {
20018
+ contract(`${sp}.paidBy.${i}`, `"${payer}" must be an extension id or <extension>.<object>`);
20019
+ }
20020
+ }
20021
+ if (s.movedFrom) {
20022
+ const rel = fieldOf(object3, s.movedFrom.field);
20023
+ if (rel?.type !== "relation" || rel.many || rel.to !== `${m.id}.${name}` && rel.to !== name) {
20024
+ contract(
20025
+ `${sp}.movedFrom.field`,
20026
+ `"${s.movedFrom.field}" must be a relation field (one record) to ${m.id}.${name}`
20027
+ );
20028
+ }
20029
+ if (!s.returnIn.includes(s.movedFrom.state)) {
20030
+ contract(
20031
+ `${sp}.movedFrom.state`,
20032
+ `"${s.movedFrom.state}" must be one of returnIn: the moved record gives its use back`
20033
+ );
20034
+ }
20035
+ if (object3.states) {
20036
+ const into = object3.states.moves.filter((move) => move.to === s.movedFrom?.state);
20037
+ if (!into.some((move) => move.by.includes("staff"))) {
20038
+ contract(
20039
+ `${sp}.movedFrom.state`,
20040
+ `A move into "${s.movedFrom.state}" by staff must be declared: staff move a record's use`
20041
+ );
20042
+ }
20043
+ }
20044
+ }
20045
+ }
20046
+
19723
20047
  // ../sdk/src/contract.ts
19724
20048
  var CONTRACT_VERSION = 1;
19725
20049
  var SUPPORTED_CONTRACT_VERSIONS = [CONTRACT_VERSION];
@@ -19799,7 +20123,7 @@ var valueMatchSchema = external_exports.union([
19799
20123
  external_exports.object({ stageType: external_exports.enum(["open", "won", "lost"]) }).strict()
19800
20124
  ]);
19801
20125
  var objectName = external_exports.string().min(1).max(80);
19802
- var fieldName = external_exports.string().min(1).max(80);
20126
+ var fieldName2 = external_exports.string().min(1).max(80);
19803
20127
  var automationTriggerSchema = external_exports.discriminatedUnion("type", [
19804
20128
  external_exports.object({
19805
20129
  type: external_exports.literal("record"),
@@ -19810,7 +20134,7 @@ var automationTriggerSchema = external_exports.discriminatedUnion("type", [
19810
20134
  external_exports.object({
19811
20135
  type: external_exports.literal("fieldChanged"),
19812
20136
  object: objectName,
19813
- field: fieldName,
20137
+ field: fieldName2,
19814
20138
  from: valueMatchSchema.optional(),
19815
20139
  to: valueMatchSchema.optional(),
19816
20140
  includeBulk: external_exports.boolean().optional()
@@ -19819,9 +20143,9 @@ var automationTriggerSchema = external_exports.discriminatedUnion("type", [
19819
20143
  external_exports.object({
19820
20144
  type: external_exports.literal("dateRelative"),
19821
20145
  object: objectName,
19822
- field: fieldName,
20146
+ field: fieldName2,
19823
20147
  offsetDays: external_exports.number().int().min(-365).max(365),
19824
- zoneField: fieldName.optional()
20148
+ zoneField: fieldName2.optional()
19825
20149
  }).strict(),
19826
20150
  external_exports.object({
19827
20151
  type: external_exports.literal("manual"),
@@ -19858,8 +20182,8 @@ var durationSchema = external_exports.union([
19858
20182
  var recipientSchema = external_exports.union([
19859
20183
  external_exports.literal("admins"),
19860
20184
  external_exports.literal("actor"),
19861
- external_exports.object({ field: fieldName }).strict(),
19862
- external_exports.object({ managerOf: fieldName }).strict(),
20185
+ external_exports.object({ field: fieldName2 }).strict(),
20186
+ external_exports.object({ managerOf: fieldName2 }).strict(),
19863
20187
  external_exports.object({ userId: external_exports.string().min(1).max(64) }).strict()
19864
20188
  ]);
19865
20189
  var writeIntentSchema = external_exports.object({
@@ -19926,7 +20250,7 @@ var filterOpSchema = external_exports.enum([
19926
20250
  ]);
19927
20251
  var automationConditionSchema = external_exports.lazy(
19928
20252
  () => external_exports.union([
19929
- external_exports.object({ field: fieldName, op: filterOpSchema, value: external_exports.unknown().optional() }).strict(),
20253
+ external_exports.object({ field: fieldName2, op: filterOpSchema, value: external_exports.unknown().optional() }).strict(),
19930
20254
  external_exports.object({ and: external_exports.array(automationConditionSchema).min(1).max(20) }).strict(),
19931
20255
  external_exports.object({ or: external_exports.array(automationConditionSchema).min(1).max(20) }).strict()
19932
20256
  ])
@@ -20164,7 +20488,7 @@ function filterFields(filter) {
20164
20488
  var isStageType = (match) => typeof match === "object" && match !== null && "stageType" in match;
20165
20489
  function checkAutomation(ctx, name, automation) {
20166
20490
  const m = ctx.manifest;
20167
- const path = `automations.${name}`;
20491
+ const path2 = `automations.${name}`;
20168
20492
  const { contract } = ctx;
20169
20493
  const perms = m.permissions;
20170
20494
  const own2 = (object4) => object4.startsWith(`${m.id}.`);
@@ -20176,17 +20500,17 @@ function checkAutomation(ctx, name, automation) {
20176
20500
  const fields = object3 && (ctx.known.has(object3) || base) ? fieldsOf(ctx, object3) : null;
20177
20501
  const ofType = (types) => Object.entries(fields ?? {}).filter(([, type]) => types.includes(type)).map(([field]) => field);
20178
20502
  if (!NAME_RE.test(name)) {
20179
- contract(path, `Automation name "${name}" must be camelCase letters and digits, e.g. wonDeal`);
20503
+ contract(path2, `Automation name "${name}" must be camelCase letters and digits, e.g. wonDeal`);
20180
20504
  }
20181
20505
  if (base && !perms.operations.includes(`${object3}.get`)) {
20182
20506
  contract(
20183
- `${path}.trigger.object`,
20507
+ `${path2}.trigger.object`,
20184
20508
  `An automation started by ${object3} reads it: add "${object3}.get" to permissions.operations`
20185
20509
  );
20186
20510
  }
20187
20511
  if (object3 !== null && !ctx.known.has(object3) && !base) {
20188
20512
  contract(
20189
- `${path}.trigger.object`,
20513
+ `${path2}.trigger.object`,
20190
20514
  `Unknown object "${object3}". Use a core object (person, organisation, task, activity) or <extension>.<object>`
20191
20515
  );
20192
20516
  }
@@ -20205,34 +20529,34 @@ function checkAutomation(ctx, name, automation) {
20205
20529
  switch (trigger.type) {
20206
20530
  case "record":
20207
20531
  if (new Set(trigger.on).size !== trigger.on.length) {
20208
- contract(`${path}.trigger.on`, "List each record event once");
20532
+ contract(`${path2}.trigger.on`, "List each record event once");
20209
20533
  }
20210
20534
  break;
20211
20535
  case "fieldChanged": {
20212
- requireField(`${path}.trigger.field`, trigger.field);
20536
+ requireField(`${path2}.trigger.field`, trigger.field);
20213
20537
  if (isStageType(trigger.from) || isStageType(trigger.to)) {
20214
20538
  const stages = own2(trigger.object) ? m.objects[trigger.object.slice(m.id.length + 1)]?.stages : void 0;
20215
20539
  if (own2(trigger.object) && stages?.field !== trigger.field) {
20216
20540
  contract(
20217
- `${path}.trigger`,
20541
+ `${path2}.trigger`,
20218
20542
  stages ? `{ stageType } compares the stage's type, so the field must be "${stages.field}" (the stage field of ${trigger.object})` : `${trigger.object} has no stage behaviour (objects.<name>.stages); compare values instead of { stageType }`
20219
20543
  );
20220
20544
  } else if (!own2(trigger.object) && CORE_AUTOMATION_FIELDS[trigger.object]) {
20221
- contract(`${path}.trigger`, `${trigger.object} has no stages; compare values instead`);
20545
+ contract(`${path2}.trigger`, `${trigger.object} has no stages; compare values instead`);
20222
20546
  }
20223
20547
  }
20224
20548
  if (trigger.from !== void 0 && trigger.to !== void 0 && JSON.stringify(trigger.from) === JSON.stringify(trigger.to)) {
20225
- contract(`${path}.trigger`, "from and to are the same, so the trigger never fires");
20549
+ contract(`${path2}.trigger`, "from and to are the same, so the trigger never fires");
20226
20550
  }
20227
20551
  break;
20228
20552
  }
20229
20553
  case "schedule":
20230
- for (const issue2 of cronIssues(trigger.cron)) contract(`${path}.trigger.cron`, issue2);
20554
+ for (const issue2 of cronIssues(trigger.cron)) contract(`${path2}.trigger.cron`, issue2);
20231
20555
  break;
20232
20556
  case "dateRelative":
20233
- requireField(`${path}.trigger.field`, trigger.field, ["date", "datetime"]);
20557
+ requireField(`${path2}.trigger.field`, trigger.field, ["date", "datetime"]);
20234
20558
  if (trigger.zoneField !== void 0) {
20235
- requireField(`${path}.trigger.zoneField`, trigger.zoneField, ["timezone"]);
20559
+ requireField(`${path2}.trigger.zoneField`, trigger.zoneField, ["timezone"]);
20236
20560
  }
20237
20561
  break;
20238
20562
  case "manual":
@@ -20240,17 +20564,17 @@ function checkAutomation(ctx, name, automation) {
20240
20564
  case "approvalDecided":
20241
20565
  if (trigger.operation !== void 0 && !OPERATION_RE.test(trigger.operation)) {
20242
20566
  contract(
20243
- `${path}.trigger.operation`,
20567
+ `${path2}.trigger.operation`,
20244
20568
  `"${trigger.operation}" is not an operation name, e.g. record.update`
20245
20569
  );
20246
20570
  }
20247
20571
  if (trigger.object !== void 0 && !ctx.known.has(trigger.object)) {
20248
- contract(`${path}.trigger.object`, `Unknown object "${trigger.object}"`);
20572
+ contract(`${path2}.trigger.object`, `Unknown object "${trigger.object}"`);
20249
20573
  }
20250
20574
  break;
20251
20575
  case "webhook":
20252
20576
  if (trigger.events && new Set(trigger.events).size !== trigger.events.length) {
20253
- contract(`${path}.trigger.events`, "List each event type once");
20577
+ contract(`${path2}.trigger.events`, "List each event type once");
20254
20578
  }
20255
20579
  break;
20256
20580
  case "syncEvent":
@@ -20264,7 +20588,7 @@ function checkAutomation(ctx, name, automation) {
20264
20588
  }
20265
20589
  const slots = /* @__PURE__ */ new Set();
20266
20590
  (automation.connections ?? []).forEach((connection, i) => {
20267
- const at = `${path}.connections.${i}`;
20591
+ const at = `${path2}.connections.${i}`;
20268
20592
  if (!NAME_RE.test(connection.id)) {
20269
20593
  contract(`${at}.id`, `Connection id "${connection.id}" must be camelCase, e.g. mailbox`);
20270
20594
  }
@@ -20282,14 +20606,14 @@ function checkAutomation(ctx, name, automation) {
20282
20606
  if (automation.conditions) {
20283
20607
  if (!object3) {
20284
20608
  contract(
20285
- `${path}.conditions`,
20609
+ `${path2}.conditions`,
20286
20610
  `conditions filter the trigger record, and a ${trigger.type} trigger has none; check inside run instead (and declare a condition step for the diagram)`
20287
20611
  );
20288
20612
  } else if (fields) {
20289
20613
  for (const field of new Set(filterFields(automation.conditions))) {
20290
20614
  if (!Object.hasOwn(fields, field) && field !== "id") {
20291
20615
  contract(
20292
- `${path}.conditions`,
20616
+ `${path2}.conditions`,
20293
20617
  `Condition field "${field}" is not a field of ${object3} (fields: ${list(Object.keys(fields))})`
20294
20618
  );
20295
20619
  }
@@ -20319,7 +20643,7 @@ function checkAutomation(ctx, name, automation) {
20319
20643
  const names = /* @__PURE__ */ new Map();
20320
20644
  let waitMs = 0;
20321
20645
  automation.steps.forEach((step, i) => {
20322
- const at = `${path}.steps.${i}`;
20646
+ const at = `${path2}.steps.${i}`;
20323
20647
  if (!NAME_RE.test(step.name)) {
20324
20648
  contract(`${at}.name`, `Step name "${step.name}" must be camelCase, e.g. createTasks`);
20325
20649
  }
@@ -20396,14 +20720,14 @@ function checkAutomation(ctx, name, automation) {
20396
20720
  });
20397
20721
  if (waitMs > MAX_TOTAL_WAIT_DAYS * DAY_MS) {
20398
20722
  contract(
20399
- `${path}.steps`,
20723
+ `${path2}.steps`,
20400
20724
  `The waits add up to ${Math.round(waitMs / DAY_MS)} days; one run may wait at most ${MAX_TOTAL_WAIT_DAYS} days in total (sleeps plus waitForEvent timeouts, default ${DEFAULT_WAIT_TIMEOUT})`
20401
20725
  );
20402
20726
  }
20403
20727
  const onRejected = automation.onRejected;
20404
20728
  if (onRejected && typeof onRejected === "object") {
20405
20729
  notifies = true;
20406
- checkRecipient(`${path}.onRejected.notify`, onRejected.notify);
20730
+ checkRecipient(`${path2}.onRejected.notify`, onRejected.notify);
20407
20731
  }
20408
20732
  if (notifies && !perms.operations.includes(NOTIFY_OPERATION)) {
20409
20733
  contract(
@@ -20423,10 +20747,10 @@ function safeDuration(duration3) {
20423
20747
  // ../sdk/src/capacity.ts
20424
20748
  var CAPACITY_SHOW = ["exact", "low", "availability"];
20425
20749
  var CAPACITY_VALUES = ["held", "taken", "available"];
20426
- var fieldName2 = external_exports.string().max(40);
20750
+ var fieldName3 = external_exports.string().max(40);
20427
20751
  var capacityManifestSchema = external_exports.object({
20428
- places: fieldName2,
20429
- pool: fieldName2.optional(),
20752
+ places: fieldName3,
20753
+ pool: fieldName3.optional(),
20430
20754
  show: external_exports.enum(CAPACITY_SHOW).optional(),
20431
20755
  lowAt: external_exports.number().int().min(1).max(1e6).optional(),
20432
20756
  releaseOnRefund: external_exports.boolean().optional()
@@ -20434,11 +20758,11 @@ var capacityManifestSchema = external_exports.object({
20434
20758
  function checkObjectCapacity(m, name, object3, contract) {
20435
20759
  const capacity = object3.capacity;
20436
20760
  if (!capacity) return;
20437
- const path = `objects.${name}.capacity`;
20761
+ const path2 = `objects.${name}.capacity`;
20438
20762
  const fieldOf = (local) => Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
20439
20763
  const places = fieldOf(capacity.places);
20440
20764
  if (places?.type !== "number" || places.many) {
20441
- contract(`${path}.places`, `"${capacity.places}" must be a number field of ${name}`);
20765
+ contract(`${path2}.places`, `"${capacity.places}" must be a number field of ${name}`);
20442
20766
  }
20443
20767
  for (const reserved of CAPACITY_VALUES) {
20444
20768
  if (Object.hasOwn(object3.fields, reserved)) {
@@ -20455,26 +20779,82 @@ function checkObjectCapacity(m, name, object3, contract) {
20455
20779
  const targetObject = local !== void 0 && Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
20456
20780
  if (!targetObject) {
20457
20781
  contract(
20458
- `${path}.pool`,
20782
+ `${path2}.pool`,
20459
20783
  `"${capacity.pool}" must be a relation field (one record) to another of this extension's objects`
20460
20784
  );
20461
20785
  } else if (local === name) {
20462
- contract(`${path}.pool`, "An object cannot be its own pool");
20786
+ contract(`${path2}.pool`, "An object cannot be its own pool");
20463
20787
  } else if (!targetObject.capacity) {
20464
- contract(`${path}.pool`, `The pool's object ${target} must declare a capacity`);
20788
+ contract(`${path2}.pool`, `The pool's object ${target} must declare a capacity`);
20465
20789
  } else if (targetObject.capacity.pool !== void 0) {
20466
20790
  contract(
20467
- `${path}.pool`,
20791
+ `${path2}.pool`,
20468
20792
  `The pool's object ${target} has a pool of its own; capacity has one level of pool`
20469
20793
  );
20470
20794
  }
20471
20795
  }
20472
20796
  if (capacity.lowAt !== void 0 && capacity.show !== "low") {
20473
- contract(`${path}.lowAt`, 'lowAt is the threshold of show: "low"');
20797
+ contract(`${path2}.lowAt`, 'lowAt is the threshold of show: "low"');
20474
20798
  }
20475
20799
  if (capacity.show === "low" && capacity.lowAt === void 0) {
20476
- contract(`${path}.lowAt`, 'show: "low" needs lowAt, the number at or below which it says so');
20800
+ contract(`${path2}.lowAt`, 'show: "low" needs lowAt, the number at or below which it says so');
20801
+ }
20802
+ }
20803
+ var claimsManifestSchema = external_exports.object({
20804
+ on: fieldName3,
20805
+ held: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional(),
20806
+ confirmed: external_exports.array(external_exports.string().min(1).max(100)).max(20).optional()
20807
+ }).strict();
20808
+ function checkObjectClaims(m, name, object3, contract) {
20809
+ const claims = object3.claims;
20810
+ if (!claims) return;
20811
+ const path2 = `objects.${name}.claims`;
20812
+ const on = Object.hasOwn(object3.fields, claims.on) ? object3.fields[claims.on] : void 0;
20813
+ const target = on?.type === "relation" && !on.many ? on.to : void 0;
20814
+ const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : void 0;
20815
+ const targetObject = local !== void 0 && Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
20816
+ if (!targetObject || local === name) {
20817
+ contract(
20818
+ `${path2}.on`,
20819
+ `"${claims.on}" must be a relation field (one record) to another of this extension's objects`
20820
+ );
20821
+ } else if (!targetObject.capacity) {
20822
+ contract(`${path2}.on`, `${target} must declare a capacity for its places to be claimed`);
20823
+ }
20824
+ const held = claims.held ?? [];
20825
+ const confirmed = claims.confirmed ?? [];
20826
+ if (!held.length && !confirmed.length) {
20827
+ contract(path2, "Name the states that hold a place (held) or take one (confirmed)");
20477
20828
  }
20829
+ const states = object3.states;
20830
+ if (!states) {
20831
+ contract(path2, `${name} must declare states: its states hold and release the claim`);
20832
+ return;
20833
+ }
20834
+ const field = Object.hasOwn(object3.fields, states.field) ? object3.fields[states.field] : void 0;
20835
+ const values = new Set((field?.options ?? []).map((o) => o.value));
20836
+ for (const [key, list2] of [
20837
+ ["held", held],
20838
+ ["confirmed", confirmed]
20839
+ ]) {
20840
+ if (new Set(list2).size !== list2.length) contract(`${path2}.${key}`, "List each state once");
20841
+ for (const state of list2) {
20842
+ if (!values.has(state)) contract(`${path2}.${key}`, `"${state}" is not a state of ${name}`);
20843
+ }
20844
+ }
20845
+ const both = held.filter((state) => confirmed.includes(state));
20846
+ if (both.length) {
20847
+ contract(path2, `"${both[0]}" cannot both hold and take a place`);
20848
+ }
20849
+ states.moves.forEach((move, i) => {
20850
+ const from = typeof move.from === "string" ? [move.from] : move.from;
20851
+ if (held.includes(move.to) && from.some((state) => confirmed.includes(state))) {
20852
+ contract(
20853
+ `objects.${name}.states.moves.${i}`,
20854
+ `A move from a state that takes a place cannot go back to one that only holds it ("${move.to}")`
20855
+ );
20856
+ }
20857
+ });
20478
20858
  }
20479
20859
 
20480
20860
  // ../sdk/src/document.ts
@@ -20520,8 +20900,8 @@ function documentBytes(value) {
20520
20900
  }
20521
20901
  function checkDocumentSchema(schema, knownObjects) {
20522
20902
  const problems = [];
20523
- const add = (path, message) => {
20524
- if (problems.length < 50) problems.push([path, message]);
20903
+ const add = (path2, message) => {
20904
+ if (problems.length < 50) problems.push([path2, message]);
20525
20905
  };
20526
20906
  if (!isObject2(schema)) {
20527
20907
  add("", "A document schema is an object with a `root` object node");
@@ -20535,13 +20915,13 @@ function checkDocumentSchema(schema, knownObjects) {
20535
20915
  for (const name of Object.keys(defs)) {
20536
20916
  if (!KEY_RE.test(name)) add(`defs.${name}`, "A definition's name is camelCase");
20537
20917
  }
20538
- const node2 = (path, value, depth, inFields) => {
20918
+ const node2 = (path2, value, depth, inFields) => {
20539
20919
  if (depth > DOCUMENT_MAX_DEPTH) {
20540
- add(path, `The schema nests deeper than ${DOCUMENT_MAX_DEPTH}`);
20920
+ add(path2, `The schema nests deeper than ${DOCUMENT_MAX_DEPTH}`);
20541
20921
  return;
20542
20922
  }
20543
20923
  if (!isObject2(value)) {
20544
- add(path, "A node is an object with a `type`");
20924
+ add(path2, "A node is an object with a `type`");
20545
20925
  return;
20546
20926
  }
20547
20927
  const allowed = /* @__PURE__ */ new Set(["type", "description", "optional"]);
@@ -20549,45 +20929,48 @@ function checkDocumentSchema(schema, knownObjects) {
20549
20929
  for (const key of keys) allowed.add(key);
20550
20930
  };
20551
20931
  if (value.optional !== void 0 && (typeof value.optional !== "boolean" || !inFields)) {
20552
- add(`${path}.optional`, "optional is true or false, on a field of an object");
20932
+ add(`${path2}.optional`, "optional is true or false, on a field of an object");
20553
20933
  }
20554
20934
  if (value.description !== void 0 && typeof value.description !== "string") {
20555
- add(`${path}.description`, "description is text");
20935
+ add(`${path2}.description`, "description is text");
20556
20936
  }
20557
20937
  const num = (key, opts = {}) => {
20558
20938
  const v = value[key];
20559
20939
  if (v === void 0) return void 0;
20560
20940
  if (typeof v !== "number" || !Number.isFinite(v) || opts.int && !Number.isInteger(v)) {
20561
- add(`${path}.${key}`, `${key} is ${opts.int ? "a whole number" : "a number"}`);
20941
+ add(`${path2}.${key}`, `${key} is ${opts.int ? "a whole number" : "a number"}`);
20562
20942
  return void 0;
20563
20943
  }
20564
20944
  if (opts.min !== void 0 && v < opts.min)
20565
- add(`${path}.${key}`, `${key} is at least ${opts.min}`);
20945
+ add(`${path2}.${key}`, `${key} is at least ${opts.min}`);
20566
20946
  if (opts.max !== void 0 && v > opts.max)
20567
- add(`${path}.${key}`, `${key} is at most ${opts.max}`);
20947
+ add(`${path2}.${key}`, `${key} is at most ${opts.max}`);
20568
20948
  return v;
20569
20949
  };
20570
20950
  switch (value.type) {
20571
20951
  case "object": {
20572
- expect("fields", "private");
20573
- object3(path, value, depth);
20952
+ expect("fields", "private", "holders");
20953
+ object3(path2, value, depth);
20574
20954
  break;
20575
20955
  }
20576
20956
  case "array": {
20577
- expect("of", "max", "min", "unique");
20957
+ expect("of", "max", "min", "unique", "uniqueAcross");
20958
+ if (value.uniqueAcross !== void 0 && (value.uniqueAcross !== true || !value.unique)) {
20959
+ add(`${path2}.uniqueAcross`, "uniqueAcross is true, beside unique");
20960
+ }
20578
20961
  const max = num("max", { int: true, min: 1, max: DOCUMENT_MAX_LIST });
20579
- if (value.max === void 0) add(`${path}.max`, "A list declares its most entries (max)");
20962
+ if (value.max === void 0) add(`${path2}.max`, "A list declares its most entries (max)");
20580
20963
  const min = num("min", { int: true, min: 0 });
20581
20964
  if (min !== void 0 && max !== void 0 && min > max)
20582
- add(`${path}.min`, "min is above max");
20583
- node2(`${path}.of`, value.of, depth + 1, false);
20965
+ add(`${path2}.min`, "min is above max");
20966
+ node2(`${path2}.of`, value.of, depth + 1, false);
20584
20967
  if (value.unique !== void 0) {
20585
20968
  const of = resolve(value.of);
20586
20969
  const shapes = of?.type === "object" ? [of] : of?.type === "union" ? Object.values(of.variants ?? {}) : [];
20587
20970
  const keyNodes = shapes.map((shape) => resolve(shape.fields?.[String(value.unique)]));
20588
20971
  if (typeof value.unique !== "string" || !keyNodes.length || keyNodes.some((n) => !n || !["text", "number", "choice", "ref"].includes(n.type))) {
20589
20972
  add(
20590
- `${path}.unique`,
20973
+ `${path2}.unique`,
20591
20974
  "unique names a text, number, choice or ref key of the listed objects"
20592
20975
  );
20593
20976
  }
@@ -20597,20 +20980,20 @@ function checkDocumentSchema(schema, knownObjects) {
20597
20980
  case "text": {
20598
20981
  expect("max", "min", "multiline", "chars", "noMarkup", "href");
20599
20982
  if (value.noMarkup !== void 0 && typeof value.noMarkup !== "boolean") {
20600
- add(`${path}.noMarkup`, "noMarkup is true or false");
20983
+ add(`${path2}.noMarkup`, "noMarkup is true or false");
20601
20984
  }
20602
20985
  if (value.href !== void 0 && value.href !== "web" && value.href !== "link") {
20603
- add(`${path}.href`, "href is web or link");
20986
+ add(`${path2}.href`, "href is web or link");
20604
20987
  }
20605
20988
  const max = num("max", { int: true, min: 1, max: DOCUMENT_MAX_TEXT });
20606
20989
  const min = num("min", { int: true, min: 0 });
20607
20990
  if (min !== void 0 && (max ?? DOCUMENT_DEFAULT_TEXT) < min)
20608
- add(`${path}.min`, "min is above max");
20991
+ add(`${path2}.min`, "min is above max");
20609
20992
  if (value.multiline !== void 0 && typeof value.multiline !== "boolean") {
20610
- add(`${path}.multiline`, "multiline is true or false");
20993
+ add(`${path2}.multiline`, "multiline is true or false");
20611
20994
  }
20612
20995
  if (value.chars !== void 0 && (typeof value.chars !== "string" || !value.chars.length || value.chars.length > 200)) {
20613
- add(`${path}.chars`, "chars is the allowed characters, 1 to 200 of them");
20996
+ add(`${path2}.chars`, "chars is the allowed characters, 1 to 200 of them");
20614
20997
  }
20615
20998
  break;
20616
20999
  }
@@ -20619,12 +21002,12 @@ function checkDocumentSchema(schema, knownObjects) {
20619
21002
  const min = num("min");
20620
21003
  const max = num("max");
20621
21004
  if (min !== void 0 && max !== void 0 && min > max)
20622
- add(`${path}.min`, "min is above max");
21005
+ add(`${path2}.min`, "min is above max");
20623
21006
  if (value.integer !== void 0 && typeof value.integer !== "boolean") {
20624
- add(`${path}.integer`, "integer is true or false");
21007
+ add(`${path2}.integer`, "integer is true or false");
20625
21008
  }
20626
21009
  const step = num("step");
20627
- if (step !== void 0 && step <= 0) add(`${path}.step`, "step is above 0");
21010
+ if (step !== void 0 && step <= 0) add(`${path2}.step`, "step is above 0");
20628
21011
  break;
20629
21012
  }
20630
21013
  case "boolean":
@@ -20633,32 +21016,38 @@ function checkDocumentSchema(schema, knownObjects) {
20633
21016
  expect("options");
20634
21017
  const options = value.options;
20635
21018
  if (!Array.isArray(options) || !options.length || options.length > 100 || options.some((o) => typeof o !== "string" || !o.length || o.length > 100)) {
20636
- add(`${path}.options`, "A choice lists 1 to 100 words");
21019
+ add(`${path2}.options`, "A choice lists 1 to 100 words");
20637
21020
  } else if (new Set(options).size !== options.length) {
20638
- add(`${path}.options`, "A choice lists each word once");
21021
+ add(`${path2}.options`, "A choice lists each word once");
20639
21022
  }
20640
21023
  break;
20641
21024
  }
20642
21025
  case "ref": {
20643
- expect("to");
21026
+ expect("to", "media");
20644
21027
  if (typeof value.to !== "string" || !OBJECT_RE.test(value.to)) {
20645
- add(`${path}.to`, "A ref names an object: `<extension>.<object>` or a core object");
21028
+ add(`${path2}.to`, "A ref names an object: `<extension>.<object>` or a core object");
20646
21029
  } else if (knownObjects && !knownObjects.has(value.to)) {
20647
- add(`${path}.to`, `Unknown object "${value.to}"`);
21030
+ add(`${path2}.to`, `Unknown object "${value.to}"`);
21031
+ }
21032
+ if (value.media !== void 0) {
21033
+ if (value.to !== "media") add(`${path2}.media`, "media is for a ref to media");
21034
+ else if (!["image", "video", "file"].includes(String(value.media))) {
21035
+ add(`${path2}.media`, "media is image, video or file");
21036
+ }
20648
21037
  }
20649
21038
  break;
20650
21039
  }
20651
21040
  case "union": {
20652
21041
  expect("tag", "variants");
20653
21042
  if (typeof value.tag !== "string" || !KEY_RE.test(value.tag)) {
20654
- add(`${path}.tag`, "A union's tag is a camelCase key");
21043
+ add(`${path2}.tag`, "A union's tag is a camelCase key");
20655
21044
  }
20656
21045
  if (!isObject2(value.variants) || !Object.keys(value.variants).length) {
20657
- add(`${path}.variants`, "A union has at least one variant");
21046
+ add(`${path2}.variants`, "A union has at least one variant");
20658
21047
  break;
20659
21048
  }
20660
21049
  for (const [name, variant] of Object.entries(value.variants)) {
20661
- const vp = `${path}.variants.${name}`;
21050
+ const vp = `${path2}.variants.${name}`;
20662
21051
  if (!name.length || name.length > 100) add(vp, "A variant's name is 1 to 100 characters");
20663
21052
  if (!isObject2(variant) || variant.type !== "object") {
20664
21053
  add(vp, "A variant is an object node");
@@ -20677,39 +21066,56 @@ function checkDocumentSchema(schema, knownObjects) {
20677
21066
  case "use": {
20678
21067
  expect("def");
20679
21068
  if (typeof value.def !== "string" || !Object.hasOwn(defs, value.def)) {
20680
- add(`${path}.def`, `"${String(value.def)}" is not one of the schema's defs`);
21069
+ add(`${path2}.def`, `"${String(value.def)}" is not one of the schema's defs`);
20681
21070
  }
20682
21071
  break;
20683
21072
  }
20684
21073
  default:
20685
21074
  add(
20686
- `${path}.type`,
21075
+ `${path2}.type`,
20687
21076
  "type is one of object, array, text, number, boolean, choice, ref, union, use"
20688
21077
  );
20689
21078
  return;
20690
21079
  }
20691
21080
  for (const key of Object.keys(value)) {
20692
21081
  if (!allowed.has(key))
20693
- add(`${path}.${key}`, `Unknown key "${key}" on a ${String(value.type)} node`);
21082
+ add(`${path2}.${key}`, `Unknown key "${key}" on a ${String(value.type)} node`);
20694
21083
  }
20695
21084
  };
20696
- const object3 = (path, value, depth) => {
21085
+ const object3 = (path2, value, depth) => {
20697
21086
  if (!isObject2(value.fields)) {
20698
- add(`${path}.fields`, "An object node lists its fields");
21087
+ add(`${path2}.fields`, "An object node lists its fields");
20699
21088
  return;
20700
21089
  }
20701
21090
  const keys = Object.keys(value.fields);
20702
- if (keys.length > 100) add(`${path}.fields`, "An object has at most 100 fields");
21091
+ if (keys.length > 100) add(`${path2}.fields`, "An object has at most 100 fields");
20703
21092
  for (const key of keys) {
20704
- if (!KEY_RE.test(key)) add(`${path}.fields.${key}`, "A field's key is camelCase");
20705
- node2(`${path}.fields.${key}`, value.fields[key], depth + 1, true);
21093
+ if (!KEY_RE.test(key)) add(`${path2}.fields.${key}`, "A field's key is camelCase");
21094
+ node2(`${path2}.fields.${key}`, value.fields[key], depth + 1, true);
20706
21095
  }
20707
21096
  const priv = value.private;
20708
21097
  if (priv !== void 0 && priv !== true) {
20709
21098
  const unless = isObject2(priv) ? priv.unless : void 0;
20710
21099
  const flag = typeof unless === "string" ? value.fields[unless] : void 0;
20711
21100
  if (!isObject2(flag) || flag.type !== "boolean") {
20712
- add(`${path}.private`, "private is true, or { unless: <a boolean key of this object> }");
21101
+ add(`${path2}.private`, "private is true, or { unless: <a boolean key of this object> }");
21102
+ }
21103
+ }
21104
+ const holders = value.holders;
21105
+ if (holders !== void 0 && holders !== true) {
21106
+ const fields = value.fields;
21107
+ const shape = isObject2(holders) ? holders : null;
21108
+ const unless = shape?.unless;
21109
+ const keys2 = shape?.keys;
21110
+ const flag = typeof unless === "string" ? fields[unless] : void 0;
21111
+ const badUnless = unless !== void 0 && (!isObject2(flag) || flag.type !== "boolean");
21112
+ const badKeys = keys2 !== void 0 && (!Array.isArray(keys2) || !keys2.length || keys2.some((k) => typeof k !== "string" || !Object.hasOwn(fields, k) || k === unless));
21113
+ const extra = shape ? Object.keys(shape).filter((k) => k !== "unless" && k !== "keys") : [];
21114
+ if (!shape || unless === void 0 && keys2 === void 0 || badUnless || badKeys || extra.length) {
21115
+ add(
21116
+ `${path2}.holders`,
21117
+ "holders is true, { unless: <a boolean key> } or { keys: [<keys of this object>], unless? }"
21118
+ );
20713
21119
  }
20714
21120
  }
20715
21121
  };
@@ -20743,6 +21149,9 @@ function documentPathNode(schema, spec) {
20743
21149
  const at = useOf(schema, current);
20744
21150
  if (at?.type !== "object")
20745
21151
  return `"${spec.path}" passes through something that is not an object`;
21152
+ if (at.holders && (at.holders === true || !at.holders.keys || at.holders.keys.includes(key))) {
21153
+ return `"${spec.path}" is in a part for holders only, which a column cannot keep from others`;
21154
+ }
20746
21155
  current = at.fields[key];
20747
21156
  if (!current) return `"${spec.path}" is not in the schema (no "${key}")`;
20748
21157
  }
@@ -20764,10 +21173,10 @@ function documentPathNode(schema, spec) {
20764
21173
  return `"${spec.path}" is not a text, number, boolean, choice or ref (use count for a list)`;
20765
21174
  }
20766
21175
  }
20767
- function documentJsonPath(path) {
20768
- if (!path.split(".").every((key) => KEY_RE.test(key)))
20769
- throw new Error(`Bad document path ${path}`);
20770
- return `$.${path}`;
21176
+ function documentJsonPath(path2) {
21177
+ if (!path2.split(".").every((key) => KEY_RE.test(key)))
21178
+ throw new Error(`Bad document path ${path2}`);
21179
+ return `$.${path2}`;
20771
21180
  }
20772
21181
  function useOf(schema, node2) {
20773
21182
  let current = node2;
@@ -20791,86 +21200,101 @@ function validateDocument(schema, value, options = {}) {
20791
21200
  };
20792
21201
  }
20793
21202
  const issues = [];
20794
- const fault = (path, message) => {
20795
- if (issues.length < DOCUMENT_MAX_ISSUES) issues.push({ path: [...path], message });
21203
+ const acrossLists = /* @__PURE__ */ new Map();
21204
+ const fault = (path2, message) => {
21205
+ if (issues.length < DOCUMENT_MAX_ISSUES) issues.push({ path: [...path2], message });
20796
21206
  };
20797
- const walk = (node2, v, path, depth) => {
21207
+ const walk = (node2, v, path2, depth) => {
20798
21208
  if (issues.length >= DOCUMENT_MAX_ISSUES) return;
20799
21209
  if (depth > DOCUMENT_MAX_DEPTH) {
20800
- fault(path, `Nested deeper than ${DOCUMENT_MAX_DEPTH}`);
21210
+ fault(path2, `Nested deeper than ${DOCUMENT_MAX_DEPTH}`);
20801
21211
  return;
20802
21212
  }
20803
21213
  switch (node2.type) {
20804
21214
  case "use": {
20805
21215
  const target = useOf(schema, node2);
20806
- if (!target) fault(path, `The schema's definition "${node2.def}" is missing`);
20807
- else walk(target, v, path, depth);
21216
+ if (!target) fault(path2, `The schema's definition "${node2.def}" is missing`);
21217
+ else walk(target, v, path2, depth);
20808
21218
  return;
20809
21219
  }
20810
21220
  case "object":
20811
- objectValue(node2, v, path, depth, null);
21221
+ objectValue(node2, v, path2, depth, null);
20812
21222
  return;
20813
21223
  case "union": {
20814
21224
  if (!isObject2(v)) {
20815
- fault(path, `Expected an object with "${node2.tag}"`);
21225
+ fault(path2, `Expected an object with "${node2.tag}"`);
20816
21226
  return;
20817
21227
  }
20818
21228
  const tag = v[node2.tag];
20819
21229
  const variant = typeof tag === "string" && Object.hasOwn(node2.variants, tag) ? node2.variants[tag] : void 0;
20820
21230
  if (!variant) {
20821
- fault([...path, node2.tag], `Expected one of ${Object.keys(node2.variants).join(", ")}`);
21231
+ fault([...path2, node2.tag], `Expected one of ${Object.keys(node2.variants).join(", ")}`);
20822
21232
  return;
20823
21233
  }
20824
- objectValue(variant, v, path, depth, node2.tag);
21234
+ objectValue(variant, v, path2, depth, node2.tag);
20825
21235
  return;
20826
21236
  }
20827
21237
  case "array": {
20828
21238
  if (!Array.isArray(v)) {
20829
- fault(path, "Expected a list");
21239
+ fault(path2, "Expected a list");
20830
21240
  return;
20831
21241
  }
20832
- if (v.length > node2.max) fault(path, `At most ${node2.max} entries (this has ${v.length})`);
21242
+ if (v.length > node2.max) fault(path2, `At most ${node2.max} entries (this has ${v.length})`);
20833
21243
  if (node2.min !== void 0 && v.length < node2.min) {
20834
- fault(path, `At least ${node2.min} ${node2.min === 1 ? "entry" : "entries"}`);
21244
+ fault(path2, `At least ${node2.min} ${node2.min === 1 ? "entry" : "entries"}`);
20835
21245
  }
20836
21246
  const seen = /* @__PURE__ */ new Map();
21247
+ let across = node2.uniqueAcross ? acrossLists.get(node2) : void 0;
21248
+ if (node2.uniqueAcross && !across) {
21249
+ across = /* @__PURE__ */ new Map();
21250
+ acrossLists.set(node2, across);
21251
+ }
20837
21252
  v.slice(0, node2.max).forEach((item, i) => {
20838
- walk(node2.of, item, [...path, i], depth + 1);
21253
+ walk(node2.of, item, [...path2, i], depth + 1);
20839
21254
  if (node2.unique && isObject2(item) && item[node2.unique] !== void 0) {
20840
21255
  const key = JSON.stringify(item[node2.unique]);
20841
21256
  const first = seen.get(key);
21257
+ const elsewhere = across?.get(key);
20842
21258
  if (first !== void 0) {
20843
21259
  fault(
20844
- [...path, i, node2.unique],
21260
+ [...path2, i, node2.unique],
20845
21261
  `${JSON.stringify(item[node2.unique])} is there twice (also entry ${first})`
20846
21262
  );
20847
- } else seen.set(key, i);
21263
+ } else if (elsewhere !== void 0) {
21264
+ fault(
21265
+ [...path2, i, node2.unique],
21266
+ `${JSON.stringify(item[node2.unique])} is used already (at ${elsewhere})`
21267
+ );
21268
+ } else {
21269
+ seen.set(key, i);
21270
+ across?.set(key, [...path2, i].join("."));
21271
+ }
20848
21272
  }
20849
21273
  });
20850
21274
  return;
20851
21275
  }
20852
21276
  case "text": {
20853
21277
  if (typeof v !== "string") {
20854
- fault(path, "Expected text");
21278
+ fault(path2, "Expected text");
20855
21279
  return;
20856
21280
  }
20857
21281
  const max = node2.max ?? DOCUMENT_DEFAULT_TEXT;
20858
- if (v.length > max) fault(path, `At most ${max} characters (this has ${v.length})`);
21282
+ if (v.length > max) fault(path2, `At most ${max} characters (this has ${v.length})`);
20859
21283
  if (node2.min !== void 0 && v.length < node2.min)
20860
- fault(path, `At least ${node2.min} characters`);
20861
- if (CONTROL_RE.test(v)) fault(path, "Control characters are not allowed");
20862
- else if (!node2.multiline && /[\r\n]/.test(v)) fault(path, "One line only");
21284
+ fault(path2, `At least ${node2.min} characters`);
21285
+ if (CONTROL_RE.test(v)) fault(path2, "Control characters are not allowed");
21286
+ else if (!node2.multiline && /[\r\n]/.test(v)) fault(path2, "One line only");
20863
21287
  if (node2.chars) {
20864
21288
  const allowed = new Set(node2.chars);
20865
21289
  const bad = [...v].find((c) => !allowed.has(c));
20866
- if (bad !== void 0) fault(path, `"${bad}" is not allowed here (only ${node2.chars})`);
21290
+ if (bad !== void 0) fault(path2, `"${bad}" is not allowed here (only ${node2.chars})`);
20867
21291
  }
20868
21292
  if (node2.noMarkup && MARKUP_RE.test(v)) {
20869
- fault(path, "Markup is not allowed: rich text is data, not HTML");
21293
+ fault(path2, "Markup is not allowed: rich text is data, not HTML");
20870
21294
  }
20871
21295
  if (node2.href && !isDocumentHref(v, node2.href)) {
20872
21296
  fault(
20873
- path,
21297
+ path2,
20874
21298
  node2.href === "web" ? "Expected an http or https address" : "Expected an http, https, mailto or tel address, a path on the site or an anchor"
20875
21299
  );
20876
21300
  }
@@ -20878,48 +21302,48 @@ function validateDocument(schema, value, options = {}) {
20878
21302
  }
20879
21303
  case "number": {
20880
21304
  if (typeof v !== "number" || !Number.isFinite(v)) {
20881
- fault(path, "Expected a number");
21305
+ fault(path2, "Expected a number");
20882
21306
  return;
20883
21307
  }
20884
- if (node2.integer && !Number.isInteger(v)) fault(path, "Expected a whole number");
20885
- if (node2.min !== void 0 && v < node2.min) fault(path, `At least ${node2.min}`);
20886
- if (node2.max !== void 0 && v > node2.max) fault(path, `At most ${node2.max}`);
21308
+ if (node2.integer && !Number.isInteger(v)) fault(path2, "Expected a whole number");
21309
+ if (node2.min !== void 0 && v < node2.min) fault(path2, `At least ${node2.min}`);
21310
+ if (node2.max !== void 0 && v > node2.max) fault(path2, `At most ${node2.max}`);
20887
21311
  if (node2.step !== void 0) {
20888
21312
  const steps = (v - (node2.min ?? 0)) / node2.step;
20889
- if (Math.abs(steps - Math.round(steps)) > 1e-9) fault(path, `In steps of ${node2.step}`);
21313
+ if (Math.abs(steps - Math.round(steps)) > 1e-9) fault(path2, `In steps of ${node2.step}`);
20890
21314
  }
20891
21315
  return;
20892
21316
  }
20893
21317
  case "boolean":
20894
- if (typeof v !== "boolean") fault(path, "Expected true or false");
21318
+ if (typeof v !== "boolean") fault(path2, "Expected true or false");
20895
21319
  return;
20896
21320
  case "choice":
20897
21321
  if (typeof v !== "string" || !node2.options.includes(v)) {
20898
- fault(path, `Expected one of ${node2.options.join(", ")}`);
21322
+ fault(path2, `Expected one of ${node2.options.join(", ")}`);
20899
21323
  }
20900
21324
  return;
20901
21325
  case "ref":
20902
- if (typeof v !== "string" || !ID_RE.test(v)) fault(path, `Expected the id of a ${node2.to}`);
21326
+ if (typeof v !== "string" || !ID_RE.test(v)) fault(path2, `Expected the id of a ${node2.to}`);
20903
21327
  return;
20904
21328
  }
20905
21329
  };
20906
- const objectValue = (node2, v, path, depth, tag) => {
21330
+ const objectValue = (node2, v, path2, depth, tag) => {
20907
21331
  if (!isObject2(v)) {
20908
- fault(path, "Expected an object");
21332
+ fault(path2, "Expected an object");
20909
21333
  return;
20910
21334
  }
20911
21335
  for (const key of Object.keys(v)) {
20912
21336
  if (key === tag) continue;
20913
21337
  if (!Object.hasOwn(node2.fields, key)) {
20914
- fault([...path, key], `Unknown key "${key}"`);
21338
+ fault([...path2, key], `Unknown key "${key}"`);
20915
21339
  }
20916
21340
  }
20917
21341
  for (const [key, child] of Object.entries(node2.fields)) {
20918
21342
  if (!Object.hasOwn(v, key) || v[key] === void 0) {
20919
- if (!child.optional) fault([...path, key], "Required");
21343
+ if (!child.optional) fault([...path2, key], "Required");
20920
21344
  continue;
20921
21345
  }
20922
- walk(child, v[key], [...path, key], depth + 1);
21346
+ walk(child, v[key], [...path2, key], depth + 1);
20923
21347
  }
20924
21348
  };
20925
21349
  walk(schema.root, value, [], 0);
@@ -20930,12 +21354,27 @@ function formatDocumentIssue(issue2) {
20930
21354
  }
20931
21355
  function documentRefs(schema, value) {
20932
21356
  const refs = [];
20933
- visit2(schema, value, (node2, v, path) => {
20934
- if (node2.type === "ref" && typeof v === "string") refs.push({ to: node2.to, id: v, path });
21357
+ visit2(schema, value, (node2, v, path2) => {
21358
+ if (node2.type === "ref" && typeof v === "string") {
21359
+ refs.push({ to: node2.to, id: v, path: path2, ...node2.media ? { media: node2.media } : {} });
21360
+ }
20935
21361
  });
20936
21362
  return refs;
20937
21363
  }
20938
- function redactDocument(schema, value) {
21364
+ function documentMediaReach(schema, value, mediaObject = "media") {
21365
+ const ids = (v) => new Set(
21366
+ v === null || v === void 0 ? [] : documentRefs(schema, v).filter((r) => r.to === mediaObject).map((r) => r.id)
21367
+ );
21368
+ const everyone = ids(redactDocument(schema, value, { holder: false }));
21369
+ const holders = ids(redactDocument(schema, value, { holder: true }));
21370
+ const reach = /* @__PURE__ */ new Map();
21371
+ for (const id of ids(value)) {
21372
+ reach.set(id, everyone.has(id) ? "all" : holders.has(id) ? "holders" : "private");
21373
+ }
21374
+ return reach;
21375
+ }
21376
+ function redactDocument(schema, value, options = {}) {
21377
+ const holder = options.holder === true;
20939
21378
  if (value === null || value === void 0) return value ?? null;
20940
21379
  const strip = (node2, v, depth) => {
20941
21380
  const at = useOf(schema, node2);
@@ -20950,10 +21389,21 @@ function redactDocument(schema, value) {
20950
21389
  const unless = shape.private === true ? null : shape.private.unless;
20951
21390
  if (!unless || v[unless] !== true) return { keep: false, value: null };
20952
21391
  }
21392
+ let dropped = null;
21393
+ const h = shape.holders;
21394
+ if (h && !holder) {
21395
+ const unless = h === true ? void 0 : h.unless;
21396
+ const open2 = unless !== void 0 && v[unless] === true;
21397
+ if (!open2) {
21398
+ const keys = h === true ? void 0 : h.keys;
21399
+ if (!keys) return { keep: false, value: null };
21400
+ dropped = new Set(keys);
21401
+ }
21402
+ }
20953
21403
  const out = {};
20954
21404
  if (at.type === "union") out[at.tag] = v[at.tag];
20955
21405
  for (const [key, child] of Object.entries(shape.fields)) {
20956
- if (!Object.hasOwn(v, key)) continue;
21406
+ if (!Object.hasOwn(v, key) || dropped?.has(key)) continue;
20957
21407
  const kept = strip(child, v[key], depth + 1);
20958
21408
  if (kept.keep) out[key] = kept.value;
20959
21409
  }
@@ -20975,18 +21425,18 @@ function redactDocument(schema, value) {
20975
21425
  return result.keep ? result.value : null;
20976
21426
  }
20977
21427
  function visit2(schema, value, each) {
20978
- const walk = (node2, v, path, depth) => {
21428
+ const walk = (node2, v, path2, depth) => {
20979
21429
  const at = useOf(schema, node2);
20980
21430
  if (!at || depth > DOCUMENT_MAX_DEPTH) return;
20981
- each(at, v, path);
21431
+ each(at, v, path2);
20982
21432
  if (at.type === "array" && Array.isArray(v)) {
20983
21433
  v.forEach((item, i) => {
20984
- walk(at.of, item, [...path, i], depth + 1);
21434
+ walk(at.of, item, [...path2, i], depth + 1);
20985
21435
  });
20986
21436
  } else if ((at.type === "object" || at.type === "union") && isObject2(v)) {
20987
21437
  const shape = at.type === "object" ? at : at.variants[String(v[at.tag])];
20988
21438
  for (const [key, child] of Object.entries(shape?.fields ?? {})) {
20989
- if (Object.hasOwn(v, key)) walk(child, v[key], [...path, key], depth + 1);
21439
+ if (Object.hasOwn(v, key)) walk(child, v[key], [...path2, key], depth + 1);
20990
21440
  }
20991
21441
  }
20992
21442
  };
@@ -21022,7 +21472,10 @@ var FIELD_TYPES = [
21022
21472
  // unique among the object's live records, made from the title when left empty (ADR 0442).
21023
21473
  "slug",
21024
21474
  // A picture from the media library, with alt text and a focal point (stage 28, ADR 0444).
21025
- "image"
21475
+ "image",
21476
+ // A video from the media library, held in Cloudflare Stream, played only with a token the host
21477
+ // signs (stage 42, ADR 0475).
21478
+ "video"
21026
21479
  ];
21027
21480
  function formulaTypeOf(type, many = false) {
21028
21481
  switch (type) {
@@ -21053,6 +21506,7 @@ function formulaTypeOf(type, many = false) {
21053
21506
  case "document":
21054
21507
  case "richText":
21055
21508
  case "image":
21509
+ case "video":
21056
21510
  return null;
21057
21511
  }
21058
21512
  }
@@ -21077,7 +21531,8 @@ var LOSSLESS_TYPE_CHANGES = {
21077
21531
  timezone: ["text", "longText"],
21078
21532
  richText: [],
21079
21533
  slug: ["text", "longText"],
21080
- image: []
21534
+ image: [],
21535
+ video: []
21081
21536
  };
21082
21537
  function isLosslessChange(from, to) {
21083
21538
  return from === to || LOSSLESS_TYPE_CHANGES[from].includes(to);
@@ -21087,20 +21542,20 @@ function isLosslessChange(from, to) {
21087
21542
  var NUMERIC = ["number", "percent", "currency"];
21088
21543
  var SEED_KEY_RE = /^[a-z][a-zA-Z0-9]{0,39}$/;
21089
21544
  function checkObjectBehaviour(m, name, object3, contract) {
21090
- const path = `objects.${name}`;
21545
+ const path2 = `objects.${name}`;
21091
21546
  const fieldOf = (local) => Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
21092
21547
  const isSingle = (field) => field !== void 0 && field.type !== "formula" && field.type !== "multiSelect" && !field.many;
21093
21548
  const relationTo = (field) => field?.type === "relation" && !field.many ? field.to : void 0;
21094
21549
  const ownObject = (target) => target?.startsWith(`${m.id}.`) ? m.objects[target.slice(m.id.length + 1)] : void 0;
21095
21550
  (object3.indexes ?? []).forEach((columns, i) => {
21096
21551
  if (new Set(columns).size !== columns.length) {
21097
- contract(`${path}.indexes.${i}`, "An index lists each field once");
21552
+ contract(`${path2}.indexes.${i}`, "An index lists each field once");
21098
21553
  }
21099
21554
  for (const column of columns) {
21100
21555
  if (column === "createdAt" || column === "updatedAt") continue;
21101
21556
  if (!isSingle(fieldOf(column))) {
21102
21557
  contract(
21103
- `${path}.indexes.${i}`,
21558
+ `${path2}.indexes.${i}`,
21104
21559
  `Index field "${column}" must be a single-valued, non-formula field of ${name}`
21105
21560
  );
21106
21561
  }
@@ -21108,12 +21563,12 @@ function checkObjectBehaviour(m, name, object3, contract) {
21108
21563
  });
21109
21564
  (object3.timelineLinks ?? []).forEach((local, i) => {
21110
21565
  if (!relationTo(fieldOf(local))) {
21111
- contract(`${path}.timelineLinks.${i}`, `"${local}" must be a relation field (one record)`);
21566
+ contract(`${path2}.timelineLinks.${i}`, `"${local}" must be a relation field (one record)`);
21112
21567
  }
21113
21568
  });
21114
21569
  const stages = object3.stages;
21115
21570
  if (stages) {
21116
- const sp = `${path}.stages`;
21571
+ const sp = `${path2}.stages`;
21117
21572
  const stageTarget = relationTo(fieldOf(stages.field));
21118
21573
  const stageObject = ownObject(stageTarget);
21119
21574
  if (!stageObject) {
@@ -21247,7 +21702,7 @@ function checkObjectBehaviour(m, name, object3, contract) {
21247
21702
  }
21248
21703
  }
21249
21704
  for (const [key, values] of Object.entries(object3.seed ?? {})) {
21250
- const kp = `${path}.seed.${key}`;
21705
+ const kp = `${path2}.seed.${key}`;
21251
21706
  if (!SEED_KEY_RE.test(key)) contract(kp, "Seed keys must be camelCase");
21252
21707
  for (const [local, value] of Object.entries(values)) {
21253
21708
  const field = fieldOf(local);
@@ -22037,6 +22492,213 @@ function checkFormula(expression, env, self) {
22037
22492
  }
22038
22493
  }
22039
22494
 
22495
+ // ../sdk/src/recurring.ts
22496
+ var WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
22497
+ var RECURRING_HORIZON_DAYS = 56;
22498
+ var RECURRING_HORIZON_MAX = 366;
22499
+ var fieldName4 = external_exports.string().max(40);
22500
+ var recurringManifestSchema = external_exports.object({
22501
+ generates: fieldName4,
22502
+ link: fieldName4,
22503
+ rule: external_exports.object({
22504
+ weekdays: fieldName4,
22505
+ time: fieldName4,
22506
+ length: fieldName4.optional(),
22507
+ from: fieldName4,
22508
+ until: fieldName4.optional(),
22509
+ zone: fieldName4.optional()
22510
+ }).strict(),
22511
+ into: external_exports.object({
22512
+ starts: fieldName4,
22513
+ ends: fieldName4.optional(),
22514
+ zone: fieldName4.optional(),
22515
+ changed: fieldName4.optional()
22516
+ }).strict(),
22517
+ copy: external_exports.record(fieldName4, fieldName4).refine((copy) => Object.keys(copy).length <= 20, "At most 20 copied fields").optional(),
22518
+ cancel: external_exports.string().min(1).max(100),
22519
+ ended: external_exports.object({ field: fieldName4, in: external_exports.array(external_exports.string().min(1).max(100)).min(1).max(20) }).strict().optional(),
22520
+ closures: external_exports.object({ object: fieldName4, from: fieldName4, until: fieldName4 }).strict().optional(),
22521
+ horizonDays: external_exports.number().int().min(1).max(RECURRING_HORIZON_MAX).optional(),
22522
+ horizonAtLeast: external_exports.object({ object: fieldName4, field: fieldName4 }).strict().optional()
22523
+ }).strict();
22524
+ function checkObjectRecurring(m, name, object3, contract) {
22525
+ const recurring = object3.recurring;
22526
+ if (!recurring) return;
22527
+ const path2 = `objects.${name}.recurring`;
22528
+ const own2 = (o, local) => Object.hasOwn(o.fields, local) ? o.fields[local] : void 0;
22529
+ const expect = (o, oName, at, local, types, what) => {
22530
+ if (local === void 0) return void 0;
22531
+ const field = own2(o, local);
22532
+ if (!field || !types.includes(field.type) || field.many) {
22533
+ contract(at, `"${local}" must be ${what} of ${oName}`);
22534
+ return void 0;
22535
+ }
22536
+ return field;
22537
+ };
22538
+ const rule = recurring.rule;
22539
+ const weekdays = expect(
22540
+ object3,
22541
+ name,
22542
+ `${path2}.rule.weekdays`,
22543
+ rule.weekdays,
22544
+ ["multiSelect"],
22545
+ "a multiSelect field"
22546
+ );
22547
+ if (weekdays) {
22548
+ const values = (weekdays.options ?? []).map((o) => o.value);
22549
+ const wrong = values.filter((v) => !WEEKDAYS.includes(v));
22550
+ if (wrong.length || !values.length) {
22551
+ contract(
22552
+ `${path2}.rule.weekdays`,
22553
+ `"${rule.weekdays}"'s options must be weekdays (${WEEKDAYS.join(", ")})`
22554
+ );
22555
+ }
22556
+ if (weekdays.editableOptions) {
22557
+ contract(`${path2}.rule.weekdays`, "The weekdays field cannot have editableOptions");
22558
+ }
22559
+ }
22560
+ expect(object3, name, `${path2}.rule.time`, rule.time, ["text"], "a text field (HH:MM)");
22561
+ expect(object3, name, `${path2}.rule.length`, rule.length, ["number"], "a number field (minutes)");
22562
+ expect(object3, name, `${path2}.rule.from`, rule.from, ["date"], "a date field");
22563
+ expect(object3, name, `${path2}.rule.until`, rule.until, ["date"], "a date field");
22564
+ expect(object3, name, `${path2}.rule.zone`, rule.zone, ["timezone"], "a timezone field");
22565
+ if (recurring.ended) {
22566
+ const field = expect(
22567
+ object3,
22568
+ name,
22569
+ `${path2}.ended.field`,
22570
+ recurring.ended.field,
22571
+ ["select"],
22572
+ "a select field"
22573
+ );
22574
+ const values = new Set((field?.options ?? []).map((o) => o.value));
22575
+ for (const value of recurring.ended.in) {
22576
+ if (field && !values.has(value)) {
22577
+ contract(`${path2}.ended.in`, `"${value}" is not an option of ${recurring.ended.field}`);
22578
+ }
22579
+ }
22580
+ }
22581
+ const generatedName = recurring.generates;
22582
+ const generated = Object.hasOwn(m.objects, generatedName) ? m.objects[generatedName] : void 0;
22583
+ if (!generated || generatedName === name) {
22584
+ contract(`${path2}.generates`, `"${generatedName}" must be another of this extension's objects`);
22585
+ return;
22586
+ }
22587
+ const link = own2(generated, recurring.link);
22588
+ if (link?.type !== "relation" || link.many || link.to !== `${m.id}.${name}`) {
22589
+ contract(
22590
+ `${path2}.link`,
22591
+ `"${recurring.link}" must be a relation field of ${generatedName} to ${m.id}.${name}`
22592
+ );
22593
+ } else if (!link.readOnly) {
22594
+ contract(`${path2}.link`, `"${recurring.link}" must be read-only: the host sets it`);
22595
+ }
22596
+ expect(
22597
+ generated,
22598
+ generatedName,
22599
+ `${path2}.into.starts`,
22600
+ recurring.into.starts,
22601
+ ["datetime"],
22602
+ "a datetime field"
22603
+ );
22604
+ expect(
22605
+ generated,
22606
+ generatedName,
22607
+ `${path2}.into.ends`,
22608
+ recurring.into.ends,
22609
+ ["datetime"],
22610
+ "a datetime field"
22611
+ );
22612
+ expect(
22613
+ generated,
22614
+ generatedName,
22615
+ `${path2}.into.zone`,
22616
+ recurring.into.zone,
22617
+ ["timezone"],
22618
+ "a timezone field"
22619
+ );
22620
+ const changed = expect(
22621
+ generated,
22622
+ generatedName,
22623
+ `${path2}.into.changed`,
22624
+ recurring.into.changed,
22625
+ ["boolean"],
22626
+ "a boolean field"
22627
+ );
22628
+ if (changed && !changed.readOnly) {
22629
+ contract(
22630
+ `${path2}.into.changed`,
22631
+ `"${recurring.into.changed}" must be read-only: the host sets it`
22632
+ );
22633
+ }
22634
+ const into = new Set(Object.values(recurring.into));
22635
+ if (generated.states) into.add(generated.states.field);
22636
+ for (const [target, source] of Object.entries(recurring.copy ?? {})) {
22637
+ const to = own2(generated, target);
22638
+ const from = own2(object3, source);
22639
+ if (!to || to.type === "formula" || into.has(target) || target === recurring.link) {
22640
+ contract(
22641
+ `${path2}.copy.${target}`,
22642
+ `"${target}" must be a field of ${generatedName} the host does not already fill`
22643
+ );
22644
+ } else if (!from || from.type !== to.type || Boolean(from.many) !== Boolean(to.many) || from.to !== to.to) {
22645
+ contract(
22646
+ `${path2}.copy.${target}`,
22647
+ `"${source}" must be a field of ${name} of the same type as ${generatedName}.${target}`
22648
+ );
22649
+ }
22650
+ }
22651
+ const states = generated.states;
22652
+ if (!states) {
22653
+ contract(
22654
+ `${path2}.cancel`,
22655
+ `${generatedName} must declare states, with a host move into "${recurring.cancel}"`
22656
+ );
22657
+ } else {
22658
+ const field = own2(generated, states.field);
22659
+ if (!(field?.options ?? []).some((o) => o.value === recurring.cancel)) {
22660
+ contract(`${path2}.cancel`, `"${recurring.cancel}" is not a state of ${generatedName}`);
22661
+ } else if (!states.moves.some((move) => move.to === recurring.cancel && move.by.includes("host"))) {
22662
+ contract(
22663
+ `${path2}.cancel`,
22664
+ `${generatedName} needs a move into "${recurring.cancel}" that the host may make`
22665
+ );
22666
+ }
22667
+ }
22668
+ if (recurring.horizonAtLeast) {
22669
+ const h = recurring.horizonAtLeast;
22670
+ const target = Object.hasOwn(m.objects, h.object) ? m.objects[h.object] : void 0;
22671
+ if (!target) {
22672
+ contract(
22673
+ `${path2}.horizonAtLeast.object`,
22674
+ `"${h.object}" must be one of this extension's objects`
22675
+ );
22676
+ } else {
22677
+ expect(
22678
+ target,
22679
+ h.object,
22680
+ `${path2}.horizonAtLeast.field`,
22681
+ h.field,
22682
+ ["number"],
22683
+ "a number field (days)"
22684
+ );
22685
+ }
22686
+ }
22687
+ if (recurring.closures) {
22688
+ const c = recurring.closures;
22689
+ const closure = Object.hasOwn(m.objects, c.object) ? m.objects[c.object] : void 0;
22690
+ if (!closure || c.object === name || c.object === generatedName) {
22691
+ contract(
22692
+ `${path2}.closures.object`,
22693
+ `"${c.object}" must be another of this extension's objects`
22694
+ );
22695
+ } else {
22696
+ expect(closure, c.object, `${path2}.closures.from`, c.from, ["date"], "a date field");
22697
+ expect(closure, c.object, `${path2}.closures.until`, c.until, ["date"], "a date field");
22698
+ }
22699
+ }
22700
+ }
22701
+
22040
22702
  // ../sdk/src/renamed.ts
22041
22703
  var OLD_PREFIX = "crm";
22042
22704
  var OPS_MODULE = "ops";
@@ -22082,25 +22744,44 @@ function renamedMessage(name) {
22082
22744
 
22083
22745
  // ../sdk/src/states.ts
22084
22746
  var MOVERS = ["staff", "customer", "host"];
22085
- var fieldName3 = external_exports.string().max(40);
22086
- var stateValue = external_exports.string().min(1).max(100);
22747
+ var fieldName5 = external_exports.string().max(40);
22748
+ var stateValue2 = external_exports.string().min(1).max(100);
22749
+ var fieldPath = external_exports.string().min(1).max(81);
22750
+ var windowBound = external_exports.union([
22751
+ fieldPath,
22752
+ external_exports.object({
22753
+ at: fieldPath,
22754
+ daysBefore: external_exports.union([external_exports.number().int().min(-366).max(366), fieldPath]).optional(),
22755
+ minutesBefore: external_exports.union([external_exports.number().int().min(-527040).max(527040), fieldPath]).optional(),
22756
+ zone: fieldPath.optional()
22757
+ }).strict()
22758
+ ]);
22759
+ var moveWindow = external_exports.object({ from: windowBound.optional(), until: windowBound.optional() }).strict().refine((w) => w.from !== void 0 || w.until !== void 0, "A window needs from or until");
22087
22760
  var statesManifestSchema = external_exports.object({
22088
- field: fieldName3,
22089
- initial: stateValue,
22761
+ field: fieldName5,
22762
+ initial: stateValue2,
22090
22763
  moves: external_exports.array(
22091
22764
  external_exports.object({
22092
- from: external_exports.union([stateValue, external_exports.array(stateValue).min(1).max(50)]),
22093
- to: stateValue,
22765
+ from: external_exports.union([stateValue2, external_exports.array(stateValue2).min(1).max(50)]),
22766
+ to: stateValue2,
22094
22767
  by: external_exports.array(external_exports.enum(MOVERS)).min(1).max(MOVERS.length),
22095
- requires: external_exports.array(fieldName3).max(50).optional(),
22096
- final: external_exports.boolean().optional()
22768
+ requires: external_exports.array(fieldName5).max(50).optional(),
22769
+ final: external_exports.boolean().optional(),
22770
+ window: moveWindow.optional(),
22771
+ staffOnly: fieldPath.optional()
22097
22772
  })
22098
- ).max(200)
22773
+ ).max(200),
22774
+ create: external_exports.object({
22775
+ in: external_exports.record(stateValue2, external_exports.array(external_exports.enum(MOVERS)).min(1).max(MOVERS.length)).refine((r) => Object.keys(r).length <= 20, "At most 20 states").optional(),
22776
+ window: moveWindow.optional(),
22777
+ staffOnly: fieldPath.optional()
22778
+ }).strict().optional(),
22779
+ requests: external_exports.record(external_exports.string().regex(/^[a-z][a-z0-9_]{0,39}$/), external_exports.array(stateValue2).min(1).max(10)).refine((r) => Object.keys(r).length <= 10, "At most 10 requests").optional()
22099
22780
  });
22100
22781
  function moveOrigins(move) {
22101
22782
  return typeof move.from === "string" ? [move.from] : move.from;
22102
22783
  }
22103
- function checkObjectStates(_m, name, object3, contract) {
22784
+ function checkObjectStates(m, name, object3, contract) {
22104
22785
  const states = object3.states;
22105
22786
  if (!states) return;
22106
22787
  const sp = `objects.${name}.states`;
@@ -22177,10 +22858,75 @@ function checkObjectStates(_m, name, object3, contract) {
22177
22858
  }
22178
22859
  }
22179
22860
  });
22861
+ const checkPath = (at, path2, type) => {
22862
+ const field2 = resolveFieldPath(m, object3, at);
22863
+ if (field2?.type !== type || field2.many) {
22864
+ contract(
22865
+ path2,
22866
+ `"${at}" must be a ${type} field of ${name}, or <relation>.<field> through a relation (one record) to another of this extension's objects`
22867
+ );
22868
+ }
22869
+ };
22870
+ const checkWindow = (window, path2) => {
22871
+ for (const end of ["from", "until"]) {
22872
+ const bound = window?.[end];
22873
+ if (bound === void 0) continue;
22874
+ const b = typeof bound === "string" ? { at: bound } : bound;
22875
+ checkPath(b.at, `${path2}.${end}.at`, "datetime");
22876
+ for (const key of ["daysBefore", "minutesBefore"]) {
22877
+ const value = b[key];
22878
+ if (typeof value === "string") checkPath(value, `${path2}.${end}.${key}`, "number");
22879
+ }
22880
+ if (b.zone !== void 0) checkPath(b.zone, `${path2}.${end}.zone`, "timezone");
22881
+ }
22882
+ };
22883
+ states.moves.forEach((move, i) => {
22884
+ const mp = `${sp}.moves.${i}`;
22885
+ if ((move.window || move.staffOnly) && !move.by.includes("customer")) {
22886
+ contract(mp, "A window or staffOnly binds customers: the move must list customer in by");
22887
+ }
22888
+ checkWindow(move.window, `${mp}.window`);
22889
+ if (move.staffOnly) checkPath(move.staffOnly, `${mp}.staffOnly`, "boolean");
22890
+ });
22891
+ if (states.create) {
22892
+ for (const state of Object.keys(states.create.in ?? {})) {
22893
+ if (!isState(state))
22894
+ contract(`${sp}.create.in`, `"${state}" is not an option of ${states.field}`);
22895
+ if (finals.has(state))
22896
+ contract(`${sp}.create.in`, `"${state}" is final: nothing is created in it`);
22897
+ }
22898
+ checkWindow(states.create.window, `${sp}.create.window`);
22899
+ if (states.create.staffOnly)
22900
+ checkPath(states.create.staffOnly, `${sp}.create.staffOnly`, "boolean");
22901
+ }
22902
+ for (const [request, targets] of Object.entries(states.requests ?? {})) {
22903
+ const rp = `${sp}.requests.${request}`;
22904
+ if (isState(request)) contract(rp, `"${request}" is a state; a request needs its own name`);
22905
+ if (new Set(targets).size !== targets.length) contract(rp, "List each state once");
22906
+ for (const to of targets) {
22907
+ if (!isState(to)) contract(rp, `"${to}" is not an option of ${states.field}`);
22908
+ else if (!states.moves.some((move) => move.to === to)) {
22909
+ contract(rp, `No move goes to "${to}"`);
22910
+ }
22911
+ }
22912
+ }
22913
+ }
22914
+ function resolveFieldPath(m, object3, path2) {
22915
+ const own2 = (o, local2) => Object.hasOwn(o.fields, local2) ? o.fields[local2] : void 0;
22916
+ const parts = path2.split(".");
22917
+ if (parts.length === 1) return own2(object3, path2);
22918
+ if (parts.length !== 2) return void 0;
22919
+ const [relation, local] = parts;
22920
+ const via = own2(object3, relation);
22921
+ const to = via?.type === "relation" && !via.many ? via.to : void 0;
22922
+ const target = to?.startsWith(`${m.id}.`) ? to.slice(m.id.length + 1) : void 0;
22923
+ const targetObject = target !== void 0 && Object.hasOwn(m.objects, target) ? m.objects[target] : void 0;
22924
+ return targetObject ? own2(targetObject, local) : void 0;
22180
22925
  }
22181
22926
 
22182
22927
  // ../sdk/src/sellable.ts
22183
- var fieldName4 = external_exports.string().max(40);
22928
+ var TAX_CODE_PATTERN = /^txcd_\d{8}$/;
22929
+ var fieldName6 = external_exports.string().max(40);
22184
22930
  var GRANT_SOURCES = [
22185
22931
  "item",
22186
22932
  "order",
@@ -22196,36 +22942,51 @@ var grantSource = external_exports.union([
22196
22942
  external_exports.string().regex(/^item\.[a-z][a-zA-Z0-9]{0,39}$/, "Use item, item.<field>, order, line or code")
22197
22943
  ]);
22198
22944
  var sellableManifestSchema = external_exports.object({
22199
- price: fieldName4,
22945
+ price: fieldName6,
22200
22946
  currency: external_exports.string().regex(/^[A-Z]{3}$/).optional(),
22201
- saleWindow: external_exports.object({ from: fieldName4.optional(), until: fieldName4.optional() }).strict().optional(),
22202
- maxPerOrder: fieldName4.optional(),
22203
- deposit: external_exports.object({ amount: fieldName4.optional(), balanceDue: fieldName4.optional() }).strict().optional(),
22947
+ saleWindow: external_exports.object({ from: fieldName6.optional(), until: fieldName6.optional() }).strict().optional(),
22948
+ maxPerOrder: fieldName6.optional(),
22949
+ deposit: external_exports.object({ amount: fieldName6.optional(), balanceDue: fieldName6.optional() }).strict().optional(),
22204
22950
  grants: external_exports.object({
22205
22951
  object: external_exports.string().max(40),
22206
- set: external_exports.record(fieldName4, grantSource),
22952
+ set: external_exports.record(fieldName6, grantSource),
22207
22953
  void: external_exports.string().min(1).max(100)
22954
+ }).strict().optional(),
22955
+ tax: external_exports.object({
22956
+ code: external_exports.string().regex(TAX_CODE_PATTERN, "A product tax code: txcd_ and eight digits"),
22957
+ place: external_exports.object({
22958
+ via: fieldName6.optional(),
22959
+ country: fieldName6,
22960
+ region: fieldName6.optional(),
22961
+ postcode: fieldName6.optional(),
22962
+ city: fieldName6.optional(),
22963
+ line1: fieldName6.optional()
22964
+ }).strict().optional()
22965
+ }).strict().optional(),
22966
+ recurring: external_exports.object({
22967
+ interval: external_exports.enum(["week", "month", "year"]),
22968
+ trialDays: fieldName6.optional()
22208
22969
  }).strict().optional()
22209
22970
  }).strict();
22210
22971
  var NUMERIC2 = /* @__PURE__ */ new Set(["number", "currency"]);
22211
- var DATES = /* @__PURE__ */ new Set(["date", "datetime"]);
22972
+ var DATES2 = /* @__PURE__ */ new Set(["date", "datetime"]);
22212
22973
  var TEXT = /* @__PURE__ */ new Set(["text"]);
22213
22974
  function checkObjectSellable(m, name, object3, contract) {
22214
22975
  const sellable = object3.sellable;
22215
22976
  if (!sellable) return;
22216
- const path = `objects.${name}.sellable`;
22977
+ const path2 = `objects.${name}.sellable`;
22217
22978
  const fieldOf = (local) => Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
22218
22979
  const single = (local, types) => {
22219
22980
  const field = fieldOf(local);
22220
22981
  return field !== void 0 && types.has(field.type) && !field.many;
22221
22982
  };
22222
22983
  if (!single(sellable.price, NUMERIC2)) {
22223
- contract(`${path}.price`, `"${sellable.price}" must be a currency or number field of ${name}`);
22984
+ contract(`${path2}.price`, `"${sellable.price}" must be a currency or number field of ${name}`);
22224
22985
  } else {
22225
22986
  const own2 = fieldOf(sellable.price)?.currency;
22226
22987
  if (sellable.currency && own2 && own2 !== sellable.currency) {
22227
22988
  contract(
22228
- `${path}.currency`,
22989
+ `${path2}.currency`,
22229
22990
  `The price field is in ${own2}; currency says ${sellable.currency}. Declare one`
22230
22991
  );
22231
22992
  }
@@ -22233,67 +22994,110 @@ function checkObjectSellable(m, name, object3, contract) {
22233
22994
  if (sellable.saleWindow) {
22234
22995
  const { from, until } = sellable.saleWindow;
22235
22996
  if (from === void 0 && until === void 0) {
22236
- contract(`${path}.saleWindow`, "A sale window names its from field, its until field or both");
22997
+ contract(`${path2}.saleWindow`, "A sale window names its from field, its until field or both");
22237
22998
  }
22238
22999
  for (const [key, local] of [
22239
23000
  ["from", from],
22240
23001
  ["until", until]
22241
23002
  ]) {
22242
- if (local !== void 0 && !single(local, DATES)) {
23003
+ if (local !== void 0 && !single(local, DATES2)) {
22243
23004
  contract(
22244
- `${path}.saleWindow.${key}`,
23005
+ `${path2}.saleWindow.${key}`,
22245
23006
  `"${local}" must be a date or datetime field of ${name}`
22246
23007
  );
22247
23008
  }
22248
23009
  }
22249
23010
  }
23011
+ if (sellable.recurring) {
23012
+ for (const key of ["deposit", "maxPerOrder", "grants"]) {
23013
+ if (sellable[key] !== void 0) {
23014
+ contract(
23015
+ `${path2}.${key}`,
23016
+ `A recurring plan has no ${key}: it is subscribed to, one at a time`
23017
+ );
23018
+ }
23019
+ }
23020
+ const trial = sellable.recurring.trialDays;
23021
+ if (trial !== void 0 && !single(trial, /* @__PURE__ */ new Set(["number"]))) {
23022
+ contract(`${path2}.recurring.trialDays`, `"${trial}" must be a number field of ${name}`);
23023
+ }
23024
+ }
22250
23025
  if (sellable.maxPerOrder !== void 0 && !single(sellable.maxPerOrder, /* @__PURE__ */ new Set(["number"]))) {
22251
- contract(`${path}.maxPerOrder`, `"${sellable.maxPerOrder}" must be a number field of ${name}`);
23026
+ contract(`${path2}.maxPerOrder`, `"${sellable.maxPerOrder}" must be a number field of ${name}`);
22252
23027
  }
22253
23028
  if (sellable.deposit) {
22254
23029
  const { amount, balanceDue } = sellable.deposit;
22255
23030
  if (amount === void 0 || balanceDue === void 0) {
22256
23031
  contract(
22257
- `${path}.deposit`,
23032
+ `${path2}.deposit`,
22258
23033
  "A deposit names both fields: amount (the deposit for one) and balanceDue (when the rest is due)"
22259
23034
  );
22260
23035
  }
22261
23036
  if (amount !== void 0 && !single(amount, NUMERIC2)) {
22262
23037
  contract(
22263
- `${path}.deposit.amount`,
23038
+ `${path2}.deposit.amount`,
22264
23039
  `"${amount}" must be a currency or number field of ${name}`
22265
23040
  );
22266
23041
  }
22267
- if (balanceDue !== void 0 && !single(balanceDue, DATES)) {
23042
+ if (balanceDue !== void 0 && !single(balanceDue, DATES2)) {
22268
23043
  contract(
22269
- `${path}.deposit.balanceDue`,
23044
+ `${path2}.deposit.balanceDue`,
22270
23045
  `"${balanceDue}" must be a date or datetime field of ${name}`
22271
23046
  );
22272
23047
  }
22273
23048
  }
22274
- if (sellable.grants) checkGrants(m, name, object3, sellable.grants, `${path}.grants`, contract);
23049
+ if (sellable.grants) checkGrants(m, name, object3, sellable.grants, `${path2}.grants`, contract);
23050
+ const place = sellable.tax?.place;
23051
+ if (place) {
23052
+ let holder = object3;
23053
+ let holderName = name;
23054
+ if (place.via !== void 0) {
23055
+ const via = fieldOf(place.via);
23056
+ const local = via?.to?.startsWith(`${m.id}.`) ? via.to.slice(m.id.length + 1) : void 0;
23057
+ if (!via || via.type !== "relation" || via.many || !local || !Object.hasOwn(m.objects, local)) {
23058
+ contract(
23059
+ `${path2}.tax.place.via`,
23060
+ `"${place.via}" must be a relation of ${name} to one record of another of this extension's objects`
23061
+ );
23062
+ holder = void 0;
23063
+ } else {
23064
+ holder = m.objects[local];
23065
+ holderName = local;
23066
+ }
23067
+ }
23068
+ if (holder) {
23069
+ for (const key of ["country", "region", "postcode", "city", "line1"]) {
23070
+ const local = place[key];
23071
+ if (local === void 0) continue;
23072
+ const field = Object.hasOwn(holder.fields, local) ? holder.fields[local] : void 0;
23073
+ if (!field || field.type !== "text" || field.many) {
23074
+ contract(`${path2}.tax.place.${key}`, `"${local}" must be a text field of ${holderName}`);
23075
+ }
23076
+ }
23077
+ }
23078
+ }
22275
23079
  }
22276
- function checkGrants(m, name, item, grants, path, contract) {
23080
+ function checkGrants(m, name, item, grants, path2, contract) {
22277
23081
  const local = grants.object.startsWith(`${m.id}.`) ? grants.object.slice(m.id.length + 1) : grants.object;
22278
23082
  const granted = Object.hasOwn(m.objects, local) ? m.objects[local] : void 0;
22279
23083
  if (!granted) {
22280
- contract(`${path}.object`, `"${grants.object}" must be another of this extension's objects`);
23084
+ contract(`${path2}.object`, `"${grants.object}" must be another of this extension's objects`);
22281
23085
  return;
22282
23086
  }
22283
23087
  if (local === name) {
22284
- contract(`${path}.object`, "An object cannot grant records of itself");
23088
+ contract(`${path2}.object`, "An object cannot grant records of itself");
22285
23089
  return;
22286
23090
  }
22287
23091
  if (granted.sellable) {
22288
23092
  contract(
22289
- `${path}.object`,
23093
+ `${path2}.object`,
22290
23094
  `${local} is itself sellable; a grant is what was bought, not more for sale`
22291
23095
  );
22292
23096
  }
22293
23097
  const states = granted.states;
22294
23098
  if (!states) {
22295
23099
  contract(
22296
- `${path}.object`,
23100
+ `${path2}.object`,
22297
23101
  `${local} must declare states, so what was granted can be voided (to "${grants.void}")`
22298
23102
  );
22299
23103
  } else {
@@ -22301,10 +23105,10 @@ function checkGrants(m, name, item, grants, path, contract) {
22301
23105
  const values = new Set((stateField?.options ?? []).map((o) => o.value));
22302
23106
  const finals = new Set(states.moves.filter((mv) => mv.final).map((mv) => mv.to));
22303
23107
  if (!values.has(grants.void)) {
22304
- contract(`${path}.void`, `"${grants.void}" is not a state of ${local}`);
23108
+ contract(`${path2}.void`, `"${grants.void}" is not a state of ${local}`);
22305
23109
  } else if (grants.void === states.initial) {
22306
23110
  contract(
22307
- `${path}.void`,
23111
+ `${path2}.void`,
22308
23112
  `"${grants.void}" is ${local}'s initial state; void is where a grant ends`
22309
23113
  );
22310
23114
  } else {
@@ -22315,7 +23119,7 @@ function checkGrants(m, name, item, grants, path, contract) {
22315
23119
  );
22316
23120
  if (!moves) {
22317
23121
  contract(
22318
- `${path}.void`,
23122
+ `${path2}.void`,
22319
23123
  `${local} needs a move from "${state}" to "${grants.void}" that the host may make (by: ["host", ...])`
22320
23124
  );
22321
23125
  }
@@ -22323,7 +23127,7 @@ function checkGrants(m, name, item, grants, path, contract) {
22323
23127
  }
22324
23128
  if (Object.hasOwn(grants.set, states.field)) {
22325
23129
  contract(
22326
- `${path}.set.${states.field}`,
23130
+ `${path2}.set.${states.field}`,
22327
23131
  `${states.field} is ${local}'s state: a granted record starts in "${states.initial}"`
22328
23132
  );
22329
23133
  }
@@ -22331,7 +23135,7 @@ function checkGrants(m, name, item, grants, path, contract) {
22331
23135
  const itemField = (f) => Object.hasOwn(item.fields, f) ? item.fields[f] : void 0;
22332
23136
  let codes = 0;
22333
23137
  for (const [target, source] of Object.entries(grants.set)) {
22334
- const fp = `${path}.set.${target}`;
23138
+ const fp = `${path2}.set.${target}`;
22335
23139
  const field = Object.hasOwn(granted.fields, target) ? granted.fields[target] : void 0;
22336
23140
  if (!field || field.type === "formula") {
22337
23141
  contract(fp, `"${target}" must be a field of ${local} other than a formula`);
@@ -22382,7 +23186,7 @@ function checkGrants(m, name, item, grants, path, contract) {
22382
23186
  }
22383
23187
  }
22384
23188
  }
22385
- if (codes > 1) contract(`${path}.set`, "A grant has at most one code");
23189
+ if (codes > 1) contract(`${path2}.set`, "A grant has at most one code");
22386
23190
  const always = (source) => source === "order.person" ? false : source.startsWith("item.") ? Boolean(itemField(source.slice("item.".length))?.required) : true;
22387
23191
  const filled = /* @__PURE__ */ new Set([
22388
23192
  ...Object.entries(grants.set).filter(([, source]) => always(source)).map(([field]) => field),
@@ -22402,33 +23206,82 @@ function checkGrants(m, name, item, grants, path, contract) {
22402
23206
  );
22403
23207
  }
22404
23208
  });
22405
- for (const [fieldName5, field] of Object.entries(granted.fields)) {
23209
+ for (const [fieldName7, field] of Object.entries(granted.fields)) {
22406
23210
  if (field.type !== "select") continue;
22407
- const source = grants.set[fieldName5];
22408
- const values = source?.startsWith("item.") === true ? (field.options ?? []).map((o) => o.value) : states && fieldName5 === states.field ? [states.initial] : field.default !== void 0 ? [String(field.default)] : [];
23211
+ const source = grants.set[fieldName7];
23212
+ const values = source?.startsWith("item.") === true ? (field.options ?? []).map((o) => o.value) : states && fieldName7 === states.field ? [states.initial] : field.default !== void 0 ? [String(field.default)] : [];
22409
23213
  for (const option of field.options ?? []) {
22410
23214
  if (!values.includes(option.value)) continue;
22411
23215
  const missing2 = (option.requires ?? []).filter((required2) => !filled.has(required2));
22412
23216
  if (missing2.length) {
22413
23217
  contract(
22414
- `objects.${local}.fields.${fieldName5}.options`,
23218
+ `objects.${local}.fields.${fieldName7}.options`,
22415
23219
  `${local} is granted by ${name}: "${option.value}" needs ${missing2.join(", ")}, which grants.set does not always fill`
22416
23220
  );
22417
23221
  }
22418
23222
  }
22419
23223
  }
22420
- for (const [fieldName5, field] of Object.entries(granted.fields)) {
23224
+ for (const [fieldName7, field] of Object.entries(granted.fields)) {
22421
23225
  if (!field.required || field.type === "formula" || field.default !== void 0) continue;
22422
- if (states && fieldName5 === states.field) continue;
22423
- if (!Object.hasOwn(grants.set, fieldName5)) {
23226
+ if (states && fieldName7 === states.field) continue;
23227
+ if (!Object.hasOwn(grants.set, fieldName7)) {
22424
23228
  contract(
22425
- `${path}.set`,
22426
- `${local}.${fieldName5} is required: set it from the item, the order or the line`
23229
+ `${path2}.set`,
23230
+ `${local}.${fieldName7} is required: set it from the item, the order or the line`
22427
23231
  );
22428
23232
  }
22429
23233
  }
22430
23234
  }
22431
23235
 
23236
+ // ../sdk/src/unique.ts
23237
+ var uniqueManifestSchema = external_exports.array(
23238
+ external_exports.object({
23239
+ fields: external_exports.array(external_exports.string().max(40)).min(1).max(4),
23240
+ states: external_exports.array(external_exports.string().min(1).max(100)).min(1).max(20).optional()
23241
+ }).strict()
23242
+ ).min(1).max(4);
23243
+ var UNIQUE_TYPES = /* @__PURE__ */ new Set([
23244
+ "text",
23245
+ "number",
23246
+ "date",
23247
+ "datetime",
23248
+ "boolean",
23249
+ "select",
23250
+ "relation",
23251
+ "user",
23252
+ "email",
23253
+ "phone",
23254
+ "url",
23255
+ "slug",
23256
+ "timezone"
23257
+ ]);
23258
+ function checkObjectUnique(_m, name, object3, contract) {
23259
+ (object3.unique ?? []).forEach((rule, i) => {
23260
+ const path2 = `objects.${name}.unique.${i}`;
23261
+ if (new Set(rule.fields).size !== rule.fields.length) {
23262
+ contract(`${path2}.fields`, "List each field once");
23263
+ }
23264
+ for (const local of rule.fields) {
23265
+ const field = Object.hasOwn(object3.fields, local) ? object3.fields[local] : void 0;
23266
+ if (!field || field.many || !UNIQUE_TYPES.has(field.type)) {
23267
+ contract(`${path2}.fields`, `"${local}" must be a single-valued, stored field of ${name}`);
23268
+ }
23269
+ }
23270
+ if (rule.states) {
23271
+ const states = object3.states;
23272
+ if (!states) {
23273
+ contract(`${path2}.states`, `${name} has no states`);
23274
+ return;
23275
+ }
23276
+ const field = Object.hasOwn(object3.fields, states.field) ? object3.fields[states.field] : void 0;
23277
+ const values = new Set((field?.options ?? []).map((o) => o.value));
23278
+ for (const state of rule.states) {
23279
+ if (!values.has(state)) contract(`${path2}.states`, `"${state}" is not a state of ${name}`);
23280
+ }
23281
+ }
23282
+ });
23283
+ }
23284
+
22432
23285
  // ../sdk/src/manifest.ts
22433
23286
  var EXTENSION_ID_RE = /^[a-z][a-z0-9]{1,29}$/;
22434
23287
  var OBJECT_NAME_RE = /^[a-z][a-z0-9]{0,29}$/;
@@ -22560,12 +23413,17 @@ var objectManifestSchema = external_exports.object({
22560
23413
  stages: stagesManifestSchema.optional(),
22561
23414
  capacity: capacityManifestSchema.optional(),
22562
23415
  sellable: sellableManifestSchema.optional(),
23416
+ allowance: allowanceManifestSchema.optional(),
22563
23417
  states: statesManifestSchema.optional(),
23418
+ claims: claimsManifestSchema.optional(),
23419
+ unique: uniqueManifestSchema.optional(),
23420
+ recurring: recurringManifestSchema.optional(),
22564
23421
  owner: external_exports.string().max(40).optional(),
22565
23422
  customer: external_exports.object({
22566
23423
  field: external_exports.string().max(40),
22567
23424
  read: external_exports.array(external_exports.string().max(40)).max(100),
22568
- write: external_exports.array(external_exports.string().max(40)).max(100)
23425
+ write: external_exports.array(external_exports.string().max(40)).max(100),
23426
+ requireAccess: external_exports.array(external_exports.string().max(40)).max(10).optional()
22569
23427
  }).strict().optional(),
22570
23428
  public: readDeclarationSchema.optional(),
22571
23429
  signedIn: readDeclarationSchema.optional(),
@@ -22574,6 +23432,31 @@ var objectManifestSchema = external_exports.object({
22574
23432
  field: external_exports.string().max(40),
22575
23433
  read: external_exports.array(external_exports.string().max(40)).min(1).max(100)
22576
23434
  }).strict().optional(),
23435
+ access: external_exports.object({
23436
+ sources: external_exports.array(
23437
+ external_exports.union([
23438
+ external_exports.object({
23439
+ via: external_exports.string().max(81),
23440
+ field: external_exports.string().max(40),
23441
+ through: external_exports.string().max(40).optional(),
23442
+ states: external_exports.array(external_exports.string().max(60)).min(1).max(20).optional(),
23443
+ until: external_exports.string().max(40).optional()
23444
+ }).strict(),
23445
+ external_exports.object({
23446
+ kind: external_exports.string().regex(/^[a-z][a-zA-Z0-9]{0,39}$/),
23447
+ options: external_exports.record(
23448
+ external_exports.string().max(40),
23449
+ external_exports.union([
23450
+ external_exports.string().max(200),
23451
+ external_exports.number(),
23452
+ external_exports.boolean(),
23453
+ external_exports.array(external_exports.string().max(200)).max(20)
23454
+ ])
23455
+ ).optional()
23456
+ }).strict()
23457
+ ])
23458
+ ).min(1).max(8)
23459
+ }).strict().optional(),
22577
23460
  publishable: external_exports.object({
22578
23461
  content: external_exports.array(external_exports.string().max(40)).min(1).max(40),
22579
23462
  slug: external_exports.string().max(40).optional(),
@@ -22690,6 +23573,7 @@ var manifestSchema = external_exports.object({
22690
23573
  contractVersion: external_exports.number().int(),
22691
23574
  label: external_exports.string().max(100).optional(),
22692
23575
  description: external_exports.string().max(2e3).optional(),
23576
+ requires: external_exports.array(external_exports.string().regex(/^[a-z][a-z0-9]*$/)).max(10).optional(),
22693
23577
  permissions: permissionsManifestSchema.default({
22694
23578
  read: [],
22695
23579
  write: [],
@@ -22709,52 +23593,55 @@ var manifestSchema = external_exports.object({
22709
23593
  /** Tool permissions an admin may grant one by one (ADR 0449). */
22710
23594
  grantable: external_exports.array(external_exports.string().max(80)).max(20).optional()
22711
23595
  });
22712
- function checkDocumentField(path, name, field, fields, known, contract) {
22713
- if (field.type === "image") {
23596
+ function checkDocumentField(path2, name, field, fields, known, contract) {
23597
+ if (field.type === "image" || field.type === "video") {
22714
23598
  for (const key of ["schema", "maxBytes", "paths"]) {
22715
23599
  if (field[key] !== void 0) {
22716
- contract(`${path}.${key}`, `An image field has the platform's schema and no ${key}`);
23600
+ contract(
23601
+ `${path2}.${key}`,
23602
+ `An ${field.type} field has the platform's schema and no ${key}`
23603
+ );
22717
23604
  }
22718
23605
  }
22719
- if (field.track) contract(`${path}.track`, "An image is not tracked on the timeline");
23606
+ if (field.track) contract(`${path2}.track`, `An ${field.type} is not tracked on the timeline`);
22720
23607
  return;
22721
23608
  }
22722
23609
  if (field.type === "richText") {
22723
23610
  for (const key of ["schema", "paths"]) {
22724
23611
  if (field[key] !== void 0) {
22725
- contract(`${path}.${key}`, `A richText field has the platform's schema and no ${key}`);
23612
+ contract(`${path2}.${key}`, `A richText field has the platform's schema and no ${key}`);
22726
23613
  }
22727
23614
  }
22728
- if (field.track) contract(`${path}.track`, "Rich text is not tracked on the timeline");
23615
+ if (field.track) contract(`${path2}.track`, "Rich text is not tracked on the timeline");
22729
23616
  if (field.maxBytes !== void 0 && (field.maxBytes < 1024 || field.maxBytes > DOCUMENT_MAX_BYTES)) {
22730
- contract(`${path}.maxBytes`, `maxBytes is from 1024 to ${DOCUMENT_MAX_BYTES}`);
23617
+ contract(`${path2}.maxBytes`, `maxBytes is from 1024 to ${DOCUMENT_MAX_BYTES}`);
22731
23618
  }
22732
23619
  return;
22733
23620
  }
22734
23621
  if (field.type !== "document") {
22735
23622
  for (const key of ["schema", "maxBytes", "paths"]) {
22736
23623
  if (field[key] !== void 0) {
22737
- contract(`${path}.${key}`, `Only document and richText fields take ${key}`);
23624
+ contract(`${path2}.${key}`, `Only document and richText fields take ${key}`);
22738
23625
  }
22739
23626
  }
22740
23627
  return;
22741
23628
  }
22742
- if (field.track) contract(`${path}.track`, "A document is not tracked on the timeline");
23629
+ if (field.track) contract(`${path2}.track`, "A document is not tracked on the timeline");
22743
23630
  if (!field.schema) {
22744
- contract(`${path}.schema`, "A document field declares its schema");
23631
+ contract(`${path2}.schema`, "A document field declares its schema");
22745
23632
  return;
22746
23633
  }
22747
- const problems = checkDocumentSchema(field.schema, known);
22748
- for (const [at, message] of problems) contract(`${path}.schema${at ? `.${at}` : ""}`, message);
23634
+ const problems = checkDocumentSchema(field.schema, /* @__PURE__ */ new Set([...known, "media"]));
23635
+ for (const [at, message] of problems) contract(`${path2}.schema${at ? `.${at}` : ""}`, message);
22749
23636
  if (field.maxBytes !== void 0 && (field.maxBytes < 1024 || field.maxBytes > DOCUMENT_MAX_BYTES)) {
22750
- contract(`${path}.maxBytes`, `maxBytes is from 1024 to ${DOCUMENT_MAX_BYTES}`);
23637
+ contract(`${path2}.maxBytes`, `maxBytes is from 1024 to ${DOCUMENT_MAX_BYTES}`);
22751
23638
  }
22752
23639
  const paths = Object.entries(field.paths ?? {});
22753
23640
  if (paths.length > DOCUMENT_MAX_PATHS) {
22754
- contract(`${path}.paths`, `A document declares at most ${DOCUMENT_MAX_PATHS} paths`);
23641
+ contract(`${path2}.paths`, `A document declares at most ${DOCUMENT_MAX_PATHS} paths`);
22755
23642
  }
22756
23643
  for (const [pathName, spec] of paths) {
22757
- const at = `${path}.paths.${pathName}`;
23644
+ const at = `${path2}.paths.${pathName}`;
22758
23645
  if (!FIELD_NAME_RE.test(pathName) || RESERVED_FIELD_NAMES.has(pathName)) {
22759
23646
  contract(at, `A path's name is a camelCase field name that is not reserved`);
22760
23647
  }
@@ -22863,6 +23750,7 @@ function toManifest(extension) {
22863
23750
  ])
22864
23751
  ),
22865
23752
  ...extension.grantable ? { grantable: [...extension.grantable] } : {},
23753
+ ...extension.requires?.length ? { requires: [...extension.requires] } : {},
22866
23754
  roles: Object.fromEntries(
22867
23755
  Object.entries(extension.roles ?? {}).map(([name, role]) => [
22868
23756
  name,
@@ -22955,7 +23843,7 @@ function formulaFields(fields) {
22955
23843
  }
22956
23844
  function validateManifest(input2, options = {}) {
22957
23845
  const issues = [];
22958
- const contract = (path, message) => issues.push({ code: "contract", path, message });
23846
+ const contract = (path2, message) => issues.push({ code: "contract", path: path2, message });
22959
23847
  const parsed = manifestSchema.safeParse(input2);
22960
23848
  if (!parsed.success) {
22961
23849
  for (const issue2 of parsed.error.issues) {
@@ -22986,129 +23874,129 @@ function validateManifest(input2, options = {}) {
22986
23874
  ]);
22987
23875
  const checkFields = (base, object3, fields, env) => {
22988
23876
  for (const [name, field] of Object.entries(fields)) {
22989
- const path = `${base}.${name}`;
23877
+ const path2 = `${base}.${name}`;
22990
23878
  if (!FIELD_NAME_RE.test(name)) {
22991
23879
  contract(
22992
- path,
23880
+ path2,
22993
23881
  `Field name "${name}" must be camelCase letters and digits, starting lowercase`
22994
23882
  );
22995
23883
  }
22996
- if (RESERVED_FIELD_NAMES.has(name)) contract(path, `"${name}" is reserved on every record`);
23884
+ if (RESERVED_FIELD_NAMES.has(name)) contract(path2, `"${name}" is reserved on every record`);
22997
23885
  if (field.renamedFrom !== void 0 && !FIELD_NAME_RE.test(field.renamedFrom)) {
22998
- contract(`${path}.renamedFrom`, "renamedFrom must be a valid field name");
23886
+ contract(`${path2}.renamedFrom`, "renamedFrom must be a valid field name");
22999
23887
  }
23000
23888
  if (field.renamedFrom === name)
23001
- contract(`${path}.renamedFrom`, "renamedFrom equals the name");
23889
+ contract(`${path2}.renamedFrom`, "renamedFrom equals the name");
23002
23890
  if (field.type === "select" || field.type === "multiSelect") {
23003
23891
  if (!field.options?.length)
23004
- contract(`${path}.options`, `${field.type} fields need options`);
23892
+ contract(`${path2}.options`, `${field.type} fields need options`);
23005
23893
  const values = field.options?.map((o) => o.value) ?? [];
23006
23894
  if (new Set(values).size !== values.length) {
23007
- contract(`${path}.options`, "Option values must be unique");
23895
+ contract(`${path2}.options`, "Option values must be unique");
23008
23896
  }
23009
23897
  for (const option of field.options ?? []) {
23010
23898
  if (!option.requires?.length) continue;
23011
23899
  if (field.type !== "select") {
23012
- contract(`${path}.options`, "Only select fields take `requires`");
23900
+ contract(`${path2}.options`, "Only select fields take `requires`");
23013
23901
  continue;
23014
23902
  }
23015
23903
  for (const required2 of option.requires) {
23016
23904
  if (!(required2 in fields)) {
23017
23905
  contract(
23018
- `${path}.options`,
23906
+ `${path2}.options`,
23019
23907
  `Option "${option.value}" requires "${required2}", which is not a field here`
23020
23908
  );
23021
23909
  }
23022
23910
  }
23023
23911
  }
23024
23912
  if (!field.editableOptions && field.options?.some((o) => o.fixed !== void 0)) {
23025
- contract(`${path}.options`, "Only fields with editableOptions take `fixed`");
23913
+ contract(`${path2}.options`, "Only fields with editableOptions take `fixed`");
23026
23914
  }
23027
23915
  } else if (field.options) {
23028
- contract(`${path}.options`, `Only select and multiSelect fields take options`);
23916
+ contract(`${path2}.options`, `Only select and multiSelect fields take options`);
23029
23917
  }
23030
23918
  if (field.editableOptions !== void 0 && field.type !== "select" && field.type !== "multiSelect") {
23031
23919
  contract(
23032
- `${path}.editableOptions`,
23920
+ `${path2}.editableOptions`,
23033
23921
  "Only select and multiSelect fields take editableOptions"
23034
23922
  );
23035
23923
  }
23036
23924
  if (field.type === "relation") {
23037
- if (!field.to) contract(`${path}.to`, "relation fields need `to`");
23925
+ if (!field.to) contract(`${path2}.to`, "relation fields need `to`");
23038
23926
  else if (!RELATION_CORE_TARGETS.includes(field.to) && !(field.to.includes(".") && known.has(field.to))) {
23039
23927
  contract(
23040
- `${path}.to`,
23928
+ `${path2}.to`,
23041
23929
  `Unknown relation target "${field.to}". Use person, organisation, task or <extension>.<object>`
23042
23930
  );
23043
23931
  }
23044
23932
  } else if (field.to !== void 0 || field.many !== void 0) {
23045
- contract(path, "Only relation fields take `to` and `many`");
23933
+ contract(path2, "Only relation fields take `to` and `many`");
23046
23934
  }
23047
23935
  if (field.type === "currency" && field.currency === void 0) {
23048
23936
  } else if (field.type !== "currency" && field.currency !== void 0) {
23049
- contract(`${path}.currency`, "Only currency fields take `currency`");
23937
+ contract(`${path2}.currency`, "Only currency fields take `currency`");
23050
23938
  }
23051
23939
  if (field.readOnly && field.required) {
23052
- contract(`${path}.readOnly`, "A read-only field is set by the host and cannot be required");
23940
+ contract(`${path2}.readOnly`, "A read-only field is set by the host and cannot be required");
23053
23941
  }
23054
- checkDocumentField(path, name, field, fields, known, contract);
23942
+ checkDocumentField(path2, name, field, fields, known, contract);
23055
23943
  if (["number", "currency", "percent"].includes(field.type)) {
23056
23944
  if (field.min !== void 0 && field.max !== void 0 && field.min > field.max) {
23057
- contract(`${path}.min`, "min is above max");
23945
+ contract(`${path2}.min`, "min is above max");
23058
23946
  }
23059
23947
  if (typeof field.default === "number") {
23060
23948
  const d = field.default;
23061
23949
  const step = field.step;
23062
23950
  if (field.min !== void 0 && d < field.min || field.max !== void 0 && d > field.max || step !== void 0 && !onStep(d, field.min ?? 0, step)) {
23063
- contract(`${path}.default`, "The default is outside the field's min, max or step");
23951
+ contract(`${path2}.default`, "The default is outside the field's min, max or step");
23064
23952
  }
23065
23953
  }
23066
23954
  } else {
23067
23955
  for (const key of ["min", "max", "step"]) {
23068
23956
  if (field[key] !== void 0)
23069
- contract(`${path}.${key}`, `Only number fields take ${key}`);
23957
+ contract(`${path2}.${key}`, `Only number fields take ${key}`);
23070
23958
  }
23071
23959
  }
23072
23960
  if (field.type === "formula") {
23073
- if (field.required) contract(`${path}.required`, "Formula fields cannot be required");
23961
+ if (field.required) contract(`${path2}.required`, "Formula fields cannot be required");
23074
23962
  if (field.track)
23075
- contract(`${path}.track`, "Formula fields cannot be tracked on the timeline");
23963
+ contract(`${path2}.track`, "Formula fields cannot be tracked on the timeline");
23076
23964
  if (!field.expression?.trim()) {
23077
- contract(`${path}.expression`, "formula fields need an expression");
23965
+ contract(`${path2}.expression`, "formula fields need an expression");
23078
23966
  } else {
23079
23967
  const result = checkFormula(field.expression, { fields: env }, name);
23080
23968
  if (!result.ok) {
23081
23969
  issues.push({
23082
23970
  code: result.issue.code,
23083
- path: `${path}.expression`,
23971
+ path: `${path2}.expression`,
23084
23972
  message: `${object3}.${name}: ${result.issue.message}`,
23085
23973
  span: result.issue.span
23086
23974
  });
23087
23975
  }
23088
23976
  }
23089
23977
  } else if (field.expression !== void 0) {
23090
- contract(`${path}.expression`, "Only formula fields take an expression");
23978
+ contract(`${path2}.expression`, "Only formula fields take an expression");
23091
23979
  }
23092
23980
  }
23093
23981
  };
23094
23982
  for (const [name, object3] of Object.entries(m.objects)) {
23095
- const path = `objects.${name}`;
23983
+ const path2 = `objects.${name}`;
23096
23984
  if (!OBJECT_NAME_RE.test(name)) {
23097
23985
  contract(
23098
- path,
23986
+ path2,
23099
23987
  `Object name "${name}" must be lowercase letters and digits, starting with a letter`
23100
23988
  );
23101
23989
  }
23102
- if (RESERVED_OBJECT_NAMES.has(name)) contract(path, `"${name}" is a reserved object name`);
23990
+ if (RESERVED_OBJECT_NAMES.has(name)) contract(path2, `"${name}" is a reserved object name`);
23103
23991
  if (object3.renamedFrom !== void 0 && !OBJECT_NAME_RE.test(object3.renamedFrom)) {
23104
- contract(`${path}.renamedFrom`, "renamedFrom must be a valid object name");
23992
+ contract(`${path2}.renamedFrom`, "renamedFrom must be a valid object name");
23105
23993
  }
23106
23994
  const title = object3.fields[object3.titleField];
23107
23995
  if (!title) {
23108
- contract(`${path}.titleField`, `titleField "${object3.titleField}" is not a field of ${name}`);
23996
+ contract(`${path2}.titleField`, `titleField "${object3.titleField}" is not a field of ${name}`);
23109
23997
  } else if (!TEXT_LIKE.includes(title.type)) {
23110
23998
  contract(
23111
- `${path}.titleField`,
23999
+ `${path2}.titleField`,
23112
24000
  `titleField must be a text-like field (${TEXT_LIKE.join(", ")})`
23113
24001
  );
23114
24002
  }
@@ -23117,75 +24005,79 @@ function validateManifest(input2, options = {}) {
23117
24005
  updatedAt: { type: "datetime", sql: '"updated_at"' },
23118
24006
  ...formulaFields(object3.fields)
23119
24007
  };
23120
- checkFields(`${path}.fields`, `${m.id}.${name}`, object3.fields, env);
24008
+ checkFields(`${path2}.fields`, `${m.id}.${name}`, object3.fields, env);
23121
24009
  checkObjectBehaviour(m, name, object3, contract);
23122
24010
  checkObjectCapacity(m, name, object3, contract);
23123
24011
  checkObjectSellable(m, name, object3, contract);
24012
+ checkObjectAllowance(m, name, object3, contract);
23124
24013
  checkObjectStates(m, name, object3, contract);
24014
+ checkObjectClaims(m, name, object3, contract);
24015
+ checkObjectUnique(m, name, object3, contract);
24016
+ checkObjectRecurring(m, name, object3, contract);
23125
24017
  object3.requireOneOf?.forEach((group, i) => {
23126
24018
  for (const field of group) {
23127
24019
  if (!object3.fields[field]) {
23128
- contract(`${path}.requireOneOf.${i}`, `"${field}" is not a field of ${name}`);
24020
+ contract(`${path2}.requireOneOf.${i}`, `"${field}" is not a field of ${name}`);
23129
24021
  }
23130
24022
  }
23131
24023
  });
23132
24024
  for (const field of object3.titleDefault?.from ?? []) {
23133
24025
  if (object3.fields[field]?.type !== "relation") {
23134
- contract(`${path}.titleDefault`, `"${field}" is not a relation field of ${name}`);
24026
+ contract(`${path2}.titleDefault`, `"${field}" is not a relation field of ${name}`);
23135
24027
  }
23136
24028
  }
23137
- for (const [fieldName5, field] of Object.entries(object3.fields)) {
23138
- const fieldPath = `${path}.fields.${fieldName5}`;
24029
+ for (const [fieldName7, field] of Object.entries(object3.fields)) {
24030
+ const fieldPath2 = `${path2}.fields.${fieldName7}`;
23139
24031
  if (field.default !== void 0) {
23140
24032
  const expected = field.type === "boolean" ? "boolean" : ["number", "currency", "percent"].includes(field.type) ? "number" : ["text", "longText", "select", "date", "email", "phone", "url"].includes(field.type) ? "string" : null;
23141
- if (!expected) contract(`${fieldPath}.default`, `${field.type} fields take no default`);
24033
+ if (!expected) contract(`${fieldPath2}.default`, `${field.type} fields take no default`);
23142
24034
  else if (typeof field.default !== expected) {
23143
- contract(`${fieldPath}.default`, `The default must be a ${expected}`);
24035
+ contract(`${fieldPath2}.default`, `The default must be a ${expected}`);
23144
24036
  } else if (field.type === "select" && !field.options?.some((o) => o.value === field.default)) {
23145
- contract(`${fieldPath}.default`, "The default must be one of the options");
24037
+ contract(`${fieldPath2}.default`, "The default must be one of the options");
23146
24038
  }
23147
24039
  }
23148
24040
  if (field.defaultSetting !== void 0 && !m.settings[field.defaultSetting]) {
23149
24041
  contract(
23150
- `${fieldPath}.defaultSetting`,
24042
+ `${fieldPath2}.defaultSetting`,
23151
24043
  `"${field.defaultSetting}" is not one of this extension's settings`
23152
24044
  );
23153
24045
  }
23154
24046
  }
23155
24047
  if (object3.owner !== void 0) {
23156
24048
  const owner = object3.fields[object3.owner];
23157
- if (!owner) contract(`${path}.owner`, `owner "${object3.owner}" is not a field of ${name}`);
23158
- else if (owner.type !== "user") contract(`${path}.owner`, "owner must name a user field");
24049
+ if (!owner) contract(`${path2}.owner`, `owner "${object3.owner}" is not a field of ${name}`);
24050
+ else if (owner.type !== "user") contract(`${path2}.owner`, "owner must name a user field");
23159
24051
  }
23160
24052
  if (object3.customer !== void 0) {
23161
24053
  const c = object3.customer;
23162
24054
  const whose = object3.fields[c.field];
23163
24055
  if (!whose) {
23164
- contract(`${path}.customer.field`, `customer field "${c.field}" is not a field of ${name}`);
24056
+ contract(`${path2}.customer.field`, `customer field "${c.field}" is not a field of ${name}`);
23165
24057
  } else if (whose.type !== "relation" || whose.to !== "person" || whose.many) {
23166
- contract(`${path}.customer.field`, "customer.field must be a relation to one person");
24058
+ contract(`${path2}.customer.field`, "customer.field must be a relation to one person");
23167
24059
  }
23168
24060
  for (const key of ["read", "write"]) {
23169
24061
  if (new Set(c[key]).size !== c[key].length) {
23170
- contract(`${path}.customer.${key}`, `customer.${key} lists a field twice`);
24062
+ contract(`${path2}.customer.${key}`, `customer.${key} lists a field twice`);
23171
24063
  }
23172
- for (const fieldName5 of c[key]) {
23173
- if (!object3.fields[fieldName5]) {
24064
+ for (const fieldName7 of c[key]) {
24065
+ if (!object3.fields[fieldName7]) {
23174
24066
  contract(
23175
- `${path}.customer.${key}`,
23176
- `customer.${key} lists "${fieldName5}", which is not a field of ${name}`
24067
+ `${path2}.customer.${key}`,
24068
+ `customer.${key} lists "${fieldName7}", which is not a field of ${name}`
23177
24069
  );
23178
24070
  }
23179
24071
  }
23180
24072
  }
23181
- for (const fieldName5 of c.write) {
23182
- if (fieldName5 === c.field) {
23183
- contract(`${path}.customer.write`, "customer.write may not list the customer field");
24073
+ for (const fieldName7 of c.write) {
24074
+ if (fieldName7 === c.field) {
24075
+ contract(`${path2}.customer.write`, "customer.write may not list the customer field");
23184
24076
  }
23185
- if (!c.read.includes(fieldName5)) {
24077
+ if (!c.read.includes(fieldName7)) {
23186
24078
  contract(
23187
- `${path}.customer.write`,
23188
- `customer.write lists "${fieldName5}", which customer.read does not`
24079
+ `${path2}.customer.write`,
24080
+ `customer.write lists "${fieldName7}", which customer.read does not`
23189
24081
  );
23190
24082
  }
23191
24083
  }
@@ -23198,33 +24090,33 @@ function validateManifest(input2, options = {}) {
23198
24090
  })
23199
24091
  );
23200
24092
  for (const { name, object: object3, key, p } of readDeclarations) {
23201
- const path = `objects.${name}.${key}`;
24093
+ const path2 = `objects.${name}.${key}`;
23202
24094
  if (key === "public" && object3.customer) {
23203
- contract(path, "An object declares customer or public, not both");
24095
+ contract(path2, "An object declares customer or public, not both");
23204
24096
  }
23205
24097
  if (key === "signedIn" && object3.public) {
23206
24098
  contract(
23207
- path,
24099
+ path2,
23208
24100
  "An object declares public or signedIn, not both: the public's is read by customers too"
23209
24101
  );
23210
24102
  }
23211
24103
  if (new Set(p.read).size !== p.read.length)
23212
- contract(`${path}.read`, `${key}.read lists a field twice`);
23213
- for (const fieldName5 of p.read) {
23214
- const hostField = key === "public" && object3.publishable !== void 0 && (fieldName5 === "publishedAt" || fieldName5 === "publishedVersion");
23215
- if (!object3.fields[fieldName5] && !hostField) {
24104
+ contract(`${path2}.read`, `${key}.read lists a field twice`);
24105
+ for (const fieldName7 of p.read) {
24106
+ const hostField = key === "public" && object3.publishable !== void 0 && (fieldName7 === "publishedAt" || fieldName7 === "publishedVersion");
24107
+ if (!object3.fields[fieldName7] && !hostField) {
23216
24108
  contract(
23217
- `${path}.read`,
23218
- `${key}.read lists "${fieldName5}", which is not a field of ${name}`
24109
+ `${path2}.read`,
24110
+ `${key}.read lists "${fieldName7}", which is not a field of ${name}`
23219
24111
  );
23220
24112
  }
23221
24113
  }
23222
24114
  if (key === "signedIn" && object3.customer) {
23223
- for (const fieldName5 of p.read) {
23224
- if (!object3.customer.read.includes(fieldName5)) {
24115
+ for (const fieldName7 of p.read) {
24116
+ if (!object3.customer.read.includes(fieldName7)) {
23225
24117
  contract(
23226
- `${path}.read`,
23227
- `signedIn.read lists "${fieldName5}", which customer.read does not: a shared record shows no more than one's own`
24118
+ `${path2}.read`,
24119
+ `signedIn.read lists "${fieldName7}", which customer.read does not: a shared record shows no more than one's own`
23228
24120
  );
23229
24121
  }
23230
24122
  }
@@ -23238,7 +24130,7 @@ function validateManifest(input2, options = {}) {
23238
24130
  const pointed = local ? m.objects[local] : void 0;
23239
24131
  if (!pointed || !local) {
23240
24132
  contract(
23241
- `${path}.when.via`,
24133
+ `${path2}.when.via`,
23242
24134
  `${key}.when.via must name a relation of ${name} to one record of another of this extension's objects`
23243
24135
  );
23244
24136
  continue;
@@ -23248,41 +24140,41 @@ function validateManifest(input2, options = {}) {
23248
24140
  }
23249
24141
  const field = target.fields[p.when.field];
23250
24142
  if (!field || field.type !== "select") {
23251
- contract(`${path}.when.field`, `${key}.when.field must name a select field of ${targetName}`);
24143
+ contract(`${path2}.when.field`, `${key}.when.field must name a select field of ${targetName}`);
23252
24144
  continue;
23253
24145
  }
23254
24146
  const values = new Set((field.options ?? []).map((o) => typeof o === "string" ? o : o.value));
23255
24147
  for (const value of p.when.in) {
23256
24148
  if (!values.has(value)) {
23257
- contract(`${path}.when.in`, `"${value}" is not an option of ${targetName}.${p.when.field}`);
24149
+ contract(`${path2}.when.in`, `"${value}" is not an option of ${targetName}.${p.when.field}`);
23258
24150
  }
23259
24151
  }
23260
24152
  }
23261
24153
  for (const [name, object3] of Object.entries(m.objects)) {
23262
24154
  const p = object3.publishable;
23263
24155
  if (!p) continue;
23264
- const path = `objects.${name}.publishable`;
24156
+ const path2 = `objects.${name}.publishable`;
23265
24157
  if (new Set(p.content).size !== p.content.length) {
23266
- contract(`${path}.content`, "publishable.content lists a field twice");
24158
+ contract(`${path2}.content`, "publishable.content lists a field twice");
23267
24159
  }
23268
- for (const fieldName5 of p.content) {
23269
- const field = object3.fields[fieldName5];
24160
+ for (const fieldName7 of p.content) {
24161
+ const field = object3.fields[fieldName7];
23270
24162
  if (!field) {
23271
- contract(`${path}.content`, `"${fieldName5}" is not a field of ${name}`);
24163
+ contract(`${path2}.content`, `"${fieldName7}" is not a field of ${name}`);
23272
24164
  } else if (field.type === "formula" || field.readOnly) {
23273
24165
  contract(
23274
- `${path}.content`,
23275
- `"${fieldName5}" is ${field.type === "formula" ? "a formula" : "read-only"}: content is what staff edit`
24166
+ `${path2}.content`,
24167
+ `"${fieldName7}" is ${field.type === "formula" ? "a formula" : "read-only"}: content is what staff edit`
23276
24168
  );
23277
24169
  }
23278
24170
  }
23279
24171
  if (p.slug !== void 0) {
23280
24172
  const slug = object3.fields[p.slug];
23281
24173
  if (slug?.type !== "slug") {
23282
- contract(`${path}.slug`, `publishable.slug must name a slug field of ${name}`);
24174
+ contract(`${path2}.slug`, `publishable.slug must name a slug field of ${name}`);
23283
24175
  } else if (p.content.includes(p.slug)) {
23284
24176
  contract(
23285
- `${path}.slug`,
24177
+ `${path2}.slug`,
23286
24178
  "The slug is the record's address, not content: leave it out of content"
23287
24179
  );
23288
24180
  }
@@ -23290,28 +24182,28 @@ function validateManifest(input2, options = {}) {
23290
24182
  if (p.date !== void 0) {
23291
24183
  const date5 = object3.fields[p.date];
23292
24184
  if (!date5 || date5.type !== "date" && date5.type !== "datetime") {
23293
- contract(`${path}.date`, `publishable.date must name a date or datetime field of ${name}`);
24185
+ contract(`${path2}.date`, `publishable.date must name a date or datetime field of ${name}`);
23294
24186
  } else if (!p.content.includes(p.date)) {
23295
- contract(`${path}.date`, "publishable.date is content: list it in content too");
24187
+ contract(`${path2}.date`, "publishable.date is content: list it in content too");
23296
24188
  }
23297
24189
  }
23298
24190
  if (object3.public) {
23299
24191
  if (p.slug === void 0) {
23300
- contract(`${path}.slug`, "A publishable object the public reads names its slug field");
24192
+ contract(`${path2}.slug`, "A publishable object the public reads names its slug field");
23301
24193
  }
23302
- for (const fieldName5 of object3.public.read) {
23303
- const field = object3.fields[fieldName5];
24194
+ for (const fieldName7 of object3.public.read) {
24195
+ const field = object3.fields[fieldName7];
23304
24196
  if (field?.type === "formula") {
23305
24197
  contract(
23306
24198
  `objects.${name}.public.read`,
23307
- `public.read lists "${fieldName5}", a formula: on a publishable object a formula reads the working copy`
24199
+ `public.read lists "${fieldName7}", a formula: on a publishable object a formula reads the working copy`
23308
24200
  );
23309
24201
  }
23310
24202
  }
23311
24203
  }
23312
24204
  if (object3.customer || object3.customerVia) {
23313
24205
  contract(
23314
- path,
24206
+ path2,
23315
24207
  "A publishable object declares no customer or customerVia: what outsiders read of it is its published version"
23316
24208
  );
23317
24209
  }
@@ -23328,18 +24220,18 @@ function validateManifest(input2, options = {}) {
23328
24220
  for (const [name, object3] of Object.entries(m.objects)) {
23329
24221
  const v = object3.customerVia;
23330
24222
  if (!v) continue;
23331
- const path = `objects.${name}.customerVia`;
24223
+ const path2 = `objects.${name}.customerVia`;
23332
24224
  if (object3.customer) {
23333
- contract(path, "An object that declares a customer cannot also declare customerVia");
24225
+ contract(path2, "An object that declares a customer cannot also declare customerVia");
23334
24226
  }
23335
24227
  if (new Set(v.read).size !== v.read.length) {
23336
- contract(`${path}.read`, "customerVia.read lists a field twice");
24228
+ contract(`${path2}.read`, "customerVia.read lists a field twice");
23337
24229
  }
23338
- for (const fieldName5 of v.read) {
23339
- if (!object3.fields[fieldName5]) {
24230
+ for (const fieldName7 of v.read) {
24231
+ if (!object3.fields[fieldName7]) {
23340
24232
  contract(
23341
- `${path}.read`,
23342
- `customerVia.read lists "${fieldName5}", which is not a field of ${name}`
24233
+ `${path2}.read`,
24234
+ `customerVia.read lists "${fieldName7}", which is not a field of ${name}`
23343
24235
  );
23344
24236
  }
23345
24237
  }
@@ -23347,49 +24239,173 @@ function validateManifest(input2, options = {}) {
23347
24239
  const from = local ? m.objects[local] : void 0;
23348
24240
  if (!from || local === name) {
23349
24241
  contract(
23350
- `${path}.from`,
24242
+ `${path2}.from`,
23351
24243
  `customerVia.from must name another of this extension's objects, as ${m.id}.<object>`
23352
24244
  );
23353
24245
  continue;
23354
24246
  }
23355
24247
  if (!from.customer) {
23356
- contract(`${path}.from`, "customerVia.from must name an object that declares a customer");
24248
+ contract(`${path2}.from`, "customerVia.from must name an object that declares a customer");
23357
24249
  continue;
23358
24250
  }
23359
24251
  const pointer = from.fields[v.field];
23360
24252
  if (pointer?.type !== "relation" || pointer.many || pointer.to !== `${m.id}.${name}`) {
23361
24253
  contract(
23362
- `${path}.field`,
24254
+ `${path2}.field`,
23363
24255
  `customerVia.field must name a relation of ${local} to one ${name}`
23364
24256
  );
23365
24257
  } else if (!from.customer.read.includes(v.field)) {
23366
24258
  contract(
23367
- `${path}.field`,
24259
+ `${path2}.field`,
23368
24260
  `customerVia.field "${v.field}" must be one ${local}'s customer may read (customer.read)`
23369
24261
  );
23370
24262
  }
23371
24263
  }
24264
+ for (const [i, required2] of (m.requires ?? []).entries()) {
24265
+ if (required2 === m.id) contract(`requires.${i}`, "An extension does not require itself");
24266
+ if ((m.requires ?? []).indexOf(required2) !== i) {
24267
+ contract(`requires.${i}`, `"${required2}" is listed twice`);
24268
+ }
24269
+ }
24270
+ for (const [name, object3] of Object.entries(m.objects)) {
24271
+ for (const fieldName7 of object3.customer?.requireAccess ?? []) {
24272
+ const path2 = `objects.${name}.customer.requireAccess`;
24273
+ const field = object3.fields[fieldName7];
24274
+ const local = field?.to?.startsWith(`${m.id}.`) ? field.to.slice(m.id.length + 1) : null;
24275
+ const target = local ? m.objects[local] : void 0;
24276
+ if (field?.type !== "relation" || field.many || !target) {
24277
+ contract(
24278
+ path2,
24279
+ `"${fieldName7}" must be a relation of ${name} to one of this extension's objects`
24280
+ );
24281
+ } else if (!target.access) {
24282
+ contract(path2, `"${fieldName7}" points to ${local}, which declares no access`);
24283
+ } else if (!object3.customer?.read.includes(fieldName7)) {
24284
+ contract(path2, `"${fieldName7}" must be one the customer reads (customer.read)`);
24285
+ }
24286
+ }
24287
+ }
24288
+ for (const [name, object3] of Object.entries(m.objects)) {
24289
+ const a = object3.access;
24290
+ if (!a) continue;
24291
+ a.sources.forEach((given, i) => {
24292
+ const path2 = `objects.${name}.access.sources.${i}`;
24293
+ if ("kind" in given && given.kind === "subscription") {
24294
+ const options2 = given.options ?? {};
24295
+ for (const key of Object.keys(options2)) {
24296
+ if (key !== "plans" && key !== "covers") {
24297
+ contract(`${path2}.options.${key}`, `a subscription source has no option "${key}"`);
24298
+ }
24299
+ }
24300
+ if (options2.covers !== "all") {
24301
+ contract(`${path2}.options.covers`, 'covers must be "all": every live record');
24302
+ }
24303
+ const plans = typeof options2.plans === "string" ? options2.plans : "";
24304
+ const planLocal = plans.startsWith(`${m.id}.`) ? plans.slice(m.id.length + 1) : null;
24305
+ const plan = planLocal && planLocal !== name ? m.objects[planLocal] : void 0;
24306
+ if (!plan) {
24307
+ contract(
24308
+ `${path2}.options.plans`,
24309
+ `plans must name another of this extension's objects, as ${m.id}.<object>`
24310
+ );
24311
+ } else if (!plan.sellable?.recurring) {
24312
+ contract(
24313
+ `${path2}.options.plans`,
24314
+ "plans must name a plan: its sellable declares recurring"
24315
+ );
24316
+ }
24317
+ return;
24318
+ }
24319
+ if (!("via" in given)) return;
24320
+ const source = given;
24321
+ const local = source.via.startsWith(`${m.id}.`) ? source.via.slice(m.id.length + 1) : null;
24322
+ const via = local ? m.objects[local] : void 0;
24323
+ if (!via || local === name) {
24324
+ contract(
24325
+ `${path2}.via`,
24326
+ `via must name another of this extension's objects, as ${m.id}.<object>`
24327
+ );
24328
+ return;
24329
+ }
24330
+ if (!via.customer) {
24331
+ contract(`${path2}.via`, "via must name an object that declares a customer");
24332
+ return;
24333
+ }
24334
+ const pointer = via.fields[source.field];
24335
+ if (pointer?.type !== "relation" || pointer.many || !pointer.to) {
24336
+ contract(`${path2}.field`, `field must name a relation of ${local} to one record`);
24337
+ return;
24338
+ }
24339
+ if (source.through === void 0) {
24340
+ if (pointer.to !== `${m.id}.${name}`) {
24341
+ contract(`${path2}.field`, `field must be a relation of ${local} to one ${name}`);
24342
+ }
24343
+ } else {
24344
+ const targetLocal = pointer.to.startsWith(`${m.id}.`) ? pointer.to.slice(m.id.length + 1) : null;
24345
+ const target = targetLocal ? m.objects[targetLocal] : void 0;
24346
+ const list2 = target?.fields[source.through];
24347
+ const lists = list2?.type === "relation" && list2.many && list2.to === `${m.id}.${name}` || list2?.type === "document";
24348
+ if (!target || !lists) {
24349
+ contract(
24350
+ `${path2}.through`,
24351
+ `through must name a many relation to ${name}, or a document whose refs name it, on the object field points to`
24352
+ );
24353
+ }
24354
+ }
24355
+ if (via.states) {
24356
+ const stateField = via.fields[via.states.field];
24357
+ const known2 = new Set((stateField?.options ?? []).map((o) => o.value));
24358
+ const voids = new Set(
24359
+ Object.values(m.objects).flatMap((o) => {
24360
+ const g = o.sellable?.grants;
24361
+ return g && (g.object === local || g.object === source.via) ? [g.void] : [];
24362
+ })
24363
+ );
24364
+ if (!source.states?.length) {
24365
+ contract(`${path2}.states`, `${local} has states: name the ones that give access`);
24366
+ } else {
24367
+ for (const st of source.states) {
24368
+ if (!known2.has(st)) contract(`${path2}.states`, `"${st}" is not a state of ${local}`);
24369
+ if (voids.has(st)) {
24370
+ contract(
24371
+ `${path2}.states`,
24372
+ `"${st}" is where a refund moves ${local}: it gives no access`
24373
+ );
24374
+ }
24375
+ }
24376
+ }
24377
+ } else if (source.states !== void 0) {
24378
+ contract(`${path2}.states`, `${local} has no states`);
24379
+ }
24380
+ if (source.until !== void 0) {
24381
+ const until = via.fields[source.until];
24382
+ if (until?.type !== "date" && until?.type !== "datetime") {
24383
+ contract(`${path2}.until`, `until must name a date or datetime field of ${local}`);
24384
+ }
24385
+ }
24386
+ });
24387
+ }
23372
24388
  for (const [target, fields] of Object.entries(m.fields)) {
23373
- const path = `fields.${target}`;
24389
+ const path2 = `fields.${target}`;
23374
24390
  if (!known.has(target)) {
23375
- contract(path, `Unknown object "${target}". Use a core object or <extension>.<object>`);
24391
+ contract(path2, `Unknown object "${target}". Use a core object or <extension>.<object>`);
23376
24392
  continue;
23377
24393
  }
23378
24394
  if (target.startsWith(`${m.id}.`)) {
23379
- contract(path, "Declare fields of your own objects in objects.<name>.fields");
24395
+ contract(path2, "Declare fields of your own objects in objects.<name>.fields");
23380
24396
  continue;
23381
24397
  }
23382
- for (const [fieldName5, field] of Object.entries(fields)) {
24398
+ for (const [fieldName7, field] of Object.entries(fields)) {
23383
24399
  if (field.default !== void 0 || field.defaultSetting !== void 0) {
23384
- contract(`${path}.${fieldName5}`, "Only fields of your own objects take a default");
24400
+ contract(`${path2}.${fieldName7}`, "Only fields of your own objects take a default");
23385
24401
  }
23386
24402
  if (field.type === "slug") {
23387
- contract(`${path}.${fieldName5}`, "Only fields of your own objects can be a slug");
24403
+ contract(`${path2}.${fieldName7}`, "Only fields of your own objects can be a slug");
23388
24404
  }
23389
24405
  }
23390
24406
  const base = options.baseFields?.(target) ?? coreFormulaRefs(target);
23391
24407
  const env = { ...base, ...formulaFields(fields) };
23392
- checkFields(path, target, fields, env);
24408
+ checkFields(path2, target, fields, env);
23393
24409
  }
23394
24410
  for (const [name, tool] of Object.entries(m.tools)) {
23395
24411
  if (!TOOL_NAME_RE.test(name)) {
@@ -23432,16 +24448,16 @@ function validateManifest(input2, options = {}) {
23432
24448
  );
23433
24449
  continue;
23434
24450
  }
23435
- for (const fieldName5 of fieldNames) {
23436
- if (fieldName5 === "id" || fieldName5 === own2.customer.field) {
24451
+ for (const fieldName7 of fieldNames) {
24452
+ if (fieldName7 === "id" || fieldName7 === own2.customer.field) {
23437
24453
  contract(
23438
24454
  `tools.${name}.customerFields.${objectName2}`,
23439
- `A tool may never set "${fieldName5}": whose record it is, and its id, are the host's`
24455
+ `A tool may never set "${fieldName7}": whose record it is, and its id, are the host's`
23440
24456
  );
23441
- } else if (!own2.fields[fieldName5]) {
24457
+ } else if (!own2.fields[fieldName7]) {
23442
24458
  contract(
23443
24459
  `tools.${name}.customerFields.${objectName2}`,
23444
- `"${fieldName5}" is not a field of ${objectName2}`
24460
+ `"${fieldName7}" is not a field of ${objectName2}`
23445
24461
  );
23446
24462
  }
23447
24463
  }
@@ -23495,15 +24511,15 @@ function validateManifest(input2, options = {}) {
23495
24511
  Object.values(m.tools).flatMap((tool) => tool.permission ? [tool.permission] : [])
23496
24512
  );
23497
24513
  for (const [name, role] of Object.entries(m.roles)) {
23498
- const path = `roles.${name}`;
23499
- if (!FIELD_NAME_RE.test(name)) contract(path, `Role name "${name}" must be camelCase`);
24514
+ const path2 = `roles.${name}`;
24515
+ if (!FIELD_NAME_RE.test(name)) contract(path2, `Role name "${name}" must be camelCase`);
23500
24516
  if (!role.permissions.length && !role.read.length) {
23501
- contract(path, "A role holds at least one permission or reads at least one object");
24517
+ contract(path2, "A role holds at least one permission or reads at least one object");
23502
24518
  }
23503
24519
  for (const permission of role.permissions) {
23504
24520
  if (!declaredPermissions.has(permission)) {
23505
24521
  contract(
23506
- `${path}.permissions`,
24522
+ `${path2}.permissions`,
23507
24523
  `"${permission}" is not the permission of any of this extension's tools (tools.<name>.permission)`
23508
24524
  );
23509
24525
  }
@@ -23512,7 +24528,7 @@ function validateManifest(input2, options = {}) {
23512
24528
  const local = object3.startsWith(`${m.id}.`) ? object3.slice(m.id.length + 1) : null;
23513
24529
  if (!local || !m.objects[local]) {
23514
24530
  contract(
23515
- `${path}.read`,
24531
+ `${path2}.read`,
23516
24532
  `"${object3}" is not an object of this extension: a role reads ${m.id}.<object> only`
23517
24533
  );
23518
24534
  }
@@ -23540,11 +24556,11 @@ function validateManifest(input2, options = {}) {
23540
24556
  ["recordPanels", m.recordPanels]
23541
24557
  ]) {
23542
24558
  for (const [name, entry] of Object.entries(entries)) {
23543
- const path = `${kind}.${name}`;
23544
- if (!FIELD_NAME_RE.test(name)) contract(path, `${kind} names must be camelCase`);
23545
- if (!known.has(entry.on)) contract(`${path}.on`, `Unknown object "${entry.on}"`);
24559
+ const path2 = `${kind}.${name}`;
24560
+ if (!FIELD_NAME_RE.test(name)) contract(path2, `${kind} names must be camelCase`);
24561
+ if (!known.has(entry.on)) contract(`${path2}.on`, `Unknown object "${entry.on}"`);
23546
24562
  if (!known.has(entry.view.object)) {
23547
- contract(`${path}.view.object`, `Unknown object "${entry.view.object}"`);
24563
+ contract(`${path2}.view.object`, `Unknown object "${entry.view.object}"`);
23548
24564
  continue;
23549
24565
  }
23550
24566
  const own2 = entry.view.object.startsWith(`${m.id}.`) ? m.objects[entry.view.object.slice(m.id.length + 1)] : void 0;
@@ -23552,44 +24568,44 @@ function validateManifest(input2, options = {}) {
23552
24568
  const relation = own2.fields[entry.view.relation];
23553
24569
  if (!relation) {
23554
24570
  contract(
23555
- `${path}.view.relation`,
24571
+ `${path2}.view.relation`,
23556
24572
  `${entry.view.object} has no field "${entry.view.relation}"`
23557
24573
  );
23558
24574
  } else if (relation.type !== "relation" || relation.to !== entry.on) {
23559
24575
  contract(
23560
- `${path}.view.relation`,
24576
+ `${path2}.view.relation`,
23561
24577
  `${entry.view.object}.${entry.view.relation} must be a relation to ${entry.on}`
23562
24578
  );
23563
24579
  }
23564
24580
  for (const key of ["groupBy", "sumField", "dateField", "imageField"]) {
23565
24581
  const field = entry.view[key];
23566
24582
  if (field && !own2.fields[field]) {
23567
- contract(`${path}.view.${key}`, `${entry.view.object} has no field "${field}"`);
24583
+ contract(`${path2}.view.${key}`, `${entry.view.object} has no field "${field}"`);
23568
24584
  }
23569
24585
  }
23570
24586
  }
23571
24587
  if (entry.view.type === "board" && !entry.view.groupBy) {
23572
- contract(`${path}.view.groupBy`, "board views need groupBy");
24588
+ contract(`${path2}.view.groupBy`, "board views need groupBy");
23573
24589
  }
23574
24590
  if (entry.view.type === "calendar" && !entry.view.dateField) {
23575
- contract(`${path}.view.dateField`, "calendar views need dateField");
24591
+ contract(`${path2}.view.dateField`, "calendar views need dateField");
23576
24592
  }
23577
24593
  }
23578
24594
  }
23579
24595
  for (const [name, setting] of Object.entries(m.settings)) {
23580
- const path = `settings.${name}`;
23581
- if (!FIELD_NAME_RE.test(name)) contract(path, "Setting names must be camelCase");
24596
+ const path2 = `settings.${name}`;
24597
+ if (!FIELD_NAME_RE.test(name)) contract(path2, "Setting names must be camelCase");
23582
24598
  if (setting.type === "select") {
23583
- if (!setting.options?.length) contract(`${path}.options`, "select settings need options");
24599
+ if (!setting.options?.length) contract(`${path2}.options`, "select settings need options");
23584
24600
  if (setting.default !== void 0 && !setting.options?.some((o) => o.value === setting.default)) {
23585
- contract(`${path}.default`, "The default must be one of the options");
24601
+ contract(`${path2}.default`, "The default must be one of the options");
23586
24602
  }
23587
24603
  } else if (setting.options) {
23588
- contract(`${path}.options`, "Only select settings take options");
24604
+ contract(`${path2}.options`, "Only select settings take options");
23589
24605
  }
23590
24606
  const expected = { text: "string", select: "string", number: "number", boolean: "boolean" };
23591
24607
  if (setting.default !== void 0 && typeof setting.default !== expected[setting.type]) {
23592
- contract(`${path}.default`, `The default must be a ${expected[setting.type]}`);
24608
+ contract(`${path2}.default`, `The default must be a ${expected[setting.type]}`);
23593
24609
  }
23594
24610
  }
23595
24611
  for (const [name, automation] of Object.entries(m.automations)) {
@@ -23656,6 +24672,32 @@ function mediaProblem(bytes) {
23656
24672
  }
23657
24673
  return null;
23658
24674
  }
24675
+ var MEDIA_KINDS = ["image", "video", "file"];
24676
+ var MEDIA_FILE_TYPES = ["application/pdf"];
24677
+ var MEDIA_VIDEO_TYPE = "video/stream";
24678
+ var MEDIA_FILE_MAX_BYTES = 50 * 1024 * 1024;
24679
+ var MEDIA_VIDEO_MAX_BYTES = 30 * 1e3 * 1e3 * 1e3 - 1;
24680
+ var MEDIA_VIDEO_MAX_SECONDS = 6 * 60 * 60;
24681
+ var MEDIA_CAPTION_MAX_BYTES = 10 * 1024 * 1024;
24682
+ function sniffFileType(bytes) {
24683
+ return ascii(bytes, 0, "%PDF-") ? "application/pdf" : null;
24684
+ }
24685
+ function sniffUpload(bytes) {
24686
+ const image = sniffMediaType(bytes);
24687
+ if (image) return { kind: "image", type: image };
24688
+ const file2 = sniffFileType(bytes);
24689
+ return file2 ? { kind: "file", type: file2 } : null;
24690
+ }
24691
+ function maxBytesOf(kind) {
24692
+ return kind === "file" ? MEDIA_FILE_MAX_BYTES : MEDIA_MAX_BYTES;
24693
+ }
24694
+ function isWebVtt(bytes) {
24695
+ const at = bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191 ? 3 : 0;
24696
+ if (!ascii(bytes, at, "WEBVTT")) return false;
24697
+ const next = bytes[at + 6];
24698
+ return next === void 0 || next === 10 || next === 13 || next === 32 || next === 9;
24699
+ }
24700
+ var CAPTION_LANGUAGE_RE = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8}){0,2}$/;
23659
24701
 
23660
24702
  // ../sdk/src/permissions.ts
23661
24703
  function checkGrant(id, permissions, request) {
@@ -23733,7 +24775,12 @@ var blocks = {
23733
24775
  list: listShape(),
23734
24776
  quote: object2({ content: inlines, attribution: optional2(prose(300)) }),
23735
24777
  image: object2({
23736
- media: { type: "ref", to: RICH_TEXT_MEDIA_OBJECT, description: "The picture, from media" },
24778
+ media: {
24779
+ type: "ref",
24780
+ to: RICH_TEXT_MEDIA_OBJECT,
24781
+ media: "image",
24782
+ description: "The picture, from media"
24783
+ },
23737
24784
  alt: prose(500, { description: "What the picture shows, for people who cannot see it" }),
23738
24785
  caption: optional2(inlines)
23739
24786
  }),
@@ -23793,7 +24840,12 @@ var RICH_TEXT_SCHEMA = {
23793
24840
  };
23794
24841
  var IMAGE_SCHEMA = {
23795
24842
  root: object2({
23796
- media: { type: "ref", to: RICH_TEXT_MEDIA_OBJECT, description: "The picture, from media" },
24843
+ media: {
24844
+ type: "ref",
24845
+ to: RICH_TEXT_MEDIA_OBJECT,
24846
+ media: "image",
24847
+ description: "The picture, from media"
24848
+ },
23797
24849
  alt: prose(500, { description: "What the picture shows, for people who cannot see it" }),
23798
24850
  focal: optional2(
23799
24851
  object2({
@@ -23804,17 +24856,41 @@ var IMAGE_SCHEMA = {
23804
24856
  })
23805
24857
  };
23806
24858
  var IMAGE_MAX_BYTES = 2048;
24859
+ var VIDEO_NODE = object2({
24860
+ media: {
24861
+ type: "ref",
24862
+ to: RICH_TEXT_MEDIA_OBJECT,
24863
+ media: "video",
24864
+ description: "The video, from media (a ready one)"
24865
+ },
24866
+ poster: optional2({
24867
+ type: "ref",
24868
+ to: RICH_TEXT_MEDIA_OBJECT,
24869
+ media: "image",
24870
+ description: "A picture shown before it plays"
24871
+ })
24872
+ });
24873
+ var FILE_NODE = {
24874
+ type: "ref",
24875
+ to: RICH_TEXT_MEDIA_OBJECT,
24876
+ media: "file",
24877
+ description: "The file, from media"
24878
+ };
24879
+ var VIDEO_SCHEMA = { root: VIDEO_NODE };
24880
+ var VIDEO_MAX_BYTES = 1024;
23807
24881
  function isDocumentType(type) {
23808
- return type === "document" || type === "richText" || type === "image";
24882
+ return type === "document" || type === "richText" || type === "image" || type === "video";
23809
24883
  }
23810
24884
  function documentSchemaOf(field) {
23811
24885
  if (field.type === "richText") return RICH_TEXT_SCHEMA;
23812
24886
  if (field.type === "image") return IMAGE_SCHEMA;
24887
+ if (field.type === "video") return VIDEO_SCHEMA;
23813
24888
  if (field.type === "document") return field.schema;
23814
24889
  return void 0;
23815
24890
  }
23816
24891
  function documentMaxBytesOf(field) {
23817
24892
  if (field.type === "image") return IMAGE_MAX_BYTES;
24893
+ if (field.type === "video") return VIDEO_MAX_BYTES;
23818
24894
  if (field.maxBytes !== void 0) return field.maxBytes;
23819
24895
  return field.type === "richText" ? RICH_TEXT_DEFAULT_BYTES : void 0;
23820
24896
  }
@@ -24183,6 +25259,14 @@ export {
24183
25259
  custom,
24184
25260
  _instanceof,
24185
25261
  external_exports,
25262
+ ALLOWANCE_PERIODS,
25263
+ ALLOWANCE_VALUES,
25264
+ allowanceManifestSchema,
25265
+ spendsOnList,
25266
+ hostFilledFields,
25267
+ spenderAllows,
25268
+ customerWritable,
25269
+ checkObjectAllowance,
24186
25270
  CONTRACT_VERSION,
24187
25271
  SUPPORTED_CONTRACT_VERSIONS,
24188
25272
  GATEKEEPER_MODULES,
@@ -24222,6 +25306,8 @@ export {
24222
25306
  CAPACITY_VALUES,
24223
25307
  capacityManifestSchema,
24224
25308
  checkObjectCapacity,
25309
+ claimsManifestSchema,
25310
+ checkObjectClaims,
24225
25311
  DOCUMENT_MAX_BYTES,
24226
25312
  DOCUMENT_DEFAULT_BYTES,
24227
25313
  DOCUMENT_MAX_DEPTH,
@@ -24239,6 +25325,7 @@ export {
24239
25325
  validateDocument,
24240
25326
  formatDocumentIssue,
24241
25327
  documentRefs,
25328
+ documentMediaReach,
24242
25329
  redactDocument,
24243
25330
  FIELD_TYPES,
24244
25331
  formulaTypeOf,
@@ -24246,6 +25333,11 @@ export {
24246
25333
  isLosslessChange,
24247
25334
  FormulaError,
24248
25335
  compileFormula,
25336
+ WEEKDAYS,
25337
+ RECURRING_HORIZON_DAYS,
25338
+ RECURRING_HORIZON_MAX,
25339
+ recurringManifestSchema,
25340
+ checkObjectRecurring,
24249
25341
  OPS_MODULE,
24250
25342
  OLD_OPS_MODULE,
24251
25343
  OPS_SPECIFIER,
@@ -24258,9 +25350,13 @@ export {
24258
25350
  statesManifestSchema,
24259
25351
  moveOrigins,
24260
25352
  checkObjectStates,
25353
+ resolveFieldPath,
25354
+ TAX_CODE_PATTERN,
24261
25355
  GRANT_SOURCES,
24262
25356
  sellableManifestSchema,
24263
25357
  checkObjectSellable,
25358
+ uniqueManifestSchema,
25359
+ checkObjectUnique,
24264
25360
  EXTENSION_ID_RE,
24265
25361
  OBJECT_NAME_RE,
24266
25362
  FIELD_NAME_RE,
@@ -24293,6 +25389,18 @@ export {
24293
25389
  MEDIA_MAX_BYTES,
24294
25390
  sniffMediaType,
24295
25391
  mediaProblem,
25392
+ MEDIA_KINDS,
25393
+ MEDIA_FILE_TYPES,
25394
+ MEDIA_VIDEO_TYPE,
25395
+ MEDIA_FILE_MAX_BYTES,
25396
+ MEDIA_VIDEO_MAX_BYTES,
25397
+ MEDIA_VIDEO_MAX_SECONDS,
25398
+ MEDIA_CAPTION_MAX_BYTES,
25399
+ sniffFileType,
25400
+ sniffUpload,
25401
+ maxBytesOf,
25402
+ isWebVtt,
25403
+ CAPTION_LANGUAGE_RE,
24296
25404
  checkGrant,
24297
25405
  RICH_TEXT_BLOCKS,
24298
25406
  RICH_TEXT_MARKS,
@@ -24301,6 +25409,10 @@ export {
24301
25409
  RICH_TEXT_SCHEMA,
24302
25410
  IMAGE_SCHEMA,
24303
25411
  IMAGE_MAX_BYTES,
25412
+ VIDEO_NODE,
25413
+ FILE_NODE,
25414
+ VIDEO_SCHEMA,
25415
+ VIDEO_MAX_BYTES,
24304
25416
  isDocumentType,
24305
25417
  documentSchemaOf,
24306
25418
  documentMaxBytesOf,