UNPKG

@softlock/sdk

Version:

Official Softlock SDK for access key validation and management

127 lines 3.69 kB
export interface SoftlockConfig { /** Your Softlock project/tenant ID */ tenantId: string; /** Base URL for your Softlock instance (defaults to official hosted service) */ baseUrl?: string; /** API key for server-side validation (optional for client-side) */ apiKey?: string; /** Cache TTL in milliseconds (default: 5 minutes) */ cacheTtl?: number; /** Enable debug logging */ debug?: boolean; } export interface AccessKey { id: string; key_value: string; status: 'active' | 'revoked' | 'expired'; discord_user_id?: string; discord_tag?: string; created_at: string; expires_at?: string; used_at?: string; } export interface ValidationResult { valid: boolean; key?: AccessKey; error?: string; cached?: boolean; } export interface User { discordId?: string; discordTag?: string; userId?: string; } export interface UseAccessKeyOptions { /** Auto-validate on mount */ autoValidate?: boolean; /** Refetch interval in milliseconds */ refetchInterval?: number; /** Disable caching for this hook */ disableCache?: boolean; } export interface UseAccessKeyResult { /** Validation result */ result: ValidationResult | null; /** Loading state */ loading: boolean; /** Error state */ error: string | null; /** Manually validate a key */ validate: (key: string) => Promise<ValidationResult>; /** Clear current validation */ clear: () => void; /** Retry last validation */ retry: () => void; } export interface UseUserAccessOptions { /** Auto-refresh access data */ autoRefresh?: boolean; /** Refresh interval in milliseconds */ refreshInterval?: number; } export interface UseUserAccessResult { /** User data */ user: User | null; /** Loading state */ loading: boolean; /** Error state */ error: string | null; /** Manually refresh access */ refreshAccess: () => Promise<void>; } export interface UseAccessGuardOptions { /** Fallback component for invalid access */ fallback?: React.ReactNode; /** Auto-validate on mount */ autoValidate?: boolean; } export interface UseAccessGuardResult { /** Whether access is granted */ hasAccess: boolean; /** Loading state */ loading: boolean; /** Error state */ error: string | null; /** Validation result */ result: ValidationResult | null; } export interface SoftlockMiddlewareOptions { /** Custom error handler */ onError?: (error: string, req: any, res: any) => void; /** Custom unauthorized handler */ onUnauthorized?: (req: any, res: any) => void; /** Extract key from custom location */ extractKey?: (req: any) => string | null; } export interface CacheEntry { result: ValidationResult; timestamp: number; ttl: number; } export interface ApiResponse<T = any> { success: boolean; data?: T; error?: string; } export interface ValidationApiResponse extends ApiResponse { data?: { valid: boolean; key?: AccessKey; user?: User; }; } export declare class SoftlockError extends Error { code?: string | undefined; statusCode?: number | undefined; constructor(message: string, code?: string | undefined, statusCode?: number | undefined); } export declare class ValidationError extends SoftlockError { constructor(message: string, code?: string); } export declare class NetworkError extends SoftlockError { constructor(message: string, statusCode?: number); } export declare class ConfigurationError extends SoftlockError { constructor(message: string); } //# sourceMappingURL=types.d.ts.map