@aglyn/aglyn 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/lib/app-utils/crm.js +8 -7
- package/src/lib/app-utils/crm.js.map +1 -1
- package/src/lib/app-utils/docs-help-sections.generated.js +8 -2
- package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
- package/src/lib/app-utils/docs-help.generated.d.ts +1 -1
- package/src/lib/app-utils/docs-help.generated.js +7 -0
- package/src/lib/app-utils/docs-help.generated.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +48 -34
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/dynamic-list-rule.js +9 -5
- package/src/lib/app-utils/dynamic-list-rule.js.map +1 -1
- package/src/lib/app-utils/host-permissions.d.ts +12 -0
- package/src/lib/app-utils/host-permissions.js +26 -1
- package/src/lib/app-utils/host-permissions.js.map +1 -1
- package/src/lib/app-utils/media-asset-facts.d.ts +2 -2
- package/src/lib/app-utils/media-asset-facts.js +4 -3
- package/src/lib/app-utils/media-asset-facts.js.map +1 -1
- package/src/lib/app-utils/media-cdn-scope.d.ts +19 -4
- package/src/lib/app-utils/media-cdn-scope.js +19 -5
- package/src/lib/app-utils/media-cdn-scope.js.map +1 -1
- package/src/lib/app-utils/media-ref.d.ts +10 -6
- package/src/lib/app-utils/media-ref.js +34 -8
- package/src/lib/app-utils/media-ref.js.map +1 -1
- package/src/lib/app-utils/native-nav.d.ts +2 -2
- package/src/lib/app-utils/native-nav.js +2 -2
- package/src/lib/app-utils/native-nav.js.map +1 -1
- package/src/lib/app-utils/org-permissions.d.ts +7 -0
- package/src/lib/app-utils/org-permissions.js +2 -0
- package/src/lib/app-utils/org-permissions.js.map +1 -1
- package/src/lib/app-utils/org-role-grants.d.ts +7 -0
- package/src/lib/app-utils/org-role-grants.js +7 -5
- package/src/lib/app-utils/org-role-grants.js.map +1 -1
- package/src/lib/app-utils/scope-tokens.d.ts +132 -3
- package/src/lib/app-utils/scope-tokens.js +276 -3
- package/src/lib/app-utils/scope-tokens.js.map +1 -1
- package/src/lib/app-utils/site-placement.d.ts +74 -0
- package/src/lib/app-utils/site-placement.js +80 -0
- package/src/lib/app-utils/site-placement.js.map +1 -0
- package/src/lib/app-utils/transfer-launcher-context.d.ts +17 -1
- package/src/lib/app-utils/transfer-launcher-context.js.map +1 -1
- package/src/lib/data-transfer/access.d.ts +10 -18
- package/src/lib/data-transfer/access.js +21 -25
- package/src/lib/data-transfer/access.js.map +1 -1
- package/src/lib/data-transfer/resource.d.ts +13 -14
- package/src/lib/data-transfer/resource.js +9 -10
- package/src/lib/data-transfer/resource.js.map +1 -1
- package/src/lib/plugin-manager/first-party-plugins.generated.js +3 -4
- package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
- package/src/lib/plugin-manager/plugin-contact-capture.d.ts +10 -0
- package/src/lib/plugin-manager/plugin-contact-capture.js +11 -0
- package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
- package/src/lib/plugin-manager/plugin-entitlements.d.ts +12 -0
- package/src/lib/plugin-manager/plugin-entitlements.js +3 -1
- package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
- package/src/lib/plugin-manager/plugin-scope-sharing.d.ts +52 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.generated.d.ts +10 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.generated.js +82 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.generated.js.map +1 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.js +85 -0
- package/src/lib/plugin-manager/plugin-scope-sharing.js.map +1 -0
- package/src/lib/plugin-manager/plugin-transfer-resources.d.ts +56 -1
- package/src/lib/plugin-manager/plugin-transfer-resources.js +13 -0
- package/src/lib/plugin-manager/plugin-transfer-resources.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/scope-tokens.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 * Scoped sharing (AGL-1037): org-owned resources — datasets, media assets,\n * media folders — carry a `visibleTo` array naming who may see them, so an\n * agency can keep an internal dataset off its client sites without forking\n * storage into a second host-scoped collection (see AGL-237, which moved\n * these the other way).\n *\n * The shape is dictated by what both enforcement layers can evaluate:\n * Firestore rules have no `.map()`, so the caller's read set is denormalized\n * onto their member doc (AGL-1038) and matched with `list.hasAny(list)`;\n * clients match the same field with `array-contains-any`. A flat array of\n * strings is the only shape both primitives accept — the friendlier\n * `{ kind, hostIds }` form is a presentation concern and lives in\n * `describeScope` below, never on the doc.\n */\n\nimport type { ScopeToken } from '../foundation'\n\n// The type itself lives in foundation (app-utils imports foundation, never\n// the reverse) so the media doc interfaces can reference it; re-exported\n// here so callers get the type and its helpers from one place.\nexport type { ScopeToken }\n\n/** Everyone in the owning org, and every host it owns. */\nexport const ORG_SCOPE_TOKEN = 'org' as const satisfies ScopeToken\n\nconst HOST_TOKEN_PREFIX = 'host:'\n\n/**\n * `array-contains-any` and `hasAny` both cap at 30 values. That caps a\n * selected-sites scope at 30 hosts, and a collaborator's read query at 29\n * hosts plus `'org'`. Wider than that is the `['org']` case.\n */\nexport const MAX_SCOPE_HOSTS = 30\n\n/** `host:{hostId}` — the token naming a single site. */\nexport function hostScopeToken(hostId: string): ScopeToken {\n return `${HOST_TOKEN_PREFIX}${hostId}`\n}\n\nexport function isScopeToken(value: unknown): value is ScopeToken {\n if (typeof value !== 'string') return false\n if (value === ORG_SCOPE_TOKEN) return true\n return (\n value.startsWith(HOST_TOKEN_PREFIX) &&\n value.length > HOST_TOKEN_PREFIX.length\n )\n}\n\n/** Reads a token back apart; null when it isn't one. */\nexport function parseScopeToken(\n token: string\n): { kind: 'org' } | { kind: 'host'; hostId: string } | null {\n if (token === ORG_SCOPE_TOKEN) return { kind: 'org' }\n if (!isScopeToken(token)) return null\n return { kind: 'host', hostId: token.slice(HOST_TOKEN_PREFIX.length) }\n}\n\n/** Every host id named by a scope, in order; `['org']` names none. */\nexport function hostIdsFromScope(\n visibleTo: readonly string[] | undefined\n): string[] {\n const ids: string[] = []\n for (const token of visibleTo ?? []) {\n const parsed = parseScopeToken(token)\n if (parsed?.kind === 'host') ids.push(parsed.hostId)\n }\n return ids\n}\n\n/**\n * The read set for one site: what a server read path or a scoped client\n * query passes to `array-contains-any`. `'org'` is included because an\n * org-wide resource is visible to every host in the org.\n */\nexport function scopeTokensForHost(hostId: string): ScopeToken[] {\n return [ORG_SCOPE_TOKEN, hostScopeToken(hostId)]\n}\n\n/**\n * Whether a host may see a resource.\n *\n * ## A missing `visibleTo` is visible to NOBODY\n *\n * It once read as org-wide, so that documents predating the scope backfill\n * stayed visible until it reached them. That default is the shape of failure\n * this codebase keeps paying for: **a read that cannot see a value answered\n * the same as a value that is absent.** \"This document was never scoped\" and\n * \"this document is shared with every site\" are different facts, and one\n * unscoped document under an agency account was one client's data on every\n * other client's site — silently, because the permissive answer is the one\n * nothing complains about.\n *\n * Both enforcement layers below this function already fail CLOSED on the\n * missing field: `array-contains-any` matches nothing on a document that\n * lacks the array, and the rules' `hasAny` is false for the same reason. So\n * the permissive default was never a policy either of them agreed with — it\n * was one TypeScript helper disagreeing with the database, which is what made\n * AGL-1466 invisible for three weeks.\n *\n * The migration is `tools/scripts/backfill-consent-host.mjs`, which stamps\n * `['org']` on the documents that should carry it. Until a document is\n * stamped it is hidden, and hiding is the recoverable direction.\n *\n * An **empty array** answers the same and always did.\n */\nexport function visibleToHost(\n visibleTo: readonly string[] | undefined | null,\n hostId: string\n): boolean {\n if (visibleTo == null) return false\n if (visibleTo.includes(ORG_SCOPE_TOKEN)) return true\n return visibleTo.includes(hostScopeToken(hostId))\n}\n\n/**\n * Whether a caller holding `scopeTokens` (AGL-1038) may see a resource.\n * The TypeScript twin of the rules' `visibleTo.hasAny(scopeTokens)`, for\n * the Admin-SDK paths that never evaluate rules at all.\n *\n * A missing `visibleTo` is visible to nobody, for the reason\n * {@link visibleToHost} gives — and here the twinning is the argument on its\n * own: `hasAny` over a missing field is false in the rules, so a helper that\n * answered `true` was not a twin of anything.\n */\nexport function visibleToTokens(\n visibleTo: readonly string[] | undefined | null,\n scopeTokens: readonly string[] | undefined | null\n): boolean {\n if (visibleTo == null) return false\n if (!scopeTokens?.length) return false\n return visibleTo.some((token) => scopeTokens.includes(token))\n}\n\n/**\n * The scope a document ACTUALLY carries — `null` when it carries none\n * (AGL-1466/AGL-1480).\n *\n * Every helper above this line answers \"may this be seen\", and answers it\n * the way both enforcement layers do: a missing `visibleTo` is seen by\n * nobody.\n *\n * An **editor** asks a different question — \"what did somebody choose\" —\n * and it still needs its own answer, because \"nobody chose\" and \"somebody\n * chose nobody\" are the same to an editor and different on the document.\n * Four call sites across two files each wrote their own\n *\n * ```ts\n * Array.isArray(doc.visibleTo) ? doc.visibleTo : [ORG_SCOPE_TOKEN]\n * ```\n *\n * and every one of them rendered \"All sites\" over a document no site could\n * see. That inversion is why AGL-1466 went three weeks unnoticed with the\n * folder tree missing from every host, and AGL-1480 is the third and fourth\n * copies of it turning up at the surface people use most.\n *\n * So: one function, the same lesson `newMediaFolderDoc` drew on the write\n * side. A caller that wants a display default may still `?? []` or\n * `?? [ORG_SCOPE_TOKEN]` — but it has to say so, in one visible place,\n * instead of a ternary that reads like a null check.\n *\n * An empty array answers `null` too. On the document the two differ, and\n * `newResourceScopeFields` refuses to WRITE one; to an editor they are the\n * same fact — nobody chose this — and both must offer the choice rather\n * than pre-fill an answer.\n *\n * Not normalized, deliberately. `normalizeVisibleTo` collapses for STORAGE;\n * doing it here would make an untouched editor differ from the document it\n * was seeded from, and the save gates compare exactly those two to decide\n * whether to write at all.\n */\nexport function storedScope(\n visibleTo: readonly string[] | undefined | null\n): string[] | null {\n return Array.isArray(visibleTo) && visibleTo.length ? [...visibleTo] : null\n}\n\n/**\n * Cleans a scope for storage: drops junk, dedupes, and collapses to\n * `['org']` when org-wide is present, since that already implies every\n * host. Returns null when the result is unusable — empty, or over\n * `MAX_SCOPE_HOSTS` — so the caller decides rather than this silently\n * dropping hosts (losing access) or widening to org (leaking).\n */\nexport function normalizeVisibleTo(\n input: readonly string[] | undefined | null\n): ScopeToken[] | null {\n const tokens = (input ?? []).filter(isScopeToken)\n if (!tokens.length) return null\n if (tokens.includes(ORG_SCOPE_TOKEN)) return [ORG_SCOPE_TOKEN]\n const unique = [...new Set(tokens)]\n if (unique.length > MAX_SCOPE_HOSTS) return null\n return unique\n}\n\n/**\n * The scope a save writes, or why the selection cannot be written.\n *\n * {@link normalizeVisibleTo} answers null for a selection it cannot store, and\n * a save has no safe substitute for that null: the org token shares the\n * resource with every site, and dropping tokens takes access from sites\n * somebody picked. So a caller refuses the save and shows `problem`.\n */\nexport function scopeToStore(\n input: readonly string[] | undefined | null\n): { scope: ScopeToken[]; problem: null } | { scope: null; problem: string } {\n const scope = normalizeVisibleTo(input)\n if (scope) return { scope, problem: null }\n return {\n scope: null,\n problem: (input ?? []).some(isScopeToken)\n ? `Choose ${MAX_SCOPE_HOSTS} sites or fewer, or share with All sites.`\n : 'Choose at least one site, or share with All sites.',\n }\n}\n\n/** A scope covering exactly the given hosts; null when unusable. */\nexport function scopeForHosts(\n hostIds: readonly string[]\n): ScopeToken[] | null {\n return normalizeVisibleTo(hostIds.map(hostScopeToken))\n}\n\n/**\n * Whether a scope is the org-wide one.\n *\n * An absent scope is NOT org-wide — see {@link visibleToHost}. That is the\n * whole correction: this predicate is what `describeScope` renders and what\n * `scopeCovers` and `narrowsScope` reason from, and while it answered `true`\n * for a document nothing could see, the console said \"All sites\" over it.\n */\nexport function isOrgWideScope(\n visibleTo: readonly string[] | undefined | null\n): boolean {\n return visibleTo != null && visibleTo.includes(ORG_SCOPE_TOKEN)\n}\n\n/**\n * Whether moving from `before` to `after` takes visibility away from any\n * host — the direction that can break a published page, and the one the\n * console confirms before saving (AGL-1044/AGL-1045).\n */\nexport function narrowsScope(\n before: readonly string[] | undefined | null,\n after: readonly string[] | undefined | null\n): boolean {\n if (isOrgWideScope(before)) return !isOrgWideScope(after)\n if (isOrgWideScope(after)) return false\n const kept = new Set(after ?? [])\n return (before ?? []).some((token) => !kept.has(token))\n}\n\n/**\n * The sentence the console shows. `hostNames` maps host id → display name;\n * ids missing from it fall back to the count wording, since a name we\n * can't resolve is worse than no name.\n */\nexport function describeScope(\n visibleTo: readonly string[] | undefined | null,\n hostNames: Readonly<Record<string, string>> = {}\n): string {\n if (isOrgWideScope(visibleTo)) return 'All sites'\n const hostIds = hostIdsFromScope(visibleTo ?? [])\n if (!hostIds.length) return 'No sites'\n if (hostIds.length === 1) {\n const name = hostNames[hostIds[0]]\n return name ? `${name} only` : '1 site'\n }\n return `${hostIds.length} sites`\n}\n\n/**\n * The scope a newly created resource starts with (AGL-1048).\n *\n * Honours the org's default — `defaultResourceScope` for a dataset,\n * `defaultMediaScopeOf(org)` for media, passed in the same option — but\n * only when a site is\n * actually in context: created from the org Media or Data page there is no\n * host to scope to, and inventing one would hide the resource from the\n * page that just created it.\n */\nexport function defaultScopeForNewResource(options: {\n defaultResourceScope?: 'org' | 'host'\n hostId?: string | null\n}): ScopeToken[] {\n return options.defaultResourceScope === 'host' && options.hostId\n ? [hostScopeToken(options.hostId)]\n : [ORG_SCOPE_TOKEN]\n}\n\n/**\n * The org's default sharing for new MEDIA — uploads and folders (AGL-3662).\n *\n * `defaultMediaScope` when the org has set it, otherwise\n * `defaultResourceScope`: until the two were split one field decided both,\n * so an org that chose \"only the site they were created in\" before the split\n * keeps that choice for media until it sets media on its own. Datasets read\n * `defaultResourceScope` directly.\n */\nexport function defaultMediaScopeOf(\n org:\n | {\n defaultMediaScope?: 'org' | 'host'\n defaultResourceScope?: 'org' | 'host'\n }\n | null\n | undefined,\n): 'org' | 'host' | undefined {\n return org?.defaultMediaScope ?? org?.defaultResourceScope\n}\n\n/**\n * The scope fields a document being CREATED in a scoped collection carries\n * (AGL-1478), as a spreadable object.\n *\n * The argument is REQUIRED and has no default, which is the whole point.\n * AGL-1466 was two call sites that each built a `mediaFolders` document\n * inline and each forgot `visibleTo`; `newMediaFolderDoc` fixed that one\n * collection by making the input mandatory, and this is the same guarantee\n * for the collections that have no document constructor of their own —\n * `datasets`, `media`, `contacts`, `contactSegments`. A creator that has\n * not decided cannot compile.\n *\n * Three inputs, three meanings:\n *\n * - **tokens** — stamp them.\n * - **`null`** — this collection is NOT scoped (a `hosts/{hostId}`\n * subcollection is private by construction), so store nothing. Saying it\n * out loud is what distinguishes \"not applicable\" from \"forgotten\".\n * - **`[]`** — throws. Unlike a missing field, a stored empty array is a\n * written \"visible to nobody\": the backfill leaves it alone by design and\n * no read path treats it as legacy, so it is permanent where absent is\n * repairable. Getting here means a caller computed a scope and came back\n * with nothing, which is worth a stack trace.\n */\nexport function newResourceScopeFields(\n visibleTo: readonly ScopeToken[] | null\n): { visibleTo?: ScopeToken[] } {\n if (visibleTo && !visibleTo.length) {\n throw new Error('A scoped resource cannot be created with an empty scope')\n }\n return visibleTo ? { visibleTo: [...visibleTo] } : {}\n}\n\n/**\n * Whether `target` is visible everywhere `source` is — the condition a\n * cross-dataset REFERENCE has to satisfy (AGL-1044).\n *\n * A reference field on dataset A pointing at dataset B is only resolvable\n * on the sites that can see BOTH. If A is shared with a site that cannot\n * see B, a page there resolves the reference to nothing: the row renders\n * with a blank where the linked value should be, and nothing says why. So\n * B's scope must COVER A's.\n *\n * Org-wide covers everything. A missing scope is seen by nobody and\n * therefore covers nothing, matching the rest of this module.\n */\nexport function scopeCovers(\n target: readonly string[] | undefined | null,\n source: readonly string[] | undefined | null,\n): boolean {\n if (isOrgWideScope(target)) return true\n // The target is restricted; an org-wide source reaches sites it cannot.\n if (isOrgWideScope(source)) return false\n const reach = new Set(target ?? [])\n return (source ?? []).every((token) => reach.has(token))\n}\n\n/**\n * Rewrites an org media CDN path so it names the site using the asset\n * (AGL-1043/1045).\n *\n * `/api/media/cdn/org:{orgId}/{mediaId}` serves ORG-WIDE assets only. A\n * restricted asset has to be requested through the form that names the\n * site — `org:{orgId}:{hostId}` — because the CDN is unauthenticated and\n * the URL is the only thing it can decide from.\n *\n * Returns the path untouched when there is nothing to do: an org-wide\n * asset, a host-library asset, no host context, or a path that is not an\n * org CDN URL. That keeps it safe to apply blindly at every pick site.\n */\nexport function hostQualifiedCdnPath(\n cdnPath: string | undefined | null,\n visibleTo: readonly string[] | undefined | null,\n hostId: string | undefined | null,\n): string | undefined {\n if (!cdnPath) return cdnPath ?? undefined\n if (!hostId || isOrgWideScope(visibleTo)) return cdnPath\n // `/api/media/cdn/{scope}/{mediaId}[/{hash}]`\n const marker = '/api/media/cdn/'\n const at = cdnPath.indexOf(marker)\n if (at === -1) return cdnPath\n const head = cdnPath.slice(0, at + marker.length)\n const rest = cdnPath.slice(at + marker.length)\n const [scopeSegment, ...tail] = rest.split('/')\n // Only the bare `org:{orgId}` form is rewritten; an already-qualified\n // scope is left alone rather than gaining a second host.\n if (!scopeSegment.startsWith('org:') || scopeSegment.includes(':', 4)) {\n return cdnPath\n }\n return [`${head}${scopeSegment}:${hostId}`, ...tail].join('/')\n}\n\n/*==========================================\n * SEEN, AND HELD (AGL-3336).\n *\n * `visibleTo` answers one question, \"who may see this\", because it is the\n * one field both enforcement layers can evaluate. A visibility GRANT — an\n * org manager sharing a record with another site, by hand or by a rule —\n * has to widen exactly that field, or the other site's lists, which are\n * real `array-contains-any` queries, could never return the record.\n *\n * But a site a record was shared with does not HOLD it. It did not capture\n * the person, it holds no consent from them, and letting go of the record\n * is not its decision. So a document that carries a grant records which of\n * its tokens the grant added, under `sharing.added`, and every question\n * about holding — who may delete it, whose audience it joins, which site's\n * list it enters — reads {@link heldScopeTokens} instead of `visibleTo`.\n *\n * A document without the field is held by everything that sees it, which\n * is every document written before grants existed.\n *=========================================*/\n\n/** The map a scoped document records its visibility grants under. */\nexport const SCOPE_GRANTS_FIELD = 'sharing'\n\n/** The tokens a grant ADDED to `visibleTo`: seen through, never held. */\nexport function grantedScopeTokens(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n): string[] {\n const grants = (doc ?? {})[SCOPE_GRANTS_FIELD]\n if (!grants || typeof grants !== 'object' || Array.isArray(grants)) return []\n const added = (grants as Record<string, unknown>)['added']\n return Array.isArray(added)\n ? added.filter((token): token is string => typeof token === 'string')\n : []\n}\n\n/**\n * The tokens that HOLD a document: `visibleTo` without the ones a grant\n * added. Missing `visibleTo` is held by nobody, as it is seen by nobody.\n *\n * A site that created the document (`hostId`) or captured the person on it\n * (`capturedByHostIds`) holds its token whatever the grants say: a record\n * shared with a site that then captures the person itself is that site's\n * own from the capture on, before anything re-evaluates the grants.\n */\nexport function heldScopeTokens(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n): string[] {\n const visibleTo = (doc ?? {})['visibleTo']\n if (!Array.isArray(visibleTo)) return []\n const granted = new Set(grantedScopeTokens(doc))\n const capturing = new Set<string>()\n const hostId = (doc ?? {})['hostId']\n if (typeof hostId === 'string' && hostId) capturing.add(hostScopeToken(hostId))\n const captured = (doc ?? {})['capturedByHostIds']\n if (Array.isArray(captured)) {\n for (const id of captured) if (typeof id === 'string' && id) capturing.add(hostScopeToken(id))\n }\n return visibleTo.filter(\n (token): token is string =>\n typeof token === 'string' && (!granted.has(token) || capturing.has(token)),\n )\n}\n\n/**\n * Whether a site HOLDS a document rather than only seeing it through a\n * grant. The question a marketing audience, a list rule, a sequence and a\n * holder count ask; {@link visibleToHost} is the one a reader asks.\n */\nexport function heldByHost(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n hostId: string,\n): boolean {\n return visibleToHost(heldScopeTokens(doc), hostId)\n}\n\n/**\n * Whether a site sees a document ONLY through a grant: it carries grants and\n * the site does not hold it. The filter an audience sweep applies to what\n * its scoped query returned — a document with no grants answers `false`, so\n * every read that predates sharing keeps exactly the rows it had.\n */\nexport function seenOnlyThroughGrant(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n hostId: string,\n): boolean {\n return grantedScopeTokens(doc).length > 0 && !heldByHost(doc, hostId)\n}\n"],"names":["ORG_SCOPE_TOKEN","HOST_TOKEN_PREFIX","MAX_SCOPE_HOSTS","hostScopeToken","hostId","isScopeToken","value","startsWith","length","parseScopeToken","token","kind","slice","hostIdsFromScope","visibleTo","ids","parsed","push","scopeTokensForHost","visibleToHost","includes","visibleToTokens","scopeTokens","some","storedScope","Array","isArray","normalizeVisibleTo","input","tokens","filter","unique","Set","scopeToStore","scope","problem","scopeForHosts","hostIds","map","isOrgWideScope","narrowsScope","before","after","kept","has","describeScope","hostNames","name","defaultScopeForNewResource","options","defaultResourceScope","defaultMediaScopeOf","org","defaultMediaScope","newResourceScopeFields","Error","scopeCovers","target","source","reach","every","hostQualifiedCdnPath","cdnPath","undefined","marker","at","indexOf","head","rest","scopeSegment","tail","split","join","SCOPE_GRANTS_FIELD","grantedScopeTokens","doc","grants","added","heldScopeTokens","granted","capturing","add","captured","id","heldByHost","seenOnlyThroughGrant"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;CAcC,GASD,wDAAwD,GACxD,OAAO,MAAMA,kBAAkB,MAAmC;AAElE,MAAMC,oBAAoB;AAE1B;;;;CAIC,GACD,OAAO,MAAMC,kBAAkB,GAAE;AAEjC,sDAAsD,GACtD,OAAO,SAASC,eAAeC,MAAc;IAC3C,OAAO,GAAGH,oBAAoBG,QAAQ;AACxC;AAEA,OAAO,SAASC,aAAaC,KAAc;IACzC,IAAI,OAAOA,UAAU,UAAU,OAAO;IACtC,IAAIA,UAAUN,iBAAiB,OAAO;IACtC,OACEM,MAAMC,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AA,MAAO,CAAC,EAAE,CAAC,YAAY;IAC1C,IAAI,CAAClD,MAAMC,OAAO,CAACZ,YAAY,OAAO,EAAE;IACxC,MAAMiE,UAAU,IAAI/C,IAAI0C,mBAAmBC;IAC3C,MAAMK,YAAY,IAAIhD;IACtB,MAAM5B,SAAS,CAACuE,cAAAA,MAAO,CAAC,EAAE,CAAC,SAAS;IACpC,IAAI,OAAOvE,WAAW,YAAYA,QAAQ4E,UAAUC,GAAG,CAAC9E,eAAeC;IACvE,MAAM8E,WAAW,CAACP,cAAAA,MAAO,CAAC,EAAE,CAAC,oBAAoB;IACjD,IAAIlD,MAAMC,OAAO,CAACwD,WAAW;QAC3B,KAAK,MAAMC,MAAMD,SAAU,IAAI,OAAOC,OAAO,YAAYA,IAAIH,UAAUC,GAAG,CAAC9E,eAAegF;IAC5F;IACA,OAAOrE,UAAUgB,MAAM,CACrB,CAACpB,QACC,OAAOA,UAAU,YAAa,CAAA,CAACqE,QAAQnC,GAAG,CAAClC,UAAUsE,UAAUpC,GAAG,CAAClC,MAAK;AAE9E;AAEA;;;;CAIC,GACD,OAAO,SAAS0E,WACdT,GAAyD,EACzDvE,MAAc;IAEd,OAAOe,cAAc2D,gBAAgBH,MAAMvE;AAC7C;AAEA;;;;;CAKC,GACD,OAAO,SAASiF,qBACdV,GAAyD,EACzDvE,MAAc;IAEd,OAAOsE,mBAAmBC,KAAKnE,MAAM,GAAG,KAAK,CAAC4E,WAAWT,KAAKvE;AAChE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/scope-tokens.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 * Scoped sharing (AGL-1037): org-owned resources — datasets, media assets,\n * media folders — carry a `visibleTo` array naming who may see them, so an\n * agency can keep an internal dataset off its client sites without forking\n * storage into a second host-scoped collection (see AGL-237, which moved\n * these the other way).\n *\n * The shape is dictated by what both enforcement layers can evaluate:\n * Firestore rules have no `.map()`, so the caller's read set is denormalized\n * onto their member doc (AGL-1038) and matched with `list.hasAny(list)`;\n * clients match the same field with `array-contains-any`. A flat array of\n * strings is the only shape both primitives accept — the friendlier\n * `{ kind, hostIds }` form is a presentation concern and lives in\n * `describeScope` below, never on the doc.\n */\n\nimport type { ScopeToken } from '../foundation'\n\n// The type itself lives in foundation (app-utils imports foundation, never\n// the reverse) so the media doc interfaces can reference it; re-exported\n// here so callers get the type and its helpers from one place.\nexport type { ScopeToken }\n\n/** Everyone in the owning org, and every host it owns. */\nexport const ORG_SCOPE_TOKEN = 'org' as const satisfies ScopeToken\n\nconst HOST_TOKEN_PREFIX = 'host:'\n\n/**\n * `array-contains-any` and `hasAny` both cap at 30 values. That caps a\n * selected-sites scope at 30 hosts, and a collaborator's read query at 29\n * hosts plus `'org'`. Wider than that is the `['org']` case.\n */\nexport const MAX_SCOPE_HOSTS = 30\n\n/** `host:{hostId}` — the token naming a single site. */\nexport function hostScopeToken(hostId: string): ScopeToken {\n return `${HOST_TOKEN_PREFIX}${hostId}`\n}\n\nexport function isScopeToken(value: unknown): value is ScopeToken {\n if (typeof value !== 'string') return false\n if (value === ORG_SCOPE_TOKEN) return true\n return (\n value.startsWith(HOST_TOKEN_PREFIX) &&\n value.length > HOST_TOKEN_PREFIX.length\n )\n}\n\n/** Reads a token back apart; null when it isn't one. */\nexport function parseScopeToken(\n token: string\n): { kind: 'org' } | { kind: 'host'; hostId: string } | null {\n if (token === ORG_SCOPE_TOKEN) return { kind: 'org' }\n if (!isScopeToken(token)) return null\n return { kind: 'host', hostId: token.slice(HOST_TOKEN_PREFIX.length) }\n}\n\n/** Every host id named by a scope, in order; `['org']` names none. */\nexport function hostIdsFromScope(\n visibleTo: readonly string[] | undefined\n): string[] {\n const ids: string[] = []\n for (const token of visibleTo ?? []) {\n const parsed = parseScopeToken(token)\n if (parsed?.kind === 'host') ids.push(parsed.hostId)\n }\n return ids\n}\n\n/**\n * The read set for one site: what a server read path or a scoped client\n * query passes to `array-contains-any`. `'org'` is included because an\n * org-wide resource is visible to every host in the org.\n */\nexport function scopeTokensForHost(hostId: string): ScopeToken[] {\n return [ORG_SCOPE_TOKEN, hostScopeToken(hostId)]\n}\n\n/**\n * Whether a host may see a resource.\n *\n * ## A missing `visibleTo` is visible to NOBODY\n *\n * It once read as org-wide, so that documents predating the scope backfill\n * stayed visible until it reached them. That default is the shape of failure\n * this codebase keeps paying for: **a read that cannot see a value answered\n * the same as a value that is absent.** \"This document was never scoped\" and\n * \"this document is shared with every site\" are different facts, and one\n * unscoped document under an agency account was one client's data on every\n * other client's site — silently, because the permissive answer is the one\n * nothing complains about.\n *\n * Both enforcement layers below this function already fail CLOSED on the\n * missing field: `array-contains-any` matches nothing on a document that\n * lacks the array, and the rules' `hasAny` is false for the same reason. So\n * the permissive default was never a policy either of them agreed with — it\n * was one TypeScript helper disagreeing with the database, which is what made\n * AGL-1466 invisible for three weeks.\n *\n * The migration is `tools/scripts/backfill-consent-host.mjs`, which stamps\n * `['org']` on the documents that should carry it. Until a document is\n * stamped it is hidden, and hiding is the recoverable direction.\n *\n * An **empty array** answers the same and always did.\n */\nexport function visibleToHost(\n visibleTo: readonly string[] | undefined | null,\n hostId: string\n): boolean {\n if (visibleTo == null) return false\n if (visibleTo.includes(ORG_SCOPE_TOKEN)) return true\n return visibleTo.includes(hostScopeToken(hostId))\n}\n\n/**\n * Whether a caller holding `scopeTokens` (AGL-1038) may see a resource.\n * The TypeScript twin of the rules' `visibleTo.hasAny(scopeTokens)`, for\n * the Admin-SDK paths that never evaluate rules at all.\n *\n * A missing `visibleTo` is visible to nobody, for the reason\n * {@link visibleToHost} gives — and here the twinning is the argument on its\n * own: `hasAny` over a missing field is false in the rules, so a helper that\n * answered `true` was not a twin of anything.\n */\nexport function visibleToTokens(\n visibleTo: readonly string[] | undefined | null,\n scopeTokens: readonly string[] | undefined | null\n): boolean {\n if (visibleTo == null) return false\n if (!scopeTokens?.length) return false\n return visibleTo.some((token) => scopeTokens.includes(token))\n}\n\n/**\n * The scope a document ACTUALLY carries — `null` when it carries none\n * (AGL-1466/AGL-1480).\n *\n * Every helper above this line answers \"may this be seen\", and answers it\n * the way both enforcement layers do: a missing `visibleTo` is seen by\n * nobody.\n *\n * An **editor** asks a different question — \"what did somebody choose\" —\n * and it still needs its own answer, because \"nobody chose\" and \"somebody\n * chose nobody\" are the same to an editor and different on the document.\n * Four call sites across two files each wrote their own\n *\n * ```ts\n * Array.isArray(doc.visibleTo) ? doc.visibleTo : [ORG_SCOPE_TOKEN]\n * ```\n *\n * and every one of them rendered \"All sites\" over a document no site could\n * see. That inversion is why AGL-1466 went three weeks unnoticed with the\n * folder tree missing from every host, and AGL-1480 is the third and fourth\n * copies of it turning up at the surface people use most.\n *\n * So: one function, the same lesson `newMediaFolderDoc` drew on the write\n * side. A caller that wants a display default may still `?? []` or\n * `?? [ORG_SCOPE_TOKEN]` — but it has to say so, in one visible place,\n * instead of a ternary that reads like a null check.\n *\n * An empty array answers `null` too. On the document the two differ, and\n * `newResourceScopeFields` refuses to WRITE one; to an editor they are the\n * same fact — nobody chose this — and both must offer the choice rather\n * than pre-fill an answer.\n *\n * Not normalized, deliberately. `normalizeVisibleTo` collapses for STORAGE;\n * doing it here would make an untouched editor differ from the document it\n * was seeded from, and the save gates compare exactly those two to decide\n * whether to write at all.\n */\nexport function storedScope(\n visibleTo: readonly string[] | undefined | null\n): string[] | null {\n return Array.isArray(visibleTo) && visibleTo.length ? [...visibleTo] : null\n}\n\n/**\n * Cleans a scope for storage: drops junk, dedupes, and collapses to\n * `['org']` when org-wide is present, since that already implies every\n * host. Returns null when the result is unusable — empty, or over\n * `MAX_SCOPE_HOSTS` — so the caller decides rather than this silently\n * dropping hosts (losing access) or widening to org (leaking).\n */\nexport function normalizeVisibleTo(\n input: readonly string[] | undefined | null\n): ScopeToken[] | null {\n const tokens = (input ?? []).filter(isScopeToken)\n if (!tokens.length) return null\n if (tokens.includes(ORG_SCOPE_TOKEN)) return [ORG_SCOPE_TOKEN]\n const unique = [...new Set(tokens)]\n if (unique.length > MAX_SCOPE_HOSTS) return null\n return unique\n}\n\n/**\n * The scope a save writes, or why the selection cannot be written.\n *\n * {@link normalizeVisibleTo} answers null for a selection it cannot store, and\n * a save has no safe substitute for that null: the org token shares the\n * resource with every site, and dropping tokens takes access from sites\n * somebody picked. So a caller refuses the save and shows `problem`.\n */\nexport function scopeToStore(\n input: readonly string[] | undefined | null\n): { scope: ScopeToken[]; problem: null } | { scope: null; problem: string } {\n const scope = normalizeVisibleTo(input)\n if (scope) return { scope, problem: null }\n return {\n scope: null,\n problem: (input ?? []).some(isScopeToken)\n ? `Choose ${MAX_SCOPE_HOSTS} sites or fewer, or share with All sites.`\n : 'Choose at least one site, or share with All sites.',\n }\n}\n\n/** A scope covering exactly the given hosts; null when unusable. */\nexport function scopeForHosts(\n hostIds: readonly string[]\n): ScopeToken[] | null {\n return normalizeVisibleTo(hostIds.map(hostScopeToken))\n}\n\n/**\n * Whether a scope is the org-wide one.\n *\n * An absent scope is NOT org-wide — see {@link visibleToHost}. That is the\n * whole correction: this predicate is what `describeScope` renders and what\n * `scopeCovers` and `narrowsScope` reason from, and while it answered `true`\n * for a document nothing could see, the console said \"All sites\" over it.\n */\nexport function isOrgWideScope(\n visibleTo: readonly string[] | undefined | null\n): boolean {\n return visibleTo != null && visibleTo.includes(ORG_SCOPE_TOKEN)\n}\n\n/**\n * Whether moving from `before` to `after` takes visibility away from any\n * host — the direction that can break a published page, and the one the\n * console confirms before saving (AGL-1044/AGL-1045).\n */\nexport function narrowsScope(\n before: readonly string[] | undefined | null,\n after: readonly string[] | undefined | null\n): boolean {\n if (isOrgWideScope(before)) return !isOrgWideScope(after)\n if (isOrgWideScope(after)) return false\n const kept = new Set(after ?? [])\n return (before ?? []).some((token) => !kept.has(token))\n}\n\n/**\n * The sentence the console shows. `hostNames` maps host id → display name;\n * ids missing from it fall back to the count wording, since a name we\n * can't resolve is worse than no name.\n */\nexport function describeScope(\n visibleTo: readonly string[] | undefined | null,\n hostNames: Readonly<Record<string, string>> = {}\n): string {\n if (isOrgWideScope(visibleTo)) return 'All sites'\n const hostIds = hostIdsFromScope(visibleTo ?? [])\n if (!hostIds.length) return 'No sites'\n if (hostIds.length === 1) {\n const name = hostNames[hostIds[0]]\n return name ? `${name} only` : '1 site'\n }\n return `${hostIds.length} sites`\n}\n\n/**\n * The scope a newly created resource starts with (AGL-1048).\n *\n * Honours the org's default — `defaultResourceScope` for a dataset,\n * `defaultMediaScopeOf(org)` for media, passed in the same option — but\n * only when a site is\n * actually in context: created from the org Media or Data page there is no\n * host to scope to, and inventing one would hide the resource from the\n * page that just created it.\n */\nexport function defaultScopeForNewResource(options: {\n defaultResourceScope?: 'org' | 'host'\n hostId?: string | null\n}): ScopeToken[] {\n return options.defaultResourceScope === 'host' && options.hostId\n ? [hostScopeToken(options.hostId)]\n : [ORG_SCOPE_TOKEN]\n}\n\n/**\n * The org's default sharing for new MEDIA — uploads and folders (AGL-3662).\n *\n * `defaultMediaScope` when the org has set it, otherwise\n * `defaultResourceScope`: until the two were split one field decided both,\n * so an org that chose \"only the site they were created in\" before the split\n * keeps that choice for media until it sets media on its own. Datasets read\n * `defaultResourceScope` directly.\n */\nexport function defaultMediaScopeOf(\n org:\n | {\n defaultMediaScope?: 'org' | 'host'\n defaultResourceScope?: 'org' | 'host'\n }\n | null\n | undefined,\n): 'org' | 'host' | undefined {\n return org?.defaultMediaScope ?? org?.defaultResourceScope\n}\n\n/**\n * The scope fields a document being CREATED in a scoped collection carries\n * (AGL-1478), as a spreadable object.\n *\n * The argument is REQUIRED and has no default, which is the whole point.\n * AGL-1466 was two call sites that each built a `mediaFolders` document\n * inline and each forgot `visibleTo`; `newMediaFolderDoc` fixed that one\n * collection by making the input mandatory, and this is the same guarantee\n * for the collections that have no document constructor of their own —\n * `datasets`, `media`, `contacts`, `contactSegments`. A creator that has\n * not decided cannot compile.\n *\n * Three inputs, three meanings:\n *\n * - **tokens** — stamp them.\n * - **`null`** — this collection is NOT scoped (a `hosts/{hostId}`\n * subcollection is private by construction), so store nothing. Saying it\n * out loud is what distinguishes \"not applicable\" from \"forgotten\".\n * - **`[]`** — throws. Unlike a missing field, a stored empty array is a\n * written \"visible to nobody\": the backfill leaves it alone by design and\n * no read path treats it as legacy, so it is permanent where absent is\n * repairable. Getting here means a caller computed a scope and came back\n * with nothing, which is worth a stack trace.\n */\nexport function newResourceScopeFields(\n visibleTo: readonly ScopeToken[] | null\n): { visibleTo?: ScopeToken[] } {\n if (visibleTo && !visibleTo.length) {\n throw new Error('A scoped resource cannot be created with an empty scope')\n }\n return visibleTo ? { visibleTo: [...visibleTo] } : {}\n}\n\n/**\n * Whether `target` is visible everywhere `source` is — the condition a\n * cross-dataset REFERENCE has to satisfy (AGL-1044).\n *\n * A reference field on dataset A pointing at dataset B is only resolvable\n * on the sites that can see BOTH. If A is shared with a site that cannot\n * see B, a page there resolves the reference to nothing: the row renders\n * with a blank where the linked value should be, and nothing says why. So\n * B's scope must COVER A's.\n *\n * Org-wide covers everything. A missing scope is seen by nobody and\n * therefore covers nothing, matching the rest of this module.\n */\nexport function scopeCovers(\n target: readonly string[] | undefined | null,\n source: readonly string[] | undefined | null,\n): boolean {\n if (isOrgWideScope(target)) return true\n // The target is restricted; an org-wide source reaches sites it cannot.\n if (isOrgWideScope(source)) return false\n const reach = new Set(target ?? [])\n return (source ?? []).every((token) => reach.has(token))\n}\n\n/**\n * Rewrites an org media CDN path so it names the site using the asset\n * (AGL-1043/1045).\n *\n * `/api/media/cdn/org:{orgId}/{mediaId}` serves org-wide assets, and assets\n * shared with all sites except some. An asset shared with chosen sites has to\n * be requested through the form that names the site — `org:{orgId}:{hostId}` — because the CDN is unauthenticated and\n * the URL is the only thing it can decide from.\n *\n * Returns the path untouched when there is nothing to do: an org-wide\n * asset, a host-library asset, no host context, or a path that is not an\n * org CDN URL. That keeps it safe to apply blindly at every pick site.\n */\nexport function hostQualifiedCdnPath(\n cdnPath: string | undefined | null,\n visibleTo: readonly string[] | undefined | null,\n hostId: string | undefined | null,\n): string | undefined {\n if (!cdnPath) return cdnPath ?? undefined\n if (!hostId || isOrgWideScope(visibleTo)) return cdnPath\n // `/api/media/cdn/{scope}/{mediaId}[/{hash}]`\n const marker = '/api/media/cdn/'\n const at = cdnPath.indexOf(marker)\n if (at === -1) return cdnPath\n const head = cdnPath.slice(0, at + marker.length)\n const rest = cdnPath.slice(at + marker.length)\n const [scopeSegment, ...tail] = rest.split('/')\n // Only the bare `org:{orgId}` form is rewritten; an already-qualified\n // scope is left alone rather than gaining a second host.\n if (!scopeSegment.startsWith('org:') || scopeSegment.includes(':', 4)) {\n return cdnPath\n }\n return [`${head}${scopeSegment}:${hostId}`, ...tail].join('/')\n}\n\n/*==========================================\n * SEEN, AND HELD (AGL-3336).\n *\n * `visibleTo` answers one question, \"who may see this\", because it is the\n * one field both enforcement layers can evaluate. A visibility GRANT — an\n * org manager sharing a record with another site, by hand or by a rule —\n * has to widen exactly that field, or the other site's lists, which are\n * real `array-contains-any` queries, could never return the record.\n *\n * But a site a record was shared with does not HOLD it. It did not capture\n * the person, it holds no consent from them, and letting go of the record\n * is not its decision. So a document that carries a grant records which of\n * its tokens the grant added, under `sharing.added`, and every question\n * about holding — who may delete it, whose audience it joins, which site's\n * list it enters — reads {@link heldScopeTokens} instead of `visibleTo`.\n *\n * A document without the field is held by everything that sees it, which\n * is every document written before grants existed.\n *=========================================*/\n\n/** The map a scoped document records its visibility grants under. */\nexport const SCOPE_GRANTS_FIELD = 'sharing'\n\n/** The tokens a grant ADDED to `visibleTo`: seen through, never held. */\nexport function grantedScopeTokens(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n): string[] {\n const grants = (doc ?? {})[SCOPE_GRANTS_FIELD]\n if (!grants || typeof grants !== 'object' || Array.isArray(grants)) return []\n const added = (grants as Record<string, unknown>)['added']\n return Array.isArray(added)\n ? added.filter((token): token is string => typeof token === 'string')\n : []\n}\n\n/**\n * The tokens that HOLD a document: `visibleTo` without the ones a grant\n * added. Missing `visibleTo` is held by nobody, as it is seen by nobody.\n *\n * A site that created the document (`hostId`) or captured the person on it\n * (`capturedByHostIds`) holds its token whatever the grants say: a record\n * shared with a site that then captures the person itself is that site's\n * own from the capture on, before anything re-evaluates the grants.\n */\nexport function heldScopeTokens(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n): string[] {\n const visibleTo = (doc ?? {})['visibleTo']\n if (!Array.isArray(visibleTo)) return []\n const granted = new Set(grantedScopeTokens(doc))\n const capturing = new Set<string>()\n const hostId = (doc ?? {})['hostId']\n if (typeof hostId === 'string' && hostId) capturing.add(hostScopeToken(hostId))\n const captured = (doc ?? {})['capturedByHostIds']\n if (Array.isArray(captured)) {\n for (const id of captured) if (typeof id === 'string' && id) capturing.add(hostScopeToken(id))\n }\n return visibleTo.filter(\n (token): token is string =>\n typeof token === 'string' && (!granted.has(token) || capturing.has(token)),\n )\n}\n\n/**\n * Whether a site HOLDS a document rather than only seeing it through a\n * grant. The question a marketing audience, a list rule, a sequence and a\n * holder count ask; {@link visibleToHost} is the one a reader asks.\n */\nexport function heldByHost(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n hostId: string,\n): boolean {\n return visibleToHost(heldScopeTokens(doc), hostId)\n}\n\n/**\n * Whether a site sees a document ONLY through a grant: it carries grants and\n * the site does not hold it. The filter an audience sweep applies to what\n * its scoped query returned — a document with no grants answers `false`, so\n * every read that predates sharing keeps exactly the rows it had.\n */\nexport function seenOnlyThroughGrant(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n hostId: string,\n): boolean {\n return grantedScopeTokens(doc).length > 0 && !heldByHost(doc, hostId)\n}\n\n/*==========================================\n * ALL SITES EXCEPT… (AGL-4047).\n *\n * A third way to share, beside \"All sites\" and \"these sites\". Neither\n * enforcement layer can read an exclusion: Firestore has no \"does not\n * contain\", `not-in` cannot sit beside `array-contains-any`, and a rule that\n * refused on one would fail every scoped member's whole list. So what readers\n * enforce stays what it has always been, a flat `visibleTo` of the sites that\n * ARE included, and the choice that produced it sits beside it as a marker:\n *\n * visibleTo: ['host:b', 'host:c'] the only field a reader looks at\n * scopeMode: 'allExcept' says new sites join\n * scopeExcept: ['host:a'] the sites that stay out\n *\n * `visibleTo` is therefore a list that has to be kept up: a new site joins it\n * and a deleted one leaves it. {@link reconcileAllExcept} is the one answer to\n * what it should hold; the sweep (`scope-sharing-sweep.ts`) applies it.\n *\n * `visibleTo` always wins over the marker when they disagree, because it is\n * what the database enforces. A helper describing a document some other way\n * would be describing something no reader does.\n *=========================================*/\n\n/** The `scopeMode` a document kept up by the sweep carries. */\nexport const SCOPE_MODE_ALL_EXCEPT = 'allExcept' as const\n\n/**\n * What a sharing choice writes. A `null` marker field means the document must\n * not carry it, which a server write spells as a field delete, so a document\n * moved back to All sites or to chosen sites keeps no stale marker.\n */\nexport interface ScopeSharingFields {\n visibleTo: ScopeToken[]\n scopeMode: typeof SCOPE_MODE_ALL_EXCEPT | null\n scopeExcept: ScopeToken[] | null\n}\n\n/** How a document is shared, as a person would choose it. */\nexport type ScopeSharing =\n | { mode: 'all' }\n | { mode: 'selected'; hostIds: string[] }\n | { mode: 'allExcept'; exceptHostIds: string[]; includedHostIds: string[] }\n | { mode: 'none' }\n\n/** What a person picked: the input to {@link sharingFromChoice}. */\nexport type ScopeSharingChoice =\n | { mode: 'all' }\n | { mode: 'selected'; hostIds: readonly string[] }\n | { mode: 'allExcept'; exceptHostIds: readonly string[] }\n\nconst uniqueStrings = (values: readonly string[]): string[] => [\n ...new Set(values.filter((value) => typeof value === 'string' && value)),\n]\n\n/**\n * The excluded sites a marker names, or null when the marker is not one this\n * module can act on: anything but an array of host tokens. Null is what keeps\n * a damaged marker from being read as \"except nothing\", which means All sites.\n */\nfunction markerExceptHostIds(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n): string[] | null {\n if (doc?.['scopeMode'] !== SCOPE_MODE_ALL_EXCEPT) return null\n const except = doc['scopeExcept']\n if (!Array.isArray(except)) return null\n const ids: string[] = []\n for (const token of except) {\n const parsed = typeof token === 'string' ? parseScopeToken(token) : null\n if (parsed?.kind !== 'host') return null\n ids.push(parsed.hostId)\n }\n return uniqueStrings(ids)\n}\n\n/**\n * How a document is shared. Reads the marker only where it agrees with what\n * readers enforce: a document carrying `'org'` is shared with all sites\n * whatever a marker beside it says, and a damaged marker reads as the chosen\n * sites `visibleTo` names.\n */\nexport function scopeSharingOf(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n): ScopeSharing {\n const visibleTo = doc?.['visibleTo']\n const tokens = Array.isArray(visibleTo)\n ? visibleTo.filter((token): token is string => typeof token === 'string')\n : null\n if (tokens?.includes(ORG_SCOPE_TOKEN)) return { mode: 'all' }\n const included = uniqueStrings(hostIdsFromScope(tokens ?? []))\n const except = tokens ? markerExceptHostIds(doc) : null\n if (except) {\n return { mode: 'allExcept', exceptHostIds: except, includedHostIds: included }\n }\n return included.length ? { mode: 'selected', hostIds: included } : { mode: 'none' }\n}\n\n/**\n * What a sharing choice writes, or why it cannot be written.\n *\n * `orgHostIds` is the workspace's sites as the writer read them. An exclusion\n * naming a site that is no longer there is dropped, not refused: the person\n * asked for that site to stay out, and it is out. Excluding nothing is\n * refused, since that choice is All sites; excluding everything is refused,\n * since it would hide the document from every site.\n *\n * An all-except list is not held to `MAX_SCOPE_HOSTS`, which limits what a\n * QUERY can ask for and never what a document stores. A collection whose\n * stored fields multiply by site passes its own `maxIncluded`. `keepHostIds`\n * are sites that stay on the list even if excluded, such as a site that\n * captured the person a record is about.\n */\nexport function sharingFromChoice(\n choice: ScopeSharingChoice,\n orgHostIds: readonly string[],\n options: { maxIncluded?: number | null; keepHostIds?: readonly string[] } = {},\n): { fields: ScopeSharingFields; problem: null } | { fields: null; problem: string } {\n if (choice.mode === 'all') {\n return {\n fields: { visibleTo: [ORG_SCOPE_TOKEN], scopeMode: null, scopeExcept: null },\n problem: null,\n }\n }\n if (choice.mode === 'selected') {\n const stored = scopeToStore(choice.hostIds.map(hostScopeToken))\n return stored.scope\n ? { fields: { visibleTo: stored.scope, scopeMode: null, scopeExcept: null }, problem: null }\n : { fields: null, problem: stored.problem }\n }\n const org = uniqueStrings(orgHostIds)\n const except = uniqueStrings(choice.exceptHostIds).filter((id) => org.includes(id))\n if (!except.length) {\n return {\n fields: null,\n problem: 'Choose at least one site to leave out, or share with All sites.',\n }\n }\n const included = includedHostIds(org, except, options.keepHostIds)\n if (!included.length) {\n return { fields: null, problem: 'Keep at least one site in, or choose the sites.' }\n }\n if (options.maxIncluded != null && included.length > options.maxIncluded) {\n return {\n fields: null,\n problem: `This can reach ${options.maxIncluded === 1 ? '1 site' : `${options.maxIncluded} sites`} at most. Leave out more sites, or choose the sites.`,\n }\n }\n return {\n fields: {\n visibleTo: included.map(hostScopeToken),\n scopeMode: SCOPE_MODE_ALL_EXCEPT,\n scopeExcept: except.map(hostScopeToken),\n },\n problem: null,\n }\n}\n\n/** The workspace's sites minus the excluded ones, plus the kept, sorted. */\nfunction includedHostIds(\n org: readonly string[],\n except: readonly string[],\n keep: readonly string[] | undefined,\n): string[] {\n const out = new Set(except)\n const kept = new Set(keep ?? [])\n return org.filter((id) => !out.has(id) || kept.has(id)).sort()\n}\n\n/** What keeping an all-except document up to date came to. */\nexport interface AllExceptReconcile {\n /**\n * - `unmarked`: not an all-except document; nothing to do.\n * - `current`: already says what it should.\n * - `changed`: write `fields`.\n * - `capped`: it should reach more sites than `maxIncluded`, so it stopped\n * widening. Any `fields` only take away sites that are gone.\n * - `invalid`: a marker this module cannot act on, or one beside `'org'`.\n * Left alone and reported, because either guess moves who can see it.\n */\n status: 'unmarked' | 'current' | 'changed' | 'capped' | 'invalid'\n fields: ScopeSharingFields | null\n}\n\n/**\n * What an all-except document should say, given the workspace's sites today.\n *\n * Pure and idempotent, which is what lets every trigger and the drift report\n * ask the same question: a second run over its own answer says `current`.\n *\n * - A new site joins `visibleTo`, unless it is excluded.\n * - A site that left the workspace leaves `visibleTo` and `scopeExcept`.\n * - Once no exclusion is left the document IS All sites, so it collapses to\n * `['org']` and drops its marker.\n * - When every remaining site is excluded `visibleTo` is empty and the marker\n * stays: no site sees it until a new one joins. The data is kept, which is\n * why {@link isSiteOnlyScope} answers false for a marked document.\n * - A site in `sharing.added` stays, since a person shared the document with\n * it. So do `keepHostIds`. Both only while the site is in the workspace.\n */\nexport function reconcileAllExcept(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n orgHostIds: readonly string[],\n options: { maxIncluded?: number | null; keepHostIds?: readonly string[] } = {},\n): AllExceptReconcile {\n if (doc?.['scopeMode'] === undefined || doc['scopeMode'] === null) {\n return { status: 'unmarked', fields: null }\n }\n const storedExcept = markerExceptHostIds(doc)\n const visibleTo = doc['visibleTo']\n if (\n !storedExcept ||\n !Array.isArray(visibleTo) ||\n visibleTo.includes(ORG_SCOPE_TOKEN)\n ) {\n return { status: 'invalid', fields: null }\n }\n const org = uniqueStrings(orgHostIds)\n const except = storedExcept.filter((id) => org.includes(id))\n if (!except.length) {\n return {\n status: 'changed',\n fields: { visibleTo: [ORG_SCOPE_TOKEN], scopeMode: null, scopeExcept: null },\n }\n }\n const current = uniqueStrings(hostIdsFromScope(visibleTo as string[]))\n const keep = [\n ...(options.keepHostIds ?? []),\n ...hostIdsFromScope(grantedScopeTokens(doc)),\n ]\n let included = includedHostIds(org, except, keep)\n let capped = false\n if (\n options.maxIncluded != null &&\n included.length > options.maxIncluded &&\n included.some((id) => !current.includes(id))\n ) {\n capped = true\n included = current.filter((id) => org.includes(id)).sort()\n }\n const same =\n included.length === current.length &&\n included.every((id) => current.includes(id)) &&\n except.length === storedExcept.length\n const fields: ScopeSharingFields | null = same\n ? null\n : {\n visibleTo: included.map(hostScopeToken),\n scopeMode: SCOPE_MODE_ALL_EXCEPT,\n scopeExcept: except.map(hostScopeToken),\n }\n if (capped) return { status: 'capped', fields }\n return fields ? { status: 'changed', fields } : { status: 'current', fields: null }\n}\n\n/**\n * The sentence the console shows for how a document is shared:\n * {@link describeScope}, plus the all-except wording. Sites are named only\n * where `hostNames` has them, so a reader who cannot see a site's name is told\n * how many sites, never an id.\n */\nexport function describeSharing(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n hostNames: Readonly<Record<string, string>> = {},\n): string {\n const sharing = scopeSharingOf(doc)\n if (sharing.mode !== 'allExcept') {\n return describeScope(doc?.['visibleTo'] as readonly string[] | undefined, hostNames)\n }\n if (!sharing.includedHostIds.length) return 'No sites'\n const names = sharing.exceptHostIds.map((id) => hostNames[id])\n const count = names.length\n if (count === 1) return `All sites except ${names[0] || '1 site'}`\n if (count === 2 && names.every(Boolean)) {\n return `All sites except ${names[0]} and ${names[1]}`\n }\n return `All sites except ${count} sites`\n}\n\n/**\n * Whether a document belongs to this site alone: what deciding to erase it\n * with the site asks, so the three copies of that question share one answer.\n *\n * FALSE FOR ANY MARKED DOCUMENT, and that is the reason this exists. A site\n * can be the last one an all-except document still reaches, with `visibleTo`\n * naming it and nothing else, and the document is still the workspace's.\n * Reading that as \"this site's own\" would erase the data with the site.\n */\nexport function isSiteOnlyScope(\n doc: Readonly<Record<string, unknown>> | null | undefined,\n hostId: string,\n): boolean {\n if (doc?.['scopeMode'] !== undefined && doc?.['scopeMode'] !== null) return false\n const visibleTo = doc?.['visibleTo']\n const token = hostScopeToken(hostId)\n return (\n Array.isArray(visibleTo) &&\n visibleTo.length > 0 &&\n visibleTo.every((entry) => entry === token)\n )\n}\n\n/**\n * {@link scopeCovers} for whole documents: whether `target` stays visible\n * everywhere `source` is, which a cross-dataset reference needs.\n *\n * Today's tokens are not enough once either side is all-except, because the\n * two lists move when a site is added: a chosen-sites target cannot cover an\n * all-except source however it looks today (the next new site gets the source\n * and not the target), and an all-except target covers an all-except source\n * only when it leaves out no site the source includes.\n */\nexport function sharingCovers(\n target: Readonly<Record<string, unknown>> | null | undefined,\n source: Readonly<Record<string, unknown>> | null | undefined,\n): boolean {\n const targetTokens = target?.['visibleTo'] as readonly string[] | undefined\n const sourceTokens = source?.['visibleTo'] as readonly string[] | undefined\n const targetSharing = scopeSharingOf(target)\n const sourceSharing = scopeSharingOf(source)\n if (sourceSharing.mode === 'allExcept') {\n if (targetSharing.mode === 'all') return true\n if (targetSharing.mode !== 'allExcept') return false\n const sourceExcept = new Set(sourceSharing.exceptHostIds)\n if (!targetSharing.exceptHostIds.every((id) => sourceExcept.has(id))) return false\n }\n return scopeCovers(targetTokens, sourceTokens)\n}\n"],"names":["ORG_SCOPE_TOKEN","HOST_TOKEN_PREFIX","MAX_SCOPE_HOSTS","hostScopeToken","hostId","isScopeToken","value","startsWith","length","parseScopeToken","token","kind","slice","hostIdsFromScope","visibleTo","ids","parsed","push","scopeTokensForHost","visibleToHost","includes","visibleToTokens","scopeTokens","some","storedScope","Array","isArray","normalizeVisibleTo","input","tokens","filter","unique","Set","scopeToStore","scope","problem","scopeForHosts","hostIds","map","isOrgWideScope","narrowsScope","before","after","kept","has","describeScope","hostNames","name","defaultScopeForNewResource","options","defaultResourceScope","defaultMediaScopeOf","org","defaultMediaScope","newResourceScopeFields","Error","scopeCovers","target","source","reach","every","hostQualifiedCdnPath","cdnPath","undefined","marker","at","indexOf","head","rest","scopeSegment","tail","split","join","SCOPE_GRANTS_FIELD","grantedScopeTokens","doc","grants","added","heldScopeTokens","granted","capturing","add","captured","id","heldByHost","seenOnlyThroughGrant","SCOPE_MODE_ALL_EXCEPT","uniqueStrings","values","markerExceptHostIds","except","scopeSharingOf","mode","included","exceptHostIds","includedHostIds","sharingFromChoice","choice","orgHostIds","fields","scopeMode","scopeExcept","stored","keepHostIds","maxIncluded","keep","out","sort","reconcileAllExcept","status","storedExcept","current","capped","same","describeSharing","sharing","names","count","Boolean","isSiteOnlyScope","entry","sharingCovers","targetTokens","sourceTokens","targetSharing","sourceSharing","sourceExcept"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;CAcC,GASD,wDAAwD,GACxD,OAAO,MAAMA,kBAAkB,MAAmC;AAElE,MAAMC,oBAAoB;AAE1B;;;;CAIC,GACD,OAAO,MAAMC,kBAAkB,GAAE;AAEjC,sDAAsD,GACtD,OAAO,SAASC,eAAeC,MAAc;IAC3C,OAAO,GAAGH,oBAAoBG,QAAQ;AACxC;AAEA,OAAO,SAASC,aAAaC,KAAc;IACzC,IAAI,OAAOA,UAAU,UAAU,OAAO;IACtC,IAAIA,UAAUN,iBAAiB,OAAO;IACtC,OACEM,MAAMC,UAAU,CAACN,sBACjBK,MAAME,MAAM,GAAGP,kBAAkBO,MAAM;AAE3C;AAEA,sDAAsD,GACtD,OAAO,SAASC,gBACdC,KAAa;IAEb,IAAIA,UAAUV,iBAAiB,OAAO;QAAEW,MAAM;IAAM;IACpD,IAAI,CAACN,aAAaK,QAAQ,OAAO;IACjC,OAAO;QAAEC,MAAM;QAAQP,QAAQM,MAAME,KAAK,CAACX,kBAAkBO,MAAM;IAAE;AACvE;AAEA,oEAAoE,GACpE,OAAO,SAASK,iBACdC,SAAwC;IAExC,MAAMC,MAAgB,EAAE;IACxB,KAAK,MAAML,SAASI,oBAAAA,YAAa,EAAE,CAAE;QACnC,MAAME,SAASP,gBAAgBC;QAC/B,IAAIM,CAAAA,0BAAAA,OAAQL,IAAI,MAAK,QAAQI,IAAIE,IAAI,CAACD,OAAOZ,MAAM;IACrD;IACA,OAAOW;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,mBAAmBd,MAAc;IAC/C,OAAO;QAACJ;QAAiBG,eAAeC;KAAQ;AAClD;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GACD,OAAO,SAASe,cACdL,SAA+C,EAC/CV,MAAc;IAEd,IAAIU,aAAa,MAAM,OA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,eAAe,IAAI9F,IAAI6F,cAAc/B,aAAa;QACxD,IAAI,CAAC8B,cAAc9B,aAAa,CAAClC,KAAK,CAAC,CAACuB,KAAO2C,aAAalF,GAAG,CAACuC,MAAM,OAAO;IAC/E;IACA,OAAO3B,YAAYkE,cAAcC;AACnC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { AglynOrgMember, HostAccessRole } from '../foundation';
|
|
18
|
+
import type { AglynOrgCustomRole } from './org-permissions';
|
|
19
|
+
/**
|
|
20
|
+
* Where a resource sits: the fields of its document that decide it. A whole
|
|
21
|
+
* document, never `visibleTo` alone, so no caller can answer without the marker.
|
|
22
|
+
*/
|
|
23
|
+
export type ScopePlaced = Readonly<{
|
|
24
|
+
visibleTo?: unknown;
|
|
25
|
+
scopeMode?: unknown;
|
|
26
|
+
scopeExcept?: unknown;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* The one site a resource is placed on, or `null` for every site, several, or
|
|
30
|
+
* none.
|
|
31
|
+
*
|
|
32
|
+
* `null` for a document shared with all sites except some, however few it reaches
|
|
33
|
+
* today. Its list can shrink to one site while it still belongs to the whole
|
|
34
|
+
* workspace, and the next new site joins it, so that one site never comes to
|
|
35
|
+
* answer for it. Read as the rules' `scopePlacement` reads it: either key present
|
|
36
|
+
* is marked, so a stored null or half a marker fails closed.
|
|
37
|
+
*/
|
|
38
|
+
export declare function oneSitePlacement(placed: ScopePlaced | null | undefined): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The verdict for a resource placed as `placed` says: see above. `site` is asked
|
|
41
|
+
* only when the workspace key did not settle it, so a door pays for reading the
|
|
42
|
+
* site only then.
|
|
43
|
+
*/
|
|
44
|
+
export declare function placementVerdict<T extends boolean | Promise<boolean>>(input: {
|
|
45
|
+
member: Partial<AglynOrgMember> | null | undefined;
|
|
46
|
+
placed: ScopePlaced | null | undefined;
|
|
47
|
+
workspace: boolean;
|
|
48
|
+
site: (hostId: string) => T;
|
|
49
|
+
}): boolean | T;
|
|
50
|
+
/**
|
|
51
|
+
* The site key as the site's stamp gives it, read as the rules read it:
|
|
52
|
+
* `memberPermissions[uid][key]`, else, on a site the projection has not reached
|
|
53
|
+
* since the key existed, the site role's preset, unless someone decided against
|
|
54
|
+
* this member in a way the stamp would carry: a custom role, or their own
|
|
55
|
+
* workspace key refused. Those wait for the stamp, so nobody refused regains it
|
|
56
|
+
* from `memberRoles`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function stampedPlacementKey(stamps: {
|
|
59
|
+
memberPermissions?: unknown;
|
|
60
|
+
memberRoles?: unknown;
|
|
61
|
+
} | null | undefined, uid: string, key: string, preset: Readonly<Partial<Record<HostAccessRole, boolean>>>, member: (Partial<AglynOrgMember> & {
|
|
62
|
+
roleId?: unknown;
|
|
63
|
+
permissions?: unknown;
|
|
64
|
+
}) | null | undefined, workspaceKey: string): boolean;
|
|
65
|
+
/** The site key from the membership alone, by the function the site's stamp is written from. */
|
|
66
|
+
export declare function resolvedPlacementKey(member: Partial<AglynOrgMember> | null | undefined, hostId: string, key: string, customRole?: AglynOrgCustomRole | null): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Whether deleting a resource is out of this member's reach whatever they hold:
|
|
69
|
+
* they do not reach every site, and it is placed on every site, on several, or on
|
|
70
|
+
* all sites except some. It belongs to the whole workspace.
|
|
71
|
+
*/
|
|
72
|
+
export declare function deleteBeyondReach(member: Partial<AglynOrgMember> | null | undefined, placed: ScopePlaced | null | undefined): boolean;
|
|
73
|
+
/** The refusal for it, which names the reach it takes because no permission decides it. */
|
|
74
|
+
export declare function deleteBeyondReachRefusal(label: string): string;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { hostStampedSitePermission, resolveMemberHostPermissions, siteMayNarrow } from "./host-permissions.js";
|
|
17
|
+
import { hostRoleFor, isOrgWideMember } from "./organizations.js";
|
|
18
|
+
/**
|
|
19
|
+
* The one site a resource is placed on, or `null` for every site, several, or
|
|
20
|
+
* none.
|
|
21
|
+
*
|
|
22
|
+
* `null` for a document shared with all sites except some, however few it reaches
|
|
23
|
+
* today. Its list can shrink to one site while it still belongs to the whole
|
|
24
|
+
* workspace, and the next new site joins it, so that one site never comes to
|
|
25
|
+
* answer for it. Read as the rules' `scopePlacement` reads it: either key present
|
|
26
|
+
* is marked, so a stored null or half a marker fails closed.
|
|
27
|
+
*/ export function oneSitePlacement(placed) {
|
|
28
|
+
if (!placed || placed.scopeMode !== undefined || placed.scopeExcept !== undefined) return null;
|
|
29
|
+
const { visibleTo } = placed;
|
|
30
|
+
if (!Array.isArray(visibleTo) || visibleTo.length !== 1) return null;
|
|
31
|
+
const [token] = visibleTo;
|
|
32
|
+
const match = typeof token === 'string' ? /^host:([^:/]+)$/.exec(token) : null;
|
|
33
|
+
return match ? match[1] : null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The verdict for a resource placed as `placed` says: see above. `site` is asked
|
|
37
|
+
* only when the workspace key did not settle it, so a door pays for reading the
|
|
38
|
+
* site only then.
|
|
39
|
+
*/ export function placementVerdict(input) {
|
|
40
|
+
const hostId = oneSitePlacement(input.placed);
|
|
41
|
+
if (!hostId) return input.workspace;
|
|
42
|
+
if (input.workspace && !siteMayNarrow(input.member, hostId)) return true;
|
|
43
|
+
return input.site(hostId);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The site key as the site's stamp gives it, read as the rules read it:
|
|
47
|
+
* `memberPermissions[uid][key]`, else, on a site the projection has not reached
|
|
48
|
+
* since the key existed, the site role's preset, unless someone decided against
|
|
49
|
+
* this member in a way the stamp would carry: a custom role, or their own
|
|
50
|
+
* workspace key refused. Those wait for the stamp, so nobody refused regains it
|
|
51
|
+
* from `memberRoles`.
|
|
52
|
+
*/ export function stampedPlacementKey(stamps, uid, key, preset, member, workspaceKey) {
|
|
53
|
+
var _stamps_memberPermissions_uid, _stamps_memberPermissions, _member_permissions;
|
|
54
|
+
const stamp = stamps == null ? void 0 : (_stamps_memberPermissions = stamps.memberPermissions) == null ? void 0 : (_stamps_memberPermissions_uid = _stamps_memberPermissions[uid]) == null ? void 0 : _stamps_memberPermissions_uid[key];
|
|
55
|
+
if (typeof stamp === 'boolean') return stamp;
|
|
56
|
+
if ((member == null ? void 0 : member.roleId) != null || (member == null ? void 0 : (_member_permissions = member.permissions) == null ? void 0 : _member_permissions[workspaceKey]) === false) return false;
|
|
57
|
+
return hostStampedSitePermission({
|
|
58
|
+
memberRoles: stamps == null ? void 0 : stamps.memberRoles
|
|
59
|
+
}, uid, key, preset);
|
|
60
|
+
}
|
|
61
|
+
/** The site key from the membership alone, by the function the site's stamp is written from. */ export function resolvedPlacementKey(member, hostId, key, customRole) {
|
|
62
|
+
if (!member || !hostRoleFor(member, hostId)) return false;
|
|
63
|
+
return resolveMemberHostPermissions({
|
|
64
|
+
member,
|
|
65
|
+
customRole: customRole != null ? customRole : null,
|
|
66
|
+
hostId
|
|
67
|
+
})[key] === true;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Whether deleting a resource is out of this member's reach whatever they hold:
|
|
71
|
+
* they do not reach every site, and it is placed on every site, on several, or on
|
|
72
|
+
* all sites except some. It belongs to the whole workspace.
|
|
73
|
+
*/ export function deleteBeyondReach(member, placed) {
|
|
74
|
+
return !isOrgWideMember(member) && oneSitePlacement(placed) === null;
|
|
75
|
+
}
|
|
76
|
+
/** The refusal for it, which names the reach it takes because no permission decides it. */ export function deleteBeyondReachRefusal(label) {
|
|
77
|
+
return `This ${label.toLowerCase()} is shared beyond one site, so deleting it takes access to every site in the workspace.`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=site-placement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-placement.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, HostAccessRole } from '../foundation'\nimport { hostStampedSitePermission, resolveMemberHostPermissions, siteMayNarrow } from './host-permissions'\nimport type { AglynOrgCustomRole } from './org-permissions'\nimport { hostRoleFor, isOrgWideMember } from './organizations'\n\n/*\n * A RESOURCE PLACED ON ONE SITE ANSWERS TO THAT SITE (AGL-4047).\n *\n * The workspace's shared resources carry `visibleTo`, and one placed on exactly\n * one site belongs to it. Where a plugin decides a resource's writes that way,\n * its keys come in pairs: a workspace key, and a site key that follows it for a\n * member of the whole workspace, which a site can narrow and raise\n * (`narrowsPerSite`, `raisesPerSite`), and which a site collaborator holds by\n * their site role. The verdict:\n *\n * - the workspace key admits, unless a site narrows the member on the one site\n * the resource sits on;\n * - else, on that one site, the site key.\n *\n * Placed on every site, on several, or on all sites except some, the workspace key\n * alone: no one site can be asked, and a security rule cannot look through a list\n * of them.\n *\n * The rules ask the same thing in their own words, so these are kept in step with\n * them, placement test included.\n */\n\n/**\n * Where a resource sits: the fields of its document that decide it. A whole\n * document, never `visibleTo` alone, so no caller can answer without the marker.\n */\nexport type ScopePlaced = Readonly<{ visibleTo?: unknown; scopeMode?: unknown; scopeExcept?: unknown }>\n\n/**\n * The one site a resource is placed on, or `null` for every site, several, or\n * none.\n *\n * `null` for a document shared with all sites except some, however few it reaches\n * today. Its list can shrink to one site while it still belongs to the whole\n * workspace, and the next new site joins it, so that one site never comes to\n * answer for it. Read as the rules' `scopePlacement` reads it: either key present\n * is marked, so a stored null or half a marker fails closed.\n */\nexport function oneSitePlacement(placed: ScopePlaced | null | undefined): string | null {\n if (!placed || placed.scopeMode !== undefined || placed.scopeExcept !== undefined) return null\n const { visibleTo } = placed\n if (!Array.isArray(visibleTo) || visibleTo.length !== 1) return null\n const [token] = visibleTo as unknown[]\n const match = typeof token === 'string' ? /^host:([^:/]+)$/.exec(token) : null\n return match ? match[1] : null\n}\n\n/**\n * The verdict for a resource placed as `placed` says: see above. `site` is asked\n * only when the workspace key did not settle it, so a door pays for reading the\n * site only then.\n */\nexport function placementVerdict<T extends boolean | Promise<boolean>>(input: {\n member: Partial<AglynOrgMember> | null | undefined\n placed: ScopePlaced | null | undefined\n workspace: boolean\n site: (hostId: string) => T\n}): boolean | T {\n const hostId = oneSitePlacement(input.placed)\n if (!hostId) return input.workspace\n if (input.workspace && !siteMayNarrow(input.member, hostId)) return true\n return input.site(hostId)\n}\n\n/**\n * The site key as the site's stamp gives it, read as the rules read it:\n * `memberPermissions[uid][key]`, else, on a site the projection has not reached\n * since the key existed, the site role's preset, unless someone decided against\n * this member in a way the stamp would carry: a custom role, or their own\n * workspace key refused. Those wait for the stamp, so nobody refused regains it\n * from `memberRoles`.\n */\nexport function stampedPlacementKey(\n stamps: { memberPermissions?: unknown; memberRoles?: unknown } | null | undefined,\n uid: string,\n key: string,\n preset: Readonly<Partial<Record<HostAccessRole, boolean>>>,\n member: (Partial<AglynOrgMember> & { roleId?: unknown; permissions?: unknown }) | null | undefined,\n workspaceKey: string,\n): boolean {\n const stamp = (stamps?.memberPermissions as Record<string, Record<string, unknown> | undefined> | undefined)?.[uid]?.[key]\n if (typeof stamp === 'boolean') return stamp\n if (member?.roleId != null || (member?.permissions as Record<string, unknown> | undefined)?.[workspaceKey] === false) return false\n return hostStampedSitePermission({ memberRoles: stamps?.memberRoles }, uid, key, preset)\n}\n\n/** The site key from the membership alone, by the function the site's stamp is written from. */\nexport function resolvedPlacementKey(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: string,\n key: string,\n customRole?: AglynOrgCustomRole | null,\n): boolean {\n if (!member || !hostRoleFor(member, hostId)) return false\n return resolveMemberHostPermissions({ member, customRole: customRole ?? null, hostId })[key] === true\n}\n\n/**\n * Whether deleting a resource is out of this member's reach whatever they hold:\n * they do not reach every site, and it is placed on every site, on several, or on\n * all sites except some. It belongs to the whole workspace.\n */\nexport function deleteBeyondReach(\n member: Partial<AglynOrgMember> | null | undefined,\n placed: ScopePlaced | null | undefined,\n): boolean {\n return !isOrgWideMember(member) && oneSitePlacement(placed) === null\n}\n\n/** The refusal for it, which names the reach it takes because no permission decides it. */\nexport function deleteBeyondReachRefusal(label: string): string {\n return `This ${label.toLowerCase()} is shared beyond one site, so deleting it takes access to every site in the workspace.`\n}\n"],"names":["hostStampedSitePermission","resolveMemberHostPermissions","siteMayNarrow","hostRoleFor","isOrgWideMember","oneSitePlacement","placed","scopeMode","undefined","scopeExcept","visibleTo","Array","isArray","length","token","match","exec","placementVerdict","input","hostId","workspace","member","site","stampedPlacementKey","stamps","uid","key","preset","workspaceKey","stamp","memberPermissions","roleId","permissions","memberRoles","resolvedPlacementKey","customRole","deleteBeyondReach","deleteBeyondReachRefusal","label","toLowerCase"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,yBAAyB,EAAEC,4BAA4B,EAAEC,aAAa,QAAQ,wBAAoB;AAE3G,SAASC,WAAW,EAAEC,eAAe,QAAQ,qBAAiB;AA8B9D;;;;;;;;;CASC,GACD,OAAO,SAASC,iBAAiBC,MAAsC;IACrE,IAAI,CAACA,UAAUA,OAAOC,SAAS,KAAKC,aAAaF,OAAOG,WAAW,KAAKD,WAAW,OAAO;IAC1F,MAAM,EAAEE,SAAS,EAAE,GAAGJ;IACtB,IAAI,CAACK,MAAMC,OAAO,CAACF,cAAcA,UAAUG,MAAM,KAAK,GAAG,OAAO;IAChE,MAAM,CAACC,MAAM,GAAGJ;IAChB,MAAMK,QAAQ,OAAOD,UAAU,WAAW,kBAAkBE,IAAI,CAACF,SAAS;IAC1E,OAAOC,QAAQA,KAAK,CAAC,EAAE,GAAG;AAC5B;AAEA;;;;CAIC,GACD,OAAO,SAASE,iBAAuDC,KAKtE;IACC,MAAMC,SAASd,iBAAiBa,MAAMZ,MAAM;IAC5C,IAAI,CAACa,QAAQ,OAAOD,MAAME,SAAS;IACnC,IAAIF,MAAME,SAAS,IAAI,CAAClB,cAAcgB,MAAMG,MAAM,EAAEF,SAAS,OAAO;IACpE,OAAOD,MAAMI,IAAI,CAACH;AACpB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASI,oBACdC,MAAiF,EACjFC,GAAW,EACXC,GAAW,EACXC,MAA0D,EAC1DN,MAAkG,EAClGO,YAAoB;QAEN,+BAACJ,2BAEgBH;IAF/B,MAAMQ,QAASL,2BAAAA,4BAAAA,OAAQM,iBAAiB,sBAA1B,gCAAA,AAACN,yBAA+F,CAACC,IAAI,qBAArG,6BAAuG,CAACC,IAAI;IAC1H,IAAI,OAAOG,UAAU,WAAW,OAAOA;IACvC,IAAIR,CAAAA,0BAAAA,OAAQU,MAAM,KAAI,QAAQ,CAACV,2BAAAA,sBAAAA,OAAQW,WAAW,qBAApB,AAACX,mBAA6D,CAACO,aAAa,MAAK,OAAO,OAAO;IAC7H,OAAO5B,0BAA0B;QAAEiC,WAAW,EAAET,0BAAAA,OAAQS,WAAW;IAAC,GAAGR,KAAKC,KAAKC;AACnF;AAEA,8FAA8F,GAC9F,OAAO,SAASO,qBACdb,MAAkD,EAClDF,MAAc,EACdO,GAAW,EACXS,UAAsC;IAEtC,IAAI,CAACd,UAAU,CAAClB,YAAYkB,QAAQF,SAAS,OAAO;IACpD,OAAOlB,6BAA6B;QAAEoB;QAAQc,UAAU,EAAEA,qBAAAA,aAAc;QAAMhB;IAAO,EAAE,CAACO,IAAI,KAAK;AACnG;AAEA;;;;CAIC,GACD,OAAO,SAASU,kBACdf,MAAkD,EAClDf,MAAsC;IAEtC,OAAO,CAACF,gBAAgBiB,WAAWhB,iBAAiBC,YAAY;AAClE;AAEA,yFAAyF,GACzF,OAAO,SAAS+B,yBAAyBC,KAAa;IACpD,OAAO,CAAC,KAAK,EAAEA,MAAMC,WAAW,GAAG,uFAAuF,CAAC;AAC7H"}
|
|
@@ -98,6 +98,13 @@ export interface TransferAccessTarget {
|
|
|
98
98
|
scope: TransferLaunchScope;
|
|
99
99
|
/** The site, for a `host` resource or a workspace resource read through one site. */
|
|
100
100
|
hostId?: string | null;
|
|
101
|
+
/**
|
|
102
|
+
* The surface's own verdict on importing into this instance (AGL-4047), for
|
|
103
|
+
* a resource whose server half answers `importAccess`, in place of "Manage
|
|
104
|
+
* data" on the workspace. The plan is still asked. The routes stay the
|
|
105
|
+
* enforcement.
|
|
106
|
+
*/
|
|
107
|
+
importAllowed?: boolean;
|
|
101
108
|
}
|
|
102
109
|
/**
|
|
103
110
|
* An import the person started and left before it wrote anything
|
|
@@ -117,9 +124,18 @@ export interface TransferLauncher {
|
|
|
117
124
|
* permissions have answered. Importing needs "Manage data" (on the named
|
|
118
125
|
* site, for a site's records); exporting needs only access to the
|
|
119
126
|
* records — membership, and reaching the named site — unless the resource
|
|
120
|
-
* declares a `readPermission
|
|
127
|
+
* declares a `readPermission`, or the target carries the resource's own
|
|
128
|
+
* `importAllowed`. The routes stay the enforcement.
|
|
121
129
|
*/
|
|
122
130
|
can(action: TransferAction, target: TransferAccessTarget): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* The permission to name beside a switched-off Import or Export (AGL-4047),
|
|
133
|
+
* once it is known to be a permission that refuses them. `null` when `can`
|
|
134
|
+
* says yes, while its reads are out or failed, and for what no permission
|
|
135
|
+
* decides: the plan, which a surface has its own words for, or a site the
|
|
136
|
+
* person does not reach.
|
|
137
|
+
*/
|
|
138
|
+
refusedPermission?(action: TransferAction, target: TransferAccessTarget): string | null;
|
|
123
139
|
/**
|
|
124
140
|
* The person's own unfinished imports (AGL-3549), newest first: of the
|
|
125
141
|
* target's resource — the exact key, so one dataset's are not another's —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/transfer-launcher-context.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 { createContext, useContext } from 'react'\nimport type { TransferUnfinishedImportSummary } from '../data-transfer/transfer-api'\n\n/**\n * The console shell's import wizard and export dialog, for a plugin to open.\n *\n * The wizard and the dialog are the console's private UI kit, which a\n * published plugin cannot depend on. So the shell hands down a launcher\n * through this context, and a plugin's list or hub opens the wizard for its\n * own resource — the key it declared in `transferResources` — with\n * `useTransferLauncher()?.openImport({ resource, scope })`.\n *\n * Outside the console shell — a spec, a tenant page, a surface mounted by\n * something else — the context holds `null`, and a plugin hides its Import\n * and Export actions: with no shell there is no workspace to move data into.\n *\n * Inside it, `can('import' | 'export', target)` says which of the two this\n * person may use (AGL-3546): a plugin shows Import only when `can('import')`\n * and Export only when `can('export')`. The transfer routes stay the\n * enforcement; `can` answers what they would.\n *\n * Only types and a context: it names no resource, imports nothing from the\n * transfer core, and so costs the barrel nothing past React.\n *\n * A client-only context like the others in `contexts.ts`: it calls\n * `createContext` at module scope, so it is reachable from the full\n * `@aglyn/aglyn` barrel (and this subpath) and never from\n * `@aglyn/aglyn/server` (AGL-405).\n */\n\n/** Where the records live: the workspace, or one of its sites. */\nexport type TransferLaunchScope = 'org' | 'host'\n\n/** Opens the import wizard on one resource. */\nexport interface TransferImportLaunch {\n /**\n * The resource key the plugin declared in `transferResources` — for one\n * declared with `instances`, the key naming the instance\n * (`data.dataset:<datasetId>`).\n */\n resource: string\n scope: TransferLaunchScope\n /** The wizard's title, naming the instance (\"Import into Products\"); \"Import <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** Resume this import instead of starting a new one. */\n jobId?: string | null\n /**\n * What the file is imported as, as the `importMapping` zone's widgets know\n * it (`contacts`); omitted, the mapping step shows no zone.\n */\n mappingZone?: string\n /** Called when the person leaves the wizard from its results with Done. */\n onFinished?(): void\n}\n\n/** Opens the export dialog on one resource. */\nexport interface TransferExportLaunch {\n /** The resource key the plugin declared in `transferResources`, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The dialog's title, naming the instance (\"Export Products\"); \"Export <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** The record ids the person selected in the list, when there is a selection. */\n selection?: readonly string[]\n /** The list's current filter: a name for it, and the value the resource's `readPage` reads. */\n filter?: { label: string; value: unknown }\n /**\n * One of the resource's own presets to open on (`TransferResourcePreset.id`)\n * — a list's \"Export for Pirate Ship\" — instead of the person's last\n * choice. An id the resource does not offer is ignored.\n */\n preset?: string\n}\n\n/** What a person may do with a resource's records. */\nexport type TransferAction = 'import' | 'export'\n\n/** The resource a list asks {@link TransferLauncher.can} about. */\nexport interface TransferAccessTarget {\n /** The resource key, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The site, for a `host` resource or a workspace resource read through one site. */\n hostId?: string | null\n}\n\n/**\n * An import the person started and left before it wrote anything\n * (AGL-3549) — a tab closed mid-wizard — which `openImport({ jobId })`\n * reopens on the step it was left at.\n */\nexport type TransferUnfinishedImport = TransferUnfinishedImportSummary\n\n/** What the shell offers: open the wizard or the dialog, or close whichever is open. */\nexport interface TransferLauncher {\n openImport(launch: TransferImportLaunch): void\n openExport(launch: TransferExportLaunch): void\n close(): void\n /**\n * Whether the person may `action` the target's records (AGL-3546) — the\n * answer the transfer routes give, from the permissions the shell already\n * holds: synchronous, with no request per button, and `false` until those\n * permissions have answered. Importing needs \"Manage data\" (on the named\n * site, for a site's records); exporting needs only access to the\n * records — membership, and reaching the named site — unless the resource\n * declares a `readPermission`. The routes stay the enforcement.\n */\n can(action: TransferAction, target: TransferAccessTarget): boolean\n /**\n * The person's own unfinished imports (AGL-3549), newest first: of the\n * target's resource — the exact key, so one dataset's are not another's —\n * on the target's site when it names one, when a target is given; every\n * one otherwise. Empty\n * until the shell has read them; the first ask starts the read, and the\n * list is read again whenever the wizard closes. Only for a person who may\n * import into the workspace.\n */\n unfinished?(target?: TransferAccessTarget): readonly TransferUnfinishedImport[]\n /**\n * Throws an unfinished import away now — its job, its file and its saved\n * choices — instead of leaving it to expire. Refused for an import that\n * has written anything, which is undone instead.\n */\n discard?(jobId: string): Promise<void>\n}\n\nexport const TransferLauncherContext = createContext<TransferLauncher | null>(null)\nTransferLauncherContext.displayName = 'TransferLauncherContext'\n\n/** The shell's launcher, or `null` outside the console shell. */\nexport function useTransferLauncher(): TransferLauncher | null {\n return useContext(TransferLauncherContext)\n}\n\n"],"names":["createContext","useContext","TransferLauncherContext","displayName","useTransferLauncher"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAO;
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/transfer-launcher-context.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 { createContext, useContext } from 'react'\nimport type { TransferUnfinishedImportSummary } from '../data-transfer/transfer-api'\n\n/**\n * The console shell's import wizard and export dialog, for a plugin to open.\n *\n * The wizard and the dialog are the console's private UI kit, which a\n * published plugin cannot depend on. So the shell hands down a launcher\n * through this context, and a plugin's list or hub opens the wizard for its\n * own resource — the key it declared in `transferResources` — with\n * `useTransferLauncher()?.openImport({ resource, scope })`.\n *\n * Outside the console shell — a spec, a tenant page, a surface mounted by\n * something else — the context holds `null`, and a plugin hides its Import\n * and Export actions: with no shell there is no workspace to move data into.\n *\n * Inside it, `can('import' | 'export', target)` says which of the two this\n * person may use (AGL-3546): a plugin shows Import only when `can('import')`\n * and Export only when `can('export')`. The transfer routes stay the\n * enforcement; `can` answers what they would.\n *\n * Only types and a context: it names no resource, imports nothing from the\n * transfer core, and so costs the barrel nothing past React.\n *\n * A client-only context like the others in `contexts.ts`: it calls\n * `createContext` at module scope, so it is reachable from the full\n * `@aglyn/aglyn` barrel (and this subpath) and never from\n * `@aglyn/aglyn/server` (AGL-405).\n */\n\n/** Where the records live: the workspace, or one of its sites. */\nexport type TransferLaunchScope = 'org' | 'host'\n\n/** Opens the import wizard on one resource. */\nexport interface TransferImportLaunch {\n /**\n * The resource key the plugin declared in `transferResources` — for one\n * declared with `instances`, the key naming the instance\n * (`data.dataset:<datasetId>`).\n */\n resource: string\n scope: TransferLaunchScope\n /** The wizard's title, naming the instance (\"Import into Products\"); \"Import <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** Resume this import instead of starting a new one. */\n jobId?: string | null\n /**\n * What the file is imported as, as the `importMapping` zone's widgets know\n * it (`contacts`); omitted, the mapping step shows no zone.\n */\n mappingZone?: string\n /** Called when the person leaves the wizard from its results with Done. */\n onFinished?(): void\n}\n\n/** Opens the export dialog on one resource. */\nexport interface TransferExportLaunch {\n /** The resource key the plugin declared in `transferResources`, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The dialog's title, naming the instance (\"Export Products\"); \"Export <resource label>\" when absent. */\n title?: string\n /** The site, for a `host` resource. */\n hostId?: string | null\n /** The record ids the person selected in the list, when there is a selection. */\n selection?: readonly string[]\n /** The list's current filter: a name for it, and the value the resource's `readPage` reads. */\n filter?: { label: string; value: unknown }\n /**\n * One of the resource's own presets to open on (`TransferResourcePreset.id`)\n * — a list's \"Export for Pirate Ship\" — instead of the person's last\n * choice. An id the resource does not offer is ignored.\n */\n preset?: string\n}\n\n/** What a person may do with a resource's records. */\nexport type TransferAction = 'import' | 'export'\n\n/** The resource a list asks {@link TransferLauncher.can} about. */\nexport interface TransferAccessTarget {\n /** The resource key, naming the instance for one declared with `instances`. */\n resource: string\n scope: TransferLaunchScope\n /** The site, for a `host` resource or a workspace resource read through one site. */\n hostId?: string | null\n /**\n * The surface's own verdict on importing into this instance (AGL-4047), for\n * a resource whose server half answers `importAccess`, in place of \"Manage\n * data\" on the workspace. The plan is still asked. The routes stay the\n * enforcement.\n */\n importAllowed?: boolean\n}\n\n/**\n * An import the person started and left before it wrote anything\n * (AGL-3549) — a tab closed mid-wizard — which `openImport({ jobId })`\n * reopens on the step it was left at.\n */\nexport type TransferUnfinishedImport = TransferUnfinishedImportSummary\n\n/** What the shell offers: open the wizard or the dialog, or close whichever is open. */\nexport interface TransferLauncher {\n openImport(launch: TransferImportLaunch): void\n openExport(launch: TransferExportLaunch): void\n close(): void\n /**\n * Whether the person may `action` the target's records (AGL-3546) — the\n * answer the transfer routes give, from the permissions the shell already\n * holds: synchronous, with no request per button, and `false` until those\n * permissions have answered. Importing needs \"Manage data\" (on the named\n * site, for a site's records); exporting needs only access to the\n * records — membership, and reaching the named site — unless the resource\n * declares a `readPermission`, or the target carries the resource's own\n * `importAllowed`. The routes stay the enforcement.\n */\n can(action: TransferAction, target: TransferAccessTarget): boolean\n /**\n * The permission to name beside a switched-off Import or Export (AGL-4047),\n * once it is known to be a permission that refuses them. `null` when `can`\n * says yes, while its reads are out or failed, and for what no permission\n * decides: the plan, which a surface has its own words for, or a site the\n * person does not reach.\n */\n refusedPermission?(action: TransferAction, target: TransferAccessTarget): string | null\n /**\n * The person's own unfinished imports (AGL-3549), newest first: of the\n * target's resource — the exact key, so one dataset's are not another's —\n * on the target's site when it names one, when a target is given; every\n * one otherwise. Empty\n * until the shell has read them; the first ask starts the read, and the\n * list is read again whenever the wizard closes. Only for a person who may\n * import into the workspace.\n */\n unfinished?(target?: TransferAccessTarget): readonly TransferUnfinishedImport[]\n /**\n * Throws an unfinished import away now — its job, its file and its saved\n * choices — instead of leaving it to expire. Refused for an import that\n * has written anything, which is undone instead.\n */\n discard?(jobId: string): Promise<void>\n}\n\nexport const TransferLauncherContext = createContext<TransferLauncher | null>(null)\nTransferLauncherContext.displayName = 'TransferLauncherContext'\n\n/** The shell's launcher, or `null` outside the console shell. */\nexport function useTransferLauncher(): TransferLauncher | null {\n return useContext(TransferLauncherContext)\n}\n\n"],"names":["createContext","useContext","TransferLauncherContext","displayName","useTransferLauncher"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,EAAEC,UAAU,QAAQ,QAAO;AAkJjD,OAAO,MAAMC,0BAA0BF,cAAuC,MAAK;AACnFE,wBAAwBC,WAAW,GAAG;AAEtC,+DAA+D,GAC/D,OAAO,SAASC;IACd,OAAOH,WAAWC;AACpB"}
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import type {
|
|
17
|
+
import type { TransferResourceDescriptor } from './resource';
|
|
18
18
|
import { type TransferApiRoute, type TransferPlanRequiredResponse } from './transfer-api';
|
|
19
19
|
/** What a resource declares about who may read and import its records. */
|
|
20
|
-
export type TransferReadDeclaration = Pick<TransferResourceDescriptor, 'readPermission' | 'readableByMembers' | '
|
|
20
|
+
export type TransferReadDeclaration = Pick<TransferResourceDescriptor, 'readPermission' | 'readPermissionOnly' | 'readableByMembers' | 'importPermission'>;
|
|
21
21
|
/** What a resource declares about the plan that moves its records. */
|
|
22
22
|
export type TransferPlanDeclaration = Pick<TransferResourceDescriptor, 'featureFlag' | 'featureFlagExempt'>;
|
|
23
23
|
/** What a member is doing with a resource's records. */
|
|
@@ -40,29 +40,21 @@ export interface TransferMemberAxis {
|
|
|
40
40
|
holds(permission: string): boolean;
|
|
41
41
|
/** Whether the member reaches the named site; `true` when none is named or the member is org-wide. */
|
|
42
42
|
reachesSite: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* The member's role where the records are — on the named site
|
|
45
|
-
* (`hostRoleFor`), or on the workspace (`transferWorkspaceRole`) — for a
|
|
46
|
-
* resource that names `importRoles`; `null` for none.
|
|
47
|
-
*/
|
|
48
|
-
role?: TransferImportRole | null;
|
|
49
43
|
}
|
|
50
44
|
/** Whether a member may `intent` a resource's records: see the block above. */
|
|
51
45
|
export declare function transferAccessAllowed(intent: TransferAccessIntent, descriptor: TransferReadDeclaration | null | undefined, axis: TransferMemberAxis): boolean;
|
|
52
46
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
47
|
+
* The permission to name when a member may not `intent` the records, or `null`
|
|
48
|
+
* when their permissions are not what refuses them: they hold what it takes, or
|
|
49
|
+
* they do not reach the site, which no key decides. Asked in the gate's order.
|
|
56
50
|
*/
|
|
57
|
-
export declare function
|
|
51
|
+
export declare function transferMissingPermission(intent: TransferAccessIntent, descriptor: TransferReadDeclaration | null | undefined, axis: TransferMemberAxis): string | null;
|
|
58
52
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
53
|
+
* The key a member must also hold to `intent` the records, on top of
|
|
54
|
+
* `data.manage` (AGL-4047): the resource's `importPermission` for an import,
|
|
55
|
+
* and nothing for an export or a resource that names none.
|
|
62
56
|
*/
|
|
63
|
-
export declare function
|
|
64
|
-
/** The sentence refusing a member whose role is not among the resource's `importRoles`. */
|
|
65
|
-
export declare function transferImportRoleRefusal(descriptor: Pick<TransferResourceDescriptor, 'importRoles' | 'label' | 'scope'>): string;
|
|
57
|
+
export declare function transferImportPermission(intent: TransferAccessIntent, descriptor: Pick<TransferResourceDescriptor, 'importPermission'> | null | undefined): string | null;
|
|
66
58
|
/**
|
|
67
59
|
* The plan feature a workspace needs to `intent` a resource's records, or
|
|
68
60
|
* `null` when every plan may — no `featureFlag`, or an intent the resource
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
];
|
|
34
34
|
if ((descriptor == null ? void 0 : descriptor.readableByMembers) === true) return [];
|
|
35
35
|
const read = descriptor == null ? void 0 : (_descriptor_readPermission = descriptor.readPermission) == null ? void 0 : _descriptor_readPermission.trim();
|
|
36
|
+
if (read && (descriptor == null ? void 0 : descriptor.readPermissionOnly) === true) return [
|
|
37
|
+
read
|
|
38
|
+
];
|
|
36
39
|
// Whoever may write the records may read them.
|
|
37
40
|
return read && read !== TRANSFER_MANAGE_PERMISSION ? [
|
|
38
41
|
read,
|
|
@@ -42,38 +45,31 @@
|
|
|
42
45
|
];
|
|
43
46
|
}
|
|
44
47
|
/** Whether a member may `intent` a resource's records: see the block above. */ export function transferAccessAllowed(intent, descriptor, axis) {
|
|
45
|
-
var _axis_role;
|
|
46
48
|
if (!axis.reachesSite) return false;
|
|
47
|
-
|
|
49
|
+
const stricter = transferImportPermission(intent, descriptor);
|
|
50
|
+
if (stricter && !axis.holds(stricter)) return false;
|
|
48
51
|
const needed = transferAccessPermissions(intent, descriptor);
|
|
49
52
|
return !needed.length || needed.some((permission)=>axis.holds(permission));
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*/ export function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
* The permission to name when a member may not `intent` the records, or `null`
|
|
56
|
+
* when their permissions are not what refuses them: they hold what it takes, or
|
|
57
|
+
* they do not reach the site, which no key decides. Asked in the gate's order.
|
|
58
|
+
*/ export function transferMissingPermission(intent, descriptor, axis) {
|
|
59
|
+
if (!axis.reachesSite) return null;
|
|
60
|
+
const needed = transferAccessPermissions(intent, descriptor);
|
|
61
|
+
if (needed.length && !needed.some((permission)=>axis.holds(permission))) return needed[0];
|
|
62
|
+
const stricter = transferImportPermission(intent, descriptor);
|
|
63
|
+
return stricter && !axis.holds(stricter) ? stricter : null;
|
|
59
64
|
}
|
|
60
65
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*/ export function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/** The sentence refusing a member whose role is not among the resource's `importRoles`. */ export function transferImportRoleRefusal(descriptor) {
|
|
69
|
-
var _descriptor_importRoles;
|
|
70
|
-
const roles = (_descriptor_importRoles = descriptor.importRoles) != null ? _descriptor_importRoles : [];
|
|
71
|
-
const what = /^[A-Z][a-z]/.test(descriptor.label) ? descriptor.label.charAt(0).toLowerCase() + descriptor.label.slice(1) : descriptor.label;
|
|
72
|
-
if (roles.length === 1 && roles[0] === 'admin') {
|
|
73
|
-
return descriptor.scope === 'host' ? `Only the workspace’s owners and admins, and the site’s admins, can import ${what}.` : `Only the workspace’s owners and admins can import ${what}.`;
|
|
74
|
-
}
|
|
75
|
-
const named = roles.map((role)=>role.charAt(0).toUpperCase() + role.slice(1)).join(', ');
|
|
76
|
-
return `Importing ${what} needs one of these roles${descriptor.scope === 'host' ? ' on the site' : ''}: ${named}.`;
|
|
66
|
+
* The key a member must also hold to `intent` the records, on top of
|
|
67
|
+
* `data.manage` (AGL-4047): the resource's `importPermission` for an import,
|
|
68
|
+
* and nothing for an export or a resource that names none.
|
|
69
|
+
*/ export function transferImportPermission(intent, descriptor) {
|
|
70
|
+
var _descriptor_importPermission;
|
|
71
|
+
const key = descriptor == null ? void 0 : (_descriptor_importPermission = descriptor.importPermission) == null ? void 0 : _descriptor_importPermission.trim();
|
|
72
|
+
return intent === 'import' && key ? key : null;
|
|
77
73
|
}
|
|
78
74
|
/**
|
|
79
75
|
* The plan feature a workspace needs to `intent` a resource's records, or
|