Skip to content

Commit 0a433cc

Browse files
authoredSep 9, 2024··
fix(javascript): use transporter directly (#3682)
1 parent 265d392 commit 0a433cc

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed
 

‎templates/javascript/clients/algoliasearch/builds/definition.mustache

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt
3636
throw new Error('`apiKey` is missing.');
3737
}
3838

39+
const client = searchClient(appId, apiKey, options);
40+
3941
return {
40-
...searchClient(appId, apiKey, options),
42+
...client,
4143
/**
4244
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
4345
*/
4446
get _ua(): string {
45-
return this.transporter.algoliaAgent.value;
47+
return client.transporter.algoliaAgent.value;
4648
},
4749
initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => {
4850
return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);

‎templates/javascript/clients/api-single.mustache

+26-25
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,27 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
2121
...options
2222
}: CreateClientOptions{{#hasRegionalHost}} & {region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: Region }{{/hasRegionalHost}}) {
2323
const auth = createAuth(appIdOption, apiKeyOption, authMode);
24+
const transporter = createTransporter({
25+
hosts: getDefaultHosts({{#hostWithAppID}}appIdOption{{/hostWithAppID}}{{#hasRegionalHost}}regionOption{{/hasRegionalHost}}),
26+
...options,
27+
algoliaAgent: getAlgoliaAgent({
28+
algoliaAgents,
29+
client: '{{{algoliaAgent}}}',
30+
version: apiClientVersion,
31+
}),
32+
baseHeaders: {
33+
'content-type': 'text/plain',
34+
...auth.headers(),
35+
...options.baseHeaders,
36+
},
37+
baseQueryParameters: {
38+
...auth.queryParameters(),
39+
...options.baseQueryParameters,
40+
},
41+
});
2442

2543
return {
26-
transporter: createTransporter({
27-
hosts: getDefaultHosts({{#hostWithAppID}}appIdOption{{/hostWithAppID}}{{#hasRegionalHost}}regionOption{{/hasRegionalHost}}),
28-
...options,
29-
algoliaAgent: getAlgoliaAgent({
30-
algoliaAgents,
31-
client: '{{{algoliaAgent}}}',
32-
version: apiClientVersion,
33-
}),
34-
baseHeaders: {
35-
'content-type': 'text/plain',
36-
...auth.headers(),
37-
...options.baseHeaders,
38-
},
39-
baseQueryParameters: {
40-
...auth.queryParameters(),
41-
...options.baseQueryParameters,
42-
},
43-
}),
44+
transporter,
4445
4546
/**
4647
* The `appId` currently in use.
@@ -52,16 +53,16 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
5253
*/
5354
clearCache(): Promise<void> {
5455
return Promise.all([
55-
this.transporter.requestsCache.clear(),
56-
this.transporter.responsesCache.clear(),
56+
transporter.requestsCache.clear(),
57+
transporter.responsesCache.clear(),
5758
]).then(() => undefined);
5859
},
5960

6061
/**
6162
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
6263
*/
6364
get _ua(): string {
64-
return this.transporter.algoliaAgent.value;
65+
return transporter.algoliaAgent.value;
6566
},
6667

6768
/**
@@ -71,7 +72,7 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
7172
* @param version - The version of the agent.
7273
*/
7374
addAlgoliaAgent(segment: string, version?: string): void {
74-
this.transporter.algoliaAgent.add({ segment, version });
75+
transporter.algoliaAgent.add({ segment, version });
7576
},
7677

7778
/**
@@ -82,9 +83,9 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
8283
*/
8384
setClientApiKey({ apiKey }: { apiKey: string }): void {
8485
if (!authMode || authMode === 'WithinHeaders') {
85-
this.transporter.baseHeaders['x-algolia-api-key'] = apiKey;
86+
transporter.baseHeaders['x-algolia-api-key'] = apiKey;
8687
} else {
87-
this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;
88+
transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;
8889
}
8990
},
9091

@@ -156,7 +157,7 @@ export function create{{#lambda.titlecase}}{{apiName}}{{/lambda.titlecase}}({
156157
{{/vendorExtensions}}
157158
};
158159

159-
return this.transporter.request(request, requestOptions);
160+
return transporter.request(request, requestOptions);
160161
},
161162

162163
{{/operation}}

0 commit comments

Comments
 (0)
Please sign in to comment.