@aglyn/aglyn 1.11.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/account-preferences.d.ts +15 -13
  3. package/src/lib/app-utils/account-preferences.js +20 -20
  4. package/src/lib/app-utils/account-preferences.js.map +1 -1
  5. package/src/lib/app-utils/crm.d.ts +3 -1
  6. package/src/lib/app-utils/crm.js +6 -3
  7. package/src/lib/app-utils/crm.js.map +1 -1
  8. package/src/lib/app-utils/docs-help-sections.generated.js +10 -4
  9. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  10. package/src/lib/app-utils/docs-help.generated.d.ts +2 -2
  11. package/src/lib/app-utils/docs-help.generated.js +8 -0
  12. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  13. package/src/lib/app-utils/docs-index.generated.js +117 -96
  14. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  15. package/src/lib/app-utils/host-permissions.d.ts +12 -0
  16. package/src/lib/app-utils/host-permissions.js +26 -1
  17. package/src/lib/app-utils/host-permissions.js.map +1 -1
  18. package/src/lib/app-utils/markdown-lite.js +8 -1
  19. package/src/lib/app-utils/markdown-lite.js.map +1 -1
  20. package/src/lib/app-utils/media-asset-facts.d.ts +2 -2
  21. package/src/lib/app-utils/media-asset-facts.js +4 -3
  22. package/src/lib/app-utils/media-asset-facts.js.map +1 -1
  23. package/src/lib/app-utils/media-cdn-scope.d.ts +19 -4
  24. package/src/lib/app-utils/media-cdn-scope.js +19 -5
  25. package/src/lib/app-utils/media-cdn-scope.js.map +1 -1
  26. package/src/lib/app-utils/media-ref.d.ts +10 -6
  27. package/src/lib/app-utils/media-ref.js +34 -8
  28. package/src/lib/app-utils/media-ref.js.map +1 -1
  29. package/src/lib/app-utils/org-permissions.d.ts +7 -0
  30. package/src/lib/app-utils/org-permissions.js +2 -0
  31. package/src/lib/app-utils/org-permissions.js.map +1 -1
  32. package/src/lib/app-utils/org-role-grants.d.ts +13 -0
  33. package/src/lib/app-utils/org-role-grants.js +9 -5
  34. package/src/lib/app-utils/org-role-grants.js.map +1 -1
  35. package/src/lib/app-utils/person-erasure.d.ts +8 -0
  36. package/src/lib/app-utils/person-erasure.js +6 -0
  37. package/src/lib/app-utils/person-erasure.js.map +1 -1
  38. package/src/lib/app-utils/scope-tokens.d.ts +132 -3
  39. package/src/lib/app-utils/scope-tokens.js +276 -3
  40. package/src/lib/app-utils/scope-tokens.js.map +1 -1
  41. package/src/lib/app-utils/site-placement.d.ts +56 -0
  42. package/src/lib/app-utils/site-placement.js +88 -0
  43. package/src/lib/app-utils/site-placement.js.map +1 -0
  44. package/src/lib/app-utils/site-preview.d.ts +6 -2
  45. package/src/lib/app-utils/site-preview.js +5 -3
  46. package/src/lib/app-utils/site-preview.js.map +1 -1
  47. package/src/lib/app-utils/site-unavailable.d.ts +4 -7
  48. package/src/lib/app-utils/site-unavailable.js +4 -8
  49. package/src/lib/app-utils/site-unavailable.js.map +1 -1
  50. package/src/lib/app-utils/transfer-launcher-context.d.ts +17 -1
  51. package/src/lib/app-utils/transfer-launcher-context.js.map +1 -1
  52. package/src/lib/data-transfer/access.d.ts +10 -18
  53. package/src/lib/data-transfer/access.js +21 -25
  54. package/src/lib/data-transfer/access.js.map +1 -1
  55. package/src/lib/data-transfer/resource.d.ts +13 -14
  56. package/src/lib/data-transfer/resource.js +9 -10
  57. package/src/lib/data-transfer/resource.js.map +1 -1
  58. package/src/lib/foundation/definitions/org-billing.types.js +2 -2
  59. package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
  60. package/src/lib/foundation/definitions/platform.types.d.ts +1 -1
  61. package/src/lib/foundation/definitions/platform.types.js.map +1 -1
  62. package/src/lib/foundation/definitions/write-deny-coverage.util.d.ts +1 -1
  63. package/src/lib/foundation/definitions/write-deny-coverage.util.js +1 -1
  64. package/src/lib/foundation/definitions/write-deny-coverage.util.js.map +1 -1
  65. package/src/lib/plugin-manager/first-party-plugins.generated.js +4 -5
  66. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  67. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +18 -0
  68. package/src/lib/plugin-manager/plugin-contact-capture.js +26 -0
  69. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
  70. package/src/lib/plugin-manager/plugin-entitlements.d.ts +12 -0
  71. package/src/lib/plugin-manager/plugin-entitlements.js +3 -1
  72. package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
  73. package/src/lib/plugin-manager/plugin-person-erasure-notes.d.ts +61 -0
  74. package/src/lib/plugin-manager/plugin-person-erasure-notes.js +114 -0
  75. package/src/lib/plugin-manager/plugin-person-erasure-notes.js.map +1 -0
  76. package/src/lib/plugin-manager/plugin-scope-sharing.d.ts +52 -0
  77. package/src/lib/plugin-manager/plugin-scope-sharing.generated.d.ts +10 -0
  78. package/src/lib/plugin-manager/plugin-scope-sharing.generated.js +82 -0
  79. package/src/lib/plugin-manager/plugin-scope-sharing.generated.js.map +1 -0
  80. package/src/lib/plugin-manager/plugin-scope-sharing.js +85 -0
  81. package/src/lib/plugin-manager/plugin-scope-sharing.js.map +1 -0
  82. package/src/lib/plugin-manager/plugin-site-starters.d.ts +7 -0
  83. package/src/lib/plugin-manager/plugin-site-starters.js.map +1 -1
  84. package/src/lib/plugin-manager/plugin-transfer-resources.d.ts +56 -1
  85. package/src/lib/plugin-manager/plugin-transfer-resources.js +13 -0
  86. package/src/lib/plugin-manager/plugin-transfer-resources.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/media-asset-facts.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * What a placed library asset is NOW, read from its DAM document when the\n * page is composed rather than copied onto the node when it was picked: a\n * film's length, shape and poster (AGL-2807), and an image's pixel pair\n * (AGL-2833).\n *\n * ## Why the pick-time copy is not enough\n *\n * Picking a library asset copies facts onto the node. An image gets its pixel\n * pair ({@link intrinsicMediaSize}), which `image.tsx` renders as the\n * `<img>`'s `width`/`height` attributes so the browser can reserve the box\n * before the bytes arrive. A film gets its running time, its frame's pair and\n * a poster flag ({@link videoMediaProps}): the pair becomes the player's CSS\n * `aspect-ratio`, the running time becomes `VideoObject.duration`, and the\n * flag decides whether a lightbox `<img>` and a `thumbnailUrl` exist at all.\n *\n * A replace (AGL-2732) keeps the asset's id and URL and rewrites its document:\n * an image's `width`/`height`, a film's `video` and `poster` records. It\n * cannot rewrite the nodes, which sit in every screen, layout, component and\n * published version that places the asset. So after a replace with a\n * different shape, every page placing the image reserved the previous\n * picture's box and shifted when the new one decoded, and every page placing\n * the film kept the previous film's length and shape, until someone re-picked\n * it.\n *\n * ## The rule\n *\n * Two surfaces read each placed asset's document and lay what it records over\n * the node here: the tenant's composition, for the page a visitor gets\n * (`libs/tenant/runtime/src/lib/get-media-asset-facts.ts`), and the console,\n * for the besigner canvas an author edits and the Preview that checks it\n * (AGL-2838, AGL-2849). Both decide what a read answers through\n * {@link mediaAssetFactsFromDocument}, so the editor cannot disagree with the\n * page about which assets answer. When the asset cannot be answered for (a\n * failed or pending read, a missing or deleted document, an asset the CDN\n * would not serve under this page's URL, one past the composition's cap), the\n * node keeps what the pick stored. That is the render every page had before\n * this, never a worse one. When the asset answers:\n *\n * - **A film's facts win, including their ABSENCE.** A film the replace left\n * with no `video` record has no known shape, so a stored pair describing\n * the previous film is dropped rather than published, and a poster flag the\n * document no longer backs is dropped with it. One stored value survives: a\n * running time the AUTHOR typed for a film the DAM has no running time for.\n * The pick only ever writes the duration together with the pixel pair\n * ({@link videoMediaProps} is all-or-nothing on the `video` record), and the\n * pair is not an author control. So a duration standing alone is an\n * author's, and a duration standing beside a pair is a copy of a film that\n * may no longer be the one in the bucket.\n * - **An image's pair wins when the document records one.** When it records\n * none (an SVG, which the upload cannot measure, or a file older than\n * AGL-173), the stored pair stays, whether an author typed it through the\n * API or it is a copy of the file the asset held before. The asymmetry with\n * a film is in the render, not the data. A film's pair is the player's\n * permanent box, but an image's is only a reservation\n * (`aspect-ratio: auto w / h`), which the decoded picture's own ratio\n * replaces. Dropping the pair guarantees a shift of the image's full height\n * on every view. A stale pair shifts by the difference between two heights,\n * and a pair typed for a file the DAM cannot measure shifts by nothing.\n *\n * Nothing an author sets for the placement is touched: an image's CSS\n * `width` and `height`, its fit and radius, and a film's own poster describe\n * the placement rather than the file.\n *\n * Imported by path and never through a barrel: every `@aglyn/aglyn` barrel\n * ships to published pages, and nothing here has a reason to reach one, so\n * the composition and the console both import this module by path.\n */\n\nimport { CANVAS_ROOT_ELEMENT_ID } from '../foundation/constants/canvas'\nimport { mediaCdnScopeRefusal, parseMediaCdnScope } from './media-cdn-scope'\nimport { intrinsicMediaSize, videoMediaProps } from './media-metadata'\nimport {\n hostQualifiedScope,\n isMediaCdnPath,\n mediaCdnVersionToken,\n type MediaRef,\n mediaRefFromCdnPath,\n parseMediaRef,\n} from './media-ref'\nimport { VIDEO_COMPONENT_ID } from './video-object'\n\n/** The Image element's persisted component id (`image.tsx`), never renamed. */\nexport const IMAGE_COMPONENT_ID = 'image'\n\n/**\n * The prop each element that holds a markdown-lite DOCUMENT keeps it in, and\n * therefore every element whose body can name a library image (AGL-3149).\n *\n * The same two elements and the same two prop names `resolveMarkdownSource`\n * walks for a table of contents (AGL-1162), which is the other reader of a\n * body's contents. They differ: the Markdown element calls it `content` and a\n * collection entry's body calls it `markdown`.\n *\n * Both ids are spelled out rather than imported. `markdown` belongs to a\n * plugin, which core may never import; `collectionEntryBody` is exported by\n * `collection-entries.ts`, but that module is 1,860 lines and drags\n * `content-authors.ts` behind it, and this one is deliberately outside the\n * barrel that ships to published pages. A persisted component id is a string\n * that cannot change — renaming one orphans every document that stores it —\n * so the copy cannot drift in the way an imported value would protect against.\n */\nconst MARKDOWN_BODY_PROPS: Readonly<Record<string, string>> = {\n markdown: 'content',\n collectionEntryBody: 'markdown',\n}\n\n/** The root of a composed map, where a walk in document order starts. */\nconst ROOT_NODE_ID: string = CANVAS_ROOT_ELEMENT_ID\n\n/**\n * What a readable asset's media document records, as the overlay consumes it.\n *\n * Raw on purpose: {@link intrinsicMediaSize} and {@link videoMediaProps} are\n * where a pair and a `video` record are bounded, and a second reading of the\n * same numbers here is how two files come to disagree about what a partial\n * record means.\n */\nexport interface MediaAssetFacts {\n /** The document's `width`: an image's, read from its bytes at upload. */\n width?: unknown\n /** The document's `height`, the other half of {@link width}. */\n height?: unknown\n /** The document's `video` record: `durationMs`, `width` and `height`. */\n video?: unknown\n /** The document's generated `poster` record, when it has one. */\n poster?: unknown\n /**\n * The document's `contentHash`, which a replace changes with the bytes. An\n * image placement carries it as `mediaVersion`, and the URL it renders is\n * then the versioned one the CDN lets every cache keep (AGL-3485).\n */\n contentHash?: unknown\n}\n\n/**\n * Every field an asset's facts are decided from, and the projection a reader\n * asks Firestore for: ONE list, whichever surface reads. `width` and `height`\n * (an image's) and `video` and `poster` (a film's) are the facts. The other\n * three are the gates `serveMediaCdn` applies before it will serve an asset at\n * all, so no surface shows the shape of a file its page's URL refuses.\n */\nexport const MEDIA_ASSET_FACT_FIELDS = [\n 'width',\n 'height',\n 'video',\n 'poster',\n 'contentHash',\n 'deletedAt',\n 'private',\n 'visibleTo',\n] as const\n\n/** An asset's media document, as far as {@link MEDIA_ASSET_FACT_FIELDS} reach. */\nexport type MediaAssetDocument = Partial<\n Record<(typeof MEDIA_ASSET_FACT_FIELDS)[number], unknown>\n>\n\n/** The elements whose placements follow their file. */\nexport type MediaAssetElement =\n | typeof IMAGE_COMPONENT_ID\n | typeof VIDEO_COMPONENT_ID\n\nexport interface MediaAssetFactsOptions {\n /**\n * One element's placements only, by persisted component id. Absent means\n * both, which is what the composition asks for.\n */\n only?: MediaAssetElement\n}\n\n/** A node as the composed map holds it: flat, children by id. */\ninterface ComposedMediaNode {\n componentId?: string\n nodes?: unknown\n props?: Record<string, unknown>\n resolvedProps?: Record<string, unknown>\n}\n\nconst owns = (map: object, key: string) =>\n Object.prototype.hasOwnProperty.call(map, key)\n\n/**\n * The key an asset's facts are filed under: the reference's own scope and id.\n *\n * Deliberately NOT the host-qualified scope a page renders. The document lives\n * under the scope's owner whichever site places it, and which site may be\n * shown it is the reader's question, answered once per page.\n */\nexport function mediaAssetFactsKey(\n ref: Pick<MediaRef, 'scope' | 'mediaId'>,\n): string {\n return `${ref.scope}/${ref.mediaId}`\n}\n\n/**\n * Where an asset's media document lives: under the scope's OWNER, `orgs/` for\n * the org library and `hosts/` for a site's own, whichever site places it.\n * `null` for a scope the CDN would not parse, which no read can answer for.\n */\nexport function mediaAssetDocumentPath(\n ref: Pick<MediaRef, 'scope' | 'mediaId'>,\n): string | null {\n const scope = parseMediaCdnScope(ref.scope)\n if (!scope) return null\n return `${scope.isOrg ? 'orgs' : 'hosts'}/${scope.scopeId}/media/${ref.mediaId}`\n}\n\n/**\n * The facts one read of an asset's document yields for a placement rendered\n * on `hostId`'s pages, or `undefined` when the placement keeps its stored\n * props.\n *\n * An answer exists only for a document that was read, is live, is not\n * private, and is visible to that site under the host-qualified scope the page\n * renders: the verdict the CDN reaches when the browser asks for the bytes.\n * The URL a page renders names the site doing the rendering\n * (`resolveMediaSrc`), so visibility is asked of THAT scope, not of the scope\n * the reference was stored with.\n */\nexport function mediaAssetFactsFromDocument(\n document: MediaAssetDocument | null | undefined,\n ref: Pick<MediaRef, 'scope'>,\n hostId: string,\n): MediaAssetFacts | undefined {\n if (!document) return undefined\n if (document.deletedAt || document.private === true) return undefined\n const served = parseMediaCdnScope(hostQualifiedScope(ref.scope, hostId))\n if (!served || mediaCdnScopeRefusal(served, document.visibleTo)) {\n return undefined\n }\n return {\n width: document.width,\n height: document.height,\n video: document.video,\n poster: document.poster,\n contentHash: document.contentHash,\n }\n}\n\n/** The library asset an Image or Video node places, or null for anything else. */\nfunction placedAsset(\n node: ComposedMediaNode | null | undefined,\n only?: MediaAssetElement,\n): MediaRef | null {\n const componentId = node?.componentId\n if (componentId !== IMAGE_COMPONENT_ID && componentId !== VIDEO_COMPONENT_ID) {\n return null\n }\n if (only && componentId !== only) return null\n // The precedence every other reader of the composed map uses: a node inside\n // a repeated collection carries its bound values in the resolved copy.\n const props = node?.resolvedProps ?? node?.props\n return placedRef(props?.['src'])\n}\n\n/**\n * The library asset a stored `src` names: a `media:` reference, or the\n * site-relative CDN path the first media picker wrote before references\n * existed (AGL-1215). Both name one asset by its id, and the path's are among\n * the oldest placements on the platform — the ones that most need their file's\n * shape read back, since nothing copied it onto the node when they were made.\n * Only the strict root-relative path: a hotlink on another host that happens\n * to contain our route names nothing of ours.\n */\nfunction placedRef(src: unknown): MediaRef | null {\n if (isMediaCdnPath(src)) return parseMediaRef(mediaRefFromCdnPath(src))\n return parseMediaRef(src)\n}\n\n/** A compose-time token the tenant has not substituted — never a document. */\nconst UNRESOLVED_TOKEN = /^\\{\\{[^}]+\\}\\}$/\n\n/**\n * The markdown-lite document a node holds, or `''` for a node holding none.\n *\n * `resolvedProps` first, for the reason {@link placedAsset} gives: an entry\n * body is the literal `{{entry.body}}` in `props` and the entry's real text in\n * the resolved copy. An unsubstituted token is not a document — it can name no\n * asset — so it is dropped here rather than walked for images that a canvas\n * surface would never find.\n */\nfunction markdownBodyOf(\n props: Record<string, unknown> | undefined,\n componentId: string | undefined,\n): string {\n const prop =\n componentId && owns(MARKDOWN_BODY_PROPS, componentId)\n ? MARKDOWN_BODY_PROPS[componentId]\n : undefined\n const text = prop ? props?.[prop] : undefined\n if (typeof text !== 'string' || UNRESOLVED_TOKEN.test(text.trim())) return ''\n return text\n}\n\n/** See {@link markdownBodyOf} — the body the page will actually render. */\nfunction markdownBody(node: ComposedMediaNode | null | undefined): string {\n return markdownBodyOf(\n node?.resolvedProps ?? node?.props,\n node?.componentId,\n )\n}\n\n/**\n * A markdown-lite image: `![alt](target)`, capturing only the target, and only\n * up to the first whitespace or `)`.\n *\n * That is the whole of the syntax `markdown-lite.ts` accepts — no title string\n * after the target, no angle-bracket form — so there is nowhere else in a body\n * for a reference to hide, and matching more than the parser does would name\n * assets the renderer never asks for.\n */\nconst MARKDOWN_IMAGE_TARGET = /!\\[[^\\]]*\\]\\(\\s*([^)\\s]+)/g\n\n/**\n * Every library asset a markdown body's images name, in the order the body\n * names them, each beside the target EXACTLY as the body wrote it.\n *\n * The raw target is carried because that is the key the renderer has: it holds\n * the parsed block's `src`, the same string, and looking a pair up by it costs\n * no second parse per image on every render.\n *\n * A target that is not a `media:` reference yields nothing — a hotlinked URL\n * and a legacy stored path have no DAM document to read, and the renderer\n * gives those today's markup unchanged.\n */\nfunction markdownImageRefs(\n text: string,\n): Array<{ target: string; ref: MediaRef }> {\n if (!text.includes('![')) return []\n const found: Array<{ target: string; ref: MediaRef }> = []\n for (const match of text.matchAll(MARKDOWN_IMAGE_TARGET)) {\n const target = match[1]\n const ref = parseMediaRef(target)\n if (ref) found.push({ target, ref })\n }\n return found\n}\n\n/**\n * The map's node ids in document order: depth first from the root through\n * each node's child ids, then every id the walk never reached (a map with no\n * root, an orphan) in the order the map lists it. That puts the top of the\n * page ahead of its footer, and it is the same order for the same map.\n */\nfunction documentOrder(nodes: Record<string, unknown>): string[] {\n const order: string[] = []\n const seen = new Set<string>()\n const stack = owns(nodes, ROOT_NODE_ID) ? [ROOT_NODE_ID] : []\n while (stack.length) {\n const id = stack.pop() as string\n if (seen.has(id) || !owns(nodes, id)) continue\n seen.add(id)\n order.push(id)\n const children = (nodes[id] as ComposedMediaNode | null)?.nodes\n if (!Array.isArray(children)) continue\n for (let index = children.length - 1; index >= 0; index -= 1) {\n const child = children[index]\n if (typeof child === 'string' && !seen.has(child)) stack.push(child)\n }\n }\n for (const id in nodes) if (!seen.has(id)) order.push(id)\n return order\n}\n\n/**\n * Every distinct library asset the Image and Video nodes in a map place:\n * films first, then images, each in document order.\n *\n * A read that is capped honors that order. A film goes first because its\n * stale facts are the worse render (a player of the wrong shape and a\n * thumbnail that 404s, against a reservation that corrects itself when an\n * image decodes), and document order covers the top of the page before its\n * footer.\n *\n * `[]` for a page that places none, so a caller that gates its read on the\n * length spends nothing on it. A pinned and an unpinned reference to one\n * asset are one entry: a pin names bytes, not a different asset.\n */\nexport function mediaAssetRefs(\n nodes: Record<string, unknown> | null | undefined,\n options: MediaAssetFactsOptions = {},\n): MediaRef[] {\n const refs: MediaRef[] = []\n if (!nodes) return refs\n const order = documentOrder(nodes)\n const seen = new Set<string>()\n for (const element of [VIDEO_COMPONENT_ID, IMAGE_COMPONENT_ID] as const) {\n if (options.only && options.only !== element) continue\n for (const id of order) {\n const node = nodes[id] as ComposedMediaNode | null\n if (node?.componentId !== element) continue\n const ref = placedAsset(node)\n if (!ref) continue\n const key = mediaAssetFactsKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n refs.push(ref)\n }\n }\n // A markdown body's images come LAST, and only when the caller wants every\n // element (AGL-3149). Last because of what a capped read costs each kind: a\n // placement that misses out renders at its pick-time pair, a body image that\n // misses out renders exactly as it does today, and a film that misses out\n // gets a player of the wrong shape. Only-when-unfiltered because `only` asks\n // for one ELEMENT's placements, and a body image is not a placement of the\n // Image element — the video-asset reader would otherwise read image\n // documents it has no use for.\n if (options.only) return refs\n for (const id of order) {\n const body = markdownBody(nodes[id] as ComposedMediaNode | null)\n for (const { ref } of markdownImageRefs(body)) {\n const key = mediaAssetFactsKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n refs.push(ref)\n }\n }\n return refs\n}\n\nconst usable = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value) && value > 0\n\n/** A film's props with its asset's facts laid over them. See the module note. */\nfunction withFilmFacts(\n props: Record<string, unknown>,\n facts: MediaAssetFacts,\n): Record<string, unknown> {\n const live = videoMediaProps({\n componentId: VIDEO_COMPONENT_ID,\n propName: 'src',\n assetVideo: facts.video,\n assetPoster: facts.poster,\n })\n const {\n durationSeconds,\n intrinsicWidth,\n intrinsicHeight,\n posterFromSource: _storedPosterFlag,\n ...next\n } = props\n // The pick writes a duration only beside the pixel pair, so a pair is what\n // marks the stored duration as a copy rather than an author's own.\n const typedByAuthor = !(usable(intrinsicWidth) && usable(intrinsicHeight))\n if (live.durationSeconds !== undefined) {\n next['durationSeconds'] = live.durationSeconds\n } else if (typedByAuthor && durationSeconds !== undefined) {\n next['durationSeconds'] = durationSeconds\n }\n if (live.intrinsicWidth !== undefined && live.intrinsicHeight !== undefined) {\n next['intrinsicWidth'] = live.intrinsicWidth\n next['intrinsicHeight'] = live.intrinsicHeight\n }\n if (live.posterFromSource) next['posterFromSource'] = true\n return next\n}\n\n/**\n * An image's props with its asset's pair laid over them, or the SAME object\n * when the document records no usable pair or the stored one already matches.\n * See the module note.\n */\nfunction withImageFacts(\n props: Record<string, unknown>,\n facts: MediaAssetFacts,\n): Record<string, unknown> {\n // Through the pick's own gate, so the overlay and the pick agree on what a\n // usable pair is: both halves, finite and positive.\n const live = intrinsicMediaSize({\n componentId: IMAGE_COMPONENT_ID,\n propName: 'src',\n assetWidth: facts.width,\n assetHeight: facts.height,\n })\n const version = mediaVersionOf(facts)\n const pair =\n live.intrinsicWidth !== undefined && live.intrinsicHeight !== undefined\n const pairChanged =\n pair &&\n (props['intrinsicWidth'] !== live.intrinsicWidth ||\n props['intrinsicHeight'] !== live.intrinsicHeight)\n const versionChanged =\n version !== undefined && props[IMAGE_MEDIA_VERSION_PROP] !== version\n if (!pairChanged && !versionChanged) return props\n return {\n ...props,\n ...(pairChanged\n ? {\n intrinsicWidth: live.intrinsicWidth,\n intrinsicHeight: live.intrinsicHeight,\n }\n : {}),\n ...(versionChanged ? { [IMAGE_MEDIA_VERSION_PROP]: version } : {}),\n }\n}\n\n/**\n * The prop an Image placement carries its asset's current content hash in\n * (AGL-3485). Laid on at composition like the pixel pair and never an author\n * control: it describes the file, and `image.tsx` hands it to\n * `resolveMediaSrc` so the page names the versioned URL.\n */\nexport const IMAGE_MEDIA_VERSION_PROP = 'mediaVersion'\n\n/** The document's content hash, when it is one a URL can carry. */\nfunction mediaVersionOf(facts: MediaAssetFacts): string | undefined {\n return mediaCdnVersionToken(facts.contentHash) === undefined\n ? undefined\n : (facts.contentHash as string)\n}\n\n/**\n * The prop a markdown body carries its images' pixel pairs in, keyed by the\n * target the body wrote (AGL-3149).\n *\n * A body image is not a node, so it cannot take `intrinsicWidth` and\n * `intrinsicHeight` the way a placement does; the pairs travel together on the\n * element that holds the document, and the renderer looks each one up by the\n * parsed block's `src`.\n */\nexport const BODY_IMAGE_SIZES_PROP = 'intrinsicSizes'\n\n/** One body image's pair, as {@link BODY_IMAGE_SIZES_PROP} carries it. */\nexport interface BodyImageSize {\n width: number\n height: number\n /** The asset's content hash, for the versioned URL (AGL-3485). */\n version?: string\n}\n\n/**\n * A markdown body's props with a pair for each library image it names, or the\n * SAME object when no image in it can be answered for.\n *\n * Only images whose document records a usable pair get an entry, through the\n * same {@link intrinsicMediaSize} gate a placement goes through. An image left\n * out is one the renderer must give today's markup: `srcSet` without the pair\n * makes `sizes` the image's rendered width, which upscales anything narrower\n * than the column, so a partial answer is worse here than no answer.\n */\nfunction withBodyImageFacts(\n props: Record<string, unknown>,\n componentId: string | undefined,\n facts: ReadonlyMap<string, MediaAssetFacts>,\n): Record<string, unknown> {\n // THIS object's own body, never the node's resolved one: `props` on a bound\n // entry body still holds the `{{entry.body}}` token, and pairs for images it\n // does not name are bytes in the tree that nothing can ever look up.\n let sizes: Record<string, BodyImageSize> | undefined\n for (const { target, ref } of markdownImageRefs(\n markdownBodyOf(props, componentId),\n )) {\n const found = facts.get(mediaAssetFactsKey(ref))\n if (!found) continue\n const live = intrinsicMediaSize({\n componentId: IMAGE_COMPONENT_ID,\n propName: 'src',\n assetWidth: found.width,\n assetHeight: found.height,\n })\n if (\n live.intrinsicWidth === undefined ||\n live.intrinsicHeight === undefined\n ) {\n continue\n }\n if (!sizes) sizes = {}\n const version = mediaVersionOf(found)\n sizes[target] = {\n width: live.intrinsicWidth,\n height: live.intrinsicHeight,\n ...(version ? { version } : {}),\n }\n }\n if (!sizes) return props\n return { ...props, [BODY_IMAGE_SIZES_PROP]: sizes }\n}\n\n/**\n * The composed map with each placed asset's facts laid over its node, and each\n * markdown body's images' pairs laid over the element holding the body.\n *\n * `facts` is keyed by {@link mediaAssetFactsKey}. A placement with no entry,\n * because the reader could not answer for its asset, keeps its stored props.\n * The SAME map comes back when nothing changes, so a page with no library\n * asset pays for one walk and no copy, and the input is never mutated either\n * way.\n */\nexport function applyMediaAssetFacts<T extends Record<string, unknown>>(\n nodes: T,\n facts: ReadonlyMap<string, MediaAssetFacts>,\n options: MediaAssetFactsOptions = {},\n): T {\n if (!facts.size) return nodes\n let applied: Record<string, unknown> | undefined\n const write = (id: string, node: ComposedMediaNode, next: {\n props?: Record<string, unknown>\n resolvedProps?: Record<string, unknown>\n }): void => {\n if (!applied) applied = { ...nodes }\n applied[id] = {\n ...node,\n ...(next.props ? { props: next.props } : {}),\n ...(next.resolvedProps ? { resolvedProps: next.resolvedProps } : {}),\n }\n }\n for (const id in nodes) {\n const node = nodes[id] as ComposedMediaNode\n const ref = placedAsset(node, options.only)\n const found = ref ? facts.get(mediaAssetFactsKey(ref)) : undefined\n if (found) {\n const overlay =\n node.componentId === VIDEO_COMPONENT_ID ? withFilmFacts : withImageFacts\n const props = node.props && overlay(node.props, found)\n const resolvedProps =\n node.resolvedProps && overlay(node.resolvedProps, found)\n if (props === node.props && resolvedProps === node.resolvedProps) continue\n write(id, node, { props, resolvedProps })\n continue\n }\n // A markdown body, under the same `only` rule `mediaAssetRefs` collects\n // under: a body image is not a placement of the Image element, so a reader\n // asking for one element's placements is not asking about bodies.\n if (options.only) continue\n const { componentId } = node\n if (!componentId || !owns(MARKDOWN_BODY_PROPS, componentId)) continue\n const props =\n node.props && withBodyImageFacts(node.props, componentId, facts)\n const resolvedProps =\n node.resolvedProps &&\n withBodyImageFacts(node.resolvedProps, componentId, facts)\n if (props === node.props && resolvedProps === node.resolvedProps) continue\n write(id, node, { props, resolvedProps })\n }\n return applied ? (applied as T) : nodes\n}\n"],"names":["CANVAS_ROOT_ELEMENT_ID","mediaCdnScopeRefusal","parseMediaCdnScope","intrinsicMediaSize","videoMediaProps","hostQualifiedScope","isMediaCdnPath","mediaCdnVersionToken","mediaRefFromCdnPath","parseMediaRef","VIDEO_COMPONENT_ID","IMAGE_COMPONENT_ID","MARKDOWN_BODY_PROPS","markdown","collectionEntryBody","ROOT_NODE_ID","MEDIA_ASSET_FACT_FIELDS","owns","map","key","Object","prototype","hasOwnProperty","call","mediaAssetFactsKey","ref","scope","mediaId","mediaAssetDocumentPath","isOrg","scopeId","mediaAssetFactsFromDocument","document","hostId","undefined","deletedAt","private","served","visibleTo","width","height","video","poster","contentHash","placedAsset","node","only","componentId","props","resolvedProps","placedRef","src","UNRESOLVED_TOKEN","markdownBodyOf","prop","text","test","trim","markdownBody","MARKDOWN_IMAGE_TARGET","markdownImageRefs","includes","found","match","matchAll","target","push","documentOrder","nodes","order","seen","Set","stack","length","id","pop","has","add","children","Array","isArray","index","child","mediaAssetRefs","options","refs","element","body","usable","value","Number","isFinite","withFilmFacts","facts","live","propName","assetVideo","assetPoster","durationSeconds","intrinsicWidth","intrinsicHeight","posterFromSource","_storedPosterFlag","next","typedByAuthor","withImageFacts","assetWidth","assetHeight","version","mediaVersionOf","pair","pairChanged","versionChanged","IMAGE_MEDIA_VERSION_PROP","BODY_IMAGE_SIZES_PROP","withBodyImageFacts","sizes","get","applyMediaAssetFacts","size","applied","write","overlay"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;QAClB,MAAM,EAAEC,WAAW,EAAE,GAAGF;QACxB,IAAI,CAACE,eAAe,CAAC9B,KAAKL,qBAAqBmC,cAAc;QAC7D,MAAMC,QACJH,KAAKG,KAAK,IAAImE,mBAAmBtE,KAAKG,KAAK,EAAED,aAAa8C;QAC5D,MAAM5C,gBACJJ,KAAKI,aAAa,IAClBkE,mBAAmBtE,KAAKI,aAAa,EAAEF,aAAa8C;QACtD,IAAI7C,UAAUH,KAAKG,KAAK,IAAIC,kBAAkBJ,KAAKI,aAAa,EAAE;QAClEwE,MAAM/C,IAAI7B,MAAM;YAAEG;YAAOC;QAAc;IACzC;IACA,OAAOuE,UAAWA,UAAgBpD;AACpC"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/media-asset-facts.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * What a placed library asset is NOW, read from its DAM document when the\n * page is composed rather than copied onto the node when it was picked: a\n * film's length, shape and poster (AGL-2807), and an image's pixel pair\n * (AGL-2833).\n *\n * ## Why the pick-time copy is not enough\n *\n * Picking a library asset copies facts onto the node. An image gets its pixel\n * pair ({@link intrinsicMediaSize}), which `image.tsx` renders as the\n * `<img>`'s `width`/`height` attributes so the browser can reserve the box\n * before the bytes arrive. A film gets its running time, its frame's pair and\n * a poster flag ({@link videoMediaProps}): the pair becomes the player's CSS\n * `aspect-ratio`, the running time becomes `VideoObject.duration`, and the\n * flag decides whether a lightbox `<img>` and a `thumbnailUrl` exist at all.\n *\n * A replace (AGL-2732) keeps the asset's id and URL and rewrites its document:\n * an image's `width`/`height`, a film's `video` and `poster` records. It\n * cannot rewrite the nodes, which sit in every screen, layout, component and\n * published version that places the asset. So after a replace with a\n * different shape, every page placing the image reserved the previous\n * picture's box and shifted when the new one decoded, and every page placing\n * the film kept the previous film's length and shape, until someone re-picked\n * it.\n *\n * ## The rule\n *\n * Two surfaces read each placed asset's document and lay what it records over\n * the node here: the tenant's composition, for the page a visitor gets\n * (`libs/tenant/runtime/src/lib/get-media-asset-facts.ts`), and the console,\n * for the besigner canvas an author edits and the Preview that checks it\n * (AGL-2838, AGL-2849). Both decide what a read answers through\n * {@link mediaAssetFactsFromDocument}, so the editor cannot disagree with the\n * page about which assets answer. When the asset cannot be answered for (a\n * failed or pending read, a missing or deleted document, an asset the CDN\n * would not serve under this page's URL, one past the composition's cap), the\n * node keeps what the pick stored. That is the render every page had before\n * this, never a worse one. When the asset answers:\n *\n * - **A film's facts win, including their ABSENCE.** A film the replace left\n * with no `video` record has no known shape, so a stored pair describing\n * the previous film is dropped rather than published, and a poster flag the\n * document no longer backs is dropped with it. One stored value survives: a\n * running time the AUTHOR typed for a film the DAM has no running time for.\n * The pick only ever writes the duration together with the pixel pair\n * ({@link videoMediaProps} is all-or-nothing on the `video` record), and the\n * pair is not an author control. So a duration standing alone is an\n * author's, and a duration standing beside a pair is a copy of a film that\n * may no longer be the one in the bucket.\n * - **An image's pair wins when the document records one.** When it records\n * none (an SVG, which the upload cannot measure, or a file older than\n * AGL-173), the stored pair stays, whether an author typed it through the\n * API or it is a copy of the file the asset held before. The asymmetry with\n * a film is in the render, not the data. A film's pair is the player's\n * permanent box, but an image's is only a reservation\n * (`aspect-ratio: auto w / h`), which the decoded picture's own ratio\n * replaces. Dropping the pair guarantees a shift of the image's full height\n * on every view. A stale pair shifts by the difference between two heights,\n * and a pair typed for a file the DAM cannot measure shifts by nothing.\n *\n * Nothing an author sets for the placement is touched: an image's CSS\n * `width` and `height`, its fit and radius, and a film's own poster describe\n * the placement rather than the file.\n *\n * Imported by path and never through a barrel: every `@aglyn/aglyn` barrel\n * ships to published pages, and nothing here has a reason to reach one, so\n * the composition and the console both import this module by path.\n */\n\nimport { CANVAS_ROOT_ELEMENT_ID } from '../foundation/constants/canvas'\nimport { mediaCdnScopeRefusal, parseMediaCdnScope } from './media-cdn-scope'\nimport { intrinsicMediaSize, videoMediaProps } from './media-metadata'\nimport {\n hostQualifiedScope,\n isMediaCdnPath,\n mediaCdnVersionToken,\n type MediaRef,\n mediaRefFromCdnPath,\n parseMediaRef,\n} from './media-ref'\nimport { VIDEO_COMPONENT_ID } from './video-object'\n\n/** The Image element's persisted component id (`image.tsx`), never renamed. */\nexport const IMAGE_COMPONENT_ID = 'image'\n\n/**\n * The prop each element that holds a markdown-lite DOCUMENT keeps it in, and\n * therefore every element whose body can name a library image (AGL-3149).\n *\n * The same two elements and the same two prop names `resolveMarkdownSource`\n * walks for a table of contents (AGL-1162), which is the other reader of a\n * body's contents. They differ: the Markdown element calls it `content` and a\n * collection entry's body calls it `markdown`.\n *\n * Both ids are spelled out rather than imported. `markdown` belongs to a\n * plugin, which core may never import; `collectionEntryBody` is exported by\n * `collection-entries.ts`, but that module is 1,860 lines and drags\n * `content-authors.ts` behind it, and this one is deliberately outside the\n * barrel that ships to published pages. A persisted component id is a string\n * that cannot change — renaming one orphans every document that stores it —\n * so the copy cannot drift in the way an imported value would protect against.\n */\nconst MARKDOWN_BODY_PROPS: Readonly<Record<string, string>> = {\n markdown: 'content',\n collectionEntryBody: 'markdown',\n}\n\n/** The root of a composed map, where a walk in document order starts. */\nconst ROOT_NODE_ID: string = CANVAS_ROOT_ELEMENT_ID\n\n/**\n * What a readable asset's media document records, as the overlay consumes it.\n *\n * Raw on purpose: {@link intrinsicMediaSize} and {@link videoMediaProps} are\n * where a pair and a `video` record are bounded, and a second reading of the\n * same numbers here is how two files come to disagree about what a partial\n * record means.\n */\nexport interface MediaAssetFacts {\n /** The document's `width`: an image's, read from its bytes at upload. */\n width?: unknown\n /** The document's `height`, the other half of {@link width}. */\n height?: unknown\n /** The document's `video` record: `durationMs`, `width` and `height`. */\n video?: unknown\n /** The document's generated `poster` record, when it has one. */\n poster?: unknown\n /**\n * The document's `contentHash`, which a replace changes with the bytes. An\n * image placement carries it as `mediaVersion`, and the URL it renders is\n * then the versioned one the CDN lets every cache keep (AGL-3485).\n */\n contentHash?: unknown\n}\n\n/**\n * Every field an asset's facts are decided from, and the projection a reader\n * asks Firestore for: ONE list, whichever surface reads. `width` and `height`\n * (an image's) and `video` and `poster` (a film's) are the facts. The other\n * four are the gates `serveMediaCdn` applies before it will serve an asset at\n * all, so no surface shows the shape of a file its page's URL refuses.\n */\nexport const MEDIA_ASSET_FACT_FIELDS = [\n 'width',\n 'height',\n 'video',\n 'poster',\n 'contentHash',\n 'deletedAt',\n 'private',\n 'visibleTo',\n 'scopeMode',\n] as const\n\n/** An asset's media document, as far as {@link MEDIA_ASSET_FACT_FIELDS} reach. */\nexport type MediaAssetDocument = Partial<\n Record<(typeof MEDIA_ASSET_FACT_FIELDS)[number], unknown>\n>\n\n/** The elements whose placements follow their file. */\nexport type MediaAssetElement =\n | typeof IMAGE_COMPONENT_ID\n | typeof VIDEO_COMPONENT_ID\n\nexport interface MediaAssetFactsOptions {\n /**\n * One element's placements only, by persisted component id. Absent means\n * both, which is what the composition asks for.\n */\n only?: MediaAssetElement\n}\n\n/** A node as the composed map holds it: flat, children by id. */\ninterface ComposedMediaNode {\n componentId?: string\n nodes?: unknown\n props?: Record<string, unknown>\n resolvedProps?: Record<string, unknown>\n}\n\nconst owns = (map: object, key: string) =>\n Object.prototype.hasOwnProperty.call(map, key)\n\n/**\n * The key an asset's facts are filed under: the reference's own scope and id.\n *\n * Deliberately NOT the host-qualified scope a page renders. The document lives\n * under the scope's owner whichever site places it, and which site may be\n * shown it is the reader's question, answered once per page.\n */\nexport function mediaAssetFactsKey(\n ref: Pick<MediaRef, 'scope' | 'mediaId'>,\n): string {\n return `${ref.scope}/${ref.mediaId}`\n}\n\n/**\n * Where an asset's media document lives: under the scope's OWNER, `orgs/` for\n * the org library and `hosts/` for a site's own, whichever site places it.\n * `null` for a scope the CDN would not parse, which no read can answer for.\n */\nexport function mediaAssetDocumentPath(\n ref: Pick<MediaRef, 'scope' | 'mediaId'>,\n): string | null {\n const scope = parseMediaCdnScope(ref.scope)\n if (!scope) return null\n return `${scope.isOrg ? 'orgs' : 'hosts'}/${scope.scopeId}/media/${ref.mediaId}`\n}\n\n/**\n * The facts one read of an asset's document yields for a placement rendered\n * on `hostId`'s pages, or `undefined` when the placement keeps its stored\n * props.\n *\n * An answer exists only for a document that was read, is live, is not\n * private, and is visible to that site under the host-qualified scope the page\n * renders: the verdict the CDN reaches when the browser asks for the bytes.\n * The URL a page renders names the site doing the rendering\n * (`resolveMediaSrc`), so visibility is asked of THAT scope, not of the scope\n * the reference was stored with.\n */\nexport function mediaAssetFactsFromDocument(\n document: MediaAssetDocument | null | undefined,\n ref: Pick<MediaRef, 'scope'>,\n hostId: string,\n): MediaAssetFacts | undefined {\n if (!document) return undefined\n if (document.deletedAt || document.private === true) return undefined\n const served = parseMediaCdnScope(hostQualifiedScope(ref.scope, hostId))\n if (\n !served ||\n mediaCdnScopeRefusal(served, document.visibleTo, document.scopeMode)\n ) {\n return undefined\n }\n return {\n width: document.width,\n height: document.height,\n video: document.video,\n poster: document.poster,\n contentHash: document.contentHash,\n }\n}\n\n/** The library asset an Image or Video node places, or null for anything else. */\nfunction placedAsset(\n node: ComposedMediaNode | null | undefined,\n only?: MediaAssetElement,\n): MediaRef | null {\n const componentId = node?.componentId\n if (componentId !== IMAGE_COMPONENT_ID && componentId !== VIDEO_COMPONENT_ID) {\n return null\n }\n if (only && componentId !== only) return null\n // The precedence every other reader of the composed map uses: a node inside\n // a repeated collection carries its bound values in the resolved copy.\n const props = node?.resolvedProps ?? node?.props\n return placedRef(props?.['src'])\n}\n\n/**\n * The library asset a stored `src` names: a `media:` reference, or the\n * site-relative CDN path the first media picker wrote before references\n * existed (AGL-1215). Both name one asset by its id, and the path's are among\n * the oldest placements on the platform — the ones that most need their file's\n * shape read back, since nothing copied it onto the node when they were made.\n * Only the strict root-relative path: a hotlink on another host that happens\n * to contain our route names nothing of ours.\n */\nfunction placedRef(src: unknown): MediaRef | null {\n if (isMediaCdnPath(src)) return parseMediaRef(mediaRefFromCdnPath(src))\n return parseMediaRef(src)\n}\n\n/** A compose-time token the tenant has not substituted — never a document. */\nconst UNRESOLVED_TOKEN = /^\\{\\{[^}]+\\}\\}$/\n\n/**\n * The markdown-lite document a node holds, or `''` for a node holding none.\n *\n * `resolvedProps` first, for the reason {@link placedAsset} gives: an entry\n * body is the literal `{{entry.body}}` in `props` and the entry's real text in\n * the resolved copy. An unsubstituted token is not a document — it can name no\n * asset — so it is dropped here rather than walked for images that a canvas\n * surface would never find.\n */\nfunction markdownBodyOf(\n props: Record<string, unknown> | undefined,\n componentId: string | undefined,\n): string {\n const prop =\n componentId && owns(MARKDOWN_BODY_PROPS, componentId)\n ? MARKDOWN_BODY_PROPS[componentId]\n : undefined\n const text = prop ? props?.[prop] : undefined\n if (typeof text !== 'string' || UNRESOLVED_TOKEN.test(text.trim())) return ''\n return text\n}\n\n/** See {@link markdownBodyOf} — the body the page will actually render. */\nfunction markdownBody(node: ComposedMediaNode | null | undefined): string {\n return markdownBodyOf(\n node?.resolvedProps ?? node?.props,\n node?.componentId,\n )\n}\n\n/**\n * A markdown-lite image: `![alt](target)`, capturing only the target, and only\n * up to the first whitespace or `)`.\n *\n * That is the whole of the syntax `markdown-lite.ts` accepts — no title string\n * after the target, no angle-bracket form — so there is nowhere else in a body\n * for a reference to hide, and matching more than the parser does would name\n * assets the renderer never asks for.\n */\nconst MARKDOWN_IMAGE_TARGET = /!\\[[^\\]]*\\]\\(\\s*([^)\\s]+)/g\n\n/**\n * Every library asset a markdown body's images name, in the order the body\n * names them, each beside the target EXACTLY as the body wrote it.\n *\n * The raw target is carried because that is the key the renderer has: it holds\n * the parsed block's `src`, the same string, and looking a pair up by it costs\n * no second parse per image on every render.\n *\n * A target that is not a `media:` reference yields nothing — a hotlinked URL\n * and a legacy stored path have no DAM document to read, and the renderer\n * gives those today's markup unchanged.\n */\nfunction markdownImageRefs(\n text: string,\n): Array<{ target: string; ref: MediaRef }> {\n if (!text.includes('![')) return []\n const found: Array<{ target: string; ref: MediaRef }> = []\n for (const match of text.matchAll(MARKDOWN_IMAGE_TARGET)) {\n const target = match[1]\n const ref = parseMediaRef(target)\n if (ref) found.push({ target, ref })\n }\n return found\n}\n\n/**\n * The map's node ids in document order: depth first from the root through\n * each node's child ids, then every id the walk never reached (a map with no\n * root, an orphan) in the order the map lists it. That puts the top of the\n * page ahead of its footer, and it is the same order for the same map.\n */\nfunction documentOrder(nodes: Record<string, unknown>): string[] {\n const order: string[] = []\n const seen = new Set<string>()\n const stack = owns(nodes, ROOT_NODE_ID) ? [ROOT_NODE_ID] : []\n while (stack.length) {\n const id = stack.pop() as string\n if (seen.has(id) || !owns(nodes, id)) continue\n seen.add(id)\n order.push(id)\n const children = (nodes[id] as ComposedMediaNode | null)?.nodes\n if (!Array.isArray(children)) continue\n for (let index = children.length - 1; index >= 0; index -= 1) {\n const child = children[index]\n if (typeof child === 'string' && !seen.has(child)) stack.push(child)\n }\n }\n for (const id in nodes) if (!seen.has(id)) order.push(id)\n return order\n}\n\n/**\n * Every distinct library asset the Image and Video nodes in a map place:\n * films first, then images, each in document order.\n *\n * A read that is capped honors that order. A film goes first because its\n * stale facts are the worse render (a player of the wrong shape and a\n * thumbnail that 404s, against a reservation that corrects itself when an\n * image decodes), and document order covers the top of the page before its\n * footer.\n *\n * `[]` for a page that places none, so a caller that gates its read on the\n * length spends nothing on it. A pinned and an unpinned reference to one\n * asset are one entry: a pin names bytes, not a different asset.\n */\nexport function mediaAssetRefs(\n nodes: Record<string, unknown> | null | undefined,\n options: MediaAssetFactsOptions = {},\n): MediaRef[] {\n const refs: MediaRef[] = []\n if (!nodes) return refs\n const order = documentOrder(nodes)\n const seen = new Set<string>()\n for (const element of [VIDEO_COMPONENT_ID, IMAGE_COMPONENT_ID] as const) {\n if (options.only && options.only !== element) continue\n for (const id of order) {\n const node = nodes[id] as ComposedMediaNode | null\n if (node?.componentId !== element) continue\n const ref = placedAsset(node)\n if (!ref) continue\n const key = mediaAssetFactsKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n refs.push(ref)\n }\n }\n // A markdown body's images come LAST, and only when the caller wants every\n // element (AGL-3149). Last because of what a capped read costs each kind: a\n // placement that misses out renders at its pick-time pair, a body image that\n // misses out renders exactly as it does today, and a film that misses out\n // gets a player of the wrong shape. Only-when-unfiltered because `only` asks\n // for one ELEMENT's placements, and a body image is not a placement of the\n // Image element — the video-asset reader would otherwise read image\n // documents it has no use for.\n if (options.only) return refs\n for (const id of order) {\n const body = markdownBody(nodes[id] as ComposedMediaNode | null)\n for (const { ref } of markdownImageRefs(body)) {\n const key = mediaAssetFactsKey(ref)\n if (seen.has(key)) continue\n seen.add(key)\n refs.push(ref)\n }\n }\n return refs\n}\n\nconst usable = (value: unknown): value is number =>\n typeof value === 'number' && Number.isFinite(value) && value > 0\n\n/** A film's props with its asset's facts laid over them. See the module note. */\nfunction withFilmFacts(\n props: Record<string, unknown>,\n facts: MediaAssetFacts,\n): Record<string, unknown> {\n const live = videoMediaProps({\n componentId: VIDEO_COMPONENT_ID,\n propName: 'src',\n assetVideo: facts.video,\n assetPoster: facts.poster,\n })\n const {\n durationSeconds,\n intrinsicWidth,\n intrinsicHeight,\n posterFromSource: _storedPosterFlag,\n ...next\n } = props\n // The pick writes a duration only beside the pixel pair, so a pair is what\n // marks the stored duration as a copy rather than an author's own.\n const typedByAuthor = !(usable(intrinsicWidth) && usable(intrinsicHeight))\n if (live.durationSeconds !== undefined) {\n next['durationSeconds'] = live.durationSeconds\n } else if (typedByAuthor && durationSeconds !== undefined) {\n next['durationSeconds'] = durationSeconds\n }\n if (live.intrinsicWidth !== undefined && live.intrinsicHeight !== undefined) {\n next['intrinsicWidth'] = live.intrinsicWidth\n next['intrinsicHeight'] = live.intrinsicHeight\n }\n if (live.posterFromSource) next['posterFromSource'] = true\n return next\n}\n\n/**\n * An image's props with its asset's pair laid over them, or the SAME object\n * when the document records no usable pair or the stored one already matches.\n * See the module note.\n */\nfunction withImageFacts(\n props: Record<string, unknown>,\n facts: MediaAssetFacts,\n): Record<string, unknown> {\n // Through the pick's own gate, so the overlay and the pick agree on what a\n // usable pair is: both halves, finite and positive.\n const live = intrinsicMediaSize({\n componentId: IMAGE_COMPONENT_ID,\n propName: 'src',\n assetWidth: facts.width,\n assetHeight: facts.height,\n })\n const version = mediaVersionOf(facts)\n const pair =\n live.intrinsicWidth !== undefined && live.intrinsicHeight !== undefined\n const pairChanged =\n pair &&\n (props['intrinsicWidth'] !== live.intrinsicWidth ||\n props['intrinsicHeight'] !== live.intrinsicHeight)\n const versionChanged =\n version !== undefined && props[IMAGE_MEDIA_VERSION_PROP] !== version\n if (!pairChanged && !versionChanged) return props\n return {\n ...props,\n ...(pairChanged\n ? {\n intrinsicWidth: live.intrinsicWidth,\n intrinsicHeight: live.intrinsicHeight,\n }\n : {}),\n ...(versionChanged ? { [IMAGE_MEDIA_VERSION_PROP]: version } : {}),\n }\n}\n\n/**\n * The prop an Image placement carries its asset's current content hash in\n * (AGL-3485). Laid on at composition like the pixel pair and never an author\n * control: it describes the file, and `image.tsx` hands it to\n * `resolveMediaSrc` so the page names the versioned URL.\n */\nexport const IMAGE_MEDIA_VERSION_PROP = 'mediaVersion'\n\n/** The document's content hash, when it is one a URL can carry. */\nfunction mediaVersionOf(facts: MediaAssetFacts): string | undefined {\n return mediaCdnVersionToken(facts.contentHash) === undefined\n ? undefined\n : (facts.contentHash as string)\n}\n\n/**\n * The prop a markdown body carries its images' pixel pairs in, keyed by the\n * target the body wrote (AGL-3149).\n *\n * A body image is not a node, so it cannot take `intrinsicWidth` and\n * `intrinsicHeight` the way a placement does; the pairs travel together on the\n * element that holds the document, and the renderer looks each one up by the\n * parsed block's `src`.\n */\nexport const BODY_IMAGE_SIZES_PROP = 'intrinsicSizes'\n\n/** One body image's pair, as {@link BODY_IMAGE_SIZES_PROP} carries it. */\nexport interface BodyImageSize {\n width: number\n height: number\n /** The asset's content hash, for the versioned URL (AGL-3485). */\n version?: string\n}\n\n/**\n * A markdown body's props with a pair for each library image it names, or the\n * SAME object when no image in it can be answered for.\n *\n * Only images whose document records a usable pair get an entry, through the\n * same {@link intrinsicMediaSize} gate a placement goes through. An image left\n * out is one the renderer must give today's markup: `srcSet` without the pair\n * makes `sizes` the image's rendered width, which upscales anything narrower\n * than the column, so a partial answer is worse here than no answer.\n */\nfunction withBodyImageFacts(\n props: Record<string, unknown>,\n componentId: string | undefined,\n facts: ReadonlyMap<string, MediaAssetFacts>,\n): Record<string, unknown> {\n // THIS object's own body, never the node's resolved one: `props` on a bound\n // entry body still holds the `{{entry.body}}` token, and pairs for images it\n // does not name are bytes in the tree that nothing can ever look up.\n let sizes: Record<string, BodyImageSize> | undefined\n for (const { target, ref } of markdownImageRefs(\n markdownBodyOf(props, componentId),\n )) {\n const found = facts.get(mediaAssetFactsKey(ref))\n if (!found) continue\n const live = intrinsicMediaSize({\n componentId: IMAGE_COMPONENT_ID,\n propName: 'src',\n assetWidth: found.width,\n assetHeight: found.height,\n })\n if (\n live.intrinsicWidth === undefined ||\n live.intrinsicHeight === undefined\n ) {\n continue\n }\n if (!sizes) sizes = {}\n const version = mediaVersionOf(found)\n sizes[target] = {\n width: live.intrinsicWidth,\n height: live.intrinsicHeight,\n ...(version ? { version } : {}),\n }\n }\n if (!sizes) return props\n return { ...props, [BODY_IMAGE_SIZES_PROP]: sizes }\n}\n\n/**\n * The composed map with each placed asset's facts laid over its node, and each\n * markdown body's images' pairs laid over the element holding the body.\n *\n * `facts` is keyed by {@link mediaAssetFactsKey}. A placement with no entry,\n * because the reader could not answer for its asset, keeps its stored props.\n * The SAME map comes back when nothing changes, so a page with no library\n * asset pays for one walk and no copy, and the input is never mutated either\n * way.\n */\nexport function applyMediaAssetFacts<T extends Record<string, unknown>>(\n nodes: T,\n facts: ReadonlyMap<string, MediaAssetFacts>,\n options: MediaAssetFactsOptions = {},\n): T {\n if (!facts.size) return nodes\n let applied: Record<string, unknown> | undefined\n const write = (id: string, node: ComposedMediaNode, next: {\n props?: Record<string, unknown>\n resolvedProps?: Record<string, unknown>\n }): void => {\n if (!applied) applied = { ...nodes }\n applied[id] = {\n ...node,\n ...(next.props ? { props: next.props } : {}),\n ...(next.resolvedProps ? { resolvedProps: next.resolvedProps } : {}),\n }\n }\n for (const id in nodes) {\n const node = nodes[id] as ComposedMediaNode\n const ref = placedAsset(node, options.only)\n const found = ref ? facts.get(mediaAssetFactsKey(ref)) : undefined\n if (found) {\n const overlay =\n node.componentId === VIDEO_COMPONENT_ID ? withFilmFacts : withImageFacts\n const props = node.props && overlay(node.props, found)\n const resolvedProps =\n node.resolvedProps && overlay(node.resolvedProps, found)\n if (props === node.props && resolvedProps === node.resolvedProps) continue\n write(id, node, { props, resolvedProps })\n continue\n }\n // A markdown body, under the same `only` rule `mediaAssetRefs` collects\n // under: a body image is not a placement of the Image element, so a reader\n // asking for one element's placements is not asking about bodies.\n if (options.only) continue\n const { componentId } = node\n if (!componentId || !owns(MARKDOWN_BODY_PROPS, componentId)) continue\n const props =\n node.props && withBodyImageFacts(node.props, componentId, facts)\n const resolvedProps =\n node.resolvedProps &&\n withBodyImageFacts(node.resolvedProps, componentId, facts)\n if (props === node.props && resolvedProps === node.resolvedProps) continue\n write(id, node, { props, resolvedProps })\n }\n return applied ? (applied as T) : nodes\n}\n"],"names":["CANVAS_ROOT_ELEMENT_ID","mediaCdnScopeRefusal","parseMediaCdnScope","intrinsicMediaSize","videoMediaProps","hostQualifiedScope","isMediaCdnPath","mediaCdnVersionToken","mediaRefFromCdnPath","parseMediaRef","VIDEO_COMPONENT_ID","IMAGE_COMPONENT_ID","MARKDOWN_BODY_PROPS","markdown","collectionEntryBody","ROOT_NODE_ID","MEDIA_ASSET_FACT_FIELDS","owns","map","key","Object","prototype","hasOwnProperty","call","mediaAssetFactsKey","ref","scope","mediaId","mediaAssetDocumentPath","isOrg","scopeId","mediaAssetFactsFromDocument","document","hostId","undefined","deletedAt","private","served","visibleTo","scopeMode","width","height","video","poster","contentHash","placedAsset","node","only","componentId","props","resolvedProps","placedRef","src","UNRESOLVED_TOKEN","markdownBodyOf","prop","text","test","trim","markdownBody","MARKDOWN_IMAGE_TARGET","markdownImageRefs","includes","found","match","matchAll","target","push","documentOrder","nodes","order","seen","Set","stack","length","id","pop","has","add","children","Array","isArray","index","child","mediaAssetRefs","options","refs","element","body","usable","value","Number","isFinite","withFilmFacts","facts","live","propName","assetVideo","assetPoster","durationSeconds","intrinsicWidth","intrinsicHeight","posterFromSource","_storedPosterFlag","next","typedByAuthor","withImageFacts","assetWidth","assetHeight","version","mediaVersionOf","pair","pairChanged","versionChanged","IMAGE_MEDIA_VERSION_PROP","BODY_IMAGE_SIZES_PROP","withBodyImageFacts","sizes","get","applyMediaAssetFacts","size","applied","write","overlay"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEC,GAED,SAASA,sBAAsB,QAAQ,oCAAgC;AACvE,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,uBAAmB;AAC5E,SAASC,kBAAkB,EAAEC,eAAe,QAAQ,sBAAkB;AACtE,SACEC,kBAAkB,EAClBC,cAAc,EACdC,oBAAoB,EAEpBC,mBAAmB,EACnBC,aAAa,QACR,iBAAa;AACpB,SAASC,kBAAkB,QAAQ,oBAAgB;AAEnD,6EAA6E,GAC7E,OAAO,MAAMC,qBAAqB,QAAO;AAEzC;;;;;;;;;;;;;;;;CAgBC,GACD,MAAMC,sBAAwD;IAC5DC,UAAU;IACVC,qBAAqB;AACvB;AAEA,uEAAuE,GACvE,MAAMC,eAAuBf;AA2B7B;;;;;;CAMC,GACD,OAAO,MAAMgB,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
