Skip to content

Commit

Permalink
lint and api-extractor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pragatimodi committed Oct 20, 2023
1 parent c5045b5 commit da7aa6e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
9 changes: 9 additions & 0 deletions etc/firebase-admin.auth.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,5 @@ export {
UserInfo,
UserMetadata,
UserRecord,
PasskeyInfo,
} from './user-record';
25 changes: 15 additions & 10 deletions src/auth/user-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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(
Expand All @@ -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;
}

};
}
}

/**
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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());
Expand Down
28 changes: 14 additions & 14 deletions test/unit/auth/user-record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ function getValidUserResponse(tenantId?: string): GetAccountInfoUserResponse {
],
passkeyInfo: [
{
name: "[email protected]",
credentialId: "credentialId1",
displayName: "passkey1",
name: '[email protected]',
credentialId: 'credentialId1',
displayName: 'passkey1',
},
{
name: "[email protected]",
credentialId: "credentialId2",
displayName: "passkey2",
name: '[email protected]',
credentialId: 'credentialId2',
displayName: 'passkey2',
}
]
};
Expand Down Expand Up @@ -199,14 +199,14 @@ function getUserJSON(tenantId?: string): object {
},
passkeyInfo: [
{
name: "[email protected]",
credentialId: "credentialId1",
displayName: "passkey1",
name: '[email protected]',
credentialId: 'credentialId1',
displayName: 'passkey1',
},
{
name: "[email protected]",
credentialId: "credentialId2",
displayName: "passkey2",
name: '[email protected]',
credentialId: 'credentialId2',
displayName: 'passkey2',
}
]
};
Expand Down Expand Up @@ -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');
});
});
Expand Down

0 comments on commit da7aa6e

Please sign in to comment.