@unifiedcommerce/core 0.1.1 → 0.2.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 (257) hide show
  1. package/dist/auth/setup.d.ts.map +1 -1
  2. package/dist/auth/setup.js +8 -3
  3. package/dist/config/types.d.ts +3 -1
  4. package/dist/config/types.d.ts.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/interfaces/mcp/server.d.ts +3 -5
  9. package/dist/interfaces/mcp/server.d.ts.map +1 -1
  10. package/dist/interfaces/mcp/server.js +25 -510
  11. package/dist/interfaces/mcp/tool-builder.d.ts +120 -0
  12. package/dist/interfaces/mcp/tool-builder.d.ts.map +1 -0
  13. package/dist/interfaces/mcp/tool-builder.js +224 -0
  14. package/dist/interfaces/mcp/tools/analytics.d.ts +42 -0
  15. package/dist/interfaces/mcp/tools/analytics.d.ts.map +1 -0
  16. package/dist/interfaces/mcp/tools/analytics.js +70 -0
  17. package/dist/interfaces/mcp/tools/cart.d.ts +14 -0
  18. package/dist/interfaces/mcp/tools/cart.d.ts.map +1 -0
  19. package/dist/interfaces/mcp/tools/cart.js +47 -0
  20. package/dist/interfaces/mcp/tools/catalog.d.ts +53 -0
  21. package/dist/interfaces/mcp/tools/catalog.d.ts.map +1 -0
  22. package/dist/interfaces/mcp/tools/catalog.js +284 -0
  23. package/dist/interfaces/mcp/tools/index.d.ts +3 -0
  24. package/dist/interfaces/mcp/tools/index.d.ts.map +1 -0
  25. package/dist/interfaces/mcp/tools/index.js +20 -0
  26. package/dist/interfaces/mcp/tools/inventory.d.ts +27 -0
  27. package/dist/interfaces/mcp/tools/inventory.d.ts.map +1 -0
  28. package/dist/interfaces/mcp/tools/inventory.js +143 -0
  29. package/dist/interfaces/mcp/tools/orders.d.ts +18 -0
  30. package/dist/interfaces/mcp/tools/orders.d.ts.map +1 -0
  31. package/dist/interfaces/mcp/tools/orders.js +82 -0
  32. package/dist/interfaces/mcp/tools/pricing.d.ts +29 -0
  33. package/dist/interfaces/mcp/tools/pricing.d.ts.map +1 -0
  34. package/dist/interfaces/mcp/tools/pricing.js +90 -0
  35. package/dist/interfaces/mcp/tools/promotions.d.ts +44 -0
  36. package/dist/interfaces/mcp/tools/promotions.d.ts.map +1 -0
  37. package/dist/interfaces/mcp/tools/promotions.js +109 -0
  38. package/dist/interfaces/mcp/tools/registry.d.ts +32 -0
  39. package/dist/interfaces/mcp/tools/registry.d.ts.map +1 -0
  40. package/dist/interfaces/mcp/tools/registry.js +55 -0
  41. package/dist/interfaces/mcp/tools/search.d.ts +14 -0
  42. package/dist/interfaces/mcp/tools/search.d.ts.map +1 -0
  43. package/dist/interfaces/mcp/tools/search.js +39 -0
  44. package/dist/interfaces/mcp/tools/webhooks.d.ts +15 -0
  45. package/dist/interfaces/mcp/tools/webhooks.d.ts.map +1 -0
  46. package/dist/interfaces/mcp/tools/webhooks.js +48 -0
  47. package/dist/interfaces/mcp/transport.d.ts +17 -2
  48. package/dist/interfaces/mcp/transport.d.ts.map +1 -1
  49. package/dist/interfaces/mcp/transport.js +91 -44
  50. package/dist/interfaces/rest/router.d.ts.map +1 -1
  51. package/dist/interfaces/rest/routes/checkout.d.ts.map +1 -1
  52. package/dist/interfaces/rest/routes/checkout.js +1 -1
  53. package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -1
  54. package/dist/interfaces/rest/routes/promotions.js +3 -2
  55. package/dist/kernel/database/adapter.d.ts +8 -0
  56. package/dist/kernel/database/adapter.d.ts.map +1 -1
  57. package/dist/kernel/factory/repository-factory.d.ts.map +1 -1
  58. package/dist/kernel/factory/repository-factory.js +3 -1
  59. package/dist/kernel/local-api.d.ts.map +1 -1
  60. package/dist/kernel/local-api.js +2 -0
  61. package/dist/kernel/plugin/manifest.d.ts +3 -3
  62. package/dist/kernel/plugin/manifest.d.ts.map +1 -1
  63. package/dist/kernel/plugin/manifest.js +36 -7
  64. package/dist/runtime/kernel.d.ts +1 -2
  65. package/dist/runtime/kernel.d.ts.map +1 -1
  66. package/dist/runtime/kernel.js +16 -8
  67. package/dist/runtime/server.d.ts.map +1 -1
  68. package/dist/runtime/server.js +8 -3
  69. package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -1
  70. package/dist/test-utils/create-pglite-adapter.js +7 -6
  71. package/dist/tsconfig.tsbuildinfo +1 -0
  72. package/package.json +3 -1
  73. package/src/adapters/console-email.ts +43 -0
  74. package/src/auth/access.ts +187 -0
  75. package/src/auth/auth-schema.ts +139 -0
  76. package/src/auth/middleware.ts +161 -0
  77. package/src/auth/org.ts +41 -0
  78. package/src/auth/permissions.ts +28 -0
  79. package/src/auth/setup.ts +171 -0
  80. package/src/auth/system-actor.ts +19 -0
  81. package/src/auth/types.ts +10 -0
  82. package/src/config/defaults.ts +82 -0
  83. package/src/config/define-config.ts +53 -0
  84. package/src/config/types.ts +301 -0
  85. package/src/generated/plugin-capabilities.d.ts +20 -0
  86. package/src/generated/plugin-manifest.ts +23 -0
  87. package/src/generated/plugin-repositories.d.ts +20 -0
  88. package/src/hooks/checkout-completion.ts +262 -0
  89. package/src/hooks/checkout.ts +677 -0
  90. package/src/hooks/order-emails.ts +62 -0
  91. package/src/index.ts +215 -0
  92. package/src/interfaces/mcp/agent-prompt.ts +174 -0
  93. package/src/interfaces/mcp/context-enrichment.ts +177 -0
  94. package/src/interfaces/mcp/server.ts +47 -0
  95. package/src/interfaces/mcp/tool-builder.ts +261 -0
  96. package/src/interfaces/mcp/tools/analytics.ts +76 -0
  97. package/src/interfaces/mcp/tools/cart.ts +57 -0
  98. package/src/interfaces/mcp/tools/catalog.ts +299 -0
  99. package/src/interfaces/mcp/tools/index.ts +22 -0
  100. package/src/interfaces/mcp/tools/inventory.ts +161 -0
  101. package/src/interfaces/mcp/tools/orders.ts +104 -0
  102. package/src/interfaces/mcp/tools/pricing.ts +94 -0
  103. package/src/interfaces/mcp/tools/promotions.ts +106 -0
  104. package/src/interfaces/mcp/tools/registry.ts +101 -0
  105. package/src/interfaces/mcp/tools/search.ts +42 -0
  106. package/src/interfaces/mcp/tools/webhooks.ts +48 -0
  107. package/src/interfaces/mcp/transport.ts +128 -0
  108. package/src/interfaces/rest/customer-portal.ts +299 -0
  109. package/src/interfaces/rest/index.ts +74 -0
  110. package/src/interfaces/rest/router.ts +333 -0
  111. package/src/interfaces/rest/routes/admin-jobs.ts +58 -0
  112. package/src/interfaces/rest/routes/audit.ts +50 -0
  113. package/src/interfaces/rest/routes/carts.ts +89 -0
  114. package/src/interfaces/rest/routes/catalog.ts +493 -0
  115. package/src/interfaces/rest/routes/checkout.ts +284 -0
  116. package/src/interfaces/rest/routes/inventory.ts +70 -0
  117. package/src/interfaces/rest/routes/media.ts +86 -0
  118. package/src/interfaces/rest/routes/orders.ts +78 -0
  119. package/src/interfaces/rest/routes/payments.ts +60 -0
  120. package/src/interfaces/rest/routes/pricing.ts +57 -0
  121. package/src/interfaces/rest/routes/promotions.ts +93 -0
  122. package/src/interfaces/rest/routes/search.ts +71 -0
  123. package/src/interfaces/rest/routes/webhooks.ts +46 -0
  124. package/src/interfaces/rest/schemas/admin-jobs.ts +40 -0
  125. package/src/interfaces/rest/schemas/audit.ts +46 -0
  126. package/src/interfaces/rest/schemas/carts.ts +125 -0
  127. package/src/interfaces/rest/schemas/catalog.ts +450 -0
  128. package/src/interfaces/rest/schemas/checkout.ts +66 -0
  129. package/src/interfaces/rest/schemas/customer-portal.ts +195 -0
  130. package/src/interfaces/rest/schemas/inventory.ts +138 -0
  131. package/src/interfaces/rest/schemas/media.ts +75 -0
  132. package/src/interfaces/rest/schemas/orders.ts +104 -0
  133. package/src/interfaces/rest/schemas/pricing.ts +80 -0
  134. package/src/interfaces/rest/schemas/promotions.ts +110 -0
  135. package/src/interfaces/rest/schemas/responses.ts +85 -0
  136. package/src/interfaces/rest/schemas/search.ts +58 -0
  137. package/src/interfaces/rest/schemas/shared.ts +62 -0
  138. package/src/interfaces/rest/schemas/webhooks.ts +68 -0
  139. package/src/interfaces/rest/utils.ts +104 -0
  140. package/src/interfaces/rest/webhook-router.ts +50 -0
  141. package/src/kernel/compensation/executor.ts +61 -0
  142. package/src/kernel/compensation/types.ts +26 -0
  143. package/src/kernel/database/adapter.ts +21 -0
  144. package/src/kernel/database/drizzle-db.ts +56 -0
  145. package/src/kernel/database/migrate.ts +76 -0
  146. package/src/kernel/database/plugin-types.ts +34 -0
  147. package/src/kernel/database/schema.ts +49 -0
  148. package/src/kernel/database/scoped-db.ts +68 -0
  149. package/src/kernel/database/tx-context.ts +46 -0
  150. package/src/kernel/error-mapper.ts +15 -0
  151. package/src/kernel/errors.ts +89 -0
  152. package/src/kernel/factory/repository-factory.ts +244 -0
  153. package/src/kernel/hooks/create-context.ts +43 -0
  154. package/src/kernel/hooks/executor.ts +88 -0
  155. package/src/kernel/hooks/registry.ts +74 -0
  156. package/src/kernel/hooks/types.ts +52 -0
  157. package/src/kernel/http-error.ts +44 -0
  158. package/src/kernel/jobs/adapter.ts +36 -0
  159. package/src/kernel/jobs/drizzle-adapter.ts +58 -0
  160. package/src/kernel/jobs/runner.ts +153 -0
  161. package/src/kernel/jobs/schema.ts +46 -0
  162. package/src/kernel/jobs/types.ts +30 -0
  163. package/src/kernel/local-api.ts +187 -0
  164. package/src/kernel/plugin/manifest.ts +271 -0
  165. package/src/kernel/query/executor.ts +184 -0
  166. package/src/kernel/query/registry.ts +46 -0
  167. package/src/kernel/result.ts +33 -0
  168. package/src/kernel/schema/extra-columns.ts +37 -0
  169. package/src/kernel/service-registry.ts +76 -0
  170. package/src/kernel/service-timing.ts +89 -0
  171. package/src/kernel/state-machine/machine.ts +101 -0
  172. package/src/modules/analytics/drizzle-adapter.ts +426 -0
  173. package/src/modules/analytics/hooks.ts +11 -0
  174. package/src/modules/analytics/models.ts +125 -0
  175. package/src/modules/analytics/repository/index.ts +6 -0
  176. package/src/modules/analytics/service.ts +245 -0
  177. package/src/modules/analytics/types.ts +180 -0
  178. package/src/modules/audit/hooks.ts +78 -0
  179. package/src/modules/audit/schema.ts +33 -0
  180. package/src/modules/audit/service.ts +151 -0
  181. package/src/modules/cart/access.ts +27 -0
  182. package/src/modules/cart/matcher.ts +26 -0
  183. package/src/modules/cart/repository/index.ts +234 -0
  184. package/src/modules/cart/schema.ts +42 -0
  185. package/src/modules/cart/schemas.ts +38 -0
  186. package/src/modules/cart/service.ts +541 -0
  187. package/src/modules/catalog/repository/index.ts +772 -0
  188. package/src/modules/catalog/schema.ts +203 -0
  189. package/src/modules/catalog/schemas.ts +104 -0
  190. package/src/modules/catalog/service.ts +1544 -0
  191. package/src/modules/customers/repository/index.ts +327 -0
  192. package/src/modules/customers/schema.ts +64 -0
  193. package/src/modules/customers/service.ts +171 -0
  194. package/src/modules/fulfillment/repository/index.ts +426 -0
  195. package/src/modules/fulfillment/schema.ts +101 -0
  196. package/src/modules/fulfillment/service.ts +555 -0
  197. package/src/modules/fulfillment/types.ts +59 -0
  198. package/src/modules/inventory/repository/index.ts +509 -0
  199. package/src/modules/inventory/schema.ts +94 -0
  200. package/src/modules/inventory/schemas.ts +38 -0
  201. package/src/modules/inventory/service.ts +490 -0
  202. package/src/modules/media/adapter.ts +17 -0
  203. package/src/modules/media/repository/index.ts +274 -0
  204. package/src/modules/media/schema.ts +41 -0
  205. package/src/modules/media/service.ts +151 -0
  206. package/src/modules/orders/repository/index.ts +287 -0
  207. package/src/modules/orders/schema.ts +66 -0
  208. package/src/modules/orders/service.ts +619 -0
  209. package/src/modules/orders/stale-order-cleanup.ts +76 -0
  210. package/src/modules/organization/service.ts +191 -0
  211. package/src/modules/payments/adapter.ts +47 -0
  212. package/src/modules/payments/repository/index.ts +6 -0
  213. package/src/modules/payments/service.ts +107 -0
  214. package/src/modules/pricing/repository/index.ts +291 -0
  215. package/src/modules/pricing/schema.ts +71 -0
  216. package/src/modules/pricing/schemas.ts +38 -0
  217. package/src/modules/pricing/service.ts +494 -0
  218. package/src/modules/promotions/repository/index.ts +325 -0
  219. package/src/modules/promotions/schema.ts +62 -0
  220. package/src/modules/promotions/schemas.ts +38 -0
  221. package/src/modules/promotions/service.ts +598 -0
  222. package/src/modules/search/adapter.ts +57 -0
  223. package/src/modules/search/hooks.ts +12 -0
  224. package/src/modules/search/repository/index.ts +6 -0
  225. package/src/modules/search/service.ts +315 -0
  226. package/src/modules/shipping/calculator.ts +188 -0
  227. package/src/modules/shipping/repository/index.ts +6 -0
  228. package/src/modules/shipping/service.ts +51 -0
  229. package/src/modules/tax/adapter.ts +60 -0
  230. package/src/modules/tax/repository/index.ts +6 -0
  231. package/src/modules/tax/service.ts +53 -0
  232. package/src/modules/webhooks/hook.ts +34 -0
  233. package/src/modules/webhooks/repository/index.ts +278 -0
  234. package/src/modules/webhooks/schema.ts +56 -0
  235. package/src/modules/webhooks/service.ts +117 -0
  236. package/src/modules/webhooks/signing.ts +6 -0
  237. package/src/modules/webhooks/ssrf-guard.ts +71 -0
  238. package/src/modules/webhooks/tasks.ts +52 -0
  239. package/src/modules/webhooks/worker.ts +134 -0
  240. package/src/runtime/commerce.ts +145 -0
  241. package/src/runtime/kernel.ts +426 -0
  242. package/src/runtime/logger.ts +36 -0
  243. package/src/runtime/server.ts +355 -0
  244. package/src/runtime/shutdown.ts +43 -0
  245. package/src/test-utils/create-pglite-adapter.ts +129 -0
  246. package/src/test-utils/create-plugin-test-app.ts +128 -0
  247. package/src/test-utils/create-repository-test-harness.ts +16 -0
  248. package/src/test-utils/create-test-config.ts +190 -0
  249. package/src/test-utils/create-test-kernel.ts +7 -0
  250. package/src/test-utils/create-test-plugin-context.ts +75 -0
  251. package/src/test-utils/rest-api-test-utils.ts +265 -0
  252. package/src/test-utils/test-actors.ts +62 -0
  253. package/src/test-utils/typed-hooks.ts +54 -0
  254. package/src/types/commerce-types.ts +34 -0
  255. package/src/utils/id.ts +3 -0
  256. package/src/utils/logger.ts +18 -0
  257. package/src/utils/pagination.ts +22 -0
