@porulle/core 0.64.0 → 0.65.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 (463) hide show
  1. package/dist/adapters/email-render.d.ts +18 -0
  2. package/dist/adapters/email-render.d.ts.map +1 -0
  3. package/dist/adapters/email-render.js +37 -0
  4. package/dist/auth/actor.d.ts.map +1 -1
  5. package/dist/auth/actor.js +11 -0
  6. package/dist/auth/auth-failure.d.ts +0 -2
  7. package/dist/auth/auth-failure.d.ts.map +1 -1
  8. package/dist/auth/auth-failure.js +0 -4
  9. package/dist/auth/middleware.d.ts +0 -1
  10. package/dist/auth/middleware.d.ts.map +1 -1
  11. package/dist/auth/middleware.js +7 -6
  12. package/dist/auth/permissions.d.ts +2 -0
  13. package/dist/auth/permissions.d.ts.map +1 -1
  14. package/dist/auth/permissions.js +8 -6
  15. package/dist/auth/role-authority.d.ts +0 -1
  16. package/dist/auth/role-authority.d.ts.map +1 -1
  17. package/dist/auth/role-authority.js +1 -8
  18. package/dist/auth/setup.d.ts.map +1 -1
  19. package/dist/auth/setup.js +5 -0
  20. package/dist/auth/strict-org-resolution.d.ts +8 -1
  21. package/dist/auth/strict-org-resolution.d.ts.map +1 -1
  22. package/dist/auth/strict-org-resolution.js +9 -19
  23. package/dist/auth/system-actor.d.ts +3 -2
  24. package/dist/auth/system-actor.d.ts.map +1 -1
  25. package/dist/auth/system-actor.js +3 -3
  26. package/dist/config/defaults.d.ts.map +1 -1
  27. package/dist/config/defaults.js +3 -20
  28. package/dist/config/define-config.d.ts +2 -2
  29. package/dist/config/define-config.d.ts.map +1 -1
  30. package/dist/config/define-config.js +3 -2
  31. package/dist/config/types.d.ts +2 -3
  32. package/dist/config/types.d.ts.map +1 -1
  33. package/dist/hooks/checkout.d.ts +2 -15
  34. package/dist/hooks/checkout.d.ts.map +1 -1
  35. package/dist/hooks/checkout.js +2 -51
  36. package/dist/index.d.ts +11 -19
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +11 -12
  39. package/dist/interfaces/rest/router.js +3 -3
  40. package/dist/interfaces/rest/routes/admin/compensation-failures.d.ts.map +1 -1
  41. package/dist/interfaces/rest/routes/admin/compensation-failures.js +5 -5
  42. package/dist/interfaces/rest/routes/admin/entity-field-definitions.js +5 -5
  43. package/dist/interfaces/rest/routes/admin/staff.d.ts.map +1 -1
  44. package/dist/interfaces/rest/routes/admin/staff.js +2 -3
  45. package/dist/interfaces/rest/routes/analytics.d.ts.map +1 -1
  46. package/dist/interfaces/rest/routes/analytics.js +2 -2
  47. package/dist/interfaces/rest/routes/carts.d.ts.map +1 -1
  48. package/dist/interfaces/rest/routes/carts.js +12 -12
  49. package/dist/interfaces/rest/routes/catalog.js +37 -37
  50. package/dist/interfaces/rest/routes/checkout.d.ts.map +1 -1
  51. package/dist/interfaces/rest/routes/checkout.js +9 -10
  52. package/dist/interfaces/rest/routes/customers.d.ts.map +1 -1
  53. package/dist/interfaces/rest/routes/customers.js +12 -12
  54. package/dist/interfaces/rest/routes/documents.d.ts.map +1 -1
  55. package/dist/interfaces/rest/routes/documents.js +9 -9
  56. package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -1
  57. package/dist/interfaces/rest/routes/inventory.js +8 -8
  58. package/dist/interfaces/rest/routes/media.d.ts.map +1 -1
  59. package/dist/interfaces/rest/routes/media.js +5 -5
  60. package/dist/interfaces/rest/routes/orders.d.ts.map +1 -1
  61. package/dist/interfaces/rest/routes/orders.js +32 -32
  62. package/dist/interfaces/rest/routes/payments.d.ts.map +1 -1
  63. package/dist/interfaces/rest/routes/payments.js +2 -2
  64. package/dist/interfaces/rest/routes/pricing.d.ts.map +1 -1
  65. package/dist/interfaces/rest/routes/pricing.js +8 -8
  66. package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -1
  67. package/dist/interfaces/rest/routes/promotions.js +7 -7
  68. package/dist/interfaces/rest/routes/search.d.ts.map +1 -1
  69. package/dist/interfaces/rest/routes/search.js +3 -3
  70. package/dist/interfaces/rest/routes/settings.d.ts.map +1 -1
  71. package/dist/interfaces/rest/routes/settings.js +4 -4
  72. package/dist/interfaces/rest/routes/shipping.d.ts.map +1 -1
  73. package/dist/interfaces/rest/routes/shipping.js +9 -9
  74. package/dist/interfaces/rest/routes/tax.d.ts.map +1 -1
  75. package/dist/interfaces/rest/routes/tax.js +9 -9
  76. package/dist/interfaces/rest/routes/webhooks.d.ts.map +1 -1
  77. package/dist/interfaces/rest/routes/webhooks.js +4 -4
  78. package/dist/interfaces/rest/utils.d.ts +1 -1
  79. package/dist/interfaces/rest/utils.d.ts.map +1 -1
  80. package/dist/interfaces/rest/utils.js +4 -13
  81. package/dist/jobs.d.ts +1 -0
  82. package/dist/jobs.d.ts.map +1 -1
  83. package/dist/jobs.js +1 -0
  84. package/dist/kernel/database/adapter.d.ts +9 -0
  85. package/dist/kernel/database/adapter.d.ts.map +1 -1
  86. package/dist/kernel/database/adapter.js +1 -1
  87. package/dist/kernel/database/migrate.d.ts +0 -4
  88. package/dist/kernel/database/migrate.d.ts.map +1 -1
  89. package/dist/kernel/database/migrate.js +2 -14
  90. package/dist/kernel/database/pglite-transaction.d.ts +28 -0
  91. package/dist/kernel/database/pglite-transaction.d.ts.map +1 -0
  92. package/dist/kernel/database/pglite-transaction.js +52 -0
  93. package/dist/kernel/database/tx-context.d.ts +0 -1
  94. package/dist/kernel/database/tx-context.d.ts.map +1 -1
  95. package/dist/kernel/database/tx-context.js +2 -14
  96. package/dist/kernel/database/unique-violation.d.ts +3 -0
  97. package/dist/kernel/database/unique-violation.d.ts.map +1 -0
  98. package/dist/kernel/database/unique-violation.js +9 -0
  99. package/dist/kernel/error-mapper.d.ts.map +1 -1
  100. package/dist/kernel/error-mapper.js +1 -0
  101. package/dist/kernel/errors.d.ts +12 -0
  102. package/dist/kernel/errors.d.ts.map +1 -1
  103. package/dist/kernel/errors.js +16 -0
  104. package/dist/kernel/hooks/create-context.d.ts +18 -9
  105. package/dist/kernel/hooks/create-context.d.ts.map +1 -1
  106. package/dist/kernel/hooks/create-context.js +24 -3
  107. package/dist/kernel/hooks/registry.d.ts +0 -19
  108. package/dist/kernel/hooks/registry.d.ts.map +1 -1
  109. package/dist/kernel/hooks/registry.js +0 -32
  110. package/dist/kernel/jobs/drizzle-adapter.d.ts.map +1 -1
  111. package/dist/kernel/jobs/drizzle-adapter.js +3 -10
  112. package/dist/kernel/jobs/prepare-enqueue.d.ts +20 -0
  113. package/dist/kernel/jobs/prepare-enqueue.d.ts.map +1 -0
  114. package/dist/kernel/jobs/prepare-enqueue.js +24 -0
  115. package/dist/kernel/jobs/types.d.ts +0 -4
  116. package/dist/kernel/jobs/types.d.ts.map +1 -1
  117. package/dist/kernel/jobs/types.js +0 -4
  118. package/dist/kernel/local-api.d.ts +0 -33
  119. package/dist/kernel/local-api.d.ts.map +1 -1
  120. package/dist/kernel/local-api.js +0 -36
  121. package/dist/kernel/plugin/manifest.d.ts +3 -5
  122. package/dist/kernel/plugin/manifest.d.ts.map +1 -1
  123. package/dist/modules/analytics/service.d.ts +0 -6
  124. package/dist/modules/analytics/service.d.ts.map +1 -1
  125. package/dist/modules/analytics/service.js +0 -32
  126. package/dist/modules/cart/service.d.ts.map +1 -1
  127. package/dist/modules/cart/service.js +5 -17
  128. package/dist/modules/catalog/entity-service.d.ts.map +1 -1
  129. package/dist/modules/catalog/entity-service.js +9 -17
  130. package/dist/modules/catalog/import-service.d.ts.map +1 -1
  131. package/dist/modules/catalog/import-service.js +4 -13
  132. package/dist/modules/catalog/service.d.ts +1 -81
  133. package/dist/modules/catalog/service.d.ts.map +1 -1
  134. package/dist/modules/catalog/service.js +1 -8
  135. package/dist/modules/customers/service.d.ts.map +1 -1
  136. package/dist/modules/customers/service.js +5 -17
  137. package/dist/modules/documents/render.d.ts +0 -3
  138. package/dist/modules/documents/render.d.ts.map +1 -1
  139. package/dist/modules/documents/render.js +2 -17
  140. package/dist/modules/fulfillment/service.d.ts.map +1 -1
  141. package/dist/modules/fulfillment/service.js +8 -26
  142. package/dist/modules/inventory/service.d.ts.map +1 -1
  143. package/dist/modules/inventory/service.js +3 -20
  144. package/dist/modules/media/service.d.ts.map +1 -1
  145. package/dist/modules/media/service.js +2 -10
  146. package/dist/modules/orders/quote.d.ts.map +1 -1
  147. package/dist/modules/orders/quote.js +1 -2
  148. package/dist/modules/orders/service.d.ts.map +1 -1
  149. package/dist/modules/orders/service.js +4 -17
  150. package/dist/modules/pricing/service.d.ts.map +1 -1
  151. package/dist/modules/pricing/service.js +7 -18
  152. package/dist/modules/promotions/service.d.ts.map +1 -1
  153. package/dist/modules/promotions/service.js +4 -16
  154. package/dist/modules/tax/service.d.ts +1 -3
  155. package/dist/modules/tax/service.d.ts.map +1 -1
  156. package/dist/modules/tax/service.js +16 -52
  157. package/dist/modules/webhooks/hook.d.ts.map +1 -1
  158. package/dist/modules/webhooks/hook.js +3 -2
  159. package/dist/modules/webhooks/service.d.ts.map +1 -1
  160. package/dist/modules/webhooks/service.js +1 -50
  161. package/dist/runtime/commerce.d.ts.map +1 -1
  162. package/dist/runtime/commerce.js +4 -11
  163. package/dist/runtime/kernel-modules.d.ts +38 -1799
  164. package/dist/runtime/kernel-modules.d.ts.map +1 -1
  165. package/dist/runtime/kernel-modules.js +160 -66
  166. package/dist/runtime/kernel-types.d.ts +3 -15
  167. package/dist/runtime/kernel-types.d.ts.map +1 -1
  168. package/dist/runtime/kernel-types.js +0 -10
  169. package/dist/runtime/kernel.d.ts +2 -3
  170. package/dist/runtime/kernel.d.ts.map +1 -1
  171. package/dist/runtime/kernel.js +10 -51
  172. package/dist/runtime/server.d.ts +1 -1
  173. package/dist/runtime/server.d.ts.map +1 -1
  174. package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -1
  175. package/dist/test-utils/create-pglite-adapter.js +5 -62
  176. package/dist/test-utils/create-plugin-test-app.d.ts.map +1 -1
  177. package/dist/test-utils/create-plugin-test-app.js +13 -32
  178. package/dist/test-utils/rest-api-test-utils.d.ts +0 -12
  179. package/dist/test-utils/rest-api-test-utils.d.ts.map +1 -1
  180. package/dist/test-utils/rest-api-test-utils.js +3 -70
  181. package/dist/test-utils/test-actors.d.ts +9 -0
  182. package/dist/test-utils/test-actors.d.ts.map +1 -1
  183. package/dist/test-utils/test-actors.js +62 -0
  184. package/dist/testing.d.ts +1 -4
  185. package/dist/testing.d.ts.map +1 -1
  186. package/dist/testing.js +1 -4
  187. package/dist/utils/escape-html.d.ts +3 -0
  188. package/dist/utils/escape-html.d.ts.map +1 -0
  189. package/dist/utils/escape-html.js +9 -0
  190. package/dist/utils/id.d.ts +0 -1
  191. package/dist/utils/id.d.ts.map +1 -1
  192. package/dist/utils/id.js +0 -3
  193. package/dist/utils/logger.d.ts +1 -1
  194. package/dist/utils/logger.d.ts.map +1 -1
  195. package/dist/utils/logger.js +1 -1
  196. package/dist/utils/money.d.ts +13 -0
  197. package/dist/utils/money.d.ts.map +1 -0
  198. package/dist/utils/money.js +58 -0
  199. package/package.json +5 -6
  200. package/src/adapters/email-render.ts +63 -0
  201. package/src/auth/actor.ts +14 -0
  202. package/src/auth/auth-failure.ts +0 -5
  203. package/src/auth/middleware.ts +7 -6
  204. package/src/auth/permissions.ts +12 -6
  205. package/src/auth/role-authority.ts +1 -10
  206. package/src/auth/setup.ts +8 -0
  207. package/src/auth/strict-org-resolution.ts +9 -16
  208. package/src/auth/system-actor.ts +3 -3
  209. package/src/config/defaults.ts +3 -20
  210. package/src/config/define-config.ts +5 -4
  211. package/src/config/types.ts +2 -2
  212. package/src/hooks/checkout.ts +2 -86
  213. package/src/index.ts +9 -36
  214. package/src/interfaces/rest/router.ts +3 -3
  215. package/src/interfaces/rest/routes/admin/compensation-failures.ts +5 -5
  216. package/src/interfaces/rest/routes/admin/entity-field-definitions.ts +5 -5
  217. package/src/interfaces/rest/routes/admin/staff.ts +2 -3
  218. package/src/interfaces/rest/routes/analytics.ts +2 -2
  219. package/src/interfaces/rest/routes/carts.ts +12 -12
  220. package/src/interfaces/rest/routes/catalog.ts +37 -37
  221. package/src/interfaces/rest/routes/checkout.ts +8 -10
  222. package/src/interfaces/rest/routes/customers.ts +12 -12
  223. package/src/interfaces/rest/routes/documents.ts +9 -9
  224. package/src/interfaces/rest/routes/inventory.ts +8 -8
  225. package/src/interfaces/rest/routes/media.ts +5 -5
  226. package/src/interfaces/rest/routes/orders.ts +32 -32
  227. package/src/interfaces/rest/routes/payments.ts +2 -2
  228. package/src/interfaces/rest/routes/pricing.ts +8 -8
  229. package/src/interfaces/rest/routes/promotions.ts +7 -7
  230. package/src/interfaces/rest/routes/search.ts +3 -3
  231. package/src/interfaces/rest/routes/settings.ts +4 -4
  232. package/src/interfaces/rest/routes/shipping.ts +9 -9
  233. package/src/interfaces/rest/routes/tax.ts +9 -9
  234. package/src/interfaces/rest/routes/webhooks.ts +4 -4
  235. package/src/interfaces/rest/utils.ts +4 -14
  236. package/src/jobs.ts +2 -1
  237. package/src/kernel/database/adapter.ts +1 -1
  238. package/src/kernel/database/migrate.ts +2 -17
  239. package/src/kernel/database/pglite-transaction.ts +61 -0
  240. package/src/kernel/database/tx-context.ts +2 -20
  241. package/src/kernel/database/unique-violation.ts +7 -0
  242. package/src/kernel/error-mapper.ts +1 -0
  243. package/src/kernel/errors.ts +18 -0
  244. package/src/kernel/hooks/create-context.ts +38 -8
  245. package/src/kernel/hooks/registry.ts +0 -37
  246. package/src/kernel/jobs/drizzle-adapter.ts +4 -15
  247. package/src/kernel/jobs/prepare-enqueue.ts +42 -0
  248. package/src/kernel/jobs/types.ts +0 -5
  249. package/src/kernel/local-api.ts +0 -44
  250. package/src/kernel/plugin/manifest.ts +3 -5
  251. package/src/modules/analytics/service.ts +0 -36
  252. package/src/modules/cart/service.ts +6 -29
  253. package/src/modules/catalog/entity-service.ts +9 -19
  254. package/src/modules/catalog/import-service.ts +4 -11
  255. package/src/modules/catalog/service.ts +2 -286
  256. package/src/modules/customers/service.ts +6 -27
  257. package/src/modules/documents/render.ts +2 -19
  258. package/src/modules/fulfillment/service.ts +8 -27
  259. package/src/modules/inventory/service.ts +3 -21
  260. package/src/modules/media/service.ts +2 -8
  261. package/src/modules/orders/quote.ts +1 -2
  262. package/src/modules/orders/service.ts +5 -30
  263. package/src/modules/pricing/service.ts +12 -30
  264. package/src/modules/promotions/service.ts +5 -28
  265. package/src/modules/tax/service.ts +20 -48
  266. package/src/modules/webhooks/hook.ts +3 -2
  267. package/src/modules/webhooks/service.ts +1 -42
  268. package/src/runtime/commerce.ts +4 -11
  269. package/src/runtime/kernel-modules.ts +191 -67
  270. package/src/runtime/kernel-types.ts +3 -26
  271. package/src/runtime/kernel.ts +11 -66
  272. package/src/runtime/server.ts +1 -3
  273. package/src/test-utils/create-pglite-adapter.ts +5 -67
  274. package/src/test-utils/create-plugin-test-app.ts +13 -52
  275. package/src/test-utils/rest-api-test-utils.ts +3 -70
  276. package/src/test-utils/test-actors.ts +66 -0
  277. package/src/testing.ts +1 -3
  278. package/src/utils/escape-html.ts +9 -0
  279. package/src/utils/id.ts +0 -4
  280. package/src/utils/logger.ts +1 -1
  281. package/src/utils/money.ts +62 -0
  282. package/dist/auth/access.d.ts +0 -101
  283. package/dist/auth/access.d.ts.map +0 -1
  284. package/dist/auth/access.js +0 -128
  285. package/dist/generated/plugin-manifest.d.ts +0 -51
  286. package/dist/generated/plugin-manifest.d.ts.map +0 -1
  287. package/dist/generated/plugin-manifest.js +0 -21
  288. package/dist/kernel/factory/repository-factory.d.ts +0 -71
  289. package/dist/kernel/factory/repository-factory.d.ts.map +0 -1
  290. package/dist/kernel/factory/repository-factory.js +0 -138
  291. package/dist/kernel/http-error.d.ts +0 -30
  292. package/dist/kernel/http-error.d.ts.map +0 -1
  293. package/dist/kernel/http-error.js +0 -35
  294. package/dist/kernel/jobs/builtin-job-tasks.d.ts +0 -3
  295. package/dist/kernel/jobs/builtin-job-tasks.d.ts.map +0 -1
  296. package/dist/kernel/jobs/builtin-job-tasks.js +0 -6
  297. package/dist/kernel/module/define.d.ts +0 -21
  298. package/dist/kernel/module/define.d.ts.map +0 -1
  299. package/dist/kernel/module/define.js +0 -3
  300. package/dist/kernel/module/index.d.ts +0 -4
  301. package/dist/kernel/module/index.d.ts.map +0 -1
  302. package/dist/kernel/module/index.js +0 -2
  303. package/dist/kernel/module/topo-sort.d.ts +0 -7
  304. package/dist/kernel/module/topo-sort.d.ts.map +0 -1
  305. package/dist/kernel/module/topo-sort.js +0 -89
  306. package/dist/kernel/query/executor.d.ts +0 -21
  307. package/dist/kernel/query/executor.d.ts.map +0 -1
  308. package/dist/kernel/query/executor.js +0 -128
  309. package/dist/kernel/query/registry.d.ts +0 -33
  310. package/dist/kernel/query/registry.d.ts.map +0 -1
  311. package/dist/kernel/query/registry.js +0 -20
  312. package/dist/kernel/service-registry.d.ts +0 -109
  313. package/dist/kernel/service-registry.d.ts.map +0 -1
  314. package/dist/kernel/service-registry.js +0 -26
  315. package/dist/modules/analytics/hooks.d.ts +0 -13
  316. package/dist/modules/analytics/hooks.d.ts.map +0 -1
  317. package/dist/modules/analytics/hooks.js +0 -12
  318. package/dist/modules/analytics/module.d.ts +0 -3
  319. package/dist/modules/analytics/module.d.ts.map +0 -1
  320. package/dist/modules/analytics/module.js +0 -24
  321. package/dist/modules/analytics/repository/index.d.ts +0 -5
  322. package/dist/modules/analytics/repository/index.d.ts.map +0 -1
  323. package/dist/modules/analytics/repository/index.js +0 -1
  324. package/dist/modules/audit/index.d.ts +0 -2
  325. package/dist/modules/audit/index.d.ts.map +0 -1
  326. package/dist/modules/audit/index.js +0 -1
  327. package/dist/modules/audit/module.d.ts +0 -180
  328. package/dist/modules/audit/module.d.ts.map +0 -1
  329. package/dist/modules/audit/module.js +0 -8
  330. package/dist/modules/cart/access.d.ts +0 -11
  331. package/dist/modules/cart/access.d.ts.map +0 -1
  332. package/dist/modules/cart/access.js +0 -18
  333. package/dist/modules/cart/module.d.ts +0 -14
  334. package/dist/modules/cart/module.d.ts.map +0 -1
  335. package/dist/modules/cart/module.js +0 -17
  336. package/dist/modules/catalog/module.d.ts +0 -26
  337. package/dist/modules/catalog/module.d.ts.map +0 -1
  338. package/dist/modules/catalog/module.js +0 -33
  339. package/dist/modules/customers/index.d.ts +0 -2
  340. package/dist/modules/customers/index.d.ts.map +0 -1
  341. package/dist/modules/customers/index.js +0 -1
  342. package/dist/modules/customers/module.d.ts +0 -563
  343. package/dist/modules/customers/module.d.ts.map +0 -1
  344. package/dist/modules/customers/module.js +0 -20
  345. package/dist/modules/documents/module.d.ts +0 -7
  346. package/dist/modules/documents/module.d.ts.map +0 -1
  347. package/dist/modules/documents/module.js +0 -13
  348. package/dist/modules/fulfillment/module.d.ts +0 -13
  349. package/dist/modules/fulfillment/module.d.ts.map +0 -1
  350. package/dist/modules/fulfillment/module.js +0 -23
  351. package/dist/modules/inventory/module.d.ts +0 -13
  352. package/dist/modules/inventory/module.d.ts.map +0 -1
  353. package/dist/modules/inventory/module.js +0 -20
  354. package/dist/modules/media/index.d.ts +0 -2
  355. package/dist/modules/media/index.d.ts.map +0 -1
  356. package/dist/modules/media/index.js +0 -1
  357. package/dist/modules/media/module.d.ts +0 -360
  358. package/dist/modules/media/module.d.ts.map +0 -1
  359. package/dist/modules/media/module.js +0 -24
  360. package/dist/modules/orders/module.d.ts +0 -25
  361. package/dist/modules/orders/module.d.ts.map +0 -1
  362. package/dist/modules/orders/module.js +0 -33
  363. package/dist/modules/organization/index.d.ts +0 -2
  364. package/dist/modules/organization/index.d.ts.map +0 -1
  365. package/dist/modules/organization/index.js +0 -1
  366. package/dist/modules/organization/module.d.ts +0 -205
  367. package/dist/modules/organization/module.d.ts.map +0 -1
  368. package/dist/modules/organization/module.js +0 -8
  369. package/dist/modules/payments/module.d.ts +0 -3
  370. package/dist/modules/payments/module.d.ts.map +0 -1
  371. package/dist/modules/payments/module.js +0 -7
  372. package/dist/modules/payments/repository/index.d.ts +0 -5
  373. package/dist/modules/payments/repository/index.d.ts.map +0 -1
  374. package/dist/modules/payments/repository/index.js +0 -1
  375. package/dist/modules/pricing/index.d.ts +0 -2
  376. package/dist/modules/pricing/index.d.ts.map +0 -1
  377. package/dist/modules/pricing/index.js +0 -1
  378. package/dist/modules/pricing/module.d.ts +0 -14
  379. package/dist/modules/pricing/module.d.ts.map +0 -1
  380. package/dist/modules/pricing/module.js +0 -17
  381. package/dist/modules/promotions/module.d.ts +0 -14
  382. package/dist/modules/promotions/module.d.ts.map +0 -1
  383. package/dist/modules/promotions/module.js +0 -19
  384. package/dist/modules/search/module.d.ts +0 -8
  385. package/dist/modules/search/module.d.ts.map +0 -1
  386. package/dist/modules/search/module.js +0 -22
  387. package/dist/modules/search/repository/index.d.ts +0 -5
  388. package/dist/modules/search/repository/index.d.ts.map +0 -1
  389. package/dist/modules/search/repository/index.js +0 -1
  390. package/dist/modules/settings/module.d.ts +0 -6
  391. package/dist/modules/settings/module.d.ts.map +0 -1
  392. package/dist/modules/settings/module.js +0 -12
  393. package/dist/modules/shipping/module.d.ts +0 -12
  394. package/dist/modules/shipping/module.d.ts.map +0 -1
  395. package/dist/modules/shipping/module.js +0 -14
  396. package/dist/modules/tax/module.d.ts +0 -7
  397. package/dist/modules/tax/module.d.ts.map +0 -1
  398. package/dist/modules/tax/module.js +0 -13
  399. package/dist/modules/webhooks/index.d.ts +0 -2
  400. package/dist/modules/webhooks/index.d.ts.map +0 -1
  401. package/dist/modules/webhooks/index.js +0 -1
  402. package/dist/modules/webhooks/module.d.ts +0 -403
  403. package/dist/modules/webhooks/module.d.ts.map +0 -1
  404. package/dist/modules/webhooks/module.js +0 -16
  405. package/dist/test-utils/create-repository-test-harness.d.ts +0 -8
  406. package/dist/test-utils/create-repository-test-harness.d.ts.map +0 -1
  407. package/dist/test-utils/create-repository-test-harness.js +0 -7
  408. package/dist/test-utils/create-test-plugin-context.d.ts +0 -38
  409. package/dist/test-utils/create-test-plugin-context.d.ts.map +0 -1
  410. package/dist/test-utils/create-test-plugin-context.js +0 -39
  411. package/dist/test-utils/typed-hooks.d.ts +0 -44
  412. package/dist/test-utils/typed-hooks.d.ts.map +0 -1
  413. package/dist/test-utils/typed-hooks.js +0 -36
  414. package/dist/types/commerce-types.d.ts +0 -34
  415. package/dist/types/commerce-types.d.ts.map +0 -1
  416. package/dist/types/commerce-types.js +0 -1
  417. package/src/auth/access.ts +0 -187
  418. package/src/generated/plugin-capabilities.d.ts +0 -21
  419. package/src/generated/plugin-manifest.ts +0 -24
  420. package/src/generated/plugin-repositories.d.ts +0 -21
  421. package/src/kernel/factory/repository-factory.ts +0 -244
  422. package/src/kernel/http-error.ts +0 -44
  423. package/src/kernel/jobs/builtin-job-tasks.ts +0 -17
  424. package/src/kernel/module/define.ts +0 -36
  425. package/src/kernel/module/index.ts +0 -3
  426. package/src/kernel/module/topo-sort.ts +0 -99
  427. package/src/kernel/query/executor.ts +0 -184
  428. package/src/kernel/query/registry.ts +0 -46
  429. package/src/kernel/service-registry.ts +0 -76
  430. package/src/modules/analytics/hooks.ts +0 -11
  431. package/src/modules/analytics/module.ts +0 -35
  432. package/src/modules/analytics/repository/index.ts +0 -5
  433. package/src/modules/audit/index.ts +0 -1
  434. package/src/modules/audit/module.ts +0 -11
  435. package/src/modules/cart/access.ts +0 -27
  436. package/src/modules/cart/module.ts +0 -32
  437. package/src/modules/catalog/module.ts +0 -80
  438. package/src/modules/customers/index.ts +0 -1
  439. package/src/modules/customers/module.ts +0 -29
  440. package/src/modules/documents/module.ts +0 -21
  441. package/src/modules/fulfillment/module.ts +0 -44
  442. package/src/modules/inventory/module.ts +0 -37
  443. package/src/modules/media/index.ts +0 -1
  444. package/src/modules/media/module.ts +0 -27
  445. package/src/modules/orders/module.ts +0 -67
  446. package/src/modules/organization/index.ts +0 -1
  447. package/src/modules/organization/module.ts +0 -11
  448. package/src/modules/payments/module.ts +0 -14
  449. package/src/modules/payments/repository/index.ts +0 -5
  450. package/src/modules/pricing/index.ts +0 -1
  451. package/src/modules/pricing/module.ts +0 -32
  452. package/src/modules/promotions/module.ts +0 -34
  453. package/src/modules/search/module.ts +0 -32
  454. package/src/modules/search/repository/index.ts +0 -5
  455. package/src/modules/settings/module.ts +0 -20
  456. package/src/modules/shipping/module.ts +0 -27
  457. package/src/modules/tax/module.ts +0 -21
  458. package/src/modules/webhooks/index.ts +0 -1
  459. package/src/modules/webhooks/module.ts +0 -24
  460. package/src/test-utils/create-repository-test-harness.ts +0 -16
  461. package/src/test-utils/create-test-plugin-context.ts +0 -66
  462. package/src/test-utils/typed-hooks.ts +0 -55
  463. package/src/types/commerce-types.ts +0 -34
