mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-12511] implement OIDC authentication capabilities in ADF (#7856)
* feat: add custom AlfrescoApiHttpClient [ci:force]
* feat: update configs
* feat: move api to follow second entry point structure
* feat: add auth module [ci:force]
* Fix rebasing issues
* Isolate oidc package as subfolder
* Canary mode
* [AAE-12498] Fix unit test should load external settings: resolve reponse data instead returning default config
* [AAE-12498] Set @nrwl/eslint-plugin-nx@14.5.4 version to fix lint job that failed because of the 14.8.6 version (https://github.com/Alfresco/alfresco-ng2-components/actions/runs/4165060892/jobs/7207651856\#step:5:3379)
* [AAE-12498] Fix stories:build-storybook:ci issues
* [AAE-7991] cherry-pick e935f7b0b1
from repo https://github.com/Alfresco/alfresco-ng2-components/pull/7818: send onLogin to initialize acs version to fix [C362242] on canary configuration
* [AAE-12498] Fix security hotspot: fix unsafe pseudorandom number generator
* test: add missing tests for oidc-auth.guard
* test: fix lint issues
* chore: remove assignment in return
* [AAE-12498] Remove warning comment because we already know we're doing breaking changes
* [AAE-12498] Add auth-config.service unit tests
* [AAE-12498] Remove getUserProfile from auth service
---------
Co-authored-by: Andras Popovics <popovics@ndras.hu>
Co-authored-by: Amedeo Lepore <amedeo.lepore@hyland.com>
This commit is contained in:
22
lib/core/api/src/index.ts
Normal file
22
lib/core/api/src/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* @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 './lib/api-client.factory';
|
||||
export * from './lib/api-clients.service';
|
||||
export * from './lib/clients';
|
||||
export * from './lib/types';
|
||||
export * from './lib/alfresco-api/alfresco-api.http-client';
|
@@ -0,0 +1,316 @@
|
||||
/*!
|
||||
* @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 { Emitters, RequestOptions, ResultListDataRepresentationTaskRepresentation, SecurityOptions } from '@alfresco/js-api';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { AlfrescoApiHttpClient } from './alfresco-api.http-client';
|
||||
import { AlfrescoApiResponseError } from './alfresco-api.response-error';
|
||||
|
||||
const securityOptions: SecurityOptions = {
|
||||
authentications: {},
|
||||
defaultHeaders: {},
|
||||
isBpmRequest: false,
|
||||
enableCsrf: true,
|
||||
withCredentials: false
|
||||
};
|
||||
|
||||
const emitter = {
|
||||
emit: () => {},
|
||||
off: () => {},
|
||||
on: () => {},
|
||||
once: () => {}
|
||||
};
|
||||
|
||||
const emitters: Emitters = {
|
||||
eventEmitter: emitter,
|
||||
apiClientEmitter: emitter
|
||||
};
|
||||
|
||||
const mockResponse = {
|
||||
data: [
|
||||
{
|
||||
id: 14,
|
||||
name: 'nameFake1',
|
||||
created: '2017-03-01T12:25:17.189+0000'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
describe('AlfrescoApiHttpClient', () => {
|
||||
let angularHttpClient: AlfrescoApiHttpClient;
|
||||
let controller: HttpTestingController;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
HttpClientTestingModule
|
||||
]
|
||||
});
|
||||
angularHttpClient = TestBed.inject(AlfrescoApiHttpClient);
|
||||
controller = TestBed.inject(HttpTestingController);
|
||||
});
|
||||
|
||||
|
||||
describe('deserialize', () => {
|
||||
|
||||
afterEach(() => {
|
||||
controller.verify();
|
||||
});
|
||||
|
||||
it('should deserialize incoming request based on return type', (done) => {
|
||||
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST',
|
||||
returnType: ResultListDataRepresentationTaskRepresentation,
|
||||
headerParams: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
accepts: ['application/json']
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters).then((res: ResultListDataRepresentationTaskRepresentation) => {
|
||||
expect(res instanceof ResultListDataRepresentationTaskRepresentation).toBeTruthy();
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
expect(res.data![0].created instanceof Date).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
const req = controller.expectOne('http://example.com');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
|
||||
req.flush(mockResponse);
|
||||
|
||||
});
|
||||
|
||||
it('should return parsed json object when responseType is json', (done) => {
|
||||
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST',
|
||||
responseType: 'json'
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters).then((res) => {
|
||||
expect(res).toEqual(mockResponse);
|
||||
done();
|
||||
});
|
||||
|
||||
const req = controller.expectOne('http://example.com');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
|
||||
req.flush(mockResponse);
|
||||
|
||||
});
|
||||
|
||||
it('should emit unauthorized message for 401 request', (done) => {
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST'
|
||||
};
|
||||
|
||||
const spy = spyOn(emitter, 'emit').and.callThrough();
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch(() => {
|
||||
expect(spy).toHaveBeenCalledWith('unauthorized');
|
||||
done();
|
||||
});
|
||||
|
||||
const req = controller.expectOne('http://example.com');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
|
||||
req.flush('<div></div>', { status: 401, statusText: 'unauthorized'});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('upload', () => {
|
||||
|
||||
afterEach(() => {
|
||||
controller.verify();
|
||||
});
|
||||
|
||||
it('should behave...', () => {
|
||||
const requestOptions: RequestOptions = {
|
||||
path: '/nodes/{nodeId}/children',
|
||||
httpMethod: 'POST',
|
||||
queryParams: {
|
||||
autoRename: true,
|
||||
include: 'allowableOperations',
|
||||
fields: null
|
||||
},
|
||||
formParams: {
|
||||
filedata: new File([], 'file.txt'),
|
||||
relativePath: '',
|
||||
include: ['allowableOperations'],
|
||||
renditions: 'doclib',
|
||||
autoRename: true,
|
||||
nodeType: 'cm:content'
|
||||
},
|
||||
bodyParam: {
|
||||
name: 'demo.txt',
|
||||
nodeType: 'cm:content',
|
||||
relativePath: '',
|
||||
newVersion: false,
|
||||
majorVersion: false,
|
||||
parentId: '-my-',
|
||||
path: ''
|
||||
},
|
||||
contentType: 'multipart/form-data',
|
||||
accept: 'application/json',
|
||||
returnType: null
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com', requestOptions, securityOptions, emitters);
|
||||
const req = controller.expectOne('http://example.com?autoRename=true&include=allowableOperations');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
|
||||
// filedata: (binary)
|
||||
// include: allowableOperations
|
||||
|
||||
const body = req.request.body as HttpParams;
|
||||
|
||||
expect(body.get('relativePath')).toBe('');
|
||||
expect(body.get('renditions')).toBe('doclib');
|
||||
expect(body.get('autoRename')).toBeTruthy();
|
||||
expect(body.get('nodeType')).toBe('cm:content');
|
||||
expect(body.get('include')).toBe('allowableOperations');
|
||||
expect(body.get('filedata')).toEqual(jasmine.any(File));
|
||||
|
||||
req.flush('');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a Error type on failed promise, for backward compatibility, with string value to prevent JSON.parse from crashing when we try to get status code from message', (done) => {
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST'
|
||||
};
|
||||
|
||||
const errorResponse = {
|
||||
error: {
|
||||
errorKey: 'Cant perform action',
|
||||
statusCode: 403
|
||||
}
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch((res: AlfrescoApiResponseError) => {
|
||||
expect(res instanceof Error).toBeTruthy();
|
||||
expect(res.message).toBe(JSON.stringify(errorResponse));
|
||||
expect(res.status).toBe(403);
|
||||
done();
|
||||
});
|
||||
|
||||
const req = controller.expectOne('http://example.com');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
|
||||
req.flush(errorResponse, { status: 403, statusText: 'Forbidden' });
|
||||
});
|
||||
|
||||
it('should return a Error type on failed promise with response body', (done) => {
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST',
|
||||
responseType: 'blob'
|
||||
};
|
||||
|
||||
const errorResponse = new Blob();
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch((res: AlfrescoApiResponseError) => {
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.error.response.body instanceof Blob).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
const req = controller.expectOne('http://example.com');
|
||||
|
||||
req.flush(errorResponse, { status: 400, statusText: 'Bad request' });
|
||||
});
|
||||
|
||||
it('should correctly handle queryParams with arrays', () => {
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST',
|
||||
queryParams: {
|
||||
skipCount: 0,
|
||||
status: [
|
||||
'RUNNING',
|
||||
'SUSPENDED'
|
||||
],
|
||||
sort: 'startDate,DESC'
|
||||
}
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com/candidatebaseapp/query/v1/process-instances', options, securityOptions, emitters);
|
||||
|
||||
const req = controller.expectOne('http://example.com/candidatebaseapp/query/v1/process-instances?skipCount=0&status=RUNNING&status=SUSPENDED&sort=startDate%2CDESC');
|
||||
expect(req.request.method).toEqual('POST');
|
||||
|
||||
req.flush(null, { status: 200, statusText: 'Ok' });
|
||||
});
|
||||
|
||||
it('should convert null values to empty stirng for backward compatibility', (done) => {
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'GET'
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters).then((res) => {
|
||||
expect(res).toEqual('');
|
||||
done();
|
||||
});
|
||||
|
||||
const req = controller.expectOne('http://example.com');
|
||||
|
||||
req.flush(null, { status: 200, statusText: 'Ok' });
|
||||
});
|
||||
|
||||
it('should correctly decode types to string', () => {
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST',
|
||||
queryParams: {
|
||||
lastModifiedFrom: '2022-08-17T00:00:00.000+02:00'
|
||||
}
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters);
|
||||
|
||||
const req = controller.expectOne('http://example.com?lastModifiedFrom=2022-08-17T00%3A00%3A00.000%2B02%3A00');
|
||||
|
||||
req.flush(null, { status: 200, statusText: 'Ok' });
|
||||
});
|
||||
|
||||
it('should correctly decode Date types to string ', () => {
|
||||
const options: RequestOptions = {
|
||||
path: '',
|
||||
httpMethod: 'POST',
|
||||
queryParams: {
|
||||
lastModifiedFrom: new Date('2022-08-17T00:00:00.000Z')
|
||||
}
|
||||
};
|
||||
|
||||
angularHttpClient.request('http://example.com', options, securityOptions, emitters);
|
||||
|
||||
const req = controller.expectOne('http://example.com?lastModifiedFrom=2022-08-17T00%3A00%3A00.000Z');
|
||||
|
||||
req.flush(null, { status: 200, statusText: 'Ok' });
|
||||
});
|
||||
|
||||
});
|
227
lib/core/api/src/lib/alfresco-api/alfresco-api.http-client.ts
Normal file
227
lib/core/api/src/lib/alfresco-api/alfresco-api.http-client.ts
Normal file
@@ -0,0 +1,227 @@
|
||||
/*!
|
||||
* @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 { SHOULD_ADD_AUTH_TOKEN } from '@alfresco/adf-core/auth';
|
||||
import { Emitters as JsApiEmitters, HttpClient as JsApiHttpClient, RequestOptions, 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';
|
||||
import { catchError, map, takeUntil } from 'rxjs/operators';
|
||||
import { convertObjectToFormData, getQueryParamsWithCustomEncoder, isBlobResponse, isConstructor, isHttpResponseEvent, isHttpUploadProgressEvent, removeNilValues } from './alfresco-api.utils';
|
||||
import { AlfrescoApiParamEncoder } from './alfresco-api.param-encoder';
|
||||
import { AlfrescoApiResponseError } from './alfresco-api.response-error';
|
||||
import { Constructor } from '../types';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AlfrescoApiHttpClient implements JsApiHttpClient {
|
||||
|
||||
constructor(private httpClient: HttpClient) {}
|
||||
|
||||
request<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> {
|
||||
const body = AlfrescoApiHttpClient.getBody(options);
|
||||
const params = getQueryParamsWithCustomEncoder(options.queryParams, new AlfrescoApiParamEncoder());
|
||||
const headers = AlfrescoApiHttpClient.getHeaders(options);
|
||||
const responseType = AlfrescoApiHttpClient.getResponseType(options);
|
||||
const context = new HttpContext().set(SHOULD_ADD_AUTH_TOKEN, true);
|
||||
|
||||
const request = this.httpClient.request(
|
||||
options.httpMethod,
|
||||
url,
|
||||
{
|
||||
context,
|
||||
...(body && { body }),
|
||||
...(responseType && { responseType }),
|
||||
...(sc.withCredentials && { withCredentials: true }),
|
||||
...(params && { params }),
|
||||
headers,
|
||||
observe: 'events',
|
||||
reportProgress: true
|
||||
}
|
||||
);
|
||||
|
||||
return this.requestWithLegacyEventEmitters<T>(request, emitters, options.returnType);
|
||||
}
|
||||
|
||||
post<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> {
|
||||
return this.request<T>(url, { ...options, httpMethod: 'POST' }, sc, emitters);
|
||||
}
|
||||
|
||||
put<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> {
|
||||
return this.request<T>(url, { ...options, httpMethod: 'PUT' }, sc, emitters);
|
||||
}
|
||||
|
||||
get<T = any>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> {
|
||||
return this.request<T>(url, { ...options, httpMethod: 'GET' }, sc, emitters);
|
||||
}
|
||||
|
||||
delete<T = void>(url: string, options: RequestOptions, sc: SecurityOptions, emitters: JsApiEmitters): Promise<T> {
|
||||
return this.request<T>(url, { ...options, httpMethod: 'DELETE' }, sc, emitters);
|
||||
}
|
||||
|
||||
private requestWithLegacyEventEmitters<T = any>(request$: Observable<HttpEvent<T>>, emitters: JsApiEmitters, returnType: any): Promise<T> {
|
||||
|
||||
const abort$ = new Subject<void>();
|
||||
const { eventEmitter, apiClientEmitter } = emitters;
|
||||
|
||||
const promise = request$.pipe(
|
||||
map((res) => {
|
||||
if (isHttpUploadProgressEvent(res)) {
|
||||
const percent = Math.round((res.loaded / res.total) * 100);
|
||||
eventEmitter.emit('progress', { loaded: res.loaded, total: res.total, percent });
|
||||
}
|
||||
|
||||
if (isHttpResponseEvent(res)) {
|
||||
eventEmitter.emit('success', res.body);
|
||||
return AlfrescoApiHttpClient.deserialize(res, returnType);
|
||||
}
|
||||
}),
|
||||
catchError((err: HttpErrorResponse): Observable<AlfrescoApiResponseError> => {
|
||||
|
||||
// since we can't always determinate ahead of time if the response is going to be xml or plain text response
|
||||
// we need to handle false positive cases here.
|
||||
|
||||
if (err.status === 200) {
|
||||
eventEmitter.emit('success', err.error.text);
|
||||
return of(err.error.text);
|
||||
}
|
||||
|
||||
eventEmitter.emit('error', err);
|
||||
apiClientEmitter.emit('error', err);
|
||||
|
||||
if (err.status === 401) {
|
||||
eventEmitter.emit('unauthorized');
|
||||
apiClientEmitter.emit('unauthorized');
|
||||
}
|
||||
|
||||
// for backwards compatibility we need to convert it to error class as the HttpErrorResponse only implements Error interface, not extending it,
|
||||
// and we need to be able to correctly pass instanceof Error conditions used inside repository
|
||||
// we also need to pass error as Stringify string as we are detecting statusCodes using JSON.parse(error.message) in some places
|
||||
const msg = typeof err.error === 'string' ? err.error : JSON.stringify(err.error);
|
||||
|
||||
// for backwards compatibility to handle cases in code where we try read response.error.response.body;
|
||||
|
||||
const error = {
|
||||
response: { ...err, body: err.error }
|
||||
};
|
||||
|
||||
const alfrescoApiError = new AlfrescoApiResponseError(msg, err.status, error);
|
||||
|
||||
return throwError(alfrescoApiError);
|
||||
}),
|
||||
takeUntil(abort$)
|
||||
).toPromise();
|
||||
|
||||
(promise as any).abort = function() {
|
||||
eventEmitter.emit('abort');
|
||||
abort$.next();
|
||||
abort$.complete();
|
||||
return this;
|
||||
};
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
private static getBody(options: RequestOptions): any {
|
||||
const contentType = options.contentType;
|
||||
const isFormData = contentType === 'multipart/form-data';
|
||||
const isFormUrlEncoded = contentType === 'application/x-www-form-urlencoded';
|
||||
const body = options.bodyParam;
|
||||
|
||||
if (isFormData) {
|
||||
return convertObjectToFormData(options.formParams);
|
||||
}
|
||||
|
||||
if (isFormUrlEncoded) {
|
||||
return new HttpParams({ fromObject: removeNilValues(options.formParams) });
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
private static getHeaders(options: RequestOptions): HttpHeaders {
|
||||
const optionsHeaders = {
|
||||
...options.headerParams,
|
||||
...(options.accept && { Accept: options.accept }),
|
||||
...((options.contentType) && { 'Content-Type': options.contentType })
|
||||
};
|
||||
|
||||
return new HttpHeaders(optionsHeaders);
|
||||
}
|
||||
|
||||
private static getResponseType(options: RequestOptions): 'blob' | 'json' | 'text' {
|
||||
|
||||
const isBlobType = options.returnType?.toString().toLowerCase() === 'blob' || options.responseType?.toString().toLowerCase() === 'blob';
|
||||
|
||||
if (isBlobType) {
|
||||
return 'blob';
|
||||
}
|
||||
|
||||
if (options.returnType === 'String') {
|
||||
return 'text';
|
||||
}
|
||||
|
||||
return 'json';
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize an HTTP response body into a value of the specified type.
|
||||
*/
|
||||
private static deserialize<T>(response: HttpResponse<T>, returnType?: Constructor<unknown> | 'blob'): any {
|
||||
|
||||
if (response === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const body = response.body;
|
||||
|
||||
if (!returnType) {
|
||||
// for backwards compatibility we need to return empty string instead of null,
|
||||
// to avoid issues when accessing null response would break application [C309878]
|
||||
// cannot read property 'entry' of null in cases like
|
||||
// return this.post(apiUrl, saveFormRepresentation).pipe(map((res: any) => res.entry))
|
||||
|
||||
return body !== null ? body : '';
|
||||
}
|
||||
|
||||
if (isBlobResponse(response, returnType)) {
|
||||
return AlfrescoApiHttpClient.deserializeBlobResponse(response);
|
||||
}
|
||||
|
||||
if (!isConstructor(returnType)) {
|
||||
return body;
|
||||
}
|
||||
|
||||
if (Array.isArray(body)) {
|
||||
return body.map((element) => new returnType(element));
|
||||
}
|
||||
|
||||
return new returnType(body);
|
||||
}
|
||||
|
||||
|
||||
private static deserializeBlobResponse(response: HttpResponse<Blob>) {
|
||||
|
||||
if (isBrowser()) {
|
||||
return new Blob([response.body], { type: response.headers.get('Content-Type') });
|
||||
}
|
||||
|
||||
return Buffer.from(response.body as unknown as WithImplicitCoercion<string>, 'binary');
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,29 @@
|
||||
/*!
|
||||
* @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 { AlfrescoApiParamEncoder } from './alfresco-api.param-encoder';
|
||||
|
||||
describe('AlfrescoApiParamEncoder', () => {
|
||||
it('should propely encode special "+" character', () => {
|
||||
const encoder = new AlfrescoApiParamEncoder();
|
||||
const value = '2022-08-17T00:00:00.000+02:00';
|
||||
const encodeValue = '2022-08-17T00%3A00%3A00.000%2B02%3A00';
|
||||
|
||||
expect(encoder.encodeValue(value)).toBe(encodeValue);
|
||||
expect(encoder.decodeValue(encodeValue)).toBe(value);
|
||||
});
|
||||
});
|
@@ -0,0 +1,40 @@
|
||||
/*!
|
||||
* @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 { HttpParameterCodec } from '@angular/common/http';
|
||||
|
||||
// The default implementation of HttpParameterCodec from angular
|
||||
// does not encode some special characters like + with is causing issues with the alfresco js API and returns 500 error
|
||||
|
||||
export class AlfrescoApiParamEncoder implements HttpParameterCodec {
|
||||
|
||||
encodeKey(key: string): string {
|
||||
return encodeURIComponent(key);
|
||||
}
|
||||
|
||||
encodeValue(value: string): string {
|
||||
return encodeURIComponent(value);
|
||||
}
|
||||
|
||||
decodeKey(key: string): string {
|
||||
return decodeURIComponent(key);
|
||||
}
|
||||
|
||||
decodeValue(value: string): string {
|
||||
return decodeURIComponent(value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
/*!
|
||||
* @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 class AlfrescoApiResponseError extends Error {
|
||||
|
||||
public name = 'AlfrescoApiResponseError';
|
||||
|
||||
constructor(msg: string, public status: number, public error: { response: Record<string, any> }) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
99
lib/core/api/src/lib/alfresco-api/alfresco-api.utils.spec.ts
Normal file
99
lib/core/api/src/lib/alfresco-api/alfresco-api.utils.spec.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
/*!
|
||||
* @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 { isConstructor, getQueryParamsWithCustomEncoder, removeNilValues } from './alfresco-api.utils';
|
||||
|
||||
describe('AlfrescoApiUtils', () => {
|
||||
|
||||
describe('isConstructor', () => {
|
||||
class MockClass {}
|
||||
function mockFUnction() {}
|
||||
|
||||
it('should return true for class and functions', () => {
|
||||
expect(isConstructor(MockClass)).toBe(true);
|
||||
expect(isConstructor(mockFUnction)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for instances of a class/function', () => {
|
||||
expect(isConstructor(new MockClass())).toBe(false);
|
||||
expect(isConstructor(new mockFUnction())).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for object', () => {
|
||||
expect(isConstructor({})).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for primitive types', () => {
|
||||
expect(isConstructor('test')).toBe(false);
|
||||
expect(isConstructor(1)).toBe(false);
|
||||
expect(isConstructor(true)).toBe(false);
|
||||
expect(isConstructor(false)).toBe(false);
|
||||
expect(isConstructor(null)).toBe(false);
|
||||
expect(isConstructor(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('getQueryParamsWithCustomEncoder', () => {
|
||||
|
||||
it('should return queryParams with removed undefined values', () => {
|
||||
const actual = getQueryParamsWithCustomEncoder({
|
||||
key1: 'value1',
|
||||
key2: undefined
|
||||
});
|
||||
|
||||
expect(actual?.has('key2')).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle array values', () => {
|
||||
const actual = getQueryParamsWithCustomEncoder({
|
||||
key1: 'value1',
|
||||
key2: [undefined, 'value2', null, 'value3', '']
|
||||
});
|
||||
|
||||
expect(actual?.get('key2')).toEqual('value2');
|
||||
expect(actual?.getAll('key2')).toEqual(['value2', 'value3']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('removeUndefinedValues', () => {
|
||||
|
||||
it('should return queryParams with removed undefined values', () => {
|
||||
const actual = removeNilValues({
|
||||
key1: 'value1',
|
||||
key2: undefined,
|
||||
key3: null
|
||||
});
|
||||
|
||||
expect(actual).toEqual({
|
||||
key1: 'value1'
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle array values', () => {
|
||||
const actual = getQueryParamsWithCustomEncoder({
|
||||
key1: 'value1',
|
||||
key2: [undefined, 'value2', null, 'value3', '']
|
||||
});
|
||||
|
||||
expect(actual?.get('key2')).toEqual('value2');
|
||||
expect(actual?.getAll('key2')).toEqual(['value2', 'value3']);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
91
lib/core/api/src/lib/alfresco-api/alfresco-api.utils.ts
Normal file
91
lib/core/api/src/lib/alfresco-api/alfresco-api.utils.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
/*!
|
||||
* @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 { HttpEvent, HttpUploadProgressEvent, HttpEventType, HttpResponse, HttpParams, HttpParameterCodec, HttpUrlEncodingCodec } from '@angular/common/http';
|
||||
import { Constructor } from '../types';
|
||||
|
||||
export const isHttpUploadProgressEvent = <T>(val: HttpEvent<T>): val is HttpUploadProgressEvent => val.type === HttpEventType.UploadProgress;
|
||||
export const isHttpResponseEvent = <T>(val: HttpEvent<T>): val is HttpResponse<T> => val.type === HttpEventType.Response;
|
||||
export const isDate = (value: unknown): value is Date => value instanceof Date;
|
||||
export const isXML = (value: unknown): boolean => typeof value === 'string' && value.startsWith('<?xml');
|
||||
export const isBlobResponse = (response: HttpResponse<any>, returnType: Constructor<unknown> | 'blob'): response is HttpResponse<Blob> => returnType === 'blob' || response.body instanceof Blob;
|
||||
export const isConstructor = <T = unknown>(value: any): value is Constructor<T> => typeof value === 'function' && !!value?.prototype?.constructor.name;
|
||||
|
||||
const convertParamsToString = (value: any): any => isDate(value) ? value.toISOString() : value;
|
||||
export const getQueryParamsWithCustomEncoder = (obj: Record<string | number, unknown>, encoder: HttpParameterCodec = new HttpUrlEncodingCodec()): HttpParams | undefined => {
|
||||
if (!obj) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let httpParams = new HttpParams({
|
||||
encoder
|
||||
});
|
||||
|
||||
const params = removeNilValues(obj);
|
||||
|
||||
for (const key in params) {
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(params, key)) {
|
||||
const value = params[key];
|
||||
if (value instanceof Array) {
|
||||
const array = value.map(convertParamsToString).filter(Boolean);
|
||||
httpParams = httpParams.appendAll({
|
||||
[key]: array
|
||||
});
|
||||
} else {
|
||||
httpParams = httpParams.append(key, convertParamsToString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return httpParams;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes null and undefined values from an object.
|
||||
*/
|
||||
export const removeNilValues = (obj: Record<string | number, unknown>) => {
|
||||
|
||||
if (!obj) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return Object.keys(obj).reduce((acc, key) => {
|
||||
const value = obj[key];
|
||||
const isNil = value === undefined || value === null;
|
||||
return isNil ? acc : { ...acc, [key]: value };
|
||||
}, {});
|
||||
};
|
||||
|
||||
|
||||
export const convertObjectToFormData = (formParams: Record<string | number, string | Blob>): FormData => {
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
for (const key in formParams) {
|
||||
if (Object.prototype.hasOwnProperty.call(formParams, key)) {
|
||||
const value = formParams[key];
|
||||
if (value instanceof File) {
|
||||
formData.append(key, value, value.name);
|
||||
} else {
|
||||
formData.append(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return formData;
|
||||
};
|
25
lib/core/api/src/lib/api-client.factory.ts
Normal file
25
lib/core/api/src/lib/api-client.factory.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*!
|
||||
* @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 { InjectionToken } from '@angular/core';
|
||||
import { Constructor } from './types';
|
||||
|
||||
export interface ApiClientFactory {
|
||||
create<T>(apiClass: Constructor<T>): T;
|
||||
}
|
||||
|
||||
export const API_CLIENT_FACTORY_TOKEN = new InjectionToken<ApiClientFactory>('api-client-factory');
|
66
lib/core/api/src/lib/api-clients.service.spec.ts
Normal file
66
lib/core/api/src/lib/api-clients.service.spec.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
/*!
|
||||
* @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 { 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<T>(apiClass: Constructor<T>): 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);
|
||||
});
|
||||
|
||||
});
|
66
lib/core/api/src/lib/api-clients.service.ts
Normal file
66
lib/core/api/src/lib/api-clients.service.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
/*!
|
||||
* @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 { 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<Constructor<any>> = {};
|
||||
private instances: Partial<AlfrescoCore.ApiRegistry> = {};
|
||||
|
||||
get<T extends keyof AlfrescoCore.ApiRegistry>(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<T extends keyof AlfrescoCore.ApiRegistry>(apiName: T, api: Constructor<AlfrescoCore.ApiRegistry[T]>): void {
|
||||
this.registry[apiName] = api;
|
||||
}
|
||||
|
||||
private instantiateApi<T extends keyof AlfrescoCore.ApiRegistry>(apiName: T): AlfrescoCore.ApiRegistry[T] {
|
||||
const apiClass = this.registry[apiName];
|
||||
const instance = this.apiCreateFactory.create<AlfrescoCore.ApiRegistry[T]>(apiClass);
|
||||
this.instances[apiName] = instance;
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
/*!
|
||||
* @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 { 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
lib/core/api/src/lib/clients/alfresco-js-clients.module.ts
Normal file
38
lib/core/api/src/lib/clients/alfresco-js-clients.module.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/*!
|
||||
* @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 { 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 { }
|
@@ -0,0 +1,27 @@
|
||||
/*!
|
||||
* @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 { 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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
/*!
|
||||
* @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 { DiscoveryApi } from '@alfresco/js-api';
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace AlfrescoCore {
|
||||
interface ApiRegistry {
|
||||
['DiscoveryClient.discovery']: DiscoveryApi;
|
||||
}
|
||||
}
|
||||
}
|
20
lib/core/api/src/lib/clients/index.ts
Normal file
20
lib/core/api/src/lib/clients/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 './activiti/activiti-client.types';
|
||||
export * from './alfresco-js-clients.module';
|
||||
export * from './discovery/discovery-client.types';
|
22
lib/core/api/src/lib/types.ts
Normal file
22
lib/core/api/src/lib/types.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* @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 Dictionary<T> {
|
||||
[key: string]: T;
|
||||
};
|
||||
|
||||
export type Constructor<T> = new (...args: any[]) => T;
|
Reference in New Issue
Block a user