@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,1571 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_kysely__ from "kysely";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_zod__ from "zod";
3
+ import "superjson";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_base_x_aeb88370__ from "base-x";
5
+ import "node:crypto";
6
+ import "neverthrow";
7
+ const levels = [
8
+ 'info',
9
+ 'success',
10
+ 'warn',
11
+ 'error',
12
+ 'debug'
13
+ ];
14
+ function shouldPublishLog(currentLogLevel, logLevel) {
15
+ return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
16
+ }
17
+ const colors = {
18
+ reset: '\x1b[0m',
19
+ bright: '\x1b[1m',
20
+ dim: '\x1b[2m',
21
+ underscore: '\x1b[4m',
22
+ blink: '\x1b[5m',
23
+ reverse: '\x1b[7m',
24
+ hidden: '\x1b[8m',
25
+ fg: {
26
+ black: '\x1b[30m',
27
+ red: '\x1b[31m',
28
+ green: '\x1b[32m',
29
+ yellow: '\x1b[33m',
30
+ blue: '\x1b[34m',
31
+ magenta: '\x1b[35m',
32
+ cyan: '\x1b[36m',
33
+ white: '\x1b[37m'
34
+ },
35
+ bg: {
36
+ black: '\x1b[40m',
37
+ red: '\x1b[41m',
38
+ green: '\x1b[42m',
39
+ yellow: '\x1b[43m',
40
+ blue: '\x1b[44m',
41
+ magenta: '\x1b[45m',
42
+ cyan: '\x1b[46m',
43
+ white: '\x1b[47m'
44
+ }
45
+ };
46
+ const levelColors = {
47
+ info: colors.fg.blue,
48
+ success: colors.fg.green,
49
+ warn: colors.fg.yellow,
50
+ error: colors.fg.red,
51
+ debug: colors.fg.magenta
52
+ };
53
+ const formatMessage = (level, message)=>{
54
+ const timestamp = new Date().toISOString();
55
+ return `${colors.dim}${timestamp}${colors.reset} ${levelColors[level]}${level.toUpperCase()}${colors.reset} ${colors.bright}[c15t]:${colors.reset} ${message}`;
56
+ };
57
+ const logger_createLogger = (options)=>{
58
+ const enabled = options?.disabled !== true;
59
+ const logLevel = options?.level ?? 'error';
60
+ const LogFunc = (level, message, args = [])=>{
61
+ if (!enabled || !shouldPublishLog(logLevel, level)) return;
62
+ const formattedMessage = formatMessage(level, message);
63
+ if (!options || 'function' != typeof options.log) {
64
+ if ('error' === level) console.error(formattedMessage, ...args);
65
+ else if ('warn' === level) console.warn(formattedMessage, ...args);
66
+ else if ('info' === level) console.log(formattedMessage, ...args);
67
+ else if ('debug' === level) console.debug(formattedMessage, ...args);
68
+ else if ('success' === level) console.log(formattedMessage, ...args);
69
+ return;
70
+ }
71
+ options.log('success' === level ? 'info' : level, message, ...args);
72
+ };
73
+ return Object.fromEntries(levels.map((level)=>[
74
+ level,
75
+ (...[message, ...args])=>LogFunc(level, message, args)
76
+ ]));
77
+ };
78
+ logger_createLogger();
79
+ function dialect_getDatabaseType(db) {
80
+ if (!db) return null;
81
+ if ('dialect' in db) return dialect_getDatabaseType(db.dialect);
82
+ if ('createDriver' in db) {
83
+ if (db instanceof __WEBPACK_EXTERNAL_MODULE_kysely__.SqliteDialect) return 'sqlite';
84
+ if (db instanceof __WEBPACK_EXTERNAL_MODULE_kysely__.MysqlDialect) return 'mysql';
85
+ if (db instanceof __WEBPACK_EXTERNAL_MODULE_kysely__.PostgresDialect) return 'postgres';
86
+ if (db instanceof __WEBPACK_EXTERNAL_MODULE_kysely__.MssqlDialect) return 'mssql';
87
+ }
88
+ if ('aggregate' in db) return 'sqlite';
89
+ if ('getConnection' in db) return 'mysql';
90
+ if ('connect' in db) return 'postgres';
91
+ return null;
92
+ }
93
+ const dialect_createKyselyAdapter = async (config)=>{
94
+ const db = config.database;
95
+ if (!db) return {
96
+ kysely: null,
97
+ databaseType: null
98
+ };
99
+ if ('db' in db) {
100
+ const kyselyConfig = db;
101
+ return {
102
+ kysely: kyselyConfig.db,
103
+ databaseType: kyselyConfig.type
104
+ };
105
+ }
106
+ if ('dialect' in db) {
107
+ const dialectConfig = db;
108
+ return {
109
+ kysely: new __WEBPACK_EXTERNAL_MODULE_kysely__.Kysely({
110
+ dialect: dialectConfig.dialect
111
+ }),
112
+ databaseType: dialectConfig.type
113
+ };
114
+ }
115
+ let dialect;
116
+ const databaseType = dialect_getDatabaseType(db);
117
+ if ('createDriver' in db) dialect = db;
118
+ if ('aggregate' in db) dialect = new __WEBPACK_EXTERNAL_MODULE_kysely__.SqliteDialect({
119
+ database: db
120
+ });
121
+ if ('getConnection' in db) dialect = new __WEBPACK_EXTERNAL_MODULE_kysely__.MysqlDialect({
122
+ pool: db
123
+ });
124
+ if ('connect' in db) dialect = new __WEBPACK_EXTERNAL_MODULE_kysely__.PostgresDialect({
125
+ pool: db
126
+ });
127
+ return {
128
+ kysely: dialect ? new __WEBPACK_EXTERNAL_MODULE_kysely__.Kysely({
129
+ dialect
130
+ }) : null,
131
+ databaseType
132
+ };
133
+ };
134
+ const postgresMap = {
135
+ string: [
136
+ 'character varying',
137
+ 'text'
138
+ ],
139
+ number: [
140
+ 'int4',
141
+ 'integer',
142
+ 'bigint',
143
+ 'smallint',
144
+ 'numeric',
145
+ 'real',
146
+ 'double precision'
147
+ ],
148
+ boolean: [
149
+ 'bool',
150
+ 'boolean'
151
+ ],
152
+ date: [
153
+ 'timestamp',
154
+ 'date'
155
+ ],
156
+ json: [
157
+ 'json',
158
+ 'jsonb'
159
+ ],
160
+ timezone: [
161
+ 'text',
162
+ 'character varying'
163
+ ]
164
+ };
165
+ const mysqlMap = {
166
+ string: [
167
+ 'varchar(255)',
168
+ 'varchar(36)',
169
+ 'text'
170
+ ],
171
+ number: [
172
+ 'integer',
173
+ 'int',
174
+ 'bigint',
175
+ 'smallint',
176
+ 'decimal',
177
+ 'float',
178
+ 'double'
179
+ ],
180
+ boolean: [
181
+ 'boolean',
182
+ 'tinyint'
183
+ ],
184
+ date: [
185
+ 'timestamp',
186
+ 'datetime',
187
+ 'date'
188
+ ],
189
+ json: [
190
+ 'json'
191
+ ],
192
+ timezone: [
193
+ 'varchar(50)'
194
+ ]
195
+ };
196
+ const sqliteMap = {
197
+ string: [
198
+ 'TEXT'
199
+ ],
200
+ number: [
201
+ 'INTEGER',
202
+ 'REAL'
203
+ ],
204
+ boolean: [
205
+ 'INTEGER',
206
+ 'BOOLEAN'
207
+ ],
208
+ date: [
209
+ 'DATE',
210
+ 'INTEGER'
211
+ ],
212
+ json: [
213
+ 'TEXT'
214
+ ],
215
+ timezone: [
216
+ 'TEXT'
217
+ ]
218
+ };
219
+ const mssqlMap = {
220
+ string: [
221
+ 'text',
222
+ 'varchar'
223
+ ],
224
+ number: [
225
+ 'int',
226
+ 'bigint',
227
+ 'smallint',
228
+ 'decimal',
229
+ 'float(53)',
230
+ 'float(24)'
231
+ ],
232
+ boolean: [
233
+ 'bit',
234
+ 'smallint'
235
+ ],
236
+ date: [
237
+ 'datetime',
238
+ 'date'
239
+ ],
240
+ json: [
241
+ 'nvarchar(max)'
242
+ ],
243
+ timezone: [
244
+ 'varchar',
245
+ 'text'
246
+ ]
247
+ };
248
+ const map = {
249
+ postgres: postgresMap,
250
+ mysql: mysqlMap,
251
+ sqlite: sqliteMap,
252
+ mssql: mssqlMap
253
+ };
254
+ function getMySqlStringType(field) {
255
+ if (field.unique) return 'varchar(255)';
256
+ if (field.references) return 'varchar(36)';
257
+ return 'text';
258
+ }
259
+ function matchType(columnDataType, fieldType, dbType) {
260
+ if ('string[]' === fieldType || 'number[]' === fieldType) return columnDataType.toLowerCase().includes('json');
261
+ const types = map[dbType];
262
+ const type = Array.isArray(fieldType) ? types.string.map((t)=>t.toLowerCase()) : types[fieldType].map((t)=>t.toLowerCase());
263
+ const matches = type.includes(columnDataType.toLowerCase());
264
+ return matches;
265
+ }
266
+ function getType(field, dbType = 'sqlite') {
267
+ const type = field.type;
268
+ const typeMap = {
269
+ string: {
270
+ sqlite: 'text',
271
+ postgres: 'text',
272
+ mysql: getMySqlStringType(field),
273
+ mssql: getMySqlStringType(field)
274
+ },
275
+ boolean: {
276
+ sqlite: 'integer',
277
+ postgres: 'boolean',
278
+ mysql: 'boolean',
279
+ mssql: 'smallint'
280
+ },
281
+ number: {
282
+ sqlite: field.bigint ? 'bigint' : 'integer',
283
+ postgres: field.bigint ? 'bigint' : 'integer',
284
+ mysql: field.bigint ? 'bigint' : 'integer',
285
+ mssql: field.bigint ? 'bigint' : 'integer'
286
+ },
287
+ date: {
288
+ sqlite: 'date',
289
+ postgres: 'timestamp',
290
+ mysql: 'datetime',
291
+ mssql: 'datetime'
292
+ },
293
+ timezone: {
294
+ sqlite: 'text',
295
+ postgres: 'text',
296
+ mysql: 'varchar(50)',
297
+ mssql: 'nvarchar(50)'
298
+ },
299
+ json: {
300
+ sqlite: 'text',
301
+ postgres: 'jsonb',
302
+ mysql: 'json',
303
+ mssql: 'nvarchar(max)'
304
+ }
305
+ };
306
+ if ('sqlite' === dbType && ('string[]' === type || 'number[]' === type)) return 'text';
307
+ if ('string[]' === type || 'number[]' === type) switch(dbType){
308
+ case 'postgres':
309
+ return 'jsonb';
310
+ case 'mysql':
311
+ case 'mssql':
312
+ return 'json';
313
+ default:
314
+ return 'text';
315
+ }
316
+ if ('json' === type) return typeMap.json[dbType];
317
+ return typeMap[type][dbType];
318
+ }
319
+ function buildColumnAddMigrations(db, toBeAdded, dbType) {
320
+ const migrations = [];
321
+ for (const table of toBeAdded)for (const [fieldName, field] of Object.entries(table.fields)){
322
+ const type = getType(field, dbType);
323
+ const exec = db.schema.alterTable(table.table).addColumn(fieldName, type, (col)=>{
324
+ let column = false !== field.required ? col.notNull() : col;
325
+ if (field.references) column = column.references(`${field.references.model}.${field.references.field}`);
326
+ if (field.unique) column = column.unique();
327
+ return column;
328
+ });
329
+ migrations.push(exec);
330
+ }
331
+ return migrations;
332
+ }
333
+ function buildTableCreateMigrations(db, toBeCreated, dbType) {
334
+ const logger = logger_createLogger();
335
+ const migrations = [];
336
+ for (const table of toBeCreated){
337
+ const fieldNames = Object.keys(table.fields);
338
+ logger.info(`Creating table ${table.table} with fields: ${fieldNames.join(', ')}`);
339
+ if (fieldNames.includes('id')) logger.warn(`⚠️ Table ${table.table} already has an explicit 'id' field, which may conflict with the auto-generated primary key`);
340
+ for (const [fieldName, field] of Object.entries(table.fields))if ('id' === field.fieldName && 'id' !== fieldName) logger.error(`❌ ERROR: Table ${table.table} has field '${fieldName}' with fieldName 'id' - this will cause a duplicate column error`);
341
+ let dbT = db.schema.createTable(table.table).addColumn('id', 'mysql' === dbType || 'mssql' === dbType ? 'varchar(36)' : 'text', (col)=>col.primaryKey().notNull());
342
+ for (const [fieldName, field] of Object.entries(table.fields)){
343
+ const type = getType(field, dbType);
344
+ logger.info(`Adding column ${fieldName} (fieldName: ${field.fieldName || fieldName}) to table ${table.table}`);
345
+ dbT = dbT.addColumn(fieldName, type, (col)=>{
346
+ let column = false !== field.required ? col.notNull() : col;
347
+ if (field.references) column = column.references(`${field.references.model}.${field.references.field}`);
348
+ if (field.unique) column = column.unique();
349
+ return column;
350
+ });
351
+ }
352
+ const sqlDebug = dbT.compile().sql;
353
+ logger.info(`SQL for table ${table.table}:\n${sqlDebug}`);
354
+ migrations.push(dbT);
355
+ }
356
+ return migrations;
357
+ }
358
+ function createMigrationExecutors(migrations) {
359
+ const logger = logger_createLogger();
360
+ async function runMigrations() {
361
+ for (const migration of migrations)try {
362
+ await migration.execute();
363
+ } catch (error) {
364
+ const sql = migration.compile().sql;
365
+ logger.error(`Migration failed! SQL:\n${sql}`);
366
+ throw error;
367
+ }
368
+ }
369
+ async function compileMigrations() {
370
+ const compiled = migrations.map((m)=>m.compile().sql);
371
+ return `${compiled.join(';\n\n')};`;
372
+ }
373
+ return {
374
+ runMigrations,
375
+ compileMigrations
376
+ };
377
+ }
378
+ const definition_getConsentTables = (options)=>{
379
+ const pluginSchema = options.plugins?.reduce((acc, plugin)=>{
380
+ const schema = plugin.schema;
381
+ if (!schema) return acc;
382
+ for (const [key, value] of Object.entries(schema))acc[key] = {
383
+ fields: {
384
+ ...acc[key]?.fields,
385
+ ...value.fields
386
+ },
387
+ entityName: value.entityName || key
388
+ };
389
+ return acc;
390
+ }, {});
391
+ const { subject, consentPurpose, consentPolicy, domain, geoLocation, consent, consentPurposeJunction, record, consentGeoLocation, consentWithdrawal, auditLog, ...pluginTables } = pluginSchema || {};
392
+ return {
393
+ subject: getSubjectTable(options, subject?.fields),
394
+ consentPurpose: getPurposeTable(options, consentPurpose?.fields),
395
+ consentPolicy: getConsentPolicyTable(options, consentPolicy?.fields),
396
+ domain: getDomainTable(options, domain?.fields),
397
+ consent: getConsentTable(options, consent?.fields),
398
+ consentPurposeJunction: getPurposeJunctionTable(options, consentPurposeJunction?.fields),
399
+ consentRecord: getConsentRecordTable(options, record?.fields),
400
+ consentGeoLocation: getConsentGeoLocationTable(options, consentGeoLocation?.fields),
401
+ consentWithdrawal: getConsentWithdrawalTable(options, consentWithdrawal?.fields),
402
+ auditLog: getAuditLogTable(options, auditLog?.fields),
403
+ geoLocation: getGeoLocationTable(options, geoLocation?.fields),
404
+ ...pluginTables
405
+ };
406
+ };
407
+ const auditLogSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
408
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
409
+ entityType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
410
+ entityId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
411
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
412
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
413
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
414
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
415
+ changes: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
416
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
417
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
418
+ });
419
+ const fieldConfigSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
420
+ required: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
421
+ returned: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
422
+ input: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
423
+ defaultValue: __WEBPACK_EXTERNAL_MODULE_zod__.z.union([
424
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
425
+ __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
426
+ ]).optional(),
427
+ transform: __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
428
+ input: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
429
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
430
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.promise(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
431
+ ])).optional(),
432
+ output: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
433
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.any(),
434
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.promise(__WEBPACK_EXTERNAL_MODULE_zod__.z.any())
435
+ ])).optional()
436
+ }).optional(),
437
+ validator: __WEBPACK_EXTERNAL_MODULE_zod__.z["function"]().args(__WEBPACK_EXTERNAL_MODULE_zod__.z.any()).returns(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
438
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
439
+ __WEBPACK_EXTERNAL_MODULE_zod__.z["null"]()
440
+ ])).optional(),
441
+ unique: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().optional(),
442
+ indexed: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().optional(),
443
+ sortable: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
444
+ fieldName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
445
+ bigint: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false)
446
+ });
447
+ const stringFieldSchema = fieldConfigSchema.extend({
448
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('string'),
449
+ minLength: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
450
+ maxLength: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
451
+ pattern: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional()
452
+ });
453
+ const numberFieldSchema = fieldConfigSchema.extend({
454
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('number'),
455
+ min: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional(),
456
+ max: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().optional()
457
+ });
458
+ const booleanFieldSchema = fieldConfigSchema.extend({
459
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('boolean')
460
+ });
461
+ const dateFieldSchema = fieldConfigSchema.extend({
462
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('date'),
463
+ minDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
464
+ maxDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
465
+ dateOnly: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
466
+ format: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional()
467
+ });
468
+ const timezoneFieldSchema = fieldConfigSchema.extend({
469
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('timezone'),
470
+ validateTimezone: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
471
+ suggestedValues: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional(),
472
+ restrictToSuggestedValues: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false)
473
+ });
474
+ const jsonFieldSchema = fieldConfigSchema.extend({
475
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('json'),
476
+ validateJson: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true)
477
+ });
478
+ const stringArrayFieldSchema = fieldConfigSchema.extend({
479
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('string[]')
480
+ });
481
+ const numberArrayFieldSchema = fieldConfigSchema.extend({
482
+ type: __WEBPACK_EXTERNAL_MODULE_zod__.z.literal('number[]')
483
+ });
484
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.discriminatedUnion('type', [
485
+ stringFieldSchema,
486
+ numberFieldSchema,
487
+ booleanFieldSchema,
488
+ dateFieldSchema,
489
+ timezoneFieldSchema,
490
+ jsonFieldSchema,
491
+ stringArrayFieldSchema,
492
+ numberArrayFieldSchema
493
+ ]);
494
+ const COMMON_TIMEZONES = {
495
+ UTC: 'UTC',
496
+ GMT: 'GMT',
497
+ EASTERN: 'America/New_York',
498
+ CENTRAL: 'America/Chicago',
499
+ MOUNTAIN: 'America/Denver',
500
+ PACIFIC: 'America/Los_Angeles',
501
+ LONDON: 'Europe/London',
502
+ PARIS: 'Europe/Paris',
503
+ BERLIN: 'Europe/Berlin',
504
+ TOKYO: 'Asia/Tokyo',
505
+ SHANGHAI: 'Asia/Shanghai',
506
+ SINGAPORE: 'Asia/Singapore',
507
+ SYDNEY: 'Australia/Sydney',
508
+ SAO_PAULO: 'America/Sao_Paulo'
509
+ };
510
+ (0, __WEBPACK_EXTERNAL_MODULE_base_x_aeb88370__["default"])('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');
511
+ function getAuditLogTable(options, auditLogFields) {
512
+ const auditLogConfig = options.tables?.auditLog;
513
+ const subjectConfig = options.tables?.subject;
514
+ return {
515
+ entityName: auditLogConfig?.entityName || 'auditLog',
516
+ entityPrefix: auditLogConfig?.entityPrefix || 'log',
517
+ schema: auditLogSchema,
518
+ fields: {
519
+ entityType: {
520
+ type: 'string',
521
+ required: true,
522
+ fieldName: auditLogConfig?.fields?.entityType || 'entityType'
523
+ },
524
+ entityId: {
525
+ type: 'string',
526
+ required: true,
527
+ fieldName: auditLogConfig?.fields?.entityId || 'entityId'
528
+ },
529
+ actionType: {
530
+ type: 'string',
531
+ required: true,
532
+ fieldName: auditLogConfig?.fields?.actionType || 'actionType'
533
+ },
534
+ subjectId: {
535
+ type: 'string',
536
+ required: false,
537
+ fieldName: auditLogConfig?.fields?.subjectId || 'subjectId',
538
+ references: {
539
+ model: subjectConfig?.entityName || 'subject',
540
+ field: 'id'
541
+ }
542
+ },
543
+ ipAddress: {
544
+ type: 'string',
545
+ required: false,
546
+ fieldName: auditLogConfig?.fields?.ipAddress || 'ipAddress'
547
+ },
548
+ userAgent: {
549
+ type: 'string',
550
+ required: false,
551
+ fieldName: auditLogConfig?.fields?.userAgent || 'userAgent'
552
+ },
553
+ changes: {
554
+ type: 'json',
555
+ required: false,
556
+ fieldName: auditLogConfig?.fields?.changes || 'changes'
557
+ },
558
+ metadata: {
559
+ type: 'json',
560
+ required: false,
561
+ fieldName: auditLogConfig?.fields?.metadata || 'metadata'
562
+ },
563
+ createdAt: {
564
+ type: 'date',
565
+ defaultValue: ()=>new Date(),
566
+ required: true,
567
+ fieldName: auditLogConfig?.fields?.createdAt || 'createdAt'
568
+ },
569
+ eventTimezone: {
570
+ type: 'timezone',
571
+ required: true,
572
+ defaultValue: COMMON_TIMEZONES.UTC,
573
+ fieldName: auditLogConfig?.fields?.eventTimezone || 'eventTimezone'
574
+ },
575
+ ...auditLogFields || {},
576
+ ...auditLogConfig?.additionalFields || {}
577
+ },
578
+ indexes: [
579
+ {
580
+ name: 'entity_index',
581
+ fields: [
582
+ 'entityType',
583
+ 'entityId'
584
+ ]
585
+ },
586
+ {
587
+ name: 'action_type_index',
588
+ fields: [
589
+ 'actionType'
590
+ ]
591
+ },
592
+ {
593
+ name: 'subject_id_index',
594
+ fields: [
595
+ 'subjectId'
596
+ ]
597
+ },
598
+ {
599
+ name: 'created_at_index',
600
+ fields: [
601
+ 'createdAt'
602
+ ]
603
+ }
604
+ ],
605
+ order: 5
606
+ };
607
+ }
608
+ const consentGeoLocationSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
609
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
610
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
611
+ ip: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().ip(),
612
+ country: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
613
+ region: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
614
+ city: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
615
+ latitude: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().min(-90).max(90).optional(),
616
+ longitude: __WEBPACK_EXTERNAL_MODULE_zod__.z.number().min(-180).max(180).optional(),
617
+ timezone: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().regex(/^[A-Za-z_]+\/[A-Za-z_]+$/).optional(),
618
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
619
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
620
+ });
621
+ function getConsentGeoLocationTable(options, geoLocationFields) {
622
+ const consentGeoLocationConfig = options.tables?.consentGeoLocation;
623
+ const consentConfig = options.tables?.consent;
624
+ return {
625
+ entityName: consentGeoLocationConfig?.entityName || 'consentGeoLocation',
626
+ entityPrefix: consentGeoLocationConfig?.entityPrefix || 'cgl',
627
+ schema: consentGeoLocationSchema,
628
+ fields: {
629
+ consentId: {
630
+ type: 'string',
631
+ required: true,
632
+ fieldName: consentGeoLocationConfig?.fields?.consentId || 'consentId',
633
+ references: {
634
+ model: consentConfig?.entityName || 'consent',
635
+ field: 'id'
636
+ }
637
+ },
638
+ ip: {
639
+ type: 'string',
640
+ required: true,
641
+ fieldName: consentGeoLocationConfig?.fields?.ip || 'ip'
642
+ },
643
+ country: {
644
+ type: 'string',
645
+ required: false,
646
+ fieldName: consentGeoLocationConfig?.fields?.country || 'country'
647
+ },
648
+ region: {
649
+ type: 'string',
650
+ required: false,
651
+ fieldName: consentGeoLocationConfig?.fields?.region || 'region'
652
+ },
653
+ city: {
654
+ type: 'string',
655
+ required: false,
656
+ fieldName: consentGeoLocationConfig?.fields?.city || 'city'
657
+ },
658
+ latitude: {
659
+ type: 'number',
660
+ required: false,
661
+ fieldName: consentGeoLocationConfig?.fields?.latitude || 'latitude'
662
+ },
663
+ longitude: {
664
+ type: 'number',
665
+ required: false,
666
+ fieldName: consentGeoLocationConfig?.fields?.longitude || 'longitude'
667
+ },
668
+ timezone: {
669
+ type: 'string',
670
+ required: false,
671
+ fieldName: consentGeoLocationConfig?.fields?.timezone || 'timezone'
672
+ },
673
+ createdAt: {
674
+ type: 'date',
675
+ defaultValue: ()=>new Date(),
676
+ required: true,
677
+ fieldName: consentGeoLocationConfig?.fields?.createdAt || 'createdAt'
678
+ },
679
+ ...geoLocationFields || {},
680
+ ...consentGeoLocationConfig?.additionalFields || {}
681
+ },
682
+ indexes: [
683
+ {
684
+ name: 'consent_id_index',
685
+ fields: [
686
+ 'consentId'
687
+ ]
688
+ },
689
+ {
690
+ name: 'country_index',
691
+ fields: [
692
+ 'country'
693
+ ]
694
+ },
695
+ {
696
+ name: 'created_at_index',
697
+ fields: [
698
+ 'createdAt'
699
+ ]
700
+ }
701
+ ],
702
+ order: 4
703
+ };
704
+ }
705
+ const consentPolicySchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
706
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
707
+ version: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
708
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
709
+ effectiveDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date(),
710
+ expirationDate: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().nullable().optional(),
711
+ content: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
712
+ contentHash: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
713
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
714
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
715
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
716
+ });
717
+ function getConsentPolicyTable(options, policyFields) {
718
+ const consentPolicyConfig = options.tables?.consentPolicy;
719
+ return {
720
+ entityName: consentPolicyConfig?.entityName || 'consentPolicy',
721
+ entityPrefix: consentPolicyConfig?.entityPrefix || 'pol',
722
+ schema: consentPolicySchema,
723
+ fields: {
724
+ version: {
725
+ type: 'string',
726
+ required: true,
727
+ fieldName: consentPolicyConfig?.fields?.version || 'version'
728
+ },
729
+ name: {
730
+ type: 'string',
731
+ required: true,
732
+ fieldName: consentPolicyConfig?.fields?.name || 'name'
733
+ },
734
+ effectiveDate: {
735
+ type: 'date',
736
+ required: true,
737
+ fieldName: consentPolicyConfig?.fields?.effectiveDate || 'effectiveDate'
738
+ },
739
+ expirationDate: {
740
+ type: 'date',
741
+ required: false,
742
+ fieldName: consentPolicyConfig?.fields?.expirationDate || 'expirationDate'
743
+ },
744
+ content: {
745
+ type: 'string',
746
+ required: true,
747
+ fieldName: consentPolicyConfig?.fields?.content || 'content'
748
+ },
749
+ contentHash: {
750
+ type: 'string',
751
+ required: true,
752
+ fieldName: consentPolicyConfig?.fields?.contentHash || 'contentHash'
753
+ },
754
+ isActive: {
755
+ type: 'boolean',
756
+ defaultValue: true,
757
+ required: true,
758
+ fieldName: consentPolicyConfig?.fields?.isActive || 'isActive'
759
+ },
760
+ createdAt: {
761
+ type: 'date',
762
+ defaultValue: ()=>new Date(),
763
+ required: true,
764
+ fieldName: consentPolicyConfig?.fields?.createdAt || 'createdAt'
765
+ },
766
+ ...policyFields || {},
767
+ ...consentPolicyConfig?.additionalFields || {}
768
+ },
769
+ order: 2
770
+ };
771
+ }
772
+ const consentPurposeJunctionSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
773
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
774
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
775
+ consentPurposeId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
776
+ status: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
777
+ 'active',
778
+ 'withdrawn'
779
+ ], {
780
+ errorMap: ()=>({
781
+ message: "Status must be either 'active' or 'withdrawn'"
782
+ })
783
+ }).default('active'),
784
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.union([
785
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
786
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.number(),
787
+ __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean()
788
+ ])).optional(),
789
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
790
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
791
+ });
792
+ function getPurposeJunctionTable(options, junctionFields) {
793
+ const purposeJunctionConfig = options.tables?.consentPurposeJunction;
794
+ const consentConfig = options.tables?.consent;
795
+ const purposeConfig = options.tables?.consentPurpose;
796
+ return {
797
+ entityName: purposeJunctionConfig?.entityName || 'consentPurposeJunction',
798
+ entityPrefix: purposeJunctionConfig?.entityPrefix || 'pjx',
799
+ schema: consentPurposeJunctionSchema,
800
+ fields: {
801
+ consentId: {
802
+ type: 'string',
803
+ required: true,
804
+ fieldName: purposeJunctionConfig?.fields?.consentId || 'consentId',
805
+ references: {
806
+ model: consentConfig?.entityName || 'consent',
807
+ field: 'id'
808
+ }
809
+ },
810
+ purposeId: {
811
+ type: 'string',
812
+ required: true,
813
+ fieldName: purposeJunctionConfig?.fields?.purposeId || 'purposeId',
814
+ references: {
815
+ model: purposeConfig?.entityName || 'consentPurpose',
816
+ field: 'id'
817
+ }
818
+ },
819
+ status: {
820
+ type: 'string',
821
+ defaultValue: ()=>'active',
822
+ required: true,
823
+ fieldName: purposeJunctionConfig?.fields?.status || 'status'
824
+ },
825
+ metadata: {
826
+ type: 'json',
827
+ required: false,
828
+ fieldName: purposeJunctionConfig?.fields?.metadata || 'metadata'
829
+ },
830
+ createdAt: {
831
+ type: 'date',
832
+ defaultValue: ()=>new Date(),
833
+ required: true,
834
+ fieldName: purposeJunctionConfig?.fields?.createdAt || 'createdAt'
835
+ },
836
+ updatedAt: {
837
+ type: 'date',
838
+ required: false,
839
+ fieldName: purposeJunctionConfig?.fields?.updatedAt || 'updatedAt'
840
+ },
841
+ ...junctionFields || {},
842
+ ...purposeJunctionConfig?.additionalFields || {}
843
+ },
844
+ uniqueConstraints: [
845
+ {
846
+ name: 'unique_consent_purpose',
847
+ fields: [
848
+ 'consentId',
849
+ 'purposeId'
850
+ ]
851
+ }
852
+ ],
853
+ order: 4
854
+ };
855
+ }
856
+ const purposeSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
857
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
858
+ code: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
859
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
860
+ description: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
861
+ isEssential: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
862
+ dataCategory: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
863
+ legalBasis: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
864
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
865
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
866
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
867
+ });
868
+ function getPurposeTable(options, purposeFields) {
869
+ const purposeConfig = options.tables?.consentPurpose;
870
+ return {
871
+ entityName: purposeConfig?.entityName || 'consentPurpose',
872
+ entityPrefix: purposeConfig?.entityPrefix || 'pur',
873
+ schema: purposeSchema,
874
+ fields: {
875
+ code: {
876
+ type: 'string',
877
+ required: true,
878
+ fieldName: purposeConfig?.fields?.code || 'code'
879
+ },
880
+ name: {
881
+ type: 'string',
882
+ required: true,
883
+ fieldName: purposeConfig?.fields?.name || 'name'
884
+ },
885
+ description: {
886
+ type: 'string',
887
+ required: true,
888
+ fieldName: purposeConfig?.fields?.description || "description"
889
+ },
890
+ isEssential: {
891
+ type: 'boolean',
892
+ defaultValue: ()=>false,
893
+ required: true,
894
+ fieldName: purposeConfig?.fields?.isEssential || 'isEssential'
895
+ },
896
+ dataCategory: {
897
+ type: 'string',
898
+ required: false,
899
+ fieldName: purposeConfig?.fields?.dataCategory || 'dataCategory'
900
+ },
901
+ legalBasis: {
902
+ type: 'string',
903
+ required: false,
904
+ fieldName: purposeConfig?.fields?.legalBasis || 'legalBasis'
905
+ },
906
+ isActive: {
907
+ type: 'boolean',
908
+ defaultValue: true,
909
+ required: true,
910
+ fieldName: purposeConfig?.fields?.isActive || 'isActive'
911
+ },
912
+ createdAt: {
913
+ type: 'date',
914
+ defaultValue: ()=>new Date(),
915
+ required: true,
916
+ fieldName: purposeConfig?.fields?.createdAt || 'createdAt'
917
+ },
918
+ updatedAt: {
919
+ type: 'date',
920
+ defaultValue: ()=>new Date(),
921
+ required: true,
922
+ fieldName: purposeConfig?.fields?.updatedAt || 'updatedAt'
923
+ },
924
+ ...purposeFields || {},
925
+ ...purposeConfig?.additionalFields || {}
926
+ },
927
+ order: 1
928
+ };
929
+ }
930
+ const consentRecordSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
931
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
932
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
933
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
934
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
935
+ details: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
936
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
937
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
938
+ });
939
+ function getConsentRecordTable(options, recordFields) {
940
+ const recordConfig = options.tables?.record;
941
+ const subjectConfig = options.tables?.subject;
942
+ const consentConfig = options.tables?.consent;
943
+ return {
944
+ entityName: recordConfig?.entityName || 'consentRecord',
945
+ entityPrefix: recordConfig?.entityPrefix || 'rec',
946
+ schema: consentRecordSchema,
947
+ fields: {
948
+ subjectId: {
949
+ type: 'string',
950
+ required: true,
951
+ fieldName: recordConfig?.fields?.subjectId || 'subjectId',
952
+ references: {
953
+ model: subjectConfig?.entityName || 'subject',
954
+ field: 'id'
955
+ }
956
+ },
957
+ consentId: {
958
+ type: 'string',
959
+ required: false,
960
+ fieldName: recordConfig?.fields?.consentId || 'consentId',
961
+ references: {
962
+ model: consentConfig?.entityName || 'consent',
963
+ field: 'id'
964
+ }
965
+ },
966
+ actionType: {
967
+ type: 'string',
968
+ required: true,
969
+ fieldName: recordConfig?.fields?.actionType || 'actionType'
970
+ },
971
+ details: {
972
+ type: 'json',
973
+ required: false,
974
+ fieldName: recordConfig?.fields?.details || 'details'
975
+ },
976
+ createdAt: {
977
+ type: 'date',
978
+ defaultValue: ()=>new Date(),
979
+ required: true,
980
+ fieldName: recordConfig?.fields?.createdAt || 'createdAt'
981
+ },
982
+ ...recordFields || {},
983
+ ...recordConfig?.additionalFields || {}
984
+ },
985
+ order: 4
986
+ };
987
+ }
988
+ const consentWithdrawalSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
989
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
990
+ consentId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
991
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
992
+ withdrawalReason: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
993
+ withdrawalMethod: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
994
+ 'subject-initiated',
995
+ 'automatic-expiry',
996
+ 'admin',
997
+ 'api',
998
+ 'other'
999
+ ]).default('subject-initiated'),
1000
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1001
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1002
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
1003
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
1004
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
1005
+ });
1006
+ function getConsentWithdrawalTable(options, withdrawalFields) {
1007
+ const consentWithdrawalConfig = options.tables?.consentWithdrawal;
1008
+ const consentConfig = options.tables?.consent;
1009
+ const subjectConfig = options.tables?.subject;
1010
+ return {
1011
+ entityName: consentWithdrawalConfig?.entityName || 'consentWithdrawal',
1012
+ entityPrefix: consentWithdrawalConfig?.entityPrefix || 'wdr',
1013
+ schema: consentWithdrawalSchema,
1014
+ fields: {
1015
+ consentId: {
1016
+ type: 'string',
1017
+ required: true,
1018
+ fieldName: consentWithdrawalConfig?.fields?.consentId || 'consentId',
1019
+ references: {
1020
+ model: consentConfig?.entityName || 'consent',
1021
+ field: 'id'
1022
+ }
1023
+ },
1024
+ subjectId: {
1025
+ type: 'string',
1026
+ required: true,
1027
+ fieldName: consentWithdrawalConfig?.fields?.subjectId || 'subjectId',
1028
+ references: {
1029
+ model: subjectConfig?.entityName || 'subject',
1030
+ field: 'id'
1031
+ }
1032
+ },
1033
+ withdrawalReason: {
1034
+ type: 'string',
1035
+ required: false,
1036
+ fieldName: consentWithdrawalConfig?.fields?.withdrawalReason || 'withdrawalReason'
1037
+ },
1038
+ withdrawalMethod: {
1039
+ type: 'string',
1040
+ defaultValue: ()=>'subject-initiated',
1041
+ required: true,
1042
+ fieldName: consentWithdrawalConfig?.fields?.withdrawalMethod || 'withdrawalMethod'
1043
+ },
1044
+ ipAddress: {
1045
+ type: 'string',
1046
+ required: false,
1047
+ fieldName: consentWithdrawalConfig?.fields?.ipAddress || 'ipAddress'
1048
+ },
1049
+ userAgent: {
1050
+ type: 'string',
1051
+ required: false,
1052
+ fieldName: consentWithdrawalConfig?.fields?.userAgent || 'userAgent'
1053
+ },
1054
+ metadata: {
1055
+ type: 'json',
1056
+ required: false,
1057
+ fieldName: consentWithdrawalConfig?.fields?.metadata || 'metadata'
1058
+ },
1059
+ createdAt: {
1060
+ type: 'date',
1061
+ defaultValue: ()=>new Date(),
1062
+ required: true,
1063
+ fieldName: consentWithdrawalConfig?.fields?.createdAt || 'createdAt'
1064
+ },
1065
+ ...withdrawalFields || {},
1066
+ ...consentWithdrawalConfig?.additionalFields || {}
1067
+ },
1068
+ uniqueConstraints: consentWithdrawalConfig?.preventMultipleWithdrawals !== false ? [
1069
+ {
1070
+ name: 'unique_consent_withdrawal',
1071
+ fields: [
1072
+ 'consentId'
1073
+ ]
1074
+ }
1075
+ ] : [],
1076
+ indexes: [
1077
+ {
1078
+ name: 'subject_id_index',
1079
+ fields: [
1080
+ 'subjectId'
1081
+ ]
1082
+ },
1083
+ {
1084
+ name: 'created_at_index',
1085
+ fields: [
1086
+ 'createdAt'
1087
+ ]
1088
+ }
1089
+ ],
1090
+ order: 4
1091
+ };
1092
+ }
1093
+ const consentHistorySchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1094
+ actionType: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
1095
+ 'given',
1096
+ 'withdrawn',
1097
+ 'updated',
1098
+ 'expired'
1099
+ ]),
1100
+ timestamp: __WEBPACK_EXTERNAL_MODULE_zod__.z.date(),
1101
+ details: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
1102
+ previousState: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
1103
+ newState: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional()
1104
+ });
1105
+ const consentSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1106
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1107
+ subjectId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1108
+ domainId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1109
+ purposeIds: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()),
1110
+ metadata: __WEBPACK_EXTERNAL_MODULE_zod__.z.record(__WEBPACK_EXTERNAL_MODULE_zod__.z.unknown()).optional(),
1111
+ policyId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1112
+ ipAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1113
+ userAgent: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1114
+ status: __WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
1115
+ 'active',
1116
+ 'withdrawn',
1117
+ 'expired'
1118
+ ]).default('active'),
1119
+ withdrawalReason: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1120
+ givenAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
1121
+ validUntil: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().optional(),
1122
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
1123
+ history: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(consentHistorySchema).default([])
1124
+ });
1125
+ function getConsentTable(options, consentFields) {
1126
+ const consentConfig = options.tables?.consent;
1127
+ const subjectConfig = options.tables?.subject;
1128
+ const domainConfig = options.tables?.domain;
1129
+ const policyConfig = options.tables?.consentPolicy;
1130
+ const purposeConfig = options.tables?.consentPurpose;
1131
+ return {
1132
+ entityName: consentConfig?.entityName || 'consent',
1133
+ entityPrefix: consentConfig?.entityPrefix || 'cns',
1134
+ schema: consentSchema,
1135
+ fields: {
1136
+ subjectId: {
1137
+ type: 'string',
1138
+ required: true,
1139
+ fieldName: consentConfig?.fields?.subjectId || 'subjectId',
1140
+ references: {
1141
+ model: subjectConfig?.entityName || 'subject',
1142
+ field: 'id'
1143
+ }
1144
+ },
1145
+ domainId: {
1146
+ type: 'string',
1147
+ required: true,
1148
+ fieldName: consentConfig?.fields?.domainId || 'domainId',
1149
+ references: {
1150
+ model: domainConfig?.entityName || 'domain',
1151
+ field: 'id'
1152
+ }
1153
+ },
1154
+ purposeIds: {
1155
+ type: 'json',
1156
+ required: false,
1157
+ fieldName: consentConfig?.fields?.purposeIds || 'purposeIds',
1158
+ references: {
1159
+ model: purposeConfig?.entityName || 'consentPurpose',
1160
+ field: 'id',
1161
+ type: 'array'
1162
+ }
1163
+ },
1164
+ metadata: {
1165
+ type: 'json',
1166
+ required: false,
1167
+ fieldName: consentConfig?.fields?.metadata || 'metadata'
1168
+ },
1169
+ policyId: {
1170
+ type: 'string',
1171
+ required: false,
1172
+ fieldName: consentConfig?.fields?.policyId || 'policyId',
1173
+ references: {
1174
+ model: policyConfig?.entityName || 'consentPolicy',
1175
+ field: 'id'
1176
+ }
1177
+ },
1178
+ ipAddress: {
1179
+ type: 'string',
1180
+ required: false,
1181
+ fieldName: consentConfig?.fields?.ipAddress || 'ipAddress'
1182
+ },
1183
+ userAgent: {
1184
+ type: 'string',
1185
+ required: false,
1186
+ fieldName: consentConfig?.fields?.userAgent || 'userAgent'
1187
+ },
1188
+ status: {
1189
+ type: 'string',
1190
+ defaultValue: ()=>'active',
1191
+ required: true,
1192
+ fieldName: consentConfig?.fields?.status || 'status'
1193
+ },
1194
+ withdrawalReason: {
1195
+ type: 'string',
1196
+ required: false,
1197
+ fieldName: consentConfig?.fields?.withdrawalReason || 'withdrawalReason'
1198
+ },
1199
+ givenAt: {
1200
+ type: 'date',
1201
+ defaultValue: ()=>new Date(),
1202
+ required: true,
1203
+ fieldName: consentConfig?.fields?.givenAt || 'givenAt'
1204
+ },
1205
+ validUntil: {
1206
+ type: 'date',
1207
+ required: false,
1208
+ fieldName: consentConfig?.fields?.validUntil || 'validUntil',
1209
+ transform: {
1210
+ input: (val, data)=>{
1211
+ if (val) return val;
1212
+ const expiresIn = consentConfig?.expiresIn || 31536000;
1213
+ const givenAt = data.givenAt instanceof Date ? data.givenAt : new Date();
1214
+ if (expiresIn > 0) {
1215
+ const validUntil = new Date(givenAt);
1216
+ validUntil.setSeconds(validUntil.getSeconds() + expiresIn);
1217
+ return validUntil;
1218
+ }
1219
+ }
1220
+ }
1221
+ },
1222
+ isActive: {
1223
+ type: 'boolean',
1224
+ defaultValue: true,
1225
+ required: true,
1226
+ fieldName: consentConfig?.fields?.isActive || 'isActive'
1227
+ },
1228
+ ...consentFields || {},
1229
+ ...consentConfig?.additionalFields || {}
1230
+ },
1231
+ order: 3
1232
+ };
1233
+ }
1234
+ const domainSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1235
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1236
+ name: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().min(1),
1237
+ description: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1238
+ allowedOrigins: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z.string()).optional().default([]),
1239
+ isVerified: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
1240
+ isActive: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(true),
1241
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
1242
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
1243
+ });
1244
+ function getDomainTable(options, domainFields) {
1245
+ const domainConfig = options.tables?.domain;
1246
+ return {
1247
+ entityName: domainConfig?.entityName || 'domain',
1248
+ entityPrefix: domainConfig?.entityPrefix || 'dom',
1249
+ schema: domainSchema,
1250
+ fields: {
1251
+ name: {
1252
+ type: 'string',
1253
+ required: true,
1254
+ unique: true,
1255
+ fieldName: domainConfig?.fields?.name || 'name'
1256
+ },
1257
+ description: {
1258
+ type: 'string',
1259
+ required: false,
1260
+ fieldName: domainConfig?.fields?.description || "description"
1261
+ },
1262
+ allowedOrigins: {
1263
+ type: 'json',
1264
+ defaultValue: ()=>[],
1265
+ required: false,
1266
+ fieldName: domainConfig?.fields?.allowedOrigins || 'allowedOrigins'
1267
+ },
1268
+ isVerified: {
1269
+ type: 'boolean',
1270
+ defaultValue: true,
1271
+ required: true,
1272
+ fieldName: domainConfig?.fields?.isVerified || 'isVerified'
1273
+ },
1274
+ isActive: {
1275
+ type: 'boolean',
1276
+ defaultValue: true,
1277
+ required: true,
1278
+ fieldName: domainConfig?.fields?.isActive || 'isActive'
1279
+ },
1280
+ createdAt: {
1281
+ type: 'date',
1282
+ defaultValue: ()=>new Date(),
1283
+ required: true,
1284
+ fieldName: domainConfig?.fields?.createdAt || 'createdAt'
1285
+ },
1286
+ updatedAt: {
1287
+ type: 'date',
1288
+ required: false,
1289
+ fieldName: domainConfig?.fields?.updatedAt || 'updatedAt'
1290
+ },
1291
+ ...domainFields || {},
1292
+ ...domainConfig?.additionalFields || {}
1293
+ },
1294
+ order: 1
1295
+ };
1296
+ }
1297
+ const geoLocationSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1298
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1299
+ countryCode: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().length(2).toUpperCase(),
1300
+ countryName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1301
+ regionCode: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1302
+ regionName: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1303
+ regulatoryZones: __WEBPACK_EXTERNAL_MODULE_zod__.z.array(__WEBPACK_EXTERNAL_MODULE_zod__.z["enum"]([
1304
+ 'GDPR',
1305
+ 'CCPA',
1306
+ 'CPRA',
1307
+ 'LGPD',
1308
+ 'PIPEDA'
1309
+ ])).optional(),
1310
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
1311
+ });
1312
+ function getGeoLocationTable(options, geoLocationFields) {
1313
+ const geoLocationConfig = options.tables?.geoLocation;
1314
+ return {
1315
+ entityName: geoLocationConfig?.entityName || 'geoLocation',
1316
+ entityPrefix: geoLocationConfig?.entityPrefix || 'geo',
1317
+ schema: geoLocationSchema,
1318
+ fields: {
1319
+ countryCode: {
1320
+ type: 'string',
1321
+ required: true,
1322
+ fieldName: geoLocationConfig?.fields?.countryCode || 'countryCode'
1323
+ },
1324
+ countryName: {
1325
+ type: 'string',
1326
+ required: true,
1327
+ fieldName: geoLocationConfig?.fields?.countryName || 'countryName'
1328
+ },
1329
+ regionCode: {
1330
+ type: 'string',
1331
+ required: false,
1332
+ fieldName: geoLocationConfig?.fields?.regionCode || 'regionCode'
1333
+ },
1334
+ regionName: {
1335
+ type: 'string',
1336
+ required: false,
1337
+ fieldName: geoLocationConfig?.fields?.regionName || 'regionName'
1338
+ },
1339
+ regulatoryZones: {
1340
+ type: 'json',
1341
+ required: false,
1342
+ fieldName: geoLocationConfig?.fields?.regulatoryZones || 'regulatoryZones',
1343
+ transformer: {
1344
+ input: (value)=>JSON.stringify(value),
1345
+ output: (value)=>{
1346
+ try {
1347
+ return JSON.parse(value);
1348
+ } catch {
1349
+ return [];
1350
+ }
1351
+ }
1352
+ }
1353
+ },
1354
+ createdAt: {
1355
+ type: 'date',
1356
+ defaultValue: ()=>new Date(),
1357
+ required: true,
1358
+ fieldName: geoLocationConfig?.fields?.createdAt || 'createdAt'
1359
+ },
1360
+ ...geoLocationFields || {},
1361
+ ...geoLocationConfig?.additionalFields || {}
1362
+ },
1363
+ indexes: [
1364
+ {
1365
+ name: 'country_code_index',
1366
+ fields: [
1367
+ 'countryCode'
1368
+ ]
1369
+ },
1370
+ {
1371
+ name: 'region_code_index',
1372
+ fields: [
1373
+ 'regionCode'
1374
+ ]
1375
+ },
1376
+ {
1377
+ name: 'created_at_index',
1378
+ fields: [
1379
+ 'createdAt'
1380
+ ]
1381
+ }
1382
+ ],
1383
+ order: 1
1384
+ };
1385
+ }
1386
+ const subjectSchema = __WEBPACK_EXTERNAL_MODULE_zod__.z.object({
1387
+ id: __WEBPACK_EXTERNAL_MODULE_zod__.z.string(),
1388
+ isIdentified: __WEBPACK_EXTERNAL_MODULE_zod__.z.boolean().default(false),
1389
+ externalId: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().nullable().optional(),
1390
+ identityProvider: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1391
+ lastIpAddress: __WEBPACK_EXTERNAL_MODULE_zod__.z.string().optional(),
1392
+ createdAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date()),
1393
+ updatedAt: __WEBPACK_EXTERNAL_MODULE_zod__.z.date().default(()=>new Date())
1394
+ });
1395
+ function getSubjectTable(options, subjectFields) {
1396
+ const subjectConfig = options.tables?.subject;
1397
+ return {
1398
+ entityName: subjectConfig?.entityName || 'subject',
1399
+ entityPrefix: subjectConfig?.entityPrefix || 'sub',
1400
+ schema: subjectSchema,
1401
+ fields: {
1402
+ isIdentified: {
1403
+ type: 'boolean',
1404
+ defaultValue: ()=>false,
1405
+ required: true,
1406
+ fieldName: subjectConfig?.fields?.isIdentified || 'isIdentified'
1407
+ },
1408
+ externalId: {
1409
+ type: 'string',
1410
+ required: false,
1411
+ fieldName: subjectConfig?.fields?.externalId || 'externalId'
1412
+ },
1413
+ identityProvider: {
1414
+ type: 'string',
1415
+ required: false,
1416
+ fieldName: subjectConfig?.fields?.identityProvider || 'identityProvider'
1417
+ },
1418
+ lastIpAddress: {
1419
+ type: 'string',
1420
+ required: false,
1421
+ fieldName: subjectConfig?.fields?.lastIpAddress || 'lastIpAddress'
1422
+ },
1423
+ createdAt: {
1424
+ type: 'date',
1425
+ defaultValue: ()=>new Date(),
1426
+ required: true,
1427
+ fieldName: subjectConfig?.fields?.createdAt || 'createdAt'
1428
+ },
1429
+ updatedAt: {
1430
+ type: 'date',
1431
+ defaultValue: ()=>new Date(),
1432
+ required: true,
1433
+ fieldName: subjectConfig?.fields?.updatedAt || 'updatedAt'
1434
+ },
1435
+ subjectTimezone: {
1436
+ type: 'timezone',
1437
+ required: false,
1438
+ defaultValue: COMMON_TIMEZONES.UTC,
1439
+ fieldName: subjectConfig?.fields?.subjectTimezone || 'subjectTimezone'
1440
+ },
1441
+ ...subjectFields || {},
1442
+ ...subjectConfig?.additionalFields || {}
1443
+ },
1444
+ order: 1
1445
+ };
1446
+ }
1447
+ function getSchema(config) {
1448
+ const entities = definition_getConsentTables(config);
1449
+ const schema = {};
1450
+ for (const [key, entity] of Object.entries(entities)){
1451
+ if (!entity) continue;
1452
+ const fields = entity.fields || {};
1453
+ const processedFields = {};
1454
+ for (const [fieldKey, field] of Object.entries(fields)){
1455
+ if (!field) continue;
1456
+ const fieldName = field.fieldName || fieldKey;
1457
+ const typedField = field;
1458
+ processedFields[fieldName] = typedField;
1459
+ if (typedField && 'references' in typedField && typedField.references) {
1460
+ const entityName = typedField.references.model;
1461
+ const referencedEntity = entities[entityName];
1462
+ if (referencedEntity) processedFields[fieldName] = {
1463
+ ...typedField,
1464
+ references: {
1465
+ model: referencedEntity.entityName,
1466
+ entity: referencedEntity.entityName,
1467
+ field: typedField.references.field,
1468
+ onDelete: typedField.references.onDelete
1469
+ }
1470
+ };
1471
+ }
1472
+ }
1473
+ const entityName = entity.entityName || key;
1474
+ if (entityName in schema) {
1475
+ const existingEntry = schema[entityName];
1476
+ schema[entityName] = {
1477
+ ...existingEntry,
1478
+ order: existingEntry?.order ?? Number.POSITIVE_INFINITY,
1479
+ fields: {
1480
+ ...existingEntry?.fields,
1481
+ ...processedFields
1482
+ }
1483
+ };
1484
+ } else schema[entityName] = {
1485
+ fields: processedFields,
1486
+ order: entity.order ?? Number.POSITIVE_INFINITY
1487
+ };
1488
+ }
1489
+ return schema;
1490
+ }
1491
+ function analyzeSchemaChanges(config, tableMetadata, dbType) {
1492
+ const betterAuthSchema = getSchema(config);
1493
+ const logger = logger_createLogger(config.logger);
1494
+ const toBeCreated = [];
1495
+ const toBeAdded = [];
1496
+ for (const [key, value] of Object.entries(betterAuthSchema)){
1497
+ const table = tableMetadata.find((t)=>t.name === key);
1498
+ if (!table) {
1499
+ handleNewTable(key, value, toBeCreated);
1500
+ continue;
1501
+ }
1502
+ handleExistingTable(key, value, table, toBeAdded, dbType, logger);
1503
+ }
1504
+ return {
1505
+ toBeCreated,
1506
+ toBeAdded
1507
+ };
1508
+ }
1509
+ function handleNewTable(tableName, value, toBeCreated) {
1510
+ const tIndex = toBeCreated.findIndex((t)=>t.table === tableName);
1511
+ const tableData = {
1512
+ table: tableName,
1513
+ fields: value.fields,
1514
+ order: value.order || Number.POSITIVE_INFINITY
1515
+ };
1516
+ const insertIndex = toBeCreated.findIndex((t)=>(t.order || Number.POSITIVE_INFINITY) > tableData.order);
1517
+ if (-1 === insertIndex) {
1518
+ if (-1 === tIndex) toBeCreated.push(tableData);
1519
+ else {
1520
+ const existingTable = toBeCreated[tIndex];
1521
+ if (existingTable) existingTable.fields = {
1522
+ ...existingTable.fields,
1523
+ ...value.fields
1524
+ };
1525
+ }
1526
+ } else toBeCreated.splice(insertIndex, 0, tableData);
1527
+ }
1528
+ function handleExistingTable(tableName, value, table, toBeAdded, dbType, logger) {
1529
+ const toBeAddedFields = {};
1530
+ for (const [fieldName, field] of Object.entries(value.fields)){
1531
+ const column = table.columns.find((c)=>c.name === fieldName);
1532
+ if (!column) {
1533
+ toBeAddedFields[fieldName] = field;
1534
+ continue;
1535
+ }
1536
+ if (!matchType(column.dataType, field.type, dbType)) logger.warn(`Field ${fieldName} in table ${tableName} has a different type in the database. Expected ${field.type} but got ${column.dataType}.`);
1537
+ }
1538
+ if (Object.keys(toBeAddedFields).length > 0) toBeAdded.push({
1539
+ table: tableName,
1540
+ fields: toBeAddedFields,
1541
+ order: value.order || Number.POSITIVE_INFINITY
1542
+ });
1543
+ }
1544
+ async function getMigrations(config) {
1545
+ const logger = logger_createLogger(config.logger);
1546
+ let { kysely: db, databaseType: dbType } = await dialect_createKyselyAdapter(config);
1547
+ if (!dbType) {
1548
+ logger.warn('Could not determine database type, defaulting to sqlite. Please provide a type in the database options to avoid this.');
1549
+ dbType = 'sqlite';
1550
+ }
1551
+ if (!db) {
1552
+ logger.error("Only kysely adapter is supported for migrations. You can use `generate` command to generate the schema, if you're using a different adapter.");
1553
+ process.exit(1);
1554
+ }
1555
+ const tableMetadata = await db.introspection.getTables();
1556
+ const { toBeCreated, toBeAdded } = analyzeSchemaChanges(config, tableMetadata, dbType);
1557
+ const columnMigrations = buildColumnAddMigrations(db, toBeAdded, dbType);
1558
+ const tableMigrations = buildTableCreateMigrations(db, toBeCreated, dbType);
1559
+ const migrations = [
1560
+ ...columnMigrations,
1561
+ ...tableMigrations
1562
+ ];
1563
+ const { runMigrations, compileMigrations } = createMigrationExecutors(migrations);
1564
+ return {
1565
+ toBeCreated,
1566
+ toBeAdded,
1567
+ runMigrations,
1568
+ compileMigrations
1569
+ };
1570
+ }
1571
+ export { getMigrations };