Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x-license] Add support for plan version #13459

Merged
merged 25 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
190a18e
license update proposal
michelengelen Jun 12, 2024
1706016
Revert "license update proposal"
michelengelen Jun 13, 2024
93a4e9a
second iteration on license update
michelengelen Jun 13, 2024
8b4369e
3rd iteration
michelengelen Jun 13, 2024
f815941
changed status return on charts/treeview check
michelengelen Jun 13, 2024
3ccba21
removed tests for now
michelengelen Jun 13, 2024
46cf0d5
adjusted things and fixed tests
michelengelen Jun 13, 2024
da18b3f
review remarks
michelengelen Jun 14, 2024
ac5e804
removed productScope optional marking
michelengelen Jun 14, 2024
300e0b5
Update verifyLicense.ts
michelengelen Jun 14, 2024
e62b985
added license generation tests
michelengelen Jun 17, 2024
f4b0ed5
fixed typo
michelengelen Jun 17, 2024
b5cec8b
Added 'Mui X:' prefix on error
michelengelen Jun 17, 2024
88056dd
Added Key Version 2.2 tests
michelengelen Jun 18, 2024
508c785
added product scope tests
michelengelen Jun 18, 2024
c6e7a17
added useLicenseVerifier test
michelengelen Jun 18, 2024
1a26ce8
Apply suggestions from code review
michelengelen Jun 19, 2024
e572ab4
added some tests requested from @cherniavskii
michelengelen Jun 19, 2024
c67d0f9
Update packages/x-license/src/utils/licenseErrorMessageUtils.ts
michelengelen Jun 19, 2024
001a411
changed error wording
michelengelen Jun 19, 2024
4fffe6a
added link to license page back in
michelengelen Jun 20, 2024
c04fa6b
Merge remote-tracking branch 'refs/remotes/upstream/master' into lice…
michelengelen Jun 20, 2024
f19b30e
added text for new license state to watermark
michelengelen Jun 20, 2024
a0da60e
fix tests
michelengelen Jun 20, 2024
a19da9d
fix tests
michelengelen Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('<DataGridPremium /> - License', () => {
orderNumber: 'Test',
licensingModel: 'subscription',
scope: 'pro',
planVersion: 'initial',
}),
);
expect(() => render(<DataGridPremium columns={[]} rows={[]} autoHeight />)).toErrorDev([
Expand Down
12 changes: 8 additions & 4 deletions packages/x-license/src/generateLicense/generateLicense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ describe('License: generateLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planVersion: 'initial',
}),
).to.equal(
'b2b2ea9c6fd846e11770da3c795d6f63Tz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXBybyxMTT1zdWJzY3JpcHRpb24sS1Y9Mg==',
'076fc290e354b9a04720190023e1f868Tz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXBybyxMTT1zdWJzY3JpcHRpb24sUFY9bGVnYWN5LEtWPTI=',
);
});

Expand All @@ -22,9 +23,10 @@ describe('License: generateLicense', () => {
orderNumber: 'MUI-123',
scope: 'premium',
licensingModel: 'subscription',
planVersion: 'initial',
}),
).to.equal(
'ac8d20b4ecd1f919157f3713f8ba1651Tz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXByZW1pdW0sTE09c3Vic2NyaXB0aW9uLEtWPTI=',
'fafc52d1dbb97e825702a7ccf5986fbbTz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXByZW1pdW0sTE09c3Vic2NyaXB0aW9uLFBWPWxlZ2FjeSxLVj0y',
);
});

Expand All @@ -35,9 +37,10 @@ describe('License: generateLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planVersion: 'initial',
}),
).to.equal(
'b2b2ea9c6fd846e11770da3c795d6f63Tz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXBybyxMTT1zdWJzY3JpcHRpb24sS1Y9Mg==',
'076fc290e354b9a04720190023e1f868Tz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXBybyxMTT1zdWJzY3JpcHRpb24sUFY9bGVnYWN5LEtWPTI=',
);
});

Expand All @@ -48,9 +51,10 @@ describe('License: generateLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'perpetual',
planVersion: 'initial',
}),
).to.equal(
'b16edd8e6bc83293a723779a259f520cTz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXBybyxMTT1wZXJwZXR1YWwsS1Y9Mg==',
'a32c4d6c8cce5d9ca0132527a252e999Tz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXBybyxMTT1wZXJwZXR1YWwsUFY9bGVnYWN5LEtWPTI=',
);
});
});
16 changes: 12 additions & 4 deletions packages/x-license/src/generateLicense/generateLicense.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { md5 } from '../encoding/md5';
import { base64Encode } from '../encoding/base64';
import { LICENSE_SCOPES, LicenseScope } from '../utils/licenseScope';
import { LICENSE_SCOPES, LicenseScope, PlanVersion } from '../utils/licenseScope';
import { LICENSING_MODELS, LicensingModel } from '../utils/licensingModel';

