- Notifications
You must be signed in to change notification settings - Fork 27
feat(spec): add Predict client #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 29 commits
Commits
Show all changes
30 commits Select commit Hold shift + click to select a range
7289b7d Fetch user profile endpoint
8bf2435 Fix errors
8eb49db Add Javascript client
b5f01ca Update configuration
5cb4425 Add JavaScript API client
4f779f1 Fetch user profile endpoint
0a65382 Fix errors
e082c8b Add Javascript client
ba67c5b Add JavaScript API client
04f2b3c Merge branch 'feat/predict-pilot' of github.com:algolia/api-clients-a…
217c0c1 Fix configuration
68f60b3 Remove old files
2e667ab Remove long descriptions
3bbf2a0 Clean up old files, regenerate client
c3c4e5f Disable enum validation
be5f35e Update request body to remove InlineObject name
5e9b9f8 Remove old file
f4b2533 Update requestBody name
f498f0a Add 400 error
a1dfb13 Add example
36e5a1c Update example and config files
8214c19 Merge branch 'main' of github.com:algolia/api-clients-automation into…
0be4c32 Remove duplicate error spec, formatting
2b5dc90 Remove git push file
c0a5cb5 Fix error base path
3278c85 Remove extra empty lines
ba8af71 Merge branch 'main' into feat/predict-pilot
shortcuts 9ccd6d0 regenerate and fix host edge case
shortcuts 1861535 Add response titles, regenerate client
9a12538 update clients/README.md
shortcuts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions 9 clients/algoliasearch-client-javascript/packages/client-predict/.openapi-generator-ignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # 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 | ||
| model/models.ts | ||
| .gitignore |
36 changes: 36 additions & 0 deletions 36 clients/algoliasearch-client-javascript/packages/client-predict/browser.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { Host, Requester } from '@algolia/client-common'; | ||
| import { XhrRequester } from '@algolia/requester-browser-xhr'; | ||
| | ||
| import { createPredictApi } from './src/predictApi'; | ||
| import type { PredictApi } from './src/predictApi'; | ||
| | ||
| export * from './src/predictApi'; | ||
| | ||
| export function predictApi( | ||
| appId: string, | ||
| apiKey: string, | ||
| options?: { requester?: Requester; hosts?: Host[] } | ||
| ): PredictApi { | ||
| if (!appId) { | ||
| throw new Error('`appId` is missing.'); | ||
| } | ||
| | ||
| if (!apiKey) { | ||
| throw new Error('`apiKey` is missing.'); | ||
| } | ||
| | ||
| return createPredictApi({ | ||
| appId, | ||
| apiKey, | ||
| | ||
| timeouts: { | ||
| connect: 1, | ||
| read: 2, | ||
| write: 30, | ||
| }, | ||
| requester: options?.requester ?? new XhrRequester(), | ||
| userAgents: [{ segment: 'Browser' }], | ||
| authMode: 'WithinQueryParameters', | ||
| ...options, | ||
| }); | ||
| } |
5 changes: 5 additions & 0 deletions 5 clients/algoliasearch-client-javascript/packages/client-predict/model/affinities.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export type Affinities = { | ||
| name?: string; | ||
| value?: string; | ||
| probability?: number; | ||
| }; |
6 changes: 6 additions & 0 deletions 6 clients/algoliasearch-client-javascript/packages/client-predict/model/errorBase.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Error. | ||
| */ | ||
| export type ErrorBase = { | ||
| message?: string; | ||
| }; |
10 changes: 10 additions & 0 deletions 10 ...algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import type { Predictions } from './predictions'; | ||
| import type { Properties } from './properties'; | ||
| import type { Segments } from './segments'; | ||
| | ||
| export type FetchUserProfileResponse = { | ||
| user: string; | ||
| predictions?: Predictions; | ||
| properties?: Properties; | ||
| segments?: Segments; | ||
| }; |
4 changes: 4 additions & 0 deletions 4 clients/algoliasearch-client-javascript/packages/client-predict/model/funnelStage.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export type FunnelStage = { | ||
| name?: string; | ||
| probability?: number; | ||
| }; |
20 changes: 20 additions & 0 deletions 20 clients/algoliasearch-client-javascript/packages/client-predict/model/params.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Object with models and types to retrieve. | ||
| */ | ||
| export type Params = { | ||
| /** | ||
| * List with model types for which to retrieve predictions. | ||
| */ | ||
| modelsToRetrieve?: ParamsModelsToRetrieve[]; | ||
| /** | ||
| * List with types to be retrieved. | ||
| */ | ||
| typesToRetrieve?: ParamsTypesToRetrieve[]; | ||
| }; | ||
| | ||
| export type ParamsModelsToRetrieve = | ||
| | 'affinities' | ||
| | 'funnel_stage' | ||
| | 'order_value'; | ||
| | ||
| export type ParamsTypesToRetrieve = 'properties' | 'segments'; |
9 changes: 9 additions & 0 deletions 9 clients/algoliasearch-client-javascript/packages/client-predict/model/predictions.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { PredictionsAffinities } from './predictionsAffinities'; | ||
| import type { PredictionsFunnelStage } from './predictionsFunnelStage'; | ||
| import type { PredictionsOrderValue } from './predictionsOrderValue'; | ||
| | ||
| export type Predictions = { | ||
| funnel_stage?: PredictionsFunnelStage; | ||
| order_value?: PredictionsOrderValue; | ||
| affinities?: PredictionsAffinities; | ||
| }; |
9 changes: 9 additions & 0 deletions 9 ...ts/algoliasearch-client-javascript/packages/client-predict/model/predictionsAffinities.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { Affinities } from './affinities'; | ||
| | ||
| /** | ||
| * Prediction for the **affinities** model. | ||
| */ | ||
| export type PredictionsAffinities = { | ||
| value?: Affinities[]; | ||
| lastUpdatedAt?: string; | ||
| }; |
9 changes: 9 additions & 0 deletions 9 ...s/algoliasearch-client-javascript/packages/client-predict/model/predictionsFunnelStage.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { FunnelStage } from './funnelStage'; | ||
| | ||
| /** | ||
| * Prediction for the **funnel_stage** model. | ||
| */ | ||
| export type PredictionsFunnelStage = { | ||
| value?: FunnelStage[]; | ||
| lastUpdatedAt?: string; | ||
| }; |
7 changes: 7 additions & 0 deletions 7 ...ts/algoliasearch-client-javascript/packages/client-predict/model/predictionsOrderValue.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * Prediction for the **order_value** model. | ||
| */ | ||
| export type PredictionsOrderValue = { | ||
| value?: number; | ||
| lastUpdatedAt?: string; | ||
| }; |
17 changes: 17 additions & 0 deletions 17 clients/algoliasearch-client-javascript/packages/client-predict/model/properties.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * Properties for the user profile. | ||
| */ | ||
| export type Properties = { | ||
| /** | ||
| * Raw user properties (key-value pairs). | ||
| */ | ||
| raw?: Record<string, any>; | ||
| /** | ||
| * Computed user properties (key-value pairs). | ||
| */ | ||
| computed?: Record<string, any>; | ||
| /** | ||
| * Custom user properties (key-value pairs). | ||
| */ | ||
| custom?: Record<string, any>; | ||
| }; |
13 changes: 13 additions & 0 deletions 13 clients/algoliasearch-client-javascript/packages/client-predict/model/segments.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * Segments that the user belongs to. | ||
| */ | ||
| export type Segments = { | ||
| /** | ||
| * List of computed segments IDs. | ||
| */ | ||
| computed?: string[]; | ||
| /** | ||
| * List of custom segments IDs. | ||
| */ | ||
| custom?: string[]; | ||
| }; |
35 changes: 35 additions & 0 deletions 35 clients/algoliasearch-client-javascript/packages/client-predict/node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type { Host, Requester } from '@algolia/client-common'; | ||
| import { HttpRequester } from '@algolia/requester-node-http'; | ||
| | ||
| import { createPredictApi } from './src/predictApi'; | ||
| import type { PredictApi } from './src/predictApi'; | ||
| | ||
| export * from './src/predictApi'; | ||
| | ||
| export function predictApi( | ||
| appId: string, | ||
| apiKey: string, | ||
| options?: { requester?: Requester; hosts?: Host[] } | ||
| ): PredictApi { | ||
| if (!appId) { | ||
| throw new Error('`appId` is missing.'); | ||
| } | ||
| | ||
| if (!apiKey) { | ||
| throw new Error('`apiKey` is missing.'); | ||
| } | ||
| | ||
| return createPredictApi({ | ||
| appId, | ||
| apiKey, | ||
| | ||
| timeouts: { | ||
| connect: 2, | ||
| read: 5, | ||
| write: 30, | ||
| }, | ||
| requester: options?.requester ?? new HttpRequester(), | ||
| userAgents: [{ segment: 'Node.js', version: process.versions.node }], | ||
| ...options, | ||
| }); | ||
| } |
32 changes: 32 additions & 0 deletions 32 clients/algoliasearch-client-javascript/packages/client-predict/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "name": "@algolia/client-predict", | ||
| "version": "0.0.1", | ||
| "description": "JavaScript client for @algolia/client-predict", | ||
| "repository": "algolia/algoliasearch-client-javascript", | ||
| "author": "Algolia", | ||
| "private": true, | ||
| "license": "MIT", | ||
| "main": "./dist/node.js", | ||
| "types": "./dist/node.d.ts", | ||
| "jsdelivr": "./dist/browser.js", | ||
| "unpkg": "./dist/browser.js", | ||
| "browser": { | ||
| "./index.js": "./dist/browser.js" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "clean": "rm -rf dist/" | ||
| }, | ||
| "engines": { | ||
| "node": "^14.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "@algolia/client-common": "5.0.0", | ||
| "@algolia/requester-browser-xhr": "5.0.0", | ||
| "@algolia/requester-node-http": "5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "16.11.11", | ||
| "typescript": "4.5.4" | ||
| } | ||
| } |
97 changes: 97 additions & 0 deletions 97 clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { Transporter, createAuth, getUserAgent } from '@algolia/client-common'; | ||
| import type { | ||
| CreateClientOptions, | ||
| Headers, | ||
| Host, | ||
| Request, | ||
| } from '@algolia/client-common'; | ||
| | ||
| import type { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; | ||
| import type { Params } from '../model/params'; | ||
| | ||
| export const version = '0.0.1'; | ||
| | ||
| function getDefaultHosts(): Host[] { | ||
| return [ | ||
| { | ||
| url: 'predict-api-oslcbws3zq-ew.a.run.app', | ||
| accept: 'readWrite', | ||
| protocol: 'https', | ||
| }, | ||
| ]; | ||
| } | ||
| | ||
| // eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
| export const createPredictApi = (options: CreateClientOptions) => { | ||
| const auth = createAuth(options.appId, options.apiKey, options.authMode); | ||
| const transporter = new Transporter({ | ||
| hosts: options?.hosts ?? getDefaultHosts(), | ||
| baseHeaders: { | ||
| 'content-type': 'application/x-www-form-urlencoded', | ||
| ...auth.headers(), | ||
| }, | ||
| baseQueryParameters: auth.queryParameters(), | ||
| userAgent: getUserAgent({ | ||
| userAgents: options.userAgents, | ||
| client: 'Predict', | ||
| version, | ||
| }), | ||
| timeouts: options.timeouts, | ||
| requester: options.requester, | ||
| }); | ||
| | ||
| /** | ||
| * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a user profile. | ||
| * | ||
| * @summary Get user profile. | ||
| * @param fetchUserProfile - The fetchUserProfile object. | ||
| * @param fetchUserProfile.userID - User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). | ||
| * @param fetchUserProfile.params - The params object. | ||
| */ | ||
| function fetchUserProfile({ | ||
| userID, | ||
| params, | ||
| }: FetchUserProfileProps): Promise<FetchUserProfileResponse> { | ||
| const path = '/1/users/{userID}/fetch'.replace( | ||
| '{userID}', | ||
| encodeURIComponent(String(userID)) | ||
| ); | ||
| const headers: Headers = { Accept: 'application/json' }; | ||
| const queryParameters: Record<string, string> = {}; | ||
| | ||
| if (!userID) { | ||
| throw new Error( | ||
| 'Parameter `userID` is required when calling `fetchUserProfile`.' | ||
| ); | ||
| } | ||
| | ||
| if (!params) { | ||
| throw new Error( | ||
| 'Parameter `params` is required when calling `fetchUserProfile`.' | ||
| ); | ||
| } | ||
| | ||
| const request: Request = { | ||
| method: 'POST', | ||
| path, | ||
| data: params, | ||
| }; | ||
| | ||
| return transporter.request(request, { | ||
| queryParameters, | ||
| headers, | ||
| }); | ||
| } | ||
| | ||
| return { fetchUserProfile }; | ||
| }; | ||
| | ||
| export type PredictApi = ReturnType<typeof createPredictApi>; | ||
| | ||
| export type FetchUserProfileProps = { | ||
| /** | ||
| * User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). | ||
| */ | ||
| userID: string; | ||
| params: Params; | ||
| }; |
8 changes: 8 additions & 0 deletions 8 clients/algoliasearch-client-javascript/packages/client-predict/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "outDir": "dist", | ||
| }, | ||
| "include": ["src", "model", "node.ts", "browser.ts"], | ||
| "exclude": ["dist", "node_modules"] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.