@nocobase/server 1.2.13-alpha → 1.3.0-alpha.20240710084543

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 (124) hide show
  1. package/package.json +14 -14
  2. package/lib/acl/available-action.d.ts +0 -13
  3. package/lib/acl/available-action.js +0 -71
  4. package/lib/acl/index.d.ts +0 -10
  5. package/lib/acl/index.js +0 -46
  6. package/lib/app-command.d.ts +0 -20
  7. package/lib/app-command.js +0 -82
  8. package/lib/app-supervisor.d.ts +0 -69
  9. package/lib/app-supervisor.js +0 -302
  10. package/lib/application.d.ts +0 -345
  11. package/lib/application.js +0 -876
  12. package/lib/cache/index.d.ts +0 -11
  13. package/lib/cache/index.js +0 -44
  14. package/lib/commands/console.d.ts +0 -11
  15. package/lib/commands/console.js +0 -48
  16. package/lib/commands/create-migration.d.ts +0 -11
  17. package/lib/commands/create-migration.js +0 -79
  18. package/lib/commands/db-auth.d.ts +0 -11
  19. package/lib/commands/db-auth.js +0 -38
  20. package/lib/commands/db-clean.d.ts +0 -11
  21. package/lib/commands/db-clean.js +0 -41
  22. package/lib/commands/db-sync.d.ts +0 -11
  23. package/lib/commands/db-sync.js +0 -50
  24. package/lib/commands/destroy.d.ts +0 -11
  25. package/lib/commands/destroy.js +0 -40
  26. package/lib/commands/index.d.ts +0 -10
  27. package/lib/commands/index.js +0 -82
  28. package/lib/commands/install.d.ts +0 -11
  29. package/lib/commands/install.js +0 -43
  30. package/lib/commands/migrator.d.ts +0 -11
  31. package/lib/commands/migrator.js +0 -41
  32. package/lib/commands/pm.d.ts +0 -11
  33. package/lib/commands/pm.js +0 -98
  34. package/lib/commands/refresh.d.ts +0 -11
  35. package/lib/commands/refresh.js +0 -41
  36. package/lib/commands/restart.d.ts +0 -11
  37. package/lib/commands/restart.js +0 -45
  38. package/lib/commands/start.d.ts +0 -11
  39. package/lib/commands/start.js +0 -85
  40. package/lib/commands/stop.d.ts +0 -11
  41. package/lib/commands/stop.js +0 -44
  42. package/lib/commands/upgrade.d.ts +0 -14
  43. package/lib/commands/upgrade.js +0 -39
  44. package/lib/cron/cron-job-manager.d.ts +0 -22
  45. package/lib/cron/cron-job-manager.js +0 -82
  46. package/lib/errors/application-not-install.d.ts +0 -12
  47. package/lib/errors/application-not-install.js +0 -45
  48. package/lib/errors/handler.d.ts +0 -11
  49. package/lib/errors/handler.js +0 -50
  50. package/lib/errors/plugin-command-error.d.ts +0 -10
  51. package/lib/errors/plugin-command-error.js +0 -40
  52. package/lib/errors/plugin-not-exist.d.ts +0 -10
  53. package/lib/errors/plugin-not-exist.js +0 -40
  54. package/lib/gateway/errors.d.ts +0 -30
  55. package/lib/gateway/errors.js +0 -154
  56. package/lib/gateway/index.d.ts +0 -79
  57. package/lib/gateway/index.js +0 -393
  58. package/lib/gateway/ipc-socket-client.d.ts +0 -27
  59. package/lib/gateway/ipc-socket-client.js +0 -110
  60. package/lib/gateway/ipc-socket-server.d.ts +0 -21
  61. package/lib/gateway/ipc-socket-server.js +0 -150
  62. package/lib/gateway/ws-server.d.ts +0 -36
  63. package/lib/gateway/ws-server.js +0 -196
  64. package/lib/helper.d.ts +0 -18
  65. package/lib/helper.js +0 -193
  66. package/lib/helpers/application-version.d.ts +0 -18
  67. package/lib/helpers/application-version.js +0 -88
  68. package/lib/index.d.ts +0 -17
  69. package/lib/index.js +0 -64
  70. package/lib/locale/index.d.ts +0 -9
  71. package/lib/locale/index.js +0 -30
  72. package/lib/locale/locale.d.ts +0 -38
  73. package/lib/locale/locale.js +0 -174
  74. package/lib/locale/resource.d.ts +0 -9
  75. package/lib/locale/resource.js +0 -87
  76. package/lib/main-data-source.d.ts +0 -12
  77. package/lib/main-data-source.js +0 -57
  78. package/lib/middlewares/data-template.d.ts +0 -10
  79. package/lib/middlewares/data-template.js +0 -146
  80. package/lib/middlewares/data-wrapping.d.ts +0 -11
  81. package/lib/middlewares/data-wrapping.js +0 -100
  82. package/lib/middlewares/i18n.d.ts +0 -9
  83. package/lib/middlewares/i18n.js +0 -53
  84. package/lib/middlewares/index.d.ts +0 -10
  85. package/lib/middlewares/index.js +0 -39
  86. package/lib/middlewares/parse-variables.d.ts +0 -9
  87. package/lib/middlewares/parse-variables.js +0 -95
  88. package/lib/middlewares/validate-filter-params.d.ts +0 -9
  89. package/lib/middlewares/validate-filter-params.js +0 -42
  90. package/lib/migration.d.ts +0 -20
  91. package/lib/migration.js +0 -54
  92. package/lib/migrations/20230912193824-package-name-unique.d.ts +0 -14
  93. package/lib/migrations/20230912193824-package-name-unique.js +0 -59
  94. package/lib/migrations/20230912294620-update-pkg.d.ts +0 -14
  95. package/lib/migrations/20230912294620-update-pkg.js +0 -65
  96. package/lib/migrations/20240106082756-update-plugins.d.ts +0 -14
  97. package/lib/migrations/20240106082756-update-plugins.js +0 -51
  98. package/lib/migrations/20240428235620-rename-plugins.d.ts +0 -14
  99. package/lib/migrations/20240428235620-rename-plugins.js +0 -49
  100. package/lib/plugin-manager/clientStaticUtils.d.ts +0 -31
  101. package/lib/plugin-manager/clientStaticUtils.js +0 -129
  102. package/lib/plugin-manager/constants.d.ts +0 -15
  103. package/lib/plugin-manager/constants.js +0 -135
  104. package/lib/plugin-manager/deps.d.ts +0 -10
  105. package/lib/plugin-manager/deps.js +0 -83
  106. package/lib/plugin-manager/index.d.ts +0 -10
  107. package/lib/plugin-manager/index.js +0 -32
  108. package/lib/plugin-manager/middleware.d.ts +0 -10
  109. package/lib/plugin-manager/middleware.js +0 -45
  110. package/lib/plugin-manager/options/collection.d.ts +0 -10
  111. package/lib/plugin-manager/options/collection.js +0 -47
  112. package/lib/plugin-manager/options/resource.d.ts +0 -23
  113. package/lib/plugin-manager/options/resource.js +0 -186
  114. package/lib/plugin-manager/plugin-manager-repository.d.ts +0 -36
  115. package/lib/plugin-manager/plugin-manager-repository.js +0 -158
  116. package/lib/plugin-manager/plugin-manager.d.ts +0 -206
  117. package/lib/plugin-manager/plugin-manager.js +0 -1100
  118. package/lib/plugin-manager/types.d.ts +0 -23
  119. package/lib/plugin-manager/types.js +0 -24
  120. package/lib/plugin-manager/utils.d.ts +0 -115
  121. package/lib/plugin-manager/utils.js +0 -568
  122. package/lib/plugin.d.ts +0 -99
  123. package/lib/plugin.js +0 -228
  124. package/lib/swagger/index.json +0 -1569
