@intlayer/api 8.1.2 → 8.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +1 -20
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +1 -22
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/distantDictionary/index.cjs +1 -6
- package/dist/cjs/fetcher.cjs +1 -122
- package/dist/cjs/fetcher.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs +2 -166
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/audit.cjs +1 -41
- package/dist/cjs/getIntlayerAPI/audit.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs +1 -74
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/dictionary.cjs +1 -72
- package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/editor.cjs +1 -40
- package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/github.cjs +1 -74
- package/dist/cjs/getIntlayerAPI/github.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/gitlab.cjs +1 -88
- package/dist/cjs/getIntlayerAPI/gitlab.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/index.cjs +1 -38
- package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/newsletter.cjs +1 -43
- package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/oAuth.cjs +1 -29
- package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/organization.cjs +1 -96
- package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/project.cjs +1 -144
- package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/search.cjs +1 -25
- package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/stripe.cjs +1 -41
- package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/tag.cjs +1 -50
- package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/user.cjs +1 -82
- package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -43
- package/dist/cjs/proxy.cjs +1 -101
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +1 -19
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +1 -21
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/distantDictionary/index.mjs +1 -4
- package/dist/esm/fetcher.mjs +1 -119
- package/dist/esm/fetcher.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/ai.mjs +2 -163
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/audit.mjs +1 -38
- package/dist/esm/getIntlayerAPI/audit.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/bitbucket.mjs +1 -71
- package/dist/esm/getIntlayerAPI/bitbucket.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/dictionary.mjs +1 -69
- package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/editor.mjs +1 -37
- package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/github.mjs +1 -71
- package/dist/esm/getIntlayerAPI/github.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/gitlab.mjs +1 -85
- package/dist/esm/getIntlayerAPI/gitlab.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/index.mjs +1 -37
- package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/newsletter.mjs +1 -40
- package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/oAuth.mjs +1 -26
- package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/organization.mjs +1 -93
- package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/project.mjs +1 -141
- package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/search.mjs +1 -22
- package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/stripe.mjs +1 -38
- package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/tag.mjs +1 -47
- package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/user.mjs +1 -79
- package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -22
- package/dist/esm/proxy.mjs +1 -100
- package/dist/esm/proxy.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1,164 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/getIntlayerAPI/ai.ts
|
|
5
|
-
const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
6
|
-
const backendURL = intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;
|
|
7
|
-
if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
|
|
8
|
-
const AI_API_ROUTE = `${backendURL}/api/ai`;
|
|
9
|
-
/**
|
|
10
|
-
* Custom query
|
|
11
|
-
* @param body - Custom query parameters.
|
|
12
|
-
* @returns Custom query result.
|
|
13
|
-
*/
|
|
14
|
-
const customQuery = async (body, otherOptions = {}) => await fetcher(AI_API_ROUTE, authAPIOptions, otherOptions, {
|
|
15
|
-
method: "POST",
|
|
16
|
-
body
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* Translate a JSON
|
|
20
|
-
* @param body - Audit file parameters.
|
|
21
|
-
* @returns Audited file content.
|
|
22
|
-
*/
|
|
23
|
-
const translateJSON = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/translate/json`, authAPIOptions, otherOptions, {
|
|
24
|
-
method: "POST",
|
|
25
|
-
body
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Audits a content declaration file
|
|
29
|
-
* @param body - Audit file parameters.
|
|
30
|
-
* @returns Audited file content.
|
|
31
|
-
*/
|
|
32
|
-
const auditContentDeclaration = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/dictionary`, authAPIOptions, otherOptions, {
|
|
33
|
-
method: "POST",
|
|
34
|
-
body
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* Audits a content declaration field
|
|
38
|
-
* @param body - Audit file parameters.
|
|
39
|
-
* @returns Audited file content.
|
|
40
|
-
*/
|
|
41
|
-
const auditContentDeclarationField = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/dictionary/field`, authAPIOptions, otherOptions, {
|
|
42
|
-
method: "POST",
|
|
43
|
-
body
|
|
44
|
-
});
|
|
45
|
-
/**
|
|
46
|
-
* Audits a content declaration file to retrieve title, description and tags
|
|
47
|
-
* @param body - Audit file parameters.
|
|
48
|
-
* @returns Audited file content.
|
|
49
|
-
*/
|
|
50
|
-
const auditContentDeclarationMetadata = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/dictionary/metadata`, authAPIOptions, otherOptions, {
|
|
51
|
-
method: "POST",
|
|
52
|
-
body
|
|
53
|
-
});
|
|
54
|
-
/**
|
|
55
|
-
* Audits a tag
|
|
56
|
-
* @param body - Audit tag parameters.
|
|
57
|
-
* @returns Audited tag content.
|
|
58
|
-
*/
|
|
59
|
-
const auditTag = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/tag`, authAPIOptions, otherOptions, {
|
|
60
|
-
method: "POST",
|
|
61
|
-
body
|
|
62
|
-
});
|
|
63
|
-
/**
|
|
64
|
-
* Asks a question to the AI related to the documentation **and streams the
|
|
65
|
-
* answer as Server‑Sent Events (SSE)**.
|
|
66
|
-
*
|
|
67
|
-
* The function **returns immediately** with a handle exposing:
|
|
68
|
-
* - `promise` → resolves when the stream completes (or rejects on error)
|
|
69
|
-
* - `abort()` → allows canceling the request on demand
|
|
70
|
-
*
|
|
71
|
-
* Usage example:
|
|
72
|
-
* ```ts
|
|
73
|
-
* const { promise, abort } = ai.askDocQuestion({
|
|
74
|
-
* ...body,
|
|
75
|
-
* onMessage: console.log,
|
|
76
|
-
* onDone: (full) => console.log("✔", full),
|
|
77
|
-
* });
|
|
78
|
-
* // later → abort();
|
|
79
|
-
* await promise; // waits for completion if desired
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
const askDocQuestion = async (body, otherOptions = {}) => {
|
|
83
|
-
if (!body) return;
|
|
84
|
-
const { onMessage, onDone, ...rest } = body;
|
|
85
|
-
const abortController = new AbortController();
|
|
86
|
-
try {
|
|
87
|
-
const response = await fetch(`${AI_API_ROUTE}/ask`, {
|
|
88
|
-
method: "POST",
|
|
89
|
-
headers: {
|
|
90
|
-
"Content-Type": "application/json",
|
|
91
|
-
...authAPIOptions.headers,
|
|
92
|
-
...otherOptions.headers
|
|
93
|
-
},
|
|
94
|
-
body: JSON.stringify({
|
|
95
|
-
...rest,
|
|
96
|
-
...authAPIOptions.body,
|
|
97
|
-
...otherOptions.body
|
|
98
|
-
}),
|
|
99
|
-
signal: abortController.signal,
|
|
100
|
-
credentials: "include"
|
|
101
|
-
});
|
|
102
|
-
if (!response.ok) {
|
|
103
|
-
let errorMessage = "An error occurred";
|
|
104
|
-
try {
|
|
105
|
-
const errorData = await response.json();
|
|
106
|
-
errorMessage = JSON.stringify(errorData.error) ?? "An error occurred";
|
|
107
|
-
} catch {
|
|
108
|
-
try {
|
|
109
|
-
const errorText = await response.text();
|
|
110
|
-
if (errorText) errorMessage = errorText;
|
|
111
|
-
} catch {}
|
|
112
|
-
}
|
|
113
|
-
throw new Error(errorMessage);
|
|
114
|
-
}
|
|
115
|
-
const reader = response.body?.getReader();
|
|
116
|
-
if (!reader) throw new Error("No reader available");
|
|
117
|
-
const decoder = new TextDecoder();
|
|
118
|
-
let buffer = "";
|
|
119
|
-
while (true) {
|
|
120
|
-
const { done, value } = await reader.read();
|
|
121
|
-
if (done) break;
|
|
122
|
-
buffer += decoder.decode(value, { stream: true });
|
|
123
|
-
const lines = buffer.split("\n");
|
|
124
|
-
buffer = lines.pop() ?? "";
|
|
125
|
-
for (const line of lines) if (line.startsWith("data: ")) try {
|
|
126
|
-
const data = JSON.parse(line.slice(6));
|
|
127
|
-
if (data.chunk) onMessage?.(data.chunk);
|
|
128
|
-
if (data.done && data.response) onDone?.(data.response);
|
|
129
|
-
} catch (e) {
|
|
130
|
-
console.error("Failed to parse SSE data:", e);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error("Error in askDocQuestion:", error);
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const autocomplete = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/autocomplete`, authAPIOptions, otherOptions, {
|
|
139
|
-
method: "POST",
|
|
140
|
-
body
|
|
141
|
-
});
|
|
142
|
-
/**
|
|
143
|
-
* Retrieves discussions with filters and pagination. Only user or admin can access.
|
|
144
|
-
*/
|
|
145
|
-
const getDiscussions = async (params, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/discussions`, authAPIOptions, otherOptions, {
|
|
146
|
-
method: "GET",
|
|
147
|
-
params
|
|
148
|
-
});
|
|
149
|
-
return {
|
|
150
|
-
customQuery,
|
|
151
|
-
translateJSON,
|
|
152
|
-
auditContentDeclaration,
|
|
153
|
-
auditContentDeclarationField,
|
|
154
|
-
auditContentDeclarationMetadata,
|
|
155
|
-
auditTag,
|
|
156
|
-
askDocQuestion,
|
|
157
|
-
autocomplete,
|
|
158
|
-
getDiscussions
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
//#endregion
|
|
163
|
-
export { getAiAPI };
|
|
1
|
+
import{fetcher as e}from"../fetcher.mjs";import t from"@intlayer/config/built";const n=(n={},r)=>{let i=r?.editor?.backendURL??t?.editor?.backendURL;if(!i)throw Error(`Backend URL is not defined in the Intlayer configuration.`);let a=`${i}/api/ai`;return{customQuery:async(t,r={})=>await e(a,n,r,{method:`POST`,body:t}),translateJSON:async(t,r={})=>await e(`${a}/translate/json`,n,r,{method:`POST`,body:t}),auditContentDeclaration:async(t,r={})=>await e(`${a}/audit/dictionary`,n,r,{method:`POST`,body:t}),auditContentDeclarationField:async(t,r={})=>await e(`${a}/audit/dictionary/field`,n,r,{method:`POST`,body:t}),auditContentDeclarationMetadata:async(t,r={})=>await e(`${a}/audit/dictionary/metadata`,n,r,{method:`POST`,body:t}),auditTag:async(t,r={})=>await e(`${a}/audit/tag`,n,r,{method:`POST`,body:t}),askDocQuestion:async(e,t={})=>{if(!e)return;let{onMessage:r,onDone:i,...o}=e,s=new AbortController;try{let e=await fetch(`${a}/ask`,{method:`POST`,headers:{"Content-Type":`application/json`,...n.headers,...t.headers},body:JSON.stringify({...o,...n.body,...t.body}),signal:s.signal,credentials:`include`});if(!e.ok){let t=`An error occurred`;try{let n=await e.json();t=JSON.stringify(n.error)??`An error occurred`}catch{try{let n=await e.text();n&&(t=n)}catch{}}throw Error(t)}let c=e.body?.getReader();if(!c)throw Error(`No reader available`);let l=new TextDecoder,u=``;for(;;){let{done:e,value:t}=await c.read();if(e)break;u+=l.decode(t,{stream:!0});let n=u.split(`
|
|
2
|
+
`);u=n.pop()??``;for(let e of n)if(e.startsWith(`data: `))try{let t=JSON.parse(e.slice(6));t.chunk&&r?.(t.chunk),t.done&&t.response&&i?.(t.response)}catch(e){console.error(`Failed to parse SSE data:`,e)}}}catch(e){throw console.error(`Error in askDocQuestion:`,e),e}},autocomplete:async(t,r={})=>await e(`${a}/autocomplete`,n,r,{method:`POST`,body:t}),getDiscussions:async(t,r={})=>await e(`${a}/discussions`,n,r,{method:`GET`,params:t})}};export{n as getAiAPI};
|
|
164
3
|
//# sourceMappingURL=ai.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.mjs","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n AskDocQuestionResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AutocompleteBody,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n CustomQueryBody,\n CustomQueryResult,\n GetDiscussionsParams,\n GetDiscussionsResult,\n TranslateJSONBody,\n TranslateJSONResult,\n} from '../types';\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: AskDocQuestionResult) => void;\n};\n\nexport type { AskDocQuestionResult };\n\nexport const getAiAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\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 errorMessage = JSON.stringify(errorData.error) ?? '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 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 autocomplete,\n getDiscussions,\n };\n};\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"ai.mjs","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n AskDocQuestionResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AutocompleteBody,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n CustomQueryBody,\n CustomQueryResult,\n GetDiscussionsParams,\n GetDiscussionsResult,\n TranslateJSONBody,\n TranslateJSONResult,\n} from '../types';\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: AskDocQuestionResult) => void;\n};\n\nexport type { AskDocQuestionResult };\n\nexport const getAiAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\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 errorMessage = JSON.stringify(errorData.error) ?? '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 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 autocomplete,\n getDiscussions,\n };\n};\n"],"mappings":"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"}
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import configuration from "@intlayer/config/built";
|
|
3
|
-
|
|
4
|
-
//#region src/getIntlayerAPI/audit.ts
|
|
5
|
-
const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
6
|
-
const backendURL = intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;
|
|
7
|
-
if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
|
|
8
|
-
const AUDIT_API_ROUTE = `${backendURL}/api/audit`;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new audit in the database.
|
|
11
|
-
* @param audit - Audit data.
|
|
12
|
-
*/
|
|
13
|
-
const createAudit = async (audit, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}`, authAPIOptions, otherOptions, {
|
|
14
|
-
method: "POST",
|
|
15
|
-
body: audit
|
|
16
|
-
});
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves audits for the current user or project.
|
|
19
|
-
* @param params - Query parameters (page, pageSize).
|
|
20
|
-
*/
|
|
21
|
-
const getAudits = async (params, otherOptions = {}) => await fetcher(AUDIT_API_ROUTE, authAPIOptions, otherOptions, {
|
|
22
|
-
cache: "no-store",
|
|
23
|
-
params
|
|
24
|
-
});
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves an audit by its ID.
|
|
27
|
-
* @param auditId - Audit ID.
|
|
28
|
-
*/
|
|
29
|
-
const getAuditById = async (auditId, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}/${String(auditId)}`, authAPIOptions, otherOptions, { cache: "no-store" });
|
|
30
|
-
return {
|
|
31
|
-
createAudit,
|
|
32
|
-
getAudits,
|
|
33
|
-
getAuditById
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
export { getAuditAPI };
|
|
1
|
+
import{fetcher as e}from"../fetcher.mjs";import t from"@intlayer/config/built";const n=(n={},r)=>{let i=r?.editor?.backendURL??t?.editor?.backendURL;if(!i)throw Error(`Backend URL is not defined in the Intlayer configuration.`);let a=`${i}/api/audit`;return{createAudit:async(t,r={})=>await e(`${a}`,n,r,{method:`POST`,body:t}),getAudits:async(t,r={})=>await e(a,n,r,{cache:`no-store`,params:t}),getAuditById:async(t,r={})=>await e(`${a}/${String(t)}`,n,r,{cache:`no-store`})}};export{n as getAuditAPI};
|
|
39
2
|
//# sourceMappingURL=audit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.mjs","names":[],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n CreateAuditBody,\n CreateAuditResult,\n GetAuditByIdParams,\n GetAuditByIdResult,\n GetAuditsParams,\n GetAuditsResult,\n} from '../types';\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n const AUDIT_API_ROUTE = `${backendURL}/api/audit`;\n\n /**\n * Creates a new audit in the database.\n * @param audit - Audit data.\n */\n const createAudit = async (\n audit: CreateAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreateAuditResult>(\n `${AUDIT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: audit,\n }\n );\n\n /**\n * Retrieves audits for the current user or project.\n * @param params - Query parameters (page, pageSize).\n */\n const getAudits = async (\n params?: GetAuditsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAuditsResult>(\n AUDIT_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,\n }\n );\n\n /**\n * Retrieves an audit by its ID.\n * @param auditId - Audit ID.\n */\n const getAuditById = async (\n auditId: GetAuditByIdParams['auditId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAuditByIdResult>(\n `${AUDIT_API_ROUTE}/${String(auditId)}`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n return {\n createAudit,\n getAudits,\n getAuditById,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"audit.mjs","names":[],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n CreateAuditBody,\n CreateAuditResult,\n GetAuditByIdParams,\n GetAuditByIdResult,\n GetAuditsParams,\n GetAuditsResult,\n} from '../types';\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n const AUDIT_API_ROUTE = `${backendURL}/api/audit`;\n\n /**\n * Creates a new audit in the database.\n * @param audit - Audit data.\n */\n const createAudit = async (\n audit: CreateAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreateAuditResult>(\n `${AUDIT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: audit,\n }\n );\n\n /**\n * Retrieves audits for the current user or project.\n * @param params - Query parameters (page, pageSize).\n */\n const getAudits = async (\n params?: GetAuditsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAuditsResult>(\n AUDIT_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,\n }\n );\n\n /**\n * Retrieves an audit by its ID.\n * @param auditId - Audit ID.\n */\n const getAuditById = async (\n auditId: GetAuditByIdParams['auditId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAuditByIdResult>(\n `${AUDIT_API_ROUTE}/${String(auditId)}`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n return {\n createAudit,\n getAudits,\n getAuditById,\n };\n};\n"],"mappings":"+EAYA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CACH,IAAM,EACJ,GAAgB,QAAQ,YAAc,GAAe,QAAQ,WAE/D,GAAI,CAAC,EACH,MAAU,MACR,4DACD,CAGH,IAAM,EAAkB,GAAG,EAAW,YAwDtC,MAAO,CACL,YAnDkB,MAClB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,IACH,EACA,EACA,CACE,OAAQ,OACR,KAAM,EACP,CACF,CAwCD,UAlCgB,MAChB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,EACA,EACA,EACA,CACE,MAAO,WAEP,SACD,CACF,CAsBD,aAhBmB,MACnB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAgB,GAAG,OAAO,EAAQ,GACrC,EACA,EACA,CACE,MAAO,WACR,CACF,CAMF"}
|
|
@@ -1,72 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import configuration from "@intlayer/config/built";
|
|
3
|
-
|
|
4
|
-
//#region src/getIntlayerAPI/bitbucket.ts
|
|
5
|
-
const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
6
|
-
const backendURL = intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;
|
|
7
|
-
if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
|
|
8
|
-
const BITBUCKET_API_ROUTE = `${backendURL}/api/bitbucket`;
|
|
9
|
-
/**
|
|
10
|
-
* Get Bitbucket OAuth authorization URL
|
|
11
|
-
* @param redirectUri - Redirect URI after OAuth authorization
|
|
12
|
-
*/
|
|
13
|
-
const getAuthUrl = async (redirectUri, otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/auth-url`, authAPIOptions, otherOptions, { params: { redirectUri } });
|
|
14
|
-
/**
|
|
15
|
-
* Exchange Bitbucket authorization code for access token
|
|
16
|
-
* @param code - Bitbucket authorization code
|
|
17
|
-
*/
|
|
18
|
-
const authenticate = async (code, otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/auth`, authAPIOptions, otherOptions, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
body: { code }
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Get user's Bitbucket repositories
|
|
24
|
-
* @param token - Optional Bitbucket access token. If not provided, backend will use session.
|
|
25
|
-
*/
|
|
26
|
-
const getRepositories = async (token, otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/repos`, authAPIOptions, otherOptions, { params: token ? { token } : void 0 });
|
|
27
|
-
/**
|
|
28
|
-
* Check if intlayer.config.ts exists in a Bitbucket repository
|
|
29
|
-
* @param token - Optional Bitbucket access token. If not provided, backend will use session.
|
|
30
|
-
* @param workspace - Bitbucket workspace slug
|
|
31
|
-
* @param repoSlug - Repository slug
|
|
32
|
-
* @param branch - Branch name (default: 'main')
|
|
33
|
-
*/
|
|
34
|
-
const checkIntlayerConfig = async (token, workspace, repoSlug, branch = "main", otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/check-config`, authAPIOptions, otherOptions, {
|
|
35
|
-
method: "POST",
|
|
36
|
-
body: {
|
|
37
|
-
token: token ?? void 0,
|
|
38
|
-
workspace,
|
|
39
|
-
repoSlug,
|
|
40
|
-
branch
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
/**
|
|
44
|
-
* Get intlayer.config.ts file contents from a Bitbucket repository
|
|
45
|
-
* @param token - Optional Bitbucket access token. If not provided, backend will use session.
|
|
46
|
-
* @param workspace - Bitbucket workspace slug
|
|
47
|
-
* @param repoSlug - Repository slug
|
|
48
|
-
* @param branch - Branch name (default: 'main')
|
|
49
|
-
* @param path - File path (default: 'intlayer.config.ts')
|
|
50
|
-
*/
|
|
51
|
-
const getConfigFile = async (token, workspace, repoSlug, branch = "main", path = "intlayer.config.ts", otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/get-config-file`, authAPIOptions, otherOptions, {
|
|
52
|
-
method: "POST",
|
|
53
|
-
body: {
|
|
54
|
-
token: token ?? void 0,
|
|
55
|
-
workspace,
|
|
56
|
-
repoSlug,
|
|
57
|
-
branch,
|
|
58
|
-
path
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
getAuthUrl,
|
|
63
|
-
authenticate,
|
|
64
|
-
getRepositories,
|
|
65
|
-
checkIntlayerConfig,
|
|
66
|
-
getConfigFile
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
//#endregion
|
|
71
|
-
export { getBitbucketAPI };
|
|
1
|
+
import{fetcher as e}from"../fetcher.mjs";import t from"@intlayer/config/built";const n=(n={},r)=>{let i=r?.editor?.backendURL??t?.editor?.backendURL;if(!i)throw Error(`Backend URL is not defined in the Intlayer configuration.`);let a=`${i}/api/bitbucket`;return{getAuthUrl:async(t,r={})=>await e(`${a}/auth-url`,n,r,{params:{redirectUri:t}}),authenticate:async(t,r={})=>await e(`${a}/auth`,n,r,{method:`POST`,body:{code:t}}),getRepositories:async(t,r={})=>await e(`${a}/repos`,n,r,{params:t?{token:t}:void 0}),checkIntlayerConfig:async(t,r,i,o=`main`,s={})=>await e(`${a}/check-config`,n,s,{method:`POST`,body:{token:t??void 0,workspace:r,repoSlug:i,branch:o}}),getConfigFile:async(t,r,i,o=`main`,s=`intlayer.config.ts`,c={})=>await e(`${a}/get-config-file`,n,c,{method:`POST`,body:{token:t??void 0,workspace:r,repoSlug:i,branch:o,path:s}})}};export{n as getBitbucketAPI};
|
|
72
2
|
//# sourceMappingURL=bitbucket.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitbucket.mjs","names":[],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n const BITBUCKET_API_ROUTE = `${backendURL}/api/bitbucket`;\n\n /**\n * Get Bitbucket OAuth authorization URL\n * @param redirectUri - Redirect URI after OAuth authorization\n */\n const getAuthUrl = async (\n redirectUri: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetAuthUrlResult>(\n `${BITBUCKET_API_ROUTE}/auth-url`,\n authAPIOptions,\n otherOptions,\n {\n params: { redirectUri },\n }\n );\n\n /**\n * Exchange Bitbucket authorization code for access token\n * @param code - Bitbucket authorization code\n */\n const authenticate = async (\n code: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketAuthCallbackResult>(\n `${BITBUCKET_API_ROUTE}/auth`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { code },\n }\n );\n\n /**\n * Get user's Bitbucket repositories\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n */\n const getRepositories = async (\n token?: string | null,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketListReposResult>(\n `${BITBUCKET_API_ROUTE}/repos`,\n authAPIOptions,\n otherOptions,\n {\n params: token ? { token } : undefined,\n }\n );\n\n /**\n * Check if intlayer.config.ts exists in a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n */\n const checkIntlayerConfig = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketCheckConfigResult>(\n `${BITBUCKET_API_ROUTE}/check-config`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { token: token ?? undefined, workspace, repoSlug, branch },\n }\n );\n\n /**\n * Get intlayer.config.ts file contents from a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n * @param path - File path (default: 'intlayer.config.ts')\n */\n const getConfigFile = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n path: string = 'intlayer.config.ts',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetConfigFileResult>(\n `${BITBUCKET_API_ROUTE}/get-config-file`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: {\n token: token ?? undefined,\n workspace,\n repoSlug,\n branch,\n path,\n },\n }\n );\n\n return {\n getAuthUrl,\n authenticate,\n getRepositories,\n checkIntlayerConfig,\n getConfigFile,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bitbucket.mjs","names":[],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n const BITBUCKET_API_ROUTE = `${backendURL}/api/bitbucket`;\n\n /**\n * Get Bitbucket OAuth authorization URL\n * @param redirectUri - Redirect URI after OAuth authorization\n */\n const getAuthUrl = async (\n redirectUri: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetAuthUrlResult>(\n `${BITBUCKET_API_ROUTE}/auth-url`,\n authAPIOptions,\n otherOptions,\n {\n params: { redirectUri },\n }\n );\n\n /**\n * Exchange Bitbucket authorization code for access token\n * @param code - Bitbucket authorization code\n */\n const authenticate = async (\n code: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketAuthCallbackResult>(\n `${BITBUCKET_API_ROUTE}/auth`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { code },\n }\n );\n\n /**\n * Get user's Bitbucket repositories\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n */\n const getRepositories = async (\n token?: string | null,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketListReposResult>(\n `${BITBUCKET_API_ROUTE}/repos`,\n authAPIOptions,\n otherOptions,\n {\n params: token ? { token } : undefined,\n }\n );\n\n /**\n * Check if intlayer.config.ts exists in a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n */\n const checkIntlayerConfig = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketCheckConfigResult>(\n `${BITBUCKET_API_ROUTE}/check-config`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { token: token ?? undefined, workspace, repoSlug, branch },\n }\n );\n\n /**\n * Get intlayer.config.ts file contents from a Bitbucket repository\n * @param token - Optional Bitbucket access token. If not provided, backend will use session.\n * @param workspace - Bitbucket workspace slug\n * @param repoSlug - Repository slug\n * @param branch - Branch name (default: 'main')\n * @param path - File path (default: 'intlayer.config.ts')\n */\n const getConfigFile = async (\n token: string | null | undefined,\n workspace: string,\n repoSlug: string,\n branch: string = 'main',\n path: string = 'intlayer.config.ts',\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<BitbucketGetConfigFileResult>(\n `${BITBUCKET_API_ROUTE}/get-config-file`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: {\n token: token ?? undefined,\n workspace,\n repoSlug,\n branch,\n path,\n },\n }\n );\n\n return {\n getAuthUrl,\n authenticate,\n getRepositories,\n checkIntlayerConfig,\n getConfigFile,\n };\n};\n"],"mappings":"+EAgFA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CACH,IAAM,EACJ,GAAgB,QAAQ,YAAc,GAAe,QAAQ,WAE/D,GAAI,CAAC,EACH,MAAU,MACR,4DACD,CAGH,IAAM,EAAsB,GAAG,EAAW,gBA8G1C,MAAO,CACL,WAzGiB,MACjB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAoB,WACvB,EACA,EACA,CACE,OAAQ,CAAE,cAAa,CACxB,CACF,CA+FD,aAzFmB,MACnB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAoB,OACvB,EACA,EACA,CACE,OAAQ,OACR,KAAM,CAAE,OAAM,CACf,CACF,CA8ED,gBAxEsB,MACtB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAoB,QACvB,EACA,EACA,CACE,OAAQ,EAAQ,CAAE,QAAO,CAAG,IAAA,GAC7B,CACF,CA8DD,oBArD0B,MAC1B,EACA,EACA,EACA,EAAiB,OACjB,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAoB,eACvB,EACA,EACA,CACE,OAAQ,OACR,KAAM,CAAE,MAAO,GAAS,IAAA,GAAW,YAAW,WAAU,SAAQ,CACjE,CACF,CAuCD,cA7BoB,MACpB,EACA,EACA,EACA,EAAiB,OACjB,EAAe,qBACf,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAoB,kBACvB,EACA,EACA,CACE,OAAQ,OACR,KAAM,CACJ,MAAO,GAAS,IAAA,GAChB,YACA,WACA,SACA,OACD,CACF,CACF,CAQF"}
|
|
@@ -1,70 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import configuration from "@intlayer/config/built";
|
|
3
|
-
|
|
4
|
-
//#region src/getIntlayerAPI/dictionary.ts
|
|
5
|
-
const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
6
|
-
const backendURL = intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;
|
|
7
|
-
if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
|
|
8
|
-
const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;
|
|
9
|
-
/**
|
|
10
|
-
* Retrieves a list of dictionaries based on filters and pagination.
|
|
11
|
-
* @param filters - Filters and pagination options.
|
|
12
|
-
*/
|
|
13
|
-
const getDictionaries = async (filters, otherOptions = {}) => await fetcher(PROJECT_API_ROUTE, authAPIOptions, otherOptions, {
|
|
14
|
-
cache: "no-store",
|
|
15
|
-
params: filters
|
|
16
|
-
});
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves a list of dictionary keys related to the project.
|
|
19
|
-
*/
|
|
20
|
-
const getDictionariesKeys = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/keys`, authAPIOptions, otherOptions, { cache: "no-store" });
|
|
21
|
-
/**
|
|
22
|
-
* Retrieves a list of dictionary keys related to the project.
|
|
23
|
-
*/
|
|
24
|
-
const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/update`, authAPIOptions, otherOptions, { cache: "no-store" });
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves a dictionary by its key and version.
|
|
27
|
-
* @param dictionaryKey - Dictionary key.
|
|
28
|
-
* @param version - Dictionary version of content.
|
|
29
|
-
*/
|
|
30
|
-
const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${dictionaryKey}`, authAPIOptions, otherOptions, { params: version ? { version: version.toString() } : void 0 });
|
|
31
|
-
/**
|
|
32
|
-
* Adds a new dictionary to the database.
|
|
33
|
-
* @param dictionary - Dictionary data.
|
|
34
|
-
*/
|
|
35
|
-
const addDictionary = async (body, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
|
|
36
|
-
method: "POST",
|
|
37
|
-
body
|
|
38
|
-
});
|
|
39
|
-
const pushDictionaries = async (dictionaries, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
|
|
40
|
-
method: "PATCH",
|
|
41
|
-
body: { dictionaries }
|
|
42
|
-
});
|
|
43
|
-
/**
|
|
44
|
-
* Updates an existing dictionary in the database.
|
|
45
|
-
* @param dictionary - Updated dictionary data.
|
|
46
|
-
*/
|
|
47
|
-
const updateDictionary = async (dictionary, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${dictionary.id}`, authAPIOptions, otherOptions, {
|
|
48
|
-
method: "PUT",
|
|
49
|
-
body: dictionary
|
|
50
|
-
});
|
|
51
|
-
/**
|
|
52
|
-
* Deletes a dictionary from the database by its ID.
|
|
53
|
-
* @param id - Dictionary ID.
|
|
54
|
-
*/
|
|
55
|
-
const deleteDictionary = async (id, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${id}`, authAPIOptions, otherOptions, { method: "DELETE" });
|
|
56
|
-
return {
|
|
57
|
-
getDictionaries,
|
|
58
|
-
getDictionariesKeys,
|
|
59
|
-
getDictionariesUpdateTimestamp,
|
|
60
|
-
getDictionary,
|
|
61
|
-
pushDictionaries,
|
|
62
|
-
addDictionary,
|
|
63
|
-
updateDictionary,
|
|
64
|
-
deleteDictionary
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
export { getDictionaryAPI };
|
|
1
|
+
import{fetcher as e}from"../fetcher.mjs";import t from"@intlayer/config/built";const n=(n={},r)=>{let i=r?.editor?.backendURL??t?.editor?.backendURL;if(!i)throw Error(`Backend URL is not defined in the Intlayer configuration.`);let a=`${i}/api/dictionary`;return{getDictionaries:async(t,r={})=>await e(a,n,r,{cache:`no-store`,params:t}),getDictionariesKeys:async(t={})=>await e(`${a}/keys`,n,t,{cache:`no-store`}),getDictionariesUpdateTimestamp:async(t={})=>await e(`${a}/update`,n,t,{cache:`no-store`}),getDictionary:async(t,r,i={})=>await e(`${a}/${t}`,n,i,{params:r?{version:r.toString()}:void 0}),pushDictionaries:async(t,r={})=>await e(`${a}`,n,r,{method:`PATCH`,body:{dictionaries:t}}),addDictionary:async(t,r={})=>await e(`${a}`,n,r,{method:`POST`,body:t}),updateDictionary:async(t,r={})=>await e(`${a}/${t.id}`,n,r,{method:`PUT`,body:t}),deleteDictionary:async(t,r={})=>await e(`${a}/${t}`,n,r,{method:`DELETE`})}};export{n as getDictionaryAPI};
|
|
70
2
|
//# sourceMappingURL=dictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n} from '../types';\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;\n\n /**\n * Retrieves a list of dictionaries based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getDictionaries = async (\n filters?: GetDictionariesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesResult>(\n PROJECT_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params: filters,\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesKeys = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetDictionariesKeysResult>(\n `${PROJECT_API_ROUTE}/keys`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesUpdateTimestamp = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesUpdateTimestampResult>(\n `${PROJECT_API_ROUTE}/update`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a dictionary by its key and version.\n * @param dictionaryKey - Dictionary key.\n * @param version - Dictionary version of content.\n */\n const getDictionary = async (\n dictionaryKey: GetDictionaryParams['dictionaryKey'],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionaryKey}`,\n authAPIOptions,\n otherOptions,\n {\n params: version ? { version: version.toString() } : undefined,\n }\n );\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const addDictionary = async (\n body: AddDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddDictionaryResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n const pushDictionaries = async (\n dictionaries: PushDictionariesBody['dictionaries'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushDictionariesResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { dictionaries },\n }\n );\n\n /**\n * Updates an existing dictionary in the database.\n * @param dictionary - Updated dictionary data.\n */\n const updateDictionary = async (\n dictionary: UpdateDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionary.id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: dictionary,\n }\n );\n\n /**\n * Deletes a dictionary from the database by its ID.\n * @param id - Dictionary ID.\n */\n const deleteDictionary = async (\n id: DeleteDictionaryParam['dictionaryId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteDictionaryResult>(\n `${PROJECT_API_ROUTE}/${id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n return {\n getDictionaries,\n getDictionariesKeys,\n getDictionariesUpdateTimestamp,\n getDictionary,\n pushDictionaries,\n addDictionary,\n updateDictionary,\n deleteDictionary,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n} from '../types';\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;\n\n /**\n * Retrieves a list of dictionaries based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getDictionaries = async (\n filters?: GetDictionariesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesResult>(\n PROJECT_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params: filters,\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesKeys = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetDictionariesKeysResult>(\n `${PROJECT_API_ROUTE}/keys`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a list of dictionary keys related to the project.\n */\n const getDictionariesUpdateTimestamp = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionariesUpdateTimestampResult>(\n `${PROJECT_API_ROUTE}/update`,\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n }\n );\n\n /**\n * Retrieves a dictionary by its key and version.\n * @param dictionaryKey - Dictionary key.\n * @param version - Dictionary version of content.\n */\n const getDictionary = async (\n dictionaryKey: GetDictionaryParams['dictionaryKey'],\n version?: GetDictionaryQuery['version'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionaryKey}`,\n authAPIOptions,\n otherOptions,\n {\n params: version ? { version: version.toString() } : undefined,\n }\n );\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const addDictionary = async (\n body: AddDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AddDictionaryResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n const pushDictionaries = async (\n dictionaries: PushDictionariesBody['dictionaries'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<PushDictionariesResult>(\n `${PROJECT_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PATCH',\n body: { dictionaries },\n }\n );\n\n /**\n * Updates an existing dictionary in the database.\n * @param dictionary - Updated dictionary data.\n */\n const updateDictionary = async (\n dictionary: UpdateDictionaryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateDictionaryResult>(\n `${PROJECT_API_ROUTE}/${dictionary.id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: dictionary,\n }\n );\n\n /**\n * Deletes a dictionary from the database by its ID.\n * @param id - Dictionary ID.\n */\n const deleteDictionary = async (\n id: DeleteDictionaryParam['dictionaryId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteDictionaryResult>(\n `${PROJECT_API_ROUTE}/${id}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n return {\n getDictionaries,\n getDictionariesKeys,\n getDictionariesUpdateTimestamp,\n getDictionary,\n pushDictionaries,\n addDictionary,\n updateDictionary,\n deleteDictionary,\n };\n};\n"],"mappings":"+EAqBA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CACH,IAAM,EACJ,GAAgB,QAAQ,YAAc,GAAe,QAAQ,WAE/D,GAAI,CAAC,EACH,MAAU,MACR,4DACD,CAGH,IAAM,EAAoB,GAAG,EAAW,iBAuIxC,MAAO,CACL,gBAlIsB,MACtB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,EACA,EACA,EACA,CACE,MAAO,WAEP,OAAQ,EACT,CACF,CAsHD,oBAjH0B,MAAO,EAA+B,EAAE,GAClE,MAAM,EACJ,GAAG,EAAkB,OACrB,EACA,EACA,CACE,MAAO,WACR,CACF,CA0GD,+BArGqC,MACrC,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAkB,SACrB,EACA,EACA,CACE,MAAO,WACR,CACF,CA4FD,cArFoB,MACpB,EACA,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAkB,GAAG,IACxB,EACA,EACA,CACE,OAAQ,EAAU,CAAE,QAAS,EAAQ,UAAU,CAAE,CAAG,IAAA,GACrD,CACF,CA0ED,iBAtDuB,MACvB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,IACH,EACA,EACA,CACE,OAAQ,QACR,KAAM,CAAE,eAAc,CACvB,CACF,CA2CD,cArEoB,MACpB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,IACH,EACA,EACA,CACE,OAAQ,OACR,OACD,CACF,CA0DD,iBAtCuB,MACvB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAkB,GAAG,EAAW,KACnC,EACA,EACA,CACE,OAAQ,MACR,KAAM,EACP,CACF,CA2BD,iBArBuB,MACvB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAkB,GAAG,IACxB,EACA,EACA,CACE,OAAQ,SACT,CACF,CAWF"}
|
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import configuration from "@intlayer/config/built";
|
|
3
|
-
|
|
4
|
-
//#region src/getIntlayerAPI/editor.ts
|
|
5
|
-
const getEditorAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
6
|
-
const editorURL = intlayerConfig?.editor?.editorURL ?? configuration?.editor?.editorURL;
|
|
7
|
-
if (!editorURL) throw new Error("Editor URL is not defined in the Intlayer configuration.");
|
|
8
|
-
const EDITOR_API_ROUTE = `${editorURL}/api`;
|
|
9
|
-
/**
|
|
10
|
-
* Get the Intlayer configuration
|
|
11
|
-
*/
|
|
12
|
-
const getConfiguration = async (otherOptions = {}) => {
|
|
13
|
-
return (await fetcher(`${EDITOR_API_ROUTE}/config`, authAPIOptions, otherOptions)).data;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Get the Intlayer configuration
|
|
17
|
-
*/
|
|
18
|
-
const getDictionaries = async (otherOptions = {}) => {
|
|
19
|
-
return (await fetcher(`${EDITOR_API_ROUTE}/dictionary`, authAPIOptions, otherOptions)).data;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Adds a new dictionary to the database.
|
|
23
|
-
* @param dictionary - Dictionary data.
|
|
24
|
-
*/
|
|
25
|
-
const writeDictionary = async (body, otherOptions = {}) => await fetcher(`${EDITOR_API_ROUTE}/dictionary`, authAPIOptions, otherOptions, {
|
|
26
|
-
method: "POST",
|
|
27
|
-
body
|
|
28
|
-
});
|
|
29
|
-
return {
|
|
30
|
-
getDictionaries,
|
|
31
|
-
getConfiguration,
|
|
32
|
-
writeDictionary
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
export { getEditorAPI };
|
|
1
|
+
import{fetcher as e}from"../fetcher.mjs";import t from"@intlayer/config/built";const n=(n={},r)=>{let i=r?.editor?.editorURL??t?.editor?.editorURL;if(!i)throw Error(`Editor URL is not defined in the Intlayer configuration.`);let a=`${i}/api`;return{getDictionaries:async(t={})=>(await e(`${a}/dictionary`,n,t)).data,getConfiguration:async(t={})=>(await e(`${a}/config`,n,t)).data,writeDictionary:async(t,r={})=>await e(`${a}/dictionary`,n,r,{method:`POST`,body:t})}};export{n as getEditorAPI};
|
|
38
2
|
//# sourceMappingURL=editor.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.mjs","names":[],"sources":["../../../src/getIntlayerAPI/editor.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n GetConfigurationResult,\n GetEditorDictionariesResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from '../types';\n\nexport const getEditorAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const editorURL =\n intlayerConfig?.editor?.editorURL ?? configuration?.editor?.editorURL;\n\n if (!editorURL) {\n throw new Error('Editor URL is not defined in the Intlayer configuration.');\n }\n\n const EDITOR_API_ROUTE = `${editorURL}/api`;\n\n /**\n * Get the Intlayer configuration\n */\n const getConfiguration = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetConfigurationResult> => {\n const response = await fetcher<GetConfigurationResult>(\n `${EDITOR_API_ROUTE}/config`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetConfigurationResult;\n };\n\n /**\n * Get the Intlayer configuration\n */\n const getDictionaries = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetEditorDictionariesResult> => {\n const response = await fetcher<GetEditorDictionariesResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetEditorDictionariesResult;\n };\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const writeDictionary = async (\n body: WriteContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<WriteContentDeclarationResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n return {\n getDictionaries,\n getConfiguration,\n writeDictionary,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"editor.mjs","names":[],"sources":["../../../src/getIntlayerAPI/editor.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { type FetcherOptions, fetcher } from '../fetcher';\nimport type {\n GetConfigurationResult,\n GetEditorDictionariesResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from '../types';\n\nexport const getEditorAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const editorURL =\n intlayerConfig?.editor?.editorURL ?? configuration?.editor?.editorURL;\n\n if (!editorURL) {\n throw new Error('Editor URL is not defined in the Intlayer configuration.');\n }\n\n const EDITOR_API_ROUTE = `${editorURL}/api`;\n\n /**\n * Get the Intlayer configuration\n */\n const getConfiguration = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetConfigurationResult> => {\n const response = await fetcher<GetConfigurationResult>(\n `${EDITOR_API_ROUTE}/config`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetConfigurationResult;\n };\n\n /**\n * Get the Intlayer configuration\n */\n const getDictionaries = async (\n otherOptions: FetcherOptions = {}\n ): Promise<GetEditorDictionariesResult> => {\n const response = await fetcher<GetEditorDictionariesResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions\n );\n\n return response.data as unknown as GetEditorDictionariesResult;\n };\n\n /**\n * Adds a new dictionary to the database.\n * @param dictionary - Dictionary data.\n */\n const writeDictionary = async (\n body: WriteContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<WriteContentDeclarationResult>(\n `${EDITOR_API_ROUTE}/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n return {\n getDictionaries,\n getConfiguration,\n writeDictionary,\n };\n};\n"],"mappings":"+EAUA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CACH,IAAM,EACJ,GAAgB,QAAQ,WAAa,GAAe,QAAQ,UAE9D,GAAI,CAAC,EACH,MAAU,MAAM,2DAA2D,CAG7E,IAAM,EAAmB,GAAG,EAAU,MAkDtC,MAAO,CACL,gBA/BsB,MACtB,EAA+B,EAAE,IAEhB,MAAM,EACrB,GAAG,EAAiB,aACpB,EACA,EACD,EAEe,KAuBhB,iBA/CuB,MACvB,EAA+B,EAAE,IAEhB,MAAM,EACrB,GAAG,EAAiB,SACpB,EACA,EACD,EAEe,KAuChB,gBAjBsB,MACtB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAiB,aACpB,EACA,EACA,CACE,OAAQ,OACR,OACD,CACF,CAMF"}
|
|
@@ -1,72 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import configuration from "@intlayer/config/built";
|
|
3
|
-
|
|
4
|
-
//#region src/getIntlayerAPI/github.ts
|
|
5
|
-
const getGithubAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
6
|
-
const backendURL = intlayerConfig?.editor?.backendURL ?? configuration?.editor?.backendURL;
|
|
7
|
-
if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
|
|
8
|
-
const GITHUB_API_ROUTE = `${backendURL}/api/github`;
|
|
9
|
-
/**
|
|
10
|
-
* Get GitHub OAuth authorization URL
|
|
11
|
-
* @param redirectUri - Redirect URI after OAuth authorization
|
|
12
|
-
*/
|
|
13
|
-
const getAuthUrl = async (redirectUri, otherOptions = {}) => await fetcher(`${GITHUB_API_ROUTE}/auth-url`, authAPIOptions, otherOptions, { params: { redirectUri } });
|
|
14
|
-
/**
|
|
15
|
-
* Exchange GitHub authorization code for access token
|
|
16
|
-
* @param code - GitHub authorization code
|
|
17
|
-
*/
|
|
18
|
-
const authenticate = async (code, otherOptions = {}) => await fetcher(`${GITHUB_API_ROUTE}/auth`, authAPIOptions, otherOptions, {
|
|
19
|
-
method: "POST",
|
|
20
|
-
body: { code }
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Get user's GitHub repositories
|
|
24
|
-
* @param token - Optional GitHub access token. If not provided, backend will use session.
|
|
25
|
-
*/
|
|
26
|
-
const getRepositories = async (token, otherOptions = {}) => await fetcher(`${GITHUB_API_ROUTE}/repos`, authAPIOptions, otherOptions, { params: token ? { token } : void 0 });
|
|
27
|
-
/**
|
|
28
|
-
* Check if intlayer.config.ts exists in a repository
|
|
29
|
-
* @param token - Optional GitHub access token. If not provided, backend will use session.
|
|
30
|
-
* @param owner - Repository owner
|
|
31
|
-
* @param repository - Repository name
|
|
32
|
-
* @param branch - Branch name (default: 'main')
|
|
33
|
-
*/
|
|
34
|
-
const checkIntlayerConfig = async (token, owner, repository, branch = "main", otherOptions = {}) => await fetcher(`${GITHUB_API_ROUTE}/check-config`, authAPIOptions, otherOptions, {
|
|
35
|
-
method: "POST",
|
|
36
|
-
body: {
|
|
37
|
-
token: token ?? void 0,
|
|
38
|
-
owner,
|
|
39
|
-
repository,
|
|
40
|
-
branch
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
/**
|
|
44
|
-
* Get intlayer.config.ts file contents from a repository
|
|
45
|
-
* @param token - Optional GitHub access token. If not provided, backend will use session.
|
|
46
|
-
* @param owner - Repository owner
|
|
47
|
-
* @param repository - Repository name
|
|
48
|
-
* @param branch - Branch name (default: 'main')
|
|
49
|
-
* @param path - File path (default: 'intlayer.config.ts')
|
|
50
|
-
*/
|
|
51
|
-
const getConfigFile = async (token, owner, repository, branch = "main", path = "intlayer.config.ts", otherOptions = {}) => await fetcher(`${GITHUB_API_ROUTE}/get-config-file`, authAPIOptions, otherOptions, {
|
|
52
|
-
method: "POST",
|
|
53
|
-
body: {
|
|
54
|
-
token: token ?? void 0,
|
|
55
|
-
owner,
|
|
56
|
-
repository,
|
|
57
|
-
branch,
|
|
58
|
-
path
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
getAuthUrl,
|
|
63
|
-
authenticate,
|
|
64
|
-
getRepositories,
|
|
65
|
-
checkIntlayerConfig,
|
|
66
|
-
getConfigFile
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
//#endregion
|
|
71
|
-
export { getGithubAPI };
|
|
1
|
+
import{fetcher as e}from"../fetcher.mjs";import t from"@intlayer/config/built";const n=(n={},r)=>{let i=r?.editor?.backendURL??t?.editor?.backendURL;if(!i)throw Error(`Backend URL is not defined in the Intlayer configuration.`);let a=`${i}/api/github`;return{getAuthUrl:async(t,r={})=>await e(`${a}/auth-url`,n,r,{params:{redirectUri:t}}),authenticate:async(t,r={})=>await e(`${a}/auth`,n,r,{method:`POST`,body:{code:t}}),getRepositories:async(t,r={})=>await e(`${a}/repos`,n,r,{params:t?{token:t}:void 0}),checkIntlayerConfig:async(t,r,i,o=`main`,s={})=>await e(`${a}/check-config`,n,s,{method:`POST`,body:{token:t??void 0,owner:r,repository:i,branch:o}}),getConfigFile:async(t,r,i,o=`main`,s=`intlayer.config.ts`,c={})=>await e(`${a}/get-config-file`,n,c,{method:`POST`,body:{token:t??void 0,owner:r,repository:i,branch:o,path:s}})}};export{n as getGithubAPI};
|
|
72
2
|
//# sourceMappingURL=github.mjs.map
|