@algolia/client-common 5.0.0-alpha.8 → 5.0.0-alpha.81

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.
Files changed (44) hide show
  1. package/dist/{client-common.cjs.js → client-common.cjs} +140 -199
  2. package/dist/client-common.esm.node.js +140 -198
  3. package/dist/index.d.ts +9 -9
  4. package/dist/src/cache/createBrowserLocalStorageCache.d.ts +2 -2
  5. package/dist/src/cache/createFallbackableCache.d.ts +2 -2
  6. package/dist/src/cache/createMemoryCache.d.ts +2 -2
  7. package/dist/src/cache/createNullCache.d.ts +2 -2
  8. package/dist/src/cache/index.d.ts +4 -4
  9. package/dist/src/constants.d.ts +6 -6
  10. package/dist/src/createAlgoliaAgent.d.ts +2 -2
  11. package/dist/src/createAuth.d.ts +5 -5
  12. package/dist/src/createEchoRequester.d.ts +6 -6
  13. package/dist/src/createEchoRequester.d.ts.map +1 -1
  14. package/dist/src/createIterablePromise.d.ts +12 -12
  15. package/dist/src/getAlgoliaAgent.d.ts +7 -7
  16. package/dist/src/getAlgoliaAgent.d.ts.map +1 -1
  17. package/dist/src/transporter/createStatefulHost.d.ts +2 -2
  18. package/dist/src/transporter/createTransporter.d.ts +2 -2
  19. package/dist/src/transporter/createTransporter.d.ts.map +1 -1
  20. package/dist/src/transporter/errors.d.ts +37 -20
  21. package/dist/src/transporter/errors.d.ts.map +1 -1
  22. package/dist/src/transporter/helpers.d.ts +8 -8
  23. package/dist/src/transporter/helpers.d.ts.map +1 -1
  24. package/dist/src/transporter/index.d.ts +6 -6
  25. package/dist/src/transporter/responses.d.ts +4 -4
  26. package/dist/src/transporter/stackTrace.d.ts +3 -3
  27. package/dist/src/types/cache.d.ts +46 -46
  28. package/dist/src/types/cache.d.ts.map +1 -1
  29. package/dist/src/types/createClient.d.ts +11 -11
  30. package/dist/src/types/createClient.d.ts.map +1 -1
  31. package/dist/src/types/createIterablePromise.d.ts +35 -35
  32. package/dist/src/types/createIterablePromise.d.ts.map +1 -1
  33. package/dist/src/types/host.d.ts +32 -32
  34. package/dist/src/types/host.d.ts.map +1 -1
  35. package/dist/src/types/index.d.ts +6 -6
  36. package/dist/src/types/requester.d.ts +65 -65
  37. package/dist/src/types/requester.d.ts.map +1 -1
  38. package/dist/src/types/transporter.d.ts +127 -127
  39. package/dist/src/types/transporter.d.ts.map +1 -1
  40. package/package.json +9 -8
  41. package/src/createEchoRequester.ts +2 -2
  42. package/src/transporter/createTransporter.ts +4 -1
  43. package/src/transporter/errors.ts +38 -2
  44. package/src/transporter/helpers.ts +14 -6
