Skip to content

Commit

Permalink
Enable specifying custom region and base uri for Recombee
Browse files Browse the repository at this point in the history
- update recombee client
  • Loading branch information
JiriLojda committed Apr 29, 2024
1 parent a332860 commit 9fbb37d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 68 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hotkeys-hook": "^4.5.0",
"recombee-api-client": "^4.0.0"
"recombee-api-client": "^4.1.5"
},
"scripts": {
"dev": "vite",
Expand Down
2 changes: 2 additions & 0 deletions src/functions/model/configuration-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type KontentConfiguration = {
export type RecombeeConfiguration = {
database: string;
key: string;
region: string | undefined;
baseUri: string | undefined;
};

export type RecommendationProjectConfiguration = {
Expand Down
17 changes: 12 additions & 5 deletions src/functions/model/recombee-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import * as Recombee from "recombee-api-client";
import { notNull } from "../../typeguards";
import { RecombeeConfiguration } from "./configuration-model";

type RecombeeDataType = "int" | "double" | "string" | "boolean" | "timestamp" | "set" | "image" | "imageList";

export default class RecombeeClient {
config: RecombeeConfiguration;
client: Recombee.ApiClient;

private datatypeMap: Map<string, Recombee.PropertyType>;
private datatypeMap: Map<string, RecombeeDataType>;

constructor(config: RecombeeConfiguration) {
this.config = config;
this.client = new Recombee.ApiClient(config.database, config.key);
this.client = new Recombee.ApiClient(config.database, config.key, {
region: config.region,
baseUri: config.baseUri,
});

this.datatypeMap = new Map([
["text", "string"],
Expand Down Expand Up @@ -87,7 +92,7 @@ export default class RecombeeClient {
})
.filter(notNull),
];
return this.client.send(new Recombee.requests.Batch(requests));
return this.client.send(new Recombee.requests.Batch(requests)).then(dropResult);
}

importContent(items: IContentItem[]): Promise<void> {
Expand All @@ -103,12 +108,14 @@ export default class RecombeeClient {
return Promise.resolve();
}

return this.client.send(new Recombee.requests.Batch(requests));
return this.client.send(new Recombee.requests.Batch(requests)).then(dropResult);
}

deleteContent(ids: string[]): Promise<void> {
const requests = ids.map(id => new Recombee.requests.DeleteItem(id));

return this.client.send(new Recombee.requests.Batch(requests));
return this.client.send(new Recombee.requests.Batch(requests)).then(dropResult);
}
}

const dropResult = () => {};
58 changes: 0 additions & 58 deletions src/functions/model/recombeeClient.d.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/functions/recombee-init-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const getConfiguration = (body: string): RecommendationProjectConfiguration => {
},
recombee: {
database: jsonBody.recombeeApiId,
region: process.env.RECOMBEE_REGION,
baseUri: process.env.RECOMBEE_BASE_URI,
key: RECOMBEE_API_KEY || "",
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/functions/recombee-sync-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const handler: Handler = async (event) => {
const recombeeConfig: RecombeeConfiguration = {
database: recombeeApiId,
key: RECOMBEE_API_KEY,
region: process.env.RECOMBEE_REGION,
baseUri: process.env.RECOMBEE_BASE_URI,
};

const signitureHelper = new SignatureHelper();
Expand Down

0 comments on commit 9fbb37d

Please sign in to comment.