Skip to content

Commit

Permalink
Add deleteUser method (#44)
Browse files Browse the repository at this point in the history
* Add deleteUser method

* wip
  • Loading branch information
chrisfisher authored Nov 17, 2024
1 parent b0027cb commit 0b245d8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@authsignal/node",
"version": "1.2.0",
"version": "1.2.1",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
97 changes: 52 additions & 45 deletions src/authsignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ChallengeRequest,
ChallengeResponse,
DeleteAuthenticatorRequest,
DeleteAuthenticatorResponse,
EnrollVerifiedAuthenticatorRequest,
EnrollVerifiedAuthenticatorResponse,
TrackRequest,
Expand Down Expand Up @@ -58,6 +57,16 @@ export class Authsignal {
return response.data;
}

public async deleteUser(request: UserRequest): Promise<void> {
const {userId} = request;

const url = `${this.apiBaseUrl}/users/${userId}`;

const config = this.getBasicAuthConfig();

await axios.delete(url, config);
}

public async getAuthenticators(request: UserRequest): Promise<UserAuthenticator[]> {
const {userId} = request;

Expand All @@ -70,26 +79,30 @@ export class Authsignal {
return response.data;
}

public async getChallenge(request: ChallengeRequest): Promise<ChallengeResponse> {
const {userId, action, verificationMethod} = request;

const url = new URL(`${this.apiBaseUrl}/users/${userId}/challenge`);

if (action) {
url.searchParams.set("action", action);
}
public async enrollVerifiedAuthenticator(
request: EnrollVerifiedAuthenticatorRequest
): Promise<EnrollVerifiedAuthenticatorResponse> {
const {userId, ...data} = request;

if (verificationMethod) {
url.searchParams.set("verificationMethod", verificationMethod);
}
const url = `${this.apiBaseUrl}/users/${userId}/authenticators`;

const config = this.getBasicAuthConfig();

const response = await axios.get<ChallengeResponse>(url.toString(), config);
const response = await axios.post<EnrollVerifiedAuthenticatorResponse>(url, data, config);

return response.data;
}

public async deleteAuthenticator(request: DeleteAuthenticatorRequest): Promise<void> {
const {userId, userAuthenticatorId} = request;

const url = `${this.apiBaseUrl}/users/${userId}/authenticators/${userAuthenticatorId}`;

const config = this.getBasicAuthConfig();

await axios.delete(url, config);
}

public async track(request: TrackRequest): Promise<TrackResponse> {
const {userId, action, redirectUrl = this.redirectUrl, ...rest} = request;

Expand All @@ -104,6 +117,18 @@ export class Authsignal {
return response.data;
}

public async validateChallenge(request: ValidateChallengeRequest): Promise<ValidateChallengeResponse> {
const url = `${this.apiBaseUrl}/validate`;

const config = this.getBasicAuthConfig();

const response = await axios.post<ValidateChallengeRawResponse>(url, request, config);

const {actionCode: action, ...rest} = response.data;

return {action, ...rest};
}

public async getAction(request: ActionRequest): Promise<ActionResponse | undefined> {
const {userId, action, idempotencyKey} = request;

Expand All @@ -124,52 +149,34 @@ export class Authsignal {
}
}

public async enrollVerifiedAuthenticator(
request: EnrollVerifiedAuthenticatorRequest
): Promise<EnrollVerifiedAuthenticatorResponse> {
const {userId, ...data} = request;

const url = `${this.apiBaseUrl}/users/${userId}/authenticators`;

const config = this.getBasicAuthConfig();

const response = await axios.post<EnrollVerifiedAuthenticatorResponse>(url, data, config);

return response.data;
}

public async deleteAuthenticator(request: DeleteAuthenticatorRequest): Promise<DeleteAuthenticatorResponse> {
const {userId, userAuthenticatorId} = request;
public async updateActionState(request: UpdateActionStateRequest): Promise<ActionResponse> {
const {userId, action, idempotencyKey, state} = request;

const url = `${this.apiBaseUrl}/users/${userId}/authenticators/${userAuthenticatorId}`;
const url = `${this.apiBaseUrl}/users/${userId}/actions/${action}/${idempotencyKey}`;

const config = this.getBasicAuthConfig();

const response = await axios.delete<DeleteAuthenticatorResponse>(url, config);
const response = await axios.patch<ActionResponse>(url, {state}, config);

return response.data;
}

public async validateChallenge(request: ValidateChallengeRequest): Promise<ValidateChallengeResponse> {
const url = `${this.apiBaseUrl}/validate`;

const config = this.getBasicAuthConfig();

const response = await axios.post<ValidateChallengeRawResponse>(url, request, config);

const {actionCode: action, ...rest} = response.data;
public async getChallenge(request: ChallengeRequest): Promise<ChallengeResponse> {
const {userId, action, verificationMethod} = request;

return {action, ...rest};
}
const url = new URL(`${this.apiBaseUrl}/users/${userId}/challenge`);

public async updateActionState(request: UpdateActionStateRequest): Promise<ActionResponse> {
const {userId, action, idempotencyKey, state} = request;
if (action) {
url.searchParams.set("action", action);
}

const url = `${this.apiBaseUrl}/users/${userId}/actions/${action}/${idempotencyKey}`;
if (verificationMethod) {
url.searchParams.set("verificationMethod", verificationMethod);
}

const config = this.getBasicAuthConfig();

const response = await axios.patch<ActionResponse>(url, {state}, config);
const response = await axios.get<ChallengeResponse>(url.toString(), config);

return response.data;
}
Expand Down
4 changes: 0 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ export interface DeleteAuthenticatorRequest {
userAuthenticatorId: string;
}

export interface DeleteAuthenticatorResponse {
success: boolean;
}

export enum UserActionState {
ALLOW = "ALLOW",
BLOCK = "BLOCK",
Expand Down

0 comments on commit 0b245d8

Please sign in to comment.