@intlayer/api 8.4.3 → 8.4.5

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.
Files changed (178) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +20 -1
  3. package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
  4. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +22 -1
  5. package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
  6. package/dist/cjs/distantDictionary/index.cjs +6 -1
  7. package/dist/cjs/fetcher.cjs +122 -1
  8. package/dist/cjs/fetcher.cjs.map +1 -1
  9. package/dist/cjs/getIntlayerAPI/ai.cjs +161 -2
  10. package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
  11. package/dist/cjs/getIntlayerAPI/audit.cjs +94 -2
  12. package/dist/cjs/getIntlayerAPI/audit.cjs.map +1 -1
  13. package/dist/cjs/getIntlayerAPI/bitbucket.cjs +69 -1
  14. package/dist/cjs/getIntlayerAPI/bitbucket.cjs.map +1 -1
  15. package/dist/cjs/getIntlayerAPI/dictionary.cjs +67 -1
  16. package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
  17. package/dist/cjs/getIntlayerAPI/editor.cjs +37 -1
  18. package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
  19. package/dist/cjs/getIntlayerAPI/github.cjs +69 -1
  20. package/dist/cjs/getIntlayerAPI/github.cjs.map +1 -1
  21. package/dist/cjs/getIntlayerAPI/gitlab.cjs +83 -1
  22. package/dist/cjs/getIntlayerAPI/gitlab.cjs.map +1 -1
  23. package/dist/cjs/getIntlayerAPI/index.cjs +48 -1
  24. package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -0
  25. package/dist/cjs/getIntlayerAPI/newsletter.cjs +38 -1
  26. package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
  27. package/dist/cjs/getIntlayerAPI/oAuth.cjs +25 -1
  28. package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
  29. package/dist/cjs/getIntlayerAPI/organization.cjs +91 -1
  30. package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
  31. package/dist/cjs/getIntlayerAPI/project.cjs +139 -1
  32. package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
  33. package/dist/cjs/getIntlayerAPI/search.cjs +20 -1
  34. package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
  35. package/dist/cjs/getIntlayerAPI/showcaseProject.cjs +58 -1
  36. package/dist/cjs/getIntlayerAPI/showcaseProject.cjs.map +1 -1
  37. package/dist/cjs/getIntlayerAPI/stripe.cjs +36 -1
  38. package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
  39. package/dist/cjs/getIntlayerAPI/tag.cjs +45 -1
  40. package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
  41. package/dist/cjs/getIntlayerAPI/user.cjs +77 -1
  42. package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
  43. package/dist/cjs/index.cjs +43 -1
  44. package/dist/cjs/proxy.cjs +100 -1
  45. package/dist/cjs/proxy.cjs.map +1 -1
  46. package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +19 -1
  47. package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
  48. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +21 -1
  49. package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
  50. package/dist/esm/distantDictionary/index.mjs +4 -1
  51. package/dist/esm/fetcher.mjs +119 -1
  52. package/dist/esm/fetcher.mjs.map +1 -1
  53. package/dist/esm/getIntlayerAPI/ai.mjs +160 -2
  54. package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
  55. package/dist/esm/getIntlayerAPI/audit.mjs +93 -2
  56. package/dist/esm/getIntlayerAPI/audit.mjs.map +1 -1
  57. package/dist/esm/getIntlayerAPI/bitbucket.mjs +68 -1
  58. package/dist/esm/getIntlayerAPI/bitbucket.mjs.map +1 -1
  59. package/dist/esm/getIntlayerAPI/dictionary.mjs +66 -1
  60. package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
  61. package/dist/esm/getIntlayerAPI/editor.mjs +36 -1
  62. package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
  63. package/dist/esm/getIntlayerAPI/github.mjs +68 -1
  64. package/dist/esm/getIntlayerAPI/github.mjs.map +1 -1
  65. package/dist/esm/getIntlayerAPI/gitlab.mjs +82 -1
  66. package/dist/esm/getIntlayerAPI/gitlab.mjs.map +1 -1
  67. package/dist/esm/getIntlayerAPI/index.mjs +44 -1
  68. package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
  69. package/dist/esm/getIntlayerAPI/newsletter.mjs +37 -1
  70. package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
  71. package/dist/esm/getIntlayerAPI/oAuth.mjs +24 -1
  72. package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
  73. package/dist/esm/getIntlayerAPI/organization.mjs +90 -1
  74. package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
  75. package/dist/esm/getIntlayerAPI/project.mjs +138 -1
  76. package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
  77. package/dist/esm/getIntlayerAPI/search.mjs +19 -1
  78. package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
  79. package/dist/esm/getIntlayerAPI/showcaseProject.mjs +57 -1
  80. package/dist/esm/getIntlayerAPI/showcaseProject.mjs.map +1 -1
  81. package/dist/esm/getIntlayerAPI/stripe.mjs +35 -1
  82. package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
  83. package/dist/esm/getIntlayerAPI/tag.mjs +44 -1
  84. package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
  85. package/dist/esm/getIntlayerAPI/user.mjs +76 -1
  86. package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
  87. package/dist/esm/index.mjs +22 -1
  88. package/dist/esm/proxy.mjs +99 -1
  89. package/dist/esm/proxy.mjs.map +1 -1
  90. package/dist/types/@intlayer/unmerged-dictionaries-entry/dist/types/index.d.ts +10 -0
  91. package/dist/types/@intlayer/unmerged-dictionaries-entry/dist/types/index.d.ts.map +1 -0
  92. package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +11 -2
  93. package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts.map +1 -0
  94. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +11 -2
  95. package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -0
  96. package/dist/types/distantDictionary/index.d.ts +2 -2
  97. package/dist/types/getIntlayerAPI/ai.d.ts +32 -2
  98. package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -0
  99. package/dist/types/getIntlayerAPI/audit.d.ts +44 -2
  100. package/dist/types/getIntlayerAPI/audit.d.ts.map +1 -0
  101. package/dist/types/getIntlayerAPI/bitbucket.d.ts +81 -2
  102. package/dist/types/getIntlayerAPI/bitbucket.d.ts.map +1 -0
  103. package/dist/types/getIntlayerAPI/dictionary.d.ts +18 -2
  104. package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -0
  105. package/dist/types/getIntlayerAPI/editor.d.ts +14 -2
  106. package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -0
  107. package/dist/types/getIntlayerAPI/github.d.ts +65 -2
  108. package/dist/types/getIntlayerAPI/github.d.ts.map +1 -0
  109. package/dist/types/getIntlayerAPI/gitlab.d.ts +70 -2
  110. package/dist/types/getIntlayerAPI/gitlab.d.ts.map +1 -0
  111. package/dist/types/getIntlayerAPI/index.d.ts +16 -16
  112. package/dist/types/getIntlayerAPI/newsletter.d.ts +13 -2
  113. package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -0
  114. package/dist/types/getIntlayerAPI/oAuth.d.ts +10 -2
  115. package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -0
  116. package/dist/types/getIntlayerAPI/organization.d.ts +20 -2
  117. package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -0
  118. package/dist/types/getIntlayerAPI/project.d.ts +25 -2
  119. package/dist/types/getIntlayerAPI/project.d.ts.map +1 -0
  120. package/dist/types/getIntlayerAPI/search.d.ts +11 -2
  121. package/dist/types/getIntlayerAPI/search.d.ts.map +1 -0
  122. package/dist/types/getIntlayerAPI/showcaseProject.d.ts +33 -2
  123. package/dist/types/getIntlayerAPI/showcaseProject.d.ts.map +1 -0
  124. package/dist/types/getIntlayerAPI/stripe.d.ts +13 -2
  125. package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -0
  126. package/dist/types/getIntlayerAPI/tag.d.ts +14 -2
  127. package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -0
  128. package/dist/types/getIntlayerAPI/user.d.ts +22 -2
  129. package/dist/types/getIntlayerAPI/user.d.ts.map +1 -0
  130. package/dist/types/index.d.ts +17 -17
  131. package/dist/types/intlayer-editor/server/dist/controllers/configuration.controller.d.ts +12 -0
  132. package/dist/types/intlayer-editor/server/dist/controllers/configuration.controller.d.ts.map +1 -0
  133. package/dist/types/intlayer-editor/server/dist/controllers/dictionary.controller.d.ts +25 -0
  134. package/dist/types/intlayer-editor/server/dist/controllers/dictionary.controller.d.ts.map +1 -0
  135. package/dist/types/intlayer-editor/server/dist/export.d.ts +2 -0
  136. package/dist/types/{editor-DTBh5ovU.d.ts → intlayer-editor/server/dist/utils/httpStatusCodes.d.ts} +3 -61
  137. package/dist/types/intlayer-editor/server/dist/utils/httpStatusCodes.d.ts.map +1 -0
  138. package/dist/types/intlayer-editor/server/dist/utils/responseData.d.ts +20 -0
  139. package/dist/types/intlayer-editor/server/dist/utils/responseData.d.ts.map +1 -0
  140. package/dist/types/proxy.d.ts.map +1 -1
  141. package/package.json +3 -3
  142. package/dist/cjs/getIntlayerAPI-CUu2tiLP.cjs +0 -2
  143. package/dist/cjs/getIntlayerAPI-CUu2tiLP.cjs.map +0 -1
  144. package/dist/types/ai-FbIMwui1.d.ts +0 -32
  145. package/dist/types/ai-FbIMwui1.d.ts.map +0 -1
  146. package/dist/types/audit-DzTxbapP.d.ts +0 -44
  147. package/dist/types/audit-DzTxbapP.d.ts.map +0 -1
  148. package/dist/types/bitbucket-DeRx5IlR.d.ts +0 -81
  149. package/dist/types/bitbucket-DeRx5IlR.d.ts.map +0 -1
  150. package/dist/types/dictionary-W5LSPsxq.d.ts +0 -18
  151. package/dist/types/dictionary-W5LSPsxq.d.ts.map +0 -1
  152. package/dist/types/editor-DTBh5ovU.d.ts.map +0 -1
  153. package/dist/types/fetchDistantDictionaries-CLQEr6NS.d.ts +0 -11
  154. package/dist/types/fetchDistantDictionaries-CLQEr6NS.d.ts.map +0 -1
  155. package/dist/types/fetchDistantDictionary-C7esreMl.d.ts +0 -11
  156. package/dist/types/fetchDistantDictionary-C7esreMl.d.ts.map +0 -1
  157. package/dist/types/github-D077Il7G.d.ts +0 -65
  158. package/dist/types/github-D077Il7G.d.ts.map +0 -1
  159. package/dist/types/gitlab-BrWydMCh.d.ts +0 -70
  160. package/dist/types/gitlab-BrWydMCh.d.ts.map +0 -1
  161. package/dist/types/newsletter-Dg_6QDY_.d.ts +0 -13
  162. package/dist/types/newsletter-Dg_6QDY_.d.ts.map +0 -1
  163. package/dist/types/oAuth-DfQmGzLO.d.ts +0 -10
  164. package/dist/types/oAuth-DfQmGzLO.d.ts.map +0 -1
  165. package/dist/types/organization-CNkB8dnj.d.ts +0 -20
  166. package/dist/types/organization-CNkB8dnj.d.ts.map +0 -1
  167. package/dist/types/project-DKLgh9Mz.d.ts +0 -25
  168. package/dist/types/project-DKLgh9Mz.d.ts.map +0 -1
  169. package/dist/types/search-CVbo1OMK.d.ts +0 -11
  170. package/dist/types/search-CVbo1OMK.d.ts.map +0 -1
  171. package/dist/types/showcaseProject-1zcpB4aW.d.ts +0 -33
  172. package/dist/types/showcaseProject-1zcpB4aW.d.ts.map +0 -1
  173. package/dist/types/stripe-vRfMjdAc.d.ts +0 -13
  174. package/dist/types/stripe-vRfMjdAc.d.ts.map +0 -1
  175. package/dist/types/tag-0oc2-9J5.d.ts +0 -14
  176. package/dist/types/tag-0oc2-9J5.d.ts.map +0 -1
  177. package/dist/types/user-BVi1Ho0Q.d.ts +0 -22
  178. package/dist/types/user-BVi1Ho0Q.d.ts.map +0 -1
