UNPKG

@elusion-sdk/briq

Version:

A modern TypeScript SDK for Briq SMS API integration

55 lines 1.71 kB
export class BaseClient { config; defaultHeaders; constructor(config) { this.config = { baseUrl: "https://karibu.briq.tz", timeout: 30000, retries: 3, version: "v1", ...config, }; this.defaultHeaders = { "Content-Type": "application/json", "X-API-Key": this.config.apiKey, "User-Agent": "Briq-SDK-TS/1.0.0", }; } async request(config) { const url = this.buildUrl(config.url); const headers = { ...this.defaultHeaders, ...config.headers }; try { const response = await this.executeRequest({ ...config, url, headers, }); return this.handleResponse(response); } catch (error) { throw this.handleError(error); } } buildUrl(endpoint) { const cleanEndpoint = endpoint.startsWith("/") ? endpoint.slice(1) : endpoint; return `${this.config.baseUrl}/${this.config.version}/${cleanEndpoint}`; } async get(url, config) { return this.request({ method: "GET", url, ...config }); } async post(url, data, config) { return this.request({ method: "POST", url, data, ...config }); } async patch(url, data, config) { return this.request({ method: "PATCH", url, data, ...config }); } async put(url, data, config) { return this.request({ method: "PUT", url, data, ...config }); } async delete(url, config) { return this.request({ method: "DELETE", url, ...config }); } } //# sourceMappingURL=BaseClient.js.map