UNPKG

@elucidatainc/pollycli

Version:

pollycli lets users access the functionalities of Polly over a command line interface

74 lines (66 loc) 2.08 kB
const axios = require("axios"); const v2_url = require("./env.json")["baseV2Api"]; const auth_api_url = require('./env.json')['authBaseApi'] const workspace_api_url = require('./env.json')['workspaceBaseApi'] const pollyApi = axios.create({ baseURL: v2_url, headers: { 'Content-Type': 'application/vnd.api+json' } }); const authApi = axios.create({ baseURL: auth_api_url, headers: { 'Content-Type': 'application/vnd.api+json', }, }) const workspaceApi = axios.create({ baseURL: workspace_api_url, headers: { 'Content-Type': 'application/vnd.api+json', }, }) // to refresh accessToken pollyApi.interceptors.request.use(function (config) { if(pollystore.get('pollyUser')) { const email = pollystore.get('pollyUser').pollyemail; const accessToken = pollystore.get(email).pollyAccessToken; if(accessToken) { config.headers.common["Authorization"] = "Bearer " + accessToken; } else if(pollystore.get(email).pollyApiKey) { config.headers.common["x-api-key"] = pollystore.get(email).pollyApiKey; } } return config; }); authApi.interceptors.request.use(function (config) { if (pollystore.get('pollyUser')) { const email = pollystore.get('pollyUser').pollyemail const accessToken = pollystore.get(email).pollyAccessToken if (accessToken) { config.headers.common['Authorization'] = 'Bearer ' + accessToken } else if (pollystore.get(email).pollyApiKey) { config.headers.common['x-api-key'] = pollystore.get(email).pollyApiKey } } return config }) workspaceApi.interceptors.request.use(function (config) { if (pollystore.get('pollyUser')) { const email = pollystore.get('pollyUser').pollyemail const accessToken = pollystore.get(email).pollyAccessToken if (accessToken) { config.headers.common['Authorization'] = 'Bearer ' + accessToken } else if (pollystore.get(email).pollyApiKey) { config.headers.common['x-api-key'] = pollystore.get(email).pollyApiKey } } return config }) module.exports = { pollyApi, authApi, workspaceApi, }