UNPKG

@sudowealth/schwab-api

Version:

TypeScript client for Charles Schwab API with OAuth support, market data, trading functionality, and complete type safety

137 lines (136 loc) 3.77 kB
import { type ITokenLifecycleManager } from './token-lifecycle-manager.js'; import { type TokenData } from './types.js'; /** * Options for the auth diagnostics function */ export interface AuthDiagnosticsOptions { /** * Force refresh the tokens before returning the diagnostics * @default false */ forceRefresh?: boolean; /** * Return the full tokens (only for diagnostic purposes, handle with care) * @default false */ includeTokens?: boolean; /** * Include token segments (first 8 chars) for debugging without exposing full tokens * @default true */ includeTokenSegments?: boolean; } /** * Authentication diagnostics result */ export interface AuthDiagnosticsResult { /** * Type of auth manager being used */ authManagerType: string; /** * Whether the auth manager supports token refresh */ supportsRefresh: boolean; /** * Detailed token status information */ tokenStatus: { /** * Whether an access token is present */ hasAccessToken: boolean; /** * Whether a refresh token is present */ hasRefreshToken: boolean; /** * Whether the token is expired */ isExpired: boolean; /** * Time in milliseconds until token expires * Negative value means the token is already expired */ expiresInMs?: number; /** * Time in seconds until token expires (for human readability) */ expiresInSeconds?: number; /** * Whether a refresh was successfully performed */ refreshSuccessful?: boolean; /** * New expiration time after refresh */ newExpiresAt?: number; /** * First 8 characters of the access token (for debugging) */ accessTokenSegment?: string; /** * First 8 characters of the refresh token (for debugging) */ refreshTokenSegment?: string; /** * Full token details (only returned if includeTokens is true) * WARNING: This contains sensitive information! */ tokens?: TokenData; }; /** * Detailed environment information */ environment: { /** * API environment (sandbox or production) */ apiEnvironment: string; /** * Client ID (first 8 characters) */ clientIdSegment?: string; }; /** * Authorization header test results */ authHeaderTest?: { /** * Whether the test was successful */ success: boolean; /** * Whether the format is correct (Bearer + token) */ isCorrectFormat?: boolean; /** * Format description */ format?: string; /** * Preview of the auth header (first 8 characters of token) */ preview?: string; /** * Reason for failure if unsuccessful */ reason?: string; /** * Error message if an error occurred */ error?: string; }; } /** * Diagnostic function to get detailed information about authentication state * Helps troubleshoot 401 Unauthorized errors by providing token status details * * @param tokenManager The token lifecycle manager to diagnose * @param options Options for diagnostics * @returns Detailed diagnostics information */ export declare function getAuthDiagnostics(tokenManager: ITokenLifecycleManager, environment: { apiEnvironment: string; clientId?: string; }, options?: AuthDiagnosticsOptions): Promise<AuthDiagnosticsResult>;