UNPKG

@sudowealth/schwab-api

Version:

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

84 lines (83 loc) 3.03 kB
import { z } from 'zod'; /** * SchawbDate utility type * This type can be used to represent a Schwab date in any of its forms */ type SchwabDate = Date | string | number; /** * Type of date representation to use */ export declare enum DateFormatType { /** JavaScript Date object */ DATE_OBJECT = "date_object", /** ISO 8601 string (e.g., "2023-10-15T14:30:00.000Z") */ ISO_STRING = "iso_string", /** Date string in YYYY-MM-DD format */ DATE_STRING = "date_string", /** UNIX timestamp in milliseconds */ EPOCH_MS = "epoch_ms" } /** * Configuration options for parsing dates */ interface DateParserOptions { /** Output format type */ outputFormat?: DateFormatType; /** Whether to include timezone offset in ISO strings */ includeOffset?: boolean; /** Custom format function */ formatFn?: (date: Date) => string | number; } /** * Zod transformer for date fields * Can be used in schemas to automatically transform date fields * * @example * const schema = z.object({ * timestamp: z.number().transform(dateTransformer()) * }) * * @param options - Options for date transformation * @returns A zod transformer function */ export declare function dateTransformer(options?: DateParserOptions): (value: SchwabDate | null | undefined) => string | number | Date | null; /** * Zod schema for validating and transforming Unix timestamp in milliseconds */ export declare const epochMillisSchema: z.ZodEffects<z.ZodNumber, string | number | Date | null, number>; /** * Zod schema for validating and transforming ISO 8601 date strings */ export declare const isoDateTimeSchema: z.ZodEffects<z.ZodString, string | number | Date | null, string>; /** * Zod schema for validating and transforming YYYY-MM-DD date strings */ export declare const dateStringSchema: z.ZodEffects<z.ZodString, string | number | Date | null, string>; /** * Creates a Zod schema for query parameter dates that accepts: * - UNIX epoch milliseconds (number) * - YYYY-MM-DD formatted strings * - null values * * All values are transformed to UNIX epoch milliseconds or undefined (if null/undefined) * for API compatibility. * * @returns A Zod schema for query parameter dates */ export declare function createQueryDateSchema(): z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodNull]>>, number | undefined, string | number | null | undefined>; /** * Creates a Zod schema for ISO-8601 datetime query parameters that: * - Validates ISO-8601 format with timezone offset * - Sets default to current time or specified days offset * - Handles transformations if needed * * @param options Configuration options * @param options.daysOffset Number of days to offset from current date (negative for past) * @param options.description Field description * @returns A Zod schema for ISO-8601 datetime fields */ export declare function createISODateTimeSchema(options: { daysOffset?: number; description?: string; }): z.ZodDefault<z.ZodString>; export {};