@codefast/tracking 0.5.0-canary.5 → 0.5.0-canary.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/CHANGELOG.md +467 -0
  2. package/README.md +176 -126
  3. package/dist/adapters/tanstack-start.d.ts +80 -0
  4. package/dist/adapters/tanstack-start.d.ts.map +1 -0
  5. package/dist/adapters/tanstack-start.js +74 -0
  6. package/dist/adapters/tanstack-start.js.map +1 -0
  7. package/dist/client/ad-framework-consent.d.ts +62 -0
  8. package/dist/client/ad-framework-consent.d.ts.map +1 -0
  9. package/dist/client/ad-framework-consent.js +40 -0
  10. package/dist/client/ad-framework-consent.js.map +1 -0
  11. package/dist/client/browser-cookie.d.ts +9 -0
  12. package/dist/client/browser-cookie.d.ts.map +1 -0
  13. package/dist/client/browser-cookie.js +15 -0
  14. package/dist/client/browser-cookie.js.map +1 -0
  15. package/dist/client/consent-runtime.d.ts +53 -0
  16. package/dist/client/consent-runtime.d.ts.map +1 -0
  17. package/dist/client/consent-runtime.js +33 -0
  18. package/dist/client/consent-runtime.js.map +1 -0
  19. package/dist/client/{consent-storage.d.mts → consent-storage.d.ts} +8 -6
  20. package/dist/client/consent-storage.d.ts.map +1 -0
  21. package/dist/client/consent-storage.js +109 -0
  22. package/dist/client/consent-storage.js.map +1 -0
  23. package/dist/client/consent-withdrawal.d.ts +18 -0
  24. package/dist/client/consent-withdrawal.d.ts.map +1 -0
  25. package/dist/client/consent-withdrawal.js +17 -0
  26. package/dist/client/consent-withdrawal.js.map +1 -0
  27. package/dist/client/cookie-anonymous-id.d.ts +41 -0
  28. package/dist/client/cookie-anonymous-id.d.ts.map +1 -0
  29. package/dist/client/cookie-anonymous-id.js +65 -0
  30. package/dist/client/cookie-anonymous-id.js.map +1 -0
  31. package/dist/client/create-client-tracker.d.ts +60 -0
  32. package/dist/client/create-client-tracker.d.ts.map +1 -0
  33. package/dist/client/create-client-tracker.js +91 -0
  34. package/dist/client/create-client-tracker.js.map +1 -0
  35. package/dist/client/gpc.d.ts +10 -0
  36. package/dist/client/gpc.d.ts.map +1 -0
  37. package/dist/client/gpc.js +12 -0
  38. package/dist/client/gpc.js.map +1 -0
  39. package/dist/client/initial-consent-store.d.ts +63 -0
  40. package/dist/client/initial-consent-store.d.ts.map +1 -0
  41. package/dist/client/initial-consent-store.js +138 -0
  42. package/dist/client/initial-consent-store.js.map +1 -0
  43. package/dist/client/is-analytics-allowed.d.ts +26 -0
  44. package/dist/client/is-analytics-allowed.d.ts.map +1 -0
  45. package/dist/client/is-analytics-allowed.js +22 -0
  46. package/dist/client/is-analytics-allowed.js.map +1 -0
  47. package/dist/client/server-persisted-anonymous-id.d.ts +30 -0
  48. package/dist/client/server-persisted-anonymous-id.d.ts.map +1 -0
  49. package/dist/client/server-persisted-anonymous-id.js +72 -0
  50. package/dist/client/server-persisted-anonymous-id.js.map +1 -0
  51. package/dist/core/consent-config.d.ts +24 -0
  52. package/dist/core/consent-config.d.ts.map +1 -0
  53. package/dist/core/consent-config.js +9 -0
  54. package/dist/core/consent-config.js.map +1 -0
  55. package/dist/core/consent-receipt.d.ts +71 -0
  56. package/dist/core/consent-receipt.d.ts.map +1 -0
  57. package/dist/core/consent-receipt.js +39 -0
  58. package/dist/core/consent-receipt.js.map +1 -0
  59. package/dist/core/consent.d.ts +182 -0
  60. package/dist/core/consent.d.ts.map +1 -0
  61. package/dist/core/consent.js +159 -0
  62. package/dist/core/consent.js.map +1 -0
  63. package/dist/core/cookie.d.ts +15 -0
  64. package/dist/core/cookie.d.ts.map +1 -0
  65. package/dist/core/cookie.js +26 -0
  66. package/dist/core/cookie.js.map +1 -0
  67. package/dist/core/destination.d.ts +29 -0
  68. package/dist/core/destination.d.ts.map +1 -0
  69. package/dist/core/destination.js +2 -0
  70. package/dist/core/destination.js.map +1 -0
  71. package/dist/core/event-catalog.d.ts +35 -0
  72. package/dist/core/event-catalog.d.ts.map +1 -0
  73. package/dist/core/event-catalog.js +30 -0
  74. package/dist/core/event-catalog.js.map +1 -0
  75. package/dist/core/event-id.d.ts +7 -0
  76. package/dist/core/event-id.d.ts.map +1 -0
  77. package/dist/core/event-id.js +9 -0
  78. package/dist/core/event-id.js.map +1 -0
  79. package/dist/core/tracked-event.d.ts +15 -0
  80. package/dist/core/tracked-event.d.ts.map +1 -0
  81. package/dist/core/tracked-event.js +2 -0
  82. package/dist/core/tracked-event.js.map +1 -0
  83. package/dist/destinations/ad-consent.d.ts +23 -0
  84. package/dist/destinations/ad-consent.d.ts.map +1 -0
  85. package/dist/destinations/ad-consent.js +12 -0
  86. package/dist/destinations/ad-consent.js.map +1 -0
  87. package/dist/destinations/google-analytics.d.ts +148 -0
  88. package/dist/destinations/google-analytics.d.ts.map +1 -0
  89. package/dist/destinations/google-analytics.js +156 -0
  90. package/dist/destinations/google-analytics.js.map +1 -0
  91. package/dist/destinations/google-consent.d.ts +62 -0
  92. package/dist/destinations/google-consent.d.ts.map +1 -0
  93. package/dist/destinations/google-consent.js +109 -0
  94. package/dist/destinations/google-consent.js.map +1 -0
  95. package/dist/destinations/meta.d.ts +63 -0
  96. package/dist/destinations/meta.d.ts.map +1 -0
  97. package/dist/destinations/meta.js +44 -0
  98. package/dist/destinations/meta.js.map +1 -0
  99. package/dist/destinations/microsoft-uet.d.ts +56 -0
  100. package/dist/destinations/microsoft-uet.d.ts.map +1 -0
  101. package/dist/destinations/microsoft-uet.js +41 -0
  102. package/dist/destinations/microsoft-uet.js.map +1 -0
  103. package/dist/destinations/shared.d.ts +18 -0
  104. package/dist/destinations/shared.d.ts.map +1 -0
  105. package/dist/destinations/shared.js +19 -0
  106. package/dist/destinations/shared.js.map +1 -0
  107. package/dist/destinations/tiktok.d.ts +55 -0
  108. package/dist/destinations/tiktok.d.ts.map +1 -0
  109. package/dist/destinations/tiktok.js +40 -0
  110. package/dist/destinations/tiktok.js.map +1 -0
  111. package/dist/destinations/vercel-analytics.d.ts +25 -0
  112. package/dist/destinations/vercel-analytics.d.ts.map +1 -0
  113. package/dist/destinations/vercel-analytics.js +23 -0
  114. package/dist/destinations/vercel-analytics.js.map +1 -0
  115. package/dist/index.d.ts +64 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +41 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/react/consent-banner.d.ts +155 -0
  120. package/dist/react/consent-banner.d.ts.map +1 -0
  121. package/dist/react/consent-banner.js +171 -0
  122. package/dist/react/consent-banner.js.map +1 -0
  123. package/dist/react/gtag-consent-bootstrap.d.ts +17 -0
  124. package/dist/react/gtag-consent-bootstrap.d.ts.map +1 -0
  125. package/dist/react/gtag-consent-bootstrap.js +22 -0
  126. package/dist/react/gtag-consent-bootstrap.js.map +1 -0
  127. package/dist/react/use-consent.d.ts +42 -0
  128. package/dist/react/use-consent.d.ts.map +1 -0
  129. package/dist/react/use-consent.js +60 -0
  130. package/dist/react/use-consent.js.map +1 -0
  131. package/dist/react/use-google-consent-sync.d.ts +20 -0
  132. package/dist/react/use-google-consent-sync.d.ts.map +1 -0
  133. package/dist/react/use-google-consent-sync.js +22 -0
  134. package/dist/react/use-google-consent-sync.js.map +1 -0
  135. package/dist/react/use-initial-consent.d.ts +11 -0
  136. package/dist/react/use-initial-consent.d.ts.map +1 -0
  137. package/dist/react/use-initial-consent.js +18 -0
  138. package/dist/react/use-initial-consent.js.map +1 -0
  139. package/dist/server/anonymous-id-cookie.d.ts +67 -0
  140. package/dist/server/anonymous-id-cookie.d.ts.map +1 -0
  141. package/dist/server/anonymous-id-cookie.js +71 -0
  142. package/dist/server/anonymous-id-cookie.js.map +1 -0
  143. package/dist/server/consent-receipt-store.d.ts +56 -0
  144. package/dist/server/consent-receipt-store.d.ts.map +1 -0
  145. package/dist/server/consent-receipt-store.js +44 -0
  146. package/dist/server/consent-receipt-store.js.map +1 -0
  147. package/dist/server/consent-receipt.d.ts +41 -0
  148. package/dist/server/consent-receipt.d.ts.map +1 -0
  149. package/dist/server/consent-receipt.js +60 -0
  150. package/dist/server/consent-receipt.js.map +1 -0
  151. package/dist/server/initial-consent.d.ts +26 -0
  152. package/dist/server/initial-consent.d.ts.map +1 -0
  153. package/dist/server/initial-consent.js +31 -0
  154. package/dist/server/initial-consent.js.map +1 -0
  155. package/dist/server/measurement-protocol.d.ts +69 -0
  156. package/dist/server/measurement-protocol.d.ts.map +1 -0
  157. package/dist/server/measurement-protocol.js +61 -0
  158. package/dist/server/measurement-protocol.js.map +1 -0
  159. package/dist/server/region.d.ts +27 -0
  160. package/dist/server/region.d.ts.map +1 -0
  161. package/dist/server/region.js +69 -0
  162. package/dist/server/region.js.map +1 -0
  163. package/dist/server/user-deletion.d.ts +64 -0
  164. package/dist/server/user-deletion.d.ts.map +1 -0
  165. package/dist/server/user-deletion.js +54 -0
  166. package/dist/server/user-deletion.js.map +1 -0
  167. package/dist/tooling/import-protection.d.ts +19 -0
  168. package/dist/tooling/import-protection.d.ts.map +1 -0
  169. package/dist/tooling/import-protection.js +23 -0
  170. package/dist/tooling/import-protection.js.map +1 -0
  171. package/package.json +201 -107
  172. package/src/adapters/tanstack-start.ts +135 -0
  173. package/src/client/ad-framework-consent.ts +86 -0
  174. package/src/client/browser-cookie.ts +16 -0
  175. package/src/client/consent-runtime.ts +80 -0
  176. package/src/client/consent-storage.ts +31 -1
  177. package/src/client/consent-withdrawal.ts +32 -0
  178. package/src/client/cookie-anonymous-id.ts +112 -0
  179. package/src/client/create-client-tracker.ts +128 -86
  180. package/src/client/gpc.ts +4 -2
  181. package/src/client/initial-consent-store.ts +218 -0
  182. package/src/client/is-analytics-allowed.ts +43 -0
  183. package/src/client/server-persisted-anonymous-id.ts +102 -0
  184. package/src/core/consent-config.ts +27 -0
  185. package/src/core/consent-receipt.ts +115 -0
  186. package/src/core/consent.ts +164 -10
  187. package/src/core/cookie.ts +29 -0
  188. package/src/core/destination.ts +17 -8
  189. package/src/core/event-catalog.ts +29 -15
  190. package/src/core/event-id.ts +1 -2
  191. package/src/core/tracked-event.ts +4 -4
  192. package/src/destinations/ad-consent.ts +29 -0
  193. package/src/destinations/google-analytics.ts +196 -133
  194. package/src/destinations/google-consent.ts +164 -0
  195. package/src/destinations/meta.ts +96 -0
  196. package/src/destinations/microsoft-uet.ts +86 -0
  197. package/src/destinations/shared.ts +45 -0
  198. package/src/destinations/tiktok.ts +85 -0
  199. package/src/destinations/vercel-analytics.ts +23 -24
  200. package/src/index.ts +165 -8
  201. package/src/react/consent-banner.tsx +40 -14
  202. package/src/react/gtag-consent-bootstrap.tsx +48 -0
  203. package/src/react/use-consent.ts +53 -45
  204. package/src/react/use-google-consent-sync.ts +38 -0
  205. package/src/react/use-initial-consent.ts +22 -0
  206. package/src/server/anonymous-id-cookie.ts +103 -0
  207. package/src/server/consent-receipt-store.ts +79 -0
  208. package/src/server/consent-receipt.ts +89 -0
  209. package/src/server/initial-consent.ts +46 -0
  210. package/src/server/measurement-protocol.ts +114 -0
  211. package/src/server/region.ts +22 -15
  212. package/src/server/user-deletion.ts +93 -0
  213. package/src/tooling/import-protection.ts +22 -0
  214. package/dist/client/consent-storage.mjs +0 -63
  215. package/dist/client/create-client-tracker.d.mts +0 -37
  216. package/dist/client/create-client-tracker.mjs +0 -66
  217. package/dist/client/gpc.d.mts +0 -10
  218. package/dist/client/gpc.mjs +0 -12
  219. package/dist/client/index.d.mts +0 -8
  220. package/dist/client/index.mjs +0 -8
  221. package/dist/client/lifecycle.d.mts +0 -23
  222. package/dist/client/lifecycle.mjs +0 -30
  223. package/dist/client/local-storage.d.mts +0 -13
  224. package/dist/client/local-storage.mjs +0 -31
  225. package/dist/client/queue.d.mts +0 -49
  226. package/dist/client/queue.mjs +0 -71
  227. package/dist/client/router.d.mts +0 -30
  228. package/dist/client/router.mjs +0 -17
  229. package/dist/core/consent.d.mts +0 -89
  230. package/dist/core/consent.mjs +0 -57
  231. package/dist/core/destination.d.mts +0 -23
  232. package/dist/core/destination.mjs +0 -1
  233. package/dist/core/event-catalog.d.mts +0 -36
  234. package/dist/core/event-catalog.mjs +0 -12
  235. package/dist/core/event-id.d.mts +0 -10
  236. package/dist/core/event-id.mjs +0 -12
  237. package/dist/core/index.d.mts +0 -6
  238. package/dist/core/index.mjs +0 -4
  239. package/dist/core/tracked-event.d.mts +0 -17
  240. package/dist/core/tracked-event.mjs +0 -1
  241. package/dist/destinations/ga4-measurement-protocol.d.mts +0 -54
  242. package/dist/destinations/ga4-measurement-protocol.mjs +0 -89
  243. package/dist/destinations/google-analytics.d.mts +0 -98
  244. package/dist/destinations/google-analytics.mjs +0 -126
  245. package/dist/destinations/http-destination.d.mts +0 -20
  246. package/dist/destinations/http-destination.mjs +0 -25
  247. package/dist/destinations/index.d.mts +0 -5
  248. package/dist/destinations/index.mjs +0 -5
  249. package/dist/destinations/vercel-analytics.d.mts +0 -13
  250. package/dist/destinations/vercel-analytics.mjs +0 -30
  251. package/dist/index.d.mts +0 -6
  252. package/dist/index.mjs +0 -4
  253. package/dist/react/consent-banner.d.mts +0 -163
  254. package/dist/react/consent-banner.mjs +0 -209
  255. package/dist/react/index.d.mts +0 -3
  256. package/dist/react/index.mjs +0 -3
  257. package/dist/react/use-consent.d.mts +0 -49
  258. package/dist/react/use-consent.mjs +0 -54
  259. package/dist/server/create-server-tracker.d.mts +0 -42
  260. package/dist/server/create-server-tracker.mjs +0 -67
  261. package/dist/server/index.d.mts +0 -3
  262. package/dist/server/index.mjs +0 -3
  263. package/dist/server/region.d.mts +0 -20
  264. package/dist/server/region.mjs +0 -56
  265. package/src/client/index.ts +0 -17
  266. package/src/client/lifecycle.ts +0 -50
  267. package/src/client/local-storage.ts +0 -44
  268. package/src/client/queue.ts +0 -117
  269. package/src/client/router.ts +0 -37
  270. package/src/core/index.ts +0 -24
  271. package/src/destinations/ga4-measurement-protocol.ts +0 -166
  272. package/src/destinations/http-destination.ts +0 -33
  273. package/src/destinations/index.ts +0 -20
  274. package/src/react/index.ts +0 -29
  275. package/src/server/create-server-tracker.ts +0 -128
  276. package/src/server/index.ts +0 -4
