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] Add new license status 'Out of scope' #6774

Merged
merged 2 commits into from
Nov 8, 2022
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
5 changes: 5 additions & 0 deletions docs/data/introduction/licensing/licensing.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ For example, if you purchase a one-year license today, you will be able to updat
Those versions will always be available for use in a deployed application,
however you'll be required to renew your license if you need to continue development with a version released after twelve months.

#### Out of scope license key

This error indicates that the component you are trying to use is not included in your license.
This can happen if you try to use `DataGridPremium` with a Pro license.

#### Invalid license key

This error indicates that your license key doesn't match what is expected. This is likely a typo.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import addYears from 'date-fns/addYears';
import { expect } from 'chai';
// @ts-ignore Remove once the test utils are typed
import { createRenderer } from '@mui/monorepo/test/utils';
import { DataGridPremium, LicenseInfo } from '@mui/x-data-grid-premium';
import { generateLicense } from '@mui/x-license-pro';

describe('<DataGridPremium /> - License', () => {
const { render } = createRenderer();

it('should throw out of scope error when using DataGridPremium with a pro license', () => {
LicenseInfo.setLicenseKey(
generateLicense({
expiryDate: addYears(new Date(), 1),
orderNumber: 'Test',
scope: 'pro',
}),
);
expect(() => render(<DataGridPremium columns={[]} rows={[]} autoHeight />)).toErrorDev([
'Your MUI X license key isn\'t valid. You are rendering a DataGridPremium component that requires a license key with the "premium" feature scope but your license key has the "pro" feature scope',
]);
});
});
4 changes: 3 additions & 1 deletion packages/x-license-pro/src/Watermark/Watermark.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useLicenseVerifier, MuiCommercialPackageName } from '../useLicenseVerifier';
import { MuiCommercialPackageName, useLicenseVerifier } from '../useLicenseVerifier';
import { LicenseStatus } from '../utils/licenseStatus';

function getLicenseErrorMessage(licenseStatus: LicenseStatus) {
Expand All @@ -8,6 +8,8 @@ function getLicenseErrorMessage(licenseStatus: LicenseStatus) {
return 'MUI X: License key expired';
case LicenseStatus.Invalid:
return 'MUI X: Invalid license key';
case LicenseStatus.OutOfScope:
return 'MUI X: Out of scope license key';
case LicenseStatus.NotFound:
return 'MUI X: Missing license key';
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
showExpiredLicenseError,
showInvalidLicenseError,
showNotFoundLicenseError,
showOutOfScopeLicenseError,
} from '../utils/licenseErrorMessageUtils';
import { LicenseStatus } from '../utils/licenseStatus';
import { LicenseScope } from '../utils/licenseScope';
Expand Down Expand Up @@ -47,6 +48,8 @@ export function useLicenseVerifier(

if (licenseStatus === LicenseStatus.Invalid) {
showInvalidLicenseError();
} else if (licenseStatus === LicenseStatus.OutOfScope) {
showOutOfScopeLicenseError();
} else if (licenseStatus === LicenseStatus.NotFound) {
showNotFoundLicenseError({ plan, packageName: `@mui/${packageName}` });
} else if (licenseStatus === LicenseStatus.Expired) {
Expand Down
11 changes: 11 additions & 0 deletions packages/x-license-pro/src/utils/licenseErrorMessageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ export function showInvalidLicenseError() {
]);
}

export function showOutOfScopeLicenseError() {
showError([
'MUI: Out of scope license key.',
'',
'Your MUI X license key isn\'t valid. You are rendering a DataGridPremium component that requires a license key with the "premium" feature scope but your license key has the "pro" feature scope.',
'',
'You can solve the issue by purchasing a Premium license at https://mui.com/r/x-get-license?scope=premium',
'Alternatively, you can replace the import on DataGridPremium with DataGridPro.',
]);
}

export function showNotFoundLicenseError({
plan,
packageName,
Expand Down
1 change: 1 addition & 0 deletions packages/x-license-pro/src/utils/licenseStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ enum LicenseStatus {
Invalid = 'Invalid',
Expired = 'Expired',
Valid = 'Valid',
OutOfScope = 'OutOfScope',
}

export { LicenseStatus };
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('License: verifyLicense', () => {
acceptedScopes: ['premium'],
isProduction: true,
}),
).to.equal(LicenseStatus.Invalid);
).to.equal(LicenseStatus.OutOfScope);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/x-license-pro/src/verifyLicense/verifyLicense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function verifyLicense({
}

if (!acceptedScopes.includes(license.scope)) {
return LicenseStatus.Invalid;
return LicenseStatus.OutOfScope;
}

return LicenseStatus.Valid;
Expand Down
1 change: 1 addition & 0 deletions scripts/x-license-pro.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{ "name": "showExpiredLicenseError", "kind": "Function" },
{ "name": "showInvalidLicenseError", "kind": "Function" },
{ "name": "showNotFoundLicenseError", "kind": "Function" },
{ "name": "showOutOfScopeLicenseError", "kind": "Function" },
{ "name": "useLicenseVerifier", "kind": "Function" },
{ "name": "verifyLicense", "kind": "Function" },
{ "name": "Watermark", "kind": "Function" }
Expand Down