@reactionary/core 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.
Files changed (92) hide show
  1. package/cache/memory-cache.js +2 -4
  2. package/cache/noop-cache.js +1 -3
  3. package/cache/redis-cache.js +2 -1
  4. package/{providers/analytics.provider.js → capabilities/analytics.capability.js} +11 -10
  5. package/{providers/base.provider.js → capabilities/base.capability.js} +4 -2
  6. package/capabilities/cart.capability.js +9 -0
  7. package/capabilities/category.capability.js +9 -0
  8. package/capabilities/checkout.capability.js +9 -0
  9. package/{providers/identity.provider.js → capabilities/identity.capability.js} +3 -3
  10. package/capabilities/index.js +18 -0
  11. package/{providers/inventory.provider.js → capabilities/inventory.capability.js} +3 -3
  12. package/capabilities/order-search.capability.js +9 -0
  13. package/{providers/order.provider.js → capabilities/order.capability.js} +3 -3
  14. package/{providers/price.provider.js → capabilities/price.capability.js} +3 -3
  15. package/capabilities/product-associations.capability.js +9 -0
  16. package/capabilities/product-list.capability.js +10 -0
  17. package/{providers/product-recommendations.provider.js → capabilities/product-recommendations.capability.js} +23 -22
  18. package/{providers/product-reviews.provider.js → capabilities/product-reviews.capability.js} +3 -3
  19. package/capabilities/product-search.capability.js +15 -0
  20. package/{providers/product.provider.js → capabilities/product.capability.js} +3 -3
  21. package/capabilities/profile.capability.js +9 -0
  22. package/capabilities/store.capability.js +9 -0
  23. package/client/client-builder.js +47 -15
  24. package/decorators/reactionary.decorator.js +30 -32
  25. package/factories/cart.factory.js +0 -0
  26. package/factories/category.factory.js +0 -0
  27. package/factories/checkout.factory.js +0 -0
  28. package/factories/identity.factory.js +0 -0
  29. package/factories/index.js +15 -0
  30. package/factories/inventory.factory.js +0 -0
  31. package/factories/order-search.factory.js +0 -0
  32. package/factories/order.factory.js +0 -0
  33. package/factories/price.factory.js +0 -0
  34. package/factories/product-associations.factory.js +0 -0
  35. package/factories/product-list.factory.js +0 -0
  36. package/factories/product-reviews.factory.js +0 -0
  37. package/factories/product-search.factory.js +0 -0
  38. package/factories/product.factory.js +0 -0
  39. package/factories/profile.factory.js +0 -0
  40. package/factories/store.factory.js +0 -0
  41. package/index.js +2 -1
  42. package/package.json +8 -8
  43. package/src/{providers/analytics.provider.d.ts → capabilities/analytics.capability.d.ts} +5 -5
  44. package/src/{providers/base.provider.d.ts → capabilities/base.capability.d.ts} +2 -2
  45. package/src/{providers/cart.provider.d.ts → capabilities/cart.capability.d.ts} +10 -10
  46. package/src/{providers/category.provider.d.ts → capabilities/category.capability.d.ts} +9 -9
  47. package/src/{providers/checkout.provider.d.ts → capabilities/checkout.capability.d.ts} +11 -11
  48. package/src/{providers/identity.provider.d.ts → capabilities/identity.capability.d.ts} +7 -7
  49. package/src/capabilities/index.d.ts +18 -0
  50. package/src/{providers/inventory.provider.d.ts → capabilities/inventory.capability.d.ts} +4 -4
  51. package/src/{providers/order-search.provider.d.ts → capabilities/order-search.capability.d.ts} +3 -3
  52. package/src/{providers/order.provider.d.ts → capabilities/order.capability.d.ts} +4 -4
  53. package/src/{providers/price.provider.d.ts → capabilities/price.capability.d.ts} +5 -5
  54. package/src/{providers/product-associations.provider.d.ts → capabilities/product-associations.capability.d.ts} +5 -5
  55. package/src/{providers/product-list.provider.d.ts → capabilities/product-list.capability.d.ts} +9 -9
  56. package/src/{providers/product-recommendations.provider.d.ts → capabilities/product-recommendations.capability.d.ts} +6 -6
  57. package/src/{providers/product-reviews.provider.d.ts → capabilities/product-reviews.capability.d.ts} +5 -5
  58. package/src/{providers/product-search.provider.d.ts → capabilities/product-search.capability.d.ts} +5 -28
  59. package/src/{providers/product.provider.d.ts → capabilities/product.capability.d.ts} +6 -6
  60. package/src/{providers/profile.provider.d.ts → capabilities/profile.capability.d.ts} +9 -9
  61. package/src/{providers/store.provider.d.ts → capabilities/store.capability.d.ts} +3 -3
  62. package/src/client/client-builder.d.ts +10 -1
  63. package/src/client/client.d.ts +29 -29
  64. package/src/decorators/reactionary.decorator.d.ts +5 -5
  65. package/src/factories/cart.factory.d.ts +18 -0
  66. package/src/factories/category.factory.d.ts +17 -0
  67. package/src/factories/checkout.factory.d.ts +24 -0
  68. package/src/factories/identity.factory.d.ts +12 -0
  69. package/src/factories/index.d.ts +15 -0
  70. package/src/factories/inventory.factory.d.ts +12 -0
  71. package/src/factories/order-search.factory.d.ts +13 -0
  72. package/src/factories/order.factory.d.ts +12 -0
  73. package/src/factories/price.factory.d.ts +16 -0
  74. package/src/factories/product-associations.factory.d.ts +12 -0
  75. package/src/factories/product-list.factory.d.ts +27 -0
  76. package/src/factories/product-reviews.factory.d.ts +22 -0
  77. package/src/factories/product-search.factory.d.ts +13 -0
  78. package/src/factories/product.factory.d.ts +12 -0
  79. package/src/factories/profile.factory.d.ts +12 -0
  80. package/src/factories/store.factory.d.ts +12 -0
  81. package/src/index.d.ts +3 -1
  82. package/providers/cart.provider.js +0 -9
  83. package/providers/category.provider.js +0 -9
  84. package/providers/checkout.provider.js +0 -9
  85. package/providers/index.js +0 -18
  86. package/providers/order-search.provider.js +0 -9
  87. package/providers/product-associations.provider.js +0 -9
  88. package/providers/product-list.provider.js +0 -10
  89. package/providers/product-search.provider.js +0 -9
  90. package/providers/profile.provider.js +0 -9
  91. package/providers/store.provider.js +0 -9
  92. package/src/providers/index.d.ts +0 -18
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.6.1",
4
- "main": "index.js",
5
- "types": "src/index.d.ts",
3
+ "version": "0.6.3",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "types": "./src/index.d.ts",
6
7
  "dependencies": {
7
8
  "zod": "4.1.9",
8
9
  "@upstash/redis": "^1.34.9",
9
- "node-object-hash": "^3.1.1"
10
- },
11
- "peerDependencies": {
12
- "@opentelemetry/api": "^1.0.0"
10
+ "@opentelemetry/api": "^1.9.0",
11
+ "node-object-hash": "^3.1.1",
12
+ "vitest": "^4.0.9",
13
+ "@nx/vite": "22.4.5"
13
14
  },
