@nocobase/plugin-license 2.0.0-alpha.51 → 2.0.0-alpha.53
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 +26 -2
- package/dist/locale/zh-CN.json +26 -2
- 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 +6 -3
- package/tsconfig.env.json +17 -0
- package/utils/env.js +79 -0
- package/utils/interface.js +10 -0
|
@@ -0,0 +1,56 @@
|
|
|
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 interface KeyData {
|
|
10
|
+
upgradeExpirationDate: string;
|
|
11
|
+
licenseKey: {
|
|
12
|
+
id: string;
|
|
13
|
+
licensee: string;
|
|
14
|
+
desc: string;
|
|
15
|
+
type: string;
|
|
16
|
+
domain: string;
|
|
17
|
+
licenseStatus: string;
|
|
18
|
+
};
|
|
19
|
+
plugins: Array<{
|
|
20
|
+
displayName: string;
|
|
21
|
+
packageName: string;
|
|
22
|
+
updateExpirationDate?: string;
|
|
23
|
+
}>;
|
|
24
|
+
instanceData: {
|
|
25
|
+
timestamp: string;
|
|
26
|
+
sys: string;
|
|
27
|
+
osVer: string;
|
|
28
|
+
kVer: string;
|
|
29
|
+
hostname: string;
|
|
30
|
+
mac: string;
|
|
31
|
+
db: {
|
|
32
|
+
type: string;
|
|
33
|
+
name: string;
|
|
34
|
+
oid: number;
|
|
35
|
+
ver: string;
|
|
36
|
+
id?: string;
|
|
37
|
+
};
|
|
38
|
+
container: {
|
|
39
|
+
name: string;
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
service: {
|
|
44
|
+
domain: string;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
};
|
|
47
|
+
accessKeyId: string;
|
|
48
|
+
accessKeySecret: string;
|
|
49
|
+
timestamp: number;
|
|
50
|
+
}
|
|
51
|
+
export declare const enum LICENSE_ERROR {
|
|
52
|
+
KEY_FORMAT_ERROR = "KEY_FORMAT_ERROR",
|
|
53
|
+
KEY_NOT_FOUND = "KEY_NOT_FOUND",
|
|
54
|
+
KEY_READ_ERROR = "KEY_READ_ERROR"
|
|
55
|
+
}
|
|
56
|
+
export declare const CACHE_KEY = "license-key";
|
|
@@ -0,0 +1,44 @@
|
|
|
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 interface_exports = {};
|
|
28
|
+
__export(interface_exports, {
|
|
29
|
+
CACHE_KEY: () => CACHE_KEY,
|
|
30
|
+
LICENSE_ERROR: () => LICENSE_ERROR
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(interface_exports);
|
|
33
|
+
var LICENSE_ERROR = /* @__PURE__ */ ((LICENSE_ERROR2) => {
|
|
34
|
+
LICENSE_ERROR2["KEY_FORMAT_ERROR"] = "KEY_FORMAT_ERROR";
|
|
35
|
+
LICENSE_ERROR2["KEY_NOT_FOUND"] = "KEY_NOT_FOUND";
|
|
36
|
+
LICENSE_ERROR2["KEY_READ_ERROR"] = "KEY_READ_ERROR";
|
|
37
|
+
return LICENSE_ERROR2;
|
|
38
|
+
})(LICENSE_ERROR || {});
|
|
39
|
+
const CACHE_KEY = "license-key";
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
CACHE_KEY,
|
|
43
|
+
LICENSE_ERROR
|
|
44
|
+
});
|
|
@@ -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 { Context } from 'koa';
|
|
10
|
+
import { KeyData } from './interface';
|
|
11
|
+
export declare function request({ url, method, body, headers, timeout, }: {
|
|
12
|
+
url: string;
|
|
13
|
+
method?: string;
|
|
14
|
+
body?: Record<string, any>;
|
|
15
|
+
headers?: any;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
}, ctx?: Context): Promise<any>;
|
|
18
|
+
export declare function saveLicenseKey(licenseKey: string, ctx?: any): Promise<void>;
|
|
19
|
+
export declare function getLocalKeyData(): Promise<any>;
|
|
20
|
+
export declare function getKey(ctx?: Context): Promise<string>;
|
|
21
|
+
export declare function getLicenseStatus(keyData: KeyData): Promise<'active' | 'invalid'>;
|
|
22
|
+
export declare function parseKey(key: string): KeyData;
|
|
23
|
+
export declare function getKeyInfo(ctx?: Context): Promise<KeyData>;
|
|
24
|
+
export declare function isDateExpired(upgradeExpirationDate: string): boolean;
|
|
@@ -0,0 +1,211 @@
|
|
|
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 key_exports = {};
|
|
38
|
+
__export(key_exports, {
|
|
39
|
+
getKey: () => getKey,
|
|
40
|
+
getKeyInfo: () => getKeyInfo,
|
|
41
|
+
getLicenseStatus: () => getLicenseStatus,
|
|
42
|
+
getLocalKeyData: () => getLocalKeyData,
|
|
43
|
+
isDateExpired: () => isDateExpired,
|
|
44
|
+
parseKey: () => parseKey,
|
|
45
|
+
request: () => request,
|
|
46
|
+
saveLicenseKey: () => saveLicenseKey
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(key_exports);
|
|
49
|
+
var import_license_kit = require("@nocobase/license-kit");
|
|
50
|
+
var import_path = __toESM(require("path"));
|
|
51
|
+
var import_fs = __toESM(require("fs"));
|
|
52
|
+
var import_interface2 = require("./interface");
|
|
53
|
+
var import_axios = __toESM(require("axios"));
|
|
54
|
+
var import_logger = require("@nocobase/logger");
|
|
55
|
+
async function request({
|
|
56
|
+
url,
|
|
57
|
+
method = "GET",
|
|
58
|
+
body,
|
|
59
|
+
headers,
|
|
60
|
+
timeout = 5e3
|
|
61
|
+
}, ctx) {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
63
|
+
const xHeaders = {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
"X-Hostname": new URL(url).hostname,
|
|
66
|
+
"X-Timezone": (_b = (_a = ctx == null ? void 0 : ctx.request) == null ? void 0 : _a.headers) == null ? void 0 : _b["x-timezone"],
|
|
67
|
+
"X-Locale": (_d = (_c = ctx == null ? void 0 : ctx.request) == null ? void 0 : _c.headers) == null ? void 0 : _d["x-locale"],
|
|
68
|
+
"X-Role": (_f = (_e = ctx == null ? void 0 : ctx.request) == null ? void 0 : _e.headers) == null ? void 0 : _f["x-role"],
|
|
69
|
+
"X-Authenticator": (_h = (_g = ctx == null ? void 0 : ctx.request) == null ? void 0 : _g.headers) == null ? void 0 : _h["x-authenticator"]
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const res = await (0, import_axios.default)({
|
|
73
|
+
url,
|
|
74
|
+
method,
|
|
75
|
+
timeout,
|
|
76
|
+
headers: {
|
|
77
|
+
...xHeaders,
|
|
78
|
+
...headers
|
|
79
|
+
},
|
|
80
|
+
data: body || {}
|
|
81
|
+
});
|
|
82
|
+
return res.data;
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (err.code === "ECONNABORTED") {
|
|
85
|
+
throw new Error(`Request timeout after ${timeout}ms`);
|
|
86
|
+
}
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function saveLicenseKey(licenseKey, ctx) {
|
|
91
|
+
const dir = import_path.default.resolve(process.cwd(), "storage/.license");
|
|
92
|
+
const filePath = import_path.default.resolve(dir, "license-key");
|
|
93
|
+
await import_fs.default.promises.writeFile(filePath, licenseKey);
|
|
94
|
+
if (ctx && ctx.cache) {
|
|
95
|
+
await ctx.cache.set("license-key", licenseKey);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function getLocalKeyData() {
|
|
99
|
+
const keyFile = import_path.default.resolve(process.cwd(), "storage/.license/license-key");
|
|
100
|
+
try {
|
|
101
|
+
const key = (await import_fs.default.promises.readFile(keyFile, "utf8")).trim();
|
|
102
|
+
return JSON.parse((0, import_license_kit.keyDecrypt)(key));
|
|
103
|
+
} catch (e) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function getKey(ctx) {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
let key;
|
|
110
|
+
const keyFile = import_path.default.resolve(process.cwd(), "storage/.license/license-key");
|
|
111
|
+
if (ctx == null ? void 0 : ctx.cache) {
|
|
112
|
+
try {
|
|
113
|
+
key = await ctx.cache.get(import_interface2.CACHE_KEY);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
import_logger.logger.warn("Failed to get license key from cache", e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!key) {
|
|
119
|
+
try {
|
|
120
|
+
key = (await import_fs.default.promises.readFile(keyFile, "utf8")).trim();
|
|
121
|
+
} catch (e) {
|
|
122
|
+
import_logger.logger.error("Failed to read license key file", e);
|
|
123
|
+
throw new Error("notfound");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!key) {
|
|
127
|
+
import_logger.logger.error("License key not found");
|
|
128
|
+
throw new Error("notfound");
|
|
129
|
+
}
|
|
130
|
+
let keyData;
|
|
131
|
+
try {
|
|
132
|
+
keyData = JSON.parse((0, import_license_kit.keyDecrypt)(key));
|
|
133
|
+
} catch (e) {
|
|
134
|
+
import_logger.logger.error("Failed to parse license key");
|
|
135
|
+
throw new Error("invalid");
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const { data } = await request({
|
|
139
|
+
url: `${(_a = keyData == null ? void 0 : keyData.service) == null ? void 0 : _a.domain}/api/license_keys:getKey`,
|
|
140
|
+
method: "POST",
|
|
141
|
+
body: {
|
|
142
|
+
access_key_id: keyData == null ? void 0 : keyData.accessKeyId,
|
|
143
|
+
access_key_secret: keyData == null ? void 0 : keyData.accessKeySecret
|
|
144
|
+
},
|
|
145
|
+
headers: ((_b = keyData == null ? void 0 : keyData.service) == null ? void 0 : _b.headers) || {}
|
|
146
|
+
});
|
|
147
|
+
const { key: remoteKey } = data || {};
|
|
148
|
+
if (remoteKey && typeof remoteKey === "string") {
|
|
149
|
+
await saveLicenseKey(remoteKey, ctx);
|
|
150
|
+
return remoteKey;
|
|
151
|
+
}
|
|
152
|
+
} catch (e) {
|
|
153
|
+
return key;
|
|
154
|
+
}
|
|
155
|
+
return key;
|
|
156
|
+
}
|
|
157
|
+
async function getLicenseStatus(keyData) {
|
|
158
|
+
var _a, _b, _c;
|
|
159
|
+
if (!keyData) {
|
|
160
|
+
return "invalid";
|
|
161
|
+
}
|
|
162
|
+
if (((_a = keyData == null ? void 0 : keyData.licenseKey) == null ? void 0 : _a.licenseStatus) === "invalid") {
|
|
163
|
+
return "invalid";
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const { data } = await request({
|
|
167
|
+
url: `${(_b = keyData == null ? void 0 : keyData.service) == null ? void 0 : _b.domain}/api/license_keys:getKeyStatus`,
|
|
168
|
+
method: "POST",
|
|
169
|
+
body: {
|
|
170
|
+
access_key_id: keyData == null ? void 0 : keyData.accessKeyId,
|
|
171
|
+
access_key_secret: keyData == null ? void 0 : keyData.accessKeySecret
|
|
172
|
+
},
|
|
173
|
+
headers: ((_c = keyData == null ? void 0 : keyData.service) == null ? void 0 : _c.headers) || {}
|
|
174
|
+
});
|
|
175
|
+
if ((data == null ? void 0 : data.status) === "active") {
|
|
176
|
+
return "active";
|
|
177
|
+
} else {
|
|
178
|
+
return "invalid";
|
|
179
|
+
}
|
|
180
|
+
} catch (e) {
|
|
181
|
+
return "active";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function parseKey(key) {
|
|
185
|
+
try {
|
|
186
|
+
return JSON.parse((0, import_license_kit.keyDecrypt)(key));
|
|
187
|
+
} catch (e) {
|
|
188
|
+
throw new Error("invalid");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function getKeyInfo(ctx) {
|
|
192
|
+
const key = await getKey(ctx);
|
|
193
|
+
return parseKey(key);
|
|
194
|
+
}
|
|
195
|
+
function isDateExpired(upgradeExpirationDate) {
|
|
196
|
+
if (!upgradeExpirationDate) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
return /* @__PURE__ */ new Date() > new Date(upgradeExpirationDate);
|
|
200
|
+
}
|
|
201
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
+
0 && (module.exports = {
|
|
203
|
+
getKey,
|
|
204
|
+
getKeyInfo,
|
|
205
|
+
getLicenseStatus,
|
|
206
|
+
getLocalKeyData,
|
|
207
|
+
isDateExpired,
|
|
208
|
+
parseKey,
|
|
209
|
+
request,
|
|
210
|
+
saveLicenseKey
|
|
211
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { Env } from '@nocobase/license-kit';
|
|
10
|
+
import { KeyData } from './interface';
|
|
11
|
+
import { PluginData } from './plugin';
|
|
12
|
+
export interface LicenseValidateResult {
|
|
13
|
+
current: {
|
|
14
|
+
env: Env;
|
|
15
|
+
domain: string;
|
|
16
|
+
};
|
|
17
|
+
dbMatch: boolean;
|
|
18
|
+
sysMatch: boolean;
|
|
19
|
+
envMatch: boolean;
|
|
20
|
+
domainMatch: boolean;
|
|
21
|
+
isExpired: boolean;
|
|
22
|
+
isServiceConnection: boolean;
|
|
23
|
+
isPkgLogin: boolean;
|
|
24
|
+
keyData: KeyData;
|
|
25
|
+
pkgUrl: string;
|
|
26
|
+
licenseStatus: 'active' | 'invalid';
|
|
27
|
+
pluginsLicensed: boolean;
|
|
28
|
+
plugins: PluginData[];
|
|
29
|
+
keyStatus?: 'invalid' | 'notfound';
|
|
30
|
+
}
|
|
31
|
+
export declare function getLicenseValidate({ key, ctx }: {
|
|
32
|
+
key?: string;
|
|
33
|
+
ctx?: any;
|
|
34
|
+
}): Promise<LicenseValidateResult>;
|
|
@@ -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
|
|
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;
|