This commit enhances application security against potential attacks by isolating dependencies that access the host system (like file operations) from the renderer process. It narrows the exposed functionality to script execution only, adding an extra security layer. The changes allow secure and scalable API exposure, preparing for future functionalities such as desktop notifications for script errors (#264), improved script execution handling (#296), and creating restore points (#50) in a secure and repeatable way. Changes include: - Inject `CodeRunner` into Vue components via dependency injection. - Move `CodeRunner` to the application layer as an abstraction for better domain-driven design alignment. - Refactor `SystemOperations` and related interfaces, removing the `I` prefix. - Update architecture documentation for clarity. - Update return types in `NodeSystemOperations` to match the Node APIs. - Improve `WindowVariablesProvider` integration tests for better error context. - Centralize type checks with common functions like `isArray` and `isNumber`. - Change `CodeRunner` to use `os` parameter, ensuring correct window variable injection. - Streamline API exposure to the renderer process: - Automatically bind function contexts to prevent loss of original context. - Implement a way to create facades (wrapper/proxy objects) for increased security.
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
export type Constructible<T, TArgs extends unknown[] = never> = {
|
|
prototype: T;
|
|
apply: (this: unknown, args: TArgs) => void;
|
|
readonly name: string;
|
|
};
|
|
|
|
export type PropertyKeys<T> = {
|
|
[K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? never : K;
|
|
}[keyof T];
|
|
|
|
export type ConstructorArguments<T> =
|
|
T extends new (...args: infer U) => unknown ? U : never;
|
|
|
|
export type FunctionKeys<T> = {
|
|
[K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? K : never;
|
|
}[keyof T];
|
|
|
|
export function isString(value: unknown): value is string {
|
|
return typeof value === 'string';
|
|
}
|
|
|
|
export function isNumber(value: unknown): value is number {
|
|
return typeof value === 'number';
|
|
}
|
|
|
|
export function isBoolean(value: unknown): value is boolean {
|
|
return typeof value === 'boolean';
|
|
}
|
|
|
|
export function isFunction(value: unknown): value is (...args: unknown[]) => unknown {
|
|
return typeof value === 'function';
|
|
}
|
|
|
|
export function isArray(value: unknown): value is Array<unknown> {
|
|
return Array.isArray(value);
|
|
}
|
|
|
|
export function isPlainObject(
|
|
variable: unknown,
|
|
): variable is object & Record<string, unknown> {
|
|
return Boolean(variable) // the data type of null is an object
|
|
&& typeof variable === 'object'
|
|
&& !Array.isArray(variable);
|
|
}
|
|
|
|
export function isNullOrUndefined(value: unknown): value is (null | undefined) {
|
|
return typeof value === 'undefined' || value === null;
|
|
}
|