From da7aa6e965b70476f6084e343c041fbd692e9d9d Mon Sep 17 00:00:00 2001 From: Pragati Date: Wed, 18 Oct 2023 15:49:51 -0700 Subject: [PATCH] lint and api-extractor fixes --- etc/firebase-admin.auth.api.md | 9 +++++++++ src/auth/index.ts | 1 + src/auth/user-record.ts | 25 +++++++++++++++---------- test/unit/auth/user-record.spec.ts | 28 ++++++++++++++-------------- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/etc/firebase-admin.auth.api.md b/etc/firebase-admin.auth.api.md index 42e217ba60..7969c494e0 100644 --- a/etc/firebase-admin.auth.api.md +++ b/etc/firebase-admin.auth.api.md @@ -365,6 +365,14 @@ export interface PasskeyConfigRequest { expectedOrigins?: string[]; } +// @public +export class PasskeyInfo { + readonly credentialId: string; + readonly displayName?: string; + readonly name: string; + toJSON(): object; +} + // @public export interface PasswordPolicyConfig { constraints?: CustomStrengthOptionsConfig; @@ -664,6 +672,7 @@ export class UserRecord { readonly emailVerified: boolean; readonly metadata: UserMetadata; readonly multiFactor?: MultiFactorSettings; + readonly passkeyInfo?: PasskeyInfo[]; readonly passwordHash?: string; readonly passwordSalt?: string; readonly phoneNumber?: string; diff --git a/src/auth/index.ts b/src/auth/index.ts index b3f5f954c7..e2819ca89f 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -172,4 +172,5 @@ export { UserInfo, UserMetadata, UserRecord, + PasskeyInfo, } from './user-record'; diff --git a/src/auth/user-record.ts b/src/auth/user-record.ts index 8b6aed3061..9d2a6501c4 100644 --- a/src/auth/user-record.ts +++ b/src/auth/user-record.ts @@ -372,7 +372,7 @@ export class PasskeyInfo { /** * The name of the user. */ - public readonly name?: string; + public readonly name: string; /** * Identifier for the registered credential. */ @@ -382,6 +382,13 @@ export class PasskeyInfo { */ public readonly displayName?: string; + /** + * Initializes the PasskeyInfo object using the server side response. + * + * @param response - The server side response. + * @constructor + * @internal + */ constructor(response: PasskeyInfoResponse) { if (!isNonNullObject(response)) { throw new FirebaseAuthError( @@ -399,14 +406,12 @@ export class PasskeyInfo { * @returns A JSON-serializable representation of this passkey info object. */ public toJSON(): object { - const json: any = { + return { name: this.name, credentialId: this.credentialId, displayName: this.displayName, - } - return json; - } - + }; + } } /** @@ -694,12 +699,12 @@ export class UserRecord { if (multiFactor.enrolledFactors.length > 0) { utils.addReadonlyGetter(this, 'multiFactor', multiFactor); } - if(response.passkeyInfo) { - let passkeys: PasskeyInfo[] = []; + if (response.passkeyInfo) { + const passkeys: PasskeyInfo[] = []; response.passkeyInfo.forEach((passkey) => { passkeys.push(new PasskeyInfo(passkey)); }); - if(passkeys.length > 0) { + if (passkeys.length > 0) { utils.addReadonlyGetter(this, 'passkeyInfo', passkeys); } } @@ -730,7 +735,7 @@ export class UserRecord { if (this.multiFactor) { json.multiFactor = this.multiFactor.toJSON(); } - if(this.passkeyInfo) { + if (this.passkeyInfo) { json.passkeyInfo = []; this.passkeyInfo.forEach((passkey) => { json.passkeyInfo.push(passkey.toJSON()); diff --git a/test/unit/auth/user-record.spec.ts b/test/unit/auth/user-record.spec.ts index d635617294..346dcd0729 100644 --- a/test/unit/auth/user-record.spec.ts +++ b/test/unit/auth/user-record.spec.ts @@ -102,14 +102,14 @@ function getValidUserResponse(tenantId?: string): GetAccountInfoUserResponse { ], passkeyInfo: [ { - name: "name1@google.com", - credentialId: "credentialId1", - displayName: "passkey1", + name: 'name1@google.com', + credentialId: 'credentialId1', + displayName: 'passkey1', }, { - name: "name2@google.com", - credentialId: "credentialId2", - displayName: "passkey2", + name: 'name2@google.com', + credentialId: 'credentialId2', + displayName: 'passkey2', } ] }; @@ -199,14 +199,14 @@ function getUserJSON(tenantId?: string): object { }, passkeyInfo: [ { - name: "name1@google.com", - credentialId: "credentialId1", - displayName: "passkey1", + name: 'name1@google.com', + credentialId: 'credentialId1', + displayName: 'passkey1', }, { - name: "name2@google.com", - credentialId: "credentialId2", - displayName: "passkey2", + name: 'name2@google.com', + credentialId: 'credentialId2', + displayName: 'passkey2', } ] }; @@ -699,10 +699,10 @@ describe('PasskeyInfo', () => { it('should create a PasskeyInfo object with valid data', () => { expect(passkeyInfo).to.be.an.instanceOf(PasskeyInfo); }); - + it('should throw when missing required fields', () => { expect(() => { - return new PasskeyInfo({}); + return new PasskeyInfo(null as any); }).to.throw('INTERNAL ASSERT FAILED: Invalid passkey info response'); }); });