UNPKG

mdl-shoplet-ts

Version:

TypeScript client SDK for the headless micro CRM, Minddale.

36 lines (35 loc) 1.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MinddaleClient = void 0; const axios_1 = __importDefault(require("axios")); const mdl_identifi_ts_1 = require("mdl-identifi-ts"); class MinddaleClient { constructor(apiKey, baseUrl, timeout) { const host = typeof window !== 'undefined' ? window.location.host : 'unknown'; const tokenKey = `MDL_DNTF@${host}`; const identifiClient = new mdl_identifi_ts_1.IdentifiClient(apiKey, baseUrl); const token = identifiClient.getItemFromLocalStorage(tokenKey)?.token; this.client = axios_1.default.create({ timeout: timeout || MinddaleClient.TIMEOUT, baseURL: baseUrl || MinddaleClient.BASE_URL, headers: { 'Content-Type': 'application/json', Authorization: token ? `Identifi ${token}` : `Minddale ${apiKey}`, }, }); } async put(endpoint, shoplet) { const response = await this.client.put(endpoint, shoplet); return response.data; } async delete(endpoint) { const response = await this.client.delete(endpoint); return response.data; } } exports.MinddaleClient = MinddaleClient; MinddaleClient.TIMEOUT = 5000; MinddaleClient.BASE_URL = 'https://api.minddale.com';