Skip to content

Commit

Permalink
fix: authts#7 drop Global.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Jul 21, 2021
1 parent e5d6cad commit 142d883
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 84 deletions.
65 changes: 0 additions & 65 deletions src/Global.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/JsonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { Log } from './Log';
import { Global } from './Global';

export class JsonService {
private _contentTypes: string[];
Expand All @@ -11,7 +10,7 @@ export class JsonService {

constructor(
additionalContentTypes: string[] | null = null,
XMLHttpRequestCtor = Global.XMLHttpRequest,
XMLHttpRequestCtor = XMLHttpRequest,
jwtHandler: any = null
) {
if (additionalContentTypes && Array.isArray(additionalContentTypes))
Expand Down
5 changes: 2 additions & 3 deletions src/SessionMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

import { Log } from './Log';
import { CheckSessionIFrame } from './CheckSessionIFrame';
import { Global } from './Global';
import { UserManager } from './UserManager';
import { IntervalTimer } from './Timer';
import { g_timer, IntervalTimer } from './Timer';

export class SessionMonitor {
private _userManager: UserManager;
Expand All @@ -15,7 +14,7 @@ export class SessionMonitor {
private _sid: any;
private _checkSessionIFrame?: CheckSessionIFrame;

constructor(userManager: UserManager, CheckSessionIFrameCtor = CheckSessionIFrame, timer = Global.timer) {
constructor(userManager: UserManager, CheckSessionIFrameCtor = CheckSessionIFrame, timer = g_timer) {
if (!userManager) {
Log.error("SessionMonitor.ctor: No user manager passed to SessionMonitor");
throw new Error("userManager");
Expand Down
17 changes: 14 additions & 3 deletions src/Timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { Log } from './Log';
import { Global } from './Global';
import { Event } from './Event';

const TimerDuration = 5; // seconds

export type IntervalTimer = { setInterval: (cb: (...args: any[]) => void, duration?: number | undefined) => number; clearInterval: (handle: number) => void; };
export type IntervalTimer = {
setInterval: (cb: (...args: any[]) => void, duration?: number | undefined) => number;
clearInterval: (handle: number) => void;
};
export const g_timer: IntervalTimer = {
setInterval: function (cb: (...args: any[]) => void, duration?: number): number {
// @ts-ignore
return setInterval(cb, duration);
},
clearInterval: function (handle: number): void {
return clearInterval(handle);
}
};

export class Timer extends Event {
private _timer: IntervalTimer;
private _nowFunc: () => number;
private _timerHandle: number | null;
private _expiration: number;

constructor(name: string, timer = Global.timer, nowFunc?: (() => number)) {
constructor(name: string, timer = g_timer, nowFunc?: (() => number)) {
super(name);
this._timer = timer;

Expand Down
3 changes: 1 addition & 2 deletions src/TokenRevocationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { Log } from './Log';
import { Global } from './Global';
import { MetadataService } from './MetadataService';
import { OidcClientSettingsStore } from './OidcClientSettings';

Expand All @@ -14,7 +13,7 @@ export class TokenRevocationClient {
private _XMLHttpRequestCtor: typeof XMLHttpRequest;
private _metadataService: MetadataService;

constructor(settings: OidcClientSettingsStore, XMLHttpRequestCtor = Global.XMLHttpRequest, MetadataServiceCtor = MetadataService) {
constructor(settings: OidcClientSettingsStore, XMLHttpRequestCtor = XMLHttpRequest, MetadataServiceCtor = MetadataService) {
if (!settings) {
Log.error("TokenRevocationClient.ctor: No settings provided");
throw new Error("No settings provided.");
Expand Down
5 changes: 2 additions & 3 deletions src/UrlUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { Log } from './Log';
import { Global } from './Global';

export class UrlUtility {
static addQueryParam(url: string, name: string, value: string) {
Expand All @@ -21,9 +20,9 @@ export class UrlUtility {
return url;
}

static parseUrlFragment(value?: string, delimiter = "#", global = Global) {
static parseUrlFragment(value?: string, delimiter = "#") {
if (typeof value !== 'string') {
value = global.location.href;
value = location.href;
}

var idx = value.lastIndexOf(delimiter);
Expand Down
3 changes: 1 addition & 2 deletions src/UserManagerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { RedirectNavigator } from './RedirectNavigator';
import { PopupNavigator } from './PopupNavigator';
import { IFrameNavigator } from './IFrameNavigator';
import { WebStorageStateStore } from './WebStorageStateStore';
import { Global } from './Global';
import { SigninRequest } from './SigninRequest';

const DefaultAccessTokenExpiringNotificationTime = 60;
Expand Down Expand Up @@ -95,7 +94,7 @@ export class UserManagerSettingsStore extends OidcClientSettingsStore {
redirectNavigator = new RedirectNavigator(),
popupNavigator = new PopupNavigator(),
iframeNavigator = new IFrameNavigator(),
userStore = new WebStorageStateStore({ store: Global.sessionStorage })
userStore = new WebStorageStateStore({ store: sessionStorage })
}: UserManagerSettings = {}) {
super(arguments[0]);

Expand Down
3 changes: 1 addition & 2 deletions src/WebStorageStateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { Log } from './Log';
import { Global } from './Global';

export class WebStorageStateStore {
private _store: Storage
private _prefix: string

constructor({prefix = "oidc.", store = Global.localStorage} = {}) {
constructor({ prefix = "oidc.", store = localStorage } = {}) {
this._store = store;
this._prefix = prefix;
}
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { CheckSessionIFrame } from './CheckSessionIFrame';
import { TokenRevocationClient } from './TokenRevocationClient';
import { SessionMonitor } from './SessionMonitor';
import { SessionStatus } from './SessionStatus';
import { Global } from './Global';
import { User } from './User';

import { Version } from './Version';
Expand All @@ -41,6 +40,5 @@ export {
CheckSessionIFrame,
TokenRevocationClient,
SessionMonitor,
Global,
User
};

0 comments on commit 142d883

Please sign in to comment.