UNPKG

@sudowealth/schwab-api

Version:

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

61 lines (60 loc) 2.5 kB
/** * Default refresh threshold: 5 minutes (300,000 ms) * This is the default time before token expiration when a refresh should be triggered */ export declare const DEFAULT_REFRESH_THRESHOLD_MS = 300000; /** * Schwab refresh token expiration: 7 days (604,800,000 ms) * Schwab refresh tokens expire after 7 days of inactivity */ export declare const REFRESH_TOKEN_EXPIRATION_MS = 604800000; /** * Schwab refresh token warning threshold: 6 days (518,400,000 ms) * We warn about refresh token expiration when it's 6 days old (1 day before expiry) */ export declare const REFRESH_TOKEN_WARNING_THRESHOLD_MS = 518400000; /** * Sanitize authorization code for Schwab's OAuth requirements * This handles any encoding issues that might come up with special characters * and ensures base64 padding is correctly handled. * * Specifically addresses: * - Removing invalid base64 characters * - Converting from base64url to standard base64 format * - Adding proper padding to make length a multiple of 4 * - Handling URL-encoded characters * * @param code The authorization code to sanitize * @param debug Optional flag to enable debug logging * @returns The sanitized authorization code */ export declare function sanitizeAuthCode(code: string, debug?: boolean): string; /** * Unified method to check if any token is approaching expiration * Can be used for both access tokens and refresh tokens with appropriate parameters * * @param expirationTime The timestamp to check against, or undefined * @param thresholdMs Time threshold before expiration to return true * @returns True if the token is expiring within the threshold window */ export declare function tokenIsExpiringSoon(expirationTime?: number, thresholdMs?: number): boolean; /** * Safe Base64 decoding using native Node.js Buffer * - Handles standard base64 and base64url formats * - Provides consistent behavior and error handling * * @param input The Base64 or Base64URL string to decode * @returns The decoded string */ export declare function safeBase64Decode(input: string): string; /** * Safe Base64 encoding using native Node.js Buffer * - Encodes strings to base64 with consistent behavior * - Supports URL-safe base64 format (base64url) * - Enhanced error handling * * @param input The string to encode * @param urlSafe Whether to make the output URL-safe (default: true) * @returns The Base64 encoded string */ export declare function safeBase64Encode(input: string, urlSafe?: boolean): string;