Skip to content

Commit 488d915

Browse files
Fix lint issues in browser package
1 parent 30a8574 commit 488d915

14 files changed

Lines changed: 132 additions & 257 deletions

File tree

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
"seroval": "1.4.1",
7070
"qs": "6.14.1",
7171
"@vitejs/plugin-vue>vite": "7.1.12",
72-
"prettier": "2.6.2"
72+
"prettier": "2.6.2",
73+
"@typescript-eslint/eslint-plugin": "5.62.0",
74+
"@typescript-eslint/parser": "5.62.0"
7375
}
7476
},
7577
"publishConfig": {

packages/browser/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/dist
22
/build
33
/node_modules
4-
/coverage
4+
/coverage
5+
/src/__legacy__

packages/browser/esbuild.config.mjs

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,88 +16,89 @@
1616
* under the License.
1717
*/
1818

19-
import { readFileSync } from 'fs';
19+
import {readFileSync} from 'fs';
20+
import {createRequire} from 'module';
2021
import * as esbuild from 'esbuild';
21-
import { createRequire } from 'module';
2222
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';
2323

2424
const require = createRequire(import.meta.url);
2525
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
2626

2727
// Get dependencies excluding crypto-related ones that need to be bundled
28-
const externalDeps = [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
29-
.filter(dep => !['crypto-browserify', 'randombytes', 'buffer'].includes(dep));
28+
const externalDeps = [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})].filter(
29+
dep => !['crypto-browserify', 'randombytes', 'buffer'].includes(dep),
30+
);
3031

