@cookiemunch/sdk 0.14.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +6 -0
- package/dist/embed.cjs +62 -0
- package/dist/embed.cjs.map +1 -0
- package/dist/embed.d.ts +88 -0
- package/dist/embed.js +34 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.cjs +9 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +35 -2
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/rights.cjs +105 -5
- package/dist/rights.cjs.map +1 -1
- package/dist/rights.d.ts +53 -4
- package/dist/rights.js +89 -4
- package/dist/rights.js.map +1 -1
- package/dist/types.d.ts +14 -0
- package/package.json +10 -11
- package/LICENSE +0 -21
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Every published release, newest first. Dates are the day the version was cut.
|
|
4
4
|
|
|
5
|
+
## 0.15.0 (2026-11-03)
|
|
6
|
+
|
|
7
|
+
- Added: `fileStore(dir)`, `sqlStore({ query })` with `RIGHTS_STORE_TABLE_SQL`, and `redisStore(client)` in `@cookiemunch/sdk/rights`.
|
|
8
|
+
- Added: `RightsStore.set(key, value, { ttlSeconds })` and an optional `RightsStore.delete(key)`; backward compatible.
|
|
9
|
+
- Changed: Idempotency-Key answers in `createRightsHandlers` expire after 24 hours (`IDEMPOTENCY_TTL_SECONDS`), whatever the store.
|
|
10
|
+
|
|
5
11
|
## 0.14.2 (2026-11-02)
|
|
6
12
|
|
|
7
13
|
- Added: `planCookies` accepts `presets.custom` (the body of `presets.applyCustom`).
|
package/README.md
CHANGED
|
@@ -81,5 +81,11 @@ export const { GET, POST } = createRightsHandlers({
|
|
|
81
81
|
lookup: ({ emails, identity }) => findUserId(emails, identity),
|
|
82
82
|
access: async (r) => ({ status: 'completed', result: await exportUser(r.subjectId) }),
|
|
83
83
|
erase: async (r) => { await deleteUser(r.subjectId); },
|
|
84
|
+
store: fileStore('/var/lib/myapp/rights'), // import it too; or sqlStore({ query }) / redisStore(client)
|
|
84
85
|
});
|
|
85
86
|
```
|
|
87
|
+
|
|
88
|
+
The default store is in memory. A scheduled erasure has no timer in your process: `erase` runs on
|
|
89
|
+
Cookie Munch's next poll after `executeAfter` (every 10 minutes), so production needs a durable
|
|
90
|
+
`store`: `fileStore(dir)`, `sqlStore({ query })` (table: `RIGHTS_STORE_TABLE_SQL`) or
|
|
91
|
+
`redisStore(client)`.
|
package/dist/embed.cjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/embed.ts
|
|
21
|
+
var embed_exports = {};
|
|
22
|
+
__export(embed_exports, {
|
|
23
|
+
consentState: () => consentState,
|
|
24
|
+
getCookieMunch: () => getCookieMunch,
|
|
25
|
+
hasConsent: () => hasConsent,
|
|
26
|
+
onConsent: () => onConsent
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(embed_exports);
|
|
29
|
+
function getCookieMunch() {
|
|
30
|
+
return typeof window === "undefined" ? void 0 : window.CookieMunch;
|
|
31
|
+
}
|
|
32
|
+
function consentState(category) {
|
|
33
|
+
return getCookieMunch()?.consentState?.(category) ?? null;
|
|
34
|
+
}
|
|
35
|
+
function hasConsent(category) {
|
|
36
|
+
return getCookieMunch()?.hasConsent?.(category) ?? false;
|
|
37
|
+
}
|
|
38
|
+
function onConsent(category, callback) {
|
|
39
|
+
if (typeof window === "undefined") return () => {
|
|
40
|
+
};
|
|
41
|
+
const w = window;
|
|
42
|
+
const cm = w.CookieMunch;
|
|
43
|
+
if (typeof cm?.onConsent === "function") return cm.onConsent(category, callback);
|
|
44
|
+
if (cm && !cm.__q) return () => {
|
|
45
|
+
};
|
|
46
|
+
const q = cm?.__q ?? (w.CookieMunch = { __q: [] }).__q;
|
|
47
|
+
const entry = ["onConsent", [category, callback]];
|
|
48
|
+
q.push(entry);
|
|
49
|
+
return () => {
|
|
50
|
+
const at = q.indexOf(entry);
|
|
51
|
+
if (at >= 0) q.splice(at, 1);
|
|
52
|
+
else if (typeof entry[2] === "function") entry[2]();
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
consentState,
|
|
58
|
+
getCookieMunch,
|
|
59
|
+
hasConsent,
|
|
60
|
+
onConsent
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=embed.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/embed.ts"],"sourcesContent":["/**\n * `@cookiemunch/sdk/embed` — typed, framework-free access to the browser embed's `window.CookieMunch`.\n *\n * import { onConsent, consentState } from '@cookiemunch/sdk/embed';\n * onConsent('statistics', () => loadAnalytics());\n *\n * Every helper is safe to call during server-side rendering (no window: `null`, `false` or a no-op)\n * and before the embed has loaded: `onConsent` joins the embed's own early queue (`__q`), which the\n * embed replays when it starts. On a path out of the site's `scope` the embed never starts, so a\n * queued callback never runs.\n *\n * The types mirror `packages/react/src/types.ts` (a test pins the two equal); this module adds no\n * `Window` augmentation, so it can sit next to `@cookiemunch/react` in one project.\n */\n\n/** The four base consent categories. */\nexport type Category = 'necessary' | 'preferences' | 'statistics' | 'marketing';\n\n/**\n * The visitor's consent snapshot, mirroring what the embed exposes at\n * `window.CookieMunch.consent`. Includes the four base categories, the granular\n * advertising signals, and a receipt `stamp`. Custom category keys may also be\n * present, hence the index signature.\n */\nexport interface PublicConsent {\n necessary: boolean;\n preferences: boolean;\n statistics: boolean;\n marketing: boolean;\n /** Granular advertising signals (IAB TCF purposes), else fall back to `marketing`. */\n personalizedAds: boolean;\n basicAds: boolean;\n adProfiling: boolean;\n adMeasurement: boolean;\n /** The current consent-receipt stamp. */\n stamp: string;\n /** Custom category keys are included when the site defines them. */\n [key: string]: boolean | string;\n}\n\n/**\n * The minimal shape of the global `window.CookieMunch` API this wrapper relies\n * on. The real embed exposes a superset of this (Cookiebot-compatible facade);\n * we only type the members we call.\n */\n/**\n * Empty until you augment it with your site's category ids (`cookiemunch types` writes the augmentation):\n *\n * declare module '@cookiemunch/sdk/embed' { interface CookieMunchCategories { necessary: true; statistics: true } }\n */\nexport interface CookieMunchCategories {}\n\n/** A category id: one of CookieMunchCategories' keys once augmented, any string until then. */\nexport type CategoryId = [keyof CookieMunchCategories] extends [never] ? string : Extract<keyof CookieMunchCategories, string>;\n\nexport interface CookieMunchGlobal {\n readonly consent: PublicConsent;\n readonly consented: boolean;\n readonly hasResponse: boolean;\n /** The site id, including one resolved from the page host (`data-cbid=\"auto\"`); undefined until known. */\n cbid?: string;\n show(): void;\n renew(): void;\n /** Open the preference center / second layer. */\n showSettings(): void;\n withdraw(): void;\n submitCustomConsent(preferences: boolean, statistics: boolean, marketing: boolean): void;\n /** Subscribe to consent changes (accept/decline). Returns an unsubscribe fn. */\n onConsentChange(callback: (state: unknown) => void): () => void;\n /**\n * Whether `category` (a site category id or an alias such as `functional`) is consented.\n * An unknown category answers false. Optional: older embeds lack it.\n */\n hasConsent?(category: CategoryId): boolean;\n /** `true` granted, `false` refused (or unknown name), `null` not decided yet. Optional: older embeds lack it. */\n consentState?(category: CategoryId): boolean | null;\n /** Call `callback` once when `category` is granted (a microtask later if it already is). Returns an unsubscribe. Optional: older embeds lack it. */\n onConsent?(category: CategoryId, callback: () => void): () => void;\n /** Draw the cookie declaration into `el` (all mounts when omitted). Optional: older embeds lack it. */\n renderDeclaration?(el?: Element | null): Promise<void>;\n}\n\ntype QueueEntry = [string, unknown[], unknown?];\ntype Slot = { CookieMunch?: Partial<CookieMunchGlobal> & { __q?: QueueEntry[] } };\n\n/** `window.CookieMunch`, or undefined during SSR or before the embed (or its stub) exists. */\nexport function getCookieMunch(): CookieMunchGlobal | undefined {\n return typeof window === 'undefined' ? undefined : ((window as unknown as Slot).CookieMunch as CookieMunchGlobal | undefined);\n}\n\n/** `true` granted, `false` refused, `null` not decided yet — or no embed (SSR, not loaded). */\nexport function consentState(category: CategoryId): boolean | null {\n return getCookieMunch()?.consentState?.(category) ?? null;\n}\n\n/** Whether `category` is consented. False whenever it cannot be known yet. */\nexport function hasConsent(category: CategoryId): boolean {\n return getCookieMunch()?.hasConsent?.(category) ?? false;\n}\n\n/**\n * Run `callback` once `category` is granted. Before the embed loads the call is queued for it,\n * exactly as its own early stub would. Returns an unsubscribe; a no-op during SSR.\n */\nexport function onConsent(category: CategoryId, callback: () => void): () => void {\n if (typeof window === 'undefined') return () => {};\n const w = window as unknown as Slot;\n const cm = w.CookieMunch;\n if (typeof cm?.onConsent === 'function') return cm.onConsent(category, callback);\n // An embed too old to have onConsent: nothing to queue for.\n if (cm && !cm.__q) return () => {};\n // No embed yet (or only the queue this created): the embed adopts an existing `__q` and replays it.\n const q = cm?.__q ?? (w.CookieMunch = { __q: [] }).__q!;\n const entry: QueueEntry = ['onConsent', [category, callback]];\n q.push(entry);\n return () => {\n const at = q.indexOf(entry);\n if (at >= 0) q.splice(at, 1);\n else if (typeof entry[2] === 'function') (entry[2] as () => void)();\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsFO,SAAS,iBAAgD;AAC9D,SAAO,OAAO,WAAW,cAAc,SAAc,OAA2B;AAClF;AAGO,SAAS,aAAa,UAAsC;AACjE,SAAO,eAAe,GAAG,eAAe,QAAQ,KAAK;AACvD;AAGO,SAAS,WAAW,UAA+B;AACxD,SAAO,eAAe,GAAG,aAAa,QAAQ,KAAK;AACrD;AAMO,SAAS,UAAU,UAAsB,UAAkC;AAChF,MAAI,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AACjD,QAAM,IAAI;AACV,QAAM,KAAK,EAAE;AACb,MAAI,OAAO,IAAI,cAAc,WAAY,QAAO,GAAG,UAAU,UAAU,QAAQ;AAE/E,MAAI,MAAM,CAAC,GAAG,IAAK,QAAO,MAAM;AAAA,EAAC;AAEjC,QAAM,IAAI,IAAI,QAAQ,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,GAAG;AACnD,QAAM,QAAoB,CAAC,aAAa,CAAC,UAAU,QAAQ,CAAC;AAC5D,IAAE,KAAK,KAAK;AACZ,SAAO,MAAM;AACX,UAAM,KAAK,EAAE,QAAQ,KAAK;AAC1B,QAAI,MAAM,EAAG,GAAE,OAAO,IAAI,CAAC;AAAA,aAClB,OAAO,MAAM,CAAC,MAAM,WAAY,CAAC,MAAM,CAAC,EAAiB;AAAA,EACpE;AACF;","names":[]}
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@cookiemunch/sdk/embed` — typed, framework-free access to the browser embed's `window.CookieMunch`.
|
|
3
|
+
*
|
|
4
|
+
* import { onConsent, consentState } from '@cookiemunch/sdk/embed';
|
|
5
|
+
* onConsent('statistics', () => loadAnalytics());
|
|
6
|
+
*
|
|
7
|
+
* Every helper is safe to call during server-side rendering (no window: `null`, `false` or a no-op)
|
|
8
|
+
* and before the embed has loaded: `onConsent` joins the embed's own early queue (`__q`), which the
|
|
9
|
+
* embed replays when it starts. On a path out of the site's `scope` the embed never starts, so a
|
|
10
|
+
* queued callback never runs.
|
|
11
|
+
*
|
|
12
|
+
* The types mirror `packages/react/src/types.ts` (a test pins the two equal); this module adds no
|
|
13
|
+
* `Window` augmentation, so it can sit next to `@cookiemunch/react` in one project.
|
|
14
|
+
*/
|
|
15
|
+
/** The four base consent categories. */
|
|
16
|
+
export type Category = 'necessary' | 'preferences' | 'statistics' | 'marketing';
|
|
17
|
+
/**
|
|
18
|
+
* The visitor's consent snapshot, mirroring what the embed exposes at
|
|
19
|
+
* `window.CookieMunch.consent`. Includes the four base categories, the granular
|
|
20
|
+
* advertising signals, and a receipt `stamp`. Custom category keys may also be
|
|
21
|
+
* present, hence the index signature.
|
|
22
|
+
*/
|
|
23
|
+
export interface PublicConsent {
|
|
24
|
+
necessary: boolean;
|
|
25
|
+
preferences: boolean;
|
|
26
|
+
statistics: boolean;
|
|
27
|
+
marketing: boolean;
|
|
28
|
+
/** Granular advertising signals (IAB TCF purposes), else fall back to `marketing`. */
|
|
29
|
+
personalizedAds: boolean;
|
|
30
|
+
basicAds: boolean;
|
|
31
|
+
adProfiling: boolean;
|
|
32
|
+
adMeasurement: boolean;
|
|
33
|
+
/** The current consent-receipt stamp. */
|
|
34
|
+
stamp: string;
|
|
35
|
+
/** Custom category keys are included when the site defines them. */
|
|
36
|
+
[key: string]: boolean | string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The minimal shape of the global `window.CookieMunch` API this wrapper relies
|
|
40
|
+
* on. The real embed exposes a superset of this (Cookiebot-compatible facade);
|
|
41
|
+
* we only type the members we call.
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* Empty until you augment it with your site's category ids (`cookiemunch types` writes the augmentation):
|
|
45
|
+
*
|
|
46
|
+
* declare module '@cookiemunch/sdk/embed' { interface CookieMunchCategories { necessary: true; statistics: true } }
|
|
47
|
+
*/
|
|
48
|
+
export interface CookieMunchCategories {
|
|
49
|
+
}
|
|
50
|
+
/** A category id: one of CookieMunchCategories' keys once augmented, any string until then. */
|
|
51
|
+
export type CategoryId = [keyof CookieMunchCategories] extends [never] ? string : Extract<keyof CookieMunchCategories, string>;
|
|
52
|
+
export interface CookieMunchGlobal {
|
|
53
|
+
readonly consent: PublicConsent;
|
|
54
|
+
readonly consented: boolean;
|
|
55
|
+
readonly hasResponse: boolean;
|
|
56
|
+
/** The site id, including one resolved from the page host (`data-cbid="auto"`); undefined until known. */
|
|
57
|
+
cbid?: string;
|
|
58
|
+
show(): void;
|
|
59
|
+
renew(): void;
|
|
60
|
+
/** Open the preference center / second layer. */
|
|
61
|
+
showSettings(): void;
|
|
62
|
+
withdraw(): void;
|
|
63
|
+
submitCustomConsent(preferences: boolean, statistics: boolean, marketing: boolean): void;
|
|
64
|
+
/** Subscribe to consent changes (accept/decline). Returns an unsubscribe fn. */
|
|
65
|
+
onConsentChange(callback: (state: unknown) => void): () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Whether `category` (a site category id or an alias such as `functional`) is consented.
|
|
68
|
+
* An unknown category answers false. Optional: older embeds lack it.
|
|
69
|
+
*/
|
|
70
|
+
hasConsent?(category: CategoryId): boolean;
|
|
71
|
+
/** `true` granted, `false` refused (or unknown name), `null` not decided yet. Optional: older embeds lack it. */
|
|
72
|
+
consentState?(category: CategoryId): boolean | null;
|
|
73
|
+
/** Call `callback` once when `category` is granted (a microtask later if it already is). Returns an unsubscribe. Optional: older embeds lack it. */
|
|
74
|
+
onConsent?(category: CategoryId, callback: () => void): () => void;
|
|
75
|
+
/** Draw the cookie declaration into `el` (all mounts when omitted). Optional: older embeds lack it. */
|
|
76
|
+
renderDeclaration?(el?: Element | null): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/** `window.CookieMunch`, or undefined during SSR or before the embed (or its stub) exists. */
|
|
79
|
+
export declare function getCookieMunch(): CookieMunchGlobal | undefined;
|
|
80
|
+
/** `true` granted, `false` refused, `null` not decided yet — or no embed (SSR, not loaded). */
|
|
81
|
+
export declare function consentState(category: CategoryId): boolean | null;
|
|
82
|
+
/** Whether `category` is consented. False whenever it cannot be known yet. */
|
|
83
|
+
export declare function hasConsent(category: CategoryId): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Run `callback` once `category` is granted. Before the embed loads the call is queued for it,
|
|
86
|
+
* exactly as its own early stub would. Returns an unsubscribe; a no-op during SSR.
|
|
87
|
+
*/
|
|
88
|
+
export declare function onConsent(category: CategoryId, callback: () => void): () => void;
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/embed.ts
|
|
2
|
+
function getCookieMunch() {
|
|
3
|
+
return typeof window === "undefined" ? void 0 : window.CookieMunch;
|
|
4
|
+
}
|
|
5
|
+
function consentState(category) {
|
|
6
|
+
return getCookieMunch()?.consentState?.(category) ?? null;
|
|
7
|
+
}
|
|
8
|
+
function hasConsent(category) {
|
|
9
|
+
return getCookieMunch()?.hasConsent?.(category) ?? false;
|
|
10
|
+
}
|
|
11
|
+
function onConsent(category, callback) {
|
|
12
|
+
if (typeof window === "undefined") return () => {
|
|
13
|
+
};
|
|
14
|
+
const w = window;
|
|
15
|
+
const cm = w.CookieMunch;
|
|
16
|
+
if (typeof cm?.onConsent === "function") return cm.onConsent(category, callback);
|
|
17
|
+
if (cm && !cm.__q) return () => {
|
|
18
|
+
};
|
|
19
|
+
const q = cm?.__q ?? (w.CookieMunch = { __q: [] }).__q;
|
|
20
|
+
const entry = ["onConsent", [category, callback]];
|
|
21
|
+
q.push(entry);
|
|
22
|
+
return () => {
|
|
23
|
+
const at = q.indexOf(entry);
|
|
24
|
+
if (at >= 0) q.splice(at, 1);
|
|
25
|
+
else if (typeof entry[2] === "function") entry[2]();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
consentState,
|
|
30
|
+
getCookieMunch,
|
|
31
|
+
hasConsent,
|
|
32
|
+
onConsent
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/embed.ts"],"sourcesContent":["/**\n * `@cookiemunch/sdk/embed` — typed, framework-free access to the browser embed's `window.CookieMunch`.\n *\n * import { onConsent, consentState } from '@cookiemunch/sdk/embed';\n * onConsent('statistics', () => loadAnalytics());\n *\n * Every helper is safe to call during server-side rendering (no window: `null`, `false` or a no-op)\n * and before the embed has loaded: `onConsent` joins the embed's own early queue (`__q`), which the\n * embed replays when it starts. On a path out of the site's `scope` the embed never starts, so a\n * queued callback never runs.\n *\n * The types mirror `packages/react/src/types.ts` (a test pins the two equal); this module adds no\n * `Window` augmentation, so it can sit next to `@cookiemunch/react` in one project.\n */\n\n/** The four base consent categories. */\nexport type Category = 'necessary' | 'preferences' | 'statistics' | 'marketing';\n\n/**\n * The visitor's consent snapshot, mirroring what the embed exposes at\n * `window.CookieMunch.consent`. Includes the four base categories, the granular\n * advertising signals, and a receipt `stamp`. Custom category keys may also be\n * present, hence the index signature.\n */\nexport interface PublicConsent {\n necessary: boolean;\n preferences: boolean;\n statistics: boolean;\n marketing: boolean;\n /** Granular advertising signals (IAB TCF purposes), else fall back to `marketing`. */\n personalizedAds: boolean;\n basicAds: boolean;\n adProfiling: boolean;\n adMeasurement: boolean;\n /** The current consent-receipt stamp. */\n stamp: string;\n /** Custom category keys are included when the site defines them. */\n [key: string]: boolean | string;\n}\n\n/**\n * The minimal shape of the global `window.CookieMunch` API this wrapper relies\n * on. The real embed exposes a superset of this (Cookiebot-compatible facade);\n * we only type the members we call.\n */\n/**\n * Empty until you augment it with your site's category ids (`cookiemunch types` writes the augmentation):\n *\n * declare module '@cookiemunch/sdk/embed' { interface CookieMunchCategories { necessary: true; statistics: true } }\n */\nexport interface CookieMunchCategories {}\n\n/** A category id: one of CookieMunchCategories' keys once augmented, any string until then. */\nexport type CategoryId = [keyof CookieMunchCategories] extends [never] ? string : Extract<keyof CookieMunchCategories, string>;\n\nexport interface CookieMunchGlobal {\n readonly consent: PublicConsent;\n readonly consented: boolean;\n readonly hasResponse: boolean;\n /** The site id, including one resolved from the page host (`data-cbid=\"auto\"`); undefined until known. */\n cbid?: string;\n show(): void;\n renew(): void;\n /** Open the preference center / second layer. */\n showSettings(): void;\n withdraw(): void;\n submitCustomConsent(preferences: boolean, statistics: boolean, marketing: boolean): void;\n /** Subscribe to consent changes (accept/decline). Returns an unsubscribe fn. */\n onConsentChange(callback: (state: unknown) => void): () => void;\n /**\n * Whether `category` (a site category id or an alias such as `functional`) is consented.\n * An unknown category answers false. Optional: older embeds lack it.\n */\n hasConsent?(category: CategoryId): boolean;\n /** `true` granted, `false` refused (or unknown name), `null` not decided yet. Optional: older embeds lack it. */\n consentState?(category: CategoryId): boolean | null;\n /** Call `callback` once when `category` is granted (a microtask later if it already is). Returns an unsubscribe. Optional: older embeds lack it. */\n onConsent?(category: CategoryId, callback: () => void): () => void;\n /** Draw the cookie declaration into `el` (all mounts when omitted). Optional: older embeds lack it. */\n renderDeclaration?(el?: Element | null): Promise<void>;\n}\n\ntype QueueEntry = [string, unknown[], unknown?];\ntype Slot = { CookieMunch?: Partial<CookieMunchGlobal> & { __q?: QueueEntry[] } };\n\n/** `window.CookieMunch`, or undefined during SSR or before the embed (or its stub) exists. */\nexport function getCookieMunch(): CookieMunchGlobal | undefined {\n return typeof window === 'undefined' ? undefined : ((window as unknown as Slot).CookieMunch as CookieMunchGlobal | undefined);\n}\n\n/** `true` granted, `false` refused, `null` not decided yet — or no embed (SSR, not loaded). */\nexport function consentState(category: CategoryId): boolean | null {\n return getCookieMunch()?.consentState?.(category) ?? null;\n}\n\n/** Whether `category` is consented. False whenever it cannot be known yet. */\nexport function hasConsent(category: CategoryId): boolean {\n return getCookieMunch()?.hasConsent?.(category) ?? false;\n}\n\n/**\n * Run `callback` once `category` is granted. Before the embed loads the call is queued for it,\n * exactly as its own early stub would. Returns an unsubscribe; a no-op during SSR.\n */\nexport function onConsent(category: CategoryId, callback: () => void): () => void {\n if (typeof window === 'undefined') return () => {};\n const w = window as unknown as Slot;\n const cm = w.CookieMunch;\n if (typeof cm?.onConsent === 'function') return cm.onConsent(category, callback);\n // An embed too old to have onConsent: nothing to queue for.\n if (cm && !cm.__q) return () => {};\n // No embed yet (or only the queue this created): the embed adopts an existing `__q` and replays it.\n const q = cm?.__q ?? (w.CookieMunch = { __q: [] }).__q!;\n const entry: QueueEntry = ['onConsent', [category, callback]];\n q.push(entry);\n return () => {\n const at = q.indexOf(entry);\n if (at >= 0) q.splice(at, 1);\n else if (typeof entry[2] === 'function') (entry[2] as () => void)();\n };\n}\n"],"mappings":";AAsFO,SAAS,iBAAgD;AAC9D,SAAO,OAAO,WAAW,cAAc,SAAc,OAA2B;AAClF;AAGO,SAAS,aAAa,UAAsC;AACjE,SAAO,eAAe,GAAG,eAAe,QAAQ,KAAK;AACvD;AAGO,SAAS,WAAW,UAA+B;AACxD,SAAO,eAAe,GAAG,aAAa,QAAQ,KAAK;AACrD;AAMO,SAAS,UAAU,UAAsB,UAAkC;AAChF,MAAI,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AACjD,QAAM,IAAI;AACV,QAAM,KAAK,EAAE;AACb,MAAI,OAAO,IAAI,cAAc,WAAY,QAAO,GAAG,UAAU,UAAU,QAAQ;AAE/E,MAAI,MAAM,CAAC,GAAG,IAAK,QAAO,MAAM;AAAA,EAAC;AAEjC,QAAM,IAAI,IAAI,QAAQ,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,GAAG;AACnD,QAAM,QAAoB,CAAC,aAAa,CAAC,UAAU,QAAQ,CAAC;AAC5D,IAAE,KAAK,KAAK;AACZ,SAAO,MAAM;AACX,UAAM,KAAK,EAAE,QAAQ,KAAK;AAC1B,QAAI,MAAM,EAAG,GAAE,OAAO,IAAI,CAAC;AAAA,aAClB,OAAO,MAAM,CAAC,MAAM,WAAY,CAAC,MAAM,CAAC,EAAiB;AAAA,EACpE;AACF;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -465,7 +465,7 @@ async function exchangeOperatorToken(input) {
|
|
|
465
465
|
}
|
|
466
466
|
|
|
467
467
|
// src/index.ts
|
|
468
|
-
var SDK_VERSION = "0.
|
|
468
|
+
var SDK_VERSION = "0.15.0";
|
|
469
469
|
var CookieMunchApiError = class extends Error {
|
|
470
470
|
constructor(status, message, code, body) {
|
|
471
471
|
super(message);
|
|
@@ -480,6 +480,12 @@ function metaQs(o) {
|
|
|
480
480
|
const parts = Object.entries(o?.metadata ?? {}).map(([k, v]) => `metadata%5B${encodeURIComponent(k)}%5D=${encodeURIComponent(v)}`);
|
|
481
481
|
return parts.length ? `?${parts.join("&")}` : "";
|
|
482
482
|
}
|
|
483
|
+
function unwrapList(version, body) {
|
|
484
|
+
if (!version || version < "2026-11-03" || !body || typeof body !== "object" || Array.isArray(body)) return body;
|
|
485
|
+
const o = body;
|
|
486
|
+
const keys = Object.keys(o);
|
|
487
|
+
return Array.isArray(o.data) && keys.every((k) => k === "data" || k === "next") ? o.data : body;
|
|
488
|
+
}
|
|
483
489
|
function qs(query) {
|
|
484
490
|
if (!query) return "";
|
|
485
491
|
const parts = [];
|
|
@@ -523,7 +529,7 @@ function createCookieMunch(opts) {
|
|
|
523
529
|
if (res.status === 204) return void 0;
|
|
524
530
|
if (raw) return res.text();
|
|
525
531
|
const contentType = res.headers.get("content-type") ?? "";
|
|
526
|
-
return contentType.includes("application/json") ? res.json() : res.text();
|
|
532
|
+
return contentType.includes("application/json") ? unwrapList(res.headers.get("cookiemunch-version"), await res.json()) : res.text();
|
|
527
533
|
}
|
|
528
534
|
const get = (p) => request("GET", p);
|
|
529
535
|
async function requestBytes(path) {
|
|
@@ -599,7 +605,7 @@ function createCookieMunch(opts) {
|
|
|
599
605
|
ab: (cbid) => get(`/sites/${enc(cbid)}/ab`),
|
|
600
606
|
policy: (cbid, o) => request(
|
|
601
607
|
"GET",
|
|
602
|
-
`/sites/${enc(cbid)}/policy${qs({ contactEmail: o?.contactEmail, effectiveDate: o?.effectiveDate, jurisdictions: o?.jurisdictions?.join(",") })}`,
|
|
608
|
+
`/sites/${enc(cbid)}/policy${qs({ contactEmail: o?.contactEmail, effectiveDate: o?.effectiveDate, jurisdictions: o?.jurisdictions?.join(","), fragment: o?.fragment, format: o?.format, lang: o?.lang })}`,
|
|
603
609
|
void 0,
|
|
604
610
|
true
|
|
605
611
|
),
|