Skip to content

Commit a104e19

Browse files
Merge pull request #357 from DonOmalVindula/fix/javascript-lint
Fix CI issues in javascript package
2 parents 561ba05 + 242a01d commit a104e19

121 files changed

Lines changed: 3009 additions & 2863 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/rich-goats-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@asgardeo/javascript': patch
3+
---
4+
5+
Fix CI issues in javascript package

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"tar": "7.5.7",
6060
"seroval": "1.4.1",
6161
"qs": "6.14.1",
62-
"@vitejs/plugin-vue>vite": "7.1.12"
62+
"@vitejs/plugin-vue>vite": "7.1.12",
63+
"prettier": "2.6.2"
6364
}
6465
},
6566
"publishConfig": {

packages/javascript/src/AsgardeoJavaScriptClient.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
* under the License.
1717
*/
1818

19-
import {AllOrganizationsApiResponse} from './models/organization';
2019
import {AsgardeoClient} from './models/client';
2120
import {Config, SignInOptions, SignOutOptions, SignUpOptions} from './models/config';
22-
import {Storage} from './models/store';
2321
import {EmbeddedFlowExecuteRequestPayload, EmbeddedFlowExecuteResponse} from './models/embedded-flow';
2422
import {EmbeddedSignInFlowHandleRequestPayload} from './models/embedded-signin-flow';
23+
import {AllOrganizationsApiResponse, Organization} from './models/organization';
24+
import {Storage} from './models/store';
2525
import {TokenExchangeRequestConfig, TokenResponse} from './models/token';
26-
import {Organization} from './models/organization';
2726
import {User, UserProfile} from './models/user';
2827

2928
/**
@@ -90,7 +89,7 @@ abstract class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T>
9089

9190
abstract setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void>;
9291

93-
abstract decodeJwtToken<T = Record<string, unknown>>(token: string): Promise<T>;
92+
abstract decodeJwtToken<R = Record<string, unknown>>(token: string): Promise<R>;
9493
}
9594

9695
export default AsgardeoJavaScriptClient;

packages/javascript/src/IsomorphicCrypto.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
* under the License.
1717
*/
1818

19+
import TokenConstants from './constants/TokenConstants';
1920
import {AsgardeoAuthException} from './errors/exception';
2021
import {Crypto, JWKInterface} from './models/crypto';
21-
import {IdToken} from './models/token';
22-
import TokenConstants from './constants/TokenConstants';
2322

2423
export class IsomorphicCrypto<T = any> {
25-
private _cryptoUtils: Crypto<T>;
24+
private cryptoUtils: Crypto<T>;
2625

2726
public constructor(cryptoUtils: Crypto<T>) {
28-
this._cryptoUtils = cryptoUtils;
27+
this.cryptoUtils = cryptoUtils;
2928
}
3029

3130
/**
@@ -34,7 +33,7 @@ export class IsomorphicCrypto<T = any> {
3433
* @returns code verifier.
3534
*/
3635
public getCodeVerifier(): string {
37-
return this._cryptoUtils.base64URLEncode(this._cryptoUtils.generateRandomBytes(32));
36+
return this.cryptoUtils.base64URLEncode(this.cryptoUtils.generateRandomBytes(32));
3837
}
3938

4039
/**
@@ -45,7 +44,7 @@ export class IsomorphicCrypto<T = any> {
4544
* @returns - code challenge.
4645
*/
4746
public getCodeChallenge(verifier: string): string {
48-
return this._cryptoUtils.base64URLEncode(this._cryptoUtils.hashSha256(verifier));
47+
return this.cryptoUtils.base64URLEncode(this.cryptoUtils.hashSha256(verifier));
4948
}
5049

5150
/**
@@ -60,21 +59,22 @@ export class IsomorphicCrypto<T = any> {
6059
*/
6160
/* eslint-disable @typescript-eslint/no-explicit-any */
6261
public getJWKForTheIdToken(jwtHeader: string, keys: JWKInterface[]): JWKInterface {
63-
const headerJSON: Record<string, string> = JSON.parse(this._cryptoUtils.base64URLDecode(jwtHeader));
62+
const headerJSON: Record<string, string> = JSON.parse(this.cryptoUtils.base64URLDecode(jwtHeader));
63+
64+
const matchingKey: JWKInterface | undefined = keys.find(
65+
(key: JWKInterface): boolean => headerJSON['kid'] === key.kid,
66+
);
6467

65-
for (const key of keys) {
66-
if (headerJSON['kid'] === key.kid) {
67-
return key;
68-
}
68+
if (matchingKey) {
69+
return matchingKey;
6970
}
7071

7172
throw new AsgardeoAuthException(
7273
'JS-CRYPTO_UTIL-GJFTIT-IV01',
7374
'kid not found.',
74-
"Failed to find the 'kid' specified in the id_token. 'kid' found in the header : " +
75-
headerJSON['kid'] +
76-
', Expected values: ' +
77-
keys.map((key: JWKInterface) => key.kid).join(', '),
75+
`Failed to find the 'kid' specified in the id_token. 'kid' found in the header : ${
76+
headerJSON['kid']
77+
}, Expected values: ${keys.map((key: JWKInterface) => key.kid).join(', ')}`,
7878
);
7979
}
8080

@@ -101,7 +101,7 @@ export class IsomorphicCrypto<T = any> {
101101
clockTolerance: number | undefined,
102102
validateJwtIssuer: boolean | undefined,
103103
): Promise<boolean> {
104-
return this._cryptoUtils
104+
return this.cryptoUtils
105105
.verifyJwt(
106106
idToken,
107107
jwk,
@@ -125,15 +125,13 @@ export class IsomorphicCrypto<T = any> {
125125
),
126126
);
127127
})
128-
.catch((error: AsgardeoAuthException) => {
129-
return Promise.reject(error);
130-
});
128+
.catch((error: AsgardeoAuthException) => Promise.reject(error));
131129
}
132130

133-
public decodeJwtToken<T = Record<string, unknown>>(token: string): T {
131+
public decodeJwtToken<R = Record<string, unknown>>(token: string): R {
134132
try {
135-
const utf8String: string = this._cryptoUtils.base64URLDecode(token?.split('.')[1]);
136-
const payload: T = JSON.parse(utf8String);
133+
const utf8String: string = this.cryptoUtils.base64URLDecode(token?.split('.')[1]);
134+
const payload: R = JSON.parse(utf8String);
137135

138136
return payload;
139137
} catch (error: any) {

0 commit comments

Comments
 (0)