@intlayer/api 5.6.0 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/getIntlayerAPI/user.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport type {\n CreateUserBody,\n CreateUserResult,\n GetUserByAccountParams,\n GetUserByAccountResult,\n GetUserByEmailParams,\n GetUserByEmailResult,\n GetUserByIdParams,\n GetUserByIdResult,\n GetUsersParams,\n GetUsersResult,\n UpdateUserBody,\n UpdateUserResult,\n} from '../types';\n\nimport { fetcher, type FetcherOptions } from '../fetcher';\n\nexport const getUserAPI = (\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 USER_API_ROUTE = `${backendURL}/api/user`;\n\n /**\n * Retrieves a list of users based on filters and pagination.\n * @param filters - Filters and pagination options.\n * @returns List of users.\n */\n const getUsers = async (\n filters?: GetUsersParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUsersResult>(\n USER_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n params: filters,\n }\n );\n\n /**\n * Retrieves a user by ID.\n * @param userId - User ID.\n * @returns User object.\n */\n const getUserById = async (\n userId: GetUserByIdParams['userId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUserByIdResult>(\n `${USER_API_ROUTE}/${userId}`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Retrieves a user by email.\n * @param email - User email.\n * @returns User object.\n */\n const getUserByEmail = async (\n email: GetUserByEmailParams['email'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUserByEmailResult>(\n `${USER_API_ROUTE}/email/${email}`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Retrieves a user by account.\n * @param providerAccountId - The provider account ID.\n * @param provider - The provider of the account.\n */\n const getUserByAccount = async (\n providerAccountId: GetUserByAccountParams['providerAccountId'],\n provider: GetUserByAccountParams['provider'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUserByAccountResult>(\n `${USER_API_ROUTE}/account/${provider}/${providerAccountId}`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Creates a new user.\n * @param user - User credentials.\n * @returns User object.\n */\n const createUser = async (\n user: CreateUserBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreateUserResult>(\n `${USER_API_ROUTE}/`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: user,\n }\n );\n\n /**\n * Updates the user with the provided data.\n * @param user - Updated user data.\n * @returns User object.\n */\n const updateUser = async (\n user: UpdateUserBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateUserResult>(\n `${USER_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: user,\n }\n );\n\n /**\n * Deletes a user with the provided ID.\n * @param userId - User ID.\n * @returns User object.\n */\n const deleteUser = async (\n userId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateUserResult>(\n `${USER_API_ROUTE}/${userId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\n }\n );\n\n return {\n createUser,\n getUsers,\n getUserById,\n getUserByAccount,\n getUserByEmail,\n updateUser,\n deleteUser,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;
|
|
1
|
+
{"version":3,"sources":["../../../src/getIntlayerAPI/user.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type IntlayerConfig } from '@intlayer/config/client';\nimport type {\n CreateUserBody,\n CreateUserResult,\n GetUserByAccountParams,\n GetUserByAccountResult,\n GetUserByEmailParams,\n GetUserByEmailResult,\n GetUserByIdParams,\n GetUserByIdResult,\n GetUsersParams,\n GetUsersResult,\n UpdateUserBody,\n UpdateUserResult,\n UserAPI,\n} from '../types';\n\nimport { fetcher, type FetcherOptions } from '../fetcher';\n\nexport const getUserAPI = (\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 USER_API_ROUTE = `${backendURL}/api/user`;\n\n /**\n * Retrieves a list of users based on filters and pagination.\n * @param filters - Filters and pagination options.\n * @returns List of users.\n */\n const getUsers = async (\n filters?: GetUsersParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUsersResult>(\n USER_API_ROUTE,\n authAPIOptions,\n otherOptions,\n {\n params: filters,\n }\n );\n\n /**\n * Retrieves a user by ID.\n * @param userId - User ID.\n * @returns User object.\n */\n const getUserById = async (\n userId: GetUserByIdParams['userId'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUserByIdResult>(\n `${USER_API_ROUTE}/${userId}`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Retrieves a user by email.\n * @param email - User email.\n * @returns User object.\n */\n const getUserByEmail = async (\n email: GetUserByEmailParams['email'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUserByEmailResult>(\n `${USER_API_ROUTE}/email/${email}`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Retrieves a user by account.\n * @param providerAccountId - The provider account ID.\n * @param provider - The provider of the account.\n */\n const getUserByAccount = async (\n providerAccountId: GetUserByAccountParams['providerAccountId'],\n provider: GetUserByAccountParams['provider'],\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetUserByAccountResult>(\n `${USER_API_ROUTE}/account/${provider}/${providerAccountId}`,\n authAPIOptions,\n otherOptions\n );\n\n /**\n * Creates a new user.\n * @param user - User credentials.\n * @returns User object.\n */\n const createUser = async (\n user: CreateUserBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreateUserResult>(\n `${USER_API_ROUTE}/`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body: user,\n }\n );\n\n /**\n * Updates the user with the provided data.\n * @param user - Updated user data.\n * @returns User object.\n */\n const updateUser = async (\n user: UpdateUserBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateUserResult>(\n `${USER_API_ROUTE}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'PUT',\n body: user,\n }\n );\n\n /**\n * Deletes a user with the provided ID.\n * @param userId - User ID.\n * @returns User object.\n */\n const deleteUser = async (\n userId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateUserResult>(\n `${USER_API_ROUTE}/${userId}`,\n authAPIOptions,\n otherOptions,\n {\n method: 'DELETE',\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 `${USER_API_ROUTE}/verify-email-status/${String(userId)}`;\n\n return {\n createUser,\n getUsers,\n getUserById,\n getUserByAccount,\n getUserByEmail,\n updateUser,\n deleteUser,\n getVerifyEmailStatusURL,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAkB1B,qBAA6C;AAEtC,MAAM,aAAa,CACxB,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,iBAAiB,GAAG,UAAU;AAOpC,QAAM,WAAW,OACf,SACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,IACV;AAAA,EACF;AAOF,QAAM,cAAc,OAClB,QACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc,IAAI,MAAM;AAAA,IAC3B;AAAA,IACA;AAAA,EACF;AAOF,QAAM,iBAAiB,OACrB,OACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc,UAAU,KAAK;AAAA,IAChC;AAAA,IACA;AAAA,EACF;AAOF,QAAM,mBAAmB,OACvB,mBACA,UACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc,YAAY,QAAQ,IAAI,iBAAiB;AAAA,IAC1D;AAAA,IACA;AAAA,EACF;AAOF,QAAM,aAAa,OACjB,MACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAOF,QAAM,aAAa,OACjB,MACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,MACR,MAAM;AAAA,IACR;AAAA,EACF;AAOF,QAAM,aAAa,OACjB,QACA,eAA+B,CAAC,MAEhC,UAAM;AAAA,IACJ,GAAG,cAAc,IAAI,MAAM;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,MACE,QAAQ;AAAA,IACV;AAAA,EACF;AAOF,QAAM,0BAA0B,CAAC,WAC/B,GAAG,cAAc,wBAAwB,OAAO,MAAM,CAAC;AAEzD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["configuration"]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ __reExport(index_exports, require('./getIntlayerAPI/ai.cjs'), module.exports);
|
|
|
22
22
|
__reExport(index_exports, require('./getIntlayerAPI/auth.cjs'), module.exports);
|
|
23
23
|
__reExport(index_exports, require('./getIntlayerAPI/dictionary.cjs'), module.exports);
|
|
24
24
|
__reExport(index_exports, require('./getIntlayerAPI/editor.cjs'), module.exports);
|
|
25
|
+
__reExport(index_exports, require('./getIntlayerAPI/oAuth.cjs'), module.exports);
|
|
25
26
|
__reExport(index_exports, require('./getIntlayerAPI/organization.cjs'), module.exports);
|
|
26
27
|
__reExport(index_exports, require('./getIntlayerAPI/project.cjs'), module.exports);
|
|
27
28
|
__reExport(index_exports, require('./getIntlayerAPI/stripe.cjs'), module.exports);
|
|
@@ -38,6 +39,7 @@ __reExport(index_exports, require('./types.cjs'), module.exports);
|
|
|
38
39
|
...require('./getIntlayerAPI/auth.cjs'),
|
|
39
40
|
...require('./getIntlayerAPI/dictionary.cjs'),
|
|
40
41
|
...require('./getIntlayerAPI/editor.cjs'),
|
|
42
|
+
...require('./getIntlayerAPI/oAuth.cjs'),
|
|
41
43
|
...require('./getIntlayerAPI/organization.cjs'),
|
|
42
44
|
...require('./getIntlayerAPI/project.cjs'),
|
|
43
45
|
...require('./getIntlayerAPI/stripe.cjs'),
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './distantDictionary/index';\nexport * from './fetcher';\nexport * from './getIntlayerAPI';\nexport * from './getIntlayerAPI/ai';\nexport * from './getIntlayerAPI/auth';\nexport * from './getIntlayerAPI/dictionary';\nexport * from './getIntlayerAPI/editor';\nexport * from './getIntlayerAPI/organization';\nexport * from './getIntlayerAPI/project';\nexport * from './getIntlayerAPI/stripe';\nexport * from './getIntlayerAPI/tag';\nexport * from './getIntlayerAPI/user';\nexport * from './IntlayerEventListener';\nexport * from './types';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,sCAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,6BAFd;AAGA,0BAAc,gCAHd;AAIA,0BAAc,kCAJd;AAKA,0BAAc,wCALd;AAMA,0BAAc,oCANd;AAOA,0BAAc,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './distantDictionary/index';\nexport * from './fetcher';\nexport * from './getIntlayerAPI';\nexport * from './getIntlayerAPI/ai';\nexport * from './getIntlayerAPI/auth';\nexport * from './getIntlayerAPI/dictionary';\nexport * from './getIntlayerAPI/editor';\nexport * from './getIntlayerAPI/oAuth';\nexport * from './getIntlayerAPI/organization';\nexport * from './getIntlayerAPI/project';\nexport * from './getIntlayerAPI/stripe';\nexport * from './getIntlayerAPI/tag';\nexport * from './getIntlayerAPI/user';\nexport * from './IntlayerEventListener';\nexport * from './types';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,sCAAd;AACA,0BAAc,sBADd;AAEA,0BAAc,6BAFd;AAGA,0BAAc,gCAHd;AAIA,0BAAc,kCAJd;AAKA,0BAAc,wCALd;AAMA,0BAAc,oCANd;AAOA,0BAAc,mCAPd;AAQA,0BAAc,0CARd;AASA,0BAAc,qCATd;AAUA,0BAAc,oCAVd;AAWA,0BAAc,iCAXd;AAYA,0BAAc,kCAZd;AAaA,0BAAc,oCAbd;AAcA,0BAAc,oBAdd;","names":[]}
|
package/dist/cjs/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["// @ts-nocheck\n/**\n * This file re-exports all types to allow non-blocking build because\n * the backend and intlayer-editor are not built yet.\n */\nexport type {\n AIOptions,\n AIProvider,\n AddDictionaryBody,\n AddDictionaryResult,\n AddNewAccessKeyBody,\n AddNewAccessKeyResponse,\n AddOrganizationBody,\n AddOrganizationMemberBody,\n AddOrganizationMemberResult,\n AddOrganizationResult,\n AddProjectBody,\n AddProjectResult,\n AddTagBody,\n AddTagResult,\n AskDocQuestionResult,\n AskResetPasswordBody,\n AskResetPasswordResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AutocompleteBody,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n CheckIfUserHasPasswordResult,\n CreateSessionBody,\n CreateSessionResult,\n CreateUserBody,\n CreateUserResult,\n CustomQueryBody,\n CustomQueryResult,\n DefinePasswordBody,\n DefinePasswordResult,\n DeleteAccessKeyBody,\n DeleteAccessKeyResponse,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n DeleteOrganizationResult,\n DeleteProjectResult,\n DeleteTagParams,\n DeleteTagResult,\n GetCheckoutSessionBody,\n GetCheckoutSessionResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n GetOAuth2TokenBody,\n GetOAuth2TokenResult,\n GetOrganizationParam,\n GetOrganizationResult,\n GetOrganizationsParams,\n GetOrganizationsResult,\n GetPricingBody,\n GetPricingResult,\n GetProjectsParams,\n GetProjectsResult,\n GetSessionInformationQuery,\n GetSessionInformationResult,\n GetTagsParams,\n GetTagsResult,\n GetUserByAccountParams,\n GetUserByAccountResult,\n GetUserByEmailParams,\n GetUserByEmailResult,\n GetUserByIdParams,\n GetUserByIdResult,\n GetUsersParams,\n GetUsersResult,\n GithubLoginQueryParams,\n GoogleLoginQueryParams,\n LoginBody,\n LoginResult,\n Messages,\n NewsletterSubscriptionBody,\n NewsletterSubscriptionResult,\n NewsletterUnsubscriptionBody,\n PushDictionariesBody,\n PushDictionariesResult,\n PushProjectConfigurationBody,\n PushProjectConfigurationResult,\n RefreshAccessKeyBody,\n RefreshAccessKeyResponse,\n RegisterBody,\n RegisterQuery,\n RegisterResult,\n SearchDocUtilParams,\n SearchDocUtilResult,\n SelectOrganizationParam,\n SelectOrganizationResult,\n SelectProjectParam,\n SelectProjectResult,\n SetCSRFTokenResult,\n TranslateJSONBody,\n TranslateJSONResult,\n UnselectOrganizationResult,\n UnselectProjectResult,\n UpdateDictionaryBody,\n UpdateDictionaryParam,\n UpdateDictionaryResult,\n UpdateOrganizationBody,\n UpdateOrganizationMembersBody,\n UpdateOrganizationMembersResult,\n UpdateOrganizationResult,\n UpdatePasswordBody,\n UpdatePasswordResult,\n UpdateProjectBody,\n UpdateProjectMembersBody,\n UpdateProjectMembersResult,\n UpdateProjectResult,\n UpdateTagBody,\n UpdateTagParams,\n UpdateTagResult,\n UpdateUserBody,\n UpdateUserResult,\n UserAPI,\n ValidEmailParams,\n ValidEmailResult,\n} from '@intlayer/backend';\nexport type {\n GetConfigurationResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from 'intlayer-editor';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["// @ts-nocheck\n/**\n * This file re-exports all types to allow non-blocking build because\n * the backend and intlayer-editor are not built yet.\n */\nexport type {\n AIOptions,\n AIProvider,\n AddDictionaryBody,\n AddDictionaryResult,\n AddNewAccessKeyBody,\n AddNewAccessKeyResponse,\n AddOrganizationBody,\n AddOrganizationMemberBody,\n AddOrganizationMemberResult,\n AddOrganizationResult,\n AddProjectBody,\n AddProjectResult,\n AddTagBody,\n AddTagResult,\n AskDocQuestionResult,\n AskResetPasswordBody,\n AskResetPasswordResult,\n AuditContentDeclarationBody,\n AuditContentDeclarationFieldBody,\n AuditContentDeclarationFieldResult,\n AuditContentDeclarationMetadataBody,\n AuditContentDeclarationMetadataResult,\n AuditContentDeclarationResult,\n AuditTagBody,\n AuditTagResult,\n AuthClient,\n AutocompleteBody,\n AutocompleteResponse,\n ChatCompletionRequestMessage,\n CheckIfUserHasPasswordResult,\n CreateSessionBody,\n CreateSessionResult,\n CreateUserBody,\n CreateUserResult,\n CustomQueryBody,\n CustomQueryResult,\n DefinePasswordBody,\n DefinePasswordResult,\n DeleteAccessKeyBody,\n DeleteAccessKeyResponse,\n DeleteDictionaryParam,\n DeleteDictionaryResult,\n DeleteOrganizationResult,\n DeleteProjectResult,\n DeleteTagParams,\n DeleteTagResult,\n GetCheckoutSessionBody,\n GetCheckoutSessionResult,\n GetDictionariesKeysResult,\n GetDictionariesParams,\n GetDictionariesResult,\n GetDictionaryParams,\n GetDictionaryQuery,\n GetDictionaryResult,\n GetOAuth2TokenBody,\n GetOAuth2TokenBody,\n GetOAuth2TokenResult,\n GetOAuth2TokenResult,\n GetOrganizationParam,\n GetOrganizationResult,\n GetOrganizationsParams,\n GetOrganizationsResult,\n GetPricingBody,\n GetPricingResult,\n GetProjectsParams,\n GetProjectsResult,\n GetSessionInformationQuery,\n GetSessionInformationResult,\n GetTagsParams,\n GetTagsResult,\n GetUserByAccountParams,\n GetUserByAccountResult,\n GetUserByEmailParams,\n GetUserByEmailResult,\n GetUserByIdParams,\n GetUserByIdResult,\n GetUsersParams,\n GetUsersResult,\n GithubLoginQueryParams,\n GoogleLoginQueryParams,\n LoginBody,\n LoginResult,\n Messages,\n NewsletterSubscriptionBody,\n NewsletterSubscriptionResult,\n NewsletterUnsubscriptionBody,\n PushDictionariesBody,\n PushDictionariesResult,\n PushProjectConfigurationBody,\n PushProjectConfigurationResult,\n RefreshAccessKeyBody,\n RefreshAccessKeyResponse,\n RegisterBody,\n RegisterQuery,\n RegisterResult,\n SearchDocUtilParams,\n SearchDocUtilResult,\n SelectOrganizationParam,\n SelectOrganizationResult,\n SelectProjectParam,\n SelectProjectResult,\n SetCSRFTokenResult,\n TranslateJSONBody,\n TranslateJSONResult,\n UnselectOrganizationResult,\n UnselectProjectResult,\n UpdateDictionaryBody,\n UpdateDictionaryParam,\n UpdateDictionaryResult,\n UpdateOrganizationBody,\n UpdateOrganizationMembersBody,\n UpdateOrganizationMembersResult,\n UpdateOrganizationResult,\n UpdatePasswordBody,\n UpdatePasswordResult,\n UpdateProjectBody,\n UpdateProjectMembersBody,\n UpdateProjectMembersResult,\n UpdateProjectResult,\n UpdateTagBody,\n UpdateTagParams,\n UpdateTagResult,\n UpdateUserBody,\n UpdateUserResult,\n UserAPI,\n ValidEmailParams,\n ValidEmailResult,\n} from '@intlayer/backend';\nexport type {\n GetConfigurationResult,\n WriteContentDeclarationBody,\n WriteContentDeclarationResult,\n} from 'intlayer-editor';\n\nexport type AutocompleteBody = {\n text: string;\n aiOptions?: AIOptions;\n contextBefore?: string;\n currentLine?: string;\n contextAfter?: string;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import configuration from "@intlayer/config/built";
|
|
2
|
-
import {
|
|
2
|
+
import { getOAuthAPI } from "./getIntlayerAPI/oAuth.mjs";
|
|
3
3
|
class IntlayerEventListener {
|
|
4
4
|
constructor(intlayerConfig = configuration) {
|
|
5
5
|
this.intlayerConfig = intlayerConfig;
|
|
@@ -23,19 +23,12 @@ class IntlayerEventListener {
|
|
|
23
23
|
*/
|
|
24
24
|
async initialize() {
|
|
25
25
|
const backendURL = this.intlayerConfig.editor.backendURL;
|
|
26
|
-
const
|
|
27
|
-
{},
|
|
26
|
+
const accessToken = await getOAuthAPI(
|
|
28
27
|
this.intlayerConfig
|
|
29
28
|
).getOAuth2AccessToken();
|
|
30
|
-
const accessToken = oAuth2TokenResult.data?.accessToken;
|
|
31
29
|
if (!accessToken) {
|
|
32
30
|
throw new Error("Failed to retrieve access token");
|
|
33
31
|
}
|
|
34
|
-
if (oAuth2TokenResult.data?.organization.plan?.type !== "ENTERPRISE") {
|
|
35
|
-
throw new Error(
|
|
36
|
-
"Hot reload is enabled, but is only available for enterprise plans"
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
32
|
const API_ROUTE = `${backendURL}/api/event-listener`;
|
|
40
33
|
const url = `${API_ROUTE}/${accessToken}`;
|
|
41
34
|
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":"AAEA,OAAO,mBAAmB;AAE1B,SAAS,mBAAmB;AA4BrB,MAAM,sBAAsB;AAAA,EAkBjC,YAAoB,iBAAiC,eAAe;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,MAAM;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":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import configuration from "@intlayer/config/built";
|
|
2
|
-
import { getAuthAPI } from "../getIntlayerAPI/auth.mjs";
|
|
3
2
|
import { getDictionaryAPI } from "../getIntlayerAPI/dictionary.mjs";
|
|
3
|
+
import { getOAuthAPI } from "../getIntlayerAPI/oAuth.mjs";
|
|
4
4
|
const fetchDistantDictionaries = async (intlayerConfig = configuration) => {
|
|
5
5
|
try {
|
|
6
6
|
const { clientId, clientSecret } = intlayerConfig?.editor;
|
|
@@ -10,9 +10,8 @@ const fetchDistantDictionaries = async (intlayerConfig = configuration) => {
|
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
const dictionaryAPI = getDictionaryAPI(void 0, intlayerConfig);
|
|
13
|
-
const authAPI =
|
|
14
|
-
const
|
|
15
|
-
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
13
|
+
const authAPI = getOAuthAPI(intlayerConfig);
|
|
14
|
+
const oAuth2AccessToken = await authAPI.getOAuth2AccessToken();
|
|
16
15
|
const getDictionaryResult = await dictionaryAPI.getDictionaries(void 0, {
|
|
17
16
|
...oAuth2AccessToken && {
|
|
18
17
|
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":"AAEA,OAAO,mBAAmB;AAE1B,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAKrB,MAAM,2BAA2B,OACtC,iBAAiC,kBACe;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,gBAAgB,iBAAiB,QAAW,cAAc;AAChE,UAAM,UAAU,YAAY,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":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import configuration from "@intlayer/config/built";
|
|
2
|
-
import { getAuthAPI } from "../getIntlayerAPI/auth.mjs";
|
|
3
2
|
import { getDictionaryAPI } from "../getIntlayerAPI/dictionary.mjs";
|
|
3
|
+
import { getOAuthAPI } from "../getIntlayerAPI/oAuth.mjs";
|
|
4
4
|
const fetchDistantDictionary = async (dictionaryKey, intlayerConfig = configuration) => {
|
|
5
5
|
try {
|
|
6
6
|
const { clientId, clientSecret } = intlayerConfig?.editor;
|
|
@@ -10,16 +10,15 @@ const fetchDistantDictionary = async (dictionaryKey, intlayerConfig = configurat
|
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
const dictionaryAPI = getDictionaryAPI(void 0, intlayerConfig);
|
|
13
|
-
const authAPI =
|
|
14
|
-
const
|
|
15
|
-
const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
|
|
13
|
+
const authAPI = getOAuthAPI(intlayerConfig);
|
|
14
|
+
const accessToken = await authAPI.getOAuth2AccessToken();
|
|
16
15
|
const getDictionaryResult = await dictionaryAPI.getDictionary(
|
|
17
16
|
dictionaryKey,
|
|
18
17
|
void 0,
|
|
19
18
|
{
|
|
20
|
-
...
|
|
19
|
+
...accessToken && {
|
|
21
20
|
headers: {
|
|
22
|
-
Authorization: `Bearer ${
|
|
21
|
+
Authorization: `Bearer ${accessToken}`
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
}
|
|
@@ -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":"AAEA,OAAO,mBAAmB;AAE1B,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAKrB,MAAM,yBAAyB,OACpC,eACA,iBAAiC,kBACM;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,gBAAgB,iBAAiB,QAAW,cAAc;AAChE,UAAM,UAAU,YAAY,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":[]}
|
|
@@ -74,12 +74,29 @@ const getAiAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
74
74
|
...authAPIOptions.headers,
|
|
75
75
|
...otherOptions.headers
|
|
76
76
|
},
|
|
77
|
-
body: JSON.stringify(
|
|
78
|
-
|
|
77
|
+
body: JSON.stringify({
|
|
78
|
+
...rest,
|
|
79
|
+
...authAPIOptions.body,
|
|
80
|
+
...otherOptions.body
|
|
81
|
+
}),
|
|
82
|
+
signal: abortController.signal,
|
|
83
|
+
credentials: "include"
|
|
79
84
|
});
|
|
80
85
|
if (!response.ok) {
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
let errorMessage = "An error occurred";
|
|
87
|
+
try {
|
|
88
|
+
const errorData = await response.json();
|
|
89
|
+
errorMessage = JSON.stringify(errorData.error) ?? "An error occurred";
|
|
90
|
+
} catch {
|
|
91
|
+
try {
|
|
92
|
+
const errorText = await response.text();
|
|
93
|
+
if (errorText) {
|
|
94
|
+
errorMessage = errorText;
|
|
95
|
+
}
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
throw new Error(errorMessage);
|
|
83
100
|
}
|
|
84
101
|
const reader = response.body?.getReader();
|
|
85
102
|
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":"AAmBA,OAAO,mBAAmB;AAG1B,SAAS,eAAoC;AAWtC,MAAM,WAAW,CACtB,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,aACJ,gBAAgB,QAAQ,cAAc,cAAc,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,MAAM;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,MAAM;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,MAAM;AAAA,IACJ,GAAG,YAAY;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAA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AAI,YAAY;AAChC,UAAI,SAAS;AAEb,aAAO,MAAM;AACX,cAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;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,MAAM;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":[]}
|
|
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":"AAmBA,OAAO,mBAAmB;AAG1B,SAAS,eAAoC;AAWtC,MAAM,WAAW,CACtB,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,aACJ,gBAAgB,QAAQ,cAA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AAO;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,MAAM;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":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import configuration from "@intlayer/config/built";
|
|
2
|
-
import {
|
|
3
|
-
const getAuthAPI = (
|
|
2
|
+
import { createAuthClient } from "better-auth/client";
|
|
3
|
+
const getAuthAPI = (intlayerConfig) => {
|
|
4
4
|
const backendURL = intlayerConfig?.editor?.backendURL ?? configuration.editor?.backendURL;
|
|
5
5
|
const { clientId, clientSecret } = intlayerConfig?.editor ?? {};
|
|
6
6
|
if (!backendURL) {
|
|
@@ -8,138 +8,60 @@ const getAuthAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
8
8
|
"Backend URL is not defined in the Intlayer configuration."
|
|
9
9
|
);
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
const
|
|
40
|
-
`${AUTH_API_ROUTE}/logout`,
|
|
41
|
-
authAPIOptions,
|
|
42
|
-
otherOptions,
|
|
43
|
-
{
|
|
44
|
-
method: "POST"
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
const askResetPassword = async (email, otherOptions = {}) => await fetcher(
|
|
48
|
-
`${AUTH_API_ROUTE}/password/reset`,
|
|
49
|
-
authAPIOptions,
|
|
50
|
-
otherOptions,
|
|
51
|
-
{
|
|
52
|
-
method: "POST",
|
|
53
|
-
body: { email }
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
const defineNewPassword = async (data, otherOptions = {}) => await fetcher(
|
|
57
|
-
`${AUTH_API_ROUTE}/password/define`,
|
|
58
|
-
authAPIOptions,
|
|
59
|
-
otherOptions,
|
|
60
|
-
{
|
|
61
|
-
method: "POST",
|
|
62
|
-
body: data
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
const changePassword = async (data, otherOptions = {}) => await fetcher(
|
|
66
|
-
`${AUTH_API_ROUTE}/password`,
|
|
67
|
-
authAPIOptions,
|
|
68
|
-
otherOptions,
|
|
69
|
-
{
|
|
70
|
-
method: "PUT",
|
|
71
|
-
body: data
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
const checkIfUserHasPassword = async (otherOptions = {}) => await fetcher(
|
|
75
|
-
`${AUTH_API_ROUTE}/password/has`,
|
|
76
|
-
authAPIOptions,
|
|
77
|
-
otherOptions,
|
|
78
|
-
{
|
|
79
|
-
method: "GET"
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
const verifyEmail = async ({ userId, secret }, otherOptions = {}) => await fetcher(
|
|
83
|
-
`${AUTH_API_ROUTE}/active/${userId}/${secret}`,
|
|
84
|
-
authAPIOptions,
|
|
85
|
-
otherOptions,
|
|
86
|
-
{
|
|
87
|
-
method: "PUT"
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
const getVerifyEmailStatusURL = (userId) => `${AUTH_API_ROUTE}/verify-email-status/${String(userId)}`;
|
|
91
|
-
const createSession = async (data, otherOptions = {}) => await fetcher(
|
|
92
|
-
`${AUTH_API_ROUTE}/session`,
|
|
93
|
-
authAPIOptions,
|
|
94
|
-
otherOptions,
|
|
95
|
-
{
|
|
96
|
-
method: "POST",
|
|
97
|
-
body: data
|
|
98
|
-
}
|
|
99
|
-
);
|
|
100
|
-
const getSession = async (sessionToken, otherOptions = {}) => await fetcher(
|
|
101
|
-
`${backendURL}/session`,
|
|
102
|
-
authAPIOptions,
|
|
103
|
-
otherOptions,
|
|
104
|
-
{ params: { session_token: sessionToken } }
|
|
105
|
-
);
|
|
106
|
-
const getCSRFToken = async (otherOptions = {}) => await fetcher(
|
|
107
|
-
`${backendURL}/csrf-token`,
|
|
108
|
-
authAPIOptions,
|
|
109
|
-
otherOptions
|
|
110
|
-
);
|
|
111
|
-
const getOAuth2AccessToken = async (otherOptions = {}) => await fetcher(
|
|
112
|
-
`${backendURL}/oauth2/token`,
|
|
113
|
-
authAPIOptions,
|
|
114
|
-
otherOptions,
|
|
115
|
-
{
|
|
116
|
-
method: "POST",
|
|
117
|
-
headers: {
|
|
118
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
119
|
-
},
|
|
120
|
-
body: {
|
|
121
|
-
grant_type: "client_credentials",
|
|
122
|
-
client_id: clientId,
|
|
123
|
-
client_secret: clientSecret
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
);
|
|
11
|
+
const authClient = createAuthClient({
|
|
12
|
+
baseURL: backendURL,
|
|
13
|
+
withCredentials: true
|
|
14
|
+
// makes fetch forward cookies
|
|
15
|
+
});
|
|
16
|
+
const signInEmail = async (...args) => await authClient.signIn.email(...args);
|
|
17
|
+
const signInSocial = async (...args) => await authClient.signIn.social(...args);
|
|
18
|
+
const signUpEmail = async (...args) => await authClient.signUp.email(...args);
|
|
19
|
+
const signOut = async (...args) => await authClient.signOut(...args);
|
|
20
|
+
const changePasswordSession = async (...args) => await authClient.changePassword(...args);
|
|
21
|
+
const requestPasswordResetSession = async (...args) => await authClient.requestPasswordReset(...args);
|
|
22
|
+
const resetPassword = authClient.resetPassword;
|
|
23
|
+
const verifyEmailSession = async (...args) => await authClient.verifyEmail(...args);
|
|
24
|
+
const getSession = async (...args) => await authClient.getSession(...args);
|
|
25
|
+
const forgetPassword = async (...args) => await authClient.forgetPassword(...args);
|
|
26
|
+
const sendVerificationEmail = async (...args) => await authClient.sendVerificationEmail(...args);
|
|
27
|
+
const changeEmail = async (...args) => await authClient.changeEmail(...args);
|
|
28
|
+
const deleteUser = authClient.deleteUser;
|
|
29
|
+
const revokeSession = async (...args) => await authClient.revokeSession(...args);
|
|
30
|
+
const revokeSessions = async (...args) => await authClient.revokeSessions(...args);
|
|
31
|
+
const revokeOtherSessions = async (...args) => await authClient.revokeOtherSessions(...args);
|
|
32
|
+
const linkSocial = async (...args) => await authClient.linkSocial(...args);
|
|
33
|
+
const listAccounts = async (...args) => await authClient.listAccounts(...args);
|
|
34
|
+
const unlinkAccount = async (...args) => await authClient.unlinkAccount(...args);
|
|
35
|
+
const refreshToken = async (...args) => await authClient.refreshToken(...args);
|
|
36
|
+
const getAccessToken = async (...args) => await authClient.getAccessToken(...args);
|
|
37
|
+
const accountInfo = async (...args) => await authClient.accountInfo(...args);
|
|
38
|
+
const updateUser = async (...args) => await authClient.updateUser(...args);
|
|
39
|
+
const listSessions = async (...args) => await authClient.listSessions(...args);
|
|
127
40
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
getVerifyEmailStatusURL,
|
|
138
|
-
changePassword,
|
|
139
|
-
createSession,
|
|
41
|
+
signInEmail,
|
|
42
|
+
signUpEmail,
|
|
43
|
+
signOut,
|
|
44
|
+
signInSocial,
|
|
45
|
+
linkSocial,
|
|
46
|
+
changePasswordSession,
|
|
47
|
+
requestPasswordResetSession,
|
|
48
|
+
resetPassword,
|
|
49
|
+
verifyEmailSession,
|
|
140
50
|
getSession,
|
|
141
|
-
|
|
142
|
-
|
|
51
|
+
forgetPassword,
|
|
52
|
+
sendVerificationEmail,
|
|
53
|
+
changeEmail,
|
|
54
|
+
deleteUser,
|
|
55
|
+
revokeSession,
|
|
56
|
+
revokeSessions,
|
|
57
|
+
revokeOtherSessions,
|
|
58
|
+
listAccounts,
|
|
59
|
+
unlinkAccount,
|
|
60
|
+
refreshToken,
|
|
61
|
+
getAccessToken,
|
|
62
|
+
accountInfo,
|
|
63
|
+
updateUser,
|
|
64
|
+
listSessions
|
|
143
65
|
};
|
|
144
66
|
};
|
|
145
67
|
export {
|
|
@@ -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,OAAO,mBAAmB;AA6B1B,SAAS,eAAoC;AAEtC,MAAM,aAAa,CACxB,iBAAiC,CAAC,GAClC,mBACG;AACH,QAAM,aACJ,gBAAgB,QAAQ,cAAc,cAAc,QAAQ;AAC9D,QAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB,UAAU,CAAC;AAE9D,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAA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A,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":[]}
|
|
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,OAAO,mBAAmB;AAE1B,SAAS,wBAAwB;AA+B1B,MAAM,aAAa,CAAC,mBAA6C;AACtE,QAAM,aACJ,gBAAgB,QAAQ,cAAc,cAAc,QAAQ;AAC9D,QAAM,EAAE,UAAU,aAAa,IAAI,gBAAgB,UAAU,CAAC;AAE9D,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAIA,QAAM,aAAyB,iBAAiB;AAAA,IAC9C,SAAS;AAAA,IACT,iBAAiB;AAAA;AAAA,EACnB,CAAC;AAED,QAAM,cAA6C,UAAU,SAC3D,MAAM,WAAW,OAAO,MAAM,GAAG,IAAI;AAEvC,QAAM,eAA+C,UAAU,SAC7D,MAAM,WAAW,OAAO,OAAO,GAAG,IAAI;AAExC,QAAM,cAA6C,UAAU,SAC3D,MAAM,WAAW,OAAO,MAAM,GAAG,IAAI;AAEvC,QAAM,UAAiC,UAAU,SAC/C,MAAM,WAAW,QAAQ,GAAG,IAAI;AAElC,QAA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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":[]}
|
|
@@ -3,6 +3,7 @@ import { getAuthAPI } from "./auth.mjs";
|
|
|
3
3
|
import { getDictionaryAPI } from "./dictionary.mjs";
|
|
4
4
|
import { getEditorAPI } from "./editor.mjs";
|
|
5
5
|
import { getNewsletterAPI } from "./newsletter.mjs";
|
|
6
|
+
import { getOAuthAPI } from "./oAuth.mjs";
|
|
6
7
|
import { getOrganizationAPI } from "./organization.mjs";
|
|
7
8
|
import { getProjectAPI } from "./project.mjs";
|
|
8
9
|
import { getSearchAPI } from "./search.mjs";
|
|
@@ -13,7 +14,8 @@ const getIntlayerAPI = (authAPIOptions = {}, intlayerConfig) => ({
|
|
|
13
14
|
organization: getOrganizationAPI(authAPIOptions, intlayerConfig),
|
|
14
15
|
project: getProjectAPI(authAPIOptions, intlayerConfig),
|
|
15
16
|
user: getUserAPI(authAPIOptions, intlayerConfig),
|
|
16
|
-
auth: getAuthAPI(
|
|
17
|
+
auth: getAuthAPI(intlayerConfig),
|
|
18
|
+
oAuth: getOAuthAPI(intlayerConfig),
|
|
17
19
|
dictionary: getDictionaryAPI(authAPIOptions, intlayerConfig),
|
|
18
20
|
stripe: getStripeAPI(authAPIOptions, intlayerConfig),
|
|
19
21
|
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":"AAEA,SAAS,gBAAgB;AACzB,SAAkB,kBAAkB;AACpC,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC,SAAS,mBAA6B;AACtC,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAiBpB,MAAM,iBAAiB,CAC5B,iBAAiC,CAAC,GAClC,oBACuB;AAAA,EACvB,cAAc,mBAAmB,gBAAgB,cAAc;AAAA,EAC/D,SAAS,cAAc,gBAAgB,cAAc;AAAA,EACrD,MAAM,WAAW,gBAAgB,cAAc;AAAA,EAC/C,MAAM,WAAW,cAAc;AAAA,EAC/B,OAAO,YAAY,cAAc;AAAA,EACjC,YAAY,iBAAiB,gBAAgB,cAAc;AAAA,EAC3D,QAAQ,aAAa,gBAAgB,cAAc;AAAA,EACnD,IAAI,SAAS,gBAAgB,cAAc;AAAA,EAC3C,KAAK,UAAU,gBAAgB,cAAc;AAAA,EAC7C,QAAQ,aAAa,gBAAgB,cAAc;AAAA,EACnD,QAAQ,aAAa,gBAAgB,cAAc;AAAA,EACnD,YAAY,iBAAiB,gBAAgB,cAAc;AAC7D;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
2
|
+
import { fetcher } from "../fetcher.mjs";
|
|
3
|
+
const getOAuthAPI = (intlayerConfig) => {
|
|
4
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? configuration.editor?.backendURL;
|
|
5
|
+
const { clientId, clientSecret } = intlayerConfig?.editor ?? {};
|
|
6
|
+
if (!backendURL) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"Backend URL is not defined in the Intlayer configuration."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const getOAuth2AccessToken = async (otherOptions = {}) => await fetcher(
|
|
12
|
+
`${backendURL}/oauth2/token`,
|
|
13
|
+
{},
|
|
14
|
+
otherOptions,
|
|
15
|
+
{
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: {
|
|
18
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
19
|
+
},
|
|
20
|
+
body: {
|
|
21
|
+
grant_type: "client_credentials",
|
|
22
|
+
client_id: clientId,
|
|
23
|
+
client_secret: clientSecret
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
return {
|
|
28
|
+
getOAuth2AccessToken
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
getOAuthAPI
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=oAuth.mjs.map
|