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

[license] Clean-up terminology to match codebase #14531

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -13,7 +13,7 @@ describe('<DataGridPremium /> - License', () => {
generateLicense({
expiryDate: addYears(new Date(), 1),
orderNumber: 'Test',
licensingModel: 'subscription',
licenseModel: 'subscription',
scope: 'pro',
planVersion: 'initial',
}),
Expand Down
28 changes: 14 additions & 14 deletions packages/x-license/src/generateLicense/generateLicense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ describe('License: generateLicense', () => {
generateLicense({
expiryDate: new Date(1591723879062),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
}),
).to.equal(
Expand All @@ -21,36 +21,36 @@ describe('License: generateLicense', () => {
generateLicense({
expiryDate: new Date(1591723879062),
orderNumber: 'MUI-123',
scope: 'premium',
licensingModel: 'subscription',
planScope: 'premium',
licenseModel: 'subscription',
planVersion: 'initial',
}),
).to.equal(
'8ca0384bfb92ec214d4cd72483f5110bTz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXByZW1pdW0sTE09c3Vic2NyaXB0aW9uLFBWPWluaXRpYWwsS1Y9Mg==',
);
});

it('should generate annual license when `licensingModel: "subscription"`', () => {
it('should generate annual license when `licenseModel: "subscription"`', () => {
expect(
generateLicense({
expiryDate: new Date(1591723879062),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
}),
).to.equal(
'e8fad422a82720084ec67dd693f08056Tz1NVUktMTIzLEU9MTU5MTcyMzg3OTA2MixTPXBybyxMTT1zdWJzY3JpcHRpb24sUFY9aW5pdGlhbCxLVj0y',
);
});

it('should generate perpetual license when `licensingModel: "perpetual"`', () => {
it('should generate perpetual license when `licenseModel: "perpetual"`', () => {
expect(
generateLicense({
expiryDate: new Date(1591723879062),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'perpetual',
planScope: 'pro',
licenseModel: 'perpetual',
planVersion: 'initial',
}),
).to.equal(
Expand All @@ -63,8 +63,8 @@ describe('License: generateLicense', () => {
generateLicense({
expiryDate: new Date(1591723879062),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'Q3-2024',
}),
).to.equal(
Expand All @@ -77,8 +77,8 @@ describe('License: generateLicense', () => {
generateLicense({
expiryDate: new Date(1591723879062),
orderNumber: 'MUI-123',
scope: 'premium',
licensingModel: 'subscription',
planScope: 'premium',
licenseModel: 'subscription',
planVersion: 'Q3-2024',
}),
).to.equal(
Expand Down
22 changes: 14 additions & 8 deletions packages/x-license/src/generateLicense/generateLicense.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { md5 } from '../encoding/md5';
import { base64Encode } from '../encoding/base64';
import { LICENSE_SCOPES, LicenseScope, PlanVersion } from '../utils/licenseScope';
import { LICENSING_MODELS, LicensingModel } from '../utils/licensingModel';
import { PLAN_SCOPES, PlanScope, PlanVersion } from '../utils/plan';
import { LICENSE_MODELS, LicenseModel } from '../utils/licenseModel';

const licenseVersion = '2';

export interface LicenseDetails {
orderNumber: string;
expiryDate: Date;
scope?: LicenseScope;
planScope?: LicenseScope; // TODO deprecate
licenseModel?: LicensingModel;
licensingModel?: LicensingModel; // TODO deprecate
/**
* @deprecated Use planScope instead.
*/
scope?: PlanScope;
planScope?: PlanScope;
/**
* @deprecated Use licenseModel instead.
*/
licensingModel?: LicenseModel; // TODO deprecate
licenseModel?: LicenseModel;
planVersion: PlanVersion;
}

Expand All @@ -25,11 +31,11 @@ function getClearLicenseString(details: LicenseDetails) {
details.planScope = details.scope;
}

if (details.planScope && !LICENSE_SCOPES.includes(details.planScope)) {
if (details.planScope && !PLAN_SCOPES.includes(details.planScope)) {
throw new Error('MUI X: Invalid scope');
}

if (details.licenseModel && !LICENSING_MODELS.includes(details.licenseModel)) {
if (details.licenseModel && !LICENSE_MODELS.includes(details.licenseModel)) {
throw new Error('MUI X: Invalid licensing model');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ describe('useLicenseVerifier', function test() {
it('should detect an override of a valid license key in the context', () => {
const key = generateLicense({
expiryDate: new Date(3001, 0, 0, 0, 0, 0, 0),
licensingModel: 'perpetual',
licenseModel: 'perpetual',
orderNumber: '12345',
scope: 'pro',
planScope: 'pro',
planVersion: 'initial',
});

Expand All @@ -88,8 +88,8 @@ describe('useLicenseVerifier', function test() {
const expiredLicenseKey = generateLicense({
expiryDate: new Date(new Date().getTime() - oneDayInMS * 30),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
});
LicenseInfo.setLicenseKey(expiredLicenseKey);
Expand Down Expand Up @@ -117,8 +117,8 @@ describe('useLicenseVerifier', function test() {
const licenseKey = generateLicense({
expiryDate: new Date(3001, 0, 0, 0, 0, 0, 0),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
});

Expand All @@ -141,8 +141,8 @@ describe('useLicenseVerifier', function test() {
const licenseKey = generateLicense({
expiryDate: new Date(3001, 0, 0, 0, 0, 0, 0),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'Q3-2024',
});

Expand All @@ -165,8 +165,8 @@ describe('useLicenseVerifier', function test() {
const licenseKey = generateLicense({
expiryDate: new Date(3001, 0, 0, 0, 0, 0, 0),
orderNumber: 'MUI-123',
scope: 'premium',
licensingModel: 'subscription',
planScope: 'premium',
licenseModel: 'subscription',
planVersion: 'Q3-2024',
});

Expand Down
4 changes: 2 additions & 2 deletions packages/x-license/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './licenseErrorMessageUtils';
export * from './licenseInfo';
export * from './licenseStatus';
export type { LicenseScope } from './licenseScope';
export type { LicensingModel } from './licensingModel';
export type { PlanScope } from './plan';
export type { LicenseModel } from './licenseModel';
export type { MuiCommercialPackageName } from './commercialPackages';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const LICENSING_MODELS = [
export const LICENSE_MODELS = [
/**
* A license is outdated if the current version of the software was released after the expiry date of the license.
* But the license can be used indefinitely with an older version of the software.
Expand All @@ -10,9 +10,9 @@ export const LICENSING_MODELS = [
*/
'annual',
/**
* TODO 2025 remove, legacy name of annual.
* TODO 2026 remove, legacy name of annual.
*/
'subscription',
] as const;

export type LicensingModel = (typeof LICENSING_MODELS)[number];
export type LicenseModel = (typeof LICENSE_MODELS)[number];
Copy link
Member

Choose a reason for hiding this comment

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

This is public API strictly speaking
We can either keep exporting an LicensingModel next to LicenseModel, or don't care because nobody would actually use this variable

Copy link
Member Author

Choose a reason for hiding this comment

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

We indeed use for this tool: https://tools-private.mui.com/prod/pages/x_licenseKey. But it's simple to handle on our side.

Copy link
Member

Choose a reason for hiding this comment

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

But do we agree that it's a breaking change? Since it's exported from a package people install, and without an unstable or equivalent prefix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically, it's a breaking change, but we have never documented it and there is no practical use case for developers, so I think it's ok.

We have #9346 about the root problem.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const LICENSE_SCOPES = ['pro', 'premium'] as const;
export const PLAN_SCOPES = ['pro', 'premium'] as const;
export const PLAN_VERSIONS = ['initial', 'Q3-2024'] as const;

export type LicenseScope = (typeof LICENSE_SCOPES)[number];
export type PlanScope = (typeof PLAN_SCOPES)[number];
Copy link
Member

Choose a reason for hiding this comment

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

This is public API strictly speaking
We can either keep exporting an LIcenseScope next to PlanScope, or don't care because nobody would actually use this variable

export type PlanVersion = (typeof PLAN_VERSIONS)[number];
46 changes: 23 additions & 23 deletions packages/x-license/src/verifyLicense/verifyLicense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('License: verifyLicense', () => {
process.env.NODE_ENV = 'production';
const expiredLicenseKey = generateLicense({
expiryDate: new Date(releaseDate.getTime() - oneDayInMS),
scope: 'pro',
licensingModel: 'perpetual',
planScope: 'pro',
licenseModel: 'perpetual',
orderNumber: 'MUI-123',
planVersion: 'initial',
});
Expand Down Expand Up @@ -82,16 +82,16 @@ describe('License: verifyLicense', () => {
const licenseKeyPro = generateLicense({
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
});

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

Expand Down Expand Up @@ -148,8 +148,8 @@ describe('License: verifyLicense', () => {
const expiredLicenseKey = generateLicense({
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
});

Expand All @@ -166,8 +166,8 @@ describe('License: verifyLicense', () => {
const expiredLicenseKey = generateLicense({
expiryDate: new Date(new Date().getTime() - oneDayInMS),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
});

Expand All @@ -185,8 +185,8 @@ describe('License: verifyLicense', () => {
const expiredLicenseKey = generateLicense({
expiryDate: new Date(new Date().getTime() - oneDayInMS * 30),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'subscription',
planScope: 'pro',
licenseModel: 'subscription',
planVersion: 'initial',
});

Expand All @@ -203,8 +203,8 @@ describe('License: verifyLicense', () => {
const expiredLicenseKey = generateLicense({
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'perpetual',
planScope: 'pro',
licenseModel: 'perpetual',
planVersion: 'initial',
});

Expand Down Expand Up @@ -235,12 +235,12 @@ describe('License: verifyLicense', () => {
const licenseKeyPro = generateLicense({
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'annual',
planScope: 'pro',
licenseModel: 'annual',
planVersion: 'initial',
});

it('should accept licensingModel="annual"', () => {
it('should accept licenseModel="annual"', () => {
process.env.NODE_ENV = 'production';
expect(
verifyLicense({
Expand All @@ -256,24 +256,24 @@ describe('License: verifyLicense', () => {
const proLicenseKeyInitial = generateLicense({
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'annual',
planScope: 'pro',
licenseModel: 'annual',
planVersion: 'initial',
});

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

const proLicenseKeyQ32024 = generateLicense({
expiryDate: new Date(releaseDate.getTime() + oneDayInMS),
orderNumber: 'MUI-123',
scope: 'pro',
licensingModel: 'annual',
planScope: 'pro',
licenseModel: 'annual',
planVersion: 'Q3-2024',
});

Expand Down
Loading