@limrun/api 0.79.0 → 0.79.2

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 (59) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/destination-tunnel-dialer.d.mts.map +1 -1
  3. package/destination-tunnel-dialer.d.ts.map +1 -1
  4. package/destination-tunnel-dialer.js +23 -14
  5. package/destination-tunnel-dialer.js.map +1 -1
  6. package/destination-tunnel-dialer.mjs +23 -14
  7. package/destination-tunnel-dialer.mjs.map +1 -1
  8. package/internal/app-log-events.d.mts +21 -0
  9. package/internal/app-log-events.d.mts.map +1 -0
  10. package/internal/app-log-events.d.ts +21 -0
  11. package/internal/app-log-events.d.ts.map +1 -0
  12. package/internal/app-log-events.js +73 -0
  13. package/internal/app-log-events.js.map +1 -0
  14. package/internal/app-log-events.mjs +69 -0
  15. package/internal/app-log-events.mjs.map +1 -0
  16. package/internal/signaling-transport.d.mts +79 -0
  17. package/internal/signaling-transport.d.mts.map +1 -0
  18. package/internal/signaling-transport.d.ts +79 -0
  19. package/internal/signaling-transport.d.ts.map +1 -0
  20. package/internal/signaling-transport.js +320 -0
  21. package/internal/signaling-transport.js.map +1 -0
  22. package/internal/signaling-transport.mjs +316 -0
  23. package/internal/signaling-transport.mjs.map +1 -0
  24. package/ios-client.d.mts +4 -9
  25. package/ios-client.d.mts.map +1 -1
  26. package/ios-client.d.ts +4 -9
  27. package/ios-client.d.ts.map +1 -1
  28. package/ios-client.js +172 -412
  29. package/ios-client.js.map +1 -1
  30. package/ios-client.mjs +173 -413
  31. package/ios-client.mjs.map +1 -1
  32. package/log-stream.d.mts +11 -4
  33. package/log-stream.d.mts.map +1 -1
  34. package/log-stream.d.ts +11 -4
  35. package/log-stream.d.ts.map +1 -1
  36. package/log-stream.js +45 -8
  37. package/log-stream.js.map +1 -1
  38. package/log-stream.mjs +45 -8
  39. package/log-stream.mjs.map +1 -1
  40. package/package.json +1 -1
  41. package/resources/macos-instances-helpers.d.mts +12 -0
  42. package/resources/macos-instances-helpers.d.mts.map +1 -1
  43. package/resources/macos-instances-helpers.d.ts +12 -0
  44. package/resources/macos-instances-helpers.d.ts.map +1 -1
  45. package/resources/macos-instances-helpers.js +118 -141
  46. package/resources/macos-instances-helpers.js.map +1 -1
  47. package/resources/macos-instances-helpers.mjs +118 -141
  48. package/resources/macos-instances-helpers.mjs.map +1 -1
  49. package/src/destination-tunnel-dialer.ts +23 -14
  50. package/src/internal/app-log-events.ts +76 -0
  51. package/src/internal/signaling-transport.ts +454 -0
  52. package/src/ios-client.ts +193 -471
  53. package/src/log-stream.ts +54 -11
  54. package/src/resources/macos-instances-helpers.ts +153 -136
  55. package/src/version.ts +1 -1
  56. package/version.d.mts +1 -1
  57. package/version.d.ts +1 -1
  58. package/version.js +1 -1
  59. package/version.mjs +1 -1
package/src/log-stream.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { WebSocket, Data } from 'ws';
3
3
  import { nodeProxyTransport } from './internal/proxy-transport';
4
+ import { followAppLogEvents, type AppLogEventsSource } from './internal/app-log-events';
4
5
 
