UNPKG

friday-sdk

Version:

Official JavaScript/TypeScript SDK for the Friday API

34 lines (33 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.APIClient = void 0; class APIClient { constructor(options) { this.apiKey = options.apiKey; this.baseUrl = options.baseUrl || "https://api.fridaydata.com"; } async request(path, options = {}, auth) { var _a; const headers = { "Content-Type": "application/json", ...options.headers, }; const useApiKey = (_a = auth === null || auth === void 0 ? void 0 : auth.useApiKey) !== null && _a !== void 0 ? _a : true; if (useApiKey) { headers["X-API-Key"] = this.apiKey; } if (auth === null || auth === void 0 ? void 0 : auth.bearerToken) { headers["Authorization"] = `Bearer ${auth.bearerToken}`; } const res = await fetch(`${this.baseUrl}${path}`, { ...options, headers, }); if (!res.ok) { const errorText = await res.text(); throw new Error(`API Error ${res.status}: ${errorText}`); } return res.json(); } } exports.APIClient = APIClient;