n8n-nodes-zohoteaminbox
Version:
This is an n8n community node. It lets you use Zoho TeamInbox in your n8n workflows.
122 lines • 5.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.throwOnErrorStatus = throwOnErrorStatus;
exports.zohoteaminboxApiRequest = zohoteaminboxApiRequest;
exports.getPicklistWorkspaceOptions = getPicklistWorkspaceOptions;
exports.getPicklistTeamOptions = getPicklistTeamOptions;
exports.getPicklistInboxOptions = getPicklistInboxOptions;
exports.getPicklistFromOptions = getPicklistFromOptions;
exports.getPicklistAssigneeOptions = getPicklistAssigneeOptions;
exports.getDomain = getDomain;
const n8n_workflow_1 = require("n8n-workflow");
function throwOnErrorStatus(responseData) {
var _a, _b;
const errorCode = (_a = responseData.error) === null || _a === void 0 ? void 0 : _a.error_code;
const errorDescription = (_b = responseData.error) === null || _b === void 0 ? void 0 : _b.error_description;
if (errorCode || errorDescription) {
const fullMessage = errorCode ? `${errorCode}: ${errorDescription !== null && errorDescription !== void 0 ? errorDescription : 'Zoho TeamInbox Internal error'}` : errorDescription !== null && errorDescription !== void 0 ? errorDescription : 'Zoho TeamInbox Internal error';
throw new n8n_workflow_1.NodeOperationError(this.getNode(), fullMessage);
}
}
async function zohoteaminboxApiRequest(method, endpoint, body = {}, qs = {}, url) {
var _a, _b, _c, _d, _e, _f, _g;
const { oauthTokenData } = await this.getCredentials('zohoTeamInboxOAuth2Api');
const options = {
headers: { "user-agent": "n8n zohoteaminbox" },
body: body,
method,
qs,
url: `https://teaminbox.${getDomain(oauthTokenData.api_domain)}/${endpoint}`,
json: true,
};
if (!Object.keys(body).length) {
delete options.body;
}
if (!Object.keys(qs).length) {
delete options.qs;
}
try {
const responseData = await ((_a = this.helpers.requestOAuth2) === null || _a === void 0 ? void 0 : _a.call(this, 'zohoTeamInboxOAuth2Api', options));
if (responseData === undefined)
return [];
throwOnErrorStatus.call(this, responseData);
return responseData;
}
catch (error) {
const args = error ? {
message: (_d = (_c = (_b = error.error) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.error_description) !== null && _d !== void 0 ? _d : 'The Zoho TeamInbox API returned an error',
description: (_g = (_f = (_e = error.error) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.error_code) !== null && _g !== void 0 ? _g : 'No additional information provided.',
} : undefined;
throw new n8n_workflow_1.NodeApiError(this.getNode(), error, args);
}
}
async function getPicklistWorkspaceOptions() {
const responseData = (await zohoteaminboxApiRequest.call(this, 'GET', 'api/v1/workspaces', {}));
const pickListOptions = responseData.data;
if (!pickListOptions)
return [];
return pickListOptions.map((option) => ({
name: option.name,
value: option.soid,
}));
}
async function getPicklistTeamOptions(targetField) {
const responseData = (await zohoteaminboxApiRequest.call(this, 'GET', `api/v1/workspaces/${targetField}/teams`, {}));
const pickListOptions = responseData.data;
if (!pickListOptions)
return [];
return pickListOptions.filter(option => option.team_type === "2").map(option => ({
name: option.name,
value: option.team_id,
}));
}
async function getPicklistInboxOptions(workspace, team) {
const responseData = (await zohoteaminboxApiRequest.call(this, 'GET', `api/workspaces/${workspace}/teams/${team}/inbox`, {}));
const pickListOptions = responseData.data;
if (!pickListOptions)
return [];
return pickListOptions.map((option) => ({
name: option.name,
value: option.id,
}));
}
async function getPicklistFromOptions(workspace) {
const responseData = (await zohoteaminboxApiRequest.call(this, 'GET', `api/workspaces/${workspace}/channel/outgoing`, {}));
const pickListOptions = responseData.data.outgoing_channels;
if (!pickListOptions)
return [];
return pickListOptions.map((option) => ({
name: option.name,
value: option.source,
}));
}
async function getPicklistAssigneeOptions(workspace, team) {
const responseData = (await zohoteaminboxApiRequest.call(this, 'GET', `api/workspaces/${workspace}/teams/${team}/users`, {}));
const pickListOptions = responseData.data;
if (!pickListOptions)
return [];
return pickListOptions.map((option) => ({
name: option.name,
value: option.zuid,
}));
}
function getDomain(domain) {
const value = {
".com": "zoho.com",
".eu": "zoho.eu",
".com.cn": "zoho.com.cn",
".com.au": "zoho.com.au",
".in": "zoho.in",
".ca": "zohocloud.ca",
".sa": "zoho.sa",
".jp": "zoho.jp"
};
const suffixes = new Set(Object.keys(value));
for (const key of suffixes) {
if (domain.endsWith(key)) {
return value[key];
}
}
return undefined;
}
//# sourceMappingURL=GenericFunctions.js.map