@metamask/snaps-controllers 9.12.0 → 9.13.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 +13 -1
- package/dist/interface/SnapInterfaceController.cjs +35 -3
- package/dist/interface/SnapInterfaceController.cjs.map +1 -1
- package/dist/interface/SnapInterfaceController.d.cts +36 -2
- package/dist/interface/SnapInterfaceController.d.cts.map +1 -1
- package/dist/interface/SnapInterfaceController.d.mts +36 -2
- package/dist/interface/SnapInterfaceController.d.mts.map +1 -1
- package/dist/interface/SnapInterfaceController.mjs +36 -4
- package/dist/interface/SnapInterfaceController.mjs.map +1 -1
- package/dist/snaps/SnapController.cjs +3 -2
- package/dist/snaps/SnapController.cjs.map +1 -1
- package/dist/snaps/SnapController.d.cts.map +1 -1
- package/dist/snaps/SnapController.d.mts.map +1 -1
- package/dist/snaps/SnapController.mjs +3 -2
- package/dist/snaps/SnapController.mjs.map +1 -1
- package/dist/snaps/location/http.cjs +4 -14
- package/dist/snaps/location/http.cjs.map +1 -1
- package/dist/snaps/location/http.d.cts.map +1 -1
- package/dist/snaps/location/http.d.mts.map +1 -1
- package/dist/snaps/location/http.mjs +4 -14
- package/dist/snaps/location/http.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -5,12 +5,6 @@ const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
|
5
5
|
const utils_1 = require("@metamask/utils");
|
|
6
6
|
class HttpLocation {
|
|
7
7
|
constructor(url, opts = {}) {
|
|
8
|
-
// We keep contents separate because then we can use only one Blob in cache,
|
|
9
|
-
// which we convert to Uint8Array when actually returning the file.
|
|
10
|
-
//
|
|
11
|
-
// That avoids deepCloning file contents.
|
|
12
|
-
// I imagine ArrayBuffers are copy-on-write optimized, meaning
|
|
13
|
-
// in most often case we'll only have one file contents in common case.
|
|
14
8
|
this.cache = new Map();
|
|
15
9
|
(0, utils_1.assertStruct)(url.toString(), snaps_utils_1.HttpSnapIdStruct, 'Invalid Snap Id: ');
|
|
16
10
|
this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);
|
|
@@ -42,25 +36,21 @@ class HttpLocation {
|
|
|
42
36
|
const relativePath = (0, snaps_utils_1.normalizeRelative)(path);
|
|
43
37
|
const cached = this.cache.get(relativePath);
|
|
44
38
|
if (cached !== undefined) {
|
|
45
|
-
|
|
46
|
-
const value = new Uint8Array(await contents.arrayBuffer());
|
|
47
|
-
const vfile = file.clone();
|
|
48
|
-
vfile.value = value;
|
|
49
|
-
return vfile;
|
|
39
|
+
return cached.clone();
|
|
50
40
|
}
|
|
51
41
|
const canonicalPath = this.toCanonical(relativePath).toString();
|
|
52
42
|
const response = await this.fetchFn(canonicalPath, this.fetchOptions);
|
|
53
43
|
if (!response.ok) {
|
|
54
44
|
throw new Error(`Failed to fetch "${canonicalPath}". Status code: ${response.status}.`);
|
|
55
45
|
}
|
|
46
|
+
const buffer = await response.arrayBuffer();
|
|
56
47
|
const vfile = new snaps_utils_1.VirtualFile({
|
|
57
|
-
value:
|
|
48
|
+
value: new Uint8Array(buffer),
|
|
58
49
|
path: relativePath,
|
|
59
50
|
data: { canonicalPath },
|
|
60
51
|
});
|
|
61
|
-
const blob = await response.blob();
|
|
62
52
|
(0, utils_1.assert)(!this.cache.has(relativePath), 'Corrupted cache, multiple files with same path.');
|
|
63
|
-
this.cache.set(relativePath,
|
|
53
|
+
this.cache.set(relativePath, vfile);
|
|
64
54
|
return this.fetch(relativePath);
|
|
65
55
|
}
|
|
66
56
|
get root() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.cjs","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":";;;AACA,uDAO+B;AAC/B,2CAAuD;AAYvD,MAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"http.cjs","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":";;;AACA,uDAO+B;AAC/B,2CAAuD;AAYvD,MAAa,YAAY;IA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AAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEO,WAAW,CAAC,IAAY;QAC9B,IAAA,cAAM,EAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,+BAA+B,CAAC,CAAC;QAC/D,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AArFD,oCAqFC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n VirtualFile,\n HttpSnapIdStruct,\n NpmSnapFileNames,\n createSnapManifest,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { SnapLocation } from './location';\n\nexport interface HttpOptions {\n /**\n * @default fetch\n */\n fetch?: typeof fetch;\n fetchOptions?: RequestInit;\n}\n\nexport class HttpLocation implements SnapLocation {\n private readonly cache = new Map<string, VirtualFile>();\n\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n private readonly url: URL;\n\n private readonly fetchFn: typeof fetch;\n\n private readonly fetchOptions?: RequestInit;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');\n this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);\n this.fetchOptions = opts.fetchOptions;\n this.url = url;\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()\n const canonicalPath = new URL(\n NpmSnapFileNames.Manifest,\n this.url,\n ).toString();\n\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const contents = await response.text();\n const manifest = parseJson(contents);\n const vfile = new VirtualFile<SnapManifest>({\n value: contents,\n result: createSnapManifest(manifest),\n path: NpmSnapFileNames.Manifest,\n data: { canonicalPath },\n });\n this.validatedManifest = vfile;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n const cached = this.cache.get(relativePath);\n if (cached !== undefined) {\n return cached.clone();\n }\n\n const canonicalPath = this.toCanonical(relativePath).toString();\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const buffer = await response.arrayBuffer();\n const vfile = new VirtualFile({\n value: new Uint8Array(buffer),\n path: relativePath,\n data: { canonicalPath },\n });\n assert(\n !this.cache.has(relativePath),\n 'Corrupted cache, multiple files with same path.',\n );\n this.cache.set(relativePath, vfile);\n\n return this.fetch(relativePath);\n }\n\n get root(): URL {\n return new URL(this.url);\n }\n\n private toCanonical(path: string): URL {\n assert(!path.startsWith('/'), 'Tried to parse absolute path.');\n return new URL(path, this.url);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.cts","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,EACL,WAAW,EAMZ,8BAA8B;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAmB;AAE/C,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED,qBAAa,YAAa,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"http.d.cts","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,EACL,WAAW,EAMZ,8BAA8B;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAmB;AAE/C,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED,qBAAa,YAAa,YAAW,YAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkC;IAExD,OAAO,CAAC,iBAAiB,CAAC,CAA4B;IAEtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAM;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IAEvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAc;gBAEhC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,WAAgB;IAOtC,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IA8B9C,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA6B/C,IAAI,IAAI,IAAI,GAAG,CAEd;IAED,OAAO,CAAC,WAAW;CAIpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.mts","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,EACL,WAAW,EAMZ,8BAA8B;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAmB;AAE/C,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED,qBAAa,YAAa,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"http.d.mts","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAC1D,OAAO,EACL,WAAW,EAMZ,8BAA8B;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAmB;AAE/C,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,YAAY,CAAC,EAAE,WAAW,CAAC;CAC5B;AAED,qBAAa,YAAa,YAAW,YAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAkC;IAExD,OAAO,CAAC,iBAAiB,CAAC,CAA4B;IAEtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAM;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IAEvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAc;gBAEhC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAE,WAAgB;IAOtC,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IA8B9C,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA6B/C,IAAI,IAAI,IAAI,GAAG,CAEd;IAED,OAAO,CAAC,WAAW;CAIpB"}
|
|
@@ -2,12 +2,6 @@ import { VirtualFile, HttpSnapIdStruct, NpmSnapFileNames, createSnapManifest, no
|
|
|
2
2
|
import { assert, assertStruct } from "@metamask/utils";
|
|
3
3
|
export class HttpLocation {
|
|
4
4
|
constructor(url, opts = {}) {
|
|
5
|
-
// We keep contents separate because then we can use only one Blob in cache,
|
|
6
|
-
// which we convert to Uint8Array when actually returning the file.
|
|
7
|
-
//
|
|
8
|
-
// That avoids deepCloning file contents.
|
|
9
|
-
// I imagine ArrayBuffers are copy-on-write optimized, meaning
|
|
10
|
-
// in most often case we'll only have one file contents in common case.
|
|
11
5
|
this.cache = new Map();
|
|
12
6
|
assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');
|
|
13
7
|
this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);
|
|
@@ -39,25 +33,21 @@ export class HttpLocation {
|
|
|
39
33
|
const relativePath = normalizeRelative(path);
|
|
40
34
|
const cached = this.cache.get(relativePath);
|
|
41
35
|
if (cached !== undefined) {
|
|
42
|
-
|
|
43
|
-
const value = new Uint8Array(await contents.arrayBuffer());
|
|
44
|
-
const vfile = file.clone();
|
|
45
|
-
vfile.value = value;
|
|
46
|
-
return vfile;
|
|
36
|
+
return cached.clone();
|
|
47
37
|
}
|
|
48
38
|
const canonicalPath = this.toCanonical(relativePath).toString();
|
|
49
39
|
const response = await this.fetchFn(canonicalPath, this.fetchOptions);
|
|
50
40
|
if (!response.ok) {
|
|
51
41
|
throw new Error(`Failed to fetch "${canonicalPath}". Status code: ${response.status}.`);
|
|
52
42
|
}
|
|
43
|
+
const buffer = await response.arrayBuffer();
|
|
53
44
|
const vfile = new VirtualFile({
|
|
54
|
-
value:
|
|
45
|
+
value: new Uint8Array(buffer),
|
|
55
46
|
path: relativePath,
|
|
56
47
|
data: { canonicalPath },
|
|
57
48
|
});
|
|
58
|
-
const blob = await response.blob();
|
|
59
49
|
assert(!this.cache.has(relativePath), 'Corrupted cache, multiple files with same path.');
|
|
60
|
-
this.cache.set(relativePath,
|
|
50
|
+
this.cache.set(relativePath, vfile);
|
|
61
51
|
return this.fetch(relativePath);
|
|
62
52
|
}
|
|
63
53
|
get root() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.mjs","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EACV,8BAA8B;AAC/B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,wBAAwB;AAYvD,MAAM,OAAO,YAAY;
|
|
1
|
+
{"version":3,"file":"http.mjs","sourceRoot":"","sources":["../../../src/snaps/location/http.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EACV,8BAA8B;AAC/B,OAAO,EAAE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ED,IAAI,IAAI;QACN,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEO,WAAW,CAAC,IAAY;QAC9B,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,+BAA+B,CAAC,CAAC;QAC/D,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n VirtualFile,\n HttpSnapIdStruct,\n NpmSnapFileNames,\n createSnapManifest,\n normalizeRelative,\n parseJson,\n} from '@metamask/snaps-utils';\nimport { assert, assertStruct } from '@metamask/utils';\n\nimport type { SnapLocation } from './location';\n\nexport interface HttpOptions {\n /**\n * @default fetch\n */\n fetch?: typeof fetch;\n fetchOptions?: RequestInit;\n}\n\nexport class HttpLocation implements SnapLocation {\n private readonly cache = new Map<string, VirtualFile>();\n\n private validatedManifest?: VirtualFile<SnapManifest>;\n\n private readonly url: URL;\n\n private readonly fetchFn: typeof fetch;\n\n private readonly fetchOptions?: RequestInit;\n\n constructor(url: URL, opts: HttpOptions = {}) {\n assertStruct(url.toString(), HttpSnapIdStruct, 'Invalid Snap Id: ');\n this.fetchFn = opts.fetch ?? globalThis.fetch.bind(undefined);\n this.fetchOptions = opts.fetchOptions;\n this.url = url;\n }\n\n async manifest(): Promise<VirtualFile<SnapManifest>> {\n if (this.validatedManifest) {\n return this.validatedManifest.clone();\n }\n\n // jest-fetch-mock doesn't handle new URL(), we need to convert .toString()\n const canonicalPath = new URL(\n NpmSnapFileNames.Manifest,\n this.url,\n ).toString();\n\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const contents = await response.text();\n const manifest = parseJson(contents);\n const vfile = new VirtualFile<SnapManifest>({\n value: contents,\n result: createSnapManifest(manifest),\n path: NpmSnapFileNames.Manifest,\n data: { canonicalPath },\n });\n this.validatedManifest = vfile;\n\n return this.manifest();\n }\n\n async fetch(path: string): Promise<VirtualFile> {\n const relativePath = normalizeRelative(path);\n const cached = this.cache.get(relativePath);\n if (cached !== undefined) {\n return cached.clone();\n }\n\n const canonicalPath = this.toCanonical(relativePath).toString();\n const response = await this.fetchFn(canonicalPath, this.fetchOptions);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch \"${canonicalPath}\". Status code: ${response.status}.`,\n );\n }\n const buffer = await response.arrayBuffer();\n const vfile = new VirtualFile({\n value: new Uint8Array(buffer),\n path: relativePath,\n data: { canonicalPath },\n });\n assert(\n !this.cache.has(relativePath),\n 'Corrupted cache, multiple files with same path.',\n );\n this.cache.set(relativePath, vfile);\n\n return this.fetch(relativePath);\n }\n\n get root(): URL {\n return new URL(this.url);\n }\n\n private toCanonical(path: string): URL {\n assert(!path.startsWith('/'), 'Tried to parse absolute path.');\n return new URL(path, this.url);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-controllers",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.13.0",
|
|
4
4
|
"description": "Controllers for MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"@metamask/rpc-errors": "^7.0.1",
|
|
91
91
|
"@metamask/snaps-registry": "^3.2.2",
|
|
92
92
|
"@metamask/snaps-rpc-methods": "^11.5.1",
|
|
93
|
-
"@metamask/snaps-sdk": "^6.
|
|
94
|
-
"@metamask/snaps-utils": "^8.
|
|
93
|
+
"@metamask/snaps-sdk": "^6.11.0",
|
|
94
|
+
"@metamask/snaps-utils": "^8.6.0",
|
|
95
95
|
"@metamask/utils": "^10.0.0",
|
|
96
96
|
"@xstate/fsm": "^2.0.0",
|
|
97
97
|
"browserify-zlib": "^0.2.0",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"@metamask/template-snap": "^0.7.0",
|
|
119
119
|
"@swc/core": "1.3.78",
|
|
120
120
|
"@swc/jest": "^0.2.26",
|
|
121
|
-
"@ts-bridge/cli": "^0.
|
|
121
|
+
"@ts-bridge/cli": "^0.6.0",
|
|
122
122
|
"@types/chrome": "^0.0.237",
|
|
123
123
|
"@types/concat-stream": "^2.0.0",
|
|
124
124
|
"@types/gunzip-maybe": "^1.4.0",
|
|
@@ -167,7 +167,7 @@
|
|
|
167
167
|
"webdriverio": "^8.19.0"
|
|
168
168
|
},
|
|
169
169
|
"peerDependencies": {
|
|
170
|
-
"@metamask/snaps-execution-environments": "^6.
|
|
170
|
+
"@metamask/snaps-execution-environments": "^6.10.0"
|
|
171
171
|
},
|
|
172
172
|
"peerDependenciesMeta": {
|
|
173
173
|
"@metamask/snaps-execution-environments": {
|