diff --git a/lib/core/api/src/index.ts b/lib/core/api/src/index.ts index e79643fd1f..bc6ac8685c 100644 --- a/lib/core/api/src/index.ts +++ b/lib/core/api/src/index.ts @@ -20,3 +20,4 @@ export * from './lib/api-clients.service'; export * from './lib/clients'; export * from './lib/types'; export * from './lib/adf-http-client.service'; +export * from './lib/interfaces'; diff --git a/lib/core/api/src/lib/adf-http-client.service.ts b/lib/core/api/src/lib/adf-http-client.service.ts index b7e69126bd..b3b399dbe7 100644 --- a/lib/core/api/src/lib/adf-http-client.service.ts +++ b/lib/core/api/src/lib/adf-http-client.service.ts @@ -16,7 +16,7 @@ */ import { SHOULD_ADD_AUTH_TOKEN } from '@alfresco/adf-core/auth'; -import { Emitters as JsApiEmitters, HttpClient as JsApiHttpClient, RequestOptions, SecurityOptions, isBrowser } from '@alfresco/js-api'; +import { Emitters as JsApiEmitters, HttpClient as JsApiHttpClient, SecurityOptions, isBrowser } from '@alfresco/js-api'; import { HttpClient, HttpContext, HttpErrorResponse, HttpEvent, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, of, Subject, throwError } from 'rxjs'; @@ -25,6 +25,7 @@ import { convertObjectToFormData, getQueryParamsWithCustomEncoder, isBlobRespons import { AlfrescoApiParamEncoder } from './alfresco-api/alfresco-api.param-encoder'; import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error'; import { Constructor } from './types'; +import { RequestOptions } from './interfaces'; @Injectable({ providedIn: 'root' @@ -35,7 +36,6 @@ export class AdfHttpClient implements JsApiHttpClient { constructor(private httpClient: HttpClient) {} - request(url: string, options: RequestOptions, sc: SecurityOptions = this.defaultSecurityOptions, emitters?: JsApiEmitters): Promise { const body = AdfHttpClient.getBody(options); const params = getQueryParamsWithCustomEncoder(options.queryParams, new AlfrescoApiParamEncoder()); @@ -61,7 +61,7 @@ export class AdfHttpClient implements JsApiHttpClient { if(emitters){ return this.requestWithLegacyEventEmitters(request, emitters, options.returnType); } - return request.toPromise(); + return request.pipe(map(req => req.body)).toPromise(); } post(url: string, options: RequestOptions, sc?: SecurityOptions, emitters?: JsApiEmitters): Promise { diff --git a/lib/core/api/src/lib/interfaces.ts b/lib/core/api/src/lib/interfaces.ts new file mode 100644 index 0000000000..2474e929c9 --- /dev/null +++ b/lib/core/api/src/lib/interfaces.ts @@ -0,0 +1,28 @@ +/*! + * @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 interface RequestOptions { + httpMethod?: string; + queryParams?: any; + headerParams?: any; + formParams?: any; + bodyParam?: any; + returnType?: any; + responseType?: string; + readonly accept?: string; + readonly contentType?: string; +} diff --git a/lib/core/src/lib/auth/services/oauth2.service.ts b/lib/core/src/lib/auth/services/oauth2.service.ts index 86d424c31b..87a0f3fe90 100644 --- a/lib/core/src/lib/auth/services/oauth2.service.ts +++ b/lib/core/src/lib/auth/services/oauth2.service.ts @@ -34,20 +34,16 @@ export class OAuth2Service { constructor(private adfHttpClient: AdfHttpClient) {} request(opts: OAuth2RequestParams): Observable { - const { httpMethod, url, bodyParam, pathParams, queryParams } = opts; + const { httpMethod, url, bodyParam, queryParams } = opts; return from( this.adfHttpClient.request( url, { - path: url, httpMethod, - pathParams, queryParams, headerParams: {}, formParams: {}, bodyParam, - contentTypes: JSON_TYPE, - accepts: JSON_TYPE, returnType: Object } )