@intlayer/api 6.1.6 → 7.0.0-canary.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.
Files changed (117) hide show
  1. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  2. package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +18 -55
  3. package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
  4. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +20 -58
  5. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
  6. package/dist/cjs/distantDictionary/index.cjs +5 -25
  7. package/dist/cjs/fetcher.cjs +113 -89
  8. package/dist/cjs/fetcher.cjs.map +1 -1
  9. package/dist/cjs/getIntlayerAPI/ai.cjs +163 -188
  10. package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
  11. package/dist/cjs/getIntlayerAPI/dictionary.cjs +69 -117
  12. package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
  13. package/dist/cjs/getIntlayerAPI/editor.cjs +37 -74
  14. package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
  15. package/dist/cjs/getIntlayerAPI/index.cjs +27 -49
  16. package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
  17. package/dist/cjs/getIntlayerAPI/newsletter.cjs +40 -77
  18. package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
  19. package/dist/cjs/getIntlayerAPI/oAuth.cjs +26 -65
  20. package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
  21. package/dist/cjs/getIntlayerAPI/organization.cjs +93 -130
  22. package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
  23. package/dist/cjs/getIntlayerAPI/project.cjs +109 -154
  24. package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
  25. package/dist/cjs/getIntlayerAPI/search.cjs +22 -58
  26. package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
  27. package/dist/cjs/getIntlayerAPI/stripe.cjs +38 -77
  28. package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
  29. package/dist/cjs/getIntlayerAPI/tag.cjs +47 -86
  30. package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
  31. package/dist/cjs/getIntlayerAPI/user.cjs +79 -106
  32. package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
  33. package/dist/cjs/index.cjs +30 -49
  34. package/dist/cjs/proxy.cjs +90 -115
  35. package/dist/cjs/proxy.cjs.map +1 -1
  36. package/dist/cjs/types.cjs +0 -17
  37. package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +17 -20
  38. package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
  39. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +19 -23
  40. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
  41. package/dist/esm/distantDictionary/index.mjs +4 -3
  42. package/dist/esm/fetcher.mjs +111 -64
  43. package/dist/esm/fetcher.mjs.map +1 -1
  44. package/dist/esm/getIntlayerAPI/ai.mjs +160 -153
  45. package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
  46. package/dist/esm/getIntlayerAPI/dictionary.mjs +66 -82
  47. package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
  48. package/dist/esm/getIntlayerAPI/editor.mjs +34 -39
  49. package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
  50. package/dist/esm/getIntlayerAPI/index.mjs +16 -14
  51. package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
  52. package/dist/esm/getIntlayerAPI/newsletter.mjs +37 -42
  53. package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
  54. package/dist/esm/getIntlayerAPI/oAuth.mjs +23 -30
  55. package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
  56. package/dist/esm/getIntlayerAPI/organization.mjs +90 -95
  57. package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
  58. package/dist/esm/getIntlayerAPI/project.mjs +106 -119
  59. package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
  60. package/dist/esm/getIntlayerAPI/search.mjs +19 -23
  61. package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
  62. package/dist/esm/getIntlayerAPI/stripe.mjs +35 -42
  63. package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
  64. package/dist/esm/getIntlayerAPI/tag.mjs +44 -51
  65. package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
  66. package/dist/esm/getIntlayerAPI/user.mjs +76 -71
  67. package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
  68. package/dist/esm/index.mjs +16 -15
  69. package/dist/esm/proxy.mjs +89 -90
  70. package/dist/esm/proxy.mjs.map +1 -1
  71. package/dist/esm/types.mjs +0 -1
  72. package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +8 -3
  73. package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts.map +1 -1
  74. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +8 -3
  75. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
  76. package/dist/types/distantDictionary/index.d.ts +3 -3
  77. package/dist/types/fetcher.d.ts +14 -11
  78. package/dist/types/fetcher.d.ts.map +1 -1
  79. package/dist/types/getIntlayerAPI/ai.d.ts +22 -18
  80. package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
  81. package/dist/types/getIntlayerAPI/dictionary.d.ts +16 -12
  82. package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -1
  83. package/dist/types/getIntlayerAPI/editor.d.ts +11 -7
  84. package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -1
  85. package/dist/types/getIntlayerAPI/index.d.ts +30 -27
  86. package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
  87. package/dist/types/getIntlayerAPI/newsletter.d.ts +11 -7
  88. package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -1
  89. package/dist/types/getIntlayerAPI/oAuth.d.ts +8 -5
  90. package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -1
  91. package/dist/types/getIntlayerAPI/organization.d.ts +18 -13
  92. package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -1
  93. package/dist/types/getIntlayerAPI/project.d.ts +19 -15
  94. package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
  95. package/dist/types/getIntlayerAPI/search.d.ts +9 -5
  96. package/dist/types/getIntlayerAPI/search.d.ts.map +1 -1
  97. package/dist/types/getIntlayerAPI/stripe.d.ts +11 -7
  98. package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -1
  99. package/dist/types/getIntlayerAPI/tag.d.ts +12 -8
  100. package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -1
  101. package/dist/types/getIntlayerAPI/user.d.ts +16 -12
  102. package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
  103. package/dist/types/index.d.ts +16 -15
  104. package/dist/types/proxy.d.ts +10 -5
  105. package/dist/types/proxy.d.ts.map +1 -1
  106. package/dist/types/types.d.ts +13 -12
  107. package/dist/types/types.d.ts.map +1 -1
  108. package/package.json +29 -38
  109. package/LICENSE +0 -202
  110. package/dist/cjs/distantDictionary/index.cjs.map +0 -1
  111. package/dist/cjs/index.cjs.map +0 -1
  112. package/dist/cjs/types.cjs.map +0 -1
  113. package/dist/esm/distantDictionary/index.mjs.map +0 -1
  114. package/dist/esm/index.mjs.map +0 -1
  115. package/dist/esm/types.mjs.map +0 -1
  116. package/dist/types/distantDictionary/index.d.ts.map +0 -1
  117. package/dist/types/index.d.ts.map +0 -1
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
@@ -1,57 +1,20 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ const require_proxy = require('../proxy.cjs');
2
+
3
+ //#region src/distantDictionary/fetchDistantDictionaries.ts
4
+ /**
5
+ * Fetch distant dictionary
6
+ */
7
+ const fetchDistantDictionaries = async (intlayerConfig) => {
8
+ try {
9
+ const { clientId, clientSecret } = intlayerConfig.editor;
10
+ if (!clientId || !clientSecret) throw new Error("Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.");
11
+ return (await require_proxy.getIntlayerAPIProxy(void 0, intlayerConfig).dictionary.getDictionaries()).data;
12
+ } catch (error) {
13
+ console.error(error);
14
+ return;
15
+ }
11
16
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var fetchDistantDictionaries_exports = {};
30
- __export(fetchDistantDictionaries_exports, {
31
- fetchDistantDictionaries: () => fetchDistantDictionaries
32
- });
33
- module.exports = __toCommonJS(fetchDistantDictionaries_exports);
34
- var import_built = __toESM(require("@intlayer/config/built"));
35
- var import_proxy = require('../proxy.cjs');
36
- const fetchDistantDictionaries = async (intlayerConfig = import_built.default) => {
37
- try {
38
- const { clientId, clientSecret } = intlayerConfig?.editor;
39
- if (!clientId || !clientSecret) {
40
- throw new Error(
41
- "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
42
- );
43
- }
44
- const api = (0, import_proxy.getIntlayerAPIProxy)(void 0, intlayerConfig);
45
- const getDictionaryResult = await api.dictionary.getDictionaries();
46
- const distantDictionaries = getDictionaryResult.data;
47
- return distantDictionaries;
48
- } catch (error) {
49
- console.error(error);
50
- return void 0;
51
- }
52
- };
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- fetchDistantDictionaries
56
- });
17
+
18
+ //#endregion
19
+ exports.fetchDistantDictionaries = fetchDistantDictionaries;
57
20
  //# sourceMappingURL=fetchDistantDictionaries.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport { getIntlayerAPIProxy } from '../proxy';\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionaries = async (\n intlayerConfig: IntlayerConfig = configuration\n): Promise<DictionaryAPI[] | null | undefined> => {\n try {\n const { clientId, clientSecret } = intlayerConfig?.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const api = getIntlayerAPIProxy(undefined, intlayerConfig);\n\n // Fetch the dictionary list\n const getDictionaryResult = await api.dictionary.getDictionaries();\n\n const distantDictionaries = getDictionaryResult.data;\n\n return distantDictionaries;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAE1B,mBAAoC;AAK7B,MAAM,2BAA2B,OACtC,iBAAiC,aAAAA,YACe;AAChD,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB;AAEnD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAM,kCAAoB,QAAW,cAAc;AAGzD,UAAM,sBAAsB,MAAM,IAAI,WAAW,gBAAgB;AAEjE,UAAM,sBAAsB,oBAAoB;AAEhD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":["configuration"]}
