function createSanitizedEnvironment({ policy, env, getCurrentNode }) {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const hook = (item) => {
        if (!policy.console && isConsoleOperation(item)) {
            return false;
        }
        if (!policy.io.read && isIoRead(item)) {
            throw new IoError({ kind: "read", node: getCurrentNode() });
        }
        if (!policy.io.write && isIoWrite(item)) {
            throw new IoError({ kind: "write", node: getCurrentNode() });
        }
        if (!policy.process.exit && isProcessExitOperation(item)) {
            throw new ProcessError({ kind: "exit", node: getCurrentNode() });
        }
        if (!policy.process.exit && isProcessSpawnChildOperation(item)) {
            throw new ProcessError({ kind: "spawnChild", node: getCurrentNode() });
        }
        if (!policy.network && isNetworkOperation(item)) {
            throw new NetworkError({ operation: stringifyPolicyTrapKindOnPath(item.kind, item.path), node: getCurrentNode() });
        }
        if (policy.deterministic && isNonDeterministic(item)) {
            throw new NonDeterministicError({ operation: stringifyPolicyTrapKindOnPath(item.kind, item.path), node: getCurrentNode() });
        }
        return true;
    };
    const descriptors = Object.entries(Object.getOwnPropertyDescriptors(env));
    const gettersAndSetters = Object.assign({}, ...descriptors.filter(([, descriptor]) => !("value" in descriptor)).map(([name, descriptor]) => ({ [name]: descriptor })));
    const values = Object.assign({}, ...descriptors
        .filter(([, descriptor]) => "value" in descriptor)
        .map(([name, descriptor]) => ({
        [name]: name === "require"
            ? new Proxy(descriptor.value, {
                /**
                 * A trap for a function call. Used to create new proxies for methods on the retrieved module objects
                 *
                 * @param target
                 * @param thisArg
                 * @param argArray
                 * @return
                 */
                apply(target, thisArg, argArray = []) {
                    const [moduleName] = argArray;
                    return createPolicyProxy({
                        policy,
                        item: Reflect.apply(target, thisArg, argArray),
                        scope: moduleName,
                        hook
                    });
                }
            })
            : createPolicyProxy({
                policy,
                item: descriptor.value,
                scope: name,
                hook
            })
    })));
    return Object.defineProperties(values, Object.assign({}, gettersAndSetters));
}
/**
 * Creates an environment that provide hooks into policy checks
 */
Creates an environment that provide hooks into policy checks
Creates an environment that provide hooks into policy checks
function createSanitizedEnvironment({ policy, env, getCurrentNode }) {
    const hook = (item) => {
        if (!policy.console && isConsoleOperation(item)) {
            return false;
        }
        if (!policy.io.read && isIoRead(item)) {
            throw new IoError({ kind: "read", node: getCurrentNode() });
        }
        if (!policy.io.write && isIoWrite(item)) {
            throw new IoError({ kind: "write", node: getCurrentNode() });
        }
        if (!policy.process.exit && isProcessExitOperation(item)) {
            throw new ProcessError({ kind: "exit", node: getCurrentNode() });
        }
        if (!policy.process.exit && isProcessSpawnChildOperation(item)) {
            throw new ProcessError({ kind: "spawnChild", node: getCurrentNode() });
        }
        if (!policy.network && isNetworkOperation(item)) {
            throw new NetworkError({ operation: stringifyPolicyTrapKindOnPath(item.kind, item.path), node: getCurrentNode() });
        }
        if (policy.deterministic && isNonDeterministic(item)) {
            throw new NonDeterministicError({ operation: stringifyPolicyTrapKindOnPath(item.kind, item.path), node: getCurrentNode() });
        }
        return true;
    };
    const descriptors = Object.entries(Object.getOwnPropertyDescriptors(env));
    const gettersAndSetters = Object.assign({}, ...descriptors.filter(([, descriptor]) => !("value" in descriptor)).map(([name, descriptor]) => ({ [name]: descriptor })));
    const values = Object.assign({}, ...descriptors
        .filter(([, descriptor]) => "value" in descriptor)
        .map(([name, descriptor]) => ({
        [name]: name === "require"
            ? new Proxy(descriptor.value, {
                apply(target, thisArg, argArray = []) {
                    const [moduleName] = argArray;
                    return createPolicyProxy({
                        policy,
                        item: Reflect.apply(target, thisArg, argArray),
                        scope: moduleName,
                        hook
                    });
                }
            })
            : createPolicyProxy({
                policy,
                item: descriptor.value,
                scope: name,
                hook
            })
    })));
    return Object.defineProperties(values, Object.assign({}, gettersAndSetters));
}
function createSanitizedEnvironment ( { policy , env , getCurrentNode } ) { const hook = ( item ) => { if ( ! policy . console && isConsoleOperation ( item ) ) { return false ; } if ( ! policy . io . read && isIoRead ( item ) ) { throw new IoError ( { kind : "read" , node : getCurrentNode ( ) } ) ; } if ( ! policy . io . write && isIoWrite ( item ) ) { throw new IoError ( { kind : "write" , node : getCurrentNode ( ) } ) ; } if ( ! policy . process . exit && isProcessExitOperation ( item ) ) { throw new ProcessError ( { kind : "exit" , node : getCurrentNode ( ) } ) ; } if ( ! policy . process . exit && isProcessSpawnChildOperation ( item ) ) { throw new ProcessError ( { kind : "spawnChild" , node : getCurrentNode ( ) } ) ; } if ( ! policy . network && isNetworkOperation ( item ) ) { throw new NetworkError ( { operation : stringifyPolicyTrapKindOnPath ( item . kind , item . path ) , node : getCurrentNode ( ) } ) ; } if ( policy . deterministic && isNonDeterministic ( item ) ) { throw new NonDeterministicError ( { operation : stringifyPolicyTrapKindOnPath ( item . kind , item . path ) , node : getCurrentNode ( ) } ) ; } return true ; } ; const descriptors = Object . entries ( Object . getOwnPropertyDescriptors ( env ) ) ; const gettersAndSetters = Object . assign ( { } , ... descriptors . filter ( ( [ , descriptor ] ) => ! ( "value" in descriptor ) ) . map ( ( [ name , descriptor ] ) => ( { [ name ] : descriptor } ) ) ) ; const values = Object . assign ( { } , ... descriptors . filter ( ( [ , descriptor ] ) => "value" in descriptor ) . map ( ( [ name , descriptor ] ) => ( { [ name ] : name === "require" ? new Proxy ( descriptor . value , { apply ( target , thisArg , argArray = [ ] ) { const [ moduleName ] = argArray ; return createPolicyProxy ( { policy , item : Reflect . apply ( target , thisArg , argArray ) , scope : moduleName , hook } ) ; } } ) : createPolicyProxy ( { policy , item : descriptor . value , scope : name , hook } ) } ) ) ) ; return Object . defineProperties ( values , Object . assign ( { } , gettersAndSetters ) ) ; }
Creates an environment that provide hooks into policy checks
Creates an environment that provide hooks into policy checks
// eslint-disable-next-line @typescript-eslint/no-explicit-any /**
                 * A trap for a function call. Used to create new proxies for methods on the retrieved module objects
                 *
                 * @param target
                 * @param thisArg
                 * @param argArray
                 * @return
                 */