@impro.social/impro-plugin 0.0.23 → 0.0.25

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 (3) hide show
  1. package/main.d.ts +170 -13
  2. package/main.js +208 -16
  3. package/package.json +3 -2
package/main.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Proxied fetch through the host. Requires the `"networkRequest"` permission
3
- * scope and the target URL must be covered by the plugin's manifest allowlist.
2
+ * Proxied fetch through the host. The target URL must match one of the
3
+ * `permissions.fetch` URL patterns declared in the plugin's manifest, which
4
+ * the user grants at install.
4
5
  * `init` accepts `method`, `headers` (plain object, `Headers`, `Map`, or
5
6
  * `[name, value]` iterable), and a string `body`. Resolves to a
6
7
  * {@link PluginResponse}.
@@ -9,6 +10,30 @@
9
10
  * @returns {Promise<PluginResponse>}
10
11
  */
11
12
  export function fetch(url: string, init?: PluginFetchInit): Promise<PluginResponse>;
13
+ /**
14
+ * Asks the user to grant this plugin network access to `url`'s origin — for
15
+ * endpoints the plugin can't know in advance, such as a user-supplied API
16
+ * provider. Requires `permissions.userFetch` in the manifest.
17
+ *
18
+ * Grants are origin-scoped (scheme, host, and port; the path is ignored) and
19
+ * persist until the user revokes them in the app's plugin settings. Resolves
20
+ * `true` without prompting if the origin is already permitted, so it is safe
21
+ * to call before every request. Resolves `false` if the user declines, if
22
+ * `url` can't be an origin, or if a prompt for this plugin is already open.
23
+ *
24
+ * Any credential for the endpoint is the plugin's to hold — use
25
+ * {@link Plugin.saveLocalData} rather than {@link Plugin.saveData}, which
26
+ * syncs through the user's account preferences.
27
+ * @param {string} url
28
+ * @returns {Promise<boolean>}
29
+ */
30
+ export function requestFetchPermission(url: string): Promise<boolean>;
31
+ /**
32
+ * The origins the user has granted this plugin, as fetch patterns
33
+ * (`https://example.com/*`). Manifest-declared permissions are not included.
34
+ * @returns {Promise<string[]>}
35
+ */
36
+ export function getUserGrantedFetchOrigins(): Promise<string[]>;
12
37
  /**
13
38
  * Convenience wrapper that returns a new {@link FlattenedTokens} for `tokens`.
14
39
  * @param {RichTextToken[]} tokens
@@ -26,6 +51,15 @@ export function flattenForScan(tokens: RichTextToken[]): FlattenedTokens;
26
51
  * Paginated response from `getKnownFollowers`: `{ followers, cursor }`.
27
52
  * @typedef {Record<string, unknown>} RepoRecord
28
53
  * A raw repo record: `{ uri, cid, value }`.
54
+ * @typedef {Record<string, unknown>} PostThreadView
55
+ * Hydrated thread for a post: the post plus `parent`/`replies`.
56
+ * @typedef {Record<string, unknown>} ListView
57
+ * An `app.bsky.graph.defs#listView` shape.
58
+ * @typedef {Record<string, unknown>} FeedGeneratorView
59
+ * An `app.bsky.feed.defs#generatorView` shape.
60
+ * @typedef {{ ok: boolean, status: number, data: unknown }} XrpcQueryResponse
61
+ * Raw XRPC response: on failure `data` is the error body
62
+ * (`{ error, message }`) when the service provided one.
29
63
  * @typedef {{ did: string, collection: string, rkey: string }} BacklinkRecord
30
64
  * A record that links to a queried subject.
31
65
  * @typedef {Record<string, unknown>} FeedItem
@@ -71,6 +105,8 @@ export class SimpleUUID {
71
105
  export class MenuItem {
72
106
  title: string;
73
107
  icon: string | VirtualEl | null;
108
+ /** @type {string | null} */
109
+ url: string | null;
74
110
  /** @internal */
75
111
  _callback: () => void;
76
112
  /**
@@ -86,6 +122,14 @@ export class MenuItem {
86
122
  * @returns {this}
87
123
  */
88
124
  setIcon(icon: string | VirtualEl): this;
