1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const axios_1 = require("axios");
|
4 | const login_1 = require("../actions/login");
|
5 | exports.devPortalClient = (command) => {
|
6 | const instance = axios_1.default.create({
|
7 | baseURL: command.constants.DeveloperPortalAPIUrl
|
8 | });
|
9 | instance.interceptors.response.use(r => r, error => {
|
10 | if (error.response && error.response.status) {
|
11 | command.error('Unauthorized action, please run bearer login first');
|
12 | }
|
13 | return Promise.reject(error);
|
14 | });
|
15 | async function requestFunction(data) {
|
16 | let token = await command.bearerConfig.getToken();
|
17 | if (!token) {
|
18 | command.debug('no token found, trying to log you in');
|
19 | await login_1.promptToLogin(command);
|
20 | token = await command.bearerConfig.getToken();
|
21 | }
|
22 | return await instance.post('', data, {
|
23 | headers: {
|
24 | Authorization: `Bearer ${token.access_token}`
|
25 | }
|
26 | });
|
27 | }
|
28 | return {
|
29 | request: requestFunction
|
30 | };
|
31 | };
|