1
+ {"version":3,"file":"fetchDistantDictionaries.cjs","names":["getIntlayerAPIProxy"],"sources":["../../../src/distantDictionary/fetchDistantDictionaries.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types';\nimport { getIntlayerAPIProxy } from '../proxy';\nimport type { DictionaryAPI } from '../types';\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionaries = async (\n intlayerConfig: IntlayerConfig\n): Promise<DictionaryAPI[] | null | undefined> => {\n try {\n const { clientId, clientSecret } = intlayerConfig.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const api = getIntlayerAPIProxy(undefined, intlayerConfig);\n\n // Fetch the dictionary list\n const getDictionaryResult = await api.dictionary.getDictionaries();\n\n const distantDictionaries = getDictionaryResult.data;\n\n return distantDictionaries;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;AAOA,MAAa,2BAA2B,OACtC,mBACgD;AAChD,KAAI;EACF,MAAM,EAAE,UAAU,iBAAiB,eAAe;AAElD,MAAI,CAAC,YAAY,CAAC,aAChB,OAAM,IAAI,MACR,+GACD;AAUH,UAJ4B,MAHhBA,kCAAoB,QAAW,eAAe,CAGpB,WAAW,iBAAiB,EAElB;UAGzC,OAAO;AACd,UAAQ,MAAM,MAAM;AACpB"}
@@ -1,60 +1,22 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ const require_proxy = require('../proxy.cjs');
2
+
3
+ //#region src/distantDictionary/fetchDistantDictionary.ts
4
+ /**
5
+ * Fetch distant dictionary
6
+ */
7
+ const fetchDistantDictionary = async (dictionaryKey, intlayerConfig) => {
8
+ try {
9
+ const { clientId, clientSecret } = intlayerConfig.editor;
10
+ if (!clientId || !clientSecret) throw new Error("Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.");
11
+ const distantDictionary = (await require_proxy.getIntlayerAPIProxy(void 0, intlayerConfig).dictionary.getDictionary(dictionaryKey)).data;
12
+ if (!distantDictionary) throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
13
+ return distantDictionary;
14
+ } catch (error) {
15
+ console.error(error);
16
+ return;
17
+ }
11
18
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var fetchDistantDictionary_exports = {};
30
- __export(fetchDistantDictionary_exports, {
31
- fetchDistantDictionary: () => fetchDistantDictionary
32
- });
33
- module.exports = __toCommonJS(fetchDistantDictionary_exports);
34
- var import_built = __toESM(require("@intlayer/config/built"));
35
- var import_proxy = require('../proxy.cjs');
36
- const fetchDistantDictionary = async (dictionaryKey, intlayerConfig = import_built.default) => {
37
- try {
38
- const { clientId, clientSecret } = intlayerConfig?.editor;
39
- if (!clientId || !clientSecret) {
40
- throw new Error(
41
- "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
42
- );
43
- }
44
- const api = (0, import_proxy.getIntlayerAPIProxy)(void 0, intlayerConfig);
45
- const getDictionaryResult = await api.dictionary.getDictionary(dictionaryKey);
46
- const distantDictionary = getDictionaryResult.data;
47
- if (!distantDictionary) {
48
- throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
49
- }
50
- return distantDictionary;
51
- } catch (error) {
52
- console.error(error);
53
- return void 0;
54
- }
55
- };
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- fetchDistantDictionary
59
- });
19
+
20
+ //#endregion
21
+ exports.fetchDistantDictionary = fetchDistantDictionary;
60
22
  //# sourceMappingURL=fetchDistantDictionary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport { getIntlayerAPIProxy } from '../proxy';\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string,\n intlayerConfig: IntlayerConfig = configuration\n): Promise<DictionaryAPI | undefined> => {\n try {\n const { clientId, clientSecret } = intlayerConfig?.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const api = getIntlayerAPIProxy(undefined, intlayerConfig);\n\n // Fetch the dictionary\n const getDictionaryResult =\n await api.dictionary.getDictionary(dictionaryKey);\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAE1B,mBAAoC;AAK7B,MAAM,yBAAyB,OACpC,eACA,iBAAiC,aAAAA,YACM;AACvC,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB;AAEnD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAM,kCAAoB,QAAW,cAAc;AAGzD,UAAM,sBACJ,MAAM,IAAI,WAAW,cAAc,aAAa;AAElD,UAAM,oBAAoB,oBAAoB;AAE9C,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,IACnE;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":["configuration"]}
