@aglyn/aglyn 1.12.0 → 1.14.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 (64) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/crm.js +8 -7
  3. package/src/lib/app-utils/crm.js.map +1 -1
  4. package/src/lib/app-utils/docs-help-sections.generated.js +8 -2
  5. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  6. package/src/lib/app-utils/docs-help.generated.d.ts +1 -1
  7. package/src/lib/app-utils/docs-help.generated.js +7 -0
  8. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  9. package/src/lib/app-utils/docs-index.generated.js +48 -34
  10. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  11. package/src/lib/app-utils/dynamic-list-rule.js +9 -5
  12. package/src/lib/app-utils/dynamic-list-rule.js.map +1 -1
  13. package/src/lib/app-utils/host-permissions.d.ts +12 -0
  14. package/src/lib/app-utils/host-permissions.js +26 -1
  15. package/src/lib/app-utils/host-permissions.js.map +1 -1
  16. package/src/lib/app-utils/media-asset-facts.d.ts +2 -2
  17. package/src/lib/app-utils/media-asset-facts.js +4 -3
  18. package/src/lib/app-utils/media-asset-facts.js.map +1 -1
  19. package/src/lib/app-utils/media-cdn-scope.d.ts +19 -4
  20. package/src/lib/app-utils/media-cdn-scope.js +19 -5
  21. package/src/lib/app-utils/media-cdn-scope.js.map +1 -1
  22. package/src/lib/app-utils/media-ref.d.ts +10 -6
  23. package/src/lib/app-utils/media-ref.js +34 -8
  24. package/src/lib/app-utils/media-ref.js.map +1 -1
  25. package/src/lib/app-utils/native-nav.d.ts +2 -2
  26. package/src/lib/app-utils/native-nav.js +2 -2
  27. package/src/lib/app-utils/native-nav.js.map +1 -1
  28. package/src/lib/app-utils/org-permissions.d.ts +7 -0
  29. package/src/lib/app-utils/org-permissions.js +2 -0
  30. package/src/lib/app-utils/org-permissions.js.map +1 -1
  31. package/src/lib/app-utils/org-role-grants.d.ts +7 -0
  32. package/src/lib/app-utils/org-role-grants.js +7 -5
  33. package/src/lib/app-utils/org-role-grants.js.map +1 -1
  34. package/src/lib/app-utils/scope-tokens.d.ts +132 -3
  35. package/src/lib/app-utils/scope-tokens.js +276 -3
  36. package/src/lib/app-utils/scope-tokens.js.map +1 -1
  37. package/src/lib/app-utils/site-placement.d.ts +74 -0
  38. package/src/lib/app-utils/site-placement.js +80 -0
  39. package/src/lib/app-utils/site-placement.js.map +1 -0
  40. package/src/lib/app-utils/transfer-launcher-context.d.ts +17 -1
  41. package/src/lib/app-utils/transfer-launcher-context.js.map +1 -1
  42. package/src/lib/data-transfer/access.d.ts +10 -18
  43. package/src/lib/data-transfer/access.js +21 -25
  44. package/src/lib/data-transfer/access.js.map +1 -1
  45. package/src/lib/data-transfer/resource.d.ts +13 -14
  46. package/src/lib/data-transfer/resource.js +9 -10
  47. package/src/lib/data-transfer/resource.js.map +1 -1
  48. package/src/lib/plugin-manager/first-party-plugins.generated.js +3 -4
  49. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  50. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +10 -0
  51. package/src/lib/plugin-manager/plugin-contact-capture.js +11 -0
  52. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
  53. package/src/lib/plugin-manager/plugin-entitlements.d.ts +12 -0
  54. package/src/lib/plugin-manager/plugin-entitlements.js +3 -1
  55. package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
  56. package/src/lib/plugin-manager/plugin-scope-sharing.d.ts +52 -0
  57. package/src/lib/plugin-manager/plugin-scope-sharing.generated.d.ts +10 -0
  58. package/src/lib/plugin-manager/plugin-scope-sharing.generated.js +82 -0
  59. package/src/lib/plugin-manager/plugin-scope-sharing.generated.js.map +1 -0
  60. package/src/lib/plugin-manager/plugin-scope-sharing.js +85 -0
  61. package/src/lib/plugin-manager/plugin-scope-sharing.js.map +1 -0
  62. package/src/lib/plugin-manager/plugin-transfer-resources.d.ts +56 -1
  63. package/src/lib/plugin-manager/plugin-transfer-resources.js +13 -0
  64. package/src/lib/plugin-manager/plugin-transfer-resources.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/org-role-grants.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * WHAT EACH ORG ROLE MAY DO, AS DATA (AGL-243, AGL-3950).\n *\n * The core permission catalog and the core keys each org role holds when\n * nothing refines it. `org-permissions.ts` builds the console's live\n * catalog from these (adding the keys plugins declare, with their own role\n * defaults), and the native apps read the same grants through the generated\n * contracts, so a native gate (`hosts.create`, `data.manage`) answers as the\n * console does for a member row that carries no `resolvedPermissions` stamp.\n *\n * `ORG_ROLE_GRANTS` in the contracts is this table with every plugin's\n * declared catalog keys added (`assembleOrgRoleGrants`, run by\n * `generate:native-contracts` over each plugin's declarations), which is\n * exactly the set the console's `DEFAULT_ROLE_PERMISSIONS` holds once the\n * plugins have registered.\n *\n * NO IMPORTS, on purpose: the native apps read it through the generated\n * contracts.\n */\n\n/** The four org roles. */\nexport type OrgRoleName = 'owner' | 'admin' | 'editor' | 'viewer'\n\n/**\n * Where a key is decided (AGL-4047). `org`: by the member's org role, custom\n * role and overrides, the same on every site. `site`: as `org` for a member\n * who reaches the whole workspace, and per site for a site collaborator,\n * from the host role they hold there and that site's toggle.\n */\nexport type OrgPermissionScope = 'org' | 'site'\n\n/** One key of the org permission catalog. */\nexport interface OrgPermissionEntry {\n key: string\n label: string\n description: string\n /** The plugin that declared it; absent for a core key. */\n pluginId?: string\n /** The group the role editor files it under (`ORG_PERMISSION_GROUPS`, or the declaring plugin's id). */\n group?: string\n /** Where it is decided; absent reads as `org`. */\n scope?: OrgPermissionScope\n /**\n * The broader key this one is a finer part of (AGL-4047): never granted\n * without it, and following it where no custom role or override sets this\n * key. Absent for a key that refines nothing.\n */\n refines?: string\n /**\n * The key this one follows where no custom role or override sets it,\n * without needing it (AGL-4047): granted on its own, it holds while that\n * key is refused. Absent for a key that follows nothing, and for one that\n * refines.\n */\n follows?: string\n /**\n * Whether a site can narrow the key (`narrowsPerSite`, AGL-4047), so the\n * role and member editors offer its \"follow the site role\" choice. Absent\n * for a key a site cannot narrow.\n */\n narrowable?: boolean\n}\n\n/** A heading the role editor groups keys under. */\nexport interface OrgPermissionGroup {\n id: string\n label: string\n /** The plugin whose keys it holds; absent for a core group. */\n pluginId?: string\n}\n\n/** The catalog and each role's default grants. */\nexport interface OrgRoleGrants {\n /** Every key, in the order the role editor lists them. */\n permissions: OrgPermissionEntry[]\n /** The keys each role holds when no custom role or per-member override sets them. */\n grants: Record<OrgRoleName, string[]>\n /** The groups the keys are filed under, in display order; absent in a catalog written before them. */\n groups?: OrgPermissionGroup[]\n}\n\n/**\n * A key a plugin declares into the catalog: `PluginOrgPermissionDeclaration`\n * with org-role defaults, or a `registerPluginPermissions` key (`managePos`),\n * whose `defaults` are per role tier, the owner holding the admin tier's.\n */\nexport interface OrgPermissionDeclaration {\n key: string\n label: string\n description?: string\n roleDefaults?: Record<OrgRoleName, boolean>\n /** The tier defaults of a `registerPluginPermissions` key, used when `roleDefaults` is absent. */\n defaults?: { admin: boolean; editor: boolean; viewer: boolean }\n /** The host-role defaults of a key a site collaborator holds per site. */\n hostRoleDefaults?: Record<string, boolean>\n /** The group it is filed under; absent: a group named by the declaring plugin's id. */\n group?: string\n /** That group's heading, for a group the core does not name. */\n groupLabel?: string\n pluginId?: string\n /** The broader key it refines (AGL-4047). */\n refines?: string\n /** The key it follows without needing it (AGL-4047). */\n follows?: string\n}\n\n/** A custom role (`orgs/{orgId}/roles/{roleId}`) or a member's overrides: explicit verdicts per key. */\nexport interface OrgPermissionLayer {\n permissions?: Record<string, boolean>\n}\n\nexport const ORG_ROLE_NAMES: readonly OrgRoleName[] = ['owner', 'admin', 'editor', 'viewer']\n\n/**\n * The core groups, in display order. A plugin's keys are filed under a group\n * named by the plugin's id unless its declaration names one of these, so no\n * core group id is a plugin id.\n */\nexport const CORE_ORG_PERMISSION_GROUPS: readonly OrgPermissionGroup[] = [\n { id: 'organization', label: 'Organization' },\n { id: 'billing', label: 'Billing' },\n { id: 'team', label: 'Team' },\n { id: 'sites', label: 'Sites' },\n { id: 'datasets', label: 'Data' },\n { id: 'extensions', label: 'Marketplace and plugins' },\n]\n\n/**\n * A declaration's verdict for each org role: its `roleDefaults`, or, for a\n * `registerPluginPermissions` key, its tier `defaults` with the owner on the\n * admin tier (the tier `ORG_ROLE_TIER` resolves the owner onto).\n */\nexport function declarationRoleDefaults(\n declaration: Pick<OrgPermissionDeclaration, 'roleDefaults' | 'defaults'>,\n): Record<OrgRoleName, boolean> {\n if (declaration.roleDefaults) {\n return {\n owner: declaration.roleDefaults.owner === true,\n admin: declaration.roleDefaults.admin === true,\n editor: declaration.roleDefaults.editor === true,\n viewer: declaration.roleDefaults.viewer === true,\n }\n }\n const tiers = declaration.defaults\n return {\n owner: tiers?.admin === true,\n admin: tiers?.admin === true,\n editor: tiers?.editor === true,\n viewer: tiers?.viewer === true,\n }\n}\n\n/**\n * The core keys, in display order for role editors. Every key here is\n * enforced server-side (`apps/console/specs/org-permissions-are-enforced.spec.ts`).\n */\nexport const CORE_ORG_PERMISSION_ENTRIES: readonly OrgPermissionEntry[] = [\n {\n key: 'org.settings',\n group: 'organization',\n label: 'Organization settings',\n description: 'Rename the organization, change its slug, transfer it.',\n },\n {\n key: 'org.auditLog',\n group: 'organization',\n label: 'Activity & audit log',\n description: 'See the organization activity feed.',\n },\n {\n key: 'org.apiKeys',\n group: 'organization',\n label: 'Manage API keys',\n description: 'Create and revoke the workspace’s REST API keys.',\n },\n {\n key: 'org.privacy',\n group: 'organization',\n label: 'Privacy requests',\n description: 'Erase a person from every site in the workspace when they ask.',\n },\n {\n key: 'org.holds',\n group: 'organization',\n label: 'Holds and reviews',\n description: 'See what is held, flagged or locked on the workspace, and request a review.',\n },\n // Workspace acts that asked for the owner or admin role (AGL-4047), each\n // a key of its own whose default is exactly those roles.\n {\n key: 'org.export',\n group: 'organization',\n label: 'Export workspace data',\n description: 'Download a copy of everything the workspace holds.',\n },\n {\n key: 'org.sendingDomains',\n group: 'organization',\n label: 'Sending domains',\n description: 'Add, verify and remove the domains the workspace’s mail is sent from.',\n },\n {\n key: 'org.businessProfile',\n group: 'organization',\n label: 'Business profile',\n description: 'Change the services, audience and tone every site starts from.',\n },\n {\n key: 'billing.view',\n group: 'billing',\n label: 'View billing',\n description: 'See the plan, usage meters, and invoices.',\n },\n {\n key: 'billing.manage',\n group: 'billing',\n label: 'Manage billing',\n description: 'Change plans, buy add-ons, update payment details.',\n },\n {\n key: 'members.manage',\n group: 'team',\n label: 'Manage members',\n description: 'Invite, remove, and re-role organization members.',\n },\n {\n key: 'hosts.create',\n group: 'sites',\n label: 'Create sites',\n description: 'Create new sites in the organization.',\n },\n {\n key: 'hosts.delete',\n group: 'sites',\n label: 'Delete sites',\n description: 'Delete sites the member can access.',\n },\n // The site keys (AGL-4047): each replaced a gate on the member's role on a\n // site, and keeps that role as its preset (`CORE_SITE_ROLE_PRESETS`).\n {\n key: 'site.edit',\n group: 'sites',\n scope: 'site',\n label: 'Edit site content',\n description: 'Create and change pages, content and everything else on a site, without making it live.',\n },\n {\n key: 'site.publish',\n group: 'sites',\n scope: 'site',\n label: 'Publish site content',\n description: 'Make pages and content live, take them down or schedule them, change redirects and change the site’s fonts.',\n },\n {\n key: 'site.sensitive',\n group: 'sites',\n scope: 'site',\n label: 'See orders and webhooks',\n description: 'Read a site’s orders, returns and sending address, and set up its webhooks.',\n },\n {\n key: 'site.manage',\n group: 'sites',\n scope: 'site',\n label: 'Manage site settings',\n description: 'Manage a site’s people, domain, address and plugins, change its plugin settings (live chat, Zapier) and security allow-lists, import, export and delete it.',\n },\n {\n key: 'data.manage',\n group: 'datasets',\n label: 'Manage data',\n description: 'Create, edit, and delete organization datasets, the CRM’s records, and marketing lists and topics.',\n },\n // Workspace content that asked for the owner, admin or editor role\n // (AGL-4047), each a key whose default is exactly those roles.\n {\n key: 'org.media',\n group: 'datasets',\n label: 'Edit the workspace media library',\n description: 'Upload, change, move and remove the files in the media library every site shares.',\n },\n {\n key: 'org.eraseRecords',\n group: 'datasets',\n label: 'Delete workspace records',\n description: 'Delete records the whole workspace shares, such as dataset rows, contacts and lists.',\n },\n {\n key: 'marketplace.publish',\n group: 'extensions',\n label: 'Publish to marketplace',\n description: 'Publish listings under the organization profile.',\n },\n {\n key: 'plugins.install',\n group: 'extensions',\n label: 'Install plugins',\n description: 'Install or remove marketplace plugins.',\n },\n]\n\nconst CORE_KEYS = CORE_ORG_PERMISSION_ENTRIES.map((entry) => entry.key)\n\n/**\n * The core keys whose preset is the member's role ON THE SITE (AGL-4047), and\n * each site role's verdict: the sets the rules' `canWriteHostContent`,\n * `canPublishHostContent`, `canReadHostSensitive` and the site-admin checks\n * asked before they asked these keys. A member's preset on a site is the\n * verdict for the role they hold there (the owner and admins are Admin on\n * every site); a custom role, their own permissions and that site's toggle\n * then grant or refuse it. Each workspace role's default below is the verdict\n * for its own site role, which is the answer with no site named.\n */\nexport const CORE_SITE_ROLE_PRESETS: Readonly<Record<string, Readonly<Record<string, boolean>>>> = {\n 'site.edit': { admin: true, editor: true, author: true, viewer: false },\n 'site.publish': { admin: true, editor: true, author: false, viewer: false },\n 'site.sensitive': { admin: true, editor: true, author: false, viewer: false },\n 'site.manage': { admin: true, editor: false, author: false, viewer: false },\n}\n\n/** The workspace editor's site keys: its own site role's preset. */\nconst EDITOR_SITE_KEYS = Object.keys(CORE_SITE_ROLE_PRESETS).filter((key) => CORE_SITE_ROLE_PRESETS[key].editor)\n\n/**\n * The core keys each org role holds when nothing refines it: owners and\n * admins hold every core key (owner-only acts like deleting the\n * organization stay role-checked, not permission-checked); editors work on\n * content and see no money or roster controls; viewers read only.\n */\nexport const CORE_ORG_ROLE_GRANTS: Readonly<Record<OrgRoleName, readonly string[]>> = {\n owner: CORE_KEYS,\n admin: CORE_KEYS,\n editor: ['data.manage', 'org.media', 'org.eraseRecords', 'marketplace.publish', 'plugins.install', ...EDITOR_SITE_KEYS],\n viewer: [],\n}\n\n/** The core's catalog and grants; the contracts' value adds the plugins' keys. */\nexport const ORG_ROLE_GRANTS: OrgRoleGrants = {\n permissions: CORE_ORG_PERMISSION_ENTRIES.map((entry) => ({ ...entry })),\n groups: CORE_ORG_PERMISSION_GROUPS.map((group) => ({ ...group })),\n grants: {\n owner: [...CORE_ORG_ROLE_GRANTS.owner],\n admin: [...CORE_ORG_ROLE_GRANTS.admin],\n editor: [...CORE_ORG_ROLE_GRANTS.editor],\n viewer: [...CORE_ORG_ROLE_GRANTS.viewer],\n },\n}\n\n/**\n * The catalog with plugins' declared keys after the core ones, each role\n * holding a declared key when its declaration's defaults say so. A\n * declaration naming a key already taken is refused, as the console's\n * catalog refuses it: the first declaration keeps its meaning and defaults.\n * Every declaration list after the first is folded in the same way, so the\n * org catalog keys (`PluginOrgPermissionDeclaration`) and the\n * `registerPluginPermissions` keys land in one catalog (AGL-4047).\n */\nexport function assembleOrgRoleGrants(\n core: OrgRoleGrants,\n ...declarationLists: ReadonlyArray<readonly OrgPermissionDeclaration[]>\n): OrgRoleGrants {\n const permissions = [...core.permissions]\n const groups = [...(core.groups ?? [])]\n const grants = Object.fromEntries(ORG_ROLE_NAMES.map((role) => [role, [...core.grants[role]]])) as Record<\n OrgRoleName,\n string[]\n >\n const taken = new Set(permissions.map((entry) => entry.key))\n const groupIds = new Set(groups.map((group) => group.id))\n for (const declaration of declarationLists.flat()) {\n if (!declaration?.key || taken.has(declaration.key)) continue\n taken.add(declaration.key)\n const group = declaration.group ?? declaration.pluginId\n permissions.push({\n key: declaration.key,\n label: declaration.label,\n description: declaration.description ?? '',\n ...(declaration.pluginId ? { pluginId: declaration.pluginId } : {}),\n ...(group ? { group } : {}),\n scope: declaration.hostRoleDefaults ? 'site' : 'org',\n ...(declaration.refines && declaration.refines !== declaration.key ? { refines: declaration.refines } : {}),\n ...(declaration.follows && declaration.follows !== declaration.key && !declaration.refines\n ? { follows: declaration.follows }\n : {}),\n // A plugin's own declaration carries `narrowsPerSite` (a flag or one per role); only whether it is set matters here.\n ...((declaration as { narrowsPerSite?: unknown }).narrowsPerSite ? { narrowable: true } : {}),\n })\n if (group && !groupIds.has(group)) {\n groupIds.add(group)\n groups.push({\n id: group,\n label: declaration.groupLabel ?? group,\n ...(declaration.pluginId ? { pluginId: declaration.pluginId } : {}),\n })\n } else if (group && declaration.pluginId) {\n // A plugin's group opened by a declaration that names no plugin (an org\n // catalog declaration, AGL-4047) is still that plugin's: the first of\n // its declarations that names one says so.\n const index = groups.findIndex((entry) => entry.id === group)\n if (index >= 0 && !groups[index].pluginId) groups[index] = { ...groups[index], pluginId: declaration.pluginId }\n }\n const defaults = declarationRoleDefaults(declaration)\n for (const role of ORG_ROLE_NAMES) {\n if (defaults[role]) grants[role].push(declaration.key)\n }\n }\n return { permissions, grants, groups }\n}\n\n/**\n * A member's effective permissions, as the console's `resolveOrgPermissions`\n * answers them: the role's defaults, then the custom role's explicit\n * verdicts (when the member has one), then the member's own overrides,\n * later layers winning key by key, over the catalog's keys only. A missing\n * role reads as viewer; a role the catalog does not know holds nothing.\n */\nexport function rolePermissions(\n catalog: OrgRoleGrants,\n role: string | null | undefined,\n customRole?: OrgPermissionLayer | null,\n overrides?: OrgPermissionLayer | null,\n): Record<string, boolean> {\n const keys = catalog.permissions.map((entry) => entry.key)\n const name = role ?? 'viewer'\n const held = new Set((catalog.grants as Record<string, string[] | undefined>)[name] ?? [])\n const out: Record<string, boolean> = Object.fromEntries(keys.map((key) => [key, held.has(key)]))\n for (const layer of [customRole, overrides]) {\n const values = layer?.permissions\n if (!values) continue\n for (const key of keys) {\n if (typeof values[key] === 'boolean') out[key] = values[key]\n }\n }\n // A key that refines a broader one (AGL-4047) is never held without it, and\n // follows it where neither layer set the key; a key that only follows one\n // takes its verdict where neither layer set the key, and nothing more.\n // Applied broader keys first, so a chain settles in one pass; a refinement\n // that loops is left alone.\n const broader = new Map<string, string>()\n const followsOnly = new Set<string>()\n for (const entry of catalog.permissions) {\n if (entry.refines && entry.refines in out) broader.set(entry.key, entry.refines)\n else if (entry.follows && entry.follows in out) {\n broader.set(entry.key, entry.follows)\n followsOnly.add(entry.key)\n }\n }\n const depth = (key: string): number => {\n const seen = new Set<string>()\n let steps = 0\n let current = key\n while (broader.has(current)) {\n if (seen.has(current)) return -1\n seen.add(current)\n current = broader.get(current) as string\n steps += 1\n }\n return steps\n }\n const ordered = [...broader.keys()]\n .map((key) => ({ key, steps: depth(key) }))\n .filter((entry) => entry.steps > 0)\n .sort((a, b) => a.steps - b.steps)\n for (const { key } of ordered) {\n let stored: boolean | undefined\n for (const layer of [customRole, overrides]) {\n const value = layer?.permissions?.[key]\n if (typeof value === 'boolean') stored = value\n }\n const held = out[broader.get(key) as string] === true\n out[key] = followsOnly.has(key) ? (stored === undefined ? held : stored) : held && (stored === undefined ? true : stored)\n }\n return out\n}\n"],"names":["ORG_ROLE_NAMES","CORE_ORG_PERMISSION_GROUPS","id","label","declarationRoleDefaults","declaration","roleDefaults","owner","admin","editor","viewer","tiers","defaults","CORE_ORG_PERMISSION_ENTRIES","key","group","description","scope","CORE_KEYS","map","entry","CORE_SITE_ROLE_PRESETS","author","EDITOR_SITE_KEYS","Object","keys","filter","CORE_ORG_ROLE_GRANTS","ORG_ROLE_GRANTS","permissions","groups","grants","assembleOrgRoleGrants","core","declarationLists","fromEntries","role","taken","Set","groupIds","flat","has","add","pluginId","push","hostRoleDefaults","refines","follows","narrowsPerSite","narrowable","groupLabel","index","findIndex","rolePermissions","catalog","customRole","overrides","name","held","out","layer","values","broader","Map","followsOnly","set","depth","seen","steps","current","get","ordered","sort","a","b","stored","value","undefined"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;CAkBC,GAED,wBAAwB;AA2FxB,OAAO,MAAMA,iBAAyC;IAAC;IAAS;IAAS;IAAU;CAAS,CAAA;AAE5F;;;;CAIC,GACD,OAAO,MAAMC,6BAA4D;IACvE;QAAEC,IAAI;QAAgBC,OAAO;IAAe;IAC5C;QAAED,IAAI;QAAWC,OAAO;IAAU;IAClC;QAAED,IAAI;QAAQC,OAAO;IAAO;IAC5B;QAAED,IAAI;QAASC,OAAO;IAAQ;IAC9B;QAAED,IAAI;QAAYC,OAAO;IAAO;IAChC;QAAED,IAAI;QAAcC,OAAO;IAA0B;CACtD,CAAA;AAED;;;;CAIC,GACD,OAAO,SAASC,wBACdC,WAAwE;IAExE,IAAIA,YAAYC,YAAY,EAAE;QAC5B,OAAO;YACLC,OAAOF,YAAYC,YAAY,CAACC,KAAK,KAAK;YAC1CC,OAAOH,YAAYC,YAAY,CAACE,KAAK,KAAK;YAC1CC,QAAQJ,YAAYC,YAAY,CAACG,MAAM,KAAK;YAC5CC,QAAQL,YAAYC,YAAY,CAACI,MAAM,KAAK;QAC9C;IACF;IACA,MAAMC,QAAQN,YAAYO,QAAQ;IAClC,OAAO;QACLL,OAAOI,CAAAA,yBAAAA,MAAOH,KAAK,MAAK;QACxBA,OAAOG,CAAAA,yBAAAA,MAAOH,KAAK,MAAK;QACxBC,QAAQE,CAAAA,yBAAAA,MAAOF,MAAM,MAAK;QAC1BC,QAAQC,CAAAA,yBAAAA,MAAOD,MAAM,MAAK;IAC5B;AACF;AAEA;;;CAGC,GACD,OAAO,MAAMG,8BAA6D;IACxE;QACEC,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA,yEAAyE;IACzE,yDAAyD;IACzD;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA,2EAA2E;IAC3E,sEAAsE;IACtE;QACEF,KAAK;QACLC,OAAO;QACPE,OAAO;QACPd,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPE,OAAO;QACPd,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPE,OAAO;QACPd,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPE,OAAO;QACPd,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA,mEAAmE;IACnE,+DAA+D;IAC/D;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACPa,aAAa;IACf;IACA;QACEF,KAAK;QACLC,OAAO;QACPZ,OAAO;QACP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IACT;IACA,MAAMG,UAAU;WAAIT,QAAQrC,IAAI;KAAG,CAChCN,GAAG,CAAC,CAACL,MAAS,CAAA;YAAEA;YAAKsD,OAAOF,MAAMpD;QAAK,CAAA,GACvCY,MAAM,CAAC,CAACN,QAAUA,MAAMgD,KAAK,GAAG,GAChCI,IAAI,CAAC,CAACC,GAAGC,IAAMD,EAAEL,KAAK,GAAGM,EAAEN,KAAK;IACnC,KAAK,MAAM,EAAEtD,GAAG,EAAE,IAAIyD,QAAS;QAC7B,IAAII;QACJ,KAAK,MAAMf,SAAS;YAACL;YAAYC;SAAU,CAAE;gBAC7BI;YAAd,MAAMgB,QAAQhB,0BAAAA,qBAAAA,MAAO/B,WAAW,qBAAlB+B,kBAAoB,CAAC9C,IAAI;YACvC,IAAI,OAAO8D,UAAU,WAAWD,SAASC;QAC3C;QACA,MAAMlB,OAAOC,GAAG,CAACG,QAAQQ,GAAG,CAACxD,KAAe,KAAK;QACjD6C,GAAG,CAAC7C,IAAI,GAAGkD,YAAYvB,GAAG,CAAC3B,OAAQ6D,WAAWE,YAAYnB,OAAOiB,SAAUjB,QAASiB,CAAAA,WAAWE,YAAY,OAAOF,MAAK;IACzH;IACA,OAAOhB;AACT"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/org-role-grants.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * WHAT EACH ORG ROLE MAY DO, AS DATA (AGL-243, AGL-3950).\n *\n * The core permission catalog and the core keys each org role holds when\n * nothing refines it. `org-permissions.ts` builds the console's live\n * catalog from these (adding the keys plugins declare, with their own role\n * defaults), and the native apps read the same grants through the generated\n * contracts, so a native gate (`hosts.create`, `data.manage`) answers as the\n * console does for a member row that carries no `resolvedPermissions` stamp.\n *\n * `ORG_ROLE_GRANTS` in the contracts is this table with every plugin's\n * declared catalog keys added (`assembleOrgRoleGrants`, run by\n * `generate:native-contracts` over each plugin's declarations), which is\n * exactly the set the console's `DEFAULT_ROLE_PERMISSIONS` holds once the\n * plugins have registered.\n *\n * NO IMPORTS, on purpose: the native apps read it through the generated\n * contracts.\n */\n\n/** The four org roles. */\nexport type OrgRoleName = 'owner' | 'admin' | 'editor' | 'viewer'\n\n/**\n * Where a key is decided (AGL-4047). `org`: by the member's org role, custom\n * role and overrides, the same on every site. `site`: as `org` for a member\n * who reaches the whole workspace, and per site for a site collaborator,\n * from the host role they hold there and that site's toggle.\n */\nexport type OrgPermissionScope = 'org' | 'site'\n\n/** One key of the org permission catalog. */\nexport interface OrgPermissionEntry {\n key: string\n label: string\n description: string\n /** The plugin that declared it; absent for a core key. */\n pluginId?: string\n /** The group the role editor files it under (`ORG_PERMISSION_GROUPS`, or the declaring plugin's id). */\n group?: string\n /** Where it is decided; absent reads as `org`. */\n scope?: OrgPermissionScope\n /**\n * The broader key this one is a finer part of (AGL-4047): never granted\n * without it, and following it where no custom role or override sets this\n * key. Absent for a key that refines nothing.\n */\n refines?: string\n /**\n * The key this one follows where no custom role or override sets it,\n * without needing it (AGL-4047): granted on its own, it holds while that\n * key is refused. Absent for a key that follows nothing, and for one that\n * refines.\n */\n follows?: string\n /**\n * Whether a site can narrow the key (`narrowsPerSite`, AGL-4047), so the\n * role and member editors offer its \"follow the site role\" choice. Absent\n * for a key a site cannot narrow.\n */\n narrowable?: boolean\n /**\n * For a site key, who holds it by the role they have on that site, read\n * where the site has no stamp for them (`hostStampedSitePermission`, AGL-4047).\n * Absent for a key with no such preset, and for one that holds for members of\n * the whole workspace only, which a site's roles alone cannot answer.\n */\n sitePreset?: Record<string, boolean>\n}\n\n/** A heading the role editor groups keys under. */\nexport interface OrgPermissionGroup {\n id: string\n label: string\n /** The plugin whose keys it holds; absent for a core group. */\n pluginId?: string\n}\n\n/** The catalog and each role's default grants. */\nexport interface OrgRoleGrants {\n /** Every key, in the order the role editor lists them. */\n permissions: OrgPermissionEntry[]\n /** The keys each role holds when no custom role or per-member override sets them. */\n grants: Record<OrgRoleName, string[]>\n /** The groups the keys are filed under, in display order; absent in a catalog written before them. */\n groups?: OrgPermissionGroup[]\n}\n\n/**\n * A key a plugin declares into the catalog: `PluginOrgPermissionDeclaration`\n * with org-role defaults, or a `registerPluginPermissions` key (`managePos`),\n * whose `defaults` are per role tier, the owner holding the admin tier's.\n */\nexport interface OrgPermissionDeclaration {\n key: string\n label: string\n description?: string\n roleDefaults?: Record<OrgRoleName, boolean>\n /** The tier defaults of a `registerPluginPermissions` key, used when `roleDefaults` is absent. */\n defaults?: { admin: boolean; editor: boolean; viewer: boolean }\n /** The host-role defaults of a key a site collaborator holds per site. */\n hostRoleDefaults?: Record<string, boolean>\n /** The group it is filed under; absent: a group named by the declaring plugin's id. */\n group?: string\n /** That group's heading, for a group the core does not name. */\n groupLabel?: string\n pluginId?: string\n /** The broader key it refines (AGL-4047). */\n refines?: string\n /** The key it follows without needing it (AGL-4047). */\n follows?: string\n}\n\n/** A custom role (`orgs/{orgId}/roles/{roleId}`) or a member's overrides: explicit verdicts per key. */\nexport interface OrgPermissionLayer {\n permissions?: Record<string, boolean>\n}\n\nexport const ORG_ROLE_NAMES: readonly OrgRoleName[] = ['owner', 'admin', 'editor', 'viewer']\n\n/**\n * The core groups, in display order. A plugin's keys are filed under a group\n * named by the plugin's id unless its declaration names one of these, so no\n * core group id is a plugin id.\n */\nexport const CORE_ORG_PERMISSION_GROUPS: readonly OrgPermissionGroup[] = [\n { id: 'organization', label: 'Organization' },\n { id: 'billing', label: 'Billing' },\n { id: 'team', label: 'Team' },\n { id: 'sites', label: 'Sites' },\n { id: 'datasets', label: 'Data' },\n { id: 'extensions', label: 'Marketplace and plugins' },\n]\n\n/**\n * A declaration's verdict for each org role: its `roleDefaults`, or, for a\n * `registerPluginPermissions` key, its tier `defaults` with the owner on the\n * admin tier (the tier `ORG_ROLE_TIER` resolves the owner onto).\n */\nexport function declarationRoleDefaults(\n declaration: Pick<OrgPermissionDeclaration, 'roleDefaults' | 'defaults'>,\n): Record<OrgRoleName, boolean> {\n if (declaration.roleDefaults) {\n return {\n owner: declaration.roleDefaults.owner === true,\n admin: declaration.roleDefaults.admin === true,\n editor: declaration.roleDefaults.editor === true,\n viewer: declaration.roleDefaults.viewer === true,\n }\n }\n const tiers = declaration.defaults\n return {\n owner: tiers?.admin === true,\n admin: tiers?.admin === true,\n editor: tiers?.editor === true,\n viewer: tiers?.viewer === true,\n }\n}\n\n/**\n * The core keys, in display order for role editors. Every key here is\n * enforced server-side (`apps/console/specs/org-permissions-are-enforced.spec.ts`).\n */\nexport const CORE_ORG_PERMISSION_ENTRIES: readonly OrgPermissionEntry[] = [\n {\n key: 'org.settings',\n group: 'organization',\n label: 'Organization settings',\n description: 'Rename the organization, change its slug, transfer it.',\n },\n {\n key: 'org.auditLog',\n group: 'organization',\n label: 'Activity & audit log',\n description: 'See the organization activity feed.',\n },\n {\n key: 'org.apiKeys',\n group: 'organization',\n label: 'Manage API keys',\n description: 'Create and revoke the workspace’s REST API keys.',\n },\n {\n key: 'org.privacy',\n group: 'organization',\n label: 'Privacy requests',\n description: 'Erase a person from every site in the workspace when they ask.',\n },\n {\n key: 'org.holds',\n group: 'organization',\n label: 'Holds and reviews',\n description: 'See what is held, flagged or locked on the workspace, and request a review.',\n },\n // Workspace acts that asked for the owner or admin role (AGL-4047), each\n // a key of its own whose default is exactly those roles.\n {\n key: 'org.export',\n group: 'organization',\n label: 'Export workspace data',\n description: 'Download a copy of everything the workspace holds.',\n },\n {\n key: 'org.sendingDomains',\n group: 'organization',\n label: 'Sending domains',\n description: 'Add, verify and remove the domains the workspace’s mail is sent from.',\n },\n {\n key: 'org.businessProfile',\n group: 'organization',\n label: 'Business profile',\n description: 'Change the services, audience and tone every site starts from.',\n },\n {\n key: 'billing.view',\n group: 'billing',\n label: 'View billing',\n description: 'See the plan, usage meters, and invoices.',\n },\n {\n key: 'billing.manage',\n group: 'billing',\n label: 'Manage billing',\n description: 'Change plans, buy add-ons, update payment details.',\n },\n {\n key: 'members.manage',\n group: 'team',\n label: 'Manage members',\n description: 'Invite, remove, and re-role organization members.',\n },\n {\n key: 'hosts.create',\n group: 'sites',\n label: 'Create sites',\n description: 'Create new sites in the organization.',\n },\n {\n key: 'hosts.delete',\n group: 'sites',\n label: 'Delete sites',\n description: 'Delete sites the member can access.',\n },\n // The site keys (AGL-4047): each replaced a gate on the member's role on a\n // site, and keeps that role as its preset (`CORE_SITE_ROLE_PRESETS`).\n {\n key: 'site.edit',\n group: 'sites',\n scope: 'site',\n label: 'Edit site content',\n description: 'Create and change pages, content and everything else on a site, without making it live.',\n },\n {\n key: 'site.publish',\n group: 'sites',\n scope: 'site',\n label: 'Publish site content',\n description: 'Make pages and content live, take them down or schedule them, change redirects and change the site’s fonts.',\n },\n {\n key: 'site.sensitive',\n group: 'sites',\n scope: 'site',\n label: 'See orders and webhooks',\n description: 'Read a site’s orders, returns and sending address, and set up its webhooks.',\n },\n {\n key: 'site.manage',\n group: 'sites',\n scope: 'site',\n label: 'Manage site settings',\n description: 'Manage a site’s people, domain, address and plugins, change its plugin settings (live chat, Zapier) and security allow-lists, import, export and delete it.',\n },\n {\n key: 'data.manage',\n group: 'datasets',\n label: 'Manage data',\n description: 'Create and edit organization datasets, add, change and delete their rows, and manage the CRM’s records and marketing lists and topics.',\n },\n // Workspace content that asked for the owner, admin or editor role\n // (AGL-4047), each a key whose default is exactly those roles.\n {\n key: 'org.media',\n group: 'datasets',\n label: 'Edit the workspace media library',\n description: 'Upload, change, move and remove the files in the media library every site shares.',\n },\n {\n key: 'org.eraseRecords',\n group: 'datasets',\n label: 'Delete workspace records',\n description: 'Delete a whole dataset or list the workspace shares, with everything in it. Deleting one row of a dataset asks “Manage data”.',\n },\n {\n key: 'marketplace.publish',\n group: 'extensions',\n label: 'Publish to marketplace',\n description: 'Publish listings under the organization profile.',\n },\n {\n key: 'plugins.install',\n group: 'extensions',\n label: 'Install plugins',\n description: 'Install or remove marketplace plugins.',\n },\n]\n\nconst CORE_KEYS = CORE_ORG_PERMISSION_ENTRIES.map((entry) => entry.key)\n\n/**\n * The core keys whose preset is the member's role ON THE SITE (AGL-4047), and\n * each site role's verdict: the sets the rules' `canWriteHostContent`,\n * `canPublishHostContent`, `canReadHostSensitive` and the site-admin checks\n * asked before they asked these keys. A member's preset on a site is the\n * verdict for the role they hold there (the owner and admins are Admin on\n * every site); a custom role, their own permissions and that site's toggle\n * then grant or refuse it. Each workspace role's default below is the verdict\n * for its own site role, which is the answer with no site named.\n */\nexport const CORE_SITE_ROLE_PRESETS: Readonly<Record<string, Readonly<Record<string, boolean>>>> = {\n 'site.edit': { admin: true, editor: true, author: true, viewer: false },\n 'site.publish': { admin: true, editor: true, author: false, viewer: false },\n 'site.sensitive': { admin: true, editor: true, author: false, viewer: false },\n 'site.manage': { admin: true, editor: false, author: false, viewer: false },\n}\n\n/** The workspace editor's site keys: its own site role's preset. */\nconst EDITOR_SITE_KEYS = Object.keys(CORE_SITE_ROLE_PRESETS).filter((key) => CORE_SITE_ROLE_PRESETS[key].editor)\n\n/**\n * The core keys each org role holds when nothing refines it: owners and\n * admins hold every core key (owner-only acts like deleting the\n * organization stay role-checked, not permission-checked); editors work on\n * content and see no money or roster controls; viewers read only.\n */\nexport const CORE_ORG_ROLE_GRANTS: Readonly<Record<OrgRoleName, readonly string[]>> = {\n owner: CORE_KEYS,\n admin: CORE_KEYS,\n editor: ['data.manage', 'org.media', 'org.eraseRecords', 'marketplace.publish', 'plugins.install', ...EDITOR_SITE_KEYS],\n viewer: [],\n}\n\n/** The core's catalog and grants; the contracts' value adds the plugins' keys. */\nexport const ORG_ROLE_GRANTS: OrgRoleGrants = {\n permissions: CORE_ORG_PERMISSION_ENTRIES.map((entry) => ({ ...entry })),\n groups: CORE_ORG_PERMISSION_GROUPS.map((group) => ({ ...group })),\n grants: {\n owner: [...CORE_ORG_ROLE_GRANTS.owner],\n admin: [...CORE_ORG_ROLE_GRANTS.admin],\n editor: [...CORE_ORG_ROLE_GRANTS.editor],\n viewer: [...CORE_ORG_ROLE_GRANTS.viewer],\n },\n}\n\n/**\n * The catalog with plugins' declared keys after the core ones, each role\n * holding a declared key when its declaration's defaults say so. A\n * declaration naming a key already taken is refused, as the console's\n * catalog refuses it: the first declaration keeps its meaning and defaults.\n * Every declaration list after the first is folded in the same way, so the\n * org catalog keys (`PluginOrgPermissionDeclaration`) and the\n * `registerPluginPermissions` keys land in one catalog (AGL-4047).\n */\nexport function assembleOrgRoleGrants(\n core: OrgRoleGrants,\n ...declarationLists: ReadonlyArray<readonly OrgPermissionDeclaration[]>\n): OrgRoleGrants {\n const permissions = core.permissions.map((entry) =>\n CORE_SITE_ROLE_PRESETS[entry.key] ? { ...entry, sitePreset: { ...CORE_SITE_ROLE_PRESETS[entry.key] } } : entry,\n )\n const groups = [...(core.groups ?? [])]\n const grants = Object.fromEntries(ORG_ROLE_NAMES.map((role) => [role, [...core.grants[role]]])) as Record<\n OrgRoleName,\n string[]\n >\n const taken = new Set(permissions.map((entry) => entry.key))\n const groupIds = new Set(groups.map((group) => group.id))\n for (const declaration of declarationLists.flat()) {\n if (!declaration?.key || taken.has(declaration.key)) continue\n taken.add(declaration.key)\n const group = declaration.group ?? declaration.pluginId\n permissions.push({\n key: declaration.key,\n label: declaration.label,\n description: declaration.description ?? '',\n ...(declaration.pluginId ? { pluginId: declaration.pluginId } : {}),\n ...(group ? { group } : {}),\n scope: declaration.hostRoleDefaults ? 'site' : 'org',\n ...(declaration.refines && declaration.refines !== declaration.key ? { refines: declaration.refines } : {}),\n ...(declaration.follows && declaration.follows !== declaration.key && !declaration.refines\n ? { follows: declaration.follows }\n : {}),\n // A plugin's own declaration carries `narrowsPerSite` (a flag or one per role); only whether it is set matters here.\n ...((declaration as { narrowsPerSite?: unknown }).narrowsPerSite ? { narrowable: true } : {}),\n ...(declaration.hostRoleDefaults && !(declaration as { workspaceMembersOnly?: unknown }).workspaceMembersOnly\n ? { sitePreset: { ...declaration.hostRoleDefaults } }\n : {}),\n })\n if (group && !groupIds.has(group)) {\n groupIds.add(group)\n groups.push({\n id: group,\n label: declaration.groupLabel ?? group,\n ...(declaration.pluginId ? { pluginId: declaration.pluginId } : {}),\n })\n } else if (group && declaration.pluginId) {\n // A plugin's group opened by a declaration that names no plugin (an org\n // catalog declaration, AGL-4047) is still that plugin's: the first of\n // its declarations that names one says so.\n const index = groups.findIndex((entry) => entry.id === group)\n if (index >= 0 && !groups[index].pluginId) groups[index] = { ...groups[index], pluginId: declaration.pluginId }\n }\n const defaults = declarationRoleDefaults(declaration)\n for (const role of ORG_ROLE_NAMES) {\n if (defaults[role]) grants[role].push(declaration.key)\n }\n }\n return { permissions, grants, groups }\n}\n\n/**\n * A member's effective permissions, as the console's `resolveOrgPermissions`\n * answers them: the role's defaults, then the custom role's explicit\n * verdicts (when the member has one), then the member's own overrides,\n * later layers winning key by key, over the catalog's keys only. A missing\n * role reads as viewer; a role the catalog does not know holds nothing.\n */\nexport function rolePermissions(\n catalog: OrgRoleGrants,\n role: string | null | undefined,\n customRole?: OrgPermissionLayer | null,\n overrides?: OrgPermissionLayer | null,\n): Record<string, boolean> {\n const keys = catalog.permissions.map((entry) => entry.key)\n const name = role ?? 'viewer'\n const held = new Set((catalog.grants as Record<string, string[] | undefined>)[name] ?? [])\n const out: Record<string, boolean> = Object.fromEntries(keys.map((key) => [key, held.has(key)]))\n for (const layer of [customRole, overrides]) {\n const values = layer?.permissions\n if (!values) continue\n for (const key of keys) {\n if (typeof values[key] === 'boolean') out[key] = values[key]\n }\n }\n // A key that refines a broader one (AGL-4047) is never held without it, and\n // follows it where neither layer set the key; a key that only follows one\n // takes its verdict where neither layer set the key, and nothing more.\n // Applied broader keys first, so a chain settles in one pass; a refinement\n // that loops is left alone.\n const broader = new Map<string, string>()\n const followsOnly = new Set<string>()\n for (const entry of catalog.permissions) {\n if (entry.refines && entry.refines in out) broader.set(entry.key, entry.refines)\n else if (entry.follows && entry.follows in out) {\n broader.set(entry.key, entry.follows)\n followsOnly.add(entry.key)\n }\n }\n const depth = (key: string): number => {\n const seen = new Set<string>()\n let steps = 0\n let current = key\n while (broader.has(current)) {\n if (seen.has(current)) return -1\n seen.add(current)\n current = broader.get(current) as string\n steps += 1\n }\n return steps\n }\n const ordered = [...broader.keys()]\n .map((key) => ({ key, steps: depth(key) }))\n .filter((entry) => entry.steps > 0)\n .sort((a, b) => a.steps - b.steps)\n for (const { key } of ordered) {\n let stored: boolean | undefined\n for (const layer of [customRole, overrides]) {\n const value = layer?.permissions?.[key]\n if (typeof value === 'boolean') stored = value\n }\n const held = out[broader.get(key) as string] === true\n out[key] = followsOnly.has(key) ? (stored === undefined ? held : stored) : held && (stored === undefined ? true : stored)\n }\n return out\n}\n"],"names":["ORG_ROLE_NAMES","CORE_ORG_PERMISSION_GROUPS","id","label","declarationRoleDefaults","declaration","roleDefaults","owner","admin","editor","viewer","tiers","defaults","CORE_ORG_PERMISSION_ENTRIES","key","group","description","scope","CORE_KEYS","map","entry","CORE_SITE_ROLE_PRESETS","author","EDITOR_SITE_KEYS","Object","keys","filter","CORE_ORG_ROLE_GRANTS","ORG_ROLE_GRANTS","permissions","groups","grants","assembleOrgRoleGrants","core","declarationLists","sitePreset","fromEntries","role","taken","Set","groupIds","flat","has","add","pluginId","push","hostRoleDefaults","refines","follows","narrowsPerSite","narrowable","workspaceMembersOnly","groupLabel","index","findIndex","rolePermissions","catalog","customRole","overrides","name","held","out","layer","values","broader","Map","followsOnly","set","depth","seen","steps","current","get","ordered","sort","a","b","stored","value","undefined"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;CAkBC,GAED,wBAAwB;AAkGxB,OAA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,GAAG,CAAC4B;YACTA,UAAUP,QAAQQ,GAAG,CAACD;YACtBD,SAAS;QACX;QACA,OAAOA;IACT;IACA,MAAMG,UAAU;WAAIT,QAAQvC,IAAI;KAAG,CAChCN,GAAG,CAAC,CAACL,MAAS,CAAA;YAAEA;YAAKwD,OAAOF,MAAMtD;QAAK,CAAA,GACvCY,MAAM,CAAC,CAACN,QAAUA,MAAMkD,KAAK,GAAG,GAChCI,IAAI,CAAC,CAACC,GAAGC,IAAMD,EAAEL,KAAK,GAAGM,EAAEN,KAAK;IACnC,KAAK,MAAM,EAAExD,GAAG,EAAE,IAAI2D,QAAS;QAC7B,IAAII;QACJ,KAAK,MAAMf,SAAS;YAACL;YAAYC;SAAU,CAAE;gBAC7BI;YAAd,MAAMgB,QAAQhB,0BAAAA,qBAAAA,MAAOjC,WAAW,qBAAlBiC,kBAAoB,CAAChD,IAAI;YACvC,IAAI,OAAOgE,UAAU,WAAWD,SAASC;QAC3C;QACA,MAAMlB,OAAOC,GAAG,CAACG,QAAQQ,GAAG,CAAC1D,KAAe,KAAK;QACjD+C,GAAG,CAAC/C,IAAI,GAAGoD,YAAYxB,GAAG,CAAC5B,OAAQ+D,WAAWE,YAAYnB,OAAOiB,SAAUjB,QAASiB,CAAAA,WAAWE,YAAY,OAAOF,MAAK;IACzH;IACA,OAAOhB;AACT"}
@@ -252,9 +252,9 @@ export declare function scopeCovers(target: readonly string[] | undefined | null
252
252
  * Rewrites an org media CDN path so it names the site using the asset
253
253
  * (AGL-1043/1045).
254
254
  *
255
- * `/api/media/cdn/org:{orgId}/{mediaId}` serves ORG-WIDE assets only. A
256
- * restricted asset has to be requested through the form that names the
257
- * site — `org:{orgId}:{hostId}` — because the CDN is unauthenticated and
255
+ * `/api/media/cdn/org:{orgId}/{mediaId}` serves org-wide assets, and assets
256
+ * shared with all sites except some. An asset shared with chosen sites has to
257
+ * be requested through the form that names the site — `org:{orgId}:{hostId}` — because the CDN is unauthenticated and
258
258
  * the URL is the only thing it can decide from.
259
259
  *
260
260
  * Returns the path untouched when there is nothing to do: an org-wide
@@ -289,3 +289,132 @@ export declare function heldByHost(doc: Readonly<Record<string, unknown>> | null
289
289
  * every read that predates sharing keeps exactly the rows it had.
290
290
  */
291
291
  export declare function seenOnlyThroughGrant(doc: Readonly<Record<string, unknown>> | null | undefined, hostId: string): boolean;
292
+ /** The `scopeMode` a document kept up by the sweep carries. */
293
+ export declare const SCOPE_MODE_ALL_EXCEPT: "allExcept";
294
+ /**
295
+ * What a sharing choice writes. A `null` marker field means the document must
296
+ * not carry it, which a server write spells as a field delete, so a document
297
+ * moved back to All sites or to chosen sites keeps no stale marker.
298
+ */
299
+ export interface ScopeSharingFields {
300
+ visibleTo: ScopeToken[];
301
+ scopeMode: typeof SCOPE_MODE_ALL_EXCEPT | null;
302
+ scopeExcept: ScopeToken[] | null;
303
+ }
304
+ /** How a document is shared, as a person would choose it. */
305
+ export type ScopeSharing = {
306
+ mode: 'all';
307
+ } | {
308
+ mode: 'selected';
309
+ hostIds: string[];
310
+ } | {
311
+ mode: 'allExcept';
312
+ exceptHostIds: string[];
313
+ includedHostIds: string[];
314
+ } | {
315
+ mode: 'none';
316
+ };
317
+ /** What a person picked: the input to {@link sharingFromChoice}. */
318
+ export type ScopeSharingChoice = {
319
+ mode: 'all';
320
+ } | {
321
+ mode: 'selected';
322
+ hostIds: readonly string[];
323
+ } | {
324
+ mode: 'allExcept';
325
+ exceptHostIds: readonly string[];
326
+ };
327
+ /**
328
+ * How a document is shared. Reads the marker only where it agrees with what
329
+ * readers enforce: a document carrying `'org'` is shared with all sites
330
+ * whatever a marker beside it says, and a damaged marker reads as the chosen
331
+ * sites `visibleTo` names.
332
+ */
333
+ export declare function scopeSharingOf(doc: Readonly<Record<string, unknown>> | null | undefined): ScopeSharing;
334
+ /**
335
+ * What a sharing choice writes, or why it cannot be written.
336
+ *
337
+ * `orgHostIds` is the workspace's sites as the writer read them. An exclusion
338
+ * naming a site that is no longer there is dropped, not refused: the person
339
+ * asked for that site to stay out, and it is out. Excluding nothing is
340
+ * refused, since that choice is All sites; excluding everything is refused,
341
+ * since it would hide the document from every site.
342
+ *
343
+ * An all-except list is not held to `MAX_SCOPE_HOSTS`, which limits what a
344
+ * QUERY can ask for and never what a document stores. A collection whose
345
+ * stored fields multiply by site passes its own `maxIncluded`. `keepHostIds`
346
+ * are sites that stay on the list even if excluded, such as a site that
347
+ * captured the person a record is about.
348
+ */
349
+ export declare function sharingFromChoice(choice: ScopeSharingChoice, orgHostIds: readonly string[], options?: {
350
+ maxIncluded?: number | null;
351
+ keepHostIds?: readonly string[];
352
+ }): {
353
+ fields: ScopeSharingFields;
354
+ problem: null;
355
+ } | {
356
+ fields: null;
357
+ problem: string;
358
+ };
359
+ /** What keeping an all-except document up to date came to. */
360
+ export interface AllExceptReconcile {
361
+ /**
362
+ * - `unmarked`: not an all-except document; nothing to do.
363
+ * - `current`: already says what it should.
364
+ * - `changed`: write `fields`.
365
+ * - `capped`: it should reach more sites than `maxIncluded`, so it stopped
366
+ * widening. Any `fields` only take away sites that are gone.
367
+ * - `invalid`: a marker this module cannot act on, or one beside `'org'`.
368
+ * Left alone and reported, because either guess moves who can see it.
369
+ */
370
+ status: 'unmarked' | 'current' | 'changed' | 'capped' | 'invalid';
371
+ fields: ScopeSharingFields | null;
372
+ }
373
+ /**
374
+ * What an all-except document should say, given the workspace's sites today.
375
+ *
376
+ * Pure and idempotent, which is what lets every trigger and the drift report
377
+ * ask the same question: a second run over its own answer says `current`.
378
+ *
379
+ * - A new site joins `visibleTo`, unless it is excluded.
380
+ * - A site that left the workspace leaves `visibleTo` and `scopeExcept`.
381
+ * - Once no exclusion is left the document IS All sites, so it collapses to
382
+ * `['org']` and drops its marker.
383
+ * - When every remaining site is excluded `visibleTo` is empty and the marker
384
+ * stays: no site sees it until a new one joins. The data is kept, which is
385
+ * why {@link isSiteOnlyScope} answers false for a marked document.
386
+ * - A site in `sharing.added` stays, since a person shared the document with
387
+ * it. So do `keepHostIds`. Both only while the site is in the workspace.
388
+ */
389
+ export declare function reconcileAllExcept(doc: Readonly<Record<string, unknown>> | null | undefined, orgHostIds: readonly string[], options?: {
390
+ maxIncluded?: number | null;
391
+ keepHostIds?: readonly string[];
392
+ }): AllExceptReconcile;
393
+ /**
394
+ * The sentence the console shows for how a document is shared:
395
+ * {@link describeScope}, plus the all-except wording. Sites are named only
396
+ * where `hostNames` has them, so a reader who cannot see a site's name is told
397
+ * how many sites, never an id.
398
+ */
399
+ export declare function describeSharing(doc: Readonly<Record<string, unknown>> | null | undefined, hostNames?: Readonly<Record<string, string>>): string;
400
+ /**
401
+ * Whether a document belongs to this site alone: what deciding to erase it
402
+ * with the site asks, so the three copies of that question share one answer.
403
+ *
404
+ * FALSE FOR ANY MARKED DOCUMENT, and that is the reason this exists. A site
405
+ * can be the last one an all-except document still reaches, with `visibleTo`
406
+ * naming it and nothing else, and the document is still the workspace's.
407
+ * Reading that as "this site's own" would erase the data with the site.
408
+ */
409
+ export declare function isSiteOnlyScope(doc: Readonly<Record<string, unknown>> | null | undefined, hostId: string): boolean;
410
+ /**
411
+ * {@link scopeCovers} for whole documents: whether `target` stays visible
412
+ * everywhere `source` is, which a cross-dataset reference needs.
413
+ *
414
+ * Today's tokens are not enough once either side is all-except, because the
415
+ * two lists move when a site is added: a chosen-sites target cannot cover an
416
+ * all-except source however it looks today (the next new site gets the source
417
+ * and not the target), and an all-except target covers an all-except source
418
+ * only when it leaves out no site the source includes.
419
+ */
420
+ export declare function sharingCovers(target: Readonly<Record<string, unknown>> | null | undefined, source: Readonly<Record<string, unknown>> | null | undefined): boolean;
@@ -313,9 +313,9 @@ export function isScopeToken(value) {
313
313
  * Rewrites an org media CDN path so it names the site using the asset
314
314
  * (AGL-1043/1045).
315
315
  *
316
- * `/api/media/cdn/org:{orgId}/{mediaId}` serves ORG-WIDE assets only. A
317
- * restricted asset has to be requested through the form that names the
318
- * site — `org:{orgId}:{hostId}` — because the CDN is unauthenticated and
316
+ * `/api/media/cdn/org:{orgId}/{mediaId}` serves org-wide assets, and assets
317
+ * shared with all sites except some. An asset shared with chosen sites has to
318
+ * be requested through the form that names the site — `org:{orgId}:{hostId}` — because the CDN is unauthenticated and
319
319
  * the URL is the only thing it can decide from.
320
320
  *
321
321
  * Returns the path untouched when there is nothing to do: an org-wide
@@ -402,5 +402,278 @@ export function isScopeToken(value) {
402
402
  */ export function seenOnlyThroughGrant(doc, hostId) {
403
403
  return grantedScopeTokens(doc).length > 0 && !heldByHost(doc, hostId);
404
404
  }
405
+ /*==========================================
406
+ * ALL SITES EXCEPT… (AGL-4047).
407
+ *
408
+ * A third way to share, beside "All sites" and "these sites". Neither
409
+ * enforcement layer can read an exclusion: Firestore has no "does not
410
+ * contain", `not-in` cannot sit beside `array-contains-any`, and a rule that
411
+ * refused on one would fail every scoped member's whole list. So what readers
412
+ * enforce stays what it has always been, a flat `visibleTo` of the sites that
413
+ * ARE included, and the choice that produced it sits beside it as a marker:
414
+ *
415
+ * visibleTo: ['host:b', 'host:c'] the only field a reader looks at
416
+ * scopeMode: 'allExcept' says new sites join
417
+ * scopeExcept: ['host:a'] the sites that stay out
418
+ *
419
+ * `visibleTo` is therefore a list that has to be kept up: a new site joins it
420
+ * and a deleted one leaves it. {@link reconcileAllExcept} is the one answer to
421
+ * what it should hold; the sweep (`scope-sharing-sweep.ts`) applies it.
422
+ *
423
+ * `visibleTo` always wins over the marker when they disagree, because it is
424
+ * what the database enforces. A helper describing a document some other way
425
+ * would be describing something no reader does.
426
+ *=========================================*/ /** The `scopeMode` a document kept up by the sweep carries. */ export const SCOPE_MODE_ALL_EXCEPT = 'allExcept';
427
+ const uniqueStrings = (values)=>[
428
+ ...new Set(values.filter((value)=>typeof value === 'string' && value))
429
+ ];
430
+ /**
431
+ * The excluded sites a marker names, or null when the marker is not one this
432
+ * module can act on: anything but an array of host tokens. Null is what keeps
433
+ * a damaged marker from being read as "except nothing", which means All sites.
434
+ */ function markerExceptHostIds(doc) {
435
+ if ((doc == null ? void 0 : doc['scopeMode']) !== SCOPE_MODE_ALL_EXCEPT) return null;
436
+ const except = doc['scopeExcept'];
437
+ if (!Array.isArray(except)) return null;
438
+ const ids = [];
439
+ for (const token of except){
440
+ const parsed = typeof token === 'string' ? parseScopeToken(token) : null;
441
+ if ((parsed == null ? void 0 : parsed.kind) !== 'host') return null;
442
+ ids.push(parsed.hostId);
443
+ }
444
+ return uniqueStrings(ids);
445
+ }
446
+ /**
447
+ * How a document is shared. Reads the marker only where it agrees with what
448
+ * readers enforce: a document carrying `'org'` is shared with all sites
449
+ * whatever a marker beside it says, and a damaged marker reads as the chosen
450
+ * sites `visibleTo` names.
451
+ */ export function scopeSharingOf(doc) {
452
+ const visibleTo = doc == null ? void 0 : doc['visibleTo'];
453
+ const tokens = Array.isArray(visibleTo) ? visibleTo.filter((token)=>typeof token === 'string') : null;
454
+ if (tokens == null ? void 0 : tokens.includes(ORG_SCOPE_TOKEN)) return {
455
+ mode: 'all'
456
+ };
457
+ const included = uniqueStrings(hostIdsFromScope(tokens != null ? tokens : []));
458
+ const except = tokens ? markerExceptHostIds(doc) : null;
459
+ if (except) {
460
+ return {
461
+ mode: 'allExcept',
462
+ exceptHostIds: except,
463
+ includedHostIds: included
464
+ };
465
+ }
466
+ return included.length ? {
467
+ mode: 'selected',
468
+ hostIds: included
469
+ } : {
470
+ mode: 'none'
471
+ };
472
+ }
473
+ /**
474
+ * What a sharing choice writes, or why it cannot be written.
475
+ *
476
+ * `orgHostIds` is the workspace's sites as the writer read them. An exclusion
477
+ * naming a site that is no longer there is dropped, not refused: the person
478
+ * asked for that site to stay out, and it is out. Excluding nothing is
479
+ * refused, since that choice is All sites; excluding everything is refused,
480
+ * since it would hide the document from every site.
481
+ *
482
+ * An all-except list is not held to `MAX_SCOPE_HOSTS`, which limits what a
483
+ * QUERY can ask for and never what a document stores. A collection whose
484
+ * stored fields multiply by site passes its own `maxIncluded`. `keepHostIds`
485
+ * are sites that stay on the list even if excluded, such as a site that
486
+ * captured the person a record is about.
487
+ */ export function sharingFromChoice(choice, orgHostIds, options = {}) {
488
+ if (choice.mode === 'all') {
489
+ return {
490
+ fields: {
491
+ visibleTo: [
492
+ ORG_SCOPE_TOKEN
493
+ ],
494
+ scopeMode: null,
495
+ scopeExcept: null
496
+ },
497
+ problem: null
498
+ };
499
+ }
500
+ if (choice.mode === 'selected') {
501
+ const stored = scopeToStore(choice.hostIds.map(hostScopeToken));
502
+ return stored.scope ? {
503
+ fields: {
504
+ visibleTo: stored.scope,
505
+ scopeMode: null,
506
+ scopeExcept: null
507
+ },
508
+ problem: null
509
+ } : {
510
+ fields: null,
511
+ problem: stored.problem
512
+ };
513
+ }
514
+ const org = uniqueStrings(orgHostIds);
515
+ const except = uniqueStrings(choice.exceptHostIds).filter((id)=>org.includes(id));
516
+ if (!except.length) {
517
+ return {
518
+ fields: null,
519
+ problem: 'Choose at least one site to leave out, or share with All sites.'
520
+ };
521
+ }
522
+ const included = includedHostIds(org, except, options.keepHostIds);
523
+ if (!included.length) {
524
+ return {
525
+ fields: null,
526
+ problem: 'Keep at least one site in, or choose the sites.'
527
+ };
528
+ }
529
+ if (options.maxIncluded != null && included.length > options.maxIncluded) {
530
+ return {
531
+ fields: null,
532
+ problem: `This can reach ${options.maxIncluded === 1 ? '1 site' : `${options.maxIncluded} sites`} at most. Leave out more sites, or choose the sites.`
533
+ };
534
+ }
535
+ return {
536
+ fields: {
537
+ visibleTo: included.map(hostScopeToken),
538
+ scopeMode: SCOPE_MODE_ALL_EXCEPT,
539
+ scopeExcept: except.map(hostScopeToken)
540
+ },
541
+ problem: null
542
+ };
543
+ }
544
+ /** The workspace's sites minus the excluded ones, plus the kept, sorted. */ function includedHostIds(org, except, keep) {
545
+ const out = new Set(except);
546
+ const kept = new Set(keep != null ? keep : []);
547
+ return org.filter((id)=>!out.has(id) || kept.has(id)).sort();
548
+ }
549
+ /**
550
+ * What an all-except document should say, given the workspace's sites today.
551
+ *
552
+ * Pure and idempotent, which is what lets every trigger and the drift report
553
+ * ask the same question: a second run over its own answer says `current`.
554
+ *
555
+ * - A new site joins `visibleTo`, unless it is excluded.
556
+ * - A site that left the workspace leaves `visibleTo` and `scopeExcept`.
557
+ * - Once no exclusion is left the document IS All sites, so it collapses to
558
+ * `['org']` and drops its marker.
559
+ * - When every remaining site is excluded `visibleTo` is empty and the marker
560
+ * stays: no site sees it until a new one joins. The data is kept, which is
561
+ * why {@link isSiteOnlyScope} answers false for a marked document.
562
+ * - A site in `sharing.added` stays, since a person shared the document with
563
+ * it. So do `keepHostIds`. Both only while the site is in the workspace.
564
+ */ export function reconcileAllExcept(doc, orgHostIds, options = {}) {
565
+ var _options_keepHostIds;
566
+ if ((doc == null ? void 0 : doc['scopeMode']) === undefined || doc['scopeMode'] === null) {
567
+ return {
568
+ status: 'unmarked',
569
+ fields: null
570
+ };
571
+ }
572
+ const storedExcept = markerExceptHostIds(doc);
573
+ const visibleTo = doc['visibleTo'];
574
+ if (!storedExcept || !Array.isArray(visibleTo) || visibleTo.includes(ORG_SCOPE_TOKEN)) {
575
+ return {
576
+ status: 'invalid',
577
+ fields: null
578
+ };
579
+ }
580
+ const org = uniqueStrings(orgHostIds);
581
+ const except = storedExcept.filter((id)=>org.includes(id));
582
+ if (!except.length) {
583
+ return {
584
+ status: 'changed',
585
+ fields: {
586
+ visibleTo: [
587
+ ORG_SCOPE_TOKEN
588
+ ],
589
+ scopeMode: null,
590
+ scopeExcept: null
591
+ }
592
+ };
593
+ }
594
+ const current = uniqueStrings(hostIdsFromScope(visibleTo));
595
+ const keep = [
596
+ ...(_options_keepHostIds = options.keepHostIds) != null ? _options_keepHostIds : [],
597
+ ...hostIdsFromScope(grantedScopeTokens(doc))
598
+ ];
599
+ let included = includedHostIds(org, except, keep);
600
+ let capped = false;
601
+ if (options.maxIncluded != null && included.length > options.maxIncluded && included.some((id)=>!current.includes(id))) {
602
+ capped = true;
603
+ included = current.filter((id)=>org.includes(id)).sort();
604
+ }
605
+ const same = included.length === current.length && included.every((id)=>current.includes(id)) && except.length === storedExcept.length;
606
+ const fields = same ? null : {
607
+ visibleTo: included.map(hostScopeToken),
608
+ scopeMode: SCOPE_MODE_ALL_EXCEPT,
609
+ scopeExcept: except.map(hostScopeToken)
610
+ };
611
+ if (capped) return {
612
+ status: 'capped',
613
+ fields
614
+ };
615
+ return fields ? {
616
+ status: 'changed',
617
+ fields
618
+ } : {
619
+ status: 'current',
620
+ fields: null
621
+ };
622
+ }
623
+ /**
624
+ * The sentence the console shows for how a document is shared:
625
+ * {@link describeScope}, plus the all-except wording. Sites are named only
626
+ * where `hostNames` has them, so a reader who cannot see a site's name is told
627
+ * how many sites, never an id.
628
+ */ export function describeSharing(doc, hostNames = {}) {
629
+ const sharing = scopeSharingOf(doc);
630
+ if (sharing.mode !== 'allExcept') {
631
+ return describeScope(doc == null ? void 0 : doc['visibleTo'], hostNames);
632
+ }
633
+ if (!sharing.includedHostIds.length) return 'No sites';
634
+ const names = sharing.exceptHostIds.map((id)=>hostNames[id]);
635
+ const count = names.length;
636
+ if (count === 1) return `All sites except ${names[0] || '1 site'}`;
637
+ if (count === 2 && names.every(Boolean)) {
638
+ return `All sites except ${names[0]} and ${names[1]}`;
639
+ }
640
+ return `All sites except ${count} sites`;
641
+ }
642
+ /**
643
+ * Whether a document belongs to this site alone: what deciding to erase it
644
+ * with the site asks, so the three copies of that question share one answer.
645
+ *
646
+ * FALSE FOR ANY MARKED DOCUMENT, and that is the reason this exists. A site
647
+ * can be the last one an all-except document still reaches, with `visibleTo`
648
+ * naming it and nothing else, and the document is still the workspace's.
649
+ * Reading that as "this site's own" would erase the data with the site.
650
+ */ export function isSiteOnlyScope(doc, hostId) {
651
+ if ((doc == null ? void 0 : doc['scopeMode']) !== undefined && (doc == null ? void 0 : doc['scopeMode']) !== null) return false;
652
+ const visibleTo = doc == null ? void 0 : doc['visibleTo'];
653
+ const token = hostScopeToken(hostId);
654
+ return Array.isArray(visibleTo) && visibleTo.length > 0 && visibleTo.every((entry)=>entry === token);
655
+ }
656
+ /**
657
+ * {@link scopeCovers} for whole documents: whether `target` stays visible
658
+ * everywhere `source` is, which a cross-dataset reference needs.
659
+ *
660
+ * Today's tokens are not enough once either side is all-except, because the
661
+ * two lists move when a site is added: a chosen-sites target cannot cover an
662
+ * all-except source however it looks today (the next new site gets the source
663
+ * and not the target), and an all-except target covers an all-except source
664
+ * only when it leaves out no site the source includes.
665
+ */ export function sharingCovers(target, source) {
666
+ const targetTokens = target == null ? void 0 : target['visibleTo'];
667
+ const sourceTokens = source == null ? void 0 : source['visibleTo'];
668
+ const targetSharing = scopeSharingOf(target);
669
+ const sourceSharing = scopeSharingOf(source);
670
+ if (sourceSharing.mode === 'allExcept') {
671
+ if (targetSharing.mode === 'all') return true;
672
+ if (targetSharing.mode !== 'allExcept') return false;
673
+ const sourceExcept = new Set(sourceSharing.exceptHostIds);
674
+ if (!targetSharing.exceptHostIds.every((id)=>sourceExcept.has(id))) return false;
675
+ }
676
+ return scopeCovers(targetTokens, sourceTokens);
677
+ }
405
678
 
406
679
  //# sourceMappingURL=scope-tokens.js.map