const licenseVersion = '2';
Expand All @@ -10,6 +10,7 @@ export interface LicenseDetails {
expiryDate: Date;
scope: LicenseScope;
licensingModel: LicensingModel;
planVersion: PlanVersion;
}

function getClearLicenseString(details: LicenseDetails) {
Expand All @@ -21,9 +22,16 @@ function getClearLicenseString(details: LicenseDetails) {
throw new Error('MUI X: Invalid licensing model');
}

return `O=${details.orderNumber},E=${details.expiryDate.getTime()},S=${details.scope},LM=${
details.licensingModel
},KV=${licenseVersion}`;
const keyParts = [
michelengelen marked this conversation as resolved.
Show resolved Hide resolved
`O=${details.orderNumber}`,
`E=${details.expiryDate.getTime()}`,
`S=${details.scope}`,
`LM=${details.licensingModel}`,
`PV=${details.planVersion}`,
`KV=${licenseVersion}`,
];

return keyParts.join(',');
}

export function generateLicense(details: LicenseDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('useLicenseVerifier', function test() {
licensingModel: 'perpetual',
orderNumber: '12345',
scope: 'pro',
planVersion: 'initial',
});

LicenseInfo.setLicenseKey('');
Expand All @@ -88,6 +89,7 @@ describe('useLicenseVerifier', function test() {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planVersion: 'initial',
});
LicenseInfo.setLicenseKey(expiredLicenseKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
showExpiredPackageVersionError,
} from '../utils/licenseErrorMessageUtils';
import { LICENSE_STATUS, LicenseStatus } from '../utils/licenseStatus';
import { LicenseScope } from '../utils/licenseScope';
import { extractAcceptedScopes, extractProductScope } from '../utils/licenseScope';
import MuiLicenseInfoContext from '../Unstable_LicenseInfoProvider/MuiLicenseInfoContext';

export type MuiCommercialPackageName =
Expand Down Expand Up @@ -47,15 +47,15 @@ export function useLicenseVerifier(
return sharedLicenseStatuses[packageName]!.licenseVerifier;
}

const acceptedScopes: LicenseScope[] = packageName.includes('premium')
? ['premium']
: ['pro', 'premium'];
const acceptedScopes = extractAcceptedScopes(packageName);
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved
const productScope = extractProductScope(packageName);
flaviendelangle marked this conversation as resolved.
Show resolved Hide resolved

const plan = packageName.includes('premium') ? 'Premium' : 'Pro';
const licenseStatus = verifyLicense({
releaseInfo,
licenseKey,
acceptedScopes,
productScope,
});

const fullPackageName = `@mui/${packageName}`;
Expand Down
17 changes: 17 additions & 0 deletions packages/x-license/src/utils/licenseScope.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
export const LICENSE_SCOPES = ['pro', 'premium'] as const;
export const PRODUCT_SCOPES = ['data-grid', 'date-pickers', 'charts', 'tree-view'] as const;
export const PLAN_VERSIONS = ['initial', 'Q3-2024'] as const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced about "initial". To me, what we have today is

Suggested change
export const PLAN_VERSIONS = ['initial', 'Q3-2024'] as const;
export const PLAN_VERSIONS = ['Q3-2022', 'Q3-2024'] as const;

the last time we changed the plan.


export type LicenseScope = (typeof LICENSE_SCOPES)[number];
export type ProductScope = (typeof PRODUCT_SCOPES)[number];
export type PlanVersion = (typeof PLAN_VERSIONS)[number];

export const extractProductScope = (packageName: string): ProductScope => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small detail, default function convention we use is function for top level scope and arrow function for lower scope; applied here would be:

Suggested change
export const extractProductScope = (packageName: string): ProductScope => {
export function extractProductScope(packageName: string): ProductScope {

// extract the part between "x-" and "-pro"/"-premium"
const regex = /x-(.*?)(-pro|-premium)?$/;
const match = packageName.match(regex);
return match![1] as ProductScope;
michelengelen marked this conversation as resolved.
Show resolved Hide resolved
};

export const extractAcceptedScopes = (packageName: string): readonly LicenseScope[] => {
return packageName.includes('premium')
? LICENSE_SCOPES.filter((scope) => scope.includes('premium'))
: LICENSE_SCOPES;
};
22 changes: 22 additions & 0 deletions packages/x-license/src/verifyLicense/verifyLicense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('License: verifyLicense', () => {
releaseInfo: '__RELEASE_INFO__',
licenseKey,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.throw('MUI X: The release information is invalid. Not able to validate license.');
});
Expand All @@ -42,6 +43,7 @@ describe('License: verifyLicense', () => {
releaseInfo: RELEASE_INFO,
licenseKey,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Valid);
});
Expand All @@ -53,13 +55,15 @@ describe('License: verifyLicense', () => {
scope: 'pro',
licensingModel: 'perpetual',
orderNumber: 'MUI-123',
planVersion: 'initial',
});

expect(
verifyLicense({
releaseInfo: RELEASE_INFO,
licenseKey: expiredLicenseKey,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.ExpiredVersion);
});
Expand All @@ -72,6 +76,7 @@ describe('License: verifyLicense', () => {
licenseKey:
'b43ff5f9ac93f021855ff59ff0ba5220TkFNRTpNYC1VSSBTQVMsREVWRUxPUEVSX0NPVU5UPTEwLEVYUElSWT0xNTkxNzIzMDY3MDQyLFZFUlNJT049MS4yLjM',
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Invalid);
});
Expand All @@ -83,13 +88,15 @@ describe('License: verifyLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planVersion: 'initial',
});

