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

This reverts commit 49375181e4.
This commit is contained in:
Vito Albano
2025-09-10 15:57:01 +01:00
committed by GitHub
parent c8c1ae7838
commit fd29e953d6
15 changed files with 267 additions and 174 deletions

View File

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