recombee-api-client 6.1.0 → 6.3.0

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/README.md CHANGED
@@ -37,14 +37,12 @@ const client = new ApiClient(
37
37
 
38
38
  const request = new requests.ListUsers({ count: 10 });
39
39
 
40
- client
41
- .send(request)
42
- .then((result) => {
43
- console.log(result);
44
- })
45
- .catch((error) => {
46
- console.error(error);
47
- });
40
+ try {
41
+ const result = await client.send(request);
42
+ console.log(result);
43
+ } catch (error) {
44
+ console.error(error);
45
+ }
48
46
  ```
49
47
 
50
48
  ```javascript
@@ -89,12 +87,12 @@ async function example() {
89
87
  const response = await client.send(
90
88
  new requests.RecommendItemsToUser("user-25", 5)
91
89
  );
92
- console.log("Recommended items for user-25: %j", response.recomms);
90
+ console.log("Recommended items for user-25:", response.recomms);
93
91
  // User scrolled down - get next 3 recommended items
94
92
  const response2 = await client.send(
95
93
  new requests.RecommendNextItems(response.recommId, 3)
96
94
  );
97
- console.log("Next recommended items for user-25: %j", response2.recomms);
95
+ console.log("Next recommended items for user-25:", response2.recomms);
98
96
  }
99
97
 
100
98
  example();
@@ -121,137 +119,107 @@ const NUM = 100;
121
119
  // - image (url of computer's photo)
122
120
 
123
121
  // Add properties of items
124
- client
125
- .send(
126
- new rqs.Batch([
127
- new rqs.AddItemProperty("price", "double"),
128
- new rqs.AddItemProperty("num-cores", "int"),
129
- new rqs.AddItemProperty("description", "string"),
130
- new rqs.AddItemProperty("time", "timestamp"),
131
- new rqs.AddItemProperty("image", "image"),
132
- ])
133
- )
134
- .then((responses) => {
135
- //Prepare requests for setting a catalog of computers
136
-
137
- var requests = Array.apply(0, Array(NUM)).map((_, i) => {
138
- return new rqs.SetItemValues(
139
- `computer-${i}`, //itemId
140
- //values:
141
- {
142
- price: 600 + 400 * Math.random(),
143
- "num-cores": Math.floor(Math.random() * 8) + 1,
144
- description: "Great computer",
145
- time: new Date().toISOString(),
146
- image: `http://examplesite.com/products/computer-${i}.jpg`,
147
- },
148
- //optional parameters:
149
- {
150
- cascadeCreate: true, // Use cascadeCreate for creating item
151
- // with given itemId, if it doesn't exist
152
- }
153
- );
154
- });
155
- //Send catalog to the recommender system
156
- return client.send(new rqs.Batch(requests));
157
- })
158
- .then((responses) => {
159
- // Generate some random purchases of items by users
160
- const userIds = Array.apply(0, Array(NUM)).map((_, i) => {
161
- return `user-${i}`;
162
- });
163
- const itemIds = Array.apply(0, Array(NUM)).map((_, i) => {
164
- return `computer-${i}`;
165
- });
122
+ await client.send(
123
+ new rqs.Batch([
124
+ new rqs.AddItemProperty("price", "double"),
125
+ new rqs.AddItemProperty("num-cores", "int"),
126
+ new rqs.AddItemProperty("description", "string"),
127
+ new rqs.AddItemProperty("time", "timestamp"),
128
+ new rqs.AddItemProperty("image", "image"),
129
+ ])
130
+ );
166
131
 
167
- // Generate some random purchases of items by users
168
- const PROBABILITY_PURCHASED = 0.1;
169
- const purchases = [];
170
- userIds.forEach((userId) => {
171
- const purchased = itemIds.filter(
172
- () => Math.random() < PROBABILITY_PURCHASED
173
- );
174
- purchased.forEach((itemId) => {
175
- purchases.push(
176
- new rqs.AddPurchase(userId, itemId, { cascadeCreate: true })
177
- );
178
- });
179
- });
180
- // Send purchases to the recommender system
181
- return client.send(new rqs.Batch(purchases));
182
- })
183
- .then((responses) => {
184
- // Get 5 recommendations for user-42, who is currently viewing computer-6
185
- // Recommend only computers that have at least 3 cores
186
- return client.send(
187
- new rqs.RecommendItemsToItem("computer-6", "user-42", 5, {
188
- filter: "'num-cores' >= 3",
189
- })
190
- );
191
- })
192
- .then((recommended) => {
193
- console.log(
194
- "Recommended items with at least 3 processor cores: %j",
195
- recommended
196
- );
197
132
 
198
- // Recommend only items that are more expensive then currently viewed item (up-sell)
199
- return client.send(
200
- new rqs.RecommendItemsToItem("computer-6", "user-42", 5, {
201
- filter: " 'price' > context_item[\"price\"] ",
202
- returnProperties: true,
203
- })
204
- );
205
- })
206
- .then((recommended) => {
207
- console.log("Recommended up-sell items: %j", recommended);
208
-
209
- // Filters, boosters and other settings can be set also in the Admin UI (admin.recombee.com)
210
- // when scenario is specified
211
- return client.send(
212
- new rqs.RecommendItemsToItem("computer-6", "user-42", 5, {
213
- scenario: "product_detail",
214
- })
215
- );
216
- })
217
- .then((recommended) => {
218
- // Perform personalized full-text search with a user's search query (e.g. "computers")
219
- return client.send(
220
- new rqs.SearchItems("user-42", "computers", 5, {
221
- scenario: "search_top",
222
- })
223
- );
224
- })
225
- .then((matched) => {
226
- console.log("Matched items: %j", matched);
227
- })
228
- .catch((error) => {
229
- console.error(error);
230
- // Use fallback
231
- });
232
- ```
133
+ // Prepare requests for setting a catalog of computers
134
+ var requests = Array.apply(0, Array(NUM)).map((_, i) => {
135
+ return new rqs.SetItemValues(
136
+ `computer-${i}`, // itemId
137
+ // values:
138
+ {
139
+ price: 600 + 400 * Math.random(),
140
+ "num-cores": Math.floor(Math.random() * 8) + 1,
141
+ description: "Great computer",
142
+ time: new Date().toISOString(),
143
+ image: `http://examplesite.com/products/computer-${i}.jpg`,
144
+ },
145
+ // optional parameters:
146
+ {
147
+ cascadeCreate: true, // Use cascadeCreate for creating item
148
+ // with given itemId, if it doesn't exist
149
+ }
150
+ );
151
+ });
233
152
 
