@owlmeans/consent 0.1.18-rc.6 → 0.1.18-rc.7
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/build/gtm.d.ts.map +1 -1
- package/build/gtm.js +8 -0
- package/build/gtm.js.map +1 -1
- package/build/i18n/be.json +3 -1
- package/build/i18n/de.json +3 -1
- package/build/i18n/en.json +3 -1
- package/build/i18n/es.json +3 -1
- package/build/i18n/fr.json +3 -1
- package/build/i18n/pl.json +3 -1
- package/build/i18n/ru.json +3 -1
- package/build/i18n/uk.json +3 -1
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/linker.d.ts +57 -0
- package/build/linker.d.ts.map +1 -0
- package/build/linker.js +252 -0
- package/build/linker.js.map +1 -0
- package/build/plugins.d.ts +55 -0
- package/build/plugins.d.ts.map +1 -0
- package/build/plugins.js +58 -0
- package/build/plugins.js.map +1 -0
- package/build/store.d.ts.map +1 -1
- package/build/store.js +24 -1
- package/build/store.js.map +1 -1
- package/build/types.d.ts +18 -0
- package/build/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/gtm.ts +8 -0
- package/src/i18n/be.json +3 -1
- package/src/i18n/de.json +3 -1
- package/src/i18n/en.json +3 -1
- package/src/i18n/es.json +3 -1
- package/src/i18n/fr.json +3 -1
- package/src/i18n/pl.json +3 -1
- package/src/i18n/ru.json +3 -1
- package/src/i18n/uk.json +3 -1
- package/src/index.ts +10 -0
- package/src/linker.ts +289 -0
- package/src/plugins.ts +104 -0
- package/src/store.ts +26 -1
- package/src/types.ts +19 -0
- package/tests/linker.spec.ts +352 -0
package/build/gtm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gtm.d.ts","sourceRoot":"","sources":["../src/gtm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gtm.d.ts","sourceRoot":"","sources":["../src/gtm.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAUhF;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAUrD;AAKD,8EAA8E;AAC9E,eAAO,MAAM,eAAe,gBACb,eAAe,EAAE,KAC7B,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAMrC,CAAA;AAED,sDAAsD;AACtD,eAAO,MAAM,aAAa,WAChB,aAAa,eAAe,eAAe,EAAE,KACpD,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAWrC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,UAAW,cAAc,KAAG,IAO3D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,WAAY,aAAa,SAAS,cAAc,KAAG,IA6B3E,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,WAClB,aAAa,GAAG,IAAI,eAAc,eAAe,EAAE,KAC1D,OAEF,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,UAAW,cAAc,KAAG,MA+B9D,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,iBAAiB,eAChB,MAAM,SAAS,cAAc,GAAG;IAAE,UAAU,CAAC,EAAE,eAAe,EAAE,CAAA;CAAE,KAC7E,MAuBF,CAAA"}
|
package/build/gtm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CONSENT_EVENT, CONSENT_KEY, CONSENT_SETUP_FLAG, CONSENT_SIGNAL_DEFAULTS, DEFAULT_CONSENT_CATEGORIES, } from './consts.js';
|
|
2
|
+
import { consentLinkerScript } from './linker.js';
|
|
2
3
|
const global = () => typeof window !== 'undefined' ? window : null;
|
|
3
4
|
/**
|
|
4
5
|
* Push onto the tag-manager queue in the shape Google's own snippet uses.
|
|
@@ -114,9 +115,16 @@ export const consentBootstrapScript = (opts) => {
|
|
|
114
115
|
})));
|
|
115
116
|
const storageKey = JSON.stringify(opts?.storageKey ?? CONSENT_KEY);
|
|
116
117
|
const flag = JSON.stringify(CONSENT_SETUP_FLAG);
|
|
118
|
+
// Right after the default is pushed and before EITHER storage read below (this one, and the
|
|
119
|
+
// `consentGateScript` that is concatenated after this whole IIFE) — an adopted decision must
|
|
120
|
+
// already be in storage by the time anything reads it, so `gtm.js`'s own `page_view` never sees
|
|
121
|
+
// the parameter and a granted decision loads the tag on arrival. A page with no `opts.linker`
|
|
122
|
+
// gets an empty string here, unchanged from before this existed.
|
|
123
|
+
const linker = opts?.linker != null ? `${consentLinkerScript(opts)};` : '';
|
|
117
124
|
return `(function(w,d){` +
|
|
118
125
|
`w.dataLayer=w.dataLayer||[];function g(){w.dataLayer.push(arguments)}` +
|
|
119
126
|
`if(w[${flag}])return;g('consent','default',${defaults});w[${flag}]=true;` +
|
|
127
|
+
linker +
|
|
120
128
|
`var raw=null;try{raw=w.localStorage.getItem(${storageKey})}catch(e){}` +
|
|
121
129
|
`if(!raw){var p=('; '+d.cookie).split('; '+${storageKey}+'=');` +
|
|
122
130
|
`if(p.length===2){raw=p.pop().split(';').shift()}}` +
|
package/build/gtm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gtm.js","sourceRoot":"","sources":["../src/gtm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,uBAAuB,EACvE,0BAA0B,GAC3B,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"gtm.js","sourceRoot":"","sources":["../src/gtm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,uBAAuB,EACvE,0BAA0B,GAC3B,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM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AC9E,oCAAoC;QACpC,yDAAyD;QACzD,+CAA+C;QAC/C,4CAA4C,CAAA;AAChD,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,UAAkB,EAAE,IAA0D,EACtE,EAAE;IACV,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9D,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,QAAQ,EAAE,QAAQ,CAAC,QAAQ,KAAK,IAAI;QACpC,SAAS,EAAE,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;KAC/C,CAAC,CAAC,CAAC,CAAA;IACJ,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,IAAI,WAAW,CAAC,CAAA;IAClE,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;IAE3C,OAAO,iBAAiB;QACtB,4CAA4C,IAAI,GAAG;QACnD,2CAA2C;QAC3C,wEAAwE;QACxE,mBAAmB,UAAU,GAAG;QAChC,+CAA+C,UAAU,cAAc;QACvE,6CAA6C,UAAU,QAAQ;QAC/D,mDAAmD;QACnD,4DAA4D;QAC5D,0BAA0B;QAC1B,yDAAyD;QACzD,yBAAyB,KAAK,cAAc;QAC5C,sBAAsB,KAAK,KAAK;QAChC,qBAAqB,CAAA;AACzB,CAAC,CAAA"}
|
package/build/i18n/be.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Файлы cookie",
|
|
31
31
|
"policyServicePrivacy": "Палітыка прыватнасці: {{provider}}",
|
|
32
32
|
"privacy": "Палітыка прыватнасці",
|
|
33
|
-
"terms": "Умовы карыстання"
|
|
33
|
+
"terms": "Умовы карыстання",
|
|
34
|
+
"domains": "Гэты выбар распаўсюджваецца на {{domains}}.",
|
|
35
|
+
"policyDomains": "Гэты выбар распаўсюджваецца на наступныя дамены:"
|
|
34
36
|
}
|
package/build/i18n/de.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Cookies",
|
|
31
31
|
"policyServicePrivacy": "Datenschutzerklärung von {{provider}}",
|
|
32
32
|
"privacy": "Datenschutzerklärung",
|
|
33
|
-
"terms": "Nutzungsbedingungen"
|
|
33
|
+
"terms": "Nutzungsbedingungen",
|
|
34
|
+
"domains": "Diese Wahl gilt für {{domains}}.",
|
|
35
|
+
"policyDomains": "Diese Wahl gilt für die folgenden Domains:"
|
|
34
36
|
}
|
package/build/i18n/en.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Cookies",
|
|
31
31
|
"policyServicePrivacy": "{{provider}} privacy policy",
|
|
32
32
|
"privacy": "Privacy Policy",
|
|
33
|
-
"terms": "Terms & Conditions"
|
|
33
|
+
"terms": "Terms & Conditions",
|
|
34
|
+
"domains": "This choice applies to {{domains}}.",
|
|
35
|
+
"policyDomains": "This choice applies across these domains:"
|
|
34
36
|
}
|
package/build/i18n/es.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Cookies",
|
|
31
31
|
"policyServicePrivacy": "Política de privacidad de {{provider}}",
|
|
32
32
|
"privacy": "Política de privacidad",
|
|
33
|
-
"terms": "Términos y condiciones"
|
|
33
|
+
"terms": "Términos y condiciones",
|
|
34
|
+
"domains": "Esta elección se aplica a {{domains}}.",
|
|
35
|
+
"policyDomains": "Esta elección se aplica a los siguientes dominios:"
|
|
34
36
|
}
|
package/build/i18n/fr.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Cookies",
|
|
31
31
|
"policyServicePrivacy": "Politique de confidentialité de {{provider}}",
|
|
32
32
|
"privacy": "Politique de confidentialité",
|
|
33
|
-
"terms": "Conditions générales"
|
|
33
|
+
"terms": "Conditions générales",
|
|
34
|
+
"domains": "Ce choix s'applique à {{domains}}.",
|
|
35
|
+
"policyDomains": "Ce choix s'applique aux domaines suivants :"
|
|
34
36
|
}
|
package/build/i18n/pl.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Pliki cookie",
|
|
31
31
|
"policyServicePrivacy": "Polityka prywatności: {{provider}}",
|
|
32
32
|
"privacy": "Polityka prywatności",
|
|
33
|
-
"terms": "Regulamin"
|
|
33
|
+
"terms": "Regulamin",
|
|
34
|
+
"domains": "Ten wybór dotyczy: {{domains}}.",
|
|
35
|
+
"policyDomains": "Ten wybór dotyczy następujących domen:"
|
|
34
36
|
}
|
package/build/i18n/ru.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Файлы cookie",
|
|
31
31
|
"policyServicePrivacy": "Политика конфиденциальности: {{provider}}",
|
|
32
32
|
"privacy": "Политика конфиденциальности",
|
|
33
|
-
"terms": "Условия использования"
|
|
33
|
+
"terms": "Условия использования",
|
|
34
|
+
"domains": "Этот выбор применяется к {{domains}}.",
|
|
35
|
+
"policyDomains": "Этот выбор применяется к следующим доменам:"
|
|
34
36
|
}
|
package/build/i18n/uk.json
CHANGED
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
"policyCookies": "Файли cookie",
|
|
31
31
|
"policyServicePrivacy": "Політика конфіденційності: {{provider}}",
|
|
32
32
|
"privacy": "Політика конфіденційності",
|
|
33
|
-
"terms": "Умови користування"
|
|
33
|
+
"terms": "Умови користування",
|
|
34
|
+
"domains": "Цей вибір застосовується до {{domains}}.",
|
|
35
|
+
"policyDomains": "Цей вибір застосовується до таких доменів:"
|
|
34
36
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ export * from './storage.js';
|
|
|
4
4
|
export * from './gtm.js';
|
|
5
5
|
export * from './store.js';
|
|
6
6
|
export * from './i18n.js';
|
|
7
|
+
export type { ConsentPlugin } from './plugins.js';
|
|
8
|
+
export { registerConsentPlugin, consentPlugins, decorateConsentUrl, consentDomains, adoptConsent, startConsentPlugins, } from './plugins.js';
|
|
9
|
+
export type { ConsentLinkPayload } from './linker.js';
|
|
10
|
+
export { consentLinker, encodeConsentLink, decodeConsentLink, stripConsentLinkParam, consentLinkerScript, CONSENT_LINK_PARAM, CONSENT_LINK_MAX_AGE, CONSENT_LINK_SKEW, } from './linker.js';
|
|
7
11
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EACL,qBAAqB,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,YAAY,EACvF,mBAAmB,GACpB,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EACL,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,mBAAmB,EAC/F,kBAAkB,EAAE,oBAAoB,EAAE,iBAAiB,GAC5D,MAAM,aAAa,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -3,4 +3,6 @@ export * from './storage.js';
|
|
|
3
3
|
export * from './gtm.js';
|
|
4
4
|
export * from './store.js';
|
|
5
5
|
export * from './i18n.js';
|
|
6
|
+
export { registerConsentPlugin, consentPlugins, decorateConsentUrl, consentDomains, adoptConsent, startConsentPlugins, } from './plugins.js';
|
|
7
|
+
export { consentLinker, encodeConsentLink, decodeConsentLink, stripConsentLinkParam, consentLinkerScript, CONSENT_LINK_PARAM, CONSENT_LINK_MAX_AGE, CONSENT_LINK_SKEW, } from './linker.js';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AAEzB,OAAO,EACL,qBAAqB,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,YAAY,EACvF,mBAAmB,GACpB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,mBAAmB,EAC/F,kBAAkB,EAAE,oBAAoB,EAAE,iBAAiB,GAC5D,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ConsentPlugin } from './plugins.js';
|
|
2
|
+
import type { ConsentOptions, ConsentRecord } from './types.js';
|
|
3
|
+
/** The URL parameter a decorated link carries the decision in, absent an override. */
|
|
4
|
+
export declare const CONSENT_LINK_PARAM = "owlcc";
|
|
5
|
+
/** How old a decorated link's timestamp may be and still be trusted, in seconds, absent an override. */
|
|
6
|
+
export declare const CONSENT_LINK_MAX_AGE = 300;
|
|
7
|
+
/** Clock skew allowed the OTHER way — a timestamp up to this far in the future is still trusted. */
|
|
8
|
+
export declare const CONSENT_LINK_SKEW = 60;
|
|
9
|
+
declare const CONSENT_LINK_VERSION = 2;
|
|
10
|
+
/** The decoded, not-yet-validated payload a decorated link's parameter carries. */
|
|
11
|
+
export interface ConsentLinkPayload {
|
|
12
|
+
v: typeof CONSENT_LINK_VERSION;
|
|
13
|
+
/** One entry per OPTIONAL category this site knows, `1` granted / `0` denied. */
|
|
14
|
+
c: Record<string, 0 | 1>;
|
|
15
|
+
/** Unix seconds the link was decorated at. */
|
|
16
|
+
t: number;
|
|
17
|
+
}
|
|
18
|
+
/** The current document's decision, as the link parameter's `c`: one `0`/`1` per optional category. */
|
|
19
|
+
export declare const encodeConsentLink: (record: ConsentRecord, opts?: ConsentOptions) => string;
|
|
20
|
+
/** Parse-only — no trust decision here, that is `consentLinker(opts).adopt`'s job. Never throws. */
|
|
21
|
+
export declare const decodeConsentLink: (value: string) => ConsentLinkPayload | null;
|
|
22
|
+
/**
|
|
23
|
+
* Cross-domain consent: share this decision, and adopt one, between the domains named in
|
|
24
|
+
* `opts.linker.domains`.
|
|
25
|
+
*
|
|
26
|
+
* `start` decorates outgoing first-party links; `adopt` reads and validates an incoming one;
|
|
27
|
+
* `domains` discloses the list a dialog or policy page names. `decorate` is generic (a bare `URL`,
|
|
28
|
+
* no DOM) so the same trust rule serves a real anchor click and a programmatic navigation
|
|
29
|
+
* (`decorateConsentUrl`) alike — the `rel="noreferrer"` exemption is a DOM-only concept and is
|
|
30
|
+
* therefore checked by `start`'s click handler, never here.
|
|
31
|
+
*/
|
|
32
|
+
export declare const consentLinker: () => ConsentPlugin;
|
|
33
|
+
/**
|
|
34
|
+
* Remove the link parameter from the visible URL, keeping every other parameter and the hash — the
|
|
35
|
+
* real-TS equivalent of what {@link consentLinkerScript}'s embedded fragment already did inline.
|
|
36
|
+
* Idempotent: a page with no head script calls this from `consentStore.init` and it strips once; a
|
|
37
|
+
* page that ALSO carried the head script finds the parameter already gone and does nothing.
|
|
38
|
+
*/
|
|
39
|
+
export declare const stripConsentLinkParam: (opts: ConsentOptions) => void;
|
|
40
|
+
/**
|
|
41
|
+
* The inline `<head>` fragment that adopts a decorated link's decision and strips the parameter —
|
|
42
|
+
* standalone, so a page can stamp it even where nothing else here runs (a legal page with no tag
|
|
43
|
+
* script). `@owlmeans/web-gtm`'s `consentBootstrapScript` embeds this SAME fragment right after
|
|
44
|
+
* pushing Consent Mode's defaults, so a page that has both never runs it twice with different
|
|
45
|
+
* effect — the second attempt finds the parameter already gone and does nothing.
|
|
46
|
+
*
|
|
47
|
+
* Mirrors `consentLinker().adopt` exactly (v2, referrer + freshness/skew + full optional coverage +
|
|
48
|
+
* no existing record), but as hand-rolled JS text rather than a call into this module — the same
|
|
49
|
+
* discipline `consentBootstrapScript`/`consentGateScript` already follow, because this has to run
|
|
50
|
+
* before any bundle (this module included) has loaded. The parameter is ALWAYS stripped via
|
|
51
|
+
* `history.replaceState`, whether or not the trust rule accepts it: a stale or foreign `owlcc` is
|
|
52
|
+
* exactly as much noise as an adopted one, and neither belongs in the visible URL or in what a page
|
|
53
|
+
* reload, a shared link or a browser history entry carries forward.
|
|
54
|
+
*/
|
|
55
|
+
export declare const consentLinkerScript: (opts: ConsentOptions) => string;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=linker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../src/linker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAGjD,OAAO,KAAK,EAAmB,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhF,sFAAsF;AACtF,eAAO,MAAM,kBAAkB,UAAU,CAAA;AACzC,wGAAwG;AACxG,eAAO,MAAM,oBAAoB,MAAM,CAAA;AACvC,oGAAoG;AACpG,eAAO,MAAM,iBAAiB,KAAK,CAAA;AAEnC,QAAA,MAAM,oBAAoB,IAAI,CAAA;AAE9B,mFAAmF;AACnF,MAAM,WAAW,kBAAkB;IACjC,CAAC,EAAE,OAAO,oBAAoB,CAAA;IAC9B,iFAAiF;IACjF,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IACxB,8CAA8C;IAC9C,CAAC,EAAE,MAAM,CAAA;CACV;AAwBD,uGAAuG;AACvG,eAAO,MAAM,iBAAiB,WAAY,aAAa,SAAS,cAAc,KAAG,MAQhF,CAAA;AAED,oGAAoG;AACpG,eAAO,MAAM,iBAAiB,UAAW,MAAM,KAAG,kBAAkB,GAAG,IAmBtE,CAAA;AAmBD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAAO,aAgGhC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,SAAU,cAAc,KAAG,IAgB5D,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,SAAU,cAAc,KAAG,MA6C1D,CAAA"}
|
package/build/linker.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { CONSENT_COOKIE_DAYS, CONSENT_KEY, CONSENT_SCHEMA_VERSION, DEFAULT_CONSENT_CATEGORIES } from './consts.js';
|
|
2
|
+
import { decorateConsentUrl } from './plugins.js';
|
|
3
|
+
import { readConsent } from './storage.js';
|
|
4
|
+
/** The URL parameter a decorated link carries the decision in, absent an override. */
|
|
5
|
+
export const CONSENT_LINK_PARAM = 'owlcc';
|
|
6
|
+
/** How old a decorated link's timestamp may be and still be trusted, in seconds, absent an override. */
|
|
7
|
+
export const CONSENT_LINK_MAX_AGE = 300;
|
|
8
|
+
/** Clock skew allowed the OTHER way — a timestamp up to this far in the future is still trusted. */
|
|
9
|
+
export const CONSENT_LINK_SKEW = 60;
|
|
10
|
+
const CONSENT_LINK_VERSION = 2;
|
|
11
|
+
const categoriesOf = (opts) => opts?.categories ?? DEFAULT_CONSENT_CATEGORIES;
|
|
12
|
+
const optionalOf = (opts) => categoriesOf(opts).filter(category => category.required !== true);
|
|
13
|
+
const toBase64Url = (json) => btoa(json).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
14
|
+
const fromBase64Url = (value) => {
|
|
15
|
+
try {
|
|
16
|
+
let padded = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
17
|
+
while (padded.length % 4 !== 0) {
|
|
18
|
+
padded += '=';
|
|
19
|
+
}
|
|
20
|
+
return atob(padded);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/** The current document's decision, as the link parameter's `c`: one `0`/`1` per optional category. */
|
|
27
|
+
export const encodeConsentLink = (record, opts) => {
|
|
28
|
+
const c = {};
|
|
29
|
+
for (const category of optionalOf(opts)) {
|
|
30
|
+
c[category.key] = record[category.key] === true ? 1 : 0;
|
|
31
|
+
}
|
|
32
|
+
const payload = { v: CONSENT_LINK_VERSION, c, t: Math.floor(Date.now() / 1000) };
|
|
33
|
+
return toBase64Url(JSON.stringify(payload));
|
|
34
|
+
};
|
|
35
|
+
/** Parse-only — no trust decision here, that is `consentLinker(opts).adopt`'s job. Never throws. */
|
|
36
|
+
export const decodeConsentLink = (value) => {
|
|
37
|
+
const json = fromBase64Url(value);
|
|
38
|
+
if (json == null) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(json);
|
|
43
|
+
if (parsed == null || typeof parsed !== 'object') {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const { v, c, t } = parsed;
|
|
47
|
+
if (v !== CONSENT_LINK_VERSION || typeof t !== 'number' || c == null || typeof c !== 'object') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return { v: CONSENT_LINK_VERSION, c: c, t };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const referrerHostname = () => {
|
|
57
|
+
if (typeof document === 'undefined' || document.referrer === '') {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
return new URL(document.referrer).hostname;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/** Escape `<` inside a JSON literal meant for an inline `<script>` — the same discipline every
|
|
68
|
+
* caller of `consentBootstrapScript`/`consentGateScript` already owes the HTML it lands in, applied
|
|
69
|
+
* here at the source since this fragment's dynamic values (a configured domain, a storage key) are
|
|
70
|
+
* least likely to have been reviewed for it by whoever composes the final page. */
|
|
71
|
+
const jsonForScript = (value) => JSON.stringify(value).replace(/</g, '\\u003c');
|
|
72
|
+
/**
|
|
73
|
+
* Cross-domain consent: share this decision, and adopt one, between the domains named in
|
|
74
|
+
* `opts.linker.domains`.
|
|
75
|
+
*
|
|
76
|
+
* `start` decorates outgoing first-party links; `adopt` reads and validates an incoming one;
|
|
77
|
+
* `domains` discloses the list a dialog or policy page names. `decorate` is generic (a bare `URL`,
|
|
78
|
+
* no DOM) so the same trust rule serves a real anchor click and a programmatic navigation
|
|
79
|
+
* (`decorateConsentUrl`) alike — the `rel="noreferrer"` exemption is a DOM-only concept and is
|
|
80
|
+
* therefore checked by `start`'s click handler, never here.
|
|
81
|
+
*/
|
|
82
|
+
export const consentLinker = () => {
|
|
83
|
+
let installed = false;
|
|
84
|
+
return {
|
|
85
|
+
alias: 'linker',
|
|
86
|
+
start: opts => {
|
|
87
|
+
if (typeof document === 'undefined' || installed || opts.linker == null) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
installed = true;
|
|
91
|
+
const onNavigate = (event) => {
|
|
92
|
+
const target = event.target;
|
|
93
|
+
const anchor = target instanceof Element ? target.closest('a[href]') : null;
|
|
94
|
+
if (!(anchor instanceof HTMLAnchorElement)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// The trust rule keeps `noreferrer` links untouched: a link that refuses to disclose the
|
|
98
|
+
// referrer is refusing exactly the signal the receiving side's `adopt` needs to trust it.
|
|
99
|
+
if (/\bnoreferrer\b/.test(anchor.getAttribute('rel') ?? '')) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const record = readConsent(opts);
|
|
103
|
+
if (record == null) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let url;
|
|
107
|
+
try {
|
|
108
|
+
url = new URL(anchor.href, location.href);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const decorated = decorateConsentUrl(url, record, opts);
|
|
114
|
+
if (decorated.toString() !== url.toString()) {
|
|
115
|
+
anchor.href = decorated.toString();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
// Capture phase: this must decide before the click's own navigation (or a framework router
|
|
119
|
+
// intercepting it) reads `href`. `auxclick`/`contextmenu` cover a middle-click and "copy link
|
|
120
|
+
// address" — an address copied undecorated is a link that silently fails to carry the choice.
|
|
121
|
+
document.addEventListener('click', onNavigate, true);
|
|
122
|
+
document.addEventListener('auxclick', onNavigate, true);
|
|
123
|
+
document.addEventListener('contextmenu', onNavigate, true);
|
|
124
|
+
},
|
|
125
|
+
decorate: (url, record, opts) => {
|
|
126
|
+
const linker = opts.linker;
|
|
127
|
+
const host = typeof location !== 'undefined' ? location.hostname : '';
|
|
128
|
+
if (linker == null || url.hostname === host || !linker.domains.includes(url.hostname)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const next = new URL(url.toString());
|
|
132
|
+
next.searchParams.set(linker.param ?? CONSENT_LINK_PARAM, encodeConsentLink(record, opts));
|
|
133
|
+
return next;
|
|
134
|
+
},
|
|
135
|
+
adopt: opts => {
|
|
136
|
+
const linker = opts.linker;
|
|
137
|
+
if (linker == null || typeof location === 'undefined') {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const raw = new URLSearchParams(location.search).get(linker.param ?? CONSENT_LINK_PARAM);
|
|
141
|
+
if (raw == null) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const decoded = decodeConsentLink(raw);
|
|
145
|
+
if (decoded == null) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const now = Math.floor(Date.now() / 1000);
|
|
149
|
+
const maxAge = linker.maxAge ?? CONSENT_LINK_MAX_AGE;
|
|
150
|
+
if (now - decoded.t > maxAge || decoded.t - now > CONSENT_LINK_SKEW) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
const referrer = referrerHostname();
|
|
154
|
+
if (referrer == null || !linker.domains.includes(referrer)) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
const optional = optionalOf(opts);
|
|
158
|
+
if (!optional.every(category => decoded.c[category.key] === 0 || decoded.c[category.key] === 1)) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const record = { v: CONSENT_SCHEMA_VERSION };
|
|
162
|
+
for (const category of categoriesOf(opts)) {
|
|
163
|
+
record[category.key] = category.required === true || decoded.c[category.key] === 1;
|
|
164
|
+
}
|
|
165
|
+
return record;
|
|
166
|
+
},
|
|
167
|
+
domains: opts => opts.linker?.domains ?? [],
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Remove the link parameter from the visible URL, keeping every other parameter and the hash — the
|
|
172
|
+
* real-TS equivalent of what {@link consentLinkerScript}'s embedded fragment already did inline.
|
|
173
|
+
* Idempotent: a page with no head script calls this from `consentStore.init` and it strips once; a
|
|
174
|
+
* page that ALSO carried the head script finds the parameter already gone and does nothing.
|
|
175
|
+
*/
|
|
176
|
+
export const stripConsentLinkParam = (opts) => {
|
|
177
|
+
const linker = opts.linker;
|
|
178
|
+
if (linker == null || typeof location === 'undefined' || typeof history === 'undefined') {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const param = linker.param ?? CONSENT_LINK_PARAM;
|
|
182
|
+
const url = new URL(location.href);
|
|
183
|
+
if (!url.searchParams.has(param)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
url.searchParams.delete(param);
|
|
187
|
+
try {
|
|
188
|
+
history.replaceState(history.state, '', `${url.pathname}${url.search}${url.hash}`);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// A sandboxed/embedded context may refuse history writes; the parameter just stays visible.
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* The inline `<head>` fragment that adopts a decorated link's decision and strips the parameter —
|
|
196
|
+
* standalone, so a page can stamp it even where nothing else here runs (a legal page with no tag
|
|
197
|
+
* script). `@owlmeans/web-gtm`'s `consentBootstrapScript` embeds this SAME fragment right after
|
|
198
|
+
* pushing Consent Mode's defaults, so a page that has both never runs it twice with different
|
|
199
|
+
* effect — the second attempt finds the parameter already gone and does nothing.
|
|
200
|
+
*
|
|
201
|
+
* Mirrors `consentLinker().adopt` exactly (v2, referrer + freshness/skew + full optional coverage +
|
|
202
|
+
* no existing record), but as hand-rolled JS text rather than a call into this module — the same
|
|
203
|
+
* discipline `consentBootstrapScript`/`consentGateScript` already follow, because this has to run
|
|
204
|
+
* before any bundle (this module included) has loaded. The parameter is ALWAYS stripped via
|
|
205
|
+
* `history.replaceState`, whether or not the trust rule accepts it: a stale or foreign `owlcc` is
|
|
206
|
+
* exactly as much noise as an adopted one, and neither belongs in the visible URL or in what a page
|
|
207
|
+
* reload, a shared link or a browser history entry carries forward.
|
|
208
|
+
*/
|
|
209
|
+
export const consentLinkerScript = (opts) => {
|
|
210
|
+
const linker = opts.linker;
|
|
211
|
+
if (linker == null) {
|
|
212
|
+
return '';
|
|
213
|
+
}
|
|
214
|
+
const param = jsonForScript(linker.param ?? CONSENT_LINK_PARAM);
|
|
215
|
+
const domains = jsonForScript(linker.domains);
|
|
216
|
+
const storageKey = jsonForScript(opts.storageKey ?? CONSENT_KEY);
|
|
217
|
+
const optionalKeys = jsonForScript(optionalOf(opts).map(category => category.key));
|
|
218
|
+
const allCategories = jsonForScript(categoriesOf(opts).map(category => ({ key: category.key, required: category.required === true })));
|
|
219
|
+
const maxAge = linker.maxAge ?? CONSENT_LINK_MAX_AGE;
|
|
220
|
+
const skew = CONSENT_LINK_SKEW;
|
|
221
|
+
const cookieDays = opts.cookieDays ?? CONSENT_COOKIE_DAYS;
|
|
222
|
+
const version = CONSENT_LINK_VERSION;
|
|
223
|
+
return `(function(w,d){` +
|
|
224
|
+
`var p=${param};var qs;try{qs=new URLSearchParams(location.search)}catch(e){return}` +
|
|
225
|
+
`var raw=qs.get(p);if(raw==null)return;` +
|
|
226
|
+
`qs.delete(p);var rest=qs.toString();` +
|
|
227
|
+
`var url=location.pathname+(rest?('?'+rest):'')+location.hash;` +
|
|
228
|
+
`try{history.replaceState(history.state,'',url)}catch(e){}` +
|
|
229
|
+
`try{` +
|
|
230
|
+
`var b=raw.replace(/-/g,'+').replace(/_/g,'/');while(b.length%4)b+='=';` +
|
|
231
|
+
`var j=JSON.parse(atob(b));` +
|
|
232
|
+
`if(!j||j.v!==${version}||typeof j.t!=='number'||!j.c||typeof j.c!=='object')return;` +
|
|
233
|
+
`var now=Math.floor(Date.now()/1000);` +
|
|
234
|
+
`if(now-j.t>${maxAge}||j.t-now>${skew})return;` +
|
|
235
|
+
`var ref=null;try{ref=new URL(d.referrer).hostname}catch(e){}` +
|
|
236
|
+
`if(!ref||${domains}.indexOf(ref)<0)return;` +
|
|
237
|
+
`var keys=${optionalKeys};` +
|
|
238
|
+
`for(var i=0;i<keys.length;i++){if(j.c[keys[i]]!==0&&j.c[keys[i]]!==1)return}` +
|
|
239
|
+
`var existing=null;try{existing=w.localStorage.getItem(${storageKey})}catch(e){}` +
|
|
240
|
+
`if(!existing){var cp=('; '+d.cookie).split('; '+${storageKey}+'=');` +
|
|
241
|
+
`if(cp.length===2)existing=cp.pop().split(';').shift()}` +
|
|
242
|
+
`if(existing)return;` +
|
|
243
|
+
`var cats=${allCategories},rec={v:${version}};` +
|
|
244
|
+
`for(var k=0;k<cats.length;k++){var c=cats[k];rec[c.key]=c.required||j.c[c.key]===1}` +
|
|
245
|
+
`var val=JSON.stringify(rec);` +
|
|
246
|
+
`try{w.localStorage.setItem(${storageKey},val)}catch(e){}` +
|
|
247
|
+
`var exp=new Date(Date.now()+${cookieDays}*86400000).toUTCString();` +
|
|
248
|
+
`d.cookie=${storageKey}+'='+val+';expires='+exp+';path=/;SameSite=Lax'` +
|
|
249
|
+
`}catch(e){}` +
|
|
250
|
+
`})(window,document)`;
|
|
251
|
+
};
|
|
252
|
+
//# sourceMappingURL=linker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linker.js","sourceRoot":"","sources":["../src/linker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAElH,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C,sFAAsF;AACtF,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAA;AACzC,wGAAwG;AACxG,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAA;AACvC,oGAAoG;AACpG,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAEnC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AAW9B,MAAM,YAAY,GAAG,CAAC,IAAqB,EAAqB,EAAE,CAChE,IAAI,EAAE,UAAU,IAAI,0BAA0B,CAAA;AAEhD,MAAM,UAAU,GAAG,CAAC,IAAqB,EAAqB,EAAE,CAC9D,YAAY,CAAC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sE;QACpF,wCAAwC;QACxC,sCAAsC;QACtC,+DAA+D;QAC/D,2DAA2D;QAC3D,MAAM;QACJ,wEAAwE;QACxE,4BAA4B;QAC5B,gBAAgB,OAAO,8DAA8D;QACrF,sCAAsC;QACtC,cAAc,MAAM,aAAa,IAAI,UAAU;QAC/C,8DAA8D;QAC9D,YAAY,OAAO,yBAAyB;QAC5C,YAAY,YAAY,GAAG;QAC3B,8EAA8E;QAC9E,yDAAyD,UAAU,cAAc;QACjF,mDAAmD,UAAU,QAAQ;QACnE,wDAAwD;QAC1D,qBAAqB;QACrB,YAAY,aAAa,WAAW,OAAO,IAAI;QAC/C,qFAAqF;QACrF,8BAA8B;QAC9B,8BAA8B,UAAU,kBAAkB;QAC1D,+BAA+B,UAAU,2BAA2B;QACpE,YAAY,UAAU,iDAAiD;QACzE,aAAa;QACf,qBAAqB,CAAA;AACvB,CAAC,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ConsentOptions, ConsentRecord } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* An extension seam for `@owlmeans/consent`: something that reacts to this document's consent
|
|
4
|
+
* decision, or supplies one from elsewhere, without the core store knowing anything about where
|
|
5
|
+
* that decision came from.
|
|
6
|
+
*
|
|
7
|
+
* `consentLinker` (`./linker.js`) is the one built-in plugin — cross-domain consent through
|
|
8
|
+
* decorated links — but nothing here is specific to it. A registry rather than a fixed option on
|
|
9
|
+
* `ConsentOptions` because the store has zero dependencies today and stays that way: a plugin is
|
|
10
|
+
* opt-in code an application imports for its own reason, never a bundled feature this package
|
|
11
|
+
* pulls in whether or not anything uses it.
|
|
12
|
+
*/
|
|
13
|
+
export interface ConsentPlugin {
|
|
14
|
+
/** Stable identity. Registering the same alias again REPLACES the earlier plugin. */
|
|
15
|
+
alias: string;
|
|
16
|
+
/** Run order when more than one plugin implements the same hook. Higher first. Defaults to 0. */
|
|
17
|
+
priority?: number;
|
|
18
|
+
/** Installed once, the first time `consentStore.init` runs with this plugin registered. */
|
|
19
|
+
start?: (opts: ConsentOptions) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Offer a decision from outside this document's own storage — e.g. one carried on the URL that
|
|
22
|
+
* led here. Returns a full record to adopt, or `null` to defer to the next plugin / the ordinary
|
|
23
|
+
* "ask" path. Never called once a stored record already exists.
|
|
24
|
+
*/
|
|
25
|
+
adopt?: (opts: ConsentOptions) => ConsentRecord | null;
|
|
26
|
+
/**
|
|
27
|
+
* Rewrite an outgoing URL to carry this document's current decision, or `null` to leave it
|
|
28
|
+
* untouched (a foreign host, a link that opts out, nothing to carry yet).
|
|
29
|
+
*/
|
|
30
|
+
decorate?: (url: URL, record: ConsentRecord, opts: ConsentOptions) => URL | null;
|
|
31
|
+
/** Extra domains this decision is understood to apply to, for disclosure — never deduplicated here. */
|
|
32
|
+
domains?: (opts: ConsentOptions) => string[];
|
|
33
|
+
}
|
|
34
|
+
/** Register a plugin. Replace-by-alias; sorted by priority (higher first) on every read. */
|
|
35
|
+
export declare const registerConsentPlugin: (plugin: ConsentPlugin) => void;
|
|
36
|
+
/** Every registered plugin, priority-sorted (higher first, ties keep insertion order). */
|
|
37
|
+
export declare const consentPlugins: () => ConsentPlugin[];
|
|
38
|
+
/**
|
|
39
|
+
* Ask every registered plugin to decorate `url` with this document's decision, in priority order,
|
|
40
|
+
* stopping at the first one that actually changes it. A plugin whose own rules refuse (a foreign
|
|
41
|
+
* host, a `noreferrer` link, no local decision yet) returns `null` and is skipped, not an error.
|
|
42
|
+
*/
|
|
43
|
+
export declare const decorateConsentUrl: (url: string | URL, record: ConsentRecord, opts: ConsentOptions) => URL;
|
|
44
|
+
/**
|
|
45
|
+
* Every domain this document's decision is disclosed to, current host first, deduplicated — what a
|
|
46
|
+
* dialog or a policy page lists. A plugin that runs on this host but names no domains of its own
|
|
47
|
+
* (nothing registered, or `domains` not implemented) leaves the list at just the current host,
|
|
48
|
+
* which is always correct to show even with no plugin at all.
|
|
49
|
+
*/
|
|
50
|
+
export declare const consentDomains: (opts: ConsentOptions) => string[];
|
|
51
|
+
/** Try every registered plugin's `adopt`, in priority order, and use the first decision offered. */
|
|
52
|
+
export declare const adoptConsent: (opts: ConsentOptions) => ConsentRecord | null;
|
|
53
|
+
/** Run every registered plugin's `start`, in priority order. `consentStore.init` calls this once. */
|
|
54
|
+
export declare const startConsentPlugins: (opts: ConsentOptions) => void;
|
|
55
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B,qFAAqF;IACrF,KAAK,EAAE,MAAM,CAAA;IACb,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAA;IACtC;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,aAAa,GAAG,IAAI,CAAA;IACtD;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,KAAK,GAAG,GAAG,IAAI,CAAA;IAChF,uGAAuG;IACvG,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,MAAM,EAAE,CAAA;CAC7C;AASD,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,WAAY,aAAa,KAAG,IAE7D,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,cAAc,QAAO,aAAa,EAC8B,CAAA;AAE7E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QACxB,MAAM,GAAG,GAAG,UAAU,aAAa,QAAQ,cAAc,KAC7D,GAaF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,SAAU,cAAc,KAAG,MAAM,EAK3D,CAAA;AAED,oGAAoG;AACpG,eAAO,MAAM,YAAY,SAAU,cAAc,KAAG,aAAa,GAAG,IASnE,CAAA;AAED,qGAAqG;AACrG,eAAO,MAAM,mBAAmB,SAAU,cAAc,KAAG,IAI1D,CAAA"}
|
package/build/plugins.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-global by design, like `@owlmeans/client-auth/login`'s method/step registries: consent is
|
|
3
|
+
* one thing per document, not per component tree, and a plugin is installed once at bundle scope
|
|
4
|
+
* (an Astro island, a script tag, a React app) regardless of how many components read the store.
|
|
5
|
+
*/
|
|
6
|
+
const plugins = new Map();
|
|
7
|
+
/** Register a plugin. Replace-by-alias; sorted by priority (higher first) on every read. */
|
|
8
|
+
export const registerConsentPlugin = (plugin) => {
|
|
9
|
+
plugins.set(plugin.alias, plugin);
|
|
10
|
+
};
|
|
11
|
+
/** Every registered plugin, priority-sorted (higher first, ties keep insertion order). */
|
|
12
|
+
export const consentPlugins = () => [...plugins.values()].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
13
|
+
/**
|
|
14
|
+
* Ask every registered plugin to decorate `url` with this document's decision, in priority order,
|
|
15
|
+
* stopping at the first one that actually changes it. A plugin whose own rules refuse (a foreign
|
|
16
|
+
* host, a `noreferrer` link, no local decision yet) returns `null` and is skipped, not an error.
|
|
17
|
+
*/
|
|
18
|
+
export const decorateConsentUrl = (url, record, opts) => {
|
|
19
|
+
let result = url instanceof URL ? url : new URL(url);
|
|
20
|
+
for (const plugin of consentPlugins()) {
|
|
21
|
+
if (plugin.decorate == null) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const decorated = plugin.decorate(result, record, opts);
|
|
25
|
+
if (decorated != null) {
|
|
26
|
+
result = decorated;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Every domain this document's decision is disclosed to, current host first, deduplicated — what a
|
|
33
|
+
* dialog or a policy page lists. A plugin that runs on this host but names no domains of its own
|
|
34
|
+
* (nothing registered, or `domains` not implemented) leaves the list at just the current host,
|
|
35
|
+
* which is always correct to show even with no plugin at all.
|
|
36
|
+
*/
|
|
37
|
+
export const consentDomains = (opts) => {
|
|
38
|
+
const host = typeof location !== 'undefined' ? location.hostname : '';
|
|
39
|
+
const named = consentPlugins().flatMap(plugin => plugin.domains?.(opts) ?? []);
|
|
40
|
+
return [...new Set([host, ...named].filter(domain => domain !== ''))];
|
|
41
|
+
};
|
|
42
|
+
/** Try every registered plugin's `adopt`, in priority order, and use the first decision offered. */
|
|
43
|
+
export const adoptConsent = (opts) => {
|
|
44
|
+
for (const plugin of consentPlugins()) {
|
|
45
|
+
const adopted = plugin.adopt?.(opts);
|
|
46
|
+
if (adopted != null) {
|
|
47
|
+
return adopted;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
/** Run every registered plugin's `start`, in priority order. `consentStore.init` calls this once. */
|
|
53
|
+
export const startConsentPlugins = (opts) => {
|
|
54
|
+
for (const plugin of consentPlugins()) {
|
|
55
|
+
plugin.start?.(opts);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAmCA;;;;GAIG;AACH,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAA;AAEhD,4FAA4F;AAC5F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAqB,EAAQ,EAAE;IACnE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AACnC,CAAC,CAAA;AAED,0FAA0F;AAC1F,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