Skip to content

Commit 3db4af1

Browse files
committed
Fix formatting issues in code
1 parent 69ac2d8 commit 3db4af1

23 files changed

+1269
-878
lines changed

example/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { EmulatorEnv } from '../src';
2-
import { Auth, emulatorHost, WorkersKVStoreSingle } from '../src';
1+
import type { EmulatorEnv } from '../src'
2+
import { Auth, emulatorHost, WorkersKVStoreSingle } from '../src'
33

44
interface Bindings extends EmulatorEnv {
55
EMAIL_ADDRESS: string;
@@ -10,13 +10,13 @@ interface Bindings extends EmulatorEnv {
1010
PUBLIC_JWK_CACHE_KEY: string;
1111
}
1212

13-
const signInPath = '/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=test1234';
13+
const signInPath = '/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=test1234'
1414

1515
export async function handleRequest(req: Request, env: Bindings) {
16-
const url = new URL(req.url);
17-
const firebaseEmuHost = emulatorHost(env);
16+
const url = new URL(req.url)
17+
const firebaseEmuHost = emulatorHost(env)
1818
if (url.pathname === '/get-jwt' && !!firebaseEmuHost) {
19-
const firebaseEmulatorSignInUrl = 'http://' + firebaseEmuHost + signInPath;
19+
const firebaseEmulatorSignInUrl = 'http://' + firebaseEmuHost + signInPath
2020
const resp = await fetch(firebaseEmulatorSignInUrl, {
2121
method: 'POST',
2222
body: JSON.stringify({
@@ -27,28 +27,28 @@ export async function handleRequest(req: Request, env: Bindings) {
2727
headers: {
2828
'Content-Type': 'application/json',
2929
},
30-
});
31-
return resp;
30+
})
31+
return resp
3232
}
3333

34-
const authorization = req.headers.get('Authorization');
34+
const authorization = req.headers.get('Authorization')
3535
if (authorization === null) {
3636
return new Response(null, {
3737
status: 400,
38-
});
38+
})
3939
}
40-
const jwt = authorization.replace(/Bearer\s+/i, '');
40+
const jwt = authorization.replace(/Bearer\s+/i, '')
4141
const auth = Auth.getOrInitialize(
4242
env.PROJECT_ID,
4343
WorkersKVStoreSingle.getOrInitialize(env.PUBLIC_JWK_CACHE_KEY, env.PUBLIC_JWK_CACHE_KV)
44-
);
45-
const firebaseToken = await auth.verifyIdToken(jwt, env);
44+
)
45+
const firebaseToken = await auth.verifyIdToken(jwt, env)
4646

4747
return new Response(JSON.stringify(firebaseToken), {
4848
headers: {
4949
'Content-Type': 'application/json',
5050
},
51-
});
51+
})
5252
}
5353

54-
export default { fetch: handleRequest };
54+
export default { fetch: handleRequest }

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828
"dependencies": {},
2929
"devDependencies": {
3030
"@cloudflare/workers-types": "^4.20231025.0",
31-
"@typescript-eslint/eslint-plugin": "^5.30.5",
32-
"@typescript-eslint/parser": "^5.30.5",
33-
"eslint": "^8.19.0",
34-
"eslint-config-prettier": "^8.5.0",
35-
"eslint-define-config": "^1.5.1",
36-
"eslint-import-resolver-typescript": "^3.2.4",
31+
"@typescript-eslint/eslint-plugin": "^6.10.0",
32+
"@typescript-eslint/parser": "^6.10.0",
33+
"eslint": "^8.53.0",
34+
"eslint-config-prettier": "^9.0.0",
35+
"eslint-define-config": "^1.24.1",
36+
"eslint-import-resolver-typescript": "^3.6.1",
3737
"eslint-plugin-eslint-comments": "^3.2.0",
38-
"eslint-plugin-import": "^2.26.0",
38+
"eslint-plugin-import": "^2.29.0",
3939
"firebase-tools": "^11.2.0",
4040
"miniflare": "^3.20231025.1",
4141
"npm-run-all": "^4.1.5",
42-
"prettier": "^2.7.1",
42+
"prettier": "^3.0.3",
4343
"typescript": "^5.2.2",
4444
"vitest": "^0.34.6",
4545
"wrangler": "^3.15.0"

src/auth.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import type { EmulatorEnv } from './emulator';
2-
import { useEmulator } from './emulator';
3-
import type { KeyStorer } from './key-store';
4-
import type { FirebaseIdToken, FirebaseTokenVerifier } from './token-verifier';
5-
import { createIdTokenVerifier } from './token-verifier';
1+
import type { EmulatorEnv } from './emulator'
2+
import { useEmulator } from './emulator'
3+
import type { KeyStorer } from './key-store'
4+
import type { FirebaseIdToken, FirebaseTokenVerifier } from './token-verifier'
5+
import { createIdTokenVerifier } from './token-verifier'
66

77
export class BaseAuth {
88
/** @internal */
9-
protected readonly idTokenVerifier: FirebaseTokenVerifier;
9+
protected readonly idTokenVerifier: FirebaseTokenVerifier
1010

1111
constructor(projectId: string, keyStore: KeyStorer) {
12-
this.idTokenVerifier = createIdTokenVerifier(projectId, keyStore);
12+
this.idTokenVerifier = createIdTokenVerifier(projectId, keyStore)
1313
}
1414

1515
/**
@@ -25,7 +25,7 @@ export class BaseAuth {
2525
* promise.
2626
*/
2727
public verifyIdToken(idToken: string, env?: EmulatorEnv): Promise<FirebaseIdToken> {
28-
const isEmulator = useEmulator(env);
29-
return this.idTokenVerifier.verifyJWT(idToken, isEmulator);
28+
const isEmulator = useEmulator(env)
29+
return this.idTokenVerifier.verifyJWT(idToken, isEmulator)
3030
}
3131
}

src/base64.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
export const decodeBase64Url = (str: string): Uint8Array => {
2-
return decodeBase64(str.replace(/_|-/g, m => ({ _: '/', '-': '+' }[m] ?? m)));
3-
};
2+
return decodeBase64(str.replace(/_|-/g, m => ({ _: '/', '-': '+' })[m] ?? m))
3+
}
44

