@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.
- package/cache/memory-cache.js +2 -4
- package/cache/noop-cache.js +1 -3
- package/cache/redis-cache.js +2 -1
- package/{providers/analytics.provider.js → capabilities/analytics.capability.js} +11 -10
- package/{providers/base.provider.js → capabilities/base.capability.js} +4 -2
- package/capabilities/cart.capability.js +9 -0
- package/capabilities/category.capability.js +9 -0
- package/capabilities/checkout.capability.js +9 -0
- package/{providers/identity.provider.js → capabilities/identity.capability.js} +3 -3
- package/capabilities/index.js +18 -0
- package/{providers/inventory.provider.js → capabilities/inventory.capability.js} +3 -3
- package/capabilities/order-search.capability.js +9 -0
- package/{providers/order.provider.js → capabilities/order.capability.js} +3 -3
- package/{providers/price.provider.js → capabilities/price.capability.js} +3 -3
- package/capabilities/product-associations.capability.js +9 -0
- package/capabilities/product-list.capability.js +10 -0
- package/{providers/product-recommendations.provider.js → capabilities/product-recommendations.capability.js} +23 -22
- package/{providers/product-reviews.provider.js → capabilities/product-reviews.capability.js} +3 -3
- package/capabilities/product-search.capability.js +15 -0
- package/{providers/product.provider.js → capabilities/product.capability.js} +3 -3
- package/capabilities/profile.capability.js +9 -0
- package/capabilities/store.capability.js +9 -0
- package/client/client-builder.js +47 -15
- package/decorators/reactionary.decorator.js +30 -32
- package/factories/cart.factory.js +0 -0
- package/factories/category.factory.js +0 -0
- package/factories/checkout.factory.js +0 -0
- package/factories/identity.factory.js +0 -0
- package/factories/index.js +15 -0
- package/factories/inventory.factory.js +0 -0
- package/factories/order-search.factory.js +0 -0
- package/factories/order.factory.js +0 -0
- package/factories/price.factory.js +0 -0
- package/factories/product-associations.factory.js +0 -0
- package/factories/product-list.factory.js +0 -0
- package/factories/product-reviews.factory.js +0 -0
- package/factories/product-search.factory.js +0 -0
- package/factories/product.factory.js +0 -0
- package/factories/profile.factory.js +0 -0
- package/factories/store.factory.js +0 -0
- package/index.js +2 -1
- package/package.json +8 -8
- package/src/{providers/analytics.provider.d.ts → capabilities/analytics.capability.d.ts} +5 -5
- package/src/{providers/base.provider.d.ts → capabilities/base.capability.d.ts} +2 -2
- package/src/{providers/cart.provider.d.ts → capabilities/cart.capability.d.ts} +10 -10
- package/src/{providers/category.provider.d.ts → capabilities/category.capability.d.ts} +9 -9
- package/src/{providers/checkout.provider.d.ts → capabilities/checkout.capability.d.ts} +11 -11
- package/src/{providers/identity.provider.d.ts → capabilities/identity.capability.d.ts} +7 -7
- package/src/capabilities/index.d.ts +18 -0
- package/src/{providers/inventory.provider.d.ts → capabilities/inventory.capability.d.ts} +4 -4
- package/src/{providers/order-search.provider.d.ts → capabilities/order-search.capability.d.ts} +3 -3
- package/src/{providers/order.provider.d.ts → capabilities/order.capability.d.ts} +4 -4
- package/src/{providers/price.provider.d.ts → capabilities/price.capability.d.ts} +5 -5
- package/src/{providers/product-associations.provider.d.ts → capabilities/product-associations.capability.d.ts} +5 -5
- package/src/{providers/product-list.provider.d.ts → capabilities/product-list.capability.d.ts} +9 -9
- package/src/{providers/product-recommendations.provider.d.ts → capabilities/product-recommendations.capability.d.ts} +6 -6
- package/src/{providers/product-reviews.provider.d.ts → capabilities/product-reviews.capability.d.ts} +5 -5
- package/src/{providers/product-search.provider.d.ts → capabilities/product-search.capability.d.ts} +5 -28
- package/src/{providers/product.provider.d.ts → capabilities/product.capability.d.ts} +6 -6
- package/src/{providers/profile.provider.d.ts → capabilities/profile.capability.d.ts} +9 -9
- package/src/{providers/store.provider.d.ts → capabilities/store.capability.d.ts} +3 -3
- package/src/client/client-builder.d.ts +10 -1
- package/src/client/client.d.ts +29 -29
- package/src/decorators/reactionary.decorator.d.ts +5 -5
- package/src/factories/cart.factory.d.ts +18 -0
- package/src/factories/category.factory.d.ts +17 -0
- package/src/factories/checkout.factory.d.ts +24 -0
- package/src/factories/identity.factory.d.ts +12 -0
- package/src/factories/index.d.ts +15 -0
- package/src/factories/inventory.factory.d.ts +12 -0
- package/src/factories/order-search.factory.d.ts +13 -0
- package/src/factories/order.factory.d.ts +12 -0
- package/src/factories/price.factory.d.ts +16 -0
- package/src/factories/product-associations.factory.d.ts +12 -0
- package/src/factories/product-list.factory.d.ts +27 -0
- package/src/factories/product-reviews.factory.d.ts +22 -0
- package/src/factories/product-search.factory.d.ts +13 -0
- package/src/factories/product.factory.d.ts +12 -0
- package/src/factories/profile.factory.d.ts +12 -0
- package/src/factories/store.factory.d.ts +12 -0
- package/src/index.d.ts +3 -1
- package/providers/cart.provider.js +0 -9
- package/providers/category.provider.js +0 -9
- package/providers/checkout.provider.js +0 -9
- package/providers/index.js +0 -18
- package/providers/order-search.provider.js +0 -9
- package/providers/product-associations.provider.js +0 -9
- package/providers/product-list.provider.js +0 -10
- package/providers/product-search.provider.js +0 -9
- package/providers/profile.provider.js +0 -9
- package/providers/store.provider.js +0 -9
- package/src/providers/index.d.ts +0 -18
package/cache/memory-cache.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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) {
|
package/cache/noop-cache.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { getReactionaryCacheMeter } from "../metrics/metrics.js";
|
|
2
2
|
class NoOpCache {
|
|
3
|
-
|
|
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"
|
package/cache/redis-cache.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
52
|
-
|
|
51
|
+
class MulticastAnalyticsCapability extends AnalyticsCapability {
|
|
52
|
+
capabilities;
|
|
53
|
+
constructor(cache, requestContext, capabilities) {
|
|
53
54
|
super(cache, requestContext);
|
|
54
|
-
this.
|
|
55
|
+
this.capabilities = capabilities;
|
|
55
56
|
}
|
|
56
57
|
async track(event) {
|
|
57
|
-
for (const
|
|
58
|
-
|
|
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
|
-
],
|
|
67
|
+
], MulticastAnalyticsCapability.prototype, "track", 1);
|
|
67
68
|
export {
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
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
|
-
|
|
26
|
+
BaseCapability
|
|
25
27
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
class
|
|
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
|
-
|
|
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 {
|
|
2
|
-
class
|
|
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
|
-
|
|
16
|
+
InventoryCapability
|
|
17
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
class
|
|
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
|
-
|
|
49
|
+
OrderCapability
|
|
50
50
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
class
|
|
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
|
-
|
|
32
|
+
PriceCapability
|
|
33
33
|
};
|
|
@@ -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 {
|
|
16
|
-
class
|
|
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
|
|
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
|
|
80
|
-
|
|
79
|
+
class MulticastProductRecommendationsCapability extends ProductRecommendationsCapability {
|
|
80
|
+
capabilities;
|
|
81
|
+
constructor(cache, requestContext, capabilities) {
|
|
81
82
|
super(cache, requestContext);
|
|
82
|
-
this.
|
|
83
|
+
this.capabilities = capabilities;
|
|
83
84
|
}
|
|
84
85
|
async getRecommendations(query) {
|
|
85
86
|
const output = [];
|
|
86
|
-
for (const
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
output.push(...
|
|
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
|
|
92
|
-
return
|
|
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
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
105
|
-
output.push(...
|
|
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 (
|
|
108
|
+
if (capabilityOutput.error.type === "NotFound") {
|
|
108
109
|
continue;
|
|
109
110
|
} else {
|
|
110
|
-
console.error(`Error from
|
|
111
|
-
return
|
|
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
|
-
],
|
|
126
|
+
], MulticastProductRecommendationsCapability.prototype, "getRecommendations", 1);
|
|
126
127
|
export {
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
MulticastProductRecommendationsCapability,
|
|
129
|
+
ProductRecommendationsCapability
|
|
129
130
|
};
|
package/{providers/product-reviews.provider.js → capabilities/product-reviews.capability.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseCapability } from "./base.capability.js";
|
|
2
2
|
import {} from "../schemas/models/identifiers.model.js";
|
|
3
|
-
class
|
|
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
|
-
|
|
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 {
|
|
2
|
-
class
|
|
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
|
-
|
|
43
|
+
ProductCapability
|
|
44
44
|
};
|
package/client/client-builder.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { NoOpCache } from "../cache/noop-cache.js";
|
|
2
|
-
import {
|
|
2
|
+
import { MulticastAnalyticsCapability } from "../capabilities/analytics.capability.js";
|
|
3
3
|
import {
|
|
4
4
|
RequestContextSchema
|
|
5
5
|
} from "../schemas/session.schema.js";
|
|
6
|
-
import {
|
|
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
|
|
47
|
+
const mergedProductRecommendations = [];
|
|
35
48
|
for (const factory of this.factories) {
|
|
36
|
-
const
|
|
37
|
-
client =
|
|
38
|
-
|
|
39
|
-
|
|
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 (
|
|
45
|
-
|
|
54
|
+
if (capability.productRecommendations) {
|
|
55
|
+
mergedProductRecommendations.push(capability.productRecommendations);
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
const completeClient = {
|
|
49
59
|
...client,
|
|
50
|
-
analytics: new
|
|
51
|
-
productRecommendations: new
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
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 "./
|
|
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";
|