@dxos/edge-client 0.7.5-labs.ea4b4c2 → 0.7.5-labs.f400bbc

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.
@@ -10,9 +10,9 @@ import {
10
10
  export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
11
11
 
12
12
  // packages/core/mesh/edge-client/src/edge-client.ts
13
- import { Trigger, scheduleMicroTask, TriggerState } from "@dxos/async";
14
- import { Resource as Resource3 } from "@dxos/context";
15
- import { log as log3, logInfo as logInfo2 } from "@dxos/log";
13
+ import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from "@dxos/async";
14
+ import { Resource as Resource2 } from "@dxos/context";
15
+ import { log as log2, logInfo as logInfo2 } from "@dxos/log";
16
16
 
17
17
  // packages/core/mesh/edge-client/src/edge-identity.ts
18
18
  import { invariant } from "@dxos/invariant";
@@ -289,118 +289,6 @@ var EdgeIdentityChangedError = class extends Error {
289
289
  }
290
290
  };
291
291
 
292
- // packages/core/mesh/edge-client/src/persistent-lifecycle.ts
293
- import { DeferredTask, sleep, synchronized } from "@dxos/async";
294
- import { cancelWithContext, LifecycleState, Resource as Resource2 } from "@dxos/context";
295
- import { warnAfterTimeout } from "@dxos/debug";
296
- import { log as log2 } from "@dxos/log";
297
- function _ts_decorate2(decorators, target, key, desc) {
298
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
299
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
300
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
301
- return c > 3 && r && Object.defineProperty(target, key, r), r;
302
- }
303
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/persistent-lifecycle.ts";
304
- var INIT_RESTART_DELAY = 100;
305
- var DEFAULT_MAX_RESTART_DELAY = 5e3;
306
- var PersistentLifecycle = class extends Resource2 {
307
- constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }) {
308
- super();
309
- this._currentContext = void 0;
310
- this._restartTask = void 0;
311
- this._restartAfter = 0;
312
- this._start = start;
313
- this._stop = stop;
314
- this._onRestart = onRestart;
315
- this._maxRestartDelay = maxRestartDelay;
316
- }
317
- async _open() {
318
- this._restartTask = new DeferredTask(this._ctx, async () => {
319
- try {
320
- await this._restart();
321
- } catch (err) {
322
- log2.warn("Restart failed", {
323
- err
324
- }, {
325
- F: __dxlog_file3,
326
- L: 65,
327
- S: this,
328
- C: (f, a) => f(...a)
329
- });
330
- this._restartTask?.schedule();
331
- }
332
- });
333
- this._currentContext = await this._start().catch((err) => {
334
- log2.warn("Start failed", {
335
- err
336
- }, {
337
- F: __dxlog_file3,
338
- L: 70,
339
- S: this,
340
- C: (f, a) => f(...a)
341
- });
342
- this._restartTask?.schedule();
343
- return void 0;
344
- });
345
- }
346
- async _close() {
347
- await this._restartTask?.join();
348
- await this._stopCurrentContext();
349
- this._restartTask = void 0;
350
- }
351
- async _restart() {
352
- log2(`restarting in ${this._restartAfter}ms`, {
353
- state: this._lifecycleState
354
- }, {
355
- F: __dxlog_file3,
356
- L: 83,
357
- S: this,
358
- C: (f, a) => f(...a)
359
- });
360
- await this._stopCurrentContext();
361
- if (this._lifecycleState !== LifecycleState.OPEN) {
362
- return;
363
- }
364
- await cancelWithContext(this._ctx, sleep(this._restartAfter));
365
- this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);
366
- await warnAfterTimeout(5e3, "Connection establishment takes too long", async () => {
367
- this._currentContext = await this._start();
368
- });
369
- this._restartAfter = 0;
370
- await this._onRestart?.();
371
- }
372
- async _stopCurrentContext() {
373
- if (this._currentContext) {
374
- try {
375
- await this._stop(this._currentContext);
376
- } catch (err) {
377
- log2.catch(err, void 0, {
378
- F: __dxlog_file3,
379
- L: 105,
380
- S: this,
381
- C: (f, a) => f(...a)
382
- });
383
- }
384
- this._currentContext = void 0;
385
- }
386
- }
387
- /**
388
- * Scheduling restart should be done from outside.
389
- */
390
- scheduleRestart() {
391
- if (this._lifecycleState !== LifecycleState.OPEN) {
392
- return;
393
- }
394
- this._restartTask.schedule();
395
- }
396
- };
397
- _ts_decorate2([
398
- synchronized
399
- ], PersistentLifecycle.prototype, "_open", null);
400
- _ts_decorate2([
401
- synchronized
402
- ], PersistentLifecycle.prototype, "scheduleRestart", null);
403
-
404
292
  // packages/core/mesh/edge-client/src/utils.ts
