@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,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
+ }