@reactionary/source 0.3.3 → 0.3.5
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/examples/node/package.json +6 -6
- package/examples/node/src/capabilities/product-recommendations.spec.ts +46 -0
- package/package.json +2 -2
- package/providers/algolia/package.json +1 -1
- package/providers/algolia/src/providers/product-recommendations.provider.ts +16 -14
- package/providers/meilisearch/src/providers/product-recommendations.provider.ts +3 -3
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/examples-node",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@reactionary/core": "0.3.
|
|
8
|
-
"@reactionary/provider-commercetools": "0.3.
|
|
9
|
-
"@reactionary/provider-algolia": "0.3.
|
|
10
|
-
"@reactionary/provider-medusa": "0.3.
|
|
11
|
-
"@reactionary/provider-meilisearch": "0.3.
|
|
7
|
+
"@reactionary/core": "0.3.5",
|
|
8
|
+
"@reactionary/provider-commercetools": "0.3.5",
|
|
9
|
+
"@reactionary/provider-algolia": "0.3.5",
|
|
10
|
+
"@reactionary/provider-medusa": "0.3.5",
|
|
11
|
+
"@reactionary/provider-meilisearch": "0.3.5"
|
|
12
12
|
},
|
|
13
13
|
"type": "module"
|
|
14
14
|
}
|
|
@@ -76,6 +76,8 @@ describe.each([PrimaryProvider.MEILISEARCH])(
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
expect(result.value.length).toBeGreaterThan(0);
|
|
79
|
+
expect(result.value[0].product.key).toBeDefined();
|
|
80
|
+
expect(result.value[0].recommendationIdentifier.key).toBeDefined();
|
|
79
81
|
});
|
|
80
82
|
|
|
81
83
|
it('should return an empty result for an unknown sku', async () => {
|
|
@@ -94,3 +96,47 @@ describe.each([PrimaryProvider.MEILISEARCH])(
|
|
|
94
96
|
expect(result.value.length).toBe(0);
|
|
95
97
|
});
|
|
96
98
|
});
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
describe.each([PrimaryProvider.ALGOLIA])(
|
|
103
|
+
'Product Recommendations - Related - %s',
|
|
104
|
+
(provider) => {
|
|
105
|
+
let client: ReturnType<typeof createClient>;
|
|
106
|
+
|
|
107
|
+
beforeEach(() => {
|
|
108
|
+
client = createClient(provider);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should be able to return a list of products for recommendation - Related ', async () => {
|
|
112
|
+
const result = await client.productRecommendations.getRecommendations({
|
|
113
|
+
algorithm: 'related',
|
|
114
|
+
sourceProduct: {
|
|
115
|
+
key: testData.product.id,
|
|
116
|
+
},
|
|
117
|
+
numberOfRecommendations: 10,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (!result.success) {
|
|
121
|
+
assert.fail(JSON.stringify(result.error));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
expect(result.value.length).toBeGreaterThan(0);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should return an empty result for an unknown sku', async () => {
|
|
128
|
+
const result = await client.productRecommendations.getRecommendations({
|
|
129
|
+
algorithm: 'related',
|
|
130
|
+
sourceProduct: {
|
|
131
|
+
key: 'unknown-product-id',
|
|
132
|
+
},
|
|
133
|
+
numberOfRecommendations: 10,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (!result.success) {
|
|
137
|
+
assert.fail(JSON.stringify(result.error));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
expect(result.value.length).toBe(0);
|
|
141
|
+
});
|
|
142
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/source",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"private": false,
|
|
6
6
|
"dependencies": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@opentelemetry/sdk-trace-base": "^2.0.1",
|
|
17
17
|
"@opentelemetry/sdk-trace-node": "^2.0.1",
|
|
18
18
|
"@upstash/redis": "^1.34.9",
|
|
19
|
-
"algoliasearch": "^5.
|
|
19
|
+
"algoliasearch": "^5.48.0",
|
|
20
20
|
"debug": "^4.4.3",
|
|
21
21
|
"dotenv": "^17.2.2",
|
|
22
22
|
"meilisearch": "^0.55.0",
|
|
@@ -9,7 +9,16 @@ import {
|
|
|
9
9
|
type RequestContext,
|
|
10
10
|
type ProductRecommendationsQuery,
|
|
11
11
|
} from '@reactionary/core';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
liteClient,
|
|
14
|
+
type BoughtTogetherQuery,
|
|
15
|
+
type LookingSimilarQuery,
|
|
16
|
+
type RecommendationsResults,
|
|
17
|
+
type RecommendSearchParams,
|
|
18
|
+
type RelatedQuery,
|
|
19
|
+
type TrendingItemsQuery,
|
|
20
|
+
type LiteClient
|
|
21
|
+
} from 'algoliasearch/lite';
|
|
13
22
|
import type { AlgoliaConfiguration } from '../schema/configuration.schema.js';
|
|
14
23
|
import type { AlgoliaProductRecommendationIdentifier } from '../schema/product-recommendation.schema.js';
|
|
15
24
|
|
|
@@ -34,14 +43,12 @@ interface AlgoliaRecommendHit {
|
|
|
34
43
|
|
|
35
44
|
export class AlgoliaProductRecommendationsProvider extends ProductRecommendationsProvider {
|
|
36
45
|
protected config: AlgoliaConfiguration;
|
|
46
|
+
protected client: LiteClient;
|
|
37
47
|
|
|
38
48
|
constructor(config: AlgoliaConfiguration, cache: Cache, context: RequestContext) {
|
|
39
49
|
super(cache, context);
|
|
40
50
|
this.config = config;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
protected getRecommendClient(): RecommendClient {
|
|
44
|
-
return recommendClient(this.config.appId, this.config.apiKey);
|
|
51
|
+
this.client = liteClient(this.config.appId, this.config.apiKey);
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -66,12 +73,11 @@ export class AlgoliaProductRecommendationsProvider extends ProductRecommendation
|
|
|
66
73
|
protected override async getFrequentlyBoughtTogetherRecommendations(
|
|
67
74
|
query: ProductRecommendationAlgorithmFrequentlyBoughtTogetherQuery
|
|
68
75
|
): Promise<ProductRecommendation[]> {
|
|
69
|
-
const client = this.getRecommendClient();
|
|
70
76
|
|
|
71
77
|
try {
|
|
72
78
|
// Note: Algolia's Recommend API requires setting up AI Recommend models
|
|
73
79
|
// This implementation uses the getRecommendations method from the recommend client
|
|
74
|
-
const response = await client.getRecommendations({
|
|
80
|
+
const response = await this.client.getRecommendations({
|
|
75
81
|
requests: [
|
|
76
82
|
{
|
|
77
83
|
indexName: this.config.indexName,
|
|
@@ -104,10 +110,9 @@ export class AlgoliaProductRecommendationsProvider extends ProductRecommendation
|
|
|
104
110
|
protected override async getSimilarProductsRecommendations(
|
|
105
111
|
query: ProductRecommendationAlgorithmSimilarProductsQuery
|
|
106
112
|
): Promise<ProductRecommendation[]> {
|
|
107
|
-
const client = this.getRecommendClient();
|
|
108
113
|
|
|
109
114
|
try {
|
|
110
|
-
const response = await client.getRecommendations({
|
|
115
|
+
const response = await this.client.getRecommendations({
|
|
111
116
|
requests: [
|
|
112
117
|
{
|
|
113
118
|
indexName: this.config.indexName,
|
|
@@ -139,10 +144,9 @@ export class AlgoliaProductRecommendationsProvider extends ProductRecommendation
|
|
|
139
144
|
protected override async getRelatedProductsRecommendations(
|
|
140
145
|
query: ProductRecommendationAlgorithmRelatedProductsQuery
|
|
141
146
|
): Promise<ProductRecommendation[]> {
|
|
142
|
-
const client = this.getRecommendClient();
|
|
143
147
|
|
|
144
148
|
try {
|
|
145
|
-
const response = await client.getRecommendations({
|
|
149
|
+
const response = await this.client.getRecommendations({
|
|
146
150
|
requests: [
|
|
147
151
|
{
|
|
148
152
|
indexName: this.config.indexName,
|
|
@@ -174,10 +178,8 @@ export class AlgoliaProductRecommendationsProvider extends ProductRecommendation
|
|
|
174
178
|
protected override async getTrendingInCategoryRecommendations(
|
|
175
179
|
query: ProductRecommendationAlgorithmTrendingInCategoryQuery
|
|
176
180
|
): Promise<ProductRecommendation[]> {
|
|
177
|
-
const client = this.getRecommendClient();
|
|
178
|
-
|
|
179
181
|
try {
|
|
180
|
-
const response = await client.getRecommendations({
|
|
182
|
+
const response = await this.client.getRecommendations({
|
|
181
183
|
requests: [
|
|
182
184
|
{
|
|
183
185
|
indexName: this.config.indexName,
|
|
@@ -12,7 +12,7 @@ import { MeiliSearch, type Hits, type RecordAny, type SearchParams, type SearchR
|
|
|
12
12
|
import type { MeilisearchConfiguration } from '../schema/configuration.schema.js';
|
|
13
13
|
|
|
14
14
|
interface MeilisearchRecommendHit {
|
|
15
|
-
|
|
15
|
+
objectID: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -78,11 +78,11 @@ export class MeilisearchProductRecommendationsProvider extends ProductRecommenda
|
|
|
78
78
|
protected parseRecommendations(recommendation: SearchResponse<MeilisearchRecommendHit>, algorithm: string): ProductRecommendation[] {
|
|
79
79
|
return recommendation.hits.map((hit) => ({
|
|
80
80
|
recommendationIdentifier: {
|
|
81
|
-
key: hit.
|
|
81
|
+
key: hit.objectID,
|
|
82
82
|
algorithm,
|
|
83
83
|
},
|
|
84
84
|
product: {
|
|
85
|
-
key: hit.
|
|
85
|
+
key: hit.objectID,
|
|
86
86
|
},
|
|
87
87
|
}));
|
|
88
88
|
}
|