UNPKG

vista-co

Version:
49 lines (48 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BackgroundJob = void 0; const axios_master_1 = require("axios-master"); const BackgroundJob = (config) => { return { GetBackgroundJobDetails: async (backgroundJobId) => { var _a, _b, _c; try { // Construct the request URL with the backgroundJobId path parameter. const url = `${config.host}/WSVistaWebClient/OData.svc/BackgroundJob.svc/${backgroundJobId}`; // Send the GET request with headers including API token and region code if provided. const res = await (0, axios_master_1.axiosMasterMain)({ method: "GET", url, headers: { connectapitoken: `${config.token}`, // API token for authentication "Content-Type": "application/json", // Ensures the response format is JSON "Connect-Region-Code": config.regionCode, // Region code for localization }, }, { name: "GetBackgroundJobDetails", // Request identifier for logging and debugging timeout: 20000, // Timeout of 20 seconds for the request logger(data) { if (config.logger) { console.log(data); // Logs request data for debugging purposes } }, }); // Return the 'data' from the successful response. return { success: true, message: "Request successful", data: res, }; } catch (error) { // Logs and returns an error message if the request fails. console.error("Request failed", (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data); return { success: false, message: ((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || "An error occurred", }; } }, }; }; exports.BackgroundJob = BackgroundJob;