14
- "type": "module",
15
15
  "sideEffects": false
16
16
  }
@@ -1,8 +1,8 @@
1
1
  import type { RequestContext } from '../schemas/session.schema.js';
2
- import { BaseProvider } from './base.provider.js';
2
+ import { BaseCapability } from './base.capability.js';
3
3
  import type { Cache } from '../cache/cache.interface.js';
4
4
  import { type AnalyticsMutation, type AnalyticsMutationProductAddToCartEvent, type AnalyticsMutationProductDetailsViewEvent, type AnalyticsMutationProductSummaryClickEvent, type AnalyticsMutationProductSummaryViewEvent, type AnalyticsMutationPurchaseEvent } from '../schemas/index.js';
5
- export declare abstract class AnalyticsProvider extends BaseProvider {
5
+ export declare abstract class AnalyticsCapability extends BaseCapability {
6
6
  protected getResourceName(): string;
7
7
  track(event: AnalyticsMutation): Promise<void>;
8
8
  protected processProductSummaryView(event: AnalyticsMutationProductSummaryViewEvent): Promise<void>;
@@ -11,8 +11,8 @@ export declare abstract class AnalyticsProvider extends BaseProvider {
11
11
  protected processProductAddToCart(event: AnalyticsMutationProductAddToCartEvent): Promise<void>;
12
12
  protected processPurchase(event: AnalyticsMutationPurchaseEvent): Promise<void>;
13
13
  }
14
- export declare class MulticastAnalyticsProvider extends AnalyticsProvider {
15
- protected providers: Array<AnalyticsProvider>;
16
- constructor(cache: Cache, requestContext: RequestContext, providers: Array<AnalyticsProvider>);
14
+ export declare class MulticastAnalyticsCapability extends AnalyticsCapability {
15
+ protected capabilities: Array<AnalyticsCapability>;
16
+ constructor(cache: Cache, requestContext: RequestContext, capabilities: Array<AnalyticsCapability>);
17
17
  track(event: AnalyticsMutation): Promise<void>;
18
18
  }
@@ -1,10 +1,10 @@
1
1
  import type { Cache } from '../cache/cache.interface.js';
2
2
  import { type RequestContext } from '../schemas/session.schema.js';
3
3
  /**
4
- * Base capability provider, responsible for mutations (changes) and queries (fetches)
4
+ * Base capability abstraction, responsible for mutations (changes) and queries (fetches)
5
5
  * for a given business object domain.
6
6
  */
7
- export declare abstract class BaseProvider {
7
+ export declare abstract class BaseCapability {
8
8
  protected cache: Cache;
9
9
  protected context: RequestContext;
10
10
  constructor(cache: Cache, context: RequestContext);
@@ -4,11 +4,11 @@ import type { CartIdentifier } from "../schemas/models/identifiers.model.js";
4
4
  import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon } from "../schemas/mutations/cart.mutation.js";
5
5
  import type { CartQueryById } from "../schemas/queries/cart.query.js";
6
6
  import type { Result } from "../schemas/result.js";
7
- import { BaseProvider } from "./base.provider.js";
7
+ import { BaseCapability } from "./base.capability.js";
8
8
  /**
9
9
  * @group Providers
10
10
  */
11
- export declare abstract class CartProvider extends BaseProvider {
11
+ export declare abstract class CartCapability<TCart extends Cart = Cart, TCartIdentifier extends CartIdentifier = CartIdentifier> extends BaseCapability {
12
12
  /**
13
13
  * Get cart by ID.
14
14
  *
@@ -16,14 +16,14 @@ export declare abstract class CartProvider extends BaseProvider {
16
16
  * @param payload
17
17
  * @param session
18
18
  */
19
- abstract getById(payload: CartQueryById): Promise<Result<Cart, NotFoundError>>;
19
+ abstract getById(payload: CartQueryById): Promise<Result<TCart, NotFoundError>>;
20
20
  /**
21
21
  * Get the active cart id for the user.
22
22
  *
23
23
  * 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.
24
24
  * @param session
25
25
  */
26
- abstract getActiveCartId(): Promise<Result<CartIdentifier, NotFoundError>>;
26
+ abstract getActiveCartId(): Promise<Result<TCartIdentifier, NotFoundError>>;
27
27
  /**
28
28
  * Add item to cart. If no cart exists, create a new one. Returns the updated and recalculated cart.
29
29
  * Does not automatically consolidate items, so if you want to have second add of same item to increase quantity,
@@ -33,7 +33,7 @@ export declare abstract class CartProvider extends BaseProvider {
33
33
  * @param payload
34
34
  * @param session
35
35
  */
36
- abstract add(payload: CartMutationItemAdd): Promise<Result<Cart>>;
36
+ abstract add(payload: CartMutationItemAdd): Promise<Result<TCart>>;
37
37
  /**
38
38
  * Remove item from cart. If the cart is empty after removal, delete the cart. Returns the updated and recalculated cart.
39
39
  *
@@ -41,7 +41,7 @@ export declare abstract class CartProvider extends BaseProvider {
41
41
  * @param payload
42
42
  * @param session
43
43
  */
44
- abstract remove(payload: CartMutationItemRemove): Promise<Result<Cart>>;
44
+ abstract remove(payload: CartMutationItemRemove): Promise<Result<TCart>>;
45
45
  /**
46
46
  * Change quantity of item in cart. If the cart is empty after change, delete the cart. Returns the updated and recalculated cart.
47
47
  * Changing quantity to 0 is not allowed. Use the remove call instead. This is done to avoid accidental removal of item.
@@ -51,7 +51,7 @@ export declare abstract class CartProvider extends BaseProvider {
51
51
  * @param payload
52
52
  * @param session
53
53
  */
54
- abstract changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<Cart>>;
54
+ abstract changeQuantity(payload: CartMutationItemQuantityChange): Promise<Result<TCart>>;
55
55
  /**
56
56
  * Deletes the entire cart.
57
57
  *
@@ -67,7 +67,7 @@ export declare abstract class CartProvider extends BaseProvider {
67
67
  * @param payload
68
68
  * @param session
69
69
  */
70
- abstract applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<Cart>>;
70
+ abstract applyCouponCode(payload: CartMutationApplyCoupon): Promise<Result<TCart>>;
71
71
  /**
72
72
  * Removes a coupon code from the cart. Returns the updated and recalculated cart.
73
73
  *
@@ -75,7 +75,7 @@ export declare abstract class CartProvider extends BaseProvider {
75
75
  * @param payload
76
76
  * @param session
77
77
  */
78
- abstract removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<Cart>>;
78
+ abstract removeCouponCode(payload: CartMutationRemoveCoupon): Promise<Result<TCart>>;
79
79
  /**
80
80
  * Changes the currency of the cart.
81
81
  *
@@ -83,6 +83,6 @@ export declare abstract class CartProvider extends BaseProvider {
83
83
  * @param newCurrency
84
84
  * @param session
85
85
  */
86
- abstract changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<Cart>>;
86
+ abstract changeCurrency(payload: CartMutationChangeCurrency): Promise<Result<TCart>>;
87
87
  protected getResourceName(): string;
88
88
  }
@@ -1,16 +1,16 @@
1
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 { BaseProvider } from "./base.provider.js";
3
+ import { BaseCapability } from "./base.capability.js";
4
4
  /**
5
- * CategoryProvider
5
+ * CategoryCapability
6
6
  *
7
- * This provider allows fetching of single or sets of categories.
7
+ * This capability allows fetching of single or sets of categories.
8
8
  *
9
9
  * 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.."
10
10
  *
11
11
  * @group Foo
12
12
  */
13
- export declare abstract class CategoryProvider extends BaseProvider {
13
+ export declare abstract class CategoryCapability<TCategory extends Category = Category, TCategoryPaginatedResult extends CategoryPaginatedResult = CategoryPaginatedResult> extends BaseCapability {
14
14
  /**
15
15
  * Get a single category by its ID. Cannot return null, because HOW did you come across a categories ID that does not exist?
16
16
  *
@@ -26,7 +26,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
26
26
  * @param id
27
27
  * @param session
28
28
  */
29
- abstract getById(payload: CategoryQueryById): Promise<Result<Category, NotFoundError>>;
29
+ abstract getById(payload: CategoryQueryById): Promise<Result<TCategory, NotFoundError>>;
30
30
  /**
31
31
  * Gets a single category by its seo slug
32
32
  *
@@ -34,7 +34,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
34
34
  * @param slug the slug
35
35
  * @param session
36
36
  */
37
- abstract getBySlug(payload: CategoryQueryBySlug): Promise<Result<Category, NotFoundError>>;
37
+ abstract getBySlug(payload: CategoryQueryBySlug): Promise<Result<TCategory, NotFoundError>>;
38
38
  /**
39
39
  * Gets the breadcrumb path to the category, i.e. all parents up to the root.
40
40
  * The returned order is from root to leaf.
@@ -43,7 +43,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
43
43
  * @param id
44
44
  * @param session
45
45
  */
46
- abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<Category[]>>;
46
+ abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb): Promise<Result<TCategory[]>>;
47
47
  /**
48
48
  * Finds all child categories of a given category.
49
49
  *
@@ -54,7 +54,7 @@ export declare abstract class CategoryProvider extends BaseProvider {
54
54
  * @param id The ID of the parent category.
55
55
  * @param session The session information.
56
56
  */
57
- abstract findChildCategories(payload: CategoryQueryForChildCategories): Promise<Result<CategoryPaginatedResult>>;
57
+ abstract findChildCategories(payload: CategoryQueryForChildCategories): Promise<Result<TCategoryPaginatedResult>>;
58
58
  /**
59
59
  * Returns all top categories, i.e. categories without a parent.
60
60
  *
@@ -62,6 +62,6 @@ export declare abstract class CategoryProvider extends BaseProvider {
62
62
  * @param paginationOptions
63
63
  * @param session
64
64
  */
65
- abstract findTopCategories(payload: CategoryQueryForTopCategories): Promise<Result<CategoryPaginatedResult>>;
65
+ abstract findTopCategories(payload: CategoryQueryForTopCategories): Promise<Result<TCategoryPaginatedResult>>;
66
66
  protected getResourceName(): string;
67
67
  }
@@ -1,10 +1,10 @@
1
1
  import type { Checkout, PaymentMethod, ShippingMethod } from "../schemas/models/index.js";
2
- import { BaseProvider } from "./base.provider.js";
2
+ import { BaseCapability } from "./base.capability.js";
3
3
  import type { CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationSetShippingAddress, CheckoutMutationAddPaymentInstruction, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingInstruction } from "../schemas/mutations/checkout.mutation.js";
4
4
  import type { CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods } from "../schemas/queries/index.js";
5
5
  import type { Result } from "../schemas/result.js";
6
6
  import type { NotFoundError } from "../schemas/index.js";
7
- export declare abstract class CheckoutProvider extends BaseProvider {
7
+ export declare abstract class CheckoutCapability<TCheckout extends Checkout = Checkout, TShippingMethod extends ShippingMethod = ShippingMethod, TPaymentMethod extends PaymentMethod = PaymentMethod> extends BaseCapability {
8
8
  /**
9
9
  * 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,
10
10
  * is not reflected in the checkout, and vice versa. The checkout is a snapshot of the cart at the time of initiation.
@@ -15,7 +15,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
15
15
  * @param billingAddress the billing/shipping address to start with. This affects available shipping methods, and may be required by some payment providers.
16
16
  * @param reqCtx
17
17
  */
18
- abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Result<Checkout>>;
18
+ abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout): Promise<Result<TCheckout>>;
19
19
  /**
20
20
  * Fetches an existing checkout by its identifier.
21
21
  *
@@ -23,7 +23,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
23
23
  * @param payload
24
24
  * @param reqCtx
25
25
  */
26
- abstract getById(payload: CheckoutQueryById): Promise<Result<Checkout, NotFoundError>>;
26
+ abstract getById(payload: CheckoutQueryById): Promise<Result<TCheckout, NotFoundError>>;
27
27
  /**
28
28
  * Updates the shipping address for the checkout and recalculates the shipping methods and totals.
29
29
  *
@@ -32,7 +32,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
32
32
  * NOTE: Unsure this is really needed.
33
33
  * @param shippingAddress The updated shipping address. Note: This may also be the billing address, if your store does not differentiate.
34
34
  */
35
- abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Result<Checkout>>;
35
+ abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress): Promise<Result<TCheckout>>;
36
36
  /**
37
37
  * 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.
38
38
  *
@@ -41,7 +41,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
41
41
  * @param checkoutId The checkout you want to get shipping methods for.
42
42
  * @param reqCtx
43
43
  */
44
- abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<Result<ShippingMethod[]>>;
44
+ abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods): Promise<Result<TShippingMethod[]>>;
45
45
  /**
46
46
  * Returns all available payment methods for the given checkout. This will typically depend mostly on the billing address and jurisdiction.
47
47
  *
@@ -50,20 +50,20 @@ export declare abstract class CheckoutProvider extends BaseProvider {
50
50
  * @param checkoutId The checkout you want to get payment methods for.
51
51
  * @param reqCtx
52
52
  */
53
- abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<Result<PaymentMethod[]>>;
53
+ abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods): Promise<Result<TPaymentMethod[]>>;
54
54
  /**
55
55
  * Adds a payment instruction to the checkout. This will typically create a payment intent in the payment provider, and return whatever is needed to continue the payment process, e.g. a client secret for Stripe, or a redirect URL for PayPal.
56
56
  *
57
57
  * Usecase: User has chosen a payment method, and you need to start the payment process.
58
58
  */
59
- abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Result<Checkout>>;
59
+ abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction): Promise<Result<TCheckout>>;
60
60
  /**
61
61
  * 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.
62
62
  *
63
63
  * Usecase: User has decided to change payment method, or has cancelled the payment process.
64
64
  * @param paymentInstructionId
65
65
  */
66
- abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Result<Checkout>>;
66
+ abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction): Promise<Result<TCheckout>>;
67
67
  /**
68
68
  * Sets the shipping method and optional pickup point for the checkout. The pickup point can be a physical store, a locker, or similar.
69
69
  * If it is unset, it means home delivery to the shipping address.
@@ -74,7 +74,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
74
74
  * @param shippingMethodId
75
75
  * @param pickupPoint
76
76
  */
77
- abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Result<Checkout>>;
77
+ abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction): Promise<Result<TCheckout>>;
78
78
  /**
79
79
  * Finalizes the checkout process. This typically involves creating an order from the checkout and processing payment.
80
80
  *
@@ -83,7 +83,7 @@ export declare abstract class CheckoutProvider extends BaseProvider {
83
83
  * @param payload
84
84
  * @param reqCtx
85
85
  */
