@reactionary/core 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/cache/memory-cache.js +2 -4
  2. package/cache/noop-cache.js +1 -3
  3. package/cache/redis-cache.js +2 -1
  4. package/{providers/analytics.provider.js → capabilities/analytics.capability.js} +11 -10
  5. package/{providers/base.provider.js → capabilities/base.capability.js} +4 -2
  6. package/capabilities/cart.capability.js +9 -0
  7. package/capabilities/category.capability.js +9 -0
  8. package/capabilities/checkout.capability.js +9 -0
  9. package/{providers/identity.provider.js → capabilities/identity.capability.js} +3 -3
  10. package/capabilities/index.js +18 -0
  11. package/{providers/inventory.provider.js → capabilities/inventory.capability.js} +3 -3
  12. package/capabilities/order-search.capability.js +9 -0
  13. package/{providers/order.provider.js → capabilities/order.capability.js} +3 -3
  14. package/{providers/price.provider.js → capabilities/price.capability.js} +3 -3
  15. package/capabilities/product-associations.capability.js +9 -0
  16. package/capabilities/product-list.capability.js +10 -0
  17. package/{providers/product-recommendations.provider.js → capabilities/product-recommendations.capability.js} +23 -22
  18. package/{providers/product-reviews.provider.js → capabilities/product-reviews.capability.js} +3 -3
  19. package/capabilities/product-search.capability.js +15 -0
  20. package/{providers/product.provider.js → capabilities/product.capability.js} +3 -3
  21. package/capabilities/profile.capability.js +9 -0
  22. package/capabilities/store.capability.js +9 -0
  23. package/client/client-builder.js +47 -15
  24. package/decorators/reactionary.decorator.js +30 -32
  25. package/factories/cart.factory.js +0 -0
  26. package/factories/category.factory.js +0 -0
  27. package/factories/checkout.factory.js +0 -0
  28. package/factories/identity.factory.js +0 -0
  29. package/factories/index.js +15 -0
  30. package/factories/inventory.factory.js +0 -0
  31. package/factories/order-search.factory.js +0 -0
  32. package/factories/order.factory.js +0 -0
  33. package/factories/price.factory.js +0 -0
  34. package/factories/product-associations.factory.js +0 -0
  35. package/factories/product-list.factory.js +0 -0
  36. package/factories/product-reviews.factory.js +0 -0
  37. package/factories/product-search.factory.js +0 -0
  38. package/factories/product.factory.js +0 -0
  39. package/factories/profile.factory.js +0 -0
  40. package/factories/store.factory.js +0 -0
  41. package/index.js +2 -1
  42. package/package.json +8 -8
  43. package/src/{providers/analytics.provider.d.ts → capabilities/analytics.capability.d.ts} +5 -5
  44. package/src/{providers/base.provider.d.ts → capabilities/base.capability.d.ts} +2 -2
  45. package/src/{providers/cart.provider.d.ts → capabilities/cart.capability.d.ts} +10 -10
  46. package/src/{providers/category.provider.d.ts → capabilities/category.capability.d.ts} +9 -9
  47. package/src/{providers/checkout.provider.d.ts → capabilities/checkout.capability.d.ts} +11 -11
  48. package/src/{providers/identity.provider.d.ts → capabilities/identity.capability.d.ts} +7 -7
  49. package/src/capabilities/index.d.ts +18 -0
  50. package/src/{providers/inventory.provider.d.ts → capabilities/inventory.capability.d.ts} +4 -4
  51. package/src/{providers/order-search.provider.d.ts → capabilities/order-search.capability.d.ts} +3 -3
  52. package/src/{providers/order.provider.d.ts → capabilities/order.capability.d.ts} +4 -4
  53. package/src/{providers/price.provider.d.ts → capabilities/price.capability.d.ts} +5 -5
  54. package/src/{providers/product-associations.provider.d.ts → capabilities/product-associations.capability.d.ts} +5 -5
  55. package/src/{providers/product-list.provider.d.ts → capabilities/product-list.capability.d.ts} +9 -9
  56. package/src/{providers/product-recommendations.provider.d.ts → capabilities/product-recommendations.capability.d.ts} +6 -6
  57. package/src/{providers/product-reviews.provider.d.ts → capabilities/product-reviews.capability.d.ts} +5 -5
  58. package/src/{providers/product-search.provider.d.ts → capabilities/product-search.capability.d.ts} +5 -28
  59. package/src/{providers/product.provider.d.ts → capabilities/product.capability.d.ts} +6 -6
  60. package/src/{providers/profile.provider.d.ts → capabilities/profile.capability.d.ts} +9 -9
  61. package/src/{providers/store.provider.d.ts → capabilities/store.capability.d.ts} +3 -3
  62. package/src/client/client-builder.d.ts +10 -1
  63. package/src/client/client.d.ts +29 -29
  64. package/src/decorators/reactionary.decorator.d.ts +5 -5
  65. package/src/factories/cart.factory.d.ts +18 -0
  66. package/src/factories/category.factory.d.ts +17 -0
  67. package/src/factories/checkout.factory.d.ts +24 -0
  68. package/src/factories/identity.factory.d.ts +12 -0
  69. package/src/factories/index.d.ts +15 -0
  70. package/src/factories/inventory.factory.d.ts +12 -0
  71. package/src/factories/order-search.factory.d.ts +13 -0
  72. package/src/factories/order.factory.d.ts +12 -0
  73. package/src/factories/price.factory.d.ts +16 -0
  74. package/src/factories/product-associations.factory.d.ts +12 -0
  75. package/src/factories/product-list.factory.d.ts +27 -0
  76. package/src/factories/product-reviews.factory.d.ts +22 -0
  77. package/src/factories/product-search.factory.d.ts +13 -0
  78. package/src/factories/product.factory.d.ts +12 -0
  79. package/src/factories/profile.factory.d.ts +12 -0
  80. package/src/factories/store.factory.d.ts +12 -0
  81. package/src/index.d.ts +3 -1
  82. package/providers/cart.provider.js +0 -9
  83. package/providers/category.provider.js +0 -9
  84. package/providers/checkout.provider.js +0 -9
  85. package/providers/index.js +0 -18
  86. package/providers/order-search.provider.js +0 -9
  87. package/providers/product-associations.provider.js +0 -9
  88. package/providers/product-list.provider.js +0 -10
  89. package/providers/product-search.provider.js +0 -9
  90. package/providers/profile.provider.js +0 -9
  91. package/providers/store.provider.js +0 -9
  92. package/src/providers/index.d.ts +0 -18
