Feature/identity provider abstraction#82
Open
dubemoyibe-star wants to merge 3 commits into
Open
Conversation
|
@dubemoyibe-star is attempting to deploy a commit to the ManuelJG's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Identity Provider Abstraction Layer (KYC/KYB)
Summary
This PR introduces a provider-agnostic Identity Verification layer that lets Thalos
integrate multiple KYC and KYB providers without changing core business logic. The
abstraction standardizes verification workflows behind a single interface, makes the
active provider configurable, and keeps all vendor-specific code isolated from the rest
of the application (including the Agreement Service).
This layer is intended to be the foundation for all future compliance services inside
Thalos and is explicitly designed to avoid vendor lock-in.
Motivation
Compliance requirements demand flexibility in how identity verification is performed:
To achieve this, all providers implement a common interface, and the core services
depend only on that interface — never on a concrete vendor implementation.
Scope of Providers
The abstraction is designed to support the following integrations (via a single enum and
the pluggable factory). Only the
mockprovider is implemented in this PR; the others arefirst-class citizens of the abstraction and can be added by implementing the interface and
registering the instance — no core code changes required.
Architecture
Key principle: the core never imports a vendor. It resolves an
IVerificationProviderfrom the factory and calls the standardized operations.Standardized Operations
Every provider implements the following lifecycle operations (
IVerificationProvider):createSession()getStatus()getResults()handleWebhook()cancelSession()validateWebhookSignature()applyConfig()getResults,cancelSession, andapplyConfigare optional so that lightweight orcapability-limited providers (and test doubles) remain valid implementations. The service
degrades gracefully when a capability is absent (e.g. falls back to stored results, or
performs local-only cancellation).
Configuration
Provider selection is configurable through environment variables / application config.
Default provider
DEFAULT_VERIFICATION_PROVIDERis also accepted as an alias. Requests may still overridethe provider per-session via the request body (
providerfield).Per-provider credentials (convention-based)
Credentials are resolved from env using the convention
<PROVIDER>_API_KEY,<PROVIDER>_API_SECRET,<PROVIDER>_BASE_URL,<PROVIDER>_WEBHOOK_SECRET. Example:See
.env.examplefor the full set of documented variables for every supported provider.API Endpoints
All routes are under the
verificationcontroller (JWT-protected unless noted):POST/verification/sessionsGET/verification/sessionsGET/verification/sessions/:idGET/verification/sessions/:id/resultsDELETE/verification/sessions/:idPOST/verification/webhooks/:providerGET/verification/providersFiles Changed
Core abstraction
src/verification/providers/verification.provider.tsIVerificationProviderinterface with the full lifecycle (addedgetResults?,cancelSession?,applyConfig?).ProviderConfigtype for credentials/timeouts.src/verification/providers/provider-factory.tsgetDefaultProviderName()readsVERIFICATION_PROVIDERwith safe fallback.resolveConfig()maps env credentials by provider prefix.hasProvider(),registerProvider(),getSupportedProviders().src/verification/providers/mock.provider.tsgetResults,cancelSession,applyConfig.configure()helper for scripted responses/failures.DTOs / types
src/verification/dto/verification.dto.tsVerificationProviderenum aligned to the required vendors(
MOCK, SUMSUB, PERSONA, VERIFF, SYNAPS, STRIPE_IDENTITY, ALLOY).VerificationStatus.CANCELLEDandcancelled_aton the session.ProviderVerificationResult,ProviderCancelResponse.Service / Controller
src/verification/verification.service.tscreateSession.getResults()— fetches + persists normalized results, falls back to stored data.cancelSession()— provider-side (best-effort) + local cancellation withterminal-state guarding.
src/verification/verification.controller.tsGET /sessions/:id/results,DELETE /sessions/:id,POST /webhooks/:provider.Config / Tests
.env.exampleVERIFICATION_PROVIDERand commented credential blocks for all six vendors.src/verification/verification.abstraction.spec.ts(new)provider error, config application, runtime registration.
Adding a New Provider
src/verification/providers/<vendor>.provider.tsimplementingIVerificationProvider.(
ProviderStatusResponse,ProviderVerificationResult).VerificationProviderFactory.registerDefaults()or dynamically viaregisterProvider())..envusing the<PROVIDER>_*convention.No changes to
VerificationService, controllers, or any consuming service are needed.Backward Compatibility
test's stub provider) remain valid without modification.
verification.integration.spec.tscontinues to pass unchanged.Validation
npx tsc --noEmit— clean.integration spec).
pre-existing Supabase result-destructuring pattern already used across the service).
Follow-ups / Notes
production, add the
cancelled_atcolumn and thecancelledvalue to theverification_sessionsstatus enum in Supabase.validateWebhookSignature;concrete providers should implement vendor-specific HMAC verification.
Closes #71