5
6
  /**
6
7
  * Handle for a running log stream subscription (app logs, syslog, or logcat).
@@ -24,26 +25,34 @@ type LogStreamMessage = {
24
25
  };
25
26
 
26
27
  /**
27
- * Log stream with dedicated WebSocket connection.
28
- * Each LogStream opens its own WebSocket to isolate log traffic from signaling.
28
+ * Log stream with a connection of its own, separate from signaling: a WebSocket for syslog and
29
+ * logcat, and server-sent events for app logs.
29
30
  */
30
31
  export class LogStream extends EventEmitter {
31
32
  private ws: WebSocket | null = null;
32
33
  private subscriptionId: string;
33
34
  private stopped = false;
34
35
  private terminateMessageType: string;
36
+ private sse: AbortController | null = null;
35
37
 
36
- /** @internal */
38
+ /**
39
+ * @internal - Either a signaling WebSocket subscription, or the instance's app log
40
+ * server-sent events (`GET /app-logs/stream`), which emit one line per event.
41
+ */
37
42
  constructor(
38
- private wsUrl: string,
39
- private subscribeMessage: object,
40
- terminateMessageType: string,
41
- subscriptionId: string,
43
+ private wsUrl: string | AppLogEventsSource,
44
+ private subscribeMessage: object = {},
45
+ terminateMessageType: string = '',
46
+ subscriptionId: string = '',
42
47
  ) {
43
48
  super();
44
49
  this.terminateMessageType = terminateMessageType;
45
50
  this.subscriptionId = subscriptionId;
46
- this._connect();
51
+ if (typeof wsUrl === 'string') {
52
+ this._connect(wsUrl);
53
+ } else {
54
+ this._follow(wsUrl);
55
+ }
47
56
  }
48
57
 
49
58
  override on<E extends keyof LogStreamEvents>(event: E, listener: LogStreamEvents[E]): this {
@@ -62,6 +71,8 @@ export class LogStream extends EventEmitter {
62
71
  stop(): void {
63
72
  if (this.stopped) return;
64
73
  this.stopped = true;
74
+ this.sse?.abort();
75
+ this.sse = null;
65
76
 
66
77
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
67
78
  // Send terminate message before closing
@@ -77,10 +88,42 @@ export class LogStream extends EventEmitter {
77
88
  this.emit('close');
78
89
  }
79
90
 
91
+ /** @internal - Follow the app log's server-sent events */
92
+ private _follow(source: AppLogEventsSource): void {
93
+ const controller = new AbortController();
94
+ this.sse = controller;
95
+ // Emit after the caller attached its listeners, as the WebSocket stream does.
96
+ void Promise.resolve()
97
+ .then(() =>
98
+ followAppLogEvents(
99
+ source,
100
+ (line) => {
101
+ if (this.stopped) return;
102
+ this.emit('lines', [line]);
103
+ this.emit('line', line);
104
+ },
105
+ controller.signal,
106
+ ),
107
+ )
108
+ .then(
109
+ () => {
110
+ if (this.stopped) return;
111
+ this.stopped = true;
112
+ this.sse = null;
113
+ this.emit('close');
114
+ },
115
+ (error: unknown) => {
116
+ if (this.stopped) return;
117
+ this.emit('error', error instanceof Error ? error : new Error(String(error)));
118
+ this.stop();
119
+ },
120
+ );
121
+ }
122
+
80
123
  /** @internal - Establish the dedicated WebSocket connection */
81
- private _connect(): void {
82
- const proxyAgent = nodeProxyTransport.getWebSocketAgent(this.wsUrl);
83
- this.ws = new WebSocket(this.wsUrl, proxyAgent ? { agent: proxyAgent } : {});
124
+ private _connect(wsUrl: string): void {
125
+ const proxyAgent = nodeProxyTransport.getWebSocketAgent(wsUrl);
126
+ this.ws = new WebSocket(wsUrl, proxyAgent ? { agent: proxyAgent } : {});
84
127
 
85
128
  this.ws.on('open', () => {
86
129
  if (this.stopped) {
@@ -1,5 +1,10 @@
1
- import { nodeProxyTransport } from '../internal/proxy-transport';
2
- import { directInstanceErrorReason } from '../internal/direct-instance-errors';
1
+ import { LogStream } from '../log-stream';
2
+ import {
3
+ openSignalingTransport,
4
+ type ConnectionState,
5
+ type ConnectionStateCallback,
6
+ type SignalingMessage,
7
+ } from '../internal/signaling-transport';
3
8
  import { instanceToken } from '../instance-token';
4
9
  import { startTcpTunnel, type TcpTunnelOptions, type Tunnel } from '../tunnel';
5
10
  import { type ExecChildProcess } from '../exec-client';
@@ -117,8 +122,23 @@ export interface MacosSshAccess {
117
122
  * MacosClient works inside a running macOS instance: it runs shell commands
118
123
  * as the guest's user, forwards local ports into the guest, and drives the
119
124
  * screen with the mouse and keyboard.
125
+ *
126
+ * Commands go over the instance's signaling WebSocket, as on iOS, which the client opens when it
127
+ * is created and keeps open, reconnecting when it drops. Call {@link disconnect} when done.
120
128
  */
121
129
  export interface MacosClient {
130
+ /** Close the signaling WebSocket. Pending commands fail. */
131
+ disconnect(): void;
132
+
133
+ /** Send an application-level keepAlive message on the signaling WebSocket. */
134
+ keepAlive(): void;
135
+
136
+ /** The signaling WebSocket's connection state. */
137
+ getConnectionState(): ConnectionState;
138
+
139
+ /** Register a callback for connection state changes. Returns a function that unregisters it. */
140
+ onConnectionStateChange(callback: ConnectionStateCallback): () => void;
141
+
122
142
  /**
123
143
  * Run a shell command line as the guest's user, in its login session, with
124
144
  * a login shell's PATH. `cwd` is relative to the user's home directory.
@@ -345,26 +365,6 @@ class MacosInstancesHelpers extends MacosInstances {
345
365
  apiUrl = apiUrl.replace(/\/+$/, '');
346
366
  const log = createDaemonLogger('[MacosInstance]', params.logLevel ?? 'info');
347
367
 
348
- async function request(path: string, init: { method: string; body?: unknown }): Promise<Response> {
349
- const response = await nodeProxyTransport.fetch(`${apiUrl}${path}`, {
350
- method: init.method,
351
- headers: {
352
- Authorization: `Bearer ${token}`,
353
- ...(init.body !== undefined && { 'Content-Type': 'application/json' }),
354
- },
355
- ...(init.body !== undefined && { body: JSON.stringify(init.body) }),
356
- });
357
- if (!response.ok) {
358
- const reason = directInstanceErrorReason(await response.text());
359
- throw new Error(`${init.method} ${path} failed: ${response.status} ${reason}`.trim());
360
- }
361
- return response;
362
- }
363
-
364
- async function post(path: string, body: unknown): Promise<void> {
365
- await request(path, { method: 'POST', body });
366
- }
367
-
368
368
  function tail<T extends { ts: number }>(
369
369
  kind: 'applogs' | 'events' | 'performance',
370
370
  handlers: MacosStreamHandlers<T>,
@@ -378,12 +378,41 @@ class MacosInstancesHelpers extends MacosInstances {
378
378
  });
379
379
  }
380
380
 
381
+ // Restores in progress by request ID; the instance sends progress before the result.
382
+ const restoreProgress = new Map<string, (progress: MacosSnapshotProgress) => void>();
383
+ const transport = await openSignalingTransport({
384
+ apiUrl,
385
+ token,
386
+ logger: {
387
+ debug: (...args) => log('debug', args.map(String).join(' ')),
388
+ info: (...args) => log('info', args.map(String).join(' ')),
389
+ warn: (...args) => log('warn', args.map(String).join(' ')),
390
+ error: (...args) => log('error', args.map(String).join(' ')),
391
+ },
392
+ handleMessage: (message: SignalingMessage) => {
393
+ if (message.type !== 'restoreSnapshotProgress') return false;
394
+ if (message['progress']) restoreProgress.get(message.id)?.(message['progress']);
395
+ return true;
396
+ },
397
+ });
398
+ const send = <T = void>(
399
+ type: string,
400
+ params: Record<string, unknown> = {},
401
+ transform?: (message: SignalingMessage) => T,
402
+ timeoutMs?: number,
403
+ ): Promise<T> =>
404
+ transport.request<T>(type, params, transform ?? ((() => undefined) as () => T), timeoutMs);
405
+
381
406
  return {
382
407
  run: createBuildRun({ apiUrl, token, log }),
383
408
 
384
- async enableSsh(publicKey: string): Promise<MacosSshAccess> {
385
- const response = await request('/ssh', { method: 'POST', body: { publicKey } });
386
- return (await response.json()) as MacosSshAccess;
409
+ disconnect: () => transport.disconnect(),
410
+ keepAlive: () => transport.keepAlive(),
411
+ getConnectionState: () => transport.getConnectionState(),
412
+ onConnectionStateChange: (callback) => transport.onConnectionStateChange(callback),
413
+
414
+ enableSsh(publicKey: string): Promise<MacosSshAccess> {
415
+ return send('enableSsh', { publicKey }, (msg) => ({ user: msg['user'], port: msg['port'] }));
387
416
  },
388
417
 
389
418
  startPortForward(localPort, remotePort, options) {
@@ -413,103 +442,103 @@ class MacosInstancesHelpers extends MacosInstances {
413
442
 
414
443
  async startRecording(options) {
415
444
  if (options?.recordingId !== undefined) validateRecordingId(options.recordingId);
416
- const response = await request('/recordings', {
417
- method: 'POST',
418
- body: {
445
+ return send(
446
+ 'startVideoRecordingSession',
447
+ {
419
448
  ...(options?.recordingId !== undefined && { recordingId: options.recordingId }),
420
449
  ...(options?.quality !== undefined && { quality: options.quality }),
421
450
  ...persistFields(options?.persist),
422
451
  },
423
- });
424
- return ((await response.json()) as { recordingId: string }).recordingId;
452
+ (msg) => msg['recordingId'] as string,
453
+ );
425
454
  },
426
455
 
427
456
  async stopRecording(recordingId, saveTo = {}) {
428
457
  if (recordingId !== undefined) validateRecordingId(recordingId);
429
- const response = await request(
430
- recordingId === undefined ? '/recordings/stop' : `/recordings/${recordingId}/stop`,
458
+ const stoppedId = await send(
459
+ 'stopVideoRecordingSession',
431
460
  {
432
- method: 'POST',
433
- body: saveTo.presignedUrl ? { presignedUrl: saveTo.presignedUrl } : {},
461
+ ...(recordingId !== undefined && { recordingId }),
462
+ ...(saveTo.presignedUrl && { upload: { presignedUrl: saveTo.presignedUrl } }),
434
463
  },
464
+ (msg) => msg['recordingId'] as string | undefined,
465
+ recordingStopTimeoutMs,
435
466
  );
436
- const stopped = ((await response.json()) as { recordingId?: string }).recordingId || recordingId;
467
+ const stopped = stoppedId || recordingId;
437
468
  if (!stopped) throw new Error('the instance did not say which recording stopped');
438
469
  const downloadUrl = `${apiUrl}/files?name=${encodeURIComponent(`recording_${stopped}.mp4`)}`;
439
470
  if (saveTo.localPath) await downloadFileToLocalPath(downloadUrl, token, saveTo.localPath);
440
471
  return downloadUrl;
441
472
  },
442
473
 
443
- async launchApp(app, options) {
444
- const response = await request('/apps/launch', {
445
- method: 'POST',
446
- body: {
447
- app,
474
+ launchApp(app, options) {
475
+ return send(
476
+ 'launchApp',
477
+ {
478
+ bundleId: app,
448
479
  ...(options?.mode !== undefined && { mode: options.mode }),
449
- ...(options?.arguments !== undefined && { arguments: options.arguments }),
480
+ ...(options?.arguments !== undefined && { args: options.arguments }),
450
481
  ...(options?.env !== undefined && { env: options.env }),
451
482
  },
452
- });
453
- return (await response.json()) as MacosLaunchAppResult;
483
+ (msg): MacosLaunchAppResult => ({
484
+ bundleId: msg['bundleId'] ?? app,
485
+ pid: msg['pid'],
486
+ launched: msg['launched'] ?? false,
487
+ }),
488
+ launchAppTimeoutMs,
489
+ );
454
490
  },
455
491
 
456
492
  async terminateApp(bundleId) {
457
- await request('/apps/terminate', { method: 'POST', body: { bundleId } });
493
+ await send('terminateApp', { bundleId });
458
494
  },
459
495
 
460
- async appLogTail(bundleId, lines) {
461
- const query = new URLSearchParams({ bundleId, lines: String(lines) });
462
- const response = await request(`/app-logs?${query}`, { method: 'GET' });
463
- return ((await response.json()) as { logs?: string }).logs ?? '';
496
+ appLogTail(bundleId, lines) {
497
+ return send('appLogTail', { bundleId, lines }, (msg) => (msg['logs'] as string | undefined) ?? '');
464
498
  },
465
499
 
466
500
  streamAppLog(bundleId, handlers) {
467
- const controller = new AbortController();
468
- void (async () => {
469
- try {
470
- const response = await nodeProxyTransport.fetch(
471
- `${apiUrl}/app-logs/stream?${new URLSearchParams({ bundleId })}`,
472
- { headers: { Authorization: `Bearer ${token}` }, signal: controller.signal },
473
- );
474
- if (!response.ok || !response.body) {
475
- throw new Error(
476
- `GET /app-logs/stream failed: ${response.status} ${await response.text()}`.trim(),
477
- );
478
- }
479
- for await (const event of readServerSentEvents(response.body)) handlers.onEntry(event.data);
480
- if (!controller.signal.aborted) throw new Error('the app log stream ended');
481
- } catch (error) {
482
- if (!controller.signal.aborted) {
483
- handlers.onError?.(error instanceof Error ? error : new Error(String(error)));
484
- }
485
- }
486
- })();
487
- return () => controller.abort();
501
+ // Server-sent events on the instance API, one event per line, as on iOS.
502
+ const stream = new LogStream({ apiUrl, token, bundleId });
503
+ let ended = false;
504
+ const fail = (error: Error) => {
505
+ if (ended) return;
506
+ ended = true;
507
+ stream.stop();
508
+ handlers.onError?.(error);
509
+ };
510
+ stream.on('line', (line) => handlers.onEntry(line));
511
+ stream.on('error', fail);
512
+ stream.on('close', () => fail(new Error('the app log stream ended')));
513
+ return () => {
514
+ ended = true;
515
+ stream.stop();
516
+ };
488
517
  },
489
518
 
490
519
  async startAppLogCapture({ bundleId, persist }) {
491
520
  if (!bundleId) throw new Error('bundleId must be a non-empty string');
492
- await post('/session/applogs/start', { bundleId, ...persistFields(persist) });
521
+ await send('startAppLogCapture', { bundleId, ...persistFields(persist) });
493
522
  },
494
523
 
495
524
  async stopAppLogCapture() {
496
- await post('/session/applogs/stop', {});
525
+ await send('stopAppLogCapture', {}, undefined, captureStopTimeoutMs);
497
526
  },
498
527
 
499
528
  async startEventCapture(options) {
500
- await post('/session/events/start', { ...persistFields(options?.persist) });
529
+ await send('startEventCapture', { ...persistFields(options?.persist) });
501
530
  },
502
531
 
503
532
  async stopEventCapture() {
504
- await post('/session/events/stop', {});
533
+ await send('stopEventCapture', {}, undefined, captureStopTimeoutMs);
505
534
  },
506
535
 
507
536
  async startPerformanceCapture(options) {
508
- await post('/session/performance/start', { ...ttlFields(options?.ttlSeconds) });
537
+ await send('startPerformanceCapture', { ...ttlFields(options?.ttlSeconds) });
509
538
  },
510
539
 
511
540
  async stopPerformanceCapture() {
512
- await post('/session/performance/stop', {});
541
+ await send('stopPerformanceCapture', {}, undefined, captureStopTimeoutMs);
513
542
  },
514
543
 
515
544
  streamAppLogCapture(handlers) {
@@ -532,49 +561,66 @@ class MacosInstancesHelpers extends MacosInstances {
532
561
  await stopDestinationTunnel(apiUrl, token, tunnelId);
533
562
  },
534
563
 
535
- async screenshot(): Promise<Buffer> {
536
- const response = await request('/screenshot.jpg', { method: 'GET' });
537
- return Buffer.from(await response.arrayBuffer());
564
+ screenshot(): Promise<Buffer> {
565
+ return send('screenshot', {}, (msg) =>
566
+ Buffer.from((msg['base64'] as string | undefined) ?? '', 'base64'),
567
+ );
538
568
  },
539
569
 
540
- tap(point, options) {
541
- return post('/tap', { x: point.x, y: point.y, ...(options?.button && { button: options.button }) });
570
+ async tap(point, options) {
571
+ await send('tap', { x: point.x, y: point.y, ...(options?.button && { button: options.button }) });
542
572
  },
543
573
 
544
- typeText(text) {
545
- return post('/type', { text });
574
+ async typeText(text) {
575
+ await send('typeText', { text });
546
576
  },
547
577
 
548
- pressKey(key, modifiers) {
549
- return post('/press-key', { key, ...(modifiers?.length && { modifiers }) });
578
+ async pressKey(key, modifiers) {
579
+ await send('pressKey', { key, ...(modifiers?.length && { modifiers }) });
550
580
  },
551
581
 
552
- scroll({ dx, dy, at }) {
553
- return post('/scroll', { dx: dx ?? 0, dy: dy ?? 0, ...(at && { x: at.x, y: at.y }) });
582
+ async scroll({ dx, dy, at }) {
583
+ await send('scroll', { dx: dx ?? 0, dy: dy ?? 0, ...(at && { coordinate: [at.x, at.y] }) });
554
584
  },
555
585
 
556
586
  async restoreSnapshot({
557
587
  onProgress,
558
- ...body
588
+ key,
589
+ restoreKeys,
559
590
  }: MacosSnapshotRestoreOptions): Promise<MacosSnapshotProgress> {
560
- const response = await request('/snapshot', { method: 'POST', body });
561
- if (!response.body) throw new Error('POST /snapshot answered without a body');
591
+ const id = transport.nextId();
562
592
  let last: MacosSnapshotProgress | undefined;
563
- for await (const event of readServerSentEvents(response.body)) {
564
- if (event.event !== 'snapshot') continue;
565
- last = JSON.parse(event.data) as MacosSnapshotProgress;
566
- onProgress?.(last);
567
- }
568
- if (!last || !['restored', 'skipped', 'failed'].includes(last.phase)) {
569
- throw new Error(
570
- `the snapshot stream ended before the restore did (last phase: ${last?.phase ?? 'none'})`,
571
- );
593
+ restoreProgress.set(id, (progress) => {
594
+ last = progress;
595
+ onProgress?.(progress);
596
+ });
597
+ try {
598
+ // A restore downloads the whole disk, so it waits as long as the connection lasts.
599
+ let final: MacosSnapshotProgress | undefined;
600
+ try {
601
+ final = await transport.request<MacosSnapshotProgress | undefined>(
602
+ 'restoreSnapshot',
603
+ { ...(key !== undefined && { key }), ...(restoreKeys !== undefined && { restoreKeys }) },
604
+ (msg) => msg['progress'] as MacosSnapshotProgress | undefined,
605
+ 0,
606
+ id,
607
+ );
608
+ } catch (error) {
609
+ // A failed restore is an outcome, as it was reported in its progress, not an error.
610
+ if (last?.phase === 'failed') return last;
611
+ throw error;
612
+ }
613
+ if (final && final !== last) onProgress?.(final);
614
+ const result = final ?? last;
615
+ if (!result) throw new Error('the instance finished the restore without reporting its progress');
616
+ return result;
617
+ } finally {
618
+ restoreProgress.delete(id);
572
619
  }
573
- return last;
574
620
  },
575
621
 
576
- drag(from, to, options) {
577
- return post('/drag', {
622
+ async drag(from, to, options) {
623
+ await send('drag', {
578
624
  fromX: from.x,
579
625
  fromY: from.y,
580
626
  toX: to.x,
@@ -586,6 +632,12 @@ class MacosInstancesHelpers extends MacosInstances {
586
632
  }
587
633
  }
588
634
 
635
+ // A stop answers once its persisted capture or recording is uploaded, which grows with its length.
636
+ const captureStopTimeoutMs = 300_000;
637
+ const recordingStopTimeoutMs = 180_000;
638
+ // A first launch or a relaunch can take longer than the default, as on iOS.
639
+ const launchAppTimeoutMs = 90_000;
640
+
589
641
  MacosInstances.prototype.createClient = MacosInstancesHelpers.prototype.createClient;
590
642
 
591
643
  MacosInstances.prototype.listSessionArtifacts = function (
@@ -618,38 +670,3 @@ function validateRecordingId(recordingId: string): void {
618
670
  throw new Error('recordingId must match ^[a-z0-9][a-z0-9_-]{0,63}$');
619
671
  }
620
672
  }
621
-
622
- /** readServerSentEvents yields the events of a server-sent event stream as they arrive. */
623
- async function* readServerSentEvents(
624
- body: ReadableStream<Uint8Array>,
625
- ): AsyncGenerator<{ event: string; data: string }> {
626
- const decoder = new TextDecoder();
627
- let buffer = '';
628
- let event = 'message';
629
- let data: string[] = [];
630
- const reader = body.getReader();
631
- try {
632
- while (true) {
633
- const { value, done } = await reader.read();
634
- if (done) break;
635
- buffer += decoder.decode(value, { stream: true });
636
- let newline: number;
637
- while ((newline = buffer.indexOf('\n')) >= 0) {
638
- const line = buffer.slice(0, newline).replace(/\r$/, '');
639
- buffer = buffer.slice(newline + 1);
640
- if (line === '') {
641
- if (data.length > 0) yield { event, data: data.join('\n') };
642
- event = 'message';
643
- data = [];
644
- } else if (line.startsWith('event:')) {
645
- event = line.slice(6).trim();
646
- } else if (line.startsWith('data:')) {
647
- data.push(line.slice(5).replace(/^ /, ''));
648
- }
649
- }
650
- }
651
- if (data.length > 0) yield { event, data: data.join('\n') };
652
- } finally {
653
- reader.releaseLock();
654
- }
655
- }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.79.0'; // x-release-please-version
1
+ export const VERSION = '0.79.2'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.79.0";
1
+ export declare const VERSION = "0.79.2";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.79.0";
1
+ export declare const VERSION = "0.79.2";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.79.0'; // x-release-please-version
4
+ exports.VERSION = '0.79.2'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.79.0'; // x-release-please-version
1
+ export const VERSION = '0.79.2'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map