diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index ff7cc1fecc..1d35920770 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -100,6 +100,13 @@ runs: path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-sources/dist key: ${{ runner.os }}-1-js-client-sources-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-sources/**') }}-${{ hashFiles('specs/dist/sources.yml') }} + - name: Restore built JavaScript predict client + if: ${{ inputs.job == 'cts' }} + uses: actions/cache@v2 + with: + path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/packages/client-predict/dist + key: ${{ runner.os }}-1-js-client-predict-${{ hashFiles('clients/algoliasearch-client-javascript/packages/client-predict/**') }}-${{ hashFiles('specs/dist/predict.yml') }} + - name: Restore built Java client if: ${{ inputs.job == 'cts' }} uses: actions/cache@v2 diff --git a/.redocly.yaml b/.redocly.yaml index ff7792f2a5..6adbe9c6e5 100644 --- a/.redocly.yaml +++ b/.redocly.yaml @@ -7,6 +7,7 @@ apiDefinitions: recommend: specs/recommend/spec.yml search: specs/search/spec.yml sources: specs/sources/spec.yml + predict: specs/predict/spec.yml lint: extends: diff --git a/clients/README.md b/clients/README.md index a142b5450f..195aca962a 100644 --- a/clients/README.md +++ b/clients/README.md @@ -18,6 +18,7 @@ This folder hosts the generated clients. - [@algolia/client-search](./algoliasearch-client-javascript/packages/client-search/): The Algolia search client. - [@algolia/recommend](./algoliasearch-client-javascript/packages/recommend/): The Algolia recommend client. - [@algolia/sources](./algoliasearch-client-javascript/packages/client-sources/): The Algolia sources client. +- [@algolia/predict](./algoliasearch-client-javascript/packages/client-predict/): The Algolia predict client. - [@algolia/client-common](./algoliasearch-client-javascript/packages/client-common/): The JavaScript clients common files. - [@algolia/requester-browser-xhr](./algoliasearch-client-javascript/packages/requester-browser-xhr/): Browser XHR requester for the Algolia JavaScript clients. - [@algolia/requester-node-http](./algoliasearch-client-javascript/packages/requester-node-http/): Node.js HTTP requester for the Algolia JavaScript clients. diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/packages/client-predict/.openapi-generator-ignore new file mode 100644 index 0000000000..29b08dc3a5 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/.openapi-generator-ignore @@ -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 diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/browser.ts b/clients/algoliasearch-client-javascript/packages/client-predict/browser.ts new file mode 100644 index 0000000000..5f8a95e25c --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/browser.ts @@ -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, + }); +} diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/affinities.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/affinities.ts new file mode 100644 index 0000000000..e8187169b1 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/affinities.ts @@ -0,0 +1,5 @@ +export type Affinities = { + name?: string; + value?: string; + probability?: number; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/errorBase.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/errorBase.ts new file mode 100644 index 0000000000..a533aa7a15 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/errorBase.ts @@ -0,0 +1,6 @@ +/** + * Error. + */ +export type ErrorBase = { + message?: string; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts new file mode 100644 index 0000000000..58ebd054ad --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts @@ -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; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/funnelStage.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/funnelStage.ts new file mode 100644 index 0000000000..2fe71efd34 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/funnelStage.ts @@ -0,0 +1,4 @@ +export type FunnelStage = { + name?: string; + probability?: number; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/params.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/params.ts new file mode 100644 index 0000000000..ebcae4a6f8 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/params.ts @@ -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'; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/predictions.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictions.ts new file mode 100644 index 0000000000..632247b07d --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictions.ts @@ -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; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsAffinities.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsAffinities.ts new file mode 100644 index 0000000000..2f9c9060be --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsAffinities.ts @@ -0,0 +1,9 @@ +import type { Affinities } from './affinities'; + +/** + * Prediction for the **affinities** model. + */ +export type PredictionsAffinities = { + value?: Affinities[]; + lastUpdatedAt?: string; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsFunnelStage.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsFunnelStage.ts new file mode 100644 index 0000000000..9a653c5399 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsFunnelStage.ts @@ -0,0 +1,9 @@ +import type { FunnelStage } from './funnelStage'; + +/** + * Prediction for the **funnel_stage** model. + */ +export type PredictionsFunnelStage = { + value?: FunnelStage[]; + lastUpdatedAt?: string; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsOrderValue.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsOrderValue.ts new file mode 100644 index 0000000000..2180dacb5f --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsOrderValue.ts @@ -0,0 +1,7 @@ +/** + * Prediction for the **order_value** model. + */ +export type PredictionsOrderValue = { + value?: number; + lastUpdatedAt?: string; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/properties.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/properties.ts new file mode 100644 index 0000000000..e8c8dbe7eb --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/properties.ts @@ -0,0 +1,17 @@ +/** + * Properties for the user profile. + */ +export type Properties = { + /** + * Raw user properties (key-value pairs). + */ + raw?: Record; + /** + * Computed user properties (key-value pairs). + */ + computed?: Record; + /** + * Custom user properties (key-value pairs). + */ + custom?: Record; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/segments.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/segments.ts new file mode 100644 index 0000000000..a05df5cf46 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/segments.ts @@ -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[]; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/node.ts b/clients/algoliasearch-client-javascript/packages/client-predict/node.ts new file mode 100644 index 0000000000..a2cad9ce98 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/node.ts @@ -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, + }); +} diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/package.json b/clients/algoliasearch-client-javascript/packages/client-predict/package.json new file mode 100644 index 0000000000..05adb7aea9 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/package.json @@ -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" + } +} diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts new file mode 100644 index 0000000000..29bd285e67 --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts @@ -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 { + const path = '/1/users/{userID}/fetch'.replace( + '{userID}', + encodeURIComponent(String(userID)) + ); + const headers: Headers = { Accept: 'application/json' }; + const queryParameters: Record = {}; + + 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; + +export type FetchUserProfileProps = { + /** + * User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). + */ + userID: string; + params: Params; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/tsconfig.json b/clients/algoliasearch-client-javascript/packages/client-predict/tsconfig.json new file mode 100644 index 0000000000..8c122c680a --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-predict/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "dist", + }, + "include": ["src", "model", "node.ts", "browser.ts"], + "exclude": ["dist", "node_modules"] +} diff --git a/openapitools.json b/openapitools.json index ac2a187848..383541a63c 100644 --- a/openapitools.json +++ b/openapitools.json @@ -192,6 +192,27 @@ "topLevelDomain": "com" } }, + "javascript-predict": { + "generatorName": "typescript-node", + "templateDir": "#{cwd}/templates/javascript/", + "config": "#{cwd}/openapitools.json", + "apiPackage": "src", + "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-predict", + "glob": "specs/dist/predict.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-javascript", + "additionalProperties": { + "modelPropertyNaming": "original", + "supportsES6": true, + "npmName": "@algolia/client-predict", + "apiName": "predict", + "capitalizedApiName": "Predict", + "packageVersion": "0.0.1", + "packageName": "@algolia/client-predict", + "experimentalHost": "predict-api-oslcbws3zq-ew.a.run.app" + } + }, "java-search": { "generatorName": "java", "templateDir": "#{cwd}/templates/java/", diff --git a/playground/javascript/package.json b/playground/javascript/package.json index 5be85c89b1..e83661a983 100644 --- a/playground/javascript/package.json +++ b/playground/javascript/package.json @@ -10,18 +10,21 @@ "start:recommend": "yarn install && yarn build && yarn test:recommend", "start:search": "yarn install && yarn build && yarn test:search", "start:sources": "yarn install && yarn build && yarn test:sources", + "start:predict": "yarn install && yarn build && yarn test:predict", "test:abtesting": "node dist/analytics.js", "test:analytics": "node dist/analytics.js", "test:personalization": "node dist/personalization.js", "test:query-suggestions": "node dist/query-suggestions.js", "test:recommend": "node dist/recommend.js", "test:search": "node dist/search.js", - "test:sources": "node dist/sources.js" + "test:sources": "node dist/sources.js", + "test:predict": "node dist/predict.js" }, "devDependencies": { "@algolia/client-abtesting": "5.0.0", "@algolia/client-analytics": "5.0.0", "@algolia/client-personalization": "5.0.0", + "@algolia/client-predict": "0.0.1", "@algolia/client-query-suggestions": "5.0.0", "@algolia/client-search": "5.0.0", "@algolia/client-sources": "0.0.1", diff --git a/playground/javascript/predict.ts b/playground/javascript/predict.ts new file mode 100644 index 0000000000..301a050396 --- /dev/null +++ b/playground/javascript/predict.ts @@ -0,0 +1,35 @@ +import { predictApi } from '@algolia/client-predict'; +import { ApiError } from '@algolia/client-common'; +import dotenv from 'dotenv'; + +dotenv.config({ path: '../.env' }); + +const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****'; +const apiKey = process.env.ALGOLIA_SEARCH_KEY || '**** SEARCH_API_KEY *****'; + +const userId = process.env.USER_ID || 'user1'; + +// Init client with appId and apiKey +const predictClient = predictApi(appId, apiKey); + +async function testPredict() { + try { + const userProfile = await predictClient.fetchUserProfile({ + userID: userId, + params: { + modelsToRetrieve: ['funnel_stage', 'order_value', 'affinities'], + typesToRetrieve: ['properties', 'segments'], + }, + }); + + console.log(`[OK]`, userProfile); + } catch (e) { + if (e instanceof ApiError) { + return console.log(`[${e.status}] ${e.message}`, e.stackTrace); + } + + console.log('[ERROR]', e); + } +} + +testPredict(); diff --git a/playground/javascript/sources.ts b/playground/javascript/sources.ts index e130672c84..ad076cff33 100644 --- a/playground/javascript/sources.ts +++ b/playground/javascript/sources.ts @@ -16,7 +16,11 @@ async function testSource() { type: 'csv', input: { url: '', - // url: 'https://docs.google.com/spreadsheets/d/e/2PACX-1vR7HII972uvH_5IOVCH8HS6348FJP575hs-v1f8EtrUYEFzuapc5QYrZIktNQJMUiF-9ACN_ddodkCk/pub?output=csv' + }, + target: { + indexName: 'test', + operation: 'replace', + type: 'search', }, }); diff --git a/scripts/pre-gen/setHostsOptions.ts b/scripts/pre-gen/setHostsOptions.ts index 3578e8b275..b8f5878210 100644 --- a/scripts/pre-gen/setHostsOptions.ts +++ b/scripts/pre-gen/setHostsOptions.ts @@ -25,6 +25,10 @@ type AdditionalProperties = Partial<{ isDeHost: boolean; host: string; topLevelDomain: string; + /** + * Client name needs to be explicitly set, no variables required in the host. + */ + experimentalHost: string; }>; async function setHostsOptions(): Promise { @@ -56,6 +60,12 @@ async function setHostsOptions(): Promise { const { host } = new URL(url); + // Edge case for `predict`, we should maybe have a proper way to detect + // experimental/staging hosts + if (client === 'predict') { + additionalProperties.experimentalHost = host; + } + if (!variables?.region || !variables?.region?.enum) { continue; } diff --git a/specs/predict/common/parameters.yml b/specs/predict/common/parameters.yml new file mode 100644 index 0000000000..362f6178ce --- /dev/null +++ b/specs/predict/common/parameters.yml @@ -0,0 +1,7 @@ +userID: + name: userID + in: path + required: true + schema: + type: string + description: User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml new file mode 100644 index 0000000000..a5248fa175 --- /dev/null +++ b/specs/predict/paths/fetchUserProfile.yml @@ -0,0 +1,139 @@ +post: + tags: + - predict + operationId: fetchUserProfile + description: Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a user profile. + summary: Get user profile. + parameters: + - $ref: '../common/parameters.yml#/userID' + requestBody: + required: true + content: + application/json: + schema: + title: params + type: object + description: Object with models and types to retrieve. + additionalProperties: false + properties: + modelsToRetrieve: + type: array + description: List with model types for which to retrieve predictions + items: + type: string + enum: + - funnel_stage + - order_value + - affinities + typesToRetrieve: + type: array + description: List with types to be retrieved. + items: + type: string + enum: + - properties + - segments + minItems: 1 + responses: + '200': + description: OK + content: + application/json: + schema: + title: fetchUserProfileResponse + type: object + required: + - user + properties: + user: + type: string + predictions: + type: object + title: predictions + properties: + funnel_stage: + type: object + description: Prediction for the **funnel_stage** model + properties: + value: + type: array + items: + title: funnel_stage + type: object + properties: + name: + type: string + probability: + type: number + minimum: 0 + maximum: 1 + lastUpdatedAt: + type: string + order_value: + type: object + description: Prediction for the **order_value** model + properties: + value: + type: number + minimum: 0 + lastUpdatedAt: + type: string + affinities: + type: object + description: Prediction for the **affinities** model + properties: + value: + type: array + items: + title: affinities + type: object + properties: + name: + type: string + value: + type: string + probability: + type: number + minimum: 0 + maximum: 1 + lastUpdatedAt: + type: string + properties: + type: object + title: properties + description: Properties for the user profile + properties: + raw: + type: object + description: Raw user properties (key-value pairs) + computed: + type: object + description: Computed user properties (key-value pairs) + custom: + type: object + description: Custom user properties (key-value pairs) + segments: + type: object + title: segments + description: Segments that the user belongs to + properties: + computed: + type: array + description: List of computed segments IDs + items: + type: string + custom: + type: array + description: List of custom segments IDs + items: + type: string + '404': + $ref: ../responses/UserNotFound.yml + '405': + $ref: ../../common/responses/MethodNotAllowed.yml + '400': + description: ModelsToRetrieve or typesToRetrieve must be set. + content: + application/json: + schema: + $ref: ../../common/schemas/ErrorBase.yml diff --git a/specs/predict/responses/UserNotFound.yml b/specs/predict/responses/UserNotFound.yml new file mode 100644 index 0000000000..86630af3f7 --- /dev/null +++ b/specs/predict/responses/UserNotFound.yml @@ -0,0 +1,5 @@ +description: User not found. +content: + application/json: + schema: + $ref: ../../common/schemas/ErrorBase.yml diff --git a/specs/predict/spec.yml b/specs/predict/spec.yml new file mode 100644 index 0000000000..23f1665f25 --- /dev/null +++ b/specs/predict/spec.yml @@ -0,0 +1,19 @@ +openapi: 3.0.2 +info: + title: Predict API + description: API powering the Predict feature of Algolia. + version: 0.1.0 +components: + securitySchemes: + appId: + $ref: '../common/securitySchemes.yml#/appId' + apiKey: + $ref: '../common/securitySchemes.yml#/apiKey' +servers: + - url: https://predict-api-oslcbws3zq-ew.a.run.app +security: + - appId: [] + apiKey: [] +paths: + /1/users/{userID}/fetch: + $ref: paths/fetchUserProfile.yml diff --git a/templates/javascript/api-single.mustache b/templates/javascript/api-single.mustache index 4c824ddf88..f54fbbab19 100644 --- a/templates/javascript/api-single.mustache +++ b/templates/javascript/api-single.mustache @@ -18,7 +18,7 @@ export const version = '{{packageVersion}}'; export type Region = {{#isDeHost}}'de'{{/isDeHost}}{{#isEuHost}}'eu'{{/isEuHost}} | 'us'; {{/hasRegionalHost}} -{{^hasRegionalHost}} +{{^hasRegionalHost}}{{^experimentalHost}} function getDefaultHosts(appId: string): Host[] { return ( [ @@ -53,7 +53,13 @@ function getDefaultHosts(appId: string): Host[] { ]) ); } -{{/hasRegionalHost}} +{{/experimentalHost}}{{/hasRegionalHost}} + +{{#experimentalHost}} +function getDefaultHosts(): Host[] { + return [{ url: '{{experimentalHost}}', accept: 'readWrite', protocol: 'https' }]; +} +{{/experimentalHost}} {{#hasRegionalHost}} function getDefaultHosts(region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region): Host[] { @@ -67,7 +73,7 @@ function getDefaultHosts(region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}} export const create{{capitalizedApiName}}Api = (options: CreateClientOptions{{#hasRegionalHost}} & {region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region }{{/hasRegionalHost}}) => { const auth = createAuth(options.appId, options.apiKey, options.authMode); const transporter = new Transporter({ - hosts: options?.hosts ?? getDefaultHosts({{^hasRegionalHost}}options.appId{{/hasRegionalHost}}{{#hasRegionalHost}}options.region{{/hasRegionalHost}}), + hosts: options?.hosts ?? getDefaultHosts({{^hasRegionalHost}}{{^experimentalHost}}options.appId{{/experimentalHost}}{{/hasRegionalHost}}{{#hasRegionalHost}}options.region{{/hasRegionalHost}}), baseHeaders: { 'content-type': 'application/x-www-form-urlencoded', ...auth.headers(), diff --git a/yarn.lock b/yarn.lock index a386bea719..b884e921d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -89,6 +89,18 @@ __metadata: languageName: unknown linkType: soft +"@algolia/client-predict@0.0.1, @algolia/client-predict@workspace:clients/algoliasearch-client-javascript/packages/client-predict": + version: 0.0.0-use.local + resolution: "@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/packages/client-predict" + dependencies: + "@algolia/client-common": 5.0.0 + "@algolia/requester-browser-xhr": 5.0.0 + "@algolia/requester-node-http": 5.0.0 + "@types/node": 16.11.11 + typescript: 4.5.4 + languageName: unknown + linkType: soft + "@algolia/client-query-suggestions@5.0.0, @algolia/client-query-suggestions@workspace:clients/algoliasearch-client-javascript/packages/client-query-suggestions": version: 0.0.0-use.local resolution: "@algolia/client-query-suggestions@workspace:clients/algoliasearch-client-javascript/packages/client-query-suggestions" @@ -3908,6 +3920,7 @@ __metadata: "@algolia/client-abtesting": 5.0.0 "@algolia/client-analytics": 5.0.0 "@algolia/client-personalization": 5.0.0 + "@algolia/client-predict": 0.0.1 "@algolia/client-query-suggestions": 5.0.0 "@algolia/client-search": 5.0.0 "@algolia/client-sources": 0.0.1