Browse Source

feat: add new SES implementation (#965)

* fix: remove the old implementation

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>

* feat: add new ses implementation

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>

* feat: add SESPluginConfig

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>

* fix: add ses old implementation back for migration

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>

* feat: add ses migration source

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>

* chore: add deprecation message

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>
pull/970/head
WK WONG 3 years ago committed by GitHub
parent
commit
47988fc1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      packages/nocodb/src/lib/noco/common/XcMigrationSource.ts
  2. 36
      packages/nocodb/src/lib/noco/migrations/nc_011_remove_old_ses_plugin.ts
  3. 4
      packages/nocodb/src/lib/noco/plugins/NcPluginMgr.ts
  4. 2
      packages/nocodb/src/lib/noco/plugins/ses.ts
  5. 73
      packages/nocodb/src/plugins/ses/SES.ts
  6. 18
      packages/nocodb/src/plugins/ses/SESPlugin.ts
  7. 69
      packages/nocodb/src/plugins/ses/index.ts

7
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 <oof1lab@gmail.com>
* @author Pranav C Balan <pranavxc@gmail.com>
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*

36
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 <wingkwong.code@gmail.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

4
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 {

2
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 = {

73
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<any> {
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<any> {
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<boolean> {
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 <wingkwong.code@gmail.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

18
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<any> {
SESPlugin.storageAdapter = new SES(config);
await SESPlugin.storageAdapter.init();
}
}
export default SESPlugin;

69
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;
Loading…
Cancel
Save