Skip to content

Commit 7587ba5

Browse files
chore: generated code for commit 7bb39283. [skip ci]
algolia/api-clients-automation@7bb3928 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 24dadf7 commit 7587ba5

File tree

16 files changed

+308
-92
lines changed

16 files changed

+308
-92
lines changed

bundlesize.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"files": [
33
{
44
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
5-
"maxSize": "8.40KB"
5+
"maxSize": "8.35KB"
66
},
77
{
88
"path": "packages/algoliasearch/dist/lite/lite.umd.js",
@@ -30,15 +30,15 @@
3030
},
3131
{
3232
"path": "packages/client-search/dist/client-search.umd.js",
33-
"maxSize": "6.65KB"
33+
"maxSize": "6.60KB"
3434
},
3535
{
3636
"path": "packages/client-sources/dist/client-sources.umd.js",
3737
"maxSize": "3.85KB"
3838
},
3939
{
4040
"path": "packages/predict/dist/predict.umd.js",
41-
"maxSize": "3.85KB"
41+
"maxSize": "3.90KB"
4242
},
4343
{
4444
"path": "packages/recommend/dist/recommend.umd.js",

packages/algoliasearch/__tests__/algoliasearch.test.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import type { EchoResponse } from '@algolia/client-common';
2+
import {
3+
DEFAULT_CONNECT_TIMEOUT_NODE,
4+
DEFAULT_READ_TIMEOUT_NODE,
5+
DEFAULT_WRITE_TIMEOUT_NODE,
6+
} from '@algolia/client-common';
27
import { echoRequester } from '@algolia/requester-node-http';
38

49
import { algoliasearch, apiClientVersion } from '../builds/node';
@@ -39,6 +44,100 @@ describe('api', () => {
3944
expect(client.search).not.toBeUndefined();
4045
});
4146

47+
describe('_ua', () => {
48+
it('provides a backward compatible `_ua` variable at the root of the client', () => {
49+
expect(client._ua).toEqual(
50+
expect.stringContaining(
51+
`Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion});`
52+
)
53+
);
54+
});
55+
56+
it('keeps `_ua` updated with the transporter algolia agent', () => {
57+
expect(client._ua).toEqual(
58+
expect.stringMatching(/.*; Node\.js \(.*\)$/g)
59+
);
60+
61+
client.addAlgoliaAgent('Jest', '0.0.1');
62+
63+
expect(client._ua).toEqual(
64+
expect.stringMatching(/.*; Jest \(0\.0\.1\)$/g)
65+
);
66+
});
67+
});
68+
69+
it('exposes the search client transporter for the algoliasearch client', () => {
70+
expect(client.transporter).not.toBeUndefined();
71+
expect(client.transporter).toEqual({
72+
algoliaAgent: {
73+
add: expect.any(Function),
74+
value: expect.stringContaining(
75+
`Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion});`
76+
),
77+
},
78+
baseHeaders: {
79+
'content-type': 'text/plain',
80+
'x-algolia-api-key': 'API_KEY',
81+
'x-algolia-application-id': 'APP_ID',
82+
},
83+
baseQueryParameters: {},
84+
hosts: expect.arrayContaining([
85+
{
86+
accept: 'read',
87+
protocol: 'https',
88+
url: 'APP_ID-dsn.algolia.net',
89+
},
90+
{
91+
accept: 'write',
92+
protocol: 'https',
93+
url: 'APP_ID.algolia.net',
94+
},
95+
{
96+
accept: 'readWrite',
97+
protocol: 'https',
98+
url: 'APP_ID-3.algolianet.com',
99+
},
100+
{
101+
accept: 'readWrite',
102+
protocol: 'https',
103+
url: 'APP_ID-1.algolianet.com',
104+
},
105+
{
106+
accept: 'readWrite',
107+
protocol: 'https',
108+
url: 'APP_ID-2.algolianet.com',
109+
},
110+
]),
111+
hostsCache: {
112+
clear: expect.any(Function),
113+
delete: expect.any(Function),
114+
get: expect.any(Function),
115+
set: expect.any(Function),
116+
},
117+
request: expect.any(Function),
118+
requester: {
119+
send: expect.any(Function),
120+
},
121+
requestsCache: {
122+
clear: expect.any(Function),
123+
delete: expect.any(Function),
124+
get: expect.any(Function),
125+
set: expect.any(Function),
126+
},
127+
responsesCache: {
128+
clear: expect.any(Function),
129+
delete: expect.any(Function),
130+
get: expect.any(Function),
131+
set: expect.any(Function),
132+
},
133+
timeouts: {
134+
connect: DEFAULT_CONNECT_TIMEOUT_NODE,
135+
read: DEFAULT_READ_TIMEOUT_NODE,
136+
write: DEFAULT_WRITE_TIMEOUT_NODE,
137+
},
138+
});
139+
});
140+
42141
describe('init clients', () => {
43142
it('provides an init method for the analytics client', () => {
44143
expect(client.initAnalytics).not.toBeUndefined();

packages/algoliasearch/builds/browser.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ export function algoliasearch(
6363
throw new Error('`apiKey` is missing.');
6464
}
6565

66-
const commonOptions: Omit<CreateClientOptions, 'apiKey' | 'appId'> = {
66+
const commonOptions: CreateClientOptions = {
67+
apiKey,
68+
appId,
6769
timeouts: {
6870
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
6971
read: DEFAULT_READ_TIMEOUT_BROWSER,
7072
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
7173
},
72-
requester: options?.requester ?? createXhrRequester(),
74+
requester: createXhrRequester(),
7375
algoliaAgents: [{ segment: 'Browser' }],
7476
authMode: 'WithinQueryParameters',
7577
responsesCache: createMemoryCache(),
@@ -99,11 +101,9 @@ export function algoliasearch(
99101
}
100102

101103
return createAnalyticsClient({
102-
...initOptions.options,
103104
...commonOptions,
104-
appId: initOptions.appId ?? appId,
105-
apiKey: initOptions.apiKey ?? apiKey,
106-
region: initOptions.region,
105+
...initOptions.options,
106+
...initOptions,
107107
});
108108
}
109109

@@ -123,11 +123,9 @@ export function algoliasearch(
123123
}
124124

125125
return createAbtestingClient({
126-
...initOptions.options,
127126
...commonOptions,
128-
appId: initOptions.appId ?? appId,
129-
apiKey: initOptions.apiKey ?? apiKey,
130-
region: initOptions.region,
127+
...initOptions.options,
128+
...initOptions,
131129
});
132130
}
133131

@@ -151,16 +149,20 @@ export function algoliasearch(
151149
}
152150

153151
return createPersonalizationClient({
154-
...initOptions.options,
155152
...commonOptions,
156-
appId: initOptions.appId ?? appId,
157-
apiKey: initOptions.apiKey ?? apiKey,
158-
region: initOptions.region,
153+
...initOptions.options,
154+
...initOptions,
159155
});
160156
}
161157

162158
return {
163-
...createSearchClient({ appId, apiKey, ...commonOptions }),
159+
...createSearchClient(commonOptions),
160+
/**
161+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
162+
*/
163+
get _ua(): string {
164+
return this.transporter.algoliaAgent.value;
165+
},
164166
initAnalytics,
165167
initPersonalization,
166168
initAbtesting,

packages/algoliasearch/builds/node.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ export function algoliasearch(
6262
throw new Error('`apiKey` is missing.');
6363
}
6464

65-
const commonOptions: Omit<CreateClientOptions, 'apiKey' | 'appId'> = {
65+
const commonOptions: CreateClientOptions = {
66+
apiKey,
67+
appId,
6668
timeouts: {
6769
connect: DEFAULT_CONNECT_TIMEOUT_NODE,
6870
read: DEFAULT_READ_TIMEOUT_NODE,
6971
write: DEFAULT_WRITE_TIMEOUT_NODE,
7072
},
71-
requester: options?.requester ?? createHttpRequester(),
73+
requester: createHttpRequester(),
7274
algoliaAgents: [{ segment: 'Node.js', version: process.versions.node }],
7375
responsesCache: createNullCache(),
7476
requestsCache: createNullCache(),
@@ -92,11 +94,9 @@ export function algoliasearch(
9294
}
9395

9496
return createAnalyticsClient({
95-
...initOptions.options,
9697
...commonOptions,
97-
appId: initOptions.appId ?? appId,
98-
apiKey: initOptions.apiKey ?? apiKey,
99-
region: initOptions.region,
98+
...initOptions.options,
99+
...initOptions,
100100
});
101101
}
102102

@@ -116,11 +116,9 @@ export function algoliasearch(
116116
}
117117

118118
return createAbtestingClient({
119-
...initOptions.options,
120119
...commonOptions,
121-
appId: initOptions.appId ?? appId,
122-
apiKey: initOptions.apiKey ?? apiKey,
123-
region: initOptions.region,
120+
...initOptions.options,
121+
...initOptions,
124122
});
125123
}
126124

@@ -144,16 +142,20 @@ export function algoliasearch(
144142
}
145143

146144
return createPersonalizationClient({
147-
...initOptions.options,
148145
...commonOptions,
149-
appId: initOptions.appId ?? appId,
150-
apiKey: initOptions.apiKey ?? apiKey,
151-
region: initOptions.region,
146+
...initOptions.options,
147+
...initOptions,
152148
});
153149
}
154150

155151
return {
156-
...createSearchClient({ appId, apiKey, ...commonOptions }),
152+
...createSearchClient(commonOptions),
153+
/**
154+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
155+
*/
156+
get _ua(): string {
157+
return this.transporter.algoliaAgent.value;
158+
},
157159
initAnalytics,
158160
initPersonalization,
159161
initAbtesting,

packages/algoliasearch/lite/src/liteClient.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,23 @@ export function createLiteClient({
8585
},
8686
});
8787

88-
function addAlgoliaAgent(segment: string, version?: string): void {
89-
transporter.algoliaAgent.add({ segment, version });
90-
}
91-
9288
return {
93-
addAlgoliaAgent,
89+
transporter,
90+
/**
91+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
92+
*/
93+
get _ua(): string {
94+
return transporter.algoliaAgent.value;
95+
},
96+
/**
97+
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
98+
*
99+
* @param segment - The algolia agent (user-agent) segment to add.
100+
* @param version - The version of the agent.
101+
*/
102+
addAlgoliaAgent(segment: string, version?: string): void {
103+
transporter.algoliaAgent.add({ segment, version });
104+
},
94105
/**
95106
* This method allow you to send requests to the Algolia REST API.
96107
*

packages/client-abtesting/src/abtestingClient.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,23 @@ export function createAbtestingClient({
6969
},
7070
});
7171

72-
function addAlgoliaAgent(segment: string, version?: string): void {
73-
transporter.algoliaAgent.add({ segment, version });
74-
}
75-
7672
return {
77-
addAlgoliaAgent,
73+
transporter,
74+
/**
75+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
76+
*/
77+
get _ua(): string {
78+
return transporter.algoliaAgent.value;
79+
},
80+
/**
81+
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
82+
*
83+
* @param segment - The algolia agent (user-agent) segment to add.
84+
* @param version - The version of the agent.
85+
*/
86+
addAlgoliaAgent(segment: string, version?: string): void {
87+
transporter.algoliaAgent.add({ segment, version });
88+
},
7889
/**
7990
* Creates a new A/B test with provided configuration. You can set an A/B test on two different indices with different settings, or on the same index with different search parameters by providing a customSearchParameters setting on one of the variants.
8091
*

packages/client-analytics/src/analyticsClient.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,23 @@ export function createAnalyticsClient({
9595
},
9696
});
9797

98-
function addAlgoliaAgent(segment: string, version?: string): void {
99-
transporter.algoliaAgent.add({ segment, version });
100-
}
101-
10298
return {
103-
addAlgoliaAgent,
99+
transporter,
100+
/**
101+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
102+
*/
103+
get _ua(): string {
104+
return transporter.algoliaAgent.value;
105+
},
106+
/**
107+
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
108+
*
109+
* @param segment - The algolia agent (user-agent) segment to add.
110+
* @param version - The version of the agent.
111+
*/
112+
addAlgoliaAgent(segment: string, version?: string): void {
113+
transporter.algoliaAgent.add({ segment, version });
114+
},
104115
/**
105116
* This method allow you to send requests to the Algolia REST API.
106117
*

0 commit comments

Comments
 (0)