@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
@@ -1,49 +1,30 @@
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 index_exports = {};
17
- module.exports = __toCommonJS(index_exports);
18
- __reExport(index_exports, require('./distantDictionary/index.cjs'), module.exports);
19
- __reExport(index_exports, require('./fetcher.cjs'), module.exports);
20
- __reExport(index_exports, require('./getIntlayerAPI/index.cjs'), module.exports);
21
- __reExport(index_exports, require('./getIntlayerAPI/ai.cjs'), module.exports);
22
- __reExport(index_exports, require('./getIntlayerAPI/dictionary.cjs'), module.exports);
23
- __reExport(index_exports, require('./getIntlayerAPI/editor.cjs'), module.exports);
24
- __reExport(index_exports, require('./getIntlayerAPI/oAuth.cjs'), module.exports);
25
- __reExport(index_exports, require('./getIntlayerAPI/organization.cjs'), module.exports);
26
- __reExport(index_exports, require('./getIntlayerAPI/project.cjs'), module.exports);
27
- __reExport(index_exports, require('./getIntlayerAPI/stripe.cjs'), module.exports);
28
- __reExport(index_exports, require('./getIntlayerAPI/tag.cjs'), module.exports);
29
- __reExport(index_exports, require('./getIntlayerAPI/user.cjs'), module.exports);
30
- __reExport(index_exports, require('./proxy.cjs'), module.exports);
31
- __reExport(index_exports, require('./types.cjs'), module.exports);
32
- // Annotate the CommonJS export names for ESM import in node:
33
- 0 && (module.exports = {
34
- ...require('./distantDictionary/index.cjs'),
35
- ...require('./fetcher.cjs'),
36
- ...require('./getIntlayerAPI/index.cjs'),
37
- ...require('./getIntlayerAPI/ai.cjs'),
38
- ...require('./getIntlayerAPI/dictionary.cjs'),
39
- ...require('./getIntlayerAPI/editor.cjs'),
40
- ...require('./getIntlayerAPI/oAuth.cjs'),
41
- ...require('./getIntlayerAPI/organization.cjs'),
42
- ...require('./getIntlayerAPI/project.cjs'),
43
- ...require('./getIntlayerAPI/stripe.cjs'),
44
- ...require('./getIntlayerAPI/tag.cjs'),
45
- ...require('./getIntlayerAPI/user.cjs'),
46
- ...require('./proxy.cjs'),
47
- ...require('./types.cjs')
48
- });
49
- //# sourceMappingURL=index.cjs.map
1
+ const require_fetcher = require('./fetcher.cjs');
2
+ const require_getIntlayerAPI_ai = require('./getIntlayerAPI/ai.cjs');
3
+ const require_getIntlayerAPI_dictionary = require('./getIntlayerAPI/dictionary.cjs');
4
+ const require_getIntlayerAPI_editor = require('./getIntlayerAPI/editor.cjs');
5
+ const require_getIntlayerAPI_oAuth = require('./getIntlayerAPI/oAuth.cjs');
6
+ const require_getIntlayerAPI_organization = require('./getIntlayerAPI/organization.cjs');
7
+ const require_getIntlayerAPI_project = require('./getIntlayerAPI/project.cjs');
8
+ const require_getIntlayerAPI_stripe = require('./getIntlayerAPI/stripe.cjs');
9
+ const require_getIntlayerAPI_tag = require('./getIntlayerAPI/tag.cjs');
10
+ const require_getIntlayerAPI_user = require('./getIntlayerAPI/user.cjs');
11
+ const require_getIntlayerAPI_index = require('./getIntlayerAPI/index.cjs');
12
+ const require_proxy = require('./proxy.cjs');
13
+ const require_distantDictionary_fetchDistantDictionaries = require('./distantDictionary/fetchDistantDictionaries.cjs');
14
+ const require_distantDictionary_fetchDistantDictionary = require('./distantDictionary/fetchDistantDictionary.cjs');
15
+
16
+ exports.fetchDistantDictionaries = require_distantDictionary_fetchDistantDictionaries.fetchDistantDictionaries;
17
+ exports.fetchDistantDictionary = require_distantDictionary_fetchDistantDictionary.fetchDistantDictionary;
18
+ exports.fetcher = require_fetcher.fetcher;
19
+ exports.fetcherOptions = require_fetcher.fetcherOptions;
20
+ exports.getAiAPI = require_getIntlayerAPI_ai.getAiAPI;
21
+ exports.getDictionaryAPI = require_getIntlayerAPI_dictionary.getDictionaryAPI;
22
+ exports.getEditorAPI = require_getIntlayerAPI_editor.getEditorAPI;
23
+ exports.getIntlayerAPI = require_getIntlayerAPI_index.getIntlayerAPI;
24
+ exports.getIntlayerAPIProxy = require_proxy.getIntlayerAPIProxy;
25
+ exports.getOAuthAPI = require_getIntlayerAPI_oAuth.getOAuthAPI;
26
+ exports.getOrganizationAPI = require_getIntlayerAPI_organization.getOrganizationAPI;
27
+ exports.getProjectAPI = require_getIntlayerAPI_project.getProjectAPI;
28
+ exports.getStripeAPI = require_getIntlayerAPI_stripe.getStripeAPI;
29
+ exports.getTagAPI = require_getIntlayerAPI_tag.getTagAPI;
30
+ exports.getUserAPI = require_getIntlayerAPI_user.getUserAPI;
@@ -1,124 +1,99 @@
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 proxy_exports = {};
20
- __export(proxy_exports, {
21
- getIntlayerAPIProxy: () => getIntlayerAPIProxy
22
- });
23
- module.exports = __toCommonJS(proxy_exports);
24
- var import_getIntlayerAPI = require('./getIntlayerAPI/index.cjs');
25
- var import_oAuth = require('./getIntlayerAPI/oAuth.cjs');
1
+ const require_getIntlayerAPI_oAuth = require('./getIntlayerAPI/oAuth.cjs');
2
+ const require_getIntlayerAPI_index = require('./getIntlayerAPI/index.cjs');
3
+
4
+ //#region src/proxy.ts
26
5
  const ONE_MINUTE_MS = 6e4;
