@porulle/core 0.64.0 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/email-render.d.ts +18 -0
- package/dist/adapters/email-render.d.ts.map +1 -0
- package/dist/adapters/email-render.js +37 -0
- package/dist/auth/actor.d.ts.map +1 -1
- package/dist/auth/actor.js +11 -0
- package/dist/auth/auth-failure.d.ts +0 -2
- package/dist/auth/auth-failure.d.ts.map +1 -1
- package/dist/auth/auth-failure.js +0 -4
- package/dist/auth/middleware.d.ts +0 -1
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +7 -6
- package/dist/auth/permissions.d.ts +2 -0
- package/dist/auth/permissions.d.ts.map +1 -1
- package/dist/auth/permissions.js +8 -6
- package/dist/auth/role-authority.d.ts +0 -1
- package/dist/auth/role-authority.d.ts.map +1 -1
- package/dist/auth/role-authority.js +1 -8
- package/dist/auth/setup.d.ts.map +1 -1
- package/dist/auth/setup.js +5 -0
- package/dist/auth/strict-org-resolution.d.ts +8 -1
- package/dist/auth/strict-org-resolution.d.ts.map +1 -1
- package/dist/auth/strict-org-resolution.js +9 -19
- package/dist/auth/system-actor.d.ts +3 -2
- package/dist/auth/system-actor.d.ts.map +1 -1
- package/dist/auth/system-actor.js +3 -3
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +3 -20
- package/dist/config/define-config.d.ts +2 -2
- package/dist/config/define-config.d.ts.map +1 -1
- package/dist/config/define-config.js +3 -2
- package/dist/config/types.d.ts +2 -3
- package/dist/config/types.d.ts.map +1 -1
- package/dist/hooks/checkout.d.ts +2 -15
- package/dist/hooks/checkout.d.ts.map +1 -1
- package/dist/hooks/checkout.js +2 -51
- package/dist/index.d.ts +11 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -12
- package/dist/interfaces/rest/router.js +3 -3
- package/dist/interfaces/rest/routes/admin/compensation-failures.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/admin/compensation-failures.js +5 -5
- package/dist/interfaces/rest/routes/admin/entity-field-definitions.js +5 -5
- package/dist/interfaces/rest/routes/admin/staff.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/admin/staff.js +2 -3
- package/dist/interfaces/rest/routes/analytics.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/analytics.js +2 -2
- package/dist/interfaces/rest/routes/carts.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/carts.js +12 -12
- package/dist/interfaces/rest/routes/catalog.js +37 -37
- package/dist/interfaces/rest/routes/checkout.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/checkout.js +9 -10
- package/dist/interfaces/rest/routes/customers.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/customers.js +12 -12
- package/dist/interfaces/rest/routes/documents.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/documents.js +9 -9
- package/dist/interfaces/rest/routes/inventory.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/inventory.js +8 -8
- package/dist/interfaces/rest/routes/media.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/media.js +5 -5
- package/dist/interfaces/rest/routes/orders.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/orders.js +32 -32
- package/dist/interfaces/rest/routes/payments.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/payments.js +2 -2
- package/dist/interfaces/rest/routes/pricing.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/pricing.js +8 -8
- package/dist/interfaces/rest/routes/promotions.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/promotions.js +7 -7
- package/dist/interfaces/rest/routes/search.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/search.js +3 -3
- package/dist/interfaces/rest/routes/settings.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/settings.js +4 -4
- package/dist/interfaces/rest/routes/shipping.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/shipping.js +9 -9
- package/dist/interfaces/rest/routes/tax.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/tax.js +9 -9
- package/dist/interfaces/rest/routes/webhooks.d.ts.map +1 -1
- package/dist/interfaces/rest/routes/webhooks.js +4 -4
- package/dist/interfaces/rest/utils.d.ts +1 -1
- package/dist/interfaces/rest/utils.d.ts.map +1 -1
- package/dist/interfaces/rest/utils.js +4 -13
- package/dist/jobs.d.ts +1 -0
- package/dist/jobs.d.ts.map +1 -1
- package/dist/jobs.js +1 -0
- package/dist/kernel/database/adapter.d.ts +9 -0
- package/dist/kernel/database/adapter.d.ts.map +1 -1
- package/dist/kernel/database/adapter.js +1 -1
- package/dist/kernel/database/migrate.d.ts +0 -4
- package/dist/kernel/database/migrate.d.ts.map +1 -1
- package/dist/kernel/database/migrate.js +2 -14
- package/dist/kernel/database/pglite-transaction.d.ts +28 -0
- package/dist/kernel/database/pglite-transaction.d.ts.map +1 -0
- package/dist/kernel/database/pglite-transaction.js +52 -0
- package/dist/kernel/database/tx-context.d.ts +0 -1
- package/dist/kernel/database/tx-context.d.ts.map +1 -1
- package/dist/kernel/database/tx-context.js +2 -14
- package/dist/kernel/database/unique-violation.d.ts +3 -0
- package/dist/kernel/database/unique-violation.d.ts.map +1 -0
- package/dist/kernel/database/unique-violation.js +9 -0
- package/dist/kernel/error-mapper.d.ts.map +1 -1
- package/dist/kernel/error-mapper.js +1 -0
- package/dist/kernel/errors.d.ts +12 -0
- package/dist/kernel/errors.d.ts.map +1 -1
- package/dist/kernel/errors.js +16 -0
- package/dist/kernel/hooks/create-context.d.ts +18 -9
- package/dist/kernel/hooks/create-context.d.ts.map +1 -1
- package/dist/kernel/hooks/create-context.js +24 -3
- package/dist/kernel/hooks/registry.d.ts +0 -19
- package/dist/kernel/hooks/registry.d.ts.map +1 -1
- package/dist/kernel/hooks/registry.js +0 -32
- package/dist/kernel/jobs/drizzle-adapter.d.ts.map +1 -1
- package/dist/kernel/jobs/drizzle-adapter.js +3 -10
- package/dist/kernel/jobs/prepare-enqueue.d.ts +20 -0
- package/dist/kernel/jobs/prepare-enqueue.d.ts.map +1 -0
- package/dist/kernel/jobs/prepare-enqueue.js +24 -0
- package/dist/kernel/jobs/types.d.ts +0 -4
- package/dist/kernel/jobs/types.d.ts.map +1 -1
- package/dist/kernel/jobs/types.js +0 -4
- package/dist/kernel/local-api.d.ts +0 -33
- package/dist/kernel/local-api.d.ts.map +1 -1
- package/dist/kernel/local-api.js +0 -36
- package/dist/kernel/plugin/manifest.d.ts +3 -5
- package/dist/kernel/plugin/manifest.d.ts.map +1 -1
- package/dist/modules/analytics/service.d.ts +0 -6
- package/dist/modules/analytics/service.d.ts.map +1 -1
- package/dist/modules/analytics/service.js +0 -32
- package/dist/modules/cart/service.d.ts.map +1 -1
- package/dist/modules/cart/service.js +5 -17
- package/dist/modules/catalog/entity-service.d.ts.map +1 -1
- package/dist/modules/catalog/entity-service.js +9 -17
- package/dist/modules/catalog/import-service.d.ts.map +1 -1
- package/dist/modules/catalog/import-service.js +4 -13
- package/dist/modules/catalog/service.d.ts +1 -81
- package/dist/modules/catalog/service.d.ts.map +1 -1
- package/dist/modules/catalog/service.js +1 -8
- package/dist/modules/customers/service.d.ts.map +1 -1
- package/dist/modules/customers/service.js +5 -17
- package/dist/modules/documents/render.d.ts +0 -3
- package/dist/modules/documents/render.d.ts.map +1 -1
- package/dist/modules/documents/render.js +2 -17
- package/dist/modules/fulfillment/service.d.ts.map +1 -1
- package/dist/modules/fulfillment/service.js +8 -26
- package/dist/modules/inventory/service.d.ts.map +1 -1
- package/dist/modules/inventory/service.js +3 -20
- package/dist/modules/media/service.d.ts.map +1 -1
- package/dist/modules/media/service.js +2 -10
- package/dist/modules/orders/quote.d.ts.map +1 -1
- package/dist/modules/orders/quote.js +1 -2
- package/dist/modules/orders/service.d.ts.map +1 -1
- package/dist/modules/orders/service.js +4 -17
- package/dist/modules/pricing/service.d.ts.map +1 -1
- package/dist/modules/pricing/service.js +7 -18
- package/dist/modules/promotions/service.d.ts.map +1 -1
- package/dist/modules/promotions/service.js +4 -16
- package/dist/modules/tax/service.d.ts +1 -3
- package/dist/modules/tax/service.d.ts.map +1 -1
- package/dist/modules/tax/service.js +16 -52
- package/dist/modules/webhooks/hook.d.ts.map +1 -1
- package/dist/modules/webhooks/hook.js +3 -2
- package/dist/modules/webhooks/service.d.ts.map +1 -1
- package/dist/modules/webhooks/service.js +1 -50
- package/dist/runtime/commerce.d.ts.map +1 -1
- package/dist/runtime/commerce.js +4 -11
- package/dist/runtime/kernel-modules.d.ts +38 -1799
- package/dist/runtime/kernel-modules.d.ts.map +1 -1
- package/dist/runtime/kernel-modules.js +160 -66
- package/dist/runtime/kernel-types.d.ts +3 -15
- package/dist/runtime/kernel-types.d.ts.map +1 -1
- package/dist/runtime/kernel-types.js +0 -10
- package/dist/runtime/kernel.d.ts +2 -3
- package/dist/runtime/kernel.d.ts.map +1 -1
- package/dist/runtime/kernel.js +10 -51
- package/dist/runtime/server.d.ts +1 -1
- package/dist/runtime/server.d.ts.map +1 -1
- package/dist/test-utils/create-pglite-adapter.d.ts.map +1 -1
- package/dist/test-utils/create-pglite-adapter.js +5 -62
- package/dist/test-utils/create-plugin-test-app.d.ts.map +1 -1
- package/dist/test-utils/create-plugin-test-app.js +13 -32
- package/dist/test-utils/rest-api-test-utils.d.ts +0 -12
- package/dist/test-utils/rest-api-test-utils.d.ts.map +1 -1
- package/dist/test-utils/rest-api-test-utils.js +3 -70
- package/dist/test-utils/test-actors.d.ts +9 -0
- package/dist/test-utils/test-actors.d.ts.map +1 -1
- package/dist/test-utils/test-actors.js +62 -0
- package/dist/testing.d.ts +1 -4
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -4
- package/dist/utils/escape-html.d.ts +3 -0
- package/dist/utils/escape-html.d.ts.map +1 -0
- package/dist/utils/escape-html.js +9 -0
- package/dist/utils/id.d.ts +0 -1
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +0 -3
- package/dist/utils/logger.d.ts +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +1 -1
- package/dist/utils/money.d.ts +13 -0
- package/dist/utils/money.d.ts.map +1 -0
- package/dist/utils/money.js +58 -0
- package/package.json +5 -6
- package/src/adapters/email-render.ts +63 -0
- package/src/auth/actor.ts +14 -0
- package/src/auth/auth-failure.ts +0 -5
- package/src/auth/middleware.ts +7 -6
- package/src/auth/permissions.ts +12 -6
- package/src/auth/role-authority.ts +1 -10
- package/src/auth/setup.ts +8 -0
- package/src/auth/strict-org-resolution.ts +9 -16
- package/src/auth/system-actor.ts +3 -3
- package/src/config/defaults.ts +3 -20
- package/src/config/define-config.ts +5 -4
- package/src/config/types.ts +2 -2
- package/src/hooks/checkout.ts +2 -86
- package/src/index.ts +9 -36
- package/src/interfaces/rest/router.ts +3 -3
- package/src/interfaces/rest/routes/admin/compensation-failures.ts +5 -5
- package/src/interfaces/rest/routes/admin/entity-field-definitions.ts +5 -5
- package/src/interfaces/rest/routes/admin/staff.ts +2 -3
- package/src/interfaces/rest/routes/analytics.ts +2 -2
- package/src/interfaces/rest/routes/carts.ts +12 -12
- package/src/interfaces/rest/routes/catalog.ts +37 -37
- package/src/interfaces/rest/routes/checkout.ts +8 -10
- package/src/interfaces/rest/routes/customers.ts +12 -12
- package/src/interfaces/rest/routes/documents.ts +9 -9
- package/src/interfaces/rest/routes/inventory.ts +8 -8
- package/src/interfaces/rest/routes/media.ts +5 -5
- package/src/interfaces/rest/routes/orders.ts +32 -32
- package/src/interfaces/rest/routes/payments.ts +2 -2
- package/src/interfaces/rest/routes/pricing.ts +8 -8
- package/src/interfaces/rest/routes/promotions.ts +7 -7
- package/src/interfaces/rest/routes/search.ts +3 -3
- package/src/interfaces/rest/routes/settings.ts +4 -4
- package/src/interfaces/rest/routes/shipping.ts +9 -9
- package/src/interfaces/rest/routes/tax.ts +9 -9
- package/src/interfaces/rest/routes/webhooks.ts +4 -4
- package/src/interfaces/rest/utils.ts +4 -14
- package/src/jobs.ts +2 -1
- package/src/kernel/database/adapter.ts +1 -1
- package/src/kernel/database/migrate.ts +2 -17
- package/src/kernel/database/pglite-transaction.ts +61 -0
- package/src/kernel/database/tx-context.ts +2 -20
- package/src/kernel/database/unique-violation.ts +7 -0
- package/src/kernel/error-mapper.ts +1 -0
- package/src/kernel/errors.ts +18 -0
- package/src/kernel/hooks/create-context.ts +38 -8
- package/src/kernel/hooks/registry.ts +0 -37
- package/src/kernel/jobs/drizzle-adapter.ts +4 -15
- package/src/kernel/jobs/prepare-enqueue.ts +42 -0
- package/src/kernel/jobs/types.ts +0 -5
- package/src/kernel/local-api.ts +0 -44
- package/src/kernel/plugin/manifest.ts +3 -5
- package/src/modules/analytics/service.ts +0 -36
- package/src/modules/cart/service.ts +6 -29
- package/src/modules/catalog/entity-service.ts +9 -19
- package/src/modules/catalog/import-service.ts +4 -11
- package/src/modules/catalog/service.ts +2 -286
- package/src/modules/customers/service.ts +6 -27
- package/src/modules/documents/render.ts +2 -19
- package/src/modules/fulfillment/service.ts +8 -27
- package/src/modules/inventory/service.ts +3 -21
- package/src/modules/media/service.ts +2 -8
- package/src/modules/orders/quote.ts +1 -2
- package/src/modules/orders/service.ts +5 -30
- package/src/modules/pricing/service.ts +12 -30
- package/src/modules/promotions/service.ts +5 -28
- package/src/modules/tax/service.ts +20 -48
- package/src/modules/webhooks/hook.ts +3 -2
- package/src/modules/webhooks/service.ts +1 -42
- package/src/runtime/commerce.ts +4 -11
- package/src/runtime/kernel-modules.ts +191 -67
- package/src/runtime/kernel-types.ts +3 -26
- package/src/runtime/kernel.ts +11 -66
- package/src/runtime/server.ts +1 -3
- package/src/test-utils/create-pglite-adapter.ts +5 -67
- package/src/test-utils/create-plugin-test-app.ts +13 -52
- package/src/test-utils/rest-api-test-utils.ts +3 -70
- package/src/test-utils/test-actors.ts +66 -0
- package/src/testing.ts +1 -3
- package/src/utils/escape-html.ts +9 -0
- package/src/utils/id.ts +0 -4
- package/src/utils/logger.ts +1 -1
- package/src/utils/money.ts +62 -0
- package/dist/auth/access.d.ts +0 -101
- package/dist/auth/access.d.ts.map +0 -1
- package/dist/auth/access.js +0 -128
- package/dist/generated/plugin-manifest.d.ts +0 -51
- package/dist/generated/plugin-manifest.d.ts.map +0 -1
- package/dist/generated/plugin-manifest.js +0 -21
- package/dist/kernel/factory/repository-factory.d.ts +0 -71
- package/dist/kernel/factory/repository-factory.d.ts.map +0 -1
- package/dist/kernel/factory/repository-factory.js +0 -138
- package/dist/kernel/http-error.d.ts +0 -30
- package/dist/kernel/http-error.d.ts.map +0 -1
- package/dist/kernel/http-error.js +0 -35
- package/dist/kernel/jobs/builtin-job-tasks.d.ts +0 -3
- package/dist/kernel/jobs/builtin-job-tasks.d.ts.map +0 -1
- package/dist/kernel/jobs/builtin-job-tasks.js +0 -6
- package/dist/kernel/module/define.d.ts +0 -21
- package/dist/kernel/module/define.d.ts.map +0 -1
- package/dist/kernel/module/define.js +0 -3
- package/dist/kernel/module/index.d.ts +0 -4
- package/dist/kernel/module/index.d.ts.map +0 -1
- package/dist/kernel/module/index.js +0 -2
- package/dist/kernel/module/topo-sort.d.ts +0 -7
- package/dist/kernel/module/topo-sort.d.ts.map +0 -1
- package/dist/kernel/module/topo-sort.js +0 -89
- package/dist/kernel/query/executor.d.ts +0 -21
- package/dist/kernel/query/executor.d.ts.map +0 -1
- package/dist/kernel/query/executor.js +0 -128
- package/dist/kernel/query/registry.d.ts +0 -33
- package/dist/kernel/query/registry.d.ts.map +0 -1
- package/dist/kernel/query/registry.js +0 -20
- package/dist/kernel/service-registry.d.ts +0 -109
- package/dist/kernel/service-registry.d.ts.map +0 -1
- package/dist/kernel/service-registry.js +0 -26
- package/dist/modules/analytics/hooks.d.ts +0 -13
- package/dist/modules/analytics/hooks.d.ts.map +0 -1
- package/dist/modules/analytics/hooks.js +0 -12
- package/dist/modules/analytics/module.d.ts +0 -3
- package/dist/modules/analytics/module.d.ts.map +0 -1
- package/dist/modules/analytics/module.js +0 -24
- package/dist/modules/analytics/repository/index.d.ts +0 -5
- package/dist/modules/analytics/repository/index.d.ts.map +0 -1
- package/dist/modules/analytics/repository/index.js +0 -1
- package/dist/modules/audit/index.d.ts +0 -2
- package/dist/modules/audit/index.d.ts.map +0 -1
- package/dist/modules/audit/index.js +0 -1
- package/dist/modules/audit/module.d.ts +0 -180
- package/dist/modules/audit/module.d.ts.map +0 -1
- package/dist/modules/audit/module.js +0 -8
- package/dist/modules/cart/access.d.ts +0 -11
- package/dist/modules/cart/access.d.ts.map +0 -1
- package/dist/modules/cart/access.js +0 -18
- package/dist/modules/cart/module.d.ts +0 -14
- package/dist/modules/cart/module.d.ts.map +0 -1
- package/dist/modules/cart/module.js +0 -17
- package/dist/modules/catalog/module.d.ts +0 -26
- package/dist/modules/catalog/module.d.ts.map +0 -1
- package/dist/modules/catalog/module.js +0 -33
- package/dist/modules/customers/index.d.ts +0 -2
- package/dist/modules/customers/index.d.ts.map +0 -1
- package/dist/modules/customers/index.js +0 -1
- package/dist/modules/customers/module.d.ts +0 -563
- package/dist/modules/customers/module.d.ts.map +0 -1
- package/dist/modules/customers/module.js +0 -20
- package/dist/modules/documents/module.d.ts +0 -7
- package/dist/modules/documents/module.d.ts.map +0 -1
- package/dist/modules/documents/module.js +0 -13
- package/dist/modules/fulfillment/module.d.ts +0 -13
- package/dist/modules/fulfillment/module.d.ts.map +0 -1
- package/dist/modules/fulfillment/module.js +0 -23
- package/dist/modules/inventory/module.d.ts +0 -13
- package/dist/modules/inventory/module.d.ts.map +0 -1
- package/dist/modules/inventory/module.js +0 -20
- package/dist/modules/media/index.d.ts +0 -2
- package/dist/modules/media/index.d.ts.map +0 -1
- package/dist/modules/media/index.js +0 -1
- package/dist/modules/media/module.d.ts +0 -360
- package/dist/modules/media/module.d.ts.map +0 -1
- package/dist/modules/media/module.js +0 -24
- package/dist/modules/orders/module.d.ts +0 -25
- package/dist/modules/orders/module.d.ts.map +0 -1
- package/dist/modules/orders/module.js +0 -33
- package/dist/modules/organization/index.d.ts +0 -2
- package/dist/modules/organization/index.d.ts.map +0 -1
- package/dist/modules/organization/index.js +0 -1
- package/dist/modules/organization/module.d.ts +0 -205
- package/dist/modules/organization/module.d.ts.map +0 -1
- package/dist/modules/organization/module.js +0 -8
- package/dist/modules/payments/module.d.ts +0 -3
- package/dist/modules/payments/module.d.ts.map +0 -1
- package/dist/modules/payments/module.js +0 -7
- package/dist/modules/payments/repository/index.d.ts +0 -5
- package/dist/modules/payments/repository/index.d.ts.map +0 -1
- package/dist/modules/payments/repository/index.js +0 -1
- package/dist/modules/pricing/index.d.ts +0 -2
- package/dist/modules/pricing/index.d.ts.map +0 -1
- package/dist/modules/pricing/index.js +0 -1
- package/dist/modules/pricing/module.d.ts +0 -14
- package/dist/modules/pricing/module.d.ts.map +0 -1
- package/dist/modules/pricing/module.js +0 -17
- package/dist/modules/promotions/module.d.ts +0 -14
- package/dist/modules/promotions/module.d.ts.map +0 -1
- package/dist/modules/promotions/module.js +0 -19
- package/dist/modules/search/module.d.ts +0 -8
- package/dist/modules/search/module.d.ts.map +0 -1
- package/dist/modules/search/module.js +0 -22
- package/dist/modules/search/repository/index.d.ts +0 -5
- package/dist/modules/search/repository/index.d.ts.map +0 -1
- package/dist/modules/search/repository/index.js +0 -1
- package/dist/modules/settings/module.d.ts +0 -6
- package/dist/modules/settings/module.d.ts.map +0 -1
- package/dist/modules/settings/module.js +0 -12
- package/dist/modules/shipping/module.d.ts +0 -12
- package/dist/modules/shipping/module.d.ts.map +0 -1
- package/dist/modules/shipping/module.js +0 -14
- package/dist/modules/tax/module.d.ts +0 -7
- package/dist/modules/tax/module.d.ts.map +0 -1
- package/dist/modules/tax/module.js +0 -13
- package/dist/modules/webhooks/index.d.ts +0 -2
- package/dist/modules/webhooks/index.d.ts.map +0 -1
- package/dist/modules/webhooks/index.js +0 -1
- package/dist/modules/webhooks/module.d.ts +0 -403
- package/dist/modules/webhooks/module.d.ts.map +0 -1
- package/dist/modules/webhooks/module.js +0 -16
- package/dist/test-utils/create-repository-test-harness.d.ts +0 -8
- package/dist/test-utils/create-repository-test-harness.d.ts.map +0 -1
- package/dist/test-utils/create-repository-test-harness.js +0 -7
- package/dist/test-utils/create-test-plugin-context.d.ts +0 -38
- package/dist/test-utils/create-test-plugin-context.d.ts.map +0 -1
- package/dist/test-utils/create-test-plugin-context.js +0 -39
- package/dist/test-utils/typed-hooks.d.ts +0 -44
- package/dist/test-utils/typed-hooks.d.ts.map +0 -1
- package/dist/test-utils/typed-hooks.js +0 -36
- package/dist/types/commerce-types.d.ts +0 -34
- package/dist/types/commerce-types.d.ts.map +0 -1
- package/dist/types/commerce-types.js +0 -1
- package/src/auth/access.ts +0 -187
- package/src/generated/plugin-capabilities.d.ts +0 -21
- package/src/generated/plugin-manifest.ts +0 -24
- package/src/generated/plugin-repositories.d.ts +0 -21
- package/src/kernel/factory/repository-factory.ts +0 -244
- package/src/kernel/http-error.ts +0 -44
- package/src/kernel/jobs/builtin-job-tasks.ts +0 -17
- package/src/kernel/module/define.ts +0 -36
- package/src/kernel/module/index.ts +0 -3
- package/src/kernel/module/topo-sort.ts +0 -99
- package/src/kernel/query/executor.ts +0 -184
- package/src/kernel/query/registry.ts +0 -46
- package/src/kernel/service-registry.ts +0 -76
- package/src/modules/analytics/hooks.ts +0 -11
- package/src/modules/analytics/module.ts +0 -35
- package/src/modules/analytics/repository/index.ts +0 -5
- package/src/modules/audit/index.ts +0 -1
- package/src/modules/audit/module.ts +0 -11
- package/src/modules/cart/access.ts +0 -27
- package/src/modules/cart/module.ts +0 -32
- package/src/modules/catalog/module.ts +0 -80
- package/src/modules/customers/index.ts +0 -1
- package/src/modules/customers/module.ts +0 -29
- package/src/modules/documents/module.ts +0 -21
- package/src/modules/fulfillment/module.ts +0 -44
- package/src/modules/inventory/module.ts +0 -37
- package/src/modules/media/index.ts +0 -1
- package/src/modules/media/module.ts +0 -27
- package/src/modules/orders/module.ts +0 -67
- package/src/modules/organization/index.ts +0 -1
- package/src/modules/organization/module.ts +0 -11
- package/src/modules/payments/module.ts +0 -14
- package/src/modules/payments/repository/index.ts +0 -5
- package/src/modules/pricing/index.ts +0 -1
- package/src/modules/pricing/module.ts +0 -32
- package/src/modules/promotions/module.ts +0 -34
- package/src/modules/search/module.ts +0 -32
- package/src/modules/search/repository/index.ts +0 -5
- package/src/modules/settings/module.ts +0 -20
- package/src/modules/shipping/module.ts +0 -27
- package/src/modules/tax/module.ts +0 -21
- package/src/modules/webhooks/index.ts +0 -1
- package/src/modules/webhooks/module.ts +0 -24
- package/src/test-utils/create-repository-test-harness.ts +0 -16
- package/src/test-utils/create-test-plugin-context.ts +0 -66
- package/src/test-utils/typed-hooks.ts +0 -55
- package/src/types/commerce-types.ts +0 -34
|
@@ -4,15 +4,13 @@ import { assertPermission } from "../../auth/permissions.js";
|
|
|
4
4
|
import type { Actor } from "../../auth/types.js";
|
|
5
5
|
import type { CommerceConfig } from "../../config/types.js";
|
|
6
6
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
7
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
8
7
|
import type { TxContext } from "../../kernel/database/tx-context.js";
|
|
9
8
|
import { CommerceNotFoundError, CommerceValidationError, toCommerceError } from "../../kernel/errors.js";
|
|
10
9
|
import { runAfterHooks } from "../../kernel/hooks/executor.js";
|
|
11
|
-
import {
|
|
10
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
12
11
|
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
13
12
|
import type { AfterHook, HookContext } from "../../kernel/hooks/types.js";
|
|
14
13
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
15
|
-
import { createLogger } from "../../utils/logger.js";
|
|
16
14
|
import type {
|
|
17
15
|
FulfillmentRecord as FulfillmentDbRow,
|
|
18
16
|
FulfillmentRecordInsert,
|
|
@@ -25,7 +23,6 @@ import type {
|
|
|
25
23
|
FulfillmentStrategy,
|
|
26
24
|
FulfillmentStrategyContext,
|
|
27
25
|
} from "./types.js";
|
|
28
|
-
import { makeId } from "../../utils/id.js";
|
|
29
26
|
|
|
30
27
|
interface InventoryServiceLike {
|
|
31
28
|
adjust(input: {
|
|
@@ -90,7 +87,7 @@ class PhysicalFulfillmentStrategy implements FulfillmentStrategy {
|
|
|
90
87
|
_context: FulfillmentStrategyContext,
|
|
91
88
|
): Promise<Result<FulfillmentRecord>> {
|
|
92
89
|
return Ok({
|
|
93
|
-
id:
|
|
90
|
+
id: crypto.randomUUID(),
|
|
94
91
|
orderId: lineItem.orderId,
|
|
95
92
|
type: this.type,
|
|
96
93
|
status: "pending",
|
|
@@ -122,7 +119,7 @@ class DigitalDownloadFulfillmentStrategy implements FulfillmentStrategy {
|
|
|
122
119
|
): Promise<Result<FulfillmentRecord>> {
|
|
123
120
|
const expiresAt = new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString();
|
|
124
121
|
return Ok({
|
|
125
|
-
id:
|
|
122
|
+
id: crypto.randomUUID(),
|
|
126
123
|
orderId: lineItem.orderId,
|
|
127
124
|
type: this.type,
|
|
128
125
|
status: "fulfilled",
|
|
@@ -162,7 +159,7 @@ class DigitalAccessFulfillmentStrategy implements FulfillmentStrategy {
|
|
|
162
159
|
_context: FulfillmentStrategyContext,
|
|
163
160
|
): Promise<Result<FulfillmentRecord>> {
|
|
164
161
|
return Ok({
|
|
165
|
-
id:
|
|
162
|
+
id: crypto.randomUUID(),
|
|
166
163
|
orderId: lineItem.orderId,
|
|
167
164
|
type: this.type,
|
|
168
165
|
status: "fulfilled",
|
|
@@ -200,7 +197,7 @@ class InternalTransferFulfillmentStrategy implements FulfillmentStrategy {
|
|
|
200
197
|
_context: FulfillmentStrategyContext,
|
|
201
198
|
): Promise<Result<FulfillmentRecord>> {
|
|
202
199
|
return Ok({
|
|
203
|
-
id:
|
|
200
|
+
id: crypto.randomUUID(),
|
|
204
201
|
orderId: lineItem.orderId,
|
|
205
202
|
type: this.type,
|
|
206
203
|
status: "processing",
|
|
@@ -231,7 +228,7 @@ class AppointmentFulfillmentStrategy implements FulfillmentStrategy {
|
|
|
231
228
|
_context: FulfillmentStrategyContext,
|
|
232
229
|
): Promise<Result<FulfillmentRecord>> {
|
|
233
230
|
return Ok({
|
|
234
|
-
id:
|
|
231
|
+
id: crypto.randomUUID(),
|
|
235
232
|
orderId: lineItem.orderId,
|
|
236
233
|
type: this.type,
|
|
237
234
|
status: "pending",
|
|
@@ -328,15 +325,7 @@ export class FulfillmentService {
|
|
|
328
325
|
const afterHooks = this.deps.hooks.resolve(
|
|
329
326
|
"fulfillment.afterCreate",
|
|
330
327
|
) as AfterHook<FulfillmentRecord>[];
|
|
331
|
-
const hookCtx: HookContext =
|
|
332
|
-
actor: actor ?? ctx?.actor ?? null,
|
|
333
|
-
tx: ctx?.tx ?? null,
|
|
334
|
-
logger: createLogger("fulfillment"),
|
|
335
|
-
services: this.deps.services,
|
|
336
|
-
context: { moduleName: "fulfillment" },
|
|
337
|
-
database: { db: this.deps.database.db as PluginDb },
|
|
338
|
-
commerceConfig: this.deps.config,
|
|
339
|
-
});
|
|
328
|
+
const hookCtx: HookContext = createModuleHookContext("fulfillment", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
340
329
|
await runAfterHooks(afterHooks, null, record, "create", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
341
330
|
|
|
342
331
|
// Create a fulfillment line item linking this fulfillment to the order line item
|
|
@@ -487,15 +476,7 @@ export class FulfillmentService {
|
|
|
487
476
|
const afterHooks = this.deps.hooks.resolve(
|
|
488
477
|
"fulfillment.afterCreate",
|
|
489
478
|
) as AfterHook<FulfillmentRecord>[];
|
|
490
|
-
const hookCtx: HookContext =
|
|
491
|
-
actor: actor ?? ctx?.actor ?? null,
|
|
492
|
-
tx: ctx?.tx ?? null,
|
|
493
|
-
logger: createLogger("fulfillment"),
|
|
494
|
-
services: this.deps.services,
|
|
495
|
-
context: { moduleName: "fulfillment" },
|
|
496
|
-
database: { db: this.deps.database.db as PluginDb },
|
|
497
|
-
commerceConfig: this.deps.config,
|
|
498
|
-
});
|
|
479
|
+
const hookCtx: HookContext = createModuleHookContext("fulfillment", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
499
480
|
await runAfterHooks(afterHooks, null, record, "create", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
500
481
|
|
|
501
482
|
return Ok(record);
|
|
@@ -10,13 +10,11 @@ import {
|
|
|
10
10
|
toCommerceError,
|
|
11
11
|
} from "../../kernel/errors.js";
|
|
12
12
|
import { runAfterHooks } from "../../kernel/hooks/executor.js";
|
|
13
|
-
import {
|
|
13
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
14
14
|
import type { HookContext } from "../../kernel/hooks/types.js";
|
|
15
15
|
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
16
16
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
17
|
-
import { createLogger } from "../../utils/logger.js";
|
|
18
17
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
19
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
20
18
|
import { createTxContext, type TxContext } from "../../kernel/database/tx-context.js";
|
|
21
19
|
import {
|
|
22
20
|
InventoryRepository,
|
|
@@ -438,15 +436,7 @@ export class InventoryService {
|
|
|
438
436
|
txCtx,
|
|
439
437
|
);
|
|
440
438
|
|
|
441
|
-
const hookCtx: HookContext =
|
|
442
|
-
actor: actor ?? null,
|
|
443
|
-
tx: txCtx.tx,
|
|
444
|
-
logger: createLogger("inventory.adjust"),
|
|
445
|
-
services: this.deps.services,
|
|
446
|
-
context: { moduleName: "inventory" },
|
|
447
|
-
database: { db: this.deps.database.db as PluginDb },
|
|
448
|
-
commerceConfig: this.deps.config,
|
|
449
|
-
});
|
|
439
|
+
const hookCtx: HookContext = createModuleHookContext("inventory", this.deps, actor ?? null, txCtx.tx, { logScope: "inventory.adjust" });
|
|
450
440
|
|
|
451
441
|
const afterHooks = this.deps.hooks.resolve("inventory.afterAdjust");
|
|
452
442
|
await runAfterHooks(
|
|
@@ -622,15 +612,7 @@ export class InventoryService {
|
|
|
622
612
|
organizationId: orgId,
|
|
623
613
|
entities: [...byEntity].map(([entityId, levels]) => ({ entityId, levels })),
|
|
624
614
|
};
|
|
625
|
-
const hookCtx: HookContext =
|
|
626
|
-
actor: actor ?? null,
|
|
627
|
-
tx: txCtx.tx,
|
|
628
|
-
logger: createLogger("inventory.adjustMany"),
|
|
629
|
-
services: this.deps.services,
|
|
630
|
-
context: { moduleName: "inventory" },
|
|
631
|
-
database: { db: this.deps.database.db as PluginDb },
|
|
632
|
-
commerceConfig: this.deps.config,
|
|
633
|
-
});
|
|
615
|
+
const hookCtx: HookContext = createModuleHookContext("inventory", this.deps, actor ?? null, txCtx.tx, { logScope: "inventory.adjustMany" });
|
|
634
616
|
await runAfterHooks(
|
|
635
617
|
this.deps.hooks.resolve("inventory.afterAdjustMany") as Parameters<typeof runAfterHooks>[0],
|
|
636
618
|
null,
|
|
@@ -15,8 +15,8 @@ import type { CatalogRepository } from "../catalog/repository/index.js";
|
|
|
15
15
|
import type { TxContext } from "../../kernel/database/tx-context.js";
|
|
16
16
|
import { createTxContext } from "../../kernel/database/tx-context.js";
|
|
17
17
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
18
|
-
import { makeId } from "../../utils/id.js";
|
|
19
18
|
import type { MediaAssetOrigin } from "./schema.js";
|
|
19
|
+
import { isUniqueViolation } from "../../kernel/database/unique-violation.js";
|
|
20
20
|
|
|
21
21
|
export interface UploadMediaInput {
|
|
22
22
|
filename: string;
|
|
@@ -66,12 +66,6 @@ export function assertMediaWritable(asset: Pick<MediaAsset, "origin">, actor: Ac
|
|
|
66
66
|
if (asset.origin === "merchant") assertPermission(actor, "media:write");
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function isUniqueViolation(error: unknown): boolean {
|
|
70
|
-
if (error == null || typeof error !== "object") return false;
|
|
71
|
-
const value = error as { code?: unknown; cause?: unknown };
|
|
72
|
-
if (value.code === "23505") return true;
|
|
73
|
-
return isUniqueViolation(value.cause);
|
|
74
|
-
}
|
|
75
69
|
|
|
76
70
|
function isSvgOrXml(buffer: Uint8Array): boolean {
|
|
77
71
|
const prefix = new TextDecoder()
|
|
@@ -160,7 +154,7 @@ export class MediaService {
|
|
|
160
154
|
);
|
|
161
155
|
}
|
|
162
156
|
|
|
163
|
-
const id =
|
|
157
|
+
const id = crypto.randomUUID();
|
|
164
158
|
const key = `${new Date().getFullYear()}/${id}-${input.filename}`;
|
|
165
159
|
const uploaded = await this.deps.storage.upload(
|
|
166
160
|
key,
|
|
@@ -12,7 +12,6 @@ import type { Actor } from "../../auth/types.js";
|
|
|
12
12
|
import type { ServiceContainer } from "../../kernel/hooks/types.js";
|
|
13
13
|
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
14
14
|
import type { ShippingAddress } from "../shipping/calculator.js";
|
|
15
|
-
import { makeId } from "../../utils/id.js";
|
|
16
15
|
|
|
17
16
|
export interface OrderPricingInput {
|
|
18
17
|
currency: string;
|
|
@@ -65,7 +64,7 @@ export async function computeOrderPricing(
|
|
|
65
64
|
tx?: unknown,
|
|
66
65
|
): Promise<OrderPricingBreakdown> {
|
|
67
66
|
const data: CheckoutData = {
|
|
68
|
-
checkoutId:
|
|
67
|
+
checkoutId: crypto.randomUUID(),
|
|
69
68
|
cartId: "",
|
|
70
69
|
currency: input.currency,
|
|
71
70
|
paymentMethodId: "",
|
|
@@ -13,13 +13,8 @@ import {
|
|
|
13
13
|
toCommerceError,
|
|
14
14
|
} from "../../kernel/errors.js";
|
|
15
15
|
import { runAfterHooks, runBeforeHooks } from "../../kernel/hooks/executor.js";
|
|
16
|
-
import {
|
|
17
|
-
import type {
|
|
18
|
-
import type {
|
|
19
|
-
AfterHook,
|
|
20
|
-
BeforeHook,
|
|
21
|
-
HookContext,
|
|
22
|
-
} from "../../kernel/hooks/types.js";
|
|
16
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
17
|
+
import type { AfterHook, BeforeHook } from "../../kernel/hooks/types.js";
|
|
23
18
|
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
24
19
|
import {
|
|
25
20
|
canTransition,
|
|
@@ -28,7 +23,6 @@ import {
|
|
|
28
23
|
type StateDefinition,
|
|
29
24
|
} from "../../kernel/state-machine/machine.js";
|
|
30
25
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
31
|
-
import { createLogger } from "../../utils/logger.js";
|
|
32
26
|
import { makeIdempotencyScope } from "../../utils/id.js";
|
|
33
27
|
import { paginate, type Pagination } from "../../utils/pagination.js";
|
|
34
28
|
import {
|
|
@@ -36,7 +30,6 @@ import {
|
|
|
36
30
|
type TxContext,
|
|
37
31
|
} from "../../kernel/database/tx-context.js";
|
|
38
32
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
39
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
40
33
|
import {
|
|
41
34
|
OrdersRepository,
|
|
42
35
|
type Order,
|
|
@@ -143,24 +136,6 @@ type BeforeStatusChangeHook = BeforeHook<StatusChangeHookInput>;
|
|
|
143
136
|
*/
|
|
144
137
|
type AfterStatusChangeHook = AfterHook<HydratedOrder, StatusChangeHookInput>;
|
|
145
138
|
|
|
146
|
-
function context(
|
|
147
|
-
actor: Actor | null,
|
|
148
|
-
services: Record<string, unknown>,
|
|
149
|
-
database: DatabaseAdapter,
|
|
150
|
-
config: CommerceConfig,
|
|
151
|
-
tx: unknown = null,
|
|
152
|
-
): HookContext {
|
|
153
|
-
return createHookContext({
|
|
154
|
-
actor,
|
|
155
|
-
tx,
|
|
156
|
-
logger: createLogger("orders"),
|
|
157
|
-
services,
|
|
158
|
-
...(services.jobs ? { jobs: services.jobs as JobsAdapter } : {}),
|
|
159
|
-
context: { moduleName: "orders" },
|
|
160
|
-
database: { db: database.db as PluginDb },
|
|
161
|
-
commerceConfig: config,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
139
|
|
|
165
140
|
export class OrderService {
|
|
166
141
|
private readonly repo: OrdersRepository;
|
|
@@ -522,7 +497,7 @@ export class OrderService {
|
|
|
522
497
|
const afterHooks = this.deps.hooks.resolve(
|
|
523
498
|
"orders.afterCreate",
|
|
524
499
|
) as AfterCreateOrderHook[];
|
|
525
|
-
const hookCtx =
|
|
500
|
+
const hookCtx = createModuleHookContext("orders", this.deps, actor, ctx?.tx);
|
|
526
501
|
|
|
527
502
|
const processed = await runBeforeHooks(
|
|
528
503
|
beforeHooks,
|
|
@@ -804,7 +779,7 @@ export class OrderService {
|
|
|
804
779
|
"orders.afterGet",
|
|
805
780
|
) as AfterHook<HydratedOrder>[];
|
|
806
781
|
if (afterGetHooks.length > 0) {
|
|
807
|
-
const hookCtx =
|
|
782
|
+
const hookCtx = createModuleHookContext("orders", this.deps, actor, ctx?.tx);
|
|
808
783
|
await runAfterHooks(afterGetHooks, null, hydrated, "read", hookCtx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
809
784
|
}
|
|
810
785
|
|
|
@@ -1013,7 +988,7 @@ export class OrderService {
|
|
|
1013
988
|
"orders.afterStatusChange",
|
|
1014
989
|
) as AfterStatusChangeHook[];
|
|
1015
990
|
|
|
1016
|
-
const hookCtx =
|
|
991
|
+
const hookCtx = createModuleHookContext("orders", this.deps, actor, ctx?.tx);
|
|
1017
992
|
const statusHookInput: StatusChangeHookInput = {
|
|
1018
993
|
orderId: order.id,
|
|
1019
994
|
fromStatus: order.status as OrderState,
|
|
@@ -2,18 +2,16 @@ import { resolveOrgIdForCommerce } from "../../auth/org.js";
|
|
|
2
2
|
import type { Actor } from "../../auth/types.js";
|
|
3
3
|
import type { CommerceConfig } from "../../config/types.js";
|
|
4
4
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
5
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
6
5
|
import type { TxContext } from "../../kernel/database/tx-context.js";
|
|
7
6
|
import {
|
|
8
7
|
CommerceNotFoundError,
|
|
9
8
|
CommerceValidationError,
|
|
10
9
|
} from "../../kernel/errors.js";
|
|
11
10
|
import { runAfterHooks } from "../../kernel/hooks/executor.js";
|
|
12
|
-
import {
|
|
11
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
13
12
|
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
14
|
-
import type { AfterHook
|
|
13
|
+
import type { AfterHook } from "../../kernel/hooks/types.js";
|
|
15
14
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
16
|
-
import { createLogger } from "../../utils/logger.js";
|
|
17
15
|
import type {
|
|
18
16
|
PricingRepository,
|
|
19
17
|
Price,
|
|
@@ -39,23 +37,6 @@ interface PricingServiceDeps {
|
|
|
39
37
|
database: DatabaseAdapter;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
function hookContext(
|
|
43
|
-
actor: Actor | null,
|
|
44
|
-
services: Record<string, unknown>,
|
|
45
|
-
database: DatabaseAdapter,
|
|
46
|
-
config: CommerceConfig,
|
|
47
|
-
tx: unknown,
|
|
48
|
-
): HookContext {
|
|
49
|
-
return createHookContext({
|
|
50
|
-
actor,
|
|
51
|
-
tx,
|
|
52
|
-
logger: createLogger("pricing"),
|
|
53
|
-
services,
|
|
54
|
-
context: { moduleName: "pricing" },
|
|
55
|
-
database: { db: database.db as PluginDb },
|
|
56
|
-
commerceConfig: config,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
40
|
|
|
60
41
|
export interface PriceResolutionContext {
|
|
61
42
|
entityId: string;
|
|
@@ -92,6 +73,7 @@ export interface ResolvedPrice {
|
|
|
92
73
|
|
|
93
74
|
export type { SetBasePriceInput, CreatePriceModifierInput } from "./schemas.js";
|
|
94
75
|
import type { SetBasePriceInput, CreatePriceModifierInput } from "./schemas.js";
|
|
76
|
+
import { normalizeCurrency } from "../../utils/money.js";
|
|
95
77
|
|
|
96
78
|
function matchesQuantity(
|
|
97
79
|
min: number | null | undefined,
|
|
@@ -190,9 +172,6 @@ function toGroupSet(context: PriceResolutionContext): Set<string> {
|
|
|
190
172
|
return new Set(context.customerGroupIds ?? []);
|
|
191
173
|
}
|
|
192
174
|
|
|
193
|
-
function normalizeCurrency(currency: string): string {
|
|
194
|
-
return currency.trim().toUpperCase();
|
|
195
|
-
}
|
|
196
175
|
|
|
197
176
|
export class PricingService {
|
|
198
177
|
private readonly repo: PricingRepository;
|
|
@@ -269,9 +248,7 @@ export class PricingService {
|
|
|
269
248
|
const afterHooks = this.deps.hooks.resolve(
|
|
270
249
|
"pricing.afterCreate",
|
|
271
250
|
) as AfterHook<Price>[];
|
|
272
|
-
const hctx =
|
|
273
|
-
actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null,
|
|
274
|
-
);
|
|
251
|
+
const hctx = createModuleHookContext("pricing", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
275
252
|
await runAfterHooks(afterHooks, null, record, "create", hctx);
|
|
276
253
|
|
|
277
254
|
return Ok(record);
|
|
@@ -326,9 +303,7 @@ export class PricingService {
|
|
|
326
303
|
const afterHooks = this.deps.hooks.resolve(
|
|
327
304
|
"pricing.afterCreate",
|
|
328
305
|
) as AfterHook<PriceModifier>[];
|
|
329
|
-
const hctx =
|
|
330
|
-
actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null,
|
|
331
|
-
);
|
|
306
|
+
const hctx = createModuleHookContext("pricing", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
332
307
|
await runAfterHooks(afterHooks, null, modifier, "create", hctx);
|
|
333
308
|
|
|
334
309
|
return Ok(modifier);
|
|
@@ -388,6 +363,13 @@ export class PricingService {
|
|
|
388
363
|
},
|
|
389
364
|
ctx,
|
|
390
365
|
);
|
|
366
|
+
|
|
367
|
+
const afterHooks = this.deps.hooks.resolve(
|
|
368
|
+
"pricing.afterUpdate",
|
|
369
|
+
) as AfterHook<PriceModifier>[];
|
|
370
|
+
const hctx = createModuleHookContext("pricing", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
371
|
+
await runAfterHooks(afterHooks, existing, updated!, "update", hctx);
|
|
372
|
+
|
|
391
373
|
return Ok(updated!);
|
|
392
374
|
}
|
|
393
375
|
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
2
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
3
2
|
import type { TxContext } from "../../kernel/database/tx-context.js";
|
|
4
3
|
import {
|
|
5
4
|
CommerceNotFoundError,
|
|
6
5
|
CommerceValidationError,
|
|
7
6
|
} from "../../kernel/errors.js";
|
|
8
7
|
import { runAfterHooks } from "../../kernel/hooks/executor.js";
|
|
9
|
-
import {
|
|
8
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
10
9
|
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
11
|
-
import type { AfterHook
|
|
10
|
+
import type { AfterHook } from "../../kernel/hooks/types.js";
|
|
12
11
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
13
|
-
import { createLogger } from "../../utils/logger.js";
|
|
14
12
|
import type {
|
|
15
13
|
PromotionsRepository,
|
|
16
14
|
Promotion,
|
|
@@ -41,23 +39,6 @@ interface PromotionServiceDeps {
|
|
|
41
39
|
database: DatabaseAdapter;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
function hookContext(
|
|
45
|
-
actor: Actor | null,
|
|
46
|
-
services: Record<string, unknown>,
|
|
47
|
-
database: DatabaseAdapter,
|
|
48
|
-
config: CommerceConfig,
|
|
49
|
-
tx: unknown,
|
|
50
|
-
): HookContext {
|
|
51
|
-
return createHookContext({
|
|
52
|
-
actor,
|
|
53
|
-
tx,
|
|
54
|
-
logger: createLogger("promotions"),
|
|
55
|
-
services,
|
|
56
|
-
context: { moduleName: "promotions" },
|
|
57
|
-
database: { db: database.db as PluginDb },
|
|
58
|
-
commerceConfig: config,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
42
|
|
|
62
43
|
export interface PromotionLineItem {
|
|
63
44
|
entityId: string;
|
|
@@ -242,9 +223,7 @@ export class PromotionService {
|
|
|
242
223
|
const afterHooks = this.deps.hooks.resolve(
|
|
243
224
|
"promotions.afterCreate",
|
|
244
225
|
) as AfterHook<Promotion>[];
|
|
245
|
-
const hctx =
|
|
246
|
-
actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null,
|
|
247
|
-
);
|
|
226
|
+
const hctx = createModuleHookContext("promotions", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
248
227
|
await runAfterHooks(afterHooks, null, promotion, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
249
228
|
|
|
250
229
|
return Ok(promotion);
|
|
@@ -265,7 +244,7 @@ export class PromotionService {
|
|
|
265
244
|
"promotions.afterUpdate",
|
|
266
245
|
) as AfterHook<Promotion>[];
|
|
267
246
|
// Actor-less by design; resolves to the deployment's declared organization.
|
|
268
|
-
const hctx =
|
|
247
|
+
const hctx = createModuleHookContext("promotions", this.deps, null, ctx?.tx ?? null);
|
|
269
248
|
await runAfterHooks(afterHooks, promotion, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
270
249
|
|
|
271
250
|
return Ok(updated);
|
|
@@ -342,9 +321,7 @@ export class PromotionService {
|
|
|
342
321
|
const afterHooks = this.deps.hooks.resolve(
|
|
343
322
|
"promotions.afterUpdate",
|
|
344
323
|
) as AfterHook<Promotion>[];
|
|
345
|
-
const hctx =
|
|
346
|
-
actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null,
|
|
347
|
-
);
|
|
324
|
+
const hctx = createModuleHookContext("promotions", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
348
325
|
await runAfterHooks(afterHooks, existing, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
349
326
|
|
|
350
327
|
return Ok(updated);
|
|
@@ -15,13 +15,13 @@ import type { TaxClass, TaxRate, TaxRatesRepository } from "./repository/index.j
|
|
|
15
15
|
|
|
16
16
|
interface TaxServiceDeps {
|
|
17
17
|
adapter: TaxAdapter | undefined;
|
|
18
|
-
repository
|
|
18
|
+
repository: TaxRatesRepository;
|
|
19
19
|
config: CommerceConfig;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class TaxService {
|
|
23
23
|
private adapter: TaxAdapter | undefined;
|
|
24
|
-
private repository: TaxRatesRepository
|
|
24
|
+
private repository: TaxRatesRepository;
|
|
25
25
|
private config: CommerceConfig;
|
|
26
26
|
|
|
27
27
|
constructor(deps: TaxServiceDeps) {
|
|
@@ -47,14 +47,14 @@ export class TaxService {
|
|
|
47
47
|
orgId?: string,
|
|
48
48
|
ctx?: TxContext,
|
|
49
49
|
): Promise<Result<TaxCalculationResult>> {
|
|
50
|
-
if (
|
|
50
|
+
if (orgId && params.lineItems.length > 0) {
|
|
51
51
|
const classes = await this.repository.findActiveClasses(orgId, ctx);
|
|
52
52
|
if (classes.length > 0) {
|
|
53
53
|
return Ok(await this.calculateByClasses(params, classes, ctx));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
if (
|
|
57
|
+
if (orgId && params.toAddress) {
|
|
58
58
|
const matched = await this.matchRuntimeRates(orgId, params.toAddress, ctx);
|
|
59
59
|
if (matched.length > 0) {
|
|
60
60
|
// Subtract the order-level discount from the taxable base too (audit
|
|
@@ -110,7 +110,7 @@ export class TaxService {
|
|
|
110
110
|
const byName = new Map(classes.map((c) => [c.name, c]));
|
|
111
111
|
const defaultClass = classes.find((c) => c.isDefault) ?? null;
|
|
112
112
|
|
|
113
|
-
const { byEntity, byVariant } = await this.repository
|
|
113
|
+
const { byEntity, byVariant } = await this.repository.resolveCatalogTaxClasses(
|
|
114
114
|
params.lineItems.map((li) => ({ entityId: li.entityId, variantId: li.variantId })),
|
|
115
115
|
ctx,
|
|
116
116
|
);
|
|
@@ -175,14 +175,12 @@ export class TaxService {
|
|
|
175
175
|
actor?: Actor | null,
|
|
176
176
|
ctx?: TxContext,
|
|
177
177
|
): Promise<Result<TaxClass>> {
|
|
178
|
-
const repo = this.requireRepository();
|
|
179
|
-
if (!repo.ok) return repo;
|
|
180
178
|
if (input.rateBps < 0) {
|
|
181
179
|
return Err(new CommerceValidationError("rateBps must be non-negative."));
|
|
182
180
|
}
|
|
183
181
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
184
|
-
if (input.isDefault) await
|
|
185
|
-
const created = await
|
|
182
|
+
if (input.isDefault) await this.repository.clearDefaultClass(orgId, ctx);
|
|
183
|
+
const created = await this.repository.createClass(
|
|
186
184
|
{
|
|
187
185
|
organizationId: orgId,
|
|
188
186
|
name: input.name,
|
|
@@ -196,10 +194,8 @@ export class TaxService {
|
|
|
196
194
|
}
|
|
197
195
|
|
|
198
196
|
async listTaxClasses(actor?: Actor | null, ctx?: TxContext): Promise<Result<TaxClass[]>> {
|
|
199
|
-
const repo = this.requireRepository();
|
|
200
|
-
if (!repo.ok) return repo;
|
|
201
197
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
202
|
-
return Ok(await
|
|
198
|
+
return Ok(await this.repository.findAllClasses(orgId, ctx));
|
|
203
199
|
}
|
|
204
200
|
|
|
205
201
|
async updateTaxClass(
|
|
@@ -208,13 +204,11 @@ export class TaxService {
|
|
|
208
204
|
actor?: Actor | null,
|
|
209
205
|
ctx?: TxContext,
|
|
210
206
|
): Promise<Result<TaxClass>> {
|
|
211
|
-
const repo = this.requireRepository();
|
|
212
|
-
if (!repo.ok) return repo;
|
|
213
207
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
214
|
-
const existing = await
|
|
208
|
+
const existing = await this.repository.findClassById(orgId, id, ctx);
|
|
215
209
|
if (!existing) return Err(new CommerceNotFoundError("Tax class not found."));
|
|
216
|
-
if (patch.isDefault) await
|
|
217
|
-
const updated = await
|
|
210
|
+
if (patch.isDefault) await this.repository.clearDefaultClass(orgId, ctx);
|
|
211
|
+
const updated = await this.repository.updateClass(
|
|
218
212
|
id,
|
|
219
213
|
{
|
|
220
214
|
...(patch.name !== undefined ? { name: patch.name } : {}),
|
|
@@ -228,12 +222,10 @@ export class TaxService {
|
|
|
228
222
|
}
|
|
229
223
|
|
|
230
224
|
async deleteTaxClass(id: string, actor?: Actor | null, ctx?: TxContext): Promise<Result<{ deleted: true }>> {
|
|
231
|
-
const repo = this.requireRepository();
|
|
232
|
-
if (!repo.ok) return repo;
|
|
233
225
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
234
|
-
const existing = await
|
|
226
|
+
const existing = await this.repository.findClassById(orgId, id, ctx);
|
|
235
227
|
if (!existing) return Err(new CommerceNotFoundError("Tax class not found."));
|
|
236
|
-
await
|
|
228
|
+
await this.repository.deleteClass(id, ctx);
|
|
237
229
|
return Ok({ deleted: true });
|
|
238
230
|
}
|
|
239
231
|
|
|
@@ -242,7 +234,7 @@ export class TaxService {
|
|
|
242
234
|
toAddress: { country: string; state?: string },
|
|
243
235
|
ctx?: TxContext,
|
|
244
236
|
): Promise<TaxRate[]> {
|
|
245
|
-
const rates = await this.repository
|
|
237
|
+
const rates = await this.repository.findActive(orgId, ctx);
|
|
246
238
|
if (rates.length === 0) return [];
|
|
247
239
|
const country = toAddress.country?.toUpperCase();
|
|
248
240
|
const state = toAddress.state?.toUpperCase();
|
|
@@ -267,21 +259,9 @@ export class TaxService {
|
|
|
267
259
|
return this.adapter.voidTransaction(params);
|
|
268
260
|
}
|
|
269
261
|
|
|
270
|
-
requireConfigured(): Result<TaxAdapter> {
|
|
271
|
-
if (!this.adapter) {
|
|
272
|
-
return Err(new CommerceValidationError("Tax adapter is not configured."));
|
|
273
|
-
}
|
|
274
|
-
return Ok(this.adapter);
|
|
275
|
-
}
|
|
276
262
|
|
|
277
263
|
// ── Runtime tax-rate management (issue #45) ────────────────────────────
|
|
278
264
|
|
|
279
|
-
private requireRepository(): Result<TaxRatesRepository> {
|
|
280
|
-
if (!this.repository) {
|
|
281
|
-
return Err(new CommerceValidationError("Tax rate persistence is not available."));
|
|
282
|
-
}
|
|
283
|
-
return Ok(this.repository);
|
|
284
|
-
}
|
|
285
265
|
|
|
286
266
|
async createTaxRate(
|
|
287
267
|
input: {
|
|
@@ -296,13 +276,11 @@ export class TaxService {
|
|
|
296
276
|
actor?: Actor | null,
|
|
297
277
|
ctx?: TxContext,
|
|
298
278
|
): Promise<Result<TaxRate>> {
|
|
299
|
-
const repo = this.requireRepository();
|
|
300
|
-
if (!repo.ok) return repo;
|
|
301
279
|
if (input.rateBps < 0) {
|
|
302
280
|
return Err(new CommerceValidationError("rateBps must be non-negative."));
|
|
303
281
|
}
|
|
304
282
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
305
|
-
const rate = await
|
|
283
|
+
const rate = await this.repository.create(
|
|
306
284
|
{
|
|
307
285
|
organizationId: orgId,
|
|
308
286
|
name: input.name,
|
|
@@ -319,10 +297,8 @@ export class TaxService {
|
|
|
319
297
|
}
|
|
320
298
|
|
|
321
299
|
async listTaxRates(actor?: Actor | null, ctx?: TxContext): Promise<Result<TaxRate[]>> {
|
|
322
|
-
const repo = this.requireRepository();
|
|
323
|
-
if (!repo.ok) return repo;
|
|
324
300
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
325
|
-
return Ok(await
|
|
301
|
+
return Ok(await this.repository.findAll(orgId, ctx));
|
|
326
302
|
}
|
|
327
303
|
|
|
328
304
|
async updateTaxRate(
|
|
@@ -339,12 +315,10 @@ export class TaxService {
|
|
|
339
315
|
actor?: Actor | null,
|
|
340
316
|
ctx?: TxContext,
|
|
341
317
|
): Promise<Result<TaxRate>> {
|
|
342
|
-
const repo = this.requireRepository();
|
|
343
|
-
if (!repo.ok) return repo;
|
|
344
318
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
345
|
-
const existing = await
|
|
319
|
+
const existing = await this.repository.findById(orgId, id, ctx);
|
|
346
320
|
if (!existing) return Err(new CommerceNotFoundError("Tax rate not found."));
|
|
347
|
-
const updated = await
|
|
321
|
+
const updated = await this.repository.update(
|
|
348
322
|
id,
|
|
349
323
|
{
|
|
350
324
|
...(patch.name !== undefined ? { name: patch.name } : {}),
|
|
@@ -363,12 +337,10 @@ export class TaxService {
|
|
|
363
337
|
}
|
|
364
338
|
|
|
365
339
|
async deleteTaxRate(id: string, actor?: Actor | null, ctx?: TxContext): Promise<Result<{ deleted: true }>> {
|
|
366
|
-
const repo = this.requireRepository();
|
|
367
|
-
if (!repo.ok) return repo;
|
|
368
340
|
const orgId = resolveOrgIdForCommerce(actor ?? ctx?.actor ?? null, this.config);
|
|
369
|
-
const existing = await
|
|
341
|
+
const existing = await this.repository.findById(orgId, id, ctx);
|
|
370
342
|
if (!existing) return Err(new CommerceNotFoundError("Tax rate not found."));
|
|
371
|
-
await
|
|
343
|
+
await this.repository.delete(id, ctx);
|
|
372
344
|
return Ok({ deleted: true });
|
|
373
345
|
}
|
|
374
346
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolveOrgIdForCommerce } from "../../auth/org.js";
|
|
2
2
|
import type { AfterHook } from "../../kernel/hooks/types.js";
|
|
3
3
|
import type { InventoryAdjustManyResult } from "../inventory/service.js";
|
|
4
|
+
import { webhookDeliveryTask } from "./tasks.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Webhook delivery hook — enqueues delivery jobs instead of blocking.
|
|
@@ -27,7 +28,7 @@ export const deliverWebhooks: AfterHook<unknown> = async ({ result, operation, c
|
|
|
27
28
|
if (!endpoints.ok) return;
|
|
28
29
|
|
|
29
30
|
for (const endpoint of endpoints.value) {
|
|
30
|
-
await context.jobs.enqueue(
|
|
31
|
+
await context.jobs.enqueue(webhookDeliveryTask.slug, {
|
|
31
32
|
endpointId: endpoint.id,
|
|
32
33
|
endpointUrl: endpoint.url,
|
|
33
34
|
endpointSecret: endpoint.secret,
|
|
@@ -58,7 +59,7 @@ export const deliverWebhooksForAdjustMany: AfterHook<InventoryAdjustManyResult>
|
|
|
58
59
|
if (!endpoints.ok) return;
|
|
59
60
|
for (const endpoint of endpoints.value) {
|
|
60
61
|
for (const level of levels) {
|
|
61
|
-
await context.jobs.enqueue(
|
|
62
|
+
await context.jobs.enqueue(webhookDeliveryTask.slug, {
|
|
62
63
|
endpointId: endpoint.id,
|
|
63
64
|
endpointUrl: endpoint.url,
|
|
64
65
|
endpointSecret: endpoint.secret,
|