@metamask/snaps-utils 9.2.2 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/dist/account.cjs +53 -0
- package/dist/account.cjs.map +1 -1
- package/dist/account.d.cts +26 -1
- package/dist/account.d.cts.map +1 -1
- package/dist/account.d.mts +26 -1
- package/dist/account.d.mts.map +1 -1
- package/dist/account.mjs +49 -1
- package/dist/account.mjs.map +1 -1
- package/dist/eval-worker.cjs +38 -11
- package/dist/eval-worker.cjs.map +1 -1
- package/dist/eval-worker.d.cts.map +1 -1
- package/dist/eval-worker.d.mts.map +1 -1
- package/dist/eval-worker.mjs +38 -11
- package/dist/eval-worker.mjs.map +1 -1
- package/dist/eval.cjs +6 -0
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.d.cts +7 -0
- package/dist/eval.d.cts.map +1 -1
- package/dist/eval.d.mts +7 -0
- package/dist/eval.d.mts.map +1 -1
- package/dist/eval.mjs +6 -0
- package/dist/eval.mjs.map +1 -1
- package/dist/fs.cjs +51 -6
- package/dist/fs.cjs.map +1 -1
- package/dist/fs.d.cts +16 -4
- package/dist/fs.d.cts.map +1 -1
- package/dist/fs.d.mts +16 -4
- package/dist/fs.d.mts.map +1 -1
- package/dist/fs.mjs +49 -5
- package/dist/fs.mjs.map +1 -1
- package/dist/handlers/exports.cjs +7 -0
- package/dist/handlers/exports.cjs.map +1 -1
- package/dist/handlers/exports.d.cts +6 -1
- package/dist/handlers/exports.d.cts.map +1 -1
- package/dist/handlers/exports.d.mts +6 -1
- package/dist/handlers/exports.d.mts.map +1 -1
- package/dist/handlers/exports.mjs +7 -0
- package/dist/handlers/exports.mjs.map +1 -1
- package/dist/handlers/home-page.d.cts +3 -3
- package/dist/handlers/home-page.d.mts +3 -3
- package/dist/handlers/settings-page.d.cts +1 -1
- package/dist/handlers/settings-page.d.mts +1 -1
- package/dist/handlers/signature.d.cts +1 -1
- package/dist/handlers/signature.d.mts +1 -1
- package/dist/handlers/transaction.d.cts +3 -3
- package/dist/handlers/transaction.d.mts +3 -3
- package/dist/handlers/types.cjs +1 -0
- package/dist/handlers/types.cjs.map +1 -1
- package/dist/handlers/types.d.cts +2 -1
- package/dist/handlers/types.d.cts.map +1 -1
- package/dist/handlers/types.d.mts +2 -1
- package/dist/handlers/types.d.mts.map +1 -1
- package/dist/handlers/types.mjs +1 -0
- package/dist/handlers/types.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +36 -4
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts +40 -7
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts +40 -7
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +13 -4
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +18 -1
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +18 -1
- package/dist/manifest/validator-types.d.mts.map +1 -1
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +23 -10
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.d.cts +4 -2
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts +4 -2
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs +23 -10
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/index.cjs +2 -0
- package/dist/manifest/validators/index.cjs.map +1 -1
- package/dist/manifest/validators/index.d.cts +2 -0
- package/dist/manifest/validators/index.d.cts.map +1 -1
- package/dist/manifest/validators/index.d.mts +2 -0
- package/dist/manifest/validators/index.d.mts.map +1 -1
- package/dist/manifest/validators/index.mjs +2 -0
- package/dist/manifest/validators/index.mjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.cjs +47 -0
- package/dist/manifest/validators/production-platform-version.cjs.map +1 -0
- package/dist/manifest/validators/production-platform-version.d.cts +7 -0
- package/dist/manifest/validators/production-platform-version.d.cts.map +1 -0
- package/dist/manifest/validators/production-platform-version.d.mts +7 -0
- package/dist/manifest/validators/production-platform-version.d.mts.map +1 -0
- package/dist/manifest/validators/production-platform-version.mjs +44 -0
- package/dist/manifest/validators/production-platform-version.mjs.map +1 -0
- package/dist/manifest/validators/unused-exports.cjs +53 -0
- package/dist/manifest/validators/unused-exports.cjs.map +1 -0
- package/dist/manifest/validators/unused-exports.d.cts +7 -0
- package/dist/manifest/validators/unused-exports.d.cts.map +1 -0
- package/dist/manifest/validators/unused-exports.d.mts +7 -0
- package/dist/manifest/validators/unused-exports.d.mts.map +1 -0
- package/dist/manifest/validators/unused-exports.mjs +50 -0
- package/dist/manifest/validators/unused-exports.mjs.map +1 -0
- package/dist/time.cjs +15 -1
- package/dist/time.cjs.map +1 -1
- package/dist/time.d.cts +7 -0
- package/dist/time.d.cts.map +1 -1
- package/dist/time.d.mts +7 -0
- package/dist/time.d.mts.map +1 -1
- package/dist/time.mjs +13 -0
- package/dist/time.mjs.map +1 -1
- package/package.json +4 -3
package/dist/fs.cjs
CHANGED
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useTemporaryFile = exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName = exports.getOutfilePath = exports.readJsonFile = exports.isFile = exports.isDirectory = void 0;
|
|
6
|
+
exports.useFileSystemCache = exports.useTemporaryFile = exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName = exports.getOutfilePath = exports.readJsonFile = exports.isFile = exports.isDirectory = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
8
9
|
const os_1 = __importDefault(require("os"));
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const json_1 = require("./json.cjs");
|
|
@@ -135,19 +136,23 @@ async function validateDirPath(dirPath, createDir) {
|
|
|
135
136
|
}
|
|
136
137
|
exports.validateDirPath = validateDirPath;
|
|
137
138
|
/**
|
|
138
|
-
*
|
|
139
|
-
* This function handles deletion of the temporary
|
|
139
|
+
* Create a temporary file with a given name and content, writes it to disk and
|
|
140
|
+
* calls the provided function. This function handles deletion of the temporary
|
|
141
|
+
* file after usage.
|
|
140
142
|
*
|
|
141
143
|
* @param fileName - The name of the temporary file.
|
|
142
144
|
* @param fileContents - The content of the temporary file.
|
|
143
|
-
* @param fn - The callback function to call when the temporary file has been
|
|
145
|
+
* @param fn - The callback function to call when the temporary file has been
|
|
146
|
+
* created.
|
|
147
|
+
* @returns The result of the callback function.
|
|
144
148
|
*/
|
|
145
149
|
async function useTemporaryFile(fileName, fileContents, fn) {
|
|
146
|
-
const
|
|
150
|
+
const temporaryDirectory = await (0, promises_1.mkdtemp)(path_1.default.join(os_1.default.tmpdir(), 'snaps-'));
|
|
151
|
+
const filePath = path_1.default.join(temporaryDirectory, fileName);
|
|
147
152
|
await fs_1.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
148
153
|
await fs_1.promises.writeFile(filePath, fileContents);
|
|
149
154
|
try {
|
|
150
|
-
await fn(filePath);
|
|
155
|
+
return await fn(filePath);
|
|
151
156
|
}
|
|
152
157
|
finally {
|
|
153
158
|
if (await isFile(filePath)) {
|
|
@@ -156,4 +161,44 @@ async function useTemporaryFile(fileName, fileContents, fn) {
|
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
exports.useTemporaryFile = useTemporaryFile;
|
|
164
|
+
/**
|
|
165
|
+
* Use the file system to cache a return value with a given key and TTL.
|
|
166
|
+
*
|
|
167
|
+
* @param cacheKey - The key to use for the cache.
|
|
168
|
+
* @param ttl - The time-to-live in milliseconds.
|
|
169
|
+
* @param fn - The callback function to wrap.
|
|
170
|
+
* @returns The result from the callback.
|
|
171
|
+
*/
|
|
172
|
+
function useFileSystemCache(cacheKey, ttl, fn) {
|
|
173
|
+
return async () => {
|
|
174
|
+
const filePath = path_1.default.join(process.cwd(), 'node_modules/.cache/snaps', `${cacheKey}.json`);
|
|
175
|
+
try {
|
|
176
|
+
const cacheContents = await fs_1.promises.readFile(filePath, 'utf8');
|
|
177
|
+
const json = JSON.parse(cacheContents);
|
|
178
|
+
if (json.timestamp + ttl > Date.now()) {
|
|
179
|
+
return json.value;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// No-op
|
|
184
|
+
}
|
|
185
|
+
const value = await fn();
|
|
186
|
+
// Null or undefined is not persisted.
|
|
187
|
+
if (value === null || value === undefined) {
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
await fs_1.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
192
|
+
const json = { timestamp: Date.now(), value };
|
|
193
|
+
await fs_1.promises.writeFile(filePath, JSON.stringify(json), {
|
|
194
|
+
encoding: 'utf8',
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
// No-op
|
|
199
|
+
}
|
|
200
|
+
return value;
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
exports.useFileSystemCache = useFileSystemCache;
|
|
159
204
|
//# sourceMappingURL=fs.cjs.map
|
package/dist/fs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.cjs","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":";;;;;;AACA,2BAAoC;AACpC,4CAAoB;A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AI,KAAK,CACb,oBAAoB,OAAO,+CAA+C,CAC3E,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAXD,0CAWC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,gBAAgB,CACpC,QAAgB,EAChB,YAAoB,EACpB,EAAsC;IAEtC,MAAM,QAAQ,GAAG,cAAS,CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,aAAE,CAAC,KAAK,CAAC,cAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,MAAM,aAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,IAAI,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,aAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;AACH,CAAC;AAfD,4CAeC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport type { VirtualFile } from './virtual-file';\nimport { readVirtualFile } from './virtual-file/node';\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 {\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 extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\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\n/**\n * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.\n * This function handles deletion of the temporary file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been created.\n */\nexport async function useTemporaryFile(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<unknown>,\n): Promise<void> {\n const filePath = pathUtils.join(os.tmpdir(), fileName);\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fs.cjs","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":";;;;;;AACA,2BAAoC;AACpC,0CAAsC;AACtC,4CAAoB;AACpB,gDAA6B;AAE7B,qCAAmC;AAEnC,kDAAsD;AAEtD;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;IAElB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,aAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;YACf,CAAC;YAED,MAAM,aAAE,CAAC,KAAK,CAAC,UAAU,EA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,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAEjE,MAAM,IAAI,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC;YAC9C,MAAM,aAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBACjD,QAAQ,EAAE,MAAM;aACjB,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,QAAQ;QACV,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AA3CD,gDA2CC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport { mkdtemp } from 'fs/promises';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport type { VirtualFile } from './virtual-file';\nimport { readVirtualFile } from './virtual-file/node';\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 {\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 extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\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\n/**\n * Create a temporary file with a given name and content, writes it to disk and\n * calls the provided function. This function handles deletion of the temporary\n * file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been\n * created.\n * @returns The result of the callback function.\n */\nexport async function useTemporaryFile<Type = unknown>(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<Type>,\n): Promise<Type> {\n const temporaryDirectory = await mkdtemp(\n pathUtils.join(os.tmpdir(), 'snaps-'),\n );\n\n const filePath = pathUtils.join(temporaryDirectory, fileName);\n\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n return await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n\n/**\n * Use the file system to cache a return value with a given key and TTL.\n *\n * @param cacheKey - The key to use for the cache.\n * @param ttl - The time-to-live in milliseconds.\n * @param fn - The callback function to wrap.\n * @returns The result from the callback.\n */\nexport function useFileSystemCache<Type = unknown>(\n cacheKey: string,\n ttl: number,\n fn: () => Promise<Type>,\n) {\n return async () => {\n const filePath = pathUtils.join(\n process.cwd(),\n 'node_modules/.cache/snaps',\n `${cacheKey}.json`,\n );\n\n try {\n const cacheContents = await fs.readFile(filePath, 'utf8');\n const json = JSON.parse(cacheContents);\n\n if (json.timestamp + ttl > Date.now()) {\n return json.value;\n }\n } catch {\n // No-op\n }\n\n const value = await fn();\n\n // Null or undefined is not persisted.\n if (value === null || value === undefined) {\n return value;\n }\n\n try {\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n\n const json = { timestamp: Date.now(), value };\n await fs.writeFile(filePath, JSON.stringify(json), {\n encoding: 'utf8',\n });\n } catch {\n // No-op\n }\n\n return value;\n };\n}\n"]}
|
package/dist/fs.d.cts
CHANGED
|
@@ -59,12 +59,24 @@ export declare function validateFilePath(filePath: string): Promise<boolean>;
|
|
|
59
59
|
*/
|
|
60
60
|
export declare function validateDirPath(dirPath: string, createDir: boolean): Promise<boolean>;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
* This function handles deletion of the temporary
|
|
62
|
+
* Create a temporary file with a given name and content, writes it to disk and
|
|
63
|
+
* calls the provided function. This function handles deletion of the temporary
|
|
64
|
+
* file after usage.
|
|
64
65
|
*
|
|
65
66
|
* @param fileName - The name of the temporary file.
|
|
66
67
|
* @param fileContents - The content of the temporary file.
|
|
67
|
-
* @param fn - The callback function to call when the temporary file has been
|
|
68
|
+
* @param fn - The callback function to call when the temporary file has been
|
|
69
|
+
* created.
|
|
70
|
+
* @returns The result of the callback function.
|
|
68
71
|
*/
|
|
69
|
-
export declare function useTemporaryFile(fileName: string, fileContents: string, fn: (path: string) => Promise<
|
|
72
|
+
export declare function useTemporaryFile<Type = unknown>(fileName: string, fileContents: string, fn: (path: string) => Promise<Type>): Promise<Type>;
|
|
73
|
+
/**
|
|
74
|
+
* Use the file system to cache a return value with a given key and TTL.
|
|
75
|
+
*
|
|
76
|
+
* @param cacheKey - The key to use for the cache.
|
|
77
|
+
* @param ttl - The time-to-live in milliseconds.
|
|
78
|
+
* @param fn - The callback function to wrap.
|
|
79
|
+
* @returns The result from the callback.
|
|
80
|
+
*/
|
|
81
|
+
export declare function useFileSystemCache<Type = unknown>(cacheKey: string, ttl: number, fn: () => Promise<Type>): () => Promise<any>;
|
|
70
82
|
//# sourceMappingURL=fs.d.cts.map
|
package/dist/fs.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.cts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"fs.d.cts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAO5C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAGlD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,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declare function validateDirPath(dirPath: string, createDir: boolean): Promise<boolean>;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
* This function handles deletion of the temporary
|
|
62
|
+
* Create a temporary file with a given name and content, writes it to disk and
|
|
63
|
+
* calls the provided function. This function handles deletion of the temporary
|
|
64
|
+
* file after usage.
|
|
64
65
|
*
|
|
65
66
|
* @param fileName - The name of the temporary file.
|
|
66
67
|
* @param fileContents - The content of the temporary file.
|
|
67
|
-
* @param fn - The callback function to call when the temporary file has been
|
|
68
|
+
* @param fn - The callback function to call when the temporary file has been
|
|
69
|
+
* created.
|
|
70
|
+
* @returns The result of the callback function.
|
|
68
71
|
*/
|
|
69
|
-
export declare function useTemporaryFile(fileName: string, fileContents: string, fn: (path: string) => Promise<
|
|
72
|
+
export declare function useTemporaryFile<Type = unknown>(fileName: string, fileContents: string, fn: (path: string) => Promise<Type>): Promise<Type>;
|
|
73
|
+
/**
|
|
74
|
+
* Use the file system to cache a return value with a given key and TTL.
|
|
75
|
+
*
|
|
76
|
+
* @param cacheKey - The key to use for the cache.
|
|
77
|
+
* @param ttl - The time-to-live in milliseconds.
|
|
78
|
+
* @param fn - The callback function to wrap.
|
|
79
|
+
* @returns The result from the callback.
|
|
80
|
+
*/
|
|
81
|
+
export declare function useFileSystemCache<Type = unknown>(cacheKey: string, ttl: number, fn: () => Promise<Type>): () => Promise<any>;
|
|
70
82
|
//# sourceMappingURL=fs.d.mts.map
|
package/dist/fs.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.mts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"fs.d.mts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAO5C,OAAO,KAAK,EAAE,WAAW,EAAE,iCAAuB;AAGlD;;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
1
|
import { promises as fs } from "fs";
|
|
2
|
+
import { mkdtemp } from "fs/promises";
|
|
2
3
|
import os from "os";
|
|
3
4
|
import pathUtils from "path";
|
|
4
5
|
import { parseJson } from "./json.mjs";
|
|
@@ -122,19 +123,23 @@ export async function validateDirPath(dirPath, createDir) {
|
|
|
122
123
|
return true;
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
125
|
-
*
|
|
126
|
-
* This function handles deletion of the temporary
|
|
126
|
+
* Create a temporary file with a given name and content, writes it to disk and
|
|
127
|
+
* calls the provided function. This function handles deletion of the temporary
|
|
128
|
+
* file after usage.
|
|
127
129
|
*
|
|
128
130
|
* @param fileName - The name of the temporary file.
|
|
129
131
|
* @param fileContents - The content of the temporary file.
|
|
130
|
-
* @param fn - The callback function to call when the temporary file has been
|
|
132
|
+
* @param fn - The callback function to call when the temporary file has been
|
|
133
|
+
* created.
|
|
134
|
+
* @returns The result of the callback function.
|
|
131
135
|
*/
|
|
132
136
|
export async function useTemporaryFile(fileName, fileContents, fn) {
|
|
133
|
-
const
|
|
137
|
+
const temporaryDirectory = await mkdtemp(pathUtils.join(os.tmpdir(), 'snaps-'));
|
|
138
|
+
const filePath = pathUtils.join(temporaryDirectory, fileName);
|
|
134
139
|
await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });
|
|
135
140
|
await fs.writeFile(filePath, fileContents);
|
|
136
141
|
try {
|
|
137
|
-
await fn(filePath);
|
|
142
|
+
return await fn(filePath);
|
|
138
143
|
}
|
|
139
144
|
finally {
|
|
140
145
|
if (await isFile(filePath)) {
|
|
@@ -142,4 +147,43 @@ export async function useTemporaryFile(fileName, fileContents, fn) {
|
|
|
142
147
|
}
|
|
143
148
|
}
|
|
144
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Use the file system to cache a return value with a given key and TTL.
|
|
152
|
+
*
|
|
153
|
+
* @param cacheKey - The key to use for the cache.
|
|
154
|
+
* @param ttl - The time-to-live in milliseconds.
|
|
155
|
+
* @param fn - The callback function to wrap.
|
|
156
|
+
* @returns The result from the callback.
|
|
157
|
+
*/
|
|
158
|
+
export function useFileSystemCache(cacheKey, ttl, fn) {
|
|
159
|
+
return async () => {
|
|
160
|
+
const filePath = pathUtils.join(process.cwd(), 'node_modules/.cache/snaps', `${cacheKey}.json`);
|
|
161
|
+
try {
|
|
162
|
+
const cacheContents = await fs.readFile(filePath, 'utf8');
|
|
163
|
+
const json = JSON.parse(cacheContents);
|
|
164
|
+
if (json.timestamp + ttl > Date.now()) {
|
|
165
|
+
return json.value;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// No-op
|
|
170
|
+
}
|
|
171
|
+
const value = await fn();
|
|
172
|
+
// Null or undefined is not persisted.
|
|
173
|
+
if (value === null || value === undefined) {
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });
|
|
178
|
+
const json = { timestamp: Date.now(), value };
|
|
179
|
+
await fs.writeFile(filePath, JSON.stringify(json), {
|
|
180
|
+
encoding: 'utf8',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// No-op
|
|
185
|
+
}
|
|
186
|
+
return value;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
145
189
|
//# sourceMappingURL=fs.mjs.map
|
package/dist/fs.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.mjs","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AACpC,OAAO,EAAE,WAAW;AACpB,OAAO,SAAS,aAAa;AAE7B,OAAO,EAAE,SAAS,EAAE,mBAAe;AAEnC,OAAO,EAAE,eAAe,EAAE,gCAA4B;AAEtD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;IAElB,IAAI,C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EAChB,YAAoB,EACpB,EAAsC;IAEtC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,IAAI,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport type { VirtualFile } from './virtual-file';\nimport { readVirtualFile } from './virtual-file/node';\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 {\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 extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\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\n/**\n * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.\n * This function handles deletion of the temporary file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been created.\n */\nexport async function useTemporaryFile(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<unknown>,\n): Promise<void> {\n const filePath = pathUtils.join(os.tmpdir(), fileName);\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fs.mjs","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AACpC,OAAO,EAAE,OAAO,EAAE,oBAAoB;AACtC,OAAO,EAAE,WAAW;AACpB,OAAO,SAAS,aAAa;AAE7B,OAAO,EAAE,SAAS,EAAE,mBAAe;AAEnC,OAAO,EAAE,eAAe,EAAE,gCAA4B;AAEtD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,UAAkB,EAClB,SAAkB;IAElB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;YACf,CAAC;YAED,MAAM,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YA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I,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC;YAC9C,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;gBACjD,QAAQ,EAAE,MAAM;aACjB,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,QAAQ;QACV,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport { mkdtemp } from 'fs/promises';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport type { VirtualFile } from './virtual-file';\nimport { readVirtualFile } from './virtual-file/node';\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 {\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 extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\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\n/**\n * Create a temporary file with a given name and content, writes it to disk and\n * calls the provided function. This function handles deletion of the temporary\n * file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been\n * created.\n * @returns The result of the callback function.\n */\nexport async function useTemporaryFile<Type = unknown>(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<Type>,\n): Promise<Type> {\n const temporaryDirectory = await mkdtemp(\n pathUtils.join(os.tmpdir(), 'snaps-'),\n );\n\n const filePath = pathUtils.join(temporaryDirectory, fileName);\n\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n return await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n\n/**\n * Use the file system to cache a return value with a given key and TTL.\n *\n * @param cacheKey - The key to use for the cache.\n * @param ttl - The time-to-live in milliseconds.\n * @param fn - The callback function to wrap.\n * @returns The result from the callback.\n */\nexport function useFileSystemCache<Type = unknown>(\n cacheKey: string,\n ttl: number,\n fn: () => Promise<Type>,\n) {\n return async () => {\n const filePath = pathUtils.join(\n process.cwd(),\n 'node_modules/.cache/snaps',\n `${cacheKey}.json`,\n );\n\n try {\n const cacheContents = await fs.readFile(filePath, 'utf8');\n const json = JSON.parse(cacheContents);\n\n if (json.timestamp + ttl > Date.now()) {\n return json.value;\n }\n } catch {\n // No-op\n }\n\n const value = await fn();\n\n // Null or undefined is not persisted.\n if (value === null || value === undefined) {\n return value;\n }\n\n try {\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n\n const json = { timestamp: Date.now(), value };\n await fs.writeFile(filePath, JSON.stringify(json), {\n encoding: 'utf8',\n });\n } catch {\n // No-op\n }\n\n return value;\n };\n}\n"]}
|
|
@@ -108,6 +108,13 @@ exports.SNAP_EXPORTS = {
|
|
|
108
108
|
return typeof snapExport === 'function';
|
|
109
109
|
},
|
|
110
110
|
},
|
|
111
|
+
[types_1.HandlerType.OnClientRequest]: {
|
|
112
|
+
type: types_1.HandlerType.OnClientRequest,
|
|
113
|
+
required: true,
|
|
114
|
+
validator: (snapExport) => {
|
|
115
|
+
return typeof snapExport === 'function';
|
|
116
|
+
},
|
|
117
|
+
},
|
|
111
118
|
};
|
|
112
119
|
exports.SNAP_EXPORT_NAMES = Object.values(types_1.HandlerType);
|
|
113
120
|
//# sourceMappingURL=exports.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.cjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"exports.cjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":";;;AAmBA,uCAAsC;AAEzB,QAAA,YAAY,GAAG;IAC1B,CAAC,mBAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,IAAI,EAAE,mBAAW,CAAC,YAAY;QAC9B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAqC,EAAE;YACpE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,aAAa,CAAC,EAAE;QAC3B,IAAI,EAAE,mBAAW,CAAC,aAAa;QAC/B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAsC,EAAE;YACrE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,SAAS,CAAC,EAAE;QACvB,IAAI,EAAE,mBAAW,CAAC,SAAS;QAC3B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAkC,EAAE;YACjE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,IAAI,EAAE,mBAAW,CAAC,YAAY;QAC9B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAqC,EAAE;YACpE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,mBAAW,CAAC,SAAS,CAAC,EAAE;QACvB,IAAI,EAAE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;KACF;CACO,CAAC;AAEE,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAW,CAAC,CAAC","sourcesContent":["import type {\n OnAssetHistoricalPriceHandler,\n OnAssetsConversionHandler,\n OnAssetsLookupHandler,\n OnClientRequestHandler,\n OnCronjobHandler,\n OnHomePageHandler,\n OnInstallHandler,\n OnKeyringRequestHandler,\n OnNameLookupHandler,\n OnProtocolRequestHandler,\n OnRpcRequestHandler,\n OnSettingsPageHandler,\n OnSignatureHandler,\n OnTransactionHandler,\n OnUpdateHandler,\n OnUserInputHandler,\n} from '@metamask/snaps-sdk';\n\nimport { HandlerType } from './types';\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnNameLookup]: {\n type: HandlerType.OnNameLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnNameLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnKeyringRequest]: {\n type: HandlerType.OnKeyringRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnKeyringRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnHomePage]: {\n type: HandlerType.OnHomePage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnHomePageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSettingsPage]: {\n type: HandlerType.OnSettingsPage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSettingsPageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSignature]: {\n type: HandlerType.OnSignature,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSignatureHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUserInput]: {\n type: HandlerType.OnUserInput,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUserInputHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetHistoricalPrice]: {\n type: HandlerType.OnAssetHistoricalPrice,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetHistoricalPriceHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsLookup]: {\n type: HandlerType.OnAssetsLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnAssetsLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsConversion]: {\n type: HandlerType.OnAssetsConversion,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetsConversionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnProtocolRequest]: {\n type: HandlerType.OnProtocolRequest,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnProtocolRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnClientRequest]: {\n type: HandlerType.OnClientRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnClientRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler } from "@metamask/snaps-sdk";
|
|
1
|
+
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnClientRequestHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler } from "@metamask/snaps-sdk";
|
|
2
2
|
import { HandlerType } from "./types.cjs";
|
|
3
3
|
export declare const SNAP_EXPORTS: {
|
|
4
4
|
readonly onRpcRequest: {
|
|
@@ -76,6 +76,11 @@ export declare const SNAP_EXPORTS: {
|
|
|
76
76
|
readonly required: true;
|
|
77
77
|
readonly validator: (snapExport: unknown) => snapExport is OnProtocolRequestHandler;
|
|
78
78
|
};
|
|
79
|
+
readonly onClientRequest: {
|
|
80
|
+
readonly type: HandlerType.OnClientRequest;
|
|
81
|
+
readonly required: true;
|
|
82
|
+
readonly validator: (snapExport: unknown) => snapExport is OnClientRequestHandler;
|
|
83
|
+
};
|
|
79
84
|
};
|
|
80
85
|
export declare const SNAP_EXPORT_NAMES: HandlerType[];
|
|
81
86
|
//# sourceMappingURL=exports.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.cts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAQjB,OAAO;;;;;yCAQG,OAAO;;;;;yCAQjB,OAAO;;;;;yCASP,OAAO;;
|
|
1
|
+
{"version":3,"file":"exports.d.cts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAQjB,OAAO;;;;;yCAQG,OAAO;;;;;yCAQjB,OAAO;;;;;yCASP,OAAO;;;;;yCAQG,OAAO;;CAIzB,CAAC;AAEX,eAAO,MAAM,iBAAiB,eAA6B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler } from "@metamask/snaps-sdk";
|
|
1
|
+
import type { OnAssetHistoricalPriceHandler, OnAssetsConversionHandler, OnAssetsLookupHandler, OnClientRequestHandler, OnCronjobHandler, OnHomePageHandler, OnKeyringRequestHandler, OnNameLookupHandler, OnProtocolRequestHandler, OnRpcRequestHandler, OnSettingsPageHandler, OnSignatureHandler, OnTransactionHandler, OnUserInputHandler } from "@metamask/snaps-sdk";
|
|
2
2
|
import { HandlerType } from "./types.mjs";
|
|
3
3
|
export declare const SNAP_EXPORTS: {
|
|
4
4
|
readonly onRpcRequest: {
|
|
@@ -76,6 +76,11 @@ export declare const SNAP_EXPORTS: {
|
|
|
76
76
|
readonly required: true;
|
|
77
77
|
readonly validator: (snapExport: unknown) => snapExport is OnProtocolRequestHandler;
|
|
78
78
|
};
|
|
79
|
+
readonly onClientRequest: {
|
|
80
|
+
readonly type: HandlerType.OnClientRequest;
|
|
81
|
+
readonly required: true;
|
|
82
|
+
readonly validator: (snapExport: unknown) => snapExport is OnClientRequestHandler;
|
|
83
|
+
};
|
|
79
84
|
};
|
|
80
85
|
export declare const SNAP_EXPORT_NAMES: HandlerType[];
|
|
81
86
|
//# sourceMappingURL=exports.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.mts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAQjB,OAAO;;;;;yCAQG,OAAO;;;;;yCAQjB,OAAO;;;;;yCASP,OAAO;;
|
|
1
|
+
{"version":3,"file":"exports.d.mts","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAQjB,OAAO;;;;;yCAQG,OAAO;;;;;yCAQjB,OAAO;;;;;yCASP,OAAO;;;;;yCAQG,OAAO;;CAIzB,CAAC;AAEX,eAAO,MAAM,iBAAiB,eAA6B,CAAC"}
|
|
@@ -105,6 +105,13 @@ export const SNAP_EXPORTS = {
|
|
|
105
105
|
return typeof snapExport === 'function';
|
|
106
106
|
},
|
|
107
107
|
},
|
|
108
|
+
[HandlerType.OnClientRequest]: {
|
|
109
|
+
type: HandlerType.OnClientRequest,
|
|
110
|
+
required: true,
|
|
111
|
+
validator: (snapExport) => {
|
|
112
|
+
return typeof snapExport === 'function';
|
|
113
|
+
},
|
|
114
|
+
},
|
|
108
115
|
};
|
|
109
116
|
export const SNAP_EXPORT_NAMES = Object.values(HandlerType);
|
|
110
117
|
//# sourceMappingURL=exports.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.mjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exports.mjs","sourceRoot":"","sources":["../../src/handlers/exports.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,IAAI,EAAE,WAAW,CAAC,YAAY;QAC9B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAqC,EAAE;YACpE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE;QAC3B,IAAI,EAAE,WAAW,CAAC,aAAa;QAC/B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAsC,EAAE;YACrE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;QACvB,IAAI,EAAE,WAAW,CAAC,SAAS;QAC3B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAkC,EAAE;YACjE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE;QAC1B,IAAI,EAAE,WAAW,CAAC,YAAY;QAC9B,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,CAAC,UAAmB,EAAqC,EAAE;YACpE,OAAO,OAAO,UAAU,KAAK,UAAU,CAAC;QAC1C,CAAC;KACF;IACD,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;QACvB,IAAI,EAAE,WAAW,CAAC,SAA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AiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import type {\n OnAssetHistoricalPriceHandler,\n OnAssetsConversionHandler,\n OnAssetsLookupHandler,\n OnClientRequestHandler,\n OnCronjobHandler,\n OnHomePageHandler,\n OnInstallHandler,\n OnKeyringRequestHandler,\n OnNameLookupHandler,\n OnProtocolRequestHandler,\n OnRpcRequestHandler,\n OnSettingsPageHandler,\n OnSignatureHandler,\n OnTransactionHandler,\n OnUpdateHandler,\n OnUserInputHandler,\n} from '@metamask/snaps-sdk';\n\nimport { HandlerType } from './types';\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnNameLookup]: {\n type: HandlerType.OnNameLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnNameLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnKeyringRequest]: {\n type: HandlerType.OnKeyringRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnKeyringRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnHomePage]: {\n type: HandlerType.OnHomePage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnHomePageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSettingsPage]: {\n type: HandlerType.OnSettingsPage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSettingsPageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSignature]: {\n type: HandlerType.OnSignature,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSignatureHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUserInput]: {\n type: HandlerType.OnUserInput,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUserInputHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetHistoricalPrice]: {\n type: HandlerType.OnAssetHistoricalPrice,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetHistoricalPriceHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsLookup]: {\n type: HandlerType.OnAssetsLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnAssetsLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnAssetsConversion]: {\n type: HandlerType.OnAssetsConversion,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnAssetsConversionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnProtocolRequest]: {\n type: HandlerType.OnProtocolRequest,\n required: true,\n validator: (\n snapExport: unknown,\n ): snapExport is OnProtocolRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnClientRequest]: {\n type: HandlerType.OnClientRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnClientRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n"]}
|
|
@@ -67,7 +67,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
67
67
|
variant?: "primary" | "secondary" | undefined;
|
|
68
68
|
buttonType?: "button" | "submit" | undefined;
|
|
69
69
|
})[];
|
|
70
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
70
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
71
71
|
src: string;
|
|
72
72
|
alt?: string | undefined;
|
|
73
73
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -153,7 +153,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
153
153
|
variant?: "primary" | "secondary" | undefined;
|
|
154
154
|
buttonType?: "button" | "submit" | undefined;
|
|
155
155
|
})[];
|
|
156
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
156
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
157
157
|
src: string;
|
|
158
158
|
alt?: string | undefined;
|
|
159
159
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -245,7 +245,7 @@ export declare const OnHomePageResponseStruct: import("@metamask/superstruct").S
|
|
|
245
245
|
variant?: "primary" | "secondary" | undefined;
|
|
246
246
|
buttonType?: "button" | "submit" | undefined;
|
|
247
247
|
})[];
|
|
248
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
248
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
249
249
|
src: string;
|
|
250
250
|
alt?: string | undefined;
|
|
251
251
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -67,7 +67,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
67
67
|
variant?: "primary" | "secondary" | undefined;
|
|
68
68
|
buttonType?: "button" | "submit" | undefined;
|
|
69
69
|
})[];
|
|
70
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
70
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
71
71
|
src: string;
|
|
72
72
|
alt?: string | undefined;
|
|
73
73
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -153,7 +153,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
153
153
|
variant?: "primary" | "secondary" | undefined;
|
|
154
154
|
buttonType?: "button" | "submit" | undefined;
|
|
155
155
|
})[];
|
|
156
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
156
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
157
157
|
src: string;
|
|
158
158
|
alt?: string | undefined;
|
|
159
159
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -245,7 +245,7 @@ export declare const OnHomePageResponseStruct: import("@metamask/superstruct").S
|
|
|
245
245
|
variant?: "primary" | "secondary" | undefined;
|
|
246
246
|
buttonType?: "button" | "submit" | undefined;
|
|
247
247
|
})[];
|
|
248
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
248
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
249
249
|
src: string;
|
|
250
250
|
alt?: string | undefined;
|
|
251
251
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -67,7 +67,7 @@ export declare const OnSettingsPageResponseStruct: import("@metamask/superstruct
|
|
|
67
67
|
variant?: "primary" | "secondary" | undefined;
|
|
68
68
|
buttonType?: "button" | "submit" | undefined;
|
|
69
69
|
})[];
|
|
70
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
70
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
71
71
|
src: string;
|
|
72
72
|
alt?: string | undefined;
|
|
73
73
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -67,7 +67,7 @@ export declare const OnSettingsPageResponseStruct: import("@metamask/superstruct
|
|
|
67
67
|
variant?: "primary" | "secondary" | undefined;
|
|
68
68
|
buttonType?: "button" | "submit" | undefined;
|
|
69
69
|
})[];
|
|
70
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
70
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
71
71
|
src: string;
|
|
72
72
|
alt?: string | undefined;
|
|
73
73
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|
|
@@ -70,7 +70,7 @@ export declare const OnSignatureResponseStruct: import("@metamask/superstruct").
|
|
|
70
70
|
variant?: "primary" | "secondary" | undefined;
|
|
71
71
|
buttonType?: "button" | "submit" | undefined;
|
|
72
72
|
})[];
|
|
73
|
-
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").
|
|
73
|
+
} | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AccountSelectorProps, "AccountSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressInputProps, "AddressInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AssetSelectorProps, "AssetSelector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
74
74
|
src: string;
|
|
75
75
|
alt?: string | undefined;
|
|
76
76
|
borderRadius?: import("@metamask/snaps-sdk/jsx").BorderRadius;
|