@intlayer/api 5.6.0 → 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/IntlayerEventListener.cjs +2 -9
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs +3 -4
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs +5 -6
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs +21 -4
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/auth.cjs +54 -132
- package/dist/cjs/getIntlayerAPI/auth.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/index.cjs +3 -1
- package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/oAuth.cjs +68 -0
- package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/user.cjs +3 -1
- package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/types.cjs.map +1 -1
- package/dist/esm/IntlayerEventListener.mjs +2 -9
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs +3 -4
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +5 -6
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/ai.mjs +21 -4
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/auth.mjs +54 -132
- package/dist/esm/getIntlayerAPI/auth.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/index.mjs +3 -1
- package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/oAuth.mjs +34 -0
- package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/user.mjs +3 -1
- package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/IntlayerEventListener.d.ts.map +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/auth.d.ts +30 -19
- package/dist/types/getIntlayerAPI/auth.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/index.d.ts +28 -95
- package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/oAuth.d.ts +8 -0
- package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/user.d.ts +2 -1
- package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -1
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +8 -7
|
@@ -32,7 +32,7 @@ __export(IntlayerEventListener_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(IntlayerEventListener_exports);
|
|
34
34
|
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
-
var
|
|
35
|
+
var import_oAuth = require('./getIntlayerAPI/oAuth.cjs');
|
|
36
36
|
class IntlayerEventListener {
|
|
37
37
|
constructor(intlayerConfig = import_built.default) {
|
|
38
38
|
this.intlayerConfig = intlayerConfig;
|
|
@@ -56,19 +56,12 @@ class IntlayerEventListener {
|
|
|
56
56
|
*/
|
|
57
57
|
async initialize() {
|
|
58
58
|
const backendURL = this.intlayerConfig.editor.backendURL;
|
|
59
|
-
const
|
|
60
|
-
{},
|
|
59
|
+
const accessToken = await (0, import_oAuth.getOAuthAPI)(
|
|
61
60
|
this.intlayerConfig
|
|
62
61
|
).getOAuth2AccessToken();
|
|
63
|
-
const accessToken = oAuth2TokenResult.data?.accessToken;
|
|
64
62
|
if (!accessToken) {
|
|
65
63
|
throw new Error("Failed to retrieve access token");
|
|
66
64
|
}
|
|
67
|
-
if (oAuth2TokenResult.data?.organization.plan?.type !== "ENTERPRISE") {
|
|
68
|
-
throw new Error(
|
|
69
|
-
"Hot reload is enabled, but is only available for enterprise plans"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
65
|
const API_ROUTE = `${backendURL}/api/event-listener`;
|
|
73
66
|
const url = `${API_ROUTE}/${accessToken}`;
|
|
74
67
|
this.eventSource = new EventSource(url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/IntlayerEventListener.ts"],"sourcesContent":["// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI, MessageEventData } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/IntlayerEventListener.ts"],"sourcesContent":["// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI, MessageEventData } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport { getOAuthAPI } from './getIntlayerAPI/oAuth';\n\nexport type IntlayerMessageEvent = MessageEvent;\n\n/**\n * IntlayerEventListener class to listen for dictionary changes via SSE (Server-Sent Events).\n *\n * Usage example:\n *\n * import { buildIntlayerDictionary } from './transpiler/declaration_file_to_dictionary/intlayer_dictionary';\n * import { IntlayerEventListener } from '@intlayer/api';\n *\n * export const checkDictionaryChanges = async () => {\n * // Instantiate the listener\n * const eventListener = new IntlayerEventListener();\n *\n * // Set up your callbacks\n * eventListener.onDictionaryChange = async (dictionary) => {\n * await buildIntlayerDictionary(dictionary);\n * };\n *\n * // Initialize the listener\n * await eventListener.initialize();\n *\n * // Optionally, clean up later when you’re done\n * // eventListener.cleanup();\n * };\n */\nexport class IntlayerEventListener {\n private eventSource: EventSource | null = null;\n\n /**\n * Callback triggered when a Dictionary is ADDED.\n */\n public onDictionaryAdded?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is UPDATED.\n */\n public onDictionaryChange?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is DELETED.\n */\n public onDictionaryDeleted?: (dictionary: DictionaryAPI) => any;\n\n constructor(private intlayerConfig: IntlayerConfig = configuration) {}\n\n /**\n * Initializes the EventSource connection using the given intlayerConfig\n * (or the default config if none was provided).\n */\n public async initialize(): Promise<void> {\n const backendURL = this.intlayerConfig.editor.backendURL;\n\n // Retrieve the access token\n const accessToken = await getOAuthAPI(\n this.intlayerConfig\n ).getOAuth2AccessToken();\n\n if (!accessToken) {\n throw new Error('Failed to retrieve access token');\n }\n\n const API_ROUTE = `${backendURL}/api/event-listener`;\n const url = `${API_ROUTE}/${accessToken}`;\n\n this.eventSource = new EventSource(url);\n this.eventSource.onmessage = (event) => this.handleMessage(event);\n this.eventSource.onerror = (event) => this.handleError(event);\n }\n\n /**\n * Cleans up (closes) the EventSource connection.\n */\n public cleanup(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n }\n\n /**\n * Handles incoming SSE messages, parses the event data,\n * and invokes the appropriate callback.\n */\n private async handleMessage(event: IntlayerMessageEvent): Promise<void> {\n try {\n const { data } = event;\n\n const dataJSON: MessageEventData[] = JSON.parse(data);\n\n for (const dataEl of dataJSON) {\n switch (dataEl.object) {\n case 'DICTIONARY':\n switch (dataEl.status) {\n case 'ADDED':\n await this.onDictionaryAdded?.(dataEl.data);\n break;\n case 'UPDATED':\n await this.onDictionaryChange?.(dataEl.data);\n break;\n case 'DELETED':\n await this.onDictionaryDeleted?.(dataEl.data);\n break;\n default:\n console.error('Unhandled dictionary status:', dataEl.status);\n break;\n }\n break;\n default:\n console.error('Unknown object type:', dataEl.object);\n break;\n }\n }\n } catch (error) {\n console.error('Error processing dictionary update:', error);\n }\n }\n\n /**\n * Handles any SSE errors and then performs cleanup.\n */\n private handleError(event: Event): void {\n console.error('EventSource error:', event);\n this.cleanup();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAE1B,mBAA4B;AA4BrB,MAAM,sBAAsB;AAAA,EAkBjC,YAAoB,iBAAiC,aAAAA,SAAe;AAAhD;AAAA,EAAiD;AAAA,EAjB7D,cAAkC;AAAA;AAAA;AAAA;AAAA,EAKnC;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQP,MAAa,aAA4B;AACvC,UAAM,aAAa,KAAK,eAAe,OAAO;AAG9C,UAAM,cAAc,UAAM;AAAA,MACxB,KAAK;AAAA,IACP,EAAE,qBAAqB;AAEvB,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AAEA,UAAM,YAAY,GAAG,UAAU;AAC/B,UAAM,MAAM,GAAG,SAAS,IAAI,WAAW;AAEvC,SAAK,cAAc,IAAI,YAAY,GAAG;AACtC,SAAK,YAAY,YAAY,CAAC,UAAU,KAAK,cAAc,KAAK;AAChE,SAAK,YAAY,UAAU,CAAC,UAAU,KAAK,YAAY,KAAK;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA,EAKO,UAAgB;AACrB,QAAI,KAAK,aAAa;AACpB,WAAK,YAAY,MAAM;AACvB,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,cAAc,OAA4C;AACtE,QAAI;AACF,YAAM,EAAE,KAAK,IAAI;AAEjB,YAAM,WAA+B,KAAK,MAAM,IAAI;AAEpD,iBAAW,UAAU,UAAU;AAC7B,gBAAQ,OAAO,QAAQ;AAAA,UACrB,KAAK;AACH,oBAAQ,OAAO,QAAQ;AAAA,cACrB,KAAK;AACH,sBAAM,KAAK,oBAAoB,OAAO,IAAI;AAC1C;AAAA,cACF,KAAK;AACH,sBAAM,KAAK,qBAAqB,OAAO,IAAI;AAC3C;AAAA,cACF,KAAK;AACH,sBAAM,KAAK,sBAAsB,OAAO,IAAI;AAC5C;AAAA,cACF;AACE,wBAAQ,MAAM,gCAAgC,OAAO,MAAM;AAC3D;AAAA,YACJ;AACA;AAAA,UACF;AACE,oBAAQ,MAAM,wBAAwB,OAAO,MAAM;AACnD;AAAA,QACJ;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,MAAM,uCAAuC,KAAK;AAAA,IAC5D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,YAAY,OAAoB;AACtC,YAAQ,MAAM,sBAAsB,KAAK;AACzC,SAAK,QAAQ;AAAA,EACf;AACF;","names":["configuration"]}
|
|
@@ -32,8 +32,8 @@ __export(fetchDistantDictionaries_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(fetchDistantDictionaries_exports);
|
|
34
34
|
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
-
var import_auth = require('../getIntlayerAPI/auth.cjs');
|
|
36
35
|
var import_dictionary = require('../getIntlayerAPI/dictionary.cjs');
|
|
36
|
+
var import_oAuth = require('../getIntlayerAPI/oAuth.cjs');
|
|
37
37
|
const fetchDistantDictionaries = async (intlayerConfig = import_built.default) => {
|
|
38
38
|
try {
|
|
39
39
|
const { clientId, clientSecret } = intlayerConfig?.editor;
|
|
@@ -43,9 +43,8 @@ const fetchDistantDictionaries = async (intlayerConfig = import_built.default) =
|
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
const dictionaryAPI = (0, import_dictionary.getDictionaryAPI)(void 0, intlayerConfig);
|
|
46
|
-
const authAPI = (0,
|
|
47
|
-
const
|
|
48
|
-
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
46
|
+
const authAPI = (0, import_oAuth.getOAuthAPI)(intlayerConfig);
|
|
47
|
+
const oAuth2AccessToken = await authAPI.getOAuth2AccessToken();
|
|
49
48
|
const getDictionaryResult = await dictionaryAPI.getDictionaries(void 0, {
|
|
50
49
|
...oAuth2AccessToken && {
|
|
51
50
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionaries.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport { getDictionaryAPI } from '../getIntlayerAPI/dictionary';\nimport { getOAuthAPI } from '../getIntlayerAPI/oAuth';\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionaries = async (\n intlayerConfig: IntlayerConfig = configuration\n): Promise<DictionaryAPI[] | null | undefined> => {\n try {\n const { clientId, clientSecret } = intlayerConfig?.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const dictionaryAPI = getDictionaryAPI(undefined, intlayerConfig);\n const authAPI = getOAuthAPI(intlayerConfig);\n const oAuth2AccessToken = await authAPI.getOAuth2AccessToken();\n\n // Fetch the dictionary\n const getDictionaryResult = await dictionaryAPI.getDictionaries(undefined, {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n });\n\n const distantDictionaries = getDictionaryResult.data;\n\n return distantDictionaries;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAE1B,wBAAiC;AACjC,mBAA4B;AAKrB,MAAM,2BAA2B,OACtC,iBAAiC,aAAAA,YACe;AAChD,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB;AAEnD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAgB,oCAAiB,QAAW,cAAc;AAChE,UAAM,cAAU,0BAAY,cAAc;AAC1C,UAAM,oBAAoB,MAAM,QAAQ,qBAAqB;AAG7D,UAAM,sBAAsB,MAAM,cAAc,gBAAgB,QAAW;AAAA,MACzE,GAAI,qBAAqB;AAAA,QACvB,SAAS;AAAA,UACP,eAAe,UAAU,iBAAiB;AAAA,QAC5C;AAAA,MACF;AAAA,IACF,CAAC;AAED,UAAM,sBAAsB,oBAAoB;AAEhD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":["configuration"]}
|
|
@@ -32,8 +32,8 @@ __export(fetchDistantDictionary_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(fetchDistantDictionary_exports);
|
|
34
34
|
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
-
var import_auth = require('../getIntlayerAPI/auth.cjs');
|
|
36
35
|
var import_dictionary = require('../getIntlayerAPI/dictionary.cjs');
|
|
36
|
+
var import_oAuth = require('../getIntlayerAPI/oAuth.cjs');
|
|
37
37
|
const fetchDistantDictionary = async (dictionaryKey, intlayerConfig = import_built.default) => {
|
|
38
38
|
try {
|
|
39
39
|
const { clientId, clientSecret } = intlayerConfig?.editor;
|
|
@@ -43,16 +43,15 @@ const fetchDistantDictionary = async (dictionaryKey, intlayerConfig = import_bui
|
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
const dictionaryAPI = (0, import_dictionary.getDictionaryAPI)(void 0, intlayerConfig);
|
|
46
|
-
const authAPI = (0,
|
|
47
|
-
const
|
|
48
|
-
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
46
|
+
const authAPI = (0, import_oAuth.getOAuthAPI)(intlayerConfig);
|
|
47
|
+
const accessToken = await authAPI.getOAuth2AccessToken();
|
|
49
48
|
const getDictionaryResult = await dictionaryAPI.getDictionary(
|
|
50
49
|
dictionaryKey,
|
|
51
50
|
void 0,
|
|
52
51
|
{
|
|
53
|
-
...
|
|
52
|
+
...accessToken && {
|
|
54
53
|
headers: {
|
|
55
|
-
Authorization: `Bearer ${
|
|
54
|
+
Authorization: `Bearer ${accessToken}`
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["// @ts-ignore @intlayer/backend is not build yet\nimport type { DictionaryAPI } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport { getDictionaryAPI } from '../getIntlayerAPI/dictionary';\nimport { getOAuthAPI } from '../getIntlayerAPI/oAuth';\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string,\n intlayerConfig: IntlayerConfig = configuration\n): Promise<DictionaryAPI | undefined> => {\n try {\n const { clientId, clientSecret } = intlayerConfig?.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const dictionaryAPI = getDictionaryAPI(undefined, intlayerConfig);\n const authAPI = getOAuthAPI(intlayerConfig);\n\n const accessToken = await authAPI.getOAuth2AccessToken();\n\n // Fetch the dictionary\n const getDictionaryResult = await dictionaryAPI.getDictionary(\n dictionaryKey,\n undefined,\n {\n ...(accessToken && {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n }),\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0B;AAE1B,wBAAiC;AACjC,mBAA4B;AAKrB,MAAM,yBAAyB,OACpC,eACA,iBAAiC,aAAAA,YACM;AACvC,MAAI;AACF,UAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB;AAEnD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAgB,oCAAiB,QAAW,cAAc;AAChE,UAAM,cAAU,0BAAY,cAAc;AAE1C,UAAM,cAAc,MAAM,QAAQ,qBAAqB;AAGvD,UAAM,sBAAsB,MAAM,cAAc;AAAA,MAC9C;AAAA,MACA;AAAA,MACA;AAAA,QACE,GAAI,eAAe;AAAA,UACjB,SAAS;AAAA,YACP,eAAe,UAAU,WAAW;AAAA,UACtC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,oBAAoB;AAE9C,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,IACnE;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":["configuration"]}
|
|
@@ -107,12 +107,29 @@ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
107
107
|
...authAPIOptions.headers,
|
|
108
108
|
...otherOptions.headers
|
|
109
109
|
},
|
|
110
|
-
body: JSON.stringify(
|
|
111
|
-
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
...rest,
|
|
112
|
+
...authAPIOptions.body,
|
|
113
|
+
...otherOptions.body
|
|
114
|
+
}),
|
|
115
|
+
signal: abortController.signal,
|
|
116
|
+
credentials: "include"
|
|
112
117
|
});
|
|
113
118
|
if (!response.ok) {
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
let errorMessage = "An error occurred";
|
|
120
|
+
try {
|
|
121
|
+
const errorData = await response.json();
|
|
122
|
+
errorMessage = JSON.stringify(errorData.error) ?? "An error occurred";
|
|
123
|
+
} catch {
|
|
124
|
+
try {
|
|
125
|
+
const errorText = await response.text();
|
|
126
|
+
if (errorText) {
|
|
127
|
+
errorMessage = errorText;
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
throw new Error(errorMessage);
|
|
116
133
|
}
|
|
117
134
|
const reader = response.body?.getReader();
|
|
118
135
|
if (!reader) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import 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\nimport configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\n\nimport { fetcher, type FetcherOptions } from '../fetcher';\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(rest),\n signal: abortController.signal,\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n\n throw new Error(errorData.message || 'Failed to fetch response');\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;AAmBA,mBAA0B;AAG1B,qBAA6C;AAWtC,MAAM,WAAW,CACtB,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,aACJ,gBAAgB,QAAQ,cAAc,aAAAA,QAAc,QAAQ;AAE9D,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,GAAG,UAAU;AAOlC,QAAM,cAAc,OAClB,MACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAOF,QAAM,gBAAgB,OACpB,MACA,eAA+B,CAAC,MAE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]}
|
|
1
|
+
{"version":3,"sources":["../../../src/getIntlayerAPI/ai.ts"],"sourcesContent":["import 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\nimport configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\n\nimport { fetcher, type FetcherOptions } from '../fetcher';\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;AAmBA,mBAA0B;AAG1B,qBAA6C;AAWtC,MAAM,WAAW,CACtB,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,aACJ,gBAAgB,QAAQ,cAAc,aAAAA,QAAc,QAAQ;AAE9D,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,GAAG,UAAU;AAOlC,QAAM,cAAc,OAClB,MACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAOF,QAAM,gBAAgB,OACpB,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;AAOF,QAAM,0BAA0B,OAC9B,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;AAOF,QAAM,+BAA+B,OACnC,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;AAOF,QAAM,kCAAkC,OACtC,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;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AAC1C,YAAI,KAAM;AAEV,kBAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAChD,cAAM,QAAQ,OAAO,MAAM,IAAI;AAC/B,iBAAS,MAAM,IAAI,KAAK;AAExB,mBAAW,QAAQ,OAAO;AACxB,cAAI,KAAK,WAAW,QAAQ,GAAG;AAC7B,gBAAI;AACF,oBAAM,OAAO,KAAK,MAAM,KAAK,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"]}
|
|
@@ -32,8 +32,8 @@ __export(auth_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(auth_exports);
|
|
34
34
|
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
-
var
|
|
36
|
-
const getAuthAPI = (
|
|
35
|
+
var import_client = require("better-auth/client");
|
|
36
|
+
const getAuthAPI = (intlayerConfig) => {
|
|
37
37
|
const backendURL = intlayerConfig?.editor?.backendURL ?? import_built.default.editor?.backendURL;
|
|
38
38
|
const { clientId, clientSecret } = intlayerConfig?.editor ?? {};
|
|
39
39
|
if (!backendURL) {
|
|
@@ -41,138 +41,60 @@ const getAuthAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
41
41
|
"Backend URL is not defined in the Intlayer configuration."
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
);
|
|
72
|
-
const
|
|
73
|
-
`${AUTH_API_ROUTE}/logout`,
|
|
74
|
-
authAPIOptions,
|
|
75
|
-
otherOptions,
|
|
76
|
-
{
|
|
77
|
-
method: "POST"
|
|
78
|
-
}
|
|
79
|
-
);
|
|
80
|
-
const askResetPassword = async (email, otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
81
|
-
`${AUTH_API_ROUTE}/password/reset`,
|
|
82
|
-
authAPIOptions,
|
|
83
|
-
otherOptions,
|
|
84
|
-
{
|
|
85
|
-
method: "POST",
|
|
86
|
-
body: { email }
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
const defineNewPassword = async (data, otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
90
|
-
`${AUTH_API_ROUTE}/password/define`,
|
|
91
|
-
authAPIOptions,
|
|
92
|
-
otherOptions,
|
|
93
|
-
{
|
|
94
|
-
method: "POST",
|
|
95
|
-
body: data
|
|
96
|
-
}
|
|
97
|
-
);
|
|
98
|
-
const changePassword = async (data, otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
99
|
-
`${AUTH_API_ROUTE}/password`,
|
|
100
|
-
authAPIOptions,
|
|
101
|
-
otherOptions,
|
|
102
|
-
{
|
|
103
|
-
method: "PUT",
|
|
104
|
-
body: data
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
const checkIfUserHasPassword = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
108
|
-
`${AUTH_API_ROUTE}/password/has`,
|
|
109
|
-
authAPIOptions,
|
|
110
|
-
otherOptions,
|
|
111
|
-
{
|
|
112
|
-
method: "GET"
|
|
113
|
-
}
|
|
114
|
-
);
|
|
115
|
-
const verifyEmail = async ({ userId, secret }, otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
116
|
-
`${AUTH_API_ROUTE}/active/${userId}/${secret}`,
|
|
117
|
-
authAPIOptions,
|
|
118
|
-
otherOptions,
|
|
119
|
-
{
|
|
120
|
-
method: "PUT"
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
const getVerifyEmailStatusURL = (userId) => `${AUTH_API_ROUTE}/verify-email-status/${String(userId)}`;
|
|
124
|
-
const createSession = async (data, otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
125
|
-
`${AUTH_API_ROUTE}/session`,
|
|
126
|
-
authAPIOptions,
|
|
127
|
-
otherOptions,
|
|
128
|
-
{
|
|
129
|
-
method: "POST",
|
|
130
|
-
body: data
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
const getSession = async (sessionToken, otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
134
|
-
`${backendURL}/session`,
|
|
135
|
-
authAPIOptions,
|
|
136
|
-
otherOptions,
|
|
137
|
-
{ params: { session_token: sessionToken } }
|
|
138
|
-
);
|
|
139
|
-
const getCSRFToken = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
140
|
-
`${backendURL}/csrf-token`,
|
|
141
|
-
authAPIOptions,
|
|
142
|
-
otherOptions
|
|
143
|
-
);
|
|
144
|
-
const getOAuth2AccessToken = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
145
|
-
`${backendURL}/oauth2/token`,
|
|
146
|
-
authAPIOptions,
|
|
147
|
-
otherOptions,
|
|
148
|
-
{
|
|
149
|
-
method: "POST",
|
|
150
|
-
headers: {
|
|
151
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
152
|
-
},
|
|
153
|
-
body: {
|
|
154
|
-
grant_type: "client_credentials",
|
|
155
|
-
client_id: clientId,
|
|
156
|
-
client_secret: clientSecret
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
);
|
|
44
|
+
const authClient = (0, import_client.createAuthClient)({
|
|
45
|
+
baseURL: backendURL,
|
|
46
|
+
withCredentials: true
|
|
47
|
+
// makes fetch forward cookies
|
|
48
|
+
});
|
|
49
|
+
const signInEmail = async (...args) => await authClient.signIn.email(...args);
|
|
50
|
+
const signInSocial = async (...args) => await authClient.signIn.social(...args);
|
|
51
|
+
const signUpEmail = async (...args) => await authClient.signUp.email(...args);
|
|
52
|
+
const signOut = async (...args) => await authClient.signOut(...args);
|
|
53
|
+
const changePasswordSession = async (...args) => await authClient.changePassword(...args);
|
|
54
|
+
const requestPasswordResetSession = async (...args) => await authClient.requestPasswordReset(...args);
|
|
55
|
+
const resetPassword = authClient.resetPassword;
|
|
56
|
+
const verifyEmailSession = async (...args) => await authClient.verifyEmail(...args);
|
|
57
|
+
const getSession = async (...args) => await authClient.getSession(...args);
|
|
58
|
+
const forgetPassword = async (...args) => await authClient.forgetPassword(...args);
|
|
59
|
+
const sendVerificationEmail = async (...args) => await authClient.sendVerificationEmail(...args);
|
|
60
|
+
const changeEmail = async (...args) => await authClient.changeEmail(...args);
|
|
61
|
+
const deleteUser = authClient.deleteUser;
|
|
62
|
+
const revokeSession = async (...args) => await authClient.revokeSession(...args);
|
|
63
|
+
const revokeSessions = async (...args) => await authClient.revokeSessions(...args);
|
|
64
|
+
const revokeOtherSessions = async (...args) => await authClient.revokeOtherSessions(...args);
|
|
65
|
+
const linkSocial = async (...args) => await authClient.linkSocial(...args);
|
|
66
|
+
const listAccounts = async (...args) => await authClient.listAccounts(...args);
|
|
67
|
+
const unlinkAccount = async (...args) => await authClient.unlinkAccount(...args);
|
|
68
|
+
const refreshToken = async (...args) => await authClient.refreshToken(...args);
|
|
69
|
+
const getAccessToken = async (...args) => await authClient.getAccessToken(...args);
|
|
70
|
+
const accountInfo = async (...args) => await authClient.accountInfo(...args);
|
|
71
|
+
const updateUser = async (...args) => await authClient.updateUser(...args);
|
|
72
|
+
const listSessions = async (...args) => await authClient.listSessions(...args);
|
|
160
73
|
return {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
getVerifyEmailStatusURL,
|
|
171
|
-
changePassword,
|
|
172
|
-
createSession,
|
|
74
|
+
signInEmail,
|
|
75
|
+
signUpEmail,
|
|
76
|
+
signOut,
|
|
77
|
+
signInSocial,
|
|
78
|
+
linkSocial,
|
|
79
|
+
changePasswordSession,
|
|
80
|
+
requestPasswordResetSession,
|
|
81
|
+
resetPassword,
|
|
82
|
+
verifyEmailSession,
|
|
173
83
|
getSession,
|
|
174
|
-
|
|
175
|
-
|
|
84
|
+
forgetPassword,
|
|
85
|
+
sendVerificationEmail,
|
|
86
|
+
changeEmail,
|
|
87
|
+
deleteUser,
|
|
88
|
+
revokeSession,
|
|
89
|
+
revokeSessions,
|
|
90
|
+
revokeOtherSessions,
|
|
91
|
+
listAccounts,
|
|
92
|
+
unlinkAccount,
|
|
93
|
+
refreshToken,
|
|
94
|
+
getAccessToken,
|
|
95
|
+
accountInfo,
|
|
96
|
+
updateUser,
|
|
97
|
+
listSessions
|
|
176
98
|
};
|
|
177
99
|
};
|
|
178
100
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/getIntlayerAPI/auth.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport type {\n AskResetPasswordBody,\n AskResetPasswordResult,\n CheckIfUserHasPasswordResult,\n CreateSessionBody,\n CreateSessionResult,\n DefinePasswordBody,\n DefinePasswordResult,\n GetOAuth2TokenBody,\n GetOAuth2TokenResult,\n GetSessionInformationQuery,\n GetSessionInformationResult,\n GithubLoginQueryParams,\n GoogleLoginQueryParams,\n LoginBody,\n LoginResult,\n RegisterBody,\n RegisterQuery,\n RegisterResult,\n SetCSRFTokenResult,\n UpdatePasswordBody,\n UpdatePasswordResult,\n UserAPI,\n ValidEmailParams,\n ValidEmailResult,\n} from '../types';\n\nimport { fetcher, type FetcherOptions } from '../fetcher';\n\nexport const getAuthAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration.editor?.backendURL;\n const { clientId, clientSecret } = intlayerConfig?.editor ?? {};\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n const AUTH_API_ROUTE = `${backendURL}/api/auth`;\n\n /**\n * Logs in a user with the provided credentials.\n * @param user - User credentials.\n */\n const login = async (user: LoginBody, otherOptions: FetcherOptions = {}) =>\n await fetcher<LoginResult>(\n `${AUTH_API_ROUTE}/login`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: user,\n }\n );\n\n /**\n * Gets the login with GitHub URL.\n * @param params - The parameters for the login with GitHub URL.\n * @returns The login with GitHub URL.\n */\n const getLoginWithGitHubURL = (params: GithubLoginQueryParams): string => {\n const searchParams = new URLSearchParams(params);\n\n return `${AUTH_API_ROUTE}/login/github?${searchParams.toString()}`;\n };\n\n /**\n * Gets the login with Google URL.\n * @param params - The parameters for the login with Google URL.\n * @returns The login with Google URL.\n */\n const getLoginWithGoogleURL = (params: GoogleLoginQueryParams): string => {\n const searchParams = new URLSearchParams(params);\n\n return `${AUTH_API_ROUTE}/login/google?${searchParams.toString()}`;\n };\n\n /**\n * Registers a new user with the provided credentials.\n * @param user - User credentials.\n * @returns User object.\n */\n const register = async (\n user: RegisterBody,\n query: RegisterQuery = {},\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<RegisterResult>(\n `${AUTH_API_ROUTE}/register`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: user,\n params: query,\n }\n );\n\n /**\n * Signs out the user.\n * @returns User object.\n */\n const logout = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<void>(\n `${AUTH_API_ROUTE}/logout`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Ask to resets the password of a user with the provided email address.\n * @param email - Email address of the user.\n * @returns User object.\n */\n const askResetPassword = async (\n email: AskResetPasswordBody['email'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AskResetPasswordResult>(\n `${AUTH_API_ROUTE}/password/reset`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: { email },\n }\n );\n\n /**\n * Changes the password of a user with the provided data.\n * @param data - New password and confirmation.\n * @returns User object.\n */\n const defineNewPassword = async (\n data: DefinePasswordBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DefinePasswordResult>(\n `${AUTH_API_ROUTE}/password/define`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: data,\n }\n );\n\n /**\n * Changes the password of a user with the provided data.\n * @param data - New password and confirmation.\n * @returns User object.\n */\n const changePassword = async (\n data: UpdatePasswordBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdatePasswordResult>(\n `${AUTH_API_ROUTE}/password`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: data,\n }\n );\n\n /**\n * Checks if a user has a password.\n * @param params - User ID.\n * @returns User object.\n */\n const checkIfUserHasPassword = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<CheckIfUserHasPasswordResult>(\n `${AUTH_API_ROUTE}/password/has`,\n authAPIOptions,\n otherOptions,\n {\n method: 'GET',\n }\n );\n\n /**\n * Verifies the email address of a user with the provided token.\n * @param params - User ID and secret key.\n * @returns User object.\n */\n const verifyEmail = async (\n { userId, secret }: ValidEmailParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<ValidEmailResult>(\n `${AUTH_API_ROUTE}/active/${userId}/${secret}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n }\n );\n\n /**\n * Gets the verify email status URL to use in the SSE.\n * @param userId - User ID.\n * @returns The verify email status URL.\n */\n const getVerifyEmailStatusURL = (userId: string | UserAPI['_id']) =>\n `${AUTH_API_ROUTE}/verify-email-status/${String(userId)}`;\n\n /**\n * Creates a session for a user.\n * @param params - User ID and secret key.\n * @returns User object.\n */\n const createSession = async (\n data: CreateSessionBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreateSessionResult>(\n `${AUTH_API_ROUTE}/session`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: data,\n }\n );\n\n /**\n * Gets a session and user.\n * @param sessionToken - Session token.\n * @param otherOptions - Fetcher options.\n * @returns Session and user information.\n */\n const getSession = async (\n sessionToken?: GetSessionInformationQuery['session_token'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetSessionInformationResult>(\n `${backendURL}/session`,\n authAPIOptions,\n otherOptions,\n { params: { session_token: sessionToken } }\n );\n\n /**\n * Gets the CSRF token.\n * @param otherOptions - Fetcher options.\n * @returns The CSRF token.\n */\n const getCSRFToken = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<SetCSRFTokenResult>(\n `${backendURL}/csrf-token`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Gets an oAuth2 accessToken\n * @return The token information\n */\n const getOAuth2AccessToken = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetOAuth2TokenResult>(\n `${backendURL}/oauth2/token`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: {\n grant_type: 'client_credentials',\n client_id: clientId!,\n client_secret: clientSecret!,\n } satisfies GetOAuth2TokenBody,\n }\n );\n\n return {\n login,\n getLoginWithGitHubURL,\n getLoginWithGoogleURL,\n register,\n logout,\n defineNewPassword,\n askResetPassword,\n checkIfUserHasPassword,\n verifyEmail,\n getVerifyEmailStatusURL,\n changePassword,\n createSession,\n getSession,\n getCSRFToken,\n getOAuth2AccessToken,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AA6B1B,qBAA6C;AAEtC,MAAM,aAAa,CACxB,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,aACJ,gBAAgB,QAAQ,cAAc,aAAAA,QAAc,QAAQ;AAC9D,QAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB,UAAU,CAAC;AAE9D,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,iBAAiB,GAAG,UAAU;AAMpC,QAAM,QAAQ,OAAO,MAAiB,eAA+B,CAAC,MACpE,UAAM;AAAA,IACJ,GAAG,cAAc;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAOF,QAAM,wBAAwB,CAAC,WAA2C;AACxE,UAAM,eAAe,IAAI,gBAAgB,MAAM;AAE/C,WAAO,GAAG,cAAc,iBAAiB,aAAa,SAAS,CAAC;AAAA,EAClE;AAOA,QAAM,wBAAwB,CAAC,WAA2C;AACxE,UAAM,eAAe,IAAI,gBAAgB,MAAM;AAE/C,WAAO,GAAG,cAAc,iBAAiB,aAAa,SAAS,CAAC;AAAA,EAClE;AAOA,QAAM,WAAW,OACf,MACA,QAAuB,CAAC,GACxB,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,MACE,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AAG,cAAc;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAQF,QAAM,aAAa,OACjB,cACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,UAAU;AAAA,IACb;AAAA,IACA;AAAA,IACA,EAAE,QAAQ,EAAE,eAAe,aAAa,EAAE;AAAA,EAC5C;AAOF,QAAM,eAAe,OAAO,eAA+B,CAAC,MAC1D,UAAM;AAAA,IACJ,GAAG,UAAU;AAAA,IACb;AAAA,IACA;AAAA,EACF;AAMF,QAAM,uBAAuB,OAAO,eAA+B,CAAC,MAClE,UAAM;AAAA,IACJ,GAAG,UAAU;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,QACJ,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAEF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["configuration"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/getIntlayerAPI/auth.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport { createAuthClient } from 'better-auth/client';\n\ntype AuthClient = ReturnType<typeof createAuthClient>;\n\nexport interface AuthAPI {\n signInEmail: AuthClient['signIn']['email'];\n signUpEmail: AuthClient['signUp']['email'];\n signOut: AuthClient['signOut'];\n signInSocial: AuthClient['signIn']['social'];\n linkSocial: AuthClient['linkSocial'];\n changePasswordSession: AuthClient['changePassword'];\n requestPasswordResetSession: AuthClient['requestPasswordReset'];\n resetPassword: AuthClient['resetPassword'];\n verifyEmailSession: AuthClient['verifyEmail'];\n getSession: AuthClient['getSession'];\n forgetPassword: AuthClient['forgetPassword'];\n sendVerificationEmail: AuthClient['sendVerificationEmail'];\n changeEmail: AuthClient['changeEmail'];\n deleteUser: AuthClient['deleteUser'];\n revokeSession: AuthClient['revokeSession'];\n revokeSessions: AuthClient['revokeSessions'];\n revokeOtherSessions: AuthClient['revokeOtherSessions'];\n listAccounts: AuthClient['listAccounts'];\n unlinkAccount: AuthClient['unlinkAccount'];\n refreshToken: AuthClient['refreshToken'];\n getAccessToken: AuthClient['getAccessToken'];\n accountInfo: AuthClient['accountInfo'];\n updateUser: AuthClient['updateUser'];\n listSessions: AuthClient['listSessions'];\n}\n\nexport const getAuthAPI = (intlayerConfig?: IntlayerConfig): AuthAPI => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration.editor?.backendURL;\n const { clientId, clientSecret } = intlayerConfig?.editor ?? {};\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n /*\n * Extract each method to avoid type inference issues at build time.\n */\n const authClient: AuthClient = createAuthClient({\n baseURL: backendURL,\n withCredentials: true, // makes fetch forward cookies\n });\n\n const signInEmail: AuthClient['signIn']['email'] = async (...args) =>\n await authClient.signIn.email(...args);\n\n const signInSocial: AuthClient['signIn']['social'] = async (...args) =>\n await authClient.signIn.social(...args);\n\n const signUpEmail: AuthClient['signUp']['email'] = async (...args) =>\n await authClient.signUp.email(...args);\n\n const signOut: AuthClient['signOut'] = async (...args) =>\n await authClient.signOut(...args);\n\n const changePasswordSession: AuthClient['changePassword'] = async (...args) =>\n await authClient.changePassword(...args);\n\n const requestPasswordResetSession: AuthClient['requestPasswordReset'] =\n async (...args) => await authClient.requestPasswordReset(...args);\n\n const resetPassword = authClient.resetPassword;\n\n const verifyEmailSession: AuthClient['verifyEmail'] = async (...args) =>\n await authClient.verifyEmail(...args);\n\n const getSession: AuthClient['getSession'] = async (...args) =>\n await authClient.getSession(...args);\n\n const forgetPassword: AuthClient['forgetPassword'] = async (...args) =>\n await authClient.forgetPassword(...args);\n\n const sendVerificationEmail: AuthClient['sendVerificationEmail'] = async (\n ...args\n ) => await authClient.sendVerificationEmail(...args);\n\n const changeEmail: AuthClient['changeEmail'] = async (...args) =>\n await authClient.changeEmail(...args);\n\n const deleteUser = authClient.deleteUser;\n\n const revokeSession: AuthClient['revokeSession'] = async (...args) =>\n await authClient.revokeSession(...args);\n\n const revokeSessions: AuthClient['revokeSessions'] = async (...args) =>\n await authClient.revokeSessions(...args);\n\n const revokeOtherSessions: AuthClient['revokeOtherSessions'] = async (\n ...args\n ) => await authClient.revokeOtherSessions(...args);\n\n const linkSocial: AuthClient['linkSocial'] = async (...args) =>\n await authClient.linkSocial(...args);\n\n const listAccounts: AuthClient['listAccounts'] = async (...args) =>\n await authClient.listAccounts(...args);\n\n const unlinkAccount: AuthClient['unlinkAccount'] = async (...args) =>\n await authClient.unlinkAccount(...args);\n\n const refreshToken: AuthClient['refreshToken'] = async (...args) =>\n await authClient.refreshToken(...args);\n\n const getAccessToken: AuthClient['getAccessToken'] = async (...args) =>\n await authClient.getAccessToken(...args);\n\n const accountInfo: AuthClient['accountInfo'] = async (...args) =>\n await authClient.accountInfo(...args);\n\n const updateUser: AuthClient['updateUser'] = async (...args) =>\n await authClient.updateUser(...args);\n\n const listSessions: AuthClient['listSessions'] = async (...args) =>\n await authClient.listSessions(...args);\n\n return {\n signInEmail,\n signUpEmail,\n signOut,\n signInSocial,\n linkSocial,\n changePasswordSession,\n requestPasswordResetSession,\n resetPassword,\n verifyEmailSession,\n getSession,\n forgetPassword,\n sendVerificationEmail,\n changeEmail,\n deleteUser,\n revokeSession,\n revokeSessions,\n revokeOtherSessions,\n listAccounts,\n unlinkAccount,\n refreshToken,\n getAccessToken,\n accountInfo,\n updateUser,\n listSessions,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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7D,MAAM,WAAW,eAAe,GAAG,IAAI;AAEzC,QAAM,sBAAyD,UAC1D,SACA,MAAM,WAAW,oBAAoB,GAAG,IAAI;AAEjD,QAAM,aAAuC,UAAU,SACrD,MAAM,WAAW,WAAW,GAAG,IAAI;AAErC,QAAM,eAA2C,UAAU,SACzD,MAAM,WAAW,aAAa,GAAG,IAAI;AAEvC,QAAM,gBAA6C,UAAU,SAC3D,MAAM,WAAW,cAAc,GAAG,IAAI;AAExC,QAAM,eAA2C,UAAU,SACzD,MAAM,WAAW,aAAa,GAAG,IAAI;AAEvC,QAAM,iBAA+C,UAAU,SAC7D,MAAM,WAAW,eAAe,GAAG,IAAI;AAEzC,QAAM,cAAyC,UAAU,SACvD,MAAM,WAAW,YAAY,GAAG,IAAI;AAEtC,QAAM,aAAuC,UAAU,SACrD,MAAM,WAAW,WAAW,GAAG,IAAI;AAErC,QAAM,eAA2C,UAAU,SACzD,MAAM,WAAW,aAAa,GAAG,IAAI;AAEvC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["configuration"]}
|
|
@@ -26,6 +26,7 @@ var import_auth = require('./auth.cjs');
|
|
|
26
26
|
var import_dictionary = require('./dictionary.cjs');
|
|
27
27
|
var import_editor = require('./editor.cjs');
|
|
28
28
|
var import_newsletter = require('./newsletter.cjs');
|
|
29
|
+
var import_oAuth = require('./oAuth.cjs');
|
|
29
30
|
var import_organization = require('./organization.cjs');
|
|
30
31
|
var import_project = require('./project.cjs');
|
|
31
32
|
var import_search = require('./search.cjs');
|
|
@@ -36,7 +37,8 @@ const getIntlayerAPI = (authAPIOptions = {}, intlayerConfig) => ({
|
|
|
36
37
|
organization: (0, import_organization.getOrganizationAPI)(authAPIOptions, intlayerConfig),
|
|
37
38
|
project: (0, import_project.getProjectAPI)(authAPIOptions, intlayerConfig),
|
|
38
39
|
user: (0, import_user.getUserAPI)(authAPIOptions, intlayerConfig),
|
|
39
|
-
auth: (0, import_auth.getAuthAPI)(
|
|
40
|
+
auth: (0, import_auth.getAuthAPI)(intlayerConfig),
|
|
41
|
+
oAuth: (0, import_oAuth.getOAuthAPI)(intlayerConfig),
|
|
40
42
|
dictionary: (0, import_dictionary.getDictionaryAPI)(authAPIOptions, intlayerConfig),
|
|
41
43
|
stripe: (0, import_stripe.getStripeAPI)(authAPIOptions, intlayerConfig),
|
|
42
44
|
ai: (0, import_ai.getAiAPI)(authAPIOptions, intlayerConfig),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/getIntlayerAPI/index.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/config/client';\nimport type { FetcherOptions } from '../fetcher';\nimport { getAiAPI } from './ai';\nimport { getAuthAPI } from './auth';\nimport { getDictionaryAPI } from './dictionary';\nimport { getEditorAPI } from './editor';\nimport { getNewsletterAPI } from './newsletter';\nimport { getOrganizationAPI } from './organization';\nimport { getProjectAPI } from './project';\nimport { getSearchAPI } from './search';\nimport { getStripeAPI } from './stripe';\nimport { getTagAPI } from './tag';\nimport { getUserAPI } from './user';\n\nexport const getIntlayerAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => ({\n organization: getOrganizationAPI(authAPIOptions, intlayerConfig),\n project: getProjectAPI(authAPIOptions, intlayerConfig),\n user: getUserAPI(authAPIOptions, intlayerConfig),\n auth: getAuthAPI(
|
|
1
|
+
{"version":3,"sources":["../../../src/getIntlayerAPI/index.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/config/client';\nimport type { FetcherOptions } from '../fetcher';\nimport { getAiAPI } from './ai';\nimport { AuthAPI, getAuthAPI } from './auth';\nimport { getDictionaryAPI } from './dictionary';\nimport { getEditorAPI } from './editor';\nimport { getNewsletterAPI } from './newsletter';\nimport { getOAuthAPI, oAuthAPI } from './oAuth';\nimport { getOrganizationAPI } from './organization';\nimport { getProjectAPI } from './project';\nimport { getSearchAPI } from './search';\nimport { getStripeAPI } from './stripe';\nimport { getTagAPI } from './tag';\nimport { getUserAPI } from './user';\n\ninterface IntlayerAPIReturn {\n organization: ReturnType<typeof getOrganizationAPI>;\n project: ReturnType<typeof getProjectAPI>;\n user: ReturnType<typeof getUserAPI>;\n auth: AuthAPI;\n oAuth: oAuthAPI;\n dictionary: ReturnType<typeof getDictionaryAPI>;\n stripe: ReturnType<typeof getStripeAPI>;\n ai: ReturnType<typeof getAiAPI>;\n tag: ReturnType<typeof getTagAPI>;\n search: ReturnType<typeof getSearchAPI>;\n editor: ReturnType<typeof getEditorAPI>;\n newsletter: ReturnType<typeof getNewsletterAPI>;\n}\n\nexport const getIntlayerAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n): IntlayerAPIReturn => ({\n organization: getOrganizationAPI(authAPIOptions, intlayerConfig),\n project: getProjectAPI(authAPIOptions, intlayerConfig),\n user: getUserAPI(authAPIOptions, intlayerConfig),\n auth: getAuthAPI(intlayerConfig),\n oAuth: getOAuthAPI(intlayerConfig),\n dictionary: getDictionaryAPI(authAPIOptions, intlayerConfig),\n stripe: getStripeAPI(authAPIOptions, intlayerConfig),\n ai: getAiAPI(authAPIOptions, intlayerConfig),\n tag: getTagAPI(authAPIOptions, intlayerConfig),\n search: getSearchAPI(authAPIOptions, intlayerConfig),\n editor: getEditorAPI(authAPIOptions, intlayerConfig),\n newsletter: getNewsletterAPI(authAPIOptions, intlayerConfig),\n});\n\nexport type IntlayerAPI = ReturnType<typeof getIntlayerAPI>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gBAAyB;AACzB,kBAAoC;AACpC,wBAAiC;AACjC,oBAA6B;AAC7B,wBAAiC;AACjC,mBAAsC;AACtC,0BAAmC;AACnC,qBAA8B;AAC9B,oBAA6B;AAC7B,oBAA6B;AAC7B,iBAA0B;AAC1B,kBAA2B;AAiBpB,MAAM,iBAAiB,CAC5B,iBAAiC,CAAC,GAClC,oBACuB;AAAA,EACvB,kBAAc,wCAAmB,gBAAgB,cAAc;AAAA,EAC/D,aAAS,8BAAc,gBAAgB,cAAc;AAAA,EACrD,UAAM,wBAAW,gBAAgB,cAAc;AAAA,EAC/C,UAAM,wBAAW,cAAc;AAAA,EAC/B,WAAO,0BAAY,cAAc;AAAA,EACjC,gBAAY,oCAAiB,gBAAgB,cAAc;AAAA,EAC3D,YAAQ,4BAAa,gBAAgB,cAAc;AAAA,EACnD,QAAI,oBAAS,gBAAgB,cAAc;AAAA,EAC3C,SAAK,sBAAU,gBAAgB,cAAc;AAAA,EAC7C,YAAQ,4BAAa,gBAAgB,cAAc;AAAA,EACnD,YAAQ,4BAAa,gBAAgB,cAAc;AAAA,EACnD,gBAAY,oCAAiB,gBAAgB,cAAc;AAC7D;","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
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 oAuth_exports = {};
|
|
30
|
+
__export(oAuth_exports, {
|
|
31
|
+
getOAuthAPI: () => getOAuthAPI
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(oAuth_exports);
|
|
34
|
+
var import_built = __toESM(require("@intlayer/config/built"));
|
|
35
|
+
var import_fetcher = require('../fetcher.cjs');
|
|
36
|
+
const getOAuthAPI = (intlayerConfig) => {
|
|
37
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? import_built.default.editor?.backendURL;
|
|
38
|
+
const { clientId, clientSecret } = intlayerConfig?.editor ?? {};
|
|
39
|
+
if (!backendURL) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
"Backend URL is not defined in the Intlayer configuration."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const getOAuth2AccessToken = async (otherOptions = {}) => await (0, import_fetcher.fetcher)(
|
|
45
|
+
`${backendURL}/oauth2/token`,
|
|
46
|
+
{},
|
|
47
|
+
otherOptions,
|
|
48
|
+
{
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
52
|
+
},
|
|
53
|
+
body: {
|
|
54
|
+
grant_type: "client_credentials",
|
|
55
|
+
client_id: clientId,
|
|
56
|
+
client_secret: clientSecret
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
return {
|
|
61
|
+
getOAuth2AccessToken
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
getOAuthAPI
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=oAuth.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/getIntlayerAPI/oAuth.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/config/client';\nimport { FetcherOptions, fetcher } from '../fetcher';\nimport { GetOAuth2TokenBody, GetOAuth2TokenResult } from '../types';\n\nexport interface oAuthAPI {\n getOAuth2AccessToken: (\n otherOptions?: FetcherOptions\n ) => Promise<GetOAuth2TokenResult>;\n}\n\nexport const getOAuthAPI = (intlayerConfig?: IntlayerConfig): oAuthAPI => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? configuration.editor?.backendURL;\n const { clientId, clientSecret } = intlayerConfig?.editor ?? {};\n\n if (!backendURL) {\n throw new Error(\n 'Backend URL is not defined in the Intlayer configuration.'\n );\n }\n\n /**\n * Gets an oAuth2 accessToken\n * @return The token information\n */\n const getOAuth2AccessToken = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetOAuth2TokenResult>(\n `${backendURL}/oauth2/token`,\n {},\n otherOptions,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: {\n grant_type: 'client_credentials',\n client_id: clientId!,\n client_secret: clientSecret!,\n } satisfies GetOAuth2TokenBody,\n }\n );\n\n return {\n getOAuth2AccessToken,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,qBAAwC;AASjC,MAAM,cAAc,CAAC,mBAA8C;AACxE,QAAM,aACJ,gBAAgB,QAAQ,cAAc,aAAAA,QAAc,QAAQ;AAC9D,QAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB,UAAU,CAAC;AAE9D,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAMA,QAAM,uBAAuB,OAAO,eAA+B,CAAC,MAClE,UAAM;AAAA,IACJ,GAAG,UAAU;AAAA,IACb,CAAC;AAAA,IACD;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,QACJ,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,eAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAEF,SAAO;AAAA,IACL;AAAA,EACF;AACF;","names":["configuration"]}
|
|
@@ -90,6 +90,7 @@ const getUserAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
90
90
|
method: "DELETE"
|
|
91
91
|
}
|
|
92
92
|
);
|
|
93
|
+
const getVerifyEmailStatusURL = (userId) => `${USER_API_ROUTE}/verify-email-status/${String(userId)}`;
|
|
93
94
|
return {
|
|
94
95
|
createUser,
|
|
95
96
|
getUsers,
|
|
@@ -97,7 +98,8 @@ const getUserAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
97
98
|
getUserByAccount,
|
|
98
99
|
getUserByEmail,
|
|
99
100
|
updateUser,
|
|
100
|
-
deleteUser
|
|
101
|
+
deleteUser,
|
|
102
|
+
getVerifyEmailStatusURL
|
|
101
103
|
};
|
|
102
104
|
};
|
|
103
105
|
// Annotate the CommonJS export names for ESM import in node:
|