Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add parameter guards for all methods #84

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
ctran88 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading