-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[license] Allow to limit some packages to a specific license plan #4651
Changes from all commits
aca1806
daf89fd
85e74e1
c39c2cf
d06402a
0ed09b9
c7dd1b9
9111bfe
43d4126
e08a004
afda9c5
2189119
f5670bf
a903f18
0f6efa7
1e18b49
4b8f75f
d348529
2cd8f7c
f78817c
9af2a9d
501769c
336bd21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
import { md5 } from '../encoding/md5'; | ||
import { base64Encode } from '../encoding/base64'; | ||
import { LICENSE_SCOPES, LicenseScope } from '../utils/licenseScope'; | ||
import { LICENSING_MODELS, LicensingModel } from '../utils/licensingModel'; | ||
|
||
const licenseVersion = '2'; | ||
|
||
export type LicenseScope = 'pro' | 'premium'; | ||
|
||
export interface LicenseDetails { | ||
orderNumber: string; | ||
expiryDate: Date; | ||
// TODO: to be made required once the store is updated | ||
scope?: LicenseScope; | ||
// TODO: to be made required once the store is updated | ||
licensingModel?: LicensingModel; | ||
} | ||
|
||
function getClearLicenseString(details: LicenseDetails) { | ||
return `ORDER:${ | ||
details.orderNumber | ||
},EXPIRY=${details.expiryDate.getTime()},KEYVERSION=${licenseVersion},SCOPE=${details.scope}`; | ||
if (details.scope && !LICENSE_SCOPES.includes(details.scope)) { | ||
throw new Error('MUI: Invalid scope'); | ||
} | ||
|
||
if (details.licensingModel && !LICENSING_MODELS.includes(details.licensingModel)) { | ||
throw new Error('MUI: Invalid sales model'); | ||
} | ||
|
||
return `O=${details.orderNumber},E=${details.expiryDate.getTime()},S=${ | ||
details.scope ?? 'pro' | ||
},LM=${details.licensingModel ?? 'perpetual'},KV=${licenseVersion}`; | ||
} | ||
|
||
export function generateLicense(details: LicenseDetails) { | ||
let clearLicense; | ||
if (details.scope) { | ||
clearLicense = getClearLicenseString(details); | ||
} else { | ||
clearLicense = getClearLicenseString({ ...details, scope: 'pro' }); | ||
} | ||
const licenseStr = getClearLicenseString(details); | ||
|
||
return `${md5(base64Encode(clearLicense))}${base64Encode(clearLicense)}`; | ||
return `${md5(base64Encode(licenseStr))}${base64Encode(licenseStr)}`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
showNotFoundLicenseError, | ||
} from '../utils/licenseErrorMessageUtils'; | ||
import { LicenseStatus } from '../utils/licenseStatus'; | ||
import { LicenseScope } from '../utils/licenseScope'; | ||
|
||
export type MuiCommercialPackageName = | ||
| 'x-data-grid-pro' | ||
|
@@ -27,7 +28,16 @@ export function useLicenseVerifier( | |
return sharedLicenseStatuses[packageName]!.status; | ||
} | ||
|
||
const licenseStatus = verifyLicense(releaseInfo, licenseKey); | ||
const acceptedScopes: LicenseScope[] = packageName.includes('premium') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic would have to become smarter if we release other plans There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So to be sure that I understand it - the goal here is to if you have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
? ['premium'] | ||
: ['pro', 'premium']; | ||
|
||
const licenseStatus = verifyLicense({ | ||
releaseInfo, | ||
licenseKey, | ||
acceptedScopes, | ||
isProduction: process.env.NODE_ENV === 'production', | ||
}); | ||
|
||
sharedLicenseStatuses[packageName] = { key: licenseStatus, status: licenseStatus }; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './licenseErrorMessageUtils'; | ||
export * from './licenseInfo'; | ||
export * from './licenseStatus'; | ||
export type { LicenseScope } from './licenseScope'; | ||
export type { LicensingModel } from './licensingModel'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const LICENSE_SCOPES = ['pro', 'premium'] as const; | ||
|
||
export type LicenseScope = typeof LICENSE_SCOPES[number]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const LICENSING_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. | ||
*/ | ||
'perpetual', | ||
/** | ||
* On development, a license is outdated if the expiry date has been reached | ||
* On production, a license is outdated if the current version of the software was released after the expiry date of the license (see "perpetual") | ||
*/ | ||
'subscription', | ||
] as const; | ||
|
||
export type LicensingModel = typeof LICENSING_MODELS[number]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this change, a v2 license key is not usable by < v5.11.0 of the software. It's not backward compatible. It surfaced in https://groups.google.com/a/mui.com/g/x/c/Nkq2fQbGkn0/. Time will tell if this causes trouble with more users, I suspect it will. If the intent is to shorten the string key, I doubt it's worth the breaking change. If a breaking change needs to happen, then I think bundling with #4892 could be great.
How about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joserodolfofreitas we are one week in, how are the upgrades support cases going? I haven't seen new ones, so maybe it's fine.