@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
package/docs/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # c15t Backend Docs
2
+
3
+ Self-hosted c15t backend docs for configuration, policy packs, APIs, and operational behavior.
4
+
5
+ If you are changing consent flows, consent UI, script loading, server-side setup, or backend configuration in an app that uses this package, start here before editing code.
6
+
7
+ ## Start Here
8
+
9
+ - [Quickstart](./quickstart.md)
10
+ - [Database Setup](./guides/database-setup.md)
11
+ - [Policy Packs](./guides/policy-packs.md)
12
+ - [Configuration](./api/configuration.md)
13
+
14
+ ## Workflow Rules
15
+
16
+ ### Database & Initial Setup
17
+
18
+ Use this when:
19
+ - configuring a self-hosted backend
20
+ - choosing adapters or initial backend wiring
21
+
22
+ Prefer:
23
+ - Start with the documented database setup guide.
24
+ - Prefer the documented adapter and setup path before custom backend wiring.
25
+
26
+ If that is not enough:
27
+ - Use the API reference when you need exact option-level behavior.
28
+
29
+ Read next:
30
+ - [Quickstart](./quickstart.md)
31
+ - [Database Setup](./guides/database-setup.md)
32
+ - [Configuration](./api/configuration.md)
33
+
34
+ ### Policy Packs & Regional Behavior
35
+
36
+ Use this when:
37
+ - configuring region-aware consent behavior
38
+ - deciding whether logic belongs in backend policy config or frontend code
39
+
40
+ Prefer:
41
+ - Prefer policy-pack and documented backend configuration over frontend-only regional logic.
42
+ - Keep consent behavior centralized in backend policy configuration where possible.
43
+
44
+ Avoid:
45
+ - Do not scatter policy decisions across client code when the backend can own them.
46
+
47
+ Read next:
48
+ - [Policy Packs](./guides/policy-packs.md)
49
+ - [Configuration](./api/configuration.md)
@@ -0,0 +1,197 @@
1
+ ---
2
+ title: Configuration Reference
3
+ description: Complete reference for all c15t backend configuration options.
4
+ ---
5
+ All options are passed to `c15tInstance()`. Only `adapter` and `trustedOrigins` are required.
6
+
7
+ ## Options
8
+
9
+ ### C15TOptions
10
+
11
+ |Property|Type|Description|Default|Required|
12
+ |:--|:--|:--|:--|:--:|
13
+ |adapter|[FumaDBAdapter](https://v2.c15t.com/docs/self-host/guides/database-setup)|The database adapter to use.|-|✅ Required|
14
+ |tenantId|string \|undefined|Tenant ID for multi-tenant deployments. When set, all database queries are automatically scoped to this tenant.|-|Optional|
15
+ |tablePrefix|[string \|undefined](https://v2.c15t.com/docs/self-host/guides/database-setup)|Optional prefix for all database table names. Useful when sharing a database with other applications to avoid naming conflicts.|-|Optional|
16
+ |appName|[string \|undefined](https://v2.c15t.com/docs/self-host/api/configuration)|Application name used as backend metadata and identity. Returned by \`/init\` (\`appName\`), used in logs, telemetry defaults (\`service.name\`), and cache key prefixing.|"c15t"|Optional|
17
+ |basePath|[string \|undefined](https://v2.c15t.com/docs/self-host/api/endpoints)|Base path prefix for all API routes (e.g. \`/api/self-host\`).|-|Optional|
18
+ |trustedOrigins|[string\[\]](https://v2.c15t.com/docs/self-host/api/configuration)|Allowed origins for CORS. Required for browser-based consent collection. Protocol is optional; matching is protocol-agnostic and normalized.|-|✅ Required|
19
+ |logger|LoggerOptions \|undefined|Logger configuration.|-|Optional|
20
+ |disableGeoLocation|boolean \|undefined|Disables the use of Geo Location to determine the jurisdiction. When enabled, the jurisdiction will be set to "GDPR" to show the strictest version of the banner as we don't know the jurisdiction in this case.|false|Optional|
21
+ |customTranslations|Record\<string, Partial\<Translations>> \|undefined|Override base translations.|-|Optional|
22
+ |i18n|I18nOptions \|undefined|Internationalization message profiles used by runtime policies.|-|Optional|
23
+ |policyPacks|[PolicyConfig \|undefined](https://v2.c15t.com/docs/self-host/guides/policy-packs)|Runtime regional policy pack resolved per request.|-|Optional|
24
+ |branding|"c15t" \|"consent" \|"none" \|undefined|Select which branding to show in the consent banner. Use "none" to hide branding.|"c15t"|Optional|
25
+ |openapi|[OpenAPIOptions \|undefined](https://v2.c15t.com/docs/self-host/api/endpoints)|OpenAPI spec generation and documentation UI options.|-|Optional|
26
+ |telemetry|[TelemetryOptions \|undefined](https://v2.c15t.com/docs/self-host/guides/observability)|OpenTelemetry configuration for tracing and metrics. Telemetry is opt-in and disabled by default. Users must provide their own SDK setup (Node, Bun, edge, etc.).|-|Optional|
27
+ |ipAddress|[IPAddressOptions \|undefined](https://v2.c15t.com/docs/self-host/api/configuration)|IP address tracking and masking options.|-|Optional|
28
+ |cache|[CacheOptions \|undefined](https://v2.c15t.com/docs/self-host/guides/caching)|Cache configuration for external persistent storage. Used for caching GVL and other data.|-|Optional|
29
+ |apiKeys|string\[] \|undefined|API keys for authenticated endpoints. Used for server-side endpoints like GET /subjects.|-|Optional|
30
+ |iab|[IABOptions \|undefined](https://v2.c15t.com/docs/self-host/guides/iab-tcf)|IAB TCF configuration including GVL, CMP registration, and custom vendors. Disabled by default - most users don't need IAB TCF. Set enabled: true to activate IAB support.|-|Optional|
31
+ |policySnapshot|PolicySnapshotOptions \|undefined|Optional signed policy snapshots used to keep /init and /subjects consistent.|-|Optional|
32
+ |background|BackgroundOptions \|undefined|Optional background task runner for non-critical side effects.|-|Optional|
33
+
34
+ #### `adapter` FumaDBAdapter
35
+
36
+ The database adapter to use.
37
+
38
+ |Property|Type|Description|Default|Required|
39
+ |:--|:--|:--|:--|:--:|
40
+ |name|string|Name of the adapter|-|✅ Required|
41
+ |generateSchema|Object \|undefined|Generate ORM schema based on FumaDB Schema|-|Optional|
42
+ |createMigrationEngine|((this: FumaDBAdapterContext) => Migrator) \|undefined|-|-|Optional|
43
+
44
+ #### `logger` LoggerOptions
45
+
46
+ Logger configuration.
47
+
48
+ |Property|Type|Description|Default|Required|
49
+ |:--|:--|:--|:--|:--:|
50
+ |disabled|boolean \|undefined|Whether logging is disabled.|-|Optional|
51
+ |level|"info" \|"warn" \|"error" \|"debug" \|undefined|The minimum log level to publish.|-|Optional|
52
+ |log|((level: LogLevel, message: string, ...args: unknown\[]) => void) \|undefined|Custom log handler function.|-|Optional|
53
+ |appName|string \|undefined|Custom application name to display in log messages.|-|Optional|
54
+ |getTraceContext|(() => TraceContext \|null) \|undefined|Optional callback to get trace context for log correlation.|-|Optional|
55
+
56
+ #### `i18n` I18nOptions
57
+
58
+ Internationalization message profiles used by runtime policies.
59
+
60
+ |Property|Type|Description|Default|Required|
61
+ |:--|:--|:--|:--|:--:|
62
+ |messages|I18nMessageProfiles \|undefined|Named translation catalogs grouped by profile.|-|Optional|
63
+ |defaultProfile|string \|undefined|Fallback profile used when a policy does not provide \`messageProfile\`.|-|Optional|
64
+
65
+ #### `policyPacks` PolicyConfig
66
+
67
+ Runtime regional policy pack resolved per request.
68
+
69
+ |Property|Type|Description|Default|Required|
70
+ |:--|:--|:--|:--|:--:|
71
+ |id|string|-|-|✅ Required|
72
+ |match|Object \|undefined|-|-|✅ Required|
73
+ |i18n|Object \|undefined|-|-|Optional|
74
+ |consent|Object \|undefined|-|-|Optional|
75
+ |ui|Object \|undefined|-|-|Optional|
76
+ |proof|Object \|undefined|-|-|Optional|
77
+
78
+ #### `policySnapshot` PolicySnapshotOptions
79
+
80
+ Optional signed policy snapshots used to keep /init and /subjects consistent.
81
+
82
+ |Property|Type|Description|Default|Required|
83
+ |:--|:--|:--|:--|:--:|
84
+ |signingKey|string|Secret used for signing and verifying policy snapshot tokens.|-|✅ Required|
85
+ |onValidationFailure|"reject" \|"resolve\_current" \|undefined|How writes should behave when snapshot validation fails.|-|Optional|
86
+ |issuer|string \|undefined|JWT issuer claim for snapshot tokens.|-|Optional|
87
+ |audience|string \|undefined|JWT audience claim for snapshot tokens. When omitted, c15t derives a default snapshot audience and scopes it per tenant.|-|Optional|
88
+ |ttlSeconds|number \|undefined|Snapshot token lifetime in seconds.|-|Optional|
89
+
90
+ #### `background` BackgroundOptions
91
+
92
+ Optional background task runner for non-critical side effects.
93
+
94
+ |Property|Type|Description|Default|Required|
95
+ |:--|:--|:--|:--|:--:|
96
+ |run|(task: () => Promise\<void>) => void|Executes non-critical tasks after the response path has completed.|-|✅ Required|
97
+
98
+ ### OpenAPIOptions
99
+
100
+ |Property|Type|Description|Default|Required|
101
+ |:--|:--|:--|:--|:--:|
102
+ |enabled|boolean \|undefined|Enable/disable OpenAPI spec generation|true|Optional|
103
+ |specPath|string \|undefined|Path to serve the OpenAPI JSON spec|"/spec.json"|Optional|
104
+ |docsPath|string \|undefined|Path to serve the API documentation UI|"/docs"|Optional|
105
+ |options|Object \|undefined|OpenAPI specification options|-|Optional|
106
+ |customUiTemplate|string \|undefined|Custom template for rendering the API documentation UI If provided, this will be used instead of the default Scalar UI|-|Optional|
107
+
108
+ #### `options`
109
+
110
+ OpenAPI specification options
111
+
112
+ |Property|Type|Description|Default|Required|
113
+ |:--|:--|:--|:--|:--:|
114
+ |info|Object \|undefined|-|-|Optional|
115
+ |servers|Array\<Object> \|undefined|-|-|Optional|
116
+ |security|Record\<string, string\[]>\[] \|undefined|-|-|Optional|
117
+
118
+ ### TelemetryOptions
119
+
120
+ |Property|Type|Description|Default|Required|
121
+ |:--|:--|:--|:--|:--:|
122
+ |enabled|boolean \|undefined|Enable telemetry (tracing and metrics). Must be explicitly set to true to activate.|false|Optional|
123
+ |tracer|Tracer \|undefined|User-provided tracer instance. Users should set up their own OpenTelemetry SDK and pass the tracer here.|-|Optional|
124
+ |meter|Meter \|undefined|User-provided meter instance for metrics. Users should set up their own OpenTelemetry SDK and pass the meter here.|-|Optional|
125
+ |defaultAttributes|Record\<string, string \|number \|boolean> \|undefined|Default attributes to include on all spans and metrics.|-|Optional|
126
+
127
+ ### IPAddressOptions
128
+
129
+ |Property|Type|Description|Default|Required|
130
+ |:--|:--|:--|:--|:--:|
131
+ |tracking|boolean \|undefined|Enable/disable IP address tracking. When disabled, all IP addresses will be stored as null.|true|Optional|
132
+ |masking|boolean \|undefined|Enable/disable IP address masking to reduce PII collection.|true|Optional|
133
+ |ipAddressHeaders|string\[] \|undefined|Override the default IP address headers used to extract client IP. Headers are checked in order, first match wins.|-|Optional|
134
+
135
+ ### CacheOptions
136
+
137
+ |Property|Type|Description|Default|Required|
138
+ |:--|:--|:--|:--|:--:|
139
+ |adapter|CacheAdapter \|undefined|External cache adapter (Redis, KV, etc.). If not provided, only in-memory cache is used.|-|Optional|
140
+
141
+ ### IABOptions
142
+
143
+ |Property|Type|Description|Default|Required|
144
+ |:--|:--|:--|:--|:--:|
145
+ |enabled|true|Enable IAB TCF support. When false or not provided, /init does not include IAB payload fields. When true, /init includes IAB payload only when IAB is active for the resolved request policy (or when no policies are configured).|-|✅ Required|
146
+ |cmpId|number \|undefined|CMP ID registered with IAB Europe. This is returned to clients via the /init endpoint so they can use the correct CMP identity in TC Strings. See List of registered CMPs: https\://iabeurope.eu/cmp-list/|-|Optional|
147
+ |bundled|Object \|undefined \|null|Bundled GVL translations by language code. These are checked first before any cache or fetch.|-|Optional|
148
+ |vendorIds|number\[] \|undefined|Vendor IDs to filter when fetching non-bundled languages. Reduces payload size.|-|Optional|
149
+ |endpoint|string \|undefined|Override the default GVL endpoint.|'https\://gvl.consent.io'|Optional|
150
+ |customVendors|Array\<Object> \|undefined|Custom vendors not registered with IAB. These are synced to the frontend via the /init endpoint.|-|Optional|
151
+
152
+ ## Return Value
153
+
154
+ `c15tInstance()` returns:
155
+
156
+ ```ts
157
+ interface C15TInstance {
158
+ /** Standard Fetch API handler */
159
+ handler: (request: Request) => Promise<Response>;
160
+
161
+ /** Resolved configuration */
162
+ options: C15TOptions;
163
+
164
+ /** Internal context (database, registry, logger) */
165
+ $context: C15TContext;
166
+
167
+ /** OpenAPI spec as JSON */
168
+ getOpenAPISpec: () => Promise<Record<string, unknown>>;
169
+
170
+ /** OpenAPI docs UI as HTML string */
171
+ getDocsUI: () => string;
172
+ }
173
+ ```
174
+
175
+ ## Edge Init Options
176
+
177
+ `c15tEdgeInit()` from `@c15t/backend/edge` accepts a subset of `C15TOptions` — only the fields needed for consent policy resolution without a database. See the [Edge Deployment guide](/docs/self-host/guides/edge-deployment) for usage.
178
+
179
+ ### C15TEdgeOptions
180
+
181
+ |Property|Type|Description|Default|Required|
182
+ |:--|:--|:--|:--|:--:|
183
+ |C15TEdgeOptions|C15TEdgeOptions|Type alias for C15TEdgeOptions|-|✅ Required|
184
+
185
+ ## defineConfig Helper
186
+
187
+ For type-safe configuration in a separate file:
188
+
189
+ ```ts title="c15t.config.ts"
190
+ import { defineConfig } from '@c15t/backend';
191
+
192
+ export default defineConfig({
193
+ adapter: kyselyAdapter(db),
194
+ trustedOrigins: ['https://example.com'],
195
+ // full autocomplete on all options here
196
+ });
197
+ ```
@@ -0,0 +1,211 @@
1
+ ---
2
+ title: API Endpoints
3
+ description: Full reference for every c15t consent backend endpoint.
4
+ ---
5
+ All endpoints are relative to your configured `basePath` (e.g. `/api/c15t`).
6
+
7
+ > ℹ️ **Info:**
8
+ > The backend auto-generates interactive API docs at \{basePath}/docs using your OpenAPI spec. Visit this URL in a browser to explore endpoints with a visual UI.
9
+
10
+ ## GET /init
11
+
12
+ Returns the initial consent state for a client. This is the first call made by the frontend SDKs.
13
+
14
+ **Response:**
15
+
16
+ ```json
17
+ {
18
+ "jurisdiction": "GDPR",
19
+ "location": {
20
+ "countryCode": "DE",
21
+ "regionCode": "BY"
22
+ },
23
+ "translations": {
24
+ "language": "de",
25
+ "translations": { "...": "..." }
26
+ },
27
+ "branding": "c15t",
28
+ "gvl": null
29
+ }
30
+ ```
31
+
32
+ |Field|Description|
33
+ |--|--|
34
+ |`jurisdiction`|Detected regulation (`GDPR`, `UK_GDPR`, `CCPA`, etc.)|
35
+ |`location`|Geo-location from IP address|
36
+ |`translations`|Server-side translations based on `Accept-Language`|
37
+ |`branding`|Branding configuration|
38
+ |`gvl`|Global Vendor List (if IAB TCF is enabled)|
39
+
40
+ ## GET /status
41
+
42
+ Health check endpoint. Returns server version and client info.
43
+
44
+ **Response:**
45
+
46
+ ```json
47
+ {
48
+ "version": "1.8.0",
49
+ "timestamp": "2026-02-11T12:00:00.000Z",
50
+ "client": {
51
+ "ip": "192.168.1.0",
52
+ "acceptLanguage": "en-US",
53
+ "userAgent": "Mozilla/5.0 ...",
54
+ "region": { "countryCode": "US", "regionCode": "CA" }
55
+ }
56
+ }
57
+ ```
58
+
59
+ ## POST /subjects
60
+
61
+ Records a consent event. This is an append-only operation — every call creates a new consent record.
62
+
63
+ **Request:**
64
+
65
+ ```json
66
+ {
67
+ "type": "cookie_banner",
68
+ "subjectId": "sub_abc123",
69
+ "domain": "example.com",
70
+ "preferences": {
71
+ "necessary": true,
72
+ "measurement": true,
73
+ "marketing": false
74
+ },
75
+ "givenAt": 1707648000000,
76
+ "metadata": {}
77
+ }
78
+ ```
79
+
80
+ |Field|Type|Required|Description|
81
+ |--|--|--|--|
82
+ |`type`|string|Yes|`cookie_banner`, `privacy_policy`, `dpa`, `terms_and_conditions`, `marketing_communications`, `age_verification`, `other`|
83
+ |`subjectId`|string|Yes|Client-generated subject identifier|
84
+ |`domain`|string|Yes|Domain where consent was given|
85
+ |`preferences`|object|No|Consent category preferences (for `cookie_banner` type)|
86
+ |`givenAt`|number|Yes|Epoch timestamp|
87
+ |`policyId`|string|No|Associated policy ID|
88
+ |`metadata`|object|No|Arbitrary metadata|
89
+ |`externalSubjectId`|string|No|External user ID for cross-device linking|
90
+ |`identityProvider`|string|No|Identity provider name|
91
+
92
+ **Response:**
93
+
94
+ ```json
95
+ {
96
+ "subject": { "id": "sub_abc123", "...": "..." },
97
+ "consent": { "id": "con_xyz789", "type": "cookie_banner", "...": "..." }
98
+ }
99
+ ```
100
+
101
+ ## GET /subjects/:id
102
+
103
+ Retrieves consent status for a subject.
104
+
105
+ **Query Parameters:**
106
+
107
+ |Parameter|Description|
108
+ |--|--|
109
+ |`type`|Comma-separated consent types to filter (e.g. `cookie_banner,privacy_policy`)|
110
+
111
+ **Response:**
112
+
113
+ ```json
114
+ {
115
+ "subject": { "id": "sub_abc123" },
116
+ "consents": [
117
+ {
118
+ "id": "con_xyz789",
119
+ "type": "cookie_banner",
120
+ "givenAt": "2026-02-11T12:00:00.000Z",
121
+ "jurisdiction": "GDPR",
122
+ "preferences": { "necessary": true, "measurement": true }
123
+ }
124
+ ],
125
+ "isValid": true
126
+ }
127
+ ```
128
+
129
+ ## PATCH /subjects/:id
130
+
131
+ Links a subject to an external user ID for cross-device consent resolution.
132
+
133
+ **Request:**
134
+
135
+ ```json
136
+ {
137
+ "externalId": "user_12345",
138
+ "identityProvider": "auth0"
139
+ }
140
+ ```
141
+
142
+ **Response:**
143
+
144
+ ```json
145
+ {
146
+ "subject": {
147
+ "id": "sub_abc123",
148
+ "externalId": "user_12345",
149
+ "identityProvider": "auth0"
150
+ }
151
+ }
152
+ ```
153
+
154
+ ## GET /consents/check
155
+
156
+ Check consent status by external ID — useful for cross-device consent resolution.
157
+
158
+ **Query Parameters:**
159
+
160
+ |Parameter|Description|
161
+ |--|--|
162
+ |`externalId`|The external user ID to look up|
163
+ |`type`|Comma-separated consent types|
164
+
165
+ **Response:**
166
+
167
+ ```json
168
+ {
169
+ "found": true,
170
+ "consents": [
171
+ { "id": "con_xyz789", "type": "cookie_banner", "...": "..." }
172
+ ]
173
+ }
174
+ ```
175
+
176
+ ## GET /subjects (Authenticated)
177
+
178
+ List subjects by external ID. Requires an API key.
179
+
180
+ **Headers:**
181
+
182
+ ```
183
+ Authorization: Bearer sk_live_abc123
184
+ ```
185
+
186
+ **Query Parameters:**
187
+
188
+ |Parameter|Description|
189
+ |--|--|
190
+ |`externalId`|The external user ID to search|
191
+
192
+ **Response:**
193
+
194
+ ```json
195
+ {
196
+ "subjects": [
197
+ { "id": "sub_abc123", "externalId": "user_12345" }
198
+ ]
199
+ }
200
+ ```
201
+
202
+ > ℹ️ **Info:**
203
+ > This endpoint requires API key authentication. Configure API keys in the apiKeys option. The key is passed via the Authorization: Bearer header using timing-safe comparison.
204
+
205
+ ## GET /spec.json
206
+
207
+ Returns the OpenAPI 3.1 specification for the consent API.
208
+
209
+ ## GET /docs
210
+
211
+ Serves the interactive API documentation UI (Scalar).
@@ -0,0 +1,85 @@
1
+ ---
2
+ title: Caching
3
+ description: Add a caching layer to your self-hosted c15t backend for production performance.
4
+ ---
5
+ The backend includes a caching layer for frequently accessed data like GVL (Global Vendor List) lookups and custom server-side translations. By default, an in-memory cache is used — suitable for single-instance deployments. For production with multiple instances, plug in Redis or Cloudflare KV so all instances share the same cache.
6
+
7
+ ## In-Memory (Default)
8
+
9
+ No configuration needed. The default memory cache has a 5-minute TTL and is suitable for development and single-instance deployments.
10
+
11
+ ## Upstash Redis
12
+
13
+ ```ts title="c15t.ts"
14
+ import { c15tInstance } from '@c15t/backend';
15
+ import { createUpstashRedisAdapter } from '@c15t/backend/cache';
16
+
17
+ export const c15t = c15tInstance({
18
+ // ...
19
+ cache: {
20
+ adapter: createUpstashRedisAdapter({
21
+ url: process.env.UPSTASH_REDIS_REST_URL,
22
+ token: process.env.UPSTASH_REDIS_REST_TOKEN,
23
+ }),
24
+ },
25
+ });
26
+ ```
27
+
28
+ If you already have an Upstash Redis client, pass it directly:
29
+
30
+ ```ts
31
+ import { createUpstashRedisAdapterFromClient } from '@c15t/backend/cache';
32
+ import { Redis } from '@upstash/redis';
33
+
34
+ const redis = new Redis({
35
+ url: process.env.UPSTASH_REDIS_REST_URL,
36
+ token: process.env.UPSTASH_REDIS_REST_TOKEN,
37
+ });
38
+
39
+ const adapter = createUpstashRedisAdapterFromClient(redis);
40
+ ```
41
+
42
+ ## Cloudflare KV
43
+
44
+ For Cloudflare Workers deployments:
45
+
46
+ ```ts title="worker.ts"
47
+ import { c15tInstance } from '@c15t/backend';
48
+ import { createCloudflareKVAdapter } from '@c15t/backend/cache';
49
+
50
+ export default {
51
+ async fetch(request: Request, env: Env) {
52
+ const c15t = c15tInstance({
53
+ // ...
54
+ cache: {
55
+ adapter: createCloudflareKVAdapter(env.GVL_CACHE),
56
+ },
57
+ });
58
+
59
+ return c15t.handler(request);
60
+ },
61
+ };
62
+ ```
63
+
64
+ ## Custom Cache Adapter
65
+
66
+ Implement the `CacheAdapter` interface to use any cache backend:
67
+
68
+ ```ts
69
+ import type { CacheAdapter } from '@c15t/backend/cache';
70
+
71
+ const customCache: CacheAdapter = {
72
+ async get<T>(key: string): Promise<T | null> {
73
+ // retrieve from your cache
74
+ },
75
+ async set<T>(key: string, value: T, ttlMs?: number): Promise<void> {
76
+ // store in your cache
77
+ },
78
+ async delete(key: string): Promise<void> {
79
+ // remove from cache
80
+ },
81
+ async has(key: string): Promise<boolean> {
82
+ // check existence
83
+ },
84
+ };
85
+ ```
@@ -0,0 +1,128 @@
1
+ ---
2
+ title: Database Setup
3
+ description: Configure a database adapter for your self-hosted c15t backend.
4
+ ---
5
+ The c15t backend requires a database to store consent records, subjects, audit logs, and policies. Five adapters are supported — choose the one that matches your existing stack.
6
+
7
+ ## Adapters
8
+
9
+ ### Kysely
10
+
11
+ ```ts title="c15t.ts"
12
+ import { c15tInstance } from '@c15t/backend';
13
+ import { kyselyAdapter } from '@c15t/backend/db/adapters/kysely';
14
+ import { Kysely, PostgresDialect } from 'kysely';
15
+ import { Pool } from 'pg';
16
+
17
+ const db = new Kysely({
18
+ dialect: new PostgresDialect({
19
+ pool: new Pool({ connectionString: process.env.DATABASE_URL }),
20
+ }),
21
+ });
22
+
23
+ export const c15t = c15tInstance({
24
+ adapter: kyselyAdapter(db),
25
+ trustedOrigins: ['https://example.com'],
26
+ });
27
+ ```
28
+
29
+ ### Drizzle
30
+
31
+ ```ts title="c15t.ts"
32
+ import { c15tInstance } from '@c15t/backend';
33
+ import { drizzleAdapter } from '@c15t/backend/db/adapters/drizzle';
34
+ import { drizzle } from 'drizzle-orm/node-postgres';
35
+
36
+ const db = drizzle(process.env.DATABASE_URL);
37
+
38
+ export const c15t = c15tInstance({
39
+ adapter: drizzleAdapter(db),
40
+ trustedOrigins: ['https://example.com'],
41
+ });
42
+ ```
43
+
44
+ ### Prisma
45
+
46
+ ```ts title="c15t.ts"
47
+ import { c15tInstance } from '@c15t/backend';
48
+ import { prismaAdapter } from '@c15t/backend/db/adapters/prisma';
49
+ import { PrismaClient } from '@prisma/client';
50
+
51
+ const prisma = new PrismaClient();
52
+
53
+ export const c15t = c15tInstance({
54
+ adapter: prismaAdapter(prisma),
55
+ trustedOrigins: ['https://example.com'],
56
+ });
57
+ ```
58
+
59
+ ### TypeORM
60
+
61
+ ```ts title="c15t.ts"
62
+ import { c15tInstance } from '@c15t/backend';
63
+ import { typeormAdapter } from '@c15t/backend/db/adapters/typeorm';
64
+ import { DataSource } from 'typeorm';
65
+
66
+ const dataSource = new DataSource({
67
+ type: 'postgres',
68
+ url: process.env.DATABASE_URL,
69
+ });
70
+
71
+ export const c15t = c15tInstance({
72
+ adapter: typeormAdapter(dataSource),
73
+ trustedOrigins: ['https://example.com'],
74
+ });
75
+ ```
76
+
77
+ ### MongoDB
78
+
79
+ ```ts title="c15t.ts"
80
+ import { c15tInstance } from '@c15t/backend';
81
+ import { mongoAdapter } from '@c15t/backend/db/adapters/mongo';
82
+ import { MongoClient } from 'mongodb';
83
+
84
+ const client = new MongoClient(process.env.MONGODB_URI);
85
+
86
+ export const c15t = c15tInstance({
87
+ adapter: mongoAdapter(client),
88
+ trustedOrigins: ['https://example.com'],
89
+ });
90
+ ```
91
+
92
+ ## Migrations
93
+
94
+ To create & update the database you can use the migrator which is included in the CLI:
95
+
96
+ |Package manager|Command|
97
+ |:--|:--|
98
+ |npm|`npx @c15t/cli@rc`|
99
+ |pnpm|`pnpm dlx @c15t/cli@rc`|
100
+ |yarn|`yarn dlx @c15t/cli@rc`|
101
+ |bun|`bunx @c15t/cli@rc`|
102
+
103
+ ## Table Prefix
104
+
105
+ If you share a database with other applications, use `tablePrefix` to namespace the c15t tables:
106
+
107
+ ```ts
108
+ c15tInstance({
109
+ adapter: kyselyAdapter(db),
110
+ tablePrefix: 'c15t_',
111
+ trustedOrigins: ['https://example.com'],
112
+ });
113
+ ```
114
+
115
+ This prefixes all table names (e.g. `c15t_subject`, `c15t_consent`, `c15t_audit_log`).
116
+
117
+ ## Schema Overview
118
+
119
+ The backend creates and manages these tables:
120
+
121
+ |Table|Purpose|
122
+ |--|--|
123
+ |`subject`|Consent subjects (users/devices). Tracks identification status and external IDs.|
124
+ |`consent`|Append-only consent records. Stores preferences, jurisdiction, IP, and timestamps.|
125
+ |`domain`|Domain/website configuration for multi-domain setups.|
126
+ |`consent_policy`|Versioned consent policies.|
127
+ |`consent_purpose`|Maps consent purposes to categories.|
128
+ |`audit_log`|Immutable log of all consent-related actions.|