@ignite-ember/extension-bridge 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +303 -2
- package/dist/bridge.d.ts +33 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +92 -0
- package/dist/bridge.js.map +1 -0
- package/dist/channel.d.ts +26 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +36 -0
- package/dist/channel.js.map +1 -0
- package/dist/contract.d.ts +110 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +9 -0
- package/dist/contract.js.map +1 -0
- package/dist/correlator.d.ts +37 -0
- package/dist/correlator.d.ts.map +1 -0
- package/dist/correlator.js +67 -0
- package/dist/correlator.js.map +1 -0
- package/dist/guestBridge.d.ts +63 -0
- package/dist/guestBridge.d.ts.map +1 -0
- package/dist/guestBridge.js +156 -0
- package/dist/guestBridge.js.map +1 -0
- package/dist/hostModel.d.ts +155 -0
- package/dist/hostModel.d.ts.map +1 -0
- package/dist/hostModel.generated.d.ts +1870 -0
- package/dist/hostModel.generated.d.ts.map +1 -0
- package/dist/hostModel.generated.js +1241 -0
- package/dist/hostModel.generated.js.map +1 -0
- package/dist/hostModel.js +168 -0
- package/dist/hostModel.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +338 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +135 -0
- package/dist/protocol.js.map +1 -0
- package/dist/service.d.ts +143 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +179 -0
- package/dist/service.js.map +1 -0
- package/dist/signals.d.ts +21 -0
- package/dist/signals.d.ts.map +1 -0
- package/dist/signals.js +52 -0
- package/dist/signals.js.map +1 -0
- package/dist/tokens.d.ts +95 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +158 -0
- package/dist/tokens.js.map +1 -0
- package/dist/watchers.d.ts +12 -0
- package/dist/watchers.d.ts.map +1 -0
- package/dist/watchers.js +18 -0
- package/dist/watchers.js.map +1 -0
- package/package.json +53 -4
- package/src/bridge.ts +112 -0
- package/src/channel.ts +48 -0
- package/src/contract.ts +130 -0
- package/src/correlator.ts +81 -0
- package/src/guestBridge.ts +261 -0
- package/src/hostModel.generated.ts +2649 -0
- package/src/hostModel.ts +209 -0
- package/src/index.ts +11 -0
- package/src/protocol.ts +475 -0
- package/src/service.ts +253 -0
- package/src/signals.ts +65 -0
- package/src/tokens.ts +165 -0
- package/src/watchers.ts +18 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The guest's line to the window it is framed in: who that window is,
|
|
3
|
+
* and the nonce every message to it must carry.
|
|
4
|
+
*/
|
|
5
|
+
import { type GuestMessage } from "./protocol.js";
|
|
6
|
+
/** A guest message without the envelope `HostChannel` adds. */
|
|
7
|
+
export type GuestBody = {
|
|
8
|
+
[K in GuestMessage["kind"]]: Omit<Extract<GuestMessage, {
|
|
9
|
+
kind: K;
|
|
10
|
+
}>, "igni" | "nonce">;
|
|
11
|
+
}[GuestMessage["kind"]];
|
|
12
|
+
export declare class HostChannel {
|
|
13
|
+
private readonly host;
|
|
14
|
+
private readonly nonce;
|
|
15
|
+
constructor(host: Window, nonce: string);
|
|
16
|
+
/**
|
|
17
|
+
* Did this event come from the host? The host is the only window that
|
|
18
|
+
* can reach this frame's parent slot, so the source is the check that
|
|
19
|
+
* matters. The origin is not pinned: the guest does not know which
|
|
20
|
+
* origin the app is served from, and learning it from the message
|
|
21
|
+
* would make the check circular.
|
|
22
|
+
*/
|
|
23
|
+
isFrom(event: MessageEvent): boolean;
|
|
24
|
+
post(body: GuestBody): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAElE,+DAA+D;AAC/D,MAAM,MAAM,SAAS,GAAG;KACrB,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,IAAI,CAC/B,OAAO,CAAC,YAAY,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,EAClC,MAAM,GAAG,OAAO,CACjB;CACF,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AAExB,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM;IAGhC;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAIpC,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;CAe5B"}
|
package/dist/channel.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The guest's line to the window it is framed in: who that window is,
|
|
3
|
+
* and the nonce every message to it must carry.
|
|
4
|
+
*/
|
|
5
|
+
import { BRIDGE_VERSION } from "./protocol.js";
|
|
6
|
+
export class HostChannel {
|
|
7
|
+
host;
|
|
8
|
+
nonce;
|
|
9
|
+
constructor(host, nonce) {
|
|
10
|
+
this.host = host;
|
|
11
|
+
this.nonce = nonce;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Did this event come from the host? The host is the only window that
|
|
15
|
+
* can reach this frame's parent slot, so the source is the check that
|
|
16
|
+
* matters. The origin is not pinned: the guest does not know which
|
|
17
|
+
* origin the app is served from, and learning it from the message
|
|
18
|
+
* would make the check circular.
|
|
19
|
+
*/
|
|
20
|
+
isFrom(event) {
|
|
21
|
+
return event.source === this.host;
|
|
22
|
+
}
|
|
23
|
+
post(body) {
|
|
24
|
+
// Targeted at "*" deliberately: the guest does not know the host's
|
|
25
|
+
// origin, and guessing one would mean a message silently going
|
|
26
|
+
// nowhere the first time the app is served from somewhere else.
|
|
27
|
+
// Nothing secret travels in this direction — the host authorises,
|
|
28
|
+
// the guest only asks.
|
|
29
|
+
// `kind` before `nonce`, as the guest always posted them: the fields
|
|
30
|
+
// are the same either way, but a host or a log that compares the
|
|
31
|
+
// serialised message sees the order.
|
|
32
|
+
const { kind, ...rest } = body;
|
|
33
|
+
this.host.postMessage({ igni: BRIDGE_VERSION, kind, nonce: this.nonce, ...rest }, "*");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.js","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC;AAUlE,MAAM,OAAO,WAAW;IAEH;IACA;IAFnB,YACmB,IAAY,EACZ,KAAa;QADb,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;IAC7B,CAAC;IAEJ;;;;;;OAMG;IACH,MAAM,CAAC,KAAmB;QACxB,OAAO,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,IAAe;QAClB,mEAAmE;QACnE,+DAA+D;QAC/D,gEAAgE;QAChE,kEAAkE;QAClE,uBAAuB;QACvB,qEAAqE;QACrE,iEAAiE;QACjE,qCAAqC;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,WAAW,CACnB,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,EAC1D,GAAG,CACJ,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an extension's page is handed by `connect()`.
|
|
3
|
+
*
|
|
4
|
+
* `P` and `S` are the extension's own launch parameters and settings:
|
|
5
|
+
* the host sends whatever the extension's links and manifest put there,
|
|
6
|
+
* so the extension is the one that can name them.
|
|
7
|
+
*/
|
|
8
|
+
import type { HostError, Signal } from "./hostModel.js";
|
|
9
|
+
import type { Host } from "./hostModel.generated.js";
|
|
10
|
+
import type { ExtensionSettings, LaunchParams, LocationState, RpcArgs } from "./protocol.js";
|
|
11
|
+
import type { ServiceBridge } from "./service.js";
|
|
12
|
+
import type { ThemeTokens } from "./tokens.js";
|
|
13
|
+
/** What an extension's page is handed. */
|
|
14
|
+
export interface Bridge<P extends LaunchParams = LaunchParams, S extends ExtensionSettings = ExtensionSettings> {
|
|
15
|
+
/** The id this frame is, as the host named it. */
|
|
16
|
+
readonly extensionId: string;
|
|
17
|
+
/** Launch parameters, as the host passed them. */
|
|
18
|
+
readonly params: P;
|
|
19
|
+
/**
|
|
20
|
+
* What `contributes.settings` is configured to.
|
|
21
|
+
*
|
|
22
|
+
* Fixed for the life of this frame — a change applies at the next
|
|
23
|
+
* mount, so there is no `onSettings`. Separate from {@link params}
|
|
24
|
+
* because that is *where you are* and this is *how you are set
|
|
25
|
+
* up*; one namespace for both would make a setting and a query
|
|
26
|
+
* key with the same name the same thing.
|
|
27
|
+
*/
|
|
28
|
+
readonly settings: S;
|
|
29
|
+
/** The host's theme now. Use `onTheme` to follow it. */
|
|
30
|
+
readonly theme: string;
|
|
31
|
+
/**
|
|
32
|
+
* The published design tokens, already applied to this document's
|
|
33
|
+
* root. Here as a reading for anything that needs a value rather
|
|
34
|
+
* than a CSS variable — a canvas, a chart library.
|
|
35
|
+
*/
|
|
36
|
+
readonly tokens: ThemeTokens;
|
|
37
|
+
/** Call a backend RPC. Rejects with the host's refusal, as a sentence. */
|
|
38
|
+
rpc<T = unknown>(method: string, args?: RpcArgs, timeoutMs?: number): Promise<T>;
|
|
39
|
+
/** Ask the host app to navigate. It decides whether to. */
|
|
40
|
+
navigate(to: string): void;
|
|
41
|
+
/** Tell the host this surface is finished. */
|
|
42
|
+
close(): void;
|
|
43
|
+
/** Follow the host's theme. Returns an unsubscribe. */
|
|
44
|
+
onTheme(fn: (theme: string) => void): () => void;
|
|
45
|
+
/**
|
|
46
|
+
* Follow the launch parameters.
|
|
47
|
+
*
|
|
48
|
+
* They arrive in `hello` and can change afterwards — a link
|
|
49
|
+
* resolved while this frame was already mounted, or the host
|
|
50
|
+
* restoring a saved location. Without this the host would have to
|
|
51
|
+
* rebuild the frame to deliver a changed parameter, losing
|
|
52
|
+
* whatever state it held.
|
|
53
|
+
*
|
|
54
|
+
* Fires only on change, never for the initial value; read
|
|
55
|
+
* {@link params} for that.
|
|
56
|
+
*/
|
|
57
|
+
onParams(fn: (params: P) => void): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Tell the host where inside this extension the user now is.
|
|
60
|
+
*
|
|
61
|
+
* Not a navigation — {@link navigate} is that. This says "still
|
|
62
|
+
* here, and here is now this". The host folds it into its own URL
|
|
63
|
+
* and replays it in the next `hello`, which is the only way an
|
|
64
|
+
* extension can be linked to or restored: the frame cannot write
|
|
65
|
+
* the address bar, and its `localStorage` dies with the ephemeral
|
|
66
|
+
* port it was served from.
|
|
67
|
+
*
|
|
68
|
+
* Strings only, and keep it small — it ends up in the host's URL.
|
|
69
|
+
* Call it when the user lands somewhere worth returning to, not on
|
|
70
|
+
* every keystroke.
|
|
71
|
+
*/
|
|
72
|
+
setLocation(state: LocationState): void;
|
|
73
|
+
/**
|
|
74
|
+
* igni, as this extension sees it: the host object model
|
|
75
|
+
* (`docs/HOST_OBJECT_MODEL.md` in igni). The same model the
|
|
76
|
+
* extension's process reaches as `ext.host`.
|
|
77
|
+
*
|
|
78
|
+
* const busy = await bridge.host.chat.processing.get();
|
|
79
|
+
* await bridge.host.chat.post("Two issues in the files you changed.");
|
|
80
|
+
*
|
|
81
|
+
* A page's `host.ui` is the window it is framed in. Every object needs
|
|
82
|
+
* its grant in the manifest's `permissions.host`; one that is not
|
|
83
|
+
* granted rejects with a `HostError` whose `code` is `not_granted`.
|
|
84
|
+
*/
|
|
85
|
+
readonly host: Host;
|
|
86
|
+
/**
|
|
87
|
+
* Handle a host signal: `bridge.on(bridge.host.chat.run_completed, fn)`.
|
|
88
|
+
*
|
|
89
|
+
* The first handler of a signal subscribes to it; removing the last
|
|
90
|
+
* one unsubscribes. A signal whose object is not granted never
|
|
91
|
+
* arrives; the refusal goes to `onRefused`, or to the console when
|
|
92
|
+
* there is none. Returns an unsubscribe.
|
|
93
|
+
*/
|
|
94
|
+
on<T>(signal: Signal<T>, fn: (value: T) => void, onRefused?: (error: HostError) => void): () => void;
|
|
95
|
+
/**
|
|
96
|
+
* The extension's own service, reached directly, as the signed-in
|
|
97
|
+
* person:
|
|
98
|
+
*
|
|
99
|
+
* const res = await bridge.service.fetch("/v1/notes");
|
|
100
|
+
* const socket = await bridge.service.websocket("/v1/rooms/a");
|
|
101
|
+
*
|
|
102
|
+
* The host fetches a token whose audience is this extension's service
|
|
103
|
+
* and nothing else; it is kept and renewed before it expires. No
|
|
104
|
+
* `permissions.host` grant: having a service is the grant — see
|
|
105
|
+
* `docs/HOST_OBJECT_MODEL.md` in igni. `url` is `null` when the
|
|
106
|
+
* extension has none.
|
|
107
|
+
*/
|
|
108
|
+
readonly service: ServiceBridge;
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACr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AC,IAAI,EAAE,IAAI,CAAC;IAEpB;;;;;;;OAOG;IACH,EAAE,CAAC,CAAC,EACF,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EACtB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,GACrC,MAAM,IAAI,CAAC;IAEd;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;CACjC"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an extension's page is handed by `connect()`.
|
|
3
|
+
*
|
|
4
|
+
* `P` and `S` are the extension's own launch parameters and settings:
|
|
5
|
+
* the host sends whatever the extension's links and manifest put there,
|
|
6
|
+
* so the extension is the one that can name them.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Requests the guest sent and is waiting on, matched to their replies by
|
|
3
|
+
* id.
|
|
4
|
+
*
|
|
5
|
+
* Each kind of request the guest makes — an RPC call, a host-model
|
|
6
|
+
* request, a service token — has its own `Correlator`, so a reply of
|
|
7
|
+
* one kind can never settle a request of another.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Correlator {
|
|
10
|
+
private readonly prefix;
|
|
11
|
+
private readonly nextNumber;
|
|
12
|
+
private readonly waiting;
|
|
13
|
+
/**
|
|
14
|
+
* `prefix` tells this correlator's ids apart from another's in a log;
|
|
15
|
+
* `nextNumber` numbers them. A bridge's correlators share one counter,
|
|
16
|
+
* so its ids run 1, h2, s3 across every kind, as they always have.
|
|
17
|
+
*/
|
|
18
|
+
constructor(prefix: string, nextNumber: () => number);
|
|
19
|
+
/**
|
|
20
|
+
* Send one request and wait for its reply.
|
|
21
|
+
*
|
|
22
|
+
* `timeoutMs` null waits for as long as the reply takes; otherwise the
|
|
23
|
+
* request is given up on with `timedOut()` and a late reply is ignored.
|
|
24
|
+
*/
|
|
25
|
+
send<T>(timeoutMs: number | null, timedOut: () => Error, post: (id: string) => void): Promise<T>;
|
|
26
|
+
/** The reply to `id` succeeded. */
|
|
27
|
+
resolve(id: string, value: unknown): void;
|
|
28
|
+
/** The reply to `id` refused. */
|
|
29
|
+
reject(id: string, error: Error): void;
|
|
30
|
+
/**
|
|
31
|
+
* Stop waiting on `id`. An id nobody is waiting on is either a late
|
|
32
|
+
* reply to something that timed out, or noise; either way there is no
|
|
33
|
+
* one to tell.
|
|
34
|
+
*/
|
|
35
|
+
private take;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=correlator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlator.d.ts","sourceRoot":"","sources":["../src/correlator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,qBAAa,UAAU;IASnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAT7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IAErD;;;;OAIG;gBAEgB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,MAAM;IAG3C;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EACJ,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,KAAK,EACrB,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GACzB,OAAO,CAAC,CAAC,CAAC;IAmBb,mCAAmC;IACnC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAIzC,iCAAiC;IACjC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAItC;;;;OAIG;IACH,OAAO,CAAC,IAAI;CAOb"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Requests the guest sent and is waiting on, matched to their replies by
|
|
3
|
+
* id.
|
|
4
|
+
*
|
|
5
|
+
* Each kind of request the guest makes — an RPC call, a host-model
|
|
6
|
+
* request, a service token — has its own `Correlator`, so a reply of
|
|
7
|
+
* one kind can never settle a request of another.
|
|
8
|
+
*/
|
|
9
|
+
export class Correlator {
|
|
10
|
+
prefix;
|
|
11
|
+
nextNumber;
|
|
12
|
+
waiting = new Map();
|
|
13
|
+
/**
|
|
14
|
+
* `prefix` tells this correlator's ids apart from another's in a log;
|
|
15
|
+
* `nextNumber` numbers them. A bridge's correlators share one counter,
|
|
16
|
+
* so its ids run 1, h2, s3 across every kind, as they always have.
|
|
17
|
+
*/
|
|
18
|
+
constructor(prefix, nextNumber) {
|
|
19
|
+
this.prefix = prefix;
|
|
20
|
+
this.nextNumber = nextNumber;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Send one request and wait for its reply.
|
|
24
|
+
*
|
|
25
|
+
* `timeoutMs` null waits for as long as the reply takes; otherwise the
|
|
26
|
+
* request is given up on with `timedOut()` and a late reply is ignored.
|
|
27
|
+
*/
|
|
28
|
+
send(timeoutMs, timedOut, post) {
|
|
29
|
+
const id = `${this.prefix}${this.nextNumber()}`;
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const timer = timeoutMs === null
|
|
32
|
+
? undefined
|
|
33
|
+
: setTimeout(() => {
|
|
34
|
+
this.waiting.delete(id);
|
|
35
|
+
reject(timedOut());
|
|
36
|
+
}, timeoutMs);
|
|
37
|
+
this.waiting.set(id, {
|
|
38
|
+
resolve: resolve,
|
|
39
|
+
reject,
|
|
40
|
+
timer,
|
|
41
|
+
});
|
|
42
|
+
post(id);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The reply to `id` succeeded. */
|
|
46
|
+
resolve(id, value) {
|
|
47
|
+
this.take(id)?.resolve(value);
|
|
48
|
+
}
|
|
49
|
+
/** The reply to `id` refused. */
|
|
50
|
+
reject(id, error) {
|
|
51
|
+
this.take(id)?.reject(error);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Stop waiting on `id`. An id nobody is waiting on is either a late
|
|
55
|
+
* reply to something that timed out, or noise; either way there is no
|
|
56
|
+
* one to tell.
|
|
57
|
+
*/
|
|
58
|
+
take(id) {
|
|
59
|
+
const waiter = this.waiting.get(id);
|
|
60
|
+
if (waiter === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
this.waiting.delete(id);
|
|
63
|
+
clearTimeout(waiter.timer);
|
|
64
|
+
return waiter;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=correlator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlator.js","sourceRoot":"","sources":["../src/correlator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,MAAM,OAAO,UAAU;IASF;IACA;IATF,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAErD;;;;OAIG;IACH,YACmB,MAAc,EACd,UAAwB;QADxB,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAc;IACxC,CAAC;IAEJ;;;;;OAKG;IACH,IAAI,CACF,SAAwB,EACxB,QAAqB,EACrB,IAA0B;QAE1B,MAAM,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;QAChD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,MAAM,KAAK,GACT,SAAS,KAAK,IAAI;gBAChB,CAAC,CAAC,SAAS;gBACX,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE;oBACd,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBACxB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;gBACrB,CAAC,EAAE,SAAS,CAAC,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE;gBACnB,OAAO,EAAE,OAAmC;gBAC5C,MAAM;gBACN,KAAK;aACN,CAAC,CAAC;YACH,IAAI,CAAC,EAAE,CAAC,CAAC;QACX,CAAC,CAAC,CAAC;IACL,CAAC;IAED,mCAAmC;IACnC,OAAO,CAAC,EAAU,EAAE,KAAc;QAChC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,iCAAiC;IACjC,MAAM,CAAC,EAAU,EAAE,KAAY;QAC7B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACK,IAAI,CAAC,EAAU;QACrB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC3C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3B,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge an extension's page holds once the host has said hello.
|
|
3
|
+
*
|
|
4
|
+
* It owns everything the page learned from the host — params, theme,
|
|
5
|
+
* tokens — and the three kinds of request it can be waiting on, each
|
|
6
|
+
* with its own {@link Correlator}. Messages from the host are routed by
|
|
7
|
+
* kind through one table, {@link GuestBridge.handlers}.
|
|
8
|
+
*/
|
|
9
|
+
import type { HostChannel } from "./channel.js";
|
|
10
|
+
import type { Bridge } from "./contract.js";
|
|
11
|
+
import { HostError, type Signal } from "./hostModel.js";
|
|
12
|
+
import { Host } from "./hostModel.generated.js";
|
|
13
|
+
import type { ExtensionSettings, HelloMessage, HostMessage, LaunchParams, LocationState, RpcArgs } from "./protocol.js";
|
|
14
|
+
import { ServiceLink } from "./service.js";
|
|
15
|
+
import { type ThemeTokens } from "./tokens.js";
|
|
16
|
+
/** How long a request waits before giving up. The host has its own. */
|
|
17
|
+
export declare const DEFAULT_TIMEOUT_MS = 30000;
|
|
18
|
+
export declare class GuestBridge<P extends LaunchParams, S extends ExtensionSettings> implements Bridge<P, S> {
|
|
19
|
+
private readonly channel;
|
|
20
|
+
readonly extensionId: string;
|
|
21
|
+
readonly settings: S;
|
|
22
|
+
readonly host: Host;
|
|
23
|
+
readonly service: ServiceLink;
|
|
24
|
+
private currentParams;
|
|
25
|
+
private currentTheme;
|
|
26
|
+
private currentTokens;
|
|
27
|
+
private readonly themeWatchers;
|
|
28
|
+
private readonly paramWatchers;
|
|
29
|
+
/** One numbering for every request, whatever its kind. */
|
|
30
|
+
private requestCount;
|
|
31
|
+
private readonly nextRequest;
|
|
32
|
+
private readonly calls;
|
|
33
|
+
private readonly hostRequests;
|
|
34
|
+
private readonly tokenRequests;
|
|
35
|
+
private readonly signals;
|
|
36
|
+
private readonly handlers;
|
|
37
|
+
/**
|
|
38
|
+
* `params` and `settings` are the extension's to name (`P`, `S`): the
|
|
39
|
+
* host sends what the extension's own links and manifest put there.
|
|
40
|
+
*/
|
|
41
|
+
constructor(channel: HostChannel, hello: HelloMessage);
|
|
42
|
+
get params(): P;
|
|
43
|
+
get theme(): string;
|
|
44
|
+
get tokens(): ThemeTokens;
|
|
45
|
+
/** Act on one message the host sent. */
|
|
46
|
+
receive(message: HostMessage): void;
|
|
47
|
+
rpc<T = unknown>(method: string, args?: RpcArgs, timeoutMs?: number): Promise<T>;
|
|
48
|
+
navigate(to: string): void;
|
|
49
|
+
close(): void;
|
|
50
|
+
onTheme(fn: (theme: string) => void): () => void;
|
|
51
|
+
onParams(fn: (params: P) => void): () => void;
|
|
52
|
+
setLocation(state: LocationState): void;
|
|
53
|
+
on<T>(signal: Signal<T>, fn: (value: T) => void, onRefused?: (error: HostError) => void): () => void;
|
|
54
|
+
private applyTheme;
|
|
55
|
+
private applyParams;
|
|
56
|
+
private hostRequest;
|
|
57
|
+
/** One token request to the host, which asks igni as this extension. */
|
|
58
|
+
private askForToken;
|
|
59
|
+
private settleCall;
|
|
60
|
+
private settleHostRequest;
|
|
61
|
+
private settleTokenRequest;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=guestBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guestBridge.d.ts","sourceRoot":"","sources":["../src/guestBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAiB,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,WAAW,EAGX,YAAY,EACZ,aAAa,EAGb,OAAO,EAGR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAkC,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAGjE,uEAAuE;AACvE,eAAO,MAAM,kBAAkB,QAAS,CAAC;AAkBzC,qBAAa,WAAW,CACtB,CAAC,SAAS,YAAY,EACtB,CAAC,SAAS,iBAAiB,CAC3B,YAAW,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAqCrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IApC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC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AM,IAAI;IAI7C,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAIvC,EAAE,CAAC,CAAC,EACF,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EACtB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,GACrC,MAAM,IAAI;IAIb,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,WAAW;IAcnB,wEAAwE;IACxE,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,kBAAkB;CAe3B"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bridge an extension's page holds once the host has said hello.
|
|
3
|
+
*
|
|
4
|
+
* It owns everything the page learned from the host — params, theme,
|
|
5
|
+
* tokens — and the three kinds of request it can be waiting on, each
|
|
6
|
+
* with its own {@link Correlator}. Messages from the host are routed by
|
|
7
|
+
* kind through one table, {@link GuestBridge.handlers}.
|
|
8
|
+
*/
|
|
9
|
+
import { Correlator } from "./correlator.js";
|
|
10
|
+
import { HostError } from "./hostModel.js";
|
|
11
|
+
import { Host } from "./hostModel.generated.js";
|
|
12
|
+
import { ServiceError, ServiceLink } from "./service.js";
|
|
13
|
+
import { SignalSubscriptions } from "./signals.js";
|
|
14
|
+
import { applyThemeTokens } from "./tokens.js";
|
|
15
|
+
import { Watchers } from "./watchers.js";
|
|
16
|
+
/** How long a request waits before giving up. The host has its own. */
|
|
17
|
+
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
18
|
+
/** Members whose answer is the person's, so no timeout applies to them. */
|
|
19
|
+
const WAITS_ON_THE_PERSON = new Set(["ui.show_dialog"]);
|
|
20
|
+
export class GuestBridge {
|
|
21
|
+
channel;
|
|
22
|
+
extensionId;
|
|
23
|
+
settings;
|
|
24
|
+
host;
|
|
25
|
+
service;
|
|
26
|
+
currentParams;
|
|
27
|
+
currentTheme;
|
|
28
|
+
currentTokens;
|
|
29
|
+
themeWatchers = new Watchers();
|
|
30
|
+
paramWatchers = new Watchers();
|
|
31
|
+
/** One numbering for every request, whatever its kind. */
|
|
32
|
+
requestCount = 0;
|
|
33
|
+
nextRequest = () => ++this.requestCount;
|
|
34
|
+
calls = new Correlator("", this.nextRequest);
|
|
35
|
+
hostRequests = new Correlator("h", this.nextRequest);
|
|
36
|
+
tokenRequests = new Correlator("s", this.nextRequest);
|
|
37
|
+
signals = new SignalSubscriptions((op, signal) => this.hostRequest({ op, path: "", signals: [signal] }));
|
|
38
|
+
handlers = {
|
|
39
|
+
// Connecting already consumed the greeting; a repeat changes nothing.
|
|
40
|
+
hello: () => { },
|
|
41
|
+
theme: (message) => this.applyTheme(message),
|
|
42
|
+
params: (message) => this.applyParams(message),
|
|
43
|
+
signal: (message) => this.signals.deliver(message),
|
|
44
|
+
"host-reply": (message) => this.settleHostRequest(message),
|
|
45
|
+
"service-token-reply": (message) => this.settleTokenRequest(message),
|
|
46
|
+
result: (message) => this.settleCall(message),
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* `params` and `settings` are the extension's to name (`P`, `S`): the
|
|
50
|
+
* host sends what the extension's own links and manifest put there.
|
|
51
|
+
*/
|
|
52
|
+
constructor(channel, hello) {
|
|
53
|
+
this.channel = channel;
|
|
54
|
+
this.extensionId = hello.extensionId;
|
|
55
|
+
this.settings = (hello.settings ?? {});
|
|
56
|
+
this.currentParams = hello.params;
|
|
57
|
+
this.currentTheme = hello.theme;
|
|
58
|
+
this.currentTokens = hello.tokens;
|
|
59
|
+
const link = {
|
|
60
|
+
request: (op, path, options) => this.hostRequest({
|
|
61
|
+
op,
|
|
62
|
+
path,
|
|
63
|
+
window: options.window ?? null,
|
|
64
|
+
...(options.session ? { session: options.session } : {}),
|
|
65
|
+
...(options.params !== undefined ? { params: options.params } : {}),
|
|
66
|
+
...(op === "set" ? { value: options.value } : {}),
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
this.host = new Host(link);
|
|
70
|
+
this.service = new ServiceLink(hello.serviceUrl ?? null, () => this.askForToken());
|
|
71
|
+
// Applied before the page renders anything, so an extension never
|
|
72
|
+
// paints once in the fallback palette and again in the real one.
|
|
73
|
+
applyThemeTokens(this.currentTokens, document.documentElement);
|
|
74
|
+
}
|
|
75
|
+
get params() {
|
|
76
|
+
return this.currentParams;
|
|
77
|
+
}
|
|
78
|
+
get theme() {
|
|
79
|
+
return this.currentTheme;
|
|
80
|
+
}
|
|
81
|
+
get tokens() {
|
|
82
|
+
return this.currentTokens;
|
|
83
|
+
}
|
|
84
|
+
/** Act on one message the host sent. */
|
|
85
|
+
receive(message) {
|
|
86
|
+
// The table is keyed by kind, so this handler takes this message;
|
|
87
|
+
// TypeScript cannot follow that correlation through an index.
|
|
88
|
+
const handle = this.handlers[message.kind];
|
|
89
|
+
handle(message);
|
|
90
|
+
}
|
|
91
|
+
rpc(method, args = {}, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
92
|
+
// `Number`, not `timeoutMs` as it is: null means "no limit" to a
|
|
93
|
+
// correlator, but an untyped caller's null (or "500") reaches a
|
|
94
|
+
// call's timer the way `setTimeout` always read it — as 0 (or 500).
|
|
95
|
+
return this.calls.send(Number(timeoutMs), () => new Error(`igni bridge: ${method} timed out after ${timeoutMs}ms`), (id) => this.channel.post({ kind: "call", id, method, args }));
|
|
96
|
+
}
|
|
97
|
+
navigate(to) {
|
|
98
|
+
this.channel.post({ kind: "navigate", to });
|
|
99
|
+
}
|
|
100
|
+
close() {
|
|
101
|
+
this.channel.post({ kind: "close" });
|
|
102
|
+
}
|
|
103
|
+
onTheme(fn) {
|
|
104
|
+
return this.themeWatchers.add(fn);
|
|
105
|
+
}
|
|
106
|
+
onParams(fn) {
|
|
107
|
+
return this.paramWatchers.add(fn);
|
|
108
|
+
}
|
|
109
|
+
setLocation(state) {
|
|
110
|
+
this.channel.post({ kind: "location", state });
|
|
111
|
+
}
|
|
112
|
+
on(signal, fn, onRefused) {
|
|
113
|
+
return this.signals.on(signal, fn, onRefused);
|
|
114
|
+
}
|
|
115
|
+
applyTheme(message) {
|
|
116
|
+
this.currentTheme = message.theme;
|
|
117
|
+
this.currentTokens = message.tokens;
|
|
118
|
+
applyThemeTokens(this.currentTokens, document.documentElement);
|
|
119
|
+
this.themeWatchers.emit(this.currentTheme);
|
|
120
|
+
}
|
|
121
|
+
applyParams(message) {
|
|
122
|
+
this.currentParams = message.params;
|
|
123
|
+
this.paramWatchers.emit(this.currentParams);
|
|
124
|
+
}
|
|
125
|
+
hostRequest(body) {
|
|
126
|
+
// A dialog waits on the person, for as long as they take.
|
|
127
|
+
const waits = WAITS_ON_THE_PERSON.has(body.path);
|
|
128
|
+
return this.hostRequests.send(waits ? null : DEFAULT_TIMEOUT_MS, () => new HostError("failed", `igni bridge: host.${body.path || body.op} timed out after ${DEFAULT_TIMEOUT_MS}ms`), (id) => this.channel.post({ kind: "host", id, ...body }));
|
|
129
|
+
}
|
|
130
|
+
/** One token request to the host, which asks igni as this extension. */
|
|
131
|
+
askForToken() {
|
|
132
|
+
return this.tokenRequests.send(DEFAULT_TIMEOUT_MS, () => new ServiceError("failed", `igni bridge: no service token within ${DEFAULT_TIMEOUT_MS}ms`), (id) => this.channel.post({ kind: "service-token", id }));
|
|
133
|
+
}
|
|
134
|
+
settleCall(reply) {
|
|
135
|
+
if (reply.ok)
|
|
136
|
+
this.calls.resolve(reply.id, reply.value);
|
|
137
|
+
else
|
|
138
|
+
this.calls.reject(reply.id, new Error(reply.error || "the host refused the call without saying why"));
|
|
139
|
+
}
|
|
140
|
+
settleHostRequest(reply) {
|
|
141
|
+
if (reply.ok)
|
|
142
|
+
this.hostRequests.resolve(reply.id, reply.result);
|
|
143
|
+
else
|
|
144
|
+
this.hostRequests.reject(reply.id, new HostError(reply.error?.code ?? "failed", reply.error?.message ?? "the host refused without saying why"));
|
|
145
|
+
}
|
|
146
|
+
settleTokenRequest(reply) {
|
|
147
|
+
if (reply.ok && typeof reply.token === "string")
|
|
148
|
+
this.tokenRequests.resolve(reply.id, {
|
|
149
|
+
token: reply.token,
|
|
150
|
+
expiresIn: reply.expiresIn ?? 0,
|
|
151
|
+
});
|
|
152
|
+
else
|
|
153
|
+
this.tokenRequests.reject(reply.id, new ServiceError("refused", reply.error || "igni gave no token for this extension's service"));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=guestBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guestBridge.js","sourceRoot":"","sources":["../src/guestBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAA8B,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAehD,OAAO,EAAoB,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAoB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAexD,MAAM,OAAO,WAAW;IAwCH;IApCV,WAAW,CAAS;IACpB,QAAQ,CAAI;IACZ,IAAI,CAAO;IACX,OAAO,CAAc;IAEtB,aAAa,CAAI;IACjB,YAAY,CAAS;IACrB,aAAa,CAAc;IAClB,aAAa,GAAG,IAAI,QAAQ,EAAU,CAAC;IACvC,aAAa,GAAG,IAAI,QAAQ,EAAK,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