mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-02 17:35:08 +00:00
PoC: Make @alfresco/js-api to be compatible with angular's http client
This commit is contained in:
parent
a0c7631abb
commit
e432ba6d37
@ -20,7 +20,7 @@ import { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ChartsModule } from 'ng2-charts';
|
||||
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import {
|
||||
@ -28,8 +28,7 @@ import {
|
||||
TRANSLATION_PROVIDER,
|
||||
DebugAppConfigService,
|
||||
CoreModule,
|
||||
CoreAutomationService,
|
||||
AuthBearerInterceptor
|
||||
CoreAutomationService
|
||||
} from '@alfresco/adf-core';
|
||||
import { ExtensionsModule } from '@alfresco/adf-extensions';
|
||||
import { AppComponent } from './app.component';
|
||||
@ -115,6 +114,7 @@ import localeSv from '@angular/common/locales/sv';
|
||||
import { setupAppNotifications } from './services/app-notifications-factory';
|
||||
import { AppNotificationsService } from './services/app-notifications.service';
|
||||
import { SearchFilterChipsComponent } from './components/search/search-filter-chips.component';
|
||||
import { AlfrescoApiModule } from '@alfresco/adf-core/alfresco-api';
|
||||
|
||||
registerLocaleData(localeFr);
|
||||
registerLocaleData(localeDe);
|
||||
@ -153,6 +153,7 @@ registerLocaleData(localeSv);
|
||||
ThemePickerModule,
|
||||
ChartsModule,
|
||||
AppCloudSharedModule,
|
||||
AlfrescoApiModule,
|
||||
MonacoEditorModule.forRoot()
|
||||
],
|
||||
declarations: [
|
||||
@ -209,10 +210,6 @@ registerLocaleData(localeSv);
|
||||
SearchFilterChipsComponent
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS, useClass:
|
||||
AuthBearerInterceptor, multi: true
|
||||
},
|
||||
{ provide: AppConfigService, useClass: DebugAppConfigService }, // not use this service in production
|
||||
{
|
||||
provide: TRANSLATION_PROVIDER,
|
||||
|
54
lib/core/alfresco-api/alfresco-api.module.ts
Normal file
54
lib/core/alfresco-api/alfresco-api.module.ts
Normal file
@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*tslint:disable*/ // => because of ADF file naming problems... Try to remove it, if you don't believe me :P
|
||||
|
||||
import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||
import { AngularAlfrescoApi } from './services/angular-alfresco-api';
|
||||
import { AlfrescoApiClientFactory } from './services/alfresco-api-client.factory';
|
||||
import { AngularAlfrescoApiLoaderService } from './services/angular-alfresco-api-loader.service';
|
||||
import { createAngularAlfrescoApiService } from './services/angular-alfresco-service.factory';
|
||||
import { AuthBearerInterceptor } from './services/auth-bearer.interceptor';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
HttpClientModule,
|
||||
HttpClientXsrfModule.withOptions({
|
||||
cookieName: 'CSRF-TOKEN',
|
||||
headerName: 'X-CSRF-TOKEN'
|
||||
})
|
||||
],
|
||||
providers: [
|
||||
AngularAlfrescoApi,
|
||||
AngularAlfrescoApiLoaderService,
|
||||
AlfrescoApiClientFactory,
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: createAngularAlfrescoApiService,
|
||||
deps: [
|
||||
AngularAlfrescoApiLoaderService
|
||||
],
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS, useClass:
|
||||
AuthBearerInterceptor, multi: true
|
||||
}
|
||||
]
|
||||
})
|
||||
export class AlfrescoApiModule {}
|
20
lib/core/alfresco-api/index.ts
Normal file
20
lib/core/alfresco-api/index.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 './alfresco-api.module';
|
||||
export * from './services/angular-alfresco-api';
|
||||
export * from './services/alfresco-api-client.factory';
|
58
lib/core/alfresco-api/js-api/js-api-http-client.ts
Normal file
58
lib/core/alfresco-api/js-api/js-api-http-client.ts
Normal file
@ -0,0 +1,58 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 { RequestOptions } from '@alfresco/js-api';
|
||||
|
||||
export interface JsApiHttpClient {
|
||||
basePath: string;
|
||||
request<T = any>(options: RequestOptions): Promise<T>;
|
||||
post<T = any>(options: RequestOptions): Promise<T>;
|
||||
put<T = any>(options: RequestOptions): Promise<T>;
|
||||
get<T = any>(options: RequestOptions): Promise<T>;
|
||||
delete<T = void>(options: RequestOptions): Promise<T>;
|
||||
/** @deprecated */
|
||||
callApi(
|
||||
path: string,
|
||||
httpMethod: string,
|
||||
pathParams?: any,
|
||||
queryParams?: any,
|
||||
headerParams?: any,
|
||||
formParams?: any,
|
||||
bodyParam?: any,
|
||||
contentTypes?: string[],
|
||||
accepts?: string[],
|
||||
returnType?: any,
|
||||
contextRoot?: string,
|
||||
responseType?: string,
|
||||
url?: string
|
||||
): Promise<any>;
|
||||
/** @deprecated */
|
||||
callCustomApi(
|
||||
path: string,
|
||||
httpMethod: string,
|
||||
pathParams?: any,
|
||||
queryParams?: any,
|
||||
headerParams?: any,
|
||||
formParams?: any,
|
||||
bodyParam?: any,
|
||||
contentTypes?: string[],
|
||||
accepts?: string[],
|
||||
returnType?: any,
|
||||
contextRoot?: string,
|
||||
responseType?: string
|
||||
): Promise<any>;
|
||||
}
|
18
lib/core/alfresco-api/public-api.ts
Normal file
18
lib/core/alfresco-api/public-api.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Experimental module, nothing is published!
|
@ -0,0 +1,48 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*tslint:disable*/ // => because of ADF file naming problems... Try to remove it, if you don't believe me :P
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { DiscoveryApi } from '@alfresco/js-api';
|
||||
import { AngularAlfrescoApi } from './angular-alfresco-api';
|
||||
|
||||
@Injectable()
|
||||
export class AlfrescoApiClientFactory {
|
||||
// Here we should all the APIs from js-api
|
||||
private discoveryApi: DiscoveryApi = null;
|
||||
|
||||
constructor(
|
||||
private angularAlfrescoApi?: AngularAlfrescoApi) {
|
||||
}
|
||||
|
||||
getDiscoveryApi() {
|
||||
// DiscoveryApi needs to rely on a lot thinner interface: JsApiHttpClient;
|
||||
this.discoveryApi = this.discoveryApi || new DiscoveryApi(this.angularAlfrescoApi as any);
|
||||
return this.discoveryApi;
|
||||
}
|
||||
|
||||
getNodesApi () {
|
||||
// TODO
|
||||
}
|
||||
|
||||
getSearchApi() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// etc...
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 { Injectable } from '@angular/core';
|
||||
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
|
||||
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
|
||||
import { OauthConfigModel } from '../../models/oauth-config.model';
|
||||
import { StorageService } from '../../services/storage.service';
|
||||
import { AngularAlfrescoApi } from './angular-alfresco-api';
|
||||
|
||||
@Injectable()
|
||||
export class AngularAlfrescoApiLoaderService {
|
||||
|
||||
protected alfrescoApi: AlfrescoApi;
|
||||
|
||||
constructor(
|
||||
protected appConfig: AppConfigService,
|
||||
protected storageService: StorageService,
|
||||
private angularAlfrescoApi?: AngularAlfrescoApi) {
|
||||
}
|
||||
|
||||
async load() {
|
||||
await this.appConfig.load().then(() => {
|
||||
this.storageService.prefix = this.appConfig.get<string>(AppConfigValues.STORAGE_PREFIX, '');
|
||||
this.initAngularAlfrescoApi();
|
||||
});
|
||||
}
|
||||
|
||||
protected initAngularAlfrescoApi() {
|
||||
const oauth: OauthConfigModel = Object.assign({}, this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null));
|
||||
if (oauth) {
|
||||
oauth.redirectUri = window.location.origin + window.location.pathname;
|
||||
oauth.redirectUriLogout = window.location.origin + window.location.pathname;
|
||||
}
|
||||
|
||||
const config = new AlfrescoApiConfig({
|
||||
provider: this.appConfig.get<string>(AppConfigValues.PROVIDERS),
|
||||
hostEcm: this.appConfig.get<string>(AppConfigValues.ECMHOST),
|
||||
hostBpm: this.appConfig.get<string>(AppConfigValues.BPMHOST),
|
||||
authType: this.appConfig.get<string>(AppConfigValues.AUTHTYPE, 'BASIC'),
|
||||
contextRootBpm: this.appConfig.get<string>(AppConfigValues.CONTEXTROOTBPM),
|
||||
contextRoot: this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM),
|
||||
disableCsrf: this.appConfig.get<boolean>(AppConfigValues.DISABLECSRF),
|
||||
withCredentials: this.appConfig.get<boolean>(AppConfigValues.AUTH_WITH_CREDENTIALS, false),
|
||||
domainPrefix : this.appConfig.get<string>(AppConfigValues.STORAGE_PREFIX),
|
||||
oauth2: oauth
|
||||
});
|
||||
|
||||
this.angularAlfrescoApi.init(config);
|
||||
}
|
||||
}
|
85
lib/core/alfresco-api/services/angular-alfresco-api.ts
Normal file
85
lib/core/alfresco-api/services/angular-alfresco-api.ts
Normal file
@ -0,0 +1,85 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 { AlfrescoApiConfig } from '@alfresco/js-api';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { JsApiHttpClient } from '../js-api/js-api-http-client';
|
||||
import { JsApiAngularHttpClient } from './js-api-angular-http-client';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
@Injectable()
|
||||
export class AngularAlfrescoApi {
|
||||
public contentPrivateClient: JsApiHttpClient;
|
||||
public contentClient: JsApiHttpClient;
|
||||
public authClient: JsApiHttpClient;
|
||||
public searchClient: JsApiHttpClient;
|
||||
public discoveryClient: JsApiHttpClient;
|
||||
public gsClient: JsApiHttpClient;
|
||||
public processClient: JsApiHttpClient;
|
||||
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
|
||||
init(config: AlfrescoApiConfig) {
|
||||
this.contentPrivateClient = new JsApiAngularHttpClient(
|
||||
config.hostEcm,
|
||||
config.contextRoot,
|
||||
`/api/${config.tenant}/private/alfresco/versions/1`,
|
||||
this.httpClient
|
||||
);
|
||||
|
||||
this.contentClient = new JsApiAngularHttpClient(
|
||||
config.hostEcm,
|
||||
config.contextRoot,
|
||||
`/api/${config.tenant}/public/alfresco/versions/1`,
|
||||
this.httpClient
|
||||
);
|
||||
|
||||
this.authClient = new JsApiAngularHttpClient(
|
||||
config.hostEcm,
|
||||
config.contextRoot,
|
||||
`/api/${config.tenant}/public/authentication/versions/1`,
|
||||
this.httpClient
|
||||
);
|
||||
|
||||
this.searchClient = new JsApiAngularHttpClient(
|
||||
config.hostEcm,
|
||||
config.contextRoot,
|
||||
`/api/${config.tenant}/public/search/versions/1`,
|
||||
this.httpClient
|
||||
);
|
||||
this.discoveryClient = new JsApiAngularHttpClient(
|
||||
config.hostEcm,
|
||||
config.contextRoot,
|
||||
`/api`,
|
||||
this.httpClient
|
||||
);
|
||||
|
||||
this.gsClient = new JsApiAngularHttpClient(
|
||||
config.hostEcm,
|
||||
config.contextRoot,
|
||||
`/api/${config.tenant}/public/gs/versions/1`,
|
||||
this.httpClient
|
||||
);
|
||||
|
||||
this.processClient = new JsApiAngularHttpClient(
|
||||
config.hostBpm,
|
||||
config.contextRootBpm,
|
||||
'',
|
||||
this.httpClient
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 { AngularAlfrescoApiLoaderService } from './angular-alfresco-api-loader.service';
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
export function createAngularAlfrescoApiService(angularAlfrescoApiService: AngularAlfrescoApiLoaderService) {
|
||||
return () => angularAlfrescoApiService.load();
|
||||
}
|
@ -21,7 +21,7 @@ import {
|
||||
HttpHandler, HttpInterceptor, HttpRequest,
|
||||
HttpSentEvent, HttpHeaderResponse, HttpProgressEvent, HttpResponse, HttpUserEvent, HttpHeaders
|
||||
} from '@angular/common/http';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { AuthenticationService } from '../../services/authentication.service';
|
||||
import { catchError, mergeMap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
190
lib/core/alfresco-api/services/js-api-angular-http-client.ts
Normal file
190
lib/core/alfresco-api/services/js-api-angular-http-client.ts
Normal file
@ -0,0 +1,190 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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 {
|
||||
paramToString,
|
||||
RequestOptions
|
||||
} from '@alfresco/js-api';
|
||||
import { JsApiHttpClient } from '../js-api/js-api-http-client';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
|
||||
/** tslint:disable-next line */
|
||||
export class JsApiAngularHttpClient implements JsApiHttpClient {
|
||||
public basePath: string;
|
||||
|
||||
constructor (
|
||||
private host: string,
|
||||
private contextRoot: string,
|
||||
private servicePath: string,
|
||||
private httpClient: HttpClient
|
||||
) {
|
||||
this.basePath = `${this.host}/${this.contextRoot}${this.servicePath}`;
|
||||
}
|
||||
|
||||
request<T = any>(options: RequestOptions): Promise<T> {
|
||||
|
||||
const responseType = this.getResponseType(options);
|
||||
|
||||
return this.httpClient.request(
|
||||
options.httpMethod,
|
||||
options.url,
|
||||
{
|
||||
...(options.bodyParam ? { body: options.bodyParam } : {}),
|
||||
...(options.headerParams ? { headers: new HttpHeaders(options.headerParams) } : {}),
|
||||
observe: 'body',
|
||||
...(options.queryParams ? { params: new HttpParams({ fromObject: options.queryParams })} : {}),
|
||||
...(responseType ? { responseType } : {}),
|
||||
}).toPromise() as unknown as Promise<T>;
|
||||
}
|
||||
|
||||
private getResponseType(options: RequestOptions): 'arraybuffer' | 'blob' | 'json' | 'text' {
|
||||
let responseType = null;
|
||||
|
||||
if (options.returnType?.toString().toLowerCase() === 'blob' || options.responseType?.toString().toLowerCase() === 'blob') {
|
||||
responseType = 'blob';
|
||||
} else if (options.returnType === 'String') {
|
||||
responseType = 'text';
|
||||
}
|
||||
|
||||
return responseType;
|
||||
}
|
||||
|
||||
post<T = any>(options: RequestOptions): Promise<T> {
|
||||
return this.request<T>({
|
||||
...options,
|
||||
httpMethod: 'POST',
|
||||
contentTypes: options.contentTypes || ['application/json'],
|
||||
accepts: options.accepts || ['application/json']
|
||||
});
|
||||
}
|
||||
|
||||
put<T = any>(options: RequestOptions): Promise<T> {
|
||||
return this.request<T>({
|
||||
...options,
|
||||
httpMethod: 'PUT',
|
||||
contentTypes: options.contentTypes || ['application/json'],
|
||||
accepts: options.accepts || ['application/json']
|
||||
});
|
||||
}
|
||||
|
||||
get<T = any>(options: RequestOptions): Promise<T> {
|
||||
return this.request<T>({
|
||||
...options,
|
||||
httpMethod: 'GET',
|
||||
contentTypes: options.contentTypes || ['application/json'],
|
||||
accepts: options.accepts || ['application/json']
|
||||
});
|
||||
}
|
||||
|
||||
delete<T = void>(options: RequestOptions): Promise<T> {
|
||||
return this.request<T>({
|
||||
...options,
|
||||
httpMethod: 'DELETE',
|
||||
contentTypes: options.contentTypes || ['application/json'],
|
||||
accepts: options.accepts || ['application/json']
|
||||
});
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
callApi(
|
||||
path: string,
|
||||
httpMethod: string,
|
||||
pathParams?: any,
|
||||
queryParams?: any,
|
||||
headerParams?: any,
|
||||
formParams?: any,
|
||||
bodyParam?: any,
|
||||
contentTypes?: string[],
|
||||
accepts?: string[],
|
||||
returnType?: any,
|
||||
contextRoot?: string,
|
||||
responseType?: string,
|
||||
url?: string
|
||||
): Promise<any> {
|
||||
|
||||
const basePath = contextRoot ? `${this.host}/${contextRoot}` : this.basePath;
|
||||
url = url ?? this.buildUrl(basePath, path, pathParams);
|
||||
|
||||
return this.request({
|
||||
path,
|
||||
httpMethod,
|
||||
pathParams,
|
||||
queryParams,
|
||||
headerParams,
|
||||
formParams,
|
||||
bodyParam,
|
||||
contentTypes,
|
||||
accepts,
|
||||
returnType,
|
||||
contextRoot,
|
||||
responseType,
|
||||
url
|
||||
});
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
callCustomApi(
|
||||
fullPath: string,
|
||||
httpMethod: string,
|
||||
pathParams?: any,
|
||||
queryParams?: any,
|
||||
headerParams?: any,
|
||||
formParams?: any,
|
||||
bodyParam?: any,
|
||||
contentTypes?: string[],
|
||||
accepts?: string[],
|
||||
returnType?: any,
|
||||
contextRoot?: string,
|
||||
responseType?: string
|
||||
): Promise<any> {
|
||||
const url = this.buildUrl(fullPath, '', pathParams);
|
||||
|
||||
return this.request({
|
||||
path: fullPath,
|
||||
httpMethod,
|
||||
pathParams,
|
||||
queryParams,
|
||||
headerParams,
|
||||
formParams,
|
||||
bodyParam,
|
||||
contentTypes,
|
||||
accepts,
|
||||
returnType,
|
||||
contextRoot,
|
||||
responseType,
|
||||
url
|
||||
});
|
||||
}
|
||||
|
||||
private buildUrl(basePath: string, path: string, pathParams: any): string {
|
||||
if (path && path !== '' && !path.match(/^\//)) {
|
||||
path = '/' + path;
|
||||
}
|
||||
let url = basePath + path;
|
||||
|
||||
url = url.replace(/\{([\w-]+)\}/g, function (fullMatch, key) {
|
||||
let value;
|
||||
if (pathParams.hasOwnProperty(key)) {
|
||||
value = paramToString(pathParams[key]);
|
||||
} else {
|
||||
value = fullMatch;
|
||||
}
|
||||
return encodeURIComponent(value);
|
||||
});
|
||||
return url;
|
||||
}
|
||||
}
|
@ -18,11 +18,12 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { from, Observable, throwError, Subject } from 'rxjs';
|
||||
import { catchError, map, switchMap, filter, take } from 'rxjs/operators';
|
||||
import { AboutApi, DiscoveryApi, RepositoryInfo, SystemPropertiesApi, SystemPropertiesRepresentation } from '@alfresco/js-api';
|
||||
import { AboutApi, RepositoryInfo, SystemPropertiesApi, SystemPropertiesRepresentation } from '@alfresco/js-api';
|
||||
|
||||
import { BpmProductVersionModel } from '../models/product-version.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
import { AlfrescoApiClientFactory } from '../alfresco-api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -36,7 +37,8 @@ export class DiscoveryApiService {
|
||||
|
||||
constructor(
|
||||
private apiService: AlfrescoApiService,
|
||||
private authenticationService: AuthenticationService) {
|
||||
private authenticationService: AuthenticationService,
|
||||
private alfrescoApiClientFactory: AlfrescoApiClientFactory) {
|
||||
|
||||
this.authenticationService.onLogin
|
||||
.pipe(
|
||||
@ -53,7 +55,8 @@ export class DiscoveryApiService {
|
||||
* @returns ProductVersionModel containing product details
|
||||
*/
|
||||
getEcmProductInfo(): Observable<RepositoryInfo> {
|
||||
const discoveryApi = new DiscoveryApi(this.apiService.getInstance());
|
||||
// const discoveryApi = new DiscoveryApi(this.apiService.getInstance());
|
||||
const discoveryApi = this.alfrescoApiClientFactory.getDiscoveryApi();
|
||||
|
||||
return from(discoveryApi.getRepositoryInformation())
|
||||
.pipe(
|
||||
|
@ -62,7 +62,7 @@ export * from './identity-user.service';
|
||||
export * from './identity-group.service';
|
||||
export * from './identity-role.service';
|
||||
export * from './version-compatibility.service';
|
||||
export * from './auth-bearer.interceptor';
|
||||
export * from '../alfresco-api/services/auth-bearer.interceptor';
|
||||
export * from './oauth2.service';
|
||||
export * from './language.service';
|
||||
export * from './identity-user.service.interface';
|
||||
|
@ -32,6 +32,7 @@
|
||||
"@alfresco/js-api": ["node_modules/@alfresco/js-api"],
|
||||
"@alfresco/adf-extensions": ["lib/extensions"],
|
||||
"@alfresco/adf-core": ["lib/core"],
|
||||
"@alfresco/adf-core/*": ["lib/core/*"],
|
||||
"@alfresco/adf-content-services": ["lib/content-services"],
|
||||
"@alfresco/adf-process-services": ["lib/process-services"],
|
||||
"@alfresco/adf-insights": ["lib/insights"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user