@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.
Files changed (267) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +72 -17
  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.mts → browser-cookie.d.ts} +2 -4
  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} +3 -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.mts → gpc.d.ts} +2 -4
  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.mts → consent.d.ts} +49 -51
  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.mts → cookie.d.ts} +3 -5
  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.mts → event-id.d.ts} +2 -4
  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.mts → use-initial-consent.d.ts} +3 -6
  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.mts → region.d.ts} +5 -15
  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 +238 -59
  172. package/src/adapters/tanstack-start.ts +135 -0
  173. package/src/client/ad-framework-consent.ts +86 -0
  174. package/src/client/cookie-anonymous-id.ts +19 -0
  175. package/src/client/create-client-tracker.ts +81 -10
  176. package/src/client/server-persisted-anonymous-id.ts +4 -1
  177. package/src/core/consent-receipt.ts +115 -0
  178. package/src/core/consent.ts +2 -2
  179. package/src/core/destination.ts +7 -0
  180. package/src/core/event-catalog.ts +5 -4
  181. package/src/core/tracked-event.ts +5 -20
  182. package/src/destinations/ad-consent.ts +29 -0
  183. package/src/destinations/meta.ts +96 -0
  184. package/src/destinations/microsoft-uet.ts +86 -0
  185. package/src/destinations/tiktok.ts +85 -0
  186. package/src/index.ts +138 -19
  187. package/src/server/anonymous-id-cookie.ts +49 -22
  188. package/src/server/consent-receipt-store.ts +79 -0
  189. package/src/server/consent-receipt.ts +89 -0
  190. package/src/server/initial-consent.ts +0 -2
  191. package/src/server/measurement-protocol.ts +114 -0
  192. package/src/server/region.ts +0 -10
  193. package/src/server/user-deletion.ts +93 -0
  194. package/src/tooling/import-protection.ts +22 -0
  195. package/dist/client/browser-cookie.mjs +0 -15
  196. package/dist/client/consent-runtime.d.mts +0 -56
  197. package/dist/client/consent-runtime.mjs +0 -35
  198. package/dist/client/consent-storage.mjs +0 -82
  199. package/dist/client/consent-withdrawal.d.mts +0 -21
  200. package/dist/client/consent-withdrawal.mjs +0 -17
  201. package/dist/client/cookie-anonymous-id.d.mts +0 -37
  202. package/dist/client/cookie-anonymous-id.mjs +0 -46
  203. package/dist/client/create-client-tracker.d.mts +0 -32
  204. package/dist/client/create-client-tracker.mjs +0 -40
  205. package/dist/client/gpc.mjs +0 -14
  206. package/dist/client/index.d.mts +0 -10
  207. package/dist/client/index.mjs +0 -10
  208. package/dist/client/initial-consent-store.d.mts +0 -66
  209. package/dist/client/initial-consent-store.mjs +0 -119
  210. package/dist/client/is-analytics-allowed.d.mts +0 -29
  211. package/dist/client/is-analytics-allowed.mjs +0 -23
  212. package/dist/client/server-persisted-anonymous-id.d.mts +0 -33
  213. package/dist/client/server-persisted-anonymous-id.mjs +0 -50
  214. package/dist/core/consent-config.d.mts +0 -27
  215. package/dist/core/consent-config.mjs +0 -11
  216. package/dist/core/consent.mjs +0 -152
  217. package/dist/core/cookie.mjs +0 -23
  218. package/dist/core/destination.d.mts +0 -25
  219. package/dist/core/destination.mjs +0 -1
  220. package/dist/core/event-catalog.d.mts +0 -39
  221. package/dist/core/event-catalog.mjs +0 -30
  222. package/dist/core/event-id.mjs +0 -11
  223. package/dist/core/index.d.mts +0 -8
  224. package/dist/core/index.mjs +0 -6
  225. package/dist/core/tracked-event.d.mts +0 -30
  226. package/dist/core/tracked-event.mjs +0 -1
  227. package/dist/destinations/google-analytics.d.mts +0 -150
  228. package/dist/destinations/google-analytics.mjs +0 -130
  229. package/dist/destinations/google-consent.d.mts +0 -64
  230. package/dist/destinations/google-consent.mjs +0 -102
  231. package/dist/destinations/index.d.mts +0 -2
  232. package/dist/destinations/index.mjs +0 -2
  233. package/dist/destinations/shared.d.mts +0 -20
  234. package/dist/destinations/shared.mjs +0 -13
  235. package/dist/destinations/vercel-analytics.d.mts +0 -28
  236. package/dist/destinations/vercel-analytics.mjs +0 -23
  237. package/dist/import-protection.d.mts +0 -19
  238. package/dist/import-protection.mjs +0 -23
  239. package/dist/index.d.mts +0 -8
  240. package/dist/index.mjs +0 -6
  241. package/dist/react/consent-banner.d.mts +0 -180
  242. package/dist/react/consent-banner.mjs +0 -214
  243. package/dist/react/gtag-consent-bootstrap.d.mts +0 -27
  244. package/dist/react/gtag-consent-bootstrap.mjs +0 -29
  245. package/dist/react/index.d.mts +0 -6
  246. package/dist/react/index.mjs +0 -6
  247. package/dist/react/use-consent.d.mts +0 -45
  248. package/dist/react/use-consent.mjs +0 -71
  249. package/dist/react/use-google-consent-sync.d.mts +0 -23
  250. package/dist/react/use-google-consent-sync.mjs +0 -24
  251. package/dist/react/use-initial-consent.mjs +0 -19
  252. package/dist/server/anonymous-id-cookie.d.mts +0 -46
  253. package/dist/server/anonymous-id-cookie.mjs +0 -51
  254. package/dist/server/index.d.mts +0 -5
  255. package/dist/server/index.mjs +0 -4
  256. package/dist/server/initial-consent.d.mts +0 -29
  257. package/dist/server/initial-consent.mjs +0 -31
  258. package/dist/server/region.mjs +0 -77
  259. package/dist/tanstack-start/index.d.mts +0 -58
  260. package/dist/tanstack-start/index.mjs +0 -45
  261. package/src/client/index.ts +0 -28
  262. package/src/core/index.ts +0 -40
  263. package/src/destinations/index.ts +0 -19
  264. package/src/import-protection.ts +0 -20
  265. package/src/react/index.ts +0 -37
  266. package/src/server/index.ts +0 -16
  267. package/src/tanstack-start/index.ts +0 -83
