n8n/packages/nodes-base/nodes/Aws/AwsSns.node.ts

331 lines
8.1 KiB
TypeScript
Raw Normal View History

import type {
IExecuteFunctions,
IDataObject,
ILoadOptionsFunctions,
2019-10-04 18:06:26 -07:00
INodeExecutionData,
2022-11-28 03:27:20 -08:00
INodeListSearchItems,
INodeListSearchResult,
INodeType,
INodeTypeDescription,
2019-10-04 18:06:26 -07:00
} from 'n8n-workflow';
2019-10-15 10:21:48 -07:00
import { awsApiRequestSOAP } from './GenericFunctions';
2019-10-05 06:27:19 -07:00
2019-10-05 08:05:58 -07:00
export class AwsSns implements INodeType {
2019-10-04 18:06:26 -07:00
description: INodeTypeDescription = {
2019-10-05 08:05:58 -07:00
displayName: 'AWS SNS',
name: 'awsSns',
icon: 'file:sns.svg',
2019-10-04 18:06:26 -07:00
group: ['output'],
version: 1,
subtitle: '={{$parameter["topic"]}}',
2019-10-05 08:05:58 -07:00
description: 'Sends data to AWS SNS',
2019-10-04 18:06:26 -07:00
defaults: {
2019-10-05 08:05:58 -07:00
name: 'AWS SNS',
2019-10-04 18:06:26 -07:00
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'aws',
required: true,
2020-10-22 06:46:03 -07:00
},
2019-10-04 18:06:26 -07:00
],
properties: [
2019-10-15 10:24:45 -07:00
{
displayName: 'Operation',
name: 'operation',
type: 'options',
refactor: Apply more nodelinting rules (#3324) * :pencil2: Alphabetize lint rules * :fire: Remove duplicates * :zap: Update `lintfix` script * :shirt: Apply `node-param-operation-without-no-data-expression` (#3329) * :shirt: Apply `node-param-operation-without-no-data-expression` * :shirt: Add exceptions * :shirt: Apply `node-param-description-weak` (#3328) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-value-duplicate` (#3331) * :shirt: Apply `node-param-description-miscased-json` (#3337) * :shirt: Apply `node-param-display-name-excess-inner-whitespace` (#3335) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-type-options-missing-from-limit` (#3336) * Rule workig as intended * :pencil2: Uncomment rules Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-name-duplicate` (#3338) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-description-wrong-for-simplify` (#3334) * :zap: fix * :zap: exceptions * :zap: changed rule ignoring from file to line * :shirt: Apply `node-param-resource-without-no-data-expression` (#3339) * :shirt: Apply `node-param-display-name-untrimmed` (#3341) * :shirt: Apply `node-param-display-name-miscased-id` (#3340) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-resource-with-plural-option` (#3342) * :shirt: Apply `node-param-description-wrong-for-upsert` (#3333) * :zap: fix * :zap: replaced record with contact in description * :zap: fix Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :shirt: Apply `node-param-option-description-identical-to-name` (#3343) * :shirt: Apply `node-param-option-name-containing-star` (#3347) * :shirt: Apply `node-param-display-name-wrong-for-update-fields` (#3348) * :shirt: Apply `node-param-option-name-wrong-for-get-all` (#3345) * :zap: fix * :zap: exceptions * :shirt: Apply node-param-display-name-wrong-for-simplify (#3344) * Rule working as intended * Uncomented other rules * :shirt: Undo and add exceptions Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * :zap: Alphabetize lint rules * :zap: Restore `lintfix` script Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com>
2022-05-20 14:47:24 -07:00
noDataExpression: true,
2019-10-15 10:24:45 -07:00
options: [
2022-11-28 03:27:20 -08:00
{
name: 'Create',
value: 'create',
description: 'Create a topic',
action: 'Create a topic',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a topic',
action: 'Delete a topic',
},
2019-10-15 10:24:45 -07:00
{
name: 'Publish',
value: 'publish',
description: 'Publish a message to a topic',
action: 'Publish a message to a topic',
2019-10-15 10:24:45 -07:00
},
],
default: 'publish',
2019-10-15 10:24:45 -07:00
},
2019-10-04 18:06:26 -07:00
{
2022-11-28 03:27:20 -08:00
displayName: 'Name',
name: 'name',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
operation: ['create'],
},
2019-10-04 18:06:26 -07:00
},
2022-11-28 03:27:20 -08:00
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Display Name',
name: 'displayName',
type: 'string',
default: '',
description: 'The display name to use for a topic with SMS subscriptions',
},
{
displayName: 'Fifo Topic',
name: 'fifoTopic',
type: 'boolean',
default: false,
description:
'Whether the topic you want to create is a FIFO (first-in-first-out) topic',
},
],
2019-10-15 10:24:45 -07:00
displayOptions: {
show: {
2022-11-28 03:27:20 -08:00
operation: ['create'],
2019-10-15 10:24:45 -07:00
},
},
2022-11-28 03:27:20 -08:00
},
{
displayName: 'Topic',
name: 'topic',
type: 'resourceLocator',
default: { mode: 'list', value: '' },
2019-10-04 18:06:26 -07:00
required: true,
2022-11-28 03:27:20 -08:00
modes: [
{
displayName: 'From List',
name: 'list',
type: 'list',
placeholder: 'Select a topic...',
typeOptions: {
searchListMethod: 'listTopics',
searchable: true,
},
},
{
displayName: 'By URL',
name: 'url',
type: 'string',
placeholder:
'https://us-east-1.console.aws.amazon.com/sns/v3/home?region=us-east-1#/topic/arn:aws:sns:us-east-1:777777777777:your_topic',
validation: [
{
type: 'regex',
properties: {
regex:
'https:\\/\\/[0-9a-zA-Z\\-_]+\\.console\\.aws\\.amazon\\.com\\/sns\\/v3\\/home\\?region\\=[0-9a-zA-Z\\-_]+\\#\\/topic\\/arn:aws:sns:[0-9a-zA-Z\\-_]+:[0-9]+:[0-9a-zA-Z\\-_]+(?:\\/.*|)',
errorMessage: 'Not a valid AWS SNS Topic URL',
},
},
],
extractValue: {
type: 'regex',
regex:
'https:\\/\\/[0-9a-zA-Z\\-_]+\\.console\\.aws\\.amazon\\.com\\/sns\\/v3\\/home\\?region\\=[0-9a-zA-Z\\-_]+\\#\\/topic\\/(arn:aws:sns:[0-9a-zA-Z\\-_]+:[0-9]+:[0-9a-zA-Z\\-_]+)(?:\\/.*|)',
},
},
{
displayName: 'ID',
name: 'id',
type: 'string',
validation: [
{
type: 'regex',
properties: {
regex: 'arn:aws:sns:[0-9a-zA-Z\\-_]+:[0-9]+:[0-9a-zA-Z\\-_]+',
errorMessage: 'Not a valid AWS SNS Topic ARN',
},
},
],
placeholder: 'arn:aws:sns:your-aws-region:777777777777:your_topic',
},
],
displayOptions: {
show: {
operation: ['publish', 'delete'],
},
},
2019-10-04 18:06:26 -07:00
},
{
displayName: 'Subject',
name: 'subject',
type: 'string',
2019-10-15 10:24:45 -07:00
displayOptions: {
show: {
operation: ['publish'],
2019-10-15 10:24:45 -07:00
},
},
2019-10-04 18:06:26 -07:00
default: '',
2019-10-15 10:21:48 -07:00
required: true,
2019-10-04 18:06:26 -07:00
description: 'Subject when the message is delivered to email endpoints',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
2019-10-15 10:24:45 -07:00
displayOptions: {
show: {
operation: ['publish'],
2019-10-15 10:24:45 -07:00
},
},
2019-10-04 18:06:26 -07:00
required: true,
default: '',
description: 'The message you want to send',
},
],
};
methods = {
2022-11-28 03:27:20 -08:00
listSearch: {
async listTopics(
this: ILoadOptionsFunctions,
filter?: string,
paginationToken?: string,
): Promise<INodeListSearchResult> {
const returnData: INodeListSearchItems[] = [];
const params = paginationToken ? `NextToken=${encodeURIComponent(paginationToken)}` : '';
const data = await awsApiRequestSOAP.call(
this,
'sns',
'GET',
'/?Action=ListTopics&' + params,
);
2019-10-04 18:06:26 -07:00
let topics = data.ListTopicsResponse.ListTopicsResult.Topics.member;
2022-11-28 03:27:20 -08:00
const nextToken = data.ListTopicsResponse.ListTopicsResult.NextToken;
if (nextToken) {
paginationToken = nextToken as string;
} else {
paginationToken = undefined;
}
if (!Array.isArray(topics)) {
topics = [topics];
}
for (const topic of topics) {
const topicArn = topic.TopicArn as string;
2022-11-28 03:27:20 -08:00
const arnParsed = topicArn.split(':');
const topicName = arnParsed[5];
const awsRegion = arnParsed[3];
if (filter && !topicName.includes(filter)) {
2022-11-28 03:27:20 -08:00
continue;
}
2019-10-05 06:27:19 -07:00
2019-10-04 18:06:26 -07:00
returnData.push({
name: topicName,
value: topicArn,
2022-11-28 03:27:20 -08:00
url: `https://${awsRegion}.console.aws.amazon.com/sns/v3/home?region=${awsRegion}#/topic/${topicArn}`,
2019-10-04 18:06:26 -07:00
});
}
2022-11-28 03:27:20 -08:00
return { results: returnData, paginationToken };
2020-10-22 06:46:03 -07:00
},
2019-10-04 18:06:26 -07:00
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const operation = this.getNodeParameter('operation', 0);
2019-10-04 18:06:26 -07:00
for (let i = 0; i < items.length; i++) {
:zap: Add full continue-on-fail support to all nodes (#1996) * Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
2021-07-19 23:58:54 -07:00
try {
2022-11-28 03:27:20 -08:00
if (operation === 'create') {
let name = this.getNodeParameter('name', i) as string;
const fifoTopic = this.getNodeParameter('options.fifoTopic', i, false) as boolean;
const displayName = this.getNodeParameter('options.displayName', i, '') as string;
const params: string[] = [];
2019-10-04 18:06:26 -07:00
2022-11-28 03:27:20 -08:00
if (fifoTopic && !name.endsWith('.fifo')) {
name = `${name}.fifo`;
}
params.push(`Name=${name}`);
if (fifoTopic) {
params.push('Attributes.entry.1.key=FifoTopic');
params.push('Attributes.entry.1.value=true');
}
if (displayName) {
params.push('Attributes.entry.2.key=DisplayName');
params.push(`Attributes.entry.2.value=${displayName}`);
}
const responseData = await awsApiRequestSOAP.call(
this,
'sns',
'GET',
'/?Action=CreateTopic&' + params.join('&'),
);
returnData.push({
TopicArn: responseData.CreateTopicResponse.CreateTopicResult.TopicArn,
} as IDataObject);
}
if (operation === 'delete') {
const topic = this.getNodeParameter('topic', i, undefined, {
extractValue: true,
}) as string;
const params = ['TopicArn=' + topic];
2022-11-28 03:27:20 -08:00
await awsApiRequestSOAP.call(
this,
'sns',
'GET',
'/?Action=DeleteTopic&' + params.join('&'),
);
// response of delete is the same no matter if topic was deleted or not
returnData.push({ success: true } as IDataObject);
}
if (operation === 'publish') {
const topic = this.getNodeParameter('topic', i, undefined, {
extractValue: true,
}) as string;
const params = [
'TopicArn=' + topic,
'Subject=' + encodeURIComponent(this.getNodeParameter('subject', i) as string),
'Message=' + encodeURIComponent(this.getNodeParameter('message', i) as string),
2022-11-28 03:27:20 -08:00
];
const responseData = await awsApiRequestSOAP.call(
this,
'sns',
'GET',
'/?Action=Publish&' + params.join('&'),
);
returnData.push({
MessageId: responseData.PublishResponse.PublishResult.MessageId,
} as IDataObject);
}
:zap: Add full continue-on-fail support to all nodes (#1996) * Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
2021-07-19 23:58:54 -07:00
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
continue;
}
throw error;
}
2019-10-04 18:06:26 -07:00
}
return [this.helpers.returnJsonArray(returnData)];
}
}