Skip to content

Commit

Permalink
feat: add parameter guards for all methods (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 authored Jan 15, 2025
1 parent fb6e173 commit 7f6b79e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/classes/Auth/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class Auth extends PassageBase {
* @return {Promise<string>} The transaction ID
*/
public async createRegisterTransaction(externalId: string, passkeyDisplayName: string): Promise<string> {
if (!externalId) {
throw new Error('externalId is required.');
}

if (!passkeyDisplayName) {
throw new Error('passkeyDisplayName is required.');
}

try {
const response = await this.transactionClient.createRegisterTransaction({
appId: this.config.appId,
Expand All @@ -48,6 +56,10 @@ export class Auth extends PassageBase {
* @return {Promise<string>} The transaction ID
*/
public async createAuthenticateTransaction(externalId: string): Promise<string> {
if (!externalId) {
throw new Error('externalId is required.');
}

try {
const response = await this.transactionClient.createAuthenticateTransaction({
appId: this.config.appId,
Expand All @@ -67,6 +79,10 @@ export class Auth extends PassageBase {
* @return {Promise<string>} The unique identifier of the user associated with the nonce
*/
public async verifyNonce(nonce: string): Promise<string> {
if (!nonce) {
throw new Error('nonce is required.');
}

try {
const response = await this.authClient.authenticateVerifyNonce({
appId: this.config.appId,
Expand Down
4 changes: 2 additions & 2 deletions src/classes/PassageFlex/PassageFlex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('PassageFlex', () => {
} as unknown as PassageFlexConfig;

expect(() => new PassageFlex(config)).toThrow(
'A Passage app ID is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_APP_ID}.',
'A Passage App ID is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_APP_ID}.',
);
});

Expand All @@ -35,7 +35,7 @@ describe('PassageFlex', () => {
};

expect(() => new PassageFlex(config)).toThrow(
'A Passage app ID is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_APP_ID}.',
'A Passage App ID is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_APP_ID}.',
);
});

Expand Down
2 changes: 1 addition & 1 deletion src/classes/PassageFlex/PassageFlex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class PassageFlex {
*/
public constructor(config: PassageFlexConfig) {
if (!config.appId) {
throw Error('A Passage app ID is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_APP_ID}.');
throw Error('A Passage App ID is required. Please include {appId: YOUR_APP_ID, apiKey: YOUR_APP_ID}.');
}

if (!config.apiKey) {
Expand Down
8 changes: 8 additions & 0 deletions src/classes/User/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ export class User extends PassageBase {
* @return {Promise<void>}
*/
public async revokeDevice(externalId: string, deviceId: string): Promise<void> {
if (!externalId) {
throw new Error('externalId is required.');
}

if (!deviceId) {
throw new Error('deviceId is required.');
}

try {
const user = await this.get(externalId);
await this.deviceClient.deleteUserDevices({
Expand Down

0 comments on commit 7f6b79e

Please sign in to comment.