@monterosa/sdk-consent-kit 2.0.0-rc.1 → 2.0.0-rc.2

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/api.d.ts CHANGED
@@ -17,7 +17,7 @@ import { ConsentState, ConsentKit, ConsentHook } from './types';
17
17
  */
18
18
  export declare function getConsent(): ConsentKit;
19
19
  /**
20
- * Register a hook that will be called when consent is initialized.
20
+ * Register a hook that will be called when consent is initialised.
21
21
  *
22
22
  * @param hook - The hook function to register.
23
23
  *
package/dist/bridge.d.ts CHANGED
@@ -30,7 +30,7 @@ export declare function handleExperienceEmbedded(experience: Experience): void;
30
30
  export declare function handleExperienceUnmounted(experience: Experience): void;
31
31
  /**
32
32
  * Hook to listen for consent messages from parent application.
33
- * This is called when consent-kit is initialized in a child experience.
33
+ * This is called when consent-kit is initialised in a child Experience.
34
34
  *
35
35
  * @param consent - The consent kit instance
36
36
  * @returns Unsubscribe function
package/dist/index.d.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  /**
2
- * @license
3
- * @monterosa/sdk-consent-kit
2
+ * Manages user consent state between the parent page and embedded Experiences.
4
3
  *
5
- * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
6
- *
7
- * More details on the license can be found at https://www.monterosa.co/sdk/license
4
+ * @packageDocumentation
8
5
  */
9
6
  export { setConsentState, getConsentState, hasConsent, onConsentChanged, } from './api';
10
7
  export { DefaultCategory, ConsentState, ConsentError } from './types';
@@ -175,7 +175,7 @@ function getConsent() {
175
175
  return consent;
176
176
  }
177
177
  /**
178
- * Register a hook that will be called when consent is initialized.
178
+ * Register a hook that will be called when consent is initialised.
179
179
  *
180
180
  * @param hook - The hook function to register.
181
181
  *
@@ -354,7 +354,7 @@ function handleExperienceUnmounted(experience) {
354
354
  }
355
355
  /**
356
356
  * Hook to listen for consent messages from parent application.
357
- * This is called when consent-kit is initialized in a child experience.
357
+ * This is called when consent-kit is initialised in a child Experience.
358
358
  *
359
359
  * @param consent - The consent kit instance
360
360
  * @returns Unsubscribe function
@@ -376,12 +376,9 @@ function parentMessagesHook(consent) {
376
376
  }
377
377
 
378
378
  /**
379
- * @license
380
- * @monterosa/sdk-consent-kit
379
+ * Manages user consent state between the parent page and embedded Experiences.
381
380
  *
382
- * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
383
- *
384
- * More details on the license can be found at https://www.monterosa.co/sdk/license
381
+ * @packageDocumentation
385
382
  */
386
383
  // Register bridge handlers for parent-child communication