1
+ {"version":3,"file":"fetchDistantDictionary.cjs","names":["getIntlayerAPIProxy"],"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types';\nimport { getIntlayerAPIProxy } from '../proxy';\nimport type { DictionaryAPI } from '../types';\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string,\n intlayerConfig: IntlayerConfig\n): Promise<DictionaryAPI | undefined> => {\n try {\n const { clientId, clientSecret } = intlayerConfig.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const api = getIntlayerAPIProxy(undefined, intlayerConfig);\n\n // Fetch the dictionary\n const getDictionaryResult =\n await api.dictionary.getDictionary(dictionaryKey);\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;AAOA,MAAa,yBAAyB,OACpC,eACA,mBACuC;AACvC,KAAI;EACF,MAAM,EAAE,UAAU,iBAAiB,eAAe;AAElD,MAAI,CAAC,YAAY,CAAC,aAChB,OAAM,IAAI,MACR,+GACD;EASH,MAAM,qBAFJ,MAJUA,kCAAoB,QAAW,eAAe,CAI9C,WAAW,cAAc,cAAc,EAEL;AAE9C,MAAI,CAAC,kBACH,OAAM,IAAI,MAAM,cAAc,cAAc,sBAAsB;AAGpE,SAAO;UACA,OAAO;AACd,UAAQ,MAAM,MAAM;AACpB"}
@@ -1,25 +1,5 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var distantDictionary_exports = {};
17
- module.exports = __toCommonJS(distantDictionary_exports);
18
- __reExport(distantDictionary_exports, require('./fetchDistantDictionaries.cjs'), module.exports);
19
- __reExport(distantDictionary_exports, require('./fetchDistantDictionary.cjs'), module.exports);
20
- // Annotate the CommonJS export names for ESM import in node:
21
- 0 && (module.exports = {
22
- ...require('./fetchDistantDictionaries.cjs'),
23
- ...require('./fetchDistantDictionary.cjs')
24
- });
25
- //# sourceMappingURL=index.cjs.map
1
+ const require_distantDictionary_fetchDistantDictionaries = require('./fetchDistantDictionaries.cjs');
2
+ const require_distantDictionary_fetchDistantDictionary = require('./fetchDistantDictionary.cjs');
3
+
4
+ exports.fetchDistantDictionaries = require_distantDictionary_fetchDistantDictionaries.fetchDistantDictionaries;
5
+ exports.fetchDistantDictionary = require_distantDictionary_fetchDistantDictionary.fetchDistantDictionary;
@@ -1,98 +1,122 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var fetcher_exports = {};
20
- __export(fetcher_exports, {
21
- fetcher: () => fetcher,
22
- fetcherOptions: () => fetcherOptions
23
- });
24
- module.exports = __toCommonJS(fetcher_exports);
1
+
2
+ //#region src/fetcher.ts
3
+ /**
4
+ * Default options for the fetcher function.
5
+ * Sets the default method to 'GET', the 'Content-Type' header to 'application/json',
6
+ * and includes credentials in the request.
7
+ */
25
8
  const fetcherOptions = {
26
- method: "GET",
27
- // Default HTTP method
28
- headers: {
29
- "Content-Type": "application/json"
30
- // Default content type
31
- },
32
- credentials: "include"
9
+ method: "GET",
10
+ headers: { "Content-Type": "application/json" },
11
+ credentials: "include"
33
12
  };
