recombee-api-client 6.2.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/lib/api-client.js +1 -1
- package/lib/index.d.ts +47 -13
- package/lib/requests/add-item-property.js +22 -5
- package/lib/requests/add-user-property.js +20 -3
- package/lib/requests/recommend-next-item-segments.js +7 -7
- package/package.json +1 -1
- package/test/add-item-property-batch_test.js +9 -1
- package/test/add-item-property-callback_test.js +45 -0
- package/test/add-item-property-test.js +41 -0
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.3.0'},
|
|
47
47
|
timeout: request.timeout,
|
|
48
48
|
agent: this.options.agent
|
|
49
49
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -296,9 +296,21 @@ declare module "recombee-api-client" {
|
|
|
296
296
|
values?: Record<string, EntityProperty>;
|
|
297
297
|
}
|
|
298
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
|
+
|
|
299
309
|
export type PropertyInfo = {
|
|
300
310
|
name: string;
|
|
301
311
|
type: string;
|
|
312
|
+
role?: PropertyRole;
|
|
313
|
+
metadata?: PropertyMetadata[];
|
|
302
314
|
}
|
|
303
315
|
|
|
304
316
|
export type UpdateMoreItemsResponse = {
|
|
@@ -563,29 +575,40 @@ declare module "recombee-api-client" {
|
|
|
563
575
|
/**
|
|
564
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.
|
|
565
577
|
* @param type - Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
|
|
566
|
-
* * `int
|
|
578
|
+
* * `int` - Signed integer number.
|
|
567
579
|
* * `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
|
|
568
580
|
* * `string` - UTF-8 string.
|
|
569
581
|
* * `boolean` - *true* / *false*
|
|
570
|
-
* * `timestamp` - Value representing date and time.
|
|
582
|
+
* * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
|
|
571
583
|
* * `set` - Set of strings.
|
|
572
584
|
* * `image` - URL of an image (`jpeg`, `png` or `gif`).
|
|
573
|
-
* * `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.
|
|
574
587
|
*/
|
|
575
588
|
constructor(
|
|
576
589
|
propertyName: string,
|
|
577
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
|
+
}
|
|
578
597
|
);
|
|
579
598
|
|
|
580
599
|
propertyName: string;
|
|
581
600
|
type: string;
|
|
601
|
+
role?: string | object;
|
|
602
|
+
metadata?: string[];
|
|
582
603
|
protected __response_type: string;
|
|
583
604
|
|
|
584
605
|
bodyParameters(): {
|
|
606
|
+
type: string;
|
|
607
|
+
role?: string | object;
|
|
608
|
+
metadata?: string[];
|
|
585
609
|
};
|
|
586
610
|
|
|
587
611
|
queryParameters(): {
|
|
588
|
-
type: string;
|
|
589
612
|
};
|
|
590
613
|
}
|
|
591
614
|
|
|
@@ -1022,23 +1045,34 @@ declare module "recombee-api-client" {
|
|
|
1022
1045
|
* * `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
|
|
1023
1046
|
* * `string` - UTF-8 string.
|
|
1024
1047
|
* * `boolean` - *true* / *false*
|
|
1025
|
-
* * `timestamp` - Value representing date and time.
|
|
1048
|
+
* * `timestamp` - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).
|
|
1026
1049
|
* * `set` - Set of strings.
|
|
1050
|
+
* @param optional - Optional parameters given as an object.
|
|
1027
1051
|
*/
|
|
1028
1052
|
constructor(
|
|
1029
1053
|
propertyName: string,
|
|
1030
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
|
+
}
|
|
1031
1061
|
);
|
|
1032
1062
|
|
|
1033
1063
|
propertyName: string;
|
|
1034
1064
|
type: string;
|
|
1065
|
+
role?: string | object;
|
|
1066
|
+
metadata?: string[];
|
|
1035
1067
|
protected __response_type: string;
|
|
1036
1068
|
|
|
1037
1069
|
bodyParameters(): {
|
|
1070
|
+
type: string;
|
|
1071
|
+
role?: string | object;
|
|
1072
|
+
metadata?: string[];
|
|
1038
1073
|
};
|
|
1039
1074
|
|
|
1040
1075
|
queryParameters(): {
|
|
1041
|
-
type: string;
|
|
1042
1076
|
};
|
|
1043
1077
|
}
|
|
1044
1078
|
|
|
@@ -2608,18 +2642,18 @@ declare module "recombee-api-client" {
|
|
|
2608
2642
|
}
|
|
2609
2643
|
|
|
2610
2644
|
/**
|
|
2611
|
-
* Returns Item
|
|
2612
|
-
*
|
|
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`).
|
|
2613
2647
|
* The base request can be one of:
|
|
2614
2648
|
* - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
|
|
2615
2649
|
* - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
|
|
2616
2650
|
* - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
|
|
2617
2651
|
* - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
|
|
2618
|
-
* All
|
|
2619
|
-
*
|
|
2620
|
-
* The number of
|
|
2621
|
-
*
|
|
2622
|
-
* For billing purposes, each call to
|
|
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.
|
|
2623
2657
|
*/
|
|
2624
2658
|
export class RecommendNextItemSegments extends requests.Request {
|
|
2625
2659
|
/**
|
|
@@ -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
|
|
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,18 +6,18 @@
|
|
|
6
6
|
const rqs = require("./request");
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Returns Item
|
|
10
|
-
*
|
|
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
11
|
* The base request can be one of:
|
|
12
12
|
* - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
|
|
13
13
|
* - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
|
|
14
14
|
* - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
|
|
15
15
|
* - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
|
|
16
|
-
* All
|
|
17
|
-
*
|
|
18
|
-
* The number of
|
|
19
|
-
*
|
|
20
|
-
* For billing purposes, each call to
|
|
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
21
|
*/
|
|
22
22
|
class RecommendNextItemSegments extends rqs.Request {
|
|
23
23
|
|
package/package.json
CHANGED
|
@@ -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
|
});
|