@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.
@@ -59,17 +59,13 @@ var import_invariant2 = require("@dxos/invariant");
59
59
  var import_log2 = require("@dxos/log");
60
60
  var import_buf = require("@dxos/protocols/buf");
61
61
  var import_messenger_pb = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
62
- var import_async3 = require("@dxos/async");
63
- var import_context3 = require("@dxos/context");
64
- var import_debug = require("@dxos/debug");
65
- var import_log3 = require("@dxos/log");
66
62
  var import_credentials = require("@dxos/credentials");
67
63
  var import_invariant3 = require("@dxos/invariant");
68
64
  var import_keyring = require("@dxos/keyring");
69
65
  var import_keys = require("@dxos/keys");
70
- var import_async4 = require("@dxos/async");
71
- var import_context4 = require("@dxos/context");
72
- var import_log4 = require("@dxos/log");
66
+ var import_async3 = require("@dxos/async");
67
+ var import_context3 = require("@dxos/context");
68
+ var import_log3 = require("@dxos/log");
73
69
  var import_protocols = require("@dxos/protocols");
74
70
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
75
71
  var handleAuthChallenge = async (failedResponse, identity) => {
@@ -331,132 +327,26 @@ var EdgeIdentityChangedError = class extends Error {
331
327
  super("Edge identity changed.");
332
328
  }
333
329
  };
334
- function _ts_decorate2(decorators, target, key, desc) {
335
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
336
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
337
- 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;
338
- return c > 3 && r && Object.defineProperty(target, key, r), r;
339
- }
340
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/persistent-lifecycle.ts";
341
- var INIT_RESTART_DELAY = 100;
342
- var DEFAULT_MAX_RESTART_DELAY = 5e3;
343
- var PersistentLifecycle = class extends import_context3.Resource {
344
- constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }) {
345
- super();
346
- this._currentContext = void 0;
347
- this._restartTask = void 0;
348
- this._restartAfter = 0;
349
- this._start = start;
350
- this._stop = stop;
351
- this._onRestart = onRestart;
352
- this._maxRestartDelay = maxRestartDelay;
353
- }
354
- async _open() {
355
- this._restartTask = new import_async3.DeferredTask(this._ctx, async () => {
356
- try {
357
- await this._restart();
358
- } catch (err) {
359
- import_log3.log.warn("Restart failed", {
360
- err
361
- }, {
362
- F: __dxlog_file3,
363
- L: 65,
364
- S: this,
365
- C: (f, a) => f(...a)
366
- });
367
- this._restartTask?.schedule();
368
- }
369
- });
370
- this._currentContext = await this._start().catch((err) => {
371
- import_log3.log.warn("Start failed", {
372
- err
373
- }, {
374
- F: __dxlog_file3,
375
- L: 70,
376
- S: this,
377
- C: (f, a) => f(...a)
378
- });
379
- this._restartTask?.schedule();
380
- return void 0;
381
- });
382
- }
383
- async _close() {
384
- await this._restartTask?.join();
385
- await this._stopCurrentContext();
386
- this._restartTask = void 0;
387
- }
388
- async _restart() {
389
- (0, import_log3.log)(`restarting in ${this._restartAfter}ms`, {
390
- state: this._lifecycleState
391
- }, {
392
- F: __dxlog_file3,
393
- L: 83,
394
- S: this,
395
- C: (f, a) => f(...a)
396
- });
397
- await this._stopCurrentContext();
398
- if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
399
- return;
400
- }
401
- await (0, import_context3.cancelWithContext)(this._ctx, (0, import_async3.sleep)(this._restartAfter));
402
- this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);
403
- await (0, import_debug.warnAfterTimeout)(5e3, "Connection establishment takes too long", async () => {
404
- this._currentContext = await this._start();
405
- });
406
- this._restartAfter = 0;
407
- await this._onRestart?.();
408
- }
409
- async _stopCurrentContext() {
410
- if (this._currentContext) {
411
- try {
412
- await this._stop(this._currentContext);
413
- } catch (err) {
414
- import_log3.log.catch(err, void 0, {
415
- F: __dxlog_file3,
416
- L: 105,
417
- S: this,
418
- C: (f, a) => f(...a)
419
- });
420
- }
421
- this._currentContext = void 0;
422
- }
423
- }
424
- /**
425
- * Scheduling restart should be done from outside.
426
- */
427
- scheduleRestart() {
428
- if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
429
- return;
430
- }
431
- this._restartTask.schedule();
432
- }
433
- };
434
- _ts_decorate2([
435
- import_async3.synchronized
436
- ], PersistentLifecycle.prototype, "_open", null);
437
- _ts_decorate2([
438
- import_async3.synchronized
439
- ], PersistentLifecycle.prototype, "scheduleRestart", null);
440
330
  var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