20
  * The parsed CDN scope segment (AGL-1043). Shapes:
21
21
  *
22
22
  * - `{hostId}` — that host's own library
23
- * - `org:{orgId}` — the org library, ORG-WIDE assets only
23
+ * - `org:{orgId}` — the org library: assets shared with every site, and assets
24
+ * shared with all sites except some (`mediaCdnScopeRefusal`)
24
25
  * - `org:{orgId}:{hostId}` — an org asset in one site's context
25
26
  *
26
27
  * The host is in the URL rather than sniffed from the `Host` header on
@@ -59,7 +60,21 @@ export declare function parseMediaCdnScope(scopeSegment: string): MediaCdnScope
59
60
  * this one needs a person either way.
60
61
  */
61
62
  export type MediaCdnScopeRefusal = 'restricted' | 'unscoped' | 'no-sites';
62
- /** Why the asset is refused under this URL; `null` when it is not. */
63
- export declare function mediaCdnScopeRefusal(scope: MediaCdnScope, visibleTo: unknown): MediaCdnScopeRefusal | null;
63
+ /**
64
+ * Why the asset is refused under this URL; `null` when it is not.
65
+ *
66
+ * `scopeMode` is the document's own, passed by every caller. An asset shared
67
+ * with all sites except some has no `'org'` token (`visibleTo` lists the sites
68
+ * it IS on), and the bare `org:{orgId}` form still serves it. Bare URLs stay in
69
+ * the world after the choice is made, in raw HTML and CSS strings and in sent
70
+ * email, and refusing them would break every one the moment a single site was
71
+ * excluded. It widens nothing: the CDN is unauthenticated, and any included
72
+ * site's URL already serves these bytes to anyone. A private asset is a later,
73
+ * separate gate that demands a signature whichever form was asked for.
74
+ *
75
+ * The named-site form is unchanged, so an excluded site's URL is refused. So
76
+ * is a marked asset with no sites left, which is `no-sites` under every form.
77
+ */
78
+ export declare function mediaCdnScopeRefusal(scope: MediaCdnScope, visibleTo: unknown, scopeMode?: unknown): MediaCdnScopeRefusal | null;
64
79
  /** Whether the asset may be served under this URL. */
