diff --git a/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts b/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts index 3b0f3be0a5..7d128b13da 100644 --- a/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts +++ b/packages/nocodb/src/lib/noco/common/XcMigrationSource.ts @@ -8,6 +8,7 @@ import * as nc_007_alter_nc_shared_views_1 from '../migrations/nc_007_alter_nc_s import * as nc_008_add_nc_shared_bases from '../migrations/nc_008_add_nc_shared_bases'; import * as nc_009_add_model_order from '../migrations/nc_009_add_model_order'; import * as nc_010_add_parent_title_column from '../migrations/nc_010_add_parent_title_column'; +import * as nc_011_remove_old_ses_plugin from '../migrations/nc_011_remove_old_ses_plugin'; // Create a custom migration source class export default class XcMigrationSource { @@ -26,7 +27,8 @@ export default class XcMigrationSource { 'nc_007_alter_nc_shared_views_1', 'nc_008_add_nc_shared_bases', 'nc_009_add_model_order', - 'nc_010_add_parent_title_column' + 'nc_010_add_parent_title_column', + 'nc_011_remove_old_ses_plugin' ]); } @@ -56,6 +58,8 @@ export default class XcMigrationSource { return nc_009_add_model_order; case 'nc_010_add_parent_title_column': return nc_010_add_parent_title_column; + case 'nc_011_remove_old_ses_plugin': + return nc_011_remove_old_ses_plugin; } } } @@ -65,6 +69,7 @@ export default class XcMigrationSource { * * @author Naveen MR * @author Pranav C Balan + * @author Wing-Kam Wong * * @license GNU AGPL version 3 or any later version * diff --git a/packages/nocodb/src/lib/noco/migrations/nc_011_remove_old_ses_plugin.ts b/packages/nocodb/src/lib/noco/migrations/nc_011_remove_old_ses_plugin.ts new file mode 100644 index 0000000000..8bdf7dca78 --- /dev/null +++ b/packages/nocodb/src/lib/noco/migrations/nc_011_remove_old_ses_plugin.ts @@ -0,0 +1,36 @@ +import Knex from 'knex'; +import ses from '../plugins/ses'; + +const up = async (knex: Knex) => { + await knex('nc_plugins').del().where({title: "SES"}); +}; + +const down = async (knex: Knex) => { + await knex('nc_plugins').insert([ + ses + ]); +}; + +export { up, down }; + +/** + * @copyright Copyright (c) 2021, Xgene Cloud Ltd + * + * @author Wing-Kam Wong + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ diff --git a/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts b/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts index 2d63ea0c2f..43f630a31e 100644 --- a/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts +++ b/packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts @@ -26,6 +26,7 @@ import TwilioPluginConfig from '../../../plugins/twilio'; import TwilioWhatsappPluginConfig from '../../../plugins/twilioWhatsapp'; import UpcloudPluginConfig from '../../../plugins/upcloud'; import VultrPluginConfig from '../../../plugins/vultr'; +import SESPluginConfig from '../../../plugins/ses'; import Noco from '../Noco'; import NcMetaIO from '../meta/NcMetaIO'; @@ -49,7 +50,8 @@ const defaultPlugins = [ UpcloudPluginConfig, SMTPPluginConfig, MailerSendConfig, - ScalewayPluginConfig + ScalewayPluginConfig, + SESPluginConfig ]; class NcPluginMgr { diff --git a/packages/nocodb/src/lib/noco/plugins/ses.ts b/packages/nocodb/src/lib/noco/plugins/ses.ts index 93a01a46e6..59966014d5 100644 --- a/packages/nocodb/src/lib/noco/plugins/ses.ts +++ b/packages/nocodb/src/lib/noco/plugins/ses.ts @@ -1,3 +1,5 @@ +// @wingkwong: Deprecated. Moved to nocodb/packages/nocodb/src/plugins/ses instead. Keep this file for migration only. + import { XcActionType, XcForm, XcType } from 'nc-common'; const input: XcForm = { @@ -77,4 +79,4 @@ export default { tags: 'Email', category: 'Email', input_schema: JSON.stringify(input) -}; +}; \ No newline at end of file diff --git a/packages/nocodb/src/plugins/ses/SES.ts b/packages/nocodb/src/plugins/ses/SES.ts new file mode 100644 index 0000000000..212cd80339 --- /dev/null +++ b/packages/nocodb/src/plugins/ses/SES.ts @@ -0,0 +1,73 @@ +import { IEmailAdapter } from 'nc-plugin'; +import nodemailer from 'nodemailer'; +import Mail from 'nodemailer/lib/mailer'; +import AWS from 'aws-sdk'; +import { XcEmail } from '../../interface/IEmailAdapter'; + +export default class SES implements IEmailAdapter { + private transporter: Mail; + private input: any; + + constructor(input: any) { + this.input = input; + } + + public async init(): Promise { + const sesOptions: any = { + accessKeyId: this.input.access_key, + secretAccessKey: this.input.access_secret, + region: this.input.region + }; + + this.transporter = nodemailer.createTransport({ + SES: new AWS.SES(sesOptions) + }); + } + + public async mailSend(mail: XcEmail): Promise { + if (this.transporter) { + this.transporter.sendMail({ ...mail, from: this.input.from }, (err, info) => { + if (err) { + console.log(err); + } else { + console.log('Message sent: ' + info.response); + } + }); + } + } + + public async test(): Promise { + try { + await this.mailSend({ + to: this.input.from, + subject: 'Test email', + html: 'Test email' + } as any); + return true + } catch (e) { + throw e; + } + } +} + +/** + * @copyright Copyright (c) 2021, Xgene Cloud Ltd + * + * @author Wing-Kam Wong + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ diff --git a/packages/nocodb/src/plugins/ses/SESPlugin.ts b/packages/nocodb/src/plugins/ses/SESPlugin.ts new file mode 100644 index 0000000000..ec7de8aaae --- /dev/null +++ b/packages/nocodb/src/plugins/ses/SESPlugin.ts @@ -0,0 +1,18 @@ +import { IEmailAdapter, XcEmailPlugin } from 'nc-plugin'; + +import SES from './SES'; + +class SESPlugin extends XcEmailPlugin { + private static storageAdapter: SES; + + public getAdapter(): IEmailAdapter { + return SESPlugin.storageAdapter; + } + + public async init(config: any): Promise { + SESPlugin.storageAdapter = new SES(config); + await SESPlugin.storageAdapter.init(); + } +} + +export default SESPlugin; diff --git a/packages/nocodb/src/plugins/ses/index.ts b/packages/nocodb/src/plugins/ses/index.ts new file mode 100644 index 0000000000..9e60c8e481 --- /dev/null +++ b/packages/nocodb/src/plugins/ses/index.ts @@ -0,0 +1,69 @@ +import { XcActionType, XcType } from 'nc-common'; +import { XcPluginConfig } from 'nc-plugin'; + +import SESPlugin from './SESPlugin'; + +const config: XcPluginConfig = { + builder: SESPlugin, + title: 'SES', + version: '0.0.1', + logo: 'plugins/aws.png', + description: 'Amazon Simple Email Service (SES) is a cost-effective, flexible, and scalable email service that enables developers to send mail from within any application.', + price: 'Free', + tags: 'Email', + category: 'Email', + inputs: { + title: 'Configure Amazon Simple Email Service (SES)', + items: [ + { + key: 'from', + label: 'From', + placeholder: 'From', + type: XcType.SingleLineText, + required: true + }, + { + key: 'region', + label: 'Region', + placeholder: 'Region', + type: XcType.SingleLineText, + required: true + }, + { + key: 'access_key', + label: 'Access Key', + placeholder: 'Access Key', + type: XcType.SingleLineText, + required: true + }, + { + key: 'access_secret', + label: 'Access Secret', + placeholder: 'Access Secret', + type: XcType.Password, + required: true + } + ], + actions: [ + { + label: 'Test', + placeholder: 'Test', + key: 'test', + actionType: XcActionType.TEST, + type: XcType.Button + }, + { + label: 'Save', + placeholder: 'Save', + key: 'save', + actionType: XcActionType.SUBMIT, + type: XcType.Button + } + ], + msgOnInstall: + 'Successfully installed and email notification will use Amazon SES', + msgOnUninstall: '' + } +}; + +export default config;