125
+ /**
126
+ * Make the item a link that opens `url` in a new tab. The URL must match
127
+ * one of the `permissions.open` patterns in the plugin's manifest, or the
128
+ * host drops the item. Link items don't call their `onClick` handler.
129
+ * @param {string} url
130
+ * @returns {this}
131
+ */
132
+ setUrl(url: string): this;
89
133
  /**
90
134
  * Called when the user activates the item.
91
135
  * @param {() => void} callback
@@ -111,6 +155,7 @@ export class Menu {
111
155
  _serialize(): {
112
156
  title: string;
113
157
  icon: string | SerializedElement | null;
158
+ url: string | null;
114
159
  handlerId: number;
115
160
  }[];
116
161
  }
@@ -214,6 +259,84 @@ export class PluginData {
214
259
  source: string;
215
260
  limit?: number;
216
261
  }): Promise<BacklinkRecord[]>;
262
+ /**
263
+ * Fetch the hydrated thread around a post (the post, its parents, and
264
+ * replies), as the host renders it.
265
+ * @param {string} uri
266
+ * @returns {Promise<PostThreadView | null>}
267
+ */
268
+ getPostThread(uri: string): Promise<PostThreadView | null>;
269
+ /**
270
+ * Fetch a list's metadata view by AT-URI.
271
+ * @param {string} uri
272
+ * @returns {Promise<ListView | null>}
273
+ */
274
+ getList(uri: string): Promise<ListView | null>;
275
+ /**
276
+ * Fetch a feed generator view by AT-URI.
277
+ * @param {string} uri
278
+ * @returns {Promise<FeedGeneratorView | null>}
279
+ */
280
+ getFeedGenerator(uri: string): Promise<FeedGeneratorView | null>;
281
+ /**
282
+ * The current user's full hydrated profile (unlike `app.currentUser`,
283
+ * which carries only `did` and `handle`). `null` when signed out.
284
+ * @returns {Promise<DetailedProfileView | null>}
285
+ */
286
+ getCurrentUserProfile(): Promise<DetailedProfileView | null>;
287
+ /**
288
+ * Call a read-only AppView query endpoint through the current user's
289
+ * session and get the raw XRPC response back.
290
+ *
291
+ * Only an allowlisted set of `app.bsky.*` query NSIDs is accepted;
292
+ * viewer-private queries (mutes, bookmarks, notifications, preferences,
293
+ * timeline, ...) additionally require the `"privateData"` action
294
+ * permission. Unlike the curated methods above, responses are canonical
295
+ * server state — they may briefly disagree with what the host UI shows
296
+ * while an optimistic update is in flight, and results are not cached.
297
+ *
298
+ * @param {string} nsid e.g. `"app.bsky.feed.getQuotes"`
299
+ * @param {Record<string, string | number | boolean | string[]>} [params]
300
+ * @returns {Promise<XrpcQueryResponse>}
301
+ */
302
+ xrpcQuery(nsid: string, params?: Record<string, string | number | boolean | string[]>): Promise<XrpcQueryResponse>;
303
+ }
304
+ /**
305
+ * Host-mediated persistent storage for binary data too large for
306
+ * {@link Plugin.loadLocalData}/{@link Plugin.saveLocalData}.
307
+ * Namespaced per plugin; survives reloads but is cleared on
308
+ * uninstall.
309
+ */
310
+ export class BinaryCache {
311
+ /**
312
+ * @param {string} key
313
+ * @returns {Promise<ArrayBuffer | null>}
314
+ */
315
+ get(key: string): Promise<ArrayBuffer | null>;
316
+ /**
317
+ * Whether an entry is stored under `key`, without transferring its bytes.
318
+ *
319
+ * @param {string} key
320
+ * @returns {Promise<boolean>}
321
+ */
322
+ has(key: string): Promise<boolean>;
323
+ /**
324
+ * Every key this plugin currently has stored, in no particular order.
325
+ *
326
+ * @returns {Promise<string[]>}
327
+ */
328
+ keys(): Promise<string[]>;
329
+ /**
330
+ * @param {string} key
331
+ * @param {ArrayBuffer | ArrayBufferView} data
332
+ * @returns {Promise<void>}
333
+ */
334
+ put(key: string, data: ArrayBuffer | ArrayBufferView): Promise<void>;
335
+ /**
336
+ * @param {string} key
337
+ * @returns {Promise<void>}
338
+ */
339
+ delete(key: string): Promise<void>;
217
340
  }