65
- export declare function mediaCdnAllows(scope: MediaCdnScope, visibleTo: unknown): boolean;
80
+ export declare function mediaCdnAllows(scope: MediaCdnScope, visibleTo: unknown, scopeMode?: unknown): boolean;
@@ -35,7 +35,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
35
35
  *
36
36
  * Out of every barrel: the handler, the composition and the editor import it
37
37
  * by path, and nothing here has a reason to reach a published page's bundle.
38
- */ import { isOrgWideScope, visibleToHost } from "./scope-tokens.js";
38
+ */ import { isOrgWideScope, SCOPE_MODE_ALL_EXCEPT, visibleToHost } from "./scope-tokens.js";
39
39
  /** One CDN path segment: a host id, an org id, a media id or a content hash. */ export const MEDIA_CDN_SEGMENT = /^[A-Za-z0-9_-]{1,64}$/;
40
40
  export function parseMediaCdnScope(scopeSegment) {
41
41
  if (!scopeSegment.startsWith('org:')) {
@@ -58,18 +58,32 @@ export function parseMediaCdnScope(scopeSegment) {
58
58
  contextHostId
59
59
  } : {});
60
60
  }
61
- /** Why the asset is refused under this URL; `null` when it is not. */ export function mediaCdnScopeRefusal(scope, visibleTo) {
61
+ /**
62
+ * Why the asset is refused under this URL; `null` when it is not.
63
+ *
64
+ * `scopeMode` is the document's own, passed by every caller. An asset shared
65
+ * with all sites except some has no `'org'` token (`visibleTo` lists the sites
66
+ * it IS on), and the bare `org:{orgId}` form still serves it. Bare URLs stay in
67
+ * the world after the choice is made, in raw HTML and CSS strings and in sent
68
+ * email, and refusing them would break every one the moment a single site was
69
+ * excluded. It widens nothing: the CDN is unauthenticated, and any included
70
+ * site's URL already serves these bytes to anyone. A private asset is a later,
71
+ * separate gate that demands a signature whichever form was asked for.
72
+ *
73
+ * The named-site form is unchanged, so an excluded site's URL is refused. So
74
+ * is a marked asset with no sites left, which is `no-sites` under every form.
75
+ */ export function mediaCdnScopeRefusal(scope, visibleTo, scopeMode) {
62
76
  // Host-library assets are private by construction and carry no
63
77
  // `visibleTo`, so only the org branch is scoped at all.
64
78
  if (!scope.isOrg) return null;
65
79
  if (!Array.isArray(visibleTo)) return 'unscoped';
66
80
  if (!visibleTo.length) return 'no-sites';
67
81
  const scoped = visibleTo;
68
- const allowed = scope.contextHostId ? visibleToHost(scoped, scope.contextHostId) : isOrgWideScope(scoped);
82
+ const allowed = scope.contextHostId ? visibleToHost(scoped, scope.contextHostId) : isOrgWideScope(scoped) || scopeMode === SCOPE_MODE_ALL_EXCEPT;
69
83
  return allowed ? null : 'restricted';
70
84
  }
71
- /** Whether the asset may be served under this URL. */ export function mediaCdnAllows(scope, visibleTo) {
72
- return mediaCdnScopeRefusal(scope, visibleTo) === null;
85
+ /** Whether the asset may be served under this URL. */ export function mediaCdnAllows(scope, visibleTo, scopeMode) {
86
+ return mediaCdnScopeRefusal(scope, visibleTo, scopeMode) === null;
73
87
  }
74
88
 
75
89
  //# sourceMappingURL=media-cdn-scope.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/media-cdn-scope.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 * The media CDN's scope grammar and the verdict it reaches under it\n * (AGL-1043), as pure functions.\n *\n * `serveMediaCdn` enforces them and re-exports them, so the handler remains\n * the authority. They live here, in a module with no server dependency,\n * because two other readers have to reach the verdict the handler reaches\n * before it serves a file:\n *\n * - the tenant composition, which lays a placed asset's current facts over its\n * node only when the page's own URL would be served\n * (`libs/tenant/runtime/src/lib/get-media-asset-facts.ts`);\n * - the besigner canvas and Preview, which read the same document in the\n * browser so an author is shown what a visitor gets.\n *\n * Both reach it through `mediaAssetFactsFromDocument` in\n * `media-asset-facts.ts`. A copy in either would be a second rule, free to\n * disagree with the one that refuses the bytes.\n *\n * Out of every barrel: the handler, the composition and the editor import it\n * by path, and nothing here has a reason to reach a published page's bundle.\n */\n\nimport { isOrgWideScope, visibleToHost } from './scope-tokens'\n\n/** One CDN path segment: a host id, an org id, a media id or a content hash. */\nexport const MEDIA_CDN_SEGMENT = /^[A-Za-z0-9_-]{1,64}$/\n\n/**\n * The parsed CDN scope segment (AGL-1043). Shapes:\n *\n * - `{hostId}` — that host's own library\n * - `org:{orgId}` — the org library, ORG-WIDE assets only\n * - `org:{orgId}:{hostId}` — an org asset in one site's context\n *\n * The host is in the URL rather than sniffed from the `Host` header on\n * purpose. A header is the requester's CHOICE: anyone holding a restricted\n * asset's id could fetch it through a domain that IS permitted and get the\n * bytes, so header-based enforcement stops accidents while looking like a\n * boundary. Here the decision is a pure function of (URL, doc), and since\n * the cache key IS the URL, one host's answer can never reach another.\n */\nexport interface MediaCdnScope {\n isOrg: boolean\n scopeId: string\n /** Only on the `org:{orgId}:{hostId}` form. */\n contextHostId?: string\n}\n\nexport function parseMediaCdnScope(\n scopeSegment: string,\n): MediaCdnScope | null {\n if (!scopeSegment.startsWith('org:')) {\n return MEDIA_CDN_SEGMENT.test(scopeSegment)\n ? { isOrg: false, scopeId: scopeSegment }\n : null\n }\n const parts = scopeSegment.slice('org:'.length).split(':')\n if (parts.length > 2) return null\n const [scopeId, contextHostId] = parts\n if (!MEDIA_CDN_SEGMENT.test(scopeId ?? '')) return null\n if (contextHostId !== undefined && !MEDIA_CDN_SEGMENT.test(contextHostId)) {\n return null\n }\n return {\n isOrg: true,\n scopeId,\n ...(contextHostId ? { contextHostId } : {}),\n }\n}\n\n/**\n * The three ways an org asset can be refused under a CDN URL.\n *\n * They are one 404 on the wire — whether a restricted asset exists is not\n * something an anonymous caller has standing to learn — and three different\n * faults to whoever is looking at the broken page:\n *\n * - `restricted` — the asset carries a scope and this URL is not in it. The\n * URL is what is wrong: a restricted asset has to be requested through the\n * form that names the site (`hostQualifiedCdnPath`), and the same asset\n * serves normally from the site it is shared with.\n * - `unscoped` — no `visibleTo` at all, so the asset is undeliverable under\n * EVERY URL form there is. The document is what is wrong, and it means a\n * creation path wrote it without a scope: `newResourceScopeFields` is what\n * stops that at compile time, and the scope backfill is what repairs the\n * documents already written (`docs/SCOPE_DRIFT.md`).\n * - `no-sites` — a stored empty array: somebody chose nobody. Equally\n * undeliverable, and NOT repairable by the backfill, which leaves an empty\n * array alone rather than widening a resource nobody asked to widen — so\n * this one needs a person either way.\n */\nexport type MediaCdnScopeRefusal = 'restricted' | 'unscoped' | 'no-sites'\n\n/** Why the asset is refused under this URL; `null` when it is not. */\nexport function mediaCdnScopeRefusal(\n scope: MediaCdnScope,\n visibleTo: unknown,\n): MediaCdnScopeRefusal | null {\n // Host-library assets are private by construction and carry no\n // `visibleTo`, so only the org branch is scoped at all.\n if (!scope.isOrg) return null\n if (!Array.isArray(visibleTo)) return 'unscoped'\n if (!visibleTo.length) return 'no-sites'\n const scoped = visibleTo as string[]\n const allowed = scope.contextHostId\n ? visibleToHost(scoped, scope.contextHostId)\n : isOrgWideScope(scoped)\n return allowed ? null : 'restricted'\n}\n\n/** Whether the asset may be served under this URL. */\nexport function mediaCdnAllows(\n scope: MediaCdnScope,\n visibleTo: unknown,\n): boolean {\n return mediaCdnScopeRefusal(scope, visibleTo) === null\n}\n"],"names":["isOrgWideScope","visibleToHost","MEDIA_CDN_SEGMENT","parseMediaCdnScope","scopeSegment","startsWith","test","isOrg","scopeId","parts","slice","length","split","contextHostId","undefined","mediaCdnScopeRefusal","scope","visibleTo","Array","isArray","scoped","allowed","mediaCdnAllows"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;CAqBC,GAED,SAASA,cAAc,EAAEC,aAAa,QAAQ,oBAAgB;AAE9D,8EAA8E,GAC9E,OAAO,MAAMC,oBAAoB,wBAAuB;AAuBxD,OAAO,SAASC,mBACdC,YAAoB;IAEpB,IAAI,CAACA,aAAaC,UAAU,CAAC,SAAS;QACpC,OAAOH,kBAAkBI,IAAI,CAACF,gBAC1B;YAAEG,OAAO;YAAOC,SAASJ;QAAa,IACtC;IACN;IACA,MAAMK,QAAQL,aAAaM,KAAK,CAAC,OAAOC,MAAM,EAAEC,KAAK,CAAC;IACtD,IAAIH,MAAME,MAAM,GAAG,GAAG,OAAO;IAC7B,MAAM,CAACH,SAASK,cAAc,GAAGJ;IACjC,IAAI,CAACP,kBAAkBI,IAAI,CAACE,kBAAAA,UAAW,KAAK,OAAO;IACnD,IAAIK,kBAAkBC,aAAa,CAACZ,kBAAkBI,IAAI,CAACO,gBAAgB;QACzE,OAAO;IACT;IACA,OAAO;QACLN,OAAO;QACPC;OACIK,gBAAgB;QAAEA;IAAc,IAAI,CAAC;AAE7C;AAyBA,oEAAoE,GACpE,OAAO,SAASE,qBACdC,KAAoB,EACpBC,SAAkB;IAElB,+DAA+D;IAC/D,wDAAwD;IACxD,IAAI,CAACD,MAAMT,KAAK,EAAE,OAAO;IACzB,IAAI,CAACW,MAAMC,OAAO,CAACF,YAAY,OAAO;IACtC,IAAI,CAACA,UAAUN,MAAM,EAAE,OAAO;IAC9B,MAAMS,SAASH;IACf,MAAMI,UAAUL,MAAMH,aAAa,GAC/BZ,cAAcmB,QAAQJ,MAAMH,aAAa,IACzCb,eAAeoB;IACnB,OAAOC,UAAU,OAAO;AAC1B;AAEA,oDAAoD,GACpD,OAAO,SAASC,eACdN,KAAoB,EACpBC,SAAkB;IAElB,OAAOF,qBAAqBC,OAAOC,eAAe;AACpD"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/media-cdn-scope.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 * The media CDN's scope grammar and the verdict it reaches under it\n * (AGL-1043), as pure functions.\n *\n * `serveMediaCdn` enforces them and re-exports them, so the handler remains\n * the authority. They live here, in a module with no server dependency,\n * because two other readers have to reach the verdict the handler reaches\n * before it serves a file:\n *\n * - the tenant composition, which lays a placed asset's current facts over its\n * node only when the page's own URL would be served\n * (`libs/tenant/runtime/src/lib/get-media-asset-facts.ts`);\n * - the besigner canvas and Preview, which read the same document in the\n * browser so an author is shown what a visitor gets.\n *\n * Both reach it through `mediaAssetFactsFromDocument` in\n * `media-asset-facts.ts`. A copy in either would be a second rule, free to\n * disagree with the one that refuses the bytes.\n *\n * Out of every barrel: the handler, the composition and the editor import it\n * by path, and nothing here has a reason to reach a published page's bundle.\n */\n\nimport { isOrgWideScope, SCOPE_MODE_ALL_EXCEPT, visibleToHost } from './scope-tokens'\n\n/** One CDN path segment: a host id, an org id, a media id or a content hash. */\nexport const MEDIA_CDN_SEGMENT = /^[A-Za-z0-9_-]{1,64}$/\n\n/**\n * The parsed CDN scope segment (AGL-1043). Shapes:\n *\n * - `{hostId}` — that host's own library\n * - `org:{orgId}` — the org library: assets shared with every site, and assets\n * shared with all sites except some (`mediaCdnScopeRefusal`)\n * - `org:{orgId}:{hostId}` — an org asset in one site's context\n *\n * The host is in the URL rather than sniffed from the `Host` header on\n * purpose. A header is the requester's CHOICE: anyone holding a restricted\n * asset's id could fetch it through a domain that IS permitted and get the\n * bytes, so header-based enforcement stops accidents while looking like a\n * boundary. Here the decision is a pure function of (URL, doc), and since\n * the cache key IS the URL, one host's answer can never reach another.\n */\nexport interface MediaCdnScope {\n isOrg: boolean\n scopeId: string\n /** Only on the `org:{orgId}:{hostId}` form. */\n contextHostId?: string\n}\n\nexport function parseMediaCdnScope(\n scopeSegment: string,\n): MediaCdnScope | null {\n if (!scopeSegment.startsWith('org:')) {\n return MEDIA_CDN_SEGMENT.test(scopeSegment)\n ? { isOrg: false, scopeId: scopeSegment }\n : null\n }\n const parts = scopeSegment.slice('org:'.length).split(':')\n if (parts.length > 2) return null\n const [scopeId, contextHostId] = parts\n if (!MEDIA_CDN_SEGMENT.test(scopeId ?? '')) return null\n if (contextHostId !== undefined && !MEDIA_CDN_SEGMENT.test(contextHostId)) {\n return null\n }\n return {\n isOrg: true,\n scopeId,\n ...(contextHostId ? { contextHostId } : {}),\n }\n}\n\n/**\n * The three ways an org asset can be refused under a CDN URL.\n *\n * They are one 404 on the wire — whether a restricted asset exists is not\n * something an anonymous caller has standing to learn — and three different\n * faults to whoever is looking at the broken page:\n *\n * - `restricted` — the asset carries a scope and this URL is not in it. The\n * URL is what is wrong: a restricted asset has to be requested through the\n * form that names the site (`hostQualifiedCdnPath`), and the same asset\n * serves normally from the site it is shared with.\n * - `unscoped` — no `visibleTo` at all, so the asset is undeliverable under\n * EVERY URL form there is. The document is what is wrong, and it means a\n * creation path wrote it without a scope: `newResourceScopeFields` is what\n * stops that at compile time, and the scope backfill is what repairs the\n * documents already written (`docs/SCOPE_DRIFT.md`).\n * - `no-sites` — a stored empty array: somebody chose nobody. Equally\n * undeliverable, and NOT repairable by the backfill, which leaves an empty\n * array alone rather than widening a resource nobody asked to widen — so\n * this one needs a person either way.\n */\nexport type MediaCdnScopeRefusal = 'restricted' | 'unscoped' | 'no-sites'\n\n/**\n * Why the asset is refused under this URL; `null` when it is not.\n *\n * `scopeMode` is the document's own, passed by every caller. An asset shared\n * with all sites except some has no `'org'` token (`visibleTo` lists the sites\n * it IS on), and the bare `org:{orgId}` form still serves it. Bare URLs stay in\n * the world after the choice is made, in raw HTML and CSS strings and in sent\n * email, and refusing them would break every one the moment a single site was\n * excluded. It widens nothing: the CDN is unauthenticated, and any included\n * site's URL already serves these bytes to anyone. A private asset is a later,\n * separate gate that demands a signature whichever form was asked for.\n *\n * The named-site form is unchanged, so an excluded site's URL is refused. So\n * is a marked asset with no sites left, which is `no-sites` under every form.\n */\nexport function mediaCdnScopeRefusal(\n scope: MediaCdnScope,\n visibleTo: unknown,\n scopeMode?: unknown,\n): MediaCdnScopeRefusal | null {\n // Host-library assets are private by construction and carry no\n // `visibleTo`, so only the org branch is scoped at all.\n if (!scope.isOrg) return null\n if (!Array.isArray(visibleTo)) return 'unscoped'\n if (!visibleTo.length) return 'no-sites'\n const scoped = visibleTo as string[]\n const allowed = scope.contextHostId\n ? visibleToHost(scoped, scope.contextHostId)\n : isOrgWideScope(scoped) || scopeMode === SCOPE_MODE_ALL_EXCEPT\n return allowed ? null : 'restricted'\n}\n\n/** Whether the asset may be served under this URL. */\nexport function mediaCdnAllows(\n scope: MediaCdnScope,\n visibleTo: unknown,\n scopeMode?: unknown,\n): boolean {\n return mediaCdnScopeRefusal(scope, visibleTo, scopeMode) === null\n}\n"],"names":["isOrgWideScope","SCOPE_MODE_ALL_EXCEPT","visibleToHost","MEDIA_CDN_SEGMENT","parseMediaCdnScope","scopeSegment","startsWith","test","isOrg","scopeId","parts","slice","length","split","contextHostId","undefined","mediaCdnScopeRefusal","scope","visibleTo","scopeMode","Array","isArray","scoped","allowed","mediaCdnAllows"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;CAqBC,GAED,SAASA,cAAc,EAAEC,qBAAqB,EAAEC,aAAa,QAAQ,oBAAgB;AAErF,8EAA8E,GAC9E,OAAO,MAAMC,oBAAoB,wBAAuB;AAwBxD,OAAO,SAASC,mBACdC,YAAoB;IAEpB,IAAI,CAACA,aAAaC,UAAU,CAAC,SAAS;QACpC,OAAOH,kBAAkBI,IAAI,CAACF,gBAC1B;YAAEG,OAAO;YAAOC,SAASJ;QAAa,IACtC;IACN;IACA,MAAMK,QAAQL,aAAaM,KAAK,CAAC,OAAOC,MAAM,EAAEC,KAAK,CAAC;IACtD,IAAIH,MAAME,MAAM,GAAG,GAAG,OAAO;IAC7B,MAAM,CAACH,SAASK,cAAc,GAAGJ;IACjC,IAAI,CAACP,kBAAkBI,IAAI,CAACE,kBAAAA,UAAW,KAAK,OAAO;IACnD,IAAIK,kBAAkBC,aAAa,CAACZ,kBAAkBI,IAAI,CAACO,gBAAgB;QACzE,OAAO;IACT;IACA,OAAO;QACLN,OAAO;QACPC;OACIK,gBAAgB;QAAEA;IAAc,IAAI,CAAC;AAE7C;AAyBA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASE,qBACdC,KAAoB,EACpBC,SAAkB,EAClBC,SAAmB;IAEnB,+DAA+D;IAC/D,wDAAwD;IACxD,IAAI,CAACF,MAAMT,KAAK,EAAE,OAAO;IACzB,IAAI,CAACY,MAAMC,OAAO,CAACH,YAAY,OAAO;IACtC,IAAI,CAACA,UAAUN,MAAM,EAAE,OAAO;IAC9B,MAAMU,SAASJ;IACf,MAAMK,UAAUN,MAAMH,aAAa,GAC/BZ,cAAcoB,QAAQL,MAAMH,aAAa,IACzCd,eAAesB,WAAWH,cAAclB;IAC5C,OAAOsB,UAAU,OAAO;AAC1B;AAEA,oDAAoD,GACpD,OAAO,SAASC,eACdP,KAAoB,EACpBC,SAAkB,EAClBC,SAAmB;IAEnB,OAAOH,qBAAqBC,OAAOC,WAAWC,eAAe;AAC/D"}
@@ -232,8 +232,9 @@ export declare function isMediaCdnPath(value: unknown): value is string;
232
232
  * Rewrites an org scope so it names the site doing the rendering — the
233
233
  * scope-segment twin of `hostQualifiedCdnPath` (AGL-1043).
234
234
  *
235
- * `org:{orgId}` serves ORG-WIDE assets only; an asset restricted to
236
- * particular sites has to be asked for through `org:{orgId}:{hostId}`,
235
+ * `org:{orgId}` serves org-wide assets, and assets shared with all sites
236
+ * except some; an asset shared with chosen sites has to be asked for through
237
+ * `org:{orgId}:{hostId}`,
237
238
  * because the CDN is unauthenticated and the URL is the only thing it can
238
239
  * decide from. The qualified form is a superset — it also serves org-wide
239
240
  * assets, since `visibleToHost` is true for `['org']` — so qualifying
@@ -272,10 +273,13 @@ export interface ResolveMediaSrcOptions {
272
273
  * 2. a **Storage download URL for a library object** → the same CDN URL,
273
274
  * exactly as if the reference had been stored (AGL-3506). See
274
275
  * {@link mediaRefFromStorageUrl};
275
- * 3. any other non-empty string → **itself, untouched**. Nodes holding an
276
- * `/api/media/cdn/…` path written by the first pass and an author-typed
277
- * external URL for a hotlinked image are passed through;
278
- * 4. empty/absent → undefined, so the caller shows its placeholder.
276
+ * 3. a **legacy stored CDN path** written by the first pass → itself, naming
277
+ * the site doing the rendering if its org scope names none yet. See
278
+ * {@link hostQualifiedLegacyPath};
279
+ * 4. any other non-empty string → **itself, untouched**. An author-typed
280
+ * external URL for a hotlinked image is passed through, and so is a signed
281
+ * CDN URL, which {@link isMediaCdnPath} does not answer for;
282
+ * 5. empty/absent → undefined, so the caller shows its placeholder.
279
283
  *
280
284
  * Branch 2 is what routes every library byte through the CDN. A download
281
285
  * URL goes from Google's edge straight to the visitor, so no code of ours
@@ -383,8 +383,9 @@ const SEGMENT = new RegExp(`^${SEGMENT_SOURCE}$`);
383
383
  * Rewrites an org scope so it names the site doing the rendering — the
384
384
  * scope-segment twin of `hostQualifiedCdnPath` (AGL-1043).
385
385
  *
386
- * `org:{orgId}` serves ORG-WIDE assets only; an asset restricted to
387
- * particular sites has to be asked for through `org:{orgId}:{hostId}`,
386
+ * `org:{orgId}` serves org-wide assets, and assets shared with all sites
387
+ * except some; an asset shared with chosen sites has to be asked for through
388
+ * `org:{orgId}:{hostId}`,
388
389
  * because the CDN is unauthenticated and the URL is the only thing it can
389
390
  * decide from. The qualified form is a superset — it also serves org-wide
390
391
  * assets, since `visibleToHost` is true for `['org']` — so qualifying
@@ -403,6 +404,26 @@ const SEGMENT = new RegExp(`^${SEGMENT_SOURCE}$`);
403
404
  if (!orgId || !SEGMENT.test(orgId)) return scope;
404
405
  return `${ORG_SCOPE_PREFIX}${orgId}:${hostId}`;
405
406
  }
407
+ /**
408
+ * A legacy stored CDN path, naming `hostId` when its org scope names no site.
409
+ *
410
+ * A bare `org:{orgId}` path renders the same on every site today, so an asset
411
+ * excluded from one site would keep loading there. Naming the site lets the CDN
412
+ * refuse it there, and it is safe for every asset: the qualified form serves
413
+ * whatever the bare form serves (see {@link hostQualifiedScope}).
414
+ *
415
+ * A path that already names a site keeps it, unlike a reference. Its URL serves
416
+ * on any page today because it asks about the site it names, so an asset
417
+ * restricted to that site renders on another site's page that places it, and
418
+ * rewriting the path to the rendering site would break that page.
419
+ */ function hostQualifiedLegacyPath(path, hostId) {
420
+ const rest = path.slice(MEDIA_CDN_ROUTE.length + 1);
421
+ const slash = rest.indexOf('/');
422
+ const scope = rest.slice(0, slash);
423
+ if (!scope.startsWith(ORG_SCOPE_PREFIX)) return path;
424
+ if (scope.includes(':', ORG_SCOPE_PREFIX.length)) return path;
425
+ return `${MEDIA_CDN_ROUTE}/${hostQualifiedScope(scope, hostId)}${rest.slice(slash)}`;
426
+ }
406
427
  /**
407
428
  * The render-time resolver every surface shares. Precedence, in order:
408
429
  *
@@ -411,10 +432,13 @@ const SEGMENT = new RegExp(`^${SEGMENT_SOURCE}$`);
411
432
  * 2. a **Storage download URL for a library object** → the same CDN URL,
412
433
  * exactly as if the reference had been stored (AGL-3506). See
413
434
  * {@link mediaRefFromStorageUrl};
414
- * 3. any other non-empty string → **itself, untouched**. Nodes holding an
415
- * `/api/media/cdn/…` path written by the first pass and an author-typed
416
- * external URL for a hotlinked image are passed through;
417
- * 4. empty/absent → undefined, so the caller shows its placeholder.
435
+ * 3. a **legacy stored CDN path** written by the first pass → itself, naming
436
+ * the site doing the rendering if its org scope names none yet. See
437
+ * {@link hostQualifiedLegacyPath};
438
+ * 4. any other non-empty string → **itself, untouched**. An author-typed
439
+ * external URL for a hotlinked image is passed through, and so is a signed
440
+ * CDN URL, which {@link isMediaCdnPath} does not answer for;
441
+ * 5. empty/absent → undefined, so the caller shows its placeholder.
418
442
  *
419
443
  * Branch 2 is what routes every library byte through the CDN. A download
420
444
  * URL goes from Google's edge straight to the visitor, so no code of ours
@@ -433,10 +457,12 @@ const SEGMENT = new RegExp(`^${SEGMENT_SOURCE}$`);
433
457
  if (!value) return undefined;
434
458
  const stored = isMediaRef(value) ? value : mediaRefFromStorageUrl(value);
435
459
  if (!stored) {
460
+ if (!isMediaCdnPath(value)) return value;
436
461
  // A legacy stored CDN path names the same asset on the same route, so it
437
462
  // takes the version as a reference does (AGL-3485).
438
- const token = isMediaCdnPath(value) ? mediaCdnVersionToken(options == null ? void 0 : options.version) : undefined;
439
- return token ? `${value}?${MEDIA_CDN_VERSION_PARAM}=${token}` : value;
463
+ const path = hostQualifiedLegacyPath(value, options == null ? void 0 : options.hostId);
464
+ const token = mediaCdnVersionToken(options == null ? void 0 : options.version);
465
+ return token ? `${path}?${MEDIA_CDN_VERSION_PARAM}=${token}` : path;
440
466
  }
441
467
  const ref = parseMediaRef(stored);
442
468
  if (!ref) return undefined;