@sudowealth/schwab-api
Version:
TypeScript client for Charles Schwab API with OAuth support, market data, trading functionality, and complete type safety
48 lines (47 loc) • 1.67 kB
JavaScript
import { EnhancedTokenManager } from './enhanced-token-manager.js';
/**
* Authentication strategy for the auth factory
* Only the Enhanced strategy is supported in this version
*/
export var AuthStrategy;
(function (AuthStrategy) {
/**
* Enhanced OAuth 2.0 code flow authentication
* - Built-in token persistence and refresh capabilities
* - Includes retry logic, automatic reconnection, and token validation
* - Comprehensive error handling and debugging tools
* - Reliable token management for serverless environments
*/
AuthStrategy["ENHANCED"] = "enhanced";
})(AuthStrategy || (AuthStrategy = {}));
/**
* Creates an authentication client using the EnhancedTokenManager
*
* @example
* ```typescript
* const auth = createSchwabAuth({
* oauthConfig: {
* clientId: 'your-client-id',
* clientSecret: 'your-client-secret',
* redirectUri: 'your-redirect-uri',
* // Optional storage callbacks
* save: async (tokens) => localStorage.setItem('tokens', JSON.stringify(tokens)),
* load: async () => JSON.parse(localStorage.getItem('tokens') || 'null')
* }
* });
*
* // Get authorization URL
* const { authUrl } = auth.getAuthorizationUrl();
* // Exchange code for tokens
* const tokens = await auth.exchangeCode('authorization-code');
* ```
*/
export function createSchwabAuth(config) {
// Check if oauthConfig is provided
if (!config.oauthConfig) {
throw new Error('oauthConfig is required');
}
// Create the enhanced token manager with the provided OAuth config
const enhancedManager = new EnhancedTokenManager(config.oauthConfig);
return enhancedManager;
}