@nocobase/plugin-license 2.0.0-alpha.9 → 2.0.0-beta.1
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/client/LicenseSettingContext.d.ts +16 -0
- package/dist/client/ServiceValidate.d.ts +12 -0
- package/dist/client/index.js +1 -1
- package/dist/client/locale.d.ts +1 -1
- package/dist/client/useSubmitProps.d.ts +12 -0
- package/dist/externalVersion.js +9 -3
- package/dist/locale/de-DE.json +13 -0
- package/dist/locale/en-US.json +33 -9
- package/dist/locale/es-ES.json +13 -0
- package/dist/locale/fr-FR.json +13 -0
- package/dist/locale/hu-HU.json +13 -0
- package/dist/locale/id-ID.json +13 -0
- package/dist/locale/it-IT.json +13 -0
- package/dist/locale/ja-JP.json +13 -0
- package/dist/locale/ko-KR.json +13 -0
- package/dist/locale/nl-NL.json +13 -1
- package/dist/locale/pt-BR.json +13 -0
- package/dist/locale/ru-RU.json +13 -0
- package/dist/locale/tr-TR.json +13 -0
- package/dist/locale/uk-UA.json +13 -0
- package/dist/locale/vi-VN.json +13 -0
- package/dist/locale/zh-CN.json +32 -8
- package/dist/locale/zh-TW.json +13 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +6 -0
- package/dist/server/plugin.js +69 -6
- package/dist/server/utils/env.d.ts +16 -0
- package/dist/server/utils/env.js +125 -0
- package/dist/server/utils/index.d.ts +15 -0
- package/dist/server/utils/index.js +42 -0
- package/dist/server/{utils.d.ts → utils/instance.d.ts} +0 -1
- package/dist/server/{utils.js → utils/instance.js} +5 -12
- package/dist/server/utils/interface.d.ts +56 -0
- package/dist/server/utils/interface.js +44 -0
- package/dist/server/utils/key.d.ts +24 -0
- package/dist/server/utils/key.js +211 -0
- package/dist/server/utils/license.d.ts +34 -0
- package/dist/server/utils/license.js +80 -0
- package/dist/server/utils/pkg.d.ts +13 -0
- package/dist/server/utils/pkg.js +115 -0
- package/dist/server/utils/plugin.d.ts +24 -0
- package/dist/server/utils/plugin.js +129 -0
- package/package.json +7 -5
- package/tsconfig.env.json +17 -0
- package/utils/env.js +79 -0
- package/utils/interface.js +10 -0
|
@@ -0,0 +1,80 @@
|
|
|
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 license_exports = {};
|
|
28
|
+
__export(license_exports, {
|
|
29
|
+
getLicenseValidate: () => getLicenseValidate
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(license_exports);
|
|
32
|
+
var import_key = require("./key");
|
|
33
|
+
var import_env = require("./env");
|
|
34
|
+
var import_pkg = require("./pkg");
|
|
35
|
+
var import_plugin = require("./plugin");
|
|
36
|
+
async function getLicenseValidate({ key, ctx }) {
|
|
37
|
+
var _a;
|
|
38
|
+
const currentDomain = (0, import_env.getClientDomain)(ctx);
|
|
39
|
+
const currentEnv = await (0, import_env.getEnvOnce)();
|
|
40
|
+
let keyStatus;
|
|
41
|
+
let keyData;
|
|
42
|
+
try {
|
|
43
|
+
const keyStr = key || await (0, import_key.getKey)(ctx);
|
|
44
|
+
keyData = (0, import_key.parseKey)(keyStr);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
keyStatus = e == null ? void 0 : e.message;
|
|
47
|
+
}
|
|
48
|
+
const domainMatch = (0, import_env.isDomainMatch)(currentDomain, keyData);
|
|
49
|
+
const dbMatch = (0, import_env.isDbMatch)(currentEnv, keyData);
|
|
50
|
+
const sysMatch = (0, import_env.isSysMatch)(currentEnv, keyData);
|
|
51
|
+
const envMatch = dbMatch && sysMatch;
|
|
52
|
+
const isExpired = (0, import_key.isDateExpired)(keyData == null ? void 0 : keyData.upgradeExpirationDate);
|
|
53
|
+
const plugins = await (0, import_plugin.getPlugins)({ keyData, ctx });
|
|
54
|
+
const pluginsLicensed = (0, import_plugin.getPluginsLicenseStatus)({ plugins });
|
|
55
|
+
const isPkgLogin = await (0, import_pkg.testPkgLogin)(keyData);
|
|
56
|
+
const isServiceConnection = await (0, import_pkg.testServiceConnection)(keyData);
|
|
57
|
+
return {
|
|
58
|
+
current: {
|
|
59
|
+
env: currentEnv,
|
|
60
|
+
domain: currentDomain ? new URL(currentDomain).host : ""
|
|
61
|
+
},
|
|
62
|
+
keyData,
|
|
63
|
+
dbMatch,
|
|
64
|
+
sysMatch,
|
|
65
|
+
envMatch,
|
|
66
|
+
domainMatch,
|
|
67
|
+
isExpired,
|
|
68
|
+
isPkgLogin,
|
|
69
|
+
isServiceConnection,
|
|
70
|
+
pkgUrl: (0, import_pkg.getNocoBasePkgUrl)(),
|
|
71
|
+
plugins,
|
|
72
|
+
pluginsLicensed,
|
|
73
|
+
keyStatus,
|
|
74
|
+
licenseStatus: ((_a = keyData == null ? void 0 : keyData.licenseKey) == null ? void 0 : _a.licenseStatus) || "active"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
getLicenseValidate
|
|
80
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { KeyData } from './interface';
|
|
10
|
+
export declare function getNocoBasePkgUrl(): string;
|
|
11
|
+
export declare function testPkgConnection(): Promise<any>;
|
|
12
|
+
export declare function testPkgLogin(keyData: KeyData | Record<string, any>): Promise<boolean>;
|
|
13
|
+
export declare function testServiceConnection(keyData: KeyData): Promise<any>;
|
|
@@ -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
|
+
|
|
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 __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var pkg_exports = {};
|
|
38
|
+
__export(pkg_exports, {
|
|
39
|
+
getNocoBasePkgUrl: () => getNocoBasePkgUrl,
|
|
40
|
+
testPkgConnection: () => testPkgConnection,
|
|
41
|
+
testPkgLogin: () => testPkgLogin,
|
|
42
|
+
testServiceConnection: () => testServiceConnection
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(pkg_exports);
|
|
45
|
+
var http = __toESM(require("http"));
|
|
46
|
+
var https = __toESM(require("https"));
|
|
47
|
+
var import_axios = __toESM(require("axios"));
|
|
48
|
+
function getNocoBasePkgUrl() {
|
|
49
|
+
var _a;
|
|
50
|
+
return ((_a = process.env) == null ? void 0 : _a.NOCOBASE_PKG_URL) || "https://pkg.nocobase.com/";
|
|
51
|
+
}
|
|
52
|
+
async function testDomain(url) {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
const client = url.startsWith("https") ? https : http;
|
|
55
|
+
const req = client.get(url, (res) => {
|
|
56
|
+
resolve({
|
|
57
|
+
reachable: true,
|
|
58
|
+
statusCode: res.statusCode
|
|
59
|
+
});
|
|
60
|
+
req.end();
|
|
61
|
+
});
|
|
62
|
+
req.on("error", (err) => {
|
|
63
|
+
resolve({
|
|
64
|
+
reachable: false,
|
|
65
|
+
error: err.message
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
req.setTimeout(5e3, () => {
|
|
69
|
+
req.destroy();
|
|
70
|
+
resolve({
|
|
71
|
+
reachable: false,
|
|
72
|
+
error: "Timeout"
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async function testPkgConnection() {
|
|
78
|
+
const res = await testDomain(getNocoBasePkgUrl());
|
|
79
|
+
return res.reachable;
|
|
80
|
+
}
|
|
81
|
+
async function testPkgLogin(keyData) {
|
|
82
|
+
try {
|
|
83
|
+
const NOCOBASE_PKG_URL = getNocoBasePkgUrl();
|
|
84
|
+
const { accessKeyId, accessKeySecret } = keyData || {};
|
|
85
|
+
if (!accessKeyId || !accessKeySecret) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const credentials = { username: accessKeyId, password: accessKeySecret };
|
|
89
|
+
const res1 = await import_axios.default.post(`${NOCOBASE_PKG_URL}-/verdaccio/sec/login`, credentials, {
|
|
90
|
+
responseType: "json"
|
|
91
|
+
});
|
|
92
|
+
const token = res1.data.token;
|
|
93
|
+
if (!token) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function testServiceConnection(keyData) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
if (!((_a = keyData == null ? void 0 : keyData.service) == null ? void 0 : _a.domain)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const res = await testDomain((_b = keyData == null ? void 0 : keyData.service) == null ? void 0 : _b.domain);
|
|
107
|
+
return res.reachable;
|
|
108
|
+
}
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
getNocoBasePkgUrl,
|
|
112
|
+
testPkgConnection,
|
|
113
|
+
testPkgLogin,
|
|
114
|
+
testServiceConnection
|
|
115
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { KeyData } from './interface';
|
|
10
|
+
export interface PluginData {
|
|
11
|
+
name: string;
|
|
12
|
+
packageName: string;
|
|
13
|
+
status: string;
|
|
14
|
+
expirationDate: string;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
installed: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function getPlugins({ keyData, ctx }: {
|
|
19
|
+
keyData: KeyData;
|
|
20
|
+
ctx: any;
|
|
21
|
+
}): Promise<PluginData[]>;
|
|
22
|
+
export declare function getPluginsLicenseStatus({ plugins }: {
|
|
23
|
+
plugins: PluginData[];
|
|
24
|
+
}): boolean;
|
|
@@ -0,0 +1,129 @@
|
|
|
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 __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var plugin_exports = {};
|
|
38
|
+
__export(plugin_exports, {
|
|
39
|
+
getPlugins: () => getPlugins,
|
|
40
|
+
getPluginsLicenseStatus: () => getPluginsLicenseStatus
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
43
|
+
var import_sortBy = __toESM(require("lodash/sortBy"));
|
|
44
|
+
var import_key = require("./key");
|
|
45
|
+
async function getPlugins({ keyData, ctx }) {
|
|
46
|
+
var _a;
|
|
47
|
+
const locale = ctx.getCurrentLocale();
|
|
48
|
+
const plugin = ctx.app.pm.get("nocobase");
|
|
49
|
+
const localPlugins = await plugin.getAllPlugins(locale);
|
|
50
|
+
const currentPluginInstances = [];
|
|
51
|
+
for (const [_, p] of ctx.app.pm.getPlugins()) {
|
|
52
|
+
currentPluginInstances.push({
|
|
53
|
+
name: p.options.name,
|
|
54
|
+
__isCommercial: p.options.__isCommercial,
|
|
55
|
+
packageName: p.options.packageName,
|
|
56
|
+
enabled: p.options.enabled
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const licensedPlugins = (keyData == null ? void 0 : keyData.plugins) || [];
|
|
60
|
+
const allCommericalPluginNames = [...licensedPlugins.map((p) => p.packageName)];
|
|
61
|
+
localPlugins.forEach((p) => {
|
|
62
|
+
const instance = currentPluginInstances == null ? void 0 : currentPluginInstances.find((plugin2) => plugin2.packageName === p.packageName);
|
|
63
|
+
if (instance == null ? void 0 : instance.__isCommercial) {
|
|
64
|
+
allCommericalPluginNames.push(p.packageName);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const installedCommericalPlugins = [];
|
|
68
|
+
for (const plugin2 of localPlugins) {
|
|
69
|
+
if (allCommericalPluginNames.includes(plugin2.packageName)) {
|
|
70
|
+
installedCommericalPlugins.push(plugin2.packageName);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const plugins = [];
|
|
74
|
+
for (const name of installedCommericalPlugins) {
|
|
75
|
+
let status = "unlicensed";
|
|
76
|
+
const expirationDate = (_a = licensedPlugins == null ? void 0 : licensedPlugins.find((p) => p.packageName === name)) == null ? void 0 : _a.updateExpirationDate;
|
|
77
|
+
if (expirationDate) {
|
|
78
|
+
const isExpired = (0, import_key.isDateExpired)(expirationDate);
|
|
79
|
+
if (isExpired) {
|
|
80
|
+
status = "expired";
|
|
81
|
+
} else {
|
|
82
|
+
status = "licensed";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const plugin2 = localPlugins.find((p) => p.packageName === name);
|
|
86
|
+
plugins.push({
|
|
87
|
+
name: (plugin2 == null ? void 0 : plugin2.displayName) || (plugin2 == null ? void 0 : plugin2.name) || name,
|
|
88
|
+
packageName: name,
|
|
89
|
+
status,
|
|
90
|
+
expirationDate,
|
|
91
|
+
enabled: plugin2 == null ? void 0 : plugin2.enabled,
|
|
92
|
+
installed: true
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const statusOrder = {
|
|
96
|
+
unlicensed: 0,
|
|
97
|
+
trial: 1,
|
|
98
|
+
expired: 2,
|
|
99
|
+
suspended: 3,
|
|
100
|
+
revoked: 4,
|
|
101
|
+
invalid: 5,
|
|
102
|
+
pending: 6,
|
|
103
|
+
licensed: 7
|
|
104
|
+
};
|
|
105
|
+
const list = (0, import_sortBy.default)(plugins, (plugin2) => [statusOrder[plugin2.status] ?? 999, plugin2.enabled ? 0 : 1, plugin2.name]);
|
|
106
|
+
licensedPlugins.forEach((p) => {
|
|
107
|
+
const plugin2 = plugins.find((plugin3) => plugin3.packageName === p.packageName);
|
|
108
|
+
if (p.updateExpirationDate && !plugin2) {
|
|
109
|
+
const isExpired = (0, import_key.isDateExpired)(p.updateExpirationDate);
|
|
110
|
+
list.push({
|
|
111
|
+
name: p.displayName || p.packageName,
|
|
112
|
+
packageName: p.packageName,
|
|
113
|
+
status: isExpired ? "expired" : "licensed",
|
|
114
|
+
expirationDate: p.updateExpirationDate,
|
|
115
|
+
enabled: false,
|
|
116
|
+
installed: false
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return list;
|
|
121
|
+
}
|
|
122
|
+
function getPluginsLicenseStatus({ plugins }) {
|
|
123
|
+
return plugins.filter((p) => p.status === "unlicensed").length === 0;
|
|
124
|
+
}
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
getPlugins,
|
|
128
|
+
getPluginsLicenseStatus
|
|
129
|
+
});
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-license",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"displayName": "License settings",
|
|
6
|
+
"displayName.ru-RU": "Настройки лицензии",
|
|
6
7
|
"displayName.zh-CN": "授权设置",
|
|
7
8
|
"description": "Instance ID and license key settings",
|
|
9
|
+
"description.ru-RU": "Настройка идентификатора экземпляра и ключа лицензии",
|
|
8
10
|
"description.zh-CN": "实例 ID 和授权密钥设置",
|
|
9
|
-
"devDependencies": {
|
|
10
|
-
"@nocobase/license-kit": "^0.2.17"
|
|
11
|
-
},
|
|
12
11
|
"peerDependencies": {
|
|
13
12
|
"@nocobase/client": "2.x",
|
|
14
13
|
"@nocobase/server": "2.x",
|
|
15
14
|
"@nocobase/test": "2.x"
|
|
16
15
|
},
|
|
17
|
-
"
|
|
16
|
+
"scripts": {
|
|
17
|
+
"ts:env": "tsc -p tsconfig.env.json"
|
|
18
|
+
},
|
|
19
|
+
"gitHead": "b3d1f65848fc91e673372ee734dafe6b1cf80586"
|
|
18
20
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"rootDir": "src/server/utils",
|
|
6
|
+
"outDir": "utils",
|
|
7
|
+
"strict": true,
|
|
8
|
+
// "declaration": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"moduleResolution": "node"
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/server/utils/env.ts"],
|
|
16
|
+
"exclude": ["node_modules"]
|
|
17
|
+
}
|
package/utils/env.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* This file is part of the NocoBase (R) project.
|
|
4
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
5
|
+
* Authors: NocoBase Team.
|
|
6
|
+
*
|
|
7
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
8
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault =
|
|
11
|
+
(this && this.__importDefault) ||
|
|
12
|
+
function (mod) {
|
|
13
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
16
|
+
exports.isEnvMatch = exports.isDomainMatch = exports.getClientDomain = void 0;
|
|
17
|
+
const omit_1 = __importDefault(require('lodash/omit'));
|
|
18
|
+
const isEqual_1 = __importDefault(require('lodash/isEqual'));
|
|
19
|
+
function getClientDomain(ctx) {
|
|
20
|
+
if (!ctx) return '';
|
|
21
|
+
const referer = typeof ctx.get === 'function' ? ctx.get('referer') : null;
|
|
22
|
+
if (referer) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(referer).origin;
|
|
25
|
+
} catch {
|
|
26
|
+
console.error('Invalid Referer URL:', referer);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const protocol = ctx.headers?.['x-forwarded-proto'] || ctx.protocol || ctx.request?.protocol || 'http';
|
|
30
|
+
const host = ctx.headers?.['x-forwarded-host'] || ctx.host || ctx.request?.host || '';
|
|
31
|
+
return host ? `${protocol}://${host}` : '';
|
|
32
|
+
}
|
|
33
|
+
exports.getClientDomain = getClientDomain;
|
|
34
|
+
function matchSingleDomain(licenseDomain, currentDomain) {
|
|
35
|
+
let hostname = '';
|
|
36
|
+
let port = '';
|
|
37
|
+
try {
|
|
38
|
+
const url = new URL(currentDomain);
|
|
39
|
+
hostname = url.hostname;
|
|
40
|
+
port = url.port ? `:${url.port}` : '';
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const fullDomain = hostname + port;
|
|
45
|
+
if (!licenseDomain.includes('*')) {
|
|
46
|
+
return fullDomain === licenseDomain;
|
|
47
|
+
}
|
|
48
|
+
const base = licenseDomain.replace('*', '');
|
|
49
|
+
return fullDomain.endsWith(base);
|
|
50
|
+
}
|
|
51
|
+
function isDomainMatch(currentDomain, keyData) {
|
|
52
|
+
if (!keyData?.licenseKey?.domain || !currentDomain) return false;
|
|
53
|
+
const licenseDomains = keyData.licenseKey.domain
|
|
54
|
+
.split(',')
|
|
55
|
+
.map((d) => d.trim())
|
|
56
|
+
.filter(Boolean);
|
|
57
|
+
return licenseDomains.some((licenseDomain) => matchSingleDomain(licenseDomain, currentDomain));
|
|
58
|
+
}
|
|
59
|
+
exports.isDomainMatch = isDomainMatch;
|
|
60
|
+
function isEnvMatch(env, keyData) {
|
|
61
|
+
if (!env || !keyData?.instanceData) return false;
|
|
62
|
+
if (!env.db || !keyData.instanceData.db) return false;
|
|
63
|
+
const envDbId = env?.db?.id;
|
|
64
|
+
const keyDbId = keyData?.instanceData?.db?.id;
|
|
65
|
+
const matchById = Boolean(envDbId && keyDbId);
|
|
66
|
+
const normalizeEnvData = (envItem) => {
|
|
67
|
+
if (!envItem) return null;
|
|
68
|
+
const { sys, osVer, db } = envItem;
|
|
69
|
+
return {
|
|
70
|
+
sys,
|
|
71
|
+
osVer,
|
|
72
|
+
db: matchById ? { id: db?.id } : (0, omit_1.default)(db, ['id']),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const a = normalizeEnvData(env);
|
|
76
|
+
const b = normalizeEnvData(keyData.instanceData);
|
|
77
|
+
return (0, isEqual_1.default)(a, b);
|
|
78
|
+
}
|
|
79
|
+
exports.isEnvMatch = isEnvMatch;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* This file is part of the NocoBase (R) project.
|
|
4
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
5
|
+
* Authors: NocoBase Team.
|
|
6
|
+
*
|
|
7
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
8
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|