13
+ /**
14
+ * Utility function to remove properties with undefined values from an object.
15
+ * This helps prevent sending undefined values in the request options.
16
+ *
17
+ * @param obj - The object to clean.
18
+ * @returns The cleaned object without undefined values.
19
+ */
34
20
  const removeUndefined = (obj) => {
35
- Object.keys(obj).forEach((key) => {
36
- if (obj[key] === void 0) {
37
- delete obj[key];
38
- }
39
- });
40
- return obj;
21
+ Object.keys(obj).forEach((key) => {
22
+ if (obj[key] === void 0) delete obj[key];
23
+ });
24
+ return obj;
41
25
  };
26
+ /**
27
+ * Deeply merges an array of objects into a single object.
28
+ * Later objects in the array overwrite properties of earlier ones.
29
+ *
30
+ * @template T - The type of objects being merged.
31
+ * @param objects - An array of objects to merge.
32
+ * @returns The merged object.
33
+ */
42
34
  const deepMerge = (objects) => objects.reduce((acc, obj) => {
43
- const acc1 = acc ?? {};
44
- const obj1 = removeUndefined(obj ?? {});
45
- if (typeof acc1 === "object" && typeof obj1 === "object") {
46
- return { ...acc1, ...obj1 };
47
- }
48
- return obj1 ?? acc1;
35
+ const acc1 = acc ?? {};
36
+ const obj1 = removeUndefined(obj ?? {});
37
+ if (typeof acc1 === "object" && typeof obj1 === "object") return {
38
+ ...acc1,
39
+ ...obj1
40
+ };
41
+ return obj1 ?? acc1;
49
42
  }, {});
