projex
Version:
A command line to manage the workflow
53 lines (52 loc) • 2.14 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.serviceGetAuth = void 0;
const _shared_1 = require("../../../../../../shared/index");
const axios_1 = __importDefault(require("axios"));
/**
* The function `serviceGetAuth` is an asynchronous function that sends a POST request to a VTEX API
* endpoint to get an authentication token using an account, API key, and API token.
* @param {string} account - The `account` parameter is a string that represents the name of the VTEX
* account you want to authenticate with.
* @param {string} apiKey - The `apiKey` parameter is a string that represents the API key used for
* authentication. It is typically a unique identifier that is associated with a specific account or
* user.
* @param {string} apiToken - The `apiToken` parameter is a token that is used for authentication
* purposes. It is typically generated by the API provider and is used to verify the identity of the
* user making the request.
* @returns the result of the axios request or undefined in case of errors.
*/
const serviceGetAuth = async (account, apiKey, apiToken) => {
try {
if (!apiToken || !apiKey || !account) {
_shared_1.log.error('no account, apiToken or apiKey');
return undefined;
}
const url = _shared_1.Endpoints.VTEX_GET_TOKEN(account);
const data = JSON.stringify({
appkey: apiKey,
apptoken: apiToken,
});
const headers = {
Referer: '',
'Content-Type': 'application/json, application/json',
};
const config = {
method: 'post',
url,
headers,
data,
};
_shared_1.log.debug(config);
return await (0, axios_1.default)(config);
}
catch (error) {
_shared_1.log.debug(error);
_shared_1.log.error('error on get auth token');
return undefined;
}
};
exports.serviceGetAuth = serviceGetAuth;