@codefast/tracking 1.0.0-canary.6 → 1.0.0-canary.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +72 -17
- package/dist/adapters/tanstack-start.d.ts +80 -0
- package/dist/adapters/tanstack-start.d.ts.map +1 -0
- package/dist/adapters/tanstack-start.js +74 -0
- package/dist/adapters/tanstack-start.js.map +1 -0
- package/dist/client/ad-framework-consent.d.ts +62 -0
- package/dist/client/ad-framework-consent.d.ts.map +1 -0
- package/dist/client/ad-framework-consent.js +40 -0
- package/dist/client/ad-framework-consent.js.map +1 -0
- package/dist/client/{browser-cookie.d.mts → browser-cookie.d.ts} +2 -4
- package/dist/client/browser-cookie.d.ts.map +1 -0
- package/dist/client/browser-cookie.js +15 -0
- package/dist/client/browser-cookie.js.map +1 -0
- package/dist/client/consent-runtime.d.ts +53 -0
- package/dist/client/consent-runtime.d.ts.map +1 -0
- package/dist/client/consent-runtime.js +33 -0
- package/dist/client/consent-runtime.js.map +1 -0
- package/dist/client/{consent-storage.d.mts → consent-storage.d.ts} +3 -6
- package/dist/client/consent-storage.d.ts.map +1 -0
- package/dist/client/consent-storage.js +109 -0
- package/dist/client/consent-storage.js.map +1 -0
- package/dist/client/consent-withdrawal.d.ts +18 -0
- package/dist/client/consent-withdrawal.d.ts.map +1 -0
- package/dist/client/consent-withdrawal.js +17 -0
- package/dist/client/consent-withdrawal.js.map +1 -0
- package/dist/client/cookie-anonymous-id.d.ts +41 -0
- package/dist/client/cookie-anonymous-id.d.ts.map +1 -0
- package/dist/client/cookie-anonymous-id.js +65 -0
- package/dist/client/cookie-anonymous-id.js.map +1 -0
- package/dist/client/create-client-tracker.d.ts +60 -0
- package/dist/client/create-client-tracker.d.ts.map +1 -0
- package/dist/client/create-client-tracker.js +91 -0
- package/dist/client/create-client-tracker.js.map +1 -0
- package/dist/client/{gpc.d.mts → gpc.d.ts} +2 -4
- package/dist/client/gpc.d.ts.map +1 -0
- package/dist/client/gpc.js +12 -0
- package/dist/client/gpc.js.map +1 -0
- package/dist/client/initial-consent-store.d.ts +63 -0
- package/dist/client/initial-consent-store.d.ts.map +1 -0
- package/dist/client/initial-consent-store.js +138 -0
- package/dist/client/initial-consent-store.js.map +1 -0
- package/dist/client/is-analytics-allowed.d.ts +26 -0
- package/dist/client/is-analytics-allowed.d.ts.map +1 -0
- package/dist/client/is-analytics-allowed.js +22 -0
- package/dist/client/is-analytics-allowed.js.map +1 -0
- package/dist/client/server-persisted-anonymous-id.d.ts +30 -0
- package/dist/client/server-persisted-anonymous-id.d.ts.map +1 -0
- package/dist/client/server-persisted-anonymous-id.js +72 -0
- package/dist/client/server-persisted-anonymous-id.js.map +1 -0
- package/dist/core/consent-config.d.ts +24 -0
- package/dist/core/consent-config.d.ts.map +1 -0
- package/dist/core/consent-config.js +9 -0
- package/dist/core/consent-config.js.map +1 -0
- package/dist/core/consent-receipt.d.ts +71 -0
- package/dist/core/consent-receipt.d.ts.map +1 -0
- package/dist/core/consent-receipt.js +39 -0
- package/dist/core/consent-receipt.js.map +1 -0
- package/dist/core/{consent.d.mts → consent.d.ts} +49 -51
- package/dist/core/consent.d.ts.map +1 -0
- package/dist/core/consent.js +159 -0
- package/dist/core/consent.js.map +1 -0
- package/dist/core/{cookie.d.mts → cookie.d.ts} +3 -5
- package/dist/core/cookie.d.ts.map +1 -0
- package/dist/core/cookie.js +26 -0
- package/dist/core/cookie.js.map +1 -0
- package/dist/core/destination.d.ts +29 -0
- package/dist/core/destination.d.ts.map +1 -0
- package/dist/core/destination.js +2 -0
- package/dist/core/destination.js.map +1 -0
- package/dist/core/event-catalog.d.ts +35 -0
- package/dist/core/event-catalog.d.ts.map +1 -0
- package/dist/core/event-catalog.js +30 -0
- package/dist/core/event-catalog.js.map +1 -0
- package/dist/core/{event-id.d.mts → event-id.d.ts} +2 -4
- package/dist/core/event-id.d.ts.map +1 -0
- package/dist/core/event-id.js +9 -0
- package/dist/core/event-id.js.map +1 -0
- package/dist/core/tracked-event.d.ts +15 -0
- package/dist/core/tracked-event.d.ts.map +1 -0
- package/dist/core/tracked-event.js +2 -0
- package/dist/core/tracked-event.js.map +1 -0
- package/dist/destinations/ad-consent.d.ts +23 -0
- package/dist/destinations/ad-consent.d.ts.map +1 -0
- package/dist/destinations/ad-consent.js +12 -0
- package/dist/destinations/ad-consent.js.map +1 -0
- package/dist/destinations/google-analytics.d.ts +148 -0
- package/dist/destinations/google-analytics.d.ts.map +1 -0
- package/dist/destinations/google-analytics.js +156 -0
- package/dist/destinations/google-analytics.js.map +1 -0
- package/dist/destinations/google-consent.d.ts +62 -0
- package/dist/destinations/google-consent.d.ts.map +1 -0
- package/dist/destinations/google-consent.js +109 -0
- package/dist/destinations/google-consent.js.map +1 -0
- package/dist/destinations/meta.d.ts +63 -0
- package/dist/destinations/meta.d.ts.map +1 -0
- package/dist/destinations/meta.js +44 -0
- package/dist/destinations/meta.js.map +1 -0
- package/dist/destinations/microsoft-uet.d.ts +56 -0
- package/dist/destinations/microsoft-uet.d.ts.map +1 -0
- package/dist/destinations/microsoft-uet.js +41 -0
- package/dist/destinations/microsoft-uet.js.map +1 -0
- package/dist/destinations/shared.d.ts +18 -0
- package/dist/destinations/shared.d.ts.map +1 -0
- package/dist/destinations/shared.js +19 -0
- package/dist/destinations/shared.js.map +1 -0
- package/dist/destinations/tiktok.d.ts +55 -0
- package/dist/destinations/tiktok.d.ts.map +1 -0
- package/dist/destinations/tiktok.js +40 -0
- package/dist/destinations/tiktok.js.map +1 -0
- package/dist/destinations/vercel-analytics.d.ts +25 -0
- package/dist/destinations/vercel-analytics.d.ts.map +1 -0
- package/dist/destinations/vercel-analytics.js +23 -0
- package/dist/destinations/vercel-analytics.js.map +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/react/consent-banner.d.ts +155 -0
- package/dist/react/consent-banner.d.ts.map +1 -0
- package/dist/react/consent-banner.js +171 -0
- package/dist/react/consent-banner.js.map +1 -0
- package/dist/react/gtag-consent-bootstrap.d.ts +17 -0
- package/dist/react/gtag-consent-bootstrap.d.ts.map +1 -0
- package/dist/react/gtag-consent-bootstrap.js +22 -0
- package/dist/react/gtag-consent-bootstrap.js.map +1 -0
- package/dist/react/use-consent.d.ts +42 -0
- package/dist/react/use-consent.d.ts.map +1 -0
- package/dist/react/use-consent.js +60 -0
- package/dist/react/use-consent.js.map +1 -0
- package/dist/react/use-google-consent-sync.d.ts +20 -0
- package/dist/react/use-google-consent-sync.d.ts.map +1 -0
- package/dist/react/use-google-consent-sync.js +22 -0
- package/dist/react/use-google-consent-sync.js.map +1 -0
- package/dist/react/{use-initial-consent.d.mts → use-initial-consent.d.ts} +3 -6
- package/dist/react/use-initial-consent.d.ts.map +1 -0
- package/dist/react/use-initial-consent.js +18 -0
- package/dist/react/use-initial-consent.js.map +1 -0
- package/dist/server/anonymous-id-cookie.d.ts +67 -0
- package/dist/server/anonymous-id-cookie.d.ts.map +1 -0
- package/dist/server/anonymous-id-cookie.js +71 -0
- package/dist/server/anonymous-id-cookie.js.map +1 -0
- package/dist/server/consent-receipt-store.d.ts +56 -0
- package/dist/server/consent-receipt-store.d.ts.map +1 -0
- package/dist/server/consent-receipt-store.js +44 -0
- package/dist/server/consent-receipt-store.js.map +1 -0
- package/dist/server/consent-receipt.d.ts +41 -0
- package/dist/server/consent-receipt.d.ts.map +1 -0
- package/dist/server/consent-receipt.js +60 -0
- package/dist/server/consent-receipt.js.map +1 -0
- package/dist/server/initial-consent.d.ts +26 -0
- package/dist/server/initial-consent.d.ts.map +1 -0
- package/dist/server/initial-consent.js +31 -0
- package/dist/server/initial-consent.js.map +1 -0
- package/dist/server/measurement-protocol.d.ts +69 -0
- package/dist/server/measurement-protocol.d.ts.map +1 -0
- package/dist/server/measurement-protocol.js +61 -0
- package/dist/server/measurement-protocol.js.map +1 -0
- package/dist/server/{region.d.mts → region.d.ts} +5 -15
- package/dist/server/region.d.ts.map +1 -0
- package/dist/server/region.js +69 -0
- package/dist/server/region.js.map +1 -0
- package/dist/server/user-deletion.d.ts +64 -0
- package/dist/server/user-deletion.d.ts.map +1 -0
- package/dist/server/user-deletion.js +54 -0
- package/dist/server/user-deletion.js.map +1 -0
- package/dist/tooling/import-protection.d.ts +19 -0
- package/dist/tooling/import-protection.d.ts.map +1 -0
- package/dist/tooling/import-protection.js +23 -0
- package/dist/tooling/import-protection.js.map +1 -0
- package/package.json +238 -59
- package/src/adapters/tanstack-start.ts +135 -0
- package/src/client/ad-framework-consent.ts +86 -0
- package/src/client/cookie-anonymous-id.ts +19 -0
- package/src/client/create-client-tracker.ts +81 -10
- package/src/client/server-persisted-anonymous-id.ts +4 -1
- package/src/core/consent-receipt.ts +115 -0
- package/src/core/consent.ts +2 -2
- package/src/core/destination.ts +7 -0
- package/src/core/event-catalog.ts +5 -4
- package/src/core/tracked-event.ts +5 -20
- package/src/destinations/ad-consent.ts +29 -0
- package/src/destinations/meta.ts +96 -0
- package/src/destinations/microsoft-uet.ts +86 -0
- package/src/destinations/tiktok.ts +85 -0
- package/src/index.ts +138 -19
- package/src/server/anonymous-id-cookie.ts +49 -22
- package/src/server/consent-receipt-store.ts +79 -0
- package/src/server/consent-receipt.ts +89 -0
- package/src/server/initial-consent.ts +0 -2
- package/src/server/measurement-protocol.ts +114 -0
- package/src/server/region.ts +0 -10
- package/src/server/user-deletion.ts +93 -0
- package/src/tooling/import-protection.ts +22 -0
- package/dist/client/browser-cookie.mjs +0 -15
- package/dist/client/consent-runtime.d.mts +0 -56
- package/dist/client/consent-runtime.mjs +0 -35
- package/dist/client/consent-storage.mjs +0 -82
- package/dist/client/consent-withdrawal.d.mts +0 -21
- package/dist/client/consent-withdrawal.mjs +0 -17
- package/dist/client/cookie-anonymous-id.d.mts +0 -37
- package/dist/client/cookie-anonymous-id.mjs +0 -46
- package/dist/client/create-client-tracker.d.mts +0 -32
- package/dist/client/create-client-tracker.mjs +0 -40
- package/dist/client/gpc.mjs +0 -14
- package/dist/client/index.d.mts +0 -10
- package/dist/client/index.mjs +0 -10
- package/dist/client/initial-consent-store.d.mts +0 -66
- package/dist/client/initial-consent-store.mjs +0 -119
- package/dist/client/is-analytics-allowed.d.mts +0 -29
- package/dist/client/is-analytics-allowed.mjs +0 -23
- package/dist/client/server-persisted-anonymous-id.d.mts +0 -33
- package/dist/client/server-persisted-anonymous-id.mjs +0 -50
- package/dist/core/consent-config.d.mts +0 -27
- package/dist/core/consent-config.mjs +0 -11
- package/dist/core/consent.mjs +0 -152
- package/dist/core/cookie.mjs +0 -23
- package/dist/core/destination.d.mts +0 -25
- package/dist/core/destination.mjs +0 -1
- package/dist/core/event-catalog.d.mts +0 -39
- package/dist/core/event-catalog.mjs +0 -30
- package/dist/core/event-id.mjs +0 -11
- package/dist/core/index.d.mts +0 -8
- package/dist/core/index.mjs +0 -6
- package/dist/core/tracked-event.d.mts +0 -30
- package/dist/core/tracked-event.mjs +0 -1
- package/dist/destinations/google-analytics.d.mts +0 -150
- package/dist/destinations/google-analytics.mjs +0 -130
- package/dist/destinations/google-consent.d.mts +0 -64
- package/dist/destinations/google-consent.mjs +0 -102
- package/dist/destinations/index.d.mts +0 -2
- package/dist/destinations/index.mjs +0 -2
- package/dist/destinations/shared.d.mts +0 -20
- package/dist/destinations/shared.mjs +0 -13
- package/dist/destinations/vercel-analytics.d.mts +0 -28
- package/dist/destinations/vercel-analytics.mjs +0 -23
- package/dist/import-protection.d.mts +0 -19
- package/dist/import-protection.mjs +0 -23
- package/dist/index.d.mts +0 -8
- package/dist/index.mjs +0 -6
- package/dist/react/consent-banner.d.mts +0 -180
- package/dist/react/consent-banner.mjs +0 -214
- package/dist/react/gtag-consent-bootstrap.d.mts +0 -27
- package/dist/react/gtag-consent-bootstrap.mjs +0 -29
- package/dist/react/index.d.mts +0 -6
- package/dist/react/index.mjs +0 -6
- package/dist/react/use-consent.d.mts +0 -45
- package/dist/react/use-consent.mjs +0 -71
- package/dist/react/use-google-consent-sync.d.mts +0 -23
- package/dist/react/use-google-consent-sync.mjs +0 -24
- package/dist/react/use-initial-consent.mjs +0 -19
- package/dist/server/anonymous-id-cookie.d.mts +0 -46
- package/dist/server/anonymous-id-cookie.mjs +0 -51
- package/dist/server/index.d.mts +0 -5
- package/dist/server/index.mjs +0 -4
- package/dist/server/initial-consent.d.mts +0 -29
- package/dist/server/initial-consent.mjs +0 -31
- package/dist/server/region.mjs +0 -77
- package/dist/tanstack-start/index.d.mts +0 -58
- package/dist/tanstack-start/index.mjs +0 -45
- package/src/client/index.ts +0 -28
- package/src/core/index.ts +0 -40
- package/src/destinations/index.ts +0 -19
- package/src/import-protection.ts +0 -20
- package/src/react/index.ts +0 -37
- package/src/server/index.ts +0 -16
- package/src/tanstack-start/index.ts +0 -83
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @codefast/tracking
|
|
2
2
|
|
|
3
|
+
## 1.0.0-canary.7
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#605](https://github.com/codefastlabs/codefast/pull/605) [`cb46bdd`](https://github.com/codefastlabs/codefast/commit/cb46bdd64902230839aef738477a720f98a6479e) Thanks [@thevuong](https://github.com/thevuong)! - Adds the shared ad-destination frame for consuming one `{ ads, analytics }` decision across ad platforms (spec-destinations §5): `toAdConsentState(decision)` normalizes it to the two independent levers — `analytics` drives whether events transmit, `ads` drives Limited Data Use — so per-vendor mappings cannot drift. Ships a reference Meta destination (`createMetaDestination`, `toMetaDataProcessingOptions`) that maps each event and the live `ads` decision to Meta's `dataProcessingOptions` (geolocated LDU when `ads` is denied) and hands it to an injected `transport`. Consent-restriction mapping only — the Pixel/CAPI transport and credentials are the integrator's to supply; an ad sink is never `exempt`.
|
|
8
|
+
|
|
9
|
+
- [#612](https://github.com/codefastlabs/codefast/pull/612) [`1337fc3`](https://github.com/codefastlabs/codefast/commit/1337fc33929c9508936f0ac5807c215d0a2371d7) Thanks [@thevuong](https://github.com/thevuong)! - Adds the TCF/GPP interop reconciler (spec-ad-consent-frameworks): the system **reads** an external CMP and reconciles it with the native `{ ads, analytics }` decision — it never becomes a CMP or mints TC/GPP strings. `reconcileAdFrameworkConsent({ native, cmp, hasGlobalPrivacyControlSignal })` applies the §3 precedence (a governing CMP overrides its categories; fail-closed to denied while the CMP is loading; a missing or out-of-scope CMP leaves native standing; GPC only tightens `ads`), covering conformance vectors V1–V6. `hasTcfApi`/`hasGppApi` detect the `__tcfapi`/`__gpp` read APIs without invoking them. TCF purpose ids and the Google vendor id are deliberately **not** hard-coded — that mapping is ad-ops policy, so the caller derives the `CmpConsentSignal` it passes in.
|
|
10
|
+
|
|
11
|
+
- [#615](https://github.com/codefastlabs/codefast/pull/615) [`2bcd31f`](https://github.com/codefastlabs/codefast/commit/2bcd31fe99933d6e4fcc164069628555eef6e11c) Thanks [@thevuong](https://github.com/thevuong)! - Let `codefast mirror` generate `package.json#exports` from `dist/`, the same as every other library package (di, theme), instead of hand-curating them under mirror's preserve mode. The per-module build output is unchanged, so mirror emits a subpath for each built module, and the root becomes the client entry.
|
|
12
|
+
|
|
13
|
+
Breaking:
|
|
14
|
+
|
|
15
|
+
- The root `@codefast/tracking` is now the **client entry** — it re-exports the isomorphic core plus the whole browser surface (`createClientTracker`, `createConsentRuntime`, the React bindings, the gtag + ad-network destinations). Server code must import the core it needs from `@codefast/tracking/core/*`, not from the root.
|
|
16
|
+
- The `./client`, `./server`, `./core`, `./react`, and `./destinations` group barrels are gone. Use the client root for browser code, or a module's own subpath for granular/server imports (`@codefast/tracking/server/initial-consent`, `@codefast/tracking/client/gpc`, …).
|
|
17
|
+
- The TanStack Start adapter is now `@codefast/tracking/adapters/tanstack-start` (was `/tanstack-start`); the import-protection deny-list is `@codefast/tracking/tooling/import-protection` (was `/import-protection`). `SERVER_ONLY_SUBPATHS` now denies `server/**` and `adapters/**`.
|
|
18
|
+
|
|
19
|
+
- [#617](https://github.com/codefastlabs/codefast/pull/617) [`b979371`](https://github.com/codefastlabs/codefast/commit/b979371fb4b437be04a59cb5985de03ebe810e0d) Thanks [@thevuong](https://github.com/thevuong)! - Harden the package from a full audit — correctness, coverage, and a leaner public surface.
|
|
20
|
+
|
|
21
|
+
- **`isConsentReceiptInput` now validates `method` and `subjectIdType` against their enums**, not just `typeof === "string"` — the untrusted-body guard no longer narrows a bogus value to a closed union member.
|
|
22
|
+
- **`CookieAnonymousId` gains `current()`** — a non-minting read of the existing id (`undefined` when none) so a consent receipt stamps the id the visitor already carries instead of a throwaway that never correlates for erasure.
|
|
23
|
+
- **`coarsenIp` rejects out-of-range IPv4 octets** (`"999.…"`) rather than storing a malformed coarse value.
|
|
24
|
+
- **Microsoft UET consent routes through the shared `toAdConsentState` ad lever**, so its `ad_storage` mapping can't drift from Meta/TikTok.
|
|
25
|
+
- **Dropped unused foreign type re-exports** so each type has one home: `InitialConsent` no longer re-exported from `adapters/tanstack-start` or `server/initial-consent` (import it from `core/consent`), and the `AnonymousIdResponseCookieOptions` alias is gone — `setAnonymousIdResponseCookie` takes `AnonymousIdCookieOptions` from `server/anonymous-id-cookie` directly.
|
|
26
|
+
- **Collapsed the `TrackedEvent` envelope to a single interface** — the unused `TrackedEventBase` and `TrackEvent` names are gone (`TrackedEvent` keeps the `type: "track"` discriminant for a future additive union).
|
|
27
|
+
|
|
28
|
+
Also adds test coverage for the previously-untested `recordConsentReceiptFromRequest` adapter path (no-store header, body-IP rejection, coarsened IP, PII-free ack).
|
|
29
|
+
|
|
30
|
+
- [#617](https://github.com/codefastlabs/codefast/pull/617) [`b979371`](https://github.com/codefastlabs/codefast/commit/b979371fb4b437be04a59cb5985de03ebe810e0d) Thanks [@thevuong](https://github.com/thevuong)! - Remove two leftover indirection layers in the server lane that no call site used.
|
|
31
|
+
|
|
32
|
+
Breaking:
|
|
33
|
+
|
|
34
|
+
- The `@codefast/tracking/adapters/request-context` subpath is gone. Its `RequestContext` seam (a `getHeader`/`setHeader` interface) plus the parallel `*FromContext`/`*OnContext` helpers existed only to back a hypothetical future `./next`/`./remix` adapter, but there was exactly one adapter and it duplicated every signature and doc comment. `@codefast/tracking/adapters/tanstack-start` now calls `getRequestHeader`/`setResponseHeader` directly; its public surface (`resolveInitialConsentFromRequest`, `setAnonymousIdResponseCookie`, `clearAnonymousIdResponseCookie`, `recordConsentReceiptFromRequest`) is unchanged.
|
|
35
|
+
- `resolveRegion(headers)` is removed from `@codefast/tracking/server/region`. It was a pre-fail-closed leftover with no production call site, and its missing-geo semantics (unknown region → opt-out) contradicted the fail-closed invariant the server-first path relies on. Use `resolveRegionFromCountryCode` (what the production path already uses via `resolveInitialConsent`), or `resolveInitialConsentFromRequest` for the full per-request resolution.
|
|
36
|
+
|
|
37
|
+
- [#606](https://github.com/codefastlabs/codefast/pull/606) [`5a4ff42`](https://github.com/codefastlabs/codefast/commit/5a4ff423b89a5e249c3cb48d62c86c27fc2b2293) Thanks [@thevuong](https://github.com/thevuong)! - Adds `createDurableReceiptStore({ backend })` — a durable `ReceiptStore` over an injected `ReceiptStoreBackend` (a minimal id-keyed `get`/`put` primitive). The package supplies the append-only contract and adaptation; the deployment supplies the backend client (Vercel KV, Postgres, an append-only log), so no database dependency is baked in. `put` MUST be idempotent-by-id so the append-only guarantee holds atomically under retries/concurrency (e.g. KV set-if-absent, Postgres `INSERT … ON CONFLICT DO NOTHING`) — the frame delegates rather than doing a racy get-then-put. Pair it with a real backend in production, where `createInMemoryReceiptStore` is not a lawful store on its own.
|
|
38
|
+
|
|
39
|
+
- [#604](https://github.com/codefastlabs/codefast/pull/604) [`7bb4be7`](https://github.com/codefastlabs/codefast/commit/7bb4be7edeb015542fb1b4852026db98db6a735b) Thanks [@thevuong](https://github.com/thevuong)! - `createClientTracker` now accepts an optional `isExemptionAllowed` gate, consulted before an `exempt` destination receives an event while the consent gate is closed. ePrivacy audience-measurement exemption is jurisdiction-dependent (spec-destinations §2), so it must be gateable per region rather than assumed global — returning `false` withholds even exempt sinks where exemption is not defensible. Omit it to keep the prior behavior (exempt everywhere). The gate is irrelevant once consent is granted, since every destination then receives the full envelope.
|
|
40
|
+
|
|
41
|
+
- [#608](https://github.com/codefastlabs/codefast/pull/608) [`6cdd930`](https://github.com/codefastlabs/codefast/commit/6cdd930ede8ad6b2d25c23dd3f9fb14a1d970e11) Thanks [@thevuong](https://github.com/thevuong)! - Adds GA4 DSR delegation (spec-data-subject-rights §3): the system delegates per-visitor deletion to the platform rather than building a deletion store. `buildGa4UserDeletionRequest({ propertyId, clientId })` returns the network-free request shape and `submitGa4UserDeletion({ …, accessToken, transport? })` POSTs it — targeting the current **Analytics Admin API** `properties.submitUserDeletion` (the legacy v3 `userDeletionRequests:upsert` was sunset with Universal Analytics), keyed by a flat `clientId`. Authorization is the caller's: pass a bearer token for the `analytics.edit` scope; no OAuth or HTTP client is baked in. Server-only (`@codefast/tracking/server`).
|
|
42
|
+
|
|
43
|
+
- [#617](https://github.com/codefastlabs/codefast/pull/617) [`b979371`](https://github.com/codefastlabs/codefast/commit/b979371fb4b437be04a59cb5985de03ebe810e0d) Thanks [@thevuong](https://github.com/thevuong)! - Adopt TanStack Start's first-class server helpers in the adapter instead of hand-rolling over raw request/response headers.
|
|
44
|
+
|
|
45
|
+
- The anonymous-id cookie is now written with `setCookie`/`deleteCookie` (from `@tanstack/react-start/server`) rather than `setResponseHeader("set-cookie", …)`. The raw header call **replaces** any existing `Set-Cookie` on the response — it would clobber a session or framework cookie set on the same response — whereas `setCookie` appends. No behavior change to the emitted cookie (still `Path=/; Max-Age=1y; SameSite=Lax; Secure`, not `HttpOnly`).
|
|
46
|
+
- The connection IP for consent receipts is now read with `getRequestIP({ xForwardedFor: true })` — the maintained, platform-aware path — instead of hand-parsing `x-forwarded-for`/`x-real-ip`.
|
|
47
|
+
|
|
48
|
+
Breaking (`@codefast/tracking/server/anonymous-id-cookie`): the string builders `buildAnonymousIdSetCookie`/`buildClearAnonymousIdSetCookie` are replaced by `resolveAnonymousIdCookie`/`resolveClearAnonymousIdCookie`, which return the validated name/value plus cookie attributes for a framework `setCookie`/`deleteCookie` call. `isValidAnonymousId` is unchanged; the cookie-name guard is now the exported `assertValidAnonymousIdCookieName`.
|
|
49
|
+
|
|
50
|
+
- [#607](https://github.com/codefastlabs/codefast/pull/607) [`749dd16`](https://github.com/codefastlabs/codefast/commit/749dd166b4e6d4ddf49e0589831b69a0e9458478) Thanks [@thevuong](https://github.com/thevuong)! - Adds server-side GA4 Measurement Protocol primitives for forwarding a **server-owned** event (re-added now that a consumer tracks one — a server-recorded consent decision): `sendMeasurementProtocolEvents` POSTs `{ client_id, events, consent? }` to the credentialed `/mp/collect` endpoint through an injected `transport` (default `fetch`), so no HTTP client or credentials are baked in; `extractGaClientId` derives the GA4 `client_id` from a `_ga` cookie; `toMeasurementProtocolConsent` maps the package `ConsentDecision` to the MP `consent` signals. Server-only (`@codefast/tracking/server`). The caller owns the credentials and the consent gate.
|
|
51
|
+
|
|
52
|
+
- [#602](https://github.com/codefastlabs/codefast/pull/602) [`5ca04e2`](https://github.com/codefastlabs/codefast/commit/5ca04e2f7fe970397c9b90be727fc81d89a737a2) Thanks [@thevuong](https://github.com/thevuong)! - `createClientTracker` now accepts an optional `onDeliveryError` hook, called once per failed delivery (a destination throwing synchronously or rejecting) with `{ destination, error, event }`. The tracker still swallows the failure so tracking never breaks the interaction — the hook is a metering seam for wiring delivery failures to a monitor in production. The hook is itself guarded, so a throwing observer can't break the interaction either. Exposes the `DeliveryErrorContext` type from `@codefast/tracking/client`.
|
|
53
|
+
|
|
54
|
+
- [#610](https://github.com/codefastlabs/codefast/pull/610) [`fdb8d7c`](https://github.com/codefastlabs/codefast/commit/fdb8d7c928847a957ecb1d571e82b1948fac5a2e) Thanks [@thevuong](https://github.com/thevuong)! - Adds the per-destination erasure capability for DSR withdrawal (spec-data-subject-rights §3, DSR-V2/V4): `Destination` gains an optional `onErasure(id)` hook, and `createClientTracker` returns an `erase(id)` method that invokes each destination's `onErasure` once on withdrawal, swallowing failures so a destination can never break the flow. The reference `createMetaDestination` implements `onErasure` as cookie-clear (via an injected `clearCookies` seam) plus stop-send — Meta exposes no per-visitor deletion API, so the binding never fabricates one. Destinations with nothing to erase omit the hook.
|
|
55
|
+
|
|
56
|
+
- [#611](https://github.com/codefastlabs/codefast/pull/611) [`a5527c3`](https://github.com/codefastlabs/codefast/commit/a5527c3e7ddaf2d0ca1d11026be2cb2bd5fd476c) Thanks [@thevuong](https://github.com/thevuong)! - Extends the ad-destination frame with two more reference vendors (spec-destinations §5), consuming the same `{ ads, analytics }` decision: `createMicrosoftUetDestination` / `toMicrosoftUetConsent` map `ads` to UET's only enforced signal, `ad_storage` (UET has no `analytics_storage`); `createTiktokDestination` / `toTiktokConsent` map `ads` to TikTok's single `limited_data_use` boolean (not Meta's `dataProcessingOptions` structure). Both take an injected `transport` (no pixel id, tag id, or network client baked in) and implement `onErasure` as cookie-clear + stop-send, since neither exposes a per-visitor deletion API. `consentRequirement` stays `"required"`.
|
|
57
|
+
|
|
3
58
|
## 1.0.0-canary.6
|
|
4
59
|
|
|
5
60
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Consent-gated, type-safe event tracking for TanStack Start apps.
|
|
4
4
|
|
|
5
|
+
[](https://www.npmjs.com/package/@codefast/tracking)
|
|
6
|
+
[](https://github.com/codefastlabs/codefast/blob/main/LICENSE)
|
|
7
|
+
|
|
5
8
|
- **One catalog, typed end to end** — apps define their events over any
|
|
6
9
|
[Standard Schema](https://standardschema.dev) library (zod, `zod/mini`, valibot, ...);
|
|
7
10
|
`track()` validates properties at the call site and at runtime, and the client bundle
|
|
@@ -20,7 +23,17 @@ that shipped here before (offline queue, beacon relay, server-side tracker, GTM,
|
|
|
20
23
|
Segment-style `identify`/`group`/`alias`/`page`) were removed because no consumer called
|
|
21
24
|
them — git history has them if a real need returns.
|
|
22
25
|
|
|
23
|
-
##
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @codefast/tracking
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Every peer is optional and only needed by the surface that uses it: `react`/`react-dom`
|
|
33
|
+
(>= 19) for `/react`, `@tanstack/react-start` (>= 1.168) for `/adapters/tanstack-start`, and
|
|
34
|
+
`@vercel/analytics` for the Vercel destination.
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
24
37
|
|
|
25
38
|
```ts
|
|
26
39
|
// consent.ts — the one consent contract every surface shares
|
|
@@ -35,7 +48,7 @@ export const consentConfig = defineConsentConfig({
|
|
|
35
48
|
|
|
36
49
|
```ts
|
|
37
50
|
// consent-runtime.ts — live client instances derived from the config
|
|
38
|
-
import { createConsentRuntime } from "@codefast/tracking/client";
|
|
51
|
+
import { createConsentRuntime } from "@codefast/tracking/client/consent-runtime";
|
|
39
52
|
|
|
40
53
|
import { consentConfig } from "./consent";
|
|
41
54
|
import { resolveVisitorConsent } from "./resolve-visitor-consent"; // server fn, see below
|
|
@@ -50,8 +63,8 @@ export const consentRuntime = createConsentRuntime({
|
|
|
50
63
|
```ts
|
|
51
64
|
// tracking.ts — catalog + tracker
|
|
52
65
|
import { defineEventCatalog } from "@codefast/tracking";
|
|
53
|
-
import { createClientTracker } from "@codefast/tracking/client";
|
|
54
|
-
import { createGoogleAnalyticsDestination } from "@codefast/tracking/destinations";
|
|
66
|
+
import { createClientTracker } from "@codefast/tracking/client/create-client-tracker";
|
|
67
|
+
import { createGoogleAnalyticsDestination } from "@codefast/tracking/destinations/google-analytics";
|
|
55
68
|
import { createVercelAnalyticsDestination } from "@codefast/tracking/destinations/vercel-analytics";
|
|
56
69
|
import * as z from "zod/mini";
|
|
57
70
|
|
|
@@ -78,11 +91,48 @@ tracker.track("copy_code", { name: "button" }); // typed + runtime-validated
|
|
|
78
91
|
Destinations own their transport (gtag.js and Vercel both batch in-page), so `track()`
|
|
79
92
|
is fire-and-forget — a failing destination can never break the interaction.
|
|
80
93
|
|
|
94
|
+
## Event catalog
|
|
95
|
+
|
|
96
|
+
The package ships no events and no schema library — every app builds its own catalog
|
|
97
|
+
with `defineEventCatalog` over whatever Standard Schema validator it already uses.
|
|
98
|
+
`track()` infers both the event name and its properties from the catalog, then validates
|
|
99
|
+
the properties at runtime; a mismatch throws at the call site. Async schemas are rejected
|
|
100
|
+
by design — tracking sits on synchronous call paths.
|
|
101
|
+
|
|
102
|
+
## Subpaths
|
|
103
|
+
|
|
104
|
+
The root `@codefast/tracking` is the **client entry**: it re-exports the isomorphic core
|
|
105
|
+
(catalog types, `Destination`, consent model + config) plus the whole browser-side surface
|
|
106
|
+
(tracker, consent runtime, React bindings, and the client destinations). Server-only lanes
|
|
107
|
+
are their own subpaths and are never re-exported from the root:
|
|
108
|
+
|
|
109
|
+
- `@codefast/tracking` — client entry: core + `createClientTracker`, `createConsentRuntime`,
|
|
110
|
+
the `useConsent`/`ConsentBanner`/`GtagConsentBootstrap` React bindings, the gtag +
|
|
111
|
+
ad-network destinations.
|
|
112
|
+
- `@codefast/tracking/destinations/vercel-analytics` — its own subpath so its
|
|
113
|
+
`@vercel/analytics` peer is only pulled in when used.
|
|
114
|
+
- `@codefast/tracking/server/*` — request-scoped, **server-only**: `server/initial-consent`,
|
|
115
|
+
`server/consent-receipt-store`, `server/measurement-protocol`, … (server code imports the
|
|
116
|
+
core it needs from `@codefast/tracking/core/*`, never from the client root).
|
|
117
|
+
- `@codefast/tracking/adapters/tanstack-start` — request/response glue over Start's server
|
|
118
|
+
context, **server-only**.
|
|
119
|
+
- `@codefast/tracking/tooling/import-protection` — `SERVER_ONLY_SUBPATHS` deny-list for
|
|
120
|
+
client bundles.
|
|
121
|
+
- `@codefast/tracking/css/consent.css` — optional plain-CSS theme for the consent banner.
|
|
122
|
+
|
|
123
|
+
Every built module is also its own subpath (e.g. `@codefast/tracking/client/gpc`) for
|
|
124
|
+
granular imports. Server-only lanes (`server/*`, `adapters/*`) must never enter a client
|
|
125
|
+
bundle — feed `SERVER_ONLY_SUBPATHS` to the framework's import-protection (see below). There
|
|
126
|
+
is deliberately no server-side tracker: destinations batch in-page, and the server half of
|
|
127
|
+
the package is consent resolution plus cookie persistence.
|
|
128
|
+
|
|
81
129
|
## Consent (region-based, per-category)
|
|
82
130
|
|
|
83
131
|
`ConsentDecision` is per-purpose (`{ ads, analytics }`), mirroring Google Consent Mode
|
|
84
|
-
v2. Region resolves the mode: GDPR
|
|
85
|
-
|
|
132
|
+
v2. Region resolves the mode: GDPR (EU, plus UK/EEA-EFTA equivalents) and Vietnam's PDPL
|
|
133
|
+
get **opt-in**; the US (CCPA/CPRA) and unrecognized regions get **opt-out**, with GPC
|
|
134
|
+
honored as an ads-only opt-out. Stored records are policy-versioned and shape-checked —
|
|
135
|
+
a malformed or legacy-shaped record re-prompts instead of silently deciding.
|
|
86
136
|
|
|
87
137
|
- `useConsent({ config, mode, storage })` — `useSyncExternalStore` bridge over the stored
|
|
88
138
|
decision; cross-tab saves sync through the `storage` event.
|
|
@@ -102,28 +152,28 @@ ISR/CDN-cached HTML is shared across visitors, so no render may read geo. Bake
|
|
|
102
152
|
then resolve the region-correct default per visitor after hydration:
|
|
103
153
|
|
|
104
154
|
1. **Server function** — `resolveInitialConsentFromRequest({ requestedCategories })`
|
|
105
|
-
(`@codefast/tracking/tanstack-start`) reads the geo header and `sec-gpc`, stamps
|
|
155
|
+
(`@codefast/tracking/adapters/tanstack-start`) reads the geo header and `sec-gpc`, stamps
|
|
106
156
|
`cache-control: private, no-store`, and fails closed when geo is missing.
|
|
107
157
|
2. **Client** — `createConsentRuntime` owns the rest: strictest default until the server
|
|
108
158
|
answers, single-flight resolve, per-session cache, fail-closed-but-retryable errors.
|
|
109
159
|
Kick `runtime.ensureInitialConsentResolved()` at router creation (window-guarded) so
|
|
110
160
|
the round trip overlaps hydration; read it reactively via
|
|
111
|
-
`useInitialConsent(runtime.initialConsentStore)` (`@codefast/tracking/react`).
|
|
161
|
+
`useInitialConsent(runtime.initialConsentStore)` (`@codefast/tracking/react/use-initial-consent`).
|
|
112
162
|
|
|
113
163
|
## Durable anonymous id ("client mints, server persists")
|
|
114
164
|
|
|
115
|
-
`createServerPersistedAnonymousId` (`@codefast/tracking/client`) mints a UUID cookie
|
|
165
|
+
`createServerPersistedAnonymousId` (`@codefast/tracking/client/server-persisted-anonymous-id`) mints a UUID cookie
|
|
116
166
|
lazily — only once an event is actually allowed to send — and asks the server to re-issue
|
|
117
167
|
it via `Set-Cookie`, which escapes Safari ITP's 7-day cap on script-written cookies. The
|
|
118
168
|
server half is one line per endpoint with `setAnonymousIdResponseCookie` /
|
|
119
|
-
`clearAnonymousIdResponseCookie` (`@codefast/tracking/tanstack-start`); both validate the
|
|
169
|
+
`clearAnonymousIdResponseCookie` (`@codefast/tracking/adapters/tanstack-start`); both validate the
|
|
120
170
|
id is exactly UUID-shaped, so a public endpoint can never echo attacker input into a
|
|
121
171
|
response header.
|
|
122
172
|
|
|
123
173
|
## Google tag (advanced Consent Mode)
|
|
124
174
|
|
|
125
175
|
`<GtagConsentBootstrap config={consentConfig} defaultConsent={...} gaMeasurementId="G-…" />`
|
|
126
|
-
(`@codefast/tracking/react`) renders the pre-hydration inline script: Consent Mode v2
|
|
176
|
+
(`@codefast/tracking/react/use-initial-consent`) renders the pre-hydration inline script: Consent Mode v2
|
|
127
177
|
`default` first (stored decision wins over the baked fallback), then gtag.js always loads
|
|
128
178
|
so cookieless pings and consent modeling can run even when storage is denied. Page views
|
|
129
179
|
are gtag's own job (`config` + Enhanced Measurement) — the destination only forwards
|
|
@@ -131,16 +181,16 @@ catalog events. Runtime changes go through `useGoogleConsentSync`/`updateGoogleC
|
|
|
131
181
|
|
|
132
182
|
## Keeping server-only subpaths out of client bundles
|
|
133
183
|
|
|
134
|
-
`./server` and `./tanstack-start` must never enter a client bundle. On TanStack Start,
|
|
184
|
+
`./server` and `./adapters/tanstack-start` must never enter a client bundle. On TanStack Start,
|
|
135
185
|
spread the package's own deny-list into the plugin's import-protection so it versions
|
|
136
186
|
with the package instead of going stale in your config:
|
|
137
187
|
|
|
138
188
|
```ts
|
|
139
|
-
import {
|
|
189
|
+
import { SERVER_ONLY_SUBPATHS } from "@codefast/tracking/tooling/import-protection";
|
|
140
190
|
|
|
141
191
|
tanstackStart({
|
|
142
192
|
importProtection: {
|
|
143
|
-
client: { specifiers: [...
|
|
193
|
+
client: { specifiers: [...SERVER_ONLY_SUBPATHS] },
|
|
144
194
|
},
|
|
145
195
|
});
|
|
146
196
|
```
|
|
@@ -150,6 +200,11 @@ a trace of the offending import chain.
|
|
|
150
200
|
|
|
151
201
|
## Reference consumer
|
|
152
202
|
|
|
153
|
-
`apps/ui` (`src/features/tracking/`)
|
|
154
|
-
ISR-deployed TanStack Start site — consent
|
|
155
|
-
gtag bootstrap, durable anonymous id, and
|
|
203
|
+
[`apps/ui` (`src/features/tracking/`)](https://github.com/codefastlabs/codefast/tree/main/apps/ui/src/features/tracking)
|
|
204
|
+
in this repo wires everything above on a real ISR-deployed TanStack Start site — consent
|
|
205
|
+
config + runtime, banner + persistent toggle, gtag bootstrap, durable anonymous id, and
|
|
206
|
+
the private server-function consent lane.
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
[MIT](https://github.com/codefastlabs/codefast/blob/main/LICENSE)
|
|
@@ -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"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/client/browser-cookie.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Shared `document.cookie` writer for the client-side cookie lanes (anonymous id, consent
|
|
4
3
|
* mirror): Secure on HTTPS so values never ride plain HTTP, SameSite=Lax, never HttpOnly —
|
|
@@ -6,6 +5,5 @@
|
|
|
6
5
|
*
|
|
7
6
|
* @since 1.0.0-canary.6
|
|
8
7
|
*/
|
|
9
|
-
declare function writeBrowserCookie(cookieName: string, value: string, maxAgeSeconds: number): void;
|
|
10
|
-
//#
|
|
11
|
-
export { writeBrowserCookie };
|
|
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"}
|