@unifiedcommerce/core 0.4.4 → 0.5.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.
- package/dist/adapters/console-email.d.ts +23 -0
- package/dist/adapters/console-email.d.ts.map +1 -0
- package/dist/adapters/console-email.js +38 -0
- package/dist/auth/access.d.ts +101 -0
- package/dist/auth/access.d.ts.map +1 -0
- package/dist/auth/access.js +128 -0
- package/dist/auth/auth-schema.d.ts +1475 -0
- package/dist/auth/auth-schema.d.ts.map +1 -0
- package/dist/auth/auth-schema.js +124 -0
- package/dist/auth/middleware.d.ts +5 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +141 -0
- package/dist/auth/org.d.ts +22 -0
- package/dist/auth/org.d.ts.map +1 -0
- package/dist/auth/org.js +36 -0
- package/dist/auth/permissions.d.ts +4 -0
- package/dist/auth/permissions.d.ts.map +1 -0
- package/dist/auth/permissions.js +24 -0
- package/dist/auth/setup.d.ts +29 -0
- package/dist/auth/setup.d.ts.map +1 -0
- package/dist/auth/setup.js +144 -0
- package/dist/auth/system-actor.d.ts +7 -0
- package/dist/auth/system-actor.d.ts.map +1 -0
- package/dist/auth/system-actor.js +17 -0
- package/dist/auth/types.d.ts +11 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/config/defaults.d.ts +3 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +80 -0
- package/dist/config/define-config.d.ts +9 -0
- package/dist/config/define-config.d.ts.map +1 -0
- package/dist/config/define-config.js +44 -0
- package/dist/config/types.d.ts +327 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +1 -0
- package/dist/generated/plugin-manifest.d.ts +48 -0
- package/dist/generated/plugin-manifest.d.ts.map +1 -0
- package/dist/generated/plugin-manifest.js +20 -0
- package/dist/hooks/checkout-completion.d.ts +58 -0
- package/dist/hooks/checkout-completion.d.ts.map +1 -0
- package/dist/hooks/checkout-completion.js +137 -0
- package/dist/hooks/checkout.d.ts +99 -0
- package/dist/hooks/checkout.d.ts.map +1 -0
- package/dist/hooks/checkout.js +317 -0
- package/dist/hooks/order-emails.d.ts +16 -0
- package/dist/hooks/order-emails.d.ts.map +1 -0
- package/dist/hooks/order-emails.js +44 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/interfaces/mcp/agent-prompt.d.ts +16 -0
- package/dist/interfaces/mcp/agent-prompt.d.ts.map +1 -0
- package/dist/interfaces/mcp/agent-prompt.js +172 -0
- package/dist/interfaces/mcp/context-enrichment.d.ts +39 -0
- package/dist/interfaces/mcp/context-enrichment.d.ts.map +1 -0
- package/dist/interfaces/mcp/context-enrichment.js +119 -0
- package/dist/interfaces/mcp/server.d.ts +5 -0
- package/dist/interfaces/mcp/server.d.ts.map +1 -0
- package/dist/interfaces/mcp/server.js +30 -0
- package/dist/interfaces/mcp/tool-builder.d.ts +120 -0
- package/dist/interfaces/mcp/tool-builder.d.ts.map +1 -0
- package/dist/interfaces/mcp/tool-builder.js +224 -0
- package/dist/interfaces/mcp/tools/analytics.d.ts +42 -0
- package/dist/interfaces/mcp/tools/analytics.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/analytics.js +70 -0
- package/dist/interfaces/mcp/tools/cart.d.ts +14 -0
- package/dist/interfaces/mcp/tools/cart.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/cart.js +47 -0
- package/dist/interfaces/mcp/tools/catalog.d.ts +53 -0
- package/dist/interfaces/mcp/tools/catalog.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/catalog.js +284 -0
- package/dist/interfaces/mcp/tools/index.d.ts +3 -0
- package/dist/interfaces/mcp/tools/index.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/index.js +20 -0
- package/dist/interfaces/mcp/tools/inventory.d.ts +27 -0
- package/dist/interfaces/mcp/tools/inventory.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/inventory.js +143 -0
- package/dist/interfaces/mcp/tools/orders.d.ts +18 -0
- package/dist/interfaces/mcp/tools/orders.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/orders.js +82 -0
- package/dist/interfaces/mcp/tools/pricing.d.ts +29 -0
- package/dist/interfaces/mcp/tools/pricing.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/pricing.js +90 -0
- package/dist/interfaces/mcp/tools/promotions.d.ts +44 -0
- package/dist/interfaces/mcp/tools/promotions.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/promotions.js +109 -0
- package/dist/interfaces/mcp/tools/registry.d.ts +32 -0
- package/dist/interfaces/mcp/tools/registry.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/registry.js +55 -0
- package/dist/interfaces/mcp/tools/search.d.ts +14 -0
- package/dist/interfaces/mcp/tools/search.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/search.js +39 -0
- package/dist/interfaces/mcp/tools/webhooks.d.ts +15 -0
- package/dist/interfaces/mcp/tools/webhooks.d.ts.map +1 -0
- package/dist/interfaces/mcp/tools/webhooks.js +48 -0
- package/dist/interfaces/mcp/transport.d.ts +20 -0
- package/dist/interfaces/mcp/transport.d.ts.map +1 -0
- package/dist/interfaces/mcp/transport.js +99 -0
- package/dist/interfaces/rest/customer-portal.d.ts +5 -0
- package/dist/interfaces/rest/customer-portal.d.ts.map +1 -0
- package/dist/interfaces/rest/customer-portal.js +206 -0
- package/dist/interfaces/rest/router.d.ts +164 -0
- package/dist/interfaces/rest/router.d.ts.map +1 -0
- package/dist/interfaces/rest/router.js +259 -0
- package/dist/interfaces/rest/routes/admin-jobs.d.ts +5 -0
- package/dist/interfaces/rest/routes/admin-jobs.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/admin-jobs.js +48 -0
- package/dist/interfaces/rest/routes/audit.d.ts +5 -0
- package/dist/interfaces/rest/routes/audit.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/audit.js +43 -0
- package/dist/interfaces/rest/routes/carts.d.ts +5 -0
- package/dist/interfaces/rest/routes/carts.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/carts.js +55 -0
- package/dist/interfaces/rest/routes/catalog.d.ts +5 -0
- package/dist/interfaces/rest/routes/catalog.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/catalog.js +256 -0
- package/dist/interfaces/rest/routes/checkout.d.ts +5 -0
- package/dist/interfaces/rest/routes/checkout.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/checkout.js +216 -0
- package/dist/interfaces/rest/routes/customers.d.ts +5 -0
- package/dist/interfaces/rest/routes/customers.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/customers.js +78 -0
- package/dist/interfaces/rest/routes/entity-aliases.d.ts +18 -0
- package/dist/interfaces/rest/routes/entity-aliases.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/entity-aliases.js +39 -0
- package/dist/interfaces/rest/routes/inventory.d.ts +5 -0
- package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/inventory.js +74 -0
- package/dist/interfaces/rest/routes/media.d.ts +5 -0
- package/dist/interfaces/rest/routes/media.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/media.js +65 -0
- package/dist/interfaces/rest/routes/orders.d.ts +5 -0
- package/dist/interfaces/rest/routes/orders.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/orders.js +64 -0
- package/dist/interfaces/rest/routes/payments.d.ts +5 -0
- package/dist/interfaces/rest/routes/payments.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/payments.js +45 -0
- package/dist/interfaces/rest/routes/pricing.d.ts +5 -0
- package/dist/interfaces/rest/routes/pricing.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/pricing.js +48 -0
- package/dist/interfaces/rest/routes/promotions.d.ts +5 -0
- package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/promotions.js +76 -0
- package/dist/interfaces/rest/routes/search.d.ts +5 -0
- package/dist/interfaces/rest/routes/search.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/search.js +60 -0
- package/dist/interfaces/rest/routes/webhooks.d.ts +5 -0
- package/dist/interfaces/rest/routes/webhooks.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/webhooks.js +39 -0
- package/dist/interfaces/rest/schemas/admin-jobs.d.ts +327 -0
- package/dist/interfaces/rest/schemas/admin-jobs.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/admin-jobs.js +37 -0
- package/dist/interfaces/rest/schemas/audit.d.ts +59 -0
- package/dist/interfaces/rest/schemas/audit.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/audit.js +43 -0
- package/dist/interfaces/rest/schemas/carts.d.ts +1456 -0
- package/dist/interfaces/rest/schemas/carts.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/carts.js +109 -0
- package/dist/interfaces/rest/schemas/catalog.d.ts +5452 -0
- package/dist/interfaces/rest/schemas/catalog.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/catalog.js +397 -0
- package/dist/interfaces/rest/schemas/checkout.d.ts +160 -0
- package/dist/interfaces/rest/schemas/checkout.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/checkout.js +60 -0
- package/dist/interfaces/rest/schemas/customer-portal.d.ts +2203 -0
- package/dist/interfaces/rest/schemas/customer-portal.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/customer-portal.js +177 -0
- package/dist/interfaces/rest/schemas/customers.d.ts +422 -0
- package/dist/interfaces/rest/schemas/customers.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/customers.js +150 -0
- package/dist/interfaces/rest/schemas/inventory.d.ts +561 -0
- package/dist/interfaces/rest/schemas/inventory.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/inventory.js +148 -0
- package/dist/interfaces/rest/schemas/media.d.ts +303 -0
- package/dist/interfaces/rest/schemas/media.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/media.js +69 -0
- package/dist/interfaces/rest/schemas/orders.d.ts +1792 -0
- package/dist/interfaces/rest/schemas/orders.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/orders.js +93 -0
- package/dist/interfaces/rest/schemas/pricing.d.ts +256 -0
- package/dist/interfaces/rest/schemas/pricing.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/pricing.js +72 -0
- package/dist/interfaces/rest/schemas/promotions.d.ts +374 -0
- package/dist/interfaces/rest/schemas/promotions.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/promotions.js +104 -0
- package/dist/interfaces/rest/schemas/responses.d.ts +4086 -0
- package/dist/interfaces/rest/schemas/responses.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/responses.js +74 -0
- package/dist/interfaces/rest/schemas/search.d.ts +247 -0
- package/dist/interfaces/rest/schemas/search.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/search.js +55 -0
- package/dist/interfaces/rest/schemas/shared.d.ts +95 -0
- package/dist/interfaces/rest/schemas/shared.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/shared.js +51 -0
- package/dist/interfaces/rest/schemas/webhooks.d.ts +221 -0
- package/dist/interfaces/rest/schemas/webhooks.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/webhooks.js +62 -0
- package/dist/interfaces/rest/utils.d.ts +45 -0
- package/dist/interfaces/rest/utils.d.ts.map +1 -0
- package/dist/interfaces/rest/utils.js +71 -0
- package/dist/interfaces/rest/webhook-router.d.ts +41 -0
- package/dist/interfaces/rest/webhook-router.d.ts.map +1 -0
- package/dist/interfaces/rest/webhook-router.js +36 -0
- package/dist/kernel/compensation/executor.d.ts +21 -0
- package/dist/kernel/compensation/executor.d.ts.map +1 -0
- package/dist/kernel/compensation/executor.js +36 -0
- package/dist/kernel/compensation/types.d.ts +25 -0
- package/dist/kernel/compensation/types.d.ts.map +1 -0
- package/dist/kernel/compensation/types.js +1 -0
- package/dist/kernel/database/adapter.d.ts +18 -0
- package/dist/kernel/database/adapter.d.ts.map +1 -0
- package/dist/kernel/database/adapter.js +3 -0
- package/dist/kernel/database/drizzle-db.d.ts +49 -0
- package/dist/kernel/database/drizzle-db.d.ts.map +1 -0
- package/dist/kernel/database/drizzle-db.js +20 -0
- package/dist/kernel/database/migrate.d.ts +38 -0
- package/dist/kernel/database/migrate.d.ts.map +1 -0
- package/dist/kernel/database/migrate.js +61 -0
- package/dist/kernel/database/plugin-types.d.ts +32 -0
- package/dist/kernel/database/plugin-types.d.ts.map +1 -0
- package/dist/kernel/database/plugin-types.js +10 -0
- package/dist/kernel/database/schema.d.ts +24 -0
- package/dist/kernel/database/schema.d.ts.map +1 -0
- package/dist/kernel/database/schema.js +36 -0
- package/dist/kernel/database/scoped-db.d.ts +20 -0
- package/dist/kernel/database/scoped-db.d.ts.map +1 -0
- package/dist/kernel/database/scoped-db.js +62 -0
- package/dist/kernel/database/tx-context.d.ts +15 -0
- package/dist/kernel/database/tx-context.d.ts.map +1 -0
- package/dist/kernel/database/tx-context.js +19 -0
- package/dist/kernel/error-mapper.d.ts +3 -0
- package/dist/kernel/error-mapper.d.ts.map +1 -0
- package/dist/kernel/error-mapper.js +12 -0
- package/dist/kernel/errors.d.ts +38 -0
- package/dist/kernel/errors.d.ts.map +1 -0
- package/dist/kernel/errors.js +69 -0
- package/dist/kernel/factory/repository-factory.d.ts +71 -0
- package/dist/kernel/factory/repository-factory.d.ts.map +1 -0
- package/dist/kernel/factory/repository-factory.js +138 -0
- package/dist/kernel/hooks/create-context.d.ts +25 -0
- package/dist/kernel/hooks/create-context.d.ts.map +1 -0
- package/dist/kernel/hooks/create-context.js +22 -0
- package/dist/kernel/hooks/executor.d.ts +12 -0
- package/dist/kernel/hooks/executor.d.ts.map +1 -0
- package/dist/kernel/hooks/executor.js +50 -0
- package/dist/kernel/hooks/registry.d.ts +28 -0
- package/dist/kernel/hooks/registry.d.ts.map +1 -0
- package/dist/kernel/hooks/registry.js +58 -0
- package/dist/kernel/hooks/types.d.ts +37 -0
- package/dist/kernel/hooks/types.d.ts.map +1 -0
- package/dist/kernel/hooks/types.js +1 -0
- package/dist/kernel/http-error.d.ts +30 -0
- package/dist/kernel/http-error.d.ts.map +1 -0
- package/dist/kernel/http-error.js +35 -0
- package/dist/kernel/jobs/adapter.d.ts +25 -0
- package/dist/kernel/jobs/adapter.d.ts.map +1 -0
- package/dist/kernel/jobs/adapter.js +9 -0
- package/dist/kernel/jobs/drizzle-adapter.d.ts +15 -0
- package/dist/kernel/jobs/drizzle-adapter.d.ts.map +1 -0
- package/dist/kernel/jobs/drizzle-adapter.js +42 -0
- package/dist/kernel/jobs/runner.d.ts +24 -0
- package/dist/kernel/jobs/runner.d.ts.map +1 -0
- package/dist/kernel/jobs/runner.js +114 -0
- package/dist/kernel/jobs/schema.d.ts +280 -0
- package/dist/kernel/jobs/schema.d.ts.map +1 -0
- package/dist/kernel/jobs/schema.js +37 -0
- package/dist/kernel/jobs/types.d.ts +30 -0
- package/dist/kernel/jobs/types.d.ts.map +1 -0
- package/dist/kernel/jobs/types.js +1 -0
- package/dist/kernel/local-api.d.ts +103 -0
- package/dist/kernel/local-api.d.ts.map +1 -0
- package/dist/kernel/local-api.js +89 -0
- package/dist/kernel/plugin/manifest.d.ts +90 -0
- package/dist/kernel/plugin/manifest.d.ts.map +1 -0
- package/dist/kernel/plugin/manifest.js +169 -0
- package/dist/kernel/query/executor.d.ts +21 -0
- package/dist/kernel/query/executor.d.ts.map +1 -0
- package/dist/kernel/query/executor.js +128 -0
- package/dist/kernel/query/registry.d.ts +33 -0
- package/dist/kernel/query/registry.d.ts.map +1 -0
- package/dist/kernel/query/registry.js +20 -0
- package/dist/kernel/result.d.ts +36 -0
- package/dist/kernel/result.d.ts.map +1 -0
- package/dist/kernel/result.js +16 -0
- package/dist/kernel/schema/extra-columns.d.ts +23 -0
- package/dist/kernel/schema/extra-columns.d.ts.map +1 -0
- package/dist/kernel/schema/extra-columns.js +10 -0
- package/dist/kernel/service-registry.d.ts +109 -0
- package/dist/kernel/service-registry.d.ts.map +1 -0
- package/dist/kernel/service-registry.js +26 -0
- package/dist/kernel/service-timing.d.ts +25 -0
- package/dist/kernel/service-timing.d.ts.map +1 -0
- package/dist/kernel/service-timing.js +62 -0
- package/dist/kernel/state-machine/machine.d.ts +24 -0
- package/dist/kernel/state-machine/machine.d.ts.map +1 -0
- package/dist/kernel/state-machine/machine.js +70 -0
- package/dist/modules/analytics/drizzle-adapter.d.ts +13 -0
- package/dist/modules/analytics/drizzle-adapter.d.ts.map +1 -0
- package/dist/modules/analytics/drizzle-adapter.js +358 -0
- package/dist/modules/analytics/hooks.d.ts +13 -0
- package/dist/modules/analytics/hooks.d.ts.map +1 -0
- package/dist/modules/analytics/hooks.js +12 -0
- package/dist/modules/analytics/models.d.ts +14 -0
- package/dist/modules/analytics/models.d.ts.map +1 -0
- package/dist/modules/analytics/models.js +118 -0
- package/dist/modules/analytics/repository/index.d.ts +5 -0
- package/dist/modules/analytics/repository/index.d.ts.map +1 -0
- package/dist/modules/analytics/repository/index.js +1 -0
- package/dist/modules/analytics/service.d.ts +45 -0
- package/dist/modules/analytics/service.d.ts.map +1 -0
- package/dist/modules/analytics/service.js +196 -0
- package/dist/modules/analytics/types.d.ts +119 -0
- package/dist/modules/analytics/types.d.ts.map +1 -0
- package/dist/modules/analytics/types.js +25 -0
- package/dist/modules/audit/hooks.d.ts +7 -0
- package/dist/modules/audit/hooks.d.ts.map +1 -0
- package/dist/modules/audit/hooks.js +67 -0
- package/dist/modules/audit/schema.d.ts +178 -0
- package/dist/modules/audit/schema.d.ts.map +1 -0
- package/dist/modules/audit/schema.js +21 -0
- package/dist/modules/audit/service.d.ts +38 -0
- package/dist/modules/audit/service.d.ts.map +1 -0
- package/dist/modules/audit/service.js +109 -0
- package/dist/modules/cart/access.d.ts +11 -0
- package/dist/modules/cart/access.d.ts.map +1 -0
- package/dist/modules/cart/access.js +18 -0
- package/dist/modules/cart/matcher.d.ts +20 -0
- package/dist/modules/cart/matcher.d.ts.map +1 -0
- package/dist/modules/cart/matcher.js +2 -0
- package/dist/modules/cart/repository/index.d.ts +45 -0
- package/dist/modules/cart/repository/index.d.ts.map +1 -0
- package/dist/modules/cart/repository/index.js +158 -0
- package/dist/modules/cart/schema.d.ts +359 -0
- package/dist/modules/cart/schema.d.ts.map +1 -0
- package/dist/modules/cart/schema.js +40 -0
- package/dist/modules/cart/schemas.d.ts +29 -0
- package/dist/modules/cart/schemas.d.ts.map +1 -0
- package/dist/modules/cart/schemas.js +14 -0
- package/dist/modules/cart/service.d.ts +63 -0
- package/dist/modules/cart/service.d.ts.map +1 -0
- package/dist/modules/cart/service.js +339 -0
- package/dist/modules/catalog/repository/index.d.ts +106 -0
- package/dist/modules/catalog/repository/index.d.ts.map +1 -0
- package/dist/modules/catalog/repository/index.js +455 -0
- package/dist/modules/catalog/schema.d.ts +1193 -0
- package/dist/modules/catalog/schema.d.ts.map +1 -0
- package/dist/modules/catalog/schema.js +149 -0
- package/dist/modules/catalog/schemas.d.ts +81 -0
- package/dist/modules/catalog/schemas.d.ts.map +1 -0
- package/dist/modules/catalog/schemas.js +62 -0
- package/dist/modules/catalog/service.d.ts +165 -0
- package/dist/modules/catalog/service.d.ts.map +1 -0
- package/dist/modules/catalog/service.js +775 -0
- package/dist/modules/customers/repository/index.d.ts +47 -0
- package/dist/modules/customers/repository/index.d.ts.map +1 -0
- package/dist/modules/customers/repository/index.js +206 -0
- package/dist/modules/customers/schema.d.ts +560 -0
- package/dist/modules/customers/schema.d.ts.map +1 -0
- package/dist/modules/customers/schema.js +60 -0
- package/dist/modules/customers/service.d.ts +27 -0
- package/dist/modules/customers/service.d.ts.map +1 -0
- package/dist/modules/customers/service.js +106 -0
- package/dist/modules/fulfillment/repository/index.d.ts +63 -0
- package/dist/modules/fulfillment/repository/index.d.ts.map +1 -0
- package/dist/modules/fulfillment/repository/index.js +268 -0
- package/dist/modules/fulfillment/schema.d.ts +655 -0
- package/dist/modules/fulfillment/schema.d.ts.map +1 -0
- package/dist/modules/fulfillment/schema.js +83 -0
- package/dist/modules/fulfillment/service.d.ts +58 -0
- package/dist/modules/fulfillment/service.d.ts.map +1 -0
- package/dist/modules/fulfillment/service.js +338 -0
- package/dist/modules/fulfillment/types.d.ts +44 -0
- package/dist/modules/fulfillment/types.d.ts.map +1 -0
- package/dist/modules/fulfillment/types.js +1 -0
- package/dist/modules/inventory/repository/index.d.ts +81 -0
- package/dist/modules/inventory/repository/index.d.ts.map +1 -0
- package/dist/modules/inventory/repository/index.js +310 -0
- package/dist/modules/inventory/schema.d.ts +570 -0
- package/dist/modules/inventory/schema.d.ts.map +1 -0
- package/dist/modules/inventory/schema.js +69 -0
- package/dist/modules/inventory/schemas.d.ts +31 -0
- package/dist/modules/inventory/schemas.d.ts.map +1 -0
- package/dist/modules/inventory/schemas.js +28 -0
- package/dist/modules/inventory/service.d.ts +69 -0
- package/dist/modules/inventory/service.d.ts.map +1 -0
- package/dist/modules/inventory/service.js +283 -0
- package/dist/modules/media/adapter.d.ts +16 -0
- package/dist/modules/media/adapter.d.ts.map +1 -0
- package/dist/modules/media/adapter.js +1 -0
- package/dist/modules/media/repository/index.d.ts +35 -0
- package/dist/modules/media/repository/index.d.ts.map +1 -0
- package/dist/modules/media/repository/index.js +176 -0
- package/dist/modules/media/schema.d.ts +289 -0
- package/dist/modules/media/schema.d.ts.map +1 -0
- package/dist/modules/media/schema.js +35 -0
- package/dist/modules/media/service.d.ts +42 -0
- package/dist/modules/media/service.d.ts.map +1 -0
- package/dist/modules/media/service.js +89 -0
- package/dist/modules/orders/repository/index.d.ts +48 -0
- package/dist/modules/orders/repository/index.d.ts.map +1 -0
- package/dist/modules/orders/repository/index.js +199 -0
- package/dist/modules/orders/schema.d.ts +672 -0
- package/dist/modules/orders/schema.d.ts.map +1 -0
- package/dist/modules/orders/schema.js +63 -0
- package/dist/modules/orders/service.d.ts +85 -0
- package/dist/modules/orders/service.d.ts.map +1 -0
- package/dist/modules/orders/service.js +313 -0
- package/dist/modules/orders/stale-order-cleanup.d.ts +27 -0
- package/dist/modules/orders/stale-order-cleanup.d.ts.map +1 -0
- package/dist/modules/orders/stale-order-cleanup.js +55 -0
- package/dist/modules/organization/service.d.ts +53 -0
- package/dist/modules/organization/service.d.ts.map +1 -0
- package/dist/modules/organization/service.js +151 -0
- package/dist/modules/payments/adapter.d.ts +42 -0
- package/dist/modules/payments/adapter.d.ts.map +1 -0
- package/dist/modules/payments/adapter.js +1 -0
- package/dist/modules/payments/repository/index.d.ts +5 -0
- package/dist/modules/payments/repository/index.d.ts.map +1 -0
- package/dist/modules/payments/repository/index.js +1 -0
- package/dist/modules/payments/service.d.ts +23 -0
- package/dist/modules/payments/service.d.ts.map +1 -0
- package/dist/modules/payments/service.js +72 -0
- package/dist/modules/pricing/repository/index.d.ts +34 -0
- package/dist/modules/pricing/repository/index.d.ts.map +1 -0
- package/dist/modules/pricing/repository/index.js +176 -0
- package/dist/modules/pricing/schema.d.ts +565 -0
- package/dist/modules/pricing/schema.d.ts.map +1 -0
- package/dist/modules/pricing/schema.js +57 -0
- package/dist/modules/pricing/schemas.d.ts +37 -0
- package/dist/modules/pricing/schemas.d.ts.map +1 -0
- package/dist/modules/pricing/schemas.js +30 -0
- package/dist/modules/pricing/service.d.ts +62 -0
- package/dist/modules/pricing/service.d.ts.map +1 -0
- package/dist/modules/pricing/service.js +308 -0
- package/dist/modules/promotions/repository/index.d.ts +41 -0
- package/dist/modules/promotions/repository/index.d.ts.map +1 -0
- package/dist/modules/promotions/repository/index.js +204 -0
- package/dist/modules/promotions/schema.d.ts +427 -0
- package/dist/modules/promotions/schema.d.ts.map +1 -0
- package/dist/modules/promotions/schema.js +52 -0
- package/dist/modules/promotions/schemas.d.ts +33 -0
- package/dist/modules/promotions/schemas.d.ts.map +1 -0
- package/dist/modules/promotions/schemas.js +32 -0
- package/dist/modules/promotions/service.d.ts +85 -0
- package/dist/modules/promotions/service.d.ts.map +1 -0
- package/dist/modules/promotions/service.js +368 -0
- package/dist/modules/search/adapter.d.ts +51 -0
- package/dist/modules/search/adapter.d.ts.map +1 -0
- package/dist/modules/search/adapter.js +1 -0
- package/dist/modules/search/hooks.d.ts +8 -0
- package/dist/modules/search/hooks.d.ts.map +1 -0
- package/dist/modules/search/hooks.js +6 -0
- package/dist/modules/search/repository/index.d.ts +5 -0
- package/dist/modules/search/repository/index.d.ts.map +1 -0
- package/dist/modules/search/repository/index.js +1 -0
- package/dist/modules/search/service.d.ts +24 -0
- package/dist/modules/search/service.d.ts.map +1 -0
- package/dist/modules/search/service.js +217 -0
- package/dist/modules/shipping/calculator.d.ts +42 -0
- package/dist/modules/shipping/calculator.d.ts.map +1 -0
- package/dist/modules/shipping/calculator.js +91 -0
- package/dist/modules/shipping/repository/index.d.ts +5 -0
- package/dist/modules/shipping/repository/index.d.ts.map +1 -0
- package/dist/modules/shipping/repository/index.js +1 -0
- package/dist/modules/shipping/service.d.ts +28 -0
- package/dist/modules/shipping/service.d.ts.map +1 -0
- package/dist/modules/shipping/service.js +20 -0
- package/dist/modules/tax/adapter.d.ts +58 -0
- package/dist/modules/tax/adapter.d.ts.map +1 -0
- package/dist/modules/tax/adapter.js +1 -0
- package/dist/modules/tax/repository/index.d.ts +5 -0
- package/dist/modules/tax/repository/index.d.ts.map +1 -0
- package/dist/modules/tax/repository/index.js +1 -0
- package/dist/modules/tax/service.d.ts +19 -0
- package/dist/modules/tax/service.d.ts.map +1 -0
- package/dist/modules/tax/service.js +34 -0
- package/dist/modules/webhooks/hook.d.ts +13 -0
- package/dist/modules/webhooks/hook.d.ts.map +1 -0
- package/dist/modules/webhooks/hook.js +29 -0
- package/dist/modules/webhooks/repository/index.d.ts +40 -0
- package/dist/modules/webhooks/repository/index.d.ts.map +1 -0
- package/dist/modules/webhooks/repository/index.js +175 -0
- package/dist/modules/webhooks/schema.d.ts +404 -0
- package/dist/modules/webhooks/schema.d.ts.map +1 -0
- package/dist/modules/webhooks/schema.js +40 -0
- package/dist/modules/webhooks/service.d.ts +23 -0
- package/dist/modules/webhooks/service.d.ts.map +1 -0
- package/dist/modules/webhooks/service.js +92 -0
- package/dist/modules/webhooks/signing.d.ts +2 -0
- package/dist/modules/webhooks/signing.d.ts.map +1 -0
- package/dist/modules/webhooks/signing.js +5 -0
- package/dist/modules/webhooks/ssrf-guard.d.ts +19 -0
- package/dist/modules/webhooks/ssrf-guard.d.ts.map +1 -0
- package/dist/modules/webhooks/ssrf-guard.js +79 -0
- package/dist/modules/webhooks/tasks.d.ts +16 -0
- package/dist/modules/webhooks/tasks.d.ts.map +1 -0
- package/dist/modules/webhooks/tasks.js +35 -0
- package/dist/modules/webhooks/worker.d.ts +21 -0
- package/dist/modules/webhooks/worker.d.ts.map +1 -0
- package/dist/modules/webhooks/worker.js +113 -0
- package/dist/runtime/commerce.d.ts +110 -0
- package/dist/runtime/commerce.d.ts.map +1 -0
- package/dist/runtime/commerce.js +37 -0
- package/dist/runtime/kernel.d.ts +71 -0
- package/dist/runtime/kernel.d.ts.map +1 -0
- package/dist/runtime/kernel.js +306 -0
- package/dist/runtime/logger.d.ts +11 -0
- package/dist/runtime/logger.d.ts.map +1 -0
- package/dist/runtime/logger.js +32 -0
- package/dist/runtime/shutdown.d.ts +15 -0
- package/dist/runtime/shutdown.d.ts.map +1 -0
- package/dist/runtime/shutdown.js +34 -0
- package/dist/test-utils/create-pglite-adapter.d.ts +32 -0
- package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -0
- package/dist/test-utils/create-pglite-adapter.js +107 -0
- package/dist/test-utils/create-plugin-test-app.d.ts +50 -0
- package/dist/test-utils/create-plugin-test-app.d.ts.map +1 -0
- package/dist/test-utils/create-plugin-test-app.js +74 -0
- package/dist/test-utils/create-repository-test-harness.d.ts +8 -0
- package/dist/test-utils/create-repository-test-harness.d.ts.map +1 -0
- package/dist/test-utils/create-repository-test-harness.js +7 -0
- package/dist/test-utils/create-test-config.d.ts +18 -0
- package/dist/test-utils/create-test-config.d.ts.map +1 -0
- package/dist/test-utils/create-test-config.js +172 -0
- package/dist/test-utils/create-test-kernel.d.ts +3 -0
- package/dist/test-utils/create-test-kernel.d.ts.map +1 -0
- package/dist/test-utils/create-test-kernel.js +5 -0
- package/dist/test-utils/create-test-plugin-context.d.ts +42 -0
- package/dist/test-utils/create-test-plugin-context.d.ts.map +1 -0
- package/dist/test-utils/create-test-plugin-context.js +46 -0
- package/dist/test-utils/rest-api-test-utils.d.ts +64 -0
- package/dist/test-utils/rest-api-test-utils.d.ts.map +1 -0
- package/dist/test-utils/rest-api-test-utils.js +207 -0
- package/dist/test-utils/test-actors.d.ts +15 -0
- package/dist/test-utils/test-actors.d.ts.map +1 -0
- package/dist/test-utils/test-actors.js +57 -0
- package/dist/test-utils/typed-hooks.d.ts +43 -0
- package/dist/test-utils/typed-hooks.d.ts.map +1 -0
- package/dist/test-utils/typed-hooks.js +35 -0
- package/dist/testing.d.ts +14 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +13 -0
- package/dist/types/commerce-types.d.ts +34 -0
- package/dist/types/commerce-types.d.ts.map +1 -0
- package/dist/types/commerce-types.js +1 -0
- package/dist/utils/id.d.ts +2 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +3 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +16 -0
- package/dist/utils/pagination.d.ts +11 -0
- package/dist/utils/pagination.d.ts.map +1 -0
- package/dist/utils/pagination.js +15 -0
- package/package.json +2 -2
- package/src/auth/setup.ts +26 -0
- package/src/interfaces/rest/routes/customers.ts +7 -1
- package/src/interfaces/rest/routes/inventory.ts +4 -1
- package/src/interfaces/rest/routes/promotions.ts +12 -9
- package/src/interfaces/rest/schemas/promotions.ts +10 -4
- package/src/modules/catalog/service.ts +19 -0
- package/src/modules/promotions/service.ts +32 -0
- package/src/runtime/commerce.ts +1 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { checkoutRoute } from "../schemas/checkout.js";
|
|
3
|
+
import { applyPromotionCodes, authorizePayment, calculateShipping, calculateTax, checkInventoryAvailability, completeCheckout, recordAnalyticsEvent, resolveCurrentPrices, validateCartNotEmpty, validatePaymentMethod, } from "../../../hooks/checkout.js";
|
|
4
|
+
import { runAfterHooks, runBeforeHooks } from "../../../kernel/hooks/executor.js";
|
|
5
|
+
import { createHookContext } from "../../../kernel/hooks/create-context.js";
|
|
6
|
+
import { mapErrorToResponse, mapErrorToStatus } from "../utils.js";
|
|
7
|
+
import { isCommerceError } from "../../../kernel/errors.js";
|
|
8
|
+
import { makeId } from "../../../utils/id.js";
|
|
9
|
+
export function checkoutRoutes(kernel) {
|
|
10
|
+
const router = new OpenAPIHono();
|
|
11
|
+
// @ts-expect-error -- openapi() enforces strict response typing but our handler
|
|
12
|
+
// returns union responses (201 | 400 | 422). The route definition documents the
|
|
13
|
+
// contract; the defaultHook handles Zod validation; the handler returns dynamic status.
|
|
14
|
+
router.openapi(checkoutRoute, async (c) => {
|
|
15
|
+
const body = c.req.valid("json");
|
|
16
|
+
const actor = c.get("actor");
|
|
17
|
+
const checkoutData = {
|
|
18
|
+
checkoutId: makeId(),
|
|
19
|
+
cartId: body.cartId,
|
|
20
|
+
currency: body.currency ?? "USD",
|
|
21
|
+
paymentMethodId: body.paymentMethodId,
|
|
22
|
+
lineItems: [],
|
|
23
|
+
subtotal: 0,
|
|
24
|
+
discountTotal: 0,
|
|
25
|
+
taxTotal: 0,
|
|
26
|
+
shippingTotal: 0,
|
|
27
|
+
total: 0,
|
|
28
|
+
...(body.customerId !== undefined ? { customerId: body.customerId } : {}),
|
|
29
|
+
...(body.customerGroupIds !== undefined
|
|
30
|
+
? { customerGroupIds: body.customerGroupIds }
|
|
31
|
+
: {}),
|
|
32
|
+
...(body.promotionCodes !== undefined
|
|
33
|
+
? { promotionCodes: body.promotionCodes }
|
|
34
|
+
: {}),
|
|
35
|
+
...(body.shippingAddress != null
|
|
36
|
+
? {
|
|
37
|
+
shippingAddress: {
|
|
38
|
+
line1: body.shippingAddress.line1,
|
|
39
|
+
city: body.shippingAddress.city,
|
|
40
|
+
postalCode: body.shippingAddress.postalCode,
|
|
41
|
+
country: body.shippingAddress.country,
|
|
42
|
+
...(body.shippingAddress.line2 != null ? { line2: body.shippingAddress.line2 } : {}),
|
|
43
|
+
...(body.shippingAddress.state != null ? { state: body.shippingAddress.state } : {}),
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: {}),
|
|
47
|
+
};
|
|
48
|
+
// ── Phase 1: Validate & Calculate (inside DB transaction — fast SQL only) ──
|
|
49
|
+
const validationHooks = [
|
|
50
|
+
validateCartNotEmpty,
|
|
51
|
+
resolveCurrentPrices,
|
|
52
|
+
checkInventoryAvailability,
|
|
53
|
+
applyPromotionCodes,
|
|
54
|
+
calculateTax,
|
|
55
|
+
calculateShipping,
|
|
56
|
+
...kernel.hooks.resolve("checkout.beforePayment"),
|
|
57
|
+
validatePaymentMethod,
|
|
58
|
+
];
|
|
59
|
+
// ── Phase 2: Payment Authorization (outside transaction — external API call) ──
|
|
60
|
+
const paymentHooks = [
|
|
61
|
+
authorizePayment,
|
|
62
|
+
...kernel.hooks.resolve("checkout.beforeCreate"),
|
|
63
|
+
];
|
|
64
|
+
const afterHooks = [
|
|
65
|
+
completeCheckout,
|
|
66
|
+
recordAnalyticsEvent,
|
|
67
|
+
...kernel.hooks.resolve("checkout.afterCreate"),
|
|
68
|
+
];
|
|
69
|
+
const context = createHookContext({
|
|
70
|
+
actor,
|
|
71
|
+
logger: kernel.logger,
|
|
72
|
+
services: kernel.services,
|
|
73
|
+
context: { moduleName: "checkout" },
|
|
74
|
+
origin: "rest",
|
|
75
|
+
kernel: { database: { db: kernel.database.db } },
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
// Phase 1: DB transaction for validation — releases connection immediately after
|
|
79
|
+
const validated = await kernel.database.transaction(async (_tx) => {
|
|
80
|
+
context.tx = _tx;
|
|
81
|
+
return runBeforeHooks(validationHooks, checkoutData, "create", context);
|
|
82
|
+
});
|
|
83
|
+
// Phase 2: Payment authorization — NO DB connection held while calling Stripe/etc.
|
|
84
|
+
// If Stripe takes 5s, the DB connection pool is not affected.
|
|
85
|
+
context.tx = null;
|
|
86
|
+
const processed = await runBeforeHooks(paymentHooks, validated, "create", context);
|
|
87
|
+
// Resolve customer profile UUID from customerId (may be a profile UUID or a Better Auth user_id)
|
|
88
|
+
let customerUuid = undefined;
|
|
89
|
+
if (processed.customerId) {
|
|
90
|
+
const uuidRe = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
91
|
+
if (uuidRe.test(processed.customerId)) {
|
|
92
|
+
// Looks like a profile UUID — try direct lookup (no auto-create)
|
|
93
|
+
const byIdResult = await kernel.services.customers.getById(processed.customerId, actor);
|
|
94
|
+
if (byIdResult.ok) {
|
|
95
|
+
customerUuid = byIdResult.value.id;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!customerUuid) {
|
|
99
|
+
// Fall back to user_id lookup (auto-creates customer profile if needed)
|
|
100
|
+
const byUserIdResult = await kernel.services.customers.getByUserId(processed.customerId, actor);
|
|
101
|
+
if (byUserIdResult.ok) {
|
|
102
|
+
customerUuid = byUserIdResult.value.id;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// If both lookups fail, we still allow guest checkout (customerUuid remains undefined)
|
|
106
|
+
}
|
|
107
|
+
const orderPayload = {
|
|
108
|
+
currency: processed.currency,
|
|
109
|
+
subtotal: processed.subtotal,
|
|
110
|
+
taxTotal: processed.taxTotal,
|
|
111
|
+
shippingTotal: processed.shippingTotal,
|
|
112
|
+
discountTotal: processed.discountTotal,
|
|
113
|
+
grandTotal: processed.total,
|
|
114
|
+
paymentIntentId: processed.paymentIntentId,
|
|
115
|
+
paymentMethodId: processed.paymentMethodId,
|
|
116
|
+
metadata: {
|
|
117
|
+
// H2 fix: Merge hook-injected metadata (e.g., BNPL fee) before core fields
|
|
118
|
+
...(typeof processed.metadata === "object" && processed.metadata !== null
|
|
119
|
+
? processed.metadata
|
|
120
|
+
: {}),
|
|
121
|
+
cartId: processed.cartId,
|
|
122
|
+
paymentIntentId: processed.paymentIntentId,
|
|
123
|
+
checkoutId: processed.checkoutId,
|
|
124
|
+
promotionCodes: processed.promotionCodes,
|
|
125
|
+
appliedPromotions: processed.appliedPromotions,
|
|
126
|
+
shippingAddress: processed.shippingAddress,
|
|
127
|
+
},
|
|
128
|
+
lineItems: processed.lineItems.map((lineItem) => {
|
|
129
|
+
const payload = {
|
|
130
|
+
entityId: lineItem.entityId,
|
|
131
|
+
entityType: lineItem.entityType ?? "product",
|
|
132
|
+
title: lineItem.title ?? lineItem.entityId,
|
|
133
|
+
quantity: lineItem.quantity,
|
|
134
|
+
unitPrice: lineItem.resolvedUnitPrice ?? 0,
|
|
135
|
+
totalPrice: lineItem.resolvedTotal ?? 0,
|
|
136
|
+
};
|
|
137
|
+
return lineItem.variantId !== undefined
|
|
138
|
+
? { ...payload, variantId: lineItem.variantId }
|
|
139
|
+
: payload;
|
|
140
|
+
}),
|
|
141
|
+
...(customerUuid !== undefined
|
|
142
|
+
? { customerId: customerUuid }
|
|
143
|
+
: {}),
|
|
144
|
+
};
|
|
145
|
+
const order = await kernel.services.orders.create(orderPayload, actor);
|
|
146
|
+
if (!order.ok) {
|
|
147
|
+
return c.json(mapErrorToResponse(order.error), mapErrorToStatus(order.error));
|
|
148
|
+
}
|
|
149
|
+
if (order.ok && (processed.appliedPromotions?.length ?? 0) > 0) {
|
|
150
|
+
await kernel.services.promotions.recordUsage({
|
|
151
|
+
promotions: processed.appliedPromotions ?? [],
|
|
152
|
+
orderId: order.value.id,
|
|
153
|
+
...(customerUuid !== undefined
|
|
154
|
+
? { customerId: customerUuid }
|
|
155
|
+
: {}),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (order.ok) {
|
|
159
|
+
await kernel.services.tax.reportTransaction({
|
|
160
|
+
transactionId: order.value.id,
|
|
161
|
+
transactionDate: new Date(),
|
|
162
|
+
currency: processed.currency,
|
|
163
|
+
amount: processed.subtotal -
|
|
164
|
+
processed.discountTotal +
|
|
165
|
+
processed.shippingTotal,
|
|
166
|
+
shipping: processed.shippingTotal,
|
|
167
|
+
salesTax: processed.taxTotal,
|
|
168
|
+
lineItems: processed.lineItems.map((lineItem, index) => ({
|
|
169
|
+
id: lineItem.id ?? `${order.value.id}-${index + 1}`,
|
|
170
|
+
entityId: lineItem.entityId,
|
|
171
|
+
description: lineItem.title ?? lineItem.entityId,
|
|
172
|
+
quantity: lineItem.quantity,
|
|
173
|
+
unitPrice: lineItem.resolvedUnitPrice ?? 0,
|
|
174
|
+
...(lineItem.discountAmount !== undefined
|
|
175
|
+
? { discount: lineItem.discountAmount }
|
|
176
|
+
: {}),
|
|
177
|
+
})),
|
|
178
|
+
...(customerUuid !== undefined
|
|
179
|
+
? { customerId: customerUuid }
|
|
180
|
+
: {}),
|
|
181
|
+
...(processed.shippingAddress !== undefined
|
|
182
|
+
? { toAddress: processed.shippingAddress }
|
|
183
|
+
: {}),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// Stash paymentMethodId for completeCheckout compensation chain
|
|
187
|
+
context.context.paymentMethodId = processed.paymentMethodId;
|
|
188
|
+
const afterReport = await runAfterHooks(afterHooks, null, order.value, "create", context);
|
|
189
|
+
await kernel.services.cart.markAsCheckedOut(body.cartId, actor);
|
|
190
|
+
return c.json({
|
|
191
|
+
data: {
|
|
192
|
+
...order.value,
|
|
193
|
+
// Stripe Elements requires clientSecret to collect card details on the frontend
|
|
194
|
+
...(processed.paymentClientSecret
|
|
195
|
+
? { paymentClientSecret: processed.paymentClientSecret }
|
|
196
|
+
: {}),
|
|
197
|
+
},
|
|
198
|
+
meta: afterReport.hasErrors
|
|
199
|
+
? { hookErrors: afterReport.errors }
|
|
200
|
+
: undefined,
|
|
201
|
+
}, 201);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
const message = isCommerceError(error)
|
|
205
|
+
? error.message
|
|
206
|
+
: "Checkout failed.";
|
|
207
|
+
return c.json({
|
|
208
|
+
error: {
|
|
209
|
+
code: "CHECKOUT_FAILED",
|
|
210
|
+
message,
|
|
211
|
+
},
|
|
212
|
+
}, 422);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return router;
|
|
216
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
+
import { type AppEnv } from "../utils.js";
|
|
4
|
+
export declare function customerRoutes(kernel: Kernel): OpenAPIHono<AppEnv, {}, "/">;
|
|
5
|
+
//# sourceMappingURL=customers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customers.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/customers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAQzD,OAAO,EAAE,KAAK,MAAM,EAAsE,MAAM,aAAa,CAAC;AAE9G,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,gCAwF5C"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { listCustomersRoute, getCustomerRoute, updateCustomerRoute, getCustomerOrdersRoute, getCustomerAddressesRoute, } from "../schemas/customers.js";
|
|
3
|
+
import { mapErrorToResponse, mapErrorToStatus, parsePagination, requirePerm } from "../utils.js";
|
|
4
|
+
export function customerRoutes(kernel) {
|
|
5
|
+
const router = new OpenAPIHono();
|
|
6
|
+
// All customer admin routes require authentication + customers:read
|
|
7
|
+
router.use("/*", requirePerm("customers:read"));
|
|
8
|
+
router.use("/", requirePerm("customers:read"));
|
|
9
|
+
// @ts-expect-error -- openapi handler union return type
|
|
10
|
+
router.openapi(listCustomersRoute, async (c) => {
|
|
11
|
+
const actor = c.get("actor");
|
|
12
|
+
const { page, limit } = parsePagination(c.req.query());
|
|
13
|
+
const result = await kernel.services.customers.list(actor);
|
|
14
|
+
if (!result.ok)
|
|
15
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
16
|
+
const all = result.value;
|
|
17
|
+
const total = all.length;
|
|
18
|
+
const start = (page - 1) * limit;
|
|
19
|
+
const paged = all.slice(start, start + limit);
|
|
20
|
+
return c.json({
|
|
21
|
+
data: paged,
|
|
22
|
+
meta: {
|
|
23
|
+
pagination: { page, limit, total, totalPages: Math.ceil(total / limit) },
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
// @ts-expect-error -- openapi handler union return type
|
|
28
|
+
router.openapi(getCustomerRoute, async (c) => {
|
|
29
|
+
const { id } = c.req.valid("param");
|
|
30
|
+
const actor = c.get("actor");
|
|
31
|
+
const result = await kernel.services.customers.getById(id, actor);
|
|
32
|
+
if (!result.ok)
|
|
33
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
34
|
+
return c.json({ data: result.value });
|
|
35
|
+
});
|
|
36
|
+
// PATCH requires customers:update (checked in handler since middleware can't distinguish methods)
|
|
37
|
+
// @ts-expect-error -- openapi handler union return type
|
|
38
|
+
router.openapi(updateCustomerRoute, async (c) => {
|
|
39
|
+
const { id } = c.req.valid("param");
|
|
40
|
+
const body = c.req.valid("json");
|
|
41
|
+
const actor = c.get("actor");
|
|
42
|
+
// Strip undefined values — exactOptionalPropertyTypes requires omission, not undefined
|
|
43
|
+
const updates = {};
|
|
44
|
+
for (const [k, v] of Object.entries(body)) {
|
|
45
|
+
if (v !== undefined)
|
|
46
|
+
updates[k] = v;
|
|
47
|
+
}
|
|
48
|
+
const result = await kernel.services.customers.update(id, updates, actor);
|
|
49
|
+
if (!result.ok)
|
|
50
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
51
|
+
return c.json({ data: result.value });
|
|
52
|
+
});
|
|
53
|
+
// @ts-expect-error -- openapi handler union return type
|
|
54
|
+
router.openapi(getCustomerOrdersRoute, async (c) => {
|
|
55
|
+
const { id } = c.req.valid("param");
|
|
56
|
+
const actor = c.get("actor");
|
|
57
|
+
const { page, limit } = parsePagination(c.req.query());
|
|
58
|
+
const status = c.req.query("status") || undefined;
|
|
59
|
+
const result = await kernel.services.orders.listByCustomer(id, { page, limit, ...(status ? { status } : {}) }, actor);
|
|
60
|
+
if (!result.ok)
|
|
61
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
62
|
+
return c.json({ data: result.value.items, meta: { pagination: result.value.pagination } });
|
|
63
|
+
});
|
|
64
|
+
// @ts-expect-error -- openapi handler union return type
|
|
65
|
+
router.openapi(getCustomerAddressesRoute, async (c) => {
|
|
66
|
+
const { id } = c.req.valid("param");
|
|
67
|
+
const actor = c.get("actor");
|
|
68
|
+
// Get customer first, then use their userId for address lookup
|
|
69
|
+
const customerResult = await kernel.services.customers.getById(id, actor);
|
|
70
|
+
if (!customerResult.ok)
|
|
71
|
+
return c.json(mapErrorToResponse(customerResult.error), mapErrorToStatus(customerResult.error));
|
|
72
|
+
const addressResult = await kernel.services.customers.getAddresses(customerResult.value.userId, actor);
|
|
73
|
+
if (!addressResult.ok)
|
|
74
|
+
return c.json(mapErrorToResponse(addressResult.error), mapErrorToStatus(addressResult.error));
|
|
75
|
+
return c.json({ data: addressResult.value });
|
|
76
|
+
});
|
|
77
|
+
return router;
|
|
78
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
+
import type { AppEnv } from "../utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Register URL rewrite aliases for entity types that define `alias` in config.
|
|
6
|
+
*
|
|
7
|
+
* E.g., `entities.product.alias = "products"` rewrites:
|
|
8
|
+
* /api/products → /api/catalog/entities?type=product
|
|
9
|
+
* /api/products/:id → /api/catalog/entities/:id
|
|
10
|
+
* /api/products/:id/... → /api/catalog/entities/:id/...
|
|
11
|
+
*
|
|
12
|
+
* This is a thin rewrite layer — no handler duplication. The original
|
|
13
|
+
* catalog routes handle all logic, validation, and OpenAPI schema.
|
|
14
|
+
*
|
|
15
|
+
* The `type` filter is injected automatically on list requests.
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerEntityAliases(router: OpenAPIHono<AppEnv>, kernel: Kernel): void;
|
|
18
|
+
//# sourceMappingURL=entity-aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-aliases.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/entity-aliases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAC3B,MAAM,EAAE,MAAM,GACb,IAAI,CA4BN"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register URL rewrite aliases for entity types that define `alias` in config.
|
|
3
|
+
*
|
|
4
|
+
* E.g., `entities.product.alias = "products"` rewrites:
|
|
5
|
+
* /api/products → /api/catalog/entities?type=product
|
|
6
|
+
* /api/products/:id → /api/catalog/entities/:id
|
|
7
|
+
* /api/products/:id/... → /api/catalog/entities/:id/...
|
|
8
|
+
*
|
|
9
|
+
* This is a thin rewrite layer — no handler duplication. The original
|
|
10
|
+
* catalog routes handle all logic, validation, and OpenAPI schema.
|
|
11
|
+
*
|
|
12
|
+
* The `type` filter is injected automatically on list requests.
|
|
13
|
+
*/
|
|
14
|
+
export function registerEntityAliases(router, kernel) {
|
|
15
|
+
const entities = kernel.config.entities ?? {};
|
|
16
|
+
for (const [entityType, entityConfig] of Object.entries(entities)) {
|
|
17
|
+
if (!entityConfig.alias)
|
|
18
|
+
continue;
|
|
19
|
+
const alias = entityConfig.alias;
|
|
20
|
+
// /api/{alias} → /api/catalog/entities?type={entityType}
|
|
21
|
+
router.all(`/${alias}`, (c) => {
|
|
22
|
+
const url = new URL(c.req.url);
|
|
23
|
+
url.pathname = "/api/catalog/entities";
|
|
24
|
+
// Inject type filter for list requests
|
|
25
|
+
if (c.req.method === "GET") {
|
|
26
|
+
url.searchParams.set("type", entityType);
|
|
27
|
+
}
|
|
28
|
+
const newReq = new Request(url.toString(), c.req.raw);
|
|
29
|
+
return router.fetch(newReq);
|
|
30
|
+
});
|
|
31
|
+
// /api/{alias}/:rest → /api/catalog/entities/:rest
|
|
32
|
+
router.all(`/${alias}/*`, (c) => {
|
|
33
|
+
const url = new URL(c.req.url);
|
|
34
|
+
url.pathname = url.pathname.replace(`/api/${alias}`, "/api/catalog/entities");
|
|
35
|
+
const newReq = new Request(url.toString(), c.req.raw);
|
|
36
|
+
return router.fetch(newReq);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
+
import { type AppEnv } from "../utils.js";
|
|
4
|
+
export declare function inventoryRoutes(kernel: Kernel): OpenAPIHono<AppEnv, {}, "/">;
|
|
5
|
+
//# sourceMappingURL=inventory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/inventory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAUzD,OAAO,EAAE,KAAK,MAAM,EAAqD,MAAM,aAAa,CAAC;AAE7F,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,gCA4E7C"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { inventoryAdjustRoute, inventoryReserveRoute, inventoryReleaseRoute, createWarehouseRoute, inventoryCheckRoute, listWarehousesRoute, listInventoryLevelsRoute, } from "../schemas/inventory.js";
|
|
3
|
+
import { mapErrorToResponse, mapErrorToStatus, requirePerm } from "../utils.js";
|
|
4
|
+
export function inventoryRoutes(kernel) {
|
|
5
|
+
const router = new OpenAPIHono();
|
|
6
|
+
// Inventory levels listing requires inventory:read
|
|
7
|
+
router.use("/levels", requirePerm("inventory:read"));
|
|
8
|
+
// @ts-expect-error -- openapi handler union return type
|
|
9
|
+
router.openapi(listInventoryLevelsRoute, async (c) => {
|
|
10
|
+
const actor = c.get("actor");
|
|
11
|
+
const warehouseId = c.req.query("warehouseId");
|
|
12
|
+
const entityId = c.req.query("entityId");
|
|
13
|
+
const result = await kernel.services.inventory.listLevels({
|
|
14
|
+
...(warehouseId ? { warehouseId } : {}),
|
|
15
|
+
...(entityId ? { entityId } : {}),
|
|
16
|
+
}, actor);
|
|
17
|
+
if (!result.ok)
|
|
18
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
19
|
+
return c.json({ data: result.value });
|
|
20
|
+
});
|
|
21
|
+
// @ts-expect-error -- openapi handler union return type
|
|
22
|
+
router.openapi(inventoryCheckRoute, async (c) => {
|
|
23
|
+
const entityIds = (c.req.query("entityIds") ?? "")
|
|
24
|
+
.split(",")
|
|
25
|
+
.map((item) => item.trim())
|
|
26
|
+
.filter(Boolean);
|
|
27
|
+
const result = await kernel.services.inventory.checkMultiple(entityIds);
|
|
28
|
+
if (!result.ok)
|
|
29
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
30
|
+
return c.json({ data: result.value });
|
|
31
|
+
});
|
|
32
|
+
// @ts-expect-error -- openapi handler union return type
|
|
33
|
+
router.openapi(inventoryAdjustRoute, async (c) => {
|
|
34
|
+
const body = c.req.valid("json");
|
|
35
|
+
const result = await kernel.services.inventory.adjust(body, c.get("actor"));
|
|
36
|
+
if (!result.ok)
|
|
37
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
38
|
+
return c.json({ data: result.value });
|
|
39
|
+
});
|
|
40
|
+
// @ts-expect-error -- openapi handler union return type
|
|
41
|
+
router.openapi(inventoryReserveRoute, async (c) => {
|
|
42
|
+
const body = c.req.valid("json");
|
|
43
|
+
const result = await kernel.services.inventory.reserve(body, c.get("actor"));
|
|
44
|
+
if (!result.ok)
|
|
45
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
46
|
+
return c.json({ data: { reserved: true } });
|
|
47
|
+
});
|
|
48
|
+
// @ts-expect-error -- openapi handler union return type
|
|
49
|
+
router.openapi(inventoryReleaseRoute, async (c) => {
|
|
50
|
+
const body = c.req.valid("json");
|
|
51
|
+
const result = await kernel.services.inventory.release(body, c.get("actor"));
|
|
52
|
+
if (!result.ok)
|
|
53
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
54
|
+
return c.json({ data: { released: true } });
|
|
55
|
+
});
|
|
56
|
+
// @ts-expect-error -- openapi handler union return type
|
|
57
|
+
router.openapi(createWarehouseRoute, async (c) => {
|
|
58
|
+
const body = c.req.valid("json");
|
|
59
|
+
const actor = c.get("actor");
|
|
60
|
+
const result = await kernel.services.inventory.createWarehouse(body, actor);
|
|
61
|
+
if (!result.ok)
|
|
62
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
63
|
+
return c.json({ data: result.value }, 201);
|
|
64
|
+
});
|
|
65
|
+
// @ts-expect-error -- openapi handler union return type
|
|
66
|
+
router.openapi(listWarehousesRoute, async (c) => {
|
|
67
|
+
const actor = c.get("actor");
|
|
68
|
+
const result = await kernel.services.inventory.listWarehouses(actor);
|
|
69
|
+
if (!result.ok)
|
|
70
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
71
|
+
return c.json({ data: result.value });
|
|
72
|
+
});
|
|
73
|
+
return router;
|
|
74
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
+
import { type AppEnv } from "../utils.js";
|
|
4
|
+
export declare function mediaRoutes(kernel: Kernel): OpenAPIHono<AppEnv, {}, "/">;
|
|
5
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGzD,OAAO,EAAE,KAAK,MAAM,EAAqD,MAAM,aAAa,CAAC;AAE7F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,gCA+EzC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { attachMediaRoute, getMediaRoute, deleteMediaRoute } from "../schemas/media.js";
|
|
3
|
+
import { mapErrorToResponse, mapErrorToStatus, requirePerm } from "../utils.js";
|
|
4
|
+
export function mediaRoutes(kernel) {
|
|
5
|
+
const router = new OpenAPIHono();
|
|
6
|
+
// Upload requires authentication + media:write permission
|
|
7
|
+
router.use("/upload", requirePerm("media:write"));
|
|
8
|
+
router.post("/upload", async (c) => {
|
|
9
|
+
const body = await c.req.parseBody();
|
|
10
|
+
const file = body.file;
|
|
11
|
+
if (!file) {
|
|
12
|
+
return c.json({ error: { code: "VALIDATION_FAILED", message: "file is required" } }, 422);
|
|
13
|
+
}
|
|
14
|
+
const buffer = await file.arrayBuffer();
|
|
15
|
+
const actor = c.get("actor");
|
|
16
|
+
const result = await kernel.services.media.upload({
|
|
17
|
+
filename: file.name,
|
|
18
|
+
contentType: file.type,
|
|
19
|
+
data: buffer,
|
|
20
|
+
alt: String(body.alt ?? ""),
|
|
21
|
+
}, actor);
|
|
22
|
+
if (!result.ok) {
|
|
23
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
24
|
+
}
|
|
25
|
+
return c.json({ data: result.value }, 201);
|
|
26
|
+
});
|
|
27
|
+
router.openapi(getMediaRoute, async (c) => {
|
|
28
|
+
const signed = c.req.query("signed") === "true";
|
|
29
|
+
// Signed URLs require authentication
|
|
30
|
+
if (signed && !c.get("actor")) {
|
|
31
|
+
return c.json({ error: { code: "UNAUTHORIZED", message: "Authentication required for signed URLs." } }, 401);
|
|
32
|
+
}
|
|
33
|
+
const result = signed
|
|
34
|
+
? await kernel.services.media.getSignedUrl(c.req.param("id"))
|
|
35
|
+
: await kernel.services.media.getUrl(c.req.param("id"));
|
|
36
|
+
if (!result.ok) {
|
|
37
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
38
|
+
}
|
|
39
|
+
return c.redirect(result.value, 302);
|
|
40
|
+
});
|
|
41
|
+
// @ts-expect-error -- openapi handler union return type
|
|
42
|
+
router.openapi(deleteMediaRoute, async (c) => {
|
|
43
|
+
const actor = c.get("actor");
|
|
44
|
+
if (!actor || (!actor.permissions.includes("media:write") && !actor.permissions.includes("*:*"))) {
|
|
45
|
+
return c.json({ error: { code: "FORBIDDEN", message: "media:write permission required." } }, 403);
|
|
46
|
+
}
|
|
47
|
+
const result = await kernel.services.media.delete(c.req.param("id"));
|
|
48
|
+
if (!result.ok) {
|
|
49
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
50
|
+
}
|
|
51
|
+
return c.json({ data: { deleted: true } });
|
|
52
|
+
});
|
|
53
|
+
// Attach requires media:write
|
|
54
|
+
router.use("/attach", requirePerm("media:write"));
|
|
55
|
+
// @ts-expect-error -- openapi handler union return type
|
|
56
|
+
router.openapi(attachMediaRoute, async (c) => {
|
|
57
|
+
const body = c.req.valid("json");
|
|
58
|
+
const result = await kernel.services.media.attachToEntity(body);
|
|
59
|
+
if (!result.ok) {
|
|
60
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
61
|
+
}
|
|
62
|
+
return c.json({ data: { attached: true } }, 201);
|
|
63
|
+
});
|
|
64
|
+
return router;
|
|
65
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
+
import { type AppEnv } from "../utils.js";
|
|
4
|
+
export declare function orderRoutes(kernel: Kernel): OpenAPIHono<AppEnv, {}, "/">;
|
|
5
|
+
//# sourceMappingURL=orders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/orders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,EAAE,KAAK,MAAM,EAAiE,MAAM,aAAa,CAAC;AAEzG,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,gCAwEzC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { changeOrderStatusRoute, listOrdersRoute, getOrderRoute, getOrderFulfillmentsRoute } from "../schemas/orders.js";
|
|
3
|
+
import { isUUID, mapErrorToResponse, mapErrorToStatus, parsePagination } from "../utils.js";
|
|
4
|
+
export function orderRoutes(kernel) {
|
|
5
|
+
const router = new OpenAPIHono();
|
|
6
|
+
// @ts-expect-error -- openapi handler union return type
|
|
7
|
+
router.openapi(listOrdersRoute, async (c) => {
|
|
8
|
+
const pagination = parsePagination(c.req.query());
|
|
9
|
+
const status = c.req.query("status");
|
|
10
|
+
const result = await kernel.services.orders.list({
|
|
11
|
+
page: pagination.page,
|
|
12
|
+
limit: pagination.limit,
|
|
13
|
+
...(status !== undefined ? { status } : {}),
|
|
14
|
+
}, c.get("actor"));
|
|
15
|
+
if (!result.ok)
|
|
16
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
17
|
+
return c.json({
|
|
18
|
+
data: result.value.items,
|
|
19
|
+
meta: {
|
|
20
|
+
pagination: result.value.pagination,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
// @ts-expect-error -- openapi handler union return type
|
|
25
|
+
router.openapi(getOrderRoute, async (c) => {
|
|
26
|
+
const idOrNumber = c.req.param("idOrNumber");
|
|
27
|
+
const result = isUUID(idOrNumber)
|
|
28
|
+
? await kernel.services.orders.getById(idOrNumber, c.get("actor"))
|
|
29
|
+
: await kernel.services.orders.getByNumber(idOrNumber, c.get("actor"));
|
|
30
|
+
if (!result.ok)
|
|
31
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
32
|
+
return c.json({ data: result.value });
|
|
33
|
+
});
|
|
34
|
+
// @ts-expect-error -- openapi() enforces strict response typing but our handler
|
|
35
|
+
// returns union responses (200 | 400 | 404). The route definition documents the
|
|
36
|
+
// contract; the handler returns dynamic status.
|
|
37
|
+
router.openapi(changeOrderStatusRoute, async (c) => {
|
|
38
|
+
const body = c.req.valid("json");
|
|
39
|
+
const result = await kernel.services.orders.changeStatus({
|
|
40
|
+
orderId: c.req.param("id"),
|
|
41
|
+
newStatus: body.status,
|
|
42
|
+
...(body.reason !== undefined ? { reason: body.reason } : {}),
|
|
43
|
+
}, c.get("actor"));
|
|
44
|
+
if (!result.ok)
|
|
45
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
46
|
+
return c.json({ data: result.value });
|
|
47
|
+
});
|
|
48
|
+
// @ts-expect-error -- openapi handler union return type
|
|
49
|
+
router.openapi(getOrderFulfillmentsRoute, async (c) => {
|
|
50
|
+
const orderId = c.req.param("id");
|
|
51
|
+
const actor = c.get("actor");
|
|
52
|
+
// Verify the order exists and the actor has access before returning fulfillments
|
|
53
|
+
const orderResult = isUUID(orderId)
|
|
54
|
+
? await kernel.services.orders.getById(orderId, actor)
|
|
55
|
+
: await kernel.services.orders.getByNumber(orderId, actor);
|
|
56
|
+
if (!orderResult.ok)
|
|
57
|
+
return c.json(mapErrorToResponse(orderResult.error), mapErrorToStatus(orderResult.error));
|
|
58
|
+
const result = await kernel.services.fulfillment.getByOrderId(orderResult.value.id);
|
|
59
|
+
if (!result.ok)
|
|
60
|
+
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
61
|
+
return c.json({ data: result.value });
|
|
62
|
+
});
|
|
63
|
+
return router;
|
|
64
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import type { Kernel } from "../../../runtime/kernel.js";
|
|
3
|
+
import { type AppEnv } from "../utils.js";
|
|
4
|
+
export declare function paymentRoutes(kernel: Kernel): OpenAPIHono<AppEnv, {}, "/">;
|
|
5
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/rest/routes/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,EAAwC,MAAM,aAAa,CAAC;AAKhF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,gCAmD3C"}
|