-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: License v3 - behavior and limited reached triggers (#30561)
Co-authored-by: Guilherme Gazzo <[email protected]>
- Loading branch information
1 parent
6d46183
commit e666487
Showing
23 changed files
with
470 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import type { LicenseLimitKind } from './ILicenseV3'; | ||
import type { LicenseModule } from './LicenseModule'; | ||
|
||
export type LicenseBehavior = 'invalidate_license' | 'start_fair_policy' | 'prevent_action' | 'prevent_installation' | 'disable_modules'; | ||
|
||
export type BehaviorWithContext = { | ||
behavior: LicenseBehavior; | ||
modules?: LicenseModule[]; | ||
}; | ||
export type BehaviorWithContext = | ||
| { | ||
behavior: LicenseBehavior; | ||
modules?: LicenseModule[]; | ||
reason: 'limit'; | ||
limit?: LicenseLimitKind; | ||
} | ||
| { | ||
behavior: LicenseBehavior; | ||
modules?: LicenseModule[]; | ||
reason: 'period' | 'url'; | ||
}; |
11 changes: 11 additions & 0 deletions
11
ee/packages/license/src/definition/LicenseValidationOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { LicenseLimitKind } from './ILicenseV3'; | ||
import type { LicenseBehavior } from './LicenseBehavior'; | ||
import type { LimitContext } from './LimitContext'; | ||
|
||
export type LicenseValidationOptions = { | ||
behaviors?: LicenseBehavior[]; | ||
limits?: LicenseLimitKind[]; | ||
suppressLog?: boolean; | ||
isNewLicense?: boolean; | ||
context?: Partial<{ [K in LicenseLimitKind]: Partial<LimitContext<LicenseLimitKind>> }>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { LicenseLimitKind } from './ILicenseV3'; | ||
import type { BehaviorWithContext, LicenseBehavior } from './LicenseBehavior'; | ||
import type { LicenseModule } from './LicenseModule'; | ||
|
||
type ModuleValidation = Record<`${'invalid' | 'valid'}:${LicenseModule}`, undefined>; | ||
type BehaviorTriggered = Record<`behavior:${LicenseBehavior}`, { reason: BehaviorWithContext['reason']; limit?: LicenseLimitKind }>; | ||
type LimitReached = Record<`limitReached:${LicenseLimitKind}`, undefined>; | ||
|
||
export type LicenseEvents = ModuleValidation & | ||
BehaviorTriggered & | ||
LimitReached & { | ||
validate: undefined; | ||
invalidate: undefined; | ||
module: { module: LicenseModule; valid: boolean }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { LicenseLimitKind } from './definition/ILicenseV3'; | ||
import type { LicenseBehavior } from './definition/LicenseBehavior'; | ||
import type { LicenseValidationOptions } from './definition/LicenseValidationOptions'; | ||
|
||
const isItemAllowed = <T>(item: T, allowList?: T[]): boolean => { | ||
return !allowList || allowList.includes(item); | ||
}; | ||
|
||
export const isLimitAllowed = (item: LicenseLimitKind, options: LicenseValidationOptions): boolean => isItemAllowed(item, options.limits); | ||
|
||
export const isBehaviorAllowed = (item: LicenseBehavior, options: LicenseValidationOptions): boolean => | ||
isItemAllowed(item, options.behaviors) && (options.isNewLicense || item !== 'prevent_installation'); |
Oops, something went wrong.