UNPKG

@kinvolk/headlamp-plugin

Version:

The needed infrastructure for building Headlamp plugins.

97 lines (96 loc) 4.82 kB
/** * This is as a list of parameters to be passed to the `runPlugin` function. * To reduce the ability of overridden prototypes from snooping on data, * if it is destructured. * * @param pluginPath path to plugin * @param packageName name of package * @param packageVersion version of package * @param permissionSecrets permission secrets are keyed by permission name, valued by secret * @param handleError call back when an execution error occurs in the plugin * @param getAllowedPermissions call back which returns only allowed permission secrets for plugin * @param getArgValues call back which returns the argument names and values for the plugin * @param privateFunction is a non global private copy of Function * */ export type runPluginProps = [ /** path to plugin */ source: string, /** name of package */ packageName: string, /** version of package */ packageVersion: string, /** call back when an execution error occurs in the plugin */ handleError: (error: unknown, packageName: string, packageVersion: string) => void, /** is a non global private copy of Function */ PrivateFunction: typeof Function, /** The argument names to be given to the plugin */ args: string[], /** The values for the arguments to be given to the plugin */ values: unknown[], /** A private copy of runPlugin */ internalRunPlugin: typeof runPlugin, /** A private copy of console.error */ consoleError: typeof console.error ]; /** * Prepares the information needed to run a plugin with the `runPlugin` function. * * This function gathers the necessary details such as source code, package name, * version, and permissions, and returns them in a structured format that can be * used to execute the plugin with the `runPlugin` function. * * This is a separate step to reduce the amount of information available to the `runPlugin` function. * * @param source source code of plugin * @param pluginPath path to plugin * @param packageName name of package * @param packageVersion version of package * @param permissionSecrets permission secrets are keyed by permission name, valued by secret * @param handleError call back when an execution error occurs in the plugin * @param getAllowedPermissions call back which returns only allowed permission secrets for plugin * @param getArgValues call back which returns the argument names and values for the plugin * @param privateFunction is a non global private copy of Function */ export declare function getInfoForRunningPlugins({ source, pluginPath, packageName, packageVersion, permissionSecrets, handleError, getAllowedPermissions, getArgValues, PrivateFunction, internalRunPlugin, consoleError, }: { source: string; pluginPath: string; packageName: string; packageVersion: string; permissionSecrets: Record<string, number>; handleError: (error: unknown, packageName: string, packageVersion: string) => void; getAllowedPermissions: (pluginName: string, pluginPath: string, permissionSecrets: Record<string, number>) => Record<string, number>; getArgValues: (pluginName: string, pluginPath: string, allowedPermissions: Record<string, number>) => [string[], unknown[]]; PrivateFunction: typeof Function; internalRunPlugin: typeof runPlugin; consoleError: typeof console.error; }): runPluginProps | undefined; /** * Runs a plugin by executing the source code in the global scope. * * This provides a way to pass private variables to individual plugins. * * @param source source code of plugin * @param packageName name of package * @param packageVersion version of package * @param handleError call back when an execution error occurs in the plugin * @param PrivateFunction is a non global private copy of Function * @param args The argument names to be given to the plugin * @param values The values for the arguments to be given to the plugin * * @see getInfoForRunningPlugins for more details */ export declare function runPlugin(source: string, packageName: string, packageVersion: string, handleError: (error: unknown, packageName: string, packageVersion: string) => void, PrivateFunction: typeof Function, args: string[], values: unknown[]): void; /** * Identifies which packages this is, taking into account prereleases, and development mode. * * @param pluginPath is like "plugins/headlamp-pod-counter" * @param pluginName is like "@headlamp-k8s/minikube" * @param isDevelopmentMode * @returns the packages with { '@headlamp-k8s/minikube': true } * * @example * > identifyPackages('plugins/headlamp_minikube', '@headlamp-k8s/minikube', false) * { '@headlamp-k8s/minikube': true } */ export declare function identifyPackages(pluginPath: string, pluginName: string, isDevelopmentMode: boolean): Record<string, boolean>;