diff --git a/docs/oidc-client-ts.api.md b/docs/oidc-client-ts.api.md index 1170b8849..fc28ae363 100644 --- a/docs/oidc-client-ts.api.md +++ b/docs/oidc-client-ts.api.md @@ -1022,17 +1022,17 @@ export class UserManagerEvents extends AccessTokenEvents { addUserSignedOut(cb: UserSignedOutCallback): () => void; addUserUnloaded(cb: UserUnloadedCallback): () => void; // (undocumented) - load(user: User, raiseEvent?: boolean): void; + load(user: User, raiseEvent?: boolean): Promise; // (undocumented) protected readonly _logger: Logger; // @internal (undocumented) - _raiseSilentRenewError(e: Error): void; + _raiseSilentRenewError(e: Error): Promise; // @internal (undocumented) - _raiseUserSessionChanged(): void; + _raiseUserSessionChanged(): Promise; // @internal (undocumented) - _raiseUserSignedIn(): void; + _raiseUserSignedIn(): Promise; // @internal (undocumented) - _raiseUserSignedOut(): void; + _raiseUserSignedOut(): Promise; removeSilentRenewError(cb: SilentRenewErrorCallback): void; removeUserLoaded(cb: UserLoadedCallback): void; removeUserSessionChanged(cb: UserSessionChangedCallback): void; @@ -1040,7 +1040,7 @@ export class UserManagerEvents extends AccessTokenEvents { removeUserSignedOut(cb: UserSignedOutCallback): void; removeUserUnloaded(cb: UserUnloadedCallback): void; // (undocumented) - unload(): void; + unload(): Promise; } // @public diff --git a/src/SessionMonitor.ts b/src/SessionMonitor.ts index 4feea98bc..de8ce672a 100644 --- a/src/SessionMonitor.ts +++ b/src/SessionMonitor.ts @@ -148,7 +148,7 @@ export class SessionMonitor { this._checkSessionIFrame.start(session.session_state); logger.debug("same sub still logged in at OP, session state has changed, restarting check session iframe; session_state", session.session_state); - this._userManager.events._raiseUserSessionChanged(); + await this._userManager.events._raiseUserSessionChanged(); } else { logger.debug("different subject signed into OP", session.sub); @@ -160,10 +160,10 @@ export class SessionMonitor { if (raiseEvent) { if (this._sub) { - this._userManager.events._raiseUserSignedOut(); + await this._userManager.events._raiseUserSignedOut(); } else { - this._userManager.events._raiseUserSignedIn(); + await this._userManager.events._raiseUserSignedIn(); } } else { logger.debug("no change in session detected, no event to raise"); @@ -172,7 +172,7 @@ export class SessionMonitor { catch (err) { if (this._sub) { logger.debug("Error calling queryCurrentSigninSession; raising signed out event", err); - this._userManager.events._raiseUserSignedOut(); + await this._userManager.events._raiseUserSignedOut(); } } }; diff --git a/src/SilentRenewService.ts b/src/SilentRenewService.ts index db5a9f7e5..45d4bf084 100644 --- a/src/SilentRenewService.ts +++ b/src/SilentRenewService.ts @@ -59,7 +59,7 @@ export class SilentRenewService { } logger.error("Error from signinSilent:", err); - this._userManager.events._raiseSilentRenewError(err as Error); + await this._userManager.events._raiseSilentRenewError(err as Error); } }; } diff --git a/src/UserManager.test.ts b/src/UserManager.test.ts index a4eef9288..a079a7c31 100644 --- a/src/UserManager.test.ts +++ b/src/UserManager.test.ts @@ -93,14 +93,14 @@ describe("UserManager", () => { }); describe("getUser", () => { - it("should be able to call getUser without recursion", () => { + it("should be able to call getUser without recursion", async () => { // arrange subject.events.addUserLoaded(async () => { await subject.getUser(); }); // act - subject.events.load({} as User); + await subject.events.load({} as User); }); it("should return user if there is a user stored", async () => { @@ -314,7 +314,7 @@ describe("UserManager", () => { scope: "openid profile email", }; jest.spyOn(subject["_client"], "processResourceOwnerPasswordCredentials").mockResolvedValue(mockUser as SigninResponse); - jest.spyOn(subject["_events"], "load").mockReturnValue(); + jest.spyOn(subject["_events"], "load").mockImplementation(() => Promise.resolve()); // act const user:User = await subject.signinResourceOwnerCredentials({ username: "u", password: "p" }); diff --git a/src/UserManager.ts b/src/UserManager.ts index 65e18825e..81af6738c 100644 --- a/src/UserManager.ts +++ b/src/UserManager.ts @@ -137,7 +137,7 @@ export class UserManager { const user = await this._loadUser(); if (user) { logger.info("user loaded"); - this._events.load(user, false); + await this._events.load(user, false); return user; } @@ -154,7 +154,7 @@ export class UserManager { const logger = this._logger.create("removeUser"); await this.storeUser(null); logger.info("user removed from storage"); - this._events.unload(); + await this._events.unload(); } /** @@ -337,7 +337,7 @@ export class UserManager { const user = new User({ ...args.state, ...response }); await this.storeUser(user); - this._events.load(user); + await this._events.load(user); return user; } @@ -516,7 +516,7 @@ export class UserManager { await this.storeUser(user); logger.debug("user stored"); - this._events.load(user); + await this._events.load(user); return user; } @@ -718,7 +718,7 @@ export class UserManager { await this.storeUser(user); logger.debug("user stored"); - this._events.load(user); + await this._events.load(user); } /** diff --git a/src/UserManagerEvents.test.ts b/src/UserManagerEvents.test.ts index cdab47cb5..acac474c7 100644 --- a/src/UserManagerEvents.test.ts +++ b/src/UserManagerEvents.test.ts @@ -19,32 +19,32 @@ describe("UserManagerEvents", () => { describe("silent renew error", () => { - it("should allow callback", () => { + it("should allow callback", async () => { // arrange const cb = jest.fn(); // act subject.addSilentRenewError(cb); - subject._raiseSilentRenewError(new Error("boom")); + await subject._raiseSilentRenewError(new Error("boom")); // assert expect(cb).toBeCalled(); }); - it("should allow unregistering callback", () => { + it("should allow unregistering callback", async () => { // arrange const cb = jest.fn(); // act subject.addSilentRenewError(cb); subject.removeSilentRenewError(cb); - subject._raiseSilentRenewError(new Error("boom")); + await subject._raiseSilentRenewError(new Error("boom")); // assert expect(cb).toBeCalledTimes(0); }); - it("should pass error to callback", () => { + it("should pass error to callback", async () => { // arrange let e: Error | null = null; const cb = function (arg_e: Error) { @@ -54,7 +54,7 @@ describe("UserManagerEvents", () => { // act subject.addSilentRenewError(cb); - subject._raiseSilentRenewError(expected); + await subject._raiseSilentRenewError(expected); // assert expect(e).toEqual(expected); diff --git a/src/UserManagerEvents.ts b/src/UserManagerEvents.ts index 746a14b8a..a2b063e90 100644 --- a/src/UserManagerEvents.ts +++ b/src/UserManagerEvents.ts @@ -48,15 +48,15 @@ export class UserManagerEvents extends AccessTokenEvents { super({ expiringNotificationTimeInSeconds: settings.accessTokenExpiringNotificationTimeInSeconds }); } - public load(user: User, raiseEvent=true): void { + public async load(user: User, raiseEvent=true): Promise { super.load(user); if (raiseEvent) { - this._userLoaded.raise(user); + await this._userLoaded.raise(user); } } - public unload(): void { + public async unload(): Promise { super.unload(); - this._userUnloaded.raise(); + await this._userUnloaded.raise(); } /** @@ -100,8 +100,8 @@ export class UserManagerEvents extends AccessTokenEvents { /** * @internal */ - public _raiseSilentRenewError(e: Error): void { - this._silentRenewError.raise(e); + public async _raiseSilentRenewError(e: Error): Promise { + await this._silentRenewError.raise(e); } /** @@ -120,8 +120,8 @@ export class UserManagerEvents extends AccessTokenEvents { /** * @internal */ - public _raiseUserSignedIn(): void { - this._userSignedIn.raise(); + public async _raiseUserSignedIn(): Promise { + await this._userSignedIn.raise(); } /** @@ -140,8 +140,8 @@ export class UserManagerEvents extends AccessTokenEvents { /** * @internal */ - public _raiseUserSignedOut(): void { - this._userSignedOut.raise(); + public async _raiseUserSignedOut(): Promise { + await this._userSignedOut.raise(); } /** @@ -160,7 +160,7 @@ export class UserManagerEvents extends AccessTokenEvents { /** * @internal */ - public _raiseUserSessionChanged(): void { - this._userSessionChanged.raise(); + public async _raiseUserSessionChanged(): Promise { + await this._userSessionChanged.raise(); } } diff --git a/src/navigators/IFrameWindow.ts b/src/navigators/IFrameWindow.ts index 55264e1ff..d8720b27d 100644 --- a/src/navigators/IFrameWindow.ts +++ b/src/navigators/IFrameWindow.ts @@ -49,7 +49,7 @@ export class IFrameWindow extends AbstractChildWindow { public async navigate(params: NavigateParams): Promise { this._logger.debug("navigate: Using timeout of:", this._timeoutInSeconds); - const timer = setTimeout(() => this._abort.raise(new ErrorTimeout("IFrame timed out without a response")), this._timeoutInSeconds * 1000); + const timer = setTimeout(() => void this._abort.raise(new ErrorTimeout("IFrame timed out without a response")), this._timeoutInSeconds * 1000); this._disposeHandlers.add(() => clearTimeout(timer)); return await super.navigate(params); @@ -61,7 +61,7 @@ export class IFrameWindow extends AbstractChildWindow { this._frame.addEventListener("load", (ev) => { const frame = ev.target as HTMLIFrameElement; frame.parentNode?.removeChild(frame); - this._abort.raise(new Error("IFrame removed from DOM")); + void this._abort.raise(new Error("IFrame removed from DOM")); }, true); this._frame.contentWindow?.location.replace("about:blank"); } diff --git a/src/navigators/PopupWindow.ts b/src/navigators/PopupWindow.ts index 9624537a7..4f5144e36 100644 --- a/src/navigators/PopupWindow.ts +++ b/src/navigators/PopupWindow.ts @@ -35,7 +35,7 @@ export class PopupWindow extends AbstractChildWindow { if (popupWindowFeatures.closePopupWindowAfterInSeconds && popupWindowFeatures.closePopupWindowAfterInSeconds > 0) { setTimeout(() => { if (!this._window || typeof this._window.closed !== "boolean" || this._window.closed) { - this._abort.raise(new Error("Popup blocked by user")); + void this._abort.raise(new Error("Popup blocked by user")); return; } @@ -49,7 +49,7 @@ export class PopupWindow extends AbstractChildWindow { const popupClosedInterval = setInterval(() => { if (!this._window || this._window.closed) { - this._abort.raise(new Error("Popup closed by user")); + void this._abort.raise(new Error("Popup closed by user")); } }, checkForPopupClosedInterval); this._disposeHandlers.add(() => clearInterval(popupClosedInterval)); @@ -61,7 +61,7 @@ export class PopupWindow extends AbstractChildWindow { if (this._window) { if (!this._window.closed) { this._window.close(); - this._abort.raise(new Error("Popup closed")); + void this._abort.raise(new Error("Popup closed")); } } this._window = null; diff --git a/src/utils/Event.test.ts b/src/utils/Event.test.ts index 3b06d7930..5cc65b236 100644 --- a/src/utils/Event.test.ts +++ b/src/utils/Event.test.ts @@ -13,19 +13,19 @@ describe("Event", () => { describe("addHandler", () => { - it("should allow callback to be invoked", () => { + it("should allow callback to be invoked", async () => { // arrange const cb = jest.fn(); // act subject.addHandler(cb); - subject.raise(); + await subject.raise(); // assert expect(cb).toBeCalled(); }); - it("should allow multiple callbacks", () => { + it("should allow multiple callbacks", async () => { // arrange const cb = jest.fn(); @@ -34,7 +34,7 @@ describe("Event", () => { subject.addHandler(cb); subject.addHandler(cb); subject.addHandler(cb); - subject.raise(); + await subject.raise(); // assert expect(cb).toBeCalledTimes(4); @@ -43,20 +43,20 @@ describe("Event", () => { describe("removeHandler", () => { - it("should remove callback from being invoked", () => { + it("should remove callback from being invoked", async () => { // arrange const cb = jest.fn(); // act subject.addHandler(cb); subject.removeHandler(cb); - subject.raise(); + await subject.raise(); // assert expect(cb).toBeCalledTimes(0); }); - it("should remove individual callback", () => { + it("should remove individual callback", async () => { // arrange const cb1 = jest.fn(); const cb2 = jest.fn(); @@ -68,7 +68,7 @@ describe("Event", () => { subject.removeHandler(cb1); subject.removeHandler(cb1); - subject.raise(); + await subject.raise(); // assert expect(cb1).toBeCalledTimes(0); @@ -78,7 +78,7 @@ describe("Event", () => { describe("raise", () => { - it("should pass params", () => { + it("should pass params", async () => { // arrange const typedSubject = subject as Event<[number, number, number]>; let a = 10; @@ -92,7 +92,7 @@ describe("Event", () => { typedSubject.addHandler(cb); // act - typedSubject.raise(1, 2, 3); + await typedSubject.raise(1, 2, 3); // assert expect(a).toEqual(1); diff --git a/src/utils/Event.ts b/src/utils/Event.ts index b9a549465..1c3f019c4 100644 --- a/src/utils/Event.ts +++ b/src/utils/Event.ts @@ -30,10 +30,10 @@ export class Event { } } - public raise(...ev: EventType): void { + public async raise(...ev: EventType): Promise { this._logger.debug("raise:", ...ev); for (const cb of this._callbacks) { - void cb(...ev); + await cb(...ev); } } } diff --git a/src/utils/Timer.test.ts b/src/utils/Timer.test.ts index 2dc7093a5..46b307e71 100644 --- a/src/utils/Timer.test.ts +++ b/src/utils/Timer.test.ts @@ -180,7 +180,7 @@ describe("Timer", () => { describe("addHandler", () => { - it("should allow callback to be invoked", () => { + it("should allow callback to be invoked", async () => { // arrange const cb = jest.fn(); @@ -188,13 +188,13 @@ describe("Timer", () => { subject.addHandler(cb); subject.init(10); now += 10; - jest.runOnlyPendingTimers(); + await jest.runOnlyPendingTimersAsync(); // assert expect(cb).toBeCalled(); }); - it("should allow multiple callbacks", () => { + it("should allow multiple callbacks", async () => { // arrange const cb = jest.fn(); @@ -205,7 +205,7 @@ describe("Timer", () => { subject.addHandler(cb); subject.init(10); now += 10; - jest.runOnlyPendingTimers(); + await jest.runOnlyPendingTimersAsync(); // assert expect(cb).toBeCalledTimes(4); diff --git a/src/utils/Timer.ts b/src/utils/Timer.ts index 82bf97370..2f8966997 100644 --- a/src/utils/Timer.ts +++ b/src/utils/Timer.ts @@ -57,7 +57,7 @@ export class Timer extends Event<[void]> { if (this._expiration <= Timer.getEpochTime()) { this.cancel(); - super.raise(); + void super.raise(); } }; }