@c15t/backend 1.5.0 → 1.6.0

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 (489) hide show
  1. package/.turbo/turbo-build.log +63 -37
  2. package/CHANGELOG.md +4 -209
  3. package/README.md +86 -164
  4. package/dist/contracts/consent/index.d.ts +103 -615
  5. package/dist/contracts/consent/index.d.ts.map +1 -1
  6. package/dist/contracts/consent/post.contract.d.ts +42 -140
  7. package/dist/contracts/consent/post.contract.d.ts.map +1 -1
  8. package/dist/contracts/consent/show-banner.contract.d.ts +28 -376
  9. package/dist/contracts/consent/show-banner.contract.d.ts.map +1 -1
  10. package/dist/contracts/consent/verify.contract.d.ts +33 -99
  11. package/dist/contracts/consent/verify.contract.d.ts.map +1 -1
  12. package/dist/contracts/index.d.ts +222 -1356
  13. package/dist/contracts/index.d.ts.map +1 -1
  14. package/dist/contracts/meta/index.d.ts +8 -63
  15. package/dist/contracts/meta/index.d.ts.map +1 -1
  16. package/dist/contracts/meta/status.contract.d.ts +8 -63
  17. package/dist/contracts/meta/status.contract.d.ts.map +1 -1
  18. package/dist/contracts/shared/jurisdiction.schema.d.ts +21 -9
  19. package/dist/contracts/shared/jurisdiction.schema.d.ts.map +1 -1
  20. package/dist/contracts.cjs +100 -106
  21. package/dist/contracts.js +100 -106
  22. package/dist/core.cjs +681 -681
  23. package/dist/core.d.ts +118 -678
  24. package/dist/core.d.ts.map +1 -1
  25. package/dist/core.js +634 -637
  26. package/dist/handlers/consent/index.d.ts +103 -615
  27. package/dist/handlers/consent/index.d.ts.map +1 -1
  28. package/dist/handlers/consent/post.handler.d.ts +42 -140
  29. package/dist/handlers/consent/post.handler.d.ts.map +1 -1
  30. package/dist/handlers/consent/show-banner/handler.d.ts +28 -376
  31. package/dist/handlers/consent/show-banner/handler.d.ts.map +1 -1
  32. package/dist/handlers/consent/show-banner/translations.d.ts.map +1 -1
  33. package/dist/handlers/consent/verify.handler.d.ts +33 -99
  34. package/dist/handlers/consent/verify.handler.d.ts.map +1 -1
  35. package/dist/handlers/meta/index.d.ts +8 -63
  36. package/dist/handlers/meta/index.d.ts.map +1 -1
  37. package/dist/handlers/meta/status.handler.d.ts +8 -63
  38. package/dist/handlers/meta/status.handler.d.ts.map +1 -1
  39. package/dist/init.d.ts.map +1 -1
  40. package/dist/middleware/openapi/index.d.ts +2 -2
  41. package/dist/middleware/openapi/index.d.ts.map +1 -1
  42. package/dist/pkgs/data-model/fields/index.cjs +14 -26
  43. package/dist/pkgs/data-model/fields/index.d.ts +4 -4
  44. package/dist/pkgs/data-model/fields/index.d.ts.map +1 -1
  45. package/dist/pkgs/data-model/fields/index.js +14 -26
  46. package/dist/pkgs/data-model/fields/zod-fields.d.ts +195 -871
  47. package/dist/pkgs/data-model/fields/zod-fields.d.ts.map +1 -1
  48. package/dist/pkgs/data-model/hooks/index.d.ts +2 -2
  49. package/dist/pkgs/data-model/hooks/index.d.ts.map +1 -1
  50. package/dist/pkgs/data-model/index.cjs +346 -358
  51. package/dist/pkgs/data-model/index.d.ts +1 -1
  52. package/dist/pkgs/data-model/index.d.ts.map +1 -1
  53. package/dist/pkgs/data-model/index.js +345 -357
  54. package/dist/pkgs/data-model/schema/index.cjs +346 -358
  55. package/dist/pkgs/data-model/schema/index.d.ts +1 -1
  56. package/dist/pkgs/data-model/schema/index.d.ts.map +1 -1
  57. package/dist/pkgs/data-model/schema/index.js +345 -357
  58. package/dist/pkgs/data-model/schema/schemas.d.ts +2 -2
  59. package/dist/pkgs/data-model/schema/schemas.d.ts.map +1 -1
  60. package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts +3 -0
  61. package/dist/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.d.ts.map +1 -1
  62. package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.cjs +158 -170
  63. package/dist/pkgs/db-adapters/adapters/drizzle-adapter/index.js +157 -169
  64. package/dist/pkgs/db-adapters/adapters/index.d.ts +2 -2
  65. package/dist/pkgs/db-adapters/adapters/index.d.ts.map +1 -1
  66. package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.cjs +215 -227
  67. package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.d.ts +2 -2
  68. package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.d.ts.map +1 -1
  69. package/dist/pkgs/db-adapters/adapters/kysely-adapter/index.js +213 -225
  70. package/dist/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.d.ts +2 -0
  71. package/dist/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.d.ts.map +1 -1
  72. package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts +1 -1
  73. package/dist/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.d.ts.map +1 -1
  74. package/dist/pkgs/db-adapters/adapters/memory-adapter/index.cjs +158 -170
  75. package/dist/pkgs/db-adapters/adapters/memory-adapter/index.js +157 -169
  76. package/dist/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.d.ts +3 -0
  77. package/dist/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.d.ts.map +1 -1
  78. package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs +243 -255
  79. package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.d.ts +1 -1
  80. package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.d.ts.map +1 -1
  81. package/dist/pkgs/db-adapters/adapters/prisma-adapter/index.js +241 -253
  82. package/dist/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.d.ts +3 -0
  83. package/dist/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.d.ts.map +1 -1
  84. package/dist/pkgs/db-adapters/index.cjs +714 -726
  85. package/dist/pkgs/db-adapters/index.d.ts +6 -6
  86. package/dist/pkgs/db-adapters/index.d.ts.map +1 -1
  87. package/dist/pkgs/db-adapters/index.js +708 -720
  88. package/dist/pkgs/migrations/get-migration.d.ts.map +1 -1
  89. package/dist/pkgs/migrations/get-schema/get-schema.d.ts.map +1 -1
  90. package/dist/pkgs/migrations/get-schema/process-tables.d.ts.map +1 -1
  91. package/dist/pkgs/migrations/index.cjs +236 -248
  92. package/dist/pkgs/migrations/index.d.ts +4 -4
  93. package/dist/pkgs/migrations/index.d.ts.map +1 -1
  94. package/dist/pkgs/migrations/index.js +235 -247
  95. package/dist/pkgs/results/index.cjs +67 -67
  96. package/dist/pkgs/results/index.d.ts +5 -5
  97. package/dist/pkgs/results/index.d.ts.map +1 -1
  98. package/dist/pkgs/results/index.js +67 -67
  99. package/dist/pkgs/results/orpc-error-handler.d.ts +1 -1
  100. package/dist/pkgs/results/orpc-error-handler.d.ts.map +1 -1
  101. package/dist/pkgs/types/index.d.ts +1 -2
  102. package/dist/pkgs/types/index.d.ts.map +1 -1
  103. package/dist/pkgs/types/options.d.ts +9 -2
  104. package/dist/pkgs/types/options.d.ts.map +1 -1
  105. package/dist/pkgs/utils/index.d.ts +1 -1
  106. package/dist/pkgs/utils/index.d.ts.map +1 -1
  107. package/dist/pkgs/utils/logger.d.ts +1 -1
  108. package/dist/pkgs/utils/logger.d.ts.map +1 -1
  109. package/dist/router.cjs +114 -117
  110. package/dist/router.d.ts +111 -678
  111. package/dist/router.d.ts.map +1 -1
  112. package/dist/router.js +114 -117
  113. package/dist/schema/audit-log/schema.d.ts +2 -24
  114. package/dist/schema/audit-log/schema.d.ts.map +1 -1
  115. package/dist/schema/audit-log/table.d.ts +2 -24
  116. package/dist/schema/audit-log/table.d.ts.map +1 -1
  117. package/dist/schema/consent/registry.d.ts +8 -8
  118. package/dist/schema/consent/schema.d.ts +9 -33
  119. package/dist/schema/consent/schema.d.ts.map +1 -1
  120. package/dist/schema/consent/table.d.ts +9 -33
  121. package/dist/schema/consent/table.d.ts.map +1 -1
  122. package/dist/schema/consent-policy/registry.d.ts +20 -20
  123. package/dist/schema/consent-policy/schema.d.ts +22 -30
  124. package/dist/schema/consent-policy/schema.d.ts.map +1 -1
  125. package/dist/schema/consent-policy/table.d.ts +13 -29
  126. package/dist/schema/consent-policy/table.d.ts.map +1 -1
  127. package/dist/schema/consent-purpose/registry.d.ts +6 -6
  128. package/dist/schema/consent-purpose/schema.d.ts +5 -27
  129. package/dist/schema/consent-purpose/schema.d.ts.map +1 -1
  130. package/dist/schema/consent-purpose/table.d.ts +5 -27
  131. package/dist/schema/consent-purpose/table.d.ts.map +1 -1
  132. package/dist/schema/consent-record/schema.d.ts +3 -19
  133. package/dist/schema/consent-record/schema.d.ts.map +1 -1
  134. package/dist/schema/consent-record/table.d.ts +3 -19
  135. package/dist/schema/consent-record/table.d.ts.map +1 -1
  136. package/dist/schema/create-registry.d.ts +58 -58
  137. package/dist/schema/definition.d.ts +42 -176
  138. package/dist/schema/definition.d.ts.map +1 -1
  139. package/dist/schema/domain/registry.d.ts +20 -20
  140. package/dist/schema/domain/schema.d.ts +6 -24
  141. package/dist/schema/domain/schema.d.ts.map +1 -1
  142. package/dist/schema/domain/table.d.ts +6 -24
  143. package/dist/schema/domain/table.d.ts.map +1 -1
  144. package/dist/schema/index.cjs +426 -438
  145. package/dist/schema/index.d.ts +12 -12
  146. package/dist/schema/index.d.ts.map +1 -1
  147. package/dist/schema/index.js +426 -438
  148. package/dist/schema/schemas.d.ts +42 -176
  149. package/dist/schema/schemas.d.ts.map +1 -1
  150. package/dist/schema/subject/registry.d.ts +4 -4
  151. package/dist/schema/subject/schema.d.ts +4 -20
  152. package/dist/schema/subject/schema.d.ts.map +1 -1
  153. package/dist/schema/subject/table.d.ts +4 -20
  154. package/dist/schema/subject/table.d.ts.map +1 -1
  155. package/dist/schema/types.d.ts +1 -1
  156. package/dist/schema/types.d.ts.map +1 -1
  157. package/dist/testing/contract-testing.d.ts +3 -2
  158. package/dist/testing/contract-testing.d.ts.map +1 -1
  159. package/dist/types/index.d.ts +5 -4
  160. package/dist/types/index.d.ts.map +1 -1
  161. package/dist/types/options.d.ts +2 -2
  162. package/dist/types/options.d.ts.map +1 -1
  163. package/dist/v2/contracts/consent/index.d.ts +260 -0
  164. package/dist/v2/contracts/consent/index.d.ts.map +1 -0
  165. package/dist/v2/contracts/consent/index.test.d.ts +2 -0
  166. package/dist/v2/contracts/consent/index.test.d.ts.map +1 -0
  167. package/dist/v2/contracts/consent/post.contract.d.ts +114 -0
  168. package/dist/v2/contracts/consent/post.contract.d.ts.map +1 -0
  169. package/dist/v2/contracts/consent/post.contract.test.d.ts +2 -0
  170. package/dist/v2/contracts/consent/post.contract.test.d.ts.map +1 -0
  171. package/dist/v2/contracts/consent/show-banner.contract.d.ts +68 -0
  172. package/dist/v2/contracts/consent/show-banner.contract.d.ts.map +1 -0
  173. package/dist/v2/contracts/consent/show-banner.contract.test.d.ts +2 -0
  174. package/dist/v2/contracts/consent/show-banner.contract.test.d.ts.map +1 -0
  175. package/dist/v2/contracts/consent/verify.contract.d.ts +81 -0
  176. package/dist/v2/contracts/consent/verify.contract.d.ts.map +1 -0
  177. package/dist/v2/contracts/consent/verify.contract.test.d.ts +2 -0
  178. package/dist/v2/contracts/consent/verify.contract.test.d.ts.map +1 -0
  179. package/dist/v2/contracts/index.cjs +644 -0
  180. package/dist/v2/contracts/index.d.ts +563 -0
  181. package/dist/v2/contracts/index.d.ts.map +1 -0
  182. package/dist/v2/contracts/index.js +607 -0
  183. package/dist/v2/contracts/meta/index.d.ts +19 -0
  184. package/dist/v2/contracts/meta/index.d.ts.map +1 -0
  185. package/dist/v2/contracts/meta/index.test.d.ts +2 -0
  186. package/dist/v2/contracts/meta/index.test.d.ts.map +1 -0
  187. package/dist/v2/contracts/meta/status.contract.d.ts +18 -0
  188. package/dist/v2/contracts/meta/status.contract.d.ts.map +1 -0
  189. package/dist/v2/contracts/meta/status.contract.test.d.ts +2 -0
  190. package/dist/v2/contracts/meta/status.contract.test.d.ts.map +1 -0
  191. package/dist/v2/contracts/shared/jurisdiction.schema.d.ts +36 -0
  192. package/dist/v2/contracts/shared/jurisdiction.schema.d.ts.map +1 -0
  193. package/dist/v2/contracts/test.utils.d.ts +38 -0
  194. package/dist/v2/contracts/test.utils.d.ts.map +1 -0
  195. package/dist/v2/core.cjs +2181 -0
  196. package/dist/v2/core.d.ts +364 -0
  197. package/dist/v2/core.d.ts.map +1 -0
  198. package/dist/v2/core.js +2130 -0
  199. package/dist/v2/db/adapters/drizzle.cjs +36 -0
  200. package/dist/v2/db/adapters/drizzle.d.ts +2 -0
  201. package/dist/v2/db/adapters/drizzle.d.ts.map +1 -0
  202. package/dist/v2/db/adapters/drizzle.js +3 -0
  203. package/dist/v2/db/adapters/index.cjs +18 -0
  204. package/dist/v2/db/adapters/index.d.ts +2 -0
  205. package/dist/v2/db/adapters/index.d.ts.map +1 -0
  206. package/dist/v2/db/adapters/index.js +0 -0
  207. package/dist/v2/db/adapters/kysely.cjs +36 -0
  208. package/dist/v2/db/adapters/kysely.d.ts +2 -0
  209. package/dist/v2/db/adapters/kysely.d.ts.map +1 -0
  210. package/dist/v2/db/adapters/kysely.js +3 -0
  211. package/dist/v2/db/adapters/mongo.cjs +36 -0
  212. package/dist/v2/db/adapters/mongo.d.ts +2 -0
  213. package/dist/v2/db/adapters/mongo.d.ts.map +1 -0
  214. package/dist/v2/db/adapters/mongo.js +3 -0
  215. package/dist/v2/db/adapters/prisma.cjs +36 -0
  216. package/dist/v2/db/adapters/prisma.d.ts +2 -0
  217. package/dist/v2/db/adapters/prisma.d.ts.map +1 -0
  218. package/dist/v2/db/adapters/prisma.js +3 -0
  219. package/dist/v2/db/adapters/typeorm.cjs +36 -0
  220. package/dist/v2/db/adapters/typeorm.d.ts +2 -0
  221. package/dist/v2/db/adapters/typeorm.d.ts.map +1 -0
  222. package/dist/v2/db/adapters/typeorm.js +3 -0
  223. package/dist/v2/db/migrator/index.cjs +61 -0
  224. package/dist/v2/db/migrator/index.d.ts +29 -0
  225. package/dist/v2/db/migrator/index.d.ts.map +1 -0
  226. package/dist/v2/db/migrator/index.js +27 -0
  227. package/dist/v2/db/registry/audit-log.d.ts +21 -0
  228. package/dist/v2/db/registry/audit-log.d.ts.map +1 -0
  229. package/dist/v2/db/registry/audit-log.test.d.ts +2 -0
  230. package/dist/v2/db/registry/audit-log.test.d.ts.map +1 -0
  231. package/dist/v2/db/registry/consent-policy.d.ts +29 -0
  232. package/dist/v2/db/registry/consent-policy.d.ts.map +1 -0
  233. package/dist/v2/db/registry/consent-policy.test.d.ts +2 -0
  234. package/dist/v2/db/registry/consent-policy.test.d.ts.map +1 -0
  235. package/dist/v2/db/registry/consent-purpose.d.ts +16 -0
  236. package/dist/v2/db/registry/consent-purpose.d.ts.map +1 -0
  237. package/dist/v2/db/registry/consent-purpose.test.d.ts +2 -0
  238. package/dist/v2/db/registry/consent-purpose.test.d.ts.map +1 -0
  239. package/dist/v2/db/registry/consent.d.ts +20 -0
  240. package/dist/v2/db/registry/consent.d.ts.map +1 -0
  241. package/dist/v2/db/registry/consent.test.d.ts +2 -0
  242. package/dist/v2/db/registry/consent.test.d.ts.map +1 -0
  243. package/dist/v2/db/registry/domain.d.ts +24 -0
  244. package/dist/v2/db/registry/domain.d.ts.map +1 -0
  245. package/dist/v2/db/registry/domain.test.d.ts +2 -0
  246. package/dist/v2/db/registry/domain.test.d.ts.map +1 -0
  247. package/dist/v2/db/registry/index.d.ts +102 -0
  248. package/dist/v2/db/registry/index.d.ts.map +1 -0
  249. package/dist/v2/db/registry/subject.d.ts +18 -0
  250. package/dist/v2/db/registry/subject.d.ts.map +1 -0
  251. package/dist/v2/db/registry/subject.test.d.ts +2 -0
  252. package/dist/v2/db/registry/subject.test.d.ts.map +1 -0
  253. package/dist/v2/db/registry/types.d.ts +10 -0
  254. package/dist/v2/db/registry/types.d.ts.map +1 -0
  255. package/dist/v2/db/registry/utils/generate-id.d.ts +25 -0
  256. package/dist/v2/db/registry/utils/generate-id.d.ts.map +1 -0
  257. package/dist/v2/db/registry/utils/generate-id.test.d.ts +2 -0
  258. package/dist/v2/db/registry/utils/generate-id.test.d.ts.map +1 -0
  259. package/dist/v2/db/registry/utils.d.ts +25 -0
  260. package/dist/v2/db/registry/utils.d.ts.map +1 -0
  261. package/dist/v2/db/schema/1.0.0/audit-log.d.ts +29 -0
  262. package/dist/v2/db/schema/1.0.0/audit-log.d.ts.map +1 -0
  263. package/dist/v2/db/schema/1.0.0/consent-policy.d.ts +45 -0
  264. package/dist/v2/db/schema/1.0.0/consent-policy.d.ts.map +1 -0
  265. package/dist/v2/db/schema/1.0.0/consent-purpose.d.ts +27 -0
  266. package/dist/v2/db/schema/1.0.0/consent-purpose.d.ts.map +1 -0
  267. package/dist/v2/db/schema/1.0.0/consent-record.d.ts +19 -0
  268. package/dist/v2/db/schema/1.0.0/consent-record.d.ts.map +1 -0
  269. package/dist/v2/db/schema/1.0.0/consent.d.ts +42 -0
  270. package/dist/v2/db/schema/1.0.0/consent.d.ts.map +1 -0
  271. package/dist/v2/db/schema/1.0.0/domain.d.ts +23 -0
  272. package/dist/v2/db/schema/1.0.0/domain.d.ts.map +1 -0
  273. package/dist/v2/db/schema/1.0.0/index.d.ts +1513 -0
  274. package/dist/v2/db/schema/1.0.0/index.d.ts.map +1 -0
  275. package/dist/v2/db/schema/1.0.0/subject.d.ts +23 -0
  276. package/dist/v2/db/schema/1.0.0/subject.d.ts.map +1 -0
  277. package/dist/v2/db/schema/index.cjs +326 -0
  278. package/dist/v2/db/schema/index.d.ts +1507 -0
  279. package/dist/v2/db/schema/index.d.ts.map +1 -0
  280. package/dist/v2/db/schema/index.js +241 -0
  281. package/dist/v2/define-config.cjs +36 -0
  282. package/dist/v2/define-config.d.ts +5 -0
  283. package/dist/v2/define-config.d.ts.map +1 -0
  284. package/dist/v2/define-config.js +2 -0
  285. package/dist/v2/handlers/consent/index.d.ts +260 -0
  286. package/dist/v2/handlers/consent/index.d.ts.map +1 -0
  287. package/dist/v2/handlers/consent/post.handler.d.ts +136 -0
  288. package/dist/v2/handlers/consent/post.handler.d.ts.map +1 -0
  289. package/dist/v2/handlers/consent/show-banner/geo.d.ts +10 -0
  290. package/dist/v2/handlers/consent/show-banner/geo.d.ts.map +1 -0
  291. package/dist/v2/handlers/consent/show-banner/geo.test.d.ts +2 -0
  292. package/dist/v2/handlers/consent/show-banner/geo.test.d.ts.map +1 -0
  293. package/dist/v2/handlers/consent/show-banner/handler.d.ts +71 -0
  294. package/dist/v2/handlers/consent/show-banner/handler.d.ts.map +1 -0
  295. package/dist/v2/handlers/consent/show-banner/handler.test.d.ts +2 -0
  296. package/dist/v2/handlers/consent/show-banner/handler.test.d.ts.map +1 -0
  297. package/dist/v2/handlers/consent/show-banner/translations.d.ts +13 -0
  298. package/dist/v2/handlers/consent/show-banner/translations.d.ts.map +1 -0
  299. package/dist/v2/handlers/consent/show-banner/translations.test.d.ts +2 -0
  300. package/dist/v2/handlers/consent/show-banner/translations.test.d.ts.map +1 -0
  301. package/dist/v2/handlers/consent/verify.handler.d.ts +103 -0
  302. package/dist/v2/handlers/consent/verify.handler.d.ts.map +1 -0
  303. package/dist/v2/handlers/meta/index.d.ts +19 -0
  304. package/dist/v2/handlers/meta/index.d.ts.map +1 -0
  305. package/dist/v2/handlers/meta/status.handler.d.ts +17 -0
  306. package/dist/v2/handlers/meta/status.handler.d.ts.map +1 -0
  307. package/dist/v2/init.d.ts +3 -0
  308. package/dist/v2/init.d.ts.map +1 -0
  309. package/dist/v2/init.test.d.ts +2 -0
  310. package/dist/v2/init.test.d.ts.map +1 -0
  311. package/dist/v2/middleware/cors/cors.d.ts +37 -0
  312. package/dist/v2/middleware/cors/cors.d.ts.map +1 -0
  313. package/dist/v2/middleware/cors/cors.test.d.ts +2 -0
  314. package/dist/v2/middleware/cors/cors.test.d.ts.map +1 -0
  315. package/dist/v2/middleware/cors/index.d.ts +30 -0
  316. package/dist/v2/middleware/cors/index.d.ts.map +1 -0
  317. package/dist/v2/middleware/cors/is-origin-trusted.d.ts +49 -0
  318. package/dist/v2/middleware/cors/is-origin-trusted.d.ts.map +1 -0
  319. package/dist/v2/middleware/cors/is-origin-trusted.test.d.ts +2 -0
  320. package/dist/v2/middleware/cors/is-origin-trusted.test.d.ts.map +1 -0
  321. package/dist/v2/middleware/cors/process-cors.d.ts +31 -0
  322. package/dist/v2/middleware/cors/process-cors.d.ts.map +1 -0
  323. package/dist/v2/middleware/openapi/config.d.ts +28 -0
  324. package/dist/v2/middleware/openapi/config.d.ts.map +1 -0
  325. package/dist/v2/middleware/openapi/handlers.d.ts +29 -0
  326. package/dist/v2/middleware/openapi/handlers.d.ts.map +1 -0
  327. package/dist/v2/middleware/openapi/index.d.ts +11 -0
  328. package/dist/v2/middleware/openapi/index.d.ts.map +1 -0
  329. package/dist/v2/middleware/process-ip/index.d.ts +3 -0
  330. package/dist/v2/middleware/process-ip/index.d.ts.map +1 -0
  331. package/dist/v2/router.cjs +1275 -0
  332. package/dist/v2/router.d.ts +280 -0
  333. package/dist/v2/router.d.ts.map +1 -0
  334. package/dist/v2/router.js +1231 -0
  335. package/dist/v2/types/api.d.ts +27 -0
  336. package/dist/v2/types/api.d.ts.map +1 -0
  337. package/dist/v2/types/index.cjs +40 -0
  338. package/dist/v2/types/index.d.ts +104 -0
  339. package/dist/v2/types/index.d.ts.map +1 -0
  340. package/dist/v2/types/index.js +6 -0
  341. package/dist/v2/utils/create-telemetry-options.d.ts +28 -0
  342. package/dist/v2/utils/create-telemetry-options.d.ts.map +1 -0
  343. package/dist/v2/utils/env.d.ts +60 -0
  344. package/dist/v2/utils/env.d.ts.map +1 -0
  345. package/dist/v2/utils/index.d.ts +3 -0
  346. package/dist/v2/utils/index.d.ts.map +1 -0
  347. package/dist/v2/utils/logger.d.ts +16 -0
  348. package/dist/v2/utils/logger.d.ts.map +1 -0
  349. package/dist/version.d.ts +1 -1
  350. package/package.json +106 -15
  351. package/readme.json +30 -0
  352. package/rslib.config.ts +13 -14
  353. package/src/__tests__/server.test.ts +1 -1
  354. package/src/contracts/consent/post.contract.test.ts +3 -8
  355. package/src/contracts/consent/post.contract.ts +13 -13
  356. package/src/contracts/consent/show-banner.contract.test.ts +9 -0
  357. package/src/contracts/consent/show-banner.contract.ts +2 -0
  358. package/src/contracts/consent/verify.contract.ts +19 -23
  359. package/src/core.ts +7 -0
  360. package/src/handlers/consent/show-banner/handler.ts +12 -9
  361. package/src/handlers/consent/show-banner/translations.ts +2 -2
  362. package/src/init.ts +9 -6
  363. package/src/middleware/openapi/index.ts +2 -2
  364. package/src/pkgs/api-router/hooks/__tests__/processor.test.ts +1 -1
  365. package/src/pkgs/data-model/fields/index.ts +17 -22
  366. package/src/pkgs/data-model/fields/zod-fields.ts +14 -26
  367. package/src/pkgs/data-model/hooks/index.ts +3 -2
  368. package/src/pkgs/data-model/index.ts +2 -4
  369. package/src/pkgs/data-model/schema/index.ts +6 -7
  370. package/src/pkgs/data-model/schema/schemas.ts +3 -3
  371. package/src/pkgs/db-adapters/adapters/drizzle-adapter/drizzle-adapter.ts +4 -1
  372. package/src/pkgs/db-adapters/adapters/index.ts +2 -2
  373. package/src/pkgs/db-adapters/adapters/kysely-adapter/index.ts +4 -4
  374. package/src/pkgs/db-adapters/adapters/kysely-adapter/kysely-adapter.ts +4 -5
  375. package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/postgres.test.ts +2 -4
  376. package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/sqlite.test.ts +2 -3
  377. package/src/pkgs/db-adapters/adapters/kysely-adapter/tests/test-utils.ts +1 -6
  378. package/src/pkgs/db-adapters/adapters/memory-adapter/memory-adapter.ts +4 -1
  379. package/src/pkgs/db-adapters/adapters/prisma-adapter/index.ts +1 -1
  380. package/src/pkgs/db-adapters/adapters/prisma-adapter/prisma-adapter.ts +5 -2
  381. package/src/pkgs/db-adapters/index.ts +12 -13
  382. package/src/pkgs/migrations/get-migration.ts +4 -2
  383. package/src/pkgs/migrations/get-schema/get-schema.ts +0 -1
  384. package/src/pkgs/migrations/get-schema/process-fields.ts +1 -1
  385. package/src/pkgs/migrations/get-schema/process-tables.ts +0 -2
  386. package/src/pkgs/migrations/index.ts +7 -8
  387. package/src/pkgs/results/__tests__/error-codes.test.ts +2 -2
  388. package/src/pkgs/results/index.ts +22 -27
  389. package/src/pkgs/results/orpc-error-handler.ts +1 -1
  390. package/src/pkgs/results/results/result-helpers.ts +1 -1
  391. package/src/pkgs/types/index.ts +4 -4
  392. package/src/pkgs/types/options.ts +10 -3
  393. package/src/pkgs/utils/index.ts +1 -1
  394. package/src/pkgs/utils/logger.ts +1 -1
  395. package/src/schema/audit-log/schema.ts +3 -3
  396. package/src/schema/consent/schema.ts +4 -4
  397. package/src/schema/consent-policy/schema.ts +3 -3
  398. package/src/schema/consent-purpose/schema.ts +4 -4
  399. package/src/schema/consent-record/schema.ts +3 -3
  400. package/src/schema/definition.ts +1 -1
  401. package/src/schema/domain/schema.ts +5 -5
  402. package/src/schema/index.ts +14 -17
  403. package/src/schema/subject/schema.ts +3 -3
  404. package/src/schema/types.ts +1 -1
  405. package/src/testing/contract-testing.ts +15 -52
  406. package/src/types/index.ts +8 -8
  407. package/src/types/options.ts +2 -3
  408. package/src/v2/contracts/consent/index.test.ts +5 -0
  409. package/src/v2/contracts/consent/index.ts +9 -0
  410. package/src/v2/contracts/consent/post.contract.test.ts +521 -0
  411. package/src/v2/contracts/consent/post.contract.ts +155 -0
  412. package/src/v2/contracts/consent/show-banner.contract.test.ts +252 -0
  413. package/src/v2/contracts/consent/show-banner.contract.ts +73 -0
  414. package/src/v2/contracts/consent/verify.contract.test.ts +185 -0
  415. package/src/v2/contracts/consent/verify.contract.ts +122 -0
  416. package/src/v2/contracts/index.ts +20 -0
  417. package/src/v2/contracts/meta/index.test.ts +5 -0
  418. package/src/v2/contracts/meta/index.ts +5 -0
  419. package/src/v2/contracts/meta/status.contract.test.ts +226 -0
  420. package/src/v2/contracts/meta/status.contract.ts +34 -0
  421. package/src/v2/contracts/shared/jurisdiction.schema.ts +30 -0
  422. package/src/v2/contracts/test.utils.ts +400 -0
  423. package/src/v2/core.ts +379 -0
  424. package/src/v2/db/adapters/drizzle.ts +1 -0
  425. package/src/v2/db/adapters/index.ts +1 -0
  426. package/src/v2/db/adapters/kysely.ts +1 -0
  427. package/src/v2/db/adapters/mongo.ts +1 -0
  428. package/src/v2/db/adapters/prisma.ts +1 -0
  429. package/src/v2/db/adapters/typeorm.ts +1 -0
  430. package/src/v2/db/migrator/index.ts +80 -0
  431. package/src/v2/db/registry/audit-log.test.ts +77 -0
  432. package/src/v2/db/registry/audit-log.ts +46 -0
  433. package/src/v2/db/registry/consent-policy.test.ts +778 -0
  434. package/src/v2/db/registry/consent-policy.ts +74 -0
  435. package/src/v2/db/registry/consent-purpose.test.ts +485 -0
  436. package/src/v2/db/registry/consent-purpose.ts +41 -0
  437. package/src/v2/db/registry/consent.test.ts +843 -0
  438. package/src/v2/db/registry/consent.ts +42 -0
  439. package/src/v2/db/registry/domain.test.ts +463 -0
  440. package/src/v2/db/registry/domain.ts +51 -0
  441. package/src/v2/db/registry/index.ts +18 -0
  442. package/src/v2/db/registry/subject.test.ts +497 -0
  443. package/src/v2/db/registry/subject.ts +101 -0
  444. package/src/v2/db/registry/types.ts +10 -0
  445. package/src/v2/db/registry/utils/generate-id.test.ts +217 -0
  446. package/src/v2/db/registry/utils/generate-id.ts +134 -0
  447. package/src/v2/db/registry/utils.ts +134 -0
  448. package/src/v2/db/schema/1.0.0/audit-log.ts +32 -0
  449. package/src/v2/db/schema/1.0.0/consent-policy.ts +41 -0
  450. package/src/v2/db/schema/1.0.0/consent-purpose.ts +30 -0
  451. package/src/v2/db/schema/1.0.0/consent-record.ts +22 -0
  452. package/src/v2/db/schema/1.0.0/consent.ts +38 -0
  453. package/src/v2/db/schema/1.0.0/domain.ts +26 -0
  454. package/src/v2/db/schema/1.0.0/index.ts +56 -0
  455. package/src/v2/db/schema/1.0.0/subject.ts +26 -0
  456. package/src/v2/db/schema/index.ts +9 -0
  457. package/src/v2/define-config.ts +5 -0
  458. package/src/v2/handlers/consent/index.ts +9 -0
  459. package/src/v2/handlers/consent/post.handler.ts +254 -0
  460. package/src/v2/handlers/consent/show-banner/geo.test.ts +281 -0
  461. package/src/v2/handlers/consent/show-banner/geo.ts +96 -0
  462. package/src/v2/handlers/consent/show-banner/handler.test.ts +374 -0
  463. package/src/v2/handlers/consent/show-banner/handler.ts +123 -0
  464. package/src/v2/handlers/consent/show-banner/translations.test.ts +121 -0
  465. package/src/v2/handlers/consent/show-banner/translations.ts +79 -0
  466. package/src/v2/handlers/consent/verify.handler.ts +288 -0
  467. package/src/v2/handlers/meta/index.ts +5 -0
  468. package/src/v2/handlers/meta/status.handler.ts +43 -0
  469. package/src/v2/init.test.ts +114 -0
  470. package/src/v2/init.ts +126 -0
  471. package/src/v2/middleware/cors/cors.test.ts +111 -0
  472. package/src/v2/middleware/cors/cors.ts +192 -0
  473. package/src/v2/middleware/cors/index.ts +30 -0
  474. package/src/v2/middleware/cors/is-origin-trusted.test.ts +104 -0
  475. package/src/v2/middleware/cors/is-origin-trusted.ts +126 -0
  476. package/src/v2/middleware/cors/process-cors.ts +91 -0
  477. package/src/v2/middleware/openapi/config.ts +27 -0
  478. package/src/v2/middleware/openapi/handlers.ts +132 -0
  479. package/src/v2/middleware/openapi/index.ts +11 -0
  480. package/src/v2/middleware/process-ip/index.ts +39 -0
  481. package/src/v2/router.ts +8 -0
  482. package/src/v2/types/api.ts +32 -0
  483. package/src/v2/types/index.ts +121 -0
  484. package/src/v2/utils/create-telemetry-options.ts +115 -0
  485. package/src/v2/utils/env.ts +84 -0
  486. package/src/v2/utils/index.ts +2 -0
  487. package/src/v2/utils/logger.ts +38 -0
  488. package/src/version.ts +1 -1
  489. package/vitest.config.ts +11 -2