3132
// Plugin to alias crypto and buffer modules
3233
const polyfillPlugin = {
3334
name: 'polyfill-plugin',
3435
setup(build) {
3536
// Crypto polyfill
36-
build.onResolve({ filter: /^crypto$/ }, () => ({
37-
path: require.resolve('crypto-browserify')
37+
build.onResolve({filter: /^crypto$/}, () => ({
38+
path: require.resolve('crypto-browserify'),
3839
}));
3940

4041
// Buffer polyfill
41-
build.onResolve({ filter: /^buffer$/ }, () => ({
42-
path: require.resolve('buffer/')
42+
build.onResolve({filter: /^buffer$/}, () => ({
43+
path: require.resolve('buffer/'),
4344
}));
44-
}
45+
},
4546
};
4647

4748
const commonOptions = {
48-
bundle: true,
49-
entryPoints: ['src/index.ts'],
50-
external: externalDeps,
51-
platform: 'browser',
52-
target: ['es2020'],
53-
define: {
54-
global: 'globalThis', // Required by crypto-browserify
55-
'process.env.NODE_DEBUG': 'false',
56-
'process.version': '"16.0.0"',
57-
'process.browser': 'true'
58-
},
5949
banner: {
6050
js: `
6151
import { Buffer } from 'buffer/';
6252
if (typeof window !== 'undefined' && !window.Buffer) {
6353
window.Buffer = Buffer;
6454
}
65-
`
55+
`,
56+
},
57+
bundle: true,
58+
define: {
59+
global: 'globalThis', // Required by crypto-browserify
60+
'process.browser': 'true',
61+
'process.env.NODE_DEBUG': 'false',
62+
'process.version': '"16.0.0"',
6663
},
64+
entryPoints: ['src/index.ts'],
65+
external: externalDeps,
6766
footer: {
6867
js: `
6968
if (typeof window !== 'undefined' && !window.Buffer) {
7069
window.Buffer = require('buffer/').Buffer;
7170
}
72-
`
71+
`,
7372
},
73+
platform: 'browser',
7474
plugins: [
7575
polyfillPlugin,
7676
inlineWorkerPlugin({
77-
format: 'iife',
78-
target: 'es2020',
79-
platform: 'browser',
8077
define: {
81-
'global': 'self',
82-
'globalThis': 'self',
78+
global: 'self',
79+
globalThis: 'self',
80+
'process.browser': 'true',
8381
'process.env.NODE_DEBUG': 'false',
8482
'process.version': '"16.0.0"',
85-
'process.browser': 'true'
86-
}
87-
})
88-
]
83+
},
84+
format: 'iife',
85+
platform: 'browser',
86+
target: 'es2020',
87+
}),
88+
],
89+
target: ['es2020'],
8990
};
9091

9192
await esbuild.build({
9293
...commonOptions,
9394
format: 'esm',
9495
outfile: 'dist/index.js',
95-
sourcemap: true
96+
sourcemap: true,
9697
});
9798

9899
await esbuild.build({
99100
...commonOptions,
100101
format: 'cjs',
101102
outfile: 'dist/cjs/index.js',
102-
sourcemap: true
103+
sourcemap: true,
103104
});

packages/browser/src/__legacy__/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ export class AsgardeoSPAClient {
8585
this._instanceID = id;
8686
}
8787

88-
public instantiateAuthHelper(authHelper?: typeof AuthenticationHelper) {
88+
public instantiateAuthHelper(authHelper?: typeof AuthenticationHelper): void {
8989
if (authHelper) {
9090
this._authHelper = authHelper;
9191
} else {
9292
this._authHelper = AuthenticationHelper;
9393
}
9494
}
9595

96-
public instantiateWorker(worker: new () => Worker) {
96+
public instantiateWorker(worker: new () => Worker): void {
9797
if (worker) {
9898
this._worker = worker;
9999
} else {

packages/browser/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
/**
2020
* Entry point for all public APIs of this SDK.
2121
*/
22+
// eslint-disable-next-line import/no-cycle
2223
export * from './__legacy__/client';
24+
// eslint-disable-next-line import/no-cycle
2325
export * from './__legacy__/models';
2426

2527
// Utils
28+
// eslint-disable-next-line import/no-cycle
2629
export * from './__legacy__/utils/spa-utils';
2730

2831
// Constants

packages/browser/src/theme/themeDetection.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ export const detectThemeMode = (mode: ThemeMode, config: BrowserThemeDetection =
5151

5252
if (mode === 'class') {
5353
if (!targetElement) {
54+
// eslint-disable-next-line no-console
5455
console.warn('ThemeDetection: targetElement is required for class-based detection, falling back to light mode');
5556
return 'light';
5657
}
5758

58-
const classList = targetElement.classList;
59+
const {classList} = targetElement;
5960

6061
// Check for explicit dark class first
6162
if (classList.contains(darkClass)) {
@@ -84,10 +85,10 @@ export const createClassObserver = (
8485
): MutationObserver => {
8586
const {darkClass = 'dark', lightClass = 'light'} = config;
8687

87-
const observer = new MutationObserver(mutations => {
88-
mutations.forEach(mutation => {
88+
const observer: MutationObserver = new MutationObserver((mutations: MutationRecord[]) => {
89+
mutations.forEach((mutation: MutationRecord) => {
8990
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
90-
const classList = targetElement.classList;
91+
const {classList} = targetElement;
9192

9293
if (classList.contains(darkClass)) {
9394
callback(true);
@@ -101,8 +102,8 @@ export const createClassObserver = (
101102
});
102103

103104
observer.observe(targetElement, {
104-
attributes: true,
105105
attributeFilter: ['class'],
106+
attributes: true,
106107
});
107108

108109
return observer;
@@ -116,9 +117,9 @@ export const createMediaQueryListener = (callback: (isDark: boolean) => void): M
116117
return null;
117118
}
118119

119-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
120+
const mediaQuery: MediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
120121

121-
const handleChange = (e: MediaQueryListEvent) => {
122+
const handleChange = (e: MediaQueryListEvent): void => {
122123
callback(e.matches);
123124
};
124125

packages/browser/src/types/worker.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@
1818

1919
// Type declarations for worker files handled by esbuild-plugin-inline-worker
2020

21-
declare module "*.worker" {
21+
declare module '*.worker' {
2222
const WorkerFactory: {
2323
new (): Worker;
2424
};
2525
export default WorkerFactory;
2626
}
2727

28-
declare module "*.worker.js" {
28+
declare module '*.worker.js' {
2929
const WorkerFactory: {
3030
new (): Worker;
3131
};
3232
export default WorkerFactory;
3333
}
3434

35-
declare module "*.worker.ts" {
35+
declare module '*.worker.ts' {
3636
const WorkerFactory: {
3737
new (): Worker;
3838
};
3939
export default WorkerFactory;
4040
}
4141

42-
declare module "*.worker.jsx" {
42+
declare module '*.worker.jsx' {
4343
const WorkerFactory: {
4444
new (): Worker;
4545
};
4646
export default WorkerFactory;
4747
}
4848

49-
declare module "*.worker.tsx" {
49+
declare module '*.worker.tsx' {
5050
const WorkerFactory: {
5151
new (): Worker;
5252
};

packages/browser/src/utils/__tests__/navigate.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {vi, describe, it, expect, beforeEach, afterEach} from 'vitest';
2424
import navigate from '../navigate';
2525

2626
describe('navigate', () => {
27-
const originalLocation = window.location;
27+
const originalLocation: Location = window.location;
2828

2929
beforeEach(() => {
3030
// @ts-ignore
@@ -37,8 +37,8 @@ describe('navigate', () => {
3737
window.location = {
3838
...originalLocation,
3939
assign: vi.fn(),
40-
origin: 'https://localhost:5173',
4140
href: 'https://localhost:5173/',
41+
origin: 'https://localhost:5173',
4242
};
4343
});
4444

@@ -58,23 +58,23 @@ describe('navigate', () => {
5858
navigate('/test-url');
5959
expect(window.dispatchEvent).toHaveBeenCalledWith(
6060
expect.objectContaining({
61-
type: 'popstate',
6261
state: null,
62+
type: 'popstate',
6363
}),
6464
);
6565
expect(window.location.assign).not.toHaveBeenCalled();
6666
});
6767

6868
it('should use window.location.assign for cross-origin URLs', () => {
69-
const crossOriginUrl = 'https://accounts.asgardeo.io/t/dxlab/accountrecoveryendpoint/register.do';
69+
const crossOriginUrl: string = 'https://accounts.asgardeo.io/t/dxlab/accountrecoveryendpoint/register.do';
7070
navigate(crossOriginUrl);
7171
expect(window.location.assign).toHaveBeenCalledWith(crossOriginUrl);
7272
expect(window.history.pushState).not.toHaveBeenCalled();
7373
expect(window.dispatchEvent).not.toHaveBeenCalled();
7474
});
7575

7676
it('should use window.location.assign for malformed URLs', () => {
77-
const malformedUrl = 'http://[::1'; // Invalid URL
77+
const malformedUrl: string = 'http://[::1'; // Invalid URL
7878
navigate(malformedUrl);
7979
expect(window.location.assign).toHaveBeenCalledWith(malformedUrl);
8080
expect(window.history.pushState).not.toHaveBeenCalled();

packages/browser/src/utils/handleWebAuthnAuthentication.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,24 @@ const handleWebAuthnAuthentication = async (challengeData: string): Promise<stri
116116
}
117117

118118
try {
119-
const decodedChallenge = JSON.parse(atob(challengeData));
119+
const decodedChallenge: any = JSON.parse(atob(challengeData));
120120
const {publicKeyCredentialRequestOptions} = decodedChallenge;
121121

122-
const currentDomain = window.location.hostname;
123-
const challengeRpId = publicKeyCredentialRequestOptions.rpId;
122+
const currentDomain: string = window.location.hostname;
123+
const challengeRpId: string = publicKeyCredentialRequestOptions.rpId;
124124

125-
let rpIdToUse = challengeRpId;
125+
let rpIdToUse: string = challengeRpId;
126126

127127
if (challengeRpId && !currentDomain.endsWith(challengeRpId) && challengeRpId !== currentDomain) {
128+
// eslint-disable-next-line no-console
128129
console.warn(`RP ID mismatch detected. Challenge RP ID: ${challengeRpId}, Current domain: ${currentDomain}`);
129130
rpIdToUse = currentDomain;
130131
}
131132

132-
const adjustedOptions = {
133+
const adjustedOptions: any = {
133134
...publicKeyCredentialRequestOptions,
134-
rpId: rpIdToUse,
135135
challenge: base64urlToArrayBuffer(publicKeyCredentialRequestOptions.challenge),
136+
rpId: rpIdToUse,
136137
...(publicKeyCredentialRequestOptions.userVerification && {
137138
userVerification: publicKeyCredentialRequestOptions.userVerification,
138139
}),
@@ -144,7 +145,7 @@ const handleWebAuthnAuthentication = async (challengeData: string): Promise<stri
144145
}),
145146
};
146147

147-
const credential = (await navigator.credentials.get({
148+
const credential: PublicKeyCredential = (await navigator.credentials.get({
148149
publicKey: adjustedOptions,
149150
})) as PublicKeyCredential;
150151

@@ -157,10 +158,9 @@ const handleWebAuthnAuthentication = async (challengeData: string): Promise<stri
157158
);
158159
}
159160

160-
const authData = credential.response as AuthenticatorAssertionResponse;
161+
const authData: AuthenticatorAssertionResponse = credential.response as AuthenticatorAssertionResponse;
161162

162-
const tokenResponse = {
163-
requestId: decodedChallenge.requestId,
163+
const tokenResponse: {credential: any; requestId: string} = {
164164
credential: {
165165
id: credential.id,
166166
rawId: arrayBufferToBase64url(credential.rawId),
@@ -174,10 +174,12 @@ const handleWebAuthnAuthentication = async (challengeData: string): Promise<stri
174174
},
175175
type: credential.type,
176176
},
177+
requestId: decodedChallenge.requestId,
177178
};
178179

179180
return JSON.stringify(tokenResponse);
180181
} catch (error) {
182+
// eslint-disable-next-line no-console
181183
console.error('WebAuthn authentication failed:', error);
182184

183185
if (error instanceof AsgardeoRuntimeError) {

0 commit comments

Comments
 (0)