218
341
  /**
219
342
  * The plugin's handle to the running impro app. Exposed as `this.app` on a
@@ -229,6 +352,8 @@ export class App {
229
352
  currentUser: ProfileView | null;
230
353
  /** Read-only appview accessors — see {@link PluginData}. */
231
354
  data: PluginData;
355
+ /** Host-mediated binary storage — see {@link BinaryCache}. */
356
+ binaryCache: BinaryCache;
232
357
  /**
233
358
  * Register an event listener. Supported events:
234
359
  *
@@ -299,9 +424,10 @@ export class App {
299
424
  showMoreLikeThis(postUri: string, feedUri: string): Promise<void>;
300
425
  }
301
426
  /**
302
- * Response returned from {@link fetch}. Body is buffered by the host and
303
- * exposed as text or parsed JSON. `status`, `ok`, and `headers` (a `Map`)
304
- * mirror the underlying HTTP response.
427
+ * Response returned from {@link fetch}. The host buffers the raw response
428
+ * bytes and sends them as an `ArrayBuffer`, and this class decodes them on
429
+ * demand depending on which accessor is called. `status`, `ok`, and `headers`
430
+ * (a `Map`) mirror the underlying HTTP response.
305
431
  */
306
432
  export class PluginResponse {
307
433
  /**
@@ -316,7 +442,12 @@ export class PluginResponse {
316
442
  /** @type {Map<string, string>} */
317
443
  headers: Map<string, string>;
318
444
  /**
319
- * Resolves with the response body as a string.
445
+ * Resolves with the raw response bytes.
446
+ * @returns {Promise<ArrayBuffer>}
447
+ */
448
+ arrayBuffer(): Promise<ArrayBuffer>;
449
+ /**
450
+ * Resolves with the response body decoded as UTF-8 text.
320
451
  * @returns {Promise<string>}
321
452
  */
322
453
  text(): Promise<string>;
@@ -1160,6 +1291,27 @@ export type KnownFollowersResponse = Record<string, unknown>;
1160
1291
  * A raw repo record: `{ uri, cid, value }`.
1161
1292
  */
1162
1293
  export type RepoRecord = Record<string, unknown>;
1294
+ /**
1295
+ * Hydrated thread for a post: the post plus `parent`/`replies`.
1296
+ */
1297
+ export type PostThreadView = Record<string, unknown>;
1298
+ /**
1299
+ * An `app.bsky.graph.defs#listView` shape.
1300
+ */
1301
+ export type ListView = Record<string, unknown>;
1302
+ /**
1303
+ * An `app.bsky.feed.defs#generatorView` shape.
1304
+ */
1305
+ export type FeedGeneratorView = Record<string, unknown>;
1306
+ /**
1307
+ * Raw XRPC response: on failure `data` is the error body
1308
+ * (`{ error, message }`) when the service provided one.
1309
+ */
1310
+ export type XrpcQueryResponse = {
1311
+ ok: boolean;
1312
+ status: number;
1313
+ data: unknown;
1314
+ };
1163
1315
  /**
1164
1316
  * A record that links to a queried subject.
1165
1317
  */
@@ -1289,10 +1441,11 @@ export type CloneableObject = {
1289
1441
  */
1290
1442
  export type CloneableArray = Cloneable[];
1291
1443
  /**
1292
- * JSON-shaped data — the only thing that can cross between a plugin and the
1293
- * host. Functions, class instances, `Date`, `Map` and friends cannot.
1444
+ * JSON-shaped data, plus `ArrayBuffer` for binary payloads — the only thing
1445
+ * that can cross between a plugin and the host. Functions, class instances,
1446
+ * `Date`, `Map` and friends cannot.
1294
1447
  */
1295
- export type Cloneable = null | undefined | boolean | number | string | CloneableArray | CloneableObject;
1448
+ export type Cloneable = null | undefined | boolean | number | string | ArrayBuffer | CloneableArray | CloneableObject;
1296
1449
  /**
1297
1450
  * {@internal}
1298
1451
  */
@@ -1402,12 +1555,15 @@ export type HostCallMessage = {
1402
1555
  args: Cloneable[];
1403
1556
  };
1404
1557
  /**
1405
- * {@internal} The host answering a {@link hostCall}.
1558
+ * {@internal} The host answering a {@link hostCall}. Wider than
1559
+ * {@link Cloneable} because {@link SerializedFetchResponse} carries its
1560
+ * body as an `ArrayBuffer`, which structured clone handles but JSON
1561
+ * cannot.
1406
1562
  */
1407
1563
  export type HostResultMessage = {
1408
1564
  type: "hostResult";
1409
1565
  hostCallId: number;
1410
- value?: Cloneable;
1566
+ value?: Cloneable | SerializedFetchResponse;
1411
1567
  error?: string;
1412
1568
  };
1413
1569
  /**
@@ -1425,13 +1581,14 @@ export type HostEventMessage = {
1425
1581
  */
1426
1582
  export type HostMessage = HostCallMessage | HostResultMessage | HostEventMessage;
1427
1583
  /**
1428
- * {@internal} The host's reply to a proxied {@link fetch}.
1584
+ * {@internal} The host's reply to a proxied {@link fetch}. `body` is
1585
+ * always the raw response bytes (see {@link PluginResponse}).
1429
1586
  */
1430
1587
  export type SerializedFetchResponse = {
1431
1588
  status: number;
1432
1589
  ok: boolean;
1433
1590
  headers: Record<string, string>;
1434
- body: string;
1591
+ body: ArrayBuffer;
1435
1592
  };
1436
1593
  /**
1437
1594
  * {@internal} A {@link PluginFetchInit} with its headers flattened for transfer.
package/main.js CHANGED
@@ -9,6 +9,15 @@
9
9
  * Paginated response from `getKnownFollowers`: `{ followers, cursor }`.
10
10
  * @typedef {Record<string, unknown>} RepoRecord
11
11
  * A raw repo record: `{ uri, cid, value }`.
12
+ * @typedef {Record<string, unknown>} PostThreadView
13
+ * Hydrated thread for a post: the post plus `parent`/`replies`.
14
+ * @typedef {Record<string, unknown>} ListView
15
+ * An `app.bsky.graph.defs#listView` shape.
16
+ * @typedef {Record<string, unknown>} FeedGeneratorView
17
+ * An `app.bsky.feed.defs#generatorView` shape.
18
+ * @typedef {{ ok: boolean, status: number, data: unknown }} XrpcQueryResponse
19
+ * Raw XRPC response: on failure `data` is the error body
20
+ * (`{ error, message }`) when the service provided one.
12
21
  * @typedef {{ did: string, collection: string, rkey: string }} BacklinkRecord
13
22
  * A record that links to a queried subject.
14
23
  * @typedef {Record<string, unknown>} FeedItem
@@ -161,6 +170,8 @@ export class MenuItem {
161
170
  constructor() {
162
171
  this.title = "";
163
172
  this.icon = null;
173
+ /** @type {string | null} */
174
+ this.url = null;
164
175
  /** @internal */
165
176
  this._callback = () => {};
166
177
  }
@@ -183,6 +194,17 @@ export class MenuItem {
183
194
  this.icon = icon;
184
195
  return this;
185
196
  }
197
+ /**
198
+ * Make the item a link that opens `url` in a new tab. The URL must match
199
+ * one of the `permissions.open` patterns in the plugin's manifest, or the
200
+ * host drops the item. Link items don't call their `onClick` handler.
201
+ * @param {string} url
202
+ * @returns {this}
203
+ */
204
+ setUrl(url) {
205
+ this.url = url;
206
+ return this;
207
+ }
186
208
  /**
187
209
  * Called when the user activates the item.
188
210
  * @param {() => void} callback
@@ -222,7 +244,7 @@ export class Menu {
222
244
  callHandlers.set(handlerId, item._callback);
223
245
  const icon =
224
246
  item.icon instanceof VirtualEl ? item.icon._serialize() : item.icon;
225
- return { title: item.title, icon, handlerId };
247
+ return { title: item.title, icon, url: item.url, handlerId };
226
248
  });
227
249
  }
228
250
  }
@@ -357,6 +379,125 @@ export class PluginData {
357
379
  hostCall("getBacklinks", { subject, source, limit })
358
380
  );
359
381
  }
382
+ /**
383
+ * Fetch the hydrated thread around a post (the post, its parents, and
384
+ * replies), as the host renders it.
385
+ * @param {string} uri
386
+ * @returns {Promise<PostThreadView | null>}
387
+ */
388
+ getPostThread(uri) {
389
+ return /** @type {Promise<PostThreadView | null>} */ (
390
+ hostCall("getPostThread", { uri })
391
+ );
392
+ }
393
+ /**
394
+ * Fetch a list's metadata view by AT-URI.
395
+ * @param {string} uri
396
+ * @returns {Promise<ListView | null>}
397
+ */
398
+ getList(uri) {
399
+ return /** @type {Promise<ListView | null>} */ (
400
+ hostCall("getList", { uri })
401
+ );
402
+ }
403
+ /**
404
+ * Fetch a feed generator view by AT-URI.
405
+ * @param {string} uri
406
+ * @returns {Promise<FeedGeneratorView | null>}
407
+ */
408
+ getFeedGenerator(uri) {
409
+ return /** @type {Promise<FeedGeneratorView | null>} */ (
410
+ hostCall("getFeedGenerator", { uri })
411
+ );
412
+ }
413
+ /**
414
+ * The current user's full hydrated profile (unlike `app.currentUser`,
415
+ * which carries only `did` and `handle`). `null` when signed out.
416
+ * @returns {Promise<DetailedProfileView | null>}
417
+ */
418
+ getCurrentUserProfile() {
419
+ return /** @type {Promise<DetailedProfileView | null>} */ (
420
+ hostCall("getCurrentUserProfile", {})
421
+ );
422
+ }
423
+ /**
424
+ * Call a read-only AppView query endpoint through the current user's
425
+ * session and get the raw XRPC response back.
426
+ *
427
+ * Only an allowlisted set of `app.bsky.*` query NSIDs is accepted;
428
+ * viewer-private queries (mutes, bookmarks, notifications, preferences,
429
+ * timeline, ...) additionally require the `"privateData"` action
430
+ * permission. Unlike the curated methods above, responses are canonical
431
+ * server state — they may briefly disagree with what the host UI shows
432
+ * while an optimistic update is in flight, and results are not cached.
433
+ *
434
+ * @param {string} nsid e.g. `"app.bsky.feed.getQuotes"`
435
+ * @param {Record<string, string | number | boolean | string[]>} [params]
436
+ * @returns {Promise<XrpcQueryResponse>}
437
+ */
438
+ xrpcQuery(nsid, params = {}) {
439
+ return /** @type {Promise<XrpcQueryResponse>} */ (
440
+ hostCall("xrpcQuery", { nsid, params })
441
+ );
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Host-mediated persistent storage for binary data too large for
447
+ * {@link Plugin.loadLocalData}/{@link Plugin.saveLocalData}.
448
+ * Namespaced per plugin; survives reloads but is cleared on
449
+ * uninstall.
450
+ */
451
+ export class BinaryCache {
452
+ /**
453
+ * @param {string} key
454
+ * @returns {Promise<ArrayBuffer | null>}
455
+ */
456
+ async get(key) {
457
+ return /** @type {Promise<ArrayBuffer | null>} */ (
458
+ hostCall("getBinaryCacheEntry", { key: String(key) })
459
+ );
460
+ }
461
+ /**
462
+ * Whether an entry is stored under `key`, without transferring its bytes.
463
+ *
464
+ * @param {string} key
465
+ * @returns {Promise<boolean>}
466
+ */
467
+ async has(key) {
468
+ return /** @type {boolean} */ (
469
+ await hostCall("hasBinaryCacheEntry", { key: String(key) })
470
+ );
471
+ }
472
+ /**
473
+ * Every key this plugin currently has stored, in no particular order.
474
+ *
475
+ * @returns {Promise<string[]>}
476
+ */
477
+ async keys() {
478
+ return /** @type {string[]} */ (await hostCall("listBinaryCacheEntries"));
479
+ }
480
+ /**
481
+ * @param {string} key
482
+ * @param {ArrayBuffer | ArrayBufferView} data
483
+ * @returns {Promise<void>}
484
+ */
485
+ async put(key, data) {
486
+ // A view may be a window onto a larger buffer, so send just its bytes.
487
+ const buffer = /** @type {ArrayBuffer} */ (
488
+ data instanceof ArrayBuffer
489
+ ? data
490
+ : data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)
491
+ );
492
+ await hostCall("putBinaryCacheEntry", { key: String(key), data: buffer });
493
+ }
494
+ /**
495
+ * @param {string} key
496
+ * @returns {Promise<void>}
497
+ */
498
+ async delete(key) {
499
+ await hostCall("deleteBinaryCacheEntry", { key: String(key) });
500
+ }
360
501
  }
361
502
 
362
503
  /**
@@ -375,6 +516,8 @@ export class App {
375
516
  this.currentUser = null;
376
517
  /** Read-only appview accessors — see {@link PluginData}. */
377
518
  this.data = new PluginData();
519
+ /** Host-mediated binary storage — see {@link BinaryCache}. */
520
+ this.binaryCache = new BinaryCache();
378
521
  }
