@unifiedcommerce/core 0.0.1

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 (749) hide show
  1. package/dist/adapters/console-email.d.ts +23 -0
  2. package/dist/adapters/console-email.d.ts.map +1 -0
  3. package/dist/adapters/console-email.js +38 -0
  4. package/dist/auth/access.d.ts +101 -0
  5. package/dist/auth/access.d.ts.map +1 -0
  6. package/dist/auth/access.js +128 -0
  7. package/dist/auth/auth-schema.d.ts +1383 -0
  8. package/dist/auth/auth-schema.d.ts.map +1 -0
  9. package/dist/auth/auth-schema.js +117 -0
  10. package/dist/auth/middleware.d.ts +5 -0
  11. package/dist/auth/middleware.d.ts.map +1 -0
  12. package/dist/auth/middleware.js +91 -0
  13. package/dist/auth/org.d.ts +22 -0
  14. package/dist/auth/org.d.ts.map +1 -0
  15. package/dist/auth/org.js +36 -0
  16. package/dist/auth/permissions.d.ts +4 -0
  17. package/dist/auth/permissions.d.ts.map +1 -0
  18. package/dist/auth/permissions.js +24 -0
  19. package/dist/auth/pos.d.ts +3 -0
  20. package/dist/auth/pos.d.ts.map +1 -0
  21. package/dist/auth/pos.js +62 -0
  22. package/dist/auth/setup.d.ts +31 -0
  23. package/dist/auth/setup.d.ts.map +1 -0
  24. package/dist/auth/setup.js +106 -0
  25. package/dist/auth/system-actor.d.ts +7 -0
  26. package/dist/auth/system-actor.d.ts.map +1 -0
  27. package/dist/auth/system-actor.js +17 -0
  28. package/dist/auth/types.d.ts +11 -0
  29. package/dist/auth/types.d.ts.map +1 -0
  30. package/dist/auth/types.js +1 -0
  31. package/dist/config/defaults.d.ts +3 -0
  32. package/dist/config/defaults.d.ts.map +1 -0
  33. package/dist/config/defaults.js +80 -0
  34. package/dist/config/define-config.d.ts +9 -0
  35. package/dist/config/define-config.d.ts.map +1 -0
  36. package/dist/config/define-config.js +44 -0
  37. package/dist/config/types.d.ts +299 -0
  38. package/dist/config/types.d.ts.map +1 -0
  39. package/dist/config/types.js +1 -0
  40. package/dist/generated/plugin-manifest.d.ts +48 -0
  41. package/dist/generated/plugin-manifest.d.ts.map +1 -0
  42. package/dist/generated/plugin-manifest.js +20 -0
  43. package/dist/hooks/checkout-completion.d.ts +58 -0
  44. package/dist/hooks/checkout-completion.d.ts.map +1 -0
  45. package/dist/hooks/checkout-completion.js +137 -0
  46. package/dist/hooks/checkout.d.ts +99 -0
  47. package/dist/hooks/checkout.d.ts.map +1 -0
  48. package/dist/hooks/checkout.js +317 -0
  49. package/dist/hooks/order-emails.d.ts +16 -0
  50. package/dist/hooks/order-emails.d.ts.map +1 -0
  51. package/dist/hooks/order-emails.js +44 -0
  52. package/dist/index.d.ts +82 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +13381 -0
  55. package/dist/index.js.map +156 -0
  56. package/dist/interfaces/graphql/index.d.ts +4 -0
  57. package/dist/interfaces/graphql/index.d.ts.map +1 -0
  58. package/dist/interfaces/graphql/index.js +415 -0
  59. package/dist/interfaces/mcp/agent-prompt.d.ts +16 -0
  60. package/dist/interfaces/mcp/agent-prompt.d.ts.map +1 -0
  61. package/dist/interfaces/mcp/agent-prompt.js +172 -0
  62. package/dist/interfaces/mcp/context-enrichment.d.ts +39 -0
  63. package/dist/interfaces/mcp/context-enrichment.d.ts.map +1 -0
  64. package/dist/interfaces/mcp/context-enrichment.js +119 -0
  65. package/dist/interfaces/mcp/server.d.ts +7 -0
  66. package/dist/interfaces/mcp/server.d.ts.map +1 -0
  67. package/dist/interfaces/mcp/server.js +515 -0
  68. package/dist/interfaces/mcp/transport.d.ts +5 -0
  69. package/dist/interfaces/mcp/transport.d.ts.map +1 -0
  70. package/dist/interfaces/mcp/transport.js +52 -0
  71. package/dist/interfaces/rest/customer-portal.d.ts +5 -0
  72. package/dist/interfaces/rest/customer-portal.d.ts.map +1 -0
  73. package/dist/interfaces/rest/customer-portal.js +206 -0
  74. package/dist/interfaces/rest/index.d.ts +5 -0
  75. package/dist/interfaces/rest/index.d.ts.map +1 -0
  76. package/dist/interfaces/rest/index.js +68 -0
  77. package/dist/interfaces/rest/router.d.ts +164 -0
  78. package/dist/interfaces/rest/router.d.ts.map +1 -0
  79. package/dist/interfaces/rest/router.js +259 -0
  80. package/dist/interfaces/rest/routes/admin-jobs.d.ts +5 -0
  81. package/dist/interfaces/rest/routes/admin-jobs.d.ts.map +1 -0
  82. package/dist/interfaces/rest/routes/admin-jobs.js +48 -0
  83. package/dist/interfaces/rest/routes/audit.d.ts +5 -0
  84. package/dist/interfaces/rest/routes/audit.d.ts.map +1 -0
  85. package/dist/interfaces/rest/routes/audit.js +43 -0
  86. package/dist/interfaces/rest/routes/carts.d.ts +5 -0
  87. package/dist/interfaces/rest/routes/carts.d.ts.map +1 -0
  88. package/dist/interfaces/rest/routes/carts.js +55 -0
  89. package/dist/interfaces/rest/routes/catalog.d.ts +5 -0
  90. package/dist/interfaces/rest/routes/catalog.d.ts.map +1 -0
  91. package/dist/interfaces/rest/routes/catalog.js +256 -0
  92. package/dist/interfaces/rest/routes/checkout.d.ts +5 -0
  93. package/dist/interfaces/rest/routes/checkout.d.ts.map +1 -0
  94. package/dist/interfaces/rest/routes/checkout.js +216 -0
  95. package/dist/interfaces/rest/routes/inventory.d.ts +5 -0
  96. package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -0
  97. package/dist/interfaces/rest/routes/inventory.js +59 -0
  98. package/dist/interfaces/rest/routes/media.d.ts +5 -0
  99. package/dist/interfaces/rest/routes/media.d.ts.map +1 -0
  100. package/dist/interfaces/rest/routes/media.js +65 -0
  101. package/dist/interfaces/rest/routes/orders.d.ts +5 -0
  102. package/dist/interfaces/rest/routes/orders.d.ts.map +1 -0
  103. package/dist/interfaces/rest/routes/orders.js +64 -0
  104. package/dist/interfaces/rest/routes/payments.d.ts +5 -0
  105. package/dist/interfaces/rest/routes/payments.d.ts.map +1 -0
  106. package/dist/interfaces/rest/routes/payments.js +45 -0
  107. package/dist/interfaces/rest/routes/pricing.d.ts +5 -0
  108. package/dist/interfaces/rest/routes/pricing.d.ts.map +1 -0
  109. package/dist/interfaces/rest/routes/pricing.js +48 -0
  110. package/dist/interfaces/rest/routes/promotions.d.ts +5 -0
  111. package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -0
  112. package/dist/interfaces/rest/routes/promotions.js +75 -0
  113. package/dist/interfaces/rest/routes/search.d.ts +5 -0
  114. package/dist/interfaces/rest/routes/search.d.ts.map +1 -0
  115. package/dist/interfaces/rest/routes/search.js +60 -0
  116. package/dist/interfaces/rest/routes/webhooks.d.ts +5 -0
  117. package/dist/interfaces/rest/routes/webhooks.d.ts.map +1 -0
  118. package/dist/interfaces/rest/routes/webhooks.js +39 -0
  119. package/dist/interfaces/rest/schemas/admin-jobs.d.ts +327 -0
  120. package/dist/interfaces/rest/schemas/admin-jobs.d.ts.map +1 -0
  121. package/dist/interfaces/rest/schemas/admin-jobs.js +37 -0
  122. package/dist/interfaces/rest/schemas/audit.d.ts +59 -0
  123. package/dist/interfaces/rest/schemas/audit.d.ts.map +1 -0
  124. package/dist/interfaces/rest/schemas/audit.js +43 -0
  125. package/dist/interfaces/rest/schemas/carts.d.ts +1446 -0
  126. package/dist/interfaces/rest/schemas/carts.d.ts.map +1 -0
  127. package/dist/interfaces/rest/schemas/carts.js +109 -0
  128. package/dist/interfaces/rest/schemas/catalog.d.ts +5416 -0
  129. package/dist/interfaces/rest/schemas/catalog.d.ts.map +1 -0
  130. package/dist/interfaces/rest/schemas/catalog.js +397 -0
  131. package/dist/interfaces/rest/schemas/checkout.d.ts +160 -0
  132. package/dist/interfaces/rest/schemas/checkout.d.ts.map +1 -0
  133. package/dist/interfaces/rest/schemas/checkout.js +60 -0
  134. package/dist/interfaces/rest/schemas/customer-portal.d.ts +2197 -0
  135. package/dist/interfaces/rest/schemas/customer-portal.d.ts.map +1 -0
  136. package/dist/interfaces/rest/schemas/customer-portal.js +177 -0
  137. package/dist/interfaces/rest/schemas/inventory.d.ts +469 -0
  138. package/dist/interfaces/rest/schemas/inventory.d.ts.map +1 -0
  139. package/dist/interfaces/rest/schemas/inventory.js +128 -0
  140. package/dist/interfaces/rest/schemas/media.d.ts +303 -0
  141. package/dist/interfaces/rest/schemas/media.d.ts.map +1 -0
  142. package/dist/interfaces/rest/schemas/media.js +69 -0
  143. package/dist/interfaces/rest/schemas/orders.d.ts +1782 -0
  144. package/dist/interfaces/rest/schemas/orders.d.ts.map +1 -0
  145. package/dist/interfaces/rest/schemas/orders.js +93 -0
  146. package/dist/interfaces/rest/schemas/pricing.d.ts +256 -0
  147. package/dist/interfaces/rest/schemas/pricing.d.ts.map +1 -0
  148. package/dist/interfaces/rest/schemas/pricing.js +72 -0
  149. package/dist/interfaces/rest/schemas/promotions.d.ts +363 -0
  150. package/dist/interfaces/rest/schemas/promotions.d.ts.map +1 -0
  151. package/dist/interfaces/rest/schemas/promotions.js +98 -0
  152. package/dist/interfaces/rest/schemas/responses.d.ts +4062 -0
  153. package/dist/interfaces/rest/schemas/responses.d.ts.map +1 -0
  154. package/dist/interfaces/rest/schemas/responses.js +63 -0
  155. package/dist/interfaces/rest/schemas/search.d.ts +245 -0
  156. package/dist/interfaces/rest/schemas/search.d.ts.map +1 -0
  157. package/dist/interfaces/rest/schemas/search.js +55 -0
  158. package/dist/interfaces/rest/schemas/shared.d.ts +95 -0
  159. package/dist/interfaces/rest/schemas/shared.d.ts.map +1 -0
  160. package/dist/interfaces/rest/schemas/shared.js +51 -0
  161. package/dist/interfaces/rest/schemas/webhooks.d.ts +221 -0
  162. package/dist/interfaces/rest/schemas/webhooks.d.ts.map +1 -0
  163. package/dist/interfaces/rest/schemas/webhooks.js +62 -0
  164. package/dist/interfaces/rest/utils.d.ts +45 -0
  165. package/dist/interfaces/rest/utils.d.ts.map +1 -0
  166. package/dist/interfaces/rest/utils.js +71 -0
  167. package/dist/interfaces/rest/webhook-router.d.ts +41 -0
  168. package/dist/interfaces/rest/webhook-router.d.ts.map +1 -0
  169. package/dist/interfaces/rest/webhook-router.js +36 -0
  170. package/dist/kernel/compensation/executor.d.ts +21 -0
  171. package/dist/kernel/compensation/executor.d.ts.map +1 -0
  172. package/dist/kernel/compensation/executor.js +36 -0
  173. package/dist/kernel/compensation/types.d.ts +25 -0
  174. package/dist/kernel/compensation/types.d.ts.map +1 -0
  175. package/dist/kernel/compensation/types.js +1 -0
  176. package/dist/kernel/database/adapter.d.ts +10 -0
  177. package/dist/kernel/database/adapter.d.ts.map +1 -0
  178. package/dist/kernel/database/adapter.js +3 -0
  179. package/dist/kernel/database/drizzle-db.d.ts +49 -0
  180. package/dist/kernel/database/drizzle-db.d.ts.map +1 -0
  181. package/dist/kernel/database/drizzle-db.js +20 -0
  182. package/dist/kernel/database/migrate.d.ts +38 -0
  183. package/dist/kernel/database/migrate.d.ts.map +1 -0
  184. package/dist/kernel/database/migrate.js +61 -0
  185. package/dist/kernel/database/plugin-types.d.ts +32 -0
  186. package/dist/kernel/database/plugin-types.d.ts.map +1 -0
  187. package/dist/kernel/database/plugin-types.js +10 -0
  188. package/dist/kernel/database/schema.d.ts +24 -0
  189. package/dist/kernel/database/schema.d.ts.map +1 -0
  190. package/dist/kernel/database/schema.js +36 -0
  191. package/dist/kernel/database/scoped-db.d.ts +20 -0
  192. package/dist/kernel/database/scoped-db.d.ts.map +1 -0
  193. package/dist/kernel/database/scoped-db.js +62 -0
  194. package/dist/kernel/database/tx-context.d.ts +15 -0
  195. package/dist/kernel/database/tx-context.d.ts.map +1 -0
  196. package/dist/kernel/database/tx-context.js +19 -0
  197. package/dist/kernel/error-mapper.d.ts +3 -0
  198. package/dist/kernel/error-mapper.d.ts.map +1 -0
  199. package/dist/kernel/error-mapper.js +12 -0
  200. package/dist/kernel/errors.d.ts +38 -0
  201. package/dist/kernel/errors.d.ts.map +1 -0
  202. package/dist/kernel/errors.js +69 -0
  203. package/dist/kernel/factory/in-memory-repository-factory.d.ts +20 -0
  204. package/dist/kernel/factory/in-memory-repository-factory.d.ts.map +1 -0
  205. package/dist/kernel/factory/in-memory-repository-factory.js +83 -0
  206. package/dist/kernel/factory/repository-factory.d.ts +71 -0
  207. package/dist/kernel/factory/repository-factory.d.ts.map +1 -0
  208. package/dist/kernel/factory/repository-factory.js +136 -0
  209. package/dist/kernel/hooks/create-context.d.ts +25 -0
  210. package/dist/kernel/hooks/create-context.d.ts.map +1 -0
  211. package/dist/kernel/hooks/create-context.js +22 -0
  212. package/dist/kernel/hooks/executor.d.ts +12 -0
  213. package/dist/kernel/hooks/executor.d.ts.map +1 -0
  214. package/dist/kernel/hooks/executor.js +50 -0
  215. package/dist/kernel/hooks/registry.d.ts +28 -0
  216. package/dist/kernel/hooks/registry.d.ts.map +1 -0
  217. package/dist/kernel/hooks/registry.js +58 -0
  218. package/dist/kernel/hooks/types.d.ts +37 -0
  219. package/dist/kernel/hooks/types.d.ts.map +1 -0
  220. package/dist/kernel/hooks/types.js +1 -0
  221. package/dist/kernel/http-error.d.ts +30 -0
  222. package/dist/kernel/http-error.d.ts.map +1 -0
  223. package/dist/kernel/http-error.js +35 -0
  224. package/dist/kernel/jobs/adapter.d.ts +25 -0
  225. package/dist/kernel/jobs/adapter.d.ts.map +1 -0
  226. package/dist/kernel/jobs/adapter.js +9 -0
  227. package/dist/kernel/jobs/drizzle-adapter.d.ts +15 -0
  228. package/dist/kernel/jobs/drizzle-adapter.d.ts.map +1 -0
  229. package/dist/kernel/jobs/drizzle-adapter.js +42 -0
  230. package/dist/kernel/jobs/runner.d.ts +24 -0
  231. package/dist/kernel/jobs/runner.d.ts.map +1 -0
  232. package/dist/kernel/jobs/runner.js +114 -0
  233. package/dist/kernel/jobs/schema.d.ts +280 -0
  234. package/dist/kernel/jobs/schema.d.ts.map +1 -0
  235. package/dist/kernel/jobs/schema.js +37 -0
  236. package/dist/kernel/jobs/types.d.ts +30 -0
  237. package/dist/kernel/jobs/types.d.ts.map +1 -0
  238. package/dist/kernel/jobs/types.js +1 -0
  239. package/dist/kernel/local-api.d.ts +103 -0
  240. package/dist/kernel/local-api.d.ts.map +1 -0
  241. package/dist/kernel/local-api.js +87 -0
  242. package/dist/kernel/plugin/capability-registry.d.ts +9 -0
  243. package/dist/kernel/plugin/capability-registry.d.ts.map +1 -0
  244. package/dist/kernel/plugin/capability-registry.js +28 -0
  245. package/dist/kernel/plugin/dependency-graph.d.ts +6 -0
  246. package/dist/kernel/plugin/dependency-graph.d.ts.map +1 -0
  247. package/dist/kernel/plugin/dependency-graph.js +55 -0
  248. package/dist/kernel/plugin/manifest.d.ts +90 -0
  249. package/dist/kernel/plugin/manifest.d.ts.map +1 -0
  250. package/dist/kernel/plugin/manifest.js +140 -0
  251. package/dist/kernel/query/executor.d.ts +21 -0
  252. package/dist/kernel/query/executor.d.ts.map +1 -0
  253. package/dist/kernel/query/executor.js +128 -0
  254. package/dist/kernel/query/registry.d.ts +33 -0
  255. package/dist/kernel/query/registry.d.ts.map +1 -0
  256. package/dist/kernel/query/registry.js +20 -0
  257. package/dist/kernel/result.d.ts +36 -0
  258. package/dist/kernel/result.d.ts.map +1 -0
  259. package/dist/kernel/result.js +16 -0
  260. package/dist/kernel/schema/extra-columns.d.ts +23 -0
  261. package/dist/kernel/schema/extra-columns.d.ts.map +1 -0
  262. package/dist/kernel/schema/extra-columns.js +10 -0
  263. package/dist/kernel/service-registry.d.ts +109 -0
  264. package/dist/kernel/service-registry.d.ts.map +1 -0
  265. package/dist/kernel/service-registry.js +26 -0
  266. package/dist/kernel/service-timing.d.ts +25 -0
  267. package/dist/kernel/service-timing.d.ts.map +1 -0
  268. package/dist/kernel/service-timing.js +62 -0
  269. package/dist/kernel/state-machine/machine.d.ts +24 -0
  270. package/dist/kernel/state-machine/machine.d.ts.map +1 -0
  271. package/dist/kernel/state-machine/machine.js +70 -0
  272. package/dist/modules/analytics/cubes.d.ts +19 -0
  273. package/dist/modules/analytics/cubes.d.ts.map +1 -0
  274. package/dist/modules/analytics/cubes.js +187 -0
  275. package/dist/modules/analytics/drizzle-adapter.d.ts +13 -0
  276. package/dist/modules/analytics/drizzle-adapter.d.ts.map +1 -0
  277. package/dist/modules/analytics/drizzle-adapter.js +358 -0
  278. package/dist/modules/analytics/hooks.d.ts +13 -0
  279. package/dist/modules/analytics/hooks.d.ts.map +1 -0
  280. package/dist/modules/analytics/hooks.js +12 -0
  281. package/dist/modules/analytics/models.d.ts +14 -0
  282. package/dist/modules/analytics/models.d.ts.map +1 -0
  283. package/dist/modules/analytics/models.js +118 -0
  284. package/dist/modules/analytics/repository/index.d.ts +5 -0
  285. package/dist/modules/analytics/repository/index.d.ts.map +1 -0
  286. package/dist/modules/analytics/repository/index.js +1 -0
  287. package/dist/modules/analytics/service.d.ts +45 -0
  288. package/dist/modules/analytics/service.d.ts.map +1 -0
  289. package/dist/modules/analytics/service.js +196 -0
  290. package/dist/modules/analytics/types.d.ts +119 -0
  291. package/dist/modules/analytics/types.d.ts.map +1 -0
  292. package/dist/modules/analytics/types.js +25 -0
  293. package/dist/modules/audit/hooks.d.ts +7 -0
  294. package/dist/modules/audit/hooks.d.ts.map +1 -0
  295. package/dist/modules/audit/hooks.js +67 -0
  296. package/dist/modules/audit/schema.d.ts +178 -0
  297. package/dist/modules/audit/schema.d.ts.map +1 -0
  298. package/dist/modules/audit/schema.js +21 -0
  299. package/dist/modules/audit/service.d.ts +38 -0
  300. package/dist/modules/audit/service.d.ts.map +1 -0
  301. package/dist/modules/audit/service.js +109 -0
  302. package/dist/modules/cart/access.d.ts +11 -0
  303. package/dist/modules/cart/access.d.ts.map +1 -0
  304. package/dist/modules/cart/access.js +18 -0
  305. package/dist/modules/cart/matcher.d.ts +20 -0
  306. package/dist/modules/cart/matcher.d.ts.map +1 -0
  307. package/dist/modules/cart/matcher.js +2 -0
  308. package/dist/modules/cart/repository/in-memory.d.ts +30 -0
  309. package/dist/modules/cart/repository/in-memory.d.ts.map +1 -0
  310. package/dist/modules/cart/repository/in-memory.js +159 -0
  311. package/dist/modules/cart/repository/index.d.ts +45 -0
  312. package/dist/modules/cart/repository/index.d.ts.map +1 -0
  313. package/dist/modules/cart/repository/index.js +158 -0
  314. package/dist/modules/cart/schema.d.ts +359 -0
  315. package/dist/modules/cart/schema.d.ts.map +1 -0
  316. package/dist/modules/cart/schema.js +40 -0
  317. package/dist/modules/cart/schemas.d.ts +29 -0
  318. package/dist/modules/cart/schemas.d.ts.map +1 -0
  319. package/dist/modules/cart/schemas.js +14 -0
  320. package/dist/modules/cart/service.d.ts +63 -0
  321. package/dist/modules/cart/service.d.ts.map +1 -0
  322. package/dist/modules/cart/service.js +339 -0
  323. package/dist/modules/catalog/repository/in-memory.d.ts +82 -0
  324. package/dist/modules/catalog/repository/in-memory.d.ts.map +1 -0
  325. package/dist/modules/catalog/repository/in-memory.js +444 -0
  326. package/dist/modules/catalog/repository/index.d.ts +106 -0
  327. package/dist/modules/catalog/repository/index.d.ts.map +1 -0
  328. package/dist/modules/catalog/repository/index.js +455 -0
  329. package/dist/modules/catalog/schema.d.ts +1193 -0
  330. package/dist/modules/catalog/schema.d.ts.map +1 -0
  331. package/dist/modules/catalog/schema.js +149 -0
  332. package/dist/modules/catalog/schemas.d.ts +81 -0
  333. package/dist/modules/catalog/schemas.d.ts.map +1 -0
  334. package/dist/modules/catalog/schemas.js +62 -0
  335. package/dist/modules/catalog/service.d.ts +160 -0
  336. package/dist/modules/catalog/service.d.ts.map +1 -0
  337. package/dist/modules/catalog/service.js +759 -0
  338. package/dist/modules/customers/repository/in-memory.d.ts +37 -0
  339. package/dist/modules/customers/repository/in-memory.d.ts.map +1 -0
  340. package/dist/modules/customers/repository/in-memory.js +278 -0
  341. package/dist/modules/customers/repository/index.d.ts +47 -0
  342. package/dist/modules/customers/repository/index.d.ts.map +1 -0
  343. package/dist/modules/customers/repository/index.js +206 -0
  344. package/dist/modules/customers/schema.d.ts +560 -0
  345. package/dist/modules/customers/schema.d.ts.map +1 -0
  346. package/dist/modules/customers/schema.js +60 -0
  347. package/dist/modules/customers/service.d.ts +25 -0
  348. package/dist/modules/customers/service.d.ts.map +1 -0
  349. package/dist/modules/customers/service.js +91 -0
  350. package/dist/modules/fulfillment/repository/in-memory.d.ts +53 -0
  351. package/dist/modules/fulfillment/repository/in-memory.d.ts.map +1 -0
  352. package/dist/modules/fulfillment/repository/in-memory.js +327 -0
  353. package/dist/modules/fulfillment/repository/index.d.ts +63 -0
  354. package/dist/modules/fulfillment/repository/index.d.ts.map +1 -0
  355. package/dist/modules/fulfillment/repository/index.js +268 -0
  356. package/dist/modules/fulfillment/schema.d.ts +655 -0
  357. package/dist/modules/fulfillment/schema.d.ts.map +1 -0
  358. package/dist/modules/fulfillment/schema.js +83 -0
  359. package/dist/modules/fulfillment/service.d.ts +58 -0
  360. package/dist/modules/fulfillment/service.d.ts.map +1 -0
  361. package/dist/modules/fulfillment/service.js +338 -0
  362. package/dist/modules/fulfillment/types.d.ts +44 -0
  363. package/dist/modules/fulfillment/types.d.ts.map +1 -0
  364. package/dist/modules/fulfillment/types.js +1 -0
  365. package/dist/modules/inventory/repository/in-memory.d.ts +51 -0
  366. package/dist/modules/inventory/repository/in-memory.d.ts.map +1 -0
  367. package/dist/modules/inventory/repository/in-memory.js +281 -0
  368. package/dist/modules/inventory/repository/index.d.ts +81 -0
  369. package/dist/modules/inventory/repository/index.d.ts.map +1 -0
  370. package/dist/modules/inventory/repository/index.js +310 -0
  371. package/dist/modules/inventory/schema.d.ts +570 -0
  372. package/dist/modules/inventory/schema.d.ts.map +1 -0
  373. package/dist/modules/inventory/schema.js +69 -0
  374. package/dist/modules/inventory/schemas.d.ts +31 -0
  375. package/dist/modules/inventory/schemas.d.ts.map +1 -0
  376. package/dist/modules/inventory/schemas.js +28 -0
  377. package/dist/modules/inventory/service.d.ts +65 -0
  378. package/dist/modules/inventory/service.d.ts.map +1 -0
  379. package/dist/modules/inventory/service.js +271 -0
  380. package/dist/modules/media/adapter.d.ts +16 -0
  381. package/dist/modules/media/adapter.d.ts.map +1 -0
  382. package/dist/modules/media/adapter.js +1 -0
  383. package/dist/modules/media/repository/in-memory.d.ts +26 -0
  384. package/dist/modules/media/repository/in-memory.d.ts.map +1 -0
  385. package/dist/modules/media/repository/in-memory.js +145 -0
  386. package/dist/modules/media/repository/index.d.ts +35 -0
  387. package/dist/modules/media/repository/index.d.ts.map +1 -0
  388. package/dist/modules/media/repository/index.js +176 -0
  389. package/dist/modules/media/schema.d.ts +289 -0
  390. package/dist/modules/media/schema.d.ts.map +1 -0
  391. package/dist/modules/media/schema.js +35 -0
  392. package/dist/modules/media/service.d.ts +42 -0
  393. package/dist/modules/media/service.d.ts.map +1 -0
  394. package/dist/modules/media/service.js +89 -0
  395. package/dist/modules/orders/repository/in-memory.d.ts +40 -0
  396. package/dist/modules/orders/repository/in-memory.d.ts.map +1 -0
  397. package/dist/modules/orders/repository/in-memory.js +245 -0
  398. package/dist/modules/orders/repository/index.d.ts +48 -0
  399. package/dist/modules/orders/repository/index.d.ts.map +1 -0
  400. package/dist/modules/orders/repository/index.js +199 -0
  401. package/dist/modules/orders/schema.d.ts +672 -0
  402. package/dist/modules/orders/schema.d.ts.map +1 -0
  403. package/dist/modules/orders/schema.js +63 -0
  404. package/dist/modules/orders/service.d.ts +85 -0
  405. package/dist/modules/orders/service.d.ts.map +1 -0
  406. package/dist/modules/orders/service.js +313 -0
  407. package/dist/modules/orders/stale-order-cleanup.d.ts +27 -0
  408. package/dist/modules/orders/stale-order-cleanup.d.ts.map +1 -0
  409. package/dist/modules/orders/stale-order-cleanup.js +55 -0
  410. package/dist/modules/organization/service.d.ts +53 -0
  411. package/dist/modules/organization/service.d.ts.map +1 -0
  412. package/dist/modules/organization/service.js +151 -0
  413. package/dist/modules/payments/adapter.d.ts +42 -0
  414. package/dist/modules/payments/adapter.d.ts.map +1 -0
  415. package/dist/modules/payments/adapter.js +1 -0
  416. package/dist/modules/payments/repository/index.d.ts +5 -0
  417. package/dist/modules/payments/repository/index.d.ts.map +1 -0
  418. package/dist/modules/payments/repository/index.js +1 -0
  419. package/dist/modules/payments/service.d.ts +23 -0
  420. package/dist/modules/payments/service.d.ts.map +1 -0
  421. package/dist/modules/payments/service.js +72 -0
  422. package/dist/modules/pricing/repository/in-memory.d.ts +25 -0
  423. package/dist/modules/pricing/repository/in-memory.d.ts.map +1 -0
  424. package/dist/modules/pricing/repository/in-memory.js +288 -0
  425. package/dist/modules/pricing/repository/index.d.ts +34 -0
  426. package/dist/modules/pricing/repository/index.d.ts.map +1 -0
  427. package/dist/modules/pricing/repository/index.js +176 -0
  428. package/dist/modules/pricing/schema.d.ts +565 -0
  429. package/dist/modules/pricing/schema.d.ts.map +1 -0
  430. package/dist/modules/pricing/schema.js +57 -0
  431. package/dist/modules/pricing/schemas.d.ts +37 -0
  432. package/dist/modules/pricing/schemas.d.ts.map +1 -0
  433. package/dist/modules/pricing/schemas.js +30 -0
  434. package/dist/modules/pricing/service.d.ts +62 -0
  435. package/dist/modules/pricing/service.d.ts.map +1 -0
  436. package/dist/modules/pricing/service.js +308 -0
  437. package/dist/modules/promotions/repository/in-memory.d.ts +32 -0
  438. package/dist/modules/promotions/repository/in-memory.d.ts.map +1 -0
  439. package/dist/modules/promotions/repository/in-memory.js +227 -0
  440. package/dist/modules/promotions/repository/index.d.ts +41 -0
  441. package/dist/modules/promotions/repository/index.d.ts.map +1 -0
  442. package/dist/modules/promotions/repository/index.js +204 -0
  443. package/dist/modules/promotions/schema.d.ts +427 -0
  444. package/dist/modules/promotions/schema.d.ts.map +1 -0
  445. package/dist/modules/promotions/schema.js +52 -0
  446. package/dist/modules/promotions/schemas.d.ts +33 -0
  447. package/dist/modules/promotions/schemas.d.ts.map +1 -0
  448. package/dist/modules/promotions/schemas.js +32 -0
  449. package/dist/modules/promotions/service.d.ts +80 -0
  450. package/dist/modules/promotions/service.d.ts.map +1 -0
  451. package/dist/modules/promotions/service.js +347 -0
  452. package/dist/modules/search/adapter.d.ts +51 -0
  453. package/dist/modules/search/adapter.d.ts.map +1 -0
  454. package/dist/modules/search/adapter.js +1 -0
  455. package/dist/modules/search/hooks.d.ts +8 -0
  456. package/dist/modules/search/hooks.d.ts.map +1 -0
  457. package/dist/modules/search/hooks.js +6 -0
  458. package/dist/modules/search/repository/index.d.ts +5 -0
  459. package/dist/modules/search/repository/index.d.ts.map +1 -0
  460. package/dist/modules/search/repository/index.js +1 -0
  461. package/dist/modules/search/service.d.ts +24 -0
  462. package/dist/modules/search/service.d.ts.map +1 -0
  463. package/dist/modules/search/service.js +217 -0
  464. package/dist/modules/shipping/calculator.d.ts +42 -0
  465. package/dist/modules/shipping/calculator.d.ts.map +1 -0
  466. package/dist/modules/shipping/calculator.js +91 -0
  467. package/dist/modules/shipping/repository/index.d.ts +5 -0
  468. package/dist/modules/shipping/repository/index.d.ts.map +1 -0
  469. package/dist/modules/shipping/repository/index.js +1 -0
  470. package/dist/modules/shipping/service.d.ts +28 -0
  471. package/dist/modules/shipping/service.d.ts.map +1 -0
  472. package/dist/modules/shipping/service.js +20 -0
  473. package/dist/modules/tax/adapter.d.ts +58 -0
  474. package/dist/modules/tax/adapter.d.ts.map +1 -0
  475. package/dist/modules/tax/adapter.js +1 -0
  476. package/dist/modules/tax/repository/index.d.ts +5 -0
  477. package/dist/modules/tax/repository/index.d.ts.map +1 -0
  478. package/dist/modules/tax/repository/index.js +1 -0
  479. package/dist/modules/tax/service.d.ts +19 -0
  480. package/dist/modules/tax/service.d.ts.map +1 -0
  481. package/dist/modules/tax/service.js +34 -0
  482. package/dist/modules/webhooks/hook.d.ts +13 -0
  483. package/dist/modules/webhooks/hook.d.ts.map +1 -0
  484. package/dist/modules/webhooks/hook.js +29 -0
  485. package/dist/modules/webhooks/repository/in-memory.d.ts +31 -0
  486. package/dist/modules/webhooks/repository/in-memory.d.ts.map +1 -0
  487. package/dist/modules/webhooks/repository/in-memory.js +187 -0
  488. package/dist/modules/webhooks/repository/index.d.ts +40 -0
  489. package/dist/modules/webhooks/repository/index.d.ts.map +1 -0
  490. package/dist/modules/webhooks/repository/index.js +175 -0
  491. package/dist/modules/webhooks/schema.d.ts +404 -0
  492. package/dist/modules/webhooks/schema.d.ts.map +1 -0
  493. package/dist/modules/webhooks/schema.js +40 -0
  494. package/dist/modules/webhooks/service.d.ts +23 -0
  495. package/dist/modules/webhooks/service.d.ts.map +1 -0
  496. package/dist/modules/webhooks/service.js +92 -0
  497. package/dist/modules/webhooks/signing.d.ts +2 -0
  498. package/dist/modules/webhooks/signing.d.ts.map +1 -0
  499. package/dist/modules/webhooks/signing.js +5 -0
  500. package/dist/modules/webhooks/ssrf-guard.d.ts +19 -0
  501. package/dist/modules/webhooks/ssrf-guard.d.ts.map +1 -0
  502. package/dist/modules/webhooks/ssrf-guard.js +79 -0
  503. package/dist/modules/webhooks/tasks.d.ts +16 -0
  504. package/dist/modules/webhooks/tasks.d.ts.map +1 -0
  505. package/dist/modules/webhooks/tasks.js +35 -0
  506. package/dist/modules/webhooks/worker.d.ts +21 -0
  507. package/dist/modules/webhooks/worker.d.ts.map +1 -0
  508. package/dist/modules/webhooks/worker.js +113 -0
  509. package/dist/runtime/commerce.d.ts +110 -0
  510. package/dist/runtime/commerce.d.ts.map +1 -0
  511. package/dist/runtime/commerce.js +37 -0
  512. package/dist/runtime/kernel.d.ts +72 -0
  513. package/dist/runtime/kernel.d.ts.map +1 -0
  514. package/dist/runtime/kernel.js +298 -0
  515. package/dist/runtime/logger.d.ts +11 -0
  516. package/dist/runtime/logger.d.ts.map +1 -0
  517. package/dist/runtime/logger.js +32 -0
  518. package/dist/runtime/server.d.ts +28 -0
  519. package/dist/runtime/server.d.ts.map +1 -0
  520. package/dist/runtime/server.js +277 -0
  521. package/dist/runtime/shutdown.d.ts +15 -0
  522. package/dist/runtime/shutdown.d.ts.map +1 -0
  523. package/dist/runtime/shutdown.js +34 -0
  524. package/dist/runtime/state-manager.d.ts +14 -0
  525. package/dist/runtime/state-manager.d.ts.map +1 -0
  526. package/dist/runtime/state-manager.js +84 -0
  527. package/dist/runtime/state-repository.d.ts +13 -0
  528. package/dist/runtime/state-repository.d.ts.map +1 -0
  529. package/dist/runtime/state-repository.js +160 -0
  530. package/dist/runtime/state.d.ts +382 -0
  531. package/dist/runtime/state.d.ts.map +1 -0
  532. package/dist/runtime/state.js +37 -0
  533. package/dist/runtime/store.d.ts +382 -0
  534. package/dist/runtime/store.d.ts.map +1 -0
  535. package/dist/runtime/store.js +37 -0
  536. package/dist/test-utils/create-pglite-adapter.d.ts +32 -0
  537. package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -0
  538. package/dist/test-utils/create-pglite-adapter.js +106 -0
  539. package/dist/test-utils/create-plugin-test-app.d.ts +50 -0
  540. package/dist/test-utils/create-plugin-test-app.d.ts.map +1 -0
  541. package/dist/test-utils/create-plugin-test-app.js +74 -0
  542. package/dist/test-utils/create-repository-test-harness.d.ts +8 -0
  543. package/dist/test-utils/create-repository-test-harness.d.ts.map +1 -0
  544. package/dist/test-utils/create-repository-test-harness.js +7 -0
  545. package/dist/test-utils/create-test-config.d.ts +18 -0
  546. package/dist/test-utils/create-test-config.d.ts.map +1 -0
  547. package/dist/test-utils/create-test-config.js +174 -0
  548. package/dist/test-utils/create-test-kernel.d.ts +3 -0
  549. package/dist/test-utils/create-test-kernel.d.ts.map +1 -0
  550. package/dist/test-utils/create-test-kernel.js +5 -0
  551. package/dist/test-utils/create-test-plugin-context.d.ts +42 -0
  552. package/dist/test-utils/create-test-plugin-context.d.ts.map +1 -0
  553. package/dist/test-utils/create-test-plugin-context.js +46 -0
  554. package/dist/test-utils/rest-api-test-utils.d.ts +64 -0
  555. package/dist/test-utils/rest-api-test-utils.d.ts.map +1 -0
  556. package/dist/test-utils/rest-api-test-utils.js +207 -0
  557. package/dist/test-utils/test-actors.d.ts +15 -0
  558. package/dist/test-utils/test-actors.d.ts.map +1 -0
  559. package/dist/test-utils/test-actors.js +57 -0
  560. package/dist/test-utils/typed-hooks.d.ts +43 -0
  561. package/dist/test-utils/typed-hooks.d.ts.map +1 -0
  562. package/dist/test-utils/typed-hooks.js +35 -0
  563. package/dist/tsconfig.tsbuildinfo +1 -0
  564. package/dist/types/commerce-types.d.ts +34 -0
  565. package/dist/types/commerce-types.d.ts.map +1 -0
  566. package/dist/types/commerce-types.js +1 -0
  567. package/dist/utils/id.d.ts +2 -0
  568. package/dist/utils/id.d.ts.map +1 -0
  569. package/dist/utils/id.js +3 -0
  570. package/dist/utils/logger.d.ts +3 -0
  571. package/dist/utils/logger.d.ts.map +1 -0
  572. package/dist/utils/logger.js +16 -0
  573. package/dist/utils/pagination.d.ts +11 -0
  574. package/dist/utils/pagination.d.ts.map +1 -0
  575. package/dist/utils/pagination.js +15 -0
  576. package/package.json +63 -0
  577. package/src/adapters/console-email.ts +43 -0
  578. package/src/auth/access.ts +187 -0
  579. package/src/auth/auth-schema.ts +131 -0
  580. package/src/auth/middleware.ts +115 -0
  581. package/src/auth/org.ts +41 -0
  582. package/src/auth/permissions.ts +28 -0
  583. package/src/auth/setup.ts +160 -0
  584. package/src/auth/system-actor.ts +19 -0
  585. package/src/auth/types.ts +10 -0
  586. package/src/config/defaults.ts +82 -0
  587. package/src/config/define-config.ts +53 -0
  588. package/src/config/types.ts +299 -0
  589. package/src/generated/plugin-capabilities.d.ts +20 -0
  590. package/src/generated/plugin-manifest.ts +23 -0
  591. package/src/generated/plugin-repositories.d.ts +20 -0
  592. package/src/hooks/checkout-completion.ts +262 -0
  593. package/src/hooks/checkout.ts +677 -0
  594. package/src/hooks/order-emails.ts +62 -0
  595. package/src/index.ts +214 -0
  596. package/src/interfaces/mcp/agent-prompt.ts +174 -0
  597. package/src/interfaces/mcp/context-enrichment.ts +177 -0
  598. package/src/interfaces/mcp/server.ts +617 -0
  599. package/src/interfaces/mcp/transport.ts +68 -0
  600. package/src/interfaces/rest/customer-portal.ts +299 -0
  601. package/src/interfaces/rest/index.ts +74 -0
  602. package/src/interfaces/rest/router.ts +334 -0
  603. package/src/interfaces/rest/routes/admin-jobs.ts +58 -0
  604. package/src/interfaces/rest/routes/audit.ts +50 -0
  605. package/src/interfaces/rest/routes/carts.ts +89 -0
  606. package/src/interfaces/rest/routes/catalog.ts +493 -0
  607. package/src/interfaces/rest/routes/checkout.ts +283 -0
  608. package/src/interfaces/rest/routes/inventory.ts +70 -0
  609. package/src/interfaces/rest/routes/media.ts +86 -0
  610. package/src/interfaces/rest/routes/orders.ts +78 -0
  611. package/src/interfaces/rest/routes/payments.ts +60 -0
  612. package/src/interfaces/rest/routes/pricing.ts +57 -0
  613. package/src/interfaces/rest/routes/promotions.ts +92 -0
  614. package/src/interfaces/rest/routes/search.ts +71 -0
  615. package/src/interfaces/rest/routes/webhooks.ts +46 -0
  616. package/src/interfaces/rest/schemas/admin-jobs.ts +40 -0
  617. package/src/interfaces/rest/schemas/audit.ts +46 -0
  618. package/src/interfaces/rest/schemas/carts.ts +125 -0
  619. package/src/interfaces/rest/schemas/catalog.ts +450 -0
  620. package/src/interfaces/rest/schemas/checkout.ts +66 -0
  621. package/src/interfaces/rest/schemas/customer-portal.ts +195 -0
  622. package/src/interfaces/rest/schemas/inventory.ts +138 -0
  623. package/src/interfaces/rest/schemas/media.ts +75 -0
  624. package/src/interfaces/rest/schemas/orders.ts +104 -0
  625. package/src/interfaces/rest/schemas/pricing.ts +80 -0
  626. package/src/interfaces/rest/schemas/promotions.ts +110 -0
  627. package/src/interfaces/rest/schemas/responses.ts +85 -0
  628. package/src/interfaces/rest/schemas/search.ts +58 -0
  629. package/src/interfaces/rest/schemas/shared.ts +62 -0
  630. package/src/interfaces/rest/schemas/webhooks.ts +68 -0
  631. package/src/interfaces/rest/utils.ts +104 -0
  632. package/src/interfaces/rest/webhook-router.ts +50 -0
  633. package/src/kernel/compensation/executor.ts +61 -0
  634. package/src/kernel/compensation/types.ts +26 -0
  635. package/src/kernel/database/adapter.ts +13 -0
  636. package/src/kernel/database/drizzle-db.ts +56 -0
  637. package/src/kernel/database/migrate.ts +76 -0
  638. package/src/kernel/database/plugin-types.ts +34 -0
  639. package/src/kernel/database/schema.ts +49 -0
  640. package/src/kernel/database/scoped-db.ts +68 -0
  641. package/src/kernel/database/tx-context.ts +46 -0
  642. package/src/kernel/error-mapper.ts +15 -0
  643. package/src/kernel/errors.ts +89 -0
  644. package/src/kernel/factory/repository-factory.ts +242 -0
  645. package/src/kernel/hooks/create-context.ts +43 -0
  646. package/src/kernel/hooks/executor.ts +88 -0
  647. package/src/kernel/hooks/registry.ts +74 -0
  648. package/src/kernel/hooks/types.ts +52 -0
  649. package/src/kernel/http-error.ts +44 -0
  650. package/src/kernel/jobs/adapter.ts +36 -0
  651. package/src/kernel/jobs/drizzle-adapter.ts +58 -0
  652. package/src/kernel/jobs/runner.ts +153 -0
  653. package/src/kernel/jobs/schema.ts +46 -0
  654. package/src/kernel/jobs/types.ts +30 -0
  655. package/src/kernel/local-api.ts +185 -0
  656. package/src/kernel/plugin/manifest.ts +253 -0
  657. package/src/kernel/query/executor.ts +184 -0
  658. package/src/kernel/query/registry.ts +46 -0
  659. package/src/kernel/result.ts +33 -0
  660. package/src/kernel/schema/extra-columns.ts +37 -0
  661. package/src/kernel/service-registry.ts +76 -0
  662. package/src/kernel/service-timing.ts +89 -0
  663. package/src/kernel/state-machine/machine.ts +101 -0
  664. package/src/modules/analytics/drizzle-adapter.ts +426 -0
  665. package/src/modules/analytics/hooks.ts +11 -0
  666. package/src/modules/analytics/models.ts +125 -0
  667. package/src/modules/analytics/repository/index.ts +6 -0
  668. package/src/modules/analytics/service.ts +245 -0
  669. package/src/modules/analytics/types.ts +180 -0
  670. package/src/modules/audit/hooks.ts +78 -0
  671. package/src/modules/audit/schema.ts +33 -0
  672. package/src/modules/audit/service.ts +151 -0
  673. package/src/modules/cart/access.ts +27 -0
  674. package/src/modules/cart/matcher.ts +26 -0
  675. package/src/modules/cart/repository/index.ts +234 -0
  676. package/src/modules/cart/schema.ts +42 -0
  677. package/src/modules/cart/schemas.ts +38 -0
  678. package/src/modules/cart/service.ts +541 -0
  679. package/src/modules/catalog/repository/index.ts +772 -0
  680. package/src/modules/catalog/schema.ts +203 -0
  681. package/src/modules/catalog/schemas.ts +104 -0
  682. package/src/modules/catalog/service.ts +1544 -0
  683. package/src/modules/customers/repository/index.ts +327 -0
  684. package/src/modules/customers/schema.ts +64 -0
  685. package/src/modules/customers/service.ts +171 -0
  686. package/src/modules/fulfillment/repository/index.ts +426 -0
  687. package/src/modules/fulfillment/schema.ts +101 -0
  688. package/src/modules/fulfillment/service.ts +555 -0
  689. package/src/modules/fulfillment/types.ts +59 -0
  690. package/src/modules/inventory/repository/index.ts +509 -0
  691. package/src/modules/inventory/schema.ts +94 -0
  692. package/src/modules/inventory/schemas.ts +38 -0
  693. package/src/modules/inventory/service.ts +490 -0
  694. package/src/modules/media/adapter.ts +17 -0
  695. package/src/modules/media/repository/index.ts +274 -0
  696. package/src/modules/media/schema.ts +41 -0
  697. package/src/modules/media/service.ts +151 -0
  698. package/src/modules/orders/repository/index.ts +287 -0
  699. package/src/modules/orders/schema.ts +66 -0
  700. package/src/modules/orders/service.ts +619 -0
  701. package/src/modules/orders/stale-order-cleanup.ts +76 -0
  702. package/src/modules/organization/service.ts +191 -0
  703. package/src/modules/payments/adapter.ts +47 -0
  704. package/src/modules/payments/repository/index.ts +6 -0
  705. package/src/modules/payments/service.ts +107 -0
  706. package/src/modules/pricing/repository/index.ts +291 -0
  707. package/src/modules/pricing/schema.ts +71 -0
  708. package/src/modules/pricing/schemas.ts +38 -0
  709. package/src/modules/pricing/service.ts +494 -0
  710. package/src/modules/promotions/repository/index.ts +325 -0
  711. package/src/modules/promotions/schema.ts +62 -0
  712. package/src/modules/promotions/schemas.ts +38 -0
  713. package/src/modules/promotions/service.ts +598 -0
  714. package/src/modules/search/adapter.ts +57 -0
  715. package/src/modules/search/hooks.ts +12 -0
  716. package/src/modules/search/repository/index.ts +6 -0
  717. package/src/modules/search/service.ts +315 -0
  718. package/src/modules/shipping/calculator.ts +188 -0
  719. package/src/modules/shipping/repository/index.ts +6 -0
  720. package/src/modules/shipping/service.ts +51 -0
  721. package/src/modules/tax/adapter.ts +60 -0
  722. package/src/modules/tax/repository/index.ts +6 -0
  723. package/src/modules/tax/service.ts +53 -0
  724. package/src/modules/webhooks/hook.ts +34 -0
  725. package/src/modules/webhooks/repository/index.ts +278 -0
  726. package/src/modules/webhooks/schema.ts +56 -0
  727. package/src/modules/webhooks/service.ts +117 -0
  728. package/src/modules/webhooks/signing.ts +6 -0
  729. package/src/modules/webhooks/ssrf-guard.ts +71 -0
  730. package/src/modules/webhooks/tasks.ts +52 -0
  731. package/src/modules/webhooks/worker.ts +134 -0
  732. package/src/runtime/commerce.ts +145 -0
  733. package/src/runtime/kernel.ts +419 -0
  734. package/src/runtime/logger.ts +36 -0
  735. package/src/runtime/server.ts +345 -0
  736. package/src/runtime/shutdown.ts +43 -0
  737. package/src/test-utils/create-pglite-adapter.ts +129 -0
  738. package/src/test-utils/create-plugin-test-app.ts +128 -0
  739. package/src/test-utils/create-repository-test-harness.ts +16 -0
  740. package/src/test-utils/create-test-config.ts +190 -0
  741. package/src/test-utils/create-test-kernel.ts +7 -0
  742. package/src/test-utils/create-test-plugin-context.ts +75 -0
  743. package/src/test-utils/rest-api-test-utils.ts +265 -0
  744. package/src/test-utils/test-actors.ts +62 -0
  745. package/src/test-utils/typed-hooks.ts +54 -0
  746. package/src/types/commerce-types.ts +34 -0
  747. package/src/utils/id.ts +3 -0
  748. package/src/utils/logger.ts +18 -0
  749. package/src/utils/pagination.ts +22 -0
@@ -0,0 +1,30 @@
1
+ import { z } from "@hono/zod-openapi";
2
+ // ─── Zod Body Schemas (single source of truth) ─────────────────────────────
3
+ export const SetBasePriceBodySchema = z.object({
4
+ entityId: z.string().openapi({ example: "product-uuid" }),
5
+ variantId: z.string().optional().openapi({ example: "variant-uuid" }),
6
+ currency: z.string().length(3).openapi({ example: "USD" }),
7
+ amount: z.number().openapi({ example: 29.99 }),
8
+ customerGroupId: z.string().optional(),
9
+ minQuantity: z.number().int().optional(),
10
+ maxQuantity: z.number().int().optional(),
11
+ validFrom: z.coerce.date().optional(),
12
+ validUntil: z.coerce.date().optional(),
13
+ metadata: z.record(z.string(), z.unknown()).optional(),
14
+ }).openapi("SetBasePriceRequest");
15
+ export const CreateModifierBodySchema = z.object({
16
+ name: z.string().openapi({ example: "Summer Sale" }),
17
+ type: z.enum(["percentage_discount", "fixed_discount", "markup", "override"]).openapi({ example: "percentage_discount" }),
18
+ value: z.number().openapi({ example: 10 }),
19
+ priority: z.number().int().optional(),
20
+ entityId: z.string().optional(),
21
+ variantId: z.string().optional(),
22
+ customerGroupId: z.string().optional(),
23
+ currency: z.string().length(3).optional().openapi({ example: "USD" }),
24
+ minQuantity: z.number().int().optional(),
25
+ maxQuantity: z.number().int().optional(),
26
+ conditions: z.record(z.string(), z.unknown()).optional(),
27
+ validFrom: z.coerce.date().optional(),
28
+ validUntil: z.coerce.date().optional(),
29
+ metadata: z.record(z.string(), z.unknown()).optional(),
30
+ }).openapi("CreateModifierRequest");
@@ -0,0 +1,62 @@
1
+ import type { Actor } from "../../auth/types";
2
+ import { type Result } from "../../kernel/result";
3
+ import type { TxContext } from "../../kernel/database/tx-context";
4
+ import type { PricingRepository, Price, PriceModifier } from "./repository";
5
+ import type { CatalogRepository } from "../catalog/repository";
6
+ export type PriceModifierType = "percentage_discount" | "fixed_discount" | "markup" | "override";
7
+ interface PricingServiceDeps {
8
+ repository: PricingRepository;
9
+ catalogRepository: CatalogRepository;
10
+ }
11
+ export interface PriceResolutionContext {
12
+ entityId: string;
13
+ variantId?: string;
14
+ currency: string;
15
+ quantity: number;
16
+ customerId?: string;
17
+ customerGroupIds?: string[];
18
+ timestamp?: Date;
19
+ }
20
+ export interface PriceBreakdownStep {
21
+ label: string;
22
+ amountBefore: number;
23
+ delta: number;
24
+ amountAfter: number;
25
+ metadata?: Record<string, unknown>;
26
+ }
27
+ export interface ResolvedPrice {
28
+ baseAmount: number;
29
+ finalAmount: number;
30
+ currency: string;
31
+ appliedModifiers: Array<{
32
+ id: string;
33
+ name: string;
34
+ type: PriceModifierType;
35
+ delta: number;
36
+ value: number;
37
+ priority: number;
38
+ }>;
39
+ breakdown: PriceBreakdownStep[];
40
+ basePriceId: string;
41
+ }
42
+ export type { SetBasePriceInput, CreatePriceModifierInput } from "./schemas";
43
+ import type { SetBasePriceInput, CreatePriceModifierInput } from "./schemas";
44
+ export declare class PricingService {
45
+ private deps;
46
+ private readonly repo;
47
+ private readonly catalogRepo;
48
+ constructor(deps: PricingServiceDeps);
49
+ setBasePrice(input: SetBasePriceInput, actor?: Actor | null, ctx?: TxContext): Promise<Result<Price>>;
50
+ createModifier(input: CreatePriceModifierInput, actor?: Actor | null, ctx?: TxContext): Promise<Result<PriceModifier>>;
51
+ listPrices(filter?: {
52
+ entityId?: string;
53
+ variantId?: string;
54
+ currency?: string;
55
+ customerGroupId?: string;
56
+ }, ctx?: TxContext): Promise<Result<{
57
+ prices: Price[];
58
+ modifiers: PriceModifier[];
59
+ }>>;
60
+ resolve(input: PriceResolutionContext, ctx?: TxContext): Promise<Result<ResolvedPrice>>;
61
+ }
62
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/pricing/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAK9C,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,KAAK,EACL,aAAa,EAGd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,MAAM,MAAM,iBAAiB,GACzB,qBAAqB,GACrB,gBAAgB,GAChB,QAAQ,GACR,UAAU,CAAC;AAEf,UAAU,kBAAkB;IAC1B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,SAAS,CAAC,EAAE,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,KAAK,CAAC;QACtB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,iBAAiB,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC;IACH,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,YAAY,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAkG7E,qBAAa,cAAc;IAIb,OAAO,CAAC,IAAI;IAHxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoB;IACzC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;gBAE5B,IAAI,EAAE,kBAAkB;IAKtC,YAAY,CAChB,KAAK,EAAE,iBAAiB,EACxB,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,EACpB,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAkCnB,cAAc,CAClB,KAAK,EAAE,wBAAwB,EAC/B,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,EACpB,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IA4C3B,UAAU,CACd,MAAM,CAAC,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,EACD,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAAC,SAAS,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC,CAAC;IAkD7D,OAAO,CACX,KAAK,EAAE,sBAAsB,EAC7B,GAAG,CAAC,EAAE,SAAS,GACd,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;CA+KlC"}
@@ -0,0 +1,308 @@
1
+ import { resolveOrgId } from "../../auth/org";
2
+ import { CommerceNotFoundError, CommerceValidationError, } from "../../kernel/errors";
3
+ import { Err, Ok } from "../../kernel/result";
4
+ function matchesQuantity(min, max, quantity) {
5
+ if (min != null && quantity < min)
6
+ return false;
7
+ if (max != null && quantity > max)
8
+ return false;
9
+ return true;
10
+ }
11
+ function matchesWindow(validFrom, validUntil, timestamp) {
12
+ if (validFrom && timestamp < validFrom)
13
+ return false;
14
+ if (validUntil && timestamp > validUntil)
15
+ return false;
16
+ return true;
17
+ }
18
+ function durationScore(validFrom, validUntil) {
19
+ if (validFrom && validUntil)
20
+ return validUntil.getTime() - validFrom.getTime();
21
+ if (validFrom || validUntil)
22
+ return Number.MAX_SAFE_INTEGER - 1;
23
+ return Number.MAX_SAFE_INTEGER;
24
+ }
25
+ function quantityRangeWidth(min, max) {
26
+ if (min != null && max != null)
27
+ return Math.max(0, max - min);
28
+ if (min != null || max != null)
29
+ return Number.MAX_SAFE_INTEGER - 1;
30
+ return Number.MAX_SAFE_INTEGER;
31
+ }
32
+ function compareBasePriceSpecificity(a, b, context) {
33
+ const aVariant = context.variantId !== undefined && a.variantId === context.variantId
34
+ ? 1
35
+ : 0;
36
+ const bVariant = context.variantId !== undefined && b.variantId === context.variantId
37
+ ? 1
38
+ : 0;
39
+ if (aVariant !== bVariant)
40
+ return bVariant - aVariant;
41
+ const hasGroupA = a.customerGroupId ? 1 : 0;
42
+ const hasGroupB = b.customerGroupId ? 1 : 0;
43
+ if (hasGroupA !== hasGroupB)
44
+ return hasGroupB - hasGroupA;
45
+ const aRange = quantityRangeWidth(a.minQuantity, a.maxQuantity);
46
+ const bRange = quantityRangeWidth(b.minQuantity, b.maxQuantity);
47
+ if (aRange !== bRange)
48
+ return aRange - bRange;
49
+ const aDuration = durationScore(a.validFrom, a.validUntil);
50
+ const bDuration = durationScore(b.validFrom, b.validUntil);
51
+ if (aDuration !== bDuration)
52
+ return aDuration - bDuration;
53
+ return b.createdAt.getTime() - a.createdAt.getTime();
54
+ }
55
+ function resolveModifierDelta(type, value, amountBefore) {
56
+ switch (type) {
57
+ case "percentage_discount":
58
+ return -Math.round((amountBefore * value) / 100);
59
+ case "fixed_discount":
60
+ return -value;
61
+ case "markup":
62
+ return value;
63
+ case "override":
64
+ return value - amountBefore;
65
+ default:
66
+ return 0;
67
+ }
68
+ }
69
+ function toGroupSet(context) {
70
+ return new Set(context.customerGroupIds ?? []);
71
+ }
72
+ function normalizeCurrency(currency) {
73
+ return currency.trim().toUpperCase();
74
+ }
75
+ export class PricingService {
76
+ deps;
77
+ repo;
78
+ catalogRepo;
79
+ constructor(deps) {
80
+ this.deps = deps;
81
+ this.repo = deps.repository;
82
+ this.catalogRepo = deps.catalogRepository;
83
+ }
84
+ async setBasePrice(input, actor, ctx) {
85
+ if (input.amount < 0) {
86
+ return Err(new CommerceValidationError("Base price amount cannot be negative."));
87
+ }
88
+ const entity = await this.catalogRepo.findEntityById(input.entityId, ctx);
89
+ if (!entity) {
90
+ return Err(new CommerceNotFoundError("Entity not found for price assignment."));
91
+ }
92
+ const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
93
+ const priceData = {
94
+ organizationId: orgId,
95
+ entityId: input.entityId,
96
+ currency: normalizeCurrency(input.currency),
97
+ amount: input.amount,
98
+ metadata: input.metadata ?? {},
99
+ variantId: input.variantId ?? null,
100
+ customerGroupId: input.customerGroupId ?? null,
101
+ minQuantity: input.minQuantity ?? null,
102
+ maxQuantity: input.maxQuantity ?? null,
103
+ validFrom: input.validFrom ?? null,
104
+ validUntil: input.validUntil ?? null,
105
+ };
106
+ const record = await this.repo.createPrice(priceData, ctx);
107
+ return Ok(record);
108
+ }
109
+ async createModifier(input, actor, ctx) {
110
+ if (!input.name) {
111
+ return Err(new CommerceValidationError("Modifier name is required."));
112
+ }
113
+ // Validate modifier type
114
+ const validTypes = [
115
+ "percentage_discount",
116
+ "fixed_discount",
117
+ "markup",
118
+ "override",
119
+ ];
120
+ if (!validTypes.includes(input.type)) {
121
+ return Err(new CommerceValidationError(`Invalid modifier type "${input.type}". Must be one of: ${validTypes.join(", ")}`));
122
+ }
123
+ const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
124
+ const modifierData = {
125
+ organizationId: orgId,
126
+ name: input.name,
127
+ type: input.type,
128
+ value: input.value,
129
+ priority: input.priority ?? 100,
130
+ conditions: input.conditions ?? {},
131
+ metadata: input.metadata ?? {},
132
+ entityId: input.entityId ?? null,
133
+ variantId: input.variantId ?? null,
134
+ customerGroupId: input.customerGroupId ?? null,
135
+ currency: input.currency ? normalizeCurrency(input.currency) : null,
136
+ minQuantity: input.minQuantity ?? null,
137
+ maxQuantity: input.maxQuantity ?? null,
138
+ validFrom: input.validFrom ?? null,
139
+ validUntil: input.validUntil ?? null,
140
+ };
141
+ const modifier = await this.repo.createModifier(modifierData, ctx);
142
+ return Ok(modifier);
143
+ }
144
+ async listPrices(filter, ctx) {
145
+ // Get all prices for the entity if specified, or filter after retrieval
146
+ let prices = [];
147
+ if (filter?.entityId) {
148
+ prices = await this.repo.findPricesByEntityId(filter.entityId, ctx);
149
+ }
150
+ // Note: For full list without entityId, we'd need a findAll method
151
+ // For now, entityId is typically required for practical use
152
+ // Apply additional filters
153
+ if (filter?.variantId !== undefined) {
154
+ prices = prices.filter((p) => p.variantId === filter.variantId);
155
+ }
156
+ if (filter?.currency !== undefined) {
157
+ const normalizedCurrency = normalizeCurrency(filter.currency);
158
+ prices = prices.filter((p) => p.currency === normalizedCurrency);
159
+ }
160
+ if (filter?.customerGroupId !== undefined) {
161
+ prices = prices.filter((p) => p.customerGroupId === filter.customerGroupId);
162
+ }
163
+ // Get modifiers for the entity
164
+ let modifiers = [];
165
+ if (filter?.entityId) {
166
+ modifiers = await this.repo.findModifiersByEntityId(filter.entityId, ctx);
167
+ }
168
+ // Apply additional filters
169
+ if (filter?.variantId !== undefined) {
170
+ modifiers = modifiers.filter((m) => m.variantId === filter.variantId);
171
+ }
172
+ if (filter?.currency !== undefined) {
173
+ const normalizedCurrency = normalizeCurrency(filter.currency);
174
+ modifiers = modifiers.filter((m) => m.currency === null || m.currency === normalizedCurrency);
175
+ }
176
+ if (filter?.customerGroupId !== undefined) {
177
+ modifiers = modifiers.filter((m) => m.customerGroupId === null ||
178
+ m.customerGroupId === filter.customerGroupId);
179
+ }
180
+ return Ok({ prices, modifiers });
181
+ }
182
+ async resolve(input, ctx) {
183
+ const entity = await this.catalogRepo.findEntityById(input.entityId, ctx);
184
+ if (!entity) {
185
+ return Err(new CommerceNotFoundError(`Entity ${input.entityId} not found.`));
186
+ }
187
+ if (input.quantity <= 0) {
188
+ return Err(new CommerceValidationError("Quantity must be greater than zero for price resolution."));
189
+ }
190
+ const timestamp = input.timestamp ?? new Date();
191
+ const currency = normalizeCurrency(input.currency);
192
+ const groupSet = toGroupSet(input);
193
+ // Get matching prices from repository
194
+ const allPrices = await this.repo.findPricesByEntityId(input.entityId, ctx);
195
+ const matchingPrices = allPrices.filter((price) => {
196
+ if (input.variantId !== undefined) {
197
+ if (price.variantId !== null && price.variantId !== input.variantId)
198
+ return false;
199
+ }
200
+ else if (price.variantId !== null) {
201
+ return false;
202
+ }
203
+ if (price.currency !== currency)
204
+ return false;
205
+ if (!matchesQuantity(price.minQuantity, price.maxQuantity, input.quantity))
206
+ return false;
207
+ if (!matchesWindow(price.validFrom, price.validUntil, timestamp))
208
+ return false;
209
+ if (price.customerGroupId !== null &&
210
+ !groupSet.has(price.customerGroupId))
211
+ return false;
212
+ return true;
213
+ });
214
+ if (matchingPrices.length === 0) {
215
+ const metadataPrice = typeof entity.metadata?.basePrice === "number"
216
+ ? Math.round(entity.metadata.basePrice)
217
+ : undefined;
218
+ if (metadataPrice === undefined) {
219
+ return Err(new CommerceNotFoundError(`No base price configured for ${entity.slug} (${currency}).`));
220
+ }
221
+ const fallback = {
222
+ baseAmount: metadataPrice,
223
+ finalAmount: metadataPrice,
224
+ currency,
225
+ basePriceId: "metadata:basePrice",
226
+ appliedModifiers: [],
227
+ breakdown: [
228
+ {
229
+ label: "Base price (entity metadata)",
230
+ amountBefore: metadataPrice,
231
+ delta: 0,
232
+ amountAfter: metadataPrice,
233
+ },
234
+ ],
235
+ };
236
+ return Ok(fallback);
237
+ }
238
+ const selectedBase = [...matchingPrices].sort((a, b) => compareBasePriceSpecificity(a, b, input))[0];
239
+ if (!selectedBase) {
240
+ return Err(new CommerceNotFoundError("No matching base price could be selected."));
241
+ }
242
+ let runningAmount = selectedBase.amount;
243
+ const breakdown = [
244
+ {
245
+ label: "Base price",
246
+ amountBefore: selectedBase.amount,
247
+ delta: 0,
248
+ amountAfter: selectedBase.amount,
249
+ metadata: {
250
+ priceId: selectedBase.id,
251
+ customerGroupId: selectedBase.customerGroupId,
252
+ minQuantity: selectedBase.minQuantity,
253
+ maxQuantity: selectedBase.maxQuantity,
254
+ },
255
+ },
256
+ ];
257
+ const appliedModifiers = [];
258
+ // Get matching modifiers (includes both entity-specific and global)
259
+ const firstGroupId = groupSet.size > 0 ? [...groupSet][0] : undefined;
260
+ const activeModifiers = await this.repo.findActiveModifiers(input.entityId, input.variantId, firstGroupId, currency, input.quantity, ctx);
261
+ // Additional filtering for multiple customer groups and conditions
262
+ const modifiers = activeModifiers
263
+ .filter((modifier) => {
264
+ // Re-check customer group for multi-group support
265
+ if (modifier.customerGroupId !== null &&
266
+ !groupSet.has(modifier.customerGroupId))
267
+ return false;
268
+ const conditions = modifier.conditions;
269
+ const minSubtotal = conditions?.minSubtotal;
270
+ if (typeof minSubtotal === "number" && runningAmount < minSubtotal)
271
+ return false;
272
+ return true;
273
+ })
274
+ .sort((a, b) => a.priority - b.priority);
275
+ for (const modifier of modifiers) {
276
+ const amountBefore = runningAmount;
277
+ const rawDelta = resolveModifierDelta(modifier.type, modifier.value, amountBefore);
278
+ const delta = Math.max(-amountBefore, rawDelta);
279
+ runningAmount = Math.max(0, amountBefore + delta);
280
+ appliedModifiers.push({
281
+ id: modifier.id,
282
+ name: modifier.name,
283
+ type: modifier.type,
284
+ delta,
285
+ value: modifier.value,
286
+ priority: modifier.priority,
287
+ });
288
+ breakdown.push({
289
+ label: `Modifier: ${modifier.name}`,
290
+ amountBefore,
291
+ delta,
292
+ amountAfter: runningAmount,
293
+ metadata: {
294
+ type: modifier.type,
295
+ priority: modifier.priority,
296
+ },
297
+ });
298
+ }
299
+ return Ok({
300
+ baseAmount: selectedBase.amount,
301
+ finalAmount: runningAmount,
302
+ currency,
303
+ basePriceId: selectedBase.id,
304
+ appliedModifiers,
305
+ breakdown,
306
+ });
307
+ }
308
+ }
@@ -0,0 +1,32 @@
1
+ import type { TxContext } from "../../../kernel/database/tx-context";
2
+ import type { Promotion, PromotionInsert, PromotionUsage, PromotionUsageInsert } from "./index";
3
+ /**
4
+ * In-memory implementation of PromotionsRepository for testing.
5
+ */
6
+ export declare class InMemoryPromotionsRepository {
7
+ private promotions;
8
+ private usages;
9
+ findById(id: string, _ctx?: TxContext): Promise<Promotion | undefined>;
10
+ findByCode(code: string, _ctx?: TxContext): Promise<Promotion | undefined>;
11
+ findAll(_ctx?: TxContext): Promise<Promotion[]>;
12
+ findActive(_ctx?: TxContext): Promise<Promotion[]>;
13
+ findAutomatic(_ctx?: TxContext): Promise<Promotion[]>;
14
+ create(data: PromotionInsert, _ctx?: TxContext): Promise<Promotion>;
15
+ update(id: string, data: Partial<Omit<PromotionInsert, "id">>, _ctx?: TxContext): Promise<Promotion | undefined>;
16
+ delete(id: string, _ctx?: TxContext): Promise<boolean>;
17
+ activate(id: string, _ctx?: TxContext): Promise<Promotion | undefined>;
18
+ deactivate(id: string, _ctx?: TxContext): Promise<Promotion | undefined>;
19
+ findUsageById(id: string, _ctx?: TxContext): Promise<PromotionUsage | undefined>;
20
+ findUsagesByPromotionId(promotionId: string, _ctx?: TxContext): Promise<PromotionUsage[]>;
21
+ findUsagesByCustomerId(customerId: string, _ctx?: TxContext): Promise<PromotionUsage[]>;
22
+ createUsage(data: PromotionUsageInsert, _ctx?: TxContext): Promise<PromotionUsage>;
23
+ countUsages(promotionId: string, _ctx?: TxContext): Promise<number>;
24
+ countUsagesByCustomer(promotionId: string, customerId: string, _ctx?: TxContext): Promise<number>;
25
+ isUsageLimitReached(promotionId: string, _ctx?: TxContext): Promise<boolean>;
26
+ isCustomerUsageLimitReached(promotionId: string, customerId: string, _ctx?: TxContext): Promise<boolean>;
27
+ isPromotionValid(promotionId: string, customerId?: string, _ctx?: TxContext): Promise<{
28
+ valid: boolean;
29
+ reason?: string;
30
+ }>;
31
+ }
32
+ //# sourceMappingURL=in-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../../../src/modules/promotions/repository/in-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,cAAc,EACd,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAMjB;;GAEG;AACH,qBAAa,4BAA4B;IACvC,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,MAAM,CAAwB;IAMhC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAItE,UAAU,CACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAI3B,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAM/C,UAAU,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAYlD,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAarD,MAAM,CAAC,IAAI,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAuCnE,MAAM,CACV,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC,EAC1C,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IA2E3B,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAItD,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAItE,UAAU,CACd,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAQ3B,aAAa,CACjB,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAIhC,uBAAuB,CAC3B,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,cAAc,EAAE,CAAC;IAItB,sBAAsB,CAC1B,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,cAAc,EAAE,CAAC;IAItB,WAAW,CACf,IAAI,EAAE,oBAAoB,EAC1B,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,cAAc,CAAC;IAYpB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAInE,qBAAqB,CACzB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,MAAM,CAAC;IAMZ,mBAAmB,CACvB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,OAAO,CAAC;IAOb,2BAA2B,CAC/B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC,OAAO,CAAC;IAWb,gBAAgB,CACpB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,SAAS,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAiChD"}
@@ -0,0 +1,227 @@
1
+ function makeId() {
2
+ return crypto.randomUUID();
3
+ }
4
+ /**
5
+ * In-memory implementation of PromotionsRepository for testing.
6
+ */
7
+ export class InMemoryPromotionsRepository {
8
+ promotions = new Map();
9
+ usages = [];
10
+ // ─────────────────────────────────────────────────────────────────────────────
11
+ // Promotions
12
+ // ─────────────────────────────────────────────────────────────────────────────
13
+ async findById(id, _ctx) {
14
+ return this.promotions.get(id);
15
+ }
16
+ async findByCode(code, _ctx) {
17
+ return [...this.promotions.values()].find((p) => p.code === code);
18
+ }
19
+ async findAll(_ctx) {
20
+ return [...this.promotions.values()].sort((a, b) => b.priority - a.priority);
21
+ }
22
+ async findActive(_ctx) {
23
+ const now = new Date();
24
+ return [...this.promotions.values()]
25
+ .filter((p) => {
26
+ if (!p.isActive)
27
+ return false;
28
+ if (p.validFrom && p.validFrom > now)
29
+ return false;
30
+ if (p.validUntil && p.validUntil < now)
31
+ return false;
32
+ return true;
33
+ })
34
+ .sort((a, b) => b.priority - a.priority);
35
+ }
36
+ async findAutomatic(_ctx) {
37
+ const now = new Date();
38
+ return [...this.promotions.values()]
39
+ .filter((p) => {
40
+ if (!p.isActive)
41
+ return false;
42
+ if (!p.isAutomatic)
43
+ return false;
44
+ if (p.validFrom && p.validFrom > now)
45
+ return false;
46
+ if (p.validUntil && p.validUntil < now)
47
+ return false;
48
+ return true;
49
+ })
50
+ .sort((a, b) => b.priority - a.priority);
51
+ }
52
+ async create(data, _ctx) {
53
+ // Enforce unique code constraint (nullable: multiple NULLs allowed, but non-null codes must be unique)
54
+ if (data.code != null) {
55
+ const duplicate = [...this.promotions.values()].find((p) => p.code === data.code);
56
+ if (duplicate) {
57
+ throw new Error(`Promotion with code "${data.code}" already exists.`);
58
+ }
59
+ }
60
+ const now = new Date();
61
+ const promotion = {
62
+ id: data.id ?? makeId(),
63
+ code: data.code === undefined ? null : data.code,
64
+ name: data.name,
65
+ type: data.type,
66
+ value: data.value ?? 0,
67
+ buyQuantity: data.buyQuantity === undefined ? null : data.buyQuantity,
68
+ getQuantity: data.getQuantity === undefined ? null : data.getQuantity,
69
+ isAutomatic: data.isAutomatic ?? false,
70
+ isActive: data.isActive ?? true,
71
+ priority: data.priority ?? 100,
72
+ conditions: data.conditions === undefined ? null : data.conditions,
73
+ usageLimitTotal: data.usageLimitTotal === undefined ? null : data.usageLimitTotal,
74
+ usageLimitPerCustomer: data.usageLimitPerCustomer === undefined
75
+ ? null
76
+ : data.usageLimitPerCustomer,
77
+ validFrom: data.validFrom === undefined ? null : data.validFrom,
78
+ validUntil: data.validUntil === undefined ? null : data.validUntil,
79
+ metadata: data.metadata === undefined ? null : data.metadata,
80
+ createdAt: now,
81
+ updatedAt: now,
82
+ };
83
+ this.promotions.set(promotion.id, promotion);
84
+ return promotion;
85
+ }
86
+ async update(id, data, _ctx) {
87
+ const existing = this.promotions.get(id);
88
+ if (!existing)
89
+ return undefined;
90
+ const updated = {
91
+ id: existing.id,
92
+ code: data.code !== undefined
93
+ ? data.code === undefined
94
+ ? null
95
+ : data.code
96
+ : existing.code,
97
+ name: data.name !== undefined ? data.name : existing.name,
98
+ type: data.type !== undefined ? data.type : existing.type,
99
+ value: data.value !== undefined ? data.value : existing.value,
100
+ buyQuantity: data.buyQuantity !== undefined
101
+ ? data.buyQuantity === undefined
102
+ ? null
103
+ : data.buyQuantity
104
+ : existing.buyQuantity,
105
+ getQuantity: data.getQuantity !== undefined
106
+ ? data.getQuantity === undefined
107
+ ? null
108
+ : data.getQuantity
109
+ : existing.getQuantity,
110
+ isAutomatic: data.isAutomatic !== undefined
111
+ ? data.isAutomatic
112
+ : existing.isAutomatic,
113
+ isActive: data.isActive !== undefined ? data.isActive : existing.isActive,
114
+ priority: data.priority !== undefined ? data.priority : existing.priority,
115
+ conditions: data.conditions !== undefined
116
+ ? data.conditions === undefined
117
+ ? null
118
+ : data.conditions
119
+ : existing.conditions,
120
+ usageLimitTotal: data.usageLimitTotal !== undefined
121
+ ? data.usageLimitTotal === undefined
122
+ ? null
123
+ : data.usageLimitTotal
124
+ : existing.usageLimitTotal,
125
+ usageLimitPerCustomer: data.usageLimitPerCustomer !== undefined
126
+ ? data.usageLimitPerCustomer === undefined
127
+ ? null
128
+ : data.usageLimitPerCustomer
129
+ : existing.usageLimitPerCustomer,
130
+ validFrom: data.validFrom !== undefined
131
+ ? data.validFrom === undefined
132
+ ? null
133
+ : data.validFrom
134
+ : existing.validFrom,
135
+ validUntil: data.validUntil !== undefined
136
+ ? data.validUntil === undefined
137
+ ? null
138
+ : data.validUntil
139
+ : existing.validUntil,
140
+ metadata: data.metadata !== undefined
141
+ ? data.metadata === undefined
142
+ ? null
143
+ : data.metadata
144
+ : existing.metadata,
145
+ createdAt: existing.createdAt,
146
+ updatedAt: new Date(),
147
+ };
148
+ this.promotions.set(id, updated);
149
+ return updated;
150
+ }
151
+ async delete(id, _ctx) {
152
+ return this.promotions.delete(id);
153
+ }
154
+ async activate(id, _ctx) {
155
+ return this.update(id, { isActive: true }, _ctx);
156
+ }
157
+ async deactivate(id, _ctx) {
158
+ return this.update(id, { isActive: false }, _ctx);
159
+ }
160
+ // ─────────────────────────────────────────────────────────────────────────────
161
+ // Promotion Usages
162
+ // ─────────────────────────────────────────────────────────────────────────────
163
+ async findUsageById(id, _ctx) {
164
+ return this.usages.find((u) => u.id === id);
165
+ }
166
+ async findUsagesByPromotionId(promotionId, _ctx) {
167
+ return this.usages.filter((u) => u.promotionId === promotionId);
168
+ }
169
+ async findUsagesByCustomerId(customerId, _ctx) {
170
+ return this.usages.filter((u) => u.customerId === customerId);
171
+ }
172
+ async createUsage(data, _ctx) {
173
+ const usage = {
174
+ id: data.id ?? makeId(),
175
+ promotionId: data.promotionId,
176
+ customerId: data.customerId ?? null,
177
+ orderId: data.orderId ?? null,
178
+ usedAt: data.usedAt ?? new Date(),
179
+ };
180
+ this.usages.push(usage);
181
+ return usage;
182
+ }
183
+ async countUsages(promotionId, _ctx) {
184
+ return this.usages.filter((u) => u.promotionId === promotionId).length;
185
+ }
186
+ async countUsagesByCustomer(promotionId, customerId, _ctx) {
187
+ return this.usages.filter((u) => u.promotionId === promotionId && u.customerId === customerId).length;
188
+ }
189
+ async isUsageLimitReached(promotionId, _ctx) {
190
+ const promotion = await this.findById(promotionId, _ctx);
191
+ if (!promotion || promotion.usageLimitTotal === null)
192
+ return false;
193
+ const count = await this.countUsages(promotionId, _ctx);
194
+ return count >= promotion.usageLimitTotal;
195
+ }
196
+ async isCustomerUsageLimitReached(promotionId, customerId, _ctx) {
197
+ const promotion = await this.findById(promotionId, _ctx);
198
+ if (!promotion || promotion.usageLimitPerCustomer === null)
199
+ return false;
200
+ const count = await this.countUsagesByCustomer(promotionId, customerId, _ctx);
201
+ return count >= promotion.usageLimitPerCustomer;
202
+ }
203
+ async isPromotionValid(promotionId, customerId, _ctx) {
204
+ const promotion = await this.findById(promotionId, _ctx);
205
+ if (!promotion) {
206
+ return { valid: false, reason: "Promotion not found" };
207
+ }
208
+ if (!promotion.isActive) {
209
+ return { valid: false, reason: "Promotion is not active" };
210
+ }
211
+ const now = new Date();
212
+ if (promotion.validFrom && promotion.validFrom > now) {
213
+ return { valid: false, reason: "Promotion has not started yet" };
214
+ }
215
+ if (promotion.validUntil && promotion.validUntil < now) {
216
+ return { valid: false, reason: "Promotion has expired" };
217
+ }
218
+ if (await this.isUsageLimitReached(promotionId, _ctx)) {
219
+ return { valid: false, reason: "Promotion usage limit reached" };
220
+ }
221
+ if (customerId &&
222
+ (await this.isCustomerUsageLimitReached(promotionId, customerId, _ctx))) {
223
+ return { valid: false, reason: "Customer usage limit reached" };
224
+ }
225
+ return { valid: true };
226
+ }
227
+ }