@porulle/core 0.63.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 +8 -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 +13 -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 +11 -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 +13 -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
@@ -14,18 +14,12 @@ import {
14
14
  toCommerceError,
15
15
  } from "../../kernel/errors.js";
16
16
  import { runAfterHooks, runBeforeHooks } from "../../kernel/hooks/executor.js";
17
- import { createHookContext } from "../../kernel/hooks/create-context.js";
18
- import type {
19
- AfterHook,
20
- BeforeHook,
21
- HookContext,
22
- } from "../../kernel/hooks/types.js";
17
+ import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
18
+ import type { AfterHook, BeforeHook } from "../../kernel/hooks/types.js";
23
19
  import type { HookRegistry } from "../../kernel/hooks/registry.js";
24
20
  import { Err, Ok, type Result } from "../../kernel/result.js";
25
- import { createLogger } from "../../utils/logger.js";
26
21
  import { paginate, type Pagination } from "../../utils/pagination.js";
27
22
  import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
28
- import type { PluginDb } from "../../kernel/database/plugin-types.js";
29
23
  import type { TxContext } from "../../kernel/database/tx-context.js";
30
24
  import { CartRepository, type Cart, type CartLineItem } from "./repository/index.js";
31
25
  import type { CatalogRepository } from "../catalog/repository/index.js";
@@ -61,23 +55,6 @@ type CartRemoveAfterHook = AfterHook<CartLineItem>;
61
55
  type CartUpdateBeforeHook = BeforeHook<UpdateCartItemInput>;
62
56
  type CartUpdateAfterHook = AfterHook<CartLineItem>;
63
57
 
64
- function makeContext(
65
- actor: Actor | null,
66
- services: Record<string, unknown>,
67
- database: DatabaseAdapter,
68
- config: CommerceConfig,
69
- tx: unknown = null,
70
- ): HookContext {
71
- return createHookContext({
72
- actor,
73
- tx,
74
- logger: createLogger("cart"),
75
- services,
76
- context: { moduleName: "cart" },
77
- database: { db: database.db as PluginDb },
78
- commerceConfig: config,
79
- });
80
- }
81
58
 
82
59
  function isExpired(cart: Cart): boolean {
83
60
  return cart.expiresAt.getTime() < Date.now();
@@ -283,7 +260,7 @@ export class CartService {
283
260
  );
284
261
  }
285
262
 
286
- const context = makeContext(actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx);
263
+ const context = createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx);
287
264
  const beforeHooks = this.deps.hooks.resolve(
288
265
  "cart.beforeAddItem",
289
266
  ) as CartAddBeforeHook[];
@@ -448,7 +425,7 @@ export class CartService {
448
425
  return Err(new CommerceNotFoundError("Cart item not found."));
449
426
  }
450
427
 
451
- const context = makeContext(actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx);
428
+ const context = createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx);
452
429
  const beforeHooks = this.deps.hooks.resolve(
453
430
  "cart.beforeRemoveItem",
454
431
  ) as CartRemoveBeforeHook[];
@@ -496,7 +473,7 @@ export class CartService {
496
473
  );
497
474
  }
498
475
 
499
- const context = makeContext(actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx);
476
+ const context = createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx);
500
477
  const beforeHooks = this.deps.hooks.resolve(
501
478
  "cart.beforeUpdateQuantity",
502
479
  ) as CartUpdateBeforeHook[];
@@ -652,7 +629,7 @@ export class CartService {
652
629
  null,
653
630
  updated ?? cart,
654
631
  "recover",
655
- makeContext(actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null),
632
+ createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx ?? null),
656
633
  );
657
634
 
