@reactionary/core 0.6.2 → 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 (59) 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/{providers/product-search.provider.js → capabilities/product-search.capability.js} +3 -3
  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 +16 -14
  24. package/decorators/reactionary.decorator.js +30 -32
  25. package/index.js +1 -1
  26. package/package.json +8 -8
  27. package/src/{providers/analytics.provider.d.ts → capabilities/analytics.capability.d.ts} +5 -5
  28. package/src/{providers/base.provider.d.ts → capabilities/base.capability.d.ts} +2 -2
  29. package/src/{providers/cart.provider.d.ts → capabilities/cart.capability.d.ts} +2 -2
  30. package/src/{providers/category.provider.d.ts → capabilities/category.capability.d.ts} +4 -4
  31. package/src/{providers/checkout.provider.d.ts → capabilities/checkout.capability.d.ts} +2 -2
  32. package/src/{providers/identity.provider.d.ts → capabilities/identity.capability.d.ts} +2 -2
  33. package/src/capabilities/index.d.ts +18 -0
  34. package/src/{providers/inventory.provider.d.ts → capabilities/inventory.capability.d.ts} +2 -2
  35. package/src/{providers/order-search.provider.d.ts → capabilities/order-search.capability.d.ts} +2 -2
  36. package/src/{providers/order.provider.d.ts → capabilities/order.capability.d.ts} +2 -2
  37. package/src/{providers/price.provider.d.ts → capabilities/price.capability.d.ts} +2 -2
  38. package/src/{providers/product-associations.provider.d.ts → capabilities/product-associations.capability.d.ts} +2 -2
  39. package/src/{providers/product-list.provider.d.ts → capabilities/product-list.capability.d.ts} +2 -2
  40. package/src/{providers/product-recommendations.provider.d.ts → capabilities/product-recommendations.capability.d.ts} +6 -6
  41. package/src/{providers/product-reviews.provider.d.ts → capabilities/product-reviews.capability.d.ts} +2 -2
  42. package/src/{providers/product-search.provider.d.ts → capabilities/product-search.capability.d.ts} +2 -2
  43. package/src/{providers/product.provider.d.ts → capabilities/product.capability.d.ts} +2 -2
  44. package/src/{providers/profile.provider.d.ts → capabilities/profile.capability.d.ts} +2 -2
  45. package/src/{providers/store.provider.d.ts → capabilities/store.capability.d.ts} +2 -2
  46. package/src/client/client-builder.d.ts +1 -1
  47. package/src/client/client.d.ts +29 -29
  48. package/src/decorators/reactionary.decorator.d.ts +5 -5
  49. package/src/index.d.ts +1 -1
  50. package/providers/cart.provider.js +0 -9
  51. package/providers/category.provider.js +0 -9
  52. package/providers/checkout.provider.js +0 -9
  53. package/providers/index.js +0 -18
  54. package/providers/order-search.provider.js +0 -9
  55. package/providers/product-associations.provider.js +0 -9
  56. package/providers/product-list.provider.js +0 -10
  57. package/providers/profile.provider.js +0 -9
  58. package/providers/store.provider.js +0 -9
  59. package/src/providers/index.d.ts +0 -18
@@ -1,10 +1,8 @@
1
1
  import { getReactionaryCacheMeter } from "../metrics/metrics.js";
2
2
  import { error, NotFoundErrorSchema, success } from "../schemas/index.js";
