@empathyco/x-adapter 8.1.0-alpha.7 → 8.1.0-alpha.9

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.
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchHttpClient = void 0;
3
+ exports.fetchHttpClient = exports.fetchRawHttpClient = void 0;
4
4
  const x_utils_1 = require("@empathyco/x-utils");
5
5
  const utils_1 = require("./utils");
6
6
  /**
7
- * The `fetchHttpClient()` function is a http client implementation using the `fetch` WebAPI.
7
+ * The `fetchRawHttpClient()` function is a http client implementation using the `fetch` WebAPI.
8
+ *
9
+ * @remarks This fucntion will replace the current `fetchHttpClient` in a possible future breaking change.
8
10
  *
9
11
  * @param endpoint - The endpoint to make the request to.
10
12
  * @param options - The request options.
@@ -19,7 +21,7 @@ const utils_1 = require("./utils");
19
21
  *
20
22
  * @public
21
23
  */
22
- const fetchHttpClient = async (endpoint, { id = endpoint, cancelable = true, parameters = {}, properties, sendParamsInBody = false, sendEmptyParams = false, } = {}) => {
24
+ const fetchRawHttpClient = async (endpoint, { id = endpoint, cancelable = true, parameters = {}, properties, sendParamsInBody = false, sendEmptyParams = false, } = {}) => {
23
25
  const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {};
24
26
  if (!sendEmptyParams) {
25
27
  parameters = (0, x_utils_1.cleanEmpty)(parameters);
@@ -31,8 +33,21 @@ const fetchHttpClient = async (endpoint, { id = endpoint, cancelable = true, par
31
33
  ...properties,
32
34
  ...bodyParameters,
33
35
  ...signal,
34
- }).then(utils_1.toJson);
36
+ });
35
37
  };
38
+ exports.fetchRawHttpClient = fetchRawHttpClient;
39
+ /**
40
+ * The `fetchHttpClient()` function is wrapper of `fetchRawHttpClient()` function that parses
41
+ * the response with `toJson` function.
42
+ *
43
+ * @param endpoint - The endpoint to make the request to.
44
+ * @param options - The request options.
45
+ *
46
+ * @returns A `Promise` object.
47
+ *
48
+ * @public
49
+ */
50
+ const fetchHttpClient = async (endpoint, options = {}) => (0, exports.fetchRawHttpClient)(endpoint, options).then(utils_1.toJson);
36
51
  exports.fetchHttpClient = fetchHttpClient;
