@unifiedcommerce/core 0.4.2 → 0.4.4
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/interfaces/rest/index.d.ts.map +1 -1
- package/dist/interfaces/rest/index.js +4 -17
- package/dist/runtime/server.d.ts.map +1 -1
- package/dist/runtime/server.js +33 -0
- package/package.json +1 -1
- package/src/interfaces/rest/index.ts +4 -18
- package/src/runtime/server.ts +33 -0
- package/dist/adapters/console-email.d.ts +0 -23
- package/dist/adapters/console-email.d.ts.map +0 -1
- package/dist/adapters/console-email.js +0 -38
- package/dist/auth/access.d.ts +0 -101
- package/dist/auth/access.d.ts.map +0 -1
- package/dist/auth/access.js +0 -128
- package/dist/auth/auth-schema.d.ts +0 -1475
- package/dist/auth/auth-schema.d.ts.map +0 -1
- package/dist/auth/auth-schema.js +0 -124
- package/dist/auth/middleware.d.ts +0 -5
- package/dist/auth/middleware.d.ts.map +0 -1
- package/dist/auth/middleware.js +0 -141
- package/dist/auth/org.d.ts +0 -22
- package/dist/auth/org.d.ts.map +0 -1
- package/dist/auth/org.js +0 -36
- package/dist/auth/permissions.d.ts +0 -4
- package/dist/auth/permissions.d.ts.map +0 -1
- package/dist/auth/permissions.js +0 -24
- package/dist/auth/setup.d.ts +0 -29
- package/dist/auth/setup.d.ts.map +0 -1
- package/dist/auth/setup.js +0 -117
- package/dist/auth/system-actor.d.ts +0 -7
- package/dist/auth/system-actor.d.ts.map +0 -1
- package/dist/auth/system-actor.js +0 -17
- package/dist/auth/types.d.ts +0 -11
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -1
- package/dist/config/defaults.d.ts +0 -3
- package/dist/config/defaults.d.ts.map +0 -1
- package/dist/config/defaults.js +0 -80
- package/dist/config/define-config.d.ts +0 -9
- package/dist/config/define-config.d.ts.map +0 -1
- package/dist/config/define-config.js +0 -44
- package/dist/config/types.d.ts +0 -327
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -1
- package/dist/generated/plugin-manifest.d.ts +0 -48
- package/dist/generated/plugin-manifest.d.ts.map +0 -1
- package/dist/generated/plugin-manifest.js +0 -20
- package/dist/hooks/checkout-completion.d.ts +0 -58
- package/dist/hooks/checkout-completion.d.ts.map +0 -1
- package/dist/hooks/checkout-completion.js +0 -137
- package/dist/hooks/checkout.d.ts +0 -99
- package/dist/hooks/checkout.d.ts.map +0 -1
- package/dist/hooks/checkout.js +0 -317
- package/dist/hooks/order-emails.d.ts +0 -16
- package/dist/hooks/order-emails.d.ts.map +0 -1
- package/dist/hooks/order-emails.js +0 -44
- package/dist/index.d.ts +0 -77
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -45
- package/dist/interfaces/mcp/agent-prompt.d.ts +0 -16
- package/dist/interfaces/mcp/agent-prompt.d.ts.map +0 -1
- package/dist/interfaces/mcp/agent-prompt.js +0 -172
- package/dist/interfaces/mcp/context-enrichment.d.ts +0 -39
- package/dist/interfaces/mcp/context-enrichment.d.ts.map +0 -1
- package/dist/interfaces/mcp/context-enrichment.js +0 -119
- package/dist/interfaces/mcp/server.d.ts +0 -5
- package/dist/interfaces/mcp/server.d.ts.map +0 -1
- package/dist/interfaces/mcp/server.js +0 -30
- package/dist/interfaces/mcp/tool-builder.d.ts +0 -120
- package/dist/interfaces/mcp/tool-builder.d.ts.map +0 -1
- package/dist/interfaces/mcp/tool-builder.js +0 -224
- package/dist/interfaces/mcp/tools/analytics.d.ts +0 -42
- package/dist/interfaces/mcp/tools/analytics.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/analytics.js +0 -70
- package/dist/interfaces/mcp/tools/cart.d.ts +0 -14
- package/dist/interfaces/mcp/tools/cart.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/cart.js +0 -47
- package/dist/interfaces/mcp/tools/catalog.d.ts +0 -53
- package/dist/interfaces/mcp/tools/catalog.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/catalog.js +0 -284
- package/dist/interfaces/mcp/tools/index.d.ts +0 -3
- package/dist/interfaces/mcp/tools/index.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/index.js +0 -20
- package/dist/interfaces/mcp/tools/inventory.d.ts +0 -27
- package/dist/interfaces/mcp/tools/inventory.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/inventory.js +0 -143
- package/dist/interfaces/mcp/tools/orders.d.ts +0 -18
- package/dist/interfaces/mcp/tools/orders.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/orders.js +0 -82
- package/dist/interfaces/mcp/tools/pricing.d.ts +0 -29
- package/dist/interfaces/mcp/tools/pricing.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/pricing.js +0 -90
- package/dist/interfaces/mcp/tools/promotions.d.ts +0 -44
- package/dist/interfaces/mcp/tools/promotions.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/promotions.js +0 -109
- package/dist/interfaces/mcp/tools/registry.d.ts +0 -32
- package/dist/interfaces/mcp/tools/registry.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/registry.js +0 -55
- package/dist/interfaces/mcp/tools/search.d.ts +0 -14
- package/dist/interfaces/mcp/tools/search.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/search.js +0 -39
- package/dist/interfaces/mcp/tools/webhooks.d.ts +0 -15
- package/dist/interfaces/mcp/tools/webhooks.d.ts.map +0 -1
- package/dist/interfaces/mcp/tools/webhooks.js +0 -48
- package/dist/interfaces/mcp/transport.d.ts +0 -20
- package/dist/interfaces/mcp/transport.d.ts.map +0 -1
- package/dist/interfaces/mcp/transport.js +0 -99
- package/dist/interfaces/rest/customer-portal.d.ts +0 -5
- package/dist/interfaces/rest/customer-portal.d.ts.map +0 -1
- package/dist/interfaces/rest/customer-portal.js +0 -206
- package/dist/interfaces/rest/router.d.ts +0 -164
- package/dist/interfaces/rest/router.d.ts.map +0 -1
- package/dist/interfaces/rest/router.js +0 -259
- package/dist/interfaces/rest/routes/admin-jobs.d.ts +0 -5
- package/dist/interfaces/rest/routes/admin-jobs.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/admin-jobs.js +0 -48
- package/dist/interfaces/rest/routes/audit.d.ts +0 -5
- package/dist/interfaces/rest/routes/audit.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/audit.js +0 -43
- package/dist/interfaces/rest/routes/carts.d.ts +0 -5
- package/dist/interfaces/rest/routes/carts.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/carts.js +0 -55
- package/dist/interfaces/rest/routes/catalog.d.ts +0 -5
- package/dist/interfaces/rest/routes/catalog.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/catalog.js +0 -256
- package/dist/interfaces/rest/routes/checkout.d.ts +0 -5
- package/dist/interfaces/rest/routes/checkout.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/checkout.js +0 -216
- package/dist/interfaces/rest/routes/customers.d.ts +0 -5
- package/dist/interfaces/rest/routes/customers.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/customers.js +0 -74
- package/dist/interfaces/rest/routes/entity-aliases.d.ts +0 -18
- package/dist/interfaces/rest/routes/entity-aliases.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/entity-aliases.js +0 -39
- package/dist/interfaces/rest/routes/inventory.d.ts +0 -5
- package/dist/interfaces/rest/routes/inventory.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/inventory.js +0 -72
- package/dist/interfaces/rest/routes/media.d.ts +0 -5
- package/dist/interfaces/rest/routes/media.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/media.js +0 -65
- package/dist/interfaces/rest/routes/orders.d.ts +0 -5
- package/dist/interfaces/rest/routes/orders.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/orders.js +0 -64
- package/dist/interfaces/rest/routes/payments.d.ts +0 -5
- package/dist/interfaces/rest/routes/payments.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/payments.js +0 -45
- package/dist/interfaces/rest/routes/pricing.d.ts +0 -5
- package/dist/interfaces/rest/routes/pricing.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/pricing.js +0 -48
- package/dist/interfaces/rest/routes/promotions.d.ts +0 -5
- package/dist/interfaces/rest/routes/promotions.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/promotions.js +0 -76
- package/dist/interfaces/rest/routes/search.d.ts +0 -5
- package/dist/interfaces/rest/routes/search.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/search.js +0 -60
- package/dist/interfaces/rest/routes/webhooks.d.ts +0 -5
- package/dist/interfaces/rest/routes/webhooks.d.ts.map +0 -1
- package/dist/interfaces/rest/routes/webhooks.js +0 -39
- package/dist/interfaces/rest/schemas/admin-jobs.d.ts +0 -327
- package/dist/interfaces/rest/schemas/admin-jobs.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/admin-jobs.js +0 -37
- package/dist/interfaces/rest/schemas/audit.d.ts +0 -59
- package/dist/interfaces/rest/schemas/audit.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/audit.js +0 -43
- package/dist/interfaces/rest/schemas/carts.d.ts +0 -1456
- package/dist/interfaces/rest/schemas/carts.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/carts.js +0 -109
- package/dist/interfaces/rest/schemas/catalog.d.ts +0 -5452
- package/dist/interfaces/rest/schemas/catalog.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/catalog.js +0 -397
- package/dist/interfaces/rest/schemas/checkout.d.ts +0 -160
- package/dist/interfaces/rest/schemas/checkout.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/checkout.js +0 -60
- package/dist/interfaces/rest/schemas/customer-portal.d.ts +0 -2203
- package/dist/interfaces/rest/schemas/customer-portal.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/customer-portal.js +0 -177
- package/dist/interfaces/rest/schemas/customers.d.ts +0 -422
- package/dist/interfaces/rest/schemas/customers.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/customers.js +0 -150
- package/dist/interfaces/rest/schemas/inventory.d.ts +0 -561
- package/dist/interfaces/rest/schemas/inventory.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/inventory.js +0 -148
- package/dist/interfaces/rest/schemas/media.d.ts +0 -303
- package/dist/interfaces/rest/schemas/media.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/media.js +0 -69
- package/dist/interfaces/rest/schemas/orders.d.ts +0 -1792
- package/dist/interfaces/rest/schemas/orders.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/orders.js +0 -93
- package/dist/interfaces/rest/schemas/pricing.d.ts +0 -256
- package/dist/interfaces/rest/schemas/pricing.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/pricing.js +0 -72
- package/dist/interfaces/rest/schemas/promotions.d.ts +0 -363
- package/dist/interfaces/rest/schemas/promotions.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/promotions.js +0 -98
- package/dist/interfaces/rest/schemas/responses.d.ts +0 -4086
- package/dist/interfaces/rest/schemas/responses.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/responses.js +0 -74
- package/dist/interfaces/rest/schemas/search.d.ts +0 -247
- package/dist/interfaces/rest/schemas/search.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/search.js +0 -55
- package/dist/interfaces/rest/schemas/shared.d.ts +0 -95
- package/dist/interfaces/rest/schemas/shared.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/shared.js +0 -51
- package/dist/interfaces/rest/schemas/webhooks.d.ts +0 -221
- package/dist/interfaces/rest/schemas/webhooks.d.ts.map +0 -1
- package/dist/interfaces/rest/schemas/webhooks.js +0 -62
- package/dist/interfaces/rest/utils.d.ts +0 -45
- package/dist/interfaces/rest/utils.d.ts.map +0 -1
- package/dist/interfaces/rest/utils.js +0 -71
- package/dist/interfaces/rest/webhook-router.d.ts +0 -41
- package/dist/interfaces/rest/webhook-router.d.ts.map +0 -1
- package/dist/interfaces/rest/webhook-router.js +0 -36
- package/dist/kernel/compensation/executor.d.ts +0 -21
- package/dist/kernel/compensation/executor.d.ts.map +0 -1
- package/dist/kernel/compensation/executor.js +0 -36
- package/dist/kernel/compensation/types.d.ts +0 -25
- package/dist/kernel/compensation/types.d.ts.map +0 -1
- package/dist/kernel/compensation/types.js +0 -1
- package/dist/kernel/database/adapter.d.ts +0 -18
- package/dist/kernel/database/adapter.d.ts.map +0 -1
- package/dist/kernel/database/adapter.js +0 -3
- package/dist/kernel/database/drizzle-db.d.ts +0 -49
- package/dist/kernel/database/drizzle-db.d.ts.map +0 -1
- package/dist/kernel/database/drizzle-db.js +0 -20
- package/dist/kernel/database/migrate.d.ts +0 -38
- package/dist/kernel/database/migrate.d.ts.map +0 -1
- package/dist/kernel/database/migrate.js +0 -61
- package/dist/kernel/database/plugin-types.d.ts +0 -32
- package/dist/kernel/database/plugin-types.d.ts.map +0 -1
- package/dist/kernel/database/plugin-types.js +0 -10
- package/dist/kernel/database/schema.d.ts +0 -24
- package/dist/kernel/database/schema.d.ts.map +0 -1
- package/dist/kernel/database/schema.js +0 -36
- package/dist/kernel/database/scoped-db.d.ts +0 -20
- package/dist/kernel/database/scoped-db.d.ts.map +0 -1
- package/dist/kernel/database/scoped-db.js +0 -62
- package/dist/kernel/database/tx-context.d.ts +0 -15
- package/dist/kernel/database/tx-context.d.ts.map +0 -1
- package/dist/kernel/database/tx-context.js +0 -19
- package/dist/kernel/error-mapper.d.ts +0 -3
- package/dist/kernel/error-mapper.d.ts.map +0 -1
- package/dist/kernel/error-mapper.js +0 -12
- package/dist/kernel/errors.d.ts +0 -38
- package/dist/kernel/errors.d.ts.map +0 -1
- package/dist/kernel/errors.js +0 -69
- package/dist/kernel/factory/repository-factory.d.ts +0 -71
- package/dist/kernel/factory/repository-factory.d.ts.map +0 -1
- package/dist/kernel/factory/repository-factory.js +0 -138
- package/dist/kernel/hooks/create-context.d.ts +0 -25
- package/dist/kernel/hooks/create-context.d.ts.map +0 -1
- package/dist/kernel/hooks/create-context.js +0 -22
- package/dist/kernel/hooks/executor.d.ts +0 -12
- package/dist/kernel/hooks/executor.d.ts.map +0 -1
- package/dist/kernel/hooks/executor.js +0 -50
- package/dist/kernel/hooks/registry.d.ts +0 -28
- package/dist/kernel/hooks/registry.d.ts.map +0 -1
- package/dist/kernel/hooks/registry.js +0 -58
- package/dist/kernel/hooks/types.d.ts +0 -37
- package/dist/kernel/hooks/types.d.ts.map +0 -1
- package/dist/kernel/hooks/types.js +0 -1
- package/dist/kernel/http-error.d.ts +0 -30
- package/dist/kernel/http-error.d.ts.map +0 -1
- package/dist/kernel/http-error.js +0 -35
- package/dist/kernel/jobs/adapter.d.ts +0 -25
- package/dist/kernel/jobs/adapter.d.ts.map +0 -1
- package/dist/kernel/jobs/adapter.js +0 -9
- package/dist/kernel/jobs/drizzle-adapter.d.ts +0 -15
- package/dist/kernel/jobs/drizzle-adapter.d.ts.map +0 -1
- package/dist/kernel/jobs/drizzle-adapter.js +0 -42
- package/dist/kernel/jobs/runner.d.ts +0 -24
- package/dist/kernel/jobs/runner.d.ts.map +0 -1
- package/dist/kernel/jobs/runner.js +0 -114
- package/dist/kernel/jobs/schema.d.ts +0 -280
- package/dist/kernel/jobs/schema.d.ts.map +0 -1
- package/dist/kernel/jobs/schema.js +0 -37
- package/dist/kernel/jobs/types.d.ts +0 -30
- package/dist/kernel/jobs/types.d.ts.map +0 -1
- package/dist/kernel/jobs/types.js +0 -1
- package/dist/kernel/local-api.d.ts +0 -103
- package/dist/kernel/local-api.d.ts.map +0 -1
- package/dist/kernel/local-api.js +0 -89
- package/dist/kernel/plugin/manifest.d.ts +0 -90
- package/dist/kernel/plugin/manifest.d.ts.map +0 -1
- package/dist/kernel/plugin/manifest.js +0 -169
- package/dist/kernel/query/executor.d.ts +0 -21
- package/dist/kernel/query/executor.d.ts.map +0 -1
- package/dist/kernel/query/executor.js +0 -128
- package/dist/kernel/query/registry.d.ts +0 -33
- package/dist/kernel/query/registry.d.ts.map +0 -1
- package/dist/kernel/query/registry.js +0 -20
- package/dist/kernel/result.d.ts +0 -36
- package/dist/kernel/result.d.ts.map +0 -1
- package/dist/kernel/result.js +0 -16
- package/dist/kernel/schema/extra-columns.d.ts +0 -23
- package/dist/kernel/schema/extra-columns.d.ts.map +0 -1
- package/dist/kernel/schema/extra-columns.js +0 -10
- package/dist/kernel/service-registry.d.ts +0 -109
- package/dist/kernel/service-registry.d.ts.map +0 -1
- package/dist/kernel/service-registry.js +0 -26
- package/dist/kernel/service-timing.d.ts +0 -25
- package/dist/kernel/service-timing.d.ts.map +0 -1
- package/dist/kernel/service-timing.js +0 -62
- package/dist/kernel/state-machine/machine.d.ts +0 -24
- package/dist/kernel/state-machine/machine.d.ts.map +0 -1
- package/dist/kernel/state-machine/machine.js +0 -70
- package/dist/modules/analytics/drizzle-adapter.d.ts +0 -13
- package/dist/modules/analytics/drizzle-adapter.d.ts.map +0 -1
- package/dist/modules/analytics/drizzle-adapter.js +0 -358
- package/dist/modules/analytics/hooks.d.ts +0 -13
- package/dist/modules/analytics/hooks.d.ts.map +0 -1
- package/dist/modules/analytics/hooks.js +0 -12
- package/dist/modules/analytics/models.d.ts +0 -14
- package/dist/modules/analytics/models.d.ts.map +0 -1
- package/dist/modules/analytics/models.js +0 -118
- package/dist/modules/analytics/repository/index.d.ts +0 -5
- package/dist/modules/analytics/repository/index.d.ts.map +0 -1
- package/dist/modules/analytics/repository/index.js +0 -1
- package/dist/modules/analytics/service.d.ts +0 -45
- package/dist/modules/analytics/service.d.ts.map +0 -1
- package/dist/modules/analytics/service.js +0 -196
- package/dist/modules/analytics/types.d.ts +0 -119
- package/dist/modules/analytics/types.d.ts.map +0 -1
- package/dist/modules/analytics/types.js +0 -25
- package/dist/modules/audit/hooks.d.ts +0 -7
- package/dist/modules/audit/hooks.d.ts.map +0 -1
- package/dist/modules/audit/hooks.js +0 -67
- package/dist/modules/audit/schema.d.ts +0 -178
- package/dist/modules/audit/schema.d.ts.map +0 -1
- package/dist/modules/audit/schema.js +0 -21
- package/dist/modules/audit/service.d.ts +0 -38
- package/dist/modules/audit/service.d.ts.map +0 -1
- package/dist/modules/audit/service.js +0 -109
- package/dist/modules/cart/access.d.ts +0 -11
- package/dist/modules/cart/access.d.ts.map +0 -1
- package/dist/modules/cart/access.js +0 -18
- package/dist/modules/cart/matcher.d.ts +0 -20
- package/dist/modules/cart/matcher.d.ts.map +0 -1
- package/dist/modules/cart/matcher.js +0 -2
- package/dist/modules/cart/repository/index.d.ts +0 -45
- package/dist/modules/cart/repository/index.d.ts.map +0 -1
- package/dist/modules/cart/repository/index.js +0 -158
- package/dist/modules/cart/schema.d.ts +0 -359
- package/dist/modules/cart/schema.d.ts.map +0 -1
- package/dist/modules/cart/schema.js +0 -40
- package/dist/modules/cart/schemas.d.ts +0 -29
- package/dist/modules/cart/schemas.d.ts.map +0 -1
- package/dist/modules/cart/schemas.js +0 -14
- package/dist/modules/cart/service.d.ts +0 -63
- package/dist/modules/cart/service.d.ts.map +0 -1
- package/dist/modules/cart/service.js +0 -339
- package/dist/modules/catalog/repository/index.d.ts +0 -106
- package/dist/modules/catalog/repository/index.d.ts.map +0 -1
- package/dist/modules/catalog/repository/index.js +0 -455
- package/dist/modules/catalog/schema.d.ts +0 -1193
- package/dist/modules/catalog/schema.d.ts.map +0 -1
- package/dist/modules/catalog/schema.js +0 -149
- package/dist/modules/catalog/schemas.d.ts +0 -81
- package/dist/modules/catalog/schemas.d.ts.map +0 -1
- package/dist/modules/catalog/schemas.js +0 -62
- package/dist/modules/catalog/service.d.ts +0 -160
- package/dist/modules/catalog/service.d.ts.map +0 -1
- package/dist/modules/catalog/service.js +0 -759
- package/dist/modules/customers/repository/index.d.ts +0 -47
- package/dist/modules/customers/repository/index.d.ts.map +0 -1
- package/dist/modules/customers/repository/index.js +0 -206
- package/dist/modules/customers/schema.d.ts +0 -560
- package/dist/modules/customers/schema.d.ts.map +0 -1
- package/dist/modules/customers/schema.js +0 -60
- package/dist/modules/customers/service.d.ts +0 -27
- package/dist/modules/customers/service.d.ts.map +0 -1
- package/dist/modules/customers/service.js +0 -106
- package/dist/modules/fulfillment/repository/index.d.ts +0 -63
- package/dist/modules/fulfillment/repository/index.d.ts.map +0 -1
- package/dist/modules/fulfillment/repository/index.js +0 -268
- package/dist/modules/fulfillment/schema.d.ts +0 -655
- package/dist/modules/fulfillment/schema.d.ts.map +0 -1
- package/dist/modules/fulfillment/schema.js +0 -83
- package/dist/modules/fulfillment/service.d.ts +0 -58
- package/dist/modules/fulfillment/service.d.ts.map +0 -1
- package/dist/modules/fulfillment/service.js +0 -338
- package/dist/modules/fulfillment/types.d.ts +0 -44
- package/dist/modules/fulfillment/types.d.ts.map +0 -1
- package/dist/modules/fulfillment/types.js +0 -1
- package/dist/modules/inventory/repository/index.d.ts +0 -81
- package/dist/modules/inventory/repository/index.d.ts.map +0 -1
- package/dist/modules/inventory/repository/index.js +0 -310
- package/dist/modules/inventory/schema.d.ts +0 -570
- package/dist/modules/inventory/schema.d.ts.map +0 -1
- package/dist/modules/inventory/schema.js +0 -69
- package/dist/modules/inventory/schemas.d.ts +0 -31
- package/dist/modules/inventory/schemas.d.ts.map +0 -1
- package/dist/modules/inventory/schemas.js +0 -28
- package/dist/modules/inventory/service.d.ts +0 -69
- package/dist/modules/inventory/service.d.ts.map +0 -1
- package/dist/modules/inventory/service.js +0 -283
- package/dist/modules/media/adapter.d.ts +0 -16
- package/dist/modules/media/adapter.d.ts.map +0 -1
- package/dist/modules/media/adapter.js +0 -1
- package/dist/modules/media/repository/index.d.ts +0 -35
- package/dist/modules/media/repository/index.d.ts.map +0 -1
- package/dist/modules/media/repository/index.js +0 -176
- package/dist/modules/media/schema.d.ts +0 -289
- package/dist/modules/media/schema.d.ts.map +0 -1
- package/dist/modules/media/schema.js +0 -35
- package/dist/modules/media/service.d.ts +0 -42
- package/dist/modules/media/service.d.ts.map +0 -1
- package/dist/modules/media/service.js +0 -89
- package/dist/modules/orders/repository/index.d.ts +0 -48
- package/dist/modules/orders/repository/index.d.ts.map +0 -1
- package/dist/modules/orders/repository/index.js +0 -199
- package/dist/modules/orders/schema.d.ts +0 -672
- package/dist/modules/orders/schema.d.ts.map +0 -1
- package/dist/modules/orders/schema.js +0 -63
- package/dist/modules/orders/service.d.ts +0 -85
- package/dist/modules/orders/service.d.ts.map +0 -1
- package/dist/modules/orders/service.js +0 -313
- package/dist/modules/orders/stale-order-cleanup.d.ts +0 -27
- package/dist/modules/orders/stale-order-cleanup.d.ts.map +0 -1
- package/dist/modules/orders/stale-order-cleanup.js +0 -55
- package/dist/modules/organization/service.d.ts +0 -53
- package/dist/modules/organization/service.d.ts.map +0 -1
- package/dist/modules/organization/service.js +0 -151
- package/dist/modules/payments/adapter.d.ts +0 -42
- package/dist/modules/payments/adapter.d.ts.map +0 -1
- package/dist/modules/payments/adapter.js +0 -1
- package/dist/modules/payments/repository/index.d.ts +0 -5
- package/dist/modules/payments/repository/index.d.ts.map +0 -1
- package/dist/modules/payments/repository/index.js +0 -1
- package/dist/modules/payments/service.d.ts +0 -23
- package/dist/modules/payments/service.d.ts.map +0 -1
- package/dist/modules/payments/service.js +0 -72
- package/dist/modules/pricing/repository/index.d.ts +0 -34
- package/dist/modules/pricing/repository/index.d.ts.map +0 -1
- package/dist/modules/pricing/repository/index.js +0 -176
- package/dist/modules/pricing/schema.d.ts +0 -565
- package/dist/modules/pricing/schema.d.ts.map +0 -1
- package/dist/modules/pricing/schema.js +0 -57
- package/dist/modules/pricing/schemas.d.ts +0 -37
- package/dist/modules/pricing/schemas.d.ts.map +0 -1
- package/dist/modules/pricing/schemas.js +0 -30
- package/dist/modules/pricing/service.d.ts +0 -62
- package/dist/modules/pricing/service.d.ts.map +0 -1
- package/dist/modules/pricing/service.js +0 -308
- package/dist/modules/promotions/repository/index.d.ts +0 -41
- package/dist/modules/promotions/repository/index.d.ts.map +0 -1
- package/dist/modules/promotions/repository/index.js +0 -204
- package/dist/modules/promotions/schema.d.ts +0 -427
- package/dist/modules/promotions/schema.d.ts.map +0 -1
- package/dist/modules/promotions/schema.js +0 -52
- package/dist/modules/promotions/schemas.d.ts +0 -33
- package/dist/modules/promotions/schemas.d.ts.map +0 -1
- package/dist/modules/promotions/schemas.js +0 -32
- package/dist/modules/promotions/service.d.ts +0 -80
- package/dist/modules/promotions/service.d.ts.map +0 -1
- package/dist/modules/promotions/service.js +0 -347
- package/dist/modules/search/adapter.d.ts +0 -51
- package/dist/modules/search/adapter.d.ts.map +0 -1
- package/dist/modules/search/adapter.js +0 -1
- package/dist/modules/search/hooks.d.ts +0 -8
- package/dist/modules/search/hooks.d.ts.map +0 -1
- package/dist/modules/search/hooks.js +0 -6
- package/dist/modules/search/repository/index.d.ts +0 -5
- package/dist/modules/search/repository/index.d.ts.map +0 -1
- package/dist/modules/search/repository/index.js +0 -1
- package/dist/modules/search/service.d.ts +0 -24
- package/dist/modules/search/service.d.ts.map +0 -1
- package/dist/modules/search/service.js +0 -217
- package/dist/modules/shipping/calculator.d.ts +0 -42
- package/dist/modules/shipping/calculator.d.ts.map +0 -1
- package/dist/modules/shipping/calculator.js +0 -91
- package/dist/modules/shipping/repository/index.d.ts +0 -5
- package/dist/modules/shipping/repository/index.d.ts.map +0 -1
- package/dist/modules/shipping/repository/index.js +0 -1
- package/dist/modules/shipping/service.d.ts +0 -28
- package/dist/modules/shipping/service.d.ts.map +0 -1
- package/dist/modules/shipping/service.js +0 -20
- package/dist/modules/tax/adapter.d.ts +0 -58
- package/dist/modules/tax/adapter.d.ts.map +0 -1
- package/dist/modules/tax/adapter.js +0 -1
- package/dist/modules/tax/repository/index.d.ts +0 -5
- package/dist/modules/tax/repository/index.d.ts.map +0 -1
- package/dist/modules/tax/repository/index.js +0 -1
- package/dist/modules/tax/service.d.ts +0 -19
- package/dist/modules/tax/service.d.ts.map +0 -1
- package/dist/modules/tax/service.js +0 -34
- package/dist/modules/webhooks/hook.d.ts +0 -13
- package/dist/modules/webhooks/hook.d.ts.map +0 -1
- package/dist/modules/webhooks/hook.js +0 -29
- package/dist/modules/webhooks/repository/index.d.ts +0 -40
- package/dist/modules/webhooks/repository/index.d.ts.map +0 -1
- package/dist/modules/webhooks/repository/index.js +0 -175
- package/dist/modules/webhooks/schema.d.ts +0 -404
- package/dist/modules/webhooks/schema.d.ts.map +0 -1
- package/dist/modules/webhooks/schema.js +0 -40
- package/dist/modules/webhooks/service.d.ts +0 -23
- package/dist/modules/webhooks/service.d.ts.map +0 -1
- package/dist/modules/webhooks/service.js +0 -92
- package/dist/modules/webhooks/signing.d.ts +0 -2
- package/dist/modules/webhooks/signing.d.ts.map +0 -1
- package/dist/modules/webhooks/signing.js +0 -5
- package/dist/modules/webhooks/ssrf-guard.d.ts +0 -19
- package/dist/modules/webhooks/ssrf-guard.d.ts.map +0 -1
- package/dist/modules/webhooks/ssrf-guard.js +0 -79
- package/dist/modules/webhooks/tasks.d.ts +0 -16
- package/dist/modules/webhooks/tasks.d.ts.map +0 -1
- package/dist/modules/webhooks/tasks.js +0 -35
- package/dist/modules/webhooks/worker.d.ts +0 -21
- package/dist/modules/webhooks/worker.d.ts.map +0 -1
- package/dist/modules/webhooks/worker.js +0 -113
- package/dist/runtime/commerce.d.ts +0 -110
- package/dist/runtime/commerce.d.ts.map +0 -1
- package/dist/runtime/commerce.js +0 -37
- package/dist/runtime/kernel.d.ts +0 -71
- package/dist/runtime/kernel.d.ts.map +0 -1
- package/dist/runtime/kernel.js +0 -306
- package/dist/runtime/logger.d.ts +0 -11
- package/dist/runtime/logger.d.ts.map +0 -1
- package/dist/runtime/logger.js +0 -32
- package/dist/runtime/shutdown.d.ts +0 -15
- package/dist/runtime/shutdown.d.ts.map +0 -1
- package/dist/runtime/shutdown.js +0 -34
- package/dist/test-utils/create-pglite-adapter.d.ts +0 -32
- package/dist/test-utils/create-pglite-adapter.d.ts.map +0 -1
- package/dist/test-utils/create-pglite-adapter.js +0 -107
- package/dist/test-utils/create-plugin-test-app.d.ts +0 -50
- package/dist/test-utils/create-plugin-test-app.d.ts.map +0 -1
- package/dist/test-utils/create-plugin-test-app.js +0 -74
- package/dist/test-utils/create-repository-test-harness.d.ts +0 -8
- package/dist/test-utils/create-repository-test-harness.d.ts.map +0 -1
- package/dist/test-utils/create-repository-test-harness.js +0 -7
- package/dist/test-utils/create-test-config.d.ts +0 -18
- package/dist/test-utils/create-test-config.d.ts.map +0 -1
- package/dist/test-utils/create-test-config.js +0 -172
- package/dist/test-utils/create-test-kernel.d.ts +0 -3
- package/dist/test-utils/create-test-kernel.d.ts.map +0 -1
- package/dist/test-utils/create-test-kernel.js +0 -5
- package/dist/test-utils/create-test-plugin-context.d.ts +0 -42
- package/dist/test-utils/create-test-plugin-context.d.ts.map +0 -1
- package/dist/test-utils/create-test-plugin-context.js +0 -46
- package/dist/test-utils/rest-api-test-utils.d.ts +0 -64
- package/dist/test-utils/rest-api-test-utils.d.ts.map +0 -1
- package/dist/test-utils/rest-api-test-utils.js +0 -207
- package/dist/test-utils/test-actors.d.ts +0 -15
- package/dist/test-utils/test-actors.d.ts.map +0 -1
- package/dist/test-utils/test-actors.js +0 -57
- package/dist/test-utils/typed-hooks.d.ts +0 -43
- package/dist/test-utils/typed-hooks.d.ts.map +0 -1
- package/dist/test-utils/typed-hooks.js +0 -35
- package/dist/testing.d.ts +0 -14
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -13
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/commerce-types.d.ts +0 -34
- package/dist/types/commerce-types.d.ts.map +0 -1
- package/dist/types/commerce-types.js +0 -1
- package/dist/utils/id.d.ts +0 -2
- package/dist/utils/id.d.ts.map +0 -1
- package/dist/utils/id.js +0 -3
- package/dist/utils/logger.d.ts +0 -3
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -16
- package/dist/utils/pagination.d.ts +0 -11
- package/dist/utils/pagination.d.ts.map +0 -1
- package/dist/utils/pagination.js +0 -15
|
@@ -1,216 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAyD,MAAM,aAAa,CAAC;AAEjG,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,gCAkF5C"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import { listCustomersRoute, getCustomerRoute, updateCustomerRoute, getCustomerOrdersRoute, getCustomerAddressesRoute, } from "../schemas/customers.js";
|
|
3
|
-
import { mapErrorToResponse, mapErrorToStatus, parsePagination } from "../utils.js";
|
|
4
|
-
export function customerRoutes(kernel) {
|
|
5
|
-
const router = new OpenAPIHono();
|
|
6
|
-
// @ts-expect-error -- openapi handler union return type
|
|
7
|
-
router.openapi(listCustomersRoute, async (c) => {
|
|
8
|
-
const actor = c.get("actor");
|
|
9
|
-
const { page, limit } = parsePagination(c.req.query());
|
|
10
|
-
const result = await kernel.services.customers.list(actor);
|
|
11
|
-
if (!result.ok)
|
|
12
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
13
|
-
const all = result.value;
|
|
14
|
-
const total = all.length;
|
|
15
|
-
const start = (page - 1) * limit;
|
|
16
|
-
const paged = all.slice(start, start + limit);
|
|
17
|
-
return c.json({
|
|
18
|
-
data: paged,
|
|
19
|
-
meta: {
|
|
20
|
-
pagination: { page, limit, total, totalPages: Math.ceil(total / limit) },
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
// @ts-expect-error -- openapi handler union return type
|
|
25
|
-
router.openapi(getCustomerRoute, async (c) => {
|
|
26
|
-
const { id } = c.req.valid("param");
|
|
27
|
-
const actor = c.get("actor");
|
|
28
|
-
const result = await kernel.services.customers.getById(id, actor);
|
|
29
|
-
if (!result.ok)
|
|
30
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
31
|
-
return c.json({ data: result.value });
|
|
32
|
-
});
|
|
33
|
-
// @ts-expect-error -- openapi handler union return type
|
|
34
|
-
router.openapi(updateCustomerRoute, async (c) => {
|
|
35
|
-
const { id } = c.req.valid("param");
|
|
36
|
-
const body = c.req.valid("json");
|
|
37
|
-
const actor = c.get("actor");
|
|
38
|
-
// Strip undefined values — exactOptionalPropertyTypes requires omission, not undefined
|
|
39
|
-
const updates = {};
|
|
40
|
-
for (const [k, v] of Object.entries(body)) {
|
|
41
|
-
if (v !== undefined)
|
|
42
|
-
updates[k] = v;
|
|
43
|
-
}
|
|
44
|
-
const result = await kernel.services.customers.update(id, updates, actor);
|
|
45
|
-
if (!result.ok)
|
|
46
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
47
|
-
return c.json({ data: result.value });
|
|
48
|
-
});
|
|
49
|
-
// @ts-expect-error -- openapi handler union return type
|
|
50
|
-
router.openapi(getCustomerOrdersRoute, async (c) => {
|
|
51
|
-
const { id } = c.req.valid("param");
|
|
52
|
-
const actor = c.get("actor");
|
|
53
|
-
const { page, limit } = parsePagination(c.req.query());
|
|
54
|
-
const status = c.req.query("status") || undefined;
|
|
55
|
-
const result = await kernel.services.orders.listByCustomer(id, { page, limit, ...(status ? { status } : {}) }, actor);
|
|
56
|
-
if (!result.ok)
|
|
57
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
58
|
-
return c.json({ data: result.value.items, meta: { pagination: result.value.pagination } });
|
|
59
|
-
});
|
|
60
|
-
// @ts-expect-error -- openapi handler union return type
|
|
61
|
-
router.openapi(getCustomerAddressesRoute, async (c) => {
|
|
62
|
-
const { id } = c.req.valid("param");
|
|
63
|
-
const actor = c.get("actor");
|
|
64
|
-
// Get customer first, then use their userId for address lookup
|
|
65
|
-
const customerResult = await kernel.services.customers.getById(id, actor);
|
|
66
|
-
if (!customerResult.ok)
|
|
67
|
-
return c.json(mapErrorToResponse(customerResult.error), mapErrorToStatus(customerResult.error));
|
|
68
|
-
const addressResult = await kernel.services.customers.getAddresses(customerResult.value.userId, actor);
|
|
69
|
-
if (!addressResult.ok)
|
|
70
|
-
return c.json(mapErrorToResponse(addressResult.error), mapErrorToStatus(addressResult.error));
|
|
71
|
-
return c.json({ data: addressResult.value });
|
|
72
|
-
});
|
|
73
|
-
return router;
|
|
74
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAwC,MAAM,aAAa,CAAC;AAEhF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,gCAyE7C"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import { inventoryAdjustRoute, inventoryReserveRoute, inventoryReleaseRoute, createWarehouseRoute, inventoryCheckRoute, listWarehousesRoute, listInventoryLevelsRoute, } from "../schemas/inventory.js";
|
|
3
|
-
import { mapErrorToResponse, mapErrorToStatus } from "../utils.js";
|
|
4
|
-
export function inventoryRoutes(kernel) {
|
|
5
|
-
const router = new OpenAPIHono();
|
|
6
|
-
// @ts-expect-error -- openapi handler union return type
|
|
7
|
-
router.openapi(listInventoryLevelsRoute, async (c) => {
|
|
8
|
-
const actor = c.get("actor");
|
|
9
|
-
const warehouseId = c.req.query("warehouseId");
|
|
10
|
-
const entityId = c.req.query("entityId");
|
|
11
|
-
const result = await kernel.services.inventory.listLevels({
|
|
12
|
-
...(warehouseId ? { warehouseId } : {}),
|
|
13
|
-
...(entityId ? { entityId } : {}),
|
|
14
|
-
}, actor);
|
|
15
|
-
if (!result.ok)
|
|
16
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
17
|
-
return c.json({ data: result.value });
|
|
18
|
-
});
|
|
19
|
-
// @ts-expect-error -- openapi handler union return type
|
|
20
|
-
router.openapi(inventoryCheckRoute, async (c) => {
|
|
21
|
-
const entityIds = (c.req.query("entityIds") ?? "")
|
|
22
|
-
.split(",")
|
|
23
|
-
.map((item) => item.trim())
|
|
24
|
-
.filter(Boolean);
|
|
25
|
-
const result = await kernel.services.inventory.checkMultiple(entityIds);
|
|
26
|
-
if (!result.ok)
|
|
27
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
28
|
-
return c.json({ data: result.value });
|
|
29
|
-
});
|
|
30
|
-
// @ts-expect-error -- openapi handler union return type
|
|
31
|
-
router.openapi(inventoryAdjustRoute, async (c) => {
|
|
32
|
-
const body = c.req.valid("json");
|
|
33
|
-
const result = await kernel.services.inventory.adjust(body, c.get("actor"));
|
|
34
|
-
if (!result.ok)
|
|
35
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
36
|
-
return c.json({ data: result.value });
|
|
37
|
-
});
|
|
38
|
-
// @ts-expect-error -- openapi handler union return type
|
|
39
|
-
router.openapi(inventoryReserveRoute, async (c) => {
|
|
40
|
-
const body = c.req.valid("json");
|
|
41
|
-
const result = await kernel.services.inventory.reserve(body, c.get("actor"));
|
|
42
|
-
if (!result.ok)
|
|
43
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
44
|
-
return c.json({ data: { reserved: true } });
|
|
45
|
-
});
|
|
46
|
-
// @ts-expect-error -- openapi handler union return type
|
|
47
|
-
router.openapi(inventoryReleaseRoute, async (c) => {
|
|
48
|
-
const body = c.req.valid("json");
|
|
49
|
-
const result = await kernel.services.inventory.release(body, c.get("actor"));
|
|
50
|
-
if (!result.ok)
|
|
51
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
52
|
-
return c.json({ data: { released: true } });
|
|
53
|
-
});
|
|
54
|
-
// @ts-expect-error -- openapi handler union return type
|
|
55
|
-
router.openapi(createWarehouseRoute, async (c) => {
|
|
56
|
-
const body = c.req.valid("json");
|
|
57
|
-
const actor = c.get("actor");
|
|
58
|
-
const result = await kernel.services.inventory.createWarehouse(body, actor);
|
|
59
|
-
if (!result.ok)
|
|
60
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
61
|
-
return c.json({ data: result.value }, 201);
|
|
62
|
-
});
|
|
63
|
-
// @ts-expect-error -- openapi handler union return type
|
|
64
|
-
router.openapi(listWarehousesRoute, async (c) => {
|
|
65
|
-
const actor = c.get("actor");
|
|
66
|
-
const result = await kernel.services.inventory.listWarehouses(actor);
|
|
67
|
-
if (!result.ok)
|
|
68
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
69
|
-
return c.json({ data: result.value });
|
|
70
|
-
});
|
|
71
|
-
return router;
|
|
72
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
-
import { mapErrorToResponse, mapErrorToStatus } from "../utils.js";
|
|
3
|
-
import { processedWebhookEvents } from "../../../modules/webhooks/schema.js";
|
|
4
|
-
export function paymentRoutes(kernel) {
|
|
5
|
-
const router = new OpenAPIHono();
|
|
6
|
-
router.post("/webhook", async (c) => {
|
|
7
|
-
const result = await kernel.services.payments.verifyWebhook(c.req.raw);
|
|
8
|
-
if (!result.ok) {
|
|
9
|
-
return c.json(mapErrorToResponse(result.error), mapErrorToStatus(result.error));
|
|
10
|
-
}
|
|
11
|
-
const event = result.value;
|
|
12
|
-
const db = kernel.database.db;
|
|
13
|
-
// Atomic idempotency: INSERT ... ON CONFLICT DO NOTHING ... RETURNING
|
|
14
|
-
// If the row already exists, RETURNING yields zero rows → duplicate.
|
|
15
|
-
// If the row is new, RETURNING yields one row → process the event.
|
|
16
|
-
// No TOCTOU race: the UNIQUE constraint on event_id is the single source of truth.
|
|
17
|
-
const [inserted] = await db
|
|
18
|
-
.insert(processedWebhookEvents)
|
|
19
|
-
.values({
|
|
20
|
-
eventId: event.id,
|
|
21
|
-
provider: "stripe",
|
|
22
|
-
eventType: event.type,
|
|
23
|
-
})
|
|
24
|
-
.onConflictDoNothing()
|
|
25
|
-
.returning({ id: processedWebhookEvents.id });
|
|
26
|
-
if (!inserted) {
|
|
27
|
-
// Row already existed — this is a duplicate delivery
|
|
28
|
-
return c.json({ data: { received: true, duplicate: true } });
|
|
29
|
-
}
|
|
30
|
-
// Process the event (first time only)
|
|
31
|
-
if (event.type === "payment_intent.succeeded") {
|
|
32
|
-
const data = event.data;
|
|
33
|
-
const metadata = data?.metadata;
|
|
34
|
-
if (typeof metadata?.orderId === "string") {
|
|
35
|
-
await kernel.services.orders.changeStatus({
|
|
36
|
-
orderId: metadata.orderId,
|
|
37
|
-
newStatus: "confirmed",
|
|
38
|
-
reason: "stripe_webhook_payment_intent_succeeded",
|
|
39
|
-
}, null);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return c.json({ data: { received: true } });
|
|
43
|
-
});
|
|
44
|
-
return router;
|
|
45
|
-
}
|