From 7289b7d9f99688626f39ee91a2dfcfaaf8b7cebc Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Mon, 31 Jan 2022 17:12:29 +0200 Subject: [PATCH 01/27] Fetch user profile endpoint --- specs/predict/common/parameters.yml | 35 +++++++ specs/predict/paths/fetchUserProfile.yml | 119 +++++++++++++++++++++++ specs/predict/responses/UserNotFound.yml | 5 + specs/predict/schemas/ErrorBase.yml | 7 ++ specs/predict/spec.yml | 22 +++++ 5 files changed, 188 insertions(+) create mode 100644 specs/predict/common/parameters.yml create mode 100644 specs/predict/paths/fetchUserProfile.yml create mode 100644 specs/predict/responses/UserNotFound.yml create mode 100644 specs/predict/schemas/ErrorBase.yml create mode 100644 specs/predict/spec.yml diff --git a/specs/predict/common/parameters.yml b/specs/predict/common/parameters.yml new file mode 100644 index 0000000000..97bdb2aa08 --- /dev/null +++ b/specs/predict/common/parameters.yml @@ -0,0 +1,35 @@ +userID: + name: userID + in: path + required: true + description: | + This parameter can have different values: + * An user ID for authenticated users. + * A cookie ID for non-authenticated repeated users (visitors) + schema: + type: string + +modelsToRetrieve: + name: modelsToRetrieve + description: List with model types for which to retrieve predictions + schema: + type: array + items: + type: string + enum: + - funnel_stage + - order_value + - affinities + minItems: 1 + +typesToRetrieve: + name: typesToRetrieve + description: List with types to be retrieved. + schema: + type: array + items: + type: string + enum: + - properties + - segments + minItems: 1 diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml new file mode 100644 index 0000000000..6fc0dd98bd --- /dev/null +++ b/specs/predict/paths/fetchUserProfile.yml @@ -0,0 +1,119 @@ +post: + tags: + - predict + operationId: fetchUserProfile + description: | + Get predictions, properties (raw, computed or custom) and segments (computed or custom) for an authenticated user (userID) or an anonymous user (cookieID). + + The predictions can be goals, metrics or affinities: + * **Goals** ML models compute the probability for an action. Ex. A funnel stage model can output the next stage in the user conversion funnel - add_to_cart with a probability of 72%. + * **Metrics** ML models output a number. Ex. Next order value is 172.43 USD. Since metrics models are usually based on regression, these predictions have a single value without a probability attached to it. + * **Affinities** ML models output a set of item attributes with associated probabilities. Ex. a user is interested in items with the following characteristics: *color: red* (56% probability), *brand: Adidas* (67% probability). + + The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. + + summary: Get user profile + parameters: + - $ref: '../common/parameters.yml#/userID' + - $ref: '../common/parameters.yml#/modelsToRetrieve' + - $ref: '../common/parameters.yml#/typesToRetrieve' + responses: + '200': + description: OK + content: + application/json: + schema: + title: fetchUserProfileResponse + type: object + # additionalProperties: false + required: + - user + properties: + user: + $ref: '../common/parameters.yml#/userID' + predictions: + type: object + properties: + funnel_stage: + type: object + description: Prediction for the **funnel_stage** model + properties: + value: + type: array + items: + type: object + properties: + name: + type: string + enum: + - all_visits + - click_product_list + - product_view + - add_to_cart + - checkout + - transaction + probability: + type: number + min: 0 + max: 1 + lastUpdatedAt: + type: string + order_value: + type: object + description: Prediction for the **order_value** model + properties: + value: + type: number + min: 0 + lastUpdatedAt: + type: string + affinities: + type: object + description: Prediction for the **affinities** model + properties: + value: + type: array + items: + type: object + properties: + name: + type: string + value: + type: string + probability: + type: number + min: 0 + max: 1 + lastUpdatedAt: + type: string + properties: + type: object + 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 + 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 diff --git a/specs/predict/responses/UserNotFound.yml b/specs/predict/responses/UserNotFound.yml new file mode 100644 index 0000000000..6476b08812 --- /dev/null +++ b/specs/predict/responses/UserNotFound.yml @@ -0,0 +1,5 @@ +description: User not found. +content: + application/json: + schema: + $ref: ../schemas/ErrorBase.yml diff --git a/specs/predict/schemas/ErrorBase.yml b/specs/predict/schemas/ErrorBase.yml new file mode 100644 index 0000000000..7fa8e49656 --- /dev/null +++ b/specs/predict/schemas/ErrorBase.yml @@ -0,0 +1,7 @@ +description: Error. +type: object +additionalProperties: true +properties: + message: + type: string + example: Invalid Application-Id or API-Key diff --git a/specs/predict/spec.yml b/specs/predict/spec.yml new file mode 100644 index 0000000000..8ca8eb61b6 --- /dev/null +++ b/specs/predict/spec.yml @@ -0,0 +1,22 @@ +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 + variables: + appId: + default: myAppId +security: + - appId: [] + apiKey: [] +paths: + /1/users/{userID}/fetch: + $ref: paths/fetchUserProfile.yml From 8bf243515c29efbeae4f27e960bc821a469544ba Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 1 Feb 2022 13:45:32 +0200 Subject: [PATCH 02/27] Fix errors --- specs/predict/common/parameters.yml | 29 ++------------- specs/predict/paths/fetchUserProfile.yml | 45 ++++++++++++++++++------ specs/predict/spec.yml | 3 -- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/specs/predict/common/parameters.yml b/specs/predict/common/parameters.yml index 97bdb2aa08..c2b74e9b98 100644 --- a/specs/predict/common/parameters.yml +++ b/specs/predict/common/parameters.yml @@ -2,34 +2,9 @@ userID: name: userID in: path required: true + schema: + type: string description: | This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) - schema: - type: string - -modelsToRetrieve: - name: modelsToRetrieve - description: List with model types for which to retrieve predictions - schema: - type: array - items: - type: string - enum: - - funnel_stage - - order_value - - affinities - minItems: 1 - -typesToRetrieve: - name: typesToRetrieve - description: List with types to be retrieved. - schema: - type: array - items: - type: string - enum: - - properties - - segments - minItems: 1 diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index 6fc0dd98bd..8987cd8c42 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -12,11 +12,37 @@ post: The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. - summary: Get user profile + summary: Get user profile parameters: - $ref: '../common/parameters.yml#/userID' - - $ref: '../common/parameters.yml#/modelsToRetrieve' - - $ref: '../common/parameters.yml#/typesToRetrieve' + + requestBody: + required: true + content: + application/json: + schema: + additionalProperties: false + properties: + modelsToRetrieve: + description: List with model types for which to retrieve predictions + type: array + items: + type: string + enum: + - funnel_stage + - order_value + - affinities + minItems: 1 + typesToRetrieve: + description: List with types to be retrieved. + type: array + items: + type: string + enum: + - properties + - segments + minItems: 1 + responses: '200': description: OK @@ -25,12 +51,11 @@ post: schema: title: fetchUserProfileResponse type: object - # additionalProperties: false required: - user properties: user: - $ref: '../common/parameters.yml#/userID' + type: string predictions: type: object properties: @@ -54,8 +79,8 @@ post: - transaction probability: type: number - min: 0 - max: 1 + minimum: 0 + maximum: 1 lastUpdatedAt: type: string order_value: @@ -64,7 +89,7 @@ post: properties: value: type: number - min: 0 + minimum: 0 lastUpdatedAt: type: string affinities: @@ -82,8 +107,8 @@ post: type: string probability: type: number - min: 0 - max: 1 + minimum: 0 + maximum: 1 lastUpdatedAt: type: string properties: diff --git a/specs/predict/spec.yml b/specs/predict/spec.yml index 8ca8eb61b6..23f1665f25 100644 --- a/specs/predict/spec.yml +++ b/specs/predict/spec.yml @@ -11,9 +11,6 @@ components: $ref: '../common/securitySchemes.yml#/apiKey' servers: - url: https://predict-api-oslcbws3zq-ew.a.run.app - variables: - appId: - default: myAppId security: - appId: [] apiKey: [] From 8eb49db9f8dfddbab7e3b0be55f66544b7516aca Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 1 Feb 2022 13:50:05 +0200 Subject: [PATCH 03/27] Add Javascript client --- openapitools.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/openapitools.json b/openapitools.json index 4c4eba0dba..d235b03a36 100644 --- a/openapitools.json +++ b/openapitools.json @@ -198,6 +198,18 @@ "packageName": "algoliasearch-client-java-2" } + }, + "javascript-predict": { + "generatorName": "typescript-node", + "templateDir": "#{cwd}/templates/javascript/", + "config": "#{cwd}/openapitools.json", + "apiPackage": "src", + "output": "#{cwd}/clients/algoliasearch-client-javascript/predict", + "glob": "specs/dist/predict.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-javascript", + "reservedWordsMappings": "queryParameters=queryParameters" } } } From b5f01ca24c4502565de7ab38568472f1ab01d521 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 1 Feb 2022 14:16:07 +0200 Subject: [PATCH 04/27] Update configuration --- openapitools.json | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openapitools.json b/openapitools.json index d235b03a36..06a405e23c 100644 --- a/openapitools.json +++ b/openapitools.json @@ -204,12 +204,19 @@ "templateDir": "#{cwd}/templates/javascript/", "config": "#{cwd}/openapitools.json", "apiPackage": "src", - "output": "#{cwd}/clients/algoliasearch-client-javascript/predict", + "output": "#{cwd}/clients/algoliasearch-client-javascript/client-predict", "glob": "specs/dist/predict.yml", "gitHost": "algolia", "gitUserId": "algolia", "gitRepoId": "algoliasearch-client-javascript", - "reservedWordsMappings": "queryParameters=queryParameters" + "additionalProperties": { + "modelPropertyNaming": "original", + "supportsES6": true, + "npmName": "@algolia/client-predict", + "packageVersion": "5.0.0", + "packageName": "@algolia/client-predict", + "host": "predict" + } } } } From 5cb44255c6e307adac94220a762a201a64fb7f9a Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 1 Feb 2022 14:21:37 +0200 Subject: [PATCH 05/27] Add JavaScript API client --- .../client-predict/.gitignore | 4 + .../client-predict/.openapi-generator-ignore | 23 ++ .../client-predict/api.ts | 2 + .../client-predict/git_push.sh | 57 ++++ .../client-predict/model/errorBase.ts | 11 + .../model/fetchUserProfileResponse.ts | 14 + .../fetchUserProfileResponsePredictions.ts | 13 + ...serProfileResponsePredictionsAffinities.ts | 13 + ...ofileResponsePredictionsAffinitiesValue.ts | 10 + ...erProfileResponsePredictionsFunnelStage.ts | 13 + ...fileResponsePredictionsFunnelStageValue.ts | 11 + ...serProfileResponsePredictionsOrderValue.ts | 12 + .../fetchUserProfileResponseProperties.ts | 22 ++ .../model/fetchUserProfileResponseSegments.ts | 18 ++ .../client-predict/model/inlineObject.ts | 19 ++ .../client-predict/model/models.ts | 255 ++++++++++++++++++ .../client-predict/package.json | 26 ++ .../client-predict/src/apis.ts | 5 + .../client-predict/src/predictApi.ts | 153 +++++++++++ .../client-predict/tsconfig.json | 22 ++ yarn.lock | 10 + 21 files changed, 713 insertions(+) create mode 100644 clients/algoliasearch-client-javascript/client-predict/.gitignore create mode 100644 clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore create mode 100644 clients/algoliasearch-client-javascript/client-predict/api.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/git_push.sh create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/models.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/package.json create mode 100644 clients/algoliasearch-client-javascript/client-predict/src/apis.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/tsconfig.json diff --git a/clients/algoliasearch-client-javascript/client-predict/.gitignore b/clients/algoliasearch-client-javascript/client-predict/.gitignore new file mode 100644 index 0000000000..8aafcdc3fd --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/.gitignore @@ -0,0 +1,4 @@ +node_modules +dist +.openapi-generator +.env diff --git a/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore new file mode 100644 index 0000000000..7484ee590a --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# 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. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/clients/algoliasearch-client-javascript/client-predict/api.ts b/clients/algoliasearch-client-javascript/client-predict/api.ts new file mode 100644 index 0000000000..c4759f623a --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/api.ts @@ -0,0 +1,2 @@ +// This is the entrypoint for the package +export * from './src/apis'; diff --git a/clients/algoliasearch-client-javascript/client-predict/git_push.sh b/clients/algoliasearch-client-javascript/client-predict/git_push.sh new file mode 100644 index 0000000000..b151edf823 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="algolia" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="algolia" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="algoliasearch-client-javascript" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts b/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts new file mode 100644 index 0000000000..d90c6c2793 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts @@ -0,0 +1,11 @@ + + +/** +* Error. +*/ +export type ErrorBase = { + message?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts new file mode 100644 index 0000000000..7d65d2034f --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts @@ -0,0 +1,14 @@ +import { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; +import { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; +import { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; + + +export type FetchUserProfileResponse = { + user: string; + predictions?: FetchUserProfileResponsePredictions; + properties?: FetchUserProfileResponseProperties; + segments?: FetchUserProfileResponseSegments; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts new file mode 100644 index 0000000000..68fd5c71ae --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts @@ -0,0 +1,13 @@ +import { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; +import { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; +import { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; + + +export type FetchUserProfileResponsePredictions = { + funnel_stage?: FetchUserProfileResponsePredictionsFunnelStage; + order_value?: FetchUserProfileResponsePredictionsOrderValue; + affinities?: FetchUserProfileResponsePredictionsAffinities; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts new file mode 100644 index 0000000000..9cdd3d76cd --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts @@ -0,0 +1,13 @@ +import { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; + + +/** +* Prediction for the **affinities** model +*/ +export type FetchUserProfileResponsePredictionsAffinities = { + value?: Array; + lastUpdatedAt?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts new file mode 100644 index 0000000000..37455aff1f --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts @@ -0,0 +1,10 @@ + + +export type FetchUserProfileResponsePredictionsAffinitiesValue = { + name?: string; + value?: string; + probability?: number; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts new file mode 100644 index 0000000000..bc26169171 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts @@ -0,0 +1,13 @@ +import { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; + + +/** +* Prediction for the **funnel_stage** model +*/ +export type FetchUserProfileResponsePredictionsFunnelStage = { + value?: Array; + lastUpdatedAt?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts new file mode 100644 index 0000000000..1a5c8cf11c --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts @@ -0,0 +1,11 @@ + + +export type FetchUserProfileResponsePredictionsFunnelStageValue = { + name?: FetchUserProfileResponsePredictionsFunnelStageValueName; + probability?: number; +} + +export type FetchUserProfileResponsePredictionsFunnelStageValueName = 'all_visits'|'click_product_list'|'product_view'|'add_to_cart'|'checkout'|'transaction' + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts new file mode 100644 index 0000000000..630d6fb639 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts @@ -0,0 +1,12 @@ + + +/** +* Prediction for the **order_value** model +*/ +export type FetchUserProfileResponsePredictionsOrderValue = { + value?: number; + lastUpdatedAt?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts new file mode 100644 index 0000000000..912f8ac077 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts @@ -0,0 +1,22 @@ + + +/** +* Properties for the user profile +*/ +export type FetchUserProfileResponseProperties = { + /** + * Raw user properties (key-value pairs) + */ + raw?: object; + /** + * Computed user properties (key-value pairs) + */ + computed?: object; + /** + * Custom user properties (key-value pairs) + */ + custom?: object; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts new file mode 100644 index 0000000000..518f495f1b --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts @@ -0,0 +1,18 @@ + + +/** +* Segments that the user belongs to +*/ +export type FetchUserProfileResponseSegments = { + /** + * List of computed segments IDs + */ + computed?: Array; + /** + * List of custom segments IDs + */ + custom?: Array; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts new file mode 100644 index 0000000000..e3fc86d679 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts @@ -0,0 +1,19 @@ + + +export type InlineObject = { + /** + * List with model types for which to retrieve predictions + */ + modelsToRetrieve?: InlineObjectModelsToRetrieve[]; + /** + * List with types to be retrieved. + */ + typesToRetrieve?: InlineObjectTypesToRetrieve[]; +} + +export type InlineObjectModelsToRetrieve = 'funnel_stage'|'order_value'|'affinities' + +export type InlineObjectTypesToRetrieve = 'properties'|'segments' + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/models.ts b/clients/algoliasearch-client-javascript/client-predict/model/models.ts new file mode 100644 index 0000000000..c6a0dcb682 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/models.ts @@ -0,0 +1,255 @@ +import localVarRequest from 'request'; + +export * from './errorBase'; +export * from './fetchUserProfileResponse'; +export * from './fetchUserProfileResponsePredictions'; +export * from './fetchUserProfileResponsePredictionsAffinities'; +export * from './fetchUserProfileResponsePredictionsAffinitiesValue'; +export * from './fetchUserProfileResponsePredictionsFunnelStage'; +export * from './fetchUserProfileResponsePredictionsFunnelStageValue'; +export * from './fetchUserProfileResponsePredictionsOrderValue'; +export * from './fetchUserProfileResponseProperties'; +export * from './fetchUserProfileResponseSegments'; +export * from './inlineObject'; + +import * as fs from 'fs'; + +export interface RequestDetailedFile { + value: Buffer; + options?: { + filename?: string; + contentType?: string; + } +} + +export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; + + +import { ErrorBase } from './errorBase'; +import { FetchUserProfileResponse } from './fetchUserProfileResponse'; +import { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; +import { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; +import { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; +import { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; +import { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; +import { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; +import { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; +import { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; +import { InlineObject } from './inlineObject'; + +/* tslint:disable:no-unused-variable */ +let primitives = [ + "string", + "boolean", + "double", + "integer", + "long", + "float", + "number", + "any" + ]; + +let enumsMap: {[index: string]: any} = { + "FetchUserProfileResponsePredictionsFunnelStageValue.NameEnum": FetchUserProfileResponsePredictionsFunnelStageValue.NameEnum, + "InlineObject.ModelsToRetrieveEnum": InlineObject.ModelsToRetrieveEnum, + "InlineObject.TypesToRetrieveEnum": InlineObject.TypesToRetrieveEnum, +} + +let typeMap: {[index: string]: any} = { + "ErrorBase": ErrorBase, + "FetchUserProfileResponse": FetchUserProfileResponse, + "FetchUserProfileResponsePredictions": FetchUserProfileResponsePredictions, + "FetchUserProfileResponsePredictionsAffinities": FetchUserProfileResponsePredictionsAffinities, + "FetchUserProfileResponsePredictionsAffinitiesValue": FetchUserProfileResponsePredictionsAffinitiesValue, + "FetchUserProfileResponsePredictionsFunnelStage": FetchUserProfileResponsePredictionsFunnelStage, + "FetchUserProfileResponsePredictionsFunnelStageValue": FetchUserProfileResponsePredictionsFunnelStageValue, + "FetchUserProfileResponsePredictionsOrderValue": FetchUserProfileResponsePredictionsOrderValue, + "FetchUserProfileResponseProperties": FetchUserProfileResponseProperties, + "FetchUserProfileResponseSegments": FetchUserProfileResponseSegments, + "InlineObject": InlineObject, +} + +export class ObjectSerializer { + public static findCorrectType(data: any, expectedType: string) { + if (data == undefined) { + return expectedType; + } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) { + return expectedType; + } else if (expectedType === "Date") { + return expectedType; + } else { + if (enumsMap[expectedType]) { + return expectedType; + } + + if (!typeMap[expectedType]) { + return expectedType; // w/e we don't know the type + } + + // Check the discriminator + let discriminatorProperty = typeMap[expectedType].discriminator; + if (discriminatorProperty == null) { + return expectedType; // the type does not have a discriminator. use it. + } else { + if (data[discriminatorProperty]) { + var discriminatorType = data[discriminatorProperty]; + if(typeMap[discriminatorType]){ + return discriminatorType; // use the type given in the discriminator + } else { + return expectedType; // discriminator did not map to a type + } + } else { + return expectedType; // discriminator was not present (or an empty string) + } + } + } + } + + public static serialize(data: any, type: string) { + if (data == undefined) { + return data; + } else if (primitives.indexOf(type.toLowerCase()) !== -1) { + return data; + } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 + let subType: string = type.replace("Array<", ""); // Array => Type> + subType = subType.substring(0, subType.length - 1); // Type> => Type + let transformedData: any[] = []; + for (let index = 0; index < data.length; index++) { + let datum = data[index]; + transformedData.push(ObjectSerializer.serialize(datum, subType)); + } + return transformedData; + } else if (type === "Date") { + return data.toISOString(); + } else { + if (enumsMap[type]) { + return data; + } + if (!typeMap[type]) { // in case we dont know the type + return data; + } + + // Get the actual type of this object + type = this.findCorrectType(data, type); + + // get the map for the correct type. + let attributeTypes = typeMap[type].getAttributeTypeMap(); + let instance: {[index: string]: any} = {}; + for (let index = 0; index < attributeTypes.length; index++) { + let attributeType = attributeTypes[index]; + instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type); + } + return instance; + } + } + + public static deserialize(data: any, type: string) { + // polymorphism may change the actual type. + type = ObjectSerializer.findCorrectType(data, type); + if (data == undefined) { + return data; + } else if (primitives.indexOf(type.toLowerCase()) !== -1) { + return data; + } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 + let subType: string = type.replace("Array<", ""); // Array => Type> + subType = subType.substring(0, subType.length - 1); // Type> => Type + let transformedData: any[] = []; + for (let index = 0; index < data.length; index++) { + let datum = data[index]; + transformedData.push(ObjectSerializer.deserialize(datum, subType)); + } + return transformedData; + } else if (type === "Date") { + return new Date(data); + } else { + if (enumsMap[type]) {// is Enum + return data; + } + + if (!typeMap[type]) { // dont know the type + return data; + } + let instance = new typeMap[type](); + let attributeTypes = typeMap[type].getAttributeTypeMap(); + for (let index = 0; index < attributeTypes.length; index++) { + let attributeType = attributeTypes[index]; + instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type); + } + return instance; + } + } +} + +export interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: localVarRequest.Options): Promise | void; +} + +export class HttpBasicAuth implements Authentication { + public username: string = ''; + public password: string = ''; + + applyToRequest(requestOptions: localVarRequest.Options): void { + requestOptions.auth = { + username: this.username, password: this.password + } + } +} + +export class HttpBearerAuth implements Authentication { + public accessToken: string | (() => string) = ''; + + applyToRequest(requestOptions: localVarRequest.Options): void { + if (requestOptions && requestOptions.headers) { + const accessToken = typeof this.accessToken === 'function' + ? this.accessToken() + : this.accessToken; + requestOptions.headers["Authorization"] = "Bearer " + accessToken; + } + } +} + +export class ApiKeyAuth implements Authentication { + public apiKey: string = ''; + + constructor(private location: string, private paramName: string) { + } + + applyToRequest(requestOptions: localVarRequest.Options): void { + if (this.location == "query") { + (requestOptions.qs)[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); + } + } + } +} + +export class OAuth implements Authentication { + public accessToken: string = ''; + + applyToRequest(requestOptions: localVarRequest.Options): void { + if (requestOptions && requestOptions.headers) { + requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; + } + } +} + +export class VoidAuth implements Authentication { + public username: string = ''; + public password: string = ''; + + applyToRequest(_: localVarRequest.Options): void { + // Do nothing + } +} + +export type Interceptor = (requestOptions: localVarRequest.Options) => (Promise | void); diff --git a/clients/algoliasearch-client-javascript/client-predict/package.json b/clients/algoliasearch-client-javascript/client-predict/package.json new file mode 100644 index 0000000000..b0744cafc3 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/package.json @@ -0,0 +1,26 @@ +{ + "name": "@algolia/client-predict", + "version": "5.0.0", + "description": "JavaScript client for @algolia/client-predict", + "repository": "algolia/algoliasearch-client-javascript", + "author": "Algolia", + "private": true, + "license": "MIT", + "main": "dist/api.js", + "types": "dist/api.d.ts", + "scripts": { + "build": "tsc", + "clean": "rm -rf dist/" + }, + "engines": { + "node": "^16.0.0", + "yarn": "^3.0.0" + }, + "dependencies": { + "@algolia/client-common": "5.0.0" + }, + "devDependencies": { + "@types/node": "16.11.11", + "typescript": "4.5.4" + } +} diff --git a/clients/algoliasearch-client-javascript/client-predict/src/apis.ts b/clients/algoliasearch-client-javascript/client-predict/src/apis.ts new file mode 100644 index 0000000000..06eae5f6ac --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/src/apis.ts @@ -0,0 +1,5 @@ +export * from './predictApi'; +import { PredictApi } from './predictApi'; +export * from '@algolia/client-common'; + +export const APIS = [PredictApi]; diff --git a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts new file mode 100644 index 0000000000..14644f7bc1 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts @@ -0,0 +1,153 @@ +import { shuffle, Transporter } from '@algolia/client-common'; +import type { Headers, Requester, Host, Request, RequestOptions } from '@algolia/client-common'; + +import { ErrorBase } from '../model/errorBase'; +import { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; +import { InlineObject } from '../model/inlineObject'; + +export const version = '5.0.0'; + + +export class PredictApi { + protected authentications = { + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', + }; + + private transporter: Transporter; + + private applyAuthenticationHeaders( + requestOptions: RequestOptions + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; + } + + return requestOptions; + } + + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); + } + + constructor( + appId: string, + apiKey: string, + options?: {requester?: Requester, hosts?: Host[]} + ) { + if (!appId) { + throw new Error("`appId` is missing."); + } + if (!apiKey) { + throw new Error("`apiKey` is missing."); + } + + this.setAuthentication({ appId, apiKey }); + + this.transporter = new Transporter({ + hosts: options?.hosts ?? this.getDefaultHosts( + + + ), + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded' + }, + userAgent: 'Algolia for Javascript (5.0.0)', + timeouts: { + connect: 2, + read: 5, + write: 30, + }, + requester: options?.requester, + }); + } + + + + public getDefaultHosts(): Host[] { + return [{ url: 'predict.algolia.io', accept: 'readWrite', protocol: 'https' }]; + } + + public setRequest(requester: Requester): void { + this.transporter.setRequester(requester); + } + + public setHosts(hosts: Host[]): void { + this.transporter.setHosts(hosts); + } + + public setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; + } + + /** + * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for an authenticated user (userID) or an anonymous user (cookieID). The predictions can be goals, metrics or affinities: * **Goals** ML models compute the probability for an action. Ex. A funnel stage model can output the next stage in the user conversion funnel - add_to_cart with a probability of 72%. * **Metrics** ML models output a number. Ex. Next order value is 172.43 USD. Since metrics models are usually based on regression, these predictions have a single value without a probability attached to it. * **Affinities** ML models output a set of item attributes with associated probabilities. Ex. a user is interested in items with the following characteristics: *color: red* (56% probability), *brand: Adidas* (67% probability). The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. + * @summary Get user profile + * @param fetchUserProfile - The fetchUserProfile object. + * @param fetchUserProfile.userID This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) + * @param fetchUserProfile.inlineObject The inlineObject object. + */ + public fetchUserProfile( + { + userID, + inlineObject, + }: FetchUserProfileProps + ) : Promise { + const path = '/1/users/{userID}/fetch'.replace( + '{userID}', + encodeURIComponent(String(userID)) + ); + let headers: Headers = { Accept: 'application/json' }; + let queryParameters: Record = {}; + + if (!userID) { + throw new Error('Parameter `userID` is required when calling `fetchUserProfile`.'); + } + + + if (!inlineObject) { + throw new Error('Parameter `inlineObject` is required when calling `fetchUserProfile`.'); + } + + + + const request: Request = { + method: 'POST', + path, + data: inlineObject, + }; + + const requestOptions: RequestOptions = { + headers, + queryParameters + }; + + return this.sendRequest(request, requestOptions); + } +} + +export type FetchUserProfileProps = { + /** + * This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) + */ + userID: string; + inlineObject: InlineObject; +} + + diff --git a/clients/algoliasearch-client-javascript/client-predict/tsconfig.json b/clients/algoliasearch-client-javascript/client-predict/tsconfig.json new file mode 100644 index 0000000000..2f72c93ccb --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "ES6", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "strict": true, + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "noLib": false, + "declaration": true, + "lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"], + "outDir": "dist", + "typeRoots": ["node_modules/@types"], + "types": ["node"] + }, + "include": ["src", "model", "api.ts"], + "exclude": ["dist", "node_modules"] +} diff --git a/yarn.lock b/yarn.lock index dacd71a146..de92ce6782 100644 --- a/yarn.lock +++ b/yarn.lock @@ -81,6 +81,16 @@ __metadata: languageName: unknown linkType: soft +"@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict": + version: 0.0.0-use.local + resolution: "@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict" + dependencies: + "@algolia/client-common": 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/client-query-suggestions": version: 0.0.0-use.local resolution: "@algolia/client-query-suggestions@workspace:clients/algoliasearch-client-javascript/client-query-suggestions" From 4f779f135e1f3a3a9df4396dc18fcc70a6079dbb Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Mon, 31 Jan 2022 17:12:29 +0200 Subject: [PATCH 06/27] Fetch user profile endpoint --- specs/predict/common/parameters.yml | 35 +++++++ specs/predict/paths/fetchUserProfile.yml | 119 +++++++++++++++++++++++ specs/predict/responses/UserNotFound.yml | 5 + specs/predict/schemas/ErrorBase.yml | 7 ++ specs/predict/spec.yml | 22 +++++ 5 files changed, 188 insertions(+) create mode 100644 specs/predict/common/parameters.yml create mode 100644 specs/predict/paths/fetchUserProfile.yml create mode 100644 specs/predict/responses/UserNotFound.yml create mode 100644 specs/predict/schemas/ErrorBase.yml create mode 100644 specs/predict/spec.yml diff --git a/specs/predict/common/parameters.yml b/specs/predict/common/parameters.yml new file mode 100644 index 0000000000..97bdb2aa08 --- /dev/null +++ b/specs/predict/common/parameters.yml @@ -0,0 +1,35 @@ +userID: + name: userID + in: path + required: true + description: | + This parameter can have different values: + * An user ID for authenticated users. + * A cookie ID for non-authenticated repeated users (visitors) + schema: + type: string + +modelsToRetrieve: + name: modelsToRetrieve + description: List with model types for which to retrieve predictions + schema: + type: array + items: + type: string + enum: + - funnel_stage + - order_value + - affinities + minItems: 1 + +typesToRetrieve: + name: typesToRetrieve + description: List with types to be retrieved. + schema: + type: array + items: + type: string + enum: + - properties + - segments + minItems: 1 diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml new file mode 100644 index 0000000000..6fc0dd98bd --- /dev/null +++ b/specs/predict/paths/fetchUserProfile.yml @@ -0,0 +1,119 @@ +post: + tags: + - predict + operationId: fetchUserProfile + description: | + Get predictions, properties (raw, computed or custom) and segments (computed or custom) for an authenticated user (userID) or an anonymous user (cookieID). + + The predictions can be goals, metrics or affinities: + * **Goals** ML models compute the probability for an action. Ex. A funnel stage model can output the next stage in the user conversion funnel - add_to_cart with a probability of 72%. + * **Metrics** ML models output a number. Ex. Next order value is 172.43 USD. Since metrics models are usually based on regression, these predictions have a single value without a probability attached to it. + * **Affinities** ML models output a set of item attributes with associated probabilities. Ex. a user is interested in items with the following characteristics: *color: red* (56% probability), *brand: Adidas* (67% probability). + + The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. + + summary: Get user profile + parameters: + - $ref: '../common/parameters.yml#/userID' + - $ref: '../common/parameters.yml#/modelsToRetrieve' + - $ref: '../common/parameters.yml#/typesToRetrieve' + responses: + '200': + description: OK + content: + application/json: + schema: + title: fetchUserProfileResponse + type: object + # additionalProperties: false + required: + - user + properties: + user: + $ref: '../common/parameters.yml#/userID' + predictions: + type: object + properties: + funnel_stage: + type: object + description: Prediction for the **funnel_stage** model + properties: + value: + type: array + items: + type: object + properties: + name: + type: string + enum: + - all_visits + - click_product_list + - product_view + - add_to_cart + - checkout + - transaction + probability: + type: number + min: 0 + max: 1 + lastUpdatedAt: + type: string + order_value: + type: object + description: Prediction for the **order_value** model + properties: + value: + type: number + min: 0 + lastUpdatedAt: + type: string + affinities: + type: object + description: Prediction for the **affinities** model + properties: + value: + type: array + items: + type: object + properties: + name: + type: string + value: + type: string + probability: + type: number + min: 0 + max: 1 + lastUpdatedAt: + type: string + properties: + type: object + 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 + 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 diff --git a/specs/predict/responses/UserNotFound.yml b/specs/predict/responses/UserNotFound.yml new file mode 100644 index 0000000000..6476b08812 --- /dev/null +++ b/specs/predict/responses/UserNotFound.yml @@ -0,0 +1,5 @@ +description: User not found. +content: + application/json: + schema: + $ref: ../schemas/ErrorBase.yml diff --git a/specs/predict/schemas/ErrorBase.yml b/specs/predict/schemas/ErrorBase.yml new file mode 100644 index 0000000000..7fa8e49656 --- /dev/null +++ b/specs/predict/schemas/ErrorBase.yml @@ -0,0 +1,7 @@ +description: Error. +type: object +additionalProperties: true +properties: + message: + type: string + example: Invalid Application-Id or API-Key diff --git a/specs/predict/spec.yml b/specs/predict/spec.yml new file mode 100644 index 0000000000..8ca8eb61b6 --- /dev/null +++ b/specs/predict/spec.yml @@ -0,0 +1,22 @@ +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 + variables: + appId: + default: myAppId +security: + - appId: [] + apiKey: [] +paths: + /1/users/{userID}/fetch: + $ref: paths/fetchUserProfile.yml From 0a65382116d02c24cde237df81a16d9fe19f9192 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 1 Feb 2022 13:45:32 +0200 Subject: [PATCH 07/27] Fix errors --- specs/predict/common/parameters.yml | 29 ++------------- specs/predict/paths/fetchUserProfile.yml | 45 ++++++++++++++++++------ specs/predict/spec.yml | 3 -- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/specs/predict/common/parameters.yml b/specs/predict/common/parameters.yml index 97bdb2aa08..c2b74e9b98 100644 --- a/specs/predict/common/parameters.yml +++ b/specs/predict/common/parameters.yml @@ -2,34 +2,9 @@ userID: name: userID in: path required: true + schema: + type: string description: | This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) - schema: - type: string - -modelsToRetrieve: - name: modelsToRetrieve - description: List with model types for which to retrieve predictions - schema: - type: array - items: - type: string - enum: - - funnel_stage - - order_value - - affinities - minItems: 1 - -typesToRetrieve: - name: typesToRetrieve - description: List with types to be retrieved. - schema: - type: array - items: - type: string - enum: - - properties - - segments - minItems: 1 diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index 6fc0dd98bd..8987cd8c42 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -12,11 +12,37 @@ post: The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. - summary: Get user profile + summary: Get user profile parameters: - $ref: '../common/parameters.yml#/userID' - - $ref: '../common/parameters.yml#/modelsToRetrieve' - - $ref: '../common/parameters.yml#/typesToRetrieve' + + requestBody: + required: true + content: + application/json: + schema: + additionalProperties: false + properties: + modelsToRetrieve: + description: List with model types for which to retrieve predictions + type: array + items: + type: string + enum: + - funnel_stage + - order_value + - affinities + minItems: 1 + typesToRetrieve: + description: List with types to be retrieved. + type: array + items: + type: string + enum: + - properties + - segments + minItems: 1 + responses: '200': description: OK @@ -25,12 +51,11 @@ post: schema: title: fetchUserProfileResponse type: object - # additionalProperties: false required: - user properties: user: - $ref: '../common/parameters.yml#/userID' + type: string predictions: type: object properties: @@ -54,8 +79,8 @@ post: - transaction probability: type: number - min: 0 - max: 1 + minimum: 0 + maximum: 1 lastUpdatedAt: type: string order_value: @@ -64,7 +89,7 @@ post: properties: value: type: number - min: 0 + minimum: 0 lastUpdatedAt: type: string affinities: @@ -82,8 +107,8 @@ post: type: string probability: type: number - min: 0 - max: 1 + minimum: 0 + maximum: 1 lastUpdatedAt: type: string properties: diff --git a/specs/predict/spec.yml b/specs/predict/spec.yml index 8ca8eb61b6..23f1665f25 100644 --- a/specs/predict/spec.yml +++ b/specs/predict/spec.yml @@ -11,9 +11,6 @@ components: $ref: '../common/securitySchemes.yml#/apiKey' servers: - url: https://predict-api-oslcbws3zq-ew.a.run.app - variables: - appId: - default: myAppId security: - appId: [] apiKey: [] From e082c8b0ab8ec2f2556582d019f9a55f9dd47f11 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 1 Feb 2022 13:50:05 +0200 Subject: [PATCH 08/27] Add Javascript client --- openapitools.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/openapitools.json b/openapitools.json index 42aa40aaa4..b6f93fb7f6 100644 --- a/openapitools.json +++ b/openapitools.json @@ -369,8 +369,20 @@ "isEuHost": true, "host": "query-suggestions", "topLevelDomain": "com" + }, + "javascript-predict": { + "generatorName": "typescript-node", + "templateDir": "#{cwd}/templates/javascript/", + "config": "#{cwd}/openapitools.json", + "apiPackage": "src", + "output": "#{cwd}/clients/algoliasearch-client-javascript/predict", + "glob": "specs/dist/predict.yml", + "gitHost": "algolia", + "gitUserId": "algolia", + "gitRepoId": "algoliasearch-client-javascript", + "reservedWordsMappings": "queryParameters=queryParameters" } } } } -} \ No newline at end of file +} From ba67c5b8c530ae7167525ca3b6efeeac5993cf6d Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 1 Feb 2022 14:21:37 +0200 Subject: [PATCH 09/27] Add JavaScript API client --- .../client-predict/.gitignore | 4 + .../client-predict/.openapi-generator-ignore | 23 ++ .../client-predict/api.ts | 2 + .../client-predict/git_push.sh | 57 ++++ .../client-predict/model/errorBase.ts | 11 + .../model/fetchUserProfileResponse.ts | 14 + .../fetchUserProfileResponsePredictions.ts | 13 + ...serProfileResponsePredictionsAffinities.ts | 13 + ...ofileResponsePredictionsAffinitiesValue.ts | 10 + ...erProfileResponsePredictionsFunnelStage.ts | 13 + ...fileResponsePredictionsFunnelStageValue.ts | 11 + ...serProfileResponsePredictionsOrderValue.ts | 12 + .../fetchUserProfileResponseProperties.ts | 22 ++ .../model/fetchUserProfileResponseSegments.ts | 18 ++ .../client-predict/model/inlineObject.ts | 19 ++ .../client-predict/model/models.ts | 255 ++++++++++++++++++ .../client-predict/package.json | 26 ++ .../client-predict/src/apis.ts | 5 + .../client-predict/src/predictApi.ts | 153 +++++++++++ .../client-predict/tsconfig.json | 22 ++ yarn.lock | 10 + 21 files changed, 713 insertions(+) create mode 100644 clients/algoliasearch-client-javascript/client-predict/.gitignore create mode 100644 clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore create mode 100644 clients/algoliasearch-client-javascript/client-predict/api.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/git_push.sh create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/models.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/package.json create mode 100644 clients/algoliasearch-client-javascript/client-predict/src/apis.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/tsconfig.json diff --git a/clients/algoliasearch-client-javascript/client-predict/.gitignore b/clients/algoliasearch-client-javascript/client-predict/.gitignore new file mode 100644 index 0000000000..8aafcdc3fd --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/.gitignore @@ -0,0 +1,4 @@ +node_modules +dist +.openapi-generator +.env diff --git a/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore new file mode 100644 index 0000000000..7484ee590a --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# 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. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/clients/algoliasearch-client-javascript/client-predict/api.ts b/clients/algoliasearch-client-javascript/client-predict/api.ts new file mode 100644 index 0000000000..c4759f623a --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/api.ts @@ -0,0 +1,2 @@ +// This is the entrypoint for the package +export * from './src/apis'; diff --git a/clients/algoliasearch-client-javascript/client-predict/git_push.sh b/clients/algoliasearch-client-javascript/client-predict/git_push.sh new file mode 100644 index 0000000000..b151edf823 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="algolia" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="algolia" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="algoliasearch-client-javascript" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts b/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts new file mode 100644 index 0000000000..d90c6c2793 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts @@ -0,0 +1,11 @@ + + +/** +* Error. +*/ +export type ErrorBase = { + message?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts new file mode 100644 index 0000000000..7d65d2034f --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts @@ -0,0 +1,14 @@ +import { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; +import { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; +import { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; + + +export type FetchUserProfileResponse = { + user: string; + predictions?: FetchUserProfileResponsePredictions; + properties?: FetchUserProfileResponseProperties; + segments?: FetchUserProfileResponseSegments; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts new file mode 100644 index 0000000000..68fd5c71ae --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts @@ -0,0 +1,13 @@ +import { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; +import { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; +import { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; + + +export type FetchUserProfileResponsePredictions = { + funnel_stage?: FetchUserProfileResponsePredictionsFunnelStage; + order_value?: FetchUserProfileResponsePredictionsOrderValue; + affinities?: FetchUserProfileResponsePredictionsAffinities; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts new file mode 100644 index 0000000000..9cdd3d76cd --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts @@ -0,0 +1,13 @@ +import { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; + + +/** +* Prediction for the **affinities** model +*/ +export type FetchUserProfileResponsePredictionsAffinities = { + value?: Array; + lastUpdatedAt?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts new file mode 100644 index 0000000000..37455aff1f --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts @@ -0,0 +1,10 @@ + + +export type FetchUserProfileResponsePredictionsAffinitiesValue = { + name?: string; + value?: string; + probability?: number; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts new file mode 100644 index 0000000000..bc26169171 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts @@ -0,0 +1,13 @@ +import { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; + + +/** +* Prediction for the **funnel_stage** model +*/ +export type FetchUserProfileResponsePredictionsFunnelStage = { + value?: Array; + lastUpdatedAt?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts new file mode 100644 index 0000000000..1a5c8cf11c --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts @@ -0,0 +1,11 @@ + + +export type FetchUserProfileResponsePredictionsFunnelStageValue = { + name?: FetchUserProfileResponsePredictionsFunnelStageValueName; + probability?: number; +} + +export type FetchUserProfileResponsePredictionsFunnelStageValueName = 'all_visits'|'click_product_list'|'product_view'|'add_to_cart'|'checkout'|'transaction' + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts new file mode 100644 index 0000000000..630d6fb639 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts @@ -0,0 +1,12 @@ + + +/** +* Prediction for the **order_value** model +*/ +export type FetchUserProfileResponsePredictionsOrderValue = { + value?: number; + lastUpdatedAt?: string; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts new file mode 100644 index 0000000000..912f8ac077 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts @@ -0,0 +1,22 @@ + + +/** +* Properties for the user profile +*/ +export type FetchUserProfileResponseProperties = { + /** + * Raw user properties (key-value pairs) + */ + raw?: object; + /** + * Computed user properties (key-value pairs) + */ + computed?: object; + /** + * Custom user properties (key-value pairs) + */ + custom?: object; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts new file mode 100644 index 0000000000..518f495f1b --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts @@ -0,0 +1,18 @@ + + +/** +* Segments that the user belongs to +*/ +export type FetchUserProfileResponseSegments = { + /** + * List of computed segments IDs + */ + computed?: Array; + /** + * List of custom segments IDs + */ + custom?: Array; +} + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts new file mode 100644 index 0000000000..e3fc86d679 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts @@ -0,0 +1,19 @@ + + +export type InlineObject = { + /** + * List with model types for which to retrieve predictions + */ + modelsToRetrieve?: InlineObjectModelsToRetrieve[]; + /** + * List with types to be retrieved. + */ + typesToRetrieve?: InlineObjectTypesToRetrieve[]; +} + +export type InlineObjectModelsToRetrieve = 'funnel_stage'|'order_value'|'affinities' + +export type InlineObjectTypesToRetrieve = 'properties'|'segments' + + + diff --git a/clients/algoliasearch-client-javascript/client-predict/model/models.ts b/clients/algoliasearch-client-javascript/client-predict/model/models.ts new file mode 100644 index 0000000000..c6a0dcb682 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/models.ts @@ -0,0 +1,255 @@ +import localVarRequest from 'request'; + +export * from './errorBase'; +export * from './fetchUserProfileResponse'; +export * from './fetchUserProfileResponsePredictions'; +export * from './fetchUserProfileResponsePredictionsAffinities'; +export * from './fetchUserProfileResponsePredictionsAffinitiesValue'; +export * from './fetchUserProfileResponsePredictionsFunnelStage'; +export * from './fetchUserProfileResponsePredictionsFunnelStageValue'; +export * from './fetchUserProfileResponsePredictionsOrderValue'; +export * from './fetchUserProfileResponseProperties'; +export * from './fetchUserProfileResponseSegments'; +export * from './inlineObject'; + +import * as fs from 'fs'; + +export interface RequestDetailedFile { + value: Buffer; + options?: { + filename?: string; + contentType?: string; + } +} + +export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; + + +import { ErrorBase } from './errorBase'; +import { FetchUserProfileResponse } from './fetchUserProfileResponse'; +import { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; +import { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; +import { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; +import { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; +import { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; +import { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; +import { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; +import { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; +import { InlineObject } from './inlineObject'; + +/* tslint:disable:no-unused-variable */ +let primitives = [ + "string", + "boolean", + "double", + "integer", + "long", + "float", + "number", + "any" + ]; + +let enumsMap: {[index: string]: any} = { + "FetchUserProfileResponsePredictionsFunnelStageValue.NameEnum": FetchUserProfileResponsePredictionsFunnelStageValue.NameEnum, + "InlineObject.ModelsToRetrieveEnum": InlineObject.ModelsToRetrieveEnum, + "InlineObject.TypesToRetrieveEnum": InlineObject.TypesToRetrieveEnum, +} + +let typeMap: {[index: string]: any} = { + "ErrorBase": ErrorBase, + "FetchUserProfileResponse": FetchUserProfileResponse, + "FetchUserProfileResponsePredictions": FetchUserProfileResponsePredictions, + "FetchUserProfileResponsePredictionsAffinities": FetchUserProfileResponsePredictionsAffinities, + "FetchUserProfileResponsePredictionsAffinitiesValue": FetchUserProfileResponsePredictionsAffinitiesValue, + "FetchUserProfileResponsePredictionsFunnelStage": FetchUserProfileResponsePredictionsFunnelStage, + "FetchUserProfileResponsePredictionsFunnelStageValue": FetchUserProfileResponsePredictionsFunnelStageValue, + "FetchUserProfileResponsePredictionsOrderValue": FetchUserProfileResponsePredictionsOrderValue, + "FetchUserProfileResponseProperties": FetchUserProfileResponseProperties, + "FetchUserProfileResponseSegments": FetchUserProfileResponseSegments, + "InlineObject": InlineObject, +} + +export class ObjectSerializer { + public static findCorrectType(data: any, expectedType: string) { + if (data == undefined) { + return expectedType; + } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) { + return expectedType; + } else if (expectedType === "Date") { + return expectedType; + } else { + if (enumsMap[expectedType]) { + return expectedType; + } + + if (!typeMap[expectedType]) { + return expectedType; // w/e we don't know the type + } + + // Check the discriminator + let discriminatorProperty = typeMap[expectedType].discriminator; + if (discriminatorProperty == null) { + return expectedType; // the type does not have a discriminator. use it. + } else { + if (data[discriminatorProperty]) { + var discriminatorType = data[discriminatorProperty]; + if(typeMap[discriminatorType]){ + return discriminatorType; // use the type given in the discriminator + } else { + return expectedType; // discriminator did not map to a type + } + } else { + return expectedType; // discriminator was not present (or an empty string) + } + } + } + } + + public static serialize(data: any, type: string) { + if (data == undefined) { + return data; + } else if (primitives.indexOf(type.toLowerCase()) !== -1) { + return data; + } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 + let subType: string = type.replace("Array<", ""); // Array => Type> + subType = subType.substring(0, subType.length - 1); // Type> => Type + let transformedData: any[] = []; + for (let index = 0; index < data.length; index++) { + let datum = data[index]; + transformedData.push(ObjectSerializer.serialize(datum, subType)); + } + return transformedData; + } else if (type === "Date") { + return data.toISOString(); + } else { + if (enumsMap[type]) { + return data; + } + if (!typeMap[type]) { // in case we dont know the type + return data; + } + + // Get the actual type of this object + type = this.findCorrectType(data, type); + + // get the map for the correct type. + let attributeTypes = typeMap[type].getAttributeTypeMap(); + let instance: {[index: string]: any} = {}; + for (let index = 0; index < attributeTypes.length; index++) { + let attributeType = attributeTypes[index]; + instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type); + } + return instance; + } + } + + public static deserialize(data: any, type: string) { + // polymorphism may change the actual type. + type = ObjectSerializer.findCorrectType(data, type); + if (data == undefined) { + return data; + } else if (primitives.indexOf(type.toLowerCase()) !== -1) { + return data; + } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 + let subType: string = type.replace("Array<", ""); // Array => Type> + subType = subType.substring(0, subType.length - 1); // Type> => Type + let transformedData: any[] = []; + for (let index = 0; index < data.length; index++) { + let datum = data[index]; + transformedData.push(ObjectSerializer.deserialize(datum, subType)); + } + return transformedData; + } else if (type === "Date") { + return new Date(data); + } else { + if (enumsMap[type]) {// is Enum + return data; + } + + if (!typeMap[type]) { // dont know the type + return data; + } + let instance = new typeMap[type](); + let attributeTypes = typeMap[type].getAttributeTypeMap(); + for (let index = 0; index < attributeTypes.length; index++) { + let attributeType = attributeTypes[index]; + instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type); + } + return instance; + } + } +} + +export interface Authentication { + /** + * Apply authentication settings to header and query params. + */ + applyToRequest(requestOptions: localVarRequest.Options): Promise | void; +} + +export class HttpBasicAuth implements Authentication { + public username: string = ''; + public password: string = ''; + + applyToRequest(requestOptions: localVarRequest.Options): void { + requestOptions.auth = { + username: this.username, password: this.password + } + } +} + +export class HttpBearerAuth implements Authentication { + public accessToken: string | (() => string) = ''; + + applyToRequest(requestOptions: localVarRequest.Options): void { + if (requestOptions && requestOptions.headers) { + const accessToken = typeof this.accessToken === 'function' + ? this.accessToken() + : this.accessToken; + requestOptions.headers["Authorization"] = "Bearer " + accessToken; + } + } +} + +export class ApiKeyAuth implements Authentication { + public apiKey: string = ''; + + constructor(private location: string, private paramName: string) { + } + + applyToRequest(requestOptions: localVarRequest.Options): void { + if (this.location == "query") { + (requestOptions.qs)[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); + } + } + } +} + +export class OAuth implements Authentication { + public accessToken: string = ''; + + applyToRequest(requestOptions: localVarRequest.Options): void { + if (requestOptions && requestOptions.headers) { + requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; + } + } +} + +export class VoidAuth implements Authentication { + public username: string = ''; + public password: string = ''; + + applyToRequest(_: localVarRequest.Options): void { + // Do nothing + } +} + +export type Interceptor = (requestOptions: localVarRequest.Options) => (Promise | void); diff --git a/clients/algoliasearch-client-javascript/client-predict/package.json b/clients/algoliasearch-client-javascript/client-predict/package.json new file mode 100644 index 0000000000..b0744cafc3 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/package.json @@ -0,0 +1,26 @@ +{ + "name": "@algolia/client-predict", + "version": "5.0.0", + "description": "JavaScript client for @algolia/client-predict", + "repository": "algolia/algoliasearch-client-javascript", + "author": "Algolia", + "private": true, + "license": "MIT", + "main": "dist/api.js", + "types": "dist/api.d.ts", + "scripts": { + "build": "tsc", + "clean": "rm -rf dist/" + }, + "engines": { + "node": "^16.0.0", + "yarn": "^3.0.0" + }, + "dependencies": { + "@algolia/client-common": "5.0.0" + }, + "devDependencies": { + "@types/node": "16.11.11", + "typescript": "4.5.4" + } +} diff --git a/clients/algoliasearch-client-javascript/client-predict/src/apis.ts b/clients/algoliasearch-client-javascript/client-predict/src/apis.ts new file mode 100644 index 0000000000..06eae5f6ac --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/src/apis.ts @@ -0,0 +1,5 @@ +export * from './predictApi'; +import { PredictApi } from './predictApi'; +export * from '@algolia/client-common'; + +export const APIS = [PredictApi]; diff --git a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts new file mode 100644 index 0000000000..14644f7bc1 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts @@ -0,0 +1,153 @@ +import { shuffle, Transporter } from '@algolia/client-common'; +import type { Headers, Requester, Host, Request, RequestOptions } from '@algolia/client-common'; + +import { ErrorBase } from '../model/errorBase'; +import { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; +import { InlineObject } from '../model/inlineObject'; + +export const version = '5.0.0'; + + +export class PredictApi { + protected authentications = { + apiKey: 'Algolia-API-Key', + appId: 'Algolia-Application-Id', + }; + + private transporter: Transporter; + + private applyAuthenticationHeaders( + requestOptions: RequestOptions + ): RequestOptions { + if (requestOptions?.headers) { + return { + ...requestOptions, + headers: { + ...requestOptions.headers, + 'X-Algolia-API-Key': this.authentications.apiKey, + 'X-Algolia-Application-Id': this.authentications.appId, + }, + }; + } + + return requestOptions; + } + + private sendRequest( + request: Request, + requestOptions: RequestOptions + ): Promise { + return this.transporter.request( + request, + this.applyAuthenticationHeaders(requestOptions) + ); + } + + constructor( + appId: string, + apiKey: string, + options?: {requester?: Requester, hosts?: Host[]} + ) { + if (!appId) { + throw new Error("`appId` is missing."); + } + if (!apiKey) { + throw new Error("`apiKey` is missing."); + } + + this.setAuthentication({ appId, apiKey }); + + this.transporter = new Transporter({ + hosts: options?.hosts ?? this.getDefaultHosts( + + + ), + baseHeaders: { + 'content-type': 'application/x-www-form-urlencoded' + }, + userAgent: 'Algolia for Javascript (5.0.0)', + timeouts: { + connect: 2, + read: 5, + write: 30, + }, + requester: options?.requester, + }); + } + + + + public getDefaultHosts(): Host[] { + return [{ url: 'predict.algolia.io', accept: 'readWrite', protocol: 'https' }]; + } + + public setRequest(requester: Requester): void { + this.transporter.setRequester(requester); + } + + public setHosts(hosts: Host[]): void { + this.transporter.setHosts(hosts); + } + + public setAuthentication({ appId, apiKey }): void { + this.authentications = { + apiKey, + appId, + }; + } + + /** + * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for an authenticated user (userID) or an anonymous user (cookieID). The predictions can be goals, metrics or affinities: * **Goals** ML models compute the probability for an action. Ex. A funnel stage model can output the next stage in the user conversion funnel - add_to_cart with a probability of 72%. * **Metrics** ML models output a number. Ex. Next order value is 172.43 USD. Since metrics models are usually based on regression, these predictions have a single value without a probability attached to it. * **Affinities** ML models output a set of item attributes with associated probabilities. Ex. a user is interested in items with the following characteristics: *color: red* (56% probability), *brand: Adidas* (67% probability). The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. + * @summary Get user profile + * @param fetchUserProfile - The fetchUserProfile object. + * @param fetchUserProfile.userID This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) + * @param fetchUserProfile.inlineObject The inlineObject object. + */ + public fetchUserProfile( + { + userID, + inlineObject, + }: FetchUserProfileProps + ) : Promise { + const path = '/1/users/{userID}/fetch'.replace( + '{userID}', + encodeURIComponent(String(userID)) + ); + let headers: Headers = { Accept: 'application/json' }; + let queryParameters: Record = {}; + + if (!userID) { + throw new Error('Parameter `userID` is required when calling `fetchUserProfile`.'); + } + + + if (!inlineObject) { + throw new Error('Parameter `inlineObject` is required when calling `fetchUserProfile`.'); + } + + + + const request: Request = { + method: 'POST', + path, + data: inlineObject, + }; + + const requestOptions: RequestOptions = { + headers, + queryParameters + }; + + return this.sendRequest(request, requestOptions); + } +} + +export type FetchUserProfileProps = { + /** + * This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) + */ + userID: string; + inlineObject: InlineObject; +} + + diff --git a/clients/algoliasearch-client-javascript/client-predict/tsconfig.json b/clients/algoliasearch-client-javascript/client-predict/tsconfig.json new file mode 100644 index 0000000000..2f72c93ccb --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "ES6", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "strict": true, + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "noLib": false, + "declaration": true, + "lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"], + "outDir": "dist", + "typeRoots": ["node_modules/@types"], + "types": ["node"] + }, + "include": ["src", "model", "api.ts"], + "exclude": ["dist", "node_modules"] +} diff --git a/yarn.lock b/yarn.lock index be1d639bb0..5d16c93b10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -89,6 +89,16 @@ __metadata: languageName: unknown linkType: soft +"@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict": + version: 0.0.0-use.local + resolution: "@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict" + dependencies: + "@algolia/client-common": 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/client-query-suggestions": version: 0.0.0-use.local resolution: "@algolia/client-query-suggestions@workspace:clients/algoliasearch-client-javascript/client-query-suggestions" From 217c0c151536e8ef766093b787fc0d1d17a2d220 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 8 Feb 2022 16:56:19 +0200 Subject: [PATCH 10/27] Fix configuration --- openapitools.json | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/openapitools.json b/openapitools.json index b6f93fb7f6..6abb8acf8a 100644 --- a/openapitools.json +++ b/openapitools.json @@ -192,6 +192,26 @@ "topLevelDomain": "com" } }, + "javascript-predict": { + "generatorName": "typescript-node", + "templateDir": "#{cwd}/templates/javascript/", + "config": "#{cwd}/openapitools.json", + "apiPackage": "src", + "output": "#{cwd}/clients/algoliasearch-client-javascript/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" + } + }, "java-search": { "generatorName": "java", "templateDir": "#{cwd}/templates/java/", @@ -369,18 +389,6 @@ "isEuHost": true, "host": "query-suggestions", "topLevelDomain": "com" - }, - "javascript-predict": { - "generatorName": "typescript-node", - "templateDir": "#{cwd}/templates/javascript/", - "config": "#{cwd}/openapitools.json", - "apiPackage": "src", - "output": "#{cwd}/clients/algoliasearch-client-javascript/predict", - "glob": "specs/dist/predict.yml", - "gitHost": "algolia", - "gitUserId": "algolia", - "gitRepoId": "algoliasearch-client-javascript", - "reservedWordsMappings": "queryParameters=queryParameters" } } } From 68f60b37084d2f255077e40ab3f457e85b1b5265 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 8 Feb 2022 16:57:04 +0200 Subject: [PATCH 11/27] Remove old files --- .../client-predict/model/errorBase.ts | 11 - .../model/fetchUserProfileResponse.ts | 14 - .../fetchUserProfileResponsePredictions.ts | 13 - ...serProfileResponsePredictionsAffinities.ts | 13 - ...ofileResponsePredictionsAffinitiesValue.ts | 10 - ...erProfileResponsePredictionsFunnelStage.ts | 13 - ...fileResponsePredictionsFunnelStageValue.ts | 11 - ...serProfileResponsePredictionsOrderValue.ts | 12 - .../fetchUserProfileResponseProperties.ts | 22 -- .../model/fetchUserProfileResponseSegments.ts | 18 -- .../client-predict/model/inlineObject.ts | 19 -- .../client-predict/model/models.ts | 255 ------------------ .../client-predict/src/apis.ts | 5 - .../client-predict/src/predictApi.ts | 153 ----------- 14 files changed, 569 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/models.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/src/apis.ts delete mode 100644 clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts b/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts deleted file mode 100644 index d90c6c2793..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts +++ /dev/null @@ -1,11 +0,0 @@ - - -/** -* Error. -*/ -export type ErrorBase = { - message?: string; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts deleted file mode 100644 index 7d65d2034f..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; -import { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; -import { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; - - -export type FetchUserProfileResponse = { - user: string; - predictions?: FetchUserProfileResponsePredictions; - properties?: FetchUserProfileResponseProperties; - segments?: FetchUserProfileResponseSegments; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts deleted file mode 100644 index 68fd5c71ae..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; -import { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; -import { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; - - -export type FetchUserProfileResponsePredictions = { - funnel_stage?: FetchUserProfileResponsePredictionsFunnelStage; - order_value?: FetchUserProfileResponsePredictionsOrderValue; - affinities?: FetchUserProfileResponsePredictionsAffinities; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts deleted file mode 100644 index 9cdd3d76cd..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; - - -/** -* Prediction for the **affinities** model -*/ -export type FetchUserProfileResponsePredictionsAffinities = { - value?: Array; - lastUpdatedAt?: string; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts deleted file mode 100644 index 37455aff1f..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts +++ /dev/null @@ -1,10 +0,0 @@ - - -export type FetchUserProfileResponsePredictionsAffinitiesValue = { - name?: string; - value?: string; - probability?: number; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts deleted file mode 100644 index bc26169171..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; - - -/** -* Prediction for the **funnel_stage** model -*/ -export type FetchUserProfileResponsePredictionsFunnelStage = { - value?: Array; - lastUpdatedAt?: string; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts deleted file mode 100644 index 1a5c8cf11c..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts +++ /dev/null @@ -1,11 +0,0 @@ - - -export type FetchUserProfileResponsePredictionsFunnelStageValue = { - name?: FetchUserProfileResponsePredictionsFunnelStageValueName; - probability?: number; -} - -export type FetchUserProfileResponsePredictionsFunnelStageValueName = 'all_visits'|'click_product_list'|'product_view'|'add_to_cart'|'checkout'|'transaction' - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts deleted file mode 100644 index 630d6fb639..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts +++ /dev/null @@ -1,12 +0,0 @@ - - -/** -* Prediction for the **order_value** model -*/ -export type FetchUserProfileResponsePredictionsOrderValue = { - value?: number; - lastUpdatedAt?: string; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts deleted file mode 100644 index 912f8ac077..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts +++ /dev/null @@ -1,22 +0,0 @@ - - -/** -* Properties for the user profile -*/ -export type FetchUserProfileResponseProperties = { - /** - * Raw user properties (key-value pairs) - */ - raw?: object; - /** - * Computed user properties (key-value pairs) - */ - computed?: object; - /** - * Custom user properties (key-value pairs) - */ - custom?: object; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts deleted file mode 100644 index 518f495f1b..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts +++ /dev/null @@ -1,18 +0,0 @@ - - -/** -* Segments that the user belongs to -*/ -export type FetchUserProfileResponseSegments = { - /** - * List of computed segments IDs - */ - computed?: Array; - /** - * List of custom segments IDs - */ - custom?: Array; -} - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts deleted file mode 100644 index e3fc86d679..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts +++ /dev/null @@ -1,19 +0,0 @@ - - -export type InlineObject = { - /** - * List with model types for which to retrieve predictions - */ - modelsToRetrieve?: InlineObjectModelsToRetrieve[]; - /** - * List with types to be retrieved. - */ - typesToRetrieve?: InlineObjectTypesToRetrieve[]; -} - -export type InlineObjectModelsToRetrieve = 'funnel_stage'|'order_value'|'affinities' - -export type InlineObjectTypesToRetrieve = 'properties'|'segments' - - - diff --git a/clients/algoliasearch-client-javascript/client-predict/model/models.ts b/clients/algoliasearch-client-javascript/client-predict/model/models.ts deleted file mode 100644 index c6a0dcb682..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/models.ts +++ /dev/null @@ -1,255 +0,0 @@ -import localVarRequest from 'request'; - -export * from './errorBase'; -export * from './fetchUserProfileResponse'; -export * from './fetchUserProfileResponsePredictions'; -export * from './fetchUserProfileResponsePredictionsAffinities'; -export * from './fetchUserProfileResponsePredictionsAffinitiesValue'; -export * from './fetchUserProfileResponsePredictionsFunnelStage'; -export * from './fetchUserProfileResponsePredictionsFunnelStageValue'; -export * from './fetchUserProfileResponsePredictionsOrderValue'; -export * from './fetchUserProfileResponseProperties'; -export * from './fetchUserProfileResponseSegments'; -export * from './inlineObject'; - -import * as fs from 'fs'; - -export interface RequestDetailedFile { - value: Buffer; - options?: { - filename?: string; - contentType?: string; - } -} - -export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile; - - -import { ErrorBase } from './errorBase'; -import { FetchUserProfileResponse } from './fetchUserProfileResponse'; -import { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; -import { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; -import { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; -import { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; -import { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; -import { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; -import { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; -import { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; -import { InlineObject } from './inlineObject'; - -/* tslint:disable:no-unused-variable */ -let primitives = [ - "string", - "boolean", - "double", - "integer", - "long", - "float", - "number", - "any" - ]; - -let enumsMap: {[index: string]: any} = { - "FetchUserProfileResponsePredictionsFunnelStageValue.NameEnum": FetchUserProfileResponsePredictionsFunnelStageValue.NameEnum, - "InlineObject.ModelsToRetrieveEnum": InlineObject.ModelsToRetrieveEnum, - "InlineObject.TypesToRetrieveEnum": InlineObject.TypesToRetrieveEnum, -} - -let typeMap: {[index: string]: any} = { - "ErrorBase": ErrorBase, - "FetchUserProfileResponse": FetchUserProfileResponse, - "FetchUserProfileResponsePredictions": FetchUserProfileResponsePredictions, - "FetchUserProfileResponsePredictionsAffinities": FetchUserProfileResponsePredictionsAffinities, - "FetchUserProfileResponsePredictionsAffinitiesValue": FetchUserProfileResponsePredictionsAffinitiesValue, - "FetchUserProfileResponsePredictionsFunnelStage": FetchUserProfileResponsePredictionsFunnelStage, - "FetchUserProfileResponsePredictionsFunnelStageValue": FetchUserProfileResponsePredictionsFunnelStageValue, - "FetchUserProfileResponsePredictionsOrderValue": FetchUserProfileResponsePredictionsOrderValue, - "FetchUserProfileResponseProperties": FetchUserProfileResponseProperties, - "FetchUserProfileResponseSegments": FetchUserProfileResponseSegments, - "InlineObject": InlineObject, -} - -export class ObjectSerializer { - public static findCorrectType(data: any, expectedType: string) { - if (data == undefined) { - return expectedType; - } else if (primitives.indexOf(expectedType.toLowerCase()) !== -1) { - return expectedType; - } else if (expectedType === "Date") { - return expectedType; - } else { - if (enumsMap[expectedType]) { - return expectedType; - } - - if (!typeMap[expectedType]) { - return expectedType; // w/e we don't know the type - } - - // Check the discriminator - let discriminatorProperty = typeMap[expectedType].discriminator; - if (discriminatorProperty == null) { - return expectedType; // the type does not have a discriminator. use it. - } else { - if (data[discriminatorProperty]) { - var discriminatorType = data[discriminatorProperty]; - if(typeMap[discriminatorType]){ - return discriminatorType; // use the type given in the discriminator - } else { - return expectedType; // discriminator did not map to a type - } - } else { - return expectedType; // discriminator was not present (or an empty string) - } - } - } - } - - public static serialize(data: any, type: string) { - if (data == undefined) { - return data; - } else if (primitives.indexOf(type.toLowerCase()) !== -1) { - return data; - } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 - let subType: string = type.replace("Array<", ""); // Array => Type> - subType = subType.substring(0, subType.length - 1); // Type> => Type - let transformedData: any[] = []; - for (let index = 0; index < data.length; index++) { - let datum = data[index]; - transformedData.push(ObjectSerializer.serialize(datum, subType)); - } - return transformedData; - } else if (type === "Date") { - return data.toISOString(); - } else { - if (enumsMap[type]) { - return data; - } - if (!typeMap[type]) { // in case we dont know the type - return data; - } - - // Get the actual type of this object - type = this.findCorrectType(data, type); - - // get the map for the correct type. - let attributeTypes = typeMap[type].getAttributeTypeMap(); - let instance: {[index: string]: any} = {}; - for (let index = 0; index < attributeTypes.length; index++) { - let attributeType = attributeTypes[index]; - instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type); - } - return instance; - } - } - - public static deserialize(data: any, type: string) { - // polymorphism may change the actual type. - type = ObjectSerializer.findCorrectType(data, type); - if (data == undefined) { - return data; - } else if (primitives.indexOf(type.toLowerCase()) !== -1) { - return data; - } else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 - let subType: string = type.replace("Array<", ""); // Array => Type> - subType = subType.substring(0, subType.length - 1); // Type> => Type - let transformedData: any[] = []; - for (let index = 0; index < data.length; index++) { - let datum = data[index]; - transformedData.push(ObjectSerializer.deserialize(datum, subType)); - } - return transformedData; - } else if (type === "Date") { - return new Date(data); - } else { - if (enumsMap[type]) {// is Enum - return data; - } - - if (!typeMap[type]) { // dont know the type - return data; - } - let instance = new typeMap[type](); - let attributeTypes = typeMap[type].getAttributeTypeMap(); - for (let index = 0; index < attributeTypes.length; index++) { - let attributeType = attributeTypes[index]; - instance[attributeType.name] = ObjectSerializer.deserialize(data[attributeType.baseName], attributeType.type); - } - return instance; - } - } -} - -export interface Authentication { - /** - * Apply authentication settings to header and query params. - */ - applyToRequest(requestOptions: localVarRequest.Options): Promise | void; -} - -export class HttpBasicAuth implements Authentication { - public username: string = ''; - public password: string = ''; - - applyToRequest(requestOptions: localVarRequest.Options): void { - requestOptions.auth = { - username: this.username, password: this.password - } - } -} - -export class HttpBearerAuth implements Authentication { - public accessToken: string | (() => string) = ''; - - applyToRequest(requestOptions: localVarRequest.Options): void { - if (requestOptions && requestOptions.headers) { - const accessToken = typeof this.accessToken === 'function' - ? this.accessToken() - : this.accessToken; - requestOptions.headers["Authorization"] = "Bearer " + accessToken; - } - } -} - -export class ApiKeyAuth implements Authentication { - public apiKey: string = ''; - - constructor(private location: string, private paramName: string) { - } - - applyToRequest(requestOptions: localVarRequest.Options): void { - if (this.location == "query") { - (requestOptions.qs)[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); - } - } - } -} - -export class OAuth implements Authentication { - public accessToken: string = ''; - - applyToRequest(requestOptions: localVarRequest.Options): void { - if (requestOptions && requestOptions.headers) { - requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; - } - } -} - -export class VoidAuth implements Authentication { - public username: string = ''; - public password: string = ''; - - applyToRequest(_: localVarRequest.Options): void { - // Do nothing - } -} - -export type Interceptor = (requestOptions: localVarRequest.Options) => (Promise | void); diff --git a/clients/algoliasearch-client-javascript/client-predict/src/apis.ts b/clients/algoliasearch-client-javascript/client-predict/src/apis.ts deleted file mode 100644 index 06eae5f6ac..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/src/apis.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './predictApi'; -import { PredictApi } from './predictApi'; -export * from '@algolia/client-common'; - -export const APIS = [PredictApi]; diff --git a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts deleted file mode 100644 index 14644f7bc1..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts +++ /dev/null @@ -1,153 +0,0 @@ -import { shuffle, Transporter } from '@algolia/client-common'; -import type { Headers, Requester, Host, Request, RequestOptions } from '@algolia/client-common'; - -import { ErrorBase } from '../model/errorBase'; -import { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; -import { InlineObject } from '../model/inlineObject'; - -export const version = '5.0.0'; - - -export class PredictApi { - protected authentications = { - apiKey: 'Algolia-API-Key', - appId: 'Algolia-Application-Id', - }; - - private transporter: Transporter; - - private applyAuthenticationHeaders( - requestOptions: RequestOptions - ): RequestOptions { - if (requestOptions?.headers) { - return { - ...requestOptions, - headers: { - ...requestOptions.headers, - 'X-Algolia-API-Key': this.authentications.apiKey, - 'X-Algolia-Application-Id': this.authentications.appId, - }, - }; - } - - return requestOptions; - } - - private sendRequest( - request: Request, - requestOptions: RequestOptions - ): Promise { - return this.transporter.request( - request, - this.applyAuthenticationHeaders(requestOptions) - ); - } - - constructor( - appId: string, - apiKey: string, - options?: {requester?: Requester, hosts?: Host[]} - ) { - if (!appId) { - throw new Error("`appId` is missing."); - } - if (!apiKey) { - throw new Error("`apiKey` is missing."); - } - - this.setAuthentication({ appId, apiKey }); - - this.transporter = new Transporter({ - hosts: options?.hosts ?? this.getDefaultHosts( - - - ), - baseHeaders: { - 'content-type': 'application/x-www-form-urlencoded' - }, - userAgent: 'Algolia for Javascript (5.0.0)', - timeouts: { - connect: 2, - read: 5, - write: 30, - }, - requester: options?.requester, - }); - } - - - - public getDefaultHosts(): Host[] { - return [{ url: 'predict.algolia.io', accept: 'readWrite', protocol: 'https' }]; - } - - public setRequest(requester: Requester): void { - this.transporter.setRequester(requester); - } - - public setHosts(hosts: Host[]): void { - this.transporter.setHosts(hosts); - } - - public setAuthentication({ appId, apiKey }): void { - this.authentications = { - apiKey, - appId, - }; - } - - /** - * Get predictions, properties (raw, computed or custom) and segments (computed or custom) for an authenticated user (userID) or an anonymous user (cookieID). The predictions can be goals, metrics or affinities: * **Goals** ML models compute the probability for an action. Ex. A funnel stage model can output the next stage in the user conversion funnel - add_to_cart with a probability of 72%. * **Metrics** ML models output a number. Ex. Next order value is 172.43 USD. Since metrics models are usually based on regression, these predictions have a single value without a probability attached to it. * **Affinities** ML models output a set of item attributes with associated probabilities. Ex. a user is interested in items with the following characteristics: *color: red* (56% probability), *brand: Adidas* (67% probability). The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. - * @summary Get user profile - * @param fetchUserProfile - The fetchUserProfile object. - * @param fetchUserProfile.userID This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) - * @param fetchUserProfile.inlineObject The inlineObject object. - */ - public fetchUserProfile( - { - userID, - inlineObject, - }: FetchUserProfileProps - ) : Promise { - const path = '/1/users/{userID}/fetch'.replace( - '{userID}', - encodeURIComponent(String(userID)) - ); - let headers: Headers = { Accept: 'application/json' }; - let queryParameters: Record = {}; - - if (!userID) { - throw new Error('Parameter `userID` is required when calling `fetchUserProfile`.'); - } - - - if (!inlineObject) { - throw new Error('Parameter `inlineObject` is required when calling `fetchUserProfile`.'); - } - - - - const request: Request = { - method: 'POST', - path, - data: inlineObject, - }; - - const requestOptions: RequestOptions = { - headers, - queryParameters - }; - - return this.sendRequest(request, requestOptions); - } -} - -export type FetchUserProfileProps = { - /** - * This parameter can have different values: * An user ID for authenticated users. * A cookie ID for non-authenticated repeated users (visitors) - */ - userID: string; - inlineObject: InlineObject; -} - - From 2e667abfc8152fd15883b2c30ed3f654e7599846 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 8 Feb 2022 17:27:43 +0200 Subject: [PATCH 12/27] Remove long descriptions --- specs/predict/common/parameters.yml | 5 +---- specs/predict/paths/fetchUserProfile.yml | 11 +---------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/specs/predict/common/parameters.yml b/specs/predict/common/parameters.yml index c2b74e9b98..362f6178ce 100644 --- a/specs/predict/common/parameters.yml +++ b/specs/predict/common/parameters.yml @@ -4,7 +4,4 @@ userID: required: true schema: type: string - description: | - This parameter can have different values: - * An user ID for authenticated users. - * A cookie ID for non-authenticated repeated users (visitors) + 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 index 8987cd8c42..0305574774 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -2,16 +2,7 @@ post: tags: - predict operationId: fetchUserProfile - description: | - Get predictions, properties (raw, computed or custom) and segments (computed or custom) for an authenticated user (userID) or an anonymous user (cookieID). - - The predictions can be goals, metrics or affinities: - * **Goals** ML models compute the probability for an action. Ex. A funnel stage model can output the next stage in the user conversion funnel - add_to_cart with a probability of 72%. - * **Metrics** ML models output a number. Ex. Next order value is 172.43 USD. Since metrics models are usually based on regression, these predictions have a single value without a probability attached to it. - * **Affinities** ML models output a set of item attributes with associated probabilities. Ex. a user is interested in items with the following characteristics: *color: red* (56% probability), *brand: Adidas* (67% probability). - - The usage of segments for a user profile assumes that actions are implemented in a website or app and can be triggered when a segment is identified: *if segment1 in user_segments then do action*. For example, a segment can represent users that are close to churning and the action can be offering them an incentive such as a discount code or free shipping. - + 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' From 3bbf2a0df11c9d8351b24b1225c0c43f131f755f Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 8 Feb 2022 17:29:00 +0200 Subject: [PATCH 13/27] Clean up old files, regenerate client --- .../client-predict/.openapi-generator-ignore | 19 +-- .../client-predict/api.ts | 2 - .../client-predict/browser.ts | 37 +++++ .../client-predict/model/errorBase.ts | 6 + .../model/fetchUserProfileResponse.ts | 10 ++ .../fetchUserProfileResponsePredictions.ts | 9 ++ ...serProfileResponsePredictionsAffinities.ts | 9 ++ ...ofileResponsePredictionsAffinitiesValue.ts | 5 + ...erProfileResponsePredictionsFunnelStage.ts | 9 ++ ...fileResponsePredictionsFunnelStageValue.ts | 12 ++ ...serProfileResponsePredictionsOrderValue.ts | 7 + .../fetchUserProfileResponseProperties.ts | 17 +++ .../model/fetchUserProfileResponseSegments.ts | 13 ++ .../client-predict/model/inlineObject.ts | 17 +++ .../client-predict/node.ts | 36 +++++ .../client-predict/package.json | 17 ++- .../client-predict/src/predictApi.ts | 127 ++++++++++++++++++ .../client-predict/tsconfig.json | 2 +- openapitools.json | 2 +- 19 files changed, 330 insertions(+), 26 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/client-predict/api.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/browser.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/node.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore index 7484ee590a..000abf8f71 100644 --- a/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore @@ -4,20 +4,5 @@ # Use this file to prevent files from being overwritten by the generator. # The patterns follow closely to .gitignore or .dockerignore. -# As an example, the C# client generator defines ApiClient.cs. -# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: -#ApiClient.cs - -# You can match any string of characters against a directory, file or extension with a single asterisk (*): -#foo/*/qux -# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux - -# You can recursively match patterns against a directory, file or extension with a double asterisk (**): -#foo/**/qux -# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux - -# You can also negate patterns with an exclamation (!). -# For example, you can ignore all files in a docs folder with the file extension .md: -#docs/*.md -# Then explicitly reverse the ignore rule for a single file: -#!docs/README.md +git_push.sh +model/models.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/api.ts b/clients/algoliasearch-client-javascript/client-predict/api.ts deleted file mode 100644 index c4759f623a..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/api.ts +++ /dev/null @@ -1,2 +0,0 @@ -// This is the entrypoint for the package -export * from './src/apis'; diff --git a/clients/algoliasearch-client-javascript/client-predict/browser.ts b/clients/algoliasearch-client-javascript/client-predict/browser.ts new file mode 100644 index 0000000000..a3b4095b5e --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/browser.ts @@ -0,0 +1,37 @@ +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 * from '@algolia/client-common'; + +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/client-predict/model/errorBase.ts b/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts new file mode 100644 index 0000000000..a533aa7a15 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts @@ -0,0 +1,6 @@ +/** + * Error. + */ +export type ErrorBase = { + message?: string; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts new file mode 100644 index 0000000000..83dd597e63 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts @@ -0,0 +1,10 @@ +import type { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; +import type { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; +import type { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; + +export type FetchUserProfileResponse = { + user: string; + predictions?: FetchUserProfileResponsePredictions; + properties?: FetchUserProfileResponseProperties; + segments?: FetchUserProfileResponseSegments; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts new file mode 100644 index 0000000000..98f5ef0621 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts @@ -0,0 +1,9 @@ +import type { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; +import type { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; +import type { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; + +export type FetchUserProfileResponsePredictions = { + funnel_stage?: FetchUserProfileResponsePredictionsFunnelStage; + order_value?: FetchUserProfileResponsePredictionsOrderValue; + affinities?: FetchUserProfileResponsePredictionsAffinities; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts new file mode 100644 index 0000000000..1f4dd9b011 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts @@ -0,0 +1,9 @@ +import type { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; + +/** + * Prediction for the **affinities** model. + */ +export type FetchUserProfileResponsePredictionsAffinities = { + value?: FetchUserProfileResponsePredictionsAffinitiesValue[]; + lastUpdatedAt?: string; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts new file mode 100644 index 0000000000..c0bcc5bdb3 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts @@ -0,0 +1,5 @@ +export type FetchUserProfileResponsePredictionsAffinitiesValue = { + name?: string; + value?: string; + probability?: number; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts new file mode 100644 index 0000000000..d832aba681 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts @@ -0,0 +1,9 @@ +import type { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; + +/** + * Prediction for the **funnel_stage** model. + */ +export type FetchUserProfileResponsePredictionsFunnelStage = { + value?: FetchUserProfileResponsePredictionsFunnelStageValue[]; + lastUpdatedAt?: string; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts new file mode 100644 index 0000000000..5b3511f03c --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts @@ -0,0 +1,12 @@ +export type FetchUserProfileResponsePredictionsFunnelStageValue = { + name?: FetchUserProfileResponsePredictionsFunnelStageValueName; + probability?: number; +}; + +export type FetchUserProfileResponsePredictionsFunnelStageValueName = + | 'add_to_cart' + | 'all_visits' + | 'checkout' + | 'click_product_list' + | 'product_view' + | 'transaction'; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts new file mode 100644 index 0000000000..9628ac1883 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts @@ -0,0 +1,7 @@ +/** + * Prediction for the **order_value** model. + */ +export type FetchUserProfileResponsePredictionsOrderValue = { + value?: number; + lastUpdatedAt?: string; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts new file mode 100644 index 0000000000..8400654fcc --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts @@ -0,0 +1,17 @@ +/** + * Properties for the user profile. + */ +export type FetchUserProfileResponseProperties = { + /** + * 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/client-predict/model/fetchUserProfileResponseSegments.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts new file mode 100644 index 0000000000..1a3a5f745b --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts @@ -0,0 +1,13 @@ +/** + * Segments that the user belongs to. + */ +export type FetchUserProfileResponseSegments = { + /** + * List of computed segments IDs. + */ + computed?: string[]; + /** + * List of custom segments IDs. + */ + custom?: string[]; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts new file mode 100644 index 0000000000..f5bd02ea46 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts @@ -0,0 +1,17 @@ +export type InlineObject = { + /** + * List with model types for which to retrieve predictions. + */ + modelsToRetrieve?: InlineObjectModelsToRetrieve[]; + /** + * List with types to be retrieved. + */ + typesToRetrieve?: InlineObjectTypesToRetrieve[]; +}; + +export type InlineObjectModelsToRetrieve = + | 'affinities' + | 'funnel_stage' + | 'order_value'; + +export type InlineObjectTypesToRetrieve = 'properties' | 'segments'; diff --git a/clients/algoliasearch-client-javascript/client-predict/node.ts b/clients/algoliasearch-client-javascript/client-predict/node.ts new file mode 100644 index 0000000000..8b94b68728 --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/node.ts @@ -0,0 +1,36 @@ +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 * from '@algolia/client-common'; + +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/client-predict/package.json b/clients/algoliasearch-client-javascript/client-predict/package.json index b0744cafc3..628837be96 100644 --- a/clients/algoliasearch-client-javascript/client-predict/package.json +++ b/clients/algoliasearch-client-javascript/client-predict/package.json @@ -1,23 +1,30 @@ { "name": "@algolia/client-predict", - "version": "5.0.0", + "version": "0.0.1", "description": "JavaScript client for @algolia/client-predict", "repository": "algolia/algoliasearch-client-javascript", "author": "Algolia", "private": true, "license": "MIT", - "main": "dist/api.js", - "types": "dist/api.d.ts", + "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": "^16.0.0", + "node": "^14.0.0", "yarn": "^3.0.0" }, "dependencies": { - "@algolia/client-common": "5.0.0" + "@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", diff --git a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts new file mode 100644 index 0000000000..13319bea7d --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts @@ -0,0 +1,127 @@ +import { + shuffle, + 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 { InlineObject } from '../model/inlineObject'; + +export const version = '0.0.1'; + +function getDefaultHosts(appId: string): Host[] { + return ( + [ + { + url: `${appId}-dsn.algolia.net`, + accept: 'read', + protocol: 'https', + }, + { + url: `${appId}.algolia.net`, + accept: 'write', + protocol: 'https', + }, + ] as Host[] + ).concat( + shuffle([ + { + url: `${appId}-1.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-2.algolianet.com`, + accept: 'readWrite', + protocol: 'https', + }, + { + url: `${appId}-3.algolianet.com`, + 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(options.appId), + 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.inlineObject - The inlineObject object. + */ + function fetchUserProfile({ + userID, + inlineObject, + }: 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 (!inlineObject) { + throw new Error( + 'Parameter `inlineObject` is required when calling `fetchUserProfile`.' + ); + } + + const request: Request = { + method: 'POST', + path, + data: inlineObject, + }; + + 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; + inlineObject: InlineObject; +}; diff --git a/clients/algoliasearch-client-javascript/client-predict/tsconfig.json b/clients/algoliasearch-client-javascript/client-predict/tsconfig.json index 2f72c93ccb..2613b3ebad 100644 --- a/clients/algoliasearch-client-javascript/client-predict/tsconfig.json +++ b/clients/algoliasearch-client-javascript/client-predict/tsconfig.json @@ -17,6 +17,6 @@ "typeRoots": ["node_modules/@types"], "types": ["node"] }, - "include": ["src", "model", "api.ts"], + "include": ["src", "model", "node.ts", "browser.ts"], "exclude": ["dist", "node_modules"] } diff --git a/openapitools.json b/openapitools.json index 6abb8acf8a..73411b30ea 100644 --- a/openapitools.json +++ b/openapitools.json @@ -393,4 +393,4 @@ } } } -} +} \ No newline at end of file From c3c4e5fa6dbc69bca63c49227fabda9f86abc22a Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Tue, 8 Feb 2022 17:52:54 +0200 Subject: [PATCH 14/27] Disable enum validation --- ...fileResponsePredictionsFunnelStageValue.ts | 10 +------ .../client-predict/model/inlineObject.ts | 11 ++------ specs/predict/paths/fetchUserProfile.yml | 28 +++++++++---------- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts index 5b3511f03c..10fd439ca5 100644 --- a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts +++ b/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts @@ -1,12 +1,4 @@ export type FetchUserProfileResponsePredictionsFunnelStageValue = { - name?: FetchUserProfileResponsePredictionsFunnelStageValueName; + name?: string; probability?: number; }; - -export type FetchUserProfileResponsePredictionsFunnelStageValueName = - | 'add_to_cart' - | 'all_visits' - | 'checkout' - | 'click_product_list' - | 'product_view' - | 'transaction'; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts index f5bd02ea46..ef76961177 100644 --- a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts +++ b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts @@ -2,16 +2,9 @@ export type InlineObject = { /** * List with model types for which to retrieve predictions. */ - modelsToRetrieve?: InlineObjectModelsToRetrieve[]; + modelsToRetrieve?: string[]; /** * List with types to be retrieved. */ - typesToRetrieve?: InlineObjectTypesToRetrieve[]; + typesToRetrieve?: string[]; }; - -export type InlineObjectModelsToRetrieve = - | 'affinities' - | 'funnel_stage' - | 'order_value'; - -export type InlineObjectTypesToRetrieve = 'properties' | 'segments'; diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index 0305574774..680aff886e 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -19,19 +19,19 @@ post: type: array items: type: string - enum: - - funnel_stage - - order_value - - affinities + # enum: + # - funnel_stage + # - order_value + # - affinities minItems: 1 typesToRetrieve: description: List with types to be retrieved. type: array items: type: string - enum: - - properties - - segments + # enum: + # - properties + # - segments minItems: 1 responses: @@ -61,13 +61,13 @@ post: properties: name: type: string - enum: - - all_visits - - click_product_list - - product_view - - add_to_cart - - checkout - - transaction + # enum: + # - all_visits + # - click_product_list + # - product_view + # - add_to_cart + # - checkout + # - transaction probability: type: number minimum: 0 From be5f35ee6982c0c1244e3da203d32c67defa4920 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Wed, 9 Feb 2022 11:43:39 +0200 Subject: [PATCH 15/27] Update request body to remove InlineObject name --- .../model/modelsTypesRequest.ts | 20 ++++++++++++ .../client-predict/src/predictApi.ts | 14 ++++----- specs/predict/paths/fetchUserProfile.yml | 31 +++++++++---------- 3 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts b/clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts new file mode 100644 index 0000000000..bc22116b7d --- /dev/null +++ b/clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts @@ -0,0 +1,20 @@ +/** + * Object with models and types to retrieve. + */ +export type ModelsTypesRequest = { + /** + * List with model types for which to retrieve predictions. + */ + modelsToRetrieve?: ModelsTypesRequestModelsToRetrieve[]; + /** + * List with types to be retrieved. + */ + typesToRetrieve?: ModelsTypesRequestTypesToRetrieve[]; +}; + +export type ModelsTypesRequestModelsToRetrieve = + | 'affinities' + | 'funnel_stage' + | 'order_value'; + +export type ModelsTypesRequestTypesToRetrieve = 'properties' | 'segments'; diff --git a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts index 13319bea7d..cb33cd3e98 100644 --- a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts +++ b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts @@ -12,7 +12,7 @@ import type { } from '@algolia/client-common'; import type { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; -import type { InlineObject } from '../model/inlineObject'; +import type { ModelsTypesRequest } from '../model/modelsTypesRequest'; export const version = '0.0.1'; @@ -76,11 +76,11 @@ export const createPredictApi = (options: CreateClientOptions) => { * @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.inlineObject - The inlineObject object. + * @param fetchUserProfile.modelsTypesRequest - The modelsTypesRequest object. */ function fetchUserProfile({ userID, - inlineObject, + modelsTypesRequest, }: FetchUserProfileProps): Promise { const path = '/1/users/{userID}/fetch'.replace( '{userID}', @@ -95,16 +95,16 @@ export const createPredictApi = (options: CreateClientOptions) => { ); } - if (!inlineObject) { + if (!modelsTypesRequest) { throw new Error( - 'Parameter `inlineObject` is required when calling `fetchUserProfile`.' + 'Parameter `modelsTypesRequest` is required when calling `fetchUserProfile`.' ); } const request: Request = { method: 'POST', path, - data: inlineObject, + data: modelsTypesRequest, }; return transporter.request(request, { @@ -123,5 +123,5 @@ export type FetchUserProfileProps = { * User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). */ userID: string; - inlineObject: InlineObject; + modelsTypesRequest: ModelsTypesRequest; }; diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index 680aff886e..dadd445887 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -12,26 +12,30 @@ post: content: application/json: schema: + title: ModelsTypesRequest + type: object + description: Object with models and types to retrieve. additionalProperties: false properties: modelsToRetrieve: - description: List with model types for which to retrieve predictions type: array + title: modelsToRetrieve + description: List with model types for which to retrieve predictions items: type: string - # enum: - # - funnel_stage - # - order_value - # - affinities - minItems: 1 + enum: + - funnel_stage + - order_value + - affinities typesToRetrieve: - description: List with types to be retrieved. type: array + title: typesToRetrieve + description: List with types to be retrieved. items: type: string - # enum: - # - properties - # - segments + enum: + - properties + - segments minItems: 1 responses: @@ -61,13 +65,6 @@ post: properties: name: type: string - # enum: - # - all_visits - # - click_product_list - # - product_view - # - add_to_cart - # - checkout - # - transaction probability: type: number minimum: 0 From 5e9b9f8cd399ffaa4adc0a62415a3da4e5c7aca8 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Wed, 9 Feb 2022 11:48:36 +0200 Subject: [PATCH 16/27] Remove old file --- .../client-predict/model/inlineObject.ts | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts b/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts deleted file mode 100644 index ef76961177..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/inlineObject.ts +++ /dev/null @@ -1,10 +0,0 @@ -export type InlineObject = { - /** - * List with model types for which to retrieve predictions. - */ - modelsToRetrieve?: string[]; - /** - * List with types to be retrieved. - */ - typesToRetrieve?: string[]; -}; From f4b2533a8e8f8b417206d8f62585d254fda73a03 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Wed, 9 Feb 2022 12:03:47 +0200 Subject: [PATCH 17/27] Update requestBody name --- .../model/modelsTypesRequest.ts | 20 ------------------- .../client-predict/model/params.ts | 20 +++++++++++++++++++ .../client-predict/src/predictApi.ts | 14 ++++++------- specs/predict/paths/fetchUserProfile.yml | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts create mode 100644 clients/algoliasearch-client-javascript/client-predict/model/params.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts b/clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts deleted file mode 100644 index bc22116b7d..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/model/modelsTypesRequest.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Object with models and types to retrieve. - */ -export type ModelsTypesRequest = { - /** - * List with model types for which to retrieve predictions. - */ - modelsToRetrieve?: ModelsTypesRequestModelsToRetrieve[]; - /** - * List with types to be retrieved. - */ - typesToRetrieve?: ModelsTypesRequestTypesToRetrieve[]; -}; - -export type ModelsTypesRequestModelsToRetrieve = - | 'affinities' - | 'funnel_stage' - | 'order_value'; - -export type ModelsTypesRequestTypesToRetrieve = 'properties' | 'segments'; diff --git a/clients/algoliasearch-client-javascript/client-predict/model/params.ts b/clients/algoliasearch-client-javascript/client-predict/model/params.ts new file mode 100644 index 0000000000..ebcae4a6f8 --- /dev/null +++ b/clients/algoliasearch-client-javascript/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/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts index cb33cd3e98..f3a95a9c15 100644 --- a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts +++ b/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts @@ -12,7 +12,7 @@ import type { } from '@algolia/client-common'; import type { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; -import type { ModelsTypesRequest } from '../model/modelsTypesRequest'; +import type { Params } from '../model/params'; export const version = '0.0.1'; @@ -76,11 +76,11 @@ export const createPredictApi = (options: CreateClientOptions) => { * @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.modelsTypesRequest - The modelsTypesRequest object. + * @param fetchUserProfile.params - The params object. */ function fetchUserProfile({ userID, - modelsTypesRequest, + params, }: FetchUserProfileProps): Promise { const path = '/1/users/{userID}/fetch'.replace( '{userID}', @@ -95,16 +95,16 @@ export const createPredictApi = (options: CreateClientOptions) => { ); } - if (!modelsTypesRequest) { + if (!params) { throw new Error( - 'Parameter `modelsTypesRequest` is required when calling `fetchUserProfile`.' + 'Parameter `params` is required when calling `fetchUserProfile`.' ); } const request: Request = { method: 'POST', path, - data: modelsTypesRequest, + data: params, }; return transporter.request(request, { @@ -123,5 +123,5 @@ export type FetchUserProfileProps = { * User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). */ userID: string; - modelsTypesRequest: ModelsTypesRequest; + params: Params; }; diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index dadd445887..b04b937d6f 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -12,7 +12,7 @@ post: content: application/json: schema: - title: ModelsTypesRequest + title: params type: object description: Object with models and types to retrieve. additionalProperties: false From f498f0a994f5cb2ba84f8198a914a9d44855d1ef Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Wed, 9 Feb 2022 16:22:07 +0200 Subject: [PATCH 18/27] Add 400 error --- specs/predict/paths/fetchUserProfile.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index b04b937d6f..12121819c7 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -130,3 +130,9 @@ post: $ref: ../responses/UserNotFound.yml '405': $ref: ../../common/responses/MethodNotAllowed.yml + '400': + description: ModelsToRetrieve or typesToRetrieve must be set. + content: + application/json: + schema: + $ref: ../schemas/ErrorBase.yml From a1dfb13a2d92b0fffb66c16292d130c490abd853 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Wed, 9 Feb 2022 16:49:35 +0200 Subject: [PATCH 19/27] Add example --- playground/javascript/predict.ts | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 playground/javascript/predict.ts diff --git a/playground/javascript/predict.ts b/playground/javascript/predict.ts new file mode 100644 index 0000000000..fc2b9d0f42 --- /dev/null +++ b/playground/javascript/predict.ts @@ -0,0 +1,34 @@ +import { predictApi, ApiError } from '@algolia/predict'; +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: 'user1', + 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(); From 36e5a1cc12a22595841b15e422caafca25830d2e Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Wed, 9 Feb 2022 18:24:27 +0200 Subject: [PATCH 20/27] Update example and config files --- .github/actions/cache/action.yml | 7 +++++++ .redocly.yaml | 1 + clients/README.md | 1 + playground/javascript/package.json | 5 ++++- playground/javascript/predict.ts | 4 ++-- yarn.lock | 15 ++++----------- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 60fad58e4e..bf01e26873 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/client-sources/dist key: ${{ runner.os }}-1-js-client-sources-${{ hashFiles('clients/algoliasearch-client-javascript/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/client-predict/dist + key: ${{ runner.os }}-1-js-client-predict-${{ hashFiles('clients/algoliasearch-client-javascript/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 cb4a2a30dd..598fddd04e 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/client-search/): The Algolia search client. - [@algolia/recommend](./algoliasearch-client-javascript/recommend/): The Algolia recommend client. - [@algolia/sources](./algoliasearch-client-javascript/client-sources/): The Algolia sources client. +- [@algolia/predict](./algoliasearch-client-javascript/client-predict/): The Algolia predict client. - [@algolia/client-common](./algoliasearch-client-javascript/client-common/): The JavaScript clients common files. - [@algolia/requester-browser-xhr](./algoliasearch-client-javascript/requester-browser-xhr/): Browser XHR requester for the Algolia JavaScript clients. - [@algolia/requester-node-http](./algoliasearch-client-javascript/requester-node-http/): Node.js HTTP requester for the Algolia JavaScript clients. 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 index fc2b9d0f42..21670147a3 100644 --- a/playground/javascript/predict.ts +++ b/playground/javascript/predict.ts @@ -1,4 +1,4 @@ -import { predictApi, ApiError } from '@algolia/predict'; +import { predictApi, ApiError } from '@algolia/client-predict'; import dotenv from 'dotenv'; dotenv.config({ path: '../.env' }); @@ -14,7 +14,7 @@ const predictClient = predictApi(appId, apiKey); async function testPredict() { try { const userProfile = await predictClient.fetchUserProfile({ - userId: 'user1', + userID: userId, params: { modelsToRetrieve: ["funnel_stage", "order_value", "affinities"], typesToRetrieve: ["properties", "segments"], diff --git a/yarn.lock b/yarn.lock index 21b3fac500..21aae680b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -89,21 +89,13 @@ __metadata: languageName: unknown linkType: soft -"@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict": - version: 0.0.0-use.local - resolution: "@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict" - dependencies: - "@algolia/client-common": 5.0.0 - "@types/node": 16.11.11 - typescript: 4.5.4 - languageName: unknown - linkType: soft - -"@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict": +"@algolia/client-predict@0.0.1, @algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict": version: 0.0.0-use.local resolution: "@algolia/client-predict@workspace:clients/algoliasearch-client-javascript/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 @@ -3855,6 +3847,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 From 0be4c32e1c13c5a9be70c513b98052d2a1f37f6d Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Thu, 10 Feb 2022 13:42:18 +0200 Subject: [PATCH 21/27] Remove duplicate error spec, formatting --- specs/predict/paths/fetchUserProfile.yml | 4 ++-- specs/predict/schemas/ErrorBase.yml | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) delete mode 100644 specs/predict/schemas/ErrorBase.yml diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index 12121819c7..465818b0cd 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -3,7 +3,7 @@ post: - predict operationId: fetchUserProfile description: Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a user profile. - summary: Get user profile + summary: Get user profile. parameters: - $ref: '../common/parameters.yml#/userID' @@ -135,4 +135,4 @@ post: content: application/json: schema: - $ref: ../schemas/ErrorBase.yml + $ref: ../../common/schemas/ErrorBase.yml diff --git a/specs/predict/schemas/ErrorBase.yml b/specs/predict/schemas/ErrorBase.yml deleted file mode 100644 index 7fa8e49656..0000000000 --- a/specs/predict/schemas/ErrorBase.yml +++ /dev/null @@ -1,7 +0,0 @@ -description: Error. -type: object -additionalProperties: true -properties: - message: - type: string - example: Invalid Application-Id or API-Key From 2b5dc9098302d09d114b688a0000c6b981c466c7 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Thu, 10 Feb 2022 13:57:16 +0200 Subject: [PATCH 22/27] Remove git push file --- .../client-predict/git_push.sh | 57 ------------------- 1 file changed, 57 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/client-predict/git_push.sh diff --git a/clients/algoliasearch-client-javascript/client-predict/git_push.sh b/clients/algoliasearch-client-javascript/client-predict/git_push.sh deleted file mode 100644 index b151edf823..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/git_push.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh -# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ -# -# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" - -git_user_id=$1 -git_repo_id=$2 -release_note=$3 -git_host=$4 - -if [ "$git_host" = "" ]; then - git_host="algolia" - echo "[INFO] No command line input provided. Set \$git_host to $git_host" -fi - -if [ "$git_user_id" = "" ]; then - git_user_id="algolia" - echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" -fi - -if [ "$git_repo_id" = "" ]; then - git_repo_id="algoliasearch-client-javascript" - echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" -fi - -if [ "$release_note" = "" ]; then - release_note="Minor update" - echo "[INFO] No command line input provided. Set \$release_note to $release_note" -fi - -# Initialize the local directory as a Git repository -git init - -# Adds the files in the local repository and stages them for commit. -git add . - -# Commits the tracked changes and prepares them to be pushed to a remote repository. -git commit -m "$release_note" - -# Sets the new remote -git_remote=$(git remote) -if [ "$git_remote" = "" ]; then # git remote not defined - - if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." - git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git - else - git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git - fi - -fi - -git pull origin master - -# Pushes (Forces) the changes in the local repository up to the remote repository -echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" -git push origin master 2>&1 | grep -v 'To https' From c0a5cb5d1a6565d8c51ad5ce1f10401071cb1de9 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Thu, 10 Feb 2022 14:00:13 +0200 Subject: [PATCH 23/27] Fix error base path --- specs/predict/responses/UserNotFound.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/predict/responses/UserNotFound.yml b/specs/predict/responses/UserNotFound.yml index 6476b08812..86630af3f7 100644 --- a/specs/predict/responses/UserNotFound.yml +++ b/specs/predict/responses/UserNotFound.yml @@ -2,4 +2,4 @@ description: User not found. content: application/json: schema: - $ref: ../schemas/ErrorBase.yml + $ref: ../../common/schemas/ErrorBase.yml From 3278c8596471c0618bed683db9ad097703fb9c22 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Thu, 10 Feb 2022 15:35:08 +0200 Subject: [PATCH 24/27] Remove extra empty lines --- specs/predict/paths/fetchUserProfile.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index 465818b0cd..430a970664 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -6,7 +6,6 @@ post: summary: Get user profile. parameters: - $ref: '../common/parameters.yml#/userID' - requestBody: required: true content: @@ -19,7 +18,6 @@ post: properties: modelsToRetrieve: type: array - title: modelsToRetrieve description: List with model types for which to retrieve predictions items: type: string @@ -29,7 +27,6 @@ post: - affinities typesToRetrieve: type: array - title: typesToRetrieve description: List with types to be retrieved. items: type: string @@ -37,7 +34,6 @@ post: - properties - segments minItems: 1 - responses: '200': description: OK From 9ccd6d0c44860ad127da5861f4a4e6757a4d5690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Fri, 11 Feb 2022 10:12:33 +0100 Subject: [PATCH 25/27] regenerate and fix host edge case --- .github/actions/cache/action.yml | 4 +- .../client-predict/.gitignore | 4 -- .../client-predict/tsconfig.json | 22 -------- .../client-predict/.openapi-generator-ignore | 1 + .../{ => packages}/client-predict/browser.ts | 1 - .../client-predict/model/errorBase.ts | 0 .../model/fetchUserProfileResponse.ts | 0 .../fetchUserProfileResponsePredictions.ts | 0 ...serProfileResponsePredictionsAffinities.ts | 0 ...ofileResponsePredictionsAffinitiesValue.ts | 0 ...erProfileResponsePredictionsFunnelStage.ts | 0 ...fileResponsePredictionsFunnelStageValue.ts | 0 ...serProfileResponsePredictionsOrderValue.ts | 0 .../fetchUserProfileResponseProperties.ts | 0 .../model/fetchUserProfileResponseSegments.ts | 0 .../client-predict/model/params.ts | 0 .../{ => packages}/client-predict/node.ts | 1 - .../client-predict/package.json | 3 +- .../client-predict/src/predictApi.ts | 50 ++++--------------- .../packages/client-predict/tsconfig.json | 8 +++ openapitools.json | 5 +- playground/javascript/predict.ts | 7 +-- playground/javascript/sources.ts | 6 ++- scripts/pre-gen/setHostsOptions.ts | 10 ++++ templates/javascript/api-single.mustache | 12 +++-- yarn.lock | 5 +- 26 files changed, 55 insertions(+), 84 deletions(-) delete mode 100644 clients/algoliasearch-client-javascript/client-predict/.gitignore delete mode 100644 clients/algoliasearch-client-javascript/client-predict/tsconfig.json rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/.openapi-generator-ignore (96%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/browser.ts (95%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/errorBase.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponse.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponsePredictions.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponseProperties.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/fetchUserProfileResponseSegments.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/model/params.ts (100%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/node.ts (95%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/package.json (94%) rename clients/algoliasearch-client-javascript/{ => packages}/client-predict/src/predictApi.ts (73%) create mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/tsconfig.json diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 89f1cc36a7..1d35920770 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -104,8 +104,8 @@ runs: if: ${{ inputs.job == 'cts' }} uses: actions/cache@v2 with: - path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/client-predict/dist - key: ${{ runner.os }}-1-js-client-predict-${{ hashFiles('clients/algoliasearch-client-javascript/client-predict/**') }}-${{ hashFiles('specs/dist/predict.yml') }} + 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' }} diff --git a/clients/algoliasearch-client-javascript/client-predict/.gitignore b/clients/algoliasearch-client-javascript/client-predict/.gitignore deleted file mode 100644 index 8aafcdc3fd..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -dist -.openapi-generator -.env diff --git a/clients/algoliasearch-client-javascript/client-predict/tsconfig.json b/clients/algoliasearch-client-javascript/client-predict/tsconfig.json deleted file mode 100644 index 2613b3ebad..0000000000 --- a/clients/algoliasearch-client-javascript/client-predict/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "noImplicitAny": false, - "suppressImplicitAnyIndexErrors": true, - "target": "ES6", - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "strict": true, - "moduleResolution": "node", - "removeComments": true, - "sourceMap": true, - "noLib": false, - "declaration": true, - "lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"], - "outDir": "dist", - "typeRoots": ["node_modules/@types"], - "types": ["node"] - }, - "include": ["src", "model", "node.ts", "browser.ts"], - "exclude": ["dist", "node_modules"] -} diff --git a/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore b/clients/algoliasearch-client-javascript/packages/client-predict/.openapi-generator-ignore similarity index 96% rename from clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore rename to clients/algoliasearch-client-javascript/packages/client-predict/.openapi-generator-ignore index 000abf8f71..29b08dc3a5 100644 --- a/clients/algoliasearch-client-javascript/client-predict/.openapi-generator-ignore +++ b/clients/algoliasearch-client-javascript/packages/client-predict/.openapi-generator-ignore @@ -6,3 +6,4 @@ git_push.sh model/models.ts +.gitignore diff --git a/clients/algoliasearch-client-javascript/client-predict/browser.ts b/clients/algoliasearch-client-javascript/packages/client-predict/browser.ts similarity index 95% rename from clients/algoliasearch-client-javascript/client-predict/browser.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/browser.ts index a3b4095b5e..5f8a95e25c 100644 --- a/clients/algoliasearch-client-javascript/client-predict/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/browser.ts @@ -5,7 +5,6 @@ import { createPredictApi } from './src/predictApi'; import type { PredictApi } from './src/predictApi'; export * from './src/predictApi'; -export * from '@algolia/client-common'; export function predictApi( appId: string, diff --git a/clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/errorBase.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/errorBase.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/errorBase.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponse.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictions.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictions.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictions.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseProperties.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseProperties.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseProperties.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseSegments.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/fetchUserProfileResponseSegments.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseSegments.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/model/params.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/params.ts similarity index 100% rename from clients/algoliasearch-client-javascript/client-predict/model/params.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/params.ts diff --git a/clients/algoliasearch-client-javascript/client-predict/node.ts b/clients/algoliasearch-client-javascript/packages/client-predict/node.ts similarity index 95% rename from clients/algoliasearch-client-javascript/client-predict/node.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/node.ts index 8b94b68728..a2cad9ce98 100644 --- a/clients/algoliasearch-client-javascript/client-predict/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/node.ts @@ -5,7 +5,6 @@ import { createPredictApi } from './src/predictApi'; import type { PredictApi } from './src/predictApi'; export * from './src/predictApi'; -export * from '@algolia/client-common'; export function predictApi( appId: string, diff --git a/clients/algoliasearch-client-javascript/client-predict/package.json b/clients/algoliasearch-client-javascript/packages/client-predict/package.json similarity index 94% rename from clients/algoliasearch-client-javascript/client-predict/package.json rename to clients/algoliasearch-client-javascript/packages/client-predict/package.json index 628837be96..05adb7aea9 100644 --- a/clients/algoliasearch-client-javascript/client-predict/package.json +++ b/clients/algoliasearch-client-javascript/packages/client-predict/package.json @@ -18,8 +18,7 @@ "clean": "rm -rf dist/" }, "engines": { - "node": "^14.0.0", - "yarn": "^3.0.0" + "node": "^14.0.0" }, "dependencies": { "@algolia/client-common": "5.0.0", diff --git a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts similarity index 73% rename from clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts index f3a95a9c15..29bd285e67 100644 --- a/clients/algoliasearch-client-javascript/client-predict/src/predictApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts @@ -1,9 +1,4 @@ -import { - shuffle, - Transporter, - createAuth, - getUserAgent, -} from '@algolia/client-common'; +import { Transporter, createAuth, getUserAgent } from '@algolia/client-common'; import type { CreateClientOptions, Headers, @@ -16,46 +11,21 @@ import type { Params } from '../model/params'; export const version = '0.0.1'; -function getDefaultHosts(appId: string): Host[] { - return ( - [ - { - url: `${appId}-dsn.algolia.net`, - accept: 'read', - protocol: 'https', - }, - { - url: `${appId}.algolia.net`, - accept: 'write', - protocol: 'https', - }, - ] as Host[] - ).concat( - shuffle([ - { - url: `${appId}-1.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-2.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - { - url: `${appId}-3.algolianet.com`, - accept: 'readWrite', - protocol: 'https', - }, - ]) - ); +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(options.appId), + hosts: options?.hosts ?? getDefaultHosts(), baseHeaders: { 'content-type': 'application/x-www-form-urlencoded', ...auth.headers(), 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 9f1a66aaf3..383541a63c 100644 --- a/openapitools.json +++ b/openapitools.json @@ -197,7 +197,7 @@ "templateDir": "#{cwd}/templates/javascript/", "config": "#{cwd}/openapitools.json", "apiPackage": "src", - "output": "#{cwd}/clients/algoliasearch-client-javascript/client-predict", + "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-predict", "glob": "specs/dist/predict.yml", "gitHost": "algolia", "gitUserId": "algolia", @@ -209,7 +209,8 @@ "apiName": "predict", "capitalizedApiName": "Predict", "packageVersion": "0.0.1", - "packageName": "@algolia/client-predict" + "packageName": "@algolia/client-predict", + "experimentalHost": "predict-api-oslcbws3zq-ew.a.run.app" } }, "java-search": { diff --git a/playground/javascript/predict.ts b/playground/javascript/predict.ts index 21670147a3..301a050396 100644 --- a/playground/javascript/predict.ts +++ b/playground/javascript/predict.ts @@ -1,4 +1,5 @@ -import { predictApi, ApiError } from '@algolia/client-predict'; +import { predictApi } from '@algolia/client-predict'; +import { ApiError } from '@algolia/client-common'; import dotenv from 'dotenv'; dotenv.config({ path: '../.env' }); @@ -16,8 +17,8 @@ async function testPredict() { const userProfile = await predictClient.fetchUserProfile({ userID: userId, params: { - modelsToRetrieve: ["funnel_stage", "order_value", "affinities"], - typesToRetrieve: ["properties", "segments"], + modelsToRetrieve: ['funnel_stage', 'order_value', 'affinities'], + typesToRetrieve: ['properties', 'segments'], }, }); 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/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 8421246351..b884e921d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -89,9 +89,9 @@ __metadata: languageName: unknown linkType: soft -"@algolia/client-predict@0.0.1, @algolia/client-predict@workspace:clients/algoliasearch-client-javascript/client-predict": +"@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/client-predict" + 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 @@ -101,7 +101,6 @@ __metadata: languageName: unknown linkType: soft -"@algolia/client-query-suggestions@5.0.0, @algolia/client-query-suggestions@workspace:clients/algoliasearch-client-javascript/client-query-suggestions": "@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" From 1861535a24d5d6f08e75fb20b72ceec55982d920 Mon Sep 17 00:00:00 2001 From: Alexandra Anghel Date: Fri, 11 Feb 2022 11:51:19 +0200 Subject: [PATCH 26/27] Add response titles, regenerate client --- .../packages/client-predict/model/affinities.ts | 5 +++++ .../client-predict/model/fetchUserProfileResponse.ts | 12 ++++++------ .../model/fetchUserProfileResponsePredictions.ts | 9 --------- .../fetchUserProfileResponsePredictionsAffinities.ts | 9 --------- ...hUserProfileResponsePredictionsAffinitiesValue.ts | 5 ----- ...fetchUserProfileResponsePredictionsFunnelStage.ts | 9 --------- ...UserProfileResponsePredictionsFunnelStageValue.ts | 4 ---- .../packages/client-predict/model/funnelStage.ts | 4 ++++ .../packages/client-predict/model/predictions.ts | 9 +++++++++ .../client-predict/model/predictionsAffinities.ts | 9 +++++++++ .../client-predict/model/predictionsFunnelStage.ts | 9 +++++++++ ...ictionsOrderValue.ts => predictionsOrderValue.ts} | 2 +- ...serProfileResponseProperties.ts => properties.ts} | 2 +- ...tchUserProfileResponseSegments.ts => segments.ts} | 2 +- specs/predict/paths/fetchUserProfile.yml | 5 +++++ 15 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/affinities.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictions.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts delete mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/funnelStage.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/predictions.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsAffinities.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsFunnelStage.ts rename clients/algoliasearch-client-javascript/packages/client-predict/model/{fetchUserProfileResponsePredictionsOrderValue.ts => predictionsOrderValue.ts} (61%) rename clients/algoliasearch-client-javascript/packages/client-predict/model/{fetchUserProfileResponseProperties.ts => properties.ts} (86%) rename clients/algoliasearch-client-javascript/packages/client-predict/model/{fetchUserProfileResponseSegments.ts => segments.ts} (79%) 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/fetchUserProfileResponse.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts index 83dd597e63..58ebd054ad 100644 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponse.ts @@ -1,10 +1,10 @@ -import type { FetchUserProfileResponsePredictions } from './fetchUserProfileResponsePredictions'; -import type { FetchUserProfileResponseProperties } from './fetchUserProfileResponseProperties'; -import type { FetchUserProfileResponseSegments } from './fetchUserProfileResponseSegments'; +import type { Predictions } from './predictions'; +import type { Properties } from './properties'; +import type { Segments } from './segments'; export type FetchUserProfileResponse = { user: string; - predictions?: FetchUserProfileResponsePredictions; - properties?: FetchUserProfileResponseProperties; - segments?: FetchUserProfileResponseSegments; + predictions?: Predictions; + properties?: Properties; + segments?: Segments; }; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictions.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictions.ts deleted file mode 100644 index 98f5ef0621..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictions.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { FetchUserProfileResponsePredictionsAffinities } from './fetchUserProfileResponsePredictionsAffinities'; -import type { FetchUserProfileResponsePredictionsFunnelStage } from './fetchUserProfileResponsePredictionsFunnelStage'; -import type { FetchUserProfileResponsePredictionsOrderValue } from './fetchUserProfileResponsePredictionsOrderValue'; - -export type FetchUserProfileResponsePredictions = { - funnel_stage?: FetchUserProfileResponsePredictionsFunnelStage; - order_value?: FetchUserProfileResponsePredictionsOrderValue; - affinities?: FetchUserProfileResponsePredictionsAffinities; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts deleted file mode 100644 index 1f4dd9b011..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinities.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { FetchUserProfileResponsePredictionsAffinitiesValue } from './fetchUserProfileResponsePredictionsAffinitiesValue'; - -/** - * Prediction for the **affinities** model. - */ -export type FetchUserProfileResponsePredictionsAffinities = { - value?: FetchUserProfileResponsePredictionsAffinitiesValue[]; - lastUpdatedAt?: string; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts deleted file mode 100644 index c0bcc5bdb3..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsAffinitiesValue.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type FetchUserProfileResponsePredictionsAffinitiesValue = { - name?: string; - value?: string; - probability?: number; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts deleted file mode 100644 index d832aba681..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStage.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { FetchUserProfileResponsePredictionsFunnelStageValue } from './fetchUserProfileResponsePredictionsFunnelStageValue'; - -/** - * Prediction for the **funnel_stage** model. - */ -export type FetchUserProfileResponsePredictionsFunnelStage = { - value?: FetchUserProfileResponsePredictionsFunnelStageValue[]; - lastUpdatedAt?: string; -}; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts deleted file mode 100644 index 10fd439ca5..0000000000 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsFunnelStageValue.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type FetchUserProfileResponsePredictionsFunnelStageValue = { - name?: string; - probability?: number; -}; 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/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/fetchUserProfileResponsePredictionsOrderValue.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsOrderValue.ts similarity index 61% rename from clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsOrderValue.ts index 9628ac1883..2180dacb5f 100644 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponsePredictionsOrderValue.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/predictionsOrderValue.ts @@ -1,7 +1,7 @@ /** * Prediction for the **order_value** model. */ -export type FetchUserProfileResponsePredictionsOrderValue = { +export type PredictionsOrderValue = { value?: number; lastUpdatedAt?: string; }; diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseProperties.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/properties.ts similarity index 86% rename from clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseProperties.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/properties.ts index 8400654fcc..e8c8dbe7eb 100644 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseProperties.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/properties.ts @@ -1,7 +1,7 @@ /** * Properties for the user profile. */ -export type FetchUserProfileResponseProperties = { +export type Properties = { /** * Raw user properties (key-value pairs). */ diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseSegments.ts b/clients/algoliasearch-client-javascript/packages/client-predict/model/segments.ts similarity index 79% rename from clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseSegments.ts rename to clients/algoliasearch-client-javascript/packages/client-predict/model/segments.ts index 1a3a5f745b..a05df5cf46 100644 --- a/clients/algoliasearch-client-javascript/packages/client-predict/model/fetchUserProfileResponseSegments.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/model/segments.ts @@ -1,7 +1,7 @@ /** * Segments that the user belongs to. */ -export type FetchUserProfileResponseSegments = { +export type Segments = { /** * List of computed segments IDs. */ diff --git a/specs/predict/paths/fetchUserProfile.yml b/specs/predict/paths/fetchUserProfile.yml index 430a970664..a5248fa175 100644 --- a/specs/predict/paths/fetchUserProfile.yml +++ b/specs/predict/paths/fetchUserProfile.yml @@ -49,6 +49,7 @@ post: type: string predictions: type: object + title: predictions properties: funnel_stage: type: object @@ -57,6 +58,7 @@ post: value: type: array items: + title: funnel_stage type: object properties: name: @@ -83,6 +85,7 @@ post: value: type: array items: + title: affinities type: object properties: name: @@ -97,6 +100,7 @@ post: type: string properties: type: object + title: properties description: Properties for the user profile properties: raw: @@ -110,6 +114,7 @@ post: description: Custom user properties (key-value pairs) segments: type: object + title: segments description: Segments that the user belongs to properties: computed: From 9a125386c4e38f367e227bddfa1b95f0fc43028e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= <20689156+shortcuts@users.noreply.github.com> Date: Fri, 11 Feb 2022 11:26:51 +0100 Subject: [PATCH 27/27] update clients/README.md --- clients/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/clients/README.md b/clients/README.md index 598fddd04e..195aca962a 100644 --- a/clients/README.md +++ b/clients/README.md @@ -10,15 +10,15 @@ This folder hosts the generated clients. ### JavaScript -- [@algolia/client-abtesting](./algoliasearch-client-javascript/client-abtesting/): The Algolia AB testing client. -- [@algolia/client-analytics](./algoliasearch-client-javascript/client-analytics/): The Algolia analytics client. -- [@algolia/client-insights](./algoliasearch-client-javascript/client-insights/): The Algolia insights client. -- [@algolia/client-personalization](./algoliasearch-client-javascript/client-personalization/): The Algolia personalization client. -- [@algolia/client-query-suggestions](./algoliasearch-client-javascript/client-query-suggestions/): The Algolia query suggestions client. -- [@algolia/client-search](./algoliasearch-client-javascript/client-search/): The Algolia search client. -- [@algolia/recommend](./algoliasearch-client-javascript/recommend/): The Algolia recommend client. -- [@algolia/sources](./algoliasearch-client-javascript/client-sources/): The Algolia sources client. -- [@algolia/predict](./algoliasearch-client-javascript/client-predict/): The Algolia predict client. -- [@algolia/client-common](./algoliasearch-client-javascript/client-common/): The JavaScript clients common files. -- [@algolia/requester-browser-xhr](./algoliasearch-client-javascript/requester-browser-xhr/): Browser XHR requester for the Algolia JavaScript clients. -- [@algolia/requester-node-http](./algoliasearch-client-javascript/requester-node-http/): Node.js HTTP requester for the Algolia JavaScript clients. +- [@algolia/client-abtesting](./algoliasearch-client-javascript/packages/client-abtesting/): The Algolia AB testing client. +- [@algolia/client-analytics](./algoliasearch-client-javascript/packages/client-analytics/): The Algolia analytics client. +- [@algolia/client-insights](./algoliasearch-client-javascript/packages/client-insights/): The Algolia insights client. +- [@algolia/client-personalization](./algoliasearch-client-javascript/packages/client-personalization/): The Algolia personalization client. +- [@algolia/client-query-suggestions](./algoliasearch-client-javascript/packages/client-query-suggestions/): The Algolia query suggestions client. +- [@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.