@@ -1,3 +1,161 @@
1
- import{fetcher as e}from"../fetcher.mjs";const t=(t={},n)=>{let r=`${n.editor.backendURL}/api/ai`;return{customQuery:async(n,i={})=>await e(r,t,i,{method:`POST`,body:n}),translateJSON:async(n,i={})=>await e(`${r}/translate/json`,t,i,{method:`POST`,body:n}),auditContentDeclaration:async(n,i={})=>await e(`${r}/audit/dictionary`,t,i,{method:`POST`,body:n}),auditContentDeclarationField:async(n,i={})=>await e(`${r}/audit/dictionary/field`,t,i,{method:`POST`,body:n}),auditContentDeclarationMetadata:async(n,i={})=>await e(`${r}/audit/dictionary/metadata`,t,i,{method:`POST`,body:n}),auditTag:async(n,i={})=>await e(`${r}/audit/tag`,t,i,{method:`POST`,body:n}),askDocQuestion:async(e,n={})=>{if(!e)return;let{onMessage:i,onDone:a,...o}=e,s=new AbortController;try{let e=await fetch(`${r}/ask`,{method:`POST`,headers:{"Content-Type":`application/json`,...t.headers,...n.headers},body:JSON.stringify({...o,...t.body,...n.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&&i?.(t.chunk),t.done&&t.response&&a?.(t.response)}catch(e){console.error(`Failed to parse SSE data:`,e)}}}catch(e){throw console.error(`Error in askDocQuestion:`,e),e}},autocomplete:async(n,i={})=>await e(`${r}/autocomplete`,t,i,{method:`POST`,body:n}),getDiscussions:async(n,i={})=>await e(`${r}/discussions`,t,i,{method:`GET`,params:n})}};export{t as getAiAPI};
1
+ import { fetcher } from "../fetcher.mjs";
2
+
3
+ //#region src/getIntlayerAPI/ai.ts
4
+ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
5
+ const AI_API_ROUTE = `${intlayerConfig.editor.backendURL}/api/ai`;
6
+ /**
7
+ * Custom query
8
+ * @param body - Custom query parameters.
9
+ * @returns Custom query result.
10
+ */
11
+ const customQuery = async (body, otherOptions = {}) => await fetcher(AI_API_ROUTE, authAPIOptions, otherOptions, {
12
+ method: "POST",
13
+ body
14
+ });
15
+ /**
16
+ * Translate a JSON
17
+ * @param body - Audit file parameters.
18
+ * @returns Audited file content.
19
+ */
20
+ const translateJSON = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/translate/json`, authAPIOptions, otherOptions, {
21
+ method: "POST",
22
+ body
23
+ });
24
+ /**
25
+ * Audits a content declaration file
26
+ * @param body - Audit file parameters.
27
+ * @returns Audited file content.
28
+ */
29
+ const auditContentDeclaration = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/dictionary`, authAPIOptions, otherOptions, {
30
+ method: "POST",
31
+ body
32
+ });
33
+ /**
34
+ * Audits a content declaration field
35
+ * @param body - Audit file parameters.
36
+ * @returns Audited file content.
37
+ */
38
+ const auditContentDeclarationField = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/dictionary/field`, authAPIOptions, otherOptions, {
39
+ method: "POST",
40
+ body
41
+ });
42
+ /**
43
+ * Audits a content declaration file to retrieve title, description and tags
44
+ * @param body - Audit file parameters.
45
+ * @returns Audited file content.
46
+ */
47
+ const auditContentDeclarationMetadata = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/dictionary/metadata`, authAPIOptions, otherOptions, {
48
+ method: "POST",
49
+ body
50
+ });
51
+ /**
52
+ * Audits a tag
53
+ * @param body - Audit tag parameters.
54
+ * @returns Audited tag content.
55
+ */
56
+ const auditTag = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/audit/tag`, authAPIOptions, otherOptions, {
57
+ method: "POST",
58
+ body
59
+ });
60
+ /**
61
+ * Asks a question to the AI related to the documentation **and streams the
62
+ * answer as Server‑Sent Events (SSE)**.
63
+ *
64
+ * The function **returns immediately** with a handle exposing:
65
+ * - `promise` → resolves when the stream completes (or rejects on error)
66
+ * - `abort()` → allows canceling the request on demand
67
+ *
68
+ * Usage example:
69
+ * ```ts
70
+ * const { promise, abort } = ai.askDocQuestion({
71
+ * ...body,
72
+ * onMessage: console.log,
73
+ * onDone: (full) => console.log("✔", full),
74
+ * });
75
+ * // later → abort();
76
+ * await promise; // waits for completion if desired
77
+ * ```
78
+ */
79
+ const askDocQuestion = async (body, otherOptions = {}) => {
80
+ if (!body) return;
81
+ const { onMessage, onDone, ...rest } = body;
82
+ const abortController = new AbortController();
83
+ try {
84
+ const response = await fetch(`${AI_API_ROUTE}/ask`, {
85
+ method: "POST",
86
+ headers: {
87
+ "Content-Type": "application/json",
88
+ ...authAPIOptions.headers,
89
+ ...otherOptions.headers
90
+ },
91
+ body: JSON.stringify({
92
+ ...rest,
93
+ ...authAPIOptions.body,
94
+ ...otherOptions.body
95
+ }),
96
+ signal: abortController.signal,
97
+ credentials: "include"
98
+ });
99
+ if (!response.ok) {
100
+ let errorMessage = "An error occurred";
101
+ try {
102
+ const errorData = await response.json();
103
+ errorMessage = JSON.stringify(errorData.error) ?? "An error occurred";
104
+ } catch {
105
+ try {
106
+ const errorText = await response.text();
107
+ if (errorText) errorMessage = errorText;
108
+ } catch {}
109
+ }
110
+ throw new Error(errorMessage);
111
+ }
112
+ const reader = response.body?.getReader();
113
+ if (!reader) throw new Error("No reader available");
114
+ const decoder = new TextDecoder();
115
+ let buffer = "";
116
+ while (true) {
117
+ const { done, value } = await reader.read();
118
+ if (done) break;
119
+ buffer += decoder.decode(value, { stream: true });
120
+ const lines = buffer.split("\n");
121
+ buffer = lines.pop() ?? "";
122
+ for (const line of lines) if (line.startsWith("data: ")) try {
123
+ const data = JSON.parse(line.slice(6));
124
+ if (data.chunk) onMessage?.(data.chunk);
125
+ if (data.done && data.response) onDone?.(data.response);
126
+ } catch (e) {
127
+ console.error("Failed to parse SSE data:", e);
128
+ }
129
+ }
130
+ } catch (error) {
131
+ console.error("Error in askDocQuestion:", error);
132
+ throw error;
133
+ }
134
+ };
135
+ const autocomplete = async (body, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/autocomplete`, authAPIOptions, otherOptions, {
136
+ method: "POST",
137
+ body
138
+ });
139
+ /**
140
+ * Retrieves discussions with filters and pagination. Only user or admin can access.
141
+ */
142
+ const getDiscussions = async (params, otherOptions = {}) => await fetcher(`${AI_API_ROUTE}/discussions`, authAPIOptions, otherOptions, {
143
+ method: "GET",
144
+ params
145
+ });
146
+ return {
147
+ customQuery,
148
+ translateJSON,
149
+ auditContentDeclaration,
150
+ auditContentDeclarationField,
151
+ auditContentDeclarationMetadata,
152
+ auditTag,
153
+ askDocQuestion,
154
+ autocomplete,
155
+ getDiscussions
156
+ };
157
+ };
158
+
159
+ //#endregion
160
+ export { getAiAPI };
3
161
  //# sourceMappingURL=ai.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai.mjs","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import type {\n AIOptions,\n AskDocQuestionResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n CustomQueryBody,\n CustomQueryResult,\n GetDiscussionsParams,\n GetDiscussionsResult,\n TranslateJSONBody,\n TranslateJSONResult,\n} from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type AutocompleteBody = {\n text: string;\n aiOptions?: AIOptions;\n contextBefore?: string;\n currentLine?: string;\n contextAfter?: string;\n};\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: AskDocQuestionResult) => void;\n};\n\nexport type { AskDocQuestionResult };\n\nexport const getAiAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\n\n const AI_API_ROUTE = `${backendURL}/api/ai`;\n\n /**\n * Custom query\n * @param body - Custom query parameters.\n * @returns Custom query result.\n */\n const customQuery = async (\n body?: CustomQueryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CustomQueryResult>(\n AI_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Translate a JSON\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const translateJSON = async (\n body?: TranslateJSONBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TranslateJSONResult>(\n `${AI_API_ROUTE}/translate/json`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclaration = async (\n body?: AuditContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationResult>(\n `${AI_API_ROUTE}/audit/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration field\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationField = async (\n body?: AuditContentDeclarationFieldBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationFieldResult>(\n `${AI_API_ROUTE}/audit/dictionary/field`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file to retrieve title, description and tags\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationMetadata = async (\n body?: AuditContentDeclarationMetadataBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationMetadataResult>(\n `${AI_API_ROUTE}/audit/dictionary/metadata`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a tag\n * @param body - Audit tag parameters.\n * @returns Audited tag content.\n */\n const auditTag = async (\n body?: AuditTagBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditTagResult>(\n `${AI_API_ROUTE}/audit/tag`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Asks a question to the AI related to the documentation **and streams the\n * answer as Server‑Sent Events (SSE)**.\n *\n * The function **returns immediately** with a handle exposing:\n * - `promise` → resolves when the stream completes (or rejects on error)\n * - `abort()` → allows canceling the request on demand\n *\n * Usage example:\n * ```ts\n * const { promise, abort } = ai.askDocQuestion({\n * ...body,\n * onMessage: console.log,\n * onDone: (full) => console.log(\"✔\", full),\n * });\n * // later → abort();\n * await promise; // waits for completion if desired\n * ```\n */\n const askDocQuestion = async (\n body?: AskDocQuestionBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body) return;\n\n const { onMessage, onDone, ...rest } = body;\n const abortController = new AbortController();\n\n try {\n const response = await fetch(`${AI_API_ROUTE}/ask`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n body: JSON.stringify({\n ...rest,\n ...authAPIOptions.body,\n ...otherOptions.body,\n }),\n signal: abortController.signal,\n credentials: 'include',\n });\n\n if (!response.ok) {\n // Align error handling with generic `fetcher` utility so that callers receive\n // meaningful messages (e.g. for 429 \"Too Many Requests\" responses).\n let errorMessage: string = 'An error occurred';\n\n try {\n // Attempt to parse JSON error payload produced by backend\n const errorData = await response.json();\n 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":"yCAwCA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CAGH,IAAM,EAAe,GAFF,EAAe,OAAO,WAEN,SA+PnC,MAAO,CACL,YAzPkB,MAClB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,EACA,EACA,EACA,CACE,OAAQ,OACF,OACP,CACF,CA8OD,cAvOoB,MACpB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAa,iBAChB,EACA,EACA,CACE,OAAQ,OACF,OACP,CACF,CA4ND,wBArN8B,MAC9B,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAa,mBAChB,EACA,EACA,CACE,OAAQ,OACF,OACP,CACF,CA0MD,6BAnMmC,MACnC,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAa,yBAChB,EACA,EACA,CACE,OAAQ,OACF,OACP,CACF,CAwLD,gCAjLsC,MACtC,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAa,4BAChB,EACA,EACA,CACE,OAAQ,OACF,OACP,CACF,CAsKD,SA/Je,MACf,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAa,YAChB,EACA,EACA,CACE,OAAQ,OACF,OACP,CACF,CAoJD,eA/HqB,MACrB,EACA,EAA+B,EAAE,GAC9B,CACH,GAAI,CAAC,EAAM,OAEX,GAAM,CAAE,YAAW,SAAQ,GAAG,GAAS,EACjC,EAAkB,IAAI,gBAE5B,GAAI,CACF,IAAM,EAAW,MAAM,MAAM,GAAG,EAAa,MAAO,CAClD,OAAQ,OACR,QAAS,CACP,eAAgB,mBAChB,GAAG,EAAe,QAClB,GAAG,EAAa,QACjB,CACD,KAAM,KAAK,UAAU,CACnB,GAAG,EACH,GAAG,EAAe,KAClB,GAAG,EAAa,KACjB,CAAC,CACF,OAAQ,EAAgB,OACxB,YAAa,UACd,CAAC,CAEF,GAAI,CAAC,EAAS,GAAI,CAGhB,IAAI,EAAuB,oBAE3B,GAAI,CAEF,IAAM,EAAY,MAAM,EAAS,MAAM,CACvC,EAAe,KAAK,UAAU,EAAU,MAAM,EAAI,yBAC5C,CAEN,GAAI,CACF,IAAM,EAAY,MAAM,EAAS,MAAM,CACnC,IACF,EAAe,QAEX,GAKV,MAAU,MAAM,EAAa,CAG/B,IAAM,EAAS,EAAS,MAAM,WAAW,CACzC,GAAI,CAAC,EACH,MAAU,MAAM,sBAAsB,CAGxC,IAAM,EAAU,IAAI,YAChB,EAAS,GAEb,OAAa,CACX,GAAM,CAAE,OAAM,SAAU,MAAM,EAAO,MAAM,CAC3C,GAAI,EAAM,MAEV,GAAU,EAAQ,OAAO,EAAO,CAAE,OAAQ,GAAM,CAAC,CACjD,IAAM,EAAQ,EAAO,MAAM;EAAK,CAChC,EAAS,EAAM,KAAK,EAAI,GAExB,IAAK,IAAM,KAAQ,EACjB,GAAI,EAAK,WAAW,SAAS,CAC3B,GAAI,CACF,IAAM,EAAO,KAAK,MAAM,EAAK,MAAM,EAAE,CAAC,CAClC,EAAK,OACP,IAAY,EAAK,MAAM,CAErB,EAAK,MAAQ,EAAK,UACpB,IAAS,EAAK,SAAS,OAElB,EAAG,CACV,QAAQ,MAAM,4BAA6B,EAAE,SAK9C,EAAO,CAEd,MADA,QAAQ,MAAM,2BAA4B,EAAM,CAC1C,IA4CR,aAxCmB,MACnB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAa,eAChB,EACA,EACA,CACE,OAAQ,OACF,OACP,CACF,CA6BD,eAxBqB,MACrB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAa,cAChB,EACA,EACA,CACE,OAAQ,MAER,SACD,CACF,CAYF"}
