@jini-ai/cookie-consent 0.7.3-next.1 → 0.7.3-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/client.min.js +1 -1
  2. package/dist/contract.d.ts +2 -78
  3. package/dist/extensions.min.js +1 -1
  4. package/dist/react/ConsentFields.d.ts +4 -1
  5. package/dist/react/ConsentFields.js +11 -5
  6. package/dist/render/css.d.ts +2 -12
  7. package/dist/site/config.d.ts +51 -0
  8. package/dist/site/config.js +75 -0
  9. package/dist/site/cookie-consent.d.ts +53 -0
  10. package/dist/site/cookie-consent.js +47 -0
  11. package/dist/site/document-assets.d.ts +44 -0
  12. package/dist/site/document-assets.js +78 -0
  13. package/dist/site/document-state.d.ts +71 -0
  14. package/dist/site/document-state.js +79 -0
  15. package/dist/site/ensure-privacy-defaults.d.ts +63 -0
  16. package/dist/site/ensure-privacy-defaults.js +44 -0
  17. package/dist/site/http.d.ts +281 -0
  18. package/dist/site/http.js +271 -0
  19. package/dist/site/pre-consent-cache.d.ts +33 -0
  20. package/dist/site/pre-consent-cache.js +43 -0
  21. package/dist/site/privacy-page-template.d.ts +9 -0
  22. package/dist/site/privacy-page-template.js +17 -0
  23. package/dist/site/readiness.d.ts +29 -0
  24. package/dist/site/readiness.js +91 -0
  25. package/dist/site/region-plugins.d.ts +90 -0
  26. package/dist/site/region-plugins.js +73 -0
  27. package/dist/site/request.d.ts +19 -0
  28. package/dist/site/request.js +29 -0
  29. package/dist/site/revisions.d.ts +33 -0
  30. package/dist/site/revisions.js +5 -0
  31. package/dist/site/revisions.repo.d.ts +20 -0
  32. package/dist/site/revisions.repo.js +53 -0
  33. package/dist/site/service.d.ts +204 -0
  34. package/dist/site/service.js +198 -0
  35. package/dist/site/settings.d.ts +54 -0
  36. package/dist/site/settings.js +100 -0
  37. package/dist/site/tool-registrations.d.ts +63 -0
  38. package/dist/site/tool-registrations.js +69 -0
  39. package/dist/site/validation.d.ts +21 -0
  40. package/dist/site/validation.js +77 -0
  41. package/package.json +138 -10