405
293
  var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
406
294
  const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
@@ -410,15 +298,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
410
298
  };
411
299
 
412
300
  // packages/core/mesh/edge-client/src/edge-client.ts
413
- function _ts_decorate3(decorators, target, key, desc) {
301
+ function _ts_decorate2(decorators, target, key, desc) {
414
302
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
415
303
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
416
304
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
417
305
  return c > 3 && r && Object.defineProperty(target, key, r), r;
418
306
  }
419
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
307
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
420
308
  var DEFAULT_TIMEOUT = 1e4;
421
- var EdgeClient = class extends Resource3 {
309
+ var EdgeClient = class extends Resource2 {
422
310
  constructor(_identity, _config) {
423
311
  super();
424
312
  this._identity = _identity;
@@ -453,12 +341,12 @@ var EdgeClient = class extends Resource3 {
453
341
  }
454
342
  setIdentity(identity) {
455
343
  if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
456
- log3("Edge identity changed", {
344
+ log2("Edge identity changed", {
457
345
  identity,
458
346
  oldIdentity: this._identity
459
347
  }, {
460
- F: __dxlog_file4,
461
- L: 95,
348
+ F: __dxlog_file3,
349
+ L: 94,
462
350
  S: this,
463
351
  C: (f, a) => f(...a)
464
352
  });
@@ -479,9 +367,9 @@ var EdgeClient = class extends Resource3 {
479
367
  try {
480
368
  listener();
481
369
  } catch (error) {
482
- log3.catch(error, void 0, {
483
- F: __dxlog_file4,
484
- L: 117,
370
+ log2.catch(error, void 0, {
371
+ F: __dxlog_file3,
372
+ L: 116,
485
373
  S: this,
486
374
  C: (f, a) => f(...a)
487
375
  });
@@ -495,20 +383,20 @@ var EdgeClient = class extends Resource3 {
495
383
  * Open connection to messaging service.
496
384
  */
497
385
  async _open() {
498
- log3("opening...", {
386
+ log2("opening...", {
499
387
  info: this.info
500
388
  }, {
501
- F: __dxlog_file4,
502
- L: 129,
389
+ F: __dxlog_file3,
390
+ L: 128,
503
391
  S: this,
504
392
  C: (f, a) => f(...a)
505
393
  });
506
394
  this._persistentLifecycle.open().catch((err) => {
507
- log3.warn("Error while opening connection", {
395
+ log2.warn("Error while opening connection", {
508
396
  err
509
397
  }, {
510
- F: __dxlog_file4,
511
- L: 131,
398
+ F: __dxlog_file3,
399
+ L: 130,
512
400
  S: this,
513
401
  C: (f, a) => f(...a)
514
402
  });
@@ -518,11 +406,11 @@ var EdgeClient = class extends Resource3 {
518
406
  * Close connection and free resources.
519
407
  */
520
408
  async _close() {
521
- log3("closing...", {
409
+ log2("closing...", {
522
410
  peerKey: this._identity.peerKey
523
411
  }, {
524
- F: __dxlog_file4,
525
- L: 139,
412
+ F: __dxlog_file3,
413
+ L: 138,
526
414
  S: this,
527
415
  C: (f, a) => f(...a)
528
416
  });
@@ -537,9 +425,9 @@ var EdgeClient = class extends Resource3 {
537
425
  const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
538
426
  const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
539
427
  if (this._identity !== identity) {
540
- log3("identity changed during auth header request", void 0, {
541
- F: __dxlog_file4,
542
- L: 153,
428
+ log2("identity changed during auth header request", void 0, {
429
+ F: __dxlog_file3,
430
+ L: 152,
543
431
  S: this,
544
432
  C: (f, a) => f(...a)
545
433
  });
@@ -547,12 +435,12 @@ var EdgeClient = class extends Resource3 {
547
435
  }
548
436
  const restartRequired = new Trigger();
549
437
  const url = new URL(path, this._baseWsUrl);
550
- log3("Opening websocket", {
438
+ log2("Opening websocket", {
551
439
  url: url.toString(),
552
440
  protocolHeader
553
441
  }, {
554
- F: __dxlog_file4,
555
- L: 159,
442
+ F: __dxlog_file3,
443
+ L: 158,
556
444
  S: this,
557
445
  C: (f, a) => f(...a)
558
446
  });
@@ -565,9 +453,9 @@ var EdgeClient = class extends Resource3 {
565
453
  this._ready.wake();
566
454
  this._notifyReconnected();
567
455
  } else {
568
- log3.verbose("connected callback ignored, because connection is not active", void 0, {
569
- F: __dxlog_file4,
570
- L: 169,
456
+ log2.verbose("connected callback ignored, because connection is not active", void 0, {
457
+ F: __dxlog_file3,
458
+ L: 168,
571
459
  S: this,
572
460
  C: (f, a) => f(...a)
573
461
  });
@@ -578,9 +466,9 @@ var EdgeClient = class extends Resource3 {
578
466
  this._closeCurrentConnection();
579
467
  this._persistentLifecycle.scheduleRestart();
580
468
  } else {
581
- log3.verbose("restart requested by inactive connection", void 0, {
582
- F: __dxlog_file4,
583
- L: 177,
469
+ log2.verbose("restart requested by inactive connection", void 0, {
470
+ F: __dxlog_file3,
471
+ L: 176,
584
472
  S: this,
585
473
  C: (f, a) => f(...a)
586
474
  });
@@ -591,12 +479,12 @@ var EdgeClient = class extends Resource3 {
591
479
  if (this._isActive(connection)) {
592
480
  this._notifyMessageReceived(message);
593
481
  } else {
594
- log3.verbose("ignored a message on inactive connection", {
482
+ log2.verbose("ignored a message on inactive connection", {
595
483
  from: message.source,
596
484
  type: message.payload?.typeUrl
597
485
  }, {
598
- F: __dxlog_file4,
599
- L: 185,
486
+ F: __dxlog_file3,
487
+ L: 184,
600
488
  S: this,
601
489
  C: (f, a) => f(...a)
602
490
  });
@@ -626,11 +514,11 @@ var EdgeClient = class extends Resource3 {
626
514
  try {
627
515
  listener();
628
516
  } catch (err) {
629
- log3.error("ws reconnect listener failed", {
517
+ log2.error("ws reconnect listener failed", {
630
518
  err
631
519
  }, {
632
- F: __dxlog_file4,
633
- L: 218,
520
+ F: __dxlog_file3,
521
+ L: 217,
634
522
  S: this,
635
523
  C: (f, a) => f(...a)
636
524
  });
@@ -642,12 +530,12 @@ var EdgeClient = class extends Resource3 {
642
530
  try {
643
531
  listener(message);
644
532
  } catch (err) {
645
- log3.error("ws incoming message processing failed", {
533
+ log2.error("ws incoming message processing failed", {
646
534
  err,
647
535
  payload: protocol.getPayloadType(message)
648
536
  }, {
649
- F: __dxlog_file4,
650
- L: 228,
537
+ F: __dxlog_file3,
538
+ L: 227,
651
539
  S: this,
652
540
  C: (f, a) => f(...a)
653
541
  });
@@ -660,9 +548,9 @@ var EdgeClient = class extends Resource3 {
660
548
  */
661
549
  async send(message) {
662
550
  if (this._ready.state !== TriggerState.RESOLVED) {
663
- log3("waiting for websocket to become ready", void 0, {
664
- F: __dxlog_file4,
665
- L: 239,
551
+ log2("waiting for websocket to become ready", void 0, {
552
+ F: __dxlog_file3,
553
+ L: 238,
666
554
  S: this,
667
555
  C: (f, a) => f(...a)
668
556
  });
@@ -687,12 +575,12 @@ var EdgeClient = class extends Resource3 {
687
575
  if (response.status === 401) {
688
576
  return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
689
577
  } else {
690
- log3.warn("no auth challenge from edge", {
578
+ log2.warn("no auth challenge from edge", {
691
579
  status: response.status,
692
580
  statusText: response.statusText
693
581
  }, {
694
- F: __dxlog_file4,
695
- L: 264,
582
+ F: __dxlog_file3,
583
+ L: 263,
696
584
  S: this,
697
585
  C: (f, a) => f(...a)
698
586
  });
@@ -700,7 +588,7 @@ var EdgeClient = class extends Resource3 {
700
588
  }
701
589
  }
702
590
  };
703
- _ts_decorate3([
591
+ _ts_decorate2([
704
592
  logInfo2
705
593
  ], EdgeClient.prototype, "info", null);
706
594
  var encodePresentationWsAuthHeader = (encodedPresentation) => {
@@ -713,7 +601,7 @@ import { createCredential, signPresentation } from "@dxos/credentials";
713
601
  import { invariant as invariant3 } from "@dxos/invariant";
714
602
  import { Keyring } from "@dxos/keyring";
715
603
  import { PublicKey } from "@dxos/keys";
716
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
604
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
717
605
  var createDeviceEdgeIdentity = async (signer, key) => {
718
606
  return {
719
607
  identityKey: key.toHex(),
@@ -758,7 +646,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
758
646
  peerKey: peerKey.toHex(),
759
647
  presentCredentials: async ({ challenge }) => {
760
648
  invariant3(chain, void 0, {
761
- F: __dxlog_file5,
649
+ F: __dxlog_file4,
762
650
  L: 75,
763
651
  S: void 0,
764
652
  A: [
@@ -820,26 +708,29 @@ var createStubEdgeIdentity = () => {
820
708
  };
821
709
 
822
710
  // packages/core/mesh/edge-client/src/edge-http-client.ts
823
- import { sleep as sleep2 } from "@dxos/async";
711
+ import { sleep } from "@dxos/async";
824
712
  import { Context as Context2 } from "@dxos/context";
825
- import { log as log4 } from "@dxos/log";
713
+ import { log as log3 } from "@dxos/log";
826
714
  import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
827
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
715
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
828
716
  var DEFAULT_RETRY_TIMEOUT = 1500;
829
717
  var DEFAULT_RETRY_JITTER = 500;
830
718
  var DEFAULT_MAX_RETRIES_COUNT = 3;
831
719
  var EdgeHttpClient = class {
832
720
  constructor(baseUrl) {
833
721
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
834
- log4("created", {
722
+ log3("created", {
835
723
  url: this._baseUrl
836
724
  }, {
837
- F: __dxlog_file6,
725
+ F: __dxlog_file5,
838
726
  L: 49,
839
727
  S: this,
840
728
  C: (f, a) => f(...a)
841
729
  });
842
730
  }
731
+ get baseUrl() {
732
+ return this._baseUrl;
733
+ }
843
734
  setIdentity(identity) {
844
735
  if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {
845
736
  this._edgeIdentity = identity;
@@ -950,8 +841,8 @@ var EdgeHttpClient = class {
950
841
  }
951
842
  async _call(path, args) {
952
843
  const requestContext = args.context ?? new Context2(void 0, {
953
- F: __dxlog_file6,
954
- L: 173
844
+ F: __dxlog_file5,
845
+ L: 177
955
846
  });
956
847
  const shouldRetry = createRetryHandler(args);
957
848
  let url = `${this._baseUrl}${path.startsWith("/") ? path.slice(1) : path}`;
@@ -962,13 +853,13 @@ var EdgeHttpClient = class {
962
853
  }
963
854
  url += `?${queryParams.toString()}`;
964
855
  }
965
- log4("call", {
856
+ log3("call", {
966
857
  method: args.method,
967
858
  path,
968
859
  request: args.body
969
860
  }, {
970
- F: __dxlog_file6,
971
- L: 185,
861
+ F: __dxlog_file5,
862
+ L: 189,
972
863
  S: this,
973
864
  C: (f, a) => f(...a)
974
865
  });
@@ -986,12 +877,12 @@ var EdgeHttpClient = class {
986
877
  if (body.success) {
987
878
  return body.data;
988
879
  }
989
- log4("unsuccessful edge response", {
880
+ log3("unsuccessful edge response", {
990
881
  path,
991
882
  body
992
883
  }, {
993
- F: __dxlog_file6,
994
- L: 204,
884
+ F: __dxlog_file5,
885
+ L: 208,
995
886
  S: this,
996
887
  C: (f, a) => f(...a)
997
888
  });
@@ -1011,12 +902,12 @@ var EdgeHttpClient = class {
1011
902
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
1012
903
  }
1013
904
  if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
1014
- log4("retrying edge request", {
905
+ log3("retrying edge request", {
1015
906
  path,
1016
907
  processingError
1017
908
  }, {
1018
- F: __dxlog_file6,
1019
- L: 223,
909
+ F: __dxlog_file5,
910
+ L: 227,
1020
911
  S: this,
1021
912
  C: (f, a) => f(...a)
1022
913
  });
@@ -1027,9 +918,9 @@ var EdgeHttpClient = class {
1027
918
  }
1028
919
  async _handleUnauthorized(response) {
1029
920
  if (!this._edgeIdentity) {
1030
- log4.warn("edge unauthorized response received before identity was set", void 0, {
1031
- F: __dxlog_file6,
1032
- L: 232,
921
+ log3.warn("edge unauthorized response received before identity was set", void 0, {
922
+ F: __dxlog_file5,
923
+ L: 236,
1033
924
  S: this,
1034
925
  C: (f, a) => f(...a)
1035
926
  });
@@ -1037,9 +928,9 @@ var EdgeHttpClient = class {
1037
928
  }
1038
929
  const challenge = await handleAuthChallenge(response, this._edgeIdentity);
1039
930
  this._authHeader = encodeAuthHeader(challenge);
1040
- log4("auth header updated", void 0, {
1041
- F: __dxlog_file6,
1042
- L: 237,
931
+ log3("auth header updated", void 0, {
932
+ F: __dxlog_file5,
933
+ L: 241,
1043
934
  S: this,
1044
935
  C: (f, a) => f(...a)
1045
936
  });
@@ -1059,10 +950,10 @@ var createRetryHandler = (args) => {
1059
950
  return false;
1060
951
  }
1061
952
  if (retryAfter) {
1062
- await sleep2(retryAfter);
953
+ await sleep(retryAfter);
1063
954
  } else {
1064
955
  const timeout = baseTimeout + Math.random() * jitter;
1065
- await sleep2(timeout);
956
+ await sleep(timeout);
1066
957
  }
1067
958
  return true;
1068
959
  };