1
+ {"version":3,"file":"ai.mjs","names":[],"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import type {\n AIOptions,\n AskDocQuestionResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n CustomQueryBody,\n CustomQueryResult,\n GetDiscussionsParams,\n GetDiscussionsResult,\n TranslateJSONBody,\n TranslateJSONResult,\n} from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type AutocompleteBody = {\n text: string;\n aiOptions?: AIOptions;\n contextBefore?: string;\n currentLine?: string;\n contextAfter?: string;\n};\n\nexport type AskDocQuestionBody = {\n messages: ChatCompletionRequestMessage[];\n discussionId: string;\n onMessage?: (chunk: string) => void;\n onDone?: (response: AskDocQuestionResult) => void;\n};\n\nexport type { AskDocQuestionResult };\n\nexport const getAiAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\n\n const AI_API_ROUTE = `${backendURL}/api/ai`;\n\n /**\n * Custom query\n * @param body - Custom query parameters.\n * @returns Custom query result.\n */\n const customQuery = async (\n body?: CustomQueryBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CustomQueryResult>(\n AI_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Translate a JSON\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const translateJSON = async (\n body?: TranslateJSONBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<TranslateJSONResult>(\n `${AI_API_ROUTE}/translate/json`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclaration = async (\n body?: AuditContentDeclarationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationResult>(\n `${AI_API_ROUTE}/audit/dictionary`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration field\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationField = async (\n body?: AuditContentDeclarationFieldBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationFieldResult>(\n `${AI_API_ROUTE}/audit/dictionary/field`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a content declaration file to retrieve title, description and tags\n * @param body - Audit file parameters.\n * @returns Audited file content.\n */\n const auditContentDeclarationMetadata = async (\n body?: AuditContentDeclarationMetadataBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditContentDeclarationMetadataResult>(\n `${AI_API_ROUTE}/audit/dictionary/metadata`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Audits a tag\n * @param body - Audit tag parameters.\n * @returns Audited tag content.\n */\n const auditTag = async (\n body?: AuditTagBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AuditTagResult>(\n `${AI_API_ROUTE}/audit/tag`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: body,\n }\n );\n\n /**\n * Asks a question to the AI related to the documentation **and streams the\n * answer as Server‑Sent Events (SSE)**.\n *\n * The function **returns immediately** with a handle exposing:\n * - `promise` → resolves when the stream completes (or rejects on error)\n * - `abort()` → allows canceling the request on demand\n *\n * Usage example:\n * ```ts\n * const { promise, abort } = ai.askDocQuestion({\n * ...body,\n * onMessage: console.log,\n * onDone: (full) => console.log(\"✔\", full),\n * });\n * // later → abort();\n * await promise; // waits for completion if desired\n * ```\n */\n const askDocQuestion = async (\n body?: AskDocQuestionBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body) return;\n\n const { onMessage, onDone, ...rest } = body;\n const abortController = new AbortController();\n\n try {\n const response = await fetch(`${AI_API_ROUTE}/ask`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n body: JSON.stringify({\n ...rest,\n ...authAPIOptions.body,\n ...otherOptions.body,\n }),\n signal: abortController.signal,\n credentials: 'include',\n });\n\n if (!response.ok) {\n // Align error handling with generic `fetcher` utility so that callers receive\n // meaningful messages (e.g. for 429 \"Too Many Requests\" responses).\n let errorMessage: string = 'An error occurred';\n\n try {\n // Attempt to parse JSON error payload produced by backend\n const errorData = await response.json();\n 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":";;;AAwCA,MAAa,YACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,eAAe,GAFF,eAAe,OAAO,WAEN;;;;;;CAOnC,MAAM,cAAc,OAClB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,cACA,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,gBAAgB,OACpB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,kBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,0BAA0B,OAC9B,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,oBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,+BAA+B,OACnC,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,0BAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,kCAAkC,OACtC,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,6BAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;CAOH,MAAM,WAAW,OACf,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,aAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;;;;;;;;;;;;;;;;;CAqBH,MAAM,iBAAiB,OACrB,MACA,eAA+B,EAAE,KAC9B;AACH,MAAI,CAAC,KAAM;EAEX,MAAM,EAAE,WAAW,QAAQ,GAAG,SAAS;EACvC,MAAM,kBAAkB,IAAI,iBAAiB;AAE7C,MAAI;GACF,MAAM,WAAW,MAAM,MAAM,GAAG,aAAa,OAAO;IAClD,QAAQ;IACR,SAAS;KACP,gBAAgB;KAChB,GAAG,eAAe;KAClB,GAAG,aAAa;KACjB;IACD,MAAM,KAAK,UAAU;KACnB,GAAG;KACH,GAAG,eAAe;KAClB,GAAG,aAAa;KACjB,CAAC;IACF,QAAQ,gBAAgB;IACxB,aAAa;IACd,CAAC;AAEF,OAAI,CAAC,SAAS,IAAI;IAGhB,IAAI,eAAuB;AAE3B,QAAI;KAEF,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,oBAAe,KAAK,UAAU,UAAU,MAAM,IAAI;YAC5C;AAEN,SAAI;MACF,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,UAAI,UACF,gBAAe;aAEX;;AAKV,UAAM,IAAI,MAAM,aAAa;;GAG/B,MAAM,SAAS,SAAS,MAAM,WAAW;AACzC,OAAI,CAAC,OACH,OAAM,IAAI,MAAM,sBAAsB;GAGxC,MAAM,UAAU,IAAI,aAAa;GACjC,IAAI,SAAS;AAEb,UAAO,MAAM;IACX,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAC3C,QAAI,KAAM;AAEV,cAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,MAAM,CAAC;IACjD,MAAM,QAAQ,OAAO,MAAM,KAAK;AAChC,aAAS,MAAM,KAAK,IAAI;AAExB,SAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,WAAW,SAAS,CAC3B,KAAI;KACF,MAAM,OAAO,KAAK,MAAM,KAAK,MAAM,EAAE,CAAC;AACtC,SAAI,KAAK,MACP,aAAY,KAAK,MAAM;AAEzB,SAAI,KAAK,QAAQ,KAAK,SACpB,UAAS,KAAK,SAAS;aAElB,GAAG;AACV,aAAQ,MAAM,6BAA6B,EAAE;;;WAK9C,OAAO;AACd,WAAQ,MAAM,4BAA4B,MAAM;AAChD,SAAM;;;CAIV,MAAM,eAAe,OACnB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,gBAChB,gBACA,cACA;EACE,QAAQ;EACF;EACP,CACF;;;;CAKH,MAAM,iBAAiB,OACrB,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,aAAa,eAChB,gBACA,cACA;EACE,QAAQ;EAER;EACD,CACF;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,3 +1,94 @@
1
- import{fetcher as e}from"../fetcher.mjs";const t=(t={},n)=>{let r=`${n.editor.backendURL}/api/scan`;return{discoverUrls:async(n,i={})=>await e(`${r}/recursive/discover`,t,i,{method:`GET`,params:n}),scanUrl:async(e,n={})=>{if(!e?.url)return;let{url:i,onMessage:a,onDone:o}=e,s=`${r}?${new URLSearchParams({url:i}).toString()}`,c=await fetch(s,{method:`GET`,headers:{Accept:`text/event-stream`,...t.headers,...n.headers},credentials:`include`,signal:n.signal});if(!c.ok){let e=`An error occurred`;try{let t=await c.json();e=JSON.stringify(t.error)??e}catch{try{let t=await c.text();t&&(e=t)}catch{}}throw Error(e)}let l=c.body?.getReader();if(!l)throw Error(`No reader available`);let u=new TextDecoder,d=``;for(;;){let{done:e,value:t}=await l.read();if(e)break;d+=u.decode(t,{stream:!0});let n=d.split(`
2
- `);d=n.pop()??``;for(let e of n)if(e.startsWith(`data: `))try{let t=JSON.parse(e.slice(6));a?.(t)}catch{}}o?.()},startRecursiveAudit:async(n,i={})=>await e(`${r}/recursive/start`,t,i,{method:`POST`,params:n?.url?{url:n.url}:void 0,body:n?.urls===void 0?void 0:{urls:n.urls}}),getRecursiveAuditStatus:async(n,i={})=>await e(`${r}/recursive/${n?.jobId}`,t,i,{method:`GET`}),cancelRecursiveAudit:async(n,i={})=>await e(`${r}/recursive/${n?.jobId}/cancel`,t,i,{method:`POST`}),pauseRecursiveAudit:async(n,i={})=>await e(`${r}/recursive/${n?.jobId}/pause`,t,i,{method:`POST`}),resumeRecursiveAudit:async(n,i={})=>await e(`${r}/recursive/${n?.jobId}/resume`,t,i,{method:`POST`})}};export{t as getAuditAPI};
1
+ import { fetcher } from "../fetcher.mjs";
2
+
3
+ //#region src/getIntlayerAPI/audit.ts
4
+ const getAuditAPI = (authAPIOptions = {}, intlayerConfig) => {
5
+ const AUDIT_API_ROUTE = `${intlayerConfig.editor.backendURL}/api/scan`;
6
+ /**
7
+ * Streams a single-page SEO audit as Server-Sent Events.
8
+ *
9
+ * Usage:
10
+ * ```ts
11
+ * await audit.scanUrl({
12
+ * url: 'https://example.com',
13
+ * onMessage: (event) => console.log(event),
14
+ * onDone: () => console.log('done'),
15
+ * });
16
+ * ```
17
+ */
18
+ const discoverUrls = async (params, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}/recursive/discover`, authAPIOptions, otherOptions, {
19
+ method: "GET",
20
+ params
21
+ });
22
+ const scanUrl = async (body, otherOptions = {}) => {
23
+ if (!body?.url) return;
24
+ const { url, onMessage, onDone } = body;
25
+ const endpoint = `${AUDIT_API_ROUTE}?${new URLSearchParams({ url }).toString()}`;
26
+ const response = await fetch(endpoint, {
27
+ method: "GET",
28
+ headers: {
29
+ Accept: "text/event-stream",
30
+ ...authAPIOptions.headers,
31
+ ...otherOptions.headers
32
+ },
33
+ credentials: "include",
34
+ signal: otherOptions.signal
35
+ });
36
+ if (!response.ok) {
37
+ let errorMessage = "An error occurred";
38
+ try {
39
+ const errorData = await response.json();
40
+ errorMessage = JSON.stringify(errorData.error) ?? errorMessage;
41
+ } catch {
42
+ try {
43
+ const errorText = await response.text();
44
+ if (errorText) errorMessage = errorText;
45
+ } catch {}
46
+ }
47
+ throw new Error(errorMessage);
48
+ }
49
+ const reader = response.body?.getReader();
50
+ if (!reader) throw new Error("No reader available");
51
+ const decoder = new TextDecoder();
52
+ let buffer = "";
53
+ while (true) {
54
+ const { done, value } = await reader.read();
55
+ if (done) break;
56
+ buffer += decoder.decode(value, { stream: true });
57
+ const lines = buffer.split("\n");
58
+ buffer = lines.pop() ?? "";
59
+ for (const line of lines) if (line.startsWith("data: ")) try {
60
+ const event = JSON.parse(line.slice(6));
61
+ onMessage?.(event);
62
+ } catch {}
63
+ }
64
+ onDone?.();
65
+ };
66
+ /**
67
+ * Starts a recursive audit job for the given URL.
68
+ */
69
+ const startRecursiveAudit = async (body, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}/recursive/start`, authAPIOptions, otherOptions, {
70
+ method: "POST",
71
+ params: body?.url ? { url: body.url } : void 0,
72
+ body: body?.urls !== void 0 ? { urls: body.urls } : void 0
73
+ });
74
+ /**
75
+ * Gets the status of a recursive audit job.
76
+ */
77
+ const getRecursiveAuditStatus = async (params, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}`, authAPIOptions, otherOptions, { method: "GET" });
78
+ const cancelRecursiveAudit = async (params, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}/cancel`, authAPIOptions, otherOptions, { method: "POST" });
79
+ const pauseRecursiveAudit = async (params, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}/pause`, authAPIOptions, otherOptions, { method: "POST" });
80
+ const resumeRecursiveAudit = async (params, otherOptions = {}) => await fetcher(`${AUDIT_API_ROUTE}/recursive/${params?.jobId}/resume`, authAPIOptions, otherOptions, { method: "POST" });
81
+ return {
82
+ discoverUrls,
83
+ scanUrl,
84
+ startRecursiveAudit,
85
+ getRecursiveAuditStatus,
86
+ cancelRecursiveAudit,
87
+ pauseRecursiveAudit,
88
+ resumeRecursiveAudit
89
+ };
90
+ };
91
+
92
+ //#endregion
93
+ export { getAuditAPI };
3
94
  //# sourceMappingURL=audit.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"audit.mjs","names":[],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n} from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n};\n\nexport type ScanUrlBody = {\n url: string;\n onMessage?: (event: AuditEvent) => void;\n onDone?: () => void;\n};\n\nexport type DiscoverUrlsParams = {\n url: string;\n};\n\nexport type DiscoverUrlsResult = {\n urls: string[];\n};\n\nexport type StartRecursiveAuditBody = {\n url: string;\n urls?: string[];\n};\n\nexport type GetRecursiveAuditStatusParams = {\n jobId: string;\n};\n\nexport type RecursiveAuditJobParams = {\n jobId: string;\n};\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\n\n const AUDIT_API_ROUTE = `${backendURL}/api/scan`;\n\n /**\n * Streams a single-page SEO audit as Server-Sent Events.\n *\n * Usage:\n * ```ts\n * await audit.scanUrl({\n * url: 'https://example.com',\n * onMessage: (event) => console.log(event),\n * onDone: () => console.log('done'),\n * });\n * ```\n */\n const discoverUrls = async (\n params?: DiscoverUrlsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DiscoverUrlsResult>(\n `${AUDIT_API_ROUTE}/recursive/discover`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n params,\n }\n );\n\n const scanUrl = async (\n body?: ScanUrlBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body?.url) return;\n\n const { url, onMessage, onDone } = body;\n\n const params = new URLSearchParams({ url });\n const endpoint = `${AUDIT_API_ROUTE}?${params.toString()}`;\n\n const response = await fetch(endpoint, {\n method: 'GET',\n headers: {\n Accept: 'text/event-stream',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n credentials: 'include',\n signal: otherOptions.signal,\n });\n\n if (!response.ok) {\n let errorMessage = 'An error occurred';\n try {\n const errorData = await response.json();\n errorMessage = JSON.stringify(errorData.error) ?? errorMessage;\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) errorMessage = errorText;\n } catch {\n // ignore\n }\n }\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const event = JSON.parse(line.slice(6)) as AuditEvent;\n onMessage?.(event);\n } catch {\n // ignore malformed lines\n }\n }\n }\n }\n\n onDone?.();\n };\n\n /**\n * Starts a recursive audit job for the given URL.\n */\n const startRecursiveAudit = async (\n body?: StartRecursiveAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<StartRecursiveAuditResult>(\n `${AUDIT_API_ROUTE}/recursive/start`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n params: body?.url ? { url: body.url } : undefined,\n body: body?.urls !== undefined ? { urls: body.urls as any } : undefined,\n }\n );\n\n /**\n * Gets the status of a recursive audit job.\n */\n const getRecursiveAuditStatus = async (\n params?: GetRecursiveAuditStatusParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetRecursiveAuditStatusResult>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n const cancelRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/cancel`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const pauseRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/pause`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const resumeRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/resume`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n return {\n discoverUrls,\n scanUrl,\n startRecursiveAudit,\n getRecursiveAuditStatus,\n cancelRecursiveAudit,\n pauseRecursiveAudit,\n resumeRecursiveAudit,\n };\n};\n"],"mappings":"yCAyCA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CAGH,IAAM,EAAkB,GAFL,EAAe,OAAO,WAEH,WAmKtC,MAAO,CACL,aAtJmB,MACnB,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAgB,qBACnB,EACA,EACA,CACE,OAAQ,MACR,SACD,CACF,CA2ID,QAzIc,MACd,EACA,EAA+B,EAAE,GAC9B,CACH,GAAI,CAAC,GAAM,IAAK,OAEhB,GAAM,CAAE,MAAK,YAAW,UAAW,EAG7B,EAAW,GAAG,EAAgB,GADrB,IAAI,gBAAgB,CAAE,MAAK,CAAC,CACG,UAAU,GAElD,EAAW,MAAM,MAAM,EAAU,CACrC,OAAQ,MACR,QAAS,CACP,OAAQ,oBACR,GAAG,EAAe,QAClB,GAAG,EAAa,QACjB,CACD,YAAa,UACb,OAAQ,EAAa,OACtB,CAAC,CAEF,GAAI,CAAC,EAAS,GAAI,CAChB,IAAI,EAAe,oBACnB,GAAI,CACF,IAAM,EAAY,MAAM,EAAS,MAAM,CACvC,EAAe,KAAK,UAAU,EAAU,MAAM,EAAI,OAC5C,CACN,GAAI,CACF,IAAM,EAAY,MAAM,EAAS,MAAM,CACnC,IAAW,EAAe,QACxB,GAIV,MAAU,MAAM,EAAa,CAG/B,IAAM,EAAS,EAAS,MAAM,WAAW,CACzC,GAAI,CAAC,EAAQ,MAAU,MAAM,sBAAsB,CAEnD,IAAM,EAAU,IAAI,YAChB,EAAS,GAEb,OAAa,CACX,GAAM,CAAE,OAAM,SAAU,MAAM,EAAO,MAAM,CAE3C,GAAI,EAAM,MAEV,GAAU,EAAQ,OAAO,EAAO,CAAE,OAAQ,GAAM,CAAC,CACjD,IAAM,EAAQ,EAAO,MAAM;EAAK,CAChC,EAAS,EAAM,KAAK,EAAI,GAExB,IAAK,IAAM,KAAQ,EACjB,GAAI,EAAK,WAAW,SAAS,CAC3B,GAAI,CACF,IAAM,EAAQ,KAAK,MAAM,EAAK,MAAM,EAAE,CAAC,CACvC,IAAY,EAAM,MACZ,GAOd,KAAU,EAyEV,oBAnE0B,MAC1B,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAgB,kBACnB,EACA,EACA,CACE,OAAQ,OACR,OAAQ,GAAM,IAAM,CAAE,IAAK,EAAK,IAAK,CAAG,IAAA,GACxC,KAAM,GAAM,OAAS,IAAA,GAAyC,IAAA,GAA7B,CAAE,KAAM,EAAK,KAAa,CAC5D,CACF,CAuDD,wBAlD8B,MAC9B,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAgB,aAAa,GAAQ,QACxC,EACA,EACA,CACE,OAAQ,MACT,CACF,CAwCD,qBAtC2B,MAC3B,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAgB,aAAa,GAAQ,MAAM,SAC9C,EACA,EACA,CAAE,OAAQ,OAAQ,CACnB,CA8BD,oBA5B0B,MAC1B,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAgB,aAAa,GAAQ,MAAM,QAC9C,EACA,EACA,CAAE,OAAQ,OAAQ,CACnB,CAoBD,qBAlB2B,MAC3B,EACA,EAA+B,EAAE,GAEjC,MAAM,EACJ,GAAG,EAAgB,aAAa,GAAQ,MAAM,SAC9C,EACA,EACA,CAAE,OAAQ,OAAQ,CACnB,CAUF"}
