UNPKG

@xompass/sdk-cloud-api

Version:

Xompass Client for cloud-api

77 lines (62 loc) 1.71 kB
/** * @description * * The XompassClient module help developers to externally * configure the base url and api version for loopback.io * * Example * * import { XompassClient, BrowserStorage } from './sdk'; * * * export class MyApp { * constructor() { * XompassClient.setBaseURL('http://localhost:3000'); * XompassClient.setApiVersion('api'); * XompassClient.setStorage(new BrowserStorage()) * } * } */ import { ClientStorage, MemoryStorage } from "./storage"; export class XompassClient { private static path = '//0.0.0.0:3000'; private static version: string | number = 'api'; private static authPrefix = ''; private static authHeader = 'Authorization' private static debug = true; private static timeout = 30000; public static storage: ClientStorage = new MemoryStorage() public static setApiVersion(version = 'api'): void { this.version = version; } public static getApiVersion(): string | number { return this.version; } public static setBaseURL(url = '/'): void { this.path = url; } public static getPath(): string { return this.path; } public static setAuthPrefix(authPrefix = ''): void { this.authPrefix = authPrefix; } public static getAuthPrefix(): string { return this.authPrefix; } public static setDebugMode(isEnabled: boolean): void { this.debug = isEnabled; } public static debuggable(): boolean { return this.debug; } public static setStorage(storage: ClientStorage): void { this.storage = storage; } public static setTimeout(timeout: number): void { this.timeout = timeout; } public static getTimeout(): number { return this.timeout || 30000; } }