379
522
  /**
380
523
  * Register an event listener. Supported events:
@@ -479,8 +622,9 @@ export class App {
479
622
  }
480
623
 
481
624
  /**
482
- * Proxied fetch through the host. Requires the `"networkRequest"` permission
483
- * scope and the target URL must be covered by the plugin's manifest allowlist.
625
+ * Proxied fetch through the host. The target URL must match one of the
626
+ * `permissions.fetch` URL patterns declared in the plugin's manifest, which
627
+ * the user grants at install.
484
628
  * `init` accepts `method`, `headers` (plain object, `Headers`, `Map`, or
485
629
  * `[name, value]` iterable), and a string `body`. Resolves to a
486
630
  * {@link PluginResponse}.
@@ -495,6 +639,40 @@ export async function fetch(url, init = {}) {
495
639
  return new PluginResponse(result);
496
640
  }
497
641
 
642
+ /**
643
+ * Asks the user to grant this plugin network access to `url`'s origin — for
644
+ * endpoints the plugin can't know in advance, such as a user-supplied API
645
+ * provider. Requires `permissions.userFetch` in the manifest.
646
+ *
647
+ * Grants are origin-scoped (scheme, host, and port; the path is ignored) and
648
+ * persist until the user revokes them in the app's plugin settings. Resolves
649
+ * `true` without prompting if the origin is already permitted, so it is safe
650
+ * to call before every request. Resolves `false` if the user declines, if
651
+ * `url` can't be an origin, or if a prompt for this plugin is already open.
652
+ *
653
+ * Any credential for the endpoint is the plugin's to hold — use
654
+ * {@link Plugin.saveLocalData} rather than {@link Plugin.saveData}, which
655
+ * syncs through the user's account preferences.
656
+ * @param {string} url
657
+ * @returns {Promise<boolean>}
658
+ */
659
+ export async function requestFetchPermission(url) {
660
+ return /** @type {boolean} */ (
661
+ await hostCall("requestFetchPermission", { url })
662
+ );
663
+ }
664
+
665
+ /**
666
+ * The origins the user has granted this plugin, as fetch patterns
667
+ * (`https://example.com/*`). Manifest-declared permissions are not included.
668
+ * @returns {Promise<string[]>}
669
+ */
670
+ export async function getUserGrantedFetchOrigins() {
671
+ return /** @type {string[]} */ (
672
+ await hostCall("getUserGrantedFetchOrigins", {})
673
+ );
674
+ }
675
+
498
676
  /**
499
677
  * @param {unknown} value
500
678
  * @returns {value is { forEach: (callback: (value: string, name: string) => void) => void }}
@@ -553,11 +731,13 @@ function serializeFetchInit(init) {
553
731
  }
554
732
 
555
733
  /**
556
- * Response returned from {@link fetch}. Body is buffered by the host and
557
- * exposed as text or parsed JSON. `status`, `ok`, and `headers` (a `Map`)
558
- * mirror the underlying HTTP response.
734
+ * Response returned from {@link fetch}. The host buffers the raw response
735
+ * bytes and sends them as an `ArrayBuffer`, and this class decodes them on
736
+ * demand depending on which accessor is called. `status`, `ok`, and `headers`
737
+ * (a `Map`) mirror the underlying HTTP response.
559
738
  */