6
+ /**
7
+ * Returns the expiration timestamp in ms from an OAuth token-like object.
8
+ */
27
9
  const getExpiryTimestamp = (token) => {
28
- if (!token) return void 0;
29
- const dateLike = token.accessTokenExpiresAt ?? token.expiresAt;
30
- if (dateLike) {
31
- const ts = typeof dateLike === "string" ? Date.parse(dateLike) : dateLike.getTime?.();
32
- if (typeof ts === "number" && Number.isFinite(ts)) return ts;
33
- }
34
- const seconds = token.expires_in ?? token.expiresIn;
35
- if (typeof seconds === "number" && Number.isFinite(seconds)) {
36
- return Date.now() + seconds * 1e3;
37
- }
38
- return void 0;
10
+ if (!token) return void 0;
11
+ const dateLike = token.accessTokenExpiresAt ?? token.expiresAt;
12
+ if (dateLike) {
13
+ const ts = typeof dateLike === "string" ? Date.parse(dateLike) : dateLike.getTime?.();
14
+ if (typeof ts === "number" && Number.isFinite(ts)) return ts;
15
+ }
16
+ const seconds = token.expires_in ?? token.expiresIn;
17
+ if (typeof seconds === "number" && Number.isFinite(seconds)) return Date.now() + seconds * 1e3;
39
18
  };
40
19
  let currentAccessToken;
41
20
  let currentExpiryTs;
42
21
  let pendingRefresh;
