@unifiedcommerce/core 0.0.4 → 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.
Files changed (179) hide show
  1. package/dist/auth/auth-schema.d.ts +92 -0
  2. package/dist/auth/auth-schema.d.ts.map +1 -1
  3. package/dist/auth/auth-schema.js +7 -0
  4. package/dist/auth/setup.d.ts.map +1 -1
  5. package/dist/auth/setup.js +3 -1
  6. package/package.json +1 -2
  7. package/src/adapters/console-email.ts +0 -43
  8. package/src/auth/access.ts +0 -187
  9. package/src/auth/auth-schema.ts +0 -131
  10. package/src/auth/middleware.ts +0 -161
  11. package/src/auth/org.ts +0 -41
  12. package/src/auth/permissions.ts +0 -28
  13. package/src/auth/setup.ts +0 -165
  14. package/src/auth/system-actor.ts +0 -19
  15. package/src/auth/types.ts +0 -10
  16. package/src/config/defaults.ts +0 -82
  17. package/src/config/define-config.ts +0 -53
  18. package/src/config/types.ts +0 -299
  19. package/src/generated/plugin-capabilities.d.ts +0 -20
  20. package/src/generated/plugin-manifest.ts +0 -23
  21. package/src/generated/plugin-repositories.d.ts +0 -20
  22. package/src/hooks/checkout-completion.ts +0 -262
  23. package/src/hooks/checkout.ts +0 -677
  24. package/src/hooks/order-emails.ts +0 -62
  25. package/src/index.ts +0 -214
  26. package/src/interfaces/mcp/agent-prompt.ts +0 -174
  27. package/src/interfaces/mcp/context-enrichment.ts +0 -177
  28. package/src/interfaces/mcp/server.ts +0 -617
  29. package/src/interfaces/mcp/transport.ts +0 -68
  30. package/src/interfaces/rest/customer-portal.ts +0 -299
  31. package/src/interfaces/rest/index.ts +0 -74
  32. package/src/interfaces/rest/router.ts +0 -334
  33. package/src/interfaces/rest/routes/admin-jobs.ts +0 -58
  34. package/src/interfaces/rest/routes/audit.ts +0 -50
  35. package/src/interfaces/rest/routes/carts.ts +0 -89
  36. package/src/interfaces/rest/routes/catalog.ts +0 -493
  37. package/src/interfaces/rest/routes/checkout.ts +0 -283
  38. package/src/interfaces/rest/routes/inventory.ts +0 -70
  39. package/src/interfaces/rest/routes/media.ts +0 -86
  40. package/src/interfaces/rest/routes/orders.ts +0 -78
  41. package/src/interfaces/rest/routes/payments.ts +0 -60
  42. package/src/interfaces/rest/routes/pricing.ts +0 -57
  43. package/src/interfaces/rest/routes/promotions.ts +0 -92
  44. package/src/interfaces/rest/routes/search.ts +0 -71
  45. package/src/interfaces/rest/routes/webhooks.ts +0 -46
  46. package/src/interfaces/rest/schemas/admin-jobs.ts +0 -40
  47. package/src/interfaces/rest/schemas/audit.ts +0 -46
  48. package/src/interfaces/rest/schemas/carts.ts +0 -125
  49. package/src/interfaces/rest/schemas/catalog.ts +0 -450
  50. package/src/interfaces/rest/schemas/checkout.ts +0 -66
  51. package/src/interfaces/rest/schemas/customer-portal.ts +0 -195
  52. package/src/interfaces/rest/schemas/inventory.ts +0 -138
  53. package/src/interfaces/rest/schemas/media.ts +0 -75
  54. package/src/interfaces/rest/schemas/orders.ts +0 -104
  55. package/src/interfaces/rest/schemas/pricing.ts +0 -80
  56. package/src/interfaces/rest/schemas/promotions.ts +0 -110
  57. package/src/interfaces/rest/schemas/responses.ts +0 -85
  58. package/src/interfaces/rest/schemas/search.ts +0 -58
  59. package/src/interfaces/rest/schemas/shared.ts +0 -62
  60. package/src/interfaces/rest/schemas/webhooks.ts +0 -68
  61. package/src/interfaces/rest/utils.ts +0 -104
  62. package/src/interfaces/rest/webhook-router.ts +0 -50
  63. package/src/kernel/compensation/executor.ts +0 -61
  64. package/src/kernel/compensation/types.ts +0 -26
  65. package/src/kernel/database/adapter.ts +0 -13
  66. package/src/kernel/database/drizzle-db.ts +0 -56
  67. package/src/kernel/database/migrate.ts +0 -76
  68. package/src/kernel/database/plugin-types.ts +0 -34
  69. package/src/kernel/database/schema.ts +0 -49
  70. package/src/kernel/database/scoped-db.ts +0 -68
  71. package/src/kernel/database/tx-context.ts +0 -46
  72. package/src/kernel/error-mapper.ts +0 -15
  73. package/src/kernel/errors.ts +0 -89
  74. package/src/kernel/factory/repository-factory.ts +0 -242
  75. package/src/kernel/hooks/create-context.ts +0 -43
  76. package/src/kernel/hooks/executor.ts +0 -88
  77. package/src/kernel/hooks/registry.ts +0 -74
  78. package/src/kernel/hooks/types.ts +0 -52
  79. package/src/kernel/http-error.ts +0 -44
  80. package/src/kernel/jobs/adapter.ts +0 -36
  81. package/src/kernel/jobs/drizzle-adapter.ts +0 -58
  82. package/src/kernel/jobs/runner.ts +0 -153
  83. package/src/kernel/jobs/schema.ts +0 -46
  84. package/src/kernel/jobs/types.ts +0 -30
  85. package/src/kernel/local-api.ts +0 -185
  86. package/src/kernel/plugin/manifest.ts +0 -253
  87. package/src/kernel/query/executor.ts +0 -184
  88. package/src/kernel/query/registry.ts +0 -46
  89. package/src/kernel/result.ts +0 -33
  90. package/src/kernel/schema/extra-columns.ts +0 -37
  91. package/src/kernel/service-registry.ts +0 -76
  92. package/src/kernel/service-timing.ts +0 -89
  93. package/src/kernel/state-machine/machine.ts +0 -101
  94. package/src/modules/analytics/drizzle-adapter.ts +0 -426
  95. package/src/modules/analytics/hooks.ts +0 -11
  96. package/src/modules/analytics/models.ts +0 -125
  97. package/src/modules/analytics/repository/index.ts +0 -6
  98. package/src/modules/analytics/service.ts +0 -245
  99. package/src/modules/analytics/types.ts +0 -180
  100. package/src/modules/audit/hooks.ts +0 -78
  101. package/src/modules/audit/schema.ts +0 -33
  102. package/src/modules/audit/service.ts +0 -151
  103. package/src/modules/cart/access.ts +0 -27
  104. package/src/modules/cart/matcher.ts +0 -26
  105. package/src/modules/cart/repository/index.ts +0 -234
  106. package/src/modules/cart/schema.ts +0 -42
  107. package/src/modules/cart/schemas.ts +0 -38
  108. package/src/modules/cart/service.ts +0 -541
  109. package/src/modules/catalog/repository/index.ts +0 -772
  110. package/src/modules/catalog/schema.ts +0 -203
  111. package/src/modules/catalog/schemas.ts +0 -104
  112. package/src/modules/catalog/service.ts +0 -1544
  113. package/src/modules/customers/repository/index.ts +0 -327
  114. package/src/modules/customers/schema.ts +0 -64
  115. package/src/modules/customers/service.ts +0 -171
  116. package/src/modules/fulfillment/repository/index.ts +0 -426
  117. package/src/modules/fulfillment/schema.ts +0 -101
  118. package/src/modules/fulfillment/service.ts +0 -555
  119. package/src/modules/fulfillment/types.ts +0 -59
  120. package/src/modules/inventory/repository/index.ts +0 -509
  121. package/src/modules/inventory/schema.ts +0 -94
  122. package/src/modules/inventory/schemas.ts +0 -38
  123. package/src/modules/inventory/service.ts +0 -490
  124. package/src/modules/media/adapter.ts +0 -17
  125. package/src/modules/media/repository/index.ts +0 -274
  126. package/src/modules/media/schema.ts +0 -41
  127. package/src/modules/media/service.ts +0 -151
  128. package/src/modules/orders/repository/index.ts +0 -287
  129. package/src/modules/orders/schema.ts +0 -66
  130. package/src/modules/orders/service.ts +0 -619
  131. package/src/modules/orders/stale-order-cleanup.ts +0 -76
  132. package/src/modules/organization/service.ts +0 -191
  133. package/src/modules/payments/adapter.ts +0 -47
  134. package/src/modules/payments/repository/index.ts +0 -6
  135. package/src/modules/payments/service.ts +0 -107
  136. package/src/modules/pricing/repository/index.ts +0 -291
  137. package/src/modules/pricing/schema.ts +0 -71
  138. package/src/modules/pricing/schemas.ts +0 -38
  139. package/src/modules/pricing/service.ts +0 -494
  140. package/src/modules/promotions/repository/index.ts +0 -325
  141. package/src/modules/promotions/schema.ts +0 -62
  142. package/src/modules/promotions/schemas.ts +0 -38
  143. package/src/modules/promotions/service.ts +0 -598
  144. package/src/modules/search/adapter.ts +0 -57
  145. package/src/modules/search/hooks.ts +0 -12
  146. package/src/modules/search/repository/index.ts +0 -6
  147. package/src/modules/search/service.ts +0 -315
  148. package/src/modules/shipping/calculator.ts +0 -188
  149. package/src/modules/shipping/repository/index.ts +0 -6
  150. package/src/modules/shipping/service.ts +0 -51
  151. package/src/modules/tax/adapter.ts +0 -60
  152. package/src/modules/tax/repository/index.ts +0 -6
  153. package/src/modules/tax/service.ts +0 -53
  154. package/src/modules/webhooks/hook.ts +0 -34
  155. package/src/modules/webhooks/repository/index.ts +0 -278
  156. package/src/modules/webhooks/schema.ts +0 -56
  157. package/src/modules/webhooks/service.ts +0 -117
  158. package/src/modules/webhooks/signing.ts +0 -6
  159. package/src/modules/webhooks/ssrf-guard.ts +0 -71
  160. package/src/modules/webhooks/tasks.ts +0 -52
  161. package/src/modules/webhooks/worker.ts +0 -134
  162. package/src/runtime/commerce.ts +0 -145
  163. package/src/runtime/kernel.ts +0 -419
  164. package/src/runtime/logger.ts +0 -36
  165. package/src/runtime/server.ts +0 -349
  166. package/src/runtime/shutdown.ts +0 -43
  167. package/src/test-utils/create-pglite-adapter.ts +0 -129
  168. package/src/test-utils/create-plugin-test-app.ts +0 -128
  169. package/src/test-utils/create-repository-test-harness.ts +0 -16
  170. package/src/test-utils/create-test-config.ts +0 -190
  171. package/src/test-utils/create-test-kernel.ts +0 -7
  172. package/src/test-utils/create-test-plugin-context.ts +0 -75
  173. package/src/test-utils/rest-api-test-utils.ts +0 -265
  174. package/src/test-utils/test-actors.ts +0 -62
  175. package/src/test-utils/typed-hooks.ts +0 -54
  176. package/src/types/commerce-types.ts +0 -34
  177. package/src/utils/id.ts +0 -3
  178. package/src/utils/logger.ts +0 -18
  179. package/src/utils/pagination.ts +0 -22
