@unifiedcommerce/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +1383 -0
- package/dist/auth/auth-schema.d.ts.map +1 -0
- package/dist/auth/auth-schema.js +117 -0
- package/dist/auth/middleware.d.ts +5 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +91 -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/pos.d.ts +3 -0
- package/dist/auth/pos.d.ts.map +1 -0
- package/dist/auth/pos.js +62 -0
- package/dist/auth/setup.d.ts +31 -0
- package/dist/auth/setup.d.ts.map +1 -0
- package/dist/auth/setup.js +106 -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 +299 -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 +82 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13381 -0
- package/dist/index.js.map +156 -0
- package/dist/interfaces/graphql/index.d.ts +4 -0
- package/dist/interfaces/graphql/index.d.ts.map +1 -0
- package/dist/interfaces/graphql/index.js +415 -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 +7 -0
- package/dist/interfaces/mcp/server.d.ts.map +1 -0
- package/dist/interfaces/mcp/server.js +515 -0
- package/dist/interfaces/mcp/transport.d.ts +5 -0
- package/dist/interfaces/mcp/transport.d.ts.map +1 -0
- package/dist/interfaces/mcp/transport.js +52 -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/index.d.ts +5 -0
- package/dist/interfaces/rest/index.d.ts.map +1 -0
- package/dist/interfaces/rest/index.js +68 -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/inventory.d.ts +5 -0
- package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/inventory.js +59 -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 +75 -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 +1446 -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 +5416 -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 +2197 -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/inventory.d.ts +469 -0
- package/dist/interfaces/rest/schemas/inventory.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/inventory.js +128 -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 +1782 -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 +363 -0
- package/dist/interfaces/rest/schemas/promotions.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/promotions.js +98 -0
- package/dist/interfaces/rest/schemas/responses.d.ts +4062 -0
- package/dist/interfaces/rest/schemas/responses.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/responses.js +63 -0
- package/dist/interfaces/rest/schemas/search.d.ts +245 -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 +10 -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/in-memory-repository-factory.d.ts +20 -0
- package/dist/kernel/factory/in-memory-repository-factory.d.ts.map +1 -0
- package/dist/kernel/factory/in-memory-repository-factory.js +83 -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 +136 -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 +87 -0
- package/dist/kernel/plugin/capability-registry.d.ts +9 -0
- package/dist/kernel/plugin/capability-registry.d.ts.map +1 -0
- package/dist/kernel/plugin/capability-registry.js +28 -0
- package/dist/kernel/plugin/dependency-graph.d.ts +6 -0
- package/dist/kernel/plugin/dependency-graph.d.ts.map +1 -0
- package/dist/kernel/plugin/dependency-graph.js +55 -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 +140 -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/cubes.d.ts +19 -0
- package/dist/modules/analytics/cubes.d.ts.map +1 -0
- package/dist/modules/analytics/cubes.js +187 -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/in-memory.d.ts +30 -0
- package/dist/modules/cart/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/cart/repository/in-memory.js +159 -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/in-memory.d.ts +82 -0
- package/dist/modules/catalog/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/catalog/repository/in-memory.js +444 -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 +160 -0
- package/dist/modules/catalog/service.d.ts.map +1 -0
- package/dist/modules/catalog/service.js +759 -0
- package/dist/modules/customers/repository/in-memory.d.ts +37 -0
- package/dist/modules/customers/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/customers/repository/in-memory.js +278 -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 +25 -0
- package/dist/modules/customers/service.d.ts.map +1 -0
- package/dist/modules/customers/service.js +91 -0
- package/dist/modules/fulfillment/repository/in-memory.d.ts +53 -0
- package/dist/modules/fulfillment/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/fulfillment/repository/in-memory.js +327 -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/in-memory.d.ts +51 -0
- package/dist/modules/inventory/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/inventory/repository/in-memory.js +281 -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 +65 -0
- package/dist/modules/inventory/service.d.ts.map +1 -0
- package/dist/modules/inventory/service.js +271 -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/in-memory.d.ts +26 -0
- package/dist/modules/media/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/media/repository/in-memory.js +145 -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/in-memory.d.ts +40 -0
- package/dist/modules/orders/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/orders/repository/in-memory.js +245 -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/in-memory.d.ts +25 -0
- package/dist/modules/pricing/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/pricing/repository/in-memory.js +288 -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/in-memory.d.ts +32 -0
- package/dist/modules/promotions/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/promotions/repository/in-memory.js +227 -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 +80 -0
- package/dist/modules/promotions/service.d.ts.map +1 -0
- package/dist/modules/promotions/service.js +347 -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/in-memory.d.ts +31 -0
- package/dist/modules/webhooks/repository/in-memory.d.ts.map +1 -0
- package/dist/modules/webhooks/repository/in-memory.js +187 -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 +72 -0
- package/dist/runtime/kernel.d.ts.map +1 -0
- package/dist/runtime/kernel.js +298 -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/server.d.ts +28 -0
- package/dist/runtime/server.d.ts.map +1 -0
- package/dist/runtime/server.js +277 -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/runtime/state-manager.d.ts +14 -0
- package/dist/runtime/state-manager.d.ts.map +1 -0
- package/dist/runtime/state-manager.js +84 -0
- package/dist/runtime/state-repository.d.ts +13 -0
- package/dist/runtime/state-repository.d.ts.map +1 -0
- package/dist/runtime/state-repository.js +160 -0
- package/dist/runtime/state.d.ts +382 -0
- package/dist/runtime/state.d.ts.map +1 -0
- package/dist/runtime/state.js +37 -0
- package/dist/runtime/store.d.ts +382 -0
- package/dist/runtime/store.d.ts.map +1 -0
- package/dist/runtime/store.js +37 -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 +106 -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 +174 -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/tsconfig.tsbuildinfo +1 -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 +63 -0
- package/src/adapters/console-email.ts +43 -0
- package/src/auth/access.ts +187 -0
- package/src/auth/auth-schema.ts +131 -0
- package/src/auth/middleware.ts +115 -0
- package/src/auth/org.ts +41 -0
- package/src/auth/permissions.ts +28 -0
- package/src/auth/setup.ts +160 -0
- package/src/auth/system-actor.ts +19 -0
- package/src/auth/types.ts +10 -0
- package/src/config/defaults.ts +82 -0
- package/src/config/define-config.ts +53 -0
- package/src/config/types.ts +299 -0
- package/src/generated/plugin-capabilities.d.ts +20 -0
- package/src/generated/plugin-manifest.ts +23 -0
- package/src/generated/plugin-repositories.d.ts +20 -0
- package/src/hooks/checkout-completion.ts +262 -0
- package/src/hooks/checkout.ts +677 -0
- package/src/hooks/order-emails.ts +62 -0
- package/src/index.ts +214 -0
- package/src/interfaces/mcp/agent-prompt.ts +174 -0
- package/src/interfaces/mcp/context-enrichment.ts +177 -0
- package/src/interfaces/mcp/server.ts +617 -0
- package/src/interfaces/mcp/transport.ts +68 -0
- package/src/interfaces/rest/customer-portal.ts +299 -0
- package/src/interfaces/rest/index.ts +74 -0
- package/src/interfaces/rest/router.ts +334 -0
- package/src/interfaces/rest/routes/admin-jobs.ts +58 -0
- package/src/interfaces/rest/routes/audit.ts +50 -0
- package/src/interfaces/rest/routes/carts.ts +89 -0
- package/src/interfaces/rest/routes/catalog.ts +493 -0
- package/src/interfaces/rest/routes/checkout.ts +283 -0
- package/src/interfaces/rest/routes/inventory.ts +70 -0
- package/src/interfaces/rest/routes/media.ts +86 -0
- package/src/interfaces/rest/routes/orders.ts +78 -0
- package/src/interfaces/rest/routes/payments.ts +60 -0
- package/src/interfaces/rest/routes/pricing.ts +57 -0
- package/src/interfaces/rest/routes/promotions.ts +92 -0
- package/src/interfaces/rest/routes/search.ts +71 -0
- package/src/interfaces/rest/routes/webhooks.ts +46 -0
- package/src/interfaces/rest/schemas/admin-jobs.ts +40 -0
- package/src/interfaces/rest/schemas/audit.ts +46 -0
- package/src/interfaces/rest/schemas/carts.ts +125 -0
- package/src/interfaces/rest/schemas/catalog.ts +450 -0
- package/src/interfaces/rest/schemas/checkout.ts +66 -0
- package/src/interfaces/rest/schemas/customer-portal.ts +195 -0
- package/src/interfaces/rest/schemas/inventory.ts +138 -0
- package/src/interfaces/rest/schemas/media.ts +75 -0
- package/src/interfaces/rest/schemas/orders.ts +104 -0
- package/src/interfaces/rest/schemas/pricing.ts +80 -0
- package/src/interfaces/rest/schemas/promotions.ts +110 -0
- package/src/interfaces/rest/schemas/responses.ts +85 -0
- package/src/interfaces/rest/schemas/search.ts +58 -0
- package/src/interfaces/rest/schemas/shared.ts +62 -0
- package/src/interfaces/rest/schemas/webhooks.ts +68 -0
- package/src/interfaces/rest/utils.ts +104 -0
- package/src/interfaces/rest/webhook-router.ts +50 -0
- package/src/kernel/compensation/executor.ts +61 -0
- package/src/kernel/compensation/types.ts +26 -0
- package/src/kernel/database/adapter.ts +13 -0
- package/src/kernel/database/drizzle-db.ts +56 -0
- package/src/kernel/database/migrate.ts +76 -0
- package/src/kernel/database/plugin-types.ts +34 -0
- package/src/kernel/database/schema.ts +49 -0
- package/src/kernel/database/scoped-db.ts +68 -0
- package/src/kernel/database/tx-context.ts +46 -0
- package/src/kernel/error-mapper.ts +15 -0
- package/src/kernel/errors.ts +89 -0
- package/src/kernel/factory/repository-factory.ts +242 -0
- package/src/kernel/hooks/create-context.ts +43 -0
- package/src/kernel/hooks/executor.ts +88 -0
- package/src/kernel/hooks/registry.ts +74 -0
- package/src/kernel/hooks/types.ts +52 -0
- package/src/kernel/http-error.ts +44 -0
- package/src/kernel/jobs/adapter.ts +36 -0
- package/src/kernel/jobs/drizzle-adapter.ts +58 -0
- package/src/kernel/jobs/runner.ts +153 -0
- package/src/kernel/jobs/schema.ts +46 -0
- package/src/kernel/jobs/types.ts +30 -0
- package/src/kernel/local-api.ts +185 -0
- package/src/kernel/plugin/manifest.ts +253 -0
- package/src/kernel/query/executor.ts +184 -0
- package/src/kernel/query/registry.ts +46 -0
- package/src/kernel/result.ts +33 -0
- package/src/kernel/schema/extra-columns.ts +37 -0
- package/src/kernel/service-registry.ts +76 -0
- package/src/kernel/service-timing.ts +89 -0
- package/src/kernel/state-machine/machine.ts +101 -0
- package/src/modules/analytics/drizzle-adapter.ts +426 -0
- package/src/modules/analytics/hooks.ts +11 -0
- package/src/modules/analytics/models.ts +125 -0
- package/src/modules/analytics/repository/index.ts +6 -0
- package/src/modules/analytics/service.ts +245 -0
- package/src/modules/analytics/types.ts +180 -0
- package/src/modules/audit/hooks.ts +78 -0
- package/src/modules/audit/schema.ts +33 -0
- package/src/modules/audit/service.ts +151 -0
- package/src/modules/cart/access.ts +27 -0
- package/src/modules/cart/matcher.ts +26 -0
- package/src/modules/cart/repository/index.ts +234 -0
- package/src/modules/cart/schema.ts +42 -0
- package/src/modules/cart/schemas.ts +38 -0
- package/src/modules/cart/service.ts +541 -0
- package/src/modules/catalog/repository/index.ts +772 -0
- package/src/modules/catalog/schema.ts +203 -0
- package/src/modules/catalog/schemas.ts +104 -0
- package/src/modules/catalog/service.ts +1544 -0
- package/src/modules/customers/repository/index.ts +327 -0
- package/src/modules/customers/schema.ts +64 -0
- package/src/modules/customers/service.ts +171 -0
- package/src/modules/fulfillment/repository/index.ts +426 -0
- package/src/modules/fulfillment/schema.ts +101 -0
- package/src/modules/fulfillment/service.ts +555 -0
- package/src/modules/fulfillment/types.ts +59 -0
- package/src/modules/inventory/repository/index.ts +509 -0
- package/src/modules/inventory/schema.ts +94 -0
- package/src/modules/inventory/schemas.ts +38 -0
- package/src/modules/inventory/service.ts +490 -0
- package/src/modules/media/adapter.ts +17 -0
- package/src/modules/media/repository/index.ts +274 -0
- package/src/modules/media/schema.ts +41 -0
- package/src/modules/media/service.ts +151 -0
- package/src/modules/orders/repository/index.ts +287 -0
- package/src/modules/orders/schema.ts +66 -0
- package/src/modules/orders/service.ts +619 -0
- package/src/modules/orders/stale-order-cleanup.ts +76 -0
- package/src/modules/organization/service.ts +191 -0
- package/src/modules/payments/adapter.ts +47 -0
- package/src/modules/payments/repository/index.ts +6 -0
- package/src/modules/payments/service.ts +107 -0
- package/src/modules/pricing/repository/index.ts +291 -0
- package/src/modules/pricing/schema.ts +71 -0
- package/src/modules/pricing/schemas.ts +38 -0
- package/src/modules/pricing/service.ts +494 -0
- package/src/modules/promotions/repository/index.ts +325 -0
- package/src/modules/promotions/schema.ts +62 -0
- package/src/modules/promotions/schemas.ts +38 -0
- package/src/modules/promotions/service.ts +598 -0
- package/src/modules/search/adapter.ts +57 -0
- package/src/modules/search/hooks.ts +12 -0
- package/src/modules/search/repository/index.ts +6 -0
- package/src/modules/search/service.ts +315 -0
- package/src/modules/shipping/calculator.ts +188 -0
- package/src/modules/shipping/repository/index.ts +6 -0
- package/src/modules/shipping/service.ts +51 -0
- package/src/modules/tax/adapter.ts +60 -0
- package/src/modules/tax/repository/index.ts +6 -0
- package/src/modules/tax/service.ts +53 -0
- package/src/modules/webhooks/hook.ts +34 -0
- package/src/modules/webhooks/repository/index.ts +278 -0
- package/src/modules/webhooks/schema.ts +56 -0
- package/src/modules/webhooks/service.ts +117 -0
- package/src/modules/webhooks/signing.ts +6 -0
- package/src/modules/webhooks/ssrf-guard.ts +71 -0
- package/src/modules/webhooks/tasks.ts +52 -0
- package/src/modules/webhooks/worker.ts +134 -0
- package/src/runtime/commerce.ts +145 -0
- package/src/runtime/kernel.ts +419 -0
- package/src/runtime/logger.ts +36 -0
- package/src/runtime/server.ts +345 -0
- package/src/runtime/shutdown.ts +43 -0
- package/src/test-utils/create-pglite-adapter.ts +129 -0
- package/src/test-utils/create-plugin-test-app.ts +128 -0
- package/src/test-utils/create-repository-test-harness.ts +16 -0
- package/src/test-utils/create-test-config.ts +190 -0
- package/src/test-utils/create-test-kernel.ts +7 -0
- package/src/test-utils/create-test-plugin-context.ts +75 -0
- package/src/test-utils/rest-api-test-utils.ts +265 -0
- package/src/test-utils/test-actors.ts +62 -0
- package/src/test-utils/typed-hooks.ts +54 -0
- package/src/types/commerce-types.ts +34 -0
- package/src/utils/id.ts +3 -0
- package/src/utils/logger.ts +18 -0
- package/src/utils/pagination.ts +22 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { index, integer, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
|
2
|
+
import { organization } from "../../auth/auth-schema";
|
|
3
|
+
import { sellableEntities, variants } from "../catalog/schema";
|
|
4
|
+
|
|
5
|
+
export const prices = pgTable(
|
|
6
|
+
"prices",
|
|
7
|
+
{
|
|
8
|
+
id: uuid("id").defaultRandom().primaryKey(),
|
|
9
|
+
organizationId: text("organization_id")
|
|
10
|
+
.notNull()
|
|
11
|
+
.references(() => organization.id, { onDelete: "cascade" }),
|
|
12
|
+
entityId: uuid("entity_id")
|
|
13
|
+
.references(() => sellableEntities.id, { onDelete: "cascade" })
|
|
14
|
+
.notNull(),
|
|
15
|
+
variantId: uuid("variant_id").references(() => variants.id, { onDelete: "cascade" }),
|
|
16
|
+
currency: text("currency").notNull(),
|
|
17
|
+
amount: integer("amount").notNull(),
|
|
18
|
+
customerGroupId: text("customer_group_id"),
|
|
19
|
+
minQuantity: integer("min_quantity"),
|
|
20
|
+
maxQuantity: integer("max_quantity"),
|
|
21
|
+
validFrom: timestamp("valid_from", { withTimezone: true }),
|
|
22
|
+
validUntil: timestamp("valid_until", { withTimezone: true }),
|
|
23
|
+
metadata: jsonb("metadata").$type<Record<string, unknown>>().default({}),
|
|
24
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
25
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
|
26
|
+
},
|
|
27
|
+
(table) => ({
|
|
28
|
+
entityVariantCurrencyIdx: index("idx_prices_entity_variant_currency").on(
|
|
29
|
+
table.entityId,
|
|
30
|
+
table.variantId,
|
|
31
|
+
table.currency,
|
|
32
|
+
),
|
|
33
|
+
customerGroupIdx: index("idx_prices_customer_group").on(table.customerGroupId),
|
|
34
|
+
quantityIdx: index("idx_prices_quantity").on(table.minQuantity, table.maxQuantity),
|
|
35
|
+
validityIdx: index("idx_prices_validity").on(table.validFrom, table.validUntil),
|
|
36
|
+
orgIdx: index("idx_prices_org").on(table.organizationId),
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const priceModifiers = pgTable(
|
|
41
|
+
"price_modifiers",
|
|
42
|
+
{
|
|
43
|
+
id: uuid("id").defaultRandom().primaryKey(),
|
|
44
|
+
organizationId: text("organization_id")
|
|
45
|
+
.notNull()
|
|
46
|
+
.references(() => organization.id, { onDelete: "cascade" }),
|
|
47
|
+
name: text("name").notNull(),
|
|
48
|
+
type: text("type", {
|
|
49
|
+
enum: ["percentage_discount", "fixed_discount", "markup", "override"],
|
|
50
|
+
}).notNull(),
|
|
51
|
+
value: integer("value").notNull(),
|
|
52
|
+
priority: integer("priority").notNull().default(100),
|
|
53
|
+
entityId: uuid("entity_id").references(() => sellableEntities.id, { onDelete: "cascade" }),
|
|
54
|
+
variantId: uuid("variant_id").references(() => variants.id, { onDelete: "cascade" }),
|
|
55
|
+
customerGroupId: text("customer_group_id"),
|
|
56
|
+
currency: text("currency").default("USD"),
|
|
57
|
+
minQuantity: integer("min_quantity"),
|
|
58
|
+
maxQuantity: integer("max_quantity"),
|
|
59
|
+
conditions: jsonb("conditions").$type<Record<string, unknown>>().default({}),
|
|
60
|
+
validFrom: timestamp("valid_from", { withTimezone: true }),
|
|
61
|
+
validUntil: timestamp("valid_until", { withTimezone: true }),
|
|
62
|
+
metadata: jsonb("metadata").$type<Record<string, unknown>>().default({}),
|
|
63
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
64
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
|
65
|
+
},
|
|
66
|
+
(table) => ({
|
|
67
|
+
entityVariantIdx: index("idx_price_modifiers_entity_variant").on(table.entityId, table.variantId),
|
|
68
|
+
priorityIdx: index("idx_price_modifiers_priority").on(table.priority),
|
|
69
|
+
orgIdx: index("idx_price_modifiers_org").on(table.organizationId),
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
|
|
3
|
+
// ─── Zod Body Schemas (single source of truth) ─────────────────────────────
|
|
4
|
+
|
|
5
|
+
export const SetBasePriceBodySchema = z.object({
|
|
6
|
+
entityId: z.string().openapi({ example: "product-uuid" }),
|
|
7
|
+
variantId: z.string().optional().openapi({ example: "variant-uuid" }),
|
|
8
|
+
currency: z.string().length(3).openapi({ example: "USD" }),
|
|
9
|
+
amount: z.number().openapi({ example: 29.99 }),
|
|
10
|
+
customerGroupId: z.string().optional(),
|
|
11
|
+
minQuantity: z.number().int().optional(),
|
|
12
|
+
maxQuantity: z.number().int().optional(),
|
|
13
|
+
validFrom: z.coerce.date().optional(),
|
|
14
|
+
validUntil: z.coerce.date().optional(),
|
|
15
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
16
|
+
}).openapi("SetBasePriceRequest");
|
|
17
|
+
|
|
18
|
+
export const CreateModifierBodySchema = z.object({
|
|
19
|
+
name: z.string().openapi({ example: "Summer Sale" }),
|
|
20
|
+
type: z.enum(["percentage_discount", "fixed_discount", "markup", "override"]).openapi({ example: "percentage_discount" }),
|
|
21
|
+
value: z.number().openapi({ example: 10 }),
|
|
22
|
+
priority: z.number().int().optional(),
|
|
23
|
+
entityId: z.string().optional(),
|
|
24
|
+
variantId: z.string().optional(),
|
|
25
|
+
customerGroupId: z.string().optional(),
|
|
26
|
+
currency: z.string().length(3).optional().openapi({ example: "USD" }),
|
|
27
|
+
minQuantity: z.number().int().optional(),
|
|
28
|
+
maxQuantity: z.number().int().optional(),
|
|
29
|
+
conditions: z.record(z.string(), z.unknown()).optional(),
|
|
30
|
+
validFrom: z.coerce.date().optional(),
|
|
31
|
+
validUntil: z.coerce.date().optional(),
|
|
32
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
33
|
+
}).openapi("CreateModifierRequest");
|
|
34
|
+
|
|
35
|
+
// ─── Derived Input Types ────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
export type SetBasePriceInput = z.infer<typeof SetBasePriceBodySchema>;
|
|
38
|
+
export type CreatePriceModifierInput = z.infer<typeof CreateModifierBodySchema>;
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { resolveOrgId } from "../../auth/org";
|
|
2
|
+
import type { Actor } from "../../auth/types";
|
|
3
|
+
import {
|
|
4
|
+
CommerceNotFoundError,
|
|
5
|
+
CommerceValidationError,
|
|
6
|
+
} from "../../kernel/errors";
|
|
7
|
+
import { Err, Ok, type Result } from "../../kernel/result";
|
|
8
|
+
import type { TxContext } from "../../kernel/database/tx-context";
|
|
9
|
+
import type {
|
|
10
|
+
PricingRepository,
|
|
11
|
+
Price,
|
|
12
|
+
PriceModifier,
|
|
13
|
+
PriceInsert,
|
|
14
|
+
PriceModifierInsert,
|
|
15
|
+
} from "./repository";
|
|
16
|
+
import type { CatalogRepository } from "../catalog/repository";
|
|
17
|
+
|
|
18
|
+
// Re-export PriceModifierType from schema for external use
|
|
19
|
+
export type PriceModifierType =
|
|
20
|
+
| "percentage_discount"
|
|
21
|
+
| "fixed_discount"
|
|
22
|
+
| "markup"
|
|
23
|
+
| "override";
|
|
24
|
+
|
|
25
|
+
interface PricingServiceDeps {
|
|
26
|
+
repository: PricingRepository;
|
|
27
|
+
catalogRepository: CatalogRepository;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface PriceResolutionContext {
|
|
31
|
+
entityId: string;
|
|
32
|
+
variantId?: string;
|
|
33
|
+
currency: string;
|
|
34
|
+
quantity: number;
|
|
35
|
+
customerId?: string;
|
|
36
|
+
customerGroupIds?: string[];
|
|
37
|
+
timestamp?: Date;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PriceBreakdownStep {
|
|
41
|
+
label: string;
|
|
42
|
+
amountBefore: number;
|
|
43
|
+
delta: number;
|
|
44
|
+
amountAfter: number;
|
|
45
|
+
metadata?: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ResolvedPrice {
|
|
49
|
+
baseAmount: number;
|
|
50
|
+
finalAmount: number;
|
|
51
|
+
currency: string;
|
|
52
|
+
appliedModifiers: Array<{
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
type: PriceModifierType;
|
|
56
|
+
delta: number;
|
|
57
|
+
value: number;
|
|
58
|
+
priority: number;
|
|
59
|
+
}>;
|
|
60
|
+
breakdown: PriceBreakdownStep[];
|
|
61
|
+
basePriceId: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type { SetBasePriceInput, CreatePriceModifierInput } from "./schemas";
|
|
65
|
+
import type { SetBasePriceInput, CreatePriceModifierInput } from "./schemas";
|
|
66
|
+
|
|
67
|
+
function matchesQuantity(
|
|
68
|
+
min: number | null | undefined,
|
|
69
|
+
max: number | null | undefined,
|
|
70
|
+
quantity: number,
|
|
71
|
+
): boolean {
|
|
72
|
+
if (min != null && quantity < min) return false;
|
|
73
|
+
if (max != null && quantity > max) return false;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function matchesWindow(
|
|
78
|
+
validFrom: Date | null | undefined,
|
|
79
|
+
validUntil: Date | null | undefined,
|
|
80
|
+
timestamp: Date,
|
|
81
|
+
): boolean {
|
|
82
|
+
if (validFrom && timestamp < validFrom) return false;
|
|
83
|
+
if (validUntil && timestamp > validUntil) return false;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function durationScore(
|
|
88
|
+
validFrom: Date | null | undefined,
|
|
89
|
+
validUntil: Date | null | undefined,
|
|
90
|
+
): number {
|
|
91
|
+
if (validFrom && validUntil)
|
|
92
|
+
return validUntil.getTime() - validFrom.getTime();
|
|
93
|
+
if (validFrom || validUntil) return Number.MAX_SAFE_INTEGER - 1;
|
|
94
|
+
return Number.MAX_SAFE_INTEGER;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function quantityRangeWidth(
|
|
98
|
+
min: number | null | undefined,
|
|
99
|
+
max: number | null | undefined,
|
|
100
|
+
): number {
|
|
101
|
+
if (min != null && max != null) return Math.max(0, max - min);
|
|
102
|
+
if (min != null || max != null) return Number.MAX_SAFE_INTEGER - 1;
|
|
103
|
+
return Number.MAX_SAFE_INTEGER;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function compareBasePriceSpecificity(
|
|
107
|
+
a: Price,
|
|
108
|
+
b: Price,
|
|
109
|
+
context: PriceResolutionContext,
|
|
110
|
+
): number {
|
|
111
|
+
const aVariant =
|
|
112
|
+
context.variantId !== undefined && a.variantId === context.variantId
|
|
113
|
+
? 1
|
|
114
|
+
: 0;
|
|
115
|
+
const bVariant =
|
|
116
|
+
context.variantId !== undefined && b.variantId === context.variantId
|
|
117
|
+
? 1
|
|
118
|
+
: 0;
|
|
119
|
+
if (aVariant !== bVariant) return bVariant - aVariant;
|
|
120
|
+
|
|
121
|
+
const hasGroupA = a.customerGroupId ? 1 : 0;
|
|
122
|
+
const hasGroupB = b.customerGroupId ? 1 : 0;
|
|
123
|
+
if (hasGroupA !== hasGroupB) return hasGroupB - hasGroupA;
|
|
124
|
+
|
|
125
|
+
const aRange = quantityRangeWidth(a.minQuantity, a.maxQuantity);
|
|
126
|
+
const bRange = quantityRangeWidth(b.minQuantity, b.maxQuantity);
|
|
127
|
+
if (aRange !== bRange) return aRange - bRange;
|
|
128
|
+
|
|
129
|
+
const aDuration = durationScore(a.validFrom, a.validUntil);
|
|
130
|
+
const bDuration = durationScore(b.validFrom, b.validUntil);
|
|
131
|
+
if (aDuration !== bDuration) return aDuration - bDuration;
|
|
132
|
+
|
|
133
|
+
return b.createdAt.getTime() - a.createdAt.getTime();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function resolveModifierDelta(
|
|
137
|
+
type: PriceModifierType,
|
|
138
|
+
value: number,
|
|
139
|
+
amountBefore: number,
|
|
140
|
+
): number {
|
|
141
|
+
switch (type) {
|
|
142
|
+
case "percentage_discount":
|
|
143
|
+
return -Math.round((amountBefore * value) / 100);
|
|
144
|
+
case "fixed_discount":
|
|
145
|
+
return -value;
|
|
146
|
+
case "markup":
|
|
147
|
+
return value;
|
|
148
|
+
case "override":
|
|
149
|
+
return value - amountBefore;
|
|
150
|
+
default:
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function toGroupSet(context: PriceResolutionContext): Set<string> {
|
|
156
|
+
return new Set(context.customerGroupIds ?? []);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function normalizeCurrency(currency: string): string {
|
|
160
|
+
return currency.trim().toUpperCase();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export class PricingService {
|
|
164
|
+
private readonly repo: PricingRepository;
|
|
165
|
+
private readonly catalogRepo: CatalogRepository;
|
|
166
|
+
|
|
167
|
+
constructor(private deps: PricingServiceDeps) {
|
|
168
|
+
this.repo = deps.repository;
|
|
169
|
+
this.catalogRepo = deps.catalogRepository;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
async setBasePrice(
|
|
173
|
+
input: SetBasePriceInput,
|
|
174
|
+
actor?: Actor | null,
|
|
175
|
+
ctx?: TxContext,
|
|
176
|
+
): Promise<Result<Price>> {
|
|
177
|
+
if (input.amount < 0) {
|
|
178
|
+
return Err(
|
|
179
|
+
new CommerceValidationError("Base price amount cannot be negative."),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const entity = await this.catalogRepo.findEntityById(input.entityId, ctx);
|
|
184
|
+
if (!entity) {
|
|
185
|
+
return Err(
|
|
186
|
+
new CommerceNotFoundError("Entity not found for price assignment."),
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
191
|
+
|
|
192
|
+
const priceData: PriceInsert = {
|
|
193
|
+
organizationId: orgId,
|
|
194
|
+
entityId: input.entityId,
|
|
195
|
+
currency: normalizeCurrency(input.currency),
|
|
196
|
+
amount: input.amount,
|
|
197
|
+
metadata: input.metadata ?? {},
|
|
198
|
+
variantId: input.variantId ?? null,
|
|
199
|
+
customerGroupId: input.customerGroupId ?? null,
|
|
200
|
+
minQuantity: input.minQuantity ?? null,
|
|
201
|
+
maxQuantity: input.maxQuantity ?? null,
|
|
202
|
+
validFrom: input.validFrom ?? null,
|
|
203
|
+
validUntil: input.validUntil ?? null,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const record = await this.repo.createPrice(priceData, ctx);
|
|
207
|
+
return Ok(record);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async createModifier(
|
|
211
|
+
input: CreatePriceModifierInput,
|
|
212
|
+
actor?: Actor | null,
|
|
213
|
+
ctx?: TxContext,
|
|
214
|
+
): Promise<Result<PriceModifier>> {
|
|
215
|
+
if (!input.name) {
|
|
216
|
+
return Err(new CommerceValidationError("Modifier name is required."));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Validate modifier type
|
|
220
|
+
const validTypes: PriceModifierType[] = [
|
|
221
|
+
"percentage_discount",
|
|
222
|
+
"fixed_discount",
|
|
223
|
+
"markup",
|
|
224
|
+
"override",
|
|
225
|
+
];
|
|
226
|
+
if (!validTypes.includes(input.type)) {
|
|
227
|
+
return Err(
|
|
228
|
+
new CommerceValidationError(
|
|
229
|
+
`Invalid modifier type "${input.type}". Must be one of: ${validTypes.join(", ")}`,
|
|
230
|
+
),
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const orgId = resolveOrgId(actor ?? ctx?.actor ?? null);
|
|
235
|
+
|
|
236
|
+
const modifierData: PriceModifierInsert = {
|
|
237
|
+
organizationId: orgId,
|
|
238
|
+
name: input.name,
|
|
239
|
+
type: input.type,
|
|
240
|
+
value: input.value,
|
|
241
|
+
priority: input.priority ?? 100,
|
|
242
|
+
conditions: input.conditions ?? {},
|
|
243
|
+
metadata: input.metadata ?? {},
|
|
244
|
+
entityId: input.entityId ?? null,
|
|
245
|
+
variantId: input.variantId ?? null,
|
|
246
|
+
customerGroupId: input.customerGroupId ?? null,
|
|
247
|
+
currency: input.currency ? normalizeCurrency(input.currency) : null,
|
|
248
|
+
minQuantity: input.minQuantity ?? null,
|
|
249
|
+
maxQuantity: input.maxQuantity ?? null,
|
|
250
|
+
validFrom: input.validFrom ?? null,
|
|
251
|
+
validUntil: input.validUntil ?? null,
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const modifier = await this.repo.createModifier(modifierData, ctx);
|
|
255
|
+
return Ok(modifier);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async listPrices(
|
|
259
|
+
filter?: {
|
|
260
|
+
entityId?: string;
|
|
261
|
+
variantId?: string;
|
|
262
|
+
currency?: string;
|
|
263
|
+
customerGroupId?: string;
|
|
264
|
+
},
|
|
265
|
+
ctx?: TxContext,
|
|
266
|
+
): Promise<Result<{ prices: Price[]; modifiers: PriceModifier[] }>> {
|
|
267
|
+
// Get all prices for the entity if specified, or filter after retrieval
|
|
268
|
+
let prices: Price[] = [];
|
|
269
|
+
if (filter?.entityId) {
|
|
270
|
+
prices = await this.repo.findPricesByEntityId(filter.entityId, ctx);
|
|
271
|
+
}
|
|
272
|
+
// Note: For full list without entityId, we'd need a findAll method
|
|
273
|
+
// For now, entityId is typically required for practical use
|
|
274
|
+
|
|
275
|
+
// Apply additional filters
|
|
276
|
+
if (filter?.variantId !== undefined) {
|
|
277
|
+
prices = prices.filter((p) => p.variantId === filter.variantId);
|
|
278
|
+
}
|
|
279
|
+
if (filter?.currency !== undefined) {
|
|
280
|
+
const normalizedCurrency = normalizeCurrency(filter.currency);
|
|
281
|
+
prices = prices.filter((p) => p.currency === normalizedCurrency);
|
|
282
|
+
}
|
|
283
|
+
if (filter?.customerGroupId !== undefined) {
|
|
284
|
+
prices = prices.filter(
|
|
285
|
+
(p) => p.customerGroupId === filter.customerGroupId,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Get modifiers for the entity
|
|
290
|
+
let modifiers: PriceModifier[] = [];
|
|
291
|
+
if (filter?.entityId) {
|
|
292
|
+
modifiers = await this.repo.findModifiersByEntityId(filter.entityId, ctx);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Apply additional filters
|
|
296
|
+
if (filter?.variantId !== undefined) {
|
|
297
|
+
modifiers = modifiers.filter((m) => m.variantId === filter.variantId);
|
|
298
|
+
}
|
|
299
|
+
if (filter?.currency !== undefined) {
|
|
300
|
+
const normalizedCurrency = normalizeCurrency(filter.currency);
|
|
301
|
+
modifiers = modifiers.filter(
|
|
302
|
+
(m) => m.currency === null || m.currency === normalizedCurrency,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
if (filter?.customerGroupId !== undefined) {
|
|
306
|
+
modifiers = modifiers.filter(
|
|
307
|
+
(m) =>
|
|
308
|
+
m.customerGroupId === null ||
|
|
309
|
+
m.customerGroupId === filter.customerGroupId,
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return Ok({ prices, modifiers });
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async resolve(
|
|
317
|
+
input: PriceResolutionContext,
|
|
318
|
+
ctx?: TxContext,
|
|
319
|
+
): Promise<Result<ResolvedPrice>> {
|
|
320
|
+
const entity = await this.catalogRepo.findEntityById(input.entityId, ctx);
|
|
321
|
+
if (!entity) {
|
|
322
|
+
return Err(
|
|
323
|
+
new CommerceNotFoundError(`Entity ${input.entityId} not found.`),
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (input.quantity <= 0) {
|
|
328
|
+
return Err(
|
|
329
|
+
new CommerceValidationError(
|
|
330
|
+
"Quantity must be greater than zero for price resolution.",
|
|
331
|
+
),
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const timestamp = input.timestamp ?? new Date();
|
|
336
|
+
const currency = normalizeCurrency(input.currency);
|
|
337
|
+
const groupSet = toGroupSet(input);
|
|
338
|
+
|
|
339
|
+
// Get matching prices from repository
|
|
340
|
+
const allPrices = await this.repo.findPricesByEntityId(input.entityId, ctx);
|
|
341
|
+
|
|
342
|
+
const matchingPrices = allPrices.filter((price) => {
|
|
343
|
+
if (input.variantId !== undefined) {
|
|
344
|
+
if (price.variantId !== null && price.variantId !== input.variantId)
|
|
345
|
+
return false;
|
|
346
|
+
} else if (price.variantId !== null) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
if (price.currency !== currency) return false;
|
|
350
|
+
if (
|
|
351
|
+
!matchesQuantity(price.minQuantity, price.maxQuantity, input.quantity)
|
|
352
|
+
)
|
|
353
|
+
return false;
|
|
354
|
+
if (!matchesWindow(price.validFrom, price.validUntil, timestamp))
|
|
355
|
+
return false;
|
|
356
|
+
if (
|
|
357
|
+
price.customerGroupId !== null &&
|
|
358
|
+
!groupSet.has(price.customerGroupId)
|
|
359
|
+
)
|
|
360
|
+
return false;
|
|
361
|
+
return true;
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
if (matchingPrices.length === 0) {
|
|
365
|
+
const metadataPrice =
|
|
366
|
+
typeof entity.metadata?.basePrice === "number"
|
|
367
|
+
? Math.round(entity.metadata.basePrice)
|
|
368
|
+
: undefined;
|
|
369
|
+
if (metadataPrice === undefined) {
|
|
370
|
+
return Err(
|
|
371
|
+
new CommerceNotFoundError(
|
|
372
|
+
`No base price configured for ${entity.slug} (${currency}).`,
|
|
373
|
+
),
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
const fallback: ResolvedPrice = {
|
|
377
|
+
baseAmount: metadataPrice,
|
|
378
|
+
finalAmount: metadataPrice,
|
|
379
|
+
currency,
|
|
380
|
+
basePriceId: "metadata:basePrice",
|
|
381
|
+
appliedModifiers: [],
|
|
382
|
+
breakdown: [
|
|
383
|
+
{
|
|
384
|
+
label: "Base price (entity metadata)",
|
|
385
|
+
amountBefore: metadataPrice,
|
|
386
|
+
delta: 0,
|
|
387
|
+
amountAfter: metadataPrice,
|
|
388
|
+
},
|
|
389
|
+
],
|
|
390
|
+
};
|
|
391
|
+
return Ok(fallback);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const selectedBase = [...matchingPrices].sort((a, b) =>
|
|
395
|
+
compareBasePriceSpecificity(a, b, input),
|
|
396
|
+
)[0];
|
|
397
|
+
if (!selectedBase) {
|
|
398
|
+
return Err(
|
|
399
|
+
new CommerceNotFoundError("No matching base price could be selected."),
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
let runningAmount = selectedBase.amount;
|
|
404
|
+
const breakdown: PriceBreakdownStep[] = [
|
|
405
|
+
{
|
|
406
|
+
label: "Base price",
|
|
407
|
+
amountBefore: selectedBase.amount,
|
|
408
|
+
delta: 0,
|
|
409
|
+
amountAfter: selectedBase.amount,
|
|
410
|
+
metadata: {
|
|
411
|
+
priceId: selectedBase.id,
|
|
412
|
+
customerGroupId: selectedBase.customerGroupId,
|
|
413
|
+
minQuantity: selectedBase.minQuantity,
|
|
414
|
+
maxQuantity: selectedBase.maxQuantity,
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
];
|
|
418
|
+
|
|
419
|
+
const appliedModifiers: ResolvedPrice["appliedModifiers"] = [];
|
|
420
|
+
|
|
421
|
+
// Get matching modifiers (includes both entity-specific and global)
|
|
422
|
+
const firstGroupId = groupSet.size > 0 ? [...groupSet][0] : undefined;
|
|
423
|
+
const activeModifiers = await this.repo.findActiveModifiers(
|
|
424
|
+
input.entityId,
|
|
425
|
+
input.variantId,
|
|
426
|
+
firstGroupId,
|
|
427
|
+
currency,
|
|
428
|
+
input.quantity,
|
|
429
|
+
ctx,
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
// Additional filtering for multiple customer groups and conditions
|
|
433
|
+
const modifiers = activeModifiers
|
|
434
|
+
.filter((modifier) => {
|
|
435
|
+
// Re-check customer group for multi-group support
|
|
436
|
+
if (
|
|
437
|
+
modifier.customerGroupId !== null &&
|
|
438
|
+
!groupSet.has(modifier.customerGroupId)
|
|
439
|
+
)
|
|
440
|
+
return false;
|
|
441
|
+
|
|
442
|
+
const conditions = modifier.conditions as Record<
|
|
443
|
+
string,
|
|
444
|
+
unknown
|
|
445
|
+
> | null;
|
|
446
|
+
const minSubtotal = conditions?.minSubtotal;
|
|
447
|
+
if (typeof minSubtotal === "number" && runningAmount < minSubtotal)
|
|
448
|
+
return false;
|
|
449
|
+
|
|
450
|
+
return true;
|
|
451
|
+
})
|
|
452
|
+
.sort((a, b) => a.priority - b.priority);
|
|
453
|
+
|
|
454
|
+
for (const modifier of modifiers) {
|
|
455
|
+
const amountBefore = runningAmount;
|
|
456
|
+
const rawDelta = resolveModifierDelta(
|
|
457
|
+
modifier.type as PriceModifierType,
|
|
458
|
+
modifier.value,
|
|
459
|
+
amountBefore,
|
|
460
|
+
);
|
|
461
|
+
const delta = Math.max(-amountBefore, rawDelta);
|
|
462
|
+
runningAmount = Math.max(0, amountBefore + delta);
|
|
463
|
+
|
|
464
|
+
appliedModifiers.push({
|
|
465
|
+
id: modifier.id,
|
|
466
|
+
name: modifier.name,
|
|
467
|
+
type: modifier.type as PriceModifierType,
|
|
468
|
+
delta,
|
|
469
|
+
value: modifier.value,
|
|
470
|
+
priority: modifier.priority,
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
breakdown.push({
|
|
474
|
+
label: `Modifier: ${modifier.name}`,
|
|
475
|
+
amountBefore,
|
|
476
|
+
delta,
|
|
477
|
+
amountAfter: runningAmount,
|
|
478
|
+
metadata: {
|
|
479
|
+
type: modifier.type,
|
|
480
|
+
priority: modifier.priority,
|
|
481
|
+
},
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return Ok({
|
|
486
|
+
baseAmount: selectedBase.amount,
|
|
487
|
+
finalAmount: runningAmount,
|
|
488
|
+
currency,
|
|
489
|
+
basePriceId: selectedBase.id,
|
|
490
|
+
appliedModifiers,
|
|
491
|
+
breakdown,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
}
|