@metamask/snaps-utils 0.24.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/LICENSE +15 -0
- package/README.md +3 -0
- package/dist/caveats.d.ts +22 -0
- package/dist/caveats.js +27 -0
- package/dist/caveats.js.map +1 -0
- package/dist/cronjob.d.ts +89 -0
- package/dist/cronjob.js +74 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/deep-clone.d.ts +1 -0
- package/dist/deep-clone.js +9 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/default-endowments.d.ts +4 -0
- package/dist/default-endowments.js +43 -0
- package/dist/default-endowments.js.map +1 -0
- package/dist/eval-worker.d.ts +1 -0
- package/dist/eval-worker.js +32 -0
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval.d.ts +8 -0
- package/dist/eval.js +28 -0
- package/dist/eval.js.map +1 -0
- package/dist/flatMap.d.ts +22 -0
- package/dist/flatMap.js +38 -0
- package/dist/flatMap.js.map +1 -0
- package/dist/fs.d.ts +69 -0
- package/dist/fs.js +144 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.browser.d.ts +13 -0
- package/dist/index.browser.js +30 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/json-rpc.d.ts +10 -0
- package/dist/json-rpc.js +22 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/manifest/index.browser.d.ts +1 -0
- package/dist/manifest/index.browser.js +18 -0
- package/dist/manifest/index.browser.js.map +1 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/index.js +19 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manifest.d.ts +75 -0
- package/dist/manifest/manifest.js +237 -0
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/manifest/validation.d.ts +483 -0
- package/dist/manifest/validation.js +142 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/mock.d.ts +14 -0
- package/dist/mock.js +107 -0
- package/dist/mock.js.map +1 -0
- package/dist/namespace.d.ts +275 -0
- package/dist/namespace.js +223 -0
- package/dist/namespace.js.map +1 -0
- package/dist/notification.d.ts +66 -0
- package/dist/notification.js +58 -0
- package/dist/notification.js.map +1 -0
- package/dist/npm.d.ts +20 -0
- package/dist/npm.js +73 -0
- package/dist/npm.js.map +1 -0
- package/dist/object.d.ts +8 -0
- package/dist/object.js +15 -0
- package/dist/object.js.map +1 -0
- package/dist/post-process.d.ts +71 -0
- package/dist/post-process.js +321 -0
- package/dist/post-process.js.map +1 -0
- package/dist/snaps.d.ts +165 -0
- package/dist/snaps.js +123 -0
- package/dist/snaps.js.map +1 -0
- package/dist/types.d.ts +107 -0
- package/dist/types.js +82 -0
- package/dist/types.js.map +1 -0
- package/dist/url.d.ts +7 -0
- package/dist/url.js +19 -0
- package/dist/url.js.map +1 -0
- package/dist/versions.d.ts +44 -0
- package/dist/versions.js +77 -0
- package/dist/versions.js.map +1 -0
- package/package.json +100 -0
package/dist/fs.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName = exports.getOutfilePath = exports.readSnapJsonFile = exports.readJsonFile = exports.isFile = exports.isDirectory = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether the given path string resolves to an existing directory, and
|
|
11
|
+
* optionally creates the directory if it doesn't exist.
|
|
12
|
+
*
|
|
13
|
+
* @param pathString - The path string to check.
|
|
14
|
+
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
15
|
+
* @returns Whether the given path is an existing directory.
|
|
16
|
+
*/
|
|
17
|
+
async function isDirectory(pathString, createDir) {
|
|
18
|
+
try {
|
|
19
|
+
const stats = await fs_1.promises.stat(pathString);
|
|
20
|
+
return stats.isDirectory();
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code === 'ENOENT') {
|
|
24
|
+
if (!createDir) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
await fs_1.promises.mkdir(pathString, { recursive: true });
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.isDirectory = isDirectory;
|
|
34
|
+
/**
|
|
35
|
+
* Checks whether the given path string resolves to an existing file.
|
|
36
|
+
*
|
|
37
|
+
* @param pathString - The path string to check.
|
|
38
|
+
* @returns Whether the given path is an existing file.
|
|
39
|
+
*/
|
|
40
|
+
async function isFile(pathString) {
|
|
41
|
+
try {
|
|
42
|
+
const stats = await fs_1.promises.stat(pathString);
|
|
43
|
+
return stats.isFile();
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.isFile = isFile;
|
|
50
|
+
/**
|
|
51
|
+
* Reads a `.json` file, parses its contents, and returns them.
|
|
52
|
+
*
|
|
53
|
+
* @param pathString - The path to the JSON file.
|
|
54
|
+
* @returns The parsed contents of the JSON file.
|
|
55
|
+
*/
|
|
56
|
+
async function readJsonFile(pathString) {
|
|
57
|
+
if (!pathString.endsWith('.json')) {
|
|
58
|
+
throw new Error('The specified file must be a ".json" file.');
|
|
59
|
+
}
|
|
60
|
+
return JSON.parse(await fs_1.promises.readFile(pathString, 'utf8'));
|
|
61
|
+
}
|
|
62
|
+
exports.readJsonFile = readJsonFile;
|
|
63
|
+
/**
|
|
64
|
+
* Utility function for reading `package.json` or the Snap manifest file.
|
|
65
|
+
* These are assumed to be in the current working directory.
|
|
66
|
+
*
|
|
67
|
+
* @param pathString - The base path of the file to read.
|
|
68
|
+
* @param snapJsonFileName - The name of the file to read.
|
|
69
|
+
* @returns The parsed JSON file.
|
|
70
|
+
*/
|
|
71
|
+
async function readSnapJsonFile(pathString, snapJsonFileName) {
|
|
72
|
+
const path = path_1.default.join(pathString, snapJsonFileName);
|
|
73
|
+
try {
|
|
74
|
+
return await readJsonFile(path);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error.code === 'ENOENT') {
|
|
78
|
+
throw new Error(`Could not find '${path}'. Please ensure that the file exists.`);
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.readSnapJsonFile = readSnapJsonFile;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the complete out file path from an output file name and parent
|
|
86
|
+
* directory path.
|
|
87
|
+
*
|
|
88
|
+
* @param outDir - The path to the out file's parent directory.
|
|
89
|
+
* @param outFileName - The out file's name.
|
|
90
|
+
* @returns The complete path to the out file.
|
|
91
|
+
*/
|
|
92
|
+
function getOutfilePath(outDir, outFileName) {
|
|
93
|
+
return path_1.default.join(outDir, outFileName || 'bundle.js');
|
|
94
|
+
}
|
|
95
|
+
exports.getOutfilePath = getOutfilePath;
|
|
96
|
+
/**
|
|
97
|
+
* Ensures that the outfile name is just a `.js` file name.
|
|
98
|
+
* Throws on validation failure.
|
|
99
|
+
*
|
|
100
|
+
* @param filename - The file name to validate.
|
|
101
|
+
* @returns `true` if validation succeeded.
|
|
102
|
+
* @throws If the file name is invalid.
|
|
103
|
+
*/
|
|
104
|
+
function validateOutfileName(filename) {
|
|
105
|
+
if (!filename.endsWith('.js') ||
|
|
106
|
+
filename === '.js' ||
|
|
107
|
+
path_1.default.basename(filename) !== filename) {
|
|
108
|
+
throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
exports.validateOutfileName = validateOutfileName;
|
|
113
|
+
/**
|
|
114
|
+
* Validates a file path. Throws on validation failure.
|
|
115
|
+
*
|
|
116
|
+
* @param filePath - The file path to validate.
|
|
117
|
+
* @returns `true` if validation succeeded.
|
|
118
|
+
* @throws If the path does not resolve to a file.
|
|
119
|
+
*/
|
|
120
|
+
async function validateFilePath(filePath) {
|
|
121
|
+
const exists = await isFile(filePath);
|
|
122
|
+
if (!exists) {
|
|
123
|
+
throw new Error(`Invalid params: '${filePath}' is not a file or does not exist.`);
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
exports.validateFilePath = validateFilePath;
|
|
128
|
+
/**
|
|
129
|
+
* Validates a directory path. Throws on validation failure.
|
|
130
|
+
*
|
|
131
|
+
* @param dirPath - The directory path to validate.
|
|
132
|
+
* @param createDir - Whether to create the directory if it doesn't exist.
|
|
133
|
+
* @returns `true` if validation succeeded or the directory was created.
|
|
134
|
+
* @throws If the directory does not exist or could not be created.
|
|
135
|
+
*/
|
|
136
|
+
async function validateDirPath(dirPath, createDir) {
|
|
137
|
+
const exists = await isDirectory(dirPath, createDir);
|
|
138
|
+
if (!exists) {
|
|
139
|
+
throw new Error(`Invalid params: '${dirPath}' is not a directory or could not be created.`);
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
exports.validateDirPath = validateDirPath;
|
|
144
|
+
//# sourceMappingURL=fs.js.map
|
package/dist/fs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"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","sourcesContent":["import { promises as fs } from 'fs';\nimport pathUtils from 'path';\nimport { Json } from '@metamask/utils';\nimport { NpmSnapFileNames } from './types';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n await fs.mkdir(pathString, { recursive: true });\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile<Type = Json>(\n pathString: string,\n): Promise<Type> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n return JSON.parse(await fs.readFile(pathString, 'utf8'));\n}\n\n/**\n * Utility function for reading `package.json` or the Snap manifest file.\n * These are assumed to be in the current working directory.\n *\n * @param pathString - The base path of the file to read.\n * @param snapJsonFileName - The name of the file to read.\n * @returns The parsed JSON file.\n */\nexport async function readSnapJsonFile(\n pathString: string,\n snapJsonFileName: NpmSnapFileNames,\n): Promise<Json> {\n const path = pathUtils.join(pathString, snapJsonFileName);\n\n try {\n return await readJsonFile(path);\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${path}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n}\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n pathUtils.basename(filename) !== filename\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './caveats';
|
|
2
|
+
export * from './deep-clone';
|
|
3
|
+
export * from './default-endowments';
|
|
4
|
+
export * from './flatMap';
|
|
5
|
+
export * from './json-rpc';
|
|
6
|
+
export * from './manifest/index.browser';
|
|
7
|
+
export * from './namespace';
|
|
8
|
+
export * from './notification';
|
|
9
|
+
export * from './object';
|
|
10
|
+
export * from './snaps';
|
|
11
|
+
export * from './types';
|
|
12
|
+
export * from './url';
|
|
13
|
+
export * from './versions';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./caveats"), exports);
|
|
18
|
+
__exportStar(require("./deep-clone"), exports);
|
|
19
|
+
__exportStar(require("./default-endowments"), exports);
|
|
20
|
+
__exportStar(require("./flatMap"), exports);
|
|
21
|
+
__exportStar(require("./json-rpc"), exports);
|
|
22
|
+
__exportStar(require("./manifest/index.browser"), exports);
|
|
23
|
+
__exportStar(require("./namespace"), exports);
|
|
24
|
+
__exportStar(require("./notification"), exports);
|
|
25
|
+
__exportStar(require("./object"), exports);
|
|
26
|
+
__exportStar(require("./snaps"), exports);
|
|
27
|
+
__exportStar(require("./types"), exports);
|
|
28
|
+
__exportStar(require("./url"), exports);
|
|
29
|
+
__exportStar(require("./versions"), exports);
|
|
30
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,4CAA0B;AAC1B,6CAA2B;AAC3B,2DAAyC;AACzC,8CAA4B;AAC5B,iDAA+B;AAC/B,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB;AACxB,wCAAsB;AACtB,6CAA2B","sourcesContent":["export * from './caveats';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './flatMap';\nexport * from './json-rpc';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './notification';\nexport * from './object';\nexport * from './snaps';\nexport * from './types';\nexport * from './url';\nexport * from './versions';\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './caveats';
|
|
2
|
+
export * from './cronjob';
|
|
3
|
+
export * from './deep-clone';
|
|
4
|
+
export * from './default-endowments';
|
|
5
|
+
export * from './eval';
|
|
6
|
+
export * from './flatMap';
|
|
7
|
+
export * from './fs';
|
|
8
|
+
export * from './json-rpc';
|
|
9
|
+
export * from './manifest';
|
|
10
|
+
export * from './mock';
|
|
11
|
+
export * from './namespace';
|
|
12
|
+
export * from './notification';
|
|
13
|
+
export * from './npm';
|
|
14
|
+
export * from './object';
|
|
15
|
+
export * from './post-process';
|
|
16
|
+
export * from './snaps';
|
|
17
|
+
export * from './types';
|
|
18
|
+
export * from './url';
|
|
19
|
+
export * from './versions';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./caveats"), exports);
|
|
18
|
+
__exportStar(require("./cronjob"), exports);
|
|
19
|
+
__exportStar(require("./deep-clone"), exports);
|
|
20
|
+
__exportStar(require("./default-endowments"), exports);
|
|
21
|
+
__exportStar(require("./eval"), exports);
|
|
22
|
+
__exportStar(require("./flatMap"), exports);
|
|
23
|
+
__exportStar(require("./fs"), exports);
|
|
24
|
+
__exportStar(require("./json-rpc"), exports);
|
|
25
|
+
__exportStar(require("./manifest"), exports);
|
|
26
|
+
__exportStar(require("./mock"), exports);
|
|
27
|
+
__exportStar(require("./namespace"), exports);
|
|
28
|
+
__exportStar(require("./notification"), exports);
|
|
29
|
+
__exportStar(require("./npm"), exports);
|
|
30
|
+
__exportStar(require("./object"), exports);
|
|
31
|
+
__exportStar(require("./post-process"), exports);
|
|
32
|
+
__exportStar(require("./snaps"), exports);
|
|
33
|
+
__exportStar(require("./types"), exports);
|
|
34
|
+
__exportStar(require("./url"), exports);
|
|
35
|
+
__exportStar(require("./versions"), exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,+CAA6B;AAC7B,uDAAqC;AACrC,yCAAuB;AACvB,4CAA0B;AAC1B,uCAAqB;AACrB,6CAA2B;AAC3B,6CAA2B;AAC3B,yCAAuB;AACvB,8CAA4B;AAC5B,iDAA+B;AAC/B,wCAAsB;AACtB,2CAAyB;AACzB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,wCAAsB;AACtB,6CAA2B","sourcesContent":["export * from './caveats';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './eval';\nexport * from './flatMap';\nexport * from './fs';\nexport * from './json-rpc';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './notification';\nexport * from './npm';\nexport * from './object';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './url';\nexport * from './versions';\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Json, JsonRpcSuccess } from '@metamask/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Assert that the given value is a successful JSON-RPC response. If the value
|
|
4
|
+
* is not a success response, an error is thrown. If the value is an JSON-RPC
|
|
5
|
+
* error, the error message is included in the thrown error.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to check.
|
|
8
|
+
* @throws If the value is not a JSON-RPC success response.
|
|
9
|
+
*/
|
|
10
|
+
export declare function assertIsJsonRpcSuccess(value: unknown): asserts value is JsonRpcSuccess<Json>;
|
package/dist/json-rpc.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertIsJsonRpcSuccess = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Assert that the given value is a successful JSON-RPC response. If the value
|
|
7
|
+
* is not a success response, an error is thrown. If the value is an JSON-RPC
|
|
8
|
+
* error, the error message is included in the thrown error.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The value to check.
|
|
11
|
+
* @throws If the value is not a JSON-RPC success response.
|
|
12
|
+
*/
|
|
13
|
+
function assertIsJsonRpcSuccess(value) {
|
|
14
|
+
if (!(0, utils_1.isJsonRpcSuccess)(value)) {
|
|
15
|
+
if ((0, utils_1.isJsonRpcFailure)(value)) {
|
|
16
|
+
throw new Error(`JSON-RPC request failed: ${value.error.message}`);
|
|
17
|
+
}
|
|
18
|
+
throw new Error('Invalid JSON-RPC response.');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.assertIsJsonRpcSuccess = assertIsJsonRpcSuccess;
|
|
22
|
+
//# sourceMappingURL=json-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-rpc.js","sourceRoot":"","sources":["../src/json-rpc.ts"],"names":[],"mappings":";;;AAAA,2CAKyB;AAEzB;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,KAAc;IAEd,IAAI,CAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE;QAC5B,IAAI,IAAA,wBAAgB,EAAC,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;SACpE;QAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KAC/C;AACH,CAAC;AAVD,wDAUC","sourcesContent":["import {\n isJsonRpcFailure,\n isJsonRpcSuccess,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './validation';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./validation"), exports);
|
|
18
|
+
//# sourceMappingURL=index.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../src/manifest/index.browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B","sourcesContent":["export * from './validation';\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./manifest"), exports);
|
|
18
|
+
__exportStar(require("./validation"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/manifest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B","sourcesContent":["export * from './manifest';\nexport * from './validation';\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Json } from '@metamask/utils';
|
|
2
|
+
import { ProgrammaticallyFixableSnapError } from '../snaps';
|
|
3
|
+
import { NpmSnapPackageJson, SnapFiles } from '../types';
|
|
4
|
+
import { SnapManifest } from './validation';
|
|
5
|
+
/**
|
|
6
|
+
* The result from the `checkManifest` function.
|
|
7
|
+
*
|
|
8
|
+
* @property manifest - The fixed manifest object.
|
|
9
|
+
* @property updated - Whether the manifest was updated.
|
|
10
|
+
* @property warnings - An array of warnings that were encountered during
|
|
11
|
+
* processing of the manifest files. These warnings are not logged to the
|
|
12
|
+
* console automatically, so depending on the environment the function is called
|
|
13
|
+
* in, a different method for logging can be used.
|
|
14
|
+
* @property errors - An array of errors that were encountered during
|
|
15
|
+
* processing of the manifest files. These errors are not logged to the
|
|
16
|
+
* console automatically, so depending on the environment the function is called
|
|
17
|
+
* in, a different method for logging can be used.
|
|
18
|
+
*/
|
|
19
|
+
export declare type CheckManifestResult = {
|
|
20
|
+
manifest: SnapManifest;
|
|
21
|
+
updated?: boolean;
|
|
22
|
+
warnings: string[];
|
|
23
|
+
errors: string[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Validates a snap.manifest.json file. Attempts to fix the manifest and write
|
|
27
|
+
* the fixed version to disk if `writeManifest` is true. Throws if validation
|
|
28
|
+
* fails.
|
|
29
|
+
*
|
|
30
|
+
* @param basePath - The path to the folder with the manifest files.
|
|
31
|
+
* @param writeManifest - Whether to write the fixed manifest to disk.
|
|
32
|
+
* @param sourceCode - The source code of the Snap.
|
|
33
|
+
* @returns Whether the manifest was updated, and an array of warnings that
|
|
34
|
+
* were encountered during processing of the manifest files.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkManifest(basePath: string, writeManifest?: boolean, sourceCode?: string): Promise<CheckManifestResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Given the relevant Snap files (manifest, `package.json`, and bundle) and a
|
|
39
|
+
* Snap manifest validation error, fixes the fault in the manifest that caused
|
|
40
|
+
* the error.
|
|
41
|
+
*
|
|
42
|
+
* @param snapFiles - The contents of all Snap files.
|
|
43
|
+
* @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.
|
|
44
|
+
* @returns A copy of the manifest file where the cause of the error is fixed.
|
|
45
|
+
*/
|
|
46
|
+
export declare function fixManifest(snapFiles: SnapFiles, error: ProgrammaticallyFixableSnapError): SnapManifest;
|
|
47
|
+
/**
|
|
48
|
+
* Given an unvalidated Snap manifest, attempts to extract the location of the
|
|
49
|
+
* bundle source file location and read the file.
|
|
50
|
+
*
|
|
51
|
+
* @param basePath - The path to the folder with the manifest files.
|
|
52
|
+
* @param manifest - The unvalidated Snap manifest file contents.
|
|
53
|
+
* @returns The contents of the bundle file, if any.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getSnapSourceCode(basePath: string, manifest: Json): Promise<string | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* Sorts the given manifest in our preferred sort order and removes the
|
|
58
|
+
* `repository` field if it is falsy (it may be `null`).
|
|
59
|
+
*
|
|
60
|
+
* @param manifest - The manifest to sort and modify.
|
|
61
|
+
* @returns The disk-ready manifest.
|
|
62
|
+
*/
|
|
63
|
+
export declare function getWritableManifest(manifest: SnapManifest): SnapManifest;
|
|
64
|
+
/**
|
|
65
|
+
* Validates the fields of an npm Snap manifest that has already passed JSON
|
|
66
|
+
* Schema validation.
|
|
67
|
+
*
|
|
68
|
+
* @param snapFiles - The relevant snap files to validate.
|
|
69
|
+
* @param snapFiles.manifest - The npm Snap manifest to validate.
|
|
70
|
+
* @param snapFiles.packageJson - The npm Snap's `package.json`.
|
|
71
|
+
* @param snapFiles.sourceCode - The Snap's source code.
|
|
72
|
+
* @returns A tuple containing the validated snap manifest, snap source code,
|
|
73
|
+
* and `package.json`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function validateNpmSnapManifest({ manifest, packageJson, sourceCode, }: SnapFiles): [SnapManifest, string, NpmSnapPackageJson];
|