@@ -0,0 +1,63 @@
1
+ import type { InitialConsent } from "#/core/consent";
2
+ /**
3
+ * External-store view of the visitor's region default — the strictest value until the
4
+ * server lane answers, then the resolved one.
5
+ *
6
+ * @since 1.0.0-canary.6
7
+ */
8
+ export interface InitialConsentSnapshot {
9
+ /** The region-correct default once resolved; {@link STRICTEST_INITIAL_CONSENT} until then. */
10
+ initialConsent: InitialConsent;
11
+ /**
12
+ * True once a usable default is published — either a successful server answer or a
13
+ * fail-closed fallback. A failed fetch still sets this so consent UI can render, but
14
+ * does not lock the session: resolution stays retryable.
15
+ */
16
+ isResolved: boolean;
17
+ }
18
+ /**
19
+ * @since 1.0.0-canary.6
20
+ */
21
+ export interface InitialConsentStoreOptions {
22
+ /**
23
+ * The per-visitor server lane — typically a server function wrapping
24
+ * `resolveInitialConsentFromRequest`. Prerendered/CDN-cached HTML can carry nothing
25
+ * region-specific, so this is the only place the region-correct default may come from.
26
+ */
27
+ resolve: () => Promise<InitialConsent>;
28
+ /**
29
+ * `sessionStorage` key caching the resolved value, so only the first page load of a
30
+ * session pays the round trip — omit to resolve once per page load instead. Cached
31
+ * values are re-validated with `isInitialConsent` before use.
32
+ */
33
+ sessionStorageKey?: string | undefined;
34
+ }
35
+ /**
36
+ * `useSyncExternalStore`-shaped — pass `subscribe`/`getSnapshot`/`getServerSnapshot`
37
+ * straight through, or use the `useInitialConsent` hook from `@codefast/tracking/react`.
38
+ *
39
+ * @since 1.0.0-canary.6
40
+ */
41
+ export interface InitialConsentStore {
42
+ /**
43
+ * Kicks off region resolution (at most one in-flight request; a success is sticky for
44
+ * the store's lifetime). Call it early — e.g. at router creation, window-guarded — so
45
+ * the round trip overlaps hydration instead of waiting for the first effect.
46
+ */
47
+ ensureResolved: () => void;
48
+ getServerSnapshot: () => InitialConsentSnapshot;
49
+ getSnapshot: () => InitialConsentSnapshot;
50
+ /** Test seam — clears resolved state, retry listeners, and the session cache. */
51
+ reset: () => void;
52
+ subscribe: (listener: () => void) => () => void;
53
+ }
54
+ /**
55
+ * The client half of the server-resolved consent lane: single-flight resolution over the
56
+ * given server function, an optional per-session cache, fail-closed publishing on error
57
+ * (consent UI still renders, under the strictest default), and a retry the next time the
58
+ * tab becomes visible — so one failed request never locks the whole SPA session.
59
+ *
60
+ * @since 1.0.0-canary.6
61
+ */
62
+ export declare function createInitialConsentStore(options: InitialConsentStoreOptions): InitialConsentStore;
63
+ //# sourceMappingURL=initial-consent-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initial-consent-store.d.ts","sourceRoot":"","sources":["../../src/client/initial-consent-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,8FAA8F;IAC9F,cAAc,EAAE,cAAc,CAAC;IAC/B;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;IACvC;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;IAChD,WAAW,EAAE,MAAM,sBAAsB,CAAC;IAC1C,iFAAiF;IACjF,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CACjD;AAOD;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,CAkJlG"}
@@ -0,0 +1,138 @@
1
+ import { isInitialConsent, STRICTEST_INITIAL_CONSENT } from "#/core/consent";
2
+ const SERVER_SNAPSHOT = {
3
+ initialConsent: STRICTEST_INITIAL_CONSENT,
4
+ isResolved: false,
5
+ };
6
+ /**
7
+ * The client half of the server-resolved consent lane: single-flight resolution over the
8
+ * given server function, an optional per-session cache, fail-closed publishing on error
9
+ * (consent UI still renders, under the strictest default), and a retry the next time the
10
+ * tab becomes visible — so one failed request never locks the whole SPA session.
11
+ *
12
+ * @since 1.0.0-canary.6
13
+ */
14
+ export function createInitialConsentStore(options) {
15
+ const listeners = new Set();
16
+ let snapshot = SERVER_SNAPSHOT;
17
+ let isFetchInFlight = false;
18
+ /** Sticky only after a successful resolve (or session-cache hit) — failures stay retryable. */
19
+ let hasResolvedSuccessfully = false;
20
+ function notify() {
21
+ for (const listener of listeners) {
22
+ listener();
23
+ }
24
+ }
25
+ // add/removeEventListener dedupe an identical listener, so no armed-flag is needed.
26
+ function stopResolveRetry() {
27
+ if (typeof window === "undefined") {
28
+ return;
29
+ }
30
+ document.removeEventListener("visibilitychange", onResolveRetryResume);
31
+ window.removeEventListener("pageshow", onResolveRetryResume);
32
+ window.removeEventListener("online", onResolveRetryResume);
33
+ }
34
+ function onResolveRetryResume() {
35
+ if (hasResolvedSuccessfully) {
36
+ stopResolveRetry();
37
+ return;
38
+ }
39
+ if (document.visibilityState === "visible") {
40
+ ensureResolved();
41
+ }
42
+ }
43
+ /**
44
+ * After a failed fetch, retry when the tab becomes visible again or connectivity
45
+ * returns (coalesced by in-flight) — a visitor who never leaves the tab must not stay
46
+ * fail-closed for the whole session over one network blip.
47
+ */
48
+ function scheduleResolveRetry() {
49
+ if (typeof window === "undefined") {
50
+ return;
51
+ }
52
+ document.addEventListener("visibilitychange", onResolveRetryResume);
53
+ window.addEventListener("pageshow", onResolveRetryResume);
54
+ window.addEventListener("online", onResolveRetryResume);
55
+ }
56
+ function publishResolved(initialConsent) {
57
+ hasResolvedSuccessfully = true;
58
+ snapshot = { initialConsent, isResolved: true };
59
+ stopResolveRetry();
60
+ notify();
61
+ }
62
+ /** Fail-closed UI without permanently locking the session against a later retry. */
63
+ function publishFailClosed() {
64
+ snapshot = { initialConsent: STRICTEST_INITIAL_CONSENT, isResolved: true };
65
+ notify();
66
+ }
67
+ function readSessionCache() {
68
+ if (options.sessionStorageKey === undefined) {
69
+ return undefined;
70
+ }
71
+ try {
72
+ const raw = window.sessionStorage.getItem(options.sessionStorageKey);
73
+ const parsed = raw === null ? undefined : JSON.parse(raw);
74
+ return isInitialConsent(parsed) ? parsed : undefined;
75
+ }
76
+ catch {
77
+ return undefined;
78
+ }
79
+ }
80
+ function writeSessionCache(resolved) {
81
+ if (options.sessionStorageKey === undefined) {
82
+ return;
83
+ }
84
+ try {
85
+ window.sessionStorage.setItem(options.sessionStorageKey, JSON.stringify(resolved));
86
+ }
87
+ catch {
88
+ /* private mode / quota — resolve again next page load */
89
+ }
90
+ }
91
+ function ensureResolved() {
92
+ if (hasResolvedSuccessfully || isFetchInFlight || typeof window === "undefined") {
93
+ return;
94
+ }
95
+ const cached = readSessionCache();
96
+ if (cached) {
97
+ publishResolved(cached);
98
+ return;
99
+ }
100
+ isFetchInFlight = true;
101
+ // Promise.resolve().then(...) folds a synchronously throwing resolver into the same
102
+ // fail-closed path — tracking must never break the caller (a React mount effect).
103
+ Promise.resolve()
104
+ .then(() => options.resolve())
105
+ .then((resolved) => {
106
+ writeSessionCache(resolved);
107
+ publishResolved(resolved);
108
+ })
109
+ .catch(() => {
110
+ publishFailClosed();
111
+ scheduleResolveRetry();
112
+ })
113
+ .finally(() => {
114
+ isFetchInFlight = false;
115
+ });
116
+ }
117
+ return {
118
+ ensureResolved,
119
+ getServerSnapshot: () => SERVER_SNAPSHOT,
120
+ getSnapshot: () => snapshot,
121
+ reset() {
122
+ stopResolveRetry();
123
+ snapshot = SERVER_SNAPSHOT;
124
+ isFetchInFlight = false;
125
+ hasResolvedSuccessfully = false;
126
+ if (typeof window !== "undefined" && options.sessionStorageKey !== undefined) {
127
+ window.sessionStorage.removeItem(options.sessionStorageKey);
128
+ }
129
+ },
130
+ subscribe(listener) {
131
+ listeners.add(listener);
132
+ return () => {
133
+ listeners.delete(listener);
134
+ };
135
+ },
136
+ };
137
+ }
138
+ //# sourceMappingURL=initial-consent-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initial-consent-store.js","sourceRoot":"","sources":["../../src/client/initial-consent-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAyD7E,MAAM,eAAe,GAA2B;IAC9C,cAAc,EAAE,yBAAyB;IACzC,UAAU,EAAE,KAAK;CAClB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAmC;IAC3E,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAExC,IAAI,QAAQ,GAA2B,eAAe,CAAC;IACvD,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,+FAA+F;IAC/F,IAAI,uBAAuB,GAAG,KAAK,CAAC;IAEpC,SAAS,MAAM;QACb,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAED,oFAAoF;IACpF,SAAS,gBAAgB;QACvB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,oBAAoB,CAAC,CAAC;QACvE,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;QAC7D,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAC7D,CAAC;IAED,SAAS,oBAAoB;QAC3B,IAAI,uBAAuB,EAAE,CAAC;YAC5B,gBAAgB,EAAE,CAAC;YAEnB,OAAO;QACT,CAAC;QAED,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YAC3C,cAAc,EAAE,CAAC;QACnB,CAAC;IACH,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,KAAK,CAAC;YAEhC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;gBAC7E,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,SAAS,CAAC,QAAoB;YAC5B,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAExB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { ConsentMode, ConsentStorage } from "#/core/consent";
2
+ import type { ConsentConfig } from "#/core/consent-config";
3
+ /**
4
+ * @since 1.0.0-canary.6
5
+ */
6
+ export interface IsAnalyticsAllowedOptions {
7
+ /** Must be the same object `useConsent` receives — one config, every surface. */
8
+ config: ConsentConfig;
9
+ /**
10
+ * Re-read each call. Pass `hasGlobalPrivacyControlSignal` from `@codefast/tracking/client`
11
+ * (or a wrapper) so GPC changes apply without recreating the gate.
12
+ */
13
+ hasGlobalPrivacyControlSignal?: (() => boolean) | undefined;
14
+ /** Re-read each call so a post-hydration region resolve can win. */
15
+ getMode: () => ConsentMode;
16
+ /** Must be the same storage instance `useConsent` subscribes to. */
17
+ storage: ConsentStorage;
18
+ }
19
+ /**
20
+ * Non-React mirror of `useConsent`'s `isAnalyticsAllowed` — pass the returned function as
21
+ * `createClientTracker({ isAnalyticsAllowed })` so the pipeline and the banner share one rule.
22
+ *
23
+ * @since 1.0.0-canary.6
24
+ */
25
+ export declare function createIsAnalyticsAllowed(options: IsAnalyticsAllowedOptions): () => boolean;
26
+ //# sourceMappingURL=is-analytics-allowed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-analytics-allowed.d.ts","sourceRoot":"","sources":["../../src/client/is-analytics-allowed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,iFAAiF;IACjF,MAAM,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,6BAA6B,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5D,oEAAoE;IACpE,OAAO,EAAE,MAAM,WAAW,CAAC;IAC3B,oEAAoE;IACpE,OAAO,EAAE,cAAc,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,OAAO,CAe1F"}
@@ -0,0 +1,22 @@
1
+ import { resolveEffectiveConsent } from "#/core/consent";
2
+ /**
3
+ * Non-React mirror of `useConsent`'s `isAnalyticsAllowed` — pass the returned function as
4
+ * `createClientTracker({ isAnalyticsAllowed })` so the pipeline and the banner share one rule.
5
+ *
6
+ * @since 1.0.0-canary.6
7
+ */
8
+ export function createIsAnalyticsAllowed(options) {
9
+ const { config, getMode, storage } = options;
10
+ const readGpc = options.hasGlobalPrivacyControlSignal ?? (() => false);
11
+ return () => {
12
+ const effectiveConsent = resolveEffectiveConsent({
13
+ hasGlobalPrivacyControlSignal: readGpc(),
14
+ mode: getMode(),
15
+ policyVersion: config.policyVersion,
16
+ requestedCategories: config.requestedCategories,
17
+ storage,
18
+ });
19
+ return effectiveConsent.analytics;
20
+ };
21
+ }
22
+ //# sourceMappingURL=is-analytics-allowed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-analytics-allowed.js","sourceRoot":"","sources":["../../src/client/is-analytics-allowed.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAoBzD;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAAkC;IACzE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,6BAA6B,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IAEvE,OAAO,GAAY,EAAE;QACnB,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;YAC/C,6BAA6B,EAAE,OAAO,EAAE;YACxC,IAAI,EAAE,OAAO,EAAE;YACf,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;YAC/C,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,gBAAgB,CAAC,SAAS,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { CookieAnonymousId } from "#/client/cookie-anonymous-id";
2
+ /**
3
+ * @since 1.0.0-canary.6
4
+ */
5
+ export interface ServerPersistedAnonymousIdOptions {
6
+ /** Server round-trip that expires the cookie via `Set-Cookie` — the server half of `clear()`. */
7
+ clearOnServer?: (() => Promise<void>) | undefined;
8
+ /** Cookie name — must not collide with another cookie on the domain. */
9
+ cookieName: string;
10
+ /** How long the id survives a return visit. Defaults to one year. */
11
+ maxAgeSeconds?: number | undefined;
12
+ /**
13
+ * Server round-trip that re-sets the cookie via `Set-Cookie` (e.g. a server function
14
+ * calling `setAnonymousIdResponseCookie`). Fired at most once per page load, only after an
15
+ * id exists client-side — the server persists and prolongs, it never mints.
16
+ */
17
+ persist: (id: string) => Promise<void>;
18
+ }
19
+ /**
20
+ * `createCookieAnonymousId` plus server persistence: the client still mints the id
21
+ * (lazily, only once an event is allowed to send — consent stays client-owned), then
22
+ * delegates the durable write to the server. A script-written cookie is capped at 7 days
23
+ * by Safari ITP; the server's `Set-Cookie` re-issue is what makes the id actually live
24
+ * its full max-age. Same optimistic `document.cookie` write first, so the current event
25
+ * never waits on the round-trip and a failed `persist` degrades to today's behavior.
26
+ *
27
+ * @since 1.0.0-canary.6
28
+ */
29
+ export declare function createServerPersistedAnonymousId(options: ServerPersistedAnonymousIdOptions): CookieAnonymousId;
30
+ //# sourceMappingURL=server-persisted-anonymous-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-persisted-anonymous-id.d.ts","sourceRoot":"","sources":["../../src/client/server-persisted-anonymous-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAItE;;GAEG;AACH,MAAM,WAAW,iCAAiC;IAChD,iGAAiG;IACjG,aAAa,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;IAClD,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC;;;;OAIG;IACH,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED;;;;;;;;;GASG;AACH,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,iCAAiC,GAAG,iBAAiB,CAqE9G"}
@@ -0,0 +1,72 @@
1
+ import { createCookieAnonymousId } from "#/client/cookie-anonymous-id";
2
+ import { readCookieValue } from "#/core/cookie";
3
+ /**
4
+ * `createCookieAnonymousId` plus server persistence: the client still mints the id
5
+ * (lazily, only once an event is allowed to send — consent stays client-owned), then
6
+ * delegates the durable write to the server. A script-written cookie is capped at 7 days
7
+ * by Safari ITP; the server's `Set-Cookie` re-issue is what makes the id actually live
8
+ * its full max-age. Same optimistic `document.cookie` write first, so the current event
9
+ * never waits on the round-trip and a failed `persist` degrades to today's behavior.
10
+ *
11
+ * @since 1.0.0-canary.6
12
+ */
13
+ export function createServerPersistedAnonymousId(options) {
14
+ const { clearOnServer, cookieName, maxAgeSeconds, persist } = options;
15
+ const local = createCookieAnonymousId({ cookieName, maxAgeSeconds });
16
+ // One attempt per page load — a failure is not retried until the next load, so a down
17
+ // endpoint costs one request, not one per event. Tracking must never break the app.
18
+ let hasRequestedPersist = false;
19
+ return {
20
+ clear() {
21
+ // Skip the server round-trip when the cookie is already gone (e.g. a second
22
+ // withdrawal clear from another mounted consent surface in the same tick).
23
+ const shouldClearServer = typeof document !== "undefined" && Boolean(readCookieValue(document.cookie, cookieName));
24
+ local.clear();
25
+ // A fresh id after a re-grant must be persisted again.
26
+ hasRequestedPersist = false;
27
+ if (shouldClearServer) {
28
+ void clearOnServer?.().catch(() => {
29
+ /* the client-side expiry above already took effect */
30
+ });
31
+ }
32
+ },
33
+ current() {
34
+ return local.current();
35
+ },
36
+ getOrCreate() {
37
+ // Cross-tab withdrawal expires the cookie without this instance's `clear()` — reset
38
+ // so the next minted id is server-persisted (ITP re-issue) again.
39
+ if (typeof document !== "undefined" && !readCookieValue(document.cookie, cookieName)) {
40
+ hasRequestedPersist = false;
41
+ }
42
+ const id = local.getOrCreate();
43
+ // Also fires when the cookie already existed: the re-issue upgrades a script-written
44
+ // cookie to a server-set one and rolls its expiry forward on every visit.
45
+ if (!hasRequestedPersist && typeof document !== "undefined") {
46
+ hasRequestedPersist = true;
47
+ void persist(id).catch(() => {
48
+ /* optimistic client-side cookie still covers this session */
49
+ });
50
+ }
51
+ return id;
52
+ },
53
+ refresh() {
54
+ if (typeof document === "undefined") {
55
+ return;
56
+ }
57
+ const existing = readCookieValue(document.cookie, cookieName);
58
+ if (!existing) {
59
+ return;
60
+ }
61
+ local.refresh();
62
+ // Same once-per-load budget as getOrCreate — refresh must not add a second request.
63
+ if (!hasRequestedPersist) {
64
+ hasRequestedPersist = true;
65
+ void persist(existing).catch(() => {
66
+ /* optimistic client-side prolong above still covers this session */
67
+ });
68
+ }
69
+ },
70
+ };
71
+ }
72
+ //# sourceMappingURL=server-persisted-anonymous-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-persisted-anonymous-id.js","sourceRoot":"","sources":["../../src/client/server-persisted-anonymous-id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K,WAAW,EAAE,CAAC;gBAC5D,mBAAmB,GAAG,IAAI,CAAC;gBAC3B,KAAK,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;oBAC1B,6DAA6D;gBAC/D,CAAC,CAAC,CAAC;YACL,CAAC;YAED,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO;YACL,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;gBACpC,OAAO;YACT,CAAC;YAED,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YAE9D,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,OAAO;YACT,CAAC;YAED,KAAK,CAAC,OAAO,EAAE,CAAC;YAEhB,oFAAoF;YACpF,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBACzB,mBAAmB,GAAG,IAAI,CAAC;gBAC3B,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;oBAChC,oEAAoE;gBACtE,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { ConsentCategory } from "#/core/consent";
2
+ /**
3
+ * The consent constants every surface must agree on. The React hooks, the client
4
+ * tracker gate, and the pre-hydration tag bootstrap all accept this object, so the
5
+ * cross-surface "must match" contracts hold by construction instead of by hand-threading
6
+ * the same strings through every call site.
7
+ *
8
+ * @since 1.0.0-canary.6
9
+ */
10
+ export interface ConsentConfig {
11
+ /** Bumping re-prompts every visitor — a stored decision under any other version is ignored. */
12
+ policyVersion: string;
13
+ /** Purposes the app's prompt asks about — `grantAll` and opt-out defaults grant exactly these. */
14
+ requestedCategories: ReadonlyArray<ConsentCategory>;
15
+ /** `localStorage` key holding the visitor's `ConsentRecord`. */
16
+ storageKey: string;
17
+ }
18
+ /**
19
+ * Identity helper for declaring the config with inference — `defineEventCatalog`'s consent twin.
20
+ *
21
+ * @since 1.0.0-canary.6
22
+ */
23
+ export declare function defineConsentConfig<Config extends ConsentConfig>(config: Config): Config;
24
+ //# sourceMappingURL=consent-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-config.d.ts","sourceRoot":"","sources":["../../src/core/consent-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,+FAA+F;IAC/F,aAAa,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,mBAAmB,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IACpD,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAExF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Identity helper for declaring the config with inference — `defineEventCatalog`'s consent twin.
3
+ *
4
+ * @since 1.0.0-canary.6
5
+ */
6
+ export function defineConsentConfig(config) {
7
+ return config;
8
+ }
9
+ //# sourceMappingURL=consent-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-config.js","sourceRoot":"","sources":["../../src/core/consent-config.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAA+B,MAAc;IAC9E,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import type { ConsentDecision } from "#/core/consent";
2
+ /**
3
+ * Which consent event a receipt records. Receipts are append-only: an `update` or
4
+ * `withdraw` is a new receipt referencing the prior one, never a mutation.
5
+ *
6
+ * @since 1.0.0-canary.7
7
+ */
8
+ export type ConsentReceiptEventType = "give" | "update" | "withdraw";
9
+ /**
10
+ * How the decision was expressed — the "how" dimension a demonstrable-consent record must
11
+ * capture (GDPR Art. 7(1); EDPB 05/2020 §5.1). See spec/spec-consent-receipts.md.
12
+ *
13
+ * @since 1.0.0-canary.7
14
+ */
15
+ export type ConsentReceiptMethod = "banner-accept" | "banner-reject" | "granular" | "gpc-signal" | "withdrawal";
16
+ /**
17
+ * What kind of identifier links the receipt to a subject. A cookie-only visitor uses a
18
+ * pseudonymous `cookie` id — the receipt is still valid proof.
19
+ *
20
+ * @since 1.0.0-canary.7
21
+ */
22
+ export type ConsentReceiptSubjectIdType = "cookie" | "email-hash" | "userId";
23
+ /**
24
+ * The caller-supplied fields of a consent receipt. Deliberately carries **no IP** — the
25
+ * server derives a coarsened one from the connection so a full IP never transits the body.
26
+ *
27
+ * @since 1.0.0-canary.7
28
+ */
29
+ export interface ConsentReceiptInput {
30
+ decision: ConsentDecision;
31
+ eventType: ConsentReceiptEventType;
32
+ method: ConsentReceiptMethod;
33
+ /** BCP-47 language of the notice the subject was shown. */
34
+ noticeLanguage: string;
35
+ /** Version the stored notice snapshot resolves to — EDPB para 108's "copy of the information presented". */
36
+ noticeVersion: string;
37
+ policyVersion: string;
38
+ subjectId: string;
39
+ subjectIdType: ConsentReceiptSubjectIdType;
40
+ /** The prior receipt this update/withdrawal supersedes — the append-only chain link. */
41
+ supersedesReceiptId?: string | undefined;
42
+ }
43
+ /**
44
+ * A stored consent receipt: the caller input plus server-derived fields. This is the
45
+ * legally-authoritative record of proof — the client `ConsentRecord` is only a runtime
46
+ * cache (spec-consent-receipts §5).
47
+ *
48
+ * @remarks
49
+ * The record is append-only; never mutate a stored receipt. `ipCoarse` is truncated at
50
+ * write time and MUST NOT be a full IP.
51
+ *
52
+ * @since 1.0.0-canary.7
53
+ */
54
+ export interface ConsentReceipt extends ConsentReceiptInput {
55
+ /** Coarsened/pseudonymized IP, or absent — never a full address. */
56
+ ipCoarse?: string | undefined;
57
+ /** Optional tamper-evidence signature, present only when a signer was supplied. */
58
+ integrityKey?: string | undefined;
59
+ receiptId: string;
60
+ schemaVersion: string;
61
+ /** Milliseconds since the Unix epoch, from the server clock. */
62
+ timestamp: number;
63
+ }
64
+ /**
65
+ * Guards a receipt input received from an untrusted client. Rejects a body carrying an
66
+ * `ip`/`ipCoarse` field so a full address can never be persisted from caller input.
67
+ *
68
+ * @since 1.0.0-canary.7
69
+ */
70
+ export declare function isConsentReceiptInput(value: unknown): value is ConsentReceiptInput;
71
+ //# sourceMappingURL=consent-receipt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-receipt.d.ts","sourceRoot":"","sources":["../../src/core/consent-receipt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;AAErE;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,eAAe,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC;AAEhH;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG,QAAQ,GAAG,YAAY,GAAG,QAAQ,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,eAAe,CAAC;IAC1B,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,4GAA4G;IAC5G,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,2BAA2B,CAAC;IAC3C,wFAAwF;IACxF,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAe,SAAQ,mBAAmB;IACzD,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,gEAAgE;IAChE,SAAS,EAAE,MAAM,CAAC;CACnB;AAgBD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAwBlF"}
@@ -0,0 +1,39 @@
1
+ import { isConsentDecision } from "#/core/consent";
2
+ function isString(value) {
3
+ return typeof value === "string";
4
+ }
5
+ const RECEIPT_METHODS = new Set([
6
+ "banner-accept",
7
+ "banner-reject",
8
+ "granular",
9
+ "gpc-signal",
10
+ "withdrawal",
11
+ ]);
12
+ const RECEIPT_SUBJECT_ID_TYPES = new Set(["cookie", "email-hash", "userId"]);
13
+ /**
14
+ * Guards a receipt input received from an untrusted client. Rejects a body carrying an
15
+ * `ip`/`ipCoarse` field so a full address can never be persisted from caller input.
16
+ *
17
+ * @since 1.0.0-canary.7
18
+ */
19
+ export function isConsentReceiptInput(value) {
20
+ if (typeof value !== "object" || value === null) {
21
+ return false;
22
+ }
23
+ const input = value;
24
+ // A client MUST NOT supply IP — the server derives it. Presence is an integrity red flag.
25
+ if ("ip" in input || "ipCoarse" in input) {
26
+ return false;
27
+ }
28
+ return (isConsentDecision(input.decision) &&
29
+ (input.eventType === "give" || input.eventType === "update" || input.eventType === "withdraw") &&
30
+ isString(input.method) &&
31
+ RECEIPT_METHODS.has(input.method) &&
32
+ isString(input.noticeLanguage) &&
33
+ isString(input.noticeVersion) &&
34
+ isString(input.policyVersion) &&
35
+ isString(input.subjectId) &&
36
+ isString(input.subjectIdType) &&
37
+ RECEIPT_SUBJECT_ID_TYPES.has(input.subjectIdType));
38
+ }
39
+ //# sourceMappingURL=consent-receipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-receipt.js","sourceRoot":"","sources":["../../src/core/consent-receipt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAA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