22
+ /**
23
+ * Build an auto-auth proxy around getIntlayerAPI that:
24
+ * - Fetches an OAuth2 token when needed
25
+ * - Injects Authorization header for each request
26
+ * - Refreshes token proactively when near expiry
27
+ *
28
+ * The returned API matches the shape of getIntlayerAPI.
29
+ */
43
30
  const getIntlayerAPIProxy = (_baseAuthOptions = {}, intlayerConfig) => {
44
- const authOptionsRef = { ..._baseAuthOptions };
45
- const hasCMSAuth = intlayerConfig?.editor.clientId && intlayerConfig?.editor.clientSecret;
46
- const baseApi = (0, import_getIntlayerAPI.getIntlayerAPI)(authOptionsRef, intlayerConfig);
47
- const needsRefresh = () => {
48
- if (!currentAccessToken) return true;
49
- if (!currentExpiryTs) return false;
50
- return Date.now() + ONE_MINUTE_MS >= currentExpiryTs;
51
- };
52
- const refreshToken = async () => {
53
- const doRefresh = async () => {
54
- const authApi = (0, import_oAuth.getOAuthAPI)(intlayerConfig);
55
- const res = await authApi.getOAuth2AccessToken();
56
- const tokenData = res?.data;
57
- currentAccessToken = tokenData?.accessToken;
58
- currentExpiryTs = getExpiryTimestamp(tokenData);
59
- };
60
- if (!pendingRefresh) {
61
- pendingRefresh = doRefresh().finally(() => {
62
- pendingRefresh = void 0;
63
- });
64
- }
65
- await pendingRefresh;
66
- };
67
- const ensureValidToken = async () => {
68
- if (needsRefresh()) {
69
- await refreshToken();
70
- }
71
- };
72
- const applyAuthHeaderToRef = () => {
73
- if (!currentAccessToken) return;
74
- authOptionsRef.headers = {
75
- ...authOptionsRef.headers ?? {},
76
- Authorization: `Bearer ${currentAccessToken}`
77
- };
78
- };
79
- const wrapSection = (section, skipAuth = !hasCMSAuth) => {
80
- return new Proxy(section, {
81
- get(target, prop, receiver) {
82
- const value = Reflect.get(target, prop, receiver);
83
- if (typeof value === "function") {
84
- return async (...args) => {
85
- if (!skipAuth) {
86
- await ensureValidToken();
87
- applyAuthHeaderToRef();
88
- }
89
- try {
90
- return await value.apply(target, args);
91
- } catch (err) {
92
- if (!skipAuth) {
93
- await refreshToken();
94
- applyAuthHeaderToRef();
95
- return await value.apply(target, args);
96
- }
97
- throw err;
98
- }
99
- };
100
- }
101
- return value;
102
- }
103
- });
104
- };
105
- return {
106
- organization: wrapSection(baseApi.organization),
107
- project: wrapSection(baseApi.project),
108
- user: wrapSection(baseApi.user),
109
- oAuth: wrapSection(baseApi.oAuth, true),
110
- // do NOT inject auth for token endpoint
111
- dictionary: wrapSection(baseApi.dictionary),
112
- stripe: wrapSection(baseApi.stripe),
113
- ai: wrapSection(baseApi.ai),
114
- tag: wrapSection(baseApi.tag),
115
- search: wrapSection(baseApi.search),
116
- editor: wrapSection(baseApi.editor),
117
- newsletter: wrapSection(baseApi.newsletter)
118
- };
31
+ const authOptionsRef = { ..._baseAuthOptions };
32
+ const hasCMSAuth = intlayerConfig?.editor?.clientId && intlayerConfig?.editor?.clientSecret;
33
+ const baseApi = require_getIntlayerAPI_index.getIntlayerAPI(authOptionsRef, intlayerConfig);
34
+ const needsRefresh = () => {
35
+ if (!currentAccessToken) return true;
36
+ if (!currentExpiryTs) return false;
37
+ return Date.now() + ONE_MINUTE_MS >= currentExpiryTs;
38
+ };
39
+ const refreshToken = async () => {
40
+ const doRefresh = async () => {
41
+ const tokenData = (await require_getIntlayerAPI_oAuth.getOAuthAPI(intlayerConfig).getOAuth2AccessToken())?.data;
42
+ currentAccessToken = tokenData?.accessToken;
43
+ currentExpiryTs = getExpiryTimestamp(tokenData);
44
+ };
45
+ if (!pendingRefresh) pendingRefresh = doRefresh().finally(() => {
46
+ pendingRefresh = void 0;
47
+ });
48
+ await pendingRefresh;
49
+ };
50
+ const ensureValidToken = async () => {
51
+ if (needsRefresh()) await refreshToken();
52
+ };
53
+ const applyAuthHeaderToRef = () => {
54
+ if (!currentAccessToken) return;
55
+ authOptionsRef.headers = {
56
+ ...authOptionsRef.headers ?? {},
57
+ Authorization: `Bearer ${currentAccessToken}`
58
+ };
59
+ };
60
+ const wrapSection = (section, skipAuth = !hasCMSAuth) => {
61
+ return new Proxy(section, { get(target, prop, receiver) {
62
+ const value = Reflect.get(target, prop, receiver);
63
+ if (typeof value === "function") return async (...args) => {
64
+ if (!skipAuth) {
65
+ await ensureValidToken();
66
+ applyAuthHeaderToRef();
67
+ }
68
+ try {
69
+ return await value.apply(target, args);
70
+ } catch (err) {
71
+ if (!skipAuth) {
72
+ await refreshToken();
73
+ applyAuthHeaderToRef();
74
+ return await value.apply(target, args);
75
+ }
76
+ throw err;
77
+ }
78
+ };
79
+ return value;
80
+ } });
81
+ };
82
+ return {
83
+ organization: wrapSection(baseApi.organization),
84
+ project: wrapSection(baseApi.project),
85
+ user: wrapSection(baseApi.user),
86
+ oAuth: wrapSection(baseApi.oAuth, true),
87
+ dictionary: wrapSection(baseApi.dictionary),
88
+ stripe: wrapSection(baseApi.stripe),
89
+ ai: wrapSection(baseApi.ai),
90
+ tag: wrapSection(baseApi.tag),
91
+ search: wrapSection(baseApi.search),
92
+ editor: wrapSection(baseApi.editor),
93
+ newsletter: wrapSection(baseApi.newsletter)
94
+ };
119
95
  };