@@ -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
  };
@@ -0,0 +1,15 @@
1
+ import { BaseCapability } from "./base.capability.js";
2
+ class ProductSearchCapability extends BaseCapability {
3
+ getResourceName() {
4
+ return "product-search";
5
+ }
6
+ /**
7
+ * Parses a facet value from the search response.
8
+ * @param facetValueIdentifier The identifier for the facet value.
9
+ * @param label The label for the facet value.
10
+ * @param count The count for the facet value.
11
+ */
12
+ }
13
+ export {
14
+ ProductSearchCapability
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,12 +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
13
  this.context = context;
11
14
  }
12
15
  withCapability(factory) {
@@ -14,6 +17,7 @@ class ClientBuilder {
14
17
  newBuilder.factories = [...this.factories, factory];
15
18
  newBuilder.cache = this.cache;
16
19
  newBuilder.context = this.context;
20
+ newBuilder.collisionStrategy = this.collisionStrategy;
17
21
  return newBuilder;
18
22
  }
19
23
  withCache(cache) {
@@ -21,6 +25,15 @@ class ClientBuilder {
21
25
  newBuilder.factories = [...this.factories];
22
26
  newBuilder.cache = cache;
23
27
  newBuilder.context = this.context;
28
+ newBuilder.collisionStrategy = this.collisionStrategy;
29
+ return newBuilder;
30
+ }
31
+ withCollisionStrategy(strategy) {
32
+ const newBuilder = new ClientBuilder(this.context);
33
+ newBuilder.factories = [...this.factories];
34
+ newBuilder.cache = this.cache;
35
+ newBuilder.context = this.context;
36
+ newBuilder.collisionStrategy = strategy;
24
37
  return newBuilder;
25
38
  }
26
39
  build() {
@@ -31,28 +44,47 @@ class ClientBuilder {
31
44
  throw new Error("Invalid context: " + validatedContext.error);
32
45
  }
33
46
  const mergedAnalytics = [];
34
- const mergedProductRecommendationsProviders = [];
47
+ const mergedProductRecommendations = [];
35
48
  for (const factory of this.factories) {
36
- const provider = factory(sharedCache, this.context);
37
- client = {
38
- ...client,
39
- ...provider
40
- };
41
- if (provider.analytics) {
42
- 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);
43
53
  }
44
- if (provider.productRecommendations) {
45
- mergedProductRecommendationsProviders.push(provider.productRecommendations);
54
+ if (capability.productRecommendations) {
55
+ mergedProductRecommendations.push(capability.productRecommendations);
46
56
  }
47
57
  }
48
58
  const completeClient = {
49
59
  ...client,
50
- analytics: new MulticastAnalyticsProvider(sharedCache, this.context, mergedAnalytics),
51
- productRecommendations: new MulticastProductRecommendationsProvider(sharedCache, this.context, mergedProductRecommendationsProviders),
60
+ analytics: new MulticastAnalyticsCapability(sharedCache, this.context, mergedAnalytics),
61
+ productRecommendations: new MulticastProductRecommendationsCapability(sharedCache, this.context, mergedProductRecommendations),
52
62
  cache: sharedCache
53
63
  };
54
64
  return completeClient;
55
65
  }
66
+ resolveFactory(factory, cache, context) {
67
+ if (factory.length <= 1) {
68
+ return factory({ cache, context });
69
+ }
70
+ return factory(cache, context);
71
+ }
72
+ mergeCapabilities(target, source) {
73
+ const result = { ...target };
74
+ for (const key of Object.keys(source)) {
75
+ const hasExisting = Object.prototype.hasOwnProperty.call(result, key);
76
+ if (hasExisting) {
77
+ if (this.collisionStrategy === "first-wins") {
78
+ continue;
79
+ }
80
+ if (this.collisionStrategy === "throw") {
81
+ throw new Error(`Capability collision detected for "${key}"`);
82
+ }
83
+ }
84
+ result[key] = source[key];
85
+ }
86
+ return result;
87
+ }
56
88
  }
57
89
  export {
58
90
  ClientBuilder
@@ -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) {
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ export * from "./cart.factory.js";
2
+ export * from "./category.factory.js";
3
+ export * from "./checkout.factory.js";
4
+ export * from "./identity.factory.js";
5
+ export * from "./inventory.factory.js";
6
+ export * from "./order.factory.js";
7
+ export * from "./order-search.factory.js";
8
+ export * from "./price.factory.js";
9
+ export * from "./product.factory.js";
10
+ export * from "./product-associations.factory.js";
11
+ export * from "./product-list.factory.js";
12
+ export * from "./product-reviews.factory.js";
13
+ export * from "./product-search.factory.js";
14
+ export * from "./profile.factory.js";
15
+ export * from "./store.factory.js";
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./cache/index.js";
2
2
  export * from "./client/index.js";
3
3
  export * from "./decorators/index.js";
4
- export * from "./providers/index.js";
4
+ export * from "./factories/index.js";
5
+ export * from "./capabilities/index.js";
5
6
  export * from "./schemas/index.js";
6
7
  export * from "./initialization.js";