@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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { InventoryEntry } from '@commercetools/platform-sdk';
|
|
2
|
+
import type {
|
|
3
|
+
InventorySchema} from '@reactionary/core';
|
|
4
|
+
import {
|
|
5
|
+
type AnyInventorySchema,
|
|
6
|
+
type Inventory,
|
|
7
|
+
type InventoryFactory,
|
|
8
|
+
type InventoryIdentifier,
|
|
9
|
+
type InventoryStatus,
|
|
10
|
+
type RequestContext,
|
|
11
|
+
} from '@reactionary/core';
|
|
12
|
+
import type * as z from 'zod';
|
|
13
|
+
|
|
14
|
+
export class CommercetoolsInventoryFactory<
|
|
15
|
+
TInventorySchema extends AnyInventorySchema = typeof InventorySchema,
|
|
16
|
+
> implements InventoryFactory<TInventorySchema>
|
|
17
|
+
{
|
|
18
|
+
public readonly inventorySchema: TInventorySchema;
|
|
19
|
+
|
|
20
|
+
constructor(inventorySchema: TInventorySchema) {
|
|
21
|
+
this.inventorySchema = inventorySchema;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public parseInventory(
|
|
25
|
+
_context: RequestContext,
|
|
26
|
+
data: InventoryEntry,
|
|
27
|
+
): z.output<TInventorySchema> {
|
|
28
|
+
const identifier = {
|
|
29
|
+
variant: { sku: data.sku || '' },
|
|
30
|
+
fulfillmentCenter: {
|
|
31
|
+
key: data.supplyChannel?.obj?.key || '',
|
|
32
|
+
},
|
|
33
|
+
} satisfies InventoryIdentifier;
|
|
34
|
+
|
|
35
|
+
const quantity = data.availableQuantity || 0;
|
|
36
|
+
let status: InventoryStatus = 'outOfStock';
|
|
37
|
+
if (quantity > 0) {
|
|
38
|
+
status = 'inStock';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const result = {
|
|
42
|
+
identifier,
|
|
43
|
+
quantity,
|
|
44
|
+
status,
|
|
45
|
+
} satisfies Inventory;
|
|
46
|
+
|
|
47
|
+
return this.inventorySchema.parse(result);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { Order as CTOrder } from '@commercetools/platform-sdk';
|
|
2
|
+
import type {
|
|
3
|
+
OrderSchema} from '@reactionary/core';
|
|
4
|
+
import {
|
|
5
|
+
type AnyOrderSchema,
|
|
6
|
+
type CostBreakDown,
|
|
7
|
+
type Currency,
|
|
8
|
+
type ItemCostBreakdown,
|
|
9
|
+
type Order,
|
|
10
|
+
type OrderFactory,
|
|
11
|
+
type OrderIdentifier,
|
|
12
|
+
type OrderItem,
|
|
13
|
+
type OrderStatus,
|
|
14
|
+
type ProductVariantIdentifier,
|
|
15
|
+
type RequestContext,
|
|
16
|
+
} from '@reactionary/core';
|
|
17
|
+
import type * as z from 'zod';
|
|
18
|
+
import type { CommercetoolsOrderIdentifier } from '../../schema/commercetools.schema.js';
|
|
19
|
+
|
|
20
|
+
export class CommercetoolsOrderFactory<
|
|
21
|
+
TOrderSchema extends AnyOrderSchema = typeof OrderSchema,
|
|
22
|
+
> implements OrderFactory<TOrderSchema>
|
|
23
|
+
{
|
|
24
|
+
public readonly orderSchema: TOrderSchema;
|
|
25
|
+
|
|
26
|
+
constructor(orderSchema: TOrderSchema) {
|
|
27
|
+
this.orderSchema = orderSchema;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public parseOrder(
|
|
31
|
+
_context: RequestContext,
|
|
32
|
+
data: CTOrder,
|
|
33
|
+
): z.output<TOrderSchema> {
|
|
34
|
+
const identifier = {
|
|
35
|
+
key: data.id,
|
|
36
|
+
version: data.version || 0,
|
|
37
|
+
} satisfies CommercetoolsOrderIdentifier;
|
|
38
|
+
|
|
39
|
+
const name = data.custom?.fields['name'] || '';
|
|
40
|
+
const description = data.custom?.fields['description'] || '';
|
|
41
|
+
|
|
42
|
+
const grandTotal = data.totalPrice.centAmount || 0;
|
|
43
|
+
const shippingTotal = data.shippingInfo?.price.centAmount || 0;
|
|
44
|
+
const productTotal = grandTotal - shippingTotal;
|
|
45
|
+
const taxTotal = data.taxedPrice?.totalTax?.centAmount || 0;
|
|
46
|
+
const discountTotal = data.discountOnTotalPrice?.discountedAmount.centAmount || 0;
|
|
47
|
+
const surchargeTotal = 0;
|
|
48
|
+
const currency = data.totalPrice.currencyCode as Currency;
|
|
49
|
+
|
|
50
|
+
const price = {
|
|
51
|
+
totalTax: {
|
|
52
|
+
value: taxTotal / 100,
|
|
53
|
+
currency,
|
|
54
|
+
},
|
|
55
|
+
totalDiscount: {
|
|
56
|
+
value: discountTotal / 100,
|
|
57
|
+
currency,
|
|
58
|
+
},
|
|
59
|
+
totalSurcharge: {
|
|
60
|
+
value: surchargeTotal / 100,
|
|
61
|
+
currency,
|
|
62
|
+
},
|
|
63
|
+
totalShipping: {
|
|
64
|
+
value: shippingTotal / 100,
|
|
65
|
+
currency: data.shippingInfo?.price.currencyCode as Currency,
|
|
66
|
+
},
|
|
67
|
+
totalProductPrice: {
|
|
68
|
+
value: productTotal / 100,
|
|
69
|
+
currency,
|
|
70
|
+
},
|
|
71
|
+
grandTotal: {
|
|
72
|
+
value: grandTotal / 100,
|
|
73
|
+
currency,
|
|
74
|
+
},
|
|
75
|
+
} satisfies CostBreakDown;
|
|
76
|
+
|
|
77
|
+
let orderStatus: OrderStatus = 'AwaitingPayment';
|
|
78
|
+
if (data.paymentState === 'Paid' && data.orderState === 'Confirmed') {
|
|
79
|
+
orderStatus = 'ReleasedToFulfillment';
|
|
80
|
+
}
|
|
81
|
+
if (data.shipmentState === 'Ready' && data.orderState === 'Confirmed') {
|
|
82
|
+
orderStatus = 'ReleasedToFulfillment';
|
|
83
|
+
}
|
|
84
|
+
if (
|
|
85
|
+
(data.shipmentState === 'Shipped' || data.shipmentState === 'Delivered') &&
|
|
86
|
+
data.orderState === 'Completed'
|
|
87
|
+
) {
|
|
88
|
+
orderStatus = 'Shipped';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const items: OrderItem[] = [];
|
|
92
|
+
for (const remoteItem of data.lineItems) {
|
|
93
|
+
const lineIdentifier = {
|
|
94
|
+
key: remoteItem.id,
|
|
95
|
+
} satisfies OrderIdentifier;
|
|
96
|
+
const variant = {
|
|
97
|
+
sku: remoteItem.variant.sku || '',
|
|
98
|
+
} satisfies ProductVariantIdentifier;
|
|
99
|
+
|
|
100
|
+
const unitPrice = remoteItem.price.value.centAmount;
|
|
101
|
+
const totalPrice = remoteItem.totalPrice.centAmount || 0;
|
|
102
|
+
const totalDiscount = remoteItem.price.discounted?.value.centAmount || 0;
|
|
103
|
+
const unitDiscount = totalDiscount / remoteItem.quantity;
|
|
104
|
+
|
|
105
|
+
const linePrice = {
|
|
106
|
+
unitPrice: {
|
|
107
|
+
value: unitPrice / 100,
|
|
108
|
+
currency,
|
|
109
|
+
},
|
|
110
|
+
unitDiscount: {
|
|
111
|
+
value: unitDiscount / 100,
|
|
112
|
+
currency,
|
|
113
|
+
},
|
|
114
|
+
totalPrice: {
|
|
115
|
+
value: totalPrice / 100,
|
|
116
|
+
currency,
|
|
117
|
+
},
|
|
118
|
+
totalDiscount: {
|
|
119
|
+
value: totalDiscount / 100,
|
|
120
|
+
currency,
|
|
121
|
+
},
|
|
122
|
+
} satisfies ItemCostBreakdown;
|
|
123
|
+
|
|
124
|
+
items.push({
|
|
125
|
+
identifier: lineIdentifier,
|
|
126
|
+
inventoryStatus: 'NotAllocated',
|
|
127
|
+
price: linePrice,
|
|
128
|
+
quantity: remoteItem.quantity,
|
|
129
|
+
variant,
|
|
130
|
+
} satisfies OrderItem);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const result = {
|
|
134
|
+
identifier,
|
|
135
|
+
name,
|
|
136
|
+
description,
|
|
137
|
+
price,
|
|
138
|
+
items,
|
|
139
|
+
inventoryStatus: 'NotAllocated',
|
|
140
|
+
paymentInstructions: [],
|
|
141
|
+
userId: {
|
|
142
|
+
userId: '',
|
|
143
|
+
},
|
|
144
|
+
orderStatus,
|
|
145
|
+
} satisfies Order;
|
|
146
|
+
|
|
147
|
+
return this.orderSchema.parse(result);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Address as CTAddress,
|
|
3
|
+
Order as CTOrder,
|
|
4
|
+
OrderPagedQueryResponse,
|
|
5
|
+
} from '@commercetools/platform-sdk';
|
|
6
|
+
import type {
|
|
7
|
+
OrderSearchResultSchema} from '@reactionary/core';
|
|
8
|
+
import {
|
|
9
|
+
type Address,
|
|
10
|
+
type AnyOrderSearchResultSchema,
|
|
11
|
+
type Currency,
|
|
12
|
+
type IdentityIdentifier,
|
|
13
|
+
type MonetaryAmount,
|
|
14
|
+
type OrderSearchFactory,
|
|
15
|
+
type OrderSearchQueryByTerm,
|
|
16
|
+
type OrderSearchResult,
|
|
17
|
+
type OrderSearchResultItem,
|
|
18
|
+
type OrderStatus,
|
|
19
|
+
type RequestContext,
|
|
20
|
+
} from '@reactionary/core';
|
|
21
|
+
import type * as z from 'zod';
|
|
22
|
+
|
|
23
|
+
export class CommercetoolsOrderSearchFactory<
|
|
24
|
+
TOrderSearchResultSchema extends AnyOrderSearchResultSchema = typeof OrderSearchResultSchema,
|
|
25
|
+
> implements OrderSearchFactory<TOrderSearchResultSchema>
|
|
26
|
+
{
|
|
27
|
+
public readonly orderSearchResultSchema: TOrderSearchResultSchema;
|
|
28
|
+
|
|
29
|
+
constructor(orderSearchResultSchema: TOrderSearchResultSchema) {
|
|
30
|
+
this.orderSearchResultSchema = orderSearchResultSchema;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public parseOrderSearchResult(
|
|
34
|
+
context: RequestContext,
|
|
35
|
+
data: OrderPagedQueryResponse,
|
|
36
|
+
query: OrderSearchQueryByTerm,
|
|
37
|
+
): z.output<TOrderSearchResultSchema> {
|
|
38
|
+
const result = {
|
|
39
|
+
identifier: {
|
|
40
|
+
...query.search,
|
|
41
|
+
},
|
|
42
|
+
pageNumber: (Math.ceil(data.offset / data.limit) || 0) + 1,
|
|
43
|
+
pageSize: data.limit,
|
|
44
|
+
totalCount: data.total || 0,
|
|
45
|
+
totalPages: Math.ceil((data.total || 0) / data.limit || 0) + 1,
|
|
46
|
+
items: data.results.map((order) => this.parseOrderSearchItem(context, order)),
|
|
47
|
+
} satisfies OrderSearchResult;
|
|
48
|
+
|
|
49
|
+
return this.orderSearchResultSchema.parse(result);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected parseAddress(data: CTAddress): Address {
|
|
53
|
+
return {
|
|
54
|
+
countryCode: data.country || '',
|
|
55
|
+
firstName: data.firstName || '',
|
|
56
|
+
lastName: data.lastName || '',
|
|
57
|
+
streetAddress: data.streetName || '',
|
|
58
|
+
streetNumber: data.streetNumber || '',
|
|
59
|
+
postalCode: data.postalCode || '',
|
|
60
|
+
city: data.city || '',
|
|
61
|
+
identifier: {
|
|
62
|
+
nickName: '',
|
|
63
|
+
},
|
|
64
|
+
region: '',
|
|
65
|
+
} satisfies Address;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected parseOrderSearchItem(
|
|
69
|
+
context: RequestContext,
|
|
70
|
+
data: CTOrder,
|
|
71
|
+
): OrderSearchResultItem {
|
|
72
|
+
const userId: IdentityIdentifier = {
|
|
73
|
+
userId: data.customerId || data.anonymousId || '',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
let orderStatus: OrderStatus = 'AwaitingPayment';
|
|
77
|
+
if (data.paymentState === 'Paid' && data.orderState === 'Confirmed') {
|
|
78
|
+
orderStatus = 'ReleasedToFulfillment';
|
|
79
|
+
}
|
|
80
|
+
if (data.shipmentState === 'Ready' && data.orderState === 'Confirmed') {
|
|
81
|
+
orderStatus = 'ReleasedToFulfillment';
|
|
82
|
+
}
|
|
83
|
+
if (
|
|
84
|
+
(data.shipmentState === 'Shipped' || data.shipmentState === 'Delivered') &&
|
|
85
|
+
data.orderState === 'Completed'
|
|
86
|
+
) {
|
|
87
|
+
orderStatus = 'Shipped';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const totalAmount: MonetaryAmount = {
|
|
91
|
+
currency: data.totalPrice
|
|
92
|
+
? (data.totalPrice.currencyCode as Currency)
|
|
93
|
+
: context.languageContext.currencyCode,
|
|
94
|
+
value: data.totalPrice ? data.totalPrice.centAmount / 100 : 0,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
identifier: { key: data.id },
|
|
99
|
+
userId,
|
|
100
|
+
customerName: `${data.billingAddress?.firstName} ${data.billingAddress?.lastName}`,
|
|
101
|
+
shippingAddress: this.parseAddress(data.shippingAddress!),
|
|
102
|
+
orderDate: data.createdAt,
|
|
103
|
+
orderStatus,
|
|
104
|
+
inventoryStatus: orderStatus === 'Shipped' ? 'Allocated' : 'NotAllocated',
|
|
105
|
+
totalAmount,
|
|
106
|
+
} satisfies OrderSearchResultItem;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Price as CTPrice, ProductVariant as CTProductVariant } from '@commercetools/platform-sdk';
|
|
2
|
+
import type {
|
|
3
|
+
PriceSchema} from '@reactionary/core';
|
|
4
|
+
import {
|
|
5
|
+
type AnyPriceSchema,
|
|
6
|
+
type Currency,
|
|
7
|
+
type MonetaryAmount,
|
|
8
|
+
type Price,
|
|
9
|
+
type PriceFactory,
|
|
10
|
+
type PriceIdentifier,
|
|
11
|
+
type RequestContext,
|
|
12
|
+
} from '@reactionary/core';
|
|
13
|
+
import type * as z from 'zod';
|
|
14
|
+
|
|
15
|
+
export class CommercetoolsPriceFactory<
|
|
16
|
+
TPriceSchema extends AnyPriceSchema = typeof PriceSchema,
|
|
17
|
+
> implements PriceFactory<TPriceSchema>
|
|
18
|
+
{
|
|
19
|
+
public readonly priceSchema: TPriceSchema;
|
|
20
|
+
|
|
21
|
+
constructor(priceSchema: TPriceSchema) {
|
|
22
|
+
this.priceSchema = priceSchema;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public parsePrice(
|
|
26
|
+
context: RequestContext,
|
|
27
|
+
data: CTProductVariant,
|
|
28
|
+
options = { includeDiscounts: false },
|
|
29
|
+
): z.output<TPriceSchema> {
|
|
30
|
+
const price = data.price as CTPrice | undefined;
|
|
31
|
+
|
|
32
|
+
if (!price) {
|
|
33
|
+
return this.priceSchema.parse({
|
|
34
|
+
identifier: {
|
|
35
|
+
variant: {
|
|
36
|
+
sku: data.sku || '',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
onSale: false,
|
|
40
|
+
tieredPrices: [],
|
|
41
|
+
unitPrice: {
|
|
42
|
+
value: -1,
|
|
43
|
+
currency: context.languageContext.currencyCode,
|
|
44
|
+
},
|
|
45
|
+
} satisfies Price);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let unitPrice = {
|
|
49
|
+
value: price.value.centAmount / 100,
|
|
50
|
+
currency: price.value.currencyCode as Currency,
|
|
51
|
+
} satisfies MonetaryAmount;
|
|
52
|
+
|
|
53
|
+
if (options.includeDiscounts) {
|
|
54
|
+
const discountedPrice = price.discounted?.value || price.value;
|
|
55
|
+
unitPrice = {
|
|
56
|
+
value: discountedPrice.centAmount / 100,
|
|
57
|
+
currency: price.value.currencyCode as Currency,
|
|
58
|
+
} satisfies MonetaryAmount;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const identifier = {
|
|
62
|
+
variant: {
|
|
63
|
+
sku: data.sku || '',
|
|
64
|
+
},
|
|
65
|
+
} satisfies PriceIdentifier;
|
|
66
|
+
|
|
67
|
+
const result = {
|
|
68
|
+
identifier,
|
|
69
|
+
onSale: options.includeDiscounts && !!price.discounted,
|
|
70
|
+
tieredPrices: [],
|
|
71
|
+
unitPrice,
|
|
72
|
+
} satisfies Price;
|
|
73
|
+
|
|
74
|
+
return this.priceSchema.parse(result);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ProductSchema } from "@reactionary/core";
|
|
2
|
+
import type { ProductFactoryOutput, Result } from "@reactionary/core";
|
|
3
|
+
import { CommercetoolsProductFactory } from "./product.factory.js";
|
|
4
|
+
import { CommercetoolsProductCapability } from "../../capabilities/product.capability.js";
|
|
5
|
+
import { withCommercetoolsCapabilities } from "../../core/initialize.js";
|
|
6
|
+
import { assertNotAny, assertType } from "./utils.example.js";
|
|
7
|
+
|
|
8
|
+
const cache = {} as any;
|
|
9
|
+
const context = {} as any;
|
|
10
|
+
const config = {} as any;
|
|
11
|
+
const api = {} as any;
|
|
12
|
+
|
|
13
|
+
class ExtendedCommercetoolsProductCapability extends CommercetoolsProductCapability<CommercetoolsProductFactory> {
|
|
14
|
+
public async getByCustomIdentifier(
|
|
15
|
+
identifier: string
|
|
16
|
+
): Promise<Result<ProductFactoryOutput<CommercetoolsProductFactory>>> {
|
|
17
|
+
return this.getById({
|
|
18
|
+
identifier: { key: identifier },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const withExtendedCapabilityFactory = withCommercetoolsCapabilities(config, {
|
|
24
|
+
product: {
|
|
25
|
+
enabled: true,
|
|
26
|
+
factory: new CommercetoolsProductFactory(ProductSchema),
|
|
27
|
+
capability: ({ cache, context, config, commercetoolsApi }) =>
|
|
28
|
+
new ExtendedCommercetoolsProductCapability(
|
|
29
|
+
cache,
|
|
30
|
+
context,
|
|
31
|
+
config,
|
|
32
|
+
commercetoolsApi,
|
|
33
|
+
new CommercetoolsProductFactory(ProductSchema)
|
|
34
|
+
),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const client = withExtendedCapabilityFactory(cache, context);
|
|
39
|
+
|
|
40
|
+
client.product.getByCustomIdentifier("p-2").then((x) => {
|
|
41
|
+
assertNotAny(x);
|
|
42
|
+
if (x.success) {
|
|
43
|
+
assertNotAny(x.value);
|
|
44
|
+
assertNotAny(x.value.name);
|
|
45
|
+
assertType<string>(x.value.name);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ProductQueryByIdSchema, ProductSchema } from "@reactionary/core";
|
|
2
|
+
import type {
|
|
3
|
+
ProductFactoryOutput,
|
|
4
|
+
ProductQueryById as BaseProductQueryById,
|
|
5
|
+
Result,
|
|
6
|
+
} from "@reactionary/core";
|
|
7
|
+
import { CommercetoolsProductFactory } from "./product.factory.js";
|
|
8
|
+
import { CommercetoolsProductCapability } from "../../capabilities/product.capability.js";
|
|
9
|
+
import * as z from "zod";
|
|
10
|
+
import { assertNotAny, assertType } from "./utils.example.js";
|
|
11
|
+
|
|
12
|
+
const cache = {} as any;
|
|
13
|
+
const context = {} as any;
|
|
14
|
+
const config = {} as any;
|
|
15
|
+
const api = {} as any;
|
|
16
|
+
|
|
17
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
18
|
+
extendedValue: z.string(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
class ExtendedCommercetoolsProductFactory extends CommercetoolsProductFactory<typeof ExtendedProductSchema> {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(ExtendedProductSchema);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ExtendedProductQueryByIdSchema = ProductQueryByIdSchema.extend({
|
|
28
|
+
auditTrail: z.boolean(),
|
|
29
|
+
});
|
|
30
|
+
type ExtendedProductQueryById = z.infer<typeof ExtendedProductQueryByIdSchema>;
|
|
31
|
+
|
|
32
|
+
class ExtendedCommercetoolsProductCapability extends CommercetoolsProductCapability<ExtendedCommercetoolsProductFactory> {
|
|
33
|
+
public override async getById(
|
|
34
|
+
payload: ExtendedProductQueryById
|
|
35
|
+
) {
|
|
36
|
+
const basePayload: BaseProductQueryById = {
|
|
37
|
+
identifier: payload.identifier,
|
|
38
|
+
};
|
|
39
|
+
return super.getById(basePayload);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const extendedCapability = new ExtendedCommercetoolsProductCapability(
|
|
44
|
+
cache,
|
|
45
|
+
context,
|
|
46
|
+
config,
|
|
47
|
+
api,
|
|
48
|
+
new ExtendedCommercetoolsProductFactory()
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
extendedCapability.getById({
|
|
52
|
+
identifier: { key: "p-1" },
|
|
53
|
+
auditTrail: true
|
|
54
|
+
}).then((x) => {
|
|
55
|
+
assertNotAny(x);
|
|
56
|
+
if (x.success) {
|
|
57
|
+
assertNotAny(x.value);
|
|
58
|
+
assertNotAny(x.value.extendedValue);
|
|
59
|
+
assertType<string>(x.value.extendedValue);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ProductSchema } from "@reactionary/core";
|
|
2
|
+
import { CommercetoolsProductFactory } from "./product.factory.js";
|
|
3
|
+
import { assertNotAny, assertType } from "./utils.example.js";
|
|
4
|
+
|
|
5
|
+
const context = {} as any;
|
|
6
|
+
|
|
7
|
+
const baseFactory = new CommercetoolsProductFactory(ProductSchema);
|
|
8
|
+
const baseProduct = baseFactory.parseProduct(context, {} as any);
|
|
9
|
+
|
|
10
|
+
assertNotAny(baseProduct);
|
|
11
|
+
assertNotAny(baseProduct.name);
|
|
12
|
+
assertType<string>(baseProduct.name);
|
|
13
|
+
// @ts-expect-error base schema does not include extendedValue
|
|
14
|
+
assertType<string>(baseProduct.extendedValue);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ProductSchema } from "@reactionary/core";
|
|
2
|
+
import type { RequestContext } from "@reactionary/core";
|
|
3
|
+
import type { ProductProjection } from "@commercetools/platform-sdk";
|
|
4
|
+
import { CommercetoolsProductFactory } from "./product.factory.js";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import { assertNotAny, assertType } from "./utils.example.js";
|
|
7
|
+
|
|
8
|
+
const context = {} as any;
|
|
9
|
+
|
|
10
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
11
|
+
extendedValue: z.string(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
class ExtendedCommercetoolsProductFactory extends CommercetoolsProductFactory<typeof ExtendedProductSchema> {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(ExtendedProductSchema);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public override parseProduct(context: RequestContext, data: ProductProjection) {
|
|
20
|
+
const base = super.parseProduct(context, data);
|
|
21
|
+
|
|
22
|
+
// PAIN: Needing the satisfies here - possibly unavoidable
|
|
23
|
+
return {
|
|
24
|
+
...base,
|
|
25
|
+
extendedValue: "from-parse",
|
|
26
|
+
} satisfies z.output<typeof ExtendedProductSchema>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const extendedFactory = new ExtendedCommercetoolsProductFactory();
|
|
31
|
+
const extendedProduct = extendedFactory.parseProduct(context, {} as any);
|
|
32
|
+
|
|
33
|
+
assertNotAny(extendedProduct);
|
|
34
|
+
assertNotAny(extendedProduct.extendedValue);
|
|
35
|
+
assertType<string>(extendedProduct.extendedValue);
|
package/packages/commercetools/src/factories/product/product-factory-schema-extension.example.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ProductSchema } from "@reactionary/core";
|
|
2
|
+
import { CommercetoolsProductFactory } from "./product.factory.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import { assertNotAny, assertType } from "./utils.example.js";
|
|
5
|
+
|
|
6
|
+
const context = {} as any;
|
|
7
|
+
|
|
8
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
9
|
+
extendedValue: z.string(),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
class ExtendedCommercetoolsProductFactory extends CommercetoolsProductFactory<typeof ExtendedProductSchema> {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(ExtendedProductSchema);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const extendedFactory = new ExtendedCommercetoolsProductFactory();
|
|
19
|
+
const extendedProduct = extendedFactory.parseProduct(context, {} as any);
|
|
20
|
+
|
|
21
|
+
assertNotAny(extendedProduct);
|
|
22
|
+
assertNotAny(extendedProduct.extendedValue);
|
|
23
|
+
assertType<string>(extendedProduct.extendedValue);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ProductSchema } from "@reactionary/core";
|
|
2
|
+
import { CommercetoolsProductFactory } from "./product.factory.js";
|
|
3
|
+
import { withCommercetoolsCapabilities } from "../../core/initialize.js";
|
|
4
|
+
import * as z from "zod";
|
|
5
|
+
import { assertNotAny, assertType } from "./utils.example.js";
|
|
6
|
+
|
|
7
|
+
const cache = {} as any;
|
|
8
|
+
const context = {} as any;
|
|
9
|
+
const config = {} as any;
|
|
10
|
+
|
|
11
|
+
const ExtendedProductSchema = ProductSchema.safeExtend({
|
|
12
|
+
extendedValue: z.string(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
class ExtendedCommercetoolsProductFactory extends CommercetoolsProductFactory<typeof ExtendedProductSchema> {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(ExtendedProductSchema);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const capabilityFactory = withCommercetoolsCapabilities(config, {
|
|
22
|
+
product: {
|
|
23
|
+
enabled: true,
|
|
24
|
+
factory: new ExtendedCommercetoolsProductFactory(),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const client = capabilityFactory(cache, context);
|
|
29
|
+
|
|
30
|
+
client.product
|
|
31
|
+
.getById({
|
|
32
|
+
identifier: { key: "p-1" },
|
|
33
|
+
})
|
|
34
|
+
.then((x) => {
|
|
35
|
+
assertNotAny(x);
|
|
36
|
+
if (x.success) {
|
|
37
|
+
assertNotAny(x.value);
|
|
38
|
+
assertNotAny(x.value.extendedValue);
|
|
39
|
+
assertType<string>(x.value.extendedValue);
|
|
40
|
+
}
|
|
41
|
+
});
|