Skip to content

Commit 41e89ea

Browse files
committed
fix esLint issues
1 parent 6397a3c commit 41e89ea

4 files changed

Lines changed: 95 additions & 104 deletions

File tree

packages/javascript/src/AsgardeoJavaScriptClient.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,23 @@ import {AuthCodeResponse} from './models/auth-code-response';
2727
import {AsgardeoClient} from './models/client';
2828
import {Config, SignInOptions, SignOutOptions, SignUpOptions} from './models/config';
2929
import {Crypto} from './models/crypto';
30-
import {EmbeddedFlowExecuteRequestConfig, EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse} from './models/embedded-flow';
31-
import {EmbeddedSignInFlowAuthenticator, EmbeddedSignInFlowHandleResponse, EmbeddedSignInFlowInitiateResponse, EmbeddedSignInFlowStatus} from './models/embedded-signin-flow';
30+
import {
31+
EmbeddedFlowExecuteRequestConfig,
32+
EmbeddedFlowExecuteRequestPayload,
33+
EmbeddedFlowExecuteResponse,
34+
} from './models/embedded-flow';
35+
import {
36+
EmbeddedSignInFlowAuthenticator,
37+
EmbeddedSignInFlowHandleResponse,
38+
EmbeddedSignInFlowInitiateResponse,
39+
EmbeddedSignInFlowStatus,
40+
} from './models/embedded-signin-flow';
3241
import {AllOrganizationsApiResponse, Organization} from './models/organization';
3342
import {Storage} from './models/store';
3443
import {TokenExchangeRequestConfig, TokenResponse} from './models/token';
3544
import {User, UserProfile} from './models/user';
3645
import StorageManager from './StorageManager';
3746

38-
/**
39-
* Base class for implementing Asgardeo clients.
40-
* This class provides the core functionality for managing user authentication and sessions.
41-
*
42-
* @typeParam T - Configuration type that extends Config.
43-
*/
4447
class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
4548
private cacheStore: Storage;
4649

@@ -64,6 +67,7 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
6467
this.baseURL = config.baseUrl ?? '';
6568
}
6669

70+
/* eslint-disable class-methods-use-this, @typescript-eslint/no-unused-vars */
6771
switchOrganization(_organization: Organization, _sessionId?: string): Promise<TokenResponse | Response> {
6872
throw new Error('Method not implemented.');
6973
}
@@ -157,6 +161,7 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
157161
): Promise<void | EmbeddedFlowExecuteResponse> {
158162
throw new Error('Method not implemented.');
159163
}
164+
/* eslint-enable class-methods-use-this, @typescript-eslint/no-unused-vars */
160165

161166
public async getAgentToken(agentConfig: AgentConfig): Promise<TokenResponse> {
162167
const customParam: Record<string, string> = {
@@ -176,6 +181,7 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
176181
);
177182

178183
if (!usernamePasswordAuthenticator) {
184+
// eslint-disable-next-line no-console
179185
console.error('Basic authenticator not found among authentication steps.');
180186
return Promise.reject(new Error('Basic authenticator not found among authentication steps.'));
181187
}
@@ -197,6 +203,7 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
197203
const authnResponse: EmbeddedSignInFlowHandleResponse = await executeEmbeddedSignInFlow(authnRequest);
198204

199205
if (authnResponse.flowStatus !== EmbeddedSignInFlowStatus.SuccessCompleted) {
206+
// eslint-disable-next-line no-console
200207
console.error('Agent Authentication Failed.');
201208
return Promise.reject(new Error('Agent Authentication Failed.'));
202209
}
@@ -220,6 +227,7 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
220227
if (authURL) {
221228
return Promise.resolve(authURL.toString());
222229
}
230+
223231
return Promise.reject(new Error('Could not build Authorize URL'));
224232
}
225233

@@ -232,7 +240,7 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
232240
},
233241
};
234242

