Skip to content

Commit

Permalink
refactor: replace any types
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Mar 23, 2024
1 parent 521f399 commit e556376
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Data Service', () => {

describe('get', () => {
it('get call sets the accept header', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';

dataService
.get(url, { configId: 'configId1' })
Expand All @@ -47,7 +47,7 @@ describe('Data Service', () => {
}));

it('get call with token the accept header and the token', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';
const token = 'token';

dataService
Expand All @@ -67,7 +67,7 @@ describe('Data Service', () => {
}));

it('call without ngsw-bypass param by default', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';

dataService
.get(url, { configId: 'configId1' })
Expand All @@ -86,7 +86,7 @@ describe('Data Service', () => {
}));

it('call with ngsw-bypass param', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';

dataService
.get(url, { configId: 'configId1', ngswBypass: true })
Expand All @@ -107,7 +107,7 @@ describe('Data Service', () => {

describe('post', () => {
it('call sets the accept header when no other params given', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';

dataService
.post(url, { some: 'thing' }, { configId: 'configId1' })
Expand All @@ -123,7 +123,7 @@ describe('Data Service', () => {
}));

it('call sets custom headers ONLY (No ACCEPT header) when custom headers are given', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';
let headers = new HttpHeaders();

headers = headers.set('X-MyHeader', 'Genesis');
Expand All @@ -143,7 +143,7 @@ describe('Data Service', () => {
}));

it('call without ngsw-bypass param by default', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';

dataService
.post(url, { some: 'thing' }, { configId: 'configId1' })
Expand All @@ -160,7 +160,7 @@ describe('Data Service', () => {
}));

it('call with ngsw-bypass param', waitForAsync(() => {
const url = 'anyurl';
const url = 'testurl';

dataService
.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DataService {

post<T>(
url: string | null,
body: any,
body: unknown,
config: OpenIdConfiguration,
headersParams?: HttpHeaders
): Observable<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { Observable } from 'rxjs';
export class HttpBaseService {
private readonly http = inject(HttpClient);

get<T>(url: string, params?: { [key: string]: any }): Observable<T> {
get<T>(url: string, params?: { [key: string]: unknown }): Observable<T> {
return this.http.get<T>(url, params);
}

post<T>(
url: string,
body: any,
params?: { [key: string]: any }
body: unknown,
params?: { [key: string]: unknown }
): Observable<T> {
return this.http.post<T>(url, body, params);
}
Expand Down
4 changes: 2 additions & 2 deletions projects/angular-auth-oidc-client/src/lib/auth-options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface AuthOptions {
customParams?: { [key: string]: string | number | boolean };
urlHandler?(url: string): any;
urlHandler?(url: string): void;
/** overrides redirectUrl from configuration */
redirectUrl?: string;
}

export interface LogoutAuthOptions {
customParams?: { [key: string]: string | number | boolean };
urlHandler?(url: string): any;
urlHandler?(url: string): void;
logoffMethod?: 'GET' | 'POST';
}
5 changes: 2 additions & 3 deletions projects/angular-auth-oidc-client/src/lib/auth.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {

describe('AuthModule', () => {
describe('APP_CONFIG', () => {
let config: any;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [AuthModule.forRoot({ config: { authority: 'something' } })],
Expand All @@ -27,7 +25,8 @@ describe('AuthModule', () => {
});

it('should provide config', () => {
config = TestBed.inject(PASSED_CONFIG);
const config = TestBed.inject(PASSED_CONFIG);

expect(config).toEqual({ config: { authority: 'something' } });
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export class IntervalService {
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('AuthWellKnownDataService', () => {
(service as any)
.getWellKnownDocument('anyurl', { configId: 'configId1' })
.subscribe({
next: (res: any) => {
next: (res: unknown) => {
expect(res).toBeTruthy();
expect(res).toEqual(DUMMY_WELL_KNOWN_DOCUMENT);
},
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('AuthWellKnownDataService', () => {
);

(service as any).getWellKnownDocument('anyurl', 'configId').subscribe({
error: (err: any) => {
error: (err: unknown) => {
expect(err).toBeTruthy();
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ConfigValidationService {

private validateConfigsInternal(
passedConfigs: OpenIdConfiguration[],
allRulesToUse: any[]
allRulesToUse: ((passedConfig: OpenIdConfiguration[]) => RuleValidationResult)[]
): boolean {
if (passedConfigs.length === 0) {
return false;
Expand All @@ -47,7 +47,7 @@ export class ConfigValidationService {

private validateConfigInternal(
passedConfig: OpenIdConfiguration,
allRulesToUse: any[]
allRulesToUse: ((passedConfig: OpenIdConfiguration) => RuleValidationResult)[]
): boolean {
const allValidationResults = allRulesToUse.map((rule) =>
rule(passedConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface CallbackContext {
isRenewProcess: boolean;
jwtKeys: JwtKeys | null;
validationResult: StateValidationResult | null;
existingIdToken: any;
existingIdToken: string | null;
}

export interface AuthResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ describe('CodeFlowCallbackHandlerService', () => {
'getUrlParameter'
).and.returnValue('params');

getUrlParameterSpy.withArgs('any-url', 'state').and.returnValue('');
getUrlParameterSpy.withArgs('test-url', 'state').and.returnValue('');

service.codeFlowCallback('any-url', { configId: 'configId1' }).subscribe({
service.codeFlowCallback('test-url', { configId: 'configId1' }).subscribe({
error: (err) => {
expect(err).toBeTruthy();
},
Expand All @@ -67,9 +67,9 @@ describe('CodeFlowCallbackHandlerService', () => {
'getUrlParameter'
).and.returnValue('params');

getUrlParameterSpy.withArgs('any-url', 'code').and.returnValue('');
getUrlParameterSpy.withArgs('test-url', 'code').and.returnValue('');

service.codeFlowCallback('any-url', { configId: 'configId1' }).subscribe({
service.codeFlowCallback('test-url', { configId: 'configId1' }).subscribe({
error: (err) => {
expect(err).toBeTruthy();
},
Expand All @@ -92,7 +92,7 @@ describe('CodeFlowCallbackHandlerService', () => {
} as CallbackContext;

service
.codeFlowCallback('any-url', { configId: 'configId1' })
.codeFlowCallback('test-url', { configId: 'configId1' })
.subscribe((callbackContext) => {
expect(callbackContext).toEqual(expectedCallbackContext);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ export class CodeFlowCallbackHandlerService {
}

private handleRefreshRetry(
errors: Observable<any>,
errors: Observable<unknown>,
config: OpenIdConfiguration
): Observable<any> {
): Observable<unknown> {
return errors.pipe(
mergeMap((error) => {
// retry token refresh if there is no internet connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ export class HistoryJwtKeysCallbackHandlerService {
}

private handleResultErrorFromCallback(
result: any,
result: unknown,
isRenewProcess: boolean
): void {
let validationResult = ValidationResult.SecureTokenServerError;

if ((result.error as string) === 'login_required') {
if (result && typeof result === 'object' && 'error' in result && (result.error as string) === 'login_required') {
validationResult = ValidationResult.LoginRequired;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable, inject } from '@angular/core';
import { Observable, of } from 'rxjs';
import { OpenIdConfiguration } from '../../config/openid-configuration';
import { LoggerService } from '../../logging/logger.service';
import { CallbackContext } from '../callback-context';
import { AuthResult, CallbackContext } from '../callback-context';
import { FlowsDataService } from '../flows-data.service';
import { ResetAuthDataService } from '../reset-auth-data.service';

Expand Down Expand Up @@ -34,15 +34,15 @@ export class ImplicitFlowCallbackHandlerService {

hash = hash || this.document.location.hash.substring(1);

const authResult: any = hash
const authResult = hash
.split('&')
.reduce((resultData: any, item: string) => {
const parts = item.split('=');

resultData[parts.shift() as string] = parts.join('=');

return resultData;
}, {});
}, {} as AuthResult);

const callbackContext: CallbackContext = {
code: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('RefreshTokenCallbackHandlerService', () => {
(service as any)
.refreshTokensRequestTokens({} as CallbackContext)
.subscribe({
error: (err: any) => {
error: (err: unknown) => {
expect(err).toBeTruthy();
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export class RefreshTokenCallbackHandlerService {
}

private handleRefreshRetry(
errors: Observable<any>,
errors: Observable<unknown>,
config: OpenIdConfiguration
): Observable<any> {
): Observable<unknown> {
return errors.pipe(
mergeMap((error) => {
// retry token refresh if there is no internet connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CheckSessionService implements OnDestroy {

private checkSessionReceived = false;

private scheduledHeartBeatRunning: any;
private scheduledHeartBeatRunning: number|null= null

private lastIFrameRefresh = 0;

Expand All @@ -45,7 +45,7 @@ export class CheckSessionService implements OnDestroy {
false
);

private iframeMessageEventListener: any;
private iframeMessageEventListener?: (this:Window, ev: MessageEvent<any>) => any;

get checkSessionChanged$(): Observable<boolean> {
return this.checkSessionChangedInternal$.asObservable();
Expand All @@ -55,7 +55,7 @@ export class CheckSessionService implements OnDestroy {
this.stop();
const windowAsDefaultView = this.document.defaultView;

if (windowAsDefaultView) {
if (windowAsDefaultView && this.iframeMessageEventListener) {
windowAsDefaultView.removeEventListener(
'message',
this.iframeMessageEventListener,
Expand Down Expand Up @@ -224,10 +224,10 @@ export class CheckSessionService implements OnDestroy {
}

this.zone.runOutsideAngular(() => {
this.scheduledHeartBeatRunning = setTimeout(
this.scheduledHeartBeatRunning = this.document?.defaultView?.setTimeout(
() => this.zone.run(pollServerSessionRecur),
this.heartBeatInterval
);
) ?? null;
});
});
};
Expand All @@ -236,8 +236,10 @@ export class CheckSessionService implements OnDestroy {
}

private clearScheduledHeartBeat(): void {
clearTimeout(this.scheduledHeartBeatRunning);
this.scheduledHeartBeatRunning = null;
if(this.scheduledHeartBeatRunning !== null) {
clearTimeout(this.scheduledHeartBeatRunning);
this.scheduledHeartBeatRunning = null;
}
}

private messageHandler(configuration: OpenIdConfiguration, e: any): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class SilentRenewService {
this.refreshSessionWithIFrameCompletedInternal$.next(callbackContext);
this.flowsDataService.resetSilentRenewRunning(config);
},
error: (err: any) => {
error: (err: unknown) => {
this.loggerService.logError(config, 'Error: ' + err);
this.refreshSessionWithIFrameCompletedInternal$.next(null);
this.flowsDataService.resetSilentRenewRunning(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Injectable } from '@angular/core';
*/
@Injectable({ providedIn: 'root' })
export abstract class AbstractLoggerService {
abstract logError(message: any, ...args: any[]): void;
abstract logError(message: string|object, ...args: any[]): void;

abstract logWarning(message: any, ...args: any[]): void;
abstract logWarning(message: string|object, ...args: any[]): void;

abstract logDebug(message: any, ...args: any[]): void;
abstract logDebug(message: string|object, ...args: any[]): void;
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { AbstractLoggerService } from './abstract-logger.service';

@Injectable({ providedIn: 'root' })
export class ConsoleLoggerService implements AbstractLoggerService {
logError(message?: any, ...args: any[]): void {
logError(message: string|object, ...args: any[]): void {
console.error(message, ...args);
}

logWarning(message?: any, ...args: any[]): void {
logWarning(message: string|object, ...args: any[]): void {
console.warn(message, ...args);
}

logDebug(message?: any, ...args: any[]): void {
logDebug(message: string|object, ...args: any[]): void {
console.debug(message, ...args);
}
}
Loading

0 comments on commit e556376

Please sign in to comment.