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 3 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 @@ -10,7 +10,7 @@ import {
showExpiredPackageVersionError,
} from '../utils/licenseErrorMessageUtils';
import { LICENSE_STATUS, LicenseStatus } from '../utils/licenseStatus';
import { LicenseScope } from '../utils/licenseScope';
import { extractAcceptedScopes, LicenseScope } from '../utils/licenseScope';
import MuiLicenseInfoContext from '../Unstable_LicenseInfoProvider/MuiLicenseInfoContext';

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

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

const plan = packageName.includes('premium') ? 'Premium' : 'Pro';
const licenseStatus = verifyLicense({
Expand Down
23 changes: 22 additions & 1 deletion packages/x-license/src/utils/licenseScope.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
export const LICENSE_SCOPES = ['pro', 'premium'] as const;
export const LICENSE_SCOPES = ['pro', 'premium', 'pro2024', 'premium2024'] as const;
michelengelen marked this conversation as resolved.
Show resolved Hide resolved
export const PRODUCT_SCOPES = ['data-grid', 'date-pickers', 'charts', 'tree-view'] as const;

export type LicenseScope = (typeof LICENSE_SCOPES)[number];
export type ProductScope = (typeof PRODUCT_SCOPES)[number] | null;

export const extractProductScope = (packageName: string): ProductScope | null => {
const regex = /x-(.*?)(-pro|-premium)?$/;
const match = packageName.match(regex);
return match ? (match[1] as ProductScope) : null;
};

export const extractAcceptedScopes = (packageName: string): readonly LicenseScope[] => {
const productScope = extractProductScope(packageName);

const scopes = packageName.includes('premium')
? LICENSE_SCOPES.filter((scope) => scope.includes('premium'))
: LICENSE_SCOPES;

if (productScope === 'charts' || productScope === 'tree-view') {
return scopes.filter((scope) => scope.includes('2024'));
}
return scopes;
};
2 changes: 1 addition & 1 deletion packages/x-license/src/verifyLicense/verifyLicense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function verifyLicense({
}: {
releaseInfo: string;
licenseKey: string | undefined;
acceptedScopes: LicenseScope[];
acceptedScopes: readonly LicenseScope[];
}): { status: LicenseStatus; meta?: any } {
if (!releaseInfo) {
throw new Error('MUI X: The release information is missing. Not able to validate license.');
Expand Down