@unifiedcommerce/core 0.1.0 → 0.2.0

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 (245) 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 +2 -2
  73. package/src/adapters/console-email.ts +0 -43
  74. package/src/auth/access.ts +0 -187
  75. package/src/auth/auth-schema.ts +0 -139
  76. package/src/auth/middleware.ts +0 -161
  77. package/src/auth/org.ts +0 -41
  78. package/src/auth/permissions.ts +0 -28
  79. package/src/auth/setup.ts +0 -169
  80. package/src/auth/system-actor.ts +0 -19
  81. package/src/auth/types.ts +0 -10
  82. package/src/config/defaults.ts +0 -82
  83. package/src/config/define-config.ts +0 -53
  84. package/src/config/types.ts +0 -299
  85. package/src/generated/plugin-capabilities.d.ts +0 -20
  86. package/src/generated/plugin-manifest.ts +0 -23
  87. package/src/generated/plugin-repositories.d.ts +0 -20
  88. package/src/hooks/checkout-completion.ts +0 -262
  89. package/src/hooks/checkout.ts +0 -677
  90. package/src/hooks/order-emails.ts +0 -62
  91. package/src/index.ts +0 -214
  92. package/src/interfaces/mcp/agent-prompt.ts +0 -174
  93. package/src/interfaces/mcp/context-enrichment.ts +0 -177
  94. package/src/interfaces/mcp/server.ts +0 -617
  95. package/src/interfaces/mcp/transport.ts +0 -68
  96. package/src/interfaces/rest/customer-portal.ts +0 -299
  97. package/src/interfaces/rest/index.ts +0 -74
  98. package/src/interfaces/rest/router.ts +0 -334
  99. package/src/interfaces/rest/routes/admin-jobs.ts +0 -58
  100. package/src/interfaces/rest/routes/audit.ts +0 -50
  101. package/src/interfaces/rest/routes/carts.ts +0 -89
  102. package/src/interfaces/rest/routes/catalog.ts +0 -493
  103. package/src/interfaces/rest/routes/checkout.ts +0 -283
  104. package/src/interfaces/rest/routes/inventory.ts +0 -70
  105. package/src/interfaces/rest/routes/media.ts +0 -86
  106. package/src/interfaces/rest/routes/orders.ts +0 -78
  107. package/src/interfaces/rest/routes/payments.ts +0 -60
  108. package/src/interfaces/rest/routes/pricing.ts +0 -57
  109. package/src/interfaces/rest/routes/promotions.ts +0 -92
  110. package/src/interfaces/rest/routes/search.ts +0 -71
  111. package/src/interfaces/rest/routes/webhooks.ts +0 -46
  112. package/src/interfaces/rest/schemas/admin-jobs.ts +0 -40
  113. package/src/interfaces/rest/schemas/audit.ts +0 -46
  114. package/src/interfaces/rest/schemas/carts.ts +0 -125
  115. package/src/interfaces/rest/schemas/catalog.ts +0 -450
  116. package/src/interfaces/rest/schemas/checkout.ts +0 -66
  117. package/src/interfaces/rest/schemas/customer-portal.ts +0 -195
  118. package/src/interfaces/rest/schemas/inventory.ts +0 -138
  119. package/src/interfaces/rest/schemas/media.ts +0 -75
  120. package/src/interfaces/rest/schemas/orders.ts +0 -104
  121. package/src/interfaces/rest/schemas/pricing.ts +0 -80
  122. package/src/interfaces/rest/schemas/promotions.ts +0 -110
  123. package/src/interfaces/rest/schemas/responses.ts +0 -85
  124. package/src/interfaces/rest/schemas/search.ts +0 -58
  125. package/src/interfaces/rest/schemas/shared.ts +0 -62
  126. package/src/interfaces/rest/schemas/webhooks.ts +0 -68
  127. package/src/interfaces/rest/utils.ts +0 -104
  128. package/src/interfaces/rest/webhook-router.ts +0 -50
  129. package/src/kernel/compensation/executor.ts +0 -61
  130. package/src/kernel/compensation/types.ts +0 -26
  131. package/src/kernel/database/adapter.ts +0 -13
  132. package/src/kernel/database/drizzle-db.ts +0 -56
  133. package/src/kernel/database/migrate.ts +0 -76
  134. package/src/kernel/database/plugin-types.ts +0 -34
  135. package/src/kernel/database/schema.ts +0 -49
  136. package/src/kernel/database/scoped-db.ts +0 -68
  137. package/src/kernel/database/tx-context.ts +0 -46
  138. package/src/kernel/error-mapper.ts +0 -15
  139. package/src/kernel/errors.ts +0 -89
  140. package/src/kernel/factory/repository-factory.ts +0 -242
  141. package/src/kernel/hooks/create-context.ts +0 -43
  142. package/src/kernel/hooks/executor.ts +0 -88
  143. package/src/kernel/hooks/registry.ts +0 -74
  144. package/src/kernel/hooks/types.ts +0 -52
  145. package/src/kernel/http-error.ts +0 -44
  146. package/src/kernel/jobs/adapter.ts +0 -36
  147. package/src/kernel/jobs/drizzle-adapter.ts +0 -58
  148. package/src/kernel/jobs/runner.ts +0 -153
  149. package/src/kernel/jobs/schema.ts +0 -46
  150. package/src/kernel/jobs/types.ts +0 -30
  151. package/src/kernel/local-api.ts +0 -185
  152. package/src/kernel/plugin/manifest.ts +0 -253
  153. package/src/kernel/query/executor.ts +0 -184
  154. package/src/kernel/query/registry.ts +0 -46
  155. package/src/kernel/result.ts +0 -33
  156. package/src/kernel/schema/extra-columns.ts +0 -37
  157. package/src/kernel/service-registry.ts +0 -76
  158. package/src/kernel/service-timing.ts +0 -89
  159. package/src/kernel/state-machine/machine.ts +0 -101
  160. package/src/modules/analytics/drizzle-adapter.ts +0 -426
  161. package/src/modules/analytics/hooks.ts +0 -11
  162. package/src/modules/analytics/models.ts +0 -125
  163. package/src/modules/analytics/repository/index.ts +0 -6
  164. package/src/modules/analytics/service.ts +0 -245
  165. package/src/modules/analytics/types.ts +0 -180
  166. package/src/modules/audit/hooks.ts +0 -78
  167. package/src/modules/audit/schema.ts +0 -33
  168. package/src/modules/audit/service.ts +0 -151
  169. package/src/modules/cart/access.ts +0 -27
  170. package/src/modules/cart/matcher.ts +0 -26
  171. package/src/modules/cart/repository/index.ts +0 -234
  172. package/src/modules/cart/schema.ts +0 -42
  173. package/src/modules/cart/schemas.ts +0 -38
  174. package/src/modules/cart/service.ts +0 -541
  175. package/src/modules/catalog/repository/index.ts +0 -772
  176. package/src/modules/catalog/schema.ts +0 -203
  177. package/src/modules/catalog/schemas.ts +0 -104
  178. package/src/modules/catalog/service.ts +0 -1544
  179. package/src/modules/customers/repository/index.ts +0 -327
  180. package/src/modules/customers/schema.ts +0 -64
  181. package/src/modules/customers/service.ts +0 -171
  182. package/src/modules/fulfillment/repository/index.ts +0 -426
  183. package/src/modules/fulfillment/schema.ts +0 -101
  184. package/src/modules/fulfillment/service.ts +0 -555
  185. package/src/modules/fulfillment/types.ts +0 -59
  186. package/src/modules/inventory/repository/index.ts +0 -509
  187. package/src/modules/inventory/schema.ts +0 -94
  188. package/src/modules/inventory/schemas.ts +0 -38
  189. package/src/modules/inventory/service.ts +0 -490
  190. package/src/modules/media/adapter.ts +0 -17
  191. package/src/modules/media/repository/index.ts +0 -274
  192. package/src/modules/media/schema.ts +0 -41
  193. package/src/modules/media/service.ts +0 -151
  194. package/src/modules/orders/repository/index.ts +0 -287
  195. package/src/modules/orders/schema.ts +0 -66
  196. package/src/modules/orders/service.ts +0 -619
  197. package/src/modules/orders/stale-order-cleanup.ts +0 -76
  198. package/src/modules/organization/service.ts +0 -191
  199. package/src/modules/payments/adapter.ts +0 -47
  200. package/src/modules/payments/repository/index.ts +0 -6
  201. package/src/modules/payments/service.ts +0 -107
  202. package/src/modules/pricing/repository/index.ts +0 -291
  203. package/src/modules/pricing/schema.ts +0 -71
  204. package/src/modules/pricing/schemas.ts +0 -38
  205. package/src/modules/pricing/service.ts +0 -494
  206. package/src/modules/promotions/repository/index.ts +0 -325
  207. package/src/modules/promotions/schema.ts +0 -62
  208. package/src/modules/promotions/schemas.ts +0 -38
  209. package/src/modules/promotions/service.ts +0 -598
  210. package/src/modules/search/adapter.ts +0 -57
  211. package/src/modules/search/hooks.ts +0 -12
  212. package/src/modules/search/repository/index.ts +0 -6
  213. package/src/modules/search/service.ts +0 -315
  214. package/src/modules/shipping/calculator.ts +0 -188
  215. package/src/modules/shipping/repository/index.ts +0 -6
  216. package/src/modules/shipping/service.ts +0 -51
  217. package/src/modules/tax/adapter.ts +0 -60
  218. package/src/modules/tax/repository/index.ts +0 -6
  219. package/src/modules/tax/service.ts +0 -53
  220. package/src/modules/webhooks/hook.ts +0 -34
  221. package/src/modules/webhooks/repository/index.ts +0 -278
  222. package/src/modules/webhooks/schema.ts +0 -56
  223. package/src/modules/webhooks/service.ts +0 -117
  224. package/src/modules/webhooks/signing.ts +0 -6
  225. package/src/modules/webhooks/ssrf-guard.ts +0 -71
  226. package/src/modules/webhooks/tasks.ts +0 -52
  227. package/src/modules/webhooks/worker.ts +0 -134
  228. package/src/runtime/commerce.ts +0 -145
  229. package/src/runtime/kernel.ts +0 -419
  230. package/src/runtime/logger.ts +0 -36
  231. package/src/runtime/server.ts +0 -349
  232. package/src/runtime/shutdown.ts +0 -43
  233. package/src/test-utils/create-pglite-adapter.ts +0 -129
  234. package/src/test-utils/create-plugin-test-app.ts +0 -128
  235. package/src/test-utils/create-repository-test-harness.ts +0 -16
  236. package/src/test-utils/create-test-config.ts +0 -190
  237. package/src/test-utils/create-test-kernel.ts +0 -7
  238. package/src/test-utils/create-test-plugin-context.ts +0 -75
  239. package/src/test-utils/rest-api-test-utils.ts +0 -265
  240. package/src/test-utils/test-actors.ts +0 -62
  241. package/src/test-utils/typed-hooks.ts +0 -54
  242. package/src/types/commerce-types.ts +0 -34
  243. package/src/utils/id.ts +0 -3
  244. package/src/utils/logger.ts +0 -18
  245. 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
- });