@nocobase/plugin-notifications 0.7.0-alpha.7 → 0.7.0-alpha.72
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/lib/collections/notification_logs.js +26 -24
- package/lib/collections/notification_services.js +26 -24
- package/lib/collections/notifications.js +40 -41
- package/lib/index.js +14 -8
- package/lib/models/Notification.js +142 -89
- package/lib/models/NotificationLog.js +17 -5
- package/lib/models/NotificationService.js +66 -34
- package/lib/models/index.js +43 -15
- package/lib/server.js +49 -28
- package/package.json +3 -8
- package/esm/collections/notification_logs.d.ts +0 -3
- package/esm/collections/notification_logs.js +0 -24
- package/esm/collections/notification_logs.js.map +0 -1
- package/esm/collections/notification_services.d.ts +0 -3
- package/esm/collections/notification_services.js +0 -24
- package/esm/collections/notification_services.js.map +0 -1
- package/esm/collections/notifications.d.ts +0 -3
- package/esm/collections/notifications.js +0 -41
- package/esm/collections/notifications.js.map +0 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.js +0 -2
- package/esm/index.js.map +0 -1
- package/esm/models/Notification.d.ts +0 -9
- package/esm/models/Notification.js +0 -86
- package/esm/models/Notification.js.map +0 -1
- package/esm/models/NotificationLog.d.ts +0 -3
- package/esm/models/NotificationLog.js +0 -4
- package/esm/models/NotificationLog.js.map +0 -1
- package/esm/models/NotificationService.d.ts +0 -9
- package/esm/models/NotificationService.js +0 -32
- package/esm/models/NotificationService.js.map +0 -1
- package/esm/models/index.d.ts +0 -3
- package/esm/models/index.js +0 -4
- package/esm/models/index.js.map +0 -1
- package/esm/server.d.ts +0 -5
- package/esm/server.js +0 -24
- package/esm/server.js.map +0 -1
- package/lib/collections/notification_logs.js.map +0 -1
- package/lib/collections/notification_services.js.map +0 -1
- package/lib/collections/notifications.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/models/Notification.js.map +0 -1
- package/lib/models/NotificationLog.js.map +0 -1
- package/lib/models/NotificationService.js.map +0 -1
- package/lib/models/index.js.map +0 -1
- package/lib/server.js.map +0 -1
- package/tsconfig.build.json +0 -9
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _models = require("../models");
|
|
9
|
+
|
|
10
|
+
var _default = {
|
|
11
|
+
name: 'notification_logs',
|
|
12
|
+
model: _models.NotificationLog,
|
|
13
|
+
title: '通知日志',
|
|
14
|
+
fields: [{
|
|
15
|
+
title: '接收人',
|
|
16
|
+
type: 'json',
|
|
17
|
+
name: 'receiver'
|
|
18
|
+
}, {
|
|
19
|
+
title: '状态',
|
|
20
|
+
type: 'string',
|
|
21
|
+
name: 'state'
|
|
22
|
+
}, {
|
|
23
|
+
title: '详情',
|
|
24
|
+
type: 'json',
|
|
25
|
+
name: 'response'
|
|
26
|
+
}]
|
|
25
27
|
};
|
|
26
|
-
|
|
28
|
+
exports.default = _default;
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _models = require("../models");
|
|
9
|
+
|
|
10
|
+
var _default = {
|
|
11
|
+
name: 'notification_services',
|
|
12
|
+
model: _models.NotificationService,
|
|
13
|
+
title: '通知服务',
|
|
14
|
+
fields: [{
|
|
15
|
+
title: '类型',
|
|
16
|
+
type: 'string',
|
|
17
|
+
name: 'type'
|
|
18
|
+
}, {
|
|
19
|
+
title: '服务名称',
|
|
20
|
+
type: 'string',
|
|
21
|
+
name: 'title'
|
|
22
|
+
}, {
|
|
23
|
+
title: '配置信息',
|
|
24
|
+
type: 'json',
|
|
25
|
+
name: 'options'
|
|
26
|
+
}]
|
|
25
27
|
};
|
|
26
|
-
|
|
28
|
+
exports.default = _default;
|
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
]
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _models = require("../models");
|
|
9
|
+
|
|
10
|
+
var _default = {
|
|
11
|
+
name: 'notifications',
|
|
12
|
+
model: _models.Notification,
|
|
13
|
+
title: '通知',
|
|
14
|
+
fields: [{
|
|
15
|
+
type: 'uid',
|
|
16
|
+
name: 'name',
|
|
17
|
+
prefix: 'n_'
|
|
18
|
+
}, {
|
|
19
|
+
title: '主题',
|
|
20
|
+
type: 'string',
|
|
21
|
+
name: 'subject'
|
|
22
|
+
}, {
|
|
23
|
+
title: '内容',
|
|
24
|
+
type: 'text',
|
|
25
|
+
name: 'body'
|
|
26
|
+
}, {
|
|
27
|
+
title: '接收人配置',
|
|
28
|
+
type: 'json',
|
|
29
|
+
name: 'receiver_options'
|
|
30
|
+
}, {
|
|
31
|
+
title: '发送服务',
|
|
32
|
+
type: 'belongsTo',
|
|
33
|
+
name: 'service',
|
|
34
|
+
target: 'notification_services'
|
|
35
|
+
}, {
|
|
36
|
+
title: '日志',
|
|
37
|
+
type: 'hasMany',
|
|
38
|
+
name: 'logs',
|
|
39
|
+
target: 'notification_logs'
|
|
40
|
+
}]
|
|
42
41
|
};
|
|
43
|
-
|
|
42
|
+
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
|
|
13
|
+
var _server = _interopRequireDefault(require("./server"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,93 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
15
6
|
exports.Notification = void 0;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
yield this.createLog({
|
|
73
|
-
receiver,
|
|
74
|
-
state: 'fail',
|
|
75
|
-
response: {},
|
|
76
|
-
}, {
|
|
77
|
-
transaction,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _lodash() {
|
|
19
|
+
const data = _interopRequireDefault(require("lodash"));
|
|
20
|
+
|
|
21
|
+
_lodash = function _lodash() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
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; } } }; }
|
|
31
|
+
|
|
32
|
+
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); }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
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); } }
|
|
37
|
+
|
|
38
|
+
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); }); }; }
|
|
39
|
+
|
|
40
|
+
class Notification extends _database().Model {
|
|
41
|
+
get db() {
|
|
42
|
+
return this.constructor['database'];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getReceiversByOptions() {
|
|
46
|
+
var _this = this;
|
|
47
|
+
|
|
48
|
+
return _asyncToGenerator(function* () {
|
|
49
|
+
const _this$receiver_option = _this.receiver_options,
|
|
50
|
+
data = _this$receiver_option.data,
|
|
51
|
+
fromTable = _this$receiver_option.fromTable,
|
|
52
|
+
filter = _this$receiver_option.filter,
|
|
53
|
+
dataField = _this$receiver_option.dataField;
|
|
54
|
+
let receivers = [];
|
|
55
|
+
|
|
56
|
+
if (data) {
|
|
57
|
+
receivers = Array.isArray(data) ? data : [data];
|
|
58
|
+
} else if (fromTable) {
|
|
59
|
+
const collection = _this.db.getCollection(fromTable);
|
|
60
|
+
|
|
61
|
+
const rows = yield collection.repository.find({
|
|
62
|
+
filter
|
|
81
63
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
64
|
+
receivers = rows.map(row => row[dataField]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return receivers;
|
|
68
|
+
})();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
send(options = {}) {
|
|
72
|
+
var _this2 = this;
|
|
73
|
+
|
|
74
|
+
return _asyncToGenerator(function* () {
|
|
75
|
+
const transaction = options.transaction;
|
|
76
|
+
|
|
77
|
+
if (!_this2.service) {
|
|
78
|
+
_this2.service = yield _this2.getService();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const receivers = yield _this2.getReceiversByOptions();
|
|
82
|
+
let to = options.to;
|
|
83
|
+
|
|
84
|
+
if (to) {
|
|
85
|
+
to = Array.isArray(to) ? to : [to];
|
|
86
|
+
receivers.push(...to);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log(receivers);
|
|
90
|
+
|
|
91
|
+
var _iterator = _createForOfIteratorHelper(receivers),
|
|
92
|
+
_step;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
96
|
+
const receiver = _step.value;
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const response = yield _this2.service.send({
|
|
100
|
+
to: receiver,
|
|
101
|
+
subject: _this2.getSubject(),
|
|
102
|
+
html: _this2.getBody(options)
|
|
103
|
+
});
|
|
104
|
+
yield _this2.createLog({
|
|
105
|
+
receiver,
|
|
106
|
+
state: 'success',
|
|
107
|
+
response
|
|
108
|
+
}, {
|
|
109
|
+
transaction
|
|
110
|
+
});
|
|
111
|
+
yield new Promise(resolve => {
|
|
112
|
+
setTimeout(resolve, 100);
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error(error);
|
|
116
|
+
yield _this2.createLog({
|
|
117
|
+
receiver,
|
|
118
|
+
state: 'fail',
|
|
119
|
+
response: {}
|
|
120
|
+
}, {
|
|
121
|
+
transaction
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch (err) {
|
|
126
|
+
_iterator.e(err);
|
|
127
|
+
} finally {
|
|
128
|
+
_iterator.f();
|
|
129
|
+
}
|
|
130
|
+
})();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getSubject() {
|
|
134
|
+
return this.subject;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getBody(data) {
|
|
138
|
+
const compiled = _lodash().default.template(this.body);
|
|
139
|
+
|
|
140
|
+
const body = compiled(data);
|
|
141
|
+
return body;
|
|
142
|
+
}
|
|
143
|
+
|
|
91
144
|
}
|
|
92
|
-
|
|
93
|
-
|
|
145
|
+
|
|
146
|
+
exports.Notification = Notification;
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.NotificationLog = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
6
16
|
}
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
|
|
18
|
+
class NotificationLog extends _database().Model {}
|
|
19
|
+
|
|
20
|
+
exports.NotificationLog = NotificationLog;
|
|
@@ -1,39 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
15
6
|
exports.NotificationService = void 0;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _nodemailer() {
|
|
19
|
+
const data = _interopRequireDefault(require("nodemailer"));
|
|
20
|
+
|
|
21
|
+
_nodemailer = function _nodemailer() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
35
|
+
|
|
36
|
+
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); } }
|
|
37
|
+
|
|
38
|
+
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); }); }; }
|
|
39
|
+
|
|
40
|
+
class NotificationService extends _database().Model {
|
|
41
|
+
constructor(...args) {
|
|
42
|
+
super(...args);
|
|
43
|
+
this._transporter = null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get transporter() {
|
|
47
|
+
if (this._transporter) {
|
|
48
|
+
return this._transporter;
|
|
35
49
|
}
|
|
50
|
+
|
|
51
|
+
return this._transporter = NotificationService.createTransport(this.options);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
send(options) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
|
|
57
|
+
return _asyncToGenerator(function* () {
|
|
58
|
+
const from = _this.options.from;
|
|
59
|
+
|
|
60
|
+
const mailOptions = _objectSpread({
|
|
61
|
+
from
|
|
62
|
+
}, options);
|
|
63
|
+
|
|
64
|
+
return _this.transporter.sendMail(mailOptions);
|
|
65
|
+
})();
|
|
66
|
+
}
|
|
67
|
+
|
|
36
68
|
}
|
|
69
|
+
|
|
37
70
|
exports.NotificationService = NotificationService;
|
|
38
|
-
NotificationService.createTransport =
|
|
39
|
-
//# sourceMappingURL=NotificationService.js.map
|
|
71
|
+
NotificationService.createTransport = _nodemailer().default.createTransport;
|
package/lib/models/index.js
CHANGED
|
@@ -1,16 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _Notification = require("./Notification");
|
|
8
|
+
|
|
9
|
+
Object.keys(_Notification).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _Notification[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _Notification[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _NotificationLog = require("./NotificationLog");
|
|
21
|
+
|
|
22
|
+
Object.keys(_NotificationLog).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _NotificationLog[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _NotificationLog[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _NotificationService = require("./NotificationService");
|
|
34
|
+
|
|
35
|
+
Object.keys(_NotificationService).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _NotificationService[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function get() {
|
|
41
|
+
return _NotificationService[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
package/lib/server.js
CHANGED
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const server_1 = require("@nocobase/server");
|
|
17
|
-
class PluginNotifications extends server_1.Plugin {
|
|
18
|
-
load() {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
yield this.app.db.import({
|
|
21
|
-
directory: path_1.default.resolve(__dirname, 'collections'),
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
getName() {
|
|
26
|
-
return this.getPackageName(__dirname);
|
|
27
|
-
}
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _path() {
|
|
9
|
+
const data = _interopRequireDefault(require("path"));
|
|
10
|
+
|
|
11
|
+
_path = function _path() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
28
16
|
}
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
|
|
18
|
+
function _server() {
|
|
19
|
+
const data = require("@nocobase/server");
|
|
20
|
+
|
|
21
|
+
_server = function _server() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
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); } }
|
|
31
|
+
|
|
32
|
+
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); }); }; }
|
|
33
|
+
|
|
34
|
+
class PluginNotifications extends _server().Plugin {
|
|
35
|
+
load() {
|
|
36
|
+
var _this = this;
|
|
37
|
+
|
|
38
|
+
return _asyncToGenerator(function* () {
|
|
39
|
+
yield _this.app.db.import({
|
|
40
|
+
directory: _path().default.resolve(__dirname, 'collections')
|
|
41
|
+
});
|
|
42
|
+
})();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getName() {
|
|
46
|
+
return this.getPackageName(__dirname);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.default = PluginNotifications;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-notifications",
|
|
3
|
-
"version": "0.7.0-alpha.
|
|
3
|
+
"version": "0.7.0-alpha.72",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"licenses": [
|
|
@@ -9,18 +9,13 @@
|
|
|
9
9
|
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
|
10
10
|
}
|
|
11
11
|
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
|
|
14
|
-
"build:cjs": "tsc --project tsconfig.build.json",
|
|
15
|
-
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
|
|
16
|
-
},
|
|
17
12
|
"dependencies": {
|
|
18
13
|
"nodemailer": "^6.6.1"
|
|
19
14
|
},
|
|
20
15
|
"devDependencies": {
|
|
21
|
-
"@nocobase/test": "0.7.0-alpha.
|
|
16
|
+
"@nocobase/test": "0.7.0-alpha.72",
|
|
22
17
|
"@types/nodemailer": "6.4.4",
|
|
23
18
|
"nodemailer-mock": "^1.5.11"
|
|
24
19
|
},
|
|
25
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "db24b85879b0f911458914b49ea9644fd7eb7562"
|
|
26
21
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { NotificationLog } from '../models';
|
|
2
|
-
export default {
|
|
3
|
-
name: 'notification_logs',
|
|
4
|
-
model: NotificationLog,
|
|
5
|
-
title: '通知日志',
|
|
6
|
-
fields: [
|
|
7
|
-
{
|
|
8
|
-
title: '接收人',
|
|
9
|
-
type: 'json',
|
|
10
|
-
name: 'receiver',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
title: '状态',
|
|
14
|
-
type: 'string',
|
|
15
|
-
name: 'state',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
title: '详情',
|
|
19
|
-
type: 'json',
|
|
20
|
-
name: 'response',
|
|
21
|
-
},
|
|
22
|
-
]
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=notification_logs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notification_logs.js","sourceRoot":"","sources":["../../src/collections/notification_logs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,eAAe;IACb,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE,eAAe;IACtB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU;SACjB;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU;SACjB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\nimport { NotificationLog } from '../models';\n\nexport default {\n name: 'notification_logs',\n model: NotificationLog,\n title: '通知日志',\n fields: [\n {\n title: '接收人',\n type: 'json',\n name: 'receiver',\n },\n {\n title: '状态',\n type: 'string',\n name: 'state',\n },\n {\n title: '详情',\n type: 'json',\n name: 'response',\n },\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { NotificationService } from '../models';
|
|
2
|
-
export default {
|
|
3
|
-
name: 'notification_services',
|
|
4
|
-
model: NotificationService,
|
|
5
|
-
title: '通知服务',
|
|
6
|
-
fields: [
|
|
7
|
-
{
|
|
8
|
-
title: '类型',
|
|
9
|
-
type: 'string',
|
|
10
|
-
name: 'type',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
title: '服务名称',
|
|
14
|
-
type: 'string',
|
|
15
|
-
name: 'title',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
title: '配置信息',
|
|
19
|
-
type: 'json',
|
|
20
|
-
name: 'options',
|
|
21
|
-
},
|
|
22
|
-
]
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=notification_services.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notification_services.js","sourceRoot":"","sources":["../../src/collections/notification_services.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEhD,eAAe;IACb,IAAI,EAAE,uBAAuB;IAC7B,KAAK,EAAE,mBAAmB;IAC1B,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;QACD;YACE,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,SAAS;SAChB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\nimport { NotificationService } from '../models';\n\nexport default {\n name: 'notification_services',\n model: NotificationService,\n title: '通知服务',\n fields: [\n {\n title: '类型',\n type: 'string',\n name: 'type',\n },\n {\n title: '服务名称',\n type: 'string',\n name: 'title',\n },\n {\n title: '配置信息',\n type: 'json',\n name: 'options',\n },\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Notification } from '../models';
|
|
2
|
-
export default {
|
|
3
|
-
name: 'notifications',
|
|
4
|
-
model: Notification,
|
|
5
|
-
title: '通知',
|
|
6
|
-
fields: [
|
|
7
|
-
{
|
|
8
|
-
type: 'uid',
|
|
9
|
-
name: 'name',
|
|
10
|
-
prefix: 'n_',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
title: '主题',
|
|
14
|
-
type: 'string',
|
|
15
|
-
name: 'subject',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
title: '内容',
|
|
19
|
-
type: 'text',
|
|
20
|
-
name: 'body',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
title: '接收人配置',
|
|
24
|
-
type: 'json',
|
|
25
|
-
name: 'receiver_options',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
title: '发送服务',
|
|
29
|
-
type: 'belongsTo',
|
|
30
|
-
name: 'service',
|
|
31
|
-
target: 'notification_services',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
title: '日志',
|
|
35
|
-
type: 'hasMany',
|
|
36
|
-
name: 'logs',
|
|
37
|
-
target: 'notification_logs',
|
|
38
|
-
},
|
|
39
|
-
]
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=notifications.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.js","sourceRoot":"","sources":["../../src/collections/notifications.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,eAAe;IACb,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,IAAI;IACX,MAAM,EAAE;QACN;YACE,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,IAAI;SACb;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,SAAS;SAChB;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;SACb;QACD;YACE,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,kBAAkB;SACzB;QACD;YACE,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,uBAAuB;SAChC;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,mBAAmB;SAC5B;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\nimport { Notification } from '../models';\n\nexport default {\n name: 'notifications',\n model: Notification,\n title: '通知',\n fields: [\n {\n type: 'uid',\n name: 'name',\n prefix: 'n_',\n },\n {\n title: '主题',\n type: 'string',\n name: 'subject',\n },\n {\n title: '内容',\n type: 'text',\n name: 'body',\n },\n {\n title: '接收人配置',\n type: 'json',\n name: 'receiver_options',\n },\n {\n title: '发送服务',\n type: 'belongsTo',\n name: 'service',\n target: 'notification_services',\n },\n {\n title: '日志',\n type: 'hasMany',\n name: 'logs',\n target: 'notification_logs',\n },\n ]\n} as CollectionOptions;\n"]}
|
package/esm/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './server';
|
package/esm/index.js
DELETED
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export { default } from './server';\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import Database, { Model } from '@nocobase/database';
|
|
2
|
-
export declare class Notification extends Model {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
get db(): Database;
|
|
5
|
-
getReceiversByOptions(): Promise<any[]>;
|
|
6
|
-
send(options?: any): Promise<void>;
|
|
7
|
-
getSubject(): any;
|
|
8
|
-
getBody(data: any): string;
|
|
9
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Model } from '@nocobase/database';
|
|
11
|
-
import _ from 'lodash';
|
|
12
|
-
export class Notification extends Model {
|
|
13
|
-
get db() {
|
|
14
|
-
return this.constructor['database'];
|
|
15
|
-
}
|
|
16
|
-
getReceiversByOptions() {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const { data, fromTable, filter, dataField } = this.receiver_options;
|
|
19
|
-
let receivers = [];
|
|
20
|
-
if (data) {
|
|
21
|
-
receivers = Array.isArray(data) ? data : [data];
|
|
22
|
-
}
|
|
23
|
-
else if (fromTable) {
|
|
24
|
-
const collection = this.db.getCollection(fromTable);
|
|
25
|
-
const rows = yield collection.repository.find({
|
|
26
|
-
filter,
|
|
27
|
-
});
|
|
28
|
-
receivers = rows.map((row) => row[dataField]);
|
|
29
|
-
}
|
|
30
|
-
return receivers;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
send(options = {}) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const { transaction } = options;
|
|
36
|
-
if (!this.service) {
|
|
37
|
-
this.service = yield this.getService();
|
|
38
|
-
}
|
|
39
|
-
const receivers = yield this.getReceiversByOptions();
|
|
40
|
-
let { to } = options;
|
|
41
|
-
if (to) {
|
|
42
|
-
to = Array.isArray(to) ? to : [to];
|
|
43
|
-
receivers.push(...to);
|
|
44
|
-
}
|
|
45
|
-
console.log(receivers);
|
|
46
|
-
for (const receiver of receivers) {
|
|
47
|
-
try {
|
|
48
|
-
const response = yield this.service.send({
|
|
49
|
-
to: receiver,
|
|
50
|
-
subject: this.getSubject(),
|
|
51
|
-
html: this.getBody(options),
|
|
52
|
-
});
|
|
53
|
-
yield this.createLog({
|
|
54
|
-
receiver,
|
|
55
|
-
state: 'success',
|
|
56
|
-
response,
|
|
57
|
-
}, {
|
|
58
|
-
transaction,
|
|
59
|
-
});
|
|
60
|
-
yield new Promise((resolve) => {
|
|
61
|
-
setTimeout(resolve, 100);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
console.error(error);
|
|
66
|
-
yield this.createLog({
|
|
67
|
-
receiver,
|
|
68
|
-
state: 'fail',
|
|
69
|
-
response: {},
|
|
70
|
-
}, {
|
|
71
|
-
transaction,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
getSubject() {
|
|
78
|
-
return this.subject;
|
|
79
|
-
}
|
|
80
|
-
getBody(data) {
|
|
81
|
-
const compiled = _.template(this.body);
|
|
82
|
-
const body = compiled(data);
|
|
83
|
-
return body;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=Notification.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Notification.js","sourceRoot":"","sources":["../../src/models/Notification.ts"],"names":[],"mappings":"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","sourcesContent":["import Database, { Model } from '@nocobase/database';\nimport { NotificationService } from './NotificationService';\nimport _ from 'lodash';\n\nexport class Notification extends Model {\n [key: string]: any;\n\n get db(): Database {\n return this.constructor['database'];\n }\n\n async getReceiversByOptions(): Promise<any[]> {\n const { data, fromTable, filter, dataField } = this.receiver_options;\n let receivers = [];\n if (data) {\n receivers = Array.isArray(data) ? data : [data];\n } else if (fromTable) {\n const collection = this.db.getCollection(fromTable);\n const rows = await collection.repository.find({\n filter,\n });\n receivers = rows.map((row) => row[dataField]);\n }\n return receivers;\n }\n\n async send(options: any = {}) {\n const { transaction } = options;\n\n if (!this.service) {\n this.service = await this.getService();\n }\n const receivers = await this.getReceiversByOptions();\n let { to } = options;\n if (to) {\n to = Array.isArray(to) ? to : [to];\n receivers.push(...to);\n }\n console.log(receivers);\n for (const receiver of receivers) {\n try {\n const response = await (this.service as NotificationService).send({\n to: receiver,\n subject: this.getSubject(),\n html: this.getBody(options),\n });\n await this.createLog(\n {\n receiver,\n state: 'success',\n response,\n },\n {\n transaction,\n },\n );\n await new Promise((resolve) => {\n setTimeout(resolve, 100);\n });\n } catch (error) {\n console.error(error);\n await this.createLog(\n {\n receiver,\n state: 'fail',\n response: {},\n },\n {\n transaction,\n },\n );\n }\n }\n }\n\n getSubject() {\n return this.subject;\n }\n\n getBody(data) {\n const compiled = _.template(this.body);\n const body = compiled(data);\n return body;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationLog.js","sourceRoot":"","sources":["../../src/models/NotificationLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAEzC","sourcesContent":["import { Model } from '@nocobase/database';\n\nexport class NotificationLog extends Model {\n\n}\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Model } from '@nocobase/database';
|
|
2
|
-
import nodemailer from 'nodemailer';
|
|
3
|
-
export declare class NotificationService extends Model {
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
static createTransport: typeof nodemailer.createTransport;
|
|
6
|
-
private _transporter;
|
|
7
|
-
get transporter(): any;
|
|
8
|
-
send(options: any): Promise<any>;
|
|
9
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Model } from '@nocobase/database';
|
|
11
|
-
import nodemailer from 'nodemailer';
|
|
12
|
-
export class NotificationService extends Model {
|
|
13
|
-
constructor() {
|
|
14
|
-
super(...arguments);
|
|
15
|
-
this._transporter = null;
|
|
16
|
-
}
|
|
17
|
-
get transporter() {
|
|
18
|
-
if (this._transporter) {
|
|
19
|
-
return this._transporter;
|
|
20
|
-
}
|
|
21
|
-
return this._transporter = NotificationService.createTransport(this.options);
|
|
22
|
-
}
|
|
23
|
-
send(options) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const { from } = this.options;
|
|
26
|
-
const mailOptions = Object.assign({ from }, options);
|
|
27
|
-
return this.transporter.sendMail(mailOptions);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
NotificationService.createTransport = nodemailer.createTransport;
|
|
32
|
-
//# sourceMappingURL=NotificationService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationService.js","sourceRoot":"","sources":["../../src/models/NotificationService.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAA9C;;QAKU,iBAAY,GAAG,IAAI,CAAC;IAiB9B,CAAC;IAfC,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;QACD,OAAO,IAAI,CAAC,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/E,CAAC;IAEK,IAAI,CAAC,OAAO;;YAChB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YAC9B,MAAM,WAAW,mBACf,IAAI,IACD,OAAO,CACX,CAAC;YACF,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC;KAAA;;AAlBM,mCAAe,GAAG,UAAU,CAAC,eAAe,CAAC","sourcesContent":["import { Model } from '@nocobase/database';\nimport nodemailer from 'nodemailer';\n\nexport class NotificationService extends Model {\n [key: string]: any;\n\n static createTransport = nodemailer.createTransport;\n\n private _transporter = null;\n\n get transporter() {\n if (this._transporter) {\n return this._transporter;\n }\n return this._transporter = NotificationService.createTransport(this.options);\n }\n\n async send(options) {\n const { from } = this.options;\n const mailOptions = {\n from,\n ...options,\n };\n return this.transporter.sendMail(mailOptions);\n }\n}\n"]}
|
package/esm/models/index.d.ts
DELETED
package/esm/models/index.js
DELETED
package/esm/models/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './Notification';\nexport * from './NotificationLog';\nexport * from './NotificationService';\n"]}
|
package/esm/server.d.ts
DELETED
package/esm/server.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import { Plugin } from '@nocobase/server';
|
|
12
|
-
export default class PluginNotifications extends Plugin {
|
|
13
|
-
load() {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
yield this.app.db.import({
|
|
16
|
-
directory: path.resolve(__dirname, 'collections'),
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
getName() {
|
|
21
|
-
return this.getPackageName(__dirname);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=server.js.map
|
package/esm/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,MAAM;IAC/C,IAAI;;YACR,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC;gBACvB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;aAClD,CAAC,CAAC;QACL,CAAC;KAAA;IAED,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import path from 'path';\nimport { Plugin } from '@nocobase/server';\n\nexport default class PluginNotifications extends Plugin {\n async load() {\n await this.app.db.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n }\n\n getName(): string {\n return this.getPackageName(__dirname);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notification_logs.js","sourceRoot":"","sources":["../../src/collections/notification_logs.ts"],"names":[],"mappings":";;AACA,sCAA4C;AAE5C,kBAAe;IACb,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE,wBAAe;IACtB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU;SACjB;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU;SACjB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\nimport { NotificationLog } from '../models';\n\nexport default {\n name: 'notification_logs',\n model: NotificationLog,\n title: '通知日志',\n fields: [\n {\n title: '接收人',\n type: 'json',\n name: 'receiver',\n },\n {\n title: '状态',\n type: 'string',\n name: 'state',\n },\n {\n title: '详情',\n type: 'json',\n name: 'response',\n },\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notification_services.js","sourceRoot":"","sources":["../../src/collections/notification_services.ts"],"names":[],"mappings":";;AACA,sCAAgD;AAEhD,kBAAe;IACb,IAAI,EAAE,uBAAuB;IAC7B,KAAK,EAAE,4BAAmB;IAC1B,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;QACD;YACE,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;SACd;QACD;YACE,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,SAAS;SAChB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\nimport { NotificationService } from '../models';\n\nexport default {\n name: 'notification_services',\n model: NotificationService,\n title: '通知服务',\n fields: [\n {\n title: '类型',\n type: 'string',\n name: 'type',\n },\n {\n title: '服务名称',\n type: 'string',\n name: 'title',\n },\n {\n title: '配置信息',\n type: 'json',\n name: 'options',\n },\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.js","sourceRoot":"","sources":["../../src/collections/notifications.ts"],"names":[],"mappings":";;AACA,sCAAyC;AAEzC,kBAAe;IACb,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,qBAAY;IACnB,KAAK,EAAE,IAAI;IACX,MAAM,EAAE;QACN;YACE,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,IAAI;SACb;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,SAAS;SAChB;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,MAAM;SACb;QACD;YACE,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,kBAAkB;SACzB;QACD;YACE,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,uBAAuB;SAChC;QACD;YACE,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,mBAAmB;SAC5B;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\nimport { Notification } from '../models';\n\nexport default {\n name: 'notifications',\n model: Notification,\n title: '通知',\n fields: [\n {\n type: 'uid',\n name: 'name',\n prefix: 'n_',\n },\n {\n title: '主题',\n type: 'string',\n name: 'subject',\n },\n {\n title: '内容',\n type: 'text',\n name: 'body',\n },\n {\n title: '接收人配置',\n type: 'json',\n name: 'receiver_options',\n },\n {\n title: '发送服务',\n type: 'belongsTo',\n name: 'service',\n target: 'notification_services',\n },\n {\n title: '日志',\n type: 'hasMany',\n name: 'logs',\n target: 'notification_logs',\n },\n ]\n} as CollectionOptions;\n"]}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AAA1B,kHAAA,OAAO,OAAA","sourcesContent":["export { default } from './server';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Notification.js","sourceRoot":"","sources":["../../src/models/Notification.ts"],"names":[],"mappings":"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","sourcesContent":["import Database, { Model } from '@nocobase/database';\nimport { NotificationService } from './NotificationService';\nimport _ from 'lodash';\n\nexport class Notification extends Model {\n [key: string]: any;\n\n get db(): Database {\n return this.constructor['database'];\n }\n\n async getReceiversByOptions(): Promise<any[]> {\n const { data, fromTable, filter, dataField } = this.receiver_options;\n let receivers = [];\n if (data) {\n receivers = Array.isArray(data) ? data : [data];\n } else if (fromTable) {\n const collection = this.db.getCollection(fromTable);\n const rows = await collection.repository.find({\n filter,\n });\n receivers = rows.map((row) => row[dataField]);\n }\n return receivers;\n }\n\n async send(options: any = {}) {\n const { transaction } = options;\n\n if (!this.service) {\n this.service = await this.getService();\n }\n const receivers = await this.getReceiversByOptions();\n let { to } = options;\n if (to) {\n to = Array.isArray(to) ? to : [to];\n receivers.push(...to);\n }\n console.log(receivers);\n for (const receiver of receivers) {\n try {\n const response = await (this.service as NotificationService).send({\n to: receiver,\n subject: this.getSubject(),\n html: this.getBody(options),\n });\n await this.createLog(\n {\n receiver,\n state: 'success',\n response,\n },\n {\n transaction,\n },\n );\n await new Promise((resolve) => {\n setTimeout(resolve, 100);\n });\n } catch (error) {\n console.error(error);\n await this.createLog(\n {\n receiver,\n state: 'fail',\n response: {},\n },\n {\n transaction,\n },\n );\n }\n }\n }\n\n getSubject() {\n return this.subject;\n }\n\n getBody(data) {\n const compiled = _.template(this.body);\n const body = compiled(data);\n return body;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationLog.js","sourceRoot":"","sources":["../../src/models/NotificationLog.ts"],"names":[],"mappings":";;;AAAA,iDAA2C;AAE3C,MAAa,eAAgB,SAAQ,gBAAK;CAEzC;AAFD,0CAEC","sourcesContent":["import { Model } from '@nocobase/database';\n\nexport class NotificationLog extends Model {\n\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationService.js","sourceRoot":"","sources":["../../src/models/NotificationService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAA2C;AAC3C,4DAAoC;AAEpC,MAAa,mBAAoB,SAAQ,gBAAK;IAA9C;;QAKU,iBAAY,GAAG,IAAI,CAAC;IAiB9B,CAAC;IAfC,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;QACD,OAAO,IAAI,CAAC,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/E,CAAC;IAEK,IAAI,CAAC,OAAO;;YAChB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YAC9B,MAAM,WAAW,mBACf,IAAI,IACD,OAAO,CACX,CAAC;YACF,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC;KAAA;;AArBH,kDAsBC;AAnBQ,mCAAe,GAAG,oBAAU,CAAC,eAAe,CAAC","sourcesContent":["import { Model } from '@nocobase/database';\nimport nodemailer from 'nodemailer';\n\nexport class NotificationService extends Model {\n [key: string]: any;\n\n static createTransport = nodemailer.createTransport;\n\n private _transporter = null;\n\n get transporter() {\n if (this._transporter) {\n return this._transporter;\n }\n return this._transporter = NotificationService.createTransport(this.options);\n }\n\n async send(options) {\n const { from } = this.options;\n const mailOptions = {\n from,\n ...options,\n };\n return this.transporter.sendMail(mailOptions);\n }\n}\n"]}
|
package/lib/models/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B;AAC/B,oDAAkC;AAClC,wDAAsC","sourcesContent":["export * from './Notification';\nexport * from './NotificationLog';\nexport * from './NotificationService';\n"]}
|
package/lib/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,6CAA0C;AAE1C,MAAqB,mBAAoB,SAAQ,eAAM;IAC/C,IAAI;;YACR,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC;gBACvB,SAAS,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;aAClD,CAAC,CAAC;QACL,CAAC;KAAA;IAED,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF;AAVD,sCAUC","sourcesContent":["import path from 'path';\nimport { Plugin } from '@nocobase/server';\n\nexport default class PluginNotifications extends Plugin {\n async load() {\n await this.app.db.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n }\n\n getName(): string {\n return this.getPackageName(__dirname);\n }\n}\n"]}
|
package/tsconfig.build.json
DELETED