@htilabs/platform-common-models 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +86 -0
  2. package/dist/age/index.cjs +136 -0
  3. package/dist/age/index.cjs.map +1 -0
  4. package/dist/age/index.d.cts +136 -0
  5. package/dist/age/index.d.ts +136 -0
  6. package/dist/age/index.js +105 -0
  7. package/dist/age/index.js.map +1 -0
  8. package/dist/index.cjs +159 -0
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +2 -1
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.js +150 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/share-rules/index.cjs +822 -0
  15. package/dist/share-rules/index.cjs.map +1 -0
  16. package/dist/share-rules/index.d.cts +804 -0
  17. package/dist/share-rules/index.d.ts +804 -0
  18. package/dist/share-rules/index.js +736 -0
  19. package/dist/share-rules/index.js.map +1 -0
  20. package/dist/sharing-ceiling/index.cjs +51 -0
  21. package/dist/sharing-ceiling/index.cjs.map +1 -1
  22. package/dist/sharing-ceiling/index.d.cts +87 -1
  23. package/dist/sharing-ceiling/index.d.ts +87 -1
  24. package/dist/sharing-ceiling/index.js +47 -0
  25. package/dist/sharing-ceiling/index.js.map +1 -1
  26. package/package.json +12 -1
  27. package/src/age/__tests__/ageFromDob.test.ts +192 -0
  28. package/src/age/ageFromDob.ts +269 -0
  29. package/src/age/index.ts +8 -0
  30. package/src/index.ts +4 -0
  31. package/src/shareRules/__tests__/caseShareLane.test.ts +259 -0
  32. package/src/shareRules/__tests__/magicLinkAddresses.test.ts +107 -0
  33. package/src/shareRules/__tests__/platformApps.test.ts +133 -0
  34. package/src/shareRules/__tests__/releaseTerms.test.ts +358 -0
  35. package/src/shareRules/__tests__/senderRoiPosture.test.ts +284 -0
  36. package/src/shareRules/__tests__/sharingMethods.test.ts +105 -0
  37. package/src/shareRules/caseShareLane.ts +289 -0
  38. package/src/shareRules/index.ts +31 -0
  39. package/src/shareRules/magicLinkAddresses.ts +185 -0
  40. package/src/shareRules/platformApps.ts +168 -0
  41. package/src/shareRules/releaseTerms.ts +359 -0
  42. package/src/shareRules/reportPurposes.ts +50 -0
  43. package/src/shareRules/senderRoiPosture.ts +296 -0
  44. package/src/shareRules/sharingMethods.ts +204 -0
  45. package/src/sharingCeiling/__tests__/threadLift.test.ts +353 -0
  46. package/src/sharingCeiling/coverage.ts +63 -0
  47. package/src/sharingCeiling/defaults.ts +106 -0
  48. package/src/sharingCeiling/index.ts +7 -0
