@reactionary/source 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -11
- package/examples/node/package.json +7 -7
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +11 -5
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +9 -3
- package/examples/node/src/basic/basic-node-setup.spec.ts +6 -2
- package/examples/node/src/basic/client-creation.spec.ts +6 -6
- package/examples/node/src/utils.ts +48 -48
- package/examples/node/tsconfig.lib.json +2 -1
- package/package.json +1 -1
- package/packages/algolia/README.md +11 -0
- package/{providers/google-analytics → packages/algolia}/eslint.config.mjs +0 -2
- package/{providers → packages}/algolia/package.json +7 -5
- package/{providers/posthog → packages/algolia}/project.json +6 -6
- package/{providers/algolia/src/providers/analytics.provider.ts → packages/algolia/src/capabilities/analytics.capability.ts} +6 -6
- package/packages/algolia/src/capabilities/index.ts +3 -0
- package/{providers/algolia/src/providers/product-recommendations.provider.ts → packages/algolia/src/capabilities/product-recommendations.capability.ts} +3 -3
- package/packages/algolia/src/capabilities/product-search.capability.ts +119 -0
- package/packages/algolia/src/core/initialize.ts +82 -0
- package/packages/algolia/src/core/initialize.types.ts +107 -0
- package/packages/algolia/src/factories/index.ts +1 -0
- package/packages/algolia/src/factories/product-search/product-search.factory.ts +182 -0
- package/{providers/fake → packages/algolia}/src/index.ts +3 -2
- package/packages/algolia/src/schema/capabilities.schema.ts +84 -0
- package/{providers → packages}/algolia/src/test/analytics.spec.ts +12 -4
- package/packages/algolia/src/test/client-builder-product-search-extension.example.ts +85 -0
- package/packages/algolia/vite.config.ts +26 -0
- package/packages/algolia/vitest.config.mts +21 -0
- package/packages/commercetools/README.md +11 -0
- package/{core → packages/commercetools}/eslint.config.mjs +2 -2
- package/packages/commercetools/package.json +17 -0
- package/{providers → packages}/commercetools/project.json +7 -8
- package/{providers/commercetools/src/providers/cart.provider.ts → packages/commercetools/src/capabilities/cart.capability.ts} +68 -194
- package/{providers/commercetools/src/providers/category.provider.ts → packages/commercetools/src/capabilities/category.capability.ts} +26 -66
- package/{providers/commercetools/src/providers/checkout.provider.ts → packages/commercetools/src/capabilities/checkout.capability.ts} +51 -323
- package/{providers/commercetools/src/providers/identity.provider.ts → packages/commercetools/src/capabilities/identity.capability.ts} +36 -16
- package/packages/commercetools/src/capabilities/index.ts +15 -0
- package/{providers/commercetools/src/providers/inventory.provider.ts → packages/commercetools/src/capabilities/inventory.capability.ts} +14 -32
- package/packages/commercetools/src/capabilities/order-search.capability.ts +135 -0
- package/packages/commercetools/src/capabilities/order.capability.ts +67 -0
- package/{providers/commercetools/src/providers/price.provider.ts → packages/commercetools/src/capabilities/price.capability.ts} +38 -52
- package/{providers/commercetools/src/providers/product-associations.provider.ts → packages/commercetools/src/capabilities/product-associations.capability.ts} +40 -105
- package/{providers/commercetools/src/providers/product-list.provider.ts → packages/commercetools/src/capabilities/product-list.capability.ts} +39 -24
- package/{providers/commercetools/src/providers/product-reviews.provider.ts → packages/commercetools/src/capabilities/product-reviews.capability.ts} +35 -15
- package/{providers/commercetools/src/providers/product-search.provider.ts → packages/commercetools/src/capabilities/product-search.capability.ts} +18 -171
- package/packages/commercetools/src/capabilities/product.capability.ts +133 -0
- package/{providers/commercetools/src/providers/profile.provider.ts → packages/commercetools/src/capabilities/profile.capability.ts} +28 -74
- package/{providers/commercetools/src/providers/store.provider.ts → packages/commercetools/src/capabilities/store.capability.ts} +14 -32
- package/packages/commercetools/src/core/capability-descriptors.ts +324 -0
- package/{providers → packages}/commercetools/src/core/client.ts +2 -2
- package/packages/commercetools/src/core/initialize.ts +58 -0
- package/packages/commercetools/src/core/initialize.types.ts +174 -0
- package/packages/commercetools/src/factories/cart/cart.factory.ts +142 -0
- package/packages/commercetools/src/factories/category/category.factory.ts +77 -0
- package/packages/commercetools/src/factories/checkout/checkout-initializer-overrides.example.ts +94 -0
- package/packages/commercetools/src/factories/checkout/checkout.factory.ts +338 -0
- package/packages/commercetools/src/factories/identity/identity.factory.ts +26 -0
- package/packages/commercetools/src/factories/inventory/inventory.factory.ts +49 -0
- package/packages/commercetools/src/factories/order/order.factory.ts +149 -0
- package/packages/commercetools/src/factories/order-search/order-search.factory.ts +108 -0
- package/packages/commercetools/src/factories/price/price.factory.ts +76 -0
- package/packages/commercetools/src/factories/product/product-capability-custom-method-only.example.ts +47 -0
- package/packages/commercetools/src/factories/product/product-capability-schema-signature-extension.example.ts +61 -0
- package/packages/commercetools/src/factories/product/product-factory-baseline.example.ts +14 -0
- package/packages/commercetools/src/factories/product/product-factory-schema-and-parse-extension.example.ts +35 -0
- package/packages/commercetools/src/factories/product/product-factory-schema-extension.example.ts +23 -0
- package/packages/commercetools/src/factories/product/product-initializer-factory-extension.example.ts +41 -0
- package/packages/commercetools/src/factories/product/product.factory.ts +220 -0
- package/packages/commercetools/src/factories/product/utils.example.ts +9 -0
- package/packages/commercetools/src/factories/product-associations/product-associations.factory.ts +103 -0
- package/packages/commercetools/src/factories/product-list/product-list.factory.ts +122 -0
- package/packages/commercetools/src/factories/product-reviews/product-reviews.factory.ts +81 -0
- package/packages/commercetools/src/factories/product-search/product-search.factory.ts +182 -0
- package/packages/commercetools/src/factories/profile/profile.factory.ts +94 -0
- package/packages/commercetools/src/factories/store/store.factory.ts +49 -0
- package/packages/commercetools/src/index.ts +30 -0
- package/packages/commercetools/src/schema/capabilities.schema.ts +260 -0
- package/{providers → packages}/commercetools/src/test/caching.spec.ts +24 -8
- package/packages/commercetools/src/test/client-builder-merge-extensions.example.ts +125 -0
- package/{providers/algolia → packages/commercetools}/tsconfig.json +1 -1
- package/{core → packages/commercetools}/tsconfig.lib.json +1 -1
- package/packages/commercetools/tsconfig.spec.json +28 -0
- package/packages/commercetools/vite.config.ts +26 -0
- package/packages/commercetools/vitest.config.mts +21 -0
- package/{providers/fake → packages/core}/eslint.config.mjs +2 -1
- package/{core → packages/core}/package.json +7 -7
- package/packages/core/project.json +33 -0
- package/{core/src/providers/analytics.provider.ts → packages/core/src/capabilities/analytics.capability.ts} +8 -8
- package/{core/src/providers/base.provider.ts → packages/core/src/capabilities/base.capability.ts} +2 -2
- package/{core/src/providers/cart.provider.ts → packages/core/src/capabilities/cart.capability.ts} +13 -11
- package/{core/src/providers/category.provider.ts → packages/core/src/capabilities/category.capability.ts} +12 -10
- package/{core/src/providers/checkout.provider.ts → packages/core/src/capabilities/checkout.capability.ts} +15 -11
- package/{core/src/providers/identity.provider.ts → packages/core/src/capabilities/identity.capability.ts} +8 -8
- package/packages/core/src/capabilities/index.ts +18 -0
- package/{core/src/providers/inventory.provider.ts → packages/core/src/capabilities/inventory.capability.ts} +5 -5
- package/{core/src/providers/order-search.provider.ts → packages/core/src/capabilities/order-search.capability.ts} +5 -3
- package/{core/src/providers/order.provider.ts → packages/core/src/capabilities/order.capability.ts} +5 -5
- package/{core/src/providers/price.provider.ts → packages/core/src/capabilities/price.capability.ts} +6 -6
- package/{core/src/providers/product-associations.provider.ts → packages/core/src/capabilities/product-associations.capability.ts} +7 -5
- package/{core/src/providers/product-list.provider.ts → packages/core/src/capabilities/product-list.capability.ts} +14 -9
- package/{core/src/providers/product-recommendations.provider.ts → packages/core/src/capabilities/product-recommendations.capability.ts} +21 -21
- package/{core/src/providers/product-reviews.provider.ts → packages/core/src/capabilities/product-reviews.capability.ts} +9 -5
- package/packages/core/src/capabilities/product-search.capability.ts +48 -0
- package/{core/src/providers/product.provider.ts → packages/core/src/capabilities/product.capability.ts} +7 -7
- package/{core/src/providers/profile.provider.ts → packages/core/src/capabilities/profile.capability.ts} +9 -9
- package/{core/src/providers/store.provider.ts → packages/core/src/capabilities/store.capability.ts} +3 -3
- package/packages/core/src/client/client-builder.ts +131 -0
- package/packages/core/src/client/client.ts +35 -0
- package/{core → packages/core}/src/decorators/reactionary.decorator.ts +7 -7
- package/packages/core/src/factories/cart.factory.ts +40 -0
- package/packages/core/src/factories/category.factory.ts +40 -0
- package/packages/core/src/factories/checkout.factory.ts +59 -0
- package/packages/core/src/factories/identity.factory.ts +26 -0
- package/packages/core/src/factories/index.ts +15 -0
- package/packages/core/src/factories/inventory.factory.ts +26 -0
- package/packages/core/src/factories/order-search.factory.ts +33 -0
- package/packages/core/src/factories/order.factory.ts +21 -0
- package/packages/core/src/factories/price.factory.ts +29 -0
- package/packages/core/src/factories/product-associations.factory.ts +30 -0
- package/packages/core/src/factories/product-list.factory.ts +82 -0
- package/packages/core/src/factories/product-reviews.factory.ts +58 -0
- package/packages/core/src/factories/product-search.factory.ts +31 -0
- package/packages/core/src/factories/product.factory.ts +21 -0
- package/packages/core/src/factories/profile.factory.ts +23 -0
- package/packages/core/src/factories/store.factory.ts +21 -0
- package/packages/core/src/index.ts +8 -0
- package/packages/core/src/test/client-builder.spec.ts +141 -0
- package/{core → packages/core}/src/test/reactionary.decorator.spec.ts +27 -27
- package/{providers/meilisearch → packages/core}/tsconfig.json +1 -1
- package/{providers/medusa → packages/core}/tsconfig.lib.json +1 -2
- package/packages/core/tsconfig.spec.json +28 -0
- package/packages/core/vite.config.ts +26 -0
- package/packages/core/vitest.config.mts +21 -0
- package/packages/fake/README.md +11 -0
- package/{providers/algolia → packages/fake}/eslint.config.mjs +2 -1
- package/{providers → packages}/fake/package.json +6 -4
- package/{providers → packages}/fake/project.json +7 -8
- package/{providers/fake/src/providers/analytics.provider.ts → packages/fake/src/capabilities/analytics.capability.ts} +2 -2
- package/{providers/fake/src/providers/cart.provider.ts → packages/fake/src/capabilities/cart.capability.ts} +24 -15
- package/packages/fake/src/capabilities/category.capability.ts +199 -0
- package/{providers/fake/src/providers/checkout.provider.ts → packages/fake/src/capabilities/checkout.capability.ts} +40 -21
- package/{providers/fake/src/providers/identity.provider.ts → packages/fake/src/capabilities/identity.capability.ts} +40 -34
- package/packages/fake/src/capabilities/index.ts +15 -0
- package/packages/fake/src/capabilities/inventory.capability.ts +74 -0
- package/packages/fake/src/capabilities/order-search.capability.ts +86 -0
- package/{providers/fake/src/providers/order.provider.ts → packages/fake/src/capabilities/order.capability.ts} +22 -38
- package/{providers/fake/src/providers/price.provider.ts → packages/fake/src/capabilities/price.capability.ts} +42 -34
- package/{providers/fake/src/providers/product-associations.provider.ts → packages/fake/src/capabilities/product-associations.capability.ts} +24 -11
- package/{providers/fake/src/providers/product-reviews.provider.ts → packages/fake/src/capabilities/product-reviews.capability.ts} +72 -70
- package/{providers/fake/src/providers/product-search.provider.ts → packages/fake/src/capabilities/product-search.capability.ts} +44 -71
- package/{providers/fake/src/providers/product.provider.ts → packages/fake/src/capabilities/product.capability.ts} +35 -33
- package/packages/fake/src/capabilities/profile.capability.ts +154 -0
- package/packages/fake/src/capabilities/store.capability.ts +72 -0
- package/packages/fake/src/core/initialize.ts +274 -0
- package/packages/fake/src/core/initialize.types.ts +164 -0
- package/packages/fake/src/factories/cart/cart.factory.ts +34 -0
- package/packages/fake/src/factories/category/category.factory.ts +40 -0
- package/packages/fake/src/factories/checkout/checkout.factory.ts +53 -0
- package/packages/fake/src/factories/identity/identity.factory.ts +25 -0
- package/packages/fake/src/factories/index.ts +14 -0
- package/packages/fake/src/factories/inventory/inventory.factory.ts +25 -0
- package/packages/fake/src/factories/order/order.factory.ts +22 -0
- package/packages/fake/src/factories/order-search/order-search.factory.ts +27 -0
- package/packages/fake/src/factories/price/price.factory.ts +26 -0
- package/packages/fake/src/factories/product/product.factory.ts +22 -0
- package/packages/fake/src/factories/product-associations/product-associations.factory.ts +25 -0
- package/packages/fake/src/factories/product-reviews/product-reviews.factory.ts +53 -0
- package/packages/fake/src/factories/product-search/product-search.factory.ts +27 -0
- package/packages/fake/src/factories/profile/profile.factory.ts +22 -0
- package/packages/fake/src/factories/store/store.factory.ts +22 -0
- package/{providers/algolia → packages/fake}/src/index.ts +4 -3
- package/packages/fake/src/schema/capabilities.schema.ts +178 -0
- package/{providers/fake/src/test/cart.provider.spec.ts → packages/fake/src/test/cart.capability.spec.ts} +24 -7
- package/{providers/fake/src/test/category.provider.spec.ts → packages/fake/src/test/category.capability.spec.ts} +7 -4
- package/{providers/fake/src/test/checkout.provider.spec.ts → packages/fake/src/test/checkout.capability.spec.ts} +15 -5
- package/packages/fake/src/test/client-builder-product-extension.example.ts +75 -0
- package/{providers/fake/src/test/order-search.provider.spec.ts → packages/fake/src/test/order-search.capability.spec.ts} +7 -10
- package/{providers/fake/src/test/order.provider.spec.ts → packages/fake/src/test/order.capability.spec.ts} +7 -9
- package/{providers/fake/src/test/price.provider.spec.ts → packages/fake/src/test/price.capability.spec.ts} +6 -4
- package/{providers/fake/src/test/product.provider.spec.ts → packages/fake/src/test/product.capability.spec.ts} +10 -4
- package/{providers/fake/src/test/profile.provider.spec.ts → packages/fake/src/test/profile.capability.spec.ts} +7 -5
- package/{providers/commercetools → packages/fake}/tsconfig.json +1 -1
- package/packages/fake/tsconfig.lib.json +23 -0
- package/packages/fake/tsconfig.spec.json +28 -0
- package/packages/fake/vite.config.ts +26 -0
- package/packages/fake/vitest.config.mts +21 -0
- package/packages/google-analytics/eslint.config.mjs +23 -0
- package/{providers → packages}/google-analytics/package.json +7 -5
- package/{providers → packages}/google-analytics/project.json +5 -5
- package/{providers/google-analytics/src/providers/analytics.provider.ts → packages/google-analytics/src/capabilities/analytics.capability.ts} +2 -2
- package/packages/google-analytics/src/core/initialize.ts +41 -0
- package/packages/google-analytics/src/core/initialize.types.ts +47 -0
- package/{providers → packages}/google-analytics/src/index.ts +2 -1
- package/packages/google-analytics/src/schema/capabilities.schema.ts +36 -0
- package/{providers/google-analytics/src/test/analytics.provider.spec.ts → packages/google-analytics/src/test/analytics.capability.spec.ts} +7 -7
- package/packages/google-analytics/tsconfig.json +24 -0
- package/packages/google-analytics/tsconfig.lib.json +23 -0
- package/packages/google-analytics/tsconfig.spec.json +28 -0
- package/{providers → packages}/google-analytics/vite.config.ts +2 -2
- package/{providers → packages}/google-analytics/vitest.config.mts +2 -2
- package/packages/medusa/README.md +11 -0
- package/packages/medusa/eslint.config.mjs +23 -0
- package/packages/medusa/package.json +17 -0
- package/{providers → packages}/medusa/project.json +7 -8
- package/{providers/medusa/src/providers/cart.provider.ts → packages/medusa/src/capabilities/cart.capability.ts} +34 -21
- package/{providers/medusa/src/providers/category.provider.ts → packages/medusa/src/capabilities/category.capability.ts} +31 -13
- package/{providers/medusa/src/providers/checkout.provider.ts → packages/medusa/src/capabilities/checkout.capability.ts} +43 -18
- package/{providers/medusa/src/providers/identity.provider.ts → packages/medusa/src/capabilities/identity.capability.ts} +3 -3
- package/{providers/medusa/src/providers/inventory.provider.ts → packages/medusa/src/capabilities/inventory.capability.ts} +22 -8
- package/{providers/medusa/src/providers/order-search.provider.ts → packages/medusa/src/capabilities/order-search.capability.ts} +17 -6
- package/{providers/medusa/src/providers/order.provider.ts → packages/medusa/src/capabilities/order.capability.ts} +18 -6
- package/{providers/medusa/src/providers/price.provider.ts → packages/medusa/src/capabilities/price.capability.ts} +27 -8
- package/{providers/medusa/src/providers/product-associations.provider.ts → packages/medusa/src/capabilities/product-associations.capability.ts} +20 -9
- package/{providers/medusa/src/providers/product-recommendations.provider.ts → packages/medusa/src/capabilities/product-recommendations.capability.ts} +3 -3
- package/{providers/medusa/src/providers/product-search.provider.ts → packages/medusa/src/capabilities/product-search.capability.ts} +20 -32
- package/{providers/medusa/src/providers/product.provider.ts → packages/medusa/src/capabilities/product.capability.ts} +48 -12
- package/{providers/medusa/src/providers/profile.provider.ts → packages/medusa/src/capabilities/profile.capability.ts} +37 -13
- package/packages/medusa/src/core/initialize.ts +330 -0
- package/packages/medusa/src/core/initialize.types.ts +184 -0
- package/packages/medusa/src/factories/cart/cart.factory.ts +34 -0
- package/packages/medusa/src/factories/category/category.factory.ts +37 -0
- package/packages/medusa/src/factories/checkout/checkout.factory.ts +50 -0
- package/packages/medusa/src/factories/identity/identity.factory.ts +22 -0
- package/packages/medusa/src/factories/index.ts +12 -0
- package/packages/medusa/src/factories/inventory/inventory.factory.ts +25 -0
- package/packages/medusa/src/factories/order/order.factory.ts +22 -0
- package/packages/medusa/src/factories/order-search/order-search.factory.ts +27 -0
- package/packages/medusa/src/factories/price/price.factory.ts +26 -0
- package/packages/medusa/src/factories/product/product.factory.ts +22 -0
- package/packages/medusa/src/factories/product-associations/product-associations.factory.ts +25 -0
- package/packages/medusa/src/factories/product-search/product-search.factory.ts +27 -0
- package/packages/medusa/src/factories/profile/profile.factory.ts +22 -0
- package/packages/medusa/src/index.ts +17 -0
- package/packages/medusa/src/schema/capabilities.schema.ts +231 -0
- package/{providers/medusa/src/test/cart.provider.spec.ts → packages/medusa/src/test/cart.capability.spec.ts} +20 -4
- package/{providers/medusa/src/test/category.provider.spec.ts → packages/medusa/src/test/category.capability.spec.ts} +7 -4
- package/{providers → packages}/medusa/src/test/checkout.spec.ts +9 -9
- package/{providers/medusa/src/test/identity.provider.spec.ts → packages/medusa/src/test/identity.capability.spec.ts} +3 -3
- package/{providers/medusa/src/test/inventory.provider.spec.ts → packages/medusa/src/test/inventory.capability.spec.ts} +6 -4
- package/{providers/medusa/src/test/large-cart.provider.spec.ts → packages/medusa/src/test/large-cart.capability.spec.ts} +14 -8
- package/{providers/medusa/src/test/price.provider.spec.ts → packages/medusa/src/test/price.capability.spec.ts} +10 -3
- package/{providers/medusa/src/test/product.provider.spec.ts → packages/medusa/src/test/product.capability.spec.ts} +6 -4
- package/{providers/medusa/src/test/search.provider.spec.ts → packages/medusa/src/test/search.capability.spec.ts} +20 -7
- package/{providers → packages}/medusa/src/utils/medusa-helpers.ts +1 -1
- package/packages/medusa/tsconfig.json +24 -0
- package/packages/medusa/tsconfig.lib.json +23 -0
- package/packages/medusa/tsconfig.spec.json +28 -0
- package/packages/medusa/vite.config.ts +26 -0
- package/packages/medusa/vitest.config.mts +21 -0
- package/packages/meilisearch/README.md +11 -0
- package/packages/meilisearch/eslint.config.mjs +23 -0
- package/packages/meilisearch/package.json +15 -0
- package/{providers → packages}/meilisearch/project.json +7 -8
- package/packages/meilisearch/src/capabilities/index.ts +3 -0
- package/{providers/meilisearch/src/providers/order-search.provider.ts → packages/meilisearch/src/capabilities/order-search.capability.ts} +22 -7
- package/{providers/meilisearch/src/providers/product-recommendations.provider.ts → packages/meilisearch/src/capabilities/product-recommendations.capability.ts} +3 -3
- package/{providers/meilisearch/src/providers/product-search.provider.ts → packages/meilisearch/src/capabilities/product-search.capability.ts} +25 -9
- package/packages/meilisearch/src/core/initialize.ts +94 -0
- package/packages/meilisearch/src/core/initialize.types.ts +119 -0
- package/packages/meilisearch/src/factories/index.ts +2 -0
- package/packages/meilisearch/src/factories/order-search/order-search.factory.ts +27 -0
- package/packages/meilisearch/src/factories/product-search/product-search.factory.ts +27 -0
- package/packages/meilisearch/src/index.ts +9 -0
- package/packages/meilisearch/src/schema/capabilities.schema.ts +98 -0
- package/packages/meilisearch/tsconfig.json +24 -0
- package/packages/meilisearch/tsconfig.lib.json +23 -0
- package/packages/meilisearch/tsconfig.spec.json +28 -0
- package/packages/meilisearch/vite.config.ts +26 -0
- package/packages/meilisearch/vitest.config.mts +21 -0
- package/tsconfig.base.json +13 -21
- package/core/project.json +0 -34
- package/core/src/client/client-builder.ts +0 -84
- package/core/src/client/client.ts +0 -35
- package/core/src/index.ts +0 -6
- package/core/src/providers/index.ts +0 -18
- package/core/src/providers/product-search.provider.ts +0 -61
- package/core/src/test/client-builder.spec.ts +0 -60
- package/core/tsconfig.json +0 -24
- package/core/tsconfig.spec.json +0 -4
- package/core/vitest.config.ts +0 -14
- package/providers/algolia/README.md +0 -56
- package/providers/algolia/project.json +0 -34
- package/providers/algolia/src/core/initialize.ts +0 -27
- package/providers/algolia/src/providers/index.ts +0 -3
- package/providers/algolia/src/providers/product-search.provider.ts +0 -236
- package/providers/algolia/src/schema/capabilities.schema.ts +0 -10
- package/providers/algolia/tsconfig.lib.json +0 -10
- package/providers/algolia/tsconfig.spec.json +0 -4
- package/providers/algolia/vitest.config.ts +0 -14
- package/providers/commercetools/README.md +0 -65
- package/providers/commercetools/eslint.config.mjs +0 -22
- package/providers/commercetools/package.json +0 -15
- package/providers/commercetools/src/core/initialize.ts +0 -174
- package/providers/commercetools/src/index.ts +0 -15
- package/providers/commercetools/src/providers/index.ts +0 -15
- package/providers/commercetools/src/providers/order-search.provider.ts +0 -229
- package/providers/commercetools/src/providers/order.provider.ts +0 -198
- package/providers/commercetools/src/providers/product.provider.ts +0 -312
- package/providers/commercetools/src/schema/capabilities.schema.ts +0 -22
- package/providers/commercetools/tsconfig.lib.json +0 -10
- package/providers/commercetools/tsconfig.spec.json +0 -4
- package/providers/commercetools/vitest.config.ts +0 -15
- package/providers/fake/README.md +0 -23
- package/providers/fake/src/core/initialize.ts +0 -105
- package/providers/fake/src/providers/category.provider.ts +0 -184
- package/providers/fake/src/providers/index.ts +0 -15
- package/providers/fake/src/providers/inventory.provider.ts +0 -72
- package/providers/fake/src/providers/order-search.provider.ts +0 -78
- package/providers/fake/src/providers/profile.provider.ts +0 -147
- package/providers/fake/src/providers/store.provider.ts +0 -56
- package/providers/fake/src/schema/capabilities.schema.ts +0 -21
- package/providers/fake/tsconfig.json +0 -25
- package/providers/fake/tsconfig.lib.json +0 -11
- package/providers/fake/tsconfig.spec.json +0 -4
- package/providers/fake/vitest.config.ts +0 -14
- package/providers/google-analytics/src/core/initialize.ts +0 -16
- package/providers/google-analytics/src/schema/capabilities.schema.ts +0 -10
- package/providers/medusa/README.md +0 -30
- package/providers/medusa/TESTING.md +0 -98
- package/providers/medusa/eslint.config.mjs +0 -19
- package/providers/medusa/package.json +0 -15
- package/providers/medusa/src/core/initialize.ts +0 -87
- package/providers/medusa/src/index.ts +0 -15
- package/providers/medusa/src/schema/capabilities.schema.ts +0 -20
- package/providers/medusa/tsconfig.json +0 -24
- package/providers/medusa/tsconfig.spec.json +0 -4
- package/providers/medusa/vitest.config.ts +0 -15
- package/providers/meilisearch/README.md +0 -48
- package/providers/meilisearch/eslint.config.mjs +0 -22
- package/providers/meilisearch/package.json +0 -13
- package/providers/meilisearch/src/core/initialize.ts +0 -27
- package/providers/meilisearch/src/index.ts +0 -7
- package/providers/meilisearch/src/providers/index.ts +0 -2
- package/providers/meilisearch/src/schema/capabilities.schema.ts +0 -11
- package/providers/meilisearch/tsconfig.lib.json +0 -10
- package/providers/meilisearch/tsconfig.spec.json +0 -4
- package/providers/meilisearch/vitest.config.ts +0 -14
- package/providers/posthog/README.md +0 -7
- package/providers/posthog/eslint.config.mjs +0 -22
- package/providers/posthog/package.json +0 -12
- package/providers/posthog/src/core/initialize.ts +0 -11
- package/providers/posthog/src/index.ts +0 -4
- package/providers/posthog/src/schema/capabilities.schema.ts +0 -8
- package/providers/posthog/src/schema/configuration.schema.ts +0 -8
- package/providers/posthog/tsconfig.json +0 -21
- package/providers/posthog/tsconfig.lib.json +0 -9
- /package/{providers → packages}/algolia/src/schema/configuration.schema.ts +0 -0
- /package/{providers → packages}/algolia/src/schema/index.ts +0 -0
- /package/{providers → packages}/algolia/src/schema/product-recommendation.schema.ts +0 -0
- /package/{providers → packages}/algolia/src/schema/search.schema.ts +0 -0
- /package/{providers/google-analytics → packages/algolia}/tsconfig.json +0 -0
- /package/{providers/google-analytics → packages/algolia}/tsconfig.lib.json +0 -0
- /package/{providers/google-analytics → packages/algolia}/tsconfig.spec.json +0 -0
- /package/{providers → packages}/commercetools/src/core/token-cache.ts +0 -0
- /package/{providers → packages}/commercetools/src/schema/commercetools.schema.ts +0 -0
- /package/{providers → packages}/commercetools/src/schema/configuration.schema.ts +0 -0
- /package/{providers → packages}/commercetools/src/schema/session.schema.ts +0 -0
- /package/{providers → packages}/commercetools/src/test/identity.spec.ts +0 -0
- /package/{providers → packages}/commercetools/src/test/test-utils.ts +0 -0
- /package/{core → packages/core}/README.md +0 -0
- /package/{core → packages/core}/src/cache/cache.interface.ts +0 -0
- /package/{core → packages/core}/src/cache/index.ts +0 -0
- /package/{core → packages/core}/src/cache/memory-cache.ts +0 -0
- /package/{core → packages/core}/src/cache/noop-cache.ts +0 -0
- /package/{core → packages/core}/src/cache/redis-cache.ts +0 -0
- /package/{core → packages/core}/src/client/index.ts +0 -0
- /package/{core → packages/core}/src/decorators/index.ts +0 -0
- /package/{core → packages/core}/src/initialization.ts +0 -0
- /package/{core → packages/core}/src/metrics/metrics.ts +0 -0
- /package/{core → packages/core}/src/schemas/capabilities.schema.ts +0 -0
- /package/{core → packages/core}/src/schemas/errors/generic.error.ts +0 -0
- /package/{core → packages/core}/src/schemas/errors/index.ts +0 -0
- /package/{core → packages/core}/src/schemas/errors/invalid-input.error.ts +0 -0
- /package/{core → packages/core}/src/schemas/errors/invalid-output.error.ts +0 -0
- /package/{core → packages/core}/src/schemas/errors/not-found.error.ts +0 -0
- /package/{core → packages/core}/src/schemas/index.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/analytics.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/base.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/cart.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/category.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/checkout.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/cost.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/currency.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/identifiers.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/identity.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/index.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/inventory.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/order-search.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/order.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/payment.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/price.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/product-associations.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/product-list.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/product-recommendations.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/product-reviews.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/product-search.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/product.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/profile.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/shipping-method.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/models/store.model.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/analytics/index.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/analytics/product-add-to-cart.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/analytics/product-details-view.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/analytics/product-summary-click.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/analytics/product-summary-view.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/analytics/purchase.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/base.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/cart.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/checkout.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/identity.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/index.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/inventory.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/price.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/product-list.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/product-reviews.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/product.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/profile.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/mutations/search.mutation.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/analytics.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/base.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/cart.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/category.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/checkout.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/identity.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/index.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/inventory.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/order-search.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/order.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/price.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/product-associations.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/product-list.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/product-recommendations.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/product-reviews.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/product-search.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/product.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/profile.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/queries/store.query.ts +0 -0
- /package/{core → packages/core}/src/schemas/result.ts +0 -0
- /package/{core → packages/core}/src/schemas/session.schema.ts +0 -0
- /package/{core → packages/core}/src/test/request-context.spec.ts +0 -0
- /package/{core → packages/core}/src/zod-utils.ts +0 -0
- /package/{providers → packages}/fake/src/schema/configuration.schema.ts +0 -0
- /package/{providers → packages}/fake/src/test/test-utils.ts +0 -0
- /package/{providers → packages}/fake/src/utilities/jitter.ts +0 -0
- /package/{providers → packages}/fake/src/utilities/seed.ts +0 -0
- /package/{providers → packages}/google-analytics/README.md +0 -0
- /package/{providers → packages}/google-analytics/src/schema/configuration.schema.ts +0 -0
- /package/{providers → packages}/medusa/src/core/client.ts +0 -0
- /package/{providers → packages}/medusa/src/schema/configuration.schema.ts +0 -0
- /package/{providers → packages}/medusa/src/schema/medusa.schema.ts +0 -0
- /package/{providers → packages}/medusa/src/test/test-utils.ts +0 -0
- /package/{providers → packages}/meilisearch/src/schema/configuration.schema.ts +0 -0
- /package/{providers → packages}/meilisearch/src/schema/index.ts +0 -0
- /package/{providers → packages}/meilisearch/src/schema/search.schema.ts +0 -0
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
InventoryFactory,
|
|
3
|
+
InventoryFactoryOutput,
|
|
4
|
+
InventoryFactoryWithOutput,
|
|
3
5
|
RequestContext,
|
|
4
6
|
Cache,
|
|
5
7
|
InventoryQueryBySKU,
|
|
6
|
-
InventoryIdentifier,
|
|
7
|
-
InventoryStatus,
|
|
8
8
|
Result,
|
|
9
9
|
NotFoundError,
|
|
10
10
|
} from '@reactionary/core';
|
|
11
|
-
import {
|
|
11
|
+
import { InventoryCapability, InventoryQueryBySKUSchema, InventorySchema, Reactionary, success, error } from '@reactionary/core';
|
|
12
12
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
13
|
-
import type { InventoryEntry } from '@commercetools/platform-sdk';
|
|
14
13
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
14
|
+
import type { CommercetoolsInventoryFactory } from '../factories/inventory/inventory.factory.js';
|
|
15
15
|
|
|
16
|
-
export class
|
|
16
|
+
export class CommercetoolsInventoryCapability<
|
|
17
|
+
TFactory extends InventoryFactory = CommercetoolsInventoryFactory,
|
|
18
|
+
> extends InventoryCapability<InventoryFactoryOutput<TFactory>> {
|
|
17
19
|
protected config: CommercetoolsConfiguration;
|
|
18
20
|
protected commercetools: CommercetoolsAPI;
|
|
21
|
+
protected factory: InventoryFactoryWithOutput<TFactory>;
|
|
19
22
|
|
|
20
23
|
constructor(
|
|
21
24
|
config: CommercetoolsConfiguration,
|
|
22
25
|
cache: Cache,
|
|
23
26
|
context: RequestContext,
|
|
24
|
-
commercetools: CommercetoolsAPI
|
|
27
|
+
commercetools: CommercetoolsAPI,
|
|
28
|
+
factory: InventoryFactoryWithOutput<TFactory>,
|
|
25
29
|
) {
|
|
26
30
|
super(cache, context);
|
|
27
31
|
|
|
28
32
|
this.config = config;
|
|
29
33
|
this.commercetools = commercetools;
|
|
34
|
+
this.factory = factory;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
protected async getClient() {
|
|
@@ -42,7 +47,7 @@ export class CommercetoolsInventoryProvider extends InventoryProvider {
|
|
|
42
47
|
inputSchema: InventoryQueryBySKUSchema,
|
|
43
48
|
outputSchema: InventorySchema,
|
|
44
49
|
})
|
|
45
|
-
public override async getBySKU(payload: InventoryQueryBySKU): Promise<Result<
|
|
50
|
+
public override async getBySKU(payload: InventoryQueryBySKU): Promise<Result<InventoryFactoryOutput<TFactory>, NotFoundError>> {
|
|
46
51
|
const client = await this.getClient();
|
|
47
52
|
|
|
48
53
|
try {
|
|
@@ -65,7 +70,7 @@ export class CommercetoolsInventoryProvider extends InventoryProvider {
|
|
|
65
70
|
|
|
66
71
|
const result = remote.body.results[0];
|
|
67
72
|
|
|
68
|
-
const model = this.
|
|
73
|
+
const model = this.factory.parseInventory(this.context, result);
|
|
69
74
|
|
|
70
75
|
|
|
71
76
|
return success(model);
|
|
@@ -78,27 +83,4 @@ export class CommercetoolsInventoryProvider extends InventoryProvider {
|
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
|
|
81
|
-
protected parseSingle(body: InventoryEntry): Inventory {
|
|
82
|
-
const identifier = {
|
|
83
|
-
variant: { sku: body.sku || '' },
|
|
84
|
-
fulfillmentCenter: {
|
|
85
|
-
key: body.supplyChannel?.obj?.key || '',
|
|
86
|
-
},
|
|
87
|
-
} satisfies InventoryIdentifier;
|
|
88
|
-
|
|
89
|
-
const quantity = body.availableQuantity || 0;
|
|
90
|
-
let status: InventoryStatus = 'outOfStock';
|
|
91
|
-
|
|
92
|
-
if (quantity > 0) {
|
|
93
|
-
status = 'inStock';
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const result = {
|
|
97
|
-
identifier,
|
|
98
|
-
quantity,
|
|
99
|
-
status,
|
|
100
|
-
} satisfies Inventory;
|
|
101
|
-
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
86
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RequestContext,
|
|
3
|
+
Cache,
|
|
4
|
+
OrderSearchFactory,
|
|
5
|
+
OrderSearchFactoryOutput,
|
|
6
|
+
OrderSearchFactoryWithOutput,
|
|
7
|
+
OrderSearchQueryByTerm,
|
|
8
|
+
Result,
|
|
9
|
+
} from '@reactionary/core';
|
|
10
|
+
import {
|
|
11
|
+
OrderSearchCapability,
|
|
12
|
+
OrderSearchQueryByTermSchema,
|
|
13
|
+
OrderSearchResultSchema,
|
|
14
|
+
Reactionary,
|
|
15
|
+
success,
|
|
16
|
+
} from '@reactionary/core';
|
|
17
|
+
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
18
|
+
import type { CommercetoolsAPI } from '../core/client.js';
|
|
19
|
+
import createDebug from 'debug';
|
|
20
|
+
import type { OrderPagedQueryResponse } from '@commercetools/platform-sdk';
|
|
21
|
+
import type { CommercetoolsOrderSearchFactory } from '../factories/order-search/order-search.factory.js';
|
|
22
|
+
|
|
23
|
+
const debug = createDebug('reactionary:commercetools:order-search');
|
|
24
|
+
|
|
25
|
+
export class CommercetoolsOrderSearchCapability<
|
|
26
|
+
TFactory extends OrderSearchFactory = CommercetoolsOrderSearchFactory,
|
|
27
|
+
> extends OrderSearchCapability<OrderSearchFactoryOutput<TFactory>> {
|
|
28
|
+
protected config: CommercetoolsConfiguration;
|
|
29
|
+
protected commercetools: CommercetoolsAPI;
|
|
30
|
+
protected factory: OrderSearchFactoryWithOutput<TFactory>;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
config: CommercetoolsConfiguration,
|
|
34
|
+
cache: Cache,
|
|
35
|
+
context: RequestContext,
|
|
36
|
+
commercetools: CommercetoolsAPI,
|
|
37
|
+
factory: OrderSearchFactoryWithOutput<TFactory>,
|
|
38
|
+
) {
|
|
39
|
+
super(cache, context);
|
|
40
|
+
|
|
41
|
+
this.config = config;
|
|
42
|
+
this.commercetools = commercetools;
|
|
43
|
+
this.factory = factory;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected async getClient() {
|
|
47
|
+
const client = await this.commercetools.getClient();
|
|
48
|
+
return client
|
|
49
|
+
.withProjectKey({ projectKey: this.config.projectKey })
|
|
50
|
+
.me()
|
|
51
|
+
.orders();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@Reactionary({
|
|
55
|
+
inputSchema: OrderSearchQueryByTermSchema,
|
|
56
|
+
outputSchema: OrderSearchResultSchema,
|
|
57
|
+
})
|
|
58
|
+
public async queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<OrderSearchFactoryOutput<TFactory>>> {
|
|
59
|
+
debug('queryByTerm', payload);
|
|
60
|
+
|
|
61
|
+
const client = await this.getClient();
|
|
62
|
+
const where: string[] = [];
|
|
63
|
+
if (payload.search) {
|
|
64
|
+
if (payload.search.term) {
|
|
65
|
+
debug('Search by term is not implemented yet in CommercetoolsOrderSearchCapability');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (payload.search.partNumber) {
|
|
69
|
+
for (const partNumber of payload.search.partNumber) {
|
|
70
|
+
where.push(`lineItems(variant(sku="${partNumber}"))`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (payload.search.user && payload.search.user.userId) {
|
|
75
|
+
|
|
76
|
+
// where.push(`customerId="${payload.search.user.userId}"`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (payload.search.orderStatus) {
|
|
80
|
+
const orderStatusWhere = payload.search.orderStatus.map(x => {
|
|
81
|
+
let mappedStatus = 'Open';
|
|
82
|
+
if (x === 'AwaitingPayment') {
|
|
83
|
+
mappedStatus = `Open`
|
|
84
|
+
}
|
|
85
|
+
if (x === 'ReleasedToFulfillment') {
|
|
86
|
+
mappedStatus = `Confirmed`
|
|
87
|
+
}
|
|
88
|
+
if (x === 'Shipped') {
|
|
89
|
+
mappedStatus = `Complete`
|
|
90
|
+
}
|
|
91
|
+
if (x === 'Cancelled') {
|
|
92
|
+
mappedStatus = `Cancelled`
|
|
93
|
+
}
|
|
94
|
+
return `orderState="${mappedStatus}"`
|
|
95
|
+
}).join(' OR ');
|
|
96
|
+
where.push(orderStatusWhere);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (payload.search.startDate) {
|
|
100
|
+
where.push(`createdAt >= "${payload.search.startDate}"`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (payload.search.endDate) {
|
|
104
|
+
where.push(`createdAt <= "${payload.search.endDate}"`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const response = await client.get({
|
|
109
|
+
queryArgs: {
|
|
110
|
+
where: where,
|
|
111
|
+
withTotal: true,
|
|
112
|
+
limit: payload.search.paginationOptions.pageSize,
|
|
113
|
+
offset:
|
|
114
|
+
(payload.search.paginationOptions.pageNumber - 1) *
|
|
115
|
+
payload.search.paginationOptions.pageSize,
|
|
116
|
+
}
|
|
117
|
+
}).execute();
|
|
118
|
+
|
|
119
|
+
const responseBody = response.body;
|
|
120
|
+
const result = this.factory.parseOrderSearchResult(
|
|
121
|
+
this.context,
|
|
122
|
+
responseBody,
|
|
123
|
+
payload
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
if (debug.enabled) {
|
|
127
|
+
debug(
|
|
128
|
+
`Search for term "${payload.search.term}" returned ${responseBody.results.length} orders (page ${payload.search.paginationOptions.pageNumber} of ${result.totalPages})`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return success(result);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RequestContext,
|
|
3
|
+
Cache,
|
|
4
|
+
OrderFactory,
|
|
5
|
+
OrderFactoryOutput,
|
|
6
|
+
OrderFactoryWithOutput,
|
|
7
|
+
OrderQueryById,
|
|
8
|
+
Result,
|
|
9
|
+
NotFoundError,
|
|
10
|
+
} from '@reactionary/core';
|
|
11
|
+
import { OrderCapability, OrderQueryByIdSchema, OrderSchema, Reactionary, success, error } from '@reactionary/core';
|
|
12
|
+
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
13
|
+
import type { CommercetoolsAPI } from '../core/client.js';
|
|
14
|
+
import type { CommercetoolsOrderFactory } from '../factories/order/order.factory.js';
|
|
15
|
+
|
|
16
|
+
export class CommercetoolsOrderCapability<
|
|
17
|
+
TFactory extends OrderFactory = CommercetoolsOrderFactory,
|
|
18
|
+
> extends OrderCapability<OrderFactoryOutput<TFactory>> {
|
|
19
|
+
protected config: CommercetoolsConfiguration;
|
|
20
|
+
protected commercetools: CommercetoolsAPI;
|
|
21
|
+
protected factory: OrderFactoryWithOutput<TFactory>;
|
|
22
|
+
|
|
23
|
+
constructor(
|
|
24
|
+
config: CommercetoolsConfiguration,
|
|
25
|
+
cache: Cache,
|
|
26
|
+
context: RequestContext,
|
|
27
|
+
commercetools: CommercetoolsAPI,
|
|
28
|
+
factory: OrderFactoryWithOutput<TFactory>,
|
|
29
|
+
) {
|
|
30
|
+
super(cache, context);
|
|
31
|
+
|
|
32
|
+
this.config = config;
|
|
33
|
+
this.commercetools = commercetools;
|
|
34
|
+
this.factory = factory;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected async getClient() {
|
|
38
|
+
const client = await this.commercetools.getClient();
|
|
39
|
+
return client
|
|
40
|
+
.withProjectKey({ projectKey: this.config.projectKey })
|
|
41
|
+
.me()
|
|
42
|
+
.orders();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Reactionary({
|
|
46
|
+
inputSchema: OrderQueryByIdSchema,
|
|
47
|
+
outputSchema: OrderSchema,
|
|
48
|
+
})
|
|
49
|
+
public override async getById(payload: OrderQueryById): Promise<Result<OrderFactoryOutput<TFactory>, NotFoundError>> {
|
|
50
|
+
const client = await this.getClient();
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const remote = await client
|
|
54
|
+
.withId({ ID: payload.order.key })
|
|
55
|
+
.get()
|
|
56
|
+
.execute();
|
|
57
|
+
|
|
58
|
+
return success(this.factory.parseOrder(this.context, remote.body));
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return error<NotFoundError>({
|
|
61
|
+
type: 'NotFound',
|
|
62
|
+
identifier: payload
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CustomerPriceQuerySchema,
|
|
3
3
|
ListPriceQuerySchema,
|
|
4
|
-
|
|
4
|
+
PriceCapability,
|
|
5
|
+
type PriceFactory,
|
|
6
|
+
type PriceFactoryOutput,
|
|
7
|
+
type PriceFactoryWithOutput,
|
|
5
8
|
PriceSchema,
|
|
6
9
|
Reactionary,
|
|
7
10
|
success,
|
|
8
11
|
} from '@reactionary/core';
|
|
9
12
|
import type {
|
|
10
13
|
RequestContext,
|
|
11
|
-
Price,
|
|
12
14
|
Cache,
|
|
13
|
-
Currency,
|
|
14
15
|
CustomerPriceQuery,
|
|
15
16
|
ListPriceQuery,
|
|
16
|
-
PriceIdentifier,
|
|
17
|
-
MonetaryAmount,
|
|
18
17
|
Result,
|
|
19
18
|
} from '@reactionary/core';
|
|
20
19
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
21
20
|
import type {
|
|
22
|
-
Price as CTPrice,
|
|
23
21
|
ProductVariant as CTProductVariant,
|
|
24
22
|
} from '@commercetools/platform-sdk';
|
|
25
23
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
24
|
+
import type { CommercetoolsPriceFactory } from '../factories/price/price.factory.js';
|
|
26
25
|
|
|
27
|
-
export class
|
|
26
|
+
export class CommercetoolsPriceCapability<
|
|
27
|
+
TFactory extends PriceFactory = CommercetoolsPriceFactory,
|
|
28
|
+
> extends PriceCapability<PriceFactoryOutput<TFactory>> {
|
|
28
29
|
protected config: CommercetoolsConfiguration;
|
|
29
30
|
protected commercetools: CommercetoolsAPI;
|
|
31
|
+
protected factory: PriceFactoryWithOutput<TFactory>;
|
|
30
32
|
|
|
31
33
|
constructor(
|
|
32
34
|
config: CommercetoolsConfiguration,
|
|
33
35
|
cache: Cache,
|
|
34
36
|
context: RequestContext,
|
|
35
|
-
commercetools: CommercetoolsAPI
|
|
37
|
+
commercetools: CommercetoolsAPI,
|
|
38
|
+
factory: PriceFactoryWithOutput<TFactory>,
|
|
36
39
|
) {
|
|
37
40
|
super(cache, context);
|
|
38
41
|
|
|
39
42
|
this.config = config;
|
|
40
43
|
this.commercetools = commercetools;
|
|
44
|
+
this.factory = factory;
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
@Reactionary({
|
|
@@ -46,7 +50,7 @@ export class CommercetoolsPriceProvider extends PriceProvider {
|
|
|
46
50
|
})
|
|
47
51
|
public override async getCustomerPrice(
|
|
48
52
|
payload: CustomerPriceQuery
|
|
49
|
-
): Promise<Result<
|
|
53
|
+
): Promise<Result<PriceFactoryOutput<TFactory>>> {
|
|
50
54
|
const client = await this.getClient();
|
|
51
55
|
let priceChannelId;
|
|
52
56
|
if (this.config.customerPriceChannelKey) {
|
|
@@ -76,14 +80,14 @@ export class CommercetoolsPriceProvider extends PriceProvider {
|
|
|
76
80
|
(x) => x.sku === payload.variant.sku
|
|
77
81
|
);
|
|
78
82
|
|
|
79
|
-
return success(this.
|
|
83
|
+
return success(this.factory.parsePrice(this.context, sku, { includeDiscounts: true }));
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
@Reactionary({
|
|
83
87
|
inputSchema: ListPriceQuerySchema,
|
|
84
88
|
outputSchema: PriceSchema,
|
|
85
89
|
})
|
|
86
|
-
public override async getListPrice(payload: ListPriceQuery): Promise<Result<
|
|
90
|
+
public override async getListPrice(payload: ListPriceQuery): Promise<Result<PriceFactoryOutput<TFactory>>> {
|
|
87
91
|
const client = await this.getClient();
|
|
88
92
|
let priceChannelId;
|
|
89
93
|
if (this.config.listPriceChannelKey) {
|
|
@@ -112,7 +116,7 @@ export class CommercetoolsPriceProvider extends PriceProvider {
|
|
|
112
116
|
(x) => x.sku === payload.variant.sku
|
|
113
117
|
);
|
|
114
118
|
|
|
115
|
-
return success(this.
|
|
119
|
+
return success(this.factory.parsePrice(this.context, sku));
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
protected async getClient() {
|
|
@@ -120,48 +124,30 @@ export class CommercetoolsPriceProvider extends PriceProvider {
|
|
|
120
124
|
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
121
125
|
}
|
|
122
126
|
|
|
123
|
-
protected
|
|
124
|
-
|
|
125
|
-
options = { includeDiscounts: false }
|
|
126
|
-
): Price {
|
|
127
|
-
const body = _body as CTProductVariant;
|
|
128
|
-
const price = body.price as CTPrice | undefined;
|
|
127
|
+
protected async getChannels() {
|
|
128
|
+
const adminClient = await this.commercetools.getAdminClient();
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (price.discounted) {
|
|
143
|
-
isOnSale = true;
|
|
144
|
-
}
|
|
145
|
-
unitPrice = {
|
|
146
|
-
value: discountedPrice.centAmount / 100,
|
|
147
|
-
currency: price.value.currencyCode as Currency,
|
|
148
|
-
} satisfies MonetaryAmount;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const identifier = {
|
|
152
|
-
variant: {
|
|
153
|
-
sku: body.sku!,
|
|
154
|
-
},
|
|
155
|
-
} satisfies PriceIdentifier;
|
|
130
|
+
const offerPriceChannelPromise = adminClient
|
|
131
|
+
.withProjectKey({ projectKey: this.config.projectKey })
|
|
132
|
+
.channels()
|
|
133
|
+
.withKey({ key: 'Offer Price' })
|
|
134
|
+
.get()
|
|
135
|
+
.execute();
|
|
136
|
+
const listPriceChannelPromise = adminClient
|
|
137
|
+
.withProjectKey({ projectKey: this.config.projectKey })
|
|
138
|
+
.channels()
|
|
139
|
+
.withKey({ key: 'List Price' })
|
|
140
|
+
.get()
|
|
141
|
+
.execute();
|
|
156
142
|
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
onSale: isOnSale,
|
|
162
|
-
} satisfies Price;
|
|
143
|
+
const [offerChannel, listChannel] = await Promise.all([
|
|
144
|
+
offerPriceChannelPromise,
|
|
145
|
+
listPriceChannelPromise,
|
|
146
|
+
]);
|
|
163
147
|
|
|
164
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
offer: offerChannel.body.id,
|
|
150
|
+
list: listChannel.body.id,
|
|
151
|
+
};
|
|
165
152
|
}
|
|
166
|
-
|
|
167
153
|
}
|
|
@@ -1,47 +1,45 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
type ProductAssociationsFactory,
|
|
3
|
+
type ProductAssociationsFactoryOutput,
|
|
4
|
+
type ProductAssociationsFactoryWithOutput,
|
|
5
|
+
ProductAssociationsCapability,
|
|
3
6
|
Reactionary,
|
|
4
|
-
ImageSchema,
|
|
5
|
-
ProductVariantOptionSchema,
|
|
6
|
-
ProductOptionIdentifierSchema,
|
|
7
|
-
ProductSearchResultItemVariantSchema,
|
|
8
|
-
ProductVariantIdentifierSchema,
|
|
9
7
|
success,
|
|
10
8
|
error,
|
|
11
9
|
} from '@reactionary/core';
|
|
12
10
|
import type {
|
|
13
|
-
ProductVariantIdentifier,
|
|
14
11
|
ProductIdentifier,
|
|
15
|
-
ProductAssociation,
|
|
16
|
-
ProductSearchResultItem,
|
|
17
|
-
ProductSearchResultItemVariant,
|
|
18
12
|
ProductAssociationsGetAccessoriesQuery,
|
|
19
13
|
ProductAssociationsGetSparepartsQuery,
|
|
20
14
|
ProductAssociationsGetReplacementsQuery,
|
|
21
15
|
Result,
|
|
22
16
|
RequestContext,
|
|
23
17
|
Cache,
|
|
24
|
-
ProductOptionIdentifier,
|
|
25
|
-
ProductVariantOption,
|
|
26
18
|
NotFoundError,
|
|
27
19
|
} from '@reactionary/core';
|
|
28
|
-
import type { ProductProjection
|
|
20
|
+
import type { ProductProjection } from '@commercetools/platform-sdk';
|
|
29
21
|
import type { CommercetoolsConfiguration } from '../schema/configuration.schema.js';
|
|
30
22
|
import type { CommercetoolsAPI } from '../core/client.js';
|
|
23
|
+
import type { CommercetoolsProductAssociationsFactory } from '../factories/product-associations/product-associations.factory.js';
|
|
31
24
|
|
|
32
|
-
export class
|
|
25
|
+
export class CommercetoolsProductAssociationsCapability<
|
|
26
|
+
TFactory extends ProductAssociationsFactory = CommercetoolsProductAssociationsFactory,
|
|
27
|
+
> extends ProductAssociationsCapability<ProductAssociationsFactoryOutput<TFactory>> {
|
|
33
28
|
protected config: CommercetoolsConfiguration;
|
|
34
29
|
protected commercetools: CommercetoolsAPI;
|
|
30
|
+
protected factory: ProductAssociationsFactoryWithOutput<TFactory>;
|
|
35
31
|
|
|
36
32
|
constructor(
|
|
37
33
|
config: CommercetoolsConfiguration,
|
|
38
34
|
cache: Cache,
|
|
39
35
|
context: RequestContext,
|
|
40
|
-
commercetools: CommercetoolsAPI
|
|
36
|
+
commercetools: CommercetoolsAPI,
|
|
37
|
+
factory: ProductAssociationsFactoryWithOutput<TFactory>,
|
|
41
38
|
) {
|
|
42
39
|
super(cache, context);
|
|
43
40
|
this.config = config;
|
|
44
41
|
this.commercetools = commercetools;
|
|
42
|
+
this.factory = factory;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
protected async getClient() {
|
|
@@ -49,7 +47,7 @@ export class CommercetoolsProductAssociationsProvider extends ProductAssociation
|
|
|
49
47
|
return client.withProjectKey({ projectKey: this.config.projectKey });
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
protected async fetchAssociatedProductsFor(productKey: ProductIdentifier, maxNumberOfAssociations: number, attributeName: string): Promise<
|
|
50
|
+
protected async fetchAssociatedProductsFor(productKey: ProductIdentifier, maxNumberOfAssociations: number, attributeName: string): Promise<ProductProjection[]> {
|
|
53
51
|
const client = await this.getClient();
|
|
54
52
|
|
|
55
53
|
const product = await client
|
|
@@ -74,7 +72,7 @@ export class CommercetoolsProductAssociationsProvider extends ProductAssociation
|
|
|
74
72
|
if (!associationsAttr) {
|
|
75
73
|
return [];
|
|
76
74
|
}
|
|
77
|
-
const associatedProductSearchItems:
|
|
75
|
+
const associatedProductSearchItems: ProductProjection[] = [];
|
|
78
76
|
|
|
79
77
|
// look up each associated product,
|
|
80
78
|
const allAssociatedProductPromises = (associationsAttr.value as string[]).map(async (associatedProductId) => {
|
|
@@ -90,34 +88,12 @@ export class CommercetoolsProductAssociationsProvider extends ProductAssociation
|
|
|
90
88
|
const associatedProductsResults = await Promise.all(allAssociatedProductPromises);
|
|
91
89
|
const validAssociatedProductsResults = associatedProductsResults.filter(result => !!result).slice(0, maxNumberOfAssociations);
|
|
92
90
|
for (const associatedProductResult of validAssociatedProductsResults) {
|
|
93
|
-
|
|
94
|
-
if (resultItem) {
|
|
95
|
-
associatedProductSearchItems.push(resultItem);
|
|
96
|
-
}
|
|
91
|
+
associatedProductSearchItems.push(associatedProductResult.body);
|
|
97
92
|
}
|
|
98
93
|
return associatedProductSearchItems;
|
|
99
94
|
}
|
|
100
95
|
|
|
101
96
|
|
|
102
|
-
protected parseSingle(body: ProductProjection) {
|
|
103
|
-
const identifier = { key: body.id };
|
|
104
|
-
const name = body.name[this.context.languageContext.locale] || body.id;
|
|
105
|
-
const slug = body.slug?.[this.context.languageContext.locale] || body.id;
|
|
106
|
-
const variants = [body.masterVariant, ...body.variants].map((variant) =>
|
|
107
|
-
this.parseVariant(variant, body)
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const product = {
|
|
111
|
-
identifier,
|
|
112
|
-
name,
|
|
113
|
-
slug,
|
|
114
|
-
variants,
|
|
115
|
-
} satisfies ProductSearchResultItem;
|
|
116
|
-
|
|
117
|
-
return product;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
97
|
@Reactionary({
|
|
122
98
|
cache: true,
|
|
123
99
|
cacheTimeToLiveInSeconds: 300,
|
|
@@ -126,17 +102,17 @@ export class CommercetoolsProductAssociationsProvider extends ProductAssociation
|
|
|
126
102
|
})
|
|
127
103
|
public override async getAccessories(
|
|
128
104
|
query: ProductAssociationsGetAccessoriesQuery
|
|
129
|
-
): Promise<Result<
|
|
105
|
+
): Promise<Result<ProductAssociationsFactoryOutput<TFactory>[]>> {
|
|
130
106
|
|
|
131
107
|
const associatedProducts = await this.fetchAssociatedProductsFor(query.forProduct, query.numberOfAccessories || 4, 'reactionaryaccessories');
|
|
132
108
|
|
|
133
|
-
const result
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
109
|
+
const result = associatedProducts.map((product) =>
|
|
110
|
+
this.factory.parseAssociation(this.context, {
|
|
111
|
+
sourceProductKey: query.forProduct.key,
|
|
112
|
+
relation: 'accessory',
|
|
113
|
+
product,
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
140
116
|
|
|
141
117
|
return success(result);
|
|
142
118
|
}
|
|
@@ -149,16 +125,16 @@ export class CommercetoolsProductAssociationsProvider extends ProductAssociation
|
|
|
149
125
|
})
|
|
150
126
|
public override async getSpareparts(
|
|
151
127
|
query: ProductAssociationsGetSparepartsQuery
|
|
152
|
-
): Promise<Result<
|
|
128
|
+
): Promise<Result<ProductAssociationsFactoryOutput<TFactory>[]>> {
|
|
153
129
|
const associatedProducts = await this.fetchAssociatedProductsFor(query.forProduct, query.numberOfSpareparts || 4, 'reactionaryspareparts');
|
|
154
130
|
|
|
155
|
-
const result
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
131
|
+
const result = associatedProducts.map((product) =>
|
|
132
|
+
this.factory.parseAssociation(this.context, {
|
|
133
|
+
sourceProductKey: query.forProduct.key,
|
|
134
|
+
relation: 'sparepart',
|
|
135
|
+
product,
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
162
138
|
|
|
163
139
|
return success(result);
|
|
164
140
|
}
|
|
@@ -171,59 +147,18 @@ export class CommercetoolsProductAssociationsProvider extends ProductAssociation
|
|
|
171
147
|
})
|
|
172
148
|
public override async getReplacements(
|
|
173
149
|
query: ProductAssociationsGetReplacementsQuery
|
|
174
|
-
): Promise<Result<
|
|
150
|
+
): Promise<Result<ProductAssociationsFactoryOutput<TFactory>[]>> {
|
|
175
151
|
const associatedProducts = await this.fetchAssociatedProductsFor(query.forProduct, query.numberOfReplacements || 4, 'reactionaryreplacements');
|
|
176
152
|
|
|
177
|
-
const result
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
153
|
+
const result = associatedProducts.map((product) =>
|
|
154
|
+
this.factory.parseAssociation(this.context, {
|
|
155
|
+
sourceProductKey: query.forProduct.key,
|
|
156
|
+
relation: 'replacement',
|
|
157
|
+
product,
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
184
160
|
|
|
185
161
|
return success(result);
|
|
186
162
|
}
|
|
187
163
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
protected parseVariant(
|
|
192
|
-
variant: CTProductVariant,
|
|
193
|
-
product: ProductProjection
|
|
194
|
-
): ProductSearchResultItemVariant {
|
|
195
|
-
const sourceImage = variant.images?.[0];
|
|
196
|
-
|
|
197
|
-
const img = ImageSchema.parse({
|
|
198
|
-
sourceUrl: sourceImage?.url || '',
|
|
199
|
-
height: sourceImage?.dimensions.h || undefined,
|
|
200
|
-
width: sourceImage?.dimensions.w || undefined,
|
|
201
|
-
altText:
|
|
202
|
-
sourceImage?.label ||
|
|
203
|
-
product.name[this.context.languageContext.locale] ||
|
|
204
|
-
undefined,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const mappedOptions =
|
|
208
|
-
variant.attributes
|
|
209
|
-
?.filter((x) => x.name === 'Color')
|
|
210
|
-
.map((opt) =>
|
|
211
|
-
ProductVariantOptionSchema.parse({
|
|
212
|
-
identifier: ProductOptionIdentifierSchema.parse({
|
|
213
|
-
key: opt.name,
|
|
214
|
-
} satisfies Partial<ProductOptionIdentifier>),
|
|
215
|
-
name: opt.value || '',
|
|
216
|
-
} satisfies Partial<ProductVariantOption>)
|
|
217
|
-
) || [];
|
|
218
|
-
|
|
219
|
-
const mappedOption = mappedOptions?.[0];
|
|
220
|
-
|
|
221
|
-
return ProductSearchResultItemVariantSchema.parse({
|
|
222
|
-
variant: ProductVariantIdentifierSchema.parse({
|
|
223
|
-
sku: variant.sku || '',
|
|
224
|
-
} satisfies ProductVariantIdentifier),
|
|
225
|
-
image: img,
|
|
226
|
-
options: mappedOption,
|
|
227
|
-
} satisfies Partial<ProductSearchResultItemVariant>);
|
|
228
|
-
}
|
|
229
164
|
}
|