120
- // Annotate the CommonJS export names for ESM import in node:
121
- 0 && (module.exports = {
122
- getIntlayerAPIProxy
123
- });
96
+
97
+ //#endregion
98
+ exports.getIntlayerAPIProxy = getIntlayerAPIProxy;
124
99
  //# sourceMappingURL=proxy.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/proxy.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/config/client';\nimport type { FetcherOptions } from './fetcher';\nimport { getIntlayerAPI } from './getIntlayerAPI';\nimport type { IntlayerAPI } from './getIntlayerAPI/index';\nimport { getOAuthAPI } from './getIntlayerAPI/oAuth';\n\ntype OAuthTokenLike = {\n accessToken?: string;\n accessTokenExpiresAt?: string | Date;\n expires_in?: number;\n expiresIn?: number;\n expiresAt?: string | Date;\n};\n\nconst ONE_MINUTE_MS = 60_000;\n\n/**\n * Returns the expiration timestamp in ms from an OAuth token-like object.\n */\nconst getExpiryTimestamp = (\n token: OAuthTokenLike | undefined\n): number | undefined => {\n if (!token) return undefined;\n const dateLike = (token.accessTokenExpiresAt ?? token.expiresAt) as\n | string\n | Date\n | undefined;\n if (dateLike) {\n const ts =\n typeof dateLike === 'string'\n ? Date.parse(dateLike)\n : dateLike.getTime?.();\n if (typeof ts === 'number' && Number.isFinite(ts)) return ts;\n }\n const seconds = token.expires_in ?? token.expiresIn;\n if (typeof seconds === 'number' && Number.isFinite(seconds)) {\n return Date.now() + seconds * 1000;\n }\n return undefined;\n};\n\nlet currentAccessToken: string | undefined;\nlet currentExpiryTs: number | undefined;\nlet pendingRefresh: Promise<void> | undefined;\n\n/**\n * Build an auto-auth proxy around getIntlayerAPI that:\n * - Fetches an OAuth2 token when needed\n * - Injects Authorization header for each request\n * - Refreshes token proactively when near expiry\n *\n * The returned API matches the shape of getIntlayerAPI.\n */\nexport const getIntlayerAPIProxy = (\n _baseAuthOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n): IntlayerAPI => {\n // Use a shared mutable auth options object captured by the API closures\n const authOptionsRef: FetcherOptions = { ..._baseAuthOptions };\n const hasCMSAuth =\n intlayerConfig?.editor.clientId && intlayerConfig?.editor.clientSecret;\n const baseApi = getIntlayerAPI(authOptionsRef, intlayerConfig);\n\n const needsRefresh = (): boolean => {\n if (!currentAccessToken) return true;\n if (!currentExpiryTs) return false; // If unknown, assume usable until failure\n return Date.now() + ONE_MINUTE_MS >= currentExpiryTs; // refresh 1 min before expiry\n };\n\n const refreshToken = async (): Promise<void> => {\n const doRefresh = async () => {\n const authApi = getOAuthAPI(intlayerConfig);\n const res = await authApi.getOAuth2AccessToken();\n const tokenData = res?.data as OAuthTokenLike | undefined;\n currentAccessToken = tokenData?.accessToken;\n currentExpiryTs = getExpiryTimestamp(tokenData);\n };\n\n if (!pendingRefresh) {\n pendingRefresh = doRefresh().finally(() => {\n pendingRefresh = undefined;\n });\n }\n await pendingRefresh;\n };\n\n const ensureValidToken = async () => {\n if (needsRefresh()) {\n await refreshToken();\n }\n };\n\n const applyAuthHeaderToRef = () => {\n if (!currentAccessToken) return;\n authOptionsRef.headers = {\n ...(authOptionsRef.headers ?? {}),\n Authorization: `Bearer ${currentAccessToken}`,\n } as HeadersInit;\n };\n\n const wrapSection = <T extends Record<string, unknown>>(\n section: T,\n skipAuth = !hasCMSAuth\n ): T => {\n return new Proxy(section, {\n get(target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver);\n\n if (typeof value === 'function') {\n // Wrap section method to inject token and headers\n return async (...args: unknown[]) => {\n if (!skipAuth) {\n await ensureValidToken();\n applyAuthHeaderToRef();\n }\n\n try {\n return await value.apply(target, args);\n } catch (err) {\n // Best-effort retry: if token might be stale, refresh once and retry\n if (!skipAuth) {\n await refreshToken();\n applyAuthHeaderToRef();\n return await value.apply(target, args);\n }\n throw err;\n }\n };\n }\n\n return value;\n },\n });\n };\n\n return {\n organization: wrapSection(baseApi.organization),\n project: wrapSection(baseApi.project),\n user: wrapSection(baseApi.user),\n oAuth: wrapSection(baseApi.oAuth, true), // do NOT inject auth for token endpoint\n dictionary: wrapSection(baseApi.dictionary),\n stripe: wrapSection(baseApi.stripe),\n ai: wrapSection(baseApi.ai),\n tag: wrapSection(baseApi.tag),\n search: wrapSection(baseApi.search),\n editor: wrapSection(baseApi.editor),\n newsletter: wrapSection(baseApi.newsletter),\n } as IntlayerAPI;\n};\n\nexport type IntlayerAPIProxy = ReturnType<typeof getIntlayerAPIProxy>;\n"],"mappings":"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","names":[]}