@@ -1,187 +0,0 @@
1
- import type { Actor } from "./types.js";
2
-
3
- /**
4
- * A WhereClause is a plain object representing database filter conditions.
5
- * The shape mirrors what services and repositories can accept to narrow queries.
6
- *
7
- * Example: { customerId: "abc-123" } narrows results to that customer's records.
8
- * Composite: { or: [{ customerId: "x" }, { organizationId: "y" }] }
9
- */
10
- export type WhereClause = Record<string, unknown>;
11
-
12
- /**
13
- * AccessResult: the return value of an access function.
14
- *
15
- * - `true`: full access, no filter needed
16
- * - `false`: no access at all
17
- * - `WhereClause`: partial access — the caller should apply this as a query filter
18
- */
19
- export type AccessResult = boolean | WhereClause;
20
-
21
- /**
22
- * AccessContext carries everything an access function needs to make a decision.
23
- *
24
- * - `actor`: the authenticated user/api-key/null (anonymous)
25
- * - `data`: the document being accessed (for document-level checks)
26
- * - `id`: the document ID (when data isn't loaded yet)
27
- */
28
- export interface AccessContext<TData = unknown> {
29
- actor: Actor | null;
30
- data?: TData;
31
- id?: string;
32
- req?: Request;
33
- }
34
-
35
- /**
36
- * An AccessFn evaluates access for a given context.
37
- * Returns boolean (full/no access) or WhereClause (filtered access).
38
- */
39
- export type AccessFn<TData = unknown> = (
40
- ctx: AccessContext<TData>,
41
- ) => AccessResult | Promise<AccessResult>;
42
-
43
- /**
44
- * Combines multiple WhereClause objects with a logical operator.
45
- * If there's only one clause, returns it directly (no unnecessary nesting).
46
- */
47
- function combineWhere(
48
- queries: WhereClause[],
49
- operator: "and" | "or",
50
- ): WhereClause {
51
- if (queries.length === 1) return queries[0]!;
52
- return { [operator]: queries };
53
- }
54
-
55
- /**
56
- * Composes access functions with OR semantics.
57
- *
58
- * - If ANY function returns `true`, grants full access immediately (short-circuit).
59
- * - If one or more return WhereClause, combines them with OR.
60
- * - If ALL return `false`, denies access.
61
- *
62
- * Example:
63
- * ```typescript
64
- * const orderReadAccess = accessOR(isAdmin, isDocumentOwner("customerId"))
65
- * // Admins see all orders; customers see only their own
66
- * ```
67
- */
68
- export const accessOR = <TData = unknown>(
69
- ...fns: Array<AccessFn<TData>>
70
- ): AccessFn<TData> => {
71
- return async (ctx) => {
72
- const queries: WhereClause[] = [];
73
- for (const fn of fns) {
74
- const result = await fn(ctx);
75
- if (result === true) return true;
76
- if (result && typeof result === "object") queries.push(result);
77
- }
78
- if (queries.length > 0) return combineWhere(queries, "or");
79
- return false;
80
- };
81
- };
82
-
83
- /**
84
- * Composes access functions with AND semantics.
85
- *
86
- * - If ANY function returns `false`, denies access immediately (short-circuit).
87
- * - If one or more return WhereClause, combines them with AND.
88
- * - If ALL return `true`, grants full access.
89
- *
90
- * Example:
91
- * ```typescript
92
- * const restrictedAccess = accessAND(isAuthenticated, isDocumentOwner("customerId"))
93
- * // Must be logged in AND own the document
94
- * ```
95
- */
96
- export const accessAND = <TData = unknown>(
97
- ...fns: Array<AccessFn<TData>>
98
- ): AccessFn<TData> => {
99
- return async (ctx) => {
100
- const queries: WhereClause[] = [];
101
- for (const fn of fns) {
102
- const result = await fn(ctx);
103
- if (result === false) return false;
104
- if (result !== true && result && typeof result === "object") {
105
- queries.push(result);
106
- }
107
- }
108
- if (queries.length > 0) return combineWhere(queries, "and");
109
- return true;
110
- };
111
- };
112
-
113
- /**
114
- * Switches between two access functions based on a condition.
115
- *
116
- * Example:
117
- * ```typescript
118
- * const accessByRole = conditional(
119
- * ({ actor }) => actor?.role === "vendor",
120
- * isDocumentOwner("vendorId"),
121
- * isAdmin,
122
- * )
123
- * ```
124
- */
125
- export const conditional = <TData = unknown>(
126
- condition: ((ctx: AccessContext<TData>) => boolean) | boolean,
127
- accessFn: AccessFn<TData>,
128
- fallback: AccessFn<TData> = () => false,
129
- ): AccessFn<TData> => {
130
- return async (ctx) => {
131
- const applies =
132
- typeof condition === "function" ? condition(ctx) : condition;
133
- return applies ? accessFn(ctx) : fallback(ctx);
134
- };
135
- };
136
-
137
- // ─────────────────────────────────────────────────────────────────────────────
138
- // Built-in access functions
139
- // ─────────────────────────────────────────────────────────────────────────────
140
-
141
- /**
142
- * Grants access if the actor has admin or owner role (wildcard permissions).
143
- */
144
- export const isAdmin: AccessFn = ({ actor }) => {
145
- if (!actor) return false;
146
- return actor.permissions.includes("*:*");
147
- };
148
-
149
- /**
150
- * Grants access if the actor is authenticated (any role).
151
- */
152
- export const isAuthenticated: AccessFn = ({ actor }) => {
153
- return actor != null;
154
- };
155
-
156
- /**
157
- * Returns a WhereClause that filters to documents owned by the actor.
158
- * The ownerField is the column name that holds the owner's user ID.
159
- *
160
- * For document-level checks (when data is provided), returns true/false.
161
- * For list-level checks (when data is not provided), returns a WhereClause.
162
- */
163
- export const isDocumentOwner = (
164
- ownerField = "customerId",
165
- ): AccessFn => {
166
- return ({ actor, data }) => {
167
- if (!actor) return false;
168
-
169
- // Document-level check: compare directly
170
- if (data) {
171
- return (data as Record<string, unknown>)[ownerField] === actor.userId;
172
- }
173
-
174
- // List-level check: return a filter clause
175
- return { [ownerField]: actor.userId };
176
- };
177
- };
178
-
179
- /**
180
- * Grants access to everyone, including anonymous users.
181
- */
182
- export const publicAccess: AccessFn = () => true;
183
-
184
- /**
185
- * Denies access to everyone.
186
- */
187
- export const denyAll: AccessFn = () => false;
@@ -1,21 +0,0 @@
1
- /* eslint-disable */
2
- // AUTO-GENERATED by scripts/generate-plugin-types.mjs
3
-
4
- export interface PluginCapabilityRegistryShape {
5
- "appointments": Record<string, unknown>;
6
- "channel-connector": Record<string, unknown>;
7
- "gift-cards": Record<string, unknown>;
8
- "layaway": Record<string, unknown>;
9
- "loyalty": Record<string, unknown>;
10
- "marketplace": Record<string, unknown>;
11
- "notifications": Record<string, unknown>;
12
- "pos": Record<string, unknown>;
13
- "pos-restaurant": Record<string, unknown>;
14
- "procurement": Record<string, unknown>;
15
- "production": Record<string, unknown>;
16
- "reviews": Record<string, unknown>;
17
- "scheduled-orders": Record<string, unknown>;
18
- "uom": Record<string, unknown>;
19
- "warehouse": Record<string, unknown>;
20
- "wishlist": Record<string, unknown>;
21
- }
@@ -1,24 +0,0 @@
1
- /* eslint-disable */
2
- // AUTO-GENERATED by scripts/generate-plugin-types.mjs
3
- // DO NOT EDIT MANUALLY.
4
-
5
- export const resolvedPluginManifest = [
6
- { id: "appointments", directory: "plugin-appointments" },
7
- { id: "channel-connector", directory: "plugin-channel-connector" },
8
- { id: "gift-cards", directory: "plugin-gift-cards" },
9
- { id: "layaway", directory: "plugin-layaway" },
10
- { id: "loyalty", directory: "plugin-loyalty" },
11
- { id: "marketplace", directory: "plugin-marketplace" },
12
- { id: "notifications", directory: "plugin-notifications" },
13
- { id: "pos", directory: "plugin-pos" },
14
- { id: "pos-restaurant", directory: "plugin-pos-restaurant" },
15
- { id: "procurement", directory: "plugin-procurement" },
16
- { id: "production", directory: "plugin-production" },
17
- { id: "reviews", directory: "plugin-reviews" },
18
- { id: "scheduled-orders", directory: "plugin-scheduled-orders" },
19
- { id: "uom", directory: "plugin-uom" },
20
- { id: "warehouse", directory: "plugin-warehouse" },
21
- { id: "wishlist", directory: "plugin-wishlist" },
22
- ] as const;
23
-
24
- export type ResolvedPluginId = (typeof resolvedPluginManifest)[number]["id"];
@@ -1,21 +0,0 @@
1
- /* eslint-disable */
2
- // AUTO-GENERATED by scripts/generate-plugin-types.mjs
3
-
4
- export interface PluginRepositoryRegistryShape {
5
- "appointments": Record<string, unknown>;
6
- "channel-connector": Record<string, unknown>;
7
- "gift-cards": Record<string, unknown>;
8
- "layaway": Record<string, unknown>;
9
- "loyalty": Record<string, unknown>;
10
- "marketplace": Record<string, unknown>;
11
- "notifications": Record<string, unknown>;
12
- "pos": Record<string, unknown>;
13
- "pos-restaurant": Record<string, unknown>;
14
- "procurement": Record<string, unknown>;
15
- "production": Record<string, unknown>;
16
- "reviews": Record<string, unknown>;
17
- "scheduled-orders": Record<string, unknown>;
18
- "uom": Record<string, unknown>;
19
- "warehouse": Record<string, unknown>;
20
- "wishlist": Record<string, unknown>;
21
- }
@@ -1,244 +0,0 @@
1
- import {
2
- eq,
3
- and,
4
- isNull,
5
- sql,
6
- getTableColumns,
7
- type SQL,
8
- type Column,
9
- type InferSelectModel,
10
- type InferInsertModel,
11
- } from "drizzle-orm";
12
- import type { PgTableWithColumns, TableConfig } from "drizzle-orm/pg-core";
13
- import { PgTable } from "drizzle-orm/pg-core";
14
- import type { TxContext } from "../database/tx-context.js";
15
- import type { DrizzleDatabase, DbOrTx } from "../database/drizzle-db.js";
16
- import { CommerceNotFoundError } from "../errors.js";
17
-
18
- /**
19
- * Filter type — partial record of column values to match with eq().
20
- * Only keys that exist on TRow and have non-undefined values are used.
21
- */
22
- export type Filters<TRow> = Partial<TRow>;
23
-
24
- /**
25
- * Options for findMany / findAndCount queries.
26
- */
27
- export interface FindOptions {
28
- limit?: number;
29
- offset?: number;
30
- orderBy?: Array<{ column: string; direction: "asc" | "desc" }>;
31
- withDeleted?: boolean;
32
- }
33
-
34
- /**
35
- * Standard CRUD operations derived from a Drizzle pgTable schema.
36
- * All methods support optional TxContext for transaction participation.
37
- */
38
- export interface BaseRepository<TRow, TInsert> {
39
- findById(id: string, ctx?: TxContext): Promise<TRow | undefined>;
40
- findMany(
41
- filters?: Filters<TRow>,
42
- options?: FindOptions,
43
- ctx?: TxContext,
44
- ): Promise<TRow[]>;
45
- findAndCount(
46
- filters?: Filters<TRow>,
47
- options?: FindOptions,
48
- ctx?: TxContext,
49
- ): Promise<{ rows: TRow[]; total: number }>;
50
- create(data: TInsert, ctx?: TxContext): Promise<TRow>;
51
- createMany(data: TInsert[], ctx?: TxContext): Promise<TRow[]>;
52
- update(id: string, data: Partial<TInsert>, ctx?: TxContext): Promise<TRow>;
53
- delete(id: string, ctx?: TxContext): Promise<void>;
54
- }
55
-
56
- /**
57
- * Extended repository for tables with a `deleted_at` column.
58
- * Adds softDelete and restore operations.
59
- */
60
- export interface SoftDeletableRepository<TRow, TInsert>
61
- extends BaseRepository<TRow, TInsert> {
62
- softDelete(id: string, ctx?: TxContext): Promise<void>;
63
- restore(id: string, ctx?: TxContext): Promise<TRow>;
64
- }
65
-
66
- /**
67
- * Type-level check: does the table config have a `deletedAt` or `deleted_at` column?
68
- */
69
- type HasDeletedAt<T extends PgTableWithColumns<TableConfig>> =
70
- "deletedAt" extends keyof T ? true : "deleted_at" extends keyof T ? true : false;
71
-
72
- /**
73
- * Conditional repository type: if the table has a deleted_at column,
74
- * return SoftDeletableRepository; otherwise BaseRepository.
75
- */
76
- export type RepositoryFor<T extends PgTableWithColumns<TableConfig>> =
77
- HasDeletedAt<T> extends true
78
- ? SoftDeletableRepository<InferSelectModel<T>, InferInsertModel<T>>
79
- : BaseRepository<InferSelectModel<T>, InferInsertModel<T>>;
80
-
81
- /**
82
- * Creates a typed repository with standard CRUD operations from a Drizzle table schema.
83
- *
84
- * Usage:
85
- * ```typescript
86
- * const repo = createRepository(schema.promotions, db)
87
- * const row = await repo.findById("abc-123")
88
- * const rows = await repo.findMany({ status: "active" }, { limit: 10 })
89
- * ```
90
- *
91
- * Tables with a `deletedAt` column automatically get `softDelete()` and `restore()`.
92
- * Domain-specific queries should remain in dedicated repository classes that
93
- * delegate standard CRUD to the factory-created instance.
94
- */
95
- export function createRepository<T extends PgTableWithColumns<TableConfig>>(
96
- table: T,
97
- db: DrizzleDatabase,
98
- ): RepositoryFor<T> {
99
- // Use getTableColumns for type-safe column access
100
- const columns = getTableColumns(table) as Record<string, Column>;
101
-
102
- // Runtime check for soft-delete column
103
- const hasSoftDelete = "deletedAt" in columns || "deleted_at" in columns;
104
- const deletedAtColumn: Column | null =
105
- columns["deletedAt"] ?? columns["deleted_at"] ?? null;
106
- const idColumn = columns["id"]!;
107
-
108
- // Drizzle's generic types require PgTable at the boundary.
109
- // We cast once here rather than at every call site.
110
- const pgTable = table as PgTable;
111
-
112
- function getDb(ctx?: TxContext): DbOrTx {
113
- return (ctx?.tx as DbOrTx | undefined) ?? db;
114
- }
115
-
116
- function buildWhereConditions(
117
- filters?: Filters<InferSelectModel<T>>,
118
- includeDeleted = false,
119
- ): SQL[] {
120
- const conditions: SQL[] = [];
121
-
122
- // Automatically exclude soft-deleted rows unless explicitly requested
123
- if (hasSoftDelete && !includeDeleted && deletedAtColumn) {
124
- conditions.push(isNull(deletedAtColumn));
125
- }
126
-
127
- if (filters) {
128
- for (const [key, value] of Object.entries(filters)) {
129
- const col = columns[key];
130
- if (value !== undefined && col) {
131
- conditions.push(eq(col, value));
132
- }
133
- }
134
- }
135
-
136
- return conditions;
137
- }
138
-
139
- const repo: BaseRepository<InferSelectModel<T>, InferInsertModel<T>> = {
140
- async findById(id, ctx) {
141
- const conditions = buildWhereConditions(undefined, false);
142
- conditions.push(eq(idColumn, id));
143
- const rows = await getDb(ctx)
144
- .select()
145
- .from(pgTable)
146
- .where(and(...conditions));
147
- return rows[0] as InferSelectModel<T> | undefined;
148
- },
149
-
150
- async findMany(filters, options = {}, ctx) {
151
- const conditions = buildWhereConditions(filters, options.withDeleted);
152
- let query = getDb(ctx).select().from(pgTable).$dynamic();
153
- if (conditions.length > 0) {
154
- query = query.where(and(...conditions));
155
- }
156
- if (options.limit !== undefined) {
157
- query = query.limit(options.limit);
158
- }
159
- if (options.offset !== undefined) {
160
- query = query.offset(options.offset);
161
- }
162
- // Drizzle's $dynamic() erases the row type when using PgTable.
163
- // Use .then() to narrow the resolved array type with a single cast.
164
- return query.then((rows) => rows as InferSelectModel<T>[]);
165
- },
166
-
167
- async findAndCount(filters, options = {}, ctx) {
168
- const rows = await repo.findMany(filters, options, ctx);
169
- const conditions = buildWhereConditions(filters, options.withDeleted);
170
- let countQuery = getDb(ctx)
171
- .select({ count: sql<number>`count(*)::int` })
172
- .from(pgTable)
173
- .$dynamic();
174
- if (conditions.length > 0) {
175
- countQuery = countQuery.where(and(...conditions));
176
- }
177
- const countResult = await countQuery;
178
- return { rows, total: countResult[0]?.count ?? 0 };
179
- },
180
-
181
- async create(data, ctx) {
182
- const rows = await getDb(ctx)
183
- .insert(pgTable)
184
- .values(data as Record<string, unknown>)
185
- .returning();
186
- return rows[0] as InferSelectModel<T>;
187
- },
188
-
189
- async createMany(data, ctx) {
190
- if (data.length === 0) return [];
191
- const rows = await getDb(ctx)
192
- .insert(pgTable)
193
- .values(data as Record<string, unknown>[])
194
- .returning();
195
- return rows as InferSelectModel<T>[];
196
- },
197
-
198
- async update(id, data, ctx) {
199
- const rows = await getDb(ctx)
200
- .update(pgTable)
201
- .set(data as Record<string, unknown>)
202
- .where(eq(idColumn, id))
203
- .returning();
204
- if (!rows[0]) {
205
- throw new CommerceNotFoundError(`Record ${id} not found.`);
206
- }
207
- return rows[0] as InferSelectModel<T>;
208
- },
209
-
210
- async delete(id, ctx) {
211
- await getDb(ctx).delete(pgTable).where(eq(idColumn, id));
212
- },
213
- };
214
-
215
- if (hasSoftDelete && deletedAtColumn) {
216
- const softRepo = repo as SoftDeletableRepository<
217
- InferSelectModel<T>,
218
- InferInsertModel<T>
219
- >;
220
-
221
- softRepo.softDelete = async (id, ctx) => {
222
- await getDb(ctx)
223
- .update(pgTable)
224
- .set({ deletedAt: new Date() } as Record<string, unknown>)
225
- .where(eq(idColumn, id));
226
- };
227
-
228
- softRepo.restore = async (id, ctx) => {
229
- const rows = await getDb(ctx)
230
- .update(pgTable)
231
- .set({ deletedAt: null } as Record<string, unknown>)
232
- .where(eq(idColumn, id))
233
- .returning();
234
- if (!rows[0]) {
235
- throw new CommerceNotFoundError(`Record ${id} not found.`);
236
- }
237
- return rows[0] as InferSelectModel<T>;
238
- };
239
-
240
- return softRepo as RepositoryFor<T>;
241
- }
242
-
243
- return repo as RepositoryFor<T>;
244
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * Converts a PluginResultErr into a structured HTTP error response.
3
- *
4
- * Replaces the `throw new Error(result.error)` pattern in plugin routes
5
- * which always produces HTTP 500 with no structured error code.
6
- *
7
- * Usage in routes:
8
- * const result = await service.doSomething(orgId, input);
9
- * if (!result.ok) return toHttpError(result);
10
- * return result.value;
11
- *
12
- * The function infers HTTP status from the error code or message content:
13
- * - "NOT_FOUND" or "not found" --> 404
14
- * - "FORBIDDEN" or "permission" --> 403
15
- * - "CONFLICT" or "already exists" --> 409
16
- * - "VALIDATION" or "cannot/must" --> 422
17
- * - Everything else --> 400
18
- */
19
-
20
- import type { PluginResultErr } from "./result.js";
21
-
22
- export interface HttpErrorResponse {
23
- status: 400 | 403 | 404 | 409 | 422;
24
- body: { error: { code: string; message: string } };
25
- }
26
-
27
- export function toHttpError(result: PluginResultErr): HttpErrorResponse {
28
- const message = result.error;
29
- const code = result.code;
30
-
31
- if (code === "NOT_FOUND" || /not found/i.test(message)) {
32
- return { status: 404, body: { error: { code: "NOT_FOUND", message } } };
33
- }
34
- if (code === "FORBIDDEN" || /permission|forbidden|unauthorized/i.test(message)) {
35
- return { status: 403, body: { error: { code: "FORBIDDEN", message } } };
36
- }
37
- if (code === "CONFLICT" || /already|duplicate|exists|unique/i.test(message)) {
38
- return { status: 409, body: { error: { code: "CONFLICT", message } } };
39
- }
40
- if (code === "VALIDATION" || /invalid|cannot|must|required|exceeded|negative/i.test(message)) {
41
- return { status: 422, body: { error: { code: "VALIDATION_FAILED", message } } };
42
- }
43
- return { status: 400, body: { error: { code: code ?? "BAD_REQUEST", message } } };
44
- }
@@ -1,17 +0,0 @@
1
- import { webhookDeliveryTask } from "../../modules/webhooks/tasks.js";
2
- import { staleJobReaperTask } from "./reaper.js";
3
- import type { TaskDefinition } from "./types.js";
4
-
5
- export const defaultKernelJobTasks: TaskDefinition<
6
- Record<string, unknown>,
7
- Record<string, unknown>
8
- >[] = [
9
- webhookDeliveryTask as TaskDefinition<
10
- Record<string, unknown>,
11
- Record<string, unknown>
12
- >,
13
- staleJobReaperTask as TaskDefinition<
14
- Record<string, unknown>,
15
- Record<string, unknown>
16
- >,
17
- ];
@@ -1,36 +0,0 @@
1
- import type { DatabaseAdapter } from "../database/adapter.js";
2
- import type { HookRegistry } from "../hooks/registry.js";
3
- import type { Logger } from "../hooks/types.js";
4
-
5
- export interface ModuleDeps<TDeps extends Record<string, unknown> = Record<string, unknown>> {
6
- db: DatabaseAdapter;
7
- hooks: HookRegistry;
8
- services: TDeps;
9
- config: unknown;
10
- logger: Logger;
11
- }
12
-
13
- export interface AppModule<
14
- TSchema = unknown,
15
- TService = unknown,
16
- TDeps extends Record<string, unknown> = Record<string, unknown>,
17
- > {
18
- id: string;
19
- schema: () => TSchema;
20
- dependencies?: ReadonlyArray<keyof TDeps & string>;
21
- service: (deps: ModuleDeps<TDeps>) => TService;
22
- }
23
-
24
- export type ServiceMap<TModules extends Record<string, AppModule>> = {
25
- [K in keyof TModules]: TModules[K] extends AppModule<infer _TSchema, infer TService, infer _TDeps>
26
- ? TService
27
- : never;
28
- };
29
-
30
- export function defineModule<
31
- TSchema,
32
- TService,
33
- TDeps extends Record<string, unknown> = Record<string, unknown>,
34
- >(manifest: AppModule<TSchema, TService, TDeps>): AppModule<TSchema, TService, TDeps> {
35
- return manifest;
36
- }
@@ -1,3 +0,0 @@
1
- export type { AppModule, ModuleDeps, ServiceMap } from "./define.js";
2
- export { defineModule } from "./define.js";
3
- export { ModuleCycleError, topoSortModules } from "./topo-sort.js";