UNPKG

tsvesync

Version:

A TypeScript library for interacting with VeSync smart home devices

183 lines (182 loc) 5.95 kB
/** * Helper functions for VeSync API */ import { VeSync } from './vesync'; export declare function getApiBaseUrl(): string; export declare function setApiBaseUrl(url: string): void; export declare function getCurrentRegion(): string; export declare function setCurrentRegion(region: string): void; export declare const NON_EU_COUNTRY_CODES: string[]; export declare function getRegionFromCountryCode(countryCode: string): 'US' | 'EU'; export declare const API_RATE_LIMIT = 30; export declare const API_TIMEOUT = 15000; export declare const APP_VERSION = "5.7.16"; export declare const PHONE_BRAND = "SM N9005"; export declare const PHONE_OS = "Android"; export declare const CLIENT_INFO = "SM N9005"; export declare const USER_TYPE = "1"; export declare const DEFAULT_TZ = "America/New_York"; export declare const DEFAULT_REGION = "US"; export declare const MOBILE_ID = "1234567890123456"; export declare const BYPASS_HEADER_UA = "okhttp/3.12.1"; export declare const CLIENT_VERSION = "VeSync 5.7.16"; export declare const REGION_ENDPOINTS: { US: string; CA: string; MX: string; JP: string; EU: string; }; export declare const APP_VERSION_TOO_LOW_ERROR_CODE = -11012022; export declare const AUTH_ERROR_CODES: { ACCOUNT_PASSWORD_INCORRECT: number; ILLEGAL_ARGUMENT: number; CROSS_REGION: number; CROSS_REGION_ALT: number; }; /** * Get list of country codes that use the US endpoint * These are tried when we get a cross-region error */ export declare function getUSEndpointCountryCodes(): string[]; /** * Get the appropriate API endpoint based on country code */ export declare function getEndpointForCountryCode(countryCode: string): 'US' | 'EU'; /** * Detect user's home region from email domain or country hints */ export declare function detectUserRegion(email: string): string; /** * Get country code from region */ export declare function getCountryCodeFromRegion(region: string, email?: string): string; export declare function generateAppId(): string; export declare function generateTerminalId(): string; export declare function generateTraceId(): string; export interface RequestBody { acceptLanguage?: string; accountID?: string; appVersion?: string; cid?: string; configModule?: string; debugMode?: boolean; deviceRegion?: string; email?: string; method?: string; password?: string; phoneBrand?: string; phoneOS?: string; timeZone?: string; token?: string; traceId?: string; userType?: string; uuid?: string; status?: string; authorizeCode?: string; bizToken?: string; regionChange?: string; userCountryCode?: string; authProtocolType?: string; clientType?: string; sourceAppID?: string; appID?: string; clientVersion?: string; [key: string]: any; } export interface AuthResponse { code: number; msg: string; result?: { authorizeCode?: string; bizToken?: string; userCountryCode?: string; [key: string]: any; }; } export interface LoginResponse { code: number; msg: string; result?: { token?: string; accountID?: string; countryCode?: string; [key: string]: any; }; } export declare class Helpers { static shouldRedact: boolean; static generateTraceId(): string; static normalizeAirQuality(value: unknown): { level: number; label: string; }; /** * Calculate MD5 hash */ static hashPassword(text: string): string; /** * Build header for legacy api GET requests */ static reqHeaders(manager: VeSync): Record<string, string>; /** * Build header for api requests on 'bypass' endpoint */ static reqHeaderBypass(): Record<string, string>; /** * Build header for new authentication endpoints */ static reqHeaderAuth(): Record<string, string>; /** * Return universal keys for body of api requests */ static reqBodyBase(manager: VeSync): Record<string, string>; /** * Keys for authenticating api requests */ static reqBodyAuth(manager: VeSync): Record<string, any>; /** * Detail keys for api requests */ static reqBodyDetails(): Record<string, string>; /** * Build request body for initial authentication step */ static reqBodyAuthStep1(manager: VeSync, appId: string, terminalId: string, userCountryCode: string): Record<string, any>; /** * Build request body for second authentication step (login with authorize code) */ static reqBodyAuthStep2(authorizeCode: string, bizToken: string | null, _appId: string, terminalId: string, userCountryCode?: string, regionChange?: string): Record<string, any>; /** * Builder for body of api requests */ static reqBody(manager: VeSync, type: string): Record<string, any>; /** * Call VeSync API */ static callApi(endpoint: string, method: string, data: any | undefined, headers: Record<string, string> | undefined, manager: VeSync): Promise<[any, number]>; /** * Calculate hex value from energy response */ static calculateHex(hexStr: string): string; /** * Build energy dictionary from API response */ static buildEnergyDict(result: any): Record<string, any>; /** * Build configuration dictionary from API response */ static buildConfigDict(result: any): Record<string, any>; /** * Calculate MD5 hash */ static md5(text: string): string; /** * Perform new two-step authentication flow */ static authNewFlow(manager: VeSync, appId: string, region?: string, countryCodeOverride?: string): Promise<[boolean, string | null, string | null, string | null]>; /** * Perform legacy authentication (fallback) */ static authLegacyFlow(manager: VeSync): Promise<[boolean, string | null, string | null, string | null]>; }