234
- ## Promises / callbacks
153
+ // Send catalog to the recommender system
154
+ await client.send(new rqs.Batch(requests));
235
155
 
236
- The SDK supports both Promises and callbacks, so you can choose the way which suits your coding style and conventions of your project:
237
156
 
238
- ```javascript
239
- // Using Promises
240
- await client.send(new ListUsers());
241
- // or
242
- client
243
- .send(new ListUsers())
244
- .then((response) => {
245
- // handle response
246
- })
247
- .catch((error) => {
248
- // handle error
249
- });
157
+ // Generate some random purchases of items by users
158
+ const userIds = Array.apply(0, Array(NUM)).map((_, i) => {
159
+ return `user-${i}`;
160
+ });
161
+ const itemIds = Array.apply(0, Array(NUM)).map((_, i) => {
162
+ return `computer-${i}`;
163
+ });
250
164
 
251
- // Using callbacks
252
- client.send(new ListUsers(), (error, response) => {
253
- // handle result
165
+ // Generate some random purchases of items by users
166
+ const PROBABILITY_PURCHASED = 0.1;
167
+ const purchases = [];
168
+ userIds.forEach((userId) => {
169
+ const purchased = itemIds.filter(
170
+ () => Math.random() < PROBABILITY_PURCHASED
171
+ );
172
+ purchased.forEach((itemId) => {
173
+ purchases.push(
174
+ new rqs.AddPurchase(userId, itemId, { cascadeCreate: true })
175
+ );
176
+ });
254
177
  });
178
+ // Send purchases to the recommender system
179
+ await client.send(new rqs.Batch(purchases));
180
+
181
+ // Get 5 recommendations for user-42, who is currently viewing computer-6
182
+ // Recommend only computers that have at least 3 cores
183
+ const recommended = await client.send(
184
+ new rqs.RecommendItemsToItem("computer-6", "user-42", 5, {
185
+ filter: "'num-cores' >= 3",
186
+ })
187
+ );
188
+ console.log(
189
+ "Recommended items with at least 3 processor cores:",
190
+ recommended
191
+ );
192
+
193
+ // Recommend only items that are more expensive then currently viewed item (up-sell)
194
+ const upsell = await client.send(
195
+ new rqs.RecommendItemsToItem("computer-6", "user-42", 5, {
196
+ filter: " 'price' > context_item[\"price\"] ",
197
+ returnProperties: true,
198
+ })
199
+ );
200
+ console.log("Recommended up-sell items:", upsell);
201
+
202
+ // Filters, boosters and other settings can be set also in the Admin UI (admin.recombee.com)
203
+ // when scenario is specified
204
+ const productDetail = await client.send(
205
+ new rqs.RecommendItemsToItem("computer-6", "user-42", 5, {
206
+ scenario: "product_detail",
207
+ })
208
+ );
209
+ console.log("Recommended items for product detail scenario:", productDetail);
210
+
211
+ // Perform personalized full-text search with a user's search query (e.g. "computers")
212
+ try {
213
+ const searchResults = await client.send(
214
+ new rqs.SearchItems("user-42", "computers", 5, {
215
+ scenario: "search_top",
216
+ })
217
+ );
218
+ console.log("Matched items:", searchResults);
219
+ } catch (error) {
220
+ console.error(error);
221
+ // use fallback...
222
+ }
255
223
  ```
