@wildo-ai/external-connectors-public 1.1.11 → 1.1.13
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/dist/esm/app/compose-frontend-app-providers.d.ts.map +1 -1
- package/dist/esm/app/compose-frontend-app-providers.js.map +1 -1
- package/dist/esm/app/compose-hydrated-frontend-app-providers.d.ts.map +1 -1
- package/dist/esm/app/compose-hydrated-frontend-app-providers.js.map +1 -1
- package/dist/esm/app/engine-frontend-app-provider-registry.d.ts.map +1 -1
- package/dist/esm/app/engine-frontend-app-provider-registry.js.map +1 -1
- package/dist/esm/app/frontend-app-provider-module.types.d.ts.map +1 -1
- package/dist/esm/app/frontend-app-provider-module.types.js.map +1 -1
- package/dist/esm/app/frontend-app-provider-registry.types.d.ts.map +1 -1
- package/dist/esm/app/frontend-app-provider-registry.types.js.map +1 -1
- package/dist/esm/app/index.d.ts.map +1 -1
- package/dist/esm/app/index.js.map +1 -1
- package/dist/esm/companion-exports.d.ts.map +1 -1
- package/dist/esm/companion-exports.js +36 -1
- package/dist/esm/companion-exports.js.map +1 -1
- package/dist/esm/engine-frontend-providers-package.d.ts.map +1 -1
- package/dist/esm/engine-frontend-providers-package.js.map +1 -1
- package/dist/esm/providers/dropbox/dropbox.frontend-app.module.d.ts.map +1 -1
- package/dist/esm/providers/dropbox/dropbox.frontend-app.module.js +19 -2
- package/dist/esm/providers/dropbox/dropbox.frontend-app.module.js.map +1 -1
- package/dist/esm/providers/dropbox/index.d.ts.map +1 -1
- package/dist/esm/providers/dropbox/index.js.map +1 -1
- package/dist/esm/providers/google-drive/google-drive.frontend-app.module.d.ts.map +1 -1
- package/dist/esm/providers/google-drive/google-drive.frontend-app.module.js +21 -3
- package/dist/esm/providers/google-drive/google-drive.frontend-app.module.js.map +1 -1
- package/dist/esm/providers/google-drive/index.d.ts.map +1 -1
- package/dist/esm/providers/google-drive/index.js.map +1 -1
- package/dist/esm/providers/google-places/google-places.frontend-app.module.d.ts.map +1 -1
- package/dist/esm/providers/google-places/google-places.frontend-app.module.js +8 -2
- package/dist/esm/providers/google-places/google-places.frontend-app.module.js.map +1 -1
- package/dist/esm/providers/microsoft-onedrive/index.d.ts.map +1 -1
- package/dist/esm/providers/microsoft-onedrive/index.js.map +1 -1
- package/dist/esm/providers/microsoft-onedrive/microsoft-onedrive.frontend-app.module.d.ts.map +1 -1
- package/dist/esm/providers/microsoft-onedrive/microsoft-onedrive.frontend-app.module.js +26 -3
- package/dist/esm/providers/microsoft-onedrive/microsoft-onedrive.frontend-app.module.js.map +1 -1
- package/dist/esm/providers/recaptcha/index.d.ts.map +1 -1
- package/dist/esm/providers/recaptcha/index.js.map +1 -1
- package/dist/esm/providers/recaptcha/recaptcha.frontend-website.module.d.ts.map +1 -1
- package/dist/esm/providers/recaptcha/recaptcha.frontend-website.module.js +11 -3
- package/dist/esm/providers/recaptcha/recaptcha.frontend-website.module.js.map +1 -1
- package/dist/esm/shared/activate-frontend-provider-sdks.d.ts.map +1 -1
- package/dist/esm/shared/activate-frontend-provider-sdks.js.map +1 -1
- package/dist/esm/shared/frontend-provider-consent.d.ts +7 -0
- package/dist/esm/shared/frontend-provider-consent.d.ts.map +1 -1
- package/dist/esm/shared/frontend-provider-consent.js +2 -0
- package/dist/esm/shared/frontend-provider-consent.js.map +1 -1
- package/dist/esm/shared/frontend-provider-on-demand.d.ts.map +1 -1
- package/dist/esm/shared/frontend-provider-on-demand.js.map +1 -1
- package/dist/esm/shared/frontend-provider-surface.types.d.ts.map +1 -1
- package/dist/esm/shared/frontend-provider-surface.types.js.map +1 -1
- package/dist/esm/shared/hydrate-frontend-providers.d.ts.map +1 -1
- package/dist/esm/shared/hydrate-frontend-providers.js.map +1 -1
- package/dist/esm/shared/load-frontend-provider-scripts.d.ts.map +1 -1
- package/dist/esm/shared/load-frontend-provider-scripts.js.map +1 -1
- package/dist/esm/shared/provider-component-registry.d.ts.map +1 -1
- package/dist/esm/shared/provider-component-registry.js.map +1 -1
- package/dist/esm/techdoc/compose-frontend-techdoc-providers.d.ts.map +1 -1
- package/dist/esm/techdoc/compose-frontend-techdoc-providers.js.map +1 -1
- package/dist/esm/techdoc/compose-hydrated-frontend-techdoc-providers.d.ts.map +1 -1
- package/dist/esm/techdoc/compose-hydrated-frontend-techdoc-providers.js.map +1 -1
- package/dist/esm/techdoc/engine-frontend-techdoc-provider-registry.d.ts.map +1 -1
- package/dist/esm/techdoc/engine-frontend-techdoc-provider-registry.js.map +1 -1
- package/dist/esm/techdoc/frontend-techdoc-provider-module.types.d.ts.map +1 -1
- package/dist/esm/techdoc/frontend-techdoc-provider-module.types.js.map +1 -1
- package/dist/esm/techdoc/frontend-techdoc-provider-registry.types.d.ts.map +1 -1
- package/dist/esm/techdoc/frontend-techdoc-provider-registry.types.js.map +1 -1
- package/dist/esm/techdoc/index.d.ts.map +1 -1
- package/dist/esm/techdoc/index.js.map +1 -1
- package/dist/esm/website/compose-frontend-website-providers.d.ts.map +1 -1
- package/dist/esm/website/compose-frontend-website-providers.js.map +1 -1
- package/dist/esm/website/compose-hydrated-frontend-website-providers.d.ts.map +1 -1
- package/dist/esm/website/compose-hydrated-frontend-website-providers.js.map +1 -1
- package/dist/esm/website/engine-frontend-website-provider-registry.d.ts.map +1 -1
- package/dist/esm/website/engine-frontend-website-provider-registry.js.map +1 -1
- package/dist/esm/website/frontend-website-provider-module.types.d.ts.map +1 -1
- package/dist/esm/website/frontend-website-provider-module.types.js.map +1 -1
- package/dist/esm/website/frontend-website-provider-registry.types.d.ts.map +1 -1
- package/dist/esm/website/frontend-website-provider-registry.types.js.map +1 -1
- package/dist/esm/website/index.d.ts.map +1 -1
- package/dist/esm/website/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +7 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend-provider-consent.js","sourceRoot":"","sources":["../../../../src/shared/frontend-provider-consent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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EAAkE,CAAC;IACzE,CAAC;IACD,OAAO,aAAa,WAAW,yBAAyB,iCAAiC,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;UACpI,6CAA6C,CAAC;AACpD,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,+BAA+B,CAAC,OAAgE;IAC9G,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,KAAK,MAAM,MAAM,IAAI,OAAO,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,iCAAiC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7F,OAAO,wBAAwB,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAWD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,+BAA+B,CAAC,WAAmB,EAAE,MAAsC;IACzG,MAAM,QAAQ,GAAG,iCAAiC,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,OAAO,aAAa,WAAW,yBAAyB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,+CAA+C;cACtH,+GAA+G;cAC/G,kBAAkB,CAAC;IACzB,CAAC;IACD,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;QAC9D,OAAO,aAAa,WAAW,yBAAyB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,iDAAiD;cACxH,oHAAoH;cACpH,0BAA0B,CAAC;IACjC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Which frontend providers may start before a person consents, and which may not (#534, #1702).\n *\n * ## Why the floor lives on the CAPABILITY\n *\n * A vendor is not a purpose. PostHog is product analytics on the website and could be something else\n * tomorrow; what makes it consent-based is the capability it is registered for. So the floor is keyed by\n * `ProviderCapability`. A table of vendor names would be a second catalogue that rots.\n *\n * ## Why the table is total over the WHOLE vocabulary, not over `FRONTEND_*` names (#1702)\n *\n * It used to be total over `Extract<ProviderCapability, 'FRONTEND_${string}'>` and to answer \"no\n * consent\" for every other capability. That made the compile-time forcing depend on a naming\n * convention, and the fallback fail OPEN: frontend modules then declared `BILLING` and `SSO_OAUTH2`,\n * and a vendor declaring any other non-prefixed capability on its frontend module — or a future member\n * named without the prefix — would have started without consent, with nothing saying so.\n *\n * So every capability is classified here, and a new member of the vocabulary is a compile error until\n * somebody decides two things about it: can a browser host it at all, and if so, which purposes does it\n * rest on. A capability that is not browser-hosted may not be declared by a frontend module:\n * `projectFrontendProviderContribution` refuses the module, and at runtime the provider is never\n * permitted to start (fail closed), so a stale or hand-written entry cannot slip past the projection.\n * The `FRONTEND_` prefix remains a naming convention and nothing else.\n *\n * ## The floor, and why most capabilities need no consent\n *\n * - `FRONTEND_PRODUCT_ANALYTICS` measures how the service is used — `ConsentPurpose.ANALYTICS`.\n * - Error monitoring, captcha, search, file pickers, address lookup and sign-in code deliver or protect\n * a service the visitor asked for. They are not consent-based\n * processing; their lawful basis is the operator's to state in `operatorComplianceIdentity`, not a\n * banner's to ask. Gating them on consent would break the site for everyone who declines, which is the\n * opposite of what declining means.\n *\n * ## A vendor may add to the floor, never remove from it (#1702)\n *\n * Some vendors do more than their capability's floor. Google reCAPTCHA is the measured case: the CNIL\n * held that it is not exempt from consent as a security measure, because it also serves Google's own\n * analysis (Délibération SAN-2023-003), while a privacy-preserving captcha is exempt. The capability\n * cannot express that difference, so a frontend module may declare `consentPurposes` of its own, and the\n * provider rests on the UNION of those and its capabilities' floor. There is no field that subtracts: a\n * provider declaring `consentPurposes: []` on an analytics capability still rests on `ANALYTICS`.\n *\n * spec-cite: https://www.legifrance.gouv.fr/cnil/id/CNILTEXT000047346903 — the reCAPTCHA holding is\n * summarised from issue #1702's research, not quoted; no sentence of the decision is reproduced here.\n *\n * ## Where it is enforced\n *\n * In the shared runners — `activateFrontendProviderSdks` and `collectDeclaredProviderScripts` — and at\n * component load (`@wildo-ai/saas-frontend-lib`'s provider component registry), so no surface can\n * forget it. The SDK runner and the component registry take the granted purposes and default to NONE, so a\n * call that passes no grant — the SaaS application's startup activation, which runs before any person is known,\n * and the technical documentation, which asks no one — starts no consent-based provider rather than starting it\n * on an assumed consent. The script collector takes no grant at all: it never collects a consent-based\n * provider's scripts, granted or not (#1704). An application-tier consent-based SDK (the app-tier PostHog module is the first) is\n * activated by `ConsentBasedProviderSdksProvider` in `@wildo-ai/saas-frontend-lib`, which holds the signed-in\n * person's granted purposes (#1704).\n *\n * A consent-based provider must also be STOPPABLE ({@link consentBasedProviderStopRefusal}): refused at projection,\n * withheld at hydration, and skipped by the SDK runner, the script collector and the component registry.\n */\n\nimport {\n CONSENT_PURPOSES,\n ConsentPurpose,\n missingConsentPurposes,\n normalizeConsentPurposes,\n type ProviderCapability,\n} from '@wildo-ai/saas-models/public-runtime';\n\n/**\n * How a capability stands with respect to a browser and to consent.\n *\n * Two arms rather than a nullable purpose list, because \"needs no consent\" (`[]`) and \"cannot be hosted\n * by a browser at all\" are opposite answers, and a `null` standing for the second would be the silent\n * fallback this table exists to remove.\n */\nexport type FrontendCapabilityConsentClassification =\n | {\n /** A frontend module may declare this capability. */\n readonly browserHosted: true;\n /** The consent floor: purposes every provider of this capability rests on. Empty means none. */\n readonly consentPurposes: readonly ConsentPurpose[];\n }\n | {\n /**\n * The capability runs server-side only (a mail sender, an LLM, an audit sink). A frontend module\n * declaring it is refused at projection and never permitted to start.\n */\n readonly browserHosted: false;\n };\n\nconst SERVER_ONLY: FrontendCapabilityConsentClassification = Object.freeze({ browserHosted: false });\nconst HOSTED_WITHOUT_CONSENT: FrontendCapabilityConsentClassification = Object.freeze({\n browserHosted: true,\n consentPurposes: Object.freeze([]),\n});\n\n/** @wildo_source:part:start external-connectors.frontend-provider-consent-classification facet:kind:api facet:audience:app-developer */\n/**\n * The consent classification of EVERY provider capability — total over the vocabulary, so a capability\n * added tomorrow does not compile until it is classified here (#1702).\n *\n * A frontend provider module may declare only capabilities classified `browserHosted: true`; it rests on\n * the union of their `consentPurposes` and its own module-level `consentPurposes`.\n */\nexport const PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION = Object.freeze({\n // Browser-hosted, consent-based: measuring how the service is used.\n FRONTEND_PRODUCT_ANALYTICS: Object.freeze({ browserHosted: true, consentPurposes: Object.freeze([ConsentPurpose.ANALYTICS]) }),\n // Browser-hosted, no consent at the floor: each delivers or protects a service the person asked for.\n FRONTEND_ERROR_MONITORING: HOSTED_WITHOUT_CONSENT,\n FRONTEND_CAPTCHA: HOSTED_WITHOUT_CONSENT,\n FRONTEND_SEARCH: HOSTED_WITHOUT_CONSENT,\n FRONTEND_FILE_PICKER: HOSTED_WITHOUT_CONSENT,\n FRONTEND_ADDRESS_LOOKUP: HOSTED_WITHOUT_CONSENT,\n // Telling the chat host that opened the sign-in window that the sign-in finished: the person asked to sign in.\n FRONTEND_CHAT_SIGN_IN_COMPLETION: HOSTED_WITHOUT_CONSENT,\n // Browser sign-in code (a vendor's one-tap or button SDK). The person asked to sign in; that is not\n // consent-based processing. No engine module declares it today: the redirect-based sign-in the engine\n // ships runs no vendor code on the page, and its button labels come from the ref (#1701).\n SSO_OAUTH2: HOSTED_WITHOUT_CONSENT,\n // Server-side only. A frontend module declaring any of these is refused.\n // BILLING is the backend billing slot (subscriptions, checkout sessions, the portal link, webhooks).\n // Checkout and the customer portal are hosted redirects, so no billing code runs in the browser; a\n // frontend module declaring it used to FILL the engine's billing slot from the browser (#1701). An\n // embedded payment UI would be its own browser capability, decided in #1741.\n BILLING: SERVER_ONLY,\n EMAIL_TRANSACTIONAL: SERVER_ONLY,\n EMAIL_MARKETING: SERVER_ONLY,\n EMAIL_INBOUND: SERVER_ONLY,\n SMS: SERVER_ONLY,\n SSO_SAML: SERVER_ONLY,\n LLM_CHAT: SERVER_ONLY,\n LLM_EMBEDDINGS: SERVER_ONLY,\n DOCUMENT_TEXT_EXTRACTION: SERVER_ONLY,\n PROMPT_INJECTION_SCREENING: SERVER_ONLY,\n OUTPUT_MODERATION: SERVER_ONLY,\n CODING_AGENT: SERVER_ONLY,\n IMAGE_GENERATION: SERVER_ONLY,\n LLM_OBSERVABILITY: SERVER_ONLY,\n OBSERVABILITY_TELEMETRY: SERVER_ONLY,\n COMPLIANCE_AUDIT_TRAIL: SERVER_ONLY,\n // Key custody signs, MACs and wraps with keys a browser must never hold or reach (#2891).\n KEY_MANAGEMENT: SERVER_ONLY,\n} as const satisfies Readonly<Record<ProviderCapability, FrontendCapabilityConsentClassification>>);\n/** @wildo_source:part:end external-connectors.frontend-provider-consent-classification */\n\ntype ConsentClassificationTable = typeof PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION;\n\n/** The capabilities a browser surface can host — DERIVED from the classification, never from a name prefix. */\nexport type FrontendProviderCapability = {\n [K in keyof ConsentClassificationTable]: ConsentClassificationTable[K]['browserHosted'] extends true ? K : never;\n}[keyof ConsentClassificationTable];\n\n/** The shape this module needs off a provider module or DATA entry. */\nexport interface ConsentClassifiableProviderModule {\n readonly providerCapabilities?: ReadonlyArray<string>;\n /**\n * Purposes the provider rests on BEYOND its capabilities' floor — the vendor-level addition (#1702).\n * Typed as strings because a hydrated module reads it off the wire; an unknown member is refused at\n * projection and makes the provider unpermitted at runtime rather than being dropped.\n */\n readonly consentPurposes?: ReadonlyArray<string>;\n}\n\nfunction classificationOf(capability: string): FrontendCapabilityConsentClassification | undefined {\n return Object.prototype.hasOwnProperty.call(PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION, capability)\n ? (PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION as Readonly<Record<string, FrontendCapabilityConsentClassification>>)[capability]\n : undefined;\n}\n\n/**\n * Every capability the provider declares that a browser may NOT host — server-only capabilities and\n * strings that are no capability at all. Empty for a correctly classified frontend provider.\n */\nexport function unclassifiedFrontendCapabilities(module: ConsentClassifiableProviderModule): string[] {\n return (module.providerCapabilities ?? []).filter((capability) => classificationOf(capability)?.browserHosted !== true);\n}\n\n/** Every provider-level consent purpose that is not a member of `ConsentPurpose`. */\nexport function unknownProviderConsentPurposes(module: ConsentClassifiableProviderModule): string[] {\n const known = new Set<string>(CONSENT_PURPOSES);\n return (module.consentPurposes ?? []).filter((purpose) => !known.has(purpose));\n}\n\n/**\n * Every consent purpose a provider rests on, in vocabulary order: the union of its capabilities' floor\n * and its own module-level `consentPurposes`. Nothing a provider declares can remove a purpose its\n * capability requires — the union has no subtracting input.\n */\nexport function consentPurposesRequiredByProvider(module: ConsentClassifiableProviderModule): ConsentPurpose[] {\n const required: string[] = [...(module.consentPurposes ?? [])];\n for (const capability of module.providerCapabilities ?? []) {\n const classification = classificationOf(capability);\n if (classification?.browserHosted === true) required.push(...classification.consentPurposes);\n }\n return normalizeConsentPurposes(required);\n}\n\n/**\n * Whether a provider may start given the purposes granted.\n *\n * FAILS CLOSED on a provider whose classification is broken — a capability no browser may host, or a\n * provider-level purpose outside the vocabulary. The projection refuses both, so reaching here with one\n * means an entry that bypassed it (a stale artifact, the backend's non-refusing fallback, a hand-written\n * contribution); starting it anyway would be the fail-open defect #1702 closes.\n */\nexport function isProviderPermittedByConsent(\n module: ConsentClassifiableProviderModule,\n grantedConsentPurposes: readonly ConsentPurpose[],\n): boolean {\n if (unclassifiedFrontendCapabilities(module).length > 0) return false;\n if (unknownProviderConsentPurposes(module).length > 0) return false;\n return missingConsentPurposes(grantedConsentPurposes, consentPurposesRequiredByProvider(module)).length === 0;\n}\n\n/**\n * The purposes the person would have to grant for this provider to start — what a consent-required\n * state names and offers. Empty both when the provider is permitted and when no grant could permit it\n * (a broken classification); `isProviderPermittedByConsent` tells the two apart.\n */\nexport function missingConsentPurposesForProvider(\n module: ConsentClassifiableProviderModule,\n grantedConsentPurposes: readonly ConsentPurpose[],\n): ConsentPurpose[] {\n return missingConsentPurposes(grantedConsentPurposes, consentPurposesRequiredByProvider(module));\n}\n\n/**\n * One sentence saying why a provider was withheld, for a diagnostic. Distinguishes the two reasons,\n * because their remedies are opposite: a missing grant is the person's to give, a broken classification\n * is the provider author's to fix.\n */\nexport function describeProviderConsentRefusal(\n providerRef: string,\n module: ConsentClassifiableProviderModule,\n grantedConsentPurposes: readonly ConsentPurpose[],\n): string {\n const unclassified = unclassifiedFrontendCapabilities(module);\n if (unclassified.length > 0) {\n return `Provider \"${providerRef}\" declares ${unclassified.join(', ')}, which no browser surface may host, so it `\n + 'never starts. Remove the capability from its frontend module.';\n }\n const unknownPurposes = unknownProviderConsentPurposes(module);\n if (unknownPurposes.length > 0) {\n return `Provider \"${providerRef}\" declares consent purposes ${unknownPurposes.join(', ')}, which are not consent `\n + 'purposes, so it never starts. Declare members of ConsentPurpose.';\n }\n return `Provider \"${providerRef}\" rests on consent to ${missingConsentPurposesForProvider(module, grantedConsentPurposes).join(', ')}, `\n + 'which has not been granted on this surface.';\n}\n\n/** Every purpose the given providers rest on — what a consent surface must ask about, and nothing more. */\nexport function consentPurposesInUseByProviders(modules: Iterable<ConsentClassifiableProviderModule> | undefined): ConsentPurpose[] {\n const inUse: ConsentPurpose[] = [];\n for (const module of modules ?? []) inUse.push(...consentPurposesRequiredByProvider(module));\n return normalizeConsentPurposes(inUse);\n}\n\n/**\n * The code-bearing shape the stop rule needs: whether a provider injects `<script>` tags, and whether\n * its SDK declares that it can be stopped.\n */\nexport interface StoppableConsentProviderModule extends ConsentClassifiableProviderModule {\n readonly scripts?: ReadonlyArray<unknown>;\n readonly sdk?: { readonly stoppable?: true };\n}\n\n/**\n * Why a CONSENT-BASED provider cannot honour a withdrawal, or `undefined` when it can (#1704).\n *\n * Consent can be withdrawn at any moment and must be as easy to withdraw as to give, so a provider that\n * starts on a grant must be stoppable on the withdrawal of that grant, in the same page. Two shapes\n * cannot be:\n *\n * - **`scripts`.** A `<script>` tag is DATA: the framework injects it and has no handle on what it runs.\n * Removing the element afterwards undoes nothing — the vendor's globals, listeners, timers and the\n * storage it wrote all stay (`load-frontend-provider-scripts.ts` says the same). A consent-based\n * vendor that ships as a script loads it from inside its own `sdk.activate` instead, where it can\n * also stop it.\n * - **An SDK that does not declare `stoppable`.** Whether `activate()` returns a `deactivate` is only\n * known after the vendor has started, which is too late to refuse. So the SDK states it up front,\n * and a declared SDK whose activation then returns no `deactivate` is reported by the runner.\n *\n * Asked at projection (the provider package's own `./companion` barrel refuses) and at hydration (the\n * provider's code and scripts are withheld with a diagnostic), so neither a stale artifact nor a\n * hand-written contribution can start an unstoppable consent-based provider. A provider resting on no\n * purpose is never refused here: nothing can be withdrawn from it.\n */\nexport function consentBasedProviderStopRefusal(providerRef: string, module: StoppableConsentProviderModule): string | undefined {\n const purposes = consentPurposesRequiredByProvider(module);\n if (purposes.length === 0) return undefined;\n if ((module.scripts?.length ?? 0) > 0) {\n return `Provider \"${providerRef}\" rests on consent to ${purposes.join(', ')} and declares <script> tags, which cannot be `\n + 'stopped when that consent is withdrawn. Load the script from inside its sdk.activate and return a deactivate '\n + 'instead (#1704).';\n }\n if (module.sdk !== undefined && module.sdk.stoppable !== true) {\n return `Provider \"${providerRef}\" rests on consent to ${purposes.join(', ')} and its SDK does not declare stoppable: true, `\n + 'so a withdrawal could not stop it. Return a deactivate from sdk.activate that fully stops the vendor, and declare '\n + 'stoppable: true (#1704).';\n }\n return undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"frontend-provider-consent.js","sourceRoot":"","sources":["../../../src/shared/frontend-provider-consent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAEH,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,sBAAsB,EACtB,wBAAwB,GAEzB,MAAM,sCAAsC,CAAC;AAwB9C,MAAM,WAAW,GAA4C,MAAM,C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CAAC;AACpD,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,+BAA+B,CAAC,OAAgE;IAC9G,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,KAAK,MAAM,MAAM,IAAI,OAAO,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,iCAAiC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7F,OAAO,wBAAwB,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAWD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,+BAA+B,CAAC,WAAmB,EAAE,MAAsC;IACzG,MAAM,QAAQ,GAAG,iCAAiC,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,OAAO,aAAa,WAAW,yBAAyB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,+CAA+C;cACtH,+GAA+G;cAC/G,kBAAkB,CAAC;IACzB,CAAC;IACD,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;QAC9D,OAAO,aAAa,WAAW,yBAAyB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,iDAAiD;cACxH,oHAAoH;cACpH,0BAA0B,CAAC;IACjC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Which frontend providers may start before a person consents, and which may not (#534, #1702).\n *\n * ## Why the floor lives on the CAPABILITY\n *\n * A vendor is not a purpose. PostHog is product analytics on the website and could be something else\n * tomorrow; what makes it consent-based is the capability it is registered for. So the floor is keyed by\n * `ProviderCapability`. A table of vendor names would be a second catalogue that rots.\n *\n * ## Why the table is total over the WHOLE vocabulary, not over `FRONTEND_*` names (#1702)\n *\n * It used to be total over `Extract<ProviderCapability, 'FRONTEND_${string}'>` and to answer \"no\n * consent\" for every other capability. That made the compile-time forcing depend on a naming\n * convention, and the fallback fail OPEN: frontend modules then declared `BILLING` and `SSO_OAUTH2`,\n * and a vendor declaring any other non-prefixed capability on its frontend module — or a future member\n * named without the prefix — would have started without consent, with nothing saying so.\n *\n * So every capability is classified here, and a new member of the vocabulary is a compile error until\n * somebody decides two things about it: can a browser host it at all, and if so, which purposes does it\n * rest on. A capability that is not browser-hosted may not be declared by a frontend module:\n * `projectFrontendProviderContribution` refuses the module, and at runtime the provider is never\n * permitted to start (fail closed), so a stale or hand-written entry cannot slip past the projection.\n * The `FRONTEND_` prefix remains a naming convention and nothing else.\n *\n * ## The floor, and why most capabilities need no consent\n *\n * - `FRONTEND_PRODUCT_ANALYTICS` measures how the service is used — `ConsentPurpose.ANALYTICS`.\n * - Error monitoring, captcha, search, file pickers, address lookup and sign-in code deliver or protect\n * a service the visitor asked for. They are not consent-based\n * processing; their lawful basis is the operator's to state in `operatorComplianceIdentity`, not a\n * banner's to ask. Gating them on consent would break the site for everyone who declines, which is the\n * opposite of what declining means.\n *\n * ## A vendor may add to the floor, never remove from it (#1702)\n *\n * Some vendors do more than their capability's floor. Google reCAPTCHA is the measured case: the CNIL\n * held that it is not exempt from consent as a security measure, because it also serves Google's own\n * analysis (Délibération SAN-2023-003), while a privacy-preserving captcha is exempt. The capability\n * cannot express that difference, so a frontend module may declare `consentPurposes` of its own, and the\n * provider rests on the UNION of those and its capabilities' floor. There is no field that subtracts: a\n * provider declaring `consentPurposes: []` on an analytics capability still rests on `ANALYTICS`.\n *\n * spec-cite: https://www.legifrance.gouv.fr/cnil/id/CNILTEXT000047346903 — the reCAPTCHA holding is\n * summarised from issue #1702's research, not quoted; no sentence of the decision is reproduced here.\n *\n * ## Where it is enforced\n *\n * In the shared runners — `activateFrontendProviderSdks` and `collectDeclaredProviderScripts` — and at\n * component load (`@wildo-ai/saas-frontend-lib`'s provider component registry), so no surface can\n * forget it. The SDK runner and the component registry take the granted purposes and default to NONE, so a\n * call that passes no grant — the SaaS application's startup activation, which runs before any person is known,\n * and the technical documentation, which asks no one — starts no consent-based provider rather than starting it\n * on an assumed consent. The script collector takes no grant at all: it never collects a consent-based\n * provider's scripts, granted or not (#1704). An application-tier consent-based SDK (the app-tier PostHog module is the first) is\n * activated by `ConsentBasedProviderSdksProvider` in `@wildo-ai/saas-frontend-lib`, which holds the signed-in\n * person's granted purposes (#1704).\n *\n * A consent-based provider must also be STOPPABLE ({@link consentBasedProviderStopRefusal}): refused at projection,\n * withheld at hydration, and skipped by the SDK runner, the script collector and the component registry.\n */\n\nimport {\n CONSENT_PURPOSES,\n ConsentPurpose,\n missingConsentPurposes,\n normalizeConsentPurposes,\n type ProviderCapability,\n} from '@wildo-ai/saas-models/public-runtime';\n\n/**\n * How a capability stands with respect to a browser and to consent.\n *\n * Two arms rather than a nullable purpose list, because \"needs no consent\" (`[]`) and \"cannot be hosted\n * by a browser at all\" are opposite answers, and a `null` standing for the second would be the silent\n * fallback this table exists to remove.\n */\nexport type FrontendCapabilityConsentClassification =\n | {\n /** A frontend module may declare this capability. */\n readonly browserHosted: true;\n /** The consent floor: purposes every provider of this capability rests on. Empty means none. */\n readonly consentPurposes: readonly ConsentPurpose[];\n }\n | {\n /**\n * The capability runs server-side only (a mail sender, an LLM, an audit sink). A frontend module\n * declaring it is refused at projection and never permitted to start.\n */\n readonly browserHosted: false;\n };\n\nconst SERVER_ONLY: FrontendCapabilityConsentClassification = Object.freeze({ browserHosted: false });\nconst HOSTED_WITHOUT_CONSENT: FrontendCapabilityConsentClassification = Object.freeze({\n browserHosted: true,\n consentPurposes: Object.freeze([]),\n});\n\n/** @wildo_source:part:start external-connectors.frontend-provider-consent-classification facet:kind:api facet:audience:app-developer */\n/**\n * The consent classification of EVERY provider capability — total over the vocabulary, so a capability\n * added tomorrow does not compile until it is classified here (#1702).\n *\n * A frontend provider module may declare only capabilities classified `browserHosted: true`; it rests on\n * the union of their `consentPurposes` and its own module-level `consentPurposes`.\n */\nexport const PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION = Object.freeze({\n // Browser-hosted, consent-based: measuring how the service is used.\n FRONTEND_PRODUCT_ANALYTICS: Object.freeze({ browserHosted: true, consentPurposes: Object.freeze([ConsentPurpose.ANALYTICS]) }),\n // Browser-hosted, no consent at the floor: each delivers or protects a service the person asked for.\n FRONTEND_ERROR_MONITORING: HOSTED_WITHOUT_CONSENT,\n FRONTEND_CAPTCHA: HOSTED_WITHOUT_CONSENT,\n FRONTEND_SEARCH: HOSTED_WITHOUT_CONSENT,\n FRONTEND_FILE_PICKER: HOSTED_WITHOUT_CONSENT,\n FRONTEND_ADDRESS_LOOKUP: HOSTED_WITHOUT_CONSENT,\n // Telling the chat host that opened the sign-in window that the sign-in finished: the person asked to sign in.\n FRONTEND_CHAT_SIGN_IN_COMPLETION: HOSTED_WITHOUT_CONSENT,\n // Browser sign-in code (a vendor's one-tap or button SDK). The person asked to sign in; that is not\n // consent-based processing. No engine module declares it today: the redirect-based sign-in the engine\n // ships runs no vendor code on the page, and its button labels come from the ref (#1701).\n SSO_OAUTH2: HOSTED_WITHOUT_CONSENT,\n // Server-side only. A frontend module declaring any of these is refused.\n // BILLING is the backend billing slot (subscriptions, checkout sessions, the portal link, webhooks).\n // Checkout and the customer portal are hosted redirects, so no billing code runs in the browser; a\n // frontend module declaring it used to FILL the engine's billing slot from the browser (#1701). An\n // embedded payment UI would be its own browser capability, decided in #1741.\n BILLING: SERVER_ONLY,\n EMAIL_TRANSACTIONAL: SERVER_ONLY,\n EMAIL_MARKETING: SERVER_ONLY,\n EMAIL_INBOUND: SERVER_ONLY,\n SMS: SERVER_ONLY,\n // #2293: a deliverable is sent for signature from the backend; the vendor's signing page is its own, not a browser SDK.\n ELECTRONIC_SIGNATURE: SERVER_ONLY,\n SSO_SAML: SERVER_ONLY,\n LLM_CHAT: SERVER_ONLY,\n LLM_EMBEDDINGS: SERVER_ONLY,\n DOCUMENT_TEXT_EXTRACTION: SERVER_ONLY,\n PROMPT_INJECTION_SCREENING: SERVER_ONLY,\n OUTPUT_MODERATION: SERVER_ONLY,\n CODING_AGENT: SERVER_ONLY,\n IMAGE_GENERATION: SERVER_ONLY,\n LLM_OBSERVABILITY: SERVER_ONLY,\n OBSERVABILITY_TELEMETRY: SERVER_ONLY,\n COMPLIANCE_AUDIT_TRAIL: SERVER_ONLY,\n // Key custody signs, MACs and wraps with keys a browser must never hold or reach (#2891).\n KEY_MANAGEMENT: SERVER_ONLY,\n} as const satisfies Readonly<Record<ProviderCapability, FrontendCapabilityConsentClassification>>);\n/** @wildo_source:part:end external-connectors.frontend-provider-consent-classification */\n\ntype ConsentClassificationTable = typeof PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION;\n\n/** The capabilities a browser surface can host — DERIVED from the classification, never from a name prefix. */\nexport type FrontendProviderCapability = {\n [K in keyof ConsentClassificationTable]: ConsentClassificationTable[K]['browserHosted'] extends true ? K : never;\n}[keyof ConsentClassificationTable];\n\n/** The shape this module needs off a provider module or DATA entry. */\nexport interface ConsentClassifiableProviderModule {\n readonly providerCapabilities?: ReadonlyArray<string>;\n /**\n * Purposes the provider rests on BEYOND its capabilities' floor — the vendor-level addition (#1702).\n * Typed as strings because a hydrated module reads it off the wire; an unknown member is refused at\n * projection and makes the provider unpermitted at runtime rather than being dropped.\n */\n readonly consentPurposes?: ReadonlyArray<string>;\n}\n\nfunction classificationOf(capability: string): FrontendCapabilityConsentClassification | undefined {\n return Object.prototype.hasOwnProperty.call(PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION, capability)\n ? (PROVIDER_CAPABILITY_FRONTEND_CONSENT_CLASSIFICATION as Readonly<Record<string, FrontendCapabilityConsentClassification>>)[capability]\n : undefined;\n}\n\n/**\n * Every capability the provider declares that a browser may NOT host — server-only capabilities and\n * strings that are no capability at all. Empty for a correctly classified frontend provider.\n */\nexport function unclassifiedFrontendCapabilities(module: ConsentClassifiableProviderModule): string[] {\n return (module.providerCapabilities ?? []).filter((capability) => classificationOf(capability)?.browserHosted !== true);\n}\n\n/** Every provider-level consent purpose that is not a member of `ConsentPurpose`. */\nexport function unknownProviderConsentPurposes(module: ConsentClassifiableProviderModule): string[] {\n const known = new Set<string>(CONSENT_PURPOSES);\n return (module.consentPurposes ?? []).filter((purpose) => !known.has(purpose));\n}\n\n/**\n * Every consent purpose a provider rests on, in vocabulary order: the union of its capabilities' floor\n * and its own module-level `consentPurposes`. Nothing a provider declares can remove a purpose its\n * capability requires — the union has no subtracting input.\n */\nexport function consentPurposesRequiredByProvider(module: ConsentClassifiableProviderModule): ConsentPurpose[] {\n const required: string[] = [...(module.consentPurposes ?? [])];\n for (const capability of module.providerCapabilities ?? []) {\n const classification = classificationOf(capability);\n if (classification?.browserHosted === true) required.push(...classification.consentPurposes);\n }\n return normalizeConsentPurposes(required);\n}\n\n/**\n * Whether a provider may start given the purposes granted.\n *\n * FAILS CLOSED on a provider whose classification is broken — a capability no browser may host, or a\n * provider-level purpose outside the vocabulary. The projection refuses both, so reaching here with one\n * means an entry that bypassed it (a stale artifact, the backend's non-refusing fallback, a hand-written\n * contribution); starting it anyway would be the fail-open defect #1702 closes.\n */\nexport function isProviderPermittedByConsent(\n module: ConsentClassifiableProviderModule,\n grantedConsentPurposes: readonly ConsentPurpose[],\n): boolean {\n if (unclassifiedFrontendCapabilities(module).length > 0) return false;\n if (unknownProviderConsentPurposes(module).length > 0) return false;\n return missingConsentPurposes(grantedConsentPurposes, consentPurposesRequiredByProvider(module)).length === 0;\n}\n\n/**\n * The purposes the person would have to grant for this provider to start — what a consent-required\n * state names and offers. Empty both when the provider is permitted and when no grant could permit it\n * (a broken classification); `isProviderPermittedByConsent` tells the two apart.\n */\nexport function missingConsentPurposesForProvider(\n module: ConsentClassifiableProviderModule,\n grantedConsentPurposes: readonly ConsentPurpose[],\n): ConsentPurpose[] {\n return missingConsentPurposes(grantedConsentPurposes, consentPurposesRequiredByProvider(module));\n}\n\n/**\n * One sentence saying why a provider was withheld, for a diagnostic. Distinguishes the two reasons,\n * because their remedies are opposite: a missing grant is the person's to give, a broken classification\n * is the provider author's to fix.\n */\nexport function describeProviderConsentRefusal(\n providerRef: string,\n module: ConsentClassifiableProviderModule,\n grantedConsentPurposes: readonly ConsentPurpose[],\n): string {\n const unclassified = unclassifiedFrontendCapabilities(module);\n if (unclassified.length > 0) {\n return `Provider \"${providerRef}\" declares ${unclassified.join(', ')}, which no browser surface may host, so it `\n + 'never starts. Remove the capability from its frontend module.';\n }\n const unknownPurposes = unknownProviderConsentPurposes(module);\n if (unknownPurposes.length > 0) {\n return `Provider \"${providerRef}\" declares consent purposes ${unknownPurposes.join(', ')}, which are not consent `\n + 'purposes, so it never starts. Declare members of ConsentPurpose.';\n }\n return `Provider \"${providerRef}\" rests on consent to ${missingConsentPurposesForProvider(module, grantedConsentPurposes).join(', ')}, `\n + 'which has not been granted on this surface.';\n}\n\n/** Every purpose the given providers rest on — what a consent surface must ask about, and nothing more. */\nexport function consentPurposesInUseByProviders(modules: Iterable<ConsentClassifiableProviderModule> | undefined): ConsentPurpose[] {\n const inUse: ConsentPurpose[] = [];\n for (const module of modules ?? []) inUse.push(...consentPurposesRequiredByProvider(module));\n return normalizeConsentPurposes(inUse);\n}\n\n/**\n * The code-bearing shape the stop rule needs: whether a provider injects `<script>` tags, and whether\n * its SDK declares that it can be stopped.\n */\nexport interface StoppableConsentProviderModule extends ConsentClassifiableProviderModule {\n readonly scripts?: ReadonlyArray<unknown>;\n readonly sdk?: { readonly stoppable?: true };\n}\n\n/**\n * Why a CONSENT-BASED provider cannot honour a withdrawal, or `undefined` when it can (#1704).\n *\n * Consent can be withdrawn at any moment and must be as easy to withdraw as to give, so a provider that\n * starts on a grant must be stoppable on the withdrawal of that grant, in the same page. Two shapes\n * cannot be:\n *\n * - **`scripts`.** A `<script>` tag is DATA: the framework injects it and has no handle on what it runs.\n * Removing the element afterwards undoes nothing — the vendor's globals, listeners, timers and the\n * storage it wrote all stay (`load-frontend-provider-scripts.ts` says the same). A consent-based\n * vendor that ships as a script loads it from inside its own `sdk.activate` instead, where it can\n * also stop it.\n * - **An SDK that does not declare `stoppable`.** Whether `activate()` returns a `deactivate` is only\n * known after the vendor has started, which is too late to refuse. So the SDK states it up front,\n * and a declared SDK whose activation then returns no `deactivate` is reported by the runner.\n *\n * Asked at projection (the provider package's own `./companion` barrel refuses) and at hydration (the\n * provider's code and scripts are withheld with a diagnostic), so neither a stale artifact nor a\n * hand-written contribution can start an unstoppable consent-based provider. A provider resting on no\n * purpose is never refused here: nothing can be withdrawn from it.\n */\nexport function consentBasedProviderStopRefusal(providerRef: string, module: StoppableConsentProviderModule): string | undefined {\n const purposes = consentPurposesRequiredByProvider(module);\n if (purposes.length === 0) return undefined;\n if ((module.scripts?.length ?? 0) > 0) {\n return `Provider \"${providerRef}\" rests on consent to ${purposes.join(', ')} and declares <script> tags, which cannot be `\n + 'stopped when that consent is withdrawn. Load the script from inside its sdk.activate and return a deactivate '\n + 'instead (#1704).';\n }\n if (module.sdk !== undefined && module.sdk.stoppable !== true) {\n return `Provider \"${providerRef}\" rests on consent to ${purposes.join(', ')} and its SDK does not declare stoppable: true, `\n + 'so a withdrawal could not stop it. Return a deactivate from sdk.activate that fully stops the vendor, and declare '\n + 'stoppable: true (#1704).';\n }\n return undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend-provider-on-demand.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"frontend-provider-on-demand.d.ts","sourceRoot":"","sources":["../../../src/shared/frontend-provider-on-demand.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAgC,KAAK,iCAAiC,EAAE,MAAM,sCAAsC,CAAC;AAC5H,OAAO,EAAE,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AAEtF,uEAAuE;AACvE,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAC1C,QAAQ,CAAC,GAAG,CAAC,EAAE;QACb,QAAQ,CAAC,UAAU,CAAC,EAAE,iCAAiC,CAAC;QACxD,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;KAC1C,CAAC;CACH;AAED,kFAAkF;AAClF,oBAAY,sBAAsB;IAChC,2FAA2F;IAC3F,MAAM,WAAW;IACjB,oHAAoH;IACpH,cAAc,mBAAmB;IACjC,mGAAmG;IACnG,YAAY,iBAAiB;IAC7B,mDAAmD;IACnD,gBAAgB,qBAAqB;CACtC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE;IAAE,QAAQ,CAAC,oBAAoB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,iCAAiC,CAAC;QAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,iCAAiC,KAAK,OAAO,CAAA;KAAE,CAAA;CAAE,EACvO,OAAO,EAAE,iCAAiC,GACzC;IAAE,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,CAUxE;AAED,iHAAiH;AACjH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,0BAA0B,GAAG,MAAM,GAAG,SAAS,CAmCtH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend-provider-on-demand.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"frontend-provider-on-demand.js","sourceRoot":"","sources":["../../../src/shared/frontend-provider-on-demand.ts"],"names":[],"mappings":"A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MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,OAAO,aAAa,WAAW,sCAAsC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,kCAAkC;cAC/H,8IAA8I,CAAC;IACrJ,CAAC;IACD,8HAA8H;IAC9H,IAAI,WAAW,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QACrD,OAAO,aAAa,WAAW,0FAA0F;cACrH,kEAAkE,CAAC;IACzE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * The on-demand rule for a frontend provider (#2790), asked in one place.\n *\n * An on-demand capability (`ON_DEMAND_PROVIDER_CAPABILITIES`) is CALLED by a flow, so the SDK serving it must be one no\n * surface starts and one that can say whether it serves the flow's context. Each half alone is a provider that looks\n * declared and does nothing: an on-demand capability on an SDK started with the surface is never called (and runs on\n * every page for no reason), and an on-demand SDK serving no on-demand capability is never started.\n */\n\nimport { isOnDemandProviderCapability, type FrontendOnDemandCapabilityContext } from '@wildo-ai/saas-models/public-runtime';\nimport { ProviderFrontendSdkActivationMode } from './frontend-provider-surface.types';\n\n/** The part of a frontend provider module the on-demand rule reads. */\nexport interface OnDemandRuleProviderModule {\n readonly providerCapabilities?: ReadonlyArray<string>;\n readonly scripts?: ReadonlyArray<unknown>;\n readonly sdk?: {\n readonly activation?: ProviderFrontendSdkActivationMode;\n readonly servesOnDemandContext?: unknown;\n };\n}\n\n/** Whether a provider serves one on-demand call, and why not when it does not. */\nexport enum OnDemandServingVerdict {\n /** An ON_DEMAND SDK serving the called capability whose predicate accepted the context. */\n SERVES = 'serves',\n /** Not an ON_DEMAND SDK, another capability, or a predicate that answered no: the ordinary answer, said nowhere. */\n DOES_NOT_SERVE = 'does_not_serve',\n /** An ON_DEMAND SDK serving the capability with no predicate: it cannot say it serves the call. */\n NO_PREDICATE = 'no_predicate',\n /** Its predicate threw: treated as not serving. */\n PREDICATE_FAILED = 'predicate_failed',\n}\n\n/**\n * The ONE decision of whether `module` serves the on-demand call `context` (#2790), shared by the runner that loads the\n * providers and by the synchronous question a flow asks before offering anything that depends on one (the chat-link\n * page's Close): both must agree, or a page could offer a door the runner then refuses to open. Synchronous, and loads\n * nothing: the predicate runs before any vendor code is fetched.\n */\nexport function onDemandServingVerdict(\n module: { readonly providerCapabilities?: ReadonlyArray<string>; readonly sdk?: { readonly activation?: ProviderFrontendSdkActivationMode; readonly servesOnDemandContext?: (context: FrontendOnDemandCapabilityContext) => boolean } },\n context: FrontendOnDemandCapabilityContext,\n): { readonly verdict: OnDemandServingVerdict; readonly cause?: unknown } {\n const sdk = module.sdk;\n if (sdk?.activation !== ProviderFrontendSdkActivationMode.ON_DEMAND) return { verdict: OnDemandServingVerdict.DOES_NOT_SERVE };\n if (!(module.providerCapabilities ?? []).includes(context.capability)) return { verdict: OnDemandServingVerdict.DOES_NOT_SERVE };\n if (sdk.servesOnDemandContext === undefined) return { verdict: OnDemandServingVerdict.NO_PREDICATE };\n try {\n return { verdict: sdk.servesOnDemandContext(context) === true ? OnDemandServingVerdict.SERVES : OnDemandServingVerdict.DOES_NOT_SERVE };\n } catch (cause) {\n return { verdict: OnDemandServingVerdict.PREDICATE_FAILED, cause };\n }\n}\n\n/** Why a provider breaks the on-demand rule, in words its author can act on, or `undefined` when it keeps it. */\nexport function onDemandProviderSdkRefusal(providerRef: string, module: OnDemandRuleProviderModule): string | undefined {\n const onDemandCapabilities = (module.providerCapabilities ?? []).filter((capability) => isOnDemandProviderCapability(capability));\n const onDemandSdk = module.sdk?.activation === ProviderFrontendSdkActivationMode.ON_DEMAND;\n\n if (onDemandCapabilities.length > 0 && module.sdk === undefined) {\n return `Provider \"${providerRef}\" declares ${onDemandCapabilities.join(', ')}, which a flow calls on demand, and no sdk to call. `\n + 'Declare an sdk with activation: ON_DEMAND and a servesOnDemandContext predicate (#2790).';\n }\n if (onDemandCapabilities.length > 0 && !onDemandSdk) {\n return `Provider \"${providerRef}\" declares ${onDemandCapabilities.join(', ')}, which a flow calls on demand, but its sdk is started `\n + 'with the surface, so the call would never reach it. Declare activation: ProviderFrontendSdkActivationMode.ON_DEMAND (#2790).';\n }\n if (onDemandSdk && onDemandCapabilities.length === 0) {\n return `Provider \"${providerRef}\" declares an on-demand sdk but no on-demand capability, so no flow would ever call it. `\n + 'Declare the capability it serves, or remove activation: ON_DEMAND (#2790).';\n }\n if (onDemandSdk && typeof module.sdk?.servesOnDemandContext !== 'function') {\n return `Provider \"${providerRef}\" declares an on-demand sdk with no servesOnDemandContext, so it cannot say which calls it `\n + 'serves. Declare the predicate (#2790).';\n }\n // ONE MODE PER MODULE, decided (#2790): a module has one sdk, and an on-demand one never starts with the surface, so a\n // capability that needs a running SDK on every page (error monitoring, analytics, captcha) would silently never work\n // beside it. A component-only capability (a picker, an address lookup) would work, and is refused anyway: telling the\n // two kinds apart is a classification nothing else needs, and an on-demand module of its own costs nothing.\n const otherCapabilities = (module.providerCapabilities ?? []).filter((capability) => !isOnDemandProviderCapability(capability));\n if (onDemandSdk && otherCapabilities.length > 0) {\n return `Provider \"${providerRef}\" declares an on-demand sdk beside ${otherCapabilities.join(', ')}. A module serving an on-demand `\n + 'capability serves only on-demand capabilities (its one sdk never starts with the surface): ship the others in a module of their own (#2790).';\n }\n // A declared <script> is injected on every page by the surface, which is exactly what an on-demand provider exists not to do.\n if (onDemandSdk && (module.scripts?.length ?? 0) > 0) {\n return `Provider \"${providerRef}\" declares an on-demand sdk and <script> tags, which the surface injects on every page. `\n + 'Load the vendor script from inside sdk.activate instead (#2790).';\n }\n return undefined;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend-provider-surface.types.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"frontend-provider-surface.types.d.ts","sourceRoot":"","sources":["../../../src/shared/frontend-provider-surface.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;A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QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAeD;;;;;;;;;GASG;AACH,wBAAgB,kCAAkC,CAChD,WAAW,EAAE,mCAAmC,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7E,mCAAmC,CAerC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mCAAmC,CACjD,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mCAAmC,GAAG;IAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,GAAG,SAAS,GAClH,MAAM,CAAC,MAAM,EAAE,mCAAmC,CAAC,GAAG,SAAS,CAajE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontend-provider-surface.types.js","sourceRoot":"","sources":["../../../../src/shared/frontend-provider-surface.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAyGH,qIAAqI;AACrI;;;;;GAKG;AACH,MAAM,CAAN,IAAY,iCAQX;AARD,WAAY,iCAAiC;IAC3C,mHAAmH;IACnH,0EAAqC,CAAA;IACrC;;;OAGG;IACH,4DAAuB,CAAA;AACzB,CAAC,EARW,iCAAiC,KAAjC,iCAAiC,QAQ5C;AA6ID;;;;;;;;;;;GAWG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,kCAAkC,CAChD,WAA8E;IAE9E,OAAO;QACL,iBAAiB,EAAE,WAAW,CAAC,iBAAiB;QAChD,GAAG,CAAC,WAAW,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzG,GAAG,CAAC,WAAW,CAAC,aAAa,KAAK,SAAS;YACzC,CAAC,CAAC;gBACA,aAAa,EAAE;oBACb,kBAAkB,EAAE,WAAW,CAAC,aAAa,CAAC,kBAAkB;oBAChE,mBAAmB,EAAE,WAAW,CAAC,aAAa,CAAC,mBAAmB;oBAClE,GAAG,CAAC,WAAW,CAAC,aAAa,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,WAAW,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACxI,GAAG,CAAC,WAAW,CAAC,aAAa,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACnI;aACF;YACD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,mCAAmC,CACjD,UAAmH;IAEnH,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAE/C,MAAM,WAAW,GAAwD,EAAE,CAAC;IAC5E,6EAA6E;IAC7E,2EAA2E;IAC3E,4EAA4E;IAC5E,qBAAqB;IACrB,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3D,KAAK,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACnE,WAAW,CAAC,UAAU,CAAC,GAAG,kCAAkC,CAAC,WAAW,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["/**\n * The EXECUTABLE half of a frontend provider's surface — the part that cannot\n * cross a JSON channel, and therefore the part that defines the second channel.\n *\n * ## The two channels, and why there have to be two\n *\n * A frontend provider reaches a page through:\n *\n * - the **DATA** channel — `FrontendProviderEntry`, projected by the backend\n * into `/application-config` and materialized into the generated\n * frontend-services artifact. JSON end to end. It answers *which providers\n * are live for this service, in this environment*;\n * - the **CODE** channel — the provider package's own facet barrel, reaching\n * the bundle through a generated `frontend-providers.generated.ts` that the\n * app / website / techdoc build imports. It answers *what code exists in\n * this bundle*.\n *\n * Before this split there was one channel and a cast: the registry took a JSON\n * entry and asserted it was a module. That cast was true only for as long as the\n * module type had nothing but strings on it — the moment a provider needed to\n * load an SDK or register a component, the field would have been dropped by\n * `JSON.stringify` with no error anywhere, and the provider would have looked\n * declared and done nothing.\n *\n * So: everything in this file is CODE and never leaves the bundle, everything in\n * `provider-frontend-surface.shared.schemas.ts` (in `@wildo-ai/saas-models`) is\n * DATA and never carries a function, and `sdk` deliberately has a foot in both —\n * a `descriptor` the CLI and the CSP composer can read, and an `activate()` only\n * a browser can run.\n *\n * Added by slice S4a of epic #337 (issue #332).\n */\n\nimport type {\n AppFrontendType,\n FrontendOnDemandCapabilityContext,\n ProviderFrontendComponentDescriptor,\n ProviderFrontendSdkDescriptor,\n} from '@wildo-ai/saas-models/public-runtime';\nimport { ProviderFrontendSelectionDelivery } from '@wildo-ai/saas-models/public-runtime';\n\n/**\n * What a surface tells a provider when it activates its SDK.\n *\n * Deliberately small, because it must mean the same thing under Vite, Astro and\n * Docusaurus. Anything a single bundler can offer and the others cannot (a Vite\n * `import.meta.env`, an Astro locals object, a Docusaurus plugin context) would\n * make a provider that works on one surface and silently misbehaves on another,\n * which is the failure this whole slice exists to remove.\n */\nexport interface ProviderFrontendSdkActivationContext {\n /** The provider's own `ref`, so a provider can label its vendor-side telemetry. */\n readonly providerRef: string;\n /** Which of the three frontend surfaces is activating it. */\n readonly surface: AppFrontendType;\n /**\n * The provider's public configuration, as served on the DATA channel and\n * already validated against the module's own `publicConfigSchema` when it\n * declares one. A provider therefore never has to re-coerce it at the use\n * site — which is what the app was doing, per-site, by hand.\n */\n readonly publicConfig: Readonly<Record<string, unknown>>;\n}\n\n/**\n * The result of activating a provider's SDK.\n *\n * `deactivate` is the paired path, and it is optional only because some vendor\n * SDKs genuinely offer no teardown. Where one exists it must be declared: an\n * analytics or error-monitoring SDK that can be started and never stopped\n * cannot honour a consent withdrawal, and a surface that hot-reloads would\n * accumulate one live client per reload.\n */\nexport interface ProviderFrontendSdkActivation {\n /**\n * The vendor handle the surface may hold — a `Sentry` namespace, a `posthog`\n * instance, a picker factory. `unknown` on purpose: this package must not\n * know any vendor's type, and a consumer that needs one narrows it at the\n * point where it also knows which provider it asked for.\n */\n readonly handle: unknown;\n readonly deactivate?: () => void | Promise<void>;\n}\n\n/**\n * A provider's vendor SDK: which package it is (DATA), and how to load and start\n * it (CODE).\n *\n * `activate` owns BOTH the dynamic import and the vendor's initialization call,\n * as one function rather than two. The alternative — a `load()` returning the\n * namespace and an `initialize(handle, config)` beside it — puts the vendor's\n * own start-up contract in the surface's hands, and every surface would then\n * carry a growing switch over vendors. One function keeps that knowledge where\n * it belongs: inside the provider package.\n *\n * The import inside `activate` must be a DYNAMIC `import()`. That is what makes\n * the SDK a separate chunk in all three bundlers, and it is what lets the\n * bundle-isolation policy tell a declared optional dependency from a static one\n * that would land in every page's initial payload.\n */\nexport interface ProviderFrontendSdk {\n /** The DATA half — mirrored onto the provider entry so the CLI can see it without executing anything. */\n readonly descriptor: ProviderFrontendSdkDescriptor;\n activate(context: ProviderFrontendSdkActivationContext): Promise<ProviderFrontendSdkActivation>;\n /**\n * WHEN the SDK starts (#2790). Omitted means `AT_SURFACE_START`: every SDK before this one, and still the right\n * answer for one a surface needs from its first page (error monitoring, analytics, captcha).\n *\n * `ON_DEMAND` is for a provider serving an on-demand capability (`ON_DEMAND_PROVIDER_CAPABILITIES`): no surface\n * starts it, and a flow calls it, at the moment it needs it, through the frontend provider registry. Its projection\n * refuses either half alone: an on-demand capability with an SDK started with the surface would never be called,\n * and an on-demand SDK serving no on-demand capability would never be started.\n */\n readonly activation?: ProviderFrontendSdkActivationMode;\n /**\n * Whether THIS provider serves the context the calling flow names (#2790). Required with `ON_DEMAND`.\n *\n * Evaluated at the call, with the context the flow built from what it knew at that moment, never at startup and\n * never from the live page: several providers may serve one capability (one per chat host, say), and only the one\n * whose predicate accepts the context is loaded. Synchronous and side-effect free; it runs before any vendor code\n * is fetched.\n */\n readonly servesOnDemandContext?: (context: FrontendOnDemandCapabilityContext) => boolean;\n /**\n * `true` when `activate` returns a `deactivate` that fully stops the vendor in the page (#1704).\n *\n * REQUIRED on a provider that rests on a consent purpose: the grant can be withdrawn at any moment,\n * and a withdrawal must stop what the grant started. Declared rather than discovered because whether\n * an activation carries `deactivate` is only known once the vendor is already running — too late to\n * refuse it. A consent-based SDK without it is refused at projection and withheld at hydration\n * (`consentBasedProviderStopRefusal`); one that declares it and then returns no `deactivate` is\n * reported by the activation runner as a broken promise.\n */\n readonly stoppable?: true;\n}\n\n/** @wildo_source:part:start external-connectors.frontend-provider-sdk-activation-mode facet:kind:api facet:audience:app-developer */\n/**\n * When a provider's vendor SDK starts (#2790).\n *\n * A closed vocabulary rather than a boolean because each member carries who starts the SDK and on what: the\n * surface on its first page, or the flow that calls it with a context.\n */\nexport enum ProviderFrontendSdkActivationMode {\n /** Started by the surface itself: the application's startup, its consent phase, the website, the documentation. */\n AT_SURFACE_START = 'at_surface_start',\n /**\n * Started only when a flow calls the capability, and only if `servesOnDemandContext` accepts the flow's context.\n * Every surface start skips it.\n */\n ON_DEMAND = 'on_demand',\n}\n/** @wildo_source:part:end external-connectors.frontend-provider-sdk-activation-mode */\n\n/** @wildo_source:part:start external-connectors.frontend-provider-component-declaration facet:kind:api facet:audience:app-developer */\n/**\n * A component a provider contributes, keyed by the CAPABILITY it fills.\n *\n * Loaded on demand, like an SDK and for the same reason: a picker nobody opens\n * should cost nothing, and a bundle should not carry every provider's UI.\n *\n * ## Why the loaded value is `unknown` here\n *\n * This package ships into three browser bundles and its bare-specifier\n * allow-list holds ONE entry. Typing the result as `React.ComponentType` would\n * put `react` in the closure of a package whose whole discipline is that it has\n * no renderer — and a provider module is DATA plus loaders; what a loader\n * RETURNS is the consuming surface's business, not this package's.\n *\n * A provider author loses nothing: any `() => Promise<React.ComponentType<P>>`\n * satisfies this type, so authors keep their own props type and the surface\n * narrows once, where React actually lives.\n *\n * ## Why capability-keyed and not component-type-keyed\n *\n * The engine's own component slots are a CLOSED `FrontendComponentType` enum\n * times a preset, answered by exactly one component. A provider component is\n * answered per PROVIDER — several providers may fill one capability — and the\n * provider set is discovered per deployment rather than owned by the engine.\n * (This used to argue from provider capabilities being an OPEN vocabulary\n * extended by module augmentation; #502 closed it, and the split stands on the\n * cardinality and ownership difference above.)\n */\nexport type ProviderFrontendComponentLoader = () => Promise<unknown>;\n\n/**\n * One component a provider contributes: how to load it (CODE) and what it\n * commits to (DATA).\n *\n * Both halves in one declaration, deliberately, and it mirrors `sdk`. A loader\n * alone was the first shape — `components: { FRONTEND_FILE_PICKER: () => … }` —\n * and it could not answer the question a surface asks FIRST: what will a\n * selection from this component contain? That has to be readable without\n * downloading the component, because the framework decides how to route the\n * result before it decides to mount anything, and because a reviewer reading a\n * provider's manifest should see the answer without running a browser.\n *\n * Everything except `load` is projected onto the provider's DATA entry by\n * `projectFrontendProviderContribution`, exactly as `sdk.descriptor` is.\n */\nexport interface ProviderFrontendComponentDeclaration extends ProviderFrontendComponentDescriptor {\n /**\n * Loads the component on demand — the door for a provider PACKAGE that ships\n * its own component. Must resolve the COMPONENT, not the module:\n * `async () => (await import('./Picker')).Picker`, never\n * `() => import('./Picker')`. The registry detects and reports the second\n * shape, because a module namespace passed to React renders nothing and the\n * stack trace points at React rather than at the provider.\n *\n * OPTIONAL since #394, and an ENGINE module never sets it. This package is\n * renderer-free and sits below the component libraries, so a loader written\n * here cannot reach a React component without closing a package cycle. The\n * engine's components live in the facet library (`presets-components` for the\n * app), which contributes their loaders keyed by capability and provider ref;\n * the declaration here stays the DATA a reviewer reads. A declaration with no\n * loader from either side is reported at startup and not offered.\n */\n readonly load?: ProviderFrontendComponentLoader;\n}\n\n/**\n * The components a provider offers, by capability token.\n *\n * A provider may claim a capability without shipping a component — declaring\n * `FRONTEND_FILE_PICKER` and offering only constraints is a real and supported\n * shape — so this map is not required to cover `providerCapabilities`.\n */\nexport type ProviderFrontendComponents = Readonly<Record<string, ProviderFrontendComponentDeclaration>>;\n/** @wildo_source:part:end external-connectors.frontend-provider-component-declaration */\n\n/**\n * Minimal structural view of a Standard Schema v1 validator.\n *\n * Declared here rather than imported, for two reasons that both matter:\n *\n * 1. `@wildo-ai/external-connectors-public` ships into three browser bundles\n * and its bare-specifier allow-list holds exactly one entry. Importing\n * `zod` to type one optional field would widen that allow-list for a\n * TYPE — a runtime cost paid for a compile-time need.\n * 2. Standard Schema is a cross-library contract (Zod 4, Valibot, ArkType all\n * implement it), so typing the field this way lets a provider package\n * validate with whatever it already depends on instead of forcing Zod on\n * every provider author. Zod 4 schemas satisfy this interface as-is.\n *\n * Only the success/issue discrimination is modelled, because only that is used:\n * the surface asks \"is this public config valid, and if not, what is wrong\".\n */\nexport interface ProviderFrontendPublicConfigIssue {\n readonly message: string;\n /**\n * Standard Schema permits a path segment to be either a key or a\n * `{ key }` wrapper; both shapes are accepted so a validator from any\n * implementing library reads correctly.\n */\n readonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>;\n}\n\nexport interface ProviderFrontendPublicConfigSuccess<TOutput> {\n readonly value: TOutput;\n readonly issues?: undefined;\n}\n\nexport interface ProviderFrontendPublicConfigFailure {\n readonly issues: ReadonlyArray<ProviderFrontendPublicConfigIssue>;\n}\n\nexport type ProviderFrontendPublicConfigResult<TOutput> =\n | ProviderFrontendPublicConfigSuccess<TOutput>\n | ProviderFrontendPublicConfigFailure;\n\nexport interface ProviderFrontendPublicConfigSchema<TOutput = unknown> {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n validate(\n value: unknown,\n ): ProviderFrontendPublicConfigResult<TOutput> | Promise<ProviderFrontendPublicConfigResult<TOutput>>;\n };\n /**\n * The keys the schema admits, readable WITHOUT running it — the DATA half of\n * the declaration (#394 P3). Standard Schema v1 exposes `validate` and nothing\n * else, so without this the companion walk — which runs in Node from a\n * projected contribution, never holding the module — could not refuse an\n * application-supplied key the module never declared. `defineFrontendPublicConfigSchema`\n * from `@wildo-ai/saas-models/public-runtime` fills it; a Zod object is read\n * through its `shape` instead. Absent means \"not introspectable\", which the\n * projection, the overlay and hydration all REFUSE (#1705) — never read as\n * \"declares nothing\".\n */\n readonly declaredKeys?: readonly string[];\n}\n\n/*\n * `ProviderFileSelection`, `ProviderFilePickerConstraints` and\n * `ProviderFilePickerProps` used to live here, beside the module types that\n * declare a component. They moved to `@wildo-ai/saas-models` (#394) because a\n * component ships in its own React-bearing package, and that package importing\n * this one closed a cycle through EMITTED DECLARATIONS: its `.d.ts` referenced\n * this package's `.d.ts`, which made this package's own `dist` an input of its\n * own build (`TS5055`, once per emitted declaration — measured, not predicted).\n *\n * Deliberately NOT re-exported from here. A pass-through would be a second door\n * onto the same room, and the import site should say where the contract lives.\n */\n\n/**\n * ONE component's declared half, rebuilt field by field. The single projection of a descriptor: the served\n * entry (`projectFrontendComponentDescriptors`), the registry's enforced copy and the hydration staleness\n * check all read it, so a field added to the descriptor crosses every one of them or none (#561 — the\n * address-lookup block was the first field that would otherwise have had to be added at three sites).\n *\n * Rebuilt rather than spread-minus-`load`, so a future field on the declaration is a COMPILE decision\n * about whether it crosses the wire instead of one that crosses by default. An optional field crosses only\n * when declared, so a component that says nothing keeps the one spelling it had before the field existed.\n */\nexport function projectFrontendComponentDescriptor(\n declaration: ProviderFrontendComponentDescriptor & { readonly load?: unknown },\n): ProviderFrontendComponentDescriptor {\n return {\n selectionDelivery: declaration.selectionDelivery,\n ...(declaration.placeIdRetention !== undefined ? { placeIdRetention: declaration.placeIdRetention } : {}),\n ...(declaration.addressLookup !== undefined\n ? {\n addressLookup: {\n suggestOperationId: declaration.addressLookup.suggestOperationId,\n retrieveOperationId: declaration.addressLookup.retrieveOperationId,\n ...(declaration.addressLookup.sessionTokenInput !== undefined ? { sessionTokenInput: declaration.addressLookup.sessionTokenInput } : {}),\n ...(declaration.addressLookup.attributionMark !== undefined ? { attributionMark: declaration.addressLookup.attributionMark } : {}),\n },\n }\n : {}),\n };\n}\n\n/**\n * Strips a provider's component declarations down to the half a JSON channel\n * can carry.\n *\n * ONE named source, reachable from every facet barrel, because there are THREE\n * sites that turn a frontend module into a wire entry and they must not hold\n * three opinions: `projectFrontendProviderContribution` (the companion\n * discovery walk, which feeds the generated artifact), the backend's fallback\n * projection in `frontend-bootstrap.backend.service.ts` (what an application\n * serves when no sync has run), and the hydration join, which takes the CODE\n * side whole and needs no stripping at all.\n *\n * The failure a second opinion produces is the one that surface's own comments\n * already name for the CSP footprint: a provider's declaration would appear on\n * the entry when a sync had run and vanish when it had not — a difference no\n * consumer can see and only production can punish.\n *\n * Returns `undefined` for a provider with no components rather than `{}`, so\n * \"contributes none\" keeps one spelling, the way an absent `sdk` does.\n *\n * ## Why it lives in a browser-bound file\n *\n * Both callers are Node — the companion discovery walk and the backend's\n * fallback projection — and this file's header says everything in it is CODE\n * that never leaves the bundle. The placement is still right: the facet barrels\n * are the only surface BOTH callers can reach (the backend imports\n * `/app`, `/techdoc` and `/website`, never `/companion`), and putting it\n * anywhere else would mean either a fourth subpath for one function or a second\n * copy — which is the exact defect it exists to prevent. It is a pure function\n * with no imports and no state, so a bundler that keeps it keeps a dozen lines.\n */\nexport function projectFrontendComponentDescriptors(\n components: Readonly<Record<string, ProviderFrontendComponentDescriptor & { readonly load?: unknown }>> | undefined,\n): Record<string, ProviderFrontendComponentDescriptor> | undefined {\n if (components === undefined) return undefined;\n\n const descriptors: Record<string, ProviderFrontendComponentDescriptor> = {};\n // An AUTHORED `components: {}` must not reach the wire either. The invariant\n // is \"contributes none has one spelling\", and guarding only on `undefined`\n // would have let the second spelling through from a provider that wrote the\n // empty map by hand.\n if (Object.keys(components).length === 0) return undefined;\n for (const [capability, declaration] of Object.entries(components)) {\n descriptors[capability] = projectFrontendComponentDescriptor(declaration);\n }\n return descriptors;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"frontend-provider-surface.types.js","sourceRoot":"","sources":["../../../src/shared/frontend-provider-surface.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAyGH,qIAAqI;AACrI;;;;;GAKG;AACH,MAAM,CAAN,IAAY,iCAQX;AARD,WAAY,iCAAiC;IAC3C,mHAAmH;IACnH,0EAAqC,CAAA;IACrC;;;OAGG;IACH,4DAAuB,CAAA;AACzB,CAAC,EARW,iCAAiC,KAAjC,iCAAiC,QAQ5C;AA6ID;;;;;;;;;;;GAWG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,kCAAkC,CAChD,WAA8E;IAE9E,OAAO;QACL,iBAAiB,EAAE,WAAW,CAAC,iBAAiB;QAChD,GAAG,CAAC,WAAW,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzG,GAAG,CAAC,WAAW,CAAC,aAAa,KAAK,SAAS;YACzC,CAAC,CAAC;gBACA,aAAa,EAAE;oBACb,kBAAkB,EAAE,WAAW,CAAC,aAAa,CAAC,kBAAkB;oBAChE,mBAAmB,EAAE,WAAW,CAAC,aAAa,CAAC,mBAAmB;oBAClE,GAAG,CAAC,WAAW,CAAC,aAAa,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,WAAW,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACxI,GAAG,CAAC,WAAW,CAAC,aAAa,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACnI;aACF;YACD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,mCAAmC,CACjD,UAAmH;IAEnH,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAE/C,MAAM,WAAW,GAAwD,EAAE,CAAC;IAC5E,6EAA6E;IAC7E,2EAA2E;IAC3E,4EAA4E;IAC5E,qBAAqB;IACrB,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC3D,KAAK,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACnE,WAAW,CAAC,UAAU,CAAC,GAAG,kCAAkC,CAAC,WAAW,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["/**\n * The EXECUTABLE half of a frontend provider's surface — the part that cannot\n * cross a JSON channel, and therefore the part that defines the second channel.\n *\n * ## The two channels, and why there have to be two\n *\n * A frontend provider reaches a page through:\n *\n * - the **DATA** channel — `FrontendProviderEntry`, projected by the backend\n * into `/application-config` and materialized into the generated\n * frontend-services artifact. JSON end to end. It answers *which providers\n * are live for this service, in this environment*;\n * - the **CODE** channel — the provider package's own facet barrel, reaching\n * the bundle through a generated `frontend-providers.generated.ts` that the\n * app / website / techdoc build imports. It answers *what code exists in\n * this bundle*.\n *\n * Before this split there was one channel and a cast: the registry took a JSON\n * entry and asserted it was a module. That cast was true only for as long as the\n * module type had nothing but strings on it — the moment a provider needed to\n * load an SDK or register a component, the field would have been dropped by\n * `JSON.stringify` with no error anywhere, and the provider would have looked\n * declared and done nothing.\n *\n * So: everything in this file is CODE and never leaves the bundle, everything in\n * `provider-frontend-surface.shared.schemas.ts` (in `@wildo-ai/saas-models`) is\n * DATA and never carries a function, and `sdk` deliberately has a foot in both —\n * a `descriptor` the CLI and the CSP composer can read, and an `activate()` only\n * a browser can run.\n *\n * Added by slice S4a of epic #337 (issue #332).\n */\n\nimport type {\n AppFrontendType,\n FrontendOnDemandCapabilityContext,\n ProviderFrontendComponentDescriptor,\n ProviderFrontendSdkDescriptor,\n} from '@wildo-ai/saas-models/public-runtime';\nimport { ProviderFrontendSelectionDelivery } from '@wildo-ai/saas-models/public-runtime';\n\n/**\n * What a surface tells a provider when it activates its SDK.\n *\n * Deliberately small, because it must mean the same thing under Vite, Astro and\n * Docusaurus. Anything a single bundler can offer and the others cannot (a Vite\n * `import.meta.env`, an Astro locals object, a Docusaurus plugin context) would\n * make a provider that works on one surface and silently misbehaves on another,\n * which is the failure this whole slice exists to remove.\n */\nexport interface ProviderFrontendSdkActivationContext {\n /** The provider's own `ref`, so a provider can label its vendor-side telemetry. */\n readonly providerRef: string;\n /** Which of the three frontend surfaces is activating it. */\n readonly surface: AppFrontendType;\n /**\n * The provider's public configuration, as served on the DATA channel and\n * already validated against the module's own `publicConfigSchema` when it\n * declares one. A provider therefore never has to re-coerce it at the use\n * site — which is what the app was doing, per-site, by hand.\n */\n readonly publicConfig: Readonly<Record<string, unknown>>;\n}\n\n/**\n * The result of activating a provider's SDK.\n *\n * `deactivate` is the paired path, and it is optional only because some vendor\n * SDKs genuinely offer no teardown. Where one exists it must be declared: an\n * analytics or error-monitoring SDK that can be started and never stopped\n * cannot honour a consent withdrawal, and a surface that hot-reloads would\n * accumulate one live client per reload.\n */\nexport interface ProviderFrontendSdkActivation {\n /**\n * The vendor handle the surface may hold — a `Sentry` namespace, a `posthog`\n * instance, a picker factory. `unknown` on purpose: this package must not\n * know any vendor's type, and a consumer that needs one narrows it at the\n * point where it also knows which provider it asked for.\n */\n readonly handle: unknown;\n readonly deactivate?: () => void | Promise<void>;\n}\n\n/**\n * A provider's vendor SDK: which package it is (DATA), and how to load and start\n * it (CODE).\n *\n * `activate` owns BOTH the dynamic import and the vendor's initialization call,\n * as one function rather than two. The alternative — a `load()` returning the\n * namespace and an `initialize(handle, config)` beside it — puts the vendor's\n * own start-up contract in the surface's hands, and every surface would then\n * carry a growing switch over vendors. One function keeps that knowledge where\n * it belongs: inside the provider package.\n *\n * The import inside `activate` must be a DYNAMIC `import()`. That is what makes\n * the SDK a separate chunk in all three bundlers, and it is what lets the\n * bundle-isolation policy tell a declared optional dependency from a static one\n * that would land in every page's initial payload.\n */\nexport interface ProviderFrontendSdk {\n /** The DATA half — mirrored onto the provider entry so the CLI can see it without executing anything. */\n readonly descriptor: ProviderFrontendSdkDescriptor;\n activate(context: ProviderFrontendSdkActivationContext): Promise<ProviderFrontendSdkActivation>;\n /**\n * WHEN the SDK starts (#2790). Omitted means `AT_SURFACE_START`: every SDK before this one, and still the right\n * answer for one a surface needs from its first page (error monitoring, analytics, captcha).\n *\n * `ON_DEMAND` is for a provider serving an on-demand capability (`ON_DEMAND_PROVIDER_CAPABILITIES`): no surface\n * starts it, and a flow calls it, at the moment it needs it, through the frontend provider registry. Its projection\n * refuses either half alone: an on-demand capability with an SDK started with the surface would never be called,\n * and an on-demand SDK serving no on-demand capability would never be started.\n */\n readonly activation?: ProviderFrontendSdkActivationMode;\n /**\n * Whether THIS provider serves the context the calling flow names (#2790). Required with `ON_DEMAND`.\n *\n * Evaluated at the call, with the context the flow built from what it knew at that moment, never at startup and\n * never from the live page: several providers may serve one capability (one per chat host, say), and only the one\n * whose predicate accepts the context is loaded. Synchronous and side-effect free; it runs before any vendor code\n * is fetched.\n */\n readonly servesOnDemandContext?: (context: FrontendOnDemandCapabilityContext) => boolean;\n /**\n * `true` when `activate` returns a `deactivate` that fully stops the vendor in the page (#1704).\n *\n * REQUIRED on a provider that rests on a consent purpose: the grant can be withdrawn at any moment,\n * and a withdrawal must stop what the grant started. Declared rather than discovered because whether\n * an activation carries `deactivate` is only known once the vendor is already running — too late to\n * refuse it. A consent-based SDK without it is refused at projection and withheld at hydration\n * (`consentBasedProviderStopRefusal`); one that declares it and then returns no `deactivate` is\n * reported by the activation runner as a broken promise.\n */\n readonly stoppable?: true;\n}\n\n/** @wildo_source:part:start external-connectors.frontend-provider-sdk-activation-mode facet:kind:api facet:audience:app-developer */\n/**\n * When a provider's vendor SDK starts (#2790).\n *\n * A closed vocabulary rather than a boolean because each member carries who starts the SDK and on what: the\n * surface on its first page, or the flow that calls it with a context.\n */\nexport enum ProviderFrontendSdkActivationMode {\n /** Started by the surface itself: the application's startup, its consent phase, the website, the documentation. */\n AT_SURFACE_START = 'at_surface_start',\n /**\n * Started only when a flow calls the capability, and only if `servesOnDemandContext` accepts the flow's context.\n * Every surface start skips it.\n */\n ON_DEMAND = 'on_demand',\n}\n/** @wildo_source:part:end external-connectors.frontend-provider-sdk-activation-mode */\n\n/** @wildo_source:part:start external-connectors.frontend-provider-component-declaration facet:kind:api facet:audience:app-developer */\n/**\n * A component a provider contributes, keyed by the CAPABILITY it fills.\n *\n * Loaded on demand, like an SDK and for the same reason: a picker nobody opens\n * should cost nothing, and a bundle should not carry every provider's UI.\n *\n * ## Why the loaded value is `unknown` here\n *\n * This package ships into three browser bundles and its bare-specifier\n * allow-list holds ONE entry. Typing the result as `React.ComponentType` would\n * put `react` in the closure of a package whose whole discipline is that it has\n * no renderer — and a provider module is DATA plus loaders; what a loader\n * RETURNS is the consuming surface's business, not this package's.\n *\n * A provider author loses nothing: any `() => Promise<React.ComponentType<P>>`\n * satisfies this type, so authors keep their own props type and the surface\n * narrows once, where React actually lives.\n *\n * ## Why capability-keyed and not component-type-keyed\n *\n * The engine's own component slots are a CLOSED `FrontendComponentType` enum\n * times a preset, answered by exactly one component. A provider component is\n * answered per PROVIDER — several providers may fill one capability — and the\n * provider set is discovered per deployment rather than owned by the engine.\n * (This used to argue from provider capabilities being an OPEN vocabulary\n * extended by module augmentation; #502 closed it, and the split stands on the\n * cardinality and ownership difference above.)\n */\nexport type ProviderFrontendComponentLoader = () => Promise<unknown>;\n\n/**\n * One component a provider contributes: how to load it (CODE) and what it\n * commits to (DATA).\n *\n * Both halves in one declaration, deliberately, and it mirrors `sdk`. A loader\n * alone was the first shape — `components: { FRONTEND_FILE_PICKER: () => … }` —\n * and it could not answer the question a surface asks FIRST: what will a\n * selection from this component contain? That has to be readable without\n * downloading the component, because the framework decides how to route the\n * result before it decides to mount anything, and because a reviewer reading a\n * provider's manifest should see the answer without running a browser.\n *\n * Everything except `load` is projected onto the provider's DATA entry by\n * `projectFrontendProviderContribution`, exactly as `sdk.descriptor` is.\n */\nexport interface ProviderFrontendComponentDeclaration extends ProviderFrontendComponentDescriptor {\n /**\n * Loads the component on demand — the door for a provider PACKAGE that ships\n * its own component. Must resolve the COMPONENT, not the module:\n * `async () => (await import('./Picker')).Picker`, never\n * `() => import('./Picker')`. The registry detects and reports the second\n * shape, because a module namespace passed to React renders nothing and the\n * stack trace points at React rather than at the provider.\n *\n * OPTIONAL since #394, and an ENGINE module never sets it. This package is\n * renderer-free and sits below the component libraries, so a loader written\n * here cannot reach a React component without closing a package cycle. The\n * engine's components live in the facet library (`presets-components` for the\n * app), which contributes their loaders keyed by capability and provider ref;\n * the declaration here stays the DATA a reviewer reads. A declaration with no\n * loader from either side is reported at startup and not offered.\n */\n readonly load?: ProviderFrontendComponentLoader;\n}\n\n/**\n * The components a provider offers, by capability token.\n *\n * A provider may claim a capability without shipping a component — declaring\n * `FRONTEND_FILE_PICKER` and offering only constraints is a real and supported\n * shape — so this map is not required to cover `providerCapabilities`.\n */\nexport type ProviderFrontendComponents = Readonly<Record<string, ProviderFrontendComponentDeclaration>>;\n/** @wildo_source:part:end external-connectors.frontend-provider-component-declaration */\n\n/**\n * Minimal structural view of a Standard Schema v1 validator.\n *\n * Declared here rather than imported, for two reasons that both matter:\n *\n * 1. `@wildo-ai/external-connectors-public` ships into three browser bundles\n * and its bare-specifier allow-list holds exactly one entry. Importing\n * `zod` to type one optional field would widen that allow-list for a\n * TYPE — a runtime cost paid for a compile-time need.\n * 2. Standard Schema is a cross-library contract (Zod 4, Valibot, ArkType all\n * implement it), so typing the field this way lets a provider package\n * validate with whatever it already depends on instead of forcing Zod on\n * every provider author. Zod 4 schemas satisfy this interface as-is.\n *\n * Only the success/issue discrimination is modelled, because only that is used:\n * the surface asks \"is this public config valid, and if not, what is wrong\".\n */\nexport interface ProviderFrontendPublicConfigIssue {\n readonly message: string;\n /**\n * Standard Schema permits a path segment to be either a key or a\n * `{ key }` wrapper; both shapes are accepted so a validator from any\n * implementing library reads correctly.\n */\n readonly path?: ReadonlyArray<PropertyKey | { readonly key: PropertyKey }>;\n}\n\nexport interface ProviderFrontendPublicConfigSuccess<TOutput> {\n readonly value: TOutput;\n readonly issues?: undefined;\n}\n\nexport interface ProviderFrontendPublicConfigFailure {\n readonly issues: ReadonlyArray<ProviderFrontendPublicConfigIssue>;\n}\n\nexport type ProviderFrontendPublicConfigResult<TOutput> =\n | ProviderFrontendPublicConfigSuccess<TOutput>\n | ProviderFrontendPublicConfigFailure;\n\nexport interface ProviderFrontendPublicConfigSchema<TOutput = unknown> {\n readonly '~standard': {\n readonly version: 1;\n readonly vendor: string;\n validate(\n value: unknown,\n ): ProviderFrontendPublicConfigResult<TOutput> | Promise<ProviderFrontendPublicConfigResult<TOutput>>;\n };\n /**\n * The keys the schema admits, readable WITHOUT running it — the DATA half of\n * the declaration (#394 P3). Standard Schema v1 exposes `validate` and nothing\n * else, so without this the companion walk — which runs in Node from a\n * projected contribution, never holding the module — could not refuse an\n * application-supplied key the module never declared. `defineFrontendPublicConfigSchema`\n * from `@wildo-ai/saas-models/public-runtime` fills it; a Zod object is read\n * through its `shape` instead. Absent means \"not introspectable\", which the\n * projection, the overlay and hydration all REFUSE (#1705) — never read as\n * \"declares nothing\".\n */\n readonly declaredKeys?: readonly string[];\n}\n\n/*\n * `ProviderFileSelection`, `ProviderFilePickerConstraints` and\n * `ProviderFilePickerProps` used to live here, beside the module types that\n * declare a component. They moved to `@wildo-ai/saas-models` (#394) because a\n * component ships in its own React-bearing package, and that package importing\n * this one closed a cycle through EMITTED DECLARATIONS: its `.d.ts` referenced\n * this package's `.d.ts`, which made this package's own `dist` an input of its\n * own build (`TS5055`, once per emitted declaration — measured, not predicted).\n *\n * Deliberately NOT re-exported from here. A pass-through would be a second door\n * onto the same room, and the import site should say where the contract lives.\n */\n\n/**\n * ONE component's declared half, rebuilt field by field. The single projection of a descriptor: the served\n * entry (`projectFrontendComponentDescriptors`), the registry's enforced copy and the hydration staleness\n * check all read it, so a field added to the descriptor crosses every one of them or none (#561 — the\n * address-lookup block was the first field that would otherwise have had to be added at three sites).\n *\n * Rebuilt rather than spread-minus-`load`, so a future field on the declaration is a COMPILE decision\n * about whether it crosses the wire instead of one that crosses by default. An optional field crosses only\n * when declared, so a component that says nothing keeps the one spelling it had before the field existed.\n */\nexport function projectFrontendComponentDescriptor(\n declaration: ProviderFrontendComponentDescriptor & { readonly load?: unknown },\n): ProviderFrontendComponentDescriptor {\n return {\n selectionDelivery: declaration.selectionDelivery,\n ...(declaration.placeIdRetention !== undefined ? { placeIdRetention: declaration.placeIdRetention } : {}),\n ...(declaration.addressLookup !== undefined\n ? {\n addressLookup: {\n suggestOperationId: declaration.addressLookup.suggestOperationId,\n retrieveOperationId: declaration.addressLookup.retrieveOperationId,\n ...(declaration.addressLookup.sessionTokenInput !== undefined ? { sessionTokenInput: declaration.addressLookup.sessionTokenInput } : {}),\n ...(declaration.addressLookup.attributionMark !== undefined ? { attributionMark: declaration.addressLookup.attributionMark } : {}),\n },\n }\n : {}),\n };\n}\n\n/**\n * Strips a provider's component declarations down to the half a JSON channel\n * can carry.\n *\n * ONE named source, reachable from every facet barrel, because there are THREE\n * sites that turn a frontend module into a wire entry and they must not hold\n * three opinions: `projectFrontendProviderContribution` (the companion\n * discovery walk, which feeds the generated artifact), the backend's fallback\n * projection in `frontend-bootstrap.backend.service.ts` (what an application\n * serves when no sync has run), and the hydration join, which takes the CODE\n * side whole and needs no stripping at all.\n *\n * The failure a second opinion produces is the one that surface's own comments\n * already name for the CSP footprint: a provider's declaration would appear on\n * the entry when a sync had run and vanish when it had not — a difference no\n * consumer can see and only production can punish.\n *\n * Returns `undefined` for a provider with no components rather than `{}`, so\n * \"contributes none\" keeps one spelling, the way an absent `sdk` does.\n *\n * ## Why it lives in a browser-bound file\n *\n * Both callers are Node — the companion discovery walk and the backend's\n * fallback projection — and this file's header says everything in it is CODE\n * that never leaves the bundle. The placement is still right: the facet barrels\n * are the only surface BOTH callers can reach (the backend imports\n * `/app`, `/techdoc` and `/website`, never `/companion`), and putting it\n * anywhere else would mean either a fourth subpath for one function or a second\n * copy — which is the exact defect it exists to prevent. It is a pure function\n * with no imports and no state, so a bundler that keeps it keeps a dozen lines.\n */\nexport function projectFrontendComponentDescriptors(\n components: Readonly<Record<string, ProviderFrontendComponentDescriptor & { readonly load?: unknown }>> | undefined,\n): Record<string, ProviderFrontendComponentDescriptor> | undefined {\n if (components === undefined) return undefined;\n\n const descriptors: Record<string, ProviderFrontendComponentDescriptor> = {};\n // An AUTHORED `components: {}` must not reach the wire either. The invariant\n // is \"contributes none has one spelling\", and guarding only on `undefined`\n // would have let the second spelling through from a provider that wrote the\n // empty map by hand.\n if (Object.keys(components).length === 0) return undefined;\n for (const [capability, declaration] of Object.entries(components)) {\n descriptors[capability] = projectFrontendComponentDescriptor(declaration);\n }\n return descriptors;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate-frontend-providers.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"hydrate-frontend-providers.d.ts","sourceRoot":"","sources":["../../../src/shared/hydrate-frontend-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAYH,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAE5B,uCAAuC,EACvC,iCAAiC,EACjC,gBAAgB,EACjB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EACV,0BAA0B,EAG1B,kCAAkC,EAClC,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;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4B,CAAC;IACnC,OAAO,CAAC,EAAE,aAAa,CAAC,iCAAiC,CAAC,CAAC;IAC3D,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,UAAU,CAAC,EAAE,0BAA0B,CAAC;IACxC;;;;OAIG;IACH,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,kBAAkB,CAAC,EAAE,kCAAkC,CAAC;IACxD;;;;;OAKG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,6BAA6B,CAAC,WAAW,SAAS,0BAA0B;IAC3F,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAAC;IACrD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,mCAAmC,KAAK,IAAI,CAAC;CACnF;AAgID;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAAC,WAAW,SAAS,0BAA0B,EAC3F,KAAK,EAAE,6BAA6B,CAAC,WAAW,CAAC,GAChD,GAAG,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAuO7C;AAED;;;;;;GAMG;AACH,wBAAgB,uCAAuC,CAAC,UAAU,EAAE,mCAAmC,GAAG,IAAI,CAG7G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate-frontend-providers.js","sourceRoot":"","sources":["../../../../src/shared/hydrate-frontend-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EACL,2BAA2B,EAC3B,qCAAqC,EACrC,uCAAuC,EACvC,oCAAoC,EACpC,qCAAqC,EACrC,sCAAsC,EACtC,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,sCAAsC,CAAC;AAiB9C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S,CAAC;YAC/B,YAAY;YACZ,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,OAAO;YACP,GAAG,EAAE,IAAI,EAAE,GAAG;YACd,UAAU,EAAE,IAAI,EAAE,UAAU;YAC5B,kBAAkB,EAAE,IAAI,EAAE,kBAAkB;YAC5C,GAAG,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uCAAuC,CAAC,UAA+C;IACrG,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,8BAA8B,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/**\n * The join between the two channels a frontend provider arrives on.\n *\n * ## What this replaces\n *\n * Hydration used to be one channel and a cast: the registry took each JSON\n * entry off `/application-config` and asserted it was a provider module. The\n * assertion held only while the module type carried nothing but strings. The\n * moment a provider needed to load an SDK, the field would have been dropped by\n * `JSON.stringify` — with no error at any layer — and the provider would have\n * looked declared and done nothing.\n *\n * ## The rule\n *\n * A provider is LIVE for a surface when it appears on BOTH channels:\n *\n * - **DATA** (`entries`) — the authority on *which providers this service has\n * turned on, in this environment*. Backend-resolved, per service, and the\n * only channel that can differ between environments.\n * - **CODE** (`modules`) — the authority on *what code this bundle actually\n * contains*. Written by `wildo config sync` into a\n * `frontend-providers.generated.ts` the bundle imports.\n *\n * DATA without CODE is still live — the provider's identity, capabilities and\n * public config are all real and a UI may list it — but it has nothing to\n * execute, so `sdk` and `publicConfigSchema` are absent and a diagnostic names\n * `wildo config sync`. CODE without DATA is not live and is skipped quietly:\n * a bundle legitimately ships code for providers a given environment leaves\n * off, and warning about that would train readers to ignore the channel.\n *\n * The result is a registry of module-shaped values, so every existing consumer\n * reads exactly what it read before. What changed is that the shape is now\n * BUILT rather than asserted, and each field has a stated owner.\n */\n\nimport {\n describeProviderFrontendSdk,\n normalizeProviderFrontendCspFootprint,\n partitionFrontendCapabilityPublicConfig,\n PROVIDER_FRONTEND_CSP_ORIGIN_BUCKETS,\n describeFrontendProviderNotConfigured,\n listUnsuppliedRequiredPublicConfigKeys,\n readDeclaredPublicConfigKeys,\n readRequiredPublicConfigKeys,\n} from '@wildo-ai/saas-models/public-runtime';\nimport type {\n FileStorageAccepted,\n FrontendProvidersBlock,\n ProviderFrontendCspFootprint,\n ProviderFrontendComponentDescriptor,\n ProviderFrontendCspFootprintDeclaration,\n ProviderFrontendScriptDeclaration,\n ProviderMetadata,\n} from '@wildo-ai/saas-models/public-runtime';\nimport type {\n ProviderFrontendComponents,\n ProviderFrontendPublicConfigFailure,\n ProviderFrontendPublicConfigResult,\n ProviderFrontendPublicConfigSchema,\n ProviderFrontendSdk,\n} from './frontend-provider-surface.types';\nimport { projectFrontendComponentDescriptor } from './frontend-provider-surface.types';\nimport { consentBasedProviderStopRefusal } from './frontend-provider-consent';\n\n/**\n * Why a hydration diagnostic was raised.\n *\n * A named vocabulary rather than message strings: a surface decides what to do\n * with a diagnostic (console, telemetry, a dev overlay) by its kind, and each\n * member is a distinct operator action.\n */\nexport enum FrontendProviderHydrationDiagnosticKind {\n /**\n * The service declares this provider, but the bundle carries no code for it.\n * Its data is served and its SDK cannot run. Remedy: `wildo config sync`, so\n * the generated `frontend-providers.generated.ts` imports the provider's\n * facet barrel.\n */\n CODE_MISSING_FOR_DECLARED_PROVIDER = 'CODE_MISSING_FOR_DECLARED_PROVIDER',\n /**\n * The generated module map keys a module under a ref that is not the ref on\n * the module's own metadata. The key is what the join uses, so trusting it\n * would silently bind one provider's code to another's configuration.\n */\n GENERATED_MODULE_REF_MISMATCH = 'GENERATED_MODULE_REF_MISMATCH',\n /**\n * The entry's CSP footprint or SDK descriptor disagrees with the module's.\n * The entry is what the service's Content-Security-Policy was composed from,\n * so a disagreement means the generated artifact predates the module — and\n * the consequence lands in production only, because CSP is report-only in\n * development. Remedy: `wildo config sync`.\n */\n GENERATED_ARTIFACT_STALE = 'GENERATED_ARTIFACT_STALE',\n /**\n * The bundle carries code for providers and the service declared NONE.\n *\n * Per-provider, code-without-data is silent on purpose — a bundle legitimately\n * ships code an environment leaves off. ALL code and ZERO data is a different\n * signal: almost always a backend older than this bundle, or a service whose\n * provider scope was never authored. Every consumer then degrades with no\n * symptom at all, which is the shape this diagnostic exists to break.\n */\n DATA_MISSING_FOR_BUNDLED_PROVIDERS = 'DATA_MISSING_FOR_BUNDLED_PROVIDERS',\n /** The provider's `publicConfig` did not satisfy the schema the module declares. */\n PUBLIC_CONFIG_INVALID = 'PUBLIC_CONFIG_INVALID',\n /**\n * The declared `publicConfigSchema` validated asynchronously. Hydration is\n * synchronous — it runs before first paint on three different bundlers — so\n * an async validator cannot be awaited here and its provider is treated as\n * having no code. Standard Schema permits async validation; Zod is\n * synchronous, which is why this is a refusal rather than a redesign.\n */\n PUBLIC_CONFIG_SCHEMA_ASYNC = 'PUBLIC_CONFIG_SCHEMA_ASYNC',\n /**\n * The bundled module declares no `publicConfigSchema` whose keys can be read\n * (#1705). Nothing then holds what it is served to a key list, so its code is\n * withheld — the same treatment as a config its schema rejects. `wildo config\n * sync` refuses the same module earlier; this is the gate for a bundle that\n * reached a browser without that sync (an application-authored module, a stale\n * generated map). Remedy: declare one with `defineFrontendPublicConfigSchema`.\n */\n PUBLIC_CONFIG_SCHEMA_MISSING = 'PUBLIC_CONFIG_SCHEMA_MISSING',\n /**\n * The provider rests on a consent purpose and could not be stopped when that consent is withdrawn\n * (#1704): it declares `<script>` tags, or its SDK does not declare `stoppable`. Its code AND its scripts\n * are withheld, so it never starts on this surface. The provider package's own projection refuses the\n * same module; this is the gate for a stale artifact or a hand-written contribution.\n */\n CONSENT_BASED_PROVIDER_NOT_STOPPABLE = 'CONSENT_BASED_PROVIDER_NOT_STOPPABLE',\n /**\n * The service declares the provider, but its `publicConfig` lacks a key the module requires (a DSN, a\n * project key, a site key), so it cannot run. Its code and scripts are withheld, and this is what the\n * surface reports instead of the activation failure the vendor SDK would otherwise throw. Distinct from\n * `PUBLIC_CONFIG_INVALID`, which is a value that was supplied and is wrong: here nothing was supplied,\n * and the remedy is to supply it. `wildo config sync` and `wildo local doctor` report the same gap from\n * the artifact before any browser does.\n */\n PUBLIC_CONFIG_NOT_SUPPLIED = 'PUBLIC_CONFIG_NOT_SUPPLIED',\n}\n\nexport interface FrontendProviderHydrationDiagnostic {\n readonly kind: FrontendProviderHydrationDiagnosticKind;\n readonly providerRef: string;\n /** One sentence naming the remedy, safe to log verbatim. */\n readonly message: string;\n}\n\n/**\n * The facet-agnostic view of a provider module the CODE channel supplies.\n *\n * All three facet module types satisfy it structurally; naming it separately\n * keeps this join free of any facet's branded capability types, which are the\n * one thing that genuinely cannot cross the wire (see the note on the narrowing\n * in each facet's `composeHydratedFrontend<Facet>Providers`).\n */\nexport interface FrontendProviderCodeModule {\n metadata: ProviderMetadata;\n csp?: ProviderFrontendCspFootprintDeclaration;\n sdk?: ProviderFrontendSdk;\n components?: ProviderFrontendComponents;\n fileStorage?: FileStorageAccepted;\n publicConfigSchema?: ProviderFrontendPublicConfigSchema;\n /** The vendor's purposes beyond its capabilities' floor (#1702) — compared with, and unioned into, the entry's. */\n consentPurposes?: ReadonlyArray<string>;\n}\n\n/**\n * One provider after the join: DATA for everything JSON can carry, CODE for\n * everything it cannot.\n *\n * `providerCapabilities` and `protocols` are `string` here because that is what\n * the wire carries. Narrowing them to a facet's union happens once, visibly, at\n * each facet boundary, as an unchecked cast. The reason given for leaving it\n * unchecked — that applications extend the union by module augmentation, so its\n * members do not exist at runtime — is no longer true: `ProviderCapability` is the\n * built-in set since #502 and `ProviderProtocol` is `BuiltinProviderProtocol`, and both DO exist at runtime (`BUILTIN_PROVIDER_CAPABILITY`,\n * `BUILTIN_PROVIDER_PROTOCOL`). The cast is therefore checkable and is not yet\n * checked.\n */\nexport interface HydratedFrontendProviderModule {\n metadata: ProviderMetadata;\n providerCapabilities: ReadonlyArray<string>;\n protocols: ReadonlyArray<string>;\n publicConfig: Readonly<Record<string, unknown>>;\n csp?: ProviderFrontendCspFootprint;\n scripts?: ReadonlyArray<ProviderFrontendScriptDeclaration>;\n sdk?: ProviderFrontendSdk;\n components?: ProviderFrontendComponents;\n /**\n * The z_file storage the provider's picker fronts, from the DATA channel —\n * the served entry, not the code module, because the chooser and the backend\n * link path both read the entry and must agree with what the CLI wrote.\n */\n fileStorage?: FileStorageAccepted;\n publicConfigSchema?: ProviderFrontendPublicConfigSchema;\n /**\n * The vendor's consent purposes beyond its capabilities' floor (#1702): the UNION of the served entry's\n * and the bundled module's. Unlike every other DATA field this is not simply the entry's, because the\n * two channels can disagree only when the artifact is stale, and taking either side alone would let\n * the stale one LOWER what the provider rests on. The union can only ever withhold more.\n */\n consentPurposes?: ReadonlyArray<string>;\n}\n\nexport interface HydrateFrontendProvidersInput<TCodeModule extends FrontendProviderCodeModule> {\n /** The DATA channel: the block hydrated from the backend, or read from the generated artifact. */\n readonly entries: FrontendProvidersBlock | undefined;\n /**\n * The CODE channel: `generatedFrontendProviderModules` from this service's\n * `frontend-providers.generated.ts`. Absent is legal and common — a service\n * with no package-shipped providers ships no such file.\n */\n readonly modules?: Readonly<Record<string, TCodeModule>>;\n readonly onDiagnostic?: (diagnostic: FrontendProviderHydrationDiagnostic) => void;\n}\n\n/**\n * A descriptor as one comparable string: keys sorted at every level, and an absent optional field left out\n * (the projection never writes `undefined`, except `selectionDelivery`, which JSON drops the same way on both sides).\n */\nfunction canonicalDescriptor(descriptor: ProviderFrontendComponentDescriptor): string {\n const sortKeys = (value: unknown): unknown => {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return value;\n return Object.fromEntries(Object.keys(value).sort().map((key) => [key, sortKeys((value as Record<string, unknown>)[key])]));\n };\n return JSON.stringify(sortKeys(descriptor));\n}\n\nfunction sameOriginList(left: readonly string[], right: readonly string[]): boolean {\n if (left.length !== right.length) return false;\n const sortedLeft = [...left].sort();\n const sortedRight = [...right].sort();\n return sortedLeft.every((origin, index) => origin === sortedRight[index]);\n}\n\n/**\n * Compares the footprint the CSP was composed from against the one the module\n * declares today. Order-insensitive, because neither channel promises an order\n * and a spurious staleness warning is how a real one stops being read.\n */\nfunction sameCspFootprint(\n entryFootprint: ProviderFrontendCspFootprint | undefined,\n moduleDeclaration: ProviderFrontendCspFootprintDeclaration | undefined,\n): boolean {\n if (entryFootprint === undefined || moduleDeclaration === undefined) {\n return entryFootprint === moduleDeclaration;\n }\n // The module side is a DECLARATION — partial by design — so it is normalized\n // before comparison. Without this, a provider that named one bucket would\n // differ from its own served footprint in every bucket it did not name, and the\n // staleness diagnostic would fire on every correctly-generated artifact.\n const moduleFootprint = normalizeProviderFrontendCspFootprint(moduleDeclaration);\n // Every bucket, from the enum (#1702): a hand-kept list here is where a new\n // bucket would go uncompared — the worker and media buckets would have.\n // An entry parsed from an artifact older than a bucket lacks that key, so an\n // absent bucket reads as empty rather than throwing.\n return PROVIDER_FRONTEND_CSP_ORIGIN_BUCKETS.every((bucket) => sameOriginList(entryFootprint[bucket] ?? [], moduleFootprint[bucket]));\n}\n\n/**\n * Validates `publicConfig` against the module's declared schema.\n *\n * Returns the validated config, or `undefined` when the provider must be\n * treated as code-less. Failing that way rather than dropping the provider\n * entirely is deliberate: a misconfigured analytics provider must not take a\n * page down, but it must also not half-run — so its data stays visible and\n * nothing of it executes.\n */\n/**\n * Standard Schema discriminates success from failure by the PRESENCE of\n * `issues`, which is a shape TypeScript narrows only through an explicit\n * predicate — the success member declares `issues?: undefined`, so a bare\n * `result.issues !== undefined` leaves the union intact at the use site.\n */\nfunction isPublicConfigFailure(\n result: ProviderFrontendPublicConfigResult<unknown>,\n): result is ProviderFrontendPublicConfigFailure {\n return result.issues !== undefined;\n}\n\nfunction validatePublicConfig(\n providerRef: string,\n publicConfig: Readonly<Record<string, unknown>>,\n schema: ProviderFrontendPublicConfigSchema,\n providerCapabilities: readonly string[] | undefined,\n raise: (diagnostic: FrontendProviderHydrationDiagnostic) => void,\n): Readonly<Record<string, unknown>> | undefined {\n /*\n * The keys a CAPABILITY owns are answered by that capability's schema, not by\n * the provider's (#380). Without the split, a picker declaring `appId` and an\n * application declaring `maxFileSizeMb` produced `unknown key` here — and the\n * caller's response to a rejected config is to drop the provider's CODE, so\n * setting a size limit DELETED the picker rather than limiting it.\n */\n const partition = partitionFrontendCapabilityPublicConfig({ providerCapabilities, publicConfig });\n if (partition.issues.length > 0) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_INVALID,\n providerRef,\n message:\n `Provider \"${providerRef}\" was served a publicConfig its own schema rejects, so none of its code will run. `\n + partition.issues.map((issue) => `${issue.path.map(String).join('.') || '(root)'}: ${issue.message}`).join('; '),\n });\n return undefined;\n }\n\n const result = schema['~standard'].validate(partition.providerConfig);\n\n if (result instanceof Promise) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_SCHEMA_ASYNC,\n providerRef,\n message:\n `Provider \"${providerRef}\" declares an asynchronous publicConfigSchema. Frontend provider hydration is `\n + 'synchronous, so the schema cannot be awaited; declare a synchronous validator (a Zod schema is one).',\n });\n return undefined;\n }\n\n if (isPublicConfigFailure(result)) {\n const detail = result.issues\n .map((issue) => {\n const path = (issue.path ?? [])\n .map((segment) => String(typeof segment === 'object' ? segment.key : segment))\n .join('.');\n return path.length > 0 ? `${path}: ${issue.message}` : issue.message;\n })\n .join('; ');\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_INVALID,\n providerRef,\n message:\n `Provider \"${providerRef}\" was served a publicConfig its own schema rejects, so none of its code will run. ${detail}`,\n });\n return undefined;\n }\n\n // Recombined: the partition is how the two schemas are asked their own\n // question, never a filter on what reaches a picker.\n return { ...partition.capabilityConfig, ...(result.value as Readonly<Record<string, unknown>>) };\n}\n\n/**\n * Joins the DATA and CODE channels into one module map, ready for\n * `composeProviderRegistry`.\n *\n * Synchronous on purpose: it runs before first paint on three bundlers, and an\n * asynchronous join would either block the first render or leave a window in\n * which a consumer reads an empty registry and degrades silently — which is the\n * shape of the bug this whole surface exists to remove.\n */\nexport function hydrateFrontendProviderModules<TCodeModule extends FrontendProviderCodeModule>(\n input: HydrateFrontendProvidersInput<TCodeModule>,\n): Map<string, HydratedFrontendProviderModule> {\n const raise = (diagnostic: FrontendProviderHydrationDiagnostic): void => {\n input.onDiagnostic?.(diagnostic);\n };\n const generatedModules = input.modules ?? {};\n const hydrated = new Map<string, HydratedFrontendProviderModule>();\n\n const declaredRefs = Object.keys(input.entries?.providers ?? {});\n const bundledRefs = Object.keys(generatedModules);\n if (declaredRefs.length === 0 && bundledRefs.length > 0) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.DATA_MISSING_FOR_BUNDLED_PROVIDERS,\n // No single provider owns this: it is a statement about the payload.\n providerRef: '',\n message:\n `This bundle carries code for ${bundledRefs.length} provider(s) — ${bundledRefs.join(', ')} — and the `\n + 'backend declared none for this service, so every provider-backed surface will render as though none '\n + 'exists. Usually a backend older than this bundle, or a frontend service whose provider scope was '\n + 'never authored; `wildo config sync` settles the second.',\n });\n }\n\n for (const [ref, entry] of Object.entries(input.entries?.providers ?? {})) {\n const generated = Object.prototype.hasOwnProperty.call(generatedModules, ref)\n ? generatedModules[ref]\n : undefined;\n\n let code: TCodeModule | undefined = generated;\n\n if (code !== undefined && code.metadata.ref !== ref) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_MODULE_REF_MISMATCH,\n providerRef: ref,\n message:\n `The generated frontend provider module map lists \"${ref}\" but the module it points at declares ref `\n + `\"${code.metadata.ref}\". Its code is ignored rather than bound to another provider's configuration; `\n + 'regenerate with `wildo config sync`.',\n });\n code = undefined;\n }\n\n if (code !== undefined && !sameCspFootprint(entry.csp, code.csp)) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares a CSP footprint that differs from the one its served entry carries, so the `\n + \"service's Content-Security-Policy was composed from a stale footprint. That surfaces in production \"\n + 'only, because CSP is report-only in development. Regenerate with `wildo config sync`.',\n });\n }\n\n // Compared by the words that describe each copy, which name the package or the hosted script: the two kinds\n // of descriptor carry different fields, and a field-by-field check would miss a package that became a script.\n if (code !== undefined && describeProviderFrontendSdk(entry.sdk) !== describeProviderFrontendSdk(code.sdk?.descriptor)) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares ${describeProviderFrontendSdk(code.sdk?.descriptor)} but its served `\n + `entry says ${describeProviderFrontendSdk(entry.sdk)}. Regenerate with \\`wildo config sync\\`.`,\n });\n }\n\n // The same staleness question for the component declarations (#380).\n //\n // It matters more here than for `csp` or `sdk`, because these two copies are\n // read by DIFFERENT parties for the SAME decision. The registry takes its\n // descriptor from the CODE side and the framework refuses a selection\n // against it; a reviewer, the CLI and any build step read the DATA side. So\n // a stale artifact makes the manifest and the ENFORCED contract disagree —\n // a provider whose entry says it returns a remote reference while its code\n // says otherwise — which is precisely the property issue #383 was answered\n // to establish.\n if (code !== undefined) {\n //\n // The WHOLE projected descriptor is compared, not one field of it. Until #561 only `selectionDelivery`\n // was, so a stale `placeIdRetention` (#1702) went unreported; an address lookup's declared operations,\n // session token and attribution (#561) would have joined it. One projection, compared as one value.\n for (const [capability, declared] of Object.entries(code.components ?? {})) {\n const expected = canonicalDescriptor(projectFrontendComponentDescriptor(declared));\n const servedDescriptor = entry.components?.[capability];\n const served = servedDescriptor === undefined ? undefined : canonicalDescriptor(projectFrontendComponentDescriptor(servedDescriptor));\n if (served === expected) continue;\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares its \"${capability}\" component as ${expected} but its served entry says `\n + `${served ?? '(none)'}. The framework enforces the CODE side, so the manifest a reviewer `\n + 'reads and the contract actually held would disagree. Regenerate with `wildo config sync`.',\n });\n }\n // And for the storage a picker fronts (#394 P5): the chooser filters on the\n // served entry, the backend refuses a link against its own registry, and a\n // stale entry would offer a picker to a field whose link the backend then\n // refuses — or hide one it would accept.\n if (code.fileStorage !== entry.fileStorage) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares its file picker fronts the \"${code.fileStorage ?? '(none)'}\" storage `\n + `but its served entry says \"${entry.fileStorage ?? '(none)'}\". Regenerate with \\`wildo config sync\\`.`,\n });\n }\n }\n\n // Consent purposes (#1702): a disagreement means a stale artifact, as for `csp`. Reported, and then\n // resolved by UNION below rather than by trusting either side — see `HydratedFrontendProviderModule`.\n // Kept as the raw strings both channels carry — never normalized here — so a purpose the consent\n // vocabulary does not know still reaches the decision and makes it fail closed rather than being\n // silently dropped (which, on an additive field, would lower the floor).\n const entryConsentPurposes = [...new Set(entry.consentPurposes ?? [])];\n const codeConsentPurposes = [...new Set(code?.consentPurposes ?? [])];\n if (code !== undefined && !sameOriginList(entryConsentPurposes, codeConsentPurposes)) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares consent purposes [${codeConsentPurposes.join(', ')}] but its served entry says `\n + `[${entryConsentPurposes.join(', ')}]. It is held to both until the artifact is regenerated with `\n + '`wildo config sync`.',\n });\n }\n const consentPurposes = [...new Set<string>([...entryConsentPurposes, ...codeConsentPurposes])];\n\n let publicConfig = (entry.publicConfig ?? {}) as Readonly<Record<string, unknown>>;\n\n // assurance-control: WILDO.SECURITY.FAIL_CLOSED — code without a readable public-config key list does not run in a browser\n if (code !== undefined && readDeclaredPublicConfigKeys(code.publicConfigSchema) === undefined) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_SCHEMA_MISSING,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares no publicConfigSchema whose keys can be read, so nothing holds what it is served to `\n + 'a key list and none of its code will run. Declare one with `defineFrontendPublicConfigSchema` (#1705).',\n });\n code = undefined;\n }\n\n // assurance-control: WILDO.PRIVACY.CONSENT_ENFORCEMENT — a consent-based provider that a withdrawal could not stop never reaches a runner\n // Asked of the DATA (its scripts, its consent inputs) with the CODE's stop declaration — the scripts a\n // surface would inject come from the entry, and `stoppable` exists only on the code.\n let scripts = entry.scripts;\n const stopRefusal = consentBasedProviderStopRefusal(ref, {\n providerCapabilities: entry.providerCapabilities,\n consentPurposes,\n scripts: entry.scripts,\n sdk: code?.sdk,\n });\n if (stopRefusal !== undefined) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.CONSENT_BASED_PROVIDER_NOT_STOPPABLE,\n providerRef: ref,\n message: `${stopRefusal} Its code and scripts are withheld on this surface.`,\n });\n code = undefined;\n scripts = undefined;\n }\n\n // assurance-control: WILDO.SECURITY.FAIL_CLOSED — a declared provider missing a key it requires does not start\n // Asked of both channels: the module's own schema (CODE) and the list its projection served (DATA), so a\n // stale bundle or a stale artifact still cannot start a provider with a hole in its configuration.\n if (code !== undefined || scripts !== undefined) {\n const requiredKeys = [...new Set([\n ...readRequiredPublicConfigKeys(code?.publicConfigSchema),\n ...(entry.requiredPublicConfigKeys ?? []),\n ])];\n const missingKeys = listUnsuppliedRequiredPublicConfigKeys(requiredKeys, publicConfig);\n if (missingKeys.length > 0) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_NOT_SUPPLIED,\n providerRef: ref,\n message: describeFrontendProviderNotConfigured({ providerRef: ref, missingKeys }),\n });\n code = undefined;\n scripts = undefined;\n }\n }\n\n if (code?.publicConfigSchema !== undefined) {\n const validated = validatePublicConfig(ref, publicConfig, code.publicConfigSchema, entry.providerCapabilities, raise);\n if (validated === undefined) {\n code = undefined;\n } else {\n publicConfig = validated;\n }\n }\n\n if (code === undefined && generated === undefined) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.CODE_MISSING_FOR_DECLARED_PROVIDER,\n providerRef: ref,\n message:\n `Frontend provider \"${ref}\" is declared for this service but the bundle carries no code for it, so its `\n + 'SDK and components are unavailable. Run `wildo config sync` to regenerate '\n + 'frontend-providers.generated.ts.',\n });\n }\n\n // The DATA channel is authoritative for everything it can carry: it is the\n // one that knows what this service turned on, in this environment. The CODE\n // channel contributes only what JSON cannot express — which is why the two\n // executable fields are read off `code` explicitly rather than spread: a\n // spread would also copy the code module's own stale `csp`, and the served\n // footprint is the one the policy was composed from.\n hydrated.set(ref, {\n // The entry's metadata is structurally looser than `ProviderMetadata`:\n // `ProviderOriginSchema` is a plain object whose \"GENERATED implies a\n // catalogue provenance\" rule is a `superRefine`, and a refinement cannot\n // be expressed in an inferred type. Every entry reaching this join has\n // been through that parse — the app parses the bootstrap response, the\n // website and the technical doc parse the materialized artifact — so the\n // rule holds and the narrowing is stating what the parse just proved.\n // Exactly the assertion `defineProviderMetadata` makes for the same\n // schema, at the other end of the same wire.\n metadata: entry.metadata as ProviderMetadata,\n providerCapabilities: [...entry.providerCapabilities],\n protocols: [...entry.protocols],\n publicConfig,\n csp: entry.csp,\n scripts,\n sdk: code?.sdk,\n components: code?.components,\n publicConfigSchema: code?.publicConfigSchema,\n ...(consentPurposes.length > 0 ? { consentPurposes } : {}),\n });\n }\n\n return hydrated;\n}\n\n/**\n * The default sink for hydration diagnostics on a surface with no logger service (the website and the\n * documentation site). Until it existed every hydration diagnostic there was dropped: a declared provider with no\n * key, a stale artifact or a bundle missing a provider's code all ended with the provider silently absent. Each one\n * names a provider that is declared and cannot fully run, so it is a warning, never a failure: the page still renders.\n * One function for both surfaces, so the two cannot drift in what they print.\n */\nexport function warnFrontendProviderHydrationDiagnostic(diagnostic: FrontendProviderHydrationDiagnostic): void {\n // eslint-disable-next-line no-console\n console.warn(`[wildo-provider-hydration] ${diagnostic.kind}: ${diagnostic.message}`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"hydrate-frontend-providers.js","sourceRoot":"","sources":["../../../src/shared/hydrate-frontend-providers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EACL,2BAA2B,EAC3B,qCAAqC,EACrC,uCAAuC,EACvC,oCAAoC,EACpC,qCAAqC,EACrC,sCAAsC,EACtC,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,sCAAsC,CAAC;AAiB9C,OAAO,EAAE,kCAAkC,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAE9E;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,uCAmEX;AAnED,WAAY,uCAAuC;IACjD;;;;;OAKG;IACH,oHAAyE,CAAA;IACzE;;;;OAIG;IACH,0GAA+D,CAAA;IAC/D;;;;;;OAMG;IACH,gGAAqD,CAAA;IACrD;;;;;;;;OAQG;IACH,oHAAyE,CAAA;IACzE,oFAAoF;IACpF,0FAA+C,CAAA;IAC/C;;;;;;OAMG;IACH,oGAAyD,CAAA;IACzD;;;;;;;OAOG;IACH,wGAA6D,CAAA;IAC7D;;;;;OAKG;IACH,wHAA6E,CAAA;IAC7E;;;;;;;OAOG;IACH,oGAAyD,CAAA;AAC3D,CAAC,EAnEW,uCAAuC,KAAvC,uCAAuC,QAmElD;AA8ED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,UAA+C;IAC1E,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAW,EAAE;QAC3C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACtF,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,E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D,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,uEAAuE;YACvE,sEAAsE;YACtE,yEAAyE;YACzE,uEAAuE;YACvE,uEAAuE;YACvE,yEAAyE;YACzE,sEAAsE;YACtE,oEAAoE;YACpE,6CAA6C;YAC7C,QAAQ,EAAE,KAAK,CAAC,QAA4B;YAC5C,oBAAoB,EAAE,CAAC,GAAG,KAAK,CAAC,oBAAoB,CAAC;YACrD,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;YAC/B,YAAY;YACZ,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,OAAO;YACP,GAAG,EAAE,IAAI,EAAE,GAAG;YACd,UAAU,EAAE,IAAI,EAAE,UAAU;YAC5B,kBAAkB,EAAE,IAAI,EAAE,kBAAkB;YAC5C,GAAG,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uCAAuC,CAAC,UAA+C;IACrG,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,8BAA8B,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/**\n * The join between the two channels a frontend provider arrives on.\n *\n * ## What this replaces\n *\n * Hydration used to be one channel and a cast: the registry took each JSON\n * entry off `/application-config` and asserted it was a provider module. The\n * assertion held only while the module type carried nothing but strings. The\n * moment a provider needed to load an SDK, the field would have been dropped by\n * `JSON.stringify` — with no error at any layer — and the provider would have\n * looked declared and done nothing.\n *\n * ## The rule\n *\n * A provider is LIVE for a surface when it appears on BOTH channels:\n *\n * - **DATA** (`entries`) — the authority on *which providers this service has\n * turned on, in this environment*. Backend-resolved, per service, and the\n * only channel that can differ between environments.\n * - **CODE** (`modules`) — the authority on *what code this bundle actually\n * contains*. Written by `wildo config sync` into a\n * `frontend-providers.generated.ts` the bundle imports.\n *\n * DATA without CODE is still live — the provider's identity, capabilities and\n * public config are all real and a UI may list it — but it has nothing to\n * execute, so `sdk` and `publicConfigSchema` are absent and a diagnostic names\n * `wildo config sync`. CODE without DATA is not live and is skipped quietly:\n * a bundle legitimately ships code for providers a given environment leaves\n * off, and warning about that would train readers to ignore the channel.\n *\n * The result is a registry of module-shaped values, so every existing consumer\n * reads exactly what it read before. What changed is that the shape is now\n * BUILT rather than asserted, and each field has a stated owner.\n */\n\nimport {\n describeProviderFrontendSdk,\n normalizeProviderFrontendCspFootprint,\n partitionFrontendCapabilityPublicConfig,\n PROVIDER_FRONTEND_CSP_ORIGIN_BUCKETS,\n describeFrontendProviderNotConfigured,\n listUnsuppliedRequiredPublicConfigKeys,\n readDeclaredPublicConfigKeys,\n readRequiredPublicConfigKeys,\n} from '@wildo-ai/saas-models/public-runtime';\nimport type {\n FileStorageAccepted,\n FrontendProvidersBlock,\n ProviderFrontendCspFootprint,\n ProviderFrontendComponentDescriptor,\n ProviderFrontendCspFootprintDeclaration,\n ProviderFrontendScriptDeclaration,\n ProviderMetadata,\n} from '@wildo-ai/saas-models/public-runtime';\nimport type {\n ProviderFrontendComponents,\n ProviderFrontendPublicConfigFailure,\n ProviderFrontendPublicConfigResult,\n ProviderFrontendPublicConfigSchema,\n ProviderFrontendSdk,\n} from './frontend-provider-surface.types';\nimport { projectFrontendComponentDescriptor } from './frontend-provider-surface.types';\nimport { consentBasedProviderStopRefusal } from './frontend-provider-consent';\n\n/**\n * Why a hydration diagnostic was raised.\n *\n * A named vocabulary rather than message strings: a surface decides what to do\n * with a diagnostic (console, telemetry, a dev overlay) by its kind, and each\n * member is a distinct operator action.\n */\nexport enum FrontendProviderHydrationDiagnosticKind {\n /**\n * The service declares this provider, but the bundle carries no code for it.\n * Its data is served and its SDK cannot run. Remedy: `wildo config sync`, so\n * the generated `frontend-providers.generated.ts` imports the provider's\n * facet barrel.\n */\n CODE_MISSING_FOR_DECLARED_PROVIDER = 'CODE_MISSING_FOR_DECLARED_PROVIDER',\n /**\n * The generated module map keys a module under a ref that is not the ref on\n * the module's own metadata. The key is what the join uses, so trusting it\n * would silently bind one provider's code to another's configuration.\n */\n GENERATED_MODULE_REF_MISMATCH = 'GENERATED_MODULE_REF_MISMATCH',\n /**\n * The entry's CSP footprint or SDK descriptor disagrees with the module's.\n * The entry is what the service's Content-Security-Policy was composed from,\n * so a disagreement means the generated artifact predates the module — and\n * the consequence lands in production only, because CSP is report-only in\n * development. Remedy: `wildo config sync`.\n */\n GENERATED_ARTIFACT_STALE = 'GENERATED_ARTIFACT_STALE',\n /**\n * The bundle carries code for providers and the service declared NONE.\n *\n * Per-provider, code-without-data is silent on purpose — a bundle legitimately\n * ships code an environment leaves off. ALL code and ZERO data is a different\n * signal: almost always a backend older than this bundle, or a service whose\n * provider scope was never authored. Every consumer then degrades with no\n * symptom at all, which is the shape this diagnostic exists to break.\n */\n DATA_MISSING_FOR_BUNDLED_PROVIDERS = 'DATA_MISSING_FOR_BUNDLED_PROVIDERS',\n /** The provider's `publicConfig` did not satisfy the schema the module declares. */\n PUBLIC_CONFIG_INVALID = 'PUBLIC_CONFIG_INVALID',\n /**\n * The declared `publicConfigSchema` validated asynchronously. Hydration is\n * synchronous — it runs before first paint on three different bundlers — so\n * an async validator cannot be awaited here and its provider is treated as\n * having no code. Standard Schema permits async validation; Zod is\n * synchronous, which is why this is a refusal rather than a redesign.\n */\n PUBLIC_CONFIG_SCHEMA_ASYNC = 'PUBLIC_CONFIG_SCHEMA_ASYNC',\n /**\n * The bundled module declares no `publicConfigSchema` whose keys can be read\n * (#1705). Nothing then holds what it is served to a key list, so its code is\n * withheld — the same treatment as a config its schema rejects. `wildo config\n * sync` refuses the same module earlier; this is the gate for a bundle that\n * reached a browser without that sync (an application-authored module, a stale\n * generated map). Remedy: declare one with `defineFrontendPublicConfigSchema`.\n */\n PUBLIC_CONFIG_SCHEMA_MISSING = 'PUBLIC_CONFIG_SCHEMA_MISSING',\n /**\n * The provider rests on a consent purpose and could not be stopped when that consent is withdrawn\n * (#1704): it declares `<script>` tags, or its SDK does not declare `stoppable`. Its code AND its scripts\n * are withheld, so it never starts on this surface. The provider package's own projection refuses the\n * same module; this is the gate for a stale artifact or a hand-written contribution.\n */\n CONSENT_BASED_PROVIDER_NOT_STOPPABLE = 'CONSENT_BASED_PROVIDER_NOT_STOPPABLE',\n /**\n * The service declares the provider, but its `publicConfig` lacks a key the module requires (a DSN, a\n * project key, a site key), so it cannot run. Its code and scripts are withheld, and this is what the\n * surface reports instead of the activation failure the vendor SDK would otherwise throw. Distinct from\n * `PUBLIC_CONFIG_INVALID`, which is a value that was supplied and is wrong: here nothing was supplied,\n * and the remedy is to supply it. `wildo config sync` and `wildo local doctor` report the same gap from\n * the artifact before any browser does.\n */\n PUBLIC_CONFIG_NOT_SUPPLIED = 'PUBLIC_CONFIG_NOT_SUPPLIED',\n}\n\nexport interface FrontendProviderHydrationDiagnostic {\n readonly kind: FrontendProviderHydrationDiagnosticKind;\n readonly providerRef: string;\n /** One sentence naming the remedy, safe to log verbatim. */\n readonly message: string;\n}\n\n/**\n * The facet-agnostic view of a provider module the CODE channel supplies.\n *\n * All three facet module types satisfy it structurally; naming it separately\n * keeps this join free of any facet's branded capability types, which are the\n * one thing that genuinely cannot cross the wire (see the note on the narrowing\n * in each facet's `composeHydratedFrontend<Facet>Providers`).\n */\nexport interface FrontendProviderCodeModule {\n metadata: ProviderMetadata;\n csp?: ProviderFrontendCspFootprintDeclaration;\n sdk?: ProviderFrontendSdk;\n components?: ProviderFrontendComponents;\n fileStorage?: FileStorageAccepted;\n publicConfigSchema?: ProviderFrontendPublicConfigSchema;\n /** The vendor's purposes beyond its capabilities' floor (#1702) — compared with, and unioned into, the entry's. */\n consentPurposes?: ReadonlyArray<string>;\n}\n\n/**\n * One provider after the join: DATA for everything JSON can carry, CODE for\n * everything it cannot.\n *\n * `providerCapabilities` and `protocols` are `string` here because that is what\n * the wire carries. Narrowing them to a facet's union happens once, visibly, at\n * each facet boundary, as an unchecked cast. The reason given for leaving it\n * unchecked — that applications extend the union by module augmentation, so its\n * members do not exist at runtime — is no longer true: `ProviderCapability` is the\n * built-in set since #502 and `ProviderProtocol` is `BuiltinProviderProtocol`, and both DO exist at runtime (`BUILTIN_PROVIDER_CAPABILITY`,\n * `BUILTIN_PROVIDER_PROTOCOL`). The cast is therefore checkable and is not yet\n * checked.\n */\nexport interface HydratedFrontendProviderModule {\n metadata: ProviderMetadata;\n providerCapabilities: ReadonlyArray<string>;\n protocols: ReadonlyArray<string>;\n publicConfig: Readonly<Record<string, unknown>>;\n csp?: ProviderFrontendCspFootprint;\n scripts?: ReadonlyArray<ProviderFrontendScriptDeclaration>;\n sdk?: ProviderFrontendSdk;\n components?: ProviderFrontendComponents;\n /**\n * The z_file storage the provider's picker fronts, from the DATA channel —\n * the served entry, not the code module, because the chooser and the backend\n * link path both read the entry and must agree with what the CLI wrote.\n */\n fileStorage?: FileStorageAccepted;\n publicConfigSchema?: ProviderFrontendPublicConfigSchema;\n /**\n * The vendor's consent purposes beyond its capabilities' floor (#1702): the UNION of the served entry's\n * and the bundled module's. Unlike every other DATA field this is not simply the entry's, because the\n * two channels can disagree only when the artifact is stale, and taking either side alone would let\n * the stale one LOWER what the provider rests on. The union can only ever withhold more.\n */\n consentPurposes?: ReadonlyArray<string>;\n}\n\nexport interface HydrateFrontendProvidersInput<TCodeModule extends FrontendProviderCodeModule> {\n /** The DATA channel: the block hydrated from the backend, or read from the generated artifact. */\n readonly entries: FrontendProvidersBlock | undefined;\n /**\n * The CODE channel: `generatedFrontendProviderModules` from this service's\n * `frontend-providers.generated.ts`. Absent is legal and common — a service\n * with no package-shipped providers ships no such file.\n */\n readonly modules?: Readonly<Record<string, TCodeModule>>;\n readonly onDiagnostic?: (diagnostic: FrontendProviderHydrationDiagnostic) => void;\n}\n\n/**\n * A descriptor as one comparable string: keys sorted at every level, and an absent optional field left out\n * (the projection never writes `undefined`, except `selectionDelivery`, which JSON drops the same way on both sides).\n */\nfunction canonicalDescriptor(descriptor: ProviderFrontendComponentDescriptor): string {\n const sortKeys = (value: unknown): unknown => {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return value;\n return Object.fromEntries(Object.keys(value).sort().map((key) => [key, sortKeys((value as Record<string, unknown>)[key])]));\n };\n return JSON.stringify(sortKeys(descriptor));\n}\n\nfunction sameOriginList(left: readonly string[], right: readonly string[]): boolean {\n if (left.length !== right.length) return false;\n const sortedLeft = [...left].sort();\n const sortedRight = [...right].sort();\n return sortedLeft.every((origin, index) => origin === sortedRight[index]);\n}\n\n/**\n * Compares the footprint the CSP was composed from against the one the module\n * declares today. Order-insensitive, because neither channel promises an order\n * and a spurious staleness warning is how a real one stops being read.\n */\nfunction sameCspFootprint(\n entryFootprint: ProviderFrontendCspFootprint | undefined,\n moduleDeclaration: ProviderFrontendCspFootprintDeclaration | undefined,\n): boolean {\n if (entryFootprint === undefined || moduleDeclaration === undefined) {\n return entryFootprint === moduleDeclaration;\n }\n // The module side is a DECLARATION — partial by design — so it is normalized\n // before comparison. Without this, a provider that named one bucket would\n // differ from its own served footprint in every bucket it did not name, and the\n // staleness diagnostic would fire on every correctly-generated artifact.\n const moduleFootprint = normalizeProviderFrontendCspFootprint(moduleDeclaration);\n // Every bucket, from the enum (#1702): a hand-kept list here is where a new\n // bucket would go uncompared — the worker and media buckets would have.\n // An entry parsed from an artifact older than a bucket lacks that key, so an\n // absent bucket reads as empty rather than throwing.\n return PROVIDER_FRONTEND_CSP_ORIGIN_BUCKETS.every((bucket) => sameOriginList(entryFootprint[bucket] ?? [], moduleFootprint[bucket]));\n}\n\n/**\n * Validates `publicConfig` against the module's declared schema.\n *\n * Returns the validated config, or `undefined` when the provider must be\n * treated as code-less. Failing that way rather than dropping the provider\n * entirely is deliberate: a misconfigured analytics provider must not take a\n * page down, but it must also not half-run — so its data stays visible and\n * nothing of it executes.\n */\n/**\n * Standard Schema discriminates success from failure by the PRESENCE of\n * `issues`, which is a shape TypeScript narrows only through an explicit\n * predicate — the success member declares `issues?: undefined`, so a bare\n * `result.issues !== undefined` leaves the union intact at the use site.\n */\nfunction isPublicConfigFailure(\n result: ProviderFrontendPublicConfigResult<unknown>,\n): result is ProviderFrontendPublicConfigFailure {\n return result.issues !== undefined;\n}\n\nfunction validatePublicConfig(\n providerRef: string,\n publicConfig: Readonly<Record<string, unknown>>,\n schema: ProviderFrontendPublicConfigSchema,\n providerCapabilities: readonly string[] | undefined,\n raise: (diagnostic: FrontendProviderHydrationDiagnostic) => void,\n): Readonly<Record<string, unknown>> | undefined {\n /*\n * The keys a CAPABILITY owns are answered by that capability's schema, not by\n * the provider's (#380). Without the split, a picker declaring `appId` and an\n * application declaring `maxFileSizeMb` produced `unknown key` here — and the\n * caller's response to a rejected config is to drop the provider's CODE, so\n * setting a size limit DELETED the picker rather than limiting it.\n */\n const partition = partitionFrontendCapabilityPublicConfig({ providerCapabilities, publicConfig });\n if (partition.issues.length > 0) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_INVALID,\n providerRef,\n message:\n `Provider \"${providerRef}\" was served a publicConfig its own schema rejects, so none of its code will run. `\n + partition.issues.map((issue) => `${issue.path.map(String).join('.') || '(root)'}: ${issue.message}`).join('; '),\n });\n return undefined;\n }\n\n const result = schema['~standard'].validate(partition.providerConfig);\n\n if (result instanceof Promise) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_SCHEMA_ASYNC,\n providerRef,\n message:\n `Provider \"${providerRef}\" declares an asynchronous publicConfigSchema. Frontend provider hydration is `\n + 'synchronous, so the schema cannot be awaited; declare a synchronous validator (a Zod schema is one).',\n });\n return undefined;\n }\n\n if (isPublicConfigFailure(result)) {\n const detail = result.issues\n .map((issue) => {\n const path = (issue.path ?? [])\n .map((segment) => String(typeof segment === 'object' ? segment.key : segment))\n .join('.');\n return path.length > 0 ? `${path}: ${issue.message}` : issue.message;\n })\n .join('; ');\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_INVALID,\n providerRef,\n message:\n `Provider \"${providerRef}\" was served a publicConfig its own schema rejects, so none of its code will run. ${detail}`,\n });\n return undefined;\n }\n\n // Recombined: the partition is how the two schemas are asked their own\n // question, never a filter on what reaches a picker.\n return { ...partition.capabilityConfig, ...(result.value as Readonly<Record<string, unknown>>) };\n}\n\n/**\n * Joins the DATA and CODE channels into one module map, ready for\n * `composeProviderRegistry`.\n *\n * Synchronous on purpose: it runs before first paint on three bundlers, and an\n * asynchronous join would either block the first render or leave a window in\n * which a consumer reads an empty registry and degrades silently — which is the\n * shape of the bug this whole surface exists to remove.\n */\nexport function hydrateFrontendProviderModules<TCodeModule extends FrontendProviderCodeModule>(\n input: HydrateFrontendProvidersInput<TCodeModule>,\n): Map<string, HydratedFrontendProviderModule> {\n const raise = (diagnostic: FrontendProviderHydrationDiagnostic): void => {\n input.onDiagnostic?.(diagnostic);\n };\n const generatedModules = input.modules ?? {};\n const hydrated = new Map<string, HydratedFrontendProviderModule>();\n\n const declaredRefs = Object.keys(input.entries?.providers ?? {});\n const bundledRefs = Object.keys(generatedModules);\n if (declaredRefs.length === 0 && bundledRefs.length > 0) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.DATA_MISSING_FOR_BUNDLED_PROVIDERS,\n // No single provider owns this: it is a statement about the payload.\n providerRef: '',\n message:\n `This bundle carries code for ${bundledRefs.length} provider(s) — ${bundledRefs.join(', ')} — and the `\n + 'backend declared none for this service, so every provider-backed surface will render as though none '\n + 'exists. Usually a backend older than this bundle, or a frontend service whose provider scope was '\n + 'never authored; `wildo config sync` settles the second.',\n });\n }\n\n for (const [ref, entry] of Object.entries(input.entries?.providers ?? {})) {\n const generated = Object.prototype.hasOwnProperty.call(generatedModules, ref)\n ? generatedModules[ref]\n : undefined;\n\n let code: TCodeModule | undefined = generated;\n\n if (code !== undefined && code.metadata.ref !== ref) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_MODULE_REF_MISMATCH,\n providerRef: ref,\n message:\n `The generated frontend provider module map lists \"${ref}\" but the module it points at declares ref `\n + `\"${code.metadata.ref}\". Its code is ignored rather than bound to another provider's configuration; `\n + 'regenerate with `wildo config sync`.',\n });\n code = undefined;\n }\n\n if (code !== undefined && !sameCspFootprint(entry.csp, code.csp)) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares a CSP footprint that differs from the one its served entry carries, so the `\n + \"service's Content-Security-Policy was composed from a stale footprint. That surfaces in production \"\n + 'only, because CSP is report-only in development. Regenerate with `wildo config sync`.',\n });\n }\n\n // Compared by the words that describe each copy, which name the package or the hosted script: the two kinds\n // of descriptor carry different fields, and a field-by-field check would miss a package that became a script.\n if (code !== undefined && describeProviderFrontendSdk(entry.sdk) !== describeProviderFrontendSdk(code.sdk?.descriptor)) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares ${describeProviderFrontendSdk(code.sdk?.descriptor)} but its served `\n + `entry says ${describeProviderFrontendSdk(entry.sdk)}. Regenerate with \\`wildo config sync\\`.`,\n });\n }\n\n // The same staleness question for the component declarations (#380).\n //\n // It matters more here than for `csp` or `sdk`, because these two copies are\n // read by DIFFERENT parties for the SAME decision. The registry takes its\n // descriptor from the CODE side and the framework refuses a selection\n // against it; a reviewer, the CLI and any build step read the DATA side. So\n // a stale artifact makes the manifest and the ENFORCED contract disagree —\n // a provider whose entry says it returns a remote reference while its code\n // says otherwise — which is precisely the property issue #383 was answered\n // to establish.\n if (code !== undefined) {\n //\n // The WHOLE projected descriptor is compared, not one field of it. Until #561 only `selectionDelivery`\n // was, so a stale `placeIdRetention` (#1702) went unreported; an address lookup's declared operations,\n // session token and attribution (#561) would have joined it. One projection, compared as one value.\n for (const [capability, declared] of Object.entries(code.components ?? {})) {\n const expected = canonicalDescriptor(projectFrontendComponentDescriptor(declared));\n const servedDescriptor = entry.components?.[capability];\n const served = servedDescriptor === undefined ? undefined : canonicalDescriptor(projectFrontendComponentDescriptor(servedDescriptor));\n if (served === expected) continue;\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares its \"${capability}\" component as ${expected} but its served entry says `\n + `${served ?? '(none)'}. The framework enforces the CODE side, so the manifest a reviewer `\n + 'reads and the contract actually held would disagree. Regenerate with `wildo config sync`.',\n });\n }\n // And for the storage a picker fronts (#394 P5): the chooser filters on the\n // served entry, the backend refuses a link against its own registry, and a\n // stale entry would offer a picker to a field whose link the backend then\n // refuses — or hide one it would accept.\n if (code.fileStorage !== entry.fileStorage) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares its file picker fronts the \"${code.fileStorage ?? '(none)'}\" storage `\n + `but its served entry says \"${entry.fileStorage ?? '(none)'}\". Regenerate with \\`wildo config sync\\`.`,\n });\n }\n }\n\n // Consent purposes (#1702): a disagreement means a stale artifact, as for `csp`. Reported, and then\n // resolved by UNION below rather than by trusting either side — see `HydratedFrontendProviderModule`.\n // Kept as the raw strings both channels carry — never normalized here — so a purpose the consent\n // vocabulary does not know still reaches the decision and makes it fail closed rather than being\n // silently dropped (which, on an additive field, would lower the floor).\n const entryConsentPurposes = [...new Set(entry.consentPurposes ?? [])];\n const codeConsentPurposes = [...new Set(code?.consentPurposes ?? [])];\n if (code !== undefined && !sameOriginList(entryConsentPurposes, codeConsentPurposes)) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.GENERATED_ARTIFACT_STALE,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares consent purposes [${codeConsentPurposes.join(', ')}] but its served entry says `\n + `[${entryConsentPurposes.join(', ')}]. It is held to both until the artifact is regenerated with `\n + '`wildo config sync`.',\n });\n }\n const consentPurposes = [...new Set<string>([...entryConsentPurposes, ...codeConsentPurposes])];\n\n let publicConfig = (entry.publicConfig ?? {}) as Readonly<Record<string, unknown>>;\n\n // assurance-control: WILDO.SECURITY.FAIL_CLOSED — code without a readable public-config key list does not run in a browser\n if (code !== undefined && readDeclaredPublicConfigKeys(code.publicConfigSchema) === undefined) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_SCHEMA_MISSING,\n providerRef: ref,\n message:\n `Provider \"${ref}\" declares no publicConfigSchema whose keys can be read, so nothing holds what it is served to `\n + 'a key list and none of its code will run. Declare one with `defineFrontendPublicConfigSchema` (#1705).',\n });\n code = undefined;\n }\n\n // assurance-control: WILDO.PRIVACY.CONSENT_ENFORCEMENT — a consent-based provider that a withdrawal could not stop never reaches a runner\n // Asked of the DATA (its scripts, its consent inputs) with the CODE's stop declaration — the scripts a\n // surface would inject come from the entry, and `stoppable` exists only on the code.\n let scripts = entry.scripts;\n const stopRefusal = consentBasedProviderStopRefusal(ref, {\n providerCapabilities: entry.providerCapabilities,\n consentPurposes,\n scripts: entry.scripts,\n sdk: code?.sdk,\n });\n if (stopRefusal !== undefined) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.CONSENT_BASED_PROVIDER_NOT_STOPPABLE,\n providerRef: ref,\n message: `${stopRefusal} Its code and scripts are withheld on this surface.`,\n });\n code = undefined;\n scripts = undefined;\n }\n\n // assurance-control: WILDO.SECURITY.FAIL_CLOSED — a declared provider missing a key it requires does not start\n // Asked of both channels: the module's own schema (CODE) and the list its projection served (DATA), so a\n // stale bundle or a stale artifact still cannot start a provider with a hole in its configuration.\n if (code !== undefined || scripts !== undefined) {\n const requiredKeys = [...new Set([\n ...readRequiredPublicConfigKeys(code?.publicConfigSchema),\n ...(entry.requiredPublicConfigKeys ?? []),\n ])];\n const missingKeys = listUnsuppliedRequiredPublicConfigKeys(requiredKeys, publicConfig);\n if (missingKeys.length > 0) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.PUBLIC_CONFIG_NOT_SUPPLIED,\n providerRef: ref,\n message: describeFrontendProviderNotConfigured({ providerRef: ref, missingKeys }),\n });\n code = undefined;\n scripts = undefined;\n }\n }\n\n if (code?.publicConfigSchema !== undefined) {\n const validated = validatePublicConfig(ref, publicConfig, code.publicConfigSchema, entry.providerCapabilities, raise);\n if (validated === undefined) {\n code = undefined;\n } else {\n publicConfig = validated;\n }\n }\n\n if (code === undefined && generated === undefined) {\n raise({\n kind: FrontendProviderHydrationDiagnosticKind.CODE_MISSING_FOR_DECLARED_PROVIDER,\n providerRef: ref,\n message:\n `Frontend provider \"${ref}\" is declared for this service but the bundle carries no code for it, so its `\n + 'SDK and components are unavailable. Run `wildo config sync` to regenerate '\n + 'frontend-providers.generated.ts.',\n });\n }\n\n // The DATA channel is authoritative for everything it can carry: it is the\n // one that knows what this service turned on, in this environment. The CODE\n // channel contributes only what JSON cannot express — which is why the two\n // executable fields are read off `code` explicitly rather than spread: a\n // spread would also copy the code module's own stale `csp`, and the served\n // footprint is the one the policy was composed from.\n hydrated.set(ref, {\n // The entry's metadata is structurally looser than `ProviderMetadata`:\n // `ProviderOriginSchema` is a plain object whose \"GENERATED implies a\n // catalogue provenance\" rule is a `superRefine`, and a refinement cannot\n // be expressed in an inferred type. Every entry reaching this join has\n // been through that parse — the app parses the bootstrap response, the\n // website and the technical doc parse the materialized artifact — so the\n // rule holds and the narrowing is stating what the parse just proved.\n // Exactly the assertion `defineProviderMetadata` makes for the same\n // schema, at the other end of the same wire.\n metadata: entry.metadata as ProviderMetadata,\n providerCapabilities: [...entry.providerCapabilities],\n protocols: [...entry.protocols],\n publicConfig,\n csp: entry.csp,\n scripts,\n sdk: code?.sdk,\n components: code?.components,\n publicConfigSchema: code?.publicConfigSchema,\n ...(consentPurposes.length > 0 ? { consentPurposes } : {}),\n });\n }\n\n return hydrated;\n}\n\n/**\n * The default sink for hydration diagnostics on a surface with no logger service (the website and the\n * documentation site). Until it existed every hydration diagnostic there was dropped: a declared provider with no\n * key, a stale artifact or a bundle missing a provider's code all ended with the provider silently absent. Each one\n * names a provider that is declared and cannot fully run, so it is a warning, never a failure: the page still renders.\n * One function for both surfaces, so the two cannot drift in what they print.\n */\nexport function warnFrontendProviderHydrationDiagnostic(diagnostic: FrontendProviderHydrationDiagnostic): void {\n // eslint-disable-next-line no-console\n console.warn(`[wildo-provider-hydration] ${diagnostic.kind}: ${diagnostic.message}`);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-frontend-provider-scripts.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"load-frontend-provider-scripts.d.ts","sourceRoot":"","sources":["../../../src/shared/load-frontend-provider-scripts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,sCAAsC,CAAC;AAG9F;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,+BAA+B,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,qCAAqC,CAAC;AAElF,4GAA4G;AAC5G,oBAAY,uBAAuB;IACjC,4FAA4F;IAC5F,OAAO,YAAY;IACnB,wFAAwF;IACxF,MAAM,WAAW;IACjB;;;;;OAKG;IACH,MAAM,WAAW;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,iCAAiC,CAAC;CACzD;AAED;;;;GAIG;AACH,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,iCAAiC,CAAC,CAAC;IACpE,iGAAiG;IACjG,QAAQ,CAA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