@@ -1,66 +1,66 @@
1
- import type { Headers, QueryParameters } from './transporter';
2
- /**
3
- * The method of the request.
4
- */
5
- export declare type Method = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
6
- export declare type Request = {
7
- method: Method;
8
- /**
9
- * The path of the REST API to send the request to.
10
- */
11
- path: string;
12
- queryParameters: QueryParameters;
13
- data?: Array<Record<string, any>> | Record<string, any>;
14
- headers: Headers;
15
- /**
16
- * If the given request should persist on the cache. Keep in mind,
17
- * that some methods may have this option enabled by default.
18
- */
19
- cacheable?: boolean;
20
- /**
21
- * Some POST methods in the Algolia REST API uses the `read` transporter.
22
- * This information is defined at the spec level.
23
- */
24
- useReadTransporter?: boolean;
25
- };
26
- export declare type EndRequest = Pick<Request, 'headers' | 'method'> & {
27
- /**
28
- * The full URL of the REST API.
29
- */
30
- url: string;
31
- /**
32
- * The connection timeout, in milliseconds.
33
- */
34
- connectTimeout: number;
35
- /**
36
- * The response timeout, in milliseconds.
37
- */
38
- responseTimeout: number;
39
- data?: string;
40
- };
41
- export declare type Response = {
42
- /**
43
- * The body of the response.
44
- */
45
- content: string;
46
- /**
47
- * Whether the API call is timed out or not.
48
- */
49
- isTimedOut: boolean;
50
- /**
51
- * The HTTP status code of the response.
52
- */
53
- status: number;
54
- };
55
- export declare type Requester = {
56
- /**
57
- * Sends the given `request` to the server.
58
- */
59
- send: (request: EndRequest) => Promise<Response>;
60
- };
61
- export declare type EchoResponse = Omit<EndRequest, 'data'> & Pick<Request, 'data' | 'path'> & {
62
- host: string;
63
- algoliaAgent: string;
64
- searchParams?: Record<string, string>;
65
- };
1
+ import type { Headers, QueryParameters } from './transporter';
2
+ /**
3
+ * The method of the request.
4
+ */
5
+ export type Method = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
6
+ export type Request = {
7
+ method: Method;
8
+ /**
9
+ * The path of the REST API to send the request to.
10
+ */
11
+ path: string;
12
+ queryParameters: QueryParameters;
13
+ data?: Array<Record<string, any>> | Record<string, any>;
14
+ headers: Headers;
15
+ /**
16
+ * If the given request should persist on the cache. Keep in mind,
17
+ * that some methods may have this option enabled by default.
18
+ */
19
+ cacheable?: boolean;
20
+ /**
21
+ * Some POST methods in the Algolia REST API uses the `read` transporter.
22
+ * This information is defined at the spec level.
23
+ */
24
+ useReadTransporter?: boolean;
25
+ };
26
+ export type EndRequest = Pick<Request, 'headers' | 'method'> & {
27
+ /**
28
+ * The full URL of the REST API.
29
+ */
30
+ url: string;
31
+ /**
32
+ * The connection timeout, in milliseconds.
33
+ */
34
+ connectTimeout: number;
35
+ /**
36
+ * The response timeout, in milliseconds.
37
+ */
38
+ responseTimeout: number;
39
+ data?: string;
40
+ };
41
+ export type Response = {
42
+ /**
43
+ * The body of the response.
44
+ */
45
+ content: string;
46
+ /**
47
+ * Whether the API call is timed out or not.
48
+ */
49
+ isTimedOut: boolean;
50
+ /**
51
+ * The HTTP status code of the response.
52
+ */
53
+ status: number;
54
+ };
55
+ export type Requester = {
56
+ /**
57
+ * Sends the given `request` to the server.
58
+ */
59
+ send: (request: EndRequest) => Promise<Response>;
60
+ };
61
+ export type EchoResponse = Omit<EndRequest, 'data'> & Pick<Request, 'data' | 'path'> & {
62
+ host: string;
63
+ algoliaAgent: string;
64
+ searchParams?: Record<string, string>;
65
+ };
66
66
  //# sourceMappingURL=requester.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"requester.d.ts","sourceRo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MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB;;OAEG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GACjD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC,CAAC"}
