@metamask/snaps-utils 11.4.0 → 11.5.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 +12 -1
- package/dist/base64.cjs +3 -2
- package/dist/base64.cjs.map +1 -1
- package/dist/base64.d.cts.map +1 -1
- package/dist/base64.d.mts.map +1 -1
- package/dist/base64.mjs +3 -2
- package/dist/base64.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +9 -5
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +9 -5
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +4 -2
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +4 -2
- package/dist/manifest/validator-types.d.mts.map +1 -1
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +11 -2
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs +11 -2
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/checksum.cjs +1 -1
- package/dist/manifest/validators/checksum.cjs.map +1 -1
- package/dist/manifest/validators/checksum.d.cts.map +1 -1
- package/dist/manifest/validators/checksum.d.mts.map +1 -1
- package/dist/manifest/validators/checksum.mjs +1 -1
- package/dist/manifest/validators/checksum.mjs.map +1 -1
- package/dist/manifest/validators/expected-files.cjs +1 -1
- package/dist/manifest/validators/expected-files.cjs.map +1 -1
- package/dist/manifest/validators/expected-files.d.cts.map +1 -1
- package/dist/manifest/validators/expected-files.d.mts.map +1 -1
- package/dist/manifest/validators/expected-files.mjs +1 -1
- package/dist/manifest/validators/expected-files.mjs.map +1 -1
- package/dist/manifest/validators/icon-declared.cjs +1 -1
- package/dist/manifest/validators/icon-declared.cjs.map +1 -1
- package/dist/manifest/validators/icon-declared.d.cts.map +1 -1
- package/dist/manifest/validators/icon-declared.d.mts.map +1 -1
- package/dist/manifest/validators/icon-declared.mjs +1 -1
- package/dist/manifest/validators/icon-declared.mjs.map +1 -1
- package/dist/manifest/validators/icon-dimensions.cjs +1 -1
- package/dist/manifest/validators/icon-dimensions.cjs.map +1 -1
- package/dist/manifest/validators/icon-dimensions.d.cts.map +1 -1
- package/dist/manifest/validators/icon-dimensions.d.mts.map +1 -1
- package/dist/manifest/validators/icon-dimensions.mjs +1 -1
- package/dist/manifest/validators/icon-dimensions.mjs.map +1 -1
- package/dist/manifest/validators/icon-missing.cjs +1 -1
- package/dist/manifest/validators/icon-missing.cjs.map +1 -1
- package/dist/manifest/validators/icon-missing.mjs +1 -1
- package/dist/manifest/validators/icon-missing.mjs.map +1 -1
- package/dist/manifest/validators/is-localization-file.cjs +1 -1
- package/dist/manifest/validators/is-localization-file.cjs.map +1 -1
- package/dist/manifest/validators/is-localization-file.d.cts.map +1 -1
- package/dist/manifest/validators/is-localization-file.d.mts.map +1 -1
- package/dist/manifest/validators/is-localization-file.mjs +1 -1
- package/dist/manifest/validators/is-localization-file.mjs.map +1 -1
- package/dist/manifest/validators/is-package-json.cjs +1 -1
- package/dist/manifest/validators/is-package-json.cjs.map +1 -1
- package/dist/manifest/validators/is-package-json.d.cts.map +1 -1
- package/dist/manifest/validators/is-package-json.d.mts.map +1 -1
- package/dist/manifest/validators/is-package-json.mjs +1 -1
- package/dist/manifest/validators/is-package-json.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-icon.cjs +1 -1
- package/dist/manifest/validators/is-snap-icon.cjs.map +1 -1
- package/dist/manifest/validators/is-snap-icon.mjs +1 -1
- package/dist/manifest/validators/is-snap-icon.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.d.cts.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.d.mts.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.mjs +1 -1
- package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.cjs +1 -1
- package/dist/manifest/validators/manifest-localization.cjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.d.cts.map +1 -1
- package/dist/manifest/validators/manifest-localization.d.mts.map +1 -1
- package/dist/manifest/validators/manifest-localization.mjs +1 -1
- package/dist/manifest/validators/manifest-localization.mjs.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.cjs +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.cjs.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.d.cts.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.d.mts.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.mjs +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.mjs.map +1 -1
- package/dist/manifest/validators/package-name-match.cjs +1 -1
- package/dist/manifest/validators/package-name-match.cjs.map +1 -1
- package/dist/manifest/validators/package-name-match.d.cts.map +1 -1
- package/dist/manifest/validators/package-name-match.d.mts.map +1 -1
- package/dist/manifest/validators/package-name-match.mjs +1 -1
- package/dist/manifest/validators/package-name-match.mjs.map +1 -1
- package/dist/manifest/validators/platform-version.cjs +2 -2
- package/dist/manifest/validators/platform-version.cjs.map +1 -1
- package/dist/manifest/validators/platform-version.d.cts.map +1 -1
- package/dist/manifest/validators/platform-version.d.mts.map +1 -1
- package/dist/manifest/validators/platform-version.mjs +2 -2
- package/dist/manifest/validators/platform-version.mjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.cjs +1 -1
- package/dist/manifest/validators/production-platform-version.cjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.d.cts.map +1 -1
- package/dist/manifest/validators/production-platform-version.d.mts.map +1 -1
- package/dist/manifest/validators/production-platform-version.mjs +1 -1
- package/dist/manifest/validators/production-platform-version.mjs.map +1 -1
- package/dist/manifest/validators/repository-match.cjs +1 -1
- package/dist/manifest/validators/repository-match.cjs.map +1 -1
- package/dist/manifest/validators/repository-match.d.cts.map +1 -1
- package/dist/manifest/validators/repository-match.d.mts.map +1 -1
- package/dist/manifest/validators/repository-match.mjs +1 -1
- package/dist/manifest/validators/repository-match.mjs.map +1 -1
- package/dist/manifest/validators/unused-exports.cjs +2 -2
- package/dist/manifest/validators/unused-exports.cjs.map +1 -1
- package/dist/manifest/validators/unused-exports.d.cts.map +1 -1
- package/dist/manifest/validators/unused-exports.d.mts.map +1 -1
- package/dist/manifest/validators/unused-exports.mjs +2 -2
- package/dist/manifest/validators/unused-exports.mjs.map +1 -1
- package/dist/manifest/validators/version-match.cjs +1 -1
- package/dist/manifest/validators/version-match.cjs.map +1 -1
- package/dist/manifest/validators/version-match.d.cts.map +1 -1
- package/dist/manifest/validators/version-match.d.mts.map +1 -1
- package/dist/manifest/validators/version-match.mjs +1 -1
- package/dist/manifest/validators/version-match.mjs.map +1 -1
- package/dist/platform-version.cjs.map +1 -1
- package/dist/platform-version.d.cts +2 -1
- package/dist/platform-version.d.cts.map +1 -1
- package/dist/platform-version.d.mts +2 -1
- package/dist/platform-version.d.mts.map +1 -1
- package/dist/platform-version.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [11.5.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Merge manifest validation reports to include latest validation errors and warnings ([#3567](https://github.com/MetaMask/snaps/pull/3567))
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Disable base64 optimization in React Native ([#3564](https://github.com/MetaMask/snaps/pull/3564))
|
|
19
|
+
|
|
10
20
|
## [11.4.0]
|
|
11
21
|
|
|
12
22
|
### Added
|
|
@@ -694,7 +704,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
694
704
|
- The version of the package no longer needs to match the version of all other
|
|
695
705
|
MetaMask Snaps packages.
|
|
696
706
|
|
|
697
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.
|
|
707
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.5.0...HEAD
|
|
708
|
+
[11.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.4.0...@metamask/snaps-utils@11.5.0
|
|
698
709
|
[11.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.3.0...@metamask/snaps-utils@11.4.0
|
|
699
710
|
[11.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.2.0...@metamask/snaps-utils@11.3.0
|
|
700
711
|
[11.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@11.1.0...@metamask/snaps-utils@11.2.0
|
package/dist/base64.cjs
CHANGED
|
@@ -11,8 +11,9 @@ const bytes_1 = require("./bytes.cjs");
|
|
|
11
11
|
*/
|
|
12
12
|
async function encodeBase64(input) {
|
|
13
13
|
const bytes = (0, bytes_1.getBytes)(input);
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
15
|
+
// In the browser, FileReader is much faster than bytesToBase64. This is not supported in React Native however.
|
|
16
|
+
if ('FileReader' in globalThis && !isReactNative) {
|
|
16
17
|
return await new Promise((resolve, reject) => {
|
|
17
18
|
const reader = Object.assign(new FileReader(), {
|
|
18
19
|
onload: () => resolve(reader.result.replace('data:application/octet-stream;base64,', '')),
|
package/dist/base64.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.cjs","sourceRoot":"","sources":["../src/base64.ts"],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,GAAG,MAAM,KAAK,CAC1B,wCAAwC,MAAM,EAAE,CACjD,CAAC;IACF,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AACtD,CAAC;AALD,oCAKC","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Provides fast, asynchronous base64 encoding.\n *\n * @param input - The input value, assumed to be coercible to bytes.\n * @returns A base64 string.\n */\nexport async function encodeBase64(input: Uint8Array | VirtualFile | string) {\n const bytes = getBytes(input);\n const isReactNative =\n typeof navigator !== 'undefined' && navigator.product === 'ReactNative';\n // In the browser, FileReader is much faster than bytesToBase64. This is not supported in React Native however.\n if ('FileReader' in globalThis && !isReactNative) {\n return await new Promise((resolve, reject) => {\n const reader = Object.assign(new FileReader(), {\n onload: () =>\n resolve(\n (reader.result as string).replace(\n 'data:application/octet-stream;base64,',\n '',\n ),\n ),\n onerror: () => reject(reader.error),\n });\n reader.readAsDataURL(\n new File([bytes], '', { type: 'application/octet-stream' }),\n );\n });\n }\n return bytesToBase64(bytes);\n}\n\n/**\n * Provides fast, asynchronous base64 decoding.\n *\n * @param base64 - A base64 string.\n * @returns A Uint8Array of bytes.\n */\nexport async function decodeBase64(base64: string) {\n const response = await fetch(\n `data:application/octet-stream;base64,${base64}`,\n );\n return new Uint8Array(await response.arrayBuffer());\n}\n"]}
|
package/dist/base64.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.d.cts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"base64.d.cts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,oBAuB1E;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,uBAKhD"}
|
package/dist/base64.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.d.mts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"base64.d.mts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAElD;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,oBAuB1E;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,uBAKhD"}
|
package/dist/base64.mjs
CHANGED
|
@@ -8,8 +8,9 @@ import { getBytes } from "./bytes.mjs";
|
|
|
8
8
|
*/
|
|
9
9
|
export async function encodeBase64(input) {
|
|
10
10
|
const bytes = getBytes(input);
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
12
|
+
// In the browser, FileReader is much faster than bytesToBase64. This is not supported in React Native however.
|
|
13
|
+
if ('FileReader' in globalThis && !isReactNative) {
|
|
13
14
|
return await new Promise((resolve, reject) => {
|
|
14
15
|
const reader = Object.assign(new FileReader(), {
|
|
15
16
|
onload: () => resolve(reader.result.replace('data:application/octet-stream;base64,', '')),
|
package/dist/base64.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64.mjs","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB;AAEhD,OAAO,EAAE,QAAQ,EAAE,oBAAgB;AAGnC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAAwC;IACzE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,
|
|
1
|
+
{"version":3,"file":"base64.mjs","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB;AAEhD,OAAO,EAAE,QAAQ,EAAE,oBAAgB;AAGnC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,KAAwC;IACzE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,aAAa,GACjB,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,OAAO,KAAK,aAAa,CAAC;IAC1E,+GAA+G;IAC/G,IAAI,YAAY,IAAI,UAAU,IAAI,CAAC,aAAa,EAAE,CAAC;QACjD,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,EAAE,EAAE;gBAC7C,MAAM,EAAE,GAAG,EAAE,CACX,OAAO,CACJ,MAAM,CAAC,MAAiB,CAAC,OAAO,CAC/B,uCAAuC,EACvC,EAAE,CACH,CACF;gBACH,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;aACpC,CAAC,CAAC;YACH,MAAM,CAAC,aAAa,CAClB,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAC5D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc;IAC/C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAC1B,wCAAwC,MAAM,EAAE,CACjD,CAAC;IACF,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Provides fast, asynchronous base64 encoding.\n *\n * @param input - The input value, assumed to be coercible to bytes.\n * @returns A base64 string.\n */\nexport async function encodeBase64(input: Uint8Array | VirtualFile | string) {\n const bytes = getBytes(input);\n const isReactNative =\n typeof navigator !== 'undefined' && navigator.product === 'ReactNative';\n // In the browser, FileReader is much faster than bytesToBase64. This is not supported in React Native however.\n if ('FileReader' in globalThis && !isReactNative) {\n return await new Promise((resolve, reject) => {\n const reader = Object.assign(new FileReader(), {\n onload: () =>\n resolve(\n (reader.result as string).replace(\n 'data:application/octet-stream;base64,',\n '',\n ),\n ),\n onerror: () => reject(reader.error),\n });\n reader.readAsDataURL(\n new File([bytes], '', { type: 'application/octet-stream' }),\n );\n });\n }\n return bytesToBase64(bytes);\n}\n\n/**\n * Provides fast, asynchronous base64 decoding.\n *\n * @param base64 - A base64 string.\n * @returns A Uint8Array of bytes.\n */\nexport async function decodeBase64(base64: string) {\n const response = await fetch(\n `data:application/octet-stream;base64,${base64}`,\n );\n return new Uint8Array(await response.arrayBuffer());\n}\n"]}
|
|
@@ -144,6 +144,7 @@ async function runFixes(results, rules, errorsOnly = false) {
|
|
|
144
144
|
let fixResults = results;
|
|
145
145
|
(0, utils_1.assert)(fixResults.files);
|
|
146
146
|
fixResults.files.manifest = fixResults.files.manifest.clone();
|
|
147
|
+
const mergedReports = (0, deep_clone_1.deepClone)(fixResults.reports);
|
|
147
148
|
for (let attempts = 1; shouldRunFixes && attempts <= MAX_ATTEMPTS; attempts++) {
|
|
148
149
|
(0, utils_1.assert)(fixResults.files);
|
|
149
150
|
let manifest = fixResults.files.manifest.result;
|
|
@@ -156,11 +157,14 @@ async function runFixes(results, rules, errorsOnly = false) {
|
|
|
156
157
|
fixResults.files.manifest.result = manifest;
|
|
157
158
|
fixResults = await (0, validator_1.runValidators)(fixResults.files, rules);
|
|
158
159
|
shouldRunFixes = (0, validator_1.hasFixes)(fixResults, errorsOnly);
|
|
160
|
+
fixResults.reports
|
|
161
|
+
.filter((report) => !mergedReports.some((mergedReport) => mergedReport.id === report.id))
|
|
162
|
+
.forEach((report) => mergedReports.push(report));
|
|
159
163
|
}
|
|
160
|
-
const
|
|
164
|
+
const allReports = (0, deep_clone_1.deepClone)(mergedReports);
|
|
161
165
|
// Was fixed
|
|
162
166
|
if (!shouldRunFixes) {
|
|
163
|
-
for (const report of
|
|
167
|
+
for (const report of allReports) {
|
|
164
168
|
if (report.fix) {
|
|
165
169
|
report.wasFixed = true;
|
|
166
170
|
delete report.fix;
|
|
@@ -169,16 +173,16 @@ async function runFixes(results, rules, errorsOnly = false) {
|
|
|
169
173
|
return {
|
|
170
174
|
files: fixResults.files,
|
|
171
175
|
updated: true,
|
|
172
|
-
reports:
|
|
176
|
+
reports: allReports,
|
|
173
177
|
};
|
|
174
178
|
}
|
|
175
|
-
for (const report of
|
|
179
|
+
for (const report of allReports) {
|
|
176
180
|
delete report.fix;
|
|
177
181
|
}
|
|
178
182
|
return {
|
|
179
183
|
files: results.files,
|
|
180
184
|
updated: false,
|
|
181
|
-
reports:
|
|
185
|
+
reports: allReports,
|
|
182
186
|
};
|
|
183
187
|
}
|
|
184
188
|
exports.runFixes = runFixes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.cjs","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,m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AC,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,IAAA,2BAAe,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAlBD,oCAkBC;AAED;;;;;;GAMG;AACH,SAAgB,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;AAlBD,kDAkBC","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 { isReportFixable, 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 * Whether the compiler is running in watch mode. This is used to determine\n * whether to fix warnings or errors only.\n */\n watchMode?: 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\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 * @param options.watchMode - Whether the compiler is running in watch mode.\n * This is used to determine whether to fix warnings or errors only.\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 watchMode = false,\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, watchMode)) {\n const fixedResults = await runFixes(validatorResults, undefined, watchMode);\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 * @param errorsOnly - Whether to only run fixes for errors, not warnings.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n errorsOnly = false,\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) =>\n isReportFixable(report, errorsOnly),\n );\n\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, errorsOnly);\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.cjs","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAsD;AAEtD,2CAAwD;AACxD,2BAAoC;AACpC,gDAA6B;AAI7B,+CAAuE;AAEvE,0EAAkD;AAClD,kDAA0C;AAC1C,kCAAqC;AACrC,sCAAoC;AAEpC,wCAA4C;AAC5C,mDAAoE;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;AA4DF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACI,KAAK,UAAU,aAAa,CACjC,QAAgB,EAChB,EACE,sBAAsB,GAAG,IAAI,EAC7B,UAAU,EACV,WAAW,GAAG,aAAE,CAAC,SAAS,EAC1B,OAAO,EACP,iBAAiB,EACjB,SAAS,GAAG,KAAK,MACO,EAAE;IAE5B,MAAM,YAAY,GAAG,cAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,wBAAgB,CAAC,QAAQ,CAAC,CAAC;IACzE,MAAM,YAAY,GAAG,MAAM,IAAA,iBAAY,EAAC,YAAY,CAAC,CAAC;IACtD,MAAM,mBAAmB,GAAG,YAAY,CAAC,MAAM,CAAC;IAEhD,MAAM,WAAW,GAAG,MAAM,IAAA,iBAAY,EACpC,cAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,wBAAgB,CAAC,WAAW,CAAC,CACvD,CAAC;IAEF,MAAM,kBAA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;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;AAlBD,kDAkBC","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 { isReportFixable, 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 * Whether the compiler is running in watch mode. This is used to determine\n * whether to fix warnings or errors only.\n */\n watchMode?: 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\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 * @param options.watchMode - Whether the compiler is running in watch mode.\n * This is used to determine whether to fix warnings or errors only.\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 watchMode = false,\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, watchMode)) {\n const fixedResults = await runFixes(validatorResults, undefined, watchMode);\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 * @param errorsOnly - Whether to only run fixes for errors, not warnings.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n errorsOnly = false,\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 const mergedReports: ValidatorReport[] = deepClone(fixResults.reports);\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) =>\n isReportFixable(report, errorsOnly),\n );\n\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, errorsOnly);\n\n fixResults.reports\n .filter(\n (report) =>\n !mergedReports.some((mergedReport) => mergedReport.id === report.id),\n )\n .forEach((report) => mergedReports.push(report));\n }\n\n const allReports: (CheckManifestReport & ValidatorReport)[] =\n deepClone(mergedReports);\n\n // Was fixed\n if (!shouldRunFixes) {\n for (const report of allReports) {\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: allReports,\n };\n }\n\n for (const report of allReports) {\n delete report.fix;\n }\n\n return {\n files: results.files,\n updated: false,\n reports: allReports,\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":"manifest.d.cts","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAK5C,OAAO,KAAK,EAAE,YAAY,EAAE,yBAAqB;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAoB;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,8BAA0B;AAKxE,OAAO,KAAK,EAAE,SAAS,EAAwB,qBAAiB;AAEhE,OAAO,EAAmB,WAAW,EAAE,iCAA6B;AAepE,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,EAAE,KAAK,C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AAQ,EAAE,YAAY,GAAG,YAAY,CAkBxE"}
|
|
@@ -114,6 +114,7 @@ export async function runFixes(results, rules, errorsOnly = false) {
|
|
|
114
114
|
let fixResults = results;
|
|
115
115
|
assert(fixResults.files);
|
|
116
116
|
fixResults.files.manifest = fixResults.files.manifest.clone();
|
|
117
|
+
const mergedReports = deepClone(fixResults.reports);
|
|
117
118
|
for (let attempts = 1; shouldRunFixes && attempts <= MAX_ATTEMPTS; attempts++) {
|
|
118
119
|
assert(fixResults.files);
|
|
119
120
|
let manifest = fixResults.files.manifest.result;
|
|
@@ -126,11 +127,14 @@ export async function runFixes(results, rules, errorsOnly = false) {
|
|
|
126
127
|
fixResults.files.manifest.result = manifest;
|
|
127
128
|
fixResults = await runValidators(fixResults.files, rules);
|
|
128
129
|
shouldRunFixes = hasFixes(fixResults, errorsOnly);
|
|
130
|
+
fixResults.reports
|
|
131
|
+
.filter((report) => !mergedReports.some((mergedReport) => mergedReport.id === report.id))
|
|
132
|
+
.forEach((report) => mergedReports.push(report));
|
|
129
133
|
}
|
|
130
|
-
const
|
|
134
|
+
const allReports = deepClone(mergedReports);
|
|
131
135
|
// Was fixed
|
|
132
136
|
if (!shouldRunFixes) {
|
|
133
|
-
for (const report of
|
|
137
|
+
for (const report of allReports) {
|
|
134
138
|
if (report.fix) {
|
|
135
139
|
report.wasFixed = true;
|
|
136
140
|
delete report.fix;
|
|
@@ -139,16 +143,16 @@ export async function runFixes(results, rules, errorsOnly = false) {
|
|
|
139
143
|
return {
|
|
140
144
|
files: fixResults.files,
|
|
141
145
|
updated: true,
|
|
142
|
-
reports:
|
|
146
|
+
reports: allReports,
|
|
143
147
|
};
|
|
144
148
|
}
|
|
145
|
-
for (const report of
|
|
149
|
+
for (const report of allReports) {
|
|
146
150
|
delete report.fix;
|
|
147
151
|
}
|
|
148
152
|
return {
|
|
149
153
|
files: results.files,
|
|
150
154
|
updated: false,
|
|
151
|
-
reports:
|
|
155
|
+
reports: allReports,
|
|
152
156
|
};
|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AU,YAAY,CAChC,QAAgB,EAChB,KAA2B,EAC3B,WAAkC,MAAM;IAExC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,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 { isReportFixable, 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 * Whether the compiler is running in watch mode. This is used to determine\n * whether to fix warnings or errors only.\n */\n watchMode?: 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\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 * @param options.watchMode - Whether the compiler is running in watch mode.\n * This is used to determine whether to fix warnings or errors only.\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 watchMode = false,\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, watchMode)) {\n const fixedResults = await runFixes(validatorResults, undefined, watchMode);\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 * @param errorsOnly - Whether to only run fixes for errors, not warnings.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n errorsOnly = false,\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) =>\n isReportFixable(report, errorsOnly),\n );\n\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, errorsOnly);\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,eAAe,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAoB;AAEvE,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;AA4DF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UA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E9C,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 { isReportFixable, 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 * Whether the compiler is running in watch mode. This is used to determine\n * whether to fix warnings or errors only.\n */\n watchMode?: 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\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 * @param options.watchMode - Whether the compiler is running in watch mode.\n * This is used to determine whether to fix warnings or errors only.\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 watchMode = false,\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, watchMode)) {\n const fixedResults = await runFixes(validatorResults, undefined, watchMode);\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 * @param errorsOnly - Whether to only run fixes for errors, not warnings.\n * @returns The updated manifest and whether it was updated.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n errorsOnly = false,\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 const mergedReports: ValidatorReport[] = deepClone(fixResults.reports);\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) =>\n isReportFixable(report, errorsOnly),\n );\n\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, errorsOnly);\n\n fixResults.reports\n .filter(\n (report) =>\n !mergedReports.some((mergedReport) => mergedReport.id === report.id),\n )\n .forEach((report) => mergedReports.push(report));\n }\n\n const allReports: (CheckManifestReport & ValidatorReport)[] =\n deepClone(mergedReports);\n\n // Was fixed\n if (!shouldRunFixes) {\n for (const report of allReports) {\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: allReports,\n };\n }\n\n for (const report of allReports) {\n delete report.fix;\n }\n\n return {\n files: results.files,\n updated: false,\n reports: allReports,\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\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"]}
|
|
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: (id: string, message: string, fix?: ValidatorFix) => void;\n readonly options?: ValidatorContextOptions;\n};\n\nexport type ValidatorReport = {\n id: string;\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\n * 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"]}
|
|
@@ -24,10 +24,11 @@ export type ValidatorContextOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
export type ValidatorSeverity = 'error' | 'warning';
|
|
26
26
|
export type ValidatorContext = {
|
|
27
|
-
readonly report: (message: string, fix?: ValidatorFix) => void;
|
|
27
|
+
readonly report: (id: string, message: string, fix?: ValidatorFix) => void;
|
|
28
28
|
readonly options?: ValidatorContextOptions;
|
|
29
29
|
};
|
|
30
30
|
export type ValidatorReport = {
|
|
31
|
+
id: string;
|
|
31
32
|
severity: ValidatorSeverity;
|
|
32
33
|
message: string;
|
|
33
34
|
fix?: ValidatorFix;
|
|
@@ -35,7 +36,8 @@ export type ValidatorReport = {
|
|
|
35
36
|
export type ValidatorMeta = {
|
|
36
37
|
severity: ValidatorSeverity;
|
|
37
38
|
/**
|
|
38
|
-
* 1. Run the validator on unverified files to ensure that the files are
|
|
39
|
+
* 1. Run the validator on unverified files to ensure that the files are
|
|
40
|
+
* structurally sound.
|
|
39
41
|
*
|
|
40
42
|
* @param files - Files to be verified
|
|
41
43
|
* @param context - Validator context to report errors
|
|
@@ -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;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;
|
|
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,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,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3E,QAAQ,CAAC,OAAO,CAAC,EAAE,uBAAuB,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,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;;;;;;OAMG;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"}
|
|
@@ -24,10 +24,11 @@ export type ValidatorContextOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
export type ValidatorSeverity = 'error' | 'warning';
|
|
26
26
|
export type ValidatorContext = {
|
|
27
|
-
readonly report: (message: string, fix?: ValidatorFix) => void;
|
|
27
|
+
readonly report: (id: string, message: string, fix?: ValidatorFix) => void;
|
|
28
28
|
readonly options?: ValidatorContextOptions;
|
|
29
29
|
};
|
|
30
30
|
export type ValidatorReport = {
|
|
31
|
+
id: string;
|
|
31
32
|
severity: ValidatorSeverity;
|
|
32
33
|
message: string;
|
|
33
34
|
fix?: ValidatorFix;
|
|
@@ -35,7 +36,8 @@ export type ValidatorReport = {
|
|
|
35
36
|
export type ValidatorMeta = {
|
|
36
37
|
severity: ValidatorSeverity;
|
|
37
38
|
/**
|
|
38
|
-
* 1. Run the validator on unverified files to ensure that the files are
|
|
39
|
+
* 1. Run the validator on unverified files to ensure that the files are
|
|
40
|
+
* structurally sound.
|
|
39
41
|
*
|
|
40
42
|
* @param files - Files to be verified
|
|
41
43
|
* @param context - Validator context to report errors
|
|
@@ -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;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,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ACH,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\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"]}
|
|
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: (id: string, message: string, fix?: ValidatorFix) => void;\n readonly options?: ValidatorContextOptions;\n};\n\nexport type ValidatorReport = {\n id: string;\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\n * 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"]}
|
|
@@ -39,12 +39,21 @@ class Context {
|
|
|
39
39
|
constructor(options) {
|
|
40
40
|
this.#options = options;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Report a validation error or warning.
|
|
44
|
+
*
|
|
45
|
+
* @param id - The unique identifier for the report.
|
|
46
|
+
* @param message - The message describing the validation issue.
|
|
47
|
+
* @param fix - An optional fix function that can be used to automatically
|
|
48
|
+
* resolve the issue.
|
|
49
|
+
*/
|
|
50
|
+
report(id, message, fix) {
|
|
43
51
|
(0, utils_1.assert)(this.#nextSeverity !== undefined);
|
|
44
52
|
this.reports.push({
|
|
45
|
-
|
|
53
|
+
id,
|
|
46
54
|
message,
|
|
47
55
|
fix,
|
|
56
|
+
severity: this.#nextSeverity,
|
|
48
57
|
});
|
|
49
58
|
}
|
|
50
59
|
prepareForValidator(settings) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.cjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AAUzC,0EAAkD;AAQlD,MAAM,OAAO;IACX,OAAO,GAAsB,EAAE,CAAC;IAEvB,QAAQ,GAA4B,EAAE,CAAC;IAEhD,aAAa,GAAuB,SAAS,CAAC;IAE9C;;;;;OAKG;IACH,YAAY,OAAgC;QAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,OAAe,EAAE,GAAkB;
|
|
1
|
+
{"version":3,"file":"validator.cjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AAUzC,0EAAkD;AAQlD,MAAM,OAAO;IACX,OAAO,GAAsB,EAAE,CAAC;IAEvB,QAAQ,GAA4B,EAAE,CAAC;IAEhD,aAAa,GAAuB,SAAS,CAAC;IAE9C;;;;;OAKG;IACH,YAAY,OAAgC;QAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,EAAU,EAAE,OAAe,EAAE,GAAkB;QACpD,IAAA,cAAM,EAAC,IAAI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,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;AAjCD,sCAiCC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,MAAuB,EAAE,UAAoB;IAC3E,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC;AAFD,0CAEC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CACtB,OAAyB,EACzB,UAAoB;IAEpB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AAC/E,CAAC;AALD,4BAKC","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 /**\n * Report a validation error or warning.\n *\n * @param id - The unique identifier for the report.\n * @param message - The message describing the validation issue.\n * @param fix - An optional fix function that can be used to automatically\n * resolve the issue.\n */\n report(id: string, message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n\n this.reports.push({\n id,\n message,\n fix,\n severity: this.#nextSeverity,\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\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\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 * Check whether a report is fixable.\n *\n * @param report - The report to check.\n * @param errorsOnly - Whether to only consider errors for fixability.\n * @returns Whether the report is fixable.\n */\nexport function isReportFixable(report: ValidatorReport, errorsOnly?: boolean) {\n return Boolean(report.fix && (!errorsOnly || report.severity === 'error'));\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @param errorsOnly - Whether to only consider errors for pending fixes.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(\n results: ValidatorResults,\n errorsOnly?: boolean,\n): boolean {\n return results.reports.some((report) => isReportFixable(report, errorsOnly));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAmDF;;;;;;;;;;GAUG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,EACzD,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC,CA6B3B;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE,OAAO,WAE5E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,gBAAgB,EACzB,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAET"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAmDF;;;;;;;;;;GAUG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,EACzD,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC,CA6B3B;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE,OAAO,WAE5E;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,gBAAgB,EACzB,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAET"}
|