@@ -0,0 +1,195 @@
1
+ import { z, createRoute } from "@hono/zod-openapi";
2
+ import { errorResponses } from "./shared.js";
3
+ import { CustomerResponse, OrderResponse, OrderListResponse, CustomerAddressListResponse, CartResponse } from "./responses.js";
4
+
5
+ const GenericDataResponse = z.object({ data: z.record(z.string(), z.unknown()) });
6
+
7
+ // ─── GET Route Definitions ─────────────────────────────────────────────────
8
+
9
+ export const getProfileRoute = createRoute({
10
+ method: "get",
11
+ path: "/profile",
12
+ tags: ["Customer Portal"],
13
+ summary: "Get customer profile",
14
+ responses: {
15
+ 200: { content: { "application/json": { schema: CustomerResponse } }, description: "Customer profile" },
16
+ ...errorResponses,
17
+ },
18
+ });
19
+
20
+ export const listAddressesRoute = createRoute({
21
+ method: "get",
22
+ path: "/addresses",
23
+ tags: ["Customer Portal"],
24
+ summary: "List customer addresses",
25
+ responses: {
26
+ 200: { content: { "application/json": { schema: CustomerAddressListResponse } }, description: "Addresses" },
27
+ },
28
+ });
29
+
30
+ export const listCustomerOrdersRoute = createRoute({
31
+ method: "get",
32
+ path: "/orders",
33
+ tags: ["Customer Portal"],
34
+ summary: "List customer orders",
35
+ request: {
36
+ query: z.object({
37
+ status: z.string().optional(),
38
+ page: z.string().optional(),
39
+ limit: z.string().optional(),
40
+ }),
41
+ },
42
+ responses: {
43
+ 200: { content: { "application/json": { schema: OrderListResponse } }, description: "Orders" },
44
+ },
45
+ });
46
+
47
+ export const getCustomerOrderRoute = createRoute({
48
+ method: "get",
49
+ path: "/orders/{idOrNumber}",
50
+ tags: ["Customer Portal"],
51
+ summary: "Get a specific customer order",
52
+ request: {
53
+ params: z.object({
54
+ idOrNumber: z.string().min(1).openapi({ example: "ORD-001" }),
55
+ }),
56
+ },
57
+ responses: {
58
+ 200: { content: { "application/json": { schema: OrderResponse } }, description: "Order details" },
59
+ ...errorResponses,
60
+ },
61
+ });
62
+
63
+ export const getOrderTrackingRoute = createRoute({
64
+ method: "get",
65
+ path: "/orders/{idOrNumber}/tracking",
66
+ tags: ["Customer Portal"],
67
+ summary: "Get tracking info for an order",
68
+ request: {
69
+ params: z.object({
70
+ idOrNumber: z.string().min(1).openapi({ example: "ORD-001" }),
71
+ }),
72
+ },
73
+ responses: {
74
+ 200: { content: { "application/json": { schema: GenericDataResponse } }, description: "Tracking info" },
75
+ ...errorResponses,
76
+ },
77
+ });
78
+
79
+ export const getOrderDownloadsRoute = createRoute({
80
+ method: "get",
81
+ path: "/orders/{orderId}/downloads",
82
+ tags: ["Customer Portal"],
83
+ summary: "Get digital downloads for an order",
84
+ request: {
85
+ params: z.object({
86
+ orderId: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
87
+ }),
88
+ },
89
+ responses: {
90
+ 200: { content: { "application/json": { schema: GenericDataResponse } }, description: "Downloads" },
91
+ ...errorResponses,
92
+ },
93
+ });
94
+
95
+ export const listCoursesRoute = createRoute({
96
+ method: "get",
97
+ path: "/courses",
98
+ tags: ["Customer Portal"],
99
+ summary: "List customer course access",
100
+ responses: {
101
+ 200: { content: { "application/json": { schema: GenericDataResponse } }, description: "Courses" },
102
+ },
103
+ });
104
+
105
+ // ─── DELETE Route Definitions ──────────────────────────────────────────────
106
+
107
+ export const deleteAddressRoute = createRoute({
108
+ method: "delete",
109
+ path: "/addresses/{id}",
110
+ tags: ["Customer Portal"],
111
+ summary: "Delete a customer address",
112
+ request: {
113
+ params: z.object({
114
+ id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
115
+ }),
116
+ },
117
+ responses: {
118
+ 200: { content: { "application/json": { schema: z.object({ data: z.object({ deleted: z.literal(true) }) }) } }, description: "Deleted" },
119
+ ...errorResponses,
120
+ },
121
+ });
122
+
123
+ // ─── POST Route Definitions (no body or special) ───────────────────────────
124
+
125
+ export const reorderRoute = createRoute({
126
+ method: "post",
127
+ path: "/orders/{orderId}/reorder",
128
+ tags: ["Customer Portal"],
129
+ summary: "Reorder items from a previous order",
130
+ request: {
131
+ params: z.object({
132
+ orderId: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
133
+ }),
134
+ },
135
+ responses: {
136
+ 201: { content: { "application/json": { schema: CartResponse } }, description: "Reorder cart created" },
137
+ ...errorResponses,
138
+ },
139
+ });
140
+
141
+ // ─── Mutation Route Definitions ─────────────────────────────────────────────
142
+
143
+ const UpdateProfileBodySchema = z.object({
144
+ firstName: z.string().optional(),
145
+ lastName: z.string().optional(),
146
+ phone: z.string().optional(),
147
+ metadata: z.record(z.string(), z.unknown()).optional(),
148
+ }).openapi("UpdateProfileBody");
149
+
150
+ const CreateAddressBodySchema = z.object({
151
+ type: z.enum(["shipping", "billing"]).openapi({ example: "shipping" }),
152
+ firstName: z.string().openapi({ example: "John" }),
153
+ lastName: z.string().openapi({ example: "Doe" }),
154
+ line1: z.string().openapi({ example: "123 Main St" }),
155
+ line2: z.string().optional(),
156
+ city: z.string().openapi({ example: "New York" }),
157
+ state: z.string().optional(),
158
+ postalCode: z.string().optional(),
159
+ country: z.string().openapi({ example: "US" }),
160
+ phone: z.string().optional(),
161
+ }).openapi("CreateAddressBody");
162
+
163
+ export const updateProfileRoute = createRoute({
164
+ method: "patch",
165
+ path: "/profile",
166
+ tags: ["Customer Portal"],
167
+ summary: "Update customer profile",
168
+ request: {
169
+ body: {
170
+ content: { "application/json": { schema: UpdateProfileBodySchema } },
171
+ required: true,
172
+ },
173
+ },
174
+ responses: {
175
+ 200: { content: { "application/json": { schema: CustomerResponse } }, description: "Updated" },
176
+ ...errorResponses,
177
+ },
178
+ });
179
+
180
+ export const createAddressRoute = createRoute({
181
+ method: "post",
182
+ path: "/addresses",
183
+ tags: ["Customer Portal"],
184
+ summary: "Create a customer address",
185
+ request: {
186
+ body: {
187
+ content: { "application/json": { schema: CreateAddressBodySchema } },
188
+ required: true,
189
+ },
190
+ },
191
+ responses: {
192
+ 201: { content: { "application/json": { schema: GenericDataResponse } }, description: "Created" },
193
+ ...errorResponses,
194
+ },
195
+ });
@@ -0,0 +1,138 @@
1
+ import { z, createRoute } from "@hono/zod-openapi";
2
+ import { ErrorSchema, errorResponses } from "./shared.js";
3
+
4
+ // ─── Request Schemas ─────────────────────────────────────────────────────────
5
+
6
+ import { InventoryAdjustBodySchema, InventoryReserveBodySchema, InventoryReleaseBodySchema } from "../../../modules/inventory/schemas.js";
7
+ export { InventoryAdjustBodySchema, InventoryReserveBodySchema, InventoryReleaseBodySchema };
8
+
9
+ export const CreateWarehouseBodySchema = z.object({
10
+ name: z.string().openapi({ example: "Main Warehouse" }),
11
+ code: z.string().optional().openapi({ example: "WH-MAIN" }),
12
+ address: z.record(z.string(), z.unknown()).optional(),
13
+ }).openapi("CreateWarehouseRequest");
14
+
15
+ // ─── Route Definitions ──────────────────────────────────────────────────────
16
+
17
+ export const inventoryCheckRoute = createRoute({
18
+ method: "get",
19
+ path: "/check",
20
+ tags: ["Inventory"],
21
+ summary: "Check inventory for entities",
22
+ request: {
23
+ query: z.object({
24
+ entityIds: z.string().optional().openapi({ example: "uuid1,uuid2" }),
25
+ }),
26
+ },
27
+ responses: {
28
+ 200: {
29
+ content: { "application/json": { schema: z.object({ data: z.record(z.string(), z.unknown()) }) } },
30
+ description: "Inventory levels",
31
+ },
32
+ },
33
+ });
34
+
35
+ export const listWarehousesRoute = createRoute({
36
+ method: "get",
37
+ path: "/warehouses",
38
+ tags: ["Inventory"],
39
+ summary: "List all warehouses",
40
+ responses: {
41
+ 200: {
42
+ content: { "application/json": { schema: z.object({ data: z.record(z.string(), z.unknown()) }) } },
43
+ description: "Warehouses",
44
+ },
45
+ },
46
+ });
47
+
48
+ export const inventoryAdjustRoute = createRoute({
49
+ method: "post",
50
+ path: "/adjust",
51
+ tags: ["Inventory"],
52
+ summary: "Adjust inventory levels",
53
+ description: "Adjusts the on-hand quantity for a given entity/variant in a warehouse.",
54
+ request: {
55
+ body: {
56
+ content: {
57
+ "application/json": { schema: InventoryAdjustBodySchema },
58
+ },
59
+ required: true,
60
+ },
61
+ },
62
+ responses: {
63
+ 200: {
64
+ content: { "application/json": { schema: z.object({ data: z.record(z.string(), z.unknown()) }) } },
65
+ description: "Inventory adjusted.",
66
+ },
67
+ ...errorResponses,
68
+ },
69
+ });
70
+
71
+ export const inventoryReserveRoute = createRoute({
72
+ method: "post",
73
+ path: "/reserve",
74
+ tags: ["Inventory"],
75
+ summary: "Reserve inventory",
76
+ description: "Reserves inventory quantity for an order.",
77
+ request: {
78
+ body: {
79
+ content: {
80
+ "application/json": { schema: InventoryReserveBodySchema },
81
+ },
82
+ required: true,
83
+ },
84
+ },
85
+ responses: {
86
+ 200: {
87
+ content: { "application/json": { schema: z.object({ data: z.object({ reserved: z.literal(true) }) }) } },
88
+ description: "Inventory reserved.",
89
+ },
90
+ ...errorResponses,
91
+ },
92
+ });
93
+
94
+ export const inventoryReleaseRoute = createRoute({
95
+ method: "post",
96
+ path: "/release",
97
+ tags: ["Inventory"],
98
+ summary: "Release reserved inventory",
99
+ description: "Releases previously reserved inventory back to available stock.",
100
+ request: {
101
+ body: {
102
+ content: {
103
+ "application/json": { schema: InventoryReleaseBodySchema },
104
+ },
105
+ required: true,
106
+ },
107
+ },
108
+ responses: {
109
+ 200: {
110
+ content: { "application/json": { schema: z.object({ data: z.object({ released: z.literal(true) }) }) } },
111
+ description: "Inventory released.",
112
+ },
113
+ ...errorResponses,
114
+ },
115
+ });
116
+
117
+ export const createWarehouseRoute = createRoute({
118
+ method: "post",
119
+ path: "/warehouses",
120
+ tags: ["Inventory"],
121
+ summary: "Create a warehouse",
122
+ description: "Creates a new warehouse for inventory management.",
123
+ request: {
124
+ body: {
125
+ content: {
126
+ "application/json": { schema: CreateWarehouseBodySchema },
127
+ },
128
+ required: true,
129
+ },
130
+ },
131
+ responses: {
132
+ 201: {
133
+ content: { "application/json": { schema: z.object({ data: z.record(z.string(), z.unknown()) }) } },
134
+ description: "Warehouse created.",
135
+ },
136
+ ...errorResponses,
137
+ },
138
+ });
@@ -0,0 +1,75 @@
1
+ import { z, createRoute } from "@hono/zod-openapi";
2
+ import { ErrorSchema, errorResponses } from "./shared.js";
3
+
4
+ // ─── Request Schema ──────────────────────────────────────────────────────────
5
+
6
+ export const AttachMediaBodySchema = z.object({
7
+ mediaAssetId: z.string().openapi({ example: "asset-uuid" }),
8
+ entityId: z.string().openapi({ example: "product-uuid" }),
9
+ role: z.enum(["primary", "gallery", "thumbnail", "video", "document"]).openapi({ example: "primary" }),
10
+ variantId: z.string().optional(),
11
+ sortOrder: z.number().optional().openapi({ example: 0 }),
12
+ }).openapi("AttachMediaRequest");
13
+
14
+ // ─── Route Definitions ──────────────────────────────────────────────────────
15
+
16
+ export const getMediaRoute = createRoute({
17
+ method: "get",
18
+ path: "/{id}",
19
+ tags: ["Media"],
20
+ summary: "Get a media asset (redirects to URL)",
21
+ request: {
22
+ params: z.object({
23
+ id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
24
+ }),
25
+ query: z.object({
26
+ signed: z.string().optional().openapi({ example: "true" }),
27
+ }),
28
+ },
29
+ responses: {
30
+ 302: { description: "Redirect to media URL" },
31
+ ...errorResponses,
32
+ },
33
+ });
34
+
35
+ export const deleteMediaRoute = createRoute({
36
+ method: "delete",
37
+ path: "/{id}",
38
+ tags: ["Media"],
39
+ summary: "Delete a media asset",
40
+ request: {
41
+ params: z.object({
42
+ id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
43
+ }),
44
+ },
45
+ responses: {
46
+ 200: {
47
+ content: { "application/json": { schema: z.object({ data: z.object({ deleted: z.literal(true) }) }) } },
48
+ description: "Media deleted.",
49
+ },
50
+ ...errorResponses,
51
+ },
52
+ });
53
+
54
+ export const attachMediaRoute = createRoute({
55
+ method: "post",
56
+ path: "/attach",
57
+ tags: ["Media"],
58
+ summary: "Attach a media asset to an entity",
59
+ description: "Links an uploaded media asset to a catalog entity (product, variant, etc.).",
60
+ request: {
61
+ body: {
62
+ content: {
63
+ "application/json": { schema: AttachMediaBodySchema },
64
+ },
65
+ required: true,
66
+ },
67
+ },
68
+ responses: {
69
+ 201: {
70
+ content: { "application/json": { schema: z.object({ data: z.object({ attached: z.literal(true) }) }) } },
71
+ description: "Media attached to entity.",
72
+ },
73
+ ...errorResponses,
74
+ },
75
+ });
@@ -0,0 +1,104 @@
1
+ import { z, createRoute } from "@hono/zod-openapi";
2
+ import { ErrorSchema, errorResponses } from "./shared.js";
3
+ import { OrderResponse, OrderListResponse } from "./responses.js";
4
+
5
+ // ─── Request Schemas ────────────────────────────────────────────────────────
6
+
7
+ export const ChangeOrderStatusBodySchema = z.object({
8
+ // Accept any string — custom state machines (e.g., BNPL) add states like
9
+ // "payment_initiated", "shipped", "delivered" etc. The order service's
10
+ // state machine validates valid transitions at runtime.
11
+ status: z.string().min(1).openapi({ example: "confirmed" }),
12
+ reason: z.string().optional().openapi({ example: "Payment verified" }),
13
+ }).openapi("ChangeOrderStatusRequest");
14
+
15
+ // ─── Response Schemas ───────────────────────────────────────────────────────
16
+
17
+ export const OrderDataResponseSchema = OrderResponse;
18
+
19
+ // ─── Path Params ────────────────────────────────────────────────────────────
20
+
21
+ const OrderIdParam = z.object({
22
+ id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
23
+ });
24
+
25
+ // ─── Route Definitions ──────────────────────────────────────────────────────
26
+
27
+ export const listOrdersRoute = createRoute({
28
+ method: "get",
29
+ path: "/",
30
+ tags: ["Orders"],
31
+ summary: "List orders",
32
+ request: {
33
+ query: z.object({
34
+ status: z.string().optional(),
35
+ page: z.string().optional(),
36
+ limit: z.string().optional(),
37
+ }),
38
+ },
39
+ responses: {
40
+ 200: {
41
+ content: { "application/json": { schema: OrderListResponse } },
42
+ description: "Success",
43
+ },
44
+ },
45
+ });
46
+
47
+ export const getOrderRoute = createRoute({
48
+ method: "get",
49
+ path: "/{idOrNumber}",
50
+ tags: ["Orders"],
51
+ summary: "Get an order by ID or order number",
52
+ request: {
53
+ params: z.object({
54
+ idOrNumber: z.string().min(1).openapi({ example: "ORD-001" }),
55
+ }),
56
+ },
57
+ responses: {
58
+ 200: {
59
+ content: { "application/json": { schema: OrderDataResponseSchema } },
60
+ description: "Success",
61
+ },
62
+ ...errorResponses,
63
+ },
64
+ });
65
+
66
+ export const getOrderFulfillmentsRoute = createRoute({
67
+ method: "get",
68
+ path: "/{id}/fulfillments",
69
+ tags: ["Orders"],
70
+ summary: "Get fulfillments for an order",
71
+ request: {
72
+ params: OrderIdParam,
73
+ },
74
+ responses: {
75
+ 200: {
76
+ content: { "application/json": { schema: OrderDataResponseSchema } },
77
+ description: "Success",
78
+ },
79
+ ...errorResponses,
80
+ },
81
+ });
82
+
83
+ export const changeOrderStatusRoute = createRoute({
84
+ method: "patch",
85
+ path: "/{id}/status",
86
+ tags: ["Orders"],
87
+ summary: "Change the status of an order",
88
+ request: {
89
+ params: OrderIdParam,
90
+ body: {
91
+ content: {
92
+ "application/json": { schema: ChangeOrderStatusBodySchema },
93
+ },
94
+ required: true,
95
+ },
96
+ },
97
+ responses: {
98
+ 200: {
99
+ content: { "application/json": { schema: OrderDataResponseSchema } },
100
+ description: "Order status updated.",
101
+ },
102
+ ...errorResponses,
103
+ },
104
+ });
@@ -0,0 +1,80 @@
1
+ import { z, createRoute } from "@hono/zod-openapi";
2
+ import { ErrorSchema, errorResponses } from "./shared.js";
3
+
4
+ // ─── Request Schemas ────────────────────────────────────────────────────────
5
+
6
+ import { SetBasePriceBodySchema, CreateModifierBodySchema } from "../../../modules/pricing/schemas.js";
7
+ export { SetBasePriceBodySchema, CreateModifierBodySchema };
8
+
9
+ // ─── Response Schemas ───────────────────────────────────────────────────────
10
+
11
+ export const PricingResponseSchema = z.object({
12
+ data: z.record(z.string(), z.unknown()),
13
+ }).openapi("PricingResponse");
14
+
15
+ // ─── Route Definitions ──────────────────────────────────────────────────────
16
+
17
+ export const listPricesRoute = createRoute({
18
+ method: "get",
19
+ path: "/prices",
20
+ tags: ["Pricing"],
21
+ summary: "List prices",
22
+ request: {
23
+ query: z.object({
24
+ entityId: z.string().optional(),
25
+ variantId: z.string().optional(),
26
+ currency: z.string().optional(),
27
+ customerGroupId: z.string().optional(),
28
+ }),
29
+ },
30
+ responses: {
31
+ 200: {
32
+ content: { "application/json": { schema: PricingResponseSchema } },
33
+ description: "Prices",
34
+ },
35
+ },
36
+ });
37
+
38
+ export const setBasePriceRoute = createRoute({
39
+ method: "post",
40
+ path: "/prices",
41
+ tags: ["Pricing"],
42
+ summary: "Set a base price for a product or variant",
43
+ request: {
44
+ body: {
45
+ content: {
46
+ "application/json": { schema: SetBasePriceBodySchema },
47
+ },
48
+ required: true,
49
+ },
50
+ },
51
+ responses: {
52
+ 201: {
53
+ content: { "application/json": { schema: PricingResponseSchema } },
54
+ description: "Base price set successfully.",
55
+ },
56
+ ...errorResponses,
57
+ },
58
+ });
59
+
60
+ export const createModifierRoute = createRoute({
61
+ method: "post",
62
+ path: "/modifiers",
63
+ tags: ["Pricing"],
64
+ summary: "Create a price modifier",
65
+ request: {
66
+ body: {
67
+ content: {
68
+ "application/json": { schema: CreateModifierBodySchema },
69
+ },
70
+ required: true,
71
+ },
72
+ },
73
+ responses: {
74
+ 201: {
75
+ content: { "application/json": { schema: PricingResponseSchema } },
76
+ description: "Price modifier created successfully.",
77
+ },
78
+ ...errorResponses,
79
+ },
80
+ });
@@ -0,0 +1,110 @@
1
+ import { z, createRoute } from "@hono/zod-openapi";
2
+ import { ErrorSchema, errorResponses, UuidParamSchema } from "./shared.js";
3
+
4
+ // ─── Request Schemas ────────────────────────────────────────────────────────
5
+
6
+ import { CreatePromotionBodySchema } from "../../../modules/promotions/schemas.js";
7
+ export { CreatePromotionBodySchema };
8
+
9
+ export const ValidatePromotionBodySchema = z.object({
10
+ code: z.string().openapi({ example: "SUMMER10" }),
11
+ currency: z.string().length(3).openapi({ example: "USD" }),
12
+ subtotal: z.number().openapi({ example: 100 }),
13
+ lineItems: z.array(z.object({
14
+ entityId: z.string(),
15
+ entityType: z.string(),
16
+ quantity: z.number().int(),
17
+ unitPrice: z.number(),
18
+ totalPrice: z.number(),
19
+ })),
20
+ customerId: z.string().optional(),
21
+ customerGroupIds: z.array(z.string()).optional(),
22
+ }).openapi("ValidatePromotionRequest");
23
+
24
+ // ─── Response Schemas ───────────────────────────────────────────────────────
25
+
26
+ export const PromotionResponseSchema = z.object({
27
+ data: z.record(z.string(), z.unknown()),
28
+ }).openapi("PromotionResponse");
29
+
30
+ // ─── Path Params ────────────────────────────────────────────────────────────
31
+
32
+ const PromotionIdParam = z.object({
33
+ id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
34
+ });
35
+
36
+ // ─── Route Definitions ──────────────────────────────────────────────────────
37
+
38
+ export const listActivePromotionsRoute = createRoute({
39
+ method: "get",
40
+ path: "/",
41
+ tags: ["Promotions"],
42
+ summary: "List active promotions",
43
+ responses: {
44
+ 200: {
45
+ content: { "application/json": { schema: PromotionResponseSchema } },
46
+ description: "Active promotions",
47
+ },
48
+ },
49
+ });
50
+
51
+ export const createPromotionRoute = createRoute({
52
+ method: "post",
53
+ path: "/",
54
+ tags: ["Promotions"],
55
+ summary: "Create a new promotion",
56
+ request: {
57
+ body: {
58
+ content: {
59
+ "application/json": { schema: CreatePromotionBodySchema },
60
+ },
61
+ required: true,
62
+ },
63
+ },
64
+ responses: {
65
+ 201: {
66
+ content: { "application/json": { schema: PromotionResponseSchema } },
67
+ description: "Promotion created successfully.",
68
+ },
69
+ ...errorResponses,
70
+ },
71
+ });
72
+
73
+ export const validatePromotionRoute = createRoute({
74
+ method: "post",
75
+ path: "/validate",
76
+ tags: ["Promotions"],
77
+ summary: "Validate a promotion code against a cart",
78
+ request: {
79
+ body: {
80
+ content: {
81
+ "application/json": { schema: ValidatePromotionBodySchema },
82
+ },
83
+ required: true,
84
+ },
85
+ },
86
+ responses: {
87
+ 200: {
88
+ content: { "application/json": { schema: PromotionResponseSchema } },
89
+ description: "Promotion validation result.",
90
+ },
91
+ ...errorResponses,
92
+ },
93
+ });
94
+
95
+ export const deactivatePromotionRoute = createRoute({
96
+ method: "post",
97
+ path: "/{id}/deactivate",
98
+ tags: ["Promotions"],
99
+ summary: "Deactivate a promotion",
100
+ request: {
101
+ params: PromotionIdParam,
102
+ },
103
+ responses: {
104
+ 200: {
105
+ content: { "application/json": { schema: PromotionResponseSchema } },
106
+ description: "Promotion deactivated.",
107
+ },
108
+ ...errorResponses,
109
+ },
110
+ });