@walkeros/web-source-cmp-cookiebot 0.0.0-stage → 4.9.0-next-1793116456867

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.
@@ -0,0 +1,214 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/examples/inputs.ts
8
+ var fullConsent = {
9
+ consented: true,
10
+ declined: false,
11
+ hasResponse: true,
12
+ consent: {
13
+ stamp: "example-stamp-full",
14
+ necessary: true,
15
+ preferences: true,
16
+ statistics: true,
17
+ marketing: true,
18
+ method: "explicit"
19
+ }
20
+ };
21
+ var partialConsent = {
22
+ consented: true,
23
+ declined: false,
24
+ hasResponse: true,
25
+ consent: {
26
+ stamp: "example-stamp-partial",
27
+ necessary: true,
28
+ preferences: true,
29
+ statistics: true,
30
+ marketing: false,
31
+ method: "explicit"
32
+ }
33
+ };
34
+ var necessaryOnly = {
35
+ consented: false,
36
+ declined: true,
37
+ hasResponse: true,
38
+ consent: {
39
+ stamp: "example-stamp-necessary",
40
+ necessary: true,
41
+ preferences: false,
42
+ statistics: false,
43
+ marketing: false,
44
+ method: "explicit"
45
+ }
46
+ };
47
+ var impliedConsent = {
48
+ consented: true,
49
+ declined: false,
50
+ hasResponse: true,
51
+ consent: {
52
+ stamp: "-1",
53
+ necessary: true,
54
+ preferences: true,
55
+ statistics: true,
56
+ marketing: true,
57
+ method: "implied"
58
+ }
59
+ };
60
+ var noResponse = {
61
+ consented: false,
62
+ declined: false,
63
+ hasResponse: false,
64
+ consent: {
65
+ stamp: "0",
66
+ necessary: true,
67
+ preferences: false,
68
+ statistics: false,
69
+ marketing: false,
70
+ method: null
71
+ }
72
+ };
73
+ var uppercaseMethod = {
74
+ ...fullConsent,
75
+ consent: { ...fullConsent.consent, method: "EXPLICIT" }
76
+ };
77
+
78
+ // src/examples/outputs.ts
79
+ var fullConsentMapped = {
80
+ necessary: true,
81
+ functional: true,
82
+ analytics: true,
83
+ marketing: true
84
+ };
85
+ var partialConsentMapped = {
86
+ necessary: true,
87
+ functional: true,
88
+ analytics: true,
89
+ marketing: false
90
+ };
91
+ var necessaryOnlyMapped = {
92
+ necessary: true,
93
+ functional: false,
94
+ analytics: false,
95
+ marketing: false
96
+ };
97
+ var partialConsentCustomMapped = {
98
+ necessary: true,
99
+ functional: true,
100
+ statistics: true,
101
+ marketing: false
102
+ };
103
+
104
+ // src/examples/step.ts
105
+ var step_exports = {};
106
+ __export(step_exports, {
107
+ allowAll: () => allowAll,
108
+ categoryMapOverride: () => categoryMapOverride,
109
+ firstVisit: () => firstVisit,
110
+ impliedAllowed: () => impliedAllowed,
111
+ impliedSkipped: () => impliedSkipped,
112
+ necessaryOnlyChoice: () => necessaryOnlyChoice,
113
+ returningVisitor: () => returningVisitor
114
+ });
115
+ var allowAll = {
116
+ title: "Allow all",
117
+ description: 'The visitor clicks "Allow all". Cookiebot fires CookiebotOnAccept and the source emits a walker consent command granting functional, analytics and marketing.',
118
+ trigger: { type: "consent", options: { dispatch: "event" } },
119
+ in: fullConsent,
120
+ out: [["elb", "walker consent", fullConsentMapped]]
121
+ };
122
+ var necessaryOnlyChoice = {
123
+ title: "Necessary only",
124
+ description: 'The visitor clicks "Use necessary cookies only". Cookiebot fires CookiebotOnDecline and the source emits functional, analytics and marketing as false.',
125
+ trigger: { type: "consent", options: { dispatch: "event" } },
126
+ in: necessaryOnly,
127
+ out: [["elb", "walker consent", necessaryOnlyMapped]]
128
+ };
129
+ var returningVisitor = {
130
+ title: "Returning visitor",
131
+ description: "Cookiebot already restored a stored choice when the source starts, so the static read at init publishes it at once.",
132
+ trigger: { type: "consent", options: { dispatch: "init" } },
133
+ in: partialConsent,
134
+ out: [["elb", "walker consent", partialConsentMapped]]
135
+ };
136
+ var firstVisit = {
137
+ title: "First visit",
138
+ description: "The banner is still open and Cookiebot holds no response, so the source emits no consent command until the visitor decides.",
139
+ trigger: { type: "consent", options: { dispatch: "init" } },
140
+ in: noResponse,
141
+ out: []
142
+ };
143
+ var impliedSkipped = {
144
+ title: "Implied consent (skipped)",
145
+ description: "Cookiebot consented on its own (consent.method implied), for example outside the regions where the site asks. The default explicitOnly publishes only an explicit decision, so no consent command is emitted, and a visitor Cookiebot never asks never sends one.",
146
+ trigger: { type: "consent", options: { dispatch: "init" } },
147
+ in: impliedConsent,
148
+ out: []
149
+ };
150
+ var impliedAllowed = {
151
+ title: "Implied consent (explicitOnly off)",
152
+ description: "With explicitOnly set to false the source follows the consent Cookiebot implied and grants every group.",
153
+ trigger: { type: "consent", options: { dispatch: "init" } },
154
+ in: impliedConsent,
155
+ mapping: { settings: { explicitOnly: false } },
156
+ out: [["elb", "walker consent", fullConsentMapped]]
157
+ };
158
+ var categoryMapOverride = {
159
+ title: "Category map override",
160
+ description: "A custom categoryMap reports Cookiebot statistics as a statistics group instead of analytics.",
161
+ trigger: { type: "consent", options: { dispatch: "init" } },
162
+ in: partialConsent,
163
+ mapping: { settings: { categoryMap: { statistics: "statistics" } } },
164
+ out: [["elb", "walker consent", partialConsentCustomMapped]]
165
+ };
166
+
167
+ // src/examples/trigger.ts
168
+ import { startFlow } from "@walkeros/collector";
169
+ var createTrigger = async (config) => {
170
+ let flow;
171
+ const trigger = (_type, opts) => async (content) => {
172
+ var _a;
173
+ if (!isCookiebotState(content))
174
+ throw new Error(
175
+ "Cookiebot trigger content is the window.Cookiebot state: { consent: { necessary, preferences, statistics, marketing, method } }"
176
+ );
177
+ const viaEvent = typeof opts === "object" && opts !== null && "dispatch" in opts && opts.dispatch === "event";
178
+ if (!flow && !viaEvent) Object.assign(window, { Cookiebot: content });
179
+ if (!flow) {
180
+ const result = await startFlow({ ...config, run: (_a = config.run) != null ? _a : true });
181
+ flow = { collector: result.collector, elb: result.elb };
182
+ if (!viaEvent) return;
183
+ }
184
+ Object.assign(window, { Cookiebot: content });
185
+ window.dispatchEvent(
186
+ new Event(
187
+ content.consented ? "CookiebotOnAccept" : "CookiebotOnDecline"
188
+ )
189
+ );
190
+ };
191
+ return {
192
+ get flow() {
193
+ return flow;
194
+ },
195
+ trigger
196
+ };
197
+ };
198
+ function isCookiebotState(value) {
199
+ return typeof value === "object" && value !== null && "consent" in value && typeof value.consent === "object" && value.consent !== null;
200
+ }
201
+ export {
202
+ createTrigger,
203
+ fullConsent,
204
+ fullConsentMapped,
205
+ impliedConsent,
206
+ necessaryOnly,
207
+ necessaryOnlyMapped,
208
+ noResponse,
209
+ partialConsent,
210
+ partialConsentCustomMapped,
211
+ partialConsentMapped,
212
+ step_exports as step,
213
+ uppercaseMethod
214
+ };
@@ -0,0 +1 @@
1
+ "use strict";var SourceCookiebot=(()=>{var e=Object.defineProperty,o=Object.getOwnPropertyDescriptor,t=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,r={};((o,t)=>{for(var n in t)e(o,n,{get:t[n],enumerable:!0})})(r,{DEFAULT_CATEGORY_MAP:()=>c,SourceCookiebot:()=>l,default:()=>u,sourceCookiebot:()=>a});var i,l={},c={preferences:"functional",statistics:"analytics",marketing:"marketing"},s=["CookiebotOnAccept","CookiebotOnDecline"],a=async e=>{var o,t,n,r,i;const{config:l,env:a}=e,{elb:u}=a,v=null!=(o=a.window)?o:void 0!==globalThis.window?globalThis.window:void 0,b={...c,...null!=(n=null==(t=null==l?void 0:l.settings)?void 0:t.categoryMap)?n:{}},f={};Object.entries(b).forEach(([e,o])=>{f[e.toLowerCase()]=o});const d={categoryMap:b,explicitOnly:null==(i=null==(r=null==l?void 0:l.settings)?void 0:r.explicitOnly)||i};let p,y;const O=()=>{var e,o;const t=null==(e=null==v?void 0:v.Cookiebot)?void 0:e.consent,n=null==(o=null==t?void 0:t.method)?void 0:o.toLowerCase();if(!t||!n)return;if(d.explicitOnly&&"explicit"!==n)return;const r=(e=>{const o={};return Object.entries(e).forEach(([e,t])=>{var n;if("boolean"!=typeof t)return;const r=null!=(n=f[e.toLowerCase()])?n:e;o[r]=(void 0===o[r]||o[r])&&t}),o})(t);if(0===Object.keys(r).length)return;const i=JSON.stringify(Object.entries(r).sort());i!==y&&(y=i,u("walker consent",r))};return{type:"cookiebot",config:{settings:d},push:u,init:async()=>{var e;if(!v)return;(null==(e=v.Cookiebot)?void 0:e.hasResponse)&&O();const o=()=>O();p=o,s.forEach(e=>v.addEventListener(e,o))},destroy:async e=>{const o=p;v&&o&&(s.forEach(e=>v.removeEventListener(e,o)),p=void 0)}}},u=a;return i=r,((r,i,l,c)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let s of t(i))n.call(r,s)||s===l||e(r,s,{get:()=>i[s],enumerable:!(c=o(i,s))||c.enumerable});return r})(e({},"__esModule",{value:!0}),i)})();
@@ -0,0 +1,163 @@
1
+ import { Source, Elb } from '@walkeros/core';
2
+
3
+ declare module '@walkeros/core' {
4
+ interface SourceMap {
5
+ cookiebot: {
6
+ type: 'cookiebot';
7
+ platform?: 'web';
8
+ };
9
+ }
10
+ }
11
+ /**
12
+ * Cookiebot consent object (`window.Cookiebot.consent`).
13
+ *
14
+ * The four categories are booleans Cookiebot always sets. `method` is
15
+ * `'explicit'` when the visitor actively decided, `'implied'` when Cookiebot
16
+ * consented on its own (outside a region that requires consent, an implied
17
+ * banner, or an old consent of unknown method) and `null` without consent.
18
+ */
19
+ interface CookiebotConsent {
20
+ necessary?: boolean;
21
+ preferences?: boolean;
22
+ statistics?: boolean;
23
+ marketing?: boolean;
24
+ method?: string | null;
25
+ stamp?: string;
26
+ [category: string]: boolean | string | null | undefined;
27
+ }
28
+ /**
29
+ * The subset of the Cookiebot SDK (`window.Cookiebot`) the source reads.
30
+ */
31
+ interface CookiebotAPI {
32
+ consent: CookiebotConsent;
33
+ /** The visitor accepted at least one category. */
34
+ consented?: boolean;
35
+ /** The visitor declined. */
36
+ declined?: boolean;
37
+ /** The visitor answered the banner, or Cookiebot consented for them. */
38
+ hasResponse?: boolean;
39
+ }
40
+ /**
41
+ * Window surface the source touches: the Cookiebot global and event
42
+ * registration. Narrowed instead of the global `Window`, so the package adds
43
+ * no global declarations that could clash with `@types/cookiebot-sdk`, and
44
+ * test mocks satisfy it without a cast.
45
+ */
46
+ interface CookiebotWindow {
47
+ Cookiebot?: CookiebotAPI;
48
+ addEventListener(type: string, listener: EventListener): void;
49
+ removeEventListener(type: string, listener: EventListener): void;
50
+ }
51
+ /**
52
+ * Settings for the Cookiebot source
53
+ */
54
+ interface Settings {
55
+ /**
56
+ * Map Cookiebot categories to walkerOS consent groups.
57
+ * Keys: Cookiebot categories (necessary, preferences, statistics, marketing)
58
+ * Values: walkerOS consent group names
59
+ *
60
+ * Comparison is case-insensitive. Categories without an entry pass through
61
+ * under their own name, `necessary` among them by default.
62
+ *
63
+ * Default:
64
+ * - preferences -> functional
65
+ * - statistics -> analytics
66
+ * - marketing -> marketing
67
+ */
68
+ categoryMap?: Record<string, string>;
69
+ /**
70
+ * Only process consent the visitor actively gave (`consent.method` is
71
+ * `'explicit'`). Implied consent, which Cookiebot sets on its own, is
72
+ * skipped.
73
+ *
74
+ * Default: true
75
+ */
76
+ explicitOnly?: boolean;
77
+ }
78
+ /**
79
+ * User input settings (all optional)
80
+ */
81
+ type InitSettings = Partial<Settings>;
82
+ /**
83
+ * No mapping configuration for this source
84
+ */
85
+ interface Mapping {
86
+ }
87
+ /**
88
+ * Push function type - uses elb for consent commands
89
+ */
90
+ type Push = Elb.Fn;
91
+ /**
92
+ * Environment interface for the Cookiebot source
93
+ */
94
+ interface Env extends Source.BaseEnv {
95
+ window?: CookiebotWindow;
96
+ }
97
+ /**
98
+ * Types bundle for the Cookiebot source
99
+ */
100
+ type Types = Source.Types<Settings, Mapping, Push, Env, InitSettings>;
101
+ /**
102
+ * Config type alias
103
+ */
104
+ type Config = Source.Config<Types>;
105
+
106
+ type index_Config = Config;
107
+ type index_CookiebotAPI = CookiebotAPI;
108
+ type index_CookiebotConsent = CookiebotConsent;
109
+ type index_CookiebotWindow = CookiebotWindow;
110
+ type index_Env = Env;
111
+ type index_InitSettings = InitSettings;
112
+ type index_Mapping = Mapping;
113
+ type index_Push = Push;
114
+ type index_Settings = Settings;
115
+ type index_Types = Types;
116
+ declare namespace index {
117
+ export type { index_Config as Config, index_CookiebotAPI as CookiebotAPI, index_CookiebotConsent as CookiebotConsent, index_CookiebotWindow as CookiebotWindow, index_Env as Env, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Push as Push, index_Settings as Settings, index_Types as Types };
118
+ }
119
+
120
+ /**
121
+ * Default category mapping from Cookiebot to walkerOS consent groups.
122
+ *
123
+ * - preferences -> functional
124
+ * - statistics -> analytics
125
+ * - marketing -> marketing
126
+ *
127
+ * `necessary` has no entry and keeps its own name: Cookiebot always grants
128
+ * it, so mapping it to functional would grant functional with every choice.
129
+ */
130
+ declare const DEFAULT_CATEGORY_MAP: Record<string, string>;
131
+ /**
132
+ * Cookiebot consent management source for walkerOS.
133
+ *
134
+ * This source reads Cookiebot's consent and translates it to walkerOS
135
+ * consent commands.
136
+ *
137
+ * Two detection paths:
138
+ * 1. Already loaded: window.Cookiebot with a response
139
+ * 2. Decision: CookiebotOnAccept and CookiebotOnDecline window events
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * import { sourceCookiebot } from '@walkeros/web-source-cmp-cookiebot';
144
+ *
145
+ * await startFlow({
146
+ * sources: {
147
+ * consent: {
148
+ * code: sourceCookiebot,
149
+ * config: {
150
+ * settings: {
151
+ * categoryMap: {
152
+ * statistics: 'statistics', // Custom mapping
153
+ * },
154
+ * },
155
+ * },
156
+ * },
157
+ * },
158
+ * });
159
+ * ```
160
+ */
161
+ declare const sourceCookiebot: Source.Init<Types>;
162
+
163
+ export { DEFAULT_CATEGORY_MAP, index as SourceCookiebot, sourceCookiebot as default, sourceCookiebot };
@@ -0,0 +1,163 @@
1
+ import { Source, Elb } from '@walkeros/core';
2
+
3
+ declare module '@walkeros/core' {
4
+ interface SourceMap {
5
+ cookiebot: {
6
+ type: 'cookiebot';
7
+ platform?: 'web';
8
+ };
9
+ }
10
+ }
11
+ /**
12
+ * Cookiebot consent object (`window.Cookiebot.consent`).
13
+ *
14
+ * The four categories are booleans Cookiebot always sets. `method` is
15
+ * `'explicit'` when the visitor actively decided, `'implied'` when Cookiebot
16
+ * consented on its own (outside a region that requires consent, an implied
17
+ * banner, or an old consent of unknown method) and `null` without consent.
18
+ */
19
+ interface CookiebotConsent {
20
+ necessary?: boolean;
21
+ preferences?: boolean;
22
+ statistics?: boolean;
23
+ marketing?: boolean;
24
+ method?: string | null;
25
+ stamp?: string;
26
+ [category: string]: boolean | string | null | undefined;
27
+ }
28
+ /**
29
+ * The subset of the Cookiebot SDK (`window.Cookiebot`) the source reads.
30
+ */
31
+ interface CookiebotAPI {
32
+ consent: CookiebotConsent;
33
+ /** The visitor accepted at least one category. */
34
+ consented?: boolean;
35
+ /** The visitor declined. */
36
+ declined?: boolean;
37
+ /** The visitor answered the banner, or Cookiebot consented for them. */
38
+ hasResponse?: boolean;
39
+ }
40
+ /**
41
+ * Window surface the source touches: the Cookiebot global and event
42
+ * registration. Narrowed instead of the global `Window`, so the package adds
43
+ * no global declarations that could clash with `@types/cookiebot-sdk`, and
44
+ * test mocks satisfy it without a cast.
45
+ */
46
+ interface CookiebotWindow {
47
+ Cookiebot?: CookiebotAPI;
48
+ addEventListener(type: string, listener: EventListener): void;
49
+ removeEventListener(type: string, listener: EventListener): void;
50
+ }
51
+ /**
52
+ * Settings for the Cookiebot source
53
+ */
54
+ interface Settings {
55
+ /**
56
+ * Map Cookiebot categories to walkerOS consent groups.
57
+ * Keys: Cookiebot categories (necessary, preferences, statistics, marketing)
58
+ * Values: walkerOS consent group names
59
+ *
60
+ * Comparison is case-insensitive. Categories without an entry pass through
61
+ * under their own name, `necessary` among them by default.
62
+ *
63
+ * Default:
64
+ * - preferences -> functional
65
+ * - statistics -> analytics
66
+ * - marketing -> marketing
67
+ */
68
+ categoryMap?: Record<string, string>;
69
+ /**
70
+ * Only process consent the visitor actively gave (`consent.method` is
71
+ * `'explicit'`). Implied consent, which Cookiebot sets on its own, is
72
+ * skipped.
73
+ *
74
+ * Default: true
75
+ */
76
+ explicitOnly?: boolean;
77
+ }
78
+ /**
79
+ * User input settings (all optional)
80
+ */
81
+ type InitSettings = Partial<Settings>;
82
+ /**
83
+ * No mapping configuration for this source
84
+ */
85
+ interface Mapping {
86
+ }
87
+ /**
88
+ * Push function type - uses elb for consent commands
89
+ */
90
+ type Push = Elb.Fn;
91
+ /**
92
+ * Environment interface for the Cookiebot source
93
+ */
94
+ interface Env extends Source.BaseEnv {
95
+ window?: CookiebotWindow;
96
+ }
97
+ /**
98
+ * Types bundle for the Cookiebot source
99
+ */
100
+ type Types = Source.Types<Settings, Mapping, Push, Env, InitSettings>;
101
+ /**
102
+ * Config type alias
103
+ */
104
+ type Config = Source.Config<Types>;
105
+
106
+ type index_Config = Config;
107
+ type index_CookiebotAPI = CookiebotAPI;
108
+ type index_CookiebotConsent = CookiebotConsent;
109
+ type index_CookiebotWindow = CookiebotWindow;
110
+ type index_Env = Env;
111
+ type index_InitSettings = InitSettings;
112
+ type index_Mapping = Mapping;
113
+ type index_Push = Push;
114
+ type index_Settings = Settings;
115
+ type index_Types = Types;
116
+ declare namespace index {
117
+ export type { index_Config as Config, index_CookiebotAPI as CookiebotAPI, index_CookiebotConsent as CookiebotConsent, index_CookiebotWindow as CookiebotWindow, index_Env as Env, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Push as Push, index_Settings as Settings, index_Types as Types };
118
+ }
119
+
120
+ /**
121
+ * Default category mapping from Cookiebot to walkerOS consent groups.
122
+ *
123
+ * - preferences -> functional
124
+ * - statistics -> analytics
125
+ * - marketing -> marketing
126
+ *
127
+ * `necessary` has no entry and keeps its own name: Cookiebot always grants
128
+ * it, so mapping it to functional would grant functional with every choice.
129
+ */
130
+ declare const DEFAULT_CATEGORY_MAP: Record<string, string>;
131
+ /**
132
+ * Cookiebot consent management source for walkerOS.
133
+ *
134
+ * This source reads Cookiebot's consent and translates it to walkerOS
135
+ * consent commands.
136
+ *
137
+ * Two detection paths:
138
+ * 1. Already loaded: window.Cookiebot with a response
139
+ * 2. Decision: CookiebotOnAccept and CookiebotOnDecline window events
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * import { sourceCookiebot } from '@walkeros/web-source-cmp-cookiebot';
144
+ *
145
+ * await startFlow({
146
+ * sources: {
147
+ * consent: {
148
+ * code: sourceCookiebot,
149
+ * config: {
150
+ * settings: {
151
+ * categoryMap: {
152
+ * statistics: 'statistics', // Custom mapping
153
+ * },
154
+ * },
155
+ * },
156
+ * },
157
+ * },
158
+ * });
159
+ * ```
160
+ */
161
+ declare const sourceCookiebot: Source.Init<Types>;
162
+
163
+ export { DEFAULT_CATEGORY_MAP, index as SourceCookiebot, sourceCookiebot as default, sourceCookiebot };
@@ -0,0 +1 @@
1
+ "use strict";function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _array_with_holes(e){if(Array.isArray(e))return e}function asyncGeneratorStep(e,t,r,n,o,i,a){try{var u=e[i](a),l=u.value}catch(e){return void r(e)}u.done?t(l):Promise.resolve(l).then(n,o)}function _async_to_generator(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){asyncGeneratorStep(i,n,o,a,u,"next",e)}function u(e){asyncGeneratorStep(i,n,o,a,u,"throw",e)}a(void 0)})}}function _define_property(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _iterable_to_array_limit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){_define_property(e,t,r[t])})}return e}function _sliced_to_array(e,t){return _array_with_holes(e)||_iterable_to_array_limit(e,t)||_unsupported_iterable_to_array(e,t)||_non_iterable_rest()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,t){if(e){if("string"==typeof e)return _array_like_to_array(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_array_like_to_array(e,t):void 0}}function _ts_generator(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:l(0)}),u(a,"throw",{value:l(1)}),u(a,"return",{value:l(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function l(u){return function(l){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,u[0]&&(i=0)),i;)try{if(r=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,n=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){i.label=u[1];break}if(6===u[0]&&i.label<o[1]){i.label=o[1],o=u;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(u);break}o[2]&&i.ops.pop(),i.trys.pop();continue}u=t.call(e,i)}catch(e){u=[6,e],n=0}finally{r=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,l])}}}var SourceCookiebot=function(){var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,o={};!function(t,r){for(var n in r)e(t,n,{get:r[n],enumerable:!0})}(o,{DEFAULT_CATEGORY_MAP:function(){return u},SourceCookiebot:function(){return a},default:function(){return f},sourceCookiebot:function(){return c}});var i,a={},u={preferences:"functional",statistics:"analytics",marketing:"marketing"},l=["CookiebotOnAccept","CookiebotOnDecline"],c=function(e){return _async_to_generator(function(){var t,r,n,o,i,a,c,f,s,y,_,b,p,v,d,h;return _ts_generator(this,function(g){return a=e.config,c=e.env,f=c.elb,s=null!==(t=c.window)&&void 0!==t?t:void 0!==globalThis.window?globalThis.window:void 0,y=_object_spread({},u,null!==(r=null==a||null===(o=a.settings)||void 0===o?void 0:o.categoryMap)&&void 0!==r?r:{}),_={},Object.entries(y).forEach(function(e){var t=_sliced_to_array(e,2),r=t[0],n=t[1];_[r.toLowerCase()]=n}),b={categoryMap:y,explicitOnly:null===(n=null==a||null===(i=a.settings)||void 0===i?void 0:i.explicitOnly)||void 0===n||n},d=function(e){var t={};return Object.entries(e).forEach(function(e){var r,n=_sliced_to_array(e,2),o=n[0],i=n[1];if("boolean"==typeof i){var a=null!==(r=_[o.toLowerCase()])&&void 0!==r?r:o;t[a]=(void 0===t[a]||t[a])&&i}}),t},h=function(){var e,t,r=null==s||null===(e=s.Cookiebot)||void 0===e?void 0:e.consent,n=null==r||null===(t=r.method)||void 0===t?void 0:t.toLowerCase();if(r&&n&&(!b.explicitOnly||"explicit"===n)){var o=d(r);if(0!==Object.keys(o).length){var i=JSON.stringify(Object.entries(o).sort());i!==v&&(v=i,f("walker consent",o))}}},[2,{type:"cookiebot",config:{settings:b},push:f,init:function(){return _async_to_generator(function(){var e,t;return _ts_generator(this,function(r){return s?((null===(e=s.Cookiebot)||void 0===e?void 0:e.hasResponse)&&h(),p=t=function(){return h()},l.forEach(function(e){return s.addEventListener(e,t)}),[2]):[2]})})()},destroy:function(e){return _async_to_generator(function(){var e;return _ts_generator(this,function(t){return e=p,s&&e?(l.forEach(function(t){return s.removeEventListener(t,e)}),p=void 0,[2]):[2]})})()}}]})})()},f=c;return i=o,function(o,i,a,u){if(i&&"object"===(void 0===i?"undefined":_type_of(i))||"function"==typeof i){var l=!0,c=!1,f=void 0;try{for(var s,y=function(){var r=s.value;n.call(o,r)||r===a||e(o,r,{get:function(){return i[r]},enumerable:!(u=t(i,r))||u.enumerable})},_=r(i)[Symbol.iterator]();!(l=(s=_.next()).done);l=!0)y()}catch(e){c=!0,f=e}finally{try{l||null==_.return||_.return()}finally{if(c)throw f}}}return o}(e({},"__esModule",{value:!0}),i)}();
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.defineProperty,o=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i={};((e,o)=>{for(var n in o)t(e,n,{get:o[n],enumerable:!0})})(i,{DEFAULT_CATEGORY_MAP:()=>s,SourceCookiebot:()=>l,default:()=>u,sourceCookiebot:()=>a}),module.exports=(e=i,((e,i,l,s)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let c of n(i))r.call(e,c)||c===l||t(e,c,{get:()=>i[c],enumerable:!(s=o(i,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var l={},s={preferences:"functional",statistics:"analytics",marketing:"marketing"},c=["CookiebotOnAccept","CookiebotOnDecline"],a=async e=>{var t,o,n,r,i;const{config:l,env:a}=e,{elb:u}=a,v=null!=(t=a.window)?t:void 0!==globalThis.window?globalThis.window:void 0,d={...s,...null!=(n=null==(o=null==l?void 0:l.settings)?void 0:o.categoryMap)?n:{}},f={};Object.entries(d).forEach(([e,t])=>{f[e.toLowerCase()]=t});const b={categoryMap:d,explicitOnly:null==(i=null==(r=null==l?void 0:l.settings)?void 0:r.explicitOnly)||i};let p,y;const O=()=>{var e,t;const o=null==(e=null==v?void 0:v.Cookiebot)?void 0:e.consent,n=null==(t=null==o?void 0:o.method)?void 0:t.toLowerCase();if(!o||!n)return;if(b.explicitOnly&&"explicit"!==n)return;const r=(e=>{const t={};return Object.entries(e).forEach(([e,o])=>{var n;if("boolean"!=typeof o)return;const r=null!=(n=f[e.toLowerCase()])?n:e;t[r]=(void 0===t[r]||t[r])&&o}),t})(o);if(0===Object.keys(r).length)return;const i=JSON.stringify(Object.entries(r).sort());i!==y&&(y=i,u("walker consent",r))};return{type:"cookiebot",config:{settings:b},push:u,init:async()=>{var e;if(!v)return;(null==(e=v.Cookiebot)?void 0:e.hasResponse)&&O();const t=()=>O();p=t,c.forEach(e=>v.addEventListener(e,t))},destroy:async e=>{const t=p;v&&t&&(c.forEach(e=>v.removeEventListener(e,t)),p=void 0)}}},u=a;//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { Source, WalkerOS } from '@walkeros/core';\nimport type {\n Types,\n Settings,\n CookiebotConsent,\n CookiebotWindow,\n} from './types';\n\n// Export types for external usage\nexport * as SourceCookiebot from './types';\n\n/**\n * Default category mapping from Cookiebot to walkerOS consent groups.\n *\n * - preferences -> functional\n * - statistics -> analytics\n * - marketing -> marketing\n *\n * `necessary` has no entry and keeps its own name: Cookiebot always grants\n * it, so mapping it to functional would grant functional with every choice.\n */\nexport const DEFAULT_CATEGORY_MAP: Record<string, string> = {\n preferences: 'functional',\n statistics: 'analytics',\n marketing: 'marketing',\n};\n\n/**\n * Cookiebot's window events for a decision. uc.js fires one of them on every\n * page load with a stored choice and again after each new choice or\n * withdrawal. Its `CookieConsentOn*` aliases and `CookiebotOnConsentReady`,\n * which fires before Cookiebot's version check, are left out.\n */\nconst DECISION_EVENTS = ['CookiebotOnAccept', 'CookiebotOnDecline'];\n\n/**\n * Cookiebot consent management source for walkerOS.\n *\n * This source reads Cookiebot's consent and translates it to walkerOS\n * consent commands.\n *\n * Two detection paths:\n * 1. Already loaded: window.Cookiebot with a response\n * 2. Decision: CookiebotOnAccept and CookiebotOnDecline window events\n *\n * @example\n * ```typescript\n * import { sourceCookiebot } from '@walkeros/web-source-cmp-cookiebot';\n *\n * await startFlow({\n * sources: {\n * consent: {\n * code: sourceCookiebot,\n * config: {\n * settings: {\n * categoryMap: {\n * statistics: 'statistics', // Custom mapping\n * },\n * },\n * },\n * },\n * },\n * });\n * ```\n */\nexport const sourceCookiebot: Source.Init<Types> = async (context) => {\n const { config, env } = context;\n const { elb } = env;\n\n // Resolve window with fallback to globalThis\n const actualWindow: CookiebotWindow | undefined =\n env.window ??\n (typeof globalThis.window !== 'undefined' ? globalThis.window : undefined);\n\n // Merge user settings with defaults (user overrides win)\n const mergedCategoryMap = {\n ...DEFAULT_CATEGORY_MAP,\n ...(config?.settings?.categoryMap ?? {}),\n };\n\n // Build normalized (lowercase) lookup map for case-insensitive matching\n const normalizedMap: Record<string, string> = {};\n Object.entries(mergedCategoryMap).forEach(([key, value]) => {\n normalizedMap[key.toLowerCase()] = value;\n });\n\n const settings: Settings = {\n categoryMap: mergedCategoryMap, // Preserves original casing for config\n explicitOnly: config?.settings?.explicitOnly ?? true,\n };\n\n const fullConfig: Source.Config<Types> = { settings };\n\n // Track the listener for cleanup\n let decisionListener: (() => void) | undefined;\n // The last state sent, so a repeated signal for the same choice is dropped\n let lastState: string | undefined;\n\n /**\n * Map Cookiebot categories to walkerOS consent groups. When several\n * categories map to the same group, any deny denies: the group is true only\n * if every one of them is true. Non-boolean fields (method, stamp) are\n * skipped.\n */\n const toState = (consent: CookiebotConsent): WalkerOS.Consent => {\n const state: WalkerOS.Consent = {};\n Object.entries(consent).forEach(([category, value]) => {\n if (typeof value !== 'boolean') return;\n const mapped = normalizedMap[category.toLowerCase()] ?? category;\n // Any deny denies: once false, stays false\n state[mapped] =\n state[mapped] === undefined ? value : state[mapped] && value;\n });\n return state;\n };\n\n /**\n * Read window.Cookiebot.consent and publish it as a walker consent command.\n * A consent without method is no consent. With explicitOnly, only an\n * explicit method is published.\n */\n const handleConsent = () => {\n const consent = actualWindow?.Cookiebot?.consent;\n const method = consent?.method?.toLowerCase();\n if (!consent || !method) return;\n if (settings.explicitOnly && method !== 'explicit') return;\n\n const state = toState(consent);\n if (Object.keys(state).length === 0) return;\n\n // Cookiebot fires a decision event on every page load with a stored\n // choice, so a static read and that event report the same state twice.\n const key = JSON.stringify(Object.entries(state).sort());\n if (key === lastState) return;\n lastState = key;\n\n elb('walker consent', state);\n };\n\n // Attach the listener and perform the static consent read. Deferred to\n // init() (Pass 2 of initSources) so the factory (Pass 1) stays side-effect\n // free: no listener registration and no `elb('walker consent')` emit during\n // construction.\n const init = async (): Promise<void> => {\n if (!actualWindow) return;\n\n // --- Detection path 1: Already loaded ---\n if (actualWindow.Cookiebot?.hasResponse) handleConsent();\n\n // --- Detection path 2: Decision events ---\n const onDecision = () => handleConsent();\n decisionListener = onDecision;\n DECISION_EVENTS.forEach((name) =>\n actualWindow.addEventListener(name, onDecision),\n );\n };\n\n return {\n type: 'cookiebot',\n config: fullConfig,\n push: elb,\n init,\n destroy: async (_context) => {\n const listener = decisionListener;\n if (!actualWindow || !listener) return;\n DECISION_EVENTS.forEach((name) =>\n actualWindow.removeEventListener(name, listener),\n );\n decisionListener = undefined;\n },\n };\n};\n\nexport default sourceCookiebot;\n","import type { Source, Elb } from '@walkeros/core';\n\ndeclare module '@walkeros/core' {\n interface SourceMap {\n cookiebot: { type: 'cookiebot'; platform?: 'web' };\n }\n}\n\n/**\n * Cookiebot consent object (`window.Cookiebot.consent`).\n *\n * The four categories are booleans Cookiebot always sets. `method` is\n * `'explicit'` when the visitor actively decided, `'implied'` when Cookiebot\n * consented on its own (outside a region that requires consent, an implied\n * banner, or an old consent of unknown method) and `null` without consent.\n */\nexport interface CookiebotConsent {\n necessary?: boolean;\n preferences?: boolean;\n statistics?: boolean;\n marketing?: boolean;\n method?: string | null;\n stamp?: string;\n [category: string]: boolean | string | null | undefined;\n}\n\n/**\n * The subset of the Cookiebot SDK (`window.Cookiebot`) the source reads.\n */\nexport interface CookiebotAPI {\n consent: CookiebotConsent;\n /** The visitor accepted at least one category. */\n consented?: boolean;\n /** The visitor declined. */\n declined?: boolean;\n /** The visitor answered the banner, or Cookiebot consented for them. */\n hasResponse?: boolean;\n}\n\n/**\n * Window surface the source touches: the Cookiebot global and event\n * registration. Narrowed instead of the global `Window`, so the package adds\n * no global declarations that could clash with `@types/cookiebot-sdk`, and\n * test mocks satisfy it without a cast.\n */\nexport interface CookiebotWindow {\n Cookiebot?: CookiebotAPI;\n addEventListener(type: string, listener: EventListener): void;\n removeEventListener(type: string, listener: EventListener): void;\n}\n\n/**\n * Settings for the Cookiebot source\n */\nexport interface Settings {\n /**\n * Map Cookiebot categories to walkerOS consent groups.\n * Keys: Cookiebot categories (necessary, preferences, statistics, marketing)\n * Values: walkerOS consent group names\n *\n * Comparison is case-insensitive. Categories without an entry pass through\n * under their own name, `necessary` among them by default.\n *\n * Default:\n * - preferences -> functional\n * - statistics -> analytics\n * - marketing -> marketing\n */\n categoryMap?: Record<string, string>;\n\n /**\n * Only process consent the visitor actively gave (`consent.method` is\n * `'explicit'`). Implied consent, which Cookiebot sets on its own, is\n * skipped.\n *\n * Default: true\n */\n explicitOnly?: boolean;\n}\n\n/**\n * User input settings (all optional)\n */\nexport type InitSettings = Partial<Settings>;\n\n/**\n * No mapping configuration for this source\n */\nexport interface Mapping {}\n\n/**\n * Push function type - uses elb for consent commands\n */\nexport type Push = Elb.Fn;\n\n/**\n * Environment interface for the Cookiebot source\n */\nexport interface Env extends Source.BaseEnv {\n window?: CookiebotWindow;\n}\n\n/**\n * Types bundle for the Cookiebot source\n */\nexport type Types = Source.Types<Settings, Mapping, Push, Env, InitSettings>;\n\n/**\n * Config type alias\n */\nexport type Config = Source.Config<Types>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;;;ADqBO,IAAM,uBAA+C;AAAA,EAC1D,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,WAAW;AACb;AAQA,IAAM,kBAAkB,CAAC,qBAAqB,oBAAoB;AAgC3D,IAAM,kBAAsC,OAAO,YAAY;AAjEtE;AAkEE,QAAM,EAAE,QAAQ,IAAI,IAAI;AACxB,QAAM,EAAE,IAAI,IAAI;AAGhB,QAAM,gBACJ,SAAI,WAAJ,YACC,OAAO,WAAW,WAAW,cAAc,WAAW,SAAS;AAGlE,QAAM,oBAAoB;AAAA,IACxB,GAAG;AAAA,IACH,IAAI,4CAAQ,aAAR,mBAAkB,gBAAlB,YAAiC,CAAC;AAAA,EACxC;AAGA,QAAM,gBAAwC,CAAC;AAC/C,SAAO,QAAQ,iBAAiB,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC1D,kBAAc,IAAI,YAAY,CAAC,IAAI;AAAA,EACrC,CAAC;AAED,QAAM,WAAqB;AAAA,IACzB,aAAa;AAAA;AAAA,IACb,eAAc,4CAAQ,aAAR,mBAAkB,iBAAlB,YAAkC;AAAA,EAClD;AAEA,QAAM,aAAmC,EAAE,SAAS;AAGpD,MAAI;AAEJ,MAAI;AAQJ,QAAM,UAAU,CAAC,YAAgD;AAC/D,UAAM,QAA0B,CAAC;AACjC,WAAO,QAAQ,OAAO,EAAE,QAAQ,CAAC,CAAC,UAAU,KAAK,MAAM;AA1G3D,UAAAA;AA2GM,UAAI,OAAO,UAAU,UAAW;AAChC,YAAM,UAASA,MAAA,cAAc,SAAS,YAAY,CAAC,MAApC,OAAAA,MAAyC;AAExD,YAAM,MAAM,IACV,MAAM,MAAM,MAAM,SAAY,QAAQ,MAAM,MAAM,KAAK;AAAA,IAC3D,CAAC;AACD,WAAO;AAAA,EACT;AAOA,QAAM,gBAAgB,MAAM;AAzH9B,QAAAA,KAAAC;AA0HI,UAAM,WAAUD,MAAA,6CAAc,cAAd,gBAAAA,IAAyB;AACzC,UAAM,UAASC,MAAA,mCAAS,WAAT,gBAAAA,IAAiB;AAChC,QAAI,CAAC,WAAW,CAAC,OAAQ;AACzB,QAAI,SAAS,gBAAgB,WAAW,WAAY;AAEpD,UAAM,QAAQ,QAAQ,OAAO;AAC7B,QAAI,OAAO,KAAK,KAAK,EAAE,WAAW,EAAG;AAIrC,UAAM,MAAM,KAAK,UAAU,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC;AACvD,QAAI,QAAQ,UAAW;AACvB,gBAAY;AAEZ,QAAI,kBAAkB,KAAK;AAAA,EAC7B;AAMA,QAAM,OAAO,YAA2B;AA/I1C,QAAAD;AAgJI,QAAI,CAAC,aAAc;AAGnB,SAAIA,MAAA,aAAa,cAAb,gBAAAA,IAAwB,YAAa,eAAc;AAGvD,UAAM,aAAa,MAAM,cAAc;AACvC,uBAAmB;AACnB,oBAAgB;AAAA,MAAQ,CAAC,SACvB,aAAa,iBAAiB,MAAM,UAAU;AAAA,IAChD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,MAAM;AAAA,IACN;AAAA,IACA,SAAS,OAAO,aAAa;AAC3B,YAAM,WAAW;AACjB,UAAI,CAAC,gBAAgB,CAAC,SAAU;AAChC,sBAAgB;AAAA,QAAQ,CAAC,SACvB,aAAa,oBAAoB,MAAM,QAAQ;AAAA,MACjD;AACA,yBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["_a","_b"]}
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var e={},o={preferences:"functional",statistics:"analytics",marketing:"marketing"},n=["CookiebotOnAccept","CookiebotOnDecline"],t=async e=>{var t,i,l,s,r;const{config:c,env:a}=e,{elb:u}=a,v=null!=(t=a.window)?t:void 0!==globalThis.window?globalThis.window:void 0,d={...o,...null!=(l=null==(i=null==c?void 0:c.settings)?void 0:i.categoryMap)?l:{}},f={};Object.entries(d).forEach(([e,o])=>{f[e.toLowerCase()]=o});const b={categoryMap:d,explicitOnly:null==(r=null==(s=null==c?void 0:c.settings)?void 0:s.explicitOnly)||r};let y,g;const p=()=>{var e,o;const n=null==(e=null==v?void 0:v.Cookiebot)?void 0:e.consent,t=null==(o=null==n?void 0:n.method)?void 0:o.toLowerCase();if(!n||!t)return;if(b.explicitOnly&&"explicit"!==t)return;const i=(e=>{const o={};return Object.entries(e).forEach(([e,n])=>{var t;if("boolean"!=typeof n)return;const i=null!=(t=f[e.toLowerCase()])?t:e;o[i]=(void 0===o[i]||o[i])&&n}),o})(n);if(0===Object.keys(i).length)return;const l=JSON.stringify(Object.entries(i).sort());l!==g&&(g=l,u("walker consent",i))};return{type:"cookiebot",config:{settings:b},push:u,init:async()=>{var e;if(!v)return;(null==(e=v.Cookiebot)?void 0:e.hasResponse)&&p();const o=()=>p();y=o,n.forEach(e=>v.addEventListener(e,o))},destroy:async e=>{const o=y;v&&o&&(n.forEach(e=>v.removeEventListener(e,o)),y=void 0)}}},i=t;export{o as DEFAULT_CATEGORY_MAP,e as SourceCookiebot,i as default,t as sourceCookiebot};//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Source, Elb } from '@walkeros/core';\n\ndeclare module '@walkeros/core' {\n interface SourceMap {\n cookiebot: { type: 'cookiebot'; platform?: 'web' };\n }\n}\n\n/**\n * Cookiebot consent object (`window.Cookiebot.consent`).\n *\n * The four categories are booleans Cookiebot always sets. `method` is\n * `'explicit'` when the visitor actively decided, `'implied'` when Cookiebot\n * consented on its own (outside a region that requires consent, an implied\n * banner, or an old consent of unknown method) and `null` without consent.\n */\nexport interface CookiebotConsent {\n necessary?: boolean;\n preferences?: boolean;\n statistics?: boolean;\n marketing?: boolean;\n method?: string | null;\n stamp?: string;\n [category: string]: boolean | string | null | undefined;\n}\n\n/**\n * The subset of the Cookiebot SDK (`window.Cookiebot`) the source reads.\n */\nexport interface CookiebotAPI {\n consent: CookiebotConsent;\n /** The visitor accepted at least one category. */\n consented?: boolean;\n /** The visitor declined. */\n declined?: boolean;\n /** The visitor answered the banner, or Cookiebot consented for them. */\n hasResponse?: boolean;\n}\n\n/**\n * Window surface the source touches: the Cookiebot global and event\n * registration. Narrowed instead of the global `Window`, so the package adds\n * no global declarations that could clash with `@types/cookiebot-sdk`, and\n * test mocks satisfy it without a cast.\n */\nexport interface CookiebotWindow {\n Cookiebot?: CookiebotAPI;\n addEventListener(type: string, listener: EventListener): void;\n removeEventListener(type: string, listener: EventListener): void;\n}\n\n/**\n * Settings for the Cookiebot source\n */\nexport interface Settings {\n /**\n * Map Cookiebot categories to walkerOS consent groups.\n * Keys: Cookiebot categories (necessary, preferences, statistics, marketing)\n * Values: walkerOS consent group names\n *\n * Comparison is case-insensitive. Categories without an entry pass through\n * under their own name, `necessary` among them by default.\n *\n * Default:\n * - preferences -> functional\n * - statistics -> analytics\n * - marketing -> marketing\n */\n categoryMap?: Record<string, string>;\n\n /**\n * Only process consent the visitor actively gave (`consent.method` is\n * `'explicit'`). Implied consent, which Cookiebot sets on its own, is\n * skipped.\n *\n * Default: true\n */\n explicitOnly?: boolean;\n}\n\n/**\n * User input settings (all optional)\n */\nexport type InitSettings = Partial<Settings>;\n\n/**\n * No mapping configuration for this source\n */\nexport interface Mapping {}\n\n/**\n * Push function type - uses elb for consent commands\n */\nexport type Push = Elb.Fn;\n\n/**\n * Environment interface for the Cookiebot source\n */\nexport interface Env extends Source.BaseEnv {\n window?: CookiebotWindow;\n}\n\n/**\n * Types bundle for the Cookiebot source\n */\nexport type Types = Source.Types<Settings, Mapping, Push, Env, InitSettings>;\n\n/**\n * Config type alias\n */\nexport type Config = Source.Config<Types>;\n","import type { Source, WalkerOS } from '@walkeros/core';\nimport type {\n Types,\n Settings,\n CookiebotConsent,\n CookiebotWindow,\n} from './types';\n\n// Export types for external usage\nexport * as SourceCookiebot from './types';\n\n/**\n * Default category mapping from Cookiebot to walkerOS consent groups.\n *\n * - preferences -> functional\n * - statistics -> analytics\n * - marketing -> marketing\n *\n * `necessary` has no entry and keeps its own name: Cookiebot always grants\n * it, so mapping it to functional would grant functional with every choice.\n */\nexport const DEFAULT_CATEGORY_MAP: Record<string, string> = {\n preferences: 'functional',\n statistics: 'analytics',\n marketing: 'marketing',\n};\n\n/**\n * Cookiebot's window events for a decision. uc.js fires one of them on every\n * page load with a stored choice and again after each new choice or\n * withdrawal. Its `CookieConsentOn*` aliases and `CookiebotOnConsentReady`,\n * which fires before Cookiebot's version check, are left out.\n */\nconst DECISION_EVENTS = ['CookiebotOnAccept', 'CookiebotOnDecline'];\n\n/**\n * Cookiebot consent management source for walkerOS.\n *\n * This source reads Cookiebot's consent and translates it to walkerOS\n * consent commands.\n *\n * Two detection paths:\n * 1. Already loaded: window.Cookiebot with a response\n * 2. Decision: CookiebotOnAccept and CookiebotOnDecline window events\n *\n * @example\n * ```typescript\n * import { sourceCookiebot } from '@walkeros/web-source-cmp-cookiebot';\n *\n * await startFlow({\n * sources: {\n * consent: {\n * code: sourceCookiebot,\n * config: {\n * settings: {\n * categoryMap: {\n * statistics: 'statistics', // Custom mapping\n * },\n * },\n * },\n * },\n * },\n * });\n * ```\n */\nexport const sourceCookiebot: Source.Init<Types> = async (context) => {\n const { config, env } = context;\n const { elb } = env;\n\n // Resolve window with fallback to globalThis\n const actualWindow: CookiebotWindow | undefined =\n env.window ??\n (typeof globalThis.window !== 'undefined' ? globalThis.window : undefined);\n\n // Merge user settings with defaults (user overrides win)\n const mergedCategoryMap = {\n ...DEFAULT_CATEGORY_MAP,\n ...(config?.settings?.categoryMap ?? {}),\n };\n\n // Build normalized (lowercase) lookup map for case-insensitive matching\n const normalizedMap: Record<string, string> = {};\n Object.entries(mergedCategoryMap).forEach(([key, value]) => {\n normalizedMap[key.toLowerCase()] = value;\n });\n\n const settings: Settings = {\n categoryMap: mergedCategoryMap, // Preserves original casing for config\n explicitOnly: config?.settings?.explicitOnly ?? true,\n };\n\n const fullConfig: Source.Config<Types> = { settings };\n\n // Track the listener for cleanup\n let decisionListener: (() => void) | undefined;\n // The last state sent, so a repeated signal for the same choice is dropped\n let lastState: string | undefined;\n\n /**\n * Map Cookiebot categories to walkerOS consent groups. When several\n * categories map to the same group, any deny denies: the group is true only\n * if every one of them is true. Non-boolean fields (method, stamp) are\n * skipped.\n */\n const toState = (consent: CookiebotConsent): WalkerOS.Consent => {\n const state: WalkerOS.Consent = {};\n Object.entries(consent).forEach(([category, value]) => {\n if (typeof value !== 'boolean') return;\n const mapped = normalizedMap[category.toLowerCase()] ?? category;\n // Any deny denies: once false, stays false\n state[mapped] =\n state[mapped] === undefined ? value : state[mapped] && value;\n });\n return state;\n };\n\n /**\n * Read window.Cookiebot.consent and publish it as a walker consent command.\n * A consent without method is no consent. With explicitOnly, only an\n * explicit method is published.\n */\n const handleConsent = () => {\n const consent = actualWindow?.Cookiebot?.consent;\n const method = consent?.method?.toLowerCase();\n if (!consent || !method) return;\n if (settings.explicitOnly && method !== 'explicit') return;\n\n const state = toState(consent);\n if (Object.keys(state).length === 0) return;\n\n // Cookiebot fires a decision event on every page load with a stored\n // choice, so a static read and that event report the same state twice.\n const key = JSON.stringify(Object.entries(state).sort());\n if (key === lastState) return;\n lastState = key;\n\n elb('walker consent', state);\n };\n\n // Attach the listener and perform the static consent read. Deferred to\n // init() (Pass 2 of initSources) so the factory (Pass 1) stays side-effect\n // free: no listener registration and no `elb('walker consent')` emit during\n // construction.\n const init = async (): Promise<void> => {\n if (!actualWindow) return;\n\n // --- Detection path 1: Already loaded ---\n if (actualWindow.Cookiebot?.hasResponse) handleConsent();\n\n // --- Detection path 2: Decision events ---\n const onDecision = () => handleConsent();\n decisionListener = onDecision;\n DECISION_EVENTS.forEach((name) =>\n actualWindow.addEventListener(name, onDecision),\n );\n };\n\n return {\n type: 'cookiebot',\n config: fullConfig,\n push: elb,\n init,\n destroy: async (_context) => {\n const listener = decisionListener;\n if (!actualWindow || !listener) return;\n DECISION_EVENTS.forEach((name) =>\n actualWindow.removeEventListener(name, listener),\n );\n decisionListener = undefined;\n },\n };\n};\n\nexport default sourceCookiebot;\n"],"mappings":";AAAA;;;ACqBO,IAAM,uBAA+C;AAAA,EAC1D,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,WAAW;AACb;AAQA,IAAM,kBAAkB,CAAC,qBAAqB,oBAAoB;AAgC3D,IAAM,kBAAsC,OAAO,YAAY;AAjEtE;AAkEE,QAAM,EAAE,QAAQ,IAAI,IAAI;AACxB,QAAM,EAAE,IAAI,IAAI;AAGhB,QAAM,gBACJ,SAAI,WAAJ,YACC,OAAO,WAAW,WAAW,cAAc,WAAW,SAAS;AAGlE,QAAM,oBAAoB;AAAA,IACxB,GAAG;AAAA,IACH,IAAI,4CAAQ,aAAR,mBAAkB,gBAAlB,YAAiC,CAAC;AAAA,EACxC;AAGA,QAAM,gBAAwC,CAAC;AAC/C,SAAO,QAAQ,iBAAiB,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC1D,kBAAc,IAAI,YAAY,CAAC,IAAI;AAAA,EACrC,CAAC;AAED,QAAM,WAAqB;AAAA,IACzB,aAAa;AAAA;AAAA,IACb,eAAc,4CAAQ,aAAR,mBAAkB,iBAAlB,YAAkC;AAAA,EAClD;AAEA,QAAM,aAAmC,EAAE,SAAS;AAGpD,MAAI;AAEJ,MAAI;AAQJ,QAAM,UAAU,CAAC,YAAgD;AAC/D,UAAM,QAA0B,CAAC;AACjC,WAAO,QAAQ,OAAO,EAAE,QAAQ,CAAC,CAAC,UAAU,KAAK,MAAM;AA1G3D,UAAAA;AA2GM,UAAI,OAAO,UAAU,UAAW;AAChC,YAAM,UAASA,MAAA,cAAc,SAAS,YAAY,CAAC,MAApC,OAAAA,MAAyC;AAExD,YAAM,MAAM,IACV,MAAM,MAAM,MAAM,SAAY,QAAQ,MAAM,MAAM,KAAK;AAAA,IAC3D,CAAC;AACD,WAAO;AAAA,EACT;AAOA,QAAM,gBAAgB,MAAM;AAzH9B,QAAAA,KAAAC;AA0HI,UAAM,WAAUD,MAAA,6CAAc,cAAd,gBAAAA,IAAyB;AACzC,UAAM,UAASC,MAAA,mCAAS,WAAT,gBAAAA,IAAiB;AAChC,QAAI,CAAC,WAAW,CAAC,OAAQ;AACzB,QAAI,SAAS,gBAAgB,WAAW,WAAY;AAEpD,UAAM,QAAQ,QAAQ,OAAO;AAC7B,QAAI,OAAO,KAAK,KAAK,EAAE,WAAW,EAAG;AAIrC,UAAM,MAAM,KAAK,UAAU,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC;AACvD,QAAI,QAAQ,UAAW;AACvB,gBAAY;AAEZ,QAAI,kBAAkB,KAAK;AAAA,EAC7B;AAMA,QAAM,OAAO,YAA2B;AA/I1C,QAAAD;AAgJI,QAAI,CAAC,aAAc;AAGnB,SAAIA,MAAA,aAAa,cAAb,gBAAAA,IAAwB,YAAa,eAAc;AAGvD,UAAM,aAAa,MAAM,cAAc;AACvC,uBAAmB;AACnB,oBAAgB;AAAA,MAAQ,CAAC,SACvB,aAAa,iBAAiB,MAAM,UAAU;AAAA,IAChD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,MAAM;AAAA,IACN;AAAA,IACA,SAAS,OAAO,aAAa;AAC3B,YAAM,WAAW;AACjB,UAAI,CAAC,gBAAgB,CAAC,SAAU;AAChC,sBAAgB;AAAA,QAAQ,CAAC,SACvB,aAAa,oBAAoB,MAAM,QAAQ;AAAA,MACjD;AACA,yBAAmB;AAAA,IACrB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["_a","_b"]}