UNPKG

@bynn-intelligence/agemin-sdk

Version:

agemin.com SDK for age verification

155 lines (154 loc) 4.6 kB
export type Theme = 'light' | 'dark' | 'auto'; export type VerificationMode = 'modal' | 'redirect'; export type SearchEngineDetectionMode = 'ua' | 'headless' | 'cookies' | 'combined' | 'strict'; export interface AgeminConfig { /** * Your unique asset ID from agemin.com/app/websites * Format: asset_5b08b274353b92f4 */ assetId: string; /** * Unique reference ID for this verification request * Should be generated server-side for security * Maximum 50 bytes */ referenceId: string; /** * Optional metadata to attach to the verification * Maximum 256 bytes (will be JSON stringified) */ metadata?: Record<string, any>; /** * Base URL for the Agemin verification service * @default 'https://verify.agemin.com' */ baseUrl?: string; /** * Custom verification URL template (for development) * Use {sessionId} as placeholder for session ID * @internal */ verificationURL?: string; /** * URL to redirect to on error */ errorUrl?: string | null; /** * URL to redirect to on success */ successUrl?: string | null; /** * URL to redirect to on cancellation */ cancelUrl?: string | null; /** * Theme for the verification interface * @default 'auto' */ theme?: Theme; /** * Locale for the verification interface * Use 'auto' to detect browser language automatically * @default 'auto' */ locale?: string; /** * Enable debug mode for verbose logging * @default false */ debug?: boolean; /** * Allow search engine crawlers to bypass age verification * Useful for SEO - allows content indexing while maintaining age-gate for users * @default false */ allowSearchEngineBypass?: boolean; /** * Search engine detection mode for bypass feature * - 'ua': User agent string detection only (fastest, default) * - 'headless': Headless browser detection (plugins, languages, WebGL) * - 'cookies': Cookie support check (crawlers typically don't support cookies) * - 'combined': Any detection method triggers bypass (most inclusive) * - 'strict': Requires multiple signals (reduces false positives) * @default 'ua' */ searchEngineDetection?: SearchEngineDetectionMode; } export interface VerifyOptions { /** * How to display the verification interface * @default 'modal' */ mode?: VerificationMode; /** * Override the theme for this verification */ theme?: Theme; /** * Override the locale for this verification */ locale?: string; /** * Custom metadata to attach to the verification */ metadata?: Record<string, any>; /** * Callback when verification process completes successfully * Note: This indicates the verification process finished, NOT that the user passed * For strong API security, check results server-side with your private key */ onSuccess?: (data: VerificationResult) => void; /** * Callback when user passes age verification (JWT present and is_of_age = true) * Only called when JWT is available and successfully decoded */ onAgePass?: (data: VerificationResult) => void; /** * Callback when user fails age verification (JWT present but is_of_age = false) * Only called when JWT is available and successfully decoded */ onAgeFail?: (data: VerificationResult) => void; /** * Callback when technical error occurs (API, network, model errors) * Recommended: Show fallback age confirmation modal */ onError?: (error: VerificationError) => void; /** * Callback when verification is cancelled by user */ onCancel?: () => void; /** * Callback when verification modal/popup is closed */ onClose?: () => void; } export interface VerificationResult { /** * Unique reference ID for this verification * Use this to fetch actual results server-side */ referenceId: string; /** * Indicates verification process completed successfully * Does NOT indicate if age requirement was met */ completed: boolean; /** * Timestamp when verification completed */ timestamp: number; } export interface VerificationError { /** * Error code */ code: string; /** * Human-readable error message */ message: string; /** * Additional error details */ details?: Record<string, any>; }