@@ -1,128 +1,128 @@
1
- import type { Cache } from './cache';
2
- import type { Host } from './host';
3
- import type { Request, Requester, EndRequest, Response } from './requester';
4
- export declare type Headers = Record<string, string>;
5
- export declare type QueryParameters = Record<string, any>;
6
- export declare type RequestOptions = Pick<Request, 'cacheable'> & {
7
- /**
8
- * Custom timeout for the request. Note that, in normal situations
9
- * the given timeout will be applied. But the transporter layer may
10
- * increase this timeout if there is need for it.
11
- */
12
- timeout?: number;
13
- /**
14
- * Custom headers for the request. This headers are
15
- * going to be merged the transporter headers.
16
- */
17
- headers?: Headers;
18
- /**
19
- * Custom query parameters for the request. This query parameters are
20
- * going to be merged the transporter query parameters.
21
- */
22
- queryParameters?: QueryParameters;
23
- /**
24
- * Custom data for the request. This data is
25
- * going to be merged the transporter data.
26
- */
27
- data?: Array<Record<string, any>> | Record<string, any>;
28
- };
29
- export declare type StackFrame = {
30
- request: EndRequest;
31
- response: Response;
32
- host: Host;
33
- triesLeft: number;
34
- };
35
- export declare type AlgoliaAgentOptions = {
36
- /**
37
- * The segment. Usually the integration name.
38
- */
39
- segment: string;
40
- /**
41
- * The version. Usually the integration version.
42
- */
43
- version?: string;
44
- };
45
- export declare type AlgoliaAgent = {
46
- /**
47
- * The raw value of the user agent.
48
- */
49
- value: string;
50
- /**
51
- * Mutates the current user agent adding the given user agent options.
52
- */
53
- add: (options: AlgoliaAgentOptions) => AlgoliaAgent;
54
- };
55
- export declare type Timeouts = {
56
- /**
57
- * Timeout in milliseconds before the connection is established.
58
- */
59
- connect: number;
60
- /**
61
- * Timeout in milliseconds before reading the response on a read request.
62
- */
63
- read: number;
64
- /**
65
- * Timeout in milliseconds before reading the response on a write request.
66
- */
67
- write: number;
68
- };
69
- export declare type TransporterOptions = {
70
- /**
71
- * The cache of the hosts. Usually used to persist
72
- * the state of the host when its down.
73
- */
74
- hostsCache: Cache;
75
- /**
76
- * The underlying requester used. Should differ
77
- * depending of the environment where the client
78
- * will be used.
79
- */
80
- requester: Requester;
81
- /**
82
- * The cache of the requests. When requests are
83
- * `cacheable`, the returned promised persists
84
- * in this cache to shared in similar requests
85
- * before being resolved.
86
- */
87
- requestsCache: Cache;
88
- /**
89
- * The cache of the responses. When requests are
90
- * `cacheable`, the returned responses persists
91
- * in this cache to shared in similar requests.
92
- */
93
- responsesCache: Cache;
94
- /**
95
- * The timeouts used by the requester. The transporter
96
- * layer may increase this timeouts as defined on the
97
- * retry strategy.
98
- */
99
- timeouts: Timeouts;
100
- /**
101
- * The hosts used by the requester.
102
- */
103
- hosts: Host[];
104
- /**
105
- * The headers used by the requester. The transporter
106
- * layer may add some extra headers during the request
107
- * for the user agent, and others.
108
- */
109
- baseHeaders: Headers;
110
- /**
111
- * The query parameters used by the requester. The transporter
112
- * layer may add some extra headers during the request
113
- * for the user agent, and others.
114
- */
115
- baseQueryParameters: QueryParameters;
116
- /**
117
- * The user agent used. Sent on query parameters.
118
- */
119
- algoliaAgent: AlgoliaAgent;
120
- };
121
- export declare type Transporter = TransporterOptions & {
122
- /**
123
- * Performs a request.
124
- * The `baseRequest` and `baseRequestOptions` will be merged accordingly.
125
- */
126
- request: <TResponse>(baseRequest: Request, baseRequestOptions?: RequestOptions) => Promise<TResponse>;
127
- };
1
+ import type { Cache } from './cache';
2
+ import type { Host } from './host';
3
+ import type { Request, Requester, EndRequest, Response } from './requester';
4
+ export type Headers = Record<string, string>;
5
+ export type QueryParameters = Record<string, any>;
6
+ export type RequestOptions = Pick<Request, 'cacheable'> & {
7
+ /**
8
+ * Custom timeout for the request. Note that, in normal situations
9
+ * the given timeout will be applied. But the transporter layer may
10
+ * increase this timeout if there is need for it.
11
+ */
12
+ timeout?: number;
13
+ /**
14
+ * Custom headers for the request. This headers are
15
+ * going to be merged the transporter headers.
16
+ */
17
+ headers?: Headers;
18
+ /**
19
+ * Custom query parameters for the request. This query parameters are
20
+ * going to be merged the transporter query parameters.
21
+ */
22
+ queryParameters?: QueryParameters;
23
+ /**
24
+ * Custom data for the request. This data is
25
+ * going to be merged the transporter data.
26
+ */
27
+ data?: Array<Record<string, any>> | Record<string, any>;
28
+ };
29
+ export type StackFrame = {
30
+ request: EndRequest;
31
+ response: Response;
32
+ host: Host;
33
+ triesLeft: number;
34
+ };
35
+ export type AlgoliaAgentOptions = {
36
+ /**
37
+ * The segment. Usually the integration name.
38
+ */
39
+ segment: string;
40
+ /**
41
+ * The version. Usually the integration version.
42
+ */
43
+ version?: string;
44
+ };
45
+ export type AlgoliaAgent = {
46
+ /**
47
+ * The raw value of the user agent.
48
+ */
49
+ value: string;
50
+ /**
51
+ * Mutates the current user agent adding the given user agent options.
52
+ */
53
+ add: (options: AlgoliaAgentOptions) => AlgoliaAgent;
54
+ };
55
+ export type Timeouts = {
56
+ /**
57
+ * Timeout in milliseconds before the connection is established.
58
+ */
59
+ connect: number;
60
+ /**
61
+ * Timeout in milliseconds before reading the response on a read request.
62
+ */
63
+ read: number;
64
+ /**
65
+ * Timeout in milliseconds before reading the response on a write request.
66
+ */
67
+ write: number;
68
+ };
69
+ export type TransporterOptions = {
70
+ /**
71
+ * The cache of the hosts. Usually used to persist
72
+ * the state of the host when its down.
73
+ */
74
+ hostsCache: Cache;
75
+ /**
76
+ * The underlying requester used. Should differ
77
+ * depending of the environment where the client
78
+ * will be used.
79
+ */
80
+ requester: Requester;
81
+ /**
82
+ * The cache of the requests. When requests are
83
+ * `cacheable`, the returned promised persists
84
+ * in this cache to shared in similar requests
85
+ * before being resolved.
86
+ */
87
+ requestsCache: Cache;
88
+ /**
89
+ * The cache of the responses. When requests are
90
+ * `cacheable`, the returned responses persists
91
+ * in this cache to shared in similar requests.
92
+ */
93
+ responsesCache: Cache;
94
+ /**
95
+ * The timeouts used by the requester. The transporter
96
+ * layer may increase this timeouts as defined on the
97
+ * retry strategy.
98
+ */
99
+ timeouts: Timeouts;
100
+ /**
101
+ * The hosts used by the requester.
102
+ */
103
+ hosts: Host[];
104
+ /**
105
+ * The headers used by the requester. The transporter
106
+ * layer may add some extra headers during the request
107
+ * for the user agent, and others.
108
+ */
109
+ baseHeaders: Headers;
110
+ /**
111
+ * The query parameters used by the requester. The transporter
112
+ * layer may add some extra headers during the request
113
+ * for the user agent, and others.
114
+ */
115
+ baseQueryParameters: QueryParameters;
116
+ /**
117
+ * The user agent used. Sent on query parameters.
118
+ */
119
+ algoliaAgent: AlgoliaAgent;
120
+ };
121
+ export type Transporter = TransporterOptions & {
122
+ /**
123
+ * Performs a request.
124
+ * The `baseRequest` and `baseRequestOptions` will be merged accordingly.
125
+ */
126
+ request: <TResponse>(baseRequest: Request, baseRequestOptions?: RequestOptions) => Promise<TResponse>;
127
+ };
128
128
  //# sourceMappingURL=transporter.d.ts.map