1
+ {"version":3,"file":"audit.mjs","names":[],"sources":["../../../src/getIntlayerAPI/audit.ts"],"sourcesContent":["import type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n} from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type {\n AuditEvent,\n GetRecursiveAuditStatusResult,\n StartRecursiveAuditResult,\n};\n\nexport type ScanUrlBody = {\n url: string;\n onMessage?: (event: AuditEvent) => void;\n onDone?: () => void;\n};\n\nexport type DiscoverUrlsParams = {\n url: string;\n};\n\nexport type DiscoverUrlsResult = {\n urls: string[];\n};\n\nexport type StartRecursiveAuditBody = {\n url: string;\n urls?: string[];\n};\n\nexport type GetRecursiveAuditStatusParams = {\n jobId: string;\n};\n\nexport type RecursiveAuditJobParams = {\n jobId: string;\n};\n\nexport const getAuditAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\n\n const AUDIT_API_ROUTE = `${backendURL}/api/scan`;\n\n /**\n * Streams a single-page SEO audit as Server-Sent Events.\n *\n * Usage:\n * ```ts\n * await audit.scanUrl({\n * url: 'https://example.com',\n * onMessage: (event) => console.log(event),\n * onDone: () => console.log('done'),\n * });\n * ```\n */\n const discoverUrls = async (\n params?: DiscoverUrlsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DiscoverUrlsResult>(\n `${AUDIT_API_ROUTE}/recursive/discover`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n params,\n }\n );\n\n const scanUrl = async (\n body?: ScanUrlBody,\n otherOptions: FetcherOptions = {}\n ) => {\n if (!body?.url) return;\n\n const { url, onMessage, onDone } = body;\n\n const params = new URLSearchParams({ url });\n const endpoint = `${AUDIT_API_ROUTE}?${params.toString()}`;\n\n const response = await fetch(endpoint, {\n method: 'GET',\n headers: {\n Accept: 'text/event-stream',\n ...authAPIOptions.headers,\n ...otherOptions.headers,\n },\n credentials: 'include',\n signal: otherOptions.signal,\n });\n\n if (!response.ok) {\n let errorMessage = 'An error occurred';\n try {\n const errorData = await response.json();\n errorMessage = JSON.stringify(errorData.error) ?? errorMessage;\n } catch {\n try {\n const errorText = await response.text();\n if (errorText) errorMessage = errorText;\n } catch {\n // ignore\n }\n }\n throw new Error(errorMessage);\n }\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (line.startsWith('data: ')) {\n try {\n const event = JSON.parse(line.slice(6)) as AuditEvent;\n onMessage?.(event);\n } catch {\n // ignore malformed lines\n }\n }\n }\n }\n\n onDone?.();\n };\n\n /**\n * Starts a recursive audit job for the given URL.\n */\n const startRecursiveAudit = async (\n body?: StartRecursiveAuditBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<StartRecursiveAuditResult>(\n `${AUDIT_API_ROUTE}/recursive/start`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n params: body?.url ? { url: body.url } : undefined,\n body: body?.urls !== undefined ? { urls: body.urls as any } : undefined,\n }\n );\n\n /**\n * Gets the status of a recursive audit job.\n */\n const getRecursiveAuditStatus = async (\n params?: GetRecursiveAuditStatusParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetRecursiveAuditStatusResult>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n const cancelRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/cancel`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const pauseRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/pause`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n const resumeRecursiveAudit = async (\n params?: RecursiveAuditJobParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<{ success: boolean }>(\n `${AUDIT_API_ROUTE}/recursive/${params?.jobId}/resume`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n return {\n discoverUrls,\n scanUrl,\n startRecursiveAudit,\n getRecursiveAuditStatus,\n cancelRecursiveAudit,\n pauseRecursiveAudit,\n resumeRecursiveAudit,\n };\n};\n"],"mappings":";;;AAyCA,MAAa,eACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,kBAAkB,GAFL,eAAe,OAAO,WAEH;;;;;;;;;;;;;CActC,MAAM,eAAe,OACnB,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,sBACnB,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;CAEH,MAAM,UAAU,OACd,MACA,eAA+B,EAAE,KAC9B;AACH,MAAI,CAAC,MAAM,IAAK;EAEhB,MAAM,EAAE,KAAK,WAAW,WAAW;EAGnC,MAAM,WAAW,GAAG,gBAAgB,GADrB,IAAI,gBAAgB,EAAE,KAAK,CAAC,CACG,UAAU;EAExD,MAAM,WAAW,MAAM,MAAM,UAAU;GACrC,QAAQ;GACR,SAAS;IACP,QAAQ;IACR,GAAG,eAAe;IAClB,GAAG,aAAa;IACjB;GACD,aAAa;GACb,QAAQ,aAAa;GACtB,CAAC;AAEF,MAAI,CAAC,SAAS,IAAI;GAChB,IAAI,eAAe;AACnB,OAAI;IACF,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,mBAAe,KAAK,UAAU,UAAU,MAAM,IAAI;WAC5C;AACN,QAAI;KACF,MAAM,YAAY,MAAM,SAAS,MAAM;AACvC,SAAI,UAAW,gBAAe;YACxB;;AAIV,SAAM,IAAI,MAAM,aAAa;;EAG/B,MAAM,SAAS,SAAS,MAAM,WAAW;AACzC,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,sBAAsB;EAEnD,MAAM,UAAU,IAAI,aAAa;EACjC,IAAI,SAAS;AAEb,SAAO,MAAM;GACX,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAE3C,OAAI,KAAM;AAEV,aAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,MAAM,CAAC;GACjD,MAAM,QAAQ,OAAO,MAAM,KAAK;AAChC,YAAS,MAAM,KAAK,IAAI;AAExB,QAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,WAAW,SAAS,CAC3B,KAAI;IACF,MAAM,QAAQ,KAAK,MAAM,KAAK,MAAM,EAAE,CAAC;AACvC,gBAAY,MAAM;WACZ;;AAOd,YAAU;;;;;CAMZ,MAAM,sBAAsB,OAC1B,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,mBACnB,gBACA,cACA;EACE,QAAQ;EACR,QAAQ,MAAM,MAAM,EAAE,KAAK,KAAK,KAAK,GAAG;EACxC,MAAM,MAAM,SAAS,SAAY,EAAE,MAAM,KAAK,MAAa,GAAG;EAC/D,CACF;;;;CAKH,MAAM,0BAA0B,OAC9B,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,aAAa,QAAQ,SACxC,gBACA,cACA,EACE,QAAQ,OACT,CACF;CAEH,MAAM,uBAAuB,OAC3B,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,aAAa,QAAQ,MAAM,UAC9C,gBACA,cACA,EAAE,QAAQ,QAAQ,CACnB;CAEH,MAAM,sBAAsB,OAC1B,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,aAAa,QAAQ,MAAM,SAC9C,gBACA,cACA,EAAE,QAAQ,QAAQ,CACnB;CAEH,MAAM,uBAAuB,OAC3B,QACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,gBAAgB,aAAa,QAAQ,MAAM,UAC9C,gBACA,cACA,EAAE,QAAQ,QAAQ,CACnB;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,2 +1,69 @@
1
- import{fetcher as e}from"../fetcher.mjs";const t=(t={},n)=>{let r=`${n.editor.backendURL}/api/bitbucket`;return{getAuthUrl:async(n,i={})=>await e(`${r}/auth-url`,t,i,{params:{redirectUri:n}}),authenticate:async(n,i={})=>await e(`${r}/auth`,t,i,{method:`POST`,body:{code:n}}),getRepositories:async(n,i={})=>await e(`${r}/repos`,t,i,{params:n?{token:n}:void 0}),checkIntlayerConfig:async(n,i,a,o=`main`,s={})=>await e(`${r}/check-config`,t,s,{method:`POST`,body:{token:n??void 0,workspace:i,repoSlug:a,branch:o}}),getConfigFile:async(n,i,a,o=`main`,s=`intlayer.config.ts`,c={})=>await e(`${r}/get-config-file`,t,c,{method:`POST`,body:{token:n??void 0,workspace:i,repoSlug:a,branch:o,path:s}})}};export{t as getBitbucketAPI};
1
+ import { fetcher } from "../fetcher.mjs";
2
+
3
+ //#region src/getIntlayerAPI/bitbucket.ts
4
+ const getBitbucketAPI = (authAPIOptions = {}, intlayerConfig) => {
5
+ const BITBUCKET_API_ROUTE = `${intlayerConfig.editor.backendURL}/api/bitbucket`;
6
+ /**
7
+ * Get Bitbucket OAuth authorization URL
8
+ * @param redirectUri - Redirect URI after OAuth authorization
9
+ */
10
+ const getAuthUrl = async (redirectUri, otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/auth-url`, authAPIOptions, otherOptions, { params: { redirectUri } });
11
+ /**
12
+ * Exchange Bitbucket authorization code for access token
13
+ * @param code - Bitbucket authorization code
14
+ */
15
+ const authenticate = async (code, otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/auth`, authAPIOptions, otherOptions, {
16
+ method: "POST",
17
+ body: { code }
18
+ });
19
+ /**
20
+ * Get user's Bitbucket repositories
21
+ * @param token - Optional Bitbucket access token. If not provided, backend will use session.
22
+ */
23
+ const getRepositories = async (token, otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/repos`, authAPIOptions, otherOptions, { params: token ? { token } : void 0 });
24
+ /**
25
+ * Check if intlayer.config.ts exists in a Bitbucket repository
26
+ * @param token - Optional Bitbucket access token. If not provided, backend will use session.
27
+ * @param workspace - Bitbucket workspace slug
28
+ * @param repoSlug - Repository slug
29
+ * @param branch - Branch name (default: 'main')
30
+ */
31
+ const checkIntlayerConfig = async (token, workspace, repoSlug, branch = "main", otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/check-config`, authAPIOptions, otherOptions, {
32
+ method: "POST",
33
+ body: {
34
+ token: token ?? void 0,
35
+ workspace,
36
+ repoSlug,
37
+ branch
38
+ }
39
+ });
40
+ /**
41
+ * Get intlayer.config.ts file contents from a Bitbucket repository
42
+ * @param token - Optional Bitbucket access token. If not provided, backend will use session.
43
+ * @param workspace - Bitbucket workspace slug
44
+ * @param repoSlug - Repository slug
45
+ * @param branch - Branch name (default: 'main')
46
+ * @param path - File path (default: 'intlayer.config.ts')
47
+ */
48
+ const getConfigFile = async (token, workspace, repoSlug, branch = "main", path = "intlayer.config.ts", otherOptions = {}) => await fetcher(`${BITBUCKET_API_ROUTE}/get-config-file`, authAPIOptions, otherOptions, {
49
+ method: "POST",
50
+ body: {
51
+ token: token ?? void 0,
52
+ workspace,
53
+ repoSlug,
54
+ branch,
55
+ path
56
+ }
57
+ });
58
+ return {
59
+ getAuthUrl,
60
+ authenticate,
61
+ getRepositories,
62
+ checkIntlayerConfig,
63
+ getConfigFile
64
+ };
65
+ };
66
+
67
+ //#endregion
68
+ export { getBitbucketAPI };
2
69
  //# sourceMappingURL=bitbucket.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bitbucket.mjs","names":[],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\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":"yCA+EA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CAGH,IAAM,EAAsB,GAFT,EAAe,OAAO,WAEC,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
+ {"version":3,"file":"bitbucket.mjs","names":[],"sources":["../../../src/getIntlayerAPI/bitbucket.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type BitbucketRepository = {\n uuid: string;\n name: string;\n full_name: string;\n slug: string;\n mainbranch?: {\n name: string;\n type: string;\n };\n links: {\n html: {\n href: string;\n };\n };\n workspace: {\n slug: string;\n name: string;\n uuid: string;\n };\n owner: {\n display_name: string;\n username?: string;\n uuid: string;\n };\n updated_on: string;\n is_private: boolean;\n};\n\nexport type BitbucketAuthCallbackBody = {\n code: string;\n};\n\nexport type BitbucketAuthCallbackResult = {\n data: {\n token: string;\n };\n};\n\nexport type BitbucketListReposResult = {\n data: BitbucketRepository[];\n};\n\nexport type BitbucketCheckConfigBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n};\n\nexport type BitbucketCheckConfigResult = {\n data: {\n hasConfig: boolean;\n configPaths: string[];\n };\n};\n\nexport type BitbucketGetConfigFileBody = {\n token?: string;\n workspace: string;\n repoSlug: string;\n branch?: string;\n path?: string;\n};\n\nexport type BitbucketGetConfigFileResult = {\n data: {\n content: string;\n };\n};\n\nexport type BitbucketGetAuthUrlResult = {\n data: {\n authUrl: string;\n };\n};\n\nexport const getBitbucketAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\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":";;;AA+EA,MAAa,mBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,sBAAsB,GAFT,eAAe,OAAO,WAEC;;;;;CAM1C,MAAM,aAAa,OACjB,aACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,YACvB,gBACA,cACA,EACE,QAAQ,EAAE,aAAa,EACxB,CACF;;;;;CAMH,MAAM,eAAe,OACnB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,QACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM,EAAE,MAAM;EACf,CACF;;;;;CAMH,MAAM,kBAAkB,OACtB,OACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,SACvB,gBACA,cACA,EACE,QAAQ,QAAQ,EAAE,OAAO,GAAG,QAC7B,CACF;;;;;;;;CASH,MAAM,sBAAsB,OAC1B,OACA,WACA,UACA,SAAiB,QACjB,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,gBACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;GAAE,OAAO,SAAS;GAAW;GAAW;GAAU;GAAQ;EACjE,CACF;;;;;;;;;CAUH,MAAM,gBAAgB,OACpB,OACA,WACA,UACA,SAAiB,QACjB,OAAe,sBACf,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,oBAAoB,mBACvB,gBACA,cACA;EACE,QAAQ;EACR,MAAM;GACJ,OAAO,SAAS;GAChB;GACA;GACA;GACA;GACD;EACF,CACF;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACD"}
@@ -1,2 +1,67 @@
1
- import{fetcher as e}from"../fetcher.mjs";const t=(t={},n)=>{let r=`${n.editor.backendURL}/api/dictionary`;return{getDictionaries:async(n,i={})=>await e(r,t,i,{cache:`no-store`,params:n}),getDictionariesKeys:async(n={})=>await e(`${r}/keys`,t,n,{cache:`no-store`}),getDictionariesUpdateTimestamp:async(n={})=>await e(`${r}/update`,t,n,{cache:`no-store`}),getDictionary:async(n,i,a={})=>await e(`${r}/${n}`,t,a,{params:i?{version:i.toString()}:void 0}),pushDictionaries:async(n,i={})=>await e(`${r}`,t,i,{method:`PATCH`,body:{dictionaries:n}}),addDictionary:async(n,i={})=>await e(`${r}`,t,i,{method:`POST`,body:n}),updateDictionary:async(n,i={})=>await e(`${r}/${n.id}`,t,i,{method:`PUT`,body:n}),deleteDictionary:async(n,i={})=>await e(`${r}/${n}`,t,i,{method:`DELETE`})}};export{t as getDictionaryAPI};
1
+ import { fetcher } from "../fetcher.mjs";
2
+
3
+ //#region src/getIntlayerAPI/dictionary.ts
4
+ const getDictionaryAPI = (authAPIOptions = {}, intlayerConfig) => {
5
+ const PROJECT_API_ROUTE = `${intlayerConfig.editor.backendURL}/api/dictionary`;
6
+ /**
7
+ * Retrieves a list of dictionaries based on filters and pagination.
8
+ * @param filters - Filters and pagination options.
9
+ */
10
+ const getDictionaries = async (filters, otherOptions = {}) => await fetcher(PROJECT_API_ROUTE, authAPIOptions, otherOptions, {
11
+ cache: "no-store",
12
+ params: filters
13
+ });
14
+ /**
15
+ * Retrieves a list of dictionary keys related to the project.
16
+ */
17
+ const getDictionariesKeys = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/keys`, authAPIOptions, otherOptions, { cache: "no-store" });
18
+ /**
19
+ * Retrieves a list of dictionary keys related to the project.
20
+ */
21
+ const getDictionariesUpdateTimestamp = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/update`, authAPIOptions, otherOptions, { cache: "no-store" });
22
+ /**
23
+ * Retrieves a dictionary by its key and version.
24
+ * @param dictionaryKey - Dictionary key.
25
+ * @param version - Dictionary version of content.
26
+ */
27
+ const getDictionary = async (dictionaryKey, version, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${dictionaryKey}`, authAPIOptions, otherOptions, { params: version ? { version: version.toString() } : void 0 });
28
+ /**
29
+ * Adds a new dictionary to the database.
30
+ * @param dictionary - Dictionary data.
31
+ */
32
+ const addDictionary = async (body, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
33
+ method: "POST",
34
+ body
35
+ });
36
+ const pushDictionaries = async (dictionaries, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
37
+ method: "PATCH",
38
+ body: { dictionaries }
39
+ });
40
+ /**
41
+ * Updates an existing dictionary in the database.
42
+ * @param dictionary - Updated dictionary data.
43
+ */
44
+ const updateDictionary = async (dictionary, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${dictionary.id}`, authAPIOptions, otherOptions, {
45
+ method: "PUT",
46
+ body: dictionary
47
+ });
48
+ /**
49
+ * Deletes a dictionary from the database by its ID.
50
+ * @param id - Dictionary ID.
51
+ */
52
+ const deleteDictionary = async (id, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${id}`, authAPIOptions, otherOptions, { method: "DELETE" });
53
+ return {
54
+ getDictionaries,
55
+ getDictionariesKeys,
56
+ getDictionariesUpdateTimestamp,
57
+ getDictionary,
58
+ pushDictionaries,
59
+ addDictionary,
60
+ updateDictionary,
61
+ deleteDictionary
62
+ };
63
+ };
64
+
65
+ //#endregion
66
+ export { getDictionaryAPI };
2
67
  //# sourceMappingURL=dictionary.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n} from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\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":"yCAoBA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CAGH,IAAM,EAAoB,GAFP,EAAe,OAAO,WAED,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
+ {"version":3,"file":"dictionary.mjs","names":[],"sources":["../../../src/getIntlayerAPI/dictionary.ts"],"sourcesContent":["import type {\n AddDictionaryBody,\n AddDictionaryResult,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionariesUpdateTimestampResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n PushDictionariesBody,\n PushDictionariesResult,\n UpdateDictionaryBody,\n UpdateDictionaryResult,\n} from '@intlayer/backend';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getDictionaryAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const backendURL = intlayerConfig.editor.backendURL;\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":";;;AAoBA,MAAa,oBACX,iBAAiC,EAAE,EACnC,mBACG;CAGH,MAAM,oBAAoB,GAFP,eAAe,OAAO,WAED;;;;;CAMxC,MAAM,kBAAkB,OACtB,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,mBACA,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;EACT,CACF;;;;CAKH,MAAM,sBAAsB,OAAO,eAA+B,EAAE,KAClE,MAAM,QACJ,GAAG,kBAAkB,QACrB,gBACA,cACA,EACE,OAAO,YACR,CACF;;;;CAKH,MAAM,iCAAiC,OACrC,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,UACrB,gBACA,cACA,EACE,OAAO,YACR,CACF;;;;;;CAOH,MAAM,gBAAgB,OACpB,eACA,SACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,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,MAAM,QACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;CAEH,MAAM,mBAAmB,OACvB,cACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,qBACH,gBACA,cACA;EACE,QAAQ;EACR,MAAM,EAAE,cAAc;EACvB,CACF;;;;;CAMH,MAAM,mBAAmB,OACvB,YACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,GAAG,WAAW,MACnC,gBACA,cACA;EACE,QAAQ;EACR,MAAM;EACP,CACF;;;;;CAMH,MAAM,mBAAmB,OACvB,IACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,kBAAkB,GAAG,MACxB,gBACA,cACA,EACE,QAAQ,UACT,CACF;AAEH,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,2 +1,37 @@
1
- import{fetcher as e}from"../fetcher.mjs";const t=(t={},n)=>{let r=n.editor.editorURL;if(!r)throw Error(`Editor URL is not defined in the Intlayer configuration.`);let i=`${r}/api`;return{getDictionaries:async(n={})=>(await e(`${i}/dictionary`,t,n)).data,getConfiguration:async(n={})=>(await e(`${i}/config`,t,n)).data,writeDictionary:async(n,r={})=>await e(`${i}/dictionary`,t,r,{method:`POST`,body:n})}};export{t as getEditorAPI};
1
+ import { fetcher } from "../fetcher.mjs";
2
+
3
+ //#region src/getIntlayerAPI/editor.ts
4
+ const getEditorAPI = (authAPIOptions = {}, intlayerConfig) => {
5
+ const editorURL = intlayerConfig.editor.editorURL;
6
+ if (!editorURL) throw new Error("Editor URL is not defined in the Intlayer configuration.");
7
+ const EDITOR_API_ROUTE = `${editorURL}/api`;
8
+ /**
9
+ * Get the Intlayer configuration
10
+ */
11
+ const getConfiguration = async (otherOptions = {}) => {
12
+ return (await fetcher(`${EDITOR_API_ROUTE}/config`, authAPIOptions, otherOptions)).data;
13
+ };
14
+ /**
15
+ * Get the Intlayer configuration
16
+ */
17
+ const getDictionaries = async (otherOptions = {}) => {
18
+ return (await fetcher(`${EDITOR_API_ROUTE}/dictionary`, authAPIOptions, otherOptions)).data;
19
+ };
20
+ /**
21
+ * Adds a new dictionary to the database.
22
+ * @param dictionary - Dictionary data.
23
+ */
24
+ const writeDictionary = async (body, otherOptions = {}) => await fetcher(`${EDITOR_API_ROUTE}/dictionary`, authAPIOptions, otherOptions, {
25
+ method: "POST",
26
+ body
27
+ });
28
+ return {
29
+ getDictionaries,
30
+ getConfiguration,
31
+ writeDictionary
32
+ };
33
+ };
34
+
35
+ //#endregion
36
+ export { getEditorAPI };
2
37
  //# sourceMappingURL=editor.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor.mjs","names":[],"sources":["../../../src/getIntlayerAPI/editor.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n GetConfigurationResult,\n GetEditorDictionariesResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from 'intlayer-editor';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getEditorAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const editorURL = intlayerConfig.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":"yCASA,MAAa,GACX,EAAiC,EAAE,CACnC,IACG,CACH,IAAM,EAAY,EAAe,OAAO,UAExC,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
+ {"version":3,"file":"editor.mjs","names":[],"sources":["../../../src/getIntlayerAPI/editor.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\nimport type {\n GetConfigurationResult,\n GetEditorDictionariesResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from 'intlayer-editor';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getEditorAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig: IntlayerConfig\n) => {\n const editorURL = intlayerConfig.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":";;;AASA,MAAa,gBACX,iBAAiC,EAAE,EACnC,mBACG;CACH,MAAM,YAAY,eAAe,OAAO;AAExC,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,2DAA2D;CAG7E,MAAM,mBAAmB,GAAG,UAAU;;;;CAKtC,MAAM,mBAAmB,OACvB,eAA+B,EAAE,KACG;AAOpC,UANiB,MAAM,QACrB,GAAG,iBAAiB,UACpB,gBACA,aACD,EAEe;;;;;CAMlB,MAAM,kBAAkB,OACtB,eAA+B,EAAE,KACQ;AAOzC,UANiB,MAAM,QACrB,GAAG,iBAAiB,cACpB,gBACA,aACD,EAEe;;;;;;CAOlB,MAAM,kBAAkB,OACtB,MACA,eAA+B,EAAE,KAEjC,MAAM,QACJ,GAAG,iBAAiB,cACpB,gBACA,cACA;EACE,QAAQ;EACR;EACD,CACF;AAEH,QAAO;EACL;EACA;EACA;EACD"}