@ignite-ember/extension-bridge 0.0.0-stage → 0.2.1

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.
Files changed (69) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +364 -2
  4. package/dist/bridge.d.ts +37 -0
  5. package/dist/bridge.d.ts.map +1 -0
  6. package/dist/bridge.js +96 -0
  7. package/dist/bridge.js.map +1 -0
  8. package/dist/channel.d.ts +26 -0
  9. package/dist/channel.d.ts.map +1 -0
  10. package/dist/channel.js +36 -0
  11. package/dist/channel.js.map +1 -0
  12. package/dist/contract.d.ts +137 -0
  13. package/dist/contract.d.ts.map +1 -0
  14. package/dist/contract.js +9 -0
  15. package/dist/contract.js.map +1 -0
  16. package/dist/correlator.d.ts +37 -0
  17. package/dist/correlator.d.ts.map +1 -0
  18. package/dist/correlator.js +75 -0
  19. package/dist/correlator.js.map +1 -0
  20. package/dist/guestBridge.d.ts +63 -0
  21. package/dist/guestBridge.d.ts.map +1 -0
  22. package/dist/guestBridge.js +156 -0
  23. package/dist/guestBridge.js.map +1 -0
  24. package/dist/hostModel.d.ts +159 -0
  25. package/dist/hostModel.d.ts.map +1 -0
  26. package/dist/hostModel.generated.d.ts +2373 -0
  27. package/dist/hostModel.generated.d.ts.map +1 -0
  28. package/dist/hostModel.generated.js +1746 -0
  29. package/dist/hostModel.generated.js.map +1 -0
  30. package/dist/hostModel.js +172 -0
  31. package/dist/hostModel.js.map +1 -0
  32. package/dist/index.d.ts +12 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +12 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/protocol.d.ts +348 -0
  37. package/dist/protocol.d.ts.map +1 -0
  38. package/dist/protocol.js +145 -0
  39. package/dist/protocol.js.map +1 -0
  40. package/dist/service.d.ts +168 -0
  41. package/dist/service.d.ts.map +1 -0
  42. package/dist/service.js +196 -0
  43. package/dist/service.js.map +1 -0
  44. package/dist/signals.d.ts +21 -0
  45. package/dist/signals.d.ts.map +1 -0
  46. package/dist/signals.js +52 -0
  47. package/dist/signals.js.map +1 -0
  48. package/dist/tokens.d.ts +101 -0
  49. package/dist/tokens.d.ts.map +1 -0
  50. package/dist/tokens.js +164 -0
  51. package/dist/tokens.js.map +1 -0
  52. package/dist/watchers.d.ts +12 -0
  53. package/dist/watchers.d.ts.map +1 -0
  54. package/dist/watchers.js +18 -0
  55. package/dist/watchers.js.map +1 -0
  56. package/package.json +53 -4
  57. package/src/bridge.ts +116 -0
  58. package/src/channel.ts +48 -0
  59. package/src/contract.ts +157 -0
  60. package/src/correlator.ts +88 -0
  61. package/src/guestBridge.ts +261 -0
  62. package/src/hostModel.generated.ts +3155 -0
  63. package/src/hostModel.ts +213 -0
  64. package/src/index.ts +11 -0
  65. package/src/protocol.ts +485 -0
  66. package/src/service.ts +278 -0
  67. package/src/signals.ts +65 -0
  68. package/src/tokens.ts +171 -0
  69. package/src/watchers.ts +18 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ igni
