@mui/x-license 7.0.0-beta.2
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/CHANGELOG.md +7295 -0
- package/LICENSE +11 -0
- package/README.md +3 -0
- package/Unstable_LicenseInfoProvider/LicenseInfoContext.d.ts +4 -0
- package/Unstable_LicenseInfoProvider/LicenseInfoContext.js +4 -0
- package/Unstable_LicenseInfoProvider/LicenseInfoProvider.d.ts +13 -0
- package/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +19 -0
- package/Unstable_LicenseInfoProvider/index.d.ts +2 -0
- package/Unstable_LicenseInfoProvider/index.js +1 -0
- package/Unstable_LicenseInfoProvider/package.json +6 -0
- package/Watermark/Watermark.d.ts +8 -0
- package/Watermark/Watermark.js +46 -0
- package/Watermark/index.d.ts +1 -0
- package/Watermark/index.js +1 -0
- package/Watermark/package.json +6 -0
- package/encoding/base64.d.ts +2 -0
- package/encoding/base64.js +57 -0
- package/encoding/md5.d.ts +1 -0
- package/encoding/md5.js +42 -0
- package/generateLicense/generateLicense.d.ts +9 -0
- package/generateLicense/generateLicense.js +18 -0
- package/generateLicense/index.d.ts +1 -0
- package/generateLicense/index.js +1 -0
- package/generateLicense/package.json +6 -0
- package/index.d.ts +6 -0
- package/index.js +13 -0
- package/legacy/Unstable_LicenseInfoProvider/LicenseInfoContext.js +4 -0
- package/legacy/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +18 -0
- package/legacy/Unstable_LicenseInfoProvider/index.js +1 -0
- package/legacy/Watermark/Watermark.js +44 -0
- package/legacy/Watermark/index.js +1 -0
- package/legacy/encoding/base64.js +57 -0
- package/legacy/encoding/md5.js +42 -0
- package/legacy/generateLicense/generateLicense.js +18 -0
- package/legacy/generateLicense/index.js +1 -0
- package/legacy/index.js +13 -0
- package/legacy/useLicenseVerifier/index.js +1 -0
- package/legacy/useLicenseVerifier/useLicenseVerifier.js +59 -0
- package/legacy/utils/index.js +4 -0
- package/legacy/utils/licenseErrorMessageUtils.js +31 -0
- package/legacy/utils/licenseInfo.js +40 -0
- package/legacy/utils/licenseScope.js +1 -0
- package/legacy/utils/licenseStatus.js +11 -0
- package/legacy/utils/licensingModel.js +15 -0
- package/legacy/verifyLicense/index.js +1 -0
- package/legacy/verifyLicense/verifyLicense.js +167 -0
- package/modern/Unstable_LicenseInfoProvider/LicenseInfoContext.js +4 -0
- package/modern/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +19 -0
- package/modern/Unstable_LicenseInfoProvider/index.js +1 -0
- package/modern/Watermark/Watermark.js +46 -0
- package/modern/Watermark/index.js +1 -0
- package/modern/encoding/base64.js +57 -0
- package/modern/encoding/md5.js +42 -0
- package/modern/generateLicense/generateLicense.js +18 -0
- package/modern/generateLicense/index.js +1 -0
- package/modern/index.js +13 -0
- package/modern/useLicenseVerifier/index.js +1 -0
- package/modern/useLicenseVerifier/useLicenseVerifier.js +60 -0
- package/modern/utils/index.js +4 -0
- package/modern/utils/licenseErrorMessageUtils.js +34 -0
- package/modern/utils/licenseInfo.js +27 -0
- package/modern/utils/licenseScope.js +1 -0
- package/modern/utils/licenseStatus.js +11 -0
- package/modern/utils/licensingModel.js +15 -0
- package/modern/verifyLicense/index.js +1 -0
- package/modern/verifyLicense/verifyLicense.js +159 -0
- package/node/Unstable_LicenseInfoProvider/LicenseInfoContext.js +12 -0
- package/node/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +28 -0
- package/node/Unstable_LicenseInfoProvider/index.js +12 -0
- package/node/Watermark/Watermark.js +54 -0
- package/node/Watermark/index.js +16 -0
- package/node/encoding/base64.js +65 -0
- package/node/encoding/md5.js +48 -0
- package/node/generateLicense/generateLicense.js +24 -0
- package/node/generateLicense/index.js +16 -0
- package/node/index.js +78 -0
- package/node/useLicenseVerifier/index.js +12 -0
- package/node/useLicenseVerifier/useLicenseVerifier.js +70 -0
- package/node/utils/index.js +38 -0
- package/node/utils/licenseErrorMessageUtils.js +45 -0
- package/node/utils/licenseInfo.js +33 -0
- package/node/utils/licenseScope.js +7 -0
- package/node/utils/licenseStatus.js +17 -0
- package/node/utils/licensingModel.js +21 -0
- package/node/verifyLicense/index.js +16 -0
- package/node/verifyLicense/verifyLicense.js +166 -0
- package/package.json +42 -0
- package/useLicenseVerifier/index.d.ts +2 -0
- package/useLicenseVerifier/index.js +1 -0
- package/useLicenseVerifier/package.json +6 -0
- package/useLicenseVerifier/useLicenseVerifier.d.ts +13 -0
- package/useLicenseVerifier/useLicenseVerifier.js +60 -0
- package/utils/index.d.ts +5 -0
- package/utils/index.js +4 -0
- package/utils/licenseErrorMessageUtils.d.ts +19 -0
- package/utils/licenseErrorMessageUtils.js +34 -0
- package/utils/licenseInfo.d.ts +11 -0
- package/utils/licenseInfo.js +27 -0
- package/utils/licenseScope.d.ts +2 -0
- package/utils/licenseScope.js +1 -0
- package/utils/licenseStatus.d.ts +10 -0
- package/utils/licenseStatus.js +11 -0
- package/utils/licensingModel.d.ts +2 -0
- package/utils/licensingModel.js +15 -0
- package/utils/package.json +6 -0
- package/verifyLicense/index.d.ts +1 -0
- package/verifyLicense/index.js +1 -0
- package/verifyLicense/package.json +6 -0
- package/verifyLicense/verifyLicense.d.ts +11 -0
- package/verifyLicense/verifyLicense.js +159 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { base64Decode, base64Encode } from '../encoding/base64';
|
|
2
|
+
import { md5 } from '../encoding/md5';
|
|
3
|
+
import { LICENSE_STATUS } from '../utils/licenseStatus';
|
|
4
|
+
import { LICENSE_SCOPES } from '../utils/licenseScope';
|
|
5
|
+
import { LICENSING_MODELS } from '../utils/licensingModel';
|
|
6
|
+
const getDefaultReleaseDate = () => {
|
|
7
|
+
const today = new Date();
|
|
8
|
+
today.setHours(0, 0, 0, 0);
|
|
9
|
+
return today;
|
|
10
|
+
};
|
|
11
|
+
export function generateReleaseInfo(releaseDate = getDefaultReleaseDate()) {
|
|
12
|
+
return base64Encode(releaseDate.getTime().toString());
|
|
13
|
+
}
|
|
14
|
+
const expiryReg = /^.*EXPIRY=([0-9]+),.*$/;
|
|
15
|
+
/**
|
|
16
|
+
* Format: ORDER:${orderNumber},EXPIRY=${expiryTimestamp},KEYVERSION=1
|
|
17
|
+
*/
|
|
18
|
+
const decodeLicenseVersion1 = license => {
|
|
19
|
+
let expiryTimestamp;
|
|
20
|
+
try {
|
|
21
|
+
expiryTimestamp = parseInt(license.match(expiryReg)[1], 10);
|
|
22
|
+
if (!expiryTimestamp || Number.isNaN(expiryTimestamp)) {
|
|
23
|
+
expiryTimestamp = null;
|
|
24
|
+
}
|
|
25
|
+
} catch (err) {
|
|
26
|
+
expiryTimestamp = null;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
scope: 'pro',
|
|
30
|
+
licensingModel: 'perpetual',
|
|
31
|
+
expiryTimestamp
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Format: O=${orderNumber},E=${expiryTimestamp},S=${scope},LM=${licensingModel},KV=2`;
|
|
37
|
+
*/
|
|
38
|
+
const decodeLicenseVersion2 = license => {
|
|
39
|
+
const licenseInfo = {
|
|
40
|
+
scope: null,
|
|
41
|
+
licensingModel: null,
|
|
42
|
+
expiryTimestamp: null
|
|
43
|
+
};
|
|
44
|
+
license.split(',').map(token => token.split('=')).filter(el => el.length === 2).forEach(([key, value]) => {
|
|
45
|
+
if (key === 'S') {
|
|
46
|
+
licenseInfo.scope = value;
|
|
47
|
+
}
|
|
48
|
+
if (key === 'LM') {
|
|
49
|
+
licenseInfo.licensingModel = value;
|
|
50
|
+
}
|
|
51
|
+
if (key === 'E') {
|
|
52
|
+
const expiryTimestamp = parseInt(value, 10);
|
|
53
|
+
if (expiryTimestamp && !Number.isNaN(expiryTimestamp)) {
|
|
54
|
+
licenseInfo.expiryTimestamp = expiryTimestamp;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return licenseInfo;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Decode the license based on its key version and return a version-agnostic `MuiLicense` object.
|
|
63
|
+
*/
|
|
64
|
+
const decodeLicense = encodedLicense => {
|
|
65
|
+
const license = base64Decode(encodedLicense);
|
|
66
|
+
if (license.includes('KEYVERSION=1')) {
|
|
67
|
+
return decodeLicenseVersion1(license);
|
|
68
|
+
}
|
|
69
|
+
if (license.includes('KV=2')) {
|
|
70
|
+
return decodeLicenseVersion2(license);
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
export function verifyLicense({
|
|
75
|
+
releaseInfo,
|
|
76
|
+
licenseKey,
|
|
77
|
+
acceptedScopes
|
|
78
|
+
}) {
|
|
79
|
+
if (!releaseInfo) {
|
|
80
|
+
throw new Error('MUI X: The release information is missing. Not able to validate license.');
|
|
81
|
+
}
|
|
82
|
+
if (!licenseKey) {
|
|
83
|
+
return {
|
|
84
|
+
status: LICENSE_STATUS.NotFound
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const hash = licenseKey.substr(0, 32);
|
|
88
|
+
const encoded = licenseKey.substr(32);
|
|
89
|
+
if (hash !== md5(encoded)) {
|
|
90
|
+
return {
|
|
91
|
+
status: LICENSE_STATUS.Invalid
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const license = decodeLicense(encoded);
|
|
95
|
+
if (license == null) {
|
|
96
|
+
console.error('MUI X: Error checking license. Key version not found!');
|
|
97
|
+
return {
|
|
98
|
+
status: LICENSE_STATUS.Invalid
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (license.licensingModel == null || !LICENSING_MODELS.includes(license.licensingModel)) {
|
|
102
|
+
console.error('MUI X: Error checking license. Licensing model not found or invalid!');
|
|
103
|
+
return {
|
|
104
|
+
status: LICENSE_STATUS.Invalid
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (license.expiryTimestamp == null) {
|
|
108
|
+
console.error('MUI X: Error checking license. Expiry timestamp not found or invalid!');
|
|
109
|
+
return {
|
|
110
|
+
status: LICENSE_STATUS.Invalid
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (license.licensingModel === 'perpetual' || process.env.NODE_ENV === 'production') {
|
|
114
|
+
const pkgTimestamp = parseInt(base64Decode(releaseInfo), 10);
|
|
115
|
+
if (Number.isNaN(pkgTimestamp)) {
|
|
116
|
+
throw new Error('MUI X: The release information is invalid. Not able to validate license.');
|
|
117
|
+
}
|
|
118
|
+
if (license.expiryTimestamp < pkgTimestamp) {
|
|
119
|
+
return {
|
|
120
|
+
status: LICENSE_STATUS.ExpiredVersion
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
} else if (license.licensingModel === 'subscription' || license.licensingModel === 'annual') {
|
|
124
|
+
if (new Date().getTime() > license.expiryTimestamp) {
|
|
125
|
+
if (
|
|
126
|
+
// 30 days grace
|
|
127
|
+
new Date().getTime() < license.expiryTimestamp + 1000 * 3600 * 24 * 30 || process.env.NODE_ENV !== 'development') {
|
|
128
|
+
return {
|
|
129
|
+
status: LICENSE_STATUS.ExpiredAnnualGrace,
|
|
130
|
+
meta: {
|
|
131
|
+
expiryTimestamp: license.expiryTimestamp,
|
|
132
|
+
licenseKey
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
status: LICENSE_STATUS.ExpiredAnnual,
|
|
138
|
+
meta: {
|
|
139
|
+
expiryTimestamp: license.expiryTimestamp,
|
|
140
|
+
licenseKey
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (license.scope == null || !LICENSE_SCOPES.includes(license.scope)) {
|
|
146
|
+
console.error('Error checking license. scope not found or invalid!');
|
|
147
|
+
return {
|
|
148
|
+
status: LICENSE_STATUS.Invalid
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (!acceptedScopes.includes(license.scope)) {
|
|
152
|
+
return {
|
|
153
|
+
status: LICENSE_STATUS.OutOfScope
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
status: LICENSE_STATUS.Valid
|
|
158
|
+
};
|
|
159
|
+
}
|