UNPKG

novel-reader-sdk

Version:

SDK for Novel Reader API

82 lines 2.43 kB
/** * SDK Utility Functions * * Helper functions for URL building, query parameters, and response handling */ import type { DatabaseId } from './types'; /** * Build URL with path parameters */ export declare function buildUrl(baseUrl: string, path: string, params?: Record<string, string>): string; /** * Build query string from parameters */ export declare function buildQueryString(params?: Record<string, unknown>): string; /** * Combine URL with query parameters */ export declare function buildFullUrl(baseUrl: string, path: string, params?: Record<string, string>, query?: Record<string, unknown> | object): string; /** * Default fetch options for API requests */ export declare const defaultFetchOptions: RequestInit; /** * Enhanced fetch with timeout and error handling */ export declare function fetchWithTimeout(url: string, options?: RequestInit & { timeout?: number; }): Promise<Response>; /** * Parse JSON response with error handling */ export declare function parseJsonResponse<T>(response: Response): Promise<T>; /** * Validate database ID */ export declare function validateDatabaseId(id: string): asserts id is DatabaseId; /** * Validate URL format */ export declare function validateUrl(url: string): boolean; /** * Extract hostname from URL */ export declare function extractHostname(url: string): string; /** * Clean and normalize string data */ export declare function normalizeString(str: string | null | undefined): string; /** * Convert array to comma-separated string */ export declare function arrayToString(arr: string[]): string; /** * Safe number parsing */ export declare function parseNumber(value: string | number | null | undefined): number | undefined; /** * Retry configuration */ export interface RetryConfig { maxAttempts: number; baseDelay: number; maxDelay: number; backoffFactor: number; } /** * Default retry configuration */ export declare const defaultRetryConfig: RetryConfig; /** * Retry function with exponential backoff */ export declare function withRetry<T>(fn: () => Promise<T>, config?: Partial<RetryConfig>): Promise<T>; /** * Log request details for debugging */ export declare function logRequest(method: string, url: string, data?: unknown): void; /** * Log response details for debugging */ export declare function logResponse(url: string, status: number, data?: unknown): void; //# sourceMappingURL=utils.d.ts.map