@nocobase/plugin-notifications 0.5.0-alpha.16 → 0.5.0-alpha.17

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.
Files changed (33) hide show
  1. package/lib/collections/notification_logs.d.ts +3 -0
  2. package/lib/collections/notification_logs.d.ts.map +1 -0
  3. package/lib/collections/notification_logs.js +36 -0
  4. package/lib/collections/notification_logs.js.map +1 -0
  5. package/lib/collections/notification_services.d.ts +3 -0
  6. package/lib/collections/notification_services.d.ts.map +1 -0
  7. package/lib/collections/notification_services.js +36 -0
  8. package/lib/collections/notification_services.js.map +1 -0
  9. package/lib/collections/notifications.d.ts +3 -0
  10. package/lib/collections/notifications.d.ts.map +1 -0
  11. package/lib/collections/notifications.js +50 -0
  12. package/lib/collections/notifications.js.map +1 -0
  13. package/lib/models/Notification.d.ts +7 -0
  14. package/lib/models/Notification.d.ts.map +1 -0
  15. package/lib/models/Notification.js +159 -0
  16. package/lib/models/Notification.js.map +1 -0
  17. package/lib/models/NotificationLog.d.ts +3 -0
  18. package/lib/models/NotificationLog.d.ts.map +1 -0
  19. package/lib/models/NotificationLog.js +25 -0
  20. package/lib/models/NotificationLog.js.map +1 -0
  21. package/lib/models/NotificationService.d.ts +6 -0
  22. package/lib/models/NotificationService.d.ts.map +1 -0
  23. package/lib/models/NotificationService.js +88 -0
  24. package/lib/models/NotificationService.js.map +1 -0
  25. package/lib/models/index.d.ts +3 -0
  26. package/lib/models/index.d.ts.map +1 -0
  27. package/lib/models/index.js +41 -0
  28. package/lib/models/index.js.map +1 -0
  29. package/lib/server.d.ts +3 -0
  30. package/lib/server.d.ts.map +1 -0
  31. package/lib/server.js +108 -0
  32. package/lib/server.js.map +1 -0
  33. package/package.json +3 -3
