@unifiedcommerce/core 0.2.0 → 0.2.2
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.
- package/package.json +2 -1
- package/src/adapters/console-email.ts +43 -0
- package/src/auth/access.ts +187 -0
- package/src/auth/auth-schema.ts +139 -0
- package/src/auth/middleware.ts +161 -0
- package/src/auth/org.ts +41 -0
- package/src/auth/permissions.ts +28 -0
- package/src/auth/setup.ts +171 -0
- package/src/auth/system-actor.ts +19 -0
- package/src/auth/types.ts +10 -0
- package/src/config/defaults.ts +82 -0
- package/src/config/define-config.ts +53 -0
- package/src/config/types.ts +301 -0
- package/src/generated/plugin-capabilities.d.ts +20 -0
- package/src/generated/plugin-manifest.ts +23 -0
- package/src/generated/plugin-repositories.d.ts +20 -0
- package/src/hooks/checkout-completion.ts +262 -0
- package/src/hooks/checkout.ts +677 -0
- package/src/hooks/order-emails.ts +62 -0
- package/src/index.ts +215 -0
- package/src/interfaces/mcp/agent-prompt.ts +174 -0
- package/src/interfaces/mcp/context-enrichment.ts +177 -0
- package/src/interfaces/mcp/server.ts +47 -0
- package/src/interfaces/mcp/tool-builder.ts +261 -0
- package/src/interfaces/mcp/tools/analytics.ts +76 -0
- package/src/interfaces/mcp/tools/cart.ts +57 -0
- package/src/interfaces/mcp/tools/catalog.ts +299 -0
- package/src/interfaces/mcp/tools/index.ts +22 -0
- package/src/interfaces/mcp/tools/inventory.ts +161 -0
- package/src/interfaces/mcp/tools/orders.ts +104 -0
- package/src/interfaces/mcp/tools/pricing.ts +94 -0
- package/src/interfaces/mcp/tools/promotions.ts +106 -0
- package/src/interfaces/mcp/tools/registry.ts +101 -0
- package/src/interfaces/mcp/tools/search.ts +42 -0
- package/src/interfaces/mcp/tools/webhooks.ts +48 -0
- package/src/interfaces/mcp/transport.ts +128 -0
- package/src/interfaces/rest/customer-portal.ts +299 -0
- package/src/interfaces/rest/index.ts +74 -0
- package/src/interfaces/rest/router.ts +333 -0
- package/src/interfaces/rest/routes/admin-jobs.ts +58 -0
- package/src/interfaces/rest/routes/audit.ts +50 -0
- package/src/interfaces/rest/routes/carts.ts +89 -0
- package/src/interfaces/rest/routes/catalog.ts +493 -0
- package/src/interfaces/rest/routes/checkout.ts +284 -0
- package/src/interfaces/rest/routes/inventory.ts +70 -0
- package/src/interfaces/rest/routes/media.ts +86 -0
- package/src/interfaces/rest/routes/orders.ts +78 -0
- package/src/interfaces/rest/routes/payments.ts +60 -0
- package/src/interfaces/rest/routes/pricing.ts +57 -0
- package/src/interfaces/rest/routes/promotions.ts +93 -0
- package/src/interfaces/rest/routes/search.ts +71 -0
- package/src/interfaces/rest/routes/webhooks.ts +46 -0
- package/src/interfaces/rest/schemas/admin-jobs.ts +40 -0
- package/src/interfaces/rest/schemas/audit.ts +46 -0
- package/src/interfaces/rest/schemas/carts.ts +125 -0
- package/src/interfaces/rest/schemas/catalog.ts +450 -0
- package/src/interfaces/rest/schemas/checkout.ts +66 -0
- package/src/interfaces/rest/schemas/customer-portal.ts +195 -0
- package/src/interfaces/rest/schemas/inventory.ts +138 -0
- package/src/interfaces/rest/schemas/media.ts +75 -0
- package/src/interfaces/rest/schemas/orders.ts +104 -0
- package/src/interfaces/rest/schemas/pricing.ts +80 -0
- package/src/interfaces/rest/schemas/promotions.ts +110 -0
- package/src/interfaces/rest/schemas/responses.ts +85 -0
- package/src/interfaces/rest/schemas/search.ts +58 -0
- package/src/interfaces/rest/schemas/shared.ts +62 -0
- package/src/interfaces/rest/schemas/webhooks.ts +68 -0
- package/src/interfaces/rest/utils.ts +104 -0
- package/src/interfaces/rest/webhook-router.ts +50 -0
- package/src/kernel/compensation/executor.ts +61 -0
- package/src/kernel/compensation/types.ts +26 -0
- package/src/kernel/database/adapter.ts +21 -0
- package/src/kernel/database/drizzle-db.ts +56 -0
- package/src/kernel/database/migrate.ts +76 -0
- package/src/kernel/database/plugin-types.ts +34 -0
- package/src/kernel/database/schema.ts +49 -0
- package/src/kernel/database/scoped-db.ts +68 -0
- package/src/kernel/database/tx-context.ts +46 -0
- package/src/kernel/error-mapper.ts +15 -0
- package/src/kernel/errors.ts +89 -0
- package/src/kernel/factory/repository-factory.ts +244 -0
- package/src/kernel/hooks/create-context.ts +43 -0
- package/src/kernel/hooks/executor.ts +88 -0
- package/src/kernel/hooks/registry.ts +74 -0
- package/src/kernel/hooks/types.ts +52 -0
- package/src/kernel/http-error.ts +44 -0
- package/src/kernel/jobs/adapter.ts +36 -0
- package/src/kernel/jobs/drizzle-adapter.ts +58 -0
- package/src/kernel/jobs/runner.ts +153 -0
- package/src/kernel/jobs/schema.ts +46 -0
- package/src/kernel/jobs/types.ts +30 -0
- package/src/kernel/local-api.ts +187 -0
- package/src/kernel/plugin/manifest.ts +271 -0
- package/src/kernel/query/executor.ts +184 -0
- package/src/kernel/query/registry.ts +46 -0
- package/src/kernel/result.ts +33 -0
- package/src/kernel/schema/extra-columns.ts +37 -0
- package/src/kernel/service-registry.ts +76 -0
- package/src/kernel/service-timing.ts +89 -0
- package/src/kernel/state-machine/machine.ts +101 -0
- package/src/modules/analytics/drizzle-adapter.ts +426 -0
- package/src/modules/analytics/hooks.ts +11 -0
- package/src/modules/analytics/models.ts +125 -0
- package/src/modules/analytics/repository/index.ts +6 -0
- package/src/modules/analytics/service.ts +245 -0
- package/src/modules/analytics/types.ts +180 -0
- package/src/modules/audit/hooks.ts +78 -0
- package/src/modules/audit/schema.ts +33 -0
- package/src/modules/audit/service.ts +151 -0
- package/src/modules/cart/access.ts +27 -0
- package/src/modules/cart/matcher.ts +26 -0
- package/src/modules/cart/repository/index.ts +234 -0
- package/src/modules/cart/schema.ts +42 -0
- package/src/modules/cart/schemas.ts +38 -0
- package/src/modules/cart/service.ts +541 -0
- package/src/modules/catalog/repository/index.ts +772 -0
- package/src/modules/catalog/schema.ts +203 -0
- package/src/modules/catalog/schemas.ts +104 -0
- package/src/modules/catalog/service.ts +1544 -0
- package/src/modules/customers/repository/index.ts +327 -0
- package/src/modules/customers/schema.ts +64 -0
- package/src/modules/customers/service.ts +171 -0
- package/src/modules/fulfillment/repository/index.ts +426 -0
- package/src/modules/fulfillment/schema.ts +101 -0
- package/src/modules/fulfillment/service.ts +555 -0
- package/src/modules/fulfillment/types.ts +59 -0
- package/src/modules/inventory/repository/index.ts +509 -0
- package/src/modules/inventory/schema.ts +94 -0
- package/src/modules/inventory/schemas.ts +38 -0
- package/src/modules/inventory/service.ts +490 -0
- package/src/modules/media/adapter.ts +17 -0
- package/src/modules/media/repository/index.ts +274 -0
- package/src/modules/media/schema.ts +41 -0
- package/src/modules/media/service.ts +151 -0
- package/src/modules/orders/repository/index.ts +287 -0
- package/src/modules/orders/schema.ts +66 -0
- package/src/modules/orders/service.ts +619 -0
- package/src/modules/orders/stale-order-cleanup.ts +76 -0
- package/src/modules/organization/service.ts +191 -0
- package/src/modules/payments/adapter.ts +47 -0
- package/src/modules/payments/repository/index.ts +6 -0
- package/src/modules/payments/service.ts +107 -0
- package/src/modules/pricing/repository/index.ts +291 -0
- package/src/modules/pricing/schema.ts +71 -0
- package/src/modules/pricing/schemas.ts +38 -0
- package/src/modules/pricing/service.ts +494 -0
- package/src/modules/promotions/repository/index.ts +325 -0
- package/src/modules/promotions/schema.ts +62 -0
- package/src/modules/promotions/schemas.ts +38 -0
- package/src/modules/promotions/service.ts +598 -0
- package/src/modules/search/adapter.ts +57 -0
- package/src/modules/search/hooks.ts +12 -0
- package/src/modules/search/repository/index.ts +6 -0
- package/src/modules/search/service.ts +315 -0
- package/src/modules/shipping/calculator.ts +188 -0
- package/src/modules/shipping/repository/index.ts +6 -0
- package/src/modules/shipping/service.ts +51 -0
- package/src/modules/tax/adapter.ts +60 -0
- package/src/modules/tax/repository/index.ts +6 -0
- package/src/modules/tax/service.ts +53 -0
- package/src/modules/webhooks/hook.ts +34 -0
- package/src/modules/webhooks/repository/index.ts +278 -0
- package/src/modules/webhooks/schema.ts +56 -0
- package/src/modules/webhooks/service.ts +117 -0
- package/src/modules/webhooks/signing.ts +6 -0
- package/src/modules/webhooks/ssrf-guard.ts +71 -0
- package/src/modules/webhooks/tasks.ts +52 -0
- package/src/modules/webhooks/worker.ts +134 -0
- package/src/runtime/commerce.ts +145 -0
- package/src/runtime/kernel.ts +426 -0
- package/src/runtime/logger.ts +36 -0
- package/src/runtime/server.ts +355 -0
- package/src/runtime/shutdown.ts +43 -0
- package/src/test-utils/create-pglite-adapter.ts +129 -0
- package/src/test-utils/create-plugin-test-app.ts +128 -0
- package/src/test-utils/create-repository-test-harness.ts +16 -0
- package/src/test-utils/create-test-config.ts +190 -0
- package/src/test-utils/create-test-kernel.ts +7 -0
- package/src/test-utils/create-test-plugin-context.ts +75 -0
- package/src/test-utils/rest-api-test-utils.ts +265 -0
- package/src/test-utils/test-actors.ts +62 -0
- package/src/test-utils/typed-hooks.ts +54 -0
- package/src/types/commerce-types.ts +34 -0
- package/src/utils/id.ts +3 -0
- package/src/utils/logger.ts +18 -0
- package/src/utils/pagination.ts +22 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { z, createRoute } from "@hono/zod-openapi";
|
|
2
|
+
import { errorResponses } from "./shared.js";
|
|
3
|
+
import { CatalogEntityResponse, CatalogEntityListResponse } from "./responses.js";
|
|
4
|
+
import {
|
|
5
|
+
CreateEntityBodySchema,
|
|
6
|
+
UpdateEntityBodySchema,
|
|
7
|
+
SetAttributesBodySchema,
|
|
8
|
+
CreateCategoryBodySchema,
|
|
9
|
+
UpdateCategoryBodySchema,
|
|
10
|
+
CreateBrandBodySchema,
|
|
11
|
+
UpdateBrandBodySchema,
|
|
12
|
+
CreateOptionTypeBodySchema,
|
|
13
|
+
CreateOptionValueBodySchema,
|
|
14
|
+
CreateVariantBodySchema,
|
|
15
|
+
GenerateVariantsBodySchema,
|
|
16
|
+
} from "../../../modules/catalog/schemas.js";
|
|
17
|
+
|
|
18
|
+
// ─── Response Schemas ───────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
const DataResponse = CatalogEntityResponse;
|
|
21
|
+
const DataWithPaginationResponse = CatalogEntityListResponse;
|
|
22
|
+
|
|
23
|
+
// ─── Path Params ────────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
const EntityIdOrSlugParam = z.object({
|
|
26
|
+
idOrSlug: z.string().min(1).openapi({ example: "my-product" }),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const EntityIdParam = z.object({
|
|
30
|
+
id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const EntityIdLocaleParam = z.object({
|
|
34
|
+
id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
35
|
+
locale: z.string().min(1).openapi({ example: "en" }),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const CategoryIdParam = z.object({
|
|
39
|
+
categoryId: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const BrandIdParam = z.object({
|
|
43
|
+
brandId: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const EntityCategoryParam = z.object({
|
|
47
|
+
id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
48
|
+
categoryId: z.uuid().openapi({ example: "660e8400-e29b-41d4-a716-446655440000" }),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const EntityBrandParam = z.object({
|
|
52
|
+
id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
53
|
+
brandId: z.uuid().openapi({ example: "660e8400-e29b-41d4-a716-446655440000" }),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// ─── GET Route Definitions ─────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
export const listEntitiesRoute = createRoute({
|
|
59
|
+
method: "get",
|
|
60
|
+
path: "/entities",
|
|
61
|
+
tags: ["Catalog"],
|
|
62
|
+
summary: "List catalog entities",
|
|
63
|
+
request: {
|
|
64
|
+
query: z.object({
|
|
65
|
+
type: z.string().optional(),
|
|
66
|
+
status: z.string().optional(),
|
|
67
|
+
category: z.string().optional(),
|
|
68
|
+
brand: z.string().optional(),
|
|
69
|
+
include: z.string().optional(),
|
|
70
|
+
sort: z.string().optional(),
|
|
71
|
+
page: z.string().optional(),
|
|
72
|
+
limit: z.string().optional(),
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
responses: {
|
|
76
|
+
200: { content: { "application/json": { schema: DataWithPaginationResponse } }, description: "Success" },
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
export const getEntityRoute = createRoute({
|
|
81
|
+
method: "get",
|
|
82
|
+
path: "/entities/{idOrSlug}",
|
|
83
|
+
tags: ["Catalog"],
|
|
84
|
+
summary: "Get a catalog entity by ID or slug",
|
|
85
|
+
request: {
|
|
86
|
+
params: EntityIdOrSlugParam,
|
|
87
|
+
query: z.object({ include: z.string().optional() }),
|
|
88
|
+
},
|
|
89
|
+
responses: {
|
|
90
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Success" },
|
|
91
|
+
...errorResponses,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export const getEntityAttributesRoute = createRoute({
|
|
96
|
+
method: "get",
|
|
97
|
+
path: "/entities/{id}/attributes/{locale}",
|
|
98
|
+
tags: ["Catalog"],
|
|
99
|
+
summary: "Get entity attributes for a locale",
|
|
100
|
+
request: { params: EntityIdLocaleParam },
|
|
101
|
+
responses: {
|
|
102
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Success" },
|
|
103
|
+
...errorResponses,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export const listCategoriesRoute = createRoute({
|
|
108
|
+
method: "get",
|
|
109
|
+
path: "/categories",
|
|
110
|
+
tags: ["Catalog"],
|
|
111
|
+
summary: "List all categories",
|
|
112
|
+
responses: {
|
|
113
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Success" },
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const listBrandsRoute = createRoute({
|
|
118
|
+
method: "get",
|
|
119
|
+
path: "/brands",
|
|
120
|
+
tags: ["Catalog"],
|
|
121
|
+
summary: "List all brands",
|
|
122
|
+
responses: {
|
|
123
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Success" },
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// ─── DELETE Route Definitions ──────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
export const deleteEntityRoute = createRoute({
|
|
130
|
+
method: "delete",
|
|
131
|
+
path: "/entities/{id}",
|
|
132
|
+
tags: ["Catalog"],
|
|
133
|
+
summary: "Delete a catalog entity",
|
|
134
|
+
request: { params: EntityIdParam },
|
|
135
|
+
responses: {
|
|
136
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ deleted: z.literal(true) }) }) } }, description: "Deleted" },
|
|
137
|
+
...errorResponses,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
export const deleteCategoryRoute = createRoute({
|
|
142
|
+
method: "delete",
|
|
143
|
+
path: "/categories/{categoryId}",
|
|
144
|
+
tags: ["Catalog"],
|
|
145
|
+
summary: "Delete a category",
|
|
146
|
+
request: { params: CategoryIdParam },
|
|
147
|
+
responses: {
|
|
148
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ deleted: z.literal(true) }) }) } }, description: "Deleted" },
|
|
149
|
+
...errorResponses,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export const deleteBrandRoute = createRoute({
|
|
154
|
+
method: "delete",
|
|
155
|
+
path: "/brands/{brandId}",
|
|
156
|
+
tags: ["Catalog"],
|
|
157
|
+
summary: "Delete a brand",
|
|
158
|
+
request: { params: BrandIdParam },
|
|
159
|
+
responses: {
|
|
160
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ deleted: z.literal(true) }) }) } }, description: "Deleted" },
|
|
161
|
+
...errorResponses,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export const removeEntityFromCategoryRoute = createRoute({
|
|
166
|
+
method: "delete",
|
|
167
|
+
path: "/entities/{id}/categories/{categoryId}",
|
|
168
|
+
tags: ["Catalog"],
|
|
169
|
+
summary: "Remove entity from category",
|
|
170
|
+
request: { params: EntityCategoryParam },
|
|
171
|
+
responses: {
|
|
172
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ unlinked: z.literal(true) }) }) } }, description: "Unlinked" },
|
|
173
|
+
...errorResponses,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
export const removeEntityFromBrandRoute = createRoute({
|
|
178
|
+
method: "delete",
|
|
179
|
+
path: "/entities/{id}/brands/{brandId}",
|
|
180
|
+
tags: ["Catalog"],
|
|
181
|
+
summary: "Remove entity from brand",
|
|
182
|
+
request: { params: EntityBrandParam },
|
|
183
|
+
responses: {
|
|
184
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ unlinked: z.literal(true) }) }) } }, description: "Unlinked" },
|
|
185
|
+
...errorResponses,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// ─── No-body POST Route Definitions ────────────────────────────────────────
|
|
190
|
+
|
|
191
|
+
export const publishEntityRoute = createRoute({
|
|
192
|
+
method: "post",
|
|
193
|
+
path: "/entities/{id}/publish",
|
|
194
|
+
tags: ["Catalog"],
|
|
195
|
+
summary: "Publish a catalog entity",
|
|
196
|
+
request: { params: EntityIdParam },
|
|
197
|
+
responses: {
|
|
198
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Published" },
|
|
199
|
+
...errorResponses,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
export const archiveEntityRoute = createRoute({
|
|
204
|
+
method: "post",
|
|
205
|
+
path: "/entities/{id}/archive",
|
|
206
|
+
tags: ["Catalog"],
|
|
207
|
+
summary: "Archive a catalog entity",
|
|
208
|
+
request: { params: EntityIdParam },
|
|
209
|
+
responses: {
|
|
210
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Archived" },
|
|
211
|
+
...errorResponses,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
export const discontinueEntityRoute = createRoute({
|
|
216
|
+
method: "post",
|
|
217
|
+
path: "/entities/{id}/discontinue",
|
|
218
|
+
tags: ["Catalog"],
|
|
219
|
+
summary: "Discontinue a catalog entity",
|
|
220
|
+
request: { params: EntityIdParam },
|
|
221
|
+
responses: {
|
|
222
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Discontinued" },
|
|
223
|
+
...errorResponses,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
export const addEntityToCategoryRoute = createRoute({
|
|
228
|
+
method: "post",
|
|
229
|
+
path: "/entities/{id}/categories/{categoryId}",
|
|
230
|
+
tags: ["Catalog"],
|
|
231
|
+
summary: "Add entity to a category",
|
|
232
|
+
request: { params: EntityCategoryParam },
|
|
233
|
+
responses: {
|
|
234
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ linked: z.literal(true) }) }) } }, description: "Linked" },
|
|
235
|
+
...errorResponses,
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
export const addEntityToBrandRoute = createRoute({
|
|
240
|
+
method: "post",
|
|
241
|
+
path: "/entities/{id}/brands/{brandId}",
|
|
242
|
+
tags: ["Catalog"],
|
|
243
|
+
summary: "Add entity to a brand",
|
|
244
|
+
request: { params: EntityBrandParam },
|
|
245
|
+
responses: {
|
|
246
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ linked: z.literal(true) }) }) } }, description: "Linked" },
|
|
247
|
+
...errorResponses,
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// ─── Mutation Route Definitions ─────────────────────────────────────────────
|
|
252
|
+
|
|
253
|
+
const OptionTypeIdParam = z.object({
|
|
254
|
+
optionTypeId: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
export const createEntityRoute = createRoute({
|
|
258
|
+
method: "post",
|
|
259
|
+
path: "/entities",
|
|
260
|
+
tags: ["Catalog"],
|
|
261
|
+
summary: "Create a catalog entity",
|
|
262
|
+
request: {
|
|
263
|
+
body: {
|
|
264
|
+
content: { "application/json": { schema: CreateEntityBodySchema } },
|
|
265
|
+
required: true,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
responses: {
|
|
269
|
+
201: { content: { "application/json": { schema: DataResponse } }, description: "Created" },
|
|
270
|
+
...errorResponses,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
export const updateEntityRoute = createRoute({
|
|
275
|
+
method: "patch",
|
|
276
|
+
path: "/entities/{id}",
|
|
277
|
+
tags: ["Catalog"],
|
|
278
|
+
summary: "Update a catalog entity",
|
|
279
|
+
request: {
|
|
280
|
+
params: EntityIdParam,
|
|
281
|
+
body: {
|
|
282
|
+
content: { "application/json": { schema: UpdateEntityBodySchema } },
|
|
283
|
+
required: true,
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
responses: {
|
|
287
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Updated" },
|
|
288
|
+
...errorResponses,
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
export const setEntityAttributesRoute = createRoute({
|
|
293
|
+
method: "put",
|
|
294
|
+
path: "/entities/{id}/attributes/{locale}",
|
|
295
|
+
tags: ["Catalog"],
|
|
296
|
+
summary: "Set entity attributes for a locale",
|
|
297
|
+
request: {
|
|
298
|
+
params: EntityIdLocaleParam,
|
|
299
|
+
body: {
|
|
300
|
+
content: { "application/json": { schema: SetAttributesBodySchema } },
|
|
301
|
+
required: true,
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
responses: {
|
|
305
|
+
200: { content: { "application/json": { schema: z.object({ data: z.object({ updated: z.literal(true) }) }) } }, description: "Updated" },
|
|
306
|
+
...errorResponses,
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
export const createCategoryRoute = createRoute({
|
|
311
|
+
method: "post",
|
|
312
|
+
path: "/categories",
|
|
313
|
+
tags: ["Catalog"],
|
|
314
|
+
summary: "Create a category",
|
|
315
|
+
request: {
|
|
316
|
+
body: {
|
|
317
|
+
content: { "application/json": { schema: CreateCategoryBodySchema } },
|
|
318
|
+
required: true,
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
responses: {
|
|
322
|
+
201: { content: { "application/json": { schema: DataResponse } }, description: "Created" },
|
|
323
|
+
...errorResponses,
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
export const updateCategoryRoute = createRoute({
|
|
328
|
+
method: "patch",
|
|
329
|
+
path: "/categories/{categoryId}",
|
|
330
|
+
tags: ["Catalog"],
|
|
331
|
+
summary: "Update a category",
|
|
332
|
+
request: {
|
|
333
|
+
params: CategoryIdParam,
|
|
334
|
+
body: {
|
|
335
|
+
content: { "application/json": { schema: UpdateCategoryBodySchema } },
|
|
336
|
+
required: true,
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
responses: {
|
|
340
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Updated" },
|
|
341
|
+
...errorResponses,
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
export const createBrandRoute = createRoute({
|
|
346
|
+
method: "post",
|
|
347
|
+
path: "/brands",
|
|
348
|
+
tags: ["Catalog"],
|
|
349
|
+
summary: "Create a brand",
|
|
350
|
+
request: {
|
|
351
|
+
body: {
|
|
352
|
+
content: { "application/json": { schema: CreateBrandBodySchema } },
|
|
353
|
+
required: true,
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
responses: {
|
|
357
|
+
201: { content: { "application/json": { schema: DataResponse } }, description: "Created" },
|
|
358
|
+
...errorResponses,
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
export const updateBrandRoute = createRoute({
|
|
363
|
+
method: "patch",
|
|
364
|
+
path: "/brands/{brandId}",
|
|
365
|
+
tags: ["Catalog"],
|
|
366
|
+
summary: "Update a brand",
|
|
367
|
+
request: {
|
|
368
|
+
params: BrandIdParam,
|
|
369
|
+
body: {
|
|
370
|
+
content: { "application/json": { schema: UpdateBrandBodySchema } },
|
|
371
|
+
required: true,
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
responses: {
|
|
375
|
+
200: { content: { "application/json": { schema: DataResponse } }, description: "Updated" },
|
|
376
|
+
...errorResponses,
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
export const createOptionTypeRoute = createRoute({
|
|
381
|
+
method: "post",
|
|
382
|
+
path: "/entities/{id}/options",
|
|
383
|
+
tags: ["Catalog"],
|
|
384
|
+
summary: "Create an option type for an entity",
|
|
385
|
+
request: {
|
|
386
|
+
params: EntityIdParam,
|
|
387
|
+
body: {
|
|
388
|
+
content: { "application/json": { schema: CreateOptionTypeBodySchema } },
|
|
389
|
+
required: true,
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
responses: {
|
|
393
|
+
201: { content: { "application/json": { schema: DataResponse } }, description: "Created" },
|
|
394
|
+
...errorResponses,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
export const createOptionValueRoute = createRoute({
|
|
399
|
+
method: "post",
|
|
400
|
+
path: "/options/{optionTypeId}/values",
|
|
401
|
+
tags: ["Catalog"],
|
|
402
|
+
summary: "Create an option value",
|
|
403
|
+
request: {
|
|
404
|
+
params: OptionTypeIdParam,
|
|
405
|
+
body: {
|
|
406
|
+
content: { "application/json": { schema: CreateOptionValueBodySchema } },
|
|
407
|
+
required: true,
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
responses: {
|
|
411
|
+
201: { content: { "application/json": { schema: DataResponse } }, description: "Created" },
|
|
412
|
+
...errorResponses,
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
export const createVariantRoute = createRoute({
|
|
417
|
+
method: "post",
|
|
418
|
+
path: "/entities/{id}/variants",
|
|
419
|
+
tags: ["Catalog"],
|
|
420
|
+
summary: "Create a variant for an entity",
|
|
421
|
+
request: {
|
|
422
|
+
params: EntityIdParam,
|
|
423
|
+
body: {
|
|
424
|
+
content: { "application/json": { schema: CreateVariantBodySchema } },
|
|
425
|
+
required: true,
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
responses: {
|
|
429
|
+
201: { content: { "application/json": { schema: DataResponse } }, description: "Created" },
|
|
430
|
+
...errorResponses,
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
export const generateVariantsRoute = createRoute({
|
|
435
|
+
method: "post",
|
|
436
|
+
path: "/entities/{id}/variants/generate",
|
|
437
|
+
tags: ["Catalog"],
|
|
438
|
+
summary: "Generate variants from option combinations",
|
|
439
|
+
request: {
|
|
440
|
+
params: EntityIdParam,
|
|
441
|
+
body: {
|
|
442
|
+
content: { "application/json": { schema: GenerateVariantsBodySchema } },
|
|
443
|
+
required: true,
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
responses: {
|
|
447
|
+
201: { content: { "application/json": { schema: DataResponse } }, description: "Generated" },
|
|
448
|
+
...errorResponses,
|
|
449
|
+
},
|
|
450
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z, createRoute } from "@hono/zod-openapi";
|
|
2
|
+
import { ErrorSchema, errorResponses } from "./shared.js";
|
|
3
|
+
|
|
4
|
+
// ─── Request Schema ──────────────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
export const CheckoutBodySchema = z.object({
|
|
7
|
+
cartId: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
|
|
8
|
+
paymentMethodId: z.string().openapi({ example: "pm_card_visa" }),
|
|
9
|
+
customerId: z.string().optional().openapi({ example: "customer-uuid-or-user-id" }),
|
|
10
|
+
customerGroupIds: z.array(z.string()).optional(),
|
|
11
|
+
currency: z.string().length(3).optional().openapi({ example: "USD" }),
|
|
12
|
+
promotionCodes: z.array(z.string()).optional().openapi({ example: ["SUMMER10"] }),
|
|
13
|
+
shippingAddress: z.object({
|
|
14
|
+
line1: z.string(),
|
|
15
|
+
line2: z.string().optional(),
|
|
16
|
+
city: z.string(),
|
|
17
|
+
state: z.string().optional(),
|
|
18
|
+
postalCode: z.string(),
|
|
19
|
+
country: z.string(),
|
|
20
|
+
}).optional(),
|
|
21
|
+
}).openapi("CheckoutRequest");
|
|
22
|
+
|
|
23
|
+
// ─── Response Schema ─────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
export const OrderResponseSchema = z.object({
|
|
26
|
+
data: z.object({
|
|
27
|
+
id: z.uuid(),
|
|
28
|
+
orderNumber: z.string(),
|
|
29
|
+
status: z.string(),
|
|
30
|
+
currency: z.string(),
|
|
31
|
+
subtotal: z.number(),
|
|
32
|
+
taxTotal: z.number(),
|
|
33
|
+
shippingTotal: z.number(),
|
|
34
|
+
discountTotal: z.number(),
|
|
35
|
+
grandTotal: z.number(),
|
|
36
|
+
placedAt: z.string(),
|
|
37
|
+
}),
|
|
38
|
+
meta: z.object({
|
|
39
|
+
hookErrors: z.array(z.string()),
|
|
40
|
+
}).optional(),
|
|
41
|
+
}).openapi("CheckoutResponse");
|
|
42
|
+
|
|
43
|
+
// ─── Route Definition ────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
export const checkoutRoute = createRoute({
|
|
46
|
+
method: "post",
|
|
47
|
+
path: "/",
|
|
48
|
+
tags: ["Checkout"],
|
|
49
|
+
summary: "Process checkout and create an order",
|
|
50
|
+
description: "Validates cart, reserves inventory, authorizes payment, calculates tax/shipping, and creates the order.",
|
|
51
|
+
request: {
|
|
52
|
+
body: {
|
|
53
|
+
content: {
|
|
54
|
+
"application/json": { schema: CheckoutBodySchema },
|
|
55
|
+
},
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
responses: {
|
|
60
|
+
201: {
|
|
61
|
+
content: { "application/json": { schema: OrderResponseSchema } },
|
|
62
|
+
description: "Order created successfully.",
|
|
63
|
+
},
|
|
64
|
+
...errorResponses,
|
|
65
|
+
},
|
|
66
|
+
});
|