AAE-30878 Migrating from event-emitter to eventemitter3 which is … (#11116)

This commit is contained in:
Vito Albano
2025-09-02 13:33:35 +01:00
committed by GitHub
parent aae4efdd92
commit 49375181e4
15 changed files with 174 additions and 264 deletions

View File

@@ -21,6 +21,7 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AdfHttpClient } from './adf-http-client.service'; import { AdfHttpClient } from './adf-http-client.service';
import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error'; import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error';
import EventEmitter from 'eventemitter3';
const securityOptions: SecurityOptions = { const securityOptions: SecurityOptions = {
authentications: {}, authentications: {},
@@ -30,16 +31,9 @@ const securityOptions: SecurityOptions = {
withCredentials: false withCredentials: false
}; };
const emitter = {
emit: () => {},
off: () => {},
on: () => {},
once: () => {}
};
const emitters: Emitters = { const emitters: Emitters = {
eventEmitter: emitter, eventEmitter: new EventEmitter(),
apiClientEmitter: emitter apiClientEmitter: new EventEmitter()
}; };
const mockResponse = { const mockResponse = {
@@ -124,10 +118,10 @@ describe('AdfHttpClient', () => {
httpMethod: 'POST' httpMethod: 'POST'
}; };
const spy = spyOn(emitter, 'emit').and.callThrough(); const eventSpy = spyOn(emitters.eventEmitter, 'emit').and.callThrough();
angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch(() => { angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch(() => {
expect(spy).toHaveBeenCalledWith('unauthorized'); expect(eventSpy).toHaveBeenCalledWith('unauthorized');
done(); done();
}); });

View File

@@ -34,23 +34,24 @@ import { AlfrescoApiParamEncoder } from './alfresco-api/alfresco-api.param-encod
import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error'; import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error';
import { Constructor } from './types'; import { Constructor } from './types';
import { RequestOptions, SecurityOptions } from './interfaces'; import { RequestOptions, SecurityOptions } from './interfaces';
import ee, { Emitter } from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
type EventEmitterInstance = InstanceType<typeof EventEmitter>;
type EventEmitterEvents = 'progress' | 'success' | 'error' | 'forbidden' | 'abort' | 'unauthorized' | string;
export interface Emitters { export interface Emitters {
readonly eventEmitter: Emitter; readonly eventEmitter: EventEmitterInstance;
readonly apiClientEmitter: Emitter; readonly apiClientEmitter: EventEmitterInstance;
} }
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AdfHttpClient implements ee.Emitter, JsApiHttpClient { export class AdfHttpClient implements JsApiHttpClient {
on: ee.EmitterMethod; private eventEmitter = new EventEmitter();
off: ee.EmitterMethod;
once: ee.EmitterMethod;
_disableCsrf: boolean;
emit: (type: string, ...args: any[]) => void; _disableCsrf: boolean;
get disableCsrf(): boolean { get disableCsrf(): boolean {
return this._disableCsrf; return this._disableCsrf;
@@ -68,7 +69,27 @@ export class AdfHttpClient implements ee.Emitter, JsApiHttpClient {
}; };
constructor(private httpClient: HttpClient) { constructor(private httpClient: HttpClient) {
ee(this); // No need for ee(this) anymore - we use composition instead of inheritance
}
// EventEmitter delegation methods
on(event: EventEmitterEvents, fn: (...args: any[]) => void, context?: any): this {
this.eventEmitter.on(event, fn, context);
return this;
}
off(event: EventEmitterEvents, fn?: (...args: any[]) => void, context?: any): this {
this.eventEmitter.off(event, fn, context);
return this;
}
once(event: EventEmitterEvents, fn: (...args: any[]) => void, context?: any): this {
this.eventEmitter.once(event, fn, context);
return this;
}
emit(event: EventEmitterEvents, ...args: any[]): boolean {
return this.eventEmitter.emit(event, ...args);
} }
setDefaultSecurityOption(options: any) { setDefaultSecurityOption(options: any) {
@@ -136,24 +157,19 @@ export class AdfHttpClient implements ee.Emitter, JsApiHttpClient {
private addPromiseListeners<T = any>(promise: Promise<T>, eventEmitter: any) { private addPromiseListeners<T = any>(promise: Promise<T>, eventEmitter: any) {
const eventPromise = Object.assign(promise, { const eventPromise = Object.assign(promise, {
on() { on<K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any) {
// eslint-disable-next-line prefer-spread, prefer-rest-params eventEmitter.on(event, fn, context);
eventEmitter.on.apply(eventEmitter, arguments);
return this; return this;
}, },
once() { once<K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any) {
// eslint-disable-next-line prefer-spread, prefer-rest-params eventEmitter.once(event, fn, context);
eventEmitter.once.apply(eventEmitter, arguments);
return this; return this;
}, },
emit() { emit<K extends string | symbol>(event: K, ...args: any[]): boolean {
// eslint-disable-next-line prefer-spread, prefer-rest-params return eventEmitter.emit(event, ...args);
eventEmitter.emit.apply(eventEmitter, arguments);
return this;
}, },
off() { off<K extends string | symbol>(event: K, fn?: (...args: any[]) => void, context?: any) {
// eslint-disable-next-line prefer-spread, prefer-rest-params eventEmitter.off(event, fn, context);
eventEmitter.off.apply(eventEmitter, arguments);
return this; return this;
} }
}); });
@@ -162,16 +178,17 @@ export class AdfHttpClient implements ee.Emitter, JsApiHttpClient {
} }
private getEventEmitters(): Emitters { private getEventEmitters(): Emitters {
const apiClientEmitter = { const apiClientEmitter: EventEmitterInstance = new EventEmitter();
on: this.on.bind(this),
off: this.off.bind(this), // Bind this instance's methods to the apiClientEmitter for backward compatibility
once: this.once.bind(this), apiClientEmitter.on = this.on.bind(this);
emit: this.emit.bind(this) apiClientEmitter.off = this.off.bind(this);
}; apiClientEmitter.once = this.once.bind(this);
apiClientEmitter.emit = this.emit.bind(this);
return { return {
apiClientEmitter, apiClientEmitter,
eventEmitter: ee({}) eventEmitter: new EventEmitter()
}; };
} }

View File

@@ -16,18 +16,20 @@
*/ */
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
import ee from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
type EventEmitterInstance = InstanceType<typeof EventEmitter>;
export interface AuthenticationServiceInterface { export interface AuthenticationServiceInterface {
onError: any; onError: any;
onLogin: any; onLogin: any;
onLogout: any; onLogout: any;
on: ee.EmitterMethod; on: EventEmitterInstance['on'];
off: ee.EmitterMethod; off: EventEmitterInstance['off'];
once: ee.EmitterMethod; once: EventEmitterInstance['once'];
emit: (type: string, ...args: any[]) => void; emit: EventEmitterInstance['emit'];
getToken(): string; getToken(): string;
isLoggedIn(): boolean; isLoggedIn(): boolean;

View File

@@ -21,13 +21,13 @@ import { BasicAlfrescoAuthService } from '../basic-auth/basic-alfresco-auth.serv
import { Observable, Subject, from } from 'rxjs'; import { Observable, Subject, from } from 'rxjs';
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
import { AuthenticationServiceInterface } from '../interfaces/authentication-service.interface'; import { AuthenticationServiceInterface } from '../interfaces/authentication-service.interface';
import ee from 'event-emitter';
import { RedirectAuthService } from '../oidc/redirect-auth.service'; import { RedirectAuthService } from '../oidc/redirect-auth.service';
import { EventEmitter } from 'eventemitter3';
type EventEmitterInstance = InstanceType<typeof EventEmitter>;
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AuthenticationService implements AuthenticationServiceInterface, ee.Emitter { export class AuthenticationService implements AuthenticationServiceInterface {
onLogin: Subject<any> = new Subject<any>(); onLogin: Subject<any> = new Subject<any>();
onLogout: Subject<any> = new Subject<any>(); onLogout: Subject<any> = new Subject<any>();
onTokenReceived: Subject<any> = new Subject<any>(); onTokenReceived: Subject<any> = new Subject<any>();
@@ -49,19 +49,19 @@ export class AuthenticationService implements AuthenticationServiceInterface, ee
} }
} }
get on(): ee.EmitterMethod { get on(): EventEmitterInstance['on'] {
return this.isOauth() ? this.oidcAuthenticationService.on : this.basicAlfrescoAuthService.on; return this.isOauth() ? this.oidcAuthenticationService.on : this.basicAlfrescoAuthService.on;
} }
get off(): ee.EmitterMethod { get off(): EventEmitterInstance['off'] {
return this.isOauth() ? this.oidcAuthenticationService.off : this.basicAlfrescoAuthService.off; return this.isOauth() ? this.oidcAuthenticationService.off : this.basicAlfrescoAuthService.off;
} }
get once(): ee.EmitterMethod { get once(): EventEmitterInstance['once'] {
return this.isOauth() ? this.oidcAuthenticationService.once : this.basicAlfrescoAuthService.once; return this.isOauth() ? this.oidcAuthenticationService.once : this.basicAlfrescoAuthService.once;
} }
get emit(): (type: string, ...args: any[]) => void { get emit(): EventEmitterInstance['emit'] {
return this.isOauth() ? this.oidcAuthenticationService.emit : this.basicAlfrescoAuthService.emit; return this.isOauth() ? this.oidcAuthenticationService.emit : this.basicAlfrescoAuthService.emit;
} }

View File

@@ -21,13 +21,15 @@ import { Observable, Observer, ReplaySubject, throwError } from 'rxjs';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service'; import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { CookieService } from '../../common/services/cookie.service'; import { CookieService } from '../../common/services/cookie.service';
import { AuthenticationServiceInterface } from '../interfaces/authentication-service.interface'; import { AuthenticationServiceInterface } from '../interfaces/authentication-service.interface';
import ee from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
export abstract class BaseAuthenticationService implements AuthenticationServiceInterface, ee.Emitter { type EventEmitterInstance = InstanceType<typeof EventEmitter>;
on: ee.EmitterMethod;
off: ee.EmitterMethod; export abstract class BaseAuthenticationService implements AuthenticationServiceInterface {
once: ee.EmitterMethod; on: EventEmitterInstance['on'];
emit: (type: string, ...args: any[]) => void; off: EventEmitterInstance['off'];
once: EventEmitterInstance['once'];
emit: EventEmitterInstance['emit'];
protected redirectUrl: RedirectionModel = null; protected redirectUrl: RedirectionModel = null;
@@ -38,9 +40,7 @@ export abstract class BaseAuthenticationService implements AuthenticationService
protected constructor( protected constructor(
protected appConfig: AppConfigService, protected appConfig: AppConfigService,
protected cookie: CookieService protected cookie: CookieService
) { ) {}
ee(this);
}
abstract getAuthHeaders(requestUrl: string, header: HttpHeaders): HttpHeaders; abstract getAuthHeaders(requestUrl: string, header: HttpHeaders): HttpHeaders;
abstract getToken(): string; abstract getToken(): string;

View File

@@ -15,7 +15,7 @@
"url": "https://github.com/Alfresco/alfresco-ng2-components/issues" "url": "https://github.com/Alfresco/alfresco-ng2-components/issues"
}, },
"dependencies": { "dependencies": {
"event-emitter": "^0.3.5", "eventemitter3": "^5.0.1",
"superagent": "^9.0.1", "superagent": "^9.0.1",
"tslib": "^2.6.1" "tslib": "^2.6.1"
}, },

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import ee, { EmitterMethod, Emitter } from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
import { ContentAuth } from './authentication/contentAuth'; import { ContentAuth } from './authentication/contentAuth';
import { ProcessAuth } from './authentication/processAuth'; import { ProcessAuth } from './authentication/processAuth';
import { Oauth2Auth } from './authentication/oauth2Auth'; import { Oauth2Auth } from './authentication/oauth2Auth';
@@ -26,11 +26,12 @@ import { AlfrescoApiConfig } from './alfrescoApiConfig';
import { Authentication } from './authentication/authentication'; import { Authentication } from './authentication/authentication';
import { AlfrescoApiType } from './to-deprecate/alfresco-api-type'; import { AlfrescoApiType } from './to-deprecate/alfresco-api-type';
import { HttpClient } from './api-clients/http-client.interface'; import { HttpClient } from './api-clients/http-client.interface';
import { AlfrescoApiClient, AlfrescoApiClientPromise } from './alfrescoApiClient';
export class AlfrescoApi implements Emitter, AlfrescoApiType { type EventEmitterInstance = InstanceType<typeof EventEmitter>;
export class AlfrescoApi extends AlfrescoApiClient implements AlfrescoApiType {
__type = 'legacy-client'; __type = 'legacy-client';
storage: Storage;
config: AlfrescoApiConfig;
contentClient: ContentClient; contentClient: ContentClient;
contentPrivateClient: ContentClient; contentPrivateClient: ContentClient;
processClient: ProcessClient; processClient: ProcessClient;
@@ -43,18 +44,11 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
processAuth: ProcessAuth; processAuth: ProcessAuth;
contentAuth: ContentAuth; contentAuth: ContentAuth;
on: EmitterMethod;
off: EmitterMethod;
once: EmitterMethod;
bufferEvents: string[] = []; bufferEvents: string[] = [];
emit: (type: string, ...args: any[]) => void;
username: string; username: string;
constructor(config?: AlfrescoApiConfig, public httpClient?: HttpClient) { constructor(config?: AlfrescoApiConfig, httpClient?: HttpClient) {
ee(this); super(undefined, httpClient);
if (config) { if (config) {
this.setConfig(config); this.setConfig(config);
@@ -392,14 +386,15 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
return this.contentAuth.validateTicket(); return this.contentAuth.validateTicket();
} }
private loginBPMECM(username: string, password: string): Promise<[string, string]> { private loginBPMECM(username: string, password: string): AlfrescoApiClientPromise<[string, string]> {
const contentPromise = this.contentAuth.login(username, password); const contentPromise = this.contentAuth.login(username, password);
const processPromise = this.processAuth.login(username, password); const processPromise = this.processAuth.login(username, password);
const promise: any = new Promise<[string, string]>((resolve, reject) => { const eventEmitter: EventEmitterInstance = new EventEmitter();
const promise = new Promise<[string, string]>((resolve, reject) => {
Promise.all([contentPromise, processPromise]).then( Promise.all([contentPromise, processPromise]).then(
(data) => { (data) => {
promise.emit('success'); eventEmitter.emit('success');
resolve(data); resolve(data);
}, },
(error) => { (error) => {
@@ -407,16 +402,15 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
this.processAuth.invalidateSession(); this.processAuth.invalidateSession();
if (error.status === 401) { if (error.status === 401) {
promise.emit('unauthorized'); eventEmitter.emit('unauthorized');
} }
promise.emit('error'); eventEmitter.emit('error');
reject(error); reject(error);
} }
); );
}); });
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, eventEmitter);
return promise;
} }
/** /**
@@ -449,29 +443,29 @@ export class AlfrescoApi implements Emitter, AlfrescoApiType {
return Promise.resolve(); return Promise.resolve();
} }
private _logoutBPMECM(): Promise<void> { private _logoutBPMECM(): AlfrescoApiClientPromise<void> {
const contentPromise = this.contentAuth.logout(); const contentPromise = this.contentAuth.logout();
const processPromise = this.processAuth.logout(); const processPromise = this.processAuth.logout();
const promise: any = new Promise<void>((resolve, reject) => { const eventEmitter: EventEmitterInstance = new EventEmitter();
const promise = new Promise<void>((resolve, reject) => {
Promise.all([contentPromise, processPromise]).then( Promise.all([contentPromise, processPromise]).then(
() => { () => {
this.config.ticket = undefined; this.config.ticket = undefined;
promise.emit('logout'); eventEmitter.emit('logout');
resolve(); resolve();
}, },
(error) => { (error) => {
if (error.status === 401) { if (error.status === 401) {
promise.emit('unauthorized'); eventEmitter.emit('unauthorized');
} }
promise.emit('error'); eventEmitter.emit('error');
reject(error); reject(error);
} }
); );
}); });
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, eventEmitter);
return promise;
} }
/** /**

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import ee from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
import { AlfrescoApiConfig } from './alfrescoApiConfig'; import { AlfrescoApiConfig } from './alfrescoApiConfig';
import { Authentication } from './authentication/authentication'; import { Authentication } from './authentication/authentication';
import { SuperagentHttpClient } from './superagentHttpClient'; import { SuperagentHttpClient } from './superagentHttpClient';
@@ -25,11 +25,13 @@ import { Storage } from './storage';
declare const Buffer: any; declare const Buffer: any;
type EventEmitterInstance = InstanceType<typeof EventEmitter>;
export type AlfrescoApiClientPromise<T = any> = Promise<T> & { export type AlfrescoApiClientPromise<T = any> = Promise<T> & {
on: ee.EmitterMethod; on: <K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any) => AlfrescoApiClientPromise<T>;
off: ee.EmitterMethod; off: <K extends string | symbol>(event: K, fn?: (...args: any[]) => void, context?: any) => AlfrescoApiClientPromise<T>;
once: ee.EmitterMethod; once: <K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any) => AlfrescoApiClientPromise<T>;
emit: (type: string, ...args: any[]) => void; emit: <K extends string | symbol>(event: K, ...args: any[]) => boolean;
abort?: () => void; abort?: () => void;
}; };
@@ -62,11 +64,8 @@ export function buildCollectionParam(param: string[], collectionFormat: string):
} }
} }
export class AlfrescoApiClient implements ee.Emitter, LegacyHttpClient { export class AlfrescoApiClient implements LegacyHttpClient {
on: ee.EmitterMethod; private eventEmitter = new EventEmitter();
off: ee.EmitterMethod;
once: ee.EmitterMethod;
emit: (type: string, ...args: any[]) => void;
storage: Storage; storage: Storage;
host: string; host: string;
@@ -105,13 +104,29 @@ export class AlfrescoApiClient implements ee.Emitter, LegacyHttpClient {
constructor(host?: string, httpClient?: HttpClient) { constructor(host?: string, httpClient?: HttpClient) {
this.host = host; this.host = host;
this.storage = Storage.getInstance(); this.storage = Storage.getInstance();
// fallback for backward compatibility // fallback for backward compatibility
this.httpClient = httpClient || new SuperagentHttpClient(); this.httpClient = httpClient || new SuperagentHttpClient();
}
ee(this); // EventEmitter delegation methods
on<K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any): this {
this.eventEmitter.on(event, fn, context);
return this;
}
off<K extends string | symbol>(event: K, fn?: (...args: any[]) => void, context?: any): this {
this.eventEmitter.off(event, fn, context);
return this;
}
once<K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any): this {
this.eventEmitter.once(event, fn, context);
return this;
}
emit<K extends string | symbol>(event: K, ...args: any[]): boolean {
return this.eventEmitter.emit(event, ...args);
} }
request<T = any>(options: RequestOptions): Promise<T> { request<T = any>(options: RequestOptions): Promise<T> {
@@ -325,7 +340,7 @@ export class AlfrescoApiClient implements ee.Emitter, LegacyHttpClient {
return { return {
apiClientEmitter, apiClientEmitter,
eventEmitter: ee({}) eventEmitter: new EventEmitter()
}; };
} }
@@ -374,27 +389,22 @@ export class AlfrescoApiClient implements ee.Emitter, LegacyHttpClient {
return Boolean(contentType?.match(/^application\/json(;.*)?$/i)); return Boolean(contentType?.match(/^application\/json(;.*)?$/i));
} }
private addPromiseListeners<T = any>(promise: Promise<T>, eventEmitter: ee.Emitter): AlfrescoApiClientPromise<T> { addPromiseListeners<T = any>(promise: Promise<T>, eventEmitter: EventEmitterInstance): AlfrescoApiClientPromise<T> {
return Object.assign(promise, { return Object.assign(promise, {
on() { on<K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any): AlfrescoApiClientPromise<T> {
// eslint-disable-next-line prefer-spread,prefer-rest-params eventEmitter.on(event, fn, context);
eventEmitter.on.apply(eventEmitter, arguments); return this as AlfrescoApiClientPromise<T>;
return this;
}, },
once() { once<K extends string | symbol>(event: K, fn: (...args: any[]) => void, context?: any): AlfrescoApiClientPromise<T> {
// eslint-disable-next-line prefer-spread,prefer-rest-params eventEmitter.once(event, fn, context);
eventEmitter.once.apply(eventEmitter, arguments); return this as AlfrescoApiClientPromise<T>;
return this;
}, },
emit() { emit<K extends string | symbol>(event: K, ...args: any[]): boolean {
// eslint-disable-next-line prefer-spread,prefer-rest-params return eventEmitter.emit(event, ...args);
eventEmitter.emit.apply(eventEmitter, arguments);
return this;
}, },
off() { off<K extends string | symbol>(event: K, fn?: (...args: any[]) => void, context?: any): AlfrescoApiClientPromise<T> {
// eslint-disable-next-line prefer-spread,prefer-rest-params eventEmitter.off(event, fn, context);
eventEmitter.off.apply(eventEmitter, arguments); return this as AlfrescoApiClientPromise<T>;
return this;
} }
}); });
} }

View File

@@ -16,7 +16,9 @@
*/ */
import { Authentication } from '../authentication/authentication'; import { Authentication } from '../authentication/authentication';
import { Emitter } from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
type EventEmitterInstance = InstanceType<typeof EventEmitter>;
export interface RequestOptions { export interface RequestOptions {
path: string; path: string;
@@ -93,8 +95,13 @@ export interface SecurityOptions {
} }
export interface Emitters { export interface Emitters {
readonly eventEmitter: Emitter; readonly eventEmitter: EventEmitterInstance;
readonly apiClientEmitter: Emitter; readonly apiClientEmitter: {
on: EventEmitterInstance['on'];
off: EventEmitterInstance['off'];
once: EventEmitterInstance['once'];
emit: EventEmitterInstance['emit'];
};
} }
export interface HttpClient { export interface HttpClient {

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import ee from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
import { AuthenticationApi, TicketBody } from '../api/auth-rest-api'; import { AuthenticationApi, TicketBody } from '../api/auth-rest-api';
import { AlfrescoApiClient } from '../alfrescoApiClient'; import { AlfrescoApiClient } from '../alfrescoApiClient';
import { AlfrescoApiConfig } from '../alfrescoApiConfig'; import { AlfrescoApiConfig } from '../alfrescoApiConfig';
@@ -104,8 +104,7 @@ export class ContentAuth extends AlfrescoApiClient {
}); });
}); });
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, new EventEmitter());
return promise;
} }
/** /**
@@ -133,8 +132,7 @@ export class ContentAuth extends AlfrescoApiClient {
); );
}); });
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, new EventEmitter());
return promise;
} }
/** /**
@@ -160,8 +158,7 @@ export class ContentAuth extends AlfrescoApiClient {
); );
}); });
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, new EventEmitter());
return promise;
} }
/** /**

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import ee from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
import { AlfrescoApiClient } from '../alfrescoApiClient'; import { AlfrescoApiClient } from '../alfrescoApiClient';
import { AlfrescoApiConfig } from '../alfrescoApiConfig'; import { AlfrescoApiConfig } from '../alfrescoApiConfig';
import { Authentication } from './authentication'; import { Authentication } from './authentication';
@@ -604,7 +604,7 @@ export class Oauth2Auth extends AlfrescoApiClient {
} }
); );
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, new EventEmitter());
} }
pollingRefreshToken() { pollingRefreshToken() {
@@ -654,9 +654,7 @@ export class Oauth2Auth extends AlfrescoApiClient {
); );
}); });
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, new EventEmitter());
return promise;
} }
universalBtoa(stringToConvert: string) { universalBtoa(stringToConvert: string) {

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import ee from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
import { AlfrescoApiClient, AlfrescoApiClientPromise } from '../alfrescoApiClient'; import { AlfrescoApiClient, AlfrescoApiClientPromise } from '../alfrescoApiClient';
import { AlfrescoApiConfig } from '../alfrescoApiConfig'; import { AlfrescoApiConfig } from '../alfrescoApiConfig';
import { Authentication } from './authentication'; import { Authentication } from './authentication';
@@ -123,8 +123,7 @@ export class ProcessAuth extends AlfrescoApiClient {
); );
}); });
ee(promise); // jshint ignore:line return this.addPromiseListeners(promise, new EventEmitter());
return promise;
} }
/** /**
@@ -154,8 +153,7 @@ export class ProcessAuth extends AlfrescoApiClient {
); );
}); });
ee(promise); return this.addPromiseListeners(promise, new EventEmitter());
return promise;
} }
/** /**

View File

@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import ee, { Emitter } from 'event-emitter'; import { EventEmitter } from 'eventemitter3';
import superagent, { Response, SuperAgentRequest } from 'superagent'; import superagent, { Response, SuperAgentRequest } from 'superagent';
import { Authentication } from './authentication/authentication'; import { Authentication } from './authentication/authentication';
import { RequestOptions, HttpClient, SecurityOptions, Emitters } from './api-clients/http-client.interface'; import { RequestOptions, HttpClient, SecurityOptions, Emitters } from './api-clients/http-client.interface';
@@ -26,6 +26,8 @@ import { isBrowser, paramToString } from './utils';
declare const Blob: any; declare const Blob: any;
declare const Buffer: any; declare const Buffer: any;
type EventEmitterInstance = InstanceType<typeof EventEmitter>;
const isProgressEvent = (event: ProgressEvent | unknown): event is ProgressEvent => (event as ProgressEvent)?.lengthComputable; const isProgressEvent = (event: ProgressEvent | unknown): event is ProgressEvent => (event as ProgressEvent)?.lengthComputable;
export class SuperagentHttpClient implements HttpClient { export class SuperagentHttpClient implements HttpClient {
@@ -134,7 +136,7 @@ export class SuperagentHttpClient implements HttpClient {
contentType: string, contentType: string,
accept: string, accept: string,
responseType: string, responseType: string,
eventEmitter: ee.Emitter, eventEmitter: EventEmitterInstance,
returnType: string, returnType: string,
securityOptions: SecurityOptions securityOptions: SecurityOptions
) { ) {
@@ -268,7 +270,7 @@ export class SuperagentHttpClient implements HttpClient {
} }
} }
private progress(event: ProgressEvent | unknown, eventEmitter: Emitter): void { private progress(event: ProgressEvent | unknown, eventEmitter: EventEmitterInstance): void {
if (isProgressEvent(event)) { if (isProgressEvent(event)) {
const percent = Math.round((event.loaded / event.total) * 100); const percent = Math.round((event.loaded / event.total) * 100);

128
package-lock.json generated
View File

@@ -32,7 +32,7 @@
"cropperjs": "1.6.2", "cropperjs": "1.6.2",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
"dotenv-expand": "^5.1.0", "dotenv-expand": "^5.1.0",
"event-emitter": "^0.3.5", "eventemitter3": "^5.0.1",
"graphql-ws": "^6.0.5", "graphql-ws": "^6.0.5",
"material-icons": "^1.13.12", "material-icons": "^1.13.12",
"minimatch-browser": "1.0.0", "minimatch-browser": "1.0.0",
@@ -74,7 +74,6 @@
"@storybook/manager-api": "8.6.14", "@storybook/manager-api": "8.6.14",
"@storybook/theming": "8.6.12", "@storybook/theming": "8.6.12",
"@types/ejs": "^3.1.5", "@types/ejs": "^3.1.5",
"@types/event-emitter": "^0.3.3",
"@types/jasmine": "4.0.3", "@types/jasmine": "4.0.3",
"@types/jasminewd2": "~2.0.2", "@types/jasminewd2": "~2.0.2",
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",
@@ -15894,13 +15893,6 @@
"integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/event-emitter": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/@types/event-emitter/-/event-emitter-0.3.5.tgz",
"integrity": "sha512-zx2/Gg0Eg7gwEiOIIh5w9TrhKKTeQh7CPCOPNc0el4pLSwzebA8SmnHwZs2dWlLONvyulykSwGSQxQHLhjGLvQ==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/express": { "node_modules/@types/express": {
"version": "4.17.23", "version": "4.17.23",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.23.tgz", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.23.tgz",
@@ -20938,19 +20930,6 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/d": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz",
"integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==",
"license": "ISC",
"dependencies": {
"es5-ext": "^0.10.64",
"type": "^2.7.2"
},
"engines": {
"node": ">=0.12"
}
},
"node_modules/data-uri-to-buffer": { "node_modules/data-uri-to-buffer": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
@@ -22024,46 +22003,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/es5-ext": {
"version": "0.10.64",
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz",
"integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {
"es6-iterator": "^2.0.3",
"es6-symbol": "^3.1.3",
"esniff": "^2.0.1",
"next-tick": "^1.1.0"
},
"engines": {
"node": ">=0.10"
}
},
"node_modules/es6-iterator": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
"integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==",
"license": "MIT",
"dependencies": {
"d": "1",
"es5-ext": "^0.10.35",
"es6-symbol": "^3.1.1"
}
},
"node_modules/es6-symbol": {
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz",
"integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==",
"license": "ISC",
"dependencies": {
"d": "^1.0.2",
"ext": "^1.7.0"
},
"engines": {
"node": ">=0.12"
}
},
"node_modules/esbuild": { "node_modules/esbuild": {
"version": "0.25.4", "version": "0.25.4",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.4.tgz", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.4.tgz",
@@ -22819,21 +22758,6 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/esniff": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz",
"integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==",
"license": "ISC",
"dependencies": {
"d": "^1.0.1",
"es5-ext": "^0.10.62",
"event-emitter": "^0.3.5",
"type": "^2.7.2"
},
"engines": {
"node": ">=0.10"
}
},
"node_modules/espree": { "node_modules/espree": {
"version": "9.6.1", "version": "9.6.1",
"resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz",
@@ -22927,20 +22851,10 @@
"resolved": "https://registry.npmjs.org/eve-raphael/-/eve-raphael-0.5.0.tgz", "resolved": "https://registry.npmjs.org/eve-raphael/-/eve-raphael-0.5.0.tgz",
"integrity": "sha512-jrxnPsCGqng1UZuEp9DecX/AuSyAszATSjf4oEcRxvfxa1Oux4KkIPKBAAWWnpdwfARtr+Q0o9aPYWjsROD7ug==" "integrity": "sha512-jrxnPsCGqng1UZuEp9DecX/AuSyAszATSjf4oEcRxvfxa1Oux4KkIPKBAAWWnpdwfARtr+Q0o9aPYWjsROD7ug=="
}, },
"node_modules/event-emitter": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz",
"integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==",
"license": "MIT",
"dependencies": {
"d": "1",
"es5-ext": "~0.10.14"
}
},
"node_modules/eventemitter3": { "node_modules/eventemitter3": {
"version": "4.0.7", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/events": { "node_modules/events": {
@@ -23090,15 +23004,6 @@
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/ext": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz",
"integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==",
"license": "ISC",
"dependencies": {
"type": "^2.7.2"
}
},
"node_modules/extend": { "node_modules/extend": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
@@ -24877,6 +24782,12 @@
"node": "^14.15.0 || ^16.10.0 || >=18.0.0" "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
} }
}, },
"node_modules/http-proxy/node_modules/eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==",
"license": "MIT"
},
"node_modules/http-server": { "node_modules/http-server": {
"version": "14.1.1", "version": "14.1.1",
"resolved": "https://registry.npmjs.org/http-server/-/http-server-14.1.1.tgz", "resolved": "https://registry.npmjs.org/http-server/-/http-server-14.1.1.tgz",
@@ -29226,13 +29137,6 @@
"url": "https://github.com/chalk/ansi-styles?sponsor=1" "url": "https://github.com/chalk/ansi-styles?sponsor=1"
} }
}, },
"node_modules/listr2/node_modules/eventemitter3": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
"integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==",
"dev": true,
"license": "MIT"
},
"node_modules/listr2/node_modules/wrap-ansi": { "node_modules/listr2/node_modules/wrap-ansi": {
"version": "9.0.0", "version": "9.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz",
@@ -30617,12 +30521,6 @@
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/next-tick": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
"integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==",
"license": "ISC"
},
"node_modules/ng-packagr": { "node_modules/ng-packagr": {
"version": "19.2.2", "version": "19.2.2",
"resolved": "https://registry.npmjs.org/ng-packagr/-/ng-packagr-19.2.2.tgz", "resolved": "https://registry.npmjs.org/ng-packagr/-/ng-packagr-19.2.2.tgz",
@@ -38310,12 +38208,6 @@
"dev": true, "dev": true,
"license": "BSD" "license": "BSD"
}, },
"node_modules/type": {
"version": "2.7.3",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz",
"integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==",
"license": "ISC"
},
"node_modules/type-check": { "node_modules/type-check": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",

View File

@@ -52,7 +52,7 @@
"cropperjs": "1.6.2", "cropperjs": "1.6.2",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
"dotenv-expand": "^5.1.0", "dotenv-expand": "^5.1.0",
"event-emitter": "^0.3.5", "eventemitter3": "^5.0.1",
"graphql-ws": "^6.0.5", "graphql-ws": "^6.0.5",
"material-icons": "^1.13.12", "material-icons": "^1.13.12",
"minimatch-browser": "1.0.0", "minimatch-browser": "1.0.0",
@@ -94,7 +94,6 @@
"@storybook/manager-api": "8.6.14", "@storybook/manager-api": "8.6.14",
"@storybook/theming": "8.6.12", "@storybook/theming": "8.6.12",
"@types/ejs": "^3.1.5", "@types/ejs": "^3.1.5",
"@types/event-emitter": "^0.3.3",
"@types/jasmine": "4.0.3", "@types/jasmine": "4.0.3",
"@types/jasminewd2": "~2.0.2", "@types/jasminewd2": "~2.0.2",
"@types/jest": "^29.5.14", "@types/jest": "^29.5.14",