37
52
  /**
38
53
  * Dictionary with the request id as key and an `AbortController` as value.
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":";;;AAEA,gDAA2D;AAC3D,mCAA0C;AAE1C;;;;;;;;;;;;;;;GAeG;AACI,MAAM,eAAe,GAAe,KAAK,EAC9C,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,UAAU,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IACD,MAAM,cAAc,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,gBAAQ,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IAC5E,MAAM,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnF,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,GAAG,UAAU;QACb,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC,CAAC,IAAI,CAAC,cAAM,CAAC,CAAA;AACjB,CAAC,CAAA;AAxBY,QAAA,eAAe,mBAwB3B;AAED;;GAEG;AACH,MAAM,uBAAuB,GAAgC,EAAE,CAAA;AAE/D;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,EAAU;;IAC3C,MAAA,uBAAuB,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA;IACpC,uBAAuB,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,CAAA;IACnD,OAAO,uBAAuB,CAAC,EAAE,CAAC,CAAC,MAAM,CAAA;AAC3C,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport type { HttpClient } from './types'\nimport { cleanEmpty, flatObject } from '@empathyco/x-utils'\nimport { buildUrl, toJson } from './utils'\n\n/**\n * The `fetchHttpClient()` function is a http client implementation using the `fetch` WebAPI.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n * @param options.cancelable - Cancelable option.\n * @param options.id - ID option.\n * @param options.parameters - Parameters option.\n * @param options.properties - Properties option.\n * @param options.sendEmptyParams - SendEmptyParams option.\n * @param options.sendParamsInBody - SendParamsInBody option.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchHttpClient: HttpClient = async (\n endpoint,\n {\n id = endpoint,\n cancelable = true,\n parameters = {},\n properties,\n sendParamsInBody = false,\n sendEmptyParams = false,\n } = {},\n) => {\n const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {}\n if (!sendEmptyParams) {\n parameters = cleanEmpty(parameters)\n }\n const flatParameters = flatObject(parameters)\n const url = sendParamsInBody ? endpoint : buildUrl(endpoint, flatParameters)\n const bodyParameters = sendParamsInBody ? { body: JSON.stringify(parameters) } : {}\n\n return fetch(url, {\n ...properties,\n ...bodyParameters,\n ...signal,\n }).then(toJson)\n}\n\n/**\n * Dictionary with the request id as key and an `AbortController` as value.\n */\nconst requestAbortControllers: Dictionary<AbortController> = {}\n\n/**\n * Function that cancels previous request with the same `id` and returns a new `AbortSignal` for\n * the new request.\n *\n * @param id - The identifier of the request to cancel and create a new `AbortSignal`.\n *\n * @returns The new `AbortSignal`.\n */\nfunction abortAndGetNewAbortSignal(id: string): AbortSignal {\n requestAbortControllers[id]?.abort()\n requestAbortControllers[id] = new AbortController()\n return requestAbortControllers[id].signal\n}\n"]}
1
+ {"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":";;;AAEA,gDAA2D;AAC3D,mCAA0C;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACI,MAAM,kBAAkB,GAAe,KAAK,EACjD,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,UAAU,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IACD,MAAM,cAAc,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,gBAAQ,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IAC5E,MAAM,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnF,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,GAAG,UAAU;QACb,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC,CAAA;AACJ,CAAC,CAAA;AAxBY,QAAA,kBAAkB,sBAwB9B;AAED;;;;;;;;;;GAUG;AACI,MAAM,eAAe,GAAe,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAC1E,IAAA,0BAAkB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,cAAM,CAAC,CAAA;AADvC,QAAA,eAAe,mBACwB;AAEpD;;GAEG;AACH,MAAM,uBAAuB,GAAgC,EAAE,CAAA;AAE/D;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,EAAU;;IAC3C,MAAA,uBAAuB,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA;IACpC,uBAAuB,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,CAAA;IACnD,OAAO,uBAAuB,CAAC,EAAE,CAAC,CAAC,MAAM,CAAA;AAC3C,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport type { HttpClient } from './types'\nimport { cleanEmpty, flatObject } from '@empathyco/x-utils'\nimport { buildUrl, toJson } from './utils'\n\n/**\n * The `fetchRawHttpClient()` function is a http client implementation using the `fetch` WebAPI.\n *\n * @remarks This fucntion will replace the current `fetchHttpClient` in a possible future breaking change.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n * @param options.cancelable - Cancelable option.\n * @param options.id - ID option.\n * @param options.parameters - Parameters option.\n * @param options.properties - Properties option.\n * @param options.sendEmptyParams - SendEmptyParams option.\n * @param options.sendParamsInBody - SendParamsInBody option.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchRawHttpClient: HttpClient = async (\n endpoint,\n {\n id = endpoint,\n cancelable = true,\n parameters = {},\n properties,\n sendParamsInBody = false,\n sendEmptyParams = false,\n } = {},\n) => {\n const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {}\n if (!sendEmptyParams) {\n parameters = cleanEmpty(parameters)\n }\n const flatParameters = flatObject(parameters)\n const url = sendParamsInBody ? endpoint : buildUrl(endpoint, flatParameters)\n const bodyParameters = sendParamsInBody ? { body: JSON.stringify(parameters) } : {}\n\n return fetch(url, {\n ...properties,\n ...bodyParameters,\n ...signal,\n })\n}\n\n/**\n * The `fetchHttpClient()` function is wrapper of `fetchRawHttpClient()` function that parses\n * the response with `toJson` function.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchHttpClient: HttpClient = async (endpoint, options = {}) =>\n fetchRawHttpClient(endpoint, options).then(toJson)\n\n/**\n * Dictionary with the request id as key and an `AbortController` as value.\n */\nconst requestAbortControllers: Dictionary<AbortController> = {}\n\n/**\n * Function that cancels previous request with the same `id` and returns a new `AbortSignal` for\n * the new request.\n *\n * @param id - The identifier of the request to cancel and create a new `AbortSignal`.\n *\n * @returns The new `AbortSignal`.\n */\nfunction abortAndGetNewAbortSignal(id: string): AbortSignal {\n requestAbortControllers[id]?.abort()\n requestAbortControllers[id] = new AbortController()\n return requestAbortControllers[id].signal\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/http-clients/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\n\n/**\n * Makes a request to a backend API using the given parameters.\n *\n * @param endpoint - The endpoint to use.\n * @param options - Additional options to make the request with.\n * @returns A promise wrapped object containing the response.\n * @public\n */\nexport type HttpClient = <Response = unknown>(\n endpoint: string,\n options?: Omit<RequestOptions, 'endpoint'>,\n) => Promise<Readonly<Response>>\n\n/**\n * A record of options to make the request with.\n *\n * @public\n */\nexport interface RequestOptions {\n /**\n * A unique identifier for this request. Can be used to abort requests with same id.\n */\n id?: string\n /**\n * True if the request can be cancelled.\n */\n cancelable?: boolean\n /**\n * A flag to send parameters in the body if true or in the url QueryString if false.\n */\n sendParamsInBody?: boolean\n /**\n * A flag to always send the parameters even if their values are empty.\n */\n sendEmptyParams?: boolean\n /**\n * A list of parameters to send to the API.\n */\n parameters?: Dictionary<unknown>\n /**\n * The RequestInit object to create the request with.\n */\n properties?: RequestInit\n /**\n * The base endpoint that the request should use.\n */\n endpoint?: string\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/http-clients/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\n\n/**\n * Makes a request to a backend API using the given parameters.\n *\n * @param endpoint - The endpoint to use.\n * @param options - Additional options to make the request with.\n * @returns A promise wrapped object containing the response.\n * @public\n */\nexport type HttpClient = (\n endpoint: string,\n options?: Omit<RequestOptions, 'endpoint'>,\n) => Promise<any>\n\n/**\n * A record of options to make the request with.\n *\n * @public\n */\nexport interface RequestOptions {\n /**\n * A unique identifier for this request. Can be used to abort requests with same id.\n */\n id?: string\n /**\n * True if the request can be cancelled.\n */\n cancelable?: boolean\n /**\n * A flag to send parameters in the body if true or in the url QueryString if false.\n */\n sendParamsInBody?: boolean\n /**\n * A flag to always send the parameters even if their values are empty.\n */\n sendEmptyParams?: boolean\n /**\n * A list of parameters to send to the API.\n */\n parameters?: Dictionary<unknown>\n /**\n * The RequestInit object to create the request with.\n */\n properties?: RequestInit\n /**\n * The base endpoint that the request should use.\n */\n endpoint?: string\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import { cleanEmpty, flatObject } from '@empathyco/x-utils';
2
2
  import { buildUrl, toJson } from './utils';
3
3
  /**
4
- * The `fetchHttpClient()` function is a http client implementation using the `fetch` WebAPI.
4
+ * The `fetchRawHttpClient()` function is a http client implementation using the `fetch` WebAPI.
5
+ *
6
+ * @remarks This fucntion will replace the current `fetchHttpClient` in a possible future breaking change.
5
7
  *
6
8
  * @param endpoint - The endpoint to make the request to.
7
9
  * @param options - The request options.
@@ -16,7 +18,7 @@ import { buildUrl, toJson } from './utils';
16
18
  *
17
19
  * @public
18
20
  */
19
- export const fetchHttpClient = async (endpoint, { id = endpoint, cancelable = true, parameters = {}, properties, sendParamsInBody = false, sendEmptyParams = false, } = {}) => {
21
+ export const fetchRawHttpClient = async (endpoint, { id = endpoint, cancelable = true, parameters = {}, properties, sendParamsInBody = false, sendEmptyParams = false, } = {}) => {
20
22
  const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {};
21
23
  if (!sendEmptyParams) {
22
24
  parameters = cleanEmpty(parameters);
@@ -28,8 +30,20 @@ export const fetchHttpClient = async (endpoint, { id = endpoint, cancelable = tr
28
30
  ...properties,
29
31
  ...bodyParameters,
30
32
  ...signal,
31
- }).then(toJson);
33
+ });
32
34
  };
35
+ /**
36
+ * The `fetchHttpClient()` function is wrapper of `fetchRawHttpClient()` function that parses
37
+ * the response with `toJson` function.
38
+ *
39
+ * @param endpoint - The endpoint to make the request to.
40
+ * @param options - The request options.
41
+ *
42
+ * @returns A `Promise` object.
43
+ *
44
+ * @public
45
+ */
46
+ export const fetchHttpClient = async (endpoint, options = {}) => fetchRawHttpClient(endpoint, options).then(toJson);
33
47
  /**
34
48
  * Dictionary with the request id as key and an `AbortController` as value.
35
49
  */
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,eAAe,GAAe,KAAK,EAC9C,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IACD,MAAM,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IAC5E,MAAM,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnF,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,GAAG,UAAU;QACb,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AACjB,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,uBAAuB,GAAgC,EAAE,CAAA;AAE/D;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,EAAU;;IAC3C,MAAA,uBAAuB,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA;IACpC,uBAAuB,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,CAAA;IACnD,OAAO,uBAAuB,CAAC,EAAE,CAAC,CAAC,MAAM,CAAA;AAC3C,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport type { HttpClient } from './types'\nimport { cleanEmpty, flatObject } from '@empathyco/x-utils'\nimport { buildUrl, toJson } from './utils'\n\n/**\n * The `fetchHttpClient()` function is a http client implementation using the `fetch` WebAPI.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n * @param options.cancelable - Cancelable option.\n * @param options.id - ID option.\n * @param options.parameters - Parameters option.\n * @param options.properties - Properties option.\n * @param options.sendEmptyParams - SendEmptyParams option.\n * @param options.sendParamsInBody - SendParamsInBody option.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchHttpClient: HttpClient = async (\n endpoint,\n {\n id = endpoint,\n cancelable = true,\n parameters = {},\n properties,\n sendParamsInBody = false,\n sendEmptyParams = false,\n } = {},\n) => {\n const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {}\n if (!sendEmptyParams) {\n parameters = cleanEmpty(parameters)\n }\n const flatParameters = flatObject(parameters)\n const url = sendParamsInBody ? endpoint : buildUrl(endpoint, flatParameters)\n const bodyParameters = sendParamsInBody ? { body: JSON.stringify(parameters) } : {}\n\n return fetch(url, {\n ...properties,\n ...bodyParameters,\n ...signal,\n }).then(toJson)\n}\n\n/**\n * Dictionary with the request id as key and an `AbortController` as value.\n */\nconst requestAbortControllers: Dictionary<AbortController> = {}\n\n/**\n * Function that cancels previous request with the same `id` and returns a new `AbortSignal` for\n * the new request.\n *\n * @param id - The identifier of the request to cancel and create a new `AbortSignal`.\n *\n * @returns The new `AbortSignal`.\n */\nfunction abortAndGetNewAbortSignal(id: string): AbortSignal {\n requestAbortControllers[id]?.abort()\n requestAbortControllers[id] = new AbortController()\n return requestAbortControllers[id].signal\n}\n"]}
1
+ {"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAe,KAAK,EACjD,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IACD,MAAM,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IAC5E,MAAM,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnF,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,GAAG,UAAU;QACb,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAe,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAC1E,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAEpD;;GAEG;AACH,MAAM,uBAAuB,GAAgC,EAAE,CAAA;AAE/D;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,EAAU;;IAC3C,MAAA,uBAAuB,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA;IACpC,uBAAuB,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,CAAA;IACnD,OAAO,uBAAuB,CAAC,EAAE,CAAC,CAAC,MAAM,CAAA;AAC3C,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport type { HttpClient } from './types'\nimport { cleanEmpty, flatObject } from '@empathyco/x-utils'\nimport { buildUrl, toJson } from './utils'\n\n/**\n * The `fetchRawHttpClient()` function is a http client implementation using the `fetch` WebAPI.\n *\n * @remarks This fucntion will replace the current `fetchHttpClient` in a possible future breaking change.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n * @param options.cancelable - Cancelable option.\n * @param options.id - ID option.\n * @param options.parameters - Parameters option.\n * @param options.properties - Properties option.\n * @param options.sendEmptyParams - SendEmptyParams option.\n * @param options.sendParamsInBody - SendParamsInBody option.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchRawHttpClient: HttpClient = async (\n endpoint,\n {\n id = endpoint,\n cancelable = true,\n parameters = {},\n properties,\n sendParamsInBody = false,\n sendEmptyParams = false,\n } = {},\n) => {\n const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {}\n if (!sendEmptyParams) {\n parameters = cleanEmpty(parameters)\n }\n const flatParameters = flatObject(parameters)\n const url = sendParamsInBody ? endpoint : buildUrl(endpoint, flatParameters)\n const bodyParameters = sendParamsInBody ? { body: JSON.stringify(parameters) } : {}\n\n return fetch(url, {\n ...properties,\n ...bodyParameters,\n ...signal,\n })\n}\n\n/**\n * The `fetchHttpClient()` function is wrapper of `fetchRawHttpClient()` function that parses\n * the response with `toJson` function.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchHttpClient: HttpClient = async (endpoint, options = {}) =>\n fetchRawHttpClient(endpoint, options).then(toJson)\n\n/**\n * Dictionary with the request id as key and an `AbortController` as value.\n */\nconst requestAbortControllers: Dictionary<AbortController> = {}\n\n/**\n * Function that cancels previous request with the same `id` and returns a new `AbortSignal` for\n * the new request.\n *\n * @param id - The identifier of the request to cancel and create a new `AbortSignal`.\n *\n * @returns The new `AbortSignal`.\n */\nfunction abortAndGetNewAbortSignal(id: string): AbortSignal {\n requestAbortControllers[id]?.abort()\n requestAbortControllers[id] = new AbortController()\n return requestAbortControllers[id].signal\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/http-clients/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\n\n/**\n * Makes a request to a backend API using the given parameters.\n *\n * @param endpoint - The endpoint to use.\n * @param options - Additional options to make the request with.\n * @returns A promise wrapped object containing the response.\n * @public\n */\nexport type HttpClient = <Response = unknown>(\n endpoint: string,\n options?: Omit<RequestOptions, 'endpoint'>,\n) => Promise<Readonly<Response>>\n\n/**\n * A record of options to make the request with.\n *\n * @public\n */\nexport interface RequestOptions {\n /**\n * A unique identifier for this request. Can be used to abort requests with same id.\n */\n id?: string\n /**\n * True if the request can be cancelled.\n */\n cancelable?: boolean\n /**\n * A flag to send parameters in the body if true or in the url QueryString if false.\n */\n sendParamsInBody?: boolean\n /**\n * A flag to always send the parameters even if their values are empty.\n */\n sendEmptyParams?: boolean\n /**\n * A list of parameters to send to the API.\n */\n parameters?: Dictionary<unknown>\n /**\n * The RequestInit object to create the request with.\n */\n properties?: RequestInit\n /**\n * The base endpoint that the request should use.\n */\n endpoint?: string\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/http-clients/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\n\n/**\n * Makes a request to a backend API using the given parameters.\n *\n * @param endpoint - The endpoint to use.\n * @param options - Additional options to make the request with.\n * @returns A promise wrapped object containing the response.\n * @public\n */\nexport type HttpClient = (\n endpoint: string,\n options?: Omit<RequestOptions, 'endpoint'>,\n) => Promise<any>\n\n/**\n * A record of options to make the request with.\n *\n * @public\n */\nexport interface RequestOptions {\n /**\n * A unique identifier for this request. Can be used to abort requests with same id.\n */\n id?: string\n /**\n * True if the request can be cancelled.\n */\n cancelable?: boolean\n /**\n * A flag to send parameters in the body if true or in the url QueryString if false.\n */\n sendParamsInBody?: boolean\n /**\n * A flag to always send the parameters even if their values are empty.\n */\n sendEmptyParams?: boolean\n /**\n * A list of parameters to send to the API.\n */\n parameters?: Dictionary<unknown>\n /**\n * The RequestInit object to create the request with.\n */\n properties?: RequestInit\n /**\n * The base endpoint that the request should use.\n */\n endpoint?: string\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  import type { HttpClient } from './types';
2
2
  /**
3
- * The `fetchHttpClient()` function is a http client implementation using the `fetch` WebAPI.
3
+ * The `fetchRawHttpClient()` function is a http client implementation using the `fetch` WebAPI.
4
+ *
5
+ * @remarks This fucntion will replace the current `fetchHttpClient` in a possible future breaking change.
4
6
  *
5
7
  * @param endpoint - The endpoint to make the request to.
6
8
  * @param options - The request options.
@@ -15,4 +17,16 @@ import type { HttpClient } from './types';
15
17
  *
16
18
  * @public
17
19
  */
20
+ export declare const fetchRawHttpClient: HttpClient;
21
+ /**
22
+ * The `fetchHttpClient()` function is wrapper of `fetchRawHttpClient()` function that parses
23
+ * the response with `toJson` function.
24
+ *
25
+ * @param endpoint - The endpoint to make the request to.
26
+ * @param options - The request options.
27
+ *
28
+ * @returns A `Promise` object.
29
+ *
30
+ * @public
31
+ */
18
32
  export declare const fetchHttpClient: HttpClient;
@@ -7,7 +7,7 @@ import type { Dictionary } from '@empathyco/x-utils';
7
7
  * @returns A promise wrapped object containing the response.
8
8
  * @public
9
9
  */
10
- export type HttpClient = <Response = unknown>(endpoint: string, options?: Omit<RequestOptions, 'endpoint'>) => Promise<Readonly<Response>>;
10
+ export type HttpClient = (endpoint: string, options?: Omit<RequestOptions, 'endpoint'>) => Promise<any>;
11
11
  /**
12
12
  * A record of options to make the request with.
13
13
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-adapter",
3
- "version": "8.1.0-alpha.7",
3
+ "version": "8.1.0-alpha.9",
4
4
  "description": "A utils library to create a client for any API",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -30,7 +30,7 @@
30
30
  "build": "concurrently \"pnpm run build:*\"",
31
31
  "build:cjs": "tsc --project tsconfig.cjs.json",
32
32
  "build:esm": "tsc --project tsconfig.esm.json",
33
- "postbuild": "pnpm pack",
33
+ "pack": "pnpm pack",
34
34
  "lint": "eslint --fix",
35
35
  "lint:check": "eslint",
36
36
  "lint:inspect": "eslint --inspect-config .",
@@ -41,8 +41,8 @@
41
41
  "prepublishOnly": "pnpm run build"
42
42
  },
43
43
  "dependencies": {
44
- "@empathyco/x-deep-merge": "^2.0.3-alpha.8",
45
- "@empathyco/x-utils": "^1.0.3-alpha.7",
44
+ "@empathyco/x-deep-merge": "^2.0.3-alpha.9",
45
+ "@empathyco/x-utils": "^1.0.3-alpha.8",
46
46
  "tslib": "~2.8.1"
47
47
  },
48
48
  "devDependencies": {
@@ -56,5 +56,5 @@
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "9aed796ace02864bd0a7feb81c150ce579c73353"
59
+ "gitHead": "7045b8448848d85e2cb09fca9e3abdc35c3b2904"
60
60
  }