@monterosa/sdk-consent-kit 2.0.0-rc.1 → 2.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -1
- package/dist/bridge.d.ts +1 -1
- package/dist/{index.cjs.js → index.cjs} +65 -122
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -5
- package/dist/{index.esm.js → index.js} +5 -8
- package/dist/index.js.map +1 -0
- package/package.json +19 -14
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
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
|
|
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
|
|
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
|
|
@@ -13,7 +13,6 @@ var sdkUtil = require('@monterosa/sdk-util');
|
|
|
13
13
|
*
|
|
14
14
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
15
15
|
*/
|
|
16
|
-
var _a;
|
|
17
16
|
/**
|
|
18
17
|
* Actions used for parent-child bridge communication.
|
|
19
18
|
*
|
|
@@ -72,49 +71,9 @@ exports.ConsentError = void 0;
|
|
|
72
71
|
*
|
|
73
72
|
* @internal
|
|
74
73
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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;
|
|
74
|
+
const ConsentErrorMessages = {
|
|
75
|
+
[exports.ConsentError.NecessaryCategoryRequired]: () => "Cannot set 'necessary' category to false. Strictly necessary functionality cannot be disabled.",
|
|
76
|
+
[exports.ConsentError.CannotSetFromChild]: () => 'Cannot set consent state from embedded experience. Consent is managed by the parent application.',
|
|
118
77
|
};
|
|
119
78
|
|
|
120
79
|
/**
|
|
@@ -130,44 +89,34 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
130
89
|
*
|
|
131
90
|
* @internal
|
|
132
91
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
92
|
+
class Consent extends sdkUtil.Emitter {
|
|
93
|
+
/**
|
|
94
|
+
* The current consent state.
|
|
95
|
+
* Setting this value will automatically emit ConsentChanged event if the state
|
|
96
|
+
* actually changed.
|
|
97
|
+
*/
|
|
98
|
+
get state() {
|
|
99
|
+
return this._state;
|
|
100
|
+
}
|
|
101
|
+
set state(value) {
|
|
102
|
+
const previousState = this._state;
|
|
103
|
+
this._state = value;
|
|
104
|
+
// Only emit if state changed to a non-null value
|
|
105
|
+
if (value !== null && !Consent.isConsentStateEqual(previousState, value)) {
|
|
106
|
+
this.emit(ConsentEvent.ConsentChanged, value);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Whether consent mode is active.
|
|
111
|
+
* Returns true when state has been set.
|
|
112
|
+
*/
|
|
113
|
+
get isActive() {
|
|
114
|
+
return this._state !== null;
|
|
115
|
+
}
|
|
116
|
+
constructor() {
|
|
117
|
+
super();
|
|
118
|
+
this._state = null;
|
|
139
119
|
}
|
|
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
120
|
/**
|
|
172
121
|
* Compare two consent states for equality.
|
|
173
122
|
*
|
|
@@ -175,32 +124,31 @@ var Consent = /** @class */ (function (_super) {
|
|
|
175
124
|
* @param b - Second consent state (or null)
|
|
176
125
|
* @returns Whether the states are equal
|
|
177
126
|
*/
|
|
178
|
-
|
|
127
|
+
static isConsentStateEqual(a, b) {
|
|
179
128
|
if (a === null && b === null)
|
|
180
129
|
return true;
|
|
181
130
|
if (a === null || b === null)
|
|
182
131
|
return false;
|
|
183
|
-
|
|
184
|
-
|
|
132
|
+
const keysA = Object.keys(a);
|
|
133
|
+
const keysB = Object.keys(b);
|
|
185
134
|
if (keysA.length !== keysB.length)
|
|
186
135
|
return false;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return keysA.every(
|
|
190
|
-
}
|
|
136
|
+
const aRecord = a;
|
|
137
|
+
const bRecord = b;
|
|
138
|
+
return keysA.every((key) => aRecord[key] === bRecord[key]);
|
|
139
|
+
}
|
|
191
140
|
/**
|
|
192
141
|
* Get the singleton instance of the Consent class.
|
|
193
142
|
*
|
|
194
143
|
* @returns The Consent singleton instance.
|
|
195
144
|
*/
|
|
196
|
-
|
|
145
|
+
static getInstance() {
|
|
197
146
|
if (!Consent.instance) {
|
|
198
147
|
Consent.instance = new Consent();
|
|
199
148
|
}
|
|
200
149
|
return Consent.instance;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
}(sdkUtil.Emitter));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
204
152
|
|
|
205
153
|
/**
|
|
206
154
|
* @license
|
|
@@ -210,8 +158,8 @@ var Consent = /** @class */ (function (_super) {
|
|
|
210
158
|
*
|
|
211
159
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
212
160
|
*/
|
|
213
|
-
|
|
214
|
-
|
|
161
|
+
const consentHooks = [];
|
|
162
|
+
let hooksRegistered = false;
|
|
215
163
|
/**
|
|
216
164
|
* Get the consent kit instance.
|
|
217
165
|
*
|
|
@@ -220,11 +168,10 @@ var hooksRegistered = false;
|
|
|
220
168
|
* @internal
|
|
221
169
|
*/
|
|
222
170
|
function getConsent() {
|
|
223
|
-
|
|
171
|
+
const consent = Consent.getInstance();
|
|
224
172
|
if (!hooksRegistered) {
|
|
225
173
|
// Register hooks only once
|
|
226
|
-
for (
|
|
227
|
-
var hook = consentHooks_1[_i];
|
|
174
|
+
for (const hook of consentHooks) {
|
|
228
175
|
hook(consent);
|
|
229
176
|
}
|
|
230
177
|
hooksRegistered = true;
|
|
@@ -232,7 +179,7 @@ function getConsent() {
|
|
|
232
179
|
return consent;
|
|
233
180
|
}
|
|
234
181
|
/**
|
|
235
|
-
* Register a hook that will be called when consent is
|
|
182
|
+
* Register a hook that will be called when consent is initialised.
|
|
236
183
|
*
|
|
237
184
|
* @param hook - The hook function to register.
|
|
238
185
|
*
|
|
@@ -263,7 +210,7 @@ function registerConsentHook(hook) {
|
|
|
263
210
|
* @throws {MonterosaError} If 'necessary' category is set to false
|
|
264
211
|
*/
|
|
265
212
|
function setConsentState(state) {
|
|
266
|
-
|
|
213
|
+
const parentApp = sdkLauncherKit.getParentApplication();
|
|
267
214
|
// Cannot set consent from a child experience
|
|
268
215
|
if (parentApp !== null) {
|
|
269
216
|
throw new sdkUtil.MonterosaError(exports.ConsentError.CannotSetFromChild, ConsentErrorMessages[exports.ConsentError.CannotSetFromChild]());
|
|
@@ -272,7 +219,7 @@ function setConsentState(state) {
|
|
|
272
219
|
if ('necessary' in state && state.necessary === false) {
|
|
273
220
|
throw new sdkUtil.MonterosaError(exports.ConsentError.NecessaryCategoryRequired, ConsentErrorMessages[exports.ConsentError.NecessaryCategoryRequired]());
|
|
274
221
|
}
|
|
275
|
-
|
|
222
|
+
const consent = getConsent();
|
|
276
223
|
consent.state = state;
|
|
277
224
|
}
|
|
278
225
|
/**
|
|
@@ -317,7 +264,7 @@ function hasConsent(category) {
|
|
|
317
264
|
if (category === 'necessary') {
|
|
318
265
|
return true;
|
|
319
266
|
}
|
|
320
|
-
|
|
267
|
+
const consent = getConsent();
|
|
321
268
|
// If consent mode not active, allow everything (backwards compatibility)
|
|
322
269
|
if (!consent.isActive) {
|
|
323
270
|
return true;
|
|
@@ -342,7 +289,7 @@ function hasConsent(category) {
|
|
|
342
289
|
* @returns A function to unsubscribe from the event
|
|
343
290
|
*/
|
|
344
291
|
function onConsentChanged(callback) {
|
|
345
|
-
|
|
292
|
+
const consent = getConsent();
|
|
346
293
|
return consent.on(ConsentEvent.ConsentChanged, callback);
|
|
347
294
|
}
|
|
348
295
|
/**
|
|
@@ -353,7 +300,7 @@ function onConsentChanged(callback) {
|
|
|
353
300
|
* @internal
|
|
354
301
|
*/
|
|
355
302
|
function updateConsentFromParent(state) {
|
|
356
|
-
|
|
303
|
+
const consent = getConsent();
|
|
357
304
|
consent.state = state;
|
|
358
305
|
}
|
|
359
306
|
|
|
@@ -365,7 +312,7 @@ function updateConsentFromParent(state) {
|
|
|
365
312
|
*
|
|
366
313
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
367
314
|
*/
|
|
368
|
-
|
|
315
|
+
const experienceUnsubs = new Map();
|
|
369
316
|
/**
|
|
370
317
|
* Handle when an experience is embedded.
|
|
371
318
|
* Sends current consent state to the child (queued by the bridge until
|
|
@@ -376,7 +323,7 @@ var experienceUnsubs = new Map();
|
|
|
376
323
|
* @internal
|
|
377
324
|
*/
|
|
378
325
|
function handleExperienceEmbedded(experience) {
|
|
379
|
-
|
|
326
|
+
const consent = getConsent();
|
|
380
327
|
// Send current consent state if active.
|
|
381
328
|
// The bridge queues this message until the experience is initialised.
|
|
382
329
|
if (consent.isActive) {
|
|
@@ -385,9 +332,9 @@ function handleExperienceEmbedded(experience) {
|
|
|
385
332
|
});
|
|
386
333
|
}
|
|
387
334
|
// Subscribe to consent changes and push to child
|
|
388
|
-
|
|
335
|
+
const consentChangedUnsub = onConsentChanged((state) => {
|
|
389
336
|
sdkLauncherKit.sendSdkMessage(experience, ConsentAction.OnConsentUpdated, {
|
|
390
|
-
state
|
|
337
|
+
state,
|
|
391
338
|
});
|
|
392
339
|
});
|
|
393
340
|
experienceUnsubs.set(experience.id, [consentChangedUnsub]);
|
|
@@ -401,10 +348,9 @@ function handleExperienceEmbedded(experience) {
|
|
|
401
348
|
* @internal
|
|
402
349
|
*/
|
|
403
350
|
function handleExperienceUnmounted(experience) {
|
|
404
|
-
|
|
351
|
+
const unsubs = experienceUnsubs.get(experience.id);
|
|
405
352
|
if (unsubs) {
|
|
406
|
-
for (
|
|
407
|
-
var unsub = unsubs_1[_i];
|
|
353
|
+
for (const unsub of unsubs) {
|
|
408
354
|
unsub();
|
|
409
355
|
}
|
|
410
356
|
experienceUnsubs.delete(experience.id);
|
|
@@ -412,7 +358,7 @@ function handleExperienceUnmounted(experience) {
|
|
|
412
358
|
}
|
|
413
359
|
/**
|
|
414
360
|
* Hook to listen for consent messages from parent application.
|
|
415
|
-
* This is called when consent-kit is
|
|
361
|
+
* This is called when consent-kit is initialised in a child Experience.
|
|
416
362
|
*
|
|
417
363
|
* @param consent - The consent kit instance
|
|
418
364
|
* @returns Unsubscribe function
|
|
@@ -421,28 +367,25 @@ function handleExperienceUnmounted(experience) {
|
|
|
421
367
|
*/
|
|
422
368
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
423
369
|
function parentMessagesHook(consent) {
|
|
424
|
-
|
|
370
|
+
const parentApp = sdkLauncherKit.getParentApplication();
|
|
425
371
|
if (parentApp === null) {
|
|
426
|
-
return
|
|
372
|
+
return () => { };
|
|
427
373
|
}
|
|
428
|
-
return sdkLauncherKit.onSdkMessage(parentApp,
|
|
374
|
+
return sdkLauncherKit.onSdkMessage(parentApp, (message) => {
|
|
429
375
|
if (message.action === ConsentAction.OnConsentUpdated) {
|
|
430
|
-
|
|
376
|
+
const { state } = message.payload;
|
|
431
377
|
updateConsentFromParent(state);
|
|
432
378
|
}
|
|
433
379
|
});
|
|
434
380
|
}
|
|
435
381
|
|
|
436
382
|
/**
|
|
437
|
-
*
|
|
438
|
-
* @monterosa/sdk-consent-kit
|
|
383
|
+
* Manages user consent state between the parent page and embedded Experiences.
|
|
439
384
|
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
385
|
+
* @packageDocumentation
|
|
443
386
|
*/
|
|
444
387
|
// Register bridge handlers for parent-child communication
|
|
445
|
-
sdkLauncherKit.onStateChanged(
|
|
388
|
+
sdkLauncherKit.onStateChanged((experience, state) => {
|
|
446
389
|
if (state === 'mounted') {
|
|
447
390
|
handleExperienceEmbedded(experience);
|
|
448
391
|
}
|
|
@@ -457,4 +400,4 @@ exports.getConsentState = getConsentState;
|
|
|
457
400
|
exports.hasConsent = hasConsent;
|
|
458
401
|
exports.onConsentChanged = onConsentChanged;
|
|
459
402
|
exports.setConsentState = setConsentState;
|
|
460
|
-
//# sourceMappingURL=index.cjs.
|
|
403
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","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":["ConsentError","Emitter","getParentApplication","Monter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D,uBAAuB,CAAC,KAAK,CAAC,CAAC;AAChC,SAAA;AACH,KAAC,CAAC,CAAC;AACL;;AClGA;;;;AAIG;AAqBH;AACAC,6BAAc,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/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @monterosa/sdk-consent-kit
|
|
2
|
+
* Manages user consent state between the parent page and embedded Experiences.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
380
|
-
* @monterosa/sdk-consent-kit
|
|
379
|
+
* Manages user consent state between the parent page and embedded Experiences.
|
|
381
380
|
*
|
|
382
|
-
*
|
|
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.
|
|
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,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,EAAE;AACtB,QAAA,OAAO,MAAO,GAAC,CAAC;AACjB,KAAA;AAED,IAAA,OAAO,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,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monterosa/sdk-consent-kit",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.3",
|
|
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
|
|
7
|
-
"browser": "dist/index.esm.js",
|
|
8
|
-
"module": "dist/index.esm.js",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
9
7
|
"types": "./dist/index.d.ts",
|
|
10
|
-
"
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"default": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
11
16
|
"files": [
|
|
12
17
|
"dist"
|
|
13
18
|
],
|
|
@@ -19,19 +24,19 @@
|
|
|
19
24
|
"test:ci": "jest --color --ci --reporters=jest-junit --coverage",
|
|
20
25
|
"api-report": "api-extractor run --local --verbose"
|
|
21
26
|
},
|
|
22
|
-
"keywords": [
|
|
27
|
+
"keywords": [
|
|
28
|
+
"monterosa",
|
|
29
|
+
"sdk",
|
|
30
|
+
"interaction-cloud",
|
|
31
|
+
"consent"
|
|
32
|
+
],
|
|
23
33
|
"license": "MIT",
|
|
24
|
-
"peerDependencies": {
|
|
25
|
-
"@monterosa/sdk-launcher-kit": "0.x",
|
|
26
|
-
"@monterosa/sdk-util": "0.x"
|
|
27
|
-
},
|
|
28
34
|
"dependencies": {
|
|
29
|
-
"@monterosa/sdk-launcher-kit": "
|
|
30
|
-
"@monterosa/sdk-util": "
|
|
35
|
+
"@monterosa/sdk-launcher-kit": "2.0.0-rc.3",
|
|
36
|
+
"@monterosa/sdk-util": "2.0.0-rc.3"
|
|
31
37
|
},
|
|
32
38
|
"devDependencies": {
|
|
33
39
|
"@faker-js/faker": "^6.3.1",
|
|
34
|
-
"@rollup/plugin-commonjs": "^21.1.0",
|
|
35
40
|
"@rollup/plugin-json": "^4.1.0",
|
|
36
41
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
37
42
|
"@rollup/plugin-terser": "^0.4.4",
|
|
@@ -48,5 +53,5 @@
|
|
|
48
53
|
"publishConfig": {
|
|
49
54
|
"access": "public"
|
|
50
55
|
},
|
|
51
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "d692ad26af0b5ea7cd7b664168bffa069f9ab911"
|
|
52
57
|
}
|
package/dist/index.cjs.js.map
DELETED
|
@@ -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,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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AC,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;;;;;;;"}
|
package/dist/index.esm.js.map
DELETED
|
@@ -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,GAKvB,EAAA,CAAA,CAAA,CAAA;AAED;;;;;;;;;;;;;AAaG;IACS,aASX;AATD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;AACH,IAAA,YAAA,CAAA,2BAA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