@codefast/tracking 1.0.0-canary.6 → 1.0.0-canary.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/CHANGELOG.md +55 -0
- package/README.md +72 -17
- package/dist/adapters/tanstack-start.d.ts +80 -0
- package/dist/adapters/tanstack-start.d.ts.map +1 -0
- package/dist/adapters/tanstack-start.js +74 -0
- package/dist/adapters/tanstack-start.js.map +1 -0
- package/dist/client/ad-framework-consent.d.ts +62 -0
- package/dist/client/ad-framework-consent.d.ts.map +1 -0
- package/dist/client/ad-framework-consent.js +40 -0
- package/dist/client/ad-framework-consent.js.map +1 -0
- package/dist/client/{browser-cookie.d.mts → browser-cookie.d.ts} +2 -4
- package/dist/client/browser-cookie.d.ts.map +1 -0
- package/dist/client/browser-cookie.js +15 -0
- package/dist/client/browser-cookie.js.map +1 -0
- package/dist/client/consent-runtime.d.ts +53 -0
- package/dist/client/consent-runtime.d.ts.map +1 -0
- package/dist/client/consent-runtime.js +33 -0
- package/dist/client/consent-runtime.js.map +1 -0
- package/dist/client/{consent-storage.d.mts → consent-storage.d.ts} +3 -6
- package/dist/client/consent-storage.d.ts.map +1 -0
- package/dist/client/consent-storage.js +109 -0
- package/dist/client/consent-storage.js.map +1 -0
- package/dist/client/consent-withdrawal.d.ts +18 -0
- package/dist/client/consent-withdrawal.d.ts.map +1 -0
- package/dist/client/consent-withdrawal.js +17 -0
- package/dist/client/consent-withdrawal.js.map +1 -0
- package/dist/client/cookie-anonymous-id.d.ts +41 -0
- package/dist/client/cookie-anonymous-id.d.ts.map +1 -0
- package/dist/client/cookie-anonymous-id.js +65 -0
- package/dist/client/cookie-anonymous-id.js.map +1 -0
- package/dist/client/create-client-tracker.d.ts +60 -0
- package/dist/client/create-client-tracker.d.ts.map +1 -0
- package/dist/client/create-client-tracker.js +91 -0
- package/dist/client/create-client-tracker.js.map +1 -0
- package/dist/client/{gpc.d.mts → gpc.d.ts} +2 -4
- package/dist/client/gpc.d.ts.map +1 -0
- package/dist/client/gpc.js +12 -0
- package/dist/client/gpc.js.map +1 -0
- package/dist/client/initial-consent-store.d.ts +63 -0
- package/dist/client/initial-consent-store.d.ts.map +1 -0
- package/dist/client/initial-consent-store.js +138 -0
- package/dist/client/initial-consent-store.js.map +1 -0
- package/dist/client/is-analytics-allowed.d.ts +26 -0
- package/dist/client/is-analytics-allowed.d.ts.map +1 -0
- package/dist/client/is-analytics-allowed.js +22 -0
- package/dist/client/is-analytics-allowed.js.map +1 -0
- package/dist/client/server-persisted-anonymous-id.d.ts +30 -0
- package/dist/client/server-persisted-anonymous-id.d.ts.map +1 -0
- package/dist/client/server-persisted-anonymous-id.js +72 -0
- package/dist/client/server-persisted-anonymous-id.js.map +1 -0
- package/dist/core/consent-config.d.ts +24 -0
- package/dist/core/consent-config.d.ts.map +1 -0
- package/dist/core/consent-config.js +9 -0
- package/dist/core/consent-config.js.map +1 -0
- package/dist/core/consent-receipt.d.ts +71 -0
- package/dist/core/consent-receipt.d.ts.map +1 -0
- package/dist/core/consent-receipt.js +39 -0
- package/dist/core/consent-receipt.js.map +1 -0
- package/dist/core/{consent.d.mts → consent.d.ts} +49 -51
- package/dist/core/consent.d.ts.map +1 -0
- package/dist/core/consent.js +159 -0
- package/dist/core/consent.js.map +1 -0
- package/dist/core/{cookie.d.mts → cookie.d.ts} +3 -5
- package/dist/core/cookie.d.ts.map +1 -0
- package/dist/core/cookie.js +26 -0
- package/dist/core/cookie.js.map +1 -0
- package/dist/core/destination.d.ts +29 -0
- package/dist/core/destination.d.ts.map +1 -0
- package/dist/core/destination.js +2 -0
- package/dist/core/destination.js.map +1 -0
- package/dist/core/event-catalog.d.ts +35 -0
- package/dist/core/event-catalog.d.ts.map +1 -0
- package/dist/core/event-catalog.js +30 -0
- package/dist/core/event-catalog.js.map +1 -0
- package/dist/core/{event-id.d.mts → event-id.d.ts} +2 -4
- package/dist/core/event-id.d.ts.map +1 -0
- package/dist/core/event-id.js +9 -0
- package/dist/core/event-id.js.map +1 -0
- package/dist/core/tracked-event.d.ts +15 -0
- package/dist/core/tracked-event.d.ts.map +1 -0
- package/dist/core/tracked-event.js +2 -0
- package/dist/core/tracked-event.js.map +1 -0
- package/dist/destinations/ad-consent.d.ts +23 -0
- package/dist/destinations/ad-consent.d.ts.map +1 -0
- package/dist/destinations/ad-consent.js +12 -0
- package/dist/destinations/ad-consent.js.map +1 -0
- package/dist/destinations/google-analytics.d.ts +148 -0
- package/dist/destinations/google-analytics.d.ts.map +1 -0
- package/dist/destinations/google-analytics.js +156 -0
- package/dist/destinations/google-analytics.js.map +1 -0
- package/dist/destinations/google-consent.d.ts +62 -0
- package/dist/destinations/google-consent.d.ts.map +1 -0
- package/dist/destinations/google-consent.js +109 -0
- package/dist/destinations/google-consent.js.map +1 -0
- package/dist/destinations/meta.d.ts +63 -0
- package/dist/destinations/meta.d.ts.map +1 -0
- package/dist/destinations/meta.js +44 -0
- package/dist/destinations/meta.js.map +1 -0
- package/dist/destinations/microsoft-uet.d.ts +56 -0
- package/dist/destinations/microsoft-uet.d.ts.map +1 -0
- package/dist/destinations/microsoft-uet.js +41 -0
- package/dist/destinations/microsoft-uet.js.map +1 -0
- package/dist/destinations/shared.d.ts +18 -0
- package/dist/destinations/shared.d.ts.map +1 -0
- package/dist/destinations/shared.js +19 -0
- package/dist/destinations/shared.js.map +1 -0
- package/dist/destinations/tiktok.d.ts +55 -0
- package/dist/destinations/tiktok.d.ts.map +1 -0
- package/dist/destinations/tiktok.js +40 -0
- package/dist/destinations/tiktok.js.map +1 -0
- package/dist/destinations/vercel-analytics.d.ts +25 -0
- package/dist/destinations/vercel-analytics.d.ts.map +1 -0
- package/dist/destinations/vercel-analytics.js +23 -0
- package/dist/destinations/vercel-analytics.js.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/react/consent-banner.d.ts +155 -0
- package/dist/react/consent-banner.d.ts.map +1 -0
- package/dist/react/consent-banner.js +171 -0
- package/dist/react/consent-banner.js.map +1 -0
- package/dist/react/gtag-consent-bootstrap.d.ts +17 -0
- package/dist/react/gtag-consent-bootstrap.d.ts.map +1 -0
- package/dist/react/gtag-consent-bootstrap.js +22 -0
- package/dist/react/gtag-consent-bootstrap.js.map +1 -0
- package/dist/react/use-consent.d.ts +42 -0
- package/dist/react/use-consent.d.ts.map +1 -0
- package/dist/react/use-consent.js +60 -0
- package/dist/react/use-consent.js.map +1 -0
- package/dist/react/use-google-consent-sync.d.ts +20 -0
- package/dist/react/use-google-consent-sync.d.ts.map +1 -0
- package/dist/react/use-google-consent-sync.js +22 -0
- package/dist/react/use-google-consent-sync.js.map +1 -0
- package/dist/react/{use-initial-consent.d.mts → use-initial-consent.d.ts} +3 -6
- package/dist/react/use-initial-consent.d.ts.map +1 -0
- package/dist/react/use-initial-consent.js +18 -0
- package/dist/react/use-initial-consent.js.map +1 -0
- package/dist/server/anonymous-id-cookie.d.ts +67 -0
- package/dist/server/anonymous-id-cookie.d.ts.map +1 -0
- package/dist/server/anonymous-id-cookie.js +71 -0
- package/dist/server/anonymous-id-cookie.js.map +1 -0
- package/dist/server/consent-receipt-store.d.ts +56 -0
- package/dist/server/consent-receipt-store.d.ts.map +1 -0
- package/dist/server/consent-receipt-store.js +44 -0
- package/dist/server/consent-receipt-store.js.map +1 -0
- package/dist/server/consent-receipt.d.ts +41 -0
- package/dist/server/consent-receipt.d.ts.map +1 -0
- package/dist/server/consent-receipt.js +60 -0
- package/dist/server/consent-receipt.js.map +1 -0
- package/dist/server/initial-consent.d.ts +26 -0
- package/dist/server/initial-consent.d.ts.map +1 -0
- package/dist/server/initial-consent.js +31 -0
- package/dist/server/initial-consent.js.map +1 -0
- package/dist/server/measurement-protocol.d.ts +69 -0
- package/dist/server/measurement-protocol.d.ts.map +1 -0
- package/dist/server/measurement-protocol.js +61 -0
- package/dist/server/measurement-protocol.js.map +1 -0
- package/dist/server/{region.d.mts → region.d.ts} +5 -15
- package/dist/server/region.d.ts.map +1 -0
- package/dist/server/region.js +69 -0
- package/dist/server/region.js.map +1 -0
- package/dist/server/user-deletion.d.ts +64 -0
- package/dist/server/user-deletion.d.ts.map +1 -0
- package/dist/server/user-deletion.js +54 -0
- package/dist/server/user-deletion.js.map +1 -0
- package/dist/tooling/import-protection.d.ts +19 -0
- package/dist/tooling/import-protection.d.ts.map +1 -0
- package/dist/tooling/import-protection.js +23 -0
- package/dist/tooling/import-protection.js.map +1 -0
- package/package.json +238 -59
- package/src/adapters/tanstack-start.ts +135 -0
- package/src/client/ad-framework-consent.ts +86 -0
- package/src/client/cookie-anonymous-id.ts +19 -0
- package/src/client/create-client-tracker.ts +81 -10
- package/src/client/server-persisted-anonymous-id.ts +4 -1
- package/src/core/consent-receipt.ts +115 -0
- package/src/core/consent.ts +2 -2
- package/src/core/destination.ts +7 -0
- package/src/core/event-catalog.ts +5 -4
- package/src/core/tracked-event.ts +5 -20
- package/src/destinations/ad-consent.ts +29 -0
- package/src/destinations/meta.ts +96 -0
- package/src/destinations/microsoft-uet.ts +86 -0
- package/src/destinations/tiktok.ts +85 -0
- package/src/index.ts +138 -19
- package/src/server/anonymous-id-cookie.ts +49 -22
- package/src/server/consent-receipt-store.ts +79 -0
- package/src/server/consent-receipt.ts +89 -0
- package/src/server/initial-consent.ts +0 -2
- package/src/server/measurement-protocol.ts +114 -0
- package/src/server/region.ts +0 -10
- package/src/server/user-deletion.ts +93 -0
- package/src/tooling/import-protection.ts +22 -0
- package/dist/client/browser-cookie.mjs +0 -15
- package/dist/client/consent-runtime.d.mts +0 -56
- package/dist/client/consent-runtime.mjs +0 -35
- package/dist/client/consent-storage.mjs +0 -82
- package/dist/client/consent-withdrawal.d.mts +0 -21
- package/dist/client/consent-withdrawal.mjs +0 -17
- package/dist/client/cookie-anonymous-id.d.mts +0 -37
- package/dist/client/cookie-anonymous-id.mjs +0 -46
- package/dist/client/create-client-tracker.d.mts +0 -32
- package/dist/client/create-client-tracker.mjs +0 -40
- package/dist/client/gpc.mjs +0 -14
- package/dist/client/index.d.mts +0 -10
- package/dist/client/index.mjs +0 -10
- package/dist/client/initial-consent-store.d.mts +0 -66
- package/dist/client/initial-consent-store.mjs +0 -119
- package/dist/client/is-analytics-allowed.d.mts +0 -29
- package/dist/client/is-analytics-allowed.mjs +0 -23
- package/dist/client/server-persisted-anonymous-id.d.mts +0 -33
- package/dist/client/server-persisted-anonymous-id.mjs +0 -50
- package/dist/core/consent-config.d.mts +0 -27
- package/dist/core/consent-config.mjs +0 -11
- package/dist/core/consent.mjs +0 -152
- package/dist/core/cookie.mjs +0 -23
- package/dist/core/destination.d.mts +0 -25
- package/dist/core/destination.mjs +0 -1
- package/dist/core/event-catalog.d.mts +0 -39
- package/dist/core/event-catalog.mjs +0 -30
- package/dist/core/event-id.mjs +0 -11
- package/dist/core/index.d.mts +0 -8
- package/dist/core/index.mjs +0 -6
- package/dist/core/tracked-event.d.mts +0 -30
- package/dist/core/tracked-event.mjs +0 -1
- package/dist/destinations/google-analytics.d.mts +0 -150
- package/dist/destinations/google-analytics.mjs +0 -130
- package/dist/destinations/google-consent.d.mts +0 -64
- package/dist/destinations/google-consent.mjs +0 -102
- package/dist/destinations/index.d.mts +0 -2
- package/dist/destinations/index.mjs +0 -2
- package/dist/destinations/shared.d.mts +0 -20
- package/dist/destinations/shared.mjs +0 -13
- package/dist/destinations/vercel-analytics.d.mts +0 -28
- package/dist/destinations/vercel-analytics.mjs +0 -23
- package/dist/import-protection.d.mts +0 -19
- package/dist/import-protection.mjs +0 -23
- package/dist/index.d.mts +0 -8
- package/dist/index.mjs +0 -6
- package/dist/react/consent-banner.d.mts +0 -180
- package/dist/react/consent-banner.mjs +0 -214
- package/dist/react/gtag-consent-bootstrap.d.mts +0 -27
- package/dist/react/gtag-consent-bootstrap.mjs +0 -29
- package/dist/react/index.d.mts +0 -6
- package/dist/react/index.mjs +0 -6
- package/dist/react/use-consent.d.mts +0 -45
- package/dist/react/use-consent.mjs +0 -71
- package/dist/react/use-google-consent-sync.d.mts +0 -23
- package/dist/react/use-google-consent-sync.mjs +0 -24
- package/dist/react/use-initial-consent.mjs +0 -19
- package/dist/server/anonymous-id-cookie.d.mts +0 -46
- package/dist/server/anonymous-id-cookie.mjs +0 -51
- package/dist/server/index.d.mts +0 -5
- package/dist/server/index.mjs +0 -4
- package/dist/server/initial-consent.d.mts +0 -29
- package/dist/server/initial-consent.mjs +0 -31
- package/dist/server/region.mjs +0 -77
- package/dist/tanstack-start/index.d.mts +0 -58
- package/dist/tanstack-start/index.mjs +0 -45
- package/src/client/index.ts +0 -28
- package/src/core/index.ts +0 -40
- package/src/destinations/index.ts +0 -19
- package/src/import-protection.ts +0 -20
- package/src/react/index.ts +0 -37
- package/src/server/index.ts +0 -16
- package/src/tanstack-start/index.ts +0 -83
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
//#region src/core/consent.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* @since 0.5.0-canary.4
|
|
4
3
|
*/
|
|
5
|
-
type ConsentRegion = "eu" | "other" | "us" | "vn";
|
|
4
|
+
export type ConsentRegion = "eu" | "other" | "us" | "vn";
|
|
6
5
|
/**
|
|
7
6
|
* @since 1.0.0-canary.6
|
|
8
7
|
*/
|
|
9
|
-
declare const CONSENT_REGIONS: ReadonlyArray<ConsentRegion>;
|
|
8
|
+
export declare const CONSENT_REGIONS: ReadonlyArray<ConsentRegion>;
|
|
10
9
|
/**
|
|
11
10
|
* Guards a region read from untrusted storage (a cached `InitialConsent`, a cookie).
|
|
12
11
|
*
|
|
13
12
|
* @since 1.0.0-canary.6
|
|
14
13
|
*/
|
|
15
|
-
declare function isConsentRegion(value: unknown): value is ConsentRegion;
|
|
14
|
+
export declare function isConsentRegion(value: unknown): value is ConsentRegion;
|
|
16
15
|
/**
|
|
17
16
|
* @since 0.5.0-canary.4
|
|
18
17
|
*/
|
|
19
|
-
type ConsentMode = "opt-in" | "opt-out";
|
|
18
|
+
export type ConsentMode = "opt-in" | "opt-out";
|
|
20
19
|
/**
|
|
21
20
|
* GDPR (EU) and the PDPL — Luật 91/2025/QH15 (VN) — require explicit opt-in before any non-essential
|
|
22
21
|
* tracking; CCPA/CPRA (US) defaults to opt-out instead. There is no single global default
|
|
@@ -24,7 +23,7 @@ type ConsentMode = "opt-in" | "opt-out";
|
|
|
24
23
|
*
|
|
25
24
|
* @since 0.5.0-canary.4
|
|
26
25
|
*/
|
|
27
|
-
declare function resolveConsentMode(region: ConsentRegion): ConsentMode;
|
|
26
|
+
export declare function resolveConsentMode(region: ConsentRegion): ConsentMode;
|
|
28
27
|
/**
|
|
29
28
|
* Consent purposes, mirroring Google Consent Mode v2's split: `analytics` gates
|
|
30
29
|
* measurement (`analytics_storage`), `ads` gates advertising storage and data sharing
|
|
@@ -32,52 +31,52 @@ declare function resolveConsentMode(region: ConsentRegion): ConsentMode;
|
|
|
32
31
|
*
|
|
33
32
|
* @since 0.5.0-canary.4
|
|
34
33
|
*/
|
|
35
|
-
type ConsentCategory = "ads" | "analytics";
|
|
34
|
+
export type ConsentCategory = "ads" | "analytics";
|
|
36
35
|
/**
|
|
37
36
|
* @since 0.5.0-canary.4
|
|
38
37
|
*/
|
|
39
|
-
declare const CONSENT_CATEGORIES: ReadonlyArray<ConsentCategory>;
|
|
38
|
+
export declare const CONSENT_CATEGORIES: ReadonlyArray<ConsentCategory>;
|
|
40
39
|
/**
|
|
41
40
|
* Per-category consent — GDPR consent must be granular per purpose, so a single
|
|
42
41
|
* granted/denied flag can't represent it. `true` means the visitor granted that purpose.
|
|
43
42
|
*
|
|
44
43
|
* @since 0.5.0-canary.4
|
|
45
44
|
*/
|
|
46
|
-
type ConsentDecision = Record<ConsentCategory, boolean>;
|
|
45
|
+
export type ConsentDecision = Record<ConsentCategory, boolean>;
|
|
47
46
|
/**
|
|
48
47
|
* A decision granting exactly the given categories and denying every other one.
|
|
49
48
|
*
|
|
50
49
|
* @since 0.5.0-canary.4
|
|
51
50
|
*/
|
|
52
|
-
declare function createConsentDecision(grantedCategories: ReadonlyArray<ConsentCategory>): ConsentDecision;
|
|
51
|
+
export declare function createConsentDecision(grantedCategories: ReadonlyArray<ConsentCategory>): ConsentDecision;
|
|
53
52
|
/**
|
|
54
53
|
* Guards stored JSON — the record is tamperable, so every category must be an explicit boolean.
|
|
55
54
|
*
|
|
56
55
|
* @since 0.5.0-canary.4
|
|
57
56
|
*/
|
|
58
|
-
declare function isConsentDecision(value: unknown): value is ConsentDecision;
|
|
57
|
+
export declare function isConsentDecision(value: unknown): value is ConsentDecision;
|
|
59
58
|
/**
|
|
60
59
|
* Re-derives a clean per-category decision from a tamperable record — extra keys are
|
|
61
|
-
* dropped, every category becomes an explicit boolean. The one normalization rule
|
|
62
|
-
*
|
|
60
|
+
* dropped, every category becomes an explicit boolean. The one normalization rule every
|
|
61
|
+
* reader of stored consent shares (e.g. `readStoredDecision`).
|
|
63
62
|
*
|
|
64
63
|
* @since 1.0.0-canary.6
|
|
65
64
|
*/
|
|
66
|
-
declare function normalizeConsentDecision(decision: ConsentDecision): ConsentDecision;
|
|
65
|
+
export declare function normalizeConsentDecision(decision: ConsentDecision): ConsentDecision;
|
|
67
66
|
/**
|
|
68
67
|
* Guards a persisted consent record read from untrusted storage (e.g. `localStorage`).
|
|
69
68
|
*
|
|
70
69
|
* @since 1.0.0-canary.6
|
|
71
70
|
*/
|
|
72
|
-
declare function isConsentRecord(value: unknown): value is ConsentRecord;
|
|
71
|
+
export declare function isConsentRecord(value: unknown): value is ConsentRecord;
|
|
73
72
|
/**
|
|
74
73
|
* @since 1.0.0-canary.6
|
|
75
74
|
*/
|
|
76
|
-
interface ResolveDefaultConsentOptions {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
export interface ResolveDefaultConsentOptions {
|
|
76
|
+
/** A "do not sell or share" opt-out — forces `ads` denied under opt-out regions. */
|
|
77
|
+
hasGlobalPrivacyControlSignal: boolean;
|
|
78
|
+
mode: ConsentMode;
|
|
79
|
+
requestedCategories: ReadonlyArray<ConsentCategory>;
|
|
81
80
|
}
|
|
82
81
|
/**
|
|
83
82
|
* The effective consent before the visitor decides: opt-in regions start all-denied,
|
|
@@ -89,7 +88,7 @@ interface ResolveDefaultConsentOptions {
|
|
|
89
88
|
*
|
|
90
89
|
* @since 0.5.0-canary.4
|
|
91
90
|
*/
|
|
92
|
-
declare function resolveDefaultConsent(options: ResolveDefaultConsentOptions): ConsentDecision;
|
|
91
|
+
export declare function resolveDefaultConsent(options: ResolveDefaultConsentOptions): ConsentDecision;
|
|
93
92
|
/**
|
|
94
93
|
* Region-resolved consent defaults — typically from `resolveInitialConsent` on a
|
|
95
94
|
* per-request server lane, then handed to the client so it never re-guesses the mode.
|
|
@@ -101,10 +100,10 @@ declare function resolveDefaultConsent(options: ResolveDefaultConsentOptions): C
|
|
|
101
100
|
*
|
|
102
101
|
* @since 1.0.0-canary.6
|
|
103
102
|
*/
|
|
104
|
-
interface InitialConsent {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
export interface InitialConsent {
|
|
104
|
+
defaultConsent: ConsentDecision;
|
|
105
|
+
mode: ConsentMode;
|
|
106
|
+
region: ConsentRegion;
|
|
108
107
|
}
|
|
109
108
|
/**
|
|
110
109
|
* What shared HTML bakes and what an unknown-country request resolves to: all categories
|
|
@@ -114,7 +113,7 @@ interface InitialConsent {
|
|
|
114
113
|
*
|
|
115
114
|
* @since 1.0.0-canary.6
|
|
116
115
|
*/
|
|
117
|
-
declare const STRICTEST_INITIAL_CONSENT: InitialConsent;
|
|
116
|
+
export declare const STRICTEST_INITIAL_CONSENT: InitialConsent;
|
|
118
117
|
/**
|
|
119
118
|
* Guards an `InitialConsent` read from untrusted storage (a session cache, a cookie).
|
|
120
119
|
* Enforces the mode/region pairing rule; the one deliberate exception is
|
|
@@ -123,7 +122,7 @@ declare const STRICTEST_INITIAL_CONSENT: InitialConsent;
|
|
|
123
122
|
*
|
|
124
123
|
* @since 1.0.0-canary.6
|
|
125
124
|
*/
|
|
126
|
-
declare function isInitialConsent(value: unknown): value is InitialConsent;
|
|
125
|
+
export declare function isInitialConsent(value: unknown): value is InitialConsent;
|
|
127
126
|
/**
|
|
128
127
|
* Vietnam's PDPL and GDPR both expect a record of *when* and *under what policy* consent
|
|
129
128
|
* was given, not just per-category flags — `policyVersion` lets a later policy change
|
|
@@ -131,10 +130,10 @@ declare function isInitialConsent(value: unknown): value is InitialConsent;
|
|
|
131
130
|
*
|
|
132
131
|
* @since 0.5.0-canary.4
|
|
133
132
|
*/
|
|
134
|
-
interface ConsentRecord {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
export interface ConsentRecord {
|
|
134
|
+
decision: ConsentDecision;
|
|
135
|
+
policyVersion: string;
|
|
136
|
+
timestamp: number;
|
|
138
137
|
}
|
|
139
138
|
/**
|
|
140
139
|
* Persistence backend for the visitor's consent decision — swap in your own
|
|
@@ -142,15 +141,15 @@ interface ConsentRecord {
|
|
|
142
141
|
*
|
|
143
142
|
* @since 0.5.0-canary.4
|
|
144
143
|
*/
|
|
145
|
-
interface ConsentStorage {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
144
|
+
export interface ConsentStorage {
|
|
145
|
+
clear: () => void;
|
|
146
|
+
load: () => ConsentRecord | undefined;
|
|
147
|
+
save: (record: ConsentRecord) => void;
|
|
148
|
+
/**
|
|
149
|
+
* Notify on any change to the stored record, including writes from other tabs — this
|
|
150
|
+
* is what drives `useConsent`'s external-store subscription. Returns an unsubscribe.
|
|
151
|
+
*/
|
|
152
|
+
subscribe: (listener: () => void) => () => void;
|
|
154
153
|
}
|
|
155
154
|
/**
|
|
156
155
|
* The stored decision if one exists under the current `policyVersion`, normalized to drop
|
|
@@ -159,17 +158,17 @@ interface ConsentStorage {
|
|
|
159
158
|
*
|
|
160
159
|
* @since 1.0.0-canary.6
|
|
161
160
|
*/
|
|
162
|
-
declare function readStoredDecision(storage: ConsentStorage, policyVersion: string): ConsentDecision | undefined;
|
|
161
|
+
export declare function readStoredDecision(storage: ConsentStorage, policyVersion: string): ConsentDecision | undefined;
|
|
163
162
|
/**
|
|
164
163
|
* @since 1.0.0-canary.6
|
|
165
164
|
*/
|
|
166
|
-
interface ResolveEffectiveConsentOptions {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
165
|
+
export interface ResolveEffectiveConsentOptions {
|
|
166
|
+
/** A "do not sell or share" opt-out — forces `ads` denied under opt-out regions. */
|
|
167
|
+
hasGlobalPrivacyControlSignal: boolean;
|
|
168
|
+
mode: ConsentMode;
|
|
169
|
+
policyVersion: string;
|
|
170
|
+
requestedCategories: ReadonlyArray<ConsentCategory>;
|
|
171
|
+
storage: ConsentStorage;
|
|
173
172
|
}
|
|
174
173
|
/**
|
|
175
174
|
* The consent a tracker should honor right now: the stored decision if one exists, else
|
|
@@ -179,6 +178,5 @@ interface ResolveEffectiveConsentOptions {
|
|
|
179
178
|
*
|
|
180
179
|
* @since 1.0.0-canary.6
|
|
181
180
|
*/
|
|
182
|
-
declare function resolveEffectiveConsent(options: ResolveEffectiveConsentOptions): ConsentDecision;
|
|
183
|
-
//#
|
|
184
|
-
export { CONSENT_CATEGORIES, CONSENT_REGIONS, ConsentCategory, ConsentDecision, ConsentMode, ConsentRecord, ConsentRegion, ConsentStorage, InitialConsent, ResolveDefaultConsentOptions, ResolveEffectiveConsentOptions, STRICTEST_INITIAL_CONSENT, createConsentDecision, isConsentDecision, isConsentRecord, isConsentRegion, isInitialConsent, normalizeConsentDecision, readStoredDecision, resolveConsentMode, resolveDefaultConsent, resolveEffectiveConsent };
|
|
181
|
+
export declare function resolveEffectiveConsent(options: ResolveEffectiveConsentOptions): ConsentDecision;
|
|
182
|
+
//# sourceMappingURL=consent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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AG,eAAe,CAOhG"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0-canary.6
|
|
3
|
+
*/
|
|
4
|
+
export const CONSENT_REGIONS = ["eu", "other", "us", "vn"];
|
|
5
|
+
/**
|
|
6
|
+
* Guards a region read from untrusted storage (a cached `InitialConsent`, a cookie).
|
|
7
|
+
*
|
|
8
|
+
* @since 1.0.0-canary.6
|
|
9
|
+
*/
|
|
10
|
+
export function isConsentRegion(value) {
|
|
11
|
+
return CONSENT_REGIONS.includes(value);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* GDPR (EU) and the PDPL — Luật 91/2025/QH15 (VN) — require explicit opt-in before any non-essential
|
|
15
|
+
* tracking; CCPA/CPRA (US) defaults to opt-out instead. There is no single global default
|
|
16
|
+
* that satisfies both, so the mode is resolved per region.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.5.0-canary.4
|
|
19
|
+
*/
|
|
20
|
+
export function resolveConsentMode(region) {
|
|
21
|
+
switch (region) {
|
|
22
|
+
case "eu":
|
|
23
|
+
case "vn": {
|
|
24
|
+
return "opt-in";
|
|
25
|
+
}
|
|
26
|
+
case "other":
|
|
27
|
+
case "us": {
|
|
28
|
+
return "opt-out";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @since 0.5.0-canary.4
|
|
34
|
+
*/
|
|
35
|
+
export const CONSENT_CATEGORIES = ["ads", "analytics"];
|
|
36
|
+
/**
|
|
37
|
+
* A decision granting exactly the given categories and denying every other one.
|
|
38
|
+
*
|
|
39
|
+
* @since 0.5.0-canary.4
|
|
40
|
+
*/
|
|
41
|
+
export function createConsentDecision(grantedCategories) {
|
|
42
|
+
return { ads: grantedCategories.includes("ads"), analytics: grantedCategories.includes("analytics") };
|
|
43
|
+
}
|
|
44
|
+
function isPlainObject(value) {
|
|
45
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Guards stored JSON — the record is tamperable, so every category must be an explicit boolean.
|
|
49
|
+
*
|
|
50
|
+
* @since 0.5.0-canary.4
|
|
51
|
+
*/
|
|
52
|
+
export function isConsentDecision(value) {
|
|
53
|
+
return isPlainObject(value) && CONSENT_CATEGORIES.every((category) => typeof value[category] === "boolean");
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Re-derives a clean per-category decision from a tamperable record — extra keys are
|
|
57
|
+
* dropped, every category becomes an explicit boolean. The one normalization rule every
|
|
58
|
+
* reader of stored consent shares (e.g. `readStoredDecision`).
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0-canary.6
|
|
61
|
+
*/
|
|
62
|
+
export function normalizeConsentDecision(decision) {
|
|
63
|
+
return createConsentDecision(CONSENT_CATEGORIES.filter((category) => decision[category]));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Guards a persisted consent record read from untrusted storage (e.g. `localStorage`).
|
|
67
|
+
*
|
|
68
|
+
* @since 1.0.0-canary.6
|
|
69
|
+
*/
|
|
70
|
+
export function isConsentRecord(value) {
|
|
71
|
+
return (isPlainObject(value) &&
|
|
72
|
+
isConsentDecision(value.decision) &&
|
|
73
|
+
typeof value.policyVersion === "string" &&
|
|
74
|
+
typeof value.timestamp === "number");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The effective consent before the visitor decides: opt-in regions start all-denied,
|
|
78
|
+
* opt-out regions grant the categories the app asks for.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* A Global Privacy Control signal is a "do not sell or share" opt-out (CCPA/CPRA), so it
|
|
82
|
+
* forces `ads` denied — it does not withdraw first-party analytics measurement.
|
|
83
|
+
*
|
|
84
|
+
* @since 0.5.0-canary.4
|
|
85
|
+
*/
|
|
86
|
+
export function resolveDefaultConsent(options) {
|
|
87
|
+
const { hasGlobalPrivacyControlSignal, mode, requestedCategories } = options;
|
|
88
|
+
if (mode === "opt-in") {
|
|
89
|
+
return createConsentDecision([]);
|
|
90
|
+
}
|
|
91
|
+
const decision = createConsentDecision(requestedCategories);
|
|
92
|
+
if (hasGlobalPrivacyControlSignal) {
|
|
93
|
+
decision.ads = false;
|
|
94
|
+
}
|
|
95
|
+
return decision;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* What shared HTML bakes and what an unknown-country request resolves to: all categories
|
|
99
|
+
* denied under opt-in — the one default that is safe to show any visitor anywhere.
|
|
100
|
+
* Prerendered/CDN-cached markup must carry nothing region-specific, and a missing geo
|
|
101
|
+
* header means "unknown visitor", never "known non-EU visitor".
|
|
102
|
+
*
|
|
103
|
+
* @since 1.0.0-canary.6
|
|
104
|
+
*/
|
|
105
|
+
export const STRICTEST_INITIAL_CONSENT = Object.freeze({
|
|
106
|
+
defaultConsent: Object.freeze(createConsentDecision([])),
|
|
107
|
+
mode: "opt-in",
|
|
108
|
+
region: "other",
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Guards an `InitialConsent` read from untrusted storage (a session cache, a cookie).
|
|
112
|
+
* Enforces the mode/region pairing rule; the one deliberate exception is
|
|
113
|
+
* {@link STRICTEST_INITIAL_CONSENT}'s own pairing — stricter than the region's usual
|
|
114
|
+
* mode, never looser.
|
|
115
|
+
*
|
|
116
|
+
* @since 1.0.0-canary.6
|
|
117
|
+
*/
|
|
118
|
+
export function isInitialConsent(value) {
|
|
119
|
+
if (!isPlainObject(value)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const mode = value.mode;
|
|
123
|
+
const region = value.region;
|
|
124
|
+
if ((mode !== "opt-in" && mode !== "opt-out") ||
|
|
125
|
+
!isConsentRegion(region) ||
|
|
126
|
+
!isConsentDecision(value.defaultConsent)) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return (mode === resolveConsentMode(region) ||
|
|
130
|
+
(mode === STRICTEST_INITIAL_CONSENT.mode && region === STRICTEST_INITIAL_CONSENT.region));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The stored decision if one exists under the current `policyVersion`, normalized to drop
|
|
134
|
+
* any tampered extra keys — `undefined` if there is none yet, the record is malformed, or
|
|
135
|
+
* it was recorded under a superseded policy version.
|
|
136
|
+
*
|
|
137
|
+
* @since 1.0.0-canary.6
|
|
138
|
+
*/
|
|
139
|
+
export function readStoredDecision(storage, policyVersion) {
|
|
140
|
+
const record = storage.load();
|
|
141
|
+
if (record?.policyVersion !== policyVersion || !isConsentDecision(record.decision)) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
return normalizeConsentDecision(record.decision);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The consent a tracker should honor right now: the stored decision if one exists, else
|
|
148
|
+
* the region default — the same rule `useConsent` applies to its `effectiveConsent`, so a
|
|
149
|
+
* non-React gate (e.g. a tracker's `isAnalyticsAllowed` option) doesn't have to reimplement
|
|
150
|
+
* "read storage, validate the policy version, fall back to `resolveDefaultConsent`" itself.
|
|
151
|
+
*
|
|
152
|
+
* @since 1.0.0-canary.6
|
|
153
|
+
*/
|
|
154
|
+
export function resolveEffectiveConsent(options) {
|
|
155
|
+
const { hasGlobalPrivacyControlSignal, mode, policyVersion, requestedCategories, storage } = options;
|
|
156
|
+
return (readStoredDecision(storage, policyVersion) ??
|
|
157
|
+
resolveDefaultConsent({ hasGlobalPrivacyControlSignal, mode, requestedCategories }));
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent.js","sourceRoot":"","sources":["../../src/core/consent.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAiC,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEzF;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO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C,iBAAiB,CAAC,KAAK,CAAC,cAAc,CAAC,EACxC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,IAAI,KAAK,kBAAkB,CAAC,MAAM,CAAC;QACnC,CAAC,IAAI,KAAK,yBAAyB,CAAC,IAAI,IAAI,MAAM,KAAK,yBAAyB,CAAC,MAAM,CAAC,CACzF,CAAC;AACJ,CAAC;AAgCD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAuB,EAAE,aAAqB;IAC/E,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAE9B,IAAI,MAAM,EAAE,aAAa,KAAK,aAAa,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,wBAAwB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACnD,CAAC;AAcD;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAuC;IAC7E,MAAM,EAAE,6BAA6B,EAAE,IAAI,EAAE,aAAa,EAAE,mBAAmB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAErG,OAAO,CACL,kBAAkB,CAAC,OAAO,EAAE,aAAa,CAAC;QAC1C,qBAAqB,CAAC,EAAE,6BAA6B,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CACpF,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
//#region src/core/cookie.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Default lifetime shared by the anonymous-id and consent cookies — one year.
|
|
4
3
|
*
|
|
5
4
|
* @since 1.0.0-canary.6
|
|
6
5
|
*/
|
|
7
|
-
declare const ONE_YEAR_IN_SECONDS: number;
|
|
6
|
+
export declare const ONE_YEAR_IN_SECONDS: number;
|
|
8
7
|
/**
|
|
9
8
|
* The value of `cookieName` inside a cookie string — a request `Cookie` header or
|
|
10
9
|
* `document.cookie`, which share the `name=value; name2=value2` wire format — or
|
|
@@ -12,6 +11,5 @@ declare const ONE_YEAR_IN_SECONDS: number;
|
|
|
12
11
|
*
|
|
13
12
|
* @since 1.0.0-canary.6
|
|
14
13
|
*/
|
|
15
|
-
declare function readCookieValue(cookieString: string | null | undefined, cookieName: string): string | undefined;
|
|
16
|
-
//#
|
|
17
|
-
export { ONE_YEAR_IN_SECONDS, readCookieValue };
|
|
14
|
+
export declare function readCookieValue(cookieString: string | null | undefined, cookieName: string): string | undefined;
|
|
15
|
+
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/core/cookie.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAc/G"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default lifetime shared by the anonymous-id and consent cookies — one year.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0-canary.6
|
|
5
|
+
*/
|
|
6
|
+
export const ONE_YEAR_IN_SECONDS = 60 * 60 * 24 * 365;
|
|
7
|
+
/**
|
|
8
|
+
* The value of `cookieName` inside a cookie string — a request `Cookie` header or
|
|
9
|
+
* `document.cookie`, which share the `name=value; name2=value2` wire format — or
|
|
10
|
+
* `undefined` when absent. The name must match exactly; a longer prefix sibling is ignored.
|
|
11
|
+
*
|
|
12
|
+
* @since 1.0.0-canary.6
|
|
13
|
+
*/
|
|
14
|
+
export function readCookieValue(cookieString, cookieName) {
|
|
15
|
+
if (!cookieString) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
for (const part of cookieString.split(";")) {
|
|
19
|
+
const separatorIndex = part.indexOf("=");
|
|
20
|
+
if (separatorIndex !== -1 && part.slice(0, separatorIndex).trim() === cookieName) {
|
|
21
|
+
return part.slice(separatorIndex + 1).trim();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/core/cookie.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,YAAuC,EAAE,UAAkB;IACzF,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAEzC,IAAI,cAAc,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,IAAI,EAAE,KAAK,UAAU,EAAE,CAAC;YACjF,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TrackedEvent } from "#/core/tracked-event";
|
|
2
|
+
/**
|
|
3
|
+
* Fan-out target for tracked events. The tracker depends only on this interface, never
|
|
4
|
+
* on a specific provider SDK — destinations own their transport (gtag.js and Vercel both
|
|
5
|
+
* queue and batch in-page), so `send` is fire-and-forget at track time.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.5.0-canary.4
|
|
8
|
+
*/
|
|
9
|
+
export interface Destination {
|
|
10
|
+
/**
|
|
11
|
+
* "exempt" keeps this destination receiving events while the tracker's analytics gate
|
|
12
|
+
* is closed — only for cookieless, identifier-free sinks: gated envelopes carry no
|
|
13
|
+
* `anonymousId`, and nothing is persisted.
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue "required"
|
|
16
|
+
*/
|
|
17
|
+
consentRequirement?: "exempt" | "required" | undefined;
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* Erase this destination's trace of the subject on withdrawal (spec-data-subject-rights
|
|
21
|
+
* §3): clear the destination's cookies and stop sending, and — where the platform offers
|
|
22
|
+
* one — request per-visitor deletion. Optional: a sink with nothing to erase omits it.
|
|
23
|
+
* Invoked at most once per withdrawal; the tracker swallows its failures.
|
|
24
|
+
*/
|
|
25
|
+
onErasure?: ((id: string) => Promise<void> | void) | undefined;
|
|
26
|
+
/** Must always return a `Promise` — mark `send` `async` even if the body has no `await`. */
|
|
27
|
+
send: (event: TrackedEvent) => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=destination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../src/core/destination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;IACvD,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IAC/D,4FAA4F;IAC5F,IAAI,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../src/core/destination.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
/**
|
|
3
|
+
* One event's schema. Any Standard Schema library works (zod, zod/mini, valibot, ...) —
|
|
4
|
+
* the client bundle only pays for the one the app already ships.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.5.0-canary.4
|
|
7
|
+
*/
|
|
8
|
+
export interface EventDefinition<Schema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
9
|
+
schema: Schema;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An app-defined map of event name to its definition. `@codefast/tracking` ships no
|
|
13
|
+
* events of its own — every consuming app builds and passes in its own catalog.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.5.0-canary.4
|
|
16
|
+
*/
|
|
17
|
+
export type EventCatalog = Record<string, EventDefinition>;
|
|
18
|
+
/**
|
|
19
|
+
* Identity helper for declaring a catalog with inference — nicer call-site than
|
|
20
|
+
* `satisfies EventCatalog` when the catalog is assembled across multiple files.
|
|
21
|
+
*
|
|
22
|
+
* @since 0.5.0-canary.4
|
|
23
|
+
*/
|
|
24
|
+
export declare function defineEventCatalog<Catalog extends EventCatalog>(catalog: Catalog): Catalog;
|
|
25
|
+
/**
|
|
26
|
+
* Validates event properties against the catalog schema and returns the parsed output
|
|
27
|
+
* (unknown keys stripped / transforms applied) so destinations never see raw input.
|
|
28
|
+
*
|
|
29
|
+
* @throws Error when validation reports issues, or when the schema validates asynchronously —
|
|
30
|
+
* tracking sits on synchronous call paths, so async schemas are unsupported by design.
|
|
31
|
+
*
|
|
32
|
+
* @since 1.0.0-canary.6
|
|
33
|
+
*/
|
|
34
|
+
export declare function assertValidEventProperties(schema: StandardSchemaV1, eventName: string, properties: unknown): unknown;
|
|
35
|
+
//# sourceMappingURL=event-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-catalog.d.ts","sourceRoot":"","sources":["../../src/core/event-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,MAAM,SAAS,gBAAgB,GAAG,gBAAgB;IACjF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAE1F;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAcpH"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity helper for declaring a catalog with inference — nicer call-site than
|
|
3
|
+
* `satisfies EventCatalog` when the catalog is assembled across multiple files.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.5.0-canary.4
|
|
6
|
+
*/
|
|
7
|
+
export function defineEventCatalog(catalog) {
|
|
8
|
+
return catalog;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validates event properties against the catalog schema and returns the parsed output
|
|
12
|
+
* (unknown keys stripped / transforms applied) so destinations never see raw input.
|
|
13
|
+
*
|
|
14
|
+
* @throws Error when validation reports issues, or when the schema validates asynchronously —
|
|
15
|
+
* tracking sits on synchronous call paths, so async schemas are unsupported by design.
|
|
16
|
+
*
|
|
17
|
+
* @since 1.0.0-canary.6
|
|
18
|
+
*/
|
|
19
|
+
export function assertValidEventProperties(schema, eventName, properties) {
|
|
20
|
+
const result = schema["~standard"].validate(properties);
|
|
21
|
+
if (result instanceof Promise) {
|
|
22
|
+
throw new TypeError(`Event "${eventName}" uses an async schema — event properties must validate synchronously`);
|
|
23
|
+
}
|
|
24
|
+
if (result.issues) {
|
|
25
|
+
const detail = result.issues.map((issue) => issue.message).join("; ");
|
|
26
|
+
throw new Error(`Invalid properties for event "${eventName}": ${detail}`);
|
|
27
|
+
}
|
|
28
|
+
return result.value;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=event-catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-catalog.js","sourceRoot":"","sources":["../../src/core/event-catalog.ts"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAA+B,OAAgB;IAC/E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAwB,EAAE,SAAiB,EAAE,UAAmB;IACzG,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAExD,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,UAAU,SAAS,uEAAuE,CAAC,CAAC;IAClH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtE,MAAM,IAAI,KAAK,CAAC,iCAAiC,SAAS,MAAM,MAAM,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
//#region src/core/event-id.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Stamped on every envelope at track time — destinations that dedupe can key on it.
|
|
4
3
|
*
|
|
5
4
|
* @since 0.5.0-canary.4
|
|
6
5
|
*/
|
|
7
|
-
declare function generateEventId(): string;
|
|
8
|
-
//#
|
|
9
|
-
export { generateEventId };
|
|
6
|
+
export declare function generateEventId(): string;
|
|
7
|
+
//# sourceMappingURL=event-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-id.d.ts","sourceRoot":"","sources":["../../src/core/event-id.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-id.js","sourceRoot":"","sources":["../../src/core/event-id.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The event envelope destinations receive. `type` stays a discriminant so a future envelope
|
|
3
|
+
* kind is an additive union member, not a wire-format break.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.5.0-canary.4
|
|
6
|
+
*/
|
|
7
|
+
export interface TrackedEvent {
|
|
8
|
+
anonymousId: string;
|
|
9
|
+
eventId: string;
|
|
10
|
+
name: string;
|
|
11
|
+
properties: Record<string, unknown>;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
type: "track";
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=tracked-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracked-event.d.ts","sourceRoot":"","sources":["../../src/core/tracked-event.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracked-event.js","sourceRoot":"","sources":["../../src/core/tracked-event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ConsentDecision } from "#/core/consent";
|
|
2
|
+
/**
|
|
3
|
+
* The normalized two-lever ad-platform consent state derived from one `{ ads, analytics }`
|
|
4
|
+
* decision (spec-destinations §5): `analytics` drives whether events transmit at all, and
|
|
5
|
+
* `ads` drives Limited Data Use. The levers are independent — a US opt-out (`ads: false`)
|
|
6
|
+
* restricts to LDU but MUST NOT withhold first-party `analytics` (spec-consent §3). Every
|
|
7
|
+
* ad destination consumes this same shape so per-vendor mappings cannot drift.
|
|
8
|
+
*
|
|
9
|
+
* @since 1.0.0-canary.7
|
|
10
|
+
*/
|
|
11
|
+
export interface AdConsentState {
|
|
12
|
+
/** `ads` denied → the platform must restrict to Limited Data Use (Meta/TikTok LDU, UET `ad_storage` denied). */
|
|
13
|
+
limitedDataUse: boolean;
|
|
14
|
+
/** `analytics` granted → events may transmit; denied → hold/revoke and send nothing. */
|
|
15
|
+
transmissionAllowed: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes a package `ConsentDecision` to the vendor-agnostic {@link AdConsentState}.
|
|
19
|
+
*
|
|
20
|
+
* @since 1.0.0-canary.7
|
|
21
|
+
*/
|
|
22
|
+
export declare function toAdConsentState(decision: ConsentDecision): AdConsentState;
|
|
23
|
+
//# sourceMappingURL=ad-consent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ad-consent.d.ts","sourceRoot":"","sources":["../../src/destinations/ad-consent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,gHAAgH;IAChH,cAAc,EAAE,OAAO,CAAC;IACxB,wFAAwF;IACxF,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,cAAc,CAK1E"}
|