@@ -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,oBAAY,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7C,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM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CAAC,CAAC;CACzB,CAAC"}
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@algolia/client-common",
3
- "version": "5.0.0-alpha.8",
3
+ "version": "5.0.0-alpha.81",
4
4
  "description": "Common package for the Algolia JavaScript API client.",
5
5
  "repository": "algolia/algoliasearch-client-javascript",
6
6
  "license": "MIT",
7
7
  "author": "Algolia",
8
- "main": "dist/client-common.cjs.js",
8
+ "type": "module",
9
+ "main": "dist/client-common.cjs",
9
10
  "module": "dist/client-common.esm.node.js",
10
11
  "types": "dist/index.d.ts",
11
12
  "files": [
@@ -19,12 +20,12 @@
19
20
  "test": "jest"
20
21
  },
21
22
  "devDependencies": {
22
- "@types/jest": "28.1.6",
23
- "@types/node": "16.11.47",
24
- "jest": "28.1.3",
25
- "jest-environment-jsdom": "28.1.3",
26
- "ts-jest": "28.0.7",
27
- "typescript": "4.7.4"
23
+ "@types/jest": "29.5.4",
24
+ "@types/node": "18.17.12",
25
+ "jest": "29.6.4",
26
+ "jest-environment-jsdom": "29.6.4",
27
+ "ts-jest": "29.1.1",
28
+ "typescript": "5.2.2"
28
29
  },
