UNPKG

@sudowealth/schwab-api

Version:

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

95 lines (94 loc) 3.3 kB
import { type SchwabApiClient } from '../create-api-client'; /** * Mapping of account identifiers to display-friendly names */ export type AccountDisplayMap = Record<string, string>; /** * Configuration options for the account scrubber */ export interface AccountScrubberOptions { /** * Pre-built display map to use instead of fetching from API */ displayMap?: AccountDisplayMap; /** * Additional field names to scrub (beyond the defaults) */ scrubFields?: string[]; /** * Text to replace scrubbed values with * @default "Account Display" */ replaceWith?: string; } /** * Type for unknown data after scrubbing * Removes accountNumber and hashValue fields, adds accountDisplay */ type UnknownScrubbed<T> = T extends Array<infer U> ? UnknownScrubbed<U>[] : T extends object ? { [K in keyof T as K extends 'accountNumber' | 'hashValue' ? never : K]: UnknownScrubbed<T[K]>; } & { accountDisplay?: string; } : T; /** * Build a mapping of account identifiers to human-friendly display strings. * The mapping includes both raw account numbers and hashed account numbers. * * @param client - The Schwab API client instance * @returns Promise resolving to the account display map * * @example * ```typescript * const displayMap = await buildAccountDisplayMap(client); * // Returns: { '12345': 'My Trading Account XXXX5', 'hash123': 'My Trading Account XXXX5' } * ``` */ export declare function buildAccountDisplayMap(client: SchwabApiClient): Promise<AccountDisplayMap>; /** * Recursively scrub account identifiers from the provided data object. * Any property named "accountNumber" or "hashValue" will be removed and * replaced with an "accountDisplay" property using the provided display map. * * @param data - The data to scrub * @param displayMap - Mapping of account identifiers to display names * @param options - Additional scrubbing options * @returns The scrubbed data with account identifiers replaced * * @example * ```typescript * const data = { accountNumber: '12345', balance: 1000 }; * const scrubbed = scrubAccountIdentifiers(data, displayMap); * // Returns: { accountDisplay: 'My Trading Account XXXX5', balance: 1000 } * ``` */ export declare function scrubAccountIdentifiers<T>(data: T, displayMap: AccountDisplayMap, options?: Pick<AccountScrubberOptions, 'scrubFields' | 'replaceWith'>): UnknownScrubbed<T>; /** * Account scrubber class for stateful scrubbing operations */ export declare class AccountScrubber { private displayMap; private scrubFields; private replaceWith; constructor(options?: AccountScrubberOptions); /** * Update the display map */ setDisplayMap(displayMap: AccountDisplayMap): void; /** * Add additional fields to scrub */ addScrubFields(...fields: string[]): void; /** * Scrub data using the instance's configuration */ scrub<T>(data: T): UnknownScrubbed<T>; /** * Build display map from API client and update instance */ buildAndSetDisplayMap(client: SchwabApiClient): Promise<AccountDisplayMap>; } /** * Create a pre-configured account scrubber instance */ export declare function createAccountScrubber(options?: AccountScrubberOptions): AccountScrubber; export {};