@nocobase/plugin-notification-manager 2.1.0-beta.33 → 2.1.0-beta.35
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/dist/externalVersion.js +8 -8
- package/dist/node_modules/uuid/dist/bin/uuid +2 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/index.js +104 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/max.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/md5.js +200 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/native.js +10 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/nil.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/parse.js +44 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/regex.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/rng.js +23 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/sha1.js +82 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/stringify.js +38 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v1.js +131 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v1ToV6.js +26 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v3.js +11 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v35.js +63 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v4.js +32 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v5.js +11 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v6.js +42 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v6ToV1.js +26 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v7.js +152 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/validate.js +12 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/version.js +15 -0
- package/dist/node_modules/uuid/dist/esm-browser/index.js +14 -0
- package/dist/node_modules/uuid/dist/esm-browser/max.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/md5.js +194 -0
- package/dist/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/nil.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/parse.js +37 -0
- package/dist/node_modules/uuid/dist/esm-browser/regex.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/rng.js +17 -0
- package/dist/node_modules/uuid/dist/esm-browser/sha1.js +76 -0
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/dist/node_modules/uuid/dist/esm-browser/v1.js +125 -0
- package/dist/node_modules/uuid/dist/esm-browser/v1ToV6.js +20 -0
- package/dist/node_modules/uuid/dist/esm-browser/v3.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/v35.js +55 -0
- package/dist/node_modules/uuid/dist/esm-browser/v4.js +25 -0
- package/dist/node_modules/uuid/dist/esm-browser/v5.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/v6.js +36 -0
- package/dist/node_modules/uuid/dist/esm-browser/v6ToV1.js +20 -0
- package/dist/node_modules/uuid/dist/esm-browser/v7.js +146 -0
- package/dist/node_modules/uuid/dist/esm-browser/validate.js +5 -0
- package/dist/node_modules/uuid/dist/esm-browser/version.js +8 -0
- package/dist/node_modules/uuid/dist/esm-node/index.js +14 -0
- package/dist/node_modules/uuid/dist/esm-node/max.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/md5.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/native.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/nil.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/parse.js +37 -0
- package/dist/node_modules/uuid/dist/esm-node/regex.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/rng.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/sha1.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/stringify.js +31 -0
- package/dist/node_modules/uuid/dist/esm-node/v1.js +125 -0
- package/dist/node_modules/uuid/dist/esm-node/v1ToV6.js +20 -0
- package/dist/node_modules/uuid/dist/esm-node/v3.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/v35.js +55 -0
- package/dist/node_modules/uuid/dist/esm-node/v4.js +25 -0
- package/dist/node_modules/uuid/dist/esm-node/v5.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/v6.js +32 -0
- package/dist/node_modules/uuid/dist/esm-node/v6ToV1.js +20 -0
- package/dist/node_modules/uuid/dist/esm-node/v7.js +146 -0
- package/dist/node_modules/uuid/dist/esm-node/validate.js +5 -0
- package/dist/node_modules/uuid/dist/esm-node/version.js +8 -0
- package/dist/node_modules/uuid/dist/index.js +1 -0
- package/dist/node_modules/uuid/dist/max.js +7 -0
- package/dist/node_modules/uuid/dist/md5-browser.js +200 -0
- package/dist/node_modules/uuid/dist/md5.js +17 -0
- package/dist/node_modules/uuid/dist/native-browser.js +10 -0
- package/dist/node_modules/uuid/dist/native.js +11 -0
- package/dist/node_modules/uuid/dist/nil.js +7 -0
- package/dist/node_modules/uuid/dist/parse.js +44 -0
- package/dist/node_modules/uuid/dist/regex.js +7 -0
- package/dist/node_modules/uuid/dist/rng-browser.js +23 -0
- package/dist/node_modules/uuid/dist/rng.js +17 -0
- package/dist/node_modules/uuid/dist/sha1-browser.js +82 -0
- package/dist/node_modules/uuid/dist/sha1.js +17 -0
- package/dist/node_modules/uuid/dist/stringify.js +38 -0
- package/dist/node_modules/uuid/dist/uuid-bin.js +75 -0
- package/dist/node_modules/uuid/dist/v1.js +131 -0
- package/dist/node_modules/uuid/dist/v1ToV6.js +26 -0
- package/dist/node_modules/uuid/dist/v3.js +11 -0
- package/dist/node_modules/uuid/dist/v35.js +63 -0
- package/dist/node_modules/uuid/dist/v4.js +32 -0
- package/dist/node_modules/uuid/dist/v5.js +11 -0
- package/dist/node_modules/uuid/dist/v6.js +38 -0
- package/dist/node_modules/uuid/dist/v6ToV1.js +26 -0
- package/dist/node_modules/uuid/dist/v7.js +152 -0
- package/dist/node_modules/uuid/dist/validate.js +12 -0
- package/dist/node_modules/uuid/dist/version.js +15 -0
- package/dist/node_modules/uuid/package.json +1 -0
- package/dist/server/manager.d.ts +21 -5
- package/dist/server/manager.js +56 -8
- package/dist/server/plugin.d.ts +15 -2
- package/dist/server/types.d.ts +1 -0
- package/package.json +2 -2
package/dist/server/manager.d.ts
CHANGED
|
@@ -9,29 +9,39 @@
|
|
|
9
9
|
import { Registry } from '@nocobase/utils';
|
|
10
10
|
import PluginNotificationManagerServer from './plugin';
|
|
11
11
|
import type { NotificationQueueMessage, NotificationChannelConstructor, RegisterServerTypeFnParams, ReceiversOptions, SendOptions, SendUserOptions, WriteLogOptions } from './types';
|
|
12
|
-
import { Transactionable } from '@nocobase/database';
|
|
13
12
|
export declare class NotificationManager implements NotificationManager {
|
|
14
13
|
private static readonly SLOW_SEND_THRESHOLD_MS;
|
|
15
14
|
private plugin;
|
|
16
15
|
channelTypes: Registry<{
|
|
17
16
|
Channel: NotificationChannelConstructor;
|
|
17
|
+
useQueue: boolean;
|
|
18
18
|
}>;
|
|
19
19
|
constructor({ plugin }: {
|
|
20
20
|
plugin: PluginNotificationManagerServer;
|
|
21
21
|
});
|
|
22
|
-
registerType({ type, Channel }: RegisterServerTypeFnParams): void;
|
|
23
|
-
createSendingRecord: (options: WriteLogOptions
|
|
22
|
+
registerType({ type, Channel, useQueue }: RegisterServerTypeFnParams): void;
|
|
23
|
+
createSendingRecord: (options: WriteLogOptions) => Promise<import("@nocobase/database").Model<any, any>>;
|
|
24
24
|
private toQueueMessage;
|
|
25
25
|
private getQueuedResult;
|
|
26
|
+
private getDirectResult;
|
|
27
|
+
private getDeferredResult;
|
|
28
|
+
private shouldUseQueue;
|
|
26
29
|
private enqueue;
|
|
30
|
+
private dispatchAfterCommit;
|
|
27
31
|
findChannel(name: string): Promise<any>;
|
|
28
32
|
private getReceiverMeta;
|
|
29
33
|
send(params: SendOptions): Promise<{
|
|
30
|
-
status: "success";
|
|
34
|
+
status: "success" | "failure";
|
|
35
|
+
reason: string;
|
|
31
36
|
triggerFrom: string;
|
|
32
37
|
channelName: string;
|
|
33
38
|
receivers: ReceiversOptions;
|
|
34
39
|
queued: boolean;
|
|
40
|
+
} | {
|
|
41
|
+
status: "success";
|
|
42
|
+
triggerFrom: string;
|
|
43
|
+
channelName: string;
|
|
44
|
+
receivers: ReceiversOptions;
|
|
35
45
|
} | {
|
|
36
46
|
status: "failure";
|
|
37
47
|
reason: string;
|
|
@@ -41,11 +51,17 @@ export declare class NotificationManager implements NotificationManager {
|
|
|
41
51
|
}>;
|
|
42
52
|
sendNow(params: NotificationQueueMessage): Promise<any>;
|
|
43
53
|
sendToUsers(options: SendUserOptions): Promise<({
|
|
44
|
-
status: "success";
|
|
54
|
+
status: "success" | "failure";
|
|
55
|
+
reason: string;
|
|
45
56
|
triggerFrom: string;
|
|
46
57
|
channelName: string;
|
|
47
58
|
receivers: ReceiversOptions;
|
|
48
59
|
queued: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
status: "success";
|
|
62
|
+
triggerFrom: string;
|
|
63
|
+
channelName: string;
|
|
64
|
+
receivers: ReceiversOptions;
|
|
49
65
|
} | {
|
|
50
66
|
status: "failure";
|
|
51
67
|
reason: string;
|
package/dist/server/manager.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(manager_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(manager_exports);
|
|
33
33
|
var import_utils = require("@nocobase/utils");
|
|
34
|
+
var import_uuid = require("uuid");
|
|
34
35
|
var import_constant = require("../constant");
|
|
35
36
|
var import_compile = require("./utils/compile");
|
|
36
37
|
class NotificationManager {
|
|
@@ -40,13 +41,21 @@ class NotificationManager {
|
|
|
40
41
|
constructor({ plugin }) {
|
|
41
42
|
this.plugin = plugin;
|
|
42
43
|
}
|
|
43
|
-
registerType({ type, Channel }) {
|
|
44
|
-
this.channelTypes.register(type, { Channel });
|
|
44
|
+
registerType({ type, Channel, useQueue = true }) {
|
|
45
|
+
this.channelTypes.register(type, { Channel, useQueue });
|
|
45
46
|
}
|
|
46
47
|
createSendingRecord = async (options) => {
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const LogsModel = this.plugin.app.db.getModel(import_constant.COLLECTION_NAME.logs);
|
|
49
|
+
return LogsModel.create(
|
|
50
|
+
{
|
|
51
|
+
id: (0, import_uuid.v4)(),
|
|
52
|
+
...options
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
hooks: false,
|
|
56
|
+
validate: false
|
|
57
|
+
}
|
|
58
|
+
);
|
|
50
59
|
};
|
|
51
60
|
toQueueMessage(params) {
|
|
52
61
|
const { transaction, ...message } = params;
|
|
@@ -61,9 +70,43 @@ class NotificationManager {
|
|
|
61
70
|
queued: true
|
|
62
71
|
};
|
|
63
72
|
}
|
|
73
|
+
getDirectResult(params, result) {
|
|
74
|
+
return {
|
|
75
|
+
status: result.status,
|
|
76
|
+
reason: result.reason,
|
|
77
|
+
triggerFrom: params.triggerFrom,
|
|
78
|
+
channelName: params.channelName,
|
|
79
|
+
receivers: params.receivers,
|
|
80
|
+
queued: false
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
getDeferredResult(params) {
|
|
84
|
+
return {
|
|
85
|
+
status: "success",
|
|
86
|
+
triggerFrom: params.triggerFrom,
|
|
87
|
+
channelName: params.channelName,
|
|
88
|
+
receivers: params.receivers
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async shouldUseQueue(channelName) {
|
|
92
|
+
const channel = await this.findChannel(channelName);
|
|
93
|
+
if (!channel) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
const channelType = this.channelTypes.get(channel.notificationType);
|
|
97
|
+
return (channelType == null ? void 0 : channelType.useQueue) ?? true;
|
|
98
|
+
}
|
|
64
99
|
async enqueue(message) {
|
|
65
100
|
await this.plugin.app.eventQueue.publish(this.plugin.sendQueueChannel, message);
|
|
66
101
|
}
|
|
102
|
+
async dispatchAfterCommit(message) {
|
|
103
|
+
const useQueue = await this.shouldUseQueue(message.channelName);
|
|
104
|
+
if (useQueue) {
|
|
105
|
+
await this.enqueue(message);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
await this.sendNow(message);
|
|
109
|
+
}
|
|
67
110
|
async findChannel(name) {
|
|
68
111
|
return await this.plugin.getChannel(name);
|
|
69
112
|
}
|
|
@@ -86,15 +129,20 @@ class NotificationManager {
|
|
|
86
129
|
const transaction = params.transaction;
|
|
87
130
|
if (transaction == null ? void 0 : transaction.afterCommit) {
|
|
88
131
|
transaction.afterCommit(() => {
|
|
89
|
-
|
|
90
|
-
this.plugin.logger.error("notification
|
|
132
|
+
return this.dispatchAfterCommit(queueMessage).catch((error) => {
|
|
133
|
+
this.plugin.logger.error("notification dispatch failed after transaction committed", {
|
|
91
134
|
channelName: params.channelName,
|
|
92
135
|
triggerFrom: params.triggerFrom,
|
|
93
136
|
reason: error instanceof Error ? `${error.name}: ${error.message}` : JSON.stringify(error)
|
|
94
137
|
});
|
|
95
138
|
});
|
|
96
139
|
});
|
|
97
|
-
return this.
|
|
140
|
+
return this.getDeferredResult(params);
|
|
141
|
+
}
|
|
142
|
+
const useQueue = await this.shouldUseQueue(params.channelName);
|
|
143
|
+
if (!useQueue) {
|
|
144
|
+
const result = await this.sendNow(queueMessage);
|
|
145
|
+
return this.getDirectResult(params, result);
|
|
98
146
|
}
|
|
99
147
|
try {
|
|
100
148
|
await this.enqueue(queueMessage);
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -23,14 +23,21 @@ export declare class PluginNotificationManagerServer extends Plugin {
|
|
|
23
23
|
getChannel(name: string): Promise<any>;
|
|
24
24
|
get channelTypes(): import("@nocobase/utils").Registry<{
|
|
25
25
|
Channel: import("./types").NotificationChannelConstructor;
|
|
26
|
+
useQueue: boolean;
|
|
26
27
|
}>;
|
|
27
28
|
registerChannelType(params: RegisterServerTypeFnParams): void;
|
|
28
29
|
send(options: SendOptions): Promise<{
|
|
29
|
-
status: "success";
|
|
30
|
+
status: "success" | "failure";
|
|
31
|
+
reason: string;
|
|
30
32
|
triggerFrom: string;
|
|
31
33
|
channelName: string;
|
|
32
34
|
receivers: import("./types").ReceiversOptions;
|
|
33
35
|
queued: boolean;
|
|
36
|
+
} | {
|
|
37
|
+
status: "success";
|
|
38
|
+
triggerFrom: string;
|
|
39
|
+
channelName: string;
|
|
40
|
+
receivers: import("./types").ReceiversOptions;
|
|
34
41
|
} | {
|
|
35
42
|
status: "failure";
|
|
36
43
|
reason: string;
|
|
@@ -40,11 +47,17 @@ export declare class PluginNotificationManagerServer extends Plugin {
|
|
|
40
47
|
}>;
|
|
41
48
|
sendNow(options: SendOptions): Promise<any>;
|
|
42
49
|
sendToUsers(options: SendUserOptions): Promise<({
|
|
43
|
-
status: "success";
|
|
50
|
+
status: "success" | "failure";
|
|
51
|
+
reason: string;
|
|
44
52
|
triggerFrom: string;
|
|
45
53
|
channelName: string;
|
|
46
54
|
receivers: import("./types").ReceiversOptions;
|
|
47
55
|
queued: boolean;
|
|
56
|
+
} | {
|
|
57
|
+
status: "success";
|
|
58
|
+
triggerFrom: string;
|
|
59
|
+
channelName: string;
|
|
60
|
+
receivers: import("./types").ReceiversOptions;
|
|
48
61
|
} | {
|
|
49
62
|
status: "failure";
|
|
50
63
|
reason: string;
|
package/dist/server/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"description.ru-RU": "Предоставляет единый сервис управления, включающий конфигурирование каналов, логирование и другие функции, поддерживает настройку различных каналов уведомлений, включая внутренние сообщения и электронную почту.",
|
|
7
7
|
"displayName.zh-CN": "通知管理",
|
|
8
8
|
"description.zh-CN": "提供统一的管理服务,涵盖渠道配置、日志记录等功能,支持多种通知渠道的配置,包括站内信和电子邮件等。",
|
|
9
|
-
"version": "2.1.0-beta.
|
|
9
|
+
"version": "2.1.0-beta.35",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/notification-manager",
|
|
11
11
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/notification-manager",
|
|
12
12
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/notification-manager",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"Notification"
|
|
36
36
|
],
|
|
37
37
|
"license": "Apache-2.0",
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "74310d8b9e9581fcde14b5a93d12b41ddb5bb325"
|
|
39
39
|
}
|