@reactionary/core 0.0.42 → 0.0.51

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 (101) hide show
  1. package/cache/memory-cache.js +39 -0
  2. package/cache/noop-cache.js +3 -13
  3. package/cache/redis-cache.js +16 -32
  4. package/decorators/reactionary.decorator.js +57 -4
  5. package/index.js +2 -1
  6. package/initialization.js +43 -0
  7. package/package.json +4 -2
  8. package/providers/base.provider.js +29 -12
  9. package/providers/checkout.provider.js +6 -0
  10. package/providers/index.js +4 -1
  11. package/providers/order.provider.js +15 -0
  12. package/providers/profile.provider.js +9 -0
  13. package/providers/store.provider.js +9 -0
  14. package/schemas/capabilities.schema.js +4 -2
  15. package/schemas/models/cart.model.js +3 -24
  16. package/schemas/models/checkout.model.js +44 -0
  17. package/schemas/models/cost.model.js +20 -0
  18. package/schemas/models/identifiers.model.js +24 -6
  19. package/schemas/models/identity.model.js +18 -16
  20. package/schemas/models/index.js +5 -0
  21. package/schemas/models/order.model.js +37 -0
  22. package/schemas/models/payment.model.js +1 -10
  23. package/schemas/models/product.model.js +5 -2
  24. package/schemas/models/profile.model.js +3 -2
  25. package/schemas/models/shipping-method.model.js +26 -4
  26. package/schemas/models/store.model.js +11 -0
  27. package/schemas/mutations/cart.mutation.js +2 -2
  28. package/schemas/mutations/checkout.mutation.js +36 -0
  29. package/schemas/mutations/identity.mutation.js +6 -1
  30. package/schemas/mutations/index.js +2 -1
  31. package/schemas/mutations/profile.mutation.js +9 -0
  32. package/schemas/queries/checkout.query.js +16 -0
  33. package/schemas/queries/index.js +4 -1
  34. package/schemas/queries/inventory.query.js +3 -5
  35. package/schemas/queries/order.query.js +8 -0
  36. package/schemas/queries/product.query.js +5 -0
  37. package/schemas/queries/profile.query.js +5 -0
  38. package/schemas/queries/store.query.js +11 -0
  39. package/schemas/session.schema.js +22 -8
  40. package/src/cache/cache.interface.d.ts +13 -20
  41. package/src/cache/memory-cache.d.ts +18 -0
  42. package/src/cache/noop-cache.d.ts +5 -11
  43. package/src/cache/redis-cache.d.ts +5 -11
  44. package/src/client/client-builder.d.ts +2 -2
  45. package/src/client/client.d.ts +11 -11
  46. package/src/decorators/reactionary.decorator.d.ts +34 -1
  47. package/src/index.d.ts +2 -1
  48. package/src/initialization.d.ts +2 -0
  49. package/src/providers/analytics.provider.d.ts +1 -1
  50. package/src/providers/base.provider.d.ts +12 -9
  51. package/src/providers/cart.provider.d.ts +17 -17
  52. package/src/providers/category.provider.d.ts +9 -9
  53. package/src/providers/checkout.provider.d.ts +135 -0
  54. package/src/providers/identity.provider.d.ts +8 -7
  55. package/src/providers/index.d.ts +4 -1
  56. package/src/providers/inventory.provider.d.ts +4 -4
  57. package/src/providers/order.provider.d.ts +16 -0
  58. package/src/providers/price.provider.d.ts +6 -6
  59. package/src/providers/product.provider.d.ts +6 -5
  60. package/src/providers/profile.provider.d.ts +10 -0
  61. package/src/providers/search.provider.d.ts +4 -4
  62. package/src/providers/store.provider.d.ts +8 -0
  63. package/src/schemas/capabilities.schema.d.ts +3 -1
  64. package/src/schemas/models/analytics.model.d.ts +1 -1
  65. package/src/schemas/models/cart.model.d.ts +0 -2092
  66. package/src/schemas/models/checkout.model.d.ts +2930 -0
  67. package/src/schemas/models/cost.model.d.ts +1867 -0
  68. package/src/schemas/models/identifiers.model.d.ts +22 -6
  69. package/src/schemas/models/identity.model.d.ts +78 -27
  70. package/src/schemas/models/index.d.ts +5 -0
  71. package/src/schemas/models/inventory.model.d.ts +1 -1
  72. package/src/schemas/models/order.model.d.ts +3144 -0
  73. package/src/schemas/models/payment.model.d.ts +1 -438
  74. package/src/schemas/models/product.model.d.ts +2 -2
  75. package/src/schemas/models/profile.model.d.ts +35 -0
  76. package/src/schemas/models/shipping-method.model.d.ts +50 -0
  77. package/src/schemas/models/store.model.d.ts +18 -0
  78. package/src/schemas/mutations/cart.mutation.d.ts +14 -0
  79. package/src/schemas/mutations/{cart-payment.mutation.d.ts → checkout.mutation.d.ts} +74 -6
  80. package/src/schemas/mutations/identity.mutation.d.ts +5 -0
  81. package/src/schemas/mutations/index.d.ts +2 -1
  82. package/src/schemas/mutations/profile.mutation.d.ts +6 -0
  83. package/src/schemas/queries/cart.query.d.ts +1 -1
  84. package/src/schemas/queries/checkout.query.d.ts +19 -0
  85. package/src/schemas/queries/identity.query.d.ts +1 -1
  86. package/src/schemas/queries/index.d.ts +4 -1
  87. package/src/schemas/queries/inventory.query.d.ts +6 -15
  88. package/src/schemas/queries/order.query.d.ts +7 -0
  89. package/src/schemas/queries/price.query.d.ts +1 -1
  90. package/src/schemas/queries/product.query.d.ts +6 -0
  91. package/src/schemas/queries/profile.query.d.ts +3 -0
  92. package/src/schemas/queries/search.query.d.ts +1 -1
  93. package/src/schemas/queries/store.query.d.ts +8 -0
  94. package/src/schemas/session.schema.d.ts +56 -21
  95. package/cache/cache-evaluation.interface.js +0 -0
  96. package/providers/cart-payment.provider.js +0 -9
  97. package/schemas/mutations/cart-payment.mutation.js +0 -15
  98. package/schemas/queries/cart-payment.query.js +0 -11
  99. package/src/cache/cache-evaluation.interface.d.ts +0 -17
  100. package/src/providers/cart-payment.provider.d.ts +0 -42
  101. package/src/schemas/queries/cart-payment.query.d.ts +0 -16
