@nocobase/plugin-notifications 0.11.1-alpha.4 → 0.12.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +2 -3
- package/client.js +1 -1
- package/dist/client/index.js +11 -0
- package/{lib/server → dist}/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/server/collections/notification_logs.js +28 -0
- package/dist/server/collections/notification_services.js +28 -0
- package/dist/server/collections/notifications.js +45 -0
- package/dist/server/index.js +11 -0
- package/{src/server/models/Notification.ts → dist/server/models/Notification.js} +26 -26
- package/dist/server/models/NotificationLog.js +8 -0
- package/dist/server/models/NotificationService.js +29 -0
- package/dist/server/models/index.js +26 -0
- package/dist/server/server.js +18 -0
- package/package.json +12 -23
- package/server.d.ts +2 -3
- package/server.js +1 -1
- package/lib/client/index.js +0 -22
- package/lib/index.js +0 -13
- package/lib/server/collections/notification_logs.js +0 -26
- package/lib/server/collections/notification_services.js +0 -26
- package/lib/server/collections/notifications.js +0 -40
- package/lib/server/index.js +0 -13
- package/lib/server/models/Notification.js +0 -113
- package/lib/server/models/NotificationLog.js +0 -15
- package/lib/server/models/NotificationService.js +0 -52
- package/lib/server/models/index.js +0 -38
- package/lib/server/server.js +0 -34
- package/src/client/index.ts +0 -7
- package/src/index.ts +0 -1
- package/src/server/__tests__/notifications.test.ts +0 -53
- package/src/server/collections/notification_logs.ts +0 -25
- package/src/server/collections/notification_services.ts +0 -25
- package/src/server/collections/notifications.ts +0 -42
- package/src/server/index.ts +0 -1
- package/src/server/models/NotificationLog.ts +0 -3
- package/src/server/models/NotificationService.ts +0 -26
- package/src/server/models/index.ts +0 -3
- package/src/server/server.ts +0 -10
- /package/{lib → dist}/client/index.d.ts +0 -0
- /package/{lib → dist}/server/collections/notification_logs.d.ts +0 -0
- /package/{lib → dist}/server/collections/notification_services.d.ts +0 -0
- /package/{lib → dist}/server/collections/notifications.d.ts +0 -0
- /package/{lib → dist/server}/index.d.ts +0 -0
- /package/{lib → dist}/server/models/Notification.d.ts +0 -0
- /package/{lib → dist}/server/models/NotificationLog.d.ts +0 -0
- /package/{lib → dist}/server/models/NotificationService.d.ts +0 -0
- /package/{lib → dist}/server/models/index.d.ts +0 -0
- /package/{lib → dist}/server/server.d.ts +0 -0
package/client.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export { default } from './
|
|
3
|
-
|
|
1
|
+
export * from './dist/client';
|
|
2
|
+
export { default } from './dist/client';
|
package/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@nocobase/client")) : typeof define === "function" && define.amd ? define(["exports", "@nocobase/client"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nocobase/plugin-notifications"] = {}, global["@nocobase/client"]));
|
|
3
|
+
})(this, function(exports2, client) {
|
|
4
|
+
"use strict";
|
|
5
|
+
class NotificationPlugin extends client.Plugin {
|
|
6
|
+
async load() {
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports2.default = NotificationPlugin;
|
|
10
|
+
Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
11
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var server = require('./server');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, 'default', {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return server__namespace.default; }
|
|
12
|
+
});
|
|
13
|
+
Object.keys(server).forEach(function (k) {
|
|
14
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return server[k]; }
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var models = require('../models');
|
|
4
|
+
|
|
5
|
+
var notification_logs_default = {
|
|
6
|
+
name: "notification_logs",
|
|
7
|
+
model: models.NotificationLog,
|
|
8
|
+
title: "\u901A\u77E5\u65E5\u5FD7",
|
|
9
|
+
fields: [
|
|
10
|
+
{
|
|
11
|
+
title: "\u63A5\u6536\u4EBA",
|
|
12
|
+
type: "json",
|
|
13
|
+
name: "receiver"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: "\u72B6\u6001",
|
|
17
|
+
type: "string",
|
|
18
|
+
name: "state"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "\u8BE6\u60C5",
|
|
22
|
+
type: "json",
|
|
23
|
+
name: "response"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = notification_logs_default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var models = require('../models');
|
|
4
|
+
|
|
5
|
+
var notification_services_default = {
|
|
6
|
+
name: "notification_services",
|
|
7
|
+
model: models.NotificationService,
|
|
8
|
+
title: "\u901A\u77E5\u670D\u52A1",
|
|
9
|
+
fields: [
|
|
10
|
+
{
|
|
11
|
+
title: "\u7C7B\u578B",
|
|
12
|
+
type: "string",
|
|
13
|
+
name: "type"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: "\u670D\u52A1\u540D\u79F0",
|
|
17
|
+
type: "string",
|
|
18
|
+
name: "title"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "\u914D\u7F6E\u4FE1\u606F",
|
|
22
|
+
type: "json",
|
|
23
|
+
name: "options"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = notification_services_default;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var models = require('../models');
|
|
4
|
+
|
|
5
|
+
var notifications_default = {
|
|
6
|
+
name: "notifications",
|
|
7
|
+
model: models.Notification,
|
|
8
|
+
title: "\u901A\u77E5",
|
|
9
|
+
fields: [
|
|
10
|
+
{
|
|
11
|
+
type: "uid",
|
|
12
|
+
name: "name",
|
|
13
|
+
prefix: "n_"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
title: "\u4E3B\u9898",
|
|
17
|
+
type: "string",
|
|
18
|
+
name: "subject"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: "\u5185\u5BB9",
|
|
22
|
+
type: "text",
|
|
23
|
+
name: "body"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
title: "\u63A5\u6536\u4EBA\u914D\u7F6E",
|
|
27
|
+
type: "json",
|
|
28
|
+
name: "receiver_options"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title: "\u53D1\u9001\u670D\u52A1",
|
|
32
|
+
type: "belongsTo",
|
|
33
|
+
name: "service",
|
|
34
|
+
target: "notification_services"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
title: "\u65E5\u5FD7",
|
|
38
|
+
type: "hasMany",
|
|
39
|
+
name: "logs",
|
|
40
|
+
target: "notification_logs"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = notifications_default;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { lodash } from '@nocobase/utils';
|
|
3
|
-
import { NotificationService } from './NotificationService';
|
|
1
|
+
'use strict';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
var database = require('@nocobase/database');
|
|
4
|
+
var lodash = require('lodash');
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var lodash__default = /*#__PURE__*/_interopDefault(lodash);
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
class Notification extends database.Model {
|
|
11
|
+
get db() {
|
|
12
|
+
return this.constructor["database"];
|
|
13
|
+
}
|
|
14
|
+
async getReceiversByOptions() {
|
|
13
15
|
const { data, fromTable, filter, dataField } = this.receiver_options;
|
|
14
16
|
let receivers = [];
|
|
15
17
|
if (data) {
|
|
@@ -17,16 +19,14 @@ export class Notification extends Model {
|
|
|
17
19
|
} else if (fromTable) {
|
|
18
20
|
const collection = this.db.getCollection(fromTable);
|
|
19
21
|
const rows = await collection.repository.find({
|
|
20
|
-
filter
|
|
22
|
+
filter
|
|
21
23
|
});
|
|
22
24
|
receivers = rows.map((row) => row[dataField]);
|
|
23
25
|
}
|
|
24
26
|
return receivers;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
async send(options: any = {}) {
|
|
28
|
+
async send(options = {}) {
|
|
28
29
|
const { transaction } = options;
|
|
29
|
-
|
|
30
30
|
if (!this.service) {
|
|
31
31
|
this.service = await this.getService();
|
|
32
32
|
}
|
|
@@ -39,20 +39,20 @@ export class Notification extends Model {
|
|
|
39
39
|
console.log(receivers);
|
|
40
40
|
for (const receiver of receivers) {
|
|
41
41
|
try {
|
|
42
|
-
const response = await
|
|
42
|
+
const response = await this.service.send({
|
|
43
43
|
to: receiver,
|
|
44
44
|
subject: this.getSubject(),
|
|
45
|
-
html: this.getBody(options)
|
|
45
|
+
html: this.getBody(options)
|
|
46
46
|
});
|
|
47
47
|
await this.createLog(
|
|
48
48
|
{
|
|
49
49
|
receiver,
|
|
50
|
-
state:
|
|
51
|
-
response
|
|
50
|
+
state: "success",
|
|
51
|
+
response
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
|
-
transaction
|
|
55
|
-
}
|
|
54
|
+
transaction
|
|
55
|
+
}
|
|
56
56
|
);
|
|
57
57
|
await new Promise((resolve) => {
|
|
58
58
|
setTimeout(resolve, 100);
|
|
@@ -62,24 +62,24 @@ export class Notification extends Model {
|
|
|
62
62
|
await this.createLog(
|
|
63
63
|
{
|
|
64
64
|
receiver,
|
|
65
|
-
state:
|
|
66
|
-
response: {}
|
|
65
|
+
state: "fail",
|
|
66
|
+
response: {}
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
|
-
transaction
|
|
70
|
-
}
|
|
69
|
+
transaction
|
|
70
|
+
}
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
|
|
76
75
|
getSubject() {
|
|
77
76
|
return this.subject;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
78
|
getBody(data) {
|
|
81
|
-
const compiled =
|
|
79
|
+
const compiled = lodash__default.default.template(this.body);
|
|
82
80
|
const body = compiled(data);
|
|
83
81
|
return body;
|
|
84
82
|
}
|
|
85
83
|
}
|
|
84
|
+
|
|
85
|
+
exports.Notification = Notification;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var database = require('@nocobase/database');
|
|
4
|
+
var nodemailer = require('nodemailer');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var nodemailer__default = /*#__PURE__*/_interopDefault(nodemailer);
|
|
9
|
+
|
|
10
|
+
class NotificationService extends database.Model {
|
|
11
|
+
static createTransport = nodemailer__default.default.createTransport;
|
|
12
|
+
_transporter = null;
|
|
13
|
+
get transporter() {
|
|
14
|
+
if (this._transporter) {
|
|
15
|
+
return this._transporter;
|
|
16
|
+
}
|
|
17
|
+
return this._transporter = NotificationService.createTransport(this.options);
|
|
18
|
+
}
|
|
19
|
+
async send(options) {
|
|
20
|
+
const { from } = this.options;
|
|
21
|
+
const mailOptions = {
|
|
22
|
+
from,
|
|
23
|
+
...options
|
|
24
|
+
};
|
|
25
|
+
return this.transporter.sendMail(mailOptions);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.NotificationService = NotificationService;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Notification = require('./Notification');
|
|
4
|
+
var NotificationLog = require('./NotificationLog');
|
|
5
|
+
var NotificationService = require('./NotificationService');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.keys(Notification).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return Notification[k]; }
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
Object.keys(NotificationLog).forEach(function (k) {
|
|
16
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return NotificationLog[k]; }
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
Object.keys(NotificationService).forEach(function (k) {
|
|
22
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return NotificationService[k]; }
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var server = require('@nocobase/server');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
9
|
+
|
|
10
|
+
class PluginNotifications extends server.Plugin {
|
|
11
|
+
async load() {
|
|
12
|
+
await this.app.db.import({
|
|
13
|
+
directory: path__default.default.resolve(__dirname, "collections")
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = PluginNotifications;
|
package/package.json
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-notifications",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
|
-
"main": "./
|
|
7
|
-
"files": [
|
|
8
|
-
"lib",
|
|
9
|
-
"src",
|
|
10
|
-
"README.md",
|
|
11
|
-
"README.zh-CN.md",
|
|
12
|
-
"CHANGELOG.md",
|
|
13
|
-
"server.js",
|
|
14
|
-
"server.d.ts",
|
|
15
|
-
"client.js",
|
|
16
|
-
"client.d.ts"
|
|
17
|
-
],
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@types/nodemailer": "6.4.4",
|
|
20
|
-
"nodemailer": "^6.6.1"
|
|
21
|
-
},
|
|
6
|
+
"main": "./dist/server/index.js",
|
|
22
7
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"
|
|
25
|
-
"@nocobase/server": "0.11.1-alpha.4",
|
|
26
|
-
"@nocobase/test": "0.11.1-alpha.4",
|
|
27
|
-
"@nocobase/utils": "0.11.1-alpha.4",
|
|
8
|
+
"@types/nodemailer": "6.4.4",
|
|
9
|
+
"nodemailer": "^6.6.1",
|
|
28
10
|
"nodemailer-mock": "^1.5.11"
|
|
29
11
|
},
|
|
30
|
-
"
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@nocobase/client": "0.x",
|
|
14
|
+
"@nocobase/database": "0.x",
|
|
15
|
+
"@nocobase/server": "0.x",
|
|
16
|
+
"@nocobase/test": "0.x",
|
|
17
|
+
"@nocobase/utils": "0.x"
|
|
18
|
+
},
|
|
19
|
+
"gitHead": "543dcc0216b7b1451b552b0f685bc3e0682f9d59"
|
|
31
20
|
}
|
package/server.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export { default } from './
|
|
3
|
-
|
|
1
|
+
export * from './dist/server';
|
|
2
|
+
export { default } from './dist/server';
|
package/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|
package/lib/client/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
function _client() {
|
|
8
|
-
const data = require("@nocobase/client");
|
|
9
|
-
_client = function _client() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
|
-
class NotificationPlugin extends _client().Plugin {
|
|
17
|
-
load() {
|
|
18
|
-
return _asyncToGenerator(function* () {})();
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
var _default = NotificationPlugin;
|
|
22
|
-
exports.default = _default;
|
package/lib/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "default", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _server.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _server = _interopRequireDefault(require("./server"));
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _models = require("../models");
|
|
8
|
-
var _default = {
|
|
9
|
-
name: 'notification_logs',
|
|
10
|
-
model: _models.NotificationLog,
|
|
11
|
-
title: '通知日志',
|
|
12
|
-
fields: [{
|
|
13
|
-
title: '接收人',
|
|
14
|
-
type: 'json',
|
|
15
|
-
name: 'receiver'
|
|
16
|
-
}, {
|
|
17
|
-
title: '状态',
|
|
18
|
-
type: 'string',
|
|
19
|
-
name: 'state'
|
|
20
|
-
}, {
|
|
21
|
-
title: '详情',
|
|
22
|
-
type: 'json',
|
|
23
|
-
name: 'response'
|
|
24
|
-
}]
|
|
25
|
-
};
|
|
26
|
-
exports.default = _default;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _models = require("../models");
|
|
8
|
-
var _default = {
|
|
9
|
-
name: 'notification_services',
|
|
10
|
-
model: _models.NotificationService,
|
|
11
|
-
title: '通知服务',
|
|
12
|
-
fields: [{
|
|
13
|
-
title: '类型',
|
|
14
|
-
type: 'string',
|
|
15
|
-
name: 'type'
|
|
16
|
-
}, {
|
|
17
|
-
title: '服务名称',
|
|
18
|
-
type: 'string',
|
|
19
|
-
name: 'title'
|
|
20
|
-
}, {
|
|
21
|
-
title: '配置信息',
|
|
22
|
-
type: 'json',
|
|
23
|
-
name: 'options'
|
|
24
|
-
}]
|
|
25
|
-
};
|
|
26
|
-
exports.default = _default;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _models = require("../models");
|
|
8
|
-
var _default = {
|
|
9
|
-
name: 'notifications',
|
|
10
|
-
model: _models.Notification,
|
|
11
|
-
title: '通知',
|
|
12
|
-
fields: [{
|
|
13
|
-
type: 'uid',
|
|
14
|
-
name: 'name',
|
|
15
|
-
prefix: 'n_'
|
|
16
|
-
}, {
|
|
17
|
-
title: '主题',
|
|
18
|
-
type: 'string',
|
|
19
|
-
name: 'subject'
|
|
20
|
-
}, {
|
|
21
|
-
title: '内容',
|
|
22
|
-
type: 'text',
|
|
23
|
-
name: 'body'
|
|
24
|
-
}, {
|
|
25
|
-
title: '接收人配置',
|
|
26
|
-
type: 'json',
|
|
27
|
-
name: 'receiver_options'
|
|
28
|
-
}, {
|
|
29
|
-
title: '发送服务',
|
|
30
|
-
type: 'belongsTo',
|
|
31
|
-
name: 'service',
|
|
32
|
-
target: 'notification_services'
|
|
33
|
-
}, {
|
|
34
|
-
title: '日志',
|
|
35
|
-
type: 'hasMany',
|
|
36
|
-
name: 'logs',
|
|
37
|
-
target: 'notification_logs'
|
|
38
|
-
}]
|
|
39
|
-
};
|
|
40
|
-
exports.default = _default;
|
package/lib/server/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "default", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _server.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _server = _interopRequireDefault(require("./server"));
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Notification = void 0;
|
|
7
|
-
function _database() {
|
|
8
|
-
const data = require("@nocobase/database");
|
|
9
|
-
_database = function _database() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _utils() {
|
|
15
|
-
const data = require("@nocobase/utils");
|
|
16
|
-
_utils = function _utils() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
22
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
24
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
25
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
26
|
-
class Notification extends _database().Model {
|
|
27
|
-
get db() {
|
|
28
|
-
return this.constructor['database'];
|
|
29
|
-
}
|
|
30
|
-
getReceiversByOptions() {
|
|
31
|
-
var _this = this;
|
|
32
|
-
return _asyncToGenerator(function* () {
|
|
33
|
-
const _this$receiver_option = _this.receiver_options,
|
|
34
|
-
data = _this$receiver_option.data,
|
|
35
|
-
fromTable = _this$receiver_option.fromTable,
|
|
36
|
-
filter = _this$receiver_option.filter,
|
|
37
|
-
dataField = _this$receiver_option.dataField;
|
|
38
|
-
let receivers = [];
|
|
39
|
-
if (data) {
|
|
40
|
-
receivers = Array.isArray(data) ? data : [data];
|
|
41
|
-
} else if (fromTable) {
|
|
42
|
-
const collection = _this.db.getCollection(fromTable);
|
|
43
|
-
const rows = yield collection.repository.find({
|
|
44
|
-
filter
|
|
45
|
-
});
|
|
46
|
-
receivers = rows.map(row => row[dataField]);
|
|
47
|
-
}
|
|
48
|
-
return receivers;
|
|
49
|
-
})();
|
|
50
|
-
}
|
|
51
|
-
send(options = {}) {
|
|
52
|
-
var _this2 = this;
|
|
53
|
-
return _asyncToGenerator(function* () {
|
|
54
|
-
const transaction = options.transaction;
|
|
55
|
-
if (!_this2.service) {
|
|
56
|
-
_this2.service = yield _this2.getService();
|
|
57
|
-
}
|
|
58
|
-
const receivers = yield _this2.getReceiversByOptions();
|
|
59
|
-
let to = options.to;
|
|
60
|
-
if (to) {
|
|
61
|
-
to = Array.isArray(to) ? to : [to];
|
|
62
|
-
receivers.push(...to);
|
|
63
|
-
}
|
|
64
|
-
console.log(receivers);
|
|
65
|
-
var _iterator = _createForOfIteratorHelper(receivers),
|
|
66
|
-
_step;
|
|
67
|
-
try {
|
|
68
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
69
|
-
const receiver = _step.value;
|
|
70
|
-
try {
|
|
71
|
-
const response = yield _this2.service.send({
|
|
72
|
-
to: receiver,
|
|
73
|
-
subject: _this2.getSubject(),
|
|
74
|
-
html: _this2.getBody(options)
|
|
75
|
-
});
|
|
76
|
-
yield _this2.createLog({
|
|
77
|
-
receiver,
|
|
78
|
-
state: 'success',
|
|
79
|
-
response
|
|
80
|
-
}, {
|
|
81
|
-
transaction
|
|
82
|
-
});
|
|
83
|
-
yield new Promise(resolve => {
|
|
84
|
-
setTimeout(resolve, 100);
|
|
85
|
-
});
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error(error);
|
|
88
|
-
yield _this2.createLog({
|
|
89
|
-
receiver,
|
|
90
|
-
state: 'fail',
|
|
91
|
-
response: {}
|
|
92
|
-
}, {
|
|
93
|
-
transaction
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
} catch (err) {
|
|
98
|
-
_iterator.e(err);
|
|
99
|
-
} finally {
|
|
100
|
-
_iterator.f();
|
|
101
|
-
}
|
|
102
|
-
})();
|
|
103
|
-
}
|
|
104
|
-
getSubject() {
|
|
105
|
-
return this.subject;
|
|
106
|
-
}
|
|
107
|
-
getBody(data) {
|
|
108
|
-
const compiled = _utils().lodash.template(this.body);
|
|
109
|
-
const body = compiled(data);
|
|
110
|
-
return body;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.Notification = Notification;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.NotificationLog = void 0;
|
|
7
|
-
function _database() {
|
|
8
|
-
const data = require("@nocobase/database");
|
|
9
|
-
_database = function _database() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
class NotificationLog extends _database().Model {}
|
|
15
|
-
exports.NotificationLog = NotificationLog;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.NotificationService = void 0;
|
|
7
|
-
function _database() {
|
|
8
|
-
const data = require("@nocobase/database");
|
|
9
|
-
_database = function _database() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _nodemailer() {
|
|
15
|
-
const data = _interopRequireDefault(require("nodemailer"));
|
|
16
|
-
_nodemailer = function _nodemailer() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
24
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
26
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
27
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
28
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
29
|
-
class NotificationService extends _database().Model {
|
|
30
|
-
constructor(...args) {
|
|
31
|
-
super(...args);
|
|
32
|
-
this._transporter = null;
|
|
33
|
-
}
|
|
34
|
-
get transporter() {
|
|
35
|
-
if (this._transporter) {
|
|
36
|
-
return this._transporter;
|
|
37
|
-
}
|
|
38
|
-
return this._transporter = NotificationService.createTransport(this.options);
|
|
39
|
-
}
|
|
40
|
-
send(options) {
|
|
41
|
-
var _this = this;
|
|
42
|
-
return _asyncToGenerator(function* () {
|
|
43
|
-
const from = _this.options.from;
|
|
44
|
-
const mailOptions = _objectSpread({
|
|
45
|
-
from
|
|
46
|
-
}, options);
|
|
47
|
-
return _this.transporter.sendMail(mailOptions);
|
|
48
|
-
})();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.NotificationService = NotificationService;
|
|
52
|
-
NotificationService.createTransport = _nodemailer().default.createTransport;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _Notification = require("./Notification");
|
|
7
|
-
Object.keys(_Notification).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _Notification[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _Notification[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _NotificationLog = require("./NotificationLog");
|
|
18
|
-
Object.keys(_NotificationLog).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _NotificationLog[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _NotificationLog[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _NotificationService = require("./NotificationService");
|
|
29
|
-
Object.keys(_NotificationService).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _NotificationService[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function get() {
|
|
35
|
-
return _NotificationService[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
package/lib/server/server.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
function _server() {
|
|
8
|
-
const data = require("@nocobase/server");
|
|
9
|
-
_server = function _server() {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _path() {
|
|
15
|
-
const data = _interopRequireDefault(require("path"));
|
|
16
|
-
_path = function _path() {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
23
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
24
|
-
class PluginNotifications extends _server().Plugin {
|
|
25
|
-
load() {
|
|
26
|
-
var _this = this;
|
|
27
|
-
return _asyncToGenerator(function* () {
|
|
28
|
-
yield _this.app.db.import({
|
|
29
|
-
directory: _path().default.resolve(__dirname, 'collections')
|
|
30
|
-
});
|
|
31
|
-
})();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.default = PluginNotifications;
|
package/src/client/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './server';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import Database from '@nocobase/database';
|
|
2
|
-
import { mockServer } from '@nocobase/test';
|
|
3
|
-
import nodemailerMock from 'nodemailer-mock';
|
|
4
|
-
import { Notification, NotificationService } from '../models';
|
|
5
|
-
import plugin from '../server';
|
|
6
|
-
|
|
7
|
-
jest.setTimeout(300000);
|
|
8
|
-
|
|
9
|
-
describe('notifications', () => {
|
|
10
|
-
let db: Database;
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
const app = mockServer();
|
|
14
|
-
app.plugin(plugin);
|
|
15
|
-
await app.load();
|
|
16
|
-
db = app.db;
|
|
17
|
-
await db.sync();
|
|
18
|
-
NotificationService.createTransport = nodemailerMock.createTransport;
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => db.close());
|
|
22
|
-
|
|
23
|
-
it('create', async () => {
|
|
24
|
-
const Notification = db.getCollection('notifications');
|
|
25
|
-
const notification = (await Notification.repository.create({
|
|
26
|
-
values: {
|
|
27
|
-
subject: 'Subject',
|
|
28
|
-
body: 'hell world',
|
|
29
|
-
receiver_options: {
|
|
30
|
-
data: 'to@nocobase.com',
|
|
31
|
-
fromTable: 'users',
|
|
32
|
-
filter: {},
|
|
33
|
-
dataField: 'email',
|
|
34
|
-
},
|
|
35
|
-
service: {
|
|
36
|
-
type: 'email',
|
|
37
|
-
title: '阿里云邮件推送',
|
|
38
|
-
options: {
|
|
39
|
-
host: 'smtpdm.aliyun.com',
|
|
40
|
-
port: 465,
|
|
41
|
-
secure: true,
|
|
42
|
-
auth: {
|
|
43
|
-
user: 'from@nocobase.com',
|
|
44
|
-
pass: 'pass',
|
|
45
|
-
},
|
|
46
|
-
from: 'NocoBase<from@nocobase.com>',
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
})) as Notification;
|
|
51
|
-
await notification.send();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { CollectionOptions } from '@nocobase/database';
|
|
2
|
-
import { NotificationLog } from '../models';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
name: 'notification_logs',
|
|
6
|
-
model: NotificationLog,
|
|
7
|
-
title: '通知日志',
|
|
8
|
-
fields: [
|
|
9
|
-
{
|
|
10
|
-
title: '接收人',
|
|
11
|
-
type: 'json',
|
|
12
|
-
name: 'receiver',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
title: '状态',
|
|
16
|
-
type: 'string',
|
|
17
|
-
name: 'state',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
title: '详情',
|
|
21
|
-
type: 'json',
|
|
22
|
-
name: 'response',
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
} as CollectionOptions;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { CollectionOptions } from '@nocobase/database';
|
|
2
|
-
import { NotificationService } from '../models';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
name: 'notification_services',
|
|
6
|
-
model: NotificationService,
|
|
7
|
-
title: '通知服务',
|
|
8
|
-
fields: [
|
|
9
|
-
{
|
|
10
|
-
title: '类型',
|
|
11
|
-
type: 'string',
|
|
12
|
-
name: 'type',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
title: '服务名称',
|
|
16
|
-
type: 'string',
|
|
17
|
-
name: 'title',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
title: '配置信息',
|
|
21
|
-
type: 'json',
|
|
22
|
-
name: 'options',
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
} as CollectionOptions;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { CollectionOptions } from '@nocobase/database';
|
|
2
|
-
import { Notification } from '../models';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
name: 'notifications',
|
|
6
|
-
model: Notification,
|
|
7
|
-
title: '通知',
|
|
8
|
-
fields: [
|
|
9
|
-
{
|
|
10
|
-
type: 'uid',
|
|
11
|
-
name: 'name',
|
|
12
|
-
prefix: 'n_',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
title: '主题',
|
|
16
|
-
type: 'string',
|
|
17
|
-
name: 'subject',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
title: '内容',
|
|
21
|
-
type: 'text',
|
|
22
|
-
name: 'body',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
title: '接收人配置',
|
|
26
|
-
type: 'json',
|
|
27
|
-
name: 'receiver_options',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
title: '发送服务',
|
|
31
|
-
type: 'belongsTo',
|
|
32
|
-
name: 'service',
|
|
33
|
-
target: 'notification_services',
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
title: '日志',
|
|
37
|
-
type: 'hasMany',
|
|
38
|
-
name: 'logs',
|
|
39
|
-
target: 'notification_logs',
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
} as CollectionOptions;
|
package/src/server/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './server';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Model } from '@nocobase/database';
|
|
2
|
-
import nodemailer from 'nodemailer';
|
|
3
|
-
|
|
4
|
-
export class NotificationService extends Model {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
|
|
7
|
-
static createTransport = nodemailer.createTransport;
|
|
8
|
-
|
|
9
|
-
private _transporter = null;
|
|
10
|
-
|
|
11
|
-
get transporter() {
|
|
12
|
-
if (this._transporter) {
|
|
13
|
-
return this._transporter;
|
|
14
|
-
}
|
|
15
|
-
return (this._transporter = NotificationService.createTransport(this.options));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async send(options) {
|
|
19
|
-
const { from } = this.options;
|
|
20
|
-
const mailOptions = {
|
|
21
|
-
from,
|
|
22
|
-
...options,
|
|
23
|
-
};
|
|
24
|
-
return this.transporter.sendMail(mailOptions);
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/server/server.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|