@c15t/backend 2.0.0-rc.4 → 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 (308) hide show
  1. package/dist/core.cjs +830 -74
  2. package/dist/core.js +807 -75
  3. package/dist/db/schema.cjs +37 -0
  4. package/dist/db/schema.js +33 -2
  5. package/dist/edge.cjs +1106 -0
  6. package/dist/edge.js +1069 -0
  7. package/dist/router.cjs +613 -64
  8. package/dist/router.js +613 -64
  9. package/{dist → dist-types}/cache/adapters/cloudflare-kv.d.ts +0 -1
  10. package/{dist → dist-types}/cache/adapters/index.d.ts +0 -1
  11. package/{dist → dist-types}/cache/adapters/memory.d.ts +0 -1
  12. package/{dist → dist-types}/cache/adapters/upstash-redis.d.ts +0 -1
  13. package/{dist → dist-types}/cache/gvl-resolver.d.ts +1 -2
  14. package/{dist → dist-types}/cache/index.d.ts +0 -1
  15. package/{dist → dist-types}/cache/keys.d.ts +0 -1
  16. package/{dist → dist-types}/cache/types.d.ts +0 -1
  17. package/{dist → dist-types}/core.d.ts +8 -1
  18. package/{dist → dist-types}/db/migrator/index.d.ts +0 -1
  19. package/{dist → dist-types}/db/registry/consent-policy.d.ts +0 -1
  20. package/{dist → dist-types}/db/registry/consent-purpose.d.ts +0 -1
  21. package/{dist → dist-types}/db/registry/domain.d.ts +0 -1
  22. package/{dist → dist-types}/db/registry/index.d.ts +22 -2
  23. package/dist-types/db/registry/runtime-policy-decision.d.ts +60 -0
  24. package/{dist → dist-types}/db/registry/subject.d.ts +0 -1
  25. package/{dist → dist-types}/db/registry/types.d.ts +1 -2
  26. package/{dist → dist-types}/db/registry/utils/generate-id.d.ts +0 -1
  27. package/{dist → dist-types}/db/registry/utils.d.ts +0 -1
  28. package/{dist → dist-types}/db/schema/1.0.0/audit-log.d.ts +0 -1
  29. package/{dist → dist-types}/db/schema/1.0.0/consent-policy.d.ts +0 -1
  30. package/{dist → dist-types}/db/schema/1.0.0/consent-purpose.d.ts +0 -1
  31. package/{dist → dist-types}/db/schema/1.0.0/consent-record.d.ts +0 -1
  32. package/{dist → dist-types}/db/schema/1.0.0/consent.d.ts +1 -2
  33. package/{dist → dist-types}/db/schema/1.0.0/domain.d.ts +0 -1
  34. package/{dist → dist-types}/db/schema/1.0.0/index.d.ts +0 -1
  35. package/{dist → dist-types}/db/schema/1.0.0/subject.d.ts +0 -1
  36. package/{dist → dist-types}/db/schema/2.0.0/audit-log.d.ts +1 -2
  37. package/{dist → dist-types}/db/schema/2.0.0/consent-policy.d.ts +1 -2
  38. package/{dist → dist-types}/db/schema/2.0.0/consent-purpose.d.ts +1 -2
  39. package/{dist → dist-types}/db/schema/2.0.0/consent.d.ts +5 -2
  40. package/{dist → dist-types}/db/schema/2.0.0/domain.d.ts +1 -2
  41. package/{dist → dist-types}/db/schema/2.0.0/index.d.ts +432 -17
  42. package/dist-types/db/schema/2.0.0/runtime-policy-decision.d.ts +23 -0
  43. package/{dist → dist-types}/db/schema/2.0.0/subject.d.ts +1 -2
  44. package/{dist → dist-types}/db/schema/index.d.ts +862 -33
  45. package/{dist → dist-types}/db/tenant-scope.d.ts +0 -1
  46. package/{dist → dist-types}/define-config.d.ts +0 -1
  47. package/dist-types/edge/index.d.ts +5 -0
  48. package/dist-types/edge/init-handler.d.ts +38 -0
  49. package/dist-types/edge/resolve-consent.d.ts +80 -0
  50. package/dist-types/edge/types.d.ts +13 -0
  51. package/{dist → dist-types}/handlers/consent/check.handler.d.ts +0 -1
  52. package/{src/handlers/consent/index.ts → dist-types/handlers/consent/index.d.ts} +0 -1
  53. package/{dist → dist-types}/handlers/init/geo.d.ts +2 -3
  54. package/{dist → dist-types}/handlers/init/index.d.ts +4 -5
  55. package/dist-types/handlers/init/policy.d.ts +26 -0
  56. package/dist-types/handlers/init/resolve-init.d.ts +44 -0
  57. package/dist-types/handlers/init/translations.d.ts +48 -0
  58. package/dist-types/handlers/policy/snapshot.d.ts +99 -0
  59. package/{src/handlers/status/index.ts → dist-types/handlers/status/index.d.ts} +0 -1
  60. package/{dist → dist-types}/handlers/status/status.handler.d.ts +0 -1
  61. package/{dist → dist-types}/handlers/subject/get.handler.d.ts +0 -1
  62. package/{src/handlers/subject/index.ts → dist-types/handlers/subject/index.d.ts} +0 -1
  63. package/{dist → dist-types}/handlers/subject/list.handler.d.ts +0 -1
  64. package/{dist → dist-types}/handlers/subject/patch.handler.d.ts +0 -1
  65. package/{dist → dist-types}/handlers/subject/post.handler.d.ts +12 -1
  66. package/{dist → dist-types}/handlers/utils/consent-enrichment.d.ts +0 -1
  67. package/{dist → dist-types}/init.d.ts +0 -1
  68. package/{dist → dist-types}/middleware/auth/index.d.ts +0 -1
  69. package/{dist → dist-types}/middleware/auth/validate-api-key.d.ts +0 -1
  70. package/{dist → dist-types}/middleware/cors/cors.d.ts +0 -1
  71. package/{src/middleware/cors/index.ts → dist-types/middleware/cors/index.d.ts} +0 -1
  72. package/{dist → dist-types}/middleware/cors/is-origin-trusted.d.ts +1 -2
  73. package/{dist → dist-types}/middleware/cors/process-cors.d.ts +0 -1
  74. package/{dist → dist-types}/middleware/openapi/config.d.ts +0 -1
  75. package/{dist → dist-types}/middleware/openapi/handlers.d.ts +0 -1
  76. package/{src/middleware/openapi/index.ts → dist-types/middleware/openapi/index.d.ts} +0 -1
  77. package/{dist → dist-types}/middleware/process-ip/index.d.ts +0 -1
  78. package/dist-types/policies/builder.d.ts +127 -0
  79. package/dist-types/policies/defaults.d.ts +2 -0
  80. package/dist-types/policies/matchers.d.ts +3 -0
  81. package/{dist → dist-types}/router.d.ts +0 -1
  82. package/{dist → dist-types}/routes/consent.d.ts +0 -1
  83. package/{src/routes/index.ts → dist-types/routes/index.d.ts} +0 -1
  84. package/{dist → dist-types}/routes/init.d.ts +0 -1
  85. package/{dist → dist-types}/routes/status.d.ts +0 -1
  86. package/{dist → dist-types}/routes/subject.d.ts +0 -1
  87. package/{dist → dist-types}/types/api.d.ts +0 -1
  88. package/{dist → dist-types}/types/index.d.ts +110 -6
  89. package/dist-types/utils/background.d.ts +6 -0
  90. package/{dist → dist-types}/utils/create-telemetry-options.d.ts +0 -1
  91. package/{dist → dist-types}/utils/env.d.ts +0 -1
  92. package/{dist → dist-types}/utils/extract-error-message.d.ts +0 -1
  93. package/{dist → dist-types}/utils/instrumentation.d.ts +0 -1
  94. package/{dist → dist-types}/utils/logger.d.ts +1 -2
  95. package/{dist → dist-types}/utils/metrics.d.ts +0 -1
  96. package/dist-types/version.d.ts +1 -0
  97. package/docs/README.md +49 -0
  98. package/docs/api/configuration.md +197 -0
  99. package/docs/api/endpoints.md +211 -0
  100. package/docs/guides/caching.md +85 -0
  101. package/docs/guides/database-setup.md +128 -0
  102. package/docs/guides/edge-deployment.md +248 -0
  103. package/docs/guides/framework-integration.md +142 -0
  104. package/docs/guides/iab-tcf.md +89 -0
  105. package/docs/guides/observability.md +96 -0
  106. package/docs/guides/policy-packs.md +396 -0
  107. package/docs/quickstart.md +129 -0
  108. package/package.json +33 -19
  109. package/.turbo/turbo-build.log +0 -49
  110. package/CHANGELOG.md +0 -123
  111. package/dist/cache/adapters/cloudflare-kv.d.ts.map +0 -1
  112. package/dist/cache/adapters/index.d.ts.map +0 -1
  113. package/dist/cache/adapters/memory.d.ts.map +0 -1
  114. package/dist/cache/adapters/upstash-redis.d.ts.map +0 -1
  115. package/dist/cache/gvl-resolver.d.ts.map +0 -1
  116. package/dist/cache/index.d.ts.map +0 -1
  117. package/dist/cache/keys.d.ts.map +0 -1
  118. package/dist/cache/types.d.ts.map +0 -1
  119. package/dist/core.d.ts.map +0 -1
  120. package/dist/db/adapters/drizzle.d.ts +0 -2
  121. package/dist/db/adapters/drizzle.d.ts.map +0 -1
  122. package/dist/db/adapters/index.d.ts +0 -2
  123. package/dist/db/adapters/index.d.ts.map +0 -1
  124. package/dist/db/adapters/kysely.d.ts +0 -2
  125. package/dist/db/adapters/kysely.d.ts.map +0 -1
  126. package/dist/db/adapters/mongo.d.ts +0 -2
  127. package/dist/db/adapters/mongo.d.ts.map +0 -1
  128. package/dist/db/adapters/prisma.d.ts +0 -2
  129. package/dist/db/adapters/prisma.d.ts.map +0 -1
  130. package/dist/db/adapters/typeorm.d.ts +0 -2
  131. package/dist/db/adapters/typeorm.d.ts.map +0 -1
  132. package/dist/db/migrator/index.d.ts.map +0 -1
  133. package/dist/db/registry/consent-policy.d.ts.map +0 -1
  134. package/dist/db/registry/consent-purpose.d.ts.map +0 -1
  135. package/dist/db/registry/domain.d.ts.map +0 -1
  136. package/dist/db/registry/index.d.ts.map +0 -1
  137. package/dist/db/registry/subject.d.ts.map +0 -1
  138. package/dist/db/registry/types.d.ts.map +0 -1
  139. package/dist/db/registry/utils/generate-id.d.ts.map +0 -1
  140. package/dist/db/registry/utils.d.ts.map +0 -1
  141. package/dist/db/schema/1.0.0/audit-log.d.ts.map +0 -1
  142. package/dist/db/schema/1.0.0/consent-policy.d.ts.map +0 -1
  143. package/dist/db/schema/1.0.0/consent-purpose.d.ts.map +0 -1
  144. package/dist/db/schema/1.0.0/consent-record.d.ts.map +0 -1
  145. package/dist/db/schema/1.0.0/consent.d.ts.map +0 -1
  146. package/dist/db/schema/1.0.0/domain.d.ts.map +0 -1
  147. package/dist/db/schema/1.0.0/index.d.ts.map +0 -1
  148. package/dist/db/schema/1.0.0/subject.d.ts.map +0 -1
  149. package/dist/db/schema/2.0.0/audit-log.d.ts.map +0 -1
  150. package/dist/db/schema/2.0.0/consent-policy.d.ts.map +0 -1
  151. package/dist/db/schema/2.0.0/consent-purpose.d.ts.map +0 -1
  152. package/dist/db/schema/2.0.0/consent.d.ts.map +0 -1
  153. package/dist/db/schema/2.0.0/domain.d.ts.map +0 -1
  154. package/dist/db/schema/2.0.0/index.d.ts.map +0 -1
  155. package/dist/db/schema/2.0.0/subject.d.ts.map +0 -1
  156. package/dist/db/schema/index.d.ts.map +0 -1
  157. package/dist/db/tenant-scope.d.ts.map +0 -1
  158. package/dist/define-config.d.ts.map +0 -1
  159. package/dist/handlers/consent/check.handler.d.ts.map +0 -1
  160. package/dist/handlers/consent/index.d.ts +0 -12
  161. package/dist/handlers/consent/index.d.ts.map +0 -1
  162. package/dist/handlers/init/geo.d.ts.map +0 -1
  163. package/dist/handlers/init/index.d.ts.map +0 -1
  164. package/dist/handlers/init/translations.d.ts +0 -26
  165. package/dist/handlers/init/translations.d.ts.map +0 -1
  166. package/dist/handlers/status/index.d.ts +0 -7
  167. package/dist/handlers/status/index.d.ts.map +0 -1
  168. package/dist/handlers/status/status.handler.d.ts.map +0 -1
  169. package/dist/handlers/subject/get.handler.d.ts.map +0 -1
  170. package/dist/handlers/subject/index.d.ts +0 -10
  171. package/dist/handlers/subject/index.d.ts.map +0 -1
  172. package/dist/handlers/subject/list.handler.d.ts.map +0 -1
  173. package/dist/handlers/subject/patch.handler.d.ts.map +0 -1
  174. package/dist/handlers/subject/post.handler.d.ts.map +0 -1
  175. package/dist/handlers/utils/consent-enrichment.d.ts.map +0 -1
  176. package/dist/init.d.ts.map +0 -1
  177. package/dist/middleware/auth/index.d.ts.map +0 -1
  178. package/dist/middleware/auth/validate-api-key.d.ts.map +0 -1
  179. package/dist/middleware/cors/cors.d.ts.map +0 -1
  180. package/dist/middleware/cors/index.d.ts +0 -30
  181. package/dist/middleware/cors/index.d.ts.map +0 -1
  182. package/dist/middleware/cors/is-origin-trusted.d.ts.map +0 -1
  183. package/dist/middleware/cors/process-cors.d.ts.map +0 -1
  184. package/dist/middleware/openapi/config.d.ts.map +0 -1
  185. package/dist/middleware/openapi/handlers.d.ts.map +0 -1
  186. package/dist/middleware/openapi/index.d.ts +0 -12
  187. package/dist/middleware/openapi/index.d.ts.map +0 -1
  188. package/dist/middleware/process-ip/index.d.ts.map +0 -1
  189. package/dist/router.d.ts.map +0 -1
  190. package/dist/routes/consent.d.ts.map +0 -1
  191. package/dist/routes/index.d.ts +0 -10
  192. package/dist/routes/index.d.ts.map +0 -1
  193. package/dist/routes/init.d.ts.map +0 -1
  194. package/dist/routes/status.d.ts.map +0 -1
  195. package/dist/routes/subject.d.ts.map +0 -1
  196. package/dist/types/api.d.ts.map +0 -1
  197. package/dist/types/index.d.ts.map +0 -1
  198. package/dist/utils/create-telemetry-options.d.ts.map +0 -1
  199. package/dist/utils/env.d.ts.map +0 -1
  200. package/dist/utils/extract-error-message.d.ts.map +0 -1
  201. package/dist/utils/index.d.ts +0 -4
  202. package/dist/utils/index.d.ts.map +0 -1
  203. package/dist/utils/instrumentation.d.ts.map +0 -1
  204. package/dist/utils/logger.d.ts.map +0 -1
  205. package/dist/utils/metrics.d.ts.map +0 -1
  206. package/dist/version.d.ts +0 -2
  207. package/dist/version.d.ts.map +0 -1
  208. package/knip.json +0 -31
  209. package/rslib.config.ts +0 -93
  210. package/src/cache/adapters/cloudflare-kv.ts +0 -71
  211. package/src/cache/adapters/index.ts +0 -22
  212. package/src/cache/adapters/memory.ts +0 -111
  213. package/src/cache/adapters/upstash-redis.ts +0 -113
  214. package/src/cache/gvl-resolver.ts +0 -289
  215. package/src/cache/index.ts +0 -34
  216. package/src/cache/keys.ts +0 -68
  217. package/src/cache/types.ts +0 -66
  218. package/src/core.ts +0 -369
  219. package/src/db/migrator/index.ts +0 -80
  220. package/src/db/registry/consent-policy.test.ts +0 -451
  221. package/src/db/registry/consent-policy.ts +0 -82
  222. package/src/db/registry/consent-purpose.test.ts +0 -428
  223. package/src/db/registry/consent-purpose.ts +0 -61
  224. package/src/db/registry/domain.test.ts +0 -445
  225. package/src/db/registry/domain.ts +0 -91
  226. package/src/db/registry/index.ts +0 -14
  227. package/src/db/registry/subject.test.ts +0 -371
  228. package/src/db/registry/subject.ts +0 -126
  229. package/src/db/registry/types.ts +0 -10
  230. package/src/db/registry/utils/generate-id.test.ts +0 -216
  231. package/src/db/registry/utils/generate-id.ts +0 -133
  232. package/src/db/registry/utils.ts +0 -133
  233. package/src/db/schema/1.0.0/audit-log.ts +0 -15
  234. package/src/db/schema/1.0.0/consent-policy.ts +0 -14
  235. package/src/db/schema/1.0.0/consent-purpose.ts +0 -14
  236. package/src/db/schema/1.0.0/consent-record.ts +0 -10
  237. package/src/db/schema/1.0.0/consent.ts +0 -20
  238. package/src/db/schema/1.0.0/domain.ts +0 -12
  239. package/src/db/schema/1.0.0/index.ts +0 -48
  240. package/src/db/schema/1.0.0/subject.ts +0 -11
  241. package/src/db/schema/2.0.0/audit-log.ts +0 -18
  242. package/src/db/schema/2.0.0/consent-policy.ts +0 -28
  243. package/src/db/schema/2.0.0/consent-purpose.ts +0 -12
  244. package/src/db/schema/2.0.0/consent.ts +0 -28
  245. package/src/db/schema/2.0.0/domain.ts +0 -12
  246. package/src/db/schema/2.0.0/index.ts +0 -47
  247. package/src/db/schema/2.0.0/subject.ts +0 -13
  248. package/src/db/schema/index.ts +0 -15
  249. package/src/db/tenant-scope.test.ts +0 -747
  250. package/src/db/tenant-scope.ts +0 -103
  251. package/src/define-config.ts +0 -19
  252. package/src/handlers/consent/check.handler.ts +0 -126
  253. package/src/handlers/init/geo.test.ts +0 -317
  254. package/src/handlers/init/geo.ts +0 -195
  255. package/src/handlers/init/index.test.ts +0 -205
  256. package/src/handlers/init/index.ts +0 -114
  257. package/src/handlers/init/translations.test.ts +0 -121
  258. package/src/handlers/init/translations.ts +0 -69
  259. package/src/handlers/status/status.handler.test.ts +0 -155
  260. package/src/handlers/status/status.handler.ts +0 -51
  261. package/src/handlers/subject/get.handler.ts +0 -92
  262. package/src/handlers/subject/list.handler.ts +0 -92
  263. package/src/handlers/subject/patch.handler.ts +0 -119
  264. package/src/handlers/subject/post.handler.test.ts +0 -294
  265. package/src/handlers/subject/post.handler.ts +0 -268
  266. package/src/handlers/utils/consent-enrichment.test.ts +0 -380
  267. package/src/handlers/utils/consent-enrichment.ts +0 -218
  268. package/src/init.test.ts +0 -122
  269. package/src/init.ts +0 -88
  270. package/src/middleware/auth/index.ts +0 -11
  271. package/src/middleware/auth/validate-api-key.test.ts +0 -86
  272. package/src/middleware/auth/validate-api-key.ts +0 -107
  273. package/src/middleware/cors/cors.test.ts +0 -135
  274. package/src/middleware/cors/cors.ts +0 -186
  275. package/src/middleware/cors/is-origin-trusted.test.ts +0 -164
  276. package/src/middleware/cors/is-origin-trusted.ts +0 -130
  277. package/src/middleware/cors/process-cors.ts +0 -91
  278. package/src/middleware/openapi/config.ts +0 -29
  279. package/src/middleware/openapi/handlers.ts +0 -34
  280. package/src/middleware/process-ip/index.test.ts +0 -193
  281. package/src/middleware/process-ip/index.ts +0 -199
  282. package/src/router.ts +0 -15
  283. package/src/routes/consent.ts +0 -52
  284. package/src/routes/init.ts +0 -105
  285. package/src/routes/status.ts +0 -46
  286. package/src/routes/subject.ts +0 -152
  287. package/src/types/api.ts +0 -48
  288. package/src/types/index.ts +0 -391
  289. package/src/utils/create-telemetry-options.test.ts +0 -286
  290. package/src/utils/create-telemetry-options.ts +0 -229
  291. package/src/utils/env.ts +0 -84
  292. package/src/utils/extract-error-message.ts +0 -21
  293. package/src/utils/instrumentation.test.ts +0 -183
  294. package/src/utils/instrumentation.ts +0 -194
  295. package/src/utils/logger.ts +0 -41
  296. package/src/utils/metrics.test.ts +0 -311
  297. package/src/utils/metrics.ts +0 -402
  298. package/src/utils/telemetry-pii.test.ts +0 -323
  299. package/src/version.ts +0 -2
  300. package/tsconfig.json +0 -11
  301. package/vitest.config.ts +0 -28
  302. /package/{src/db/adapters/drizzle.ts → dist-types/db/adapters/drizzle.d.ts} +0 -0
  303. /package/{src/db/adapters/index.ts → dist-types/db/adapters/index.d.ts} +0 -0
  304. /package/{src/db/adapters/kysely.ts → dist-types/db/adapters/kysely.d.ts} +0 -0
  305. /package/{src/db/adapters/mongo.ts → dist-types/db/adapters/mongo.d.ts} +0 -0
  306. /package/{src/db/adapters/prisma.ts → dist-types/db/adapters/prisma.d.ts} +0 -0
  307. /package/{src/db/adapters/typeorm.ts → dist-types/db/adapters/typeorm.d.ts} +0 -0
  308. /package/{src/utils/index.ts → dist-types/utils/index.d.ts} +0 -0
