Skip to content

Commit 128dbde

Browse files
committed
Support setting the region of your DB
1 parent 05a8d70 commit 128dbde

File tree

9 files changed

+66
-13
lines changed

9 files changed

+66
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The library is [UMD](https://github.com/umdjs/umd) compatible.
1515
You can download [recombee-api-client.min.js](./dist/recombee-api-client.min.js) and host it at your site, or use a CDN such as [jsDelivr](https://www.jsdelivr.com/) CDN:
1616

1717
```js
18-
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@3.1.0/dist/recombee-api-client.min.js"></script>
18+
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@4.0.0/dist/recombee-api-client.min.js"></script>
1919
```
2020

2121
### npm
@@ -44,7 +44,7 @@ It is intentionally not possible to change item catalog (properties of items) wi
4444

4545
```javascript
4646
// Initialize client with name of your database and PUBLIC token
47-
var client = new recombee.ApiClient('name-of-your-db', '...db-public-token...');
47+
var client = new recombee.ApiClient('name-of-your-db', '...db-public-token...', {region: 'us-west'});
4848

4949
//Interactions take Id of user and Id of item
5050
client.send(new recombee.AddBookmark('user-13434', 'item-256'));
@@ -189,7 +189,7 @@ Let's assume we want to show recommendations at product page of pants `product-2
189189
</div>
190190
</div>
191191

192-
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@3.1.0/dist/recombee-api-client.min.js"></script>
192+
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@4.0.0/dist/recombee-api-client.min.js"></script>
193193

194194
<script type="text/javascript">
195195
@@ -211,7 +211,7 @@ Let's assume we want to show recommendations at product page of pants `product-2
211211
}
212212
213213
// Initialize client
214-
var client = new recombee.ApiClient('js-client-example', 'dXx2Jw4VkkYQP1XU4JwBAqGezs8BNzwhogGIRjDHJi39Yj3i0tWyIZ0IhKKw5Ln7');
214+
var client = new recombee.ApiClient('js-client-example', 'dXx2Jw4VkkYQP1XU4JwBAqGezs8BNzwhogGIRjDHJi39Yj3i0tWyIZ0IhKKw5Ln7', {region: 'eu-west'});
215215
216216
var itemId = 'product-270';
217217
var userId = 'user-1539'

dist/recombee-api-client.js

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/recombee-api-client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/recombee-api-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/recombee-api-client.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "recombee-js-api-client",
3-
"version": "3.1.0",
3+
"version": "4.0.0",
44
"description": "Client-side js library for easy use of the Recombee recommendation API",
55
"browser": "./src/index.js",
66
"repository": {

src/api-client.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,38 @@ class ApiClient {
1818
this.databaseId = databaseId;
1919
this.publicToken = publicToken;
2020
this.options = options || {};
21-
this.baseUri = this.options.baseUri || 'client-rapi.recombee.com';
21+
this.baseUri = this._getBaseUri()
2222
this.useHttps = ('useHttps' in this.options) ? this.options.useHttps : true;
2323
this.async = ('async' in this.options) ? this.options.async : true;
2424
}
2525

26+
27+
_getRegionalBaseUri(region) {
28+
const uri = {
29+
'ap-se': 'client-rapi-ap-se.recombee.com',
30+
'ca-east': 'client-rapi-ca-east.recombee.com',
31+
'eu-west': 'client-rapi-eu-west.recombee.com',
32+
'us-west': 'client-rapi-us-west.recombee.com'
33+
}[region.toLowerCase()];
34+
35+
if (uri === undefined) {
36+
throw new Error(`Region "${region}" is unknown. You may need to update the version of the SDK.`)
37+
}
38+
39+
return uri;
40+
}
41+
42+
_getBaseUri() {
43+
let baseUri = this.options.baseUri;
44+
if (this.options.region) {
45+
if (baseUri) {
46+
throw new Error('baseUri and region cannot be specified at the same time');
47+
}
48+
baseUri = this._getRegionalBaseUri(this.options.region);
49+
}
50+
return baseUri || 'client-rapi.recombee.com';
51+
}
52+
2653
/**
2754
* Send the request to Recombee
2855
* @param {Request} request - Request to be sent

src/requests/recommend-items-to-user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class RecommendItemsToUser extends rqs.Request {
110110
* - Description: **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested relevance, and may return less than *count* items when there is not enough data to fulfill it.
111111
* - *rotationRate*
112112
* - Type: number
113-
* - Description: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.1`.
113+
* - Description: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0`.
114114
* - *rotationTime*
115115
* - Type: number
116116
* - Description: **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`.

tests/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function createClient() {
2-
return new recombee.ApiClient('tst-public-key', 'dIuCAwTeXn87m24HYE6uAIwSVzgEkTrQflrYlDBeIoeTIrhG1FVqj1v0h6u3nNSu');
2+
return new recombee.ApiClient('tst-public-key', 'dIuCAwTeXn87m24HYE6uAIwSVzgEkTrQflrYlDBeIoeTIrhG1FVqj1v0h6u3nNSu', {region: 'eu-west'});
33
}
44

55
function testInteractionPromise(assert, interactionReq) {

0 commit comments

Comments
 (0)