@@ -0,0 +1,226 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { createContractTests } from '~/v2/contracts/test.utils';
4
+ import { statusContract } from './status.contract';
5
+
6
+ // Create base tests for the contract using the utility
7
+ const tester = createContractTests('Status', statusContract);
8
+
9
+ // Add custom tests specific to the status contract
10
+ describe('Status Contract Custom Tests', () => {
11
+ // Helper to access schemas consistently throughout tests
12
+ const schemas = {
13
+ input: statusContract['~orpc'].inputSchema,
14
+ output: statusContract['~orpc'].outputSchema,
15
+ };
16
+
17
+ // Helper functions for common test patterns
18
+ const validateInput = (input: unknown) => {
19
+ //@ts-expect-error
20
+ return schemas.input?.safeParse(input);
21
+ };
22
+
23
+ const validateOutput = (output: unknown) => {
24
+ return schemas.output?.safeParse(output);
25
+ };
26
+
27
+ describe('Schema Structure', () => {
28
+ it('input schema is an undefined', () => {
29
+ const result = validateInput(undefined);
30
+ expect(result?.success).toBe(undefined);
31
+ });
32
+
33
+ it('rejects input with extra properties', () => {
34
+ const result = validateInput({ extraProp: 'value' });
35
+ expect(result?.success).toBe(undefined);
36
+ });
37
+ });
38
+
39
+ describe('Output Validation', () => {
40
+ describe('Required fields', () => {
41
+ it('validates complete output object', () => {
42
+ const validOutput = {
43
+ status: 'ok',
44
+ version: '1.0.0',
45
+ timestamp: new Date(),
46
+ client: {
47
+ ip: '127.0.0.1',
48
+ userAgent: 'Mozilla/5.0',
49
+ region: {
50
+ countryCode: 'US',
51
+ regionCode: 'CA',
52
+ },
53
+ },
54
+ };
55
+
56
+ const result = validateOutput(validOutput);
57
+ expect(result?.success).toBe(true);
58
+ });
59
+
60
+ it('rejects output without required fields', () => {
61
+ const invalidOutput = {
62
+ status: 'ok',
63
+ // Missing version, timestamp, and client
64
+ };
65
+
66
+ const result = validateOutput(invalidOutput);
67
+ expect(result?.success).toBe(false);
68
+ });
69
+ });
70
+
71
+ describe('Status field validation', () => {
72
+ it('accepts valid status values', () => {
73
+ for (const statusValue of ['ok', 'error']) {
74
+ const output = {
75
+ status: statusValue,
76
+ version: '1.0.0',
77
+ timestamp: new Date(),
78
+ client: {
79
+ ip: '127.0.0.1',
80
+ userAgent: 'Mozilla/5.0',
81
+ region: {
82
+ countryCode: 'US',
83
+ regionCode: 'CA',
84
+ },
85
+ },
86
+ };
87
+ const result = validateOutput(output);
88
+ expect(result?.success).toBe(true);
89
+ }
90
+ });
91
+
92
+ it('rejects invalid status values', () => {
93
+ const output = {
94
+ status: 'unknown', // Invalid status
95
+ version: '1.0.0',
96
+ timestamp: new Date(),
97
+ client: {
98
+ ip: '127.0.0.1',
99
+ userAgent: 'Mozilla/5.0',
100
+ region: {
101
+ countryCode: 'US',
102
+ regionCode: 'CA',
103
+ },
104
+ },
105
+ };
106
+ // Need to use type assertion to bypass TypeScript
107
+ const result = validateOutput(output);
108
+ expect(result?.success).toBe(false);
109
+ });
110
+ });
111
+
112
+ describe('Timestamp validation', () => {
113
+ it('accepts Date objects', () => {
114
+ const output = {
115
+ status: 'ok',
116
+ version: '1.0.0',
117
+ timestamp: new Date(),
118
+ client: {
119
+ ip: '127.0.0.1',
120
+ userAgent: 'Mozilla/5.0',
121
+ region: {
122
+ countryCode: 'US',
123
+ regionCode: 'CA',
124
+ },
125
+ },
126
+ };
127
+ const result = validateOutput(output);
128
+ expect(result?.success).toBe(true);
129
+ });
130
+
131
+ it('rejects string timestamps', () => {
132
+ const output = {
133
+ status: 'ok',
134
+ version: '1.0.0',
135
+ timestamp: new Date().toISOString(), // String instead of Date
136
+ };
137
+
138
+ // Need to use type assertion to bypass TypeScript
139
+ const result = validateOutput(output);
140
+ expect(result?.success).toBe(false);
141
+ });
142
+ });
143
+
144
+ describe('Client information validation', () => {
145
+ it('accepts null values for client fields', () => {
146
+ const output = {
147
+ status: 'ok',
148
+ version: '1.0.0',
149
+ timestamp: new Date(),
150
+ client: {
151
+ ip: null,
152
+ userAgent: null,
153
+ region: {
154
+ countryCode: null,
155
+ regionCode: null,
156
+ },
157
+ },
158
+ };
159
+
160
+ const result = validateOutput(output);
161
+ expect(result?.success).toBe(true);
162
+ });
163
+
164
+ it('validates client object structure', () => {
165
+ const output = {
166
+ status: 'ok',
167
+ version: '1.0.0',
168
+ timestamp: new Date(),
169
+ client: {
170
+ ip: '127.0.0.1',
171
+ userAgent: 'Mozilla/5.0',
172
+ region: {
173
+ countryCode: 'US',
174
+ regionCode: 'CA',
175
+ },
176
+ },
177
+ };
178
+
179
+ const result = validateOutput(output);
180
+ expect(result?.success).toBe(true);
181
+ });
182
+
183
+ it('rejects invalid client IP format', () => {
184
+ const output = {
185
+ status: 'ok',
186
+ version: '1.0.0',
187
+ timestamp: new Date(),
188
+ client: {
189
+ ip: 123, // Number instead of string
190
+ userAgent: 'Mozilla/5.0',
191
+ region: {
192
+ countryCode: 'US',
193
+ regionCode: 'CA',
194
+ },
195
+ },
196
+ };
197
+
198
+ const result = validateOutput(output);
199
+ expect(result?.success).toBe(false);
200
+ });
201
+
202
+ it('rejects invalid region structure', () => {
203
+ const output = {
204
+ status: 'ok',
205
+ version: '1.0.0',
206
+ timestamp: new Date(),
207
+ client: {
208
+ ip: '127.0.0.1',
209
+ userAgent: 'Mozilla/5.0',
210
+ region: {
211
+ countryCode: 123, // Number instead of string
212
+ regionCode: 'CA',
213
+ },
214
+ },
215
+ };
216
+
217
+ const result = validateOutput(output);
218
+ expect(result?.success).toBe(false);
219
+ });
220
+ });
221
+ });
222
+ });
223
+
224
+ // Add required fields testing using the utility
225
+ // No required fields for input since it's an empty object
226
+ tester.testRequiredFields('output', ['status', 'version', 'timestamp']);
@@ -0,0 +1,34 @@
1
+ import { oc } from '@orpc/contract';
2
+ import { z } from 'zod';
3
+
4
+ export const statusContract = oc
5
+ .route({
6
+ method: 'GET',
7
+ path: '/status',
8
+ description: `Returns the current operational status and health metrics of the service.
9
+ This endpoint provides real-time information about:
10
+ - Overall service status (ok/error)
11
+ - Current API version
12
+ - Server timestamp
13
+ - Storage system status and availability
14
+ - Client information (IP, User Agent, Region)
15
+
16
+ Use this endpoint for health checks, monitoring, and service status verification.`,
17
+ tags: ['meta'],
18
+ })
19
+ .output(
20
+ z.object({
21
+ status: z.enum(['ok', 'error']),
22
+ version: z.string(),
23
+ timestamp: z.date(),
24
+
25
+ client: z.object({
26
+ ip: z.string().nullable(),
27
+ userAgent: z.string().nullable(),
28
+ region: z.object({
29
+ countryCode: z.string().nullable(),
30
+ regionCode: z.string().nullable(),
31
+ }),
32
+ }),
33
+ })
34
+ );
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+
3
+ export const JurisdictionMessages = {
4
+ GDPR: 'GDPR or equivalent regulations require a cookie banner.',
5
+ CH: 'Switzerland requires similar data protection measures.',
6
+ BR: "Brazil's LGPD requires consent for cookies.",
7
+ PIPEDA: 'PIPEDA requires consent for data collection.',
8
+ AU: "Australia's Privacy Act mandates transparency about data collection.",
9
+ APPI: "Japan's APPI requires consent for data collection.",
10
+ PIPA: "South Korea's PIPA requires consent for data collection.",
11
+ NONE: 'No specific requirements',
12
+ } as const;
13
+
14
+ export type JurisdictionCode = keyof typeof JurisdictionMessages;
15
+
16
+ export const JurisdictionCodeSchema = z.enum([
17
+ 'GDPR',
18
+ 'CH',
19
+ 'BR',
20
+ 'PIPEDA',
21
+ 'AU',
22
+ 'APPI',
23
+ 'PIPA',
24
+ 'NONE',
25
+ ]);
26
+
27
+ export const JurisdictionInfoSchema = z.object({
28
+ code: JurisdictionCodeSchema,
29
+ message: z.string(),
30
+ });
@@ -0,0 +1,400 @@
1
+ import type { Schema as ORPCSchema } from '@orpc/contract';
2
+ import { describe, expect, it } from 'vitest';
3
+ import type { ZodIssue, z } from 'zod';
4
+
5
+ /**
6
+ * Contract test utilities for creating reusable test patterns
7
+ * across multiple contracts
8
+ */
9
+
10
+ type SafeParseResult = ReturnType<z.ZodTypeAny['safeParse']>;
11
+
12
+ type ContractTestHelpers = {
13
+ validateInput?: (input: unknown) => SafeParseResult | undefined;
14
+ validateOutput: (output: unknown) => SafeParseResult | undefined;
15
+ testInput: (testName: string, input: unknown, shouldBeValid: boolean) => void;
16
+ testOutput: (
17
+ testName: string,
18
+ output: unknown,
19
+ shouldBeValid: boolean
20
+ ) => void;
21
+ testDiscriminatedUnion: (
22
+ discriminator: string,
23
+ validValues: string[]
24
+ ) => void;
25
+ testRequiredFields: (schema: 'input' | 'output', fields: string[]) => void;
26
+ };
27
+
28
+ type ContractSchema = z.ZodType | ORPCSchema<unknown, unknown>;
29
+
30
+ /**
31
+ * Creates a test suite for basic contract validation
32
+ * @param contractName Display name for the contract
33
+ * @param contract The contract to test
34
+ */
35
+ export function createContractTests(
36
+ contractName: string,
37
+ contract: {
38
+ '~orpc'?: { inputSchema?: ContractSchema; outputSchema?: ContractSchema };
39
+ }
40
+ ): ContractTestHelpers {
41
+ const schemas = {
42
+ input: contract['~orpc']?.inputSchema,
43
+ output: contract['~orpc']?.outputSchema,
44
+ };
45
+
46
+ // Helper functions
47
+ const validateInput = (input: unknown): SafeParseResult | undefined => {
48
+ const schema = schemas.input;
49
+ if (!schema) {
50
+ return undefined;
51
+ }
52
+
53
+ // Handle both Zod and oRPC schemas
54
+ if ('safeParse' in schema) {
55
+ return schema.safeParse(input);
56
+ }
57
+ // For oRPC schemas, we'll need to implement validation
58
+ // This is a placeholder - you may need to implement actual validation
59
+ return { success: true, data: input } as SafeParseResult;
60
+ };
61
+
62
+ const validateOutput = (output: unknown): SafeParseResult | undefined => {
63
+ const schema = schemas.output;
64
+ if (!schema) {
65
+ return undefined;
66
+ }
67
+
68
+ // Handle both Zod and oRPC schemas
69
+ if ('safeParse' in schema) {
70
+ return schema.safeParse(output);
71
+ }
72
+ // For oRPC schemas, we'll need to implement validation
73
+ // This is a placeholder - you may need to implement actual validation
74
+ return { success: true, data: output } as SafeParseResult;
75
+ };
76
+
77
+ // Create base test suite
78
+ describe(`${contractName} Contract`, () => {
79
+ describe('Schema Structure', () => {
80
+ it('has properly defined schemas', () => {
81
+ // Only require output schema
82
+ expect(schemas.output).toBeDefined();
83
+
84
+ // Input schema is optional
85
+ if (schemas.input) {
86
+ expect(schemas.input).toBeDefined();
87
+ }
88
+ });
89
+
90
+ it('schemas are serializable', () => {
91
+ // Test serialization for output schema
92
+ if (schemas.output) {
93
+ const serialized = JSON.stringify(schemas.output);
94
+ expect(serialized).toBeDefined();
95
+ expect(typeof serialized).toBe('string');
96
+ expect(() => JSON.parse(serialized)).not.toThrow();
97
+ }
98
+
99
+ // Test serialization for input schema if it exists
100
+ if (schemas.input) {
101
+ const serialized = JSON.stringify(schemas.input);
102
+ expect(serialized).toBeDefined();
103
+ expect(typeof serialized).toBe('string');
104
+ expect(() => JSON.parse(serialized)).not.toThrow();
105
+ }
106
+ });
107
+ });
108
+ });
109
+
110
+ // Define test helpers
111
+ const testInput = (
112
+ testName: string,
113
+ input: unknown,
114
+ shouldBeValid: boolean
115
+ ) => {
116
+ it(`${testName}`, () => {
117
+ const result = validateInput(input);
118
+ if (!result) {
119
+ throw new Error('Validation result is undefined');
120
+ }
121
+ expect(result.success).toBe(shouldBeValid);
122
+ });
123
+ };
124
+
125
+ const testOutput = (
126
+ testName: string,
127
+ output: unknown,
128
+ shouldBeValid: boolean
129
+ ) => {
130
+ it(`${testName}`, () => {
131
+ const result = validateOutput(output);
132
+ if (!result) {
133
+ throw new Error('Validation result is undefined');
134
+ }
135
+ expect(result.success).toBe(shouldBeValid);
136
+ });
137
+ };
138
+
139
+ const testDiscriminatedUnion = (
140
+ discriminator: string,
141
+ validValues: string[]
142
+ ) => {
143
+ describe('Discriminated Union validation', () => {
144
+ it(`requires '${discriminator}' discriminator`, () => {
145
+ if (!schemas.input) return;
146
+ const result = validateInput({});
147
+ expect(result?.success).toBe(false);
148
+ });
149
+
150
+ it('validates all defined discriminator values', () => {
151
+ if (!schemas.input) {
152
+ return;
153
+ }
154
+ for (const value of validValues) {
155
+ const input = {
156
+ [discriminator]: value,
157
+ // Add minimum required fields based on your contract
158
+ };
159
+
160
+ // This test assumes minimal input - you may need to add required fields
161
+ // based on the specific contract being tested
162
+ const result = validateInput(input);
163
+ // Specifically assert that it fails due to missing required fields
164
+ expect(result?.success).toBe(false);
165
+ // We no longer assert on internal issue codes; presence of failure is enough
166
+ }
167
+ });
168
+ });
169
+ };
170
+
171
+ const testRequiredFields = (schema: 'input' | 'output', fields: string[]) => {
172
+ describe(`Required ${schema} fields`, () => {
173
+ // Skip if testing input fields but no input schema exists
174
+ if (schema === 'input' && !schemas.input) {
175
+ it('skips input field tests as no input schema exists', () => {
176
+ expect(true).toBe(true);
177
+ });
178
+ return;
179
+ }
180
+
181
+ // Create a sample of valid data to test against
182
+ let sampleValid: Record<string, unknown>;
183
+
184
+ if (schema === 'input') {
185
+ // For input schema, we need a valid input based on the contract type
186
+ sampleValid = {
187
+ type: 'marketing_communications', // A common type that most contracts would have
188
+ domain: 'example.com',
189
+ // Add other fields that might be required by your contracts
190
+ subjectId: 'test-123',
191
+ metadata: {},
192
+ };
193
+ } else {
194
+ // For output schema, create a generic valid output
195
+ sampleValid = {
196
+ id: 'test-123',
197
+ domainId: 'domain-123',
198
+ domain: 'example.com',
199
+ type: 'marketing_communications',
200
+ status: 'granted',
201
+ recordId: 'record-123',
202
+ givenAt: new Date().toISOString(),
203
+ metadata: {},
204
+ };
205
+ }
206
+
207
+ for (const field of fields) {
208
+ it(`requires '${field}' field`, () => {
209
+ // Create a copy of the valid data without the tested field
210
+ const invalidData = { ...sampleValid };
211
+ delete invalidData[field];
212
+
213
+ const validator = schema === 'input' ? validateInput : validateOutput;
214
+ const result = validator(invalidData);
215
+
216
+ if (!result) {
217
+ throw new Error('Validation result is undefined');
218
+ }
219
+
220
+ expect(result.success).toBe(false);
221
+ if (!result.success) {
222
+ expect(
223
+ result.error.issues.some(
224
+ (issue: ZodIssue) =>
225
+ issue.path.some((p) => String(p).includes(field)) ||
226
+ issue.message.includes('required')
227
+ )
228
+ ).toBe(true);
229
+ }
230
+ });
231
+ }
232
+ });
233
+ };
234
+
235
+ // Return the test helpers for re-use
236
+ return {
237
+ validateInput,
238
+ validateOutput,
239
+ testInput,
240
+ testOutput,
241
+ testDiscriminatedUnion,
242
+ testRequiredFields,
243
+ };
244
+ }
245
+
246
+ /**
247
+ * Creates consistency tests for multiple related contracts
248
+ */
249
+ export function createConsistencyTests(
250
+ contracts: Record<
251
+ string,
252
+ {
253
+ '~orpc'?: {
254
+ inputSchema?: ContractSchema;
255
+ outputSchema?: ContractSchema;
256
+ };
257
+ }
258
+ >
259
+ ) {
260
+ describe('Contract Consistency', () => {
261
+ it('all contracts have output schemas', () => {
262
+ for (const [_name, contract] of Object.entries(contracts)) {
263
+ expect(contract['~orpc']?.outputSchema).toBeDefined();
264
+ }
265
+ });
266
+
267
+ // Field type consistency - ensure common fields use same types across contracts
268
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: excessive cognitive complexity is acceptable here
269
+ it('common fields have consistent types across contracts', () => {
270
+ const commonFields = ['id', 'domainId', 'type', 'status'];
271
+ const contractEntries = Object.entries(contracts);
272
+
273
+ for (const field of commonFields) {
274
+ const fieldTypes = new Set();
275
+
276
+ for (const [_name, contract] of contractEntries) {
277
+ const schema = contract['~orpc']?.outputSchema;
278
+ if (!schema || !('shape' in schema)) {
279
+ continue;
280
+ }
281
+
282
+ const shape = schema.shape as Record<string, z.ZodTypeAny>;
283
+ if (field in shape) {
284
+ const fieldDef = shape[field];
285
+ if (fieldDef) {
286
+ fieldTypes.add(fieldDef.constructor.name);
287
+ }
288
+ }
289
+ }
290
+
291
+ // If the field exists in multiple contracts, they should all use the same type
292
+ if (fieldTypes.size > 0) {
293
+ expect(
294
+ fieldTypes.size,
295
+ `Field '${field}' has inconsistent types across contracts`
296
+ ).toBe(1);
297
+ }
298
+ }
299
+ });
300
+
301
+ // Validate enum value consistency across contracts
302
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: excessive cognitive complexity is acceptable here
303
+ it('enum values are consistent across contracts', () => {
304
+ // Example: status field should have the same allowed values in all contracts
305
+ const statusValues = new Map<string, string[]>();
306
+
307
+ for (const [name, contract] of Object.entries(contracts)) {
308
+ const schema = contract['~orpc']?.outputSchema;
309
+ if (!schema || !('shape' in schema)) {
310
+ continue;
311
+ }
312
+
313
+ const shape = schema.shape as Record<string, z.ZodTypeAny>;
314
+ if (!shape.status) {
315
+ continue;
316
+ }
317
+
318
+ const statusField = shape.status;
319
+ if ('_def' in statusField && 'values' in statusField._def) {
320
+ statusValues.set(name, statusField._def.values as string[]);
321
+ }
322
+ }
323
+
324
+ // All status enums should have the same values
325
+ const allValues = Array.from(statusValues.values());
326
+ if (allValues.length > 1) {
327
+ for (let i = 1; i < allValues.length; i++) {
328
+ expect(allValues[i]).toEqual(allValues[0]);
329
+ }
330
+ }
331
+ });
332
+
333
+ // Validation rule consistency for common fields
334
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: excessive cognitive complexity is acceptable here
335
+ it('validation rules for common fields are consistent', () => {
336
+ const contractEntries = Object.entries(contracts);
337
+ const commonStringFields = ['domain', 'subjectId', 'externalSubjectId'];
338
+
339
+ for (const field of commonStringFields) {
340
+ const minLengths = new Set();
341
+ const maxLengths = new Set();
342
+
343
+ for (const [_name, contract] of contractEntries) {
344
+ const schema = contract['~orpc']?.inputSchema;
345
+ if (!schema || !('shape' in schema)) {
346
+ continue;
347
+ }
348
+
349
+ const shape = schema.shape as Record<string, z.ZodTypeAny>;
350
+ if (!shape[field]) {
351
+ continue;
352
+ }
353
+
354
+ const _fieldSchema = shape[field];
355
+ // Skip introspecting Zod internals in v4; cannot reliably extract checks
356
+ }
357
+
358
+ // All contracts should use the same min/max for common string fields
359
+ expect(
360
+ minLengths.size,
361
+ `Inconsistent min length for field '${field}'`
362
+ ).toBeLessThanOrEqual(1);
363
+ expect(
364
+ maxLengths.size,
365
+ `Inconsistent max length for field '${field}'`
366
+ ).toBeLessThanOrEqual(1);
367
+ }
368
+ });
369
+
370
+ // Discriminated union consistency
371
+ it('discriminated unions use consistent discriminator across contracts', () => {
372
+ const discriminators = new Set();
373
+
374
+ for (const [_name, contract] of Object.entries(contracts)) {
375
+ const schema = contract['~orpc']?.inputSchema;
376
+ if (!schema || !('_def' in schema)) {
377
+ continue;
378
+ }
379
+
380
+ // Check if schema is a discriminated union
381
+ if (
382
+ 'typeName' in schema._def &&
383
+ schema._def.typeName === 'ZodDiscriminatedUnion' &&
384
+ 'discriminator' in schema._def
385
+ ) {
386
+ // Safe assertion since we've checked the property exists
387
+ discriminators.add(
388
+ (schema._def as { discriminator: string }).discriminator
389
+ );
390
+ }
391
+ }
392
+
393
+ // All contracts should use the same discriminator (e.g., 'type')
394
+ expect(
395
+ discriminators.size,
396
+ 'Inconsistent discriminator fields used across contracts'
397
+ ).toBeLessThanOrEqual(1);
398
+ });
399
+ });
400
+ }