Skip to content

Commit

Permalink
feat(specs): add personalizaton spec and client (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Dec 6, 2021
1 parent f0c34de commit c1ac7be
Show file tree
Hide file tree
Showing 53 changed files with 1,467 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/client_javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@ jobs:
- name: Build recommend client
run: yarn client:build-js:recommend

- name: Generate personalization client
run: yarn generate:js:personalization

- name: Build personalization client
run: yarn client:build-js:personalization
- name: Lint
run: yarn lint
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ yarn-error.log
!.yarn/releases
!.yarn/plugins

**/.openapi-generator
**/node_modules
**/dist
**/.openapi-generator-ignore
**/git_push.sh

.vscode
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.openapi-generator
.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

git_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is the entrypoint for the package
export * from './src/apis';
export * from './model/models';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type DeleteUserProfileResponse = {
/**
* UserToken representing the user for which to fetch the Personalization profile.
*/
userToken: string;
/**
* 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.
*/
deletedUntil: Date;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Error.
*/
export type ErrorBase = {
message?: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type EventScoring = {
/**
* The score for the event.
*/
score: number;
/**
* The name of the event.
*/
eventName: string;
/**
* The type of the event.
*/
eventType: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type FacetScoring = {
/**
* The score for the event.
*/
score: number;
/**
* The name of the facet.
*/
facetName: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type GetUserTokenResponse = {
/**
* UserToken representing the user for which to fetch the Personalization profile.
*/
userToken: string;
/**
* Date of last event update. (ISO-8601 format).
*/
lastEventAt: Date;
/**
* The userToken scores.
*/
scores: { [key: string]: Record<string, any> };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable no-param-reassign */
import type { RequestOptions } from '../utils/types';

export * from './deleteUserProfileResponse';
export * from './errorBase';
export * from './eventScoring';
export * from './facetScoring';
export * from './getUserTokenResponse';
export * from './personalizationStrategyObject';
export * from './setPersonalizationStrategyResponse';

export interface Authentication {
/**
* Apply authentication settings to header and query params.
*/
applyToRequest: (requestOptions: RequestOptions) => Promise<void> | void;
}

export class ApiKeyAuth implements Authentication {
apiKey: string = '';

constructor(private location: string, private paramName: string) {}

applyToRequest(requestOptions: RequestOptions): void {
if (this.location === 'query') {
requestOptions.queryParameters[this.paramName] = this.apiKey;
} else if (
this.location === 'header' &&
requestOptions &&
requestOptions.headers
) {
requestOptions.headers[this.paramName] = this.apiKey;
} else if (
this.location === 'cookie' &&
requestOptions &&
requestOptions.headers
) {
if (requestOptions.headers.Cookie) {
requestOptions.headers.Cookie += `; ${
this.paramName
}=${encodeURIComponent(this.apiKey)}`;
} else {
requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent(
this.apiKey
)}`;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { EventScoring } from './eventScoring';
import type { FacetScoring } from './facetScoring';

export type PersonalizationStrategyObject = {
/**
* Scores associated with the events.
*/
eventScoring: EventScoring[];
/**
* Scores associated with the facets.
*/
facetScoring: FacetScoring[];
/**
* The impact that personalization has on search results: a number between 0 (personalization disabled) and 100 (personalization fully enabled).
*/
personalizationImpact: number;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type SetPersonalizationStrategyResponse = {
/**
* A message confirming the strategy update.
*/
message: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@algolia/client-personalization",
"version": "5.0.0",
"description": "JavaScript client for @algolia/client-personalization",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "dist/api.js",
"types": "dist/api.d.ts",
"scripts": {
"clean": "rm -Rf node_modules/ *.js",
"build": "tsc",
"test": "yarn build && node dist/client.js"
},
"engines": {
"node": "^16.0.0",
"yarn": "^3.0.0"
},
"devDependencies": {
"@types/node": "16.11.11",
"typescript": "4.5.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PersonalizationApi } from './personalizationApi';

export * from './personalizationApi';
export * from '../utils/errors';
export { EchoRequester } from '../utils/requester/EchoRequester';

export const APIS = [PersonalizationApi];
Loading

0 comments on commit c1ac7be

Please sign in to comment.