UNPKG

@warriorteam/redai-zalo-sdk

Version:

Comprehensive TypeScript/JavaScript SDK for Zalo APIs - Official Account, ZNS, Consultation Service, Group Messaging, and Social APIs

237 lines 4.36 kB
/** * Common types and interfaces for Zalo SDK */ /** * Standard Zalo API response wrapper */ export interface ZaloResponse<T = any> { /** * Error code (0 = success) */ error: number; /** * Response message */ message: string; /** * Response data */ data?: T; } /** * Zalo API error response */ export interface ZaloErrorResponse { /** * Error code */ error: number; /** * Error name */ error_name?: string; /** * Error reason */ error_reason?: string; /** * Error description */ error_description?: string; /** * Reference documentation link */ ref_doc?: string; } /** * Union type for Zalo API responses */ export type ZaloApiResponse<T> = ZaloResponse<T> | (ZaloErrorResponse & Partial<T>); /** * SDK Configuration */ export interface ZaloSDKConfig { /** * Application ID */ appId: string; /** * Application Secret */ appSecret: string; /** * API timeout in milliseconds (default: 30000) */ timeout?: number; /** * Enable debug logging (default: false) */ debug?: boolean; /** * Custom API base URL (optional) */ apiBaseUrl?: string; /** * Retry configuration */ retry?: { /** * Number of retry attempts (default: 3) */ attempts?: number; /** * Delay between retries in milliseconds (default: 1000) */ delay?: number; }; } /** * HTTP method types */ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; /** * Request configuration */ export interface RequestConfig { /** * HTTP method */ method: HttpMethod; /** * Request URL */ url: string; /** * Request headers */ headers?: Record<string, string>; /** * Query parameters */ params?: Record<string, any>; /** * Request body data */ data?: any; /** * Request timeout */ timeout?: number; } /** * Pagination parameters */ export interface PaginationParams { /** * Offset for pagination */ offset?: number; /** * Number of items per page */ count?: number; /** * Maximum items per page (default: 50) */ limit?: number; } /** * Paginated response */ export interface PaginatedResponse<T> { /** * Array of items */ items: T[]; /** * Total number of items */ total: number; /** * Current offset */ offset: number; /** * Number of items in current page */ count: number; /** * Whether there are more items */ hasMore: boolean; /** * Next offset for pagination */ nextOffset?: number; } /** * File upload information */ export interface FileUpload { /** * File buffer or stream */ file: Buffer | NodeJS.ReadableStream; /** * Original filename */ filename: string; /** * MIME type */ mimetype: string; /** * File size in bytes */ size?: number; } /** * Attachment information */ export interface Attachment { /** * Attachment ID from Zalo */ attachment_id: string; /** * File URL */ url: string; /** * File type */ type?: string; /** * File size in bytes */ size?: number; } /** * SDK Error class */ export declare class ZaloSDKError extends Error { readonly code: number; readonly details?: any; constructor(message: string, code?: number, details?: any); } /** * Logger interface */ export interface Logger { debug(message: string, ...args: any[]): void; info(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; error(message: string, ...args: any[]): void; } /** * Default console logger implementation */ export declare class ConsoleLogger implements Logger { private readonly enableDebug; constructor(enableDebug?: boolean); debug(message: string, ...args: any[]): void; info(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; error(message: string, ...args: any[]): void; } //# sourceMappingURL=common.d.ts.map