@referalli/sdk 0.0.0-stage → 0.3.20

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.
Files changed (184) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/LICENSE +21 -0
  3. package/README.md +236 -2
  4. package/dist/cjs/attribution.d.ts +105 -0
  5. package/dist/cjs/attribution.js +200 -0
  6. package/dist/cjs/browser.d.ts +41 -0
  7. package/dist/cjs/browser.js +88 -0
  8. package/dist/cjs/client.d.ts +97 -0
  9. package/dist/cjs/client.js +301 -0
  10. package/dist/cjs/consent/adapters/cookiebot.d.ts +7 -0
  11. package/dist/cjs/consent/adapters/cookiebot.js +49 -0
  12. package/dist/cjs/consent/adapters/cookiemunch.d.ts +8 -0
  13. package/dist/cjs/consent/adapters/cookiemunch.js +56 -0
  14. package/dist/cjs/consent/adapters/custom.d.ts +8 -0
  15. package/dist/cjs/consent/adapters/custom.js +39 -0
  16. package/dist/cjs/consent/adapters/didomi.d.ts +9 -0
  17. package/dist/cjs/consent/adapters/didomi.js +67 -0
  18. package/dist/cjs/consent/adapters/gcm.d.ts +10 -0
  19. package/dist/cjs/consent/adapters/gcm.js +78 -0
  20. package/dist/cjs/consent/adapters/gpp.d.ts +9 -0
  21. package/dist/cjs/consent/adapters/gpp.js +92 -0
  22. package/dist/cjs/consent/adapters/none.d.ts +3 -0
  23. package/dist/cjs/consent/adapters/none.js +30 -0
  24. package/dist/cjs/consent/adapters/onetrust.d.ts +8 -0
  25. package/dist/cjs/consent/adapters/onetrust.js +71 -0
  26. package/dist/cjs/consent/adapters/osano.d.ts +9 -0
  27. package/dist/cjs/consent/adapters/osano.js +71 -0
  28. package/dist/cjs/consent/adapters/tcf.d.ts +8 -0
  29. package/dist/cjs/consent/adapters/tcf.js +79 -0
  30. package/dist/cjs/consent/adapters/termly.d.ts +10 -0
  31. package/dist/cjs/consent/adapters/termly.js +61 -0
  32. package/dist/cjs/consent/adapters/usercentrics.d.ts +9 -0
  33. package/dist/cjs/consent/adapters/usercentrics.js +106 -0
  34. package/dist/cjs/consent/conformance.d.ts +22 -0
  35. package/dist/cjs/consent/conformance.js +33 -0
  36. package/dist/cjs/consent/gate.d.ts +23 -0
  37. package/dist/cjs/consent/gate.js +220 -0
  38. package/dist/cjs/consent/port.d.ts +105 -0
  39. package/dist/cjs/consent/port.js +72 -0
  40. package/dist/cjs/consent/registry.d.ts +17 -0
  41. package/dist/cjs/consent/registry.js +61 -0
  42. package/dist/cjs/consent/served.d.ts +15 -0
  43. package/dist/cjs/consent/served.js +26 -0
  44. package/dist/cjs/core.d.ts +77 -0
  45. package/dist/cjs/core.js +64 -0
  46. package/dist/cjs/errors.d.ts +42 -0
  47. package/dist/cjs/errors.generated.d.ts +183 -0
  48. package/dist/cjs/errors.generated.js +279 -0
  49. package/dist/cjs/errors.js +47 -0
  50. package/dist/cjs/generated.d.ts +15146 -0
  51. package/dist/cjs/generated.js +625 -0
  52. package/dist/cjs/index.d.ts +22 -0
  53. package/dist/cjs/index.js +93 -0
  54. package/dist/cjs/mobile.d.ts +66 -0
  55. package/dist/cjs/mobile.js +69 -0
  56. package/dist/cjs/node.d.ts +209 -0
  57. package/dist/cjs/node.js +140 -0
  58. package/dist/cjs/outbox.d.ts +186 -0
  59. package/dist/cjs/outbox.js +324 -0
  60. package/dist/cjs/package.json +3 -0
  61. package/dist/cjs/resources.generated.d.ts +6002 -0
  62. package/dist/cjs/resources.generated.js +2090 -0
  63. package/dist/cjs/served.d.ts +25 -0
  64. package/dist/cjs/served.js +214 -0
  65. package/dist/cjs/sha256.d.ts +2 -0
  66. package/dist/cjs/sha256.js +86 -0
  67. package/dist/cjs/snippet.d.ts +99 -0
  68. package/dist/cjs/snippet.js +213 -0
  69. package/dist/cjs/stripe-events.d.ts +25 -0
  70. package/dist/cjs/stripe-events.js +117 -0
  71. package/dist/cjs/version.d.ts +2 -0
  72. package/dist/cjs/version.js +5 -0
  73. package/dist/cjs/webhooks.d.ts +76 -0
  74. package/dist/cjs/webhooks.js +159 -0
  75. package/dist/esm/attribution.d.ts +105 -0
  76. package/dist/esm/attribution.js +186 -0
  77. package/dist/esm/browser.d.ts +41 -0
  78. package/dist/esm/browser.js +68 -0
  79. package/dist/esm/client.d.ts +97 -0
  80. package/dist/esm/client.js +297 -0
  81. package/dist/esm/consent/adapters/cookiebot.d.ts +7 -0
  82. package/dist/esm/consent/adapters/cookiebot.js +46 -0
  83. package/dist/esm/consent/adapters/cookiemunch.d.ts +8 -0
  84. package/dist/esm/consent/adapters/cookiemunch.js +53 -0
  85. package/dist/esm/consent/adapters/custom.d.ts +8 -0
  86. package/dist/esm/consent/adapters/custom.js +36 -0
  87. package/dist/esm/consent/adapters/didomi.d.ts +9 -0
  88. package/dist/esm/consent/adapters/didomi.js +64 -0
  89. package/dist/esm/consent/adapters/gcm.d.ts +10 -0
  90. package/dist/esm/consent/adapters/gcm.js +75 -0
  91. package/dist/esm/consent/adapters/gpp.d.ts +9 -0
  92. package/dist/esm/consent/adapters/gpp.js +89 -0
  93. package/dist/esm/consent/adapters/none.d.ts +3 -0
  94. package/dist/esm/consent/adapters/none.js +27 -0
  95. package/dist/esm/consent/adapters/onetrust.d.ts +8 -0
  96. package/dist/esm/consent/adapters/onetrust.js +68 -0
  97. package/dist/esm/consent/adapters/osano.d.ts +9 -0
  98. package/dist/esm/consent/adapters/osano.js +68 -0
  99. package/dist/esm/consent/adapters/tcf.d.ts +8 -0
  100. package/dist/esm/consent/adapters/tcf.js +76 -0
  101. package/dist/esm/consent/adapters/termly.d.ts +10 -0
  102. package/dist/esm/consent/adapters/termly.js +58 -0
  103. package/dist/esm/consent/adapters/usercentrics.d.ts +9 -0
  104. package/dist/esm/consent/adapters/usercentrics.js +103 -0
  105. package/dist/esm/consent/conformance.d.ts +22 -0
  106. package/dist/esm/consent/conformance.js +30 -0
  107. package/dist/esm/consent/gate.d.ts +23 -0
  108. package/dist/esm/consent/gate.js +217 -0
  109. package/dist/esm/consent/port.d.ts +105 -0
  110. package/dist/esm/consent/port.js +67 -0
  111. package/dist/esm/consent/registry.d.ts +17 -0
  112. package/dist/esm/consent/registry.js +55 -0
  113. package/dist/esm/consent/served.d.ts +15 -0
  114. package/dist/esm/consent/served.js +22 -0
  115. package/dist/esm/core.d.ts +77 -0
  116. package/dist/esm/core.js +60 -0
  117. package/dist/esm/errors.d.ts +42 -0
  118. package/dist/esm/errors.generated.d.ts +183 -0
  119. package/dist/esm/errors.generated.js +231 -0
  120. package/dist/esm/errors.js +40 -0
  121. package/dist/esm/generated.d.ts +15146 -0
  122. package/dist/esm/generated.js +622 -0
  123. package/dist/esm/index.d.ts +22 -0
  124. package/dist/esm/index.js +22 -0
  125. package/dist/esm/mobile.d.ts +66 -0
  126. package/dist/esm/mobile.js +64 -0
  127. package/dist/esm/node.d.ts +209 -0
  128. package/dist/esm/node.js +135 -0
  129. package/dist/esm/outbox.d.ts +186 -0
  130. package/dist/esm/outbox.js +316 -0
  131. package/dist/esm/package.json +3 -0
  132. package/dist/esm/resources.generated.d.ts +6002 -0
  133. package/dist/esm/resources.generated.js +2086 -0
  134. package/dist/esm/served.d.ts +25 -0
  135. package/dist/esm/served.js +207 -0
  136. package/dist/esm/sha256.d.ts +2 -0
  137. package/dist/esm/sha256.js +82 -0
  138. package/dist/esm/snippet.d.ts +99 -0
  139. package/dist/esm/snippet.js +210 -0
  140. package/dist/esm/stripe-events.d.ts +25 -0
  141. package/dist/esm/stripe-events.js +114 -0
  142. package/dist/esm/version.d.ts +2 -0
  143. package/dist/esm/version.js +2 -0
  144. package/dist/esm/webhooks.d.ts +76 -0
  145. package/dist/esm/webhooks.js +153 -0
  146. package/dist/tsconfig.build.tsbuildinfo +1 -0
  147. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  148. package/package.json +105 -4
  149. package/src/attribution.ts +216 -0
  150. package/src/browser.ts +107 -0
  151. package/src/client.ts +351 -0
  152. package/src/codegen.ts +130 -0
  153. package/src/consent/adapters/cookiebot.ts +42 -0
  154. package/src/consent/adapters/cookiemunch.ts +49 -0
  155. package/src/consent/adapters/custom.ts +37 -0
  156. package/src/consent/adapters/didomi.ts +59 -0
  157. package/src/consent/adapters/gcm.ts +68 -0
  158. package/src/consent/adapters/gpp.ts +81 -0
  159. package/src/consent/adapters/none.ts +28 -0
  160. package/src/consent/adapters/onetrust.ts +64 -0
  161. package/src/consent/adapters/osano.ts +63 -0
  162. package/src/consent/adapters/tcf.ts +67 -0
  163. package/src/consent/adapters/termly.ts +54 -0
  164. package/src/consent/adapters/usercentrics.ts +97 -0
  165. package/src/consent/conformance.ts +47 -0
  166. package/src/consent/gate.ts +216 -0
  167. package/src/consent/port.ts +148 -0
  168. package/src/consent/registry.ts +60 -0
  169. package/src/consent/served.ts +24 -0
  170. package/src/core.ts +127 -0
  171. package/src/errors.generated.ts +277 -0
  172. package/src/errors.ts +57 -0
  173. package/src/generated.ts +14540 -0
  174. package/src/index.ts +100 -0
  175. package/src/mobile.ts +96 -0
  176. package/src/node.ts +291 -0
  177. package/src/outbox.ts +452 -0
  178. package/src/resources.generated.ts +2097 -0
  179. package/src/served.ts +229 -0
  180. package/src/sha256.ts +82 -0
  181. package/src/snippet.ts +305 -0
  182. package/src/stripe-events.ts +130 -0
  183. package/src/version.ts +2 -0
  184. package/src/webhooks.ts +207 -0
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gpp = void 0;
4
+ const port_js_1 = require("../port.js");
5
+ /**
6
+ * IAB GPP: `__gpp('addEventListener', cb)` and `__gpp('ping', cb)`. Waits for
7
+ * `signalStatus: 'ready'`. The EU TCF section (id 2) follows the `tcf`
8
+ * rules (purpose 1 plus 7 or 9); US state sections are opt-out, so any
9
+ * `SaleOptOut`, `SharingOptOut` or `TargetedAdvertisingOptOut` of 1 (opted
10
+ * out) denies and anything else grants. Evidence: `gppString`.
11
+ */
12
+ exports.gpp = {
13
+ id: 'gpp',
14
+ name: 'IAB GPP',
15
+ defaultCategory: null,
16
+ status: 'beta',
17
+ docsUrl: 'https://referalli.com/docs/tracking-consent#gpp',
18
+ vendorDocsUrl: 'https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform',
19
+ check: (cfg) => (0, port_js_1.browserCheck)(exports.gpp, cfg),
20
+ factory: function gppConsent(w) {
21
+ let ping = null;
22
+ let listening = false;
23
+ const subs = [];
24
+ function set(p) {
25
+ if (!p || typeof p !== 'object')
26
+ return;
27
+ ping = p;
28
+ const list = subs.slice();
29
+ for (let i = 0; i < list.length; i++)
30
+ list[i]();
31
+ }
32
+ function listen() {
33
+ if (listening || typeof w.__gpp !== 'function')
34
+ return;
35
+ listening = true;
36
+ w.__gpp('addEventListener', function (ev, ok) {
37
+ if (ok !== false && ev)
38
+ set(ev.pingData || null);
39
+ });
40
+ w.__gpp('ping', function (p, ok) {
41
+ if (ok !== false)
42
+ set(p);
43
+ });
44
+ }
45
+ function seg(s) {
46
+ return Array.isArray(s) ? s[0] : s;
47
+ }
48
+ return {
49
+ detect() {
50
+ return typeof w.__gpp === 'function';
51
+ },
52
+ state() {
53
+ listen();
54
+ if (!ping || ping.signalStatus !== 'ready')
55
+ return 'unknown';
56
+ const secs = ping.parsedSections || {};
57
+ const applicable = ping.applicableSections || [];
58
+ const eu = seg(secs.tcfeuv2);
59
+ if (applicable.indexOf(2) >= 0 && eu) {
60
+ const pc = eu.PurposeConsent || [];
61
+ const p = function (n) {
62
+ return !!(pc[n - 1] === true || pc[n - 1] === 1);
63
+ };
64
+ return p(1) && (p(7) || p(9)) ? 'granted' : 'denied';
65
+ }
66
+ for (const k in secs) {
67
+ if (k === 'tcfeuv2' || k === 'tcfcav1')
68
+ continue;
69
+ const s = seg(secs[k]);
70
+ if (s && typeof s === 'object' && (s.SaleOptOut === 1 || s.SharingOptOut === 1 || s.TargetedAdvertisingOptOut === 1)) {
71
+ return 'denied';
72
+ }
73
+ }
74
+ return 'granted';
75
+ },
76
+ subscribe(_cfg, cb) {
77
+ subs.push(cb);
78
+ listen();
79
+ return function () {
80
+ const i = subs.indexOf(cb);
81
+ if (i >= 0)
82
+ subs.splice(i, 1);
83
+ };
84
+ },
85
+ evidence() {
86
+ if (!ping)
87
+ return null;
88
+ return { gppString: typeof ping.gppString === 'string' ? ping.gppString : undefined };
89
+ },
90
+ };
91
+ },
92
+ };
@@ -0,0 +1,3 @@
1
+ import { type ConsentSource } from '../port.js';
2
+ /** No consent check: always granted (the tracker before consent support). Only for sites that need no opt-in. */
3
+ export declare const none: ConsentSource;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.none = void 0;
4
+ const port_js_1 = require("../port.js");
5
+ /** No consent check: always granted (the tracker before consent support). Only for sites that need no opt-in. */
6
+ exports.none = {
7
+ id: 'none',
8
+ name: 'None (always store)',
9
+ defaultCategory: null,
10
+ status: 'ga',
11
+ docsUrl: 'https://referalli.com/docs/tracking-consent#choose-a-mode',
12
+ vendorDocsUrl: 'https://referalli.com/docs/tracking-consent#choose-a-mode',
13
+ check: (cfg) => (0, port_js_1.browserCheck)(exports.none, cfg),
14
+ factory: function noneConsent() {
15
+ return {
16
+ detect() {
17
+ return true;
18
+ },
19
+ state() {
20
+ return 'granted';
21
+ },
22
+ subscribe() {
23
+ return function () { };
24
+ },
25
+ evidence() {
26
+ return {};
27
+ },
28
+ };
29
+ },
30
+ };
@@ -0,0 +1,8 @@
1
+ import { type ConsentSource } from '../port.js';
2
+ /**
3
+ * OneTrust: `window.OnetrustActiveGroups` (",C0001,C0004,"),
4
+ * `OneTrust.OnConsentChanged` and the `OneTrustGroupsUpdated` window event.
5
+ * Group `C0004` (targeting) by default. An inactive group counts as denied
6
+ * only once the banner was closed (`OneTrust.IsAlertBoxClosed()`).
7
+ */
8
+ export declare const onetrust: ConsentSource;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onetrust = void 0;
4
+ const port_js_1 = require("../port.js");
5
+ /**
6
+ * OneTrust: `window.OnetrustActiveGroups` (",C0001,C0004,"),
7
+ * `OneTrust.OnConsentChanged` and the `OneTrustGroupsUpdated` window event.
8
+ * Group `C0004` (targeting) by default. An inactive group counts as denied
9
+ * only once the banner was closed (`OneTrust.IsAlertBoxClosed()`).
10
+ */
11
+ exports.onetrust = {
12
+ id: 'onetrust',
13
+ name: 'OneTrust',
14
+ defaultCategory: 'C0004',
15
+ status: 'ga',
16
+ docsUrl: 'https://referalli.com/docs/tracking-consent#onetrust',
17
+ vendorDocsUrl: 'https://developer.onetrust.com/',
18
+ check: (cfg) => (0, port_js_1.browserCheck)(exports.onetrust, cfg),
19
+ factory: function onetrustConsent(w) {
20
+ function groups() {
21
+ return typeof w.OnetrustActiveGroups === 'string' ? w.OnetrustActiveGroups : null;
22
+ }
23
+ return {
24
+ detect() {
25
+ return !!(w.OneTrust || w.OneTrustStub || groups() !== null);
26
+ },
27
+ state(cfg) {
28
+ const g = groups();
29
+ if (g === null)
30
+ return 'unknown';
31
+ if ((',' + g + ',').indexOf(',' + (cfg.category || 'C0004') + ',') >= 0)
32
+ return 'granted';
33
+ const ot = w.OneTrust;
34
+ const closed = ot && typeof ot.IsAlertBoxClosed === 'function'
35
+ ? ot.IsAlertBoxClosed() === true
36
+ : /(?:^|;\s*)OptanonAlertBoxClosed=/.test((w.document && w.document.cookie) || '');
37
+ return closed ? 'denied' : 'unknown';
38
+ },
39
+ subscribe(_cfg, cb) {
40
+ let off = false;
41
+ const fire = function () {
42
+ if (!off)
43
+ cb();
44
+ };
45
+ w.addEventListener('OneTrustGroupsUpdated', fire);
46
+ try {
47
+ if (w.OneTrust && typeof w.OneTrust.OnConsentChanged === 'function')
48
+ w.OneTrust.OnConsentChanged(fire);
49
+ }
50
+ catch {
51
+ /* the event covers it */
52
+ }
53
+ return function () {
54
+ off = true;
55
+ w.removeEventListener('OneTrustGroupsUpdated', fire);
56
+ };
57
+ },
58
+ evidence() {
59
+ const g = groups();
60
+ const out = { purposes: g ? g.split(',').filter(Boolean) : [] };
61
+ const ot = w.OneTrust;
62
+ if (ot && typeof ot.getDataSubjectId === 'function') {
63
+ const id = ot.getDataSubjectId();
64
+ if (id)
65
+ out.stamp = String(id);
66
+ }
67
+ return out;
68
+ },
69
+ };
70
+ },
71
+ };
@@ -0,0 +1,9 @@
1
+ import { type ConsentSource } from '../port.js';
2
+ /**
3
+ * Osano: `Osano.cm.getConsent()` (`MARKETING: 'ACCEPT' | 'DENY'`, …) and the
4
+ * `osano-cm-consent-saved` / `osano-cm-consent-changed` events. Category
5
+ * `MARKETING` by default. `DENY` counts as denied only once a choice was saved
6
+ * (the event, or Osano's `osano_consentmanager` record); before that it is
7
+ * Osano's opt-in default, so no decision.
8
+ */
9
+ export declare const osano: ConsentSource;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.osano = void 0;
4
+ const port_js_1 = require("../port.js");
5
+ /**
6
+ * Osano: `Osano.cm.getConsent()` (`MARKETING: 'ACCEPT' | 'DENY'`, …) and the
7
+ * `osano-cm-consent-saved` / `osano-cm-consent-changed` events. Category
8
+ * `MARKETING` by default. `DENY` counts as denied only once a choice was saved
9
+ * (the event, or Osano's `osano_consentmanager` record); before that it is
10
+ * Osano's opt-in default, so no decision.
11
+ */
12
+ exports.osano = {
13
+ id: 'osano',
14
+ name: 'Osano',
15
+ defaultCategory: 'MARKETING',
16
+ status: 'beta',
17
+ docsUrl: 'https://referalli.com/docs/tracking-consent#osano',
18
+ vendorDocsUrl: 'https://developers.osano.com/',
19
+ check: (cfg) => (0, port_js_1.browserCheck)(exports.osano, cfg),
20
+ factory: function osanoConsent(w) {
21
+ let saved = false;
22
+ function stored() {
23
+ try {
24
+ if (w.localStorage && w.localStorage.getItem('osano_consentmanager'))
25
+ return true;
26
+ }
27
+ catch {
28
+ /* storage blocked */
29
+ }
30
+ return /(?:^|;\s*)osano_consentmanager=/.test((w.document && w.document.cookie) || '');
31
+ }
32
+ return {
33
+ detect() {
34
+ return !!(w.Osano && w.Osano.cm);
35
+ },
36
+ state(cfg) {
37
+ const cm = w.Osano && w.Osano.cm;
38
+ if (!cm || typeof cm.getConsent !== 'function')
39
+ return 'unknown';
40
+ const c = cm.getConsent() || {};
41
+ if (c[cfg.category || 'MARKETING'] === 'ACCEPT')
42
+ return 'granted';
43
+ return saved || stored() ? 'denied' : 'unknown';
44
+ },
45
+ subscribe(_cfg, cb) {
46
+ let off = false;
47
+ const cm = w.Osano && w.Osano.cm;
48
+ const onSave = function () {
49
+ saved = true;
50
+ if (!off)
51
+ cb();
52
+ };
53
+ const onChange = function () {
54
+ if (!off)
55
+ cb();
56
+ };
57
+ if (cm && typeof cm.addEventListener === 'function') {
58
+ cm.addEventListener('osano-cm-consent-saved', onSave);
59
+ cm.addEventListener('osano-cm-consent-changed', onSave);
60
+ cm.addEventListener('osano-cm-initialized', onChange);
61
+ }
62
+ return function () {
63
+ off = true;
64
+ };
65
+ },
66
+ evidence(cfg) {
67
+ return { purposes: [cfg.category || 'MARKETING'] };
68
+ },
69
+ };
70
+ },
71
+ };
@@ -0,0 +1,8 @@
1
+ import { type ConsentSource } from '../port.js';
2
+ /**
3
+ * IAB TCF v2.2: `__tcfapi('addEventListener', 2, cb)`. Granted when purpose 1
4
+ * (store/access) and purpose 7 or 9 are consented (publisher or global
5
+ * purpose consent), or, when `tcfVendorId` is set, purpose 1 plus that
6
+ * vendor's consent. `gdprApplies: false` is granted. Evidence: `tcString`.
7
+ */
8
+ export declare const tcf: ConsentSource;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tcf = void 0;
4
+ const port_js_1 = require("../port.js");
5
+ /**
6
+ * IAB TCF v2.2: `__tcfapi('addEventListener', 2, cb)`. Granted when purpose 1
7
+ * (store/access) and purpose 7 or 9 are consented (publisher or global
8
+ * purpose consent), or, when `tcfVendorId` is set, purpose 1 plus that
9
+ * vendor's consent. `gdprApplies: false` is granted. Evidence: `tcString`.
10
+ */
11
+ exports.tcf = {
12
+ id: 'tcf',
13
+ name: 'IAB TCF v2.2',
14
+ defaultCategory: 'purposes 1 + 7/9',
15
+ status: 'ga',
16
+ docsUrl: 'https://referalli.com/docs/tracking-consent#tcf',
17
+ vendorDocsUrl: 'https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework',
18
+ check: (cfg) => (0, port_js_1.browserCheck)(exports.tcf, cfg),
19
+ factory: function tcfConsent(w) {
20
+ let data = null;
21
+ let listening = false;
22
+ const subs = [];
23
+ function listen() {
24
+ if (listening || typeof w.__tcfapi !== 'function')
25
+ return;
26
+ listening = true;
27
+ w.__tcfapi('addEventListener', 2, function (tc, ok) {
28
+ if (ok === false || !tc)
29
+ return;
30
+ data = tc;
31
+ const list = subs.slice();
32
+ for (let i = 0; i < list.length; i++)
33
+ list[i]();
34
+ });
35
+ }
36
+ function has(n) {
37
+ const pur = (data && data.purpose && data.purpose.consents) || {};
38
+ const pub = (data && data.publisher && data.publisher.consents) || {};
39
+ return !!(pur[n] || pub[n]);
40
+ }
41
+ return {
42
+ detect() {
43
+ return typeof w.__tcfapi === 'function';
44
+ },
45
+ state(cfg) {
46
+ listen();
47
+ if (!data)
48
+ return 'unknown';
49
+ if (data.gdprApplies === false)
50
+ return 'granted';
51
+ if (data.eventStatus !== 'tcloaded' && data.eventStatus !== 'useractioncomplete')
52
+ return 'unknown';
53
+ if (cfg.tcfVendorId) {
54
+ const vc = (data.vendor && data.vendor.consents) || {};
55
+ return has(1) && vc[cfg.tcfVendorId] ? 'granted' : 'denied';
56
+ }
57
+ return has(1) && (has(7) || has(9)) ? 'granted' : 'denied';
58
+ },
59
+ subscribe(_cfg, cb) {
60
+ subs.push(cb);
61
+ listen();
62
+ return function () {
63
+ const i = subs.indexOf(cb);
64
+ if (i >= 0)
65
+ subs.splice(i, 1);
66
+ };
67
+ },
68
+ evidence() {
69
+ if (!data)
70
+ return null;
71
+ const purposes = [];
72
+ for (let n = 1; n <= 11; n++)
73
+ if (has(n))
74
+ purposes.push(String(n));
75
+ return { tcString: typeof data.tcString === 'string' ? data.tcString : undefined, purposes };
76
+ },
77
+ };
78
+ },
79
+ };
@@ -0,0 +1,10 @@
1
+ import { type ConsentSource } from '../port.js';
2
+ /**
3
+ * Termly: `Termly.getConsentState()` (`{ advertising: true, … }`) and
4
+ * `Termly.on('consent' | 'initialized', cb)`. Category `advertising` by
5
+ * default. A category that isn't true counts as denied only after a consent
6
+ * event on this page, so a returning visitor who declined stays memory-only
7
+ * (never stored) rather than being read as granted. Shape per Termly's
8
+ * consent API docs; not yet checked against a live Termly site.
9
+ */
10
+ export declare const termly: ConsentSource;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.termly = void 0;
4
+ const port_js_1 = require("../port.js");
5
+ /**
6
+ * Termly: `Termly.getConsentState()` (`{ advertising: true, … }`) and
7
+ * `Termly.on('consent' | 'initialized', cb)`. Category `advertising` by
8
+ * default. A category that isn't true counts as denied only after a consent
9
+ * event on this page, so a returning visitor who declined stays memory-only
10
+ * (never stored) rather than being read as granted. Shape per Termly's
11
+ * consent API docs; not yet checked against a live Termly site.
12
+ */
13
+ exports.termly = {
14
+ id: 'termly',
15
+ name: 'Termly',
16
+ defaultCategory: 'advertising',
17
+ status: 'beta',
18
+ docsUrl: 'https://referalli.com/docs/tracking-consent#termly',
19
+ vendorDocsUrl: 'https://termly.io/',
20
+ check: (cfg) => (0, port_js_1.browserCheck)(exports.termly, cfg),
21
+ factory: function termlyConsent(w) {
22
+ let decided = false;
23
+ return {
24
+ detect() {
25
+ return !!w.Termly;
26
+ },
27
+ state(cfg) {
28
+ const t = w.Termly;
29
+ if (!t || typeof t.getConsentState !== 'function')
30
+ return 'unknown';
31
+ const s = t.getConsentState();
32
+ if (!s || typeof s !== 'object')
33
+ return 'unknown';
34
+ if (s[cfg.category || 'advertising'] === true)
35
+ return 'granted';
36
+ return decided ? 'denied' : 'unknown';
37
+ },
38
+ subscribe(_cfg, cb) {
39
+ let off = false;
40
+ const t = w.Termly;
41
+ if (t && typeof t.on === 'function') {
42
+ t.on('consent', function () {
43
+ decided = true;
44
+ if (!off)
45
+ cb();
46
+ });
47
+ t.on('initialized', function () {
48
+ if (!off)
49
+ cb();
50
+ });
51
+ }
52
+ return function () {
53
+ off = true;
54
+ };
55
+ },
56
+ evidence(cfg) {
57
+ return { purposes: [cfg.category || 'advertising'] };
58
+ },
59
+ };
60
+ },
61
+ };
@@ -0,0 +1,9 @@
1
+ import { type ConsentSource } from '../port.js';
2
+ /**
3
+ * Usercentrics: v2 `UC_UI.getServicesBaseInfo()` (services with
4
+ * `consent.status` and `categorySlug`) and v3 `__ucCmp.getConsentDetails()`
5
+ * (async; cached and refreshed on each event). `category` matches a service
6
+ * name (add a "Referalli" service and set it) or a category slug; default
7
+ * `marketing`. Events: `UC_UI_CMP_EVENT`, `UC_UI_INITIALIZED`, `UC_CONSENT`.
8
+ */
9
+ export declare const usercentrics: ConsentSource;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usercentrics = void 0;
4
+ const port_js_1 = require("../port.js");
5
+ /**
6
+ * Usercentrics: v2 `UC_UI.getServicesBaseInfo()` (services with
7
+ * `consent.status` and `categorySlug`) and v3 `__ucCmp.getConsentDetails()`
8
+ * (async; cached and refreshed on each event). `category` matches a service
9
+ * name (add a "Referalli" service and set it) or a category slug; default
10
+ * `marketing`. Events: `UC_UI_CMP_EVENT`, `UC_UI_INITIALIZED`, `UC_CONSENT`.
11
+ */
12
+ exports.usercentrics = {
13
+ id: 'usercentrics',
14
+ name: 'Usercentrics',
15
+ defaultCategory: 'marketing',
16
+ status: 'beta',
17
+ docsUrl: 'https://referalli.com/docs/tracking-consent#usercentrics',
18
+ vendorDocsUrl: 'https://docs.usercentrics.com/',
19
+ check: (cfg) => (0, port_js_1.browserCheck)(exports.usercentrics, cfg),
20
+ factory: function usercentricsConsent(w) {
21
+ const EVENTS = ['UC_UI_CMP_EVENT', 'UC_UI_INITIALIZED', 'UC_CONSENT', 'UC_UI_VIEW_CHANGED'];
22
+ let v3 = null;
23
+ function refresh(done) {
24
+ const api = w.__ucCmp;
25
+ if (!api || typeof api.getConsentDetails !== 'function') {
26
+ done();
27
+ return;
28
+ }
29
+ try {
30
+ Promise.resolve(api.getConsentDetails()).then(function (d) {
31
+ v3 = d || null;
32
+ done();
33
+ }, function () {
34
+ done();
35
+ });
36
+ }
37
+ catch {
38
+ done();
39
+ }
40
+ }
41
+ return {
42
+ detect() {
43
+ if (w.UC_UI || w.__ucCmp)
44
+ return true;
45
+ const d = w.document;
46
+ return !!(d && typeof d.getElementById === 'function' && d.getElementById('usercentrics-cmp'));
47
+ },
48
+ state(cfg) {
49
+ const cat = cfg.category || 'marketing';
50
+ const ui = w.UC_UI;
51
+ if (ui && typeof ui.getServicesBaseInfo === 'function') {
52
+ if (typeof ui.isInitialized === 'function' && !ui.isInitialized())
53
+ return 'unknown';
54
+ const list = ui.getServicesBaseInfo() || [];
55
+ const hit = list.filter(function (s) {
56
+ return s && (s.name === cat || s.categorySlug === cat);
57
+ });
58
+ if (!hit.length)
59
+ return 'unknown';
60
+ if (hit.every(function (s) {
61
+ return s.consent && s.consent.status === true;
62
+ }))
63
+ return 'granted';
64
+ if (typeof ui.isConsentRequired === 'function' && ui.isConsentRequired())
65
+ return 'unknown';
66
+ return 'denied';
67
+ }
68
+ if (!v3)
69
+ return 'unknown';
70
+ const services = v3.services || {};
71
+ for (const k in services) {
72
+ const s = services[k];
73
+ if (s && s.name === cat)
74
+ return s.consent && s.consent.given === true ? 'granted' : v3.consent && v3.consent.required ? 'unknown' : 'denied';
75
+ }
76
+ const c = v3.categories && v3.categories[cat];
77
+ if (c && c.state === 'ALL_ACCEPTED')
78
+ return 'granted';
79
+ if (v3.consent && v3.consent.required)
80
+ return 'unknown';
81
+ return c ? 'denied' : 'unknown';
82
+ },
83
+ subscribe(_cfg, cb) {
84
+ let off = false;
85
+ const fire = function () {
86
+ refresh(function () {
87
+ if (!off)
88
+ cb();
89
+ });
90
+ };
91
+ for (let i = 0; i < EVENTS.length; i++)
92
+ w.addEventListener(EVENTS[i], fire);
93
+ fire();
94
+ return function () {
95
+ off = true;
96
+ for (let i = 0; i < EVENTS.length; i++)
97
+ w.removeEventListener(EVENTS[i], fire);
98
+ };
99
+ },
100
+ evidence() {
101
+ const id = v3 && v3.consent && v3.consent.controllerId;
102
+ return id ? { stamp: String(id) } : {};
103
+ },
104
+ };
105
+ },
106
+ };
@@ -0,0 +1,22 @@
1
+ import type { ConsentSource } from './port.js';
2
+ /** The vitest functions, passed in so this module never imports a test runner at runtime. */
3
+ export interface TestApi {
4
+ describe: (name: string, fn: () => void) => void;
5
+ it: (name: string, fn: () => unknown) => void;
6
+ expect: (value: unknown) => any;
7
+ }
8
+ /** A fake CMP built from the vendor's documented browser API (test/fixtures/consent/<id>/). */
9
+ export interface ConsentFixture {
10
+ install(w: any): void;
11
+ grant(w: any): void;
12
+ deny(w: any): void;
13
+ broken(w: any): void;
14
+ }
15
+ /**
16
+ * The runtime-free half of the consent conformance suite (REF-P01,
17
+ * docs/PORTS.md): every adapter declares its docs and status, answers check(),
18
+ * is not detected on a page without its CMP, and never throws out of state()
19
+ * when the CMP's API throws (the gate reads that as `unknown`). The full
20
+ * served-script and module-build cases run in test/consent/conformance.ts.
21
+ */
22
+ export declare function runConformance(source: ConsentSource, fx: ConsentFixture, newWindow: () => any, t: TestApi): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runConformance = runConformance;
4
+ /**
5
+ * The runtime-free half of the consent conformance suite (REF-P01,
6
+ * docs/PORTS.md): every adapter declares its docs and status, answers check(),
7
+ * is not detected on a page without its CMP, and never throws out of state()
8
+ * when the CMP's API throws (the gate reads that as `unknown`). The full
9
+ * served-script and module-build cases run in test/consent/conformance.ts.
10
+ */
11
+ function runConformance(source, fx, newWindow, t) {
12
+ const { describe, it, expect } = t;
13
+ describe(`consent adapter ${source.id} conformance`, () => {
14
+ it('declares its docs, vendor docs and status', () => {
15
+ expect(source.docsUrl).toMatch(/^https:\/\/referalli\.com\/docs\//);
16
+ expect(source.vendorDocsUrl).toMatch(/^https:\/\//);
17
+ expect(['ga', 'beta']).toContain(source.status);
18
+ });
19
+ it('answers check()', async () => {
20
+ const r = await source.check();
21
+ expect(typeof r.ok).toBe('boolean');
22
+ expect(typeof r.detail).toBe('string');
23
+ });
24
+ it('is not detected on a page without its CMP', () => {
25
+ expect(source.factory(newWindow()).detect()).toBe(false);
26
+ });
27
+ it('is detected once its CMP is on the page', () => {
28
+ const w = newWindow();
29
+ fx.install(w);
30
+ expect(source.factory(w).detect()).toBe(true);
31
+ });
32
+ });
33
+ }
@@ -0,0 +1,23 @@
1
+ import type { ConsentAdapterFactory, ConsentConfig, ConsentEvidence, ConsentState } from './port.js';
2
+ export interface ConsentGate {
3
+ /** Begin detecting (call once the change handler is ready). */
4
+ start(): void;
5
+ state(): ConsentState;
6
+ /** The adapter in use: an adapter id, `auto` while still looking, `none`, `no-cmp` or `pending`. */
7
+ mode(): string;
8
+ /** The push path: `aff.consent(true|false)`. The latest signal (push or CMP) wins. Idempotent. */
9
+ push(granted: boolean): void;
10
+ evidence(): ConsentEvidence | null;
11
+ stop(): void;
12
+ }
13
+ /**
14
+ * The one consent state machine, shared by `referalli/browser` (snippet.ts)
15
+ * and the served `aff.js` (served.ts inlines this function's source text, so
16
+ * it must stay self-contained: parameters and browser globals only).
17
+ *
18
+ * `change(state, evidence)` is called on every transition (never for the
19
+ * initial `unknown`). `auto` polls every 100 ms for up to `waitMs` for a CMP
20
+ * to appear; if the page is being left before then with none found, the
21
+ * no-CMP rule applies at once so a quick click-through still keeps its referral.
22
+ */
23
+ export declare function consentGate(w: any, cfg: ConsentConfig, adapters: Record<string, ConsentAdapterFactory>, order: readonly string[], change: (state: ConsentState, evidence: ConsentEvidence | null) => void): ConsentGate;