16159: Passes the token to be expire when calling the logout endpoint.
[arvados-workbench2.git] / src / services / services.ts
index 89b3d0ff0d3cad1d5c5b312c13e30288c82735ee..6434075cab86024534fa553d7bcfc5be4a667058 100644 (file)
@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import Axios from "axios";
+import { AxiosInstance } from "axios";
 import { ApiClientAuthorizationService } from '~/services/api-client-authorization-service/api-client-authorization-service';
 import { AuthService } from "./auth-service/auth-service";
 import { GroupsService } from "./groups-service/groups-service";
@@ -11,7 +12,6 @@ import { LinkService } from "./link-service/link-service";
 import { FavoriteService } from "./favorite-service/favorite-service";
 import { CollectionService } from "./collection-service/collection-service";
 import { TagService } from "./tag-service/tag-service";
-import { CollectionFilesService } from "./collection-files-service/collection-files-service";
 import { KeepService } from "./keep-service/keep-service";
 import { WebDAV } from "~/common/webdav";
 import { Config } from "~/common/config";
@@ -32,6 +32,7 @@ import { VocabularyService } from '~/services/vocabulary-service/vocabulary-serv
 import { NodeService } from '~/services/node-service/node-service';
 import { FileViewersConfigService } from '~/services/file-viewers-config-service/file-viewers-config-service';
 import { LinkAccountService } from "./link-account-service/link-account-service";
+import parse from "parse-duration";
 
 export type ServiceRepository = ReturnType<typeof createServices>;
 
@@ -49,12 +50,12 @@ export function removeAuthorizationHeader(services: ServiceRepository) {
     delete services.webdavClient.defaults.headers.common;
 }
 
-export const createServices = (config: Config, actions: ApiActions) => {
+export const createServices = (config: Config, actions: ApiActions, useApiClient?: AxiosInstance) => {
     // Need to give empty 'headers' object or it will create an
     // instance with a reference to the global default headers object,
     // which is very bad because that means setAuthorizationHeader
     // would update the global default instead of the instance default.
-    const apiClient = Axios.create({ headers: {} });
+    const apiClient = useApiClient || Axios.create({ headers: {} });
     apiClient.defaults.baseURL = config.baseUrl;
 
     const webdavClient = new WebDAV();
@@ -78,9 +79,12 @@ export const createServices = (config: Config, actions: ApiActions) => {
     const linkAccountService = new LinkAccountService(apiClient, actions);
 
     const ancestorsService = new AncestorService(groupsService, userService);
-    const authService = new AuthService(apiClient, config.rootUrl, actions);
+
+    const idleTimeout = config && config.clusterConfig && config.clusterConfig.Workbench.IdleTimeout || '0s';
+    const authService = new AuthService(apiClient, config.rootUrl, actions,
+        (parse(idleTimeout, 's') || 0) > 0);
+
     const collectionService = new CollectionService(apiClient, webdavClient, authService, actions);
-    const collectionFilesService = new CollectionFilesService(collectionService);
     const favoriteService = new FavoriteService(linkService, groupsService);
     const tagService = new TagService(linkService);
     const searchService = new SearchService();
@@ -93,7 +97,6 @@ export const createServices = (config: Config, actions: ApiActions) => {
         apiClientAuthorizationService,
         authService,
         authorizedKeysService,
-        collectionFilesService,
         collectionService,
         containerRequestService,
         containerService,