UNPKG

phx-react

Version:

PHX REACT

49 lines 2.38 kB
import { __awaiter, __generator } from "tslib"; import { getEnv } from '../../read-env-config'; import axios from 'axios'; import Cookies from 'js-cookie'; import { AUTH_TOKEN, requestMaxDuration } from '../../utils/constants'; export default function PHXClientQueryV3(_a) { var query = _a.query, variables = _a.variables, _b = _a.isDelay, isDelay = _b === void 0 ? true : _b; return __awaiter(this, void 0, void 0, function () { var startTime, queryResult, urlApiGateway, authTokenInfo, error_1, endTime, duration; return __generator(this, function (_c) { switch (_c.label) { case 0: startTime = performance.now(); urlApiGateway = getEnv('NEXT_PUBLIC_API_GATEWAY', process.env.NEXT_PUBLIC_API_GATEWAY); authTokenInfo = Cookies.get(AUTH_TOKEN) && JSON.parse(Cookies.get(AUTH_TOKEN)); _c.label = 1; case 1: _c.trys.push([1, 3, , 4]); return [4 /*yield*/, axios.post("".concat(urlApiGateway, "/query"), { source: 'dashboard', query: query, variables: variables }, { headers: { 'Content-Type': 'application/json', Authorization: 'Bearer' + ' ' + authTokenInfo.token } })]; case 2: queryResult = _c.sent(); return [3 /*break*/, 4]; case 3: error_1 = _c.sent(); throw new Error('Error with Axios request: ' + error_1.message); case 4: endTime = performance.now(); duration = endTime - startTime; if (!(duration < requestMaxDuration && isDelay)) return [3 /*break*/, 6]; console.info('promise delay v3...'); return [4 /*yield*/, new Promise(function (r) { return setTimeout(r, 100); })]; case 5: _c.sent(); _c.label = 6; case 6: return [2 /*return*/, queryResult]; } }); }); } //# sourceMappingURL=clientQueryV3.js.map