@algolia/client-common 5.0.0-alpha.10 → 5.0.0-alpha.100
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.js → client-common.cjs} +168 -205
- package/dist/client-common.esm.node.js +168 -204
- package/dist/index.d.ts +9 -9
- package/dist/src/cache/createBrowserLocalStorageCache.d.ts +2 -2
- package/dist/src/cache/createBrowserLocalStorageCache.d.ts.map +1 -1
- package/dist/src/cache/createFallbackableCache.d.ts +2 -2
- package/dist/src/cache/createMemoryCache.d.ts +2 -2
- package/dist/src/cache/createNullCache.d.ts +2 -2
- package/dist/src/cache/index.d.ts +4 -4
- package/dist/src/constants.d.ts +6 -6
- package/dist/src/createAlgoliaAgent.d.ts +2 -2
- package/dist/src/createAuth.d.ts +5 -5
- package/dist/src/createEchoRequester.d.ts +6 -6
- package/dist/src/createEchoRequester.d.ts.map +1 -1
- package/dist/src/createIterablePromise.d.ts +12 -12
- package/dist/src/getAlgoliaAgent.d.ts +7 -7
- package/dist/src/getAlgoliaAgent.d.ts.map +1 -1
- package/dist/src/transporter/createStatefulHost.d.ts +2 -2
- package/dist/src/transporter/createTransporter.d.ts +2 -2
- package/dist/src/transporter/errors.d.ts +37 -20
- package/dist/src/transporter/errors.d.ts.map +1 -1
- package/dist/src/transporter/helpers.d.ts +8 -8
- package/dist/src/transporter/helpers.d.ts.map +1 -1
- package/dist/src/transporter/index.d.ts +6 -6
- package/dist/src/transporter/responses.d.ts +4 -4
- package/dist/src/transporter/stackTrace.d.ts +3 -3
- package/dist/src/types/cache.d.ts +60 -46
- package/dist/src/types/cache.d.ts.map +1 -1
- package/dist/src/types/createClient.d.ts +11 -11
- package/dist/src/types/createClient.d.ts.map +1 -1
- package/dist/src/types/createIterablePromise.d.ts +35 -35
- package/dist/src/types/createIterablePromise.d.ts.map +1 -1
- package/dist/src/types/host.d.ts +32 -32
- package/dist/src/types/host.d.ts.map +1 -1
- package/dist/src/types/index.d.ts +6 -6
- package/dist/src/types/requester.d.ts +65 -65
- package/dist/src/types/requester.d.ts.map +1 -1
- package/dist/src/types/transporter.d.ts +127 -127
- package/dist/src/types/transporter.d.ts.map +1 -1
- package/package.json +11 -8
- package/src/__tests__/cache/browser-local-storage-cache.test.ts +61 -9
- package/src/cache/createBrowserLocalStorageCache.ts +55 -6
- package/src/createEchoRequester.ts +2 -2
- package/src/transporter/errors.ts +39 -3
- package/src/transporter/helpers.ts +14 -6
- package/src/types/cache.ts +17 -0
|
@@ -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,
|
|
28
|
+
'Unreachable hosts - your application id may be incorrect. If the error persists, please create a ticket at https://support.algolia.com/ sharing steps we can use to reproduce the issue.',
|
|
29
29
|
stackTrace,
|
|
30
30
|
'RetryError'
|
|
31
31
|
);
|
|
@@ -35,8 +35,13 @@ export class RetryError extends ErrorWithStackTrace {
|
|
|
35
35
|
export class ApiError extends ErrorWithStackTrace {
|
|
36
36
|
status: number;
|
|
37
37
|
|
|
38
|
-
constructor(
|
|
39
|
-
|
|
38
|
+
constructor(
|
|
39
|
+
message: string,
|
|
40
|
+
status: number,
|
|
41
|
+
stackTrace: StackFrame[],
|
|
42
|
+
name = 'ApiError'
|
|
43
|
+
) {
|
|
44
|
+
super(message, stackTrace, name);
|
|
40
45
|
this.status = status;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -49,3 +54,34 @@ export class DeserializationError extends AlgoliaError {
|
|
|
49
54
|
this.response = response;
|
|
50
55
|
}
|
|
51
56
|
}
|
|
57
|
+
|
|
58
|
+
export type DetailedErrorWithMessage = {
|
|
59
|
+
message: string;
|
|
60
|
+
label: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type DetailedErrorWithTypeID = {
|
|
64
|
+
id: string;
|
|
65
|
+
type: string;
|
|
66
|
+
name?: string;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type DetailedError = {
|
|
70
|
+
code: string;
|
|
71
|
+
details?: DetailedErrorWithMessage[] | DetailedErrorWithTypeID[];
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.
|
|
75
|
+
export class DetailedApiError extends ApiError {
|
|
76
|
+
error: DetailedError;
|
|
77
|
+
|
|
78
|
+
constructor(
|
|
79
|
+
message: string,
|
|
80
|
+
status: number,
|
|
81
|
+
error: DetailedError,
|
|
82
|
+
stackTrace: StackFrame[]
|
|
83
|
+
) {
|
|
84
|
+
super(message, status, stackTrace, 'DetailedApiError');
|
|
85
|
+
this.error = error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
StackFrame,
|
|
9
9
|
} from '../types';
|
|
10
10
|
|
|
11
|
-
import { ApiError, DeserializationError } from './errors';
|
|
11
|
+
import { ApiError, DeserializationError, DetailedApiError } from './errors';
|
|
12
12
|
|
|
13
13
|
export function shuffle<TData>(array: TData[]): TData[] {
|
|
14
14
|
const shuffledArray = array;
|
|
@@ -49,11 +49,11 @@ export function serializeQueryParameters(parameters: QueryParameters): string {
|
|
|
49
49
|
return Object.keys(parameters)
|
|
50
50
|
.map(
|
|
51
51
|
(key) =>
|
|
52
|
-
`${key}=${
|
|
52
|
+
`${key}=${encodeURIComponent(
|
|
53
53
|
isObjectOrArray(parameters[key])
|
|
54
54
|
? JSON.stringify(parameters[key])
|
|
55
55
|
: parameters[key]
|
|
56
|
-
}`
|
|
56
|
+
)}`
|
|
57
57
|
)
|
|
58
58
|
.join('&');
|
|
59
59
|
}
|
|
@@ -109,11 +109,19 @@ export function deserializeFailure(
|
|
|
109
109
|
{ content, status }: Response,
|
|
110
110
|
stackFrame: StackFrame[]
|
|
111
111
|
): Error {
|
|
112
|
-
let message = content;
|
|
113
112
|
try {
|
|
114
|
-
|
|
113
|
+
const parsed = JSON.parse(content);
|
|
114
|
+
if ('error' in parsed) {
|
|
115
|
+
return new DetailedApiError(
|
|
116
|
+
parsed.message,
|
|
117
|
+
status,
|
|
118
|
+
parsed.error,
|
|
119
|
+
stackFrame
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return new ApiError(parsed.message, status, stackFrame);
|
|
115
123
|
} catch (e) {
|
|
116
124
|
// ..
|
|
117
125
|
}
|
|
118
|
-
return new ApiError(
|
|
126
|
+
return new ApiError(content, status, stackFrame);
|
|
119
127
|
}
|
package/src/types/cache.ts
CHANGED
|
@@ -47,12 +47,29 @@ export type BrowserLocalStorageOptions = {
|
|
|
47
47
|
*/
|
|
48
48
|
key: string;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The time to live for each cached item in seconds.
|
|
52
|
+
*/
|
|
53
|
+
timeToLive?: number;
|
|
54
|
+
|
|
50
55
|
/**
|
|
51
56
|
* The native local storage implementation.
|
|
52
57
|
*/
|
|
53
58
|
localStorage?: Storage;
|
|
54
59
|
};
|
|
55
60
|
|
|
61
|
+
export type BrowserLocalStorageCacheItem = {
|
|
62
|
+
/**
|
|
63
|
+
* The cache item creation timestamp.
|
|
64
|
+
*/
|
|
65
|
+
timestamp: number;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The cache item value.
|
|
69
|
+
*/
|
|
70
|
+
value: any;
|
|
71
|
+
};
|
|
72
|
+
|
|
56
73
|
export type FallbackableCacheOptions = {
|
|
57
74
|
/**
|
|
58
75
|
* List of caches order by priority.
|