1
+ {"version":3,"file":"proxy.cjs","names":["currentAccessToken: string | undefined","currentExpiryTs: number | undefined","pendingRefresh: Promise<void> | undefined","authOptionsRef: FetcherOptions","getIntlayerAPI","getOAuthAPI"],"sources":["../../src/proxy.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types';\nimport type { FetcherOptions } from './fetcher';\nimport { getIntlayerAPI } from './getIntlayerAPI';\nimport type { IntlayerAPI } from './getIntlayerAPI/index';\nimport { getOAuthAPI } from './getIntlayerAPI/oAuth';\n\ntype OAuthTokenLike = {\n accessToken?: string;\n accessTokenExpiresAt?: string | Date;\n expires_in?: number;\n expiresIn?: number;\n expiresAt?: string | Date;\n};\n\nconst ONE_MINUTE_MS = 60_000;\n\n/**\n * Returns the expiration timestamp in ms from an OAuth token-like object.\n */\nconst getExpiryTimestamp = (\n token: OAuthTokenLike | undefined\n): number | undefined => {\n if (!token) return undefined;\n const dateLike = (token.accessTokenExpiresAt ?? token.expiresAt) as\n | string\n | Date\n | undefined;\n if (dateLike) {\n const ts =\n typeof dateLike === 'string'\n ? Date.parse(dateLike)\n : dateLike.getTime?.();\n if (typeof ts === 'number' && Number.isFinite(ts)) return ts;\n }\n const seconds = token.expires_in ?? token.expiresIn;\n if (typeof seconds === 'number' && Number.isFinite(seconds)) {\n return Date.now() + seconds * 1000;\n }\n return undefined;\n};\n\nlet currentAccessToken: string | undefined;\nlet currentExpiryTs: number | undefined;\nlet pendingRefresh: Promise<void> | undefined;\n\n/**\n * Build an auto-auth proxy around getIntlayerAPI that:\n * - Fetches an OAuth2 token when needed\n * - Injects Authorization header for each request\n * - Refreshes token proactively when near expiry\n *\n * The returned API matches the shape of getIntlayerAPI.\n */\nexport const getIntlayerAPIProxy = (\n _baseAuthOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n): IntlayerAPI => {\n // Use a shared mutable auth options object captured by the API closures\n const authOptionsRef: FetcherOptions = { ..._baseAuthOptions };\n const hasCMSAuth =\n intlayerConfig?.editor?.clientId && intlayerConfig?.editor?.clientSecret;\n const baseApi = getIntlayerAPI(authOptionsRef, intlayerConfig);\n\n const needsRefresh = (): boolean => {\n if (!currentAccessToken) return true;\n if (!currentExpiryTs) return false; // If unknown, assume usable until failure\n\n return Date.now() + ONE_MINUTE_MS >= currentExpiryTs; // refresh 1 min before expiry\n };\n\n const refreshToken = async (): Promise<void> => {\n const doRefresh = async () => {\n const authApi = getOAuthAPI(intlayerConfig);\n const res = await authApi.getOAuth2AccessToken();\n const tokenData = res?.data as OAuthTokenLike | undefined;\n\n currentAccessToken = tokenData?.accessToken;\n currentExpiryTs = getExpiryTimestamp(tokenData);\n };\n\n if (!pendingRefresh) {\n pendingRefresh = doRefresh().finally(() => {\n pendingRefresh = undefined;\n });\n }\n await pendingRefresh;\n };\n\n const ensureValidToken = async () => {\n if (needsRefresh()) {\n await refreshToken();\n }\n };\n\n const applyAuthHeaderToRef = () => {\n if (!currentAccessToken) return;\n authOptionsRef.headers = {\n ...(authOptionsRef.headers ?? {}),\n Authorization: `Bearer ${currentAccessToken}`,\n } as HeadersInit;\n };\n\n const wrapSection = <T extends Record<string, unknown>>(\n section: T,\n skipAuth = !hasCMSAuth\n ): T => {\n return new Proxy(section, {\n get(target, prop, receiver) {\n const value = Reflect.get(target, prop, receiver);\n\n if (typeof value === 'function') {\n // Wrap section method to inject token and headers\n return async (...args: unknown[]) => {\n if (!skipAuth) {\n await ensureValidToken();\n applyAuthHeaderToRef();\n }\n\n try {\n return await value.apply(target, args);\n } catch (err) {\n // Best-effort retry: if token might be stale, refresh once and retry\n if (!skipAuth) {\n await refreshToken();\n applyAuthHeaderToRef();\n return await value.apply(target, args);\n }\n throw err;\n }\n };\n }\n\n return value;\n },\n });\n };\n\n return {\n organization: wrapSection(baseApi.organization),\n project: wrapSection(baseApi.project),\n user: wrapSection(baseApi.user),\n oAuth: wrapSection(baseApi.oAuth, true), // do NOT inject auth for token endpoint\n dictionary: wrapSection(baseApi.dictionary),\n stripe: wrapSection(baseApi.stripe),\n ai: wrapSection(baseApi.ai),\n tag: wrapSection(baseApi.tag),\n search: wrapSection(baseApi.search),\n editor: wrapSection(baseApi.editor),\n newsletter: wrapSection(baseApi.newsletter),\n } as IntlayerAPI;\n};\n\nexport type IntlayerAPIProxy = ReturnType<typeof getIntlayerAPIProxy>;\n"],"mappings":";;;;AAcA,MAAM,gBAAgB;;;;AAKtB,MAAM,sBACJ,UACuB;AACvB,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,WAAY,MAAM,wBAAwB,MAAM;AAItD,KAAI,UAAU;EACZ,MAAM,KACJ,OAAO,aAAa,WAChB,KAAK,MAAM,SAAS,GACpB,SAAS,WAAW;AAC1B,MAAI,OAAO,OAAO,YAAY,OAAO,SAAS,GAAG,CAAE,QAAO;;CAE5D,MAAM,UAAU,MAAM,cAAc,MAAM;AAC1C,KAAI,OAAO,YAAY,YAAY,OAAO,SAAS,QAAQ,CACzD,QAAO,KAAK,KAAK,GAAG,UAAU;;AAKlC,IAAIA;AACJ,IAAIC;AACJ,IAAIC;;;;;;;;;AAUJ,MAAa,uBACX,mBAAmC,EAAE,EACrC,mBACgB;CAEhB,MAAMC,iBAAiC,EAAE,GAAG,kBAAkB;CAC9D,MAAM,aACJ,gBAAgB,QAAQ,YAAY,gBAAgB,QAAQ;CAC9D,MAAM,UAAUC,4CAAe,gBAAgB,eAAe;CAE9D,MAAM,qBAA8B;AAClC,MAAI,CAAC,mBAAoB,QAAO;AAChC,MAAI,CAAC,gBAAiB,QAAO;AAE7B,SAAO,KAAK,KAAK,GAAG,iBAAiB;;CAGvC,MAAM,eAAe,YAA2B;EAC9C,MAAM,YAAY,YAAY;GAG5B,MAAM,aADM,MADIC,yCAAY,eAAe,CACjB,sBAAsB,GACzB;AAEvB,wBAAqB,WAAW;AAChC,qBAAkB,mBAAmB,UAAU;;AAGjD,MAAI,CAAC,eACH,kBAAiB,WAAW,CAAC,cAAc;AACzC,oBAAiB;IACjB;AAEJ,QAAM;;CAGR,MAAM,mBAAmB,YAAY;AACnC,MAAI,cAAc,CAChB,OAAM,cAAc;;CAIxB,MAAM,6BAA6B;AACjC,MAAI,CAAC,mBAAoB;AACzB,iBAAe,UAAU;GACvB,GAAI,eAAe,WAAW,EAAE;GAChC,eAAe,UAAU;GAC1B;;CAGH,MAAM,eACJ,SACA,WAAW,CAAC,eACN;AACN,SAAO,IAAI,MAAM,SAAS,EACxB,IAAI,QAAQ,MAAM,UAAU;GAC1B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAEjD,OAAI,OAAO,UAAU,WAEnB,QAAO,OAAO,GAAG,SAAoB;AACnC,QAAI,CAAC,UAAU;AACb,WAAM,kBAAkB;AACxB,2BAAsB;;AAGxB,QAAI;AACF,YAAO,MAAM,MAAM,MAAM,QAAQ,KAAK;aAC/B,KAAK;AAEZ,SAAI,CAAC,UAAU;AACb,YAAM,cAAc;AACpB,4BAAsB;AACtB,aAAO,MAAM,MAAM,MAAM,QAAQ,KAAK;;AAExC,WAAM;;;AAKZ,UAAO;KAEV,CAAC;;AAGJ,QAAO;EACL,cAAc,YAAY,QAAQ,aAAa;EAC/C,SAAS,YAAY,QAAQ,QAAQ;EACrC,MAAM,YAAY,QAAQ,KAAK;EAC/B,OAAO,YAAY,QAAQ,OAAO,KAAK;EACvC,YAAY,YAAY,QAAQ,WAAW;EAC3C,QAAQ,YAAY,QAAQ,OAAO;EACnC,IAAI,YAAY,QAAQ,GAAG;EAC3B,KAAK,YAAY,QAAQ,IAAI;EAC7B,QAAQ,YAAY,QAAQ,OAAO;EACnC,QAAQ,YAAY,QAAQ,OAAO;EACnC,YAAY,YAAY,QAAQ,WAAW;EAC5C"}
@@ -1,17 +0,0 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
17
- //# sourceMappingURL=types.cjs.map
@@ -1,23 +1,20 @@
1
- import configuration from "@intlayer/config/built";
2
1
  import { getIntlayerAPIProxy } from "../proxy.mjs";