55
export const encodeBase64Url = (buf: ArrayBufferLike): string =>
6-
encodeBase64(buf).replace(/\/|\+/g, m => ({ '/': '_', '+': '-' }[m] ?? m));
6+
encodeBase64(buf).replace(/\/|\+/g, m => ({ '/': '_', '+': '-' })[m] ?? m)
77

88
// This approach is written in MDN.
99
// btoa does not support utf-8 characters. So we need a little bit hack.
1010
export const encodeBase64 = (buf: ArrayBufferLike): string => {
11-
const binary = String.fromCharCode(...new Uint8Array(buf));
12-
return btoa(binary);
13-
};
11+
const binary = String.fromCharCode(...new Uint8Array(buf))
12+
return btoa(binary)
13+
}
1414

1515
// atob does not support utf-8 characters. So we need a little bit hack.
1616
const decodeBase64 = (str: string): Uint8Array => {
17-
const binary = atob(str);
18-
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
19-
const half = binary.length / 2;
17+
const binary = atob(str)
18+
const bytes = new Uint8Array(new ArrayBuffer(binary.length))
19+
const half = binary.length / 2
2020
for (let i = 0, j = binary.length - 1; i <= half; i++, j--) {
21-
bytes[i] = binary.charCodeAt(i);
22-
bytes[j] = binary.charCodeAt(j);
21+
bytes[i] = binary.charCodeAt(i)
22+
bytes[j] = binary.charCodeAt(j)
2323
}
24-
return bytes;
25-
};
24+
return bytes
25+
}

src/emulator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ export interface EmulatorEnv {
33
}
44

55
export function emulatorHost(env?: EmulatorEnv): string | undefined {
6-
return env?.FIREBASE_AUTH_EMULATOR_HOST;
6+
return env?.FIREBASE_AUTH_EMULATOR_HOST
77
}
88

99
/**
1010
* When true the SDK should communicate with the Auth Emulator for all API
1111
* calls and also produce unsigned tokens.
1212
*/
1313
export const useEmulator = (env?: EmulatorEnv): boolean => {
14-
return !!emulatorHost(env);
15-
};
14+
return !!emulatorHost(env)
15+
}

src/errors.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
* @constructor
77
*/
88
export class JwtError extends Error {
9-
constructor(readonly code: JwtErrorCode, readonly message: string) {
9+
constructor(
10+
readonly code: JwtErrorCode,
11+
readonly message: string
12+
) {
1013
super(message);
11-
(this as any).__proto__ = JwtError.prototype;
14+
(this as any).__proto__ = JwtError.prototype
1215
}
1316
}
1417

@@ -29,7 +32,7 @@ export enum JwtErrorCode {
2932
* App client error codes and their default messages.
3033
*/
3134
export class AppErrorCodes {
32-
public static INVALID_CREDENTIAL = 'invalid-credential';
35+
public static INVALID_CREDENTIAL = 'invalid-credential'
3336
}
3437

3538
/**
@@ -39,31 +42,31 @@ export class AuthClientErrorCode {
3942
public static INVALID_ARGUMENT = {
4043
code: 'argument-error',
4144
message: 'Invalid argument provided.',
42-
};
45+
}
4346
public static INVALID_CREDENTIAL = {
4447
code: 'invalid-credential',
4548
message: 'Invalid credential object provided.',
46-
};
49+
}
4750
public static ID_TOKEN_EXPIRED = {
4851
code: 'id-token-expired',
4952
message: 'The provided Firebase ID token is expired.',
50-
};
53+
}
5154
public static ID_TOKEN_REVOKED = {
5255
code: 'id-token-revoked',
5356
message: 'The Firebase ID token has been revoked.',
54-
};
57+
}
5558
public static INTERNAL_ERROR = {
5659
code: 'internal-error',
5760
message: 'An internal error has occurred.',
58-
};
61+
}
5962
public static USER_NOT_FOUND = {
6063
code: 'user-not-found',
6164
message: 'There is no user record corresponding to the provided identifier.',
62-
};
65+
}
6366
public static USER_DISABLED = {
6467
code: 'user-disabled',
6568
message: 'The user record is disabled.',
66-
};
69+
}
6770
}
6871

6972
/**
@@ -121,25 +124,25 @@ export class FirebaseError extends Error implements FirebaseErrorInterface {
121124
// Set the prototype explicitly. See the following link for more details:
122125
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
123126
/* tslint:enable:max-line-length */
124-
(this as any).__proto__ = FirebaseError.prototype;
127+
(this as any).__proto__ = FirebaseError.prototype
125128
}
126129

127130
/** @returns The error code. */
128131
public get code(): string {
129-
return this.errorInfo.code;
132+
return this.errorInfo.code
130133
}
131134

132135
/** @returns The error message. */
133136
public get message(): string {
134-
return this.errorInfo.message;
137+
return this.errorInfo.message
135138
}
136139

137140
/** @returns The object representation of the error. */
138141
public toJSON(): object {
139142
return {
140143
code: this.code,
141144
message: this.message,
142-
};
145+
}
143146
}
144147
}
145148