86
- abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Result<Checkout>>;
86
+ abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout): Promise<Result<TCheckout>>;
87
87
  getResourceName(): string;
88
88
  }
89
89
  /**
@@ -2,12 +2,12 @@ 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
4
  import type { Result } from "../schemas/result.js";
5
- import { BaseProvider } from "./base.provider.js";
6
- export declare abstract class IdentityProvider extends BaseProvider {
7
- abstract getSelf(payload: IdentityQuerySelf): Promise<Result<Identity>>;
8
- abstract login(payload: IdentityMutationLogin): Promise<Result<Identity>>;
9
- abstract logout(payload: IdentityMutationLogout): Promise<Result<Identity>>;
10
- abstract register(payload: IdentityMutationRegister): Promise<Result<Identity>>;
5
+ import { BaseCapability } from "./base.capability.js";
6
+ export declare abstract class IdentityCapability<TIdentity extends Identity = Identity> extends BaseCapability {
7
+ abstract getSelf(payload: IdentityQuerySelf): Promise<Result<TIdentity>>;
8
+ abstract login(payload: IdentityMutationLogin): Promise<Result<TIdentity>>;
9
+ abstract logout(payload: IdentityMutationLogout): Promise<Result<TIdentity>>;
10
+ abstract register(payload: IdentityMutationRegister): Promise<Result<TIdentity>>;
11
11
  protected getResourceName(): string;
12
- protected updateIdentityContext(identity: Identity): void;
12
+ protected updateIdentityContext(identity: TIdentity): void;
13
13
  }
@@ -0,0 +1,18 @@
1
+ export * from './analytics.capability.js';
2
+ export * from './base.capability.js';
3
+ export * from './cart.capability.js';
4
+ export * from './category.capability.js';
5
+ export * from './checkout.capability.js';
6
+ export * from './identity.capability.js';
7
+ export * from './inventory.capability.js';
8
+ export * from './price.capability.js';
9
+ export * from './product.capability.js';
10
+ export * from './profile.capability.js';
11
+ export * from './product-search.capability.js';
12
+ export * from './product-recommendations.capability.js';
13
+ export * from './product-associations.capability.js';
14
+ export * from './product-reviews.capability.js';
15
+ export * from './product-list.capability.js';
16
+ export * from './store.capability.js';
17
+ export * from './order.capability.js';
18
+ export * from './order-search.capability.js';
@@ -3,9 +3,9 @@ import type { InventoryIdentifier } from '../schemas/models/identifiers.model.js
3
3
  import type { Inventory } from '../schemas/models/inventory.model.js';
4
4
  import type { InventoryQueryBySKU } from '../schemas/queries/inventory.query.js';
5
5
  import type { Result } from '../schemas/result.js';
6
- import { BaseProvider } from './base.provider.js';
7
- export declare abstract class InventoryProvider extends BaseProvider {
8
- abstract getBySKU(payload: InventoryQueryBySKU): Promise<Result<Inventory, NotFoundError>>;
6
+ import { BaseCapability } from './base.capability.js';
7
+ export declare abstract class InventoryCapability<TInventory extends Inventory = Inventory> extends BaseCapability {
8
+ abstract getBySKU(payload: InventoryQueryBySKU): Promise<Result<TInventory, NotFoundError>>;
9
9
  protected getResourceName(): string;
10
- protected createEmptyInventory(key: InventoryIdentifier): Inventory;
10
+ protected createEmptyInventory(key: InventoryIdentifier): TInventory;
11
11
  }
@@ -1,14 +1,14 @@
1
1
  import type { OrderSearchResult } from "../schemas/models/order-search.model.js";
2
2
  import type { OrderSearchQueryByTerm } from "../schemas/queries/order-search.query.js";
3
3
  import type { Result } from "../schemas/result.js";
4
- import { BaseProvider } from "./base.provider.js";
4
+ import { BaseCapability } from "./base.capability.js";
5
5
  /**
6
6
  * This provider handles order search operations. In some situations you may have different providers for order history listing and detail retrieval.
7
7
  * The order search is primarily focused on searching and listing orders based on various criteria, and returns only summary information about each order.
8
8
  *
9
9
  * 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.
10
10
  */