3
- const fetchDistantDictionaries = async (intlayerConfig = configuration) => {
4
- try {
5
- const { clientId, clientSecret } = intlayerConfig?.editor;
6
- if (!clientId || !clientSecret) {
7
- throw new Error(
8
- "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
9
- );
10
- }
11
- const api = getIntlayerAPIProxy(void 0, intlayerConfig);
12
- const getDictionaryResult = await api.dictionary.getDictionaries();
13
- const distantDictionaries = getDictionaryResult.data;
14
- return distantDictionaries;
15
- } catch (error) {
16
- console.error(error);
17
- return void 0;
18
- }
19
- };
20
- export {
21
- fetchDistantDictionaries
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 getIntlayerAPIProxy(void 0, intlayerConfig).dictionary.getDictionaries()).data;
12
+ } catch (error) {
13
+ console.error(error);
14
+ return;
15
+ }
22
16
  };
17
+
18
+ //#endregion
19
+ export { fetchDistantDictionaries };
23
20
  //# sourceMappingURL=fetchDistantDictionaries.mjs.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":"AAEA,OAAO,mBAAmB;AAE1B,SAAS,2BAA2B;AAK7B,MAAM,2BAA2B,OACtC,iBAAiC,kBACe;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,MAAM,oBAAoB,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":[]}
