@intlayer/api 8.12.5-canary.0 → 9.0.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/getIntlayerAPI/ai.cjs +7 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/asset.cjs +86 -0
- package/dist/cjs/getIntlayerAPI/asset.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/index.cjs +2 -0
- package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/project.cjs +10 -0
- package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/esm/getIntlayerAPI/ai.mjs +7 -1
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/asset.mjs +85 -0
- package/dist/esm/getIntlayerAPI/asset.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/index.mjs +2 -0
- package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/project.mjs +10 -0
- package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/types/getIntlayerAPI/ai.d.ts +1 -0
- package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/asset.d.ts +18 -0
- package/dist/types/getIntlayerAPI/asset.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/index.d.ts +2 -0
- package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/project.d.ts +1 -0
- package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +13 -5
|
@@ -204,6 +204,11 @@ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
204
204
|
method: "GET",
|
|
205
205
|
params
|
|
206
206
|
});
|
|
207
|
+
/**
|
|
208
|
+
* Retrieves aggregated AI token-usage statistics for the currently selected
|
|
209
|
+
* project.
|
|
210
|
+
*/
|
|
211
|
+
const getAIStats = async (otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/stats`, authAPIOptions, otherOptions, { method: "GET" });
|
|
207
212
|
return {
|
|
208
213
|
customQuery,
|
|
209
214
|
translateJSON,
|
|
@@ -214,7 +219,8 @@ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
214
219
|
askDocQuestion,
|
|
215
220
|
chat,
|
|
216
221
|
autocomplete,
|
|
217
|
-
getDiscussions
|
|
222
|
+
getDiscussions,
|
|
223
|
+
getAIStats
|
|
218
224
|
};
|
|
219
225
|
};
|
|
220
226
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.cjs","names":["editor","fetcher"],"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 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 return {\n customQuery,\n translateJSON,\n auditContentDeclaration,\n auditContentDeclarationField,\n auditContentDeclarationMetadata,\n auditTag,\n askDocQuestion,\n chat,\n autocomplete,\n getDiscussions,\n };\n};\n"],"mappings":";;;;;AAsDA,MAAa,YACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,eAAe,GAFF,gBAAgB,QAAQ,cAAcA,8BAAO,WAE7B;;;;;;CAOnC,MAAM,cAAc,OAClB,MACA,eAA+B,EAAE,KAEjC,MAAMC,wBACJ,cACA,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,gBAAgB,OACpB,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,aAAa,kBAChB,gBACA,cACA;EACE,Q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etcher"],"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,cAAcA,8BAAO,WAE7B;;;;;;CAOnC,MAAM,cAAc,OAClB,MACA,eAA+B,EAAE,KAEjC,MAAMC,wBACJ,cACA,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,gBAAgB,OACpB,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,aAAa,kBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,0BAA0B,OAC9B,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,aAAa,oBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,+BAA+B,OACnC,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,aAAa,0BAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,kCAAkC,OACtC,MACA,eAA+B,EAAE,KAEjC,MAAMA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UAAU,MAAM,OAAO,MAAM;AAC3C,QAAI,KAAM;AAEV,cAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,MAAM,CAAC;IACjD,MAAM,QAAQ,OAAO,MAAM,KAAK;AAChC,aAAS,MAAM,KAAK,IAAI;AAExB,SAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,WAAW,SAAS,CAC3B,KAAI;KACF,MAAM,OAAO,KAAK,MAAM,KAAK,MAAM,EAAE,CAAC;AACtC,SAAI,KAAK,MACP,aAAY,KAAK,MAAM;AAEzB,SAAI,KAAK,OACP,YAAW,KAAK,OAAO;AAEzB,SAAI,KAAK,QAAQ,KAAK,SACpB,UAAS,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,MAAMA,wBACJ,GAAG,aAAa,gBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;CAKH,MAAM,iBAAiB,OACrB,QACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,aAAa,eAChB,gBACA,cACA;EACE,QAAQ;EAER;EACD,CACF;;;;;CAMH,MAAM,aAAa,OAAO,eAA+B,EAAE,KACzD,MAAMA,wBACJ,GAAG,aAAa,SAChB,gBACA,cACA,EACE,QAAQ,OACT,CACF;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_fetcher = require('../fetcher.cjs');
|
|
3
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
|
|
5
|
+
//#region src/getIntlayerAPI/asset.ts
|
|
6
|
+
const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
7
|
+
const ASSET_API_ROUTE = `${intlayerConfig?.editor?.backendURL ?? _intlayer_config_built.editor.backendURL}/api/assets`;
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves all assets for the current session project, paginated.
|
|
10
|
+
* @param page - Page number (1-based).
|
|
11
|
+
* @param pageSize - Number of items per page.
|
|
12
|
+
* @returns Paginated list of assets.
|
|
13
|
+
*/
|
|
14
|
+
const getAssets = async (page, pageSize, otherOptions = {}) => await require_fetcher.fetcher(ASSET_API_ROUTE, authAPIOptions, otherOptions, {
|
|
15
|
+
cache: "no-store",
|
|
16
|
+
params: {
|
|
17
|
+
...page !== void 0 && { page: String(page) },
|
|
18
|
+
...pageSize !== void 0 && { pageSize: String(pageSize) }
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves a single asset by ID.
|
|
23
|
+
* @param assetId - The asset document ID.
|
|
24
|
+
* @returns The asset.
|
|
25
|
+
*/
|
|
26
|
+
const getAssetById = async (assetId, otherOptions = {}) => await require_fetcher.fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, { cache: "no-store" });
|
|
27
|
+
/**
|
|
28
|
+
* Uploads a new asset image.
|
|
29
|
+
* @param file - The image File object.
|
|
30
|
+
* @param alt - Optional alt text.
|
|
31
|
+
* @param caption - Optional caption.
|
|
32
|
+
* @returns The created asset record with its public URL.
|
|
33
|
+
*/
|
|
34
|
+
const uploadAsset = async (file, alt, caption, otherOptions = {}) => {
|
|
35
|
+
const buffer = await file.arrayBuffer();
|
|
36
|
+
const headers = {
|
|
37
|
+
"Content-Type": file.type || "image/jpeg",
|
|
38
|
+
"X-File-Name": file.name
|
|
39
|
+
};
|
|
40
|
+
if (alt) headers["X-Alt-Text"] = alt;
|
|
41
|
+
if (caption) headers["X-Caption"] = caption;
|
|
42
|
+
const authHeaders = authAPIOptions.headers ?? {};
|
|
43
|
+
const response = await fetch(ASSET_API_ROUTE, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
credentials: "include",
|
|
46
|
+
headers: {
|
|
47
|
+
...authHeaders,
|
|
48
|
+
...headers
|
|
49
|
+
},
|
|
50
|
+
body: buffer,
|
|
51
|
+
signal: otherOptions.signal
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const result = await response.json();
|
|
55
|
+
throw new Error(JSON.stringify(result.error) ?? "Asset upload failed");
|
|
56
|
+
}
|
|
57
|
+
return await response.json();
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Updates mutable metadata (name, alt text, caption) of an asset.
|
|
61
|
+
* @param assetId - The asset document ID.
|
|
62
|
+
* @param data - Fields to update.
|
|
63
|
+
* @returns The updated asset record.
|
|
64
|
+
*/
|
|
65
|
+
const updateAsset = async (assetId, data, otherOptions = {}) => await require_fetcher.fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, {
|
|
66
|
+
method: "PATCH",
|
|
67
|
+
body: data
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Deletes an asset by ID.
|
|
71
|
+
* @param assetId - The asset document ID.
|
|
72
|
+
* @returns Confirmation response.
|
|
73
|
+
*/
|
|
74
|
+
const deleteAsset = async (assetId, otherOptions = {}) => await require_fetcher.fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, { method: "DELETE" });
|
|
75
|
+
return {
|
|
76
|
+
getAssets,
|
|
77
|
+
getAssetById,
|
|
78
|
+
uploadAsset,
|
|
79
|
+
updateAsset,
|
|
80
|
+
deleteAsset
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.getAssetAPI = getAssetAPI;
|
|
86
|
+
//# sourceMappingURL=asset.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.cjs","names":["editor","fetcher"],"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":";;;;;AAWA,MAAa,eACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,kBAAkB,GAFL,gBAAgB,QAAQ,cAAcA,8BAAO,WAE1B;;;;;;;CAQtC,MAAM,YAAY,OAChB,MACA,UACA,eAA+B,EAAE,KAEjC,MAAMC,wBACJ,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,MAAMA,wBACJ,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,MAAMA,wBACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA;EAAE,QAAQ;EAAS,MAAM;EAA4C,CACtE;;;;;;CAOH,MAAM,cAAc,OAClB,SACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,gBAAgB,GAAG,WACtB,gBACA,cACA,EAAE,QAAQ,UAAU,CACrB;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_getIntlayerAPI_ai = require('./ai.cjs');
|
|
3
|
+
const require_getIntlayerAPI_asset = require('./asset.cjs');
|
|
3
4
|
const require_getIntlayerAPI_audit = require('./audit.cjs');
|
|
4
5
|
const require_getIntlayerAPI_bitbucket = require('./bitbucket.cjs');
|
|
5
6
|
const require_getIntlayerAPI_dictionary = require('./dictionary.cjs');
|
|
@@ -25,6 +26,7 @@ let defu = require("defu");
|
|
|
25
26
|
const getIntlayerAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
26
27
|
const resolvedConfig = (0, defu.defu)(intlayerConfig ?? {}, { editor: _intlayer_config_built.editor });
|
|
27
28
|
return {
|
|
29
|
+
asset: require_getIntlayerAPI_asset.getAssetAPI(authAPIOptions, resolvedConfig),
|
|
28
30
|
organization: require_getIntlayerAPI_organization.getOrganizationAPI(authAPIOptions, resolvedConfig),
|
|
29
31
|
project: require_getIntlayerAPI_project.getProjectAPI(authAPIOptions, resolvedConfig),
|
|
30
32
|
environment: require_getIntlayerAPI_environment.getEnvironmentAPI(authAPIOptions, resolvedConfig),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["getOrganizationAPI","getProjectAPI","getEnvironmentAPI","getUserAPI","getOAuthAPI","getDictionaryAPI","getStripeAPI","getAiAPI","getAuditAPI","getTagAPI","getSearchAPI","getEditorAPI","getNewsletterAPI","getGithubAPI","getGitlabAPI","getBitbucketAPI","getShowcaseProjectAPI","getTranslateAPI","getReviewerAPI"],"sources":["../../../src/getIntlayerAPI/index.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 { getAiAPI } from './ai';\nimport { getAuditAPI } from './audit';\nimport { getBitbucketAPI } from './bitbucket';\nimport { getDictionaryAPI } from './dictionary';\nimport { getEditorAPI } from './editor';\nimport { getEnvironmentAPI } from './environment';\nimport { getGithubAPI } from './github';\nimport { getGitlabAPI } from './gitlab';\nimport { getNewsletterAPI } from './newsletter';\nimport { getOAuthAPI } from './oAuth';\nimport { getOrganizationAPI } from './organization';\nimport { getProjectAPI } from './project';\nimport { getReviewerAPI } from './reviewer';\nimport { getSearchAPI } from './search';\nimport { getShowcaseProjectAPI } from './showcaseProject';\nimport { getStripeAPI } from './stripe';\nimport { getTagAPI } from './tag';\nimport { getTranslateAPI } from './translate';\nimport { getUserAPI } from './user';\n\ninterface IntlayerAPIReturn {\n organization: ReturnType<typeof getOrganizationAPI>;\n project: ReturnType<typeof getProjectAPI>;\n environment: ReturnType<typeof getEnvironmentAPI>;\n user: ReturnType<typeof getUserAPI>;\n oAuth: ReturnType<typeof getOAuthAPI>;\n dictionary: ReturnType<typeof getDictionaryAPI>;\n stripe: ReturnType<typeof getStripeAPI>;\n ai: ReturnType<typeof getAiAPI>;\n audit: ReturnType<typeof getAuditAPI>;\n tag: ReturnType<typeof getTagAPI>;\n search: ReturnType<typeof getSearchAPI>;\n editor: ReturnType<typeof getEditorAPI>;\n newsletter: ReturnType<typeof getNewsletterAPI>;\n github: ReturnType<typeof getGithubAPI>;\n gitlab: ReturnType<typeof getGitlabAPI>;\n bitbucket: ReturnType<typeof getBitbucketAPI>;\n showcaseProject: ReturnType<typeof getShowcaseProjectAPI>;\n translate: ReturnType<typeof getTranslateAPI>;\n reviewer: ReturnType<typeof getReviewerAPI>;\n}\n\nexport const getIntlayerAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: Pick<IntlayerConfig, 'editor'>\n): IntlayerAPIReturn => {\n const resolvedConfig = defu(intlayerConfig ?? {}, {\n editor,\n }) as IntlayerConfig;\n\n return {\n organization: getOrganizationAPI(authAPIOptions, resolvedConfig),\n project: getProjectAPI(authAPIOptions, resolvedConfig),\n environment: getEnvironmentAPI(authAPIOptions, resolvedConfig),\n user: getUserAPI(authAPIOptions, resolvedConfig),\n oAuth: getOAuthAPI(authAPIOptions, resolvedConfig),\n dictionary: getDictionaryAPI(authAPIOptions, resolvedConfig),\n stripe: getStripeAPI(authAPIOptions, resolvedConfig),\n ai: getAiAPI(authAPIOptions, resolvedConfig),\n audit: getAuditAPI(authAPIOptions, resolvedConfig),\n tag: getTagAPI(authAPIOptions, resolvedConfig),\n search: getSearchAPI(authAPIOptions, resolvedConfig),\n editor: getEditorAPI(authAPIOptions, resolvedConfig),\n newsletter: getNewsletterAPI(authAPIOptions, resolvedConfig),\n github: getGithubAPI(authAPIOptions, resolvedConfig),\n gitlab: getGitlabAPI(authAPIOptions, resolvedConfig),\n bitbucket: getBitbucketAPI(authAPIOptions, resolvedConfig),\n showcaseProject: getShowcaseProjectAPI(authAPIOptions, resolvedConfig),\n translate: getTranslateAPI(authAPIOptions, resolvedConfig),\n reviewer: getReviewerAPI(authAPIOptions, resolvedConfig),\n };\n};\n\nexport type IntlayerAPI = ReturnType<typeof getIntlayerAPI>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["getAssetAPI","getOrganizationAPI","getProjectAPI","getEnvironmentAPI","getUserAPI","getOAuthAPI","getDictionaryAPI","getStripeAPI","getAiAPI","getAuditAPI","getTagAPI","getSearchAPI","getEditorAPI","getNewsletterAPI","getGithubAPI","getGitlabAPI","getBitbucketAPI","getShowcaseProjectAPI","getTranslateAPI","getReviewerAPI"],"sources":["../../../src/getIntlayerAPI/index.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 { getAiAPI } from './ai';\nimport { getAssetAPI } from './asset';\nimport { getAuditAPI } from './audit';\nimport { getBitbucketAPI } from './bitbucket';\nimport { getDictionaryAPI } from './dictionary';\nimport { getEditorAPI } from './editor';\nimport { getEnvironmentAPI } from './environment';\nimport { getGithubAPI } from './github';\nimport { getGitlabAPI } from './gitlab';\nimport { getNewsletterAPI } from './newsletter';\nimport { getOAuthAPI } from './oAuth';\nimport { getOrganizationAPI } from './organization';\nimport { getProjectAPI } from './project';\nimport { getReviewerAPI } from './reviewer';\nimport { getSearchAPI } from './search';\nimport { getShowcaseProjectAPI } from './showcaseProject';\nimport { getStripeAPI } from './stripe';\nimport { getTagAPI } from './tag';\nimport { getTranslateAPI } from './translate';\nimport { getUserAPI } from './user';\n\ninterface IntlayerAPIReturn {\n asset: ReturnType<typeof getAssetAPI>;\n organization: ReturnType<typeof getOrganizationAPI>;\n project: ReturnType<typeof getProjectAPI>;\n environment: ReturnType<typeof getEnvironmentAPI>;\n user: ReturnType<typeof getUserAPI>;\n oAuth: ReturnType<typeof getOAuthAPI>;\n dictionary: ReturnType<typeof getDictionaryAPI>;\n stripe: ReturnType<typeof getStripeAPI>;\n ai: ReturnType<typeof getAiAPI>;\n audit: ReturnType<typeof getAuditAPI>;\n tag: ReturnType<typeof getTagAPI>;\n search: ReturnType<typeof getSearchAPI>;\n editor: ReturnType<typeof getEditorAPI>;\n newsletter: ReturnType<typeof getNewsletterAPI>;\n github: ReturnType<typeof getGithubAPI>;\n gitlab: ReturnType<typeof getGitlabAPI>;\n bitbucket: ReturnType<typeof getBitbucketAPI>;\n showcaseProject: ReturnType<typeof getShowcaseProjectAPI>;\n translate: ReturnType<typeof getTranslateAPI>;\n reviewer: ReturnType<typeof getReviewerAPI>;\n}\n\nexport const getIntlayerAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: Pick<IntlayerConfig, 'editor'>\n): IntlayerAPIReturn => {\n const resolvedConfig = defu(intlayerConfig ?? {}, {\n editor,\n }) as IntlayerConfig;\n\n return {\n asset: getAssetAPI(authAPIOptions, resolvedConfig),\n organization: getOrganizationAPI(authAPIOptions, resolvedConfig),\n project: getProjectAPI(authAPIOptions, resolvedConfig),\n environment: getEnvironmentAPI(authAPIOptions, resolvedConfig),\n user: getUserAPI(authAPIOptions, resolvedConfig),\n oAuth: getOAuthAPI(authAPIOptions, resolvedConfig),\n dictionary: getDictionaryAPI(authAPIOptions, resolvedConfig),\n stripe: getStripeAPI(authAPIOptions, resolvedConfig),\n ai: getAiAPI(authAPIOptions, resolvedConfig),\n audit: getAuditAPI(authAPIOptions, resolvedConfig),\n tag: getTagAPI(authAPIOptions, resolvedConfig),\n search: getSearchAPI(authAPIOptions, resolvedConfig),\n editor: getEditorAPI(authAPIOptions, resolvedConfig),\n newsletter: getNewsletterAPI(authAPIOptions, resolvedConfig),\n github: getGithubAPI(authAPIOptions, resolvedConfig),\n gitlab: getGitlabAPI(authAPIOptions, resolvedConfig),\n bitbucket: getBitbucketAPI(authAPIOptions, resolvedConfig),\n showcaseProject: getShowcaseProjectAPI(authAPIOptions, resolvedConfig),\n translate: getTranslateAPI(authAPIOptions, resolvedConfig),\n reviewer: getReviewerAPI(authAPIOptions, resolvedConfig),\n };\n};\n\nexport type IntlayerAPI = ReturnType<typeof getIntlayerAPI>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,kBACX,iBAAiC,EAAE,EACnC,mBACsB;CACtB,MAAM,gCAAsB,kBAAkB,EAAE,EAAE,EAChD,uCACD,CAAC;AAEF,QAAO;EACL,OAAOA,yCAAY,gBAAgB,eAAe;EAClD,cAAcC,uDAAmB,gBAAgB,eAAe;EAChE,SAASC,6CAAc,gBAAgB,eAAe;EACtD,aAAaC,qDAAkB,gBAAgB,eAAe;EAC9D,MAAMC,uCAAW,gBAAgB,eAAe;EAChD,OAAOC,yCAAY,gBAAgB,eAAe;EAClD,YAAYC,mDAAiB,gBAAgB,eAAe;EAC5D,QAAQC,2CAAa,gBAAgB,eAAe;EACpD,IAAIC,mCAAS,gBAAgB,eAAe;EAC5C,OAAOC,yCAAY,gBAAgB,eAAe;EAClD,KAAKC,qCAAU,gBAAgB,eAAe;EAC9C,QAAQC,2CAAa,gBAAgB,eAAe;EACpD,QAAQC,2CAAa,gBAAgB,eAAe;EACpD,YAAYC,mDAAiB,gBAAgB,eAAe;EAC5D,QAAQC,2CAAa,gBAAgB,eAAe;EACpD,QAAQC,2CAAa,gBAAgB,eAAe;EACpD,WAAWC,iDAAgB,gBAAgB,eAAe;EAC1D,iBAAiBC,6DAAsB,gBAAgB,eAAe;EACtE,WAAWC,iDAAgB,gBAAgB,eAAe;EAC1D,UAAUC,+CAAe,gBAAgB,eAAe;EACzD"}
|
|
@@ -14,6 +14,15 @@ const getProjectAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
14
14
|
params: filters
|
|
15
15
|
});
|
|
16
16
|
/**
|
|
17
|
+
* Retrieves aggregated localization insights for the currently selected
|
|
18
|
+
* project (locale/key counts, per-locale completion, missing translations,
|
|
19
|
+
* recent activity, team/config status).
|
|
20
|
+
*/
|
|
21
|
+
const getProjectInsights = async (otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}/insights`, authAPIOptions, otherOptions, {
|
|
22
|
+
cache: "no-store",
|
|
23
|
+
method: "GET"
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
17
26
|
* Adds a new project to the database.
|
|
18
27
|
* @param project - Project data.
|
|
19
28
|
*/
|
|
@@ -133,6 +142,7 @@ const getProjectAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
133
142
|
});
|
|
134
143
|
return {
|
|
135
144
|
getProjects,
|
|
145
|
+
getProjectInsights,
|
|
136
146
|
addProject,
|
|
137
147
|
updateProject,
|
|
138
148
|
updateProjectMembers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.cjs","names":["editor","fetcher"],"sources":["../../../src/getIntlayerAPI/project.ts"],"sourcesContent":["import type {\n AddNewAccessKeyBody,\n AddNewAccessKeyResponse,\n AddProjectBody,\n AddProjectResult,\n DeleteAccessKeyBody,\n DeleteAccessKeyResponse,\n DeleteProjectResult,\n GetProjectsParams,\n GetProjectsResult,\n PushProjectConfigurationBody,\n PushProjectConfigurationResult,\n RefreshAccessKeyBody,\n RefreshAccessKeyResponse,\n ResponseData,\n SelectProjectParam,\n SelectProjectResult,\n TriggerBuildResult,\n TriggerWebhookBody,\n TriggerWebhookResult,\n UnselectProjectResult,\n UpdateMemberAccessBody,\n UpdateMemberAccessResult,\n UpdateProjectBody,\n UpdateProjectMembersBody,\n UpdateProjectMembersResult,\n UpdateProjectResult,\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 getProjectAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const PROJECT_API_ROUTE = `${backendURL}/api/project`;\n\n /**\n * Retrieves a list of projects based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getProjects = async (\n filters?: GetProjectsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetProjectsResult>(\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 * Adds a new project to the database.\n * @param project - Project data.\n */\n const addProject = async (\n project: AddProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: project,\n }\n );\n\n /**\n * Updates an existing project in the database.\n * @param project - Updated project data.\n */\n const updateProject = async (\n project: UpdateProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: project,\n }\n );\n\n /**\n * Updates project members in the database.\n * @param project - Updated project data.\n */\n const updateProjectMembers = async (\n body: UpdateProjectMembersBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectMembersResult>(\n `${PROJECT_API_ROUTE}/members`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body,\n }\n );\n\n /** Pushes a project configuration to the database.\n * @param projectConfiguration - Project configuration data.\n */\n const pushProjectConfiguration = async (\n projectConfiguration: PushProjectConfigurationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushProjectConfigurationResult>(\n `${PROJECT_API_ROUTE}/configuration`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: projectConfiguration,\n }\n );\n\n /**\n * Deletes a project from the database by its ID.\n * @param id - Project ID.\n */\n const deleteProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n /**\n * Admin-only: Deletes any project from the database by its ID.\n * @param projectId - Project ID.\n */\n const deleteProjectByIdAdmin = async (\n projectId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}/${projectId}/admin`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n /**\n * Select a project from the database by its ID.\n * @param projectId - Organization ID.\n */\n const selectProject = async (\n projectId: SelectProjectParam['projectId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<SelectProjectResult>(\n `${PROJECT_API_ROUTE}/${String(projectId)}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n }\n );\n\n /**\n * Unselect a project from the database by its ID.\n * @param projectId - Project ID.\n */\n const unselectProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<UnselectProjectResult>(\n `${PROJECT_API_ROUTE}/logout`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Add a new access key to a project.\n * @param accessKey - Access key data.\n * @param otherOptions - Fetcher options.\n * @returns The new access key.\n */\n const addNewAccessKey = async (\n accessKey: AddNewAccessKeyBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddNewAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: accessKey,\n }\n );\n\n /**\n * Delete a project access key.\n * @param clientId - Access key client ID.\n * @param otherOptions - Fetcher options.\n * @returns The deleted project.\n */\n const deleteAccessKey = async (\n clientId: DeleteAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n body: { clientId },\n }\n );\n\n /**\n * Refreshes an access key from a project.\n * @param clientId - The ID of the client to refresh.\n * @param projectId - The ID of the project to refresh the access key from.\n * @returns The new access key.\n */\n const refreshAccessKey = async (\n clientId: RefreshAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<RefreshAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { clientId },\n }\n );\n\n /**\n * Triggers CI builds for a project (Git provider pipelines and webhooks).\n * @param otherOptions - Fetcher options.\n * @returns The trigger results.\n */\n const triggerBuild = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<TriggerBuildResult>(\n `${PROJECT_API_ROUTE}/build`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Triggers a single webhook by index.\n * @param webhookIndex - The index of the webhook to trigger.\n * @param otherOptions - Fetcher options.\n * @returns The trigger result.\n */\n const triggerWebhook = async (\n webhookIndex: TriggerWebhookBody['webhookIndex'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TriggerWebhookResult>(\n `${PROJECT_API_ROUTE}/webhook`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { webhookIndex },\n }\n );\n\n /**\n * Get CI configuration status for the current project.\n * @param otherOptions - Fetcher options.\n * @returns The CI configuration status.\n */\n const getCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n /**\n * Push CI configuration file to the repository.\n * @param otherOptions - Fetcher options.\n * @returns Success status.\n */\n const pushCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Updates granular access constraints for a project member.\n * @param userId - The user ID to update access for.\n * @param body - The new access constraints.\n */\n const updateMemberAccess = async (\n userId: string,\n body: UpdateMemberAccessBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateMemberAccessResult>(\n `${PROJECT_API_ROUTE}/member/${userId}/access`,\n authAPIOptions,\n otherOptions,\n { method: 'PUT', body }\n );\n\n return {\n getProjects,\n addProject,\n updateProject,\n updateProjectMembers,\n pushProjectConfiguration,\n deleteProject,\n deleteProjectByIdAdmin,\n selectProject,\n unselectProject,\n addNewAccessKey,\n deleteAccessKey,\n refreshAccessKey,\n triggerBuild,\n triggerWebhook,\n getCIConfig,\n pushCIConfig,\n updateMemberAccess,\n };\n};\n"],"mappings":";;;;;AAgCA,MAAa,iBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,oBAAoB,GAFP,gBAAgB,QAAQ,cAAcA,8BAAO,WAExB;;;;;CAMxC,MAAM,cAAc,OAClB,SACA,eAA+B,EAAE,KAEjC,MAAMC,wBACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;EACT,CACF;;;;;CAMH,MAAM,aAAa,OACjB,SACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,gBAAgB,OACpB,SACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,uBAAuB,OAC3B,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,kBAAkB,WACrB,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;;;;CAKH,MAAM,2BAA2B,OAC/B,sBACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,kBAAkB,iBACrB,gBACA,cACA;EACE,QAAQ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F;;;;;;CAOH,MAAM,cAAc,OAAO,eAA+B,EAAE,KAC1D,MAAMA,wBACJ,GAAG,kBAAkB,MACrB,gBACA,cACA,EACE,QAAQ,OACT,CACF;;;;;;CAOH,MAAM,eAAe,OAAO,eAA+B,EAAE,KAC3D,MAAMA,wBACJ,GAAG,kBAAkB,MACrB,gBACA,cACA,EACE,QAAQ,QACT,CACF;;;;;;CAOH,MAAM,qBAAqB,OACzB,QACA,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,kBAAkB,UAAU,OAAO,UACtC,gBACA,cACA;EAAE,QAAQ;EAAO;EAAM,CACxB;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"project.cjs","names":["editor","fetcher"],"sources":["../../../src/getIntlayerAPI/project.ts"],"sourcesContent":["import type {\n AddNewAccessKeyBody,\n AddNewAccessKeyResponse,\n AddProjectBody,\n AddProjectResult,\n DeleteAccessKeyBody,\n DeleteAccessKeyResponse,\n DeleteProjectResult,\n GetProjectInsightsResult,\n GetProjectsParams,\n GetProjectsResult,\n PushProjectConfigurationBody,\n PushProjectConfigurationResult,\n RefreshAccessKeyBody,\n RefreshAccessKeyResponse,\n ResponseData,\n SelectProjectParam,\n SelectProjectResult,\n TriggerBuildResult,\n TriggerWebhookBody,\n TriggerWebhookResult,\n UnselectProjectResult,\n UpdateMemberAccessBody,\n UpdateMemberAccessResult,\n UpdateProjectBody,\n UpdateProjectMembersBody,\n UpdateProjectMembersResult,\n UpdateProjectResult,\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 getProjectAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const PROJECT_API_ROUTE = `${backendURL}/api/project`;\n\n /**\n * Retrieves a list of projects based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getProjects = async (\n filters?: GetProjectsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetProjectsResult>(\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 aggregated localization insights for the currently selected\n * project (locale/key counts, per-locale completion, missing translations,\n * recent activity, team/config status).\n */\n const getProjectInsights = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetProjectInsightsResult>(\n `${PROJECT_API_ROUTE}/insights`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n method: 'GET',\n }\n );\n\n /**\n * Adds a new project to the database.\n * @param project - Project data.\n */\n const addProject = async (\n project: AddProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: project,\n }\n );\n\n /**\n * Updates an existing project in the database.\n * @param project - Updated project data.\n */\n const updateProject = async (\n project: UpdateProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: project,\n }\n );\n\n /**\n * Updates project members in the database.\n * @param project - Updated project data.\n */\n const updateProjectMembers = async (\n body: UpdateProjectMembersBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectMembersResult>(\n `${PROJECT_API_ROUTE}/members`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body,\n }\n );\n\n /** Pushes a project configuration to the database.\n * @param projectConfiguration - Project configuration data.\n */\n const pushProjectConfiguration = async (\n projectConfiguration: PushProjectConfigurationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushProjectConfigurationResult>(\n `${PROJECT_API_ROUTE}/configuration`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: projectConfiguration,\n }\n );\n\n /**\n * Deletes a project from the database by its ID.\n * @param id - Project ID.\n */\n const deleteProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n /**\n * Admin-only: Deletes any project from the database by its ID.\n * @param projectId - Project ID.\n */\n const deleteProjectByIdAdmin = async (\n projectId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}/${projectId}/admin`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n /**\n * Select a project from the database by its ID.\n * @param projectId - Organization ID.\n */\n const selectProject = async (\n projectId: SelectProjectParam['projectId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<SelectProjectResult>(\n `${PROJECT_API_ROUTE}/${String(projectId)}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n }\n );\n\n /**\n * Unselect a project from the database by its ID.\n * @param projectId - Project ID.\n */\n const unselectProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<UnselectProjectResult>(\n `${PROJECT_API_ROUTE}/logout`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Add a new access key to a project.\n * @param accessKey - Access key data.\n * @param otherOptions - Fetcher options.\n * @returns The new access key.\n */\n const addNewAccessKey = async (\n accessKey: AddNewAccessKeyBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddNewAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: accessKey,\n }\n );\n\n /**\n * Delete a project access key.\n * @param clientId - Access key client ID.\n * @param otherOptions - Fetcher options.\n * @returns The deleted project.\n */\n const deleteAccessKey = async (\n clientId: DeleteAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n body: { clientId },\n }\n );\n\n /**\n * Refreshes an access key from a project.\n * @param clientId - The ID of the client to refresh.\n * @param projectId - The ID of the project to refresh the access key from.\n * @returns The new access key.\n */\n const refreshAccessKey = async (\n clientId: RefreshAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<RefreshAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { clientId },\n }\n );\n\n /**\n * Triggers CI builds for a project (Git provider pipelines and webhooks).\n * @param otherOptions - Fetcher options.\n * @returns The trigger results.\n */\n const triggerBuild = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<TriggerBuildResult>(\n `${PROJECT_API_ROUTE}/build`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Triggers a single webhook by index.\n * @param webhookIndex - The index of the webhook to trigger.\n * @param otherOptions - Fetcher options.\n * @returns The trigger result.\n */\n const triggerWebhook = async (\n webhookIndex: TriggerWebhookBody['webhookIndex'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TriggerWebhookResult>(\n `${PROJECT_API_ROUTE}/webhook`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { webhookIndex },\n }\n );\n\n /**\n * Get CI configuration status for the current project.\n * @param otherOptions - Fetcher options.\n * @returns The CI configuration status.\n */\n const getCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n /**\n * Push CI configuration file to the repository.\n * @param otherOptions - Fetcher options.\n * @returns Success status.\n */\n const pushCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Updates granular access constraints for a project member.\n * @param userId - The user ID to update access for.\n * @param body - The new access constraints.\n */\n const updateMemberAccess = async (\n userId: string,\n body: UpdateMemberAccessBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateMemberAccessResult>(\n `${PROJECT_API_ROUTE}/member/${userId}/access`,\n authAPIOptions,\n otherOptions,\n { method: 'PUT', body }\n );\n\n return {\n getProjects,\n getProjectInsights,\n addProject,\n updateProject,\n updateProjectMembers,\n pushProjectConfiguration,\n deleteProject,\n deleteProjectByIdAdmin,\n selectProject,\n unselectProject,\n addNewAccessKey,\n deleteAccessKey,\n refreshAccessKey,\n triggerBuild,\n triggerWebhook,\n getCIConfig,\n pushCIConfig,\n updateMemberAccess,\n };\n};\n"],"mappings":";;;;;AAiCA,MAAa,iBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,oBAAoB,GAFP,gBAAgB,QAAQ,cAAcA,8BAAO,WAExB;;;;;CAMxC,MAAM,cAAc,OAClB,SACA,eAA+B,EAAE,KAEjC,MAAMC,wBACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;EACT,CACF;;;;;;CAOH,MAAM,qBAAqB,OAAO,eAA+B,EAAE,KACjE,MAAMA,wBACJ,GAAG,kBAAkB,YACrB,gBACA,cACA;EACE,OAAO;EACP,QAAQ;EACT,CACF;;;;;CAMH,MAAM,aAAa,OACjB,SACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,gBAAgB,OACpB,SACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;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AO,eAA+B,EAAE,KAC3D,MAAMA,wBACJ,GAAG,kBAAkB,SACrB,gBACA,cACA,EACE,QAAQ,QACT,CACF;;;;;;;CAQH,MAAM,iBAAiB,OACrB,cACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,kBAAkB,WACrB,gBACA,cACA;EACE,QAAQ;EACR,MAAM,EAAE,cAAc;EACvB,CACF;;;;;;CAOH,MAAM,cAAc,OAAO,eAA+B,EAAE,KAC1D,MAAMA,wBACJ,GAAG,kBAAkB,MACrB,gBACA,cACA,EACE,QAAQ,OACT,CACF;;;;;;CAOH,MAAM,eAAe,OAAO,eAA+B,EAAE,KAC3D,MAAMA,wBACJ,GAAG,kBAAkB,MACrB,gBACA,cACA,EACE,QAAQ,QACT,CACF;;;;;;CAOH,MAAM,qBAAqB,OACzB,QACA,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,kBAAkB,UAAU,OAAO,UACtC,gBACA,cACA;EAAE,QAAQ;EAAO;EAAM,CACxB;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_fetcher = require('./fetcher.cjs');
|
|
3
3
|
const require_getIntlayerAPI_ai = require('./getIntlayerAPI/ai.cjs');
|
|
4
|
+
const require_getIntlayerAPI_asset = require('./getIntlayerAPI/asset.cjs');
|
|
4
5
|
const require_getIntlayerAPI_audit = require('./getIntlayerAPI/audit.cjs');
|
|
5
6
|
const require_getIntlayerAPI_bitbucket = require('./getIntlayerAPI/bitbucket.cjs');
|
|
6
7
|
const require_getIntlayerAPI_dictionary = require('./getIntlayerAPI/dictionary.cjs');
|
|
@@ -29,6 +30,7 @@ exports.fetchDistantDictionary = require_distantDictionary_fetchDistantDictionar
|
|
|
29
30
|
exports.fetcher = require_fetcher.fetcher;
|
|
30
31
|
exports.fetcherOptions = require_fetcher.fetcherOptions;
|
|
31
32
|
exports.getAiAPI = require_getIntlayerAPI_ai.getAiAPI;
|
|
33
|
+
exports.getAssetAPI = require_getIntlayerAPI_asset.getAssetAPI;
|
|
32
34
|
exports.getAuditAPI = require_getIntlayerAPI_audit.getAuditAPI;
|
|
33
35
|
exports.getBitbucketAPI = require_getIntlayerAPI_bitbucket.getBitbucketAPI;
|
|
34
36
|
exports.getDictionaryAPI = require_getIntlayerAPI_dictionary.getDictionaryAPI;
|
|
@@ -203,6 +203,11 @@ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
203
203
|
method: "GET",
|
|
204
204
|
params
|
|
205
205
|
});
|
|
206
|
+
/**
|
|
207
|
+
* Retrieves aggregated AI token-usage statistics for the currently selected
|
|
208
|
+
* project.
|
|
209
|
+
*/
|
|
210
|
+
const getAIStats = async (otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/stats`, authAPIOptions, otherOptions, { method: "GET" });
|
|
206
211
|
return {
|
|
207
212
|
customQuery,
|
|
208
213
|
translateJSON,
|
|
@@ -213,7 +218,8 @@ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
213
218
|
askDocQuestion,
|
|
214
219
|
chat,
|
|
215
220
|
autocomplete,
|
|
216
|
-
getDiscussions
|
|
221
|
+
getDiscussions,
|
|
222
|
+
getAIStats
|
|
217
223
|
};
|
|
218
224
|
};
|
|
219
225
|
|
|
@@ -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 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 return {\n customQuery,\n translateJSON,\n auditContentDeclaration,\n auditContentDeclarationField,\n auditContentDeclarationMetadata,\n auditTag,\n askDocQuestion,\n chat,\n autocomplete,\n getDiscussions,\n };\n};\n"],"mappings":";;;;AAsDA,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,SAA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AQ,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;AAEH,QAAO;EACL;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 { 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,OACp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,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"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { fetcher } from "../fetcher.mjs";
|
|
2
|
+
import { editor } from "@intlayer/config/built";
|
|
3
|
+
|
|
4
|
+
//#region src/getIntlayerAPI/asset.ts
|
|
5
|
+
const getAssetAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
6
|
+
const ASSET_API_ROUTE = `${intlayerConfig?.editor?.backendURL ?? editor.backendURL}/api/assets`;
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves all assets for the current session project, paginated.
|
|
9
|
+
* @param page - Page number (1-based).
|
|
10
|
+
* @param pageSize - Number of items per page.
|
|
11
|
+
* @returns Paginated list of assets.
|
|
12
|
+
*/
|
|
13
|
+
const getAssets = async (page, pageSize, otherOptions = {}) => await fetcher(ASSET_API_ROUTE, authAPIOptions, otherOptions, {
|
|
14
|
+
cache: "no-store",
|
|
15
|
+
params: {
|
|
16
|
+
...page !== void 0 && { page: String(page) },
|
|
17
|
+
...pageSize !== void 0 && { pageSize: String(pageSize) }
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves a single asset by ID.
|
|
22
|
+
* @param assetId - The asset document ID.
|
|
23
|
+
* @returns The asset.
|
|
24
|
+
*/
|
|
25
|
+
const getAssetById = async (assetId, otherOptions = {}) => await fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, { cache: "no-store" });
|
|
26
|
+
/**
|
|
27
|
+
* Uploads a new asset image.
|
|
28
|
+
* @param file - The image File object.
|
|
29
|
+
* @param alt - Optional alt text.
|
|
30
|
+
* @param caption - Optional caption.
|
|
31
|
+
* @returns The created asset record with its public URL.
|
|
32
|
+
*/
|
|
33
|
+
const uploadAsset = async (file, alt, caption, otherOptions = {}) => {
|
|
34
|
+
const buffer = await file.arrayBuffer();
|
|
35
|
+
const headers = {
|
|
36
|
+
"Content-Type": file.type || "image/jpeg",
|
|
37
|
+
"X-File-Name": file.name
|
|
38
|
+
};
|
|
39
|
+
if (alt) headers["X-Alt-Text"] = alt;
|
|
40
|
+
if (caption) headers["X-Caption"] = caption;
|
|
41
|
+
const authHeaders = authAPIOptions.headers ?? {};
|
|
42
|
+
const response = await fetch(ASSET_API_ROUTE, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
credentials: "include",
|
|
45
|
+
headers: {
|
|
46
|
+
...authHeaders,
|
|
47
|
+
...headers
|
|
48
|
+
},
|
|
49
|
+
body: buffer,
|
|
50
|
+
signal: otherOptions.signal
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const result = await response.json();
|
|
54
|
+
throw new Error(JSON.stringify(result.error) ?? "Asset upload failed");
|
|
55
|
+
}
|
|
56
|
+
return await response.json();
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Updates mutable metadata (name, alt text, caption) of an asset.
|
|
60
|
+
* @param assetId - The asset document ID.
|
|
61
|
+
* @param data - Fields to update.
|
|
62
|
+
* @returns The updated asset record.
|
|
63
|
+
*/
|
|
64
|
+
const updateAsset = async (assetId, data, otherOptions = {}) => await fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, {
|
|
65
|
+
method: "PATCH",
|
|
66
|
+
body: data
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Deletes an asset by ID.
|
|
70
|
+
* @param assetId - The asset document ID.
|
|
71
|
+
* @returns Confirmation response.
|
|
72
|
+
*/
|
|
73
|
+
const deleteAsset = async (assetId, otherOptions = {}) => await fetcher(`${ASSET_API_ROUTE}/${assetId}`, authAPIOptions, otherOptions, { method: "DELETE" });
|
|
74
|
+
return {
|
|
75
|
+
getAssets,
|
|
76
|
+
getAssetById,
|
|
77
|
+
uploadAsset,
|
|
78
|
+
updateAsset,
|
|
79
|
+
deleteAsset
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { getAssetAPI };
|
|
85
|
+
//# sourceMappingURL=asset.mjs.map
|
|
@@ -0,0 +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":";;;;AAWA,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,O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./ai.mjs";
|
|
2
|
+
import { getAssetAPI } from "./asset.mjs";
|
|
2
3
|
import { getAuditAPI } from "./audit.mjs";
|
|
3
4
|
import { getBitbucketAPI } from "./bitbucket.mjs";
|
|
4
5
|
import { getDictionaryAPI } from "./dictionary.mjs";
|
|
@@ -24,6 +25,7 @@ import { defu } from "defu";
|
|
|
24
25
|
const getIntlayerAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
25
26
|
const resolvedConfig = defu(intlayerConfig ?? {}, { editor });
|
|
26
27
|
return {
|
|
28
|
+
asset: getAssetAPI(authAPIOptions, resolvedConfig),
|
|
27
29
|
organization: getOrganizationAPI(authAPIOptions, resolvedConfig),
|
|
28
30
|
project: getProjectAPI(authAPIOptions, resolvedConfig),
|
|
29
31
|
environment: getEnvironmentAPI(authAPIOptions, resolvedConfig),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/getIntlayerAPI/index.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 { getAiAPI } from './ai';\nimport { getAuditAPI } from './audit';\nimport { getBitbucketAPI } from './bitbucket';\nimport { getDictionaryAPI } from './dictionary';\nimport { getEditorAPI } from './editor';\nimport { getEnvironmentAPI } from './environment';\nimport { getGithubAPI } from './github';\nimport { getGitlabAPI } from './gitlab';\nimport { getNewsletterAPI } from './newsletter';\nimport { getOAuthAPI } from './oAuth';\nimport { getOrganizationAPI } from './organization';\nimport { getProjectAPI } from './project';\nimport { getReviewerAPI } from './reviewer';\nimport { getSearchAPI } from './search';\nimport { getShowcaseProjectAPI } from './showcaseProject';\nimport { getStripeAPI } from './stripe';\nimport { getTagAPI } from './tag';\nimport { getTranslateAPI } from './translate';\nimport { getUserAPI } from './user';\n\ninterface IntlayerAPIReturn {\n organization: ReturnType<typeof getOrganizationAPI>;\n project: ReturnType<typeof getProjectAPI>;\n environment: ReturnType<typeof getEnvironmentAPI>;\n user: ReturnType<typeof getUserAPI>;\n oAuth: ReturnType<typeof getOAuthAPI>;\n dictionary: ReturnType<typeof getDictionaryAPI>;\n stripe: ReturnType<typeof getStripeAPI>;\n ai: ReturnType<typeof getAiAPI>;\n audit: ReturnType<typeof getAuditAPI>;\n tag: ReturnType<typeof getTagAPI>;\n search: ReturnType<typeof getSearchAPI>;\n editor: ReturnType<typeof getEditorAPI>;\n newsletter: ReturnType<typeof getNewsletterAPI>;\n github: ReturnType<typeof getGithubAPI>;\n gitlab: ReturnType<typeof getGitlabAPI>;\n bitbucket: ReturnType<typeof getBitbucketAPI>;\n showcaseProject: ReturnType<typeof getShowcaseProjectAPI>;\n translate: ReturnType<typeof getTranslateAPI>;\n reviewer: ReturnType<typeof getReviewerAPI>;\n}\n\nexport const getIntlayerAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: Pick<IntlayerConfig, 'editor'>\n): IntlayerAPIReturn => {\n const resolvedConfig = defu(intlayerConfig ?? {}, {\n editor,\n }) as IntlayerConfig;\n\n return {\n organization: getOrganizationAPI(authAPIOptions, resolvedConfig),\n project: getProjectAPI(authAPIOptions, resolvedConfig),\n environment: getEnvironmentAPI(authAPIOptions, resolvedConfig),\n user: getUserAPI(authAPIOptions, resolvedConfig),\n oAuth: getOAuthAPI(authAPIOptions, resolvedConfig),\n dictionary: getDictionaryAPI(authAPIOptions, resolvedConfig),\n stripe: getStripeAPI(authAPIOptions, resolvedConfig),\n ai: getAiAPI(authAPIOptions, resolvedConfig),\n audit: getAuditAPI(authAPIOptions, resolvedConfig),\n tag: getTagAPI(authAPIOptions, resolvedConfig),\n search: getSearchAPI(authAPIOptions, resolvedConfig),\n editor: getEditorAPI(authAPIOptions, resolvedConfig),\n newsletter: getNewsletterAPI(authAPIOptions, resolvedConfig),\n github: getGithubAPI(authAPIOptions, resolvedConfig),\n gitlab: getGitlabAPI(authAPIOptions, resolvedConfig),\n bitbucket: getBitbucketAPI(authAPIOptions, resolvedConfig),\n showcaseProject: getShowcaseProjectAPI(authAPIOptions, resolvedConfig),\n translate: getTranslateAPI(authAPIOptions, resolvedConfig),\n reviewer: getReviewerAPI(authAPIOptions, resolvedConfig),\n };\n};\n\nexport type IntlayerAPI = ReturnType<typeof getIntlayerAPI>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/getIntlayerAPI/index.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 { getAiAPI } from './ai';\nimport { getAssetAPI } from './asset';\nimport { getAuditAPI } from './audit';\nimport { getBitbucketAPI } from './bitbucket';\nimport { getDictionaryAPI } from './dictionary';\nimport { getEditorAPI } from './editor';\nimport { getEnvironmentAPI } from './environment';\nimport { getGithubAPI } from './github';\nimport { getGitlabAPI } from './gitlab';\nimport { getNewsletterAPI } from './newsletter';\nimport { getOAuthAPI } from './oAuth';\nimport { getOrganizationAPI } from './organization';\nimport { getProjectAPI } from './project';\nimport { getReviewerAPI } from './reviewer';\nimport { getSearchAPI } from './search';\nimport { getShowcaseProjectAPI } from './showcaseProject';\nimport { getStripeAPI } from './stripe';\nimport { getTagAPI } from './tag';\nimport { getTranslateAPI } from './translate';\nimport { getUserAPI } from './user';\n\ninterface IntlayerAPIReturn {\n asset: ReturnType<typeof getAssetAPI>;\n organization: ReturnType<typeof getOrganizationAPI>;\n project: ReturnType<typeof getProjectAPI>;\n environment: ReturnType<typeof getEnvironmentAPI>;\n user: ReturnType<typeof getUserAPI>;\n oAuth: ReturnType<typeof getOAuthAPI>;\n dictionary: ReturnType<typeof getDictionaryAPI>;\n stripe: ReturnType<typeof getStripeAPI>;\n ai: ReturnType<typeof getAiAPI>;\n audit: ReturnType<typeof getAuditAPI>;\n tag: ReturnType<typeof getTagAPI>;\n search: ReturnType<typeof getSearchAPI>;\n editor: ReturnType<typeof getEditorAPI>;\n newsletter: ReturnType<typeof getNewsletterAPI>;\n github: ReturnType<typeof getGithubAPI>;\n gitlab: ReturnType<typeof getGitlabAPI>;\n bitbucket: ReturnType<typeof getBitbucketAPI>;\n showcaseProject: ReturnType<typeof getShowcaseProjectAPI>;\n translate: ReturnType<typeof getTranslateAPI>;\n reviewer: ReturnType<typeof getReviewerAPI>;\n}\n\nexport const getIntlayerAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: Pick<IntlayerConfig, 'editor'>\n): IntlayerAPIReturn => {\n const resolvedConfig = defu(intlayerConfig ?? {}, {\n editor,\n }) as IntlayerConfig;\n\n return {\n asset: getAssetAPI(authAPIOptions, resolvedConfig),\n organization: getOrganizationAPI(authAPIOptions, resolvedConfig),\n project: getProjectAPI(authAPIOptions, resolvedConfig),\n environment: getEnvironmentAPI(authAPIOptions, resolvedConfig),\n user: getUserAPI(authAPIOptions, resolvedConfig),\n oAuth: getOAuthAPI(authAPIOptions, resolvedConfig),\n dictionary: getDictionaryAPI(authAPIOptions, resolvedConfig),\n stripe: getStripeAPI(authAPIOptions, resolvedConfig),\n ai: getAiAPI(authAPIOptions, resolvedConfig),\n audit: getAuditAPI(authAPIOptions, resolvedConfig),\n tag: getTagAPI(authAPIOptions, resolvedConfig),\n search: getSearchAPI(authAPIOptions, resolvedConfig),\n editor: getEditorAPI(authAPIOptions, resolvedConfig),\n newsletter: getNewsletterAPI(authAPIOptions, resolvedConfig),\n github: getGithubAPI(authAPIOptions, resolvedConfig),\n gitlab: getGitlabAPI(authAPIOptions, resolvedConfig),\n bitbucket: getBitbucketAPI(authAPIOptions, resolvedConfig),\n showcaseProject: getShowcaseProjectAPI(authAPIOptions, resolvedConfig),\n translate: getTranslateAPI(authAPIOptions, resolvedConfig),\n reviewer: getReviewerAPI(authAPIOptions, resolvedConfig),\n };\n};\n\nexport type IntlayerAPI = ReturnType<typeof getIntlayerAPI>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,kBACX,iBAAiC,EAAE,EACnC,mBACsB;CACtB,MAAM,iBAAiB,KAAK,kBAAkB,EAAE,EAAE,EAChD,QACD,CAAC;AAEF,QAAO;EACL,OAAO,YAAY,gBAAgB,eAAe;EAClD,cAAc,mBAAmB,gBAAgB,eAAe;EAChE,SAAS,cAAc,gBAAgB,eAAe;EACtD,aAAa,kBAAkB,gBAAgB,eAAe;EAC9D,MAAM,WAAW,gBAAgB,eAAe;EAChD,OAAO,YAAY,gBAAgB,eAAe;EAClD,YAAY,iBAAiB,gBAAgB,eAAe;EAC5D,QAAQ,aAAa,gBAAgB,eAAe;EACpD,IAAI,SAAS,gBAAgB,eAAe;EAC5C,OAAO,YAAY,gBAAgB,eAAe;EAClD,KAAK,UAAU,gBAAgB,eAAe;EAC9C,QAAQ,aAAa,gBAAgB,eAAe;EACpD,QAAQ,aAAa,gBAAgB,eAAe;EACpD,YAAY,iBAAiB,gBAAgB,eAAe;EAC5D,QAAQ,aAAa,gBAAgB,eAAe;EACpD,QAAQ,aAAa,gBAAgB,eAAe;EACpD,WAAW,gBAAgB,gBAAgB,eAAe;EAC1D,iBAAiB,sBAAsB,gBAAgB,eAAe;EACtE,WAAW,gBAAgB,gBAAgB,eAAe;EAC1D,UAAU,eAAe,gBAAgB,eAAe;EACzD"}
|
|
@@ -13,6 +13,15 @@ const getProjectAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
13
13
|
params: filters
|
|
14
14
|
});
|
|
15
15
|
/**
|
|
16
|
+
* Retrieves aggregated localization insights for the currently selected
|
|
17
|
+
* project (locale/key counts, per-locale completion, missing translations,
|
|
18
|
+
* recent activity, team/config status).
|
|
19
|
+
*/
|
|
20
|
+
const getProjectInsights = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/insights`, authAPIOptions, otherOptions, {
|
|
21
|
+
cache: "no-store",
|
|
22
|
+
method: "GET"
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
16
25
|
* Adds a new project to the database.
|
|
17
26
|
* @param project - Project data.
|
|
18
27
|
*/
|
|
@@ -132,6 +141,7 @@ const getProjectAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
132
141
|
});
|
|
133
142
|
return {
|
|
134
143
|
getProjects,
|
|
144
|
+
getProjectInsights,
|
|
135
145
|
addProject,
|
|
136
146
|
updateProject,
|
|
137
147
|
updateProjectMembers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.mjs","names":[],"sources":["../../../src/getIntlayerAPI/project.ts"],"sourcesContent":["import type {\n AddNewAccessKeyBody,\n AddNewAccessKeyResponse,\n AddProjectBody,\n AddProjectResult,\n DeleteAccessKeyBody,\n DeleteAccessKeyResponse,\n DeleteProjectResult,\n GetProjectsParams,\n GetProjectsResult,\n PushProjectConfigurationBody,\n PushProjectConfigurationResult,\n RefreshAccessKeyBody,\n RefreshAccessKeyResponse,\n ResponseData,\n SelectProjectParam,\n SelectProjectResult,\n TriggerBuildResult,\n TriggerWebhookBody,\n TriggerWebhookResult,\n UnselectProjectResult,\n UpdateMemberAccessBody,\n UpdateMemberAccessResult,\n UpdateProjectBody,\n UpdateProjectMembersBody,\n UpdateProjectMembersResult,\n UpdateProjectResult,\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 getProjectAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const PROJECT_API_ROUTE = `${backendURL}/api/project`;\n\n /**\n * Retrieves a list of projects based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getProjects = async (\n filters?: GetProjectsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetProjectsResult>(\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 * Adds a new project to the database.\n * @param project - Project data.\n */\n const addProject = async (\n project: AddProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: project,\n }\n );\n\n /**\n * Updates an existing project in the database.\n * @param project - Updated project data.\n */\n const updateProject = async (\n project: UpdateProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: project,\n }\n );\n\n /**\n * Updates project members in the database.\n * @param project - Updated project data.\n */\n const updateProjectMembers = async (\n body: UpdateProjectMembersBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectMembersResult>(\n `${PROJECT_API_ROUTE}/members`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body,\n }\n );\n\n /** Pushes a project configuration to the database.\n * @param projectConfiguration - Project configuration data.\n */\n const pushProjectConfiguration = async (\n projectConfiguration: PushProjectConfigurationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushProjectConfigurationResult>(\n `${PROJECT_API_ROUTE}/configuration`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: projectConfiguration,\n }\n );\n\n /**\n * Deletes a project from the database by its ID.\n * @param id - Project ID.\n */\n const deleteProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n /**\n * Admin-only: Deletes any project from the database by its ID.\n * @param projectId - Project ID.\n */\n const deleteProjectByIdAdmin = async (\n projectId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}/${projectId}/admin`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n /**\n * Select a project from the database by its ID.\n * @param projectId - Organization ID.\n */\n const selectProject = async (\n projectId: SelectProjectParam['projectId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<SelectProjectResult>(\n `${PROJECT_API_ROUTE}/${String(projectId)}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n }\n );\n\n /**\n * Unselect a project from the database by its ID.\n * @param projectId - Project ID.\n */\n const unselectProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<UnselectProjectResult>(\n `${PROJECT_API_ROUTE}/logout`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Add a new access key to a project.\n * @param accessKey - Access key data.\n * @param otherOptions - Fetcher options.\n * @returns The new access key.\n */\n const addNewAccessKey = async (\n accessKey: AddNewAccessKeyBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddNewAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: accessKey,\n }\n );\n\n /**\n * Delete a project access key.\n * @param clientId - Access key client ID.\n * @param otherOptions - Fetcher options.\n * @returns The deleted project.\n */\n const deleteAccessKey = async (\n clientId: DeleteAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n body: { clientId },\n }\n );\n\n /**\n * Refreshes an access key from a project.\n * @param clientId - The ID of the client to refresh.\n * @param projectId - The ID of the project to refresh the access key from.\n * @returns The new access key.\n */\n const refreshAccessKey = async (\n clientId: RefreshAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<RefreshAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { clientId },\n }\n );\n\n /**\n * Triggers CI builds for a project (Git provider pipelines and webhooks).\n * @param otherOptions - Fetcher options.\n * @returns The trigger results.\n */\n const triggerBuild = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<TriggerBuildResult>(\n `${PROJECT_API_ROUTE}/build`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Triggers a single webhook by index.\n * @param webhookIndex - The index of the webhook to trigger.\n * @param otherOptions - Fetcher options.\n * @returns The trigger result.\n */\n const triggerWebhook = async (\n webhookIndex: TriggerWebhookBody['webhookIndex'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TriggerWebhookResult>(\n `${PROJECT_API_ROUTE}/webhook`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { webhookIndex },\n }\n );\n\n /**\n * Get CI configuration status for the current project.\n * @param otherOptions - Fetcher options.\n * @returns The CI configuration status.\n */\n const getCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n /**\n * Push CI configuration file to the repository.\n * @param otherOptions - Fetcher options.\n * @returns Success status.\n */\n const pushCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Updates granular access constraints for a project member.\n * @param userId - The user ID to update access for.\n * @param body - The new access constraints.\n */\n const updateMemberAccess = async (\n userId: string,\n body: UpdateMemberAccessBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateMemberAccessResult>(\n `${PROJECT_API_ROUTE}/member/${userId}/access`,\n authAPIOptions,\n otherOptions,\n { method: 'PUT', body }\n );\n\n return {\n getProjects,\n addProject,\n updateProject,\n updateProjectMembers,\n pushProjectConfiguration,\n deleteProject,\n deleteProjectByIdAdmin,\n selectProject,\n unselectProject,\n addNewAccessKey,\n deleteAccessKey,\n refreshAccessKey,\n triggerBuild,\n triggerWebhook,\n getCIConfig,\n pushCIConfig,\n updateMemberAccess,\n };\n};\n"],"mappings":";;;;AAgCA,MAAa,iBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,oBAAoB,GAFP,gBAAgB,QAAQ,cAAc,OAAO,WAExB;;;;;CAMxC,MAAM,cAAc,OAClB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;EACT,CACF;;;;;CAMH,MAAM,aAAa,OACjB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,gBAAgB,OACpB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,uBAAuB,OAC3B,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,WACrB,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;;;;CAKH,MAAM,2BAA2B,OAC/B,sBACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,iBACrB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,gBAAgB,OAAO,eAA+B,EAAE,KAC5D,MAAM,QACJ,GAAG,qBACH,gBACA,cACA,EACE,QAAQ,UACT,CACF;;;;;CAMH,MAAM,yBAAyB,OAC7B,WACA,eAA+B,EAAE,KAEjC,QACE,GAAG,kBAAkB,GAAG,UAAU,SAClC,gBACA,cACA,EAAE,QAAQ,UAAU,CACrB;;;;;CAMH,MAAM,gBAAgB,OACpB,WACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,GAAG,OAAO,UAAU,IACzC,gBACA,cACA,EACE,QAAQ,OACT,CACF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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"project.mjs","names":[],"sources":["../../../src/getIntlayerAPI/project.ts"],"sourcesContent":["import type {\n AddNewAccessKeyBody,\n AddNewAccessKeyResponse,\n AddProjectBody,\n AddProjectResult,\n DeleteAccessKeyBody,\n DeleteAccessKeyResponse,\n DeleteProjectResult,\n GetProjectInsightsResult,\n GetProjectsParams,\n GetProjectsResult,\n PushProjectConfigurationBody,\n PushProjectConfigurationResult,\n RefreshAccessKeyBody,\n RefreshAccessKeyResponse,\n ResponseData,\n SelectProjectParam,\n SelectProjectResult,\n TriggerBuildResult,\n TriggerWebhookBody,\n TriggerWebhookResult,\n UnselectProjectResult,\n UpdateMemberAccessBody,\n UpdateMemberAccessResult,\n UpdateProjectBody,\n UpdateProjectMembersBody,\n UpdateProjectMembersResult,\n UpdateProjectResult,\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 getProjectAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const PROJECT_API_ROUTE = `${backendURL}/api/project`;\n\n /**\n * Retrieves a list of projects based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getProjects = async (\n filters?: GetProjectsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetProjectsResult>(\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 aggregated localization insights for the currently selected\n * project (locale/key counts, per-locale completion, missing translations,\n * recent activity, team/config status).\n */\n const getProjectInsights = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetProjectInsightsResult>(\n `${PROJECT_API_ROUTE}/insights`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n method: 'GET',\n }\n );\n\n /**\n * Adds a new project to the database.\n * @param project - Project data.\n */\n const addProject = async (\n project: AddProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: project,\n }\n );\n\n /**\n * Updates an existing project in the database.\n * @param project - Updated project data.\n */\n const updateProject = async (\n project: UpdateProjectBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: project,\n }\n );\n\n /**\n * Updates project members in the database.\n * @param project - Updated project data.\n */\n const updateProjectMembers = async (\n body: UpdateProjectMembersBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateProjectMembersResult>(\n `${PROJECT_API_ROUTE}/members`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body,\n }\n );\n\n /** Pushes a project configuration to the database.\n * @param projectConfiguration - Project configuration data.\n */\n const pushProjectConfiguration = async (\n projectConfiguration: PushProjectConfigurationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushProjectConfigurationResult>(\n `${PROJECT_API_ROUTE}/configuration`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: projectConfiguration,\n }\n );\n\n /**\n * Deletes a project from the database by its ID.\n * @param id - Project ID.\n */\n const deleteProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n /**\n * Admin-only: Deletes any project from the database by its ID.\n * @param projectId - Project ID.\n */\n const deleteProjectByIdAdmin = async (\n projectId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<DeleteProjectResult>(\n `${PROJECT_API_ROUTE}/${projectId}/admin`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n /**\n * Select a project from the database by its ID.\n * @param projectId - Organization ID.\n */\n const selectProject = async (\n projectId: SelectProjectParam['projectId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<SelectProjectResult>(\n `${PROJECT_API_ROUTE}/${String(projectId)}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n }\n );\n\n /**\n * Unselect a project from the database by its ID.\n * @param projectId - Project ID.\n */\n const unselectProject = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<UnselectProjectResult>(\n `${PROJECT_API_ROUTE}/logout`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Add a new access key to a project.\n * @param accessKey - Access key data.\n * @param otherOptions - Fetcher options.\n * @returns The new access key.\n */\n const addNewAccessKey = async (\n accessKey: AddNewAccessKeyBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddNewAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: accessKey,\n }\n );\n\n /**\n * Delete a project access key.\n * @param clientId - Access key client ID.\n * @param otherOptions - Fetcher options.\n * @returns The deleted project.\n */\n const deleteAccessKey = async (\n clientId: DeleteAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n body: { clientId },\n }\n );\n\n /**\n * Refreshes an access key from a project.\n * @param clientId - The ID of the client to refresh.\n * @param projectId - The ID of the project to refresh the access key from.\n * @returns The new access key.\n */\n const refreshAccessKey = async (\n clientId: RefreshAccessKeyBody['clientId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<RefreshAccessKeyResponse>(\n `${PROJECT_API_ROUTE}/access_key`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { clientId },\n }\n );\n\n /**\n * Triggers CI builds for a project (Git provider pipelines and webhooks).\n * @param otherOptions - Fetcher options.\n * @returns The trigger results.\n */\n const triggerBuild = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<TriggerBuildResult>(\n `${PROJECT_API_ROUTE}/build`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Triggers a single webhook by index.\n * @param webhookIndex - The index of the webhook to trigger.\n * @param otherOptions - Fetcher options.\n * @returns The trigger result.\n */\n const triggerWebhook = async (\n webhookIndex: TriggerWebhookBody['webhookIndex'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TriggerWebhookResult>(\n `${PROJECT_API_ROUTE}/webhook`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { webhookIndex },\n }\n );\n\n /**\n * Get CI configuration status for the current project.\n * @param otherOptions - Fetcher options.\n * @returns The CI configuration status.\n */\n const getCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n /**\n * Push CI configuration file to the repository.\n * @param otherOptions - Fetcher options.\n * @returns Success status.\n */\n const pushCIConfig = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<ResponseData<any>>(\n `${PROJECT_API_ROUTE}/ci`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Updates granular access constraints for a project member.\n * @param userId - The user ID to update access for.\n * @param body - The new access constraints.\n */\n const updateMemberAccess = async (\n userId: string,\n body: UpdateMemberAccessBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateMemberAccessResult>(\n `${PROJECT_API_ROUTE}/member/${userId}/access`,\n authAPIOptions,\n otherOptions,\n { method: 'PUT', body }\n );\n\n return {\n getProjects,\n getProjectInsights,\n addProject,\n updateProject,\n updateProjectMembers,\n pushProjectConfiguration,\n deleteProject,\n deleteProjectByIdAdmin,\n selectProject,\n unselectProject,\n addNewAccessKey,\n deleteAccessKey,\n refreshAccessKey,\n triggerBuild,\n triggerWebhook,\n getCIConfig,\n pushCIConfig,\n updateMemberAccess,\n };\n};\n"],"mappings":";;;;AAiCA,MAAa,iBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,oBAAoB,GAFP,gBAAgB,QAAQ,cAAc,OAAO,WAExB;;;;;CAMxC,MAAM,cAAc,OAClB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;EACT,CACF;;;;;;CAOH,MAAM,qBAAqB,OAAO,eAA+B,EAAE,KACjE,MAAM,QACJ,GAAG,kBAAkB,YACrB,gBACA,cACA;EACE,OAAO;EACP,QAAQ;EACT,CACF;;;;;CAMH,MAAM,aAAa,OACjB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,gBAAgB,OACpB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,uBAAuB,OAC3B,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,WACrB,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;;;;CAKH,MAAM,2BAA2B,OAC/B,sBACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,iBACrB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,gBAAgB,OAAO,eAA+B,EAAE,KAC5D,MAAM,QACJ,GAAG,qBACH,gBACA,cACA,EACE,QAAQ,UACT,CACF;;;;;CAMH,MAAM,yBAAyB,OAC7B,WACA,eAA+B,EAAE,KAEjC,QACE,GAAG,kBAAkB,GAAG,UAA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CAOH,MAAM,qBAAqB,OACzB,QACA,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,UAAU,OAAO,UACtC,gBACA,cACA;EAAE,QAAQ;EAAO;EAAM,CACxB;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fetcher, fetcherOptions } from "./fetcher.mjs";
|
|
2
2
|
import { getAiAPI } from "./getIntlayerAPI/ai.mjs";
|
|
3
|
+
import { getAssetAPI } from "./getIntlayerAPI/asset.mjs";
|
|
3
4
|
import { getAuditAPI } from "./getIntlayerAPI/audit.mjs";
|
|
4
5
|
import { getBitbucketAPI } from "./getIntlayerAPI/bitbucket.mjs";
|
|
5
6
|
import { getDictionaryAPI } from "./getIntlayerAPI/dictionary.mjs";
|
|
@@ -23,4 +24,4 @@ import { getIntlayerAPIProxy } from "./proxy.mjs";
|
|
|
23
24
|
import { fetchDistantDictionaries } from "./distantDictionary/fetchDistantDictionaries.mjs";
|
|
24
25
|
import { fetchDistantDictionary } from "./distantDictionary/fetchDistantDictionary.mjs";
|
|
25
26
|
|
|
26
|
-
export { fetchDistantDictionaries, fetchDistantDictionary, fetcher, fetcherOptions, getAiAPI, getAuditAPI, getBitbucketAPI, getDictionaryAPI, getEditorAPI, getEnvironmentAPI, getGithubAPI, getGitlabAPI, getIntlayerAPI, getIntlayerAPIProxy, getNewsletterAPI, getOAuthAPI, getOrganizationAPI, getProjectAPI, getReviewerAPI, getSearchAPI, getShowcaseProjectAPI, getStripeAPI, getTagAPI, getTranslateAPI, getUserAPI };
|
|
27
|
+
export { fetchDistantDictionaries, fetchDistantDictionary, fetcher, fetcherOptions, getAiAPI, getAssetAPI, getAuditAPI, getBitbucketAPI, getDictionaryAPI, getEditorAPI, getEnvironmentAPI, getGithubAPI, getGitlabAPI, getIntlayerAPI, getIntlayerAPIProxy, getNewsletterAPI, getOAuthAPI, getOrganizationAPI, getProjectAPI, getReviewerAPI, getSearchAPI, getShowcaseProjectAPI, getStripeAPI, getTagAPI, getTranslateAPI, getUserAPI };
|
|
@@ -40,6 +40,7 @@ declare const getAiAPI: (authAPIOptions?: FetcherOptions, intlayerConfig?: Intla
|
|
|
40
40
|
chat: (body?: ChatBody, otherOptions?: FetcherOptions) => Promise<void>;
|
|
41
41
|
autocomplete: (body?: AutocompleteBody, otherOptions?: FetcherOptions) => Promise<AutocompleteResponse>;
|
|
42
42
|
getDiscussions: (params?: GetDiscussionsParams, otherOptions?: FetcherOptions) => Promise<GetDiscussionsResult>;
|
|
43
|
+
getAIStats: (otherOptions?: FetcherOptions) => Promise<GetAIStatsResult>;
|
|
43
44
|
};
|
|
44
45
|
//#endregion
|
|
45
46
|
export { AskDocQuestionBody, type AskDocQuestionResult, AutocompleteBody, ChatBody, type ChatResult, ClientAction, getAiAPI };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.d.ts","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"ai.d.ts","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"mappings":";;;;;KA0BY,gBAAA;EACV,IAAA;EACA,SAAA,GAAY,SAAA;EACZ,aAAA;EACA,WAAA;EACA,YAAA;AAAA;AAAA,KAGU,kBAAA;EACV,QAAA,EAAU,4BAAA;EACV,YAAA;EACA,SAAA,IAAa,KAAA;EACb,MAAA,IAAU,QAAA,EAAU,oBAAA;AAAA;AAAA,KAGV,YAAA;EACN,IAAA;EAAkB,IAAA;AAAA;EAClB,IAAA;AAAA;AAAA,KAEM,QAAA;EACV,QAAA,EAAU,4BAAA;EACV,YAAA;EACA,SAAA,IAAa,KAAA;EACb,MAAA,IAAU,QAAA,EAAU,UAAA;EACpB,QAAA,IAAY,MAAA,EAAQ,YAAA;AAAA;AAAA,cAKT,QAAA,GACX,cAAA,GAAgB,cAAA,EAChB,cAAA,GAAiB,cAAA;uBAYR,eAAA,EAAe,YAAA,GACR,cAAA,KAAc,OAAA,CAAA,iBAAA;yBAkBrB,iBAAA,EAAiB,YAAA,GACV,cAAA,KAAc,OAAA,CAAA,mBAAA;mCAkBrB,2BAAA,EAA2B,YAAA,GACpB,cAAA,KAAc,OAAA,CAAA,6BAAA;wCAkBrB,gCAAA,EAAgC,YAAA,GACzB,cAAA,KAAc,OAAA,CAAA,kCAAA;2CAkBrB,mCAAA,EAAmC,YAAA,GAC5B,cAAA,KAAc,OAAA,CAAA,qCAAA;oBAkBrB,YAAA,EAAY,YAAA,GACL,cAAA,KAAc,OAAA,CAAA,cAAA;0BAgCrB,kBAAA,EAAkB,YAAA,GACX,cAAA,KAAc,OAAA;gBAuFH,QAAA,EAAQ,YAAA,GAAgB,cAAA,KAAc,OAAA;wBAsFxD,gBAAA,EAAgB,YAAA,GACT,cAAA,KAAc,OAAA,CAAA,oBAAA;4BAgBnB,oBAAA,EAAoB,YAAA,GACf,cAAA,KAAc,OAAA,CAAA,oBAAA;8BAiBU,cAAA,KAAc,OAAA,CAAA,gBAAA;AAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FetcherOptions } from "../fetcher.js";
|
|
2
|
+
import { IntlayerConfig } from "@intlayer/types/config";
|
|
3
|
+
|
|
4
|
+
//#region src/getIntlayerAPI/asset.d.ts
|
|
5
|
+
declare const getAssetAPI: (authAPIOptions?: FetcherOptions, intlayerConfig?: IntlayerConfig) => {
|
|
6
|
+
getAssets: (page?: number, pageSize?: number, otherOptions?: FetcherOptions) => Promise<GetAssetsResult>;
|
|
7
|
+
getAssetById: (assetId: string, otherOptions?: FetcherOptions) => Promise<GetAssetByIdResult>;
|
|
8
|
+
uploadAsset: (file: File, alt?: string, caption?: string, otherOptions?: FetcherOptions) => Promise<UploadAssetResult>;
|
|
9
|
+
updateAsset: (assetId: string, data: {
|
|
10
|
+
originalName?: string;
|
|
11
|
+
alt?: string;
|
|
12
|
+
caption?: string;
|
|
13
|
+
}, otherOptions?: FetcherOptions) => Promise<UpdateAssetResult>;
|
|
14
|
+
deleteAsset: (assetId: string, otherOptions?: FetcherOptions) => Promise<DeleteAssetResult>;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getAssetAPI };
|
|
18
|
+
//# sourceMappingURL=asset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.d.ts","names":[],"sources":["../../../src/getIntlayerAPI/asset.ts"],"mappings":";;;;cAWa,WAAA,GACX,cAAA,GAAgB,cAAA,EAChB,cAAA,GAAiB,cAAA;6BAaF,QAAA,WACI,YAAA,GACH,cAAA,KAAc,OAAA,CAAA,eAAA;kCAqBb,YAAA,GACD,cAAA,KAAc,OAAA,CAAA,kBAAA;sBAiBtB,IAAA,EAAI,GAAA,WACE,OAAA,WACI,YAAA,GACF,cAAA,KAAc,OAAA,CAAA,iBAAA;iCAsCb,IAAA;IACP,YAAA;IAAuB,GAAA;IAAc,OAAA;EAAA,GAAkB,YAAA,GACjD,cAAA,KAAc,OAAA,CAAA,iBAAA;iCAeb,YAAA,GACD,cAAA,KAAc,OAAA,CAAA,iBAAA;AAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FetcherOptions } from "../fetcher.js";
|
|
2
2
|
import { getAiAPI } from "./ai.js";
|
|
3
|
+
import { getAssetAPI } from "./asset.js";
|
|
3
4
|
import { getAuditAPI } from "./audit.js";
|
|
4
5
|
import { getBitbucketAPI } from "./bitbucket.js";
|
|
5
6
|
import { getDictionaryAPI } from "./dictionary.js";
|
|
@@ -22,6 +23,7 @@ import { IntlayerConfig } from "@intlayer/types/config";
|
|
|
22
23
|
|
|
23
24
|
//#region src/getIntlayerAPI/index.d.ts
|
|
24
25
|
interface IntlayerAPIReturn {
|
|
26
|
+
asset: ReturnType<typeof getAssetAPI>;
|
|
25
27
|
organization: ReturnType<typeof getOrganizationAPI>;
|
|
26
28
|
project: ReturnType<typeof getProjectAPI>;
|
|
27
29
|
environment: ReturnType<typeof getEnvironmentAPI>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/getIntlayerAPI/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/getIntlayerAPI/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;UAyBU,iBAAA;EACR,KAAA,EAAO,UAAA,QAAkB,WAAA;EACzB,YAAA,EAAc,UAAA,QAAkB,kBAAA;EAChC,OAAA,EAAS,UAAA,QAAkB,aAAA;EAC3B,WAAA,EAAa,UAAA,QAAkB,iBAAA;EAC/B,IAAA,EAAM,UAAA,QAAkB,UAAA;EACxB,KAAA,EAAO,UAAA,QAAkB,WAAA;EACzB,UAAA,EAAY,UAAA,QAAkB,gBAAA;EAC9B,MAAA,EAAQ,UAAA,QAAkB,YAAA;EAC1B,EAAA,EAAI,UAAA,QAAkB,QAAA;EACtB,KAAA,EAAO,UAAA,QAAkB,WAAA;EACzB,GAAA,EAAK,UAAA,QAAkB,SAAA;EACvB,MAAA,EAAQ,UAAA,QAAkB,YAAA;EAC1B,MAAA,EAAQ,UAAA,QAAkB,YAAA;EAC1B,UAAA,EAAY,UAAA,QAAkB,gBAAA;EAC9B,MAAA,EAAQ,UAAA,QAAkB,YAAA;EAC1B,MAAA,EAAQ,UAAA,QAAkB,YAAA;EAC1B,SAAA,EAAW,UAAA,QAAkB,eAAA;EAC7B,eAAA,EAAiB,UAAA,QAAkB,qBAAA;EACnC,SAAA,EAAW,UAAA,QAAkB,eAAA;EAC7B,QAAA,EAAU,UAAA,QAAkB,cAAA;AAAA;AAAA,cAGjB,cAAA,GACX,cAAA,GAAgB,cAAA,EAChB,cAAA,GAAiB,IAAA,CAAK,cAAA,gBACrB,iBAAA;AAAA,KA6BS,WAAA,GAAc,UAAA,QAAkB,cAAA"}
|
|
@@ -5,6 +5,7 @@ import { IntlayerConfig } from "@intlayer/types/config";
|
|
|
5
5
|
//#region src/getIntlayerAPI/project.d.ts
|
|
6
6
|
declare const getProjectAPI: (authAPIOptions?: FetcherOptions, intlayerConfig?: IntlayerConfig) => {
|
|
7
7
|
getProjects: (filters?: GetProjectsParams, otherOptions?: FetcherOptions) => Promise<GetProjectsResult>;
|
|
8
|
+
getProjectInsights: (otherOptions?: FetcherOptions) => Promise<GetProjectInsightsResult>;
|
|
8
9
|
addProject: (project: AddProjectBody, otherOptions?: FetcherOptions) => Promise<AddProjectResult>;
|
|
9
10
|
updateProject: (project: UpdateProjectBody, otherOptions?: FetcherOptions) => Promise<UpdateProjectResult>;
|
|
10
11
|
updateProjectMembers: (body: UpdateProjectMembersBody, otherOptions?: FetcherOptions) => Promise<UpdateProjectMembersResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","names":[],"sources":["../../../src/getIntlayerAPI/project.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"project.d.ts","names":[],"sources":["../../../src/getIntlayerAPI/project.ts"],"mappings":";;;;;cAiCa,aAAA,GACX,cAAA,GAAgB,cAAA,EAChB,cAAA,GAAiB,cAAA;0BAWL,iBAAA,EAAiB,YAAA,GACb,cAAA,KAAc,OAAA,CAAA,iBAAA;sCAkBkB,cAAA,KAAc,OAAA,CAAA,wBAAA;wBAgBnD,cAAA,EAAc,YAAA,GACT,cAAA,KAAc,OAAA,CAAA,gBAAA;2BAiBnB,iBAAA,EAAiB,YAAA,GACZ,cAAA,KAAc,OAAA,CAAA,mBAAA;+BAiBtB,wBAAA,EAAwB,YAAA,GAChB,cAAA,KAAc,OAAA,CAAA,0BAAA;mDAgBN,4BAAA,EAA4B,YAAA,GACpC,cAAA,KAAc,OAAA,CAAA,8BAAA;iCAgBa,cAAA,KAAc,OAAA,CAAA,mBAAA;8CAetC,YAAA,GACH,cAAA,KAAc,OAAA,CAAA,mBAAA;6BAcjB,kBAAA,eAA+B,YAAA,GAC5B,cAAA,KAAc,OAAA,CAAA,mBAAA;mCAee,cAAA,KAAc,OAAA,CAAA,qBAAA;+BAiB9C,mBAAA,EAAmB,YAAA,GAChB,cAAA,KAAc,OAAA,CAAA,uBAAA;8BAmBlB,mBAAA,cAA+B,YAAA,GAC3B,cAAA,KAAc,OAAA,CAAA,uBAAA;+BAmBlB,oBAAA,cAAgC,YAAA,GAC5B,cAAA,KAAc,OAAA,CAAA,wBAAA;gCAiBY,cAAA,KAAc,OAAA,CAAA,kBAAA;iCAiBxC,kBAAA,kBAAkC,YAAA,GAClC,cAAA,KAAc,OAAA,CAAA,oBAAA;+BAiBW,cAAA,KAAc,OAAA,CAAA,YAAA;gCAeb,cAAA,KAAc,OAAA,CAAA,YAAA;uCAgBxC,IAAA,EACR,sBAAA,EAAsB,YAAA,GACd,cAAA,KAAc,OAAA,CAAA,wBAAA;AAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { fetchDistantDictionaries } from "./distantDictionary/fetchDistantDictio
|
|
|
2
2
|
import { fetchDistantDictionary } from "./distantDictionary/fetchDistantDictionary.js";
|
|
3
3
|
import { FetcherOptions, fetcher, fetcherOptions } from "./fetcher.js";
|
|
4
4
|
import { AskDocQuestionBody, AskDocQuestionResult, AutocompleteBody, ChatBody, ChatResult, ClientAction, getAiAPI } from "./getIntlayerAPI/ai.js";
|
|
5
|
+
import { getAssetAPI } from "./getIntlayerAPI/asset.js";
|
|
5
6
|
import { AuditEvent, DiscoverUrlsParams, DiscoverUrlsResult, GetRecursiveAuditStatusParams, GetRecursiveAuditStatusResult, RecursiveAuditJobParams, ScanUrlBody, StartRecursiveAuditBody, StartRecursiveAuditResult, getAuditAPI } from "./getIntlayerAPI/audit.js";
|
|
6
7
|
import { BitbucketAuthCallbackBody, BitbucketAuthCallbackResult, BitbucketCheckConfigBody, BitbucketCheckConfigResult, BitbucketGetAuthUrlResult, BitbucketGetConfigFileBody, BitbucketGetConfigFileResult, BitbucketListReposResult, BitbucketRepository, getBitbucketAPI } from "./getIntlayerAPI/bitbucket.js";
|
|
7
8
|
import { getDictionaryAPI } from "./getIntlayerAPI/dictionary.js";
|
|
@@ -23,4 +24,4 @@ import { getUserAPI } from "./getIntlayerAPI/user.js";
|
|
|
23
24
|
import { IntlayerAPI, getIntlayerAPI } from "./getIntlayerAPI/index.js";
|
|
24
25
|
import { IntlayerAPIProxy, getIntlayerAPIProxy } from "./proxy.js";
|
|
25
26
|
import { AIOptions } from "./types.js";
|
|
26
|
-
export { AIOptions, AskDocQuestionBody, AskDocQuestionResult, AuditEvent, AutocompleteBody, BitbucketAuthCallbackBody, BitbucketAuthCallbackResult, BitbucketCheckConfigBody, BitbucketCheckConfigResult, BitbucketGetAuthUrlResult, BitbucketGetConfigFileBody, BitbucketGetConfigFileResult, BitbucketListReposResult, BitbucketRepository, ChatBody, ChatResult, ClientAction, DiscoverUrlsParams, DiscoverUrlsResult, FetcherOptions, GetRecursiveAuditStatusParams, GetRecursiveAuditStatusResult, GitHubAuthCallbackBody, GitHubAuthCallbackResult, GitHubCheckConfigBody, GitHubCheckConfigResult, GitHubGetAuthUrlResult, GitHubGetConfigFileBody, GitHubGetConfigFileResult, GitHubGetTokenResult, GitHubListReposResult, GitHubRepository, GitLabAuthCallbackBody, GitLabAuthCallbackResult, GitLabCheckConfigBody, GitLabCheckConfigResult, GitLabGetAuthUrlResult, GitLabGetConfigFileBody, GitLabGetConfigFileResult, GitLabListProjectsResult, GitLabProject, IntlayerAPI, IntlayerAPIProxy, OtherShowcaseProjectsQuery, RecursiveAuditJobParams, ScanUrlBody, ShowcaseProjectsQuery, StartRecursiveAuditBody, StartRecursiveAuditResult, TranslateDictionariesBody, TranslateDictionariesResult, fetchDistantDictionaries, fetchDistantDictionary, fetcher, fetcherOptions, getAiAPI, getAuditAPI, getBitbucketAPI, getDictionaryAPI, getEditorAPI, getEnvironmentAPI, getGithubAPI, getGitlabAPI, getIntlayerAPI, getIntlayerAPIProxy, getNewsletterAPI, getOAuthAPI, getOrganizationAPI, getProjectAPI, getReviewerAPI, getSearchAPI, getShowcaseProjectAPI, getStripeAPI, getTagAPI, getTranslateAPI, getUserAPI };
|
|
27
|
+
export { AIOptions, AskDocQuestionBody, AskDocQuestionResult, AuditEvent, AutocompleteBody, BitbucketAuthCallbackBody, BitbucketAuthCallbackResult, BitbucketCheckConfigBody, BitbucketCheckConfigResult, BitbucketGetAuthUrlResult, BitbucketGetConfigFileBody, BitbucketGetConfigFileResult, BitbucketListReposResult, BitbucketRepository, ChatBody, ChatResult, ClientAction, DiscoverUrlsParams, DiscoverUrlsResult, FetcherOptions, GetRecursiveAuditStatusParams, GetRecursiveAuditStatusResult, GitHubAuthCallbackBody, GitHubAuthCallbackResult, GitHubCheckConfigBody, GitHubCheckConfigResult, GitHubGetAuthUrlResult, GitHubGetConfigFileBody, GitHubGetConfigFileResult, GitHubGetTokenResult, GitHubListReposResult, GitHubRepository, GitLabAuthCallbackBody, GitLabAuthCallbackResult, GitLabCheckConfigBody, GitLabCheckConfigResult, GitLabGetAuthUrlResult, GitLabGetConfigFileBody, GitLabGetConfigFileResult, GitLabListProjectsResult, GitLabProject, IntlayerAPI, IntlayerAPIProxy, OtherShowcaseProjectsQuery, RecursiveAuditJobParams, ScanUrlBody, ShowcaseProjectsQuery, StartRecursiveAuditBody, StartRecursiveAuditResult, TranslateDictionariesBody, TranslateDictionariesResult, fetchDistantDictionaries, fetchDistantDictionary, fetcher, fetcherOptions, getAiAPI, getAssetAPI, getAuditAPI, getBitbucketAPI, getDictionaryAPI, getEditorAPI, getEnvironmentAPI, getGithubAPI, getGitlabAPI, getIntlayerAPI, getIntlayerAPIProxy, getNewsletterAPI, getOAuthAPI, getOrganizationAPI, getProjectAPI, getReviewerAPI, getSearchAPI, getShowcaseProjectAPI, getStripeAPI, getTagAPI, getTranslateAPI, getUserAPI };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-canary.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "SDK for interacting with the Intlayer API, enabling content auditing, and managing organizations, projects, and users.",
|
|
6
6
|
"keywords": [
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
"require": "./dist/cjs/getIntlayerAPI/ai.cjs",
|
|
44
44
|
"import": "./dist/esm/getIntlayerAPI/ai.mjs"
|
|
45
45
|
},
|
|
46
|
+
"./asset": {
|
|
47
|
+
"types": "./dist/types/getIntlayerAPI/asset.d.ts",
|
|
48
|
+
"require": "./dist/cjs/getIntlayerAPI/asset.cjs",
|
|
49
|
+
"import": "./dist/esm/getIntlayerAPI/asset.mjs"
|
|
50
|
+
},
|
|
46
51
|
"./audit": {
|
|
47
52
|
"types": "./dist/types/getIntlayerAPI/audit.d.ts",
|
|
48
53
|
"require": "./dist/cjs/getIntlayerAPI/audit.cjs",
|
|
@@ -149,6 +154,9 @@
|
|
|
149
154
|
"bitbucket": [
|
|
150
155
|
"./dist/types/getIntlayerAPI/bitbucket.d.ts"
|
|
151
156
|
],
|
|
157
|
+
"asset": [
|
|
158
|
+
"./dist/types/getIntlayerAPI/asset.d.ts"
|
|
159
|
+
],
|
|
152
160
|
"dictionary": [
|
|
153
161
|
"./dist/types/getIntlayerAPI/dictionary.d.ts"
|
|
154
162
|
],
|
|
@@ -224,19 +232,19 @@
|
|
|
224
232
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
225
233
|
},
|
|
226
234
|
"dependencies": {
|
|
227
|
-
"@intlayer/config": "
|
|
228
|
-
"@intlayer/types": "
|
|
235
|
+
"@intlayer/config": "9.0.0-canary.1",
|
|
236
|
+
"@intlayer/types": "9.0.0-canary.1",
|
|
229
237
|
"defu": "6.1.7"
|
|
230
238
|
},
|
|
231
239
|
"devDependencies": {
|
|
232
|
-
"@types/node": "25.9.
|
|
240
|
+
"@types/node": "25.9.3",
|
|
233
241
|
"@utils/ts-config": "1.0.4",
|
|
234
242
|
"@utils/ts-config-types": "1.0.4",
|
|
235
243
|
"@utils/tsdown-config": "1.0.4",
|
|
236
244
|
"rimraf": "6.1.3",
|
|
237
245
|
"tsdown": "0.21.10",
|
|
238
246
|
"typescript": "6.0.3",
|
|
239
|
-
"vitest": "4.1.
|
|
247
|
+
"vitest": "4.1.9"
|
|
240
248
|
},
|
|
241
249
|
"engines": {
|
|
242
250
|
"node": ">=14.18"
|