@intlayer/api 9.0.0-canary.1 → 9.0.0-canary.11
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/cms/createAuthManager.cjs +116 -0
- package/dist/cjs/cms/createAuthManager.cjs.map +1 -0
- package/dist/cjs/cms/createIntlayerCMS.cjs +64 -0
- package/dist/cjs/cms/createIntlayerCMS.cjs.map +1 -0
- package/dist/cjs/cms/index.cjs +7 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +3 -2
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +3 -2
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/asset.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/asset.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/audit.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/audit.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/dictionary.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/editor.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/environment.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/environment.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/github.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/github.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/gitlab.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/gitlab.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/index.cjs +1 -1
- package/dist/cjs/getIntlayerAPI/newsletter.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/organization.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/project.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/reviewer.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/reviewer.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/search.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/showcaseProject.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/showcaseProject.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/stripe.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/tag.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/translate.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/translate.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/user.cjs +9 -0
- package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
- package/dist/cjs/index.cjs +27 -3
- package/dist/cjs/proxy.cjs +78 -97
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/esm/cms/createAuthManager.mjs +115 -0
- package/dist/esm/cms/createAuthManager.mjs.map +1 -0
- package/dist/esm/cms/createIntlayerCMS.mjs +62 -0
- package/dist/esm/cms/createIntlayerCMS.mjs.map +1 -0
- package/dist/esm/cms/index.mjs +4 -0
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +3 -2
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +3 -2
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/ai.mjs +9 -1
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/asset.mjs +9 -1
- package/dist/esm/getIntlayerAPI/asset.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/audit.mjs +9 -1
- package/dist/esm/getIntlayerAPI/audit.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/bitbucket.mjs +9 -1
- package/dist/esm/getIntlayerAPI/bitbucket.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/dictionary.mjs +9 -1
- package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/editor.mjs +9 -1
- package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/environment.mjs +9 -1
- package/dist/esm/getIntlayerAPI/environment.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/github.mjs +9 -1
- package/dist/esm/getIntlayerAPI/github.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/gitlab.mjs +9 -1
- package/dist/esm/getIntlayerAPI/gitlab.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/index.mjs +1 -1
- package/dist/esm/getIntlayerAPI/newsletter.mjs +9 -1
- package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/organization.mjs +9 -1
- package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/project.mjs +9 -1
- package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/reviewer.mjs +9 -1
- package/dist/esm/getIntlayerAPI/reviewer.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/search.mjs +9 -1
- package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/showcaseProject.mjs +9 -1
- package/dist/esm/getIntlayerAPI/showcaseProject.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/stripe.mjs +9 -1
- package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/tag.mjs +9 -1
- package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/translate.mjs +9 -1
- package/dist/esm/getIntlayerAPI/translate.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/user.mjs +9 -1
- package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
- package/dist/esm/index.mjs +23 -21
- package/dist/esm/proxy.mjs +78 -97
- package/dist/esm/proxy.mjs.map +1 -1
- package/dist/types/cms/createAuthManager.d.ts +103 -0
- package/dist/types/cms/createAuthManager.d.ts.map +1 -0
- package/dist/types/cms/createIntlayerCMS.d.ts +80 -0
- package/dist/types/cms/createIntlayerCMS.d.ts.map +1 -0
- package/dist/types/cms/index.d.ts +3 -0
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts +22 -2
- package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/asset.d.ts +19 -1
- package/dist/types/getIntlayerAPI/asset.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/audit.d.ts +24 -2
- package/dist/types/getIntlayerAPI/audit.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/bitbucket.d.ts +15 -1
- package/dist/types/getIntlayerAPI/bitbucket.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/dictionary.d.ts +19 -2
- package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/editor.d.ts +15 -2
- package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/environment.d.ts +17 -2
- package/dist/types/getIntlayerAPI/environment.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/github.d.ts +16 -1
- package/dist/types/getIntlayerAPI/github.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/gitlab.d.ts +15 -1
- package/dist/types/getIntlayerAPI/gitlab.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/index.d.ts +1 -1
- package/dist/types/getIntlayerAPI/newsletter.d.ts +14 -2
- package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/organization.d.ts +22 -2
- package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/project.d.ts +29 -2
- package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/reviewer.d.ts +46 -2
- package/dist/types/getIntlayerAPI/reviewer.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/search.d.ts +12 -2
- package/dist/types/getIntlayerAPI/search.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/showcaseProject.d.ts +23 -2
- package/dist/types/getIntlayerAPI/showcaseProject.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/stripe.d.ts +68 -2
- package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/tag.d.ts +15 -2
- package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/translate.d.ts +37 -2
- package/dist/types/getIntlayerAPI/translate.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/user.d.ts +20 -2
- package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
- package/dist/types/index.d.ts +23 -21
- package/dist/types/packages/@intlayer/unmerged-dictionaries-entry/dist/types/index.d.ts +10 -0
- package/dist/types/packages/@intlayer/unmerged-dictionaries-entry/dist/types/index.d.ts.map +1 -0
- package/dist/types/packages/intlayer-editor/server/dist/controllers/configuration.controller.d.ts +11 -0
- package/dist/types/packages/intlayer-editor/server/dist/controllers/configuration.controller.d.ts.map +1 -0
- package/dist/types/packages/intlayer-editor/server/dist/controllers/dictionary.controller.d.ts +25 -0
- package/dist/types/packages/intlayer-editor/server/dist/controllers/dictionary.controller.d.ts.map +1 -0
- package/dist/types/packages/intlayer-editor/server/dist/export.d.ts +2 -0
- package/dist/types/packages/intlayer-editor/server/dist/utils/httpStatusCodes.d.ts +408 -0
- package/dist/types/packages/intlayer-editor/server/dist/utils/httpStatusCodes.d.ts.map +1 -0
- package/dist/types/packages/intlayer-editor/server/dist/utils/responseData.d.ts +20 -0
- package/dist/types/packages/intlayer-editor/server/dist/utils/responseData.d.ts.map +1 -0
- package/dist/types/proxy.d.ts +11 -9
- package/dist/types/proxy.d.ts.map +1 -1
- package/package.json +12 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { getOAuthAPI } from "../getIntlayerAPI/oAuth.mjs";
|
|
2
|
+
import { editor } from "@intlayer/config/built";
|
|
3
|
+
import { defu } from "defu";
|
|
4
|
+
|
|
5
|
+
//#region src/cms/createAuthManager.ts
|
|
6
|
+
const ONE_MINUTE_MS = 6e4;
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the expiration timestamp (in ms since epoch) from an OAuth2
|
|
9
|
+
* token-like payload, supporting both absolute dates and relative durations.
|
|
10
|
+
*/
|
|
11
|
+
const getExpiryTimestamp = (token) => {
|
|
12
|
+
if (!token) return void 0;
|
|
13
|
+
const dateLike = token.accessTokenExpiresAt ?? token.expiresAt;
|
|
14
|
+
if (dateLike) {
|
|
15
|
+
const timestamp = typeof dateLike === "string" ? Date.parse(dateLike) : dateLike.getTime?.();
|
|
16
|
+
if (typeof timestamp === "number" && Number.isFinite(timestamp)) return timestamp;
|
|
17
|
+
}
|
|
18
|
+
const seconds = token.expires_in ?? token.expiresIn;
|
|
19
|
+
if (typeof seconds === "number" && Number.isFinite(seconds)) return Date.now() + seconds * 1e3;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance-scoped {@link AuthManager} handling the OAuth2
|
|
23
|
+
* `client_credentials` flow (or a pre-issued CLI session token).
|
|
24
|
+
*
|
|
25
|
+
* Unlike a global token cache, each manager keeps its own token state, so
|
|
26
|
+
* independent SDK instances never interfere with one another.
|
|
27
|
+
*
|
|
28
|
+
* @param intlayerConfig - Intlayer configuration carrying the `editor`
|
|
29
|
+
* credentials. Defaults to the build-time configuration.
|
|
30
|
+
* @param options - Optional session token and base fetcher options.
|
|
31
|
+
*/
|
|
32
|
+
const createAuthManager = (intlayerConfig = { editor }, options = {}) => {
|
|
33
|
+
const { baseFetcherOptions = {}, sessionToken } = options;
|
|
34
|
+
const resolvedConfig = defu(intlayerConfig ?? {}, { editor });
|
|
35
|
+
const fetcherOptions = {
|
|
36
|
+
...baseFetcherOptions,
|
|
37
|
+
credentials: "omit"
|
|
38
|
+
};
|
|
39
|
+
const hasCredentials = Boolean(sessionToken) || Boolean(resolvedConfig?.editor?.clientId && resolvedConfig?.editor?.clientSecret);
|
|
40
|
+
if (sessionToken) fetcherOptions.headers = {
|
|
41
|
+
...fetcherOptions.headers ?? {},
|
|
42
|
+
Authorization: `Bearer ${sessionToken}`
|
|
43
|
+
};
|
|
44
|
+
let accessToken;
|
|
45
|
+
let expiryTimestamp;
|
|
46
|
+
let pendingRefresh;
|
|
47
|
+
const needsRefresh = () => {
|
|
48
|
+
if (!accessToken) return true;
|
|
49
|
+
if (!expiryTimestamp) return false;
|
|
50
|
+
return Date.now() + ONE_MINUTE_MS >= expiryTimestamp;
|
|
51
|
+
};
|
|
52
|
+
const refreshToken = async () => {
|
|
53
|
+
const doRefresh = async () => {
|
|
54
|
+
const tokenData = (await getOAuthAPI({}, resolvedConfig).getOAuth2AccessToken())?.data;
|
|
55
|
+
accessToken = tokenData?.accessToken;
|
|
56
|
+
expiryTimestamp = getExpiryTimestamp(tokenData);
|
|
57
|
+
};
|
|
58
|
+
pendingRefresh ??= doRefresh().finally(() => {
|
|
59
|
+
pendingRefresh = void 0;
|
|
60
|
+
});
|
|
61
|
+
await pendingRefresh;
|
|
62
|
+
};
|
|
63
|
+
const applyAuthHeader = () => {
|
|
64
|
+
if (!accessToken) return;
|
|
65
|
+
fetcherOptions.headers = {
|
|
66
|
+
...fetcherOptions.headers ?? {},
|
|
67
|
+
Authorization: `Bearer ${accessToken}`
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const ensureAuth = async () => {
|
|
71
|
+
if (sessionToken) return;
|
|
72
|
+
if (needsRefresh()) await refreshToken();
|
|
73
|
+
applyAuthHeader();
|
|
74
|
+
};
|
|
75
|
+
const reset = () => {
|
|
76
|
+
accessToken = void 0;
|
|
77
|
+
expiryTimestamp = void 0;
|
|
78
|
+
};
|
|
79
|
+
const withAuth = (method, skipAuth = !hasCredentials) => {
|
|
80
|
+
if (skipAuth) return method;
|
|
81
|
+
return async (...args) => {
|
|
82
|
+
await ensureAuth();
|
|
83
|
+
try {
|
|
84
|
+
return await method(...args);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (sessionToken) throw error;
|
|
87
|
+
await refreshToken();
|
|
88
|
+
applyAuthHeader();
|
|
89
|
+
return await method(...args);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const bindSection = (factory, bindOptions = {}) => {
|
|
94
|
+
const section = factory(fetcherOptions, resolvedConfig);
|
|
95
|
+
const skipAuth = bindOptions.skipAuth ?? !hasCredentials;
|
|
96
|
+
return new Proxy(section, { get(target, property, receiver) {
|
|
97
|
+
const value = Reflect.get(target, property, receiver);
|
|
98
|
+
if (typeof value !== "function") return value;
|
|
99
|
+
return withAuth(value.bind(target), skipAuth);
|
|
100
|
+
} });
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
fetcherOptions,
|
|
104
|
+
intlayerConfig: resolvedConfig,
|
|
105
|
+
hasCredentials,
|
|
106
|
+
ensureAuth,
|
|
107
|
+
reset,
|
|
108
|
+
withAuth,
|
|
109
|
+
bindSection
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
export { createAuthManager };
|
|
115
|
+
//# sourceMappingURL=createAuthManager.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createAuthManager.mjs","names":[],"sources":["../../../src/cms/createAuthManager.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { defu } from 'defu';\nimport type { FetcherOptions } from '../fetcher';\nimport { getOAuthAPI } from '../getIntlayerAPI/oAuth';\n\n/**\n * Shape of the various OAuth2 token payloads the backend may return. Only the\n * fields used to derive the expiration timestamp are described here.\n */\ntype OAuthTokenLike = {\n accessToken?: string;\n accessTokenExpiresAt?: string | Date;\n expires_in?: number;\n expiresIn?: number;\n expiresAt?: string | Date;\n};\n\n/**\n * Any asynchronous API method exposed by a domain section\n * (e.g. `getDictionaries`, `pushDictionaries`).\n */\ntype AsyncMethod<Arguments extends unknown[], Result> = (\n ...args: Arguments\n) => Promise<Result>;\n\n/**\n * A domain section factory: builds a plain object of async methods from shared\n * fetcher options and the Intlayer configuration.\n */\ntype SectionFactory<Section extends Record<string, unknown>> = (\n fetcherOptions: FetcherOptions,\n intlayerConfig: IntlayerConfig\n) => Section;\n\nconst ONE_MINUTE_MS = 60_000;\n\n/**\n * Resolves the expiration timestamp (in ms since epoch) from an OAuth2\n * token-like payload, supporting both absolute dates and relative durations.\n */\nconst getExpiryTimestamp = (\n token: OAuthTokenLike | undefined\n): number | undefined => {\n if (!token) return undefined;\n\n const dateLike = (token.accessTokenExpiresAt ?? token.expiresAt) as\n | string\n | Date\n | undefined;\n\n if (dateLike) {\n const timestamp =\n typeof dateLike === 'string'\n ? Date.parse(dateLike)\n : dateLike.getTime?.();\n if (typeof timestamp === 'number' && Number.isFinite(timestamp)) {\n return timestamp;\n }\n }\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\n return undefined;\n};\n\n/**\n * Options accepted when creating an {@link AuthManager}.\n */\nexport type AuthManagerOptions = {\n /**\n * Base fetcher options merged into every request (e.g. custom headers).\n */\n baseFetcherOptions?: FetcherOptions;\n /**\n * A pre-issued CLI session token (prefixed with `clisession_`). When provided,\n * it is used directly as the Bearer token and the OAuth2 `client_credentials`\n * exchange is skipped entirely.\n */\n sessionToken?: string;\n};\n\n/**\n * Options accepted when binding a domain section to an {@link AuthManager}.\n */\nexport type BindSectionOptions = {\n /**\n * Forces auth injection on (`false`) or off (`true`). Defaults to enabled\n * whenever credentials are available.\n */\n skipAuth?: boolean;\n};\n\n/**\n * Manages CMS authentication for a set of API calls.\n *\n * The manager owns a single mutable {@link FetcherOptions} object\n * (`fetcherOptions`). Domain factories bound through it share the same\n * reference, so refreshing the token in place transparently authenticates every\n * call — without rebuilding the API clients.\n */\nexport type AuthManager = {\n /**\n * Mutable fetcher options carrying the `Authorization` header. Bound sections\n * share this reference so the injected token is reused everywhere.\n */\n fetcherOptions: FetcherOptions;\n /**\n * The resolved Intlayer configuration (merged with the build-time defaults).\n */\n intlayerConfig: IntlayerConfig;\n /**\n * `true` when credentials are available — either a session token or a\n * `clientId`/`clientSecret` pair in the configuration.\n */\n hasCredentials: boolean;\n /**\n * Ensures a valid access token is available and applies it to\n * `fetcherOptions`. Called automatically by {@link withAuth}.\n */\n ensureAuth: () => Promise<void>;\n /**\n * Forces a token refresh on the next call by clearing the cached token.\n */\n reset: () => void;\n /**\n * Wraps a single API method so it injects (and, on failure, refreshes) the\n * access token on every invocation while preserving the method's signature.\n */\n withAuth: <Arguments extends unknown[], Result>(\n method: AsyncMethod<Arguments, Result>,\n skipAuth?: boolean\n ) => AsyncMethod<Arguments, Result>;\n /**\n * Instantiates a domain factory with the managed fetcher options and config,\n * returning a section whose every method authenticates automatically.\n *\n * @example\n * ```ts\n * const dictionary = authManager.bindSection(getDictionaryAPI);\n * await dictionary.pushDictionaries(dictionaries);\n * ```\n */\n bindSection: <Section extends Record<string, unknown>>(\n factory: SectionFactory<Section>,\n options?: BindSectionOptions\n ) => Section;\n};\n\n/**\n * Creates an instance-scoped {@link AuthManager} handling the OAuth2\n * `client_credentials` flow (or a pre-issued CLI session token).\n *\n * Unlike a global token cache, each manager keeps its own token state, so\n * independent SDK instances never interfere with one another.\n *\n * @param intlayerConfig - Intlayer configuration carrying the `editor`\n * credentials. Defaults to the build-time configuration.\n * @param options - Optional session token and base fetcher options.\n */\nexport const createAuthManager = (\n intlayerConfig: Pick<IntlayerConfig, 'editor'> = { editor },\n options: AuthManagerOptions = {}\n): AuthManager => {\n const { baseFetcherOptions = {}, sessionToken } = options;\n\n const resolvedConfig = defu(intlayerConfig ?? {}, {\n editor,\n }) as IntlayerConfig;\n\n // `credentials: 'omit'` prevents the browser from attaching session cookies;\n // authentication is handled exclusively through the injected Bearer token.\n // This is required because the backend only allows credentialed requests for\n // whitelisted first-party origins.\n const fetcherOptions: FetcherOptions = {\n ...baseFetcherOptions,\n credentials: 'omit',\n };\n\n const hasCredentials =\n Boolean(sessionToken) ||\n Boolean(\n resolvedConfig?.editor?.clientId && resolvedConfig?.editor?.clientSecret\n );\n\n // A session token is used as-is and never expires within the SDK's concern,\n // so inject it once up-front and skip the OAuth2 exchange.\n if (sessionToken) {\n fetcherOptions.headers = {\n ...(fetcherOptions.headers ?? {}),\n Authorization: `Bearer ${sessionToken}`,\n } as HeadersInit;\n }\n\n let accessToken: string | undefined;\n let expiryTimestamp: number | undefined;\n let pendingRefresh: Promise<void> | undefined;\n\n const needsRefresh = (): boolean => {\n if (!accessToken) return true;\n if (!expiryTimestamp) return false; // Unknown expiry: assume usable until failure.\n\n // Refresh one minute before the actual expiry to avoid edge-of-expiry races.\n return Date.now() + ONE_MINUTE_MS >= expiryTimestamp;\n };\n\n const refreshToken = async (): Promise<void> => {\n const doRefresh = async (): Promise<void> => {\n const oAuthAPI = getOAuthAPI({}, resolvedConfig);\n const response = await oAuthAPI.getOAuth2AccessToken();\n const tokenData = response?.data as OAuthTokenLike | undefined;\n\n accessToken = tokenData?.accessToken;\n expiryTimestamp = getExpiryTimestamp(tokenData);\n };\n\n // De-duplicate concurrent refreshes so a burst of calls triggers one fetch.\n pendingRefresh ??= doRefresh().finally(() => {\n pendingRefresh = undefined;\n });\n\n await pendingRefresh;\n };\n\n const applyAuthHeader = (): void => {\n if (!accessToken) return;\n fetcherOptions.headers = {\n ...(fetcherOptions.headers ?? {}),\n Authorization: `Bearer ${accessToken}`,\n } as HeadersInit;\n };\n\n const ensureAuth = async (): Promise<void> => {\n if (sessionToken) return; // Already injected; nothing to refresh.\n if (needsRefresh()) {\n await refreshToken();\n }\n applyAuthHeader();\n };\n\n const reset = (): void => {\n accessToken = undefined;\n expiryTimestamp = undefined;\n };\n\n const withAuth = <Arguments extends unknown[], Result>(\n method: AsyncMethod<Arguments, Result>,\n skipAuth = !hasCredentials\n ): AsyncMethod<Arguments, Result> => {\n if (skipAuth) return method;\n\n return async (...args: Arguments): Promise<Result> => {\n await ensureAuth();\n\n try {\n return await method(...args);\n } catch (error) {\n // The token may have been revoked or expired early: refresh once and\n // retry before surfacing the error. A session token cannot be\n // refreshed, so re-throw immediately in that case.\n if (sessionToken) throw error;\n\n await refreshToken();\n applyAuthHeader();\n return await method(...args);\n }\n };\n };\n\n const bindSection = <Section extends Record<string, unknown>>(\n factory: SectionFactory<Section>,\n bindOptions: BindSectionOptions = {}\n ): Section => {\n const section = factory(fetcherOptions, resolvedConfig);\n const skipAuth = bindOptions.skipAuth ?? !hasCredentials;\n\n return new Proxy(section, {\n get(target, property, receiver) {\n const value = Reflect.get(target, property, receiver);\n\n if (typeof value !== 'function') return value;\n\n return withAuth(\n (value as AsyncMethod<unknown[], unknown>).bind(target),\n skipAuth\n );\n },\n });\n };\n\n return {\n fetcherOptions,\n intlayerConfig: resolvedConfig,\n hasCredentials,\n ensureAuth,\n reset,\n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AiB;IACjB;AAEF,QAAM;;CAGR,MAAM,wBAA8B;AAClC,MAAI,CAAC,YAAa;AAClB,iBAAe,UAAU;GACvB,GAAI,eAAe,WAAW,EAAE;GAChC,eAAe,UAAU;GAC1B;;CAGH,MAAM,aAAa,YAA2B;AAC5C,MAAI,aAAc;AAClB,MAAI,cAAc,CAChB,OAAM,cAAc;AAEtB,mBAAiB;;CAGnB,MAAM,cAAoB;AACxB,gBAAc;AACd,oBAAkB;;CAGpB,MAAM,YACJ,QACA,WAAW,CAAC,mBACuB;AACnC,MAAI,SAAU,QAAO;AAErB,SAAO,OAAO,GAAG,SAAqC;AACpD,SAAM,YAAY;AAElB,OAAI;AACF,WAAO,MAAM,OAAO,GAAG,KAAK;YACrB,OAAO;AAId,QAAI,aAAc,OAAM;AAExB,UAAM,cAAc;AACpB,qBAAiB;AACjB,WAAO,MAAM,OAAO,GAAG,KAAK;;;;CAKlC,MAAM,eACJ,SACA,cAAkC,EAAE,KACxB;EACZ,MAAM,UAAU,QAAQ,gBAAgB,eAAe;EACvD,MAAM,WAAW,YAAY,YAAY,CAAC;AAE1C,SAAO,IAAI,MAAM,SAAS,EACxB,IAAI,QAAQ,UAAU,UAAU;GAC9B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,UAAU,SAAS;AAErD,OAAI,OAAO,UAAU,WAAY,QAAO;AAExC,UAAO,SACJ,MAA0C,KAAK,OAAO,EACvD,SACD;KAEJ,CAAC;;AAGJ,QAAO;EACL;EACA,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createAuthManager } from "./createAuthManager.mjs";
|
|
2
|
+
import { editor } from "@intlayer/config/built";
|
|
3
|
+
|
|
4
|
+
//#region src/cms/createIntlayerCMS.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates an Intlayer CMS authenticator handling authentication automatically
|
|
7
|
+
* (OAuth2 `client_credentials`, or a CLI session token).
|
|
8
|
+
*
|
|
9
|
+
* This factory is intentionally lightweight: it does **not** bundle any domain
|
|
10
|
+
* client. Combine it with the per-domain endpoint binders — imported separately
|
|
11
|
+
* so only the domains you use are included in your bundle.
|
|
12
|
+
*
|
|
13
|
+
* The configuration is optional: when omitted, the credentials are read from the
|
|
14
|
+
* build-time configuration (`@intlayer/config/built`), which resolves the
|
|
15
|
+
* `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET` environment variables.
|
|
16
|
+
*
|
|
17
|
+
* > Security: the CMS credentials grant write access to your content. Only ever
|
|
18
|
+
* > create the authenticator on the server side — never ship `clientId` /
|
|
19
|
+
* > `clientSecret` to the browser.
|
|
20
|
+
*
|
|
21
|
+
* @param intlayerConfig - Intlayer configuration carrying the `editor`
|
|
22
|
+
* credentials. Defaults to the build-time configuration.
|
|
23
|
+
* @param options - Optional CLI session token and base fetcher options.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { createIntlayerCMS } from '@intlayer/api';
|
|
28
|
+
* import { dictionaryEndpoint } from '@intlayer/api/dictionary';
|
|
29
|
+
*
|
|
30
|
+
* // Optional: reads INTLAYER_CLIENT_ID / INTLAYER_CLIENT_SECRET when omitted
|
|
31
|
+
* const cms = createIntlayerCMS();
|
|
32
|
+
*
|
|
33
|
+
* // Read
|
|
34
|
+
* const { data: dictionaries } = await dictionaryEndpoint(cms).getDictionaries();
|
|
35
|
+
*
|
|
36
|
+
* // Write
|
|
37
|
+
* await dictionaryEndpoint(cms).pushDictionaries([myDictionary]);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
const createIntlayerCMS = (intlayerConfig = { editor }, options = {}) => createAuthManager(intlayerConfig, options);
|
|
41
|
+
/**
|
|
42
|
+
* Turns a domain factory into a tree-shakeable endpoint binder.
|
|
43
|
+
*
|
|
44
|
+
* Each endpoint pulls in only its own domain client plus the auth machinery, so
|
|
45
|
+
* importing `dictionaryEndpoint` never bundles the project, AI, or any other
|
|
46
|
+
* domain.
|
|
47
|
+
*
|
|
48
|
+
* @param factory - The domain factory (e.g. `getDictionaryAPI`).
|
|
49
|
+
* @param options - Binding options, e.g. `{ skipAuth: true }` for the token
|
|
50
|
+
* endpoint itself.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* // inside @intlayer/api/dictionary
|
|
55
|
+
* export const dictionaryEndpoint = createEndpoint(getDictionaryAPI);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const createEndpoint = (factory, options) => (cms = createIntlayerCMS()) => cms.bindSection(factory, options);
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { createEndpoint, createIntlayerCMS };
|
|
62
|
+
//# sourceMappingURL=createIntlayerCMS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIntlayerCMS.mjs","names":[],"sources":["../../../src/cms/createIntlayerCMS.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { FetcherOptions } from '../fetcher';\nimport {\n type AuthManager,\n type AuthManagerOptions,\n type BindSectionOptions,\n createAuthManager,\n} from './createAuthManager';\n\n/**\n * Options accepted when creating the Intlayer CMS authenticator.\n */\nexport type IntlayerCMSOptions = AuthManagerOptions;\n\n/**\n * The Intlayer CMS authenticator returned by {@link createIntlayerCMS}.\n *\n * It is a lightweight object that holds the credentials and the managed token,\n * but knows nothing about individual domains. Pair it with a domain endpoint\n * (e.g. `dictionaryEndpoint`) to issue authenticated requests.\n */\nexport type IntlayerCMS = AuthManager;\n\n/**\n * Creates an Intlayer CMS authenticator handling authentication automatically\n * (OAuth2 `client_credentials`, or a CLI session token).\n *\n * This factory is intentionally lightweight: it does **not** bundle any domain\n * client. Combine it with the per-domain endpoint binders — imported separately\n * so only the domains you use are included in your bundle.\n *\n * The configuration is optional: when omitted, the credentials are read from the\n * build-time configuration (`@intlayer/config/built`), which resolves the\n * `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET` environment variables.\n *\n * > Security: the CMS credentials grant write access to your content. Only ever\n * > create the authenticator on the server side — never ship `clientId` /\n * > `clientSecret` to the browser.\n *\n * @param intlayerConfig - Intlayer configuration carrying the `editor`\n * credentials. Defaults to the build-time configuration.\n * @param options - Optional CLI session token and base fetcher options.\n *\n * @example\n * ```ts\n * import { createIntlayerCMS } from '@intlayer/api';\n * import { dictionaryEndpoint } from '@intlayer/api/dictionary';\n *\n * // Optional: reads INTLAYER_CLIENT_ID / INTLAYER_CLIENT_SECRET when omitted\n * const cms = createIntlayerCMS();\n *\n * // Read\n * const { data: dictionaries } = await dictionaryEndpoint(cms).getDictionaries();\n *\n * // Write\n * await dictionaryEndpoint(cms).pushDictionaries([myDictionary]);\n * ```\n */\nexport const createIntlayerCMS = (\n intlayerConfig: Pick<IntlayerConfig, 'editor'> = { editor },\n options: IntlayerCMSOptions = {}\n): IntlayerCMS => createAuthManager(intlayerConfig, options);\n\n/**\n * A domain endpoint binder: given an authenticator (or none, in which case a\n * default one is created from the build-time configuration), returns the\n * authenticated domain section.\n */\nexport type CMSEndpoint<Section extends Record<string, unknown>> = (\n cms?: IntlayerCMS\n) => Section;\n\n/**\n * Turns a domain factory into a tree-shakeable endpoint binder.\n *\n * Each endpoint pulls in only its own domain client plus the auth machinery, so\n * importing `dictionaryEndpoint` never bundles the project, AI, or any other\n * domain.\n *\n * @param factory - The domain factory (e.g. `getDictionaryAPI`).\n * @param options - Binding options, e.g. `{ skipAuth: true }` for the token\n * endpoint itself.\n *\n * @example\n * ```ts\n * // inside @intlayer/api/dictionary\n * export const dictionaryEndpoint = createEndpoint(getDictionaryAPI);\n * ```\n */\nexport const createEndpoint =\n <Section extends Record<string, unknown>>(\n factory: (\n fetcherOptions: FetcherOptions,\n intlayerConfig: IntlayerConfig\n ) => Section,\n options?: BindSectionOptions\n ): CMSEndpoint<Section> =>\n (cms: IntlayerCMS = createIntlayerCMS()): Section =>\n cms.bindSection(factory, options);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,MAAa,qBACX,iBAAiD,EAAE,QAAQ,EAC3D,UAA8B,EAAE,KAChB,kBAAkB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;AA4B5D,MAAa,kBAET,SAIA,aAED,MAAmB,mBAAmB,KACrC,IAAI,YAAY,SAAS,QAAQ"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createIntlayerCMS } from "../cms/createIntlayerCMS.mjs";
|
|
2
|
+
import { dictionaryEndpoint } from "../getIntlayerAPI/dictionary.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/distantDictionary/fetchDistantDictionaries.ts
|
|
4
5
|
/**
|
|
@@ -8,7 +9,7 @@ const fetchDistantDictionaries = async (intlayerConfig) => {
|
|
|
8
9
|
try {
|
|
9
10
|
const { clientId, clientSecret } = intlayerConfig.editor;
|
|
10
11
|
if (!clientId || !clientSecret) throw new Error("Missing OAuth2 client ID or client secret. To get access token go to https://app.intlayer.org/project.");
|
|
11
|
-
return (await
|
|
12
|
+
return (await dictionaryEndpoint(createIntlayerCMS(intlayerConfig)).getDictionaries()).data;
|
|
12
13
|
} catch (error) {
|
|
13
14
|
console.error(error);
|
|
14
15
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchDistantDictionaries.mjs","names":[],"sources":["../../../src/distantDictionary/fetchDistantDictionaries.ts"],"sourcesContent":["import type { DictionaryAPI } from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {
|
|
1
|
+
{"version":3,"file":"fetchDistantDictionaries.mjs","names":[],"sources":["../../../src/distantDictionary/fetchDistantDictionaries.ts"],"sourcesContent":["import type { DictionaryAPI } from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createIntlayerCMS } from '../cms/createIntlayerCMS';\nimport { dictionaryEndpoint } from '../getIntlayerAPI/dictionary';\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://app.intlayer.org/project.'\n );\n }\n\n const dictionary = dictionaryEndpoint(createIntlayerCMS(intlayerConfig));\n\n // Fetch the dictionary list\n const getDictionaryResult = await 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":";;;;;;;AAQA,MAAa,2BAA2B,OACtC,mBACgD;AAChD,KAAI;EACF,MAAM,EAAE,UAAU,iBAAiB,eAAe;AAElD,MAAI,CAAC,YAAY,CAAC,aAChB,OAAM,IAAI,MACR,yGACD;AAUH,UAF4B,MALT,mBAAmB,kBAAkB,eAAe,CAG3B,CAAC,iBAAiB,EAEd;UAGzC,OAAO;AACd,UAAQ,MAAM,MAAM;AACpB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createIntlayerCMS } from "../cms/createIntlayerCMS.mjs";
|
|
2
|
+
import { dictionaryEndpoint } from "../getIntlayerAPI/dictionary.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/distantDictionary/fetchDistantDictionary.ts
|
|
4
5
|
/**
|
|
@@ -8,7 +9,7 @@ const fetchDistantDictionary = async (dictionaryKey, intlayerConfig) => {
|
|
|
8
9
|
try {
|
|
9
10
|
const { clientId, clientSecret } = intlayerConfig.editor;
|
|
10
11
|
if (!clientId || !clientSecret) throw new Error("Missing OAuth2 client ID or client secret. To get access token go to https://app.intlayer.org/project.");
|
|
11
|
-
const distantDictionary = (await
|
|
12
|
+
const distantDictionary = (await dictionaryEndpoint(createIntlayerCMS(intlayerConfig)).getDictionary(dictionaryKey)).data;
|
|
12
13
|
if (!distantDictionary) throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
|
|
13
14
|
return distantDictionary;
|
|
14
15
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchDistantDictionary.mjs","names":[],"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import type { DictionaryAPI } from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport {
|
|
1
|
+
{"version":3,"file":"fetchDistantDictionary.mjs","names":[],"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import type { DictionaryAPI } from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createIntlayerCMS } from '../cms/createIntlayerCMS';\nimport { dictionaryEndpoint } from '../getIntlayerAPI/dictionary';\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://app.intlayer.org/project.'\n );\n }\n\n const dictionary = dictionaryEndpoint(createIntlayerCMS(intlayerConfig));\n\n // Fetch the dictionary\n const getDictionaryResult = await 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":";;;;;;;AAQA,MAAa,yBAAyB,OACpC,eACA,mBACuC;AACvC,KAAI;EACF,MAAM,EAAE,UAAU,iBAAiB,eAAe;AAElD,MAAI,CAAC,YAAY,CAAC,aAChB,OAAM,IAAI,MACR,yGACD;EAQH,MAAM,qBAAoB,MALP,mBAAmB,kBAAkB,eAAe,CAG3B,CAAC,cAAc,cAAc,EAE3B;AAE9C,MAAI,CAAC,kBACH,OAAM,IAAI,MAAM,cAAc,cAAc,sBAAsB;AAGpE,SAAO;UACA,OAAO;AACd,UAAQ,MAAM,MAAM;AACpB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
|
+
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
2
3
|
import { editor } from "@intlayer/config/built";
|
|
3
4
|
|
|
4
5
|
//#region src/getIntlayerAPI/ai.ts
|
|
@@ -222,7 +223,14 @@ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
222
223
|
getAIStats
|
|
223
224
|
};
|
|
224
225
|
};
|
|
226
|
+
/**
|
|
227
|
+
* Authenticated `ai` endpoint bound to an Intlayer CMS authenticator.
|
|
228
|
+
*
|
|
229
|
+
* Pass an authenticator created with `createIntlayerCMS`, or omit it to use
|
|
230
|
+
* the build-time configuration (`@intlayer/config/built`).
|
|
231
|
+
*/
|
|
232
|
+
const aiEndpoint = createEndpoint(getAiAPI);
|
|
225
233
|
|
|
226
234
|
//#endregion
|
|
227
|
-
export { getAiAPI };
|
|
235
|
+
export { aiEndpoint, getAiAPI };
|
|
228
236
|
//# sourceMappingURL=ai.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.mjs","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import type {\n AIOptions,\n AskDocQuestionResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n ChatResult,\n CustomQueryBody,\n CustomQueryResult,\n GetAIStatsResult,\n GetDiscussionsParams,\n GetDiscussionsResult,\n TranslateJSONBody,\n TranslateJSONResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type AutocompleteBody = {\n text: string;\n aiOptions?: AIOptions;\n contextBefore?: string;\n currentLine?: string;\n contextAfter?: string;\n};\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: AskDocQuestionResult) => void;\n};\n\nexport type ClientAction =\n | { type: 'navigate'; path: string }\n | { type: 'invalidate_queries' };\n\nexport type ChatBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: ChatResult) => void;\n onAction?: (action: ClientAction) => void;\n};\n\nexport type { AskDocQuestionResult, ChatResult };\n\nexport const getAiAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const AI_API_ROUTE = `${backendURL}/api/ai`;\n\n /**\n * Custom query\n * @param body - Custom query parameters.\n * @returns Custom query result.\n */\n const customQuery = async (\n body?: CustomQueryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CustomQueryResult>(\n AI_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Translate a JSON\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const translateJSON = async (\n body?: TranslateJSONBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TranslateJSONResult>(\n `${AI_API_ROUTE}/translate/json`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclaration = async (\n body?: AuditContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationResult>(\n `${AI_API_ROUTE}/audit/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration field\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationField = async (\n body?: AuditContentDeclarationFieldBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationFieldResult>(\n `${AI_API_ROUTE}/audit/dictionary/field`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file to retrieve title, description and tags\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationMetadata = async (\n body?: AuditContentDeclarationMetadataBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationMetadataResult>(\n `${AI_API_ROUTE}/audit/dictionary/metadata`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a tag\n * @param body - Audit tag parameters.\n * @returns Audited tag content.\n */\n const auditTag = async (\n body?: AuditTagBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditTagResult>(\n `${AI_API_ROUTE}/audit/tag`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Asks a question to the AI related to the documentation **and streams the\n * answer as Server‑Sent Events (SSE)**.\n *\n * The function **returns immediately** with a handle exposing:\n * - `promise` → resolves when the stream completes (or rejects on error)\n * - `abort()` → allows canceling the request on demand\n *\n * Usage example:\n * ```ts\n * const { promise, abort } = ai.askDocQuestion({\n * ...body,\n * onMessage: console.log,\n * onDone: (full) => console.log(\"✔\", full),\n * });\n * // later → abort();\n * await promise; // waits for completion if desired\n * ```\n */\n const askDocQuestion = async (\n body?: AskDocQuestionBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body) return;\n\n const { onMessage, onDone, ...rest } = body;\n const abortController = new AbortController();\n\n try {\n const response = await fetch(`${AI_API_ROUTE}/ask`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n body: JSON.stringify({\n ...rest,\n ...authAPIOptions.body,\n ...otherOptions.body,\n }),\n signal: abortController.signal,\n credentials: 'include',\n });\n\n if (!response.ok) {\n // Align error handling with generic `fetcher` utility so that callers receive\n // meaningful messages (e.g. for 429 \"Too Many Requests\" responses).\n let errorMessage: string = 'An error occurred';\n\n try {\n // Attempt to parse JSON error payload produced by backend\n const errorData = await response.json();\n const errorObj = errorData.error ?? errorData;\n errorMessage = JSON.stringify(errorObj) ?? 'An error occurred';\n } catch {\n // Fallback to plain-text body or HTTP status text\n try {\n const errorText = await response.text();\n if (errorText) {\n errorMessage = errorText;\n }\n } catch {\n // ignore – we already have a default message\n }\n }\n\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('No reader available');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const data = JSON.parse(line.slice(6));\n if (data.chunk) {\n onMessage?.(data.chunk);\n }\n if (data.done && data.response) {\n onDone?.(data.response);\n }\n } catch (e) {\n console.error('Failed to parse SSE data:', e);\n }\n }\n }\n }\n } catch (error) {\n console.error('Error in askDocQuestion:', error);\n throw error;\n }\n };\n\n const chat = async (body?: ChatBody, otherOptions: FetcherOptions = {}) => {\n if (!body) return;\n\n const { onMessage, onDone, onAction, ...rest } = body;\n const abortController = new AbortController();\n\n try {\n const response = await fetch(`${AI_API_ROUTE}/chat`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n body: JSON.stringify({\n ...rest,\n ...authAPIOptions.body,\n ...otherOptions.body,\n }),\n signal: abortController.signal,\n credentials: 'include',\n });\n\n if (!response.ok) {\n let errorMessage: string = 'An error occurred';\n\n try {\n const errorData = await response.json();\n const errorObj = errorData.error ?? errorData;\n errorMessage = JSON.stringify(errorObj) ?? 'An error occurred';\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) {\n errorMessage = errorText;\n }\n } catch {\n // ignore\n }\n }\n\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('No reader available');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const data = JSON.parse(line.slice(6));\n if (data.chunk) {\n onMessage?.(data.chunk);\n }\n if (data.action) {\n onAction?.(data.action);\n }\n if (data.done && data.response) {\n onDone?.(data.response);\n }\n } catch (e) {\n console.error('Failed to parse SSE data:', e);\n }\n }\n }\n }\n } catch (error) {\n console.error('Error in chat:', error);\n throw error;\n }\n };\n\n const autocomplete = async (\n body?: AutocompleteBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AutocompleteResponse>(\n `${AI_API_ROUTE}/autocomplete`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Retrieves discussions with filters and pagination. Only user or admin can access.\n */\n const getDiscussions = async (\n params?: GetDiscussionsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDiscussionsResult>(\n `${AI_API_ROUTE}/discussions`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params,\n }\n );\n\n /**\n * Retrieves aggregated AI token-usage statistics for the currently selected\n * project.\n */\n const getAIStats = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetAIStatsResult>(\n `${AI_API_ROUTE}/stats`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n return {\n customQuery,\n translateJSON,\n auditContentDeclaration,\n auditContentDeclarationField,\n auditContentDeclarationMetadata,\n auditTag,\n askDocQuestion,\n chat,\n autocomplete,\n getDiscussions,\n getAIStats,\n };\n};\n"],"mappings":";;;;AAuDA,MAAa,YACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,eAAe,GAFF,gBAAgB,QAAQ,cAAc,OAAO,WAE7B;;;;;;CAOnC,MAAM,cAAc,OAClB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,cACA,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,gBAAgB,OACpB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,kBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,0BAA0B,OAC9B,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,oBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,+BAA+B,OACnC,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,0BAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,kCAAkC,OACtC,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,6BAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,WAAW,OACf,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,aAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;;;;;;;;;;;;;;;CAqBH,MAAM,iBAAiB,OACrB,MACA,eAA+B,EAAE,KAC9B;AACH,MAAI,CAAC,KAAM;EAEX,MAAM,EAAE,WAAW,QAAQ,GAAG,SAAS;EACvC,MAAM,kBAAkB,IAAI,iBAAiB;AAE7C,MAAI;GACF,MAAM,WAAW,MAAM,MAAM,GAAG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AS,KAAK,SAAS;aAElB,GAAG;AACV,aAAQ,MAAM,6BAA6B,EAAE;;;WAK9C,OAAO;AACd,WAAQ,MAAM,kBAAkB,MAAM;AACtC,SAAM;;;CAIV,MAAM,eAAe,OACnB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,gBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;CAKH,MAAM,iBAAiB,OACrB,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,eAChB,gBACA,cACA;EACE,QAAQ;EAER;EACD,CACF;;;;;CAMH,MAAM,aAAa,OAAO,eAA+B,EAAE,KACzD,MAAM,QACJ,GAAG,aAAa,SAChB,gBACA,cACA,EACE,QAAQ,OACT,CACF;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"ai.mjs","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import type {\n AIOptions,\n AskDocQuestionResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n ChatResult,\n CustomQueryBody,\n CustomQueryResult,\n GetAIStatsResult,\n GetDiscussionsParams,\n GetDiscussionsResult,\n TranslateJSONBody,\n TranslateJSONResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type AutocompleteBody = {\n text: string;\n aiOptions?: AIOptions;\n contextBefore?: string;\n currentLine?: string;\n contextAfter?: string;\n};\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: AskDocQuestionResult) => void;\n};\n\nexport type ClientAction =\n | { type: 'navigate'; path: string }\n | { type: 'invalidate_queries' };\n\nexport type ChatBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: ChatResult) => void;\n onAction?: (action: ClientAction) => void;\n};\n\nexport type { AskDocQuestionResult, ChatResult };\n\nexport const getAiAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const AI_API_ROUTE = `${backendURL}/api/ai`;\n\n /**\n * Custom query\n * @param body - Custom query parameters.\n * @returns Custom query result.\n */\n const customQuery = async (\n body?: CustomQueryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CustomQueryResult>(\n AI_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Translate a JSON\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const translateJSON = async (\n body?: TranslateJSONBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TranslateJSONResult>(\n `${AI_API_ROUTE}/translate/json`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclaration = async (\n body?: AuditContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationResult>(\n `${AI_API_ROUTE}/audit/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration field\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationField = async (\n body?: AuditContentDeclarationFieldBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationFieldResult>(\n `${AI_API_ROUTE}/audit/dictionary/field`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file to retrieve title, description and tags\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationMetadata = async (\n body?: AuditContentDeclarationMetadataBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationMetadataResult>(\n `${AI_API_ROUTE}/audit/dictionary/metadata`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a tag\n * @param body - Audit tag parameters.\n * @returns Audited tag content.\n */\n const auditTag = async (\n body?: AuditTagBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditTagResult>(\n `${AI_API_ROUTE}/audit/tag`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Asks a question to the AI related to the documentation **and streams the\n * answer as Server‑Sent Events (SSE)**.\n *\n * The function **returns immediately** with a handle exposing:\n * - `promise` → resolves when the stream completes (or rejects on error)\n * - `abort()` → allows canceling the request on demand\n *\n * Usage example:\n * ```ts\n * const { promise, abort } = ai.askDocQuestion({\n * ...body,\n * onMessage: console.log,\n * onDone: (full) => console.log(\"✔\", full),\n * });\n * // later → abort();\n * await promise; // waits for completion if desired\n * ```\n */\n const askDocQuestion = async (\n body?: AskDocQuestionBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body) return;\n\n const { onMessage, onDone, ...rest } = body;\n const abortController = new AbortController();\n\n try {\n const response = await fetch(`${AI_API_ROUTE}/ask`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n body: JSON.stringify({\n ...rest,\n ...authAPIOptions.body,\n ...otherOptions.body,\n }),\n signal: abortController.signal,\n credentials: 'include',\n });\n\n if (!response.ok) {\n // Align error handling with generic `fetcher` utility so that callers receive\n // meaningful messages (e.g. for 429 \"Too Many Requests\" responses).\n let errorMessage: string = 'An error occurred';\n\n try {\n // Attempt to parse JSON error payload produced by backend\n const errorData = await response.json();\n const errorObj = errorData.error ?? errorData;\n errorMessage = JSON.stringify(errorObj) ?? 'An error occurred';\n } catch {\n // Fallback to plain-text body or HTTP status text\n try {\n const errorText = await response.text();\n if (errorText) {\n errorMessage = errorText;\n }\n } catch {\n // ignore – we already have a default message\n }\n }\n\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('No reader available');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const data = JSON.parse(line.slice(6));\n if (data.chunk) {\n onMessage?.(data.chunk);\n }\n if (data.done && data.response) {\n onDone?.(data.response);\n }\n } catch (e) {\n console.error('Failed to parse SSE data:', e);\n }\n }\n }\n }\n } catch (error) {\n console.error('Error in askDocQuestion:', error);\n throw error;\n }\n };\n\n const chat = async (body?: ChatBody, otherOptions: FetcherOptions = {}) => {\n if (!body) return;\n\n const { onMessage, onDone, onAction, ...rest } = body;\n const abortController = new AbortController();\n\n try {\n const response = await fetch(`${AI_API_ROUTE}/chat`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n body: JSON.stringify({\n ...rest,\n ...authAPIOptions.body,\n ...otherOptions.body,\n }),\n signal: abortController.signal,\n credentials: 'include',\n });\n\n if (!response.ok) {\n let errorMessage: string = 'An error occurred';\n\n try {\n const errorData = await response.json();\n const errorObj = errorData.error ?? errorData;\n errorMessage = JSON.stringify(errorObj) ?? 'An error occurred';\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) {\n errorMessage = errorText;\n }\n } catch {\n // ignore\n }\n }\n\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n throw new Error('No reader available');\n }\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const data = JSON.parse(line.slice(6));\n if (data.chunk) {\n onMessage?.(data.chunk);\n }\n if (data.action) {\n onAction?.(data.action);\n }\n if (data.done && data.response) {\n onDone?.(data.response);\n }\n } catch (e) {\n console.error('Failed to parse SSE data:', e);\n }\n }\n }\n }\n } catch (error) {\n console.error('Error in chat:', error);\n throw error;\n }\n };\n\n const autocomplete = async (\n body?: AutocompleteBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AutocompleteResponse>(\n `${AI_API_ROUTE}/autocomplete`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Retrieves discussions with filters and pagination. Only user or admin can access.\n */\n const getDiscussions = async (\n params?: GetDiscussionsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDiscussionsResult>(\n `${AI_API_ROUTE}/discussions`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params,\n }\n );\n\n /**\n * Retrieves aggregated AI token-usage statistics for the currently selected\n * project.\n */\n const getAIStats = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetAIStatsResult>(\n `${AI_API_ROUTE}/stats`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n return {\n customQuery,\n translateJSON,\n auditContentDeclaration,\n auditContentDeclarationField,\n auditContentDeclarationMetadata,\n auditTag,\n askDocQuestion,\n chat,\n autocomplete,\n getDiscussions,\n getAIStats,\n };\n};\n\n/**\n * Authenticated `ai` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const aiEndpoint = createEndpoint(getAiAPI);\n"],"mappings":";;;;;AAwDA,MAAa,YACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,eAAe,GAFF,gBAAgB,QAAQ,cAAc,OAAO,WAE7B;;;;;;CAOnC,MAAM,cAAc,OAClB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,cACA,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,gBAAgB,OACpB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,kBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,0BAA0B,OAC9B,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,oBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,+BAA+B,OACnC,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,0BAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,kCAAkC,OACtC,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,6BAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,WAAW,OACf,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,aAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;;;;;;;;;;;;;;;CAqBH,MAAM,iBAAiB,OACrB,MACA,eAA+B,EAAE,KAC9B;AACH,MAAI,CAAC,KAAM;EAEX,MAAM,EAAE,WAAW,QAAQ,GAAG,SAAS;EACvC,MAAM,kBAAkB,IAAI,iBAAiB;AAE7C,MAAI;GACF,MAAM,WAAW,MAAM,MAAM,GAAG,aAAa,OAAO;IAClD,QAAQ;IACR,SAAS;KACP,gBAAgB;KAChB,GAAG,eAAe;KAClB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O;AACd,WAAQ,MAAM,kBAAkB,MAAM;AACtC,SAAM;;;CAIV,MAAM,eAAe,OACnB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,gBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;CAKH,MAAM,iBAAiB,OACrB,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,eAChB,gBACA,cACA;EACE,QAAQ;EAER;EACD,CACF;;;;;CAMH,MAAM,aAAa,OAAO,eAA+B,EAAE,KACzD,MAAM,QACJ,GAAG,aAAa,SAChB,gBACA,cACA,EACE,QAAQ,OACT,CACF;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;;;;;;;AASH,MAAa,aAAa,eAAe,SAAS"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
|
+
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
2
3
|
import { editor } from "@intlayer/config/built";
|
|
3
4
|
|
|
4
5
|
//#region src/getIntlayerAPI/asset.ts
|
|
@@ -79,7 +80,14 @@ const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
79
80
|
deleteAsset
|
|
80
81
|
};
|
|
81
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Authenticated `asset` endpoint bound to an Intlayer CMS authenticator.
|
|
85
|
+
*
|
|
86
|
+
* Pass an authenticator created with `createIntlayerCMS`, or omit it to use
|
|
87
|
+
* the build-time configuration (`@intlayer/config/built`).
|
|
88
|
+
*/
|
|
89
|
+
const assetEndpoint = createEndpoint(getAssetAPI);
|
|
82
90
|
|
|
83
91
|
//#endregion
|
|
84
|
-
export { getAssetAPI };
|
|
92
|
+
export { assetEndpoint, getAssetAPI };
|
|
85
93
|
//# sourceMappingURL=asset.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset.mjs","names":[],"sources":["../../../src/getIntlayerAPI/asset.ts"],"sourcesContent":["import type {\n DeleteAssetResult,\n GetAssetByIdResult,\n GetAssetsResult,\n UpdateAssetResult,\n UploadAssetResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getAssetAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const ASSET_API_ROUTE = `${backendURL}/api/assets`;\n\n /**\n * Retrieves all assets for the current session project, paginated.\n * @param page - Page number (1-based).\n * @param pageSize - Number of items per page.\n * @returns Paginated list of assets.\n */\n const getAssets = async (\n page?: number,\n pageSize?: number,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetsResult>(\n ASSET_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n params: {\n ...(page !== undefined && { page: String(page) }),\n ...(pageSize !== undefined && { pageSize: String(pageSize) }),\n },\n }\n );\n\n /**\n * Retrieves a single asset by ID.\n * @param assetId - The asset document ID.\n * @returns The asset.\n */\n const getAssetById = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetByIdResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { cache: 'no-store' }\n );\n\n /**\n * Uploads a new asset image.\n * @param file - The image File object.\n * @param alt - Optional alt text.\n * @param caption - Optional caption.\n * @returns The created asset record with its public URL.\n */\n const uploadAsset = async (\n file: File,\n alt?: string,\n caption?: string,\n otherOptions: FetcherOptions = {}\n ) => {\n const buffer = await file.arrayBuffer();\n\n const headers: Record<string, string> = {\n 'Content-Type': file.type || 'image/jpeg',\n 'X-File-Name': file.name,\n };\n\n if (alt) headers['X-Alt-Text'] = alt;\n if (caption) headers['X-Caption'] = caption;\n\n const authHeaders =\n (authAPIOptions.headers as Record<string, string> | undefined) ?? {};\n\n const response = await fetch(ASSET_API_ROUTE, {\n method: 'POST',\n credentials: 'include',\n headers: { ...authHeaders, ...headers },\n body: buffer,\n signal: otherOptions.signal as AbortSignal | undefined,\n });\n\n if (!response.ok) {\n const result = await response.json();\n throw new Error(JSON.stringify(result.error) ?? 'Asset upload failed');\n }\n\n return (await response.json()) as UploadAssetResult;\n };\n\n /**\n * Updates mutable metadata (name, alt text, caption) of an asset.\n * @param assetId - The asset document ID.\n * @param data - Fields to update.\n * @returns The updated asset record.\n */\n const updateAsset = async (\n assetId: string,\n data: { originalName?: string; alt?: string; caption?: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateAssetResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { method: 'PATCH', body: data as unknown as Record<string, unknown> }\n );\n\n /**\n * Deletes an asset by ID.\n * @param assetId - The asset document ID.\n * @returns Confirmation response.\n */\n const deleteAsset = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAssetResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n return {\n getAssets,\n getAssetById,\n uploadAsset,\n updateAsset,\n deleteAsset,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"asset.mjs","names":[],"sources":["../../../src/getIntlayerAPI/asset.ts"],"sourcesContent":["import type {\n DeleteAssetResult,\n GetAssetByIdResult,\n GetAssetsResult,\n UpdateAssetResult,\n UploadAssetResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getAssetAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const ASSET_API_ROUTE = `${backendURL}/api/assets`;\n\n /**\n * Retrieves all assets for the current session project, paginated.\n * @param page - Page number (1-based).\n * @param pageSize - Number of items per page.\n * @returns Paginated list of assets.\n */\n const getAssets = async (\n page?: number,\n pageSize?: number,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetsResult>(\n ASSET_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n params: {\n ...(page !== undefined && { page: String(page) }),\n ...(pageSize !== undefined && { pageSize: String(pageSize) }),\n },\n }\n );\n\n /**\n * Retrieves a single asset by ID.\n * @param assetId - The asset document ID.\n * @returns The asset.\n */\n const getAssetById = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAssetByIdResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { cache: 'no-store' }\n );\n\n /**\n * Uploads a new asset image.\n * @param file - The image File object.\n * @param alt - Optional alt text.\n * @param caption - Optional caption.\n * @returns The created asset record with its public URL.\n */\n const uploadAsset = async (\n file: File,\n alt?: string,\n caption?: string,\n otherOptions: FetcherOptions = {}\n ) => {\n const buffer = await file.arrayBuffer();\n\n const headers: Record<string, string> = {\n 'Content-Type': file.type || 'image/jpeg',\n 'X-File-Name': file.name,\n };\n\n if (alt) headers['X-Alt-Text'] = alt;\n if (caption) headers['X-Caption'] = caption;\n\n const authHeaders =\n (authAPIOptions.headers as Record<string, string> | undefined) ?? {};\n\n const response = await fetch(ASSET_API_ROUTE, {\n method: 'POST',\n credentials: 'include',\n headers: { ...authHeaders, ...headers },\n body: buffer,\n signal: otherOptions.signal as AbortSignal | undefined,\n });\n\n if (!response.ok) {\n const result = await response.json();\n throw new Error(JSON.stringify(result.error) ?? 'Asset upload failed');\n }\n\n return (await response.json()) as UploadAssetResult;\n };\n\n /**\n * Updates mutable metadata (name, alt text, caption) of an asset.\n * @param assetId - The asset document ID.\n * @param data - Fields to update.\n * @returns The updated asset record.\n */\n const updateAsset = async (\n assetId: string,\n data: { originalName?: string; alt?: string; caption?: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateAssetResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { method: 'PATCH', body: data as unknown as Record<string, unknown> }\n );\n\n /**\n * Deletes an asset by ID.\n * @param assetId - The asset document ID.\n * @returns Confirmation response.\n */\n const deleteAsset = async (\n assetId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAssetResult>(\n `${ASSET_API_ROUTE}/${assetId}`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n return {\n getAssets,\n getAssetById,\n uploadAsset,\n updateAsset,\n deleteAsset,\n };\n};\n\n/**\n * Authenticated `asset` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const assetEndpoint = createEndpoint(getAssetAPI);\n"],"mappings":";;;;;AAYA,MAAa,eACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,kBAAkB,GAFL,gBAAgB,QAAQ,cAAc,OAAO,WAE1B;;;;;;;CAQtC,MAAM,YAAY,OAChB,MACA,UACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,iBACA,gBACA,cACA;EACE,OAAO;EACP,QAAQ;GACN,GAAI,SAAS,UAAa,EAAE,MAAM,OAAO,KAAK,EAAE;GAChD,GAAI,aAAa,UAAa,EAAE,UAAU,OAAO,SAAS,EAAE;GAC7D;EACF,CACF;;;;;;CAOH,MAAM,eAAe,OACnB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA,EAAE,OAAO,YAAY,CACtB;;;;;;;;CASH,MAAM,cAAc,OAClB,MACA,KACA,SACA,eAA+B,EAAE,KAC9B;EACH,MAAM,SAAS,MAAM,KAAK,aAAa;EAEvC,MAAM,UAAkC;GACtC,gBAAgB,KAAK,QAAQ;GAC7B,eAAe,KAAK;GACrB;AAED,MAAI,IAAK,SAAQ,gBAAgB;AACjC,MAAI,QAAS,SAAQ,eAAe;EAEpC,MAAM,cACH,eAAe,WAAkD,EAAE;EAEtE,MAAM,WAAW,MAAM,MAAM,iBAAiB;GAC5C,QAAQ;GACR,aAAa;GACb,SAAS;IAAE,GAAG;IAAa,GAAG;IAAS;GACvC,MAAM;GACN,QAAQ,aAAa;GACtB,CAAC;AAEF,MAAI,CAAC,SAAS,IAAI;GAChB,MAAM,SAAS,MAAM,SAAS,MAAM;AACpC,SAAM,IAAI,MAAM,KAAK,UAAU,OAAO,MAAM,IAAI,sBAAsB;;AAGxE,SAAQ,MAAM,SAAS,MAAM;;;;;;;;CAS/B,MAAM,cAAc,OAClB,SACA,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA;EAAE,QAAQ;EAAS,MAAM;EAA4C,CACtE;;;;;;CAOH,MAAM,cAAc,OAClB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA,EAAE,QAAQ,UAAU,CACrB;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;;;;;;;;AASH,MAAa,gBAAgB,eAAe,YAAY"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
|
+
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
2
3
|
import { editor } from "@intlayer/config/built";
|
|
3
4
|
|
|
4
5
|
//#region src/getIntlayerAPI/audit.ts
|
|
@@ -89,7 +90,14 @@ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
89
90
|
resumeRecursiveAudit
|
|
90
91
|
};
|
|
91
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* Authenticated `audit` endpoint bound to an Intlayer CMS authenticator.
|
|
95
|
+
*
|
|
96
|
+
* Pass an authenticator created with `createIntlayerCMS`, or omit it to use
|
|
97
|
+
* the build-time configuration (`@intlayer/config/built`).
|
|
98
|
+
*/
|
|
99
|
+
const auditEndpoint = createEndpoint(getAuditAPI);
|
|
92
100
|
|
|
93
101
|
//#endregion
|
|
94
|
-
export { getAuditAPI };
|
|
102
|
+
export { auditEndpoint, getAuditAPI };
|
|
95
103
|
//# sourceMappingURL=audit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.mjs","names":[],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n};\n\nexport type ScanUrlBody = {\n url: string;\n onMessage?: (event: AuditEvent) => void;\n onDone?: () => void;\n};\n\nexport type DiscoverUrlsParams = {\n url: string;\n};\n\nexport type DiscoverUrlsResult = {\n urls: string[];\n};\n\nexport type StartRecursiveAuditBody = {\n url: string;\n urls?: string[];\n};\n\nexport type GetRecursiveAuditStatusParams = {\n jobId: string;\n};\n\nexport type RecursiveAuditJobParams = {\n jobId: string;\n};\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const AUDIT_API_ROUTE = `${backendURL}/api/scan`;\n\n /**\n * Streams a single-page SEO audit as Server-Sent Events.\n *\n * Usage:\n * ```ts\n * await audit.scanUrl({\n * url: 'https://example.com',\n * onMessage: (event) => console.log(event),\n * onDone: () => console.log('done'),\n * });\n * ```\n */\n const discoverUrls = async (\n params?: DiscoverUrlsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DiscoverUrlsResult>(\n `${AUDIT_API_ROUTE}/recursive/discover`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n params,\n }\n );\n\n const scanUrl = async (\n body?: ScanUrlBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body?.url) return;\n\n const { url, onMessage, onDone } = body;\n\n const params = new URLSearchParams({ url });\n const endpoint = `${AUDIT_API_ROUTE}?${params.toString()}`;\n\n const response = await fetch(endpoint, {\n method: 'GET',\n headers: {\n Accept: 'text/event-stream',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n credentials: 'include',\n signal: otherOptions.signal,\n });\n\n if (!response.ok) {\n let errorMessage = 'An error occurred';\n try {\n const errorData = await response.json();\n errorMessage = JSON.stringify(errorData.error) ?? errorMessage;\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) errorMessage = errorText;\n } catch {\n // ignore\n }\n }\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const event = JSON.parse(line.slice(6)) as AuditEvent;\n onMessage?.(event);\n } catch {\n // ignore malformed lines\n }\n }\n }\n }\n\n onDone?.();\n };\n\n /**\n * Starts a recursive audit job for the given URL.\n */\n const startRecursiveAudit = async (\n body?: StartRecursiveAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<StartRecursiveAuditResult>(\n `${AUDIT_API_ROUTE}/recursive/start`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n params: body?.url ? { url: body.url } : undefined,\n body: body?.urls !== undefined ? { urls: body.urls as any } : undefined,\n }\n );\n\n /**\n * Gets the status of a recursive audit job.\n */\n const getRecursiveAuditStatus = async (\n params?: GetRecursiveAuditStatusParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetRecursiveAuditStatusResult>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n const cancelRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/cancel`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const pauseRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/pause`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const resumeRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/resume`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n return {\n discoverUrls,\n scanUrl,\n startRecursiveAudit,\n getRecursiveAuditStatus,\n cancelRecursiveAudit,\n pauseRecursiveAudit,\n resumeRecursiveAudit,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"audit.mjs","names":[],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n};\n\nexport type ScanUrlBody = {\n url: string;\n onMessage?: (event: AuditEvent) => void;\n onDone?: () => void;\n};\n\nexport type DiscoverUrlsParams = {\n url: string;\n};\n\nexport type DiscoverUrlsResult = {\n urls: string[];\n};\n\nexport type StartRecursiveAuditBody = {\n url: string;\n urls?: string[];\n};\n\nexport type GetRecursiveAuditStatusParams = {\n jobId: string;\n};\n\nexport type RecursiveAuditJobParams = {\n jobId: string;\n};\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const AUDIT_API_ROUTE = `${backendURL}/api/scan`;\n\n /**\n * Streams a single-page SEO audit as Server-Sent Events.\n *\n * Usage:\n * ```ts\n * await audit.scanUrl({\n * url: 'https://example.com',\n * onMessage: (event) => console.log(event),\n * onDone: () => console.log('done'),\n * });\n * ```\n */\n const discoverUrls = async (\n params?: DiscoverUrlsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DiscoverUrlsResult>(\n `${AUDIT_API_ROUTE}/recursive/discover`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n params,\n }\n );\n\n const scanUrl = async (\n body?: ScanUrlBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body?.url) return;\n\n const { url, onMessage, onDone } = body;\n\n const params = new URLSearchParams({ url });\n const endpoint = `${AUDIT_API_ROUTE}?${params.toString()}`;\n\n const response = await fetch(endpoint, {\n method: 'GET',\n headers: {\n Accept: 'text/event-stream',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n credentials: 'include',\n signal: otherOptions.signal,\n });\n\n if (!response.ok) {\n let errorMessage = 'An error occurred';\n try {\n const errorData = await response.json();\n errorMessage = JSON.stringify(errorData.error) ?? errorMessage;\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) errorMessage = errorText;\n } catch {\n // ignore\n }\n }\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const event = JSON.parse(line.slice(6)) as AuditEvent;\n onMessage?.(event);\n } catch {\n // ignore malformed lines\n }\n }\n }\n }\n\n onDone?.();\n };\n\n /**\n * Starts a recursive audit job for the given URL.\n */\n const startRecursiveAudit = async (\n body?: StartRecursiveAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<StartRecursiveAuditResult>(\n `${AUDIT_API_ROUTE}/recursive/start`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n params: body?.url ? { url: body.url } : undefined,\n body: body?.urls !== undefined ? { urls: body.urls as any } : undefined,\n }\n );\n\n /**\n * Gets the status of a recursive audit job.\n */\n const getRecursiveAuditStatus = async (\n params?: GetRecursiveAuditStatusParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetRecursiveAuditStatusResult>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n const cancelRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/cancel`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const pauseRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/pause`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const resumeRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/resume`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n return {\n discoverUrls,\n scanUrl,\n startRecursiveAudit,\n getRecursiveAuditStatus,\n cancelRecursiveAudit,\n pauseRecursiveAudit,\n resumeRecursiveAudit,\n };\n};\n\n/**\n * Authenticated `audit` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const auditEndpoint = createEndpoint(getAuditAPI);\n"],"mappings":";;;;;AA2CA,MAAa,eACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,kBAAkB,GAFL,gBAAgB,QAAQ,cAAc,OAAO,WAE1B;;;;;;;;;;;;;CActC,MAAM,eAAe,OACnB,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,sBACnB,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;CAEH,MAAM,UAAU,OACd,MACA,eAA+B,EAAE,KAC9B;AACH,MAAI,CAAC,MAAM,IAAK;EAEhB,MAAM,EAAE,KAAK,WAAW,WAAW;EAGnC,MAAM,WAAW,GAAG,gBAAgB,GAAG,IADpB,gBAAgB,EAAE,KAAK,CACG,CAAC,UAAU;EAExD,MAAM,WAAW,MAAM,MAAM,UAAU;GACrC,QAAQ;GACR,SAAS;IACP,QAAQ;IACR,GAAG,eAAe;IAClB,GAAG,aAAa;IACjB;GACD,aAAa;GACb,QAAQ,aAAa;GACtB,CAAC;AAEF,MAAI,CAAC,SAAS,IAAI;GAChB,IAAI,eAAe;AACnB,OAAI;IACF,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,mBAAe,KAAK,UAAU,UAAU,MAAM,IAAI;WAC5C;AACN,QAAI;KACF,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,SAAI,UAAW,gBAAe;YACxB;;AAIV,SAAM,IAAI,MAAM,aAAa;;EAG/B,MAAM,SAAS,SAAS,MAAM,WAAW;AACzC,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,sBAAs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,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACD;;;;;;;;AASH,MAAa,gBAAgB,eAAe,YAAY"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
|
+
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
2
3
|
import { editor } from "@intlayer/config/built";
|
|
3
4
|
|
|
4
5
|
//#region src/getIntlayerAPI/bitbucket.ts
|
|
@@ -64,7 +65,14 @@ const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
64
65
|
getConfigFile
|
|
65
66
|
};
|
|
66
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Authenticated `bitbucket` endpoint bound to an Intlayer CMS authenticator.
|
|
70
|
+
*
|
|
71
|
+
* Pass an authenticator created with `createIntlayerCMS`, or omit it to use
|
|
72
|
+
* the build-time configuration (`@intlayer/config/built`).
|
|
73
|
+
*/
|
|
74
|
+
const bitbucketEndpoint = createEndpoint(getBitbucketAPI);
|
|
67
75
|
|
|
68
76
|
//#endregion
|
|
69
|
-
export { getBitbucketAPI };
|
|
77
|
+
export { bitbucketEndpoint, getBitbucketAPI };
|
|
70
78
|
//# sourceMappingURL=bitbucket.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitbucket.mjs","names":[],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const BITBUCKET_API_ROUTE = `${backendURL}/api/bitbucket`;\n\n /**\n * Get Bitbucket OAuth authorization URL\n * @param redirectUri - Redirect URI after OAuth authorization\n */\n const getAuthUrl = async (\n redirectUri: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetAuthUrlResult>(\n `${BITBUCKET_API_ROUTE}/auth-url`,\n authAPIOptions,\n otherOptions,\n {\n params: { redirectUri },\n }\n );\n\n /**\n * Exchange Bitbucket authorization code for access token\n * @param code - Bitbucket authorization code\n */\n const authenticate = async (\n code: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketAuthCallbackResult>(\n `${BITBUCKET_API_ROUTE}/auth`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { code },\n }\n );\n\n /**\n * Get user's Bitbucket repositories\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n */\n const getRepositories = async (\n token?: string | null,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketListReposResult>(\n `${BITBUCKET_API_ROUTE}/repos`,\n authAPIOptions,\n otherOptions,\n {\n params: token ? { token } : undefined,\n }\n );\n\n /**\n * Check if intlayer.config.ts exists in a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n */\n const checkIntlayerConfig = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketCheckConfigResult>(\n `${BITBUCKET_API_ROUTE}/check-config`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { token: token ?? undefined, workspace, repoSlug, branch },\n }\n );\n\n /**\n * Get intlayer.config.ts file contents from a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n * @param path - File path (default: 'intlayer.config.ts')\n */\n const getConfigFile = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n path: string = 'intlayer.config.ts',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetConfigFileResult>(\n `${BITBUCKET_API_ROUTE}/get-config-file`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: {\n token: token ?? undefined,\n workspace,\n repoSlug,\n branch,\n path,\n },\n }\n );\n\n return {\n getAuthUrl,\n authenticate,\n getRepositories,\n checkIntlayerConfig,\n getConfigFile,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bitbucket.mjs","names":[],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const BITBUCKET_API_ROUTE = `${backendURL}/api/bitbucket`;\n\n /**\n * Get Bitbucket OAuth authorization URL\n * @param redirectUri - Redirect URI after OAuth authorization\n */\n const getAuthUrl = async (\n redirectUri: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetAuthUrlResult>(\n `${BITBUCKET_API_ROUTE}/auth-url`,\n authAPIOptions,\n otherOptions,\n {\n params: { redirectUri },\n }\n );\n\n /**\n * Exchange Bitbucket authorization code for access token\n * @param code - Bitbucket authorization code\n */\n const authenticate = async (\n code: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketAuthCallbackResult>(\n `${BITBUCKET_API_ROUTE}/auth`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { code },\n }\n );\n\n /**\n * Get user's Bitbucket repositories\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n */\n const getRepositories = async (\n token?: string | null,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketListReposResult>(\n `${BITBUCKET_API_ROUTE}/repos`,\n authAPIOptions,\n otherOptions,\n {\n params: token ? { token } : undefined,\n }\n );\n\n /**\n * Check if intlayer.config.ts exists in a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n */\n const checkIntlayerConfig = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketCheckConfigResult>(\n `${BITBUCKET_API_ROUTE}/check-config`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { token: token ?? undefined, workspace, repoSlug, branch },\n }\n );\n\n /**\n * Get intlayer.config.ts file contents from a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n * @param path - File path (default: 'intlayer.config.ts')\n */\n const getConfigFile = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n path: string = 'intlayer.config.ts',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetConfigFileResult>(\n `${BITBUCKET_API_ROUTE}/get-config-file`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: {\n token: token ?? undefined,\n workspace,\n repoSlug,\n branch,\n path,\n },\n }\n );\n\n return {\n getAuthUrl,\n authenticate,\n getRepositories,\n checkIntlayerConfig,\n getConfigFile,\n };\n};\n\n/**\n * Authenticated `bitbucket` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const bitbucketEndpoint = createEndpoint(getBitbucketAPI);\n"],"mappings":";;;;;AAiFA,MAAa,mBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,sBAAsB,GAFT,gBAAgB,QAAQ,cAAc,OAAO,WAEtB;;;;;CAM1C,MAAM,aAAa,OACjB,aACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,YACvB,gBACA,cACA,EACE,QAAQ,EAAE,aAAa,EACxB,CACF;;;;;CAMH,MAAM,eAAe,OACnB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,QACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM,EAAE,MAAM;EACf,CACF;;;;;CAMH,MAAM,kBAAkB,OACtB,OACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,SACvB,gBACA,cACA,EACE,QAAQ,QAAQ,EAAE,OAAO,GAAG,QAC7B,CACF;;;;;;;;CASH,MAAM,sBAAsB,OAC1B,OACA,WACA,UACA,SAAiB,QACjB,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,gBACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;GAAE,OAAO,SAAS;GAAW;GAAW;GAAU;GAAQ;EACjE,CACF;;;;;;;;;CAUH,MAAM,gBAAgB,OACpB,OACA,WACA,UACA,SAAiB,QACjB,OAAe,sBACf,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,mBACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;GACJ,OAAO,SAAS;GAChB;GACA;GACA;GACA;GACD;EACF,CACF;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;;;;;;;;AASH,MAAa,oBAAoB,eAAe,gBAAgB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
|
+
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
2
3
|
import { editor } from "@intlayer/config/built";
|
|
3
4
|
|
|
4
5
|
//#region src/getIntlayerAPI/dictionary.ts
|
|
@@ -62,7 +63,14 @@ const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
62
63
|
deleteDictionary
|
|
63
64
|
};
|
|
64
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Authenticated `dictionary` endpoint bound to an Intlayer CMS authenticator.
|
|
68
|
+
*
|
|
69
|
+
* Pass an authenticator created with `createIntlayerCMS`, or omit it to use
|
|
70
|
+
* the build-time configuration (`@intlayer/config/built`).
|
|
71
|
+
*/
|
|
72
|
+
const dictionaryEndpoint = createEndpoint(getDictionaryAPI);
|
|
65
73
|
|
|
66
74
|
//#endregion
|
|
67
|
-
export { getDictionaryAPI };
|
|
75
|
+
export { dictionaryEndpoint, getDictionaryAPI };
|
|
68
76
|
//# sourceMappingURL=dictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;\n\n /**\n * Retrieves a list of dictionaries based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getDictionaries = async (\n filters?: GetDictionariesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesResult>(\n PROJECT_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params: filters,\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesKeys = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetDictionariesKeysResult>(\n `${PROJECT_API_ROUTE}/keys`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesUpdateTimestamp = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesUpdateTimestampResult>(\n `${PROJECT_API_ROUTE}/update`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a dictionary by its key and version.\n * @param dictionaryKey - Dictionary key.\n * @param version - Dictionary version of content.\n */\n const getDictionary = async (\n dictionaryKey: GetDictionaryParams['dictionaryKey'],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionaryKey}`,\n authAPIOptions,\n otherOptions,\n {\n params: version ? { version: version.toString() } : undefined,\n }\n );\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const addDictionary = async (\n body: AddDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddDictionaryResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n const pushDictionaries = async (\n dictionaries: PushDictionariesBody['dictionaries'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushDictionariesResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { dictionaries },\n }\n );\n\n /**\n * Updates an existing dictionary in the database.\n * @param dictionary - Updated dictionary data.\n */\n const updateDictionary = async (\n dictionary: UpdateDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionary.id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: dictionary,\n }\n );\n\n /**\n * Deletes a dictionary from the database by its ID.\n * @param id - Dictionary ID.\n */\n const deleteDictionary = async (\n id: DeleteDictionaryParam['dictionaryId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteDictionaryResult>(\n `${PROJECT_API_ROUTE}/${id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n return {\n getDictionaries,\n getDictionariesKeys,\n getDictionariesUpdateTimestamp,\n getDictionary,\n pushDictionaries,\n addDictionary,\n updateDictionary,\n deleteDictionary,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;\n\n /**\n * Retrieves a list of dictionaries based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getDictionaries = async (\n filters?: GetDictionariesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesResult>(\n PROJECT_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params: filters,\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesKeys = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetDictionariesKeysResult>(\n `${PROJECT_API_ROUTE}/keys`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesUpdateTimestamp = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesUpdateTimestampResult>(\n `${PROJECT_API_ROUTE}/update`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a dictionary by its key and version.\n * @param dictionaryKey - Dictionary key.\n * @param version - Dictionary version of content.\n */\n const getDictionary = async (\n dictionaryKey: GetDictionaryParams['dictionaryKey'],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionaryKey}`,\n authAPIOptions,\n otherOptions,\n {\n params: version ? { version: version.toString() } : undefined,\n }\n );\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const addDictionary = async (\n body: AddDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddDictionaryResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n const pushDictionaries = async (\n dictionaries: PushDictionariesBody['dictionaries'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushDictionariesResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { dictionaries },\n }\n );\n\n /**\n * Updates an existing dictionary in the database.\n * @param dictionary - Updated dictionary data.\n */\n const updateDictionary = async (\n dictionary: UpdateDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionary.id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: dictionary,\n }\n );\n\n /**\n * Deletes a dictionary from the database by its ID.\n * @param id - Dictionary ID.\n */\n const deleteDictionary = async (\n id: DeleteDictionaryParam['dictionaryId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteDictionaryResult>(\n `${PROJECT_API_ROUTE}/${id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n return {\n getDictionaries,\n getDictionariesKeys,\n getDictionariesUpdateTimestamp,\n getDictionary,\n pushDictionaries,\n addDictionary,\n updateDictionary,\n deleteDictionary,\n };\n};\n\n/**\n * Authenticated `dictionary` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const dictionaryEndpoint = createEndpoint(getDictionaryAPI);\n"],"mappings":";;;;;AAsBA,MAAa,oBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,oBAAoB,GAFP,gBAAgB,QAAQ,cAAc,OAAO,WAExB;;;;;CAMxC,MAAM,kBAAkB,OACtB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;EACT,CACF;;;;CAKH,MAAM,sBAAsB,OAAO,eAA+B,EAAE,KAClE,MAAM,QACJ,GAAG,kBAAkB,QACrB,gBACA,cACA,EACE,OAAO,YACR,CACF;;;;CAKH,MAAM,iCAAiC,OACrC,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,UACrB,gBACA,cACA,EACE,OAAO,YACR,CACF;;;;;;CAOH,MAAM,g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