@aglyn/aglyn 1.0.0-beta.285 → 1.0.0-beta.288

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 (91) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/account-acquisition.d.ts +14 -0
  3. package/src/lib/app-utils/account-acquisition.js +19 -0
  4. package/src/lib/app-utils/account-acquisition.js.map +1 -1
  5. package/src/lib/app-utils/api-plugins.d.ts +25 -0
  6. package/src/lib/app-utils/api-plugins.js +13 -0
  7. package/src/lib/app-utils/api-plugins.js.map +1 -1
  8. package/src/lib/app-utils/business-profile-values.d.ts +15 -3
  9. package/src/lib/app-utils/business-profile-values.js +19 -3
  10. package/src/lib/app-utils/business-profile-values.js.map +1 -1
  11. package/src/lib/app-utils/business-profile.d.ts +5 -3
  12. package/src/lib/app-utils/business-profile.js +2 -1
  13. package/src/lib/app-utils/business-profile.js.map +1 -1
  14. package/src/lib/app-utils/contacts.d.ts +11 -0
  15. package/src/lib/app-utils/contacts.js +18 -0
  16. package/src/lib/app-utils/contacts.js.map +1 -1
  17. package/src/lib/app-utils/docs-deflection.d.ts +1 -1
  18. package/src/lib/app-utils/docs-deflection.js +17 -0
  19. package/src/lib/app-utils/docs-deflection.js.map +1 -1
  20. package/src/lib/app-utils/docs-help-sections.generated.js +5 -2
  21. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  22. package/src/lib/app-utils/docs-help.generated.d.ts +9 -9
  23. package/src/lib/app-utils/docs-help.generated.js +20 -0
  24. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  25. package/src/lib/app-utils/docs-index.generated.js +168 -63
  26. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  27. package/src/lib/app-utils/docs-retrieval.d.ts +17 -0
  28. package/src/lib/app-utils/docs-retrieval.js +28 -0
  29. package/src/lib/app-utils/docs-retrieval.js.map +1 -1
  30. package/src/lib/app-utils/host-naming.d.ts +2 -1
  31. package/src/lib/app-utils/host-naming.js +65 -2
  32. package/src/lib/app-utils/host-naming.js.map +1 -1
  33. package/src/lib/app-utils/host-permissions.d.ts +159 -3
  34. package/src/lib/app-utils/host-permissions.js +384 -12
  35. package/src/lib/app-utils/host-permissions.js.map +1 -1
  36. package/src/lib/app-utils/org-permission-editor.d.ts +128 -1
  37. package/src/lib/app-utils/org-permission-editor.js +176 -1
  38. package/src/lib/app-utils/org-permission-editor.js.map +1 -1
  39. package/src/lib/app-utils/org-permissions.d.ts +62 -1
  40. package/src/lib/app-utils/org-permissions.js +55 -5
  41. package/src/lib/app-utils/org-permissions.js.map +1 -1
  42. package/src/lib/app-utils/org-role-grants.d.ts +28 -0
  43. package/src/lib/app-utils/org-role-grants.js +180 -2
  44. package/src/lib/app-utils/org-role-grants.js.map +1 -1
  45. package/src/lib/app-utils/org-roles.js +11 -2
  46. package/src/lib/app-utils/org-roles.js.map +1 -1
  47. package/src/lib/app-utils/redirect-query.d.ts +39 -0
  48. package/src/lib/app-utils/redirect-query.js +57 -0
  49. package/src/lib/app-utils/redirect-query.js.map +1 -0
  50. package/src/lib/app-utils/release-flags.js +2 -2
  51. package/src/lib/app-utils/release-flags.js.map +1 -1
  52. package/src/lib/app-utils/site-starter-links.d.ts +42 -0
  53. package/src/lib/app-utils/site-starter-links.js +79 -0
  54. package/src/lib/app-utils/site-starter-links.js.map +1 -0
  55. package/src/lib/app-utils/site-starter-nodes.d.ts +91 -0
  56. package/src/lib/app-utils/site-starter-nodes.js +210 -0
  57. package/src/lib/app-utils/site-starter-nodes.js.map +1 -0
  58. package/src/lib/app-utils/site-starter-theme.d.ts +90 -0
  59. package/src/lib/app-utils/site-starter-theme.js +241 -0
  60. package/src/lib/app-utils/site-starter-theme.js.map +1 -0
  61. package/src/lib/app-utils/webhook-delivery.js +6 -1
  62. package/src/lib/app-utils/webhook-delivery.js.map +1 -1
  63. package/src/lib/foundation/definitions/organization.types.d.ts +12 -2
  64. package/src/lib/foundation/definitions/organization.types.js.map +1 -1
  65. package/src/lib/plugin-manager/first-party-plugins.generated.js +39 -0
  66. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  67. package/src/lib/plugin-manager/plugin-closure-notices.d.ts +88 -0
  68. package/src/lib/plugin-manager/plugin-closure-notices.js +123 -0
  69. package/src/lib/plugin-manager/plugin-closure-notices.js.map +1 -0
  70. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +15 -0
  71. package/src/lib/plugin-manager/plugin-contact-capture.js +24 -1
  72. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
  73. package/src/lib/plugin-manager/plugin-customer-display-verifier.d.ts +77 -0
  74. package/src/lib/plugin-manager/plugin-customer-display-verifier.js +74 -0
  75. package/src/lib/plugin-manager/plugin-customer-display-verifier.js.map +1 -0
  76. package/src/lib/plugin-manager/plugin-customer-display.d.ts +135 -0
  77. package/src/lib/plugin-manager/plugin-customer-display.js +189 -0
  78. package/src/lib/plugin-manager/plugin-customer-display.js.map +1 -0
  79. package/src/lib/plugin-manager/plugin-entitlements.d.ts +59 -0
  80. package/src/lib/plugin-manager/plugin-entitlements.js +32 -3
  81. package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
  82. package/src/lib/plugin-manager/plugin-events.d.ts +45 -0
  83. package/src/lib/plugin-manager/plugin-events.js.map +1 -1
  84. package/src/lib/plugin-manager/plugin-permissions.d.ts +74 -0
  85. package/src/lib/plugin-manager/plugin-permissions.js +91 -1
  86. package/src/lib/plugin-manager/plugin-permissions.js.map +1 -1
  87. package/src/lib/plugin-manager/plugin-site-starters.d.ts +7 -0
  88. package/src/lib/plugin-manager/plugin-site-starters.js.map +1 -1
  89. package/src/lib/plugin-manager/plugin-tax-return-sources.d.ts +87 -4
  90. package/src/lib/plugin-manager/plugin-tax-return-sources.js +155 -35
  91. package/src/lib/plugin-manager/plugin-tax-return-sources.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/org-permissions.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\nimport type { AglynOrgMember, OrgRole } from '../foundation'\nimport {\n listPluginCatalogPermissions,\n subscribePluginEntitlements,\n} from '../plugin-manager/plugin-entitlements'\nimport { subscribePluginPermissions } from '../plugin-manager/plugin-permissions'\nimport { ORG_ROLE_PERMISSION_KEYS } from './org-roles'\nimport {\n CORE_ORG_PERMISSION_ENTRIES,\n CORE_ORG_PERMISSION_GROUPS,\n CORE_ORG_ROLE_GRANTS,\n type OrgPermissionGroup,\n type OrgPermissionScope,\n} from './org-role-grants'\n\nexport type { OrgPermissionGroup, OrgPermissionScope }\n\n/**\n * Granular org permissions (AGL-243) layered on the 4 org roles: each\n * role maps to a default permission set; custom roles\n * (`orgs/{orgId}/roles/{roleId}`) and per-member overrides refine it, so\n * e.g. an editor restricted to one host can also be granted billing\n * visibility — or an admin stripped of it — without inventing new roles.\n * The console hides unpermitted surfaces; the org API routes are the\n * enforcement point.\n */\nexport type CoreOrgPermission =\n | 'org.settings'\n | 'org.auditLog'\n | 'billing.view'\n | 'billing.manage'\n | 'members.manage'\n | 'hosts.create'\n | 'hosts.delete'\n | 'data.manage'\n | 'marketplace.publish'\n | 'plugins.install'\n\n/**\n * A key of the catalog: a core key above, or a key a plugin declares into\n * the catalog through `registerPluginEntitlements` (AGL-2984). A declared key\n * is stored on custom roles and member overrides, layered and resolved\n * exactly like a core key.\n */\nexport type OrgPermission = CoreOrgPermission | (string & {})\n\n/**\n * Legacy boolean permission map derived from the granular `OrgPermission`\n * set (AGL-243). Kept for the console surfaces that predate the granular\n * model; lives here so relocated feature plugins can accept it as a prop\n * (AGL-395).\n */\nexport interface OrgPermissions {\n createHosts: boolean\n editHosts: boolean\n editBilling: boolean\n publishToMarketplace: boolean\n installPlugins: boolean\n manageMembers: boolean\n}\n\nexport interface OrgPermissionDefinition {\n key: OrgPermission\n label: string\n description: string\n /** The plugin that declared the key; absent for a core key. */\n pluginId?: string\n /** The `ORG_PERMISSION_GROUPS` id the role editor files it under (AGL-4047). */\n group: string\n /** Where it is decided: `org`, or `site` for a key a site collaborator holds per site. */\n scope: OrgPermissionScope\n /** Each org role's verdict when nothing refines it (`DEFAULT_ROLE_PERMISSIONS`). */\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n /** Each host role's verdict, for a `site` key. */\n hostRoleDefaults?: Readonly<Record<string, boolean>>\n}\n\n/**\n * The core keys, in display order for role editors.\n *\n * ⚠️ **EVERY KEY HERE MUST BE ENFORCED SERVER-SIDE.** A permission a customer\n * can tick that changes nothing is worse than its absence, because it implies\n * a control that does not exist — an owner unticks \"delete sites\", hands the\n * role out, and the member deletes sites while the console does not even dim\n * the button. Three of the eleven were in exactly that state (AGL-2444).\n *\n * `marketing.manage` was removed rather than wired, and the reason is worth\n * keeping: announcement bars, popups and campaigns live at\n * `hosts/{hostId}/overlays|campaigns|experiments` and are written\n * client-direct against the security rules, which gate on the HOST role.\n * There is no org-level boundary for it to sit on, and the action it named is\n * not org-scoped at all. Wiring it would have meant inventing one and\n * producing a second permission that looks enforced and is not. If a granular\n * marketing permission is wanted it belongs in the plugin-declared mechanism\n * (AGL-435), scoped to a host — a product decision, not this repair.\n *\n * `apps/console/specs/org-permissions-are-enforced.spec.ts` fails the build if\n * a key here, or a key a plugin declares, gains no server-side consumer.\n */\nconst CORE_ORG_PERMISSIONS: readonly OrgPermissionDefinition[] =\n // One table, shared with the native apps through the contracts (AGL-3950).\n CORE_ORG_PERMISSION_ENTRIES.map((entry) => ({\n ...entry,\n key: entry.key as CoreOrgPermission,\n group: entry.group ?? 'organization',\n scope: 'org' as const,\n roleDefaults: {\n owner: CORE_ORG_ROLE_GRANTS.owner.includes(entry.key),\n admin: CORE_ORG_ROLE_GRANTS.admin.includes(entry.key),\n editor: CORE_ORG_ROLE_GRANTS.editor.includes(entry.key),\n viewer: CORE_ORG_ROLE_GRANTS.viewer.includes(entry.key),\n },\n }))\n\n/** The core keys: a plugin may add keys beside them and never redefine one. */\nconst CORE_ORG_PERMISSION_KEYS: ReadonlySet<string> = new Set(\n CORE_ORG_PERMISSIONS.map((definition) => definition.key),\n)\n\n/** The legacy camelCase projection's keys, which no declaration may take either. */\nconst LEGACY_PERMISSION_KEYS: ReadonlySet<string> = new Set<string>(\n ORG_ROLE_PERMISSION_KEYS,\n)\n\n/** The org roles, in the order `DEFAULT_ROLE_PERMISSIONS` lists them. */\nconst ORG_ROLES: readonly OrgRole[] = ['owner', 'admin', 'editor', 'viewer']\n\n/**\n * Every permission, in display order for role editors: the core keys, then\n * the keys plugins declare through `registerPluginEntitlements`, in the\n * plugins' catalog order (AGL-2984).\n *\n * LIVE, and kept in step in place. A plugin's declarations register at\n * module scope — at boot on the server, before the first paint in the\n * console — which can be after a module holding this binding was evaluated.\n * So this array, the key list, the role defaults and the empty map below are\n * rewritten in place on every registration instead of being computed once\n * when this module loads, and whoever holds the binding reads the declared\n * keys with the core ones.\n */\nexport const ORG_PERMISSIONS: readonly OrgPermissionDefinition[] = []\n\nexport const ORG_PERMISSION_KEYS: readonly OrgPermission[] = []\n\n/**\n * The groups the catalog's keys are filed under, in display order (AGL-4047):\n * the core groups, then one per plugin group a declaration names. Live, like\n * `ORG_PERMISSIONS`; a group with no key is left out.\n */\nexport const ORG_PERMISSION_GROUPS: readonly OrgPermissionGroup[] = []\n\n/**\n * The catalog keys that came through `registerPluginPermissions` (AGL-4047):\n * the keys the per-tier resolver (`resolveRolePermissions`) also answers,\n * which a caller holding a catalog-resolved map lays over that resolver's\n * answer so a custom role reaches them. Live.\n */\nexport const TIER_PERMISSION_KEYS: readonly OrgPermission[] = []\n\nconst NO_PERMISSIONS = {} as Record<OrgPermission, boolean>\n\n/**\n * Role → default permission set. Owner/admin hold everything (owner-only\n * actions like org deletion stay role-checked, not permission-checked);\n * editors work on content but see no money or roster controls; viewers read\n * only. A declared key's default for each role is the one its declaration\n * names.\n */\nexport const DEFAULT_ROLE_PERMISSIONS: Record<\n OrgRole,\n Record<OrgPermission, boolean>\n> = {\n owner: {} as Record<OrgPermission, boolean>,\n admin: {} as Record<OrgPermission, boolean>,\n editor: {} as Record<OrgPermission, boolean>,\n viewer: {} as Record<OrgPermission, boolean>,\n}\n\n/** Refused declarations already logged, so a refusal is reported once. */\nconst reportedRefusals = new Set<string>()\n\nfunction replaceItems<T>(target: readonly T[], items: readonly T[]): void {\n const list = target as T[]\n list.length = 0\n list.push(...items)\n}\n\nfunction replaceEntries(\n target: Record<string, boolean>,\n entries: Record<string, boolean>,\n): void {\n for (const key of Object.keys(target)) delete target[key]\n Object.assign(target, entries)\n}\n\n/**\n * Rebuilds the live catalog: the core keys, then every key a plugin declared\n * through either declaration API (`listPluginCatalogPermissions`, AGL-4047).\n * A declaration naming a core or legacy key is refused — that key keeps its\n * own meaning and defaults — and logged once.\n */\nfunction syncCatalog(): void {\n const definitions: OrgPermissionDefinition[] = [...CORE_ORG_PERMISSIONS]\n const tierKeys: string[] = []\n const groups: OrgPermissionGroup[] = CORE_ORG_PERMISSION_GROUPS.map((group) => ({ ...group }))\n for (const declared of listPluginCatalogPermissions()) {\n if (\n CORE_ORG_PERMISSION_KEYS.has(declared.key) ||\n LEGACY_PERMISSION_KEYS.has(declared.key)\n ) {\n const refusal = `${declared.pluginId}\\x00${declared.key}`\n if (!reportedRefusals.has(refusal)) {\n reportedRefusals.add(refusal)\n console.error(\n `[plugins] refused catalog permission \"${declared.key}\" to ` +\n `\"${declared.pluginId}\": the key belongs to the core catalog`,\n )\n }\n continue\n }\n definitions.push({\n key: declared.key,\n label: declared.label,\n description: declared.description,\n pluginId: declared.pluginId,\n group: declared.group,\n scope: declared.hostRoleDefaults ? 'site' : 'org',\n roleDefaults: declared.roleDefaults,\n ...(declared.hostRoleDefaults ? { hostRoleDefaults: declared.hostRoleDefaults } : {}),\n })\n if (declared.source === 'tier') tierKeys.push(declared.key)\n if (!groups.some((group) => group.id === declared.group)) {\n groups.push({ id: declared.group, label: declared.groupLabel, pluginId: declared.pluginId })\n }\n }\n const keys = definitions.map((definition) => definition.key)\n replaceItems(ORG_PERMISSIONS, definitions)\n replaceItems(ORG_PERMISSION_KEYS, keys)\n replaceItems(\n ORG_PERMISSION_GROUPS,\n groups.filter((group) => definitions.some((definition) => definition.group === group.id)),\n )\n replaceItems(TIER_PERMISSION_KEYS, tierKeys)\n replaceEntries(NO_PERMISSIONS, Object.fromEntries(keys.map((key) => [key, false])))\n for (const role of ORG_ROLES) {\n replaceEntries(\n DEFAULT_ROLE_PERMISSIONS[role],\n Object.fromEntries(\n definitions.map((definition) => [definition.key, definition.roleDefaults[role] === true]),\n ),\n )\n }\n CATALOG_AND_LEGACY_KEYS.clear()\n for (const key of [...keys, ...LEGACY_PERMISSION_KEYS]) {\n CATALOG_AND_LEGACY_KEYS.add(key)\n }\n}\n\n/**\n * The `registerPluginPermissions` keys of a catalog-resolved map (AGL-4047).\n *\n * Those keys are answered twice: by the per-tier resolver\n * (`resolveRolePermissions`, the role's tier default and the member's\n * override) and, now that they are catalog keys, by `resolveOrgPermissions`\n * with every layer — the custom role's included. A caller that builds its\n * map from the first spreads this over it, so the custom role a member\n * carries reaches `managePos` the way it reaches `hosts.create`.\n */\nexport function tierPermissionsOf(\n granted: Readonly<Record<string, boolean>> | null | undefined,\n): Record<string, boolean> {\n const picked: Record<string, boolean> = {}\n if (!granted) return picked\n for (const key of TIER_PERMISSION_KEYS) {\n if (typeof granted[key] === 'boolean') picked[key] = granted[key]\n }\n return picked\n}\n\n/** One catalog key by name, or undefined. */\nexport function orgPermissionDefinition(\n permission: OrgPermission,\n): OrgPermissionDefinition | undefined {\n return ORG_PERMISSIONS.find((definition) => definition.key === permission)\n}\n\n/** `orgs/{orgId}/roles/{roleId}` — a named custom permission set. */\nexport interface AglynOrgCustomRole {\n $id?: string\n name?: string\n description?: string\n /** Full permission map; missing keys read as false. */\n permissions?: Partial<Record<OrgPermission, boolean>>\n}\n\n/**\n * Effective permission map for a member: the org role's defaults, then\n * the custom role's map (when the member has `roleId` and the role doc\n * is supplied), then per-member overrides — later layers win key-by-key.\n */\nexport function resolveOrgPermissions(\n member:\n | (Partial<AglynOrgMember> & {\n roleId?: string\n permissions?: Partial<Record<OrgPermission, boolean>>\n })\n | null\n | undefined,\n customRole?: AglynOrgCustomRole | null,\n): Record<OrgPermission, boolean> {\n if (!member) return NO_PERMISSIONS\n const role = (member.role ?? 'viewer') as OrgRole\n const base = DEFAULT_ROLE_PERMISSIONS[role] ?? NO_PERMISSIONS\n const merged: Record<OrgPermission, boolean> = { ...base }\n if (member.roleId && customRole?.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = customRole.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n if (member.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = member.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n return merged\n}\n\n/**\n * The values a custom role and a per-member override set EXPLICITLY for\n * permission keys outside this catalog — the keys plugins declare through\n * `registerPluginPermissions` (AGL-2974).\n *\n * `resolveOrgPermissions` walks the catalog alone, so a plugin key stored on\n * a custom role or a member document never reached the `resolvedPermissions`\n * stamp the Firestore rules read. A rule gating on one could then honor\n * neither a grant to an editor nor a revocation from an admin. This carries\n * exactly those stored decisions, custom role first and the per-member\n * override over it, which is the precedence the resolver applies.\n *\n * Tier DEFAULTS are deliberately absent. They live in the plugin registry,\n * which is populated per process by whichever plugin bundles that process\n * loaded, and a stamp computed from it would differ by which route happened\n * to write it. A rule supplies the default itself from the member's role,\n * the way `memberResolves` is always conjoined with a role gate.\n *\n * The legacy six camelCase keys are excluded as well: they are the catalog's\n * older projection, not plugin keys, and no rule reads them.\n */\nexport function explicitPluginPermissionValues(\n member:\n | {\n roleId?: string\n permissions?: Partial<Record<string, unknown>> | null\n }\n | null\n | undefined,\n customRole?: { permissions?: Partial<Record<string, unknown>> | null } | null,\n): Record<string, boolean> {\n const values: Record<string, boolean> = {}\n if (!member) return values\n const layers = [\n member.roleId ? customRole?.permissions : undefined,\n member.permissions,\n ]\n for (const layer of layers) {\n for (const [key, value] of Object.entries(layer ?? {})) {\n if (typeof value !== 'boolean') continue\n if (CATALOG_AND_LEGACY_KEYS.has(key)) continue\n values[key] = value\n }\n }\n return values\n}\n\n/**\n * Keys {@link explicitPluginPermissionValues} leaves to the catalog: every\n * catalog key, declared ones included, and the legacy six. Kept in step by\n * `syncCatalog`.\n */\nconst CATALOG_AND_LEGACY_KEYS = new Set<string>()\n\n/**\n * The `resolvedPermissions` map stamped on a member document for the\n * Firestore rules: the catalog verdict with every layer applied, and beside\n * it the plugin keys a custom role or an override set explicitly.\n *\n * One function for every writer of the stamp, so the org-create transaction\n * and `syncOrgAuthProjections` cannot project different maps. The catalog\n * spreads last; the two key spaces do not overlap, and the order keeps it\n * true that nothing but the resolver decides a catalog key.\n */\nexport function projectMemberResolvedPermissions(\n member: Parameters<typeof resolveOrgPermissions>[0],\n customRole?: AglynOrgCustomRole | null,\n): Record<string, boolean> {\n return {\n ...explicitPluginPermissionValues(member, customRole),\n ...resolveOrgPermissions(member, customRole),\n }\n}\n\n/** Single-permission convenience over `resolveOrgPermissions`. */\nexport function hasOrgPermission(\n member: Parameters<typeof resolveOrgPermissions>[0],\n permission: OrgPermission,\n customRole?: AglynOrgCustomRole | null,\n): boolean {\n return resolveOrgPermissions(member, customRole)[permission]\n}\n\n/** The catalog label for a key — the words a refusal names — or the key itself. */\nexport function orgPermissionLabel(permission: OrgPermission): string {\n return (\n ORG_PERMISSIONS.find((definition) => definition.key === permission)?.label ??\n permission\n )\n}\n\n/** The keys plugins declared into the catalog, in catalog order. */\nexport function pluginOrgPermissionKeys(): OrgPermission[] {\n return ORG_PERMISSIONS.filter((definition) => definition.pluginId).map(\n (definition) => definition.key,\n )\n}\n\n/** One declared catalog key that moved, and the direction it moved in. */\nexport interface PluginPermissionChange {\n permission: string\n granted: boolean\n}\n\n/**\n * The keys PLUGINS declared into the catalog whose value moved between two\n * maps, in the new map's order — what a member, role or collaborator write\n * raises `org.permissions.changed` for, once per key, so the plugin that owns\n * a key can record who moved it.\n *\n * A key the new map leaves unset is not a change: on a role it defers to the\n * base role, on a site toggle to the host role, and neither is a grant or a\n * revocation of its own. A key set for the first time is a change, because\n * the verdict it produces is no longer the default's. The core keys and the\n * legacy six raise nothing; their writes are recorded by the routes' own\n * activity sentences.\n */\nexport function pluginPermissionChanges(\n before: Partial<Record<string, unknown>> | null | undefined,\n after: Partial<Record<string, unknown>> | null | undefined,\n): PluginPermissionChange[] {\n const changes: PluginPermissionChange[] = []\n for (const [key, next] of Object.entries(after ?? {})) {\n if (typeof next !== 'boolean') continue\n if (CORE_ORG_PERMISSION_KEYS.has(key) || LEGACY_PERMISSION_KEYS.has(key)) continue\n if (before?.[key] === next) continue\n changes.push({ permission: key, granted: next })\n }\n return changes\n}\n\n/**\n * The granular (dotted) set projected onto the legacy boolean map\n * (AGL-2350).\n *\n * ## Why this lives here rather than in the console hook\n *\n * It was a private function in `apps/console/hooks/use-org-permissions.ts`,\n * which meant the CLIENT translated the stored permission model into the\n * legacy flags and the SERVER did not translate at all — it derived the\n * legacy flags straight from the built-in role tier and dropped custom roles\n * and per-member overrides on the floor. The two disagreed exactly on the\n * feature `custom-roles.md` sells, in both directions: a permission granted\n * by a custom role showed in the UI and 403'd on POST, and one revoked by an\n * override was hidden in the UI and still succeeded on POST.\n *\n * One exported copy is what stops them drifting again.\n *\n * ## The key spaces are NOT interchangeable, and that is the trap\n *\n * Two permission vocabularies exist. The stored one is DOTTED\n * (`plugins.install`) — `apps/console/app/api/orgs/roles/route.ts` sanitizes\n * against `ORG_PERMISSION_KEYS` before writing, and `AglynOrgMember`\n * `permissions` is typed to it. The legacy one is camelCase\n * (`installPlugins`).\n *\n * `resolveRolePermissions` in `org-roles.ts` accepts `overrides` and\n * `customRoles` arguments keyed by the CAMELCASE space. Feeding it the real\n * stored documents therefore matches no key and changes nothing — it looks\n * like wiring the feature up while doing precisely nothing. Those two\n * parameters are used by nothing but that module's own spec. Translate\n * through here instead.\n *\n * `editHosts` is derived from the ROLE, not from a dotted key: it has no\n * counterpart in the granular catalog and never had one.\n */\nexport function toLegacyPermissions(\n granted: Record<OrgPermission, boolean>,\n role: OrgRole | null | undefined,\n): OrgPermissions {\n return {\n createHosts: granted['hosts.create'],\n editHosts: role !== 'viewer',\n editBilling: granted['billing.manage'],\n publishToMarketplace: granted['marketplace.publish'],\n installPlugins: granted['plugins.install'],\n manageMembers: granted['members.manage'],\n }\n}\n\nsyncCatalog()\nsubscribePluginEntitlements(syncCatalog)\n// The second declaration API feeds the same catalog (AGL-4047).\nsubscribePluginPermissions(syncCatalog)\n"],"names":["listPluginCatalogPermissions","subscribePluginEntitlements","subscribePluginPermissions","ORG_ROLE_PERMISSION_KEYS","CORE_ORG_PERMISSION_ENTRIES","CORE_ORG_PERMISSION_GROUPS","CORE_ORG_ROLE_GRANTS","CORE_ORG_PERMISSIONS","map","entry","key","group","scope","roleDefaults","owner","includes","admin","editor","viewer","CORE_ORG_PERMISSION_KEYS","Set","definition","LEGACY_PERMISSION_KEYS","ORG_ROLES","ORG_PERMISSIONS","ORG_PERMISSION_KEYS","ORG_PERMISSION_GROUPS","TIER_PERMISSION_KEYS","NO_PERMISSIONS","DEFAULT_ROLE_PERMISSIONS","reportedRefusals","replaceItems","target","items","list","length","push","replaceEntries","entries","Object","keys","assign","syncCatalog","definitions","tierKeys","groups","declared","has","refusal","pluginId","add","console","error","label","description","hostRoleDefaults","source","some","id","groupLabel","filter","fromEntries","role","CATALOG_AND_LEGACY_KEYS","clear","tierPermissionsOf","granted","picked","orgPermissionDefinition","permission","find","resolveOrgPermissions","member","customRole","base","merged","roleId","permissions","value","explicitPluginPermissionValues","values","layers","undefined","layer","projectMemberResolvedPermissions","hasOrgPermission","orgPermissionLabel","pluginOrgPermissionKeys","pluginPermissionChanges","before","after","changes","next","toLegacyPermissions","createHosts","editHosts","editBilling","publishToMarketplace","installPlugins","manageMembers"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,4BAA4B,EAC5BC,2BAA2B,QACtB,2CAAuC;AAC9C,SAASC,0BAA0B,QAAQ,0CAAsC;AACjF,SAASC,wBAAwB,QAAQ,iBAAa;AACtD,SACEC,2BAA2B,EAC3BC,0BAA0B,EAC1BC,oBAAoB,QAGf,uBAAmB;AAgE1B;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,MAAMC,uBACJ,2EAA2E;AAC3EH,4BAA4BI,GAAG,CAAC,CAACC;QAGxBA;WAHmC,aACvCA;QACHC,KAAKD,MAAMC,GAAG;QACdC,KAAK,GAAEF,eAAAA,MAAME,KAAK,YAAXF,eAAe;QACtBG,OAAO;QACPC,cAAc;YACZC,OAAOR,qBAAqBQ,KAAK,CAACC,QAAQ,CAACN,MAAMC,GAAG;YACpDM,OAAOV,qBAAqBU,KAAK,CAACD,QAAQ,CAACN,MAAMC,GAAG;YACpDO,QAAQX,qBAAqBW,MAAM,CAACF,QAAQ,CAACN,MAAMC,GAAG;YACtDQ,QAAQZ,qBAAqBY,MAAM,CAACH,QAAQ,CAACN,MAAMC,GAAG;QACxD;;;AAGJ,6EAA6E,GAC7E,MAAMS,2BAAgD,IAAIC,IACxDb,qBAAqBC,GAAG,CAAC,CAACa,aAAeA,WAAWX,GAAG;AAGzD,kFAAkF,GAClF,MAAMY,yBAA8C,IAAIF,IACtDjB;AAGF,uEAAuE,GACvE,MAAMoB,YAAgC;IAAC;IAAS;IAAS;IAAU;CAAS;AAE5E;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,kBAAsD,EAAE,CAAA;AAErE,OAAO,MAAMC,sBAAgD,EAAE,CAAA;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,IAAIrD,OAAOD,OAAO,CAACoD,gBAAAA,QAAS,CAAC,GAAI;QACrD,IAAI,OAAOE,SAAS,WAAW;QAC/B,IAAIzE,yBAAyB4B,GAAG,CAACrC,QAAQY,uBAAuByB,GAAG,CAACrC,MAAM;QAC1E,IAAI+E,CAAAA,0BAAAA,MAAQ,CAAC/E,IAAI,MAAKkF,MAAM;QAC5BD,QAAQvD,IAAI,CAAC;YAAEiC,YAAY3D;YAAKwD,SAAS0B;QAAK;IAChD;IACA,OAAOD;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCC,GACD,OAAO,SAASE,oBACd3B,OAAuC,EACvCJ,IAAgC;IAEhC,OAAO;QACLgC,aAAa5B,OAAO,CAAC,eAAe;QACpC6B,WAAWjC,SAAS;QACpBkC,aAAa9B,OAAO,CAAC,iBAAiB;QACtC+B,sBAAsB/B,OAAO,CAAC,sBAAsB;QACpDgC,gBAAgBhC,OAAO,CAAC,kBAAkB;QAC1CiC,eAAejC,OAAO,CAAC,iBAAiB;IAC1C;AACF;AAEAxB;AACAzC,4BAA4ByC;AAC5B,gEAAgE;AAChExC,2BAA2BwC"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/org-permissions.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\nimport type { AglynOrgMember, OrgRole } from '../foundation'\nimport {\n listPluginCatalogPermissions,\n subscribePluginEntitlements,\n} from '../plugin-manager/plugin-entitlements'\nimport {\n permissionRefinementOf,\n refinePermissionMap,\n subscribePluginPermissions,\n type PermissionRefinement,\n} from '../plugin-manager/plugin-permissions'\nimport { ORG_ROLE_PERMISSION_KEYS } from './org-roles'\nimport {\n CORE_ORG_PERMISSION_ENTRIES,\n CORE_ORG_PERMISSION_GROUPS,\n CORE_ORG_ROLE_GRANTS,\n CORE_SITE_ROLE_PRESETS,\n type OrgPermissionGroup,\n type OrgPermissionScope,\n} from './org-role-grants'\n\nexport type { OrgPermissionGroup, OrgPermissionScope }\n\n/**\n * Granular org permissions (AGL-243) layered on the 4 org roles: each\n * role maps to a default permission set; custom roles\n * (`orgs/{orgId}/roles/{roleId}`) and per-member overrides refine it, so\n * e.g. an editor restricted to one host can also be granted billing\n * visibility — or an admin stripped of it — without inventing new roles.\n * The console hides unpermitted surfaces; the org API routes are the\n * enforcement point.\n */\nexport type CoreOrgPermission =\n | 'org.settings'\n | 'org.auditLog'\n | 'org.apiKeys'\n | 'org.privacy'\n | 'org.holds'\n | 'org.export'\n | 'org.sendingDomains'\n | 'org.businessProfile'\n | 'org.media'\n | 'org.eraseRecords'\n | 'billing.view'\n | 'billing.manage'\n | 'members.manage'\n | 'hosts.create'\n | 'hosts.delete'\n | 'data.manage'\n | 'marketplace.publish'\n | 'plugins.install'\n | 'site.edit'\n | 'site.publish'\n | 'site.sensitive'\n | 'site.manage'\n\n/**\n * A key of the catalog: a core key above, or a key a plugin declares into\n * the catalog through `registerPluginEntitlements` (AGL-2984). A declared key\n * is stored on custom roles and member overrides, layered and resolved\n * exactly like a core key.\n */\nexport type OrgPermission = CoreOrgPermission | (string & {})\n\n/**\n * Legacy boolean permission map derived from the granular `OrgPermission`\n * set (AGL-243). Kept for the console surfaces that predate the granular\n * model; lives here so relocated feature plugins can accept it as a prop\n * (AGL-395).\n */\nexport interface OrgPermissions {\n createHosts: boolean\n editHosts: boolean\n editBilling: boolean\n publishToMarketplace: boolean\n installPlugins: boolean\n manageMembers: boolean\n}\n\nexport interface OrgPermissionDefinition {\n key: OrgPermission\n label: string\n description: string\n /** The plugin that declared the key; absent for a core key. */\n pluginId?: string\n /** The `ORG_PERMISSION_GROUPS` id the role editor files it under (AGL-4047). */\n group: string\n /** Where it is decided: `org`, or `site` for a key a site collaborator holds per site. */\n scope: OrgPermissionScope\n /** Each org role's verdict when nothing refines it (`DEFAULT_ROLE_PERMISSIONS`). */\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n /** Each host role's verdict, for a `site` key. */\n hostRoleDefaults?: Readonly<Record<string, boolean>>\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. Only a plugin's key refines, and only a key the catalog holds.\n */\n refines?: OrgPermission\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. Only a plugin's key follows, and only a key the catalog\n * holds; a key that refines does not also follow.\n */\n follows?: OrgPermission\n /**\n * Present when a site can narrow the key (AGL-4047): where a member who\n * works across the workspace has narrower access to one site than their\n * workspace role, whether the key follows that site role there is a\n * control, set per key on a custom role (`siteNarrowing`) and per member\n * (`AglynOrgMember.siteNarrowing`), and this is each built-in role's\n * default for it. `narrowPermissionsToSite` applies it. Only a plugin's key.\n */\n narrowsPerSite?: Readonly<Record<OrgRole, boolean>>\n /**\n * The key's preset is the member's role ON THE SITE a request names, for\n * every member (AGL-4047): `hostRoleDefaults` read for the access they hold\n * there, then their custom role, their own permissions and that site's\n * toggle. `roleDefaults` is the answer with no site named.\n * `resolveSiteRolePresetPermissions` decides it. The core's site keys\n * (`CORE_SITE_ROLE_PRESETS`) and a plugin's key with `hostRoleDefaults`.\n */\n presetFromSiteRole?: true\n /**\n * With `presetFromSiteRole`: the site role is the preset only for a member\n * of the whole workspace (AGL-4047). A site collaborator's preset is\n * refusal, whatever their site role, and only the site's toggle grants it\n * to them. A plugin's key that replaces a gate asking for an admin of the\n * whole workspace who is also the site's admin.\n */\n workspaceMembersOnly?: true\n}\n\n/**\n * The core keys, in display order for role editors.\n *\n * ⚠️ **EVERY KEY HERE MUST BE ENFORCED SERVER-SIDE.** A permission a customer\n * can tick that changes nothing is worse than its absence, because it implies\n * a control that does not exist — an owner unticks \"delete sites\", hands the\n * role out, and the member deletes sites while the console does not even dim\n * the button. Three of the eleven were in exactly that state (AGL-2444).\n *\n * `marketing.manage` was removed rather than wired, and the reason is worth\n * keeping: announcement bars, popups and campaigns live at\n * `hosts/{hostId}/overlays|campaigns|experiments` and are written\n * client-direct against the security rules, which gate on the HOST role.\n * There is no org-level boundary for it to sit on, and the action it named is\n * not org-scoped at all. Wiring it would have meant inventing one and\n * producing a second permission that looks enforced and is not. If a granular\n * marketing permission is wanted it belongs in the plugin-declared mechanism\n * (AGL-435), scoped to a host — a product decision, not this repair.\n *\n * `apps/console/specs/org-permissions-are-enforced.spec.ts` fails the build if\n * a key here, or a key a plugin declares, gains no server-side consumer.\n */\nconst CORE_ORG_PERMISSIONS: readonly OrgPermissionDefinition[] =\n // One table, shared with the native apps through the contracts (AGL-3950).\n CORE_ORG_PERMISSION_ENTRIES.map((entry) => ({\n ...entry,\n key: entry.key as CoreOrgPermission,\n group: entry.group ?? 'organization',\n scope: entry.scope ?? 'org',\n // A site key's preset is the member's role on the site (AGL-4047).\n ...(CORE_SITE_ROLE_PRESETS[entry.key]\n ? { hostRoleDefaults: { ...CORE_SITE_ROLE_PRESETS[entry.key] }, presetFromSiteRole: true as const }\n : {}),\n roleDefaults: {\n owner: CORE_ORG_ROLE_GRANTS.owner.includes(entry.key),\n admin: CORE_ORG_ROLE_GRANTS.admin.includes(entry.key),\n editor: CORE_ORG_ROLE_GRANTS.editor.includes(entry.key),\n viewer: CORE_ORG_ROLE_GRANTS.viewer.includes(entry.key),\n },\n }))\n\n/** The core keys: a plugin may add keys beside them and never redefine one. */\nconst CORE_ORG_PERMISSION_KEYS: ReadonlySet<string> = new Set(\n CORE_ORG_PERMISSIONS.map((definition) => definition.key),\n)\n\n/** The legacy camelCase projection's keys, which no declaration may take either. */\nconst LEGACY_PERMISSION_KEYS: ReadonlySet<string> = new Set<string>(\n ORG_ROLE_PERMISSION_KEYS,\n)\n\n/** The org roles, in the order `DEFAULT_ROLE_PERMISSIONS` lists them. */\nconst ORG_ROLES: readonly OrgRole[] = ['owner', 'admin', 'editor', 'viewer']\n\n/**\n * Every permission, in display order for role editors: the core keys, then\n * the keys plugins declare through `registerPluginEntitlements`, in the\n * plugins' catalog order (AGL-2984).\n *\n * LIVE, and kept in step in place. A plugin's declarations register at\n * module scope — at boot on the server, before the first paint in the\n * console — which can be after a module holding this binding was evaluated.\n * So this array, the key list, the role defaults and the empty map below are\n * rewritten in place on every registration instead of being computed once\n * when this module loads, and whoever holds the binding reads the declared\n * keys with the core ones.\n */\nexport const ORG_PERMISSIONS: readonly OrgPermissionDefinition[] = []\n\nexport const ORG_PERMISSION_KEYS: readonly OrgPermission[] = []\n\n/**\n * The groups the catalog's keys are filed under, in display order (AGL-4047):\n * the core groups, then one per plugin group a declaration names. Live, like\n * `ORG_PERMISSIONS`; a group with no key is left out.\n */\nexport const ORG_PERMISSION_GROUPS: readonly OrgPermissionGroup[] = []\n\n/**\n * The catalog keys that came through `registerPluginPermissions` (AGL-4047):\n * the keys the per-tier resolver (`resolveRolePermissions`) also answers,\n * which a caller holding a catalog-resolved map lays over that resolver's\n * answer so a custom role reaches them. Live.\n */\nexport const TIER_PERMISSION_KEYS: readonly OrgPermission[] = []\n\n/**\n * Every catalog key that refines a broader one, with that key (AGL-4047),\n * and every key that only follows one, marked `'follows'`. Live, like\n * `ORG_PERMISSIONS`. A resolver lays it over its map with\n * `refinePermissionMap`.\n */\nexport const ORG_PERMISSION_REFINEMENTS: readonly PermissionRefinement[] = []\n\nconst NO_PERMISSIONS = {} as Record<OrgPermission, boolean>\n\n/**\n * Role → default permission set. Owner/admin hold everything (owner-only\n * actions like org deletion stay role-checked, not permission-checked);\n * editors work on content but see no money or roster controls; viewers read\n * only. A declared key's default for each role is the one its declaration\n * names.\n */\nexport const DEFAULT_ROLE_PERMISSIONS: Record<\n OrgRole,\n Record<OrgPermission, boolean>\n> = {\n owner: {} as Record<OrgPermission, boolean>,\n admin: {} as Record<OrgPermission, boolean>,\n editor: {} as Record<OrgPermission, boolean>,\n viewer: {} as Record<OrgPermission, boolean>,\n}\n\n/** Refused declarations already logged, so a refusal is reported once. */\nconst reportedRefusals = new Set<string>()\n\nfunction replaceItems<T>(target: readonly T[], items: readonly T[]): void {\n const list = target as T[]\n list.length = 0\n list.push(...items)\n}\n\nfunction replaceEntries(\n target: Record<string, boolean>,\n entries: Record<string, boolean>,\n): void {\n for (const key of Object.keys(target)) delete target[key]\n Object.assign(target, entries)\n}\n\n/**\n * Rebuilds the live catalog: the core keys, then every key a plugin declared\n * through either declaration API (`listPluginCatalogPermissions`, AGL-4047).\n * A declaration naming a core or legacy key is refused — that key keeps its\n * own meaning and defaults — and logged once.\n */\nfunction syncCatalog(): void {\n const definitions: OrgPermissionDefinition[] = [...CORE_ORG_PERMISSIONS]\n const tierKeys: string[] = []\n const groups: OrgPermissionGroup[] = CORE_ORG_PERMISSION_GROUPS.map((group) => ({ ...group }))\n for (const declared of listPluginCatalogPermissions()) {\n if (\n CORE_ORG_PERMISSION_KEYS.has(declared.key) ||\n LEGACY_PERMISSION_KEYS.has(declared.key)\n ) {\n const refusal = `${declared.pluginId}\\x00${declared.key}`\n if (!reportedRefusals.has(refusal)) {\n reportedRefusals.add(refusal)\n console.error(\n `[plugins] refused catalog permission \"${declared.key}\" to ` +\n `\"${declared.pluginId}\": the key belongs to the core catalog`,\n )\n }\n continue\n }\n definitions.push({\n key: declared.key,\n label: declared.label,\n description: declared.description,\n pluginId: declared.pluginId,\n group: declared.group,\n scope: declared.hostRoleDefaults ? 'site' : 'org',\n roleDefaults: declared.roleDefaults,\n ...(declared.hostRoleDefaults ? { hostRoleDefaults: declared.hostRoleDefaults } : {}),\n ...(declared.refines ? { refines: declared.refines } : {}),\n ...(declared.follows && !declared.refines ? { follows: declared.follows } : {}),\n ...(declared.narrowsPerSite ? { narrowsPerSite: { ...declared.narrowsPerSite } } : {}),\n ...(declared.presetFromSiteRole && declared.hostRoleDefaults ? { presetFromSiteRole: true as const } : {}),\n ...(declared.presetFromSiteRole && declared.hostRoleDefaults && declared.workspaceMembersOnly\n ? { workspaceMembersOnly: true as const }\n : {}),\n })\n if (declared.source === 'tier') tierKeys.push(declared.key)\n if (!groups.some((group) => group.id === declared.group)) {\n groups.push({ id: declared.group, label: declared.groupLabel, pluginId: declared.pluginId })\n }\n }\n const keys = definitions.map((definition) => definition.key)\n const known = new Set<string>(keys)\n // A refinement of a key the catalog does not hold refines nothing, and is\n // dropped from the definition so no editor offers a link to nowhere.\n for (const definition of definitions) {\n if (definition.refines && (!known.has(definition.refines) || definition.refines === definition.key)) {\n delete definition.refines\n }\n if (definition.follows && (!known.has(definition.follows) || definition.follows === definition.key)) {\n delete definition.follows\n }\n }\n replaceItems(\n ORG_PERMISSION_REFINEMENTS,\n definitions.flatMap((definition) => {\n const refinement = permissionRefinementOf(definition)\n return refinement ? [refinement] : []\n }),\n )\n replaceItems(ORG_PERMISSIONS, definitions)\n replaceItems(ORG_PERMISSION_KEYS, keys)\n replaceItems(\n ORG_PERMISSION_GROUPS,\n groups.filter((group) => definitions.some((definition) => definition.group === group.id)),\n )\n replaceItems(TIER_PERMISSION_KEYS, tierKeys)\n replaceEntries(NO_PERMISSIONS, Object.fromEntries(keys.map((key) => [key, false])))\n for (const role of ORG_ROLES) {\n replaceEntries(\n DEFAULT_ROLE_PERMISSIONS[role],\n Object.fromEntries(\n definitions.map((definition) => [definition.key, definition.roleDefaults[role] === true]),\n ),\n )\n }\n CATALOG_AND_LEGACY_KEYS.clear()\n for (const key of [...keys, ...LEGACY_PERMISSION_KEYS]) {\n CATALOG_AND_LEGACY_KEYS.add(key)\n }\n}\n\n/**\n * The `registerPluginPermissions` keys of a catalog-resolved map (AGL-4047).\n *\n * Those keys are answered twice: by the per-tier resolver\n * (`resolveRolePermissions`, the role's tier default and the member's\n * override) and, now that they are catalog keys, by `resolveOrgPermissions`\n * with every layer — the custom role's included. A caller that builds its\n * map from the first spreads this over it, so the custom role a member\n * carries reaches `managePos` the way it reaches `hosts.create`.\n */\nexport function tierPermissionsOf(\n granted: Readonly<Record<string, boolean>> | null | undefined,\n): Record<string, boolean> {\n const picked: Record<string, boolean> = {}\n if (!granted) return picked\n for (const key of TIER_PERMISSION_KEYS) {\n if (typeof granted[key] === 'boolean') picked[key] = granted[key]\n }\n return picked\n}\n\n/** One catalog key by name, or undefined. */\nexport function orgPermissionDefinition(\n permission: OrgPermission,\n): OrgPermissionDefinition | undefined {\n return ORG_PERMISSIONS.find((definition) => definition.key === permission)\n}\n\n/** `orgs/{orgId}/roles/{roleId}` — a named custom permission set. */\nexport interface AglynOrgCustomRole {\n $id?: string\n name?: string\n description?: string\n /** Full permission map; missing keys read as false. */\n permissions?: Partial<Record<OrgPermission, boolean>>\n /**\n * Per key a site can narrow (AGL-4047): `true` follows the site role on a\n * site where the member's access is narrower than their workspace role,\n * `false` keeps the permission there. A key it leaves out follows the\n * built-in role's default (`OrgPermissionDefinition.narrowsPerSite`), and\n * a member's own `siteNarrowing` wins over it.\n */\n siteNarrowing?: Partial<Record<OrgPermission, boolean>>\n}\n\n/**\n * Effective permission map for a member: the org role's defaults, then\n * the custom role's map (when the member has `roleId` and the role doc\n * is supplied), then per-member overrides — later layers win key-by-key.\n */\nexport function resolveOrgPermissions(\n member:\n | (Partial<AglynOrgMember> & {\n roleId?: string\n permissions?: Partial<Record<OrgPermission, boolean>>\n })\n | null\n | undefined,\n customRole?: AglynOrgCustomRole | null,\n): Record<OrgPermission, boolean> {\n if (!member) return NO_PERMISSIONS\n const role = (member.role ?? 'viewer') as OrgRole\n const base = DEFAULT_ROLE_PERMISSIONS[role] ?? NO_PERMISSIONS\n const merged: Record<OrgPermission, boolean> = { ...base }\n if (member.roleId && customRole?.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = customRole.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n if (member.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = member.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n // A key that refines a broader one (AGL-4047) follows it where neither\n // layer set the key, and is never held without it; a key that only follows\n // one takes its verdict where neither layer set the key, and nothing more.\n return refinePermissionMap(merged, ORG_PERMISSION_REFINEMENTS, [\n member.roleId ? customRole?.permissions : undefined,\n member.permissions,\n ])\n}\n\n/**\n * The values a custom role and a per-member override set EXPLICITLY for\n * permission keys outside this catalog — the keys plugins declare through\n * `registerPluginPermissions` (AGL-2974).\n *\n * `resolveOrgPermissions` walks the catalog alone, so a plugin key stored on\n * a custom role or a member document never reached the `resolvedPermissions`\n * stamp the Firestore rules read. A rule gating on one could then honor\n * neither a grant to an editor nor a revocation from an admin. This carries\n * exactly those stored decisions, custom role first and the per-member\n * override over it, which is the precedence the resolver applies.\n *\n * Tier DEFAULTS are deliberately absent. They live in the plugin registry,\n * which is populated per process by whichever plugin bundles that process\n * loaded, and a stamp computed from it would differ by which route happened\n * to write it. A rule supplies the default itself from the member's role,\n * the way `memberResolves` is always conjoined with a role gate.\n *\n * The legacy six camelCase keys are excluded as well: they are the catalog's\n * older projection, not plugin keys, and no rule reads them.\n */\nexport function explicitPluginPermissionValues(\n member:\n | {\n roleId?: string\n permissions?: Partial<Record<string, unknown>> | null\n }\n | null\n | undefined,\n customRole?: { permissions?: Partial<Record<string, unknown>> | null } | null,\n): Record<string, boolean> {\n const values: Record<string, boolean> = {}\n if (!member) return values\n const layers = [\n member.roleId ? customRole?.permissions : undefined,\n member.permissions,\n ]\n for (const layer of layers) {\n for (const [key, value] of Object.entries(layer ?? {})) {\n if (typeof value !== 'boolean') continue\n if (CATALOG_AND_LEGACY_KEYS.has(key)) continue\n values[key] = value\n }\n }\n return values\n}\n\n/**\n * Keys {@link explicitPluginPermissionValues} leaves to the catalog: every\n * catalog key, declared ones included, and the legacy six. Kept in step by\n * `syncCatalog`.\n */\nconst CATALOG_AND_LEGACY_KEYS = new Set<string>()\n\n/**\n * The `resolvedPermissions` map stamped on a member document for the\n * Firestore rules: the catalog verdict with every layer applied, and beside\n * it the plugin keys a custom role or an override set explicitly.\n *\n * One function for every writer of the stamp, so the org-create transaction\n * and `syncOrgAuthProjections` cannot project different maps. The catalog\n * spreads last; the two key spaces do not overlap, and the order keeps it\n * true that nothing but the resolver decides a catalog key.\n */\nexport function projectMemberResolvedPermissions(\n member: Parameters<typeof resolveOrgPermissions>[0],\n customRole?: AglynOrgCustomRole | null,\n): Record<string, boolean> {\n return {\n ...explicitPluginPermissionValues(member, customRole),\n ...resolveOrgPermissions(member, customRole),\n }\n}\n\n/** Single-permission convenience over `resolveOrgPermissions`. */\nexport function hasOrgPermission(\n member: Parameters<typeof resolveOrgPermissions>[0],\n permission: OrgPermission,\n customRole?: AglynOrgCustomRole | null,\n): boolean {\n return resolveOrgPermissions(member, customRole)[permission]\n}\n\n/** The catalog label for a key — the words a refusal names — or the key itself. */\nexport function orgPermissionLabel(permission: OrgPermission): string {\n return (\n ORG_PERMISSIONS.find((definition) => definition.key === permission)?.label ??\n permission\n )\n}\n\n/**\n * The sentence a door answers when a member does not hold a key (AGL-4047):\n * it names the permission by its catalog label and who can change it, never\n * a role.\n */\nexport function permissionRefusalText(permission: OrgPermission): string {\n return `Your role does not include \"${orgPermissionLabel(permission)}\" — ask an organization admin`\n}\n\n/** The keys plugins declared into the catalog, in catalog order. */\nexport function pluginOrgPermissionKeys(): OrgPermission[] {\n return ORG_PERMISSIONS.filter((definition) => definition.pluginId).map(\n (definition) => definition.key,\n )\n}\n\n/** One declared catalog key that moved, and the direction it moved in. */\nexport interface PluginPermissionChange {\n permission: string\n granted: boolean\n}\n\n/**\n * The keys PLUGINS declared into the catalog whose value moved between two\n * maps, in the new map's order — what a member, role or collaborator write\n * raises `org.permissions.changed` for, once per key, so the plugin that owns\n * a key can record who moved it.\n *\n * A key the new map leaves unset is not a change: on a role it defers to the\n * base role, on a site toggle to the host role, and neither is a grant or a\n * revocation of its own. A key set for the first time is a change, because\n * the verdict it produces is no longer the default's. The core keys and the\n * legacy six raise nothing; their writes are recorded by the routes' own\n * activity sentences.\n */\nexport function pluginPermissionChanges(\n before: Partial<Record<string, unknown>> | null | undefined,\n after: Partial<Record<string, unknown>> | null | undefined,\n): PluginPermissionChange[] {\n const changes: PluginPermissionChange[] = []\n for (const [key, next] of Object.entries(after ?? {})) {\n if (typeof next !== 'boolean') continue\n if (CORE_ORG_PERMISSION_KEYS.has(key) || LEGACY_PERMISSION_KEYS.has(key)) continue\n if (before?.[key] === next) continue\n changes.push({ permission: key, granted: next })\n }\n return changes\n}\n\n/**\n * The granular (dotted) set projected onto the legacy boolean map\n * (AGL-2350).\n *\n * ## Why this lives here rather than in the console hook\n *\n * It was a private function in `apps/console/hooks/use-org-permissions.ts`,\n * which meant the CLIENT translated the stored permission model into the\n * legacy flags and the SERVER did not translate at all — it derived the\n * legacy flags straight from the built-in role tier and dropped custom roles\n * and per-member overrides on the floor. The two disagreed exactly on the\n * feature `custom-roles.md` sells, in both directions: a permission granted\n * by a custom role showed in the UI and 403'd on POST, and one revoked by an\n * override was hidden in the UI and still succeeded on POST.\n *\n * One exported copy is what stops them drifting again.\n *\n * ## The key spaces are NOT interchangeable, and that is the trap\n *\n * Two permission vocabularies exist. The stored one is DOTTED\n * (`plugins.install`) — `apps/console/app/api/orgs/roles/route.ts` sanitizes\n * against `ORG_PERMISSION_KEYS` before writing, and `AglynOrgMember`\n * `permissions` is typed to it. The legacy one is camelCase\n * (`installPlugins`).\n *\n * `resolveRolePermissions` in `org-roles.ts` accepts `overrides` and\n * `customRoles` arguments keyed by the CAMELCASE space. Feeding it the real\n * stored documents therefore matches no key and changes nothing — it looks\n * like wiring the feature up while doing precisely nothing. Those two\n * parameters are used by nothing but that module's own spec. Translate\n * through here instead.\n *\n * `editHosts` is derived from the ROLE, not from a dotted key: it has no\n * counterpart in the granular catalog and never had one.\n */\nexport function toLegacyPermissions(\n granted: Record<OrgPermission, boolean>,\n role: OrgRole | null | undefined,\n): OrgPermissions {\n return {\n createHosts: granted['hosts.create'],\n editHosts: role !== 'viewer',\n editBilling: granted['billing.manage'],\n publishToMarketplace: granted['marketplace.publish'],\n installPlugins: granted['plugins.install'],\n manageMembers: granted['members.manage'],\n }\n}\n\nsyncCatalog()\nsubscribePluginEntitlements(syncCatalog)\n// The second declaration API feeds the same catalog (AGL-4047).\nsubscribePluginPermissions(syncCatalog)\n"],"names":["listPluginCatalogPermissions","subscribePluginEntitlements","permissionRefinementOf","refinePermissionMap","subscribePluginPermissions","ORG_ROLE_PERMISSION_KEYS","CORE_ORG_PERMISSION_ENTRIES","CORE_ORG_PERMISSION_GROUPS","CORE_ORG_ROLE_GRANTS","CORE_SITE_ROLE_PRESETS","CORE_ORG_PERMISSIONS","map","entry","key","group","scope","hostRoleDefaults","presetFromSiteRole","roleDefaults","owner","includes","admin","editor","viewer","CORE_ORG_PERMISSION_KEYS","Set","definition","LEGACY_PERMISSION_KEYS","ORG_ROLES","ORG_PERMISSIONS","ORG_PERMISSION_KEYS","ORG_PERMISSION_GROUPS","TIER_PERMISSION_KEYS","ORG_PERMISSION_REFINEMENTS","NO_PERMISSIONS","DEFAULT_ROLE_PERMISSIONS","reportedRefusals","replaceItems","target","items","list","length","push","replaceEntries","entries","Object","keys","assign","syncCatalog","definitions","tierKeys","groups","declared","has","refusal","pluginId","add","console","error","label","description","refines","follows","narrowsPerSite","workspaceMembersOnly","source","some","id","groupLabel","known","flatMap","refinement","filter","fromEntries","role","CATALOG_AND_LEGACY_KEYS","clear","tierPermissionsOf","granted","picked","orgPermissionDefinition","permission","find","resolveOrgPermissions","member","customRole","base","merged","roleId","permissions","value","undefined","explicitPluginPermissionValues","values","layers","layer","projectMemberResolvedPermissions","hasOrgPermission","orgPermissionLabel","permissionRefusalText","pluginOrgPermissionKeys","pluginPermissionChanges","before","after","changes","next","toLegacyPermissions","createHosts","editHosts","editBilling","publishToMarketplace","installPlugins","manageMembers"],"mappings":"AAAA;;;;;;;;;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,CACpE,CAACe,aAAeA,WAAWb,GAAG;AAElC;AAQA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASwF,wBACdC,MAA2D,EAC3DC,KAA0D;IAE1D,MAAMC,UAAoC,EAAE;IAC5C,KAAK,MAAM,CAAC3F,KAAK4F,KAAK,IAAI5D,OAAOD,OAAO,CAAC2D,gBAAAA,QAAS,CAAC,GAAI;QACrD,IAAI,OAAOE,SAAS,WAAW;QAC/B,IAAIjF,yBAAyB6B,GAAG,CAACxC,QAAQc,uBAAuB0B,GAAG,CAACxC,MAAM;QAC1E,IAAIyF,CAAAA,0BAAAA,MAAQ,CAACzF,IAAI,MAAK4F,MAAM;QAC5BD,QAAQ9D,IAAI,CAAC;YAAEuC,YAAYpE;YAAKiE,SAAS2B;QAAK;IAChD;IACA,OAAOD;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCC,GACD,OAAO,SAASE,oBACd5B,OAAuC,EACvCJ,IAAgC;IAEhC,OAAO;QACLiC,aAAa7B,OAAO,CAAC,eAAe;QACpC8B,WAAWlC,SAAS;QACpBmC,aAAa/B,OAAO,CAAC,iBAAiB;QACtCgC,sBAAsBhC,OAAO,CAAC,sBAAsB;QACpDiC,gBAAgBjC,OAAO,CAAC,kBAAkB;QAC1CkC,eAAelC,OAAO,CAAC,iBAAiB;IAC1C;AACF;AAEA9B;AACA/C,4BAA4B+C;AAC5B,gEAAgE;AAChE5C,2BAA2B4C"}