@@ -1,8 +1,9 @@
1
- import { z } from 'zod';
2
- import { BaseModel, createPaginatedResponseSchema } from '../schemas/models/base.model';
3
- import { Cache } from '../cache/cache.interface';
4
- import { Session } from '../schemas/session.schema';
5
- import { IdentifierType } from '../schemas/models/identifiers.model';
1
+ import type { z } from 'zod';
2
+ import type { BaseModel } from '../schemas/models/base.model';
3
+ import { createPaginatedResponseSchema } from '../schemas/models/base.model';
4
+ import type { Cache } from '../cache/cache.interface';
5
+ import type { RequestContext } from '../schemas/session.schema';
6
+ import type { IdentifierType } from '../schemas/models/identifiers.model';
6
7
  /**
7
8
  * Base capability provider, responsible for mutations (changes) and queries (fetches)
8
9
  * for a given business object domain.
@@ -24,10 +25,12 @@ export declare abstract class BaseProvider<T extends BaseModel = BaseModel> {
24
25
  * Handler for parsing a response from a remote provider and converting it
25
26
  * into the typed domain model.
26
27
  */
27
- protected parseSingle(_body: unknown, session: Session): T;
28
- protected parsePaginatedResult(_body: unknown, session: Session): z.infer<ReturnType<typeof createPaginatedResponseSchema<typeof this.schema>>>;
29
- protected generateCacheKeyPaginatedResult(resultSetName: string, res: ReturnType<typeof this.parsePaginatedResult>, session: Session): string;
30
- protected generateCacheKeySingle(identifier: IdentifierType, session: Session): string;
28
+ protected parseSingle(_body: unknown, reqCtx: RequestContext): T;
29
+ protected parsePaginatedResult(_body: unknown, reqCtx: RequestContext): z.infer<ReturnType<typeof createPaginatedResponseSchema<typeof this.schema>>>;
30
+ generateDependencyIdsForModel(model: unknown): Array<string>;
31
+ protected generateCacheKeyForQuery(scope: string, query: object): string;
32
+ protected generateCacheKeyPaginatedResult(resultSetName: string, res: ReturnType<typeof this.parsePaginatedResult>, reqCtx: RequestContext): string;
33
+ protected generateCacheKeySingle(identifier: IdentifierType, reqCtx: RequestContext): string;
31
34
  /**
32
35
  * Returns the abstract resource name provided by the remote system.
33
36
  */
@@ -1,9 +1,9 @@
1
1
  import { BaseProvider } from "./base.provider";