235-
return await this.auth.requestAccessToken(
243+
return this.auth.requestAccessToken(
236244
authCodeResponse.code,
237245
authCodeResponse.session_state,
238246
authCodeResponse.state,

packages/javascript/src/DefaultCacheStore.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,46 @@
1717
*/
1818

1919
export class DefaultCacheStore implements Storage {
20-
private cache: Map<string, string>;
20+
private cache: Map<string, string>;
2121

22-
constructor() {
23-
this.cache = new Map<string, string>();
24-
}
22+
constructor() {
23+
this.cache = new Map<string, string>();
24+
}
2525

26-
public get length(): number {
27-
return this.cache.size;
28-
}
26+
public get length(): number {
27+
return this.cache.size;
28+
}
2929

30-
public getItem(key: string): string | null {
31-
return this.cache.get(key) ?? null;
32-
}
30+
public getItem(key: string): string | null {
31+
return this.cache.get(key) ?? null;
32+
}
3333

34-
public setItem(key: string, value: string): void {
35-
this.cache.set(key, value);
36-
}
34+
public setItem(key: string, value: string): void {
35+
this.cache.set(key, value);
36+
}
3737

38-
public removeItem(key: string): void {
39-
this.cache.delete(key);
40-
}
38+
public removeItem(key: string): void {
39+
this.cache.delete(key);
40+
}
4141

42-
public clear(): void {
43-
this.cache.clear();
44-
}
42+
public clear(): void {
43+
this.cache.clear();
44+
}
4545

46-
public key(index: number): string | null {
47-
const keys: string[] = Array.from(this.cache.keys());
48-
return keys[index] ?? null;
49-
}
46+
public key(index: number): string | null {
47+
const keys: string[] = Array.from(this.cache.keys());
48+
return keys[index] ?? null;
49+
}
5050

51-
public async setData(key: string, value: string): Promise<void> {
52-
this.cache.set(key, value);
53-
}
51+
public async setData(key: string, value: string): Promise<void> {
52+
this.cache.set(key, value);
53+
}
5454

55-
public async getData(key: string): Promise<string> {
56-
return this.cache.get(key) ?? '{}';
57-
}
55+
public async getData(key: string): Promise<string> {
56+
return this.cache.get(key) ?? '{}';
57+
}
5858

59-
public async removeData(key: string): Promise<void> {
60-
this.cache.delete(key);
61-
}
59+
public async removeData(key: string): Promise<void> {
60+
this.cache.delete(key);
61+
}
6262
}

packages/javascript/src/DefaultCrypto.ts

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,77 +17,59 @@
1717
*/
1818

1919
import * as jose from 'jose';
20-
import { Crypto, JWKInterface } from './models/crypto';
20+
import {Crypto, JWKInterface} from './models/crypto';
2121

2222
/**
2323
* Default implementation of the Crypto interface using the 'jose' library
2424
* and the native Web Crypto API.
2525
*/
2626
export class DefaultCrypto implements Crypto<Uint8Array> {
27-
/**
28-
* Decodes a base64url string back into a UTF-8 string.
29-
*/
30-
// eslint-disable-next-line class-methods-use-this
31-
public base64URLDecode(value: string): string {
32-
const decodedArray: Uint8Array = jose.base64url.decode(value);
33-
return new TextDecoder().decode(decodedArray);
34-
}
27+
// eslint-disable-next-line class-methods-use-this
28+
public base64URLDecode(value: string): string {
29+
const decodedArray: Uint8Array = jose.base64url.decode(value);
30+
return new TextDecoder().decode(decodedArray);
31+
}
3532

36-
/**
37-
* Encodes a Uint8Array into a base64url string.
38-
*/
39-
// eslint-disable-next-line class-methods-use-this
40-
public base64URLEncode(value: Uint8Array): string {
41-
return jose.base64url.encode(value);
42-
}
33+
// eslint-disable-next-line class-methods-use-this
34+
public base64URLEncode(value: Uint8Array): string {
35+
return jose.base64url.encode(value);
36+
}
4337

44-
/**
45-
* Generates cryptographically strong random bytes.
46-
*/
47-
// eslint-disable-next-line class-methods-use-this
48-
public generateRandomBytes(length: number): Uint8Array {
49-
return crypto.getRandomValues(new Uint8Array(length));
50-
}
38+
// eslint-disable-next-line class-methods-use-this
39+
public generateRandomBytes(length: number): Uint8Array {
40+
return crypto.getRandomValues(new Uint8Array(length));
41+
}
5142

52-
/**
53-
* Hash data using SHA-256.
54-
* Note: The Crypto interface expects synchronous return, but Web Crypto is async.
55-
* This implementation throws an error - use IsomorphicCrypto wrapper for async hashing.
56-
*/
57-
// eslint-disable-next-line class-methods-use-this
58-
public async hashSha256(data: string): Promise<Uint8Array> {
59-
const encoder: TextEncoder = new TextEncoder();
60-
const dataBuffer: Uint8Array = encoder.encode(data);
43+
// eslint-disable-next-line class-methods-use-this
44+
public async hashSha256(data: string): Promise<Uint8Array> {
45+
const encoder: TextEncoder = new TextEncoder();
46+
const dataBuffer: Uint8Array = encoder.encode(data);
47+
const hashBuffer: ArrayBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);
6148

62-
// Using native web crypto (available in modern Node and Browsers)
63-
const hashBuffer: ArrayBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);
64-
return new Uint8Array(hashBuffer);
65-
}
49+
return new Uint8Array(hashBuffer);
50+
}
6651

67-
/**
68-
* Verifies the JWT using the provided JWK and claims.
69-
*/
70-
// eslint-disable-next-line class-methods-use-this
71-
public async verifyJwt(
72-
idToken: string,
73-
jwk: JWKInterface,
74-
algorithms: string[],
75-
clientId: string,
76-
issuer: string,
77-
subject: string,
78-
clockTolerance?: number,
79-
validateJwtIssuer: boolean = true,
80-
): Promise<boolean> {
81-
const key: jose.KeyLike | Uint8Array = await jose.importJWK(jwk as jose.JWK);
52+
// eslint-disable-next-line class-methods-use-this
53+
public async verifyJwt(
54+
idToken: string,
55+
jwk: JWKInterface,
56+
algorithms: string[],
57+
clientId: string,
58+
issuer: string,
59+
subject: string,
60+
clockTolerance?: number,
61+
validateJwtIssuer: boolean = true,
62+
): Promise<boolean> {
63+
const key: jose.KeyLike | Uint8Array = await jose.importJWK(jwk as jose.JWK);
8264

83-
await jose.jwtVerify(idToken, key, {
84-
algorithms,
85-
audience: clientId,
86-
clockTolerance,
87-
issuer: validateJwtIssuer ? issuer : undefined,
88-
subject,
89-
});
65+
await jose.jwtVerify(idToken, key, {
66+
algorithms,
67+
audience: clientId,
68+
clockTolerance,
69+
issuer: validateJwtIssuer ? issuer : undefined,
70+
subject,
71+
});
9072

91-
return true;
92-
}
73+
return true;
74+
}
9375
}

packages/javascript/src/IsomorphicCrypto.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
import TokenConstants from './constants/TokenConstants';
20-
import { AsgardeoAuthException } from './errors/exception';
21-
import { Crypto, JWKInterface } from './models/crypto';
20+
import {AsgardeoAuthException} from './errors/exception';
21+
import {Crypto, JWKInterface} from './models/crypto';
2222

2323
export class IsomorphicCrypto<T = any> {
2424
private cryptoUtils: Crypto<T>;
@@ -73,7 +73,8 @@ export class IsomorphicCrypto<T = any> {
7373
throw new AsgardeoAuthException(
7474
'JS-CRYPTO_UTIL-GJFTIT-IV01',
7575
'kid not found.',
76-
`Failed to find the 'kid' specified in the id_token. 'kid' found in the header : ${headerJSON['kid']
76+
`Failed to find the 'kid' specified in the id_token. 'kid' found in the header : ${
77+
headerJSON['kid']
7778
}, Expected values: ${keys.map((key: JWKInterface) => key.kid).join(', ')}`,
7879
);
7980
}

0 commit comments

Comments
 (0)