@reactionary/source 0.3.3 → 0.3.4

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.
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reactionary/examples-node",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.3.3",
8
- "@reactionary/provider-commercetools": "0.3.3",
9
- "@reactionary/provider-algolia": "0.3.3",
10
- "@reactionary/provider-medusa": "0.3.3",
11
- "@reactionary/provider-meilisearch": "0.3.3"
7
+ "@reactionary/core": "0.3.4",
8
+ "@reactionary/provider-commercetools": "0.3.4",
9
+ "@reactionary/provider-algolia": "0.3.4",
10
+ "@reactionary/provider-medusa": "0.3.4",
11
+ "@reactionary/provider-meilisearch": "0.3.4"
12
12
  },
13
13
  "type": "module"
14
14
  }
@@ -94,3 +94,47 @@ describe.each([PrimaryProvider.MEILISEARCH])(
94
94
  expect(result.value.length).toBe(0);
95
95
  });
96
96
  });
97
+
98
+
99
+
100
+ describe.each([PrimaryProvider.ALGOLIA])(
101
+ 'Product Recommendations - Related - %s',
102
+ (provider) => {
103
+ let client: ReturnType<typeof createClient>;
104
+
105
+ beforeEach(() => {
106
+ client = createClient(provider);
107
+ });
108
+
109
+ it('should be able to return a list of products for recommendation - Related ', async () => {
110
+ const result = await client.productRecommendations.getRecommendations({
111
+ algorithm: 'related',
112
+ sourceProduct: {
113
+ key: testData.product.id,
114
+ },
115
+ numberOfRecommendations: 10,
116
+ });
117
+
118
+ if (!result.success) {
119
+ assert.fail(JSON.stringify(result.error));
120
+ }
121
+
122
+ expect(result.value.length).toBeGreaterThan(0);
123
+ });
124
+
125
+ it('should return an empty result for an unknown sku', async () => {
126
+ const result = await client.productRecommendations.getRecommendations({
127
+ algorithm: 'related',
128
+ sourceProduct: {
129
+ key: 'unknown-product-id',
130
+ },
131
+ numberOfRecommendations: 10,
132
+ });
133
+
134
+ if (!result.success) {
135
+ assert.fail(JSON.stringify(result.error));
136
+ }
137
+
138
+ expect(result.value.length).toBe(0);
139
+ });
140
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/source",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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.23.4",
19
+ "algoliasearch": "^5.48.0",
20
20
  "debug": "^4.4.3",
21
21
  "dotenv": "^17.2.2",
22
22
  "meilisearch": "^0.55.0",
@@ -5,7 +5,7 @@
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
7
  "@reactionary/core": "0.0.1",
8
- "algoliasearch": "^5.23.4",
8
+ "algoliasearch": "^5.48.0",
9
9
  "zod": "4.1.9"
10
10
  },
11
11
  "type": "module",
@@ -9,7 +9,16 @@ import {
9
9
  type RequestContext,
10
10
  type ProductRecommendationsQuery,
11
11
  } from '@reactionary/core';
12
- import { recommendClient, type BoughtTogetherQuery, type LookingSimilarQuery, type RecommendationsResults, type RecommendClient, type RecommendSearchParams, type RelatedQuery, type TrendingItemsQuery } from 'algoliasearch';
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,