/** * @quantabit/sdk-config TypeScript 类型定义 */ export interface SDKConfig { /** API 基础路径(相对或绝对 URL) */ apiBaseUrl: string; /** 完整 API URL */ apiFullUrl: string; /** 请求超时时间(毫秒) */ timeout: number; /** 请求重试次数 */ retryCount: number; /** 重试延迟(毫秒) */ retryDelay: number; /** Access Token 存储 Key */ tokenStorageKey: string; /** Refresh Token 存储 Key */ refreshTokenStorageKey: string; /** 当前会话存储 Key */ currentSessionKey: string; /** 是否自动刷新 Token */ autoRefreshToken: boolean; /** 是否启用 WebSocket */ enableWs: boolean; /** WebSocket 基础 URL */ wsBaseUrl: string; /** 是否自动重连 WebSocket */ wsReconnect: boolean; /** WebSocket 重连间隔(毫秒) */ wsReconnectInterval: number; /** 收银台生产环境 URL */ checkoutUrl?: string; /** 收银台沙箱环境 URL */ checkoutSandboxUrl?: string; /** 商户中心 URL */ merchantUrl?: string; /** 管理后台 URL */ adminUrl?: string; /** 支付网关 URL */ payUrl?: string; /** 钱包 URL */ walletUrl?: string; /** 是否开启调试模式 */ debug: boolean; /** 日志级别 */ logLevel: 'debug' | 'info' | 'warn' | 'error'; /** 环境标识 */ environment: string; /** 当前链网络 */ chainNetwork: QBitChainNetwork | string; /** QBit RPC 端点 */ chainEndpoint: string; /** QBit WebSocket RPC 端点 */ chainWsEndpoint: string; /** 链确认级别 */ chainCommitment: ChainCommitment; /** 链交互超时(毫秒) */ chainTimeoutMs: number; /** 区块链浏览器基础 URL(顶层便捷字段,切换网络时同步) */ explorerUrl?: string; /** IPFS HTTP Gateway 前缀,例如 https://ipfs.io/ipfs */ ipfsGateway?: string; /** .qbit Name Service */ nameService?: { tld?: string; apiPrefix?: string; anchorNamespace?: string; }; /** 当前语言 */ language: string; /** 回退语言 */ fallbackLanguage: string; /** 支持语言列表 */ supportedLanguages: string[]; /** 语言存储 Key */ languageStorageKey: string; [key: string]: any; } export interface InitConfigOptions extends Partial {} export type EnvironmentName = 'development' | 'staging' | 'production' | 'icenter'; export type QBitChainNetwork = 'mainnet' | 'testnet' | 'devnet'; export type ChainCommitment = 'processed' | 'confirmed' | 'finalized'; export interface NativeTokenConfig { symbol: string; decimals: number; name: string; } /** QBit Chain 规范程序地址 */ export interface CanonicalPrograms { system: string; token: string; token2022: string; associatedToken: string; memo: string; tokenMetadata: string; mplCore: string; raydiumCpmm: string; raydiumCpSwap: string; raydiumAmmV4: string; raydiumClmm: string; squadsV4: string; orcaWhirlpool: string; openbookV2: string; mplBubblegum: string; mplCandyGuard: string; [key: string]: string; } /** QBit 代币 mint 信息 */ export interface CanonicalTokenInfo { mint: string; decimals: number; symbol: string; name: string; status?: string; } export interface CanonicalTokens { wQBT: CanonicalTokenInfo; XWIN: CanonicalTokenInfo; [key: string]: CanonicalTokenInfo; } export interface ChainNetworkConfig { name: string; rpcEndpoint: string; wsEndpoint: string; explorerUrl: string; genesisHash: string; nativeToken: NativeTokenConfig; programs: CanonicalPrograms; tokens: CanonicalTokens; } export interface ChainConfig extends ChainNetworkConfig { network: QBitChainNetwork | string; endpoint: string; wsEndpoint: string; commitment: ChainCommitment; timeoutMs: number; } export interface UseSDKConfigReturn { config: SDKConfig; initConfig: (options: InitConfigOptions) => SDKConfig; setApiBaseUrl: (url: string) => void; setWsBaseUrl: (url: string) => void; resetConfig: () => void; initWithEnvironment: (env: EnvironmentName, overrides?: InitConfigOptions) => SDKConfig; } export interface UseChainConfigReturn { chainConfig: ChainConfig; setNetwork: (network: QBitChainNetwork | string) => void; networks: Record; } export interface Logger { debug: (...args: any[]) => void; info: (...args: any[]) => void; warn: (...args: any[]) => void; error: (...args: any[]) => void; } export class BaseApiClient { constructor(modulePath?: string, config?: Record); setToken(token: string): void; setBaseUrl(url: string): void; destroy(): void; } export function createApiClient(config?: Record): BaseApiClient; /** 获取当前配置 */ export function getConfig(): SDKConfig; /** 根据服务名称获取端点 URL */ export function getEndpoint(name: string): string; /** 初始化配置 */ export function initConfig(options?: InitConfigOptions): SDKConfig; /** 设置 API 基础 URL */ export function setApiBaseUrl(url: string): void; /** 设置 QBit 链网络 */ export function setChainNetwork(network: QBitChainNetwork | string): void; /** 获取当前 QBit 链配置 */ export function getChainConfig(): ChainConfig; /** 设置 WebSocket URL */ export function setWsBaseUrl(url: string): void; /** 设置调试模式 */ export function setDebug(debug: boolean): void; /** 重置配置 */ export function resetConfig(): void; /** 订阅配置变更 */ export function subscribeConfig(listener: (config: SDKConfig) => void): () => void; /** 使用环境预设初始化 */ export function initWithEnvironment(env: EnvironmentName, overrides?: InitConfigOptions): SDKConfig; /** 动态解析 Site ID */ export function resolveSiteId(host: string, legacyAppId: string): string; /** 环境预设配置 */ export const ENVIRONMENT_PRESETS: Record>; /** QBit Chain 网络端点配置 */ export const CHAIN_NETWORKS: Record; /** QBit Chain 规范程序地址(单一来源) */ export const CANONICAL_PROGRAMS: CanonicalPrograms; /** QBit 代币 mint(非 program_id) */ export const CANONICAL_TOKENS: CanonicalTokens; /** React Hook: 获取和管理配置 */ export function useSDKConfig(): UseSDKConfigReturn; /** React Hook: 获取和管理 QBit Chain 配置 */ export function useChainConfig(): UseChainConfigReturn; /** 构建完整 API URL */ export function buildApiUrl(endpoint: string, useFullUrl?: boolean): string; /** 获取 Access Token */ export function getToken(): string | null; /** 获取 Refresh Token */ export function getRefreshToken(): string | null; /** 保存 Token */ export function saveTokens(accessToken: string, refreshToken?: string): void; /** 清除 Token */ export function clearTokens(): void; /** 检查是否已认证 */ export function isAuthenticated(): boolean; /** 日志工具 */ export const logger: Logger; // ============ Display Surface ============ export type DisplayModeValue = | 'link' | 'new_tab' | 'popup' | 'redirect' | 'modal' | 'iframe'; export declare const DisplayMode: { readonly LINK: 'link'; readonly NEW_TAB: 'new_tab'; readonly POPUP: 'popup'; readonly REDIRECT: 'redirect'; readonly MODAL: 'modal'; readonly IFRAME: 'iframe'; }; export declare const DEFAULT_PAGE_CONTEXT_QUERY_KEYS: readonly string[]; export interface PageContext { page_url: string; domain: string; path: string; title: string; referrer: string; platform: string; app_id: string; app_name: string; language: string; screen: string; user_agent: string; [key: string]: any; } export interface SurfaceParamOptions { autoPageContext?: boolean; pageContextKeys?: string[]; pageContext?: Partial; platform?: string; appId?: string; appName?: string; language?: string; [key: string]: any; } export interface OpenSurfaceOptions extends SurfaceParamOptions { url: string; mode?: DisplayModeValue; params?: Record; popupOptions?: { width?: number; height?: number }; popupName?: string; title?: string; showClose?: boolean; completeType?: string; cancelType?: string; onComplete?: (result?: any) => void; onCancel?: (payload?: any) => void; onOpen?: (target: Window | HTMLElement | null, url: string) => void; } export function getPageContext(overrides?: Partial & Record): PageContext; export function toSearchParams(params?: Record): URLSearchParams; export function mergeSurfaceParams( params?: Record, options?: SurfaceParamOptions ): Record; export function buildUrl( baseUrl: string, params?: Record, options?: SurfaceParamOptions ): string; export function normalizeDisplayMode(mode?: DisplayModeValue | string): string; export function openSurface(options: OpenSurfaceOptions): Window | HTMLElement | null; export function closeSurface(): void; export declare class DisplaySurfaceHelper { constructor(defaults?: Partial); open(options?: Partial): Window | HTMLElement | null; buildUrl(url: string, params?: Record, options?: SurfaceParamOptions): string; close(): void; } export function createDisplaySurfaceHelper( defaults?: Partial ): DisplaySurfaceHelper; export function openUtilitySurface(options: OpenSurfaceOptions): Window | HTMLElement | null; export function openFeedbackSurface(options?: Partial): Window | HTMLElement | null; export function openHelpSurface(options?: Partial): Window | HTMLElement | null; export function openHelpdeskSurface(options?: Partial): Window | HTMLElement | null; export function openAISurface(options?: Partial): Window | HTMLElement | null; export function openReportSurface(options?: Partial): Window | HTMLElement | null; export function openSubscriptionSurface(options?: Partial): Window | HTMLElement | null; export function openCheckinSurface(options?: Partial): Window | HTMLElement | null; export function openInviteSurface(options?: Partial): Window | HTMLElement | null; export function openShareSurface(options?: Partial): Window | HTMLElement | null; export function openTipSurface(options?: Partial): Window | HTMLElement | null; export function openChatSurface(options?: Partial): Window | HTMLElement | null; export function openAIAgentSurface(options?: Partial): Window | HTMLElement | null; export function openDonateSurface(options?: Partial): Window | HTMLElement | null; export function withPageContext( payload?: Record, options?: SurfaceParamOptions ): Record; /** 获取当前语言 */ export function getLanguage(): string; /** 设置全局语言 */ export function setLanguage(lang: string): boolean; /** 初始化语言 */ export function initLanguage(): string; /** 订阅语言变更 */ export function subscribeLanguage(listener: (newLang: string, oldLang: string) => void): () => void; /** React Hook: 获取和管理语言 */ export function useLanguage(): { language: string; setLanguage: (lang: string) => void; supportedLanguages: string[]; fallbackLanguage: string; }; export interface ConsentManager { init(config?: any): void; hasConsent(category: string): boolean; setConsent(consent: Record): void; getConsent(): Record; acceptAll(): void; acceptEssentialOnly(): void; hasUserDecided(): boolean; subscribe(listener: (consent: Record) => void): () => void; } export const consentManager: ConsentManager; export function useConsent(): { consent: Record; hasUserDecided: boolean; acceptAll: () => void; acceptEssentialOnly: () => void; setConsent: (consent: Record) => void; }; export interface DataSanitizer { sanitizeUrl(url: string): string; sanitizeObject(obj: Record): Record; sanitizeString(str: string): string; } export const dataSanitizer: DataSanitizer; declare const sdkConfig: { getConfig: typeof getConfig; getEndpoint: typeof getEndpoint; initConfig: typeof initConfig; setApiBaseUrl: typeof setApiBaseUrl; setWsBaseUrl: typeof setWsBaseUrl; setDebug: typeof setDebug; resetConfig: typeof resetConfig; subscribeConfig: typeof subscribeConfig; initWithEnvironment: typeof initWithEnvironment; resolveSiteId: typeof resolveSiteId; ENVIRONMENT_PRESETS: typeof ENVIRONMENT_PRESETS; buildApiUrl: typeof buildApiUrl; getToken: typeof getToken; getRefreshToken: typeof getRefreshToken; saveTokens: typeof saveTokens; clearTokens: typeof clearTokens; isAuthenticated: typeof isAuthenticated; logger: typeof logger; useSDKConfig: typeof useSDKConfig; CHAIN_NETWORKS: typeof CHAIN_NETWORKS; CANONICAL_PROGRAMS: typeof CANONICAL_PROGRAMS; CANONICAL_TOKENS: typeof CANONICAL_TOKENS; setChainNetwork: typeof setChainNetwork; getChainConfig: typeof getChainConfig; useChainConfig: typeof useChainConfig; getLanguage: typeof getLanguage; setLanguage: typeof setLanguage; initLanguage: typeof initLanguage; subscribeLanguage: typeof subscribeLanguage; useLanguage: typeof useLanguage; consentManager: typeof consentManager; useConsent: typeof useConsent; dataSanitizer: typeof dataSanitizer; }; export default sdkConfig;