256
224
 
257
225
  ## Errors handling
package/lib/api-client.js CHANGED
@@ -43,7 +43,7 @@ class ApiClient {
43
43
  method: request.method,
44
44
  headers: {'Accept': 'application/json',
45
45
  'Content-Type': 'application/json',
46
- 'User-Agent': 'recombee-node-api-client/6.1.0'},
46
+ 'User-Agent': 'recombee-node-api-client/6.3.0'},
47
47
  timeout: request.timeout,
48
48
  agent: this.options.agent
49
49
  };
package/lib/index.d.ts CHANGED
@@ -168,6 +168,8 @@ declare module "recombee-api-client" {
168
168
  statusCode: number,
169
169
  message: string
170
170
  );
171
+
172
+ public readonly statusCode: number;
171
173
  }
172
174
 
173
175
  /**
@@ -294,9 +296,21 @@ declare module "recombee-api-client" {
294
296
  values?: Record<string, EntityProperty>;
295
297
  }
296
298
 
299
+ export type PropertyRole = {
300
+ name: string;
301
+ settings?: Record<string, unknown>;
302
+ }
303
+
304
+ export type PropertyMetadata = {
305
+ name: string;
306
+ settings?: Record<string, unknown>;
307
+ }
308
+
297
309
  export type PropertyInfo = {
298
310
  name: string;
299
311
  type: string;
312
+ role?: PropertyRole;
313
+ metadata?: PropertyMetadata[];
300
314
  }
301
315
 
302
316
  export type UpdateMoreItemsResponse = {
@@ -561,29 +575,40 @@ declare module "recombee-api-client" {
561
575
  /**
562
576
  * @param propertyName - Name of the item property to be created. Currently, the following names are reserved: `id`, `itemid`, case-insensitively. Also, the length of the property name must not exceed 63 characters.
563
577
  * @param type - Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
564
- * * `int`- Signed integer number.
578
+ * * `int` - Signed integer number.
565
579
  * * `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
566
580
  * * `string` - UTF-8 string.
567
581
  * * `boolean` - *true* / *false*
568
- * * `timestamp` - Value representing date and time.
582
+ * * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
569
583
  * * `set` - Set of strings.
570
584
  * * `image` - URL of an image (`jpeg`, `png` or `gif`).
571
- * * `imageList` - List of URLs that refer to images.
585
+ * * `imageList` - List of URLs that refer to images.
586
+ * @param optional - Optional parameters given as an object.
572
587
  */
573
588
  constructor(
574
589
  propertyName: string,
575
590
  type: string,
591
+ optional?: {
592
+ /** [Role](https://docs.recombee.com/api/property_roles_metadata#roles) to assign to the property. */
593
+ role?: string | object;
594
+ /** List of [metadata](https://docs.recombee.com/api/property_roles_metadata#metadata) entries to assign to the property. */
595
+ metadata?: string[];
596
+ }
576
597
  );
577
598
 
578
599
  propertyName: string;
579
600
  type: string;
601
+ role?: string | object;
602
+ metadata?: string[];
580
603
  protected __response_type: string;
581
604
 
582
605
  bodyParameters(): {
606
+ type: string;
607
+ role?: string | object;
608
+ metadata?: string[];
583
609
  };
584
610
 
585
611
  queryParameters(): {
586
- type: string;
587
612
  };
588
613
  }
589
614
 