@@ -1,216 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
- import type { InferFumaDB } from 'fumadb';
3
- import { afterEach, describe, expect, it, vi } from 'vitest';
4
- import type { LatestDB } from '~/db/schema';
5
- import { generateUniqueId } from './generate-id';
6
-
7
- type MockDB = ReturnType<InferFumaDB<typeof LatestDB>['orm']>;
8
-
9
- // Define regex patterns at the top level for performance
10
- const SUBJECT_ID_PATTERN = /^sub_[A-Za-z0-9]+$/;
11
- const CONSENT_ID_PATTERN = /^cns_[A-Za-z0-9]+$/;
12
- const DOMAIN_ID_PATTERN = /^dom_[A-Za-z0-9]+$/;
13
-
14
- describe('generateUniqueId', () => {
15
- afterEach(() => {
16
- vi.clearAllMocks();
17
- });
18
-
19
- // Ensure crypto.getRandomValues exists in Node/Vitest environments
20
- // that may not provide a Web Crypto global by default.
21
- if (
22
- !(globalThis as { crypto?: { getRandomValues?: unknown } }).crypto
23
- ?.getRandomValues
24
- ) {
25
- (
26
- globalThis as {
27
- crypto: { getRandomValues: (a: Uint8Array) => Uint8Array };
28
- }
29
- ).crypto = {
30
- getRandomValues: (array: Uint8Array) => {
31
- const bytes = randomBytes(array.length);
32
- array.set(bytes);
33
- return array;
34
- },
35
- };
36
- }
37
-
38
- it('should return unique ID on first attempt when no collision exists', async () => {
39
- const mockDb = {
40
- findFirst: vi.fn().mockResolvedValue(null), // No existing record found
41
- } as unknown as MockDB;
42
-
43
- const result = await generateUniqueId(mockDb, 'subject');
44
-
45
- expect(mockDb.findFirst).toHaveBeenCalledTimes(1);
46
- expect(mockDb.findFirst).toHaveBeenCalledWith('subject', {
47
- where: expect.any(Function),
48
- });
49
- expect(result).toMatch(SUBJECT_ID_PATTERN); // Should have 'sub_' prefix
50
- expect(result.length).toBeGreaterThan(4); // Should be longer than just prefix
51
- });
52
-
53
- it('should retry when ID collision occurs and return unique ID on second attempt', async () => {
54
- const mockExistingRecord = { id: 'mock_existing' };
55
- const mockDb = {
56
- findFirst: vi
57
- .fn()
58
- .mockResolvedValueOnce(mockExistingRecord) // First call returns existing record
59
- .mockResolvedValueOnce(null), // Second call returns null (unique)
60
- } as unknown as MockDB;
61
-
62
- const result = await generateUniqueId(mockDb, 'consent');
63
-
64
- expect(mockDb.findFirst).toHaveBeenCalledTimes(2);
65
- expect(result).toMatch(CONSENT_ID_PATTERN); // Should have 'cns_' prefix
66
- });
67
-
68
- it('should handle multiple collisions before finding unique ID', async () => {
69
- const mockExistingRecord = { id: 'mock_existing' };
70
- const mockDb = {
71
- findFirst: vi
72
- .fn()
73
- .mockResolvedValueOnce(mockExistingRecord) // First collision
74
- .mockResolvedValueOnce(mockExistingRecord) // Second collision
75
- .mockResolvedValueOnce(mockExistingRecord) // Third collision
76
- .mockResolvedValueOnce(null), // Finally unique
77
- } as unknown as MockDB;
78
-
79
- const result = await generateUniqueId(mockDb, 'domain');
80
-
81
- expect(mockDb.findFirst).toHaveBeenCalledTimes(4);
82
- expect(result).toMatch(DOMAIN_ID_PATTERN); // Should have 'dom_' prefix
83
- });
84
-
85
- it('should work with different model types and use correct prefixes', async () => {
86
- const mockDb = {
87
- findFirst: vi.fn().mockResolvedValue(null),
88
- } as unknown as MockDB;
89
-
90
- const testCases = [
91
- { model: 'auditLog' as const, expectedPrefix: 'log_' },
92
- { model: 'consent' as const, expectedPrefix: 'cns_' },
93
- { model: 'consentPolicy' as const, expectedPrefix: 'pol_' },
94
- { model: 'consentPurpose' as const, expectedPrefix: 'pur_' },
95
- { model: 'domain' as const, expectedPrefix: 'dom_' },
96
- { model: 'subject' as const, expectedPrefix: 'sub_' },
97
- ];
98
-
99
- for (const { model, expectedPrefix } of testCases) {
100
- const result = await generateUniqueId(mockDb, model);
101
- expect(result).toMatch(
102
- new RegExp(
103
- `^${expectedPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[A-Za-z0-9]+$`
104
- )
105
- );
106
- }
107
-
108
- expect(mockDb.findFirst).toHaveBeenCalledTimes(testCases.length);
109
- });
110
-
111
- it('should call findFirst with correct where clause function', async () => {
112
- const mockDb = {
113
- findFirst: vi.fn().mockResolvedValue(null),
114
- } as unknown as MockDB;
115
-
116
- await generateUniqueId(mockDb, 'subject');
117
-
118
- const mockFindFirst = vi.mocked(mockDb.findFirst);
119
- const [model, options] = mockFindFirst.mock.calls[0] as [
120
- string,
121
- { where: (builder: unknown) => void },
122
- ];
123
- expect(mockFindFirst.mock.calls).toHaveLength(1);
124
- expect(model).toBe('subject');
125
- expect(options).toHaveProperty('where');
126
- expect(typeof options.where).toBe('function');
127
-
128
- // Test the where function behavior
129
- const mockBuilder = vi.fn();
130
- options.where(mockBuilder);
131
- expect(mockBuilder).toHaveBeenCalledWith(
132
- 'id',
133
- '=',
134
- expect.stringMatching(SUBJECT_ID_PATTERN)
135
- );
136
- });
137
-
138
- it('should generate different IDs on subsequent calls', async () => {
139
- const mockDb = {
140
- findFirst: vi.fn().mockResolvedValue(null),
141
- } as unknown as MockDB;
142
-
143
- const id1 = await generateUniqueId(mockDb, 'subject');
144
- const id2 = await generateUniqueId(mockDb, 'subject');
145
- const id3 = await generateUniqueId(mockDb, 'subject');
146
-
147
- expect(id1).not.toBe(id2);
148
- expect(id2).not.toBe(id3);
149
- expect(id1).not.toBe(id3);
150
-
151
- // All should have the same prefix
152
- expect(id1).toMatch(SUBJECT_ID_PATTERN);
153
- expect(id2).toMatch(SUBJECT_ID_PATTERN);
154
- expect(id3).toMatch(SUBJECT_ID_PATTERN);
155
- });
156
-
157
- it('should throw an error when max retries is exceeded', async () => {
158
- const mockExistingRecord = { id: 'mock_existing' };
159
- const mockLogger = {
160
- error: vi.fn(),
161
- debug: vi.fn(),
162
- info: vi.fn(),
163
- success: vi.fn(),
164
- warn: vi.fn(),
165
- };
166
- const mockCtx = { logger: mockLogger };
167
-
168
- const mockDb = {
169
- findFirst: vi.fn().mockResolvedValue(mockExistingRecord), // Always return a collision
170
- } as unknown as MockDB;
171
-
172
- // Use a small maxRetries value for faster test execution
173
- await expect(
174
- generateUniqueId(mockDb, 'subject', mockCtx, { maxRetries: 3 })
175
- ).rejects.toThrow(
176
- 'Failed to generate unique ID for subject after 3 attempts'
177
- );
178
-
179
- // Should have attempted exactly maxRetries times
180
- expect(mockDb.findFirst).toHaveBeenCalledTimes(3);
181
- expect(mockLogger.error).toHaveBeenCalledWith(
182
- 'ID generation failed',
183
- expect.objectContaining({ model: 'subject', maxRetries: 3 })
184
- );
185
- });
186
-
187
- it('should respect custom retry options', async () => {
188
- const mockExistingRecord = { id: 'mock_existing' };
189
- const mockDb = {
190
- findFirst: vi
191
- .fn()
192
- .mockResolvedValueOnce(mockExistingRecord) // First call returns existing record
193
- .mockResolvedValueOnce(null), // Second call returns null (unique)
194
- } as unknown as MockDB;
195
-
196
- // Mock the setTimeout function directly
197
- const originalSetTimeout = global.setTimeout;
198
- global.setTimeout = vi.fn((callback) => {
199
- // Execute callback immediately
200
- callback();
201
- return 1; // Return a timeout ID
202
- }) as any;
203
-
204
- try {
205
- const result = await generateUniqueId(mockDb, 'subject', undefined, {
206
- baseDelay: 100,
207
- });
208
-
209
- expect(mockDb.findFirst).toHaveBeenCalledTimes(2);
210
- expect(result).toMatch(SUBJECT_ID_PATTERN);
211
- } finally {
212
- // Restore original setTimeout
213
- global.setTimeout = originalSetTimeout;
214
- }
215
- });
216
- });
@@ -1,133 +0,0 @@
1
- import baseX from 'base-x';
2
- import type { InferFumaDB } from 'fumadb';
3
- import type { LatestDB } from '~/db/schema';
4
- import type { C15TContext } from '~/types';
5
-
6
- type Tables = InferFumaDB<typeof LatestDB>['schemas'][-1]['tables'];
7
-
8
- const prefixes: Record<keyof Tables, string> = {
9
- auditLog: 'log',
10
- consent: 'cns',
11
- consentPolicy: 'pol',
12
- consentPurpose: 'pur',
13
- domain: 'dom',
14
- subject: 'sub',
15
- } as const;
16
-
17
- const b58 = baseX('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
18
-
19
- /**
20
- * Creates time-ordered, prefixed, base58-encoded identifiers that:
21
- * - Start with the provided prefix for clear identification
22
- * - Embed a timestamp for chronological ordering
23
- * - Include random data for uniqueness
24
- */
25
- function generateId(model: keyof typeof prefixes): string {
26
- const buf = crypto.getRandomValues(new Uint8Array(20));
27
- const prefix = prefixes[model];
28
-
29
- const EPOCH_TIMESTAMP = 1_700_000_000_000;
30
-
31
- const t = Date.now() - EPOCH_TIMESTAMP;
32
-
33
- // Use 8 bytes for the timestamp (0..7) and shift accordingly:
34
- const high = Math.floor(t / 0x100000000);
35
- const low = t >>> 0;
36
- buf[0] = (high >>> 24) & 255;
37
- buf[1] = (high >>> 16) & 255;
38
- buf[2] = (high >>> 8) & 255;
39
- buf[3] = high & 255;
40
- buf[4] = (low >>> 24) & 255;
41
- buf[5] = (low >>> 16) & 255;
42
- buf[6] = (low >>> 8) & 255;
43
- buf[7] = low & 255;
44
-
45
- return `${prefix}_${b58.encode(buf)}`;
46
- }
47
-
48
- /**
49
- * Generates a unique ID for the specified model with conflict handling
50
- *
51
- * @param db - Database ORM instance
52
- * @param model - The model/table name to generate ID for
53
- * @param ctx - Application context containing logger (optional)
54
- * @param options - Configuration options for ID generation
55
- * @returns Promise resolving to a unique ID
56
- *
57
- * @throws {Error} When max retry attempts are exceeded
58
- */
59
- export async function generateUniqueId(
60
- db: ReturnType<InferFumaDB<typeof LatestDB>['orm']>,
61
- model: keyof Tables,
62
- ctx?: Partial<C15TContext> | undefined,
63
- options: {
64
- /** Maximum number of retry attempts (default: 10) */
65
- maxRetries?: number;
66
- /** Current retry attempt (used internally) */
67
- attempt?: number;
68
- /** Base delay for exponential backoff in ms (default: 5) */
69
- baseDelay?: number;
70
- } = {}
71
- ): Promise<string> {
72
- const { maxRetries = 10, attempt = 0, baseDelay = 5 } = options;
73
-
74
- // Check if we've exceeded the maximum retry attempts
75
- if (attempt >= maxRetries) {
76
- const error = new Error(
77
- `Failed to generate unique ID for ${model} after ${maxRetries} attempts`
78
- );
79
- ctx?.logger?.error?.('ID generation failed', { model, maxRetries });
80
- throw error;
81
- }
82
-
83
- const id = generateId(model);
84
-
85
- try {
86
- const existing = await db.findFirst(model, {
87
- where: (b) => b('id', '=', id),
88
- });
89
-
90
- if (existing) {
91
- ctx?.logger?.debug?.('ID conflict detected', {
92
- id,
93
- model,
94
- attempt: attempt + 1,
95
- maxRetries,
96
- });
97
-
98
- // Implement exponential backoff
99
- const delay = Math.min(baseDelay * 2 ** attempt, 1000);
100
-
101
- // Wait before retrying to reduce contention in high-volume scenarios
102
- await new Promise((resolve) => setTimeout(resolve, delay));
103
-
104
- return generateUniqueId(db, model, ctx, {
105
- maxRetries,
106
- attempt: attempt + 1,
107
- baseDelay,
108
- });
109
- }
110
-
111
- return id;
112
- } catch (error) {
113
- ctx?.logger?.error?.('Error checking ID uniqueness', {
114
- error: (error as Error).message,
115
- model,
116
- attempt,
117
- });
118
-
119
- // If database error occurs, retry with backoff
120
- if (attempt < maxRetries - 1) {
121
- const delay = Math.min(baseDelay * 2 ** attempt, 2000);
122
- await new Promise((resolve) => setTimeout(resolve, delay));
123
-
124
- return generateUniqueId(db, model, ctx, {
125
- maxRetries,
126
- attempt: attempt + 1,
127
- baseDelay,
128
- });
129
- }
130
-
131
- throw error;
132
- }
133
- }
@@ -1,133 +0,0 @@
1
- import baseX from 'base-x';
2
- import type { InferFumaDB } from 'fumadb';
3
- import type { DB, LatestDB } from '~/db/schema';
4
- import type { C15TContext } from '~/types';
5
-
6
- type Tables = InferFumaDB<typeof DB>['schemas'][-1]['tables'];
7
-
8
- const prefixes: Record<keyof Tables, string> = {
9
- auditLog: 'log',
10
- consent: 'cns',
11
- consentPolicy: 'pol',
12
- consentPurpose: 'pur',
13
- domain: 'dom',
14
- subject: 'sub',
15
- } as const;
16
-
17
- const b58 = baseX('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
18
-
19
- /**
20
- * Creates time-ordered, prefixed, base58-encoded identifiers that:
21
- * - Start with the provided prefix for clear identification
22
- * - Embed a timestamp for chronological ordering
23
- * - Include random data for uniqueness
24
- */
25
- function generateId(model: keyof typeof prefixes): string {
26
- const buf = crypto.getRandomValues(new Uint8Array(20));
27
- const prefix = prefixes[model];
28
-
29
- const EPOCH_TIMESTAMP = 1_700_000_000_000;
30
-
31
- const t = Date.now() - EPOCH_TIMESTAMP;
32
-
33
- // Use 8 bytes for the timestamp (0..7) and shift accordingly:
34
- const high = Math.floor(t / 0x100000000);
35
- const low = t >>> 0;
36
- buf[0] = (high >>> 24) & 255;
37
- buf[1] = (high >>> 16) & 255;
38
- buf[2] = (high >>> 8) & 255;
39
- buf[3] = high & 255;
40
- buf[4] = (low >>> 24) & 255;
41
- buf[5] = (low >>> 16) & 255;
42
- buf[6] = (low >>> 8) & 255;
43
- buf[7] = low & 255;
44
-
45
- return `${prefix}_${b58.encode(buf)}`;
46
- }
47
-
48
- /**
49
- * Generates a unique ID for the specified model with conflict handling
50
- *
51
- * @param db - Database ORM instance
52
- * @param model - The model/table name to generate ID for
53
- * @param ctx - Application context containing logger (optional)
54
- * @param options - Configuration options for ID generation
55
- * @returns Promise resolving to a unique ID
56
- *
57
- * @throws {Error} When max retry attempts are exceeded
58
- */
59
- export async function generateUniqueId(
60
- db: ReturnType<InferFumaDB<typeof LatestDB>['orm']>,
61
- model: keyof Tables,
62
- ctx?: Partial<C15TContext> | undefined,
63
- options: {
64
- /** Maximum number of retry attempts (default: 10) */
65
- maxRetries?: number;
66
- /** Current retry attempt (used internally) */
67
- attempt?: number;
68
- /** Base delay for exponential backoff in ms (default: 5) */
69
- baseDelay?: number;
70
- } = {}
71
- ): Promise<string> {
72
- const { maxRetries = 10, attempt = 0, baseDelay = 5 } = options;
73
-
74
- // Check if we've exceeded the maximum retry attempts
75
- if (attempt >= maxRetries) {
76
- const error = new Error(
77
- `Failed to generate unique ID for ${model} after ${maxRetries} attempts`
78
- );
79
- ctx?.logger?.error?.('ID generation failed', { model, maxRetries });
80
- throw error;
81
- }
82
-
83
- const id = generateId(model);
84
-
85
- try {
86
- const existing = await db.findFirst(model, {
87
- where: (b) => b('id', '=', id),
88
- });
89
-
90
- if (existing) {
91
- ctx?.logger?.debug?.('ID conflict detected', {
92
- id,
93
- model,
94
- attempt: attempt + 1,
95
- maxRetries,
96
- });
97
-
98
- // Implement exponential backoff
99
- const delay = Math.min(baseDelay * 2 ** attempt, 1000);
100
-
101
- // Wait before retrying to reduce contention in high-volume scenarios
102
- await new Promise((resolve) => setTimeout(resolve, delay));
103
-
104
- return generateUniqueId(db, model, ctx, {
105
- maxRetries,
106
- attempt: attempt + 1,
107
- baseDelay,
108
- });
109
- }
110
-
111
- return id;
112
- } catch (error) {
113
- ctx?.logger?.error?.('Error checking ID uniqueness', {
114
- error: (error as Error).message,
115
- model,
116
- attempt,
117
- });
118
-
119
- // If database error occurs, retry with backoff
120
- if (attempt < maxRetries - 1) {
121
- const delay = Math.min(baseDelay * 2 ** attempt, 2000);
122
- await new Promise((resolve) => setTimeout(resolve, delay));
123
-
124
- return generateUniqueId(db, model, ctx, {
125
- maxRetries,
126
- attempt: attempt + 1,
127
- baseDelay,
128
- });
129
- }
130
-
131
- throw error;
132
- }
133
- }
@@ -1,15 +0,0 @@
1
- import { column, idColumn, table } from 'fumadb/schema';
2
-
3
- export const auditLogTable = table('auditLog', {
4
- id: idColumn('id', 'varchar(255)'),
5
- entityType: column('entityType', 'string'),
6
- entityId: column('entityId', 'string'),
7
- actionType: column('actionType', 'string'),
8
- subjectId: column('subjectId', 'string').nullable(),
9
- ipAddress: column('ipAddress', 'string').nullable(),
10
- userAgent: column('userAgent', 'string').nullable(),
11
- changes: column('changes', 'json').nullable(),
12
- metadata: column('metadata', 'json').nullable(),
13
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
14
- eventTimezone: column('eventTimezone', 'string').defaultTo$(() => 'UTC'),
15
- });
@@ -1,14 +0,0 @@
1
- import { column, idColumn, table } from 'fumadb/schema';
2
-
3
- export const consentPolicyTable = table('consentPolicy', {
4
- id: idColumn('id', 'varchar(255)'),
5
- version: column('version', 'string'),
6
- type: column('type', 'string'),
7
- name: column('name', 'string'),
8
- effectiveDate: column('effectiveDate', 'timestamp'),
9
- expirationDate: column('expirationDate', 'timestamp').nullable(),
10
- content: column('content', 'string'),
11
- contentHash: column('contentHash', 'string'),
12
- isActive: column('isActive', 'bool').defaultTo$(() => true),
13
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
14
- });
@@ -1,14 +0,0 @@
1
- import { column, idColumn, table } from 'fumadb/schema';
2
-
3
- export const consentPurposeTable = table('consentPurpose', {
4
- id: idColumn('id', 'varchar(255)'),
5
- code: column('code', 'string'),
6
- name: column('name', 'string'),
7
- description: column('description', 'string'),
8
- isEssential: column('isEssential', 'bool'),
9
- dataCategory: column('dataCategory', 'string').nullable(),
10
- legalBasis: column('legalBasis', 'string').nullable(),
11
- isActive: column('isActive', 'bool').defaultTo$(() => true),
12
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
13
- updatedAt: column('updatedAt', 'timestamp').defaultTo$('now'),
14
- });
@@ -1,10 +0,0 @@
1
- import { column, idColumn, table } from 'fumadb/schema';
2
-
3
- export const consentRecordTable = table('consentRecord', {
4
- id: idColumn('id', 'varchar(255)'),
5
- subjectId: column('subjectId', 'string'),
6
- consentId: column('consentId', 'string').nullable(),
7
- actionType: column('actionType', 'string'),
8
- details: column('details', 'json').nullable(),
9
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
10
- });
@@ -1,20 +0,0 @@
1
- import { type Consent, consentSchema } from '@c15t/schema';
2
- import { column, idColumn, table } from 'fumadb/schema';
3
-
4
- export const consentTable = table('consent', {
5
- id: idColumn('id', 'varchar(255)'),
6
- subjectId: column('subjectId', 'string'),
7
- domainId: column('domainId', 'string'),
8
- policyId: column('policyId', 'string').nullable(),
9
- purposeIds: column('purposeIds', 'json'),
10
- metadata: column('metadata', 'json').nullable(),
11
- ipAddress: column('ipAddress', 'string').nullable(),
12
- userAgent: column('userAgent', 'string').nullable(),
13
- status: column('status', 'string').defaultTo$(() => 'active'),
14
- withdrawalReason: column('withdrawalReason', 'string').nullable(),
15
- givenAt: column('givenAt', 'timestamp').defaultTo$('now'),
16
- validUntil: column('validUntil', 'timestamp').nullable(),
17
- isActive: column('isActive', 'bool').defaultTo$(() => true),
18
- });
19
-
20
- export { consentSchema, type Consent };
@@ -1,12 +0,0 @@
1
- import { column, idColumn, table } from 'fumadb/schema';
2
-
3
- export const domainTable = table('domain', {
4
- id: idColumn('id', 'varchar(255)'),
5
- name: column('name', 'string').unique(),
6
- description: column('description', 'string').nullable(),
7
- allowedOrigins: column('allowedOrigins', 'json').nullable(),
8
- isVerified: column('isVerified', 'bool').defaultTo$(() => true),
9
- isActive: column('isActive', 'bool').defaultTo$(() => true),
10
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
11
- updatedAt: column('updatedAt', 'timestamp').defaultTo$('now'),
12
- });
@@ -1,48 +0,0 @@
1
- import { schema } from 'fumadb/schema';
2
- import { auditLogTable } from './audit-log';
3
- import { consentTable } from './consent';
4
- import { consentPolicyTable } from './consent-policy';
5
- import { consentPurposeTable } from './consent-purpose';
6
- import { consentRecordTable } from './consent-record';
7
- import { domainTable } from './domain';
8
- import { subjectTable } from './subject';
9
-
10
- export const v1 = schema({
11
- version: '1.0.0',
12
- tables: {
13
- subject: subjectTable,
14
- domain: domainTable,
15
- consentPolicy: consentPolicyTable,
16
- consentPurpose: consentPurposeTable,
17
- consent: consentTable,
18
- auditLog: auditLogTable,
19
- consentRecord: consentRecordTable,
20
- },
21
- relations: {
22
- subject: ({ many }) => ({
23
- consents: many('consent'),
24
- consentRecords: many('consentRecord'),
25
- auditLogs: many('auditLog'),
26
- }),
27
- domain: ({ many }) => ({
28
- consents: many('consent'),
29
- }),
30
- consentPolicy: ({ many }) => ({
31
- consents: many('consent'),
32
- }),
33
- consentPurpose: () => ({}),
34
- consent: ({ one, many }) => ({
35
- subject: one('subject', ['subjectId', 'id']).foreignKey(),
36
- domain: one('domain', ['domainId', 'id']).foreignKey(),
37
- policy: one('consentPolicy', ['policyId', 'id']).foreignKey(),
38
- consentRecords: many('consentRecord'),
39
- }),
40
- consentRecord: ({ one }) => ({
41
- subject: one('subject', ['subjectId', 'id']).foreignKey(),
42
- consent: one('consent', ['consentId', 'id']).foreignKey(),
43
- }),
44
- auditLog: ({ one }) => ({
45
- subject: one('subject', ['subjectId', 'id']).foreignKey(),
46
- }),
47
- },
48
- });
@@ -1,11 +0,0 @@
1
- import { column, idColumn, table } from 'fumadb/schema';
2
-
3
- export const subjectTable = table('subject', {
4
- id: idColumn('id', 'varchar(255)'),
5
- externalId: column('externalId', 'string').nullable(),
6
- identityProvider: column('identityProvider', 'string').nullable(),
7
- lastIpAddress: column('lastIpAddress', 'string').nullable(),
8
- subjectTimezone: column('subjectTimezone', 'string').nullable(),
9
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
10
- updatedAt: column('updatedAt', 'timestamp').defaultTo$('now'),
11
- });
@@ -1,18 +0,0 @@
1
- import { type AuditLog, auditLogSchema } from '@c15t/schema';
2
- import { column, idColumn, table } from 'fumadb/schema';
3
-
4
- export const auditLogTable = table('auditLog', {
5
- id: idColumn('id', 'varchar(255)'),
6
- entityType: column('entityType', 'string'),
7
- entityId: column('entityId', 'string'),
8
- actionType: column('actionType', 'string'),
9
- subjectId: column('subjectId', 'string').nullable(),
10
- ipAddress: column('ipAddress', 'string').nullable(),
11
- userAgent: column('userAgent', 'string').nullable(),
12
- changes: column('changes', 'json').nullable(),
13
- metadata: column('metadata', 'json').nullable(),
14
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
15
- tenantId: column('tenantId', 'string').nullable(),
16
- });
17
-
18
- export { auditLogSchema, type AuditLog };
@@ -1,28 +0,0 @@
1
- import {
2
- type ConsentPolicy,
3
- consentPolicySchema,
4
- type PolicyType,
5
- policyTypeSchema,
6
- } from '@c15t/schema';
7
- import { column, idColumn, table } from 'fumadb/schema';
8
-
9
- export const consentPolicyTable = table('consentPolicy', {
10
- id: idColumn('id', 'varchar(255)'),
11
- version: column('version', 'string'),
12
- type: column('type', 'string'),
13
- effectiveDate: column('effectiveDate', 'timestamp'),
14
- isActive: column('isActive', 'bool').defaultTo$(() => true),
15
- createdAt: column('createdAt', 'timestamp').defaultTo$('now'),
16
- tenantId: column('tenantId', 'string').nullable(),
17
- });
18
-
19
- // Re-export for backward compatibility
20
- export {
21
- consentPolicySchema,
22
- policyTypeSchema,
23
- type ConsentPolicy,
24
- type PolicyType,
25
- };
26
-
27
- // Backward compatible alias
28
- export const PolicyTypeSchema = policyTypeSchema;