@metamask/snaps-utils 8.2.0 → 8.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 +23 -1
- package/dist/currency.cjs +20 -0
- package/dist/currency.cjs.map +1 -0
- package/dist/currency.d.cts +11 -0
- package/dist/currency.d.cts.map +1 -0
- package/dist/currency.d.mts +11 -0
- package/dist/currency.d.mts.map +1 -0
- package/dist/currency.mjs +16 -0
- package/dist/currency.mjs.map +1 -0
- package/dist/errors.cjs +24 -11
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.mjs +24 -11
- package/dist/errors.mjs.map +1 -1
- package/dist/eval.cjs +0 -1
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.mjs +0 -1
- package/dist/eval.mjs.map +1 -1
- package/dist/handlers.d.cts +7 -0
- package/dist/handlers.d.cts.map +1 -1
- package/dist/handlers.d.mts +7 -0
- package/dist/handlers.d.mts.map +1 -1
- package/dist/iframe.cjs +8 -5
- package/dist/iframe.cjs.map +1 -1
- package/dist/iframe.d.cts +12 -4
- package/dist/iframe.d.cts.map +1 -1
- package/dist/iframe.d.mts +12 -4
- package/dist/iframe.d.mts.map +1 -1
- package/dist/iframe.mjs +8 -5
- package/dist/iframe.mjs.map +1 -1
- package/dist/iframe.test.browser.cjs +36 -1
- package/dist/iframe.test.browser.cjs.map +1 -1
- package/dist/iframe.test.browser.mjs +36 -1
- package/dist/iframe.test.browser.mjs.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/manifest/validation.cjs +1 -1
- package/dist/manifest/validation.cjs.map +1 -1
- package/dist/manifest/validation.mjs +1 -1
- package/dist/manifest/validation.mjs.map +1 -1
- package/dist/manifest/validator.cjs +20 -5
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.mjs +20 -5
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/snaps.cjs +12 -1
- package/dist/snaps.cjs.map +1 -1
- package/dist/snaps.d.cts +8 -0
- package/dist/snaps.d.cts.map +1 -1
- package/dist/snaps.d.mts +8 -0
- package/dist/snaps.d.mts.map +1 -1
- package/dist/snaps.mjs +11 -1
- package/dist/snaps.mjs.map +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -2
- package/dist/types.mjs.map +1 -1
- package/dist/virtual-file/VirtualFile.cjs +0 -4
- package/dist/virtual-file/VirtualFile.cjs.map +1 -1
- package/dist/virtual-file/VirtualFile.mjs +0 -4
- package/dist/virtual-file/VirtualFile.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [8.4.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `isSnapId` utility function ([#2808](https://github.com/MetaMask/snaps/pull/2808))
|
|
15
|
+
|
|
16
|
+
## [8.3.0]
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- Add `currency` struct ([#2763](https://github.com/MetaMask/snaps/pull/2763))
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Convert `createWindow` parameters to options bag ([#2765](https://github.com/MetaMask/snaps/pull/2765))
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Update `package.json` struct to allow `repository.directory` ([#2754](https://github.com/MetaMask/snaps/pull/2754))
|
|
29
|
+
|
|
10
30
|
## [8.2.0]
|
|
11
31
|
|
|
12
32
|
### Added
|
|
@@ -435,7 +455,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
435
455
|
- The version of the package no longer needs to match the version of all other
|
|
436
456
|
MetaMask Snaps packages.
|
|
437
457
|
|
|
438
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.
|
|
458
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.4.0...HEAD
|
|
459
|
+
[8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.3.0...@metamask/snaps-utils@8.4.0
|
|
460
|
+
[8.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.2.0...@metamask/snaps-utils@8.3.0
|
|
439
461
|
[8.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.1.1...@metamask/snaps-utils@8.2.0
|
|
440
462
|
[8.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.1.0...@metamask/snaps-utils@8.1.1
|
|
441
463
|
[8.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.0.1...@metamask/snaps-utils@8.1.0
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currency = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
/**
|
|
6
|
+
* A wrapper of Superstruct's `literal` struct that accepts a value in either
|
|
7
|
+
* completely lowercase or completely uppercase (i.e., "usd" or "USD").
|
|
8
|
+
*
|
|
9
|
+
* @param string - The currency symbol.
|
|
10
|
+
* @returns The struct that accepts the currency symbol in either case. It will
|
|
11
|
+
* return the currency symbol in lowercase.
|
|
12
|
+
*/
|
|
13
|
+
function currency(string) {
|
|
14
|
+
const lowerCase = string.toLowerCase();
|
|
15
|
+
return (0, superstruct_1.coerce)((0, superstruct_1.literal)(lowerCase), (0, superstruct_1.literal)(string.toUpperCase()), (value) => {
|
|
16
|
+
return (0, superstruct_1.create)(value.toLowerCase(), (0, superstruct_1.literal)(lowerCase));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.currency = currency;
|
|
20
|
+
//# sourceMappingURL=currency.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.cjs","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":";;;AACA,uDAAgE;AAEhE;;;;;;;GAOG;AACH,SAAgB,QAAQ,CACtB,MAAa;IAEb,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAEvC,OAAO,IAAA,oBAAM,EAAC,IAAA,qBAAO,EAAC,SAAS,CAAC,EAAE,IAAA,qBAAO,EAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;QACzE,OAAO,IAAA,oBAAM,EAAC,KAAK,CAAC,WAAW,EAAE,EAAE,IAAA,qBAAO,EAAC,SAAS,CAAC,CAAC,CAAC;IACzD,CAAC,CAAgD,CAAC;AACpD,CAAC;AARD,4BAQC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { coerce, create, literal } from '@metamask/superstruct';\n\n/**\n * A wrapper of Superstruct's `literal` struct that accepts a value in either\n * completely lowercase or completely uppercase (i.e., \"usd\" or \"USD\").\n *\n * @param string - The currency symbol.\n * @returns The struct that accepts the currency symbol in either case. It will\n * return the currency symbol in lowercase.\n */\nexport function currency<Value extends string>(\n string: Value,\n): Struct<Lowercase<Value> | Uppercase<Value>> {\n const lowerCase = string.toLowerCase();\n\n return coerce(literal(lowerCase), literal(string.toUpperCase()), (value) => {\n return create(value.toLowerCase(), literal(lowerCase));\n }) as Struct<Lowercase<Value> | Uppercase<Value>>;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* A wrapper of Superstruct's `literal` struct that accepts a value in either
|
|
4
|
+
* completely lowercase or completely uppercase (i.e., "usd" or "USD").
|
|
5
|
+
*
|
|
6
|
+
* @param string - The currency symbol.
|
|
7
|
+
* @returns The struct that accepts the currency symbol in either case. It will
|
|
8
|
+
* return the currency symbol in lowercase.
|
|
9
|
+
*/
|
|
10
|
+
export declare function currency<Value extends string>(string: Value): Struct<Lowercase<Value> | Uppercase<Value>>;
|
|
11
|
+
//# sourceMappingURL=currency.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.cts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAGpD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,MAAM,EAC3C,MAAM,EAAE,KAAK,GACZ,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAM7C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* A wrapper of Superstruct's `literal` struct that accepts a value in either
|
|
4
|
+
* completely lowercase or completely uppercase (i.e., "usd" or "USD").
|
|
5
|
+
*
|
|
6
|
+
* @param string - The currency symbol.
|
|
7
|
+
* @returns The struct that accepts the currency symbol in either case. It will
|
|
8
|
+
* return the currency symbol in lowercase.
|
|
9
|
+
*/
|
|
10
|
+
export declare function currency<Value extends string>(string: Value): Struct<Lowercase<Value> | Uppercase<Value>>;
|
|
11
|
+
//# sourceMappingURL=currency.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.mts","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAGpD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,MAAM,EAC3C,MAAM,EAAE,KAAK,GACZ,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAM7C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { coerce, create, literal } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* A wrapper of Superstruct's `literal` struct that accepts a value in either
|
|
4
|
+
* completely lowercase or completely uppercase (i.e., "usd" or "USD").
|
|
5
|
+
*
|
|
6
|
+
* @param string - The currency symbol.
|
|
7
|
+
* @returns The struct that accepts the currency symbol in either case. It will
|
|
8
|
+
* return the currency symbol in lowercase.
|
|
9
|
+
*/
|
|
10
|
+
export function currency(string) {
|
|
11
|
+
const lowerCase = string.toLowerCase();
|
|
12
|
+
return coerce(literal(lowerCase), literal(string.toUpperCase()), (value) => {
|
|
13
|
+
return create(value.toLowerCase(), literal(lowerCase));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=currency.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.mjs","sourceRoot":"","sources":["../src/currency.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,8BAA8B;AAEhE;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAa;IAEb,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAEvC,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;QACzE,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACzD,CAAC,CAAgD,CAAC;AACpD,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { coerce, create, literal } from '@metamask/superstruct';\n\n/**\n * A wrapper of Superstruct's `literal` struct that accepts a value in either\n * completely lowercase or completely uppercase (i.e., \"usd\" or \"USD\").\n *\n * @param string - The currency symbol.\n * @returns The struct that accepts the currency symbol in either case. It will\n * return the currency symbol in lowercase.\n */\nexport function currency<Value extends string>(\n string: Value,\n): Struct<Lowercase<Value> | Uppercase<Value>> {\n const lowerCase = string.toLowerCase();\n\n return coerce(literal(lowerCase), literal(string.toUpperCase()), (value) => {\n return create(value.toLowerCase(), literal(lowerCase));\n }) as Struct<Lowercase<Value> | Uppercase<Value>>;\n}\n"]}
|
package/dist/errors.cjs
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _WrappedSnapError_error, _WrappedSnapError_message, _WrappedSnapError_stack;
|
|
2
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
15
|
exports.unwrapError = exports.isWrappedSnapError = exports.isSerializedSnapError = exports.isSnapError = exports.WrappedSnapError = exports.SNAP_ERROR_WRAPPER_MESSAGE = exports.SNAP_ERROR_WRAPPER_CODE = void 0;
|
|
4
16
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
@@ -7,9 +19,6 @@ const utils_1 = require("@metamask/utils");
|
|
|
7
19
|
exports.SNAP_ERROR_WRAPPER_CODE = -31001;
|
|
8
20
|
exports.SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';
|
|
9
21
|
class WrappedSnapError extends Error {
|
|
10
|
-
#error;
|
|
11
|
-
#message;
|
|
12
|
-
#stack;
|
|
13
22
|
/**
|
|
14
23
|
* Create a new `WrappedSnapError`.
|
|
15
24
|
*
|
|
@@ -18,9 +27,12 @@ class WrappedSnapError extends Error {
|
|
|
18
27
|
constructor(error) {
|
|
19
28
|
const message = (0, snaps_sdk_1.getErrorMessage)(error);
|
|
20
29
|
super(message);
|
|
21
|
-
this
|
|
22
|
-
this
|
|
23
|
-
this
|
|
30
|
+
_WrappedSnapError_error.set(this, void 0);
|
|
31
|
+
_WrappedSnapError_message.set(this, void 0);
|
|
32
|
+
_WrappedSnapError_stack.set(this, void 0);
|
|
33
|
+
__classPrivateFieldSet(this, _WrappedSnapError_error, error, "f");
|
|
34
|
+
__classPrivateFieldSet(this, _WrappedSnapError_message, message, "f");
|
|
35
|
+
__classPrivateFieldSet(this, _WrappedSnapError_stack, (0, snaps_sdk_1.getErrorStack)(error), "f");
|
|
24
36
|
}
|
|
25
37
|
/**
|
|
26
38
|
* The error name.
|
|
@@ -36,7 +48,7 @@ class WrappedSnapError extends Error {
|
|
|
36
48
|
* @returns The error message.
|
|
37
49
|
*/
|
|
38
50
|
get message() {
|
|
39
|
-
return this
|
|
51
|
+
return __classPrivateFieldGet(this, _WrappedSnapError_message, "f");
|
|
40
52
|
}
|
|
41
53
|
/**
|
|
42
54
|
* The error stack.
|
|
@@ -44,7 +56,7 @@ class WrappedSnapError extends Error {
|
|
|
44
56
|
* @returns The error stack.
|
|
45
57
|
*/
|
|
46
58
|
get stack() {
|
|
47
|
-
return this
|
|
59
|
+
return __classPrivateFieldGet(this, _WrappedSnapError_stack, "f");
|
|
48
60
|
}
|
|
49
61
|
/**
|
|
50
62
|
* Convert the error to a JSON object.
|
|
@@ -52,9 +64,9 @@ class WrappedSnapError extends Error {
|
|
|
52
64
|
* @returns The JSON object.
|
|
53
65
|
*/
|
|
54
66
|
toJSON() {
|
|
55
|
-
const cause = isSnapError(this
|
|
56
|
-
? this
|
|
57
|
-
: (0, rpc_errors_1.serializeCause)(this
|
|
67
|
+
const cause = isSnapError(__classPrivateFieldGet(this, _WrappedSnapError_error, "f"))
|
|
68
|
+
? __classPrivateFieldGet(this, _WrappedSnapError_error, "f").serialize()
|
|
69
|
+
: (0, rpc_errors_1.serializeCause)(__classPrivateFieldGet(this, _WrappedSnapError_error, "f"));
|
|
58
70
|
return {
|
|
59
71
|
code: exports.SNAP_ERROR_WRAPPER_CODE,
|
|
60
72
|
message: exports.SNAP_ERROR_WRAPPER_MESSAGE,
|
|
@@ -74,6 +86,7 @@ class WrappedSnapError extends Error {
|
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
88
|
exports.WrappedSnapError = WrappedSnapError;
|
|
89
|
+
_WrappedSnapError_error = new WeakMap(), _WrappedSnapError_message = new WeakMap(), _WrappedSnapError_stack = new WeakMap();
|
|
77
90
|
/**
|
|
78
91
|
* Check if an object is a `SnapError`.
|
|
79
92
|
*
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qDAI8B;AAG9B,mDAK6B;AAE7B,2CAA2D;AAE9C,QAAA,uBAAuB,GAAG,CAAC,KAAK,CAAC;AACjC,QAAA,0BAA0B,GAAG,oBAAoB,CAAC;AAU/D,MAAa,gBAAiB,SAA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C,IAAI,CAAC,KAAK,CAAC;gBACnE,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;YAC7D,CAAC;YAED,iDAAiD;YACjD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;YACxD,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;QAED,sEAAsE;QACtE,WAAW;QACX,OAAO;YACL,eAAe,CACb,uBAAU,CAAC,GAAG,CAAC,QAAQ,EACvB,IAAA,2BAAe,EAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EACjC,IAAA,yBAAa,EAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAChC;YACD,KAAK;SACN,CAAC;IACJ,CAAC;IAED,2EAA2E;IAC3E,qDAAqD;IACrD,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAC7C,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAED,6EAA6E;IAC7E,yDAAyD;IACzD,OAAO;QACL,eAAe,CACb,uBAAU,CAAC,GAAG,CAAC,QAAQ,EACvB,IAAA,2BAAe,EAAC,KAAK,CAAC,EACtB,IAAA,yBAAa,EAAC,KAAK,CAAC,CACrB;QACD,KAAK;KACN,CAAC;AACJ,CAAC;AAnDD,kCAmDC","sourcesContent":["import {\n errorCodes,\n JsonRpcError as RpcError,\n serializeCause,\n} from '@metamask/rpc-errors';\nimport type { DataWithOptionalCause } from '@metamask/rpc-errors';\nimport type { SerializedSnapError, SnapError } from '@metamask/snaps-sdk';\nimport {\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from '@metamask/snaps-sdk';\nimport type { Json, JsonRpcError } from '@metamask/utils';\nimport { isObject, isJsonRpcError } from '@metamask/utils';\n\nexport const SNAP_ERROR_WRAPPER_CODE = -31001;\nexport const SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';\n\nexport type SerializedSnapErrorWrapper = {\n code: typeof SNAP_ERROR_WRAPPER_CODE;\n message: typeof SNAP_ERROR_WRAPPER_MESSAGE;\n data: {\n cause: Json;\n };\n};\n\nexport class WrappedSnapError extends Error {\n readonly #error: unknown;\n\n readonly #message: string;\n\n readonly #stack?: string;\n\n /**\n * Create a new `WrappedSnapError`.\n *\n * @param error - The error to create the `WrappedSnapError` from.\n */\n constructor(error: unknown) {\n const message = getErrorMessage(error);\n super(message);\n\n this.#error = error;\n this.#message = message;\n this.#stack = getErrorStack(error);\n }\n\n /**\n * The error name.\n *\n * @returns The error name.\n */\n get name() {\n return 'WrappedSnapError';\n }\n\n /**\n * The error message.\n *\n * @returns The error message.\n */\n get message() {\n return this.#message;\n }\n\n /**\n * The error stack.\n *\n * @returns The error stack.\n */\n get stack() {\n return this.#stack;\n }\n\n /**\n * Convert the error to a JSON object.\n *\n * @returns The JSON object.\n */\n toJSON(): SerializedSnapErrorWrapper {\n const cause = isSnapError(this.#error)\n ? this.#error.serialize()\n : serializeCause(this.#error);\n\n return {\n code: SNAP_ERROR_WRAPPER_CODE,\n message: SNAP_ERROR_WRAPPER_MESSAGE,\n data: {\n cause,\n },\n };\n }\n\n /**\n * Serialize the error to a JSON object. This is called by\n * `@metamask/rpc-errors` when serializing the error.\n *\n * @returns The JSON object.\n */\n serialize() {\n return this.toJSON();\n }\n}\n\n/**\n * Check if an object is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSnapError(error: unknown): error is SnapError {\n if (\n isObject(error) &&\n 'serialize' in error &&\n typeof error.serialize === 'function'\n ) {\n const serialized = error.serialize();\n return isJsonRpcError(serialized) && isSerializedSnapError(serialized);\n }\n\n return false;\n}\n\n/**\n * Check if a JSON-RPC error is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSerializedSnapError(\n error: JsonRpcError,\n): error is SerializedSnapError {\n return error.code === SNAP_ERROR_CODE && error.message === SNAP_ERROR_MESSAGE;\n}\n\n/**\n * Check if a JSON-RPC error is a `WrappedSnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `WrappedSnapError`.\n */\nexport function isWrappedSnapError(\n error: unknown,\n): error is SerializedSnapErrorWrapper {\n return (\n isJsonRpcError(error) &&\n error.code === SNAP_ERROR_WRAPPER_CODE &&\n error.message === SNAP_ERROR_WRAPPER_MESSAGE\n );\n}\n\n/**\n * Get a JSON-RPC error with the given code, message, stack, and data.\n *\n * @param code - The error code.\n * @param message - The error message.\n * @param stack - The error stack.\n * @param data - Additional data for the error.\n * @returns The JSON-RPC error.\n */\nfunction getJsonRpcError(\n code: number,\n message: string,\n stack?: string,\n data?: Json,\n) {\n const error = new RpcError(code, message, data);\n error.stack = stack;\n\n return error;\n}\n\n/**\n * Attempt to unwrap an unknown error to a `JsonRpcError`. This function will\n * try to get the error code, message, and data from the error, and return a\n * `JsonRpcError` with those properties.\n *\n * @param error - The error to unwrap.\n * @returns A tuple containing the unwrapped error and a boolean indicating\n * whether the error was handled.\n */\nexport function unwrapError(\n error: unknown,\n): [error: RpcError<DataWithOptionalCause>, isHandled: boolean] {\n // This logic is a bit complicated, but it's necessary to handle all the\n // different types of errors that can be thrown by a Snap.\n\n // If the error is a wrapped Snap error, unwrap it.\n if (isWrappedSnapError(error)) {\n // The wrapped error can be a JSON-RPC error, or an unknown error. If it's\n // a JSON-RPC error, we can unwrap it further.\n if (isJsonRpcError(error.data.cause)) {\n // If the JSON-RPC error is a wrapped Snap error, unwrap it further.\n if (isSerializedSnapError(error.data.cause)) {\n const { code, message, stack, data } = error.data.cause.data.cause;\n return [getJsonRpcError(code, message, stack, data), true];\n }\n\n // Otherwise, we use the original JSON-RPC error.\n const { code, message, stack, data } = error.data.cause;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // Otherwise, we throw an internal error with the wrapped error as the\n // message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error.data.cause),\n getErrorStack(error.data.cause),\n ),\n false,\n ];\n }\n\n // The error can be a non-wrapped JSON-RPC error, in which case we can just\n // re-throw it with the same code, message, and data.\n if (isJsonRpcError(error)) {\n const { code, message, stack, data } = error;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // If the error is not a wrapped error, we don't know how to handle it, so we\n // throw an internal error with the error as the message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error),\n getErrorStack(error),\n ),\n false,\n ];\n}\n"]}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _WrappedSnapError_error, _WrappedSnapError_message, _WrappedSnapError_stack;
|
|
1
13
|
import { errorCodes, JsonRpcError as RpcError, serializeCause } from "@metamask/rpc-errors";
|
|
2
14
|
import { getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE } from "@metamask/snaps-sdk";
|
|
3
15
|
import { isObject, isJsonRpcError } from "@metamask/utils";
|
|
4
16
|
export const SNAP_ERROR_WRAPPER_CODE = -31001;
|
|
5
17
|
export const SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';
|
|
6
18
|
export class WrappedSnapError extends Error {
|
|
7
|
-
#error;
|
|
8
|
-
#message;
|
|
9
|
-
#stack;
|
|
10
19
|
/**
|
|
11
20
|
* Create a new `WrappedSnapError`.
|
|
12
21
|
*
|
|
@@ -15,9 +24,12 @@ export class WrappedSnapError extends Error {
|
|
|
15
24
|
constructor(error) {
|
|
16
25
|
const message = getErrorMessage(error);
|
|
17
26
|
super(message);
|
|
18
|
-
this
|
|
19
|
-
this
|
|
20
|
-
this
|
|
27
|
+
_WrappedSnapError_error.set(this, void 0);
|
|
28
|
+
_WrappedSnapError_message.set(this, void 0);
|
|
29
|
+
_WrappedSnapError_stack.set(this, void 0);
|
|
30
|
+
__classPrivateFieldSet(this, _WrappedSnapError_error, error, "f");
|
|
31
|
+
__classPrivateFieldSet(this, _WrappedSnapError_message, message, "f");
|
|
32
|
+
__classPrivateFieldSet(this, _WrappedSnapError_stack, getErrorStack(error), "f");
|
|
21
33
|
}
|
|
22
34
|
/**
|
|
23
35
|
* The error name.
|
|
@@ -33,7 +45,7 @@ export class WrappedSnapError extends Error {
|
|
|
33
45
|
* @returns The error message.
|
|
34
46
|
*/
|
|
35
47
|
get message() {
|
|
36
|
-
return this
|
|
48
|
+
return __classPrivateFieldGet(this, _WrappedSnapError_message, "f");
|
|
37
49
|
}
|
|
38
50
|
/**
|
|
39
51
|
* The error stack.
|
|
@@ -41,7 +53,7 @@ export class WrappedSnapError extends Error {
|
|
|
41
53
|
* @returns The error stack.
|
|
42
54
|
*/
|
|
43
55
|
get stack() {
|
|
44
|
-
return this
|
|
56
|
+
return __classPrivateFieldGet(this, _WrappedSnapError_stack, "f");
|
|
45
57
|
}
|
|
46
58
|
/**
|
|
47
59
|
* Convert the error to a JSON object.
|
|
@@ -49,9 +61,9 @@ export class WrappedSnapError extends Error {
|
|
|
49
61
|
* @returns The JSON object.
|
|
50
62
|
*/
|
|
51
63
|
toJSON() {
|
|
52
|
-
const cause = isSnapError(this
|
|
53
|
-
? this
|
|
54
|
-
: serializeCause(this
|
|
64
|
+
const cause = isSnapError(__classPrivateFieldGet(this, _WrappedSnapError_error, "f"))
|
|
65
|
+
? __classPrivateFieldGet(this, _WrappedSnapError_error, "f").serialize()
|
|
66
|
+
: serializeCause(__classPrivateFieldGet(this, _WrappedSnapError_error, "f"));
|
|
55
67
|
return {
|
|
56
68
|
code: SNAP_ERROR_WRAPPER_CODE,
|
|
57
69
|
message: SNAP_ERROR_WRAPPER_MESSAGE,
|
|
@@ -70,6 +82,7 @@ export class WrappedSnapError extends Error {
|
|
|
70
82
|
return this.toJSON();
|
|
71
83
|
}
|
|
72
84
|
}
|
|
85
|
+
_WrappedSnapError_error = new WeakMap(), _WrappedSnapError_message = new WeakMap(), _WrappedSnapError_stack = new WeakMap();
|
|
73
86
|
/**
|
|
74
87
|
* Check if an object is a `SnapError`.
|
|
75
88
|
*
|
package/dist/errors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,IAAI,QAAQ,EACxB,cAAc,EACf,6BAA6B;AAG9B,OAAO,EACL,eAAe,EACf,aAAa,EACb,eAAe,EACf,kBAAkB,EACnB,4BAA4B;AAE7B,OAAO,EAAE,QAAQ,EAAE,cAAc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AO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAC7C,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAED,6EAA6E;IAC7E,yDAAyD;IACzD,OAAO;QACL,eAAe,CACb,UAAU,CAAC,GAAG,CAAC,QAAQ,EACvB,eAAe,CAAC,KAAK,CAAC,EACtB,aAAa,CAAC,KAAK,CAAC,CACrB;QACD,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import {\n errorCodes,\n JsonRpcError as RpcError,\n serializeCause,\n} from '@metamask/rpc-errors';\nimport type { DataWithOptionalCause } from '@metamask/rpc-errors';\nimport type { SerializedSnapError, SnapError } from '@metamask/snaps-sdk';\nimport {\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from '@metamask/snaps-sdk';\nimport type { Json, JsonRpcError } from '@metamask/utils';\nimport { isObject, isJsonRpcError } from '@metamask/utils';\n\nexport const SNAP_ERROR_WRAPPER_CODE = -31001;\nexport const SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';\n\nexport type SerializedSnapErrorWrapper = {\n code: typeof SNAP_ERROR_WRAPPER_CODE;\n message: typeof SNAP_ERROR_WRAPPER_MESSAGE;\n data: {\n cause: Json;\n };\n};\n\nexport class WrappedSnapError extends Error {\n readonly #error: unknown;\n\n readonly #message: string;\n\n readonly #stack?: string;\n\n /**\n * Create a new `WrappedSnapError`.\n *\n * @param error - The error to create the `WrappedSnapError` from.\n */\n constructor(error: unknown) {\n const message = getErrorMessage(error);\n super(message);\n\n this.#error = error;\n this.#message = message;\n this.#stack = getErrorStack(error);\n }\n\n /**\n * The error name.\n *\n * @returns The error name.\n */\n get name() {\n return 'WrappedSnapError';\n }\n\n /**\n * The error message.\n *\n * @returns The error message.\n */\n get message() {\n return this.#message;\n }\n\n /**\n * The error stack.\n *\n * @returns The error stack.\n */\n get stack() {\n return this.#stack;\n }\n\n /**\n * Convert the error to a JSON object.\n *\n * @returns The JSON object.\n */\n toJSON(): SerializedSnapErrorWrapper {\n const cause = isSnapError(this.#error)\n ? this.#error.serialize()\n : serializeCause(this.#error);\n\n return {\n code: SNAP_ERROR_WRAPPER_CODE,\n message: SNAP_ERROR_WRAPPER_MESSAGE,\n data: {\n cause,\n },\n };\n }\n\n /**\n * Serialize the error to a JSON object. This is called by\n * `@metamask/rpc-errors` when serializing the error.\n *\n * @returns The JSON object.\n */\n serialize() {\n return this.toJSON();\n }\n}\n\n/**\n * Check if an object is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSnapError(error: unknown): error is SnapError {\n if (\n isObject(error) &&\n 'serialize' in error &&\n typeof error.serialize === 'function'\n ) {\n const serialized = error.serialize();\n return isJsonRpcError(serialized) && isSerializedSnapError(serialized);\n }\n\n return false;\n}\n\n/**\n * Check if a JSON-RPC error is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSerializedSnapError(\n error: JsonRpcError,\n): error is SerializedSnapError {\n return error.code === SNAP_ERROR_CODE && error.message === SNAP_ERROR_MESSAGE;\n}\n\n/**\n * Check if a JSON-RPC error is a `WrappedSnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `WrappedSnapError`.\n */\nexport function isWrappedSnapError(\n error: unknown,\n): error is SerializedSnapErrorWrapper {\n return (\n isJsonRpcError(error) &&\n error.code === SNAP_ERROR_WRAPPER_CODE &&\n error.message === SNAP_ERROR_WRAPPER_MESSAGE\n );\n}\n\n/**\n * Get a JSON-RPC error with the given code, message, stack, and data.\n *\n * @param code - The error code.\n * @param message - The error message.\n * @param stack - The error stack.\n * @param data - Additional data for the error.\n * @returns The JSON-RPC error.\n */\nfunction getJsonRpcError(\n code: number,\n message: string,\n stack?: string,\n data?: Json,\n) {\n const error = new RpcError(code, message, data);\n error.stack = stack;\n\n return error;\n}\n\n/**\n * Attempt to unwrap an unknown error to a `JsonRpcError`. This function will\n * try to get the error code, message, and data from the error, and return a\n * `JsonRpcError` with those properties.\n *\n * @param error - The error to unwrap.\n * @returns A tuple containing the unwrapped error and a boolean indicating\n * whether the error was handled.\n */\nexport function unwrapError(\n error: unknown,\n): [error: RpcError<DataWithOptionalCause>, isHandled: boolean] {\n // This logic is a bit complicated, but it's necessary to handle all the\n // different types of errors that can be thrown by a Snap.\n\n // If the error is a wrapped Snap error, unwrap it.\n if (isWrappedSnapError(error)) {\n // The wrapped error can be a JSON-RPC error, or an unknown error. If it's\n // a JSON-RPC error, we can unwrap it further.\n if (isJsonRpcError(error.data.cause)) {\n // If the JSON-RPC error is a wrapped Snap error, unwrap it further.\n if (isSerializedSnapError(error.data.cause)) {\n const { code, message, stack, data } = error.data.cause.data.cause;\n return [getJsonRpcError(code, message, stack, data), true];\n }\n\n // Otherwise, we use the original JSON-RPC error.\n const { code, message, stack, data } = error.data.cause;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // Otherwise, we throw an internal error with the wrapped error as the\n // message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error.data.cause),\n getErrorStack(error.data.cause),\n ),\n false,\n ];\n }\n\n // The error can be a non-wrapped JSON-RPC error, in which case we can just\n // re-throw it with the same code, message, and data.\n if (isJsonRpcError(error)) {\n const { code, message, stack, data } = error;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // If the error is not a wrapped error, we don't know how to handle it, so we\n // throw an internal error with the error as the message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error),\n getErrorStack(error),\n ),\n false,\n ];\n}\n"]}
|
package/dist/eval.cjs
CHANGED
package/dist/eval.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.cjs","sourceRoot":"","sources":["../src/eval.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,iDA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AAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG;gBACb,MAAM;gBACN,MAAM;aACP,CAAC;YAEF,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;gBACnB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC;YAED,OAAO,MAAM,CACX,IAAI,aAAa,CACf,2CAA2C,QAAQ,GAAG,EACtD,MAAM,CACP,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA1CD,gCA0CC","sourcesContent":["import { assert } from '@metamask/utils';\nimport { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\nexport type EvalOutput = {\n stdout: string;\n stderr: string;\n};\n\nexport class SnapEvalError extends Error {\n readonly output: EvalOutput;\n\n constructor(message: string, output: EvalOutput) {\n super(message);\n\n this.name = 'SnapEvalError';\n this.output = output;\n }\n}\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<EvalOutput> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.cjs'), [bundlePath], {\n // To avoid printing the output of the worker to the console, we set\n // `stdio` to `pipe` and handle the output ourselves.\n stdio: 'pipe',\n });\n\n let stdout = '';\n let stderr = '';\n\n assert(worker.stdout, '`stdout` should be defined.');\n assert(worker.stderr, '`stderr` should be defined.');\n\n worker.stdout.on('data', (data: Buffer) => {\n stdout += data.toString();\n });\n\n worker.stderr.on('data', (data: Buffer) => {\n stderr += data.toString();\n });\n\n worker.on('exit', (exitCode: number) => {\n const output = {\n stdout,\n stderr,\n };\n\n if (exitCode === 0) {\n return resolve(output);\n }\n\n return reject(\n new SnapEvalError(\n `Process exited with non-zero exit code: ${exitCode}.`,\n output,\n ),\n );\n });\n });\n}\n"]}
|
package/dist/eval.mjs
CHANGED
package/dist/eval.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.mjs","sourceRoot":"","sources":["../src/eval.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AACzC,OAAO,EAAE,IAAI,EAAE,sBAAsB;AACrC,OAAO,EAAE,IAAI,EAAE,aAAa;AAE5B,OAAO,EAAE,gBAAgB,EAAE,iBAAa;AAOxC,MAAM,OAAO,aAAc,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"eval.mjs","sourceRoot":"","sources":["../src/eval.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AACzC,OAAO,EAAE,IAAI,EAAE,sBAAsB;AACrC,OAAO,EAAE,IAAI,EAAE,aAAa;AAE5B,OAAO,EAAE,gBAAgB,EAAE,iBAAa;AAOxC,MAAM,OAAO,aAAc,SAAQ,KAAK;IAGtC,YAAY,OAAe,EAAE,MAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAEnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,8BAAY,iBAAiB,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE;YACpE,oEAAoE;YACpE,qDAAqD;YACrD,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QAEH,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;QAErD,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;YACxC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;YACxC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG;gBACb,MAAM;gBACN,MAAM;aACP,CAAC;YAEF,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;gBACnB,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC;YAED,OAAO,MAAM,CACX,IAAI,aAAa,CACf,2CAA2C,QAAQ,GAAG,EACtD,MAAM,CACP,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\nimport { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\nexport type EvalOutput = {\n stdout: string;\n stderr: string;\n};\n\nexport class SnapEvalError extends Error {\n readonly output: EvalOutput;\n\n constructor(message: string, output: EvalOutput) {\n super(message);\n\n this.name = 'SnapEvalError';\n this.output = output;\n }\n}\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<EvalOutput> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.cjs'), [bundlePath], {\n // To avoid printing the output of the worker to the console, we set\n // `stdio` to `pipe` and handle the output ourselves.\n stdio: 'pipe',\n });\n\n let stdout = '';\n let stderr = '';\n\n assert(worker.stdout, '`stdout` should be defined.');\n assert(worker.stderr, '`stderr` should be defined.');\n\n worker.stdout.on('data', (data: Buffer) => {\n stdout += data.toString();\n });\n\n worker.stderr.on('data', (data: Buffer) => {\n stderr += data.toString();\n });\n\n worker.on('exit', (exitCode: number) => {\n const output = {\n stdout,\n stderr,\n };\n\n if (exitCode === 0) {\n return resolve(output);\n }\n\n return reject(\n new SnapEvalError(\n `Process exited with non-zero exit code: ${exitCode}.`,\n output,\n ),\n );\n });\n });\n}\n"]}
|
package/dist/handlers.d.cts
CHANGED
|
@@ -152,6 +152,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
152
152
|
}, "Radio">>;
|
|
153
153
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
154
154
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
155
|
+
size?: "md" | "lg" | undefined;
|
|
155
156
|
}, "Heading">;
|
|
156
157
|
severity?: SeverityLevel | undefined;
|
|
157
158
|
}, {
|
|
@@ -235,6 +236,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
235
236
|
}, "Radio">>;
|
|
236
237
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
237
238
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
239
|
+
size?: "md" | "lg" | undefined;
|
|
238
240
|
}, "Heading">, null>;
|
|
239
241
|
severity: import("@metamask/superstruct").Struct<SeverityLevel | undefined, SeverityLevel>;
|
|
240
242
|
}>;
|
|
@@ -322,6 +324,7 @@ export declare const OnTransactionResponseStruct: import("@metamask/superstruct"
|
|
|
322
324
|
}, "Radio">>;
|
|
323
325
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
324
326
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
327
|
+
size?: "md" | "lg" | undefined;
|
|
325
328
|
}, "Heading">;
|
|
326
329
|
severity?: SeverityLevel | undefined;
|
|
327
330
|
} | null, null>;
|
|
@@ -409,6 +412,7 @@ export declare const OnSignatureResponseStruct: import("@metamask/superstruct").
|
|
|
409
412
|
}, "Radio">>;
|
|
410
413
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
411
414
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
415
|
+
size?: "md" | "lg" | undefined;
|
|
412
416
|
}, "Heading">;
|
|
413
417
|
severity?: SeverityLevel | undefined;
|
|
414
418
|
} | null, null>;
|
|
@@ -493,6 +497,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
493
497
|
}, "Radio">>;
|
|
494
498
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
495
499
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
500
|
+
size?: "md" | "lg" | undefined;
|
|
496
501
|
}, "Heading">;
|
|
497
502
|
}, {
|
|
498
503
|
content: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
@@ -575,6 +580,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
575
580
|
}, "Radio">>;
|
|
576
581
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
577
582
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
583
|
+
size?: "md" | "lg" | undefined;
|
|
578
584
|
}, "Heading">, null>;
|
|
579
585
|
}>;
|
|
580
586
|
export declare const OnHomePageResponseWithIdStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -663,6 +669,7 @@ export declare const OnHomePageResponseStruct: import("@metamask/superstruct").S
|
|
|
663
669
|
}, "Radio">>;
|
|
664
670
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
665
671
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
672
|
+
size?: "md" | "lg" | undefined;
|
|
666
673
|
}, "Heading">;
|
|
667
674
|
} | {
|
|
668
675
|
id: string;
|
package/dist/handlers.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,EAA4B,aAAa,EAAE,4BAA4B;AAa9E,OAAO,KAAK,EAAE,WAAW,EAAE,4BAAwB;AACnD,OAAO,EAAE,WAAW,EAAE,4BAAwB;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,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O,YAAY,CAAC,CAAC,EAAE,eAAe,CAClD,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,CAC3B;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC"}
|
package/dist/handlers.d.mts
CHANGED
|
@@ -152,6 +152,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
152
152
|
}, "Radio">>;
|
|
153
153
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
154
154
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
155
|
+
size?: "md" | "lg" | undefined;
|
|
155
156
|
}, "Heading">;
|
|
156
157
|
severity?: SeverityLevel | undefined;
|
|
157
158
|
}, {
|
|
@@ -235,6 +236,7 @@ export declare const OnTransactionResponseWithContentStruct: import("@metamask/s
|
|
|
235
236
|
}, "Radio">>;
|
|
236
237
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
237
238
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
239
|
+
size?: "md" | "lg" | undefined;
|
|
238
240
|
}, "Heading">, null>;
|
|
239
241
|
severity: import("@metamask/superstruct").Struct<SeverityLevel | undefined, SeverityLevel>;
|
|
240
242
|
}>;
|
|
@@ -322,6 +324,7 @@ export declare const OnTransactionResponseStruct: import("@metamask/superstruct"
|
|
|
322
324
|
}, "Radio">>;
|
|
323
325
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
324
326
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
327
|
+
size?: "md" | "lg" | undefined;
|
|
325
328
|
}, "Heading">;
|
|
326
329
|
severity?: SeverityLevel | undefined;
|
|
327
330
|
} | null, null>;
|
|
@@ -409,6 +412,7 @@ export declare const OnSignatureResponseStruct: import("@metamask/superstruct").
|
|
|
409
412
|
}, "Radio">>;
|
|
410
413
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
411
414
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
415
|
+
size?: "md" | "lg" | undefined;
|
|
412
416
|
}, "Heading">;
|
|
413
417
|
severity?: SeverityLevel | undefined;
|
|
414
418
|
} | null, null>;
|
|
@@ -493,6 +497,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
493
497
|
}, "Radio">>;
|
|
494
498
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
495
499
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
500
|
+
size?: "md" | "lg" | undefined;
|
|
496
501
|
}, "Heading">;
|
|
497
502
|
}, {
|
|
498
503
|
content: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
@@ -575,6 +580,7 @@ export declare const OnHomePageResponseWithContentStruct: import("@metamask/supe
|
|
|
575
580
|
}, "Radio">>;
|
|
576
581
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
577
582
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
583
|
+
size?: "md" | "lg" | undefined;
|
|
578
584
|
}, "Heading">, null>;
|
|
579
585
|
}>;
|
|
580
586
|
export declare const OnHomePageResponseWithIdStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -663,6 +669,7 @@ export declare const OnHomePageResponseStruct: import("@metamask/superstruct").S
|
|
|
663
669
|
}, "Radio">>;
|
|
664
670
|
}, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
|
|
665
671
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
672
|
+
size?: "md" | "lg" | undefined;
|
|
666
673
|
}, "Heading">;
|
|
667
674
|
} | {
|
|
668
675
|
id: string;
|
package/dist/handlers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,EAA4B,aAAa,EAAE,4BAA4B;AAa9E,OAAO,KAAK,EAAE,WAAW,EAAE,4BAAwB;AACnD,OAAO,EAAE,WAAW,EAAE,4BAAwB;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,YAAY;;;;yCAIG,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;;;;yCAOP,OAAO;;CAIzB,CAAC;AAEX,eAAO,MAAM,mCAAmC;;;;EAE9C,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;;;;EAK7C,CAAC;AAEF,eAAO,MAAM,sCAAsC
|
|
1
|
+
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAEjB,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EACnB,4BAA4B;AA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE9C,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;EAEzC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAGnC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;EAGlC,CAAC;AAEH,eAAO,MAAM,sBAAsB;;;;;;;;EAIjC,CAAC;AAEH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;EAE1C,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;EAEzC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;eAEtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,WAAW,IAClD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,KAAK,UAAU,IAAI,MAAM,OAAO,GAC1E,OAAO,GACP,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;KAC/B,GAAG,IAAI,MAAM,OAAO,YAAY,CAAC,CAAC,EAAE,eAAe,CAClD,CAAC,OAAO,YAAY,CAAC,CAAC,GAAG,CAAC,CAC3B;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC"}
|
package/dist/iframe.cjs
CHANGED
|
@@ -6,18 +6,21 @@ exports.createWindow = void 0;
|
|
|
6
6
|
* forever if the iframe never loads, but the promise should be wrapped in
|
|
7
7
|
* an initialization timeout in the SnapController.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
9
|
+
*
|
|
10
|
+
* @param options - The options for createWindow.
|
|
11
|
+
* @param options.uri - The iframe URI.
|
|
12
|
+
* @param options.id - The ID to assign to the iframe.
|
|
13
|
+
* @param options.sandbox - Whether to enable the sandbox attribute.
|
|
14
|
+
* @param options.testId - The data-testid attribute to assign to the iframe.
|
|
12
15
|
* @returns A promise that resolves to the contentWindow of the iframe.
|
|
13
16
|
*/
|
|
14
|
-
async function createWindow(uri, id, sandbox = true) {
|
|
17
|
+
async function createWindow({ uri, id, sandbox = true, testId = 'snaps-iframe', }) {
|
|
15
18
|
return await new Promise((resolve, reject) => {
|
|
16
19
|
const iframe = document.createElement('iframe');
|
|
17
20
|
// The order of operations appears to matter for everything except this
|
|
18
21
|
// attribute. We may as well set it here.
|
|
19
22
|
iframe.setAttribute('id', id);
|
|
20
|
-
iframe.setAttribute('data-testid',
|
|
23
|
+
iframe.setAttribute('data-testid', testId);
|
|
21
24
|
if (sandbox) {
|
|
22
25
|
// For the sandbox property to have any effect it needs to be set before the iframe is appended.
|
|
23
26
|
// We apply this property as a principle of least authority (POLA)
|