@owlmeans/consent 0.1.18-rc.9 → 0.1.18
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 +229 -0
- package/build/consts.d.ts +78 -3
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +104 -0
- package/build/consts.js.map +1 -1
- package/build/consts.local.d.ts +12 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +12 -0
- package/build/consts.local.js.map +1 -0
- package/build/geo/types.d.ts +47 -0
- package/build/geo/types.d.ts.map +1 -0
- package/build/geo/types.js +2 -0
- package/build/geo/types.js.map +1 -0
- package/build/geo.d.ts +4 -0
- package/build/geo.d.ts.map +1 -0
- package/build/geo.js +96 -0
- package/build/geo.js.map +1 -0
- package/build/gtobserver/types.d.ts +75 -0
- package/build/gtobserver/types.d.ts.map +1 -0
- package/build/gtobserver/types.js +2 -0
- package/build/gtobserver/types.js.map +1 -0
- package/build/gtobserver.d.ts +7 -0
- package/build/gtobserver.d.ts.map +1 -0
- package/build/gtobserver.js +142 -0
- package/build/gtobserver.js.map +1 -0
- package/build/i18n/be.json +8 -1
- package/build/i18n/de.json +8 -1
- package/build/i18n/en.json +8 -1
- package/build/i18n/es.json +8 -1
- package/build/i18n/fr.json +8 -1
- package/build/i18n/pl.json +8 -1
- package/build/i18n/ru.json +8 -1
- package/build/i18n/types.d.ts +11 -0
- package/build/i18n/types.d.ts.map +1 -0
- package/build/i18n/types.js +2 -0
- package/build/i18n/types.js.map +1 -0
- package/build/i18n/uk.json +8 -1
- package/build/i18n.d.ts +4 -14
- package/build/i18n.d.ts.map +1 -1
- package/build/i18n.js +12 -27
- package/build/i18n.js.map +1 -1
- package/build/index.d.ts +13 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -3
- package/build/index.js.map +1 -1
- package/build/linker/types.d.ts +59 -0
- package/build/linker/types.d.ts.map +1 -0
- package/build/linker/types.js +2 -0
- package/build/linker/types.js.map +1 -0
- package/build/linker.d.ts +5 -74
- package/build/linker.d.ts.map +1 -1
- package/build/linker.js +290 -324
- package/build/linker.js.map +1 -1
- package/build/plugins/types.d.ts +42 -0
- package/build/plugins/types.d.ts.map +1 -0
- package/build/plugins/types.js +2 -0
- package/build/plugins/types.js.map +1 -0
- package/build/plugins.d.ts +4 -68
- package/build/plugins.d.ts.map +1 -1
- package/build/plugins.js +73 -61
- package/build/plugins.js.map +1 -1
- package/build/storage/types.d.ts +31 -0
- package/build/storage/types.d.ts.map +1 -0
- package/build/storage/types.js +2 -0
- package/build/storage/types.js.map +1 -0
- package/build/storage.d.ts +6 -22
- package/build/storage.d.ts.map +1 -1
- package/build/storage.js +72 -81
- package/build/storage.js.map +1 -1
- package/build/store.d.ts +2 -2
- package/build/store.d.ts.map +1 -1
- package/build/store.js +115 -31
- package/build/store.js.map +1 -1
- package/build/types.d.ts +141 -5
- package/build/types.d.ts.map +1 -1
- package/build/types.local.d.ts +9 -0
- package/build/types.local.d.ts.map +1 -0
- package/build/types.local.js +2 -0
- package/build/types.local.js.map +1 -0
- package/package.json +3 -3
- package/src/consts.local.ts +16 -0
- package/src/consts.ts +120 -3
- package/src/geo/types.ts +49 -0
- package/src/geo.ts +122 -0
- package/src/gtobserver/types.ts +73 -0
- package/src/gtobserver.ts +182 -0
- package/src/i18n/be.json +8 -1
- package/src/i18n/de.json +8 -1
- package/src/i18n/en.json +8 -1
- package/src/i18n/es.json +8 -1
- package/src/i18n/fr.json +8 -1
- package/src/i18n/pl.json +8 -1
- package/src/i18n/ru.json +8 -1
- package/src/i18n/types.ts +11 -0
- package/src/i18n/uk.json +8 -1
- package/src/i18n.ts +20 -32
- package/src/index.ts +13 -12
- package/src/linker/types.ts +59 -0
- package/src/linker.ts +301 -349
- package/src/plugins/types.ts +42 -0
- package/src/plugins.ts +82 -105
- package/src/storage/types.ts +31 -0
- package/src/storage.ts +75 -77
- package/src/store.ts +125 -31
- package/src/types.local.ts +9 -0
- package/src/types.ts +148 -5
- package/tests/consent.spec.ts +26 -28
- package/tests/geo.spec.ts +474 -0
- package/tests/linker.spec.ts +68 -74
- package/tests/tracking.spec.ts +14 -14
- package/build/gtm.d.ts +0 -72
- package/build/gtm.d.ts.map +0 -1
- package/build/gtm.js +0 -182
- package/build/gtm.js.map +0 -1
- package/src/gtm.ts +0 -220
package/build/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAAE,iBAAiB,EAAE,WAAW,EAAE,sBAAsB,GAC5E,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAAE,iBAAiB,EAAE,WAAW,EAAE,sBAAsB,GAC5E,MAAM,aAAa,CAAA;AAIpB,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAyB,EAAE;IACnE,MAAM,GAAG,GAAG,CAAC,IAAqB,EAAU,EAAE,CAAC,IAAI,EAAE,UAAU,IAAI,WAAW,CAAA;IAE9E,MAAM,KAAK,GAAG,CAAC,GAA8B,EAAwB,EAAE;QACrE,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAA;QACb,CAAC;QACD,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAY,CAAA;YAExC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAsB,CAAC,CAAC,CAAC,IAAI,CAAA;QACnF,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC,CAAA;IAED,MAAM,cAAc,GAAG,CAAC,GAAyB,EAAwB,EAAE,CACzE,GAAG,IAAI,IAAI,CAAC,CAAC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G,IAAI,EAAE,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;YAC/E,QAAQ,CAAC,MAAM,GAAG,GAAG,IAAI,iDAAiD,MAAM,EAAE,CAAA;QACpF,CAAC;IACH,CAAC,CAAA;IAED,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,CAAA;AACpE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,EAAE,CAAA;AAEhE,sFAAsF;AACtF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAqB,EAAwB,EAAE,CAAC,oBAAoB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;AAElH,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAqB,EAAE,IAAqB,EAAQ,EAAE,CACjF,oBAAoB,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AAEjD,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAqB,EAAQ,EAAE,CAAC,oBAAoB,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA"}
|
package/build/store.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ import type { ConsentReason, ConsentStore } from './types.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const makeConsentStore: () => ConsentStore;
|
|
11
11
|
export declare const consentStore: ConsentStore;
|
|
12
|
-
/**
|
|
12
|
+
/** @deprecated compat:factory-refactor — use `consentStore.open(…)` */
|
|
13
13
|
export declare const openConsent: (reason?: ConsentReason) => void;
|
|
14
|
-
/**
|
|
14
|
+
/** @deprecated compat:factory-refactor — use `consentStore.granted(…)` */
|
|
15
15
|
export declare const isConsented: (key: string) => boolean;
|
|
16
16
|
//# sourceMappingURL=store.d.ts.map
|
package/build/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACuB,aAAa,EAA+B,YAAY,EAC1F,MAAM,YAAY,CAAA;AAGnB;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,QAAO,YA6LnC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,YAAiC,CAAA;AAE5D,uEAAuE;AACvE,eAAO,MAAM,WAAW,YAAa,aAAa,KAAG,IAAiC,CAAA;AAEtF,0EAA0E;AAC1E,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,OAAoC,CAAA"}
|
package/build/store.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { CONSENT_KEY, DEFAULT_CONSENT_CATEGORIES } from './consts.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { CONSENT_IDLE_STATE, CONSENT_KEY, CONSENT_STATE_ATTRIBUTE, DEFAULT_CONSENT_CATEGORIES, } from './consts.js';
|
|
2
|
+
import { CLOUDFLARE_LOCATOR_ALIAS } from './consts.local.js';
|
|
3
|
+
import { consentModeHelper } from './gtobserver.js';
|
|
4
|
+
import { consentGeoHelper } from './geo.js';
|
|
5
|
+
import { consentLinkHelper } from './linker.js';
|
|
6
|
+
import { consentPluginHelper } from './plugins.js';
|
|
7
|
+
import { consentStorageHelper } from './storage.js';
|
|
6
8
|
/**
|
|
7
9
|
* The consent state of this DOCUMENT.
|
|
8
10
|
*
|
|
@@ -13,17 +15,65 @@ import { readConsent, writeConsent } from './storage.js';
|
|
|
13
15
|
*/
|
|
14
16
|
export const makeConsentStore = () => {
|
|
15
17
|
const listeners = new Set();
|
|
16
|
-
|
|
18
|
+
const waiting = new Set();
|
|
19
|
+
let state = CONSENT_IDLE_STATE;
|
|
17
20
|
let options = {};
|
|
21
|
+
/** The one country lookup of this document, while it runs. */
|
|
22
|
+
let lookup = null;
|
|
23
|
+
/** What the last lookup decided — a later `init` never locates the same visitor twice. */
|
|
24
|
+
let verdict = null;
|
|
25
|
+
/** `<html data-consent>`: what a test waits on and a stylesheet may key on. */
|
|
26
|
+
const mark = () => {
|
|
27
|
+
const root = typeof document !== 'undefined' ? document.documentElement : undefined;
|
|
28
|
+
if (root == null || typeof root.setAttribute !== 'function') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
root.setAttribute(CONSENT_STATE_ATTRIBUTE, state.open ? 'open'
|
|
32
|
+
: state.locating != null ? 'locating'
|
|
33
|
+
: state.record != null ? 'decided' : 'idle');
|
|
34
|
+
};
|
|
18
35
|
const publish = (next) => {
|
|
19
36
|
state = { ...state, ...next };
|
|
37
|
+
mark();
|
|
20
38
|
listeners.forEach(listener => listener(state));
|
|
39
|
+
if (state.locating == null && lookup == null && waiting.size > 0) {
|
|
40
|
+
const settled = [...waiting];
|
|
41
|
+
waiting.clear();
|
|
42
|
+
settled.forEach(resolve => resolve(state));
|
|
43
|
+
}
|
|
21
44
|
};
|
|
22
45
|
const resolved = () => ({
|
|
23
46
|
...options,
|
|
24
47
|
categories: options.categories ?? DEFAULT_CONSENT_CATEGORIES,
|
|
25
48
|
storageKey: options.storageKey ?? CONSENT_KEY,
|
|
26
49
|
});
|
|
50
|
+
const ask = () => {
|
|
51
|
+
publish({ record: null, open: true, reason: 'initial', locating: null });
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* What a finished lookup does — unless the visitor got there first: a decision saved meanwhile, or
|
|
55
|
+
* the window opened for a reason of its own (signing in), always wins over the location.
|
|
56
|
+
*/
|
|
57
|
+
const settle = (result, pending) => {
|
|
58
|
+
verdict = result;
|
|
59
|
+
lookup = null;
|
|
60
|
+
if (state.record != null || (state.open && state.reason !== 'initial')) {
|
|
61
|
+
publish({ locating: null });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (result === 'auto') {
|
|
65
|
+
const record = consentGeoHelper.automaticRecord(resolved());
|
|
66
|
+
consentStorageHelper.writeConsent(record, options);
|
|
67
|
+
consentModeHelper.applyConsent(record, options);
|
|
68
|
+
publish({ record, open: false, reason: null, locating: null });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (pending != null) {
|
|
72
|
+
// A grant derived somewhere nobody had to be asked does not survive arriving where they must.
|
|
73
|
+
consentStorageHelper.clearConsent(options);
|
|
74
|
+
}
|
|
75
|
+
ask();
|
|
76
|
+
};
|
|
27
77
|
const store = {
|
|
28
78
|
get: () => state,
|
|
29
79
|
subscribe: listener => {
|
|
@@ -33,53 +83,84 @@ export const makeConsentStore = () => {
|
|
|
33
83
|
init: opts => {
|
|
34
84
|
options = { ...options, ...opts };
|
|
35
85
|
// Before anything is read, so a page with no stored answer still declares what is denied.
|
|
36
|
-
pushConsentDefaults(options);
|
|
86
|
+
consentModeHelper.pushConsentDefaults(options);
|
|
37
87
|
if (options.linker != null) {
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
88
|
+
// Registered once: `start` installs the click listener of THAT instance, and a second
|
|
89
|
+
// instance (a second `init` — a re-mounted provider, StrictMode, `loadGtm`) would install
|
|
90
|
+
// its own beside it.
|
|
91
|
+
if (!consentPluginHelper.consentPlugins().some(plugin => plugin.alias === 'linker')) {
|
|
92
|
+
consentPluginHelper.registerConsentPlugin(consentLinkHelper.consentLinker());
|
|
93
|
+
}
|
|
94
|
+
consentPluginHelper.startConsentPlugins(options);
|
|
43
95
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
96
|
+
if (options.geo?.cloudflare != null && options.geo.cloudflare !== false
|
|
97
|
+
&& !consentPluginHelper.consentPlugins().some(plugin => plugin.alias === CLOUDFLARE_LOCATOR_ALIAS)) {
|
|
98
|
+
consentPluginHelper.registerConsentPlugin(consentGeoHelper.cloudflareLocator());
|
|
99
|
+
}
|
|
100
|
+
let record = consentStorageHelper.readConsent(options);
|
|
101
|
+
const automatic = consentGeoHelper.autoState(record);
|
|
102
|
+
// An automatic decision past its age is held back — applied nowhere — until the visitor is
|
|
103
|
+
// located again, exactly as the head scripts already skipped it.
|
|
104
|
+
const pending = automatic === 'stale' ? record : null;
|
|
105
|
+
if (pending != null) {
|
|
106
|
+
record = null;
|
|
107
|
+
}
|
|
108
|
+
// An explicit decision carried from another domain always beats none — and beats an automatic
|
|
109
|
+
// one, which nobody chose. An explicit stored one always wins, as the ordinary "ask" path
|
|
110
|
+
// would never overwrite it either.
|
|
111
|
+
if ((record == null || automatic != null) && options.linker != null) {
|
|
112
|
+
const adopted = consentPluginHelper.adoptConsent(options);
|
|
113
|
+
if (adopted != null) {
|
|
114
|
+
consentStorageHelper.writeConsent(adopted, options);
|
|
115
|
+
record = adopted;
|
|
51
116
|
}
|
|
52
117
|
}
|
|
53
118
|
if (options.linker != null) {
|
|
54
119
|
// The language the link carried, stored at once — the interface language is strictly
|
|
55
120
|
// necessary storage, so no decision is consulted. A page that stamped the inline head
|
|
56
121
|
// fragment has already done this and stripped the parameter, which leaves nothing here.
|
|
57
|
-
const carried = adoptConsentLanguage(options);
|
|
122
|
+
const carried = consentPluginHelper.adoptConsentLanguage(options);
|
|
58
123
|
if (carried != null) {
|
|
59
|
-
writeConsentLanguage(carried, options);
|
|
124
|
+
consentLinkHelper.writeConsentLanguage(carried, options);
|
|
60
125
|
}
|
|
61
126
|
// Always, whether or not anything was adopted — a stale or foreign parameter is exactly as
|
|
62
127
|
// much noise in the visible URL as an adopted one, and a page that already had its own
|
|
63
128
|
// decision may still have arrived with one attached.
|
|
64
|
-
stripConsentLinkParam(options);
|
|
129
|
+
consentLinkHelper.stripConsentLinkParam(options);
|
|
65
130
|
}
|
|
66
131
|
if (record != null) {
|
|
67
|
-
applyConsent(record, options);
|
|
68
|
-
publish({ record, open: false, reason: null });
|
|
132
|
+
consentModeHelper.applyConsent(record, options);
|
|
133
|
+
publish({ record, open: false, reason: null, locating: null });
|
|
69
134
|
return;
|
|
70
135
|
}
|
|
71
|
-
|
|
136
|
+
if (lookup != null) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// The window is already open for a reason of its own (signing in): the visitor is answering.
|
|
140
|
+
if (state.open && state.reason !== 'initial') {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (verdict === 'ask' || !consentGeoHelper.enabled(options)) {
|
|
144
|
+
ask();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// A first visit waits behind the spinner; a re-check runs silently, nothing applied meanwhile.
|
|
148
|
+
publish({ record: null, open: false, reason: null, locating: pending != null ? 'recheck' : 'first' });
|
|
149
|
+
lookup = consentGeoHelper.decide(options).then(result => settle(result, pending));
|
|
72
150
|
},
|
|
73
151
|
save: record => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
152
|
+
const { auto: _auto, ...explicit } = record;
|
|
153
|
+
consentStorageHelper.writeConsent(explicit, options);
|
|
154
|
+
consentModeHelper.applyConsent(explicit, options);
|
|
155
|
+
publish({ record: explicit, open: false, reason: null, locating: null });
|
|
77
156
|
},
|
|
78
157
|
acceptAll: () => {
|
|
79
158
|
const record = Object.fromEntries(resolved().categories.map(category => [category.key, true]));
|
|
80
159
|
store.save(record);
|
|
81
160
|
},
|
|
82
|
-
open: (reason) => {
|
|
161
|
+
open: (reason) => {
|
|
162
|
+
publish({ open: true, reason: reason ?? 'reopen', locating: null });
|
|
163
|
+
},
|
|
83
164
|
close: () => { publish({ open: false, reason: null }); },
|
|
84
165
|
granted: key => {
|
|
85
166
|
const category = resolved().categories.find(candidate => candidate.key === key);
|
|
@@ -89,12 +170,15 @@ export const makeConsentStore = () => {
|
|
|
89
170
|
return state.record?.[key] === true;
|
|
90
171
|
},
|
|
91
172
|
options: resolved,
|
|
173
|
+
settled: () => state.locating == null && lookup == null
|
|
174
|
+
? Promise.resolve(state)
|
|
175
|
+
: new Promise(resolve => { waiting.add(resolve); }),
|
|
92
176
|
};
|
|
93
177
|
return store;
|
|
94
178
|
};
|
|
95
179
|
export const consentStore = makeConsentStore();
|
|
96
|
-
/**
|
|
180
|
+
/** @deprecated compat:factory-refactor — use `consentStore.open(…)` */
|
|
97
181
|
export const openConsent = (reason) => consentStore.open(reason);
|
|
98
|
-
/**
|
|
182
|
+
/** @deprecated compat:factory-refactor — use `consentStore.granted(…)` */
|
|
99
183
|
export const isConsented = (key) => consentStore.granted(key);
|
|
100
184
|
//# sourceMappingURL=store.js.map
|
package/build/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAAE,WAAW,EAAE,uBAAuB,EAAE,0BAA0B,GACrF,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAMnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAiB,EAAE;IACjD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmB,CAAA;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiC,CAAA;IACxD,IAAI,KAAK,GAAiB,kBAAkB,CAAA;IAC5C,IAAI,OA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AK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAiB,gBAAgB,EAAE,CAAA;AAE5D,uEAAuE;AACvE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAsB,EAAQ,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAEtF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA"}
|
package/build/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* manager simply never sees the update, and the only symptom is analytics that stay switched off
|
|
6
6
|
* for everyone who agreed to them.
|
|
7
7
|
*/
|
|
8
|
+
import { CONSENT_LINK_VERSION } from './consts.local.js';
|
|
8
9
|
export type ConsentSignal = 'ad_storage' | 'ad_user_data' | 'ad_personalization' | 'analytics_storage' | 'functionality_storage' | 'personalization_storage' | 'security_storage';
|
|
9
10
|
export interface ConsentCategory {
|
|
10
11
|
/** Stable storage key. `essential` is reserved and always required. */
|
|
@@ -62,11 +63,55 @@ export interface ConsentService {
|
|
|
62
63
|
/** The provider's own privacy policy. */
|
|
63
64
|
privacyHref?: string;
|
|
64
65
|
}
|
|
65
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* `v` is the schema version and `auto` marks an automatic decision; every other key is a category
|
|
68
|
+
* key — so neither `v` nor `auto` may ever name a category.
|
|
69
|
+
*/
|
|
66
70
|
export interface ConsentRecord {
|
|
67
71
|
v?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Unix seconds at which this record was DERIVED rather than chosen: the visitor was located
|
|
74
|
+
* outside every consent-requiring country (`ConsentGeoOptions`) and nobody asked them. Present
|
|
75
|
+
* only on an automatic decision — an explicit save drops it. An automatic decision is trusted for
|
|
76
|
+
* `CONSENT_AUTO_MAX_AGE` seconds and then counts as undecided until the visitor is located again,
|
|
77
|
+
* so a traveller who crosses into a consent country is asked there instead of carrying a grant
|
|
78
|
+
* nobody gave. It never travels on a linker link as the visitor's own choice.
|
|
79
|
+
*/
|
|
80
|
+
auto?: number;
|
|
68
81
|
[category: string]: boolean | number | undefined;
|
|
69
82
|
}
|
|
83
|
+
/** Where a locator places the visitor. */
|
|
84
|
+
export interface ConsentGeoLocation {
|
|
85
|
+
/** ISO 3166-1 alpha-2, upper case — `PL`, `US`. Anything else counts as "not located". */
|
|
86
|
+
country: string;
|
|
87
|
+
}
|
|
88
|
+
export interface ConsentCloudflareOptions {
|
|
89
|
+
/** The same-origin path of Cloudflare's trace endpoint. Defaults to `CONSENT_TRACE_PATH`. */
|
|
90
|
+
path?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Ask only where the law requires it: locate the visitor first, and decide automatically wherever
|
|
94
|
+
* no consent is required.
|
|
95
|
+
*
|
|
96
|
+
* Its presence turns the gate on. The country comes from the registered locators
|
|
97
|
+
* (`ConsentGeoPlugin`, highest priority first, the first usable answer wins); `cloudflare` adds the
|
|
98
|
+
* built-in one. A visitor nobody can locate — no locator, every one of them failing, an unusable
|
|
99
|
+
* code, `timeout` passing — is asked, exactly as without the gate.
|
|
100
|
+
*/
|
|
101
|
+
export interface ConsentGeoOptions {
|
|
102
|
+
/**
|
|
103
|
+
* The built-in locator: a same-origin GET of Cloudflare's `/cdn-cgi/trace`, reading `loc=`. It
|
|
104
|
+
* answers only where the host is proxied by Cloudflare — anywhere else (a local dev server, a
|
|
105
|
+
* self-hosted export) it fails, and the visitor is asked.
|
|
106
|
+
*/
|
|
107
|
+
cloudflare?: boolean | ConsentCloudflareOptions;
|
|
108
|
+
/** The countries where consent is asked. Defaults to `CONSENT_REQUIRED_COUNTRIES`. */
|
|
109
|
+
countries?: readonly string[];
|
|
110
|
+
/** How long locating may take before the visitor is asked anyway, in ms. `CONSENT_GEO_TIMEOUT`. */
|
|
111
|
+
timeout?: number;
|
|
112
|
+
}
|
|
113
|
+
/** Which lookup is running: the first one (the page waits behind a spinner) or a silent re-check. */
|
|
114
|
+
export type ConsentLocating = 'first' | 'recheck';
|
|
70
115
|
export interface ConsentOptions {
|
|
71
116
|
categories?: ConsentCategory[];
|
|
72
117
|
storageKey?: string;
|
|
@@ -84,6 +129,8 @@ export interface ConsentOptions {
|
|
|
84
129
|
* `consentLinker`/`ConsentPlugin` in `./plugins.js` and `./linker.js`.
|
|
85
130
|
*/
|
|
86
131
|
linker?: ConsentLinkerOptions;
|
|
132
|
+
/** Ask only in consent-requiring countries — see `ConsentGeoOptions`. Off when absent. */
|
|
133
|
+
geo?: ConsentGeoOptions;
|
|
87
134
|
}
|
|
88
135
|
export interface ConsentLinkerOptions {
|
|
89
136
|
/**
|
|
@@ -120,21 +167,35 @@ export interface ConsentLinkerLanguage {
|
|
|
120
167
|
*/
|
|
121
168
|
storageKey?: string;
|
|
122
169
|
}
|
|
123
|
-
/**
|
|
124
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Why the consent UI is open. `initial` is the first ask (the bar, in bar mode); `preferences` is the
|
|
172
|
+
* bar's own "Cookie preferences"; `reopen` a footer link or the corner button; `login` what the
|
|
173
|
+
* sign-in precondition raises. Every reason but `initial` opens the preferences window.
|
|
174
|
+
*/
|
|
175
|
+
export type ConsentReason = 'initial' | 'reopen' | 'login' | 'preferences' | string;
|
|
125
176
|
export interface ConsentState {
|
|
126
177
|
record: ConsentRecord | null;
|
|
127
178
|
open: boolean;
|
|
128
179
|
reason: ConsentReason | null;
|
|
180
|
+
/** A country lookup is running (`ConsentGeoOptions`); `null` once it settled, or when there is none. */
|
|
181
|
+
locating: ConsentLocating | null;
|
|
182
|
+
}
|
|
183
|
+
export interface ConsentListener {
|
|
184
|
+
(state: ConsentState): void;
|
|
129
185
|
}
|
|
130
|
-
export type ConsentListener = (state: ConsentState) => void;
|
|
131
186
|
export interface ConsentStore {
|
|
132
187
|
get: () => ConsentState;
|
|
133
188
|
subscribe: (listener: ConsentListener) => () => void;
|
|
134
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* Push the defaults, load and migrate any stored record, apply it — and, when there is none,
|
|
191
|
+
* either ask at once or, with `geo` set, locate the visitor first and ask or decide automatically.
|
|
192
|
+
* Synchronous: a lookup runs in the background, `locating` says so, and `settled()` waits for it.
|
|
193
|
+
*/
|
|
135
194
|
init: (opts?: ConsentOptions) => void;
|
|
195
|
+
/** Record an explicit decision. Always explicit: an `auto` key on `record` is dropped. */
|
|
136
196
|
save: (record: ConsentRecord) => void;
|
|
137
197
|
acceptAll: () => void;
|
|
198
|
+
/** Open the consent UI from anywhere — a footer link, a policy page, a login gate. */
|
|
138
199
|
open: (reason?: ConsentReason) => void;
|
|
139
200
|
close: () => void;
|
|
140
201
|
/** Imperative reader, for the callers that are not React. */
|
|
@@ -143,5 +204,80 @@ export interface ConsentStore {
|
|
|
143
204
|
categories: ConsentCategory[];
|
|
144
205
|
storageKey: string;
|
|
145
206
|
};
|
|
207
|
+
/** The state once no country lookup is running — at once when none is. */
|
|
208
|
+
settled: () => Promise<ConsentState>;
|
|
209
|
+
}
|
|
210
|
+
/** A language the dialog's built-in copy is carried in (`CONSENT_LOCALES`). */
|
|
211
|
+
export type ConsentLocale = 'en' | 'pl' | 'ru' | 'be' | 'uk' | 'es' | 'de' | 'fr';
|
|
212
|
+
/** The decoded, not-yet-validated payload a decorated link's parameter carries. */
|
|
213
|
+
export interface ConsentLinkPayload {
|
|
214
|
+
v: typeof CONSENT_LINK_VERSION;
|
|
215
|
+
/** One entry per OPTIONAL category this site knows, `1` granted / `0` denied. */
|
|
216
|
+
c: Record<string, 0 | 1>;
|
|
217
|
+
/** Unix seconds the link was decorated at. */
|
|
218
|
+
t: number;
|
|
219
|
+
/**
|
|
220
|
+
* The interface language of the page the link was on (a BCP 47 tag, lower-cased) — present only
|
|
221
|
+
* when the sender has `linker.language` set and its `<html lang>` names one. Optional on the
|
|
222
|
+
* wire, so a receiver that predates it reads the same `v: 2` payload and ignores the field.
|
|
223
|
+
*/
|
|
224
|
+
l?: string;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* An extension seam for `@owlmeans/consent`: something that reacts to this document's consent
|
|
228
|
+
* decision, or supplies one from elsewhere, without the core store knowing anything about where
|
|
229
|
+
* that decision came from.
|
|
230
|
+
*
|
|
231
|
+
* `consentLinker` (`./linker.js`) is the one built-in plugin — cross-domain consent through
|
|
232
|
+
* decorated links — but nothing here is specific to it. A registry rather than a fixed option on
|
|
233
|
+
* `ConsentOptions` because the store has zero dependencies today and stays that way: a plugin is
|
|
234
|
+
* opt-in code an application imports for its own reason, never a bundled feature this package
|
|
235
|
+
* pulls in whether or not anything uses it.
|
|
236
|
+
*/
|
|
237
|
+
export interface ConsentPlugin {
|
|
238
|
+
/** Stable identity. Registering the same alias again REPLACES the earlier plugin. */
|
|
239
|
+
alias: string;
|
|
240
|
+
/** Run order when more than one plugin implements the same hook. Higher first. Defaults to 0. */
|
|
241
|
+
priority?: number;
|
|
242
|
+
/** Installed once, the first time `consentStore.init` runs with this plugin registered. */
|
|
243
|
+
start?: (opts: ConsentOptions) => void;
|
|
244
|
+
/**
|
|
245
|
+
* Offer a decision from outside this document's own storage — e.g. one carried on the URL that
|
|
246
|
+
* led here. Returns a full record to adopt, or `null` to defer to the next plugin / the ordinary
|
|
247
|
+
* "ask" path. Never called once a stored record already exists.
|
|
248
|
+
*/
|
|
249
|
+
adopt?: (opts: ConsentOptions) => ConsentRecord | null;
|
|
250
|
+
/**
|
|
251
|
+
* Offer an interface language from outside this document's own storage — e.g. the one the page
|
|
252
|
+
* that led here was read in. Returns a language the application supports, or `null` to keep
|
|
253
|
+
* choosing its own. Only a CANDIDATE: it says what the link carried, and `writeConsentLanguage`
|
|
254
|
+
* stores it — unconditionally, since the interface language is strictly necessary storage.
|
|
255
|
+
*/
|
|
256
|
+
adoptLanguage?: (opts: ConsentOptions) => string | null;
|
|
257
|
+
/**
|
|
258
|
+
* Rewrite an outgoing URL to carry this document's current decision — and its language — or
|
|
259
|
+
* `null` to leave it untouched (a foreign host, a link that opts out, nothing to carry yet).
|
|
260
|
+
* `record` is `null` while the visitor has not decided: a plugin that also carries something
|
|
261
|
+
* else (the language) still has a reason to decorate then.
|
|
262
|
+
*/
|
|
263
|
+
decorate?: (url: URL, record: ConsentRecord | null, opts: ConsentOptions) => URL | null;
|
|
264
|
+
/** Extra domains this decision is understood to apply to, for disclosure — never deduplicated here. */
|
|
265
|
+
domains?: (opts: ConsentOptions) => string[];
|
|
266
|
+
/**
|
|
267
|
+
* Find the visitor's country, or throw when it cannot tell. Asked only while `opts.geo` is set
|
|
268
|
+
* and nothing is stored; locators run highest priority first and the first usable country wins,
|
|
269
|
+
* so a throw (or an unusable code) hands over to the next one — the built-in Cloudflare locator
|
|
270
|
+
* sits at the very bottom.
|
|
271
|
+
*/
|
|
272
|
+
locate?: (opts: ConsentOptions) => Promise<ConsentGeoLocation>;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* The country-detection plugin: one async method that resolves the visitor's country or throws.
|
|
276
|
+
* Register it with `consentPluginHelper.registerConsentPlugin` — or, in an OwlMeans application,
|
|
277
|
+
* with `@owlmeans/web-panel/consent`'s `appendConsentGeoPlugin(context, plugin)` while the context is
|
|
278
|
+
* configured.
|
|
279
|
+
*/
|
|
280
|
+
export interface ConsentGeoPlugin extends ConsentPlugin {
|
|
281
|
+
locate: (opts: ConsentOptions) => Promise<ConsentGeoLocation>;
|
|
146
282
|
}
|
|
147
283
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB,YAAY,GAAG,cAAc,GAAG,oBAAoB,GACpD,mBAAmB,GAAG,uBAAuB,GAC7C,yBAAyB,GAAG,kBAAkB,CAAA;AAElD,MAAM,WAAW,eAAe;IAC9B,uEAAuE;I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AAI,EAAE,cAAc,KAAK,MAAM,GAAG,IAAI,CAAA;IACvD;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,IAAI,EAAE,cAAc,KAAK,GAAG,GAAG,IAAI,CAAA;IACvF,uGAAuG;IACvG,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,MAAM,EAAE,CAAA;IAC5C;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;CAC/D;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;CAC9D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ConsentWindow {
|
|
2
|
+
dataLayer?: unknown[];
|
|
3
|
+
[flag: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
/** The one navigator field the automatic decision reads: Global Privacy Control. */
|
|
6
|
+
export interface ConsentNavigator {
|
|
7
|
+
globalPrivacyControl?: boolean;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=types.local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,OAAO,EAAE,CAAA;IACrB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CACxB;AAED,oFAAoF;AACpF,MAAM,WAAW,gBAAgB;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/consent",
|
|
3
|
-
"version": "0.1.18
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@owlmeans/dep-config": "
|
|
26
|
-
"@types/bun": "^1.4.
|
|
25
|
+
"@owlmeans/dep-config": "^0.1.18",
|
|
26
|
+
"@types/bun": "^1.4.2",
|
|
27
27
|
"nodemon": "^3.1.14",
|
|
28
28
|
"typescript": "^7.0.2"
|
|
29
29
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const CONSENT_LINK_VERSION = 2
|
|
2
|
+
|
|
3
|
+
/** A BCP 47-shaped tag: a 2–3 letter language and up to three subtags (`pl`, `pt-BR`, `zh-Hant-TW`). */
|
|
4
|
+
export const LANGUAGE_TAG = /^[a-z]{2,3}(?:[-_][a-z0-9]{1,8}){0,3}$/i
|
|
5
|
+
|
|
6
|
+
/** The built-in Cloudflare locator's registry alias. */
|
|
7
|
+
export const CLOUDFLARE_LOCATOR_ALIAS = 'cloudflare'
|
|
8
|
+
|
|
9
|
+
/** Below anything an application registers: an application's own locator always asks first. */
|
|
10
|
+
export const CLOUDFLARE_LOCATOR_PRIORITY = -100
|
|
11
|
+
|
|
12
|
+
/** An ISO 3166-1 alpha-2 code, upper case. */
|
|
13
|
+
export const COUNTRY_CODE = /^[A-Z]{2}$/
|
|
14
|
+
|
|
15
|
+
/** Clock skew tolerated on an automatic decision's timestamp, in seconds. */
|
|
16
|
+
export const AUTO_SKEW = 60
|