@codefast/tracking 0.5.0-canary.5 → 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 +220 -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 +203 -108
- 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,80 @@
|
|
|
1
|
+
import type { ConsentCategory, InitialConsent } from "#/core/consent";
|
|
2
|
+
import type { ConsentReceipt, ConsentReceiptInput } from "#/core/consent-receipt";
|
|
3
|
+
import type { AnonymousIdCookieOptions } from "#/server/anonymous-id-cookie";
|
|
4
|
+
import type { ReceiptStore } from "#/server/consent-receipt-store";
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0-canary.7
|
|
7
|
+
*/
|
|
8
|
+
export interface InitialConsentFromRequestOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Header carrying the ISO 3166-1 alpha-2 country code.
|
|
11
|
+
*
|
|
12
|
+
* @defaultValue "x-vercel-ip-country"
|
|
13
|
+
*/
|
|
14
|
+
countryHeaderName?: string | undefined;
|
|
15
|
+
/** Categories the app's prompt asks about — opt-out regions grant exactly these by default. */
|
|
16
|
+
requestedCategories: ReadonlyArray<ConsentCategory>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Region-correct `InitialConsent` for the current request: reads the platform geo header
|
|
20
|
+
* and `sec-gpc`, fails closed when geo is missing, and stamps
|
|
21
|
+
* `cache-control: private, no-store` — the value is per-visitor by definition, so no
|
|
22
|
+
* shared cache may ever store the response carrying it.
|
|
23
|
+
*
|
|
24
|
+
* Server-only: deny this subpath in the client environment via Start's `importProtection`
|
|
25
|
+
* — the compiler already strips it with stubbed handler bodies.
|
|
26
|
+
*
|
|
27
|
+
* @since 1.0.0-canary.6
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveInitialConsentFromRequest(options: InitialConsentFromRequestOptions): InitialConsent;
|
|
30
|
+
/**
|
|
31
|
+
* Persists (or prolongs) a client-minted anonymous id via the framework's `setCookie` (which
|
|
32
|
+
* appends, so it never clobbers another `Set-Cookie` on the response) — the server re-issue
|
|
33
|
+
* that escapes Safari ITP's 7-day cap on script-written cookies. Validation lives in
|
|
34
|
+
* `resolveAnonymousIdCookie`: a non-UUID id throws, so this can safely back a public server
|
|
35
|
+
* function without echoing attacker input into a header.
|
|
36
|
+
*
|
|
37
|
+
* @since 1.0.0-canary.6
|
|
38
|
+
*/
|
|
39
|
+
export declare function setAnonymousIdResponseCookie(options: AnonymousIdCookieOptions): void;
|
|
40
|
+
/**
|
|
41
|
+
* Expires the anonymous-id cookie on the current response — the server half of a consent withdrawal.
|
|
42
|
+
*
|
|
43
|
+
* @since 1.0.0-canary.6
|
|
44
|
+
*/
|
|
45
|
+
export declare function clearAnonymousIdResponseCookie(cookieName: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* The client-visible acknowledgement of a recorded receipt — deliberately minimal so the
|
|
48
|
+
* stored PII (`subjectId`, `ipCoarse`) is never echoed back over the wire.
|
|
49
|
+
*
|
|
50
|
+
* @since 1.0.0-canary.7
|
|
51
|
+
*/
|
|
52
|
+
export interface ConsentReceiptAck {
|
|
53
|
+
receiptId: string;
|
|
54
|
+
timestamp: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @since 1.0.0-canary.7
|
|
58
|
+
*/
|
|
59
|
+
export interface RecordConsentReceiptFromRequestOptions {
|
|
60
|
+
input: ConsentReceiptInput;
|
|
61
|
+
/**
|
|
62
|
+
* Optional tamper-evidence signer — supply an HMAC/signature over the receipt to stamp an
|
|
63
|
+
* `integrityKey`. Omit it and the stored receipt carries none.
|
|
64
|
+
*/
|
|
65
|
+
sign?: ((receipt: Omit<ConsentReceipt, "integrityKey">) => string) | undefined;
|
|
66
|
+
store: ReceiptStore;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Records a consent receipt for the current request: rejects a body-supplied IP, derives a
|
|
70
|
+
* coarsened one from the connection, builds the server-stamped receipt, appends it to the
|
|
71
|
+
* store, and stamps `cache-control: no-store` — the response carries PII, so no cache
|
|
72
|
+
* (shared or private) may store it. Returns a minimal ack, never the stored record.
|
|
73
|
+
*
|
|
74
|
+
* @throws Error when `input` fails {@link isConsentReceiptInput} (including a body that
|
|
75
|
+
* carries an `ip`/`ipCoarse` field — the server owns IP derivation).
|
|
76
|
+
*
|
|
77
|
+
* @since 1.0.0-canary.7
|
|
78
|
+
*/
|
|
79
|
+
export declare function recordConsentReceiptFromRequest(options: RecordConsentReceiptFromRequestOptions): Promise<ConsentReceiptAck>;
|
|
80
|
+
//# sourceMappingURL=tanstack-start.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tanstack-start.d.ts","sourceRoot":"","sources":["../../src/adapters/tanstack-start.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAG7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,+FAA+F;IAC/F,mBAAmB,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,gCAAgC,GAAG,cAAc,CAQ1G;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAQpF;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAIvE;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,sCAAsC;IACrD,KAAK,EAAE,mBAAmB,CAAC;IAC3B;;;OAGG;IACH,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IAC/E,KAAK,EAAE,YAAY,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,+BAA+B,CACnD,OAAO,EAAE,sCAAsC,GAC9C,OAAO,CAAC,iBAAiB,CAAC,CAe5B"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { deleteCookie, getRequestHeader, getRequestIP, setCookie, setResponseHeader, } from "@tanstack/react-start/server";
|
|
2
|
+
import { isConsentReceiptInput } from "#/core/consent-receipt";
|
|
3
|
+
import { resolveAnonymousIdCookie, resolveClearAnonymousIdCookie } from "#/server/anonymous-id-cookie";
|
|
4
|
+
import { buildConsentReceipt } from "#/server/consent-receipt";
|
|
5
|
+
import { resolveInitialConsent } from "#/server/initial-consent";
|
|
6
|
+
/**
|
|
7
|
+
* Region-correct `InitialConsent` for the current request: reads the platform geo header
|
|
8
|
+
* and `sec-gpc`, fails closed when geo is missing, and stamps
|
|
9
|
+
* `cache-control: private, no-store` — the value is per-visitor by definition, so no
|
|
10
|
+
* shared cache may ever store the response carrying it.
|
|
11
|
+
*
|
|
12
|
+
* Server-only: deny this subpath in the client environment via Start's `importProtection`
|
|
13
|
+
* — the compiler already strips it with stubbed handler bodies.
|
|
14
|
+
*
|
|
15
|
+
* @since 1.0.0-canary.6
|
|
16
|
+
*/
|
|
17
|
+
export function resolveInitialConsentFromRequest(options) {
|
|
18
|
+
setResponseHeader("cache-control", "private, no-store");
|
|
19
|
+
return resolveInitialConsent({
|
|
20
|
+
countryCode: getRequestHeader(options.countryHeaderName ?? "x-vercel-ip-country"),
|
|
21
|
+
hasGlobalPrivacyControlSignal: getRequestHeader("sec-gpc") === "1",
|
|
22
|
+
requestedCategories: options.requestedCategories,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Persists (or prolongs) a client-minted anonymous id via the framework's `setCookie` (which
|
|
27
|
+
* appends, so it never clobbers another `Set-Cookie` on the response) — the server re-issue
|
|
28
|
+
* that escapes Safari ITP's 7-day cap on script-written cookies. Validation lives in
|
|
29
|
+
* `resolveAnonymousIdCookie`: a non-UUID id throws, so this can safely back a public server
|
|
30
|
+
* function without echoing attacker input into a header.
|
|
31
|
+
*
|
|
32
|
+
* @since 1.0.0-canary.6
|
|
33
|
+
*/
|
|
34
|
+
export function setAnonymousIdResponseCookie(options) {
|
|
35
|
+
const { name, value, ...attributes } = resolveAnonymousIdCookie({
|
|
36
|
+
cookieName: options.cookieName,
|
|
37
|
+
id: options.id,
|
|
38
|
+
maxAgeSeconds: options.maxAgeSeconds,
|
|
39
|
+
});
|
|
40
|
+
setCookie(name, value, attributes);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Expires the anonymous-id cookie on the current response — the server half of a consent withdrawal.
|
|
44
|
+
*
|
|
45
|
+
* @since 1.0.0-canary.6
|
|
46
|
+
*/
|
|
47
|
+
export function clearAnonymousIdResponseCookie(cookieName) {
|
|
48
|
+
const { name, ...attributes } = resolveClearAnonymousIdCookie(cookieName);
|
|
49
|
+
deleteCookie(name, attributes);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Records a consent receipt for the current request: rejects a body-supplied IP, derives a
|
|
53
|
+
* coarsened one from the connection, builds the server-stamped receipt, appends it to the
|
|
54
|
+
* store, and stamps `cache-control: no-store` — the response carries PII, so no cache
|
|
55
|
+
* (shared or private) may store it. Returns a minimal ack, never the stored record.
|
|
56
|
+
*
|
|
57
|
+
* @throws Error when `input` fails {@link isConsentReceiptInput} (including a body that
|
|
58
|
+
* carries an `ip`/`ipCoarse` field — the server owns IP derivation).
|
|
59
|
+
*
|
|
60
|
+
* @since 1.0.0-canary.7
|
|
61
|
+
*/
|
|
62
|
+
export async function recordConsentReceiptFromRequest(options) {
|
|
63
|
+
setResponseHeader("cache-control", "no-store");
|
|
64
|
+
if (!isConsentReceiptInput(options.input)) {
|
|
65
|
+
throw new Error("Invalid consent receipt input");
|
|
66
|
+
}
|
|
67
|
+
// getRequestIP reads the platform/socket IP, trusting X-Forwarded-For's first hop — safe
|
|
68
|
+
// behind the CDN/proxy this app deploys to, and the maintained path over hand-parsing headers.
|
|
69
|
+
const rawIp = getRequestIP({ xForwardedFor: true });
|
|
70
|
+
const receipt = buildConsentReceipt({ input: options.input, rawIp, sign: options.sign });
|
|
71
|
+
await options.store.append(receipt);
|
|
72
|
+
return { receiptId: receipt.receiptId, timestamp: receipt.timestamp };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=tanstack-start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tanstack-start.js","sourceRoot":"","sources":["../../src/adapters/tanstack-start.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAgBjE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gCAAgC,CAAC,OAAyC;IACxF,iBAAiB,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;IAExD,OAAO,qBAAqB,CAAC;QAC3B,WAAW,EAAE,gBAAgB,CAAC,OAAO,CAAC,iBAAiB,IAAI,qBAAqB,CAAC;QACjF,6BAA6B,EAAE,gBAAgB,CAAC,SAAS,CAAC,KAAK,GAAG;QAClE,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;KACjD,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAAC,OAAiC;IAC5E,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,UAAU,EAAE,GAAG,wBAAwB,CAAC;QAC9D,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,aAAa,EAAE,OAAO,CAAC,aAAa;KACrC,CAAC,CAAC;IAEH,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAAC,UAAkB;IAC/D,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAE1E,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACjC,CAAC;AA0BD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,OAA+C;IAE/C,iBAAiB,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAE/C,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,yFAAyF;IACzF,+FAA+F;IAC/F,MAAM,KAAK,GAAG,YAAY,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,mBAAmB,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAEzF,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEpC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ConsentCategory, ConsentDecision } from "#/core/consent";
|
|
2
|
+
/**
|
|
3
|
+
* TCF/GPP interop reconciler (spec-ad-consent-frameworks): the system **reads** an external
|
|
4
|
+
* CMP and reconciles it with the native `{ ads, analytics }` decision — it never becomes a
|
|
5
|
+
* CMP, mints TC/GPP strings, or hard-codes TCF purpose ids or the Google vendor id (that
|
|
6
|
+
* mapping is ad-ops policy, so the caller derives `CmpConsentSignal` and passes it in).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Liveness of a detected CMP. `"out-of-scope"` is TCF `gdprApplies === false` / no applicable
|
|
10
|
+
* GPP section — the framework does not govern this user, so native consent stands.
|
|
11
|
+
*
|
|
12
|
+
* @since 1.0.0-canary.7
|
|
13
|
+
*/
|
|
14
|
+
export type CmpStatus = "loading" | "out-of-scope" | "ready";
|
|
15
|
+
/**
|
|
16
|
+
* A CMP's governance over the native decision, already derived from TCData/GPP by ad-ops policy.
|
|
17
|
+
*
|
|
18
|
+
* @since 1.0.0-canary.7
|
|
19
|
+
*/
|
|
20
|
+
export interface CmpConsentSignal {
|
|
21
|
+
/** Per-governed-category grant, read once `status` is `"ready"`. */
|
|
22
|
+
decision?: Partial<ConsentDecision> | undefined;
|
|
23
|
+
/** Categories this CMP governs in the current scope — the resolver overrides only these. */
|
|
24
|
+
governs: ReadonlyArray<ConsentCategory>;
|
|
25
|
+
status: CmpStatus;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @since 1.0.0-canary.7
|
|
29
|
+
*/
|
|
30
|
+
export interface ReconcileAdFrameworkConsentOptions {
|
|
31
|
+
/** The live CMP signal, or omitted when no CMP is present (the resolver is then inert). */
|
|
32
|
+
cmp?: CmpConsentSignal | undefined;
|
|
33
|
+
/** Native GPC — can only tighten `ads`, never loosen a CMP grant. */
|
|
34
|
+
hasGlobalPrivacyControlSignal: boolean;
|
|
35
|
+
/** The stored/default decision that stands wherever no CMP governs. */
|
|
36
|
+
native: ConsentDecision;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reconciles native consent with a CMP source of truth per spec-ad-consent-frameworks §3:
|
|
40
|
+
* a governing CMP overrides its categories (fail-closed to denied while loading); a missing
|
|
41
|
+
* or out-of-scope CMP leaves native standing; GPC always tightens `ads` last.
|
|
42
|
+
*
|
|
43
|
+
* @since 1.0.0-canary.7
|
|
44
|
+
*/
|
|
45
|
+
export declare function reconcileAdFrameworkConsent(options: ReconcileAdFrameworkConsentOptions): ConsentDecision;
|
|
46
|
+
/**
|
|
47
|
+
* Detects a TCF CMP without reading it — `typeof __tcfapi === "function"` (spec §3).
|
|
48
|
+
*
|
|
49
|
+
* @since 1.0.0-canary.7
|
|
50
|
+
*/
|
|
51
|
+
export declare function hasTcfApi(scope?: {
|
|
52
|
+
__tcfapi?: unknown;
|
|
53
|
+
}): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Detects a GPP CMP without reading it — `typeof __gpp === "function"` (spec §3).
|
|
56
|
+
*
|
|
57
|
+
* @since 1.0.0-canary.7
|
|
58
|
+
*/
|
|
59
|
+
export declare function hasGppApi(scope?: {
|
|
60
|
+
__gpp?: unknown;
|
|
61
|
+
}): boolean;
|
|
62
|
+
//# sourceMappingURL=ad-framework-consent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ad-framework-consent.d.ts","sourceRoot":"","sources":["../../src/client/ad-framework-consent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEvE;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,cAAc,GAAG,OAAO,CAAC;AAE7D;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;IAChD,4FAA4F;IAC5F,OAAO,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACxC,MAAM,EAAE,SAAS,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kCAAkC;IACjD,2FAA2F;IAC3F,GAAG,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACnC,qEAAqE;IACrE,6BAA6B,EAAE,OAAO,CAAC;IACvC,uEAAuE;IACvE,MAAM,EAAE,eAAe,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kCAAkC,GAAG,eAAe,CAkBxG;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAyC,GAAG,OAAO,CAEvG;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAsC,GAAG,OAAO,CAEjG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reconciles native consent with a CMP source of truth per spec-ad-consent-frameworks §3:
|
|
3
|
+
* a governing CMP overrides its categories (fail-closed to denied while loading); a missing
|
|
4
|
+
* or out-of-scope CMP leaves native standing; GPC always tightens `ads` last.
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0-canary.7
|
|
7
|
+
*/
|
|
8
|
+
export function reconcileAdFrameworkConsent(options) {
|
|
9
|
+
const result = { ...options.native };
|
|
10
|
+
const { cmp } = options;
|
|
11
|
+
// A governing CMP overrides only the categories it governs; no CMP / out-of-scope leaves native.
|
|
12
|
+
if (cmp && cmp.status !== "out-of-scope") {
|
|
13
|
+
for (const category of cmp.governs) {
|
|
14
|
+
// Fail closed until the CMP resolves; otherwise the CMP value wins for its categories.
|
|
15
|
+
result[category] = cmp.status === "loading" ? false : (cmp.decision?.[category] ?? false);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// GPC can only tighten `ads` — applied last so it wins over any CMP grant.
|
|
19
|
+
if (options.hasGlobalPrivacyControlSignal) {
|
|
20
|
+
result.ads = false;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Detects a TCF CMP without reading it — `typeof __tcfapi === "function"` (spec §3).
|
|
26
|
+
*
|
|
27
|
+
* @since 1.0.0-canary.7
|
|
28
|
+
*/
|
|
29
|
+
export function hasTcfApi(scope = globalThis) {
|
|
30
|
+
return typeof scope.__tcfapi === "function";
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Detects a GPP CMP without reading it — `typeof __gpp === "function"` (spec §3).
|
|
34
|
+
*
|
|
35
|
+
* @since 1.0.0-canary.7
|
|
36
|
+
*/
|
|
37
|
+
export function hasGppApi(scope = globalThis) {
|
|
38
|
+
return typeof scope.__gpp === "function";
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=ad-framework-consent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ad-framework-consent.js","sourceRoot":"","sources":["../../src/client/ad-framework-consent.ts"],"names":[],"mappings":"AA0CA;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA2C;IACrF,MAAM,MAAM,GAAoB,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACtD,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAExB,iGAAiG;IACjG,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;QACzC,KAAK,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YACnC,uFAAuF;YACvF,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;IAED,2EAA2E;IAC3E,IAAI,OAAO,CAAC,6BAA6B,EAAE,CAAC;QAC1C,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAK,GAA2B,UAAoC;IAC5F,OAAO,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,CAAC;AAC9C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,KAAK,GAAwB,UAAiC;IACtF,OAAO,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared `document.cookie` writer for the client-side cookie lanes (anonymous id, consent
|
|
3
|
+
* mirror): Secure on HTTPS so values never ride plain HTTP, SameSite=Lax, never HttpOnly —
|
|
4
|
+
* the client must read its own cookies back. A no-op without a `document` (SSR).
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0-canary.6
|
|
7
|
+
*/
|
|
8
|
+
export declare function writeBrowserCookie(cookieName: string, value: string, maxAgeSeconds: number): void;
|
|
9
|
+
//# sourceMappingURL=browser-cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-cookie.d.ts","sourceRoot":"","sources":["../../src/client/browser-cookie.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAQjG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared `document.cookie` writer for the client-side cookie lanes (anonymous id, consent
|
|
3
|
+
* mirror): Secure on HTTPS so values never ride plain HTTP, SameSite=Lax, never HttpOnly —
|
|
4
|
+
* the client must read its own cookies back. A no-op without a `document` (SSR).
|
|
5
|
+
*
|
|
6
|
+
* @since 1.0.0-canary.6
|
|
7
|
+
*/
|
|
8
|
+
export function writeBrowserCookie(cookieName, value, maxAgeSeconds) {
|
|
9
|
+
if (typeof document === "undefined") {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const secure = globalThis.location.protocol === "https:" ? "; secure" : "";
|
|
13
|
+
document.cookie = `${cookieName}=${value}; path=/; max-age=${String(maxAgeSeconds)}; samesite=lax${secure}`;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=browser-cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-cookie.js","sourceRoot":"","sources":["../../src/client/browser-cookie.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,KAAa,EAAE,aAAqB;IACzF,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3E,QAAQ,CAAC,MAAM,GAAG,GAAG,UAAU,IAAI,KAAK,qBAAqB,MAAM,CAAC,aAAa,CAAC,iBAAiB,MAAM,EAAE,CAAC;AAC9G,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { InitialConsentStore } from "#/client/initial-consent-store";
|
|
2
|
+
import type { ConsentStorage, InitialConsent } from "#/core/consent";
|
|
3
|
+
import type { ConsentConfig } from "#/core/consent-config";
|
|
4
|
+
/**
|
|
5
|
+
* @since 1.0.0-canary.6
|
|
6
|
+
*/
|
|
7
|
+
export interface ConsentRuntimeOptions {
|
|
8
|
+
config: ConsentConfig;
|
|
9
|
+
/** Re-read per event so a GPC change applies without recreating the runtime. Defaults to the real navigator signal. */
|
|
10
|
+
hasGlobalPrivacyControlSignal?: (() => boolean) | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* `sessionStorage` key caching the resolved region default, so only the first page
|
|
13
|
+
* load of a session pays the round trip — omit to resolve once per page load instead.
|
|
14
|
+
*/
|
|
15
|
+
initialConsentSessionStorageKey?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The per-visitor server lane — typically a server function wrapping
|
|
18
|
+
* `resolveInitialConsentFromRequest`. Shared/CDN-cached HTML can carry nothing
|
|
19
|
+
* region-specific, so this is the only place the region-correct default may come from.
|
|
20
|
+
*/
|
|
21
|
+
resolveInitialConsent: () => Promise<InitialConsent>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The live client-side consent instances, all derived from one `ConsentConfig` — create
|
|
25
|
+
* it once at module scope and every surface (banner hook, tracker gate, privacy page)
|
|
26
|
+
* shares the same storage and region resolution by construction.
|
|
27
|
+
*
|
|
28
|
+
* @since 1.0.0-canary.6
|
|
29
|
+
*/
|
|
30
|
+
export interface ConsentRuntime {
|
|
31
|
+
config: ConsentConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Kicks off region resolution — single-flight and idempotent. Call it early (e.g. at
|
|
34
|
+
* router creation, window-guarded) so the round trip overlaps hydration instead of
|
|
35
|
+
* waiting for the first mount effect.
|
|
36
|
+
*/
|
|
37
|
+
ensureInitialConsentResolved: () => void;
|
|
38
|
+
/** Feed to `useInitialConsent` for the reactive region default. */
|
|
39
|
+
initialConsentStore: InitialConsentStore;
|
|
40
|
+
/** Non-React gate for `createClientTracker` — the same rule `useConsent` applies. */
|
|
41
|
+
isAnalyticsAllowed: () => boolean;
|
|
42
|
+
/** The one `ConsentStorage` instance every surface must share. */
|
|
43
|
+
storage: ConsentStorage;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Composes the client half of the consent lane from a single `ConsentConfig`:
|
|
47
|
+
* `localStorage`-backed decision storage, the initial-consent store over the app's
|
|
48
|
+
* server lane, and the non-React analytics gate wired to that store's resolved mode.
|
|
49
|
+
*
|
|
50
|
+
* @since 1.0.0-canary.6
|
|
51
|
+
*/
|
|
52
|
+
export declare function createConsentRuntime(options: ConsentRuntimeOptions): ConsentRuntime;
|
|
53
|
+
//# sourceMappingURL=consent-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-runtime.d.ts","sourceRoot":"","sources":["../../src/client/consent-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAG1E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,uHAAuH;IACvH,6BAA6B,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,+BAA+B,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrD;;;;OAIG;IACH,qBAAqB,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;CACtD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,aAAa,CAAC;IACtB;;;;OAIG;IACH,4BAA4B,EAAE,MAAM,IAAI,CAAC;IACzC,mEAAmE;IACnE,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,qFAAqF;IACrF,kBAAkB,EAAE,MAAM,OAAO,CAAC;IAClC,kEAAkE;IAClE,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAqBnF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createLocalStorageConsentStorage } from "#/client/consent-storage";
|
|
2
|
+
import { hasGlobalPrivacyControlSignal } from "#/client/gpc";
|
|
3
|
+
import { createInitialConsentStore } from "#/client/initial-consent-store";
|
|
4
|
+
import { createIsAnalyticsAllowed } from "#/client/is-analytics-allowed";
|
|
5
|
+
/**
|
|
6
|
+
* Composes the client half of the consent lane from a single `ConsentConfig`:
|
|
7
|
+
* `localStorage`-backed decision storage, the initial-consent store over the app's
|
|
8
|
+
* server lane, and the non-React analytics gate wired to that store's resolved mode.
|
|
9
|
+
*
|
|
10
|
+
* @since 1.0.0-canary.6
|
|
11
|
+
*/
|
|
12
|
+
export function createConsentRuntime(options) {
|
|
13
|
+
const { config } = options;
|
|
14
|
+
const storage = createLocalStorageConsentStorage(config.storageKey);
|
|
15
|
+
const initialConsentStore = createInitialConsentStore({
|
|
16
|
+
resolve: options.resolveInitialConsent,
|
|
17
|
+
sessionStorageKey: options.initialConsentSessionStorageKey,
|
|
18
|
+
});
|
|
19
|
+
const isAnalyticsAllowed = createIsAnalyticsAllowed({
|
|
20
|
+
config,
|
|
21
|
+
getMode: () => initialConsentStore.getSnapshot().initialConsent.mode,
|
|
22
|
+
hasGlobalPrivacyControlSignal: options.hasGlobalPrivacyControlSignal ?? hasGlobalPrivacyControlSignal,
|
|
23
|
+
storage,
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
config,
|
|
27
|
+
ensureInitialConsentResolved: initialConsentStore.ensureResolved,
|
|
28
|
+
initialConsentStore,
|
|
29
|
+
isAnalyticsAllowed,
|
|
30
|
+
storage,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=consent-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-runtime.js","sourceRoot":"","sources":["../../src/client/consent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AA+CzE;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA8B;IACjE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,OAAO,GAAG,gCAAgC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACpE,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;QACpD,OAAO,EAAE,OAAO,CAAC,qBAAqB;QACtC,iBAAiB,EAAE,OAAO,CAAC,+BAA+B;KAC3D,CAAC,CAAC;IACH,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;QAClD,MAAM;QACN,OAAO,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,IAAI;QACpE,6BAA6B,EAAE,OAAO,CAAC,6BAA6B,IAAI,6BAA6B;QACrG,OAAO;KACR,CAAC,CAAC;IAEH,OAAO;QACL,MAAM;QACN,4BAA4B,EAAE,mBAAmB,CAAC,cAAc;QAChE,mBAAmB;QACnB,kBAAkB;QAClB,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { ConsentStorage } from "
|
|
2
|
-
|
|
3
|
-
//#region src/client/consent-storage.d.ts
|
|
1
|
+
import type { ConsentStorage } from "#/core/consent";
|
|
4
2
|
/**
|
|
5
3
|
* `localStorage`-backed consent storage. Corrupt state, a private-mode/quota error, or no
|
|
6
4
|
* `window` (SSR) degrades to an in-memory record — the visitor's decision still applies
|
|
7
5
|
* for the session instead of re-prompting in a loop. `subscribe` fires for same-tab
|
|
8
6
|
* writes and, via the `storage` event, for decisions made in other tabs.
|
|
9
7
|
*
|
|
8
|
+
* `load()` parses and validates at most once per change: the result is cached and
|
|
9
|
+
* invalidated by `save`/`clear` and by cross-tab `storage` events, so per-event consent
|
|
10
|
+
* gates and per-render `useSyncExternalStore` snapshots cost a memory read, not a
|
|
11
|
+
* `JSON.parse`.
|
|
12
|
+
*
|
|
10
13
|
* @remarks
|
|
11
14
|
* The record persists as plain `JSON.stringify(ConsentRecord)` — a stable contract, so
|
|
12
15
|
* pre-hydration inline scripts (e.g. a Consent Mode default bootstrap) can read the
|
|
@@ -14,6 +17,5 @@ import { ConsentStorage } from "../core/consent.mjs";
|
|
|
14
17
|
*
|
|
15
18
|
* @since 0.5.0-canary.4
|
|
16
19
|
*/
|
|
17
|
-
declare function createLocalStorageConsentStorage(storageKey: string): ConsentStorage;
|
|
18
|
-
//#
|
|
19
|
-
export { createLocalStorageConsentStorage };
|
|
20
|
+
export declare function createLocalStorageConsentStorage(storageKey: string): ConsentStorage;
|
|
21
|
+
//# sourceMappingURL=consent-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-storage.d.ts","sourceRoot":"","sources":["../../src/client/consent-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGpE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAuGnF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { isConsentRecord } from "#/core/consent";
|
|
2
|
+
/**
|
|
3
|
+
* `localStorage`-backed consent storage. Corrupt state, a private-mode/quota error, or no
|
|
4
|
+
* `window` (SSR) degrades to an in-memory record — the visitor's decision still applies
|
|
5
|
+
* for the session instead of re-prompting in a loop. `subscribe` fires for same-tab
|
|
6
|
+
* writes and, via the `storage` event, for decisions made in other tabs.
|
|
7
|
+
*
|
|
8
|
+
* `load()` parses and validates at most once per change: the result is cached and
|
|
9
|
+
* invalidated by `save`/`clear` and by cross-tab `storage` events, so per-event consent
|
|
10
|
+
* gates and per-render `useSyncExternalStore` snapshots cost a memory read, not a
|
|
11
|
+
* `JSON.parse`.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* The record persists as plain `JSON.stringify(ConsentRecord)` — a stable contract, so
|
|
15
|
+
* pre-hydration inline scripts (e.g. a Consent Mode default bootstrap) can read the
|
|
16
|
+
* decision synchronously before any tag fires.
|
|
17
|
+
*
|
|
18
|
+
* @since 0.5.0-canary.4
|
|
19
|
+
*/
|
|
20
|
+
export function createLocalStorageConsentStorage(storageKey) {
|
|
21
|
+
const listeners = new Set();
|
|
22
|
+
let memoryRecord;
|
|
23
|
+
// Keyed by the raw string so ANY write path (save(), another tab, dev tools) is caught
|
|
24
|
+
// by a cheap string compare — parse + validate re-run only when the value changed.
|
|
25
|
+
let cache;
|
|
26
|
+
function notify() {
|
|
27
|
+
for (const listener of listeners) {
|
|
28
|
+
listener();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
clear() {
|
|
33
|
+
if (typeof globalThis.window === "undefined") {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
memoryRecord = undefined;
|
|
37
|
+
cache = undefined;
|
|
38
|
+
try {
|
|
39
|
+
globalThis.window.localStorage.removeItem(storageKey);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
/* storage blocked (private mode / quota) */
|
|
43
|
+
}
|
|
44
|
+
notify();
|
|
45
|
+
},
|
|
46
|
+
load() {
|
|
47
|
+
if (typeof globalThis.window === "undefined") {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const raw = globalThis.window.localStorage.getItem(storageKey);
|
|
52
|
+
if (cache && raw === cache.raw) {
|
|
53
|
+
return cache.record;
|
|
54
|
+
}
|
|
55
|
+
let record;
|
|
56
|
+
if (raw) {
|
|
57
|
+
const parsed = JSON.parse(raw);
|
|
58
|
+
// Drop malformed records at the source — mirrors the offline-queue storage guard.
|
|
59
|
+
record = isConsentRecord(parsed) ? parsed : memoryRecord;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
record = memoryRecord;
|
|
63
|
+
}
|
|
64
|
+
cache = { raw, record };
|
|
65
|
+
return record;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Storage blocked — never seed the cache off an error path.
|
|
69
|
+
return memoryRecord;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
save(record) {
|
|
73
|
+
if (typeof globalThis.window === "undefined") {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
cache = undefined;
|
|
77
|
+
try {
|
|
78
|
+
globalThis.window.localStorage.setItem(storageKey, JSON.stringify(record));
|
|
79
|
+
// localStorage is authoritative now — a lingering memory copy would shadow an
|
|
80
|
+
// external clear (e.g. the visitor wiping site data).
|
|
81
|
+
memoryRecord = undefined;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Storage blocked (private mode / quota) — keep the decision for this session.
|
|
85
|
+
memoryRecord = record;
|
|
86
|
+
}
|
|
87
|
+
notify();
|
|
88
|
+
},
|
|
89
|
+
subscribe(listener) {
|
|
90
|
+
listeners.add(listener);
|
|
91
|
+
// The `storage` event only fires in *other* tabs; same-tab writes go through notify().
|
|
92
|
+
function handleStorageEvent(event) {
|
|
93
|
+
if (event.key === null || event.key === storageKey) {
|
|
94
|
+
listener();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (typeof globalThis.window !== "undefined") {
|
|
98
|
+
globalThis.window.addEventListener("storage", handleStorageEvent);
|
|
99
|
+
}
|
|
100
|
+
return () => {
|
|
101
|
+
listeners.delete(listener);
|
|
102
|
+
if (typeof globalThis.window !== "undefined") {
|
|
103
|
+
globalThis.window.removeEventListener("storage", handleStorageEvent);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=consent-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-storage.js","sourceRoot":"","sources":["../../src/client/consent-storage.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ConsentDecision } from "#/core/consent";
|
|
2
|
+
/**
|
|
3
|
+
* @since 1.0.0-canary.6
|
|
4
|
+
*/
|
|
5
|
+
export interface ConsentWithdrawalHandlerOptions {
|
|
6
|
+
/** Forget the cookie-backed visitor id when analytics is denied. */
|
|
7
|
+
clearAnonymousId?: (() => void) | undefined;
|
|
8
|
+
/** Expire Google's `_ga` / `_ga_*` cookies when analytics is denied. */
|
|
9
|
+
clearGoogleAnalyticsCookies?: (() => void) | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `useConsent({ onDecision })` handler that clears first-party tracking state when the
|
|
13
|
+
* visitor denies (or withdraws) analytics. Grant paths are a no-op.
|
|
14
|
+
*
|
|
15
|
+
* @since 1.0.0-canary.6
|
|
16
|
+
*/
|
|
17
|
+
export declare function createConsentWithdrawalHandler(options: ConsentWithdrawalHandlerOptions): (decision: ConsentDecision) => void;
|
|
18
|
+
//# sourceMappingURL=consent-withdrawal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-withdrawal.d.ts","sourceRoot":"","sources":["../../src/client/consent-withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5C,wEAAwE;IACxE,2BAA2B,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;CACxD;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAWrC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useConsent({ onDecision })` handler that clears first-party tracking state when the
|
|
3
|
+
* visitor denies (or withdraws) analytics. Grant paths are a no-op.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0-canary.6
|
|
6
|
+
*/
|
|
7
|
+
export function createConsentWithdrawalHandler(options) {
|
|
8
|
+
const { clearAnonymousId, clearGoogleAnalyticsCookies } = options;
|
|
9
|
+
return (decision) => {
|
|
10
|
+
if (decision.analytics) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
clearAnonymousId?.();
|
|
14
|
+
clearGoogleAnalyticsCookies?.();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=consent-withdrawal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consent-withdrawal.js","sourceRoot":"","sources":["../../src/client/consent-withdrawal.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAAwC;IAExC,MAAM,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,GAAG,OAAO,CAAC;IAElE,OAAO,CAAC,QAAyB,EAAQ,EAAE;QACzC,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;QAED,gBAAgB,EAAE,EAAE,CAAC;QACrB,2BAA2B,EAAE,EAAE,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0-canary.6
|
|
3
|
+
*/
|
|
4
|
+
export interface CookieAnonymousIdOptions {
|
|
5
|
+
/** Cookie name — must not collide with another cookie on the domain. */
|
|
6
|
+
cookieName: string;
|
|
7
|
+
/** How long the id survives a return visit. Defaults to one year. */
|
|
8
|
+
maxAgeSeconds?: number | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0-canary.6
|
|
12
|
+
*/
|
|
13
|
+
export interface CookieAnonymousId {
|
|
14
|
+
/** Expires the cookie — call when the visitor withdraws tracking consent. */
|
|
15
|
+
clear: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* The existing id **without minting one** — `undefined` when the visitor has none yet.
|
|
18
|
+
* Use this to stamp a receipt/decision with the id that already identifies the visitor,
|
|
19
|
+
* rather than re-reading the cookie or minting a throwaway that never correlates.
|
|
20
|
+
*/
|
|
21
|
+
current: () => string | undefined;
|
|
22
|
+
/** The existing id, or a freshly minted and persisted one. */
|
|
23
|
+
getOrCreate: () => string;
|
|
24
|
+
/**
|
|
25
|
+
* Rolls an *existing* id's expiry forward without ever minting one — safe to call on
|
|
26
|
+
* page load for returning consented visitors (the ITP-refresh path), a no-op for
|
|
27
|
+
* visitors who never got an id.
|
|
28
|
+
*/
|
|
29
|
+
refresh: () => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A `document.cookie`-backed anonymous id — not `localStorage`-only, so a server-owned
|
|
33
|
+
* event can read the same id from the request and correlate to this visitor. Pass
|
|
34
|
+
* `getOrCreate` (not the result of calling it) as `ClientTrackerOptions.anonymousId`:
|
|
35
|
+
* it's invoked lazily, so the cookie is minted only once an event is actually allowed to
|
|
36
|
+
* send, never as an import-time side effect.
|
|
37
|
+
*
|
|
38
|
+
* @since 1.0.0-canary.6
|
|
39
|
+
*/
|
|
40
|
+
export declare function createCookieAnonymousId(options: CookieAnonymousIdOptions): CookieAnonymousId;
|
|
41
|
+
//# sourceMappingURL=cookie-anonymous-id.d.ts.map
|