@nocobase/plugin-license 1.9.25 → 1.9.26
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/en-US.json +25 -1
- package/dist/locale/zh-CN.json +25 -1
- 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 +128 -0
- package/package.json +5 -5
- package/tsconfig.env.json +17 -0
- package/utils/env.js +79 -0
- package/utils/interface.js +10 -0
|
@@ -0,0 +1,128 @@
|
|
|
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 (!plugin2) {
|
|
109
|
+
list.push({
|
|
110
|
+
name: p.displayName || p.packageName,
|
|
111
|
+
packageName: p.packageName,
|
|
112
|
+
status: "licensed",
|
|
113
|
+
expirationDate: p.updateExpirationDate,
|
|
114
|
+
enabled: false,
|
|
115
|
+
installed: false
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return list;
|
|
120
|
+
}
|
|
121
|
+
function getPluginsLicenseStatus({ plugins }) {
|
|
122
|
+
return plugins.filter((p) => p.status === "unlicensed").length === 0;
|
|
123
|
+
}
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
126
|
+
getPlugins,
|
|
127
|
+
getPluginsLicenseStatus
|
|
128
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-license",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.26",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"displayName": "License settings",
|
|
6
6
|
"displayName.ru-RU": "Настройки лицензии",
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"description": "Instance ID and license key settings",
|
|
9
9
|
"description.ru-RU": "Настройка идентификатора экземпляра и ключа лицензии",
|
|
10
10
|
"description.zh-CN": "实例 ID 和授权密钥设置",
|
|
11
|
-
"devDependencies": {
|
|
12
|
-
"@nocobase/license-kit": "^0.2.17"
|
|
13
|
-
},
|
|
14
11
|
"peerDependencies": {
|
|
15
12
|
"@nocobase/client": "1.x",
|
|
16
13
|
"@nocobase/server": "1.x",
|
|
17
14
|
"@nocobase/test": "1.x"
|
|
18
15
|
},
|
|
19
|
-
"
|
|
16
|
+
"scripts": {
|
|
17
|
+
"ts:env": "tsc -p tsconfig.env.json"
|
|
18
|
+
},
|
|
19
|
+
"gitHead": "794e25d4aca20fbc68769ad7b1266860bd45ac5c"
|
|
20
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 });
|