-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./lavamoat-policy.v0-0-1.schema"; |
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,72 @@ | ||
/** | ||
* Adapted from `type-fest` and simplified | ||
*/ | ||
export type RequireAtLeastOne< | ||
ObjectType, | ||
KeysType extends keyof ObjectType = keyof ObjectType | ||
> = { | ||
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & | ||
Partial<Pick<ObjectType, Exclude<KeysType, Key>>>; | ||
}[KeysType]; | ||
|
||
/** | ||
* Schema for LavaMoat policy files | ||
*/ | ||
export type LavaMoatPolicySchema = RequireAtLeastOne< | ||
PartialLavaMoatPolicySchema, | ||
"resources" | "resolutions" | ||
>; | ||
|
||
export interface PartialLavaMoatPolicySchema { | ||
resources?: Resources; | ||
resolutions?: Resolutions; | ||
} | ||
|
||
/** | ||
* Describe the resources available to your application and direct dependencies | ||
*/ | ||
export interface Resources { | ||
[k: "<root>" | string]: ResourcePolicy; | ||
} | ||
|
||
export interface ResourcePolicy { | ||
globals?: Globals; | ||
builtins?: NodeJsBuiltins; | ||
packages?: ExternalPackages; | ||
} | ||
|
||
/** | ||
* Globals (including properties using dot notation) accessible to the module; `true` to allow and `false` to deny | ||
*/ | ||
export interface Globals { | ||
[k: string]: boolean; | ||
} | ||
|
||
/** | ||
* Node.js builtins (including properties using dot notation); `true` to allow and `false` to deny | ||
*/ | ||
export interface NodeJsBuiltins { | ||
[k: string]: boolean; | ||
} | ||
|
||
/** | ||
* Additional external packages (in their entirety) accessible to the module; `true` to allow and `false` to deny | ||
*/ | ||
export interface ExternalPackages { | ||
[k: string]: boolean; | ||
} | ||
|
||
/** | ||
* Custom run-time module resolutions by direct dependency | ||
*/ | ||
export interface Resolutions { | ||
/** | ||
* The key is the dependency name | ||
*/ | ||
[k: string]: { | ||
/** | ||
* The key is the original module path and the value is the new module path | ||
*/ | ||
[k: string]: string; | ||
}; | ||
} |