@@ -0,0 +1,3 @@
1
+ import { TableOptions } from '@nocobase/database';
2
+ declare const _default: TableOptions;
3
+ export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["collections/notification_logs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;;AAElD,wBAqBkB","file":"notification_logs.d.ts","sourcesContent":["import { TableOptions } from '@nocobase/database';\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 TableOptions;\n"]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ Object.defineProperty(exports, "__esModule", {
16
+ value: true
17
+ });
18
+ exports.default = {
19
+ name: 'notification_logs',
20
+ model: 'NotificationLog',
21
+ title: '通知日志',
22
+ fields: [{
23
+ title: '接收人',
24
+ type: 'json',
25
+ name: 'receiver'
26
+ }, {
27
+ title: '状态',
28
+ type: 'string',
29
+ name: 'state'
30
+ }, {
31
+ title: '详情',
32
+ type: 'json',
33
+ name: 'response'
34
+ }]
35
+ };
36
+ //# sourceMappingURL=notification_logs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["collections/notification_logs.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE,iBAAiB;IACxB,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;CACc,CAAC","file":"notification_logs.js","sourcesContent":["import { TableOptions } from '@nocobase/database';\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 TableOptions;\n"]}
@@ -0,0 +1,3 @@
1
+ import { TableOptions } from '@nocobase/database';
2
+ declare const _default: TableOptions;
3
+ export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["collections/notification_services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;;AAElD,wBAqBkB","file":"notification_services.d.ts","sourcesContent":["import { TableOptions } from '@nocobase/database';\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 TableOptions;\n"]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ Object.defineProperty(exports, "__esModule", {
16
+ value: true
17
+ });
18
+ exports.default = {
19
+ name: 'notification_services',
20
+ model: 'NotificationService',
21
+ title: '通知服务',
22
+ fields: [{
23
+ title: '类型',
24
+ type: 'string',
25
+ name: 'type'
26
+ }, {
27
+ title: '服务名称',
28
+ type: 'string',
29
+ name: 'title'
30
+ }, {
31
+ title: '配置信息',
32
+ type: 'json',
33
+ name: 'options'
34
+ }]
35
+ };
36
+ //# sourceMappingURL=notification_services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["collections/notification_services.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,uBAAuB;IAC7B,KAAK,EAAE,qBAAqB;IAC5B,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;CACc,CAAC","file":"notification_services.js","sourcesContent":["import { TableOptions } from '@nocobase/database';\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 TableOptions;\n"]}
@@ -0,0 +1,3 @@
1
+ import { TableOptions } from '@nocobase/database';
2
+ declare const _default: TableOptions;
3
+ export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["collections/notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;;AAElD,wBAsCkB","file":"notifications.d.ts","sourcesContent":["import { TableOptions } from '@nocobase/database';\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 TableOptions;\n"]}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ Object.defineProperty(exports, "__esModule", {
16
+ value: true
17
+ });
18
+ exports.default = {
19
+ name: 'notifications',
20
+ model: 'Notification',
21
+ title: '通知',
22
+ fields: [{
23
+ type: 'uid',
24
+ name: 'name',
25
+ prefix: 'n_'
26
+ }, {
27
+ title: '主题',
28
+ type: 'string',
29
+ name: 'subject'
30
+ }, {
31
+ title: '内容',
32
+ type: 'text',
33
+ name: 'body'
34
+ }, {
35
+ title: '接收人配置',
36
+ type: 'json',
37
+ name: 'receiver_options'
38
+ }, {
39
+ title: '发送服务',
40
+ type: 'belongsTo',
41
+ name: 'service',
42
+ target: 'notification_services'
43
+ }, {
44
+ title: '日志',
45
+ type: 'hasMany',
46
+ name: 'logs',
47
+ target: 'notification_logs'
48
+ }]
49
+ };
50
+ //# sourceMappingURL=notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["collections/notifications.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,cAAc;IACrB,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;CACc,CAAC","file":"notifications.js","sourcesContent":["import { TableOptions } from '@nocobase/database';\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 TableOptions;\n"]}
@@ -0,0 +1,7 @@
1
+ import { Model } from '@nocobase/database';
2
+ export declare class Notification extends Model {
3
+ getReceiversByOptions(): Promise<any[]>;
4
+ send(options?: any): Promise<void>;
5
+ getSubject(): any;
6
+ getBody(data: any): string;
7
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/Notification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI3C,qBAAa,YAAa,SAAQ,KAAK;IAE/B,qBAAqB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAevC,IAAI,CAAC,OAAO,GAAE,GAAQ;IAqC5B,UAAU;IAIV,OAAO,CAAC,IAAI,KAAA;CAKb","file":"Notification.d.ts","sourcesContent":["import { Model } from '@nocobase/database';\nimport { NotificationService } from './NotificationService';\nimport _ from 'lodash';\n\nexport class Notification extends Model {\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 M = this.database.getModel(fromTable);\n const rows = await M.findAll(M.parseApiJson2({\n filter,\n }));\n receivers = rows.map(row => row[dataField]);\n }\n return receivers;\n }\n\n async send(options: any = {}) {\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 receiver,\n state: 'success',\n response,\n });\n await new Promise((resolve) => {\n setTimeout(resolve, 100);\n });\n } catch (error) {\n console.error(error);\n await this.createLog({\n receiver,\n state: 'fail',\n response: {},\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"]}
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ 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; } } }; }
16
+
17
+ 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); }
18
+
19
+ 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; }
20
+
21
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) {
23
+ return value instanceof P ? value : new P(function (resolve) {
24
+ resolve(value);
25
+ });
26
+ }
27
+
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) {
30
+ try {
31
+ step(generator.next(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ }
36
+
37
+ function rejected(value) {
38
+ try {
39
+ step(generator["throw"](value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ }
44
+
45
+ function step(result) {
46
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
47
+ }
48
+
49
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
50
+ });
51
+ };
52
+
53
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
54
+ return mod && mod.__esModule ? mod : {
55
+ "default": mod
56
+ };
57
+ };
58
+
59
+ Object.defineProperty(exports, "__esModule", {
60
+ value: true
61
+ });
62
+ exports.Notification = void 0;
63
+
64
+ const database_1 = require("@nocobase/database");
65
+
66
+ const lodash_1 = __importDefault(require("lodash"));
67
+
68
+ class Notification extends database_1.Model {
69
+ getReceiversByOptions() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const _this$receiver_option = this.receiver_options,
72
+ data = _this$receiver_option.data,
73
+ fromTable = _this$receiver_option.fromTable,
74
+ filter = _this$receiver_option.filter,
75
+ dataField = _this$receiver_option.dataField;
76
+ let receivers = [];
77
+
78
+ if (data) {
79
+ receivers = Array.isArray(data) ? data : [data];
80
+ } else if (fromTable) {
81
+ const M = this.database.getModel(fromTable);
82
+ const rows = yield M.findAll(M.parseApiJson2({
83
+ filter
84
+ }));
85
+ receivers = rows.map(row => row[dataField]);
86
+ }
87
+
88
+ return receivers;
89
+ });
90
+ }
91
+
92
+ send(options = {}) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ if (!this.service) {
95
+ this.service = yield this.getService();
96
+ }
97
+
98
+ const receivers = yield this.getReceiversByOptions();
99
+ let to = options.to;
100
+
101
+ if (to) {
102
+ to = Array.isArray(to) ? to : [to];
103
+ receivers.push(...to);
104
+ }
105
+
106
+ console.log(receivers);
107
+
108
+ var _iterator = _createForOfIteratorHelper(receivers),
109
+ _step;
110
+
111
+ try {
112
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
113
+ const receiver = _step.value;
114
+
115
+ try {
116
+ const response = yield this.service.send({
117
+ to: receiver,
118
+ subject: this.getSubject(),
119
+ html: this.getBody(options)
120
+ });
121
+ yield this.createLog({
122
+ receiver,
123
+ state: 'success',
124
+ response
125
+ });
126
+ yield new Promise(resolve => {
127
+ setTimeout(resolve, 100);
128
+ });
129
+ } catch (error) {
130
+ console.error(error);
131
+ yield this.createLog({
132
+ receiver,
133
+ state: 'fail',
134
+ response: {}
135
+ });
136
+ }
137
+ }
138
+ } catch (err) {
139
+ _iterator.e(err);
140
+ } finally {
141
+ _iterator.f();
142
+ }
143
+ });
144
+ }
145
+
146
+ getSubject() {
147
+ return this.subject;
148
+ }
149
+
150
+ getBody(data) {
151
+ const compiled = lodash_1.default.template(this.body);
152
+ const body = compiled(data);
153
+ return body;
154
+ }
155
+
156
+ }
157
+
158
+ exports.Notification = Notification;
159
+ //# sourceMappingURL=Notification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/Notification.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAA2C;AAE3C,oDAAuB;AAEvB,MAAa,YAAa,SAAQ,gBAAK;IAE/B,qBAAqB;;YACzB,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC;YACrE,IAAI,SAAS,GAAG,EAAE,CAAC;YACnB,IAAI,IAAI,EAAE;gBACR,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aACjD;iBAAM,IAAI,SAAS,EAAE;gBACpB,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;gBAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;oBAC3C,MAAM;iBACP,CAAC,CAAC,CAAC;gBACJ,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;aAC7C;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;IAEK,IAAI,CAAC,UAAe,EAAE;;YAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACjB,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;aACxC;YACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;YACrD,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;YACrB,IAAI,EAAE,EAAE;gBACN,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACnC,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;aACvB;YACD,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YACtB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;gBAChC,IAAI;oBACF,MAAM,QAAQ,GAAG,MAAO,IAAI,CAAC,OAA+B,CAAC,IAAI,CAAC;wBAChE,EAAE,EAAE,QAAQ;wBACZ,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;wBAC1B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;qBAC5B,CAAC,CAAC;oBACH,MAAM,IAAI,CAAC,SAAS,CAAC;wBACnB,QAAQ;wBACR,KAAK,EAAE,SAAS;wBAChB,QAAQ;qBACT,CAAC,CAAC;oBACH,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;wBAC5B,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;oBAC3B,CAAC,CAAC,CAAC;iBACJ;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACrB,MAAM,IAAI,CAAC,SAAS,CAAC;wBACnB,QAAQ;wBACR,KAAK,EAAE,MAAM;wBACb,QAAQ,EAAE,EAAE;qBACb,CAAC,CAAC;iBACJ;aACF;QACH,CAAC;KAAA;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,OAAO,CAAC,IAAI;QACV,MAAM,QAAQ,GAAG,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/DD,oCA+DC","file":"Notification.js","sourcesContent":["import { Model } from '@nocobase/database';\nimport { NotificationService } from './NotificationService';\nimport _ from 'lodash';\n\nexport class Notification extends Model {\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 M = this.database.getModel(fromTable);\n const rows = await M.findAll(M.parseApiJson2({\n filter,\n }));\n receivers = rows.map(row => row[dataField]);\n }\n return receivers;\n }\n\n async send(options: any = {}) {\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 receiver,\n state: 'success',\n response,\n });\n await new Promise((resolve) => {\n setTimeout(resolve, 100);\n });\n } catch (error) {\n console.error(error);\n await this.createLog({\n receiver,\n state: 'fail',\n response: {},\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"]}
@@ -0,0 +1,3 @@
1
+ import { Model } from '@nocobase/database';
2
+ export declare class NotificationLog extends Model {
3
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/NotificationLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,qBAAa,eAAgB,SAAQ,KAAK;CAEzC","file":"NotificationLog.d.ts","sourcesContent":["import { Model } from '@nocobase/database';\n\nexport class NotificationLog extends Model {\n\n}\n"]}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ Object.defineProperty(exports, "__esModule", {
16
+ value: true
17
+ });
18
+ exports.NotificationLog = void 0;
19
+
20
+ const database_1 = require("@nocobase/database");
21
+
22
+ class NotificationLog extends database_1.Model {}
23
+
24
+ exports.NotificationLog = NotificationLog;
25
+ //# sourceMappingURL=NotificationLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/NotificationLog.ts"],"names":[],"mappings":";;;AAAA,iDAA2C;AAE3C,MAAa,eAAgB,SAAQ,gBAAK;CAEzC;AAFD,0CAEC","file":"NotificationLog.js","sourcesContent":["import { Model } from '@nocobase/database';\n\nexport class NotificationLog extends Model {\n\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { Model } from '@nocobase/database';
2
+ export declare class NotificationService extends Model {
3
+ static createTransport: any;
4
+ get transporter(): any;
5
+ send(options: any): Promise<any>;
6
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/NotificationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,qBAAa,mBAAoB,SAAQ,KAAK;IAE5C,MAAM,CAAC,eAAe,MAA8B;IAEpD,IAAI,WAAW,QAKd;IAEK,IAAI,CAAC,OAAO,KAAA;CASnB","file":"NotificationService.d.ts","sourcesContent":["import { Model } from '@nocobase/database';\nimport nodemailer from 'nodemailer';\n\nexport class NotificationService extends Model {\n\n static createTransport = nodemailer.createTransport;\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 console.log({ mailOptions });\n return this.transporter.sendMail(mailOptions);\n }\n}\n"]}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
16
+ function adopt(value) {
17
+ return value instanceof P ? value : new P(function (resolve) {
18
+ resolve(value);
19
+ });
20
+ }
21
+
22
+ return new (P || (P = Promise))(function (resolve, reject) {
23
+ function fulfilled(value) {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ }
30
+
31
+ function rejected(value) {
32
+ try {
33
+ step(generator["throw"](value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ }
38
+
39
+ function step(result) {
40
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
41
+ }
42
+
43
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
44
+ });
45
+ };
46
+
47
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
48
+ return mod && mod.__esModule ? mod : {
49
+ "default": mod
50
+ };
51
+ };
52
+
53
+ Object.defineProperty(exports, "__esModule", {
54
+ value: true
55
+ });
56
+ exports.NotificationService = void 0;
57
+
58
+ const database_1 = require("@nocobase/database");
59
+
60
+ const nodemailer_1 = __importDefault(require("nodemailer"));
61
+
62
+ class NotificationService extends database_1.Model {
63
+ get transporter() {
64
+ if (this._transporter) {
65
+ return this._transporter;
66
+ }
67
+
68
+ return this._transporter = NotificationService.createTransport(this.options);
69
+ }
70
+
71
+ send(options) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const from = this.options.from;
74
+ const mailOptions = Object.assign({
75
+ from
76
+ }, options);
77
+ console.log({
78
+ mailOptions
79
+ });
80
+ return this.transporter.sendMail(mailOptions);
81
+ });
82
+ }
83
+
84
+ }
85
+
86
+ exports.NotificationService = NotificationService;
87
+ NotificationService.createTransport = nodemailer_1.default.createTransport;
88
+ //# sourceMappingURL=NotificationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/NotificationService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iDAA2C;AAC3C,4DAAoC;AAEpC,MAAa,mBAAoB,SAAQ,gBAAK;IAI5C,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,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC;KAAA;;AAnBH,kDAoBC;AAlBQ,mCAAe,GAAG,oBAAU,CAAC,eAAe,CAAC","file":"NotificationService.js","sourcesContent":["import { Model } from '@nocobase/database';\nimport nodemailer from 'nodemailer';\n\nexport class NotificationService extends Model {\n\n static createTransport = nodemailer.createTransport;\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 console.log({ mailOptions });\n return this.transporter.sendMail(mailOptions);\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './Notification';
2
+ export * from './NotificationLog';
3
+ export * from './NotificationService';
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC","file":"index.d.ts","sourcesContent":["export * from './Notification';\nexport * from './NotificationLog';\nexport * from './NotificationService';\n"]}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ Object.defineProperty(o, k2, {
18
+ enumerable: true,
19
+ get: function get() {
20
+ return m[k];
21
+ }
22
+ });
23
+ } : function (o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ });
27
+
28
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+
32
+ Object.defineProperty(exports, "__esModule", {
33
+ value: true
34
+ });
35
+
36
+ __exportStar(require("./Notification"), exports);
37
+
38
+ __exportStar(require("./NotificationLog"), exports);
39
+
40
+ __exportStar(require("./NotificationService"), exports);
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B;AAC/B,oDAAkC;AAClC,wDAAsC","file":"index.js","sourcesContent":["export * from './Notification';\nexport * from './NotificationLog';\nexport * from './NotificationService';\n"]}
@@ -0,0 +1,3 @@
1
+ import { PluginOptions } from '@nocobase/server';
2
+ declare const _default: PluginOptions;
3
+ export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;;AAKjD,wBAOkB","file":"server.d.ts","sourcesContent":["import path from 'path';\nimport Database, { registerModels } from '@nocobase/database';\nimport { PluginOptions } from '@nocobase/server';\nimport * as models from './models';\n\nregisterModels(models);\n\nexport default {\n name: 'notifications',\n async load() {\n this.app.db.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n }\n} as PluginOptions\n"]}
package/lib/server.js ADDED
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ function _react() {
4
+ const data = _interopRequireDefault(require("react"));
5
+
6
+ _react = function _react() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ Object.defineProperty(o, k2, {
18
+ enumerable: true,
19
+ get: function get() {
20
+ return m[k];
21
+ }
22
+ });
23
+ } : function (o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ });
27
+
28
+ var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
29
+ Object.defineProperty(o, "default", {
30
+ enumerable: true,
31
+ value: v
32
+ });
33
+ } : function (o, v) {
34
+ o["default"] = v;
35
+ });
36
+
37
+ var __importStar = void 0 && (void 0).__importStar || function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
41
+
42
+ __setModuleDefault(result, mod);
43
+
44
+ return result;
45
+ };
46
+
47
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
48
+ function adopt(value) {
49
+ return value instanceof P ? value : new P(function (resolve) {
50
+ resolve(value);
51
+ });
52
+ }
53
+
54
+ return new (P || (P = Promise))(function (resolve, reject) {
55
+ function fulfilled(value) {
56
+ try {
57
+ step(generator.next(value));
58
+ } catch (e) {
59
+ reject(e);
60
+ }
61
+ }
62
+
63
+ function rejected(value) {
64
+ try {
65
+ step(generator["throw"](value));
66
+ } catch (e) {
67
+ reject(e);
68
+ }
69
+ }
70
+
71
+ function step(result) {
72
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
73
+ }
74
+
75
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
76
+ });
77
+ };
78
+
79
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
80
+ return mod && mod.__esModule ? mod : {
81
+ "default": mod
82
+ };
83
+ };
84
+
85
+ Object.defineProperty(exports, "__esModule", {
86
+ value: true
87
+ });
88
+
89
+ const path_1 = __importDefault(require("path"));
90
+
91
+ const database_1 = require("@nocobase/database");
92
+
93
+ const models = __importStar(require("./models"));
94
+
95
+ database_1.registerModels(models);
96
+ exports.default = {
97
+ name: 'notifications',
98
+
99
+ load() {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ this.app.db.import({
102
+ directory: path_1.default.resolve(__dirname, 'collections')
103
+ });
104
+ });
105
+ }
106
+
107
+ };
108
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,iDAA8D;AAE9D,iDAAmC;AAEnC,yBAAc,CAAC,MAAM,CAAC,CAAC;AAEvB,kBAAe;IACb,IAAI,EAAE,eAAe;IACf,IAAI;;YACR,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC;gBACjB,SAAS,EAAE,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;aAClD,CAAC,CAAC;QACL,CAAC;KAAA;CACe,CAAA","file":"server.js","sourcesContent":["import path from 'path';\nimport Database, { registerModels } from '@nocobase/database';\nimport { PluginOptions } from '@nocobase/server';\nimport * as models from './models';\n\nregisterModels(models);\n\nexport default {\n name: 'notifications',\n async load() {\n this.app.db.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n }\n} as PluginOptions\n"]}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-notifications",
3
- "version": "0.5.0-alpha.16",
3
+ "version": "0.5.0-alpha.17",
4
4
  "main": "lib/index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "@nocobase/server": "^0.5.0-alpha.16",
7
+ "@nocobase/server": "^0.5.0-alpha.17",
8
8
  "nodemailer": "^6.6.1"
9
9
  },
10
- "gitHead": "dafe8f14d04ae73589f7d33982b20b40b722949a"
10
+ "gitHead": "c2905dd97cc204cf225e7298cfb3e57b530bc2fa"
11
11
  }