UNPKG

voltra-hub-api-client

Version:
42 lines (41 loc) 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VoltraHubAPIClient = void 0; const openapi_fetch_1 = __importDefault(require("openapi-fetch")); class VoltraHubAPIClient { constructor(baseUrl) { this.authenticate = { onRequest: ({ request }) => { if (this.authentication) { request.headers.set('Authorization', `Bearer ${this.authentication}`); } return request; } }; this.auth = { set: (access_token) => { this.authentication = access_token; }, get: () => { return this.authentication; } }; this.pvpc = { get: (date) => { const year = date.getFullYear(); const month = `${date.getMonth() + 1}`.padStart(2, '0'); const day = date.getDate(); return this.client.GET('/pvpc', { params: { query: { date: [year, month, day].join('-') } } }); } }; this.client = (0, openapi_fetch_1.default)({ baseUrl, headers: { Bearer: 'access_token' } }); this.client.use(this.authenticate); } healthCheck() { return this.client.GET('/health-check'); } } exports.VoltraHubAPIClient = VoltraHubAPIClient;