@@ -1020,23 +1045,34 @@ declare module "recombee-api-client" {
1020
1045
  * * `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
1021
1046
  * * `string` - UTF-8 string.
1022
1047
  * * `boolean` - *true* / *false*
1023
- * * `timestamp` - Value representing date and time.
1048
+ * * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
1024
1049
  * * `set` - Set of strings.
1050
+ * @param optional - Optional parameters given as an object.
1025
1051
  */
1026
1052
  constructor(
1027
1053
  propertyName: string,
1028
1054
  type: string,
1055
+ optional?: {
1056
+ /** [Role](https://docs.recombee.com/api/property_roles_metadata#roles) to assign to the property. */
1057
+ role?: string | object;
1058
+ /** List of [metadata](https://docs.recombee.com/api/property_roles_metadata#metadata) entries to assign to the property. */
1059
+ metadata?: string[];
1060
+ }
1029
1061
  );
1030
1062
 
1031
1063
  propertyName: string;
1032
1064
  type: string;
1065
+ role?: string | object;
1066
+ metadata?: string[];
1033
1067
  protected __response_type: string;
1034
1068
 
1035
1069
  bodyParameters(): {
1070
+ type: string;
1071
+ role?: string | object;
1072
+ metadata?: string[];
1036
1073
  };
1037
1074
 
1038
1075
  queryParameters(): {
1039
- type: string;
1040
1076
  };
1041
1077
  }
1042
1078
 
@@ -2606,7 +2642,43 @@ declare module "recombee-api-client" {
2606
2642
  }
2607
2643
 
2608
2644
  /**
2609
- * Composite Recommendation returns both a *source entity* (e.g., an Item or [Item Segment](https://docs.recombee.com/segmentations.html)) and a list of related recommendations in a single response.
2645
+ * Returns [Item Segments](https://docs.recombee.com/segmentations) to be shown as the next recommendations when a user scrolls (e.g., within a carousel or feed of Item Segments such as brands, artists, topics, or categories).
2646
+ * The request requires the `recommId` of a base recommendation request and the number of Segments to return (`count`).
2647
+ * The base request can be one of:
2648
+ * - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
2649
+ * - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
2650
+ * - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
2651
+ * - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
2652
+ * All other parameters are inherited from the base request associated with the provided `recommId`.
2653
+ * This endpoint can be called multiple times for a single `recommId`. Each call returns different Item Segments that have not been recommended in previous calls.
2654
+ * The number of calls made so far is returned in the `numberNextRecommsCalls` field.
2655
+ * Requests can be made up to 30 minutes after the base request or the most recent Recommend Next Item Segments call.
2656
+ * For billing purposes, each call to this endpoint is counted as a separate recommendation request.
2657
+ */
2658
+ export class RecommendNextItemSegments extends requests.Request {
2659
+ /**
2660
+ * @param recommId - ID of the base recommendation request for which next recommendations should be returned
2661
+ * @param count - Number of item segments to be recommended
2662
+ */
2663
+ constructor(
2664
+ recommId: string,
2665
+ count: number,
2666
+ );
2667
+
2668
+ recommId: string;
2669
+ count: number;
2670
+ protected __response_type: RecommendationResponse;
2671
+
2672
+ bodyParameters(): {
2673
+ count: number;
2674
+ };
2675
+
2676
+ queryParameters(): {
2677
+ };
2678
+ }
2679
+
2680
+ /**
2681
+ * Composite Recommendation returns both a *source entity* (e.g., an Item or [Item Segment](https://docs.recombee.com/segmentations)) and a list of related recommendations in a single response.
2610
2682
  * It is ideal for use cases such as personalized homepage sections (*Articles from <category>*), *Because You Watched <movie>*, or *Artists Related to Your Favorite Artist <artist>*.
2611
2683
  * See detailed **examples and configuration guidance** in the [Composite Scenarios documentation](https://docs.recombee.com/scenarios#composite-recommendations).
2612
2684
  * **Structure**
@@ -2645,6 +2717,8 @@ declare module "recombee-api-client" {
2645
2717
  logic?: string | object;
2646
2718
  /** ID of the segment from `contextSegmentationId` for which the recommendations are to be generated. */
2647
2719
  segmentId?: string;
2720
+ /** Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario. */
2721
+ searchQuery?: string;
2648
2722
  /** If the entity for the source recommendation does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that entity, as the entity will be already known to the system. */
2649
2723
  cascadeCreate?: boolean;
2650
2724
  /** Parameters applied for recommending the *Source* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Source*. */
@@ -2662,6 +2736,7 @@ declare module "recombee-api-client" {
2662
2736
  userId?: string;
2663
2737
  logic?: string | object;
2664
2738
  segmentId?: string;
2739
+ searchQuery?: string;
2665
2740
  cascadeCreate?: boolean;
2666
2741
  sourceSettings?: Record<string, unknown>;
2667
2742
  resultSettings?: Record<string, unknown>;
@@ -2675,6 +2750,7 @@ declare module "recombee-api-client" {
2675
2750
  userId?: string;
2676
2751
  logic?: string | object;
2677
2752
  segmentId?: string;
2753
+ searchQuery?: string;
2678
2754
  cascadeCreate?: boolean;
2679
2755
  sourceSettings?: Record<string, unknown>;
2680
2756
  resultSettings?: Record<string, unknown>;
@@ -14,19 +14,30 @@ class AddItemProperty extends rqs.Request {
14
14
  * Construct the request
15
15
  * @param {string} propertyName - Name of the item property to be created. Currently, the following names are reserved: `id`, `itemid`, case-insensitively. Also, the length of the property name must not exceed 63 characters.
16
16
  * @param {string} type - Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
17
- * * `int`- Signed integer number.
17
+ * * `int` - Signed integer number.
18
18
  * * `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
19
19
  * * `string` - UTF-8 string.
20
20
  * * `boolean` - *true* / *false*
21
- * * `timestamp` - Value representing date and time.
21
+ * * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
22
22
  * * `set` - Set of strings.
23
23
  * * `image` - URL of an image (`jpeg`, `png` or `gif`).
24
- * * `imageList` - List of URLs that refer to images.
24
+ * * `imageList` - List of URLs that refer to images.
25
+ * @param {Object} optional - Optional parameters given as an object with structure name of the parameter: value
26
+ * - Allowed parameters:
27
+ * - *role*
28
+ * - Type: string | object
29
+ * - Description: [Role](https://docs.recombee.com/api/property_roles_metadata#roles) to assign to the property.
30
+ * - *metadata*
31
+ * - Type: string[]
32
+ * - Description: List of [metadata](https://docs.recombee.com/api/property_roles_metadata#metadata) entries to assign to the property.
25
33
  */
26
- constructor(propertyName, type) {
34
+ constructor(propertyName, type, optional) {
27
35
  super('PUT', `/items/properties/${propertyName}`, 100000, false);
28
36
  this.propertyName = propertyName;
29
37
  this.type = type;
38
+ optional = optional || {};
39
+ this.role = optional.role;
40
+ this.metadata = optional.metadata;
30
41
  }
31
42
 
32
43
  /**
@@ -35,6 +46,13 @@ class AddItemProperty extends rqs.Request {
35
46
  */
36
47
  bodyParameters() {
37
48
  let params = {};
49
+ params.type = this.type;
50
+
51
+ if(this.role !== undefined)
52
+ params.role = this.role;
53
+
54
+ if(this.metadata !== undefined)
55
+ params.metadata = this.metadata;
38
56
 
39
57
  return params;
40
58
  }
@@ -45,7 +63,6 @@ class AddItemProperty extends rqs.Request {
45
63
  */
46
64
  queryParameters() {
47
65
  let params = {};
48
- params.type = this.type;
49
66
  return params;
50
67
  }
51
68
  }
@@ -18,13 +18,24 @@ class AddUserProperty extends rqs.Request {
18
18
  * * `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
19
19
  * * `string` - UTF-8 string.
20
20
  * * `boolean` - *true* / *false*
21
- * * `timestamp` - Value representing date and time.
21
+ * * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
22
22
  * * `set` - Set of strings.
23
+ * @param {Object} optional - Optional parameters given as an object with structure name of the parameter: value
24
+ * - Allowed parameters:
25
+ * - *role*
26
+ * - Type: string | object
27
+ * - Description: [Role](https://docs.recombee.com/api/property_roles_metadata#roles) to assign to the property.
28
+ * - *metadata*
29
+ * - Type: string[]
30
+ * - Description: List of [metadata](https://docs.recombee.com/api/property_roles_metadata#metadata) entries to assign to the property.
23
31
  */
24
- constructor(propertyName, type) {
32
+ constructor(propertyName, type, optional) {
25
33
  super('PUT', `/users/properties/${propertyName}`, 100000, false);
26
34
  this.propertyName = propertyName;
27
35
  this.type = type;
36
+ optional = optional || {};
37
+ this.role = optional.role;
38
+ this.metadata = optional.metadata;
28
39
  }
29
40
 
30
41
  /**
@@ -33,6 +44,13 @@ class AddUserProperty extends rqs.Request {
33
44
  */
34
45
  bodyParameters() {
35
46
  let params = {};
47
+ params.type = this.type;
48
+
49
+ if(this.role !== undefined)
50
+ params.role = this.role;
51
+
52
+ if(this.metadata !== undefined)
53
+ params.metadata = this.metadata;
36
54
 
37
55
  return params;
38
56
  }
@@ -43,7 +61,6 @@ class AddUserProperty extends rqs.Request {
43
61
  */
44
62
  queryParameters() {
45
63
  let params = {};
46
- params.type = this.type;
47
64
  return params;
48
65
  }
49
66
  }
@@ -6,7 +6,7 @@
6
6
  const rqs = require("./request");
7
7
 
8
8
  /**
9
- * Composite Recommendation returns both a *source entity* (e.g., an Item or [Item Segment](https://docs.recombee.com/segmentations.html)) and a list of related recommendations in a single response.
9
+ * Composite Recommendation returns both a *source entity* (e.g., an Item or [Item Segment](https://docs.recombee.com/segmentations)) and a list of related recommendations in a single response.
10
10
  * It is ideal for use cases such as personalized homepage sections (*Articles from <category>*), *Because You Watched <movie>*, or *Artists Related to Your Favorite Artist <artist>*.
11
11
  * See detailed **examples and configuration guidance** in the [Composite Scenarios documentation](https://docs.recombee.com/scenarios#composite-recommendations).
12
12
  * **Structure**
@@ -50,6 +50,9 @@ class CompositeRecommendation extends rqs.Request {
50
50
  * - *segmentId*
51
51
  * - Type: string
52
52
  * - Description: ID of the segment from `contextSegmentationId` for which the recommendations are to be generated.
53
+ * - *searchQuery*
54
+ * - Type: string
55
+ * - Description: Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario.
53
56
  * - *cascadeCreate*
54
57
  * - Type: boolean
55
58
  * - Description: If the entity for the source recommendation does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that entity, as the entity will be already known to the system.
@@ -72,6 +75,7 @@ class CompositeRecommendation extends rqs.Request {
72
75
  this.userId = optional.userId;
73
76
  this.logic = optional.logic;
74
77
  this.segmentId = optional.segmentId;
78
+ this.searchQuery = optional.searchQuery;
75
79
  this.cascadeCreate = optional.cascadeCreate;
76
80
  this.sourceSettings = optional.sourceSettings;
77
81
  this.resultSettings = optional.resultSettings;
@@ -99,6 +103,9 @@ class CompositeRecommendation extends rqs.Request {
99
103
  if(this.segmentId !== undefined)
100
104
  params.segmentId = this.segmentId;
101
105
 
106
+ if(this.searchQuery !== undefined)
107
+ params.searchQuery = this.searchQuery;
108
+
102
109
  if(this.cascadeCreate !== undefined)
103
110
  params.cascadeCreate = this.cascadeCreate;
104
111
 
@@ -63,6 +63,7 @@ exports.RecommendUsersToItem = require("./recommend-users-to-item").RecommendUse
63
63
  exports.RecommendItemSegmentsToUser = require("./recommend-item-segments-to-user").RecommendItemSegmentsToUser;
64
64
  exports.RecommendItemSegmentsToItem = require("./recommend-item-segments-to-item").RecommendItemSegmentsToItem;
65
65
  exports.RecommendItemSegmentsToItemSegment = require("./recommend-item-segments-to-item-segment").RecommendItemSegmentsToItemSegment;
66
+ exports.RecommendNextItemSegments = require("./recommend-next-item-segments").RecommendNextItemSegments;
66
67
  exports.CompositeRecommendation = require("./composite-recommendation").CompositeRecommendation;
67
68
  exports.SearchItems = require("./search-items").SearchItems;
68
69
  exports.SearchItemSegments = require("./search-item-segments").SearchItemSegments;
@@ -0,0 +1,56 @@
1
+ /*
2
+ This file is auto-generated, do not edit
3
+ */
4
+
5
+ 'use strict';
6
+ const rqs = require("./request");
7
+
8
+ /**
9
+ * Returns [Item Segments](https://docs.recombee.com/segmentations) to be shown as the next recommendations when a user scrolls (e.g., within a carousel or feed of Item Segments such as brands, artists, topics, or categories).
10
+ * The request requires the `recommId` of a base recommendation request and the number of Segments to return (`count`).
11
+ * The base request can be one of:
12
+ * - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
13
+ * - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
14
+ * - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
15
+ * - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
16
+ * All other parameters are inherited from the base request associated with the provided `recommId`.
17
+ * This endpoint can be called multiple times for a single `recommId`. Each call returns different Item Segments that have not been recommended in previous calls.
18
+ * The number of calls made so far is returned in the `numberNextRecommsCalls` field.
19
+ * Requests can be made up to 30 minutes after the base request or the most recent Recommend Next Item Segments call.
20
+ * For billing purposes, each call to this endpoint is counted as a separate recommendation request.
21
+ */
22
+ class RecommendNextItemSegments extends rqs.Request {
23
+
24
+ /**
25
+ * Construct the request
26
+ * @param {string} recommId - ID of the base recommendation request for which next recommendations should be returned
27
+ * @param {number} count - Number of item segments to be recommended
28
+ */
29
+ constructor(recommId, count) {
30
+ super('POST', `/recomms/next/item-segments/${recommId}`, 3000, false);
31
+ this.recommId = recommId;
32
+ this.count = count;
33
+ }
34
+
35
+ /**
36
+ * Get body parameters
37
+ * @return {Object} The values of body parameters (name of parameter: value of the parameter)
38
+ */
39
+ bodyParameters() {
40
+ let params = {};
41
+ params.count = this.count;
42
+
43
+ return params;
44
+ }
45
+
46
+ /**
47
+ * Get query parameters
48
+ * @return {Object} The values of query parameters (name of parameter: value of the parameter)
49
+ */
50
+ queryParameters() {
51
+ let params = {};
52
+ return params;
53
+ }
54
+ }
55
+
56
+ exports.RecommendNextItemSegments = RecommendNextItemSegments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recombee-api-client",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "description": "Node.js client (SDK) for easy use of the Recombee recommendation API",
5
5
  "main": "index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,7 +25,11 @@ describe('AddItemProperty', function(){
25
25
  new rqs.AddItemProperty('str','string'),
26
26
  new rqs.AddItemProperty('prop','integer'),
27
27
  new rqs.AddItemProperty('number2','int'),
28
- new rqs.AddItemProperty('number2','int')
28
+ new rqs.AddItemProperty('number2','int'),
29
+ new rqs.AddItemProperty('title','string',{'role': 'title'}),
30
+ new rqs.AddItemProperty('str4','string',{'role': 'summary'}),
31
+ new rqs.AddItemProperty('str4','string',{'role': 'summary'}),
32
+ new rqs.AddItemProperty('str5','string',{'role': 'titl'})
29
33
  ];
30
34
 
31
35
  env.client.send(new rqs.Batch(requests))
@@ -35,6 +39,10 @@ describe('AddItemProperty', function(){
35
39
  assert.equal(responses[2].code, 400);
36
40
  assert.equal(responses[3].code, 201);
37
41
  assert.equal(responses[4].code, 409);
42
+ assert.equal(responses[5].code, 201);
43
+ assert.equal(responses[6].code, 201);
44
+ assert.equal(responses[7].code, 409);
45
+ assert.equal(responses[8].code, 404);
38
46
  done();
39
47
  });
40
48
  });
@@ -77,4 +77,49 @@ describe('AddItemProperty', function(){
77
77
  }
78
78
  }));
79
79
  });
80
+
81
+ it ('does not fail with valid property role and metadata', (done) => {
82
+ let req, req2, resp;
83
+ req = new rqs.AddItemProperty('title','string',{'role': 'title'});
84
+ env.client.send(req,((err,res) => {
85
+ if(err) {
86
+ assert.fail();
87
+ }
88
+ else {
89
+ done();
90
+ }
91
+ }));
92
+ });
93
+
94
+ it ('fails with duplicate property role or invalid metadata', (done) => {
95
+ let req, req2, resp;
96
+ req = new rqs.AddItemProperty('str4','string',{'role': 'summary'});
97
+ env.client.send(req,((err,res) => {
98
+ if(err) {
99
+ assert.fail();
100
+ }
101
+ else {
102
+ env.client.send(req,((err,res) => {
103
+ if(err) {
104
+ assert.equal(err.name, 'ResponseError');
105
+ assert.equal(err.statusCode, 409);
106
+ req = new rqs.AddItemProperty('str5','string',{'role': 'titl'});
107
+ env.client.send(req,((err,res) => {
108
+ if(err) {
109
+ assert.equal(err.name, 'ResponseError');
110
+ assert.equal(err.statusCode, 404);
111
+ done();
112
+ }
113
+ else {
114
+ assert.fail();
115
+ }
116
+ }));
117
+ }
118
+ else {
119
+ assert.fail();
120
+ }
121
+ }));
122
+ }
123
+ }));
124
+ });
80
125
  });
@@ -69,4 +69,45 @@ describe('AddItemProperty', function(){
69
69
  });
70
70
  });
71
71
  });
72
+
73
+ it ('does not fail with valid property role and metadata', (done) => {
74
+ let req, req2, resp;
75
+ req = new rqs.AddItemProperty('title','string',{'role': 'title'});
76
+ env.client.send(req)
77
+ .then((res) => {
78
+ done();
79
+ });
80
+ });
81
+
82
+ it ('fails with duplicate property role or invalid metadata', (done) => {
83
+ let req, req2, resp;
84
+ req = new rqs.AddItemProperty('str4','string',{'role': 'summary'});
85
+ env.client.send(req)
86
+ .then((res) => {
87
+ env.client.send(req)
88
+ .then((res) => {
89
+ assert.fail();
90
+ req = new rqs.AddItemProperty('str5','string',{'role': 'titl'});
91
+ env.client.send(req)
92
+ .then((res) => {
93
+ assert.fail();
94
+ done();
95
+ })
96
+ .catch((err) => {
97
+ if (err instanceof recombee.errors.ResponseError) {
98
+ assert.equal(err.statusCode, 404);
99
+ done();
100
+ }
101
+ throw err;
102
+ });
103
+ })
104
+ .catch((err) => {
105
+ if (err instanceof recombee.errors.ResponseError) {
106
+ assert.equal(err.statusCode, 409);
107
+ done();
108
+ }
109
+ throw err;
110
+ });
111
+ });
112
+ });
72
113
  });
@@ -0,0 +1,48 @@
1
+ /*
2
+ This file is auto-generated, do not edit
3
+ */
4
+
5
+ 'use strict'
6
+ var assert = require('chai').assert;
7
+ var recombee = require('./../index.js');
8
+ var rqs = recombee.requests;
9
+
10
+ var env = require('./set-environment.js');
11
+
12
+ describe('RecommendNextItemSegments', function(){
13
+ this.timeout(150000);
14
+
15
+ before(function(done){
16
+
17
+ env.setEnvironment()
18
+ .then(()=> {
19
+ done();
20
+ });
21
+ });
22
+ it ('works in batch', (done) => {
23
+ env.client.send(new rqs.RecommendNextItemSegments('invalid_recomm_id',5),((err,errRes) => {
24
+ if(err) {
25
+ assert.equal(err.statusCode, 400);
26
+ env.client.send(new rqs.RecommendItemsToUser('entity_id',3),((err,res) => {
27
+ if(err) {
28
+ assert.fail();
29
+ }
30
+ else {
31
+ let requests = [
32
+ new rqs.RecommendNextItemSegments(res['recommId'],5)
33
+ ];
34
+
35
+ env.client.send(new rqs.Batch(requests))
36
+ .then((responses) => {
37
+ assert.equal(responses[0].code, 400);
38
+ done();
39
+ });
40
+ }
41
+ }));
42
+ }
43
+ else {
44
+ assert.fail();
45
+ }
46
+ }));
47
+ });
48
+ });
@@ -0,0 +1,60 @@
1
+ /*
2
+ This file is auto-generated, do not edit
3
+ */
4
+
5
+ 'use strict'
6
+ var assert = require('chai').assert;
7
+ var recombee = require('./../index.js');
8
+ var rqs = recombee.requests;
9
+
10
+ var env = require('./set-environment.js');
11
+
12
+ describe('RecommendNextItemSegments', function(){
13
+ this.timeout(150000);
14
+
15
+ before(function(done){
16
+
17
+ env.setEnvironment()
18
+ .then(()=> {
19
+ done();
20
+ });
21
+ });
22
+
23
+ it ('rejects request with invalid recommId', (done) => {
24
+ let req, req2, resp;
25
+ req2 = new rqs.RecommendNextItemSegments('invalid_recomm_id',5);
26
+ env.client.send(req2,((err,res) => {
27
+ if(err) {
28
+ assert.equal(err.name, 'ResponseError');
29
+ assert.equal(err.statusCode, 400);
30
+ done();
31
+ }
32
+ else {
33
+ assert.fail();
34
+ }
35
+ }));
36
+ });
37
+
38
+ it ('rejects request to recommId which does not return item-segments', (done) => {
39
+ let req, req2, resp;
40
+ req2 = new rqs.RecommendItemsToUser('entity_id',3);
41
+ env.client.send(req2,((err,res) => {
42
+ if(err) {
43
+ assert.fail();
44
+ }
45
+ else {
46
+ req = new rqs.RecommendNextItemSegments(res['recommId'],5);
47
+ env.client.send(req,((err,res) => {
48
+ if(err) {
49
+ assert.equal(err.name, 'ResponseError');
50
+ assert.equal(err.statusCode, 400);
51
+ done();
52
+ }
53
+ else {
54
+ assert.fail();
55
+ }
56
+ }));
57
+ }
58
+ }));
59
+ });
60
+ });
@@ -0,0 +1,60 @@
1
+ /*
2
+ This file is auto-generated, do not edit
3
+ */
4
+
5
+ 'use strict'
6
+ var assert = require('chai').assert;
7
+ var recombee = require('./../index.js');
8
+ var rqs = recombee.requests;
9
+
10
+ var env = require('./set-environment.js');
11
+
12
+ describe('RecommendNextItemSegments', function(){
13
+ this.timeout(150000);
14
+
15
+ before(function(done){
16
+
17
+ env.setEnvironment()
18
+ .then(()=> {
19
+ done();
20
+ });
21
+ });
22
+
23
+ it ('rejects request with invalid recommId', (done) => {
24
+ let req, req2, resp;
25
+ req2 = new rqs.RecommendNextItemSegments('invalid_recomm_id',5);
26
+ env.client.send(req2)
27
+ .then((res) => {
28
+ assert.fail();
29
+ done();
30
+ })
31
+ .catch((err) => {
32
+ if (err instanceof recombee.errors.ResponseError) {
33
+ assert.equal(err.statusCode, 400);
34
+ done();
35
+ }
36
+ throw err;
37
+ });
38
+ });
39
+
40
+ it ('rejects request to recommId which does not return item-segments', (done) => {
41
+ let req, req2, resp;
42
+ req2 = new rqs.RecommendItemsToUser('entity_id',3);
43
+ env.client.send(req2)
44
+ .then((res) => {
45
+ req = new rqs.RecommendNextItemSegments(res['recommId'],5);
46
+ env.client.send(req)
47
+ .then((res) => {
48
+ assert.fail();
49
+ done();
50
+ })
51
+ .catch((err) => {
52
+ if (err instanceof recombee.errors.ResponseError) {
53
+ assert.equal(err.statusCode, 400);
54
+ done();
55
+ }
56
+ throw err;
57
+ });
58
+ });
59
+ });
60
+ });