@@ -314,5 +314,91 @@ declare function rowsExpandedByCeiling(scope: SharingCeilingScope, allowed: Shar
314
314
  * result.
315
315
  */
316
316
  declare function maskSelectionToCeiling(scope: SharingCeilingScope, selection: readonly string[] | null | undefined, allowed: SharingCeilingAllowed): string[];
317
+ /**
318
+ * The part of a ceiling a scope check reads: the v4 rows that may leave, or
319
+ * `null` when no ceiling binds.
320
+ */
321
+ interface SharingScopeCeiling {
322
+ readonly allowed: ReadonlySet<string> | readonly string[] | null;
323
+ }
324
+ /**
325
+ * Whether the ceiling permits one v4 ROW — the coverage rule
326
+ * ({@link scopeRowWithinCeiling}).
327
+ *
328
+ * - `null` ceiling or `allowed: null` ⇒ permitted (no ceiling binds).
329
+ * - System metadata (any row under `system`) ⇒ permitted (GDR 5.17
330
+ * clause 5 — provenance rides).
331
+ * - A code outside the tree ⇒ NOT permitted (fail closed).
332
+ */
333
+ declare function isPermittedByCeiling(scope: SharingCeilingScope, ceiling: SharingScopeCeiling | null, code: string): boolean;
334
+ /**
335
+ * What BOTH of two ceiling lists permit: a row of either list that is within
336
+ * the other (the coverage rule). A composer intersects its selected
337
+ * recipients' ceilings with this — one selection serves every recipient, so
338
+ * the narrowest wins.
339
+ */
340
+ declare function intersectSharingCeilingLists(scope: SharingCeilingScope, a: ReadonlySet<string> | readonly string[], b: ReadonlySet<string> | readonly string[]): string[];
341
+
342
+ /**
343
+ * The account's per-purpose DEFAULT share scope (C12b) — the prototype's
344
+ * `shareDefaultScopeFor`: the v4 rows a share of one purpose carries by the
345
+ * ACCOUNT's rule, before any recipient is named. The account's own
346
+ * `__default__` cell for the purpose, else the platform starter's
347
+ * `scopeByPurpose[purpose]`; `[]` when the purpose is off.
348
+ *
349
+ * Lifted unchanged from Thread `@thread/shared` `sharingCeiling.ts`
350
+ * L383-L427 @ thread develop f021be2 (`accountSharePurposePolicy`), so Thread
351
+ * and PAVE compute it once. Exported under the prototype's name
352
+ * {@link shareDefaultScopeFor}; {@link accountSharePurposePolicy} is the same
353
+ * function, kept so Thread's call sites do not change.
354
+ *
355
+ * It is the chain's `account_default` → `platform_default` tail
356
+ * (`effectiveCeiling`, ./chain.ts) — what every recipient without a partner
357
+ * rule is held to: the composer's and the release wizard's "your account's
358
+ * default for <purpose>" preset. Canon: prototype
359
+ * `HTI-LEADS-PAVE-Thread-prototype.html` @ d85f05b7 `shareEffectiveCeiling`
360
+ * L327966-L328090 (the chain's tail L328053-L328058); the off reading is
361
+ * clamp 1 (platform-prototype `src/data.js` @ a6f1f3a L51352-L51354).
362
+ *
363
+ * Pure: no mongoose, no I/O, no SOT import.
364
+ */
365
+
366
+ /**
367
+ * The account's standing on ONE share purpose, before any recipient is named
368
+ * — what the composer's purpose card shows beside each pill:
369
+ *
370
+ * - `off`: the purpose is switched off for the account (canon's clamp 1 —
371
+ * the platform row's `enabled: false`, or the account's own Share
372
+ * Purposes switch once the platform writes one; `isSharingPurposeDisabled`
373
+ * is the package's one test). An off purpose binds `[]` at every door, so
374
+ * the card renders it DISABLED-WITH-REASON (Terry ruling 2026-08-12:
375
+ * policy exclusions on this surface stay visible).
376
+ * - `accountDefault`: the v4 rows a share of that purpose carries by the
377
+ * ACCOUNT'S rule — the `__default__` cell the account authored, else the
378
+ * platform default (`starter.scopeByPurpose`); `[]` when off.
379
+ *
380
+ * `edits === null` (the store could not be read) → `[]` for every purpose,
381
+ * fail closed, like the ceiling itself.
382
+ */
383
+ interface AccountSharePurposePolicy {
384
+ readonly off: boolean;
385
+ readonly accountDefault: readonly string[];
386
+ }
387
+ /** The options {@link shareDefaultScopeFor} reads. */
388
+ interface ShareDefaultScopeOptions {
389
+ readonly starter?: SharingPlatformStarter;
390
+ /** The account's Share Purposes switches, when the platform writes them. */
391
+ readonly purposeOverrides?: Readonly<Record<string, boolean | undefined>> | null;
392
+ }
393
+ /**
394
+ * The account's default scope for `purpose` (see the module note). Total:
395
+ * never throws; a non-string entry in a stored list is dropped.
396
+ */
397
+ declare function shareDefaultScopeFor(edits: SharingScopeEdits | null | undefined, purpose: string, opts?: ShareDefaultScopeOptions): AccountSharePurposePolicy;
398
+ /**
399
+ * Thread's name for {@link shareDefaultScopeFor} — the SAME function (not a
400
+ * wrapper), kept so `@thread/shared` call sites do not change.
401
+ */
402
+ declare const accountSharePurposePolicy: typeof shareDefaultScopeFor;
317
403
 
318
- export { type EffectiveSharingCeiling, type EffectiveSharingCeilingInputs, HTI_SHARE_PLATFORM_PURPOSE_ENABLED, HTI_SHARE_PLATFORM_STARTER, HTI_SHARE_PLATFORM_STARTER_SOURCE, INFORMATION_SCOPE_FIELD_HOME_ROWS, SHARING_CEILING_DEFAULT_ROW_KEY, SHARING_CEILING_EXTERNAL_ROW_KEY, SHARING_CEILING_SCOPE_VERSION, type SharingCeilingAllowed, type SharingCeilingCellLike, type SharingCeilingRung, type SharingCeilingScope, type SharingPlatformStarter, type SharingPurposeLists, type SharingScopeEdits, ceilingCoverage, effectiveCeiling, hasOwnScopeContent, isCeilingCoverageRow, isSharingPurposeDisabled, maskSelectionToCeiling, rowsExpandedByCeiling, rowsOutsideCeiling, rowsOverCeiling, scopeRowWithinCeiling, sharingCeilingCellList, sharingCeilingRowKey, sharingScopeEditsFromCells };
404
+ export { type AccountSharePurposePolicy, type EffectiveSharingCeiling, type EffectiveSharingCeilingInputs, HTI_SHARE_PLATFORM_PURPOSE_ENABLED, HTI_SHARE_PLATFORM_STARTER, HTI_SHARE_PLATFORM_STARTER_SOURCE, INFORMATION_SCOPE_FIELD_HOME_ROWS, SHARING_CEILING_DEFAULT_ROW_KEY, SHARING_CEILING_EXTERNAL_ROW_KEY, SHARING_CEILING_SCOPE_VERSION, type ShareDefaultScopeOptions, type SharingCeilingAllowed, type SharingCeilingCellLike, type SharingCeilingRung, type SharingCeilingScope, type SharingPlatformStarter, type SharingPurposeLists, type SharingScopeCeiling, type SharingScopeEdits, accountSharePurposePolicy, ceilingCoverage, effectiveCeiling, hasOwnScopeContent, intersectSharingCeilingLists, isCeilingCoverageRow, isPermittedByCeiling, isSharingPurposeDisabled, maskSelectionToCeiling, rowsExpandedByCeiling, rowsOutsideCeiling, rowsOverCeiling, scopeRowWithinCeiling, shareDefaultScopeFor, sharingCeilingCellList, sharingCeilingRowKey, sharingScopeEditsFromCells };
@@ -314,5 +314,91 @@ declare function rowsExpandedByCeiling(scope: SharingCeilingScope, allowed: Shar
314
314
  * result.
315
315
  */
316
316
  declare function maskSelectionToCeiling(scope: SharingCeilingScope, selection: readonly string[] | null | undefined, allowed: SharingCeilingAllowed): string[];
317
+ /**
318
+ * The part of a ceiling a scope check reads: the v4 rows that may leave, or
319
+ * `null` when no ceiling binds.
320
+ */
321
+ interface SharingScopeCeiling {
322
+ readonly allowed: ReadonlySet<string> | readonly string[] | null;
323
+ }
324
+ /**
325
+ * Whether the ceiling permits one v4 ROW — the coverage rule
326
+ * ({@link scopeRowWithinCeiling}).
327
+ *
328
+ * - `null` ceiling or `allowed: null` ⇒ permitted (no ceiling binds).
329
+ * - System metadata (any row under `system`) ⇒ permitted (GDR 5.17
330
+ * clause 5 — provenance rides).
331
+ * - A code outside the tree ⇒ NOT permitted (fail closed).
332
+ */
333
+ declare function isPermittedByCeiling(scope: SharingCeilingScope, ceiling: SharingScopeCeiling | null, code: string): boolean;
334
+ /**
335
+ * What BOTH of two ceiling lists permit: a row of either list that is within
336
+ * the other (the coverage rule). A composer intersects its selected
337
+ * recipients' ceilings with this — one selection serves every recipient, so
338
+ * the narrowest wins.
339
+ */
340
+ declare function intersectSharingCeilingLists(scope: SharingCeilingScope, a: ReadonlySet<string> | readonly string[], b: ReadonlySet<string> | readonly string[]): string[];
341
+
342
+ /**
343
+ * The account's per-purpose DEFAULT share scope (C12b) — the prototype's
344
+ * `shareDefaultScopeFor`: the v4 rows a share of one purpose carries by the
345
+ * ACCOUNT's rule, before any recipient is named. The account's own
346
+ * `__default__` cell for the purpose, else the platform starter's
347
+ * `scopeByPurpose[purpose]`; `[]` when the purpose is off.
348
+ *
349
+ * Lifted unchanged from Thread `@thread/shared` `sharingCeiling.ts`
350
+ * L383-L427 @ thread develop f021be2 (`accountSharePurposePolicy`), so Thread
351
+ * and PAVE compute it once. Exported under the prototype's name
352
+ * {@link shareDefaultScopeFor}; {@link accountSharePurposePolicy} is the same
353
+ * function, kept so Thread's call sites do not change.
354
+ *
355
+ * It is the chain's `account_default` → `platform_default` tail
356
+ * (`effectiveCeiling`, ./chain.ts) — what every recipient without a partner
357
+ * rule is held to: the composer's and the release wizard's "your account's
358
+ * default for <purpose>" preset. Canon: prototype
359
+ * `HTI-LEADS-PAVE-Thread-prototype.html` @ d85f05b7 `shareEffectiveCeiling`
360
+ * L327966-L328090 (the chain's tail L328053-L328058); the off reading is
361
+ * clamp 1 (platform-prototype `src/data.js` @ a6f1f3a L51352-L51354).
362
+ *
363
+ * Pure: no mongoose, no I/O, no SOT import.
364
+ */
365
+
366
+ /**
367
+ * The account's standing on ONE share purpose, before any recipient is named
368
+ * — what the composer's purpose card shows beside each pill:
369
+ *
370
+ * - `off`: the purpose is switched off for the account (canon's clamp 1 —
371
+ * the platform row's `enabled: false`, or the account's own Share
372
+ * Purposes switch once the platform writes one; `isSharingPurposeDisabled`
373
+ * is the package's one test). An off purpose binds `[]` at every door, so
374
+ * the card renders it DISABLED-WITH-REASON (Terry ruling 2026-08-12:
375
+ * policy exclusions on this surface stay visible).
376
+ * - `accountDefault`: the v4 rows a share of that purpose carries by the
377
+ * ACCOUNT'S rule — the `__default__` cell the account authored, else the
378
+ * platform default (`starter.scopeByPurpose`); `[]` when off.
379
+ *
380
+ * `edits === null` (the store could not be read) → `[]` for every purpose,
381
+ * fail closed, like the ceiling itself.
382
+ */
383
+ interface AccountSharePurposePolicy {
384
+ readonly off: boolean;
385
+ readonly accountDefault: readonly string[];
386
+ }
387
+ /** The options {@link shareDefaultScopeFor} reads. */
388
+ interface ShareDefaultScopeOptions {
389
+ readonly starter?: SharingPlatformStarter;
390
+ /** The account's Share Purposes switches, when the platform writes them. */
391
+ readonly purposeOverrides?: Readonly<Record<string, boolean | undefined>> | null;
392
+ }
393
+ /**
394
+ * The account's default scope for `purpose` (see the module note). Total:
395
+ * never throws; a non-string entry in a stored list is dropped.
396
+ */
397
+ declare function shareDefaultScopeFor(edits: SharingScopeEdits | null | undefined, purpose: string, opts?: ShareDefaultScopeOptions): AccountSharePurposePolicy;
398
+ /**
399
+ * Thread's name for {@link shareDefaultScopeFor} — the SAME function (not a
400
+ * wrapper), kept so `@thread/shared` call sites do not change.
401
+ */
402
+ declare const accountSharePurposePolicy: typeof shareDefaultScopeFor;
317
403
 
318
- export { type EffectiveSharingCeiling, type EffectiveSharingCeilingInputs, HTI_SHARE_PLATFORM_PURPOSE_ENABLED, HTI_SHARE_PLATFORM_STARTER, HTI_SHARE_PLATFORM_STARTER_SOURCE, INFORMATION_SCOPE_FIELD_HOME_ROWS, SHARING_CEILING_DEFAULT_ROW_KEY, SHARING_CEILING_EXTERNAL_ROW_KEY, SHARING_CEILING_SCOPE_VERSION, type SharingCeilingAllowed, type SharingCeilingCellLike, type SharingCeilingRung, type SharingCeilingScope, type SharingPlatformStarter, type SharingPurposeLists, type SharingScopeEdits, ceilingCoverage, effectiveCeiling, hasOwnScopeContent, isCeilingCoverageRow, isSharingPurposeDisabled, maskSelectionToCeiling, rowsExpandedByCeiling, rowsOutsideCeiling, rowsOverCeiling, scopeRowWithinCeiling, sharingCeilingCellList, sharingCeilingRowKey, sharingScopeEditsFromCells };
404
+ export { type AccountSharePurposePolicy, type EffectiveSharingCeiling, type EffectiveSharingCeilingInputs, HTI_SHARE_PLATFORM_PURPOSE_ENABLED, HTI_SHARE_PLATFORM_STARTER, HTI_SHARE_PLATFORM_STARTER_SOURCE, INFORMATION_SCOPE_FIELD_HOME_ROWS, SHARING_CEILING_DEFAULT_ROW_KEY, SHARING_CEILING_EXTERNAL_ROW_KEY, SHARING_CEILING_SCOPE_VERSION, type ShareDefaultScopeOptions, type SharingCeilingAllowed, type SharingCeilingCellLike, type SharingCeilingRung, type SharingCeilingScope, type SharingPlatformStarter, type SharingPurposeLists, type SharingScopeCeiling, type SharingScopeEdits, accountSharePurposePolicy, ceilingCoverage, effectiveCeiling, hasOwnScopeContent, intersectSharingCeilingLists, isCeilingCoverageRow, isPermittedByCeiling, isSharingPurposeDisabled, maskSelectionToCeiling, rowsExpandedByCeiling, rowsOutsideCeiling, rowsOverCeiling, scopeRowWithinCeiling, shareDefaultScopeFor, sharingCeilingCellList, sharingCeilingRowKey, sharingScopeEditsFromCells };
@@ -426,6 +426,49 @@ function maskSelectionToCeiling(scope, selection, allowed) {
426
426
  for (const code of outside) sel = subtractRow(scope, sel, code);
427
427
  return withSystemInfo(sel.filter((c) => facts.isLive(c)));
428
428
  }
429
+ function isPermittedByCeiling(scope, ceiling, code) {
430
+ if (ceiling === null || ceiling.allowed === null) return true;
431
+ if (scope.ancestorsOf(code).includes("system")) {
432
+ return true;
433
+ }
434
+ if (scope.row(code) === void 0) return false;
435
+ return scopeRowWithinCeiling(scope, ceiling.allowed, code);
436
+ }
437
+ function intersectSharingCeilingLists(scope, a, b) {
438
+ const left = [...a];
439
+ const right = [...b];
440
+ const within = (list, code) => scopeRowWithinCeiling(scope, list, code);
441
+ return [
442
+ .../* @__PURE__ */ new Set([
443
+ ...left.filter((code) => within(right, code)),
444
+ ...right.filter((code) => within(left, code))
445
+ ])
446
+ ];
447
+ }
448
+
449
+ // src/sharingCeiling/defaults.ts
450
+ function shareDefaultScopeFor(edits, purpose, opts = {}) {
451
+ const off = isSharingPurposeDisabled(purpose, opts.purposeOverrides ?? null);
452
+ if (off || edits === null || edits === void 0) {
453
+ return { off, accountDefault: [] };
454
+ }
455
+ const starter = opts.starter ?? HTI_SHARE_PLATFORM_STARTER;
456
+ const authored = edits[SHARING_CEILING_DEFAULT_ROW_KEY]?.[purpose];
457
+ if (Array.isArray(authored)) {
458
+ return {
459
+ off,
460
+ accountDefault: authored.filter(
461
+ (v) => typeof v === "string"
462
+ )
463
+ };
464
+ }
465
+ const platform = starter.scopeByPurpose[purpose];
466
+ return {
467
+ off,
468
+ accountDefault: Array.isArray(platform) ? platform.filter((v) => typeof v === "string") : []
469
+ };
470
+ }
471
+ var accountSharePurposePolicy = shareDefaultScopeFor;
429
472
  export {
430
473
  HTI_SHARE_PLATFORM_PURPOSE_ENABLED,
431
474
  HTI_SHARE_PLATFORM_STARTER,
@@ -434,16 +477,20 @@ export {
434
477
  SHARING_CEILING_DEFAULT_ROW_KEY,
435
478
  SHARING_CEILING_EXTERNAL_ROW_KEY,
436
479
  SHARING_CEILING_SCOPE_VERSION,
480
+ accountSharePurposePolicy,
437
481
  ceilingCoverage,
438
482
  effectiveCeiling,
439
483
  hasOwnScopeContent,
484
+ intersectSharingCeilingLists,
440
485
  isCeilingCoverageRow,
486
+ isPermittedByCeiling,
441
487
  isSharingPurposeDisabled,
442
488
  maskSelectionToCeiling,
443
489
  rowsExpandedByCeiling,
444
490
  rowsOutsideCeiling,
445
491
  rowsOverCeiling,
446
492
  scopeRowWithinCeiling,
493
+ shareDefaultScopeFor,
447
494
  sharingCeilingCellList,
448
495
  sharingCeilingRowKey,
449
496
  sharingScopeEditsFromCells