UNPKG

@oneacrefund/n8n-nodes-kutt

Version:

This is an n8n community node for the Kutt URL Shortening service

226 lines 9.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Kutt = void 0; const GenericFunctions_1 = require("./GenericFunctions"); class Kutt { constructor() { this.description = { displayName: 'Kutt', subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', documentationUrl: 'https://github.com/one-acre-fund/n8n-nodes-kutt', name: 'kutt', icon: 'file:kutt.svg', group: ['transform'], version: 1, description: 'A node to shorten URLs', defaults: { name: 'Kutt', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'kuttCredentialsApi', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Link', value: 'link', description: 'Manipulate Links', }, ], default: 'link', required: true, }, { displayName: 'Operation', name: 'operation', type: 'options', required: true, noDataExpression: true, displayOptions: { show: { resource: ['link'], }, }, default: 'create', options: [ { name: 'Create', value: 'create', action: 'Create link', }, { name: 'Delete', value: 'delete', action: 'Delete link', }, { name: 'Get All', value: 'list', action: 'Get all links', }, { name: 'Get One', value: 'get', action: 'Get link', }, ], }, { displayName: 'Target URL', name: 'target', type: 'string', default: '', description: 'The target URL to point to', required: true, displayOptions: { show: { resource: ['link'], operation: ['create'], }, }, }, { displayName: 'ID', name: 'linkId', type: 'string', default: '', required: true, description: 'Link ID', displayOptions: { show: { resource: ['link'], operation: ['get', 'delete'], }, }, }, { displayName: 'Options', name: 'createOptions', placeholder: 'Add Option', type: 'collection', default: {}, displayOptions: { show: { resource: ['link'], operation: ['create'], }, }, options: [ { displayName: 'Description', name: 'description', type: 'string', default: '', }, { displayName: 'Expiration Time', description: 'Expiration time in plain English, see https://www.npmjs.com/package/ms for supported formats', name: 'expire_in', type: 'string', default: '', placeholder: 'e.g. 2 days/5h...', }, { displayName: 'Password', description: 'To password-protect your short link', name: 'password', type: 'string', typeOptions: { password: true, }, default: '', }, { displayName: 'Custom URL', description: 'To specify your own short link ID', name: 'customurl', type: 'string', default: '', }, { displayName: 'Domain', name: 'domain', type: 'string', default: '', }, { displayName: 'Reuse', description: 'Whether to try and reuse an existing short link', name: 'reuse', type: 'boolean', default: false, }, ], }, ], }; } async execute() { const items = this.getInputData(); let returnData = []; let responseData; const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); if (resource === 'link') { if (operation === 'list') { responseData = await GenericFunctions_1.kuttApiRequest.call(this, { url: `links`, scroll: true, }); returnData = returnData.concat(responseData); } if (operation === 'get') { for (let i = 0; i < items.length; i++) { const linkId = this.getNodeParameter('linkId', i, null); responseData = await GenericFunctions_1.kuttApiRequest.call(this, { url: `links/${linkId}/stats`, }); returnData = returnData.concat(responseData); } } if (operation === 'delete') { for (let i = 0; i < items.length; i++) { const linkId = this.getNodeParameter('linkId', i, null); responseData = await GenericFunctions_1.kuttApiRequest.call(this, { method: 'DELETE', url: `links/${linkId}`, }); returnData = returnData.concat(responseData); } } if (operation === 'create') { for (let i = 0; i < items.length; i++) { const target = this.getNodeParameter('target', i, ''); const createOptions = this.getNodeParameter('createOptions', i, {}); responseData = await GenericFunctions_1.kuttApiRequest.call(this, { method: 'POST', url: `links`, body: { target, ...(createOptions.description && { description: createOptions.description }), ...(createOptions.expire_in && { expire_in: createOptions.expire_in }), ...(createOptions.password && { password: createOptions.password }), ...(createOptions.customurl && { customurl: createOptions.customurl }), ...(createOptions.reuse && { reuse: createOptions.reuse }), ...(createOptions.domain && { domain: createOptions.domain }), }, }); returnData = returnData.concat(responseData); } } } return [this.helpers.returnJsonArray(returnData)]; } } exports.Kutt = Kutt; //# sourceMappingURL=Kutt.node.js.map