@porulle/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -0
- package/dist/adapters/console-email.d.ts +23 -0
- package/dist/adapters/console-email.d.ts.map +1 -0
- package/dist/adapters/console-email.js +38 -0
- package/dist/auth/access.d.ts +101 -0
- package/dist/auth/access.d.ts.map +1 -0
- package/dist/auth/access.js +128 -0
- package/dist/auth/auth-schema.d.ts +1475 -0
- package/dist/auth/auth-schema.d.ts.map +1 -0
- package/dist/auth/auth-schema.js +124 -0
- package/dist/auth/middleware.d.ts +5 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +220 -0
- package/dist/auth/org.d.ts +28 -0
- package/dist/auth/org.d.ts.map +1 -0
- package/dist/auth/org.js +68 -0
- package/dist/auth/permissions.d.ts +4 -0
- package/dist/auth/permissions.d.ts.map +1 -0
- package/dist/auth/permissions.js +24 -0
- package/dist/auth/setup.d.ts +29 -0
- package/dist/auth/setup.d.ts.map +1 -0
- package/dist/auth/setup.js +137 -0
- package/dist/auth/strict-org-resolution.d.ts +4 -0
- package/dist/auth/strict-org-resolution.d.ts.map +1 -0
- package/dist/auth/strict-org-resolution.js +13 -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 +83 -0
- package/dist/config/define-config.d.ts +10 -0
- package/dist/config/define-config.d.ts.map +1 -0
- package/dist/config/define-config.js +64 -0
- package/dist/config/types.d.ts +412 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +1 -0
- package/dist/drizzle.d.ts +28 -0
- package/dist/drizzle.d.ts.map +1 -0
- package/dist/drizzle.js +24 -0
- package/dist/generated/plugin-manifest.d.ts +45 -0
- package/dist/generated/plugin-manifest.d.ts.map +1 -0
- package/dist/generated/plugin-manifest.js +19 -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 +146 -0
- package/dist/hooks/checkout.d.ts +99 -0
- package/dist/hooks/checkout.d.ts.map +1 -0
- package/dist/hooks/checkout.js +331 -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 +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -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 +94 -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/compensation-failures.d.ts +5 -0
- package/dist/interfaces/rest/routes/admin/compensation-failures.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/admin/compensation-failures.js +114 -0
- package/dist/interfaces/rest/routes/admin/permissions.d.ts +5 -0
- package/dist/interfaces/rest/routes/admin/permissions.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/admin/permissions.js +28 -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 +61 -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 +269 -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 +220 -0
- package/dist/interfaces/rest/routes/customers.d.ts +5 -0
- package/dist/interfaces/rest/routes/customers.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/customers.js +78 -0
- package/dist/interfaces/rest/routes/inventory.d.ts +5 -0
- package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/inventory.js +74 -0
- package/dist/interfaces/rest/routes/media.d.ts +5 -0
- package/dist/interfaces/rest/routes/media.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/media.js +66 -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 +61 -0
- package/dist/interfaces/rest/routes/promotions.d.ts +5 -0
- package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/promotions.js +76 -0
- package/dist/interfaces/rest/routes/search.d.ts +5 -0
- package/dist/interfaces/rest/routes/search.d.ts.map +1 -0
- package/dist/interfaces/rest/routes/search.js +72 -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/admin-permissions.d.ts +27 -0
- package/dist/interfaces/rest/schemas/admin-permissions.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/admin-permissions.js +25 -0
- package/dist/interfaces/rest/schemas/audit.d.ts +59 -0
- package/dist/interfaces/rest/schemas/audit.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/audit.js +43 -0
- package/dist/interfaces/rest/schemas/carts.d.ts +1456 -0
- package/dist/interfaces/rest/schemas/carts.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/carts.js +109 -0
- package/dist/interfaces/rest/schemas/catalog.d.ts +5452 -0
- package/dist/interfaces/rest/schemas/catalog.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/catalog.js +397 -0
- package/dist/interfaces/rest/schemas/checkout.d.ts +160 -0
- package/dist/interfaces/rest/schemas/checkout.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/checkout.js +60 -0
- package/dist/interfaces/rest/schemas/compensation-failures.d.ts +122 -0
- package/dist/interfaces/rest/schemas/compensation-failures.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/compensation-failures.js +84 -0
- package/dist/interfaces/rest/schemas/customer-portal.d.ts +2237 -0
- package/dist/interfaces/rest/schemas/customer-portal.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/customer-portal.js +177 -0
- package/dist/interfaces/rest/schemas/customers.d.ts +422 -0
- package/dist/interfaces/rest/schemas/customers.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/customers.js +150 -0
- package/dist/interfaces/rest/schemas/inventory.d.ts +561 -0
- package/dist/interfaces/rest/schemas/inventory.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/inventory.js +148 -0
- package/dist/interfaces/rest/schemas/media.d.ts +303 -0
- package/dist/interfaces/rest/schemas/media.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/media.js +69 -0
- package/dist/interfaces/rest/schemas/orders.d.ts +1877 -0
- package/dist/interfaces/rest/schemas/orders.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/orders.js +93 -0
- package/dist/interfaces/rest/schemas/pricing.d.ts +256 -0
- package/dist/interfaces/rest/schemas/pricing.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/pricing.js +72 -0
- package/dist/interfaces/rest/schemas/promotions.d.ts +374 -0
- package/dist/interfaces/rest/schemas/promotions.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/promotions.js +104 -0
- package/dist/interfaces/rest/schemas/responses.d.ts +4138 -0
- package/dist/interfaces/rest/schemas/responses.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/responses.js +74 -0
- package/dist/interfaces/rest/schemas/search.d.ts +247 -0
- package/dist/interfaces/rest/schemas/search.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/search.js +55 -0
- package/dist/interfaces/rest/schemas/shared.d.ts +95 -0
- package/dist/interfaces/rest/schemas/shared.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/shared.js +51 -0
- package/dist/interfaces/rest/schemas/webhooks.d.ts +221 -0
- package/dist/interfaces/rest/schemas/webhooks.d.ts.map +1 -0
- package/dist/interfaces/rest/schemas/webhooks.js +62 -0
- package/dist/interfaces/rest/utils.d.ts +45 -0
- package/dist/interfaces/rest/utils.d.ts.map +1 -0
- package/dist/interfaces/rest/utils.js +71 -0
- package/dist/interfaces/rest/webhook-router.d.ts +41 -0
- package/dist/interfaces/rest/webhook-router.d.ts.map +1 -0
- package/dist/interfaces/rest/webhook-router.js +36 -0
- package/dist/kernel/compensation/executor.d.ts +21 -0
- package/dist/kernel/compensation/executor.d.ts.map +1 -0
- package/dist/kernel/compensation/executor.js +80 -0
- package/dist/kernel/compensation/repository.d.ts +47 -0
- package/dist/kernel/compensation/repository.d.ts.map +1 -0
- package/dist/kernel/compensation/repository.js +93 -0
- package/dist/kernel/compensation/schema.d.ts +217 -0
- package/dist/kernel/compensation/schema.d.ts.map +1 -0
- package/dist/kernel/compensation/schema.js +29 -0
- package/dist/kernel/compensation/types.d.ts +29 -0
- package/dist/kernel/compensation/types.d.ts.map +1 -0
- package/dist/kernel/compensation/types.js +1 -0
- package/dist/kernel/database/adapter.d.ts +18 -0
- package/dist/kernel/database/adapter.d.ts.map +1 -0
- package/dist/kernel/database/adapter.js +3 -0
- package/dist/kernel/database/drizzle-db.d.ts +49 -0
- package/dist/kernel/database/drizzle-db.d.ts.map +1 -0
- package/dist/kernel/database/drizzle-db.js +20 -0
- package/dist/kernel/database/migrate.d.ts +38 -0
- package/dist/kernel/database/migrate.d.ts.map +1 -0
- package/dist/kernel/database/migrate.js +61 -0
- package/dist/kernel/database/plugin-db-context.d.ts +3 -0
- package/dist/kernel/database/plugin-db-context.d.ts.map +1 -0
- package/dist/kernel/database/plugin-db-context.js +8 -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 +26 -0
- package/dist/kernel/database/schema.d.ts.map +1 -0
- package/dist/kernel/database/schema.js +39 -0
- package/dist/kernel/database/scoped-db.d.ts +14 -0
- package/dist/kernel/database/scoped-db.d.ts.map +1 -0
- package/dist/kernel/database/scoped-db.js +103 -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 +14 -0
- package/dist/kernel/error-mapper.d.ts.map +1 -0
- package/dist/kernel/error-mapper.js +93 -0
- package/dist/kernel/errors.d.ts +43 -0
- package/dist/kernel/errors.d.ts.map +1 -0
- package/dist/kernel/errors.js +78 -0
- package/dist/kernel/factory/repository-factory.d.ts +71 -0
- package/dist/kernel/factory/repository-factory.d.ts.map +1 -0
- package/dist/kernel/factory/repository-factory.js +138 -0
- package/dist/kernel/hooks/create-context.d.ts +32 -0
- package/dist/kernel/hooks/create-context.d.ts.map +1 -0
- package/dist/kernel/hooks/create-context.js +23 -0
- package/dist/kernel/hooks/executor.d.ts +13 -0
- package/dist/kernel/hooks/executor.d.ts.map +1 -0
- package/dist/kernel/hooks/executor.js +56 -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 +40 -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/builtin-job-tasks.d.ts +3 -0
- package/dist/kernel/jobs/builtin-job-tasks.d.ts.map +1 -0
- package/dist/kernel/jobs/builtin-job-tasks.js +6 -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 +46 -0
- package/dist/kernel/jobs/reaper.d.ts +12 -0
- package/dist/kernel/jobs/reaper.d.ts.map +1 -0
- package/dist/kernel/jobs/reaper.js +62 -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 +118 -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 +40 -0
- package/dist/kernel/jobs/types.d.ts.map +1 -0
- package/dist/kernel/jobs/types.js +4 -0
- package/dist/kernel/local-api.d.ts +104 -0
- package/dist/kernel/local-api.d.ts.map +1 -0
- package/dist/kernel/local-api.js +89 -0
- package/dist/kernel/module/define.d.ts +21 -0
- package/dist/kernel/module/define.d.ts.map +1 -0
- package/dist/kernel/module/define.js +3 -0
- package/dist/kernel/module/index.d.ts +4 -0
- package/dist/kernel/module/index.d.ts.map +1 -0
- package/dist/kernel/module/index.js +2 -0
- package/dist/kernel/module/topo-sort.d.ts +7 -0
- package/dist/kernel/module/topo-sort.d.ts.map +1 -0
- package/dist/kernel/module/topo-sort.js +89 -0
- package/dist/kernel/plugin/manifest.d.ts +84 -0
- package/dist/kernel/plugin/manifest.d.ts.map +1 -0
- package/dist/kernel/plugin/manifest.js +196 -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/service-registry.d.ts +109 -0
- package/dist/kernel/service-registry.d.ts.map +1 -0
- package/dist/kernel/service-registry.js +26 -0
- package/dist/kernel/service-timing.d.ts +25 -0
- package/dist/kernel/service-timing.d.ts.map +1 -0
- package/dist/kernel/service-timing.js +62 -0
- package/dist/kernel/state-machine/machine.d.ts +24 -0
- package/dist/kernel/state-machine/machine.d.ts.map +1 -0
- package/dist/kernel/state-machine/machine.js +70 -0
- package/dist/modules/analytics/drizzle-adapter.d.ts +13 -0
- package/dist/modules/analytics/drizzle-adapter.d.ts.map +1 -0
- package/dist/modules/analytics/drizzle-adapter.js +358 -0
- package/dist/modules/analytics/hooks.d.ts +13 -0
- package/dist/modules/analytics/hooks.d.ts.map +1 -0
- package/dist/modules/analytics/hooks.js +12 -0
- package/dist/modules/analytics/models.d.ts +14 -0
- package/dist/modules/analytics/models.d.ts.map +1 -0
- package/dist/modules/analytics/models.js +118 -0
- package/dist/modules/analytics/module.d.ts +3 -0
- package/dist/modules/analytics/module.d.ts.map +1 -0
- package/dist/modules/analytics/module.js +18 -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/index.d.ts +2 -0
- package/dist/modules/audit/index.d.ts.map +1 -0
- package/dist/modules/audit/index.js +1 -0
- package/dist/modules/audit/module.d.ts +180 -0
- package/dist/modules/audit/module.d.ts.map +1 -0
- package/dist/modules/audit/module.js +8 -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/module.d.ts +14 -0
- package/dist/modules/cart/module.d.ts.map +1 -0
- package/dist/modules/cart/module.js +17 -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 +87 -0
- package/dist/modules/cart/service.d.ts.map +1 -0
- package/dist/modules/cart/service.js +454 -0
- package/dist/modules/catalog/brand-service.d.ts +18 -0
- package/dist/modules/catalog/brand-service.d.ts.map +1 -0
- package/dist/modules/catalog/brand-service.js +126 -0
- package/dist/modules/catalog/category-service.d.ts +17 -0
- package/dist/modules/catalog/category-service.d.ts.map +1 -0
- package/dist/modules/catalog/category-service.js +128 -0
- package/dist/modules/catalog/entity-service.d.ts +30 -0
- package/dist/modules/catalog/entity-service.d.ts.map +1 -0
- package/dist/modules/catalog/entity-service.js +481 -0
- package/dist/modules/catalog/module.d.ts +21 -0
- package/dist/modules/catalog/module.d.ts.map +1 -0
- package/dist/modules/catalog/module.js +28 -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 +459 -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 +167 -0
- package/dist/modules/catalog/service.d.ts.map +1 -0
- package/dist/modules/catalog/service.js +96 -0
- package/dist/modules/customers/index.d.ts +2 -0
- package/dist/modules/customers/index.d.ts.map +1 -0
- package/dist/modules/customers/index.js +1 -0
- package/dist/modules/customers/module.d.ts +563 -0
- package/dist/modules/customers/module.d.ts.map +1 -0
- package/dist/modules/customers/module.js +19 -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 +32 -0
- package/dist/modules/customers/service.d.ts.map +1 -0
- package/dist/modules/customers/service.js +132 -0
- package/dist/modules/fulfillment/module.d.ts +13 -0
- package/dist/modules/fulfillment/module.d.ts.map +1 -0
- package/dist/modules/fulfillment/module.js +22 -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 +63 -0
- package/dist/modules/fulfillment/service.d.ts.map +1 -0
- package/dist/modules/fulfillment/service.js +351 -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/module.d.ts +13 -0
- package/dist/modules/inventory/module.d.ts.map +1 -0
- package/dist/modules/inventory/module.js +20 -0
- package/dist/modules/inventory/repository/index.d.ts +96 -0
- package/dist/modules/inventory/repository/index.d.ts.map +1 -0
- package/dist/modules/inventory/repository/index.js +361 -0
- package/dist/modules/inventory/schema.d.ts +604 -0
- package/dist/modules/inventory/schema.d.ts.map +1 -0
- package/dist/modules/inventory/schema.js +78 -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 +70 -0
- package/dist/modules/inventory/service.d.ts.map +1 -0
- package/dist/modules/inventory/service.js +284 -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/index.d.ts +2 -0
- package/dist/modules/media/index.d.ts.map +1 -0
- package/dist/modules/media/index.js +1 -0
- package/dist/modules/media/module.d.ts +292 -0
- package/dist/modules/media/module.d.ts.map +1 -0
- package/dist/modules/media/module.js +22 -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 +45 -0
- package/dist/modules/media/service.d.ts.map +1 -0
- package/dist/modules/media/service.js +149 -0
- package/dist/modules/orders/module.d.ts +25 -0
- package/dist/modules/orders/module.d.ts.map +1 -0
- package/dist/modules/orders/module.js +32 -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 +204 -0
- package/dist/modules/orders/schema.d.ts +689 -0
- package/dist/modules/orders/schema.d.ts.map +1 -0
- package/dist/modules/orders/schema.js +64 -0
- package/dist/modules/orders/sequences.d.ts +2 -0
- package/dist/modules/orders/sequences.d.ts.map +1 -0
- package/dist/modules/orders/sequences.js +5 -0
- package/dist/modules/orders/service.d.ts +81 -0
- package/dist/modules/orders/service.d.ts.map +1 -0
- package/dist/modules/orders/service.js +325 -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/index.d.ts +2 -0
- package/dist/modules/organization/index.d.ts.map +1 -0
- package/dist/modules/organization/index.js +1 -0
- package/dist/modules/organization/module.d.ts +205 -0
- package/dist/modules/organization/module.d.ts.map +1 -0
- package/dist/modules/organization/module.js +8 -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 +40 -0
- package/dist/modules/payments/adapter.d.ts.map +1 -0
- package/dist/modules/payments/adapter.js +1 -0
- package/dist/modules/payments/module.d.ts +3 -0
- package/dist/modules/payments/module.d.ts.map +1 -0
- package/dist/modules/payments/module.js +7 -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/index.d.ts +2 -0
- package/dist/modules/pricing/index.d.ts.map +1 -0
- package/dist/modules/pricing/index.js +1 -0
- package/dist/modules/pricing/module.d.ts +14 -0
- package/dist/modules/pricing/module.d.ts.map +1 -0
- package/dist/modules/pricing/module.js +16 -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 +179 -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 +67 -0
- package/dist/modules/pricing/service.d.ts.map +1 -0
- package/dist/modules/pricing/service.js +329 -0
- package/dist/modules/promotions/module.d.ts +14 -0
- package/dist/modules/promotions/module.d.ts.map +1 -0
- package/dist/modules/promotions/module.js +18 -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 +90 -0
- package/dist/modules/promotions/service.d.ts.map +1 -0
- package/dist/modules/promotions/service.js +387 -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/module.d.ts +8 -0
- package/dist/modules/search/module.d.ts.map +1 -0
- package/dist/modules/search/module.js +17 -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 +243 -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/module.d.ts +8 -0
- package/dist/modules/shipping/module.d.ts.map +1 -0
- package/dist/modules/shipping/module.js +11 -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/module.d.ts +3 -0
- package/dist/modules/tax/module.d.ts.map +1 -0
- package/dist/modules/tax/module.js +9 -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 +35 -0
- package/dist/modules/webhooks/index.d.ts +2 -0
- package/dist/modules/webhooks/index.d.ts.map +1 -0
- package/dist/modules/webhooks/index.js +1 -0
- package/dist/modules/webhooks/module.d.ts +403 -0
- package/dist/modules/webhooks/module.d.ts.map +1 -0
- package/dist/modules/webhooks/module.js +15 -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 +183 -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 +94 -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 +42 -0
- package/dist/modules/webhooks/worker.d.ts +28 -0
- package/dist/modules/webhooks/worker.d.ts.map +1 -0
- package/dist/modules/webhooks/worker.js +133 -0
- package/dist/runtime/commerce.d.ts +110 -0
- package/dist/runtime/commerce.d.ts.map +1 -0
- package/dist/runtime/commerce.js +48 -0
- package/dist/runtime/kernel-modules.d.ts +1714 -0
- package/dist/runtime/kernel-modules.d.ts.map +1 -0
- package/dist/runtime/kernel-modules.js +62 -0
- package/dist/runtime/kernel-register-hooks.d.ts +4 -0
- package/dist/runtime/kernel-register-hooks.d.ts.map +1 -0
- package/dist/runtime/kernel-register-hooks.js +46 -0
- package/dist/runtime/kernel-types.d.ts +65 -0
- package/dist/runtime/kernel-types.d.ts.map +1 -0
- package/dist/runtime/kernel-types.js +36 -0
- package/dist/runtime/kernel.d.ts +6 -0
- package/dist/runtime/kernel.d.ts.map +1 -0
- package/dist/runtime/kernel.js +113 -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 +37 -0
- package/dist/runtime/server.d.ts.map +1 -0
- package/dist/runtime/server.js +398 -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/url-alias-rewrite.d.ts +3 -0
- package/dist/runtime/url-alias-rewrite.d.ts.map +1 -0
- package/dist/runtime/url-alias-rewrite.js +33 -0
- package/dist/test-utils/create-pglite-adapter.d.ts +32 -0
- package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -0
- package/dist/test-utils/create-pglite-adapter.js +107 -0
- package/dist/test-utils/create-plugin-test-app.d.ts +50 -0
- package/dist/test-utils/create-plugin-test-app.d.ts.map +1 -0
- package/dist/test-utils/create-plugin-test-app.js +90 -0
- package/dist/test-utils/create-repository-test-harness.d.ts +8 -0
- package/dist/test-utils/create-repository-test-harness.d.ts.map +1 -0
- package/dist/test-utils/create-repository-test-harness.js +7 -0
- package/dist/test-utils/create-test-config.d.ts +18 -0
- package/dist/test-utils/create-test-config.d.ts.map +1 -0
- package/dist/test-utils/create-test-config.js +172 -0
- package/dist/test-utils/create-test-kernel.d.ts +3 -0
- package/dist/test-utils/create-test-kernel.d.ts.map +1 -0
- package/dist/test-utils/create-test-kernel.js +5 -0
- package/dist/test-utils/create-test-plugin-context.d.ts +38 -0
- package/dist/test-utils/create-test-plugin-context.d.ts.map +1 -0
- package/dist/test-utils/create-test-plugin-context.js +39 -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 +208 -0
- package/dist/test-utils/test-actors.d.ts +21 -0
- package/dist/test-utils/test-actors.d.ts.map +1 -0
- package/dist/test-utils/test-actors.js +64 -0
- package/dist/test-utils/typed-hooks.d.ts +44 -0
- package/dist/test-utils/typed-hooks.d.ts.map +1 -0
- package/dist/test-utils/typed-hooks.js +36 -0
- package/dist/testing.d.ts +15 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +13 -0
- package/dist/types/commerce-types.d.ts +34 -0
- package/dist/types/commerce-types.d.ts.map +1 -0
- package/dist/types/commerce-types.js +1 -0
- package/dist/utils/agent-prompt.d.ts +2 -0
- package/dist/utils/agent-prompt.d.ts.map +1 -0
- package/dist/utils/agent-prompt.js +12 -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 +89 -0
- package/src/adapters/console-email.ts +43 -0
- package/src/auth/access.ts +187 -0
- package/src/auth/auth-schema.ts +139 -0
- package/src/auth/middleware.ts +257 -0
- package/src/auth/org.ts +83 -0
- package/src/auth/permissions.ts +28 -0
- package/src/auth/setup.ts +187 -0
- package/src/auth/strict-org-resolution.ts +14 -0
- package/src/auth/system-actor.ts +19 -0
- package/src/auth/types.ts +10 -0
- package/src/config/defaults.ts +85 -0
- package/src/config/define-config.ts +81 -0
- package/src/config/types.ts +417 -0
- package/src/drizzle.ts +95 -0
- package/src/generated/plugin-capabilities.d.ts +19 -0
- package/src/generated/plugin-manifest.ts +22 -0
- package/src/generated/plugin-repositories.d.ts +19 -0
- package/src/hooks/checkout-completion.ts +285 -0
- package/src/hooks/checkout.ts +695 -0
- package/src/hooks/order-emails.ts +62 -0
- package/src/index.ts +213 -0
- package/src/interfaces/rest/customer-portal.ts +299 -0
- package/src/interfaces/rest/index.ts +105 -0
- package/src/interfaces/rest/router.ts +333 -0
- package/src/interfaces/rest/routes/admin/compensation-failures.ts +160 -0
- package/src/interfaces/rest/routes/admin/permissions.ts +37 -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 +100 -0
- package/src/interfaces/rest/routes/catalog.ts +508 -0
- package/src/interfaces/rest/routes/checkout.ts +289 -0
- package/src/interfaces/rest/routes/customers.ts +100 -0
- package/src/interfaces/rest/routes/inventory.ts +93 -0
- package/src/interfaces/rest/routes/media.ts +87 -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 +78 -0
- package/src/interfaces/rest/routes/promotions.ts +96 -0
- package/src/interfaces/rest/routes/search.ts +81 -0
- package/src/interfaces/rest/routes/webhooks.ts +49 -0
- package/src/interfaces/rest/schemas/admin-jobs.ts +40 -0
- package/src/interfaces/rest/schemas/admin-permissions.ts +27 -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/compensation-failures.ts +89 -0
- package/src/interfaces/rest/schemas/customer-portal.ts +195 -0
- package/src/interfaces/rest/schemas/customers.ts +155 -0
- package/src/interfaces/rest/schemas/inventory.ts +159 -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 +116 -0
- package/src/interfaces/rest/schemas/responses.ts +96 -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 +123 -0
- package/src/kernel/compensation/repository.ts +157 -0
- package/src/kernel/compensation/schema.ts +45 -0
- package/src/kernel/compensation/types.ts +30 -0
- package/src/kernel/database/adapter.ts +21 -0
- package/src/kernel/database/drizzle-db.ts +56 -0
- package/src/kernel/database/migrate.ts +76 -0
- package/src/kernel/database/plugin-db-context.ts +14 -0
- package/src/kernel/database/plugin-types.ts +34 -0
- package/src/kernel/database/schema.ts +53 -0
- package/src/kernel/database/scoped-db.ts +112 -0
- package/src/kernel/database/tx-context.ts +46 -0
- package/src/kernel/error-mapper.ts +118 -0
- package/src/kernel/errors.ts +100 -0
- package/src/kernel/factory/repository-factory.ts +244 -0
- package/src/kernel/hooks/create-context.ts +52 -0
- package/src/kernel/hooks/executor.ts +95 -0
- package/src/kernel/hooks/registry.ts +74 -0
- package/src/kernel/hooks/types.ts +55 -0
- package/src/kernel/http-error.ts +44 -0
- package/src/kernel/jobs/adapter.ts +36 -0
- package/src/kernel/jobs/builtin-job-tasks.ts +17 -0
- package/src/kernel/jobs/drizzle-adapter.ts +65 -0
- package/src/kernel/jobs/reaper.ts +95 -0
- package/src/kernel/jobs/runner.ts +157 -0
- package/src/kernel/jobs/schema.ts +46 -0
- package/src/kernel/jobs/types.ts +42 -0
- package/src/kernel/local-api.ts +188 -0
- package/src/kernel/module/define.ts +36 -0
- package/src/kernel/module/index.ts +3 -0
- package/src/kernel/module/topo-sort.ts +99 -0
- package/src/kernel/plugin/manifest.ts +310 -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/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/module.ts +25 -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/index.ts +1 -0
- package/src/modules/audit/module.ts +11 -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/module.ts +32 -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 +710 -0
- package/src/modules/catalog/brand-service.ts +101 -0
- package/src/modules/catalog/category-service.ts +103 -0
- package/src/modules/catalog/entity-service.ts +469 -0
- package/src/modules/catalog/module.ts +65 -0
- package/src/modules/catalog/repository/index.ts +777 -0
- package/src/modules/catalog/schema.ts +203 -0
- package/src/modules/catalog/schemas.ts +104 -0
- package/src/modules/catalog/service.ts +392 -0
- package/src/modules/customers/index.ts +1 -0
- package/src/modules/customers/module.ts +27 -0
- package/src/modules/customers/repository/index.ts +327 -0
- package/src/modules/customers/schema.ts +64 -0
- package/src/modules/customers/service.ts +276 -0
- package/src/modules/fulfillment/module.ts +42 -0
- package/src/modules/fulfillment/repository/index.ts +426 -0
- package/src/modules/fulfillment/schema.ts +101 -0
- package/src/modules/fulfillment/service.ts +581 -0
- package/src/modules/fulfillment/types.ts +59 -0
- package/src/modules/inventory/module.ts +37 -0
- package/src/modules/inventory/repository/index.ts +677 -0
- package/src/modules/inventory/schema.ts +107 -0
- package/src/modules/inventory/schemas.ts +38 -0
- package/src/modules/inventory/service.ts +567 -0
- package/src/modules/media/adapter.ts +17 -0
- package/src/modules/media/index.ts +1 -0
- package/src/modules/media/module.ts +25 -0
- package/src/modules/media/repository/index.ts +274 -0
- package/src/modules/media/schema.ts +41 -0
- package/src/modules/media/service.ts +237 -0
- package/src/modules/orders/module.ts +66 -0
- package/src/modules/orders/repository/index.ts +290 -0
- package/src/modules/orders/schema.ts +67 -0
- package/src/modules/orders/sequences.ts +6 -0
- package/src/modules/orders/service.ts +639 -0
- package/src/modules/orders/stale-order-cleanup.ts +76 -0
- package/src/modules/organization/index.ts +1 -0
- package/src/modules/organization/module.ts +11 -0
- package/src/modules/organization/service.ts +191 -0
- package/src/modules/payments/adapter.ts +45 -0
- package/src/modules/payments/module.ts +14 -0
- package/src/modules/payments/repository/index.ts +6 -0
- package/src/modules/payments/service.ts +107 -0
- package/src/modules/pricing/index.ts +1 -0
- package/src/modules/pricing/module.ts +30 -0
- package/src/modules/pricing/repository/index.ts +305 -0
- package/src/modules/pricing/schema.ts +71 -0
- package/src/modules/pricing/schemas.ts +38 -0
- package/src/modules/pricing/service.ts +557 -0
- package/src/modules/promotions/module.ts +32 -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 +674 -0
- package/src/modules/search/adapter.ts +57 -0
- package/src/modules/search/hooks.ts +12 -0
- package/src/modules/search/module.ts +26 -0
- package/src/modules/search/repository/index.ts +6 -0
- package/src/modules/search/service.ts +341 -0
- package/src/modules/shipping/calculator.ts +188 -0
- package/src/modules/shipping/module.ts +23 -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/module.ts +16 -0
- package/src/modules/tax/repository/index.ts +6 -0
- package/src/modules/tax/service.ts +53 -0
- package/src/modules/webhooks/hook.ts +41 -0
- package/src/modules/webhooks/index.ts +1 -0
- package/src/modules/webhooks/module.ts +22 -0
- package/src/modules/webhooks/repository/index.ts +304 -0
- package/src/modules/webhooks/schema.ts +56 -0
- package/src/modules/webhooks/service.ts +127 -0
- package/src/modules/webhooks/signing.ts +6 -0
- package/src/modules/webhooks/ssrf-guard.ts +71 -0
- package/src/modules/webhooks/tasks.ts +60 -0
- package/src/modules/webhooks/worker.ts +171 -0
- package/src/runtime/commerce.ts +158 -0
- package/src/runtime/kernel-modules.ts +66 -0
- package/src/runtime/kernel-register-hooks.ts +63 -0
- package/src/runtime/kernel-types.ts +109 -0
- package/src/runtime/kernel.ts +159 -0
- package/src/runtime/logger.ts +36 -0
- package/src/runtime/server.ts +470 -0
- package/src/runtime/shutdown.ts +43 -0
- package/src/runtime/url-alias-rewrite.ts +40 -0
- package/src/test-utils/create-pglite-adapter.ts +129 -0
- package/src/test-utils/create-plugin-test-app.ts +151 -0
- package/src/test-utils/create-repository-test-harness.ts +16 -0
- package/src/test-utils/create-test-config.ts +188 -0
- package/src/test-utils/create-test-kernel.ts +7 -0
- package/src/test-utils/create-test-plugin-context.ts +66 -0
- package/src/test-utils/rest-api-test-utils.ts +266 -0
- package/src/test-utils/test-actors.ts +70 -0
- package/src/test-utils/typed-hooks.ts +55 -0
- package/src/testing.ts +21 -0
- package/src/types/commerce-types.ts +34 -0
- package/src/utils/agent-prompt.ts +12 -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,95 @@
|
|
|
1
|
+
import type { AfterHook, BeforeHook, HookContext, HookOperation } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export interface HookError {
|
|
4
|
+
hookName: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface HookReport {
|
|
9
|
+
errors: HookError[];
|
|
10
|
+
hasErrors: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function mergeHookReports(a: HookReport, b: HookReport): HookReport {
|
|
14
|
+
return {
|
|
15
|
+
errors: [...a.errors, ...b.errors],
|
|
16
|
+
hasErrors: a.hasErrors || b.hasErrors,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Default hook timeout: 20 seconds */
|
|
21
|
+
const HOOK_TIMEOUT_MS = 20_000;
|
|
22
|
+
|
|
23
|
+
function withTimeout<T>(promiseOrValue: Promise<T> | T, timeoutMs: number, hookName: string): Promise<T> {
|
|
24
|
+
const promise = Promise.resolve(promiseOrValue);
|
|
25
|
+
return new Promise<T>((resolve, reject) => {
|
|
26
|
+
const timer = setTimeout(
|
|
27
|
+
() => reject(new Error(`Hook "${hookName}" timed out after ${timeoutMs}ms`)),
|
|
28
|
+
timeoutMs,
|
|
29
|
+
);
|
|
30
|
+
promise.then(
|
|
31
|
+
(val) => { clearTimeout(timer); resolve(val); },
|
|
32
|
+
(err) => { clearTimeout(timer); reject(err); },
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function runBeforeHooks<T>(
|
|
38
|
+
hooks: BeforeHook<T>[],
|
|
39
|
+
data: T,
|
|
40
|
+
operation: HookOperation,
|
|
41
|
+
context: HookContext,
|
|
42
|
+
): Promise<T> {
|
|
43
|
+
let current = data;
|
|
44
|
+
for (const hook of hooks) {
|
|
45
|
+
const hookName = hook.name || "(anonymous beforeHook)";
|
|
46
|
+
try {
|
|
47
|
+
current = await withTimeout(
|
|
48
|
+
hook({ data: current, operation, context }),
|
|
49
|
+
HOOK_TIMEOUT_MS,
|
|
50
|
+
hookName,
|
|
51
|
+
);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
context.logger.error(`Before-hook "${hookName}" failed during ${operation}`, {
|
|
54
|
+
error: error instanceof Error ? error.message : String(error),
|
|
55
|
+
requestId: context.requestId,
|
|
56
|
+
});
|
|
57
|
+
throw error; // Re-throw — beforeHooks MUST succeed
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return current;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function runAfterHooks<T>(
|
|
64
|
+
hooks: AfterHook<T>[],
|
|
65
|
+
originalData: T | null,
|
|
66
|
+
committedResult: T,
|
|
67
|
+
operation: HookOperation,
|
|
68
|
+
context: HookContext,
|
|
69
|
+
): Promise<HookReport> {
|
|
70
|
+
const errors: HookError[] = [];
|
|
71
|
+
for (const hook of hooks) {
|
|
72
|
+
const hookName = hook.name || "(anonymous afterHook)";
|
|
73
|
+
try {
|
|
74
|
+
await withTimeout(
|
|
75
|
+
hook({
|
|
76
|
+
data: originalData,
|
|
77
|
+
result: committedResult,
|
|
78
|
+
operation,
|
|
79
|
+
context,
|
|
80
|
+
}),
|
|
81
|
+
HOOK_TIMEOUT_MS,
|
|
82
|
+
hookName,
|
|
83
|
+
);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
errors.push({
|
|
86
|
+
hookName,
|
|
87
|
+
message: error instanceof Error ? error.message : String(error),
|
|
88
|
+
});
|
|
89
|
+
context.logger.error(`After-hook "${hookName}" failed`, {
|
|
90
|
+
error,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { errors, hasErrors: errors.length > 0 };
|
|
95
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export type HookHandler = (...args: never[]) => unknown;
|
|
2
|
+
|
|
3
|
+
type HookEntry = {
|
|
4
|
+
prepended: HookHandler[];
|
|
5
|
+
configured: HookHandler[];
|
|
6
|
+
appended: HookHandler[];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export class HookRegistry {
|
|
10
|
+
private registry = new Map<string, HookEntry>();
|
|
11
|
+
private logger?: { error: (obj: Record<string, unknown>, msg: string) => void };
|
|
12
|
+
|
|
13
|
+
registerConfigHooks(hookName: string, handlers: HookHandler[]): void {
|
|
14
|
+
this.ensureEntry(hookName);
|
|
15
|
+
this.registry.get(hookName)!.configured = [...handlers];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
append(hookName: string, handler: HookHandler): void {
|
|
19
|
+
this.ensureEntry(hookName);
|
|
20
|
+
this.registry.get(hookName)!.appended.push(handler);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
prepend(hookName: string, handler: HookHandler): void {
|
|
24
|
+
this.ensureEntry(hookName);
|
|
25
|
+
this.registry.get(hookName)!.prepended.push(handler);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
resolve(hookName: string): HookHandler[] {
|
|
29
|
+
const entry = this.registry.get(hookName);
|
|
30
|
+
if (!entry) return [];
|
|
31
|
+
return [...entry.prepended, ...entry.configured, ...entry.appended];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Emit a plugin event to all registered listeners.
|
|
36
|
+
*
|
|
37
|
+
* Unlike the before/after hook pattern (which transforms data through
|
|
38
|
+
* a pipeline), emit is fire-and-forget notification. Errors in handlers
|
|
39
|
+
* are caught and logged but do not propagate to the emitter.
|
|
40
|
+
*
|
|
41
|
+
* Usage:
|
|
42
|
+
* kernel.hooks.emit("production.afterComplete", { orderId, quantity });
|
|
43
|
+
*
|
|
44
|
+
* Any plugin can listen:
|
|
45
|
+
* hooks: () => [{ key: "production.afterComplete", handler: async (payload) => { ... } }]
|
|
46
|
+
*/
|
|
47
|
+
setLogger(logger: { error: (obj: Record<string, unknown>, msg: string) => void }): void {
|
|
48
|
+
this.logger = logger;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async emit(key: string, payload: unknown): Promise<void> {
|
|
52
|
+
const handlers = this.resolve(key);
|
|
53
|
+
for (const handler of handlers) {
|
|
54
|
+
try {
|
|
55
|
+
await (handler as (payload: unknown) => unknown)(payload);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
this.logger?.error(
|
|
58
|
+
{ err, hookKey: key },
|
|
59
|
+
`Event handler failed for "${key}"`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private ensureEntry(hookName: string): void {
|
|
66
|
+
if (!this.registry.has(hookName)) {
|
|
67
|
+
this.registry.set(hookName, {
|
|
68
|
+
prepended: [],
|
|
69
|
+
configured: [],
|
|
70
|
+
appended: [],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Actor } from "../../auth/types.js";
|
|
2
|
+
import type { JobsAdapter } from "../jobs/adapter.js";
|
|
3
|
+
import type { PluginDb } from "../database/plugin-types.js";
|
|
4
|
+
|
|
5
|
+
export type HookOperation =
|
|
6
|
+
| "create"
|
|
7
|
+
| "update"
|
|
8
|
+
| "delete"
|
|
9
|
+
| "read"
|
|
10
|
+
| "list"
|
|
11
|
+
| "statusChange"
|
|
12
|
+
| "addItem"
|
|
13
|
+
| "removeItem"
|
|
14
|
+
| "custom";
|
|
15
|
+
|
|
16
|
+
export interface Logger {
|
|
17
|
+
info(message: string, data?: unknown): void;
|
|
18
|
+
warn(message: string, data?: unknown): void;
|
|
19
|
+
error(message: string, data?: unknown): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ServiceContainer {
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type HookOrigin = "rest" | "local";
|
|
27
|
+
|
|
28
|
+
export interface HookContext {
|
|
29
|
+
actor: Actor | null;
|
|
30
|
+
tx: unknown;
|
|
31
|
+
logger: Logger;
|
|
32
|
+
services: ServiceContainer;
|
|
33
|
+
context: Record<string, unknown>;
|
|
34
|
+
requestId: string;
|
|
35
|
+
origin: HookOrigin;
|
|
36
|
+
jobs: JobsAdapter;
|
|
37
|
+
/**
|
|
38
|
+
* Drizzle database instance for hook handlers.
|
|
39
|
+
* Populated by `createHookContext` when callers pass `db`, `database`, or `kernel`.
|
|
40
|
+
*/
|
|
41
|
+
db: PluginDb;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type BeforeHook<TData> = (args: {
|
|
45
|
+
data: TData;
|
|
46
|
+
operation: HookOperation;
|
|
47
|
+
context: HookContext;
|
|
48
|
+
}) => Promise<TData> | TData;
|
|
49
|
+
|
|
50
|
+
export type AfterHook<TData> = (args: {
|
|
51
|
+
data: TData | null;
|
|
52
|
+
result: TData;
|
|
53
|
+
operation: HookOperation;
|
|
54
|
+
context: HookContext;
|
|
55
|
+
}) => Promise<void> | void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a PluginResultErr into a structured HTTP error response.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the `throw new Error(result.error)` pattern in plugin routes
|
|
5
|
+
* which always produces HTTP 500 with no structured error code.
|
|
6
|
+
*
|
|
7
|
+
* Usage in routes:
|
|
8
|
+
* const result = await service.doSomething(orgId, input);
|
|
9
|
+
* if (!result.ok) return toHttpError(result);
|
|
10
|
+
* return result.value;
|
|
11
|
+
*
|
|
12
|
+
* The function infers HTTP status from the error code or message content:
|
|
13
|
+
* - "NOT_FOUND" or "not found" --> 404
|
|
14
|
+
* - "FORBIDDEN" or "permission" --> 403
|
|
15
|
+
* - "CONFLICT" or "already exists" --> 409
|
|
16
|
+
* - "VALIDATION" or "cannot/must" --> 422
|
|
17
|
+
* - Everything else --> 400
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { PluginResultErr } from "./result.js";
|
|
21
|
+
|
|
22
|
+
export interface HttpErrorResponse {
|
|
23
|
+
status: 400 | 403 | 404 | 409 | 422;
|
|
24
|
+
body: { error: { code: string; message: string } };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function toHttpError(result: PluginResultErr): HttpErrorResponse {
|
|
28
|
+
const message = result.error;
|
|
29
|
+
const code = result.code;
|
|
30
|
+
|
|
31
|
+
if (code === "NOT_FOUND" || /not found/i.test(message)) {
|
|
32
|
+
return { status: 404, body: { error: { code: "NOT_FOUND", message } } };
|
|
33
|
+
}
|
|
34
|
+
if (code === "FORBIDDEN" || /permission|forbidden|unauthorized/i.test(message)) {
|
|
35
|
+
return { status: 403, body: { error: { code: "FORBIDDEN", message } } };
|
|
36
|
+
}
|
|
37
|
+
if (code === "CONFLICT" || /already|duplicate|exists|unique/i.test(message)) {
|
|
38
|
+
return { status: 409, body: { error: { code: "CONFLICT", message } } };
|
|
39
|
+
}
|
|
40
|
+
if (code === "VALIDATION" || /invalid|cannot|must|required|exceeded|negative/i.test(message)) {
|
|
41
|
+
return { status: 422, body: { error: { code: "VALIDATION_FAILED", message } } };
|
|
42
|
+
}
|
|
43
|
+
return { status: 400, body: { error: { code: code ?? "BAD_REQUEST", message } } };
|
|
44
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal interface for enqueueing background jobs.
|
|
3
|
+
* The full DrizzleJobsAdapter implements this; hooks receive
|
|
4
|
+
* it on HookContext.jobs so they can defer work without caring
|
|
5
|
+
* about the underlying storage.
|
|
6
|
+
*/
|
|
7
|
+
export interface JobsAdapter {
|
|
8
|
+
enqueue(
|
|
9
|
+
taskSlug: string,
|
|
10
|
+
input: Record<string, unknown>,
|
|
11
|
+
options: EnqueueOptions,
|
|
12
|
+
): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface EnqueueOptions {
|
|
16
|
+
organizationId: string;
|
|
17
|
+
queue?: string;
|
|
18
|
+
maxAttempts?: number;
|
|
19
|
+
delayMs?: number;
|
|
20
|
+
concurrencyKey?: string;
|
|
21
|
+
supersedes?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* No-op adapter used when no jobs backend is configured.
|
|
26
|
+
* All enqueue calls silently succeed and return a placeholder ID.
|
|
27
|
+
*/
|
|
28
|
+
export class NullJobsAdapter implements JobsAdapter {
|
|
29
|
+
async enqueue(
|
|
30
|
+
_taskSlug: string,
|
|
31
|
+
_input: Record<string, unknown>,
|
|
32
|
+
_options: EnqueueOptions,
|
|
33
|
+
): Promise<string> {
|
|
34
|
+
return "null-job-id";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { webhookDeliveryTask } from "../../modules/webhooks/tasks.js";
|
|
2
|
+
import { staleJobReaperTask } from "./reaper.js";
|
|
3
|
+
import type { TaskDefinition } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export const defaultKernelJobTasks: TaskDefinition<
|
|
6
|
+
Record<string, unknown>,
|
|
7
|
+
Record<string, unknown>
|
|
8
|
+
>[] = [
|
|
9
|
+
webhookDeliveryTask as TaskDefinition<
|
|
10
|
+
Record<string, unknown>,
|
|
11
|
+
Record<string, unknown>
|
|
12
|
+
>,
|
|
13
|
+
staleJobReaperTask as TaskDefinition<
|
|
14
|
+
Record<string, unknown>,
|
|
15
|
+
Record<string, unknown>
|
|
16
|
+
>,
|
|
17
|
+
];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { eq, and } from "drizzle-orm";
|
|
2
|
+
import type { DrizzleDatabase } from "../database/drizzle-db.js";
|
|
3
|
+
import type { TaskDefinition } from "./types.js";
|
|
4
|
+
import type { JobsAdapter, EnqueueOptions } from "./adapter.js";
|
|
5
|
+
import { OrgResolutionError } from "../errors.js";
|
|
6
|
+
import { commerceJobs } from "./schema.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* PostgreSQL-backed job queue adapter using the application's own database.
|
|
10
|
+
* Stores jobs in the `commerce_jobs` table. Supports concurrency keys
|
|
11
|
+
* and supersede semantics for deduplication.
|
|
12
|
+
*/
|
|
13
|
+
export class DrizzleJobsAdapter implements JobsAdapter {
|
|
14
|
+
constructor(
|
|
15
|
+
private db: DrizzleDatabase,
|
|
16
|
+
private tasks: Map<string, TaskDefinition>,
|
|
17
|
+
) {}
|
|
18
|
+
|
|
19
|
+
async enqueue(
|
|
20
|
+
taskSlug: string,
|
|
21
|
+
input: Record<string, unknown>,
|
|
22
|
+
options: EnqueueOptions,
|
|
23
|
+
): Promise<string> {
|
|
24
|
+
const organizationId = options.organizationId.trim();
|
|
25
|
+
if (!organizationId) {
|
|
26
|
+
throw new OrgResolutionError(
|
|
27
|
+
"Jobs enqueue requires a non-empty organizationId.",
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If supersedes is set, delete existing pending jobs with the same concurrency key
|
|
32
|
+
if (options.concurrencyKey && options.supersedes) {
|
|
33
|
+
await this.db
|
|
34
|
+
.delete(commerceJobs)
|
|
35
|
+
.where(
|
|
36
|
+
and(
|
|
37
|
+
eq(commerceJobs.concurrencyKey, options.concurrencyKey),
|
|
38
|
+
eq(commerceJobs.status, "pending"),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Look up task definition for default retry config
|
|
44
|
+
const task = this.tasks.get(taskSlug);
|
|
45
|
+
const maxAttempts =
|
|
46
|
+
options.maxAttempts ?? task?.retries?.attempts ?? 1;
|
|
47
|
+
|
|
48
|
+
const rows = await this.db
|
|
49
|
+
.insert(commerceJobs)
|
|
50
|
+
.values({
|
|
51
|
+
organizationId,
|
|
52
|
+
taskSlug,
|
|
53
|
+
input,
|
|
54
|
+
queue: options.queue ?? "default",
|
|
55
|
+
maxAttempts,
|
|
56
|
+
waitUntil: options.delayMs
|
|
57
|
+
? new Date(Date.now() + options.delayMs)
|
|
58
|
+
: null,
|
|
59
|
+
concurrencyKey: options.concurrencyKey ?? null,
|
|
60
|
+
})
|
|
61
|
+
.returning({ id: commerceJobs.id });
|
|
62
|
+
|
|
63
|
+
return rows[0]!.id;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { and, eq, lt, sql } from "drizzle-orm";
|
|
2
|
+
import type { DbOrTx } from "../database/drizzle-db.js";
|
|
3
|
+
import type { Logger } from "../hooks/types.js";
|
|
4
|
+
import { commerceJobs } from "./schema.js";
|
|
5
|
+
import type { TaskDefinition } from "./types.js";
|
|
6
|
+
|
|
7
|
+
export function getJobReapThresholdMs(): number {
|
|
8
|
+
const raw = process.env.JOB_REAP_THRESHOLD_MS;
|
|
9
|
+
if (raw === undefined || raw === "") return 300_000;
|
|
10
|
+
const n = Number.parseInt(raw, 10);
|
|
11
|
+
return Number.isFinite(n) && n > 0 ? n : 300_000;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getJobsReaperIntervalMs(): number {
|
|
15
|
+
const raw = process.env.JOBS_REAPER_INTERVAL_MS;
|
|
16
|
+
if (raw === undefined || raw === "") return 60_000;
|
|
17
|
+
const n = Number.parseInt(raw, 10);
|
|
18
|
+
return Number.isFinite(n) && n > 0 ? n : 60_000;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function runStaleJobReaper(
|
|
22
|
+
db: DbOrTx,
|
|
23
|
+
thresholdMs: number,
|
|
24
|
+
logger: Logger,
|
|
25
|
+
): Promise<{ reapedCount: number }> {
|
|
26
|
+
const cutoff = new Date(Date.now() - thresholdMs);
|
|
27
|
+
|
|
28
|
+
return db.transaction(async (tx) => {
|
|
29
|
+
const stuck = await tx
|
|
30
|
+
.select({
|
|
31
|
+
id: commerceJobs.id,
|
|
32
|
+
taskSlug: commerceJobs.taskSlug,
|
|
33
|
+
processingStartedAt: commerceJobs.processingStartedAt,
|
|
34
|
+
attempts: commerceJobs.attempts,
|
|
35
|
+
})
|
|
36
|
+
.from(commerceJobs)
|
|
37
|
+
.where(
|
|
38
|
+
and(
|
|
39
|
+
eq(commerceJobs.status, "processing"),
|
|
40
|
+
sql`${commerceJobs.processingStartedAt} IS NOT NULL`,
|
|
41
|
+
lt(commerceJobs.processingStartedAt, cutoff),
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
.for("update");
|
|
45
|
+
|
|
46
|
+
let reapedCount = 0;
|
|
47
|
+
for (const row of stuck) {
|
|
48
|
+
const newAttempts = Math.max(row.attempts - 1, 0);
|
|
49
|
+
const updated = await tx
|
|
50
|
+
.update(commerceJobs)
|
|
51
|
+
.set({
|
|
52
|
+
status: "pending",
|
|
53
|
+
processingStartedAt: null,
|
|
54
|
+
attempts: newAttempts,
|
|
55
|
+
updatedAt: new Date(),
|
|
56
|
+
})
|
|
57
|
+
.where(
|
|
58
|
+
and(
|
|
59
|
+
eq(commerceJobs.id, row.id),
|
|
60
|
+
eq(commerceJobs.status, "processing"),
|
|
61
|
+
lt(commerceJobs.processingStartedAt, cutoff),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
.returning({ id: commerceJobs.id });
|
|
65
|
+
|
|
66
|
+
if (updated.length === 0) continue;
|
|
67
|
+
|
|
68
|
+
reapedCount++;
|
|
69
|
+
logger.info("Reaped stale processing job", {
|
|
70
|
+
id: row.id,
|
|
71
|
+
taskSlug: row.taskSlug,
|
|
72
|
+
processingStartedAt: row.processingStartedAt,
|
|
73
|
+
attemptsAfter: newAttempts,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { reapedCount };
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const staleJobReaperTask: TaskDefinition<
|
|
82
|
+
Record<string, unknown>,
|
|
83
|
+
{ reapedCount: number }
|
|
84
|
+
> = {
|
|
85
|
+
slug: "jobs/reap-stale",
|
|
86
|
+
|
|
87
|
+
async handler({ ctx }) {
|
|
88
|
+
const reaped = await runStaleJobReaper(
|
|
89
|
+
ctx.db,
|
|
90
|
+
getJobReapThresholdMs(),
|
|
91
|
+
ctx.logger,
|
|
92
|
+
);
|
|
93
|
+
return { output: { reapedCount: reaped.reapedCount } };
|
|
94
|
+
},
|
|
95
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { eq, and, sql } from "drizzle-orm";
|
|
2
|
+
import type { DrizzleDatabase } from "../database/drizzle-db.js";
|
|
3
|
+
import type { Logger, ServiceContainer } from "../hooks/types.js";
|
|
4
|
+
import type { TaskDefinition } from "./types.js";
|
|
5
|
+
import { commerceJobs } from "./schema.js";
|
|
6
|
+
|
|
7
|
+
export interface RunPendingJobsArgs {
|
|
8
|
+
db: DrizzleDatabase;
|
|
9
|
+
tasks: Map<string, TaskDefinition>;
|
|
10
|
+
queue?: string;
|
|
11
|
+
limit?: number;
|
|
12
|
+
logger: Logger;
|
|
13
|
+
services: ServiceContainer;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Claims and processes pending jobs from the `commerce_jobs` table.
|
|
18
|
+
*
|
|
19
|
+
* Uses `FOR UPDATE SKIP LOCKED` to allow multiple runners to process
|
|
20
|
+
* jobs in parallel without conflicts. Each runner claims a batch,
|
|
21
|
+
* marks them as processing, then executes handlers outside the
|
|
22
|
+
* claim transaction.
|
|
23
|
+
*/
|
|
24
|
+
export async function runPendingJobs(
|
|
25
|
+
args: RunPendingJobsArgs,
|
|
26
|
+
): Promise<{ processed: number; failed: number }> {
|
|
27
|
+
const {
|
|
28
|
+
db,
|
|
29
|
+
tasks,
|
|
30
|
+
queue = "default",
|
|
31
|
+
limit = 10,
|
|
32
|
+
logger,
|
|
33
|
+
services,
|
|
34
|
+
} = args;
|
|
35
|
+
|
|
36
|
+
let processed = 0;
|
|
37
|
+
let failed = 0;
|
|
38
|
+
|
|
39
|
+
// Phase 1: Claim jobs atomically
|
|
40
|
+
const claimed = await db.transaction(async (tx) => {
|
|
41
|
+
const pending = await tx
|
|
42
|
+
.select()
|
|
43
|
+
.from(commerceJobs)
|
|
44
|
+
.where(
|
|
45
|
+
and(
|
|
46
|
+
eq(commerceJobs.status, "pending"),
|
|
47
|
+
eq(commerceJobs.queue, queue),
|
|
48
|
+
sql`(${commerceJobs.waitUntil} IS NULL OR ${commerceJobs.waitUntil} <= now())`,
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
.orderBy(commerceJobs.createdAt)
|
|
52
|
+
.limit(limit)
|
|
53
|
+
.for("update", { skipLocked: true });
|
|
54
|
+
|
|
55
|
+
for (const job of pending) {
|
|
56
|
+
await tx
|
|
57
|
+
.update(commerceJobs)
|
|
58
|
+
.set({
|
|
59
|
+
status: "processing",
|
|
60
|
+
processingStartedAt: new Date(),
|
|
61
|
+
updatedAt: new Date(),
|
|
62
|
+
})
|
|
63
|
+
.where(eq(commerceJobs.id, job.id));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return pending;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Phase 2: Execute each claimed job outside the claim transaction
|
|
70
|
+
for (const job of claimed) {
|
|
71
|
+
const task = tasks.get(job.taskSlug);
|
|
72
|
+
|
|
73
|
+
if (!task) {
|
|
74
|
+
logger.warn("Unknown task slug — job marked as failed. Register the task handler in config.jobs.tasks.", {
|
|
75
|
+
taskSlug: job.taskSlug,
|
|
76
|
+
jobId: job.id,
|
|
77
|
+
});
|
|
78
|
+
await db
|
|
79
|
+
.update(commerceJobs)
|
|
80
|
+
.set({
|
|
81
|
+
status: "failed",
|
|
82
|
+
error: `Unknown task slug: ${job.taskSlug}`,
|
|
83
|
+
updatedAt: new Date(),
|
|
84
|
+
completedAt: new Date(),
|
|
85
|
+
})
|
|
86
|
+
.where(eq(commerceJobs.id, job.id));
|
|
87
|
+
failed++;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const result = await task.handler({
|
|
93
|
+
input: job.input as Record<string, unknown>,
|
|
94
|
+
ctx: { logger, db, services },
|
|
95
|
+
job: {
|
|
96
|
+
attemptNumber: job.attempts + 1,
|
|
97
|
+
maxAttempts: job.maxAttempts,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await db
|
|
102
|
+
.update(commerceJobs)
|
|
103
|
+
.set({
|
|
104
|
+
status: "succeeded",
|
|
105
|
+
output: result.output,
|
|
106
|
+
attempts: job.attempts + 1,
|
|
107
|
+
updatedAt: new Date(),
|
|
108
|
+
completedAt: new Date(),
|
|
109
|
+
})
|
|
110
|
+
.where(eq(commerceJobs.id, job.id));
|
|
111
|
+
|
|
112
|
+
processed++;
|
|
113
|
+
} catch (err) {
|
|
114
|
+
logger.error("Job handler failed", {
|
|
115
|
+
taskSlug: job.taskSlug,
|
|
116
|
+
jobId: job.id,
|
|
117
|
+
error: err instanceof Error ? err.message : String(err),
|
|
118
|
+
});
|
|
119
|
+
const attempts = job.attempts + 1;
|
|
120
|
+
const maxAttempts = job.maxAttempts;
|
|
121
|
+
|
|
122
|
+
if (attempts >= maxAttempts) {
|
|
123
|
+
await db
|
|
124
|
+
.update(commerceJobs)
|
|
125
|
+
.set({
|
|
126
|
+
status: "failed",
|
|
127
|
+
error: err instanceof Error ? err.message : String(err),
|
|
128
|
+
attempts,
|
|
129
|
+
updatedAt: new Date(),
|
|
130
|
+
completedAt: new Date(),
|
|
131
|
+
})
|
|
132
|
+
.where(eq(commerceJobs.id, job.id));
|
|
133
|
+
failed++;
|
|
134
|
+
} else {
|
|
135
|
+
// Compute backoff delay
|
|
136
|
+
const retries = task.retries;
|
|
137
|
+
const delay =
|
|
138
|
+
retries?.backoff?.type === "exponential"
|
|
139
|
+
? retries.backoff.delay * Math.pow(2, attempts - 1)
|
|
140
|
+
: (retries?.backoff?.delay ?? 1000);
|
|
141
|
+
|
|
142
|
+
await db
|
|
143
|
+
.update(commerceJobs)
|
|
144
|
+
.set({
|
|
145
|
+
status: "pending",
|
|
146
|
+
error: err instanceof Error ? err.message : String(err),
|
|
147
|
+
attempts,
|
|
148
|
+
waitUntil: new Date(Date.now() + delay),
|
|
149
|
+
updatedAt: new Date(),
|
|
150
|
+
})
|
|
151
|
+
.where(eq(commerceJobs.id, job.id));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return { processed, failed };
|
|
157
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pgTable,
|
|
3
|
+
uuid,
|
|
4
|
+
text,
|
|
5
|
+
jsonb,
|
|
6
|
+
integer,
|
|
7
|
+
timestamp,
|
|
8
|
+
index,
|
|
9
|
+
} from "drizzle-orm/pg-core";
|
|
10
|
+
import { organization } from "../../auth/auth-schema.js";
|
|
11
|
+
|
|
12
|
+
export const commerceJobs = pgTable("commerce_jobs", {
|
|
13
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
14
|
+
organizationId: text("organization_id")
|
|
15
|
+
.notNull()
|
|
16
|
+
.references(() => organization.id, { onDelete: "cascade" }),
|
|
17
|
+
queue: text("queue").notNull().default("default"),
|
|
18
|
+
taskSlug: text("task_slug").notNull(),
|
|
19
|
+
input: jsonb("input").notNull().default("{}"),
|
|
20
|
+
output: jsonb("output"),
|
|
21
|
+
status: text("status", {
|
|
22
|
+
enum: ["pending", "processing", "succeeded", "failed"],
|
|
23
|
+
})
|
|
24
|
+
.notNull()
|
|
25
|
+
.default("pending"),
|
|
26
|
+
attempts: integer("attempts").notNull().default(0),
|
|
27
|
+
maxAttempts: integer("max_attempts").notNull().default(1),
|
|
28
|
+
error: text("error"),
|
|
29
|
+
waitUntil: timestamp("wait_until", { withTimezone: true }),
|
|
30
|
+
concurrencyKey: text("concurrency_key"),
|
|
31
|
+
createdAt: timestamp("created_at", { withTimezone: true })
|
|
32
|
+
.notNull()
|
|
33
|
+
.defaultNow(),
|
|
34
|
+
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
35
|
+
.notNull()
|
|
36
|
+
.defaultNow(),
|
|
37
|
+
processingStartedAt: timestamp("processing_started_at", {
|
|
38
|
+
withTimezone: true,
|
|
39
|
+
}),
|
|
40
|
+
completedAt: timestamp("completed_at", { withTimezone: true }),
|
|
41
|
+
}, (table) => ({
|
|
42
|
+
statusQueueIdx: index("idx_jobs_status_queue").on(table.status, table.queue),
|
|
43
|
+
taskSlugIdx: index("idx_jobs_task_slug").on(table.taskSlug),
|
|
44
|
+
waitUntilIdx: index("idx_jobs_wait_until").on(table.waitUntil),
|
|
45
|
+
orgIdx: index("idx_jobs_org").on(table.organizationId),
|
|
46
|
+
}));
|