n8n-nodes-supersaas
Version:
n8n node to create webhook in SuperSaaS
56 lines • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAccount = getAccount;
exports.superSaaSApiRequest = superSaaSApiRequest;
const n8n_workflow_1 = require("n8n-workflow");
async function getAccount() {
const credentials = await this.getCredentials('superSaaSApi');
if (!credentials || !credentials.account) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Invalid credentials.");
}
return credentials.account;
}
async function superSaaSApiRequest(method, endpoint, parentId, event, target_url, id) {
const credentials = await this.getCredentials('superSaaSApi');
if (!credentials || !credentials.api_key || !credentials.account) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Invalid credentials.");
}
let body = null;
if (method === 'POST' && parentId) {
body = {
parent_id: parentId,
event,
target_url
};
}
else if (method === 'DELETE' && endpoint === '/api/hooks' && id) {
body = {
parent_id: parentId,
id: id,
};
}
try {
const response = await this.helpers.request({
url: `https://www.supersaas.com${endpoint}?account=${credentials.account}&api_key=${credentials.api_key}`,
method,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body,
});
return response;
}
catch (error) {
if (error && typeof error === 'object' && 'response' in error) {
const axiosError = error;
console.error('API Error:', {
status: axiosError.response?.status,
data: axiosError.response?.data,
body: body,
});
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
//# sourceMappingURL=GenericFunctions.js.map