@reactionary/source 0.0.52 → 0.2.16
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/.env-template +19 -0
- package/.github/workflows/pull-request.yml +3 -1
- package/.github/workflows/release.yml +9 -0
- package/.vscode/extensions.json +0 -2
- package/LICENSE +21 -0
- package/README.md +175 -23
- package/core/package.json +6 -3
- package/core/src/cache/cache.interface.ts +1 -0
- package/core/src/cache/index.ts +4 -0
- package/core/src/cache/memory-cache.ts +30 -2
- package/core/src/cache/noop-cache.ts +15 -1
- package/core/src/cache/redis-cache.ts +20 -0
- package/core/src/client/client-builder.ts +71 -54
- package/core/src/client/client.ts +9 -47
- package/core/src/client/index.ts +2 -0
- package/core/src/decorators/index.ts +1 -0
- package/core/src/decorators/reactionary.decorator.ts +203 -34
- package/core/src/index.ts +6 -19
- package/core/src/initialization.ts +1 -18
- package/core/src/metrics/metrics.ts +67 -0
- package/core/src/providers/analytics.provider.ts +1 -6
- package/core/src/providers/base.provider.ts +5 -69
- package/core/src/providers/cart.provider.ts +15 -55
- package/core/src/providers/category.provider.ts +7 -11
- package/core/src/providers/checkout.provider.ts +17 -15
- package/core/src/providers/identity.provider.ts +6 -8
- package/core/src/providers/index.ts +2 -1
- package/core/src/providers/inventory.provider.ts +15 -5
- package/core/src/providers/order-search.provider.ts +29 -0
- package/core/src/providers/order.provider.ts +47 -15
- package/core/src/providers/price.provider.ts +30 -36
- package/core/src/providers/product-search.provider.ts +61 -0
- package/core/src/providers/product.provider.ts +71 -12
- package/core/src/providers/profile.provider.ts +74 -14
- package/core/src/providers/store.provider.ts +3 -5
- package/core/src/schemas/capabilities.schema.ts +10 -3
- package/core/src/schemas/errors/generic.error.ts +9 -0
- package/core/src/schemas/errors/index.ts +4 -0
- package/core/src/schemas/errors/invalid-input.error.ts +9 -0
- package/core/src/schemas/errors/invalid-output.error.ts +9 -0
- package/core/src/schemas/errors/not-found.error.ts +9 -0
- package/core/src/schemas/index.ts +7 -0
- package/core/src/schemas/models/analytics.model.ts +2 -1
- package/core/src/schemas/models/base.model.ts +6 -24
- package/core/src/schemas/models/cart.model.ts +5 -8
- package/core/src/schemas/models/category.model.ts +4 -9
- package/core/src/schemas/models/checkout.model.ts +6 -7
- package/core/src/schemas/models/cost.model.ts +4 -3
- package/core/src/schemas/models/currency.model.ts +2 -1
- package/core/src/schemas/models/identifiers.model.ts +106 -62
- package/core/src/schemas/models/identity.model.ts +10 -19
- package/core/src/schemas/models/index.ts +2 -1
- package/core/src/schemas/models/inventory.model.ts +8 -5
- package/core/src/schemas/models/order-search.model.ts +28 -0
- package/core/src/schemas/models/order.model.ts +20 -26
- package/core/src/schemas/models/payment.model.ts +14 -17
- package/core/src/schemas/models/price.model.ts +11 -11
- package/core/src/schemas/models/product-search.model.ts +42 -0
- package/core/src/schemas/models/product.model.ts +64 -22
- package/core/src/schemas/models/profile.model.ts +19 -22
- package/core/src/schemas/models/shipping-method.model.ts +24 -29
- package/core/src/schemas/models/store.model.ts +9 -5
- package/core/src/schemas/mutations/analytics.mutation.ts +8 -7
- package/core/src/schemas/mutations/base.mutation.ts +2 -1
- package/core/src/schemas/mutations/cart.mutation.ts +33 -33
- package/core/src/schemas/mutations/checkout.mutation.ts +23 -30
- package/core/src/schemas/mutations/identity.mutation.ts +4 -3
- package/core/src/schemas/mutations/profile.mutation.ts +38 -3
- package/core/src/schemas/queries/base.query.ts +2 -1
- package/core/src/schemas/queries/cart.query.ts +3 -3
- package/core/src/schemas/queries/category.query.ts +18 -18
- package/core/src/schemas/queries/checkout.query.ts +7 -9
- package/core/src/schemas/queries/identity.query.ts +2 -1
- package/core/src/schemas/queries/index.ts +2 -1
- package/core/src/schemas/queries/inventory.query.ts +5 -5
- package/core/src/schemas/queries/order-search.query.ts +10 -0
- package/core/src/schemas/queries/order.query.ts +3 -2
- package/core/src/schemas/queries/price.query.ts +10 -4
- package/core/src/schemas/queries/product-search.query.ts +16 -0
- package/core/src/schemas/queries/product.query.ts +13 -6
- package/core/src/schemas/queries/profile.query.ts +5 -2
- package/core/src/schemas/queries/store.query.ts +6 -5
- package/core/src/schemas/result.ts +107 -0
- package/core/src/schemas/session.schema.ts +4 -4
- package/core/src/test/reactionary.decorator.spec.ts +249 -0
- package/core/src/zod-utils.ts +19 -0
- package/core/tsconfig.json +1 -1
- package/core/tsconfig.spec.json +2 -26
- package/core/vitest.config.ts +14 -0
- package/documentation/1-purpose.md +114 -0
- package/documentation/2-getting-started.md +229 -0
- package/documentation/3-querying-and-changing-data.md +74 -0
- package/documentation/4-product-data.md +107 -0
- package/documentation/5-cart-and-checkout.md +211 -0
- package/documentation/6-product-search.md +143 -0
- package/documentation/7-marketing.md +3 -0
- package/eslint.config.mjs +1 -0
- package/examples/node/eslint.config.mjs +1 -4
- package/examples/node/package.json +10 -3
- package/examples/node/project.json +4 -1
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +22 -23
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +15 -11
- package/examples/node/src/basic/basic-node-setup.spec.ts +44 -28
- package/examples/node/src/basic/client-creation.spec.ts +53 -0
- package/examples/node/src/capabilities/cart.spec.ts +255 -0
- package/examples/node/src/capabilities/category.spec.ts +193 -0
- package/examples/node/src/capabilities/checkout.spec.ts +341 -0
- package/examples/node/src/capabilities/identity.spec.ts +93 -0
- package/examples/node/src/capabilities/inventory.spec.ts +66 -0
- package/examples/node/src/capabilities/order-search.spec.ts +265 -0
- package/examples/node/src/capabilities/order.spec.ts +91 -0
- package/examples/node/src/capabilities/price.spec.ts +51 -0
- package/examples/node/src/capabilities/product-search.spec.ts +293 -0
- package/examples/node/src/capabilities/product.spec.ts +122 -0
- package/examples/node/src/capabilities/profile.spec.ts +316 -0
- package/examples/node/src/capabilities/store.spec.ts +26 -0
- package/examples/node/src/utils.ts +147 -0
- package/examples/node/tsconfig.json +9 -12
- package/examples/node/tsconfig.lib.json +1 -2
- package/examples/node/tsconfig.spec.json +2 -14
- package/examples/node/vitest.config.ts +14 -0
- package/migrations.json +22 -5
- package/nx.json +8 -47
- package/package.json +24 -96
- package/providers/algolia/README.md +39 -2
- package/providers/algolia/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +7 -14
- package/providers/algolia/src/index.ts +2 -4
- package/providers/algolia/src/providers/index.ts +1 -0
- package/providers/algolia/src/providers/product-search.provider.ts +241 -0
- package/providers/algolia/src/schema/capabilities.schema.ts +2 -3
- package/providers/algolia/src/schema/index.ts +3 -0
- package/providers/algolia/src/schema/search.schema.ts +8 -8
- package/providers/algolia/tsconfig.json +1 -1
- package/providers/algolia/tsconfig.lib.json +1 -1
- package/providers/algolia/tsconfig.spec.json +2 -14
- package/providers/algolia/vitest.config.ts +14 -0
- package/providers/commercetools/README.md +30 -3
- package/providers/commercetools/package.json +2 -1
- package/providers/commercetools/src/core/client.ts +178 -99
- package/providers/commercetools/src/core/initialize.ts +130 -74
- package/providers/commercetools/src/core/token-cache.ts +45 -0
- package/providers/commercetools/src/index.ts +3 -2
- package/providers/commercetools/src/providers/cart.provider.ts +281 -341
- package/providers/commercetools/src/providers/category.provider.ts +223 -138
- package/providers/commercetools/src/providers/checkout.provider.ts +631 -449
- package/providers/commercetools/src/providers/identity.provider.ts +50 -29
- package/providers/commercetools/src/providers/index.ts +2 -2
- package/providers/commercetools/src/providers/inventory.provider.ts +76 -74
- package/providers/commercetools/src/providers/order-search.provider.ts +220 -0
- package/providers/commercetools/src/providers/order.provider.ts +96 -61
- package/providers/commercetools/src/providers/price.provider.ts +147 -117
- package/providers/commercetools/src/providers/product-search.provider.ts +528 -0
- package/providers/commercetools/src/providers/product.provider.ts +249 -74
- package/providers/commercetools/src/providers/profile.provider.ts +445 -28
- package/providers/commercetools/src/providers/store.provider.ts +54 -40
- package/providers/commercetools/src/schema/capabilities.schema.ts +3 -1
- package/providers/commercetools/src/schema/commercetools.schema.ts +17 -3
- package/providers/commercetools/src/schema/configuration.schema.ts +1 -0
- package/providers/commercetools/src/schema/session.schema.ts +7 -0
- package/providers/commercetools/src/test/caching.spec.ts +82 -0
- package/providers/commercetools/src/test/identity.spec.ts +109 -0
- package/providers/commercetools/src/test/test-utils.ts +21 -19
- package/providers/commercetools/tsconfig.json +1 -1
- package/providers/commercetools/tsconfig.lib.json +1 -1
- package/providers/commercetools/tsconfig.spec.json +2 -14
- package/providers/commercetools/vitest.config.ts +15 -0
- package/providers/fake/README.md +20 -4
- package/providers/fake/package.json +2 -1
- package/providers/fake/src/core/initialize.ts +47 -49
- package/providers/fake/src/providers/analytics.provider.ts +5 -7
- package/providers/fake/src/providers/cart.provider.ts +163 -92
- package/providers/fake/src/providers/category.provider.ts +78 -50
- package/providers/fake/src/providers/checkout.provider.ts +254 -0
- package/providers/fake/src/providers/identity.provider.ts +57 -65
- package/providers/fake/src/providers/index.ts +6 -2
- package/providers/fake/src/providers/inventory.provider.ts +40 -36
- package/providers/fake/src/providers/order-search.provider.ts +78 -0
- package/providers/fake/src/providers/order.provider.ts +106 -0
- package/providers/fake/src/providers/price.provider.ts +93 -41
- package/providers/fake/src/providers/product-search.provider.ts +206 -0
- package/providers/fake/src/providers/product.provider.ts +56 -41
- package/providers/fake/src/providers/profile.provider.ts +147 -0
- package/providers/fake/src/providers/store.provider.ts +30 -20
- package/providers/fake/src/schema/capabilities.schema.ts +5 -1
- package/providers/fake/src/test/cart.provider.spec.ts +59 -80
- package/providers/fake/src/test/category.provider.spec.ts +145 -87
- package/providers/fake/src/test/checkout.provider.spec.ts +222 -0
- package/providers/fake/src/test/order-search.provider.spec.ts +50 -0
- package/providers/fake/src/test/order.provider.spec.ts +44 -0
- package/providers/fake/src/test/price.provider.spec.ts +50 -45
- package/providers/fake/src/test/product.provider.spec.ts +15 -7
- package/providers/fake/src/test/profile.provider.spec.ts +167 -0
- package/providers/fake/tsconfig.json +1 -1
- package/providers/fake/tsconfig.lib.json +1 -1
- package/providers/fake/tsconfig.spec.json +2 -12
- package/providers/fake/vitest.config.ts +14 -0
- package/providers/medusa/README.md +30 -0
- package/providers/medusa/TESTING.md +98 -0
- package/providers/medusa/eslint.config.mjs +19 -0
- package/providers/medusa/package.json +22 -0
- package/providers/medusa/project.json +34 -0
- package/providers/medusa/src/core/client.ts +370 -0
- package/providers/medusa/src/core/initialize.ts +78 -0
- package/providers/medusa/src/index.ts +13 -0
- package/providers/medusa/src/providers/cart.provider.ts +575 -0
- package/providers/medusa/src/providers/category.provider.ts +247 -0
- package/providers/medusa/src/providers/checkout.provider.ts +636 -0
- package/providers/medusa/src/providers/identity.provider.ts +137 -0
- package/providers/medusa/src/providers/inventory.provider.ts +173 -0
- package/providers/medusa/src/providers/order-search.provider.ts +202 -0
- package/providers/medusa/src/providers/order.provider.ts +226 -0
- package/providers/medusa/src/providers/price.provider.ts +140 -0
- package/providers/medusa/src/providers/product-search.provider.ts +243 -0
- package/providers/medusa/src/providers/product.provider.ts +261 -0
- package/providers/medusa/src/providers/profile.provider.ts +392 -0
- package/providers/medusa/src/schema/capabilities.schema.ts +18 -0
- package/providers/medusa/src/schema/configuration.schema.ts +11 -0
- package/providers/medusa/src/schema/medusa.schema.ts +31 -0
- package/providers/medusa/src/test/cart.provider.spec.ts +240 -0
- package/providers/medusa/src/test/category.provider.spec.ts +231 -0
- package/providers/medusa/src/test/checkout.spec.ts +349 -0
- package/providers/medusa/src/test/identity.provider.spec.ts +122 -0
- package/providers/medusa/src/test/inventory.provider.spec.ts +88 -0
- package/providers/medusa/src/test/large-cart.provider.spec.ts +103 -0
- package/providers/medusa/src/test/price.provider.spec.ts +104 -0
- package/providers/medusa/src/test/product.provider.spec.ts +146 -0
- package/providers/medusa/src/test/search.provider.spec.ts +203 -0
- package/providers/medusa/src/test/test-utils.ts +13 -0
- package/providers/medusa/src/utils/medusa-helpers.ts +89 -0
- package/providers/medusa/tsconfig.json +21 -0
- package/providers/medusa/tsconfig.lib.json +9 -0
- package/providers/medusa/tsconfig.spec.json +4 -0
- package/providers/medusa/vitest.config.ts +15 -0
- package/providers/meilisearch/README.md +48 -0
- package/providers/meilisearch/eslint.config.mjs +22 -0
- package/providers/meilisearch/package.json +13 -0
- package/providers/meilisearch/project.json +34 -0
- package/providers/meilisearch/src/core/initialize.ts +21 -0
- package/providers/meilisearch/src/index.ts +6 -0
- package/providers/meilisearch/src/providers/index.ts +1 -0
- package/providers/meilisearch/src/providers/order-search.provider.ts +222 -0
- package/providers/meilisearch/src/providers/product-search.provider.ts +251 -0
- package/providers/meilisearch/src/schema/capabilities.schema.ts +10 -0
- package/providers/meilisearch/src/schema/configuration.schema.ts +11 -0
- package/providers/meilisearch/src/schema/index.ts +3 -0
- package/providers/meilisearch/src/schema/search.schema.ts +14 -0
- package/providers/meilisearch/tsconfig.json +24 -0
- package/providers/meilisearch/tsconfig.lib.json +10 -0
- package/providers/meilisearch/tsconfig.spec.json +4 -0
- package/providers/meilisearch/vitest.config.ts +14 -0
- package/providers/posthog/package.json +2 -1
- package/providers/posthog/tsconfig.json +1 -1
- package/tsconfig.base.json +5 -0
- package/vitest.config.ts +10 -0
- package/core/src/providers/search.provider.ts +0 -18
- package/core/src/schemas/models/search.model.ts +0 -36
- package/core/src/schemas/queries/search.query.ts +0 -9
- package/examples/next/.swcrc +0 -30
- package/examples/next/eslint.config.mjs +0 -21
- package/examples/next/index.d.ts +0 -6
- package/examples/next/next-env.d.ts +0 -5
- package/examples/next/next.config.js +0 -31
- package/examples/next/project.json +0 -9
- package/examples/next/public/.gitkeep +0 -0
- package/examples/next/public/favicon.ico +0 -0
- package/examples/next/src/app/global.css +0 -0
- package/examples/next/src/app/layout.tsx +0 -18
- package/examples/next/src/app/page.module.scss +0 -2
- package/examples/next/src/app/page.tsx +0 -47
- package/examples/next/src/instrumentation.ts +0 -9
- package/examples/next/tsconfig.json +0 -44
- package/examples/node/jest.config.ts +0 -10
- package/jest.config.ts +0 -6
- package/jest.preset.js +0 -3
- package/providers/algolia/jest.config.ts +0 -10
- package/providers/algolia/src/providers/product.provider.ts +0 -66
- package/providers/algolia/src/providers/search.provider.ts +0 -106
- package/providers/algolia/src/test/search.provider.spec.ts +0 -91
- package/providers/commercetools/jest.config.cjs +0 -10
- package/providers/commercetools/src/providers/search.provider.ts +0 -96
- package/providers/commercetools/src/test/cart.provider.spec.ts +0 -199
- package/providers/commercetools/src/test/category.provider.spec.ts +0 -168
- package/providers/commercetools/src/test/checkout.provider.spec.ts +0 -312
- package/providers/commercetools/src/test/identity.provider.spec.ts +0 -88
- package/providers/commercetools/src/test/inventory.provider.spec.ts +0 -41
- package/providers/commercetools/src/test/price.provider.spec.ts +0 -81
- package/providers/commercetools/src/test/product.provider.spec.ts +0 -80
- package/providers/commercetools/src/test/profile.provider.spec.ts +0 -49
- package/providers/commercetools/src/test/search.provider.spec.ts +0 -61
- package/providers/commercetools/src/test/store.provider.spec.ts +0 -37
- package/providers/fake/jest.config.cjs +0 -10
- package/providers/fake/src/providers/search.provider.ts +0 -132
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NotFoundError } from "../schemas/index.js";
|
|
2
2
|
import type { Cart } from "../schemas/models/cart.model.js";
|
|
3
|
+
import type { CartIdentifier } from "../schemas/models/identifiers.model.js";
|
|
4
|
+
import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon } from "../schemas/mutations/cart.mutation.js";
|
|
3
5
|
import type { CartQueryById } from "../schemas/queries/cart.query.js";
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
import type { CartIdentifier, OrderIdentifier } from "../schemas/models/identifiers.model.js";
|
|
6
|
+
import type { Result } from "../schemas/result.js";
|
|
7
|
+
import { BaseProvider } from "./base.provider.js";
|
|
7
8
|
|
|
8
|
-
export abstract class CartProvider
|
|
9
|
-
T extends Cart = Cart
|
|
10
|
-
> extends BaseProvider<T> {
|
|
9
|
+
export abstract class CartProvider extends BaseProvider {
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Get cart by ID.
|
|
@@ -16,7 +15,7 @@ export abstract class CartProvider<
|
|
|
16
15
|
* @param payload
|
|
17
16
|
* @param session
|
|
18
17
|
*/
|
|
19
|
-
public abstract getById(payload: CartQueryById
|
|
18
|
+
public abstract getById(payload: CartQueryById): Promise<Result<Cart, NotFoundError>>;
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
/**
|
|
@@ -25,7 +24,7 @@ export abstract class CartProvider<
|
|
|
25
24
|
* Usecase: Most common usecase during site load, or after login. You want to get the active cart for the user, so you can display it in the minicart.
|
|
26
25
|
* @param session
|
|
27
26
|
*/
|
|
28
|
-
public abstract getActiveCartId(
|
|
27
|
+
public abstract getActiveCartId(): Promise<Result<CartIdentifier, NotFoundError>>;
|
|
29
28
|
|
|
30
29
|
|
|
31
30
|
/**
|
|
@@ -37,7 +36,7 @@ export abstract class CartProvider<
|
|
|
37
36
|
* @param payload
|
|
38
37
|
* @param session
|
|
39
38
|
*/
|
|
40
|
-
public abstract add(payload: CartMutationItemAdd
|
|
39
|
+
public abstract add(payload: CartMutationItemAdd): Promise<Result<Cart>>;
|
|
41
40
|
|
|
42
41
|
/**
|
|
43
42
|
* Remove item from cart. If the cart is empty after removal, delete the cart. Returns the updated and recalculated cart.
|
|
@@ -46,7 +45,7 @@ export abstract class CartProvider<
|
|
|
46
45
|
* @param payload
|
|
47
46
|
* @param session
|
|
48
47
|
*/
|
|
49
|
-
public abstract remove(payload: CartMutationItemRemove
|
|
48
|
+
public abstract remove(payload: CartMutationItemRemove): Promise<Result<Cart>>;
|
|
50
49
|
|
|
51
50
|
/**
|
|
52
51
|
* Change quantity of item in cart. If the cart is empty after change, delete the cart. Returns the updated and recalculated cart.
|
|
@@ -57,7 +56,7 @@ export abstract class CartProvider<
|
|
|
57
56
|
* @param payload
|
|
58
57
|
* @param session
|
|
59
58
|
*/
|
|
60
|
-
public abstract changeQuantity(payload: CartMutationItemQuantityChange
|
|
59
|
+
public abstract changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<Cart>>;
|
|
61
60
|
|
|
62
61
|
|
|
63
62
|
/**
|
|
@@ -67,26 +66,7 @@ export abstract class CartProvider<
|
|
|
67
66
|
* @param payload
|
|
68
67
|
* @param session
|
|
69
68
|
*/
|
|
70
|
-
public abstract deleteCart(payload: CartMutationDeleteCart
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Sets shipping method and address on the cart. Returns the updated and recalculated cart.
|
|
74
|
-
*
|
|
75
|
-
* Usecase: User selects shipping method during checkout.
|
|
76
|
-
* @param payload
|
|
77
|
-
* @param session
|
|
78
|
-
*/
|
|
79
|
-
public abstract setShippingInfo(payload: CartMutationSetShippingInfo, reqCtx: RequestContext): Promise<T>;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Sets billing address on the cart. Returns the updated and recalculated cart.
|
|
83
|
-
*
|
|
84
|
-
* Usecase: User enters billing address during checkout.
|
|
85
|
-
*
|
|
86
|
-
* @param payload
|
|
87
|
-
* @param session
|
|
88
|
-
*/
|
|
89
|
-
public abstract setBillingAddress(payload: CartMutationSetBillingAddress, reqCtx: RequestContext): Promise<T>;
|
|
69
|
+
public abstract deleteCart(payload: CartMutationDeleteCart): Promise<Result<void>>;
|
|
90
70
|
|
|
91
71
|
/**
|
|
92
72
|
* Applies a coupon code to the cart. Returns the updated and recalculated cart.
|
|
@@ -95,7 +75,7 @@ export abstract class CartProvider<
|
|
|
95
75
|
* @param payload
|
|
96
76
|
* @param session
|
|
97
77
|
*/
|
|
98
|
-
public abstract applyCouponCode(payload: CartMutationApplyCoupon
|
|
78
|
+
public abstract applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<Cart>>;
|
|
99
79
|
|
|
100
80
|
|
|
101
81
|
/**
|
|
@@ -105,18 +85,7 @@ export abstract class CartProvider<
|
|
|
105
85
|
* @param payload
|
|
106
86
|
* @param session
|
|
107
87
|
*/
|
|
108
|
-
public abstract removeCouponCode(payload: CartMutationRemoveCoupon
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Checks out the cart. Returns the order identifier of the newly created order.
|
|
113
|
-
*
|
|
114
|
-
* Usecase: User proceeds to checkout.
|
|
115
|
-
*
|
|
116
|
-
* @param payload
|
|
117
|
-
* @param session
|
|
118
|
-
*/
|
|
119
|
-
public abstract checkout(payload: CartMutationCheckout, reqCtx: RequestContext): Promise<OrderIdentifier>;
|
|
88
|
+
public abstract removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<Cart>>;
|
|
120
89
|
|
|
121
90
|
/**
|
|
122
91
|
* Changes the currency of the cart.
|
|
@@ -125,16 +94,7 @@ export abstract class CartProvider<
|
|
|
125
94
|
* @param newCurrency
|
|
126
95
|
* @param session
|
|
127
96
|
*/
|
|
128
|
-
public abstract changeCurrency(payload: CartMutationChangeCurrency
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
protected createEmptyCart(): T {
|
|
133
|
-
const cart = this.newModel();
|
|
134
|
-
cart.meta = { placeholder: true, cache: { hit: true, key: 'empty-cart' } };
|
|
135
|
-
cart.identifier = { key: '' };
|
|
136
|
-
return cart;
|
|
137
|
-
}
|
|
97
|
+
public abstract changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<Cart>>;
|
|
138
98
|
|
|
139
99
|
protected override getResourceName(): string {
|
|
140
100
|
return 'cart';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Category } from "../schemas/
|
|
1
|
+
import type { Category, CategoryPaginatedResult, NotFoundError, Result } from "../schemas/index.js";
|
|
2
2
|
import type { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories } from "../schemas/queries/category.query.js";
|
|
3
|
-
import type { RequestContext} from "../schemas/session.schema.js";
|
|
4
3
|
import { BaseProvider } from "./base.provider.js";
|
|
5
4
|
|
|
6
5
|
|
|
@@ -13,9 +12,7 @@ import { BaseProvider } from "./base.provider.js";
|
|
|
13
12
|
* We only allow fetching one hierachy level at a time, for now. This is to avoid development patterns of "fetch 5000 categories in one go.."
|
|
14
13
|
*
|
|
15
14
|
*/
|
|
16
|
-
export abstract class CategoryProvider
|
|
17
|
-
T extends Category = Category
|
|
18
|
-
> extends BaseProvider<T> {
|
|
15
|
+
export abstract class CategoryProvider extends BaseProvider {
|
|
19
16
|
/**
|
|
20
17
|
* Get a single category by its ID. Cannot return null, because HOW did you come across a categories ID that does not exist?
|
|
21
18
|
*
|
|
@@ -31,7 +28,7 @@ export abstract class CategoryProvider<
|
|
|
31
28
|
* @param id
|
|
32
29
|
* @param session
|
|
33
30
|
*/
|
|
34
|
-
public abstract getById(payload: CategoryQueryById
|
|
31
|
+
public abstract getById(payload: CategoryQueryById): Promise<Result<Category, NotFoundError>>;
|
|
35
32
|
|
|
36
33
|
/**
|
|
37
34
|
* Gets a single category by its seo slug
|
|
@@ -40,8 +37,7 @@ export abstract class CategoryProvider<
|
|
|
40
37
|
* @param slug the slug
|
|
41
38
|
* @param session
|
|
42
39
|
*/
|
|
43
|
-
public abstract getBySlug(payload: CategoryQueryBySlug
|
|
44
|
-
|
|
40
|
+
public abstract getBySlug(payload: CategoryQueryBySlug): Promise<Result<Category, NotFoundError>>;
|
|
45
41
|
|
|
46
42
|
/**
|
|
47
43
|
* Gets the breadcrumb path to the category, i.e. all parents up to the root.
|
|
@@ -51,7 +47,7 @@ export abstract class CategoryProvider<
|
|
|
51
47
|
* @param id
|
|
52
48
|
* @param session
|
|
53
49
|
*/
|
|
54
|
-
public abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb
|
|
50
|
+
public abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<Category[]>>;
|
|
55
51
|
|
|
56
52
|
// hmm, this is not really good enough.... We need a type we can pass in that will allow us to specify the precise return type, but otoh we also need
|
|
57
53
|
// to be able to verify and assert the output type. FIXME
|
|
@@ -66,7 +62,7 @@ export abstract class CategoryProvider<
|
|
|
66
62
|
* @param id The ID of the parent category.
|
|
67
63
|
* @param session The session information.
|
|
68
64
|
*/
|
|
69
|
-
public abstract findChildCategories(payload: CategoryQueryForChildCategories
|
|
65
|
+
public abstract findChildCategories(payload: CategoryQueryForChildCategories): Promise<Result<CategoryPaginatedResult>>;
|
|
70
66
|
|
|
71
67
|
/**
|
|
72
68
|
* Returns all top categories, i.e. categories without a parent.
|
|
@@ -75,7 +71,7 @@ export abstract class CategoryProvider<
|
|
|
75
71
|
* @param paginationOptions
|
|
76
72
|
* @param session
|
|
77
73
|
*/
|
|
78
|
-
public abstract findTopCategories( payload: CategoryQueryForTopCategories
|
|
74
|
+
public abstract findTopCategories( payload: CategoryQueryForTopCategories): Promise<Result<CategoryPaginatedResult>>;
|
|
79
75
|
|
|
80
76
|
|
|
81
77
|
protected override getResourceName(): string {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Checkout, PaymentMethod, ShippingMethod } from "../schemas/models/index.js";
|
|
2
|
-
import type { RequestContext } from "../schemas/session.schema.js";
|
|
3
2
|
import { BaseProvider } from "./base.provider.js";
|
|
4
3
|
import type { CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationSetShippingAddress, CheckoutMutationAddPaymentInstruction, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingInstruction } from "../schemas/mutations/checkout.mutation.js";
|
|
5
4
|
import type { CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods } from "../schemas/queries/index.js";
|
|
5
|
+
import type { Result } from "../schemas/result.js";
|
|
6
|
+
import type { NotFoundError } from "../schemas/index.js";
|
|
6
7
|
|
|
7
|
-
export abstract class CheckoutProvider
|
|
8
|
-
T extends Checkout = Checkout
|
|
9
|
-
> extends BaseProvider<T> {
|
|
8
|
+
export abstract class CheckoutProvider extends BaseProvider {
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* This starts a new checkout session for the given cart. The checkout might duplicate the cart, or just reference it, depending on implementation, but changes to the cart,
|
|
@@ -18,7 +17,7 @@ export abstract class CheckoutProvider<
|
|
|
18
17
|
* @param billingAddress the billing/shipping address to start with. This affects available shipping methods, and may be required by some payment providers.
|
|
19
18
|
* @param reqCtx
|
|
20
19
|
*/
|
|
21
|
-
public abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout
|
|
20
|
+
public abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Result<Checkout>>;
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -28,9 +27,7 @@ export abstract class CheckoutProvider<
|
|
|
28
27
|
* @param payload
|
|
29
28
|
* @param reqCtx
|
|
30
29
|
*/
|
|
31
|
-
public abstract getById(payload: CheckoutQueryById
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
public abstract getById(payload: CheckoutQueryById): Promise<Result<Checkout, NotFoundError>>;
|
|
34
31
|
|
|
35
32
|
/**
|
|
36
33
|
* Updates the shipping address for the checkout and recalculates the shipping methods and totals.
|
|
@@ -40,7 +37,7 @@ export abstract class CheckoutProvider<
|
|
|
40
37
|
* NOTE: Unsure this is really needed.
|
|
41
38
|
* @param shippingAddress The updated shipping address. Note: This may also be the billing address, if your store does not differentiate.
|
|
42
39
|
*/
|
|
43
|
-
public abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress
|
|
40
|
+
public abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Result<Checkout>>;
|
|
44
41
|
|
|
45
42
|
/**
|
|
46
43
|
* Returns all available shipping methods for the given checkout. This will typically depend on the shipping address, and possibly also the items in the checkout.
|
|
@@ -50,7 +47,7 @@ export abstract class CheckoutProvider<
|
|
|
50
47
|
* @param checkoutId The checkout you want to get shipping methods for.
|
|
51
48
|
* @param reqCtx
|
|
52
49
|
*/
|
|
53
|
-
public abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods
|
|
50
|
+
public abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<Result<ShippingMethod[]>>;
|
|
54
51
|
|
|
55
52
|
/**
|
|
56
53
|
* Returns all available payment methods for the given checkout. This will typically depend mostly on the billing address and jurisdiction.
|
|
@@ -60,7 +57,7 @@ export abstract class CheckoutProvider<
|
|
|
60
57
|
* @param checkoutId The checkout you want to get payment methods for.
|
|
61
58
|
* @param reqCtx
|
|
62
59
|
*/
|
|
63
|
-
public abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods
|
|
60
|
+
public abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<Result<PaymentMethod[]>>;
|
|
64
61
|
|
|
65
62
|
|
|
66
63
|
/**
|
|
@@ -68,7 +65,7 @@ export abstract class CheckoutProvider<
|
|
|
68
65
|
*
|
|
69
66
|
* Usecase: User has chosen a payment method, and you need to start the payment process.
|
|
70
67
|
*/
|
|
71
|
-
public abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction
|
|
68
|
+
public abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Result<Checkout>>;
|
|
72
69
|
|
|
73
70
|
/**
|
|
74
71
|
* Removes a payment instruction from the checkout. This will typically void the payment intent in the payment provider, and remove the payment instruction from the checkout.
|
|
@@ -76,7 +73,7 @@ export abstract class CheckoutProvider<
|
|
|
76
73
|
* Usecase: User has decided to change payment method, or has cancelled the payment process.
|
|
77
74
|
* @param paymentInstructionId
|
|
78
75
|
*/
|
|
79
|
-
public abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction
|
|
76
|
+
public abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Result<Checkout>>;
|
|
80
77
|
|
|
81
78
|
|
|
82
79
|
|
|
@@ -90,7 +87,7 @@ export abstract class CheckoutProvider<
|
|
|
90
87
|
* @param shippingMethodId
|
|
91
88
|
* @param pickupPoint
|
|
92
89
|
*/
|
|
93
|
-
public abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction
|
|
90
|
+
public abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Result<Checkout>>;
|
|
94
91
|
|
|
95
92
|
/**
|
|
96
93
|
* Finalizes the checkout process. This typically involves creating an order from the checkout and processing payment.
|
|
@@ -100,7 +97,12 @@ export abstract class CheckoutProvider<
|
|
|
100
97
|
* @param payload
|
|
101
98
|
* @param reqCtx
|
|
102
99
|
*/
|
|
103
|
-
public abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout
|
|
100
|
+
public abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Result<Checkout>>;
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
public override getResourceName(): string {
|
|
104
|
+
return 'checkout';
|
|
105
|
+
}
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { Identity } from "../schemas/models/identity.model.js";
|
|
2
2
|
import type { IdentityMutationLogin, IdentityMutationLogout, IdentityMutationRegister } from "../schemas/mutations/identity.mutation.js";
|
|
3
3
|
import type { IdentityQuerySelf } from "../schemas/queries/identity.query.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Result } from "../schemas/result.js";
|
|
5
5
|
import { BaseProvider } from "./base.provider.js";
|
|
6
6
|
|
|
7
|
-
export abstract class IdentityProvider
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
public abstract
|
|
11
|
-
public abstract
|
|
12
|
-
public abstract logout(payload: IdentityMutationLogout, reqCtx: RequestContext): Promise<T>;
|
|
13
|
-
public abstract register(payload: IdentityMutationRegister, reqCtx: RequestContext): Promise<T>;
|
|
7
|
+
export abstract class IdentityProvider extends BaseProvider {
|
|
8
|
+
public abstract getSelf(payload: IdentityQuerySelf): Promise<Result<Identity>>;
|
|
9
|
+
public abstract login(payload: IdentityMutationLogin): Promise<Result<Identity>>;
|
|
10
|
+
public abstract logout(payload: IdentityMutationLogout): Promise<Result<Identity>>;
|
|
11
|
+
public abstract register(payload: IdentityMutationRegister): Promise<Result<Identity>>;
|
|
14
12
|
|
|
15
13
|
protected override getResourceName(): string {
|
|
16
14
|
return 'identity';
|
|
@@ -8,6 +8,7 @@ export * from './inventory.provider.js';
|
|
|
8
8
|
export * from './price.provider.js';
|
|
9
9
|
export * from './product.provider.js';
|
|
10
10
|
export * from './profile.provider.js';
|
|
11
|
-
export * from './search.provider.js';
|
|
11
|
+
export * from './product-search.provider.js';
|
|
12
12
|
export * from './store.provider.js';
|
|
13
13
|
export * from './order.provider.js'
|
|
14
|
+
export * from './order-search.provider.js'
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
import type { NotFoundError } from '../schemas/index.js';
|
|
2
|
+
import type { InventoryIdentifier } from '../schemas/models/identifiers.model.js';
|
|
1
3
|
import type { Inventory } from '../schemas/models/inventory.model.js';
|
|
2
4
|
import type { InventoryQueryBySKU } from '../schemas/queries/inventory.query.js';
|
|
3
|
-
import type {
|
|
5
|
+
import type { Result } from '../schemas/result.js';
|
|
4
6
|
import { BaseProvider } from './base.provider.js';
|
|
5
7
|
|
|
6
|
-
export abstract class InventoryProvider
|
|
7
|
-
|
|
8
|
-
> extends BaseProvider<T> {
|
|
9
|
-
public abstract getBySKU(payload: InventoryQueryBySKU, reqCtx: RequestContext): Promise<T>;
|
|
8
|
+
export abstract class InventoryProvider extends BaseProvider {
|
|
9
|
+
public abstract getBySKU(payload: InventoryQueryBySKU): Promise<Result<Inventory, NotFoundError>>;
|
|
10
10
|
|
|
11
11
|
protected override getResourceName(): string {
|
|
12
12
|
return 'inventory';
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
protected createEmptyInventory(key: InventoryIdentifier): Inventory {
|
|
16
|
+
const inventory = {
|
|
17
|
+
identifier: key,
|
|
18
|
+
quantity: 0,
|
|
19
|
+
status: 'outOfStock'
|
|
20
|
+
} satisfies Inventory;
|
|
21
|
+
|
|
22
|
+
return inventory;
|
|
23
|
+
}
|
|
14
24
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OrderSearchResult } from "../schemas/models/order-search.model.js";
|
|
2
|
+
import type { OrderSearchQueryByTerm } from "../schemas/queries/order-search.query.js";
|
|
3
|
+
import type { Result } from "../schemas/result.js";
|
|
4
|
+
import { BaseProvider } from "./base.provider.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This provider handles order search operations. In some situations you may have different providers for order history listing and detail retrieval.
|
|
8
|
+
* The order search is primarily focused on searching and listing orders based on various criteria, and returns only summary information about each order.
|
|
9
|
+
*
|
|
10
|
+
* Usecase: An e-commerce platform wants to provide customers with a way to search through their past orders using filters like date range, order status, or total amount spent.
|
|
11
|
+
*/
|
|
12
|
+
export abstract class OrderSearchProvider extends BaseProvider {
|
|
13
|
+
protected override getResourceName(): string {
|
|
14
|
+
return 'order-search';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Queries orders based on the provided search criteria.
|
|
19
|
+
*
|
|
20
|
+
* Usecase: A customer is in the My Account section, and wants to search for orders placed within the last month that are marked as "shipped".
|
|
21
|
+
* Usecase: A widget on the frontpage after login, shows the last 5 orders placed by the customer.
|
|
22
|
+
* @param payload The search criteria for querying orders.
|
|
23
|
+
*/
|
|
24
|
+
public abstract queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<OrderSearchResult>>;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { BaseProvider } from
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export abstract class OrderProvider<
|
|
7
|
-
T extends Order = Order
|
|
8
|
-
> extends BaseProvider<T> {
|
|
1
|
+
import { BaseProvider } from './base.provider.js';
|
|
2
|
+
import type { Order } from '../schemas/models/index.js';
|
|
3
|
+
import type { OrderQueryById } from '../schemas/queries/index.js';
|
|
4
|
+
import type { Result } from '../schemas/result.js';
|
|
5
|
+
import type { NotFoundError } from '../schemas/index.js';
|
|
9
6
|
|
|
7
|
+
export abstract class OrderProvider extends BaseProvider {
|
|
10
8
|
/**
|
|
11
9
|
* Get order by ID.
|
|
12
10
|
*
|
|
@@ -14,12 +12,48 @@ export abstract class OrderProvider<
|
|
|
14
12
|
* @param payload
|
|
15
13
|
* @param session
|
|
16
14
|
*/
|
|
17
|
-
public abstract getById(payload: OrderQueryById
|
|
15
|
+
public abstract getById(payload: OrderQueryById): Promise<Result<Order, NotFoundError>>;
|
|
16
|
+
|
|
17
|
+
protected createEmptyOrder(): Order {
|
|
18
|
+
const order = {
|
|
19
|
+
identifier: {
|
|
20
|
+
key: '',
|
|
21
|
+
},
|
|
22
|
+
inventoryStatus: 'NotAllocated',
|
|
23
|
+
items: [],
|
|
24
|
+
orderStatus: 'AwaitingPayment',
|
|
25
|
+
paymentInstructions: [],
|
|
26
|
+
price: {
|
|
27
|
+
grandTotal: {
|
|
28
|
+
value: 0,
|
|
29
|
+
currency: 'XXX',
|
|
30
|
+
},
|
|
31
|
+
totalDiscount: {
|
|
32
|
+
value: 0,
|
|
33
|
+
currency: 'XXX',
|
|
34
|
+
},
|
|
35
|
+
totalProductPrice: {
|
|
36
|
+
value: 0,
|
|
37
|
+
currency: 'XXX',
|
|
38
|
+
},
|
|
39
|
+
totalShipping: {
|
|
40
|
+
value: 0,
|
|
41
|
+
currency: 'XXX',
|
|
42
|
+
},
|
|
43
|
+
totalSurcharge: {
|
|
44
|
+
value: 0,
|
|
45
|
+
currency: 'XXX',
|
|
46
|
+
},
|
|
47
|
+
totalTax: {
|
|
48
|
+
value: 0,
|
|
49
|
+
currency: 'XXX',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
userId: {
|
|
53
|
+
userId: '',
|
|
54
|
+
},
|
|
55
|
+
} satisfies Order;
|
|
18
56
|
|
|
19
|
-
protected createEmptyOrder(): T {
|
|
20
|
-
const order = this.newModel();
|
|
21
|
-
order.meta = { placeholder: true, cache: { hit: true, key: 'empty-order' } };
|
|
22
|
-
order.identifier = { key: '' };
|
|
23
57
|
return order;
|
|
24
58
|
}
|
|
25
59
|
|
|
@@ -27,5 +61,3 @@ export abstract class OrderProvider<
|
|
|
27
61
|
return 'order';
|
|
28
62
|
}
|
|
29
63
|
}
|
|
30
|
-
|
|
31
|
-
|
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Price, Result } from '../schemas/index.js';
|
|
2
|
+
import type {
|
|
3
|
+
CustomerPriceQuery,
|
|
4
|
+
ListPriceQuery,
|
|
5
|
+
} from '../schemas/queries/price.query.js';
|
|
5
6
|
import { BaseProvider } from './base.provider.js';
|
|
6
7
|
|
|
7
|
-
export abstract class PriceProvider
|
|
8
|
-
T extends Price = Price
|
|
9
|
-
> extends BaseProvider<T> {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export abstract class PriceProvider extends BaseProvider {
|
|
12
9
|
/**
|
|
13
|
-
* Get a price by SKU.
|
|
14
|
-
*
|
|
15
|
-
* Note: This does not include any discounts or promotions that may apply.
|
|
16
|
-
* For B2B scenarios, this will be the base price, and any customer specific pricing
|
|
10
|
+
* Get a list price price by SKU. This is the most general, undiscounted price and is typically
|
|
11
|
+
* used as the "before" price in most ecommerce setups.
|
|
17
12
|
*
|
|
18
13
|
* Usecase: You are rendering a product page, and you need to show the price for a SKU.
|
|
19
14
|
* @param payload The SKU to query
|
|
20
15
|
* @param session The session information
|
|
21
16
|
*/
|
|
22
|
-
public abstract
|
|
23
|
-
|
|
17
|
+
public abstract getListPrice(payload: ListPriceQuery): Promise<Result<Price>>;
|
|
24
18
|
|
|
25
19
|
/**
|
|
26
|
-
*
|
|
20
|
+
* Get a customer-specific price by SKU.
|
|
21
|
+
*
|
|
22
|
+
* No
|
|
27
23
|
*
|
|
28
|
-
* Usecase: You are rendering a product
|
|
29
|
-
* @param payload The
|
|
24
|
+
* Usecase: You are rendering a product page, and you need to show the price for a SKU.
|
|
25
|
+
* @param payload The SKU to query
|
|
30
26
|
* @param session The session information
|
|
31
27
|
*/
|
|
32
|
-
public abstract
|
|
33
|
-
|
|
28
|
+
public abstract getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<Price>>;
|
|
34
29
|
|
|
35
30
|
/**
|
|
36
31
|
* Utility function to create an empty price result, with a value of -1.
|
|
@@ -40,24 +35,23 @@ export abstract class PriceProvider<
|
|
|
40
35
|
* @param currency
|
|
41
36
|
* @returns
|
|
42
37
|
*/
|
|
43
|
-
protected createEmptyPriceResult(sku: string
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
38
|
+
protected createEmptyPriceResult(sku: string): Price {
|
|
39
|
+
const price = {
|
|
40
|
+
identifier: {
|
|
41
|
+
variant: {
|
|
42
|
+
sku,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
tieredPrices: [],
|
|
46
|
+
unitPrice: {
|
|
47
|
+
value: -1,
|
|
48
|
+
currency: this.context.languageContext.currencyCode,
|
|
49
|
+
}
|
|
50
|
+
} satisfies Price;
|
|
51
|
+
|
|
52
|
+
return price;
|
|
57
53
|
}
|
|
58
54
|
|
|
59
|
-
|
|
60
|
-
|
|
61
55
|
protected override getResourceName(): string {
|
|
62
56
|
return 'price';
|
|
63
57
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Category, FacetIdentifier, FacetValueIdentifier, Result } from '../index.js';
|
|
2
|
+
import type { ProductSearchResult, ProductSearchResultFacet, ProductSearchResultFacetValue, ProductSearchResultItemVariant } from '../schemas/models/product-search.model.js';
|
|
3
|
+
import type { ProductSearchQueryByTerm, ProductSearchQueryCreateNavigationFilter } from '../schemas/queries/product-search.query.js';
|
|
4
|
+
import { BaseProvider } from './base.provider.js';
|
|
5
|
+
|
|
6
|
+
export abstract class ProductSearchProvider extends BaseProvider {
|
|
7
|
+
protected override getResourceName(): string {
|
|
8
|
+
return 'product-search';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public abstract queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<ProductSearchResult>>;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Since each platform has it own way of representing categories and their hierarchy, we leave it to the platform to tell us how to get from a
|
|
16
|
+
* category breadcrumb path to a global category navigation filter that can be applied to product searches.
|
|
17
|
+
*
|
|
18
|
+
* So, the CLP pattern would be
|
|
19
|
+
*
|
|
20
|
+
* const c: Category = await categoryProvider.getBySlug({ slug: 'some-category' });
|
|
21
|
+
* const breadcrumbPath: Category[] = await categoryProvider.getBreadcrumbPathToCategory({ id: c.identifier });
|
|
22
|
+
* const categoryFilter: FacetValueIdentifier = categoryNavigationProvider.createCategoryNavigationFilterBreadcrumbs(breadcrumbPath);
|
|
23
|
+
* const searchResult: ProductSearchResult = await productSearchProvider.queryByTerm({ term: 'some search', facets: [], categoryFilter: [categoryFilter], ... });
|
|
24
|
+
*
|
|
25
|
+
* from here, you would maybe get facets back with subcategories, but those are relative to the current category filter you have applied, so you
|
|
26
|
+
* do not need any special handling for that.
|
|
27
|
+
*
|
|
28
|
+
* Usecase: You are rendering a category page and you want to run a product search to find everything in that category (or below).
|
|
29
|
+
*
|
|
30
|
+
* @param categoryPath
|
|
31
|
+
*/
|
|
32
|
+
public abstract createCategoryNavigationFilter(payload: ProductSearchQueryCreateNavigationFilter): Promise<Result<FacetValueIdentifier>>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Parses a facet value from the search response.
|
|
36
|
+
* @param facetValueIdentifier The identifier for the facet value.
|
|
37
|
+
* @param label The label for the facet value.
|
|
38
|
+
* @param count The count for the facet value.
|
|
39
|
+
*/
|
|
40
|
+
protected abstract parseFacetValue(facetValueIdentifier: FacetValueIdentifier, label: string, count: number) : ProductSearchResultFacetValue;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parses a facet from the search response.
|
|
44
|
+
* @param facetIdentifier The identifier for the facet.
|
|
45
|
+
* @param facetValue The value for the facet.
|
|
46
|
+
*
|
|
47
|
+
* Usecase: Override this to customize the parsing of facets.
|
|
48
|
+
*/
|
|
49
|
+
protected abstract parseFacet(facetIdentifier: FacetIdentifier, facetValue: unknown) : ProductSearchResultFacet;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parses a product variant from the search response.
|
|
53
|
+
* @param variant The variant data from the search response.
|
|
54
|
+
* @param product The product data from the search response.
|
|
55
|
+
*
|
|
56
|
+
* Usecase: Override this to customize the parsing of product variants.
|
|
57
|
+
*/
|
|
58
|
+
protected abstract parseVariant(variant: unknown, product: unknown): ProductSearchResultItemVariant;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|