@c15t/backend 2.0.0-rc.3 → 2.0.0-rc.5

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 (314) hide show
  1. package/dist/cache.cjs +4 -4
  2. package/dist/cache.js +4 -4
  3. package/dist/core.cjs +845 -87
  4. package/dist/core.js +821 -87
  5. package/dist/db/schema.cjs +37 -0
  6. package/dist/db/schema.js +33 -2
  7. package/dist/edge.cjs +1106 -0
  8. package/dist/edge.js +1069 -0
  9. package/dist/router.cjs +621 -71
  10. package/dist/router.js +621 -71
  11. package/{dist → dist-types}/cache/adapters/cloudflare-kv.d.ts +0 -1
  12. package/{dist → dist-types}/cache/adapters/index.d.ts +0 -1
  13. package/{dist → dist-types}/cache/adapters/memory.d.ts +0 -1
  14. package/{dist → dist-types}/cache/adapters/upstash-redis.d.ts +0 -1
  15. package/{dist → dist-types}/cache/gvl-resolver.d.ts +1 -2
  16. package/{dist → dist-types}/cache/index.d.ts +0 -1
  17. package/{dist → dist-types}/cache/keys.d.ts +0 -1
  18. package/{dist → dist-types}/cache/types.d.ts +0 -1
  19. package/{dist → dist-types}/core.d.ts +8 -1
  20. package/{dist → dist-types}/db/migrator/index.d.ts +0 -1
  21. package/{dist → dist-types}/db/registry/consent-policy.d.ts +0 -1
  22. package/{dist → dist-types}/db/registry/consent-purpose.d.ts +0 -1
  23. package/{dist → dist-types}/db/registry/domain.d.ts +0 -1
  24. package/{dist → dist-types}/db/registry/index.d.ts +22 -2
  25. package/dist-types/db/registry/runtime-policy-decision.d.ts +60 -0
  26. package/{dist → dist-types}/db/registry/subject.d.ts +0 -1
  27. package/{dist → dist-types}/db/registry/types.d.ts +1 -2
  28. package/{dist → dist-types}/db/registry/utils/generate-id.d.ts +0 -1
  29. package/{dist → dist-types}/db/registry/utils.d.ts +0 -1
  30. package/{dist → dist-types}/db/schema/1.0.0/audit-log.d.ts +0 -1
  31. package/{dist → dist-types}/db/schema/1.0.0/consent-policy.d.ts +0 -1
  32. package/{dist → dist-types}/db/schema/1.0.0/consent-purpose.d.ts +0 -1
  33. package/{dist → dist-types}/db/schema/1.0.0/consent-record.d.ts +0 -1
  34. package/{dist → dist-types}/db/schema/1.0.0/consent.d.ts +1 -2
  35. package/{dist → dist-types}/db/schema/1.0.0/domain.d.ts +0 -1
  36. package/{dist → dist-types}/db/schema/1.0.0/index.d.ts +0 -1
  37. package/{dist → dist-types}/db/schema/1.0.0/subject.d.ts +0 -1
  38. package/{dist → dist-types}/db/schema/2.0.0/audit-log.d.ts +1 -2
  39. package/{dist → dist-types}/db/schema/2.0.0/consent-policy.d.ts +1 -2
  40. package/{dist → dist-types}/db/schema/2.0.0/consent-purpose.d.ts +1 -2
  41. package/{dist → dist-types}/db/schema/2.0.0/consent.d.ts +5 -2
  42. package/{dist → dist-types}/db/schema/2.0.0/domain.d.ts +1 -2
  43. package/{dist → dist-types}/db/schema/2.0.0/index.d.ts +432 -17
  44. package/dist-types/db/schema/2.0.0/runtime-policy-decision.d.ts +23 -0
  45. package/{dist → dist-types}/db/schema/2.0.0/subject.d.ts +1 -2
  46. package/{dist → dist-types}/db/schema/index.d.ts +862 -33
  47. package/{dist → dist-types}/db/tenant-scope.d.ts +0 -1
  48. package/dist-types/define-config.d.ts +17 -0
  49. package/dist-types/edge/index.d.ts +5 -0
  50. package/dist-types/edge/init-handler.d.ts +38 -0
  51. package/dist-types/edge/resolve-consent.d.ts +80 -0
  52. package/dist-types/edge/types.d.ts +13 -0
  53. package/{dist → dist-types}/handlers/consent/check.handler.d.ts +0 -1
  54. package/{src/handlers/consent/index.ts → dist-types/handlers/consent/index.d.ts} +0 -1
  55. package/{dist → dist-types}/handlers/init/geo.d.ts +2 -3
  56. package/{dist → dist-types}/handlers/init/index.d.ts +4 -5
  57. package/dist-types/handlers/init/policy.d.ts +26 -0
  58. package/dist-types/handlers/init/resolve-init.d.ts +44 -0
  59. package/dist-types/handlers/init/translations.d.ts +48 -0
  60. package/dist-types/handlers/policy/snapshot.d.ts +99 -0
  61. package/{src/handlers/status/index.ts → dist-types/handlers/status/index.d.ts} +0 -1
  62. package/{dist → dist-types}/handlers/status/status.handler.d.ts +0 -1
  63. package/{dist → dist-types}/handlers/subject/get.handler.d.ts +0 -1
  64. package/{src/handlers/subject/index.ts → dist-types/handlers/subject/index.d.ts} +0 -1
  65. package/{dist → dist-types}/handlers/subject/list.handler.d.ts +0 -1
  66. package/{dist → dist-types}/handlers/subject/patch.handler.d.ts +0 -1
  67. package/{dist → dist-types}/handlers/subject/post.handler.d.ts +12 -1
  68. package/{dist → dist-types}/handlers/utils/consent-enrichment.d.ts +0 -1
  69. package/{dist → dist-types}/init.d.ts +4 -7
  70. package/{dist → dist-types}/middleware/auth/index.d.ts +0 -1
  71. package/{dist → dist-types}/middleware/auth/validate-api-key.d.ts +0 -1
  72. package/{dist → dist-types}/middleware/cors/cors.d.ts +0 -1
  73. package/{src/middleware/cors/index.ts → dist-types/middleware/cors/index.d.ts} +0 -1
  74. package/{dist → dist-types}/middleware/cors/is-origin-trusted.d.ts +1 -2
  75. package/{dist → dist-types}/middleware/cors/process-cors.d.ts +0 -1
  76. package/{dist → dist-types}/middleware/openapi/config.d.ts +0 -1
  77. package/{dist → dist-types}/middleware/openapi/handlers.d.ts +0 -1
  78. package/{src/middleware/openapi/index.ts → dist-types/middleware/openapi/index.d.ts} +0 -1
  79. package/{dist → dist-types}/middleware/process-ip/index.d.ts +0 -1
  80. package/dist-types/policies/builder.d.ts +127 -0
  81. package/dist-types/policies/defaults.d.ts +2 -0
  82. package/dist-types/policies/matchers.d.ts +3 -0
  83. package/{dist → dist-types}/router.d.ts +0 -1
  84. package/{dist → dist-types}/routes/consent.d.ts +0 -1
  85. package/{src/routes/index.ts → dist-types/routes/index.d.ts} +0 -1
  86. package/{dist → dist-types}/routes/init.d.ts +0 -1
  87. package/{dist → dist-types}/routes/status.d.ts +0 -1
  88. package/{dist → dist-types}/routes/subject.d.ts +0 -1
  89. package/{dist → dist-types}/types/api.d.ts +0 -1
  90. package/dist-types/types/index.d.ts +443 -0
  91. package/dist-types/utils/background.d.ts +6 -0
  92. package/{dist → dist-types}/utils/create-telemetry-options.d.ts +1 -2
  93. package/{dist → dist-types}/utils/env.d.ts +0 -1
  94. package/{dist → dist-types}/utils/extract-error-message.d.ts +0 -1
  95. package/{dist → dist-types}/utils/instrumentation.d.ts +0 -1
  96. package/{dist → dist-types}/utils/logger.d.ts +1 -2
  97. package/{dist → dist-types}/utils/metrics.d.ts +0 -1
  98. package/dist-types/version.d.ts +1 -0
  99. package/docs/README.md +49 -0
  100. package/docs/api/configuration.md +197 -0
  101. package/docs/api/endpoints.md +211 -0
  102. package/docs/guides/caching.md +85 -0
  103. package/docs/guides/database-setup.md +128 -0
  104. package/docs/guides/edge-deployment.md +248 -0
  105. package/docs/guides/framework-integration.md +142 -0
  106. package/docs/guides/iab-tcf.md +89 -0
  107. package/docs/guides/observability.md +96 -0
  108. package/docs/guides/policy-packs.md +396 -0
  109. package/docs/quickstart.md +129 -0
  110. package/package.json +37 -23
  111. package/.turbo/turbo-build.log +0 -49
  112. package/CHANGELOG.md +0 -115
  113. package/dist/cache/adapters/cloudflare-kv.d.ts.map +0 -1
  114. package/dist/cache/adapters/index.d.ts.map +0 -1
  115. package/dist/cache/adapters/memory.d.ts.map +0 -1
  116. package/dist/cache/adapters/upstash-redis.d.ts.map +0 -1
  117. package/dist/cache/gvl-resolver.d.ts.map +0 -1
  118. package/dist/cache/index.d.ts.map +0 -1
  119. package/dist/cache/keys.d.ts.map +0 -1
  120. package/dist/cache/types.d.ts.map +0 -1
  121. package/dist/core.d.ts.map +0 -1
  122. package/dist/db/adapters/drizzle.d.ts +0 -2
  123. package/dist/db/adapters/drizzle.d.ts.map +0 -1
  124. package/dist/db/adapters/index.d.ts +0 -2
  125. package/dist/db/adapters/index.d.ts.map +0 -1
  126. package/dist/db/adapters/kysely.d.ts +0 -2
  127. package/dist/db/adapters/kysely.d.ts.map +0 -1
  128. package/dist/db/adapters/mongo.d.ts +0 -2
  129. package/dist/db/adapters/mongo.d.ts.map +0 -1
  130. package/dist/db/adapters/prisma.d.ts +0 -2
  131. package/dist/db/adapters/prisma.d.ts.map +0 -1
  132. package/dist/db/adapters/typeorm.d.ts +0 -2
  133. package/dist/db/adapters/typeorm.d.ts.map +0 -1
  134. package/dist/db/migrator/index.d.ts.map +0 -1
  135. package/dist/db/registry/consent-policy.d.ts.map +0 -1
  136. package/dist/db/registry/consent-purpose.d.ts.map +0 -1
  137. package/dist/db/registry/domain.d.ts.map +0 -1
  138. package/dist/db/registry/index.d.ts.map +0 -1
  139. package/dist/db/registry/subject.d.ts.map +0 -1
  140. package/dist/db/registry/types.d.ts.map +0 -1
  141. package/dist/db/registry/utils/generate-id.d.ts.map +0 -1
  142. package/dist/db/registry/utils.d.ts.map +0 -1
  143. package/dist/db/schema/1.0.0/audit-log.d.ts.map +0 -1
  144. package/dist/db/schema/1.0.0/consent-policy.d.ts.map +0 -1
  145. package/dist/db/schema/1.0.0/consent-purpose.d.ts.map +0 -1
  146. package/dist/db/schema/1.0.0/consent-record.d.ts.map +0 -1
  147. package/dist/db/schema/1.0.0/consent.d.ts.map +0 -1
  148. package/dist/db/schema/1.0.0/domain.d.ts.map +0 -1
  149. package/dist/db/schema/1.0.0/index.d.ts.map +0 -1
  150. package/dist/db/schema/1.0.0/subject.d.ts.map +0 -1
  151. package/dist/db/schema/2.0.0/audit-log.d.ts.map +0 -1
  152. package/dist/db/schema/2.0.0/consent-policy.d.ts.map +0 -1
  153. package/dist/db/schema/2.0.0/consent-purpose.d.ts.map +0 -1
  154. package/dist/db/schema/2.0.0/consent.d.ts.map +0 -1
  155. package/dist/db/schema/2.0.0/domain.d.ts.map +0 -1
  156. package/dist/db/schema/2.0.0/index.d.ts.map +0 -1
  157. package/dist/db/schema/2.0.0/subject.d.ts.map +0 -1
  158. package/dist/db/schema/index.d.ts.map +0 -1
  159. package/dist/db/tenant-scope.d.ts.map +0 -1
  160. package/dist/define-config.d.ts +0 -5
  161. package/dist/define-config.d.ts.map +0 -1
  162. package/dist/handlers/consent/check.handler.d.ts.map +0 -1
  163. package/dist/handlers/consent/index.d.ts +0 -12
  164. package/dist/handlers/consent/index.d.ts.map +0 -1
  165. package/dist/handlers/init/geo.d.ts.map +0 -1
  166. package/dist/handlers/init/index.d.ts.map +0 -1
  167. package/dist/handlers/init/translations.d.ts +0 -28
  168. package/dist/handlers/init/translations.d.ts.map +0 -1
  169. package/dist/handlers/status/index.d.ts +0 -7
  170. package/dist/handlers/status/index.d.ts.map +0 -1
  171. package/dist/handlers/status/status.handler.d.ts.map +0 -1
  172. package/dist/handlers/subject/get.handler.d.ts.map +0 -1
  173. package/dist/handlers/subject/index.d.ts +0 -10
  174. package/dist/handlers/subject/index.d.ts.map +0 -1
  175. package/dist/handlers/subject/list.handler.d.ts.map +0 -1
  176. package/dist/handlers/subject/patch.handler.d.ts.map +0 -1
  177. package/dist/handlers/subject/post.handler.d.ts.map +0 -1
  178. package/dist/handlers/utils/consent-enrichment.d.ts.map +0 -1
  179. package/dist/init.d.ts.map +0 -1
  180. package/dist/middleware/auth/index.d.ts.map +0 -1
  181. package/dist/middleware/auth/validate-api-key.d.ts.map +0 -1
  182. package/dist/middleware/cors/cors.d.ts.map +0 -1
  183. package/dist/middleware/cors/index.d.ts +0 -30
  184. package/dist/middleware/cors/index.d.ts.map +0 -1
  185. package/dist/middleware/cors/is-origin-trusted.d.ts.map +0 -1
  186. package/dist/middleware/cors/process-cors.d.ts.map +0 -1
  187. package/dist/middleware/openapi/config.d.ts.map +0 -1
  188. package/dist/middleware/openapi/handlers.d.ts.map +0 -1
  189. package/dist/middleware/openapi/index.d.ts +0 -12
  190. package/dist/middleware/openapi/index.d.ts.map +0 -1
  191. package/dist/middleware/process-ip/index.d.ts.map +0 -1
  192. package/dist/router.d.ts.map +0 -1
  193. package/dist/routes/consent.d.ts.map +0 -1
  194. package/dist/routes/index.d.ts +0 -10
  195. package/dist/routes/index.d.ts.map +0 -1
  196. package/dist/routes/init.d.ts.map +0 -1
  197. package/dist/routes/status.d.ts.map +0 -1
  198. package/dist/routes/subject.d.ts.map +0 -1
  199. package/dist/types/api.d.ts.map +0 -1
  200. package/dist/types/index.d.ts +0 -263
  201. package/dist/types/index.d.ts.map +0 -1
  202. package/dist/utils/create-telemetry-options.d.ts.map +0 -1
  203. package/dist/utils/env.d.ts.map +0 -1
  204. package/dist/utils/extract-error-message.d.ts.map +0 -1
  205. package/dist/utils/index.d.ts +0 -4
  206. package/dist/utils/index.d.ts.map +0 -1
  207. package/dist/utils/instrumentation.d.ts.map +0 -1
  208. package/dist/utils/logger.d.ts.map +0 -1
  209. package/dist/utils/metrics.d.ts.map +0 -1
  210. package/dist/version.d.ts +0 -2
  211. package/dist/version.d.ts.map +0 -1
  212. package/knip.json +0 -31
  213. package/rslib.config.ts +0 -93
  214. package/src/cache/adapters/cloudflare-kv.ts +0 -71
  215. package/src/cache/adapters/index.ts +0 -22
  216. package/src/cache/adapters/memory.ts +0 -111
  217. package/src/cache/adapters/upstash-redis.ts +0 -113
  218. package/src/cache/gvl-resolver.ts +0 -289
  219. package/src/cache/index.ts +0 -34
  220. package/src/cache/keys.ts +0 -68
  221. package/src/cache/types.ts +0 -66
  222. package/src/core.ts +0 -369
  223. package/src/db/migrator/index.ts +0 -80
  224. package/src/db/registry/consent-policy.test.ts +0 -451
  225. package/src/db/registry/consent-policy.ts +0 -82
  226. package/src/db/registry/consent-purpose.test.ts +0 -428
  227. package/src/db/registry/consent-purpose.ts +0 -61
  228. package/src/db/registry/domain.test.ts +0 -445
  229. package/src/db/registry/domain.ts +0 -91
  230. package/src/db/registry/index.ts +0 -14
  231. package/src/db/registry/subject.test.ts +0 -371
  232. package/src/db/registry/subject.ts +0 -126
  233. package/src/db/registry/types.ts +0 -10
  234. package/src/db/registry/utils/generate-id.test.ts +0 -216
  235. package/src/db/registry/utils/generate-id.ts +0 -133
  236. package/src/db/registry/utils.ts +0 -133
  237. package/src/db/schema/1.0.0/audit-log.ts +0 -15
  238. package/src/db/schema/1.0.0/consent-policy.ts +0 -14
  239. package/src/db/schema/1.0.0/consent-purpose.ts +0 -14
  240. package/src/db/schema/1.0.0/consent-record.ts +0 -10
  241. package/src/db/schema/1.0.0/consent.ts +0 -20
  242. package/src/db/schema/1.0.0/domain.ts +0 -12
  243. package/src/db/schema/1.0.0/index.ts +0 -48
  244. package/src/db/schema/1.0.0/subject.ts +0 -11
  245. package/src/db/schema/2.0.0/audit-log.ts +0 -18
  246. package/src/db/schema/2.0.0/consent-policy.ts +0 -28
  247. package/src/db/schema/2.0.0/consent-purpose.ts +0 -12
  248. package/src/db/schema/2.0.0/consent.ts +0 -28
  249. package/src/db/schema/2.0.0/domain.ts +0 -12
  250. package/src/db/schema/2.0.0/index.ts +0 -47
  251. package/src/db/schema/2.0.0/subject.ts +0 -13
  252. package/src/db/schema/index.ts +0 -15
  253. package/src/db/tenant-scope.test.ts +0 -747
  254. package/src/db/tenant-scope.ts +0 -103
  255. package/src/define-config.ts +0 -5
  256. package/src/handlers/consent/check.handler.ts +0 -126
  257. package/src/handlers/init/geo.test.ts +0 -317
  258. package/src/handlers/init/geo.ts +0 -195
  259. package/src/handlers/init/index.test.ts +0 -205
  260. package/src/handlers/init/index.ts +0 -114
  261. package/src/handlers/init/translations.test.ts +0 -121
  262. package/src/handlers/init/translations.ts +0 -72
  263. package/src/handlers/status/status.handler.test.ts +0 -155
  264. package/src/handlers/status/status.handler.ts +0 -51
  265. package/src/handlers/subject/get.handler.ts +0 -92
  266. package/src/handlers/subject/list.handler.ts +0 -92
  267. package/src/handlers/subject/patch.handler.ts +0 -119
  268. package/src/handlers/subject/post.handler.test.ts +0 -294
  269. package/src/handlers/subject/post.handler.ts +0 -268
  270. package/src/handlers/utils/consent-enrichment.test.ts +0 -380
  271. package/src/handlers/utils/consent-enrichment.ts +0 -218
  272. package/src/init.test.ts +0 -126
  273. package/src/init.ts +0 -87
  274. package/src/middleware/auth/index.ts +0 -11
  275. package/src/middleware/auth/validate-api-key.test.ts +0 -86
  276. package/src/middleware/auth/validate-api-key.ts +0 -107
  277. package/src/middleware/cors/cors.test.ts +0 -135
  278. package/src/middleware/cors/cors.ts +0 -186
  279. package/src/middleware/cors/is-origin-trusted.test.ts +0 -164
  280. package/src/middleware/cors/is-origin-trusted.ts +0 -130
  281. package/src/middleware/cors/process-cors.ts +0 -91
  282. package/src/middleware/openapi/config.ts +0 -29
  283. package/src/middleware/openapi/handlers.ts +0 -34
  284. package/src/middleware/process-ip/index.test.ts +0 -195
  285. package/src/middleware/process-ip/index.ts +0 -199
  286. package/src/router.ts +0 -15
  287. package/src/routes/consent.ts +0 -52
  288. package/src/routes/init.ts +0 -105
  289. package/src/routes/status.ts +0 -46
  290. package/src/routes/subject.ts +0 -152
  291. package/src/types/api.ts +0 -48
  292. package/src/types/index.ts +0 -297
  293. package/src/utils/create-telemetry-options.test.ts +0 -302
  294. package/src/utils/create-telemetry-options.ts +0 -229
  295. package/src/utils/env.ts +0 -84
  296. package/src/utils/extract-error-message.ts +0 -21
  297. package/src/utils/instrumentation.test.ts +0 -185
  298. package/src/utils/instrumentation.ts +0 -196
  299. package/src/utils/logger.ts +0 -41
  300. package/src/utils/metrics.test.ts +0 -323
  301. package/src/utils/metrics.ts +0 -402
  302. package/src/utils/telemetry-pii.test.ts +0 -325
  303. package/src/version.ts +0 -2
  304. package/tsconfig.json +0 -11
  305. package/vitest.config.ts +0 -28
  306. /package/dist/{types.cjs → types/index.cjs} +0 -0
  307. /package/dist/{types.js → types/index.js} +0 -0
  308. /package/{src/db/adapters/drizzle.ts → dist-types/db/adapters/drizzle.d.ts} +0 -0
  309. /package/{src/db/adapters/index.ts → dist-types/db/adapters/index.d.ts} +0 -0
  310. /package/{src/db/adapters/kysely.ts → dist-types/db/adapters/kysely.d.ts} +0 -0
  311. /package/{src/db/adapters/mongo.ts → dist-types/db/adapters/mongo.d.ts} +0 -0
  312. /package/{src/db/adapters/prisma.ts → dist-types/db/adapters/prisma.d.ts} +0 -0
  313. /package/{src/db/adapters/typeorm.ts → dist-types/db/adapters/typeorm.d.ts} +0 -0
  314. /package/{src/utils/index.ts → dist-types/utils/index.d.ts} +0 -0
