Skip to content

Commit

Permalink
fix(javascript): use transporter directly (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3682

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Sep 9, 2024
1 parent 0efc936 commit 95b871f
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 520 deletions.
6 changes: 4 additions & 2 deletions packages/algoliasearch/builds/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt
throw new Error('`apiKey` is missing.');
}

const client = searchClient(appId, apiKey, options);

return {
...searchClient(appId, apiKey, options),
...client,
/**
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
*/
get _ua(): string {
return this.transporter.algoliaAgent.value;
return client.transporter.algoliaAgent.value;
},
initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => {
return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
Expand Down
6 changes: 4 additions & 2 deletions packages/algoliasearch/builds/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt
throw new Error('`apiKey` is missing.');
}

const client = searchClient(appId, apiKey, options);

return {
...searchClient(appId, apiKey, options),
...client,
/**
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
*/
get _ua(): string {
return this.transporter.algoliaAgent.value;
return client.transporter.algoliaAgent.value;
},
initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => {
return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
Expand Down
55 changes: 27 additions & 28 deletions packages/algoliasearch/lite/src/liteClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,27 @@ export function createLiteClient({
...options
}: CreateClientOptions) {
const auth = createAuth(appIdOption, apiKeyOption, authMode);
const transporter = createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: 'Lite',
version: apiClientVersion,
}),
baseHeaders: {
'content-type': 'text/plain',
...auth.headers(),
...options.baseHeaders,
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters,
},
});

return {
transporter: createTransporter({
hosts: getDefaultHosts(appIdOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: 'Lite',
version: apiClientVersion,
}),
baseHeaders: {
'content-type': 'text/plain',
...auth.headers(),
...options.baseHeaders,
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters,
},
}),
transporter,

/**
* The `appId` currently in use.
Expand All @@ -98,16 +99,14 @@ export function createLiteClient({
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
*/
clearCache(): Promise<void> {
return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
() => undefined,
);
return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined);
},

/**
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
*/
get _ua(): string {
return this.transporter.algoliaAgent.value;
return transporter.algoliaAgent.value;
},

/**
Expand All @@ -117,7 +116,7 @@ export function createLiteClient({
* @param version - The version of the agent.
*/
addAlgoliaAgent(segment: string, version?: string): void {
this.transporter.algoliaAgent.add({ segment, version });
transporter.algoliaAgent.add({ segment, version });
},

/**
Expand All @@ -128,9 +127,9 @@ export function createLiteClient({
*/
setClientApiKey({ apiKey }: { apiKey: string }): void {
if (!authMode || authMode === 'WithinHeaders') {
this.transporter.baseHeaders['x-algolia-api-key'] = apiKey;
transporter.baseHeaders['x-algolia-api-key'] = apiKey;
} else {
this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;
transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;
}
},
/**
Expand Down Expand Up @@ -193,7 +192,7 @@ export function createLiteClient({
data: body ? body : {},
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -240,7 +239,7 @@ export function createLiteClient({
cacheable: true,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -303,7 +302,7 @@ export function createLiteClient({
cacheable: true,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},
};
}
72 changes: 36 additions & 36 deletions packages/client-abtesting/src/abtestingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,27 @@ export function createAbtestingClient({
...options
}: CreateClientOptions & { region?: Region }) {
const auth = createAuth(appIdOption, apiKeyOption, authMode);
const transporter = createTransporter({
hosts: getDefaultHosts(regionOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: 'Abtesting',
version: apiClientVersion,
}),
baseHeaders: {
'content-type': 'text/plain',
...auth.headers(),
...options.baseHeaders,
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters,
},
});

return {
transporter: createTransporter({
hosts: getDefaultHosts(regionOption),
...options,
algoliaAgent: getAlgoliaAgent({
algoliaAgents,
client: 'Abtesting',
version: apiClientVersion,
}),
baseHeaders: {
'content-type': 'text/plain',
...auth.headers(),
...options.baseHeaders,
},
baseQueryParameters: {
...auth.queryParameters(),
...options.baseQueryParameters,
},
}),
transporter,

/**
* The `appId` currently in use.
Expand All @@ -78,16 +79,14 @@ export function createAbtestingClient({
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
*/
clearCache(): Promise<void> {
return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
() => undefined,
);
return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined);
},

/**
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
*/
get _ua(): string {
return this.transporter.algoliaAgent.value;
return transporter.algoliaAgent.value;
},

/**
Expand All @@ -97,7 +96,7 @@ export function createAbtestingClient({
* @param version - The version of the agent.
*/
addAlgoliaAgent(segment: string, version?: string): void {
this.transporter.algoliaAgent.add({ segment, version });
transporter.algoliaAgent.add({ segment, version });
},

/**
Expand All @@ -108,9 +107,9 @@ export function createAbtestingClient({
*/
setClientApiKey({ apiKey }: { apiKey: string }): void {
if (!authMode || authMode === 'WithinHeaders') {
this.transporter.baseHeaders['x-algolia-api-key'] = apiKey;
transporter.baseHeaders['x-algolia-api-key'] = apiKey;
} else {
this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;
transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;
}
},

Expand Down Expand Up @@ -150,7 +149,7 @@ export function createAbtestingClient({
data: addABTestsRequest,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -180,7 +179,7 @@ export function createAbtestingClient({
headers,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand All @@ -207,7 +206,7 @@ export function createAbtestingClient({
headers,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -239,7 +238,7 @@ export function createAbtestingClient({
data: body ? body : {},
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -271,7 +270,7 @@ export function createAbtestingClient({
data: body ? body : {},
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -300,7 +299,7 @@ export function createAbtestingClient({
headers,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -329,7 +328,7 @@ export function createAbtestingClient({
headers,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand All @@ -352,13 +351,14 @@ export function createAbtestingClient({
const requestPath = '/2/abtests';
const headers: Headers = {};
const queryParameters: QueryParameters = {};

if (offset !== undefined) {
queryParameters.offset = offset.toString();
}

if (limit !== undefined) {
queryParameters.limit = limit.toString();
}

if (indexPrefix !== undefined) {
queryParameters.indexPrefix = indexPrefix.toString();
}
Expand All @@ -373,7 +373,7 @@ export function createAbtestingClient({
headers,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -418,7 +418,7 @@ export function createAbtestingClient({
data: scheduleABTestsRequest,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},

/**
Expand Down Expand Up @@ -447,7 +447,7 @@ export function createAbtestingClient({
headers,
};

return this.transporter.request(request, requestOptions);
return transporter.request(request, requestOptions);
},
};
}
Loading

0 comments on commit 95b871f

Please sign in to comment.