Skip to content

Commit 471fd52

Browse files
flaviendelanglealexfauquette
authored andcommitted
[license] Allow usage of charts an tree view pro package for old premium licenses (mui#13619)
Signed-off-by: Flavien DELANGLE <[email protected]> Co-authored-by: Alexandre Fauquette <[email protected]>
1 parent aca5af4 commit 471fd52

File tree

8 files changed

+103
-88
lines changed

8 files changed

+103
-88
lines changed

packages/x-license/src/Watermark/Watermark.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
2-
import { MuiCommercialPackageName, useLicenseVerifier } from '../useLicenseVerifier';
2+
import { useLicenseVerifier } from '../useLicenseVerifier';
33
import { LICENSE_STATUS, LicenseStatus } from '../utils/licenseStatus';
4+
import { MuiCommercialPackageName } from '../utils/commercialPackages';
45

56
function getLicenseErrorMessage(licenseStatus: LicenseStatus) {
67
switch (licenseStatus) {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export { useLicenseVerifier } from './useLicenseVerifier';
2-
export type { MuiCommercialPackageName } from './useLicenseVerifier';

packages/x-license/src/useLicenseVerifier/useLicenseVerifier.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ import {
1111
showNotAvailableInInitialProPlanError,
1212
} from '../utils/licenseErrorMessageUtils';
1313
import { LICENSE_STATUS, LicenseStatus } from '../utils/licenseStatus';
14-
import { extractAcceptedScopes, extractProductScope } from '../utils/licenseScope';
1514
import MuiLicenseInfoContext from '../Unstable_LicenseInfoProvider/MuiLicenseInfoContext';
16-
17-
export type MuiCommercialPackageName =
18-
| 'x-data-grid-pro'
19-
| 'x-data-grid-premium'
20-
| 'x-date-pickers-pro'
21-
| 'x-tree-view-pro'
22-
| 'x-charts-pro';
15+
import { MuiCommercialPackageName } from '../utils/commercialPackages';
2316

2417
export const sharedLicenseStatuses: {
2518
[packageName in MuiCommercialPackageName]?: {
@@ -48,15 +41,11 @@ export function useLicenseVerifier(
4841
return sharedLicenseStatuses[packageName]!.licenseVerifier;
4942
}
5043

51-
const acceptedScopes = extractAcceptedScopes(packageName);
52-
const productScope = extractProductScope(packageName);
53-
5444
const plan = packageName.includes('premium') ? 'Premium' : 'Pro';
5545
const licenseStatus = verifyLicense({
5646
releaseInfo,
5747
licenseKey,
58-
acceptedScopes,
59-
productScope,
48+
packageName,
6049
});
6150

6251
const fullPackageName = `@mui/${packageName}`;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type MuiCommercialPackageName =
2+
| 'x-data-grid-pro'
3+
| 'x-data-grid-premium'
4+
| 'x-date-pickers-pro'
5+
| 'x-tree-view-pro'
6+
| 'x-charts-pro';

packages/x-license/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './licenseInfo';
33
export * from './licenseStatus';
44
export type { LicenseScope } from './licenseScope';
55
export type { LicensingModel } from './licensingModel';
6+
export type { MuiCommercialPackageName } from './commercialPackages';
Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
export const LICENSE_SCOPES = ['pro', 'premium'] as const;
2-
export const PRODUCT_SCOPES = ['data-grid', 'date-pickers', 'charts', 'tree-view'] as const;
32
export const PLAN_VERSIONS = ['initial', 'Q3-2024'] as const;
43

54
export type LicenseScope = (typeof LICENSE_SCOPES)[number];
6-
export type ProductScope = (typeof PRODUCT_SCOPES)[number];
75
export type PlanVersion = (typeof PLAN_VERSIONS)[number];
8-
9-
export const extractProductScope = (packageName: string): ProductScope => {
10-
// extract the part between "x-" and "-pro"/"-premium"
11-
const regex = /x-(.*?)(-pro|-premium)?$/;
12-
const match = packageName.match(regex);
13-
return match![1] as ProductScope;
14-
};
15-
16-
export const extractAcceptedScopes = (packageName: string): readonly LicenseScope[] => {
17-
return packageName.includes('premium')
18-
? LICENSE_SCOPES.filter((scope) => scope.includes('premium'))
19-
: LICENSE_SCOPES;
20-
};

packages/x-license/src/verifyLicense/verifyLicense.test.ts

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ describe('License: verifyLicense', () => {
3030
verifyLicense({
3131
releaseInfo: '__RELEASE_INFO__',
3232
licenseKey,
33-
acceptedScopes: ['pro', 'premium'],
34-
productScope: 'data-grid',
33+
packageName: 'x-data-grid-pro',
3534
}).status,
3635
).to.throw('MUI X: The release information is invalid. Not able to validate license.');
3736
});
@@ -42,8 +41,7 @@ describe('License: verifyLicense', () => {
4241
verifyLicense({
4342
releaseInfo: RELEASE_INFO,
4443
licenseKey,
45-
acceptedScopes: ['pro', 'premium'],
46-
productScope: 'data-grid',
44+
packageName: 'x-data-grid-pro',
4745
}).status,
4846
).to.equal(LICENSE_STATUS.Valid);
4947
});
@@ -62,8 +60,7 @@ describe('License: verifyLicense', () => {
6260
verifyLicense({
6361
releaseInfo: RELEASE_INFO,
6462
licenseKey: expiredLicenseKey,
65-
acceptedScopes: ['pro', 'premium'],
66-
productScope: 'data-grid',
63+
packageName: 'x-data-grid-pro',
6764
}).status,
6865
).to.equal(LICENSE_STATUS.ExpiredVersion);
6966
});
@@ -75,8 +72,7 @@ describe('License: verifyLicense', () => {
7572
releaseInfo: RELEASE_INFO,
7673
licenseKey:
7774
'b43ff5f9ac93f021855ff59ff0ba5220TkFNRTpNYC1VSSBTQVMsREVWRUxPUEVSX0NPVU5UPTEwLEVYUElSWT0xNTkxNzIzMDY3MDQyLFZFUlNJT049MS4yLjM',
78-
acceptedScopes: ['pro', 'premium'],
79-
productScope: 'data-grid',
75+
packageName: 'x-data-grid-pro',
8076
}).status,
8177
).to.equal(LICENSE_STATUS.Invalid);
8278
});
@@ -106,8 +102,7 @@ describe('License: verifyLicense', () => {
106102
verifyLicense({
107103
releaseInfo: '__RELEASE_INFO__',
108104
licenseKey: licenseKeyPro,
109-
acceptedScopes: ['pro', 'premium'],
110-
productScope: 'data-grid',
105+
packageName: 'x-data-grid-pro',
111106
}).status,
112107
).to.throw('MUI X: The release information is invalid. Not able to validate license.');
113108
});
@@ -119,8 +114,7 @@ describe('License: verifyLicense', () => {
119114
verifyLicense({
120115
releaseInfo: RELEASE_INFO,
121116
licenseKey: licenseKeyPro,
122-
acceptedScopes: ['pro', 'premium'],
123-
productScope: 'data-grid',
117+
packageName: 'x-data-grid-pro',
124118
}).status,
125119
).to.equal(LICENSE_STATUS.Valid);
126120
});
@@ -131,8 +125,7 @@ describe('License: verifyLicense', () => {
131125
verifyLicense({
132126
releaseInfo: RELEASE_INFO,
133127
licenseKey: licenseKeyPremium,
134-
acceptedScopes: ['premium'],
135-
productScope: 'data-grid',
128+
packageName: 'x-data-grid-premium',
136129
}).status,
137130
).to.equal(LICENSE_STATUS.Valid);
138131
});
@@ -143,8 +136,7 @@ describe('License: verifyLicense', () => {
143136
verifyLicense({
144137
releaseInfo: RELEASE_INFO,
145138
licenseKey: licenseKeyPro,
146-
acceptedScopes: ['premium'],
147-
productScope: 'data-grid',
139+
packageName: 'x-data-grid-premium',
148140
}).status,
149141
).to.equal(LICENSE_STATUS.OutOfScope);
150142
});
@@ -165,8 +157,7 @@ describe('License: verifyLicense', () => {
165157
verifyLicense({
166158
releaseInfo: RELEASE_INFO,
167159
licenseKey: expiredLicenseKey,
168-
acceptedScopes: ['pro', 'premium'],
169-
productScope: 'data-grid',
160+
packageName: 'x-data-grid-pro',
170161
}).status,
171162
).to.equal(LICENSE_STATUS.Valid);
172163
});
@@ -184,8 +175,7 @@ describe('License: verifyLicense', () => {
184175
verifyLicense({
185176
releaseInfo: RELEASE_INFO,
186177
licenseKey: expiredLicenseKey,
187-
acceptedScopes: ['pro', 'premium'],
188-
productScope: 'data-grid',
178+
packageName: 'x-data-grid-pro',
189179
}).status,
190180
).to.equal(LICENSE_STATUS.ExpiredAnnualGrace);
191181
});
@@ -204,8 +194,7 @@ describe('License: verifyLicense', () => {
204194
verifyLicense({
205195
releaseInfo: RELEASE_INFO,
206196
licenseKey: expiredLicenseKey,
207-
acceptedScopes: ['pro', 'premium'],
208-
productScope: 'data-grid',
197+
packageName: 'x-data-grid-pro',
209198
}).status,
210199
).to.equal(LICENSE_STATUS.ExpiredAnnual);
211200
});
@@ -223,8 +212,7 @@ describe('License: verifyLicense', () => {
223212
verifyLicense({
224213
releaseInfo: RELEASE_INFO,
225214
licenseKey: expiredLicenseKey,
226-
acceptedScopes: ['pro', 'premium'],
227-
productScope: 'data-grid',
215+
packageName: 'x-data-grid-pro',
228216
}).status,
229217
).to.equal(LICENSE_STATUS.Valid);
230218
});
@@ -237,8 +225,7 @@ describe('License: verifyLicense', () => {
237225
releaseInfo: RELEASE_INFO,
238226
licenseKey:
239227
'b43ff5f9ac93f021855ff59ff0ba5220TkFNRTpNYC1VSSBTQVMsREVWRUxPUEVSX0NPVU5UPTEwLEVYUElSWT0xNTkxNzIzMDY3MDQyLFZFUlNJT049MS4yLjM',
240-
acceptedScopes: ['pro', 'premium'],
241-
productScope: 'data-grid',
228+
packageName: 'x-data-grid-pro',
242229
}).status,
243230
).to.equal(LICENSE_STATUS.Invalid);
244231
});
@@ -259,74 +246,99 @@ describe('License: verifyLicense', () => {
259246
verifyLicense({
260247
releaseInfo: RELEASE_INFO,
261248
licenseKey: licenseKeyPro,
262-
acceptedScopes: ['pro', 'premium'],
263-
productScope: 'data-grid',
249+
packageName: 'x-data-grid-pro',
264250
}).status,
265251
).to.equal(LICENSE_STATUS.Valid);
266252
});
267253
});
268254

