From 63fdfc0a1dc491f214c7059d75e60ebc8c02e44e Mon Sep 17 00:00:00 2001 From: Kio Date: Wed, 10 Jul 2024 00:36:09 -0400 Subject: [PATCH] refactor: :recycle: Move validation and "retriability" to FE --- src/main.ts | 35 ++++++++++++++--------------------- src/messages.ts | 9 ++++++++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main.ts b/src/main.ts index 38a67e0..7f65e0c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -306,28 +306,11 @@ export class AgeVerificationSystem { this.accountsOpen[ws.data.identity].stripe?.id ?? "", ); - if (data.code === "session_cancelled") { - return; - } - - if (errorSession.last_error?.code === "consent_declined") { - await this.handleConsentDeclined(ws); - } - if (errorSession.last_error?.code === "under_supported_age") { await this.handleUnsupportedAge(ws); } } - private handleConsentDeclined(ws: WebSocketType): void { - this.sendMessage(ws, { - type: MessageTypes.VerificationFailed, - data: { - reason: "noconsent", - }, - }); - } - /** * Handles user under age errors * @param ws - The WebSocket connection @@ -371,7 +354,17 @@ export class AgeVerificationSystem { session: Stripe.Identity.VerificationSession, ): Promise { const ws = this.accountsOpen[session.metadata.identity].ws; + this.sendMessage(ws, { + type: MessageTypes.VerificationComplete, + data: { + verificationId: session.id, + }, + }); await this.stripe.identity.verificationSessions.redact(session.id); + this.sendMessage(ws, { + type: MessageTypes.VerificationCompleteStep, + data: "redact", + }); const user = await this.getUserInfo( session.metadata.identity.replace("M_", ""), ); @@ -380,11 +373,11 @@ export class AgeVerificationSystem { } await this.updateUserNote(user, `ADM-ID/Verified - ${session.id}`); this.sendMessage(ws, { - type: MessageTypes.VerificationComplete, - data: { - verificationId: session.id, - }, + type: MessageTypes.VerificationCompleteStep, + data: "redact", }); + this.accountsOpen[session.metadata.identity].stripe = undefined; + ws.close(); } /** diff --git a/src/messages.ts b/src/messages.ts index 9f64696..2dd3b01 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -10,6 +10,7 @@ export enum MessageTypes { Identify = "identify", Identification = "identification", FailedIdentification = "failedIdentification", + VerificationCompleteStep = "verificationCompleteStep", } export interface MessageStructure { @@ -17,6 +18,11 @@ export interface MessageStructure { data?: unknown; } +export interface VerificationCompleteStep extends MessageStructure { + type: MessageTypes.VerificationCompleteStep; + data: "redact" | "unban"; +} + export interface FailedIdentification extends MessageStructure { type: MessageTypes.FailedIdentification; data: null; @@ -87,4 +93,5 @@ export type WebSocketMessage = | VerificationCompleteMessage | IdentifyMessage | IdentificationMessage - | FailedIdentification; + | FailedIdentification + | VerificationCompleteStep;