@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.
Files changed (293) hide show
  1. package/.env-template +19 -0
  2. package/.github/workflows/pull-request.yml +3 -1
  3. package/.github/workflows/release.yml +9 -0
  4. package/.vscode/extensions.json +0 -2
  5. package/LICENSE +21 -0
  6. package/README.md +175 -23
  7. package/core/package.json +6 -3
  8. package/core/src/cache/cache.interface.ts +1 -0
  9. package/core/src/cache/index.ts +4 -0
  10. package/core/src/cache/memory-cache.ts +30 -2
  11. package/core/src/cache/noop-cache.ts +15 -1
  12. package/core/src/cache/redis-cache.ts +20 -0
  13. package/core/src/client/client-builder.ts +71 -54
  14. package/core/src/client/client.ts +9 -47
  15. package/core/src/client/index.ts +2 -0
  16. package/core/src/decorators/index.ts +1 -0
  17. package/core/src/decorators/reactionary.decorator.ts +203 -34
  18. package/core/src/index.ts +6 -19
  19. package/core/src/initialization.ts +1 -18
  20. package/core/src/metrics/metrics.ts +67 -0
  21. package/core/src/providers/analytics.provider.ts +1 -6
  22. package/core/src/providers/base.provider.ts +5 -69
  23. package/core/src/providers/cart.provider.ts +15 -55
  24. package/core/src/providers/category.provider.ts +7 -11
  25. package/core/src/providers/checkout.provider.ts +17 -15
  26. package/core/src/providers/identity.provider.ts +6 -8
  27. package/core/src/providers/index.ts +2 -1
  28. package/core/src/providers/inventory.provider.ts +15 -5
  29. package/core/src/providers/order-search.provider.ts +29 -0
  30. package/core/src/providers/order.provider.ts +47 -15
  31. package/core/src/providers/price.provider.ts +30 -36
  32. package/core/src/providers/product-search.provider.ts +61 -0
  33. package/core/src/providers/product.provider.ts +71 -12
  34. package/core/src/providers/profile.provider.ts +74 -14
  35. package/core/src/providers/store.provider.ts +3 -5
  36. package/core/src/schemas/capabilities.schema.ts +10 -3
  37. package/core/src/schemas/errors/generic.error.ts +9 -0
  38. package/core/src/schemas/errors/index.ts +4 -0
  39. package/core/src/schemas/errors/invalid-input.error.ts +9 -0
  40. package/core/src/schemas/errors/invalid-output.error.ts +9 -0
  41. package/core/src/schemas/errors/not-found.error.ts +9 -0
  42. package/core/src/schemas/index.ts +7 -0
  43. package/core/src/schemas/models/analytics.model.ts +2 -1
  44. package/core/src/schemas/models/base.model.ts +6 -24
  45. package/core/src/schemas/models/cart.model.ts +5 -8
  46. package/core/src/schemas/models/category.model.ts +4 -9
  47. package/core/src/schemas/models/checkout.model.ts +6 -7
  48. package/core/src/schemas/models/cost.model.ts +4 -3
  49. package/core/src/schemas/models/currency.model.ts +2 -1
  50. package/core/src/schemas/models/identifiers.model.ts +106 -62
  51. package/core/src/schemas/models/identity.model.ts +10 -19
  52. package/core/src/schemas/models/index.ts +2 -1
  53. package/core/src/schemas/models/inventory.model.ts +8 -5
  54. package/core/src/schemas/models/order-search.model.ts +28 -0
  55. package/core/src/schemas/models/order.model.ts +20 -26
  56. package/core/src/schemas/models/payment.model.ts +14 -17
  57. package/core/src/schemas/models/price.model.ts +11 -11
  58. package/core/src/schemas/models/product-search.model.ts +42 -0
  59. package/core/src/schemas/models/product.model.ts +64 -22
  60. package/core/src/schemas/models/profile.model.ts +19 -22
  61. package/core/src/schemas/models/shipping-method.model.ts +24 -29
  62. package/core/src/schemas/models/store.model.ts +9 -5
  63. package/core/src/schemas/mutations/analytics.mutation.ts +8 -7
  64. package/core/src/schemas/mutations/base.mutation.ts +2 -1
  65. package/core/src/schemas/mutations/cart.mutation.ts +33 -33
  66. package/core/src/schemas/mutations/checkout.mutation.ts +23 -30
  67. package/core/src/schemas/mutations/identity.mutation.ts +4 -3
  68. package/core/src/schemas/mutations/profile.mutation.ts +38 -3
  69. package/core/src/schemas/queries/base.query.ts +2 -1
  70. package/core/src/schemas/queries/cart.query.ts +3 -3
  71. package/core/src/schemas/queries/category.query.ts +18 -18
  72. package/core/src/schemas/queries/checkout.query.ts +7 -9
  73. package/core/src/schemas/queries/identity.query.ts +2 -1
  74. package/core/src/schemas/queries/index.ts +2 -1
  75. package/core/src/schemas/queries/inventory.query.ts +5 -5
  76. package/core/src/schemas/queries/order-search.query.ts +10 -0
  77. package/core/src/schemas/queries/order.query.ts +3 -2
  78. package/core/src/schemas/queries/price.query.ts +10 -4
  79. package/core/src/schemas/queries/product-search.query.ts +16 -0
  80. package/core/src/schemas/queries/product.query.ts +13 -6
  81. package/core/src/schemas/queries/profile.query.ts +5 -2
  82. package/core/src/schemas/queries/store.query.ts +6 -5
  83. package/core/src/schemas/result.ts +107 -0
  84. package/core/src/schemas/session.schema.ts +4 -4
  85. package/core/src/test/reactionary.decorator.spec.ts +249 -0
  86. package/core/src/zod-utils.ts +19 -0
  87. package/core/tsconfig.json +1 -1
  88. package/core/tsconfig.spec.json +2 -26
  89. package/core/vitest.config.ts +14 -0
  90. package/documentation/1-purpose.md +114 -0
  91. package/documentation/2-getting-started.md +229 -0
  92. package/documentation/3-querying-and-changing-data.md +74 -0
  93. package/documentation/4-product-data.md +107 -0
  94. package/documentation/5-cart-and-checkout.md +211 -0
  95. package/documentation/6-product-search.md +143 -0
  96. package/documentation/7-marketing.md +3 -0
  97. package/eslint.config.mjs +1 -0
  98. package/examples/node/eslint.config.mjs +1 -4
  99. package/examples/node/package.json +10 -3
  100. package/examples/node/project.json +4 -1
  101. package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +22 -23
  102. package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +15 -11
  103. package/examples/node/src/basic/basic-node-setup.spec.ts +44 -28
  104. package/examples/node/src/basic/client-creation.spec.ts +53 -0
  105. package/examples/node/src/capabilities/cart.spec.ts +255 -0
  106. package/examples/node/src/capabilities/category.spec.ts +193 -0
  107. package/examples/node/src/capabilities/checkout.spec.ts +341 -0
  108. package/examples/node/src/capabilities/identity.spec.ts +93 -0
  109. package/examples/node/src/capabilities/inventory.spec.ts +66 -0
  110. package/examples/node/src/capabilities/order-search.spec.ts +265 -0
  111. package/examples/node/src/capabilities/order.spec.ts +91 -0
  112. package/examples/node/src/capabilities/price.spec.ts +51 -0
  113. package/examples/node/src/capabilities/product-search.spec.ts +293 -0
  114. package/examples/node/src/capabilities/product.spec.ts +122 -0
  115. package/examples/node/src/capabilities/profile.spec.ts +316 -0
  116. package/examples/node/src/capabilities/store.spec.ts +26 -0
  117. package/examples/node/src/utils.ts +147 -0
  118. package/examples/node/tsconfig.json +9 -12
  119. package/examples/node/tsconfig.lib.json +1 -2
  120. package/examples/node/tsconfig.spec.json +2 -14
  121. package/examples/node/vitest.config.ts +14 -0
  122. package/migrations.json +22 -5
  123. package/nx.json +8 -47
  124. package/package.json +24 -96
  125. package/providers/algolia/README.md +39 -2
  126. package/providers/algolia/package.json +2 -1
  127. package/providers/algolia/src/core/initialize.ts +7 -14
  128. package/providers/algolia/src/index.ts +2 -4
  129. package/providers/algolia/src/providers/index.ts +1 -0
  130. package/providers/algolia/src/providers/product-search.provider.ts +241 -0
  131. package/providers/algolia/src/schema/capabilities.schema.ts +2 -3
  132. package/providers/algolia/src/schema/index.ts +3 -0
  133. package/providers/algolia/src/schema/search.schema.ts +8 -8
  134. package/providers/algolia/tsconfig.json +1 -1
  135. package/providers/algolia/tsconfig.lib.json +1 -1
  136. package/providers/algolia/tsconfig.spec.json +2 -14
  137. package/providers/algolia/vitest.config.ts +14 -0
  138. package/providers/commercetools/README.md +30 -3
  139. package/providers/commercetools/package.json +2 -1
  140. package/providers/commercetools/src/core/client.ts +178 -99
  141. package/providers/commercetools/src/core/initialize.ts +130 -74
  142. package/providers/commercetools/src/core/token-cache.ts +45 -0
  143. package/providers/commercetools/src/index.ts +3 -2
  144. package/providers/commercetools/src/providers/cart.provider.ts +281 -341
  145. package/providers/commercetools/src/providers/category.provider.ts +223 -138
  146. package/providers/commercetools/src/providers/checkout.provider.ts +631 -449
  147. package/providers/commercetools/src/providers/identity.provider.ts +50 -29
  148. package/providers/commercetools/src/providers/index.ts +2 -2
  149. package/providers/commercetools/src/providers/inventory.provider.ts +76 -74
  150. package/providers/commercetools/src/providers/order-search.provider.ts +220 -0
  151. package/providers/commercetools/src/providers/order.provider.ts +96 -61
  152. package/providers/commercetools/src/providers/price.provider.ts +147 -117
  153. package/providers/commercetools/src/providers/product-search.provider.ts +528 -0
  154. package/providers/commercetools/src/providers/product.provider.ts +249 -74
  155. package/providers/commercetools/src/providers/profile.provider.ts +445 -28
  156. package/providers/commercetools/src/providers/store.provider.ts +54 -40
  157. package/providers/commercetools/src/schema/capabilities.schema.ts +3 -1
  158. package/providers/commercetools/src/schema/commercetools.schema.ts +17 -3
  159. package/providers/commercetools/src/schema/configuration.schema.ts +1 -0
  160. package/providers/commercetools/src/schema/session.schema.ts +7 -0
  161. package/providers/commercetools/src/test/caching.spec.ts +82 -0
  162. package/providers/commercetools/src/test/identity.spec.ts +109 -0
  163. package/providers/commercetools/src/test/test-utils.ts +21 -19
  164. package/providers/commercetools/tsconfig.json +1 -1
  165. package/providers/commercetools/tsconfig.lib.json +1 -1
  166. package/providers/commercetools/tsconfig.spec.json +2 -14
  167. package/providers/commercetools/vitest.config.ts +15 -0
  168. package/providers/fake/README.md +20 -4
  169. package/providers/fake/package.json +2 -1
  170. package/providers/fake/src/core/initialize.ts +47 -49
  171. package/providers/fake/src/providers/analytics.provider.ts +5 -7
  172. package/providers/fake/src/providers/cart.provider.ts +163 -92
  173. package/providers/fake/src/providers/category.provider.ts +78 -50
  174. package/providers/fake/src/providers/checkout.provider.ts +254 -0
  175. package/providers/fake/src/providers/identity.provider.ts +57 -65
  176. package/providers/fake/src/providers/index.ts +6 -2
  177. package/providers/fake/src/providers/inventory.provider.ts +40 -36
  178. package/providers/fake/src/providers/order-search.provider.ts +78 -0
  179. package/providers/fake/src/providers/order.provider.ts +106 -0
  180. package/providers/fake/src/providers/price.provider.ts +93 -41
  181. package/providers/fake/src/providers/product-search.provider.ts +206 -0
  182. package/providers/fake/src/providers/product.provider.ts +56 -41
  183. package/providers/fake/src/providers/profile.provider.ts +147 -0
  184. package/providers/fake/src/providers/store.provider.ts +30 -20
  185. package/providers/fake/src/schema/capabilities.schema.ts +5 -1
  186. package/providers/fake/src/test/cart.provider.spec.ts +59 -80
  187. package/providers/fake/src/test/category.provider.spec.ts +145 -87
  188. package/providers/fake/src/test/checkout.provider.spec.ts +222 -0
  189. package/providers/fake/src/test/order-search.provider.spec.ts +50 -0
  190. package/providers/fake/src/test/order.provider.spec.ts +44 -0
  191. package/providers/fake/src/test/price.provider.spec.ts +50 -45
  192. package/providers/fake/src/test/product.provider.spec.ts +15 -7
  193. package/providers/fake/src/test/profile.provider.spec.ts +167 -0
  194. package/providers/fake/tsconfig.json +1 -1
  195. package/providers/fake/tsconfig.lib.json +1 -1
  196. package/providers/fake/tsconfig.spec.json +2 -12
  197. package/providers/fake/vitest.config.ts +14 -0
  198. package/providers/medusa/README.md +30 -0
  199. package/providers/medusa/TESTING.md +98 -0
  200. package/providers/medusa/eslint.config.mjs +19 -0
  201. package/providers/medusa/package.json +22 -0
  202. package/providers/medusa/project.json +34 -0
  203. package/providers/medusa/src/core/client.ts +370 -0
  204. package/providers/medusa/src/core/initialize.ts +78 -0
  205. package/providers/medusa/src/index.ts +13 -0
  206. package/providers/medusa/src/providers/cart.provider.ts +575 -0
  207. package/providers/medusa/src/providers/category.provider.ts +247 -0
  208. package/providers/medusa/src/providers/checkout.provider.ts +636 -0
  209. package/providers/medusa/src/providers/identity.provider.ts +137 -0
  210. package/providers/medusa/src/providers/inventory.provider.ts +173 -0
  211. package/providers/medusa/src/providers/order-search.provider.ts +202 -0
  212. package/providers/medusa/src/providers/order.provider.ts +226 -0
  213. package/providers/medusa/src/providers/price.provider.ts +140 -0
  214. package/providers/medusa/src/providers/product-search.provider.ts +243 -0
  215. package/providers/medusa/src/providers/product.provider.ts +261 -0
  216. package/providers/medusa/src/providers/profile.provider.ts +392 -0
  217. package/providers/medusa/src/schema/capabilities.schema.ts +18 -0
  218. package/providers/medusa/src/schema/configuration.schema.ts +11 -0
  219. package/providers/medusa/src/schema/medusa.schema.ts +31 -0
  220. package/providers/medusa/src/test/cart.provider.spec.ts +240 -0
  221. package/providers/medusa/src/test/category.provider.spec.ts +231 -0
  222. package/providers/medusa/src/test/checkout.spec.ts +349 -0
  223. package/providers/medusa/src/test/identity.provider.spec.ts +122 -0
  224. package/providers/medusa/src/test/inventory.provider.spec.ts +88 -0
  225. package/providers/medusa/src/test/large-cart.provider.spec.ts +103 -0
  226. package/providers/medusa/src/test/price.provider.spec.ts +104 -0
  227. package/providers/medusa/src/test/product.provider.spec.ts +146 -0
  228. package/providers/medusa/src/test/search.provider.spec.ts +203 -0
  229. package/providers/medusa/src/test/test-utils.ts +13 -0
  230. package/providers/medusa/src/utils/medusa-helpers.ts +89 -0
  231. package/providers/medusa/tsconfig.json +21 -0
  232. package/providers/medusa/tsconfig.lib.json +9 -0
  233. package/providers/medusa/tsconfig.spec.json +4 -0
  234. package/providers/medusa/vitest.config.ts +15 -0
  235. package/providers/meilisearch/README.md +48 -0
  236. package/providers/meilisearch/eslint.config.mjs +22 -0
  237. package/providers/meilisearch/package.json +13 -0
  238. package/providers/meilisearch/project.json +34 -0
  239. package/providers/meilisearch/src/core/initialize.ts +21 -0
  240. package/providers/meilisearch/src/index.ts +6 -0
  241. package/providers/meilisearch/src/providers/index.ts +1 -0
  242. package/providers/meilisearch/src/providers/order-search.provider.ts +222 -0
  243. package/providers/meilisearch/src/providers/product-search.provider.ts +251 -0
  244. package/providers/meilisearch/src/schema/capabilities.schema.ts +10 -0
  245. package/providers/meilisearch/src/schema/configuration.schema.ts +11 -0
  246. package/providers/meilisearch/src/schema/index.ts +3 -0
  247. package/providers/meilisearch/src/schema/search.schema.ts +14 -0
  248. package/providers/meilisearch/tsconfig.json +24 -0
  249. package/providers/meilisearch/tsconfig.lib.json +10 -0
  250. package/providers/meilisearch/tsconfig.spec.json +4 -0
  251. package/providers/meilisearch/vitest.config.ts +14 -0
  252. package/providers/posthog/package.json +2 -1
  253. package/providers/posthog/tsconfig.json +1 -1
  254. package/tsconfig.base.json +5 -0
  255. package/vitest.config.ts +10 -0
  256. package/core/src/providers/search.provider.ts +0 -18
  257. package/core/src/schemas/models/search.model.ts +0 -36
  258. package/core/src/schemas/queries/search.query.ts +0 -9
  259. package/examples/next/.swcrc +0 -30
  260. package/examples/next/eslint.config.mjs +0 -21
  261. package/examples/next/index.d.ts +0 -6
  262. package/examples/next/next-env.d.ts +0 -5
  263. package/examples/next/next.config.js +0 -31
  264. package/examples/next/project.json +0 -9
  265. package/examples/next/public/.gitkeep +0 -0
  266. package/examples/next/public/favicon.ico +0 -0
  267. package/examples/next/src/app/global.css +0 -0
  268. package/examples/next/src/app/layout.tsx +0 -18
  269. package/examples/next/src/app/page.module.scss +0 -2
  270. package/examples/next/src/app/page.tsx +0 -47
  271. package/examples/next/src/instrumentation.ts +0 -9
  272. package/examples/next/tsconfig.json +0 -44
  273. package/examples/node/jest.config.ts +0 -10
  274. package/jest.config.ts +0 -6
  275. package/jest.preset.js +0 -3
  276. package/providers/algolia/jest.config.ts +0 -10
  277. package/providers/algolia/src/providers/product.provider.ts +0 -66
  278. package/providers/algolia/src/providers/search.provider.ts +0 -106
  279. package/providers/algolia/src/test/search.provider.spec.ts +0 -91
  280. package/providers/commercetools/jest.config.cjs +0 -10
  281. package/providers/commercetools/src/providers/search.provider.ts +0 -96
  282. package/providers/commercetools/src/test/cart.provider.spec.ts +0 -199
  283. package/providers/commercetools/src/test/category.provider.spec.ts +0 -168
  284. package/providers/commercetools/src/test/checkout.provider.spec.ts +0 -312
  285. package/providers/commercetools/src/test/identity.provider.spec.ts +0 -88
  286. package/providers/commercetools/src/test/inventory.provider.spec.ts +0 -41
  287. package/providers/commercetools/src/test/price.provider.spec.ts +0 -81
  288. package/providers/commercetools/src/test/product.provider.spec.ts +0 -80
  289. package/providers/commercetools/src/test/profile.provider.spec.ts +0 -49
  290. package/providers/commercetools/src/test/search.provider.spec.ts +0 -61
  291. package/providers/commercetools/src/test/store.provider.spec.ts +0 -37
  292. package/providers/fake/jest.config.cjs +0 -10
  293. package/providers/fake/src/providers/search.provider.ts +0 -132
@@ -1,13 +1,12 @@
1
- import { BaseProvider } from "./base.provider.js";
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 { RequestContext } from "../schemas/session.schema.js";
5
- import type { CartMutationApplyCoupon, CartMutationChangeCurrency, CartMutationCheckout, CartMutationDeleteCart, CartMutationItemAdd, CartMutationItemQuantityChange, CartMutationItemRemove, CartMutationRemoveCoupon, CartMutationSetBillingAddress, CartMutationSetShippingInfo } from "../schemas/mutations/cart.mutation.js";
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, reqCtx: RequestContext): Promise<T>;
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(reqCtx: RequestContext): Promise<CartIdentifier>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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/models/category.model.js";
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T | null>;
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, reqCtx: RequestContext): Promise<T[]>;
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, reqCtx: RequestContext): Promise< ReturnType<typeof this.parsePaginatedResult>>;
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, reqCtx: RequestContext): Promise<ReturnType<typeof this.parsePaginatedResult>>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T | null>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<ShippingMethod[]>;
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, reqCtx: RequestContext): Promise<PaymentMethod[]>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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, reqCtx: RequestContext): Promise<T>;
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 { RequestContext} from "../schemas/session.schema.js";
4
+ import type { Result } from "../schemas/result.js";
5
5
  import { BaseProvider } from "./base.provider.js";
