@growi/sdk-typescript 1.7.0 → 1.8.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/CHANGELOG.md +6 -0
- package/dist/apiv1/index.d.ts +19 -19
- package/dist/apiv3/index.d.ts +235 -235
- package/dist/generated/v1/index.d.ts +1 -1
- package/dist/generated/v1/index.schemas.d.ts +1 -1
- package/dist/generated/v3/index.d.ts +1 -1
- package/dist/generated/v3/index.schemas.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/axios-instance-manager.d.ts +27 -0
- package/dist/utils/axios-instance-manager.d.ts.map +1 -0
- package/dist/utils/axios-instance-manager.js +36 -0
- package/dist/utils/axios-instance-manager.js.map +1 -0
- package/dist/utils/types/custom-instance.d.ts +6 -0
- package/dist/utils/types/custom-instance.d.ts.map +1 -0
- package/dist/utils/types/custom-instance.js +2 -0
- package/dist/utils/types/custom-instance.js.map +1 -0
- package/dist/utils/v1/axios-instance.d.ts +2 -1
- package/dist/utils/v1/axios-instance.d.ts.map +1 -1
- package/dist/utils/v1/axios-instance.js +9 -5
- package/dist/utils/v1/axios-instance.js.map +1 -1
- package/dist/utils/v3/axios-instance.d.ts +2 -1
- package/dist/utils/v3/axios-instance.d.ts.map +1 -1
- package/dist/utils/v3/axios-instance.js +9 -5
- package/dist/utils/v3/axios-instance.js.map +1 -1
- package/package.json +1 -1
- package/src/generated/v1/index.schemas.ts +1 -1
- package/src/generated/v1/index.ts +1 -1
- package/src/generated/v3/index.schemas.ts +1 -1
- package/src/generated/v3/index.ts +1 -1
- package/src/index.ts +1 -1
- package/src/utils/axios-instance-manager.ts +41 -0
- package/src/utils/types/custom-instance.ts +6 -0
- package/src/utils/v1/axios-instance.test.ts +26 -15
- package/src/utils/v1/axios-instance.ts +13 -6
- package/src/utils/v3/axios-instance.test.ts +43 -25
- package/src/utils/v3/axios-instance.ts +13 -6
- package/dist/utils/axios-default-instance.d.ts +0 -14
- package/dist/utils/axios-default-instance.d.ts.map +0 -1
- package/dist/utils/axios-default-instance.js +0 -22
- package/dist/utils/axios-default-instance.js.map +0 -1
- package/src/utils/axios-default-instance.test.ts +0 -108
- package/src/utils/axios-default-instance.ts +0 -23
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Generated by orval v7.9.0 🍺
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* GROWI REST API v1
|
|
5
|
-
* OpenAPI spec version: 7.3.
|
|
5
|
+
* OpenAPI spec version: 7.3.3-RC.0
|
|
6
6
|
*/
|
|
7
7
|
import type { AddComment200, AddCommentBody, ApiResponseSuccess, GetComments200, GetCommentsParams, GetPageTagParams, GetUpdatePostParams, ListTags200, ListTagsParams, PageRemoveSuccessResponse, PageRevertSuccessResponse, PageTagsSuccessResponse, PageUnlinkSuccessResponse, PostLogin200, PostLoginBody, PostRegister200, PostRegisterBody, RemoveAttachmentBody, RemoveCommentBody, RemovePageBody, RemoveProfileImageBody, RevertRemovePageBody, SearchPages200, SearchPagesParams, SearchTags200, SearchTagsParams, UnlinkPageBody, UpdateComment200, UpdateCommentBody, UpdatePostSuccessResponse, UpdateTag200, UpdateTagBody, UploadProfileImage200, UploadProfileImageBodyOne, UploadProfileImageBodyTwo } from './index.schemas.js';
|
|
8
8
|
import { customInstance } from '../../utils/v1/axios-instance.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Generated by orval v7.9.0 🍺
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* GROWI REST API v3
|
|
5
|
-
* OpenAPI spec version: 7.3.
|
|
5
|
+
* OpenAPI spec version: 7.3.3-RC.0
|
|
6
6
|
*/
|
|
7
7
|
import type { ActivityResponse, AppSettingPutParams, AttachmentPaginateResult, BookmarkInfo, BookmarkParams, Bookmarks, BotType, CustomizeCss, CustomizeFunction, CustomizeHighlight, CustomizeLayout, CustomizeLogo, CustomizeNoscript, CustomizePresentation, CustomizeScript, CustomizeSidebar, CustomizeTheme, CustomizeTitle, DeleteAllForShareLinks200, DeleteAllShareLinksForSecuritySetting200, DeleteBookmarkFolderById200, DeleteEmptyTrashForPages200, DeleteExportByFileName200, DeleteExternalUserGroupsById200, DeleteExternalUserGroupsByIdParams, DeleteRemoveByIdForPlugins200, DeleteRemoveByIdForUsers200, DeleteRemoveByIdForUsersExternalAccounts200, DeleteShareLinksParams, DeleteSlackAppIntegrationsByIdForSlackIntegrationSettings200, DeleteUserGroupsById200, DeleteUserGroupsByIdParams, DeleteUsersByUsernameByIdForUserGroups200, DisassociateUser, FileImportResponse, FileUploadSettingParams, GeneralSetting, GetAccessTokenForPersonalSetting200, GetActivityParams, GetAdminHome200, GetAllShareLinksForSecuritySetting200, GetAncestorsChildrenForPageListing200, GetAncestorsChildrenForPageListingParams, GetAncestorsForExternalUserGroups200, GetAncestorsForExternalUserGroupsParams, GetAncestorsForUserGroups200, GetAncestorsForUserGroupsParams, GetAppSettings200, GetApplicableGrantForPage200, GetApplicableGrantForPageParams, GetAttachmentById200, GetAuthenticationForSecuritySetting200, GetChildrenForExternalUserGroups200, GetChildrenForExternalUserGroupsParams, GetChildrenForPageListing200, GetChildrenForPageListingParams, GetChildrenForUserGroups200, GetChildrenForUserGroupsParams, GetCollectionsForMongo200, GetCustomizeSetting200, GetEditorSettingsForPersonalSetting200, GetExistForPage200, GetExistForPageParams, GetExistPathsForPage200, GetExistPathsForPageParams, GetExternalAccountsForPersonalSetting200, GetExternalAccountsForUsers200, GetExternalAccountsForUsersParams, GetExternalUserGroupRelations200, GetExternalUserGroupRelationsByIdForExternalUserGroups200, GetExternalUserGroupRelationsParams, GetExternalUserGroups200, GetExternalUserGroupsById200, GetExternalUserGroupsParams, GetFilesForG2gTransfer200, GetGlobalNotificationByIdForNotificationSetting200, GetGrantDataForPage200, GetGrantDataForPageParams, GetGrowiInfoForG2gTransfer200, GetHealthcheck200, GetHealthcheckParams, GetImport200, GetInAppNotificationSettingsForPersonalSetting200, GetIndicesForSearch200, GetInfoForBookmarksParams, GetInfoForPageListing200, GetInfoForPageListingParams, GetInfoForPageParams, GetIsPasswordSetForPersonalSetting200, GetLimitForAttachment200, GetLimitForAttachmentParams, GetListByUserIdForBookmarkFolder200, GetListForAttachmentParams, GetListForInAppNotificationParams, GetListForPages200, GetListForPagesParams, GetListForRevisions200, GetListForRevisionsParams, GetListForUsers200, GetListForUsersParams, GetMarkdownSetting200, GetNonUserRelatedGroupsGrantedForPage200, GetNonUserRelatedGroupsGrantedForPageParams, GetNotificationSetting200, GetPageParams, GetPagesByIdForUserGroups200, GetPersonalSetting200, GetPluginTemplatesByLocaleByTemplateIdByReposIdByOrganizationIdForTemplates200, GetPresetTemplatesByLocaleByTemplateIdForTemplates200, GetRecentByIdForUsers200, GetRecentForPagesParams, GetRevisionsById200, GetRevisionsByIdParams, GetRootForPageListing200, GetSecuritySetting200, GetSelectableChildGroups200, GetSelectableChildGroupsParams, GetSelectableParentGroups200, GetSelectableParentGroupsParams, GetShareLinks200, GetShareLinksParams, GetSlackIntegrationLegacySetting200, GetSlackIntegrationSettings200, GetStatusForExport200, GetStatusForImport200, GetStatusForInAppNotification200, GetSubordinatedListForPages200, GetSubordinatedListForPagesParams, GetSupportedCommandsForSlackIntegration200, GetSyncSettingsForExternalUserGroupsKeycloak200, GetSyncSettingsForExternalUserGroupsLdap200, GetTemplates200, GetTemplatesParams, GetThemeForCustomizeSetting200, GetUnrelatedUsersByIdForUserGroups200, GetUnrelatedUsersByIdForUserGroupsParams, GetUserGroupRelations200, GetUserGroupRelationsByIdForUserGroups200, GetUserGroups200, GetUserGroupsById200, GetUserGroupsParams, GetUsernamesForUsers200, GetUsernamesForUsersParams, GetUsers200, GetUsersByIdForUserGroups200, GetUsersParams, GetV5MigrationStatusForPages200, GetYjsDataByPageId200, GitHubOAuthSetting, GlobalNotification, GlobalNotificationParams, GoogleOAuthSetting, InAppNotificationListResponse, IndentParams, LdapAuthSetting, LikeParams, LineBreakParams, LocalSetting, NotifyForPageGrant, OidcAuthSetting, Page, PageInfoAll, PersonalSettings, PostAccessTokenForPersonalSetting200, PostAddBookmarkToFolderForBookmarkFolder200, PostAddBookmarkToFolderForBookmarkFolderBody, PostAttachment200, PostAttachmentBodyOne, PostAttachmentBodyTwo, PostAttachmentForG2gTransfer200, PostAttachmentForG2gTransferBody, PostBookmarkFolder200, PostBookmarkFolderBody, PostCommandsForSlackIntegrationBody, PostCommandsForSlackIntegrationProxiedBody, PostCompleteRegistration200, PostCompleteRegistrationBody, PostConvertPagesByPathForPages200, PostConvertPagesByPathForPagesBody, PostDeleteForPages200, PostDeleteForPagesBody, PostDuplicateForPages200, PostDuplicateForPagesBody, PostEventsForSlackIntegration200, PostEventsForSlackIntegrationBody, PostEventsForSlackIntegrationProxied200, PostEventsForSlackIntegrationProxiedBody, PostExport200, PostExportBody, PostForgotPassword200, PostForgotPasswordBody, PostG2gTransfer200, PostG2gTransferBody, PostGenerateKeyForG2gTransfer200, PostGenerateKeyForG2gTransferBody, PostGlobalNotificationForNotificationSetting200, PostImportBody, PostInstaller200, PostInstallerBody, PostInteractionsForSlackIntegrationBody, PostInteractionsForSlackIntegrationProxiedBody, PostInviteForUsers200, PostInviteForUsersParams, PostInvited200, PostInvitedBody, PostLegacyPagesMigrationForPages200, PostLegacyPagesMigrationForPagesBody, PostLogin200, PostLoginBody, PostMaintenanceModeForAppSettings200, PostMaintenanceModeForAppSettingsBody, PostOpenForInAppNotification200, PostOpenForInAppNotificationBody, PostPage201, PostPageBody, PostPlugins200, PostPluginsBody, PostRegister200, PostRegisterBody, PostRelationTestByIdForSlackIntegrationSettingsSlackAppIntegrationsBody, PostResumeRenameForPages200, PostResumeRenameForPagesBody, PostShareLinksBody, PostSlackAppIntegrationsForSlackIntegrationSettings200, PostSmtpTestForAppSettings200, PostTestForSlackIntegrationSettingsWithoutProxyBody, PostTransferForG2gTransfer200, PostTransferForG2gTransferBody, PostUploadForImportBody, PostUserGroups200, PostUserGroupsBody, PostUserNotificationForNotificationSetting200, PostUsersByUsernameByIdForUserGroups200, PostV5SchemaMigrationForAppSettings200, PostVerifyForSlackIntegrationProxied200, PostVerifyForSlackIntegrationProxiedBody, PutActivateByIdForPlugins200, PutActivateByIdForUsers200, PutApiTokenForPersonalSetting200, PutAppSettingForAppSettings200, PutAssociateLdapForPersonalSetting200, PutAssociateLdapForPersonalSettingBody, PutBookmarkFolder200, PutBookmarkFolderBody, PutBookmarks200, PutContentWidthByPageId200, PutContentWidthByPageIdBody, PutCustomizeCssForCustomizeSetting200, PutCustomizeLogoForCustomizeSetting200, PutCustomizeNoscriptForCustomizeSetting200, PutCustomizeScriptForCustomizeSetting200, PutCustomizeTitleForCustomizeSetting200, PutDeactivateByIdForUsers200, PutDisassociateLdapForPersonalSetting200, PutEditorSettingsForPersonalSetting200, PutEditorSettingsForPersonalSettingBody, PutEnabledByIdForNotificationSettingGlobalNotification200, PutEnabledByIdForNotificationSettingGlobalNotificationBody, PutEnabledForSecuritySettingAuthentication200, PutEnabledForSecuritySettingAuthenticationBody, PutExternalUserGroupsById200, PutExternalUserGroupsByIdBody, PutFileUploadSettingsForAppSettings200, PutForgotPassword200, PutForgotPasswordBody, PutFunctionForCustomizeSetting200, PutGithubOauthForSecuritySetting200, PutGlobalNotificationByIdForNotificationSetting200, PutGoogleOauthForSecuritySetting200, PutGrantAdminByIdForUsers200, PutGrantByPageIdBody, PutGrantReadOnlyByIdForUsers200, PutHighlightForCustomizeSetting200, PutImageTypeForPersonalSetting200, PutImageTypeForPersonalSettingBody, PutInAppNotificationSettingsForPersonalSetting200, PutInAppNotificationSettingsForPersonalSettingBody, PutIndentForMarkdownSetting200, PutIndicesForSearch200, PutIndicesForSearchBody, PutLayoutForCustomizeSetting200, PutLdapForSecuritySetting200, PutLineBreakForMarkdownSetting200, PutLocalSettingForSecuritySetting200, PutOidcForSecuritySetting200, PutPage200, PutPageBody, PutPasswordForPersonalSetting200, PutPasswordForPersonalSettingBody, PutPermissionsByIdForSlackIntegrationSettingsSlackAppIntegrations200, PutPermissionsByIdForSlackIntegrationSettingsSlackAppIntegrationsBody, PutPersonalSetting200, PutPresentationForCustomizeSetting200, PutProxyUriForSlackIntegrationSettings200, PutProxyUriForSlackIntegrationSettingsBody, PutRegenerateTokensByIdForSlackIntegrationSettingsSlackAppIntegrations200, PutRenameForPages200, PutRenameForPagesBody, PutResetPasswordEmailForUsersBody, PutResetPasswordForUsers200, PutResetPasswordForUsersBody, PutRevokeAdminByIdForUsers200, PutRevokeReadOnlyByIdForUsers200, PutSamlForSecuritySetting200, PutSendInvitationEmailForUsers200, PutSendInvitationEmailForUsersBody, PutShareLinkSettingForSecuritySetting200, PutSidebarForCustomizeSetting200, PutSiteUrlSettingForAppSettings200, PutSlackIntegrationLegacySetting200, PutSlackIntegrationLegacySettingBody, PutSmtpSettingForAppSettings200, PutSubscribeForPageBody, PutSyncForExternalUserGroupsKeycloak202, PutSyncForExternalUserGroupsLdap202, PutSyncLatestRevisionBodyToYjsDraftByPageId200, PutSyncLatestRevisionBodyToYjsDraftByPageIdBody, PutSyncSettingsForExternalUserGroupsKeycloak204, PutSyncSettingsForExternalUserGroupsKeycloakBody, PutSyncSettingsForExternalUserGroupsLdap204, PutSyncSettingsForExternalUserGroupsLdapBody, PutThemeForCustomizeSetting200, PutUpdateBookmarkForBookmarkFolder200, PutUpdateBookmarkForBookmarkFolderBody, PutUpdateImageUrlCacheForUsers200, PutUpdateImageUrlCacheForUsersBody, PutUpdatePermissionsForSlackIntegrationSettingsWithoutProxyBody, PutUpdateSettingsForSlackIntegrationSettingsWithoutProxyBody, PutUploadBrandLogoForCustomizeSetting200, PutUploadBrandLogoForCustomizeSettingBody, PutUserGroupsById200, PutUserGroupsByIdBody, PutUserUiSettings200, PutUserUiSettingsBody, SamlAuthSetting, SesSettingParams, SesSettingResponseParams, ShareLinkSetting, ShareLinkSimple, SiteUrlSettingParams, SmtpSettingParams, StatisticsUserResponse, SyncStatus, UserNotification, UserNotificationParams, XssParams } from './index.schemas.js';
|
|
8
8
|
import { customInstance } from '../../utils/v3/axios-instance.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { axiosInstanceManager } from './utils/axios-instance-manager.js';
|
|
2
2
|
export type * as Apiv1Types from './apiv1/index.js';
|
|
3
3
|
export type * as Apiv3Types from './apiv3/index.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,YAAY,KAAK,UAAU,MAAM,kBAAkB,CAAC;AACpD,YAAY,KAAK,UAAU,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { axiosInstanceManager } from './utils/axios-instance-manager.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AxiosInstance } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* A singleton class for managing multiple named Axios instances.
|
|
4
|
+
*/
|
|
5
|
+
declare class AxiosInstanceManager {
|
|
6
|
+
private instances;
|
|
7
|
+
/**
|
|
8
|
+
* Add or update a named Axios instance.
|
|
9
|
+
* @param appName The name/key for the instance.
|
|
10
|
+
* @param config The configuration for the Axios instance.
|
|
11
|
+
*/
|
|
12
|
+
addAxiosInstance(config: {
|
|
13
|
+
appName: string;
|
|
14
|
+
baseURL: string;
|
|
15
|
+
token: string;
|
|
16
|
+
}): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get a named Axios instance.
|
|
19
|
+
* @param appName The name/key of the instance.
|
|
20
|
+
* @returns The AxiosInstance.
|
|
21
|
+
* @throws Error if no instance is found for the given appName.
|
|
22
|
+
*/
|
|
23
|
+
getAxiosInstance(appName: string): AxiosInstance;
|
|
24
|
+
}
|
|
25
|
+
export declare const axiosInstanceManager: AxiosInstanceManager;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=axios-instance-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axios-instance-manager.d.ts","sourceRoot":"","sources":["../../src/utils/axios-instance-manager.ts"],"names":[],"mappings":"AAAA,OAAc,EAA2B,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3E;;GAEG;AACH,cAAM,oBAAoB;IACxB,OAAO,CAAC,SAAS,CAAyC;IAE1D;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAW5E;;;;;OAKG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa;CAOjD;AAGD,eAAO,MAAM,oBAAoB,sBAA6B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Axios from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* A singleton class for managing multiple named Axios instances.
|
|
4
|
+
*/
|
|
5
|
+
class AxiosInstanceManager {
|
|
6
|
+
instances = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* Add or update a named Axios instance.
|
|
9
|
+
* @param appName The name/key for the instance.
|
|
10
|
+
* @param config The configuration for the Axios instance.
|
|
11
|
+
*/
|
|
12
|
+
addAxiosInstance(config) {
|
|
13
|
+
const axiosInstance = Axios.create({
|
|
14
|
+
baseURL: config.baseURL,
|
|
15
|
+
});
|
|
16
|
+
// Set the Authorization header
|
|
17
|
+
axiosInstance.defaults.headers.common.Authorization = `Bearer ${config.token}`;
|
|
18
|
+
this.instances.set(config.appName, axiosInstance);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get a named Axios instance.
|
|
22
|
+
* @param appName The name/key of the instance.
|
|
23
|
+
* @returns The AxiosInstance.
|
|
24
|
+
* @throws Error if no instance is found for the given appName.
|
|
25
|
+
*/
|
|
26
|
+
getAxiosInstance(appName) {
|
|
27
|
+
const instance = this.instances.get(appName);
|
|
28
|
+
if (!instance) {
|
|
29
|
+
throw new Error(`No Axios instance found for appName: ${appName}`);
|
|
30
|
+
}
|
|
31
|
+
return instance;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Export singleton instance
|
|
35
|
+
export const axiosInstanceManager = new AxiosInstanceManager();
|
|
36
|
+
//# sourceMappingURL=axios-instance-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axios-instance-manager.js","sourceRoot":"","sources":["../../src/utils/axios-instance-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsD,MAAM,OAAO,CAAC;AAE3E;;GAEG;AACH,MAAM,oBAAoB;IAChB,SAAS,GAA+B,IAAI,GAAG,EAAE,CAAC;IAE1D;;;;OAIG;IACH,gBAAgB,CAAC,MAA2D;QAC1E,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC;YACjC,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CAAC;QAEH,+BAA+B;QAC/B,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,GAAG,UAAU,MAAM,CAAC,KAAK,EAAE,CAAC;QAE/E,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,OAAe;QAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,wCAAwC,OAAO,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-instance.d.ts","sourceRoot":"","sources":["../../../src/utils/types/custom-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEhD,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-instance.js","sourceRoot":"","sources":["../../../src/utils/types/custom-instance.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type AxiosRequestConfig } from 'axios';
|
|
2
|
-
|
|
2
|
+
import type { CustomInstanceOptions } from '../types/custom-instance.js';
|
|
3
|
+
export declare const customInstance: <T>(config: AxiosRequestConfig, options?: CustomInstanceOptions) => Promise<T>;
|
|
3
4
|
//# sourceMappingURL=axios-instance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios-instance.d.ts","sourceRoot":"","sources":["../../../src/utils/v1/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"axios-instance.d.ts","sourceRoot":"","sources":["../../../src/utils/v1/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,QAAQ,kBAAkB,EAAE,UAAU,qBAAqB,KAAG,OAAO,CAAC,CAAC,CAyBxG,CAAC"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import Axios from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { axiosInstanceManager } from '../axios-instance-manager.js';
|
|
3
3
|
export const customInstance = (config, options) => {
|
|
4
|
+
const { appName, axiosOptions } = options ?? {};
|
|
5
|
+
if (appName == null) {
|
|
6
|
+
throw new Error('appName is required');
|
|
7
|
+
}
|
|
4
8
|
const source = Axios.CancelToken.source();
|
|
5
|
-
const
|
|
6
|
-
const baseURL = `${
|
|
7
|
-
const promise =
|
|
9
|
+
const instance = axiosInstanceManager.getAxiosInstance(appName);
|
|
10
|
+
const baseURL = `${axiosOptions?.baseURL ?? config?.baseURL ?? instance.defaults.baseURL ?? ''}/_api`;
|
|
11
|
+
const promise = instance({
|
|
8
12
|
...config,
|
|
9
|
-
...
|
|
13
|
+
...axiosOptions,
|
|
10
14
|
baseURL,
|
|
11
15
|
cancelToken: source.token,
|
|
12
16
|
}).then(({ data }) => data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios-instance.js","sourceRoot":"","sources":["../../../src/utils/v1/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"axios-instance.js","sourceRoot":"","sources":["../../../src/utils/v1/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGpE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAI,MAA0B,EAAE,OAA+B,EAAc,EAAE;IAC3G,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEhD,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAE1C,MAAM,QAAQ,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,GAAG,YAAY,EAAE,OAAO,IAAI,MAAM,EAAE,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,OAAO,CAAC;IAEtG,MAAM,OAAO,GAAG,QAAQ,CAAC;QACvB,GAAG,MAAM;QACT,GAAG,YAAY;QACf,OAAO;QACP,WAAW,EAAE,MAAM,CAAC,KAAK;KAC1B,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAE5B,aAAa;IACb,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE;QACpB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type AxiosRequestConfig } from 'axios';
|
|
2
|
-
|
|
2
|
+
import type { CustomInstanceOptions } from '../types/custom-instance.js';
|
|
3
|
+
export declare const customInstance: <T>(config: AxiosRequestConfig, options?: CustomInstanceOptions) => Promise<T>;
|
|
3
4
|
//# sourceMappingURL=axios-instance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios-instance.d.ts","sourceRoot":"","sources":["../../../src/utils/v3/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"axios-instance.d.ts","sourceRoot":"","sources":["../../../src/utils/v3/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,QAAQ,kBAAkB,EAAE,UAAU,qBAAqB,KAAG,OAAO,CAAC,CAAC,CAyBxG,CAAC"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import Axios from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { axiosInstanceManager } from '../axios-instance-manager.js';
|
|
3
3
|
export const customInstance = (config, options) => {
|
|
4
|
+
const { appName, axiosOptions } = options ?? {};
|
|
5
|
+
if (appName == null) {
|
|
6
|
+
throw new Error('appName is required');
|
|
7
|
+
}
|
|
4
8
|
const source = Axios.CancelToken.source();
|
|
5
|
-
const
|
|
6
|
-
const baseURL = `${
|
|
7
|
-
const promise =
|
|
9
|
+
const instance = axiosInstanceManager.getAxiosInstance(appName);
|
|
10
|
+
const baseURL = `${axiosOptions?.baseURL ?? config?.baseURL ?? instance.defaults.baseURL ?? ''}/_api/v3`;
|
|
11
|
+
const promise = instance({
|
|
8
12
|
...config,
|
|
9
|
-
...
|
|
13
|
+
...axiosOptions,
|
|
10
14
|
baseURL,
|
|
11
15
|
cancelToken: source.token,
|
|
12
16
|
}).then(({ data }) => data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axios-instance.js","sourceRoot":"","sources":["../../../src/utils/v3/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"axios-instance.js","sourceRoot":"","sources":["../../../src/utils/v3/axios-instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGpE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAI,MAA0B,EAAE,OAA+B,EAAc,EAAE;IAC3G,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEhD,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAE1C,MAAM,QAAQ,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,GAAG,YAAY,EAAE,OAAO,IAAI,MAAM,EAAE,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,UAAU,CAAC;IAEzG,MAAM,OAAO,GAAG,QAAQ,CAAC;QACvB,GAAG,MAAM;QACT,GAAG,YAAY;QACf,OAAO;QACP,WAAW,EAAE,MAAM,CAAC,KAAK;KAC1B,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAE5B,aAAa;IACb,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE;QACpB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Axios, { type AxiosRequestConfig, type AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A singleton class for managing multiple named Axios instances.
|
|
5
|
+
*/
|
|
6
|
+
class AxiosInstanceManager {
|
|
7
|
+
private instances: Map<string, AxiosInstance> = new Map();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Add or update a named Axios instance.
|
|
11
|
+
* @param appName The name/key for the instance.
|
|
12
|
+
* @param config The configuration for the Axios instance.
|
|
13
|
+
*/
|
|
14
|
+
addAxiosInstance(config: { appName: string; baseURL: string; token: string }) {
|
|
15
|
+
const axiosInstance = Axios.create({
|
|
16
|
+
baseURL: config.baseURL,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Set the Authorization header
|
|
20
|
+
axiosInstance.defaults.headers.common.Authorization = `Bearer ${config.token}`;
|
|
21
|
+
|
|
22
|
+
this.instances.set(config.appName, axiosInstance);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get a named Axios instance.
|
|
27
|
+
* @param appName The name/key of the instance.
|
|
28
|
+
* @returns The AxiosInstance.
|
|
29
|
+
* @throws Error if no instance is found for the given appName.
|
|
30
|
+
*/
|
|
31
|
+
getAxiosInstance(appName: string): AxiosInstance {
|
|
32
|
+
const instance = this.instances.get(appName);
|
|
33
|
+
if (!instance) {
|
|
34
|
+
throw new Error(`No Axios instance found for appName: ${appName}`);
|
|
35
|
+
}
|
|
36
|
+
return instance;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Export singleton instance
|
|
41
|
+
export const axiosInstanceManager = new AxiosInstanceManager();
|
|
@@ -7,15 +7,15 @@ import Axios from 'axios';
|
|
|
7
7
|
* including automatic base URL configuration, cancellation capability, and request configuration merging.
|
|
8
8
|
*/
|
|
9
9
|
import { type MockedFunction, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
10
|
-
import {
|
|
10
|
+
import { axiosInstanceManager } from '../axios-instance-manager.js';
|
|
11
11
|
import { customInstance } from './axios-instance.js';
|
|
12
12
|
|
|
13
13
|
// Mock Axios
|
|
14
14
|
vi.mock('axios');
|
|
15
|
-
vi.mock('../axios-
|
|
15
|
+
vi.mock('../axios-instance-manager.js');
|
|
16
16
|
|
|
17
17
|
const mockedAxios = vi.mocked(Axios);
|
|
18
|
-
const
|
|
18
|
+
const mockedAxiosInstanceManager = vi.mocked(axiosInstanceManager);
|
|
19
19
|
|
|
20
20
|
// Type for the promise returned by customInstance with cancel functionality
|
|
21
21
|
type CancellablePromise<T> = Promise<T> & {
|
|
@@ -52,9 +52,9 @@ describe('v1 customInstance', () => {
|
|
|
52
52
|
config: {},
|
|
53
53
|
} as AxiosResponse<{ result: string }>);
|
|
54
54
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
Object.defineProperty(
|
|
55
|
+
// Create a mock AxiosInstance with defaults
|
|
56
|
+
const mockInstance = mockAxiosInstance as unknown as AxiosInstance;
|
|
57
|
+
Object.defineProperty(mockInstance, 'defaults', {
|
|
58
58
|
value: {
|
|
59
59
|
baseURL: 'http://localhost',
|
|
60
60
|
headers: {
|
|
@@ -70,6 +70,9 @@ describe('v1 customInstance', () => {
|
|
|
70
70
|
writable: true,
|
|
71
71
|
configurable: true,
|
|
72
72
|
});
|
|
73
|
+
|
|
74
|
+
// Mock for axiosInstanceManager
|
|
75
|
+
mockedAxiosInstanceManager.getAxiosInstance.mockReturnValue(mockInstance);
|
|
73
76
|
});
|
|
74
77
|
|
|
75
78
|
afterEach(() => {
|
|
@@ -82,7 +85,7 @@ describe('v1 customInstance', () => {
|
|
|
82
85
|
const config: AxiosRequestConfig = { method: 'GET', url: '/test' };
|
|
83
86
|
|
|
84
87
|
// Act
|
|
85
|
-
await customInstance(config);
|
|
88
|
+
await customInstance(config, { appName: 'testApp' });
|
|
86
89
|
|
|
87
90
|
// Assert
|
|
88
91
|
expect(mockAxiosInstance).toHaveBeenCalledWith(
|
|
@@ -99,7 +102,7 @@ describe('v1 customInstance', () => {
|
|
|
99
102
|
const options: AxiosRequestConfig = { baseURL: 'https://custom.example.com' };
|
|
100
103
|
|
|
101
104
|
// Act
|
|
102
|
-
await customInstance(config, options);
|
|
105
|
+
await customInstance(config, { appName: 'testApp', axiosOptions: options });
|
|
103
106
|
|
|
104
107
|
// Assert
|
|
105
108
|
expect(mockAxiosInstance).toHaveBeenCalledWith(
|
|
@@ -118,7 +121,7 @@ describe('v1 customInstance', () => {
|
|
|
118
121
|
};
|
|
119
122
|
|
|
120
123
|
// Act
|
|
121
|
-
await customInstance(config);
|
|
124
|
+
await customInstance(config, { appName: 'testApp' });
|
|
122
125
|
|
|
123
126
|
// Assert
|
|
124
127
|
expect(mockAxiosInstance).toHaveBeenCalledWith(
|
|
@@ -143,7 +146,7 @@ describe('v1 customInstance', () => {
|
|
|
143
146
|
};
|
|
144
147
|
|
|
145
148
|
// Act
|
|
146
|
-
await customInstance(config, options);
|
|
149
|
+
await customInstance(config, { appName: 'testApp', axiosOptions: options });
|
|
147
150
|
|
|
148
151
|
// Assert
|
|
149
152
|
expect(mockAxiosInstance).toHaveBeenCalledWith(
|
|
@@ -170,7 +173,7 @@ describe('v1 customInstance', () => {
|
|
|
170
173
|
};
|
|
171
174
|
|
|
172
175
|
// Act
|
|
173
|
-
await customInstance(config, options);
|
|
176
|
+
await customInstance(config, { appName: 'testApp', axiosOptions: options });
|
|
174
177
|
|
|
175
178
|
// Assert
|
|
176
179
|
expect(mockAxiosInstance).toHaveBeenCalledWith(
|
|
@@ -196,7 +199,7 @@ describe('v1 customInstance', () => {
|
|
|
196
199
|
const config: AxiosRequestConfig = { method: 'GET', url: '/users' };
|
|
197
200
|
|
|
198
201
|
// Act
|
|
199
|
-
const result = await customInstance(config);
|
|
202
|
+
const result = await customInstance(config, { appName: 'testApp' });
|
|
200
203
|
|
|
201
204
|
// Assert
|
|
202
205
|
expect(result).toEqual(expectedData);
|
|
@@ -209,7 +212,7 @@ describe('v1 customInstance', () => {
|
|
|
209
212
|
const config: AxiosRequestConfig = { method: 'GET', url: '/test' };
|
|
210
213
|
|
|
211
214
|
// Act
|
|
212
|
-
const promise = customInstance(config) as CancellablePromise<unknown>;
|
|
215
|
+
const promise = customInstance(config, { appName: 'testApp' }) as CancellablePromise<unknown>;
|
|
213
216
|
|
|
214
217
|
// Assert
|
|
215
218
|
expect(promise).toHaveProperty('cancel');
|
|
@@ -224,7 +227,7 @@ describe('v1 customInstance', () => {
|
|
|
224
227
|
const config: AxiosRequestConfig = { method: 'GET', url: '/test' };
|
|
225
228
|
|
|
226
229
|
// Act
|
|
227
|
-
const promise = customInstance(config) as CancellablePromise<unknown>;
|
|
230
|
+
const promise = customInstance(config, { appName: 'testApp' }) as CancellablePromise<unknown>;
|
|
228
231
|
promise.cancel();
|
|
229
232
|
|
|
230
233
|
// Assert
|
|
@@ -244,7 +247,15 @@ describe('v1 customInstance', () => {
|
|
|
244
247
|
const config: AxiosRequestConfig = { method: 'GET', url: '/test' };
|
|
245
248
|
|
|
246
249
|
// Act & Assert
|
|
247
|
-
await expect(customInstance(config)).rejects.toThrow('Network error');
|
|
250
|
+
await expect(customInstance(config, { appName: 'testApp' })).rejects.toThrow('Network error');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('should throw error when appName is not provided', () => {
|
|
254
|
+
// Arrange
|
|
255
|
+
const config: AxiosRequestConfig = { method: 'GET', url: '/test' };
|
|
256
|
+
|
|
257
|
+
// Act & Assert
|
|
258
|
+
expect(() => customInstance(config)).toThrow('appName is required');
|
|
248
259
|
});
|
|
249
260
|
});
|
|
250
261
|
});
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import Axios, { type AxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { axiosInstanceManager } from '../axios-instance-manager.js';
|
|
3
|
+
import type { CustomInstanceOptions } from '../types/custom-instance.js';
|
|
4
|
+
|
|
5
|
+
export const customInstance = <T>(config: AxiosRequestConfig, options?: CustomInstanceOptions): Promise<T> => {
|
|
6
|
+
const { appName, axiosOptions } = options ?? {};
|
|
7
|
+
|
|
8
|
+
if (appName == null) {
|
|
9
|
+
throw new Error('appName is required');
|
|
10
|
+
}
|
|
3
11
|
|
|
4
|
-
export const customInstance = <T>(config: AxiosRequestConfig, options?: AxiosRequestConfig): Promise<T> => {
|
|
5
12
|
const source = Axios.CancelToken.source();
|
|
6
13
|
|
|
7
|
-
const
|
|
8
|
-
const baseURL = `${
|
|
14
|
+
const instance = axiosInstanceManager.getAxiosInstance(appName);
|
|
15
|
+
const baseURL = `${axiosOptions?.baseURL ?? config?.baseURL ?? instance.defaults.baseURL ?? ''}/_api`;
|
|
9
16
|
|
|
10
|
-
const promise =
|
|
17
|
+
const promise = instance({
|
|
11
18
|
...config,
|
|
12
|
-
...
|
|
19
|
+
...axiosOptions,
|
|
13
20
|
baseURL,
|
|
14
21
|
cancelToken: source.token,
|
|
15
22
|
}).then(({ data }) => data);
|