@codefast/tracking 0.5.0-canary.5 → 0.5.0-canary.6
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 +467 -0
- package/README.md +176 -126
- 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.ts +9 -0
- 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} +8 -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.ts +10 -0
- 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.ts +182 -0
- 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.ts +15 -0
- 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.ts +7 -0
- 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.ts +11 -0
- 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.ts +27 -0
- 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 +201 -107
- package/src/adapters/tanstack-start.ts +135 -0
- package/src/client/ad-framework-consent.ts +86 -0
- package/src/client/browser-cookie.ts +16 -0
- package/src/client/consent-runtime.ts +80 -0
- package/src/client/consent-storage.ts +31 -1
- package/src/client/consent-withdrawal.ts +32 -0
- package/src/client/cookie-anonymous-id.ts +112 -0
- package/src/client/create-client-tracker.ts +128 -86
- package/src/client/gpc.ts +4 -2
- package/src/client/initial-consent-store.ts +218 -0
- package/src/client/is-analytics-allowed.ts +43 -0
- package/src/client/server-persisted-anonymous-id.ts +102 -0
- package/src/core/consent-config.ts +27 -0
- package/src/core/consent-receipt.ts +115 -0
- package/src/core/consent.ts +164 -10
- package/src/core/cookie.ts +29 -0
- package/src/core/destination.ts +17 -8
- package/src/core/event-catalog.ts +29 -15
- package/src/core/event-id.ts +1 -2
- package/src/core/tracked-event.ts +4 -4
- package/src/destinations/ad-consent.ts +29 -0
- package/src/destinations/google-analytics.ts +196 -133
- package/src/destinations/google-consent.ts +164 -0
- package/src/destinations/meta.ts +96 -0
- package/src/destinations/microsoft-uet.ts +86 -0
- package/src/destinations/shared.ts +45 -0
- package/src/destinations/tiktok.ts +85 -0
- package/src/destinations/vercel-analytics.ts +23 -24
- package/src/index.ts +165 -8
- package/src/react/consent-banner.tsx +40 -14
- package/src/react/gtag-consent-bootstrap.tsx +48 -0
- package/src/react/use-consent.ts +53 -45
- package/src/react/use-google-consent-sync.ts +38 -0
- package/src/react/use-initial-consent.ts +22 -0
- package/src/server/anonymous-id-cookie.ts +103 -0
- package/src/server/consent-receipt-store.ts +79 -0
- package/src/server/consent-receipt.ts +89 -0
- package/src/server/initial-consent.ts +46 -0
- package/src/server/measurement-protocol.ts +114 -0
- package/src/server/region.ts +22 -15
- package/src/server/user-deletion.ts +93 -0
- package/src/tooling/import-protection.ts +22 -0
- package/dist/client/consent-storage.mjs +0 -63
- package/dist/client/create-client-tracker.d.mts +0 -37
- package/dist/client/create-client-tracker.mjs +0 -66
- package/dist/client/gpc.d.mts +0 -10
- package/dist/client/gpc.mjs +0 -12
- package/dist/client/index.d.mts +0 -8
- package/dist/client/index.mjs +0 -8
- package/dist/client/lifecycle.d.mts +0 -23
- package/dist/client/lifecycle.mjs +0 -30
- package/dist/client/local-storage.d.mts +0 -13
- package/dist/client/local-storage.mjs +0 -31
- package/dist/client/queue.d.mts +0 -49
- package/dist/client/queue.mjs +0 -71
- package/dist/client/router.d.mts +0 -30
- package/dist/client/router.mjs +0 -17
- package/dist/core/consent.d.mts +0 -89
- package/dist/core/consent.mjs +0 -57
- package/dist/core/destination.d.mts +0 -23
- package/dist/core/destination.mjs +0 -1
- package/dist/core/event-catalog.d.mts +0 -36
- package/dist/core/event-catalog.mjs +0 -12
- package/dist/core/event-id.d.mts +0 -10
- package/dist/core/event-id.mjs +0 -12
- package/dist/core/index.d.mts +0 -6
- package/dist/core/index.mjs +0 -4
- package/dist/core/tracked-event.d.mts +0 -17
- package/dist/core/tracked-event.mjs +0 -1
- package/dist/destinations/ga4-measurement-protocol.d.mts +0 -54
- package/dist/destinations/ga4-measurement-protocol.mjs +0 -89
- package/dist/destinations/google-analytics.d.mts +0 -98
- package/dist/destinations/google-analytics.mjs +0 -126
- package/dist/destinations/http-destination.d.mts +0 -20
- package/dist/destinations/http-destination.mjs +0 -25
- package/dist/destinations/index.d.mts +0 -5
- package/dist/destinations/index.mjs +0 -5
- package/dist/destinations/vercel-analytics.d.mts +0 -13
- package/dist/destinations/vercel-analytics.mjs +0 -30
- package/dist/index.d.mts +0 -6
- package/dist/index.mjs +0 -4
- package/dist/react/consent-banner.d.mts +0 -163
- package/dist/react/consent-banner.mjs +0 -209
- package/dist/react/index.d.mts +0 -3
- package/dist/react/index.mjs +0 -3
- package/dist/react/use-consent.d.mts +0 -49
- package/dist/react/use-consent.mjs +0 -54
- package/dist/server/create-server-tracker.d.mts +0 -42
- package/dist/server/create-server-tracker.mjs +0 -67
- package/dist/server/index.d.mts +0 -3
- package/dist/server/index.mjs +0 -3
- package/dist/server/region.d.mts +0 -20
- package/dist/server/region.mjs +0 -56
- package/src/client/index.ts +0 -17
- package/src/client/lifecycle.ts +0 -50
- package/src/client/local-storage.ts +0 -44
- package/src/client/queue.ts +0 -117
- package/src/client/router.ts +0 -37
- package/src/core/index.ts +0 -24
- package/src/destinations/ga4-measurement-protocol.ts +0 -166
- package/src/destinations/http-destination.ts +0 -33
- package/src/destinations/index.ts +0 -20
- package/src/react/index.ts +0 -29
- package/src/server/create-server-tracker.ts +0 -128
- package/src/server/index.ts +0 -4
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 0.5.0-canary.4
|
|
3
|
+
*/
|
|
4
|
+
export type ConsentRegion = "eu" | "other" | "us" | "vn";
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0-canary.6
|
|
7
|
+
*/
|
|
8
|
+
export declare const CONSENT_REGIONS: ReadonlyArray<ConsentRegion>;
|
|
9
|
+
/**
|
|
10
|
+
* Guards a region read from untrusted storage (a cached `InitialConsent`, a cookie).
|
|
11
|
+
*
|
|
12
|
+
* @since 1.0.0-canary.6
|
|
13
|
+
*/
|
|
14
|
+
export declare function isConsentRegion(value: unknown): value is ConsentRegion;
|
|
15
|
+
/**
|
|
16
|
+
* @since 0.5.0-canary.4
|
|
17
|
+
*/
|
|
18
|
+
export type ConsentMode = "opt-in" | "opt-out";
|
|
19
|
+
/**
|
|
20
|
+
* GDPR (EU) and the PDPL — Luật 91/2025/QH15 (VN) — require explicit opt-in before any non-essential
|
|
21
|
+
* tracking; CCPA/CPRA (US) defaults to opt-out instead. There is no single global default
|
|
22
|
+
* that satisfies both, so the mode is resolved per region.
|
|
23
|
+
*
|
|
24
|
+
* @since 0.5.0-canary.4
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveConsentMode(region: ConsentRegion): ConsentMode;
|
|
27
|
+
/**
|
|
28
|
+
* Consent purposes, mirroring Google Consent Mode v2's split: `analytics` gates
|
|
29
|
+
* measurement (`analytics_storage`), `ads` gates advertising storage and data sharing
|
|
30
|
+
* (`ad_storage`/`ad_user_data`/`ad_personalization`).
|
|
31
|
+
*
|
|
32
|
+
* @since 0.5.0-canary.4
|
|
33
|
+
*/
|
|
34
|
+
export type ConsentCategory = "ads" | "analytics";
|
|
35
|
+
/**
|
|
36
|
+
* @since 0.5.0-canary.4
|
|
37
|
+
*/
|
|
38
|
+
export declare const CONSENT_CATEGORIES: ReadonlyArray<ConsentCategory>;
|
|
39
|
+
/**
|
|
40
|
+
* Per-category consent — GDPR consent must be granular per purpose, so a single
|
|
41
|
+
* granted/denied flag can't represent it. `true` means the visitor granted that purpose.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.5.0-canary.4
|
|
44
|
+
*/
|
|
45
|
+
export type ConsentDecision = Record<ConsentCategory, boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* A decision granting exactly the given categories and denying every other one.
|
|
48
|
+
*
|
|
49
|
+
* @since 0.5.0-canary.4
|
|
50
|
+
*/
|
|
51
|
+
export declare function createConsentDecision(grantedCategories: ReadonlyArray<ConsentCategory>): ConsentDecision;
|
|
52
|
+
/**
|
|
53
|
+
* Guards stored JSON — the record is tamperable, so every category must be an explicit boolean.
|
|
54
|
+
*
|
|
55
|
+
* @since 0.5.0-canary.4
|
|
56
|
+
*/
|
|
57
|
+
export declare function isConsentDecision(value: unknown): value is ConsentDecision;
|
|
58
|
+
/**
|
|
59
|
+
* Re-derives a clean per-category decision from a tamperable record — extra keys are
|
|
60
|
+
* dropped, every category becomes an explicit boolean. The one normalization rule every
|
|
61
|
+
* reader of stored consent shares (e.g. `readStoredDecision`).
|
|
62
|
+
*
|
|
63
|
+
* @since 1.0.0-canary.6
|
|
64
|
+
*/
|
|
65
|
+
export declare function normalizeConsentDecision(decision: ConsentDecision): ConsentDecision;
|
|
66
|
+
/**
|
|
67
|
+
* Guards a persisted consent record read from untrusted storage (e.g. `localStorage`).
|
|
68
|
+
*
|
|
69
|
+
* @since 1.0.0-canary.6
|
|
70
|
+
*/
|
|
71
|
+
export declare function isConsentRecord(value: unknown): value is ConsentRecord;
|
|
72
|
+
/**
|
|
73
|
+
* @since 1.0.0-canary.6
|
|
74
|
+
*/
|
|
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>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The effective consent before the visitor decides: opt-in regions start all-denied,
|
|
83
|
+
* opt-out regions grant the categories the app asks for.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* A Global Privacy Control signal is a "do not sell or share" opt-out (CCPA/CPRA), so it
|
|
87
|
+
* forces `ads` denied — it does not withdraw first-party analytics measurement.
|
|
88
|
+
*
|
|
89
|
+
* @since 0.5.0-canary.4
|
|
90
|
+
*/
|
|
91
|
+
export declare function resolveDefaultConsent(options: ResolveDefaultConsentOptions): ConsentDecision;
|
|
92
|
+
/**
|
|
93
|
+
* Region-resolved consent defaults — typically from `resolveInitialConsent` on a
|
|
94
|
+
* per-request server lane, then handed to the client so it never re-guesses the mode.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* Drive UI and gates from `mode` (recompute `effectiveConsent` with live navigator GPC).
|
|
98
|
+
* `defaultConsent` is the server snapshot — useful when you need request-time `sec-gpc`
|
|
99
|
+
* as-is; analytics-only apps can ignore it because GPC only forces `ads` denied.
|
|
100
|
+
*
|
|
101
|
+
* @since 1.0.0-canary.6
|
|
102
|
+
*/
|
|
103
|
+
export interface InitialConsent {
|
|
104
|
+
defaultConsent: ConsentDecision;
|
|
105
|
+
mode: ConsentMode;
|
|
106
|
+
region: ConsentRegion;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* What shared HTML bakes and what an unknown-country request resolves to: all categories
|
|
110
|
+
* denied under opt-in — the one default that is safe to show any visitor anywhere.
|
|
111
|
+
* Prerendered/CDN-cached markup must carry nothing region-specific, and a missing geo
|
|
112
|
+
* header means "unknown visitor", never "known non-EU visitor".
|
|
113
|
+
*
|
|
114
|
+
* @since 1.0.0-canary.6
|
|
115
|
+
*/
|
|
116
|
+
export declare const STRICTEST_INITIAL_CONSENT: InitialConsent;
|
|
117
|
+
/**
|
|
118
|
+
* Guards an `InitialConsent` read from untrusted storage (a session cache, a cookie).
|
|
119
|
+
* Enforces the mode/region pairing rule; the one deliberate exception is
|
|
120
|
+
* {@link STRICTEST_INITIAL_CONSENT}'s own pairing — stricter than the region's usual
|
|
121
|
+
* mode, never looser.
|
|
122
|
+
*
|
|
123
|
+
* @since 1.0.0-canary.6
|
|
124
|
+
*/
|
|
125
|
+
export declare function isInitialConsent(value: unknown): value is InitialConsent;
|
|
126
|
+
/**
|
|
127
|
+
* Vietnam's PDPL and GDPR both expect a record of *when* and *under what policy* consent
|
|
128
|
+
* was given, not just per-category flags — `policyVersion` lets a later policy change
|
|
129
|
+
* invalidate stale consent.
|
|
130
|
+
*
|
|
131
|
+
* @since 0.5.0-canary.4
|
|
132
|
+
*/
|
|
133
|
+
export interface ConsentRecord {
|
|
134
|
+
decision: ConsentDecision;
|
|
135
|
+
policyVersion: string;
|
|
136
|
+
timestamp: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Persistence backend for the visitor's consent decision — swap in your own
|
|
140
|
+
* implementation for non-browser environments or a different persistence layer.
|
|
141
|
+
*
|
|
142
|
+
* @since 0.5.0-canary.4
|
|
143
|
+
*/
|
|
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;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The stored decision if one exists under the current `policyVersion`, normalized to drop
|
|
156
|
+
* any tampered extra keys — `undefined` if there is none yet, the record is malformed, or
|
|
157
|
+
* it was recorded under a superseded policy version.
|
|
158
|
+
*
|
|
159
|
+
* @since 1.0.0-canary.6
|
|
160
|
+
*/
|
|
161
|
+
export declare function readStoredDecision(storage: ConsentStorage, policyVersion: string): ConsentDecision | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* @since 1.0.0-canary.6
|
|
164
|
+
*/
|
|
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;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The consent a tracker should honor right now: the stored decision if one exists, else
|
|
175
|
+
* the region default — the same rule `useConsent` applies to its `effectiveConsent`, so a
|
|
176
|
+
* non-React gate (e.g. a tracker's `isAnalyticsAllowed` option) doesn't have to reimplement
|
|
177
|
+
* "read storage, validate the policy version, fall back to `resolveDefaultConsent`" itself.
|
|
178
|
+
*
|
|
179
|
+
* @since 1.0.0-canary.6
|
|
180
|
+
*/
|
|
181
|
+
export declare function resolveEffectiveConsent(options: ResolveEffectiveConsentOptions): ConsentDecision;
|
|
182
|
+
//# sourceMappingUR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AOG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,8BAA8B,GAAG,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;;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AS,CAAC;QACzC,CAAC,eAAe,CAAC,MAAM,CAAC;QACxB,CAAC,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 declare const ONE_YEAR_IN_SECONDS: number;
|
|
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 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"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a package `ConsentDecision` to the vendor-agnostic {@link AdConsentState}.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0-canary.7
|
|
5
|
+
*/
|
|
6
|
+
export function toAdConsentState(decision) {
|
|
7
|
+
return {
|
|
8
|
+
limitedDataUse: !decision.ads,
|
|
9
|
+
transmissionAllowed: decision.analytics,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ad-consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ad-consent.js","sourceRoot":"","sources":["../../src/destinations/ad-consent.ts"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAyB;IACxD,OAAO;QACL,cAAc,EAAE,CAAC,QAAQ,CAAC,GAAG;QAC7B,mBAAmB,EAAE,QAAQ,CAAC,SAAS;KACxC,CAAC;AACJ,CAAC"}
|