UNPKG

@malga-checkout/core

Version:
31 lines (30 loc) 781 B
import axios from 'axios'; import settings from '../../stores/settings'; export class Api { constructor() { this.axiosConfig = { baseURL: this.getCurrentHost(), headers: { 'Content-Type': 'application/json', 'X-Client-Id': settings.clientId, 'X-Api-Key': settings.publicKey, }, }; this.api = axios.create(this.axiosConfig); } getCurrentHost() { if (settings.debug) { return 'https://api.dev.malga.io/v1'; } if (settings.sandbox) { return 'https://sandbox-api.malga.io/v1'; } return 'https://api.malga.io/v1'; } async create({ endpoint, data, headers }) { return this.api.post(endpoint, data, { headers }); } async fetch({ endpoint }) { return this.api.get(endpoint); } }