25 行
609 B
TypeScript
25 行
609 B
TypeScript
|
|
import type { SDKConfig } from '../types'
|
||
|
|
import { configureHttp } from './http'
|
||
|
|
|
||
|
|
let _config: SDKConfig | null = null
|
||
|
|
let _token: string | null = null
|
||
|
|
|
||
|
|
export function init(config: SDKConfig) {
|
||
|
|
_config = config
|
||
|
|
configureHttp(config.apiBaseUrl, () => _token)
|
||
|
|
if (config.debug) console.log('[XuqmSDK] initialized', config.appKey)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function setToken(token: string | null) {
|
||
|
|
_token = token
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getToken(): string | null {
|
||
|
|
return _token
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getConfig(): SDKConfig {
|
||
|
|
if (!_config) throw new Error('XuqmSDK not initialized. Call init() first.')
|
||
|
|
return _config
|
||
|
|
}
|