@@ -53,6 +53,19 @@ export interface OrgPermissionEntry {
53
53
  group?: string;
54
54
  /** Where it is decided; absent reads as `org`. */
55
55
  scope?: OrgPermissionScope;
56
+ /**
57
+ * The broader key this one is a finer part of (AGL-4047): never granted
58
+ * without it, and following it where no custom role or override sets this
59
+ * key. Absent for a key that refines nothing.
60
+ */
61
+ refines?: string;
62
+ /**
63
+ * The key this one follows where no custom role or override sets it,
64
+ * without needing it (AGL-4047): granted on its own, it holds while that
65
+ * key is refused. Absent for a key that follows nothing, and for one that
66
+ * refines.
67
+ */
68
+ follows?: string;
56
69
  }
57
70
  /** A heading the role editor groups keys under. */
58
71
  export interface OrgPermissionGroup {
@@ -93,6 +106,10 @@ export interface OrgPermissionDeclaration {
93
106
  /** That group's heading, for a group the core does not name. */
94
107
  groupLabel?: string;
95
108
  pluginId?: string;
109
+ /** The broader key it refines (AGL-4047). */
110
+ refines?: string;
111
+ /** The key it follows without needing it (AGL-4047). */
112
+ follows?: string;
96
113
  }
97
114
  /** A custom role (`orgs/{orgId}/roles/{roleId}`) or a member's overrides: explicit verdicts per key. */
98
115
  export interface OrgPermissionLayer {
@@ -116,6 +133,17 @@ export declare function declarationRoleDefaults(declaration: Pick<OrgPermissionD
116
133
  * enforced server-side (`apps/console/specs/org-permissions-are-enforced.spec.ts`).
117
134
  */
118
135
  export declare const CORE_ORG_PERMISSION_ENTRIES: readonly OrgPermissionEntry[];
136
+ /**
137
+ * The core keys whose preset is the member's role ON THE SITE (AGL-4047), and
138
+ * each site role's verdict: the sets the rules' `canWriteHostContent`,
139
+ * `canPublishHostContent`, `canReadHostSensitive` and the site-admin checks
140
+ * asked before they asked these keys. A member's preset on a site is the
141
+ * verdict for the role they hold there (the owner and admins are Admin on
142
+ * every site); a custom role, their own permissions and that site's toggle
143
+ * then grant or refuse it. Each workspace role's default below is the verdict
144
+ * for its own site role, which is the answer with no site named.
145
+ */
146
+ export declare const CORE_SITE_ROLE_PRESETS: Readonly<Record<string, Readonly<Record<string, boolean>>>>;
119
147
  /**
120
148
  * The core keys each org role holds when nothing refines it: owners and
121
149
  * admins hold every core key (owner-only acts like deleting the
@@ -105,6 +105,44 @@ export const ORG_ROLE_NAMES = [
105
105
  label: 'Activity & audit log',
106
106
  description: 'See the organization activity feed.'
107
107
  },
108
+ {
109
+ key: 'org.apiKeys',
110
+ group: 'organization',
111
+ label: 'Manage API keys',
112
+ description: 'Create and revoke the workspace’s REST API keys.'
113
+ },
114
+ {
115
+ key: 'org.privacy',
116
+ group: 'organization',
117
+ label: 'Privacy requests',
118
+ description: 'Erase a person from every site in the workspace when they ask.'
119
+ },
120
+ {
121
+ key: 'org.holds',
122
+ group: 'organization',
123
+ label: 'Holds and reviews',
124
+ description: 'See what is held, flagged or locked on the workspace, and request a review.'
125
+ },
126
+ // Workspace acts that asked for the owner or admin role (AGL-4047), each
127
+ // a key of its own whose default is exactly those roles.
128
+ {
129
+ key: 'org.export',
130
+ group: 'organization',
131
+ label: 'Export workspace data',
132
+ description: 'Download a copy of everything the workspace holds.'
133
+ },
134
+ {
135
+ key: 'org.sendingDomains',
136
+ group: 'organization',
137
+ label: 'Sending domains',
138
+ description: 'Add, verify and remove the domains the workspace’s mail is sent from.'
139
+ },
140
+ {
141
+ key: 'org.businessProfile',
142
+ group: 'organization',
143
+ label: 'Business profile',
144
+ description: 'Change the services, audience and tone every site starts from.'
145
+ },
108
146
  {
109
147
  key: 'billing.view',
110
148
  group: 'billing',
@@ -135,12 +173,56 @@ export const ORG_ROLE_NAMES = [
135
173
  label: 'Delete sites',
136
174
  description: 'Delete sites the member can access.'
137
175
  },
176
+ // The site keys (AGL-4047): each replaced a gate on the member's role on a
177
+ // site, and keeps that role as its preset (`CORE_SITE_ROLE_PRESETS`).
178
+ {
179
+ key: 'site.edit',
180
+ group: 'sites',
181
+ scope: 'site',
182
+ label: 'Edit site content',
183
+ description: 'Create and change pages, content and everything else on a site, without making it live.'
184
+ },
185
+ {
186
+ key: 'site.publish',
187
+ group: 'sites',
188
+ scope: 'site',
189
+ label: 'Publish site content',
190
+ description: 'Make pages and content live, take them down or schedule them, change redirects and change the site’s fonts.'
191
+ },
192
+ {
193
+ key: 'site.sensitive',
194
+ group: 'sites',
195
+ scope: 'site',
196
+ label: 'See orders and webhooks',
197
+ description: 'Read a site’s orders, returns and sending address, and set up its webhooks.'
198
+ },
199
+ {
200
+ key: 'site.manage',
201
+ group: 'sites',
202
+ scope: 'site',
203
+ label: 'Manage site settings',
204
+ 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.'
205
+ },
138
206
  {
139
207
  key: 'data.manage',
140
208
  group: 'datasets',
141
209
  label: 'Manage data',
142
210
  description: 'Create, edit, and delete organization datasets.'
143
211
  },
212
+ // Workspace content that asked for the owner, admin or editor role
213
+ // (AGL-4047), each a key whose default is exactly those roles.
214
+ {
215
+ key: 'org.media',
216
+ group: 'datasets',
217
+ label: 'Edit the workspace media library',
218
+ description: 'Upload, change, move and remove the files in the media library every site shares.'
219
+ },
220
+ {
221
+ key: 'org.eraseRecords',
222
+ group: 'datasets',
223
+ label: 'Delete workspace records',
224
+ description: 'Delete records the whole workspace shares, such as dataset rows, contacts and lists.'
225
+ },
144
226
  {
145
227
  key: 'marketplace.publish',
146
228
  group: 'extensions',
@@ -155,6 +237,42 @@ export const ORG_ROLE_NAMES = [
155
237
  }
156
238
  ];
157
239
  const CORE_KEYS = CORE_ORG_PERMISSION_ENTRIES.map((entry)=>entry.key);
240
+ /**
241
+ * The core keys whose preset is the member's role ON THE SITE (AGL-4047), and
242
+ * each site role's verdict: the sets the rules' `canWriteHostContent`,
243
+ * `canPublishHostContent`, `canReadHostSensitive` and the site-admin checks
244
+ * asked before they asked these keys. A member's preset on a site is the
245
+ * verdict for the role they hold there (the owner and admins are Admin on
246
+ * every site); a custom role, their own permissions and that site's toggle
247
+ * then grant or refuse it. Each workspace role's default below is the verdict
248
+ * for its own site role, which is the answer with no site named.
249
+ */ export const CORE_SITE_ROLE_PRESETS = {
250
+ 'site.edit': {
251
+ admin: true,
252
+ editor: true,
253
+ author: true,
254
+ viewer: false
255
+ },
256
+ 'site.publish': {
257
+ admin: true,
258
+ editor: true,
259
+ author: false,
260
+ viewer: false
261
+ },
262
+ 'site.sensitive': {
263
+ admin: true,
264
+ editor: true,
265
+ author: false,
266
+ viewer: false
267
+ },
268
+ 'site.manage': {
269
+ admin: true,
270
+ editor: false,
271
+ author: false,
272
+ viewer: false
273
+ }
274
+ };
275
+ /** The workspace editor's site keys: its own site role's preset. */ const EDITOR_SITE_KEYS = Object.keys(CORE_SITE_ROLE_PRESETS).filter((key)=>CORE_SITE_ROLE_PRESETS[key].editor);
158
276
  /**
159
277
  * The core keys each org role holds when nothing refines it: owners and
160
278
  * admins hold every core key (owner-only acts like deleting the
@@ -165,8 +283,11 @@ const CORE_KEYS = CORE_ORG_PERMISSION_ENTRIES.map((entry)=>entry.key);
165
283
  admin: CORE_KEYS,
166
284
  editor: [
167
285
  'data.manage',
286
+ 'org.media',
287
+ 'org.eraseRecords',
168
288
  'marketplace.publish',
169
- 'plugins.install'
289
+ 'plugins.install',
290
+ ...EDITOR_SITE_KEYS
170
291
  ],
171
292
  viewer: []
172
293
  };
@@ -227,7 +348,11 @@ const CORE_KEYS = CORE_ORG_PERMISSION_ENTRIES.map((entry)=>entry.key);
227
348
  group
228
349
  } : {}, {
229
350
  scope: declaration.hostRoleDefaults ? 'site' : 'org'
230
- }));
351
+ }, declaration.refines && declaration.refines !== declaration.key ? {
352
+ refines: declaration.refines
353
+ } : {}, declaration.follows && declaration.follows !== declaration.key && !declaration.refines ? {
354
+ follows: declaration.follows
355
+ } : {}));
231
356
  if (group && !groupIds.has(group)) {
232
357
  var _declaration_groupLabel;
233
358
  groupIds.add(group);
@@ -237,6 +362,14 @@ const CORE_KEYS = CORE_ORG_PERMISSION_ENTRIES.map((entry)=>entry.key);
237
362
  }, declaration.pluginId ? {
238
363
  pluginId: declaration.pluginId
239
364
  } : {}));
365
+ } else if (group && declaration.pluginId) {
366
+ // A plugin's group opened by a declaration that names no plugin (an org
367
+ // catalog declaration, AGL-4047) is still that plugin's: the first of
368
+ // its declarations that names one says so.
369
+ const index = groups.findIndex((entry)=>entry.id === group);
370
+ if (index >= 0 && !groups[index].pluginId) groups[index] = _extends({}, groups[index], {
371
+ pluginId: declaration.pluginId
372
+ });
240
373
  }
241
374
  const defaults = declarationRoleDefaults(declaration);
242
375
  for (const role of ORG_ROLE_NAMES){
@@ -274,6 +407,51 @@ const CORE_KEYS = CORE_ORG_PERMISSION_ENTRIES.map((entry)=>entry.key);
274
407
  if (typeof values[key] === 'boolean') out[key] = values[key];
275
408
  }
276
409
  }
410
+ // A key that refines a broader one (AGL-4047) is never held without it, and
411
+ // follows it where neither layer set the key; a key that only follows one
412
+ // takes its verdict where neither layer set the key, and nothing more.
413
+ // Applied broader keys first, so a chain settles in one pass; a refinement
414
+ // that loops is left alone.
415
+ const broader = new Map();
416
+ const followsOnly = new Set();
417
+ for (const entry of catalog.permissions){
418
+ if (entry.refines && entry.refines in out) broader.set(entry.key, entry.refines);
419
+ else if (entry.follows && entry.follows in out) {
420
+ broader.set(entry.key, entry.follows);
421
+ followsOnly.add(entry.key);
422
+ }
423
+ }
424
+ const depth = (key)=>{
425
+ const seen = new Set();
426
+ let steps = 0;
427
+ let current = key;
428
+ while(broader.has(current)){
429
+ if (seen.has(current)) return -1;
430
+ seen.add(current);
431
+ current = broader.get(current);
432
+ steps += 1;
433
+ }
434
+ return steps;
435
+ };
436
+ const ordered = [
437
+ ...broader.keys()
438
+ ].map((key)=>({
439
+ key,
440
+ steps: depth(key)
441
+ })).filter((entry)=>entry.steps > 0).sort((a, b)=>a.steps - b.steps);
442
+ for (const { key } of ordered){
443
+ let stored;
444
+ for (const layer of [
445
+ customRole,
446
+ overrides
447
+ ]){
448
+ var _layer_permissions;
449
+ const value = layer == null ? void 0 : (_layer_permissions = layer.permissions) == null ? void 0 : _layer_permissions[key];
450
+ if (typeof value === 'boolean') stored = value;
451
+ }
452
+ const held = out[broader.get(key)] === true;
453
+ out[key] = followsOnly.has(key) ? stored === undefined ? held : stored : held && (stored === undefined ? true : stored);
454
+ }
277
455
  return out;
278
456
  }
279
457
 
@@ -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\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}\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: '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 {\n key: 'data.manage',\n group: 'datasets',\n label: 'Manage data',\n description: 'Create, edit, and delete organization datasets.',\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 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', 'marketplace.publish', 'plugins.install'],\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 })\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 }\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 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","CORE_KEYS","map","entry","CORE_ORG_ROLE_GRANTS","ORG_ROLE_GRANTS","permissions","groups","grants","assembleOrgRoleGrants","core","declarationLists","Object","fromEntries","role","taken","Set","groupIds","flat","has","add","pluginId","push","scope","hostRoleDefaults","groupLabel","rolePermissions","catalog","customRole","overrides","keys","name","held","out","layer","values"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;CAkBC,GAED,wBAAwB;AAoExB,OAAO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D,OAAO,SAASmB,gBACdC,OAAsB,EACtBb,IAA+B,EAC/Bc,UAAsC,EACtCC,SAAqC;QAIhB;IAFrB,MAAMC,OAAOH,QAAQrB,WAAW,CAACJ,GAAG,CAAC,CAACC,QAAUA,MAAML,GAAG;IACzD,MAAMiC,OAAOjB,eAAAA,OAAQ;IACrB,MAAMkB,OAAO,IAAIhB,KAAI,uBAAA,AAACW,QAAQnB,MAAM,AAAyC,CAACuB,KAAK,YAA9D,uBAAkE,EAAE;IACzF,MAAME,MAA+BrB,OAAOC,WAAW,CAACiB,KAAK5B,GAAG,CAAC,CAACJ,MAAQ;YAACA;YAAKkC,KAAKb,GAAG,CAACrB;SAAK;IAC9F,KAAK,MAAMoC,SAAS;QAACN;QAAYC;KAAU,CAAE;QAC3C,MAAMM,SAASD,yBAAAA,MAAO5B,WAAW;QACjC,IAAI,CAAC6B,QAAQ;QACb,KAAK,MAAMrC,OAAOgC,KAAM;YACtB,IAAI,OAAOK,MAAM,CAACrC,IAAI,KAAK,WAAWmC,GAAG,CAACnC,IAAI,GAAGqC,MAAM,CAACrC,IAAI;QAC9D;IACF;IACA,OAAOmC;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\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.',\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 })\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","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;AAqFxB,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,MAAO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,CAAClD;QACb,MAAMmD,OAAO,IAAI3B;QACjB,IAAI4B,QAAQ;QACZ,IAAIC,UAAUrD;QACd,MAAO8C,QAAQnB,GAAG,CAAC0B,SAAU;YAC3B,IAAIF,KAAKxB,GAAG,CAAC0B,UAAU,OAAO,CAAC;YAC/BF,KAAKvB,GAAG,CAACyB;YACTA,UAAUP,QAAQQ,GAAG,CAACD;YACtBD,SAAS;QACX;QACA,OAAOA;IACT;IACA,MAAMG,UAAU;WAAIT,QAAQnC,IAAI;KAAG,CAChCN,GAAG,CAAC,CAACL,MAAS,CAAA;YAAEA;YAAKoD,OAAOF,MAAMlD;QAAK,CAAA,GACvCY,MAAM,CAAC,CAACN,QAAUA,MAAM8C,KAAK,GAAG,GAChCI,IAAI,CAAC,CAACC,GAAGC,IAAMD,EAAEL,KAAK,GAAGM,EAAEN,KAAK;IACnC,KAAK,MAAM,EAAEpD,GAAG,EAAE,IAAIuD,QAAS;QAC7B,IAAII;QACJ,KAAK,MAAMf,SAAS;YAACL;YAAYC;SAAU,CAAE;gBAC7BI;YAAd,MAAMgB,QAAQhB,0BAAAA,qBAAAA,MAAO7B,WAAW,qBAAlB6B,kBAAoB,CAAC5C,IAAI;YACvC,IAAI,OAAO4D,UAAU,WAAWD,SAASC;QAC3C;QACA,MAAMlB,OAAOC,GAAG,CAACG,QAAQQ,GAAG,CAACtD,KAAe,KAAK;QACjD2C,GAAG,CAAC3C,IAAI,GAAGgD,YAAYrB,GAAG,CAAC3B,OAAQ2D,WAAWE,YAAYnB,OAAOiB,SAAUjB,QAASiB,CAAAA,WAAWE,YAAY,OAAOF,MAAK;IACzH;IACA,OAAOhB;AACT"}
@@ -14,7 +14,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
14
14
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
- */ import { listPluginPermissionKeys, pluginPermissionDefaults } from "../plugin-manager/plugin-permissions.js";
17
+ */ import { listPluginPermissionKeys, pluginPermissionDefaults, pluginPermissionRefinements, refinePermissionMap } from "../plugin-manager/plugin-permissions.js";
18
18
  /**
19
19
  * Org roles (AGL-120): named permission sets assigned to team members,
20
20
  * with per-user overrides an admin can apply on top. Shared between the
@@ -101,9 +101,13 @@ export const ORG_ROLE_TIER_LABELS = {
101
101
  ...ORG_ROLE_PERMISSION_KEYS,
102
102
  ...listPluginPermissionKeys()
103
103
  ];
104
+ // The custom role's map, when one decides the base: a stored layer for the
105
+ // refinement pass below.
106
+ let customLayer;
104
107
  if (!builtIn) {
105
108
  const custom = customRoles == null ? void 0 : customRoles[role != null ? role : ''];
106
109
  if (custom) {
110
+ customLayer = custom.permissions;
107
111
  // Plugin tier defaults are re-laid under the viewer base (AGL-2474).
108
112
  // Rebuilding from `ORG_ROLE_TIER_PERMISSIONS.viewer` alone dropped every
109
113
  // plugin key off a custom-role member's map entirely — `managePos` came
@@ -122,7 +126,12 @@ export const ORG_ROLE_TIER_LABELS = {
122
126
  const value = overrides == null ? void 0 : overrides[key];
123
127
  if (typeof value === 'boolean') permissions[key] = value;
124
128
  }
125
- return permissions;
129
+ // A key that refines a broader one (AGL-4047) follows it where nothing
130
+ // set the key, and is never held without it.
131
+ return refinePermissionMap(permissions, pluginPermissionRefinements(), [
132
+ customLayer,
133
+ overrides
134
+ ]);
126
135
  }
127
136
  /** True for the fixed admin/editor/viewer ids. */ export function isBuiltInRole(role) {
128
137
  return (role != null ? role : '') in ORG_ROLE_TIER_PERMISSIONS;