43
+ /**
44
+ * Fetcher function to make HTTP requests.
45
+ * It merges default options with user-provided options,
46
+ * handles query parameters and request body,
47
+ * and returns the parsed JSON response.
48
+ *
49
+ * @template T - The expected type of the response data.
50
+ * @param url - The endpoint URL.
51
+ * @param options - Additional options to customize the request.
52
+ * @returns A promise that resolves with the response data of type T.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Making a GET request with query parameters
57
+ * const data = await fetcher<MyResponseType>('https://api.example.com/data', {
58
+ * params: { search: 'query' },
59
+ * });
60
+ *
61
+ * // Making a POST request with a JSON body
62
+ * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {
63
+ * method: 'POST',
64
+ * body: { key: 'value' },
65
+ * });
66
+ *
67
+ * // Merge body, headers, and params
68
+ * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {
69
+ * method: 'POST',
70
+ * body: { key: 'value' },
71
+ * headers: { 'Content-Type': 'application/json' },
72
+ * params: { search: 'query' },
73
+ * },
74
+ * {
75
+ * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
76
+ * params: { page: 1 },
77
+ * });
78
+ * ```
79
+ *
80
+ * Result:
81
+ * ```typescript
82
+ * {
83
+ * method: 'POST',
84
+ * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
85
+ * params: { page: 1, search: 'query' },
86
+ * body: { key: 'value' },
87
+ * }
88
+ * ```
89
+ */
50
90
  const fetcher = async (url, ...options) => {
51
- const { signal } = new AbortController();
52
- let paramsString = "";
53
- let bodyString = void 0;
54
- const otherOptions = options.map(
55
- ({ body, params: params2, headers, ...otherOptions2 }) => otherOptions2
56
- );
57
- const mergedOptions = deepMerge([fetcherOptions, ...otherOptions]);
58
- const mergedHeaders = deepMerge([
59
- fetcherOptions.headers,
60
- ...options.map((option) => option.headers)
61
- ]);
62
- const params = deepMerge(options.map((option) => option.params));
63
- const method = mergedOptions.method;
64
- if (method !== "GET" && method !== "HEAD") {
65
- const body = deepMerge(options.map((option) => option.body));
66
- if (mergedHeaders?.["Content-Type"] === "application/x-www-form-urlencoded") {
67
- bodyString = new URLSearchParams(
68
- body
69
- ).toString();
70
- } else {
71
- bodyString = JSON.stringify(body);
72
- }
73
- }
74
- if (Object.entries(params).length > 0) {
75
- paramsString = `?${new URLSearchParams(
76
- params
77
- ).toString()}`;
78
- }
79
- const formattedOptions = {
80
- ...mergedOptions,
81
- headers: mergedHeaders,
82
- body: bodyString,
83
- signal
84
- };
85
- const urlResult = `${url}${paramsString}`;
86
- const response = await fetch(urlResult, formattedOptions);
87
- if (!response.ok) {
88
- const result = await response.json();
89
- throw new Error(JSON.stringify(result.error) ?? "An error occurred");
90
- }
91
- return await response.json();
91
+ const { signal } = new AbortController();
92
+ let paramsString = "";
93
+ let bodyString;
94
+ const mergedOptions = deepMerge([fetcherOptions, ...options.map(({ body, params: params$1, headers,...otherOptions }) => otherOptions)]);
95
+ const mergedHeaders = deepMerge([fetcherOptions.headers, ...options.map((option) => option.headers)]);
96
+ const params = deepMerge(options.map((option) => option.params));
97
+ const method = mergedOptions.method;
98
+ if (method !== "GET" && method !== "HEAD") {
99
+ const body = deepMerge(options.map((option) => option.body));
100
+ if (mergedHeaders?.["Content-Type"] === "application/x-www-form-urlencoded") bodyString = new URLSearchParams(body).toString();
101
+ else bodyString = JSON.stringify(body);
102
+ }
103
+ if (Object.entries(params).length > 0) paramsString = `?${new URLSearchParams(params).toString()}`;
104
+ const formattedOptions = {
105
+ ...mergedOptions,
106
+ headers: mergedHeaders,
107
+ body: bodyString,
108
+ signal
109
+ };
110
+ const urlResult = `${url}${paramsString}`;
111
+ const response = await fetch(urlResult, formattedOptions);
112
+ if (!response.ok) {
113
+ const result = await response.json();
114
+ throw new Error(JSON.stringify(result.error) ?? "An error occurred");
115
+ }
116
+ return await response.json();
92
117
  };
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {
95
- fetcher,
96
- fetcherOptions
97
- });
118
+
119
+ //#endregion
120
+ exports.fetcher = fetcher;
121
+ exports.fetcherOptions = fetcherOptions;
98
122
  //# sourceMappingURL=fetcher.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fetcher.ts"],"sourcesContent":["/**\n * Type definition for options used in the fetcher function.\n * Extends the standard RequestInit interface (excluding 'body'),\n * and adds 'body' and 'params' properties for convenience.\n */\nexport type FetcherOptions = Omit<RequestInit, 'body'> & {\n /**\n * Body of the request. Should be a key-value pair object.\n */\n body?: Record<string, unknown>;\n /**\n * Query parameters to be appended to the URL.\n */\n params?:\n | Record<string, string | string[] | undefined>\n | string[]\n | URLSearchParams;\n};\n\n/**\n * Default options for the fetcher function.\n * Sets the default method to 'GET', the 'Content-Type' header to 'application/json',\n * and includes credentials in the request.\n */\nexport const fetcherOptions: FetcherOptions = {\n method: 'GET', // Default HTTP method\n headers: {\n 'Content-Type': 'application/json', // Default content type\n },\n credentials: 'include',\n};\n\n/**\n * Utility function to remove properties with undefined values from an object.\n * This helps prevent sending undefined values in the request options.\n *\n * @param obj - The object to clean.\n * @returns The cleaned object without undefined values.\n */\nconst removeUndefined = (obj: object) => {\n Object.keys(obj).forEach((key) => {\n if (obj[key as keyof typeof obj] === undefined) {\n delete obj[key as keyof typeof obj];\n }\n });\n return obj;\n};\n\n/**\n * Deeply merges an array of objects into a single object.\n * Later objects in the array overwrite properties of earlier ones.\n *\n * @template T - The type of objects being merged.\n * @param objects - An array of objects to merge.\n * @returns The merged object.\n */\nconst deepMerge = <T extends object>(objects: (T | undefined)[]): T =>\n objects.reduce((acc, obj) => {\n const acc1: T = (acc ?? {}) as T;\n const obj1: T = removeUndefined(obj ?? {}) as T;\n\n if (typeof acc1 === 'object' && typeof obj1 === 'object') {\n // Merge the two objects\n return { ...acc1, ...obj1 };\n }\n\n // If one of them is not an object, return the defined one\n return obj1 ?? acc1;\n }, {} as T)!;\n\n/**\n * Fetcher function to make HTTP requests.\n * It merges default options with user-provided options,\n * handles query parameters and request body,\n * and returns the parsed JSON response.\n *\n * @template T - The expected type of the response data.\n * @param url - The endpoint URL.\n * @param options - Additional options to customize the request.\n * @returns A promise that resolves with the response data of type T.\n *\n * @example\n * ```typescript\n * // Making a GET request with query parameters\n * const data = await fetcher<MyResponseType>('https://api.example.com/data', {\n * params: { search: 'query' },\n * });\n *\n * // Making a POST request with a JSON body\n * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {\n * method: 'POST',\n * body: { key: 'value' },\n * });\n *\n * // Merge body, headers, and params\n * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {\n * method: 'POST',\n * body: { key: 'value' },\n * headers: { 'Content-Type': 'application/json' },\n * params: { search: 'query' },\n * },\n * {\n * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n * params: { page: 1 },\n * });\n * ```\n *\n * Result:\n * ```typescript\n * {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n * params: { page: 1, search: 'query' },\n * body: { key: 'value' },\n * }\n * ```\n */\nexport const fetcher = async <T>(\n url: string,\n ...options: FetcherOptions[]\n): Promise<T> => {\n const { signal } = new AbortController();\n\n // Initialize query parameters string and request body string\n let paramsString = '';\n let bodyString: string | undefined = undefined;\n\n // Extract other options excluding 'body', 'params', and 'headers'\n const otherOptions = options.map(\n ({ body, params, headers, ...otherOptions }) => otherOptions\n );\n\n // Merge default options with user-provided options\n const mergedOptions = deepMerge([fetcherOptions, ...otherOptions]);\n\n // Merge default headers with user-provided headers\n const mergedHeaders = deepMerge([\n fetcherOptions.headers,\n ...options.map((option) => option.headers),\n ]);\n\n // Merge query parameters\n const params = deepMerge(options.map((option) => option.params));\n\n const method = mergedOptions.method;\n\n // If the request method is not 'GET' or 'HEAD', prepare the request body\n if (method !== 'GET' && method !== 'HEAD') {\n // Merge all 'body' options\n const body = deepMerge(options.map((option) => option.body));\n if (\n mergedHeaders?.['Content-Type' as keyof HeadersInit] ===\n 'application/x-www-form-urlencoded'\n ) {\n // If the content type is 'application/x-www-form-urlencoded', encode the body accordingly\n bodyString = new URLSearchParams(\n body as Record<string, string>\n ).toString();\n } else {\n // Otherwise, stringify the body as JSON\n bodyString = JSON.stringify(body);\n }\n }\n\n // If there are query parameters, append them to the URL\n if (Object.entries(params).length > 0) {\n paramsString = `?${new URLSearchParams(\n params as Record<string, string>\n ).toString()}`;\n }\n\n // Prepare the final request options\n const formattedOptions: RequestInit = {\n ...mergedOptions,\n headers: mergedHeaders,\n body: bodyString,\n signal,\n };\n\n // Construct the full URL with query parameters\n const urlResult = `${url}${paramsString}`;\n\n // Make the HTTP request using fetch\n const response = await fetch(urlResult, formattedOptions);\n\n if (!response.ok) {\n const result = await response.json();\n\n // You can customize the error message or include more details\n throw new Error(JSON.stringify(result.error) ?? 'An error occurred');\n }\n return await response.json();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,iBAAiC;AAAA,EAC5C,QAAQ;AAAA;AAAA,EACR,SAAS;AAAA,IACP,gBAAgB;AAAA;AAAA,EAClB;AAAA,EACA,aAAa;AACf;AASA,MAAM,kBAAkB,CAAC,QAAgB;AACvC,SAAO,KAAK,GAAG,EAAE,QAAQ,CAAC,QAAQ;AAChC,QAAI,IAAI,GAAuB,MAAM,QAAW;AAC9C,aAAO,IAAI,GAAuB;AAAA,IACpC;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAUA,MAAM,YAAY,CAAmB,YACnC,QAAQ,OAAO,CAAC,KAAK,QAAQ;AAC3B,QAAM,OAAW,OAAO,CAAC;AACzB,QAAM,OAAU,gBAAgB,OAAO,CAAC,CAAC;AAEzC,MAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAAU;AAExD,WAAO,EAAE,GAAG,MAAM,GAAG,KAAK;AAAA,EAC5B;AAGA,SAAO,QAAQ;AACjB,GAAG,CAAC,CAAM;AAiDL,MAAM,UAAU,OACrB,QACG,YACY;AACf,QAAM,EAAE,OAAO,IAAI,IAAI,gBAAgB;AAGvC,MAAI,eAAe;AACnB,MAAI,aAAiC;AAGrC,QAAM,eAAe,QAAQ;AAAA,IAC3B,CAAC,EAAE,MAAM,QAAAA,SAAQ,SAAS,GAAGC,cAAa,MAAMA;AAAA,EAClD;AAGA,QAAM,gBAAgB,UAAU,CAAC,gBAAgB,GAAG,YAAY,CAAC;AAGjE,QAAM,gBAAgB,UAAU;AAAA,IAC9B,eAAe;AAAA,IACf,GAAG,QAAQ,IAAI,CAAC,WAAW,OAAO,OAAO;AAAA,EAC3C,CAAC;AAGD,QAAM,SAAS,UAAU,QAAQ,IAAI,CAAC,WAAW,OAAO,MAAM,CAAC;AAE/D,QAAM,SAAS,cAAc;AAG7B,MAAI,WAAW,SAAS,WAAW,QAAQ;AAEzC,UAAM,OAAO,UAAU,QAAQ,IAAI,CAAC,WAAW,OAAO,IAAI,CAAC;AAC3D,QACE,gBAAgB,cAAmC,MACnD,qCACA;AAEA,mBAAa,IAAI;AAAA,QACf;AAAA,MACF,EAAE,SAAS;AAAA,IACb,OAAO;AAEL,mBAAa,KAAK,UAAU,IAAI;AAAA,IAClC;AAAA,EACF;AAGA,MAAI,OAAO,QAAQ,MAAM,EAAE,SAAS,GAAG;AACrC,mBAAe,IAAI,IAAI;AAAA,MACrB;AAAA,IACF,EAAE,SAAS,CAAC;AAAA,EACd;AAGA,QAAM,mBAAgC;AAAA,IACpC,GAAG;AAAA,IACH,SAAS;AAAA,IACT,MAAM;AAAA,IACN;AAAA,EACF;AAGA,QAAM,YAAY,GAAG,GAAG,GAAG,YAAY;AAGvC,QAAM,WAAW,MAAM,MAAM,WAAW,gBAAgB;AAExD,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,SAAS,MAAM,SAAS,KAAK;AAGnC,UAAM,IAAI,MAAM,KAAK,UAAU,OAAO,KAAK,KAAK,mBAAmB;AAAA,EACrE;AACA,SAAO,MAAM,SAAS,KAAK;AAC7B;","names":["params","otherOptions"]}
