@algolia/client-common 5.1.0 → 5.2.1
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 +7 -4
- package/dist/client-common.esm.node.js +7 -4
- package/dist/src/cache/createBrowserLocalStorageCache.d.ts.map +1 -1
- package/dist/src/cache/createFallbackableCache.d.ts.map +1 -1
- package/dist/src/cache/createMemoryCache.d.ts.map +1 -1
- package/dist/src/cache/createNullCache.d.ts.map +1 -1
- package/dist/src/createAlgoliaAgent.d.ts.map +1 -1
- package/dist/src/createEchoRequester.d.ts +1 -1
- package/dist/src/createEchoRequester.d.ts.map +1 -1
- package/dist/src/getAlgoliaAgent.d.ts +1 -1
- package/dist/src/getAlgoliaAgent.d.ts.map +1 -1
- package/dist/src/transporter/createStatefulHost.d.ts.map +1 -1
- package/dist/src/transporter/createTransporter.d.ts.map +1 -1
- package/dist/src/transporter/errors.d.ts.map +1 -1
- package/dist/src/transporter/helpers.d.ts.map +1 -1
- package/dist/src/transporter/responses.d.ts +2 -2
- package/dist/src/transporter/responses.d.ts.map +1 -1
- package/dist/src/transporter/stackTrace.d.ts.map +1 -1
- package/dist/src/types/cache.d.ts.map +1 -1
- package/dist/src/types/createClient.d.ts.map +1 -1
- package/dist/src/types/transporter.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/cache/browser-local-storage-cache.test.ts +14 -31
- package/src/__tests__/cache/memory-cache.test.ts +7 -17
- package/src/__tests__/cache/null-cache.test.ts +6 -10
- package/src/__tests__/create-iterable-promise.test.ts +4 -8
- package/src/cache/createBrowserLocalStorageCache.ts +14 -31
- package/src/cache/createFallbackableCache.ts +4 -13
- package/src/cache/createMemoryCache.ts +6 -19
- package/src/cache/createNullCache.ts +3 -8
- package/src/createAlgoliaAgent.ts +1 -3
- package/src/createAuth.ts +1 -1
- package/src/createEchoRequester.ts +3 -9
- package/src/getAlgoliaAgent.ts +2 -8
- package/src/transporter/createStatefulHost.ts +2 -7
- package/src/transporter/createTransporter.ts +20 -52
- package/src/transporter/errors.ts +3 -13
- package/src/transporter/helpers.ts +11 -39
- package/src/transporter/responses.ts +3 -13
- package/src/transporter/stackTrace.ts +4 -12
- package/src/types/cache.ts +2 -5
- package/src/types/createClient.ts +3 -11
- package/src/types/transporter.ts +1 -4
package/dist/client-common.cjs
CHANGED
|
@@ -431,7 +431,7 @@ function deserializeFailure({
|
|
|
431
431
|
return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
|
|
432
432
|
}
|
|
433
433
|
return new ApiError(parsed.message, status, stackFrame);
|
|
434
|
-
} catch
|
|
434
|
+
} catch {
|
|
435
435
|
// ..
|
|
436
436
|
}
|
|
437
437
|
return new ApiError(content, status, stackFrame);
|
|
@@ -559,14 +559,17 @@ function createTransporter({
|
|
|
559
559
|
if (host === undefined) {
|
|
560
560
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
561
561
|
}
|
|
562
|
-
|
|
562
|
+
const timeout = {
|
|
563
|
+
...timeouts,
|
|
564
|
+
...requestOptions.timeouts
|
|
565
|
+
};
|
|
563
566
|
const payload = {
|
|
564
567
|
data,
|
|
565
568
|
headers,
|
|
566
569
|
method: request.method,
|
|
567
570
|
url: serializeUrl(host, request.path, queryParameters),
|
|
568
|
-
connectTimeout: getTimeout(timeoutsCount,
|
|
569
|
-
responseTimeout: getTimeout(timeoutsCount,
|
|
571
|
+
connectTimeout: getTimeout(timeoutsCount, timeout.connect),
|
|
572
|
+
responseTimeout: getTimeout(timeoutsCount, isRead ? timeout.read : timeout.write)
|
|
570
573
|
};
|
|
571
574
|
/**
|
|
572
575
|
* The stackFrame is pushed to the stackTrace so we
|
|
@@ -429,7 +429,7 @@ function deserializeFailure({
|
|
|
429
429
|
return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
|
|
430
430
|
}
|
|
431
431
|
return new ApiError(parsed.message, status, stackFrame);
|
|
432
|
-
} catch
|
|
432
|
+
} catch {
|
|
433
433
|
// ..
|
|
434
434
|
}
|
|
435
435
|
return new ApiError(content, status, stackFrame);
|
|
@@ -557,14 +557,17 @@ function createTransporter({
|
|
|
557
557
|
if (host === undefined) {
|
|
558
558
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
559
559
|
}
|
|
560
|
-
|
|
560
|
+
const timeout = {
|
|
561
|
+
...timeouts,
|
|
562
|
+
...requestOptions.timeouts
|
|
563
|
+
};
|
|
561
564
|
const payload = {
|
|
562
565
|
data,
|
|
563
566
|
headers,
|
|
564
567
|
method: request.method,
|
|
565
568
|
url: serializeUrl(host, request.path, queryParameters),
|
|
566
|
-
connectTimeout: getTimeout(timeoutsCount,
|
|
567
|
-
responseTimeout: getTimeout(timeoutsCount,
|
|
569
|
+
connectTimeout: getTimeout(timeoutsCount, timeout.connect),
|
|
570
|
+
responseTimeout: getTimeout(timeoutsCount, isRead ? timeout.read : timeout.write)
|
|
568
571
|
};
|
|
569
572
|
/**
|
|
570
573
|
* The stackFrame is pushed to the stackTrace so we
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBrowserLocalStorageCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createBrowserLocalStorageCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createBrowserLocalStorageCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createBrowserLocalStorageCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,0BAA0B,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAE7G,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,0BAA0B,GAAG,KAAK,CAuGzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFallbackableCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createFallbackableCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAI7E,wBAAgB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"createFallbackableCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createFallbackableCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAI7E,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,KAAK,CAuChF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMemoryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createMemoryCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEvE,wBAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"createMemoryCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createMemoryCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEvE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,kBAA2C,GAAG,KAAK,CAwC7F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNullCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createNullCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAEnD,wBAAgB,eAAe,IAAI,KAAK,
|
|
1
|
+
{"version":3,"file":"createNullCache.d.ts","sourceRoot":"","sources":["../../../src/cache/createNullCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAEnD,wBAAgB,eAAe,IAAI,KAAK,CA0BvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../src/createAlgoliaAgent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"createAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../src/createAlgoliaAgent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAehE"}
|
|
@@ -3,5 +3,5 @@ export type EchoRequesterParams = {
|
|
|
3
3
|
getURL: (url: string) => URL;
|
|
4
4
|
status?: number;
|
|
5
5
|
};
|
|
6
|
-
export declare function createEchoRequester({ getURL, status
|
|
6
|
+
export declare function createEchoRequester({ getURL, status }: EchoRequesterParams): Requester;
|
|
7
7
|
//# sourceMappingURL=createEchoRequester.d.ts.map
|
|
@@ -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;AAyCF,wBAAgB,mBAAmB,CAAC,EAAE,MAAM,EAAE,MAAY,EAAE,EAAE,mBAAmB,GAAG,SAAS,CAqB5F"}
|
|
@@ -4,5 +4,5 @@ export type GetAlgoliaAgent = {
|
|
|
4
4
|
client: string;
|
|
5
5
|
version: string;
|
|
6
6
|
};
|
|
7
|
-
export declare function getAlgoliaAgent({ algoliaAgents, client, version
|
|
7
|
+
export declare function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent;
|
|
8
8
|
//# sourceMappingURL=getAlgoliaAgent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../src/getAlgoliaAgent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"getAlgoliaAgent.d.ts","sourceRoot":"","sources":["../../src/getAlgoliaAgent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjE,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,eAAe,GAAG,YAAY,CASjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStatefulHost.d.ts","sourceRoot":"","sources":["../../../src/transporter/createStatefulHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMnD,wBAAgB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"createStatefulHost.d.ts","sourceRoot":"","sources":["../../../src/transporter/createStatefulHost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAMnD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,YAAY,CAAC,QAAQ,CAAQ,GAAG,YAAY,CAYlG"}
|
|
@@ -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;
|
|
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;AAalB,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,CAyRlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/transporter/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAkB;gBAElB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAO1C;AAED,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,UAAU,EAAE,UAAU,EAAE,CAAC;gBAEb,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,MAAM;CAKpE;AAED,qBAAa,U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AC,EAAE,wBAAwB,EAAE,GAAG,uBAAuB,EAAE,CAAC;CAClE,CAAC;AAGF,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,KAAK,EAAE,aAAa,CAAC;gBAET,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE;CAI5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/transporter/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/transporter/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAI9G,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,CAYtD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,GAAG,MAAM,CAW/F;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,eAAe,GAAG,MAAM,CAa5E;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAQlG;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,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,KAAK,CAWjG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Response } from '../types';
|
|
2
|
-
export declare function isNetworkError({ isTimedOut, status
|
|
3
|
-
export declare function isRetryable({ isTimedOut, status
|
|
2
|
+
export declare function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean;
|
|
3
|
+
export declare function isRetryable({ isTimedOut, status }: Omit<Response, 'content'>): boolean;
|
|
4
4
|
export declare function isSuccess({ status }: Pick<Response, 'status'>): boolean;
|
|
5
5
|
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../../src/transporter/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../../src/transporter/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAEzF;AAED,wBAAgB,WAAW,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAEtF;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,OAAO,CAEvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stackTrace.d.ts","sourceRoot":"","sources":["../../../src/transporter/stackTrace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,4BAA4B,
|
|
1
|
+
{"version":3,"file":"stackTrace.d.ts","sourceRoot":"","sources":["../../../src/transporter/stackTrace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAEnF;AAED,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAe/E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/types/cache.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IAClB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,EACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EACjC,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACnC,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,KACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/types/cache.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG;IAClB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,EACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EACjC,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACnC,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,KACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnF;;OAEG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI;IAChC;;OAEG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../src/types/createClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE7E,MAAM,MAAM,QAAQ,GAAG,eAAe,GAAG,uBAAuB,CAAC;AAEjE,KAAK,4BAA4B,
|
|
1
|
+
{"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../src/types/createClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAk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;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,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;CACvG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/client-common",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Common package for the Algolia JavaScript API client.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
"test": "jest"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@babel/preset-env": "7.25.
|
|
26
|
+
"@babel/preset-env": "7.25.4",
|
|
27
27
|
"@babel/preset-typescript": "7.24.7",
|
|
28
28
|
"@types/jest": "29.5.12",
|
|
29
|
-
"@types/node": "
|
|
29
|
+
"@types/node": "22.5.0",
|
|
30
30
|
"jest": "29.7.0",
|
|
31
31
|
"jest-environment-jsdom": "29.7.0",
|
|
32
|
-
"ts-jest": "29.2.
|
|
32
|
+
"ts-jest": "29.2.5",
|
|
33
33
|
"typescript": "5.5.4"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
@@ -26,16 +26,12 @@ describe('browser local storage cache', () => {
|
|
|
26
26
|
const cache = createBrowserLocalStorageCache({ key: version });
|
|
27
27
|
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 1 });
|
|
28
28
|
|
|
29
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
30
|
-
{ bar: 1 }
|
|
31
|
-
);
|
|
29
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 1 });
|
|
32
30
|
expect(missMock.mock.calls.length).toBe(1);
|
|
33
31
|
|
|
34
32
|
await cache.set({ key: 'foo' }, { foo: 2 });
|
|
35
33
|
|
|
36
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
37
|
-
{ foo: 2 }
|
|
38
|
-
);
|
|
34
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ foo: 2 });
|
|
39
35
|
expect(missMock.mock.calls.length).toBe(1);
|
|
40
36
|
});
|
|
41
37
|
|
|
@@ -51,7 +47,7 @@ describe('browser local storage cache', () => {
|
|
|
51
47
|
expect(
|
|
52
48
|
await cache.get({ key: 'foo' }, defaultValue, {
|
|
53
49
|
miss: () => Promise.resolve(missMock()),
|
|
54
|
-
})
|
|
50
|
+
}),
|
|
55
51
|
).toMatchObject({ bar: 1 });
|
|
56
52
|
|
|
57
53
|
expect(missMock.mock.calls.length).toBe(0);
|
|
@@ -65,9 +61,7 @@ describe('browser local storage cache', () => {
|
|
|
65
61
|
|
|
66
62
|
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
67
63
|
|
|
68
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
69
|
-
{ bar: 2 }
|
|
70
|
-
);
|
|
64
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
71
65
|
expect(missMock.mock.calls.length).toBe(1);
|
|
72
66
|
});
|
|
73
67
|
|
|
@@ -83,7 +77,7 @@ describe('browser local storage cache', () => {
|
|
|
83
77
|
expect(
|
|
84
78
|
await cache.get({ key: 'foo' }, defaultValue, {
|
|
85
79
|
miss: () => Promise.resolve(missMock()),
|
|
86
|
-
})
|
|
80
|
+
}),
|
|
87
81
|
).toMatchObject({ bar: 2 });
|
|
88
82
|
|
|
89
83
|
expect(missMock.mock.calls.length).toBe(1);
|
|
@@ -102,7 +96,7 @@ describe('browser local storage cache', () => {
|
|
|
102
96
|
expect(
|
|
103
97
|
await cache.get({ key: 'foo' }, defaultValue, {
|
|
104
98
|
miss: () => Promise.resolve(missMock()),
|
|
105
|
-
})
|
|
99
|
+
}),
|
|
106
100
|
).toMatchObject({ bar: 2 });
|
|
107
101
|
|
|
108
102
|
expect(missMock.mock.calls.length).toBe(1);
|
|
@@ -111,8 +105,7 @@ describe('browser local storage cache', () => {
|
|
|
111
105
|
});
|
|
112
106
|
|
|
113
107
|
it('do throws localstorage exceptions on access', async () => {
|
|
114
|
-
const message =
|
|
115
|
-
"Failed to read the 'localStorage' property from 'Window': Access is denied for this document.";
|
|
108
|
+
const message = "Failed to read the 'localStorage' property from 'Window': Access is denied for this document.";
|
|
116
109
|
const cache = createBrowserLocalStorageCache(
|
|
117
110
|
new Proxy(
|
|
118
111
|
{ key: 'foo' },
|
|
@@ -125,20 +118,16 @@ describe('browser local storage cache', () => {
|
|
|
125
118
|
// Simulates a window.localStorage access.
|
|
126
119
|
throw new DOMException(message);
|
|
127
120
|
},
|
|
128
|
-
}
|
|
129
|
-
)
|
|
121
|
+
},
|
|
122
|
+
),
|
|
130
123
|
);
|
|
131
124
|
const key = { foo: 'bar' };
|
|
132
125
|
const value = 'foo';
|
|
133
126
|
const fallback = 'bar';
|
|
134
127
|
|
|
135
128
|
await expect(cache.delete(key)).rejects.toEqual(new DOMException(message));
|
|
136
|
-
await expect(cache.set(key, value)).rejects.toEqual(
|
|
137
|
-
|
|
138
|
-
);
|
|
139
|
-
await expect(
|
|
140
|
-
cache.get(key, () => Promise.resolve(fallback))
|
|
141
|
-
).rejects.toEqual(new DOMException(message));
|
|
129
|
+
await expect(cache.set(key, value)).rejects.toEqual(new DOMException(message));
|
|
130
|
+
await expect(cache.get(key, () => Promise.resolve(fallback))).rejects.toEqual(new DOMException(message));
|
|
142
131
|
});
|
|
143
132
|
|
|
144
133
|
it('do throws localstorage exceptions after access', async () => {
|
|
@@ -153,9 +142,7 @@ describe('browser local storage cache', () => {
|
|
|
153
142
|
|
|
154
143
|
await expect(cache.delete(key)).rejects.toEqual(new Error(message));
|
|
155
144
|
await expect(cache.set(key, value)).rejects.toEqual(new Error(message));
|
|
156
|
-
await expect(
|
|
157
|
-
cache.get(key, () => Promise.resolve(fallback))
|
|
158
|
-
).rejects.toEqual(new Error(message));
|
|
145
|
+
await expect(cache.get(key, () => Promise.resolve(fallback))).rejects.toEqual(new Error(message));
|
|
159
146
|
});
|
|
160
147
|
|
|
161
148
|
it('creates a namespace within local storage', async () => {
|
|
@@ -175,12 +162,8 @@ describe('browser local storage cache', () => {
|
|
|
175
162
|
},
|
|
176
163
|
});
|
|
177
164
|
|
|
178
|
-
const localStorageValue = localStorage.getItem(
|
|
179
|
-
`algolia-client-js-${version}`
|
|
180
|
-
);
|
|
165
|
+
const localStorageValue = localStorage.getItem(`algolia-client-js-${version}`);
|
|
181
166
|
|
|
182
|
-
expect(JSON.parse(localStorageValue ? localStorageValue : '{}')).toEqual(
|
|
183
|
-
expectedValue
|
|
184
|
-
);
|
|
167
|
+
expect(JSON.parse(localStorageValue ? localStorageValue : '{}')).toEqual(expectedValue);
|
|
185
168
|
});
|
|
186
169
|
});
|
|
@@ -16,18 +16,14 @@ describe('memory cache', () => {
|
|
|
16
16
|
const cache = createMemoryCache();
|
|
17
17
|
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 1 });
|
|
18
18
|
|
|
19
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
);
|
|
19
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({
|
|
20
|
+
bar: 1,
|
|
21
|
+
});
|
|
24
22
|
|
|
25
23
|
await cache.set({ key: 'foo' }, { foo: 2 });
|
|
26
24
|
|
|
27
25
|
expect(missMock.mock.calls.length).toBe(1);
|
|
28
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
29
|
-
{ foo: 2 }
|
|
30
|
-
);
|
|
26
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ foo: 2 });
|
|
31
27
|
expect(missMock.mock.calls.length).toBe(1);
|
|
32
28
|
});
|
|
33
29
|
|
|
@@ -54,9 +50,7 @@ describe('memory cache', () => {
|
|
|
54
50
|
|
|
55
51
|
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
56
52
|
|
|
57
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
58
|
-
{ bar: 2 }
|
|
59
|
-
);
|
|
53
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
60
54
|
expect(missMock.mock.calls.length).toBe(1);
|
|
61
55
|
});
|
|
62
56
|
|
|
@@ -68,9 +62,7 @@ describe('memory cache', () => {
|
|
|
68
62
|
|
|
69
63
|
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
70
64
|
|
|
71
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
72
|
-
{ bar: 2 }
|
|
73
|
-
);
|
|
65
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
74
66
|
expect(missMock.mock.calls.length).toBe(1);
|
|
75
67
|
});
|
|
76
68
|
|
|
@@ -82,9 +74,7 @@ describe('memory cache', () => {
|
|
|
82
74
|
|
|
83
75
|
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
84
76
|
|
|
85
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
|
|
86
|
-
{ bar: 2 }
|
|
87
|
-
);
|
|
77
|
+
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
88
78
|
expect(missMock.mock.calls.length).toBe(1);
|
|
89
79
|
});
|
|
90
80
|
});
|
|
@@ -18,11 +18,9 @@ describe('null cache', () => {
|
|
|
18
18
|
|
|
19
19
|
await cache.set({ key: 'key' }, { foo: 10 });
|
|
20
20
|
|
|
21
|
-
expect(await cache.get({ key: 'key' }, defaultValue, events)).toMatchObject(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
);
|
|
21
|
+
expect(await cache.get({ key: 'key' }, defaultValue, events)).toMatchObject({
|
|
22
|
+
bar: 12,
|
|
23
|
+
});
|
|
26
24
|
|
|
27
25
|
expect(missMock.mock.calls.length).toBe(1);
|
|
28
26
|
});
|
|
@@ -30,11 +28,9 @@ describe('null cache', () => {
|
|
|
30
28
|
it('returns default value', async () => {
|
|
31
29
|
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 12 });
|
|
32
30
|
|
|
33
|
-
expect(await cache.get({ foo: 'foo' }, defaultValue, events)).toMatchObject(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
);
|
|
31
|
+
expect(await cache.get({ foo: 'foo' }, defaultValue, events)).toMatchObject({
|
|
32
|
+
bar: 12,
|
|
33
|
+
});
|
|
38
34
|
|
|
39
35
|
expect(missMock.mock.calls.length).toBe(1);
|
|
40
36
|
});
|
|
@@ -156,9 +156,7 @@ describe('createIterablePromise', () => {
|
|
|
156
156
|
validate: () => false,
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
await expect(promise).rejects.toEqual(
|
|
160
|
-
expect.objectContaining({ message: 'nope' })
|
|
161
|
-
);
|
|
159
|
+
await expect(promise).rejects.toEqual(expect.objectContaining({ message: 'nope' }));
|
|
162
160
|
});
|
|
163
161
|
|
|
164
162
|
it('gets the rejection of the given promise via throw', async () => {
|
|
@@ -178,9 +176,7 @@ describe('createIterablePromise', () => {
|
|
|
178
176
|
validate: () => false,
|
|
179
177
|
});
|
|
180
178
|
|
|
181
|
-
await expect(promise).rejects.toEqual(
|
|
182
|
-
expect.objectContaining({ message: 'nope' })
|
|
183
|
-
);
|
|
179
|
+
await expect(promise).rejects.toEqual(expect.objectContaining({ message: 'nope' }));
|
|
184
180
|
});
|
|
185
181
|
|
|
186
182
|
it('rejects with the given `message` when `validate` hits', async () => {
|
|
@@ -204,7 +200,7 @@ describe('createIterablePromise', () => {
|
|
|
204
200
|
await expect(promise).rejects.toEqual(
|
|
205
201
|
expect.objectContaining({
|
|
206
202
|
message: 'Error is thrown: 3/3',
|
|
207
|
-
})
|
|
203
|
+
}),
|
|
208
204
|
);
|
|
209
205
|
expect(calls).toBe(MAX_RETRIES);
|
|
210
206
|
});
|
|
@@ -230,7 +226,7 @@ describe('createIterablePromise', () => {
|
|
|
230
226
|
await expect(promise).rejects.toEqual(
|
|
231
227
|
expect.objectContaining({
|
|
232
228
|
message: 'Error is thrown: 3/3',
|
|
233
|
-
})
|
|
229
|
+
}),
|
|
234
230
|
);
|
|
235
231
|
expect(calls).toBe(MAX_RETRIES);
|
|
236
232
|
});
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Cache,
|
|
5
|
-
CacheEvents,
|
|
6
|
-
} from '../types';
|
|
7
|
-
|
|
8
|
-
export function createBrowserLocalStorageCache(
|
|
9
|
-
options: BrowserLocalStorageOptions
|
|
10
|
-
): Cache {
|
|
1
|
+
import type { BrowserLocalStorageCacheItem, BrowserLocalStorageOptions, Cache, CacheEvents } from '../types';
|
|
2
|
+
|
|
3
|
+
export function createBrowserLocalStorageCache(options: BrowserLocalStorageOptions): Cache {
|
|
11
4
|
let storage: Storage;
|
|
12
5
|
// We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change
|
|
13
6
|
const namespaceKey = `algolia-client-js-${options.key}`;
|
|
@@ -35,7 +28,7 @@ export function createBrowserLocalStorageCache(
|
|
|
35
28
|
const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(
|
|
36
29
|
Object.entries(namespace).filter(([, cacheItem]) => {
|
|
37
30
|
return cacheItem.timestamp !== undefined;
|
|
38
|
-
})
|
|
31
|
+
}),
|
|
39
32
|
);
|
|
40
33
|
|
|
41
34
|
setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);
|
|
@@ -45,14 +38,12 @@ export function createBrowserLocalStorageCache(
|
|
|
45
38
|
}
|
|
46
39
|
|
|
47
40
|
const filteredNamespaceWithoutExpiredItems = Object.fromEntries(
|
|
48
|
-
Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
)
|
|
41
|
+
Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
|
|
42
|
+
const currentTimestamp = new Date().getTime();
|
|
43
|
+
const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
|
|
44
|
+
|
|
45
|
+
return !isExpired;
|
|
46
|
+
}),
|
|
56
47
|
);
|
|
57
48
|
|
|
58
49
|
setNamespace(filteredNamespaceWithoutExpiredItems);
|
|
@@ -64,21 +55,16 @@ export function createBrowserLocalStorageCache(
|
|
|
64
55
|
defaultValue: () => Promise<TValue>,
|
|
65
56
|
events: CacheEvents<TValue> = {
|
|
66
57
|
miss: () => Promise.resolve(),
|
|
67
|
-
}
|
|
58
|
+
},
|
|
68
59
|
): Promise<TValue> {
|
|
69
60
|
return Promise.resolve()
|
|
70
61
|
.then(() => {
|
|
71
62
|
removeOutdatedCacheItems();
|
|
72
63
|
|
|
73
|
-
return getNamespace<Promise<BrowserLocalStorageCacheItem>>()[
|
|
74
|
-
JSON.stringify(key)
|
|
75
|
-
];
|
|
64
|
+
return getNamespace<Promise<BrowserLocalStorageCacheItem>>()[JSON.stringify(key)];
|
|
76
65
|
})
|
|
77
66
|
.then((value) => {
|
|
78
|
-
return Promise.all([
|
|
79
|
-
value ? value.value : defaultValue(),
|
|
80
|
-
value !== undefined,
|
|
81
|
-
]);
|
|
67
|
+
return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
|
|
82
68
|
})
|
|
83
69
|
.then(([value, exists]) => {
|
|
84
70
|
return Promise.all([value, exists || events.miss(value)]);
|
|
@@ -86,10 +72,7 @@ export function createBrowserLocalStorageCache(
|
|
|
86
72
|
.then(([value]) => value);
|
|
87
73
|
},
|
|
88
74
|
|
|
89
|
-
set<TValue>(
|
|
90
|
-
key: Record<string, any> | string,
|
|
91
|
-
value: TValue
|
|
92
|
-
): Promise<TValue> {
|
|
75
|
+
set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {
|
|
93
76
|
return Promise.resolve().then(() => {
|
|
94
77
|
const namespace = getNamespace();
|
|
95
78
|
|
|
@@ -2,9 +2,7 @@ import type { FallbackableCacheOptions, Cache, CacheEvents } from '../types';
|
|
|
2
2
|
|
|
3
3
|
import { createNullCache } from './createNullCache';
|
|
4
4
|
|
|
5
|
-
export function createFallbackableCache(
|
|
6
|
-
options: FallbackableCacheOptions
|
|
7
|
-
): Cache {
|
|
5
|
+
export function createFallbackableCache(options: FallbackableCacheOptions): Cache {
|
|
8
6
|
const caches = [...options.caches];
|
|
9
7
|
const current = caches.shift();
|
|
10
8
|
|
|
@@ -18,21 +16,14 @@ export function createFallbackableCache(
|
|
|
18
16
|
defaultValue: () => Promise<TValue>,
|
|
19
17
|
events: CacheEvents<TValue> = {
|
|
20
18
|
miss: (): Promise<void> => Promise.resolve(),
|
|
21
|
-
}
|
|
19
|
+
},
|
|
22
20
|
): Promise<TValue> {
|
|
23
21
|
return current.get(key, defaultValue, events).catch(() => {
|
|
24
|
-
return createFallbackableCache({ caches }).get(
|
|
25
|
-
key,
|
|
26
|
-
defaultValue,
|
|
27
|
-
events
|
|
28
|
-
);
|
|
22
|
+
return createFallbackableCache({ caches }).get(key, defaultValue, events);
|
|
29
23
|
});
|
|
30
24
|
},
|
|
31
25
|
|
|
32
|
-
set<TValue>(
|
|
33
|
-
key: Record<string, any> | string,
|
|
34
|
-
value: TValue
|
|
35
|
-
): Promise<TValue> {
|
|
26
|
+
set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {
|
|
36
27
|
return current.set(key, value).catch(() => {
|
|
37
28
|
return createFallbackableCache({ caches }).set(key, value);
|
|
38
29
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Cache, CacheEvents, MemoryCacheOptions } from '../types';
|
|
2
2
|
|
|
3
|
-
export function createMemoryCache(
|
|
4
|
-
options: MemoryCacheOptions = { serializable: true }
|
|
5
|
-
): Cache {
|
|
3
|
+
export function createMemoryCache(options: MemoryCacheOptions = { serializable: true }): Cache {
|
|
6
4
|
let cache: Record<string, any> = {};
|
|
7
5
|
|
|
8
6
|
return {
|
|
@@ -11,32 +9,21 @@ export function createMemoryCache(
|
|
|
11
9
|
defaultValue: () => Promise<TValue>,
|
|
12
10
|
events: CacheEvents<TValue> = {
|
|
13
11
|
miss: (): Promise<void> => Promise.resolve(),
|
|
14
|
-
}
|
|
12
|
+
},
|
|
15
13
|
): Promise<TValue> {
|
|
16
14
|
const keyAsString = JSON.stringify(key);
|
|
17
15
|
|
|
18
16
|
if (keyAsString in cache) {
|
|
19
|
-
return Promise.resolve(
|
|
20
|
-
options.serializable
|
|
21
|
-
? JSON.parse(cache[keyAsString])
|
|
22
|
-
: cache[keyAsString]
|
|
23
|
-
);
|
|
17
|
+
return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
|
|
24
18
|
}
|
|
25
19
|
|
|
26
20
|
const promise = defaultValue();
|
|
27
21
|
|
|
28
|
-
return promise
|
|
29
|
-
.then((value: TValue) => events.miss(value))
|
|
30
|
-
.then(() => promise);
|
|
22
|
+
return promise.then((value: TValue) => events.miss(value)).then(() => promise);
|
|
31
23
|
},
|
|
32
24
|
|
|
33
|
-
set<TValue>(
|
|
34
|
-
key
|
|
35
|
-
value: TValue
|
|
36
|
-
): Promise<TValue> {
|
|
37
|
-
cache[JSON.stringify(key)] = options.serializable
|
|
38
|
-
? JSON.stringify(value)
|
|
39
|
-
: value;
|
|
25
|
+
set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {
|
|
26
|
+
cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
|
|
40
27
|
|
|
41
28
|
return Promise.resolve(value);
|
|
42
29
|
},
|
|
@@ -7,19 +7,14 @@ export function createNullCache(): Cache {
|
|
|
7
7
|
defaultValue: () => Promise<TValue>,
|
|
8
8
|
events: CacheEvents<TValue> = {
|
|
9
9
|
miss: (): Promise<void> => Promise.resolve(),
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
11
|
): Promise<TValue> {
|
|
12
12
|
const value = defaultValue();
|
|
13
13
|
|
|
14
|
-
return value
|
|
15
|
-
.then((result) => Promise.all([result, events.miss(result)]))
|
|
16
|
-
.then(([result]) => result);
|
|
14
|
+
return value.then((result) => Promise.all([result, events.miss(result)])).then(([result]) => result);
|
|
17
15
|
},
|
|
18
16
|
|
|
19
|
-
set<TValue>(
|
|
20
|
-
_key: Record<string, any> | string,
|
|
21
|
-
value: TValue
|
|
22
|
-
): Promise<TValue> {
|
|
17
|
+
set<TValue>(_key: Record<string, any> | string, value: TValue): Promise<TValue> {
|
|
23
18
|
return Promise.resolve(value);
|
|
24
19
|
},
|
|
25
20
|
|
|
@@ -4,9 +4,7 @@ export function createAlgoliaAgent(version: string): AlgoliaAgent {
|
|
|
4
4
|
const algoliaAgent = {
|
|
5
5
|
value: `Algolia for JavaScript (${version})`,
|
|
6
6
|
add(options: AlgoliaAgentOptions): AlgoliaAgent {
|
|
7
|
-
const addedAlgoliaAgent = `; ${options.segment}${
|
|
8
|
-
options.version !== undefined ? ` (${options.version})` : ''
|
|
9
|
-
}`;
|
|
7
|
+
const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
|
|
10
8
|
|
|
11
9
|
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
|
|
12
10
|
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
|
package/src/createAuth.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AuthMode, Headers, QueryParameters } from './types';
|
|
|
3
3
|
export function createAuth(
|
|
4
4
|
appId: string,
|
|
5
5
|
apiKey: string,
|
|
6
|
-
authMode: AuthMode = 'WithinHeaders'
|
|
6
|
+
authMode: AuthMode = 'WithinHeaders',
|
|
7
7
|
): {
|
|
8
8
|
readonly headers: () => Headers;
|
|
9
9
|
readonly queryParameters: () => QueryParameters;
|
|
@@ -39,20 +39,14 @@ function getUrlParams({
|
|
|
39
39
|
return {
|
|
40
40
|
host,
|
|
41
41
|
algoliaAgent,
|
|
42
|
-
searchParams:
|
|
43
|
-
Object.keys(searchParams).length === 0 ? undefined : searchParams,
|
|
42
|
+
searchParams: Object.keys(searchParams).length === 0 ? undefined : searchParams,
|
|
44
43
|
path: pathname,
|
|
45
44
|
};
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
export function createEchoRequester({
|
|
49
|
-
getURL,
|
|
50
|
-
status = 200,
|
|
51
|
-
}: EchoRequesterParams): Requester {
|
|
47
|
+
export function createEchoRequester({ getURL, status = 200 }: EchoRequesterParams): Requester {
|
|
52
48
|
function send(request: EndRequest): Promise<Response> {
|
|
53
|
-
const { host, searchParams, algoliaAgent, path } = getUrlParams(
|
|
54
|
-
getURL(request.url)
|
|
55
|
-
);
|
|
49
|
+
const { host, searchParams, algoliaAgent, path } = getUrlParams(getURL(request.url));
|
|
56
50
|
|
|
57
51
|
const content: EchoResponse = {
|
|
58
52
|
...request,
|
package/src/getAlgoliaAgent.ts
CHANGED
|
@@ -7,19 +7,13 @@ export type GetAlgoliaAgent = {
|
|
|
7
7
|
version: string;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export function getAlgoliaAgent({
|
|
11
|
-
algoliaAgents,
|
|
12
|
-
client,
|
|
13
|
-
version,
|
|
14
|
-
}: GetAlgoliaAgent): AlgoliaAgent {
|
|
10
|
+
export function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent {
|
|
15
11
|
const defaultAlgoliaAgent = createAlgoliaAgent(version).add({
|
|
16
12
|
segment: client,
|
|
17
13
|
version,
|
|
18
14
|
});
|
|
19
15
|
|
|
20
|
-
algoliaAgents.forEach((algoliaAgent) =>
|
|
21
|
-
defaultAlgoliaAgent.add(algoliaAgent)
|
|
22
|
-
);
|
|
16
|
+
algoliaAgents.forEach((algoliaAgent) => defaultAlgoliaAgent.add(algoliaAgent));
|
|
23
17
|
|
|
24
18
|
return defaultAlgoliaAgent;
|
|
25
19
|
}
|
|
@@ -4,10 +4,7 @@ import type { Host, StatefulHost } from '../types';
|
|
|
4
4
|
// In the JavaScript client, we have 2 mins.
|
|
5
5
|
const EXPIRATION_DELAY = 2 * 60 * 1000;
|
|
6
6
|
|
|
7
|
-
export function createStatefulHost(
|
|
8
|
-
host: Host,
|
|
9
|
-
status: StatefulHost['status'] = 'up'
|
|
10
|
-
): StatefulHost {
|
|
7
|
+
export function createStatefulHost(host: Host, status: StatefulHost['status'] = 'up'): StatefulHost {
|
|
11
8
|
const lastUpdate = Date.now();
|
|
12
9
|
|
|
13
10
|
function isUp(): boolean {
|
|
@@ -15,9 +12,7 @@ export function createStatefulHost(
|
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
function isTimedOut(): boolean {
|
|
18
|
-
return (
|
|
19
|
-
status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY
|
|
20
|
-
);
|
|
15
|
+
return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
|
|
21
16
|
}
|
|
22
17
|
|
|
23
18
|
return { ...host, status, lastUpdate, isUp, isTimedOut };
|
|
@@ -12,18 +12,9 @@ import type {
|
|
|
12
12
|
|
|
13
13
|
import { createStatefulHost } from './createStatefulHost';
|
|
14
14
|
import { RetryError } from './errors';
|
|
15
|
-
import {
|
|
16
|
-
deserializeFailure,
|
|
17
|
-
deserializeSuccess,
|
|
18
|
-
serializeData,
|
|
19
|
-
serializeHeaders,
|
|
20
|
-
serializeUrl,
|
|
21
|
-
} from './helpers';
|
|
15
|
+
import { deserializeFailure, deserializeSuccess, serializeData, serializeHeaders, serializeUrl } from './helpers';
|
|
22
16
|
import { isRetryable, isSuccess } from './responses';
|
|
23
|
-
import {
|
|
24
|
-
stackTraceWithoutCredentials,
|
|
25
|
-
stackFrameWithoutCredentials,
|
|
26
|
-
} from './stackTrace';
|
|
17
|
+
import { stackTraceWithoutCredentials, stackFrameWithoutCredentials } from './stackTrace';
|
|
27
18
|
|
|
28
19
|
type RetryableOptions = {
|
|
29
20
|
hosts: Host[];
|
|
@@ -41,23 +32,20 @@ export function createTransporter({
|
|
|
41
32
|
requestsCache,
|
|
42
33
|
responsesCache,
|
|
43
34
|
}: TransporterOptions): Transporter {
|
|
44
|
-
async function createRetryableOptions(
|
|
45
|
-
compatibleHosts: Host[]
|
|
46
|
-
): Promise<RetryableOptions> {
|
|
35
|
+
async function createRetryableOptions(compatibleHosts: Host[]): Promise<RetryableOptions> {
|
|
47
36
|
const statefulHosts = await Promise.all(
|
|
48
37
|
compatibleHosts.map((compatibleHost) => {
|
|
49
38
|
return hostsCache.get(compatibleHost, () => {
|
|
50
39
|
return Promise.resolve(createStatefulHost(compatibleHost));
|
|
51
40
|
});
|
|
52
|
-
})
|
|
41
|
+
}),
|
|
53
42
|
);
|
|
54
43
|
const hostsUp = statefulHosts.filter((host) => host.isUp());
|
|
55
44
|
const hostsTimedOut = statefulHosts.filter((host) => host.isTimedOut());
|
|
56
45
|
|
|
57
46
|
// Note, we put the hosts that previously timed out on the end of the list.
|
|
58
47
|
const hostsAvailable = [...hostsUp, ...hostsTimedOut];
|
|
59
|
-
const compatibleHostsAvailable =
|
|
60
|
-
hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
|
|
48
|
+
const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
|
|
61
49
|
|
|
62
50
|
return {
|
|
63
51
|
hosts: compatibleHostsAvailable,
|
|
@@ -74,9 +62,7 @@ export function createTransporter({
|
|
|
74
62
|
* current v3 version.
|
|
75
63
|
*/
|
|
76
64
|
const timeoutMultiplier =
|
|
77
|
-
hostsTimedOut.length === 0 && timeoutsCount === 0
|
|
78
|
-
? 1
|
|
79
|
-
: hostsTimedOut.length + 3 + timeoutsCount;
|
|
65
|
+
hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
|
|
80
66
|
|
|
81
67
|
return timeoutMultiplier * baseTimeout;
|
|
82
68
|
},
|
|
@@ -86,7 +72,7 @@ export function createTransporter({
|
|
|
86
72
|
async function retryableRequest<TResponse>(
|
|
87
73
|
request: Request,
|
|
88
74
|
requestOptions: RequestOptions,
|
|
89
|
-
isRead = true
|
|
75
|
+
isRead = true,
|
|
90
76
|
): Promise<TResponse> {
|
|
91
77
|
const stackTrace: StackFrame[] = [];
|
|
92
78
|
|
|
@@ -94,11 +80,7 @@ export function createTransporter({
|
|
|
94
80
|
* First we prepare the payload that do not depend from hosts.
|
|
95
81
|
*/
|
|
96
82
|
const data = serializeData(request, requestOptions);
|
|
97
|
-
const headers = serializeHeaders(
|
|
98
|
-
baseHeaders,
|
|
99
|
-
request.headers,
|
|
100
|
-
requestOptions.headers
|
|
101
|
-
);
|
|
83
|
+
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
102
84
|
|
|
103
85
|
// On `GET`, the data is proxied to query parameters.
|
|
104
86
|
const dataQueryParameters: QueryParameters =
|
|
@@ -126,9 +108,7 @@ export function createTransporter({
|
|
|
126
108
|
// handled in the `serializeUrl` step right after.
|
|
127
109
|
if (
|
|
128
110
|
!requestOptions.queryParameters[key] ||
|
|
129
|
-
Object.prototype.toString.call(
|
|
130
|
-
requestOptions.queryParameters[key]
|
|
131
|
-
) === '[object Object]'
|
|
111
|
+
Object.prototype.toString.call(requestOptions.queryParameters[key]) === '[object Object]'
|
|
132
112
|
) {
|
|
133
113
|
queryParameters[key] = requestOptions.queryParameters[key];
|
|
134
114
|
} else {
|
|
@@ -141,7 +121,7 @@ export function createTransporter({
|
|
|
141
121
|
|
|
142
122
|
const retry = async (
|
|
143
123
|
retryableHosts: Host[],
|
|
144
|
-
getTimeout: (timeoutsCount: number, timeout: number) => number
|
|
124
|
+
getTimeout: (timeoutsCount: number, timeout: number) => number,
|
|
145
125
|
): Promise<TResponse> => {
|
|
146
126
|
/**
|
|
147
127
|
* We iterate on each host, until there is no host left.
|
|
@@ -151,15 +131,15 @@ export function createTransporter({
|
|
|
151
131
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
152
132
|
}
|
|
153
133
|
|
|
154
|
-
|
|
134
|
+
const timeout = { ...timeouts, ...requestOptions.timeouts };
|
|
155
135
|
|
|
156
136
|
const payload: EndRequest = {
|
|
157
137
|
data,
|
|
158
138
|
headers,
|
|
159
139
|
method: request.method,
|
|
160
140
|
url: serializeUrl(host, request.path, queryParameters),
|
|
161
|
-
connectTimeout: getTimeout(timeoutsCount,
|
|
162
|
-
responseTimeout: getTimeout(timeoutsCount,
|
|
141
|
+
connectTimeout: getTimeout(timeoutsCount, timeout.connect),
|
|
142
|
+
responseTimeout: getTimeout(timeoutsCount, isRead ? timeout.read : timeout.write),
|
|
163
143
|
};
|
|
164
144
|
|
|
165
145
|
/**
|
|
@@ -195,20 +175,14 @@ export function createTransporter({
|
|
|
195
175
|
* when a retry error does not happen.
|
|
196
176
|
*/
|
|
197
177
|
// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
|
|
198
|
-
console.log(
|
|
199
|
-
'Retryable failure',
|
|
200
|
-
stackFrameWithoutCredentials(stackFrame)
|
|
201
|
-
);
|
|
178
|
+
console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
|
|
202
179
|
|
|
203
180
|
/**
|
|
204
181
|
* We also store the state of the host in failure cases. If the host, is
|
|
205
182
|
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
206
183
|
* this host will be added end of the list of hosts on the next request.
|
|
207
184
|
*/
|
|
208
|
-
await hostsCache.set(
|
|
209
|
-
host,
|
|
210
|
-
createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down')
|
|
211
|
-
);
|
|
185
|
+
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
|
|
212
186
|
|
|
213
187
|
return retry(retryableHosts, getTimeout);
|
|
214
188
|
}
|
|
@@ -230,19 +204,14 @@ export function createTransporter({
|
|
|
230
204
|
* for the current context.
|
|
231
205
|
*/
|
|
232
206
|
const compatibleHosts = hosts.filter(
|
|
233
|
-
(host) =>
|
|
234
|
-
host.accept === 'readWrite' ||
|
|
235
|
-
(isRead ? host.accept === 'read' : host.accept === 'write')
|
|
207
|
+
(host) => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'),
|
|
236
208
|
);
|
|
237
209
|
const options = await createRetryableOptions(compatibleHosts);
|
|
238
210
|
|
|
239
211
|
return retry([...options.hosts].reverse(), options.getTimeout);
|
|
240
212
|
}
|
|
241
213
|
|
|
242
|
-
function createRequest<TResponse>(
|
|
243
|
-
request: Request,
|
|
244
|
-
requestOptions: RequestOptions = {}
|
|
245
|
-
): Promise<TResponse> {
|
|
214
|
+
function createRequest<TResponse>(request: Request, requestOptions: RequestOptions = {}): Promise<TResponse> {
|
|
246
215
|
/**
|
|
247
216
|
* A read request is either a `GET` request, or a request that we make
|
|
248
217
|
* via the `read` transporter (e.g. `search`).
|
|
@@ -315,10 +284,9 @@ export function createTransporter({
|
|
|
315
284
|
.set(key, createRetryableRequest())
|
|
316
285
|
.then(
|
|
317
286
|
(response) => Promise.all([requestsCache.delete(key), response]),
|
|
318
|
-
(err) =>
|
|
319
|
-
Promise.all([requestsCache.delete(key), Promise.reject(err)])
|
|
287
|
+
(err) => Promise.all([requestsCache.delete(key), Promise.reject(err)]),
|
|
320
288
|
)
|
|
321
|
-
.then(([_, response]) => response)
|
|
289
|
+
.then(([_, response]) => response),
|
|
322
290
|
);
|
|
323
291
|
},
|
|
324
292
|
{
|
|
@@ -328,7 +296,7 @@ export function createTransporter({
|
|
|
328
296
|
* to be used later.
|
|
329
297
|
*/
|
|
330
298
|
miss: (response) => responsesCache.set(key, response),
|
|
331
|
-
}
|
|
299
|
+
},
|
|
332
300
|
);
|
|
333
301
|
}
|
|
334
302
|
|
|
@@ -27,7 +27,7 @@ export class RetryError extends ErrorWithStackTrace {
|
|
|
27
27
|
super(
|
|
28
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
|
-
'RetryError'
|
|
30
|
+
'RetryError',
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -35,12 +35,7 @@ export class RetryError extends ErrorWithStackTrace {
|
|
|
35
35
|
export class ApiError extends ErrorWithStackTrace {
|
|
36
36
|
status: number;
|
|
37
37
|
|
|
38
|
-
constructor(
|
|
39
|
-
message: string,
|
|
40
|
-
status: number,
|
|
41
|
-
stackTrace: StackFrame[],
|
|
42
|
-
name = 'ApiError'
|
|
43
|
-
) {
|
|
38
|
+
constructor(message: string, status: number, stackTrace: StackFrame[], name = 'ApiError') {
|
|
44
39
|
super(message, stackTrace, name);
|
|
45
40
|
this.status = status;
|
|
46
41
|
}
|
|
@@ -75,12 +70,7 @@ export type DetailedError = {
|
|
|
75
70
|
export class DetailedApiError extends ApiError {
|
|
76
71
|
error: DetailedError;
|
|
77
72
|
|
|
78
|
-
constructor(
|
|
79
|
-
message: string,
|
|
80
|
-
status: number,
|
|
81
|
-
error: DetailedError,
|
|
82
|
-
stackTrace: StackFrame[]
|
|
83
|
-
) {
|
|
73
|
+
constructor(message: string, status: number, error: DetailedError, stackTrace: StackFrame[]) {
|
|
84
74
|
super(message, status, stackTrace, 'DetailedApiError');
|
|
85
75
|
this.error = error;
|
|
86
76
|
}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Headers,
|
|
3
|
-
Host,
|
|
4
|
-
QueryParameters,
|
|
5
|
-
Request,
|
|
6
|
-
RequestOptions,
|
|
7
|
-
Response,
|
|
8
|
-
StackFrame,
|
|
9
|
-
} from '../types';
|
|
1
|
+
import type { Headers, Host, QueryParameters, Request, RequestOptions, Response, StackFrame } from '../types';
|
|
10
2
|
|
|
11
3
|
import { ApiError, DeserializationError, DetailedApiError } from './errors';
|
|
12
4
|
|
|
@@ -24,11 +16,7 @@ export function shuffle<TData>(array: TData[]): TData[] {
|
|
|
24
16
|
return shuffledArray;
|
|
25
17
|
}
|
|
26
18
|
|
|
27
|
-
export function serializeUrl(
|
|
28
|
-
host: Host,
|
|
29
|
-
path: string,
|
|
30
|
-
queryParameters: QueryParameters
|
|
31
|
-
): string {
|
|
19
|
+
export function serializeUrl(host: Host, path: string, queryParameters: QueryParameters): string {
|
|
32
20
|
const queryParametersAsString = serializeQueryParameters(queryParameters);
|
|
33
21
|
let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${
|
|
34
22
|
path.charAt(0) === '/' ? path.substring(1) : path
|
|
@@ -50,26 +38,18 @@ export function serializeQueryParameters(parameters: QueryParameters): string {
|
|
|
50
38
|
`${key}=${encodeURIComponent(
|
|
51
39
|
Object.prototype.toString.call(parameters[key]) === '[object Array]'
|
|
52
40
|
? parameters[key].join(',')
|
|
53
|
-
: parameters[key]
|
|
54
|
-
).replaceAll('+', '%20')}
|
|
41
|
+
: parameters[key],
|
|
42
|
+
).replaceAll('+', '%20')}`,
|
|
55
43
|
)
|
|
56
44
|
.join('&');
|
|
57
45
|
}
|
|
58
46
|
|
|
59
|
-
export function serializeData(
|
|
60
|
-
request
|
|
61
|
-
requestOptions: RequestOptions
|
|
62
|
-
): string | undefined {
|
|
63
|
-
if (
|
|
64
|
-
request.method === 'GET' ||
|
|
65
|
-
(request.data === undefined && requestOptions.data === undefined)
|
|
66
|
-
) {
|
|
47
|
+
export function serializeData(request: Request, requestOptions: RequestOptions): string | undefined {
|
|
48
|
+
if (request.method === 'GET' || (request.data === undefined && requestOptions.data === undefined)) {
|
|
67
49
|
return undefined;
|
|
68
50
|
}
|
|
69
51
|
|
|
70
|
-
const data = Array.isArray(request.data)
|
|
71
|
-
? request.data
|
|
72
|
-
: { ...request.data, ...requestOptions.data };
|
|
52
|
+
const data = Array.isArray(request.data) ? request.data : { ...request.data, ...requestOptions.data };
|
|
73
53
|
|
|
74
54
|
return JSON.stringify(data);
|
|
75
55
|
}
|
|
@@ -77,7 +57,7 @@ export function serializeData(
|
|
|
77
57
|
export function serializeHeaders(
|
|
78
58
|
baseHeaders: Headers,
|
|
79
59
|
requestHeaders: Headers,
|
|
80
|
-
requestOptionsHeaders?: Headers
|
|
60
|
+
requestOptionsHeaders?: Headers,
|
|
81
61
|
): Headers {
|
|
82
62
|
const headers: Headers = {
|
|
83
63
|
Accept: 'application/json',
|
|
@@ -103,22 +83,14 @@ export function deserializeSuccess<TObject>(response: Response): TObject {
|
|
|
103
83
|
}
|
|
104
84
|
}
|
|
105
85
|
|
|
106
|
-
export function deserializeFailure(
|
|
107
|
-
{ content, status }: Response,
|
|
108
|
-
stackFrame: StackFrame[]
|
|
109
|
-
): Error {
|
|
86
|
+
export function deserializeFailure({ content, status }: Response, stackFrame: StackFrame[]): Error {
|
|
110
87
|
try {
|
|
111
88
|
const parsed = JSON.parse(content);
|
|
112
89
|
if ('error' in parsed) {
|
|
113
|
-
return new DetailedApiError(
|
|
114
|
-
parsed.message,
|
|
115
|
-
status,
|
|
116
|
-
parsed.error,
|
|
117
|
-
stackFrame
|
|
118
|
-
);
|
|
90
|
+
return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
|
|
119
91
|
}
|
|
120
92
|
return new ApiError(parsed.message, status, stackFrame);
|
|
121
|
-
} catch
|
|
93
|
+
} catch {
|
|
122
94
|
// ..
|
|
123
95
|
}
|
|
124
96
|
return new ApiError(content, status, stackFrame);
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import type { Response } from '../types';
|
|
2
2
|
|
|
3
|
-
export function isNetworkError({
|
|
4
|
-
isTimedOut,
|
|
5
|
-
status,
|
|
6
|
-
}: Omit<Response, 'content'>): boolean {
|
|
3
|
+
export function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean {
|
|
7
4
|
return !isTimedOut && ~~status === 0;
|
|
8
5
|
}
|
|
9
6
|
|
|
10
|
-
export function isRetryable({
|
|
11
|
-
isTimedOut,
|
|
12
|
-
status,
|
|
13
|
-
}: Omit<Response, 'content'>): boolean {
|
|
14
|
-
return (
|
|
15
|
-
isTimedOut ||
|
|
16
|
-
isNetworkError({ isTimedOut, status }) ||
|
|
17
|
-
(~~(status / 100) !== 2 && ~~(status / 100) !== 4)
|
|
18
|
-
);
|
|
7
|
+
export function isRetryable({ isTimedOut, status }: Omit<Response, 'content'>): boolean {
|
|
8
|
+
return isTimedOut || isNetworkError({ isTimedOut, status }) || (~~(status / 100) !== 2 && ~~(status / 100) !== 4);
|
|
19
9
|
}
|
|
20
10
|
|
|
21
11
|
export function isSuccess({ status }: Pick<Response, 'status'>): boolean {
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import type { Headers, StackFrame } from '../types';
|
|
2
2
|
|
|
3
|
-
export function stackTraceWithoutCredentials(
|
|
4
|
-
stackTrace
|
|
5
|
-
): StackFrame[] {
|
|
6
|
-
return stackTrace.map((stackFrame) =>
|
|
7
|
-
stackFrameWithoutCredentials(stackFrame)
|
|
8
|
-
);
|
|
3
|
+
export function stackTraceWithoutCredentials(stackTrace: StackFrame[]): StackFrame[] {
|
|
4
|
+
return stackTrace.map((stackFrame) => stackFrameWithoutCredentials(stackFrame));
|
|
9
5
|
}
|
|
10
6
|
|
|
11
|
-
export function stackFrameWithoutCredentials(
|
|
12
|
-
|
|
13
|
-
): StackFrame {
|
|
14
|
-
const modifiedHeaders: Headers = stackFrame.request.headers[
|
|
15
|
-
'x-algolia-api-key'
|
|
16
|
-
]
|
|
7
|
+
export function stackFrameWithoutCredentials(stackFrame: StackFrame): StackFrame {
|
|
8
|
+
const modifiedHeaders: Headers = stackFrame.request.headers['x-algolia-api-key']
|
|
17
9
|
? { 'x-algolia-api-key': '*****' }
|
|
18
10
|
: {};
|
|
19
11
|
|
package/src/types/cache.ts
CHANGED
|
@@ -5,16 +5,13 @@ export type Cache = {
|
|
|
5
5
|
get: <TValue>(
|
|
6
6
|
key: Record<string, any> | string,
|
|
7
7
|
defaultValue: () => Promise<TValue>,
|
|
8
|
-
events?: CacheEvents<TValue
|
|
8
|
+
events?: CacheEvents<TValue>,
|
|
9
9
|
) => Promise<TValue>;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Sets the given value with the given `key`.
|
|
13
13
|
*/
|
|
14
|
-
set: <TValue>(
|
|
15
|
-
key: Record<string, any> | string,
|
|
16
|
-
value: TValue
|
|
17
|
-
) => Promise<TValue>;
|
|
14
|
+
set: <TValue>(key: Record<string, any> | string, value: TValue) => Promise<TValue>;
|
|
18
15
|
|
|
19
16
|
/**
|
|
20
17
|
* Deletes the given `key`.
|
|
@@ -2,15 +2,9 @@ import type { AlgoliaAgentOptions, TransporterOptions } from './transporter';
|
|
|
2
2
|
|
|
3
3
|
export type AuthMode = 'WithinHeaders' | 'WithinQueryParameters';
|
|
4
4
|
|
|
5
|
-
type OverriddenTransporterOptions =
|
|
6
|
-
| 'baseHeaders'
|
|
7
|
-
| 'baseQueryParameters'
|
|
8
|
-
| 'hosts';
|
|
5
|
+
type OverriddenTransporterOptions = 'baseHeaders' | 'baseQueryParameters' | 'hosts';
|
|
9
6
|
|
|
10
|
-
export type CreateClientOptions = Omit<
|
|
11
|
-
TransporterOptions,
|
|
12
|
-
OverriddenTransporterOptions | 'algoliaAgent'
|
|
13
|
-
> &
|
|
7
|
+
export type CreateClientOptions = Omit<TransporterOptions, OverriddenTransporterOptions | 'algoliaAgent'> &
|
|
14
8
|
Partial<Pick<TransporterOptions, OverriddenTransporterOptions>> & {
|
|
15
9
|
appId: string;
|
|
16
10
|
apiKey: string;
|
|
@@ -18,6 +12,4 @@ export type CreateClientOptions = Omit<
|
|
|
18
12
|
algoliaAgents: AlgoliaAgentOptions[];
|
|
19
13
|
};
|
|
20
14
|
|
|
21
|
-
export type ClientOptions = Partial<
|
|
22
|
-
Omit<CreateClientOptions, 'apiKey' | 'appId'>
|
|
23
|
-
>;
|
|
15
|
+
export type ClientOptions = Partial<Omit<CreateClientOptions, 'apiKey' | 'appId'>>;
|
package/src/types/transporter.ts
CHANGED
|
@@ -146,8 +146,5 @@ export type Transporter = TransporterOptions & {
|
|
|
146
146
|
* Performs a request.
|
|
147
147
|
* The `baseRequest` and `baseRequestOptions` will be merged accordingly.
|
|
148
148
|
*/
|
|
149
|
-
request: <TResponse>(
|
|
150
|
-
baseRequest: Request,
|
|
151
|
-
baseRequestOptions?: RequestOptions
|
|
152
|
-
) => Promise<TResponse>;
|
|
149
|
+
request: <TResponse>(baseRequest: Request, baseRequestOptions?: RequestOptions) => Promise<TResponse>;
|
|
153
150
|
};
|