@algolia/client-common 5.0.0-alpha.99 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client-common.cjs +36 -32
- package/dist/client-common.esm.node.js +36 -32
- package/dist/src/createEchoRequester.d.ts.map +1 -1
- package/dist/src/transporter/createTransporter.d.ts.map +1 -1
- package/dist/src/transporter/helpers.d.ts.map +1 -1
- package/dist/src/types/host.d.ts +4 -0
- package/dist/src/types/host.d.ts.map +1 -1
- package/dist/src/types/transporter.d.ts +1 -1
- package/dist/src/types/transporter.d.ts.map +1 -1
- package/package.json +11 -8
- package/src/__tests__/create-iterable-promise.test.ts +2 -2
- package/src/createEchoRequester.ts +23 -8
- package/src/transporter/createTransporter.ts +2 -5
- package/src/transporter/errors.ts +1 -1
- package/src/transporter/helpers.ts +7 -9
- package/src/types/host.ts +5 -0
- package/src/types/transporter.ts +1 -1
package/dist/client-common.cjs
CHANGED
|
@@ -17,16 +17,30 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
|
|
|
17
17
|
|
|
18
18
|
function getUrlParams({
|
|
19
19
|
host,
|
|
20
|
-
|
|
20
|
+
search,
|
|
21
21
|
pathname
|
|
22
22
|
}) {
|
|
23
|
-
const
|
|
23
|
+
const urlSearchParams = search.split('?');
|
|
24
|
+
if (urlSearchParams.length === 1) {
|
|
25
|
+
return {
|
|
26
|
+
host,
|
|
27
|
+
algoliaAgent: '',
|
|
28
|
+
searchParams: undefined,
|
|
29
|
+
path: pathname
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const splitSearchParams = urlSearchParams[1].split('&');
|
|
33
|
+
let algoliaAgent = '';
|
|
24
34
|
const searchParams = {};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
if (splitSearchParams.length > 0) {
|
|
36
|
+
splitSearchParams.forEach(param => {
|
|
37
|
+
const [key, value] = param.split('=');
|
|
38
|
+
if (key === 'x-algolia-agent') {
|
|
39
|
+
algoliaAgent = value;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
searchParams[key] = value;
|
|
43
|
+
});
|
|
30
44
|
}
|
|
31
45
|
return {
|
|
32
46
|
host,
|
|
@@ -51,7 +65,7 @@ function createEchoRequester({
|
|
|
51
65
|
data: request.data ? JSON.parse(request.data) : undefined,
|
|
52
66
|
path,
|
|
53
67
|
host,
|
|
54
|
-
algoliaAgent
|
|
68
|
+
algoliaAgent,
|
|
55
69
|
searchParams
|
|
56
70
|
};
|
|
57
71
|
return Promise.resolve({
|
|
@@ -287,6 +301,14 @@ function createStatefulHost(host, status = 'up') {
|
|
|
287
301
|
};
|
|
288
302
|
}
|
|
289
303
|
|
|
304
|
+
function _defineProperty(e, r, t) {
|
|
305
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
306
|
+
value: t,
|
|
307
|
+
enumerable: !0,
|
|
308
|
+
configurable: !0,
|
|
309
|
+
writable: !0
|
|
310
|
+
}) : e[r] = t, e;
|
|
311
|
+
}
|
|
290
312
|
function _toPrimitive(t, r) {
|
|
291
313
|
if ("object" != typeof t || !t) return t;
|
|
292
314
|
var e = t[Symbol.toPrimitive];
|
|
@@ -299,21 +321,7 @@ function _toPrimitive(t, r) {
|
|
|
299
321
|
}
|
|
300
322
|
function _toPropertyKey(t) {
|
|
301
323
|
var i = _toPrimitive(t, "string");
|
|
302
|
-
return "symbol" == typeof i ? i :
|
|
303
|
-
}
|
|
304
|
-
function _defineProperty(obj, key, value) {
|
|
305
|
-
key = _toPropertyKey(key);
|
|
306
|
-
if (key in obj) {
|
|
307
|
-
Object.defineProperty(obj, key, {
|
|
308
|
-
value: value,
|
|
309
|
-
enumerable: true,
|
|
310
|
-
configurable: true,
|
|
311
|
-
writable: true
|
|
312
|
-
});
|
|
313
|
-
} else {
|
|
314
|
-
obj[key] = value;
|
|
315
|
-
}
|
|
316
|
-
return obj;
|
|
324
|
+
return "symbol" == typeof i ? i : i + "";
|
|
317
325
|
}
|
|
318
326
|
|
|
319
327
|
class AlgoliaError extends Error {
|
|
@@ -335,7 +343,7 @@ class ErrorWithStackTrace extends AlgoliaError {
|
|
|
335
343
|
}
|
|
336
344
|
class RetryError extends ErrorWithStackTrace {
|
|
337
345
|
constructor(stackTrace) {
|
|
338
|
-
super('Unreachable hosts - your application id may be incorrect. If the error persists, please
|
|
346
|
+
super('Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.', stackTrace, 'RetryError');
|
|
339
347
|
}
|
|
340
348
|
}
|
|
341
349
|
class ApiError extends ErrorWithStackTrace {
|
|
@@ -373,15 +381,14 @@ function shuffle(array) {
|
|
|
373
381
|
}
|
|
374
382
|
function serializeUrl(host, path, queryParameters) {
|
|
375
383
|
const queryParametersAsString = serializeQueryParameters(queryParameters);
|
|
376
|
-
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.
|
|
384
|
+
let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${path.charAt(0) === '/' ? path.substring(1) : path}`;
|
|
377
385
|
if (queryParametersAsString.length) {
|
|
378
386
|
url += `?${queryParametersAsString}`;
|
|
379
387
|
}
|
|
380
388
|
return url;
|
|
381
389
|
}
|
|
382
390
|
function serializeQueryParameters(parameters) {
|
|
383
|
-
|
|
384
|
-
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key])}`).join('&');
|
|
391
|
+
return Object.keys(parameters).filter(key => parameters[key] !== undefined).sort().map(key => `${key}=${encodeURIComponent(Object.prototype.toString.call(parameters[key]) === '[object Array]' ? parameters[key].join(',') : parameters[key]).replaceAll('+', '%20')}`).join('&');
|
|
385
392
|
}
|
|
386
393
|
function serializeData(request, requestOptions) {
|
|
387
394
|
if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
|
|
@@ -552,16 +559,13 @@ function createTransporter({
|
|
|
552
559
|
if (host === undefined) {
|
|
553
560
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
554
561
|
}
|
|
555
|
-
let responseTimeout = requestOptions.
|
|
556
|
-
if (responseTimeout === undefined) {
|
|
557
|
-
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
558
|
-
}
|
|
562
|
+
let responseTimeout = isRead ? requestOptions.timeouts?.read || timeouts.read : requestOptions.timeouts?.write || timeouts.write;
|
|
559
563
|
const payload = {
|
|
560
564
|
data,
|
|
561
565
|
headers,
|
|
562
566
|
method: request.method,
|
|
563
567
|
url: serializeUrl(host, request.path, queryParameters),
|
|
564
|
-
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
|
|
568
|
+
connectTimeout: getTimeout(timeoutsCount, requestOptions.timeouts?.connect || timeouts.connect),
|
|
565
569
|
responseTimeout: getTimeout(timeoutsCount, responseTimeout)
|
|
566
570
|
};
|
|
567
571
|
/**
|
|
@@ -15,16 +15,30 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
|
|
|
15
15
|
|
|
16
16
|
function getUrlParams({
|
|
17
17
|
host,
|
|
18
|
-
|
|
18
|
+
search,
|
|
19
19
|
pathname
|
|
20
20
|
}) {
|
|
21
|
-
const
|
|
21
|
+
const urlSearchParams = search.split('?');
|
|
22
|
+
if (urlSearchParams.length === 1) {
|
|
23
|
+
return {
|
|
24
|
+
host,
|
|
25
|
+
algoliaAgent: '',
|
|
26
|
+
searchParams: undefined,
|
|
27
|
+
path: pathname
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const splitSearchParams = urlSearchParams[1].split('&');
|
|
31
|
+
let algoliaAgent = '';
|
|
22
32
|
const searchParams = {};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
if (splitSearchParams.length > 0) {
|
|
34
|
+
splitSearchParams.forEach(param => {
|
|
35
|
+
const [key, value] = param.split('=');
|
|
36
|
+
if (key === 'x-algolia-agent') {
|
|
37
|
+
algoliaAgent = value;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
searchParams[key] = value;
|
|
41
|
+
});
|
|
28
42
|
}
|
|
29
43
|
return {
|
|
30
44
|
host,
|
|
@@ -49,7 +63,7 @@ function createEchoRequester({
|
|
|
49
63
|
data: request.data ? JSON.parse(request.data) : undefined,
|
|
50
64
|
path,
|
|
51
65
|
host,
|
|
52
|
-
algoliaAgent
|
|
66
|
+
algoliaAgent,
|
|
53
67
|
searchParams
|
|
54
68
|
};
|
|
55
69
|
return Promise.resolve({
|
|
@@ -285,6 +299,14 @@ function createStatefulHost(host, status = 'up') {
|
|
|
285
299
|
};
|
|
286
300
|
}
|
|
287
301
|
|
|
302
|
+
function _defineProperty(e, r, t) {
|
|
303
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
304
|
+
value: t,
|
|
305
|
+
enumerable: !0,
|
|
306
|
+
configurable: !0,
|
|
307
|
+
writable: !0
|
|
308
|
+
}) : e[r] = t, e;
|
|
309
|
+
}
|
|
288
310
|
function _toPrimitive(t, r) {
|
|
289
311
|
if ("object" != typeof t || !t) return t;
|
|
290
312
|
var e = t[Symbol.toPrimitive];
|
|
@@ -297,21 +319,7 @@ function _toPrimitive(t, r) {
|
|
|
297
319
|
}
|
|
298
320
|
function _toPropertyKey(t) {
|
|
299
321
|
var i = _toPrimitive(t, "string");
|
|
300
|
-
return "symbol" == typeof i ? i :
|
|
301
|
-
}
|
|
302
|
-
function _defineProperty(obj, key, value) {
|
|
303
|
-
key = _toPropertyKey(key);
|
|
304
|
-
if (key in obj) {
|
|
305
|
-
Object.defineProperty(obj, key, {
|
|
306
|
-
value: value,
|
|
307
|
-
enumerable: true,
|
|
308
|
-
configurable: true,
|
|
309
|
-
writable: true
|
|
310
|
-
});
|
|
311
|
-
} else {
|
|
312
|
-
obj[key] = value;
|
|
313
|
-
}
|
|
314
|
-
return obj;
|
|
322
|
+
return "symbol" == typeof i ? i : i + "";
|
|
315
323
|
}
|
|
316
324
|
|
|
317
325
|
class AlgoliaError extends Error {
|
|
@@ -333,7 +341,7 @@ class ErrorWithStackTrace extends AlgoliaError {
|
|
|
333
341
|
}
|
|
334
342
|
class RetryError extends ErrorWithStackTrace {
|
|
335
343
|
constructor(stackTrace) {
|
|
336
|
-
super('Unreachable hosts - your application id may be incorrect. If the error persists, please
|
|
344
|
+
super('Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.', stackTrace, 'RetryError');
|
|
337
345
|
}
|
|
338
346
|
}
|
|
339
347
|
class ApiError extends ErrorWithStackTrace {
|
|
@@ -371,15 +379,14 @@ function shuffle(array) {
|
|
|
371
379
|
}
|
|
372
380
|
function serializeUrl(host, path, queryParameters) {
|
|
373
381
|
const queryParametersAsString = serializeQueryParameters(queryParameters);
|
|
374
|
-
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.
|
|
382
|
+
let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${path.charAt(0) === '/' ? path.substring(1) : path}`;
|
|
375
383
|
if (queryParametersAsString.length) {
|
|
376
384
|
url += `?${queryParametersAsString}`;
|
|
377
385
|
}
|
|
378
386
|
return url;
|
|
379
387
|
}
|
|
380
388
|
function serializeQueryParameters(parameters) {
|
|
381
|
-
|
|
382
|
-
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key])}`).join('&');
|
|
389
|
+
return Object.keys(parameters).filter(key => parameters[key] !== undefined).sort().map(key => `${key}=${encodeURIComponent(Object.prototype.toString.call(parameters[key]) === '[object Array]' ? parameters[key].join(',') : parameters[key]).replaceAll('+', '%20')}`).join('&');
|
|
383
390
|
}
|
|
384
391
|
function serializeData(request, requestOptions) {
|
|
385
392
|
if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
|
|
@@ -550,16 +557,13 @@ function createTransporter({
|
|
|
550
557
|
if (host === undefined) {
|
|
551
558
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
552
559
|
}
|
|
553
|
-
let responseTimeout = requestOptions.
|
|
554
|
-
if (responseTimeout === undefined) {
|
|
555
|
-
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
556
|
-
}
|
|
560
|
+
let responseTimeout = isRead ? requestOptions.timeouts?.read || timeouts.read : requestOptions.timeouts?.write || timeouts.write;
|
|
557
561
|
const payload = {
|
|
558
562
|
data,
|
|
559
563
|
headers,
|
|
560
564
|
method: request.method,
|
|
561
565
|
url: serializeUrl(host, request.path, queryParameters),
|
|
562
|
-
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
|
|
566
|
+
connectTimeout: getTimeout(timeoutsCount, requestOptions.timeouts?.connect || timeouts.connect),
|
|
563
567
|
responseTimeout: getTimeout(timeoutsCount, responseTimeout)
|
|
564
568
|
};
|
|
565
569
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEchoRequester.d.ts","sourceRoot":"","sources":["../../src/createEchoRequester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,SAAS,EAAY,MAAM,SAAS,CAAC;AAE7E,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;
|
|
1
|
+
{"version":3,"file":"createEchoRequester.d.ts","sourceRoot":"","sources":["../../src/createEchoRequester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA4B,SAAS,EAAY,MAAM,SAAS,CAAC;AAE7E,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AA0CF,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,MAAY,GACb,EAAE,mBAAmB,GAAG,SAAS,CAuBjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTransporter.d.ts","sourceRoot":"","sources":["../../../src/transporter/createTransporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAOV,kBAAkB,EAClB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAsBlB,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,aAAa,EACb,cAAc,GACf,EAAE,kBAAkB,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"createTransporter.d.ts","sourceRoot":"","sources":["../../../src/transporter/createTransporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAOV,kBAAkB,EAClB,WAAW,EAEZ,MAAM,UAAU,CAAC;AAsBlB,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,aAAa,EACb,cAAc,GACf,EAAE,kBAAkB,GAAG,WAAW,CAgTlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/transporter/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EACJ,eAAe,EACf,OAAO,EACP,cAAc,EACd,QAAQ,EACR,UAAU,EACX,MAAM,UAAU,CAAC;AAIlB,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAYtD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,eAAe,GAC/B,MAAM,CAWR;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,eAAe,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/transporter/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EACJ,eAAe,EACf,OAAO,EACP,cAAc,EACd,QAAQ,EACR,UAAU,EACX,MAAM,UAAU,CAAC;AAIlB,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAYtD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,eAAe,GAC/B,MAAM,CAWR;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,eAAe,GAAG,MAAM,CAa5E;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,GAC7B,MAAM,GAAG,SAAS,CAapB;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,cAAc,EAAE,OAAO,EACvB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAeT;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAMvE;AAED,wBAAgB,kBAAkB,CAChC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAC7B,UAAU,EAAE,UAAU,EAAE,GACvB,KAAK,CAgBP"}
|
package/dist/src/types/host.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../../src/types/host.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG;IACjB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;IAEvC;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../../src/types/host.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG;IACjB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;IAEvC;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,IAAI,EAAE,MAAM,OAAO,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC;CAC3B,CAAC"}
|
|
@@ -9,7 +9,7 @@ export type RequestOptions = Pick<Request, 'cacheable'> & {
|
|
|
9
9
|
* the given timeout will be applied. But the transporter layer may
|
|
10
10
|
* increase this timeout if there is need for it.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
timeouts?: Partial<Timeouts>;
|
|
13
13
|
/**
|
|
14
14
|
* Custom headers for the request. This headers are
|
|
15
15
|
* going to be merged the transporter headers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transporter.d.ts","sourceRoot":"","sources":["../../../src/types/transporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG;IACxD;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"transporter.d.ts","sourceRoot":"","sources":["../../../src/types/transporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,GAAG;IACxD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE7B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;;OAGG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,GAAG,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,YAAY,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,UAAU,EAAE,KAAK,CAAC;IAElB;;;;OAIG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;OAKG;IACH,aAAa,EAAE,KAAK,CAAC;IAErB;;;;OAIG;IACH,cAAc,EAAE,KAAK,CAAC;IAEtB;;;;OAIG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,IAAI,EAAE,CAAC;IAEd;;;;OAIG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;;;OAIG;IACH,mBAAmB,EAAE,eAAe,CAAC;IAErC;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,kBAAkB,GAAG;IAC7C;;;OAGG;IACH,OAAO,EAAE,CAAC,SAAS,EACjB,WAAW,EAAE,OAAO,EACpB,kBAAkB,CAAC,EAAE,cAAc,KAChC,OAAO,CAAC,SAAS,CAAC,CAAC;CACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/client-common",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-beta.10",
|
|
4
4
|
"description": "Common package for the Algolia JavaScript API client.",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/algolia/algoliasearch-client-javascript.git"
|
|
8
|
+
},
|
|
6
9
|
"license": "MIT",
|
|
7
10
|
"author": "Algolia",
|
|
8
11
|
"type": "module",
|
|
@@ -20,14 +23,14 @@
|
|
|
20
23
|
"test": "jest"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
23
|
-
"@babel/preset-env": "7.
|
|
24
|
-
"@babel/preset-typescript": "7.
|
|
25
|
-
"@types/jest": "29.5.
|
|
26
|
-
"@types/node": "20.
|
|
26
|
+
"@babel/preset-env": "7.24.7",
|
|
27
|
+
"@babel/preset-typescript": "7.24.7",
|
|
28
|
+
"@types/jest": "29.5.12",
|
|
29
|
+
"@types/node": "20.14.10",
|
|
27
30
|
"jest": "29.7.0",
|
|
28
31
|
"jest-environment-jsdom": "29.7.0",
|
|
29
|
-
"ts-jest": "29.1.
|
|
30
|
-
"typescript": "5.
|
|
32
|
+
"ts-jest": "29.1.5",
|
|
33
|
+
"typescript": "5.5.3"
|
|
31
34
|
},
|
|
32
35
|
"engines": {
|
|
33
36
|
"node": ">= 14.0.0"
|
|
@@ -112,7 +112,7 @@ describe('createIterablePromise', () => {
|
|
|
112
112
|
await expect(promise).resolves.toEqual('success #2');
|
|
113
113
|
|
|
114
114
|
expect(Date.now() - before).toBeGreaterThanOrEqual(0);
|
|
115
|
-
expect(Date.now() - before).toBeLessThanOrEqual(
|
|
115
|
+
expect(Date.now() - before).toBeLessThanOrEqual(20);
|
|
116
116
|
expect(calls).toBe(2);
|
|
117
117
|
});
|
|
118
118
|
|
|
@@ -133,7 +133,7 @@ describe('createIterablePromise', () => {
|
|
|
133
133
|
await expect(promise).resolves.toEqual('success #2');
|
|
134
134
|
|
|
135
135
|
expect(Date.now() - before).toBeGreaterThanOrEqual(2000);
|
|
136
|
-
expect(Date.now() - before).toBeLessThanOrEqual(
|
|
136
|
+
expect(Date.now() - before).toBeLessThanOrEqual(2020);
|
|
137
137
|
expect(calls).toBe(2);
|
|
138
138
|
});
|
|
139
139
|
});
|
|
@@ -7,18 +7,33 @@ export type EchoRequesterParams = {
|
|
|
7
7
|
|
|
8
8
|
function getUrlParams({
|
|
9
9
|
host,
|
|
10
|
-
|
|
10
|
+
search,
|
|
11
11
|
pathname,
|
|
12
12
|
}: URL): Pick<EchoResponse, 'algoliaAgent' | 'host' | 'path' | 'searchParams'> {
|
|
13
|
-
const
|
|
13
|
+
const urlSearchParams = search.split('?');
|
|
14
|
+
if (urlSearchParams.length === 1) {
|
|
15
|
+
return {
|
|
16
|
+
host,
|
|
17
|
+
algoliaAgent: '',
|
|
18
|
+
searchParams: undefined,
|
|
19
|
+
path: pathname,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const splitSearchParams = urlSearchParams[1].split('&');
|
|
24
|
+
let algoliaAgent = '';
|
|
14
25
|
const searchParams: Record<string, string> = {};
|
|
15
26
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
if (splitSearchParams.length > 0) {
|
|
28
|
+
splitSearchParams.forEach((param) => {
|
|
29
|
+
const [key, value] = param.split('=');
|
|
30
|
+
if (key === 'x-algolia-agent') {
|
|
31
|
+
algoliaAgent = value;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
searchParams[key] = value;
|
|
36
|
+
});
|
|
22
37
|
}
|
|
23
38
|
|
|
24
39
|
return {
|
|
@@ -44,7 +59,7 @@ export function createEchoRequester({
|
|
|
44
59
|
data: request.data ? JSON.parse(request.data) : undefined,
|
|
45
60
|
path,
|
|
46
61
|
host,
|
|
47
|
-
algoliaAgent
|
|
62
|
+
algoliaAgent,
|
|
48
63
|
searchParams,
|
|
49
64
|
};
|
|
50
65
|
|
|
@@ -151,17 +151,14 @@ export function createTransporter({
|
|
|
151
151
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
let responseTimeout = requestOptions.
|
|
155
|
-
if (responseTimeout === undefined) {
|
|
156
|
-
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
157
|
-
}
|
|
154
|
+
let responseTimeout = isRead ? requestOptions.timeouts?.read || timeouts.read : requestOptions.timeouts?.write || timeouts.write;
|
|
158
155
|
|
|
159
156
|
const payload: EndRequest = {
|
|
160
157
|
data,
|
|
161
158
|
headers,
|
|
162
159
|
method: request.method,
|
|
163
160
|
url: serializeUrl(host, request.path, queryParameters),
|
|
164
|
-
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
|
|
161
|
+
connectTimeout: getTimeout(timeoutsCount, requestOptions.timeouts?.connect || timeouts.connect),
|
|
165
162
|
responseTimeout: getTimeout(timeoutsCount, responseTimeout),
|
|
166
163
|
};
|
|
167
164
|
|
|
@@ -25,7 +25,7 @@ export class ErrorWithStackTrace extends AlgoliaError {
|
|
|
25
25
|
export class RetryError extends ErrorWithStackTrace {
|
|
26
26
|
constructor(stackTrace: StackFrame[]) {
|
|
27
27
|
super(
|
|
28
|
-
'Unreachable hosts - your application id may be incorrect. If the error persists, please
|
|
28
|
+
'Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.',
|
|
29
29
|
stackTrace,
|
|
30
30
|
'RetryError'
|
|
31
31
|
);
|
|
@@ -30,8 +30,8 @@ export function serializeUrl(
|
|
|
30
30
|
queryParameters: QueryParameters
|
|
31
31
|
): string {
|
|
32
32
|
const queryParametersAsString = serializeQueryParameters(queryParameters);
|
|
33
|
-
let url = `${host.protocol}://${host.url}/${
|
|
34
|
-
path.charAt(0) === '/' ? path.
|
|
33
|
+
let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${
|
|
34
|
+
path.charAt(0) === '/' ? path.substring(1) : path
|
|
35
35
|
}`;
|
|
36
36
|
|
|
37
37
|
if (queryParametersAsString.length) {
|
|
@@ -42,18 +42,16 @@ export function serializeUrl(
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export function serializeQueryParameters(parameters: QueryParameters): string {
|
|
45
|
-
const isObjectOrArray = (value: any): boolean =>
|
|
46
|
-
Object.prototype.toString.call(value) === '[object Object]' ||
|
|
47
|
-
Object.prototype.toString.call(value) === '[object Array]';
|
|
48
|
-
|
|
49
45
|
return Object.keys(parameters)
|
|
46
|
+
.filter((key) => parameters[key] !== undefined)
|
|
47
|
+
.sort()
|
|
50
48
|
.map(
|
|
51
49
|
(key) =>
|
|
52
50
|
`${key}=${encodeURIComponent(
|
|
53
|
-
|
|
54
|
-
?
|
|
51
|
+
Object.prototype.toString.call(parameters[key]) === '[object Array]'
|
|
52
|
+
? parameters[key].join(',')
|
|
55
53
|
: parameters[key]
|
|
56
|
-
)}`
|
|
54
|
+
).replaceAll('+', '%20')}`
|
|
57
55
|
)
|
|
58
56
|
.join('&');
|
|
59
57
|
}
|
package/src/types/host.ts
CHANGED
package/src/types/transporter.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type RequestOptions = Pick<Request, 'cacheable'> & {
|
|
|
11
11
|
* the given timeout will be applied. But the transporter layer may
|
|
12
12
|
* increase this timeout if there is need for it.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
timeouts?: Partial<Timeouts>;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Custom headers for the request. This headers are
|