1
+ {"version":3,"file":"fetcher.cjs","names":["fetcherOptions: FetcherOptions","acc1: T","obj1: T","bodyString: string | undefined","formattedOptions: RequestInit"],"sources":["../../src/fetcher.ts"],"sourcesContent":["/**\n * Type definition for options used in the fetcher function.\n * Extends the standard RequestInit interface (excluding 'body'),\n * and adds 'body' and 'params' properties for convenience.\n */\nexport type FetcherOptions = Omit<RequestInit, 'body'> & {\n /**\n * Body of the request. Should be a key-value pair object.\n */\n body?: Record<string, unknown>;\n /**\n * Query parameters to be appended to the URL.\n */\n params?:\n | Record<string, string | string[] | undefined>\n | string[]\n | URLSearchParams;\n};\n\n/**\n * Default options for the fetcher function.\n * Sets the default method to 'GET', the 'Content-Type' header to 'application/json',\n * and includes credentials in the request.\n */\nexport const fetcherOptions: FetcherOptions = {\n method: 'GET', // Default HTTP method\n headers: {\n 'Content-Type': 'application/json', // Default content type\n },\n credentials: 'include',\n};\n\n/**\n * Utility function to remove properties with undefined values from an object.\n * This helps prevent sending undefined values in the request options.\n *\n * @param obj - The object to clean.\n * @returns The cleaned object without undefined values.\n */\nconst removeUndefined = (obj: object) => {\n Object.keys(obj).forEach((key) => {\n if (obj[key as keyof typeof obj] === undefined) {\n delete obj[key as keyof typeof obj];\n }\n });\n return obj;\n};\n\n/**\n * Deeply merges an array of objects into a single object.\n * Later objects in the array overwrite properties of earlier ones.\n *\n * @template T - The type of objects being merged.\n * @param objects - An array of objects to merge.\n * @returns The merged object.\n */\nconst deepMerge = <T extends object>(objects: (T | undefined)[]): T =>\n objects.reduce((acc, obj) => {\n const acc1: T = (acc ?? {}) as T;\n const obj1: T = removeUndefined(obj ?? {}) as T;\n\n if (typeof acc1 === 'object' && typeof obj1 === 'object') {\n // Merge the two objects\n return { ...acc1, ...obj1 };\n }\n\n // If one of them is not an object, return the defined one\n return obj1 ?? acc1;\n }, {} as T)!;\n\n/**\n * Fetcher function to make HTTP requests.\n * It merges default options with user-provided options,\n * handles query parameters and request body,\n * and returns the parsed JSON response.\n *\n * @template T - The expected type of the response data.\n * @param url - The endpoint URL.\n * @param options - Additional options to customize the request.\n * @returns A promise that resolves with the response data of type T.\n *\n * @example\n * ```typescript\n * // Making a GET request with query parameters\n * const data = await fetcher<MyResponseType>('https://api.example.com/data', {\n * params: { search: 'query' },\n * });\n *\n * // Making a POST request with a JSON body\n * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {\n * method: 'POST',\n * body: { key: 'value' },\n * });\n *\n * // Merge body, headers, and params\n * const result = await fetcher<AnotherResponseType>('https://api.example.com/submit', {\n * method: 'POST',\n * body: { key: 'value' },\n * headers: { 'Content-Type': 'application/json' },\n * params: { search: 'query' },\n * },\n * {\n * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n * params: { page: 1 },\n * });\n * ```\n *\n * Result:\n * ```typescript\n * {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n * params: { page: 1, search: 'query' },\n * body: { key: 'value' },\n * }\n * ```\n */\nexport const fetcher = async <T>(\n url: string,\n ...options: FetcherOptions[]\n): Promise<T> => {\n const { signal } = new AbortController();\n\n // Initialize query parameters string and request body string\n let paramsString = '';\n let bodyString: string | undefined;\n\n // Extract other options excluding 'body', 'params', and 'headers'\n const otherOptions = options.map(\n ({ body, params, headers, ...otherOptions }) => otherOptions\n );\n\n // Merge default options with user-provided options\n const mergedOptions = deepMerge([fetcherOptions, ...otherOptions]);\n\n // Merge default headers with user-provided headers\n const mergedHeaders = deepMerge([\n fetcherOptions.headers,\n ...options.map((option) => option.headers),\n ]);\n\n // Merge query parameters\n const params = deepMerge(options.map((option) => option.params));\n\n const method = mergedOptions.method;\n\n // If the request method is not 'GET' or 'HEAD', prepare the request body\n if (method !== 'GET' && method !== 'HEAD') {\n // Merge all 'body' options\n const body = deepMerge(options.map((option) => option.body));\n if (\n mergedHeaders?.['Content-Type' as keyof HeadersInit] ===\n 'application/x-www-form-urlencoded'\n ) {\n // If the content type is 'application/x-www-form-urlencoded', encode the body accordingly\n bodyString = new URLSearchParams(\n body as Record<string, string>\n ).toString();\n } else {\n // Otherwise, stringify the body as JSON\n bodyString = JSON.stringify(body);\n }\n }\n\n // If there are query parameters, append them to the URL\n if (Object.entries(params).length > 0) {\n paramsString = `?${new URLSearchParams(\n params as Record<string, string>\n ).toString()}`;\n }\n\n // Prepare the final request options\n const formattedOptions: RequestInit = {\n ...mergedOptions,\n headers: mergedHeaders,\n body: bodyString,\n signal,\n };\n\n // Construct the full URL with query parameters\n const urlResult = `${url}${paramsString}`;\n\n // Make the HTTP request using fetch\n const response = await fetch(urlResult, formattedOptions);\n\n if (!response.ok) {\n const result = await response.json();\n\n // You can customize the error message or include more details\n throw new Error(JSON.stringify(result.error) ?? 'An error occurred');\n }\n return await response.json();\n};\n"],"mappings":";;;;;;;AAwBA,MAAaA,iBAAiC;CAC5C,QAAQ;CACR,SAAS,EACP,gBAAgB,oBACjB;CACD,aAAa;CACd;;;;;;;;AASD,MAAM,mBAAmB,QAAgB;AACvC,QAAO,KAAK,IAAI,CAAC,SAAS,QAAQ;AAChC,MAAI,IAAI,SAA6B,OACnC,QAAO,IAAI;GAEb;AACF,QAAO;;;;;;;;;;AAWT,MAAM,aAA+B,YACnC,QAAQ,QAAQ,KAAK,QAAQ;CAC3B,MAAMC,OAAW,OAAO,EAAE;CAC1B,MAAMC,OAAU,gBAAgB,OAAO,EAAE,CAAC;AAE1C,KAAI,OAAO,SAAS,YAAY,OAAO,SAAS,SAE9C,QAAO;EAAE,GAAG;EAAM,GAAG;EAAM;AAI7B,QAAO,QAAQ;GACd,EAAE,CAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDb,MAAa,UAAU,OACrB,KACA,GAAG,YACY;CACf,MAAM,EAAE,WAAW,IAAI,iBAAiB;CAGxC,IAAI,eAAe;CACnB,IAAIC;CAQJ,MAAM,gBAAgB,UAAU,CAAC,gBAAgB,GAL5B,QAAQ,KAC1B,EAAE,MAAM,kBAAQ,QAAS,GAAG,mBAAmB,aACjD,CAGgE,CAAC;CAGlE,MAAM,gBAAgB,UAAU,CAC9B,eAAe,SACf,GAAG,QAAQ,KAAK,WAAW,OAAO,QAAQ,CAC3C,CAAC;CAGF,MAAM,SAAS,UAAU,QAAQ,KAAK,WAAW,OAAO,OAAO,CAAC;CAEhE,MAAM,SAAS,cAAc;AAG7B,KAAI,WAAW,SAAS,WAAW,QAAQ;EAEzC,MAAM,OAAO,UAAU,QAAQ,KAAK,WAAW,OAAO,KAAK,CAAC;AAC5D,MACE,gBAAgB,oBAChB,oCAGA,cAAa,IAAI,gBACf,KACD,CAAC,UAAU;MAGZ,cAAa,KAAK,UAAU,KAAK;;AAKrC,KAAI,OAAO,QAAQ,OAAO,CAAC,SAAS,EAClC,gBAAe,IAAI,IAAI,gBACrB,OACD,CAAC,UAAU;CAId,MAAMC,mBAAgC;EACpC,GAAG;EACH,SAAS;EACT,MAAM;EACN;EACD;CAGD,MAAM,YAAY,GAAG,MAAM;CAG3B,MAAM,WAAW,MAAM,MAAM,WAAW,iBAAiB;AAEzD,KAAI,CAAC,SAAS,IAAI;EAChB,MAAM,SAAS,MAAM,SAAS,MAAM;AAGpC,QAAM,IAAI,MAAM,KAAK,UAAU,OAAO,MAAM,IAAI,oBAAoB;;AAEtE,QAAO,MAAM,SAAS,MAAM"}