@dxos/edge-client 0.8.4-main.70d3990 → 0.8.4-main.74a063c4e0
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/{browser → neutral}/index.mjs +149 -91
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs.map +1 -1
- package/dist/types/src/edge-client.d.ts +5 -2
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +42 -29
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts +1 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts +2 -2
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +28 -24
- package/src/edge-client.test.ts +16 -11
- package/src/edge-client.ts +32 -3
- package/src/edge-http-client.test.ts +2 -1
- package/src/edge-http-client.ts +144 -53
- package/src/edge-ws-connection.ts +2 -1
- package/src/http-client.test.ts +3 -2
- package/src/testing/test-utils.ts +4 -4
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/chunk-JTBFRYNM.mjs +0 -303
- package/dist/lib/node-esm/chunk-JTBFRYNM.mjs.map +0 -7
- package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -1364
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -186
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- /package/dist/lib/{browser → neutral}/chunk-VESGVCLQ.mjs +0 -0
- /package/dist/lib/{browser → neutral}/chunk-VESGVCLQ.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/edge-ws-muxer.mjs +0 -0
- /package/dist/lib/{browser → neutral}/edge-ws-muxer.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/testing/index.mjs +0 -0
|
@@ -123,10 +123,12 @@ var createStubEdgeIdentity = () => {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
// src/edge-client.ts
|
|
126
|
+
import { propagation } from "@opentelemetry/api";
|
|
126
127
|
import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask, scheduleTaskInterval as scheduleTaskInterval2 } from "@dxos/async";
|
|
127
128
|
import { Resource as Resource2 } from "@dxos/context";
|
|
128
129
|
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
129
130
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
131
|
+
import { TRACE_PROCESSOR, TRACE_SPAN_ATTRIBUTE } from "@dxos/tracing";
|
|
130
132
|
|
|
131
133
|
// src/edge-identity.ts
|
|
132
134
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
@@ -300,14 +302,16 @@ var EdgeWsConnection = class extends Resource {
|
|
|
300
302
|
this._connectionInfo.protocolHeader
|
|
301
303
|
] : [
|
|
302
304
|
...baseProtocols
|
|
303
|
-
]
|
|
305
|
+
], this._connectionInfo.headers ? {
|
|
306
|
+
headers: this._connectionInfo.headers
|
|
307
|
+
} : void 0);
|
|
304
308
|
const muxer = new WebSocketMuxer(this._ws);
|
|
305
309
|
this._wsMuxer = muxer;
|
|
306
310
|
this._ws.onopen = () => {
|
|
307
311
|
if (this.isOpen) {
|
|
308
312
|
log("connected", void 0, {
|
|
309
313
|
F: __dxlog_file3,
|
|
310
|
-
L:
|
|
314
|
+
L: 131,
|
|
311
315
|
S: this,
|
|
312
316
|
C: (f, a) => f(...a)
|
|
313
317
|
});
|
|
@@ -320,7 +324,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
320
324
|
currentIdentity: this._identity
|
|
321
325
|
}, {
|
|
322
326
|
F: __dxlog_file3,
|
|
323
|
-
L:
|
|
327
|
+
L: 137,
|
|
324
328
|
S: this,
|
|
325
329
|
C: (f, a) => f(...a)
|
|
326
330
|
});
|
|
@@ -333,7 +337,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
333
337
|
reason: event.reason
|
|
334
338
|
}, {
|
|
335
339
|
F: __dxlog_file3,
|
|
336
|
-
L:
|
|
340
|
+
L: 142,
|
|
337
341
|
S: this,
|
|
338
342
|
C: (f, a) => f(...a)
|
|
339
343
|
});
|
|
@@ -348,7 +352,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
348
352
|
info: event.message
|
|
349
353
|
}, {
|
|
350
354
|
F: __dxlog_file3,
|
|
351
|
-
L:
|
|
355
|
+
L: 149,
|
|
352
356
|
S: this,
|
|
353
357
|
C: (f, a) => f(...a)
|
|
354
358
|
});
|
|
@@ -358,7 +362,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
358
362
|
error: event.error
|
|
359
363
|
}, {
|
|
360
364
|
F: __dxlog_file3,
|
|
361
|
-
L:
|
|
365
|
+
L: 152,
|
|
362
366
|
S: this,
|
|
363
367
|
C: (f, a) => f(...a)
|
|
364
368
|
});
|
|
@@ -370,7 +374,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
370
374
|
event: event.type
|
|
371
375
|
}, {
|
|
372
376
|
F: __dxlog_file3,
|
|
373
|
-
L:
|
|
377
|
+
L: 160,
|
|
374
378
|
S: this,
|
|
375
379
|
C: (f, a) => f(...a)
|
|
376
380
|
});
|
|
@@ -398,7 +402,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
398
402
|
payload: protocol.getPayloadType(message)
|
|
399
403
|
}, {
|
|
400
404
|
F: __dxlog_file3,
|
|
401
|
-
L:
|
|
405
|
+
L: 186,
|
|
402
406
|
S: this,
|
|
403
407
|
C: (f, a) => f(...a)
|
|
404
408
|
});
|
|
@@ -422,7 +426,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
422
426
|
err
|
|
423
427
|
}, {
|
|
424
428
|
F: __dxlog_file3,
|
|
425
|
-
L:
|
|
429
|
+
L: 204,
|
|
426
430
|
S: this,
|
|
427
431
|
C: (f, a) => f(...a)
|
|
428
432
|
});
|
|
@@ -431,7 +435,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
431
435
|
_scheduleHeartbeats() {
|
|
432
436
|
invariant3(this._ws, void 0, {
|
|
433
437
|
F: __dxlog_file3,
|
|
434
|
-
L:
|
|
438
|
+
L: 209,
|
|
435
439
|
S: this,
|
|
436
440
|
A: [
|
|
437
441
|
"this._ws",
|
|
@@ -453,7 +457,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
453
457
|
void this._inactivityTimeoutCtx?.dispose();
|
|
454
458
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
455
459
|
F: __dxlog_file3,
|
|
456
|
-
L:
|
|
460
|
+
L: 230
|
|
457
461
|
});
|
|
458
462
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
459
463
|
if (this.isOpen) {
|
|
@@ -462,7 +466,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
462
466
|
lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
|
|
463
467
|
}, {
|
|
464
468
|
F: __dxlog_file3,
|
|
465
|
-
L:
|
|
469
|
+
L: 236,
|
|
466
470
|
S: this,
|
|
467
471
|
C: (f, a) => f(...a)
|
|
468
472
|
});
|
|
@@ -600,7 +604,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
600
604
|
oldIdentity: this._identity
|
|
601
605
|
}, {
|
|
602
606
|
F: __dxlog_file4,
|
|
603
|
-
L:
|
|
607
|
+
L: 124,
|
|
604
608
|
S: this,
|
|
605
609
|
C: (f, a) => f(...a)
|
|
606
610
|
});
|
|
@@ -613,11 +617,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
613
617
|
* Send message.
|
|
614
618
|
* NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
|
|
615
619
|
*/
|
|
616
|
-
async send(message) {
|
|
620
|
+
async send(ctx, message) {
|
|
617
621
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
618
622
|
log2("waiting for websocket", void 0, {
|
|
619
623
|
F: __dxlog_file4,
|
|
620
|
-
L:
|
|
624
|
+
L: 137,
|
|
621
625
|
S: this,
|
|
622
626
|
C: (f, a) => f(...a)
|
|
623
627
|
});
|
|
@@ -631,6 +635,17 @@ var EdgeClient = class extends Resource2 {
|
|
|
631
635
|
if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
|
|
632
636
|
throw new EdgeIdentityChangedError();
|
|
633
637
|
}
|
|
638
|
+
const spanId = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE);
|
|
639
|
+
const otlpContext = typeof spanId === "number" ? TRACE_PROCESSOR.remoteTracing.getSpanContext(spanId) : void 0;
|
|
640
|
+
if (otlpContext) {
|
|
641
|
+
const activeSpan = {};
|
|
642
|
+
propagation.inject(otlpContext, activeSpan);
|
|
643
|
+
message.traceContext = {
|
|
644
|
+
$typeName: "dxos.edge.messenger.TraceContext",
|
|
645
|
+
traceparent: activeSpan.traceparent,
|
|
646
|
+
tracestate: activeSpan.tracestate
|
|
647
|
+
};
|
|
648
|
+
}
|
|
634
649
|
this._currentConnection.send(message);
|
|
635
650
|
}
|
|
636
651
|
onMessage(listener) {
|
|
@@ -647,7 +662,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
647
662
|
} catch (error) {
|
|
648
663
|
log2.catch(error, void 0, {
|
|
649
664
|
F: __dxlog_file4,
|
|
650
|
-
L:
|
|
665
|
+
L: 189,
|
|
651
666
|
S: this,
|
|
652
667
|
C: (f, a) => f(...a)
|
|
653
668
|
});
|
|
@@ -665,7 +680,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
665
680
|
info: this.info
|
|
666
681
|
}, {
|
|
667
682
|
F: __dxlog_file4,
|
|
668
|
-
L:
|
|
683
|
+
L: 202,
|
|
669
684
|
S: this,
|
|
670
685
|
C: (f, a) => f(...a)
|
|
671
686
|
});
|
|
@@ -674,7 +689,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
674
689
|
err
|
|
675
690
|
}, {
|
|
676
691
|
F: __dxlog_file4,
|
|
677
|
-
L:
|
|
692
|
+
L: 204,
|
|
678
693
|
S: this,
|
|
679
694
|
C: (f, a) => f(...a)
|
|
680
695
|
});
|
|
@@ -694,7 +709,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
694
709
|
peerKey: this._identity.peerKey
|
|
695
710
|
}, {
|
|
696
711
|
F: __dxlog_file4,
|
|
697
|
-
L:
|
|
712
|
+
L: 224,
|
|
698
713
|
S: this,
|
|
699
714
|
C: (f, a) => f(...a)
|
|
700
715
|
});
|
|
@@ -711,7 +726,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
711
726
|
if (this._identity !== identity) {
|
|
712
727
|
log2("identity changed during auth header request", void 0, {
|
|
713
728
|
F: __dxlog_file4,
|
|
714
|
-
L:
|
|
729
|
+
L: 238,
|
|
715
730
|
S: this,
|
|
716
731
|
C: (f, a) => f(...a)
|
|
717
732
|
});
|
|
@@ -724,13 +739,16 @@ var EdgeClient = class extends Resource2 {
|
|
|
724
739
|
protocolHeader
|
|
725
740
|
}, {
|
|
726
741
|
F: __dxlog_file4,
|
|
727
|
-
L:
|
|
742
|
+
L: 244,
|
|
728
743
|
S: this,
|
|
729
744
|
C: (f, a) => f(...a)
|
|
730
745
|
});
|
|
731
746
|
const connection = new EdgeWsConnection(identity, {
|
|
732
747
|
url,
|
|
733
|
-
protocolHeader
|
|
748
|
+
protocolHeader,
|
|
749
|
+
headers: this._config.clientTag ? {
|
|
750
|
+
"X-DXOS-Client-Tag": this._config.clientTag
|
|
751
|
+
} : void 0
|
|
734
752
|
}, {
|
|
735
753
|
onConnected: () => {
|
|
736
754
|
if (this._isActive(connection)) {
|
|
@@ -739,7 +757,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
739
757
|
} else {
|
|
740
758
|
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
741
759
|
F: __dxlog_file4,
|
|
742
|
-
L:
|
|
760
|
+
L: 258,
|
|
743
761
|
S: this,
|
|
744
762
|
C: (f, a) => f(...a)
|
|
745
763
|
});
|
|
@@ -752,7 +770,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
752
770
|
} else {
|
|
753
771
|
log2.verbose("restart requested by inactive connection", void 0, {
|
|
754
772
|
F: __dxlog_file4,
|
|
755
|
-
L:
|
|
773
|
+
L: 266,
|
|
756
774
|
S: this,
|
|
757
775
|
C: (f, a) => f(...a)
|
|
758
776
|
});
|
|
@@ -768,7 +786,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
768
786
|
type: message.payload?.typeUrl
|
|
769
787
|
}, {
|
|
770
788
|
F: __dxlog_file4,
|
|
771
|
-
L:
|
|
789
|
+
L: 274,
|
|
772
790
|
S: this,
|
|
773
791
|
C: (f, a) => f(...a)
|
|
774
792
|
});
|
|
@@ -805,7 +823,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
805
823
|
err
|
|
806
824
|
}, {
|
|
807
825
|
F: __dxlog_file4,
|
|
808
|
-
L:
|
|
826
|
+
L: 309,
|
|
809
827
|
S: this,
|
|
810
828
|
C: (f, a) => f(...a)
|
|
811
829
|
});
|
|
@@ -822,7 +840,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
822
840
|
payload: protocol.getPayloadType(message)
|
|
823
841
|
}, {
|
|
824
842
|
F: __dxlog_file4,
|
|
825
|
-
L:
|
|
843
|
+
L: 319,
|
|
826
844
|
S: this,
|
|
827
845
|
C: (f, a) => f(...a)
|
|
828
846
|
});
|
|
@@ -843,7 +861,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
843
861
|
statusText: response.statusText
|
|
844
862
|
}, {
|
|
845
863
|
F: __dxlog_file4,
|
|
846
|
-
L:
|
|
864
|
+
L: 331,
|
|
847
865
|
S: this,
|
|
848
866
|
C: (f, a) => f(...a)
|
|
849
867
|
});
|
|
@@ -863,13 +881,15 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
863
881
|
// src/edge-http-client.ts
|
|
864
882
|
import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
|
|
865
883
|
import * as HttpClient from "@effect/platform/HttpClient";
|
|
884
|
+
import { propagation as propagation2 } from "@opentelemetry/api";
|
|
866
885
|
import * as Effect2 from "effect/Effect";
|
|
867
886
|
import * as Function from "effect/Function";
|
|
868
887
|
import { sleep } from "@dxos/async";
|
|
869
|
-
import {
|
|
888
|
+
import { runAndForwardErrors } from "@dxos/effect";
|
|
870
889
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
871
890
|
import { log as log4 } from "@dxos/log";
|
|
872
|
-
import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
891
|
+
import { EDGE_CLIENT_TAG_HEADER, EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
892
|
+
import { TRACE_PROCESSOR as TRACE_PROCESSOR2, TRACE_SPAN_ATTRIBUTE as TRACE_SPAN_ATTRIBUTE2 } from "@dxos/tracing";
|
|
873
893
|
import { createUrl } from "@dxos/util";
|
|
874
894
|
|
|
875
895
|
// src/http-client.ts
|
|
@@ -923,18 +943,20 @@ var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
|
923
943
|
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
924
944
|
var EdgeHttpClient = class {
|
|
925
945
|
_baseUrl;
|
|
946
|
+
_clientTag;
|
|
926
947
|
_edgeIdentity;
|
|
927
948
|
/**
|
|
928
949
|
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
929
950
|
*/
|
|
930
951
|
_authHeader;
|
|
931
|
-
constructor(baseUrl) {
|
|
952
|
+
constructor(baseUrl, options) {
|
|
932
953
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
954
|
+
this._clientTag = options?.clientTag;
|
|
933
955
|
log4("created", {
|
|
934
956
|
url: this._baseUrl
|
|
935
957
|
}, {
|
|
936
958
|
F: __dxlog_file6,
|
|
937
|
-
L:
|
|
959
|
+
L: 121,
|
|
938
960
|
S: this,
|
|
939
961
|
C: (f, a) => f(...a)
|
|
940
962
|
});
|
|
@@ -951,24 +973,25 @@ var EdgeHttpClient = class {
|
|
|
951
973
|
//
|
|
952
974
|
// Status
|
|
953
975
|
//
|
|
954
|
-
async getStatus(args) {
|
|
955
|
-
return this._call(new URL("/status", this.baseUrl), {
|
|
976
|
+
async getStatus(ctx, args) {
|
|
977
|
+
return this._call(ctx, new URL("/status", this.baseUrl), {
|
|
956
978
|
...args,
|
|
957
|
-
method: "GET"
|
|
979
|
+
method: "GET",
|
|
980
|
+
auth: true
|
|
958
981
|
});
|
|
959
982
|
}
|
|
960
983
|
//
|
|
961
984
|
// Agents
|
|
962
985
|
//
|
|
963
|
-
createAgent(body, args) {
|
|
964
|
-
return this._call(new URL("/agents/create", this.baseUrl), {
|
|
986
|
+
createAgent(ctx, body, args) {
|
|
987
|
+
return this._call(ctx, new URL("/agents/create", this.baseUrl), {
|
|
965
988
|
...args,
|
|
966
989
|
method: "POST",
|
|
967
990
|
body
|
|
968
991
|
});
|
|
969
992
|
}
|
|
970
|
-
getAgentStatus(request, args) {
|
|
971
|
-
return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
993
|
+
getAgentStatus(ctx, request, args) {
|
|
994
|
+
return this._call(ctx, new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
972
995
|
...args,
|
|
973
996
|
method: "GET"
|
|
974
997
|
});
|
|
@@ -976,14 +999,14 @@ var EdgeHttpClient = class {
|
|
|
976
999
|
//
|
|
977
1000
|
// Credentials
|
|
978
1001
|
//
|
|
979
|
-
getCredentialsForNotarization(spaceId, args) {
|
|
980
|
-
return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
1002
|
+
getCredentialsForNotarization(ctx, spaceId, args) {
|
|
1003
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
981
1004
|
...args,
|
|
982
1005
|
method: "GET"
|
|
983
1006
|
});
|
|
984
1007
|
}
|
|
985
|
-
async notarizeCredentials(spaceId, body, args) {
|
|
986
|
-
await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
1008
|
+
async notarizeCredentials(ctx, spaceId, body, args) {
|
|
1009
|
+
await this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
987
1010
|
...args,
|
|
988
1011
|
body,
|
|
989
1012
|
method: "POST"
|
|
@@ -992,8 +1015,8 @@ var EdgeHttpClient = class {
|
|
|
992
1015
|
//
|
|
993
1016
|
// Identity
|
|
994
1017
|
//
|
|
995
|
-
async recoverIdentity(body, args) {
|
|
996
|
-
return this._call(new URL("/identity/recover", this.baseUrl), {
|
|
1018
|
+
async recoverIdentity(ctx, body, args) {
|
|
1019
|
+
return this._call(ctx, new URL("/identity/recover", this.baseUrl), {
|
|
997
1020
|
...args,
|
|
998
1021
|
body,
|
|
999
1022
|
method: "POST"
|
|
@@ -1002,8 +1025,8 @@ var EdgeHttpClient = class {
|
|
|
1002
1025
|
//
|
|
1003
1026
|
// Invitations
|
|
1004
1027
|
//
|
|
1005
|
-
async joinSpaceByInvitation(spaceId, body, args) {
|
|
1006
|
-
return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
1028
|
+
async joinSpaceByInvitation(ctx, spaceId, body, args) {
|
|
1029
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
1007
1030
|
...args,
|
|
1008
1031
|
body,
|
|
1009
1032
|
method: "POST"
|
|
@@ -1012,8 +1035,8 @@ var EdgeHttpClient = class {
|
|
|
1012
1035
|
//
|
|
1013
1036
|
// OAuth and credentials
|
|
1014
1037
|
//
|
|
1015
|
-
async initiateOAuthFlow(body, args) {
|
|
1016
|
-
return this._call(new URL("/oauth/initiate", this.baseUrl), {
|
|
1038
|
+
async initiateOAuthFlow(ctx, body, args) {
|
|
1039
|
+
return this._call(ctx, new URL("/oauth/initiate", this.baseUrl), {
|
|
1017
1040
|
...args,
|
|
1018
1041
|
body,
|
|
1019
1042
|
method: "POST"
|
|
@@ -1022,8 +1045,8 @@ var EdgeHttpClient = class {
|
|
|
1022
1045
|
//
|
|
1023
1046
|
// Spaces
|
|
1024
1047
|
//
|
|
1025
|
-
async createSpace(body, args) {
|
|
1026
|
-
return this._call(new URL("/spaces/create", this.baseUrl), {
|
|
1048
|
+
async createSpace(ctx, body, args) {
|
|
1049
|
+
return this._call(ctx, new URL("/spaces/create", this.baseUrl), {
|
|
1027
1050
|
...args,
|
|
1028
1051
|
body,
|
|
1029
1052
|
method: "POST"
|
|
@@ -1032,9 +1055,18 @@ var EdgeHttpClient = class {
|
|
|
1032
1055
|
//
|
|
1033
1056
|
// Queues
|
|
1034
1057
|
//
|
|
1035
|
-
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1058
|
+
async queryQueue(ctx, subspaceTag, spaceId, query, args) {
|
|
1059
|
+
const queueId = query.queueIds?.[0];
|
|
1060
|
+
invariant4(queueId, "queueId required", {
|
|
1061
|
+
F: __dxlog_file6,
|
|
1062
|
+
L: 244,
|
|
1063
|
+
S: this,
|
|
1064
|
+
A: [
|
|
1065
|
+
"queueId",
|
|
1066
|
+
"'queueId required'"
|
|
1067
|
+
]
|
|
1068
|
+
});
|
|
1069
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
1038
1070
|
after: query.after,
|
|
1039
1071
|
before: query.before,
|
|
1040
1072
|
limit: query.limit,
|
|
@@ -1045,8 +1077,8 @@ var EdgeHttpClient = class {
|
|
|
1045
1077
|
method: "GET"
|
|
1046
1078
|
});
|
|
1047
1079
|
}
|
|
1048
|
-
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
1049
|
-
return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1080
|
+
async insertIntoQueue(ctx, subspaceTag, spaceId, queueId, objects, args) {
|
|
1081
|
+
return this._call(ctx, new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1050
1082
|
...args,
|
|
1051
1083
|
body: {
|
|
1052
1084
|
objects
|
|
@@ -1054,8 +1086,8 @@ var EdgeHttpClient = class {
|
|
|
1054
1086
|
method: "POST"
|
|
1055
1087
|
});
|
|
1056
1088
|
}
|
|
1057
|
-
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1058
|
-
return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1089
|
+
async deleteFromQueue(ctx, subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1090
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1059
1091
|
ids: objectIds.join(",")
|
|
1060
1092
|
}), {
|
|
1061
1093
|
...args,
|
|
@@ -1065,7 +1097,7 @@ var EdgeHttpClient = class {
|
|
|
1065
1097
|
//
|
|
1066
1098
|
// Functions
|
|
1067
1099
|
//
|
|
1068
|
-
async uploadFunction(pathParts, body, args) {
|
|
1100
|
+
async uploadFunction(ctx, pathParts, body, args) {
|
|
1069
1101
|
const formData = new FormData();
|
|
1070
1102
|
formData.append("name", body.name ?? "");
|
|
1071
1103
|
formData.append("version", body.version);
|
|
@@ -1085,20 +1117,20 @@ var EdgeHttpClient = class {
|
|
|
1085
1117
|
pathParts.functionId
|
|
1086
1118
|
] : []
|
|
1087
1119
|
].join("/");
|
|
1088
|
-
return this._call(new URL(path, this.baseUrl), {
|
|
1120
|
+
return this._call(ctx, new URL(path, this.baseUrl), {
|
|
1089
1121
|
...args,
|
|
1090
1122
|
body: formData,
|
|
1091
1123
|
method: "PUT",
|
|
1092
1124
|
json: false
|
|
1093
1125
|
});
|
|
1094
1126
|
}
|
|
1095
|
-
async listFunctions(args) {
|
|
1096
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
1127
|
+
async listFunctions(ctx, args) {
|
|
1128
|
+
return this._call(ctx, new URL("/functions", this.baseUrl), {
|
|
1097
1129
|
...args,
|
|
1098
1130
|
method: "GET"
|
|
1099
1131
|
});
|
|
1100
1132
|
}
|
|
1101
|
-
async invokeFunction(params, input, args) {
|
|
1133
|
+
async invokeFunction(ctx, params, input, args) {
|
|
1102
1134
|
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1103
1135
|
if (params.version) {
|
|
1104
1136
|
url.searchParams.set("version", params.version);
|
|
@@ -1112,7 +1144,7 @@ var EdgeHttpClient = class {
|
|
|
1112
1144
|
if (params.subrequestsLimit) {
|
|
1113
1145
|
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1114
1146
|
}
|
|
1115
|
-
return this._call(url, {
|
|
1147
|
+
return this._call(ctx, url, {
|
|
1116
1148
|
...args,
|
|
1117
1149
|
body: input,
|
|
1118
1150
|
method: "POST"
|
|
@@ -1121,8 +1153,8 @@ var EdgeHttpClient = class {
|
|
|
1121
1153
|
//
|
|
1122
1154
|
// Workflows
|
|
1123
1155
|
//
|
|
1124
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1125
|
-
return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
1156
|
+
async executeWorkflow(ctx, spaceId, graphId, input, args) {
|
|
1157
|
+
return this._call(ctx, new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
1126
1158
|
...args,
|
|
1127
1159
|
body: input,
|
|
1128
1160
|
method: "POST"
|
|
@@ -1131,28 +1163,41 @@ var EdgeHttpClient = class {
|
|
|
1131
1163
|
//
|
|
1132
1164
|
// Triggers
|
|
1133
1165
|
//
|
|
1134
|
-
async getCronTriggers(spaceId) {
|
|
1135
|
-
return this._call(new URL(`/
|
|
1166
|
+
async getCronTriggers(ctx, spaceId) {
|
|
1167
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
1136
1168
|
method: "GET"
|
|
1137
1169
|
});
|
|
1138
1170
|
}
|
|
1139
|
-
async forceRunCronTrigger(spaceId, triggerId) {
|
|
1140
|
-
return this._call(new URL(`/
|
|
1171
|
+
async forceRunCronTrigger(ctx, spaceId, triggerId) {
|
|
1172
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
|
|
1173
|
+
method: "POST"
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
//
|
|
1177
|
+
// Query
|
|
1178
|
+
//
|
|
1179
|
+
/**
|
|
1180
|
+
* Execute a QueryAST query against a space.
|
|
1181
|
+
*/
|
|
1182
|
+
async execQuery(ctx, spaceId, body, args) {
|
|
1183
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), {
|
|
1184
|
+
...args,
|
|
1185
|
+
body,
|
|
1141
1186
|
method: "POST"
|
|
1142
1187
|
});
|
|
1143
1188
|
}
|
|
1144
1189
|
//
|
|
1145
1190
|
// Import/Export space.
|
|
1146
1191
|
//
|
|
1147
|
-
async importBundle(spaceId, body, args) {
|
|
1148
|
-
return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1192
|
+
async importBundle(ctx, spaceId, body, args) {
|
|
1193
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1149
1194
|
...args,
|
|
1150
1195
|
body,
|
|
1151
1196
|
method: "PUT"
|
|
1152
1197
|
});
|
|
1153
1198
|
}
|
|
1154
|
-
async exportBundle(spaceId, body, args) {
|
|
1155
|
-
return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1199
|
+
async exportBundle(ctx, spaceId, body, args) {
|
|
1200
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1156
1201
|
...args,
|
|
1157
1202
|
body,
|
|
1158
1203
|
method: "POST"
|
|
@@ -1162,24 +1207,21 @@ var EdgeHttpClient = class {
|
|
|
1162
1207
|
// Internal
|
|
1163
1208
|
//
|
|
1164
1209
|
async _fetch(url, _args) {
|
|
1165
|
-
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"),
|
|
1210
|
+
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1166
1211
|
}
|
|
1167
1212
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1168
|
-
async _call(url, args) {
|
|
1213
|
+
async _call(ctx, url, args) {
|
|
1169
1214
|
const shouldRetry = createRetryHandler(args);
|
|
1170
|
-
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1171
|
-
F: __dxlog_file6,
|
|
1172
|
-
L: 400
|
|
1173
|
-
});
|
|
1174
1215
|
log4("fetch", {
|
|
1175
1216
|
url,
|
|
1176
1217
|
request: args.body
|
|
1177
1218
|
}, {
|
|
1178
1219
|
F: __dxlog_file6,
|
|
1179
|
-
L:
|
|
1220
|
+
L: 461,
|
|
1180
1221
|
S: this,
|
|
1181
1222
|
C: (f, a) => f(...a)
|
|
1182
1223
|
});
|
|
1224
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1183
1225
|
let handledAuth = false;
|
|
1184
1226
|
const tryCount = 1;
|
|
1185
1227
|
while (true) {
|
|
@@ -1191,14 +1233,14 @@ var EdgeHttpClient = class {
|
|
|
1191
1233
|
this._authHeader = await this._handleUnauthorized(response2);
|
|
1192
1234
|
}
|
|
1193
1235
|
}
|
|
1194
|
-
const request = createRequest(args, this._authHeader);
|
|
1236
|
+
const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
|
|
1195
1237
|
log4("call edge", {
|
|
1196
1238
|
url,
|
|
1197
1239
|
tryCount,
|
|
1198
1240
|
authHeader: !!this._authHeader
|
|
1199
1241
|
}, {
|
|
1200
1242
|
F: __dxlog_file6,
|
|
1201
|
-
L:
|
|
1243
|
+
L: 478,
|
|
1202
1244
|
S: this,
|
|
1203
1245
|
C: (f, a) => f(...a)
|
|
1204
1246
|
});
|
|
@@ -1207,7 +1249,7 @@ var EdgeHttpClient = class {
|
|
|
1207
1249
|
const body2 = await response.clone().json();
|
|
1208
1250
|
invariant4(body2, "Expected body to be present", {
|
|
1209
1251
|
F: __dxlog_file6,
|
|
1210
|
-
L:
|
|
1252
|
+
L: 483,
|
|
1211
1253
|
S: this,
|
|
1212
1254
|
A: [
|
|
1213
1255
|
"body",
|
|
@@ -1228,7 +1270,7 @@ var EdgeHttpClient = class {
|
|
|
1228
1270
|
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1229
1271
|
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
|
|
1230
1272
|
F: __dxlog_file6,
|
|
1231
|
-
L:
|
|
1273
|
+
L: 499,
|
|
1232
1274
|
S: this,
|
|
1233
1275
|
A: [
|
|
1234
1276
|
"!body?.success",
|
|
@@ -1242,7 +1284,7 @@ var EdgeHttpClient = class {
|
|
|
1242
1284
|
} else {
|
|
1243
1285
|
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1244
1286
|
F: __dxlog_file6,
|
|
1245
|
-
L:
|
|
1287
|
+
L: 506,
|
|
1246
1288
|
S: this,
|
|
1247
1289
|
A: [
|
|
1248
1290
|
"!response.ok",
|
|
@@ -1254,13 +1296,13 @@ var EdgeHttpClient = class {
|
|
|
1254
1296
|
} catch (error) {
|
|
1255
1297
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1256
1298
|
}
|
|
1257
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1299
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1258
1300
|
log4.verbose("retrying edge request", {
|
|
1259
1301
|
url,
|
|
1260
1302
|
processingError
|
|
1261
1303
|
}, {
|
|
1262
1304
|
F: __dxlog_file6,
|
|
1263
|
-
L:
|
|
1305
|
+
L: 514,
|
|
1264
1306
|
S: this,
|
|
1265
1307
|
C: (f, a) => f(...a)
|
|
1266
1308
|
});
|
|
@@ -1273,7 +1315,7 @@ var EdgeHttpClient = class {
|
|
|
1273
1315
|
if (!this._edgeIdentity) {
|
|
1274
1316
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1275
1317
|
F: __dxlog_file6,
|
|
1276
|
-
L:
|
|
1318
|
+
L: 523,
|
|
1277
1319
|
S: this,
|
|
1278
1320
|
C: (f, a) => f(...a)
|
|
1279
1321
|
});
|
|
@@ -1283,7 +1325,7 @@ var EdgeHttpClient = class {
|
|
|
1283
1325
|
return encodeAuthHeader(challenge);
|
|
1284
1326
|
}
|
|
1285
1327
|
};
|
|
1286
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1328
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
|
|
1287
1329
|
let requestBody;
|
|
1288
1330
|
const headers = {};
|
|
1289
1331
|
if (json) {
|
|
@@ -1297,7 +1339,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1297
1339
|
bodySize: requestBody.length
|
|
1298
1340
|
}, {
|
|
1299
1341
|
F: __dxlog_file6,
|
|
1300
|
-
L:
|
|
1342
|
+
L: 549,
|
|
1301
1343
|
S: void 0,
|
|
1302
1344
|
C: (f, a) => f(...a)
|
|
1303
1345
|
});
|
|
@@ -1305,12 +1347,28 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1305
1347
|
if (authHeader) {
|
|
1306
1348
|
headers["Authorization"] = authHeader;
|
|
1307
1349
|
}
|
|
1350
|
+
if (traceHeaders) {
|
|
1351
|
+
Object.assign(headers, traceHeaders);
|
|
1352
|
+
}
|
|
1353
|
+
if (clientTag) {
|
|
1354
|
+
headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
|
|
1355
|
+
}
|
|
1308
1356
|
return {
|
|
1309
1357
|
method,
|
|
1310
1358
|
body: requestBody,
|
|
1311
1359
|
headers
|
|
1312
1360
|
};
|
|
1313
1361
|
};
|
|
1362
|
+
var getTraceHeaders = (ctx) => {
|
|
1363
|
+
const spanId = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE2);
|
|
1364
|
+
const otlpContext = typeof spanId === "number" ? TRACE_PROCESSOR2.remoteTracing.getSpanContext(spanId) : void 0;
|
|
1365
|
+
if (!otlpContext) {
|
|
1366
|
+
return void 0;
|
|
1367
|
+
}
|
|
1368
|
+
const headers = {};
|
|
1369
|
+
propagation2.inject(otlpContext, headers);
|
|
1370
|
+
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
1371
|
+
};
|
|
1314
1372
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1315
1373
|
if (!retry2 || retry2.count < 1) {
|
|
1316
1374
|
return async () => false;
|