/// import type { Json } from "@metamask/utils"; import type { SnapManifest } from "./validation.mjs"; import type { ValidatorResults } from "./validator.mjs"; import type { ValidatorMeta, ValidatorReport } from "./validator-types.mjs"; import type { DeepPartial, ExtendableSnapFiles, UnvalidatedExtendableManifest } from "../types.mjs"; import { VirtualFile } from "../virtual-file/node.mjs"; /** * Load a manifest and its extended manifest if it has one. * * Note: This function does not validate the manifests. * * @param manifestPath - The path to the manifest file. * @param files - A set of already loaded manifest file paths to prevent * circular dependencies. * @param root - Whether this is the root manifest being loaded. Used for * recursive calls, and should not be set by callers. * @returns The base and extended manifests. */ export declare function loadManifest(manifestPath: string, files?: Set, root?: boolean): Promise; export type CheckManifestReport = Omit & { wasFixed?: boolean; }; /** * The options for the `checkManifest` function. */ export type CheckManifestOptions = { /** * Whether to auto-magically try to fix errors and then write the manifest to * disk. */ updateAndWriteManifest?: boolean; /** * The source code of the Snap. */ sourceCode?: string; /** * The function to use to write the manifest to disk. */ writeFileFn?: WriteFileFunction; /** * The exports detected by evaluating the bundle. This may be used by one or * more validators to determine whether the Snap is valid. */ exports?: string[]; /** * An object containing the names of the handlers and their respective * permission name. This must be provided to avoid circular dependencies * between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`. */ handlerEndowments?: Record; /** * Whether the compiler is running in watch mode. This is used to determine * whether to fix warnings or errors only. */ watchMode?: boolean; }; /** * The result from the `checkManifest` function. * * @property manifest - The fixed manifest object. * @property updated - Whether the manifest was written and updated. */ export type CheckManifestResult = { files?: ExtendableSnapFiles; updated: boolean; reports: CheckManifestReport[]; }; export type WriteFileFunction = (path: string, data: string) => Promise; /** * Validates a snap.manifest.json file. Attempts to fix the manifest and write * the fixed version to disk if `writeManifest` is true. Throws if validation * fails. * * @param manifestPath - The path to the manifest file. * @param options - Additional options for the function. * @param options.sourceCode - The source code of the Snap. * @param options.writeFileFn - The function to use to write the manifest to * disk. * @param options.updateAndWriteManifest - Whether to auto-magically try to fix * errors and then write the manifest to disk. * @param options.exports - The exports detected by evaluating the bundle. This * may be used by one or more validators to determine whether the Snap is valid. * @param options.handlerEndowments - An object containing the names of the * handlers and their respective permission name. This must be provided to avoid * circular dependencies between `@metamask/snaps-utils` and * `@metamask/snaps-rpc-methods`. * @param options.watchMode - Whether the compiler is running in watch mode. * This is used to determine whether to fix warnings or errors only. * @returns Whether the manifest was updated, and an array of warnings that * were encountered during processing of the manifest files. */ export declare function checkManifest(manifestPath: string, { updateAndWriteManifest, sourceCode, writeFileFn, exports, handlerEndowments, watchMode, }?: CheckManifestOptions): Promise; /** * Run the algorithm for automatically fixing errors in manifest. * * The algorithm updates the manifest by fixing all fixable problems, * and then run validation again to check if the new manifest is now correct. * If not correct, the algorithm will use the manifest from previous iteration * and try again `MAX_ATTEMPTS` times to update it before bailing and * resulting in failure. * * @param results - Results of the initial run of validation. * @param rules - Optional list of rules to run the fixes with. * @param errorsOnly - Whether to only run fixes for errors, not warnings. * @returns The updated manifest and whether it was updated. */ export declare function runFixes(results: ValidatorResults, rules?: ValidatorMeta[], errorsOnly?: boolean): Promise; /** * Given an unvalidated Snap manifest, attempts to extract the location of the * bundle source file location and read the file. * * @param basePath - The path to the folder with the manifest files. * @param manifest - The unvalidated Snap manifest file contents. * @param sourceCode - Override source code for plugins. * @returns The contents of the bundle file, if any. */ export declare function getSnapSourceCode(basePath: string, manifest: Json, sourceCode?: string): Promise; /** * Given an unvalidated Snap manifest, attempts to extract the location of the * icon and read the file. * * @param basePath - The path to the folder with the manifest files. * @param manifest - The unvalidated Snap manifest file contents. * @returns The contents of the icon, if any. */ export declare function getSnapIcon(basePath: string, manifest: Json): Promise; /** * Get an array of paths from an unvalidated Snap manifest. * * @param manifest - The unvalidated Snap manifest file contents. * @param selector - A function that returns the paths to the files. * @returns The paths to the files, if any. */ export declare function getSnapFilePaths(manifest: Json, selector: (manifest: Partial) => string[] | undefined): string[] | undefined; /** * Given an unvalidated Snap manifest, attempts to extract the files with the * given paths and read them. * * @param basePath - The path to the folder with the manifest files. * @param paths - The paths to the files. * @param encoding - An optional encoding to pass down to readVirtualFile. * @returns A list of auxiliary files and their contents, if any. */ export declare function getSnapFiles(basePath: string, paths: string[] | undefined, encoding?: BufferEncoding | null): Promise; /** * Sorts the given manifest in our preferred sort order and removes the * `repository` field if it is falsy (it may be `null`). * * @param manifest - The manifest to sort and modify. * @returns The disk-ready manifest. */ export declare function getWritableManifest(manifest: DeepPartial): DeepPartial; //# sourceMappingURL=manifest.d.mts.map