@nocobase/server 2.1.0-beta.30 → 2.1.0-beta.33

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.
@@ -0,0 +1,9 @@
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
+ export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
@@ -0,0 +1,36 @@
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 __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var constants_exports = {};
28
+ __export(constants_exports, {
29
+ OFFICIAL_PLUGIN_PREFIX: () => OFFICIAL_PLUGIN_PREFIX
30
+ });
31
+ module.exports = __toCommonJS(constants_exports);
32
+ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ OFFICIAL_PLUGIN_PREFIX
36
+ });
@@ -66,6 +66,7 @@ var import_plugin_manager = require("../plugin-manager");
66
66
  var import_errors = require("./errors");
67
67
  var import_ipc_socket_client = require("./ipc-socket-client");
68
68
  var import_ipc_socket_server = require("./ipc-socket-server");
69
+ var import_static_file_security = require("./static-file-security");
69
70
  var import_utils3 = require("./utils");
70
71
  var import_ws_server = require("./ws-server");
71
72
  var import_node_worker_threads = require("node:worker_threads");
@@ -286,6 +287,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
286
287
  getV2RuntimeConfig() {
287
288
  return {
288
289
  __nocobase_public_path__: this.getV2PublicPath(),
290
+ __webpack_public_path__: import_node_process.default.env.CDN_BASE_URL ? `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/` : "",
289
291
  __nocobase_api_base_url__: import_node_process.default.env.API_BASE_URL || import_node_process.default.env.API_BASE_PATH,
290
292
  __nocobase_api_client_storage_prefix__: import_node_process.default.env.API_CLIENT_STORAGE_PREFIX,
291
293
  __nocobase_api_client_storage_type__: import_node_process.default.env.API_CLIENT_STORAGE_TYPE,
@@ -357,6 +359,10 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
357
359
  return;
358
360
  }
359
361
  }
362
+ const headers = (0, import_static_file_security.getStorageUploadSecurityHeaders)(pathname);
363
+ for (const [key, value] of Object.entries(headers)) {
364
+ res.setHeader(key, value);
365
+ }
360
366
  req.url = req.url.substring(APP_PUBLIC_PATH.length + "storage".length);
361
367
  await compress(req, res);
362
368
  return (0, import_serve_handler.default)(req, res, {
@@ -0,0 +1,10 @@
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
+ export declare function hasActiveContentExtension(pathname?: string): boolean;
10
+ export declare function getStorageUploadSecurityHeaders(pathname?: string): Record<string, string>;
@@ -0,0 +1,69 @@
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 static_file_security_exports = {};
39
+ __export(static_file_security_exports, {
40
+ getStorageUploadSecurityHeaders: () => getStorageUploadSecurityHeaders,
41
+ hasActiveContentExtension: () => hasActiveContentExtension
42
+ });
43
+ module.exports = __toCommonJS(static_file_security_exports);
44
+ var import_node_path = __toESM(require("node:path"));
45
+ const ACTIVE_CONTENT_EXTENSIONS = /* @__PURE__ */ new Set([".htm", ".html", ".svg", ".svgz", ".xhtml"]);
46
+ function stripQueryAndHash(pathname = "") {
47
+ return pathname.split("?")[0].split("#")[0];
48
+ }
49
+ __name(stripQueryAndHash, "stripQueryAndHash");
50
+ function hasActiveContentExtension(pathname = "") {
51
+ const ext = import_node_path.default.extname(stripQueryAndHash(pathname)).toLowerCase();
52
+ return ACTIVE_CONTENT_EXTENSIONS.has(ext);
53
+ }
54
+ __name(hasActiveContentExtension, "hasActiveContentExtension");
55
+ function getStorageUploadSecurityHeaders(pathname = "") {
56
+ const headers = {
57
+ "X-Content-Type-Options": "nosniff"
58
+ };
59
+ if (hasActiveContentExtension(pathname)) {
60
+ headers["Content-Disposition"] = "attachment";
61
+ }
62
+ return headers;
63
+ }
64
+ __name(getStorageUploadSecurityHeaders, "getStorageUploadSecurityHeaders");
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ getStorageUploadSecurityHeaders,
68
+ hasActiveContentExtension
69
+ });
package/lib/index.d.ts CHANGED
@@ -23,7 +23,8 @@ export * from './worker-id-allocator';
23
23
  export * from './worker-mode';