const licenseKeyPremium = generateLicense({
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
orderNumber: 'MUI-123',
scope: 'premium',
licensingModel: 'subscription',
planVersion: 'initial',
});

it('should log an error when ReleaseInfo is not valid', () => {
Expand All @@ -100,6 +107,7 @@ describe('License: verifyLicense', () => {
releaseInfo: '__RELEASE_INFO__',
licenseKey: licenseKeyPro,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.throw('MUI X: The release information is invalid. Not able to validate license.');
});
Expand All @@ -112,6 +120,7 @@ describe('License: verifyLicense', () => {
releaseInfo: RELEASE_INFO,
licenseKey: licenseKeyPro,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Valid);
});
Expand All @@ -123,6 +132,7 @@ describe('License: verifyLicense', () => {
releaseInfo: RELEASE_INFO,
licenseKey: licenseKeyPremium,
acceptedScopes: ['premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Valid);
});
Expand All @@ -134,6 +144,7 @@ describe('License: verifyLicense', () => {
releaseInfo: RELEASE_INFO,
licenseKey: licenseKeyPro,
acceptedScopes: ['premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.OutOfScope);
});
Expand All @@ -147,13 +158,15 @@ describe('License: verifyLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planVersion: 'initial',
});

expect(
verifyLicense({
releaseInfo: RELEASE_INFO,
licenseKey: expiredLicenseKey,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Valid);
});
Expand All @@ -164,13 +177,15 @@ describe('License: verifyLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planVersion: 'initial',
});

expect(
verifyLicense({
releaseInfo: RELEASE_INFO,
licenseKey: expiredLicenseKey,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.ExpiredAnnualGrace);
});
Expand All @@ -182,13 +197,15 @@ describe('License: verifyLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planVersion: 'initial',
});

expect(
verifyLicense({
releaseInfo: RELEASE_INFO,
licenseKey: expiredLicenseKey,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.ExpiredAnnual);
});
Expand All @@ -199,13 +216,15 @@ describe('License: verifyLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'perpetual',
planVersion: 'initial',
});

expect(
verifyLicense({
releaseInfo: RELEASE_INFO,
licenseKey: expiredLicenseKey,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Valid);
});
Expand All @@ -219,6 +238,7 @@ describe('License: verifyLicense', () => {
licenseKey:
'b43ff5f9ac93f021855ff59ff0ba5220TkFNRTpNYC1VSSBTQVMsREVWRUxPUEVSX0NPVU5UPTEwLEVYUElSWT0xNTkxNzIzMDY3MDQyLFZFUlNJT049MS4yLjM',
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Invalid);
});
Expand All @@ -230,6 +250,7 @@ describe('License: verifyLicense', () => {
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'annual',
planVersion: 'initial',
});

it('should accept licensingModel="annual"', () => {
Expand All @@ -239,6 +260,7 @@ describe('License: verifyLicense', () => {
releaseInfo: RELEASE_INFO,
licenseKey: licenseKeyPro,
acceptedScopes: ['pro', 'premium'],
productScope: 'data-grid',
}).status,
).to.equal(LICENSE_STATUS.Valid);
});
Expand Down
Loading