@@ -1,92 +0,0 @@
1
- import { OpenAPIHono } from "@hono/zod-openapi";
2
- import { rateLimiter } from "hono-rate-limiter";
3
- import type { Kernel } from "../../../runtime/kernel.js";
4
- import { createPromotionRoute, validatePromotionRoute, deactivatePromotionRoute, listActivePromotionsRoute } from "../schemas/promotions.js";
5
- import { type AppEnv, mapErrorToResponse, mapErrorToStatus, requirePerm } from "../utils.js";
6
- import { resolveOrgId } from "../../../auth/org.js";
7
-
8
- export function promotionRoutes(kernel: Kernel) {
9
- const router = new OpenAPIHono<AppEnv>();
10
-
11
- // Rate limit promo code validation — prevents brute-force code enumeration
12
- router.use(
13
- "/validate",
14
- rateLimiter({
15
- windowMs: 60 * 1000,
16
- limit: 10,
17
- keyGenerator: (c) => {
18
- const raw = c.req.raw as unknown as { socket?: { remoteAddress?: string } };
19
- return raw?.socket?.remoteAddress ?? "unknown";
20
- },
21
- }),
22
- );
23
-
24
- router.use("/", requirePerm("promotions:manage"));
25
-
26
- // @ts-expect-error -- openapi() enforces strict response typing but our handler
27
- // returns union responses (201 | 400 | 422). The route definition documents the
28
- // contract; the handler returns dynamic status.
29
- router.openapi(createPromotionRoute, async (c) => {
30
- const body = c.req.valid("json");
31
- const actor = c.get("actor");
32
- const result = await kernel.services.promotions.create(body, actor);
33
- if (!result.ok) {
34
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
35
- }
36
- return c.json({ data: result.value }, 201);
37
- });
38
-
39
- // List active promotions — requires auth
40
- router.use("/active", requirePerm("promotions:read"));
41
-
42
- // @ts-expect-error -- openapi handler union return type
43
- router.openapi(listActivePromotionsRoute, async (_c) => {
44
- const actor = _c.get("actor");
45
- const result = await kernel.services.promotions.listActive(actor);
46
- if (!result.ok) {
47
- return _c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
48
- }
49
- return _c.json({ data: result.value });
50
- });
51
-
52
- // @ts-expect-error -- openapi() enforces strict response typing but our handler
53
- // returns union responses (200 | 400 | 404). The route definition documents the
54
- // contract; the handler returns dynamic status.
55
- router.openapi(validatePromotionRoute, async (c) => {
56
- const payload = c.req.valid("json");
57
- const actor = c.get("actor");
58
- const orgId = resolveOrgId(actor);
59
-
60
- const result = await kernel.services.promotions.validate(payload.code, {
61
- orgId,
62
- currency: payload.currency,
63
- subtotal: payload.subtotal,
64
- lineItems: payload.lineItems,
65
- ...(payload.customerId !== undefined ? { customerId: payload.customerId } : {}),
66
- ...(payload.customerGroupIds !== undefined ? { customerGroupIds: payload.customerGroupIds } : {}),
67
- });
68
-
69
- if (!result.ok) {
70
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
71
- }
72
-
73
- return c.json({ data: result.value });
74
- });
75
-
76
- router.use("/:id/deactivate", requirePerm("promotions:manage"));
77
-
78
- // @ts-expect-error -- openapi() enforces strict response typing but our handler
79
- // returns union responses (200 | 400 | 404). The route definition documents the
80
- // contract; the handler returns dynamic status.
81
- router.openapi(deactivatePromotionRoute, async (c) => {
82
- const actor = c.get("actor");
83
- const orgId = resolveOrgId(actor);
84
- const result = await kernel.services.promotions.deactivate(orgId, c.req.param("id"));
85
- if (!result.ok) {
86
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
87
- }
88
- return c.json({ data: result.value });
89
- });
90
-
91
- return router;
92
- }
@@ -1,71 +0,0 @@
1
- import { OpenAPIHono } from "@hono/zod-openapi";
2
- import type { Kernel } from "../../../runtime/kernel.js";
3
- import { searchRoute, suggestRoute } from "../schemas/search.js";
4
- import { type AppEnv, mapErrorToResponse, mapErrorToStatus } from "../utils.js";
5
-
6
- export function searchRoutes(kernel: Kernel) {
7
- const router = new OpenAPIHono<AppEnv>();
8
-
9
- // @ts-expect-error -- openapi handler union return type
10
- router.openapi(searchRoute, async (c) => {
11
- const q = c.req.query("q") ?? "";
12
- const type = c.req.query("type");
13
- const category = c.req.query("category");
14
- const brand = c.req.query("brand");
15
- const status = c.req.query("status");
16
- const page = Number.parseInt(c.req.query("page") ?? "1", 10);
17
- const limit = Number.parseInt(c.req.query("limit") ?? "20", 10);
18
- const facets = (c.req.query("facets") ?? "")
19
- .split(",")
20
- .map((facet) => facet.trim())
21
- .filter(Boolean);
22
-
23
- const result = await kernel.services.search.query({
24
- query: q,
25
- page,
26
- limit,
27
- filters: {
28
- ...(type ? { type } : {}),
29
- ...(category ? { category } : {}),
30
- ...(brand ? { brand } : {}),
31
- ...(status ? { status } : {}),
32
- },
33
- ...(facets.length > 0 ? { facets } : {}),
34
- }, { actor: c.get("actor"), tx: null, requestId: "" });
35
-
36
- if (!result.ok) {
37
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
38
- }
39
-
40
- return c.json({
41
- data: result.value.hits,
42
- meta: {
43
- total: result.value.total,
44
- page: result.value.page,
45
- limit: result.value.limit,
46
- facets: result.value.facets,
47
- },
48
- });
49
- });
50
-
51
- // @ts-expect-error -- openapi handler union return type
52
- router.openapi(suggestRoute, async (c) => {
53
- const prefix = c.req.query("prefix") ?? "";
54
- const type = c.req.query("type");
55
- const limit = Number.parseInt(c.req.query("limit") ?? "10", 10);
56
-
57
- const result = await kernel.services.search.suggest({
58
- prefix,
59
- ...(type ? { type } : {}),
60
- limit,
61
- }, { actor: c.get("actor"), tx: null, requestId: "" });
62
-
63
- if (!result.ok) {
64
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
65
- }
66
-
67
- return c.json({ data: result.value });
68
- });
69
-
70
- return router;
71
- }
@@ -1,46 +0,0 @@
1
- import { OpenAPIHono } from "@hono/zod-openapi";
2
- import type { Kernel } from "../../../runtime/kernel.js";
3
- import { createWebhookEndpointRoute, listWebhookEndpointsRoute, deleteWebhookEndpointRoute } from "../schemas/webhooks.js";
4
- import { type AppEnv, mapErrorToResponse, mapErrorToStatus, requirePerm } from "../utils.js";
5
-
6
- export function webhookRoutes(kernel: Kernel) {
7
- const router = new OpenAPIHono<AppEnv>();
8
-
9
- router.use("/*", requirePerm("webhooks:manage"));
10
-
11
- // @ts-expect-error -- openapi handler union return type
12
- router.openapi(createWebhookEndpointRoute, async (c) => {
13
- const body = c.req.valid("json") as Parameters<typeof kernel.services.webhooks.createEndpoint>[0];
14
- // Generate a default secret if none provided (Zod schema marks it optional for API convenience)
15
- if (!body.secret) {
16
- body.secret = `whsec_${crypto.randomUUID().replace(/-/g, "")}`;
17
- }
18
- const actor = c.get("actor");
19
- const result = await kernel.services.webhooks.createEndpoint(body, actor);
20
- if (!result.ok) {
21
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
22
- }
23
- return c.json({ data: result.value }, 201);
24
- });
25
-
26
- // @ts-expect-error -- openapi handler union return type
27
- router.openapi(listWebhookEndpointsRoute, async (c) => {
28
- const result = await kernel.services.webhooks.listEndpoints();
29
- if (!result.ok) {
30
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
31
- }
32
- const sanitized = result.value.map(({ secret: _secret, ...rest }) => rest);
33
- return c.json({ data: sanitized });
34
- });
35
-
36
- // @ts-expect-error -- openapi handler union return type
37
- router.openapi(deleteWebhookEndpointRoute, async (c) => {
38
- const result = await kernel.services.webhooks.deleteEndpoint(c.req.param("id"));
39
- if (!result.ok) {
40
- return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
41
- }
42
- return c.json({ data: { deleted: true } });
43
- });
44
-
45
- return router;
46
- }
@@ -1,40 +0,0 @@
1
- import { z, createRoute } from "@hono/zod-openapi";
2
- import { JobListResponse } from "./responses.js";
3
-
4
- // ─── Route Definitions ──────────────────────────────────────────────────────
5
-
6
- export const listFailedJobsRoute = createRoute({
7
- method: "get",
8
- path: "/jobs/failed",
9
- tags: ["Admin Jobs"],
10
- summary: "List failed jobs",
11
- request: {
12
- query: z.object({
13
- limit: z.string().optional(),
14
- }),
15
- },
16
- responses: {
17
- 200: {
18
- content: { "application/json": { schema: JobListResponse } },
19
- description: "Failed jobs",
20
- },
21
- },
22
- });
23
-
24
- export const retryJobRoute = createRoute({
25
- method: "post",
26
- path: "/jobs/{id}/retry",
27
- tags: ["Admin Jobs"],
28
- summary: "Retry a failed job",
29
- request: {
30
- params: z.object({
31
- id: z.string().min(1).openapi({ example: "job-uuid" }),
32
- }),
33
- },
34
- responses: {
35
- 200: {
36
- content: { "application/json": { schema: z.object({ data: z.object({ retried: z.literal(true) }) }) } },
37
- description: "Job retried",
38
- },
39
- },
40
- });
@@ -1,46 +0,0 @@
1
- import { z, createRoute } from "@hono/zod-openapi";
2
-
3
- // ─── Route Definitions ──────────────────────────────────────────────────────
4
-
5
- export const listAuditRoute = createRoute({
6
- method: "get",
7
- path: "/",
8
- tags: ["Audit"],
9
- summary: "List audit entries",
10
- request: {
11
- query: z.object({
12
- entityType: z.string().optional(),
13
- entityId: z.string().optional(),
14
- event: z.string().optional(),
15
- actorId: z.string().optional(),
16
- from: z.string().optional(),
17
- to: z.string().optional(),
18
- limit: z.string().optional(),
19
- }),
20
- },
21
- responses: {
22
- 200: {
23
- content: { "application/json": { schema: z.object({ data: z.array(z.record(z.string(), z.unknown())) }) } },
24
- description: "Audit entries",
25
- },
26
- },
27
- });
28
-
29
- export const listEntityAuditRoute = createRoute({
30
- method: "get",
31
- path: "/{entityType}/{entityId}",
32
- tags: ["Audit"],
33
- summary: "List audit history for a specific entity",
34
- request: {
35
- params: z.object({
36
- entityType: z.string().min(1).openapi({ example: "order" }),
37
- entityId: z.string().min(1).openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
38
- }),
39
- },
40
- responses: {
41
- 200: {
42
- content: { "application/json": { schema: z.object({ data: z.array(z.record(z.string(), z.unknown())) }) } },
43
- description: "Entity audit history",
44
- },
45
- },
46
- });
@@ -1,125 +0,0 @@
1
- import { z, createRoute } from "@hono/zod-openapi";
2
- import { ErrorSchema, errorResponses, UuidParamSchema, DeletedResponseSchema } from "./shared.js";
3
- import { CartResponse } from "./responses.js";
4
- import {
5
- CreateCartBodySchema,
6
- AddCartItemBodySchema,
7
- UpdateCartItemQuantityBodySchema,
8
- } from "../../../modules/cart/schemas.js";
9
-
10
- export { CreateCartBodySchema, AddCartItemBodySchema, UpdateCartItemQuantityBodySchema };
11
-
12
- // ─── Response Schemas ───────────────────────────────────────────────────────
13
-
14
- export const CartResponseSchema = CartResponse;
15
-
16
- // ─── Path Params ────────────────────────────────────────────────────────────
17
-
18
- const CartIdParam = z.object({
19
- id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
20
- });
21
-
22
- const CartItemParams = z.object({
23
- id: z.uuid().openapi({ example: "550e8400-e29b-41d4-a716-446655440000" }),
24
- itemId: z.uuid().openapi({ example: "660e8400-e29b-41d4-a716-446655440000" }),
25
- });
26
-
27
- // ─── Route Definitions ──────────────────────────────────────────────────────
28
-
29
- export const getCartRoute = createRoute({
30
- method: "get",
31
- path: "/{id}",
32
- tags: ["Carts"],
33
- summary: "Get a cart by ID",
34
- request: { params: CartIdParam },
35
- responses: {
36
- 200: {
37
- content: { "application/json": { schema: CartResponseSchema } },
38
- description: "Cart retrieved.",
39
- },
40
- ...errorResponses,
41
- },
42
- });
43
-
44
- export const removeCartItemRoute = createRoute({
45
- method: "delete",
46
- path: "/{id}/items/{itemId}",
47
- tags: ["Carts"],
48
- summary: "Remove an item from a cart",
49
- request: { params: CartItemParams },
50
- responses: {
51
- 200: {
52
- content: { "application/json": { schema: DeletedResponseSchema } },
53
- description: "Item removed.",
54
- },
55
- ...errorResponses,
56
- },
57
- });
58
-
59
- export const createCartRoute = createRoute({
60
- method: "post",
61
- path: "/",
62
- tags: ["Carts"],
63
- summary: "Create a new cart",
64
- request: {
65
- body: {
66
- content: {
67
- "application/json": { schema: CreateCartBodySchema },
68
- },
69
- required: true,
70
- },
71
- },
72
- responses: {
73
- 201: {
74
- content: { "application/json": { schema: CartResponseSchema } },
75
- description: "Cart created successfully.",
76
- },
77
- ...errorResponses,
78
- },
79
- });
80
-
81
- export const addCartItemRoute = createRoute({
82
- method: "post",
83
- path: "/{id}/items",
84
- tags: ["Carts"],
85
- summary: "Add an item to a cart",
86
- request: {
87
- params: CartIdParam,
88
- body: {
89
- content: {
90
- "application/json": { schema: AddCartItemBodySchema },
91
- },
92
- required: true,
93
- },
94
- },
95
- responses: {
96
- 201: {
97
- content: { "application/json": { schema: CartResponseSchema } },
98
- description: "Item added to cart.",
99
- },
100
- ...errorResponses,
101
- },
102
- });
103
-
104
- export const updateCartItemQuantityRoute = createRoute({
105
- method: "patch",
106
- path: "/{id}/items/{itemId}",
107
- tags: ["Carts"],
108
- summary: "Update the quantity of a cart line item",
109
- request: {
110
- params: CartItemParams,
111
- body: {
112
- content: {
113
- "application/json": { schema: UpdateCartItemQuantityBodySchema },
114
- },
115
- required: true,
116
- },
117
- },
118
- responses: {
119
- 200: {
120
- content: { "application/json": { schema: CartResponseSchema } },
121
- description: "Cart item quantity updated.",
122
- },
123
- ...errorResponses,
124
- },
125
- });