@metamask/snaps-controllers 12.2.0 → 12.3.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 +16 -1
- package/dist/cronjob/CronjobController.cjs +13 -4
- package/dist/cronjob/CronjobController.cjs.map +1 -1
- package/dist/cronjob/CronjobController.d.cts.map +1 -1
- package/dist/cronjob/CronjobController.d.mts.map +1 -1
- package/dist/cronjob/CronjobController.mjs +15 -6
- package/dist/cronjob/CronjobController.mjs.map +1 -1
- package/dist/interface/SnapInterfaceController.cjs +15 -1
- package/dist/interface/SnapInterfaceController.cjs.map +1 -1
- package/dist/interface/SnapInterfaceController.d.cts +10 -2
- package/dist/interface/SnapInterfaceController.d.cts.map +1 -1
- package/dist/interface/SnapInterfaceController.d.mts +10 -2
- package/dist/interface/SnapInterfaceController.d.mts.map +1 -1
- package/dist/interface/SnapInterfaceController.mjs +17 -3
- package/dist/interface/SnapInterfaceController.mjs.map +1 -1
- package/dist/interface/utils.cjs +104 -4
- package/dist/interface/utils.cjs.map +1 -1
- package/dist/interface/utils.d.cts +71 -2
- package/dist/interface/utils.d.cts.map +1 -1
- package/dist/interface/utils.d.mts +71 -2
- package/dist/interface/utils.d.mts.map +1 -1
- package/dist/interface/utils.mjs +101 -5
- package/dist/interface/utils.mjs.map +1 -1
- package/dist/services/AbstractExecutionService.cjs +127 -202
- package/dist/services/AbstractExecutionService.cjs.map +1 -1
- package/dist/services/AbstractExecutionService.d.cts +8 -53
- package/dist/services/AbstractExecutionService.d.cts.map +1 -1
- package/dist/services/AbstractExecutionService.d.mts +8 -53
- package/dist/services/AbstractExecutionService.d.mts.map +1 -1
- package/dist/services/AbstractExecutionService.mjs +127 -202
- package/dist/services/AbstractExecutionService.mjs.map +1 -1
- package/dist/services/iframe/IframeExecutionService.cjs +2 -2
- package/dist/services/iframe/IframeExecutionService.cjs.map +1 -1
- package/dist/services/iframe/IframeExecutionService.d.cts +1 -1
- package/dist/services/iframe/IframeExecutionService.d.cts.map +1 -1
- package/dist/services/iframe/IframeExecutionService.d.mts +1 -1
- package/dist/services/iframe/IframeExecutionService.d.mts.map +1 -1
- package/dist/services/iframe/IframeExecutionService.mjs +2 -2
- package/dist/services/iframe/IframeExecutionService.mjs.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.cjs +5 -5
- package/dist/services/offscreen/OffscreenExecutionService.cjs.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.d.cts +4 -4
- package/dist/services/offscreen/OffscreenExecutionService.d.cts.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.d.mts +4 -4
- package/dist/services/offscreen/OffscreenExecutionService.d.mts.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.mjs +5 -5
- package/dist/services/offscreen/OffscreenExecutionService.mjs.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.cjs +6 -6
- package/dist/services/proxy/ProxyExecutionService.cjs.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.d.cts +4 -4
- package/dist/services/proxy/ProxyExecutionService.d.cts.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.d.mts +4 -4
- package/dist/services/proxy/ProxyExecutionService.d.mts.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.mjs +6 -6
- package/dist/services/proxy/ProxyExecutionService.mjs.map +1 -1
- package/dist/services/webview/WebViewExecutionService.cjs +6 -6
- package/dist/services/webview/WebViewExecutionService.cjs.map +1 -1
- package/dist/services/webview/WebViewExecutionService.d.cts +5 -5
- package/dist/services/webview/WebViewExecutionService.d.cts.map +1 -1
- package/dist/services/webview/WebViewExecutionService.d.mts +5 -5
- package/dist/services/webview/WebViewExecutionService.d.mts.map +1 -1
- package/dist/services/webview/WebViewExecutionService.mjs +6 -6
- package/dist/services/webview/WebViewExecutionService.mjs.map +1 -1
- package/dist/snaps/SnapController.cjs +43 -72
- package/dist/snaps/SnapController.cjs.map +1 -1
- package/dist/snaps/SnapController.d.cts +5 -9
- package/dist/snaps/SnapController.d.cts.map +1 -1
- package/dist/snaps/SnapController.d.mts +5 -9
- package/dist/snaps/SnapController.d.mts.map +1 -1
- package/dist/snaps/SnapController.mjs +43 -72
- package/dist/snaps/SnapController.mjs.map +1 -1
- package/dist/snaps/registry/json.cjs +4 -2
- package/dist/snaps/registry/json.cjs.map +1 -1
- package/dist/snaps/registry/json.d.cts.map +1 -1
- package/dist/snaps/registry/json.d.mts.map +1 -1
- package/dist/snaps/registry/json.mjs +4 -2
- package/dist/snaps/registry/json.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/snaps/RequestQueue.cjs +0 -44
- package/dist/snaps/RequestQueue.cjs.map +0 -1
- package/dist/snaps/RequestQueue.d.cts +0 -25
- package/dist/snaps/RequestQueue.d.cts.map +0 -1
- package/dist/snaps/RequestQueue.d.mts +0 -25
- package/dist/snaps/RequestQueue.d.mts.map +0 -1
- package/dist/snaps/RequestQueue.mjs +0 -40
- package/dist/snaps/RequestQueue.mjs.map +0 -1
|
@@ -13,10 +13,10 @@ export class IframeExecutionService extends AbstractExecutionService {
|
|
|
13
13
|
terminateJob(jobWrapper) {
|
|
14
14
|
document.getElementById(jobWrapper.id)?.remove();
|
|
15
15
|
}
|
|
16
|
-
async initEnvStream(
|
|
16
|
+
async initEnvStream(snapId) {
|
|
17
17
|
const iframeWindow = await createWindow({
|
|
18
18
|
uri: this.iframeUrl.toString(),
|
|
19
|
-
id:
|
|
19
|
+
id: snapId,
|
|
20
20
|
});
|
|
21
21
|
const stream = new WindowPostMessageStream({
|
|
22
22
|
name: 'parent',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/iframe/IframeExecutionService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,sCAAsC;AACxE,OAAO,EAAE,YAAY,EAAE,8BAA8B;AAMrD,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAMvE,MAAM,OAAO,sBAAuB,SAAQ,wBAAgC;IAG1E,YAAY,EACV,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EAC+B;QACtC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAES,YAAY,CAAC,UAAoC;QACzD,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACnD,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"IframeExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/iframe/IframeExecutionService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,sCAAsC;AACxE,OAAO,EAAE,YAAY,EAAE,8BAA8B;AAMrD,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAMvE,MAAM,OAAO,sBAAuB,SAAQ,wBAAgC;IAG1E,YAAY,EACV,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EAC+B;QACtC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAES,YAAY,CAAC,UAAoC;QACzD,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACnD,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,MAAc;QAI1C,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC;YACtC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC9B,EAAE,EAAE,MAAM;SACX,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,uBAAuB,CAAC;YACzC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,YAAY,EAAE,YAAY;YAC1B,YAAY,EAAE,GAAG;SAClB,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { WindowPostMessageStream } from '@metamask/post-message-stream';\nimport { createWindow } from '@metamask/snaps-utils';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\n\ntype IframeExecutionEnvironmentServiceArgs = {\n iframeUrl: URL;\n} & ExecutionServiceArgs;\n\nexport class IframeExecutionService extends AbstractExecutionService<Window> {\n public iframeUrl: URL;\n\n constructor({\n iframeUrl,\n messenger,\n setupSnapProvider,\n ...args\n }: IframeExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n this.iframeUrl = iframeUrl;\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<Window>): void {\n document.getElementById(jobWrapper.id)?.remove();\n }\n\n protected async initEnvStream(snapId: string): Promise<{\n worker: Window;\n stream: BasePostMessageStream;\n }> {\n const iframeWindow = await createWindow({\n uri: this.iframeUrl.toString(),\n id: snapId,\n });\n\n const stream = new WindowPostMessageStream({\n name: 'parent',\n target: 'child',\n targetWindow: iframeWindow,\n targetOrigin: '*',\n });\n\n return { worker: iframeWindow, stream };\n }\n}\n"]}
|
|
@@ -41,15 +41,15 @@ class OffscreenExecutionService extends ProxyExecutionService_1.ProxyExecutionSe
|
|
|
41
41
|
__classPrivateFieldSet(this, _OffscreenExecutionService_offscreenPromise, offscreenPromise, "f");
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Create a new stream for the given
|
|
44
|
+
* Create a new stream for the given Snap ID. This will wait for the offscreen
|
|
45
45
|
* environment to be ready before creating the stream.
|
|
46
46
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @returns The stream for the given
|
|
47
|
+
* @param snapId - The Snap ID to create a stream for.
|
|
48
|
+
* @returns The stream for the given Snap ID.
|
|
49
49
|
*/
|
|
50
|
-
async initEnvStream(
|
|
50
|
+
async initEnvStream(snapId) {
|
|
51
51
|
await __classPrivateFieldGet(this, _OffscreenExecutionService_offscreenPromise, "f");
|
|
52
|
-
return await super.initEnvStream(
|
|
52
|
+
return await super.initEnvStream(snapId);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
exports.OffscreenExecutionService = OffscreenExecutionService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OffscreenExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAAgF;AAGhF,8EAAuE;AAMvE,MAAa,yBAA0B,SAAQ,6CAAqB;IAGlE;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACkC;QACzC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,MAAM,EAAE,IAAI,qDAA+B,CAAC;gBAC1C,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;aAChB,CAAC;SACH,CAAC,CAAC;QA3BI,8DAAoC;QA6B3C,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"OffscreenExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAAgF;AAGhF,8EAAuE;AAMvE,MAAa,yBAA0B,SAAQ,6CAAqB;IAGlE;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACkC;QACzC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,MAAM,EAAE,IAAI,qDAA+B,CAAC;gBAC1C,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;aAChB,CAAC;SACH,CAAC,CAAC;QA3BI,8DAAoC;QA6B3C,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,MAAc;QAC1C,MAAM,uBAAA,IAAI,mDAAkB,CAAC;QAE7B,OAAO,MAAM,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF;AA7CD,8DA6CC","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n offscreenPromise: Promise<unknown>;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n readonly #offscreenPromise: Promise<unknown>;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.offscreenPromise - A promise that resolves when the offscreen\n * environment is ready.\n */\n constructor({\n messenger,\n setupSnapProvider,\n offscreenPromise,\n ...args\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.#offscreenPromise = offscreenPromise;\n }\n\n /**\n * Create a new stream for the given Snap ID. This will wait for the offscreen\n * environment to be ready before creating the stream.\n *\n * @param snapId - The Snap ID to create a stream for.\n * @returns The stream for the given Snap ID.\n */\n protected async initEnvStream(snapId: string) {\n await this.#offscreenPromise;\n\n return await super.initEnvStream(snapId);\n }\n}\n"]}
|
|
@@ -18,13 +18,13 @@ export declare class OffscreenExecutionService extends ProxyExecutionService {
|
|
|
18
18
|
*/
|
|
19
19
|
constructor({ messenger, setupSnapProvider, offscreenPromise, ...args }: OffscreenExecutionEnvironmentServiceArgs);
|
|
20
20
|
/**
|
|
21
|
-
* Create a new stream for the given
|
|
21
|
+
* Create a new stream for the given Snap ID. This will wait for the offscreen
|
|
22
22
|
* environment to be ready before creating the stream.
|
|
23
23
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @returns The stream for the given
|
|
24
|
+
* @param snapId - The Snap ID to create a stream for.
|
|
25
|
+
* @returns The stream for the given Snap ID.
|
|
26
26
|
*/
|
|
27
|
-
protected initEnvStream(
|
|
27
|
+
protected initEnvStream(snapId: string): Promise<{
|
|
28
28
|
worker: string;
|
|
29
29
|
stream: import("../index.cjs").ProxyPostMessageStream;
|
|
30
30
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OffscreenExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wCAAoC;AACxE,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAEvE,KAAK,wCAAwC,GAAG;IAC9C,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACpC,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,yBAA0B,SAAQ,qBAAqB;;IAGlE;;;;;;;;;;OAUG;gBACS,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAc3C;;;;;;OAMG;cACa,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"OffscreenExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wCAAoC;AACxE,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAEvE,KAAK,wCAAwC,GAAG;IAC9C,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACpC,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,yBAA0B,SAAQ,qBAAqB;;IAGlE;;;;;;;;;;OAUG;gBACS,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAc3C;;;;;;OAMG;cACa,aAAa,CAAC,MAAM,EAAE,MAAM;;;;CAK7C"}
|
|
@@ -18,13 +18,13 @@ export declare class OffscreenExecutionService extends ProxyExecutionService {
|
|
|
18
18
|
*/
|
|
19
19
|
constructor({ messenger, setupSnapProvider, offscreenPromise, ...args }: OffscreenExecutionEnvironmentServiceArgs);
|
|
20
20
|
/**
|
|
21
|
-
* Create a new stream for the given
|
|
21
|
+
* Create a new stream for the given Snap ID. This will wait for the offscreen
|
|
22
22
|
* environment to be ready before creating the stream.
|
|
23
23
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @returns The stream for the given
|
|
24
|
+
* @param snapId - The Snap ID to create a stream for.
|
|
25
|
+
* @returns The stream for the given Snap ID.
|
|
26
26
|
*/
|
|
27
|
-
protected initEnvStream(
|
|
27
|
+
protected initEnvStream(snapId: string): Promise<{
|
|
28
28
|
worker: string;
|
|
29
29
|
stream: import("../index.mjs").ProxyPostMessageStream;
|
|
30
30
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OffscreenExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wCAAoC;AACxE,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAEvE,KAAK,wCAAwC,GAAG;IAC9C,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACpC,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,yBAA0B,SAAQ,qBAAqB;;IAGlE;;;;;;;;;;OAUG;gBACS,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAc3C;;;;;;OAMG;cACa,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"OffscreenExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,wCAAoC;AACxE,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAEvE,KAAK,wCAAwC,GAAG;IAC9C,gBAAgB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CACpC,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,yBAA0B,SAAQ,qBAAqB;;IAGlE;;;;;;;;;;OAUG;gBACS,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACR,EAAE,wCAAwC;IAc3C;;;;;;OAMG;cACa,aAAa,CAAC,MAAM,EAAE,MAAM;;;;CAK7C"}
|
|
@@ -38,15 +38,15 @@ export class OffscreenExecutionService extends ProxyExecutionService {
|
|
|
38
38
|
__classPrivateFieldSet(this, _OffscreenExecutionService_offscreenPromise, offscreenPromise, "f");
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
* Create a new stream for the given
|
|
41
|
+
* Create a new stream for the given Snap ID. This will wait for the offscreen
|
|
42
42
|
* environment to be ready before creating the stream.
|
|
43
43
|
*
|
|
44
|
-
* @param
|
|
45
|
-
* @returns The stream for the given
|
|
44
|
+
* @param snapId - The Snap ID to create a stream for.
|
|
45
|
+
* @returns The stream for the given Snap ID.
|
|
46
46
|
*/
|
|
47
|
-
async initEnvStream(
|
|
47
|
+
async initEnvStream(snapId) {
|
|
48
48
|
await __classPrivateFieldGet(this, _OffscreenExecutionService_offscreenPromise, "f");
|
|
49
|
-
return await super.initEnvStream(
|
|
49
|
+
return await super.initEnvStream(snapId);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
_OffscreenExecutionService_offscreenPromise = new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OffscreenExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,+BAA+B,EAAE,sCAAsC;AAGhF,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAMvE,MAAM,OAAO,yBAA0B,SAAQ,qBAAqB;IAGlE;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACkC;QACzC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,MAAM,EAAE,IAAI,+BAA+B,CAAC;gBAC1C,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;aAChB,CAAC;SACH,CAAC,CAAC;QA3BI,8DAAoC;QA6B3C,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"OffscreenExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,+BAA+B,EAAE,sCAAsC;AAGhF,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAMvE,MAAM,OAAO,yBAA0B,SAAQ,qBAAqB;IAGlE;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,GAAG,IAAI,EACkC;QACzC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,MAAM,EAAE,IAAI,+BAA+B,CAAC;gBAC1C,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,OAAO;aAChB,CAAC;SACH,CAAC,CAAC;QA3BI,8DAAoC;QA6B3C,uBAAA,IAAI,+CAAqB,gBAAgB,MAAA,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,MAAc;QAC1C,MAAM,uBAAA,IAAI,mDAAkB,CAAC;QAE7B,OAAO,MAAM,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n offscreenPromise: Promise<unknown>;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n readonly #offscreenPromise: Promise<unknown>;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.offscreenPromise - A promise that resolves when the offscreen\n * environment is ready.\n */\n constructor({\n messenger,\n setupSnapProvider,\n offscreenPromise,\n ...args\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.#offscreenPromise = offscreenPromise;\n }\n\n /**\n * Create a new stream for the given Snap ID. This will wait for the offscreen\n * environment to be ready before creating the stream.\n *\n * @param snapId - The Snap ID to create a stream for.\n * @returns The stream for the given Snap ID.\n */\n protected async initEnvStream(snapId: string) {\n await this.#offscreenPromise;\n\n return await super.initEnvStream(snapId);\n }\n}\n"]}
|
|
@@ -59,16 +59,16 @@ class ProxyExecutionService extends AbstractExecutionService_1.AbstractExecution
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Create a new stream for the specified
|
|
63
|
-
* in a stream specific to the
|
|
62
|
+
* Create a new stream for the specified Snap. This wraps the root stream
|
|
63
|
+
* in a stream specific to the Snap.
|
|
64
64
|
*
|
|
65
|
-
* @param
|
|
65
|
+
* @param snapId - The Snap ID.
|
|
66
66
|
* @returns An object with the worker ID and stream.
|
|
67
67
|
*/
|
|
68
|
-
async initEnvStream(
|
|
68
|
+
async initEnvStream(snapId) {
|
|
69
69
|
const stream = new ProxyPostMessageStream_1.ProxyPostMessageStream({
|
|
70
70
|
stream: __classPrivateFieldGet(this, _ProxyExecutionService_stream, "f"),
|
|
71
|
-
jobId,
|
|
71
|
+
jobId: snapId,
|
|
72
72
|
});
|
|
73
73
|
// Send a request and await any response before continuing
|
|
74
74
|
// This simulates the behaviour of non-proxy environments by effectively awaiting
|
|
@@ -81,7 +81,7 @@ class ProxyExecutionService extends AbstractExecutionService_1.AbstractExecution
|
|
|
81
81
|
data: { jsonrpc: '2.0', method: 'ping', id: (0, nanoid_1.nanoid)() },
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
|
-
return { worker:
|
|
84
|
+
return { worker: snapId, stream };
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
exports.ProxyExecutionService = ProxyExecutionService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mCAAgC;AAMhC,8EAAuE;AACvE,0EAAmE;AAMnE,MAAa,qBAAsB,SAAQ,mDAAgC;IAGzE;;;;;;;;;;OAUG;IACH,YAAY,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EAC8B;QACrC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAxBI,gDAA+B;QA0BtC,uBAAA,IAAI,iCAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,wEAAwE;IACxE,WAAW;IACX,kEAAkE;IACxD,KAAK,CAAC,YAAY,CAAC,GAA6B;QACxD,0EAA0E;QAC1E,8CAA8C;QAC9C,uBAAA,IAAI,qCAAQ,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,cAAc;gBACtB,EAAE,EAAE,IAAA,eAAM,GAAE;aACb;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"ProxyExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mCAAgC;AAMhC,8EAAuE;AACvE,0EAAmE;AAMnE,MAAa,qBAAsB,SAAQ,mDAAgC;IAGzE;;;;;;;;;;OAUG;IACH,YAAY,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EAC8B;QACrC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAxBI,gDAA+B;QA0BtC,uBAAA,IAAI,iCAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,wEAAwE;IACxE,WAAW;IACX,kEAAkE;IACxD,KAAK,CAAC,YAAY,CAAC,GAA6B;QACxD,0EAA0E;QAC1E,8CAA8C;QAC9C,uBAAA,IAAI,qCAAQ,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,cAAc;gBACtB,EAAE,EAAE,IAAA,eAAM,GAAE;aACb;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,MAAc;QAC1C,MAAM,MAAM,GAAG,IAAI,+CAAsB,CAAC;YACxC,MAAM,EAAE,uBAAA,IAAI,qCAAQ;YACpB,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QAEH,0DAA0D;QAC1D,iFAAiF;QACjF,2DAA2D;QAC3D,sFAAsF;QACtF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC7B,MAAM,CAAC,KAAK,CAAC;gBACX,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,IAAA,eAAM,GAAE,EAAE;aACvD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;CACF;AA9ED,sDA8EC","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype ProxyExecutionEnvironmentServiceArgs = {\n stream: BasePostMessageStream;\n} & ExecutionServiceArgs;\n\nexport class ProxyExecutionService extends AbstractExecutionService<string> {\n readonly #stream: BasePostMessageStream;\n\n /**\n * Create a new proxy execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.stream - The stream to use for communicating with the proxy\n * executor.\n */\n constructor({\n stream,\n messenger,\n setupSnapProvider,\n ...args\n }: ProxyExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n usePing: false,\n });\n\n this.#stream = stream;\n }\n\n /**\n * Send a termination command to the proxy stream.\n *\n * @param job - The job to terminate.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n this.#stream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified Snap. This wraps the root stream\n * in a stream specific to the Snap.\n *\n * @param snapId - The Snap ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(snapId: string) {\n const stream = new ProxyPostMessageStream({\n stream: this.#stream,\n jobId: snapId,\n });\n\n // Send a request and await any response before continuing\n // This simulates the behaviour of non-proxy environments by effectively awaiting\n // the load of the environment inside the proxy environment\n // This assumes the proxy environment is already loaded before this function is called\n await new Promise((resolve) => {\n stream.once('data', resolve);\n stream.write({\n name: 'command',\n data: { jsonrpc: '2.0', method: 'ping', id: nanoid() },\n });\n });\n\n return { worker: snapId, stream };\n }\n}\n"]}
|
|
@@ -26,13 +26,13 @@ export declare class ProxyExecutionService extends AbstractExecutionService<stri
|
|
|
26
26
|
*/
|
|
27
27
|
protected terminateJob(job: TerminateJobArgs<string>): Promise<void>;
|
|
28
28
|
/**
|
|
29
|
-
* Create a new stream for the specified
|
|
30
|
-
* in a stream specific to the
|
|
29
|
+
* Create a new stream for the specified Snap. This wraps the root stream
|
|
30
|
+
* in a stream specific to the Snap.
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
32
|
+
* @param snapId - The Snap ID.
|
|
33
33
|
* @returns An object with the worker ID and stream.
|
|
34
34
|
*/
|
|
35
|
-
protected initEnvStream(
|
|
35
|
+
protected initEnvStream(snapId: string): Promise<{
|
|
36
36
|
worker: string;
|
|
37
37
|
stream: ProxyPostMessageStream;
|
|
38
38
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"ProxyExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,MAAM,EAAE,MAAM;;;;CAoB7C"}
|
|
@@ -26,13 +26,13 @@ export declare class ProxyExecutionService extends AbstractExecutionService<stri
|
|
|
26
26
|
*/
|
|
27
27
|
protected terminateJob(job: TerminateJobArgs<string>): Promise<void>;
|
|
28
28
|
/**
|
|
29
|
-
* Create a new stream for the specified
|
|
30
|
-
* in a stream specific to the
|
|
29
|
+
* Create a new stream for the specified Snap. This wraps the root stream
|
|
30
|
+
* in a stream specific to the Snap.
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
32
|
+
* @param snapId - The Snap ID.
|
|
33
33
|
* @returns An object with the worker ID and stream.
|
|
34
34
|
*/
|
|
35
|
-
protected initEnvStream(
|
|
35
|
+
protected initEnvStream(snapId: string): Promise<{
|
|
36
36
|
worker: string;
|
|
37
37
|
stream: ProxyPostMessageStream;
|
|
38
38
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"ProxyExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sCAAsC;AAG3E,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AACrC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAEnE,KAAK,oCAAoC,GAAG;IAC1C,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GAAG,oBAAoB,CAAC;AAEzB,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,MAAM,CAAC;;IAGzE;;;;;;;;;;OAUG;gBACS,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EACR,EAAE,oCAAoC;IAWvC;;;;OAIG;cAIa,YAAY,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;IAa1D;;;;;;OAMG;cACa,aAAa,CAAC,MAAM,EAAE,MAAM;;;;CAoB7C"}
|
|
@@ -56,16 +56,16 @@ export class ProxyExecutionService extends AbstractExecutionService {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Create a new stream for the specified
|
|
60
|
-
* in a stream specific to the
|
|
59
|
+
* Create a new stream for the specified Snap. This wraps the root stream
|
|
60
|
+
* in a stream specific to the Snap.
|
|
61
61
|
*
|
|
62
|
-
* @param
|
|
62
|
+
* @param snapId - The Snap ID.
|
|
63
63
|
* @returns An object with the worker ID and stream.
|
|
64
64
|
*/
|
|
65
|
-
async initEnvStream(
|
|
65
|
+
async initEnvStream(snapId) {
|
|
66
66
|
const stream = new ProxyPostMessageStream({
|
|
67
67
|
stream: __classPrivateFieldGet(this, _ProxyExecutionService_stream, "f"),
|
|
68
|
-
jobId,
|
|
68
|
+
jobId: snapId,
|
|
69
69
|
});
|
|
70
70
|
// Send a request and await any response before continuing
|
|
71
71
|
// This simulates the behaviour of non-proxy environments by effectively awaiting
|
|
@@ -78,7 +78,7 @@ export class ProxyExecutionService extends AbstractExecutionService {
|
|
|
78
78
|
data: { jsonrpc: '2.0', method: 'ping', id: nanoid() },
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
|
-
return { worker:
|
|
81
|
+
return { worker: snapId, stream };
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
_ProxyExecutionService_stream = new WeakMap();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,eAAe;AAMhC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAMnE,MAAM,OAAO,qBAAsB,SAAQ,wBAAgC;IAGzE;;;;;;;;;;OAUG;IACH,YAAY,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EAC8B;QACrC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAxBI,gDAA+B;QA0BtC,uBAAA,IAAI,iCAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,wEAAwE;IACxE,WAAW;IACX,kEAAkE;IACxD,KAAK,CAAC,YAAY,CAAC,GAA6B;QACxD,0EAA0E;QAC1E,8CAA8C;QAC9C,uBAAA,IAAI,qCAAQ,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,cAAc;gBACtB,EAAE,EAAE,MAAM,EAAE;aACb;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"ProxyExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/proxy/ProxyExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,eAAe;AAMhC,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,sBAAsB,EAAE,sCAAkC;AAMnE,MAAM,OAAO,qBAAsB,SAAQ,wBAAgC;IAGzE;;;;;;;;;;OAUG;IACH,YAAY,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,GAAG,IAAI,EAC8B;QACrC,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;YACjB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAxBI,gDAA+B;QA0BtC,uBAAA,IAAI,iCAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,wEAAwE;IACxE,WAAW;IACX,kEAAkE;IACxD,KAAK,CAAC,YAAY,CAAC,GAA6B;QACxD,0EAA0E;QAC1E,8CAA8C;QAC9C,uBAAA,IAAI,qCAAQ,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,GAAG,CAAC,EAAE;YACb,IAAI,EAAE;gBACJ,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,cAAc;gBACtB,EAAE,EAAE,MAAM,EAAE;aACb;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,MAAc;QAC1C,MAAM,MAAM,GAAG,IAAI,sBAAsB,CAAC;YACxC,MAAM,EAAE,uBAAA,IAAI,qCAAQ;YACpB,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QAEH,0DAA0D;QAC1D,iFAAiF;QACjF,2DAA2D;QAC3D,sFAAsF;QACtF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC7B,MAAM,CAAC,KAAK,CAAC;gBACX,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE;aACvD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;CACF","sourcesContent":["import type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport { nanoid } from 'nanoid';\n\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport { ProxyPostMessageStream } from '../ProxyPostMessageStream';\n\ntype ProxyExecutionEnvironmentServiceArgs = {\n stream: BasePostMessageStream;\n} & ExecutionServiceArgs;\n\nexport class ProxyExecutionService extends AbstractExecutionService<string> {\n readonly #stream: BasePostMessageStream;\n\n /**\n * Create a new proxy execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.stream - The stream to use for communicating with the proxy\n * executor.\n */\n constructor({\n stream,\n messenger,\n setupSnapProvider,\n ...args\n }: ProxyExecutionEnvironmentServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n usePing: false,\n });\n\n this.#stream = stream;\n }\n\n /**\n * Send a termination command to the proxy stream.\n *\n * @param job - The job to terminate.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n protected async terminateJob(job: TerminateJobArgs<string>) {\n // The `AbstractExecutionService` will have already closed the job stream,\n // so we write to the runtime stream directly.\n this.#stream.write({\n jobId: job.id,\n data: {\n jsonrpc: '2.0',\n method: 'terminateJob',\n id: nanoid(),\n },\n });\n }\n\n /**\n * Create a new stream for the specified Snap. This wraps the root stream\n * in a stream specific to the Snap.\n *\n * @param snapId - The Snap ID.\n * @returns An object with the worker ID and stream.\n */\n protected async initEnvStream(snapId: string) {\n const stream = new ProxyPostMessageStream({\n stream: this.#stream,\n jobId: snapId,\n });\n\n // Send a request and await any response before continuing\n // This simulates the behaviour of non-proxy environments by effectively awaiting\n // the load of the environment inside the proxy environment\n // This assumes the proxy environment is already loaded before this function is called\n await new Promise((resolve) => {\n stream.once('data', resolve);\n stream.write({\n name: 'command',\n data: { jsonrpc: '2.0', method: 'ping', id: nanoid() },\n });\n });\n\n return { worker: snapId, stream };\n }\n}\n"]}
|
|
@@ -28,14 +28,14 @@ class WebViewExecutionService extends AbstractExecutionService_1.AbstractExecuti
|
|
|
28
28
|
__classPrivateFieldSet(this, _WebViewExecutionService_removeWebView, removeWebView, "f");
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Create a new stream for the specified
|
|
32
|
-
* in a stream specific to the
|
|
31
|
+
* Create a new stream for the specified Snap. This wraps the runtime stream
|
|
32
|
+
* in a stream specific to the Snap.
|
|
33
33
|
*
|
|
34
|
-
* @param
|
|
35
|
-
* @returns An object with the
|
|
34
|
+
* @param snapId - The Snap ID.
|
|
35
|
+
* @returns An object with the webview and stream.
|
|
36
36
|
*/
|
|
37
|
-
async initEnvStream(
|
|
38
|
-
const webView = await __classPrivateFieldGet(this, _WebViewExecutionService_createWebView, "f").call(this,
|
|
37
|
+
async initEnvStream(snapId) {
|
|
38
|
+
const webView = await __classPrivateFieldGet(this, _WebViewExecutionService_createWebView, "f").call(this, snapId);
|
|
39
39
|
const stream = new WebViewMessageStream_1.WebViewMessageStream({
|
|
40
40
|
name: 'parent',
|
|
41
41
|
target: 'child',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,qEAA8D;AAC9D,8EAAuE;AAWvE,MAAa,uBAAwB,SAAQ,mDAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"WebViewExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,qEAA8D;AAC9D,8EAAuE;AAWvE,MAAa,uBAAwB,SAAQ,mDAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,MAAc;QAC1C,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,MAAM,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,IAAI,2CAAoB,CAAC;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;IAES,YAAY,CAAC,UAA8C;QACnE,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AA3CD,0DA2CC","sourcesContent":["import type { WebViewInterface } from './WebViewMessageStream';\nimport { WebViewMessageStream } from './WebViewMessageStream';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\n\nexport type WebViewExecutionServiceArgs = ExecutionServiceArgs & {\n createWebView: (jobId: string) => Promise<WebViewInterface>;\n removeWebView: (jobId: string) => void;\n};\n\nexport class WebViewExecutionService extends AbstractExecutionService<WebViewInterface> {\n readonly #createWebView;\n\n readonly #removeWebView;\n\n constructor({\n messenger,\n setupSnapProvider,\n createWebView,\n removeWebView,\n ...args\n }: WebViewExecutionServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n this.#createWebView = createWebView;\n this.#removeWebView = removeWebView;\n }\n\n /**\n * Create a new stream for the specified Snap. This wraps the runtime stream\n * in a stream specific to the Snap.\n *\n * @param snapId - The Snap ID.\n * @returns An object with the webview and stream.\n */\n protected async initEnvStream(snapId: string) {\n const webView = await this.#createWebView(snapId);\n\n const stream = new WebViewMessageStream({\n name: 'parent',\n target: 'child',\n webView,\n });\n\n return { worker: webView, stream };\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<WebViewInterface>): void {\n this.#removeWebView(jobWrapper.id);\n }\n}\n"]}
|
|
@@ -10,13 +10,13 @@ export declare class WebViewExecutionService extends AbstractExecutionService<We
|
|
|
10
10
|
#private;
|
|
11
11
|
constructor({ messenger, setupSnapProvider, createWebView, removeWebView, ...args }: WebViewExecutionServiceArgs);
|
|
12
12
|
/**
|
|
13
|
-
* Create a new stream for the specified
|
|
14
|
-
* in a stream specific to the
|
|
13
|
+
* Create a new stream for the specified Snap. This wraps the runtime stream
|
|
14
|
+
* in a stream specific to the Snap.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @returns An object with the
|
|
16
|
+
* @param snapId - The Snap ID.
|
|
17
|
+
* @returns An object with the webview and stream.
|
|
18
18
|
*/
|
|
19
|
-
protected initEnvStream(
|
|
19
|
+
protected initEnvStream(snapId: string): Promise<{
|
|
20
20
|
worker: WebViewInterface;
|
|
21
21
|
stream: WebViewMessageStream;
|
|
22
22
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AAErC,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"WebViewExecutionService.d.cts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AAErC,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,MAAM,EAAE,MAAM;;;;IAY5C,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,IAAI;CAG7E"}
|
|
@@ -10,13 +10,13 @@ export declare class WebViewExecutionService extends AbstractExecutionService<We
|
|
|
10
10
|
#private;
|
|
11
11
|
constructor({ messenger, setupSnapProvider, createWebView, removeWebView, ...args }: WebViewExecutionServiceArgs);
|
|
12
12
|
/**
|
|
13
|
-
* Create a new stream for the specified
|
|
14
|
-
* in a stream specific to the
|
|
13
|
+
* Create a new stream for the specified Snap. This wraps the runtime stream
|
|
14
|
+
* in a stream specific to the Snap.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @returns An object with the
|
|
16
|
+
* @param snapId - The Snap ID.
|
|
17
|
+
* @returns An object with the webview and stream.
|
|
18
18
|
*/
|
|
19
|
-
protected initEnvStream(
|
|
19
|
+
protected initEnvStream(snapId: string): Promise<{
|
|
20
20
|
worker: WebViewInterface;
|
|
21
21
|
stream: WebViewMessageStream;
|
|
22
22
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AAErC,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"WebViewExecutionService.d.mts","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mCAA+B;AAC/D,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,wCAAoC;AAErC,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAEF,qBAAa,uBAAwB,SAAQ,wBAAwB,CAAC,gBAAgB,CAAC;;gBAKzE,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACR,EAAE,2BAA2B;IAU9B;;;;;;OAMG;cACa,aAAa,CAAC,MAAM,EAAE,MAAM;;;;IAY5C,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,IAAI;CAG7E"}
|
|
@@ -25,14 +25,14 @@ export class WebViewExecutionService extends AbstractExecutionService {
|
|
|
25
25
|
__classPrivateFieldSet(this, _WebViewExecutionService_removeWebView, removeWebView, "f");
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Create a new stream for the specified
|
|
29
|
-
* in a stream specific to the
|
|
28
|
+
* Create a new stream for the specified Snap. This wraps the runtime stream
|
|
29
|
+
* in a stream specific to the Snap.
|
|
30
30
|
*
|
|
31
|
-
* @param
|
|
32
|
-
* @returns An object with the
|
|
31
|
+
* @param snapId - The Snap ID.
|
|
32
|
+
* @returns An object with the webview and stream.
|
|
33
33
|
*/
|
|
34
|
-
async initEnvStream(
|
|
35
|
-
const webView = await __classPrivateFieldGet(this, _WebViewExecutionService_createWebView, "f").call(this,
|
|
34
|
+
async initEnvStream(snapId) {
|
|
35
|
+
const webView = await __classPrivateFieldGet(this, _WebViewExecutionService_createWebView, "f").call(this, snapId);
|
|
36
36
|
const stream = new WebViewMessageStream({
|
|
37
37
|
name: 'parent',
|
|
38
38
|
target: 'child',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebViewExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAWvE,MAAM,OAAO,uBAAwB,SAAQ,wBAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"WebViewExecutionService.mjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,oBAAoB,EAAE,mCAA+B;AAC9D,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAWvE,MAAM,OAAO,uBAAwB,SAAQ,wBAA0C;IAKrF,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QAfI,yDAAe;QAEf,yDAAe;QActB,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;QACpC,uBAAA,IAAI,0CAAkB,aAAa,MAAA,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,MAAc;QAC1C,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,MAAM,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,IAAI,oBAAoB,CAAC;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;IAES,YAAY,CAAC,UAA8C;QACnE,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF","sourcesContent":["import type { WebViewInterface } from './WebViewMessageStream';\nimport { WebViewMessageStream } from './WebViewMessageStream';\nimport { AbstractExecutionService } from '../AbstractExecutionService';\nimport type {\n ExecutionServiceArgs,\n TerminateJobArgs,\n} from '../AbstractExecutionService';\n\nexport type WebViewExecutionServiceArgs = ExecutionServiceArgs & {\n createWebView: (jobId: string) => Promise<WebViewInterface>;\n removeWebView: (jobId: string) => void;\n};\n\nexport class WebViewExecutionService extends AbstractExecutionService<WebViewInterface> {\n readonly #createWebView;\n\n readonly #removeWebView;\n\n constructor({\n messenger,\n setupSnapProvider,\n createWebView,\n removeWebView,\n ...args\n }: WebViewExecutionServiceArgs) {\n super({\n ...args,\n messenger,\n setupSnapProvider,\n });\n this.#createWebView = createWebView;\n this.#removeWebView = removeWebView;\n }\n\n /**\n * Create a new stream for the specified Snap. This wraps the runtime stream\n * in a stream specific to the Snap.\n *\n * @param snapId - The Snap ID.\n * @returns An object with the webview and stream.\n */\n protected async initEnvStream(snapId: string) {\n const webView = await this.#createWebView(snapId);\n\n const stream = new WebViewMessageStream({\n name: 'parent',\n target: 'child',\n webView,\n });\n\n return { worker: webView, stream };\n }\n\n protected terminateJob(jobWrapper: TerminateJobArgs<WebViewInterface>): void {\n this.#removeWebView(jobWrapper.id);\n }\n}\n"]}
|