@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,772 @@
|
|
|
1
|
+
import { eq, and, inArray, type SQL } from "drizzle-orm";
|
|
2
|
+
import type { TxContext } from "../../../kernel/database/tx-context";
|
|
3
|
+
import type {
|
|
4
|
+
DrizzleDatabase,
|
|
5
|
+
DbOrTx,
|
|
6
|
+
} from "../../../kernel/database/drizzle-db";
|
|
7
|
+
import {
|
|
8
|
+
sellableEntities,
|
|
9
|
+
sellableAttributes,
|
|
10
|
+
sellableCustomFields,
|
|
11
|
+
categories,
|
|
12
|
+
entityCategories,
|
|
13
|
+
brands,
|
|
14
|
+
entityBrands,
|
|
15
|
+
optionTypes,
|
|
16
|
+
optionValues,
|
|
17
|
+
variants,
|
|
18
|
+
variantOptionValues,
|
|
19
|
+
} from "../schema";
|
|
20
|
+
|
|
21
|
+
// Infer types from Drizzle schema
|
|
22
|
+
export type SellableEntity = typeof sellableEntities.$inferSelect;
|
|
23
|
+
export type SellableEntityInsert = typeof sellableEntities.$inferInsert;
|
|
24
|
+
export type SellableAttribute = typeof sellableAttributes.$inferSelect;
|
|
25
|
+
export type SellableAttributeInsert = typeof sellableAttributes.$inferInsert;
|
|
26
|
+
export type SellableCustomField = typeof sellableCustomFields.$inferSelect;
|
|
27
|
+
export type SellableCustomFieldInsert =
|
|
28
|
+
typeof sellableCustomFields.$inferInsert;
|
|
29
|
+
export type Category = typeof categories.$inferSelect;
|
|
30
|
+
export type CategoryInsert = typeof categories.$inferInsert;
|
|
31
|
+
export type EntityCategory = typeof entityCategories.$inferSelect;
|
|
32
|
+
export type EntityCategoryInsert = typeof entityCategories.$inferInsert;
|
|
33
|
+
export type Brand = typeof brands.$inferSelect;
|
|
34
|
+
export type BrandInsert = typeof brands.$inferInsert;
|
|
35
|
+
export type EntityBrand = typeof entityBrands.$inferSelect;
|
|
36
|
+
export type EntityBrandInsert = typeof entityBrands.$inferInsert;
|
|
37
|
+
export type OptionType = typeof optionTypes.$inferSelect;
|
|
38
|
+
export type OptionTypeInsert = typeof optionTypes.$inferInsert;
|
|
39
|
+
export type OptionValue = typeof optionValues.$inferSelect;
|
|
40
|
+
export type OptionValueInsert = typeof optionValues.$inferInsert;
|
|
41
|
+
export type Variant = typeof variants.$inferSelect;
|
|
42
|
+
export type VariantInsert = typeof variants.$inferInsert;
|
|
43
|
+
export type VariantOptionValue = typeof variantOptionValues.$inferSelect;
|
|
44
|
+
export type VariantOptionValueInsert = typeof variantOptionValues.$inferInsert;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* CatalogRepository provides type-safe database operations for catalog entities.
|
|
48
|
+
*
|
|
49
|
+
* This repository uses Drizzle ORM with PostgresJsDatabase for full type inference.
|
|
50
|
+
* Transaction context is passed through TxContext when needed for transactional writes.
|
|
51
|
+
*
|
|
52
|
+
* All methods support an optional TxContext parameter for transaction participation.
|
|
53
|
+
* When ctx is provided, operations run within that transaction; otherwise they use the main db.
|
|
54
|
+
*/
|
|
55
|
+
export class CatalogRepository {
|
|
56
|
+
constructor(private readonly db: DrizzleDatabase) {}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the appropriate database context - either a transaction or the main db.
|
|
60
|
+
* Both DrizzleDatabase and DrizzleTx have the same query builder interface.
|
|
61
|
+
*/
|
|
62
|
+
private getDb(ctx?: TxContext): DbOrTx {
|
|
63
|
+
return (ctx?.tx as DbOrTx | undefined) ?? this.db;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
67
|
+
// Sellable Entities
|
|
68
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
69
|
+
|
|
70
|
+
async findEntityById(
|
|
71
|
+
id: string,
|
|
72
|
+
ctx?: TxContext,
|
|
73
|
+
): Promise<SellableEntity | undefined> {
|
|
74
|
+
const db = this.getDb(ctx);
|
|
75
|
+
const rows = await db
|
|
76
|
+
.select()
|
|
77
|
+
.from(sellableEntities)
|
|
78
|
+
.where(eq(sellableEntities.id, id));
|
|
79
|
+
return rows[0];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async findEntityBySlug(
|
|
83
|
+
orgId: string,
|
|
84
|
+
slug: string,
|
|
85
|
+
ctx?: TxContext,
|
|
86
|
+
): Promise<SellableEntity | undefined> {
|
|
87
|
+
const db = this.getDb(ctx);
|
|
88
|
+
const rows = await db
|
|
89
|
+
.select()
|
|
90
|
+
.from(sellableEntities)
|
|
91
|
+
.where(
|
|
92
|
+
and(
|
|
93
|
+
eq(sellableEntities.organizationId, orgId),
|
|
94
|
+
eq(sellableEntities.slug, slug),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
return rows[0];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async findEntities(
|
|
101
|
+
orgId: string,
|
|
102
|
+
filter?: {
|
|
103
|
+
type?: string;
|
|
104
|
+
status?: string;
|
|
105
|
+
ids?: string[];
|
|
106
|
+
},
|
|
107
|
+
ctx?: TxContext,
|
|
108
|
+
): Promise<SellableEntity[]> {
|
|
109
|
+
const db = this.getDb(ctx);
|
|
110
|
+
const conditions: SQL[] = [eq(sellableEntities.organizationId, orgId)];
|
|
111
|
+
|
|
112
|
+
if (filter?.type) {
|
|
113
|
+
conditions.push(eq(sellableEntities.type, filter.type));
|
|
114
|
+
}
|
|
115
|
+
if (filter?.status) {
|
|
116
|
+
conditions.push(
|
|
117
|
+
eq(sellableEntities.status, filter.status as SellableEntity["status"]),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (filter?.ids && filter.ids.length > 0) {
|
|
121
|
+
conditions.push(inArray(sellableEntities.id, filter.ids));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return db
|
|
125
|
+
.select()
|
|
126
|
+
.from(sellableEntities)
|
|
127
|
+
.where(conditions.length === 1 ? conditions[0] : and(...conditions));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async createEntity(
|
|
131
|
+
data: SellableEntityInsert,
|
|
132
|
+
ctx?: TxContext,
|
|
133
|
+
): Promise<SellableEntity> {
|
|
134
|
+
const db = this.getDb(ctx);
|
|
135
|
+
const rows = await db.insert(sellableEntities).values(data).returning();
|
|
136
|
+
return rows[0]!;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async updateEntity(
|
|
140
|
+
id: string,
|
|
141
|
+
data: Partial<Omit<SellableEntityInsert, "id">>,
|
|
142
|
+
ctx?: TxContext,
|
|
143
|
+
): Promise<SellableEntity | undefined> {
|
|
144
|
+
const db = this.getDb(ctx);
|
|
145
|
+
const rows = await db
|
|
146
|
+
.update(sellableEntities)
|
|
147
|
+
.set({ ...data, updatedAt: new Date() })
|
|
148
|
+
.where(eq(sellableEntities.id, id))
|
|
149
|
+
.returning();
|
|
150
|
+
return rows[0];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async deleteEntity(id: string, ctx?: TxContext): Promise<boolean> {
|
|
154
|
+
const db = this.getDb(ctx);
|
|
155
|
+
const result = await db
|
|
156
|
+
.delete(sellableEntities)
|
|
157
|
+
.where(eq(sellableEntities.id, id))
|
|
158
|
+
.returning();
|
|
159
|
+
return result.length > 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
// Sellable Attributes
|
|
164
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
165
|
+
|
|
166
|
+
async findAttributesByEntityId(
|
|
167
|
+
entityId: string,
|
|
168
|
+
ctx?: TxContext,
|
|
169
|
+
): Promise<SellableAttribute[]> {
|
|
170
|
+
const db = this.getDb(ctx);
|
|
171
|
+
return db
|
|
172
|
+
.select()
|
|
173
|
+
.from(sellableAttributes)
|
|
174
|
+
.where(eq(sellableAttributes.entityId, entityId));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async findAttributeByLocale(
|
|
178
|
+
entityId: string,
|
|
179
|
+
locale: string,
|
|
180
|
+
ctx?: TxContext,
|
|
181
|
+
): Promise<SellableAttribute | undefined> {
|
|
182
|
+
const db = this.getDb(ctx);
|
|
183
|
+
const rows = await db
|
|
184
|
+
.select()
|
|
185
|
+
.from(sellableAttributes)
|
|
186
|
+
.where(
|
|
187
|
+
and(
|
|
188
|
+
eq(sellableAttributes.entityId, entityId),
|
|
189
|
+
eq(sellableAttributes.locale, locale),
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
return rows[0];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async createAttribute(
|
|
196
|
+
data: SellableAttributeInsert,
|
|
197
|
+
ctx?: TxContext,
|
|
198
|
+
): Promise<SellableAttribute> {
|
|
199
|
+
const db = this.getDb(ctx);
|
|
200
|
+
const rows = await db.insert(sellableAttributes).values(data).returning();
|
|
201
|
+
return rows[0]!;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async updateAttribute(
|
|
205
|
+
id: string,
|
|
206
|
+
data: Partial<Omit<SellableAttributeInsert, "id">>,
|
|
207
|
+
ctx?: TxContext,
|
|
208
|
+
): Promise<SellableAttribute | undefined> {
|
|
209
|
+
const db = this.getDb(ctx);
|
|
210
|
+
const rows = await db
|
|
211
|
+
.update(sellableAttributes)
|
|
212
|
+
.set(data)
|
|
213
|
+
.where(eq(sellableAttributes.id, id))
|
|
214
|
+
.returning();
|
|
215
|
+
return rows[0];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async upsertAttribute(
|
|
219
|
+
entityId: string,
|
|
220
|
+
locale: string,
|
|
221
|
+
data: Omit<SellableAttributeInsert, "entityId" | "locale">,
|
|
222
|
+
ctx?: TxContext,
|
|
223
|
+
): Promise<SellableAttribute> {
|
|
224
|
+
const existing = await this.findAttributeByLocale(entityId, locale, ctx);
|
|
225
|
+
if (existing) {
|
|
226
|
+
const updated = await this.updateAttribute(existing.id, data, ctx);
|
|
227
|
+
return updated!;
|
|
228
|
+
}
|
|
229
|
+
return this.createAttribute({ ...data, entityId, locale }, ctx);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async deleteAttributesByEntityId(
|
|
233
|
+
entityId: string,
|
|
234
|
+
ctx?: TxContext,
|
|
235
|
+
): Promise<void> {
|
|
236
|
+
const db = this.getDb(ctx);
|
|
237
|
+
await db
|
|
238
|
+
.delete(sellableAttributes)
|
|
239
|
+
.where(eq(sellableAttributes.entityId, entityId));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
243
|
+
// Custom Fields
|
|
244
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
245
|
+
|
|
246
|
+
async findCustomFieldsByEntityId(
|
|
247
|
+
entityId: string,
|
|
248
|
+
ctx?: TxContext,
|
|
249
|
+
): Promise<SellableCustomField[]> {
|
|
250
|
+
const db = this.getDb(ctx);
|
|
251
|
+
return db
|
|
252
|
+
.select()
|
|
253
|
+
.from(sellableCustomFields)
|
|
254
|
+
.where(eq(sellableCustomFields.entityId, entityId));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async createCustomField(
|
|
258
|
+
data: SellableCustomFieldInsert,
|
|
259
|
+
ctx?: TxContext,
|
|
260
|
+
): Promise<SellableCustomField> {
|
|
261
|
+
const db = this.getDb(ctx);
|
|
262
|
+
const rows = await db.insert(sellableCustomFields).values(data).returning();
|
|
263
|
+
return rows[0]!;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async deleteCustomFieldsByEntityId(
|
|
267
|
+
entityId: string,
|
|
268
|
+
ctx?: TxContext,
|
|
269
|
+
): Promise<void> {
|
|
270
|
+
const db = this.getDb(ctx);
|
|
271
|
+
await db
|
|
272
|
+
.delete(sellableCustomFields)
|
|
273
|
+
.where(eq(sellableCustomFields.entityId, entityId));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
277
|
+
// Categories
|
|
278
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
279
|
+
|
|
280
|
+
async findCategoryById(
|
|
281
|
+
id: string,
|
|
282
|
+
ctx?: TxContext,
|
|
283
|
+
): Promise<Category | undefined> {
|
|
284
|
+
const db = this.getDb(ctx);
|
|
285
|
+
const rows = await db
|
|
286
|
+
.select()
|
|
287
|
+
.from(categories)
|
|
288
|
+
.where(eq(categories.id, id));
|
|
289
|
+
return rows[0];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async findCategoryBySlug(
|
|
293
|
+
orgId: string,
|
|
294
|
+
slug: string,
|
|
295
|
+
ctx?: TxContext,
|
|
296
|
+
): Promise<Category | undefined> {
|
|
297
|
+
const db = this.getDb(ctx);
|
|
298
|
+
const rows = await db
|
|
299
|
+
.select()
|
|
300
|
+
.from(categories)
|
|
301
|
+
.where(
|
|
302
|
+
and(
|
|
303
|
+
eq(categories.organizationId, orgId),
|
|
304
|
+
eq(categories.slug, slug),
|
|
305
|
+
),
|
|
306
|
+
);
|
|
307
|
+
return rows[0];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async findAllCategories(
|
|
311
|
+
orgId: string,
|
|
312
|
+
ctx?: TxContext,
|
|
313
|
+
): Promise<Category[]> {
|
|
314
|
+
const db = this.getDb(ctx);
|
|
315
|
+
return db
|
|
316
|
+
.select()
|
|
317
|
+
.from(categories)
|
|
318
|
+
.where(eq(categories.organizationId, orgId));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async createCategory(
|
|
322
|
+
data: CategoryInsert,
|
|
323
|
+
ctx?: TxContext,
|
|
324
|
+
): Promise<Category> {
|
|
325
|
+
const db = this.getDb(ctx);
|
|
326
|
+
const rows = await db.insert(categories).values(data).returning();
|
|
327
|
+
return rows[0]!;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async updateCategory(
|
|
331
|
+
id: string,
|
|
332
|
+
data: Partial<Omit<CategoryInsert, "id">>,
|
|
333
|
+
ctx?: TxContext,
|
|
334
|
+
): Promise<Category | undefined> {
|
|
335
|
+
const db = this.getDb(ctx);
|
|
336
|
+
const rows = await db
|
|
337
|
+
.update(categories)
|
|
338
|
+
.set(data)
|
|
339
|
+
.where(eq(categories.id, id))
|
|
340
|
+
.returning();
|
|
341
|
+
return rows[0];
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async deleteCategory(id: string, ctx?: TxContext): Promise<boolean> {
|
|
345
|
+
const db = this.getDb(ctx);
|
|
346
|
+
const result = await db
|
|
347
|
+
.delete(categories)
|
|
348
|
+
.where(eq(categories.id, id))
|
|
349
|
+
.returning();
|
|
350
|
+
return result.length > 0;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
354
|
+
// Entity Categories (Join Table)
|
|
355
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
356
|
+
|
|
357
|
+
async findEntityCategories(
|
|
358
|
+
entityId: string,
|
|
359
|
+
ctx?: TxContext,
|
|
360
|
+
): Promise<EntityCategory[]> {
|
|
361
|
+
const db = this.getDb(ctx);
|
|
362
|
+
return db
|
|
363
|
+
.select()
|
|
364
|
+
.from(entityCategories)
|
|
365
|
+
.where(eq(entityCategories.entityId, entityId));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async findEntitiesByCategory(
|
|
369
|
+
categoryId: string,
|
|
370
|
+
ctx?: TxContext,
|
|
371
|
+
): Promise<string[]> {
|
|
372
|
+
const db = this.getDb(ctx);
|
|
373
|
+
const rows = await db
|
|
374
|
+
.select()
|
|
375
|
+
.from(entityCategories)
|
|
376
|
+
.where(eq(entityCategories.categoryId, categoryId));
|
|
377
|
+
return rows.map((r) => r.entityId);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async addEntityToCategory(
|
|
381
|
+
entityId: string,
|
|
382
|
+
categoryId: string,
|
|
383
|
+
sortOrder = 0,
|
|
384
|
+
ctx?: TxContext,
|
|
385
|
+
): Promise<void> {
|
|
386
|
+
const db = this.getDb(ctx);
|
|
387
|
+
await db
|
|
388
|
+
.insert(entityCategories)
|
|
389
|
+
.values({ entityId, categoryId, sortOrder })
|
|
390
|
+
.onConflictDoNothing();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
async removeEntityFromCategory(
|
|
394
|
+
entityId: string,
|
|
395
|
+
categoryId: string,
|
|
396
|
+
ctx?: TxContext,
|
|
397
|
+
): Promise<boolean> {
|
|
398
|
+
const db = this.getDb(ctx);
|
|
399
|
+
const result = await db
|
|
400
|
+
.delete(entityCategories)
|
|
401
|
+
.where(
|
|
402
|
+
and(
|
|
403
|
+
eq(entityCategories.entityId, entityId),
|
|
404
|
+
eq(entityCategories.categoryId, categoryId),
|
|
405
|
+
),
|
|
406
|
+
)
|
|
407
|
+
.returning();
|
|
408
|
+
return result.length > 0;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async deleteEntityCategoriesByEntityId(
|
|
412
|
+
entityId: string,
|
|
413
|
+
ctx?: TxContext,
|
|
414
|
+
): Promise<void> {
|
|
415
|
+
const db = this.getDb(ctx);
|
|
416
|
+
await db
|
|
417
|
+
.delete(entityCategories)
|
|
418
|
+
.where(eq(entityCategories.entityId, entityId));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async deleteEntityCategoriesByCategoryId(
|
|
422
|
+
categoryId: string,
|
|
423
|
+
ctx?: TxContext,
|
|
424
|
+
): Promise<void> {
|
|
425
|
+
const db = this.getDb(ctx);
|
|
426
|
+
await db
|
|
427
|
+
.delete(entityCategories)
|
|
428
|
+
.where(eq(entityCategories.categoryId, categoryId));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
432
|
+
// Brands
|
|
433
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
434
|
+
|
|
435
|
+
async findBrandById(id: string, ctx?: TxContext): Promise<Brand | undefined> {
|
|
436
|
+
const db = this.getDb(ctx);
|
|
437
|
+
const rows = await db.select().from(brands).where(eq(brands.id, id));
|
|
438
|
+
return rows[0];
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async findBrandBySlug(
|
|
442
|
+
orgId: string,
|
|
443
|
+
slug: string,
|
|
444
|
+
ctx?: TxContext,
|
|
445
|
+
): Promise<Brand | undefined> {
|
|
446
|
+
const db = this.getDb(ctx);
|
|
447
|
+
const rows = await db
|
|
448
|
+
.select()
|
|
449
|
+
.from(brands)
|
|
450
|
+
.where(
|
|
451
|
+
and(
|
|
452
|
+
eq(brands.organizationId, orgId),
|
|
453
|
+
eq(brands.slug, slug),
|
|
454
|
+
),
|
|
455
|
+
);
|
|
456
|
+
return rows[0];
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
async findAllBrands(orgId: string, ctx?: TxContext): Promise<Brand[]> {
|
|
460
|
+
const db = this.getDb(ctx);
|
|
461
|
+
return db
|
|
462
|
+
.select()
|
|
463
|
+
.from(brands)
|
|
464
|
+
.where(eq(brands.organizationId, orgId));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
async createBrand(data: BrandInsert, ctx?: TxContext): Promise<Brand> {
|
|
468
|
+
const db = this.getDb(ctx);
|
|
469
|
+
const rows = await db.insert(brands).values(data).returning();
|
|
470
|
+
return rows[0]!;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
async updateBrand(
|
|
474
|
+
id: string,
|
|
475
|
+
data: Partial<Omit<BrandInsert, "id">>,
|
|
476
|
+
ctx?: TxContext,
|
|
477
|
+
): Promise<Brand | undefined> {
|
|
478
|
+
const db = this.getDb(ctx);
|
|
479
|
+
const rows = await db
|
|
480
|
+
.update(brands)
|
|
481
|
+
.set(data)
|
|
482
|
+
.where(eq(brands.id, id))
|
|
483
|
+
.returning();
|
|
484
|
+
return rows[0];
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
async deleteBrand(id: string, ctx?: TxContext): Promise<boolean> {
|
|
488
|
+
const db = this.getDb(ctx);
|
|
489
|
+
const result = await db.delete(brands).where(eq(brands.id, id)).returning();
|
|
490
|
+
return result.length > 0;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
494
|
+
// Entity Brands (Join Table)
|
|
495
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
496
|
+
|
|
497
|
+
async findEntityBrands(
|
|
498
|
+
entityId: string,
|
|
499
|
+
ctx?: TxContext,
|
|
500
|
+
): Promise<EntityBrand[]> {
|
|
501
|
+
const db = this.getDb(ctx);
|
|
502
|
+
return db
|
|
503
|
+
.select()
|
|
504
|
+
.from(entityBrands)
|
|
505
|
+
.where(eq(entityBrands.entityId, entityId));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
async addEntityToBrand(
|
|
509
|
+
entityId: string,
|
|
510
|
+
brandId: string,
|
|
511
|
+
sortOrder = 0,
|
|
512
|
+
ctx?: TxContext,
|
|
513
|
+
): Promise<void> {
|
|
514
|
+
const db = this.getDb(ctx);
|
|
515
|
+
await db
|
|
516
|
+
.insert(entityBrands)
|
|
517
|
+
.values({ entityId, brandId, sortOrder })
|
|
518
|
+
.onConflictDoNothing();
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
async removeEntityFromBrand(
|
|
522
|
+
entityId: string,
|
|
523
|
+
brandId: string,
|
|
524
|
+
ctx?: TxContext,
|
|
525
|
+
): Promise<boolean> {
|
|
526
|
+
const db = this.getDb(ctx);
|
|
527
|
+
const result = await db
|
|
528
|
+
.delete(entityBrands)
|
|
529
|
+
.where(
|
|
530
|
+
and(
|
|
531
|
+
eq(entityBrands.entityId, entityId),
|
|
532
|
+
eq(entityBrands.brandId, brandId),
|
|
533
|
+
),
|
|
534
|
+
)
|
|
535
|
+
.returning();
|
|
536
|
+
return result.length > 0;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
async deleteEntityBrandsByEntityId(
|
|
540
|
+
entityId: string,
|
|
541
|
+
ctx?: TxContext,
|
|
542
|
+
): Promise<void> {
|
|
543
|
+
const db = this.getDb(ctx);
|
|
544
|
+
await db.delete(entityBrands).where(eq(entityBrands.entityId, entityId));
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
async deleteEntityBrandsByBrandId(
|
|
548
|
+
brandId: string,
|
|
549
|
+
ctx?: TxContext,
|
|
550
|
+
): Promise<void> {
|
|
551
|
+
const db = this.getDb(ctx);
|
|
552
|
+
await db.delete(entityBrands).where(eq(entityBrands.brandId, brandId));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
556
|
+
// Option Types
|
|
557
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
558
|
+
|
|
559
|
+
async findOptionTypesByEntityId(
|
|
560
|
+
entityId: string,
|
|
561
|
+
ctx?: TxContext,
|
|
562
|
+
): Promise<OptionType[]> {
|
|
563
|
+
const db = this.getDb(ctx);
|
|
564
|
+
return db
|
|
565
|
+
.select()
|
|
566
|
+
.from(optionTypes)
|
|
567
|
+
.where(eq(optionTypes.entityId, entityId));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
async findOptionTypeById(
|
|
571
|
+
id: string,
|
|
572
|
+
ctx?: TxContext,
|
|
573
|
+
): Promise<OptionType | undefined> {
|
|
574
|
+
const db = this.getDb(ctx);
|
|
575
|
+
const rows = await db
|
|
576
|
+
.select()
|
|
577
|
+
.from(optionTypes)
|
|
578
|
+
.where(eq(optionTypes.id, id));
|
|
579
|
+
return rows[0];
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
async createOptionType(
|
|
583
|
+
data: OptionTypeInsert,
|
|
584
|
+
ctx?: TxContext,
|
|
585
|
+
): Promise<OptionType> {
|
|
586
|
+
const db = this.getDb(ctx);
|
|
587
|
+
const rows = await db.insert(optionTypes).values(data).returning();
|
|
588
|
+
return rows[0]!;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
async deleteOptionTypesByEntityId(
|
|
592
|
+
entityId: string,
|
|
593
|
+
ctx?: TxContext,
|
|
594
|
+
): Promise<void> {
|
|
595
|
+
const db = this.getDb(ctx);
|
|
596
|
+
await db.delete(optionTypes).where(eq(optionTypes.entityId, entityId));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
600
|
+
// Option Values
|
|
601
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
602
|
+
|
|
603
|
+
async findOptionValuesByTypeId(
|
|
604
|
+
optionTypeId: string,
|
|
605
|
+
ctx?: TxContext,
|
|
606
|
+
): Promise<OptionValue[]> {
|
|
607
|
+
const db = this.getDb(ctx);
|
|
608
|
+
return db
|
|
609
|
+
.select()
|
|
610
|
+
.from(optionValues)
|
|
611
|
+
.where(eq(optionValues.optionTypeId, optionTypeId));
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
async findOptionValueById(
|
|
615
|
+
id: string,
|
|
616
|
+
ctx?: TxContext,
|
|
617
|
+
): Promise<OptionValue | undefined> {
|
|
618
|
+
const db = this.getDb(ctx);
|
|
619
|
+
const rows = await db
|
|
620
|
+
.select()
|
|
621
|
+
.from(optionValues)
|
|
622
|
+
.where(eq(optionValues.id, id));
|
|
623
|
+
return rows[0];
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
async findOptionValuesByIds(
|
|
627
|
+
ids: string[],
|
|
628
|
+
ctx?: TxContext,
|
|
629
|
+
): Promise<OptionValue[]> {
|
|
630
|
+
if (ids.length === 0) return [];
|
|
631
|
+
const db = this.getDb(ctx);
|
|
632
|
+
return db.select().from(optionValues).where(inArray(optionValues.id, ids));
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
async createOptionValue(
|
|
636
|
+
data: OptionValueInsert,
|
|
637
|
+
ctx?: TxContext,
|
|
638
|
+
): Promise<OptionValue> {
|
|
639
|
+
const db = this.getDb(ctx);
|
|
640
|
+
const rows = await db.insert(optionValues).values(data).returning();
|
|
641
|
+
return rows[0]!;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
async deleteOptionValuesByTypeId(
|
|
645
|
+
optionTypeId: string,
|
|
646
|
+
ctx?: TxContext,
|
|
647
|
+
): Promise<void> {
|
|
648
|
+
const db = this.getDb(ctx);
|
|
649
|
+
await db
|
|
650
|
+
.delete(optionValues)
|
|
651
|
+
.where(eq(optionValues.optionTypeId, optionTypeId));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
655
|
+
// Variants
|
|
656
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
657
|
+
|
|
658
|
+
async findVariantsByEntityId(
|
|
659
|
+
entityId: string,
|
|
660
|
+
ctx?: TxContext,
|
|
661
|
+
): Promise<Variant[]> {
|
|
662
|
+
const db = this.getDb(ctx);
|
|
663
|
+
return db.select().from(variants).where(eq(variants.entityId, entityId));
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
async findVariantById(
|
|
667
|
+
id: string,
|
|
668
|
+
ctx?: TxContext,
|
|
669
|
+
): Promise<Variant | undefined> {
|
|
670
|
+
const db = this.getDb(ctx);
|
|
671
|
+
const rows = await db.select().from(variants).where(eq(variants.id, id));
|
|
672
|
+
return rows[0];
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
async findVariantBySku(
|
|
676
|
+
sku: string,
|
|
677
|
+
ctx?: TxContext,
|
|
678
|
+
): Promise<Variant | undefined> {
|
|
679
|
+
const db = this.getDb(ctx);
|
|
680
|
+
const rows = await db.select().from(variants).where(eq(variants.sku, sku));
|
|
681
|
+
return rows[0];
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
async findVariantByBarcode(
|
|
685
|
+
barcode: string,
|
|
686
|
+
ctx?: TxContext,
|
|
687
|
+
): Promise<Variant | undefined> {
|
|
688
|
+
const db = this.getDb(ctx);
|
|
689
|
+
const rows = await db
|
|
690
|
+
.select()
|
|
691
|
+
.from(variants)
|
|
692
|
+
.where(eq(variants.barcode, barcode));
|
|
693
|
+
return rows[0];
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
async createVariant(data: VariantInsert, ctx?: TxContext): Promise<Variant> {
|
|
697
|
+
const db = this.getDb(ctx);
|
|
698
|
+
const rows = await db.insert(variants).values(data).returning();
|
|
699
|
+
return rows[0]!;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
async updateVariant(
|
|
703
|
+
id: string,
|
|
704
|
+
data: Partial<Omit<VariantInsert, "id">>,
|
|
705
|
+
ctx?: TxContext,
|
|
706
|
+
): Promise<Variant | undefined> {
|
|
707
|
+
const db = this.getDb(ctx);
|
|
708
|
+
const rows = await db
|
|
709
|
+
.update(variants)
|
|
710
|
+
.set(data)
|
|
711
|
+
.where(eq(variants.id, id))
|
|
712
|
+
.returning();
|
|
713
|
+
return rows[0];
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
async deleteVariantsByEntityId(
|
|
717
|
+
entityId: string,
|
|
718
|
+
ctx?: TxContext,
|
|
719
|
+
): Promise<void> {
|
|
720
|
+
const db = this.getDb(ctx);
|
|
721
|
+
await db.delete(variants).where(eq(variants.entityId, entityId));
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
725
|
+
// Variant Option Values (Join Table)
|
|
726
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
727
|
+
|
|
728
|
+
async findVariantOptionValues(
|
|
729
|
+
variantId: string,
|
|
730
|
+
ctx?: TxContext,
|
|
731
|
+
): Promise<VariantOptionValue[]> {
|
|
732
|
+
const db = this.getDb(ctx);
|
|
733
|
+
return db
|
|
734
|
+
.select()
|
|
735
|
+
.from(variantOptionValues)
|
|
736
|
+
.where(eq(variantOptionValues.variantId, variantId));
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
async createVariantOptionValues(
|
|
740
|
+
data: VariantOptionValueInsert[],
|
|
741
|
+
ctx?: TxContext,
|
|
742
|
+
): Promise<void> {
|
|
743
|
+
if (data.length === 0) return;
|
|
744
|
+
const db = this.getDb(ctx);
|
|
745
|
+
await db.insert(variantOptionValues).values(data).onConflictDoNothing();
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
async deleteVariantOptionValuesByVariantId(
|
|
749
|
+
variantId: string,
|
|
750
|
+
ctx?: TxContext,
|
|
751
|
+
): Promise<void> {
|
|
752
|
+
const db = this.getDb(ctx);
|
|
753
|
+
await db
|
|
754
|
+
.delete(variantOptionValues)
|
|
755
|
+
.where(eq(variantOptionValues.variantId, variantId));
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
async deleteVariantOptionValuesByEntityId(
|
|
759
|
+
entityId: string,
|
|
760
|
+
ctx?: TxContext,
|
|
761
|
+
): Promise<void> {
|
|
762
|
+
const db = this.getDb(ctx);
|
|
763
|
+
// Get all variant IDs for this entity first
|
|
764
|
+
const entityVariants = await this.findVariantsByEntityId(entityId, ctx);
|
|
765
|
+
const variantIds = entityVariants.map((v) => v.id);
|
|
766
|
+
if (variantIds.length > 0) {
|
|
767
|
+
await db
|
|
768
|
+
.delete(variantOptionValues)
|
|
769
|
+
.where(inArray(variantOptionValues.variantId, variantIds));
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|