@nocobase/server 1.5.0-beta.1 → 1.6.0-alpha.2

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.
@@ -16,6 +16,7 @@ import { Logger, LoggerOptions, RequestLoggerOptions, SystemLogger, SystemLogger
16
16
  import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
17
17
  import { Telemetry, TelemetryOptions } from '@nocobase/telemetry';
18
18
  import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
19
+ import { LockManager, LockManagerOptions } from '@nocobase/lock-manager';
19
20
  import { Command, CommandOptions, ParseOptions } from 'commander';
20
21
  import { IncomingMessage, ServerResponse } from 'http';
21
22
  import { i18n, InitOptions } from 'i18next';
@@ -28,7 +29,9 @@ import { ApplicationVersion } from './helpers/application-version';
28
29
  import { Locale } from './locale';
29
30
  import { Plugin } from './plugin';
30
31
  import { InstallOptions, PluginManager } from './plugin-manager';
31
- import { SyncManager } from './sync-manager';
32
+ import { PubSubManager, PubSubManagerOptions } from './pub-sub-manager';
33
+ import { SyncMessageManager } from './sync-message-manager';
34
+ import { AuditManager } from './audit-manager';
32
35
  export type PluginType = string | typeof Plugin;
33
36
  export type PluginConfiguration = PluginType | [PluginType, any];
34
37
  export interface ResourceManagerOptions {
@@ -58,6 +61,8 @@ export interface ApplicationOptions {
58
61
  */
59
62
  resourcer?: ResourceManagerOptions;
60
63
  resourceManager?: ResourceManagerOptions;
64
+ pubSubManager?: PubSubManagerOptions;
65
+ syncMessageManager?: any;
61
66
  bodyParser?: any;
62
67
  cors?: any;
63
68
  dataWrapping?: boolean;
@@ -72,6 +77,8 @@ export interface ApplicationOptions {
72
77
  pmSock?: string;
73
78
  name?: string;
74
79
  authManager?: AuthManagerOptions;
80
+ auditManager?: AuditManager;
81
+ lockManager?: LockManagerOptions;
75
82
  /**
76
83
  * @internal
77
84
  */
@@ -152,7 +159,8 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
152
159
  /**
153
160
  * @internal
154
161
  */
155
- syncManager: SyncManager;
162
+ pubSubManager: PubSubManager;
163
+ syncMessageManager: SyncMessageManager;
156
164
  requestLogger: Logger;
157
165
  protected plugins: Map<string, Plugin<any>>;
158
166
  protected _appSupervisor: AppSupervisor;
@@ -161,6 +169,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
161
169
  private _maintainingCommandStatus;
162
170
  private _maintainingStatusBeforeCommand;
163
171
  private _actionCommand;
172
+ lockManager: LockManager;
164
173
  constructor(options: ApplicationOptions);
165
174
  private static staticCommands;
166
175
  static addCommand(callback: (app: Application) => void): void;
@@ -212,6 +221,8 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
212
221
  get acl(): import("@nocobase/acl").ACL;
213
222
  protected _authManager: AuthManager;
214
223
  get authManager(): AuthManager;
224
+ protected _auditManager: AuditManager;
225
+ get auditManager(): AuditManager;
215
226
  protected _locales: Locale;
216
227
  /**
217
228
  * This method is deprecated and should not be used.
@@ -50,6 +50,7 @@ var import_database = __toESM(require("@nocobase/database"));
50
50
  var import_logger = require("@nocobase/logger");
51
51
  var import_telemetry = require("@nocobase/telemetry");
52
52
  var import_utils = require("@nocobase/utils");
53
+ var import_lock_manager = require("@nocobase/lock-manager");
53
54
  var import_crypto = require("crypto");
54
55
  var import_glob = __toESM(require("glob"));
55
56
  var import_koa = __toESM(require("koa"));
@@ -72,8 +73,10 @@ var import_middlewares = require("./middlewares");
72
73
  var import_data_template = require("./middlewares/data-template");
73
74
  var import_validate_filter_params = __toESM(require("./middlewares/validate-filter-params"));
74
75
  var import_plugin_manager = require("./plugin-manager");
75
- var import_sync_manager = require("./sync-manager");
76
+ var import_pub_sub_manager = require("./pub-sub-manager");
77
+ var import_sync_message_manager = require("./sync-message-manager");
76
78
  var import_package = __toESM(require("../package.json"));
79
+ var import_audit_manager = require("./audit-manager");
77
80
  const _Application = class _Application extends import_koa.default {
78
81
  constructor(options) {
79
82
  super();
@@ -112,7 +115,8 @@ const _Application = class _Application extends import_koa.default {
112
115
  /**
113
116
  * @internal
114
117
  */
115
- syncManager;
118
+ pubSubManager;
119
+ syncMessageManager;
116
120
  requestLogger;
117
121
  plugins = /* @__PURE__ */ new Map();
118
122
  _appSupervisor = import_app_supervisor.AppSupervisor.getInstance();
@@ -121,6 +125,7 @@ const _Application = class _Application extends import_koa.default {
121
125
  _maintainingCommandStatus;
122
126
  _maintainingStatusBeforeCommand;
123
127
  _actionCommand;
128
+ lockManager;
124
129
  static addCommand(callback) {
125
130
  this.staticCommands.push(callback);
126
131
  }
@@ -214,6 +219,10 @@ const _Application = class _Application extends import_koa.default {
214
219
  get authManager() {
215
220
  return this._authManager;
216
221
  }
222
+ _auditManager;
223
+ get auditManager() {
224
+ return this._auditManager;
225
+ }
217
226
  _locales;
218
227
  /**
219
228
  * This method is deprecated and should not be used.
@@ -346,6 +355,9 @@ const _Application = class _Application extends import_koa.default {
346
355
  if (this.cacheManager) {
347
356
  await this.cacheManager.close();
348
357
  }
358
+ if (this.pubSubManager) {
359
+ await this.pubSubManager.close();
360
+ }
349
361
  if (this.telemetry.started) {
350
362
  await this.telemetry.shutdown();
351
363
  }
@@ -820,7 +832,12 @@ const _Application = class _Application extends import_koa.default {
820
832
  this._cronJobManager = new import_cron_job_manager.CronJobManager(this);
821
833
  this._cli = this.createCLI();
822
834
  this._i18n = (0, import_helper.createI18n)(options);
823
- this.syncManager = new import_sync_manager.SyncManager(this);
835
+ this.pubSubManager = (0, import_pub_sub_manager.createPubSubManager)(this, options.pubSubManager);
836
+ this.syncMessageManager = new import_sync_message_manager.SyncMessageManager(this, options.syncMessageManager);
837
+ this.lockManager = new import_lock_manager.LockManager({
838
+ defaultAdapter: process.env.LOCK_ADAPTER_DEFAULT,
839
+ ...options.lockManager
840
+ });
824
841
  this.context.db = this.db;
825
842
  this.context.resourcer = this.resourceManager;
826
843
  this.context.resourceManager = this.resourceManager;
@@ -841,6 +858,7 @@ const _Application = class _Application extends import_koa.default {
841
858
  default: "basic",
842
859
  ...this.options.authManager || {}
843
860
  });
861
+ this._auditManager = new import_audit_manager.AuditManager();
844
862
  this.resourceManager.define({
845
863
  name: "auth",
846
864
  actions: import_auth.actions
@@ -0,0 +1,115 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Context } from '@nocobase/actions';
10
+ export interface AuditLog {
11
+ uuid: string;
12
+ dataSource: string;
13
+ resource: string;
14
+ action: string;
15
+ sourceCollection?: string;
16
+ sourceRecordUK?: string;
17
+ targetCollection?: string;
18
+ targetRecordUK?: string;
19
+ userId: string;
20
+ roleName: string;
21
+ ip: string;
22
+ ua: string;
23
+ status: number;
24
+ metadata?: Record<string, any>;
25
+ }
26
+ export interface UserInfo {
27
+ userId?: string;
28
+ roleName?: string;
29
+ }
30
+ export interface SourceAndTarget {
31
+ sourceCollection?: string;
32
+ sourceRecordUK?: string;
33
+ targetCollection?: string;
34
+ targetRecordUK?: string;
35
+ }
36
+ export interface AuditLogger {
37
+ log(auditLog: AuditLog): Promise<void>;
38
+ }
39
+ type Action = string | {
40
+ name: string;
41
+ getMetaData?: (ctx: Context) => Promise<Record<string, any>>;
42
+ getUserInfo?: (ctx: Context) => Promise<UserInfo>;
43
+ getSourceAndTarget?: (ctx: Context) => Promise<SourceAndTarget>;
44
+ };
45
+ export declare class AuditManager {
46
+ logger: AuditLogger;
47
+ resources: Map<string, Map<string, Action>>;
48
+ constructor();
49
+ setLogger(logger: AuditLogger): void;
50
+ /**
51
+ * 注册需要参与审计的资源和操作,支持几种写法
52
+ *
53
+ * 对所有资源生效;
54
+ * registerActions(['create'])
55
+ *
56
+ * 对某个资源的所有操作生效 resource:*
57
+ * registerActions(['app:*'])
58
+ *
59
+ * 对某个资源的某个操作生效 resouce:action
60
+ * registerAction(['pm:update'])
61
+ *
62
+ * 支持传getMetaData方法
63
+ *
64
+ * registerActions([
65
+ * 'create',
66
+ * { name: 'auth:signIn', getMetaData}
67
+ * ])
68
+ *
69
+ * 支持传getUserInfo方法
70
+ *
71
+ * registerActions([
72
+ * 'create',
73
+ * { name: 'auth:signIn', getUserInfo }
74
+ * ])
75
+ *
76
+ * 当注册的接口有重叠时,颗粒度细的注册方法优先级更高
77
+ *
78
+ * Action1: registerActions(['create']);
79
+ *
80
+ * Action2: registerAction([{ name: 'user:*', getMetaData }]);
81
+ *
82
+ * Action3: registerAction([{ name: 'user:create', getMetaData }]);
83
+ *
84
+ * 对于user:create接口,以上优先级顺序是 Action3 > Action2 > Action1
85
+ *
86
+ * @param actions 操作列表
87
+ */
88
+ registerActions(actions: Action[]): void;
89
+ /**
90
+ * 注册单个操作,支持的用法同registerActions
91
+ * @param action 操作
92
+ */
93
+ registerAction(action: Action): void;
94
+ getAction(action: string, resource?: string): Action;
95
+ getDefaultMetaData(ctx: any): Promise<{
96
+ request: {
97
+ params: any;
98
+ query: any;
99
+ body: any;
100
+ path: any;
101
+ headers: {
102
+ 'x-authenticator': any;
103
+ 'x-locale': any;
104
+ 'x-timezone': any;
105
+ };
106
+ };
107
+ response: {
108
+ body: any;
109
+ };
110
+ }>;
111
+ formatAuditData(ctx: Context): AuditLog;
112
+ output(ctx: any, reqId: any, metadata?: Record<string, any>): Promise<void>;
113
+ middleware(): (ctx: any, next: any) => Promise<void>;
114
+ }
115
+ export {};
@@ -0,0 +1,326 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var audit_manager_exports = {};
39
+ __export(audit_manager_exports, {
40
+ AuditManager: () => AuditManager
41
+ });
42
+ module.exports = __toCommonJS(audit_manager_exports);
43
+ var import_stream = __toESM(require("stream"));
44
+ function isStream(obj) {
45
+ return obj instanceof import_stream.default.Readable || obj instanceof import_stream.default.Writable || obj instanceof import_stream.default.Duplex || obj instanceof import_stream.default.Transform;
46
+ }
47
+ __name(isStream, "isStream");
48
+ const _AuditManager = class _AuditManager {
49
+ logger;
50
+ resources;
51
+ constructor() {
52
+ this.resources = /* @__PURE__ */ new Map();
53
+ }
54
+ setLogger(logger) {
55
+ this.logger = logger;
56
+ }
57
+ /**
58
+ * 注册需要参与审计的资源和操作,支持几种写法
59
+ *
60
+ * 对所有资源生效;
61
+ * registerActions(['create'])
62
+ *
63
+ * 对某个资源的所有操作生效 resource:*
64
+ * registerActions(['app:*'])
65
+ *
66
+ * 对某个资源的某个操作生效 resouce:action
67
+ * registerAction(['pm:update'])
68
+ *
69
+ * 支持传getMetaData方法
70
+ *
71
+ * registerActions([
72
+ * 'create',
73
+ * { name: 'auth:signIn', getMetaData}
74
+ * ])
75
+ *
76
+ * 支持传getUserInfo方法
77
+ *
78
+ * registerActions([
79
+ * 'create',
80
+ * { name: 'auth:signIn', getUserInfo }
81
+ * ])
82
+ *
83
+ * 当注册的接口有重叠时,颗粒度细的注册方法优先级更高
84
+ *
85
+ * Action1: registerActions(['create']);
86
+ *
87
+ * Action2: registerAction([{ name: 'user:*', getMetaData }]);
88
+ *
89
+ * Action3: registerAction([{ name: 'user:create', getMetaData }]);
90
+ *
91
+ * 对于user:create接口,以上优先级顺序是 Action3 > Action2 > Action1
92
+ *
93
+ * @param actions 操作列表
94
+ */
95
+ registerActions(actions) {
96
+ actions.forEach((action) => {
97
+ this.registerAction(action);
98
+ });
99
+ }
100
+ /**
101
+ * 注册单个操作,支持的用法同registerActions
102
+ * @param action 操作
103
+ */
104
+ registerAction(action) {
105
+ let originAction = "";
106
+ let getMetaData = null;
107
+ let getUserInfo = null;
108
+ let getSourceAndTarget = null;
109
+ if (typeof action === "string") {
110
+ originAction = action;
111
+ } else {
112
+ originAction = action.name;
113
+ getMetaData = action.getMetaData;
114
+ getUserInfo = action.getUserInfo;
115
+ getSourceAndTarget = action.getSourceAndTarget;
116
+ }
117
+ const nameRegex = /^[a-zA-Z0-9_-]+$/;
118
+ const resourceWildcardRegex = /^([a-zA-Z0-9_-]+):\*$/;
119
+ const resourceAndActionRegex = /^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)$/;
120
+ let resourceName = "";
121
+ let actionName = "";
122
+ if (nameRegex.test(originAction)) {
123
+ actionName = originAction;
124
+ resourceName = "__default__";
125
+ }
126
+ if (resourceWildcardRegex.test(originAction)) {
127
+ const match = originAction.match(resourceWildcardRegex);
128
+ resourceName = match[1];
129
+ actionName = "__default__";
130
+ }
131
+ if (resourceAndActionRegex.test(originAction)) {
132
+ const match = originAction.match(resourceAndActionRegex);
133
+ resourceName = match[1];
134
+ actionName = match[2];
135
+ }
136
+ if (!resourceName && !actionName) {
137
+ return;
138
+ }
139
+ let resource = this.resources.get(resourceName);
140
+ if (!resource) {
141
+ resource = /* @__PURE__ */ new Map();
142
+ this.resources.set(resourceName, resource);
143
+ }
144
+ const saveAction = {
145
+ name: originAction
146
+ };
147
+ if (getMetaData) {
148
+ saveAction.getMetaData = getMetaData;
149
+ }
150
+ if (getUserInfo) {
151
+ saveAction.getUserInfo = getUserInfo;
152
+ }
153
+ if (getSourceAndTarget) {
154
+ saveAction.getSourceAndTarget = getSourceAndTarget;
155
+ }
156
+ resource.set(actionName, saveAction);
157
+ }
158
+ getAction(action, resource) {
159
+ let resourceName = resource;
160
+ if (!resource) {
161
+ resourceName = "__default__";
162
+ }
163
+ if (resourceName === "__default__") {
164
+ const resourceActions = this.resources.get(resourceName);
165
+ if (resourceActions) {
166
+ const resourceAction = resourceActions.get(action);
167
+ if (resourceAction) {
168
+ return resourceAction;
169
+ }
170
+ }
171
+ } else {
172
+ const resourceActions = this.resources.get(resourceName);
173
+ if (resourceActions) {
174
+ let resourceAction = resourceActions.get(action);
175
+ if (resourceAction) {
176
+ return resourceAction;
177
+ } else {
178
+ resourceAction = resourceActions.get("__default__");
179
+ if (resourceAction) {
180
+ return resourceAction;
181
+ } else {
182
+ const defaultResourceActions = this.resources.get("__default__");
183
+ if (defaultResourceActions) {
184
+ const defaultResourceAction = defaultResourceActions.get(action);
185
+ if (defaultResourceAction) {
186
+ return defaultResourceAction;
187
+ }
188
+ }
189
+ }
190
+ }
191
+ } else {
192
+ const resourceActions2 = this.resources.get("__default__");
193
+ if (resourceActions2) {
194
+ const resourceAction = resourceActions2.get(action);
195
+ if (resourceAction) {
196
+ return resourceAction;
197
+ }
198
+ }
199
+ }
200
+ }
201
+ return null;
202
+ }
203
+ async getDefaultMetaData(ctx) {
204
+ var _a, _b, _c;
205
+ let body = null;
206
+ if (ctx.body) {
207
+ if (!Buffer.isBuffer(ctx.body) && !isStream(ctx.body)) {
208
+ body = ctx.body;
209
+ }
210
+ }
211
+ return {
212
+ request: {
213
+ params: ctx.request.params,
214
+ query: ctx.request.query,
215
+ body: ctx.request.body,
216
+ path: ctx.request.path,
217
+ headers: {
218
+ "x-authenticator": (_a = ctx.request) == null ? void 0 : _a.headers["x-authenticator"],
219
+ "x-locale": (_b = ctx.request) == null ? void 0 : _b.headers["x-locale"],
220
+ "x-timezone": (_c = ctx.request) == null ? void 0 : _c.headers["x-timezone"]
221
+ }
222
+ },
223
+ response: {
224
+ body
225
+ }
226
+ };
227
+ }
228
+ formatAuditData(ctx) {
229
+ var _a, _b, _c;
230
+ const { resourceName } = ctx.action;
231
+ const ipvalues = ctx.request.header["x-forwarded-for"];
232
+ let ipvalue = "";
233
+ if (ipvalues instanceof Array) {
234
+ ipvalue = ipvalues[0];
235
+ } else {
236
+ ipvalue = ipvalues;
237
+ }
238
+ const ips = ipvalue ? ipvalue == null ? void 0 : ipvalue.split(/\s*,\s*/) : [];
239
+ const auditLog = {
240
+ uuid: ctx.reqId,
241
+ dataSource: ctx.request.header["x-data-source"] || "main",
242
+ resource: resourceName,
243
+ action: ctx.action.actionName,
244
+ userId: (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id,
245
+ roleName: (_c = ctx.state) == null ? void 0 : _c.currentRole,
246
+ ip: ips.length > 0 ? ips[0] : ctx.request.ip,
247
+ ua: ctx.request.header["user-agent"],
248
+ status: ctx.response.status
249
+ };
250
+ return auditLog;
251
+ }
252
+ async output(ctx, reqId, metadata) {
253
+ var _a;
254
+ try {
255
+ const { resourceName, actionName } = ctx.action;
256
+ const action = this.getAction(actionName, resourceName);
257
+ if (!action) {
258
+ return;
259
+ }
260
+ const auditLog = this.formatAuditData(ctx);
261
+ auditLog.uuid = reqId;
262
+ auditLog.status = ctx.status;
263
+ if (typeof action !== "string") {
264
+ if (action.getUserInfo) {
265
+ const userInfo = await action.getUserInfo(ctx);
266
+ if (userInfo) {
267
+ if (userInfo.userId) {
268
+ auditLog.userId = userInfo.userId;
269
+ }
270
+ if (userInfo.roleName) {
271
+ auditLog.roleName = userInfo.roleName;
272
+ }
273
+ }
274
+ }
275
+ if (action.getMetaData) {
276
+ const extra = await action.getMetaData(ctx);
277
+ auditLog.metadata = { ...metadata, ...extra };
278
+ } else {
279
+ const defaultMetaData = await this.getDefaultMetaData(ctx);
280
+ auditLog.metadata = { ...metadata, ...defaultMetaData };
281
+ }
282
+ if (action.getSourceAndTarget) {
283
+ const sourceAndTarget = await action.getSourceAndTarget(ctx);
284
+ if (sourceAndTarget) {
285
+ auditLog.sourceCollection = sourceAndTarget.sourceCollection;
286
+ auditLog.sourceRecordUK = sourceAndTarget.sourceRecordUK;
287
+ auditLog.targetCollection = sourceAndTarget.targetCollection;
288
+ auditLog.targetRecordUK = sourceAndTarget.targetRecordUK;
289
+ }
290
+ }
291
+ } else {
292
+ const defaultMetaData = await this.getDefaultMetaData(ctx);
293
+ auditLog.metadata = { ...metadata, ...defaultMetaData };
294
+ }
295
+ this.logger.log(auditLog);
296
+ } catch (err) {
297
+ (_a = ctx.log) == null ? void 0 : _a.error(err);
298
+ }
299
+ }
300
+ // 中间件
301
+ middleware() {
302
+ return async (ctx, next) => {
303
+ const reqId = ctx.reqId;
304
+ let metadata = {};
305
+ try {
306
+ await next();
307
+ } catch (err) {
308
+ metadata = {
309
+ status: ctx.status,
310
+ errMsg: err.message
311
+ };
312
+ throw err;
313
+ } finally {
314
+ if (this.logger) {
315
+ this.output(ctx, reqId, metadata);
316
+ }
317
+ }
318
+ };
319
+ }
320
+ };
321
+ __name(_AuditManager, "AuditManager");
322
+ let AuditManager = _AuditManager;
323
+ // Annotate the CommonJS export names for ESM import in node:
324
+ 0 && (module.exports = {
325
+ AuditManager
326
+ });
package/lib/helper.js CHANGED
@@ -82,6 +82,7 @@ function registerMiddlewares(app, options) {
82
82
  }, "generateReqId"),
83
83
  { tag: "generateReqId" }
84
84
  );
85
+ app.use(app.auditManager.middleware(), { tag: "audit", after: "generateReqId" });
85
86
  app.use((0, import_logger.requestLogger)(app.name, app.requestLogger, (_a = options.logger) == null ? void 0 : _a.request), { tag: "logger" });
86
87
  app.use(
87
88
  (0, import_cors.default)({
package/lib/index.d.ts CHANGED
@@ -14,7 +14,8 @@ export * as middlewares from './middlewares';
14
14
  export * from './migration';
15
15
  export * from './plugin';
16
16
  export * from './plugin-manager';
17
- export * from './sync-manager';
17
+ export * from './audit-manager';
18
+ export * from './pub-sub-manager';
18
19
  export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
19
20
  export { appendToBuiltInPlugins, findAllPlugins, findBuiltInPlugins, findLocalPlugins, packageNameTrim, } from './plugin-manager/findPackageNames';
20
21
  export { runPluginStaticImports } from './run-plugin-static-imports';
package/lib/index.js CHANGED
@@ -56,7 +56,8 @@ var middlewares = __toESM(require("./middlewares"));
56
56
  __reExport(src_exports, require("./migration"), module.exports);
57
57
  __reExport(src_exports, require("./plugin"), module.exports);
58
58
  __reExport(src_exports, require("./plugin-manager"), module.exports);
59
- __reExport(src_exports, require("./sync-manager"), module.exports);
59
+ __reExport(src_exports, require("./audit-manager"), module.exports);
60
+ __reExport(src_exports, require("./pub-sub-manager"), module.exports);
60
61
  var import_findPackageNames = require("./plugin-manager/findPackageNames");
61
62
  var import_run_plugin_static_imports = require("./run-plugin-static-imports");
62
63
  const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
@@ -76,5 +77,6 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
76
77
  ...require("./migration"),
77
78
  ...require("./plugin"),
78
79
  ...require("./plugin-manager"),
79
- ...require("./sync-manager")
80
+ ...require("./audit-manager"),
81
+ ...require("./pub-sub-manager")
80
82
  });
@@ -25,6 +25,7 @@ export declare class Locale {
25
25
  resourceStorers: Registry<ResourceStorer>;
26
26
  constructor(app: Application);
27
27
  load(): Promise<void>;
28
+ reset(): Promise<void>;
28
29
  reload(): Promise<void>;
29
30
  setLocaleFn(name: string, fn: (lang: string) => Promise<any>): void;
30
31
  registerResourceStorer(name: string, storer: ResourceStorer): void;
@@ -61,6 +61,13 @@ const _Locale = class _Locale {
61
61
  this.app.log.debug("locale resource loaded", { submodule: "locale", method: "onAfterLoad" });
62
62
  this.app.setMaintainingMessage("locale resource loaded");
63
63
  });
64
+ this.app.syncMessageManager.subscribe("localeManager", async (message) => {
65
+ switch (message.type) {
66
+ case "reload":
67
+ await this.reset();
68
+ return;
69
+ }
70
+ });
64
71
  }
65
72
  async load() {
66
73
  this.cache = await this.app.cacheManager.createCache({
@@ -70,11 +77,15 @@ const _Locale = class _Locale {
70
77
  });
71
78
  await this.get(this.defaultLang);
72
79
  }
73
- async reload() {
80
+ async reset() {
74
81
  const storers = Array.from(this.resourceStorers.getValues());
75
82
  const promises = storers.map((storer) => storer.reset());
76
83
  await Promise.all([this.cache.reset(), ...promises]);
77
84
  }
85
+ async reload() {
86
+ await this.reset();
87
+ this.app.syncMessageManager.publish("localeManager", { type: "reload" });
88
+ }
78
89
  setLocaleFn(name, fn) {
79
90
  this.localeFn.set(name, fn);
80
91
  }
@@ -39,7 +39,7 @@ const deps = {
39
39
  "cache-manager": "5.x",
40
40
  sequelize: "6.x",
41
41
  umzug: "3.x",
42
- "async-mutex": "0.3.x",
42
+ "async-mutex": "0.5.x",
43
43
  "@formulajs/formulajs": "4.x",
44
44
  mathjs: "10.x",
45
45
  winston: "3.x",