@intlayer/api 6.1.6-canary.0 → 7.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +18 -55
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +20 -58
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/distantDictionary/index.cjs +5 -25
- package/dist/cjs/fetcher.cjs +113 -89
- package/dist/cjs/fetcher.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs +163 -188
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/dictionary.cjs +69 -117
- package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/editor.cjs +37 -74
- package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/index.cjs +27 -49
- package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/newsletter.cjs +40 -77
- package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/oAuth.cjs +26 -65
- package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/organization.cjs +93 -130
- package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/project.cjs +109 -154
- package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/search.cjs +22 -58
- package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/stripe.cjs +38 -77
- package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/tag.cjs +47 -86
- package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/user.cjs +79 -106
- package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
- package/dist/cjs/index.cjs +30 -49
- package/dist/cjs/proxy.cjs +90 -115
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/cjs/types.cjs +0 -17
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +17 -20
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +19 -23
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/distantDictionary/index.mjs +4 -3
- package/dist/esm/fetcher.mjs +111 -64
- package/dist/esm/fetcher.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/ai.mjs +160 -153
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/dictionary.mjs +66 -82
- package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/editor.mjs +34 -39
- package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/index.mjs +16 -14
- package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/newsletter.mjs +37 -42
- package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/oAuth.mjs +23 -30
- package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/organization.mjs +90 -95
- package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/project.mjs +106 -119
- package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/search.mjs +19 -23
- package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/stripe.mjs +35 -42
- package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/tag.mjs +44 -51
- package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/user.mjs +76 -71
- package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
- package/dist/esm/index.mjs +16 -15
- package/dist/esm/proxy.mjs +89 -90
- package/dist/esm/proxy.mjs.map +1 -1
- package/dist/esm/types.mjs +0 -1
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +8 -3
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +8 -3
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
- package/dist/types/distantDictionary/index.d.ts +3 -3
- package/dist/types/fetcher.d.ts +14 -11
- package/dist/types/fetcher.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts +22 -18
- package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/dictionary.d.ts +16 -12
- package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/editor.d.ts +11 -7
- package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/index.d.ts +30 -27
- package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/newsletter.d.ts +11 -7
- package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/oAuth.d.ts +8 -5
- package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/organization.d.ts +18 -13
- package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/project.d.ts +19 -15
- package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/search.d.ts +9 -5
- package/dist/types/getIntlayerAPI/search.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/stripe.d.ts +11 -7
- package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/tag.d.ts +12 -8
- package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/user.d.ts +16 -12
- package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
- package/dist/types/index.d.ts +16 -15
- package/dist/types/proxy.d.ts +10 -5
- package/dist/types/proxy.d.ts.map +1 -1
- package/dist/types/types.d.ts +13 -12
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +29 -38
- package/LICENSE +0 -202
- package/dist/cjs/distantDictionary/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/types.cjs.map +0 -1
- package/dist/esm/distantDictionary/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/types/distantDictionary/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
|
@@ -1,191 +1,166 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var ai_exports = {};
|
|
30
|
-
__export(ai_exports, {
|
|
31
|
-
getAiAPI: () => getAiAPI
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(ai_exports);
|
|
34
|
-
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
-
var import_fetcher = require('../fetcher.cjs');
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_fetcher = require('../fetcher.cjs');
|
|
3
|
+
let __intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
5
|
+
|
|
6
|
+
//#region src/getIntlayerAPI/ai.ts
|
|
36
7
|
const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
8
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? __intlayer_config_built.default?.editor?.backendURL;
|
|
9
|
+
if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
|
|
10
|
+
const AI_API_ROUTE = `${backendURL}/api/ai`;
|
|
11
|
+
/**
|
|
12
|
+
* Custom query
|
|
13
|
+
* @param body - Custom query parameters.
|
|
14
|
+
* @returns Custom query result.
|
|
15
|
+
*/
|
|
16
|
+
const customQuery = async (body, otherOptions = {}) => await require_fetcher.fetcher(AI_API_ROUTE, authAPIOptions, otherOptions, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
body
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Translate a JSON
|
|
22
|
+
* @param body - Audit file parameters.
|
|
23
|
+
* @returns Audited file content.
|
|
24
|
+
*/
|
|
25
|
+
const translateJSON = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/translate/json`, authAPIOptions, otherOptions, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Audits a content declaration file
|
|
31
|
+
* @param body - Audit file parameters.
|
|
32
|
+
* @returns Audited file content.
|
|
33
|
+
*/
|
|
34
|
+
const auditContentDeclaration = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/audit/dictionary`, authAPIOptions, otherOptions, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
body
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Audits a content declaration field
|
|
40
|
+
* @param body - Audit file parameters.
|
|
41
|
+
* @returns Audited file content.
|
|
42
|
+
*/
|
|
43
|
+
const auditContentDeclarationField = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/audit/dictionary/field`, authAPIOptions, otherOptions, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
body
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Audits a content declaration file to retrieve title, description and tags
|
|
49
|
+
* @param body - Audit file parameters.
|
|
50
|
+
* @returns Audited file content.
|
|
51
|
+
*/
|
|
52
|
+
const auditContentDeclarationMetadata = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/audit/dictionary/metadata`, authAPIOptions, otherOptions, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Audits a tag
|
|
58
|
+
* @param body - Audit tag parameters.
|
|
59
|
+
* @returns Audited tag content.
|
|
60
|
+
*/
|
|
61
|
+
const auditTag = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/audit/tag`, authAPIOptions, otherOptions, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
body
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Asks a question to the AI related to the documentation **and streams the
|
|
67
|
+
* answer as Server‑Sent Events (SSE)**.
|
|
68
|
+
*
|
|
69
|
+
* The function **returns immediately** with a handle exposing:
|
|
70
|
+
* - `promise` → resolves when the stream completes (or rejects on error)
|
|
71
|
+
* - `abort()` → allows canceling the request on demand
|
|
72
|
+
*
|
|
73
|
+
* Usage example:
|
|
74
|
+
* ```ts
|
|
75
|
+
* const { promise, abort } = ai.askDocQuestion({
|
|
76
|
+
* ...body,
|
|
77
|
+
* onMessage: console.log,
|
|
78
|
+
* onDone: (full) => console.log("✔", full),
|
|
79
|
+
* });
|
|
80
|
+
* // later → abort();
|
|
81
|
+
* await promise; // waits for completion if desired
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
const askDocQuestion = async (body, otherOptions = {}) => {
|
|
85
|
+
if (!body) return;
|
|
86
|
+
const { onMessage, onDone,...rest } = body;
|
|
87
|
+
const abortController = new AbortController();
|
|
88
|
+
try {
|
|
89
|
+
const response = await fetch(`${AI_API_ROUTE}/ask`, {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "application/json",
|
|
93
|
+
...authAPIOptions.headers,
|
|
94
|
+
...otherOptions.headers
|
|
95
|
+
},
|
|
96
|
+
body: JSON.stringify({
|
|
97
|
+
...rest,
|
|
98
|
+
...authAPIOptions.body,
|
|
99
|
+
...otherOptions.body
|
|
100
|
+
}),
|
|
101
|
+
signal: abortController.signal,
|
|
102
|
+
credentials: "include"
|
|
103
|
+
});
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
let errorMessage = "An error occurred";
|
|
106
|
+
try {
|
|
107
|
+
const errorData = await response.json();
|
|
108
|
+
errorMessage = JSON.stringify(errorData.error) ?? "An error occurred";
|
|
109
|
+
} catch {
|
|
110
|
+
try {
|
|
111
|
+
const errorText = await response.text();
|
|
112
|
+
if (errorText) errorMessage = errorText;
|
|
113
|
+
} catch {}
|
|
114
|
+
}
|
|
115
|
+
throw new Error(errorMessage);
|
|
116
|
+
}
|
|
117
|
+
const reader = response.body?.getReader();
|
|
118
|
+
if (!reader) throw new Error("No reader available");
|
|
119
|
+
const decoder = new TextDecoder();
|
|
120
|
+
let buffer = "";
|
|
121
|
+
while (true) {
|
|
122
|
+
const { done, value } = await reader.read();
|
|
123
|
+
if (done) break;
|
|
124
|
+
buffer += decoder.decode(value, { stream: true });
|
|
125
|
+
const lines = buffer.split("\n");
|
|
126
|
+
buffer = lines.pop() ?? "";
|
|
127
|
+
for (const line of lines) if (line.startsWith("data: ")) try {
|
|
128
|
+
const data = JSON.parse(line.slice(6));
|
|
129
|
+
if (data.chunk) onMessage?.(data.chunk);
|
|
130
|
+
if (data.done && data.response) onDone?.(data.response);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.error("Failed to parse SSE data:", e);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error("Error in askDocQuestion:", error);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const autocomplete = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/autocomplete`, authAPIOptions, otherOptions, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
body
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Retrieves discussions with filters and pagination. Only user or admin can access.
|
|
146
|
+
*/
|
|
147
|
+
const getDiscussions = async (params, otherOptions = {}) => await require_fetcher.fetcher(`${AI_API_ROUTE}/discussions`, authAPIOptions, otherOptions, {
|
|
148
|
+
method: "GET",
|
|
149
|
+
params
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
customQuery,
|
|
153
|
+
translateJSON,
|
|
154
|
+
auditContentDeclaration,
|
|
155
|
+
auditContentDeclarationField,
|
|
156
|
+
auditContentDeclarationMetadata,
|
|
157
|
+
auditTag,
|
|
158
|
+
askDocQuestion,
|
|
159
|
+
autocomplete,
|
|
160
|
+
getDiscussions
|
|
161
|
+
};
|
|
186
162
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
exports.getAiAPI = getAiAPI;
|
|
191
166
|
//# sourceMappingURL=ai.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport { fetcher, type FetcherOptions } 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 TranslateJSONBody,\n TranslateJSONResult,\n} from '../types';\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discutionId: 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 return {\n customQuery,\n translateJSON,\n auditContentDeclaration,\n auditContentDeclarationField,\n auditContentDeclarationMetadata,\n auditTag,\n askDocQuestion,\n autocomplete,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,qBAA6C;AA6BtC,MAAM,WAAW,CACtB,iBAAiC,CAAC,GAClC,mBACG;AACH,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MAAM,CAAC,CAAC;AACrC,kBAAI,KAAK,OAAO;AACd,4BAAY,KAAK,KAAK;AAAA,cACxB;AACA,kBAAI,KAAK,QAAQ,KAAK,UAAU;AAC9B,yBAAS,KAAK,QAAQ;AAAA,cACxB;AAAA,YACF,SAAS,GAAG;AACV,sBAAQ,MAAM,6BAA6B,CAAC;AAAA,YAC9C;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,4BAA4B,KAAK;AAC/C,YAAM;AAAA,IACR;AAAA,EACF;AAEA,QAAM,eAAe,OACnB,MACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,YAAY;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["configuration"]}
|
|
1
|
+
{"version":3,"file":"ai.cjs","names":["configuration","fetcher","errorMessage: string"],"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":";;;;;;AAiCA,MAAa,YACX,iBAAiC,EAAE,EACnC,mBACG;CACH,MAAM,aACJ,gBAAgB,QAAQ,cAAcA,iCAAe,QAAQ;AAE/D,KAAI,CAAC,WACH,OAAM,IAAI,MACR,4DACD;CAGH,MAAM,eAAe,GAAG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
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var dictionary_exports = {};
|
|
30
|
-
__export(dictionary_exports, {
|
|
31
|
-
getDictionaryAPI: () => getDictionaryAPI
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(dictionary_exports);
|
|
34
|
-
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
-
var import_fetcher = require('../fetcher.cjs');
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_fetcher = require('../fetcher.cjs');
|
|
3
|
+
let __intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
__intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
|
|
5
|
+
|
|
6
|
+
//#region src/getIntlayerAPI/dictionary.ts
|
|
36
7
|
const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const deleteDictionary = async (id, otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
98
|
-
`${PROJECT_API_ROUTE}/${id}`,
|
|
99
|
-
authAPIOptions,
|
|
100
|
-
otherOptions,
|
|
101
|
-
{
|
|
102
|
-
method: "DELETE"
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
return {
|
|
106
|
-
getDictionaries,
|
|
107
|
-
getDictionariesKeys,
|
|
108
|
-
getDictionariesUpdateTimestamp,
|
|
109
|
-
getDictionary,
|
|
110
|
-
pushDictionaries,
|
|
111
|
-
addDictionary,
|
|
112
|
-
updateDictionary,
|
|
113
|
-
deleteDictionary
|
|
114
|
-
};
|
|
8
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? __intlayer_config_built.default?.editor?.backendURL;
|
|
9
|
+
if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
|
|
10
|
+
const PROJECT_API_ROUTE = `${backendURL}/api/dictionary`;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves a list of dictionaries based on filters and pagination.
|
|
13
|
+
* @param filters - Filters and pagination options.
|
|
14
|
+
*/
|
|
15
|
+
const getDictionaries = async (filters, otherOptions = {}) => await require_fetcher.fetcher(PROJECT_API_ROUTE, authAPIOptions, otherOptions, {
|
|
16
|
+
cache: "no-store",
|
|
17
|
+
params: filters
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves a list of dictionary keys related to the project.
|
|
21
|
+
*/
|
|
22
|
+
const getDictionariesKeys = async (otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}/keys`, authAPIOptions, otherOptions, { cache: "no-store" });
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves a list of dictionary keys related to the project.
|
|
25
|
+
*/
|
|
26
|
+
const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}/update`, authAPIOptions, otherOptions, { cache: "no-store" });
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves a dictionary by its key and version.
|
|
29
|
+
* @param dictionaryKey - Dictionary key.
|
|
30
|
+
* @param version - Dictionary version of content.
|
|
31
|
+
*/
|
|
32
|
+
const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}/${dictionaryKey}`, authAPIOptions, otherOptions, { params: version ? { version: version.toString() } : void 0 });
|
|
33
|
+
/**
|
|
34
|
+
* Adds a new dictionary to the database.
|
|
35
|
+
* @param dictionary - Dictionary data.
|
|
36
|
+
*/
|
|
37
|
+
const addDictionary = async (body, otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
body
|
|
40
|
+
});
|
|
41
|
+
const pushDictionaries = async (dictionaries, otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
|
|
42
|
+
method: "PATCH",
|
|
43
|
+
body: { dictionaries }
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Updates an existing dictionary in the database.
|
|
47
|
+
* @param dictionary - Updated dictionary data.
|
|
48
|
+
*/
|
|
49
|
+
const updateDictionary = async (dictionary, otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}/${dictionary.id}`, authAPIOptions, otherOptions, {
|
|
50
|
+
method: "PUT",
|
|
51
|
+
body: dictionary
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Deletes a dictionary from the database by its ID.
|
|
55
|
+
* @param id - Dictionary ID.
|
|
56
|
+
*/
|
|
57
|
+
const deleteDictionary = async (id, otherOptions = {}) => await require_fetcher.fetcher(`${PROJECT_API_ROUTE}/${id}`, authAPIOptions, otherOptions, { method: "DELETE" });
|
|
58
|
+
return {
|
|
59
|
+
getDictionaries,
|
|
60
|
+
getDictionariesKeys,
|
|
61
|
+
getDictionariesUpdateTimestamp,
|
|
62
|
+
getDictionary,
|
|
63
|
+
pushDictionaries,
|
|
64
|
+
addDictionary,
|
|
65
|
+
updateDictionary,
|
|
66
|
+
deleteDictionary
|
|
67
|
+
};
|
|
115
68
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.getDictionaryAPI = getDictionaryAPI;
|
|
120
72
|
//# sourceMappingURL=dictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/
|
|
1
|
+
{"version":3,"file":"dictionary.cjs","names":["configuration","fetcher"],"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":";;;;;;AAqBA,MAAa,oBACX,iBAAiC,EAAE,EACnC,mBACG;CACH,MAAM,aACJ,gBAAgB,QAAQ,cAAcA,iCAAe,QAAQ;AAE/D,KAAI,CAAC,WACH,OAAM,IAAI,MACR,4DACD;CAGH,MAAM,oBAAoB,GAAG,WAAW;;;;;CAMxC,MAAM,kBAAkB,OACtB,SACA,eAA+B,EAAE,KAEjC,MAAMC,wBACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;EACT,CACF;;;;CAKH,MAAM,sBAAsB,OAAO,eAA+B,EAAE,KAClE,MAAMA,wBACJ,GAAG,kBAAkB,QACrB,gBACA,cACA,EACE,OAAO,YACR,CACF;;;;CAKH,MAAM,iCAAiC,OACrC,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,kBAAkB,UACrB,gBACA,cACA,EACE,OAAO,YACR,CACF;;;;;;CAOH,MAAM,gBAAgB,OACpB,eACA,SACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,kBAAkB,GAAG,iBACxB,gBACA,cACA,EACE,QAAQ,UAAU,EAAE,SAAS,QAAQ,UAAU,EAAE,GAAG,QACrD,CACF;;;;;CAMH,MAAM,gBAAgB,OACpB,MACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;CAEH,MAAM,mBAAmB,OACvB,cACA,eAA+B,EAAE,KAEjC,MAAMA,wBACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM,EAAE,cAAc;EACvB,CACF;;;;;CAMH,MAAM,mBAAmB,OACvB,YACA,eAA+B,EAAE,KAEjC,M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