@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.
Files changed (110) hide show
  1. package/CHANGELOG.md +7295 -0
  2. package/LICENSE +11 -0
  3. package/README.md +3 -0
  4. package/Unstable_LicenseInfoProvider/LicenseInfoContext.d.ts +4 -0
  5. package/Unstable_LicenseInfoProvider/LicenseInfoContext.js +4 -0
  6. package/Unstable_LicenseInfoProvider/LicenseInfoProvider.d.ts +13 -0
  7. package/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +19 -0
  8. package/Unstable_LicenseInfoProvider/index.d.ts +2 -0
  9. package/Unstable_LicenseInfoProvider/index.js +1 -0
  10. package/Unstable_LicenseInfoProvider/package.json +6 -0
  11. package/Watermark/Watermark.d.ts +8 -0
  12. package/Watermark/Watermark.js +46 -0
  13. package/Watermark/index.d.ts +1 -0
  14. package/Watermark/index.js +1 -0
  15. package/Watermark/package.json +6 -0
  16. package/encoding/base64.d.ts +2 -0
  17. package/encoding/base64.js +57 -0
  18. package/encoding/md5.d.ts +1 -0
  19. package/encoding/md5.js +42 -0
  20. package/generateLicense/generateLicense.d.ts +9 -0
  21. package/generateLicense/generateLicense.js +18 -0
  22. package/generateLicense/index.d.ts +1 -0
  23. package/generateLicense/index.js +1 -0
  24. package/generateLicense/package.json +6 -0
  25. package/index.d.ts +6 -0
  26. package/index.js +13 -0
  27. package/legacy/Unstable_LicenseInfoProvider/LicenseInfoContext.js +4 -0
  28. package/legacy/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +18 -0
  29. package/legacy/Unstable_LicenseInfoProvider/index.js +1 -0
  30. package/legacy/Watermark/Watermark.js +44 -0
  31. package/legacy/Watermark/index.js +1 -0
  32. package/legacy/encoding/base64.js +57 -0
  33. package/legacy/encoding/md5.js +42 -0
  34. package/legacy/generateLicense/generateLicense.js +18 -0
  35. package/legacy/generateLicense/index.js +1 -0
  36. package/legacy/index.js +13 -0
  37. package/legacy/useLicenseVerifier/index.js +1 -0
  38. package/legacy/useLicenseVerifier/useLicenseVerifier.js +59 -0
  39. package/legacy/utils/index.js +4 -0
  40. package/legacy/utils/licenseErrorMessageUtils.js +31 -0
  41. package/legacy/utils/licenseInfo.js +40 -0
  42. package/legacy/utils/licenseScope.js +1 -0
  43. package/legacy/utils/licenseStatus.js +11 -0
  44. package/legacy/utils/licensingModel.js +15 -0
  45. package/legacy/verifyLicense/index.js +1 -0
  46. package/legacy/verifyLicense/verifyLicense.js +167 -0
  47. package/modern/Unstable_LicenseInfoProvider/LicenseInfoContext.js +4 -0
  48. package/modern/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +19 -0
  49. package/modern/Unstable_LicenseInfoProvider/index.js +1 -0
  50. package/modern/Watermark/Watermark.js +46 -0
  51. package/modern/Watermark/index.js +1 -0
  52. package/modern/encoding/base64.js +57 -0
  53. package/modern/encoding/md5.js +42 -0
  54. package/modern/generateLicense/generateLicense.js +18 -0
  55. package/modern/generateLicense/index.js +1 -0
  56. package/modern/index.js +13 -0
  57. package/modern/useLicenseVerifier/index.js +1 -0
  58. package/modern/useLicenseVerifier/useLicenseVerifier.js +60 -0
  59. package/modern/utils/index.js +4 -0
  60. package/modern/utils/licenseErrorMessageUtils.js +34 -0
  61. package/modern/utils/licenseInfo.js +27 -0
  62. package/modern/utils/licenseScope.js +1 -0
  63. package/modern/utils/licenseStatus.js +11 -0
  64. package/modern/utils/licensingModel.js +15 -0
  65. package/modern/verifyLicense/index.js +1 -0
  66. package/modern/verifyLicense/verifyLicense.js +159 -0
  67. package/node/Unstable_LicenseInfoProvider/LicenseInfoContext.js +12 -0
  68. package/node/Unstable_LicenseInfoProvider/LicenseInfoProvider.js +28 -0
  69. package/node/Unstable_LicenseInfoProvider/index.js +12 -0
  70. package/node/Watermark/Watermark.js +54 -0
  71. package/node/Watermark/index.js +16 -0
  72. package/node/encoding/base64.js +65 -0
  73. package/node/encoding/md5.js +48 -0
  74. package/node/generateLicense/generateLicense.js +24 -0
  75. package/node/generateLicense/index.js +16 -0
  76. package/node/index.js +78 -0
  77. package/node/useLicenseVerifier/index.js +12 -0
  78. package/node/useLicenseVerifier/useLicenseVerifier.js +70 -0
  79. package/node/utils/index.js +38 -0
  80. package/node/utils/licenseErrorMessageUtils.js +45 -0
  81. package/node/utils/licenseInfo.js +33 -0
  82. package/node/utils/licenseScope.js +7 -0
  83. package/node/utils/licenseStatus.js +17 -0
  84. package/node/utils/licensingModel.js +21 -0
  85. package/node/verifyLicense/index.js +16 -0
  86. package/node/verifyLicense/verifyLicense.js +166 -0
  87. package/package.json +42 -0
  88. package/useLicenseVerifier/index.d.ts +2 -0
  89. package/useLicenseVerifier/index.js +1 -0
  90. package/useLicenseVerifier/package.json +6 -0
  91. package/useLicenseVerifier/useLicenseVerifier.d.ts +13 -0
  92. package/useLicenseVerifier/useLicenseVerifier.js +60 -0
  93. package/utils/index.d.ts +5 -0
  94. package/utils/index.js +4 -0
  95. package/utils/licenseErrorMessageUtils.d.ts +19 -0
  96. package/utils/licenseErrorMessageUtils.js +34 -0
  97. package/utils/licenseInfo.d.ts +11 -0
  98. package/utils/licenseInfo.js +27 -0
  99. package/utils/licenseScope.d.ts +2 -0
  100. package/utils/licenseScope.js +1 -0
  101. package/utils/licenseStatus.d.ts +10 -0
  102. package/utils/licenseStatus.js +11 -0
  103. package/utils/licensingModel.d.ts +2 -0
  104. package/utils/licensingModel.js +15 -0
  105. package/utils/package.json +6 -0
  106. package/verifyLicense/index.d.ts +1 -0
  107. package/verifyLicense/index.js +1 -0
  108. package/verifyLicense/package.json +6 -0
  109. package/verifyLicense/verifyLicense.d.ts +11 -0
  110. package/verifyLicense/verifyLicense.js +159 -0
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.showExpiredAnnualGraceLicenseKeyError = showExpiredAnnualGraceLicenseKeyError;
7
+ exports.showExpiredAnnualLicenseKeyError = showExpiredAnnualLicenseKeyError;
8
+ exports.showExpiredPackageVersionError = showExpiredPackageVersionError;
9
+ exports.showInvalidLicenseKeyError = showInvalidLicenseKeyError;
10
+ exports.showLicenseKeyPlanMismatchError = showLicenseKeyPlanMismatchError;
11
+ exports.showMissingLicenseKeyError = showMissingLicenseKeyError;
12
+ function showError(message) {
13
+ console.error(['*************************************************************', '', ...message, '', '*************************************************************'].join('\n'));
14
+ }
15
+ function showInvalidLicenseKeyError() {
16
+ showError(['MUI X: Invalid license key.', '', "Your MUI X license key format isn't valid. It could be because the license key is missing a character or has a typo.", '', 'To solve the issue, you need to double check that `setLicenseKey()` is called with the right argument', 'Please check the license key installation https://mui.com/r/x-license-key-installation.']);
17
+ }
18
+ function showLicenseKeyPlanMismatchError() {
19
+ showError(['MUI X: License key plan mismatch.', '', 'Your use of MUI X is not compatible with the plan of your license key. The feature you are trying to use is not included in the plan of your license key. This happens if you try to use `DataGridPremium` with a license key for the Pro plan.', '', 'To solve the issue, you can upgrade your plan from Pro to Premium at https://mui.com/r/x-get-license?scope=premium.', "Of if you didn't intend to use Premium features, you can replace the import of `@mui/x-data-grid-premium` with `@mui/x-data-grid-pro`."]);
20
+ }
21
+ function showMissingLicenseKeyError({
22
+ plan,
23
+ packageName
24
+ }) {
25
+ showError(['MUI X: Missing license key.', '', `The license key is missing. You might not be allowed to use \`${packageName}\` which is part of MUI X ${plan}.`, '', 'To solve the issue, you can check the free trial conditions: https://mui.com/r/x-license-trial.', 'If you are eligible no actions are required. If you are not eligible to the free trial, you need to purchase a license https://mui.com/r/x-get-license or stop using the software immediately.']);
26
+ }
27
+ function showExpiredPackageVersionError({
28
+ packageName
29
+ }) {
30
+ showError(['MUI X: Expired package version.', '', `You have installed a version of \`${packageName}\` that is outside of the maintenance plan of your license key. By default, commercial licenses provide access to new versions released during the first year after the purchase.`, '', 'To solve the issue, you can renew your license https://mui.com/r/x-get-license or install an older version of the npm package that is compatible with your license key.']);
31
+ }
32
+ function showExpiredAnnualGraceLicenseKeyError({
33
+ plan,
34
+ licenseKey,
35
+ expiryTimestamp
36
+ }) {
37
+ showError(['MUI X: Expired license key.', '', `Your annual license key to use MUI X ${plan}'s on non-production environments is expired. If you are seeing this development console message, you might be close to breach the license terms by making direct or indirect changes to the frontend of an app that render a MUI X ${plan} component (more details in https://mui.com/r/x-license-annual).`, '', 'To solve the problem you can either:', '', '- Renew your license https://mui.com/r/x-get-license and use the new key', `- Stop making changes to code depending directly or indirectly on MUI X ${plan}'s APIs`, '', 'Note that your license is perpetual in production environments with any version released before your license term ends.', '', `- License key expiry timestamp: ${new Date(expiryTimestamp)}`, `- Installed license key: ${licenseKey}`, '']);
38
+ }
39
+ function showExpiredAnnualLicenseKeyError({
40
+ plan,
41
+ licenseKey,
42
+ expiryTimestamp
43
+ }) {
44
+ throw new Error(['MUI X: Expired license key.', '', `Your annual license key to use MUI X ${plan}'s on non-production environments is expired. If you are seeing this development console message, you might be close to breach the license terms by making direct or indirect changes to the frontend of an app that render a MUI X ${plan} component (more details in https://mui.com/r/x-license-annual).`, '', 'To solve the problem you can either:', '', '- Renew your license https://mui.com/r/x-get-license and use the new key', `- Stop making changes to code depending directly or indirectly on MUI X ${plan}'s APIs`, '', 'Note that your license is perpetual in production environments with any version released before your license term ends.', '', `- License key expiry timestamp: ${new Date(expiryTimestamp)}`, `- Installed license key: ${licenseKey}`, ''].join('\n'));
45
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LicenseInfo = void 0;
7
+ var _utils = require("@mui/utils");
8
+ /**
9
+ * @ignore - do not document.
10
+ */
11
+
12
+ // Store the license information in a global, so it can be shared
13
+ // when module duplication occurs. The duplication of the modules can happen
14
+ // if using multiple version of MUI X at the same time of the bundler
15
+ // decide to duplicate to improve the size of the chunks.
16
+ // eslint-disable-next-line no-underscore-dangle
17
+ _utils.ponyfillGlobal.__MUI_LICENSE_INFO__ = _utils.ponyfillGlobal.__MUI_LICENSE_INFO__ || {
18
+ key: undefined
19
+ };
20
+ class LicenseInfo {
21
+ static getLicenseInfo() {
22
+ // eslint-disable-next-line no-underscore-dangle
23
+ return _utils.ponyfillGlobal.__MUI_LICENSE_INFO__;
24
+ }
25
+ static getLicenseKey() {
26
+ return LicenseInfo.getLicenseInfo().key;
27
+ }
28
+ static setLicenseKey(key) {
29
+ const licenseInfo = LicenseInfo.getLicenseInfo();
30
+ licenseInfo.key = key;
31
+ }
32
+ }
33
+ exports.LicenseInfo = LicenseInfo;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LICENSE_SCOPES = void 0;
7
+ const LICENSE_SCOPES = exports.LICENSE_SCOPES = ['pro', 'premium'];
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LICENSE_STATUS = void 0;
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ let LICENSE_STATUS = exports.LICENSE_STATUS = /*#__PURE__*/function (LICENSE_STATUS) {
9
+ LICENSE_STATUS["NotFound"] = "NotFound";
10
+ LICENSE_STATUS["Invalid"] = "Invalid";
11
+ LICENSE_STATUS["ExpiredAnnual"] = "ExpiredAnnual";
12
+ LICENSE_STATUS["ExpiredAnnualGrace"] = "ExpiredAnnualGrace";
13
+ LICENSE_STATUS["ExpiredVersion"] = "ExpiredVersion";
14
+ LICENSE_STATUS["Valid"] = "Valid";
15
+ LICENSE_STATUS["OutOfScope"] = "OutOfScope";
16
+ return LICENSE_STATUS;
17
+ }({});
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LICENSING_MODELS = void 0;
7
+ const LICENSING_MODELS = exports.LICENSING_MODELS = [
8
+ /**
9
+ * A license is outdated if the current version of the software was released after the expiry date of the license.
10
+ * But the license can be used indefinitely with an older version of the software.
11
+ */
12
+ 'perpetual',
13
+ /**
14
+ * On development, a license is outdated if the expiry date has been reached
15
+ * On production, a license is outdated if the current version of the software was released after the expiry date of the license (see "perpetual")
16
+ */
17
+ 'annual',
18
+ /**
19
+ * TODO 2025 remove, legacy name of annual.
20
+ */
21
+ 'subscription'];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _verifyLicense = require("./verifyLicense");
7
+ Object.keys(_verifyLicense).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _verifyLicense[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _verifyLicense[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateReleaseInfo = generateReleaseInfo;
7
+ exports.verifyLicense = verifyLicense;
8
+ var _base = require("../encoding/base64");
9
+ var _md = require("../encoding/md5");
10
+ var _licenseStatus = require("../utils/licenseStatus");
11
+ var _licenseScope = require("../utils/licenseScope");
12
+ var _licensingModel = require("../utils/licensingModel");
13
+ const getDefaultReleaseDate = () => {
14
+ const today = new Date();
15
+ today.setHours(0, 0, 0, 0);
16
+ return today;
17
+ };
18
+ function generateReleaseInfo(releaseDate = getDefaultReleaseDate()) {
19
+ return (0, _base.base64Encode)(releaseDate.getTime().toString());
20
+ }
21
+ const expiryReg = /^.*EXPIRY=([0-9]+),.*$/;
22
+ /**
23
+ * Format: ORDER:${orderNumber},EXPIRY=${expiryTimestamp},KEYVERSION=1
24
+ */
25
+ const decodeLicenseVersion1 = license => {
26
+ let expiryTimestamp;
27
+ try {
28
+ expiryTimestamp = parseInt(license.match(expiryReg)[1], 10);
29
+ if (!expiryTimestamp || Number.isNaN(expiryTimestamp)) {
30
+ expiryTimestamp = null;
31
+ }
32
+ } catch (err) {
33
+ expiryTimestamp = null;
34
+ }
35
+ return {
36
+ scope: 'pro',
37
+ licensingModel: 'perpetual',
38
+ expiryTimestamp
39
+ };
40
+ };
41
+
42
+ /**
43
+ * Format: O=${orderNumber},E=${expiryTimestamp},S=${scope},LM=${licensingModel},KV=2`;
44
+ */
45
+ const decodeLicenseVersion2 = license => {
46
+ const licenseInfo = {
47
+ scope: null,
48
+ licensingModel: null,
49
+ expiryTimestamp: null
50
+ };
51
+ license.split(',').map(token => token.split('=')).filter(el => el.length === 2).forEach(([key, value]) => {
52
+ if (key === 'S') {
53
+ licenseInfo.scope = value;
54
+ }
55
+ if (key === 'LM') {
56
+ licenseInfo.licensingModel = value;
57
+ }
58
+ if (key === 'E') {
59
+ const expiryTimestamp = parseInt(value, 10);
60
+ if (expiryTimestamp && !Number.isNaN(expiryTimestamp)) {
61
+ licenseInfo.expiryTimestamp = expiryTimestamp;
62
+ }
63
+ }
64
+ });
65
+ return licenseInfo;
66
+ };
67
+
68
+ /**
69
+ * Decode the license based on its key version and return a version-agnostic `MuiLicense` object.
70
+ */
71
+ const decodeLicense = encodedLicense => {
72
+ const license = (0, _base.base64Decode)(encodedLicense);
73
+ if (license.includes('KEYVERSION=1')) {
74
+ return decodeLicenseVersion1(license);
75
+ }
76
+ if (license.includes('KV=2')) {
77
+ return decodeLicenseVersion2(license);
78
+ }
79
+ return null;
80
+ };
81
+ function verifyLicense({
82
+ releaseInfo,
83
+ licenseKey,
84
+ acceptedScopes
85
+ }) {
86
+ if (!releaseInfo) {
87
+ throw new Error('MUI X: The release information is missing. Not able to validate license.');
88
+ }
89
+ if (!licenseKey) {
90
+ return {
91
+ status: _licenseStatus.LICENSE_STATUS.NotFound
92
+ };
93
+ }
94
+ const hash = licenseKey.substr(0, 32);
95
+ const encoded = licenseKey.substr(32);
96
+ if (hash !== (0, _md.md5)(encoded)) {
97
+ return {
98
+ status: _licenseStatus.LICENSE_STATUS.Invalid
99
+ };
100
+ }
101
+ const license = decodeLicense(encoded);
102
+ if (license == null) {
103
+ console.error('MUI X: Error checking license. Key version not found!');
104
+ return {
105
+ status: _licenseStatus.LICENSE_STATUS.Invalid
106
+ };
107
+ }
108
+ if (license.licensingModel == null || !_licensingModel.LICENSING_MODELS.includes(license.licensingModel)) {
109
+ console.error('MUI X: Error checking license. Licensing model not found or invalid!');
110
+ return {
111
+ status: _licenseStatus.LICENSE_STATUS.Invalid
112
+ };
113
+ }
114
+ if (license.expiryTimestamp == null) {
115
+ console.error('MUI X: Error checking license. Expiry timestamp not found or invalid!');
116
+ return {
117
+ status: _licenseStatus.LICENSE_STATUS.Invalid
118
+ };
119
+ }
120
+ if (license.licensingModel === 'perpetual' || process.env.NODE_ENV === 'production') {
121
+ const pkgTimestamp = parseInt((0, _base.base64Decode)(releaseInfo), 10);
122
+ if (Number.isNaN(pkgTimestamp)) {
123
+ throw new Error('MUI X: The release information is invalid. Not able to validate license.');
124
+ }
125
+ if (license.expiryTimestamp < pkgTimestamp) {
126
+ return {
127
+ status: _licenseStatus.LICENSE_STATUS.ExpiredVersion
128
+ };
129
+ }
130
+ } else if (license.licensingModel === 'subscription' || license.licensingModel === 'annual') {
131
+ if (new Date().getTime() > license.expiryTimestamp) {
132
+ if (
133
+ // 30 days grace
134
+ new Date().getTime() < license.expiryTimestamp + 1000 * 3600 * 24 * 30 || process.env.NODE_ENV !== 'development') {
135
+ return {
136
+ status: _licenseStatus.LICENSE_STATUS.ExpiredAnnualGrace,
137
+ meta: {
138
+ expiryTimestamp: license.expiryTimestamp,
139
+ licenseKey
140
+ }
141
+ };
142
+ }
143
+ return {
144
+ status: _licenseStatus.LICENSE_STATUS.ExpiredAnnual,
145
+ meta: {
146
+ expiryTimestamp: license.expiryTimestamp,
147
+ licenseKey
148
+ }
149
+ };
150
+ }
151
+ }
152
+ if (license.scope == null || !_licenseScope.LICENSE_SCOPES.includes(license.scope)) {
153
+ console.error('Error checking license. scope not found or invalid!');
154
+ return {
155
+ status: _licenseStatus.LICENSE_STATUS.Invalid
156
+ };
157
+ }
158
+ if (!acceptedScopes.includes(license.scope)) {
159
+ return {
160
+ status: _licenseStatus.LICENSE_STATUS.OutOfScope
161
+ };
162
+ }
163
+ return {
164
+ status: _licenseStatus.LICENSE_STATUS.Valid
165
+ };
166
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mui/x-license",
3
+ "version": "7.0.0-beta.2",
4
+ "description": "MUI X License verification",
5
+ "author": "MUI Team",
6
+ "main": "./node/index.js",
7
+ "license": "SEE LICENSE IN LICENSE",
8
+ "bugs": {
9
+ "url": "https://github.com/mui/mui-x/issues"
10
+ },
11
+ "homepage": "https://mui.com/x/introduction/licensing/",
12
+ "sideEffects": [
13
+ "./utils/licenseInfo.js",
14
+ "./legacy/utils/licenseInfo.js",
15
+ "./modern/utils/licenseInfo.js",
16
+ "./node/utils/licenseInfo.js"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/mui/mui-x.git",
24
+ "directory": "packages/x-license"
25
+ },
26
+ "dependencies": {
27
+ "@babel/runtime": "^7.23.9",
28
+ "@mui/utils": "^5.15.7"
29
+ },
30
+ "peerDependencies": {
31
+ "react": "^17.0.0 || ^18.0.0"
32
+ },
33
+ "setupFiles": [
34
+ "<rootDir>/src/setupTests.js"
35
+ ],
36
+ "engines": {
37
+ "node": ">=14.0.0"
38
+ },
39
+ "private": false,
40
+ "module": "./index.js",
41
+ "types": "./index.d.ts"
42
+ }
@@ -0,0 +1,2 @@
1
+ export { useLicenseVerifier } from './useLicenseVerifier';
2
+ export type { MuiCommercialPackageName } from './useLicenseVerifier';
@@ -0,0 +1 @@
1
+ export { useLicenseVerifier } from './useLicenseVerifier';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/useLicenseVerifier/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,13 @@
1
+ import { LicenseStatus } from '../utils/licenseStatus';
2
+ export type MuiCommercialPackageName = 'x-data-grid-pro' | 'x-data-grid-premium' | 'x-date-pickers-pro';
3
+ export declare const sharedLicenseStatuses: {
4
+ [packageName in MuiCommercialPackageName]?: {
5
+ key: string | undefined;
6
+ licenseVerifier: {
7
+ status: LicenseStatus;
8
+ };
9
+ };
10
+ };
11
+ export declare function useLicenseVerifier(packageName: MuiCommercialPackageName, releaseInfo: string): {
12
+ status: LicenseStatus;
13
+ };
@@ -0,0 +1,60 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { verifyLicense } from '../verifyLicense/verifyLicense';
4
+ import { LicenseInfo } from '../utils/licenseInfo';
5
+ import { showExpiredAnnualGraceLicenseKeyError, showExpiredAnnualLicenseKeyError, showInvalidLicenseKeyError, showMissingLicenseKeyError, showLicenseKeyPlanMismatchError, showExpiredPackageVersionError } from '../utils/licenseErrorMessageUtils';
6
+ import { LICENSE_STATUS } from '../utils/licenseStatus';
7
+ import LicenseInfoContext from '../Unstable_LicenseInfoProvider/LicenseInfoContext';
8
+ export const sharedLicenseStatuses = {};
9
+ export function useLicenseVerifier(packageName, releaseInfo) {
10
+ const {
11
+ key: contextKey
12
+ } = React.useContext(LicenseInfoContext);
13
+ return React.useMemo(() => {
14
+ const licenseKey = contextKey != null ? contextKey : LicenseInfo.getLicenseKey();
15
+
16
+ // Cache the response to not trigger the error twice.
17
+ if (sharedLicenseStatuses[packageName] && sharedLicenseStatuses[packageName].key === licenseKey) {
18
+ return sharedLicenseStatuses[packageName].licenseVerifier;
19
+ }
20
+ const acceptedScopes = packageName.includes('premium') ? ['premium'] : ['pro', 'premium'];
21
+ const plan = packageName.includes('premium') ? 'Premium' : 'Pro';
22
+ const licenseStatus = verifyLicense({
23
+ releaseInfo,
24
+ licenseKey,
25
+ acceptedScopes
26
+ });
27
+ const fullPackageName = `@mui/${packageName}`;
28
+ if (licenseStatus.status === LICENSE_STATUS.Valid) {
29
+ // Skip
30
+ } else if (licenseStatus.status === LICENSE_STATUS.Invalid) {
31
+ showInvalidLicenseKeyError();
32
+ } else if (licenseStatus.status === LICENSE_STATUS.OutOfScope) {
33
+ showLicenseKeyPlanMismatchError();
34
+ } else if (licenseStatus.status === LICENSE_STATUS.NotFound) {
35
+ showMissingLicenseKeyError({
36
+ plan,
37
+ packageName: fullPackageName
38
+ });
39
+ } else if (licenseStatus.status === LICENSE_STATUS.ExpiredAnnualGrace) {
40
+ showExpiredAnnualGraceLicenseKeyError(_extends({
41
+ plan
42
+ }, licenseStatus.meta));
43
+ } else if (licenseStatus.status === LICENSE_STATUS.ExpiredAnnual) {
44
+ showExpiredAnnualLicenseKeyError(_extends({
45
+ plan
46
+ }, licenseStatus.meta));
47
+ } else if (licenseStatus.status === LICENSE_STATUS.ExpiredVersion) {
48
+ showExpiredPackageVersionError({
49
+ packageName: fullPackageName
50
+ });
51
+ } else if (process.env.NODE_ENV !== 'production') {
52
+ throw new Error('missing status handler');
53
+ }
54
+ sharedLicenseStatuses[packageName] = {
55
+ key: licenseKey,
56
+ licenseVerifier: licenseStatus
57
+ };
58
+ return licenseStatus;
59
+ }, [packageName, releaseInfo, contextKey]);
60
+ }
@@ -0,0 +1,5 @@
1
+ export * from './licenseErrorMessageUtils';
2
+ export * from './licenseInfo';
3
+ export * from './licenseStatus';
4
+ export type { LicenseScope } from './licenseScope';
5
+ export type { LicensingModel } from './licensingModel';
package/utils/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './licenseErrorMessageUtils';
2
+ export * from './licenseInfo';
3
+ export * from './licenseStatus';
4
+ export {};
@@ -0,0 +1,19 @@
1
+ export declare function showInvalidLicenseKeyError(): void;
2
+ export declare function showLicenseKeyPlanMismatchError(): void;
3
+ export declare function showMissingLicenseKeyError({ plan, packageName, }: {
4
+ plan: string;
5
+ packageName: string;
6
+ }): void;
7
+ export declare function showExpiredPackageVersionError({ packageName }: {
8
+ packageName: string;
9
+ }): void;
10
+ export declare function showExpiredAnnualGraceLicenseKeyError({ plan, licenseKey, expiryTimestamp, }: {
11
+ plan: string;
12
+ licenseKey: string;
13
+ expiryTimestamp: number;
14
+ }): void;
15
+ export declare function showExpiredAnnualLicenseKeyError({ plan, licenseKey, expiryTimestamp, }: {
16
+ plan: string;
17
+ licenseKey: string;
18
+ expiryTimestamp: number;
19
+ }): void;
@@ -0,0 +1,34 @@
1
+ function showError(message) {
2
+ console.error(['*************************************************************', '', ...message, '', '*************************************************************'].join('\n'));
3
+ }
4
+ export function showInvalidLicenseKeyError() {
5
+ showError(['MUI X: Invalid license key.', '', "Your MUI X license key format isn't valid. It could be because the license key is missing a character or has a typo.", '', 'To solve the issue, you need to double check that `setLicenseKey()` is called with the right argument', 'Please check the license key installation https://mui.com/r/x-license-key-installation.']);
6
+ }
7
+ export function showLicenseKeyPlanMismatchError() {
8
+ showError(['MUI X: License key plan mismatch.', '', 'Your use of MUI X is not compatible with the plan of your license key. The feature you are trying to use is not included in the plan of your license key. This happens if you try to use `DataGridPremium` with a license key for the Pro plan.', '', 'To solve the issue, you can upgrade your plan from Pro to Premium at https://mui.com/r/x-get-license?scope=premium.', "Of if you didn't intend to use Premium features, you can replace the import of `@mui/x-data-grid-premium` with `@mui/x-data-grid-pro`."]);
9
+ }
10
+ export function showMissingLicenseKeyError({
11
+ plan,
12
+ packageName
13
+ }) {
14
+ showError(['MUI X: Missing license key.', '', `The license key is missing. You might not be allowed to use \`${packageName}\` which is part of MUI X ${plan}.`, '', 'To solve the issue, you can check the free trial conditions: https://mui.com/r/x-license-trial.', 'If you are eligible no actions are required. If you are not eligible to the free trial, you need to purchase a license https://mui.com/r/x-get-license or stop using the software immediately.']);
15
+ }
16
+ export function showExpiredPackageVersionError({
17
+ packageName
18
+ }) {
19
+ showError(['MUI X: Expired package version.', '', `You have installed a version of \`${packageName}\` that is outside of the maintenance plan of your license key. By default, commercial licenses provide access to new versions released during the first year after the purchase.`, '', 'To solve the issue, you can renew your license https://mui.com/r/x-get-license or install an older version of the npm package that is compatible with your license key.']);
20
+ }
21
+ export function showExpiredAnnualGraceLicenseKeyError({
22
+ plan,
23
+ licenseKey,
24
+ expiryTimestamp
25
+ }) {
26
+ showError(['MUI X: Expired license key.', '', `Your annual license key to use MUI X ${plan}'s on non-production environments is expired. If you are seeing this development console message, you might be close to breach the license terms by making direct or indirect changes to the frontend of an app that render a MUI X ${plan} component (more details in https://mui.com/r/x-license-annual).`, '', 'To solve the problem you can either:', '', '- Renew your license https://mui.com/r/x-get-license and use the new key', `- Stop making changes to code depending directly or indirectly on MUI X ${plan}'s APIs`, '', 'Note that your license is perpetual in production environments with any version released before your license term ends.', '', `- License key expiry timestamp: ${new Date(expiryTimestamp)}`, `- Installed license key: ${licenseKey}`, '']);
27
+ }
28
+ export function showExpiredAnnualLicenseKeyError({
29
+ plan,
30
+ licenseKey,
31
+ expiryTimestamp
32
+ }) {
33
+ throw new Error(['MUI X: Expired license key.', '', `Your annual license key to use MUI X ${plan}'s on non-production environments is expired. If you are seeing this development console message, you might be close to breach the license terms by making direct or indirect changes to the frontend of an app that render a MUI X ${plan} component (more details in https://mui.com/r/x-license-annual).`, '', 'To solve the problem you can either:', '', '- Renew your license https://mui.com/r/x-get-license and use the new key', `- Stop making changes to code depending directly or indirectly on MUI X ${plan}'s APIs`, '', 'Note that your license is perpetual in production environments with any version released before your license term ends.', '', `- License key expiry timestamp: ${new Date(expiryTimestamp)}`, `- Installed license key: ${licenseKey}`, ''].join('\n'));
34
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @ignore - do not document.
3
+ */
4
+ export interface MuiLicenseInfo {
5
+ key: string | undefined;
6
+ }
7
+ export declare class LicenseInfo {
8
+ private static getLicenseInfo;
9
+ static getLicenseKey(): MuiLicenseInfo['key'];
10
+ static setLicenseKey(key: string): void;
11
+ }
@@ -0,0 +1,27 @@
1
+ import { ponyfillGlobal } from '@mui/utils';
2
+
3
+ /**
4
+ * @ignore - do not document.
5
+ */
6
+
7
+ // Store the license information in a global, so it can be shared
8
+ // when module duplication occurs. The duplication of the modules can happen
9
+ // if using multiple version of MUI X at the same time of the bundler
10
+ // decide to duplicate to improve the size of the chunks.
11
+ // eslint-disable-next-line no-underscore-dangle
12
+ ponyfillGlobal.__MUI_LICENSE_INFO__ = ponyfillGlobal.__MUI_LICENSE_INFO__ || {
13
+ key: undefined
14
+ };
15
+ export class LicenseInfo {
16
+ static getLicenseInfo() {
17
+ // eslint-disable-next-line no-underscore-dangle
18
+ return ponyfillGlobal.__MUI_LICENSE_INFO__;
19
+ }
20
+ static getLicenseKey() {
21
+ return LicenseInfo.getLicenseInfo().key;
22
+ }
23
+ static setLicenseKey(key) {
24
+ const licenseInfo = LicenseInfo.getLicenseInfo();
25
+ licenseInfo.key = key;
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ export declare const LICENSE_SCOPES: readonly ["pro", "premium"];
2
+ export type LicenseScope = (typeof LICENSE_SCOPES)[number];
@@ -0,0 +1 @@
1
+ export const LICENSE_SCOPES = ['pro', 'premium'];
@@ -0,0 +1,10 @@
1
+ export declare enum LICENSE_STATUS {
2
+ NotFound = "NotFound",
3
+ Invalid = "Invalid",
4
+ ExpiredAnnual = "ExpiredAnnual",
5
+ ExpiredAnnualGrace = "ExpiredAnnualGrace",
6
+ ExpiredVersion = "ExpiredVersion",
7
+ Valid = "Valid",
8
+ OutOfScope = "OutOfScope"
9
+ }
10
+ export type LicenseStatus = keyof typeof LICENSE_STATUS;
@@ -0,0 +1,11 @@
1
+ // eslint-disable-next-line @typescript-eslint/naming-convention
2
+ export let LICENSE_STATUS = /*#__PURE__*/function (LICENSE_STATUS) {
3
+ LICENSE_STATUS["NotFound"] = "NotFound";
4
+ LICENSE_STATUS["Invalid"] = "Invalid";
5
+ LICENSE_STATUS["ExpiredAnnual"] = "ExpiredAnnual";
6
+ LICENSE_STATUS["ExpiredAnnualGrace"] = "ExpiredAnnualGrace";
7
+ LICENSE_STATUS["ExpiredVersion"] = "ExpiredVersion";
8
+ LICENSE_STATUS["Valid"] = "Valid";
9
+ LICENSE_STATUS["OutOfScope"] = "OutOfScope";
10
+ return LICENSE_STATUS;
11
+ }({});
@@ -0,0 +1,2 @@
1
+ export declare const LICENSING_MODELS: readonly ["perpetual", "annual", "subscription"];
2
+ export type LicensingModel = (typeof LICENSING_MODELS)[number];
@@ -0,0 +1,15 @@
1
+ export const LICENSING_MODELS = [
2
+ /**
3
+ * A license is outdated if the current version of the software was released after the expiry date of the license.
4
+ * But the license can be used indefinitely with an older version of the software.
5
+ */
6
+ 'perpetual',
7
+ /**
8
+ * On development, a license is outdated if the expiry date has been reached
9
+ * On production, a license is outdated if the current version of the software was released after the expiry date of the license (see "perpetual")
10
+ */
11
+ 'annual',
12
+ /**
13
+ * TODO 2025 remove, legacy name of annual.
14
+ */
15
+ 'subscription'];
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/utils/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1 @@
1
+ export * from './verifyLicense';
@@ -0,0 +1 @@
1
+ export * from './verifyLicense';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/verifyLicense/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1,11 @@
1
+ import { LicenseStatus } from '../utils/licenseStatus';
2
+ import { LicenseScope } from '../utils/licenseScope';
3
+ export declare function generateReleaseInfo(releaseDate?: Date): string;
4
+ export declare function verifyLicense({ releaseInfo, licenseKey, acceptedScopes, }: {
5
+ releaseInfo: string;
6
+ licenseKey: string | undefined;
7
+ acceptedScopes: LicenseScope[];
8
+ }): {
9
+ status: LicenseStatus;
10
+ meta?: any;
11
+ };