11
- export declare abstract class OrderSearchProvider extends BaseProvider {
11
+ export declare abstract class OrderSearchCapability<TOrderSearchResult extends OrderSearchResult = OrderSearchResult> extends BaseCapability {
12
12
  protected getResourceName(): string;
13
13
  /**
14
14
  * Queries orders based on the provided search criteria.
@@ -17,5 +17,5 @@ export declare abstract class OrderSearchProvider extends BaseProvider {
17
17
  * Usecase: A widget on the frontpage after login, shows the last 5 orders placed by the customer.
18
18
  * @param payload The search criteria for querying orders.
19
19
  */
20
- abstract queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<OrderSearchResult>>;
20
+ abstract queryByTerm(payload: OrderSearchQueryByTerm): Promise<Result<TOrderSearchResult>>;
21
21
  }
@@ -1,9 +1,9 @@
1
- import { BaseProvider } from './base.provider.js';
1
+ import { BaseCapability } from './base.capability.js';
2
2
  import type { Order } from '../schemas/models/index.js';
3
3
  import type { OrderQueryById } from '../schemas/queries/index.js';
4
4
  import type { Result } from '../schemas/result.js';
5
5
  import type { NotFoundError } from '../schemas/index.js';
6
- export declare abstract class OrderProvider extends BaseProvider {
6
+ export declare abstract class OrderCapability<TOrder extends Order = Order> extends BaseCapability {
7
7
  /**
8
8
  * Get order by ID.
9
9
  *
@@ -11,7 +11,7 @@ export declare abstract class OrderProvider extends BaseProvider {
11
11
  * @param payload
12
12
  * @param session
13
13
  */
14
- abstract getById(payload: OrderQueryById): Promise<Result<Order, NotFoundError>>;
15
- protected createEmptyOrder(): Order;
14
+ abstract getById(payload: OrderQueryById): Promise<Result<TOrder, NotFoundError>>;
15
+ protected createEmptyOrder(): TOrder;
16
16
  protected getResourceName(): string;
17
17
  }
@@ -1,7 +1,7 @@
1
1
  import type { Price, Result } from '../schemas/index.js';
2
2
  import type { CustomerPriceQuery, ListPriceQuery } from '../schemas/queries/price.query.js';
3
- import { BaseProvider } from './base.provider.js';
4
- export declare abstract class PriceProvider extends BaseProvider {
3
+ import { BaseCapability } from './base.capability.js';
4
+ export declare abstract class PriceCapability<TPrice extends Price = Price> extends BaseCapability {
5
5
  /**
6
6
  * Get a list price price by SKU. This is the most general, undiscounted price and is typically
7
7
  * used as the "before" price in most ecommerce setups.
@@ -10,7 +10,7 @@ export declare abstract class PriceProvider extends BaseProvider {
10
10
  * @param payload The SKU to query
11
11
  * @param session The session information
12
12
  */
13
- abstract getListPrice(payload: ListPriceQuery): Promise<Result<Price>>;
13
+ abstract getListPrice(payload: ListPriceQuery): Promise<Result<TPrice>>;
14
14
  /**
15
15
  * Get a customer-specific price by SKU.
16
16
  *
@@ -20,7 +20,7 @@ export declare abstract class PriceProvider extends BaseProvider {
20
20
  * @param payload The SKU to query
21
21
  * @param session The session information
22
22
  */
23
- abstract getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<Price>>;
23
+ abstract getCustomerPrice(payload: CustomerPriceQuery): Promise<Result<TPrice>>;
24
24
  /**
25
25
  * Utility function to create an empty price result, with a value of -1.
26
26
  * This is used when no price is found for a given SKU + currency combination.
@@ -29,6 +29,6 @@ export declare abstract class PriceProvider extends BaseProvider {
29
29
  * @param currency
30
30
  * @returns
31
31
  */
32
- protected createEmptyPriceResult(sku: string): Price;
32
+ protected createEmptyPriceResult(sku: string): TPrice;
33
33
  protected getResourceName(): string;
34
34
  }
@@ -1,5 +1,5 @@
1
1
  import type { ProductAssociationsGetAccessoriesQuery, ProductAssociationsGetSparepartsQuery, ProductAssociationsGetReplacementsQuery } from "../schemas/queries/product-associations.query.js";
2
- import { BaseProvider } from "./base.provider.js";
2
+ import { BaseCapability } from "./base.capability.js";
3
3
  import type { Result } from '../schemas/result.js';
4
4
  import type { ProductAssociation } from '../schemas/models/product-associations.model.js';
5
5
  /**
@@ -7,7 +7,7 @@ import type { ProductAssociation } from '../schemas/models/product-associations.
7
7
  * accessories, spareparts, and replacements. These associations are typically used to provide recommendations to customers on the product detail page, but can also be used in other contexts such as the cart or post-purchase, but
8
8
  * do not carry any personalization concept to them.
9
9
  */
10
- export declare abstract class ProductAssociationsProvider extends BaseProvider {
10
+ export declare abstract class ProductAssociationsCapability<TProductAssociation extends ProductAssociation = ProductAssociation> extends BaseCapability {
11
11
  /**
12
12
  * Returns a list of product identifiers which are accessories to the given product.
13
13
  * Accessories in are products in their own right, but are commonly purchased alongside or recommended as complementary to the main product. Examples of accessories include:
@@ -20,7 +20,7 @@ export declare abstract class ProductAssociationsProvider extends BaseProvider {
20
20
  *
21
21
  * TODO: This should be a PaginatedResult
22
22
  */
23
- abstract getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<ProductAssociation[]>>;
23
+ abstract getAccessories(query: ProductAssociationsGetAccessoriesQuery): Promise<Result<TProductAssociation[]>>;
24
24
  /**
25
25
  * Returns a list of product identifiers which are spareparts to the given product.
26
26
  * Spareparts are products which are necessary for the use of the main product, but are not typically purchased alongside it. Examples of spareparts include:
@@ -30,13 +30,13 @@ export declare abstract class ProductAssociationsProvider extends BaseProvider {
30
30
  *
31
31
  * TODO: This should be a PaginatedResult
32
32
  */
33
- abstract getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<ProductAssociation[]>>;
33
+ abstract getSpareparts(query: ProductAssociationsGetSparepartsQuery): Promise<Result<TProductAssociation[]>>;
34
34
  /**
35
35
  * This product is replaced by these equivalent or newer products
36
36
  *
37
37
  * TODO: This should be a PaginatedResult
38
38
  * @param query
39
39
  */
40
- abstract getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<ProductAssociation[]>>;
40
+ abstract getReplacements(query: ProductAssociationsGetReplacementsQuery): Promise<Result<TProductAssociation[]>>;
41
41
  getResourceName(): string;
42
42
  }
@@ -3,7 +3,7 @@ import type { ProductListItemMutationCreate, ProductListItemMutationDelete, Prod
3
3
  import type { ProductListQuery, ProductListQueryById } from "../schemas/queries/product-list.query.js";
4
4
  import { type ProductListItemsQuery } from "../schemas/queries/product-list.query.js";
5
5
  import type { Result } from "../schemas/result.js";
6
- import { BaseProvider } from "./base.provider.js";
6
+ import { BaseCapability } from "./base.capability.js";
7
7
  /**
8
8
  * The product list provider is a general purpose provider for creating various types of product lists, such as favorite lists, projects, wishlists, requisitionlists, etc
9
9
  * It supports having multiples of each list, so that users can have multiple wishlists for example. The lists are identified by a key, which is passed in the query for the various methods.
@@ -12,21 +12,21 @@ import { BaseProvider } from "./base.provider.js";
12
12
  *
13
13
  * Some systems might only support single entries of each type, but the general case is to support multiples.
14
14
  */
15
- export declare abstract class ProductListProvider extends BaseProvider {
15
+ export declare abstract class ProductListCapability<TProductList extends ProductList = ProductList, TProductListItem extends ProductListItem = ProductListItem, TProductListPaginatedResult extends ProductListPaginatedResult = ProductListPaginatedResult, TProductListItemPaginatedResult extends ProductListItemPaginatedResult = ProductListItemPaginatedResult> extends BaseCapability {
16
16
  protected getResourceName(): string;
17
17
  /**
18
18
  * Usecase: in the frontend you want to fetch a specific list, for example a specific wishlist, to show the details of the list, such as the name, description, image, etc.
19
19
  * you might have stored the identifier from an earlier session or looked it up previously.
20
20
  * @param payload
21
21
  */
22
- abstract getById(payload: ProductListQueryById): Promise<Result<ProductList>>;
22
+ abstract getById(payload: ProductListQueryById): Promise<Result<TProductList>>;
23
23
  /**
24
24
  * Usecase: in the frontend you want to see if the customer already has a favorite list or wishlist, to which the product can be added.
25
25
  * In complex scenarios you might want to fetch a list of wishlists, and allow customer to pick which one to add the product-variant to.
26
26
  *
27
27
  * @param query
28
28
  */
29
- abstract queryLists(query: ProductListQuery): Promise<Result<ProductListPaginatedResult>>;
29
+ abstract queryLists(query: ProductListQuery): Promise<Result<TProductListPaginatedResult>>;
30
30
  /**
31
31
  * Usecase: in the frontend, if customer has clicked the "add to favorites list", and you have used the queryLists to find out there is no
32
32
  * preexistiing list, you can use this method to create a new favorite list.
@@ -35,13 +35,13 @@ export declare abstract class ProductListProvider extends BaseProvider {
35
35
  * which the customer can then add the product to.
36
36
  * @param mutation
37
37
  */
38
- abstract addList(mutation: ProductListMutationCreate): Promise<Result<ProductList>>;
38
+ abstract addList(mutation: ProductListMutationCreate): Promise<Result<TProductList>>;
39
39
  /**
40
40
  *
41
41
  * Usecase: update name of list, or other metadata related to the list, such as "this is my summer wishlist", or "this is my favorite list for cameras".
42
42
  * @param mutation
43
43
  */
44
- abstract updateList(mutation: ProductListMutationUpdate): Promise<Result<ProductList>>;
44
+ abstract updateList(mutation: ProductListMutationUpdate): Promise<Result<TProductList>>;
45
45
  /**
46
46
  * Usecase: customer wants to delete a list, such as "delete my summer wishlist", including all the product list items
47
47
  * @param mutation
@@ -51,12 +51,12 @@ export declare abstract class ProductListProvider extends BaseProvider {
51
51
  * Usecase: in the frontend you want to show a list of the products in the customers wishlist.
52
52
  * @param query
53
53
  */
54
- abstract queryListItems(query: ProductListItemsQuery): Promise<Result<ProductListItemPaginatedResult>>;
54
+ abstract queryListItems(query: ProductListItemsQuery): Promise<Result<TProductListItemPaginatedResult>>;
55
55
  /**
56
56
  * Usecase: Add a new product-variant to a list
57
57
  * @param mutation
58
58
  */
59
- abstract addItem(mutation: ProductListItemMutationCreate): Promise<Result<ProductListItem>>;
59
+ abstract addItem(mutation: ProductListItemMutationCreate): Promise<Result<TProductListItem>>;
60
60
  /**
61
61
  * Usecase: Remove a product-variant from a list.
62
62
  * @param mutation
@@ -66,5 +66,5 @@ export declare abstract class ProductListProvider extends BaseProvider {
66
66
  * Usecase: Update the quantity of a product-variant in a list.
67
67
  * @param mutation
68
68
  */
69
- abstract updateItem(mutation: ProductListItemMutationUpdate): Promise<Result<ProductListItem>>;
69
+ abstract updateItem(mutation: ProductListItemMutationUpdate): Promise<Result<TProductListItem>>;
70
70
  }
@@ -1,10 +1,10 @@
1
1
  import type { Cache } from '../cache/cache.interface.js';
2
2
  import { type ProductRecommendation, type ProductRecommendationsByCollectionQuery, type RequestContext, type Result } from "../schemas/index.js";
3
3
  import { type ProductRecommendationAlgorithmAlsoViewedProductsQuery, type ProductRecommendationAlgorithmFrequentlyBoughtTogetherQuery, type ProductRecommendationAlgorithmPopuplarProductsQuery, type ProductRecommendationAlgorithmRelatedProductsQuery, type ProductRecommendationAlgorithmSimilarProductsQuery, type ProductRecommendationAlgorithmTopPicksProductsQuery, type ProductRecommendationAlgorithmTrendingInCategoryQuery, type ProductRecommendationsQuery } from "../schemas/queries/product-recommendations.query.js";
4
- import { BaseProvider } from "./base.provider.js";
5
- export declare abstract class ProductRecommendationsProvider extends BaseProvider {
4
+ import { BaseCapability } from "./base.capability.js";
5
+ export declare abstract class ProductRecommendationsCapability extends BaseCapability {
6
6
  /**
7
- * returns a list of recommended products, based on the selected algorithm and the provided query parameters. The recommendations should be relevant to the product specified in the query, and can be personalized based on the customer segments or contexts provided. The provider should return a list of product variant identifiers that are recommended for the given product, which can then be used to fetch the full product details from the product provider if needed.
7
+ * returns a list of recommended products, based on the selected algorithm and the provided query parameters. The recommendations should be relevant to the product specified in the query, and can be personalized based on the customer segments or contexts provided. The capability should return a list of product variant identifiers that are recommended for the given product, which can then be used to fetch the full product details from the product capability if needed.
8
8
  * *
9
9
  * Usecase:
10
10
  * - PDP - "Customers who viewed this product also viewed"
@@ -24,9 +24,9 @@ export declare abstract class ProductRecommendationsProvider extends BaseProvide
24
24
  protected getAlsoViewedProductsRecommendations(query: ProductRecommendationAlgorithmAlsoViewedProductsQuery): Promise<ProductRecommendation[]>;
25
25
  protected getResourceName(): string;
26
26
  }
27
- export declare class MulticastProductRecommendationsProvider extends ProductRecommendationsProvider {
28
- protected providers: Array<ProductRecommendationsProvider>;
29
- constructor(cache: Cache, requestContext: RequestContext, providers: Array<ProductRecommendationsProvider>);
27
+ export declare class MulticastProductRecommendationsCapability extends ProductRecommendationsCapability {
28
+ protected capabilities: Array<ProductRecommendationsCapability>;
29
+ constructor(cache: Cache, requestContext: RequestContext, capabilities: Array<ProductRecommendationsCapability>);
30
30
  getRecommendations(query: ProductRecommendationsQuery): Promise<Result<ProductRecommendation[]>>;
31
31
  getCollection(query: ProductRecommendationsByCollectionQuery): Promise<Result<ProductRecommendation[]>>;
32
32
  }
@@ -1,35 +1,35 @@
1
1
  import type { Result, ProductReview, ProductRatingSummary, ProductReviewPaginatedResult } from '../schemas/index.js';
2
2
  import type { ProductReviewsListQuery, ProductReviewsGetRatingSummaryQuery } from '../schemas/queries/product-reviews.query.js';
3
3
  import type { ProductReviewMutationSubmit } from '../schemas/mutations/product-reviews.mutation.js';
4
- import { BaseProvider } from './base.provider.js';
4
+ import { BaseCapability } from './base.capability.js';
5
5
  import { type ProductRatingIdentifier } from '../schemas/models/identifiers.model.js';
6
6
  /**
7
7
  * The product reviews provider is responsible for providing detailed product reviews from customers.
8
8
  * Reviews contain ratings along with textual feedback, author information, and verification status.
9
9
  * This provider also handles aggregated rating summaries for products.
10
10
  */
11
- export declare abstract class ProductReviewsProvider extends BaseProvider {
11
+ export declare abstract class ProductReviewsCapability<TProductRatingSummary extends ProductRatingSummary = ProductRatingSummary, TProductReviewPaginatedResult extends ProductReviewPaginatedResult = ProductReviewPaginatedResult, TProductReview extends ProductReview = ProductReview> extends BaseCapability {
12
12
  /**
13
13
  * Get the rating summary for a product, including average rating and distribution.
14
14
  *
15
15
  * Usecase: Display rating summary on product detail pages or product listing pages.
16
16
  * @param query The product to get ratings for
17
17
  */
18
- abstract getRatingSummary(query: ProductReviewsGetRatingSummaryQuery): Promise<Result<ProductRatingSummary>>;
18
+ abstract getRatingSummary(query: ProductReviewsGetRatingSummaryQuery): Promise<Result<TProductRatingSummary>>;
19
19
  /**
20
20
  * Get a paginated list of reviews for a product.
21
21
  *
22
22
  * Usecase: Display customer reviews on product detail pages with filtering and sorting options.
23
23
  * @param query The query parameters including product, pagination, sorting, and filtering options
24
24
  */
25
- abstract findReviews(query: ProductReviewsListQuery): Promise<Result<ProductReviewPaginatedResult>>;
25
+ abstract findReviews(query: ProductReviewsListQuery): Promise<Result<TProductReviewPaginatedResult>>;
26
26
  /**
27
27
  * Submit a review for a product.
28
28
  *
29
29
  * Usecase: Allow customers to submit detailed reviews with ratings for products they have purchased.
30
30
  * @param mutation The review submission data including rating, title, and content
31
31
  */
32
- abstract submitReview(mutation: ProductReviewMutationSubmit): Promise<Result<ProductReview>>;
32
+ abstract submitReview(mutation: ProductReviewMutationSubmit): Promise<Result<TProductReview>>;
33
33
  protected createEmptyProductRatingSummary(key: ProductRatingIdentifier): ProductRatingSummary;
34
34
  getResourceName(): string;
35
35
  }