387
384
  onStateChanged((experience, state) => {
@@ -396,4 +393,4 @@ onStateChanged((experience, state) => {
396
393
  registerConsentHook(parentMessagesHook);
397
394
 
398
395
  export { ConsentError, getConsentState, hasConsent, onConsentChanged, setConsentState };
399
- //# sourceMappingURL=index.esm.js.map
396
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/types.ts","../src/consent.ts","../src/api.ts","../src/bridge.ts","../src/index.ts"],"sourcesContent":["/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * Default consent categories commonly used for GDPR/privacy compliance.\n *\n * @remarks\n * - `necessary` - Essential cookies/tracking required for the site to function\n * - `analytics` - Analytics and performance tracking\n * - `marketing` - Marketing and advertising tracking\n * - `functional` - User preference and personalization tracking\n */\nexport type DefaultCategory =\n | 'necessary'\n | 'analytics'\n | 'marketing'\n | 'functional';\n\n/**\n * Represents the consent state for each category.\n * Maps category names to boolean values indicating whether consent is granted.\n *\n * @typeParam T - The type of category keys, defaults to DefaultCategory\n *\n * @example\n * ```typescript\n * const state: ConsentState = {\n * necessary: true,\n * analytics: false,\n * marketing: false,\n * preferences: true,\n * };\n * ```\n */\nexport type ConsentState<T extends string = DefaultCategory> = {\n [K in T]?: boolean;\n};\n\n/**\n * Actions used for parent-child bridge communication.\n *\n * @internal\n */\nexport enum ConsentAction {\n /**\n * Sent when consent state is updated.\n */\n OnConsentUpdated = 'consentOnConsentUpdated',\n /**\n * Request to set consent state from child to parent.\n */\n SetConsent = 'consentSetConsent',\n}\n\n/**\n * Internal event names for the consent emitter.\n *\n * @internal\n */\nexport enum ConsentEvent {\n /**\n * Emitted when consent state changes.\n */\n ConsentChanged = 'consent_changed',\n}\n\n/**\n * Defines error codes that may be encountered when using the Consent kit.\n *\n * @example\n * ```typescript\n * try {\n * setConsentState({ necessary: false });\n * } catch (err) {\n * if (err.code === ConsentError.NecessaryCategoryRequired) {\n * // handle necessary category error\n * }\n * }\n * ```\n */\nexport enum ConsentError {\n /**\n * Indicates that the 'necessary' category cannot be set to false.\n */\n NecessaryCategoryRequired = 'necessary_category_required',\n /**\n * Indicates that consent cannot be set from a child experience.\n */\n CannotSetFromChild = 'cannot_set_from_child',\n}\n\n/**\n * Error messages for consent errors.\n *\n * @internal\n */\nexport const ConsentErrorMessages = {\n [ConsentError.NecessaryCategoryRequired]: () =>\n \"Cannot set 'necessary' category to false. Strictly necessary functionality cannot be disabled.\",\n [ConsentError.CannotSetFromChild]: () =>\n 'Cannot set consent state from embedded experience. Consent is managed by the parent application.',\n};\n\n/**\n * Hook function type for registering consent hooks.\n *\n * @internal\n */\nexport type ConsentHook = (consent: ConsentKit) => Unsubscribe;\n\n/**\n * The ConsentKit interface provides properties and methods\n * for managing user consent state.\n *\n * @internal\n */\nexport interface ConsentKit extends Emitter {\n /**\n * Whether consent mode is active.\n * Returns true when state has been set.\n */\n readonly isActive: boolean;\n /**\n * The current consent state.\n */\n state: ConsentState | null;\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Emitter } from '@monterosa/sdk-util';\n\nimport { ConsentKit, ConsentState, ConsentEvent } from './types';\n\n/**\n * Internal Consent class that manages consent state.\n *\n * @internal\n */\nexport class Consent extends Emitter implements ConsentKit {\n private static instance: Consent;\n\n private _state: ConsentState | null = null;\n\n /**\n * The current consent state.\n * Setting this value will automatically emit ConsentChanged event if the state\n * actually changed.\n */\n get state(): ConsentState | null {\n return this._state;\n }\n\n set state(value: ConsentState | null) {\n const previousState = this._state;\n this._state = value;\n\n // Only emit if state changed to a non-null value\n if (value !== null && !Consent.isConsentStateEqual(previousState, value)) {\n this.emit(ConsentEvent.ConsentChanged, value);\n }\n }\n\n /**\n * Whether consent mode is active.\n * Returns true when state has been set.\n */\n get isActive(): boolean {\n return this._state !== null;\n }\n\n private constructor() {\n super();\n }\n\n /**\n * Compare two consent states for equality.\n *\n * @param a - First consent state (or null)\n * @param b - Second consent state (or null)\n * @returns Whether the states are equal\n */\n private static isConsentStateEqual<T extends string = string>(\n a: ConsentState<T> | null,\n b: ConsentState<T> | null,\n ): boolean {\n if (a === null && b === null) return true;\n if (a === null || b === null) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n const aRecord = a as Record<string, boolean | undefined>;\n const bRecord = b as Record<string, boolean | undefined>;\n\n return keysA.every((key) => aRecord[key] === bRecord[key]);\n }\n\n /**\n * Get the singleton instance of the Consent class.\n *\n * @returns The Consent singleton instance.\n */\n public static getInstance(): Consent {\n if (!Consent.instance) {\n Consent.instance = new Consent();\n }\n\n return Consent.instance;\n }\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe, MonterosaError } from '@monterosa/sdk-util';\nimport { getParentApplication } from '@monterosa/sdk-launcher-kit';\n\nimport {\n ConsentState,\n ConsentKit,\n ConsentEvent,\n ConsentError,\n ConsentErrorMessages,\n ConsentHook,\n} from './types';\n\nimport { Consent } from './consent';\n\nconst consentHooks: ConsentHook[] = [];\nlet hooksRegistered = false;\n\n/**\n * Get the consent kit instance.\n *\n * @returns The consent kit instance.\n *\n * @internal\n */\nexport function getConsent(): ConsentKit {\n const consent = Consent.getInstance();\n\n if (!hooksRegistered) {\n // Register hooks only once\n for (const hook of consentHooks) {\n hook(consent);\n }\n\n hooksRegistered = true;\n }\n\n return consent;\n}\n\n/**\n * Register a hook that will be called when consent is initialised.\n *\n * @param hook - The hook function to register.\n *\n * @internal\n */\nexport function registerConsentHook(hook: ConsentHook): void {\n consentHooks.push(hook);\n}\n\n/**\n * Set the consent state.\n *\n * @remarks\n * - The 'necessary' category cannot be set to false\n * - Cannot be called from a child experience (use parent application instead)\n *\n * @example\n * ```typescript\n * setConsentState({\n * necessary: true,\n * analytics: true,\n * marketing: false,\n * functional: true,\n * });\n * ```\n *\n * @param state - The consent state to set\n * @throws {MonterosaError} If called from a child experience\n * @throws {MonterosaError} If 'necessary' category is set to false\n */\nexport function setConsentState<T extends string = string>(\n state: ConsentState<T>,\n): void {\n const parentApp = getParentApplication();\n\n // Cannot set consent from a child experience\n if (parentApp !== null) {\n throw new MonterosaError(\n ConsentError.CannotSetFromChild,\n ConsentErrorMessages[ConsentError.CannotSetFromChild](),\n );\n }\n\n // Necessary category cannot be false\n if ('necessary' in state && state.necessary === false) {\n throw new MonterosaError(\n ConsentError.NecessaryCategoryRequired,\n ConsentErrorMessages[ConsentError.NecessaryCategoryRequired](),\n );\n }\n\n const consent = getConsent();\n consent.state = state;\n}\n\n/**\n * Get the current consent state.\n *\n * @example\n * ```typescript\n * const state = getConsentState();\n * if (state.analytics) {\n * // Analytics consent granted\n * }\n * ```\n *\n * @returns The current consent state, or empty object if consent mode not active\n */\nexport function getConsentState<T extends string = string>(): ConsentState<T> {\n return (getConsent().state ?? {}) as ConsentState<T>;\n}\n\n/**\n * Check if consent is granted for a specific category.\n *\n * @remarks\n * - The 'necessary' category always returns true\n * - Returns true if consent mode is not active (backwards compatibility)\n * - Returns false for missing keys when consent mode is active (GDPR strict opt-in)\n * - Returns the boolean value if the category exists in consent state\n *\n * @example\n * ```typescript\n * if (hasConsent('analytics')) {\n * // Track analytics event\n * }\n * ```\n *\n * @param category - The consent category to check\n * @returns Whether consent is granted for the category\n */\nexport function hasConsent(category: string): boolean {\n // 'necessary' always returns true\n if (category === 'necessary') {\n return true;\n }\n\n const consent = getConsent();\n\n // If consent mode not active, allow everything (backwards compatibility)\n if (!consent.isActive) {\n return true;\n }\n\n // GDPR strict opt-in: missing keys default to false\n return (\n (consent.state as Record<string, boolean | undefined>)?.[category] === true\n );\n}\n\n/**\n * Subscribe to consent state changes.\n *\n * @example\n * ```typescript\n * const unsubscribe = onConsentChanged((state) => {\n * console.log('Consent changed:', state);\n * });\n *\n * // Later, to stop listening:\n * unsubscribe();\n * ```\n *\n * @param callback - The callback to call when consent state changes\n * @returns A function to unsubscribe from the event\n */\nexport function onConsentChanged<T extends string = string>(\n callback: (state: ConsentState<T>) => void,\n): Unsubscribe {\n const consent = getConsent();\n\n return consent.on(ConsentEvent.ConsentChanged, callback);\n}\n\n/**\n * Update consent state from parent (used internally by bridge).\n *\n * @param state - The consent state received from parent\n *\n * @internal\n */\nexport function updateConsentFromParent<T extends string = string>(\n state: ConsentState<T>,\n): void {\n const consent = getConsent();\n consent.state = state;\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe } from '@monterosa/sdk-util';\nimport {\n Experience,\n Message,\n getParentApplication,\n onSdkMessage,\n sendSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport { ConsentKit, ConsentState, ConsentAction } from './types';\n\nimport { getConsent, onConsentChanged, updateConsentFromParent } from './api';\n\nconst experienceUnsubs = new Map<string, Unsubscribe[]>();\n\n/**\n * Handle when an experience is embedded.\n * Sends current consent state to the child (queued by the bridge until\n * the experience is initialised) and subscribes to consent changes.\n *\n * @param experience - The embedded experience\n *\n * @internal\n */\nexport function handleExperienceEmbedded(experience: Experience): void {\n const consent = getConsent();\n\n // Send current consent state if active.\n // The bridge queues this message until the experience is initialised.\n if (consent.isActive) {\n sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {\n state: consent.state,\n });\n }\n\n // Subscribe to consent changes and push to child\n const consentChangedUnsub = onConsentChanged((state) => {\n sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {\n state,\n });\n });\n\n experienceUnsubs.set(experience.id, [consentChangedUnsub]);\n}\n\n/**\n * Handle when an experience is unmounted.\n * Cleans up subscriptions for the experience.\n *\n * @param experience - The unmounted experience\n *\n * @internal\n */\nexport function handleExperienceUnmounted(experience: Experience): void {\n const unsubs = experienceUnsubs.get(experience.id);\n\n if (unsubs) {\n for (const unsub of unsubs) {\n unsub();\n }\n\n experienceUnsubs.delete(experience.id);\n }\n}\n\n/**\n * Hook to listen for consent messages from parent application.\n * This is called when consent-kit is initialised in a child Experience.\n *\n * @param consent - The consent kit instance\n * @returns Unsubscribe function\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function parentMessagesHook(consent: ConsentKit): Unsubscribe {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, (message: Message) => {\n if (message.action === ConsentAction.OnConsentUpdated) {\n const { state } = message.payload as { state: ConsentState };\n\n updateConsentFromParent(state);\n }\n });\n}\n","/**\n * Manages user consent state between the parent page and embedded Experiences.\n *\n * @packageDocumentation\n */\n\n/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { onStateChanged } from '@monterosa/sdk-launcher-kit';\n\nimport {\n handleExperienceEmbedded,\n handleExperienceUnmounted,\n parentMessagesHook,\n} from './bridge';\n\nimport { registerConsentHook } from './api';\n\n// Register bridge handlers for parent-child communication\nonStateChanged((experience, state) => {\n if (state === 'mounted') {\n handleExperienceEmbedded(experience);\n } else if (state === 'unmounted') {\n handleExperienceUnmounted(experience);\n }\n});\n\n// Register hook for child experiences to receive consent from parent\nregisterConsentHook(parentMessagesHook);\n\n// Public API exports\nexport {\n setConsentState,\n getConsentState,\n hasConsent,\n onConsentChanged,\n} from './api';\n\n// Type exports\nexport { DefaultCategory, ConsentState, ConsentError } from './types';\n"],"names":[],"mappings":";;;AAAA;;;;;;;AAOG;AAuCH;;;;AAIG;AACH,IAAY,aASX,CAAA;AATD,CAAA,UAAY,aAAa,EAAA;AACvB;;AAEG;AACH,IAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,yBAA4C,CAAA;AAC5C;;AAEG;AACH,IAAA,aAAA,CAAA,YAAA,CAAA,GAAA,mBAAgC,CAAA;AAClC,CAAC,EATW,aAAa,KAAb,aAAa,GASxB,EAAA,CAAA,CAAA,CAAA;AAED;;;;AAIG;AACH,IAAY,YAKX,CAAA;AALD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;AACH,IAAA,YAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AACpC,CAAC,EALW,YAAY,KAAZ,YAAY,GAKvB,EAAA,CAAA,CAAA,CAAA;AAED;;;;;;;;;;;;;AAaG;IACS,aASX;AATD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;AACH,IAAA,YAAA,CAAA,2BAAA,CAAA,GAAA,6BAAyD,CAAA;AACzD;;AAEG;AACH,IAAA,YAAA,CAAA,oBAAA,CAAA,GAAA,uBAA4C,CAAA;AAC9C,CAAC,EATW,YAAY,KAAZ,YAAY,GASvB,EAAA,CAAA,CAAA,CAAA;AAED;;;;AAIG;AACI,MAAM,oBAAoB,GAAG;IAClC,CAAC,YAAY,CAAC,yBAAyB,GAAG,MACxC,gGAAgG;IAClG,CAAC,YAAY,CAAC,kBAAkB,GAAG,MACjC,kGAAkG;CACrG;;AC7GD;;;;;;;AAOG;AAMH;;;;AAIG;AACG,MAAO,O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O,YAAY,CAAC,SAAS,EAAE,CAAC,OAAgB,KAAI;AAClD,QAAA,IAAI,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,gBAAgB,EAAE;AACrD,YAAA,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAkC,CAAC;YAE7D,uBAAuB,CAAC,KAAK,CAAC,CAAC;AAChC,SAAA;AACH,KAAC,CAAC,CAAC;AACL;;AClGA;;;;AAIG;AAqBH;AACA,cAAc,CAAC,CAAC,UAAU,EAAE,KAAK,KAAI;IACnC,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,wBAAwB,CAAC,UAAU,CAAC,CAAC;AACtC,KAAA;SAAM,IAAI,KAAK,KAAK,WAAW,EAAE;QAChC,yBAAyB,CAAC,UAAU,CAAC,CAAC;AACvC,KAAA;AACH,CAAC,CAAC,CAAC;AAEH;AACA,mBAAmB,CAAC,kBAAkB,CAAC;;;;"}
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@monterosa/sdk-consent-kit",
3
- "version": "2.0.0-rc.1",
3
+ "version": "2.0.0-rc.2",
4
4
  "description": "Consent Kit for the Monterosa JS SDK",
5
5
  "author": "Monterosa Productions Limited <hello@monterosa.co.uk> (https://www.monterosa.co/)",
6
- "main": "dist/index.cjs.js",
7
- "browser": "dist/index.esm.js",
8
- "module": "dist/index.esm.js",
6
+ "main": "./dist/index.js",
9
7
  "types": "./dist/index.d.ts",
10
- "cdn": "../../dist",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
11
15
  "files": [
12
16
  "dist"
13
17
  ],
@@ -19,19 +23,19 @@
19
23
  "test:ci": "jest --color --ci --reporters=jest-junit --coverage",
20
24
  "api-report": "api-extractor run --local --verbose"
21
25
  },
22
- "keywords": [],
26
+ "keywords": [
27
+ "monterosa",
28
+ "sdk",
29
+ "interaction-cloud",
30
+ "consent"
31
+ ],
23
32
  "license": "MIT",
24
- "peerDependencies": {
25
- "@monterosa/sdk-launcher-kit": "0.x",
26
- "@monterosa/sdk-util": "0.x"
27
- },
28
33
  "dependencies": {
29
- "@monterosa/sdk-launcher-kit": "^2.0.0-rc.1",
30
- "@monterosa/sdk-util": "^2.0.0-rc.1"
34
+ "@monterosa/sdk-launcher-kit": "2.0.0-rc.2",
35
+ "@monterosa/sdk-util": "2.0.0-rc.2"
31
36
  },
32
37
  "devDependencies": {
33
38
  "@faker-js/faker": "^6.3.1",
34
- "@rollup/plugin-commonjs": "^21.1.0",
35
39
  "@rollup/plugin-json": "^4.1.0",
36
40
  "@rollup/plugin-node-resolve": "^13.3.0",
37
41
  "@rollup/plugin-terser": "^0.4.4",
@@ -48,5 +52,5 @@
48
52
  "publishConfig": {
49
53
  "access": "public"
50
54
  },
51
- "gitHead": "7cb580eebfab4fb87632a96519dac2f9762fc8b2"
55
+ "gitHead": "0e2d4cd71055bf0ab38ec5a73d6040c55151da1c"
52
56
  }
package/dist/index.cjs.js DELETED
@@ -1,460 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var sdkLauncherKit = require('@monterosa/sdk-launcher-kit');
6
- var sdkUtil = require('@monterosa/sdk-util');
7
-
8
- /**
9
- * @license
10
- * @monterosa/sdk-consent-kit
11
- *
12
- * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
13
- *
14
- * More details on the license can be found at https://www.monterosa.co/sdk/license
15
- */
16
- var _a;
17
- /**
18
- * Actions used for parent-child bridge communication.
19
- *
20
- * @internal
21
- */
22
- var ConsentAction;
23
- (function (ConsentAction) {
24
- /**
25
- * Sent when consent state is updated.
26
- */
27
- ConsentAction["OnConsentUpdated"] = "consentOnConsentUpdated";
28
- /**
29
- * Request to set consent state from child to parent.
30
- */
31
- ConsentAction["SetConsent"] = "consentSetConsent";
32
- })(ConsentAction || (ConsentAction = {}));
33
- /**
34
- * Internal event names for the consent emitter.
35
- *
36
- * @internal
37
- */
38
- var ConsentEvent;
39
- (function (ConsentEvent) {
40
- /**
41
- * Emitted when consent state changes.
42
- */
43
- ConsentEvent["ConsentChanged"] = "consent_changed";
44
- })(ConsentEvent || (ConsentEvent = {}));
45
- /**
46
- * Defines error codes that may be encountered when using the Consent kit.
47
- *
48
- * @example
49
- * ```typescript
50
- * try {
51
- * setConsentState({ necessary: false });
52
- * } catch (err) {
53
- * if (err.code === ConsentError.NecessaryCategoryRequired) {
54
- * // handle necessary category error
55
- * }
56
- * }
57
- * ```
58
- */
59
- exports.ConsentError = void 0;
60
- (function (ConsentError) {
61
- /**
62
- * Indicates that the 'necessary' category cannot be set to false.
63
- */
64
- ConsentError["NecessaryCategoryRequired"] = "necessary_category_required";
65
- /**
66
- * Indicates that consent cannot be set from a child experience.
67
- */
68
- ConsentError["CannotSetFromChild"] = "cannot_set_from_child";
69
- })(exports.ConsentError || (exports.ConsentError = {}));
70
- /**
71
- * Error messages for consent errors.
72
- *
73
- * @internal
74
- */
75
- var ConsentErrorMessages = (_a = {},
76
- _a[exports.ConsentError.NecessaryCategoryRequired] = function () {
77
- return "Cannot set 'necessary' category to false. Strictly necessary functionality cannot be disabled.";
78
- },
79
- _a[exports.ConsentError.CannotSetFromChild] = function () {
80
- return 'Cannot set consent state from embedded experience. Consent is managed by the parent application.';
81
- },
82
- _a);
83
-
84
- /******************************************************************************
85
- Copyright (c) Microsoft Corporation.
86
-
87
- Permission to use, copy, modify, and/or distribute this software for any
88
- purpose with or without fee is hereby granted.
89
-
90
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
91
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
92
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
93
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
94
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
95
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
96
- PERFORMANCE OF THIS SOFTWARE.
97
- ***************************************************************************** */
98
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
99
-
100
- var extendStatics = function(d, b) {
101
- extendStatics = Object.setPrototypeOf ||
102
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
103
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
104
- return extendStatics(d, b);
105
- };
106
-
107
- function __extends(d, b) {
108
- if (typeof b !== "function" && b !== null)
109
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
110
- extendStatics(d, b);
111
- function __() { this.constructor = d; }
112
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
113
- }
114
-
115
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
116
- var e = new Error(message);
117
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
118
- };
119
-
120
- /**
121
- * @license
122
- * @monterosa/sdk-consent-kit
123
- *
124
- * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
125
- *
126
- * More details on the license can be found at https://www.monterosa.co/sdk/license
127
- */
128
- /**
129
- * Internal Consent class that manages consent state.
130
- *
131
- * @internal
132
- */
133
- var Consent = /** @class */ (function (_super) {
134
- __extends(Consent, _super);
135
- function Consent() {
136
- var _this = _super.call(this) || this;
137
- _this._state = null;
138
- return _this;
139
- }
140
- Object.defineProperty(Consent.prototype, "state", {
141
- /**
142
- * The current consent state.
143
- * Setting this value will automatically emit ConsentChanged event if the state
144
- * actually changed.
145
- */
146
- get: function () {
147
- return this._state;
148
- },
149
- set: function (value) {
150
- var previousState = this._state;
151
- this._state = value;
152
- // Only emit if state changed to a non-null value
153
- if (value !== null && !Consent.isConsentStateEqual(previousState, value)) {
154
- this.emit(ConsentEvent.ConsentChanged, value);
155
- }
156
- },
157
- enumerable: false,
158
- configurable: true
159
- });
160
- Object.defineProperty(Consent.prototype, "isActive", {
161
- /**
162
- * Whether consent mode is active.
163
- * Returns true when state has been set.
164
- */
165
- get: function () {
166
- return this._state !== null;
167
- },
168
- enumerable: false,
169
- configurable: true
170
- });
171
- /**
172
- * Compare two consent states for equality.
173
- *
174
- * @param a - First consent state (or null)
175
- * @param b - Second consent state (or null)
176
- * @returns Whether the states are equal
177
- */
178
- Consent.isConsentStateEqual = function (a, b) {
179
- if (a === null && b === null)
180
- return true;
181
- if (a === null || b === null)
182
- return false;
183
- var keysA = Object.keys(a);
184
- var keysB = Object.keys(b);
185
- if (keysA.length !== keysB.length)
186
- return false;
187
- var aRecord = a;
188
- var bRecord = b;
189
- return keysA.every(function (key) { return aRecord[key] === bRecord[key]; });
190
- };
191
- /**
192
- * Get the singleton instance of the Consent class.
193
- *
194
- * @returns The Consent singleton instance.
195
- */
196
- Consent.getInstance = function () {
197
- if (!Consent.instance) {
198
- Consent.instance = new Consent();
199
- }
200
- return Consent.instance;
201
- };
202
- return Consent;
203
- }(sdkUtil.Emitter));
204
-
205
- /**
206
- * @license
207
- * @monterosa/sdk-consent-kit
208
- *
209
- * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
210
- *
211
- * More details on the license can be found at https://www.monterosa.co/sdk/license
212
- */
213
- var consentHooks = [];
214
- var hooksRegistered = false;
215
- /**
216
- * Get the consent kit instance.
217
- *
218
- * @returns The consent kit instance.
219
- *
220
- * @internal
221
- */
222
- function getConsent() {
223
- var consent = Consent.getInstance();
224
- if (!hooksRegistered) {
225
- // Register hooks only once
226
- for (var _i = 0, consentHooks_1 = consentHooks; _i < consentHooks_1.length; _i++) {
227
- var hook = consentHooks_1[_i];
228
- hook(consent);
229
- }
230
- hooksRegistered = true;
231
- }
232
- return consent;
233
- }
234
- /**
235
- * Register a hook that will be called when consent is initialized.
236
- *
237
- * @param hook - The hook function to register.
238
- *
239
- * @internal
240
- */
241
- function registerConsentHook(hook) {
242
- consentHooks.push(hook);
243
- }
244
- /**
245
- * Set the consent state.
246
- *
247
- * @remarks
248
- * - The 'necessary' category cannot be set to false
249
- * - Cannot be called from a child experience (use parent application instead)
250
- *
251
- * @example
252
- * ```typescript
253
- * setConsentState({
254
- * necessary: true,
255
- * analytics: true,
256
- * marketing: false,
257
- * functional: true,
258
- * });
259
- * ```
260
- *
261
- * @param state - The consent state to set
262
- * @throws {MonterosaError} If called from a child experience
263
- * @throws {MonterosaError} If 'necessary' category is set to false
264
- */
265
- function setConsentState(state) {
266
- var parentApp = sdkLauncherKit.getParentApplication();
267
- // Cannot set consent from a child experience
268
- if (parentApp !== null) {
269
- throw new sdkUtil.MonterosaError(exports.ConsentError.CannotSetFromChild, ConsentErrorMessages[exports.ConsentError.CannotSetFromChild]());
270
- }
271
- // Necessary category cannot be false
272
- if ('necessary' in state && state.necessary === false) {
273
- throw new sdkUtil.MonterosaError(exports.ConsentError.NecessaryCategoryRequired, ConsentErrorMessages[exports.ConsentError.NecessaryCategoryRequired]());
274
- }
275
- var consent = getConsent();
276
- consent.state = state;
277
- }
278
- /**
279
- * Get the current consent state.
280
- *
281
- * @example
282
- * ```typescript
283
- * const state = getConsentState();
284
- * if (state.analytics) {
285
- * // Analytics consent granted
286
- * }
287
- * ```
288
- *
289
- * @returns The current consent state, or empty object if consent mode not active
290
- */
291
- function getConsentState() {
292
- var _a;
293
- return ((_a = getConsent().state) !== null && _a !== void 0 ? _a : {});
294
- }
295
- /**
296
- * Check if consent is granted for a specific category.
297
- *
298
- * @remarks
299
- * - The 'necessary' category always returns true
300
- * - Returns true if consent mode is not active (backwards compatibility)
301
- * - Returns false for missing keys when consent mode is active (GDPR strict opt-in)
302
- * - Returns the boolean value if the category exists in consent state
303
- *
304
- * @example
305
- * ```typescript
306
- * if (hasConsent('analytics')) {
307
- * // Track analytics event
308
- * }
309
- * ```
310
- *
311
- * @param category - The consent category to check
312
- * @returns Whether consent is granted for the category
313
- */
314
- function hasConsent(category) {
315
- var _a;
316
- // 'necessary' always returns true
317
- if (category === 'necessary') {
318
- return true;
319
- }
320
- var consent = getConsent();
321
- // If consent mode not active, allow everything (backwards compatibility)
322
- if (!consent.isActive) {
323
- return true;
324
- }
325
- // GDPR strict opt-in: missing keys default to false
326
- return (((_a = consent.state) === null || _a === void 0 ? void 0 : _a[category]) === true);
327
- }
328
- /**
329
- * Subscribe to consent state changes.
330
- *
331
- * @example
332
- * ```typescript
333
- * const unsubscribe = onConsentChanged((state) => {
334
- * console.log('Consent changed:', state);
335
- * });
336
- *
337
- * // Later, to stop listening:
338
- * unsubscribe();
339
- * ```
340
- *
341
- * @param callback - The callback to call when consent state changes
342
- * @returns A function to unsubscribe from the event
343
- */
344
- function onConsentChanged(callback) {
345
- var consent = getConsent();
346
- return consent.on(ConsentEvent.ConsentChanged, callback);
347
- }
348
- /**
349
- * Update consent state from parent (used internally by bridge).
350
- *
351
- * @param state - The consent state received from parent
352
- *
353
- * @internal
354
- */
355
- function updateConsentFromParent(state) {
356
- var consent = getConsent();
357
- consent.state = state;
358
- }
359
-
360
- /**
361
- * @license
362
- * @monterosa/sdk-consent-kit
363
- *
364
- * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
365
- *
366
- * More details on the license can be found at https://www.monterosa.co/sdk/license
367
- */
368
- var experienceUnsubs = new Map();
369
- /**
370
- * Handle when an experience is embedded.
371
- * Sends current consent state to the child (queued by the bridge until
372
- * the experience is initialised) and subscribes to consent changes.
373
- *
374
- * @param experience - The embedded experience
375
- *
376
- * @internal
377
- */
378
- function handleExperienceEmbedded(experience) {
379
- var consent = getConsent();
380
- // Send current consent state if active.
381
- // The bridge queues this message until the experience is initialised.
382
- if (consent.isActive) {
383
- sdkLauncherKit.sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {
384
- state: consent.state,
385
- });
386
- }
387
- // Subscribe to consent changes and push to child
388
- var consentChangedUnsub = onConsentChanged(function (state) {
389
- sdkLauncherKit.sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {
390
- state: state,
391
- });
392
- });
393
- experienceUnsubs.set(experience.id, [consentChangedUnsub]);
394
- }
395
- /**
396
- * Handle when an experience is unmounted.
397
- * Cleans up subscriptions for the experience.
398
- *
399
- * @param experience - The unmounted experience
400
- *
401
- * @internal
402
- */
403
- function handleExperienceUnmounted(experience) {
404
- var unsubs = experienceUnsubs.get(experience.id);
405
- if (unsubs) {
406
- for (var _i = 0, unsubs_1 = unsubs; _i < unsubs_1.length; _i++) {
407
- var unsub = unsubs_1[_i];
408
- unsub();
409
- }
410
- experienceUnsubs.delete(experience.id);
411
- }
412
- }
413
- /**
414
- * Hook to listen for consent messages from parent application.
415
- * This is called when consent-kit is initialized in a child experience.
416
- *
417
- * @param consent - The consent kit instance
418
- * @returns Unsubscribe function
419
- *
420
- * @internal
421
- */
422
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
423
- function parentMessagesHook(consent) {
424
- var parentApp = sdkLauncherKit.getParentApplication();
425
- if (parentApp === null) {
426
- return function () { };
427
- }
428
- return sdkLauncherKit.onSdkMessage(parentApp, function (message) {
429
- if (message.action === ConsentAction.OnConsentUpdated) {
430
- var state = message.payload.state;
431
- updateConsentFromParent(state);
432
- }
433
- });
434
- }
435
-
436
- /**
437
- * @license
438
- * @monterosa/sdk-consent-kit
439
- *
440
- * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
441
- *
442
- * More details on the license can be found at https://www.monterosa.co/sdk/license
443
- */
444
- // Register bridge handlers for parent-child communication
445
- sdkLauncherKit.onStateChanged(function (experience, state) {
446
- if (state === 'mounted') {
447
- handleExperienceEmbedded(experience);
448
- }
449
- else if (state === 'unmounted') {
450
- handleExperienceUnmounted(experience);
451
- }
452
- });
453
- // Register hook for child experiences to receive consent from parent
454
- registerConsentHook(parentMessagesHook);
455
-
456
- exports.getConsentState = getConsentState;
457
- exports.hasConsent = hasConsent;
458
- exports.onConsentChanged = onConsentChanged;
459
- exports.setConsentState = setConsentState;
460
- //# sourceMappingURL=index.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/consent.ts","../src/api.ts","../src/bridge.ts","../src/index.ts"],"sourcesContent":["/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * Default consent categories commonly used for GDPR/privacy compliance.\n *\n * @remarks\n * - `necessary` - Essential cookies/tracking required for the site to function\n * - `analytics` - Analytics and performance tracking\n * - `marketing` - Marketing and advertising tracking\n * - `functional` - User preference and personalization tracking\n */\nexport type DefaultCategory =\n | 'necessary'\n | 'analytics'\n | 'marketing'\n | 'functional';\n\n/**\n * Represents the consent state for each category.\n * Maps category names to boolean values indicating whether consent is granted.\n *\n * @typeParam T - The type of category keys, defaults to DefaultCategory\n *\n * @example\n * ```typescript\n * const state: ConsentState = {\n * necessary: true,\n * analytics: false,\n * marketing: false,\n * preferences: true,\n * };\n * ```\n */\nexport type ConsentState<T extends string = DefaultCategory> = {\n [K in T]?: boolean;\n};\n\n/**\n * Actions used for parent-child bridge communication.\n *\n * @internal\n */\nexport enum ConsentAction {\n /**\n * Sent when consent state is updated.\n */\n OnConsentUpdated = 'consentOnConsentUpdated',\n /**\n * Request to set consent state from child to parent.\n */\n SetConsent = 'consentSetConsent',\n}\n\n/**\n * Internal event names for the consent emitter.\n *\n * @internal\n */\nexport enum ConsentEvent {\n /**\n * Emitted when consent state changes.\n */\n ConsentChanged = 'consent_changed',\n}\n\n/**\n * Defines error codes that may be encountered when using the Consent kit.\n *\n * @example\n * ```typescript\n * try {\n * setConsentState({ necessary: false });\n * } catch (err) {\n * if (err.code === ConsentError.NecessaryCategoryRequired) {\n * // handle necessary category error\n * }\n * }\n * ```\n */\nexport enum ConsentError {\n /**\n * Indicates that the 'necessary' category cannot be set to false.\n */\n NecessaryCategoryRequired = 'necessary_category_required',\n /**\n * Indicates that consent cannot be set from a child experience.\n */\n CannotSetFromChild = 'cannot_set_from_child',\n}\n\n/**\n * Error messages for consent errors.\n *\n * @internal\n */\nexport const ConsentErrorMessages = {\n [ConsentError.NecessaryCategoryRequired]: () =>\n \"Cannot set 'necessary' category to false. Strictly necessary functionality cannot be disabled.\",\n [ConsentError.CannotSetFromChild]: () =>\n 'Cannot set consent state from embedded experience. Consent is managed by the parent application.',\n};\n\n/**\n * Hook function type for registering consent hooks.\n *\n * @internal\n */\nexport type ConsentHook = (consent: ConsentKit) => Unsubscribe;\n\n/**\n * The ConsentKit interface provides properties and methods\n * for managing user consent state.\n *\n * @internal\n */\nexport interface ConsentKit extends Emitter {\n /**\n * Whether consent mode is active.\n * Returns true when state has been set.\n */\n readonly isActive: boolean;\n /**\n * The current consent state.\n */\n state: ConsentState | null;\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Emitter } from '@monterosa/sdk-util';\n\nimport { ConsentKit, ConsentState, ConsentEvent } from './types';\n\n/**\n * Internal Consent class that manages consent state.\n *\n * @internal\n */\nexport class Consent extends Emitter implements ConsentKit {\n private static instance: Consent;\n\n private _state: ConsentState | null = null;\n\n /**\n * The current consent state.\n * Setting this value will automatically emit ConsentChanged event if the state\n * actually changed.\n */\n get state(): ConsentState | null {\n return this._state;\n }\n\n set state(value: ConsentState | null) {\n const previousState = this._state;\n this._state = value;\n\n // Only emit if state changed to a non-null value\n if (value !== null && !Consent.isConsentStateEqual(previousState, value)) {\n this.emit(ConsentEvent.ConsentChanged, value);\n }\n }\n\n /**\n * Whether consent mode is active.\n * Returns true when state has been set.\n */\n get isActive(): boolean {\n return this._state !== null;\n }\n\n private constructor() {\n super();\n }\n\n /**\n * Compare two consent states for equality.\n *\n * @param a - First consent state (or null)\n * @param b - Second consent state (or null)\n * @returns Whether the states are equal\n */\n private static isConsentStateEqual<T extends string = string>(\n a: ConsentState<T> | null,\n b: ConsentState<T> | null,\n ): boolean {\n if (a === null && b === null) return true;\n if (a === null || b === null) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n const aRecord = a as Record<string, boolean | undefined>;\n const bRecord = b as Record<string, boolean | undefined>;\n\n return keysA.every((key) => aRecord[key] === bRecord[key]);\n }\n\n /**\n * Get the singleton instance of the Consent class.\n *\n * @returns The Consent singleton instance.\n */\n public static getInstance(): Consent {\n if (!Consent.instance) {\n Consent.instance = new Consent();\n }\n\n return Consent.instance;\n }\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe, MonterosaError } from '@monterosa/sdk-util';\nimport { getParentApplication } from '@monterosa/sdk-launcher-kit';\n\nimport {\n ConsentState,\n ConsentKit,\n ConsentEvent,\n ConsentError,\n ConsentErrorMessages,\n ConsentHook,\n} from './types';\n\nimport { Consent } from './consent';\n\nconst consentHooks: ConsentHook[] = [];\nlet hooksRegistered = false;\n\n/**\n * Get the consent kit instance.\n *\n * @returns The consent kit instance.\n *\n * @internal\n */\nexport function getConsent(): ConsentKit {\n const consent = Consent.getInstance();\n\n if (!hooksRegistered) {\n // Register hooks only once\n for (const hook of consentHooks) {\n hook(consent);\n }\n\n hooksRegistered = true;\n }\n\n return consent;\n}\n\n/**\n * Register a hook that will be called when consent is initialized.\n *\n * @param hook - The hook function to register.\n *\n * @internal\n */\nexport function registerConsentHook(hook: ConsentHook): void {\n consentHooks.push(hook);\n}\n\n/**\n * Set the consent state.\n *\n * @remarks\n * - The 'necessary' category cannot be set to false\n * - Cannot be called from a child experience (use parent application instead)\n *\n * @example\n * ```typescript\n * setConsentState({\n * necessary: true,\n * analytics: true,\n * marketing: false,\n * functional: true,\n * });\n * ```\n *\n * @param state - The consent state to set\n * @throws {MonterosaError} If called from a child experience\n * @throws {MonterosaError} If 'necessary' category is set to false\n */\nexport function setConsentState<T extends string = string>(\n state: ConsentState<T>,\n): void {\n const parentApp = getParentApplication();\n\n // Cannot set consent from a child experience\n if (parentApp !== null) {\n throw new MonterosaError(\n ConsentError.CannotSetFromChild,\n ConsentErrorMessages[ConsentError.CannotSetFromChild](),\n );\n }\n\n // Necessary category cannot be false\n if ('necessary' in state && state.necessary === false) {\n throw new MonterosaError(\n ConsentError.NecessaryCategoryRequired,\n ConsentErrorMessages[ConsentError.NecessaryCategoryRequired](),\n );\n }\n\n const consent = getConsent();\n consent.state = state;\n}\n\n/**\n * Get the current consent state.\n *\n * @example\n * ```typescript\n * const state = getConsentState();\n * if (state.analytics) {\n * // Analytics consent granted\n * }\n * ```\n *\n * @returns The current consent state, or empty object if consent mode not active\n */\nexport function getConsentState<T extends string = string>(): ConsentState<T> {\n return (getConsent().state ?? {}) as ConsentState<T>;\n}\n\n/**\n * Check if consent is granted for a specific category.\n *\n * @remarks\n * - The 'necessary' category always returns true\n * - Returns true if consent mode is not active (backwards compatibility)\n * - Returns false for missing keys when consent mode is active (GDPR strict opt-in)\n * - Returns the boolean value if the category exists in consent state\n *\n * @example\n * ```typescript\n * if (hasConsent('analytics')) {\n * // Track analytics event\n * }\n * ```\n *\n * @param category - The consent category to check\n * @returns Whether consent is granted for the category\n */\nexport function hasConsent(category: string): boolean {\n // 'necessary' always returns true\n if (category === 'necessary') {\n return true;\n }\n\n const consent = getConsent();\n\n // If consent mode not active, allow everything (backwards compatibility)\n if (!consent.isActive) {\n return true;\n }\n\n // GDPR strict opt-in: missing keys default to false\n return (\n (consent.state as Record<string, boolean | undefined>)?.[category] === true\n );\n}\n\n/**\n * Subscribe to consent state changes.\n *\n * @example\n * ```typescript\n * const unsubscribe = onConsentChanged((state) => {\n * console.log('Consent changed:', state);\n * });\n *\n * // Later, to stop listening:\n * unsubscribe();\n * ```\n *\n * @param callback - The callback to call when consent state changes\n * @returns A function to unsubscribe from the event\n */\nexport function onConsentChanged<T extends string = string>(\n callback: (state: ConsentState<T>) => void,\n): Unsubscribe {\n const consent = getConsent();\n\n return consent.on(ConsentEvent.ConsentChanged, callback);\n}\n\n/**\n * Update consent state from parent (used internally by bridge).\n *\n * @param state - The consent state received from parent\n *\n * @internal\n */\nexport function updateConsentFromParent<T extends string = string>(\n state: ConsentState<T>,\n): void {\n const consent = getConsent();\n consent.state = state;\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe } from '@monterosa/sdk-util';\nimport {\n Experience,\n Message,\n getParentApplication,\n onSdkMessage,\n sendSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport { ConsentKit, ConsentState, ConsentAction } from './types';\n\nimport { getConsent, onConsentChanged, updateConsentFromParent } from './api';\n\nconst experienceUnsubs = new Map<string, Unsubscribe[]>();\n\n/**\n * Handle when an experience is embedded.\n * Sends current consent state to the child (queued by the bridge until\n * the experience is initialised) and subscribes to consent changes.\n *\n * @param experience - The embedded experience\n *\n * @internal\n */\nexport function handleExperienceEmbedded(experience: Experience): void {\n const consent = getConsent();\n\n // Send current consent state if active.\n // The bridge queues this message until the experience is initialised.\n if (consent.isActive) {\n sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {\n state: consent.state,\n });\n }\n\n // Subscribe to consent changes and push to child\n const consentChangedUnsub = onConsentChanged((state) => {\n sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {\n state,\n });\n });\n\n experienceUnsubs.set(experience.id, [consentChangedUnsub]);\n}\n\n/**\n * Handle when an experience is unmounted.\n * Cleans up subscriptions for the experience.\n *\n * @param experience - The unmounted experience\n *\n * @internal\n */\nexport function handleExperienceUnmounted(experience: Experience): void {\n const unsubs = experienceUnsubs.get(experience.id);\n\n if (unsubs) {\n for (const unsub of unsubs) {\n unsub();\n }\n\n experienceUnsubs.delete(experience.id);\n }\n}\n\n/**\n * Hook to listen for consent messages from parent application.\n * This is called when consent-kit is initialized in a child experience.\n *\n * @param consent - The consent kit instance\n * @returns Unsubscribe function\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function parentMessagesHook(consent: ConsentKit): Unsubscribe {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, (message: Message) => {\n if (message.action === ConsentAction.OnConsentUpdated) {\n const { state } = message.payload as { state: ConsentState };\n\n updateConsentFromParent(state);\n }\n });\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Monterosa SDK / Consent Kit\n *\n * @packageDocumentation\n */\n\nimport { onStateChanged } from '@monterosa/sdk-launcher-kit';\n\nimport {\n handleExperienceEmbedded,\n handleExperienceUnmounted,\n parentMessagesHook,\n} from './bridge';\n\nimport { registerConsentHook } from './api';\n\n// Register bridge handlers for parent-child communication\nonStateChanged((experience, state) => {\n if (state === 'mounted') {\n handleExperienceEmbedded(experience);\n } else if (state === 'unmounted') {\n handleExperienceUnmounted(experience);\n }\n});\n\n// Register hook for child experiences to receive consent from parent\nregisterConsentHook(parentMessagesHook);\n\n// Public API exports\nexport {\n setConsentState,\n getConsentState,\n hasConsent,\n onConsentChanged,\n} from './api';\n\n// Type exports\nexport { DefaultCategory, ConsentState, ConsentError } from './types';\n"],"names":["ConsentError","Emitter","getParentApplication","MonterosaError","sendSdkMessage","onSdkMessage","onStateChanged"],"mappings":";;;;;;;AAAA;;;;;;;AAOG;;AAuCH;;;;AAIG;AACH,IAAY,aASX,CAAA;AATD,CAAA,UAAY,aAAa,EAAA;AACvB;;AAEG;AACH,IAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,yB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MAAA,EAAN,IAAM,EAAE;AAAvB,YAAA,IAAM,KAAK,GAAA,QAAA,CAAA,EAAA,CAAA,CAAA;AACd,YAAA,KAAK,EAAE,CAAC;AACT,SAAA;AAED,QAAA,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AACxC,KAAA;AACH,CAAC;AAED;;;;;;;;AAQG;AACH;AACM,SAAU,kBAAkB,CAAC,OAAmB,EAAA;AACpD,IAAA,IAAM,SAAS,GAAGF,mCAAoB,EAAE,CAAC;IAEzC,IAAI,SAAS,KAAK,IAAI,EAAE;QACtB,OAAO,YAAA,GAAQ,CAAC;AACjB,KAAA;AAED,IAAA,OAAOG,2BAAY,CAAC,SAAS,EAAE,UAAC,OAAgB,EAAA;AAC9C,QAAA,IAAI,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,gBAAgB,EAAE;AAC7C,YAAA,IAAA,KAAK,GAAK,OAAO,CAAC,OAAkC,MAA/C,CAAgD;YAE7D,uBAAuB,CAAC,KAAK,CAAC,CAAC;AAChC,SAAA;AACH,KAAC,CAAC,CAAC;AACL;;AClGA;;;;;;;AAOG;AAkBH;AACAC,6BAAc,CAAC,UAAC,UAAU,EAAE,KAAK,EAAA;IAC/B,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,wBAAwB,CAAC,UAAU,CAAC,CAAC;AACtC,KAAA;SAAM,IAAI,KAAK,KAAK,WAAW,EAAE;QAChC,yBAAyB,CAAC,UAAU,CAAC,CAAC;AACvC,KAAA;AACH,CAAC,CAAC,CAAC;AAEH;AACA,mBAAmB,CAAC,kBAAkB,CAAC;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/types.ts","../src/consent.ts","../src/api.ts","../src/bridge.ts","../src/index.ts"],"sourcesContent":["/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * Default consent categories commonly used for GDPR/privacy compliance.\n *\n * @remarks\n * - `necessary` - Essential cookies/tracking required for the site to function\n * - `analytics` - Analytics and performance tracking\n * - `marketing` - Marketing and advertising tracking\n * - `functional` - User preference and personalization tracking\n */\nexport type DefaultCategory =\n | 'necessary'\n | 'analytics'\n | 'marketing'\n | 'functional';\n\n/**\n * Represents the consent state for each category.\n * Maps category names to boolean values indicating whether consent is granted.\n *\n * @typeParam T - The type of category keys, defaults to DefaultCategory\n *\n * @example\n * ```typescript\n * const state: ConsentState = {\n * necessary: true,\n * analytics: false,\n * marketing: false,\n * preferences: true,\n * };\n * ```\n */\nexport type ConsentState<T extends string = DefaultCategory> = {\n [K in T]?: boolean;\n};\n\n/**\n * Actions used for parent-child bridge communication.\n *\n * @internal\n */\nexport enum ConsentAction {\n /**\n * Sent when consent state is updated.\n */\n OnConsentUpdated = 'consentOnConsentUpdated',\n /**\n * Request to set consent state from child to parent.\n */\n SetConsent = 'consentSetConsent',\n}\n\n/**\n * Internal event names for the consent emitter.\n *\n * @internal\n */\nexport enum ConsentEvent {\n /**\n * Emitted when consent state changes.\n */\n ConsentChanged = 'consent_changed',\n}\n\n/**\n * Defines error codes that may be encountered when using the Consent kit.\n *\n * @example\n * ```typescript\n * try {\n * setConsentState({ necessary: false });\n * } catch (err) {\n * if (err.code === ConsentError.NecessaryCategoryRequired) {\n * // handle necessary category error\n * }\n * }\n * ```\n */\nexport enum ConsentError {\n /**\n * Indicates that the 'necessary' category cannot be set to false.\n */\n NecessaryCategoryRequired = 'necessary_category_required',\n /**\n * Indicates that consent cannot be set from a child experience.\n */\n CannotSetFromChild = 'cannot_set_from_child',\n}\n\n/**\n * Error messages for consent errors.\n *\n * @internal\n */\nexport const ConsentErrorMessages = {\n [ConsentError.NecessaryCategoryRequired]: () =>\n \"Cannot set 'necessary' category to false. Strictly necessary functionality cannot be disabled.\",\n [ConsentError.CannotSetFromChild]: () =>\n 'Cannot set consent state from embedded experience. Consent is managed by the parent application.',\n};\n\n/**\n * Hook function type for registering consent hooks.\n *\n * @internal\n */\nexport type ConsentHook = (consent: ConsentKit) => Unsubscribe;\n\n/**\n * The ConsentKit interface provides properties and methods\n * for managing user consent state.\n *\n * @internal\n */\nexport interface ConsentKit extends Emitter {\n /**\n * Whether consent mode is active.\n * Returns true when state has been set.\n */\n readonly isActive: boolean;\n /**\n * The current consent state.\n */\n state: ConsentState | null;\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Emitter } from '@monterosa/sdk-util';\n\nimport { ConsentKit, ConsentState, ConsentEvent } from './types';\n\n/**\n * Internal Consent class that manages consent state.\n *\n * @internal\n */\nexport class Consent extends Emitter implements ConsentKit {\n private static instance: Consent;\n\n private _state: ConsentState | null = null;\n\n /**\n * The current consent state.\n * Setting this value will automatically emit ConsentChanged event if the state\n * actually changed.\n */\n get state(): ConsentState | null {\n return this._state;\n }\n\n set state(value: ConsentState | null) {\n const previousState = this._state;\n this._state = value;\n\n // Only emit if state changed to a non-null value\n if (value !== null && !Consent.isConsentStateEqual(previousState, value)) {\n this.emit(ConsentEvent.ConsentChanged, value);\n }\n }\n\n /**\n * Whether consent mode is active.\n * Returns true when state has been set.\n */\n get isActive(): boolean {\n return this._state !== null;\n }\n\n private constructor() {\n super();\n }\n\n /**\n * Compare two consent states for equality.\n *\n * @param a - First consent state (or null)\n * @param b - Second consent state (or null)\n * @returns Whether the states are equal\n */\n private static isConsentStateEqual<T extends string = string>(\n a: ConsentState<T> | null,\n b: ConsentState<T> | null,\n ): boolean {\n if (a === null && b === null) return true;\n if (a === null || b === null) return false;\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n const aRecord = a as Record<string, boolean | undefined>;\n const bRecord = b as Record<string, boolean | undefined>;\n\n return keysA.every((key) => aRecord[key] === bRecord[key]);\n }\n\n /**\n * Get the singleton instance of the Consent class.\n *\n * @returns The Consent singleton instance.\n */\n public static getInstance(): Consent {\n if (!Consent.instance) {\n Consent.instance = new Consent();\n }\n\n return Consent.instance;\n }\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe, MonterosaError } from '@monterosa/sdk-util';\nimport { getParentApplication } from '@monterosa/sdk-launcher-kit';\n\nimport {\n ConsentState,\n ConsentKit,\n ConsentEvent,\n ConsentError,\n ConsentErrorMessages,\n ConsentHook,\n} from './types';\n\nimport { Consent } from './consent';\n\nconst consentHooks: ConsentHook[] = [];\nlet hooksRegistered = false;\n\n/**\n * Get the consent kit instance.\n *\n * @returns The consent kit instance.\n *\n * @internal\n */\nexport function getConsent(): ConsentKit {\n const consent = Consent.getInstance();\n\n if (!hooksRegistered) {\n // Register hooks only once\n for (const hook of consentHooks) {\n hook(consent);\n }\n\n hooksRegistered = true;\n }\n\n return consent;\n}\n\n/**\n * Register a hook that will be called when consent is initialized.\n *\n * @param hook - The hook function to register.\n *\n * @internal\n */\nexport function registerConsentHook(hook: ConsentHook): void {\n consentHooks.push(hook);\n}\n\n/**\n * Set the consent state.\n *\n * @remarks\n * - The 'necessary' category cannot be set to false\n * - Cannot be called from a child experience (use parent application instead)\n *\n * @example\n * ```typescript\n * setConsentState({\n * necessary: true,\n * analytics: true,\n * marketing: false,\n * functional: true,\n * });\n * ```\n *\n * @param state - The consent state to set\n * @throws {MonterosaError} If called from a child experience\n * @throws {MonterosaError} If 'necessary' category is set to false\n */\nexport function setConsentState<T extends string = string>(\n state: ConsentState<T>,\n): void {\n const parentApp = getParentApplication();\n\n // Cannot set consent from a child experience\n if (parentApp !== null) {\n throw new MonterosaError(\n ConsentError.CannotSetFromChild,\n ConsentErrorMessages[ConsentError.CannotSetFromChild](),\n );\n }\n\n // Necessary category cannot be false\n if ('necessary' in state && state.necessary === false) {\n throw new MonterosaError(\n ConsentError.NecessaryCategoryRequired,\n ConsentErrorMessages[ConsentError.NecessaryCategoryRequired](),\n );\n }\n\n const consent = getConsent();\n consent.state = state;\n}\n\n/**\n * Get the current consent state.\n *\n * @example\n * ```typescript\n * const state = getConsentState();\n * if (state.analytics) {\n * // Analytics consent granted\n * }\n * ```\n *\n * @returns The current consent state, or empty object if consent mode not active\n */\nexport function getConsentState<T extends string = string>(): ConsentState<T> {\n return (getConsent().state ?? {}) as ConsentState<T>;\n}\n\n/**\n * Check if consent is granted for a specific category.\n *\n * @remarks\n * - The 'necessary' category always returns true\n * - Returns true if consent mode is not active (backwards compatibility)\n * - Returns false for missing keys when consent mode is active (GDPR strict opt-in)\n * - Returns the boolean value if the category exists in consent state\n *\n * @example\n * ```typescript\n * if (hasConsent('analytics')) {\n * // Track analytics event\n * }\n * ```\n *\n * @param category - The consent category to check\n * @returns Whether consent is granted for the category\n */\nexport function hasConsent(category: string): boolean {\n // 'necessary' always returns true\n if (category === 'necessary') {\n return true;\n }\n\n const consent = getConsent();\n\n // If consent mode not active, allow everything (backwards compatibility)\n if (!consent.isActive) {\n return true;\n }\n\n // GDPR strict opt-in: missing keys default to false\n return (\n (consent.state as Record<string, boolean | undefined>)?.[category] === true\n );\n}\n\n/**\n * Subscribe to consent state changes.\n *\n * @example\n * ```typescript\n * const unsubscribe = onConsentChanged((state) => {\n * console.log('Consent changed:', state);\n * });\n *\n * // Later, to stop listening:\n * unsubscribe();\n * ```\n *\n * @param callback - The callback to call when consent state changes\n * @returns A function to unsubscribe from the event\n */\nexport function onConsentChanged<T extends string = string>(\n callback: (state: ConsentState<T>) => void,\n): Unsubscribe {\n const consent = getConsent();\n\n return consent.on(ConsentEvent.ConsentChanged, callback);\n}\n\n/**\n * Update consent state from parent (used internally by bridge).\n *\n * @param state - The consent state received from parent\n *\n * @internal\n */\nexport function updateConsentFromParent<T extends string = string>(\n state: ConsentState<T>,\n): void {\n const consent = getConsent();\n consent.state = state;\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe } from '@monterosa/sdk-util';\nimport {\n Experience,\n Message,\n getParentApplication,\n onSdkMessage,\n sendSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport { ConsentKit, ConsentState, ConsentAction } from './types';\n\nimport { getConsent, onConsentChanged, updateConsentFromParent } from './api';\n\nconst experienceUnsubs = new Map<string, Unsubscribe[]>();\n\n/**\n * Handle when an experience is embedded.\n * Sends current consent state to the child (queued by the bridge until\n * the experience is initialised) and subscribes to consent changes.\n *\n * @param experience - The embedded experience\n *\n * @internal\n */\nexport function handleExperienceEmbedded(experience: Experience): void {\n const consent = getConsent();\n\n // Send current consent state if active.\n // The bridge queues this message until the experience is initialised.\n if (consent.isActive) {\n sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {\n state: consent.state,\n });\n }\n\n // Subscribe to consent changes and push to child\n const consentChangedUnsub = onConsentChanged((state) => {\n sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {\n state,\n });\n });\n\n experienceUnsubs.set(experience.id, [consentChangedUnsub]);\n}\n\n/**\n * Handle when an experience is unmounted.\n * Cleans up subscriptions for the experience.\n *\n * @param experience - The unmounted experience\n *\n * @internal\n */\nexport function handleExperienceUnmounted(experience: Experience): void {\n const unsubs = experienceUnsubs.get(experience.id);\n\n if (unsubs) {\n for (const unsub of unsubs) {\n unsub();\n }\n\n experienceUnsubs.delete(experience.id);\n }\n}\n\n/**\n * Hook to listen for consent messages from parent application.\n * This is called when consent-kit is initialized in a child experience.\n *\n * @param consent - The consent kit instance\n * @returns Unsubscribe function\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function parentMessagesHook(consent: ConsentKit): Unsubscribe {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, (message: Message) => {\n if (message.action === ConsentAction.OnConsentUpdated) {\n const { state } = message.payload as { state: ConsentState };\n\n updateConsentFromParent(state);\n }\n });\n}\n","/**\n * @license\n * @monterosa/sdk-consent-kit\n *\n * Copyright © 2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\n/**\n * Monterosa SDK / Consent Kit\n *\n * @packageDocumentation\n */\n\nimport { onStateChanged } from '@monterosa/sdk-launcher-kit';\n\nimport {\n handleExperienceEmbedded,\n handleExperienceUnmounted,\n parentMessagesHook,\n} from './bridge';\n\nimport { registerConsentHook } from './api';\n\n// Register bridge handlers for parent-child communication\nonStateChanged((experience, state) => {\n if (state === 'mounted') {\n handleExperienceEmbedded(experience);\n } else if (state === 'unmounted') {\n handleExperienceUnmounted(experience);\n }\n});\n\n// Register hook for child experiences to receive consent from parent\nregisterConsentHook(parentMessagesHook);\n\n// Public API exports\nexport {\n setConsentState,\n getConsentState,\n hasConsent,\n onConsentChanged,\n} from './api';\n\n// Type exports\nexport { DefaultCategory, ConsentState, ConsentError } from './types';\n"],"names":[],"mappings":";;;AAAA;;;;;;;AAOG;AAuCH;;;;AAIG;AACH,IAAY,aASX,CAAA;AATD,CAAA,UAAY,aAAa,EAAA;AACvB;;AAEG;AACH,IAAA,aAAA,CAAA,kBAAA,CAAA,GAAA,yBAA4C,CAAA;AAC5C;;AAEG;AACH,IAAA,aAAA,CAAA,YAAA,CAAA,GAAA,mBAAgC,CAAA;AAClC,CAAC,EATW,aAAa,KAAb,aAAa,GASxB,EAAA,CAAA,CAAA,CAAA;AAED;;;;AAIG;AACH,IAAY,YAKX,CAAA;AALD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;AACH,IAAA,YAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AACpC,CAAC,EALW,YAAY,KAAZ,YAAY,GAK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