Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Identity8 * File : sdk/typescript/src/types.ts9 * Module : sdk10 * Repository : https://git.spboucher.ai/maclustr-identity11 * Project Website : https://identity.spboucher.ai12 * Created : 2026-12-0113 * Last Modified : 2026-12-0114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142/**43 * Public object and parameter types of the MacLustr Identity API (v1).44 * Field names are the wire names (snake_case): objects are returned exactly as the API sends them.45 */4647export type VerificationSessionStatus =48 | "created"49 | "awaiting_consent"50 | "awaiting_document"51 | "awaiting_selfie"52 | "processing"53 | "manual_review"54 | "verified"55 | "inconclusive"56 | "rejected"57 | "expired"58 | "cancelled"59 | "revoked"60 // A status added by a later version of the service is passed through: always keep a default branch.61 | (string & {});6263export type VerificationStatus = "verified" | "manual_review" | "inconclusive" | "rejected" | "revoked" | (string & {});6465/** Session statuses after which the person may simply start a new session. */66export const RETRYABLE_SESSION_STATUSES: readonly string[] = ["inconclusive", "expired", "cancelled"];6768/**69 * Reason codes known to this SDK version. The list grows: treat an unknown code as informative only.70 * `review_not_completed`: the manual review was not handled before its deadline, the result is `inconclusive` and the71 * person may start again. `decision_overturned`: a contested decision was set aside after review.72 */73export type VerificationReasonCode =74 | "simulated"75 | "capture_quality_insufficient"76 | "document_expired"77 | "authenticity_indicators"78 | "engine_unavailable"79 | "reviewer_decision"80 | "review_not_completed"81 | "decision_overturned"82 | (string & {});8384export type VerificationMethod = "document_selfie" | "document_review" | "document_only";8586/** Built-in policies; an application may also define its own keys. */87export type VerificationPolicy = "identity_document_v1" | "identity_document_face_v1" | (string & {});8889export type AssuranceLevel =90 | "document_check"91 | "document_face_liveness_check"92 | "document_manual_review"93 | "document_face_manual_review"94 | "sandbox_simulated"95 | (string & {});9697export type Metadata = Record<string, unknown>;9899export interface VerificationSession {100 id: string;101 object: "verification_session";102 status: VerificationSessionStatus;103 livemode: boolean;104 external_user_id: string | null;105 purpose: string;106 verification_policy: VerificationPolicy;107 policy_version: string;108 locale: string;109 return_url: string | null;110 method: VerificationMethod | null;111 metadata: Metadata;112 /** Set once a decision (or a manual review) exists. */113 verification_id: string | null;114 created_at: string;115 expires_at: string;116 completed_at: string | null;117}118119/** Returned by `verificationSessions.create` only: the client secret and hosted URL are never returned again. */120export interface CreatedVerificationSession extends VerificationSession {121 /** Session-scoped secret (`vsc_…`) for the person's flow. Safe to hand to that person's browser or app. */122 client_secret: string;123 /** Hosted verification page: `{origin}/verify/{id}#{client_secret}`. */124 url: string;125}126127export interface LocalizedMessage {128 fr: string;129 en: string;130}131132export interface VerificationReason {133 code: VerificationReasonCode;134 message: LocalizedMessage;135}136137export interface Verification {138 verification_id: string;139 object: "verification";140 session_id: string;141 status: VerificationStatus;142 assurance_level: AssuranceLevel | null;143 method: VerificationMethod | null;144 verification_policy: VerificationPolicy;145 policy_version: string;146 livemode: boolean;147 /** True for sandbox results: no real document was examined. */148 simulated: boolean;149 external_user_id: string | null;150 reasons: VerificationReason[];151 /** Per-dimension outcome. Scores are never kept once a decision is made: only `status` (and optional `notes`). */152 dimensions: Record<string, VerificationDimension>;153 decision_engine: string | null;154 created_at: string;155 verified_at: string | null;156 expires_at: string | null;157 revoked_at: string | null;158 personal_data_deleted_at: string | null;159}160161export interface VerificationDimension {162 status: string;163 notes?: unknown;164 /** Present only on results produced before scores were dropped from final decisions; never rely on it. */165 score?: number;166 [key: string]: unknown;167}168169export interface VerificationStatusSummary {170 verification_id: string;171 status: VerificationStatus;172 /** `true` only when status is `verified` and the verification has not expired. */173 valid: boolean;174 assurance_level: AssuranceLevel | null;175 expires_at: string | null;176}177178export interface PersonalDataDeletion {179 verification_id: string;180 deleted: true;181 /** Counters reported by the service (for example `artifacts_destroyed`). */182 [counter: string]: unknown;183}184185export type WebhookEventType =186 | "verification.created"187 | "verification.processing"188 | "verification.completed"189 | "verification.verified"190 | "verification.inconclusive"191 | "verification.manual_review"192 | "verification.rejected"193 | "verification.expired"194 | "verification.cancelled"195 | "verification.revoked";196197export interface WebhookEndpoint {198 id: string;199 object: "webhook_endpoint";200 url: string;201 events: Array<WebhookEventType | "*">;202 status: string;203 livemode: boolean;204 description: string;205 created_at: string;206}207208/** Returned by `webhooks.create` only: the signing secret (`whsec_…`) is shown once. */209export interface CreatedWebhookEndpoint extends WebhookEndpoint {210 secret: string;211}212213export interface DeletedWebhookEndpoint {214 id: string;215 deleted: true;216}217218export interface RotatedWebhookSecret {219 id: string;220 /** New signing secret. The previous one keeps signing in parallel for 24 hours. */221 secret: string;222}223224export interface List<T> {225 object: "list";226 data: T[];227 has_more: boolean;228}229230/* ----------------------------------------------------------------- parameters */231232export interface VerificationSessionCreateParams {233 /** Why this verification is requested (shown to the person). Required, 120 characters at most. */234 purpose: string;235 /** Your own identifier for the user. Never an e-mail or a name: use an opaque id. */236 external_user_id?: string;237 /** Defaults to `identity_document_face_v1`. */238 verification_policy?: VerificationPolicy;239 /** Where the hosted page sends the person back. Must be allowed for the application. */240 return_url?: string;241 /** Defaults to `fr-CA`. */242 locale?: string;243 /** Free-form object, 2000 bytes at most once serialized. Never put personal data here. */244 metadata?: Metadata;245 /** Session lifetime, clamped by the service to 10..1440 minutes (default 60). */246 expires_in_minutes?: number;247}248249export interface ListParams {250 /** 1..100, default 20. */251 limit?: number;252 /** Cursor: id of the last object of the previous page. */253 starting_after?: string;254 external_user_id?: string;255}256257export interface VerificationSessionListParams extends ListParams {258 status?: VerificationSessionStatus;259}260261export interface VerificationListParams extends ListParams {262 status?: VerificationStatus;263}264265export interface VerificationRevokeParams {266 /** Stored with the revocation (200 characters at most). */267 reason?: string;268}269270export interface WebhookEndpointCreateParams {271 url: string;272 /** Defaults to `["*"]`. */273 events?: Array<WebhookEventType | "*">;274 description?: string;275}276277/* ----------------------------------------------------------------- events */278279interface EventBase<T extends WebhookEventType, O> {280 id: string;281 object: "event";282 type: T;283 api_version: string;284 /** Unix seconds. */285 created: number;286 livemode: boolean;287 data: { object: O };288}289290/** Events whose `data.object` is a verification session (no decision exists yet). */291export type SessionEvent =292 | EventBase<"verification.created", VerificationSession>293 | EventBase<"verification.processing", VerificationSession>294 | EventBase<"verification.expired", VerificationSession>295 | EventBase<"verification.cancelled", VerificationSession>;296297/** Events whose `data.object` is a verification (a decision or a manual review exists). */298export type DecisionEvent =299 | EventBase<"verification.completed", Verification>300 | EventBase<"verification.verified", Verification>301 | EventBase<"verification.inconclusive", Verification>302 | EventBase<"verification.manual_review", Verification>303 | EventBase<"verification.rejected", Verification>304 | EventBase<"verification.revoked", Verification>;305306export type WebhookEvent = SessionEvent | DecisionEvent;307308/**309 * Narrowing helper: true when `event.data.object` is a `Verification`.310 * Safe on an event type this SDK version does not know: it looks at the object, not at the type.311 */312export function isDecisionEvent(event: WebhookEvent): event is DecisionEvent {313 return (event as { data?: { object?: { object?: unknown } } })?.data?.object?.object === "verification";314}315316/** Narrowing helper: true when `event.data.object` is a `VerificationSession` (created, processing, expired, cancelled). */317export function isSessionEvent(event: WebhookEvent): event is SessionEvent {318 return (event as { data?: { object?: { object?: unknown } } })?.data?.object?.object === "verification_session";319}320321/** True when the event tells that the session ended without a decision and the person may start a new one. */322export function sessionEndedWithoutDecision(event: WebhookEvent): boolean {323 return event.type === "verification.cancelled" || event.type === "verification.expired";324}325