diff --git a/clients/algoliasearch-client-javascript/README.md b/clients/algoliasearch-client-javascript/README.md index a3f52d4afe..33e9f9c912 100644 --- a/clients/algoliasearch-client-javascript/README.md +++ b/clients/algoliasearch-client-javascript/README.md @@ -47,7 +47,11 @@ Without a package manager Add the following JavaScript snippet to the
of your website: ```html - +// for the full client + + +// for the lite client + ``` You can now import the Algolia API client in your project and play with it. @@ -63,7 +67,7 @@ import { liteClient } from 'algoliasearch/lite'; const client = liteClient('YOUR_APP_ID', 'YOUR_API_KEY'); ``` -For full documentation, visit the **[Algolia JavaScript API Client](https://www.algolia.com/doc/libraries/javascript/)**. +For full documentation, visit the **[Algolia JavaScript API Client](https://www.algolia.com/doc/libraries/javascript/v5/methods/search/)**. ## ❓ Troubleshooting diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index 4ed4856663..79bad9b646 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -148,14 +148,23 @@ public static String getPackageName(String client) throws ConfigException { /** Set default generator options */ private void setDefaultGeneratorOptions() { - String apiName = CLIENT + Helpers.API_SUFFIX; + String clientName = CLIENT + Helpers.API_SUFFIX; String packageName = getPackageName((String) additionalProperties.get("client")); - additionalProperties.put("apiName", apiName); + additionalProperties.put("apiName", CLIENT); + additionalProperties.put("clientName", clientName); additionalProperties.put("algoliaAgent", Helpers.capitalize(CLIENT)); additionalProperties.put("isSearchClient", CLIENT.equals("search") || isAlgoliasearchClient); additionalProperties.put("isIngestionClient", CLIENT.equals("ingestion")); additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient); + additionalProperties.put( + "isAvailableInAlgoliasearch", + CLIENT.equals("search") || + CLIENT.equals("recommend") || + CLIENT.equals("personalization") || + CLIENT.equals("analytics") || + CLIENT.equals("abtesting") + ); additionalProperties.put("packageVersion", Helpers.getPackageJsonVersion(packageName)); additionalProperties.put("packageName", packageName); additionalProperties.put("npmPackageName", isAlgoliasearchClient ? packageName : "@algolia/" + packageName); @@ -170,8 +179,9 @@ private void setDefaultGeneratorOptions() { additionalProperties.put("recommendVersion", Helpers.getPackageJsonVersion("recommend")); // Files used to generate the `lite` client - apiName = "lite" + Helpers.API_SUFFIX; - additionalProperties.put("apiName", apiName); + clientName = "lite" + Helpers.API_SUFFIX; + additionalProperties.put("apiName", "search"); + additionalProperties.put("clientName", clientName); additionalProperties.put("algoliaAgent", "Lite"); } } diff --git a/templates/javascript/clients/README.mustache b/templates/javascript/clients/README.mustache index 6d28116090..5c1a25f2a0 100644 --- a/templates/javascript/clients/README.mustache +++ b/templates/javascript/clients/README.mustache @@ -32,31 +32,51 @@ ## 💡 Getting Started -To get started, you first need to install {{npmPackageName}} (or any other available API client package). +{{#isAvailableInAlgoliasearch}} +> [!TIP] +> This API client is already a dependency of [the algoliasearch client](https://www.npmjs.com/package/algoliasearch), you don't need to manually install `{{{npmPackageName}}}` if you already have `algoliasearch` installed. +{{/isAvailableInAlgoliasearch}} +To get started, you first need to install {{npmPackageName}} (or any other available API client package). All of our clients comes with type definition, and are available for both browser and node environments. +### With a package manager + + ```bash -yarn add {{npmPackageName}} +yarn add {{npmPackageName}}@{{{packageVersion}}} +# or +npm install {{npmPackageName}}@{{{packageVersion}}} # or -npm install {{npmPackageName}} +pnpm add {{npmPackageName}}@{{{packageVersion}}} ``` -Without a package manager +### Without a package manager Add the following JavaScript snippet to the of your website: ```html - +{{#isAlgoliasearchClient}} +// for the full client + + +// for the lite client + +{{/isAlgoliasearchClient}} +{{^isAlgoliasearchClient}} + +{{/isAlgoliasearchClient}} ``` +### Usage + You can now import the Algolia API client in your project and play with it. ```js {{^isAlgoliasearchClient}} -import { {{apiName}} } from '{{npmPackageName}}'; +import { {{clientName}} } from '{{npmPackageName}}'; -const client = {{apiName}}('YOUR_APP_ID', 'YOUR_API_KEY'); +const client = {{clientName}}('YOUR_APP_ID', 'YOUR_API_KEY'); {{/isAlgoliasearchClient}} {{#isAlgoliasearchClient}} import { algoliasearch } from '{{npmPackageName}}'; @@ -64,13 +84,13 @@ import { algoliasearch } from '{{npmPackageName}}'; const client = algoliasearch('YOUR_APP_ID', 'YOUR_API_KEY'); // or with the lite client -import { {{apiName}} } from '{{npmPackageName}}/lite'; +import { {{clientName}} } from '{{npmPackageName}}/lite'; -const client = {{apiName}}('YOUR_APP_ID', 'YOUR_API_KEY'); +const client = {{clientName}}('YOUR_APP_ID', 'YOUR_API_KEY'); {{/isAlgoliasearchClient}} ``` -For full documentation, visit the **[Algolia JavaScript API Client](https://www.algolia.com/doc/libraries/javascript/)**. +For full documentation, visit the **[Algolia JavaScript API Client](https://www.algolia.com/doc/libraries/javascript/v5/methods/{{#lambda.kebabcase}}{{apiName}}{{/lambda.kebabcase}}/)**. ## ❓ Troubleshooting diff --git a/templates/javascript/clients/api-single.mustache b/templates/javascript/clients/api-single.mustache index 009c970509..34b77e4e12 100644 --- a/templates/javascript/clients/api-single.mustache +++ b/templates/javascript/clients/api-single.mustache @@ -13,7 +13,7 @@ export const apiClientVersion = '{{packageVersion}}'; {{/isIngestionClient}} // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({ +export function create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}({ appId: appIdOption, apiKey: apiKeyOption, authMode, diff --git a/templates/javascript/clients/client/builds/browser.mustache b/templates/javascript/clients/client/builds/browser.mustache index 7b7dc3109c..675766aec7 100644 --- a/templates/javascript/clients/client/builds/browser.mustache +++ b/templates/javascript/clients/client/builds/browser.mustache @@ -1,9 +1,9 @@ // {{{generationBanner}}} -export type {{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}} = ReturnType