From 21d09d3d3dc7c52f74f3898e68487b740825d0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Mon, 14 Oct 2024 16:13:49 +0200 Subject: [PATCH] feat(javascript): add every APIs (#3942) --- .eslintignore | 1 + .github/workflows/check.yml | 10 +-- .../bundlesize.config.json | 10 +-- .../package.json | 2 +- .../algoliasearch-client-javascript/yarn.lock | 27 +++---- .../codegen/AlgoliaJavascriptGenerator.java | 39 +++++----- .../com/algolia/codegen/utils/Helpers.java | 16 +++++ playground/javascript/node/algoliasearch.ts | 4 +- templates/javascript/clients/README.mustache | 4 +- .../algoliasearch/builds/definition.mustache | 64 ++++++----------- .../algoliasearch/builds/models.mustache | 71 ++++++++++++------- .../javascript/clients/api-single.mustache | 2 +- .../clients/client/api/hosts.mustache | 1 + .../clients/client/builds/definition.mustache | 3 +- templates/javascript/clients/package.mustache | 8 +-- 15 files changed, 142 insertions(+), 120 deletions(-) diff --git a/.eslintignore b/.eslintignore index 583e0662e3..85f17a31be 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,3 +6,4 @@ composer.json tsconfig.json vendor builddir +foo diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 5fabfb14f8..fe37963a60 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -199,10 +199,10 @@ jobs: type: specs - name: Remove generated clients - if: ${{ startsWith(env.head_ref, 'chore/prepare-release-') }} + if: ${{ startsWith(github.head_ref, 'chore/prepare-release-') }} run: | cd clients/algoliasearch-client-javascript/packages - ls | grep -v -E "(client-common|requester-*|algoliasearch)" | xargs rm -rf + ls | grep -v -E "(logger-console|client-common|requester-*|algoliasearch)" | xargs rm -rf cd algoliasearch ls | grep -v -E "__tests__" | xargs rm -rf @@ -228,11 +228,11 @@ jobs: run: cd clients/algoliasearch-client-javascript && yarn test ${{ !contains(fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun, 'algoliasearch') && '--ignore algoliasearch' || '' }} - name: Test JavaScript bundle size - if: ${{ startsWith(env.head_ref, 'chore/prepare-release-') }} + if: ${{ startsWith(github.head_ref, 'chore/prepare-release-') }} run: cd clients/algoliasearch-client-javascript && yarn test:size - name: Test JavaScript bundle and types - if: ${{ startsWith(env.head_ref, 'chore/prepare-release-') }} + if: ${{ startsWith(github.head_ref, 'chore/prepare-release-') }} run: cd clients/algoliasearch-client-javascript && yarn test:bundle - name: Remove previous CTS output @@ -335,7 +335,7 @@ jobs: run: yarn cli generate ${{ matrix.client.language }} ${{ matrix.client.toRun }} - name: Update composer.lock - if: ${{ matrix.client.language == 'php' && startsWith(env.head_ref, 'chore/renovateBaseBranch') && matrix.client.isMainVersion }} + if: ${{ matrix.client.language == 'php' && startsWith(github.head_ref, 'chore/renovateBaseBranch') && matrix.client.isMainVersion }} run: cd ${{ matrix.client.path }} && composer update - name: Check for file duplicates in Swift diff --git a/clients/algoliasearch-client-javascript/bundlesize.config.json b/clients/algoliasearch-client-javascript/bundlesize.config.json index f72ce0e533..14fb1b2950 100644 --- a/clients/algoliasearch-client-javascript/bundlesize.config.json +++ b/clients/algoliasearch-client-javascript/bundlesize.config.json @@ -2,7 +2,7 @@ "files": [ { "path": "packages/algoliasearch/dist/algoliasearch.umd.js", - "maxSize": "9.50KB" + "maxSize": "12.60KB" }, { "path": "packages/algoliasearch/dist/lite/builds/browser.umd.js", @@ -10,11 +10,11 @@ }, { "path": "packages/client-abtesting/dist/builds/browser.umd.js", - "maxSize": "4.10KB" + "maxSize": "4.15KB" }, { "path": "packages/client-analytics/dist/builds/browser.umd.js", - "maxSize": "4.75KB" + "maxSize": "4.85KB" }, { "path": "packages/client-insights/dist/builds/browser.umd.js", @@ -30,7 +30,7 @@ }, { "path": "packages/client-search/dist/builds/browser.umd.js", - "maxSize": "7.15KB" + "maxSize": "7.25KB" }, { "path": "packages/ingestion/dist/builds/browser.umd.js", @@ -42,7 +42,7 @@ }, { "path": "packages/recommend/dist/builds/browser.umd.js", - "maxSize": "4.10KB" + "maxSize": "4.15KB" } ] } diff --git a/clients/algoliasearch-client-javascript/package.json b/clients/algoliasearch-client-javascript/package.json index 7beab792d4..da0789dada 100644 --- a/clients/algoliasearch-client-javascript/package.json +++ b/clients/algoliasearch-client-javascript/package.json @@ -7,7 +7,7 @@ ], "scripts": { "build:all": "lerna run build --include-dependencies", - "build:many": "lerna run build --scope '@algolia/requester-testing' --scope ${0:-'{@algolia/*,algoliasearch}'} --include-dependencies", + "build:many": "lerna run build --scope '@algolia/requester-testing' --scope '@algolia/logger-console' --scope ${0:-'{@algolia/*,algoliasearch}'} --include-dependencies", "clean": "lerna run clean", "release:bump": "lerna version ${0:-patch} --no-changelog --no-git-tag-version --no-push --exact --force-publish --yes", "release:publish": "tsc --project scripts/tsconfig.json && node scripts/dist/scripts/publish.js", diff --git a/clients/algoliasearch-client-javascript/yarn.lock b/clients/algoliasearch-client-javascript/yarn.lock index 19141a3c13..90eca7a7ff 100644 --- a/clients/algoliasearch-client-javascript/yarn.lock +++ b/clients/algoliasearch-client-javascript/yarn.lock @@ -54,7 +54,7 @@ __metadata: languageName: unknown linkType: soft -"@algolia/client-insights@workspace:packages/client-insights": +"@algolia/client-insights@npm:5.8.1, @algolia/client-insights@workspace:packages/client-insights": version: 0.0.0-use.local resolution: "@algolia/client-insights@workspace:packages/client-insights" dependencies: @@ -88,7 +88,7 @@ __metadata: languageName: unknown linkType: soft -"@algolia/client-query-suggestions@workspace:packages/client-query-suggestions": +"@algolia/client-query-suggestions@npm:5.8.1, @algolia/client-query-suggestions@workspace:packages/client-query-suggestions": version: 0.0.0-use.local resolution: "@algolia/client-query-suggestions@workspace:packages/client-query-suggestions" dependencies: @@ -105,7 +105,7 @@ __metadata: languageName: unknown linkType: soft -"@algolia/client-search@npm:5.8.1, @algolia/client-search@workspace:packages/client-search": +"@algolia/client-search@workspace:packages/client-search": version: 0.0.0-use.local resolution: "@algolia/client-search@workspace:packages/client-search" dependencies: @@ -122,7 +122,7 @@ __metadata: languageName: unknown linkType: soft -"@algolia/ingestion@workspace:packages/ingestion": +"@algolia/ingestion@npm:1.8.1, @algolia/ingestion@workspace:packages/ingestion": version: 0.0.0-use.local resolution: "@algolia/ingestion@workspace:packages/ingestion" dependencies: @@ -155,7 +155,7 @@ __metadata: languageName: unknown linkType: soft -"@algolia/monitoring@workspace:packages/monitoring": +"@algolia/monitoring@npm:1.8.1, @algolia/monitoring@workspace:packages/monitoring": version: 0.0.0-use.local resolution: "@algolia/monitoring@workspace:packages/monitoring" dependencies: @@ -2088,8 +2088,11 @@ __metadata: "@algolia/client-abtesting": "npm:5.8.1" "@algolia/client-analytics": "npm:5.8.1" "@algolia/client-common": "npm:5.8.1" + "@algolia/client-insights": "npm:5.8.1" "@algolia/client-personalization": "npm:5.8.1" - "@algolia/client-search": "npm:5.8.1" + "@algolia/client-query-suggestions": "npm:5.8.1" + "@algolia/ingestion": "npm:1.8.1" + "@algolia/monitoring": "npm:1.8.1" "@algolia/recommend": "npm:5.8.1" "@algolia/requester-browser-xhr": "npm:5.8.1" "@algolia/requester-fetch": "npm:5.8.1" @@ -3938,13 +3941,13 @@ __metadata: linkType: hard "form-data@npm:^4.0.0": - version: 4.0.0 - resolution: "form-data@npm:4.0.0" + version: 4.0.1 + resolution: "form-data@npm:4.0.1" dependencies: asynckit: "npm:^0.4.0" combined-stream: "npm:^1.0.8" mime-types: "npm:^2.1.12" - checksum: 10/7264aa760a8cf09482816d8300f1b6e2423de1b02bba612a136857413fdc96d7178298ced106817655facc6b89036c6e12ae31c9eb5bdc16aabf502ae8a5d805 + checksum: 10/6adb1cff557328bc6eb8a68da205f9ae44ab0e88d4d9237aaf91eed591ffc64f77411efb9016af7d87f23d0a038c45a788aa1c6634e51175c4efa36c2bc53774 languageName: node linkType: hard @@ -5819,11 +5822,11 @@ __metadata: linkType: hard "nan@npm:^2.14.0": - version: 2.20.0 - resolution: "nan@npm:2.20.0" + version: 2.21.0 + resolution: "nan@npm:2.21.0" dependencies: node-gyp: "npm:latest" - checksum: 10/5f16e4c9953075d9920229c703c1d781c0b74118ce3d9e926b448a4eef92b7d8be5ac6adc748a13a5fafb594436cbfe63250e3471aefdd78e3a0cd14603b9ba7 + checksum: 10/4517d316776b509a961c65241b72863e70f63aa5b0c354ca19fbbbf7c78254e54aa1f0de142fac1df986a04c27e74a1fb7e4aa85e9e3834daa172b8d9d1bbb07 languageName: node linkType: hard diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index 7de7583a00..faa94bdf66 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -5,10 +5,7 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.servers.Server; -import java.util.List; -import java.util.Map; -import java.util.Spliterator; -import java.util.Spliterators; +import java.util.*; import java.util.stream.StreamSupport; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.SupportingFile; @@ -158,26 +155,32 @@ private void setDefaultGeneratorOptions() { 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); additionalProperties.put("nodeSearchHelpers", CLIENT.equals("search") || isAlgoliasearchClient); if (isAlgoliasearchClient) { - // Files used to create the package.json of the algoliasearch package - additionalProperties.put("analyticsVersion", Helpers.getPackageJsonVersion("client-analytics")); - additionalProperties.put("abtestingVersion", Helpers.getPackageJsonVersion("client-abtesting")); - additionalProperties.put("personalizationVersion", Helpers.getPackageJsonVersion("client-personalization")); - additionalProperties.put("searchVersion", Helpers.getPackageJsonVersion("client-search")); - additionalProperties.put("recommendVersion", Helpers.getPackageJsonVersion("recommend")); + var dependencies = new ArrayList>(); + List> packages = Helpers.getClientConfigList("javascript", "clients"); + for (Map pkg : packages) { + String name = ((String) pkg.get("output")).replace("clients/algoliasearch-client-javascript/packages/", ""); + if (name.contains("search")) { + continue; + } + + var dependency = new HashMap(); + dependency.put("dependencyName", Helpers.createClientName((String) pkg.get("name"), "javascript")); + dependency.put("dependencyPackage", "@algolia/" + name); + dependency.put("dependencyVersion", Helpers.getPackageJsonVersion(name)); + dependency.put( + "dependencyHasRegionalHosts", + !name.contains("search") && !name.contains("recommend") && !name.contains("monitoring") + ); + + dependencies.add(dependency); + } + additionalProperties.put("dependencies", dependencies); // Files used to generate the `lite` client clientName = "lite" + Helpers.API_SUFFIX; diff --git a/generators/src/main/java/com/algolia/codegen/utils/Helpers.java b/generators/src/main/java/com/algolia/codegen/utils/Helpers.java index 2b60eac644..4296d2dad5 100644 --- a/generators/src/main/java/com/algolia/codegen/utils/Helpers.java +++ b/generators/src/main/java/com/algolia/codegen/utils/Helpers.java @@ -198,6 +198,22 @@ public static String getClientConfigField(String language, String... fields) thr return value.asText(); } + /** Get the `field` value in the `config/clients.config.json` file for the given language */ + public static List> getClientConfigList(String language, String... fields) throws ConfigException { + if (fields.length == 0) { + throw new ConfigException("getClientConfigList requires at least one field"); + } + JsonNode value = getClientConfig(language); + for (String field : fields) { + value = value.get(field); + } + try { + return new ObjectMapper().readerForListOf(Map.class).readValue(value); + } catch (IOException e) { + throw new ConfigException("Cannot convert value", e); + } + } + public static List getClientListForLanguage(String language) throws ConfigException { JsonNode value = getClientConfig(language); value = value.get("clients"); diff --git a/playground/javascript/node/algoliasearch.ts b/playground/javascript/node/algoliasearch.ts index 6de434cc53..a9e21f5e52 100644 --- a/playground/javascript/node/algoliasearch.ts +++ b/playground/javascript/node/algoliasearch.ts @@ -80,7 +80,7 @@ async function testAlgoliasearch() { } try { - const analyticsClient = client.initAnalytics(); + const analyticsClient = client.initAnalytics({region: 'de'}); const res = await analyticsClient.getTopFilterForAttribute({ attribute: 'myAttribute1,myAttribute2', @@ -97,7 +97,7 @@ async function testAlgoliasearch() { } try { - const abtestingClient = client.initAbtesting(); + const abtestingClient = client.initAbtesting({region: 'us'}); const res = await abtestingClient.getABTest({ id: 42, diff --git a/templates/javascript/clients/README.mustache b/templates/javascript/clients/README.mustache index 5c1a25f2a0..133b867e3b 100644 --- a/templates/javascript/clients/README.mustache +++ b/templates/javascript/clients/README.mustache @@ -32,10 +32,10 @@ ## 💡 Getting Started -{{#isAvailableInAlgoliasearch}} +{{^isAlgoliasearchClient}} > [!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}} +{{/isAlgoliasearchClient}} 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. diff --git a/templates/javascript/clients/algoliasearch/builds/definition.mustache b/templates/javascript/clients/algoliasearch/builds/definition.mustache index b455f15433..4236e3cfc6 100644 --- a/templates/javascript/clients/algoliasearch/builds/definition.mustache +++ b/templates/javascript/clients/algoliasearch/builds/definition.mustache @@ -1,30 +1,30 @@ // {{{generationBanner}}} import type { ClientOptions } from '@algolia/client-common'; -import type { AbtestingClient, Region as AbtestingRegion } from "@algolia/client-abtesting" -import type { AnalyticsClient, Region as AnalyticsRegion } from "@algolia/client-analytics" -import type { PersonalizationClient, Region as PersonalizationRegion } from "@algolia/client-personalization" -import type { RecommendClient } from "@algolia/recommend" -import type { SearchClient } from "@algolia/client-search" - -import { abtestingClient } from '@algolia/client-abtesting'; -import { analyticsClient } from '@algolia/client-analytics'; -import { personalizationClient } from '@algolia/client-personalization'; +import type { SearchClient } from '@algolia/client-search'; import { searchClient } from '@algolia/client-search'; -import { recommendClient } from '@algolia/recommend'; + +{{#dependencies}} +import { {{{dependencyName}}}Client } from '{{{dependencyPackage}}}'; +import type { {{#lambda.titlecase}}{{{dependencyName}}}{{/lambda.titlecase}}Client } from '{{{dependencyPackage}}}'; +{{/dependencies}} import type { InitClientOptions, - InitClientRegion, + {{#dependencies}} + {{#dependencyHasRegionalHosts}} + {{#lambda.titlecase}}{{{dependencyName}}}Region{{/lambda.titlecase}}, + {{#lambda.titlecase}}{{{dependencyName}}}RegionOptions{{/lambda.titlecase}}, + {{/dependencyHasRegionalHosts}} + {{/dependencies}} } from './models'; export * from './models'; export type Algoliasearch = SearchClient & { - initRecommend: (initOptions?: InitClientOptions)=> RecommendClient; - initAnalytics: (initOptions?: InitClientOptions & InitClientRegion)=> AnalyticsClient; - initAbtesting: (initOptions?: InitClientOptions & InitClientRegion)=> AbtestingClient; - initPersonalization: (initOptions: InitClientOptions & Required>)=> PersonalizationClient; + {{#dependencies}} + init{{#lambda.titlecase}}{{{dependencyName}}}{{/lambda.titlecase}}: (initOptions: InitClientOptions {{#dependencyHasRegionalHosts}}& {{#lambda.titlecase}}{{{dependencyName}}}RegionOptions{{/lambda.titlecase}}{{/dependencyHasRegionalHosts}}) => {{#lambda.titlecase}}{{{dependencyName}}}{{/lambda.titlecase}}Client; + {{/dependencies}} }; export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch { @@ -40,43 +40,19 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt return { ...client, + /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { return client.transporter.algoliaAgent.value; }, - initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => { - return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options); - }, - initAnalytics: (initOptions: InitClientOptions & InitClientRegion = {}): AnalyticsClient => { - return analyticsClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); + {{#dependencies}} + init{{#lambda.titlecase}}{{{dependencyName}}}{{/lambda.titlecase}}: (initOptions: InitClientOptions {{#dependencyHasRegionalHosts}}& {{#lambda.titlecase}}{{{dependencyName}}}RegionOptions{{/lambda.titlecase}}{{/dependencyHasRegionalHosts}}): {{#lambda.titlecase}}{{{dependencyName}}}{{/lambda.titlecase}}Client => { + return {{{dependencyName}}}Client(initOptions.appId || appId, initOptions.apiKey || apiKey, {{#dependencyHasRegionalHosts}}initOptions.region,{{/dependencyHasRegionalHosts}}initOptions.options); }, - initAbtesting: (initOptions: InitClientOptions & InitClientRegion = {}): AbtestingClient => { - return abtestingClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - }, - - initPersonalization: ( - initOptions: InitClientOptions & Required>, - ): PersonalizationClient => { - return personalizationClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - }, + {{/dependencies}} } } \ No newline at end of file diff --git a/templates/javascript/clients/algoliasearch/builds/models.mustache b/templates/javascript/clients/algoliasearch/builds/models.mustache index 1829c343de..0532b2f215 100644 --- a/templates/javascript/clients/algoliasearch/builds/models.mustache +++ b/templates/javascript/clients/algoliasearch/builds/models.mustache @@ -1,9 +1,18 @@ // {{{generationBanner}}} -import type { AbtestingClient, Region as AbTestingRegion } from '@algolia/client-abtesting'; -import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics'; +{{#dependencies}} +import type { + {{#lambda.titlecase}}{{{dependencyName}}}Client{{/lambda.titlecase}}, + {{#dependencyHasRegionalHosts}} + Region as {{#lambda.titlecase}}{{{dependencyName}}}Region{{/lambda.titlecase}}, + RegionOptions as {{#lambda.titlecase}}{{{dependencyName}}}RegionOptions{{/lambda.titlecase}}, + {{/dependencyHasRegionalHosts}} +} from '{{{dependencyPackage}}}'; +{{/dependencies}} + import type { ClientOptions } from '@algolia/client-common'; import type { + Action, AdvancedSyntaxFeatures, AlternativesAsExact, Anchoring, @@ -31,6 +40,7 @@ import type { CustomGetProps, CustomPostProps, CustomPutProps, + DeleteSourceProps, DeletedAtResponse, Distinct, Edit, @@ -40,14 +50,16 @@ import type { Exhaustive, FacetFilters, FacetOrdering, - Facets, FacetStats, + Facets, + GetTaskProps, HighlightResult, HighlightResultOption, IgnorePlurals, IndexSettingsAsSearchParams, - MatchedGeoLocation, + Languages, MatchLevel, + MatchedGeoLocation, Mode, NumericFilters, OptionalFilters, @@ -59,6 +71,7 @@ import type { QueryType, Range, RankingInfo, + ReRankingApplyFilter, Redirect, RedirectRuleIndexData, RedirectRuleIndexMetadata, @@ -66,7 +79,6 @@ import type { RemoveStopWords, RemoveWordsIfNoResults, RenderingContent, - ReRankingApplyFilter, SearchPagination, SearchParams, SearchParamsObject, @@ -75,6 +87,7 @@ import type { SnippetResult, SnippetResultOption, SortRemainingBy, + Source, SupportedLanguage, TagFilters, TaskStatus, @@ -85,23 +98,26 @@ import type { Widgets, } from '@algolia/client-search'; import { apiClientVersion } from '@algolia/client-search'; -import type { RecommendClient } from '@algolia/recommend'; +import { + Status, +} from '@algolia/client-abtesting'; +import { + EventType, +} from '@algolia/client-personalization'; -type Region = AbTestingRegion | AnalyticsRegion; +type Region = {{#dependencies}} {{#dependencyHasRegionalHosts}}{{^-first}}|{{/-first}}{{#lambda.titlecase}}{{{dependencyName}}}Region{{/lambda.titlecase}} {{/dependencyHasRegionalHosts}}{{/dependencies}}; +type RegionOptions = {{#dependencies}} {{#dependencyHasRegionalHosts}}{{^-first}}|{{/-first}}{{#lambda.titlecase}}{{{dependencyName}}}RegionOptions{{/lambda.titlecase}} {{/dependencyHasRegionalHosts}}{{/dependencies}}; +{{#dependencies}} +export * from '{{{dependencyPackage}}}'; +{{/dependencies}} export * from '@algolia/client-search'; -export * from '@algolia/recommend'; -export * from '@algolia/client-personalization'; -export * from '@algolia/client-analytics'; -export * from '@algolia/client-abtesting'; export { - AbTestingRegion, + Action, AdvancedSyntaxFeatures, AlternativesAsExact, - AnalyticsRegion, Anchoring, - apiClientVersion, AroundPrecision, AroundRadius, AroundRadiusAll, @@ -126,23 +142,27 @@ export { CustomGetProps, CustomPostProps, CustomPutProps, + DeleteSourceProps, DeletedAtResponse, Distinct, Edit, EditType, ErrorBase, + EventType, ExactOnSingleWordQuery, Exhaustive, FacetFilters, FacetOrdering, - Facets, FacetStats, + Facets, + GetTaskProps, HighlightResult, HighlightResultOption, IgnorePlurals, IndexSettingsAsSearchParams, - MatchedGeoLocation, + Languages, MatchLevel, + MatchedGeoLocation, Mode, NumericFilters, OptionalFilters, @@ -154,15 +174,16 @@ export { QueryType, Range, RankingInfo, + ReRankingApplyFilter, Redirect, RedirectRuleIndexData, RedirectRuleIndexMetadata, RedirectURL, Region, + RegionOptions, RemoveStopWords, RemoveWordsIfNoResults, RenderingContent, - ReRankingApplyFilter, SearchPagination, SearchParams, SearchParamsObject, @@ -171,6 +192,8 @@ export { SnippetResult, SnippetResultOption, SortRemainingBy, + Source, + Status, SupportedLanguage, TagFilters, TaskStatus, @@ -179,6 +202,13 @@ export { TypoToleranceEnum, Value, Widgets, + apiClientVersion, +{{#dependencies}} + {{#dependencyHasRegionalHosts}} + {{#lambda.titlecase}}{{{dependencyName}}}Region{{/lambda.titlecase}}, + {{#lambda.titlecase}}{{{dependencyName}}}RegionOptions{{/lambda.titlecase}}, + {{/dependencyHasRegionalHosts}} +{{/dependencies}} }; /** @@ -194,11 +224,4 @@ export type InitClientOptions = Partial<{ */ apiKey: string; options: ClientOptions; -}>; - -export type InitClientRegion = Partial<{ - /** - * Available regions of the initialized client. - */ - region: TRegion; }>; \ No newline at end of file diff --git a/templates/javascript/clients/api-single.mustache b/templates/javascript/clients/api-single.mustache index 1f03c32c70..2018f8dd74 100644 --- a/templates/javascript/clients/api-single.mustache +++ b/templates/javascript/clients/api-single.mustache @@ -18,7 +18,7 @@ export function create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}({ authMode, algoliaAgents,{{#hasRegionalHost}} region: regionOption,{{/hasRegionalHost}} ...options - }: CreateClientOptions{{#hasRegionalHost}} & {region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region }{{/hasRegionalHost}}) { + }: CreateClientOptions{{#hasRegionalHost}} & RegionOptions{{/hasRegionalHost}}) { const auth = createAuth(appIdOption, apiKeyOption, authMode); const transporter = createTransporter({ hosts: getDefaultHosts({{#hostWithAppID}}appIdOption{{/hostWithAppID}}{{#hasRegionalHost}}regionOption{{/hasRegionalHost}}), diff --git a/templates/javascript/clients/client/api/hosts.mustache b/templates/javascript/clients/client/api/hosts.mustache index 76b473a399..8f201a1b3c 100644 --- a/templates/javascript/clients/client/api/hosts.mustache +++ b/templates/javascript/clients/client/api/hosts.mustache @@ -1,6 +1,7 @@ {{#hasRegionalHost}} export const REGIONS = [{{#allowedRegions}}'{{.}}'{{^-last}},{{/-last}}{{/allowedRegions}}] as const; export type Region = (typeof REGIONS)[number]; +export type RegionOptions = {region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region }; {{/hasRegionalHost}} {{^hasRegionalHost}} diff --git a/templates/javascript/clients/client/builds/definition.mustache b/templates/javascript/clients/client/builds/definition.mustache index e7de6b43dd..31312f3ab1 100644 --- a/templates/javascript/clients/client/builds/definition.mustache +++ b/templates/javascript/clients/client/builds/definition.mustache @@ -6,7 +6,7 @@ import { createNullLogger, createMemoryCache, createFallbackableCache, createBro import { create{{#lambda.titlecase}}{{clientName}}{{/lambda.titlecase}}, apiClientVersion } from '../src/{{clientName}}'; {{#hasRegionalHost}} -import { Region, REGIONS } from '../src/{{clientName}}'; +import { Region, REGIONS, RegionOptions } from '../src/{{clientName}}'; {{/hasRegionalHost}} {{! We don't use `export *` to prevent exposing the factory, to avoid confusion for the user }} @@ -14,6 +14,7 @@ export { apiClientVersion, {{#hasRegionalHost}} Region, + RegionOptions, {{/hasRegionalHost}} {{#isIngestionClient}} isOnDemandTrigger, diff --git a/templates/javascript/clients/package.mustache b/templates/javascript/clients/package.mustache index 737bdc05c7..92416d269a 100644 --- a/templates/javascript/clients/package.mustache +++ b/templates/javascript/clients/package.mustache @@ -120,12 +120,10 @@ "lite.d.ts" ], "dependencies": { - "@algolia/client-analytics": "{{analyticsVersion}}", - "@algolia/client-abtesting": "{{abtestingVersion}}", - "@algolia/client-personalization": "{{personalizationVersion}}", - "@algolia/client-search": "{{searchVersion}}", + {{#dependencies}} + "{{{dependencyPackage}}}": "{{{dependencyVersion}}}", + {{/dependencies}} "@algolia/client-common": "{{utilsPackageVersion}}", - "@algolia/recommend": "{{recommendVersion}}", "@algolia/requester-browser-xhr": "{{utilsPackageVersion}}", "@algolia/requester-node-http": "{{utilsPackageVersion}}", "@algolia/requester-fetch": "{{utilsPackageVersion}}"