recombee-api-client 6.0.0 → 6.2.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 +102 -134
- package/lib/api-client.js +1 -1
- package/lib/index.d.ts +59 -1
- package/lib/requests/composite-recommendation.js +8 -1
- package/lib/requests/index.js +1 -0
- package/lib/requests/recommend-item-segments-to-item-segment.js +39 -0
- package/lib/requests/recommend-item-segments-to-item.js +39 -0
- package/lib/requests/recommend-item-segments-to-user.js +39 -0
- package/lib/requests/recommend-next-item-segments.js +56 -0
- package/lib/requests/search-item-segments.js +39 -0
- package/package.json +1 -1
- package/test/recommend-next-item-segments-batch_test.js +48 -0
- package/test/recommend-next-item-segments-callback_test.js +60 -0
- package/test/recommend-next-item-segments-test.js +60 -0
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
|
-
|
|
41
|
-
.send(request)
|
|
42
|
-
.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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:
|
|
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:
|
|
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
|
-
.
|
|
126
|
-
new rqs.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
//
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
//
|
|
252
|
-
|
|
253
|
-
|
|
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.
|
|
46
|
+
'User-Agent': 'recombee-node-api-client/6.2.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
|
/**
|
|
@@ -2404,6 +2406,8 @@ declare module "recombee-api-client" {
|
|
|
2404
2406
|
expertSettings?: Record<string, unknown>;
|
|
2405
2407
|
/** If there is a custom AB-testing running, return the name of the group to which the request belongs. */
|
|
2406
2408
|
returnAbGroup?: boolean;
|
|
2409
|
+
/** A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment. */
|
|
2410
|
+
reqlExpressions?: Record<string, string>;
|
|
2407
2411
|
}
|
|
2408
2412
|
);
|
|
2409
2413
|
|
|
@@ -2416,6 +2420,7 @@ declare module "recombee-api-client" {
|
|
|
2416
2420
|
logic?: string | object;
|
|
2417
2421
|
expertSettings?: Record<string, unknown>;
|
|
2418
2422
|
returnAbGroup?: boolean;
|
|
2423
|
+
reqlExpressions?: Record<string, string>;
|
|
2419
2424
|
protected __response_type: RecommendationResponse;
|
|
2420
2425
|
|
|
2421
2426
|
bodyParameters(): {
|
|
@@ -2427,6 +2432,7 @@ declare module "recombee-api-client" {
|
|
|
2427
2432
|
logic?: string | object;
|
|
2428
2433
|
expertSettings?: Record<string, unknown>;
|
|
2429
2434
|
returnAbGroup?: boolean;
|
|
2435
|
+
reqlExpressions?: Record<string, string>;
|
|
2430
2436
|
};
|
|
2431
2437
|
|
|
2432
2438
|
queryParameters(): {
|
|
@@ -2482,6 +2488,8 @@ declare module "recombee-api-client" {
|
|
|
2482
2488
|
expertSettings?: Record<string, unknown>;
|
|
2483
2489
|
/** If there is a custom AB-testing running, return the name of the group to which the request belongs. */
|
|
2484
2490
|
returnAbGroup?: boolean;
|
|
2491
|
+
/** A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment. */
|
|
2492
|
+
reqlExpressions?: Record<string, string>;
|
|
2485
2493
|
}
|
|
2486
2494
|
);
|
|
2487
2495
|
|
|
@@ -2495,6 +2503,7 @@ declare module "recombee-api-client" {
|
|
|
2495
2503
|
logic?: string | object;
|
|
2496
2504
|
expertSettings?: Record<string, unknown>;
|
|
2497
2505
|
returnAbGroup?: boolean;
|
|
2506
|
+
reqlExpressions?: Record<string, string>;
|
|
2498
2507
|
protected __response_type: RecommendationResponse;
|
|
2499
2508
|
|
|
2500
2509
|
bodyParameters(): {
|
|
@@ -2507,6 +2516,7 @@ declare module "recombee-api-client" {
|
|
|
2507
2516
|
logic?: string | object;
|
|
2508
2517
|
expertSettings?: Record<string, unknown>;
|
|
2509
2518
|
returnAbGroup?: boolean;
|
|
2519
|
+
reqlExpressions?: Record<string, string>;
|
|
2510
2520
|
};
|
|
2511
2521
|
|
|
2512
2522
|
queryParameters(): {
|
|
@@ -2561,6 +2571,8 @@ declare module "recombee-api-client" {
|
|
|
2561
2571
|
expertSettings?: Record<string, unknown>;
|
|
2562
2572
|
/** If there is a custom AB-testing running, return the name of the group to which the request belongs. */
|
|
2563
2573
|
returnAbGroup?: boolean;
|
|
2574
|
+
/** A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment. */
|
|
2575
|
+
reqlExpressions?: Record<string, string>;
|
|
2564
2576
|
}
|
|
2565
2577
|
);
|
|
2566
2578
|
|
|
@@ -2574,6 +2586,7 @@ declare module "recombee-api-client" {
|
|
|
2574
2586
|
logic?: string | object;
|
|
2575
2587
|
expertSettings?: Record<string, unknown>;
|
|
2576
2588
|
returnAbGroup?: boolean;
|
|
2589
|
+
reqlExpressions?: Record<string, string>;
|
|
2577
2590
|
protected __response_type: RecommendationResponse;
|
|
2578
2591
|
|
|
2579
2592
|
bodyParameters(): {
|
|
@@ -2587,6 +2600,7 @@ declare module "recombee-api-client" {
|
|
|
2587
2600
|
logic?: string | object;
|
|
2588
2601
|
expertSettings?: Record<string, unknown>;
|
|
2589
2602
|
returnAbGroup?: boolean;
|
|
2603
|
+
reqlExpressions?: Record<string, string>;
|
|
2590
2604
|
};
|
|
2591
2605
|
|
|
2592
2606
|
queryParameters(): {
|
|
@@ -2594,7 +2608,43 @@ declare module "recombee-api-client" {
|
|
|
2594
2608
|
}
|
|
2595
2609
|
|
|
2596
2610
|
/**
|
|
2597
|
-
*
|
|
2611
|
+
* Returns Item segments that shall be shown to a user as next recommendations when the user e.g. scrolls the page down (*infinite scroll*) or goes to the next page.
|
|
2612
|
+
* It accepts `recommId` of a base recommendation request (e.g., request from the first page) and the number of segments that shall be returned (`count`).
|
|
2613
|
+
* The base request can be one of:
|
|
2614
|
+
* - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
|
|
2615
|
+
* - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
|
|
2616
|
+
* - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
|
|
2617
|
+
* - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
|
|
2618
|
+
* All the other parameters are inherited from the base request.
|
|
2619
|
+
* *Recommend next Item segments* can be called many times for a single `recommId` and each call returns different (previously not recommended) segments.
|
|
2620
|
+
* The number of *Recommend next Item segments* calls performed so far is returned in the `numberNextRecommsCalls` field.
|
|
2621
|
+
* *Recommend next Item segments* can be requested up to 30 minutes after the base request or a previous *Recommend next Item segments* call.
|
|
2622
|
+
* For billing purposes, each call to *Recommend next Item segments* is counted as a separate recommendation request.
|
|
2623
|
+
*/
|
|
2624
|
+
export class RecommendNextItemSegments extends requests.Request {
|
|
2625
|
+
/**
|
|
2626
|
+
* @param recommId - ID of the base recommendation request for which next recommendations should be returned
|
|
2627
|
+
* @param count - Number of item segments to be recommended
|
|
2628
|
+
*/
|
|
2629
|
+
constructor(
|
|
2630
|
+
recommId: string,
|
|
2631
|
+
count: number,
|
|
2632
|
+
);
|
|
2633
|
+
|
|
2634
|
+
recommId: string;
|
|
2635
|
+
count: number;
|
|
2636
|
+
protected __response_type: RecommendationResponse;
|
|
2637
|
+
|
|
2638
|
+
bodyParameters(): {
|
|
2639
|
+
count: number;
|
|
2640
|
+
};
|
|
2641
|
+
|
|
2642
|
+
queryParameters(): {
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
/**
|
|
2647
|
+
* 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.
|
|
2598
2648
|
* 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>*.
|
|
2599
2649
|
* See detailed **examples and configuration guidance** in the [Composite Scenarios documentation](https://docs.recombee.com/scenarios#composite-recommendations).
|
|
2600
2650
|
* **Structure**
|
|
@@ -2633,6 +2683,8 @@ declare module "recombee-api-client" {
|
|
|
2633
2683
|
logic?: string | object;
|
|
2634
2684
|
/** ID of the segment from `contextSegmentationId` for which the recommendations are to be generated. */
|
|
2635
2685
|
segmentId?: string;
|
|
2686
|
+
/** Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario. */
|
|
2687
|
+
searchQuery?: string;
|
|
2636
2688
|
/** 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. */
|
|
2637
2689
|
cascadeCreate?: boolean;
|
|
2638
2690
|
/** Parameters applied for recommending the *Source* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Source*. */
|
|
@@ -2650,6 +2702,7 @@ declare module "recombee-api-client" {
|
|
|
2650
2702
|
userId?: string;
|
|
2651
2703
|
logic?: string | object;
|
|
2652
2704
|
segmentId?: string;
|
|
2705
|
+
searchQuery?: string;
|
|
2653
2706
|
cascadeCreate?: boolean;
|
|
2654
2707
|
sourceSettings?: Record<string, unknown>;
|
|
2655
2708
|
resultSettings?: Record<string, unknown>;
|
|
@@ -2663,6 +2716,7 @@ declare module "recombee-api-client" {
|
|
|
2663
2716
|
userId?: string;
|
|
2664
2717
|
logic?: string | object;
|
|
2665
2718
|
segmentId?: string;
|
|
2719
|
+
searchQuery?: string;
|
|
2666
2720
|
cascadeCreate?: boolean;
|
|
2667
2721
|
sourceSettings?: Record<string, unknown>;
|
|
2668
2722
|
resultSettings?: Record<string, unknown>;
|
|
@@ -2788,6 +2842,8 @@ declare module "recombee-api-client" {
|
|
|
2788
2842
|
expertSettings?: Record<string, unknown>;
|
|
2789
2843
|
/** If there is a custom AB-testing running, return the name of the group to which the request belongs. */
|
|
2790
2844
|
returnAbGroup?: boolean;
|
|
2845
|
+
/** A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment. */
|
|
2846
|
+
reqlExpressions?: Record<string, string>;
|
|
2791
2847
|
}
|
|
2792
2848
|
);
|
|
2793
2849
|
|
|
@@ -2801,6 +2857,7 @@ declare module "recombee-api-client" {
|
|
|
2801
2857
|
logic?: string | object;
|
|
2802
2858
|
expertSettings?: Record<string, unknown>;
|
|
2803
2859
|
returnAbGroup?: boolean;
|
|
2860
|
+
reqlExpressions?: Record<string, string>;
|
|
2804
2861
|
protected __response_type: SearchResponse;
|
|
2805
2862
|
|
|
2806
2863
|
bodyParameters(): {
|
|
@@ -2813,6 +2870,7 @@ declare module "recombee-api-client" {
|
|
|
2813
2870
|
logic?: string | object;
|
|
2814
2871
|
expertSettings?: Record<string, unknown>;
|
|
2815
2872
|
returnAbGroup?: boolean;
|
|
2873
|
+
reqlExpressions?: Record<string, string>;
|
|
2816
2874
|
};
|
|
2817
2875
|
|
|
2818
2876
|
queryParameters(): {
|
|
@@ -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
|
|
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
|
|
package/lib/requests/index.js
CHANGED
|
@@ -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;
|
|
@@ -62,6 +62,41 @@ class RecommendItemSegmentsToItemSegment extends rqs.Request {
|
|
|
62
62
|
* - *returnAbGroup*
|
|
63
63
|
* - Type: boolean
|
|
64
64
|
* - Description: If there is a custom AB-testing running, return the name of the group to which the request belongs.
|
|
65
|
+
* - *reqlExpressions*
|
|
66
|
+
* - Type: object
|
|
67
|
+
* - Description: A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
|
|
68
|
+
* This can be used to compute additional properties of the recommended Item Segments.
|
|
69
|
+
* The keys are the names of the expressions, and the values are the actual ReQL expressions.
|
|
70
|
+
* Example request:
|
|
71
|
+
* ```json
|
|
72
|
+
* {
|
|
73
|
+
* "reqlExpressions": {
|
|
74
|
+
* "countItems": "size(segment_items(\"categories\", 'segmentId'))"
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
* Example response:
|
|
79
|
+
* ```json
|
|
80
|
+
* {
|
|
81
|
+
* "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
|
|
82
|
+
* "recomms":
|
|
83
|
+
* [
|
|
84
|
+
* {
|
|
85
|
+
* "id": "category-fantasy-books",
|
|
86
|
+
* "reqlEvaluations": {
|
|
87
|
+
* "countItems": 486
|
|
88
|
+
* }
|
|
89
|
+
* },
|
|
90
|
+
* {
|
|
91
|
+
* "id": "category-sci-fi-costumes",
|
|
92
|
+
* "reqlEvaluations": {
|
|
93
|
+
* "countItems": 19
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* ],
|
|
97
|
+
* "numberNextRecommsCalls": 0
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
65
100
|
*/
|
|
66
101
|
constructor(contextSegmentId, targetUserId, count, optional) {
|
|
67
102
|
super('POST', '/recomms/item-segments/item-segments/', 3000, false);
|
|
@@ -76,6 +111,7 @@ class RecommendItemSegmentsToItemSegment extends rqs.Request {
|
|
|
76
111
|
this.logic = optional.logic;
|
|
77
112
|
this.expertSettings = optional.expertSettings;
|
|
78
113
|
this.returnAbGroup = optional.returnAbGroup;
|
|
114
|
+
this.reqlExpressions = optional.reqlExpressions;
|
|
79
115
|
}
|
|
80
116
|
|
|
81
117
|
/**
|
|
@@ -109,6 +145,9 @@ class RecommendItemSegmentsToItemSegment extends rqs.Request {
|
|
|
109
145
|
if(this.returnAbGroup !== undefined)
|
|
110
146
|
params.returnAbGroup = this.returnAbGroup;
|
|
111
147
|
|
|
148
|
+
if(this.reqlExpressions !== undefined)
|
|
149
|
+
params.reqlExpressions = this.reqlExpressions;
|
|
150
|
+
|
|
112
151
|
return params;
|
|
113
152
|
}
|
|
114
153
|
|
|
@@ -63,6 +63,41 @@ class RecommendItemSegmentsToItem extends rqs.Request {
|
|
|
63
63
|
* - *returnAbGroup*
|
|
64
64
|
* - Type: boolean
|
|
65
65
|
* - Description: If there is a custom AB-testing running, return the name of the group to which the request belongs.
|
|
66
|
+
* - *reqlExpressions*
|
|
67
|
+
* - Type: object
|
|
68
|
+
* - Description: A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
|
|
69
|
+
* This can be used to compute additional properties of the recommended Item Segments.
|
|
70
|
+
* The keys are the names of the expressions, and the values are the actual ReQL expressions.
|
|
71
|
+
* Example request:
|
|
72
|
+
* ```json
|
|
73
|
+
* {
|
|
74
|
+
* "reqlExpressions": {
|
|
75
|
+
* "countItems": "size(segment_items(\"categories\", 'segmentId'))"
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
* Example response:
|
|
80
|
+
* ```json
|
|
81
|
+
* {
|
|
82
|
+
* "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
|
|
83
|
+
* "recomms":
|
|
84
|
+
* [
|
|
85
|
+
* {
|
|
86
|
+
* "id": "category-fantasy-books",
|
|
87
|
+
* "reqlEvaluations": {
|
|
88
|
+
* "countItems": 486
|
|
89
|
+
* }
|
|
90
|
+
* },
|
|
91
|
+
* {
|
|
92
|
+
* "id": "category-sci-fi-costumes",
|
|
93
|
+
* "reqlEvaluations": {
|
|
94
|
+
* "countItems": 19
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* ],
|
|
98
|
+
* "numberNextRecommsCalls": 0
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
66
101
|
*/
|
|
67
102
|
constructor(itemId, targetUserId, count, optional) {
|
|
68
103
|
super('POST', `/recomms/items/${itemId}/item-segments/`, 3000, false);
|
|
@@ -77,6 +112,7 @@ class RecommendItemSegmentsToItem extends rqs.Request {
|
|
|
77
112
|
this.logic = optional.logic;
|
|
78
113
|
this.expertSettings = optional.expertSettings;
|
|
79
114
|
this.returnAbGroup = optional.returnAbGroup;
|
|
115
|
+
this.reqlExpressions = optional.reqlExpressions;
|
|
80
116
|
}
|
|
81
117
|
|
|
82
118
|
/**
|
|
@@ -109,6 +145,9 @@ class RecommendItemSegmentsToItem extends rqs.Request {
|
|
|
109
145
|
if(this.returnAbGroup !== undefined)
|
|
110
146
|
params.returnAbGroup = this.returnAbGroup;
|
|
111
147
|
|
|
148
|
+
if(this.reqlExpressions !== undefined)
|
|
149
|
+
params.reqlExpressions = this.reqlExpressions;
|
|
150
|
+
|
|
112
151
|
return params;
|
|
113
152
|
}
|
|
114
153
|
|
|
@@ -50,6 +50,41 @@ class RecommendItemSegmentsToUser extends rqs.Request {
|
|
|
50
50
|
* - *returnAbGroup*
|
|
51
51
|
* - Type: boolean
|
|
52
52
|
* - Description: If there is a custom AB-testing running, return the name of the group to which the request belongs.
|
|
53
|
+
* - *reqlExpressions*
|
|
54
|
+
* - Type: object
|
|
55
|
+
* - Description: A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
|
|
56
|
+
* This can be used to compute additional properties of the recommended Item Segments.
|
|
57
|
+
* The keys are the names of the expressions, and the values are the actual ReQL expressions.
|
|
58
|
+
* Example request:
|
|
59
|
+
* ```json
|
|
60
|
+
* {
|
|
61
|
+
* "reqlExpressions": {
|
|
62
|
+
* "countItems": "size(segment_items(\"categories\", 'segmentId'))"
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
* Example response:
|
|
67
|
+
* ```json
|
|
68
|
+
* {
|
|
69
|
+
* "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
|
|
70
|
+
* "recomms":
|
|
71
|
+
* [
|
|
72
|
+
* {
|
|
73
|
+
* "id": "category-fantasy-books",
|
|
74
|
+
* "reqlEvaluations": {
|
|
75
|
+
* "countItems": 486
|
|
76
|
+
* }
|
|
77
|
+
* },
|
|
78
|
+
* {
|
|
79
|
+
* "id": "category-sci-fi-costumes",
|
|
80
|
+
* "reqlEvaluations": {
|
|
81
|
+
* "countItems": 19
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* ],
|
|
85
|
+
* "numberNextRecommsCalls": 0
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
53
88
|
*/
|
|
54
89
|
constructor(userId, count, optional) {
|
|
55
90
|
super('POST', `/recomms/users/${userId}/item-segments/`, 3000, false);
|
|
@@ -63,6 +98,7 @@ class RecommendItemSegmentsToUser extends rqs.Request {
|
|
|
63
98
|
this.logic = optional.logic;
|
|
64
99
|
this.expertSettings = optional.expertSettings;
|
|
65
100
|
this.returnAbGroup = optional.returnAbGroup;
|
|
101
|
+
this.reqlExpressions = optional.reqlExpressions;
|
|
66
102
|
}
|
|
67
103
|
|
|
68
104
|
/**
|
|
@@ -94,6 +130,9 @@ class RecommendItemSegmentsToUser extends rqs.Request {
|
|
|
94
130
|
if(this.returnAbGroup !== undefined)
|
|
95
131
|
params.returnAbGroup = this.returnAbGroup;
|
|
96
132
|
|
|
133
|
+
if(this.reqlExpressions !== undefined)
|
|
134
|
+
params.reqlExpressions = this.reqlExpressions;
|
|
135
|
+
|
|
97
136
|
return params;
|
|
98
137
|
}
|
|
99
138
|
|
|
@@ -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 that shall be shown to a user as next recommendations when the user e.g. scrolls the page down (*infinite scroll*) or goes to the next page.
|
|
10
|
+
* It accepts `recommId` of a base recommendation request (e.g., request from the first page) and the number of segments that shall be returned (`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 the other parameters are inherited from the base request.
|
|
17
|
+
* *Recommend next Item segments* can be called many times for a single `recommId` and each call returns different (previously not recommended) segments.
|
|
18
|
+
* The number of *Recommend next Item segments* calls performed so far is returned in the `numberNextRecommsCalls` field.
|
|
19
|
+
* *Recommend next Item segments* can be requested up to 30 minutes after the base request or a previous *Recommend next Item segments* call.
|
|
20
|
+
* For billing purposes, each call to *Recommend next Item segments* 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
|
|
@@ -50,6 +50,41 @@ class SearchItemSegments extends rqs.Request {
|
|
|
50
50
|
* - *returnAbGroup*
|
|
51
51
|
* - Type: boolean
|
|
52
52
|
* - Description: If there is a custom AB-testing running, return the name of the group to which the request belongs.
|
|
53
|
+
* - *reqlExpressions*
|
|
54
|
+
* - Type: object
|
|
55
|
+
* - Description: A dictionary of [ReQL](https://docs.recombee.com/reql) expressions that will be executed for each recommended Item Segment.
|
|
56
|
+
* This can be used to compute additional properties of the recommended Item Segments.
|
|
57
|
+
* The keys are the names of the expressions, and the values are the actual ReQL expressions.
|
|
58
|
+
* Example request:
|
|
59
|
+
* ```json
|
|
60
|
+
* {
|
|
61
|
+
* "reqlExpressions": {
|
|
62
|
+
* "countItems": "size(segment_items(\"categories\", 'segmentId'))"
|
|
63
|
+
* }
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
* Example response:
|
|
67
|
+
* ```json
|
|
68
|
+
* {
|
|
69
|
+
* "recommId": "a7ac55a4-8d6e-4f19-addc-abac4164d8a8",
|
|
70
|
+
* "recomms":
|
|
71
|
+
* [
|
|
72
|
+
* {
|
|
73
|
+
* "id": "category-fantasy-books",
|
|
74
|
+
* "reqlEvaluations": {
|
|
75
|
+
* "countItems": 486
|
|
76
|
+
* }
|
|
77
|
+
* },
|
|
78
|
+
* {
|
|
79
|
+
* "id": "category-sci-fi-costumes",
|
|
80
|
+
* "reqlEvaluations": {
|
|
81
|
+
* "countItems": 19
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* ],
|
|
85
|
+
* "numberNextRecommsCalls": 0
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
53
88
|
*/
|
|
54
89
|
constructor(userId, searchQuery, count, optional) {
|
|
55
90
|
super('POST', `/search/users/${userId}/item-segments/`, 3000, false);
|
|
@@ -64,6 +99,7 @@ class SearchItemSegments extends rqs.Request {
|
|
|
64
99
|
this.logic = optional.logic;
|
|
65
100
|
this.expertSettings = optional.expertSettings;
|
|
66
101
|
this.returnAbGroup = optional.returnAbGroup;
|
|
102
|
+
this.reqlExpressions = optional.reqlExpressions;
|
|
67
103
|
}
|
|
68
104
|
|
|
69
105
|
/**
|
|
@@ -96,6 +132,9 @@ class SearchItemSegments extends rqs.Request {
|
|
|
96
132
|
if(this.returnAbGroup !== undefined)
|
|
97
133
|
params.returnAbGroup = this.returnAbGroup;
|
|
98
134
|
|
|
135
|
+
if(this.reqlExpressions !== undefined)
|
|
136
|
+
params.reqlExpressions = this.reqlExpressions;
|
|
137
|
+
|
|
99
138
|
return params;
|
|
100
139
|
}
|
|
101
140
|
|
package/package.json
CHANGED
|
@@ -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
|
+
});
|