@metamask/snaps-utils 9.2.2 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/dist/account.cjs +53 -0
- package/dist/account.cjs.map +1 -1
- package/dist/account.d.cts +26 -1
- package/dist/account.d.cts.map +1 -1
- package/dist/account.d.mts +26 -1
- package/dist/account.d.mts.map +1 -1
- package/dist/account.mjs +49 -1
- package/dist/account.mjs.map +1 -1
- package/dist/eval-worker.cjs +38 -11
- package/dist/eval-worker.cjs.map +1 -1
- package/dist/eval-worker.d.cts.map +1 -1
- package/dist/eval-worker.d.mts.map +1 -1
- package/dist/eval-worker.mjs +38 -11
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/eval.cjs +6 -0
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.d.cts +7 -0
- package/dist/eval.d.cts.map +1 -1
- package/dist/eval.d.mts +7 -0
- package/dist/eval.d.mts.map +1 -1
- package/dist/eval.mjs +6 -0
- package/dist/eval.mjs.map +1 -1
- package/dist/fs.cjs +51 -6
- package/dist/fs.cjs.map +1 -1
- package/dist/fs.d.cts +16 -4
- package/dist/fs.d.cts.map +1 -1
- package/dist/fs.d.mts +16 -4
- package/dist/fs.d.mts.map +1 -1
- package/dist/fs.mjs +49 -5
- package/dist/fs.mjs.map +1 -1
- package/dist/handlers/exports.cjs +7 -0
- package/dist/handlers/exports.cjs.map +1 -1
- package/dist/handlers/exports.d.cts +6 -1
- package/dist/handlers/exports.d.cts.map +1 -1
- package/dist/handlers/exports.d.mts +6 -1
- package/dist/handlers/exports.d.mts.map +1 -1
- package/dist/handlers/exports.mjs +7 -0
- package/dist/handlers/exports.mjs.map +1 -1
- package/dist/handlers/home-page.d.cts +3 -3
- package/dist/handlers/home-page.d.mts +3 -3
- package/dist/handlers/settings-page.d.cts +1 -1
- package/dist/handlers/settings-page.d.mts +1 -1
- package/dist/handlers/signature.d.cts +1 -1
- package/dist/handlers/signature.d.mts +1 -1
- package/dist/handlers/transaction.d.cts +3 -3
- package/dist/handlers/transaction.d.mts +3 -3
- package/dist/handlers/types.cjs +1 -0
- package/dist/handlers/types.cjs.map +1 -1
- package/dist/handlers/types.d.cts +2 -1
- package/dist/handlers/types.d.cts.map +1 -1
- package/dist/handlers/types.d.mts +2 -1
- package/dist/handlers/types.d.mts.map +1 -1
- package/dist/handlers/types.mjs +1 -0
- package/dist/handlers/types.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +36 -4
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts +40 -7
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts +40 -7
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +13 -4
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +18 -1
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +18 -1
- package/dist/manifest/validator-types.d.mts.map +1 -1
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +23 -10
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.d.cts +4 -2
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts +4 -2
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs +23 -10
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/index.cjs +2 -0
- package/dist/manifest/validators/index.cjs.map +1 -1
- package/dist/manifest/validators/index.d.cts +2 -0
- package/dist/manifest/validators/index.d.cts.map +1 -1
- package/dist/manifest/validators/index.d.mts +2 -0
- package/dist/manifest/validators/index.d.mts.map +1 -1
- package/dist/manifest/validators/index.mjs +2 -0
- package/dist/manifest/validators/index.mjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.cjs +47 -0
- package/dist/manifest/validators/production-platform-version.cjs.map +1 -0
- package/dist/manifest/validators/production-platform-version.d.cts +7 -0
- package/dist/manifest/validators/production-platform-version.d.cts.map +1 -0
- package/dist/manifest/validators/production-platform-version.d.mts +7 -0
- package/dist/manifest/validators/production-platform-version.d.mts.map +1 -0
- package/dist/manifest/validators/production-platform-version.mjs +44 -0
- package/dist/manifest/validators/production-platform-version.mjs.map +1 -0
- package/dist/manifest/validators/unused-exports.cjs +53 -0
- package/dist/manifest/validators/unused-exports.cjs.map +1 -0
- package/dist/manifest/validators/unused-exports.d.cts +7 -0
- package/dist/manifest/validators/unused-exports.d.cts.map +1 -0
- package/dist/manifest/validators/unused-exports.d.mts +7 -0
- package/dist/manifest/validators/unused-exports.d.mts.map +1 -0
- package/dist/manifest/validators/unused-exports.mjs +50 -0
- package/dist/manifest/validators/unused-exports.mjs.map +1 -0
- package/dist/time.cjs +15 -1
- package/dist/time.cjs.map +1 -1
- package/dist/time.d.cts +7 -0
- package/dist/time.d.cts.map +1 -1
- package/dist/time.d.mts +7 -0
- package/dist/time.d.mts.map +1 -1
- package/dist/time.mjs +13 -0
- package/dist/time.mjs.map +1 -1
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.mjs","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,4BAA4B;AAEtD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AACxD,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AACpC,OAAO,SAAS,aAAa;AAI7B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAoB;AAEtD,O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MAAM,CAAC,IAAI,CACtB,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAC5B,CAAC;IAE5B,MAAM,gBAAgB,GAAG,IAAI;SAC1B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;SAC/D,MAAM,CACL,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAChB,GAAG,MAAM;QACT,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC;KACrB,CAAC,EACF,EAAE,CACH,CAAC;IAEJ,OAAO,gBAAgC,CAAC;AAC1C,CAAC","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isPlainObject } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport type { SnapManifest } from './validation';\nimport type { ValidatorResults } from './validator';\nimport { hasFixes, runValidators } from './validator';\nimport type { ValidatorMeta, ValidatorReport } from './validator-types';\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { parseJson } from '../json';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file/node';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n platformVersion: 9,\n manifestVersion: 10,\n};\n\nexport type CheckManifestReport = Omit<ValidatorReport, 'fix'> & {\n wasFixed?: boolean;\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was written and updated.\n */\nexport type CheckManifestResult = {\n files?: SnapFiles;\n updated: boolean;\n reports: CheckManifestReport[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param options - Additional options for the function.\n * @param options.sourceCode - The source code of the Snap.\n * @param options.writeFileFn - The function to use to write the manifest to disk.\n * @param options.updateAndWriteManifest - Whether to auto-magically try to fix errors and then write the manifest to disk.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n {\n updateAndWriteManifest = true,\n sourceCode,\n writeFileFn = fs.writeFile,\n }: {\n updateAndWriteManifest?: boolean;\n sourceCode?: string;\n writeFileFn?: WriteFileFunction;\n } = {},\n): Promise<CheckManifestResult> {\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n const localizationFiles =\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [];\n for (const localization of localizationFiles) {\n try {\n localization.result = parseJson(localization.toString());\n } catch (error) {\n assert(error instanceof SyntaxError, error);\n throw new Error(\n `Failed to parse localization file \"${localization.path}\" as JSON.`,\n );\n }\n }\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles,\n };\n\n const validatorResults = await runValidators(snapFiles);\n let manifestResults: CheckManifestResult = {\n updated: false,\n files: validatorResults.files,\n reports: validatorResults.reports,\n };\n\n if (updateAndWriteManifest && hasFixes(manifestResults)) {\n const fixedResults = await runFixes(validatorResults);\n\n if (fixedResults.updated) {\n manifestResults = fixedResults;\n\n assert(manifestResults.files);\n\n try {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n manifestResults.files.manifest.toString(),\n );\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(\n `Failed to update \"snap.manifest.json\": ${getErrorMessage(error)}`,\n );\n }\n }\n }\n\n return manifestResults;\n}\n\n/**\n * Run the algorithm for automatically fixing errors in manifest.\n *\n * The algorithm updates the manifest by fixing all fixable problems,\n * and then run validation again to check if the new manifest is now correct.\n * If not correct, the algorithm will use the manifest from previous iteration\n * and try again `MAX_ATTEMPTS` times to update it before bailing and\n * resulting in failure.\n *\n * @param results - Results of the initial run of validation.\n * @param rules - Optional list of rules to run the fixes with.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n): Promise<CheckManifestResult> {\n let shouldRunFixes = true;\n const MAX_ATTEMPTS = 10;\n\n assert(results.files);\n\n let fixResults: ValidatorResults = results;\n assert(fixResults.files);\n fixResults.files.manifest = fixResults.files.manifest.clone();\n\n for (\n let attempts = 1;\n shouldRunFixes && attempts <= MAX_ATTEMPTS;\n attempts++\n ) {\n assert(fixResults.files);\n\n let manifest = fixResults.files.manifest.result;\n\n const fixable = fixResults.reports.filter((report) => report.fix);\n for (const report of fixable) {\n assert(report.fix);\n ({ manifest } = await report.fix({ manifest }));\n }\n\n fixResults.files.manifest.value = `${JSON.stringify(\n getWritableManifest(manifest),\n null,\n 2,\n )}\\n`;\n fixResults.files.manifest.result = manifest;\n\n fixResults = await runValidators(fixResults.files, rules);\n shouldRunFixes = hasFixes(fixResults);\n }\n\n const initialReports: (CheckManifestReport & ValidatorReport)[] = deepClone(\n results.reports,\n );\n\n // Was fixed\n if (!shouldRunFixes) {\n for (const report of initialReports) {\n if (report.fix) {\n report.wasFixed = true;\n delete report.fix;\n }\n }\n\n return {\n files: fixResults.files,\n updated: true,\n reports: initialReports,\n };\n }\n\n for (const report of initialReports) {\n delete report.fix;\n }\n\n return {\n files: results.files,\n updated: false,\n reports: initialReports,\n };\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"manifest.mjs","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,4BAA4B;AAEtD,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AACxD,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AACpC,OAAO,SAAS,aAAa;AAI7B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAoB;AAEtD,OAAO,KAAK,iBAAiB,+BAAqB;AAClD,OAAO,EAAE,SAAS,EAAE,0BAAsB;AAC1C,OAAO,EAAE,YAAY,EAAE,kBAAc;AACrC,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAEpC,OAAO,EAAE,gBAAgB,EAAE,qBAAiB;AAC5C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,iCAA6B;AAEpE,MAAM,mBAAmB,GAAuC;IAC9D,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;IACf,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC;IACT,kBAAkB,EAAE,CAAC;IACrB,kBAAkB,EAAE,CAAC;IACrB,eAAe,EAAE,CAAC;IAClB,eAAe,EAAE,EAAE;CACpB,CAAC;AAsDF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAgB,EAChB,EACE,sBAAsB,GAAG,IAAI,EAC7B,UAAU,EACV,WAAW,GAAG,EAAE,CAAC,SAAS,EAC1B,OAAO,EACP,iBAAiB,MACO,EAAE;IAE5B,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACzE,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,CAAC;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ED,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAC3B,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAC9D,CACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,8BAA8B,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC;IAE9C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAC5B,CAAC;IAE5B,MAAM,gBAAgB,GAAG,IAAI;SAC1B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;SAC/D,MAAM,CACL,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAChB,GAAG,MAAM;QACT,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC;KACrB,CAAC,EACF,EAAE,CACH,CAAC;IAEJ,OAAO,gBAAgC,CAAC;AAC1C,CAAC","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isPlainObject } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport type { SnapManifest } from './validation';\nimport type { ValidatorResults } from './validator';\nimport { hasFixes, runValidators } from './validator';\nimport type { ValidatorMeta, ValidatorReport } from './validator-types';\nimport * as defaultValidators from './validators';\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { parseJson } from '../json';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file/node';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n platformVersion: 9,\n manifestVersion: 10,\n};\n\nexport type CheckManifestReport = Omit<ValidatorReport, 'fix'> & {\n wasFixed?: boolean;\n};\n\n/**\n * The options for the `checkManifest` function.\n */\nexport type CheckManifestOptions = {\n /**\n * Whether to auto-magically try to fix errors and then write the manifest to\n * disk.\n */\n updateAndWriteManifest?: boolean;\n\n /**\n * The source code of the Snap.\n */\n sourceCode?: string;\n\n /**\n * The function to use to write the manifest to disk.\n */\n writeFileFn?: WriteFileFunction;\n\n /**\n * The exports detected by evaluating the bundle. This may be used by one or\n * more validators to determine whether the Snap is valid.\n */\n exports?: string[];\n\n /**\n * An object containing the names of the handlers and their respective\n * permission name. This must be provided to avoid circular dependencies\n * between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.\n */\n handlerEndowments?: Record<string, string | null>;\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was written and updated.\n */\nexport type CheckManifestResult = {\n files?: SnapFiles;\n updated: boolean;\n reports: CheckManifestReport[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param options - Additional options for the function.\n * @param options.sourceCode - The source code of the Snap.\n * @param options.writeFileFn - The function to use to write the manifest to\n * disk.\n * @param options.updateAndWriteManifest - Whether to auto-magically try to fix\n * errors and then write the manifest to disk.\n * @param options.exports - The exports detected by evaluating the bundle. This\n * may be used by one or more validators to determine whether the Snap is valid.\n * @param options.handlerEndowments - An object containing the names of the\n * handlers and their respective permission name. This must be provided to avoid\n * circular dependencies between `@metamask/snaps-utils` and\n * `@metamask/snaps-rpc-methods`.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n {\n updateAndWriteManifest = true,\n sourceCode,\n writeFileFn = fs.writeFile,\n exports,\n handlerEndowments,\n }: CheckManifestOptions = {},\n): Promise<CheckManifestResult> {\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n const localizationFiles =\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [];\n for (const localization of localizationFiles) {\n try {\n localization.result = parseJson(localization.toString());\n } catch (error) {\n assert(error instanceof SyntaxError, error);\n throw new Error(\n `Failed to parse localization file \"${localization.path}\" as JSON.`,\n );\n }\n }\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles,\n };\n\n const validatorResults = await runValidators(\n snapFiles,\n Object.values(defaultValidators),\n { exports, handlerEndowments },\n );\n\n let manifestResults: CheckManifestResult = {\n updated: false,\n files: validatorResults.files,\n reports: validatorResults.reports,\n };\n\n if (updateAndWriteManifest && hasFixes(manifestResults)) {\n const fixedResults = await runFixes(validatorResults);\n\n if (fixedResults.updated) {\n manifestResults = fixedResults;\n\n assert(manifestResults.files);\n\n try {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n manifestResults.files.manifest.toString(),\n );\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(\n `Failed to update \"snap.manifest.json\": ${getErrorMessage(error)}`,\n );\n }\n }\n }\n\n return manifestResults;\n}\n\n/**\n * Run the algorithm for automatically fixing errors in manifest.\n *\n * The algorithm updates the manifest by fixing all fixable problems,\n * and then run validation again to check if the new manifest is now correct.\n * If not correct, the algorithm will use the manifest from previous iteration\n * and try again `MAX_ATTEMPTS` times to update it before bailing and\n * resulting in failure.\n *\n * @param results - Results of the initial run of validation.\n * @param rules - Optional list of rules to run the fixes with.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n): Promise<CheckManifestResult> {\n let shouldRunFixes = true;\n const MAX_ATTEMPTS = 10;\n\n assert(results.files);\n\n let fixResults: ValidatorResults = results;\n assert(fixResults.files);\n fixResults.files.manifest = fixResults.files.manifest.clone();\n\n for (\n let attempts = 1;\n shouldRunFixes && attempts <= MAX_ATTEMPTS;\n attempts++\n ) {\n assert(fixResults.files);\n\n let manifest = fixResults.files.manifest.result;\n\n const fixable = fixResults.reports.filter((report) => report.fix);\n for (const report of fixable) {\n assert(report.fix);\n ({ manifest } = await report.fix({ manifest }));\n }\n\n fixResults.files.manifest.value = `${JSON.stringify(\n getWritableManifest(manifest),\n null,\n 2,\n )}\\n`;\n fixResults.files.manifest.result = manifest;\n\n fixResults = await runValidators(fixResults.files, rules);\n shouldRunFixes = hasFixes(fixResults);\n }\n\n const initialReports: (CheckManifestReport & ValidatorReport)[] = deepClone(\n results.reports,\n );\n\n // Was fixed\n if (!shouldRunFixes) {\n for (const report of initialReports) {\n if (report.fix) {\n report.wasFixed = true;\n delete report.fix;\n }\n }\n\n return {\n files: fixResults.files,\n updated: true,\n reports: initialReports,\n };\n }\n\n for (const report of initialReports) {\n delete report.fix;\n }\n\n return {\n files: results.files,\n updated: false,\n reports: initialReports,\n };\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-types.cjs","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SnapManifest } from './validation';\nimport type { Promisable } from '../promise';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\
|
|
1
|
+
{"version":3,"file":"validator-types.cjs","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SnapManifest } from './validation';\nimport type { Promisable } from '../promise';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorFix = (files: {\n manifest: SnapManifest;\n}) => Promisable<{ manifest: SnapManifest }>;\n\n/**\n * The options for the validator context.\n */\nexport type ValidatorContextOptions = {\n /**\n * An object containing the names of the handlers and their respective\n * permission name. This must be provided to avoid circular dependencies\n * between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.\n */\n handlerEndowments?: Record<string, string | null>;\n\n /**\n * Exports detected by evaluating the bundle. This may be used by one or more\n * validators to determine whether the snap is valid.\n */\n exports?: string[];\n};\n\nexport type ValidatorSeverity = 'error' | 'warning';\n\nexport type ValidatorContext = {\n readonly report: (message: string, fix?: ValidatorFix) => void;\n readonly options?: ValidatorContextOptions;\n};\n\nexport type ValidatorReport = {\n severity: ValidatorSeverity;\n message: string;\n fix?: ValidatorFix;\n};\n\nexport type ValidatorMeta = {\n severity: ValidatorSeverity;\n\n /**\n * 1. Run the validator on unverified files to ensure that the files are structurally sound.\n *\n * @param files - Files to be verified\n * @param context - Validator context to report errors\n */\n structureCheck?: (\n files: UnvalidatedSnapFiles,\n context: ValidatorContext,\n ) => void | Promise<void>;\n\n /**\n * 2. Run the validator after the files were checked to be structurally sound.\n *\n * @param files - Files to be verified\n * @param context - Validator context to report errors\n */\n semanticCheck?: (\n files: SnapFiles,\n context: ValidatorContext,\n ) => void | Promise<void>;\n};\n"]}
|
|
@@ -6,9 +6,26 @@ export type ValidatorFix = (files: {
|
|
|
6
6
|
}) => Promisable<{
|
|
7
7
|
manifest: SnapManifest;
|
|
8
8
|
}>;
|
|
9
|
+
/**
|
|
10
|
+
* The options for the validator context.
|
|
11
|
+
*/
|
|
12
|
+
export type ValidatorContextOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* An object containing the names of the handlers and their respective
|
|
15
|
+
* permission name. This must be provided to avoid circular dependencies
|
|
16
|
+
* between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.
|
|
17
|
+
*/
|
|
18
|
+
handlerEndowments?: Record<string, string | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Exports detected by evaluating the bundle. This may be used by one or more
|
|
21
|
+
* validators to determine whether the snap is valid.
|
|
22
|
+
*/
|
|
23
|
+
exports?: string[];
|
|
24
|
+
};
|
|
9
25
|
export type ValidatorSeverity = 'error' | 'warning';
|
|
10
26
|
export type ValidatorContext = {
|
|
11
|
-
report: (message: string, fix?: ValidatorFix) => void;
|
|
27
|
+
readonly report: (message: string, fix?: ValidatorFix) => void;
|
|
28
|
+
readonly options?: ValidatorContextOptions;
|
|
12
29
|
};
|
|
13
30
|
export type ValidatorReport = {
|
|
14
31
|
severity: ValidatorSeverity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-types.d.cts","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAmB;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;
|
|
1
|
+
{"version":3,"file":"validator-types.d.cts","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAmB;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK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validator context.
|
|
11
|
+
*/
|
|
12
|
+
export type ValidatorContextOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* An object containing the names of the handlers and their respective
|
|
15
|
+
* permission name. This must be provided to avoid circular dependencies
|
|
16
|
+
* between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.
|
|
17
|
+
*/
|
|
18
|
+
handlerEndowments?: Record<string, string | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Exports detected by evaluating the bundle. This may be used by one or more
|
|
21
|
+
* validators to determine whether the snap is valid.
|
|
22
|
+
*/
|
|
23
|
+
exports?: string[];
|
|
24
|
+
};
|
|
9
25
|
export type ValidatorSeverity = 'error' | 'warning';
|
|
10
26
|
export type ValidatorContext = {
|
|
11
|
-
report: (message: string, fix?: ValidatorFix) => void;
|
|
27
|
+
readonly report: (message: string, fix?: ValidatorFix) => void;
|
|
28
|
+
readonly options?: ValidatorContextOptions;
|
|
12
29
|
};
|
|
13
30
|
export type ValidatorReport = {
|
|
14
31
|
severity: ValidatorSeverity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-types.d.mts","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAmB;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;
|
|
1
|
+
{"version":3,"file":"validator-types.d.mts","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAmB;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE;IACjC,QAAQ,EAAE,YAAY,CAAC;CACxB,KAAK,UAAU,CAAC;IAAE,QAAQ,EAAE,YAAY,CAAA;CAAE,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IAElD;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,CAAC;AAEpD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,uBAAuB,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,iBAAiB,CAAC;IAE5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CACf,KAAK,EAAE,oBAAoB,EAC3B,OAAO,EAAE,gBAAgB,KACtB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,CACd,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,gBAAgB,KACtB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator-types.mjs","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SnapManifest } from './validation';\nimport type { Promisable } from '../promise';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\
|
|
1
|
+
{"version":3,"file":"validator-types.mjs","sourceRoot":"","sources":["../../src/manifest/validator-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SnapManifest } from './validation';\nimport type { Promisable } from '../promise';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorFix = (files: {\n manifest: SnapManifest;\n}) => Promisable<{ manifest: SnapManifest }>;\n\n/**\n * The options for the validator context.\n */\nexport type ValidatorContextOptions = {\n /**\n * An object containing the names of the handlers and their respective\n * permission name. This must be provided to avoid circular dependencies\n * between `@metamask/snaps-utils` and `@metamask/snaps-rpc-methods`.\n */\n handlerEndowments?: Record<string, string | null>;\n\n /**\n * Exports detected by evaluating the bundle. This may be used by one or more\n * validators to determine whether the snap is valid.\n */\n exports?: string[];\n};\n\nexport type ValidatorSeverity = 'error' | 'warning';\n\nexport type ValidatorContext = {\n readonly report: (message: string, fix?: ValidatorFix) => void;\n readonly options?: ValidatorContextOptions;\n};\n\nexport type ValidatorReport = {\n severity: ValidatorSeverity;\n message: string;\n fix?: ValidatorFix;\n};\n\nexport type ValidatorMeta = {\n severity: ValidatorSeverity;\n\n /**\n * 1. Run the validator on unverified files to ensure that the files are structurally sound.\n *\n * @param files - Files to be verified\n * @param context - Validator context to report errors\n */\n structureCheck?: (\n files: UnvalidatedSnapFiles,\n context: ValidatorContext,\n ) => void | Promise<void>;\n\n /**\n * 2. Run the validator after the files were checked to be structurally sound.\n *\n * @param files - Files to be verified\n * @param context - Validator context to report errors\n */\n semanticCheck?: (\n files: SnapFiles,\n context: ValidatorContext,\n ) => void | Promise<void>;\n};\n"]}
|
|
@@ -22,26 +22,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
-
};
|
|
30
25
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
31
26
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
32
27
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
33
28
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
34
29
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
35
30
|
};
|
|
36
|
-
var
|
|
31
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
32
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
33
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
34
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
|
+
};
|
|
36
|
+
var _Context_options, _Context_nextSeverity;
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.hasFixes = exports.runValidators = void 0;
|
|
39
39
|
const utils_1 = require("@metamask/utils");
|
|
40
40
|
const defaultValidators = __importStar(require("./validators/index.cjs"));
|
|
41
41
|
class Context {
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Construct a new validator context.
|
|
44
|
+
*
|
|
45
|
+
* @param options - The options for the validator context.
|
|
46
|
+
* @param options.exports - Exports detected by evaluating the bundle.
|
|
47
|
+
*/
|
|
48
|
+
constructor(options) {
|
|
43
49
|
this.reports = [];
|
|
50
|
+
_Context_options.set(this, {});
|
|
44
51
|
_Context_nextSeverity.set(this, undefined);
|
|
52
|
+
__classPrivateFieldSet(this, _Context_options, options, "f");
|
|
45
53
|
}
|
|
46
54
|
report(message, fix) {
|
|
47
55
|
(0, utils_1.assert)(__classPrivateFieldGet(this, _Context_nextSeverity, "f") !== undefined);
|
|
@@ -57,8 +65,11 @@ class Context {
|
|
|
57
65
|
get hasErrors() {
|
|
58
66
|
return this.reports.some((report) => report.severity === 'error');
|
|
59
67
|
}
|
|
68
|
+
get options() {
|
|
69
|
+
return __classPrivateFieldGet(this, _Context_options, "f");
|
|
70
|
+
}
|
|
60
71
|
}
|
|
61
|
-
_Context_nextSeverity = new WeakMap();
|
|
72
|
+
_Context_options = new WeakMap(), _Context_nextSeverity = new WeakMap();
|
|
62
73
|
/**
|
|
63
74
|
* Verify that snap files are completely valid.
|
|
64
75
|
* First it runs validators on unparsed files to check structure.
|
|
@@ -66,13 +77,15 @@ _Context_nextSeverity = new WeakMap();
|
|
|
66
77
|
*
|
|
67
78
|
* @param files - All files required to run a snap.
|
|
68
79
|
* @param rules - Validators to run.
|
|
80
|
+
* @param options - Options for the validation.
|
|
81
|
+
* @param options.exports - Exports detected by evaluating the bundle.
|
|
69
82
|
* @returns The validation results.
|
|
70
83
|
*/
|
|
71
84
|
// TODO(ritave): snap.manifest.json and package.json should check
|
|
72
85
|
// json parsing as well instead of assuming it's
|
|
73
86
|
// already parsed
|
|
74
|
-
async function runValidators(files, rules = Object.values(defaultValidators)) {
|
|
75
|
-
const context = new Context();
|
|
87
|
+
async function runValidators(files, rules = Object.values(defaultValidators), options = {}) {
|
|
88
|
+
const context = new Context(options);
|
|
76
89
|
for (const rule of rules) {
|
|
77
90
|
context.prepareForValidator({
|
|
78
91
|
severity: rule.severity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.cjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;
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YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AA/BD,sCA+BC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAFD,4BAEC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorContextOptions,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n readonly #options: ValidatorContextOptions = {};\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n /**\n * Construct a new validator context.\n *\n * @param options - The options for the validator context.\n * @param options.exports - Exports detected by evaluating the bundle.\n */\n constructor(options: ValidatorContextOptions) {\n this.#options = options;\n }\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n\n get options() {\n return this.#options;\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @param options - Options for the validation.\n * @param options.exports - Exports detected by evaluating the bundle.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n options: ValidatorContextOptions = {},\n): Promise<ValidatorResults> {\n const context = new Context(options);\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ValidatorMeta, ValidatorReport } from "./validator-types.cjs";
|
|
1
|
+
import type { ValidatorContextOptions, ValidatorMeta, ValidatorReport } from "./validator-types.cjs";
|
|
2
2
|
import type { SnapFiles, UnvalidatedSnapFiles } from "../types.cjs";
|
|
3
3
|
export type ValidatorResults = {
|
|
4
4
|
files?: SnapFiles;
|
|
@@ -11,9 +11,11 @@ export type ValidatorResults = {
|
|
|
11
11
|
*
|
|
12
12
|
* @param files - All files required to run a snap.
|
|
13
13
|
* @param rules - Validators to run.
|
|
14
|
+
* @param options - Options for the validation.
|
|
15
|
+
* @param options.exports - Exports detected by evaluating the bundle.
|
|
14
16
|
* @returns The validation results.
|
|
15
17
|
*/
|
|
16
|
-
export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[]): Promise<ValidatorResults>;
|
|
18
|
+
export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[], options?: ValidatorContextOptions): Promise<ValidatorResults>;
|
|
17
19
|
/**
|
|
18
20
|
* Get whether any reports has pending fixes.
|
|
19
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.cts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"validator.d.cts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,uBAAuB,EAEvB,aAAa,EACb,eAAe,EAEhB,8BAA0B;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAyCF;;;;;;;;;;GAUG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,EACzD,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC,CA2B3B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAE3D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ValidatorMeta, ValidatorReport } from "./validator-types.mjs";
|
|
1
|
+
import type { ValidatorContextOptions, ValidatorMeta, ValidatorReport } from "./validator-types.mjs";
|
|
2
2
|
import type { SnapFiles, UnvalidatedSnapFiles } from "../types.mjs";
|
|
3
3
|
export type ValidatorResults = {
|
|
4
4
|
files?: SnapFiles;
|
|
@@ -11,9 +11,11 @@ export type ValidatorResults = {
|
|
|
11
11
|
*
|
|
12
12
|
* @param files - All files required to run a snap.
|
|
13
13
|
* @param rules - Validators to run.
|
|
14
|
+
* @param options - Options for the validation.
|
|
15
|
+
* @param options.exports - Exports detected by evaluating the bundle.
|
|
14
16
|
* @returns The validation results.
|
|
15
17
|
*/
|
|
16
|
-
export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[]): Promise<ValidatorResults>;
|
|
18
|
+
export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[], options?: ValidatorContextOptions): Promise<ValidatorResults>;
|
|
17
19
|
/**
|
|
18
20
|
* Get whether any reports has pending fixes.
|
|
19
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.mts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"validator.d.mts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,uBAAuB,EAEvB,aAAa,EACb,eAAe,EAEhB,8BAA0B;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAyCF;;;;;;;;;;GAUG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,EACzD,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC,CA2B3B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAE3D"}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
1
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
2
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
3
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
4
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
5
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
6
|
};
|
|
12
|
-
var
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _Context_options, _Context_nextSeverity;
|
|
13
13
|
import { assert } from "@metamask/utils";
|
|
14
14
|
import * as defaultValidators from "./validators/index.mjs";
|
|
15
15
|
class Context {
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Construct a new validator context.
|
|
18
|
+
*
|
|
19
|
+
* @param options - The options for the validator context.
|
|
20
|
+
* @param options.exports - Exports detected by evaluating the bundle.
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
17
23
|
this.reports = [];
|
|
24
|
+
_Context_options.set(this, {});
|
|
18
25
|
_Context_nextSeverity.set(this, undefined);
|
|
26
|
+
__classPrivateFieldSet(this, _Context_options, options, "f");
|
|
19
27
|
}
|
|
20
28
|
report(message, fix) {
|
|
21
29
|
assert(__classPrivateFieldGet(this, _Context_nextSeverity, "f") !== undefined);
|
|
@@ -31,8 +39,11 @@ class Context {
|
|
|
31
39
|
get hasErrors() {
|
|
32
40
|
return this.reports.some((report) => report.severity === 'error');
|
|
33
41
|
}
|
|
42
|
+
get options() {
|
|
43
|
+
return __classPrivateFieldGet(this, _Context_options, "f");
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
|
-
_Context_nextSeverity = new WeakMap();
|
|
46
|
+
_Context_options = new WeakMap(), _Context_nextSeverity = new WeakMap();
|
|
36
47
|
/**
|
|
37
48
|
* Verify that snap files are completely valid.
|
|
38
49
|
* First it runs validators on unparsed files to check structure.
|
|
@@ -40,13 +51,15 @@ _Context_nextSeverity = new WeakMap();
|
|
|
40
51
|
*
|
|
41
52
|
* @param files - All files required to run a snap.
|
|
42
53
|
* @param rules - Validators to run.
|
|
54
|
+
* @param options - Options for the validation.
|
|
55
|
+
* @param options.exports - Exports detected by evaluating the bundle.
|
|
43
56
|
* @returns The validation results.
|
|
44
57
|
*/
|
|
45
58
|
// TODO(ritave): snap.manifest.json and package.json should check
|
|
46
59
|
// json parsing as well instead of assuming it's
|
|
47
60
|
// already parsed
|
|
48
|
-
export async function runValidators(files, rules = Object.values(defaultValidators)) {
|
|
49
|
-
const context = new Context();
|
|
61
|
+
export async function runValidators(files, rules = Object.values(defaultValidators), options = {}) {
|
|
62
|
+
const context = new Context(options);
|
|
50
63
|
for (const rule of rules) {
|
|
51
64
|
context.prepareForValidator({
|
|
52
65
|
severity: rule.severity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.mjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"validator.mjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAUzC,OAAO,KAAK,iBAAiB,+BAAqB;AAQlD,MAAM,OAAO;IAOX;;;;;OAKG;IACH,YAAY,OAAgC;QAZ5C,YAAO,GAAsB,EAAE,CAAC;QAEvB,2BAAoC,EAAE,EAAC;QAEhD,gCAAoC,SAAS,EAAC;QAS5C,uBAAA,IAAI,oBAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,OAAe,EAAE,GAAkB;QACxC,MAAM,CAAC,uBAAA,IAAI,6BAAc,KAAK,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,uBAAA,IAAI,6BAAc;YAC5B,OAAO;YACP,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,QAAyC;QAC3D,uBAAA,IAAI,yBAAiB,QAAQ,CAAC,QAAQ,MAAA,CAAC;IACzC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO;QACT,OAAO,uBAAA,IAAI,wBAAS,CAAC;IACvB,CAAC;CACF;;AAED;;;;;;;;;;GAUG;AACH,iEAAiE;AACjE,8DAA8D;AAC9D,+BAA+B;AAC/B,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAA2B,EAC3B,QAAyB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EACzD,UAAmC,EAAE;IAErC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorContextOptions,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n readonly #options: ValidatorContextOptions = {};\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n /**\n * Construct a new validator context.\n *\n * @param options - The options for the validator context.\n * @param options.exports - Exports detected by evaluating the bundle.\n */\n constructor(options: ValidatorContextOptions) {\n this.#options = options;\n }\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n\n get options() {\n return this.#options;\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @param options - Options for the validation.\n * @param options.exports - Exports detected by evaluating the bundle.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n options: ValidatorContextOptions = {},\n): Promise<ValidatorResults> {\n const context = new Context(options);\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
|
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./checksum.cjs"), exports);
|
|
18
18
|
__exportStar(require("./expected-files.cjs"), exports);
|
|
19
|
+
__exportStar(require("./unused-exports.cjs"), exports);
|
|
19
20
|
__exportStar(require("./icon-dimensions.cjs"), exports);
|
|
20
21
|
__exportStar(require("./is-localization-file.cjs"), exports);
|
|
21
22
|
__exportStar(require("./is-package-json.cjs"), exports);
|
|
@@ -25,6 +26,7 @@ __exportStar(require("./manifest-localization.cjs"), exports);
|
|
|
25
26
|
__exportStar(require("./package-json-recommended-fields.cjs"), exports);
|
|
26
27
|
__exportStar(require("./package-name-match.cjs"), exports);
|
|
27
28
|
__exportStar(require("./platform-version.cjs"), exports);
|
|
29
|
+
__exportStar(require("./production-platform-version.cjs"), exports);
|
|
28
30
|
__exportStar(require("./repository-match.cjs"), exports);
|
|
29
31
|
__exportStar(require("./version-match.cjs"), exports);
|
|
30
32
|
__exportStar(require("./icon-declared.cjs"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B,uDAAiC;AACjC,wDAAkC;AAClC,6DAAuC;AACvC,wDAAkC;AAClC,qDAA+B;AAC/B,yDAAmC;AACnC,8DAAwC;AACxC,wEAAkD;AAClD,2DAAqC;AACrC,yDAAmC;AACnC,yDAAmC;AACnC,sDAAgC;AAChC,sDAAgC;AAChC,qDAA+B","sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './icon-dimensions';\nexport * from './is-localization-file';\nexport * from './is-package-json';\nexport * from './is-snap-icon';\nexport * from './is-snap-manifest';\nexport * from './manifest-localization';\nexport * from './package-json-recommended-fields';\nexport * from './package-name-match';\nexport * from './platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B,uDAAiC;AACjC,uDAAiC;AACjC,wDAAkC;AAClC,6DAAuC;AACvC,wDAAkC;AAClC,qDAA+B;AAC/B,yDAAmC;AACnC,8DAAwC;AACxC,wEAAkD;AAClD,2DAAqC;AACrC,yDAAmC;AACnC,oEAA8C;AAC9C,yDAAmC;AACnC,sDAAgC;AAChC,sDAAgC;AAChC,qDAA+B","sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './unused-exports';\nexport * from './icon-dimensions';\nexport * from './is-localization-file';\nexport * from './is-package-json';\nexport * from './is-snap-icon';\nexport * from './is-snap-manifest';\nexport * from './manifest-localization';\nexport * from './package-json-recommended-fields';\nexport * from './package-name-match';\nexport * from './platform-version';\nexport * from './production-platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./checksum.cjs";
|
|
2
2
|
export * from "./expected-files.cjs";
|
|
3
|
+
export * from "./unused-exports.cjs";
|
|
3
4
|
export * from "./icon-dimensions.cjs";
|
|
4
5
|
export * from "./is-localization-file.cjs";
|
|
5
6
|
export * from "./is-package-json.cjs";
|
|
@@ -9,6 +10,7 @@ export * from "./manifest-localization.cjs";
|
|
|
9
10
|
export * from "./package-json-recommended-fields.cjs";
|
|
10
11
|
export * from "./package-name-match.cjs";
|
|
11
12
|
export * from "./platform-version.cjs";
|
|
13
|
+
export * from "./production-platform-version.cjs";
|
|
12
14
|
export * from "./repository-match.cjs";
|
|
13
15
|
export * from "./version-match.cjs";
|
|
14
16
|
export * from "./icon-declared.cjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,kDAA8C;AAC9C,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./checksum.mjs";
|
|
2
2
|
export * from "./expected-files.mjs";
|
|
3
|
+
export * from "./unused-exports.mjs";
|
|
3
4
|
export * from "./icon-dimensions.mjs";
|
|
4
5
|
export * from "./is-localization-file.mjs";
|
|
5
6
|
export * from "./is-package-json.mjs";
|
|
@@ -9,6 +10,7 @@ export * from "./manifest-localization.mjs";
|
|
|
9
10
|
export * from "./package-json-recommended-fields.mjs";
|
|
10
11
|
export * from "./package-name-match.mjs";
|
|
11
12
|
export * from "./platform-version.mjs";
|
|
13
|
+
export * from "./production-platform-version.mjs";
|
|
12
14
|
export * from "./repository-match.mjs";
|
|
13
15
|
export * from "./version-match.mjs";
|
|
14
16
|
export * from "./icon-declared.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,kDAA8C;AAC9C,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./checksum.mjs";
|
|
2
2
|
export * from "./expected-files.mjs";
|
|
3
|
+
export * from "./unused-exports.mjs";
|
|
3
4
|
export * from "./icon-dimensions.mjs";
|
|
4
5
|
export * from "./is-localization-file.mjs";
|
|
5
6
|
export * from "./is-package-json.mjs";
|
|
@@ -9,6 +10,7 @@ export * from "./manifest-localization.mjs";
|
|
|
9
10
|
export * from "./package-json-recommended-fields.mjs";
|
|
10
11
|
export * from "./package-name-match.mjs";
|
|
11
12
|
export * from "./platform-version.mjs";
|
|
13
|
+
export * from "./production-platform-version.mjs";
|
|
12
14
|
export * from "./repository-match.mjs";
|
|
13
15
|
export * from "./version-match.mjs";
|
|
14
16
|
export * from "./icon-declared.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B","sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './icon-dimensions';\nexport * from './is-localization-file';\nexport * from './is-package-json';\nexport * from './is-snap-icon';\nexport * from './is-snap-manifest';\nexport * from './manifest-localization';\nexport * from './package-json-recommended-fields';\nexport * from './package-name-match';\nexport * from './platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,kDAA8C;AAC9C,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B","sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './unused-exports';\nexport * from './icon-dimensions';\nexport * from './is-localization-file';\nexport * from './is-package-json';\nexport * from './is-snap-icon';\nexport * from './is-snap-manifest';\nexport * from './manifest-localization';\nexport * from './package-json-recommended-fields';\nexport * from './package-name-match';\nexport * from './platform-version';\nexport * from './production-platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.productionPlatformVersion = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const semver_1 = require("semver");
|
|
6
|
+
const fs_1 = require("../../fs.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Determine the production version of the Snaps platform by inspecting
|
|
9
|
+
* the latest GitHub release of the MetaMask extension.
|
|
10
|
+
*
|
|
11
|
+
* @returns The production version of the Snaps platform or null if any error occurred.
|
|
12
|
+
*/
|
|
13
|
+
const determineProductionVersion = (0, fs_1.useFileSystemCache)('snaps-production-version', (0, utils_1.inMilliseconds)(3, utils_1.Duration.Day), async () => {
|
|
14
|
+
try {
|
|
15
|
+
const latestRelease = await fetch('https://api.github.com/repos/metamask/metamask-extension/releases/latest');
|
|
16
|
+
const latestReleaseJson = await latestRelease.json();
|
|
17
|
+
const latestReleaseCommit = latestReleaseJson.target_commitish;
|
|
18
|
+
const packageJsonResponse = await fetch(`https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`, { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) });
|
|
19
|
+
const packageJson = await packageJsonResponse.json();
|
|
20
|
+
const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];
|
|
21
|
+
return (0, semver_1.minVersion)(versionRange)?.format();
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Check if the platform version in manifest exceeds the version
|
|
29
|
+
* used in production.
|
|
30
|
+
*/
|
|
31
|
+
exports.productionPlatformVersion = {
|
|
32
|
+
severity: 'warning',
|
|
33
|
+
async semanticCheck(files, context) {
|
|
34
|
+
const manifestPlatformVersion = files.manifest.result.platformVersion;
|
|
35
|
+
if (!manifestPlatformVersion) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const maximumVersion = await determineProductionVersion();
|
|
39
|
+
if (!maximumVersion) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if ((0, semver_1.gt)(manifestPlatformVersion, maximumVersion)) {
|
|
43
|
+
context.report(`The specified platform version "${manifestPlatformVersion}" is not supported in the production version of MetaMask. The current maximum supported version is "${maximumVersion}". To resolve this, downgrade \`@metamask/snaps-sdk\` to a compatible version.`);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=production-platform-version.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production-platform-version.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAC3D,mCAAwC;AAExC,qCAA8C;AAG9C;;;;;GAKG;AACH,MAAM,0BAA0B,GAAG,IAAA,uBAAkB,EACnD,0BAA0B,EAC1B,IAAA,sBAAc,EAAC,CAAC,EAAE,gBAAQ,CAAC,GAAG,CAAC,EAC/B,KAAK,IAAI,EAAE;IACT,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,KAAK,CAC/B,0EAA0E,CAC3E,CAAC;QAEF,MAAM,iBAAiB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,gBAAgB,CAAC;QAE/D,MAAM,mBAAmB,GAAG,MAAM,KAAK,CACrC,sFAAsF,mBAAmB,EAAE,EAC3G,EAAE,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,iCAAiC,EAAE,CAAC,EAAE,CACxE,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;QAErE,OAAO,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC;AAEF;;;GAGG;AACU,QAAA,yBAAyB,GAAkB;IACtD,QAAQ,EAAE,SAAS;IACnB,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO;QAChC,MAAM,uBAAuB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC;QAEtE,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,0BAA0B,EAAE,CAAC;QAE1D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,IAAA,WAAE,EAAC,uBAAuB,EAAE,cAAc,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,MAAM,CACZ,mCAAmC,uBAAuB,uGAAuG,cAAc,gFAAgF,CAChQ,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import { Duration, inMilliseconds } from '@metamask/utils';\nimport { minVersion, gt } from 'semver';\n\nimport { useFileSystemCache } from '../../fs';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Determine the production version of the Snaps platform by inspecting\n * the latest GitHub release of the MetaMask extension.\n *\n * @returns The production version of the Snaps platform or null if any error occurred.\n */\nconst determineProductionVersion = useFileSystemCache(\n 'snaps-production-version',\n inMilliseconds(3, Duration.Day),\n async () => {\n try {\n const latestRelease = await fetch(\n 'https://api.github.com/repos/metamask/metamask-extension/releases/latest',\n );\n\n const latestReleaseJson = await latestRelease.json();\n\n const latestReleaseCommit = latestReleaseJson.target_commitish;\n\n const packageJsonResponse = await fetch(\n `https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`,\n { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) },\n );\n\n const packageJson = await packageJsonResponse.json();\n\n const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];\n\n return minVersion(versionRange)?.format();\n } catch {\n return null;\n }\n },\n);\n\n/**\n * Check if the platform version in manifest exceeds the version\n * used in production.\n */\nexport const productionPlatformVersion: ValidatorMeta = {\n severity: 'warning',\n async semanticCheck(files, context) {\n const manifestPlatformVersion = files.manifest.result.platformVersion;\n\n if (!manifestPlatformVersion) {\n return;\n }\n\n const maximumVersion = await determineProductionVersion();\n\n if (!maximumVersion) {\n return;\n }\n\n if (gt(manifestPlatformVersion, maximumVersion)) {\n context.report(\n `The specified platform version \"${manifestPlatformVersion}\" is not supported in the production version of MetaMask. The current maximum supported version is \"${maximumVersion}\". To resolve this, downgrade \\`@metamask/snaps-sdk\\` to a compatible version.`,\n );\n }\n },\n};\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ValidatorMeta } from "../validator-types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Check if the platform version in manifest exceeds the version
|
|
4
|
+
* used in production.
|
|
5
|
+
*/
|
|
6
|
+
export declare const productionPlatformVersion: ValidatorMeta;
|
|
7
|
+
//# sourceMappingURL=production-platform-version.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production-platform-version.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAqCxD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,aAqBvC,CAAC"}
|