658
635
  return Ok({
@@ -12,17 +12,14 @@ import {
12
12
  runAfterHooks,
13
13
  runBeforeHooks,
14
14
  } from "../../kernel/hooks/executor.js";
15
- import { createHookContext } from "../../kernel/hooks/create-context.js";
15
+ import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
16
16
  import type {
17
17
  AfterHook,
18
18
  BeforeHook,
19
19
  HookContext,
20
20
  } from "../../kernel/hooks/types.js";
21
21
  import { Err, Ok, type Result } from "../../kernel/result.js";
22
- import { createLogger } from "../../utils/logger.js";
23
22
  import { paginate } from "../../utils/pagination.js";
24
- import type { JobsAdapter } from "../../kernel/jobs/adapter.js";
25
- import type { PluginDb } from "../../kernel/database/plugin-types.js";
26
23
  import type { CatalogWriteContext, TxContext } from "../../kernel/database/tx-context.js";
27
24
  import { createTxContext, isWriteContextTransactional } from "../../kernel/database/tx-context.js";
28
25
  import { canReadUnpublishedCatalog, isCatalogEntityVisible } from "./read-policy.js";
@@ -52,9 +49,6 @@ import type {
52
49
  Variant,
53
50
  } from "./repository/index.js";
54
51
 
55
- function hookDatabaseArg(database: CatalogServiceDeps["database"]): { database: { db: PluginDb } } {
56
- return { database: { db: database.db as PluginDb } };
57
- }
58
52
 
59
53
  const attributeFields = ["title", "subtitle", "description", "richDescription", "seoTitle", "seoDescription"] as const;
60
54
 
@@ -64,15 +58,9 @@ export function catalogHookContext(
64
58
  ctx: CatalogWriteContext | undefined,
65
59
  operation: string,
66
60
  ): HookContext {
67
- return createHookContext({
68
- actor,
69
- tx: isWriteContextTransactional(ctx) ? ctx.tx : null,
70
- logger: createLogger(`catalog.${operation}`),
71
- services: deps.services,
72
- ...(deps.services.jobs ? { jobs: deps.services.jobs as JobsAdapter } : {}),
73
- context: { moduleName: "catalog", ...(ctx?.hookContext ?? {}) },
74
- ...hookDatabaseArg(deps.database),
75
- commerceConfig: deps.config,
61
+ return createModuleHookContext("catalog", deps, actor, isWriteContextTransactional(ctx) ? ctx.tx : null, {
62
+ logScope: `catalog.${operation}`,
63
+ ...(ctx?.hookContext ? { context: ctx.hookContext } : {}),
76
64
  });
77
65
  }
78
66
 
@@ -336,13 +324,15 @@ export class EntityService {
336
324
  await this.repo.deleteVariantOptionValuesByEntityId(id, ctx);
337
325
  await this.repo.deleteVariantsByEntityId(id, ctx);
338
326
  await this.repo.deleteEntity(id, ctx);
327
+ const afterHooks = this.deps.hooks.resolve("catalog.afterDelete") as AfterHook<SellableEntity>[];
328
+ await runAfterHooks(afterHooks, existing, existing, "delete", catalogHookContext(this.deps, actor, ctx, "delete"), (hook) => this.deps.hooks.runsInTransaction(hook));
339
329
  return Ok(undefined);
340
330
  } catch (error) { return Err(toCommerceError(error)); } }
341
331
 
342
332
  async getById(id: string, options: GetOptions | undefined, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogEntityHydrated>> {
343
333
  const resolvedActor = actor ?? ctx?.actor ?? null;
344
334
  const orgId = resolveOrgIdForCommerce(resolvedActor, this.deps.config);
345
- const context: HookContext = createHookContext({ actor: resolvedActor, tx: ctx?.tx ?? null, logger: createLogger("catalog.read"), services: this.deps.services, context: { moduleName: "catalog" }, ...hookDatabaseArg(this.deps.database), commerceConfig: this.deps.config });
335
+ const context: HookContext = createModuleHookContext("catalog", this.deps, resolvedActor, ctx?.tx ?? null, { logScope: "catalog.read" });
346
336
  const globalBeforeHooks = this.deps.hooks.resolve("catalog.beforeRead") as CatalogReadBeforeHook[];
347
337
  const globalAfterHooks = this.deps.hooks.resolve("catalog.afterRead") as CatalogReadAfterHook[];
348
338
  let processed = await runBeforeHooks(globalBeforeHooks, { id, ...(options !== undefined ? { options } : {}) }, "read", context);
@@ -389,7 +379,7 @@ export class EntityService {
389
379
  }
390
380
 
391
381
  async getBySlug(slug: string, options: GetOptions | undefined, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogEntityHydrated>> {
392
- const context: HookContext = createHookContext({ actor: actor ?? null, tx: ctx?.tx ?? null, logger: createLogger("catalog.read"), services: this.deps.services, context: { moduleName: "catalog" }, ...hookDatabaseArg(this.deps.database), commerceConfig: this.deps.config });
382
+ const context: HookContext = createModuleHookContext("catalog", this.deps, actor ?? null, ctx?.tx ?? null, { logScope: "catalog.read" });
393
383
  const globalBeforeHooks = this.deps.hooks.resolve("catalog.beforeRead") as CatalogReadBeforeHook[];
394
384
  const globalAfterHooks = this.deps.hooks.resolve("catalog.afterRead") as CatalogReadAfterHook[];
395
385
  let processed = await runBeforeHooks(globalBeforeHooks, { slug, ...(options !== undefined ? { options } : {}) }, "read", context);
@@ -424,7 +414,7 @@ export class EntityService {
424
414
 
425
415
  async list(params: ListParams, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogListResult>> {
426
416
  const resolvedActor = actor ?? ctx?.actor ?? null;
427
- const context: HookContext = createHookContext({ actor: resolvedActor, tx: ctx?.tx ?? null, logger: createLogger("catalog.list"), services: this.deps.services, context: { moduleName: "catalog" }, ...hookDatabaseArg(this.deps.database), commerceConfig: this.deps.config });
417
+ const context: HookContext = createModuleHookContext("catalog", this.deps, resolvedActor, ctx?.tx ?? null, { logScope: "catalog.list" });
428
418
  const globalBeforeHooks = this.deps.hooks.resolve("catalog.beforeList") as CatalogListBeforeHook[];
429
419
  const globalAfterHooks = this.deps.hooks.resolve("catalog.afterList") as CatalogListAfterHook[];
430
420
  let processed = await runBeforeHooks(globalBeforeHooks, params, "list", context);
@@ -29,6 +29,8 @@ import {
29
29
  import { prices } from "../pricing/schema.js";
30
30
  import { catalogHookContext } from "./entity-service.js";
31
31
  import type { CatalogServiceDeps } from "./service.js";
32
+ import { isUniqueViolation } from "../../kernel/database/unique-violation.js";
33
+ import { normalizeCurrency } from "../../utils/money.js";
32
34
 
33
35
  /**
34
36
  * The import fast path: a PAGE of new products lands in one transaction.
@@ -147,12 +149,6 @@ function failed(ref: string, code: ImportRowFailureCode, error: string): ImportP
147
149
  return { ref, status: "failed", code, error };
148
150
  }
149
151
 
150
- function isUniqueViolation(error: unknown): boolean {
151
- if (typeof error !== "object" || error === null) return false;
152
- const value = error as { code?: unknown; cause?: unknown };
153
- if (value.code === "23505") return true;
154
- return isUniqueViolation(value.cause);
155
- }
156
152
 
157
153
  /**
158
154
  * A row's failure names the constraint, not the statement: Drizzle's message carries the whole
@@ -169,9 +165,6 @@ function describeWriteError(error: unknown): string {
169
165
  return message.split("\n", 1)[0] ?? message;
170
166
  }
171
167
 
172
- function normaliseCurrency(currency: string): string {
173
- return currency.trim().toUpperCase();
174
- }
175
168
 
176
169
  /** Everything that can be known wrong without a database. */
177
170
  function validateInMemory(page: ImportProduct[]): Map<number, Failure> {
@@ -215,7 +208,7 @@ function validateInMemory(page: ImportProduct[]): Map<number, Failure> {
215
208
  }
216
209
  for (const price of variant.prices ?? []) {
217
210
  if (!Number.isInteger(price.amount) || price.amount < 0) fail(`Variant "${variant.ref}" has a non-integer or negative amount for ${price.currency}.`);
218
- if (normaliseCurrency(price.currency).length === 0) fail(`Variant "${variant.ref}" has a price with no currency.`);
211
+ if (normalizeCurrency(price.currency).length === 0) fail(`Variant "${variant.ref}" has a price with no currency.`);
219
212
  }
220
213
  }
221
214
  for (const path of item.ownedFieldPaths ?? []) {
@@ -382,7 +375,7 @@ async function writeItem(
382
375
  organizationId: orgId,
383
376
  entityId,
384
377
  variantId,
385
- currency: normaliseCurrency(price.currency),
378
+ currency: normalizeCurrency(price.currency),
386
379
  amount: price.amount,
387
380
  ...(price.compareAtAmount !== undefined ? { compareAtAmount: price.compareAtAmount } : {}),
388
381
  };
@@ -60,6 +60,7 @@ import { EntityService } from "./entity-service.js";
60
60
  import { CategoryService } from "./category-service.js";
61
61
  import { BrandService } from "./brand-service.js";
62
62
  import { CatalogImportService, type ImportProduct, type ImportProductsOptions, type ImportProductsReport } from "./import-service.js";
63
+ import { isUniqueViolation } from "../../kernel/database/unique-violation.js";
63
64
 
64
65
  // ─── Hand-written types (not derivable from a single z.infer) ───────────────
65
66
 
@@ -151,285 +152,6 @@ export interface CatalogEntityHydrated extends SellableEntity {
151
152
  pricing?: Array<{ id: string; currency: string; amount: number; compareAtAmount?: number | null; createdAt: Date }>;
152
153
  }
153
154
 
154
- export interface CatalogService {
155
- readonly repository: CatalogRepository;
156
- create(
157
- input: CreateEntityInput,
158
- actor: Actor | null,
159
- ctx?: TxContext,
160
- ): Promise<Result<CatalogEntityHydrated>>;
161
- update(
162
- id: string,
163
- input: UpdateEntityInput,
164
- actor: Actor | null,
165
- ctx?: CatalogWriteContext,
166
- ): Promise<Result<CatalogEntityHydrated>>;
167
- delete(
168
- id: string,
169
- actor: Actor | null,
170
- ctx?: TxContext,
171
- ): Promise<Result<void>>;
172
- getById(
173
- id: string,
174
- options: GetOptions | undefined,
175
- actor: Actor | null,
176
- ctx?: TxContext,
177
- ): Promise<Result<CatalogEntityHydrated>>;
178
- getByIdForInternalUse(
179
- id: string,
180
- organizationId: string,
181
- options?: GetOptions,
182
- ctx?: TxContext,
183
- ): Promise<Result<CatalogEntityHydrated>>;
184
- getBySlug(
185
- slug: string,
186
- options: GetOptions | undefined,
187
- actor: Actor | null,
188
- ctx?: TxContext,
189
- ): Promise<Result<CatalogEntityHydrated>>;
190
- list(params: ListParams, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogListResult>>;
191
- /** Returns undefined when no concrete ownership row applies to the field. */
192
- resolveFieldOwner(
193
- entityId: string,
194
- fieldPath: FieldPath,
195
- storeId: string,
196
- ctx?: TxContext,
197
- variantId?: string | null,
198
- ): Promise<FieldOwner | undefined>;
199
- /** Entity-level bulk resolution: variant-scoped ownership rows are not consulted. */
200
- resolveFieldOwners(
201
- entityId: string,
202
- storeId: string,
203
- ctx?: TxContext,
204
- ): Promise<Map<FieldPath, FieldOwner>>;
205
- setFieldOwner(
206
- entityId: string,
207
- fieldPath: FieldPath,
208
- storeId: string | null,
209
- owner: FieldOwner,
210
- actor: Actor | null,
211
- ctx?: TxContext,
212
- variantId?: string | null,
213
- ): Promise<Result<void>>;
214
- listFieldOwnership(
215
- entityId: string,
216
- actor: Actor | null,
217
- ctx?: TxContext,
218
- storeId?: string,
219
- ): Promise<Result<CatalogFieldOwnership[]>>;
220
- seedImportedFieldOwnership(
221
- entityId: string,
222
- storeId: string,
223
- fieldPaths: FieldPath[],
224
- ctx?: TxContext,
225
- ): Promise<Result<void>>;
226
- publish(
227
- id: string,
228
- actor: Actor | null,
229
- ctx?: TxContext,
230
- ): Promise<Result<CatalogEntityHydrated>>;
231
- archive(
232
- id: string,
233
- actor: Actor | null,
234
- ctx?: TxContext,
235
- ): Promise<Result<CatalogEntityHydrated>>;
236
- /**
237
- * The import fast path: a page of NEW products in one transaction, per-item savepoints, one
238
- * revision per item, one `catalog.afterImport` hook per page. See `import-service.ts`.
239
- */
240
- importProducts(
241
- page: ImportProduct[],
242
- options: ImportProductsOptions,
243
- actor: Actor | null,
244
- ctx?: CatalogWriteContext,
245
- ): Promise<Result<ImportProductsReport>>;
246
- discontinue(
247
- id: string,
248
- actor: Actor | null,
249
- ctx?: TxContext,
250
- ): Promise<Result<CatalogEntityHydrated>>;
251
- setAttributes(
252
- entityId: string,
253
- locale: string,
254
- attrs: SetAttributesInput,
255
- actor: Actor | null,
256
- ctx?: CatalogWriteContext,
257
- ): Promise<Result<void>>;
258
- approveCustomField(
259
- entityId: string,
260
- fieldName: string,
261
- locale: string,
262
- actor: Actor | null,
263
- ctx?: TxContext,
264
- ): Promise<Result<SellableCustomField>>;
265
- rejectCustomField(
266
- entityId: string,
267
- fieldName: string,
268
- locale: string,
269
- actor: Actor | null,
270
- ctx?: TxContext,
271
- ): Promise<Result<SellableCustomField>>;
272
- getAttributes(
273
- entityId: string,
274
- locale: string,
275
- actor: Actor | null,
276
- ctx?: TxContext,
277
- ): Promise<Result<SellableAttribute>>;
278
- listCategories(
279
- ctx?: TxContext,
280
- opts?: { includeArchived?: boolean },
281
- ): Promise<Result<CategorySummary[]>>;
282
- createCategory(
283
- input: CreateCategoryInput,
284
- actor: Actor | null,
285
- ctx?: TxContext,
286
- ): Promise<Result<CategorySummary>>;
287
- archiveCategory(
288
- id: string,
289
- actor: Actor | null,
290
- ctx?: TxContext,
291
- ): Promise<Result<CategorySummary>>;
292
- restoreCategory(
293
- id: string,
294
- actor: Actor | null,
295
- ctx?: TxContext,
296
- ): Promise<Result<CategorySummary>>;
297
- updateCategory(
298
- id: string,
299
- input: UpdateCategoryInput,
300
- actor: Actor | null,
301
- ctx?: TxContext,
302
- ): Promise<Result<CategorySummary>>;
303
- deleteCategory(
304
- id: string,
305
- actor: Actor | null,
306
- ctx?: TxContext,
307
- ): Promise<Result<void>>;
308
- addToCategory(
309
- entityId: string,
310
- categoryId: string,
311
- actor: Actor | null,
312
- ctx?: TxContext,
313
- ): Promise<Result<void>>;
314
- removeFromCategory(
315
- entityId: string,
316
- categoryId: string,
317
- actor: Actor | null,
318
- ctx?: TxContext,
319
- ): Promise<Result<void>>;
320
- listBrands(ctx?: TxContext): Promise<Result<Brand[]>>;
321
- createBrand(
322
- input: CreateBrandInput,
323
- actor: Actor | null,
324
- ctx?: TxContext,
325
- ): Promise<Result<Brand>>;
326
- updateBrand(
327
- id: string,
328
- input: UpdateBrandInput,
329
- actor: Actor | null,
330
- ctx?: TxContext,
331
- ): Promise<Result<Brand>>;
332
- deleteBrand(
333
- id: string,
334
- actor: Actor | null,
335
- ctx?: TxContext,
336
- ): Promise<Result<void>>;
337
- addToBrand(
338
- entityId: string,
339
- brandId: string,
340
- actor: Actor | null,
341
- ctx?: TxContext,
342
- ): Promise<Result<void>>;
343
- removeFromBrand(
344
- entityId: string,
345
- brandId: string,
346
- actor: Actor | null,
347
- ctx?: TxContext,
348
- ): Promise<Result<void>>;
349
- createOptionType(
350
- input: CreateOptionTypeInput,
351
- actor: Actor | null,
352
- ctx?: TxContext,
353
- ): Promise<Result<OptionType>>;
354
- createOptionValue(
355
- input: CreateOptionValueInput,
356
- actor: Actor | null,
357
- ctx?: TxContext,
358
- ): Promise<Result<OptionValue>>;
359
- createVariant(
360
- input: CreateVariantInput,
361
- actor: Actor | null,
362
- ctx?: TxContext,
363
- ): Promise<Result<Variant>>;
364
- generateVariants(
365
- entityId: string,
366
- strategy: VariantGenerationStrategy,
367
- actor: Actor | null,
368
- ctx?: TxContext,
369
- ): Promise<Result<Variant[]>>;
370
- quickCreateVariant(
371
- entityId: string,
372
- input: { options: Record<string, string>; sku?: string | undefined; barcode?: string | undefined },
373
- actor: Actor | null,
374
- ctx?: TxContext,
375
- ): Promise<Result<{ variant: Variant; created: boolean }>>;
376
- bulkCreateVariants(
377
- entityId: string,
378
- input: { axes: Array<{ name: string; values: string[] }>; skuPrefix?: string | undefined },
379
- actor: Actor | null,
380
- ctx?: TxContext,
381
- ): Promise<Result<{ created: Variant[]; skipped: number }>>;
382
- /**
383
- * Move the entity's `updated_at` and fire `catalog.afterUpdate` for a change to rows RELATED to
384
- * it (links, media) — the versioning contract consumers rely on to re-read a product.
385
- */
386
- notifyEntityChanged(
387
- entityId: string,
388
- changedFieldPaths: readonly string[],
389
- actor: Actor | null,
390
- ctx?: TxContext,
391
- ): Promise<void>;
392
- recordEntityRevision(
393
- entityId: string,
394
- actor: Actor | null,
395
- reason?: SellableEntityRevisionReason,
396
- ctx?: TxContext,
397
- ): Promise<Result<SellableEntityRevision>>;
398
- restoreEntityRevision(
399
- entityId: string,
400
- revisionId: string,
401
- actor: Actor | null,
402
- ctx?: TxContext,
403
- ): Promise<Result<CatalogEntityHydrated>>;
404
- trimEntityRevisions(
405
- actor: Actor | null,
406
- olderThanDays?: number,
407
- ctx?: TxContext,
408
- ): Promise<Result<number>>;
409
- listEntityFieldDefinitions(
410
- actor?: Actor | null,
411
- entityType?: string,
412
- ctx?: TxContext,
413
- ): Promise<Result<EntityFieldDefinitionRecord[]>>;
414
- createEntityFieldDefinition(
415
- input: CreateEntityFieldDefinitionInput,
416
- actor: Actor | null,
417
- ctx?: TxContext,
418
- ): Promise<Result<EntityFieldDefinitionRecord>>;
419
- updateEntityFieldDefinition(
420
- id: string,
421
- input: UpdateEntityFieldDefinitionInput,
422
- actor: Actor | null,
423
- ctx?: TxContext,
424
- ): Promise<Result<EntityFieldDefinitionRecord>>;
425
- archiveEntityFieldDefinition(
426
- id: string,
427
- actor: Actor | null,
428
- ctx?: TxContext,
429
- ): Promise<Result<EntityFieldDefinitionRecord>>;
430
- resolveEntityFieldDefinitions: EntityFieldDefinitionResolver;
431
- }
432
-
433
155
  export interface CatalogServiceDeps {
434
156
  repository: CatalogRepository;
435
157
  hooks: HookRegistry;
@@ -452,14 +174,8 @@ export type CategorySummary = {
452
174
  metadata: Record<string, unknown>;
453
175
  };
454
176
 
455
- function isUniqueViolation(error: unknown): boolean {
456
- if (error == null || typeof error !== "object") return false;
457
- const value = error as { code?: unknown; cause?: unknown };
458
- if (value.code === "23505") return true;
459
- return isUniqueViolation(value.cause);
460
- }
461
177
 
462
- export class CatalogServiceImpl implements CatalogService {
178
+ export class CatalogServiceImpl {
463
179
  readonly repository: CatalogRepository;
464
180
  private readonly database: DatabaseAdapter;
465
181
  private readonly config: CommerceConfig;
@@ -4,14 +4,12 @@ import type { Actor } from "../../auth/types.js";
4
4
  import type { CommerceConfig } from "../../config/types.js";
5
5
  import { CommerceNotFoundError, toCommerceError } from "../../kernel/errors.js";
6
6
  import { runAfterHooks } from "../../kernel/hooks/executor.js";
7
- import { createHookContext } from "../../kernel/hooks/create-context.js";
7
+ import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
8
8
  import type { HookRegistry } from "../../kernel/hooks/registry.js";
9
- import type { AfterHook, HookContext } from "../../kernel/hooks/types.js";
9
+ import type { AfterHook } from "../../kernel/hooks/types.js";
10
10
  import { Err, Ok, type Result } from "../../kernel/result.js";
11
11
  import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
12
- import type { PluginDb } from "../../kernel/database/plugin-types.js";
13
12
  import type { TxContext } from "../../kernel/database/tx-context.js";
14
- import { createLogger } from "../../utils/logger.js";
15
13
  import type {
16
14
  CustomersRepository,
17
15
  Customer,
@@ -28,23 +26,6 @@ interface CustomerServiceDeps {
28
26
  database: DatabaseAdapter;
29
27
  }
30
28
 
31
- function hookContext(
32
- actor: Actor | null,
33
- services: Record<string, unknown>,
34
- database: DatabaseAdapter,
35
- config: CommerceConfig,
36
- tx: unknown,
37
- ): HookContext {
38
- return createHookContext({
39
- actor,
40
- tx,
41
- logger: createLogger("customers"),
42
- services,
43
- context: { moduleName: "customers" },
44
- database: { db: database.db as PluginDb },
45
- commerceConfig: config,
46
- });
47
- }
48
29
 
49
30
  export class CustomerService {
50
31
  private readonly repo: CustomersRepository;
@@ -101,7 +82,7 @@ export class CustomerService {
101
82
  const afterHooks = this.deps.hooks.resolve(
102
83
  "customers.afterCreate",
103
84
  ) as AfterHook<Customer>[];
104
- const hctx = hookContext(actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
85
+ const hctx = createModuleHookContext("customers", this.deps, actor ?? null, ctx?.tx ?? null);
105
86
  await runAfterHooks(afterHooks, null, customer, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
106
87
 
107
88
  return Ok(customer);
@@ -202,7 +183,7 @@ export class CustomerService {
202
183
  const afterHooks = this.deps.hooks.resolve(
203
184
  "customers.afterCreate",
204
185
  ) as AfterHook<Customer>[];
205
- const hctx = hookContext(actor, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
186
+ const hctx = createModuleHookContext("customers", this.deps, actor, ctx?.tx ?? null);
206
187
  await runAfterHooks(afterHooks, null, customer, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
207
188
 
208
189
  return customer;
@@ -282,9 +263,7 @@ export class CustomerService {
282
263
  const afterHooks = this.deps.hooks.resolve(
283
264
  "customers.afterUpdate",
284
265
  ) as AfterHook<Customer>[];
285
- const hctx = hookContext(
286
- actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null,
287
- );
266
+ const hctx = createModuleHookContext("customers", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
288
267
  await runAfterHooks(afterHooks, existing, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
289
268
 
290
269
  return Ok(updated);
@@ -315,7 +294,7 @@ export class CustomerService {
315
294
  const afterHooks = this.deps.hooks.resolve(
316
295
  "customers.afterUpdate",
317
296
  ) as AfterHook<Customer>[];
318
- const hctx = hookContext(resolvedActor, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null);
297
+ const hctx = createModuleHookContext("customers", this.deps, resolvedActor, ctx?.tx ?? null);
319
298
  await runAfterHooks(afterHooks, customer, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
320
299
 
321
300
  return Ok(updated);
@@ -1,5 +1,7 @@
1
1
  import type { HydratedOrder } from "../orders/service.js";
2
2
  import { A4, type PdfTextOp } from "./pdf.js";
3
+ import { escapeHtml } from "../../utils/escape-html.js";
4
+ import { formatAmount } from "../../utils/money.js";
3
5
 
4
6
  /** Branding values read from the settings module's `branding` group. */
5
7
  export interface DocumentBranding {
@@ -19,25 +21,6 @@ export interface DocumentContext {
19
21
  invoiceNumber: string;
20
22
  }
21
23
 
22
- export function escapeHtml(value: unknown): string {
23
- return String(value ?? "")
24
- .replaceAll("&", "&amp;")
25
- .replaceAll("<", "&lt;")
26
- .replaceAll(">", "&gt;")
27
- .replaceAll('"', "&quot;")
28
- .replaceAll("'", "&#39;");
29
- }
30
-
31
- /** Minor units → "1,234.50 LKR". */
32
- export function formatAmount(minor: number, currency: string): string {
33
- const major = minor / 100;
34
- const formatted = major.toLocaleString("en-US", {
35
- minimumFractionDigits: 2,
36
- maximumFractionDigits: 2,
37
- });
38
- return `${formatted} ${currency}`;
39
- }
40
-
41
24
  function formatDate(date: Date | string | null | undefined): string {
42
25
  if (!date) return "";
43
26
  const d = typeof date === "string" ? new Date(date) : date;