6
6
 
7
- export abstract class IdentityProvider<
8
- T extends Identity = Identity,
9
- > extends BaseProvider<T> {
10
- public abstract getSelf(payload: IdentityQuerySelf, reqCtx: RequestContext): Promise<T>;
11
- public abstract login(payload: IdentityMutationLogin, reqCtx: RequestContext): Promise<T>;
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 { RequestContext } from '../schemas/session.schema.js';
5
+ import type { Result } from '../schemas/result.js';
4
6
  import { BaseProvider } from './base.provider.js';
5
7
 
6
- export abstract class InventoryProvider<
7
- T extends Inventory = Inventory
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 "./base.provider.js";
2
- import type { RequestContext } from "../schemas/session.schema.js";
3
- import type { Order } from "../schemas/models/index.js";
4
- import type { OrderQueryById } from "../schemas/queries/index.js";
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, reqCtx: RequestContext): Promise<T>;
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 { Currency } from '../schemas/models/currency.model.js';
2
- import type { Price } from '../schemas/models/price.model.js';
3
- import type { PriceQueryBySku } from '../schemas/queries/price.query.js';
4
- import type { RequestContext } from '../schemas/session.schema.js';
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 getBySKU(payload: PriceQueryBySku, reqCtx: RequestContext): Promise<T>;
23
-
17
+ public abstract getListPrice(payload: ListPriceQuery): Promise<Result<Price>>;
24
18
 
25
19
  /**
26
- * Fetch prices for multiple SKUs in one go.
20
+ * Get a customer-specific price by SKU.
21
+ *
22
+ * No
27
23
  *
28
- * Usecase: You are rendering a product grid, and you need to show prices for multiple SKUs.
29
- * @param payload The SKUs to query
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 getBySKUs(payload: PriceQueryBySku[], reqCtx: RequestContext): Promise<T[]>;
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, currency: Currency): T {
44
- const base = this.newModel();
45
- base.identifier = {
46
- sku: { key: sku }
47
- };
48
- base.unitPrice = {
49
- value: -1,
50
- currency: currency,
51
- };
52
- base.meta = {
53
- cache: { hit: false, key: `price-${sku}-${currency}` },
54
- placeholder: true
55
- };
56
- return this.assert(base);
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
+