@@ -1,568 +0,0 @@
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 utils_exports = {};
39
- __export(utils_exports, {
40
- checkAndGetCompatible: () => checkAndGetCompatible,
41
- checkCompatible: () => checkCompatible,
42
- copyTempPackageToStorageAndLinkToNodeModules: () => copyTempPackageToStorageAndLinkToNodeModules,
43
- download: () => download,
44
- downloadAndUnzipToTempDir: () => downloadAndUnzipToTempDir,
45
- getAuthorizationHeaders: () => getAuthorizationHeaders,
46
- getCompatible: () => getCompatible,
47
- getExcludePackages: () => getExcludePackages,
48
- getExternalVersionFromSource: () => getExternalVersionFromSource,
49
- getIncludePackages: () => getIncludePackages,
50
- getLatestVersion: () => getLatestVersion,
51
- getLocalPluginDir: () => getLocalPluginDir,
52
- getLocalPluginPackagesPathArr: () => getLocalPluginPackagesPathArr,
53
- getNewVersion: () => getNewVersion,
54
- getNodeModulesPluginDir: () => getNodeModulesPluginDir,
55
- getNpmInfo: () => getNpmInfo,
56
- getPackageJson: () => getPackageJson,
57
- getPackageJsonByLocalPath: () => getPackageJsonByLocalPath,
58
- getPackageNameFromString: () => getPackageNameFromString,
59
- getPackagesFromFiles: () => getPackagesFromFiles,
60
- getPluginBasePath: () => getPluginBasePath,
61
- getPluginInfoByNpm: () => getPluginInfoByNpm,
62
- getPluginStoragePath: () => getPluginStoragePath,
63
- getServerPackages: () => getServerPackages,
64
- getStoragePluginDir: () => getStoragePluginDir,
65
- getTempDir: () => getTempDir,
66
- isNotBuiltinModule: () => isNotBuiltinModule,
67
- isValidPackageName: () => isValidPackageName,
68
- readJSONFileContent: () => readJSONFileContent,
69
- removePluginPackage: () => removePluginPackage,
70
- removeRequireCache: () => removeRequireCache,
71
- removeTmpDir: () => removeTmpDir,
72
- requireModule: () => requireModule,
73
- requireNoCache: () => requireNoCache,
74
- updatePluginByCompressedFileUrl: () => updatePluginByCompressedFileUrl
75
- });
76
- module.exports = __toCommonJS(utils_exports);
77
- var import_utils = require("@nocobase/utils");
78
- var import_plugin_symlink = require("@nocobase/utils/plugin-symlink");
79
- var import_axios = __toESM(require("axios"));
80
- var import_decompress = __toESM(require("decompress"));
81
- var import_fast_glob = __toESM(require("fast-glob"));
82
- var import_fs_extra = __toESM(require("fs-extra"));
83
- var import_ini = __toESM(require("ini"));
84
- var import_module = require("module");
85
- var import_os = __toESM(require("os"));
86
- var import_path = __toESM(require("path"));
87
- var import_semver = __toESM(require("semver"));
88
- var import_clientStaticUtils = require("./clientStaticUtils");
89
- var import_constants = require("./constants");
90
- var import_deps = __toESM(require("./deps"));
91
- /* istanbul ignore next -- @preserve */
92
- async function getTempDir() {
93
- const temporaryDirectory = await import_fs_extra.default.realpath(import_os.default.tmpdir());
94
- return import_path.default.join(temporaryDirectory, import_constants.APP_NAME);
95
- }
96
- __name(getTempDir, "getTempDir");
97
- function getPluginStoragePath() {
98
- const pluginStoragePath = process.env.PLUGIN_STORAGE_PATH || import_constants.DEFAULT_PLUGIN_STORAGE_PATH;
99
- return import_path.default.isAbsolute(pluginStoragePath) ? pluginStoragePath : import_path.default.join(process.cwd(), pluginStoragePath);
100
- }
101
- __name(getPluginStoragePath, "getPluginStoragePath");
102
- function getLocalPluginPackagesPathArr() {
103
- const pluginPackagesPathArr = process.env.PLUGIN_PATH || import_constants.DEFAULT_PLUGIN_PATH;
104
- return pluginPackagesPathArr.split(",").map((pluginPackagesPath) => {
105
- pluginPackagesPath = pluginPackagesPath.trim();
106
- return import_path.default.isAbsolute(pluginPackagesPath) ? pluginPackagesPath : import_path.default.join(process.cwd(), pluginPackagesPath);
107
- });
108
- }
109
- __name(getLocalPluginPackagesPathArr, "getLocalPluginPackagesPathArr");
110
- function getStoragePluginDir(packageName) {
111
- const pluginStoragePath = getPluginStoragePath();
112
- return import_path.default.join(pluginStoragePath, packageName);
113
- }
114
- __name(getStoragePluginDir, "getStoragePluginDir");
115
- function getLocalPluginDir(packageDirBasename) {
116
- const localPluginDir = getLocalPluginPackagesPathArr().map((pluginPackagesPath) => import_path.default.join(pluginPackagesPath, packageDirBasename)).find((pluginDir) => import_fs_extra.default.existsSync(pluginDir));
117
- if (!localPluginDir) {
118
- throw new Error(`local plugin "${packageDirBasename}" not found`);
119
- }
120
- return localPluginDir;
121
- }
122
- __name(getLocalPluginDir, "getLocalPluginDir");
123
- function getNodeModulesPluginDir(packageName) {
124
- return import_path.default.join(process.env.NODE_MODULES_PATH, packageName);
125
- }
126
- __name(getNodeModulesPluginDir, "getNodeModulesPluginDir");
127
- function getAuthorizationHeaders(registry, authToken) {
128
- const headers = {};
129
- if (registry && !authToken) {
130
- const npmrcPath = import_path.default.join(import_os.default.homedir(), ".npmrc");
131
- const url = new URL(registry);
132
- let envConfig = process.env;
133
- if (import_fs_extra.default.existsSync(npmrcPath)) {
134
- const content = import_fs_extra.default.readFileSync(npmrcPath, "utf-8");
135
- envConfig = {
136
- ...envConfig,
137
- ...import_ini.default.parse(content)
138
- };
139
- }
140
- const key = Object.keys(envConfig).find((key2) => key2.includes(url.host) && key2.includes("_authToken"));
141
- if (key) {
142
- authToken = envConfig[key];
143
- }
144
- }
145
- if (authToken) {
146
- headers["Authorization"] = `Bearer ${authToken}`;
147
- }
148
- return headers;
149
- }
150
- __name(getAuthorizationHeaders, "getAuthorizationHeaders");
151
- async function getLatestVersion(packageName, registry, token) {
152
- const npmInfo = await getNpmInfo(packageName, registry, token);
153
- const latestVersion = npmInfo["dist-tags"].latest;
154
- return latestVersion;
155
- }
156
- __name(getLatestVersion, "getLatestVersion");
157
- async function getNpmInfo(packageName, registry, token) {
158
- registry.endsWith("/") && (registry = registry.slice(0, -1));
159
- const response = await import_axios.default.get(`${registry}/${packageName}`, {
160
- headers: getAuthorizationHeaders(registry, token)
161
- });
162
- try {
163
- const data = response.data;
164
- return data;
165
- } catch (e) {
166
- console.error(e);
167
- throw new Error(`${registry} is not a valid registry, '${registry}/${packageName}' response is not a valid json.`);
168
- }
169
- }
170
- __name(getNpmInfo, "getNpmInfo");
171
- async function download(url, destination, options = {}) {
172
- const response = await import_axios.default.get(url, {
173
- ...options,
174
- responseType: "stream"
175
- });
176
- import_fs_extra.default.mkdirpSync(import_path.default.dirname(destination));
177
- const writer = import_fs_extra.default.createWriteStream(destination);
178
- response.data.pipe(writer);
179
- return new Promise((resolve, reject) => {
180
- writer.on("finish", resolve);
181
- writer.on("error", reject);
182
- });
183
- }
184
- __name(download, "download");
185
- async function removeTmpDir(tempFile, tempPackageContentDir) {
186
- await import_fs_extra.default.remove(tempFile);
187
- await import_fs_extra.default.remove(tempPackageContentDir);
188
- }
189
- __name(removeTmpDir, "removeTmpDir");
190
- async function downloadAndUnzipToTempDir(fileUrl, authToken) {
191
- const fileName = import_path.default.basename(fileUrl);
192
- const tempDir = await getTempDir();
193
- const tempFile = import_path.default.join(tempDir, fileName);
194
- const tempPackageDir = tempFile.replace(import_path.default.extname(fileName), "");
195
- await import_fs_extra.default.remove(tempPackageDir);
196
- await import_fs_extra.default.remove(tempFile);
197
- if ((0, import_utils.isURL)(fileUrl)) {
198
- await download(fileUrl, tempFile, {
199
- headers: getAuthorizationHeaders(fileUrl, authToken)
200
- });
201
- } else if (await import_fs_extra.default.exists(fileUrl)) {
202
- await import_fs_extra.default.copy(fileUrl, tempFile);
203
- } else {
204
- throw new Error(`${fileUrl} does not exist`);
205
- }
206
- if (!import_fs_extra.default.existsSync(tempFile)) {
207
- throw new Error(`download ${fileUrl} failed`);
208
- }
209
- await (0, import_decompress.default)(tempFile, tempPackageDir);
210
- if (!import_fs_extra.default.existsSync(tempPackageDir)) {
211
- await import_fs_extra.default.remove(tempFile);
212
- throw new Error(`File is not a valid compressed file. Maybe the file need authorization.`);
213
- }
214
- let tempPackageContentDir = tempPackageDir;
215
- const files = import_fs_extra.default.readdirSync(tempPackageDir, { recursive: false, withFileTypes: true }).filter((item) => item.name !== "__MACOSX");
216
- if (files.length === 1 && files[0].isDirectory() && import_fs_extra.default.existsSync(import_path.default.join(tempPackageDir, files[0]["name"], "package.json"))) {
217
- tempPackageContentDir = import_path.default.join(tempPackageDir, files[0]["name"]);
218
- }
219
- const packageJsonPath = import_path.default.join(tempPackageContentDir, "package.json");
220
- if (!import_fs_extra.default.existsSync(packageJsonPath)) {
221
- await removeTmpDir(tempFile, tempPackageContentDir);
222
- throw new Error(`decompress ${fileUrl} failed`);
223
- }
224
- const packageJson = await readJSONFileContent(packageJsonPath);
225
- const mainFile = import_path.default.join(tempPackageContentDir, packageJson.main);
226
- if (!import_fs_extra.default.existsSync(mainFile)) {
227
- await removeTmpDir(tempFile, tempPackageContentDir);
228
- throw new Error(`main file ${packageJson.main} not found, Please check if the plugin has been built.`);
229
- }
230
- return {
231
- packageName: packageJson.name,
232
- version: packageJson.version,
233
- tempPackageContentDir,
234
- tempFile
235
- };
236
- }
237
- __name(downloadAndUnzipToTempDir, "downloadAndUnzipToTempDir");
238
- async function copyTempPackageToStorageAndLinkToNodeModules(tempFile, tempPackageContentDir, packageName) {
239
- const packageDir = getStoragePluginDir(packageName);
240
- await import_fs_extra.default.remove(packageDir);
241
- await import_fs_extra.default.move(tempPackageContentDir, packageDir, { overwrite: true });
242
- await (0, import_plugin_symlink.createStoragePluginSymLink)(packageName);
243
- await removeTmpDir(tempFile, tempPackageContentDir);
244
- return {
245
- packageDir
246
- };
247
- }
248
- __name(copyTempPackageToStorageAndLinkToNodeModules, "copyTempPackageToStorageAndLinkToNodeModules");
249
- async function getPluginInfoByNpm(options) {
250
- let { registry, version } = options;
251
- const { packageName, authToken } = options;
252
- if (registry.endsWith("/")) {
253
- registry = registry.slice(0, -1);
254
- }
255
- if (!version) {
256
- version = await getLatestVersion(packageName, registry, authToken);
257
- }
258
- const compressedFileUrl = `${registry}/${packageName}/-/${packageName.split("/").pop()}-${version}.tgz`;
259
- return { compressedFileUrl, version };
260
- }
261
- __name(getPluginInfoByNpm, "getPluginInfoByNpm");
262
- function getServerPackages(packageDir) {
263
- function isBuiltinModule(packageName) {
264
- return import_module.builtinModules.includes(packageName);
265
- }
266
- __name(isBuiltinModule, "isBuiltinModule");
267
- function getSrcPlugins(sourceDir) {
268
- const importedPlugins = /* @__PURE__ */ new Set();
269
- const exts = [".js", ".ts", ".jsx", ".tsx"];
270
- const importRegex2 = /import\s+.*?\s+from\s+['"]([^'"\s.].+?)['"];?/g;
271
- const requireRegex2 = /require\s*\(\s*[`'"]([^`'"\s.].+?)[`'"]\s*\)/g;
272
- function setPluginsFromContent(reg, content) {
273
- let match;
274
- while (match = reg.exec(content)) {
275
- let importedPlugin = match[1];
276
- if (importedPlugin.startsWith("@")) {
277
- importedPlugin = importedPlugin.split("/").slice(0, 2).join("/");
278
- } else {
279
- importedPlugin = importedPlugin.split("/")[0];
280
- }
281
- if (!isBuiltinModule(importedPlugin)) {
282
- importedPlugins.add(importedPlugin);
283
- }
284
- }
285
- }
286
- __name(setPluginsFromContent, "setPluginsFromContent");
287
- function traverseDirectory(directory) {
288
- const files = import_fs_extra.default.readdirSync(directory);
289
- for (const file of files) {
290
- const filePath = import_path.default.join(directory, file);
291
- const stat = import_fs_extra.default.statSync(filePath);
292
- if (stat.isDirectory()) {
293
- traverseDirectory(filePath);
294
- } else if (stat.isFile() && !filePath.includes("__tests__")) {
295
- if (exts.includes(import_path.default.extname(filePath).toLowerCase())) {
296
- const content = import_fs_extra.default.readFileSync(filePath, "utf-8");
297
- setPluginsFromContent(importRegex2, content);
298
- setPluginsFromContent(requireRegex2, content);
299
- }
300
- }
301
- }
302
- }
303
- __name(traverseDirectory, "traverseDirectory");
304
- traverseDirectory(sourceDir);
305
- return [...importedPlugins];
306
- }
307
- __name(getSrcPlugins, "getSrcPlugins");
308
- const srcServerPlugins = getSrcPlugins(import_path.default.join(packageDir, "src/server"));
309
- return srcServerPlugins;
310
- }
311
- __name(getServerPackages, "getServerPackages");
312
- function removePluginPackage(packageName) {
313
- const packageDir = getStoragePluginDir(packageName);
314
- const nodeModulesPluginDir = getNodeModulesPluginDir(packageName);
315
- return Promise.all([import_fs_extra.default.remove(packageDir), import_fs_extra.default.remove(nodeModulesPluginDir)]);
316
- }
317
- __name(removePluginPackage, "removePluginPackage");
318
- async function getPackageJson(pluginName) {
319
- const packageDir = getStoragePluginDir(pluginName);
320
- return await getPackageJsonByLocalPath(packageDir);
321
- }
322
- __name(getPackageJson, "getPackageJson");
323
- async function getPackageJsonByLocalPath(localPath) {
324
- if (!import_fs_extra.default.existsSync(localPath)) {
325
- return null;
326
- } else {
327
- const fullPath = import_path.default.join(localPath, "package.json");
328
- const data = await import_fs_extra.default.promises.readFile(fullPath, { encoding: "utf-8" });
329
- return JSON.parse(data);
330
- }
331
- }
332
- __name(getPackageJsonByLocalPath, "getPackageJsonByLocalPath");
333
- async function updatePluginByCompressedFileUrl(options) {
334
- const { packageName, version, tempFile, tempPackageContentDir } = await downloadAndUnzipToTempDir(
335
- options.compressedFileUrl,
336
- options.authToken
337
- );
338
- const instance = await options.repository.findOne({
339
- filter: { packageName }
340
- });
341
- if (!instance) {
342
- await removeTmpDir(tempFile, tempPackageContentDir);
343
- throw new Error(`plugin ${packageName} does not exist`);
344
- }
345
- const { packageDir } = await copyTempPackageToStorageAndLinkToNodeModules(
346
- tempFile,
347
- tempPackageContentDir,
348
- packageName
349
- );
350
- return {
351
- packageName,
352
- packageDir,
353
- version
354
- };
355
- }
356
- __name(updatePluginByCompressedFileUrl, "updatePluginByCompressedFileUrl");
357
- async function getNewVersion(plugin) {
358
- if (!(plugin.packageName && plugin.registry))
359
- return false;
360
- const { version } = await getPluginInfoByNpm({
361
- packageName: plugin.packageName,
362
- registry: plugin.registry,
363
- authToken: plugin.authToken
364
- });
365
- return version !== plugin.version ? version : false;
366
- }
367
- __name(getNewVersion, "getNewVersion");
368
- function removeRequireCache(fileOrPackageName) {
369
- delete require.cache[require.resolve(fileOrPackageName)];
370
- delete require.cache[fileOrPackageName];
371
- }
372
- __name(removeRequireCache, "removeRequireCache");
373
- async function requireNoCache(fileOrPackageName) {
374
- return await (0, import_utils.importModule)(fileOrPackageName);
375
- }
376
- __name(requireNoCache, "requireNoCache");
377
- async function readJSONFileContent(filePath) {
378
- const data = await import_fs_extra.default.promises.readFile(filePath, { encoding: "utf-8" });
379
- return JSON.parse(data);
380
- }
381
- __name(readJSONFileContent, "readJSONFileContent");
382
- function requireModule(m) {
383
- if (typeof m === "string") {
384
- m = require(m);
385
- }
386
- if (typeof m !== "object") {
387
- return m;
388
- }
389
- return m.__esModule ? m.default : m;
390
- }
391
- __name(requireModule, "requireModule");
392
- async function getExternalVersionFromDistFile(packageName) {
393
- const { exists, filePath } = (0, import_clientStaticUtils.getPackageFilePathWithExistCheck)(packageName, "dist/externalVersion.js");
394
- if (!exists) {
395
- return false;
396
- }
397
- try {
398
- return await requireNoCache(filePath);
399
- } catch (e) {
400
- console.error(e);
401
- return false;
402
- }
403
- }
404
- __name(getExternalVersionFromDistFile, "getExternalVersionFromDistFile");
405
- function isNotBuiltinModule(packageName) {
406
- return !import_module.builtinModules.includes(packageName);
407
- }
408
- __name(isNotBuiltinModule, "isNotBuiltinModule");
409
- const isValidPackageName = /* @__PURE__ */ __name((str) => {
410
- const pattern = /^(?:@[a-zA-Z0-9_-]+\/)?[a-zA-Z0-9_-]+$/;
411
- return pattern.test(str);
412
- }, "isValidPackageName");
413
- function getPackageNameFromString(str) {
414
- if (str.startsWith("."))
415
- return null;
416
- const arr = str.split("/");
417
- let packageName;
418
- if (arr[0].startsWith("@")) {
419
- packageName = arr.slice(0, 2).join("/");
420
- } else {
421
- packageName = arr[0];
422
- }
423
- packageName = packageName.trim();
424
- return isValidPackageName(packageName) ? packageName : null;
425
- }
426
- __name(getPackageNameFromString, "getPackageNameFromString");
427
- function getPackagesFromFiles(files) {
428
- const packageNames = files.map((item) => [
429
- ...[...item.matchAll(import_constants.importRegex)].map((item2) => item2[2]),
430
- ...[...item.matchAll(import_constants.requireRegex)].map((item2) => item2[1])
431
- ]).flat().map(getPackageNameFromString).filter(Boolean).filter(isNotBuiltinModule);
432
- return [...new Set(packageNames)];
433
- }
434
- __name(getPackagesFromFiles, "getPackagesFromFiles");
435
- function getIncludePackages(sourcePackages, external, pluginPrefix2) {
436
- return sourcePackages.filter((packageName) => !external.includes(packageName)).filter((packageName) => !pluginPrefix2.some((prefix) => packageName.startsWith(prefix)));
437
- }
438
- __name(getIncludePackages, "getIncludePackages");
439
- function getExcludePackages(sourcePackages, external, pluginPrefix2) {
440
- const includePackages = getIncludePackages(sourcePackages, external, pluginPrefix2);
441
- return sourcePackages.filter((packageName) => !includePackages.includes(packageName));
442
- }
443
- __name(getExcludePackages, "getExcludePackages");
444
- async function getExternalVersionFromSource(packageName) {
445
- const packageDir = (0, import_clientStaticUtils.getPackageDir)(packageName);
446
- const sourceGlobalFiles = ["src/**/*.{ts,js,tsx,jsx}", "!src/**/__tests__"];
447
- const sourceFilePaths = await import_fast_glob.default.glob(sourceGlobalFiles, { cwd: packageDir, absolute: true });
448
- const sourceFiles = await Promise.all(sourceFilePaths.map((item) => import_fs_extra.default.readFile(item, "utf-8")));
449
- const sourcePackages = getPackagesFromFiles(sourceFiles);
450
- const excludePackages = getExcludePackages(sourcePackages, import_constants.EXTERNAL, import_constants.pluginPrefix);
451
- const data = excludePackages.reduce((prev, packageName2) => {
452
- const depPkgPath = (0, import_clientStaticUtils.getDepPkgPath)(packageName2, packageDir);
453
- const depPkg = require(depPkgPath);
454
- prev[packageName2] = depPkg.version;
455
- return prev;
456
- }, {});
457
- return data;
458
- }
459
- __name(getExternalVersionFromSource, "getExternalVersionFromSource");
460
- async function getCompatible(packageName) {
461
- let externalVersion;
462
- const hasSrc = import_fs_extra.default.existsSync(import_path.default.join((0, import_clientStaticUtils.getPackageDir)(packageName), "src"));
463
- let hasError = false;
464
- if (hasSrc) {
465
- try {
466
- externalVersion = await getExternalVersionFromSource(packageName);
467
- } catch {
468
- hasError = true;
469
- }
470
- }
471
- if (hasError || !hasSrc) {
472
- const res = await getExternalVersionFromDistFile(packageName);
473
- if (!res) {
474
- return false;
475
- } else {
476
- externalVersion = res;
477
- }
478
- }
479
- return Object.keys(externalVersion).reduce((result, packageName2) => {
480
- const packageVersion = externalVersion[packageName2];
481
- const globalPackageName = import_deps.default[packageName2] ? packageName2 : import_deps.default[packageName2.split("/")[0]] ? packageName2.split("/")[0] : void 0;
482
- if (globalPackageName) {
483
- const versionRange = import_deps.default[globalPackageName];
484
- result.push({
485
- name: packageName2,
486
- result: import_semver.default.satisfies(packageVersion, versionRange, { includePrerelease: true }),
487
- versionRange,
488
- packageVersion
489
- });
490
- }
491
- return result;
492
- }, []);
493
- }
494
- __name(getCompatible, "getCompatible");
495
- async function checkCompatible(packageName) {
496
- const compatible = await getCompatible(packageName);
497
- if (!compatible)
498
- return false;
499
- return compatible.every((item) => item.result);
500
- }
501
- __name(checkCompatible, "checkCompatible");
502
- async function checkAndGetCompatible(packageName) {
503
- const compatible = await getCompatible(packageName);
504
- if (!compatible) {
505
- return {
506
- isCompatible: false,
507
- depsCompatible: []
508
- };
509
- }
510
- return {
511
- isCompatible: compatible.every((item) => item.result),
512
- depsCompatible: compatible
513
- };
514
- }
515
- __name(checkAndGetCompatible, "checkAndGetCompatible");
516
- async function getPluginBasePath(packageName) {
517
- if (!packageName) {
518
- return;
519
- }
520
- const file = await import_fs_extra.default.realpath(await (0, import_utils.requireResolve)(packageName));
521
- try {
522
- const basePath = await import_fs_extra.default.realpath(import_path.default.resolve(process.env.NODE_MODULES_PATH, packageName, "src"));
523
- if (file.startsWith(basePath)) {
524
- return basePath;
525
- }
526
- } catch (error) {
527
- }
528
- return import_path.default.dirname(import_path.default.dirname(file));
529
- }
530
- __name(getPluginBasePath, "getPluginBasePath");
531
- // Annotate the CommonJS export names for ESM import in node:
532
- 0 && (module.exports = {
533
- checkAndGetCompatible,
534
- checkCompatible,
535
- copyTempPackageToStorageAndLinkToNodeModules,
536
- download,
537
- downloadAndUnzipToTempDir,
538
- getAuthorizationHeaders,
539
- getCompatible,
540
- getExcludePackages,
541
- getExternalVersionFromSource,
542
- getIncludePackages,
543
- getLatestVersion,
544
- getLocalPluginDir,
545
- getLocalPluginPackagesPathArr,
546
- getNewVersion,
547
- getNodeModulesPluginDir,
548
- getNpmInfo,
549
- getPackageJson,
550
- getPackageJsonByLocalPath,
551
- getPackageNameFromString,
552
- getPackagesFromFiles,
553
- getPluginBasePath,
554
- getPluginInfoByNpm,
555
- getPluginStoragePath,
556
- getServerPackages,
557
- getStoragePluginDir,
558
- getTempDir,
559
- isNotBuiltinModule,
560
- isValidPackageName,
561
- readJSONFileContent,
562
- removePluginPackage,
563
- removeRequireCache,
564
- removeTmpDir,
565
- requireModule,
566
- requireNoCache,
567
- updatePluginByCompressedFileUrl
568
- });
package/lib/plugin.d.ts DELETED
@@ -1,99 +0,0 @@
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 { Model } from '@nocobase/database';
10
- import { LoggerOptions } from '@nocobase/logger';
11
- import type { TFuncKey, TOptions } from 'i18next';
12
- import { Application } from './application';
13
- import { InstallOptions } from './plugin-manager';
14
- export interface PluginInterface {
15
- beforeLoad?: () => void;
16
- load(): any;
17
- getName(): string;
18
- }
19
- export interface PluginOptions {
20
- activate?: boolean;
21
- displayName?: string;
22
- description?: string;
23
- version?: string;
24
- enabled?: boolean;
25
- install?: (this: Plugin) => void;
26
- load?: (this: Plugin) => void;
27
- plugin?: typeof Plugin;
28
- [key: string]: any;
29
- }
30
- export declare abstract class Plugin<O = any> implements PluginInterface {
31
- options: any;
32
- app: Application;
33
- /**
34
- * @deprecated
35
- */
36
- model: Model;
37
- /**
38
- * @internal
39
- */
40
- state: any;
41
- /**
42
- * @internal
43
- */
44
- private _sourceDir;
45
- constructor(app: Application, options?: any);
46
- get log(): import("@nocobase/logger/lib/logger").Logger;
47
- get name(): string;
48
- get pm(): import("./plugin-manager").PluginManager;
49
- get db(): import("@nocobase/database").default;
50
- get enabled(): any;
51
- set enabled(value: any);
52
- get installed(): any;
53
- set installed(value: any);
54
- get isPreset(): any;
55
- getName(): any;
56
- createLogger(options: LoggerOptions): import("@nocobase/logger/lib/logger").Logger;
57
- afterAdd(): void;
58
- beforeLoad(): void;
59
- load(): Promise<void>;
60
- install(options?: InstallOptions): Promise<void>;
61
- upgrade(): Promise<void>;
62
- beforeEnable(): Promise<void>;
63
- afterEnable(): Promise<void>;
64
- beforeDisable(): Promise<void>;
65
- afterDisable(): Promise<void>;
66
- beforeRemove(): Promise<void>;
67
- afterRemove(): Promise<void>;
68
- /**
69
- * @deprecated
70
- */
71
- importCollections(collectionsPath: string): Promise<void>;
72
- /**
73
- * @internal
74
- */
75
- setOptions(options: any): void;
76
- /**
77
- * @internal
78
- */
79
- loadMigrations(): Promise<{
80
- beforeLoad: any[];
81
- afterSync: any[];
82
- afterLoad: any[];
83
- }>;
84
- private getPluginBasePath;
85
- /**
86
- * @internal
87
- */
88
- loadCollections(): Promise<void>;
89
- /**
90
- * @deprecated
91
- */
92
- requiredPlugins(): any[];
93
- t(text: TFuncKey | TFuncKey[], options?: TOptions): import("i18next").TFunctionDetailedResult<object>;
94
- /**
95
- * @experimental
96
- */
97
- toJSON(options?: any): Promise<any>;
98
- }
99
- export default Plugin;