@c15t/backend 0.0.1-rc.10

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 (521) hide show
  1. package/.turbo/turbo-build.log +11 -0
  2. package/.turbo/turbo-check-types.log +5 -0
  3. package/.turbo/turbo-fmt.log +7 -0
  4. package/.turbo/turbo-lint.log +6 -0
  5. package/.turbo/turbo-test.log +26 -0
  6. package/README-next.md +223 -0
  7. package/README.md +164 -0
  8. package/dist/api/call.d.ts +176 -0
  9. package/dist/api/call.d.ts.map +1 -0
  10. package/dist/api/index.d.ts +935 -0
  11. package/dist/api/index.d.ts.map +1 -0
  12. package/dist/api/middlewares/index.d.ts +39 -0
  13. package/dist/api/middlewares/index.d.ts.map +1 -0
  14. package/dist/api/middlewares/origin-check.d.ts +82 -0
  15. package/dist/api/middlewares/origin-check.d.ts.map +1 -0
  16. package/dist/api/middlewares/validate-context.d.ts +38 -0
  17. package/dist/api/middlewares/validate-context.d.ts.map +1 -0
  18. package/dist/api/routes/__tests__/consent.test.d.ts +2 -0
  19. package/dist/api/routes/__tests__/consent.test.d.ts.map +1 -0
  20. package/dist/api/routes/__tests__/status.test.d.ts +2 -0
  21. package/dist/api/routes/__tests__/status.test.d.ts.map +1 -0
  22. package/dist/api/routes/error.d.ts +57 -0
  23. package/dist/api/routes/error.d.ts.map +1 -0
  24. package/dist/api/routes/generate-consent-receipt.d.ts +130 -0
  25. package/dist/api/routes/generate-consent-receipt.d.ts.map +1 -0
  26. package/dist/api/routes/get-consent-history.d.ts +133 -0
  27. package/dist/api/routes/get-consent-history.d.ts.map +1 -0
  28. package/dist/api/routes/get-consent-policy.d.ts +164 -0
  29. package/dist/api/routes/get-consent-policy.d.ts.map +1 -0
  30. package/dist/api/routes/get-consent.d.ts +148 -0
  31. package/dist/api/routes/get-consent.d.ts.map +1 -0
  32. package/dist/api/routes/index.d.ts +339 -0
  33. package/dist/api/routes/index.d.ts.map +1 -0
  34. package/dist/api/routes/ok.d.ts +87 -0
  35. package/dist/api/routes/ok.d.ts.map +1 -0
  36. package/dist/api/routes/set-consent.d.ts +245 -0
  37. package/dist/api/routes/set-consent.d.ts.map +1 -0
  38. package/dist/api/routes/show-consent-banner.d.ts +127 -0
  39. package/dist/api/routes/show-consent-banner.d.ts.map +1 -0
  40. package/dist/api/routes/status.d.ts +61 -0
  41. package/dist/api/routes/status.d.ts.map +1 -0
  42. package/dist/api/routes/verify-consent.d.ts +179 -0
  43. package/dist/api/routes/verify-consent.d.ts.map +1 -0
  44. package/dist/api/routes/withdraw-consent.d.ts +194 -0
  45. package/dist/api/routes/withdraw-consent.d.ts.map +1 -0
  46. package/dist/api/to-endpoints.d.ts +35 -0
  47. package/dist/api/to-endpoints.d.ts.map +1 -0
  48. package/dist/client/index.cjs +139 -0
  49. package/dist/client/index.d.ts +203 -0
  50. package/dist/client/index.d.ts.map +1 -0
  51. package/dist/client/index.js +106 -0
  52. package/dist/client/types.d.ts +431 -0
  53. package/dist/client/types.d.ts.map +1 -0
  54. package/dist/core.d.ts +124 -0
  55. package/dist/core.d.ts.map +1 -0
  56. package/dist/core.test.d.ts +2 -0
  57. package/dist/core.test.d.ts.map +1 -0
  58. package/dist/db/adapters/drizzle-adapter/drizzle-adapter.d.ts +122 -0
  59. package/dist/db/adapters/drizzle-adapter/drizzle-adapter.d.ts.map +1 -0
  60. package/dist/db/adapters/drizzle-adapter/index.d.ts +2 -0
  61. package/dist/db/adapters/drizzle-adapter/index.d.ts.map +1 -0
  62. package/dist/db/adapters/drizzle.cjs +1531 -0
  63. package/dist/db/adapters/drizzle.js +1489 -0
  64. package/dist/db/adapters/kysely-adapter/dialect.d.ts +72 -0
  65. package/dist/db/adapters/kysely-adapter/dialect.d.ts.map +1 -0
  66. package/dist/db/adapters/kysely-adapter/index.d.ts +4 -0
  67. package/dist/db/adapters/kysely-adapter/index.d.ts.map +1 -0
  68. package/dist/db/adapters/kysely-adapter/kysely-adapter.d.ts +98 -0
  69. package/dist/db/adapters/kysely-adapter/kysely-adapter.d.ts.map +1 -0
  70. package/dist/db/adapters/kysely-adapter/types.d.ts +281 -0
  71. package/dist/db/adapters/kysely-adapter/types.d.ts.map +1 -0
  72. package/dist/db/adapters/kysely.cjs +1551 -0
  73. package/dist/db/adapters/kysely.js +1508 -0
  74. package/dist/db/adapters/memory-adapter/index.d.ts +2 -0
  75. package/dist/db/adapters/memory-adapter/index.d.ts.map +1 -0
  76. package/dist/db/adapters/memory-adapter/memory-adapter.d.ts +56 -0
  77. package/dist/db/adapters/memory-adapter/memory-adapter.d.ts.map +1 -0
  78. package/dist/db/adapters/memory.cjs +1391 -0
  79. package/dist/db/adapters/memory.js +1349 -0
  80. package/dist/db/adapters/prisma-adapter/index.d.ts +2 -0
  81. package/dist/db/adapters/prisma-adapter/index.d.ts.map +1 -0
  82. package/dist/db/adapters/prisma-adapter/prisma-adapter.d.ts +143 -0
  83. package/dist/db/adapters/prisma-adapter/prisma-adapter.d.ts.map +1 -0
  84. package/dist/db/adapters/prisma.cjs +1503 -0
  85. package/dist/db/adapters/prisma.js +1461 -0
  86. package/dist/db/adapters/types.d.ts +154 -0
  87. package/dist/db/adapters/types.d.ts.map +1 -0
  88. package/dist/db/adapters/utils.d.ts +36 -0
  89. package/dist/db/adapters/utils.d.ts.map +1 -0
  90. package/dist/db/core/fields/field-factory.d.ts +383 -0
  91. package/dist/db/core/fields/field-factory.d.ts.map +1 -0
  92. package/dist/db/core/fields/field-inference.d.ts +218 -0
  93. package/dist/db/core/fields/field-inference.d.ts.map +1 -0
  94. package/dist/db/core/fields/field-options-integration.d.ts +90 -0
  95. package/dist/db/core/fields/field-options-integration.d.ts.map +1 -0
  96. package/dist/db/core/fields/field-types.d.ts +182 -0
  97. package/dist/db/core/fields/field-types.d.ts.map +1 -0
  98. package/dist/db/core/fields/id-generator.d.ts +19 -0
  99. package/dist/db/core/fields/id-generator.d.ts.map +1 -0
  100. package/dist/db/core/fields/index.d.ts +8 -0
  101. package/dist/db/core/fields/index.d.ts.map +1 -0
  102. package/dist/db/core/fields/superjson-utils.d.ts +34 -0
  103. package/dist/db/core/fields/superjson-utils.d.ts.map +1 -0
  104. package/dist/db/core/fields/zod-fields.d.ts +1011 -0
  105. package/dist/db/core/fields/zod-fields.d.ts.map +1 -0
  106. package/dist/db/core/get-schema.d.ts +36 -0
  107. package/dist/db/core/get-schema.d.ts.map +1 -0
  108. package/dist/db/core/types.d.ts +41 -0
  109. package/dist/db/core/types.d.ts.map +1 -0
  110. package/dist/db/create-registry.d.ts +760 -0
  111. package/dist/db/create-registry.d.ts.map +1 -0
  112. package/dist/db/hooks/create-hooks.d.ts +32 -0
  113. package/dist/db/hooks/create-hooks.d.ts.map +1 -0
  114. package/dist/db/hooks/index.d.ts +40 -0
  115. package/dist/db/hooks/index.d.ts.map +1 -0
  116. package/dist/db/hooks/types.d.ts +133 -0
  117. package/dist/db/hooks/types.d.ts.map +1 -0
  118. package/dist/db/hooks/update-hooks.d.ts +33 -0
  119. package/dist/db/hooks/update-hooks.d.ts.map +1 -0
  120. package/dist/db/hooks/update-many-hooks.d.ts +55 -0
  121. package/dist/db/hooks/update-many-hooks.d.ts.map +1 -0
  122. package/dist/db/hooks/utils.d.ts +62 -0
  123. package/dist/db/hooks/utils.d.ts.map +1 -0
  124. package/dist/db/hooks/with-hooks-factory.d.ts +33 -0
  125. package/dist/db/hooks/with-hooks-factory.d.ts.map +1 -0
  126. package/dist/db/index.cjs +2458 -0
  127. package/dist/db/index.d.ts +11 -0
  128. package/dist/db/index.d.ts.map +1 -0
  129. package/dist/db/index.js +2404 -0
  130. package/dist/db/migration/get-migration.d.ts +32 -0
  131. package/dist/db/migration/get-migration.d.ts.map +1 -0
  132. package/dist/db/migration/get-schema/get-schema.d.ts +27 -0
  133. package/dist/db/migration/get-schema/get-schema.d.ts.map +1 -0
  134. package/dist/db/migration/get-schema/index.d.ts +21 -0
  135. package/dist/db/migration/get-schema/index.d.ts.map +1 -0
  136. package/dist/db/migration/get-schema/process-fields.d.ts +16 -0
  137. package/dist/db/migration/get-schema/process-fields.d.ts.map +1 -0
  138. package/dist/db/migration/get-schema/process-tables.d.ts +13 -0
  139. package/dist/db/migration/get-schema/process-tables.d.ts.map +1 -0
  140. package/dist/db/migration/get-schema/types.d.ts +17 -0
  141. package/dist/db/migration/get-schema/types.d.ts.map +1 -0
  142. package/dist/db/migration/index.cjs +1613 -0
  143. package/dist/db/migration/index.d.ts +14 -0
  144. package/dist/db/migration/index.d.ts.map +1 -0
  145. package/dist/db/migration/index.js +1571 -0
  146. package/dist/db/migration/migration-builders.d.ts +28 -0
  147. package/dist/db/migration/migration-builders.d.ts.map +1 -0
  148. package/dist/db/migration/migration-execution.d.ts +12 -0
  149. package/dist/db/migration/migration-execution.d.ts.map +1 -0
  150. package/dist/db/migration/schema-comparison.d.ts +54 -0
  151. package/dist/db/migration/schema-comparison.d.ts.map +1 -0
  152. package/dist/db/migration/type-mapping.d.ts +86 -0
  153. package/dist/db/migration/type-mapping.d.ts.map +1 -0
  154. package/dist/db/migration/types.d.ts +37 -0
  155. package/dist/db/migration/types.d.ts.map +1 -0
  156. package/dist/db/schema/audit-log/index.d.ts +4 -0
  157. package/dist/db/schema/audit-log/index.d.ts.map +1 -0
  158. package/dist/db/schema/audit-log/registry.d.ts +128 -0
  159. package/dist/db/schema/audit-log/registry.d.ts.map +1 -0
  160. package/dist/db/schema/audit-log/schema.d.ts +67 -0
  161. package/dist/db/schema/audit-log/schema.d.ts.map +1 -0
  162. package/dist/db/schema/audit-log/table.d.ts +175 -0
  163. package/dist/db/schema/audit-log/table.d.ts.map +1 -0
  164. package/dist/db/schema/audit-log/types.d.ts +29 -0
  165. package/dist/db/schema/audit-log/types.d.ts.map +1 -0
  166. package/dist/db/schema/consent/index.d.ts +4 -0
  167. package/dist/db/schema/consent/index.d.ts.map +1 -0
  168. package/dist/db/schema/consent/registry.d.ts +318 -0
  169. package/dist/db/schema/consent/registry.d.ts.map +1 -0
  170. package/dist/db/schema/consent/schema.d.ts +135 -0
  171. package/dist/db/schema/consent/schema.d.ts.map +1 -0
  172. package/dist/db/schema/consent/table.d.ts +245 -0
  173. package/dist/db/schema/consent/table.d.ts.map +1 -0
  174. package/dist/db/schema/consent/types.d.ts +37 -0
  175. package/dist/db/schema/consent/types.d.ts.map +1 -0
  176. package/dist/db/schema/consent-geo-location/index.d.ts +4 -0
  177. package/dist/db/schema/consent-geo-location/index.d.ts.map +1 -0
  178. package/dist/db/schema/consent-geo-location/registry.d.ts +96 -0
  179. package/dist/db/schema/consent-geo-location/registry.d.ts.map +1 -0
  180. package/dist/db/schema/consent-geo-location/schema.d.ts +71 -0
  181. package/dist/db/schema/consent-geo-location/schema.d.ts.map +1 -0
  182. package/dist/db/schema/consent-geo-location/table.d.ts +167 -0
  183. package/dist/db/schema/consent-geo-location/table.d.ts.map +1 -0
  184. package/dist/db/schema/consent-geo-location/types.d.ts +21 -0
  185. package/dist/db/schema/consent-geo-location/types.d.ts.map +1 -0
  186. package/dist/db/schema/consent-policy/index.d.ts +4 -0
  187. package/dist/db/schema/consent-policy/index.d.ts.map +1 -0
  188. package/dist/db/schema/consent-policy/registry.d.ts +186 -0
  189. package/dist/db/schema/consent-policy/registry.d.ts.map +1 -0
  190. package/dist/db/schema/consent-policy/schema.d.ts +68 -0
  191. package/dist/db/schema/consent-policy/schema.d.ts.map +1 -0
  192. package/dist/db/schema/consent-policy/table.d.ts +147 -0
  193. package/dist/db/schema/consent-policy/table.d.ts.map +1 -0
  194. package/dist/db/schema/consent-policy/types.d.ts +28 -0
  195. package/dist/db/schema/consent-policy/types.d.ts.map +1 -0
  196. package/dist/db/schema/consent-purpose/index.d.ts +4 -0
  197. package/dist/db/schema/consent-purpose/index.d.ts.map +1 -0
  198. package/dist/db/schema/consent-purpose/registry.d.ts +136 -0
  199. package/dist/db/schema/consent-purpose/registry.d.ts.map +1 -0
  200. package/dist/db/schema/consent-purpose/schema.d.ts +79 -0
  201. package/dist/db/schema/consent-purpose/schema.d.ts.map +1 -0
  202. package/dist/db/schema/consent-purpose/table.d.ts +161 -0
  203. package/dist/db/schema/consent-purpose/table.d.ts.map +1 -0
  204. package/dist/db/schema/consent-purpose/types.d.ts +16 -0
  205. package/dist/db/schema/consent-purpose/types.d.ts.map +1 -0
  206. package/dist/db/schema/consent-purpose-junction/index.d.ts +4 -0
  207. package/dist/db/schema/consent-purpose-junction/index.d.ts.map +1 -0
  208. package/dist/db/schema/consent-purpose-junction/registry.d.ts +109 -0
  209. package/dist/db/schema/consent-purpose-junction/registry.d.ts.map +1 -0
  210. package/dist/db/schema/consent-purpose-junction/schema.d.ts +57 -0
  211. package/dist/db/schema/consent-purpose-junction/schema.d.ts.map +1 -0
  212. package/dist/db/schema/consent-purpose-junction/table.d.ts +138 -0
  213. package/dist/db/schema/consent-purpose-junction/table.d.ts.map +1 -0
  214. package/dist/db/schema/consent-purpose-junction/types.d.ts +14 -0
  215. package/dist/db/schema/consent-purpose-junction/types.d.ts.map +1 -0
  216. package/dist/db/schema/consent-record/index.d.ts +4 -0
  217. package/dist/db/schema/consent-record/index.d.ts.map +1 -0
  218. package/dist/db/schema/consent-record/registry.d.ts +119 -0
  219. package/dist/db/schema/consent-record/registry.d.ts.map +1 -0
  220. package/dist/db/schema/consent-record/schema.d.ts +57 -0
  221. package/dist/db/schema/consent-record/schema.d.ts.map +1 -0
  222. package/dist/db/schema/consent-record/table.d.ts +123 -0
  223. package/dist/db/schema/consent-record/table.d.ts.map +1 -0
  224. package/dist/db/schema/consent-record/types.d.ts +21 -0
  225. package/dist/db/schema/consent-record/types.d.ts.map +1 -0
  226. package/dist/db/schema/consent-withdrawal/index.d.ts +4 -0
  227. package/dist/db/schema/consent-withdrawal/index.d.ts.map +1 -0
  228. package/dist/db/schema/consent-withdrawal/registry.d.ts +134 -0
  229. package/dist/db/schema/consent-withdrawal/registry.d.ts.map +1 -0
  230. package/dist/db/schema/consent-withdrawal/schema.d.ts +67 -0
  231. package/dist/db/schema/consent-withdrawal/schema.d.ts.map +1 -0
  232. package/dist/db/schema/consent-withdrawal/table.d.ts +170 -0
  233. package/dist/db/schema/consent-withdrawal/table.d.ts.map +1 -0
  234. package/dist/db/schema/consent-withdrawal/types.d.ts +28 -0
  235. package/dist/db/schema/consent-withdrawal/types.d.ts.map +1 -0
  236. package/dist/db/schema/definition.d.ts +1100 -0
  237. package/dist/db/schema/definition.d.ts.map +1 -0
  238. package/dist/db/schema/domain/index.d.ts +4 -0
  239. package/dist/db/schema/domain/index.d.ts.map +1 -0
  240. package/dist/db/schema/domain/registry.d.ts +169 -0
  241. package/dist/db/schema/domain/registry.d.ts.map +1 -0
  242. package/dist/db/schema/domain/schema.d.ts +60 -0
  243. package/dist/db/schema/domain/schema.d.ts.map +1 -0
  244. package/dist/db/schema/domain/table.d.ts +140 -0
  245. package/dist/db/schema/domain/table.d.ts.map +1 -0
  246. package/dist/db/schema/domain/types.d.ts +27 -0
  247. package/dist/db/schema/domain/types.d.ts.map +1 -0
  248. package/dist/db/schema/geo-location/index.d.ts +4 -0
  249. package/dist/db/schema/geo-location/index.d.ts.map +1 -0
  250. package/dist/db/schema/geo-location/registry.d.ts +114 -0
  251. package/dist/db/schema/geo-location/registry.d.ts.map +1 -0
  252. package/dist/db/schema/geo-location/schema.d.ts +58 -0
  253. package/dist/db/schema/geo-location/schema.d.ts.map +1 -0
  254. package/dist/db/schema/geo-location/table.d.ts +132 -0
  255. package/dist/db/schema/geo-location/table.d.ts.map +1 -0
  256. package/dist/db/schema/geo-location/types.d.ts +17 -0
  257. package/dist/db/schema/geo-location/types.d.ts.map +1 -0
  258. package/dist/db/schema/index.d.ts +85 -0
  259. package/dist/db/schema/index.d.ts.map +1 -0
  260. package/dist/db/schema/parser.d.ts +183 -0
  261. package/dist/db/schema/parser.d.ts.map +1 -0
  262. package/dist/db/schema/schemas.d.ts +383 -0
  263. package/dist/db/schema/schemas.d.ts.map +1 -0
  264. package/dist/db/schema/subject/index.d.ts +4 -0
  265. package/dist/db/schema/subject/index.d.ts.map +1 -0
  266. package/dist/db/schema/subject/registry.d.ts +141 -0
  267. package/dist/db/schema/subject/registry.d.ts.map +1 -0
  268. package/dist/db/schema/subject/schema.d.ts +56 -0
  269. package/dist/db/schema/subject/schema.d.ts.map +1 -0
  270. package/dist/db/schema/subject/table.d.ts +136 -0
  271. package/dist/db/schema/subject/table.d.ts.map +1 -0
  272. package/dist/db/schema/subject/types.d.ts +22 -0
  273. package/dist/db/schema/subject/types.d.ts.map +1 -0
  274. package/dist/db/schema/types.d.ts +136 -0
  275. package/dist/db/schema/types.d.ts.map +1 -0
  276. package/dist/db/utils/adapter-factory.d.ts +21 -0
  277. package/dist/db/utils/adapter-factory.d.ts.map +1 -0
  278. package/dist/db/utils/index.d.ts +10 -0
  279. package/dist/db/utils/index.d.ts.map +1 -0
  280. package/dist/db/utils.d.ts +4 -0
  281. package/dist/db/utils.d.ts.map +1 -0
  282. package/dist/error/codes.cjs +68 -0
  283. package/dist/error/codes.d.ts +175 -0
  284. package/dist/error/codes.d.ts.map +1 -0
  285. package/dist/error/codes.js +35 -0
  286. package/dist/error/error.d.ts +79 -0
  287. package/dist/error/error.d.ts.map +1 -0
  288. package/dist/error/index.cjs +172 -0
  289. package/dist/error/index.d.ts +9 -0
  290. package/dist/error/index.d.ts.map +1 -0
  291. package/dist/error/index.js +129 -0
  292. package/dist/error/logging.d.ts +25 -0
  293. package/dist/error/logging.d.ts.map +1 -0
  294. package/dist/error/pipeline.d.ts +19 -0
  295. package/dist/error/pipeline.d.ts.map +1 -0
  296. package/dist/error/recovery.d.ts +22 -0
  297. package/dist/error/recovery.d.ts.map +1 -0
  298. package/dist/error/results.d.ts +56 -0
  299. package/dist/error/results.d.ts.map +1 -0
  300. package/dist/index.cjs +4777 -0
  301. package/dist/index.d.ts +46 -0
  302. package/dist/index.d.ts.map +1 -0
  303. package/dist/index.js +4708 -0
  304. package/dist/init.d.ts +52 -0
  305. package/dist/init.d.ts.map +1 -0
  306. package/dist/init.test.d.ts +2 -0
  307. package/dist/init.test.d.ts.map +1 -0
  308. package/dist/integrations/index.cjs +281 -0
  309. package/dist/integrations/index.d.ts +7 -0
  310. package/dist/integrations/index.d.ts.map +1 -0
  311. package/dist/integrations/index.js +248 -0
  312. package/dist/integrations/next.cjs +131 -0
  313. package/dist/integrations/next.d.ts +29 -0
  314. package/dist/integrations/next.d.ts.map +1 -0
  315. package/dist/integrations/next.js +99 -0
  316. package/dist/integrations/react.cjs +182 -0
  317. package/dist/integrations/react.d.ts +257 -0
  318. package/dist/integrations/react.d.ts.map +1 -0
  319. package/dist/integrations/react.js +150 -0
  320. package/dist/plugins/geo/index.d.ts +2 -0
  321. package/dist/plugins/geo/index.d.ts.map +1 -0
  322. package/dist/test/utils.d.ts +65 -0
  323. package/dist/test/utils.d.ts.map +1 -0
  324. package/dist/types/api.d.ts +89 -0
  325. package/dist/types/api.d.ts.map +1 -0
  326. package/dist/types/context.d.ts +205 -0
  327. package/dist/types/context.d.ts.map +1 -0
  328. package/dist/types/helper.d.ts +78 -0
  329. package/dist/types/helper.d.ts.map +1 -0
  330. package/dist/types/index.cjs +19 -0
  331. package/dist/types/index.d.ts +6 -0
  332. package/dist/types/index.d.ts.map +1 -0
  333. package/dist/types/index.js +0 -0
  334. package/dist/types/options.d.ts +172 -0
  335. package/dist/types/options.d.ts.map +1 -0
  336. package/dist/types/plugins.d.ts +442 -0
  337. package/dist/types/plugins.d.ts.map +1 -0
  338. package/dist/utils/env.d.ts +77 -0
  339. package/dist/utils/env.d.ts.map +1 -0
  340. package/dist/utils/hide-metadata.d.ts +22 -0
  341. package/dist/utils/hide-metadata.d.ts.map +1 -0
  342. package/dist/utils/index.cjs +268 -0
  343. package/dist/utils/index.d.ts +18 -0
  344. package/dist/utils/index.d.ts.map +1 -0
  345. package/dist/utils/index.js +210 -0
  346. package/dist/utils/ip.d.ts +10 -0
  347. package/dist/utils/ip.d.ts.map +1 -0
  348. package/dist/utils/json.d.ts +14 -0
  349. package/dist/utils/json.d.ts.map +1 -0
  350. package/dist/utils/logger.d.ts +108 -0
  351. package/dist/utils/logger.d.ts.map +1 -0
  352. package/dist/utils/url.d.ts +87 -0
  353. package/dist/utils/url.d.ts.map +1 -0
  354. package/dist/utils/wildcard.d.ts +46 -0
  355. package/dist/utils/wildcard.d.ts.map +1 -0
  356. package/knip.json +37 -0
  357. package/package.json +146 -0
  358. package/rslib.config.ts +104 -0
  359. package/src/api/call.ts +177 -0
  360. package/src/api/index.ts +303 -0
  361. package/src/api/middlewares/index.ts +38 -0
  362. package/src/api/middlewares/origin-check.ts +260 -0
  363. package/src/api/middlewares/validate-context.ts +175 -0
  364. package/src/api/routes/__tests__/consent.test.ts +270 -0
  365. package/src/api/routes/__tests__/status.test.ts +36 -0
  366. package/src/api/routes/error.ts +130 -0
  367. package/src/api/routes/generate-consent-receipt.ts +244 -0
  368. package/src/api/routes/get-consent-history.ts +128 -0
  369. package/src/api/routes/get-consent-policy.ts +327 -0
  370. package/src/api/routes/get-consent.ts +230 -0
  371. package/src/api/routes/index.ts +12 -0
  372. package/src/api/routes/ok.ts +45 -0
  373. package/src/api/routes/set-consent.ts +328 -0
  374. package/src/api/routes/show-consent-banner.ts +149 -0
  375. package/src/api/routes/status.ts +62 -0
  376. package/src/api/routes/verify-consent.ts +272 -0
  377. package/src/api/routes/withdraw-consent.ts +293 -0
  378. package/src/api/to-endpoints.ts +371 -0
  379. package/src/client/index.ts +471 -0
  380. package/src/client/types.ts +458 -0
  381. package/src/core.test.ts +303 -0
  382. package/src/core.ts +267 -0
  383. package/src/db/adapters/drizzle-adapter/drizzle-adapter.ts +711 -0
  384. package/src/db/adapters/drizzle-adapter/index.ts +1 -0
  385. package/src/db/adapters/kysely-adapter/dialect.ts +192 -0
  386. package/src/db/adapters/kysely-adapter/index.ts +3 -0
  387. package/src/db/adapters/kysely-adapter/kysely-adapter.ts +1168 -0
  388. package/src/db/adapters/kysely-adapter/types.ts +307 -0
  389. package/src/db/adapters/memory-adapter/index.ts +1 -0
  390. package/src/db/adapters/memory-adapter/memory-adapter.ts +648 -0
  391. package/src/db/adapters/prisma-adapter/index.ts +1 -0
  392. package/src/db/adapters/prisma-adapter/prisma-adapter.ts +586 -0
  393. package/src/db/adapters/types.ts +203 -0
  394. package/src/db/adapters/utils.ts +51 -0
  395. package/src/db/core/fields/field-factory.ts +804 -0
  396. package/src/db/core/fields/field-inference.ts +298 -0
  397. package/src/db/core/fields/field-options-integration.ts +135 -0
  398. package/src/db/core/fields/field-types.ts +233 -0
  399. package/src/db/core/fields/id-generator.ts +57 -0
  400. package/src/db/core/fields/index.ts +56 -0
  401. package/src/db/core/fields/superjson-utils.ts +155 -0
  402. package/src/db/core/fields/zod-fields.ts +269 -0
  403. package/src/db/core/get-schema.ts +102 -0
  404. package/src/db/core/types.ts +52 -0
  405. package/src/db/create-registry.ts +31 -0
  406. package/src/db/hooks/create-hooks.ts +88 -0
  407. package/src/db/hooks/index.ts +39 -0
  408. package/src/db/hooks/types.ts +164 -0
  409. package/src/db/hooks/update-hooks.ts +91 -0
  410. package/src/db/hooks/update-many-hooks.ts +176 -0
  411. package/src/db/hooks/utils.ts +151 -0
  412. package/src/db/hooks/with-hooks-factory.ts +68 -0
  413. package/src/db/index.ts +32 -0
  414. package/src/db/migration/get-migration.ts +89 -0
  415. package/src/db/migration/get-schema/get-schema.ts +44 -0
  416. package/src/db/migration/get-schema/index.ts +20 -0
  417. package/src/db/migration/get-schema/process-fields.ts +66 -0
  418. package/src/db/migration/get-schema/process-tables.ts +68 -0
  419. package/src/db/migration/get-schema/types.ts +18 -0
  420. package/src/db/migration/index.ts +18 -0
  421. package/src/db/migration/migration-builders.ts +170 -0
  422. package/src/db/migration/migration-execution.ts +79 -0
  423. package/src/db/migration/schema-comparison.ts +216 -0
  424. package/src/db/migration/type-mapping.ts +255 -0
  425. package/src/db/migration/types.ts +46 -0
  426. package/src/db/schema/audit-log/index.ts +3 -0
  427. package/src/db/schema/audit-log/registry.ts +228 -0
  428. package/src/db/schema/audit-log/schema.ts +46 -0
  429. package/src/db/schema/audit-log/table.ts +185 -0
  430. package/src/db/schema/audit-log/types.ts +29 -0
  431. package/src/db/schema/consent/index.ts +3 -0
  432. package/src/db/schema/consent/registry.ts +381 -0
  433. package/src/db/schema/consent/schema.ts +65 -0
  434. package/src/db/schema/consent/table.ts +220 -0
  435. package/src/db/schema/consent/types.ts +39 -0
  436. package/src/db/schema/consent-geo-location/index.ts +3 -0
  437. package/src/db/schema/consent-geo-location/registry.ts +124 -0
  438. package/src/db/schema/consent-geo-location/schema.ts +51 -0
  439. package/src/db/schema/consent-geo-location/table.ts +169 -0
  440. package/src/db/schema/consent-geo-location/types.ts +21 -0
  441. package/src/db/schema/consent-policy/index.ts +3 -0
  442. package/src/db/schema/consent-policy/registry.ts +313 -0
  443. package/src/db/schema/consent-policy/schema.ts +47 -0
  444. package/src/db/schema/consent-policy/table.ts +141 -0
  445. package/src/db/schema/consent-policy/types.ts +28 -0
  446. package/src/db/schema/consent-purpose/index.ts +3 -0
  447. package/src/db/schema/consent-purpose/registry.ts +188 -0
  448. package/src/db/schema/consent-purpose/schema.ts +58 -0
  449. package/src/db/schema/consent-purpose/table.ts +154 -0
  450. package/src/db/schema/consent-purpose/types.ts +16 -0
  451. package/src/db/schema/consent-purpose-junction/index.ts +3 -0
  452. package/src/db/schema/consent-purpose-junction/registry.ts +189 -0
  453. package/src/db/schema/consent-purpose-junction/schema.ts +49 -0
  454. package/src/db/schema/consent-purpose-junction/table.ts +142 -0
  455. package/src/db/schema/consent-purpose-junction/types.ts +14 -0
  456. package/src/db/schema/consent-record/index.ts +3 -0
  457. package/src/db/schema/consent-record/registry.ts +209 -0
  458. package/src/db/schema/consent-record/schema.ts +42 -0
  459. package/src/db/schema/consent-record/table.ts +124 -0
  460. package/src/db/schema/consent-record/types.ts +21 -0
  461. package/src/db/schema/consent-withdrawal/index.ts +3 -0
  462. package/src/db/schema/consent-withdrawal/registry.ts +219 -0
  463. package/src/db/schema/consent-withdrawal/schema.ts +48 -0
  464. package/src/db/schema/consent-withdrawal/table.ts +181 -0
  465. package/src/db/schema/consent-withdrawal/types.ts +29 -0
  466. package/src/db/schema/definition.ts +196 -0
  467. package/src/db/schema/domain/index.ts +3 -0
  468. package/src/db/schema/domain/registry.ts +272 -0
  469. package/src/db/schema/domain/schema.ts +43 -0
  470. package/src/db/schema/domain/table.ts +137 -0
  471. package/src/db/schema/domain/types.ts +27 -0
  472. package/src/db/schema/geo-location/index.ts +3 -0
  473. package/src/db/schema/geo-location/registry.ts +159 -0
  474. package/src/db/schema/geo-location/schema.ts +45 -0
  475. package/src/db/schema/geo-location/table.ts +148 -0
  476. package/src/db/schema/geo-location/types.ts +18 -0
  477. package/src/db/schema/index.ts +96 -0
  478. package/src/db/schema/parser.ts +417 -0
  479. package/src/db/schema/schemas.ts +35 -0
  480. package/src/db/schema/subject/index.ts +3 -0
  481. package/src/db/schema/subject/registry.ts +371 -0
  482. package/src/db/schema/subject/schema.ts +41 -0
  483. package/src/db/schema/subject/table.ts +139 -0
  484. package/src/db/schema/subject/types.ts +22 -0
  485. package/src/db/schema/types.ts +154 -0
  486. package/src/db/utils/adapter-factory.ts +64 -0
  487. package/src/db/utils/index.ts +10 -0
  488. package/src/db/utils.ts +42 -0
  489. package/src/docs/ADVANCED_JSON_HANDLING.md +99 -0
  490. package/src/docs/neverthrow.md +171 -0
  491. package/src/error/codes.ts +201 -0
  492. package/src/error/error.ts +145 -0
  493. package/src/error/index.ts +23 -0
  494. package/src/error/logging.ts +52 -0
  495. package/src/error/pipeline.ts +57 -0
  496. package/src/error/recovery.ts +45 -0
  497. package/src/error/results.ts +100 -0
  498. package/src/index.ts +79 -0
  499. package/src/init.test.ts +235 -0
  500. package/src/init.ts +261 -0
  501. package/src/integrations/index.ts +10 -0
  502. package/src/integrations/next.ts +136 -0
  503. package/src/integrations/react.ts +567 -0
  504. package/src/plugins/geo/index.ts +563 -0
  505. package/src/test/utils.ts +244 -0
  506. package/src/types/api.ts +101 -0
  507. package/src/types/context.ts +235 -0
  508. package/src/types/helper.ts +87 -0
  509. package/src/types/index.ts +5 -0
  510. package/src/types/options.ts +189 -0
  511. package/src/types/plugins.ts +538 -0
  512. package/src/utils/env.ts +103 -0
  513. package/src/utils/hide-metadata.ts +21 -0
  514. package/src/utils/index.ts +17 -0
  515. package/src/utils/ip.ts +45 -0
  516. package/src/utils/json.ts +19 -0
  517. package/src/utils/logger.ts +252 -0
  518. package/src/utils/url.ts +194 -0
  519. package/src/utils/wildcard.ts +253 -0
  520. package/tsconfig.json +12 -0
  521. package/vitest.config.ts +14 -0