2
- import { Cart } from "../schemas/models/cart.model";
3
- import { CartQueryById } from "../schemas/queries/cart.query";
4
- import { Session } from "../schemas/session.schema";
5
- import { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationSetBillingAddress, CartMutationSetShippingInfo } from "../schemas/mutations/cart.mutation";
6
- import { CartIdentifier, OrderIdentifier } from "../schemas/models/identifiers.model";
2
+ import type { Cart } from "../schemas/models/cart.model";
3
+ import type { CartQueryById } from "../schemas/queries/cart.query";
4
+ import type { RequestContext } from "../schemas/session.schema";
5
+ import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationSetBillingAddress, CartMutationSetShippingInfo } from "../schemas/mutations/cart.mutation";
6
+ import type { CartIdentifier, OrderIdentifier } from "../schemas/models/identifiers.model";
7
7
  export declare abstract class CartProvider<T extends Cart = Cart> extends BaseProvider<T> {
8
8
  /**
9
9
  * Get cart by ID.
@@ -12,14 +12,14 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
12
12
  * @param payload
13
13
  * @param session
14
14
  */
15
- abstract getById(payload: CartQueryById, session: Session): Promise<T>;
15
+ abstract getById(payload: CartQueryById, reqCtx: RequestContext): Promise<T>;
16
16
  /**
17
17
  * Get the active cart id for the user.
18
18
  *
19
19
  * 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.
20
20
  * @param session
21
21
  */
22
- abstract getActiveCartId(session: Session): Promise<CartIdentifier>;
22
+ abstract getActiveCartId(reqCtx: RequestContext): Promise<CartIdentifier>;
23
23
  /**
24
24
  * Add item to cart. If no cart exists, create a new one. Returns the updated and recalculated cart.
25
25
  * Does not automatically consolidate items, so if you want to have second add of same item to increase quantity,
@@ -29,7 +29,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
29
29
  * @param payload
30
30
  * @param session
31
31
  */
32
- abstract add(payload: CartMutationItemAdd, session: Session): Promise<T>;
32
+ abstract add(payload: CartMutationItemAdd, reqCtx: RequestContext): Promise<T>;
33
33
  /**
34
34
  * Remove item from cart. If the cart is empty after removal, delete the cart. Returns the updated and recalculated cart.
35
35
  *
@@ -37,7 +37,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
37
37
  * @param payload
38
38
  * @param session
39
39
  */
40
- abstract remove(payload: CartMutationItemRemove, session: Session): Promise<T>;
40
+ abstract remove(payload: CartMutationItemRemove, reqCtx: RequestContext): Promise<T>;
41
41
  /**
42
42
  * Change quantity of item in cart. If the cart is empty after change, delete the cart. Returns the updated and recalculated cart.
43
43
  * Changing quantity to 0 is not allowed. Use the remove call instead. This is done to avoid accidental removal of item.
@@ -47,7 +47,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
47
47
  * @param payload
48
48
  * @param session
49
49
  */
50
- abstract changeQuantity(payload: CartMutationItemQuantityChange, session: Session): Promise<T>;
50
+ abstract changeQuantity(payload: CartMutationItemQuantityChange, reqCtx: RequestContext): Promise<T>;
51
51
  /**
52
52
  * Deletes the entire cart.
53
53
  *
@@ -55,7 +55,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
55
55
  * @param payload
56
56
  * @param session
57
57
  */
58
- abstract deleteCart(payload: CartMutationDeleteCart, session: Session): Promise<T>;
58
+ abstract deleteCart(payload: CartMutationDeleteCart, reqCtx: RequestContext): Promise<T>;
59
59
  /**
60
60
  * Sets shipping method and address on the cart. Returns the updated and recalculated cart.
61
61
  *
@@ -63,7 +63,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
63
63
  * @param payload
64
64
  * @param session
65
65
  */
66
- abstract setShippingInfo(payload: CartMutationSetShippingInfo, session: Session): Promise<T>;
66
+ abstract setShippingInfo(payload: CartMutationSetShippingInfo, reqCtx: RequestContext): Promise<T>;
67
67
  /**
68
68
  * Sets billing address on the cart. Returns the updated and recalculated cart.
69
69
  *
@@ -72,7 +72,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
72
72
  * @param payload
73
73
  * @param session
74
74
  */
75
- abstract setBillingAddress(payload: CartMutationSetBillingAddress, session: Session): Promise<T>;
75
+ abstract setBillingAddress(payload: CartMutationSetBillingAddress, reqCtx: RequestContext): Promise<T>;
76
76
  /**
77
77
  * Applies a coupon code to the cart. Returns the updated and recalculated cart.
78
78
  *
@@ -80,7 +80,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
80
80
  * @param payload
81
81
  * @param session
82
82
  */
83
- abstract applyCouponCode(payload: CartMutationApplyCoupon, session: Session): Promise<T>;
83
+ abstract applyCouponCode(payload: CartMutationApplyCoupon, reqCtx: RequestContext): Promise<T>;
84
84
  /**
85
85
  * Removes a coupon code from the cart. Returns the updated and recalculated cart.
86
86
  *
@@ -88,7 +88,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
88
88
  * @param payload
89
89
  * @param session
90
90
  */
91
- abstract removeCouponCode(payload: CartMutationRemoveCoupon, session: Session): Promise<T>;
91
+ abstract removeCouponCode(payload: CartMutationRemoveCoupon, reqCtx: RequestContext): Promise<T>;
92
92
  /**
93
93
  * Checks out the cart. Returns the order identifier of the newly created order.
94
94
  *
@@ -97,7 +97,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
97
97
  * @param payload
98
98
  * @param session
99
99
  */
100
- abstract checkout(payload: CartMutationCheckout, session: Session): Promise<OrderIdentifier>;
100
+ abstract checkout(payload: CartMutationCheckout, reqCtx: RequestContext): Promise<OrderIdentifier>;
101
101
  /**
102
102
  * Changes the currency of the cart.
103
103
  *
@@ -105,7 +105,7 @@ export declare abstract class CartProvider<T extends Cart = Cart> extends BasePr
105
105
  * @param newCurrency
106
106
  * @param session
107
107
  */
108
- abstract changeCurrency(payload: CartMutationChangeCurrency, session: Session): Promise<T>;
108
+ abstract changeCurrency(payload: CartMutationChangeCurrency, reqCtx: RequestContext): Promise<T>;
109
109
  protected createEmptyCart(): T;
110
110
  protected getResourceName(): string;
111
111
  }
