@dxos/edge-client 0.13.0 → 0.14.0
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.
- package/dist/lib/chunk-edge-http-client.mjs +47 -24
- package/dist/lib/chunk-edge-http-client.mjs.map +1 -1
- package/dist/lib/index.mjs +60 -39
- package/dist/lib/index.mjs.map +1 -1
- package/dist/types/src/auth-challenge.d.ts +2 -1
- package/dist/types/src/auth-challenge.d.ts.map +1 -1
- package/dist/types/src/base-http-client.d.ts +1 -1
- package/dist/types/src/base-http-client.d.ts.map +1 -1
- package/dist/types/src/client-version.d.ts +15 -0
- package/dist/types/src/client-version.d.ts.map +1 -0
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/src/auth-challenge.test.ts +17 -2
- package/src/auth-challenge.ts +9 -2
- package/src/base-http-client.ts +15 -2
- package/src/client-version.ts +44 -0
- package/src/edge-client.test.ts +28 -2
- package/src/edge-client.ts +25 -3
- package/src/edge-http-client.test.ts +43 -0
- package/src/edge-http-client.ts +1 -4
- package/src/edge-ws-connection.ts +3 -4
package/dist/lib/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { proxyFetchLegacy } from "./cors-proxy.mjs";
|
|
2
|
-
import { _ as parseChallengeHeader, a as HttpConfig, c as withRetry, d as EdgeConnectionClosedError, f as EdgeIdentityChangedError, g as handleAuthChallenge, h as fetchAuthChallengeInfo, i as getEdgeUrlWithProtocol, l as withRetryConfig, m as fetchAuthChallenge, n as EdgeHttpClientService, o as encodeAuthHeader, p as authenticateViaChallengeEndpoint, r as BaseHttpClient, s as withLogging, t as EdgeHttpClient, u as EdgeClientError, v as presentCredentialsForChallenge, y as readAuthChallenge } from "./chunk-edge-http-client.mjs";
|
|
2
|
+
import { S as clientVersionProtocol, _ as parseChallengeHeader, a as HttpConfig, b as assertClientSupported, c as withRetry, d as EdgeConnectionClosedError, f as EdgeIdentityChangedError, g as handleAuthChallenge, h as fetchAuthChallengeInfo, i as getEdgeUrlWithProtocol, l as withRetryConfig, m as fetchAuthChallenge, n as EdgeHttpClientService, o as encodeAuthHeader, p as authenticateViaChallengeEndpoint, r as BaseHttpClient, s as withLogging, t as EdgeHttpClient, u as EdgeClientError, v as presentCredentialsForChallenge, x as clientVersionHeaders, y as readAuthChallenge } from "./chunk-edge-http-client.mjs";
|
|
3
3
|
import { a as MAX_INBOUND_TOTAL_BYTES, c as WebSocketClosedError, d as Protocol, f as getTypename, i as MAX_INBOUND_MESSAGE_BYTES, l as WebSocketMuxer, n as CLOUDFLARE_RPC_MAX_BYTES, o as MessageTooLargeError, p as toUint8Array, r as MAX_INBOUND_CHUNK_COUNT, s as SegmentedMessageLimitError, t as CLOUDFLARE_MESSAGE_MAX_BYTES, u as protocol } from "./chunk-edge-ws-muxer.mjs";
|
|
4
4
|
import * as EffectContext from "effect/Context";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
@@ -9,7 +9,7 @@ import * as Layer from "effect/Layer";
|
|
|
9
9
|
import * as Schema from "effect/Schema";
|
|
10
10
|
import { invariant } from "@dxos/invariant";
|
|
11
11
|
import { log, logInfo } from "@dxos/log";
|
|
12
|
-
import { BYOK_HEADER,
|
|
12
|
+
import { BYOK_HEADER, EdgeClientTooOldError, EdgeCredentialsHeaderCodec, EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
13
13
|
import { createUrl } from "@dxos/util";
|
|
14
14
|
import { Event, Mutex, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask, scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
15
15
|
import { Context, Resource, TRACE_SPAN_ATTRIBUTE } from "@dxos/context";
|
|
@@ -124,9 +124,6 @@ var createStubEdgeIdentity = () => {
|
|
|
124
124
|
};
|
|
125
125
|
};
|
|
126
126
|
//#endregion
|
|
127
|
-
//#region package.json
|
|
128
|
-
var version = "0.13.0";
|
|
129
|
-
//#endregion
|
|
130
127
|
//#region src/reconnect-reason.ts
|
|
131
128
|
/**
|
|
132
129
|
* Classifies a close event.
|
|
@@ -397,7 +394,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
397
394
|
}
|
|
398
395
|
}
|
|
399
396
|
async _open() {
|
|
400
|
-
const baseProtocols = [...Object.values(EdgeWebsocketProtocol),
|
|
397
|
+
const baseProtocols = [...Object.values(EdgeWebsocketProtocol), clientVersionProtocol()];
|
|
401
398
|
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [...baseProtocols, this._connectionInfo.protocolHeader] : [...baseProtocols], this._connectionInfo.headers ? { headers: this._connectionInfo.headers } : void 0);
|
|
402
399
|
this._ws.binaryType = "arraybuffer";
|
|
403
400
|
const muxer = new WebSocketMuxer(this._ws);
|
|
@@ -407,7 +404,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
407
404
|
log("connected", void 0, {
|
|
408
405
|
"~LogMeta": "~LogMeta",
|
|
409
406
|
F: __dxlog_file$2,
|
|
410
|
-
L:
|
|
407
|
+
L: 201,
|
|
411
408
|
S: this
|
|
412
409
|
});
|
|
413
410
|
this._openTimestamp = Date.now();
|
|
@@ -420,7 +417,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
420
417
|
log.verbose("connected after becoming inactive", { currentIdentity: this._identity }, {
|
|
421
418
|
"~LogMeta": "~LogMeta",
|
|
422
419
|
F: __dxlog_file$2,
|
|
423
|
-
L:
|
|
420
|
+
L: 209,
|
|
424
421
|
S: this
|
|
425
422
|
});
|
|
426
423
|
}
|
|
@@ -435,7 +432,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
435
432
|
}, {
|
|
436
433
|
"~LogMeta": "~LogMeta",
|
|
437
434
|
F: __dxlog_file$2,
|
|
438
|
-
L:
|
|
435
|
+
L: 215,
|
|
439
436
|
S: this
|
|
440
437
|
});
|
|
441
438
|
this._pendingMessages = [];
|
|
@@ -451,14 +448,14 @@ var EdgeWsConnection = class extends Resource {
|
|
|
451
448
|
}, {
|
|
452
449
|
"~LogMeta": "~LogMeta",
|
|
453
450
|
F: __dxlog_file$2,
|
|
454
|
-
L:
|
|
451
|
+
L: 223,
|
|
455
452
|
S: this
|
|
456
453
|
});
|
|
457
454
|
this._callbacks.onRestartRequired(classifySocketError(isOnline()));
|
|
458
455
|
} else log.verbose("error ignored on closed connection", { error: event.error }, {
|
|
459
456
|
"~LogMeta": "~LogMeta",
|
|
460
457
|
F: __dxlog_file$2,
|
|
461
|
-
L:
|
|
458
|
+
L: 226,
|
|
462
459
|
S: this
|
|
463
460
|
});
|
|
464
461
|
};
|
|
@@ -470,7 +467,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
470
467
|
log.verbose("message ignored on closed connection", { event: event.type }, {
|
|
471
468
|
"~LogMeta": "~LogMeta",
|
|
472
469
|
F: __dxlog_file$2,
|
|
473
|
-
L:
|
|
470
|
+
L: 234,
|
|
474
471
|
S: this
|
|
475
472
|
});
|
|
476
473
|
return;
|
|
@@ -488,7 +485,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
488
485
|
this._receiveMessage(event.data, muxer).catch((err) => log.catch(err, void 0, {
|
|
489
486
|
"~LogMeta": "~LogMeta",
|
|
490
487
|
F: __dxlog_file$2,
|
|
491
|
-
L:
|
|
488
|
+
L: 251,
|
|
492
489
|
S: this
|
|
493
490
|
}));
|
|
494
491
|
};
|
|
@@ -515,7 +512,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
515
512
|
}, {
|
|
516
513
|
"~LogMeta": "~LogMeta",
|
|
517
514
|
F: __dxlog_file$2,
|
|
518
|
-
L:
|
|
515
|
+
L: 282,
|
|
519
516
|
S: this
|
|
520
517
|
});
|
|
521
518
|
this._callbacks.onMessage(message);
|
|
@@ -539,7 +536,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
539
536
|
log.warn("error closing websocket", { err }, {
|
|
540
537
|
"~LogMeta": "~LogMeta",
|
|
541
538
|
F: __dxlog_file$2,
|
|
542
|
-
L:
|
|
539
|
+
L: 300,
|
|
543
540
|
S: this
|
|
544
541
|
});
|
|
545
542
|
}
|
|
@@ -548,7 +545,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
548
545
|
invariant(this._ws, void 0, {
|
|
549
546
|
"~LogMeta": "~LogMeta",
|
|
550
547
|
F: __dxlog_file$2,
|
|
551
|
-
L:
|
|
548
|
+
L: 305,
|
|
552
549
|
S: this,
|
|
553
550
|
A: ["this._ws", ""]
|
|
554
551
|
});
|
|
@@ -582,7 +579,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
582
579
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
583
580
|
"~LogMeta": "~LogMeta",
|
|
584
581
|
F: __dxlog_file$2,
|
|
585
|
-
L:
|
|
582
|
+
L: 350
|
|
586
583
|
});
|
|
587
584
|
const armedAt = Date.now();
|
|
588
585
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
@@ -606,7 +603,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
606
603
|
}, {
|
|
607
604
|
"~LogMeta": "~LogMeta",
|
|
608
605
|
F: __dxlog_file$2,
|
|
609
|
-
L:
|
|
606
|
+
L: 374,
|
|
610
607
|
S: this
|
|
611
608
|
});
|
|
612
609
|
this._callbacks.onRestartRequired("inactivity_timeout");
|
|
@@ -621,7 +618,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
621
618
|
}, {
|
|
622
619
|
"~LogMeta": "~LogMeta",
|
|
623
620
|
F: __dxlog_file$2,
|
|
624
|
-
L:
|
|
621
|
+
L: 385,
|
|
625
622
|
S: this
|
|
626
623
|
});
|
|
627
624
|
this._unansweredProbes++;
|
|
@@ -703,6 +700,8 @@ var EdgeClient = class extends Resource {
|
|
|
703
700
|
_baseHttpUrl;
|
|
704
701
|
_currentConnection = void 0;
|
|
705
702
|
_ready = new Trigger();
|
|
703
|
+
/** Set when EDGE refused this SDK as outdated; a retry would carry the same version, so none is made. */
|
|
704
|
+
#refusal = void 0;
|
|
706
705
|
constructor(_identity, _config) {
|
|
707
706
|
super();
|
|
708
707
|
this._identity = _identity;
|
|
@@ -743,7 +742,7 @@ var EdgeClient = class extends Resource {
|
|
|
743
742
|
}, {
|
|
744
743
|
"~LogMeta": "~LogMeta",
|
|
745
744
|
F: __dxlog_file$1,
|
|
746
|
-
L:
|
|
745
|
+
L: 171,
|
|
747
746
|
S: this
|
|
748
747
|
});
|
|
749
748
|
this._identity = identity;
|
|
@@ -756,11 +755,12 @@ var EdgeClient = class extends Resource {
|
|
|
756
755
|
* NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
|
|
757
756
|
*/
|
|
758
757
|
async send(ctx, message) {
|
|
758
|
+
if (this.#refusal) throw this.#refusal;
|
|
759
759
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
760
760
|
log("waiting for websocket", void 0, {
|
|
761
761
|
"~LogMeta": "~LogMeta",
|
|
762
762
|
F: __dxlog_file$1,
|
|
763
|
-
L:
|
|
763
|
+
L: 187,
|
|
764
764
|
S: this
|
|
765
765
|
});
|
|
766
766
|
await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });
|
|
@@ -788,7 +788,7 @@ var EdgeClient = class extends Resource {
|
|
|
788
788
|
log.catch(error, void 0, {
|
|
789
789
|
"~LogMeta": "~LogMeta",
|
|
790
790
|
F: __dxlog_file$1,
|
|
791
|
-
L:
|
|
791
|
+
L: 230,
|
|
792
792
|
S: this
|
|
793
793
|
});
|
|
794
794
|
}
|
|
@@ -806,7 +806,7 @@ var EdgeClient = class extends Resource {
|
|
|
806
806
|
log.warn("Error while opening connection", { err }, {
|
|
807
807
|
"~LogMeta": "~LogMeta",
|
|
808
808
|
F: __dxlog_file$1,
|
|
809
|
-
L:
|
|
809
|
+
L: 249,
|
|
810
810
|
S: this
|
|
811
811
|
});
|
|
812
812
|
});
|
|
@@ -818,14 +818,14 @@ var EdgeClient = class extends Resource {
|
|
|
818
818
|
log("opening...", { info: this.info }, {
|
|
819
819
|
"~LogMeta": "~LogMeta",
|
|
820
820
|
F: __dxlog_file$1,
|
|
821
|
-
L:
|
|
821
|
+
L: 257,
|
|
822
822
|
S: this
|
|
823
823
|
});
|
|
824
824
|
this.#registerMetrics();
|
|
825
825
|
if (this._config.deferConnect) log("deferring connection until startNetworking", void 0, {
|
|
826
826
|
"~LogMeta": "~LogMeta",
|
|
827
827
|
F: __dxlog_file$1,
|
|
828
|
-
L:
|
|
828
|
+
L: 260,
|
|
829
829
|
S: this
|
|
830
830
|
});
|
|
831
831
|
else this.startNetworking();
|
|
@@ -841,7 +841,7 @@ var EdgeClient = class extends Resource {
|
|
|
841
841
|
log("closing...", { peerKey: this._identity.peerKey }, {
|
|
842
842
|
"~LogMeta": "~LogMeta",
|
|
843
843
|
F: __dxlog_file$1,
|
|
844
|
-
L:
|
|
844
|
+
L: 282,
|
|
845
845
|
S: this
|
|
846
846
|
});
|
|
847
847
|
for (const cleanup of this.#metricsCleanup) cleanup();
|
|
@@ -853,12 +853,29 @@ var EdgeClient = class extends Resource {
|
|
|
853
853
|
if (this._ctx.disposed) return;
|
|
854
854
|
const identity = this._identity;
|
|
855
855
|
const path = `/ws/${identity.identityDid}/${identity.peerKey}`;
|
|
856
|
-
|
|
856
|
+
this.#refusal = void 0;
|
|
857
|
+
let protocolHeader;
|
|
858
|
+
try {
|
|
859
|
+
protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
860
|
+
} catch (err) {
|
|
861
|
+
if (!(err instanceof EdgeClientTooOldError)) throw err;
|
|
862
|
+
log.warn("EDGE refused this SDK as outdated; not reconnecting until the app is updated", { data: err.data }, {
|
|
863
|
+
"~LogMeta": "~LogMeta",
|
|
864
|
+
F: __dxlog_file$1,
|
|
865
|
+
L: 307,
|
|
866
|
+
S: this
|
|
867
|
+
});
|
|
868
|
+
this.#refusal = err;
|
|
869
|
+
this._ready.throw(err);
|
|
870
|
+
this._ready.reset();
|
|
871
|
+
this.statusChanged.emit(this.status);
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
857
874
|
if (this._identity !== identity) {
|
|
858
875
|
log("identity changed during auth header request", void 0, {
|
|
859
876
|
"~LogMeta": "~LogMeta",
|
|
860
877
|
F: __dxlog_file$1,
|
|
861
|
-
L:
|
|
878
|
+
L: 315,
|
|
862
879
|
S: this
|
|
863
880
|
});
|
|
864
881
|
return;
|
|
@@ -871,7 +888,7 @@ var EdgeClient = class extends Resource {
|
|
|
871
888
|
}, {
|
|
872
889
|
"~LogMeta": "~LogMeta",
|
|
873
890
|
F: __dxlog_file$1,
|
|
874
|
-
L:
|
|
891
|
+
L: 321,
|
|
875
892
|
S: this
|
|
876
893
|
});
|
|
877
894
|
const connection = new EdgeWsConnection(identity, {
|
|
@@ -887,13 +904,13 @@ var EdgeClient = class extends Resource {
|
|
|
887
904
|
log.verbose("closing a connection that connected after it was replaced", void 0, {
|
|
888
905
|
"~LogMeta": "~LogMeta",
|
|
889
906
|
F: __dxlog_file$1,
|
|
890
|
-
L:
|
|
907
|
+
L: 336,
|
|
891
908
|
S: this
|
|
892
909
|
});
|
|
893
910
|
connection.close().catch((err) => log.catch(err, void 0, {
|
|
894
911
|
"~LogMeta": "~LogMeta",
|
|
895
912
|
F: __dxlog_file$1,
|
|
896
|
-
L:
|
|
913
|
+
L: 337,
|
|
897
914
|
S: this
|
|
898
915
|
}));
|
|
899
916
|
}
|
|
@@ -906,7 +923,7 @@ var EdgeClient = class extends Resource {
|
|
|
906
923
|
} else log.verbose("restart requested by inactive connection", void 0, {
|
|
907
924
|
"~LogMeta": "~LogMeta",
|
|
908
925
|
F: __dxlog_file$1,
|
|
909
|
-
L:
|
|
926
|
+
L: 346,
|
|
910
927
|
S: this
|
|
911
928
|
});
|
|
912
929
|
restartRequired.wake();
|
|
@@ -920,13 +937,13 @@ var EdgeClient = class extends Resource {
|
|
|
920
937
|
}, {
|
|
921
938
|
"~LogMeta": "~LogMeta",
|
|
922
939
|
F: __dxlog_file$1,
|
|
923
|
-
L:
|
|
940
|
+
L: 354,
|
|
924
941
|
S: this
|
|
925
942
|
});
|
|
926
943
|
connection.close().catch((err) => log.catch(err, void 0, {
|
|
927
944
|
"~LogMeta": "~LogMeta",
|
|
928
945
|
F: __dxlog_file$1,
|
|
929
|
-
L:
|
|
946
|
+
L: 358,
|
|
930
947
|
S: this
|
|
931
948
|
}));
|
|
932
949
|
}
|
|
@@ -969,7 +986,7 @@ var EdgeClient = class extends Resource {
|
|
|
969
986
|
}, {
|
|
970
987
|
"~LogMeta": "~LogMeta",
|
|
971
988
|
F: __dxlog_file$1,
|
|
972
|
-
L:
|
|
989
|
+
L: 424,
|
|
973
990
|
S: this
|
|
974
991
|
});
|
|
975
992
|
trace.metrics.increment("dxos.edge.ws.reconnect.count", 1, {
|
|
@@ -985,7 +1002,7 @@ var EdgeClient = class extends Resource {
|
|
|
985
1002
|
log.error("ws reconnect listener failed", { err }, {
|
|
986
1003
|
"~LogMeta": "~LogMeta",
|
|
987
1004
|
F: __dxlog_file$1,
|
|
988
|
-
L:
|
|
1005
|
+
L: 437,
|
|
989
1006
|
S: this
|
|
990
1007
|
});
|
|
991
1008
|
}
|
|
@@ -1000,7 +1017,7 @@ var EdgeClient = class extends Resource {
|
|
|
1000
1017
|
}, {
|
|
1001
1018
|
"~LogMeta": "~LogMeta",
|
|
1002
1019
|
F: __dxlog_file$1,
|
|
1003
|
-
L:
|
|
1020
|
+
L: 447,
|
|
1004
1021
|
S: this
|
|
1005
1022
|
});
|
|
1006
1023
|
}
|
|
@@ -1020,7 +1037,11 @@ var EdgeClient = class extends Resource {
|
|
|
1020
1037
|
async _createAuthHeader(path) {
|
|
1021
1038
|
const authentication = await authenticateViaChallengeEndpoint(this._baseHttpUrl, this._identity);
|
|
1022
1039
|
if (authentication) return encodePresentationWsAuthHeader(authentication.presentation);
|
|
1023
|
-
const response = await fetch(new URL(path, this._baseHttpUrl), {
|
|
1040
|
+
const response = await fetch(new URL(path, this._baseHttpUrl), {
|
|
1041
|
+
method: "GET",
|
|
1042
|
+
headers: clientVersionHeaders()
|
|
1043
|
+
});
|
|
1044
|
+
await assertClientSupported(response);
|
|
1024
1045
|
const challenge = response.status === 401 ? await readAuthChallenge(response) : void 0;
|
|
1025
1046
|
if (challenge) return encodePresentationWsAuthHeader(await presentCredentialsForChallenge(this._identity, challenge));
|
|
1026
1047
|
log.warn("no auth challenge from edge", {
|
|
@@ -1029,7 +1050,7 @@ var EdgeClient = class extends Resource {
|
|
|
1029
1050
|
}, {
|
|
1030
1051
|
"~LogMeta": "~LogMeta",
|
|
1031
1052
|
F: __dxlog_file$1,
|
|
1032
|
-
L:
|
|
1053
|
+
L: 479,
|
|
1033
1054
|
S: this
|
|
1034
1055
|
});
|
|
1035
1056
|
}
|