@@ -0,0 +1,78 @@
1
+ import { renderBanner, renderScriptAssets } from '../render/index.js';
2
+ import { siteBannerMode, toSiteCookieConsent } from './cookie-consent.js';
3
+ /** Document construction consumes data, never a completed response body. */
4
+ export async function siteConsentDocumentAssets(required, _optional = {}) {
5
+ const { scripts, static: staticDocument } = required;
6
+ const config = await required.readPolicy();
7
+ if (staticDocument)
8
+ return staticDocumentAssets({ config, required, scripts });
9
+ const allScripts = [...scripts, ...await required.readDeclarations()];
10
+ if (required.preview())
11
+ return { head: renderScriptAssets({ scripts: allScripts.filter(script => script.consent === undefined) }), body: '' };
12
+ if (!config || !required.hasConsent)
13
+ return { head: renderScriptAssets({ scripts: allScripts.filter(script => script.consent === undefined) }), body: '' };
14
+ if (siteBannerMode({ config }) === 'off')
15
+ return { head: renderScriptAssets({ scripts: allScripts }), body: '' };
16
+ return renderDocumentConsent({ required, config, scripts: allScripts });
17
+ }
18
+ /** Static documents share managed shells' cached publication; off-mode declarations need no consent runtime.
19
+ * @complexity O(declared scripts) time/space when off; reuses the cached declaration Promise without I/O. */
20
+ async function staticDocumentAssets({ config, required, scripts }) {
21
+ if (!config || required.preview())
22
+ return { head: '', body: '' };
23
+ if (siteBannerMode({ config }) === 'off') {
24
+ const allScripts = [...scripts, ...await required.readDeclarations()];
25
+ return { head: renderScriptAssets({ scripts: allScripts }), body: '' };
26
+ }
27
+ return { head: `<script src="${required.loaderSrc}" defer data-jini-consent-loader></script>`, body: '' };
28
+ }
29
+ /** Render the shared banner and client assets once a usable snapshot has been selected. */
30
+ async function renderDocumentConsent({ required, config, scripts }) {
31
+ const live = !required.exporting();
32
+ const plugins = await required.plugins({ live });
33
+ const { banner, options } = toSiteCookieConsent({ config, policy: config.policyVersion }, { plugins });
34
+ const rendered = renderBanner({ ...banner, client: { ...banner.client, scripts, ...(live ? { context: `${required.endpoint}/context` } : {}) } }, {
35
+ ...options, ...(required.clientSrc === undefined ? {} : { clientSrc: required.clientSrc }), extensionSrc: required.extensionSrc,
36
+ evidence: live ? { mode: 'durable', endpoint: required.endpoint } : { mode: 'local' },
37
+ });
38
+ return { head: rendered.head, body: rendered.body + '<a class="jini-consent-settings" href="#privacy-choices" data-consent-open>Cookie settings</a>' };
39
+ }
40
+ /** JSON declaration URLs are invisible to an HTML crawler. No live collectors enter an export. */
41
+ export async function siteConsentExportAssets({ readPolicy, readDeclarations, hasConsent, client, extensionSrc }, _optional = {}) {
42
+ const config = await readPolicy();
43
+ const declared = await readDeclarations();
44
+ const local = declared.filter(script => script.src.startsWith('/') && (config || script.consent === undefined)).map(script => script.src);
45
+ if (!config || siteBannerMode({ config }) === 'off')
46
+ return local;
47
+ if (!hasConsent())
48
+ throw new Error('cookie consent export has no consent configuration');
49
+ const loadedClient = client();
50
+ return [...(loadedClient ? [loadedClient.src] : []), extensionSrc, ...local];
51
+ }
52
+ export function staticConsentLoaderScript({ head, body, exporting }, _optional = {}) {
53
+ return `(()=>{
54
+ if(document.getElementById('jini-consent-config'))return;
55
+ const template=document.createElement('template');template.innerHTML=${JSON.stringify(head + body)};
56
+ ${exporting ? String.raw `// Only this server-owned contribution is rebased, never the authored document.
57
+ const base=document.currentScript?new URL('..',document.currentScript.src).pathname.replace(/\/$/,''):'';
58
+ const prefix=value=>typeof value==='string'&&/^\/(?!\/)/.test(value)?base+value:value;
59
+ for(const node of template.content.querySelectorAll('[src],[href]')){
60
+ for(const attr of ['src','href'])if(node.hasAttribute(attr))node.setAttribute(attr,prefix(node.getAttribute(attr)));}
61
+ const config=template.content.querySelector('#jini-consent-config');
62
+ if(config)config.textContent=JSON.stringify(JSON.parse(config.textContent),(key,value)=>key==='src'?prefix(value):value);` : ''}
63
+ const scripts=[];
64
+ for(const node of [...template.content.childNodes]){
65
+ if(node.nodeName==='SCRIPT'&&node.getAttribute('src'))scripts.push(node);
66
+ else document.body.append(node);
67
+ }
68
+ for(const node of scripts){const script=document.createElement('script');
69
+ for(const attr of node.attributes)script.setAttribute(attr.name,attr.value);
70
+ script.async=false;document.body.append(script);}
71
+ })();`;
72
+ }
73
+ export async function documentPlugins(required, _optional = {}) {
74
+ if (!required.live)
75
+ return [];
76
+ return [...required.adapters(), ...await required.browserPlugins(), ...(await required.diagnosticsEnabled() ? [required.diagnostics()] : [])];
77
+ }
78
+ //# sourceMappingURL=document-assets.js.map
@@ -0,0 +1,71 @@
1
+ import type { SiteCookieConsentDeps } from "@jini-ai/core/contracts/headless/site-cookie-consent";
2
+ import type { ConsentConfig, DeclaredScript } from '@jini-ai/core/contracts/site/cookie-consent';
3
+ /** One published construction snapshot per site (per consent deps), shared by every app built over
4
+ * them: an export, an inspection or a theme override never resets what live visitors are served.
5
+ * Refreshed by publication. No per-page reads. */
6
+ export type DocumentState = {
7
+ policy?: ConsentConfig;
8
+ pending?: Promise<void> | undefined;
9
+ scripts: Promise<readonly DeclaredScript[]>;
10
+ client?: {
11
+ body: Uint8Array;
12
+ src: string;
13
+ } | undefined;
14
+ nextReadAt: number;
15
+ now: () => number;
16
+ schedule: (run: () => void, delayMs: number) => () => void;
17
+ refresh?: () => Promise<void>;
18
+ };
19
+ /** One read per minute per mounted site, including a retry after an unavailable publication. */
20
+ export declare function documentPolicy({ state }: {
21
+ state: DocumentState | undefined;
22
+ }, _optional?: {}): Promise<ConsentConfig | null>;
23
+ /** Wait at most 250 ms for a read in flight; with none, resolve at once. A late success still lands. */
24
+ export declare function briefPendingRead({ state }: {
25
+ state: DocumentState;
26
+ }, _optional?: {}): Promise<void>;
27
+ /** Read the policy and plugin declarations together. Each keeps its last good value on failure.
28
+ * @complexity O(1): one policy read and one declaration load at a time. */
29
+ export declare function refreshDocumentState({ state, readPolicy, readDeclarations, policyFailure, declarationFailure }: {
30
+ state: DocumentState;
31
+ readPolicy: () => Promise<ConsentConfig>;
32
+ readDeclarations: () => Promise<{
33
+ scripts: readonly DeclaredScript[];
34
+ }>;
35
+ policyFailure: (error: unknown) => void;
36
+ declarationFailure: () => void;
37
+ }, _optional?: {}): Promise<void>;
38
+ export declare function createSiteConsentDocumentOwner(required: {
39
+ schedule: DocumentState['schedule'];
40
+ exportUnavailableWarning: string;
41
+ }, _optional?: {}): {
42
+ unavailableDocumentPolicy: ({ consent, config }: {
43
+ consent: SiteCookieConsentDeps | undefined;
44
+ config: ConsentConfig | null;
45
+ }) => boolean;
46
+ documentDeclarations: ({ consent }: {
47
+ consent: SiteCookieConsentDeps | undefined;
48
+ }) => Promise<readonly DeclaredScript[]>;
49
+ documentPolicy: ({ consent }: {
50
+ consent: SiteCookieConsentDeps | undefined;
51
+ }) => Promise<ConsentConfig | null>;
52
+ client: ({ consent }: {
53
+ consent: SiteCookieConsentDeps | undefined;
54
+ }) => {
55
+ body: Uint8Array;
56
+ src: string;
57
+ } | undefined;
58
+ siteDocumentState: ({ consent, client, readPolicy, readDeclarations, policyFailure, declarationFailure, exportAssets, now }: {
59
+ now: DocumentState["now"];
60
+ consent: SiteCookieConsentDeps;
61
+ client: () => DocumentState["client"];
62
+ readPolicy: () => Promise<ConsentConfig>;
63
+ readDeclarations: () => Promise<{
64
+ scripts: readonly DeclaredScript[];
65
+ }>;
66
+ policyFailure: (error: unknown) => void;
67
+ declarationFailure: () => void;
68
+ exportAssets: () => Promise<readonly string[]>;
69
+ }) => DocumentState;
70
+ };
71
+ //# sourceMappingURL=document-state.d.ts.map
@@ -0,0 +1,79 @@
1
+ import { siteBannerMode } from "./cookie-consent.js";
2
+ /** One read per minute per mounted site, including a retry after an unavailable publication. */
3
+ export async function documentPolicy({ state }, _optional = {}) {
4
+ if (!state)
5
+ return null;
6
+ if (state.now() >= state.nextReadAt) {
7
+ // The refresh logs its own failure; visitors keep the last good policy.
8
+ void state.refresh?.().catch(() => undefined);
9
+ }
10
+ if (state.policy)
11
+ return state.policy;
12
+ await briefPendingRead({ state });
13
+ return state.policy ?? null;
14
+ }
15
+ /** Wait at most 250 ms for a read in flight; with none, resolve at once. A late success still lands. */
16
+ export async function briefPendingRead({ state }, _optional = {}) {
17
+ let timer;
18
+ // The refresh logs its own failure; a failed or slow read leaves the last good policy in use.
19
+ try {
20
+ await Promise.race([state.pending?.catch(() => undefined), new Promise(resolve => { timer = state.schedule(() => resolve(undefined), 250); })]);
21
+ }
22
+ finally {
23
+ timer?.();
24
+ }
25
+ }
26
+ /** Read the policy and plugin declarations together. Each keeps its last good value on failure.
27
+ * @complexity O(1): one policy read and one declaration load at a time. */
28
+ export function refreshDocumentState({ state, readPolicy, readDeclarations, policyFailure, declarationFailure }, _optional = {}) {
29
+ if (state.pending)
30
+ return state.pending;
31
+ state.nextReadAt = state.now() + 60_000;
32
+ const policy = readPolicy().then(config => { state.policy = config; }, error => {
33
+ policyFailure(error);
34
+ throw error;
35
+ });
36
+ const lastGoodScripts = state.scripts;
37
+ state.scripts = readDeclarations().then(loaded => loaded.scripts, () => {
38
+ declarationFailure();
39
+ return lastGoodScripts;
40
+ });
41
+ state.pending = Promise.allSettled([policy, state.scripts]).then(([read]) => {
42
+ if (read.status === 'rejected')
43
+ throw read.reason;
44
+ }).finally(() => { state.pending = undefined; });
45
+ return state.pending;
46
+ }
47
+ export function createSiteConsentDocumentOwner(required, _optional = {}) {
48
+ const documentStates = new WeakMap();
49
+ return {
50
+ unavailableDocumentPolicy: ({ consent, config }) => Boolean(consent && documentStates.has(consent) && !config),
51
+ documentDeclarations: async ({ consent }) => consent ? await documentStates.get(consent)?.scripts ?? [] : [],
52
+ documentPolicy: ({ consent }) => documentPolicy({ state: consent ? documentStates.get(consent) : undefined }),
53
+ client: ({ consent }) => consent ? documentStates.get(consent)?.client : undefined,
54
+ siteDocumentState: ({ consent, client, readPolicy, readDeclarations, policyFailure, declarationFailure, exportAssets, now }) => {
55
+ const existing = documentStates.get(consent);
56
+ if (existing)
57
+ return existing;
58
+ const state = { client: client(), scripts: Promise.resolve([]), nextReadAt: Infinity, now, schedule: required.schedule };
59
+ documentStates.set(consent, state);
60
+ const refresh = () => refreshDocumentState({ state, readPolicy, readDeclarations, policyFailure, declarationFailure });
61
+ consent.refresh = refresh;
62
+ state.refresh = refresh;
63
+ consent.embedConsentOff = () => Boolean(state.policy && siteBannerMode({ config: state.policy }) === 'off');
64
+ consent.exportAssets = exportAssets;
65
+ // Answered for one export run, before it renders. A good policy is never cleared, so no later page
66
+ // can lose its banner when this finds one; a run starts from a fresh read, as it always has.
67
+ consent.exportWarning = async () => {
68
+ // The refresh logs its own failure; the export uses the last good policy or its warning.
69
+ void refresh().catch(() => undefined);
70
+ await briefPendingRead({ state });
71
+ return state.policy ? undefined : required.exportUnavailableWarning;
72
+ };
73
+ // The refresh logs its own failure; startup continues without an unavailable policy.
74
+ void refresh().catch(() => undefined);
75
+ return state;
76
+ },
77
+ };
78
+ }
79
+ //# sourceMappingURL=document-state.js.map
@@ -0,0 +1,63 @@
1
+ /** The stored post fields this bootstrap reads to find or reserve the privacy Page. */
2
+ export interface PrivacyPageRow {
3
+ slug: string;
4
+ kind: string;
5
+ title: string;
6
+ status: string;
7
+ deletedAt?: unknown;
8
+ }
9
+ /** The host's new-Page input: one published Page owned by the seeded owner. */
10
+ export interface PrivacyPageCreateInput {
11
+ workspaceId: string;
12
+ id: string;
13
+ slug: string;
14
+ title: string;
15
+ kind: 'page';
16
+ status: 'published';
17
+ actorId: string;
18
+ }
19
+ /** Site-specific CMS bootstrap ports; persistence and identity remain with their existing owners. */
20
+ export interface PrivacyDefaultsDeps {
21
+ workspaceId: string;
22
+ post: {
23
+ repo: {
24
+ list(required: {
25
+ workspaceId: string;
26
+ }): Promise<PrivacyPageRow[]>;
27
+ transaction(required: {
28
+ fn: () => Promise<void>;
29
+ }): Promise<unknown>;
30
+ };
31
+ };
32
+ /** The host's post-creation use case, bound to its own post repository, clock, outbox and author owners. */
33
+ createPost(required: {
34
+ input: PrivacyPageCreateInput;
35
+ }, optional?: Record<string, never>): Promise<unknown>;
36
+ ids: {
37
+ newId(): string;
38
+ };
39
+ pagesHtmlStore(scope: {
40
+ workspaceId: string;
41
+ postId: string;
42
+ }): {
43
+ ensureHtmlFormat(required: {
44
+ seedHtml: string;
45
+ }, optional?: Record<string, never>): Promise<void>;
46
+ };
47
+ readUrl(): Promise<string>;
48
+ setUrl(input: {
49
+ url: string;
50
+ principalId: string;
51
+ }): Promise<void>;
52
+ readIdentity(): Promise<{
53
+ siteTitle: string;
54
+ email?: string;
55
+ principalId: string;
56
+ }>;
57
+ }
58
+ /** Ensure initial CMS policy content, preserving all owner choices and existing Page states.
59
+ * @param deps Workspace-scoped content, identity, and legacy settings ports.
60
+ * @returns Resolves when an empty legacy link has been filled; failures propagate for next-open retry.
61
+ * @complexity O(n) time/space for one workspace's stored rows; one create/seed transaction at most. */
62
+ export declare function ensureSitePrivacyDefaults(deps: PrivacyDefaultsDeps, _options?: {}): Promise<void>;
63
+ //# sourceMappingURL=ensure-privacy-defaults.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { deriveAvailableName } from '@jini-ai/core/naming';
2
+ import { privacyPageTemplate } from './privacy-page-template.js';
3
+ /** Trash reserves slugs too: createPost otherwise moves its holder aside. O(n) stored rows. */
4
+ async function availableSlug({ rows }) {
5
+ const taken = new Set(rows.map(row => row.slug));
6
+ if (!taken.has('privacy'))
7
+ return 'privacy';
8
+ return deriveAvailableName({ base: 'privacy-policy', isTaken: async ({ candidate }) => taken.has(candidate),
9
+ withSuffix: ({ base, suffix }) => `${base}-${suffix}`,
10
+ exhaustionMessage: () => 'No available Privacy Policy slug.' });
11
+ }
12
+ /** Ensure initial CMS policy content, preserving all owner choices and existing Page states.
13
+ * @param deps Workspace-scoped content, identity, and legacy settings ports.
14
+ * @returns Resolves when an empty legacy link has been filled; failures propagate for next-open retry.
15
+ * @complexity O(n) time/space for one workspace's stored rows; one create/seed transaction at most. */
16
+ export async function ensureSitePrivacyDefaults(deps, _options = {}) {
17
+ // The consent URL is the identity marker; an owner-set URL is never repaired or replaced.
18
+ if ((await deps.readUrl()).trim())
19
+ return;
20
+ const rows = await deps.post.repo.list({ workspaceId: deps.workspaceId });
21
+ const candidates = rows.filter(row => row.kind === 'page' &&
22
+ (row.slug === 'privacy' || row.slug === 'privacy-policy' || row.title === 'Privacy Policy'));
23
+ const live = candidates.filter(row => !row.deletedAt);
24
+ const existing = live.find(row => row.status === 'published') ?? live[0] ?? candidates[0];
25
+ const identity = await deps.readIdentity();
26
+ let slug = existing?.slug;
27
+ if (!existing) {
28
+ const created = await availableSlug({ rows });
29
+ slug = created;
30
+ const id = deps.ids.newId();
31
+ // Only new Pages enter ensureHtmlFormat; converting an existing Page would replace owner content.
32
+ await deps.post.repo.transaction({ fn: async () => {
33
+ await deps.createPost({ input: { workspaceId: deps.workspaceId, id, slug: created,
34
+ title: 'Privacy Policy', kind: 'page', status: 'published', actorId: identity.principalId } });
35
+ await deps.pagesHtmlStore({ workspaceId: deps.workspaceId, postId: id }).ensureHtmlFormat({ seedHtml: privacyPageTemplate(identity) });
36
+ } });
37
+ // Boot runs before createApp subscribes; the serving drainer delivers the go-live event.
38
+ }
39
+ // Re-read immediately before Jini's write chokepoint so a newly saved owner URL wins.
40
+ if ((await deps.readUrl()).trim())
41
+ return;
42
+ await deps.setUrl({ url: `/${slug}`, principalId: identity.principalId });
43
+ }
44
+ //# sourceMappingURL=ensure-privacy-defaults.js.map
@@ -0,0 +1,281 @@
1
+ import { type ReceiptPorts } from "../server/receipt.js";
2
+ import { resolveRegion } from "../server/region.js";
3
+ import type { DocumentState } from "./document-state.js";
4
+ import type { DeclaredScript, RegionResolver } from "@jini-ai/core/contracts/site/cookie-consent";
5
+ import type { ConsentAnalyticsProof, ConsentConfig, ConsentState } from '@jini-ai/core/contracts/site/cookie-consent';
6
+ import type { ConsentPluginContribution, ConsentPluginHttp } from '@jini-ai/core/contracts/headless/site-cookie-consent';
7
+ import { type ConsentRecord } from '../server/receipt.js';
8
+ /** The active plugin mounted over this path; none for a path with a dot segment or encoded separator. */
9
+ export declare function matchConsentPluginHttp({ plugins, full }: {
10
+ plugins: (required: Record<string, never>) => readonly ConsentPluginContribution[];
11
+ full: string;
12
+ }, _optional?: {}): (ConsentPluginContribution & {
13
+ http: ConsentPluginHttp;
14
+ }) | undefined;
15
+ /** Same-origin/category/rate decision plus the server-owned analytics level. Anonymous delivery needs
16
+ * an adapter declaring support. A category that is not optional (even 'necessary') is read as marketing,
17
+ * the strictest. @complexity O(cookie header) plus one policy read. */
18
+ export declare function collectorDecision({ origin, siteOrigin, adapter, readState, rateAllowed }: {
19
+ origin: string | undefined;
20
+ siteOrigin: (required: Record<string, never>) => string;
21
+ adapter: Readonly<Record<string, unknown>>;
22
+ readState: (required: Record<string, never>) => Promise<ConsentState>;
23
+ rateAllowed: (required: Record<string, never>) => Promise<boolean>;
24
+ }, _optional?: {}): Promise<{
25
+ status: 403 | 429 | null;
26
+ analyticsLevel: ConsentState['analyticsLevel'];
27
+ }>;
28
+ /** The server gate: what this visitor may run right now (GPC/DNT applied, durable rule: an
29
+ * unconfirmed grant is not allowed). A failed policy read allows nothing. @complexity O(cookie header). */
30
+ export declare function readVisitorConsent({ readSnapshot, snapshotUnavailable, readPolicy, facts }: {
31
+ readSnapshot: (required: Record<string, never>) => Promise<ConsentConfig | null>;
32
+ snapshotUnavailable: (required: {
33
+ config: ConsentConfig | null;
34
+ }) => boolean;
35
+ readPolicy: (required: Record<string, never>) => Promise<ConsentConfig>;
36
+ facts: (required: Record<string, never>) => {
37
+ cookieHeader: string | undefined;
38
+ secGpc?: string | null;
39
+ dnt?: string | null;
40
+ nowMs: number;
41
+ };
42
+ }, _optional?: {}): Promise<ConsentState>;
43
+ /** Detached delivery recheck, the old engine's rule: the receipt is still active (a later choice retires
44
+ * it), names the current policy, grants analytics without GPC and is within the choice lifetime. A forged
45
+ * or withdrawn receipt id never delivers. @complexity O(1): one policy read and one receipt read. */
46
+ export declare function receiptAllowsAnalytics({ proof, readSnapshot, snapshotUnavailable, readPolicyVersion, readReceipt, nowMs }: {
47
+ proof: ConsentAnalyticsProof;
48
+ readSnapshot: (required: Record<string, never>) => Promise<ConsentConfig | null>;
49
+ snapshotUnavailable: (required: {
50
+ config: ConsentConfig | null;
51
+ }) => boolean;
52
+ readPolicyVersion: (required: Record<string, never>) => Promise<string>;
53
+ readReceipt: (required: {
54
+ id: string;
55
+ }) => Promise<Partial<ConsentRecord> | null>;
56
+ nowMs: (required: Record<string, never>) => number;
57
+ }, _optional?: {}): Promise<boolean>;
58
+ /** The old engine's analytics proof shape (receipt id + policy), from the new cookie. Undefined unless
59
+ * analytics is allowed and a server receipt exists. @complexity O(cookie header). */
60
+ export declare function analyticsProof(required: {
61
+ state: ConsentState;
62
+ cookieHeader: string | undefined;
63
+ }, _optional?: {}): ConsentAnalyticsProof | undefined;
64
+ declare function loadClient(input: {
65
+ endpoint: string;
66
+ load: () => Uint8Array;
67
+ hash: (body: Uint8Array) => string;
68
+ diagnosticUnavailable: string;
69
+ formatError: (error: unknown) => string;
70
+ warn: (diagnostic: string) => void;
71
+ }, _optional?: {}): {
72
+ body: Uint8Array<ArrayBufferLike>;
73
+ src: string;
74
+ } | undefined;
75
+ type PluginHttpWriter = {
76
+ setHeader: (name: string, value: string) => void;
77
+ status: (code: number) => void;
78
+ end: (body?: string | Uint8Array) => void;
79
+ };
80
+ declare function mountPluginHttp({ pluginBase, facts, plugins, siteOrigin, readState, rateAllowed, writer, next }: {
81
+ pluginBase: string;
82
+ facts: {
83
+ method: string;
84
+ path: string;
85
+ body: Uint8Array;
86
+ contentType: string | undefined;
87
+ origin: string | undefined;
88
+ };
89
+ plugins: Parameters<typeof matchConsentPluginHttp>[0]['plugins'];
90
+ siteOrigin: () => string;
91
+ readState: () => Promise<ConsentState>;
92
+ rateAllowed: () => Promise<boolean>;
93
+ writer: PluginHttpWriter;
94
+ next: () => void;
95
+ }, _optional?: {}): Promise<void>;
96
+ declare function mountReceipts(input: {
97
+ readPolicy: () => Promise<ConsentConfig>;
98
+ request: () => Request;
99
+ store: ReceiptPorts['store'];
100
+ now: ReceiptPorts['now'];
101
+ ids: ReceiptPorts['ids'];
102
+ allow: () => Promise<boolean>;
103
+ write: (required: {
104
+ status: number;
105
+ headers: Record<string, string>;
106
+ body: string;
107
+ }) => void;
108
+ failure: {
109
+ report: (error: unknown) => {
110
+ errorId?: string;
111
+ };
112
+ diagnosticFailure: () => void;
113
+ write: (errorId: string | undefined) => void;
114
+ };
115
+ }, _optional?: {}): Promise<void>;
116
+ declare function mountContext(input: {
117
+ readPolicy: () => Promise<ConsentConfig | null>;
118
+ resolvers: () => Promise<readonly RegionResolver[]>;
119
+ request: Parameters<typeof resolveRegion>[0]['request'];
120
+ setRegionCookie: (hint: 'us' | 'strict') => void;
121
+ clearLegacyCookie: () => void;
122
+ setCache: (value: string) => void;
123
+ json: (body: unknown) => void;
124
+ failure: {
125
+ report: (error: unknown) => {
126
+ errorId?: string;
127
+ };
128
+ diagnosticFailure: () => void;
129
+ write: (errorId: string | undefined) => void;
130
+ };
131
+ unavailable: () => Error;
132
+ }, _optional?: {}): Promise<void>;
133
+ declare function mountStaticThemeLoader(input: {
134
+ readThemeId: (() => Promise<string>) | undefined;
135
+ resolveTheme: (required: {
136
+ activeThemeId: string;
137
+ }) => {
138
+ manifest: {
139
+ scripts?: readonly DeclaredScript[];
140
+ };
141
+ } | string | null;
142
+ noThemeId: string;
143
+ assets: (scripts: readonly DeclaredScript[]) => Promise<{
144
+ head: string;
145
+ body: string;
146
+ }>;
147
+ exporting: () => boolean;
148
+ write: (body: string) => void;
149
+ failure: {
150
+ report: (error: unknown) => {
151
+ errorId?: string;
152
+ };
153
+ diagnosticFailure: () => void;
154
+ write: (errorId: string | undefined) => void;
155
+ };
156
+ }, _optional?: {}): Promise<void>;
157
+ declare function applySiteCookieConsent(input: {
158
+ install: () => DocumentState;
159
+ mountReadiness: () => void;
160
+ mountClient: (client: NonNullable<DocumentState['client']>) => void;
161
+ loadExtension: () => Uint8Array;
162
+ mountExtension: (bytes: Uint8Array) => void;
163
+ extensionFailure: {
164
+ diagnosticUnavailable: string;
165
+ formatError: (error: unknown) => string;
166
+ warn: (diagnostic: string) => void;
167
+ };
168
+ mountStaticThemeLoader: () => void;
169
+ mountDiagnostics: () => void;
170
+ mountContext: () => void;
171
+ openReceiptStore: () => ReceiptPorts['store'];
172
+ createReceiptLimiter: () => {
173
+ check: (required: {
174
+ key: string;
175
+ }) => Promise<{
176
+ allowed: boolean;
177
+ }>;
178
+ };
179
+ createCollectorLimiter: () => {
180
+ check: (required: {
181
+ key: string;
182
+ }) => Promise<{
183
+ allowed: boolean;
184
+ }>;
185
+ };
186
+ receiptBodyLimit: string;
187
+ pluginBodyLimit: string;
188
+ mountReceipts: (required: {
189
+ store: ReceiptPorts['store'];
190
+ limiter: {
191
+ check: (required: {
192
+ key: string;
193
+ }) => Promise<{
194
+ allowed: boolean;
195
+ }>;
196
+ };
197
+ bodyLimit: string;
198
+ }) => void;
199
+ mountPluginHttp: (required: {
200
+ limiter: {
201
+ check: (required: {
202
+ key: string;
203
+ }) => Promise<{
204
+ allowed: boolean;
205
+ }>;
206
+ };
207
+ bodyLimit: string;
208
+ }) => void;
209
+ }, _optional?: {}): void;
210
+ export declare function createSiteConsentHttp(required: {
211
+ endpoint: string;
212
+ pluginBase: string;
213
+ regionCookieName: string;
214
+ legacyCookieName: string;
215
+ }, _optional?: {}): {
216
+ readVisitorConsent: typeof readVisitorConsent;
217
+ receiptAllowsAnalytics: typeof receiptAllowsAnalytics;
218
+ toWebRequest: typeof toWebRequest;
219
+ beforeRender: (input: {
220
+ readPolicy: () => Promise<ConsentConfig | null>;
221
+ attachAssets: () => void;
222
+ next: () => void;
223
+ }) => Promise<void>;
224
+ setRegionCookie: (input: Omit<Parameters<typeof setRegionCookie>[0], "name">) => void;
225
+ clearLegacyCookie: (input: Omit<Parameters<typeof clearLegacyCookie>[0], "name">) => void;
226
+ readAnalyticsProof: (input: {
227
+ readState: () => Promise<ConsentState>;
228
+ cookieHeader: () => string | undefined;
229
+ }) => Promise<ConsentAnalyticsProof | undefined>;
230
+ loadClient: (input: Omit<Parameters<typeof loadClient>[0], "endpoint">) => {
231
+ body: Uint8Array<ArrayBufferLike>;
232
+ src: string;
233
+ } | undefined;
234
+ pluginHttp: (input: Omit<Parameters<typeof mountPluginHttp>[0], "pluginBase">) => Promise<void>;
235
+ diagnostics: (input: {
236
+ enabled: () => Promise<boolean>;
237
+ setCache: (cache: string) => void;
238
+ missing: () => void;
239
+ send: () => void;
240
+ }) => Promise<void>;
241
+ receipts: typeof mountReceipts;
242
+ context: typeof mountContext;
243
+ staticThemeLoader: typeof mountStaticThemeLoader;
244
+ applySiteCookieConsent: typeof applySiteCookieConsent;
245
+ };
246
+ declare function toWebRequest(required: {
247
+ header: (name: string) => string | undefined;
248
+ originalUrl: string;
249
+ origin: string;
250
+ method: string;
251
+ body: Uint8Array;
252
+ }, _optional?: {}): Request;
253
+ /** Region persistence is only reached for an enabled consent banner, never anonymous analytics. */
254
+ declare function setRegionCookie(required: {
255
+ name: string;
256
+ cookieHeader: string | undefined;
257
+ secure: boolean;
258
+ origin: string;
259
+ hint: 'us' | 'strict';
260
+ cookie: (name: string, value: string, options: {
261
+ path: string;
262
+ sameSite: 'lax';
263
+ secure: boolean;
264
+ maxAge: number;
265
+ }) => void;
266
+ clearCookie: (name: string, options: {
267
+ path: string;
268
+ }) => void;
269
+ }, _optional?: {}): void;
270
+ /** Only this engine retires the old host-only HttpOnly cookie; its receipt id proves no new categories. */
271
+ declare function clearLegacyCookie(required: {
272
+ name: string;
273
+ cookieHeader: string | undefined;
274
+ clearCookie: (name: string, options: {
275
+ path: string;
276
+ httpOnly: true;
277
+ sameSite: 'lax';
278
+ }) => void;
279
+ }, _optional?: {}): void;
280
+ export {};
281
+ //# sourceMappingURL=http.d.ts.map