@unifiedcommerce/core 0.1.0 → 0.1.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.
- package/package.json +1 -2
- package/src/adapters/console-email.ts +0 -43
- package/src/auth/access.ts +0 -187
- package/src/auth/auth-schema.ts +0 -139
- package/src/auth/middleware.ts +0 -161
- package/src/auth/org.ts +0 -41
- package/src/auth/permissions.ts +0 -28
- package/src/auth/setup.ts +0 -169
- package/src/auth/system-actor.ts +0 -19
- package/src/auth/types.ts +0 -10
- package/src/config/defaults.ts +0 -82
- package/src/config/define-config.ts +0 -53
- package/src/config/types.ts +0 -299
- package/src/generated/plugin-capabilities.d.ts +0 -20
- package/src/generated/plugin-manifest.ts +0 -23
- package/src/generated/plugin-repositories.d.ts +0 -20
- package/src/hooks/checkout-completion.ts +0 -262
- package/src/hooks/checkout.ts +0 -677
- package/src/hooks/order-emails.ts +0 -62
- package/src/index.ts +0 -214
- package/src/interfaces/mcp/agent-prompt.ts +0 -174
- package/src/interfaces/mcp/context-enrichment.ts +0 -177
- package/src/interfaces/mcp/server.ts +0 -617
- package/src/interfaces/mcp/transport.ts +0 -68
- package/src/interfaces/rest/customer-portal.ts +0 -299
- package/src/interfaces/rest/index.ts +0 -74
- package/src/interfaces/rest/router.ts +0 -334
- package/src/interfaces/rest/routes/admin-jobs.ts +0 -58
- package/src/interfaces/rest/routes/audit.ts +0 -50
- package/src/interfaces/rest/routes/carts.ts +0 -89
- package/src/interfaces/rest/routes/catalog.ts +0 -493
- package/src/interfaces/rest/routes/checkout.ts +0 -283
- package/src/interfaces/rest/routes/inventory.ts +0 -70
- package/src/interfaces/rest/routes/media.ts +0 -86
- package/src/interfaces/rest/routes/orders.ts +0 -78
- package/src/interfaces/rest/routes/payments.ts +0 -60
- package/src/interfaces/rest/routes/pricing.ts +0 -57
- package/src/interfaces/rest/routes/promotions.ts +0 -92
- package/src/interfaces/rest/routes/search.ts +0 -71
- package/src/interfaces/rest/routes/webhooks.ts +0 -46
- package/src/interfaces/rest/schemas/admin-jobs.ts +0 -40
- package/src/interfaces/rest/schemas/audit.ts +0 -46
- package/src/interfaces/rest/schemas/carts.ts +0 -125
- package/src/interfaces/rest/schemas/catalog.ts +0 -450
- package/src/interfaces/rest/schemas/checkout.ts +0 -66
- package/src/interfaces/rest/schemas/customer-portal.ts +0 -195
- package/src/interfaces/rest/schemas/inventory.ts +0 -138
- package/src/interfaces/rest/schemas/media.ts +0 -75
- package/src/interfaces/rest/schemas/orders.ts +0 -104
- package/src/interfaces/rest/schemas/pricing.ts +0 -80
- package/src/interfaces/rest/schemas/promotions.ts +0 -110
- package/src/interfaces/rest/schemas/responses.ts +0 -85
- package/src/interfaces/rest/schemas/search.ts +0 -58
- package/src/interfaces/rest/schemas/shared.ts +0 -62
- package/src/interfaces/rest/schemas/webhooks.ts +0 -68
- package/src/interfaces/rest/utils.ts +0 -104
- package/src/interfaces/rest/webhook-router.ts +0 -50
- package/src/kernel/compensation/executor.ts +0 -61
- package/src/kernel/compensation/types.ts +0 -26
- package/src/kernel/database/adapter.ts +0 -13
- package/src/kernel/database/drizzle-db.ts +0 -56
- package/src/kernel/database/migrate.ts +0 -76
- package/src/kernel/database/plugin-types.ts +0 -34
- package/src/kernel/database/schema.ts +0 -49
- package/src/kernel/database/scoped-db.ts +0 -68
- package/src/kernel/database/tx-context.ts +0 -46
- package/src/kernel/error-mapper.ts +0 -15
- package/src/kernel/errors.ts +0 -89
- package/src/kernel/factory/repository-factory.ts +0 -242
- package/src/kernel/hooks/create-context.ts +0 -43
- package/src/kernel/hooks/executor.ts +0 -88
- package/src/kernel/hooks/registry.ts +0 -74
- package/src/kernel/hooks/types.ts +0 -52
- package/src/kernel/http-error.ts +0 -44
- package/src/kernel/jobs/adapter.ts +0 -36
- package/src/kernel/jobs/drizzle-adapter.ts +0 -58
- package/src/kernel/jobs/runner.ts +0 -153
- package/src/kernel/jobs/schema.ts +0 -46
- package/src/kernel/jobs/types.ts +0 -30
- package/src/kernel/local-api.ts +0 -185
- package/src/kernel/plugin/manifest.ts +0 -253
- package/src/kernel/query/executor.ts +0 -184
- package/src/kernel/query/registry.ts +0 -46
- package/src/kernel/result.ts +0 -33
- package/src/kernel/schema/extra-columns.ts +0 -37
- package/src/kernel/service-registry.ts +0 -76
- package/src/kernel/service-timing.ts +0 -89
- package/src/kernel/state-machine/machine.ts +0 -101
- package/src/modules/analytics/drizzle-adapter.ts +0 -426
- package/src/modules/analytics/hooks.ts +0 -11
- package/src/modules/analytics/models.ts +0 -125
- package/src/modules/analytics/repository/index.ts +0 -6
- package/src/modules/analytics/service.ts +0 -245
- package/src/modules/analytics/types.ts +0 -180
- package/src/modules/audit/hooks.ts +0 -78
- package/src/modules/audit/schema.ts +0 -33
- package/src/modules/audit/service.ts +0 -151
- package/src/modules/cart/access.ts +0 -27
- package/src/modules/cart/matcher.ts +0 -26
- package/src/modules/cart/repository/index.ts +0 -234
- package/src/modules/cart/schema.ts +0 -42
- package/src/modules/cart/schemas.ts +0 -38
- package/src/modules/cart/service.ts +0 -541
- package/src/modules/catalog/repository/index.ts +0 -772
- package/src/modules/catalog/schema.ts +0 -203
- package/src/modules/catalog/schemas.ts +0 -104
- package/src/modules/catalog/service.ts +0 -1544
- package/src/modules/customers/repository/index.ts +0 -327
- package/src/modules/customers/schema.ts +0 -64
- package/src/modules/customers/service.ts +0 -171
- package/src/modules/fulfillment/repository/index.ts +0 -426
- package/src/modules/fulfillment/schema.ts +0 -101
- package/src/modules/fulfillment/service.ts +0 -555
- package/src/modules/fulfillment/types.ts +0 -59
- package/src/modules/inventory/repository/index.ts +0 -509
- package/src/modules/inventory/schema.ts +0 -94
- package/src/modules/inventory/schemas.ts +0 -38
- package/src/modules/inventory/service.ts +0 -490
- package/src/modules/media/adapter.ts +0 -17
- package/src/modules/media/repository/index.ts +0 -274
- package/src/modules/media/schema.ts +0 -41
- package/src/modules/media/service.ts +0 -151
- package/src/modules/orders/repository/index.ts +0 -287
- package/src/modules/orders/schema.ts +0 -66
- package/src/modules/orders/service.ts +0 -619
- package/src/modules/orders/stale-order-cleanup.ts +0 -76
- package/src/modules/organization/service.ts +0 -191
- package/src/modules/payments/adapter.ts +0 -47
- package/src/modules/payments/repository/index.ts +0 -6
- package/src/modules/payments/service.ts +0 -107
- package/src/modules/pricing/repository/index.ts +0 -291
- package/src/modules/pricing/schema.ts +0 -71
- package/src/modules/pricing/schemas.ts +0 -38
- package/src/modules/pricing/service.ts +0 -494
- package/src/modules/promotions/repository/index.ts +0 -325
- package/src/modules/promotions/schema.ts +0 -62
- package/src/modules/promotions/schemas.ts +0 -38
- package/src/modules/promotions/service.ts +0 -598
- package/src/modules/search/adapter.ts +0 -57
- package/src/modules/search/hooks.ts +0 -12
- package/src/modules/search/repository/index.ts +0 -6
- package/src/modules/search/service.ts +0 -315
- package/src/modules/shipping/calculator.ts +0 -188
- package/src/modules/shipping/repository/index.ts +0 -6
- package/src/modules/shipping/service.ts +0 -51
- package/src/modules/tax/adapter.ts +0 -60
- package/src/modules/tax/repository/index.ts +0 -6
- package/src/modules/tax/service.ts +0 -53
- package/src/modules/webhooks/hook.ts +0 -34
- package/src/modules/webhooks/repository/index.ts +0 -278
- package/src/modules/webhooks/schema.ts +0 -56
- package/src/modules/webhooks/service.ts +0 -117
- package/src/modules/webhooks/signing.ts +0 -6
- package/src/modules/webhooks/ssrf-guard.ts +0 -71
- package/src/modules/webhooks/tasks.ts +0 -52
- package/src/modules/webhooks/worker.ts +0 -134
- package/src/runtime/commerce.ts +0 -145
- package/src/runtime/kernel.ts +0 -419
- package/src/runtime/logger.ts +0 -36
- package/src/runtime/server.ts +0 -349
- package/src/runtime/shutdown.ts +0 -43
- package/src/test-utils/create-pglite-adapter.ts +0 -129
- package/src/test-utils/create-plugin-test-app.ts +0 -128
- package/src/test-utils/create-repository-test-harness.ts +0 -16
- package/src/test-utils/create-test-config.ts +0 -190
- package/src/test-utils/create-test-kernel.ts +0 -7
- package/src/test-utils/create-test-plugin-context.ts +0 -75
- package/src/test-utils/rest-api-test-utils.ts +0 -265
- package/src/test-utils/test-actors.ts +0 -62
- package/src/test-utils/typed-hooks.ts +0 -54
- package/src/types/commerce-types.ts +0 -34
- package/src/utils/id.ts +0 -3
- package/src/utils/logger.ts +0 -18
- package/src/utils/pagination.ts +0 -22
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
-
import type {
|
|
4
|
-
CreateEntityInput,
|
|
5
|
-
UpdateEntityInput,
|
|
6
|
-
CreateCategoryInput,
|
|
7
|
-
UpdateCategoryInput,
|
|
8
|
-
CreateBrandInput,
|
|
9
|
-
UpdateBrandInput,
|
|
10
|
-
CreateOptionTypeInput,
|
|
11
|
-
CreateOptionValueInput,
|
|
12
|
-
CreateVariantInput,
|
|
13
|
-
} from "../../../modules/catalog/schemas.js";
|
|
14
|
-
import type {
|
|
15
|
-
SetAttributesInput,
|
|
16
|
-
VariantGenerationStrategy,
|
|
17
|
-
} from "../../../modules/catalog/service.js";
|
|
18
|
-
import {
|
|
19
|
-
listEntitiesRoute,
|
|
20
|
-
getEntityRoute,
|
|
21
|
-
getEntityAttributesRoute,
|
|
22
|
-
listCategoriesRoute,
|
|
23
|
-
listBrandsRoute,
|
|
24
|
-
deleteEntityRoute,
|
|
25
|
-
deleteCategoryRoute,
|
|
26
|
-
deleteBrandRoute,
|
|
27
|
-
removeEntityFromCategoryRoute,
|
|
28
|
-
removeEntityFromBrandRoute,
|
|
29
|
-
publishEntityRoute,
|
|
30
|
-
archiveEntityRoute,
|
|
31
|
-
discontinueEntityRoute,
|
|
32
|
-
addEntityToCategoryRoute,
|
|
33
|
-
addEntityToBrandRoute,
|
|
34
|
-
createEntityRoute,
|
|
35
|
-
updateEntityRoute,
|
|
36
|
-
setEntityAttributesRoute,
|
|
37
|
-
createCategoryRoute,
|
|
38
|
-
updateCategoryRoute,
|
|
39
|
-
createBrandRoute,
|
|
40
|
-
updateBrandRoute,
|
|
41
|
-
createOptionTypeRoute,
|
|
42
|
-
createOptionValueRoute,
|
|
43
|
-
createVariantRoute,
|
|
44
|
-
generateVariantsRoute,
|
|
45
|
-
} from "../schemas/catalog.js";
|
|
46
|
-
import {
|
|
47
|
-
type AppEnv,
|
|
48
|
-
mapErrorToResponse,
|
|
49
|
-
mapErrorToStatus,
|
|
50
|
-
parseInclude,
|
|
51
|
-
parsePagination,
|
|
52
|
-
parseSort,
|
|
53
|
-
} from "../utils.js";
|
|
54
|
-
|
|
55
|
-
export function catalogRoutes(kernel: Kernel) {
|
|
56
|
-
const router = new OpenAPIHono<AppEnv>();
|
|
57
|
-
|
|
58
|
-
// @ts-expect-error -- openapi handler union return type
|
|
59
|
-
router.openapi(listEntitiesRoute, async (c) => {
|
|
60
|
-
const include = parseInclude(c.req.query("include"));
|
|
61
|
-
const pagination = parsePagination(c.req.query());
|
|
62
|
-
const filter: Record<string, string> = {};
|
|
63
|
-
const type = c.req.query("type");
|
|
64
|
-
const status = c.req.query("status");
|
|
65
|
-
const category = c.req.query("category");
|
|
66
|
-
const brand = c.req.query("brand");
|
|
67
|
-
if (type) filter.type = type;
|
|
68
|
-
if (status) filter.status = status;
|
|
69
|
-
if (category) filter.category = category;
|
|
70
|
-
if (brand) filter.brand = brand;
|
|
71
|
-
|
|
72
|
-
const payload: Record<string, unknown> = {
|
|
73
|
-
filter,
|
|
74
|
-
pagination,
|
|
75
|
-
};
|
|
76
|
-
const sort = parseSort(c.req.query("sort"));
|
|
77
|
-
if (sort) payload.sort = sort;
|
|
78
|
-
|
|
79
|
-
const result = await kernel.services.catalog.list(payload, c.get("actor"));
|
|
80
|
-
|
|
81
|
-
if (!result.ok) {
|
|
82
|
-
return c.json(
|
|
83
|
-
mapErrorToResponse(result.error),
|
|
84
|
-
mapErrorToStatus(result.error),
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let withIncludes = result.value.items;
|
|
89
|
-
if (include.size > 0) {
|
|
90
|
-
const includeOptions = {
|
|
91
|
-
includeAttributes: include.has("attributes"),
|
|
92
|
-
includeVariants: include.has("variants"),
|
|
93
|
-
includeOptionTypes: include.has("optionTypes"),
|
|
94
|
-
includeCategories: include.has("categories"),
|
|
95
|
-
includeBrands: include.has("brands"),
|
|
96
|
-
includeMedia: include.has("media"),
|
|
97
|
-
includeInventory: include.has("inventory"),
|
|
98
|
-
includePricing: include.has("pricing"),
|
|
99
|
-
};
|
|
100
|
-
const hydrated = await Promise.all(
|
|
101
|
-
result.value.items.map(async (item) => {
|
|
102
|
-
const full = await kernel.services.catalog.getById(
|
|
103
|
-
item.id,
|
|
104
|
-
includeOptions,
|
|
105
|
-
);
|
|
106
|
-
return full.ok ? full.value : item;
|
|
107
|
-
}),
|
|
108
|
-
);
|
|
109
|
-
withIncludes = hydrated;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return c.json({
|
|
113
|
-
data: withIncludes,
|
|
114
|
-
meta: {
|
|
115
|
-
pagination: result.value.pagination,
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// @ts-expect-error -- openapi handler union return type
|
|
121
|
-
router.openapi(getEntityRoute, async (c) => {
|
|
122
|
-
const idOrSlug = c.req.param("idOrSlug");
|
|
123
|
-
const include = parseInclude(c.req.query("include"));
|
|
124
|
-
|
|
125
|
-
const isUUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(idOrSlug);
|
|
126
|
-
|
|
127
|
-
const includeOptions = {
|
|
128
|
-
includeAttributes: include.has("attributes"),
|
|
129
|
-
includeVariants: include.has("variants"),
|
|
130
|
-
includeOptionTypes: include.has("optionTypes"),
|
|
131
|
-
includeCategories: include.has("categories"),
|
|
132
|
-
includeBrands: include.has("brands"),
|
|
133
|
-
includeMedia: include.has("media"),
|
|
134
|
-
includeInventory: include.has("inventory"),
|
|
135
|
-
includePricing: include.has("pricing"),
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const actor = c.get("actor");
|
|
139
|
-
const result = isUUID
|
|
140
|
-
? await kernel.services.catalog.getById(idOrSlug, includeOptions, actor)
|
|
141
|
-
: await kernel.services.catalog.getBySlug(idOrSlug, includeOptions, actor);
|
|
142
|
-
|
|
143
|
-
if (!result.ok) {
|
|
144
|
-
return c.json(
|
|
145
|
-
mapErrorToResponse(result.error),
|
|
146
|
-
mapErrorToStatus(result.error),
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return c.json({ data: result.value });
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// @ts-expect-error -- openapi handler union return type
|
|
154
|
-
router.openapi(createEntityRoute, async (c) => {
|
|
155
|
-
const result = await kernel.services.catalog.create(
|
|
156
|
-
c.req.valid("json") as CreateEntityInput,
|
|
157
|
-
c.get("actor"),
|
|
158
|
-
);
|
|
159
|
-
if (!result.ok) {
|
|
160
|
-
return c.json(
|
|
161
|
-
mapErrorToResponse(result.error),
|
|
162
|
-
mapErrorToStatus(result.error),
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return c.json({ data: result.value }, 201);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// @ts-expect-error -- openapi handler union return type
|
|
169
|
-
router.openapi(updateEntityRoute, async (c) => {
|
|
170
|
-
const result = await kernel.services.catalog.update(
|
|
171
|
-
c.req.param("id"),
|
|
172
|
-
c.req.valid("json") as UpdateEntityInput,
|
|
173
|
-
c.get("actor"),
|
|
174
|
-
);
|
|
175
|
-
if (!result.ok) {
|
|
176
|
-
return c.json(
|
|
177
|
-
mapErrorToResponse(result.error),
|
|
178
|
-
mapErrorToStatus(result.error),
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
return c.json({ data: result.value });
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// @ts-expect-error -- openapi handler union return type
|
|
185
|
-
router.openapi(deleteEntityRoute, async (c) => {
|
|
186
|
-
const result = await kernel.services.catalog.delete(
|
|
187
|
-
c.req.param("id"),
|
|
188
|
-
c.get("actor"),
|
|
189
|
-
);
|
|
190
|
-
if (!result.ok) {
|
|
191
|
-
return c.json(
|
|
192
|
-
mapErrorToResponse(result.error),
|
|
193
|
-
mapErrorToStatus(result.error),
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
return c.json({ data: { deleted: true } });
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// @ts-expect-error -- openapi handler union return type
|
|
200
|
-
router.openapi(publishEntityRoute, async (c) => {
|
|
201
|
-
const result = await kernel.services.catalog.publish(
|
|
202
|
-
c.req.param("id"),
|
|
203
|
-
c.get("actor"),
|
|
204
|
-
);
|
|
205
|
-
if (!result.ok)
|
|
206
|
-
return c.json(
|
|
207
|
-
mapErrorToResponse(result.error),
|
|
208
|
-
mapErrorToStatus(result.error),
|
|
209
|
-
);
|
|
210
|
-
return c.json({ data: result.value });
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// @ts-expect-error -- openapi handler union return type
|
|
214
|
-
router.openapi(archiveEntityRoute, async (c) => {
|
|
215
|
-
const result = await kernel.services.catalog.archive(
|
|
216
|
-
c.req.param("id"),
|
|
217
|
-
c.get("actor"),
|
|
218
|
-
);
|
|
219
|
-
if (!result.ok)
|
|
220
|
-
return c.json(
|
|
221
|
-
mapErrorToResponse(result.error),
|
|
222
|
-
mapErrorToStatus(result.error),
|
|
223
|
-
);
|
|
224
|
-
return c.json({ data: result.value });
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// @ts-expect-error -- openapi handler union return type
|
|
228
|
-
router.openapi(discontinueEntityRoute, async (c) => {
|
|
229
|
-
const result = await kernel.services.catalog.discontinue(
|
|
230
|
-
c.req.param("id"),
|
|
231
|
-
c.get("actor"),
|
|
232
|
-
);
|
|
233
|
-
if (!result.ok)
|
|
234
|
-
return c.json(
|
|
235
|
-
mapErrorToResponse(result.error),
|
|
236
|
-
mapErrorToStatus(result.error),
|
|
237
|
-
);
|
|
238
|
-
return c.json({ data: result.value });
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// @ts-expect-error -- openapi handler union return type
|
|
242
|
-
router.openapi(setEntityAttributesRoute, async (c) => {
|
|
243
|
-
const result = await kernel.services.catalog.setAttributes(
|
|
244
|
-
c.req.param("id"),
|
|
245
|
-
c.req.param("locale"),
|
|
246
|
-
c.req.valid("json") as unknown as SetAttributesInput, // Zod-validated; requires double-cast because SetAttributesInput has required fields
|
|
247
|
-
);
|
|
248
|
-
if (!result.ok)
|
|
249
|
-
return c.json(
|
|
250
|
-
mapErrorToResponse(result.error),
|
|
251
|
-
mapErrorToStatus(result.error),
|
|
252
|
-
);
|
|
253
|
-
return c.json({ data: { updated: true } });
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
// @ts-expect-error -- openapi handler union return type
|
|
257
|
-
router.openapi(getEntityAttributesRoute, async (c) => {
|
|
258
|
-
const result = await kernel.services.catalog.getAttributes(
|
|
259
|
-
c.req.param("id"),
|
|
260
|
-
c.req.param("locale"),
|
|
261
|
-
);
|
|
262
|
-
if (!result.ok)
|
|
263
|
-
return c.json(
|
|
264
|
-
mapErrorToResponse(result.error),
|
|
265
|
-
mapErrorToStatus(result.error),
|
|
266
|
-
);
|
|
267
|
-
return c.json({ data: result.value });
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
// @ts-expect-error -- openapi handler union return type
|
|
271
|
-
router.openapi(listCategoriesRoute, async (c) => {
|
|
272
|
-
const result = await kernel.services.catalog.listCategories({ actor: c.get("actor"), tx: null, requestId: "" });
|
|
273
|
-
if (!result.ok)
|
|
274
|
-
return c.json(
|
|
275
|
-
mapErrorToResponse(result.error),
|
|
276
|
-
mapErrorToStatus(result.error),
|
|
277
|
-
);
|
|
278
|
-
return c.json({ data: result.value });
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
// @ts-expect-error -- openapi handler union return type
|
|
282
|
-
router.openapi(createCategoryRoute, async (c) => {
|
|
283
|
-
const result = await kernel.services.catalog.createCategory(
|
|
284
|
-
c.req.valid("json") as CreateCategoryInput,
|
|
285
|
-
c.get("actor"),
|
|
286
|
-
);
|
|
287
|
-
if (!result.ok)
|
|
288
|
-
return c.json(
|
|
289
|
-
mapErrorToResponse(result.error),
|
|
290
|
-
mapErrorToStatus(result.error),
|
|
291
|
-
);
|
|
292
|
-
return c.json({ data: result.value }, 201);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
// @ts-expect-error -- openapi handler union return type
|
|
296
|
-
router.openapi(updateCategoryRoute, async (c) => {
|
|
297
|
-
const result = await kernel.services.catalog.updateCategory(
|
|
298
|
-
c.req.param("categoryId"),
|
|
299
|
-
c.req.valid("json") as UpdateCategoryInput,
|
|
300
|
-
c.get("actor"),
|
|
301
|
-
);
|
|
302
|
-
if (!result.ok)
|
|
303
|
-
return c.json(
|
|
304
|
-
mapErrorToResponse(result.error),
|
|
305
|
-
mapErrorToStatus(result.error),
|
|
306
|
-
);
|
|
307
|
-
return c.json({ data: result.value });
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
// @ts-expect-error -- openapi handler union return type
|
|
311
|
-
router.openapi(deleteCategoryRoute, async (c) => {
|
|
312
|
-
const result = await kernel.services.catalog.deleteCategory(
|
|
313
|
-
c.req.param("categoryId"),
|
|
314
|
-
c.get("actor"),
|
|
315
|
-
);
|
|
316
|
-
if (!result.ok)
|
|
317
|
-
return c.json(
|
|
318
|
-
mapErrorToResponse(result.error),
|
|
319
|
-
mapErrorToStatus(result.error),
|
|
320
|
-
);
|
|
321
|
-
return c.json({ data: { deleted: true } });
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
// @ts-expect-error -- openapi handler union return type
|
|
325
|
-
router.openapi(addEntityToCategoryRoute, async (c) => {
|
|
326
|
-
const result = await kernel.services.catalog.addToCategory(
|
|
327
|
-
c.req.param("id"),
|
|
328
|
-
c.req.param("categoryId"),
|
|
329
|
-
);
|
|
330
|
-
if (!result.ok)
|
|
331
|
-
return c.json(
|
|
332
|
-
mapErrorToResponse(result.error),
|
|
333
|
-
mapErrorToStatus(result.error),
|
|
334
|
-
);
|
|
335
|
-
return c.json({ data: { linked: true } });
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
// @ts-expect-error -- openapi handler union return type
|
|
339
|
-
router.openapi(removeEntityFromCategoryRoute, async (c) => {
|
|
340
|
-
const result = await kernel.services.catalog.removeFromCategory(
|
|
341
|
-
c.req.param("id"),
|
|
342
|
-
c.req.param("categoryId"),
|
|
343
|
-
);
|
|
344
|
-
if (!result.ok)
|
|
345
|
-
return c.json(
|
|
346
|
-
mapErrorToResponse(result.error),
|
|
347
|
-
mapErrorToStatus(result.error),
|
|
348
|
-
);
|
|
349
|
-
return c.json({ data: { unlinked: true } });
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
// @ts-expect-error -- openapi handler union return type
|
|
353
|
-
router.openapi(listBrandsRoute, async (c) => {
|
|
354
|
-
const result = await kernel.services.catalog.listBrands({ actor: c.get("actor"), tx: null, requestId: "" });
|
|
355
|
-
if (!result.ok)
|
|
356
|
-
return c.json(
|
|
357
|
-
mapErrorToResponse(result.error),
|
|
358
|
-
mapErrorToStatus(result.error),
|
|
359
|
-
);
|
|
360
|
-
return c.json({ data: result.value });
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
// @ts-expect-error -- openapi handler union return type
|
|
364
|
-
router.openapi(createBrandRoute, async (c) => {
|
|
365
|
-
const result = await kernel.services.catalog.createBrand(
|
|
366
|
-
c.req.valid("json") as CreateBrandInput,
|
|
367
|
-
c.get("actor"),
|
|
368
|
-
);
|
|
369
|
-
if (!result.ok)
|
|
370
|
-
return c.json(
|
|
371
|
-
mapErrorToResponse(result.error),
|
|
372
|
-
mapErrorToStatus(result.error),
|
|
373
|
-
);
|
|
374
|
-
return c.json({ data: result.value }, 201);
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
// @ts-expect-error -- openapi handler union return type
|
|
378
|
-
router.openapi(updateBrandRoute, async (c) => {
|
|
379
|
-
const result = await kernel.services.catalog.updateBrand(
|
|
380
|
-
c.req.param("brandId"),
|
|
381
|
-
c.req.valid("json") as UpdateBrandInput,
|
|
382
|
-
c.get("actor"),
|
|
383
|
-
);
|
|
384
|
-
if (!result.ok)
|
|
385
|
-
return c.json(
|
|
386
|
-
mapErrorToResponse(result.error),
|
|
387
|
-
mapErrorToStatus(result.error),
|
|
388
|
-
);
|
|
389
|
-
return c.json({ data: result.value });
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
// @ts-expect-error -- openapi handler union return type
|
|
393
|
-
router.openapi(deleteBrandRoute, async (c) => {
|
|
394
|
-
const result = await kernel.services.catalog.deleteBrand(
|
|
395
|
-
c.req.param("brandId"),
|
|
396
|
-
c.get("actor"),
|
|
397
|
-
);
|
|
398
|
-
if (!result.ok)
|
|
399
|
-
return c.json(
|
|
400
|
-
mapErrorToResponse(result.error),
|
|
401
|
-
mapErrorToStatus(result.error),
|
|
402
|
-
);
|
|
403
|
-
return c.json({ data: { deleted: true } });
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// @ts-expect-error -- openapi handler union return type
|
|
407
|
-
router.openapi(addEntityToBrandRoute, async (c) => {
|
|
408
|
-
const result = await kernel.services.catalog.addToBrand(
|
|
409
|
-
c.req.param("id"),
|
|
410
|
-
c.req.param("brandId"),
|
|
411
|
-
);
|
|
412
|
-
if (!result.ok)
|
|
413
|
-
return c.json(
|
|
414
|
-
mapErrorToResponse(result.error),
|
|
415
|
-
mapErrorToStatus(result.error),
|
|
416
|
-
);
|
|
417
|
-
return c.json({ data: { linked: true } });
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
// @ts-expect-error -- openapi handler union return type
|
|
421
|
-
router.openapi(removeEntityFromBrandRoute, async (c) => {
|
|
422
|
-
const result = await kernel.services.catalog.removeFromBrand(
|
|
423
|
-
c.req.param("id"),
|
|
424
|
-
c.req.param("brandId"),
|
|
425
|
-
);
|
|
426
|
-
if (!result.ok)
|
|
427
|
-
return c.json(
|
|
428
|
-
mapErrorToResponse(result.error),
|
|
429
|
-
mapErrorToStatus(result.error),
|
|
430
|
-
);
|
|
431
|
-
return c.json({ data: { unlinked: true } });
|
|
432
|
-
});
|
|
433
|
-
|
|
434
|
-
// @ts-expect-error -- openapi handler union return type
|
|
435
|
-
router.openapi(createOptionTypeRoute, async (c) => {
|
|
436
|
-
const result = await kernel.services.catalog.createOptionType(
|
|
437
|
-
{ ...(c.req.valid("json") as Record<string, unknown>), entityId: c.req.param("id") } as CreateOptionTypeInput,
|
|
438
|
-
c.get("actor"),
|
|
439
|
-
);
|
|
440
|
-
if (!result.ok)
|
|
441
|
-
return c.json(
|
|
442
|
-
mapErrorToResponse(result.error),
|
|
443
|
-
mapErrorToStatus(result.error),
|
|
444
|
-
);
|
|
445
|
-
return c.json({ data: result.value }, 201);
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// @ts-expect-error -- openapi handler union return type
|
|
449
|
-
router.openapi(createOptionValueRoute, async (c) => {
|
|
450
|
-
const result = await kernel.services.catalog.createOptionValue(
|
|
451
|
-
{ ...(c.req.valid("json") as Record<string, unknown>), optionTypeId: c.req.param("optionTypeId") } as CreateOptionValueInput,
|
|
452
|
-
c.get("actor"),
|
|
453
|
-
);
|
|
454
|
-
if (!result.ok)
|
|
455
|
-
return c.json(
|
|
456
|
-
mapErrorToResponse(result.error),
|
|
457
|
-
mapErrorToStatus(result.error),
|
|
458
|
-
);
|
|
459
|
-
return c.json({ data: result.value }, 201);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
// @ts-expect-error -- openapi handler union return type
|
|
463
|
-
router.openapi(createVariantRoute, async (c) => {
|
|
464
|
-
const result = await kernel.services.catalog.createVariant(
|
|
465
|
-
{ ...(c.req.valid("json") as Record<string, unknown>), entityId: c.req.param("id") } as CreateVariantInput,
|
|
466
|
-
c.get("actor"),
|
|
467
|
-
);
|
|
468
|
-
if (!result.ok)
|
|
469
|
-
return c.json(
|
|
470
|
-
mapErrorToResponse(result.error),
|
|
471
|
-
mapErrorToStatus(result.error),
|
|
472
|
-
);
|
|
473
|
-
return c.json({ data: result.value }, 201);
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
// @ts-expect-error -- openapi handler union return type
|
|
477
|
-
router.openapi(generateVariantsRoute, async (c) => {
|
|
478
|
-
const body = c.req.valid("json") as VariantGenerationStrategy;
|
|
479
|
-
const result = await kernel.services.catalog.generateVariants(
|
|
480
|
-
c.req.param("id"),
|
|
481
|
-
body,
|
|
482
|
-
c.get("actor"),
|
|
483
|
-
);
|
|
484
|
-
if (!result.ok)
|
|
485
|
-
return c.json(
|
|
486
|
-
mapErrorToResponse(result.error),
|
|
487
|
-
mapErrorToStatus(result.error),
|
|
488
|
-
);
|
|
489
|
-
return c.json({ data: result.value }, 201);
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
return router;
|
|
493
|
-
}
|