@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.
- 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/{providers/product-search.provider.js → capabilities/product-search.capability.js} +3 -3
- 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 +16 -14
- package/decorators/reactionary.decorator.js +30 -32
- package/index.js +1 -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} +2 -2
- package/src/{providers/category.provider.d.ts → capabilities/category.capability.d.ts} +4 -4
- package/src/{providers/checkout.provider.d.ts → capabilities/checkout.capability.d.ts} +2 -2
- package/src/{providers/identity.provider.d.ts → capabilities/identity.capability.d.ts} +2 -2
- package/src/capabilities/index.d.ts +18 -0
- package/src/{providers/inventory.provider.d.ts → capabilities/inventory.capability.d.ts} +2 -2
- package/src/{providers/order-search.provider.d.ts → capabilities/order-search.capability.d.ts} +2 -2
- package/src/{providers/order.provider.d.ts → capabilities/order.capability.d.ts} +2 -2
- package/src/{providers/price.provider.d.ts → capabilities/price.capability.d.ts} +2 -2
- package/src/{providers/product-associations.provider.d.ts → capabilities/product-associations.capability.d.ts} +2 -2
- package/src/{providers/product-list.provider.d.ts → capabilities/product-list.capability.d.ts} +2 -2
- 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} +2 -2
- package/src/{providers/product-search.provider.d.ts → capabilities/product-search.capability.d.ts} +2 -2
- package/src/{providers/product.provider.d.ts → capabilities/product.capability.d.ts} +2 -2
- package/src/{providers/profile.provider.d.ts → capabilities/profile.capability.d.ts} +2 -2
- package/src/{providers/store.provider.d.ts → capabilities/store.capability.d.ts} +2 -2
- package/src/client/client-builder.d.ts +1 -1
- package/src/client/client.d.ts +29 -29
- package/src/decorators/reactionary.decorator.d.ts +5 -5
- package/src/index.d.ts +1 -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/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
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
class
|
|
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
|
-
|
|
14
|
+
ProductSearchCapability
|
|
15
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,13 +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
|
-
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
|
|
47
|
+
const mergedProductRecommendations = [];
|
|
46
48
|
for (const factory of this.factories) {
|
|
47
|
-
const
|
|
48
|
-
client = this.
|
|
49
|
-
if (
|
|
50
|
-
mergedAnalytics.push(
|
|
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 (
|
|
53
|
-
|
|
54
|
+
if (capability.productRecommendations) {
|
|
55
|
+
mergedProductRecommendations.push(capability.productRecommendations);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
const completeClient = {
|
|
57
59
|
...client,
|
|
58
|
-
analytics: new
|
|
59
|
-
productRecommendations: new
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|
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 "./
|
|
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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
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
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"@
|
|
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 {
|
|
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
|
|
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
|
|
15
|
-
protected
|
|
16
|
-
constructor(cache: Cache, requestContext: RequestContext,
|
|
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
|
|
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
|
|
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 {
|
|
7
|
+
import { BaseCapability } from "./base.capability.js";
|
|
8
8
|
/**
|
|
9
9
|
* @group Providers
|
|
10
10
|
*/
|
|
11
|
-
export declare abstract class
|
|
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 {
|
|
3
|
+
import { BaseCapability } from "./base.capability.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* CategoryCapability
|
|
6
6
|
*
|
|
7
|
-
* This
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
6
|
-
export declare abstract class
|
|
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 {
|
|
7
|
-
export declare abstract class
|
|
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;
|
package/src/{providers/order-search.provider.d.ts → capabilities/order-search.capability.d.ts}
RENAMED
|
@@ -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 {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
4
|
-
export declare abstract class
|
|
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 {
|
|
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
|
|
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:
|
package/src/{providers/product-list.provider.d.ts → capabilities/product-list.capability.d.ts}
RENAMED
|
@@ -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 {
|
|
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
|
|
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 {
|
|
5
|
-
export declare abstract class
|
|
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
|
|
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
|
|
28
|
-
protected
|
|
29
|
-
constructor(cache: Cache, requestContext: RequestContext,
|
|
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
|
}
|
package/src/{providers/product-reviews.provider.d.ts → capabilities/product-reviews.capability.d.ts}
RENAMED
|
@@ -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 {
|
|
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
|
|
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
|
*
|
package/src/{providers/product-search.provider.d.ts → capabilities/product-search.capability.d.ts}
RENAMED
|
@@ -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 {
|
|
5
|
-
export declare abstract class
|
|
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 {
|
|
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
|
|
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 {
|
|
7
|
-
export declare abstract class
|
|
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 {
|
|
5
|
-
export declare abstract class
|
|
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
|
}
|
package/src/client/client.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
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 {
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import type {
|
|
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:
|
|
16
|
-
productSearch:
|
|
17
|
-
productRecommendations:
|
|
18
|
-
productAssociations:
|
|
19
|
-
productReviews:
|
|
20
|
-
productList:
|
|
21
|
-
identity:
|
|
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:
|
|
24
|
-
checkout:
|
|
25
|
-
analytics:
|
|
26
|
-
price:
|
|
27
|
-
inventory:
|
|
28
|
-
category:
|
|
29
|
-
profile:
|
|
30
|
-
store:
|
|
31
|
-
order:
|
|
32
|
-
orderSearch:
|
|
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 {
|
|
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
|
|
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
|
|
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
|
-
*
|
|
44
|
+
* capabilities.
|
|
45
45
|
*/
|
|
46
|
-
export declare function Reactionary(options: Partial<ReactionaryDecoratorOptions>): (target:
|
|
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 './
|
|
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';
|
package/providers/index.js
DELETED
|
@@ -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";
|
package/src/providers/index.d.ts
DELETED
|
@@ -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';
|