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