1
+ {"version":3,"file":"fetchDistantDictionaries.mjs","names":[],"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,MAHhB,oBAAoB,QAAW,eAAe,CAGpB,WAAW,iBAAiB,EAElB;UAGzC,OAAO;AACd,UAAQ,MAAM,MAAM;AACpB"}
@@ -1,26 +1,22 @@
1
- import configuration from "@intlayer/config/built";
2
1
  import { getIntlayerAPIProxy } from "../proxy.mjs";
3
- const fetchDistantDictionary = async (dictionaryKey, intlayerConfig = configuration) => {
4
- try {
5
- const { clientId, clientSecret } = intlayerConfig?.editor;
6
- if (!clientId || !clientSecret) {
7
- throw new Error(
8
- "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
9
- );
10
- }
11
- const api = getIntlayerAPIProxy(void 0, intlayerConfig);
12
- const getDictionaryResult = await api.dictionary.getDictionary(dictionaryKey);
13
- const distantDictionary = getDictionaryResult.data;
14
- if (!distantDictionary) {
15
- throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
16
- }
17
- return distantDictionary;
18
- } catch (error) {
19
- console.error(error);
20
- return void 0;
21
- }
22
- };
23
- export {
24
- fetchDistantDictionary
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 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
+ }
25
18
  };
19
+
20
+ //#endregion
21
+ export { fetchDistantDictionary };
26
22
  //# sourceMappingURL=fetchDistantDictionary.mjs.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":"AAEA,OAAO,mBAAmB;AAE1B,SAAS,2BAA2B;AAK7B,MAAM,yBAAyB,OACpC,eACA,iBAAiC,kBACM;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,MAAM,oBAAoB,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":[]}
1
+ {"version":3,"file":"fetchDistantDictionary.mjs","names":[],"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,MAJU,oBAAoB,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,3 +1,4 @@
1
- export * from "./fetchDistantDictionaries.mjs";
2
- export * from "./fetchDistantDictionary.mjs";
3
- //# sourceMappingURL=index.mjs.map
1
+ import { fetchDistantDictionaries } from "./fetchDistantDictionaries.mjs";
2
+ import { fetchDistantDictionary } from "./fetchDistantDictionary.mjs";
3
+
4
+ export { fetchDistantDictionaries, fetchDistantDictionary };