@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.
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +18 -55
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +20 -58
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/distantDictionary/index.cjs +5 -25
- package/dist/cjs/fetcher.cjs +113 -89
- package/dist/cjs/fetcher.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs +163 -188
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/dictionary.cjs +69 -117
- package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/editor.cjs +37 -74
- package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/index.cjs +27 -49
- package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/newsletter.cjs +40 -77
- package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/oAuth.cjs +26 -65
- package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/organization.cjs +93 -130
- package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/project.cjs +109 -154
- package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/search.cjs +22 -58
- package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/stripe.cjs +38 -77
- package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/tag.cjs +47 -86
- package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/user.cjs +79 -106
- package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
- package/dist/cjs/index.cjs +30 -49
- package/dist/cjs/proxy.cjs +90 -115
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/cjs/types.cjs +0 -17
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +17 -20
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +19 -23
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/distantDictionary/index.mjs +4 -3
- package/dist/esm/fetcher.mjs +111 -64
- package/dist/esm/fetcher.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/ai.mjs +160 -153
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/dictionary.mjs +66 -82
- package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/editor.mjs +34 -39
- package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/index.mjs +16 -14
- package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/newsletter.mjs +37 -42
- package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/oAuth.mjs +23 -30
- package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/organization.mjs +90 -95
- package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/project.mjs +106 -119
- package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/search.mjs +19 -23
- package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/stripe.mjs +35 -42
- package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/tag.mjs +44 -51
- package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/user.mjs +76 -71
- package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
- package/dist/esm/index.mjs +16 -15
- package/dist/esm/proxy.mjs +89 -90
- package/dist/esm/proxy.mjs.map +1 -1
- package/dist/esm/types.mjs +0 -1
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +8 -3
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +8 -3
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
- package/dist/types/distantDictionary/index.d.ts +3 -3
- package/dist/types/fetcher.d.ts +14 -11
- package/dist/types/fetcher.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts +22 -18
- package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/dictionary.d.ts +16 -12
- package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/editor.d.ts +11 -7
- package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/index.d.ts +30 -27
- package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/newsletter.d.ts +11 -7
- package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/oAuth.d.ts +8 -5
- package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/organization.d.ts +18 -13
- package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/project.d.ts +19 -15
- package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/search.d.ts +9 -5
- package/dist/types/getIntlayerAPI/search.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/stripe.d.ts +11 -7
- package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/tag.d.ts +12 -8
- package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/user.d.ts +16 -12
- package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
- package/dist/types/index.d.ts +16 -15
- package/dist/types/proxy.d.ts +10 -5
- package/dist/types/proxy.d.ts.map +1 -1
- package/dist/types/types.d.ts +13 -12
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +29 -38
- package/LICENSE +0 -202
- package/dist/cjs/distantDictionary/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/types.cjs.map +0 -1
- package/dist/esm/distantDictionary/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/types/distantDictionary/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,49 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
package/dist/cjs/proxy.cjs
CHANGED
|
@@ -1,124 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
exports.getIntlayerAPIProxy = getIntlayerAPIProxy;
|
|
124
99
|
//# sourceMappingURL=proxy.cjs.map
|
package/dist/cjs/proxy.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/proxy.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/
|
|
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"}
|
package/dist/cjs/types.cjs
CHANGED
|
@@ -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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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":["
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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":["
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { fetchDistantDictionaries } from "./fetchDistantDictionaries.mjs";
|
|
2
|
+
import { fetchDistantDictionary } from "./fetchDistantDictionary.mjs";
|
|
3
|
+
|
|
4
|
+
export { fetchDistantDictionaries, fetchDistantDictionary };
|