2
+ Copyright 2026 Ignite Ember
3
+
4
+ This product includes software developed at Ignite Ember
5
+ (https://igni.sh/).
package/README.md CHANGED
@@ -1,3 +1,365 @@
1
- # Temporary Holding Version
1
+ # `@ignite-ember/extension-bridge`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Full documentation:** [igni.sh/docs/sdk/extension-bridge](https://igni.sh/docs/sdk/extension-bridge) — guides and the complete API reference, a page per topic.
4
+
5
+ The guest half of the bridge between an igni extension's page and igni:
6
+ `connect()`, RPC to the extension's tools, navigation, and the theme. The
7
+ host imports the same `protocol`, so there is one description of the wire.
8
+
9
+ ```ts
10
+ import { connect } from "@ignite-ember/extension-bridge";
11
+
12
+ const bridge = await connect(); // igni has said hello; the theme is applied
13
+ bridge.onParams((params) => render(params));
14
+ const found = await bridge.rpc("ext.example.teamnotes.search", { query: "" });
15
+ ```
16
+
17
+ Writing a page for the first time? [Your first extension](https://github.com/ignite-ember/igni-sdk/blob/main/docs/YOUR_FIRST_EXTENSION.md)
18
+ builds one end to end. A page needs no build step at all to start: it can
19
+ post the wire messages itself (`igni ext init` writes one that does);
20
+ this package is that, with types.
21
+
22
+ `connect()` resolves once igni has told the page which extension it is,
23
+ its launch params and the theme. Subpaths: `@ignite-ember/extension-bridge/protocol`
24
+ (the wire format) and `@ignite-ember/extension-bridge/tokens` (the design tokens).
25
+
26
+ ## Quick start
27
+
28
+ A page is an ordinary web page that igni frames. It gets a bridge, and
29
+ the bridge is the only thing it needs from igni.
30
+
31
+ ```bash
32
+ npm install @ignite-ember/extension-bridge @ignite-ember/ui-css
33
+ ```
34
+
35
+ ```ts
36
+ import { connect } from "@ignite-ember/extension-bridge";
37
+ import "@ignite-ember/ui-css";
38
+
39
+ async function main() {
40
+ const bridge = await connect();
41
+
42
+ // The theme is already applied: igni pushed its live values.
43
+ document.body.classList.add("igni-root");
44
+
45
+ // The launch parameters: what the link carried.
46
+ bridge.onParams((params) => {
47
+ document.title = String(params.title ?? "Extension");
48
+ });
49
+
50
+ // The extension's own backend, as the person signed in to igni.
51
+ const notes = await bridge.rpc("ext.example.teamnotes.search", { query: "" });
52
+
53
+ // Draw it however your page draws: plain DOM here, React with @ignite-ember/ui-react.
54
+ const list = document.createElement("ul");
55
+ for (const note of notes as { title: string }[]) {
56
+ const item = document.createElement("li");
57
+ item.textContent = note.title;
58
+ list.append(item);
59
+ }
60
+ document.body.append(list);
61
+ }
62
+
63
+ main().catch((error) => {
64
+ console.error(error);
65
+ });
66
+ ```
67
+
68
+ Three things to know before you write more:
69
+
70
+ - **Every call is a round trip.** `bridge.rpc()` is a request to the host
71
+ and back. It is fast, but it is not free, and it can time out.
72
+ - **Nothing here carries authority.** The host checks every grant. The
73
+ bridge is a message pipe with types on it, not a key.
74
+ - **The page runs on its own origin.** It may not read igni's stylesheet,
75
+ its storage or its scripts. What it may use is pushed over the bridge.
76
+
77
+ ## The life of a page
78
+
79
+ Between the frame being created and the first paint, four things happen.
80
+ Knowing which is which saves an afternoon.
81
+
82
+ 1. **The frame loads.** Your page is served from your own origin, under
83
+ `default-src 'self'`. It may not fetch igni's stylesheet, scripts or
84
+ fonts. The refusal is deliberate: a page that could read the app's
85
+ origin could read the app.
86
+ 2. **igni says hello.** The host posts a `hello` message carrying a
87
+ nonce. `connect()` is waiting for exactly that message, from exactly
88
+ that parent window; a message from anywhere else is ignored.
89
+ 3. **The theme arrives.** The host computes the *live* token values and
90
+ pushes them, and the bridge writes them onto `:root` before it
91
+ resolves. Your stylesheet's fallbacks are what a reader sees outside
92
+ igni; inside igni the live values apply.
93
+ 4. **The params arrive.** `bridge.params` holds them, and `onParams`
94
+ fires when they change — a link resolved after the frame was already
95
+ mounted, say.
96
+
97
+ If the host never says hello, `connect()` rejects after thirty seconds;
98
+ `connect({ timeoutMs })` changes that. If the page is not framed at all —
99
+ opened in a browser tab — it rejects at once, saying that it is not
100
+ framed by a host.
101
+
102
+ ## The host: `bridge.host`
103
+
104
+ `bridge.host` is igni as the page sees it — the **host object model**
105
+ ([`docs/HOST_OBJECT_MODEL.md`](https://github.com/ignite-ember/igni-core/blob/main/docs/HOST_OBJECT_MODEL.md) in igni-core), the same model the extension's
106
+ process reaches as `ext.host`. Names are the schema's, as in Python.
107
+
108
+ ```ts
109
+ const busy = await bridge.host.chat.processing.get(); // a property
110
+ await bridge.host.chat.post("Two issues in auth.py."); // a method
111
+ await bridge.host.ui.navigate("plugins"); // this page's window
112
+ const off = bridge.on(bridge.host.chat.run_completed, (run) => {
113
+ if (run.changed_files.length) render(run.changed_files);
114
+ });
115
+ ```
116
+
117
+ Every object needs its grant in the manifest's `permissions.host`; one
118
+ that is not granted rejects with a `HostError` whose `code` is
119
+ `not_granted`, and its signals never arrive. A page's `host.ui` is the
120
+ window it is framed in. The types (`Run`, `SessionChange`, …) are
121
+ exported from the package; `hostModel.generated.ts` is generated from
122
+ igni's host schema and `SCHEMA_VERSION` says which version.
123
+
124
+ A page observes; it cannot answer a hook. Being asked before something
125
+ happens (igni's hook events, `@ext.hook` in `igni-extension`) is the
126
+ extension's process's, because igni would otherwise wait on whatever tab
127
+ happens to be open.
128
+
129
+ ## Its own service: `bridge.service`
130
+
131
+ The page talks to the service that shipped the extension directly, as
132
+ the signed-in person. igni fetches a ten-minute token for it — the same
133
+ exchange as the process's `ext.service`, audience that service and no
134
+ other — keeps it and renews it before it expires.
135
+
136
+ ```ts
137
+ bridge.service.url; // null when it has none (below)
138
+ const res = await bridge.service.fetch("/v1/notes"); // Authorization: Bearer …
139
+ const socket = await bridge.service.websocket("/v1/rooms/a");
140
+ socket.addEventListener("message", (e) => render(JSON.parse(e.data)));
141
+ ```
142
+
143
+ `url` is `null` when the extension has no service a page may reach, and
144
+ then `fetch` and `websocket` reject with `no_service`. An extension igni
145
+ distributed always has a service: the one that shipped it. A development
146
+ install has one only when its manifest declares a `serviceUrl` setting
147
+ (`contributes.settings`) and it is set. A page is given the service only
148
+ over `https`: a plain-`http` URL counts only for this machine (`localhost`,
149
+ any name under `.localhost`, or a loopback address such as `127.0.0.1` or
150
+ `::1`) and only with `IGNI_DEV_EXTENSIONS=1`. A service on another host,
151
+ or on this machine outside development, leaves `url` `null`; a service on
152
+ another host must be `https`.
153
+
154
+ `websocket` resolves once the socket is open and has sent
155
+ `{"type": "auth", "token": …}` as its first frame (a browser socket
156
+ cannot set a header); pass `{ authFrame: (token) => … }` for a service
157
+ that reads something else. `fetch` retries once with a new token after
158
+ a `401`. Both refuse a path on any other origin with a `ServiceError`
159
+ (`other_origin`): the token goes to the service only. No
160
+ `permissions.host` grant is needed. The frame's CSP admits the
161
+ service's origin over `https`/`wss` and the hosts declared in
162
+ `permissions.egress`, nothing else. `fetch` sends the token and never
163
+ cookies (`credentials: "omit"`); a service on igni-service answers it
164
+ cross-origin with nothing to configure (`igni.install(app)`).
165
+
166
+ ## Calling your extension's tools
167
+
168
+ `bridge.rpc(method, args?, timeoutMs?)` calls a method of the
169
+ extension's own service — the same namespace the agent calls.
170
+
171
+ ```ts
172
+ const found = await bridge.rpc("ext.example.teamnotes.search", { query: "auth" });
173
+ const one = await bridge.rpc<Note>("ext.example.teamnotes.get", { id: "n1" });
174
+ ```
175
+
176
+ - **The name** is `ext.<your-extension-id>.<your-method>`. The namespace
177
+ is authorised against your manifest's `permissions.rpc`, and the call
178
+ reaches your service as an MCP tool call.
179
+ - **The arguments** are a plain record of strings and JSON values, sent
180
+ as they are.
181
+ - **The answer** is the tool's text answer, parsed as JSON when it is
182
+ JSON and the text itself when it is not: a tool returning a `dict` or a
183
+ `json.dumps(...)` string gives an object, one returning a sentence a
184
+ string, and one returning a Python `list` its items' text, one per
185
+ line ([igni-extension's table](../igni-extension/README.md#what-a-tool-returns)).
186
+ Give the call its type — `rpc<Note>(...)` — and the compiler will hold
187
+ you to it; nothing checks it at runtime.
188
+ - **The deadline** is thirty seconds. `timeoutMs` overrides it. The host
189
+ has a timeout of its own, and the shorter of the two is the one that
190
+ fires.
191
+
192
+ A refusal is an error, not a value: the promise rejects with the host's
193
+ own sentence, or with "the host refused the call without saying why" if
194
+ it gave none. A method the service does not have, one the manifest does
195
+ not permit, and one the service answered with an error all reject the
196
+ same way.
197
+
198
+ ## Following the host
199
+
200
+ A page watches; it does not poll. Three subscriptions, each returning an
201
+ unsubscribe:
202
+
203
+ ```ts
204
+ const offParams = bridge.onParams((params) => render(params));
205
+ const offTheme = bridge.onTheme((theme) => setMode(theme));
206
+ const offRun = bridge.on(bridge.host.chat.run_completed, (run) => render(run));
207
+
208
+ offParams();
209
+ ```
210
+
211
+ `onParams` fires only on a *change*; read `bridge.params` for the value
212
+ you were given to start with. `onTheme` fires when the person's theme
213
+ changes — the same change that moves the live token values. `on` follows
214
+ one of the host's signals.
215
+
216
+ `bridge.on(signal, fn, onRefused?)` takes a third argument, and it
217
+ matters: a signal whose object is **not granted** never arrives, and
218
+ without `onRefused` your handler simply never runs, with only a console
219
+ warning (`igni bridge: subscribing to <signal> failed: …`) to say why.
220
+ With it, the refusal arrives as a `HostError` you can show.
221
+
222
+ The first handler of a signal subscribes to it; removing the last one
223
+ unsubscribes.
224
+
225
+ ## Where the page is
226
+
227
+ `bridge.setLocation(state)` says where inside your extension the person
228
+ now is. It is not a navigation — `bridge.navigate(to)` is that — and it
229
+ is how an extension can be linked to or restored: the frame cannot write
230
+ the address bar, and its `localStorage` dies with the ephemeral port it
231
+ was served from. The host folds the state into its own URL and replays
232
+ it in the next `hello`.
233
+
234
+ Keep the state small and keep it strings: it ends up in the host's URL.
235
+ Call it when the person lands somewhere worth returning to, not on every
236
+ keystroke.
237
+
238
+ `bridge.close()` tells the host this surface is finished. `bridge.navigate(to)`
239
+ asks the host app to navigate; it decides whether to.
240
+
241
+ ## Putting a built page in the extension
242
+
243
+ An extension's page is the `ui/` directory of its package, and its entry is
244
+ `ui/index.html`. A page built with a bundler goes there as files: build to
245
+ `ui/` (or copy the output into it), keep the script and stylesheet as files
246
+ (the page's CSP is `script-src 'self'`, so nothing may be inline), and make
247
+ the asset URLs relative. With Vite that is `base: "./"` in `vite.config`.
248
+ `igni ext init` writes a no-build page in `ui/`; replace it with the build.
249
+
250
+ A development install (`IGNI_DEV_EXTENSIONS=1 igni ext install <dir>`) is a
251
+ copy of the directory in igni's extension store, so a rebuilt page reaches
252
+ igni only by installing again: `igni ext install --replace <dir>`, which
253
+ prints again what the extension may use (it asks nothing). A running igni
254
+ serves the rebuilt page at once: reload it. A second install without
255
+ `--replace` is refused ("already installed").
256
+
257
+ With TypeScript 6 or later, `import "@ignite-ember/ui-css"` type-checks
258
+ because the stylesheet package ships a declaration for it (0.2.0 and later).
259
+
260
+ ## Testing a page
261
+
262
+ Only igni's app frames a page, and only igni's window carries a page's
263
+ `ext.*` calls to igni, in the page's extension's name; a program, a
264
+ browser test or `igni-client` cannot make those calls as the page. So a
265
+ page is tested with a stand-in for its parent window, and the tool behind
266
+ a call is tested on its own, with igni-extension's `HostHarness`.
267
+
268
+ The page speaks to its parent with `postMessage`, in the shapes the
269
+ `protocol` subpath exports. A stand-in parent sends `hello`, reads each
270
+ `call` the page posts, and answers it with a `result` of the same `id`:
271
+
272
+ ```ts
273
+ import { BRIDGE_VERSION, isGuestMessage } from "@ignite-ember/extension-bridge/protocol";
274
+ import type { HelloMessage, ResultMessage } from "@ignite-ember/extension-bridge/protocol";
275
+
276
+ const hello: HelloMessage = {
277
+ igni: BRIDGE_VERSION, kind: "hello", nonce: "n1", extensionId: "acme.tickets",
278
+ params: {}, theme: "dark", tokens: {},
279
+ };
280
+ // After the frame's load event: connect() hears only a hello posted once
281
+ // the page's script runs, and one posted earlier is lost.
282
+ frame.addEventListener("load", () => frame.contentWindow!.postMessage(hello, "*"));
283
+
284
+ window.addEventListener("message", (event) => {
285
+ if (event.source !== frame.contentWindow || !isGuestMessage(event.data)) return;
286
+ if (event.data.kind !== "call") return;
287
+ const answer: ResultMessage = {
288
+ igni: BRIDGE_VERSION, kind: "result", id: event.data.id, ok: true,
289
+ value: { id: "T-1001", status: "open" }, // what the tool would return
290
+ };
291
+ frame.contentWindow!.postMessage(answer, "*");
292
+ });
293
+ ```
294
+
295
+ `packages/test-utils/ticketLookupPage.test.ts` in this repository does
296
+ this for the ticket-lookup example's page, in jsdom.
297
+
298
+ There is deliberately no way to send a framed page's calls to the real
299
+ backend outside igni's app — no URL to point it at, no token to pass: the
300
+ answers in a test are the stand-in's. What the real tool returns is tested
301
+ on the tool, with `HostHarness`, and the two meet in igni's app.
302
+
303
+ ## The floor
304
+
305
+ Everything this package exports is under igni's **compatibility floor**:
306
+ removing a name, renaming it, or changing the meaning of one of its
307
+ members is a breaking change under [`docs/EXTENSIBILITY.md`](https://github.com/ignite-ember/igni-core/blob/main/docs/EXTENSIBILITY.md) §8.
308
+
309
+ Two versions of that floor are worth knowing about:
310
+
311
+ - **`BRIDGE_VERSION`** (on the `protocol` subpath) is the version of the
312
+ wire this package speaks. Every message carries it, and a message
313
+ whose version is not the one this package speaks is not read at all —
314
+ it is bumped only for a change the other side cannot ignore.
315
+ - **`SCHEMA_VERSION`** (exported from the package) is the version of
316
+ igni's host schema the generated host model was made from. It moves
317
+ when igni's host model moves.
318
+
319
+ The host model itself is generated from igni's own schema, so a new igni
320
+ can carry objects this package has never heard of. That is not a
321
+ version skew to worry about: an object the package does not know is not
322
+ reachable from `bridge.host`, and the page simply does not use it.
323
+
324
+ ## Changed since 0.1.0, on purpose
325
+
326
+ - `connect<P, S>()` and `Bridge<P, S>` take the extension's own launch
327
+ params and settings as type arguments. Without them, `params` and
328
+ `settings` are readonly records (`LaunchParams`, `ExtensionSettings`),
329
+ so writing into one no longer compiles; `rpc`'s args (`RpcArgs`) and
330
+ `setLocation`'s state (`LocationState`) are readonly too. The four
331
+ types are new on the `protocol` subpath, and the wire messages use them.
332
+ - `bridge.on(signal, fn, onRefused?)`: a refused or unanswered
333
+ subscription goes to `onRefused` (a `HostError`), or to the console
334
+ (`igni bridge: subscribing to <signal> failed: …`) when there is none.
335
+ In 0.1.0 it was dropped without a word. A refused unsubscribe is said
336
+ on the console only (`igni bridge: unsubscribing from <signal> failed: …`).
337
+
338
+ ## Installing
339
+
340
+ From npm, with the stylesheet a page is drawn with:
341
+
342
+ ```bash
343
+ npm install @ignite-ember/extension-bridge @ignite-ember/ui-css
344
+ ```
345
+
346
+ Each release's tarballs are also attached to igni-sdk's GitHub release
347
+ (`sdk-v<version>`), for a build that cannot reach npmjs. Versions are in
348
+ igni-sdk's `docs/PUBLISHING_THE_SDKS.md`.
349
+
350
+ ## The source, and a build beside it
351
+
352
+ This package ships its TypeScript source, and a compiled build beside it.
353
+
354
+ A bundler that compiles TypeScript (Vite, esbuild, Rollup with a TS
355
+ plugin) takes the source and compiles it as it compiles the rest of
356
+ your extension. A consumer that does not compile `node_modules` — Node
357
+ itself, a test runner that is not told to transform it, a tool that
358
+ reads the types — takes the build: plain JavaScript, and the
359
+ declarations that go with it.
360
+
361
+ The build is ES2022 modules, with source maps back to the TypeScript.
362
+ `exports` points at it for `node`, and the `types` condition points at
363
+ its declarations for everyone, so `import { connect } from
364
+ "@ignite-ember/extension-bridge"` names the same things in a bundler
365
+ and in Node, and `tsc` finds them under `moduleResolution: node16`.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The guest half: what an extension's page imports to reach igni.
3
+ *
4
+ * This is the file that becomes a published package. Nothing in it
5
+ * imports from the rest of the app, and nothing in it is trusted by
6
+ * the host — every check is on the other side. What it owes an
7
+ * extension author is an object that behaves like the client they
8
+ * would have had if their panel were part of the app, so that porting
9
+ * one is not a rewrite.
10
+ *
11
+ * The shape it presents is `rpc(method, args, timeoutMs)`, which is
12
+ * the whole surface the first panel ported behind it used. Everything else here —
13
+ * navigate, close, theme, params — is what a panel needed from the
14
+ * app around it and used to get by being inside it.
15
+ */
16
+ import type { Bridge } from "./contract.js";
17
+ import { type ExtensionSettings, type LaunchParams } from "./protocol.js";
18
+ /**
19
+ * Wait for the host's `hello`, then hand back the bridge.
20
+ *
21
+ * Connecting is asynchronous because the host issues the nonce, and
22
+ * without one there is nothing to say. An extension that renders
23
+ * before awaiting this is rendering before it knows which extension
24
+ * it is.
25
+ *
26
+ * `P` and `S` name the extension's own launch parameters and settings;
27
+ * the bridge passes on what the host sent without checking it against
28
+ * them.
29
+ *
30
+ * @param options — how long to wait for the host's `hello` before
31
+ * giving up: `timeoutMs`, in milliseconds, and thirty seconds by
32
+ * default.
33
+ */
34
+ export declare function connect<P extends LaunchParams = LaunchParams, S extends ExtensionSettings = ExtensionSettings>(options?: {
35
+ timeoutMs?: number;
36
+ }): Promise<Bridge<P, S>>;
37
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAGlB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CACrB,CAAC,SAAS,YAAY,GAAG,YAAY,EACrC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,EAC/C,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAmC7D"}