@@ -1,46 +0,0 @@
1
- //#region src/server/anonymous-id-cookie.d.ts
2
- /**
3
- * Whether a value is safe to persist as an anonymous id. The persist endpoint is public
4
- * and echoes its input into a response header, so only an exactly-UUID-shaped value may
5
- * pass — anything else is a header-injection attempt or corruption, never a valid id.
6
- *
7
- * @since 1.0.0-canary.6
8
- */
9
- declare function isValidAnonymousId(value: string): boolean;
10
- /**
11
- * @since 1.0.0-canary.6
12
- */
13
- interface AnonymousIdSetCookieOptions {
14
- /** Cookie name — must match what the client tracker reads. */
15
- cookieName: string;
16
- /** The client-minted id to persist — throws unless it is exactly UUID-shaped. */
17
- id: string;
18
- /** How long the id survives a return visit. Defaults to one year. */
19
- maxAgeSeconds?: number | undefined;
20
- }
21
- /**
22
- * `Set-Cookie` header value that persists (or prolongs) a client-minted anonymous id from
23
- * the server. A server-set cookie escapes Safari ITP's 7-day cap on `document.cookie`
24
- * writes, so the id actually lives its full max-age. The server only ever re-sets an id
25
- * the client hands it — minting stays client-side, after consent, by design.
26
- *
27
- * @remarks
28
- * Always `Secure` — on a plain-HTTP dev origin a browser may drop it, and the
29
- * client-written cookie (`createServerPersistedAnonymousId`'s optimistic write) still
30
- * covers that session. Not `HttpOnly`: the client tracker must read the id to stamp it
31
- * onto events.
32
- *
33
- * @throws Error when `id` is not UUID-shaped or `cookieName` is not a valid token.
34
- *
35
- * @since 1.0.0-canary.6
36
- */
37
- declare function buildAnonymousIdSetCookie(options: AnonymousIdSetCookieOptions): string;
38
- /**
39
- * `Set-Cookie` header value that expires the anonymous-id cookie — the server half of a
40
- * consent withdrawal, alongside the client's own `document.cookie` expiry.
41
- *
42
- * @since 1.0.0-canary.6
43
- */
44
- declare function buildClearAnonymousIdSetCookie(cookieName: string): string;
45
- //#endregion
46
- export { AnonymousIdSetCookieOptions, buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie, isValidAnonymousId };
@@ -1,51 +0,0 @@
1
- import { ONE_YEAR_IN_SECONDS } from "../core/cookie.mjs";
2
- //#region src/server/anonymous-id-cookie.ts
3
- const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
4
- const COOKIE_NAME_PATTERN = /^[\w-]+$/;
5
- function assertCookieName(cookieName) {
6
- if (!COOKIE_NAME_PATTERN.test(cookieName)) throw new Error(`Invalid anonymous-id cookie name: ${JSON.stringify(cookieName)}`);
7
- }
8
- /**
9
- * Whether a value is safe to persist as an anonymous id. The persist endpoint is public
10
- * and echoes its input into a response header, so only an exactly-UUID-shaped value may
11
- * pass — anything else is a header-injection attempt or corruption, never a valid id.
12
- *
13
- * @since 1.0.0-canary.6
14
- */
15
- function isValidAnonymousId(value) {
16
- return UUID_PATTERN.test(value);
17
- }
18
- /**
19
- * `Set-Cookie` header value that persists (or prolongs) a client-minted anonymous id from
20
- * the server. A server-set cookie escapes Safari ITP's 7-day cap on `document.cookie`
21
- * writes, so the id actually lives its full max-age. The server only ever re-sets an id
22
- * the client hands it — minting stays client-side, after consent, by design.
23
- *
24
- * @remarks
25
- * Always `Secure` — on a plain-HTTP dev origin a browser may drop it, and the
26
- * client-written cookie (`createServerPersistedAnonymousId`'s optimistic write) still
27
- * covers that session. Not `HttpOnly`: the client tracker must read the id to stamp it
28
- * onto events.
29
- *
30
- * @throws Error when `id` is not UUID-shaped or `cookieName` is not a valid token.
31
- *
32
- * @since 1.0.0-canary.6
33
- */
34
- function buildAnonymousIdSetCookie(options) {
35
- const { cookieName, id, maxAgeSeconds = ONE_YEAR_IN_SECONDS } = options;
36
- assertCookieName(cookieName);
37
- if (!isValidAnonymousId(id)) throw new Error("Invalid anonymous id: expected a UUID-shaped value");
38
- return `${cookieName}=${id}; Path=/; Max-Age=${String(maxAgeSeconds)}; SameSite=Lax; Secure`;
39
- }
40
- /**
41
- * `Set-Cookie` header value that expires the anonymous-id cookie — the server half of a
42
- * consent withdrawal, alongside the client's own `document.cookie` expiry.
43
- *
44
- * @since 1.0.0-canary.6
45
- */
46
- function buildClearAnonymousIdSetCookie(cookieName) {
47
- assertCookieName(cookieName);
48
- return `${cookieName}=; Path=/; Max-Age=0; SameSite=Lax; Secure`;
49
- }
50
- //#endregion
51
- export { buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie, isValidAnonymousId };
@@ -1,5 +0,0 @@
1
- import { InitialConsent } from "../core/consent.mjs";
2
- import { AnonymousIdSetCookieOptions, buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie, isValidAnonymousId } from "./anonymous-id-cookie.mjs";
3
- import { InitialConsentOptions, resolveInitialConsent } from "./initial-consent.mjs";
4
- import { EU_COUNTRY_CODES, OPT_IN_EQUIVALENT_COUNTRY_CODES, resolveRegion, resolveRegionFromCountryCode } from "./region.mjs";
5
- export { type AnonymousIdSetCookieOptions, EU_COUNTRY_CODES, type InitialConsent, type InitialConsentOptions, OPT_IN_EQUIVALENT_COUNTRY_CODES, buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie, isValidAnonymousId, resolveInitialConsent, resolveRegion, resolveRegionFromCountryCode };
@@ -1,4 +0,0 @@
1
- import { buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie, isValidAnonymousId } from "./anonymous-id-cookie.mjs";
2
- import { EU_COUNTRY_CODES, OPT_IN_EQUIVALENT_COUNTRY_CODES, resolveRegion, resolveRegionFromCountryCode } from "./region.mjs";
3
- import { resolveInitialConsent } from "./initial-consent.mjs";
4
- export { EU_COUNTRY_CODES, OPT_IN_EQUIVALENT_COUNTRY_CODES, buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie, isValidAnonymousId, resolveInitialConsent, resolveRegion, resolveRegionFromCountryCode };
@@ -1,29 +0,0 @@
1
- import { ConsentCategory, InitialConsent } from "../core/consent.mjs";
2
-
3
- //#region src/server/initial-consent.d.ts
4
- /**
5
- * @since 1.0.0-canary.6
6
- */
7
- interface InitialConsentOptions {
8
- /** ISO 3166-1 alpha-2 from the geo header; missing → the strictest opt-in default. */
9
- countryCode: string | undefined;
10
- /** Honored as an ads-only opt-out on the default decision. */
11
- hasGlobalPrivacyControlSignal?: boolean | undefined;
12
- /** Categories the app's prompt asks about — opt-out regions grant exactly these by default. */
13
- requestedCategories: ReadonlyArray<ConsentCategory>;
14
- }
15
- /**
16
- * Pure region → mode → default-consent resolution for server functions (or a fail-closed
17
- * bake when country is unknown). Named with the `resolve*` family it composes.
18
- *
19
- * @remarks
20
- * A missing country code means an unknown visitor (a prerender crawl, a host without a
21
- * geo header) — not a known non-EU visitor — so it fails closed to
22
- * {@link STRICTEST_INITIAL_CONSENT} instead of `"other"`'s opt-out. Conflating the two
23
- * would grant analytics by default to every visitor, EU included, on a geo-less host.
24
- *
25
- * @since 1.0.0-canary.6
26
- */
27
- declare function resolveInitialConsent(options: InitialConsentOptions): InitialConsent;
28
- //#endregion
29
- export { type InitialConsent, InitialConsentOptions, resolveInitialConsent };
@@ -1,31 +0,0 @@
1
- import { STRICTEST_INITIAL_CONSENT, resolveConsentMode, resolveDefaultConsent } from "../core/consent.mjs";
2
- import { resolveRegionFromCountryCode } from "./region.mjs";
3
- //#region src/server/initial-consent.ts
4
- /**
5
- * Pure region → mode → default-consent resolution for server functions (or a fail-closed
6
- * bake when country is unknown). Named with the `resolve*` family it composes.
7
- *
8
- * @remarks
9
- * A missing country code means an unknown visitor (a prerender crawl, a host without a
10
- * geo header) — not a known non-EU visitor — so it fails closed to
11
- * {@link STRICTEST_INITIAL_CONSENT} instead of `"other"`'s opt-out. Conflating the two
12
- * would grant analytics by default to every visitor, EU included, on a geo-less host.
13
- *
14
- * @since 1.0.0-canary.6
15
- */
16
- function resolveInitialConsent(options) {
17
- if (!options.countryCode) return STRICTEST_INITIAL_CONSENT;
18
- const region = resolveRegionFromCountryCode(options.countryCode);
19
- const mode = resolveConsentMode(region);
20
- return {
21
- defaultConsent: resolveDefaultConsent({
22
- hasGlobalPrivacyControlSignal: options.hasGlobalPrivacyControlSignal ?? false,
23
- mode,
24
- requestedCategories: options.requestedCategories
25
- }),
26
- mode,
27
- region
28
- };
29
- }
30
- //#endregion
31
- export { resolveInitialConsent };
@@ -1,77 +0,0 @@
1
- //#region src/server/region.ts
2
- /**
3
- * EU member states — GDPR opt-in via `resolveConsentMode("eu")`.
4
- *
5
- * @since 1.0.0-canary.6
6
- */
7
- const EU_COUNTRY_CODES = /* @__PURE__ */ new Set([
8
- "AT",
9
- "BE",
10
- "BG",
11
- "HR",
12
- "CY",
13
- "CZ",
14
- "DK",
15
- "EE",
16
- "FI",
17
- "FR",
18
- "DE",
19
- "GR",
20
- "HU",
21
- "IE",
22
- "IT",
23
- "LV",
24
- "LT",
25
- "LU",
26
- "MT",
27
- "NL",
28
- "PL",
29
- "PT",
30
- "RO",
31
- "SK",
32
- "SI",
33
- "ES",
34
- "SE"
35
- ]);
36
- /**
37
- * UK GDPR (post-Brexit) and EEA/EFTA states that apply GDPR-equivalent rules — mapped to
38
- * the same `"eu"` consent region so they get opt-in, not the `"other"` opt-out default.
39
- *
40
- * Restricted edge runtimes that cannot import this package should duplicate these codes
41
- * and keep a sync test against this export.
42
- *
43
- * @since 1.0.0-canary.6
44
- */
45
- const OPT_IN_EQUIVALENT_COUNTRY_CODES = /* @__PURE__ */ new Set([
46
- "GB",
47
- "IS",
48
- "LI",
49
- "NO"
50
- ]);
51
- /**
52
- * Unrecognized codes fall back to "other", which `resolveConsentMode` treats as
53
- * opt-out — safe only because opt-in regions (EU/VN plus UK/EEA/EFTA above) are matched
54
- * explicitly. A *missing* code also maps to "other" here, but `resolveInitialConsent`
55
- * intercepts that case first and fails closed — unknown is not known-elsewhere.
56
- *
57
- * @since 0.5.0-canary.4
58
- */
59
- function resolveRegionFromCountryCode(countryCode) {
60
- if (!countryCode) return "other";
61
- const normalized = countryCode.toUpperCase();
62
- if (EU_COUNTRY_CODES.has(normalized) || OPT_IN_EQUIVALENT_COUNTRY_CODES.has(normalized)) return "eu";
63
- if (normalized === "VN") return "vn";
64
- if (normalized === "US") return "us";
65
- return "other";
66
- }
67
- /**
68
- * Reads the hosting platform's geo header (e.g. Vercel's `x-vercel-ip-country`) — pass
69
- * the incoming request's `Headers` from server-function/middleware context.
70
- *
71
- * @since 0.5.0-canary.4
72
- */
73
- function resolveRegion(headers, headerName = "x-vercel-ip-country") {
74
- return resolveRegionFromCountryCode(headers.get(headerName) ?? void 0);
75
- }
76
- //#endregion
77
- export { EU_COUNTRY_CODES, OPT_IN_EQUIVALENT_COUNTRY_CODES, resolveRegion, resolveRegionFromCountryCode };
@@ -1,58 +0,0 @@
1
- import { ConsentCategory, InitialConsent } from "../core/consent.mjs";
2
-
3
- //#region src/tanstack-start/index.d.ts
4
- /**
5
- * Request/response glue for TanStack Start — each helper reads or writes the framework's
6
- * ambient request context (AsyncLocalStorage), so a consumer's server functions shrink to
7
- * one-line handlers around them. Server-only: deny this subpath in the client environment
8
- * via Start's `importProtection` — the compiler already strips it with stubbed handler bodies.
9
- *
10
- * @since 1.0.0-canary.6
11
- */
12
- interface InitialConsentFromRequestOptions {
13
- /**
14
- * Header carrying the ISO 3166-1 alpha-2 country code.
15
- *
16
- * @defaultValue "x-vercel-ip-country"
17
- */
18
- countryHeaderName?: string | undefined;
19
- /** Categories the app's prompt asks about — opt-out regions grant exactly these by default. */
20
- requestedCategories: ReadonlyArray<ConsentCategory>;
21
- }
22
- /**
23
- * Region-correct `InitialConsent` for the current request: reads the platform geo header
24
- * and `sec-gpc`, fails closed when geo is missing, and stamps
25
- * `cache-control: private, no-store` — the value is per-visitor by definition, so no
26
- * shared cache may ever store the response carrying it.
27
- *
28
- * @since 1.0.0-canary.6
29
- */
30
- declare function resolveInitialConsentFromRequest(options: InitialConsentFromRequestOptions): InitialConsent;
31
- /**
32
- * @since 1.0.0-canary.6
33
- */
34
- interface AnonymousIdResponseCookieOptions {
35
- /** Cookie name — must match what the client tracker reads. */
36
- cookieName: string;
37
- /** The client-minted id to persist — throws unless it is exactly UUID-shaped. */
38
- id: string;
39
- /** How long the id survives a return visit. Defaults to one year. */
40
- maxAgeSeconds?: number | undefined;
41
- }
42
- /**
43
- * Persists (or prolongs) a client-minted anonymous id via `Set-Cookie` on the current
44
- * response — the server re-issue that escapes Safari ITP's 7-day cap on script-written
45
- * cookies. Validation lives in `buildAnonymousIdSetCookie`: a non-UUID id throws, so this
46
- * can safely back a public server function without echoing attacker input into a header.
47
- *
48
- * @since 1.0.0-canary.6
49
- */
50
- declare function setAnonymousIdResponseCookie(options: AnonymousIdResponseCookieOptions): void;
51
- /**
52
- * Expires the anonymous-id cookie on the current response — the server half of a consent withdrawal.
53
- *
54
- * @since 1.0.0-canary.6
55
- */
56
- declare function clearAnonymousIdResponseCookie(cookieName: string): void;
57
- //#endregion
58
- export { AnonymousIdResponseCookieOptions, InitialConsentFromRequestOptions, clearAnonymousIdResponseCookie, resolveInitialConsentFromRequest, setAnonymousIdResponseCookie };
@@ -1,45 +0,0 @@
1
- import { buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie } from "../server/anonymous-id-cookie.mjs";
2
- import { resolveInitialConsent } from "../server/initial-consent.mjs";
3
- import { getRequestHeader, setResponseHeader } from "@tanstack/react-start/server";
4
- //#region src/tanstack-start/index.ts
5
- /**
6
- * Region-correct `InitialConsent` for the current request: reads the platform geo header
7
- * and `sec-gpc`, fails closed when geo is missing, and stamps
8
- * `cache-control: private, no-store` — the value is per-visitor by definition, so no
9
- * shared cache may ever store the response carrying it.
10
- *
11
- * @since 1.0.0-canary.6
12
- */
13
- function resolveInitialConsentFromRequest(options) {
14
- setResponseHeader("cache-control", "private, no-store");
15
- return resolveInitialConsent({
16
- countryCode: getRequestHeader(options.countryHeaderName ?? "x-vercel-ip-country"),
17
- hasGlobalPrivacyControlSignal: getRequestHeader("sec-gpc") === "1",
18
- requestedCategories: options.requestedCategories
19
- });
20
- }
21
- /**
22
- * Persists (or prolongs) a client-minted anonymous id via `Set-Cookie` on the current
23
- * response — the server re-issue that escapes Safari ITP's 7-day cap on script-written
24
- * cookies. Validation lives in `buildAnonymousIdSetCookie`: a non-UUID id throws, so this
25
- * can safely back a public server function without echoing attacker input into a header.
26
- *
27
- * @since 1.0.0-canary.6
28
- */
29
- function setAnonymousIdResponseCookie(options) {
30
- setResponseHeader("set-cookie", buildAnonymousIdSetCookie({
31
- cookieName: options.cookieName,
32
- id: options.id,
33
- maxAgeSeconds: options.maxAgeSeconds
34
- }));
35
- }
36
- /**
37
- * Expires the anonymous-id cookie on the current response — the server half of a consent withdrawal.
38
- *
39
- * @since 1.0.0-canary.6
40
- */
41
- function clearAnonymousIdResponseCookie(cookieName) {
42
- setResponseHeader("set-cookie", buildClearAnonymousIdSetCookie(cookieName));
43
- }
44
- //#endregion
45
- export { clearAnonymousIdResponseCookie, resolveInitialConsentFromRequest, setAnonymousIdResponseCookie };
@@ -1,28 +0,0 @@
1
- export type { ClientTracker, ClientTrackerOptions } from "#/client/create-client-tracker";
2
- export { createClientTracker } from "#/client/create-client-tracker";
3
-
4
- export type { ConsentRuntime, ConsentRuntimeOptions } from "#/client/consent-runtime";
5
- export { createConsentRuntime } from "#/client/consent-runtime";
6
-
7
- export { createLocalStorageConsentStorage } from "#/client/consent-storage";
8
-
9
- export type { ConsentWithdrawalHandlerOptions } from "#/client/consent-withdrawal";
10
- export { createConsentWithdrawalHandler } from "#/client/consent-withdrawal";
11
-
12
- export type { CookieAnonymousId, CookieAnonymousIdOptions } from "#/client/cookie-anonymous-id";
13
- export { createCookieAnonymousId } from "#/client/cookie-anonymous-id";
14
-
15
- export { hasGlobalPrivacyControlSignal } from "#/client/gpc";
16
-
17
- export type {
18
- InitialConsentSnapshot,
19
- InitialConsentStore,
20
- InitialConsentStoreOptions,
21
- } from "#/client/initial-consent-store";
22
- export { createInitialConsentStore } from "#/client/initial-consent-store";
23
-
24
- export type { IsAnalyticsAllowedOptions } from "#/client/is-analytics-allowed";
25
- export { createIsAnalyticsAllowed } from "#/client/is-analytics-allowed";
26
-
27
- export type { ServerPersistedAnonymousIdOptions } from "#/client/server-persisted-anonymous-id";
28
- export { createServerPersistedAnonymousId } from "#/client/server-persisted-anonymous-id";
package/src/core/index.ts DELETED
@@ -1,40 +0,0 @@
1
- export type {
2
- ConsentCategory,
3
- ConsentDecision,
4
- ConsentMode,
5
- ConsentRecord,
6
- ConsentRegion,
7
- ConsentStorage,
8
- InitialConsent,
9
- ResolveDefaultConsentOptions,
10
- ResolveEffectiveConsentOptions,
11
- } from "#/core/consent";
12
- export {
13
- CONSENT_CATEGORIES,
14
- CONSENT_REGIONS,
15
- createConsentDecision,
16
- isConsentDecision,
17
- isConsentRecord,
18
- isConsentRegion,
19
- isInitialConsent,
20
- normalizeConsentDecision,
21
- readStoredDecision,
22
- resolveConsentMode,
23
- resolveDefaultConsent,
24
- resolveEffectiveConsent,
25
- STRICTEST_INITIAL_CONSENT,
26
- } from "#/core/consent";
27
-
28
- export type { ConsentConfig } from "#/core/consent-config";
29
- export { defineConsentConfig } from "#/core/consent-config";
30
-
31
- export { readCookieValue } from "#/core/cookie";
32
-
33
- export type { Destination } from "#/core/destination";
34
-
35
- export type { EventCatalog, EventDefinition } from "#/core/event-catalog";
36
- export { assertValidEventProperties, defineEventCatalog } from "#/core/event-catalog";
37
-
38
- export { generateEventId } from "#/core/event-id";
39
-
40
- export type { TrackedEvent, TrackedEventBase, TrackEvent } from "#/core/tracked-event";
@@ -1,19 +0,0 @@
1
- // Browser-lane barrel. Deliberately NOT re-exported here:
2
- // - `#/destinations/vercel-analytics` — its top-level `@vercel/analytics` import would make
3
- // the optional peer mandatory for every barrel consumer; import it via its own subpath.
4
-
5
- export type {
6
- EnsureGtagOptions,
7
- GoogleAnalyticsDestinationOptions,
8
- GtagConsentBootstrapOptions,
9
- GtagFunction,
10
- LoadGtagScriptOptions,
11
- } from "#/destinations/google-analytics";
12
- export {
13
- buildGtagConsentBootstrapScript,
14
- clearGoogleAnalyticsCookies,
15
- createGoogleAnalyticsDestination,
16
- ensureGtag,
17
- loadGtagScript,
18
- updateGoogleConsent,
19
- } from "#/destinations/google-analytics";
@@ -1,20 +0,0 @@
1
- /**
2
- * Import specifiers (picomatch patterns) every client bundle must deny — spread into
3
- * TanStack Start's `importProtection.client.specifiers` so the deny-list ships and
4
- * versions with the package instead of going stale in each consumer's config. Nothing in
5
- * this package imports it — its consumers are app build configs (see apps/ui vite.config.ts).
6
- *
7
- * @example
8
- * ```ts
9
- * tanstackStart({
10
- * importProtection: { client: { specifiers: [...SERVER_ONLY_IMPORT_SPECIFIERS] } },
11
- * });
12
- * ```
13
- *
14
- * @since 1.0.0-canary.6
15
- */
16
- export const SERVER_ONLY_IMPORT_SPECIFIERS: ReadonlyArray<string> = [
17
- "@codefast/tracking/server",
18
- "@codefast/tracking/server/**",
19
- "@codefast/tracking/tanstack-start",
20
- ];
@@ -1,37 +0,0 @@
1
- export type {
2
- ConsentBannerAcceptProps,
3
- ConsentBannerActionsProps,
4
- ConsentBannerCategoryProps,
5
- ConsentBannerCustomizeProps,
6
- ConsentBannerDescriptionProps,
7
- ConsentBannerPreferencesProps,
8
- ConsentBannerProps,
9
- ConsentBannerRejectProps,
10
- ConsentBannerSaveProps,
11
- ConsentBannerTitleProps,
12
- ConsentToggleProps,
13
- } from "#/react/consent-banner";
14
- export {
15
- ConsentBanner,
16
- ConsentBannerAccept,
17
- ConsentBannerActions,
18
- ConsentBannerCategory,
19
- ConsentBannerCustomize,
20
- ConsentBannerDescription,
21
- ConsentBannerPreferences,
22
- ConsentBannerReject,
23
- ConsentBannerSave,
24
- ConsentBannerTitle,
25
- ConsentToggle,
26
- } from "#/react/consent-banner";
27
-
28
- export type { UseConsentOptions, UseConsentResult } from "#/react/use-consent";
29
- export { useConsent } from "#/react/use-consent";
30
-
31
- export { useInitialConsent } from "#/react/use-initial-consent";
32
-
33
- export type { UseGoogleConsentSyncOptions } from "#/react/use-google-consent-sync";
34
- export { useGoogleConsentSync } from "#/react/use-google-consent-sync";
35
-
36
- export type { GtagConsentBootstrapProps } from "#/react/gtag-consent-bootstrap";
37
- export { GtagConsentBootstrap } from "#/react/gtag-consent-bootstrap";
@@ -1,16 +0,0 @@
1
- export type { AnonymousIdSetCookieOptions } from "#/server/anonymous-id-cookie";
2
- export {
3
- buildAnonymousIdSetCookie,
4
- buildClearAnonymousIdSetCookie,
5
- isValidAnonymousId,
6
- } from "#/server/anonymous-id-cookie";
7
-
8
- export type { InitialConsent, InitialConsentOptions } from "#/server/initial-consent";
9
- export { resolveInitialConsent } from "#/server/initial-consent";
10
-
11
- export {
12
- EU_COUNTRY_CODES,
13
- OPT_IN_EQUIVALENT_COUNTRY_CODES,
14
- resolveRegion,
15
- resolveRegionFromCountryCode,
16
- } from "#/server/region";
@@ -1,83 +0,0 @@
1
- import { getRequestHeader, setResponseHeader } from "@tanstack/react-start/server";
2
-
3
- import type { ConsentCategory, InitialConsent } from "#/core/consent";
4
- import { buildAnonymousIdSetCookie, buildClearAnonymousIdSetCookie } from "#/server/anonymous-id-cookie";
5
- import { resolveInitialConsent } from "#/server/initial-consent";
6
-
7
- /**
8
- * Request/response glue for TanStack Start — each helper reads or writes the framework's
9
- * ambient request context (AsyncLocalStorage), so a consumer's server functions shrink to
10
- * one-line handlers around them. Server-only: deny this subpath in the client environment
11
- * via Start's `importProtection` — the compiler already strips it with stubbed handler bodies.
12
- *
13
- * @since 1.0.0-canary.6
14
- */
15
-
16
- export interface InitialConsentFromRequestOptions {
17
- /**
18
- * Header carrying the ISO 3166-1 alpha-2 country code.
19
- *
20
- * @defaultValue "x-vercel-ip-country"
21
- */
22
- countryHeaderName?: string | undefined;
23
- /** Categories the app's prompt asks about — opt-out regions grant exactly these by default. */
24
- requestedCategories: ReadonlyArray<ConsentCategory>;
25
- }
26
-
27
- /**
28
- * Region-correct `InitialConsent` for the current request: reads the platform geo header
29
- * and `sec-gpc`, fails closed when geo is missing, and stamps
30
- * `cache-control: private, no-store` — the value is per-visitor by definition, so no
31
- * shared cache may ever store the response carrying it.
32
- *
33
- * @since 1.0.0-canary.6
34
- */
35
- export function resolveInitialConsentFromRequest(options: InitialConsentFromRequestOptions): InitialConsent {
36
- setResponseHeader("cache-control", "private, no-store");
37
-
38
- return resolveInitialConsent({
39
- countryCode: getRequestHeader(options.countryHeaderName ?? "x-vercel-ip-country"),
40
- hasGlobalPrivacyControlSignal: getRequestHeader("sec-gpc") === "1",
41
- requestedCategories: options.requestedCategories,
42
- });
43
- }
44
-
45
- /**
46
- * @since 1.0.0-canary.6
47
- */
48
- export interface AnonymousIdResponseCookieOptions {
49
- /** Cookie name — must match what the client tracker reads. */
50
- cookieName: string;
51
- /** The client-minted id to persist — throws unless it is exactly UUID-shaped. */
52
- id: string;
53
- /** How long the id survives a return visit. Defaults to one year. */
54
- maxAgeSeconds?: number | undefined;
55
- }
56
-
57
- /**
58
- * Persists (or prolongs) a client-minted anonymous id via `Set-Cookie` on the current
59
- * response — the server re-issue that escapes Safari ITP's 7-day cap on script-written
60
- * cookies. Validation lives in `buildAnonymousIdSetCookie`: a non-UUID id throws, so this
61
- * can safely back a public server function without echoing attacker input into a header.
62
- *
63
- * @since 1.0.0-canary.6
64
- */
65
- export function setAnonymousIdResponseCookie(options: AnonymousIdResponseCookieOptions): void {
66
- setResponseHeader(
67
- "set-cookie",
68
- buildAnonymousIdSetCookie({
69
- cookieName: options.cookieName,
70
- id: options.id,
71
- maxAgeSeconds: options.maxAgeSeconds,
72
- }),
73
- );
74
- }
75
-
76
- /**
77
- * Expires the anonymous-id cookie on the current response — the server half of a consent withdrawal.
78
- *
79
- * @since 1.0.0-canary.6
80
- */
81
- export function clearAnonymousIdResponseCookie(cookieName: string): void {
82
- setResponseHeader("set-cookie", buildClearAnonymousIdSetCookie(cookieName));
83
- }