@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
package/src/codegen.ts ADDED
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Turns Referalli's OpenAPI document into TypeScript types: one type per
3
+ * component, plus `<OperationId>Body` / `<OperationId>Response` / `<OperationId>Query`
4
+ * for every operation and an `operations` table of methods and paths.
5
+ * Dependency-free; it understands the JSON Schema subset the API emits.
6
+ */
7
+ type Schema = Record<string, unknown>;
8
+
9
+ const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
10
+ const pascal = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
11
+ const key = (k: string) => (IDENT.test(k) ? k : JSON.stringify(k));
12
+
13
+ function render(schema: unknown, indent: string): string {
14
+ if (schema === true || schema === undefined) return 'unknown';
15
+ if (schema === false) return 'never';
16
+ const s = schema as Schema;
17
+ if (typeof s.$ref === 'string') return s.$ref.split('/').pop()!;
18
+ if ('const' in s) return JSON.stringify(s.const);
19
+ if (Array.isArray(s.enum)) return s.enum.map((v) => JSON.stringify(v)).join(' | ');
20
+ const union = (s.anyOf ?? s.oneOf) as unknown[] | undefined;
21
+ if (union) return union.map((o) => wrap(render(o, indent))).join(' | ');
22
+ if (Array.isArray(s.allOf)) return s.allOf.map((o) => wrap(render(o, indent))).join(' & ');
23
+ if (Array.isArray(s.type)) return s.type.map((t) => render({ ...s, type: t }, indent)).join(' | ');
24
+ switch (s.type) {
25
+ case 'string':
26
+ return 'string';
27
+ case 'integer':
28
+ case 'number':
29
+ return 'number';
30
+ case 'boolean':
31
+ return 'boolean';
32
+ case 'null':
33
+ return 'null';
34
+ case 'array':
35
+ return `Array<${render(s.items, indent)}>`;
36
+ case 'object':
37
+ case undefined: {
38
+ const props = (s.properties ?? {}) as Record<string, unknown>;
39
+ const required = new Set((s.required as string[] | undefined) ?? []);
40
+ const extra = s.additionalProperties;
41
+ const entries = Object.entries(props);
42
+ if (entries.length === 0) {
43
+ if (s.type === undefined && !('additionalProperties' in s)) return 'unknown';
44
+ return extra && typeof extra === 'object' ? `Record<string, ${render(extra, indent)}>` : 'Record<string, unknown>';
45
+ }
46
+ const inner = indent + ' ';
47
+ const lines = entries.map(([k, v]) => {
48
+ const doc = (v as Schema).description ? `${inner}/** ${String((v as Schema).description)} */\n` : '';
49
+ return `${doc}${inner}${key(k)}${required.has(k) ? '' : '?'}: ${render(v, inner)};`;
50
+ });
51
+ if (extra && typeof extra === 'object') lines.push(`${inner}[key: string]: ${render(extra, inner)};`);
52
+ return `{\n${lines.join('\n')}\n${indent}}`;
53
+ }
54
+ default:
55
+ return 'unknown';
56
+ }
57
+ }
58
+
59
+ const wrap = (t: string) => (t.includes(' | ') || t.includes(' & ') ? `(${t})` : t);
60
+
61
+ /** `GET /v1/partners/{id}` → `GetPartnersId`: the base name of an operation's types. */
62
+ export function typeName(method: string, path: string): string {
63
+ const words = path.replace(/^\/v1\//, '/').replace(/[{}]/g, '');
64
+ return pascal(`${method}${words.replace(/[^A-Za-z0-9]+(.)?/g, (_, c: string | undefined) => (c ? c.toUpperCase() : ''))}`);
65
+ }
66
+
67
+ interface Operation {
68
+ operationId: string;
69
+ summary?: string;
70
+ parameters?: Array<{ name: string; in: string; required?: boolean; schema: unknown }>;
71
+ requestBody?: { content: Record<string, { schema: unknown }> };
72
+ responses: Record<string, { content?: Record<string, { schema: unknown }> }>;
73
+ }
74
+
75
+ export function generateTypes(spec: {
76
+ components?: { schemas?: Record<string, unknown> };
77
+ paths: Record<string, Record<string, Operation>>;
78
+ webhooks?: Record<string, Record<string, { summary?: string; description?: string; requestBody?: { content?: Record<string, { schema?: unknown }> } }>>;
79
+ }): string {
80
+ const out: string[] = [
81
+ '// Generated from the Referalli OpenAPI document. Do not edit by hand:',
82
+ '// run `pnpm --filter referalli gen` after changing the API.',
83
+ '',
84
+ ];
85
+ for (const [name, schema] of Object.entries(spec.components?.schemas ?? {})) {
86
+ const doc = (schema as Schema).description;
87
+ if (doc) out.push(`/** ${String(doc)} */`);
88
+ out.push(`export type ${name} = ${render(schema, '')};`, '');
89
+ }
90
+ const table: string[] = [];
91
+ for (const [path, methods] of Object.entries(spec.paths)) {
92
+ for (const [method, op] of Object.entries(methods)) {
93
+ // Same names the API gives operation-specific components (no /v1 prefix).
94
+ const id = typeName(method, path);
95
+ if (op.summary) out.push(`/** ${method.toUpperCase()} ${path}: ${op.summary} */`);
96
+ const body = op.requestBody?.content['application/json']?.schema;
97
+ if (body) out.push(`export type ${id}Body = ${render(body, '')};`);
98
+ const query = (op.parameters ?? []).filter((p) => p.in === 'query');
99
+ if (query.length > 0) {
100
+ const fields = query.map((p) => ` ${key(p.name)}${p.required ? '' : '?'}: ${render(p.schema, ' ')};`);
101
+ out.push(`export type ${id}Query = {\n${fields.join('\n')}\n};`);
102
+ }
103
+ const success = Object.entries(op.responses).find(([code]) => /^2\d\d$/.test(code))?.[1];
104
+ const json = success?.content?.['application/json']?.schema as Schema | undefined;
105
+ // A response that is already the component `<Id>Response` needs no alias.
106
+ if (json?.$ref !== `#/components/schemas/${id}Response`) {
107
+ out.push(`export type ${id}Response = ${json ? render(json, '') : success?.content ? 'string' : 'void'};`);
108
+ }
109
+ out.push('');
110
+ table.push(` ${op.operationId}: { method: '${method.toUpperCase()}', path: '${path}' },`);
111
+ }
112
+ }
113
+ // Webhook payloads by topic (the OpenAPI document's `webhooks`); the SDK's
114
+ // `WebhookEvent` union is built from this map.
115
+ const hooks = Object.entries(spec.webhooks ?? {}).flatMap(([topic, item]) => {
116
+ const op = item.post ?? Object.values(item)[0];
117
+ const schema = op?.requestBody?.content?.['application/json']?.schema;
118
+ if (!schema) return [];
119
+ const doc = op.summary ?? op.description;
120
+ return [`${doc ? ` /** ${String(doc).replace(/\n/g, ' ')} */\n` : ''} ${JSON.stringify(topic)}: ${render(schema, ' ')};`];
121
+ });
122
+ out.push(
123
+ '/** Every webhook topic and its payload. */',
124
+ hooks.length ? `export type WebhookPayloads = {\n${hooks.join('\n')}\n};` : 'export type WebhookPayloads = Record<never, never>;',
125
+ '',
126
+ );
127
+ out.push('/** Every operation, by operationId. */', `export const operations = {\n${table.join('\n')}\n} as const;`, '');
128
+ out.push('export type OperationId = keyof typeof operations;', '');
129
+ return out.join('\n');
130
+ }
@@ -0,0 +1,42 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * Cookiebot: `Cookiebot.consent.<category>`, `Cookiebot.hasResponse` and the
5
+ * `CookiebotOnConsentReady` / `OnAccept` / `OnDecline` window events.
6
+ * Category `marketing` by default; `consentID` is the evidence stamp.
7
+ */
8
+ export const cookiebot: ConsentSource = {
9
+ id: 'cookiebot',
10
+ name: 'Cookiebot',
11
+ defaultCategory: 'marketing',
12
+ status: 'ga',
13
+ docsUrl: 'https://referalli.com/docs/tracking-consent#cookiebot',
14
+ vendorDocsUrl: 'https://www.cookiebot.com/en/developer/',
15
+ check: (cfg) => browserCheck(cookiebot, cfg),
16
+ factory: function cookiebotConsent(w: any) {
17
+ const EVENTS = ['CookiebotOnConsentReady', 'CookiebotOnAccept', 'CookiebotOnDecline', 'CookiebotOnLoad'];
18
+ return {
19
+ detect(): boolean {
20
+ if (w.Cookiebot) return true;
21
+ const d = w.document;
22
+ return !!(d && typeof d.getElementById === 'function' && d.getElementById('Cookiebot'));
23
+ },
24
+ state(cfg) {
25
+ const cb = w.Cookiebot;
26
+ if (!cb || !cb.consent) return 'unknown';
27
+ if (cb.consent[cfg.category || 'marketing'] === true) return 'granted';
28
+ return cb.hasResponse ? 'denied' : 'unknown';
29
+ },
30
+ subscribe(_cfg, cb) {
31
+ for (let i = 0; i < EVENTS.length; i++) w.addEventListener(EVENTS[i], cb);
32
+ return function () {
33
+ for (let i = 0; i < EVENTS.length; i++) w.removeEventListener(EVENTS[i], cb);
34
+ };
35
+ },
36
+ evidence() {
37
+ const c = w.Cookiebot;
38
+ return c && c.consentID ? { stamp: String(c.consentID) } : {};
39
+ },
40
+ };
41
+ },
42
+ };
@@ -0,0 +1,49 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * Cookie Munch: `window.CookieMunch.{hasResponse, consent}` and the
5
+ * `CookieMunchOnChange` window event (Cookie Munch guide R4: read the
6
+ * snapshot, never the event payload). Category `referrals`, falling back to
7
+ * `marketing` when the site declares no `referrals` category.
8
+ */
9
+ export const cookiemunch: ConsentSource = {
10
+ id: 'cookiemunch',
11
+ name: 'Cookie Munch',
12
+ defaultCategory: 'referrals',
13
+ status: 'ga',
14
+ docsUrl: 'https://referalli.com/docs/tracking-consent#cookie-munch',
15
+ vendorDocsUrl: 'https://cookiemunch.net/docs',
16
+ check: (cfg) => browserCheck(cookiemunch, cfg),
17
+ factory: function cookiemunchConsent(w: any) {
18
+ return {
19
+ detect(): boolean {
20
+ if (w.CookieMunch) return true;
21
+ const d = w.document;
22
+ return !!(d && typeof d.getElementById === 'function' && d.getElementById('CookieMunch'));
23
+ },
24
+ state(cfg) {
25
+ const cm = w.CookieMunch;
26
+ if (!cm || !cm.hasResponse) return 'unknown';
27
+ const consent = cm.consent || {};
28
+ let v = consent[cfg.category || 'referrals'];
29
+ if (typeof v !== 'boolean' && !cfg.category) v = consent.marketing;
30
+ return v === true ? 'granted' : 'denied';
31
+ },
32
+ subscribe(_cfg, cb) {
33
+ w.addEventListener('CookieMunchOnChange', cb);
34
+ w.addEventListener('CookieMunchOnLoad', cb);
35
+ return function () {
36
+ w.removeEventListener('CookieMunchOnChange', cb);
37
+ w.removeEventListener('CookieMunchOnLoad', cb);
38
+ };
39
+ },
40
+ evidence() {
41
+ const cm = w.CookieMunch;
42
+ let stamp: unknown = null;
43
+ if (cm && typeof cm.consentId === 'function') stamp = cm.consentId();
44
+ else if (cm && cm.consent && cm.consent.stamp) stamp = cm.consent.stamp;
45
+ return stamp ? { stamp: String(stamp) } : {};
46
+ },
47
+ };
48
+ },
49
+ };
@@ -0,0 +1,37 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * The contract for any CMP we don't cover: define `window.referalliConsent()`
5
+ * returning `true` (granted), `false` (denied) or `null` (no decision yet),
6
+ * and dispatch a `referalli:consent` window event when it changes. The push
7
+ * path (`aff.consent(true|false)`) needs no adapter at all.
8
+ */
9
+ export const custom: ConsentSource = {
10
+ id: 'custom',
11
+ name: 'Custom (window.referalliConsent)',
12
+ defaultCategory: null,
13
+ status: 'ga',
14
+ docsUrl: 'https://referalli.com/docs/tracking-consent#custom',
15
+ vendorDocsUrl: 'https://referalli.com/docs/tracking-consent#custom',
16
+ check: (cfg) => browserCheck(custom, cfg),
17
+ factory: function customConsent(w: any) {
18
+ return {
19
+ detect(): boolean {
20
+ return typeof w.referalliConsent === 'function';
21
+ },
22
+ state() {
23
+ const v = w.referalliConsent();
24
+ return v === true ? 'granted' : v === false ? 'denied' : 'unknown';
25
+ },
26
+ subscribe(_cfg, cb) {
27
+ w.addEventListener('referalli:consent', cb);
28
+ return function () {
29
+ w.removeEventListener('referalli:consent', cb);
30
+ };
31
+ },
32
+ evidence() {
33
+ return {};
34
+ },
35
+ };
36
+ },
37
+ };
@@ -0,0 +1,59 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * Didomi: `Didomi.getUserStatus()` (purposes and vendors, each with
5
+ * `global.enabled`), `didomiOnReady` and the `consent.changed` event via
6
+ * `didomiEventListeners`. `category` is a purpose id (default `cookies`), or a
7
+ * vendor id when it contains a colon (`c:referalli-…`) or is numeric (IAB).
8
+ * Not enabled counts as denied only once `shouldConsentBeCollected()` is false.
9
+ */
10
+ export const didomi: ConsentSource = {
11
+ id: 'didomi',
12
+ name: 'Didomi',
13
+ defaultCategory: 'cookies',
14
+ status: 'beta',
15
+ docsUrl: 'https://referalli.com/docs/tracking-consent#didomi',
16
+ vendorDocsUrl: 'https://developers.didomi.io/',
17
+ check: (cfg) => browserCheck(didomi, cfg),
18
+ factory: function didomiConsent(w: any) {
19
+ return {
20
+ detect(): boolean {
21
+ return !!(w.Didomi || w.didomiOnReady || w.didomiConfig);
22
+ },
23
+ state(cfg) {
24
+ const d = w.Didomi;
25
+ if (!d || typeof d.getUserStatus !== 'function') return 'unknown';
26
+ if (typeof d.isConsentRequired === 'function' && d.isConsentRequired() === false) return 'granted';
27
+ const cat = String(cfg.category || 'cookies');
28
+ const vendor = cat.indexOf(':') >= 0 || /^\d+$/.test(cat);
29
+ const st = d.getUserStatus() || {};
30
+ const set = vendor ? st.vendors : st.purposes;
31
+ const enabled: unknown[] = (set && set.global && set.global.enabled) || [];
32
+ for (let i = 0; i < enabled.length; i++) if (String(enabled[i]) === cat) return 'granted';
33
+ if (typeof d.shouldConsentBeCollected === 'function' && d.shouldConsentBeCollected()) return 'unknown';
34
+ return 'denied';
35
+ },
36
+ subscribe(_cfg, cb) {
37
+ let off = false;
38
+ const fire = function () {
39
+ if (!off) cb();
40
+ };
41
+ w.didomiEventListeners = w.didomiEventListeners || [];
42
+ w.didomiEventListeners.push({ event: 'consent.changed', listener: fire });
43
+ w.didomiOnReady = w.didomiOnReady || [];
44
+ w.didomiOnReady.push(fire);
45
+ return function () {
46
+ off = true;
47
+ };
48
+ },
49
+ evidence() {
50
+ const d = w.Didomi;
51
+ const st = d && typeof d.getUserStatus === 'function' ? d.getUserStatus() || {} : {};
52
+ return {
53
+ ...(st.user_id ? { stamp: String(st.user_id) } : {}),
54
+ ...(typeof st.consent_string === 'string' && st.consent_string ? { tcString: st.consent_string } : {}),
55
+ };
56
+ },
57
+ };
58
+ },
59
+ };
@@ -0,0 +1,68 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * Google Consent Mode v2: `gtag('consent', 'default' | 'update', {...})`
5
+ * commands in `window.dataLayer`, following `ad_storage` (or
6
+ * `analytics_storage` via `gcmSignal`). An `update` decides. A default of
7
+ * `granted` everywhere grants; a `denied` default (often region-scoped) with
8
+ * no update yet is no decision. gtag.js replaces `dataLayer.push`, so changes
9
+ * are picked up by watching the queue (every 250 ms).
10
+ */
11
+ export const gcm: ConsentSource = {
12
+ id: 'gcm',
13
+ name: 'Google Consent Mode v2',
14
+ defaultCategory: 'ad_storage',
15
+ status: 'ga',
16
+ docsUrl: 'https://referalli.com/docs/tracking-consent#google-consent-mode',
17
+ vendorDocsUrl: 'https://developers.google.com/tag-platform/security/guides/consent',
18
+ check: (cfg) => browserCheck(gcm, cfg),
19
+ factory: function gcmConsent(w: any) {
20
+ function cmd(e: any): boolean {
21
+ return !!(e && typeof e === 'object' && e[0] === 'consent' && (e[1] === 'default' || e[1] === 'update') && e[2] && typeof e[2] === 'object');
22
+ }
23
+ function queue(): any[] {
24
+ const dl = w.dataLayer;
25
+ return dl && typeof dl.length === 'number' ? dl : [];
26
+ }
27
+ return {
28
+ detect(): boolean {
29
+ const dl = queue();
30
+ for (let i = 0; i < dl.length; i++) if (cmd(dl[i])) return true;
31
+ return false;
32
+ },
33
+ state(cfg) {
34
+ const sig = cfg.gcmSignal || 'ad_storage';
35
+ const dl = queue();
36
+ let update: string | null = null;
37
+ let anyDenied = false;
38
+ let anyGranted = false;
39
+ for (let i = 0; i < dl.length; i++) {
40
+ const e = dl[i];
41
+ if (!cmd(e) || typeof e[2][sig] !== 'string') continue;
42
+ if (e[1] === 'update') update = e[2][sig];
43
+ else if (e[2][sig] === 'granted') anyGranted = true;
44
+ else anyDenied = true;
45
+ }
46
+ if (update !== null) return update === 'granted' ? 'granted' : 'denied';
47
+ if (anyGranted && !anyDenied) return 'granted';
48
+ return 'unknown';
49
+ },
50
+ subscribe(_cfg, cb) {
51
+ let n = queue().length;
52
+ const t = w.setInterval(function () {
53
+ const l = queue().length;
54
+ if (l !== n) {
55
+ n = l;
56
+ cb();
57
+ }
58
+ }, 250);
59
+ return function () {
60
+ w.clearInterval(t);
61
+ };
62
+ },
63
+ evidence(cfg) {
64
+ return { purposes: [cfg.gcmSignal || 'ad_storage'] };
65
+ },
66
+ };
67
+ },
68
+ };
@@ -0,0 +1,81 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * IAB GPP: `__gpp('addEventListener', cb)` and `__gpp('ping', cb)`. Waits for
5
+ * `signalStatus: 'ready'`. The EU TCF section (id 2) follows the `tcf`
6
+ * rules (purpose 1 plus 7 or 9); US state sections are opt-out, so any
7
+ * `SaleOptOut`, `SharingOptOut` or `TargetedAdvertisingOptOut` of 1 (opted
8
+ * out) denies and anything else grants. Evidence: `gppString`.
9
+ */
10
+ export const gpp: ConsentSource = {
11
+ id: 'gpp',
12
+ name: 'IAB GPP',
13
+ defaultCategory: null,
14
+ status: 'beta',
15
+ docsUrl: 'https://referalli.com/docs/tracking-consent#gpp',
16
+ vendorDocsUrl: 'https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform',
17
+ check: (cfg) => browserCheck(gpp, cfg),
18
+ factory: function gppConsent(w: any) {
19
+ let ping: any = null;
20
+ let listening = false;
21
+ const subs: Array<() => void> = [];
22
+ function set(p: any): void {
23
+ if (!p || typeof p !== 'object') return;
24
+ ping = p;
25
+ const list = subs.slice();
26
+ for (let i = 0; i < list.length; i++) (list[i] as () => void)();
27
+ }
28
+ function listen(): void {
29
+ if (listening || typeof w.__gpp !== 'function') return;
30
+ listening = true;
31
+ w.__gpp('addEventListener', function (ev: any, ok: boolean) {
32
+ if (ok !== false && ev) set(ev.pingData || null);
33
+ });
34
+ w.__gpp('ping', function (p: any, ok: boolean) {
35
+ if (ok !== false) set(p);
36
+ });
37
+ }
38
+ function seg(s: any): any {
39
+ return Array.isArray(s) ? s[0] : s;
40
+ }
41
+ return {
42
+ detect(): boolean {
43
+ return typeof w.__gpp === 'function';
44
+ },
45
+ state() {
46
+ listen();
47
+ if (!ping || ping.signalStatus !== 'ready') return 'unknown';
48
+ const secs = ping.parsedSections || {};
49
+ const applicable: number[] = ping.applicableSections || [];
50
+ const eu = seg(secs.tcfeuv2);
51
+ if (applicable.indexOf(2) >= 0 && eu) {
52
+ const pc = eu.PurposeConsent || [];
53
+ const p = function (n: number) {
54
+ return !!(pc[n - 1] === true || pc[n - 1] === 1);
55
+ };
56
+ return p(1) && (p(7) || p(9)) ? 'granted' : 'denied';
57
+ }
58
+ for (const k in secs) {
59
+ if (k === 'tcfeuv2' || k === 'tcfcav1') continue;
60
+ const s = seg(secs[k]);
61
+ if (s && typeof s === 'object' && (s.SaleOptOut === 1 || s.SharingOptOut === 1 || s.TargetedAdvertisingOptOut === 1)) {
62
+ return 'denied';
63
+ }
64
+ }
65
+ return 'granted';
66
+ },
67
+ subscribe(_cfg, cb) {
68
+ subs.push(cb);
69
+ listen();
70
+ return function () {
71
+ const i = subs.indexOf(cb);
72
+ if (i >= 0) subs.splice(i, 1);
73
+ };
74
+ },
75
+ evidence() {
76
+ if (!ping) return null;
77
+ return { gppString: typeof ping.gppString === 'string' ? ping.gppString : undefined };
78
+ },
79
+ };
80
+ },
81
+ };
@@ -0,0 +1,28 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /** No consent check: always granted (the tracker before consent support). Only for sites that need no opt-in. */
4
+ export const none: ConsentSource = {
5
+ id: 'none',
6
+ name: 'None (always store)',
7
+ defaultCategory: null,
8
+ status: 'ga',
9
+ docsUrl: 'https://referalli.com/docs/tracking-consent#choose-a-mode',
10
+ vendorDocsUrl: 'https://referalli.com/docs/tracking-consent#choose-a-mode',
11
+ check: (cfg) => browserCheck(none, cfg),
12
+ factory: function noneConsent() {
13
+ return {
14
+ detect(): boolean {
15
+ return true;
16
+ },
17
+ state() {
18
+ return 'granted';
19
+ },
20
+ subscribe() {
21
+ return function () {};
22
+ },
23
+ evidence() {
24
+ return {};
25
+ },
26
+ };
27
+ },
28
+ };
@@ -0,0 +1,64 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * OneTrust: `window.OnetrustActiveGroups` (",C0001,C0004,"),
5
+ * `OneTrust.OnConsentChanged` and the `OneTrustGroupsUpdated` window event.
6
+ * Group `C0004` (targeting) by default. An inactive group counts as denied
7
+ * only once the banner was closed (`OneTrust.IsAlertBoxClosed()`).
8
+ */
9
+ export const onetrust: ConsentSource = {
10
+ id: 'onetrust',
11
+ name: 'OneTrust',
12
+ defaultCategory: 'C0004',
13
+ status: 'ga',
14
+ docsUrl: 'https://referalli.com/docs/tracking-consent#onetrust',
15
+ vendorDocsUrl: 'https://developer.onetrust.com/',
16
+ check: (cfg) => browserCheck(onetrust, cfg),
17
+ factory: function onetrustConsent(w: any) {
18
+ function groups(): string | null {
19
+ return typeof w.OnetrustActiveGroups === 'string' ? w.OnetrustActiveGroups : null;
20
+ }
21
+ return {
22
+ detect(): boolean {
23
+ return !!(w.OneTrust || w.OneTrustStub || groups() !== null);
24
+ },
25
+ state(cfg) {
26
+ const g = groups();
27
+ if (g === null) return 'unknown';
28
+ if ((',' + g + ',').indexOf(',' + (cfg.category || 'C0004') + ',') >= 0) return 'granted';
29
+ const ot = w.OneTrust;
30
+ const closed =
31
+ ot && typeof ot.IsAlertBoxClosed === 'function'
32
+ ? ot.IsAlertBoxClosed() === true
33
+ : /(?:^|;\s*)OptanonAlertBoxClosed=/.test((w.document && w.document.cookie) || '');
34
+ return closed ? 'denied' : 'unknown';
35
+ },
36
+ subscribe(_cfg, cb) {
37
+ let off = false;
38
+ const fire = function () {
39
+ if (!off) cb();
40
+ };
41
+ w.addEventListener('OneTrustGroupsUpdated', fire);
42
+ try {
43
+ if (w.OneTrust && typeof w.OneTrust.OnConsentChanged === 'function') w.OneTrust.OnConsentChanged(fire);
44
+ } catch {
45
+ /* the event covers it */
46
+ }
47
+ return function () {
48
+ off = true;
49
+ w.removeEventListener('OneTrustGroupsUpdated', fire);
50
+ };
51
+ },
52
+ evidence() {
53
+ const g = groups();
54
+ const out: { purposes: string[]; stamp?: string } = { purposes: g ? g.split(',').filter(Boolean) : [] };
55
+ const ot = w.OneTrust;
56
+ if (ot && typeof ot.getDataSubjectId === 'function') {
57
+ const id = ot.getDataSubjectId();
58
+ if (id) out.stamp = String(id);
59
+ }
60
+ return out;
61
+ },
62
+ };
63
+ },
64
+ };
@@ -0,0 +1,63 @@
1
+ import { browserCheck, type ConsentSource } from '../port.js';
2
+
3
+ /**
4
+ * Osano: `Osano.cm.getConsent()` (`MARKETING: 'ACCEPT' | 'DENY'`, …) and the
5
+ * `osano-cm-consent-saved` / `osano-cm-consent-changed` events. Category
6
+ * `MARKETING` by default. `DENY` counts as denied only once a choice was saved
7
+ * (the event, or Osano's `osano_consentmanager` record); before that it is
8
+ * Osano's opt-in default, so no decision.
9
+ */
10
+ export const osano: ConsentSource = {
11
+ id: 'osano',
12
+ name: 'Osano',
13
+ defaultCategory: 'MARKETING',
14
+ status: 'beta',
15
+ docsUrl: 'https://referalli.com/docs/tracking-consent#osano',
16
+ vendorDocsUrl: 'https://developers.osano.com/',
17
+ check: (cfg) => browserCheck(osano, cfg),
18
+ factory: function osanoConsent(w: any) {
19
+ let saved = false;
20
+ function stored(): boolean {
21
+ try {
22
+ if (w.localStorage && w.localStorage.getItem('osano_consentmanager')) return true;
23
+ } catch {
24
+ /* storage blocked */
25
+ }
26
+ return /(?:^|;\s*)osano_consentmanager=/.test((w.document && w.document.cookie) || '');
27
+ }
28
+ return {
29
+ detect(): boolean {
30
+ return !!(w.Osano && w.Osano.cm);
31
+ },
32
+ state(cfg) {
33
+ const cm = w.Osano && w.Osano.cm;
34
+ if (!cm || typeof cm.getConsent !== 'function') return 'unknown';
35
+ const c = cm.getConsent() || {};
36
+ if (c[cfg.category || 'MARKETING'] === 'ACCEPT') return 'granted';
37
+ return saved || stored() ? 'denied' : 'unknown';
38
+ },
39
+ subscribe(_cfg, cb) {
40
+ let off = false;
41
+ const cm = w.Osano && w.Osano.cm;
42
+ const onSave = function () {
43
+ saved = true;
44
+ if (!off) cb();
45
+ };
46
+ const onChange = function () {
47
+ if (!off) cb();
48
+ };
49
+ if (cm && typeof cm.addEventListener === 'function') {
50
+ cm.addEventListener('osano-cm-consent-saved', onSave);
51
+ cm.addEventListener('osano-cm-consent-changed', onSave);
52
+ cm.addEventListener('osano-cm-initialized', onChange);
53
+ }
54
+ return function () {
55
+ off = true;
56
+ };
57
+ },
58
+ evidence(cfg) {
59
+ return { purposes: [cfg.category || 'MARKETING'] };
60
+ },
61
+ };
62
+ },
63
+ };