3
3
  class MemoryCache {
4
- constructor() {
5
- this.entries = new Array();
6
- this.meter = getReactionaryCacheMeter();
7
- }
4
+ entries = new Array();
5
+ meter = getReactionaryCacheMeter();
8
6
  async get(key, schema) {
9
7
  const c = this.entries.find((x) => x.key === key);
10
8
  if (!c) {
@@ -1,8 +1,6 @@
1
1
  import { getReactionaryCacheMeter } from "../metrics/metrics.js";
2
2
  class NoOpCache {
3
- constructor() {
4
- this.meter = getReactionaryCacheMeter();
5
- }
3
+ meter = getReactionaryCacheMeter();
6
4
  async get(_key, _schema) {
7
5
  this.meter.misses.add(1, {
8
6
  "labels.cache_type": "noop"
@@ -1,8 +1,9 @@
1
1
  import { Redis } from "@upstash/redis";
2
2
  import { getReactionaryCacheMeter } from "../metrics/metrics.js";
3
3
  class RedisCache {
4
+ redis;
5
+ meter = getReactionaryCacheMeter();
4
6
  constructor() {
5
- this.meter = getReactionaryCacheMeter();
6
7
  this.redis = Redis.fromEnv();
7
8
  }
8
9
  async get(key, schema) {
@@ -9,12 +9,12 @@ var __decorateClass = (decorators, target, key, kind) => {
9
9
  __defProp(target, key, result);
10
10
  return result;
11
11
  };
12
- import { BaseProvider } from "./base.provider.js";
12
+ import { BaseCapability } from "./base.capability.js";
13
13
  import {
14
14
  AnalyticsMutationSchema
15
15
  } from "../schemas/index.js";
16
16
  import { Reactionary } from "../decorators/reactionary.decorator.js";
17
- class AnalyticsProvider extends BaseProvider {
17
+ class AnalyticsCapability extends BaseCapability {
18
18
  getResourceName() {
19
19
  return "analytics";
20
20
  }
@@ -48,14 +48,15 @@ class AnalyticsProvider extends BaseProvider {
48
48
  async processPurchase(event) {
49
49
  }
50
50
  }
51
- class MulticastAnalyticsProvider extends AnalyticsProvider {
52
- constructor(cache, requestContext, providers) {
51
+ class MulticastAnalyticsCapability extends AnalyticsCapability {
52
+ capabilities;
53
+ constructor(cache, requestContext, capabilities) {
53
54
  super(cache, requestContext);
54
- this.providers = providers;
55
+ this.capabilities = capabilities;
55
56
  }
56
57
  async track(event) {
57
- for (const provider of this.providers) {
58
- provider.track(event);
58
+ for (const capability of this.capabilities) {
59
+ capability.track(event);
59
60
  }
60
61
  }
61
62
  }
@@ -63,8 +64,8 @@ __decorateClass([
63
64
  Reactionary({
64
65
  inputSchema: AnalyticsMutationSchema
65
66
  })
66
- ], MulticastAnalyticsProvider.prototype, "track", 1);
67
+ ], MulticastAnalyticsCapability.prototype, "track", 1);
67
68
  export {
68
- AnalyticsProvider,
69
- MulticastAnalyticsProvider
69
+ AnalyticsCapability,
70
+ MulticastAnalyticsCapability
70
71
  };
@@ -1,6 +1,8 @@
1
1
  import {} from "../schemas/session.schema.js";
2
2
  import { hasher } from "node-object-hash";
3
- class BaseProvider {
3
+ class BaseCapability {
4
+ cache;
5
+ context;
4
6
  constructor(cache, context) {
5
7
  this.cache = cache;
6
8
  this.context = context;
@@ -21,5 +23,5 @@ class BaseProvider {
21
23
  }
22
24
  }
23
25
  export {
24
- BaseProvider
26
+ BaseCapability
25
27
  };
@@ -0,0 +1,9 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class CartCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "cart";
5
+ }
6
+ }
7
+ export {
8
+ CartCapability
9
+ };
@@ -0,0 +1,9 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class CategoryCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "category";
5
+ }
6
+ }
7
+ export {
8
+ CategoryCapability
9
+ };
@@ -0,0 +1,9 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class CheckoutCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "checkout";
5
+ }
6
+ }
7
+ export {
8
+ CheckoutCapability
9
+ };
@@ -1,5 +1,5 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class IdentityProvider extends BaseProvider {
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class IdentityCapability extends BaseCapability {
3
3
  getResourceName() {
4
4
  return "identity";
5
5
  }
@@ -9,5 +9,5 @@ class IdentityProvider extends BaseProvider {
9
9
  }
10
10
  }
11
11
  export {
12
- IdentityProvider
12
+ IdentityCapability
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";
@@ -1,5 +1,5 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class InventoryProvider extends BaseProvider {
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class InventoryCapability extends BaseCapability {
3
3
  getResourceName() {
4
4
  return "inventory";
5
5
  }
@@ -13,5 +13,5 @@ class InventoryProvider extends BaseProvider {
13
13
  }
14
14
  }
15
15
  export {
16
- InventoryProvider
16
+ InventoryCapability
17
17
  };
@@ -0,0 +1,9 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class OrderSearchCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "order-search";
5
+ }
6
+ }
7
+ export {
8
+ OrderSearchCapability
9
+ };
@@ -1,5 +1,5 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class OrderProvider extends BaseProvider {
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class OrderCapability extends BaseCapability {
3
3
  createEmptyOrder() {
4
4
  const order = {
5
5
  identifier: {
@@ -46,5 +46,5 @@ class OrderProvider extends BaseProvider {
46
46
  }
47
47
  }
48
48
  export {
49
- OrderProvider
49
+ OrderCapability
50
50
  };
@@ -1,5 +1,5 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class PriceProvider extends BaseProvider {
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class PriceCapability extends BaseCapability {
3
3
  /**
4
4
  * Utility function to create an empty price result, with a value of -1.
5
5
  * This is used when no price is found for a given SKU + currency combination.
@@ -29,5 +29,5 @@ class PriceProvider extends BaseProvider {
29
29
  }
30
30
  }
31
31
  export {
32
- PriceProvider
32
+ PriceCapability
33
33
  };
@@ -0,0 +1,9 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class ProductAssociationsCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "product-associations";
5
+ }
6
+ }
7
+ export {
8
+ ProductAssociationsCapability
9
+ };
@@ -0,0 +1,10 @@
1
+ import {} from "../schemas/queries/product-list.query.js";
2
+ import { BaseCapability } from "./base.capability.js";
3
+ class ProductListCapability extends BaseCapability {
4
+ getResourceName() {
5
+ return "product-lists";
6
+ }
7
+ }
8
+ export {
9
+ ProductListCapability
10
+ };
@@ -12,10 +12,10 @@ var __decorateClass = (decorators, target, key, kind) => {
12
12
  import { Reactionary } from "../decorators/reactionary.decorator.js";
13
13
  import { success } from "../schemas/index.js";
14
14
  import { ProductRecommendationsQuerySchema } from "../schemas/queries/product-recommendations.query.js";
15
- import { BaseProvider } from "./base.provider.js";
16
- class ProductRecommendationsProvider extends BaseProvider {
15
+ import { BaseCapability } from "./base.capability.js";
16
+ class ProductRecommendationsCapability extends BaseCapability {
17
17
  /**
18
- * 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.
18
+ * 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.
19
19
  * *
20
20
  * Usecase:
21
21
  * - PDP - "Customers who viewed this product also viewed"
@@ -76,20 +76,21 @@ class ProductRecommendationsProvider extends BaseProvider {
76
76
  return "product-recommendations";
77
77
  }
78
78
  }
79
- class MulticastProductRecommendationsProvider extends ProductRecommendationsProvider {
80
- constructor(cache, requestContext, providers) {
79
+ class MulticastProductRecommendationsCapability extends ProductRecommendationsCapability {
80
+ capabilities;
81
+ constructor(cache, requestContext, capabilities) {
81
82
  super(cache, requestContext);
82
- this.providers = providers;
83
+ this.capabilities = capabilities;
83
84
  }
84
85
  async getRecommendations(query) {
85
86
  const output = [];
86
- for (const provider of this.providers) {
87
- const providerOutput = await provider.getRecommendations(query);
88
- if (providerOutput.success) {
89
- output.push(...providerOutput.value);
87
+ for (const capability of this.capabilities) {
88
+ const capabilityOutput = await capability.getRecommendations(query);
89
+ if (capabilityOutput.success) {
90
+ output.push(...capabilityOutput.value);
90
91
  } else {
91
- console.error(`Error from provider ${provider.constructor.name}:`, providerOutput.error);
92
- return providerOutput;
92
+ console.error(`Error from capability ${capability.constructor.name}:`, capabilityOutput.error);
93
+ return capabilityOutput;
93
94
  }
94
95
  if (output.length >= query.numberOfRecommendations) {
95
96
  break;
@@ -99,16 +100,16 @@ class MulticastProductRecommendationsProvider extends ProductRecommendationsProv
99
100
  }
100
101
  async getCollection(query) {
101
102
  const output = [];
102
- for (const provider of this.providers) {
103
- const providerOutput = await provider.getCollection(query);
104
- if (providerOutput.success) {
105
- output.push(...providerOutput.value);
103
+ for (const capability of this.capabilities) {
104
+ const capabilityOutput = await capability.getCollection(query);
105
+ if (capabilityOutput.success) {
106
+ output.push(...capabilityOutput.value);
106
107
  } else {
107
- if (providerOutput.error.type === "NotFound") {
108
+ if (capabilityOutput.error.type === "NotFound") {
108
109
  continue;
109
110
  } else {
110
- console.error(`Error from provider ${provider.constructor.name}:`, providerOutput.error);
111
- return providerOutput;
111
+ console.error(`Error from capability ${capability.constructor.name}:`, capabilityOutput.error);
112
+ return capabilityOutput;
112
113
  }
113
114
  }
114
115
  if (output.length >= query.numberOfRecommendations) {
@@ -122,8 +123,8 @@ __decorateClass([
122
123
  Reactionary({
123
124
  inputSchema: ProductRecommendationsQuerySchema
124
125
  })
125
- ], MulticastProductRecommendationsProvider.prototype, "getRecommendations", 1);
126
+ ], MulticastProductRecommendationsCapability.prototype, "getRecommendations", 1);
126
127
  export {
127
- MulticastProductRecommendationsProvider,
128
- ProductRecommendationsProvider
128
+ MulticastProductRecommendationsCapability,
129
+ ProductRecommendationsCapability
129
130
  };
@@ -1,6 +1,6 @@
1
- import { BaseProvider } from "./base.provider.js";
1
+ import { BaseCapability } from "./base.capability.js";
2
2
  import {} from "../schemas/models/identifiers.model.js";
3
- class ProductReviewsProvider extends BaseProvider {
3
+ class ProductReviewsCapability extends BaseCapability {
4
4
  createEmptyProductRatingSummary(key) {
5
5
  return {
6
6
  identifier: key,
@@ -14,5 +14,5 @@ class ProductReviewsProvider extends BaseProvider {
14
14
  }
15
15
  }
16
16
  export {
17
- ProductReviewsProvider
17
+ ProductReviewsCapability
18
18
  };
@@ -1,5 +1,5 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class ProductSearchProvider extends BaseProvider {
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class ProductSearchCapability extends BaseCapability {
3
3
  getResourceName() {
4
4
  return "product-search";
5
5
  }
@@ -11,5 +11,5 @@ class ProductSearchProvider extends BaseProvider {
11
11
  */
12
12
  }
13
13
  export {
14
- ProductSearchProvider
14
+ ProductSearchCapability
15
15
  };
@@ -1,5 +1,5 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class ProductProvider extends BaseProvider {
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class ProductCapability extends BaseCapability {
3
3
  createEmptyProduct(id) {
4
4
  const product = {
5
5
  brand: "",
@@ -40,5 +40,5 @@ class ProductProvider extends BaseProvider {
40
40
  }
41
41
  }
42
42
  export {
43
- ProductProvider
43
+ ProductCapability
44
44
  };
@@ -0,0 +1,9 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class ProfileCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "profile";
5
+ }
6
+ }
7
+ export {
8
+ ProfileCapability
9
+ };
@@ -0,0 +1,9 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class StoreCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "store";
5
+ }
6
+ }
7
+ export {
8
+ StoreCapability
9
+ };
@@ -1,13 +1,15 @@
1
1
  import { NoOpCache } from "../cache/noop-cache.js";
2
- import { MulticastAnalyticsProvider } from "../providers/analytics.provider.js";
2
+ import { MulticastAnalyticsCapability } from "../capabilities/analytics.capability.js";
3
3
  import {
4
4
  RequestContextSchema
5
5
  } from "../schemas/session.schema.js";
6
- import { MulticastProductRecommendationsProvider } from "../providers/product-recommendations.provider.js";
6
+ import { MulticastProductRecommendationsCapability } from "../capabilities/product-recommendations.capability.js";
7
7
  class ClientBuilder {
8
+ factories = [];
9
+ cache;
10
+ context;
11
+ collisionStrategy = "last-wins";
8
12
  constructor(context) {
9
- this.factories = [];
10
- this.collisionStrategy = "last-wins";
11
13
  this.context = context;
12
14
  }
13
15
  withCapability(factory) {
@@ -42,21 +44,21 @@ class ClientBuilder {
42
44
  throw new Error("Invalid context: " + validatedContext.error);
43
45
  }
44
46
  const mergedAnalytics = [];
45
- const mergedProductRecommendationsProviders = [];
47
+ const mergedProductRecommendations = [];
46
48
  for (const factory of this.factories) {
47
- const provider = this.resolveFactory(factory, sharedCache, this.context);
48
- client = this.mergeProviders(client, provider);
49
- if (provider.analytics) {
50
- mergedAnalytics.push(provider.analytics);
49
+ const capability = this.resolveFactory(factory, sharedCache, this.context);
50
+ client = this.mergeCapabilities(client, capability);
51
+ if (capability.analytics) {
52
+ mergedAnalytics.push(capability.analytics);
51
53
  }
52
- if (provider.productRecommendations) {
53
- mergedProductRecommendationsProviders.push(provider.productRecommendations);
54
+ if (capability.productRecommendations) {
55
+ mergedProductRecommendations.push(capability.productRecommendations);
54
56
  }
55
57
  }
56
58
  const completeClient = {
57
59
  ...client,
58
- analytics: new MulticastAnalyticsProvider(sharedCache, this.context, mergedAnalytics),
59
- productRecommendations: new MulticastProductRecommendationsProvider(sharedCache, this.context, mergedProductRecommendationsProviders),
60
+ analytics: new MulticastAnalyticsCapability(sharedCache, this.context, mergedAnalytics),
61
+ productRecommendations: new MulticastProductRecommendationsCapability(sharedCache, this.context, mergedProductRecommendations),
60
62
  cache: sharedCache
61
63
  };
62
64
  return completeClient;
@@ -67,7 +69,7 @@ class ClientBuilder {
67
69
  }
68
70
  return factory(cache, context);
69
71
  }
70
- mergeProviders(target, source) {
72
+ mergeCapabilities(target, source) {
71
73
  const result = { ...target };
72
74
  for (const key of Object.keys(source)) {
73
75
  const hasExisting = Object.prototype.hasOwnProperty.call(result, key);
@@ -8,37 +8,35 @@ function getTracer() {
8
8
  return trace.getTracer(TRACER_NAME, TRACER_VERSION);
9
9
  }
10
10
  class ReactionaryDecoratorOptions {
11
- constructor() {
12
- /**
13
- * Whether or not the query is eligible for caching. Queries that depend
14
- * heavily on personalization, for example, are likely to be a poor fit
15
- * for caching.
16
- */
17
- this.cache = false;
18
- /**
19
- * Whether or not the cache entry should be variable based on the locale
20
- * of the context in which it is querried.
21
- */
22
- this.localeDependentCaching = false;
23
- /**
24
- * Whether or not the cache entry should be variable based on the currency
25
- * of the context in which it is querried.
26
- */
27
- this.currencyDependentCaching = false;
28
- /**
29
- * The number of seconds which a cache entry should be considered valid for the
30
- * given query.
31
- */
32
- this.cacheTimeToLiveInSeconds = 60;
33
- /**
34
- * The schema for the input (query or mutation) type, for validation purposes
35
- */
36
- this.inputSchema = z.unknown();
37
- /**
38
- * The schema for the primary output type, for validation purposes
39
- */
40
- this.outputSchema = z.unknown();
41
- }
11
+ /**
12
+ * Whether or not the query is eligible for caching. Queries that depend
13
+ * heavily on personalization, for example, are likely to be a poor fit
14
+ * for caching.
15
+ */
16
+ cache = false;
17
+ /**
18
+ * Whether or not the cache entry should be variable based on the locale
19
+ * of the context in which it is querried.
20
+ */
21
+ localeDependentCaching = false;
22
+ /**
23
+ * Whether or not the cache entry should be variable based on the currency
24
+ * of the context in which it is querried.
25
+ */
26
+ currencyDependentCaching = false;
27
+ /**
28
+ * The number of seconds which a cache entry should be considered valid for the
29
+ * given query.
30
+ */
31
+ cacheTimeToLiveInSeconds = 60;
32
+ /**
33
+ * The schema for the input (query or mutation) type, for validation purposes
34
+ */
35
+ inputSchema = z.unknown();
36
+ /**
37
+ * The schema for the primary output type, for validation purposes
38
+ */
39
+ outputSchema = z.unknown();
42
40
  }
43
41
  function Reactionary(options) {
44
42
  return function(target, propertyKey, descriptor) {
@@ -54,7 +52,7 @@ function Reactionary(options) {
54
52
  let cacheStatus = "miss";
55
53
  if (!original) {
56
54
  throw new Error(
57
- "@Reactionary decorator may only be applied to methods on classes extending BaseProvider."
55
+ "@Reactionary decorator may only be applied to methods on classes extending BaseCapability."
58
56
  );
59
57
  }
60
58
  descriptor.value = async function(...args) {
package/index.js CHANGED
@@ -2,6 +2,6 @@ export * from "./cache/index.js";
2
2
  export * from "./client/index.js";
3
3
  export * from "./decorators/index.js";
4
4
  export * from "./factories/index.js";
5
- export * from "./providers/index.js";
5
+ export * from "./capabilities/index.js";
6
6
  export * from "./schemas/index.js";
7
7
  export * from "./initialization.js";
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@reactionary/core",
3
- "version": "0.6.2",
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<TCart extends Cart = Cart, TCartIdentifier extends CartIdentifier = CartIdentifier> 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
  *
@@ -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<TCategory extends Category = Category, TCategoryPaginatedResult extends CategoryPaginatedResult = CategoryPaginatedResult> 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
  *
@@ -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<TCheckout extends Checkout = Checkout, TShippingMethod extends ShippingMethod = ShippingMethod, TPaymentMethod extends PaymentMethod = PaymentMethod> 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.
@@ -2,8 +2,8 @@ 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<TIdentity extends Identity = Identity> extends BaseProvider {
5
+ import { BaseCapability } from "./base.capability.js";
6
+ export declare abstract class IdentityCapability<TIdentity extends Identity = Identity> extends BaseCapability {
7
7
  abstract getSelf(payload: IdentityQuerySelf): Promise<Result<TIdentity>>;
8
8
  abstract login(payload: IdentityMutationLogin): Promise<Result<TIdentity>>;
9
9
  abstract logout(payload: IdentityMutationLogout): Promise<Result<TIdentity>>;
@@ -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,8 +3,8 @@ 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<TInventory extends Inventory = Inventory> extends BaseProvider {
6
+ import { BaseCapability } from './base.capability.js';
7
+ export declare abstract class InventoryCapability<TInventory extends Inventory = Inventory> extends BaseCapability {
8
8
  abstract getBySKU(payload: InventoryQueryBySKU): Promise<Result<TInventory, NotFoundError>>;
9
9
  protected getResourceName(): string;
10
10
  protected createEmptyInventory(key: InventoryIdentifier): TInventory;
@@ -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<TOrderSearchResult extends OrderSearchResult = OrderSearchResult> 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.
@@ -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<TOrder extends Order = Order> extends BaseProvider {
6
+ export declare abstract class OrderCapability<TOrder extends Order = Order> extends BaseCapability {
7
7
  /**
8
8
  * Get order by ID.
9
9
  *
@@ -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<TPrice extends Price = Price> 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.
@@ -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<TProductAssociation extends ProductAssociation = ProductAssociation> 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:
@@ -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,7 +12,7 @@ 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<TProductList extends ProductList = ProductList, TProductListItem extends ProductListItem = ProductListItem, TProductListPaginatedResult extends ProductListPaginatedResult = ProductListPaginatedResult, TProductListItemPaginatedResult extends ProductListItemPaginatedResult = ProductListItemPaginatedResult> 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.
@@ -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,14 +1,14 @@
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<TProductRatingSummary extends ProductRatingSummary = ProductRatingSummary, TProductReviewPaginatedResult extends ProductReviewPaginatedResult = ProductReviewPaginatedResult, TProductReview extends ProductReview = ProductReview> 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
  *
@@ -1,8 +1,8 @@
1
1
  import type { FacetValueIdentifier, Result } from '../index.js';
2
2
  import type { ProductSearchResult } from '../schemas/models/product-search.model.js';
3
3
  import type { ProductSearchQueryByTerm, ProductSearchQueryCreateNavigationFilter } from '../schemas/queries/product-search.query.js';
4
- import { BaseProvider } from './base.provider.js';
5
- export declare abstract class ProductSearchProvider<TProductSearchResult extends ProductSearchResult = ProductSearchResult> extends BaseProvider {
4
+ import { BaseCapability } from './base.capability.js';
5
+ export declare abstract class ProductSearchCapability<TProductSearchResult extends ProductSearchResult = ProductSearchResult> extends BaseCapability {
6
6
  protected getResourceName(): string;
7
7
  abstract queryByTerm(payload: ProductSearchQueryByTerm): Promise<Result<TProductSearchResult>>;
8
8
  /**
@@ -1,9 +1,9 @@
1
1
  import type { Product } from '../schemas/models/product.model.js';
2
- import { BaseProvider } from './base.provider.js';
2
+ import { BaseCapability } from './base.capability.js';
3
3
  import type { ProductQueryById, ProductQueryBySKU, ProductQueryBySlug } from '../schemas/queries/product.query.js';
4
4
  import type { Result } from '../schemas/result.js';
5
5
  import type { NotFoundError } from '../schemas/index.js';
6
- export declare abstract class ProductProvider<TProduct extends Product = Product> extends BaseProvider {
6
+ export declare abstract class ProductCapability<TProduct extends Product = Product> extends BaseCapability {
7
7
  /**
8
8
  * Get a product by its ID.
9
9
  * @param payload The query payload containing the product ID.
@@ -3,8 +3,8 @@ import type { Profile } from '../schemas/models/index.js';
3
3
  import type { ProfileMutationAddShippingAddress, ProfileMutationMakeShippingAddressDefault, ProfileMutationRemoveShippingAddress, ProfileMutationSetBillingAddress, ProfileMutationUpdate, ProfileMutationUpdateShippingAddress } from '../schemas/mutations/index.js';
4
4
  import type { ProfileQuerySelf as ProfileQueryById } from '../schemas/queries/index.js';
5
5
  import type { Result } from '../schemas/result.js';
6
- import { BaseProvider } from './base.provider.js';
7
- export declare abstract class ProfileProvider<TProfile extends Profile = Profile> extends BaseProvider {
6
+ import { BaseCapability } from './base.capability.js';
7
+ export declare abstract class ProfileCapability<TProfile extends Profile = Profile> extends BaseCapability {
8
8
  /**
9
9
  * Returns the profile of the currently authenticated (registered) user.
10
10
  *
@@ -1,8 +1,8 @@
1
1
  import type { Store } from '../schemas/models/store.model.js';
2
2
  import type { StoreQueryByProximity } from '../schemas/queries/index.js';
3
3
  import type { Result } from '../schemas/result.js';
4
- import { BaseProvider } from './base.provider.js';
5
- export declare abstract class StoreProvider<TStore extends Store = Store> extends BaseProvider {
4
+ import { BaseCapability } from './base.capability.js';
5
+ export declare abstract class StoreCapability<TStore extends Store = Store> extends BaseCapability {
6
6
  abstract queryByProximity(payload: StoreQueryByProximity): Promise<Result<Array<TStore>>>;
7
7
  protected getResourceName(): string;
8
8
  }
@@ -21,6 +21,6 @@ export declare class ClientBuilder<TClient = Client> {
21
21
  cache: Cache;
22
22
  };
23
23
  private resolveFactory;
24
- private mergeProviders;
24
+ private mergeCapabilities;
25
25
  }
26
26
  export {};
@@ -1,33 +1,33 @@
1
- import type { ProductProvider } from "../providers/product.provider.js";
2
- import type { ProductSearchProvider } from "../providers/product-search.provider.js";
3
- import type { IdentityProvider } from '../providers/identity.provider.js';
4
- import type { CartProvider } from "../providers/cart.provider.js";
5
- import type { PriceProvider } from "../providers/price.provider.js";
6
- import type { InventoryProvider } from "../providers/inventory.provider.js";
1
+ import type { ProductCapability } from "../capabilities/product.capability.js";
2
+ import type { ProductSearchCapability } from "../capabilities/product-search.capability.js";
3
+ import type { IdentityCapability } from '../capabilities/identity.capability.js';
4
+ import type { CartCapability } from "../capabilities/cart.capability.js";
5
+ import type { PriceCapability } from "../capabilities/price.capability.js";
6
+ import type { InventoryCapability } from "../capabilities/inventory.capability.js";
7
7
  import type { Cache } from "../cache/cache.interface.js";
8
- import type { CategoryProvider } from "../providers/category.provider.js";
9
- import type { AnalyticsProvider, CheckoutProvider, OrderProvider, ProductListProvider, ProfileProvider, StoreProvider } from "../providers/index.js";
10
- import type { OrderSearchProvider } from "../providers/order-search.provider.js";
11
- import type { ProductRecommendationsProvider } from "../providers/product-recommendations.provider.js";
12
- import type { ProductAssociationsProvider } from "../providers/product-associations.provider.js";
13
- import type { ProductReviewsProvider } from "../providers/product-reviews.provider.js";
8
+ import type { CategoryCapability } from "../capabilities/category.capability.js";
9
+ import type { AnalyticsCapability, CheckoutCapability, OrderCapability, ProductListCapability, ProfileCapability, StoreCapability } from "../capabilities/index.js";
10
+ import type { OrderSearchCapability } from "../capabilities/order-search.capability.js";
11
+ import type { ProductRecommendationsCapability } from "../capabilities/product-recommendations.capability.js";
12
+ import type { ProductAssociationsCapability } from "../capabilities/product-associations.capability.js";
13
+ import type { ProductReviewsCapability } from "../capabilities/product-reviews.capability.js";
14
14
  export interface Client {
15
- product: ProductProvider;
16
- productSearch: ProductSearchProvider;
17
- productRecommendations: ProductRecommendationsProvider;
18
- productAssociations: ProductAssociationsProvider;
19
- productReviews: ProductReviewsProvider;
20
- productList: ProductListProvider;
21
- identity: IdentityProvider;
15
+ product: ProductCapability;
16
+ productSearch: ProductSearchCapability;
17
+ productRecommendations: ProductRecommendationsCapability;
18
+ productAssociations: ProductAssociationsCapability;
19
+ productReviews: ProductReviewsCapability;
20
+ productList: ProductListCapability;
21
+ identity: IdentityCapability;
22
22
  cache: Cache;
23
- cart: CartProvider;
24
- checkout: CheckoutProvider;
25
- analytics: AnalyticsProvider;
26
- price: PriceProvider;
27
- inventory: InventoryProvider;
28
- category: CategoryProvider;
29
- profile: ProfileProvider;
30
- store: StoreProvider;
31
- order: OrderProvider;
32
- orderSearch: OrderSearchProvider;
23
+ cart: CartCapability;
24
+ checkout: CheckoutCapability;
25
+ analytics: AnalyticsCapability;
26
+ price: PriceCapability;
27
+ inventory: InventoryCapability;
28
+ category: CategoryCapability;
29
+ profile: ProfileCapability;
30
+ store: StoreCapability;
31
+ order: OrderCapability;
32
+ orderSearch: OrderSearchCapability;
33
33
  }
@@ -1,10 +1,10 @@
1
1
  import type { Tracer } from '@opentelemetry/api';
2
2
  import * as z from 'zod';
3
- import type { BaseProvider } from '../providers/index.js';
3
+ import type { BaseCapability } from '../capabilities/index.js';
4
4
  import { type Result } from '../schemas/result.js';
5
5
  export declare function getTracer(): Tracer;
6
6
  /**
7
- * The options associated with annotating a provider function and marking
7
+ * The options associated with annotating a capability function and marking
8
8
  * it as a reactionary entrypoint to be called
9
9
  */
10
10
  export declare class ReactionaryDecoratorOptions {
@@ -39,11 +39,11 @@ export declare class ReactionaryDecoratorOptions {
39
39
  outputSchema: z.ZodType;
40
40
  }
41
41
  /**
42
- * Decorator for provider functions to provide functionality such as caching, tracing and type-checked
42
+ * Decorator for capability functions to provide functionality such as caching, tracing and type-checked
43
43
  * assertion through Zod. It should only be used with publically accessible queries or mutations on
44
- * providers.
44
+ * capabilities.
45
45
  */
46
- export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseProvider, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
46
+ export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target: BaseCapability, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
47
47
  /**
48
48
  * Utility function to handle input validation.
49
49
  */
package/src/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from './cache/index.js';
2
2
  export * from './client/index.js';
3
3
  export * from './decorators/index.js';
4
4
  export * from './factories/index.js';
5
- export * from './providers/index.js';
5
+ export * from './capabilities/index.js';
6
6
  export * from './schemas/index.js';
7
7
  export * from './initialization.js';
8
8
  export type { InferType } from './zod-utils.js';
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class CartProvider extends BaseProvider {
3
- getResourceName() {
4
- return "cart";
5
- }
6
- }
7
- export {
8
- CartProvider
9
- };
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class CategoryProvider extends BaseProvider {
3
- getResourceName() {
4
- return "category";
5
- }
6
- }
7
- export {
8
- CategoryProvider
9
- };
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class CheckoutProvider extends BaseProvider {
3
- getResourceName() {
4
- return "checkout";
5
- }
6
- }
7
- export {
8
- CheckoutProvider
9
- };
@@ -1,18 +0,0 @@
1
- export * from "./analytics.provider.js";
2
- export * from "./base.provider.js";
3
- export * from "./cart.provider.js";
4
- export * from "./category.provider.js";
5
- export * from "./checkout.provider.js";
6
- export * from "./identity.provider.js";
7
- export * from "./inventory.provider.js";
8
- export * from "./price.provider.js";
9
- export * from "./product.provider.js";
10
- export * from "./profile.provider.js";
11
- export * from "./product-search.provider.js";
12
- export * from "./product-recommendations.provider.js";
13
- export * from "./product-associations.provider.js";
14
- export * from "./product-reviews.provider.js";
15
- export * from "./product-list.provider.js";
16
- export * from "./store.provider.js";
17
- export * from "./order.provider.js";
18
- export * from "./order-search.provider.js";
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class OrderSearchProvider extends BaseProvider {
3
- getResourceName() {
4
- return "order-search";
5
- }
6
- }
7
- export {
8
- OrderSearchProvider
9
- };
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class ProductAssociationsProvider extends BaseProvider {
3
- getResourceName() {
4
- return "product-associations";
5
- }
6
- }
7
- export {
8
- ProductAssociationsProvider
9
- };
@@ -1,10 +0,0 @@
1
- import {} from "../schemas/queries/product-list.query.js";
2
- import { BaseProvider } from "./base.provider.js";
3
- class ProductListProvider extends BaseProvider {
4
- getResourceName() {
5
- return "product-lists";
6
- }
7
- }
8
- export {
9
- ProductListProvider
10
- };
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class ProfileProvider extends BaseProvider {
3
- getResourceName() {
4
- return "profile";
5
- }
6
- }
7
- export {
8
- ProfileProvider
9
- };
@@ -1,9 +0,0 @@
1
- import { BaseProvider } from "./base.provider.js";
2
- class StoreProvider extends BaseProvider {
3
- getResourceName() {
4
- return "store";
5
- }
6
- }
7
- export {
8
- StoreProvider
9
- };
@@ -1,18 +0,0 @@
1
- export * from './analytics.provider.js';
2
- export * from './base.provider.js';
3
- export * from './cart.provider.js';
4
- export * from './category.provider.js';
5
- export * from './checkout.provider.js';
6
- export * from './identity.provider.js';
7
- export * from './inventory.provider.js';
8
- export * from './price.provider.js';
9
- export * from './product.provider.js';
10
- export * from './profile.provider.js';
11
- export * from './product-search.provider.js';
12
- export * from './product-recommendations.provider.js';
13
- export * from './product-associations.provider.js';
14
- export * from './product-reviews.provider.js';
15
- export * from './product-list.provider.js';
16
- export * from './store.provider.js';
17
- export * from './order.provider.js';
18
- export * from './order-search.provider.js';