@@ -1,6 +1,6 @@
1
- import { Category } from "../schemas/models/category.model";
2
- import { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories } from "../schemas/queries/category.query";
3
- import { Session } from "../schemas/session.schema";
1
+ import type { Category } from "../schemas/models/category.model";
2
+ import type { CategoryQueryById, CategoryQueryBySlug, CategoryQueryForBreadcrumb, CategoryQueryForChildCategories, CategoryQueryForTopCategories } from "../schemas/queries/category.query";
3
+ import type { RequestContext } from "../schemas/session.schema";
4
4
  import { BaseProvider } from "./base.provider";
5
5
  /**
6
6
  * CategoryProvider
@@ -22,11 +22,11 @@ export declare abstract class CategoryProvider<T extends Category = Category> ex
22
22
  * For now, the result will be en empty category, but we should probably throw an error instead.
23
23
  *
24
24
  * Use case: You have received a list of category ids from a recommendation engine, and you need to show a tile of this.
25
- * Future optimization: getByIds(ids: CategoryIdentifier[], session: Session): Promise<T[]>
25
+ * Future optimization: getByIds(ids: CategoryIdentifier[], reqCtx: RequestContext): Promise<T[]>
26
26
  * @param id
27
27
  * @param session
28
28
  */
29
- abstract getById(payload: CategoryQueryById, session: Session): Promise<T>;
29
+ abstract getById(payload: CategoryQueryById, reqCtx: RequestContext): Promise<T>;
30
30
  /**
31
31
  * Gets a single category by its seo slug
32
32
  *
@@ -34,7 +34,7 @@ export declare abstract class CategoryProvider<T extends Category = Category> ex
34
34
  * @param slug the slug
35
35
  * @param session
36
36
  */
37
- abstract getBySlug(payload: CategoryQueryBySlug, session: Session): Promise<T | null>;
37
+ abstract getBySlug(payload: CategoryQueryBySlug, reqCtx: RequestContext): Promise<T | null>;
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<T extends Category = Category> ex
43
43
  * @param id
44
44
  * @param session
45
45
  */
46
- abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, session: Session): Promise<T[]>;
46
+ abstract getBreadcrumbPathToCategory(payload: CategoryQueryForBreadcrumb, reqCtx: RequestContext): Promise<T[]>;
47
47
  /**
48
48
  * Finds all child categories of a given category.
49
49
  *
@@ -54,7 +54,7 @@ export declare abstract class CategoryProvider<T extends Category = Category> ex
54
54
  * @param id The ID of the parent category.
55
55
  * @param session The session information.
56
56
  */
