Skip to content

Commit c1ac7be

Browse files
authored
feat(specs): add personalizaton spec and client (#27)
1 parent f0c34de commit c1ac7be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1467
-38
lines changed

.github/workflows/client_javascript.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ jobs:
3434
- name: Build recommend client
3535
run: yarn client:build-js:recommend
3636

37+
- name: Generate personalization client
38+
run: yarn generate:js:personalization
39+
40+
- name: Build personalization client
41+
run: yarn client:build-js:personalization
3742
- name: Lint
3843
run: yarn lint

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ yarn-error.log
1010
!.yarn/releases
1111
!.yarn/plugins
1212

13-
**/.openapi-generator
1413
**/node_modules
1514
**/dist
16-
**/.openapi-generator-ignore
17-
**/git_push.sh
1815

1916
.vscode
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.openapi-generator
4+
.env
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
git_push.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This is the entrypoint for the package
2+
export * from './src/apis';
3+
export * from './model/models';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type DeleteUserProfileResponse = {
2+
/**
3+
* UserToken representing the user for which to fetch the Personalization profile.
4+
*/
5+
userToken: string;
6+
/**
7+
* A date until which the data can safely be considered as deleted for the given user. Any data received after the deletedUntil date will start building a new user profile.
8+
*/
9+
deletedUntil: Date;
10+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Error.
3+
*/
4+
export type ErrorBase = {
5+
message?: string;
6+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type EventScoring = {
2+
/**
3+
* The score for the event.
4+
*/
5+
score: number;
6+
/**
7+
* The name of the event.
8+
*/
9+
eventName: string;
10+
/**
11+
* The type of the event.
12+
*/
13+
eventType: string;
14+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type FacetScoring = {
2+
/**
3+
* The score for the event.
4+
*/
5+
score: number;
6+
/**
7+
* The name of the facet.
8+
*/
9+
facetName: string;
10+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type GetUserTokenResponse = {
2+
/**
3+
* UserToken representing the user for which to fetch the Personalization profile.
4+
*/
5+
userToken: string;
6+
/**
7+
* Date of last event update. (ISO-8601 format).
8+
*/
9+
lastEventAt: Date;
10+
/**
11+
* The userToken scores.
12+
*/
13+
scores: { [key: string]: Record<string, any> };
14+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable no-param-reassign */
2+
import type { RequestOptions } from '../utils/types';
3+
4+
export * from './deleteUserProfileResponse';
5+
export * from './errorBase';
6+
export * from './eventScoring';
7+
export * from './facetScoring';
8+
export * from './getUserTokenResponse';
9+
export * from './personalizationStrategyObject';
10+
export * from './setPersonalizationStrategyResponse';
11+
12+
export interface Authentication {
13+
/**
14+
* Apply authentication settings to header and query params.
15+
*/
16+
applyToRequest: (requestOptions: RequestOptions) => Promise<void> | void;
17+
}
18+
19+
export class ApiKeyAuth implements Authentication {
20+
apiKey: string = '';
21+
22+
constructor(private location: string, private paramName: string) {}
23+
24+
applyToRequest(requestOptions: RequestOptions): void {
25+
if (this.location === 'query') {
26+
requestOptions.queryParameters[this.paramName] = this.apiKey;
27+
} else if (
28+
this.location === 'header' &&
29+
requestOptions &&
30+
requestOptions.headers
31+
) {
32+
requestOptions.headers[this.paramName] = this.apiKey;
33+
} else if (
34+
this.location === 'cookie' &&
35+
requestOptions &&
36+
requestOptions.headers
37+
) {
38+
if (requestOptions.headers.Cookie) {
39+
requestOptions.headers.Cookie += `; ${
40+
this.paramName
41+
}=${encodeURIComponent(this.apiKey)}`;
42+
} else {
43+
requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent(
44+
this.apiKey
45+
)}`;
46+
}
47+
}
48+
}
49+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { EventScoring } from './eventScoring';
2+
import type { FacetScoring } from './facetScoring';
3+
4+
export type PersonalizationStrategyObject = {
5+
/**
6+
* Scores associated with the events.
7+
*/
8+
eventScoring: EventScoring[];
9+
/**
10+
* Scores associated with the facets.
11+
*/
12+
facetScoring: FacetScoring[];
13+
/**
14+
* The impact that personalization has on search results: a number between 0 (personalization disabled) and 100 (personalization fully enabled).
15+
*/
16+
personalizationImpact: number;
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type SetPersonalizationStrategyResponse = {
2+
/**
3+
* A message confirming the strategy update.
4+
*/
5+
message: string;
6+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@algolia/client-personalization",
3+
"version": "5.0.0",
4+
"description": "JavaScript client for @algolia/client-personalization",
5+
"repository": "algolia/algoliasearch-client-javascript",
6+
"author": "Algolia",
7+
"private": true,
8+
"license": "MIT",
9+
"main": "dist/api.js",
10+
"types": "dist/api.d.ts",
11+
"scripts": {
12+
"clean": "rm -Rf node_modules/ *.js",
13+
"build": "tsc",
14+
"test": "yarn build && node dist/client.js"
15+
},
16+
"engines": {
17+
"node": "^16.0.0",
18+
"yarn": "^3.0.0"
19+
},
20+
"devDependencies": {
21+
"@types/node": "16.11.11",
22+
"typescript": "4.5.2"
23+
}
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { PersonalizationApi } from './personalizationApi';
2+
3+
export * from './personalizationApi';
4+
export * from '../utils/errors';
5+
export { EchoRequester } from '../utils/requester/EchoRequester';
6+
7+
export const APIS = [PersonalizationApi];

0 commit comments

Comments
 (0)