@ecomconsult/consentkit 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -16
- package/npm/core.cjs +1 -1
- package/npm/core.mjs +4 -1
- package/npm/index.cjs +5 -2
- package/npm/index.d.ts +68 -0
- package/npm/index.mjs +14 -2
- package/npm/internal-stub.mjs +7 -1
- package/package.json +1 -1
- package/src/ck-core.js +488 -29
- package/src/ck-debug-loader.js +134 -0
- package/src/ck-debug.js +862 -0
- package/src/ck-saas.js +36 -1
- package/src/ck-ui-branding.js +511 -0
- package/src/ck-ui.js +43 -416
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ConsentKit debug loader — the activation switch for the debug panel.
|
|
3
|
+
*
|
|
4
|
+
* The panel itself (src/ck-debug.js) is ~30 KB and useful to exactly one
|
|
5
|
+
* person on the page: the site owner, once, while diagnosing something. This
|
|
6
|
+
* loader ships instead of it in the inline blocks and in the WordPress plugin,
|
|
7
|
+
* and fetches the panel only when the visitor asks for it. Without activation
|
|
8
|
+
* it creates no DOM, installs no observers and makes no network request.
|
|
9
|
+
*
|
|
10
|
+
* Activation (?ck_debug=1 / #ck_debug / localStorage) and the three-step
|
|
11
|
+
* resolution order for the panel URL are documented in README «Debug mode».
|
|
12
|
+
* Two things are worth knowing while reading this file:
|
|
13
|
+
*
|
|
14
|
+
* - The off switch has to work even though the panel is not loaded, so the
|
|
15
|
+
* loader — not the panel — owns the stored flag. ck-debug.js keeps its own
|
|
16
|
+
* identical copy of parseActivation() because it is loaded directly on our
|
|
17
|
+
* demo page and must stay self-contained; writing the flag twice is
|
|
18
|
+
* idempotent, and test/debug-loader.test.mjs asserts the two agree.
|
|
19
|
+
* - Nothing here runs before activation. No DOM, no request, no observers.
|
|
20
|
+
*
|
|
21
|
+
* Load order: ck-core.js -> ck-locales.js -> ck-ui.js -> [ck-saas.js] -> this.
|
|
22
|
+
*
|
|
23
|
+
* Copyright (c) 2026 E-COM CONSULT PLUS. MIT License — see LICENSE.
|
|
24
|
+
*/
|
|
25
|
+
(function (global) {
|
|
26
|
+
'use strict';
|
|
27
|
+
|
|
28
|
+
if (!global || typeof global !== 'object') { return; }
|
|
29
|
+
|
|
30
|
+
var LS_KEY = 'ck_debug';
|
|
31
|
+
var CDN = 'https://cdn.jsdelivr.net/npm/@ecomconsult/consentkit@';
|
|
32
|
+
|
|
33
|
+
function isOffValue(v) {
|
|
34
|
+
return v === '0' || v === 'false' || v === 'no' || v === '';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Identical to src/ck-debug.js parseActivation(). Pure: no DOM, no storage.
|
|
38
|
+
function parseActivation(search, hash, stored) {
|
|
39
|
+
var on = null;
|
|
40
|
+
|
|
41
|
+
var q = String(search || '');
|
|
42
|
+
if (q.charAt(0) === '?') { q = q.slice(1); }
|
|
43
|
+
var pairs = q ? q.split('&') : [];
|
|
44
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
45
|
+
var eq = pairs[i].indexOf('=');
|
|
46
|
+
var k = eq === -1 ? pairs[i] : pairs[i].slice(0, eq);
|
|
47
|
+
if (k !== LS_KEY) { continue; }
|
|
48
|
+
on = eq === -1 ? true : !isOffValue(pairs[i].slice(eq + 1));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (on === null) {
|
|
52
|
+
var h = String(hash || '');
|
|
53
|
+
if (h.charAt(0) === '#') { h = h.slice(1); }
|
|
54
|
+
if (h === LS_KEY) { on = true; }
|
|
55
|
+
else if (h.indexOf(LS_KEY + '=') === 0) { on = !isOffValue(h.slice(LS_KEY.length + 1)); }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (on === null) {
|
|
59
|
+
return { active: String(stored || '') === '1', persist: null };
|
|
60
|
+
}
|
|
61
|
+
return { active: on, persist: on ? 'on' : 'off' };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Pure: takes what the page happens to expose, returns the URL to load.
|
|
65
|
+
// `explicit` is window.ConsentKitDebugUrl, `saas` is ConsentKit._saas.
|
|
66
|
+
// Order: explicit URL -> SaaS API origin -> jsDelivr pinned to the running
|
|
67
|
+
// core version. See README «Debug mode».
|
|
68
|
+
function resolveUrl(explicit, saas, version) {
|
|
69
|
+
var pinned = String(explicit || '').trim();
|
|
70
|
+
if (pinned) { return pinned; }
|
|
71
|
+
|
|
72
|
+
if (saas && saas.siteId && saas.api) {
|
|
73
|
+
var base = String(saas.api).replace(/\/+$/, '');
|
|
74
|
+
if (base) { return base + '/client/ck-debug.js'; }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return CDN + encodeURIComponent(String(version || 'latest')) + '/src/ck-debug.js';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var API = {
|
|
81
|
+
parseActivation: parseActivation,
|
|
82
|
+
resolveUrl: resolveUrl,
|
|
83
|
+
active: false,
|
|
84
|
+
url: null
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
if (global.ConsentKit) { global.ConsentKit._debugLoader = API; }
|
|
88
|
+
global.__ckDebugLoader = API;
|
|
89
|
+
} catch (e) { /* noop */ }
|
|
90
|
+
|
|
91
|
+
function lsGet(k) {
|
|
92
|
+
try { return global.localStorage ? global.localStorage.getItem(k) : null; } catch (e) { return null; }
|
|
93
|
+
}
|
|
94
|
+
function lsSet(k, v) {
|
|
95
|
+
try { if (global.localStorage) { global.localStorage.setItem(k, v); } } catch (e) { /* noop */ }
|
|
96
|
+
}
|
|
97
|
+
function lsDel(k) {
|
|
98
|
+
try { if (global.localStorage) { global.localStorage.removeItem(k); } } catch (e) { /* noop */ }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var loc = global.location;
|
|
102
|
+
var act = parseActivation(loc && loc.search, loc && loc.hash, lsGet(LS_KEY));
|
|
103
|
+
// Persist BEFORE the early return: ?ck_debug=0 has to clear the stored flag
|
|
104
|
+
// even though nothing is loaded afterwards, or the panel could never be
|
|
105
|
+
// switched off again once it had been switched on.
|
|
106
|
+
if (act.persist === 'on') { lsSet(LS_KEY, '1'); }
|
|
107
|
+
if (act.persist === 'off') { lsDel(LS_KEY); }
|
|
108
|
+
if (!act.active) { return; }
|
|
109
|
+
|
|
110
|
+
var doc = global.document;
|
|
111
|
+
if (!doc || typeof doc.createElement !== 'function') { return; }
|
|
112
|
+
|
|
113
|
+
// Already loaded (the panel published its surface, or this ran twice).
|
|
114
|
+
if (global.__ckDebug) { API.active = true; return; }
|
|
115
|
+
|
|
116
|
+
var CK = global.ConsentKit;
|
|
117
|
+
var url = resolveUrl(
|
|
118
|
+
global.ConsentKitDebugUrl,
|
|
119
|
+
CK && CK._saas,
|
|
120
|
+
(CK && CK.version) || ''
|
|
121
|
+
);
|
|
122
|
+
API.active = true;
|
|
123
|
+
API.url = url;
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
var s = doc.createElement('script');
|
|
127
|
+
s.src = url;
|
|
128
|
+
s.async = true;
|
|
129
|
+
// No opt-out attribute is needed: the blocking engine matches a fixed list
|
|
130
|
+
// of tracker hosts, and neither jsDelivr nor a ConsentKit API host is on
|
|
131
|
+
// it — test/debug-loader.test.mjs asserts that.
|
|
132
|
+
(doc.head || doc.body || doc.documentElement).appendChild(s);
|
|
133
|
+
} catch (e) { /* noop */ }
|
|
134
|
+
})(typeof window !== 'undefined' ? window : (typeof globalThis !== 'undefined' ? globalThis : this));
|