@@ -160,7 +163,11 @@ export interface ErrorInfo {
160163
* @constructor
161164
*/
162165
export class PrefixedFirebaseError extends FirebaseError {
163-
constructor(private codePrefix: string, code: string, message: string) {
166+
constructor(
167+
private codePrefix: string,
168+
code: string,
169+
message: string
170+
) {
164171
super({
165172
code: `${codePrefix}/${code}`,
166173
message,
@@ -170,7 +177,7 @@ export class PrefixedFirebaseError extends FirebaseError {
170177
// Set the prototype explicitly. See the following link for more details:
171178
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
172179
/* tslint:enable:max-line-length */
173-
(this as any).__proto__ = PrefixedFirebaseError.prototype;
180+
(this as any).__proto__ = PrefixedFirebaseError.prototype
174181
}
175182

176183
/**
@@ -181,7 +188,7 @@ export class PrefixedFirebaseError extends FirebaseError {
181188
* @returns True if the code matches, false otherwise.
182189
*/
183190
public hasCode(code: string): boolean {
184-
return `${this.codePrefix}/${code}` === this.code;
191+
return `${this.codePrefix}/${code}` === this.code
185192
}
186193
}
187194

@@ -202,6 +209,6 @@ export class FirebaseAuthError extends PrefixedFirebaseError {
202209
// Set the prototype explicitly. See the following link for more details:
203210
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
204211
/* tslint:enable:max-line-length */
205-
(this as any).__proto__ = FirebaseAuthError.prototype;
212+
(this as any).__proto__ = FirebaseAuthError.prototype
206213
}
207214
}

src/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
import { BaseAuth } from './auth';
2-
import type { KeyStorer } from './key-store';
3-
import { WorkersKVStore } from './key-store';
1+
import { BaseAuth } from './auth'
2+
import type { KeyStorer } from './key-store'
3+
import { WorkersKVStore } from './key-store'
44

5-
export { emulatorHost, useEmulator } from './emulator';
6-
export type { KeyStorer };
7-
export type { EmulatorEnv } from './emulator';
8-
export type { FirebaseIdToken } from './token-verifier';
5+
export { emulatorHost, useEmulator } from './emulator'
6+
export type { KeyStorer }
7+
export type { EmulatorEnv } from './emulator'
8+
export type { FirebaseIdToken } from './token-verifier'
99

1010
export class Auth extends BaseAuth {
11-
private static instance?: Auth;
11+
private static instance?: Auth
1212

1313
private constructor(projectId: string, keyStore: KeyStorer) {
14-
super(projectId, keyStore);
14+
super(projectId, keyStore)
1515
}
1616

1717
static getOrInitialize(projectId: string, keyStore: KeyStorer): Auth {
1818
if (!Auth.instance) {
19-
Auth.instance = new Auth(projectId, keyStore);
19+
Auth.instance = new Auth(projectId, keyStore)
2020
}
21-
return Auth.instance;
21+
return Auth.instance
2222
}
2323
}
2424

2525
export class WorkersKVStoreSingle extends WorkersKVStore {
26-
private static instance?: WorkersKVStoreSingle;
26+
private static instance?: WorkersKVStoreSingle
2727

2828
private constructor(cacheKey: string, cfKVNamespace: KVNamespace) {
29-
super(cacheKey, cfKVNamespace);
29+
super(cacheKey, cfKVNamespace)
3030
}
3131

3232
static getOrInitialize(cacheKey: string, cfKVNamespace: KVNamespace): WorkersKVStoreSingle {
3333
if (!WorkersKVStoreSingle.instance) {
34-
WorkersKVStoreSingle.instance = new WorkersKVStoreSingle(cacheKey, cfKVNamespace);
34+
WorkersKVStoreSingle.instance = new WorkersKVStoreSingle(cacheKey, cfKVNamespace)
3535
}
36-
return WorkersKVStoreSingle.instance;
36+
return WorkersKVStoreSingle.instance
3737
}
3838
}

0 commit comments

Comments
 (0)