diff --git a/lib/content-services/src/lib/common/services/discovery-api.service.ts b/lib/content-services/src/lib/common/services/discovery-api.service.ts index a5db003450..37ca92192a 100644 --- a/lib/content-services/src/lib/common/services/discovery-api.service.ts +++ b/lib/content-services/src/lib/common/services/discovery-api.service.ts @@ -16,18 +16,23 @@ */ import { Injectable } from '@angular/core'; -import { from, Observable, throwError, Subject } from 'rxjs'; +import { from, Observable, throwError, Subject, forkJoin } from 'rxjs'; import { catchError, map, switchMap, filter, take } from 'rxjs/operators'; -import { RepositoryInfo, SystemPropertiesRepresentation } from '@alfresco/js-api'; +import { RepositoryInfo, SystemPropertiesRepresentation, DiscoveryApi, AboutApi, SystemPropertiesApi } from '@alfresco/js-api'; import { BpmProductVersionModel, AuthenticationService } from '@alfresco/adf-core'; -import { ApiClientsService } from '@alfresco/adf-core/api'; +import { AlfrescoApiService } from '../../services/alfresco-api.service'; @Injectable({ providedIn: 'root' }) export class DiscoveryApiService { + private _discoveryApi: DiscoveryApi; + get discoveryApi(): DiscoveryApi { + this._discoveryApi = this._discoveryApi ?? new DiscoveryApi(this.alfrescoApiService.getInstance()); + return this._discoveryApi; + } /** * Gets product information for Content Services. */ @@ -35,9 +40,9 @@ export class DiscoveryApiService { constructor( private authenticationService: AuthenticationService, - private apiClientsService: ApiClientsService + private alfrescoApiService: AlfrescoApiService ) { - this.authenticationService.onLogin + forkJoin([this.alfrescoApiService.alfrescoApiInitialized, this.authenticationService.onLogin]) .pipe( filter(() => this.authenticationService.isEcmLoggedIn()), take(1), @@ -53,9 +58,8 @@ export class DiscoveryApiService { * @returns ProductVersionModel containing product details */ getEcmProductInfo(): Observable { - const discoveryApi = this.apiClientsService.get('DiscoveryClient.discovery'); - return from(discoveryApi.getRepositoryInformation()) + return from(this.discoveryApi.getRepositoryInformation()) .pipe( map((res) => res.entry.repository), catchError((err) => throwError(err)) @@ -68,7 +72,7 @@ export class DiscoveryApiService { * @returns ProductVersionModel containing product details */ getBpmProductInfo(): Observable { - const aboutApi = this.apiClientsService.get('ActivitiClient.about'); + const aboutApi = new AboutApi(this.alfrescoApiService.getInstance()); return from(aboutApi.getAppVersion()) .pipe( @@ -78,7 +82,7 @@ export class DiscoveryApiService { } getBPMSystemProperties(): Observable { - const systemPropertiesApi = this.apiClientsService.get('ActivitiClient.system-properties'); + const systemPropertiesApi = new SystemPropertiesApi(this.alfrescoApiService.getInstance()); return from(systemPropertiesApi.getProperties()) .pipe( diff --git a/lib/core/api/src/lib/api-client.factory.ts b/lib/core/api/src/lib/api-client.factory.ts deleted file mode 100644 index 6ddd1f8aef..0000000000 --- a/lib/core/api/src/lib/api-client.factory.ts +++ /dev/null @@ -1,25 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { InjectionToken } from '@angular/core'; -import { Constructor } from './types'; - -export interface ApiClientFactory { - create(apiClass: Constructor): T; -} - -export const API_CLIENT_FACTORY_TOKEN = new InjectionToken('api-client-factory'); diff --git a/lib/core/api/src/lib/api-clients.service.spec.ts b/lib/core/api/src/lib/api-clients.service.spec.ts deleted file mode 100644 index c240b5db6b..0000000000 --- a/lib/core/api/src/lib/api-clients.service.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AboutApi } from '@alfresco/js-api'; -import { TestBed } from '@angular/core/testing'; -import { ApiClientFactory, API_CLIENT_FACTORY_TOKEN } from './api-client.factory'; -import { ApiClientsService } from './api-clients.service'; -import { Constructor } from './types'; - -class MockApiClientFactory implements ApiClientFactory { - create(apiClass: Constructor): T { - return new apiClass(); - } -} - -describe('ApiService', () => { - let apiService: ApiClientsService; - - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [ - ApiClientsService, - { provide: API_CLIENT_FACTORY_TOKEN, useClass: MockApiClientFactory } - ] - }); - apiService = TestBed.inject(ApiClientsService); - }); - - it('should add api to registry', () => { - apiService.register('ActivitiClient.about', AboutApi); - - expect(apiService.get('ActivitiClient.about') instanceof AboutApi).toBeTruthy(); - }); - - it('should throw error if we try to get unregisterd API', () => { - expect(() => apiService.get('ActivitiClient.about')).toThrowError(); - - apiService.register('ActivitiClient.about', AboutApi); - - expect(() => apiService.get('ActivitiClient.about')).not.toThrowError(); - }); - - it('should create only single instance of API', () => { - apiService.register('ActivitiClient.about', AboutApi); - - const a = apiService.get('ActivitiClient.about'); - const b = apiService.get('ActivitiClient.about'); - - expect(a).toBe(b); - }); - -}); diff --git a/lib/core/api/src/lib/api-clients.service.ts b/lib/core/api/src/lib/api-clients.service.ts deleted file mode 100644 index 3c01fc56fb..0000000000 --- a/lib/core/api/src/lib/api-clients.service.ts +++ /dev/null @@ -1,66 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Inject, Injectable } from '@angular/core'; -import { ApiClientFactory, API_CLIENT_FACTORY_TOKEN } from './api-client.factory'; -import { Constructor, Dictionary } from './types'; - -/* eslint-disable */ - -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace AlfrescoCore { - interface ApiRegistry { - } - } -} -/* eslint-enable */ - -@Injectable() -export class ApiClientsService { - - constructor(@Inject(API_CLIENT_FACTORY_TOKEN) private apiCreateFactory: ApiClientFactory) { - } - - private registry: Dictionary> = {}; - private instances: Partial = {}; - - get(apiName: T): AlfrescoCore.ApiRegistry[T] { - - const apiClass = this.registry[apiName]; - - if (!apiClass) { - throw new Error(`Api not registred: ${apiName}`); - } - - return this.instances[apiName] as AlfrescoCore.ApiRegistry[T] ?? this.instantiateApi(apiName); - } - - - register(apiName: T, api: Constructor): void { - this.registry[apiName] = api; - } - - private instantiateApi(apiName: T): AlfrescoCore.ApiRegistry[T] { - const apiClass = this.registry[apiName]; - const instance = this.apiCreateFactory.create(apiClass); - this.instances[apiName] = instance; - - return instance; - } -} - diff --git a/lib/core/api/src/lib/clients/activiti/activiti-client.module.ts b/lib/core/api/src/lib/clients/activiti/activiti-client.module.ts deleted file mode 100644 index f906aafdcd..0000000000 --- a/lib/core/api/src/lib/clients/activiti/activiti-client.module.ts +++ /dev/null @@ -1,28 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AboutApi, SystemPropertiesApi } from '@alfresco/js-api'; -import { NgModule } from '@angular/core'; -import { ApiClientsService } from '../../api-clients.service'; - -@NgModule() -export class ActivitiClientModule { - constructor(private apiClientsService: ApiClientsService) { - this.apiClientsService.register('ActivitiClient.about', AboutApi); - this.apiClientsService.register('ActivitiClient.system-properties', SystemPropertiesApi); - } -} diff --git a/lib/core/api/src/lib/clients/activiti/activiti-client.types.ts b/lib/core/api/src/lib/clients/activiti/activiti-client.types.ts deleted file mode 100644 index 4a768c6c28..0000000000 --- a/lib/core/api/src/lib/clients/activiti/activiti-client.types.ts +++ /dev/null @@ -1,29 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { AboutApi, SystemPropertiesApi } from '@alfresco/js-api'; - -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace AlfrescoCore { - interface ApiRegistry { - ['ActivitiClient.about']: AboutApi; - ['ActivitiClient.system-properties']: SystemPropertiesApi; - } - } -} - diff --git a/lib/core/api/src/lib/clients/alfresco-js-clients.module.ts b/lib/core/api/src/lib/clients/alfresco-js-clients.module.ts deleted file mode 100644 index cf0ce91346..0000000000 --- a/lib/core/api/src/lib/clients/alfresco-js-clients.module.ts +++ /dev/null @@ -1,38 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { HttpClientModule, HttpClientXsrfModule } from '@angular/common/http'; -import { NgModule } from '@angular/core'; -import { ApiClientsService } from '../api-clients.service'; -import { ActivitiClientModule } from './activiti/activiti-client.module'; -import { DiscoveryClientModule } from './discovery/discovery-client.module'; - -@NgModule({ - imports: [ - HttpClientModule, - HttpClientXsrfModule.withOptions({ - cookieName: 'CSRF-TOKEN', - headerName: 'X-CSRF-TOKEN' - }), - ActivitiClientModule, - DiscoveryClientModule - ], - providers: [ - ApiClientsService - ] -}) -export class AlfrescoJsClientsModule { } diff --git a/lib/core/api/src/lib/clients/discovery/discovery-client.module.ts b/lib/core/api/src/lib/clients/discovery/discovery-client.module.ts deleted file mode 100644 index 242e09620b..0000000000 --- a/lib/core/api/src/lib/clients/discovery/discovery-client.module.ts +++ /dev/null @@ -1,27 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { DiscoveryApi } from '@alfresco/js-api'; -import { NgModule } from '@angular/core'; -import { ApiClientsService } from '../../api-clients.service'; - -@NgModule() -export class DiscoveryClientModule { - constructor(private apiClientsService: ApiClientsService) { - this.apiClientsService.register('DiscoveryClient.discovery', DiscoveryApi); - } -} diff --git a/lib/core/api/src/lib/clients/discovery/discovery-client.types.ts b/lib/core/api/src/lib/clients/discovery/discovery-client.types.ts deleted file mode 100644 index 64c7f6e52b..0000000000 --- a/lib/core/api/src/lib/clients/discovery/discovery-client.types.ts +++ /dev/null @@ -1,27 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { DiscoveryApi } from '@alfresco/js-api'; - -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace AlfrescoCore { - interface ApiRegistry { - ['DiscoveryClient.discovery']: DiscoveryApi; - } - } -} diff --git a/lib/core/api/src/lib/clients/index.ts b/lib/core/api/src/lib/clients/index.ts deleted file mode 100644 index 0855f4f09a..0000000000 --- a/lib/core/api/src/lib/clients/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export * from './activiti/activiti-client.types'; -export * from './alfresco-js-clients.module'; -export * from './discovery/discovery-client.types'; diff --git a/lib/core/src/lib/api-factories/legacy-api-client.module.ts b/lib/core/src/lib/api-factories/legacy-api-client.module.ts deleted file mode 100644 index e645fff543..0000000000 --- a/lib/core/src/lib/api-factories/legacy-api-client.module.ts +++ /dev/null @@ -1,28 +0,0 @@ -/*! - * @license - * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { NgModule } from '@angular/core'; -import { API_CLIENT_FACTORY_TOKEN } from '@alfresco/adf-core/api'; -import { LegacyClientFactory } from './legacy-api-client.factory'; - - -@NgModule({ - providers: [ - { provide: API_CLIENT_FACTORY_TOKEN, useClass: LegacyClientFactory } - ] -}) -export class LegacyApiClientModule { } diff --git a/lib/core/src/lib/core.module.ts b/lib/core/src/lib/core.module.ts index cdc7b2b84f..33b0a0e988 100644 --- a/lib/core/src/lib/core.module.ts +++ b/lib/core/src/lib/core.module.ts @@ -53,9 +53,8 @@ import { ExtensionsModule } from '@alfresco/adf-extensions'; import { directionalityConfigFactory } from './common/services/directionality-config-factory'; import { DirectionalityConfigService } from './common/services/directionality-config.service'; import { SearchTextModule } from './search-text/search-text-input.module'; -import { AdfHttpClient, AlfrescoJsClientsModule } from '@alfresco/adf-core/api'; +import { AdfHttpClient } from '@alfresco/adf-core/api'; import { AuthenticationInterceptor, Authentication } from '@alfresco/adf-core/auth'; -import { LegacyApiClientModule } from './api-factories/legacy-api-client.module'; import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http'; import { AuthenticationService } from './auth/services/authentication.service'; import { MAT_SNACK_BAR_DEFAULT_OPTIONS } from '@angular/material/snack-bar'; @@ -98,8 +97,6 @@ import { AlfrescoApiLoaderService, createAlfrescoApiInstance } from './api-facto NotificationHistoryModule, SearchTextModule, BlankPageModule, - LegacyApiClientModule, - AlfrescoJsClientsModule, HttpClientModule, HttpClientXsrfModule.withOptions({ cookieName: 'CSRF-TOKEN',