@@ -0,0 +1,248 @@
1
+ ---
2
+ title: Edge Deployment
3
+ description: Run consent policy resolution at the edge for faster initial banner loads.
4
+ ---
5
+ The `/init` endpoint determines consent policy from geo headers, resolves translations, and optionally fetches the GVL. None of this requires a database. The `@c15t/backend/edge` export lets you run this logic in edge runtimes (Vercel Middleware, Cloudflare Workers, Deno Deploy) so the consent banner resolves from the nearest PoP instead of round-tripping to your origin.
6
+
7
+ ```
8
+ Standard: Browser → Origin (single region) → c15tInstance(/init) → Response
9
+ Edge: Browser → Edge (nearest PoP) → c15tEdgeInit → Response
10
+ ```
11
+
12
+ ## When to use this
13
+
14
+ * Your origin server is in a single region and users are globally distributed
15
+ * You want the consent banner to appear as fast as possible (edge latency is typically 10-50ms vs 100-300ms to origin)
16
+ * You already use edge middleware for other purposes (auth, redirects, A/B testing)
17
+
18
+ You do **not** need this if:
19
+
20
+ * Your origin is already multi-region or on a platform like Cloudflare Workers
21
+ * Consent banner latency is not a concern for your use case
22
+
23
+ ## Setup
24
+
25
+ ### 1. Extract shared config
26
+
27
+ Keep your policy configuration in a shared file so both the edge handler and origin handler stay in sync:
28
+
29
+ ```ts title="lib/consent-config.ts"
30
+ import type { C15TEdgeOptions } from '@c15t/backend/edge';
31
+
32
+ export const consentConfig = {
33
+ trustedOrigins: ['https://myapp.com'],
34
+ policyPacks: [
35
+ {
36
+ id: 'eu_gdpr',
37
+ match: { countries: ['DE', 'FR', 'IT', 'ES', 'NL', 'PL'] },
38
+ consent: { model: 'opt-in' },
39
+ ui: { mode: 'banner' },
40
+ },
41
+ {
42
+ id: 'us_ca',
43
+ match: { regions: [{ country: 'US', region: 'CA' }] },
44
+ consent: { model: 'opt-out' },
45
+ ui: { mode: 'banner' },
46
+ },
47
+ ],
48
+ policySnapshot: {
49
+ signingKey: process.env.SNAPSHOT_KEY!,
50
+ },
51
+ } satisfies C15TEdgeOptions;
52
+ ```
53
+
54
+ ### 2. Create edge middleware
55
+
56
+ **Vercel Middleware**
57
+
58
+ ```ts title="middleware.ts"
59
+ import { c15tEdgeInit } from '@c15t/backend/edge';
60
+ import { consentConfig } from './lib/consent-config';
61
+
62
+ const initHandler = c15tEdgeInit(consentConfig);
63
+
64
+ export async function middleware(request: Request) {
65
+ const url = new URL(request.url);
66
+ if (url.pathname === '/api/c15t/init') {
67
+ return initHandler(request);
68
+ }
69
+ }
70
+
71
+ export const config = {
72
+ matcher: '/api/c15t/init',
73
+ };
74
+ ```
75
+
76
+ **Cloudflare Workers**
77
+
78
+ ```ts title="worker.ts"
79
+ import { c15tEdgeInit } from '@c15t/backend/edge';
80
+ import { consentConfig } from './lib/consent-config';
81
+
82
+ const initHandler = c15tEdgeInit(consentConfig);
83
+
84
+ export default {
85
+ async fetch(request: Request) {
86
+ const url = new URL(request.url);
87
+ if (url.pathname === '/api/c15t/init') {
88
+ return initHandler(request);
89
+ }
90
+ // Forward other requests to origin
91
+ return fetch(request);
92
+ },
93
+ };
94
+ ```
95
+
96
+ **Deno Deploy**
97
+
98
+ ```ts title="main.ts"
99
+ import { c15tEdgeInit } from '@c15t/backend/edge';
100
+ import { consentConfig } from './lib/consent-config.ts';
101
+
102
+ const initHandler = c15tEdgeInit(consentConfig);
103
+
104
+ Deno.serve(async (request) => {
105
+ const url = new URL(request.url);
106
+ if (url.pathname === '/api/c15t/init') {
107
+ return initHandler(request);
108
+ }
109
+ return new Response('Not found', { status: 404 });
110
+ });
111
+ ```
112
+
113
+ ### 3. Keep your origin handler unchanged
114
+
115
+ The origin API route still handles all database-dependent endpoints (`/subjects`, `/consents`, `/status`). The only difference is that `/init` requests no longer reach the origin — they're intercepted at the edge.
116
+
117
+ ```ts title="app/api/c15t/[[...path]]/route.ts"
118
+ import { c15tInstance } from '@c15t/backend';
119
+ import { consentConfig } from '@/lib/consent-config';
120
+
121
+ const c15t = c15tInstance({
122
+ adapter: yourDbAdapter,
123
+ ...consentConfig,
124
+ });
125
+
126
+ export const { GET, POST } = c15t;
127
+ ```
128
+
129
+ ## Configuration
130
+
131
+ `c15tEdgeInit` accepts `C15TEdgeOptions` — the same fields as `c15tInstance` minus the database-related options (`adapter`, `tablePrefix`, `basePath`, `openapi`, `ipAddress`, `apiKeys`, `background`).
132
+
133
+ |Option|Required|Description|
134
+ |--|--|--|
135
+ |`trustedOrigins`|Yes|Allowed CORS origins — must match your origin handler|
136
+ |`policyPacks`|No|Regional policy configuration|
137
+ |`policySnapshot`|No|Signing key for policy snapshot tokens|
138
+ |`iab`|No|IAB TCF configuration|
139
+ |`i18n`|No|Translation profiles|
140
+ |`branding`|No|Banner branding (default: `"c15t"`)|
141
+ |`appName`|No|Application name (default: `"c15t"`)|
142
+ |`tenantId`|No|Tenant ID for multi-tenant deployments|
143
+ |`cache`|No|External cache adapter for GVL|
144
+ |`disableGeoLocation`|No|Disable geo-location detection|
145
+ |`telemetry`|No|OpenTelemetry configuration|
146
+ |`logger`|No|Logger configuration|
147
+
148
+ > ℹ️ **Info:**
149
+ > The edge handler and origin handler must share the same policyPacks, policySnapshot, trustedOrigins, iab, and i18n configuration. If they diverge, /init will return policies that don't match what the database endpoints expect. Use a shared config file as shown above.
150
+
151
+ ## How it works
152
+
153
+ The edge handler:
154
+
155
+ 1. **Reads geo headers** — Vercel sets `x-vercel-ip-country` and `x-vercel-ip-country-region` automatically. Cloudflare sets `cf-ipcountry`. The handler checks all common provider headers.
156
+ 2. **Resolves jurisdiction** — Maps the country/region to a jurisdiction code (GDPR, CCPA, UK\_GDPR, etc.)
157
+ 3. **Matches a policy pack** — Finds the first matching policy for the visitor's location
158
+ 4. **Resolves translations** — Picks the right language from `Accept-Language` and your i18n config
159
+ 5. **Signs a snapshot token** — Creates a JWT proving which policy was served (if `policySnapshot` is configured)
160
+ 6. **Handles CORS** — Validates the `Origin` header against `trustedOrigins` and sets appropriate headers
161
+
162
+ All of this uses the same functions as the full `c15tInstance` — the edge handler is not a reimplementation, it's the same code without the database layer.
163
+
164
+ ## Caching considerations
165
+
166
+ Edge isolates have short-lived memory. The in-memory GVL cache resets on each cold start. For production:
167
+
168
+ * **Bundle GVL translations** using `iab.bundled` to avoid fetch latency entirely
169
+ * **Use an external cache** (Upstash Redis, Cloudflare KV) via the `cache.adapter` option to share cached data across isolates — see the [Caching guide](/docs/self-host/guides/caching) for setup
170
+
171
+ ## Custom consent cookie — resolveConsent
172
+
173
+ > ℹ️ **Info:**
174
+ > Experimental — this API may change in future versions.
175
+
176
+ If you manage your own consent cookie and just need to know **which categories to load** for a given visitor, use `resolveConsent` instead of `c15tEdgeInit`. It's a lightweight, fully synchronous function that returns the matched policy and default consent state — no translations, GVL, branding, or snapshot tokens.
177
+
178
+ ```ts title="middleware.ts"
179
+ import { resolveConsent } from '@c15t/backend/edge';
180
+
181
+ const policyPacks = [
182
+ {
183
+ id: 'eu_gdpr',
184
+ match: { countries: ['DE', 'FR', 'IT', 'ES'] },
185
+ consent: {
186
+ model: 'opt-in',
187
+ categories: ['necessary', 'marketing', 'measurement'],
188
+ },
189
+ ui: { mode: 'banner' },
190
+ },
191
+ {
192
+ id: 'us_default',
193
+ match: { isDefault: true },
194
+ consent: {
195
+ model: 'opt-out',
196
+ categories: ['necessary', 'marketing', 'measurement'],
197
+ gpc: true,
198
+ },
199
+ ui: { mode: 'banner' },
200
+ },
201
+ ];
202
+
203
+ export function middleware(request: Request) {
204
+ const consent = resolveConsent(request, { policyPacks });
205
+
206
+ // consent.model → "opt-in" | "opt-out" | "none" | "iab"
207
+ // consent.showBanner → true
208
+ // consent.jurisdiction → "GDPR"
209
+ // consent.gpc → false
210
+ // consent.defaults → {
211
+ // necessary: { granted: true, required: true },
212
+ // marketing: { granted: false, required: false },
213
+ // measurement: { granted: false, required: false },
214
+ // }
215
+
216
+ // Read your own cookie, merge with consent.defaults,
217
+ // decide which scripts/tags to load
218
+ }
219
+ ```
220
+
221
+ ### Default consent by model
222
+
223
+ |Model|`necessary`|Other categories|Notes|
224
+ |--|--|--|--|
225
+ |`opt-in`|granted, required|**not granted**|Unless listed in `preselectedCategories`|
226
+ |`opt-out`|granted, required|**granted**|GPC signal can override `marketing`/`measurement` to not granted|
227
+ |`none`|granted, required|**granted**|No banner shown|
228
+
229
+ ### `resolveConsent` vs `c15tEdgeInit`
230
+
231
+ ||`resolveConsent`|`c15tEdgeInit`|
232
+ |--|--|--|
233
+ |**Use case**|Custom consent cookie|Drop-in `/init` replacement|
234
+ |**Sync**|Yes|No (async — signs JWT, fetches GVL)|
235
+ |**Returns**|Policy + default consent state|Full `/init` JSON payload|
236
+ |**CORS**|Not handled (your middleware)|Built-in|
237
+ |**Translations**|Not included|Included|
238
+ |**Snapshot token**|Not included|Included|
239
+
240
+ ## What stays on the origin
241
+
242
+ Only `/init` moves to the edge. These endpoints still require the origin server:
243
+
244
+ * `POST /subjects` — creates/updates consent subjects (needs DB)
245
+ * `POST /consents` — records consent decisions (needs DB)
246
+ * `GET /status` — checks current consent status (needs DB)
247
+
248
+ The edge handler is a single-purpose optimization for the one endpoint that doesn't need persistent storage.
@@ -0,0 +1,142 @@
1
+ ---
2
+ title: Framework Integration
3
+ description: Mount the c15t consent backend in any JavaScript framework or runtime.
4
+ ---
5
+ The c15t backend exposes a single handler with the signature `(request: Request) => Promise<Response>`. This is the standard Fetch API, so it works with any runtime that supports it — Node.js, Bun, Deno, and Cloudflare Workers.
6
+
7
+ ## Bun
8
+
9
+ ```ts title="server.ts"
10
+ import { c15t } from './c15t';
11
+
12
+ Bun.serve({
13
+ port: 3001,
14
+ fetch: c15t.handler,
15
+ });
16
+ ```
17
+
18
+ ## Next.js (App Router)
19
+
20
+ Create a catch-all API route that forwards requests to the handler:
21
+
22
+ ```ts title="src/app/api/c15t/[[...path]]/route.ts"
23
+ import { c15t } from '@/lib/c15t';
24
+
25
+ const handler = c15t.handler;
26
+
27
+ export { handler as GET, handler as POST, handler as PUT, handler as PATCH, handler as DELETE };
28
+ ```
29
+
30
+ > ℹ️ **Info:**
31
+ > Use Next.js rewrites to proxy frontend requests through the same domain and avoid ad-blocker issues. See the Next.js Quickstart for the rewrite configuration.
32
+
33
+ ## Hono
34
+
35
+ ```ts title="server.ts"
36
+ import { Hono } from 'hono';
37
+ import { c15t } from './c15t';
38
+
39
+ const app = new Hono();
40
+
41
+ app.all('/api/c15t/*', (c) => c15t.handler(c.req.raw));
42
+
43
+ export default app;
44
+ ```
45
+
46
+ ## Express
47
+
48
+ ```ts title="server.ts"
49
+ import express from 'express';
50
+ import { c15t } from './c15t';
51
+
52
+ const app = express();
53
+
54
+ app.all('/api/c15t/*', async (req, res) => {
55
+ const url = `${req.protocol}://${req.get('host')}${req.originalUrl}`;
56
+ const headers = new Headers();
57
+ for (const [key, value] of Object.entries(req.headers)) {
58
+ if (value) headers.set(key, Array.isArray(value) ? value.join(', ') : value);
59
+ }
60
+
61
+ const request = new Request(url, {
62
+ method: req.method,
63
+ headers,
64
+ body: ['GET', 'HEAD'].includes(req.method) ? undefined : req,
65
+ });
66
+
67
+ const response = await c15t.handler(request);
68
+
69
+ res.status(response.status);
70
+ response.headers.forEach((value, key) => res.setHeader(key, value));
71
+ res.send(await response.text());
72
+ });
73
+
74
+ app.listen(3001);
75
+ ```
76
+
77
+ ## Fastify
78
+
79
+ ```ts title="server.ts"
80
+ import Fastify from 'fastify';
81
+ import { c15t } from './c15t';
82
+
83
+ const app = Fastify();
84
+
85
+ app.all('/api/c15t/*', async (req, reply) => {
86
+ const url = `${req.protocol}://${req.hostname}${req.url}`;
87
+ const request = new Request(url, {
88
+ method: req.method,
89
+ headers: new Headers(req.headers as Record<string, string>),
90
+ body: ['GET', 'HEAD'].includes(req.method) ? undefined : JSON.stringify(req.body),
91
+ });
92
+
93
+ const response = await c15t.handler(request);
94
+
95
+ reply.status(response.status);
96
+ response.headers.forEach((value, key) => reply.header(key, value));
97
+ reply.send(await response.text());
98
+ });
99
+
100
+ app.listen({ port: 3001 });
101
+ ```
102
+
103
+ ## Cloudflare Workers
104
+
105
+ ```ts title="worker.ts"
106
+ import { c15t } from './c15t';
107
+
108
+ export default {
109
+ async fetch(request: Request, env: Env) {
110
+ return c15t.handler(request);
111
+ },
112
+ };
113
+ ```
114
+
115
+ ## Deno
116
+
117
+ ```ts title="server.ts"
118
+ import { c15t } from './c15t.ts';
119
+
120
+ Deno.serve({ port: 3001 }, c15t.handler);
121
+ ```
122
+
123
+ ## CORS
124
+
125
+ The backend automatically handles CORS based on the `trustedOrigins` you configure:
126
+
127
+ ```ts
128
+ c15tInstance({
129
+ trustedOrigins: [
130
+ 'https://example.com',
131
+ 'https://*.example.com', // wildcard subdomains
132
+ ],
133
+ // ...
134
+ });
135
+ ```
136
+
137
+ Features:
138
+
139
+ * `www` variants are automatically allowed
140
+ * Wildcard subdomain matching with `*`
141
+ * `localhost` is allowed in development
142
+ * Preflight `OPTIONS` requests are handled automatically
@@ -0,0 +1,89 @@
1
+ ---
2
+ title: IAB TCF Support
3
+ description: Enable IAB Transparency and Consent Framework (TCF) support in your self-hosted backend.
4
+ ---
5
+ The c15t backend optionally supports [IAB TCF v2.3](https://iabeurope.eu/transparency-consent-framework/), including Global Vendor List (GVL) management and TC String generation.
6
+
7
+ ## CMP Registration
8
+
9
+ [consent.io](https://consent.io) is pending validation as an IAB Europe-registered CMP for c15t. Once approved, when using consent.io as your hosted backend, the CMP ID will be automatically provided to clients — no additional configuration needed.
10
+
11
+ If you self-host and have your own CMP registration with IAB Europe, configure your CMP ID via `iab.cmpId`. This value is returned to clients in the `/init` response so they use the correct CMP identity in TC Strings.
12
+
13
+ > ℹ️ **Info:**
14
+ > A valid (non-zero) CMP ID is required for IAB TCF compliance. If neither the backend nor the client provides a CMP ID, IAB initialization will fail with an error.
15
+ >
16
+ > ℹ️ **Info:**
17
+ > If you heavily customize or build your own IAB banner or dialog (rather than using the default IABConsentBanner and IABConsentDialog components provided by c15t), you cannot use consent.io's CMP ID. You must register your own CMP with IAB Europe and configure your CMP ID via iab.cmpId.
18
+
19
+ ## Enable IAB
20
+
21
+ ```ts title="c15t.ts"
22
+ import { c15tInstance } from '@c15t/backend';
23
+
24
+ export const c15t = c15tInstance({
25
+ // ...
26
+ iab: {
27
+ enabled: true,
28
+ cmpId: 10, // your registered CMP ID (consent.io provides this automatically)
29
+ vendorIds: [755, 52, 69], // only include vendors you use
30
+ },
31
+ });
32
+ ```
33
+
34
+ The backend fetches the GVL from `https://gvl.consent.io` by default and caches it. The `/init` endpoint returns the filtered GVL and your CMP ID to the frontend.
35
+
36
+ ## Custom GVL Endpoint
37
+
38
+ Point to your own GVL mirror:
39
+
40
+ ```ts
41
+ iab: {
42
+ enabled: true,
43
+ endpoint: 'https://your-gvl-mirror.com',
44
+ vendorIds: [755, 52, 69],
45
+ },
46
+ ```
47
+
48
+ ## Bundle GVL by Language
49
+
50
+ Pre-bundle the GVL to avoid runtime fetches:
51
+
52
+ ```ts
53
+ import gvlEn from './gvl/en.json';
54
+ import gvlDe from './gvl/de.json';
55
+
56
+ iab: {
57
+ enabled: true,
58
+ bundled: {
59
+ en: gvlEn,
60
+ de: gvlDe,
61
+ },
62
+ },
63
+ ```
64
+
65
+ > ℹ️ **Info:**
66
+ > Bundling all required GVL translations can significantly increase your deployment size. On serverless environments like Cloudflare Workers — which have strict bundle size limits — this may cause deployments to fail. Consider bundling only the languages you need, or use the GVL endpoint with a cache adapter instead.
67
+
68
+ ## Custom Non-IAB Vendors
69
+
70
+ Add your own vendors alongside IAB-registered ones:
71
+
72
+ ```ts
73
+ iab: {
74
+ enabled: true,
75
+ vendorIds: [755],
76
+ customVendors: [
77
+ {
78
+ id: 'internal-analytics',
79
+ name: 'Our Analytics Platform',
80
+ privacyPolicyUrl: 'https://example.com/privacy',
81
+ purposes: [1, 8],
82
+ },
83
+ ],
84
+ },
85
+ ```
86
+
87
+ ## TC String
88
+
89
+ When IAB TCF is enabled, consent records include a `tcString` field — the encoded TC String that can be passed to vendors. The frontend SDKs handle this automatically when using `mode: 'hosted'`.
@@ -0,0 +1,96 @@
1
+ ---
2
+ title: Observability
3
+ description: Add logging, metrics, and tracing to your self-hosted c15t backend.
4
+ ---
5
+ The c15t backend supports structured logging and opt-in OpenTelemetry integration for production observability.
6
+
7
+ ## OpenTelemetry
8
+
9
+ Telemetry is disabled by default. To enable it, pass your own tracer and meter instances:
10
+
11
+ ```ts title="c15t.ts"
12
+ import { c15tInstance } from '@c15t/backend';
13
+ import { trace, metrics } from '@opentelemetry/api';
14
+
15
+ export const c15t = c15tInstance({
16
+ // ...
17
+ telemetry: {
18
+ enabled: true,
19
+ tracer: trace.getTracer('consent-api'),
20
+ meter: metrics.getMeter('consent-api'),
21
+ defaultAttributes: {
22
+ 'service.name': 'consent-api',
23
+ environment: 'production',
24
+ },
25
+ },
26
+ });
27
+ ```
28
+
29
+ > ℹ️ **Info:**
30
+ > You need to set up your own OpenTelemetry SDK and exporter (e.g. Jaeger, Datadog, Grafana). The c15t backend creates spans and metrics using the instances you provide.
31
+
32
+ ## Metrics
33
+
34
+ When telemetry is enabled, the following metrics are recorded:
35
+
36
+ ### Business Metrics
37
+
38
+ |Metric|Type|Description|
39
+ |--|--|--|
40
+ |`consentCreated`|Counter|Consent record created (by type, jurisdiction)|
41
+ |`consentAccepted`|Counter|Consent accepted (by type)|
42
+ |`consentRejected`|Counter|Consent rejected (by type)|
43
+ |`subjectCreated`|Counter|New subject created|
44
+ |`subjectLinked`|Counter|Subject linked to external ID|
45
+ |`initCount`|Counter|`/init` endpoint called|
46
+
47
+ ### HTTP Metrics
48
+
49
+ |Metric|Type|Description|
50
+ |--|--|--|
51
+ |`httpRequestDuration`|Histogram|Request duration (by method, route, status)|
52
+ |`httpRequestCount`|Counter|Total requests|
53
+ |`httpErrorCount`|Counter|Error responses|
54
+
55
+ ### Database Metrics
56
+
57
+ |Metric|Type|Description|
58
+ |--|--|--|
59
+ |`dbQueryDuration`|Histogram|Query duration (by operation, entity)|
60
+ |`dbQueryCount`|Counter|Total queries|
61
+ |`dbErrorCount`|Counter|Query errors|
62
+
63
+ ### Cache Metrics
64
+
65
+ |Metric|Type|Description|
66
+ |--|--|--|
67
+ |`cacheHit`|Counter|Cache hits (by layer)|
68
+ |`cacheMiss`|Counter|Cache misses (by layer)|
69
+ |`cacheLatency`|Histogram|Cache operation latency|
70
+
71
+ ## Tracing
72
+
73
+ Every request creates a span with:
74
+
75
+ * HTTP method and route
76
+ * Response status code
77
+ * Tenant ID (if multi-tenant)
78
+ * API key authentication status
79
+ * Geo-location resolution
80
+
81
+ Child spans are created for database queries and cache operations.
82
+
83
+ ## Logging
84
+
85
+ Configure the log level:
86
+
87
+ ```ts
88
+ c15tInstance({
89
+ // ...
90
+ logger: {
91
+ level: 'info', // debug, info, warn, error
92
+ },
93
+ });
94
+ ```
95
+
96
+ Logs are structured (JSON-compatible) and include trace context when telemetry is enabled, making it easy to correlate logs with traces.