UNPKG

bump-cli

Version:

The Bump CLI is used to interact with your API documentation hosted on Bump.sh by using the API of developers.bump.sh

48 lines (47 loc) 1.83 kB
import axios from 'axios'; import APIError from './error.js'; import { vars } from './vars.js'; class BumpApi { config; client; getDiff = (diffId, format) => this.client.get(`/diffs/${diffId}`, { params: { formats: [format] }, }); getPing = () => this.client.get('/ping'); getVersion = (versionId, token) => this.client.get(`/versions/${versionId}`, { headers: this.authorizationHeader(token), }); postDiff = (body) => this.client.post('/diffs', body); postPreview = (body) => this.client.post('/previews', body); postValidation = (body, token) => this.client.post('/validations', body, { headers: this.authorizationHeader(token), }); postVersion = (body, token) => this.client.post('/versions', body, { headers: this.authorizationHeader(token), }); putPreview = (versionId, body) => this.client.put(`/previews/${versionId}`, body); authorizationHeader = (token) => ({ Authorization: `Basic ${Buffer.from(token).toString('base64')}`, }); handleError = (error) => Promise.reject(new APIError(error)); initializeResponseInterceptor = () => { this.client.interceptors.response.use((data) => data, this.handleError); }; // Check https://oclif.io/docs/config for details about Config.IConfig constructor(config) { this.config = config; const baseURL = `${vars.apiUrl}${vars.apiBasePath}`; const userAgent = config?.userAgent || 'bump-cli'; const headers = { 'User-Agent': vars.apiUserAgent(userAgent), }; this.client = axios.create({ baseURL, headers, }); this.initializeResponseInterceptor(); } } export { default as APIError } from './error.js'; export { BumpApi }; export * from './models.js';