24
24
  export * from './redis-connection-manager';
25
25
  export * from './main-data-source';
26
- export declare const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
26
+ export * from './constants';
27
+ export type { LocaleSource, LocaleSourceText } from './locale';
27
28
  export { appendToBuiltInPlugins, findAllPlugins, findBuiltInPlugins, findLocalPlugins, packageNameTrim, } from './plugin-manager/findPackageNames';
28
29
  export { runPluginStaticImports } from './run-plugin-static-imports';
29
30
  export { createContextVariablesScope } from './helper';
package/lib/index.js CHANGED
@@ -37,7 +37,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
  var src_exports = {};
39
39
  __export(src_exports, {
40
- OFFICIAL_PLUGIN_PREFIX: () => OFFICIAL_PLUGIN_PREFIX,
41
40
  appendToBuiltInPlugins: () => import_findPackageNames.appendToBuiltInPlugins,
42
41
  createContextVariablesScope: () => import_helper.createContextVariablesScope,
43
42
  default: () => import_application.Application,
@@ -66,13 +65,12 @@ __reExport(src_exports, require("./worker-id-allocator"), module.exports);
66
65
  __reExport(src_exports, require("./worker-mode"), module.exports);
67
66
  __reExport(src_exports, require("./redis-connection-manager"), module.exports);
68
67
  __reExport(src_exports, require("./main-data-source"), module.exports);
68
+ __reExport(src_exports, require("./constants"), module.exports);
69
69
  var import_findPackageNames = require("./plugin-manager/findPackageNames");
70
70
  var import_run_plugin_static_imports = require("./run-plugin-static-imports");
71
71
  var import_helper = require("./helper");
72
- const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
73
72
  // Annotate the CommonJS export names for ESM import in node:
74
73
  0 && (module.exports = {
75
- OFFICIAL_PLUGIN_PREFIX,
76
74
  appendToBuiltInPlugins,
77
75
  createContextVariablesScope,
78
76
  findAllPlugins,
@@ -95,5 +93,6 @@ const OFFICIAL_PLUGIN_PREFIX = "@nocobase/plugin-";
95
93
  ...require("./worker-id-allocator"),
96
94
  ...require("./worker-mode"),
97
95
  ...require("./redis-connection-manager"),
98
- ...require("./main-data-source")
96
+ ...require("./main-data-source"),
97
+ ...require("./constants")
99
98
  });
@@ -15,6 +15,24 @@ export interface ResourceStorer {
15
15
  }>;
16
16
  reset?: () => Promise<void>;
17
17
  }
18
+ export type LocaleSourceText = {
19
+ text: string;
20
+ module: string;
21
+ };
22
+ export type LocaleSource = {
23
+ title: string;
24
+ sync?: (ctx: any) => Promise<{
25
+ [module: string]: {
26
+ [text: string]: string;
27
+ };
28
+ }>;
29
+ namespace?: string;
30
+ collections?: {
31
+ collection: string;
32
+ fields?: string[];
33
+ getTexts?: (instance: any, options?: any) => LocaleSourceText[] | Promise<LocaleSourceText[]>;
34
+ }[];
35
+ };
18
36
  export declare class Locale {
19
37
  app: Application;
20
38
  cache: Cache;
@@ -23,18 +41,24 @@ export declare class Locale {
23
41
  resourceCached: Map<any, any>;
24
42
  i18nInstances: Map<any, any>;
25
43
  resourceStorers: Registry<ResourceStorer>;
44
+ sources: Registry<LocaleSource>;
26
45
  constructor(app: Application);
27
46
  load(): Promise<void>;
28
47
  reset(): Promise<void>;
29
48
  reload(): Promise<void>;
30
49
  setLocaleFn(name: string, fn: (lang: string) => Promise<any>): void;
31
50
  registerResourceStorer(name: string, storer: ResourceStorer): void;
51
+ registerSource(name: string, source: LocaleSource): void;
52
+ syncSources(ctx: any, types: string[]): Promise<{
53
+ [module: string]: any;
54
+ }>;
32
55
  get(lang: string): Promise<{
33
56
  resources: any;
34
57
  }>;
35
58
  wrapCache(key: string, fn: () => any): Promise<any>;
36
59
  loadResourcesByLang(lang: string): Promise<void>;
37
60
  getCacheResources(lang: string): Promise<any>;
61
+ getBuiltInResources(lang: string): Promise<{}>;
38
62
  getResources(lang: string): Promise<{}>;
39
63
  getI18nInstance(lang: string): Promise<any>;
40
64
  }
@@ -41,8 +41,8 @@ __export(locale_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(locale_exports);
43
43
  var import_utils = require("@nocobase/utils");
44
+ var import_constants = require("../constants");
44
45
  var import_resource = require("./resource");
45
- var import__ = require("..");
46
46
  var import_deepmerge = __toESM(require("deepmerge"));
47
47
  const _Locale = class _Locale {
48
48
  app;
@@ -52,6 +52,7 @@ const _Locale = class _Locale {
52
52
  resourceCached = /* @__PURE__ */ new Map();
53
53
  i18nInstances = /* @__PURE__ */ new Map();
54
54
  resourceStorers = new import_utils.Registry();
55
+ sources = new import_utils.Registry();
55
56
  constructor(app) {
56
57
  this.app = app;
57
58
  this.app.on("afterLoad", async () => {
@@ -92,6 +93,25 @@ const _Locale = class _Locale {
92
93
  registerResourceStorer(name, storer) {
93
94
  this.resourceStorers.register(name, storer);
94
95
  }
96
+ registerSource(name, source) {
97
+ this.sources.register(name, source);
98
+ }
99
+ async syncSources(ctx, types) {
100
+ const resources = { client: {} };
101
+ const sources = Array.from(this.sources.getKeys());
102
+ const syncSources = sources.filter((source) => types.includes(source) && this.sources.get(source).sync);
103
+ const promises = syncSources.map((source) => this.sources.get(source).sync(ctx));
104
+ const results = await Promise.all(promises);
105
+ return results.reduce((result, resource) => {
106
+ Object.entries(resource).forEach(([module2, texts]) => {
107
+ result[module2] = {
108
+ ...result[module2] || {},
109
+ ...texts
110
+ };
111
+ });
112
+ return result;
113
+ }, resources);
114
+ }
95
115
  async get(lang) {
96
116
  const defaults = {
97
117
  resources: await this.getCacheResources(lang)
@@ -124,7 +144,7 @@ const _Locale = class _Locale {
124
144
  }
125
145
  return await this.wrapCache(`resources:${lang}`, () => this.getResources(lang));
126
146
  }
127
- async getResources(lang) {
147
+ async getBuiltInResources(lang) {
128
148
  var _a;
129
149
  const resources = {};
130
150
  const names = this.app.pm.getPlugins().keys();
@@ -141,13 +161,17 @@ const _Locale = class _Locale {
141
161
  const res = await (0, import_resource.getResource)(packageName, lang);
142
162
  if (res) {
143
163
  resources[packageName] = { ...res };
144
- if (packageName.includes(import__.OFFICIAL_PLUGIN_PREFIX)) {
145
- resources[packageName.substring(import__.OFFICIAL_PLUGIN_PREFIX.length)] = { ...res };
164
+ if (packageName.includes(import_constants.OFFICIAL_PLUGIN_PREFIX)) {
165
+ resources[packageName.substring(import_constants.OFFICIAL_PLUGIN_PREFIX.length)] = { ...res };
146
166
  }
147
167
  }
148
168
  } catch (err) {
149
169
  }
150
170
  }
171
+ return resources;
172
+ }
173
+ async getResources(lang) {
174
+ const resources = await this.getBuiltInResources(lang);
151
175
  const storers = this.resourceStorers.getValues();
152
176
  for (const storer of storers) {
153
177
  const custom = await storer.getResources(lang);
@@ -156,7 +180,7 @@ const _Locale = class _Locale {
156
180
  const resource = resources[module2];
157
181
  const customResource = custom[key];
158
182
  resources[module2] = resource ? (0, import_deepmerge.default)(resource, customResource) : customResource;
159
- const pkgName = `${import__.OFFICIAL_PLUGIN_PREFIX}${module2}`;
183
+ const pkgName = `${import_constants.OFFICIAL_PLUGIN_PREFIX}${module2}`;
160
184
  if (resources[pkgName]) {
161
185
  resources[pkgName] = { ...resources[module2] };
162
186
  }
@@ -135,12 +135,19 @@ async function listEnabledPlugins(ctx, lane = "client") {
135
135
  const url = await PackageUrls.get(item.packageName, lane);
136
136
  const { name, packageName, options } = item.toJSON();
137
137
  if (url) {
138
- arr.push({
138
+ const entry = {
139
139
  name,
140
140
  packageName,
141
141
  options,
142
142
  url
143
- });
143
+ };
144
+ if (lane === "client" && await PackageUrls.hasClientEntry(packageName, "client-v2")) {
145
+ const clientV2Url = await PackageUrls.get(packageName, "client-v2");
146
+ if (clientV2Url) {
147
+ entry.clientV2Url = clientV2Url;
148
+ }
149
+ }
150
+ arr.push(entry);
144
151
  }
145
152
  }
146
153
  return arr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.1.0-beta.30",
3
+ "version": "2.1.0-beta.33",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -10,21 +10,21 @@
10
10
  "@koa/cors": "^5.0.0",
11
11
  "@koa/multer": "^3.1.0",
12
12
  "@koa/router": "^13.1.0",
13
- "@nocobase/acl": "2.1.0-beta.30",
14
- "@nocobase/actions": "2.1.0-beta.30",
15
- "@nocobase/ai": "2.1.0-beta.30",
16
- "@nocobase/auth": "2.1.0-beta.30",
17
- "@nocobase/cache": "2.1.0-beta.30",
18
- "@nocobase/data-source-manager": "2.1.0-beta.30",
19
- "@nocobase/database": "2.1.0-beta.30",
20
- "@nocobase/evaluators": "2.1.0-beta.30",
21
- "@nocobase/lock-manager": "2.1.0-beta.30",
22
- "@nocobase/logger": "2.1.0-beta.30",
23
- "@nocobase/resourcer": "2.1.0-beta.30",
24
- "@nocobase/sdk": "2.1.0-beta.30",
25
- "@nocobase/snowflake-id": "2.1.0-beta.30",
26
- "@nocobase/telemetry": "2.1.0-beta.30",
27
- "@nocobase/utils": "2.1.0-beta.30",
13
+ "@nocobase/acl": "2.1.0-beta.33",
14
+ "@nocobase/actions": "2.1.0-beta.33",
15
+ "@nocobase/ai": "2.1.0-beta.33",
16
+ "@nocobase/auth": "2.1.0-beta.33",
17
+ "@nocobase/cache": "2.1.0-beta.33",
18
+ "@nocobase/data-source-manager": "2.1.0-beta.33",
19
+ "@nocobase/database": "2.1.0-beta.33",
20
+ "@nocobase/evaluators": "2.1.0-beta.33",
21
+ "@nocobase/lock-manager": "2.1.0-beta.33",
22
+ "@nocobase/logger": "2.1.0-beta.33",
23
+ "@nocobase/resourcer": "2.1.0-beta.33",
24
+ "@nocobase/sdk": "2.1.0-beta.33",
25
+ "@nocobase/snowflake-id": "2.1.0-beta.33",
26
+ "@nocobase/telemetry": "2.1.0-beta.33",
27
+ "@nocobase/utils": "2.1.0-beta.33",
28
28
  "@types/decompress": "4.2.7",
29
29
  "@types/ini": "^1.3.31",
30
30
  "@types/koa-send": "^4.1.3",
@@ -61,5 +61,5 @@
61
61
  "@types/serve-handler": "^6.1.1",
62
62
  "@types/ws": "^8.5.5"
63
63
  },
64
- "gitHead": "1a493069cd0d8a4f403668bfe592879678c894b2"
64
+ "gitHead": "4815c394e80a264fa8ed619246280923c47aeb72"
65
65
  }