57
- abstract findChildCategories(payload: CategoryQueryForChildCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>>;
57
+ abstract findChildCategories(payload: CategoryQueryForChildCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>>;
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<T extends Category = Category> ex
62
62
  * @param paginationOptions
63
63
  * @param session
64
64
  */
65
- abstract findTopCategories(payload: CategoryQueryForTopCategories, session: Session): Promise<ReturnType<typeof this.parsePaginatedResult>>;
65
+ abstract findTopCategories(payload: CategoryQueryForTopCategories, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>>;
66
66
  protected getResourceName(): string;
67
67
  }
@@ -0,0 +1,135 @@
1
+ import type { Checkout, PaymentMethod, ShippingMethod } from "../schemas/models";
2
+ import type { RequestContext } from "../schemas/session.schema";
3
+ import { BaseProvider } from "./base.provider";
4
+ import type { CheckoutMutationFinalizeCheckout, CheckoutMutationInitiateCheckout, CheckoutMutationSetShippingAddress, CheckoutMutationAddPaymentInstruction, CheckoutMutationRemovePaymentInstruction, CheckoutMutationSetShippingInstruction } from "../schemas/mutations/checkout.mutation";
5
+ import type { CheckoutQueryById, CheckoutQueryForAvailablePaymentMethods, CheckoutQueryForAvailableShippingMethods } from "../schemas/queries";
6
+ export declare abstract class CheckoutProvider<T extends Checkout = Checkout> extends BaseProvider<T> {
7
+ /**
8
+ * 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,
9
+ * is not reflected in the checkout, and vice versa. The checkout is a snapshot of the cart at the time of initiation.
10
+ * The checkout will typically copy over addresses from the user profile, if available, or from the anonymous profile in the session.
11
+ *
12
+ * Usecase: User has filled out cart, and is ready to checkout. You call this to create a checkout object, that you can then use to set shipping method, payment method etc.
13
+ * @param cartId The cart you are trying to checkout
14
+ * @param billingAddress the billing/shipping address to start with. This affects available shipping methods, and may be required by some payment providers.
15
+ * @param reqCtx
16
+ */
17
+ abstract initiateCheckoutForCart(payload: CheckoutMutationInitiateCheckout, reqCtx: RequestContext): Promise<T>;
18
+ /**
19
+ * Fetches an existing checkout by its identifier.
20
+ *
21
+ * Usecase: User has navigated to the checkout page, or reloaded on it , or has been redirected back from the payment provider.
22
+ * @param payload
23
+ * @param reqCtx
24
+ */
25
+ abstract getById(payload: CheckoutQueryById, reqCtx: RequestContext): Promise<T | null>;
26
+ /**
27
+ * Updates the shipping address for the checkout and recalculates the shipping methods and totals.
28
+ *
29
+ * Usecase: User has chosen home delivery and you have allowed them to change the address on the checkout page.
30
+ *
31
+ * NOTE: Unsure this is really needed.
32
+ * @param shippingAddress The updated shipping address. Note: This may also be the billing address, if your store does not differentiate.
33
+ */
34
+ abstract setShippingAddress(payload: CheckoutMutationSetShippingAddress, reqCtx: RequestContext): Promise<T>;
35
+ /**
36
+ * 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.
37
+ *
38
+ * Usecase: User has filled out shipping address, and you need to show available shipping methods.
39
+ *
40
+ * @param checkoutId The checkout you want to get shipping methods for.
41
+ * @param reqCtx
42
+ */
43
+ abstract getAvailableShippingMethods(payload: CheckoutQueryForAvailableShippingMethods, reqCtx: RequestContext): Promise<ShippingMethod[]>;
44
+ /**
45
+ * Returns all available payment methods for the given checkout. This will typically depend mostly on the billing address and jurisdiction.
46
+ *
47
+ * Usecase: User has chosen shipping method, and you need to show available payment methods.
48
+ *
49
+ * @param checkoutId The checkout you want to get payment methods for.
50
+ * @param reqCtx
51
+ */
52
+ abstract getAvailablePaymentMethods(payload: CheckoutQueryForAvailablePaymentMethods, reqCtx: RequestContext): Promise<PaymentMethod[]>;
53
+ /**
54
+ * 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.
55
+ *
56
+ * Usecase: User has chosen a payment method, and you need to start the payment process.
57
+ */
58
+ abstract addPaymentInstruction(payload: CheckoutMutationAddPaymentInstruction, reqCtx: RequestContext): Promise<T>;
59
+ /**
60
+ * 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.
61
+ *
62
+ * Usecase: User has decided to change payment method, or has cancelled the payment process.
63
+ * @param paymentInstructionId
64
+ */
65
+ abstract removePaymentInstruction(payload: CheckoutMutationRemovePaymentInstruction, reqCtx: RequestContext): Promise<T>;
66
+ /**
67
+ * Sets the shipping method and optional pickup point for the checkout. The pickup point can be a physical store, a locker, or similar.
68
+ * If it is unset, it means home delivery to the shipping address.
69
+ *
70
+ *
71
+ * Usecase: record all the users shipping choices, and any special instructions they may have added.
72
+ *
73
+ * @param shippingMethodId
74
+ * @param pickupPoint
75
+ */
76
+ abstract setShippingInstruction(payload: CheckoutMutationSetShippingInstruction, reqCtx: RequestContext): Promise<T>;
77
+ /**
78
+ * Finalizes the checkout process. This typically involves creating an order from the checkout and processing payment.
79
+ *
80
+ * Usecase: User has completed all necessary steps in the checkout process and is ready to place the order.
81
+ *
82
+ * @param payload
83
+ * @param reqCtx
84
+ */
85
+ abstract finalizeCheckout(payload: CheckoutMutationFinalizeCheckout, reqCtx: RequestContext): Promise<T>;
86
+ }
87
+ /**
88
+ *
89
+ *
90
+ * How would this be used?
91
+ * // navigated to /payment
92
+ *
93
+ * const cart = await cartProvider.getById({id: 'cart-123'}, reqCtx);
94
+ *
95
+ * let address = null;
96
+ * if (reqCtx.identity.isAuthenticated) {
97
+ * const profile = await profileProvider.getByUserId({userId: reqCtx.identity.userId}, reqCtx);
98
+ * address = profile?.addresses?.[0];
99
+ * }
100
+ * if (!address) {
101
+ * address = reqCtx.session.anonymousProfile?.addresses?.[0];
102
+ * }
103
+ *
104
+ * // ok we are ready for checkout...
105
+ * const checkout = await checkoutProvider.initiateCheckoutForCart(cart.identifier, address, reqCtx);
106
+ *
107
+ * const paymentMethods = await paymentProvider.getAvailablePaymentMethods(checkout, reqCtx);
108
+ * const shippingMethods = await shippingProvider.getAvailableShippingMethods(checkout, reqCtx);
109
+ *
110
+ *
111
+ * onShippingSelected = async (shippingMethodId, pickupPoint) => {
112
+ * const checkout = await checkoutProvider.setShippingMethod(checkout.identifier, shippingMethodId, pickupPoint);
113
+ * return checkout;
114
+ * }
115
+ *
116
+ * onPaymentSelected = async (paymentMethodId) => {
117
+ * const checkout = await checkoutProvider.addPaymentInstruction(checkout.identifier, paymentMethodId);
118
+ * return checkout;
119
+ * }
120
+ *
121
+ * if (checkout.paymentInstructions.length === 0) {
122
+ * // show payment method selection
123
+ * return <PaymentMethodSelection methods={paymentMethods} onSelect={onPaymentSelected} />
124
+ *
125
+ * } else {
126
+ * if (checkout.paymentInstructions[0].status !== 'Authorized') {
127
+ * const pi = checkout.paymentInstructions[0];
128
+ * if (pi.provider === 'stripe') {
129
+ * return new StripeForm(pi.protocolData.find(x => x.key === 'clientSecret').value, onPaymentAuthorized);
130
+ * } else if (pi.provider === 'adyen') {
131
+ * return new RedirectTo(pi.protocolData.find(x => x.key === 'punchoutUrl').value);
132
+ * }
133
+ * }
134
+ * })
135
+ */
@@ -1,11 +1,12 @@
1
- import { Identity } from "../schemas/models/identity.model";
2
- import { IdentityMutationLogin, IdentityMutationLogout } from "../schemas/mutations/identity.mutation";
3
- import { IdentityQuerySelf } from "../schemas/queries/identity.query";
4
- import { Session } from "../schemas/session.schema";
1
+ import type { Identity } from "../schemas/models/identity.model";
2
+ import type { IdentityMutationLogin, IdentityMutationLogout, IdentityMutationRegister } from "../schemas/mutations/identity.mutation";
3
+ import type { IdentityQuerySelf } from "../schemas/queries/identity.query";
4
+ import type { RequestContext } from "../schemas/session.schema";
5
5
  import { BaseProvider } from "./base.provider";
6
6
  export declare abstract class IdentityProvider<T extends Identity = Identity> extends BaseProvider<T> {
7
- abstract getSelf(payload: IdentityQuerySelf, session: Session): Promise<T>;
8
- abstract login(payload: IdentityMutationLogin, session: Session): Promise<T>;
9
- abstract logout(payload: IdentityMutationLogout, session: Session): Promise<T>;
7
+ abstract getSelf(payload: IdentityQuerySelf, reqCtx: RequestContext): Promise<T>;
8
+ abstract login(payload: IdentityMutationLogin, reqCtx: RequestContext): Promise<T>;
9
+ abstract logout(payload: IdentityMutationLogout, reqCtx: RequestContext): Promise<T>;
10
+ abstract register(payload: IdentityMutationRegister, reqCtx: RequestContext): Promise<T>;
10
11
  protected getResourceName(): string;
11
12
  }
@@ -1,10 +1,13 @@
1
1
  export * from './analytics.provider';
2
2
  export * from './base.provider';
3
- export * from './cart-payment.provider';
4
3
  export * from './cart.provider';
5
4
  export * from './category.provider';
5
+ export * from './checkout.provider';
6
6
  export * from './identity.provider';
7
7
  export * from './inventory.provider';
8
8
  export * from './price.provider';
9
9
  export * from './product.provider';
10
+ export * from './profile.provider';
10
11
  export * from './search.provider';
12
+ export * from './store.provider';
13
+ export * from './order.provider';
@@ -1,8 +1,8 @@
1
- import { Inventory } from '../schemas/models/inventory.model';
2
- import { InventoryQuery } from '../schemas/queries/inventory.query';
3
- import { Session } from '../schemas/session.schema';
1
+ import type { Inventory } from '../schemas/models/inventory.model';
2
+ import type { InventoryQueryBySKU } from '../schemas/queries/inventory.query';
3
+ import type { RequestContext } from '../schemas/session.schema';
4
4
  import { BaseProvider } from './base.provider';
5
5
  export declare abstract class InventoryProvider<T extends Inventory = Inventory> extends BaseProvider<T> {
6
- abstract getBySKU(payload: InventoryQuery, session: Session): Promise<T>;
6
+ abstract getBySKU(payload: InventoryQueryBySKU, reqCtx: RequestContext): Promise<T>;
7
7
  protected getResourceName(): string;
8
8
  }
@@ -0,0 +1,16 @@
1
+ import { BaseProvider } from "./base.provider";
2
+ import type { RequestContext } from "../schemas/session.schema";
3
+ import type { Order } from "../schemas/models";
4
+ import type { OrderQueryById } from "../schemas/queries";
5
+ export declare abstract class OrderProvider<T extends Order = Order> extends BaseProvider<T> {
6
+ /**
7
+ * Get order by ID.
8
+ *
9
+ * Usecase: Fetch order after checkout, to check if we are fully paid and can continue to order confirmation page.
10
+ * @param payload
11
+ * @param session
12
+ */
13
+ abstract getById(payload: OrderQueryById, reqCtx: RequestContext): Promise<T>;
14
+ protected createEmptyOrder(): T;
15
+ protected getResourceName(): string;
16
+ }
@@ -1,7 +1,7 @@
1
- import { Currency } from '../schemas/models/currency.model';
2
- import { Price } from '../schemas/models/price.model';
3
- import { PriceQueryBySku } from '../schemas/queries/price.query';
4
- import { Session } from '../schemas/session.schema';
1
+ import type { Currency } from '../schemas/models/currency.model';
2
+ import type { Price } from '../schemas/models/price.model';
3
+ import type { PriceQueryBySku } from '../schemas/queries/price.query';
4
+ import type { RequestContext } from '../schemas/session.schema';
5
5
  import { BaseProvider } from './base.provider';
6
6
  export declare abstract class PriceProvider<T extends Price = Price> extends BaseProvider<T> {
7
7
  /**
@@ -14,7 +14,7 @@ export declare abstract class PriceProvider<T extends Price = Price> extends Bas
14
14
  * @param payload The SKU to query
15
15
  * @param session The session information
16
16
  */
17
- abstract getBySKU(payload: PriceQueryBySku, session: Session): Promise<T>;
17
+ abstract getBySKU(payload: PriceQueryBySku, reqCtx: RequestContext): Promise<T>;
18
18
  /**
19
19
  * Fetch prices for multiple SKUs in one go.
20
20
  *
@@ -22,7 +22,7 @@ export declare abstract class PriceProvider<T extends Price = Price> extends Bas
22
22
  * @param payload The SKUs to query
23
23
  * @param session The session information
24
24
  */
25
- abstract getBySKUs(payload: PriceQueryBySku[], session: Session): Promise<T[]>;
25
+ abstract getBySKUs(payload: PriceQueryBySku[], reqCtx: RequestContext): Promise<T[]>;
26
26
  /**
27
27
  * Utility function to create an empty price result, with a value of -1.
28
28
  * This is used when no price is found for a given SKU + currency combination.
@@ -1,10 +1,11 @@
1
- import { Product } from '../schemas/models/product.model';
1
+ import type { Product } from '../schemas/models/product.model';
2
2
  import { BaseProvider } from './base.provider';
3
- import { Session } from '../schemas/session.schema';
4
- import { ProductQueryById, ProductQueryBySlug } from '../schemas/queries/product.query';
3
+ import type { RequestContext } from '../schemas/session.schema';
4
+ import type { ProductQueryById, ProductQueryBySKU, ProductQueryBySlug } from '../schemas/queries/product.query';
5
5
  export declare abstract class ProductProvider<T extends Product = Product> extends BaseProvider<T> {
6
- abstract getById(payload: ProductQueryById, session: Session): Promise<T>;
7
- abstract getBySlug(payload: ProductQueryBySlug, session: Session): Promise<T | null>;
6
+ abstract getById(payload: ProductQueryById, reqCtx: RequestContext): Promise<T>;
7
+ abstract getBySlug(payload: ProductQueryBySlug, reqCtx: RequestContext): Promise<T | null>;
8
+ abstract getBySKU(payload: ProductQueryBySKU | ProductQueryBySKU[], reqCtx: RequestContext): Promise<T>;
8
9
  protected createEmptyProduct(id: string): T;
9
10
  /**
10
11
  * The resource name, used for caching and logging.
@@ -0,0 +1,10 @@
1
+ import type { Profile } from '../schemas/models';
2
+ import type { ProfileMutationUpdate } from '../schemas/mutations';
3
+ import type { ProfileQuerySelf } from '../schemas/queries';
4
+ import type { RequestContext } from '../schemas/session.schema';
5
+ import { BaseProvider } from './base.provider';
6
+ export declare abstract class ProfileProvider<T extends Profile = Profile> extends BaseProvider<T> {
7
+ abstract getSelf(payload: ProfileQuerySelf, reqCtx: RequestContext): Promise<T>;
8
+ abstract update(payload: ProfileMutationUpdate, reqCtx: RequestContext): Promise<T>;
9
+ protected getResourceName(): string;
10
+ }
@@ -1,8 +1,8 @@
1
- import { SearchResult } from '../schemas/models/search.model';
2
- import { SearchQueryByTerm } from '../schemas/queries/search.query';
3
- import { Session } from '../schemas/session.schema';
1
+ import type { SearchResult } from '../schemas/models/search.model';
2
+ import type { SearchQueryByTerm } from '../schemas/queries/search.query';
3
+ import type { RequestContext } from '../schemas/session.schema';
4
4
  import { BaseProvider } from './base.provider';
5
5
  export declare abstract class SearchProvider<T extends SearchResult = SearchResult> extends BaseProvider<T> {
6
- abstract queryByTerm(payload: SearchQueryByTerm, session: Session): Promise<SearchResult>;
6
+ abstract queryByTerm(payload: SearchQueryByTerm, reqCtx: RequestContext): Promise<SearchResult>;
7
7
  protected getResourceName(): string;
8
8
  }
@@ -0,0 +1,8 @@
1
+ import type { Store } from '../schemas/models/store.model';
2
+ import type { StoreQueryByProximity } from '../schemas/queries';
3
+ import type { RequestContext } from '../schemas/session.schema';
4
+ import { BaseProvider } from './base.provider';
5
+ export declare abstract class StoreProvider<T extends Store = Store> extends BaseProvider<T> {
6
+ abstract queryByProximity(payload: StoreQueryByProximity, reqCtx: RequestContext): Promise<Array<T>>;
7
+ protected getResourceName(): string;
8
+ }
@@ -5,9 +5,11 @@ export declare const CapabilitiesSchema: z.ZodObject<{
5
5
  analytics: z.ZodBoolean;
6
6
  identity: z.ZodBoolean;
7
7
  cart: z.ZodBoolean;
8
- cartPayment: z.ZodBoolean;
8
+ checkout: z.ZodBoolean;
9
+ order: z.ZodBoolean;
9
10
  inventory: z.ZodBoolean;
10
11
  price: z.ZodBoolean;
11
12
  category: z.ZodBoolean;
13
+ store: z.ZodBoolean;
12
14
  }, z.core.$loose>;
13
15
  export type Capabilities = z.infer<typeof CapabilitiesSchema>;
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import type { z } from 'zod';
2
2
  export declare const AnalyticsEventSchema: z.ZodObject<{
3
3
  meta: z.ZodDefault<z.ZodObject<{
4
4
  cache: z.ZodDefault<z.ZodObject<{