441
331
  const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
442
332
  const url = new URL(baseUrl);
443
333
  url.protocol = protocol2 + (isSecure ? "s" : "");
444
334
  return url.toString();
445
335
  };
446
- function _ts_decorate3(decorators, target, key, desc) {
336
+ function _ts_decorate2(decorators, target, key, desc) {
447
337
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
448
338
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
449
339
  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;
450
340
  return c > 3 && r && Object.defineProperty(target, key, r), r;
451
341
  }
452
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
342
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
453
343
  var DEFAULT_TIMEOUT = 1e4;
454
344
  var EdgeClient = class extends import_context.Resource {
455
345
  constructor(_identity, _config) {
456
346
  super();
457
347
  this._identity = _identity;
458
348
  this._config = _config;
459
- this._persistentLifecycle = new PersistentLifecycle({
349
+ this._persistentLifecycle = new import_async.PersistentLifecycle({
460
350
  start: async () => this._connect(),
461
351
  stop: async (state) => this._disconnect(state)
462
352
  });
@@ -490,8 +380,8 @@ var EdgeClient = class extends import_context.Resource {
490
380
  identity,
491
381
  oldIdentity: this._identity
492
382
  }, {
493
- F: __dxlog_file4,
494
- L: 95,
383
+ F: __dxlog_file3,
384
+ L: 94,
495
385
  S: this,
496
386
  C: (f, a) => f(...a)
497
387
  });
@@ -513,8 +403,8 @@ var EdgeClient = class extends import_context.Resource {
513
403
  listener();
514
404
  } catch (error) {
515
405
  import_log.log.catch(error, void 0, {
516
- F: __dxlog_file4,
517
- L: 117,
406
+ F: __dxlog_file3,
407
+ L: 116,
518
408
  S: this,
519
409
  C: (f, a) => f(...a)
520
410
  });
@@ -531,8 +421,8 @@ var EdgeClient = class extends import_context.Resource {
531
421
  (0, import_log.log)("opening...", {
532
422
  info: this.info
533
423
  }, {
534
- F: __dxlog_file4,
535
- L: 129,
424
+ F: __dxlog_file3,
425
+ L: 128,
536
426
  S: this,
537
427
  C: (f, a) => f(...a)
538
428
  });
@@ -540,8 +430,8 @@ var EdgeClient = class extends import_context.Resource {
540
430
  import_log.log.warn("Error while opening connection", {
541
431
  err
542
432
  }, {
543
- F: __dxlog_file4,
544
- L: 131,
433
+ F: __dxlog_file3,
434
+ L: 130,
545
435
  S: this,
546
436
  C: (f, a) => f(...a)
547
437
  });
@@ -554,8 +444,8 @@ var EdgeClient = class extends import_context.Resource {
554
444
  (0, import_log.log)("closing...", {
555
445
  peerKey: this._identity.peerKey
556
446
  }, {
557
- F: __dxlog_file4,
558
- L: 139,
447
+ F: __dxlog_file3,
448
+ L: 138,
559
449
  S: this,
560
450
  C: (f, a) => f(...a)
561
451
  });
@@ -571,8 +461,8 @@ var EdgeClient = class extends import_context.Resource {
571
461
  const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
572
462
  if (this._identity !== identity) {
573
463
  (0, import_log.log)("identity changed during auth header request", void 0, {
574
- F: __dxlog_file4,
575
- L: 153,
464
+ F: __dxlog_file3,
465
+ L: 152,
576
466
  S: this,
577
467
  C: (f, a) => f(...a)
578
468
  });
@@ -584,8 +474,8 @@ var EdgeClient = class extends import_context.Resource {
584
474
  url: url.toString(),
585
475
  protocolHeader
586
476
  }, {
587
- F: __dxlog_file4,
588
- L: 159,
477
+ F: __dxlog_file3,
478
+ L: 158,
589
479
  S: this,
590
480
  C: (f, a) => f(...a)
591
481
  });
@@ -599,8 +489,8 @@ var EdgeClient = class extends import_context.Resource {
599
489
  this._notifyReconnected();
600
490
  } else {
601
491
  import_log.log.verbose("connected callback ignored, because connection is not active", void 0, {
602
- F: __dxlog_file4,
603
- L: 169,
492
+ F: __dxlog_file3,
493
+ L: 168,
604
494
  S: this,
605
495
  C: (f, a) => f(...a)
606
496
  });
@@ -612,8 +502,8 @@ var EdgeClient = class extends import_context.Resource {
612
502
  this._persistentLifecycle.scheduleRestart();
613
503
  } else {
614
504
  import_log.log.verbose("restart requested by inactive connection", void 0, {
615
- F: __dxlog_file4,
616
- L: 177,
505
+ F: __dxlog_file3,
506
+ L: 176,
617
507
  S: this,
618
508
  C: (f, a) => f(...a)
619
509
  });
@@ -628,8 +518,8 @@ var EdgeClient = class extends import_context.Resource {
628
518
  from: message.source,
629
519
  type: message.payload?.typeUrl
630
520
  }, {
631
- F: __dxlog_file4,
632
- L: 185,
521
+ F: __dxlog_file3,
522
+ L: 184,
633
523
  S: this,
634
524
  C: (f, a) => f(...a)
635
525
  });
@@ -662,8 +552,8 @@ var EdgeClient = class extends import_context.Resource {
662
552
  import_log.log.error("ws reconnect listener failed", {
663
553
  err
664
554
  }, {
665
- F: __dxlog_file4,
666
- L: 218,
555
+ F: __dxlog_file3,
556
+ L: 217,
667
557
  S: this,
668
558
  C: (f, a) => f(...a)
669
559
  });
@@ -679,8 +569,8 @@ var EdgeClient = class extends import_context.Resource {
679
569
  err,
680
570
  payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
681
571
  }, {
682
- F: __dxlog_file4,
683
- L: 228,
572
+ F: __dxlog_file3,
573
+ L: 227,
684
574
  S: this,
685
575
  C: (f, a) => f(...a)
686
576
  });
@@ -694,8 +584,8 @@ var EdgeClient = class extends import_context.Resource {
694
584
  async send(message) {
695
585
  if (this._ready.state !== import_async.TriggerState.RESOLVED) {
696
586
  (0, import_log.log)("waiting for websocket to become ready", void 0, {
697
- F: __dxlog_file4,
698
- L: 239,
587
+ F: __dxlog_file3,
588
+ L: 238,
699
589
  S: this,
700
590
  C: (f, a) => f(...a)
701
591
  });
@@ -724,8 +614,8 @@ var EdgeClient = class extends import_context.Resource {
724
614
  status: response.status,
725
615
  statusText: response.statusText
726
616
  }, {
727
- F: __dxlog_file4,
728
- L: 264,
617
+ F: __dxlog_file3,
618
+ L: 263,
729
619
  S: this,
730
620
  C: (f, a) => f(...a)
731
621
  });
@@ -733,14 +623,14 @@ var EdgeClient = class extends import_context.Resource {
733
623
  }
734
624
  }
735
625
  };
736
- _ts_decorate3([
626
+ _ts_decorate2([
737
627
  import_log.logInfo
738
628
  ], EdgeClient.prototype, "info", null);
739
629
  var encodePresentationWsAuthHeader = (encodedPresentation) => {
740
630
  const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
741
631
  return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
742
632
  };
743
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
633
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
744
634
  var createDeviceEdgeIdentity = async (signer, key) => {
745
635
  return {
746
636
  identityKey: key.toHex(),
@@ -785,7 +675,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
785
675
  peerKey: peerKey.toHex(),
786
676
  presentCredentials: async ({ challenge }) => {
787
677
  (0, import_invariant3.invariant)(chain, void 0, {
788
- F: __dxlog_file5,
678
+ F: __dxlog_file4,
789
679
  L: 75,
790
680
  S: void 0,
791
681
  A: [
@@ -845,22 +735,25 @@ var createStubEdgeIdentity = () => {
845
735
  }
846
736
  };
847
737
  };
848
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
738
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
849
739
  var DEFAULT_RETRY_TIMEOUT = 1500;
850
740
  var DEFAULT_RETRY_JITTER = 500;
851
741
  var DEFAULT_MAX_RETRIES_COUNT = 3;
852
742
  var EdgeHttpClient = class {
853
743
  constructor(baseUrl) {
854
744
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
855
- (0, import_log4.log)("created", {
745
+ (0, import_log3.log)("created", {
856
746
  url: this._baseUrl
857
747
  }, {
858
- F: __dxlog_file6,
748
+ F: __dxlog_file5,
859
749
  L: 49,
860
750
  S: this,
861
751
  C: (f, a) => f(...a)
862
752
  });
863
753
  }
754
+ get baseUrl() {
755
+ return this._baseUrl;
756
+ }
864
757
  setIdentity(identity) {
865
758
  if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {
866
759
  this._edgeIdentity = identity;
@@ -970,9 +863,9 @@ var EdgeHttpClient = class {
970
863
  });
971
864
  }
972
865
  async _call(path, args) {
973
- const requestContext = args.context ?? new import_context4.Context(void 0, {
974
- F: __dxlog_file6,
975
- L: 173
866
+ const requestContext = args.context ?? new import_context3.Context(void 0, {
867
+ F: __dxlog_file5,
868
+ L: 177
976
869
  });
977
870
  const shouldRetry = createRetryHandler(args);
978
871
  let url = `${this._baseUrl}${path.startsWith("/") ? path.slice(1) : path}`;
@@ -983,13 +876,13 @@ var EdgeHttpClient = class {
983
876
  }
984
877
  url += `?${queryParams.toString()}`;
985
878
  }
986
- (0, import_log4.log)("call", {
879
+ (0, import_log3.log)("call", {
987
880
  method: args.method,
988
881
  path,
989
882
  request: args.body
990
883
  }, {
991
- F: __dxlog_file6,
992
- L: 185,
884
+ F: __dxlog_file5,
885
+ L: 189,
993
886
  S: this,
994
887
  C: (f, a) => f(...a)
995
888
  });
@@ -1007,12 +900,12 @@ var EdgeHttpClient = class {
1007
900
  if (body.success) {
1008
901
  return body.data;
1009
902
  }
1010
- (0, import_log4.log)("unsuccessful edge response", {
903
+ (0, import_log3.log)("unsuccessful edge response", {
1011
904
  path,
1012
905
  body
1013
906
  }, {
1014
- F: __dxlog_file6,
1015
- L: 204,
907
+ F: __dxlog_file5,
908
+ L: 208,
1016
909
  S: this,
1017
910
  C: (f, a) => f(...a)
1018
911
  });
@@ -1032,12 +925,12 @@ var EdgeHttpClient = class {
1032
925
  processingError = import_protocols.EdgeCallFailedError.fromProcessingFailureCause(error);
1033
926
  }
1034
927
  if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
1035
- (0, import_log4.log)("retrying edge request", {
928
+ (0, import_log3.log)("retrying edge request", {
1036
929
  path,
1037
930
  processingError
1038
931
  }, {
1039
- F: __dxlog_file6,
1040
- L: 223,
932
+ F: __dxlog_file5,
933
+ L: 227,
1041
934
  S: this,
1042
935
  C: (f, a) => f(...a)
1043
936
  });
@@ -1048,9 +941,9 @@ var EdgeHttpClient = class {
1048
941
  }
1049
942
  async _handleUnauthorized(response) {
1050
943
  if (!this._edgeIdentity) {
1051
- import_log4.log.warn("edge unauthorized response received before identity was set", void 0, {
1052
- F: __dxlog_file6,
1053
- L: 232,
944
+ import_log3.log.warn("edge unauthorized response received before identity was set", void 0, {
945
+ F: __dxlog_file5,
946
+ L: 236,
1054
947
  S: this,
1055
948
  C: (f, a) => f(...a)
1056
949
  });
@@ -1058,9 +951,9 @@ var EdgeHttpClient = class {
1058
951
  }
1059
952
  const challenge = await handleAuthChallenge(response, this._edgeIdentity);
1060
953
  this._authHeader = encodeAuthHeader(challenge);
1061
- (0, import_log4.log)("auth header updated", void 0, {
1062
- F: __dxlog_file6,
1063
- L: 237,
954
+ (0, import_log3.log)("auth header updated", void 0, {
955
+ F: __dxlog_file5,
956
+ L: 241,
1064
957
  S: this,
1065
958
  C: (f, a) => f(...a)
1066
959
  });
@@ -1080,10 +973,10 @@ var createRetryHandler = (args) => {
1080
973
  return false;
1081
974
  }
1082
975
  if (retryAfter) {
1083
- await (0, import_async4.sleep)(retryAfter);
976
+ await (0, import_async3.sleep)(retryAfter);
1084
977
  } else {
1085
978
  const timeout = baseTimeout + Math.random() * jitter;
1086
- await (0, import_async4.sleep)(timeout);
979
+ await (0, import_async3.sleep)(timeout);
1087
980
  }
1088
981
  return true;
1089
982
  };