560
739
  export class PluginResponse {
740
+ /** @type {ArrayBuffer} raw response bytes */
561
741
  #body;
562
742
  /**
563
743
  * @internal
@@ -573,18 +753,25 @@ export class PluginResponse {
573
753
  this.#body = body;
574
754
  }
575
755
  /**
576
- * Resolves with the response body as a string.
756
+ * Resolves with the raw response bytes.
757
+ * @returns {Promise<ArrayBuffer>}
758
+ */
759
+ async arrayBuffer() {
760
+ return this.#body;
761
+ }
762
+ /**
763
+ * Resolves with the response body decoded as UTF-8 text.
577
764
  * @returns {Promise<string>}
578
765
  */
579
766
  async text() {
580
- return this.#body;
767
+ return new TextDecoder().decode(await this.arrayBuffer());
581
768
  }
582
769
  /**
583
770
  * Resolves with the response body parsed as JSON.
584
771
  * @returns {Promise<unknown>}
585
772
  */
586
773
  async json() {
587
- return JSON.parse(this.#body);
774
+ return JSON.parse(await this.text());
588
775
  }
589
776
  }
590
777
 
@@ -1982,9 +2169,10 @@ export class VirtualEl {
1982
2169
  * An object whose values are all {@link Cloneable}.
1983
2170
  * @typedef {Cloneable[]} CloneableArray
1984
2171
  * An array of {@link Cloneable} values.
1985
- * @typedef {null | undefined | boolean | number | string | CloneableArray | CloneableObject} Cloneable
1986
- * JSON-shaped data — the only thing that can cross between a plugin and the
1987
- * host. Functions, class instances, `Date`, `Map` and friends cannot.
2172
+ * @typedef {null | undefined | boolean | number | string | ArrayBuffer | CloneableArray | CloneableObject} Cloneable
2173
+ * JSON-shaped data, plus `ArrayBuffer` for binary payloads — the only thing
2174
+ * that can cross between a plugin and the host. Functions, class instances,
2175
+ * `Date`, `Map` and friends cannot.
1988
2176
  * @typedef {{ type: "register", target: "eventListener", event: string, handlerId: number }} RegisterEventListenerMessage
1989
2177
  * {@internal}
1990
2178
  * @typedef {{ type: "register", target: "sidebarItem", icon: string | SerializedElement, title: string, handlerId: number }} RegisterSidebarItemMessage
@@ -2011,14 +2199,18 @@ export class VirtualEl {
2011
2199
  * {@internal} Anything this worker may post to the host.
2012
2200
  * @typedef {{ type: "call", callId: number, handlerId: number, args: Cloneable[] }} HostCallMessage
2013
2201
  * {@internal} The host invoking a handler this worker registered.
2014
- * @typedef {{ type: "hostResult", hostCallId: number, value?: Cloneable, error?: string }} HostResultMessage
2015
- * {@internal} The host answering a {@link hostCall}.
2202
+ * @typedef {{ type: "hostResult", hostCallId: number, value?: Cloneable | SerializedFetchResponse, error?: string }} HostResultMessage
2203
+ * {@internal} The host answering a {@link hostCall}. Wider than
2204
+ * {@link Cloneable} because {@link SerializedFetchResponse} carries its
2205
+ * body as an `ArrayBuffer`, which structured clone handles but JSON
2206
+ * cannot.
2016
2207
  * @typedef {{ type: "event", event: "modalDismissed", data: { modalId: number } }} HostEventMessage
2017
2208
  * {@internal} An out-of-band notification from the host.
2018
2209
  * @typedef {HostCallMessage | HostResultMessage | HostEventMessage} HostMessage
2019
2210
  * {@internal} Anything the host may post to this worker.
2020
- * @typedef {{ status: number, ok: boolean, headers: Record<string, string>, body: string }} SerializedFetchResponse
2021
- * {@internal} The host's reply to a proxied {@link fetch}.
2211
+ * @typedef {{ status: number, ok: boolean, headers: Record<string, string>, body: ArrayBuffer }} SerializedFetchResponse
2212
+ * {@internal} The host's reply to a proxied {@link fetch}. `body` is
2213
+ * always the raw response bytes (see {@link PluginResponse}).
2022
2214
  * @typedef {{ method?: string, headers?: Record<string, string>, body?: string }} SerializedFetchInit
2023
2215
  * {@internal} A {@link PluginFetchInit} with its headers flattened for transfer.
2024
2216
  * @typedef {Record<string, unknown>} SerializedRichTextToken
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@impro.social/impro-plugin",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "type": "module",
5
5
  "main": "main.js",
6
6
  "types": "./main.d.ts",
@@ -22,6 +22,7 @@
22
22
  ],
23
23
  "devDependencies": {
24
24
  "typedoc": "^0.28.20",
25
- "typedoc-plugin-markdown": "^4.12.0"
25
+ "typedoc-plugin-markdown": "^4.12.0",
26
+ "typescript": "^5.9.3"
26
27
  }
27
28
  }