Skip to content

Commit fd3e226

Browse files
authored
fix(javascript): expose clearCache and appId at the root of the client (#892)
1 parent 245ce69 commit fd3e226

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clients/algoliasearch-client-javascript/packages/algoliasearch/__tests__/algoliasearch.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ const client = algoliasearch('APP_ID', 'API_KEY', {
1414
});
1515

1616
describe('api', () => {
17+
it('exposes the `appId` currently in use at the root of the API', () => {
18+
expect(client.appId).toEqual('APP_ID');
19+
});
20+
21+
it('provides a `clearCache` method', () => {
22+
expect(client.clearCache).not.toBeUndefined();
23+
});
24+
1725
it('sets the user agent', async () => {
1826
const req = (await client.post({
1927
path: '/test',

templates/javascript/clients/api-single.mustache

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ export function create{{capitalizedApiName}}({
3838
return {
3939
transporter,
4040
41+
/**
42+
* The `appId` currently in use.
43+
*/
44+
appId: appIdOption,
45+
46+
/**
47+
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
48+
*/
49+
clearCache(): Promise<void> {
50+
return Promise.all([
51+
transporter.requestsCache.clear(),
52+
transporter.responsesCache.clear(),
53+
]).then(() => undefined);
54+
},
55+
4156
/**
4257
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
4358
*/

0 commit comments

Comments
 (0)