269255
describe('key version: 2.2', () => {
270-
const licenseKeyInitial = generateLicense({
256+
const proLicenseKeyInitial = generateLicense({
271257
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
272258
orderNumber: 'MUI-123',
273259
scope: 'pro',
274260
licensingModel: 'annual',
275261
planVersion: 'initial',
276262
});
277263

278-
const licenseKey2 = generateLicense({
264+
const premiumLicenseKeyInitial = generateLicense({
265+
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
266+
orderNumber: 'MUI-123',
267+
scope: 'premium',
268+
licensingModel: 'annual',
269+
planVersion: 'initial',
270+
});
271+
272+
const proLicenseKeyQ32024 = generateLicense({
279273
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
280274
orderNumber: 'MUI-123',
281275
scope: 'pro',
282276
licensingModel: 'annual',
283277
planVersion: 'Q3-2024',
284278
});
285279

286-
it('PlanVersion "initial" should not accept charts', () => {
280+
it('PlanVersion "initial" should not accept x-charts-pro', () => {
287281
process.env.NODE_ENV = 'production';
288282
expect(
289283
verifyLicense({
290284
releaseInfo: RELEASE_INFO,
291-
licenseKey: licenseKeyInitial,
292-
acceptedScopes: ['pro', 'premium'],
293-
productScope: 'charts',
285+
licenseKey: proLicenseKeyInitial,
286+
packageName: 'x-charts-pro',
294287
}).status,
295288
).to.equal(LICENSE_STATUS.NotAvailableInInitialProPlan);
296289
});
297290

298-
it('PlanVersion "initial" should not accept tree-view', () => {
291+
it('PlanVersion "initial" should not accept x-tree-view-pro', () => {
299292
process.env.NODE_ENV = 'production';
300293
expect(
301294
verifyLicense({
302295
releaseInfo: RELEASE_INFO,
303-
licenseKey: licenseKeyInitial,
304-
acceptedScopes: ['pro', 'premium'],
305-
productScope: 'tree-view',
296+
licenseKey: proLicenseKeyInitial,
297+
packageName: 'x-tree-view-pro',
306298
}).status,
307299
).to.equal(LICENSE_STATUS.NotAvailableInInitialProPlan);
308300
});
309301

310-
it('PlanVersion "Q3-2024" should accept charts', () => {
302+
it('PlanVersion "Q3-2024" should accept x-charts-pro', () => {
303+
process.env.NODE_ENV = 'production';
304+
expect(
305+
verifyLicense({
306+
releaseInfo: RELEASE_INFO,
307+
licenseKey: proLicenseKeyQ32024,
308+
packageName: 'x-charts-pro',
309+
}).status,
310+
).to.equal(LICENSE_STATUS.Valid);
311+
});
312+
313+
it('PlanVersion "Q3-2024" should accept x-tree-view-pro', () => {
314+
process.env.NODE_ENV = 'production';
315+
expect(
316+
verifyLicense({
317+
releaseInfo: RELEASE_INFO,
318+
licenseKey: proLicenseKeyQ32024,
319+
packageName: 'x-tree-view-pro',
320+
}).status,
321+
).to.equal(LICENSE_STATUS.Valid);
322+
});
323+
324+
it('Premium with planVersion "initial" should accept x-tree-view-pro', () => {
311325
process.env.NODE_ENV = 'production';
312326
expect(
313327
verifyLicense({
314328
releaseInfo: RELEASE_INFO,
315-
licenseKey: licenseKey2,
316-
acceptedScopes: ['pro', 'premium'],
317-
productScope: 'charts',
329+
licenseKey: premiumLicenseKeyInitial,
330+
packageName: 'x-tree-view-pro',
318331
}).status,
319332
).to.equal(LICENSE_STATUS.Valid);
320333
});
321334

322-
it('PlanVersion "Q3-2024" should accept tree-view', () => {
335+
it('Premium with planVersion "initial" should accept x-charts-pro', () => {
323336
process.env.NODE_ENV = 'production';
324337
expect(
325338
verifyLicense({
326339
releaseInfo: RELEASE_INFO,
327-
licenseKey: licenseKey2,
328-
acceptedScopes: ['pro', 'premium'],
329-
productScope: 'tree-view',
340+
licenseKey: premiumLicenseKeyInitial,
341+
packageName: 'x-charts-pro',
330342
}).status,
331343
).to.equal(LICENSE_STATUS.Valid);
332344
});

0 commit comments

Comments
 (0)