@porulle/core 0.64.0 → 0.65.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/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 +26 -29
- 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
|
@@ -93,33 +93,6 @@ export class AnalyticsService {
|
|
|
93
93
|
return this.deps.adapter.query(params, scope);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async getDashboard(name: string, scope: AnalyticsScope): Promise<Result<AnalyticsQueryResult>> {
|
|
97
|
-
const normalized = name.trim().toLowerCase();
|
|
98
|
-
|
|
99
|
-
if (normalized === "revenue" || normalized === "revenue-overview") {
|
|
100
|
-
return this.query({
|
|
101
|
-
measures: ["Orders.revenue", "Orders.count"],
|
|
102
|
-
timeDimensions: [{
|
|
103
|
-
dimension: "Orders.placedAt",
|
|
104
|
-
granularity: "month",
|
|
105
|
-
dateRange: "this month",
|
|
106
|
-
}],
|
|
107
|
-
order: { "Orders.placedAt": "asc" },
|
|
108
|
-
}, scope);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (normalized === "inventory" || normalized === "inventory-health") {
|
|
112
|
-
return this.query({
|
|
113
|
-
measures: ["Inventory.totalAvailable", "Inventory.lowStockCount"],
|
|
114
|
-
dimensions: ["Inventory.warehouseId"],
|
|
115
|
-
order: { "Inventory.totalAvailable": "desc" },
|
|
116
|
-
}, scope);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return Err(
|
|
120
|
-
new CommerceValidationError(`Unknown analytics dashboard: ${name}`),
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
96
|
|
|
124
97
|
/** The canned retail reports pack (issue #48). */
|
|
125
98
|
listReports(): Array<{ name: string; description: string }> {
|
|
@@ -161,15 +134,6 @@ export class AnalyticsService {
|
|
|
161
134
|
});
|
|
162
135
|
}
|
|
163
136
|
|
|
164
|
-
async meta(): Promise<Result<{ measures: string[]; dimensions: string[]; segments: string[] }>> {
|
|
165
|
-
const meta = await this.getMeta();
|
|
166
|
-
if (!meta.ok) return meta;
|
|
167
|
-
return Ok({
|
|
168
|
-
measures: meta.value.measures,
|
|
169
|
-
dimensions: meta.value.dimensions,
|
|
170
|
-
segments: meta.value.segments,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
137
|
|
|
174
138
|
// ─── Private ─────────────────────────────────────────────────────────────
|
|
175
139
|
|
|
@@ -14,18 +14,12 @@ import {
|
|
|
14
14
|
toCommerceError,
|
|
15
15
|
} from "../../kernel/errors.js";
|
|
16
16
|
import { runAfterHooks, runBeforeHooks } from "../../kernel/hooks/executor.js";
|
|
17
|
-
import {
|
|
18
|
-
import type {
|
|
19
|
-
AfterHook,
|
|
20
|
-
BeforeHook,
|
|
21
|
-
HookContext,
|
|
22
|
-
} from "../../kernel/hooks/types.js";
|
|
17
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
18
|
+
import type { AfterHook, BeforeHook } from "../../kernel/hooks/types.js";
|
|
23
19
|
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
24
20
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
25
|
-
import { createLogger } from "../../utils/logger.js";
|
|
26
21
|
import { paginate, type Pagination } from "../../utils/pagination.js";
|
|
27
22
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
28
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
29
23
|
import type { TxContext } from "../../kernel/database/tx-context.js";
|
|
30
24
|
import { CartRepository, type Cart, type CartLineItem } from "./repository/index.js";
|
|
31
25
|
import type { CatalogRepository } from "../catalog/repository/index.js";
|
|
@@ -61,23 +55,6 @@ type CartRemoveAfterHook = AfterHook<CartLineItem>;
|
|
|
61
55
|
type CartUpdateBeforeHook = BeforeHook<UpdateCartItemInput>;
|
|
62
56
|
type CartUpdateAfterHook = AfterHook<CartLineItem>;
|
|
63
57
|
|
|
64
|
-
function makeContext(
|
|
65
|
-
actor: Actor | null,
|
|
66
|
-
services: Record<string, unknown>,
|
|
67
|
-
database: DatabaseAdapter,
|
|
68
|
-
config: CommerceConfig,
|
|
69
|
-
tx: unknown = null,
|
|
70
|
-
): HookContext {
|
|
71
|
-
return createHookContext({
|
|
72
|
-
actor,
|
|
73
|
-
tx,
|
|
74
|
-
logger: createLogger("cart"),
|
|
75
|
-
services,
|
|
76
|
-
context: { moduleName: "cart" },
|
|
77
|
-
database: { db: database.db as PluginDb },
|
|
78
|
-
commerceConfig: config,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
58
|
|
|
82
59
|
function isExpired(cart: Cart): boolean {
|
|
83
60
|
return cart.expiresAt.getTime() < Date.now();
|
|
@@ -283,7 +260,7 @@ export class CartService {
|
|
|
283
260
|
);
|
|
284
261
|
}
|
|
285
262
|
|
|
286
|
-
const context =
|
|
263
|
+
const context = createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx);
|
|
287
264
|
const beforeHooks = this.deps.hooks.resolve(
|
|
288
265
|
"cart.beforeAddItem",
|
|
289
266
|
) as CartAddBeforeHook[];
|
|
@@ -448,7 +425,7 @@ export class CartService {
|
|
|
448
425
|
return Err(new CommerceNotFoundError("Cart item not found."));
|
|
449
426
|
}
|
|
450
427
|
|
|
451
|
-
const context =
|
|
428
|
+
const context = createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx);
|
|
452
429
|
const beforeHooks = this.deps.hooks.resolve(
|
|
453
430
|
"cart.beforeRemoveItem",
|
|
454
431
|
) as CartRemoveBeforeHook[];
|
|
@@ -496,7 +473,7 @@ export class CartService {
|
|
|
496
473
|
);
|
|
497
474
|
}
|
|
498
475
|
|
|
499
|
-
const context =
|
|
476
|
+
const context = createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx);
|
|
500
477
|
const beforeHooks = this.deps.hooks.resolve(
|
|
501
478
|
"cart.beforeUpdateQuantity",
|
|
502
479
|
) as CartUpdateBeforeHook[];
|
|
@@ -652,7 +629,7 @@ export class CartService {
|
|
|
652
629
|
null,
|
|
653
630
|
updated ?? cart,
|
|
654
631
|
"recover",
|
|
655
|
-
|
|
632
|
+
createModuleHookContext("cart", this.deps, actor ?? null, ctx?.tx ?? null),
|
|
656
633
|
);
|
|
657
634
|
|
|
658
635
|
return Ok({
|
|
@@ -12,17 +12,14 @@ import {
|
|
|
12
12
|
runAfterHooks,
|
|
13
13
|
runBeforeHooks,
|
|
14
14
|
} from "../../kernel/hooks/executor.js";
|
|
15
|
-
import {
|
|
15
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
16
16
|
import type {
|
|
17
17
|
AfterHook,
|
|
18
18
|
BeforeHook,
|
|
19
19
|
HookContext,
|
|
20
20
|
} from "../../kernel/hooks/types.js";
|
|
21
21
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
22
|
-
import { createLogger } from "../../utils/logger.js";
|
|
23
22
|
import { paginate } from "../../utils/pagination.js";
|
|
24
|
-
import type { JobsAdapter } from "../../kernel/jobs/adapter.js";
|
|
25
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
26
23
|
import type { CatalogWriteContext, TxContext } from "../../kernel/database/tx-context.js";
|
|
27
24
|
import { createTxContext, isWriteContextTransactional } from "../../kernel/database/tx-context.js";
|
|
28
25
|
import { canReadUnpublishedCatalog, isCatalogEntityVisible } from "./read-policy.js";
|
|
@@ -52,9 +49,6 @@ import type {
|
|
|
52
49
|
Variant,
|
|
53
50
|
} from "./repository/index.js";
|
|
54
51
|
|
|
55
|
-
function hookDatabaseArg(database: CatalogServiceDeps["database"]): { database: { db: PluginDb } } {
|
|
56
|
-
return { database: { db: database.db as PluginDb } };
|
|
57
|
-
}
|
|
58
52
|
|
|
59
53
|
const attributeFields = ["title", "subtitle", "description", "richDescription", "seoTitle", "seoDescription"] as const;
|
|
60
54
|
|
|
@@ -64,15 +58,9 @@ export function catalogHookContext(
|
|
|
64
58
|
ctx: CatalogWriteContext | undefined,
|
|
65
59
|
operation: string,
|
|
66
60
|
): HookContext {
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
logger: createLogger(`catalog.${operation}`),
|
|
71
|
-
services: deps.services,
|
|
72
|
-
...(deps.services.jobs ? { jobs: deps.services.jobs as JobsAdapter } : {}),
|
|
73
|
-
context: { moduleName: "catalog", ...(ctx?.hookContext ?? {}) },
|
|
74
|
-
...hookDatabaseArg(deps.database),
|
|
75
|
-
commerceConfig: deps.config,
|
|
61
|
+
return createModuleHookContext("catalog", deps, actor, isWriteContextTransactional(ctx) ? ctx.tx : null, {
|
|
62
|
+
logScope: `catalog.${operation}`,
|
|
63
|
+
...(ctx?.hookContext ? { context: ctx.hookContext } : {}),
|
|
76
64
|
});
|
|
77
65
|
}
|
|
78
66
|
|
|
@@ -336,13 +324,15 @@ export class EntityService {
|
|
|
336
324
|
await this.repo.deleteVariantOptionValuesByEntityId(id, ctx);
|
|
337
325
|
await this.repo.deleteVariantsByEntityId(id, ctx);
|
|
338
326
|
await this.repo.deleteEntity(id, ctx);
|
|
327
|
+
const afterHooks = this.deps.hooks.resolve("catalog.afterDelete") as AfterHook<SellableEntity>[];
|
|
328
|
+
await runAfterHooks(afterHooks, existing, existing, "delete", catalogHookContext(this.deps, actor, ctx, "delete"), (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
339
329
|
return Ok(undefined);
|
|
340
330
|
} catch (error) { return Err(toCommerceError(error)); } }
|
|
341
331
|
|
|
342
332
|
async getById(id: string, options: GetOptions | undefined, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogEntityHydrated>> {
|
|
343
333
|
const resolvedActor = actor ?? ctx?.actor ?? null;
|
|
344
334
|
const orgId = resolveOrgIdForCommerce(resolvedActor, this.deps.config);
|
|
345
|
-
const context: HookContext =
|
|
335
|
+
const context: HookContext = createModuleHookContext("catalog", this.deps, resolvedActor, ctx?.tx ?? null, { logScope: "catalog.read" });
|
|
346
336
|
const globalBeforeHooks = this.deps.hooks.resolve("catalog.beforeRead") as CatalogReadBeforeHook[];
|
|
347
337
|
const globalAfterHooks = this.deps.hooks.resolve("catalog.afterRead") as CatalogReadAfterHook[];
|
|
348
338
|
let processed = await runBeforeHooks(globalBeforeHooks, { id, ...(options !== undefined ? { options } : {}) }, "read", context);
|
|
@@ -389,7 +379,7 @@ export class EntityService {
|
|
|
389
379
|
}
|
|
390
380
|
|
|
391
381
|
async getBySlug(slug: string, options: GetOptions | undefined, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogEntityHydrated>> {
|
|
392
|
-
const context: HookContext =
|
|
382
|
+
const context: HookContext = createModuleHookContext("catalog", this.deps, actor ?? null, ctx?.tx ?? null, { logScope: "catalog.read" });
|
|
393
383
|
const globalBeforeHooks = this.deps.hooks.resolve("catalog.beforeRead") as CatalogReadBeforeHook[];
|
|
394
384
|
const globalAfterHooks = this.deps.hooks.resolve("catalog.afterRead") as CatalogReadAfterHook[];
|
|
395
385
|
let processed = await runBeforeHooks(globalBeforeHooks, { slug, ...(options !== undefined ? { options } : {}) }, "read", context);
|
|
@@ -424,7 +414,7 @@ export class EntityService {
|
|
|
424
414
|
|
|
425
415
|
async list(params: ListParams, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogListResult>> {
|
|
426
416
|
const resolvedActor = actor ?? ctx?.actor ?? null;
|
|
427
|
-
const context: HookContext =
|
|
417
|
+
const context: HookContext = createModuleHookContext("catalog", this.deps, resolvedActor, ctx?.tx ?? null, { logScope: "catalog.list" });
|
|
428
418
|
const globalBeforeHooks = this.deps.hooks.resolve("catalog.beforeList") as CatalogListBeforeHook[];
|
|
429
419
|
const globalAfterHooks = this.deps.hooks.resolve("catalog.afterList") as CatalogListAfterHook[];
|
|
430
420
|
let processed = await runBeforeHooks(globalBeforeHooks, params, "list", context);
|
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
import { prices } from "../pricing/schema.js";
|
|
30
30
|
import { catalogHookContext } from "./entity-service.js";
|
|
31
31
|
import type { CatalogServiceDeps } from "./service.js";
|
|
32
|
+
import { isUniqueViolation } from "../../kernel/database/unique-violation.js";
|
|
33
|
+
import { normalizeCurrency } from "../../utils/money.js";
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* The import fast path: a PAGE of new products lands in one transaction.
|
|
@@ -147,12 +149,6 @@ function failed(ref: string, code: ImportRowFailureCode, error: string): ImportP
|
|
|
147
149
|
return { ref, status: "failed", code, error };
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
function isUniqueViolation(error: unknown): boolean {
|
|
151
|
-
if (typeof error !== "object" || error === null) return false;
|
|
152
|
-
const value = error as { code?: unknown; cause?: unknown };
|
|
153
|
-
if (value.code === "23505") return true;
|
|
154
|
-
return isUniqueViolation(value.cause);
|
|
155
|
-
}
|
|
156
152
|
|
|
157
153
|
/**
|
|
158
154
|
* A row's failure names the constraint, not the statement: Drizzle's message carries the whole
|
|
@@ -169,9 +165,6 @@ function describeWriteError(error: unknown): string {
|
|
|
169
165
|
return message.split("\n", 1)[0] ?? message;
|
|
170
166
|
}
|
|
171
167
|
|
|
172
|
-
function normaliseCurrency(currency: string): string {
|
|
173
|
-
return currency.trim().toUpperCase();
|
|
174
|
-
}
|
|
175
168
|
|
|
176
169
|
/** Everything that can be known wrong without a database. */
|
|
177
170
|
function validateInMemory(page: ImportProduct[]): Map<number, Failure> {
|
|
@@ -215,7 +208,7 @@ function validateInMemory(page: ImportProduct[]): Map<number, Failure> {
|
|
|
215
208
|
}
|
|
216
209
|
for (const price of variant.prices ?? []) {
|
|
217
210
|
if (!Number.isInteger(price.amount) || price.amount < 0) fail(`Variant "${variant.ref}" has a non-integer or negative amount for ${price.currency}.`);
|
|
218
|
-
if (
|
|
211
|
+
if (normalizeCurrency(price.currency).length === 0) fail(`Variant "${variant.ref}" has a price with no currency.`);
|
|
219
212
|
}
|
|
220
213
|
}
|
|
221
214
|
for (const path of item.ownedFieldPaths ?? []) {
|
|
@@ -382,7 +375,7 @@ async function writeItem(
|
|
|
382
375
|
organizationId: orgId,
|
|
383
376
|
entityId,
|
|
384
377
|
variantId,
|
|
385
|
-
currency:
|
|
378
|
+
currency: normalizeCurrency(price.currency),
|
|
386
379
|
amount: price.amount,
|
|
387
380
|
...(price.compareAtAmount !== undefined ? { compareAtAmount: price.compareAtAmount } : {}),
|
|
388
381
|
};
|
|
@@ -60,6 +60,7 @@ import { EntityService } from "./entity-service.js";
|
|
|
60
60
|
import { CategoryService } from "./category-service.js";
|
|
61
61
|
import { BrandService } from "./brand-service.js";
|
|
62
62
|
import { CatalogImportService, type ImportProduct, type ImportProductsOptions, type ImportProductsReport } from "./import-service.js";
|
|
63
|
+
import { isUniqueViolation } from "../../kernel/database/unique-violation.js";
|
|
63
64
|
|
|
64
65
|
// ─── Hand-written types (not derivable from a single z.infer) ───────────────
|
|
65
66
|
|
|
@@ -151,285 +152,6 @@ export interface CatalogEntityHydrated extends SellableEntity {
|
|
|
151
152
|
pricing?: Array<{ id: string; currency: string; amount: number; compareAtAmount?: number | null; createdAt: Date }>;
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
export interface CatalogService {
|
|
155
|
-
readonly repository: CatalogRepository;
|
|
156
|
-
create(
|
|
157
|
-
input: CreateEntityInput,
|
|
158
|
-
actor: Actor | null,
|
|
159
|
-
ctx?: TxContext,
|
|
160
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
161
|
-
update(
|
|
162
|
-
id: string,
|
|
163
|
-
input: UpdateEntityInput,
|
|
164
|
-
actor: Actor | null,
|
|
165
|
-
ctx?: CatalogWriteContext,
|
|
166
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
167
|
-
delete(
|
|
168
|
-
id: string,
|
|
169
|
-
actor: Actor | null,
|
|
170
|
-
ctx?: TxContext,
|
|
171
|
-
): Promise<Result<void>>;
|
|
172
|
-
getById(
|
|
173
|
-
id: string,
|
|
174
|
-
options: GetOptions | undefined,
|
|
175
|
-
actor: Actor | null,
|
|
176
|
-
ctx?: TxContext,
|
|
177
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
178
|
-
getByIdForInternalUse(
|
|
179
|
-
id: string,
|
|
180
|
-
organizationId: string,
|
|
181
|
-
options?: GetOptions,
|
|
182
|
-
ctx?: TxContext,
|
|
183
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
184
|
-
getBySlug(
|
|
185
|
-
slug: string,
|
|
186
|
-
options: GetOptions | undefined,
|
|
187
|
-
actor: Actor | null,
|
|
188
|
-
ctx?: TxContext,
|
|
189
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
190
|
-
list(params: ListParams, actor: Actor | null, ctx?: TxContext): Promise<Result<CatalogListResult>>;
|
|
191
|
-
/** Returns undefined when no concrete ownership row applies to the field. */
|
|
192
|
-
resolveFieldOwner(
|
|
193
|
-
entityId: string,
|
|
194
|
-
fieldPath: FieldPath,
|
|
195
|
-
storeId: string,
|
|
196
|
-
ctx?: TxContext,
|
|
197
|
-
variantId?: string | null,
|
|
198
|
-
): Promise<FieldOwner | undefined>;
|
|
199
|
-
/** Entity-level bulk resolution: variant-scoped ownership rows are not consulted. */
|
|
200
|
-
resolveFieldOwners(
|
|
201
|
-
entityId: string,
|
|
202
|
-
storeId: string,
|
|
203
|
-
ctx?: TxContext,
|
|
204
|
-
): Promise<Map<FieldPath, FieldOwner>>;
|
|
205
|
-
setFieldOwner(
|
|
206
|
-
entityId: string,
|
|
207
|
-
fieldPath: FieldPath,
|
|
208
|
-
storeId: string | null,
|
|
209
|
-
owner: FieldOwner,
|
|
210
|
-
actor: Actor | null,
|
|
211
|
-
ctx?: TxContext,
|
|
212
|
-
variantId?: string | null,
|
|
213
|
-
): Promise<Result<void>>;
|
|
214
|
-
listFieldOwnership(
|
|
215
|
-
entityId: string,
|
|
216
|
-
actor: Actor | null,
|
|
217
|
-
ctx?: TxContext,
|
|
218
|
-
storeId?: string,
|
|
219
|
-
): Promise<Result<CatalogFieldOwnership[]>>;
|
|
220
|
-
seedImportedFieldOwnership(
|
|
221
|
-
entityId: string,
|
|
222
|
-
storeId: string,
|
|
223
|
-
fieldPaths: FieldPath[],
|
|
224
|
-
ctx?: TxContext,
|
|
225
|
-
): Promise<Result<void>>;
|
|
226
|
-
publish(
|
|
227
|
-
id: string,
|
|
228
|
-
actor: Actor | null,
|
|
229
|
-
ctx?: TxContext,
|
|
230
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
231
|
-
archive(
|
|
232
|
-
id: string,
|
|
233
|
-
actor: Actor | null,
|
|
234
|
-
ctx?: TxContext,
|
|
235
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
236
|
-
/**
|
|
237
|
-
* The import fast path: a page of NEW products in one transaction, per-item savepoints, one
|
|
238
|
-
* revision per item, one `catalog.afterImport` hook per page. See `import-service.ts`.
|
|
239
|
-
*/
|
|
240
|
-
importProducts(
|
|
241
|
-
page: ImportProduct[],
|
|
242
|
-
options: ImportProductsOptions,
|
|
243
|
-
actor: Actor | null,
|
|
244
|
-
ctx?: CatalogWriteContext,
|
|
245
|
-
): Promise<Result<ImportProductsReport>>;
|
|
246
|
-
discontinue(
|
|
247
|
-
id: string,
|
|
248
|
-
actor: Actor | null,
|
|
249
|
-
ctx?: TxContext,
|
|
250
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
251
|
-
setAttributes(
|
|
252
|
-
entityId: string,
|
|
253
|
-
locale: string,
|
|
254
|
-
attrs: SetAttributesInput,
|
|
255
|
-
actor: Actor | null,
|
|
256
|
-
ctx?: CatalogWriteContext,
|
|
257
|
-
): Promise<Result<void>>;
|
|
258
|
-
approveCustomField(
|
|
259
|
-
entityId: string,
|
|
260
|
-
fieldName: string,
|
|
261
|
-
locale: string,
|
|
262
|
-
actor: Actor | null,
|
|
263
|
-
ctx?: TxContext,
|
|
264
|
-
): Promise<Result<SellableCustomField>>;
|
|
265
|
-
rejectCustomField(
|
|
266
|
-
entityId: string,
|
|
267
|
-
fieldName: string,
|
|
268
|
-
locale: string,
|
|
269
|
-
actor: Actor | null,
|
|
270
|
-
ctx?: TxContext,
|
|
271
|
-
): Promise<Result<SellableCustomField>>;
|
|
272
|
-
getAttributes(
|
|
273
|
-
entityId: string,
|
|
274
|
-
locale: string,
|
|
275
|
-
actor: Actor | null,
|
|
276
|
-
ctx?: TxContext,
|
|
277
|
-
): Promise<Result<SellableAttribute>>;
|
|
278
|
-
listCategories(
|
|
279
|
-
ctx?: TxContext,
|
|
280
|
-
opts?: { includeArchived?: boolean },
|
|
281
|
-
): Promise<Result<CategorySummary[]>>;
|
|
282
|
-
createCategory(
|
|
283
|
-
input: CreateCategoryInput,
|
|
284
|
-
actor: Actor | null,
|
|
285
|
-
ctx?: TxContext,
|
|
286
|
-
): Promise<Result<CategorySummary>>;
|
|
287
|
-
archiveCategory(
|
|
288
|
-
id: string,
|
|
289
|
-
actor: Actor | null,
|
|
290
|
-
ctx?: TxContext,
|
|
291
|
-
): Promise<Result<CategorySummary>>;
|
|
292
|
-
restoreCategory(
|
|
293
|
-
id: string,
|
|
294
|
-
actor: Actor | null,
|
|
295
|
-
ctx?: TxContext,
|
|
296
|
-
): Promise<Result<CategorySummary>>;
|
|
297
|
-
updateCategory(
|
|
298
|
-
id: string,
|
|
299
|
-
input: UpdateCategoryInput,
|
|
300
|
-
actor: Actor | null,
|
|
301
|
-
ctx?: TxContext,
|
|
302
|
-
): Promise<Result<CategorySummary>>;
|
|
303
|
-
deleteCategory(
|
|
304
|
-
id: string,
|
|
305
|
-
actor: Actor | null,
|
|
306
|
-
ctx?: TxContext,
|
|
307
|
-
): Promise<Result<void>>;
|
|
308
|
-
addToCategory(
|
|
309
|
-
entityId: string,
|
|
310
|
-
categoryId: string,
|
|
311
|
-
actor: Actor | null,
|
|
312
|
-
ctx?: TxContext,
|
|
313
|
-
): Promise<Result<void>>;
|
|
314
|
-
removeFromCategory(
|
|
315
|
-
entityId: string,
|
|
316
|
-
categoryId: string,
|
|
317
|
-
actor: Actor | null,
|
|
318
|
-
ctx?: TxContext,
|
|
319
|
-
): Promise<Result<void>>;
|
|
320
|
-
listBrands(ctx?: TxContext): Promise<Result<Brand[]>>;
|
|
321
|
-
createBrand(
|
|
322
|
-
input: CreateBrandInput,
|
|
323
|
-
actor: Actor | null,
|
|
324
|
-
ctx?: TxContext,
|
|
325
|
-
): Promise<Result<Brand>>;
|
|
326
|
-
updateBrand(
|
|
327
|
-
id: string,
|
|
328
|
-
input: UpdateBrandInput,
|
|
329
|
-
actor: Actor | null,
|
|
330
|
-
ctx?: TxContext,
|
|
331
|
-
): Promise<Result<Brand>>;
|
|
332
|
-
deleteBrand(
|
|
333
|
-
id: string,
|
|
334
|
-
actor: Actor | null,
|
|
335
|
-
ctx?: TxContext,
|
|
336
|
-
): Promise<Result<void>>;
|
|
337
|
-
addToBrand(
|
|
338
|
-
entityId: string,
|
|
339
|
-
brandId: string,
|
|
340
|
-
actor: Actor | null,
|
|
341
|
-
ctx?: TxContext,
|
|
342
|
-
): Promise<Result<void>>;
|
|
343
|
-
removeFromBrand(
|
|
344
|
-
entityId: string,
|
|
345
|
-
brandId: string,
|
|
346
|
-
actor: Actor | null,
|
|
347
|
-
ctx?: TxContext,
|
|
348
|
-
): Promise<Result<void>>;
|
|
349
|
-
createOptionType(
|
|
350
|
-
input: CreateOptionTypeInput,
|
|
351
|
-
actor: Actor | null,
|
|
352
|
-
ctx?: TxContext,
|
|
353
|
-
): Promise<Result<OptionType>>;
|
|
354
|
-
createOptionValue(
|
|
355
|
-
input: CreateOptionValueInput,
|
|
356
|
-
actor: Actor | null,
|
|
357
|
-
ctx?: TxContext,
|
|
358
|
-
): Promise<Result<OptionValue>>;
|
|
359
|
-
createVariant(
|
|
360
|
-
input: CreateVariantInput,
|
|
361
|
-
actor: Actor | null,
|
|
362
|
-
ctx?: TxContext,
|
|
363
|
-
): Promise<Result<Variant>>;
|
|
364
|
-
generateVariants(
|
|
365
|
-
entityId: string,
|
|
366
|
-
strategy: VariantGenerationStrategy,
|
|
367
|
-
actor: Actor | null,
|
|
368
|
-
ctx?: TxContext,
|
|
369
|
-
): Promise<Result<Variant[]>>;
|
|
370
|
-
quickCreateVariant(
|
|
371
|
-
entityId: string,
|
|
372
|
-
input: { options: Record<string, string>; sku?: string | undefined; barcode?: string | undefined },
|
|
373
|
-
actor: Actor | null,
|
|
374
|
-
ctx?: TxContext,
|
|
375
|
-
): Promise<Result<{ variant: Variant; created: boolean }>>;
|
|
376
|
-
bulkCreateVariants(
|
|
377
|
-
entityId: string,
|
|
378
|
-
input: { axes: Array<{ name: string; values: string[] }>; skuPrefix?: string | undefined },
|
|
379
|
-
actor: Actor | null,
|
|
380
|
-
ctx?: TxContext,
|
|
381
|
-
): Promise<Result<{ created: Variant[]; skipped: number }>>;
|
|
382
|
-
/**
|
|
383
|
-
* Move the entity's `updated_at` and fire `catalog.afterUpdate` for a change to rows RELATED to
|
|
384
|
-
* it (links, media) — the versioning contract consumers rely on to re-read a product.
|
|
385
|
-
*/
|
|
386
|
-
notifyEntityChanged(
|
|
387
|
-
entityId: string,
|
|
388
|
-
changedFieldPaths: readonly string[],
|
|
389
|
-
actor: Actor | null,
|
|
390
|
-
ctx?: TxContext,
|
|
391
|
-
): Promise<void>;
|
|
392
|
-
recordEntityRevision(
|
|
393
|
-
entityId: string,
|
|
394
|
-
actor: Actor | null,
|
|
395
|
-
reason?: SellableEntityRevisionReason,
|
|
396
|
-
ctx?: TxContext,
|
|
397
|
-
): Promise<Result<SellableEntityRevision>>;
|
|
398
|
-
restoreEntityRevision(
|
|
399
|
-
entityId: string,
|
|
400
|
-
revisionId: string,
|
|
401
|
-
actor: Actor | null,
|
|
402
|
-
ctx?: TxContext,
|
|
403
|
-
): Promise<Result<CatalogEntityHydrated>>;
|
|
404
|
-
trimEntityRevisions(
|
|
405
|
-
actor: Actor | null,
|
|
406
|
-
olderThanDays?: number,
|
|
407
|
-
ctx?: TxContext,
|
|
408
|
-
): Promise<Result<number>>;
|
|
409
|
-
listEntityFieldDefinitions(
|
|
410
|
-
actor?: Actor | null,
|
|
411
|
-
entityType?: string,
|
|
412
|
-
ctx?: TxContext,
|
|
413
|
-
): Promise<Result<EntityFieldDefinitionRecord[]>>;
|
|
414
|
-
createEntityFieldDefinition(
|
|
415
|
-
input: CreateEntityFieldDefinitionInput,
|
|
416
|
-
actor: Actor | null,
|
|
417
|
-
ctx?: TxContext,
|
|
418
|
-
): Promise<Result<EntityFieldDefinitionRecord>>;
|
|
419
|
-
updateEntityFieldDefinition(
|
|
420
|
-
id: string,
|
|
421
|
-
input: UpdateEntityFieldDefinitionInput,
|
|
422
|
-
actor: Actor | null,
|
|
423
|
-
ctx?: TxContext,
|
|
424
|
-
): Promise<Result<EntityFieldDefinitionRecord>>;
|
|
425
|
-
archiveEntityFieldDefinition(
|
|
426
|
-
id: string,
|
|
427
|
-
actor: Actor | null,
|
|
428
|
-
ctx?: TxContext,
|
|
429
|
-
): Promise<Result<EntityFieldDefinitionRecord>>;
|
|
430
|
-
resolveEntityFieldDefinitions: EntityFieldDefinitionResolver;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
155
|
export interface CatalogServiceDeps {
|
|
434
156
|
repository: CatalogRepository;
|
|
435
157
|
hooks: HookRegistry;
|
|
@@ -452,14 +174,8 @@ export type CategorySummary = {
|
|
|
452
174
|
metadata: Record<string, unknown>;
|
|
453
175
|
};
|
|
454
176
|
|
|
455
|
-
function isUniqueViolation(error: unknown): boolean {
|
|
456
|
-
if (error == null || typeof error !== "object") return false;
|
|
457
|
-
const value = error as { code?: unknown; cause?: unknown };
|
|
458
|
-
if (value.code === "23505") return true;
|
|
459
|
-
return isUniqueViolation(value.cause);
|
|
460
|
-
}
|
|
461
177
|
|
|
462
|
-
export class CatalogServiceImpl
|
|
178
|
+
export class CatalogServiceImpl {
|
|
463
179
|
readonly repository: CatalogRepository;
|
|
464
180
|
private readonly database: DatabaseAdapter;
|
|
465
181
|
private readonly config: CommerceConfig;
|
|
@@ -4,14 +4,12 @@ import type { Actor } from "../../auth/types.js";
|
|
|
4
4
|
import type { CommerceConfig } from "../../config/types.js";
|
|
5
5
|
import { CommerceNotFoundError, toCommerceError } from "../../kernel/errors.js";
|
|
6
6
|
import { runAfterHooks } from "../../kernel/hooks/executor.js";
|
|
7
|
-
import {
|
|
7
|
+
import { createModuleHookContext } from "../../kernel/hooks/create-context.js";
|
|
8
8
|
import type { HookRegistry } from "../../kernel/hooks/registry.js";
|
|
9
|
-
import type { AfterHook
|
|
9
|
+
import type { AfterHook } from "../../kernel/hooks/types.js";
|
|
10
10
|
import { Err, Ok, type Result } from "../../kernel/result.js";
|
|
11
11
|
import type { DatabaseAdapter } from "../../kernel/database/adapter.js";
|
|
12
|
-
import type { PluginDb } from "../../kernel/database/plugin-types.js";
|
|
13
12
|
import type { TxContext } from "../../kernel/database/tx-context.js";
|
|
14
|
-
import { createLogger } from "../../utils/logger.js";
|
|
15
13
|
import type {
|
|
16
14
|
CustomersRepository,
|
|
17
15
|
Customer,
|
|
@@ -28,23 +26,6 @@ interface CustomerServiceDeps {
|
|
|
28
26
|
database: DatabaseAdapter;
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
function hookContext(
|
|
32
|
-
actor: Actor | null,
|
|
33
|
-
services: Record<string, unknown>,
|
|
34
|
-
database: DatabaseAdapter,
|
|
35
|
-
config: CommerceConfig,
|
|
36
|
-
tx: unknown,
|
|
37
|
-
): HookContext {
|
|
38
|
-
return createHookContext({
|
|
39
|
-
actor,
|
|
40
|
-
tx,
|
|
41
|
-
logger: createLogger("customers"),
|
|
42
|
-
services,
|
|
43
|
-
context: { moduleName: "customers" },
|
|
44
|
-
database: { db: database.db as PluginDb },
|
|
45
|
-
commerceConfig: config,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
29
|
|
|
49
30
|
export class CustomerService {
|
|
50
31
|
private readonly repo: CustomersRepository;
|
|
@@ -101,7 +82,7 @@ export class CustomerService {
|
|
|
101
82
|
const afterHooks = this.deps.hooks.resolve(
|
|
102
83
|
"customers.afterCreate",
|
|
103
84
|
) as AfterHook<Customer>[];
|
|
104
|
-
const hctx =
|
|
85
|
+
const hctx = createModuleHookContext("customers", this.deps, actor ?? null, ctx?.tx ?? null);
|
|
105
86
|
await runAfterHooks(afterHooks, null, customer, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
106
87
|
|
|
107
88
|
return Ok(customer);
|
|
@@ -202,7 +183,7 @@ export class CustomerService {
|
|
|
202
183
|
const afterHooks = this.deps.hooks.resolve(
|
|
203
184
|
"customers.afterCreate",
|
|
204
185
|
) as AfterHook<Customer>[];
|
|
205
|
-
const hctx =
|
|
186
|
+
const hctx = createModuleHookContext("customers", this.deps, actor, ctx?.tx ?? null);
|
|
206
187
|
await runAfterHooks(afterHooks, null, customer, "create", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
207
188
|
|
|
208
189
|
return customer;
|
|
@@ -282,9 +263,7 @@ export class CustomerService {
|
|
|
282
263
|
const afterHooks = this.deps.hooks.resolve(
|
|
283
264
|
"customers.afterUpdate",
|
|
284
265
|
) as AfterHook<Customer>[];
|
|
285
|
-
const hctx =
|
|
286
|
-
actor ?? ctx?.actor ?? null, this.deps.services, this.deps.database, this.deps.config, ctx?.tx ?? null,
|
|
287
|
-
);
|
|
266
|
+
const hctx = createModuleHookContext("customers", this.deps, actor ?? ctx?.actor ?? null, ctx?.tx ?? null);
|
|
288
267
|
await runAfterHooks(afterHooks, existing, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
289
268
|
|
|
290
269
|
return Ok(updated);
|
|
@@ -315,7 +294,7 @@ export class CustomerService {
|
|
|
315
294
|
const afterHooks = this.deps.hooks.resolve(
|
|
316
295
|
"customers.afterUpdate",
|
|
317
296
|
) as AfterHook<Customer>[];
|
|
318
|
-
const hctx =
|
|
297
|
+
const hctx = createModuleHookContext("customers", this.deps, resolvedActor, ctx?.tx ?? null);
|
|
319
298
|
await runAfterHooks(afterHooks, customer, updated, "update", hctx, (hook) => this.deps.hooks.runsInTransaction(hook));
|
|
320
299
|
|
|
321
300
|
return Ok(updated);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { HydratedOrder } from "../orders/service.js";
|
|
2
2
|
import { A4, type PdfTextOp } from "./pdf.js";
|
|
3
|
+
import { escapeHtml } from "../../utils/escape-html.js";
|
|
4
|
+
import { formatAmount } from "../../utils/money.js";
|
|
3
5
|
|
|
4
6
|
/** Branding values read from the settings module's `branding` group. */
|
|
5
7
|
export interface DocumentBranding {
|
|
@@ -19,25 +21,6 @@ export interface DocumentContext {
|
|
|
19
21
|
invoiceNumber: string;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
export function escapeHtml(value: unknown): string {
|
|
23
|
-
return String(value ?? "")
|
|
24
|
-
.replaceAll("&", "&")
|
|
25
|
-
.replaceAll("<", "<")
|
|
26
|
-
.replaceAll(">", ">")
|
|
27
|
-
.replaceAll('"', """)
|
|
28
|
-
.replaceAll("'", "'");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Minor units → "1,234.50 LKR". */
|
|
32
|
-
export function formatAmount(minor: number, currency: string): string {
|
|
33
|
-
const major = minor / 100;
|
|
34
|
-
const formatted = major.toLocaleString("en-US", {
|
|
35
|
-
minimumFractionDigits: 2,
|
|
36
|
-
maximumFractionDigits: 2,
|
|
37
|
-
});
|
|
38
|
-
return `${formatted} ${currency}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
24
|
function formatDate(date: Date | string | null | undefined): string {
|
|
42
25
|
if (!date) return "";
|
|
43
26
|
const d = typeof date === "string" ? new Date(date) : date;
|