29
30
  "engines": {
30
31
  "node": ">= 14.0.0"
@@ -11,7 +11,7 @@ function getUrlParams({
11
11
  pathname,
12
12
  }: URL): Pick<EchoResponse, 'algoliaAgent' | 'host' | 'path' | 'searchParams'> {
13
13
  const algoliaAgent = urlSearchParams.get('x-algolia-agent') || '';
14
- const searchParams = {};
14
+ const searchParams: Record<string, string> = {};
15
15
 
16
16
  for (const [k, v] of urlSearchParams) {
17
17
  if (k === 'x-algolia-agent') {
@@ -44,7 +44,7 @@ export function createEchoRequester({
44
44
  data: request.data ? JSON.parse(request.data) : undefined,
45
45
  path,
46
46
  host,
47
- algoliaAgent: encodeURI(algoliaAgent),
47
+ algoliaAgent: encodeURIComponent(algoliaAgent),
48
48
  searchParams,
49
49
  };
50
50
 
@@ -110,12 +110,15 @@ export function createTransporter({
110
110
  : {};
111
111
 
112
112
  const queryParameters: QueryParameters = {
113
- 'x-algolia-agent': algoliaAgent.value,
114
113
  ...baseQueryParameters,
115
114
  ...request.queryParameters,
116
115
  ...dataQueryParameters,
117
116
  };
118
117
 
118
+ if (algoliaAgent.value) {
119
+ queryParameters['x-algolia-agent'] = algoliaAgent.value;
120
+ }
121
+
119
122
  if (requestOptions && requestOptions.queryParameters) {
120
123
  for (const key of Object.keys(requestOptions.queryParameters)) {
121
124
  // We want to keep `undefined` and `null` values,
@@ -35,8 +35,13 @@ export class RetryError extends ErrorWithStackTrace {
35
35
  export class ApiError extends ErrorWithStackTrace {
36
36
  status: number;
37
37
 
38
- constructor(message: string, status: number, stackTrace: StackFrame[]) {
39
- super(message, stackTrace, 'ApiError');
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
- message = JSON.parse(content).message;
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(message, status, stackFrame);
126
+ return new ApiError(content, status, stackFrame);
119
127
  }