@@ -0,0 +1,1489 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__ from "drizzle-orm";
2
+ import "neverthrow";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_zod__ from "zod";
4
+ import "superjson";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_base_x_aeb88370__ from "base-x";
6
+ import "node:crypto";
7
+ import "kysely";
8
+ const codes_BASE_ERROR_CODES = {
9
+ NOT_FOUND: 'Resource not found',
10
+ BAD_REQUEST: 'Bad request',
11
+ CONFLICT: 'Conflict with current state',
12
+ CONSENT_NOT_FOUND: 'Consent not found',
13
+ CONSENT_EXPIRED: 'Consent has expired',
14
+ FAILED_TO_CREATE_CONSENT: 'Failed to create consent',
15
+ FAILED_TO_UPDATE_CONSENT: 'Failed to update consent',
16
+ FAILED_TO_GET_CONSENT: 'Failed to get consent',
17
+ FAILED_TO_CREATE_PURPOSE: 'Failed to create consentPurpose',
18
+ PURPOSE_NOT_FOUND: 'Consent Purpose not found',
19
+ INVALID_CONFIGURATION: 'Invalid configuration',
20
+ MISSING_REQUIRED_PARAMETER: 'Missing required parameter',
21
+ UNAUTHORIZED: 'Unauthorized',
22
+ FORBIDDEN: 'Forbidden',
23
+ INTERNAL_SERVER_ERROR: 'Internal server error',
24
+ INITIALIZATION_FAILED: 'Initialization failed',
25
+ PLUGIN_INITIALIZATION_FAILED: 'Plugin initialization failed',
26
+ DATABASE_CONNECTION_ERROR: 'Database connection error',
27
+ DATABASE_QUERY_ERROR: 'Database query error',
28
+ REQUEST_HANDLER_ERROR: 'Request handler error',
29
+ API_RETRIEVAL_ERROR: 'API retrieval error',
30
+ INVALID_REQUEST: 'Invalid request',
31
+ UNKNOWN_ERROR: 'Unknown error'
32
+ };
33
+ class error_C15TError extends Error {
34
+ code;
35
+ status;
36
+ data;
37
+ category;
38
+ constructor(message, options){
39
+ super(message);
40
+ this.name = 'C15TError';
41
+ if (options) {
42
+ this.code = options.code;
43
+ this.status = options.status;
44
+ this.data = options.data;
45
+ this.category = options.category;
46
+ }
47
+ Object.setPrototypeOf(this, error_C15TError.prototype);
48
+ }
49
+ static fromResponse(response, data) {
50
+ let message = `HTTP error ${response.status}`;
51
+ let code;
52
+ let errorData;
53
+ if (data && 'object' == typeof data && null !== data) {
54
+ const errorObj = data;
55
+ if ('string' == typeof errorObj.message) message = errorObj.message;
56
+ if ('string' == typeof errorObj.code) {
57
+ const isKnownCode = Object.values(codes_BASE_ERROR_CODES).includes(errorObj.code);
58
+ if (isKnownCode) code = errorObj.code;
59
+ }
60
+ if ('object' == typeof errorObj.data && null !== errorObj.data) errorData = errorObj.data;
61
+ }
62
+ return new error_C15TError(message, {
63
+ code,
64
+ status: response.status,
65
+ data: errorData
66
+ });
67
+ }
68
+ static isC15TError(error) {
69
+ return error instanceof error_C15TError;
70
+ }
71
+ }
72
+ const definition_getConsentTables = (options)=>{
73
+ const pluginSchema = options.plugins?.reduce((acc, plugin)=>{
74
+ const schema = plugin.schema;
75
+ if (!schema) return acc;
76
+ for (const [key, value] of Object.entries(schema))acc[key] = {
77
+ fields: {
78
+ ...acc[key]?.fields,
79
+ ...value.fields
80
+ },
81
+ entityName: value.entityName || key
82
+ };
83
+ return acc;
84
+ }, {});
85
+ const { subject, consentPurpose, consentPolicy, domain, geoLocation, consent, consentPurposeJunction, record, consentGeoLocation, consentWithdrawal, auditLog, ...pluginTables } = pluginSchema || {};
86
+ return {
87
+ subject: getSubjectTable(options, subject?.fields),
88
+ consentPurpose: getPurposeTable(options, consentPurpose?.fields),
89
+ consentPolicy: getConsentPolicyTable(options, consentPolicy?.fields),
90
+ domain: getDomainTable(options, domain?.fields),
91
+ consent: getConsentTable(options, consent?.fields),
92
+ consentPurposeJunction: getPurposeJunctionTable(options, consentPurposeJunction?.fields),
93
+ consentRecord: getConsentRecordTable(options, record?.fields),
94
+ consentGeoLocation: getConsentGeoLocationTable(options, consentGeoLocation?.fields),
95
+ consentWithdrawal: getConsentWithdrawalTable(options, consentWithdrawal?.fields),
96
+ auditLog: getAuditLogTable(options, auditLog?.fields),
97
+ geoLocation: getGeoLocationTable(options, geoLocation?.fields),
98
+ ...pluginTables
99
+ };
100
+ };
101
+ const auditLogSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
102
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
103
+ entityType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
104
+ entityId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
105
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
106
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
107
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
108
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
109
+ changes: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
110
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
111
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
112
+ });
113
+ const fieldConfigSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
114
+ required: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
115
+ returned: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
116
+ input: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
117
+ defaultValue: __WEBPACK_EXTERNAL_MODULE_zod__.z.union([
118
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
119
+ __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
120
+ ]).optional(),
121
+ transform: __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
122
+ input: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
123
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
124
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.promise(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
125
+ ])).optional(),
126
+ output: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
127
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
128
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.promise(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
129
+ ])).optional()
130
+ }).optional(),
131
+ validator: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
132
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
133
+ __WEBPACK_EXTERNAL_MODULE_zod__.z["null"]()
134
+ ])).optional(),
135
+ unique: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().optional(),
136
+ indexed: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().optional(),
137
+ sortable: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
138
+ fieldName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
139
+ bigint: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false)
140
+ });
141
+ const stringFieldSchema = fieldConfigSchema.extend({
142
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('string'),
143
+ minLength: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
144
+ maxLength: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
145
+ pattern: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional()
146
+ });
147
+ const numberFieldSchema = fieldConfigSchema.extend({
148
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('number'),
149
+ min: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
150
+ max: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional()
151
+ });
152
+ const booleanFieldSchema = fieldConfigSchema.extend({
153
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('boolean')
154
+ });
155
+ const dateFieldSchema = fieldConfigSchema.extend({
156
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('date'),
157
+ minDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
158
+ maxDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
159
+ dateOnly: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
160
+ format: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional()
161
+ });
162
+ const timezoneFieldSchema = fieldConfigSchema.extend({
163
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('timezone'),
164
+ validateTimezone: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
165
+ suggestedValues: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional(),
166
+ restrictToSuggestedValues: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false)
167
+ });
168
+ const jsonFieldSchema = fieldConfigSchema.extend({
169
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('json'),
170
+ validateJson: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true)
171
+ });
172
+ const stringArrayFieldSchema = fieldConfigSchema.extend({
173
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('string[]')
174
+ });
175
+ const numberArrayFieldSchema = fieldConfigSchema.extend({
176
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('number[]')
177
+ });
178
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.discriminatedUnion('type', [
179
+ stringFieldSchema,
180
+ numberFieldSchema,
181
+ booleanFieldSchema,
182
+ dateFieldSchema,
183
+ timezoneFieldSchema,
184
+ jsonFieldSchema,
185
+ stringArrayFieldSchema,
186
+ numberArrayFieldSchema
187
+ ]);
188
+ const COMMON_TIMEZONES = {
189
+ UTC: 'UTC',
190
+ GMT: 'GMT',
191
+ EASTERN: 'America/New_York',
192
+ CENTRAL: 'America/Chicago',
193
+ MOUNTAIN: 'America/Denver',
194
+ PACIFIC: 'America/Los_Angeles',
195
+ LONDON: 'Europe/London',
196
+ PARIS: 'Europe/Paris',
197
+ BERLIN: 'Europe/Berlin',
198
+ TOKYO: 'Asia/Tokyo',
199
+ SHANGHAI: 'Asia/Shanghai',
200
+ SINGAPORE: 'Asia/Singapore',
201
+ SYDNEY: 'Australia/Sydney',
202
+ SAO_PAULO: 'America/Sao_Paulo'
203
+ };
204
+ const b58 = (0, __WEBPACK_EXTERNAL_MODULE_base_x_aeb88370__["default"])('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
205
+ function id_generator_generateId(prefix) {
206
+ const buf = crypto.getRandomValues(new Uint8Array(20));
207
+ const EPOCH_TIMESTAMP = 1700000000000;
208
+ const t = Date.now() - EPOCH_TIMESTAMP;
209
+ const high = Math.floor(t / 0x100000000);
210
+ const low = t >>> 0;
211
+ buf[0] = high >>> 24 & 255;
212
+ buf[1] = high >>> 16 & 255;
213
+ buf[2] = high >>> 8 & 255;
214
+ buf[3] = 255 & high;
215
+ buf[4] = low >>> 24 & 255;
216
+ buf[5] = low >>> 16 & 255;
217
+ buf[6] = low >>> 8 & 255;
218
+ buf[7] = 255 & low;
219
+ return `${prefix}_${b58.encode(buf)}`;
220
+ }
221
+ function getAuditLogTable(options, auditLogFields) {
222
+ const auditLogConfig = options.tables?.auditLog;
223
+ const subjectConfig = options.tables?.subject;
224
+ return {
225
+ entityName: auditLogConfig?.entityName || 'auditLog',
226
+ entityPrefix: auditLogConfig?.entityPrefix || 'log',
227
+ schema: auditLogSchema,
228
+ fields: {
229
+ entityType: {
230
+ type: 'string',
231
+ required: true,
232
+ fieldName: auditLogConfig?.fields?.entityType || 'entityType'
233
+ },
234
+ entityId: {
235
+ type: 'string',
236
+ required: true,
237
+ fieldName: auditLogConfig?.fields?.entityId || 'entityId'
238
+ },
239
+ actionType: {
240
+ type: 'string',
241
+ required: true,
242
+ fieldName: auditLogConfig?.fields?.actionType || 'actionType'
243
+ },
244
+ subjectId: {
245
+ type: 'string',
246
+ required: false,
247
+ fieldName: auditLogConfig?.fields?.subjectId || 'subjectId',
248
+ references: {
249
+ model: subjectConfig?.entityName || 'subject',
250
+ field: 'id'
251
+ }
252
+ },
253
+ ipAddress: {
254
+ type: 'string',
255
+ required: false,
256
+ fieldName: auditLogConfig?.fields?.ipAddress || 'ipAddress'
257
+ },
258
+ userAgent: {
259
+ type: 'string',
260
+ required: false,
261
+ fieldName: auditLogConfig?.fields?.userAgent || 'userAgent'
262
+ },
263
+ changes: {
264
+ type: 'json',
265
+ required: false,
266
+ fieldName: auditLogConfig?.fields?.changes || 'changes'
267
+ },
268
+ metadata: {
269
+ type: 'json',
270
+ required: false,
271
+ fieldName: auditLogConfig?.fields?.metadata || 'metadata'
272
+ },
273
+ createdAt: {
274
+ type: 'date',
275
+ defaultValue: ()=>new Date(),
276
+ required: true,
277
+ fieldName: auditLogConfig?.fields?.createdAt || 'createdAt'
278
+ },
279
+ eventTimezone: {
280
+ type: 'timezone',
281
+ required: true,
282
+ defaultValue: COMMON_TIMEZONES.UTC,
283
+ fieldName: auditLogConfig?.fields?.eventTimezone || 'eventTimezone'
284
+ },
285
+ ...auditLogFields || {},
286
+ ...auditLogConfig?.additionalFields || {}
287
+ },
288
+ indexes: [
289
+ {
290
+ name: 'entity_index',
291
+ fields: [
292
+ 'entityType',
293
+ 'entityId'
294
+ ]
295
+ },
296
+ {
297
+ name: 'action_type_index',
298
+ fields: [
299
+ 'actionType'
300
+ ]
301
+ },
302
+ {
303
+ name: 'subject_id_index',
304
+ fields: [
305
+ 'subjectId'
306
+ ]
307
+ },
308
+ {
309
+ name: 'created_at_index',
310
+ fields: [
311
+ 'createdAt'
312
+ ]
313
+ }
314
+ ],
315
+ order: 5
316
+ };
317
+ }
318
+ const consentGeoLocationSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
319
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
320
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
321
+ ip: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().ip(),
322
+ country: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
323
+ region: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
324
+ city: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
325
+ latitude: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().min(-90).max(90).optional(),
326
+ longitude: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().min(-180).max(180).optional(),
327
+ timezone: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().regex(/^[A-Za-z_]+\/[A-Za-z_]+$/).optional(),
328
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
329
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
330
+ });
331
+ function getConsentGeoLocationTable(options, geoLocationFields) {
332
+ const consentGeoLocationConfig = options.tables?.consentGeoLocation;
333
+ const consentConfig = options.tables?.consent;
334
+ return {
335
+ entityName: consentGeoLocationConfig?.entityName || 'consentGeoLocation',
336
+ entityPrefix: consentGeoLocationConfig?.entityPrefix || 'cgl',
337
+ schema: consentGeoLocationSchema,
338
+ fields: {
339
+ consentId: {
340
+ type: 'string',
341
+ required: true,
342
+ fieldName: consentGeoLocationConfig?.fields?.consentId || 'consentId',
343
+ references: {
344
+ model: consentConfig?.entityName || 'consent',
345
+ field: 'id'
346
+ }
347
+ },
348
+ ip: {
349
+ type: 'string',
350
+ required: true,
351
+ fieldName: consentGeoLocationConfig?.fields?.ip || 'ip'
352
+ },
353
+ country: {
354
+ type: 'string',
355
+ required: false,
356
+ fieldName: consentGeoLocationConfig?.fields?.country || 'country'
357
+ },
358
+ region: {
359
+ type: 'string',
360
+ required: false,
361
+ fieldName: consentGeoLocationConfig?.fields?.region || 'region'
362
+ },
363
+ city: {
364
+ type: 'string',
365
+ required: false,
366
+ fieldName: consentGeoLocationConfig?.fields?.city || 'city'
367
+ },
368
+ latitude: {
369
+ type: 'number',
370
+ required: false,
371
+ fieldName: consentGeoLocationConfig?.fields?.latitude || 'latitude'
372
+ },
373
+ longitude: {
374
+ type: 'number',
375
+ required: false,
376
+ fieldName: consentGeoLocationConfig?.fields?.longitude || 'longitude'
377
+ },
378
+ timezone: {
379
+ type: 'string',
380
+ required: false,
381
+ fieldName: consentGeoLocationConfig?.fields?.timezone || 'timezone'
382
+ },
383
+ createdAt: {
384
+ type: 'date',
385
+ defaultValue: ()=>new Date(),
386
+ required: true,
387
+ fieldName: consentGeoLocationConfig?.fields?.createdAt || 'createdAt'
388
+ },
389
+ ...geoLocationFields || {},
390
+ ...consentGeoLocationConfig?.additionalFields || {}
391
+ },
392
+ indexes: [
393
+ {
394
+ name: 'consent_id_index',
395
+ fields: [
396
+ 'consentId'
397
+ ]
398
+ },
399
+ {
400
+ name: 'country_index',
401
+ fields: [
402
+ 'country'
403
+ ]
404
+ },
405
+ {
406
+ name: 'created_at_index',
407
+ fields: [
408
+ 'createdAt'
409
+ ]
410
+ }
411
+ ],
412
+ order: 4
413
+ };
414
+ }
415
+ const consentPolicySchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
416
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
417
+ version: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
418
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
419
+ effectiveDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date(),
420
+ expirationDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().nullable().optional(),
421
+ content: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
422
+ contentHash: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
423
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
424
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
425
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
426
+ });
427
+ function getConsentPolicyTable(options, policyFields) {
428
+ const consentPolicyConfig = options.tables?.consentPolicy;
429
+ return {
430
+ entityName: consentPolicyConfig?.entityName || 'consentPolicy',
431
+ entityPrefix: consentPolicyConfig?.entityPrefix || 'pol',
432
+ schema: consentPolicySchema,
433
+ fields: {
434
+ version: {
435
+ type: 'string',
436
+ required: true,
437
+ fieldName: consentPolicyConfig?.fields?.version || 'version'
438
+ },
439
+ name: {
440
+ type: 'string',
441
+ required: true,
442
+ fieldName: consentPolicyConfig?.fields?.name || 'name'
443
+ },
444
+ effectiveDate: {
445
+ type: 'date',
446
+ required: true,
447
+ fieldName: consentPolicyConfig?.fields?.effectiveDate || 'effectiveDate'
448
+ },
449
+ expirationDate: {
450
+ type: 'date',
451
+ required: false,
452
+ fieldName: consentPolicyConfig?.fields?.expirationDate || 'expirationDate'
453
+ },
454
+ content: {
455
+ type: 'string',
456
+ required: true,
457
+ fieldName: consentPolicyConfig?.fields?.content || 'content'
458
+ },
459
+ contentHash: {
460
+ type: 'string',
461
+ required: true,
462
+ fieldName: consentPolicyConfig?.fields?.contentHash || 'contentHash'
463
+ },
464
+ isActive: {
465
+ type: 'boolean',
466
+ defaultValue: true,
467
+ required: true,
468
+ fieldName: consentPolicyConfig?.fields?.isActive || 'isActive'
469
+ },
470
+ createdAt: {
471
+ type: 'date',
472
+ defaultValue: ()=>new Date(),
473
+ required: true,
474
+ fieldName: consentPolicyConfig?.fields?.createdAt || 'createdAt'
475
+ },
476
+ ...policyFields || {},
477
+ ...consentPolicyConfig?.additionalFields || {}
478
+ },
479
+ order: 2
480
+ };
481
+ }
482
+ const consentPurposeJunctionSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
483
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
484
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
485
+ consentPurposeId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
486
+ status: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
487
+ 'active',
488
+ 'withdrawn'
489
+ ], {
490
+ errorMap: ()=>({
491
+ message: "Status must be either 'active' or 'withdrawn'"
492
+ })
493
+ }).default('active'),
494
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
495
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
496
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.number(),
497
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean()
498
+ ])).optional(),
499
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
500
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
501
+ });
502
+ function getPurposeJunctionTable(options, junctionFields) {
503
+ const purposeJunctionConfig = options.tables?.consentPurposeJunction;
504
+ const consentConfig = options.tables?.consent;
505
+ const purposeConfig = options.tables?.consentPurpose;
506
+ return {
507
+ entityName: purposeJunctionConfig?.entityName || 'consentPurposeJunction',
508
+ entityPrefix: purposeJunctionConfig?.entityPrefix || 'pjx',
509
+ schema: consentPurposeJunctionSchema,
510
+ fields: {
511
+ consentId: {
512
+ type: 'string',
513
+ required: true,
514
+ fieldName: purposeJunctionConfig?.fields?.consentId || 'consentId',
515
+ references: {
516
+ model: consentConfig?.entityName || 'consent',
517
+ field: 'id'
518
+ }
519
+ },
520
+ purposeId: {
521
+ type: 'string',
522
+ required: true,
523
+ fieldName: purposeJunctionConfig?.fields?.purposeId || 'purposeId',
524
+ references: {
525
+ model: purposeConfig?.entityName || 'consentPurpose',
526
+ field: 'id'
527
+ }
528
+ },
529
+ status: {
530
+ type: 'string',
531
+ defaultValue: ()=>'active',
532
+ required: true,
533
+ fieldName: purposeJunctionConfig?.fields?.status || 'status'
534
+ },
535
+ metadata: {
536
+ type: 'json',
537
+ required: false,
538
+ fieldName: purposeJunctionConfig?.fields?.metadata || 'metadata'
539
+ },
540
+ createdAt: {
541
+ type: 'date',
542
+ defaultValue: ()=>new Date(),
543
+ required: true,
544
+ fieldName: purposeJunctionConfig?.fields?.createdAt || 'createdAt'
545
+ },
546
+ updatedAt: {
547
+ type: 'date',
548
+ required: false,
549
+ fieldName: purposeJunctionConfig?.fields?.updatedAt || 'updatedAt'
550
+ },
551
+ ...junctionFields || {},
552
+ ...purposeJunctionConfig?.additionalFields || {}
553
+ },
554
+ uniqueConstraints: [
555
+ {
556
+ name: 'unique_consent_purpose',
557
+ fields: [
558
+ 'consentId',
559
+ 'purposeId'
560
+ ]
561
+ }
562
+ ],
563
+ order: 4
564
+ };
565
+ }
566
+ const purposeSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
567
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
568
+ code: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
569
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
570
+ description: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
571
+ isEssential: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
572
+ dataCategory: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
573
+ legalBasis: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
574
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
575
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
576
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
577
+ });
578
+ function getPurposeTable(options, purposeFields) {
579
+ const purposeConfig = options.tables?.consentPurpose;
580
+ return {
581
+ entityName: purposeConfig?.entityName || 'consentPurpose',
582
+ entityPrefix: purposeConfig?.entityPrefix || 'pur',
583
+ schema: purposeSchema,
584
+ fields: {
585
+ code: {
586
+ type: 'string',
587
+ required: true,
588
+ fieldName: purposeConfig?.fields?.code || 'code'
589
+ },
590
+ name: {
591
+ type: 'string',
592
+ required: true,
593
+ fieldName: purposeConfig?.fields?.name || 'name'
594
+ },
595
+ description: {
596
+ type: 'string',
597
+ required: true,
598
+ fieldName: purposeConfig?.fields?.description || "description"
599
+ },
600
+ isEssential: {
601
+ type: 'boolean',
602
+ defaultValue: ()=>false,
603
+ required: true,
604
+ fieldName: purposeConfig?.fields?.isEssential || 'isEssential'
605
+ },
606
+ dataCategory: {
607
+ type: 'string',
608
+ required: false,
609
+ fieldName: purposeConfig?.fields?.dataCategory || 'dataCategory'
610
+ },
611
+ legalBasis: {
612
+ type: 'string',
613
+ required: false,
614
+ fieldName: purposeConfig?.fields?.legalBasis || 'legalBasis'
615
+ },
616
+ isActive: {
617
+ type: 'boolean',
618
+ defaultValue: true,
619
+ required: true,
620
+ fieldName: purposeConfig?.fields?.isActive || 'isActive'
621
+ },
622
+ createdAt: {
623
+ type: 'date',
624
+ defaultValue: ()=>new Date(),
625
+ required: true,
626
+ fieldName: purposeConfig?.fields?.createdAt || 'createdAt'
627
+ },
628
+ updatedAt: {
629
+ type: 'date',
630
+ defaultValue: ()=>new Date(),
631
+ required: true,
632
+ fieldName: purposeConfig?.fields?.updatedAt || 'updatedAt'
633
+ },
634
+ ...purposeFields || {},
635
+ ...purposeConfig?.additionalFields || {}
636
+ },
637
+ order: 1
638
+ };
639
+ }
640
+ const consentRecordSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
641
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
642
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
643
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
644
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
645
+ details: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
646
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
647
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
648
+ });
649
+ function getConsentRecordTable(options, recordFields) {
650
+ const recordConfig = options.tables?.record;
651
+ const subjectConfig = options.tables?.subject;
652
+ const consentConfig = options.tables?.consent;
653
+ return {
654
+ entityName: recordConfig?.entityName || 'consentRecord',
655
+ entityPrefix: recordConfig?.entityPrefix || 'rec',
656
+ schema: consentRecordSchema,
657
+ fields: {
658
+ subjectId: {
659
+ type: 'string',
660
+ required: true,
661
+ fieldName: recordConfig?.fields?.subjectId || 'subjectId',
662
+ references: {
663
+ model: subjectConfig?.entityName || 'subject',
664
+ field: 'id'
665
+ }
666
+ },
667
+ consentId: {
668
+ type: 'string',
669
+ required: false,
670
+ fieldName: recordConfig?.fields?.consentId || 'consentId',
671
+ references: {
672
+ model: consentConfig?.entityName || 'consent',
673
+ field: 'id'
674
+ }
675
+ },
676
+ actionType: {
677
+ type: 'string',
678
+ required: true,
679
+ fieldName: recordConfig?.fields?.actionType || 'actionType'
680
+ },
681
+ details: {
682
+ type: 'json',
683
+ required: false,
684
+ fieldName: recordConfig?.fields?.details || 'details'
685
+ },
686
+ createdAt: {
687
+ type: 'date',
688
+ defaultValue: ()=>new Date(),
689
+ required: true,
690
+ fieldName: recordConfig?.fields?.createdAt || 'createdAt'
691
+ },
692
+ ...recordFields || {},
693
+ ...recordConfig?.additionalFields || {}
694
+ },
695
+ order: 4
696
+ };
697
+ }
698
+ const consentWithdrawalSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
699
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
700
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
701
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
702
+ withdrawalReason: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
703
+ withdrawalMethod: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
704
+ 'subject-initiated',
705
+ 'automatic-expiry',
706
+ 'admin',
707
+ 'api',
708
+ 'other'
709
+ ]).default('subject-initiated'),
710
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
711
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
712
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
713
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
714
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
715
+ });
716
+ function getConsentWithdrawalTable(options, withdrawalFields) {
717
+ const consentWithdrawalConfig = options.tables?.consentWithdrawal;
718
+ const consentConfig = options.tables?.consent;
719
+ const subjectConfig = options.tables?.subject;
720
+ return {
721
+ entityName: consentWithdrawalConfig?.entityName || 'consentWithdrawal',
722
+ entityPrefix: consentWithdrawalConfig?.entityPrefix || 'wdr',
723
+ schema: consentWithdrawalSchema,
724
+ fields: {
725
+ consentId: {
726
+ type: 'string',
727
+ required: true,
728
+ fieldName: consentWithdrawalConfig?.fields?.consentId || 'consentId',
729
+ references: {
730
+ model: consentConfig?.entityName || 'consent',
731
+ field: 'id'
732
+ }
733
+ },
734
+ subjectId: {
735
+ type: 'string',
736
+ required: true,
737
+ fieldName: consentWithdrawalConfig?.fields?.subjectId || 'subjectId',
738
+ references: {
739
+ model: subjectConfig?.entityName || 'subject',
740
+ field: 'id'
741
+ }
742
+ },
743
+ withdrawalReason: {
744
+ type: 'string',
745
+ required: false,
746
+ fieldName: consentWithdrawalConfig?.fields?.withdrawalReason || 'withdrawalReason'
747
+ },
748
+ withdrawalMethod: {
749
+ type: 'string',
750
+ defaultValue: ()=>'subject-initiated',
751
+ required: true,
752
+ fieldName: consentWithdrawalConfig?.fields?.withdrawalMethod || 'withdrawalMethod'
753
+ },
754
+ ipAddress: {
755
+ type: 'string',
756
+ required: false,
757
+ fieldName: consentWithdrawalConfig?.fields?.ipAddress || 'ipAddress'
758
+ },
759
+ userAgent: {
760
+ type: 'string',
761
+ required: false,
762
+ fieldName: consentWithdrawalConfig?.fields?.userAgent || 'userAgent'
763
+ },
764
+ metadata: {
765
+ type: 'json',
766
+ required: false,
767
+ fieldName: consentWithdrawalConfig?.fields?.metadata || 'metadata'
768
+ },
769
+ createdAt: {
770
+ type: 'date',
771
+ defaultValue: ()=>new Date(),
772
+ required: true,
773
+ fieldName: consentWithdrawalConfig?.fields?.createdAt || 'createdAt'
774
+ },
775
+ ...withdrawalFields || {},
776
+ ...consentWithdrawalConfig?.additionalFields || {}
777
+ },
778
+ uniqueConstraints: consentWithdrawalConfig?.preventMultipleWithdrawals !== false ? [
779
+ {
780
+ name: 'unique_consent_withdrawal',
781
+ fields: [
782
+ 'consentId'
783
+ ]
784
+ }
785
+ ] : [],
786
+ indexes: [
787
+ {
788
+ name: 'subject_id_index',
789
+ fields: [
790
+ 'subjectId'
791
+ ]
792
+ },
793
+ {
794
+ name: 'created_at_index',
795
+ fields: [
796
+ 'createdAt'
797
+ ]
798
+ }
799
+ ],
800
+ order: 4
801
+ };
802
+ }
803
+ const consentHistorySchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
804
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
805
+ 'given',
806
+ 'withdrawn',
807
+ 'updated',
808
+ 'expired'
809
+ ]),
810
+ timestamp: __WEBPACK_EXTERNAL_MODULE_zod__.z.date(),
811
+ details: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
812
+ previousState: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
813
+ newState: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional()
814
+ });
815
+ const consentSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
816
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
817
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
818
+ domainId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
819
+ purposeIds: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()),
820
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
821
+ policyId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
822
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
823
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
824
+ status: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
825
+ 'active',
826
+ 'withdrawn',
827
+ 'expired'
828
+ ]).default('active'),
829
+ withdrawalReason: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
830
+ givenAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
831
+ validUntil: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
832
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
833
+ history: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(consentHistorySchema).default([])
834
+ });
835
+ function getConsentTable(options, consentFields) {
836
+ const consentConfig = options.tables?.consent;
837
+ const subjectConfig = options.tables?.subject;
838
+ const domainConfig = options.tables?.domain;
839
+ const policyConfig = options.tables?.consentPolicy;
840
+ const purposeConfig = options.tables?.consentPurpose;
841
+ return {
842
+ entityName: consentConfig?.entityName || 'consent',
843
+ entityPrefix: consentConfig?.entityPrefix || 'cns',
844
+ schema: consentSchema,
845
+ fields: {
846
+ subjectId: {
847
+ type: 'string',
848
+ required: true,
849
+ fieldName: consentConfig?.fields?.subjectId || 'subjectId',
850
+ references: {
851
+ model: subjectConfig?.entityName || 'subject',
852
+ field: 'id'
853
+ }
854
+ },
855
+ domainId: {
856
+ type: 'string',
857
+ required: true,
858
+ fieldName: consentConfig?.fields?.domainId || 'domainId',
859
+ references: {
860
+ model: domainConfig?.entityName || 'domain',
861
+ field: 'id'
862
+ }
863
+ },
864
+ purposeIds: {
865
+ type: 'json',
866
+ required: false,
867
+ fieldName: consentConfig?.fields?.purposeIds || 'purposeIds',
868
+ references: {
869
+ model: purposeConfig?.entityName || 'consentPurpose',
870
+ field: 'id',
871
+ type: 'array'
872
+ }
873
+ },
874
+ metadata: {
875
+ type: 'json',
876
+ required: false,
877
+ fieldName: consentConfig?.fields?.metadata || 'metadata'
878
+ },
879
+ policyId: {
880
+ type: 'string',
881
+ required: false,
882
+ fieldName: consentConfig?.fields?.policyId || 'policyId',
883
+ references: {
884
+ model: policyConfig?.entityName || 'consentPolicy',
885
+ field: 'id'
886
+ }
887
+ },
888
+ ipAddress: {
889
+ type: 'string',
890
+ required: false,
891
+ fieldName: consentConfig?.fields?.ipAddress || 'ipAddress'
892
+ },
893
+ userAgent: {
894
+ type: 'string',
895
+ required: false,
896
+ fieldName: consentConfig?.fields?.userAgent || 'userAgent'
897
+ },
898
+ status: {
899
+ type: 'string',
900
+ defaultValue: ()=>'active',
901
+ required: true,
902
+ fieldName: consentConfig?.fields?.status || 'status'
903
+ },
904
+ withdrawalReason: {
905
+ type: 'string',
906
+ required: false,
907
+ fieldName: consentConfig?.fields?.withdrawalReason || 'withdrawalReason'
908
+ },
909
+ givenAt: {
910
+ type: 'date',
911
+ defaultValue: ()=>new Date(),
912
+ required: true,
913
+ fieldName: consentConfig?.fields?.givenAt || 'givenAt'
914
+ },
915
+ validUntil: {
916
+ type: 'date',
917
+ required: false,
918
+ fieldName: consentConfig?.fields?.validUntil || 'validUntil',
919
+ transform: {
920
+ input: (val, data)=>{
921
+ if (val) return val;
922
+ const expiresIn = consentConfig?.expiresIn || 31536000;
923
+ const givenAt = data.givenAt instanceof Date ? data.givenAt : new Date();
924
+ if (expiresIn > 0) {
925
+ const validUntil = new Date(givenAt);
926
+ validUntil.setSeconds(validUntil.getSeconds() + expiresIn);
927
+ return validUntil;
928
+ }
929
+ }
930
+ }
931
+ },
932
+ isActive: {
933
+ type: 'boolean',
934
+ defaultValue: true,
935
+ required: true,
936
+ fieldName: consentConfig?.fields?.isActive || 'isActive'
937
+ },
938
+ ...consentFields || {},
939
+ ...consentConfig?.additionalFields || {}
940
+ },
941
+ order: 3
942
+ };
943
+ }
944
+ const domainSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
945
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
946
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().min(1),
947
+ description: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
948
+ allowedOrigins: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional().default([]),
949
+ isVerified: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
950
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
951
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
952
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
953
+ });
954
+ function getDomainTable(options, domainFields) {
955
+ const domainConfig = options.tables?.domain;
956
+ return {
957
+ entityName: domainConfig?.entityName || 'domain',
958
+ entityPrefix: domainConfig?.entityPrefix || 'dom',
959
+ schema: domainSchema,
960
+ fields: {
961
+ name: {
962
+ type: 'string',
963
+ required: true,
964
+ unique: true,
965
+ fieldName: domainConfig?.fields?.name || 'name'
966
+ },
967
+ description: {
968
+ type: 'string',
969
+ required: false,
970
+ fieldName: domainConfig?.fields?.description || "description"
971
+ },
972
+ allowedOrigins: {
973
+ type: 'json',
974
+ defaultValue: ()=>[],
975
+ required: false,
976
+ fieldName: domainConfig?.fields?.allowedOrigins || 'allowedOrigins'
977
+ },
978
+ isVerified: {
979
+ type: 'boolean',
980
+ defaultValue: true,
981
+ required: true,
982
+ fieldName: domainConfig?.fields?.isVerified || 'isVerified'
983
+ },
984
+ isActive: {
985
+ type: 'boolean',
986
+ defaultValue: true,
987
+ required: true,
988
+ fieldName: domainConfig?.fields?.isActive || 'isActive'
989
+ },
990
+ createdAt: {
991
+ type: 'date',
992
+ defaultValue: ()=>new Date(),
993
+ required: true,
994
+ fieldName: domainConfig?.fields?.createdAt || 'createdAt'
995
+ },
996
+ updatedAt: {
997
+ type: 'date',
998
+ required: false,
999
+ fieldName: domainConfig?.fields?.updatedAt || 'updatedAt'
1000
+ },
1001
+ ...domainFields || {},
1002
+ ...domainConfig?.additionalFields || {}
1003
+ },
1004
+ order: 1
1005
+ };
1006
+ }
1007
+ const geoLocationSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1008
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1009
+ countryCode: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().length(2).toUpperCase(),
1010
+ countryName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1011
+ regionCode: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1012
+ regionName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1013
+ regulatoryZones: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
1014
+ 'GDPR',
1015
+ 'CCPA',
1016
+ 'CPRA',
1017
+ 'LGPD',
1018
+ 'PIPEDA'
1019
+ ])).optional(),
1020
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
1021
+ });
1022
+ function getGeoLocationTable(options, geoLocationFields) {
1023
+ const geoLocationConfig = options.tables?.geoLocation;
1024
+ return {
1025
+ entityName: geoLocationConfig?.entityName || 'geoLocation',
1026
+ entityPrefix: geoLocationConfig?.entityPrefix || 'geo',
1027
+ schema: geoLocationSchema,
1028
+ fields: {
1029
+ countryCode: {
1030
+ type: 'string',
1031
+ required: true,
1032
+ fieldName: geoLocationConfig?.fields?.countryCode || 'countryCode'
1033
+ },
1034
+ countryName: {
1035
+ type: 'string',
1036
+ required: true,
1037
+ fieldName: geoLocationConfig?.fields?.countryName || 'countryName'
1038
+ },
1039
+ regionCode: {
1040
+ type: 'string',
1041
+ required: false,
1042
+ fieldName: geoLocationConfig?.fields?.regionCode || 'regionCode'
1043
+ },
1044
+ regionName: {
1045
+ type: 'string',
1046
+ required: false,
1047
+ fieldName: geoLocationConfig?.fields?.regionName || 'regionName'
1048
+ },
1049
+ regulatoryZones: {
1050
+ type: 'json',
1051
+ required: false,
1052
+ fieldName: geoLocationConfig?.fields?.regulatoryZones || 'regulatoryZones',
1053
+ transformer: {
1054
+ input: (value)=>JSON.stringify(value),
1055
+ output: (value)=>{
1056
+ try {
1057
+ return JSON.parse(value);
1058
+ } catch {
1059
+ return [];
1060
+ }
1061
+ }
1062
+ }
1063
+ },
1064
+ createdAt: {
1065
+ type: 'date',
1066
+ defaultValue: ()=>new Date(),
1067
+ required: true,
1068
+ fieldName: geoLocationConfig?.fields?.createdAt || 'createdAt'
1069
+ },
1070
+ ...geoLocationFields || {},
1071
+ ...geoLocationConfig?.additionalFields || {}
1072
+ },
1073
+ indexes: [
1074
+ {
1075
+ name: 'country_code_index',
1076
+ fields: [
1077
+ 'countryCode'
1078
+ ]
1079
+ },
1080
+ {
1081
+ name: 'region_code_index',
1082
+ fields: [
1083
+ 'regionCode'
1084
+ ]
1085
+ },
1086
+ {
1087
+ name: 'created_at_index',
1088
+ fields: [
1089
+ 'createdAt'
1090
+ ]
1091
+ }
1092
+ ],
1093
+ order: 1
1094
+ };
1095
+ }
1096
+ const subjectSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1097
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1098
+ isIdentified: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
1099
+ externalId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().nullable().optional(),
1100
+ identityProvider: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1101
+ lastIpAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1102
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
1103
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
1104
+ });
1105
+ function getSubjectTable(options, subjectFields) {
1106
+ const subjectConfig = options.tables?.subject;
1107
+ return {
1108
+ entityName: subjectConfig?.entityName || 'subject',
1109
+ entityPrefix: subjectConfig?.entityPrefix || 'sub',
1110
+ schema: subjectSchema,
1111
+ fields: {
1112
+ isIdentified: {
1113
+ type: 'boolean',
1114
+ defaultValue: ()=>false,
1115
+ required: true,
1116
+ fieldName: subjectConfig?.fields?.isIdentified || 'isIdentified'
1117
+ },
1118
+ externalId: {
1119
+ type: 'string',
1120
+ required: false,
1121
+ fieldName: subjectConfig?.fields?.externalId || 'externalId'
1122
+ },
1123
+ identityProvider: {
1124
+ type: 'string',
1125
+ required: false,
1126
+ fieldName: subjectConfig?.fields?.identityProvider || 'identityProvider'
1127
+ },
1128
+ lastIpAddress: {
1129
+ type: 'string',
1130
+ required: false,
1131
+ fieldName: subjectConfig?.fields?.lastIpAddress || 'lastIpAddress'
1132
+ },
1133
+ createdAt: {
1134
+ type: 'date',
1135
+ defaultValue: ()=>new Date(),
1136
+ required: true,
1137
+ fieldName: subjectConfig?.fields?.createdAt || 'createdAt'
1138
+ },
1139
+ updatedAt: {
1140
+ type: 'date',
1141
+ defaultValue: ()=>new Date(),
1142
+ required: true,
1143
+ fieldName: subjectConfig?.fields?.updatedAt || 'updatedAt'
1144
+ },
1145
+ subjectTimezone: {
1146
+ type: 'timezone',
1147
+ required: false,
1148
+ defaultValue: COMMON_TIMEZONES.UTC,
1149
+ fieldName: subjectConfig?.fields?.subjectTimezone || 'subjectTimezone'
1150
+ },
1151
+ ...subjectFields || {},
1152
+ ...subjectConfig?.additionalFields || {}
1153
+ },
1154
+ order: 1
1155
+ };
1156
+ }
1157
+ const levels = [
1158
+ 'info',
1159
+ 'success',
1160
+ 'warn',
1161
+ 'error',
1162
+ 'debug'
1163
+ ];
1164
+ function shouldPublishLog(currentLogLevel, logLevel) {
1165
+ return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
1166
+ }
1167
+ const colors = {
1168
+ reset: '\x1b[0m',
1169
+ bright: '\x1b[1m',
1170
+ dim: '\x1b[2m',
1171
+ underscore: '\x1b[4m',
1172
+ blink: '\x1b[5m',
1173
+ reverse: '\x1b[7m',
1174
+ hidden: '\x1b[8m',
1175
+ fg: {
1176
+ black: '\x1b[30m',
1177
+ red: '\x1b[31m',
1178
+ green: '\x1b[32m',
1179
+ yellow: '\x1b[33m',
1180
+ blue: '\x1b[34m',
1181
+ magenta: '\x1b[35m',
1182
+ cyan: '\x1b[36m',
1183
+ white: '\x1b[37m'
1184
+ },
1185
+ bg: {
1186
+ black: '\x1b[40m',
1187
+ red: '\x1b[41m',
1188
+ green: '\x1b[42m',
1189
+ yellow: '\x1b[43m',
1190
+ blue: '\x1b[44m',
1191
+ magenta: '\x1b[45m',
1192
+ cyan: '\x1b[46m',
1193
+ white: '\x1b[47m'
1194
+ }
1195
+ };
1196
+ const levelColors = {
1197
+ info: colors.fg.blue,
1198
+ success: colors.fg.green,
1199
+ warn: colors.fg.yellow,
1200
+ error: colors.fg.red,
1201
+ debug: colors.fg.magenta
1202
+ };
1203
+ const formatMessage = (level, message)=>{
1204
+ const timestamp = new Date().toISOString();
1205
+ return `${colors.dim}${timestamp}${colors.reset} ${levelColors[level]}${level.toUpperCase()}${colors.reset} ${colors.bright}[c15t]:${colors.reset} ${message}`;
1206
+ };
1207
+ const logger_createLogger = (options)=>{
1208
+ const enabled = options?.disabled !== true;
1209
+ const logLevel = options?.level ?? 'error';
1210
+ const LogFunc = (level, message, args = [])=>{
1211
+ if (!enabled || !shouldPublishLog(logLevel, level)) return;
1212
+ const formattedMessage = formatMessage(level, message);
1213
+ if (!options || 'function' != typeof options.log) {
1214
+ if ('error' === level) console.error(formattedMessage, ...args);
1215
+ else if ('warn' === level) console.warn(formattedMessage, ...args);
1216
+ else if ('info' === level) console.log(formattedMessage, ...args);
1217
+ else if ('debug' === level) console.debug(formattedMessage, ...args);
1218
+ else if ('success' === level) console.log(formattedMessage, ...args);
1219
+ return;
1220
+ }
1221
+ options.log('success' === level ? 'info' : level, message, ...args);
1222
+ };
1223
+ return Object.fromEntries(levels.map((level)=>[
1224
+ level,
1225
+ (...[message, ...args])=>LogFunc(level, message, args)
1226
+ ]));
1227
+ };
1228
+ logger_createLogger();
1229
+ function utils_applyDefaultValue(inputValue, field, operation) {
1230
+ if ('update' === operation) return inputValue;
1231
+ if (null == inputValue && field.defaultValue) {
1232
+ if ('function' == typeof field.defaultValue) return field.defaultValue();
1233
+ return field.defaultValue;
1234
+ }
1235
+ return inputValue;
1236
+ }
1237
+ const drizzle_adapter_rslib_entry_createEntityTransformer = (db, config, options)=>{
1238
+ const schema = definition_getConsentTables(options);
1239
+ function getField(model, field) {
1240
+ if ('id' === field) return field;
1241
+ const f = schema[model].fields[field];
1242
+ return f.fieldName || field;
1243
+ }
1244
+ function getSchema(entityName) {
1245
+ const schema = config.schema || db._.fullSchema;
1246
+ if (!schema) throw new error_C15TError('The schema could not be found. Please ensure the schema is properly configured in the adapter.', {
1247
+ code: codes_BASE_ERROR_CODES.DATABASE_CONNECTION_ERROR,
1248
+ status: 500,
1249
+ data: {
1250
+ provider: config.provider
1251
+ }
1252
+ });
1253
+ const model = getEntityName(entityName);
1254
+ const schemaModel = schema[model];
1255
+ if (!schemaModel) throw new error_C15TError(`The model "${model}" does not exist in the schema. Please verify the model name and ensure it is defined in your schema.`, {
1256
+ code: codes_BASE_ERROR_CODES.DATABASE_QUERY_ERROR,
1257
+ status: 404,
1258
+ data: {
1259
+ model,
1260
+ availableModels: Object.keys(schema)
1261
+ }
1262
+ });
1263
+ return schemaModel;
1264
+ }
1265
+ const getEntityName = (model)=>{
1266
+ if (schema[model].entityName !== model) return schema[model].entityName;
1267
+ if (config.usePlural) return `${model}s`;
1268
+ return model;
1269
+ };
1270
+ function convertWhereClause(where, model) {
1271
+ const schemaModel = getSchema(model);
1272
+ if (!where) return [];
1273
+ if (1 === where.length) {
1274
+ const w = where[0];
1275
+ if (!w) return [];
1276
+ const field = getField(model, w.field);
1277
+ if (!schemaModel[field]) throw new error_C15TError(`The field "${field}" does not exist in model "${model}". Please verify the field name and ensure it is defined in your schema.`, {
1278
+ code: codes_BASE_ERROR_CODES.DATABASE_QUERY_ERROR,
1279
+ status: 404,
1280
+ data: {
1281
+ model,
1282
+ field,
1283
+ availableFields: Object.keys(schemaModel)
1284
+ }
1285
+ });
1286
+ if ('in' === w.operator) {
1287
+ if (!Array.isArray(w.value)) throw new error_C15TError(`The value for the field "${field}" must be an array when using the "in" operator.`, {
1288
+ code: codes_BASE_ERROR_CODES.BAD_REQUEST,
1289
+ status: 400,
1290
+ data: {
1291
+ field,
1292
+ operator: w.operator,
1293
+ expectedType: 'array',
1294
+ actualType: typeof w.value
1295
+ }
1296
+ });
1297
+ return [
1298
+ (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.inArray)(schemaModel[field], w.value)
1299
+ ];
1300
+ }
1301
+ if ('contains' === w.operator) return [
1302
+ (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.like)(schemaModel[field], `%${w.value}%`)
1303
+ ];
1304
+ if ('starts_with' === w.operator) return [
1305
+ (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.like)(schemaModel[field], `${w.value}%`)
1306
+ ];
1307
+ if ('ends_with' === w.operator) return [
1308
+ (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.like)(schemaModel[field], `%${w.value}`)
1309
+ ];
1310
+ return [
1311
+ (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.eq)(schemaModel[field], w.value)
1312
+ ];
1313
+ }
1314
+ const andGroup = where.filter((w)=>'AND' === w.connector || !w.connector);
1315
+ const orGroup = where.filter((w)=>'OR' === w.connector);
1316
+ const andClause = (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.and)(...andGroup.map((w)=>{
1317
+ const field = getField(model, w.field);
1318
+ if ('in' === w.operator) {
1319
+ if (!Array.isArray(w.value)) throw new error_C15TError(`The value for the field "${field}" must be an array when using the "in" operator.`, {
1320
+ code: codes_BASE_ERROR_CODES.BAD_REQUEST,
1321
+ status: 400,
1322
+ data: {
1323
+ field,
1324
+ operator: w.operator,
1325
+ expectedType: 'array',
1326
+ actualType: typeof w.value
1327
+ }
1328
+ });
1329
+ return (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.inArray)(schemaModel[field], w.value);
1330
+ }
1331
+ return (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.eq)(schemaModel[field], w.value);
1332
+ }));
1333
+ const orClause = (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.or)(...orGroup.map((w)=>{
1334
+ const field = getField(model, w.field);
1335
+ return (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.eq)(schemaModel[field], w.value);
1336
+ }));
1337
+ const clause = [];
1338
+ if (andGroup.length && andClause) clause.push(andClause);
1339
+ if (orGroup.length && orClause) clause.push(orClause);
1340
+ return clause;
1341
+ }
1342
+ const useDatabaseGeneratedId = options?.advanced?.generateId === false;
1343
+ return {
1344
+ getSchema,
1345
+ transformInput (data, model, action) {
1346
+ const transformedData = useDatabaseGeneratedId || 'update' === action ? {} : {
1347
+ id: options.advanced?.generateId ? options.advanced.generateId({
1348
+ model
1349
+ }) : data.id || id_generator_generateId(schema[model].entityPrefix)
1350
+ };
1351
+ const fields = schema[model].fields;
1352
+ for(const field in fields)if (Object.hasOwn(fields, field)) {
1353
+ const value = data[field];
1354
+ if (void 0 === value && !fields[field].defaultValue) continue;
1355
+ transformedData[fields[field].fieldName || field] = utils_applyDefaultValue(value, fields[field], action);
1356
+ }
1357
+ return transformedData;
1358
+ },
1359
+ transformOutput (data, model, select = []) {
1360
+ if (!data) return null;
1361
+ let transformedData = {};
1362
+ if ((data.id || data._id) && (0 === select.length || select.includes('id'))) transformedData = {
1363
+ id: data.id
1364
+ };
1365
+ const tableSchema = schema[model].fields;
1366
+ for(const key in tableSchema){
1367
+ if (select.length && !select.includes(key)) continue;
1368
+ const field = tableSchema[key];
1369
+ if (field) transformedData[key] = data[field.fieldName || key];
1370
+ }
1371
+ return transformedData;
1372
+ },
1373
+ convertWhereClause,
1374
+ withReturning: async (model, builder, data, where)=>{
1375
+ if ('mysql' !== config.provider) {
1376
+ const c = await builder.returning();
1377
+ return c[0];
1378
+ }
1379
+ await builder.execute();
1380
+ const schemaModel = getSchema(model);
1381
+ const builderVal = builder.config?.values;
1382
+ if (where?.length) {
1383
+ const clause = convertWhereClause(where, model);
1384
+ const res = await db.select().from(schemaModel).where(...clause);
1385
+ return res[0];
1386
+ }
1387
+ if (builderVal) {
1388
+ const tId = builderVal[0]?.id.value;
1389
+ const res = await db.select().from(schemaModel).where((0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.eq)(schemaModel.id, tId));
1390
+ return res[0];
1391
+ }
1392
+ if (data.id) {
1393
+ const res = await db.select().from(schemaModel).where((0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.eq)(schemaModel.id, data.id));
1394
+ return res[0];
1395
+ }
1396
+ },
1397
+ getField,
1398
+ getEntityName
1399
+ };
1400
+ };
1401
+ function checkMissingFields(schema, model, values) {
1402
+ if (!schema) throw new error_C15TError('The schema could not be found. Please ensure the schema is properly configured in the adapter.', {
1403
+ code: codes_BASE_ERROR_CODES.DATABASE_CONNECTION_ERROR,
1404
+ status: 500
1405
+ });
1406
+ for(const key in values)if (!schema[key]) throw new error_C15TError(`The field "${key}" does not exist in the "${model}" schema. Please update your drizzle schema or re-generate using "npx @c15t/cli generate".`);
1407
+ }
1408
+ const drizzleAdapter = (db, config)=>(options)=>{
1409
+ const { transformInput, transformOutput, convertWhereClause, getSchema, withReturning, getField, getEntityName } = drizzle_adapter_rslib_entry_createEntityTransformer(db, config, options);
1410
+ return {
1411
+ id: 'drizzle',
1412
+ async create (data) {
1413
+ const { model, data: values } = data;
1414
+ const transformed = transformInput(values, model, 'create');
1415
+ const schemaModel = getSchema(model);
1416
+ checkMissingFields(schemaModel, getEntityName(model), transformed);
1417
+ const builder = db.insert(schemaModel).values(transformed);
1418
+ const returned = await withReturning(model, builder, transformed);
1419
+ return transformOutput(returned, model);
1420
+ },
1421
+ async findOne (data) {
1422
+ const { model, where, select } = data;
1423
+ const schemaModel = getSchema(model);
1424
+ const clause = convertWhereClause(where, model);
1425
+ const res = await db.select().from(schemaModel).where(...clause);
1426
+ if (!res.length) return null;
1427
+ return transformOutput(res[0], model, select);
1428
+ },
1429
+ async findMany (data) {
1430
+ const { model, where, sortBy, limit, offset } = data;
1431
+ const schemaModel = getSchema(model);
1432
+ const clause = where ? convertWhereClause(where, model) : [];
1433
+ const sortFn = sortBy?.direction === 'desc' ? __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.desc : __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.asc;
1434
+ const builder = db.select().from(schemaModel).limit(limit || 100).offset(offset || 0);
1435
+ if (sortBy?.field) builder.orderBy(sortFn(schemaModel[getField(model, sortBy?.field)]));
1436
+ const res = await builder.where(...clause);
1437
+ return res.map((r)=>transformOutput(r, model));
1438
+ },
1439
+ async count (data) {
1440
+ const { model, where } = data;
1441
+ const schemaModel = getSchema(model);
1442
+ const clause = where ? convertWhereClause(where, model) : [];
1443
+ const res = await db.select({
1444
+ count: (0, __WEBPACK_EXTERNAL_MODULE_drizzle_orm_51e552b8__.count)()
1445
+ }).from(schemaModel).where(...clause);
1446
+ return res[0].count;
1447
+ },
1448
+ async update (data) {
1449
+ const { model, where, update } = data;
1450
+ const schemaModel = getSchema(model);
1451
+ const clause = convertWhereClause(where, model);
1452
+ const transformed = transformInput(update, model, 'update');
1453
+ const result = await db.update(schemaModel).set(transformed).where(clause).returning();
1454
+ return result.length ? transformOutput(result[0], model) : null;
1455
+ },
1456
+ async updateMany (data) {
1457
+ const { model, where, update: values } = data;
1458
+ const schemaModel = getSchema(model);
1459
+ const clause = convertWhereClause(where, model);
1460
+ const transformed = transformInput(values, model, 'update');
1461
+ const builder = db.update(schemaModel).set(transformed).where(...clause);
1462
+ const res = await builder;
1463
+ return res ? res.changes : 0;
1464
+ },
1465
+ async delete (data) {
1466
+ const { model, where } = data;
1467
+ const schemaModel = getSchema(model);
1468
+ const clause = convertWhereClause(where, model);
1469
+ const builder = db.delete(schemaModel).where(...clause);
1470
+ await builder;
1471
+ },
1472
+ async deleteMany (data) {
1473
+ const { model, where } = data;
1474
+ const schemaModel = getSchema(model);
1475
+ const clause = convertWhereClause(where, model);
1476
+ const result = await db.delete(schemaModel).where(clause);
1477
+ return result ? result.rowCount : 0;
1478
+ },
1479
+ async transaction (data) {
1480
+ const { callback } = data;
1481
+ return await db.transaction(async (tx)=>{
1482
+ const transactionAdapter = drizzleAdapter(tx, config)(options);
1483
+ return await callback(transactionAdapter);
1484
+ });
1485
+ },
1486
+ options: config
1487
+ };
1488
+ };
1489
+ export { drizzleAdapter };