n8n-nodes-base
Version:
Base nodes of n8n
36 lines • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.driftApiRequest = driftApiRequest;
const n8n_workflow_1 = require("n8n-workflow");
async function driftApiRequest(method, resource, body = {}, query = {}, uri, option = {}) {
let options = {
headers: {},
method,
body,
qs: query,
uri: uri || `https://driftapi.com${resource}`,
json: true,
};
if (!Object.keys(body).length) {
delete options.form;
}
if (!Object.keys(query).length) {
delete options.qs;
}
options = Object.assign({}, options, option);
const authenticationMethod = this.getNodeParameter('authentication', 0);
try {
if (authenticationMethod === 'accessToken') {
const credentials = await this.getCredentials('driftApi');
options.headers.Authorization = `Bearer ${credentials.accessToken}`;
return await this.helpers.request(options);
}
else {
return await this.helpers.requestOAuth2.call(this, 'driftOAuth2Api', options);
}
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
//# sourceMappingURL=GenericFunctions.js.map