@dxos/edge-client 0.8.4-main.9735255 → 0.8.4-main.9be5663bfe
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 +136 -89
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- 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 +39 -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/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -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 +134 -51
- package/src/edge-ws-connection.ts +2 -1
- 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 -1375
- 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
- /package/dist/lib/{browser → neutral}/testing/index.mjs.map +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,14 +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 { Context as Context3 } from "@dxos/context";
|
|
870
888
|
import { runAndForwardErrors } from "@dxos/effect";
|
|
871
889
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
872
890
|
import { log as log4 } from "@dxos/log";
|
|
873
|
-
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";
|
|
874
893
|
import { createUrl } from "@dxos/util";
|
|
875
894
|
|
|
876
895
|
// src/http-client.ts
|
|
@@ -924,18 +943,20 @@ var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
|
924
943
|
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
925
944
|
var EdgeHttpClient = class {
|
|
926
945
|
_baseUrl;
|
|
946
|
+
_clientTag;
|
|
927
947
|
_edgeIdentity;
|
|
928
948
|
/**
|
|
929
949
|
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
930
950
|
*/
|
|
931
951
|
_authHeader;
|
|
932
|
-
constructor(baseUrl) {
|
|
952
|
+
constructor(baseUrl, options) {
|
|
933
953
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
954
|
+
this._clientTag = options?.clientTag;
|
|
934
955
|
log4("created", {
|
|
935
956
|
url: this._baseUrl
|
|
936
957
|
}, {
|
|
937
958
|
F: __dxlog_file6,
|
|
938
|
-
L:
|
|
959
|
+
L: 121,
|
|
939
960
|
S: this,
|
|
940
961
|
C: (f, a) => f(...a)
|
|
941
962
|
});
|
|
@@ -952,8 +973,8 @@ var EdgeHttpClient = class {
|
|
|
952
973
|
//
|
|
953
974
|
// Status
|
|
954
975
|
//
|
|
955
|
-
async getStatus(args) {
|
|
956
|
-
return this._call(new URL("/status", this.baseUrl), {
|
|
976
|
+
async getStatus(ctx, args) {
|
|
977
|
+
return this._call(ctx, new URL("/status", this.baseUrl), {
|
|
957
978
|
...args,
|
|
958
979
|
method: "GET",
|
|
959
980
|
auth: true
|
|
@@ -962,15 +983,15 @@ var EdgeHttpClient = class {
|
|
|
962
983
|
//
|
|
963
984
|
// Agents
|
|
964
985
|
//
|
|
965
|
-
createAgent(body, args) {
|
|
966
|
-
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), {
|
|
967
988
|
...args,
|
|
968
989
|
method: "POST",
|
|
969
990
|
body
|
|
970
991
|
});
|
|
971
992
|
}
|
|
972
|
-
getAgentStatus(request, args) {
|
|
973
|
-
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), {
|
|
974
995
|
...args,
|
|
975
996
|
method: "GET"
|
|
976
997
|
});
|
|
@@ -978,14 +999,14 @@ var EdgeHttpClient = class {
|
|
|
978
999
|
//
|
|
979
1000
|
// Credentials
|
|
980
1001
|
//
|
|
981
|
-
getCredentialsForNotarization(spaceId, args) {
|
|
982
|
-
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), {
|
|
983
1004
|
...args,
|
|
984
1005
|
method: "GET"
|
|
985
1006
|
});
|
|
986
1007
|
}
|
|
987
|
-
async notarizeCredentials(spaceId, body, args) {
|
|
988
|
-
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), {
|
|
989
1010
|
...args,
|
|
990
1011
|
body,
|
|
991
1012
|
method: "POST"
|
|
@@ -994,8 +1015,8 @@ var EdgeHttpClient = class {
|
|
|
994
1015
|
//
|
|
995
1016
|
// Identity
|
|
996
1017
|
//
|
|
997
|
-
async recoverIdentity(body, args) {
|
|
998
|
-
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), {
|
|
999
1020
|
...args,
|
|
1000
1021
|
body,
|
|
1001
1022
|
method: "POST"
|
|
@@ -1004,8 +1025,8 @@ var EdgeHttpClient = class {
|
|
|
1004
1025
|
//
|
|
1005
1026
|
// Invitations
|
|
1006
1027
|
//
|
|
1007
|
-
async joinSpaceByInvitation(spaceId, body, args) {
|
|
1008
|
-
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), {
|
|
1009
1030
|
...args,
|
|
1010
1031
|
body,
|
|
1011
1032
|
method: "POST"
|
|
@@ -1014,8 +1035,8 @@ var EdgeHttpClient = class {
|
|
|
1014
1035
|
//
|
|
1015
1036
|
// OAuth and credentials
|
|
1016
1037
|
//
|
|
1017
|
-
async initiateOAuthFlow(body, args) {
|
|
1018
|
-
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), {
|
|
1019
1040
|
...args,
|
|
1020
1041
|
body,
|
|
1021
1042
|
method: "POST"
|
|
@@ -1024,8 +1045,8 @@ var EdgeHttpClient = class {
|
|
|
1024
1045
|
//
|
|
1025
1046
|
// Spaces
|
|
1026
1047
|
//
|
|
1027
|
-
async createSpace(body, args) {
|
|
1028
|
-
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), {
|
|
1029
1050
|
...args,
|
|
1030
1051
|
body,
|
|
1031
1052
|
method: "POST"
|
|
@@ -1034,18 +1055,18 @@ var EdgeHttpClient = class {
|
|
|
1034
1055
|
//
|
|
1035
1056
|
// Queues
|
|
1036
1057
|
//
|
|
1037
|
-
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
1058
|
+
async queryQueue(ctx, subspaceTag, spaceId, query, args) {
|
|
1038
1059
|
const queueId = query.queueIds?.[0];
|
|
1039
1060
|
invariant4(queueId, "queueId required", {
|
|
1040
1061
|
F: __dxlog_file6,
|
|
1041
|
-
L:
|
|
1062
|
+
L: 244,
|
|
1042
1063
|
S: this,
|
|
1043
1064
|
A: [
|
|
1044
1065
|
"queueId",
|
|
1045
1066
|
"'queueId required'"
|
|
1046
1067
|
]
|
|
1047
1068
|
});
|
|
1048
|
-
return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
1069
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
1049
1070
|
after: query.after,
|
|
1050
1071
|
before: query.before,
|
|
1051
1072
|
limit: query.limit,
|
|
@@ -1056,8 +1077,8 @@ var EdgeHttpClient = class {
|
|
|
1056
1077
|
method: "GET"
|
|
1057
1078
|
});
|
|
1058
1079
|
}
|
|
1059
|
-
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
1060
|
-
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), {
|
|
1061
1082
|
...args,
|
|
1062
1083
|
body: {
|
|
1063
1084
|
objects
|
|
@@ -1065,8 +1086,8 @@ var EdgeHttpClient = class {
|
|
|
1065
1086
|
method: "POST"
|
|
1066
1087
|
});
|
|
1067
1088
|
}
|
|
1068
|
-
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1069
|
-
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), {
|
|
1070
1091
|
ids: objectIds.join(",")
|
|
1071
1092
|
}), {
|
|
1072
1093
|
...args,
|
|
@@ -1076,7 +1097,7 @@ var EdgeHttpClient = class {
|
|
|
1076
1097
|
//
|
|
1077
1098
|
// Functions
|
|
1078
1099
|
//
|
|
1079
|
-
async uploadFunction(pathParts, body, args) {
|
|
1100
|
+
async uploadFunction(ctx, pathParts, body, args) {
|
|
1080
1101
|
const formData = new FormData();
|
|
1081
1102
|
formData.append("name", body.name ?? "");
|
|
1082
1103
|
formData.append("version", body.version);
|
|
@@ -1096,20 +1117,20 @@ var EdgeHttpClient = class {
|
|
|
1096
1117
|
pathParts.functionId
|
|
1097
1118
|
] : []
|
|
1098
1119
|
].join("/");
|
|
1099
|
-
return this._call(new URL(path, this.baseUrl), {
|
|
1120
|
+
return this._call(ctx, new URL(path, this.baseUrl), {
|
|
1100
1121
|
...args,
|
|
1101
1122
|
body: formData,
|
|
1102
1123
|
method: "PUT",
|
|
1103
1124
|
json: false
|
|
1104
1125
|
});
|
|
1105
1126
|
}
|
|
1106
|
-
async listFunctions(args) {
|
|
1107
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
1127
|
+
async listFunctions(ctx, args) {
|
|
1128
|
+
return this._call(ctx, new URL("/functions", this.baseUrl), {
|
|
1108
1129
|
...args,
|
|
1109
1130
|
method: "GET"
|
|
1110
1131
|
});
|
|
1111
1132
|
}
|
|
1112
|
-
async invokeFunction(params, input, args) {
|
|
1133
|
+
async invokeFunction(ctx, params, input, args) {
|
|
1113
1134
|
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1114
1135
|
if (params.version) {
|
|
1115
1136
|
url.searchParams.set("version", params.version);
|
|
@@ -1123,7 +1144,7 @@ var EdgeHttpClient = class {
|
|
|
1123
1144
|
if (params.subrequestsLimit) {
|
|
1124
1145
|
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1125
1146
|
}
|
|
1126
|
-
return this._call(url, {
|
|
1147
|
+
return this._call(ctx, url, {
|
|
1127
1148
|
...args,
|
|
1128
1149
|
body: input,
|
|
1129
1150
|
method: "POST"
|
|
@@ -1132,8 +1153,8 @@ var EdgeHttpClient = class {
|
|
|
1132
1153
|
//
|
|
1133
1154
|
// Workflows
|
|
1134
1155
|
//
|
|
1135
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1136
|
-
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), {
|
|
1137
1158
|
...args,
|
|
1138
1159
|
body: input,
|
|
1139
1160
|
method: "POST"
|
|
@@ -1142,28 +1163,41 @@ var EdgeHttpClient = class {
|
|
|
1142
1163
|
//
|
|
1143
1164
|
// Triggers
|
|
1144
1165
|
//
|
|
1145
|
-
async getCronTriggers(spaceId) {
|
|
1146
|
-
return this._call(new URL(`/
|
|
1166
|
+
async getCronTriggers(ctx, spaceId) {
|
|
1167
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
1147
1168
|
method: "GET"
|
|
1148
1169
|
});
|
|
1149
1170
|
}
|
|
1150
|
-
async forceRunCronTrigger(spaceId, triggerId) {
|
|
1151
|
-
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,
|
|
1152
1186
|
method: "POST"
|
|
1153
1187
|
});
|
|
1154
1188
|
}
|
|
1155
1189
|
//
|
|
1156
1190
|
// Import/Export space.
|
|
1157
1191
|
//
|
|
1158
|
-
async importBundle(spaceId, body, args) {
|
|
1159
|
-
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), {
|
|
1160
1194
|
...args,
|
|
1161
1195
|
body,
|
|
1162
1196
|
method: "PUT"
|
|
1163
1197
|
});
|
|
1164
1198
|
}
|
|
1165
|
-
async exportBundle(spaceId, body, args) {
|
|
1166
|
-
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), {
|
|
1167
1201
|
...args,
|
|
1168
1202
|
body,
|
|
1169
1203
|
method: "POST"
|
|
@@ -1176,21 +1210,18 @@ var EdgeHttpClient = class {
|
|
|
1176
1210
|
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1177
1211
|
}
|
|
1178
1212
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1179
|
-
async _call(url, args) {
|
|
1213
|
+
async _call(ctx, url, args) {
|
|
1180
1214
|
const shouldRetry = createRetryHandler(args);
|
|
1181
|
-
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1182
|
-
F: __dxlog_file6,
|
|
1183
|
-
L: 408
|
|
1184
|
-
});
|
|
1185
1215
|
log4("fetch", {
|
|
1186
1216
|
url,
|
|
1187
1217
|
request: args.body
|
|
1188
1218
|
}, {
|
|
1189
1219
|
F: __dxlog_file6,
|
|
1190
|
-
L:
|
|
1220
|
+
L: 461,
|
|
1191
1221
|
S: this,
|
|
1192
1222
|
C: (f, a) => f(...a)
|
|
1193
1223
|
});
|
|
1224
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1194
1225
|
let handledAuth = false;
|
|
1195
1226
|
const tryCount = 1;
|
|
1196
1227
|
while (true) {
|
|
@@ -1202,14 +1233,14 @@ var EdgeHttpClient = class {
|
|
|
1202
1233
|
this._authHeader = await this._handleUnauthorized(response2);
|
|
1203
1234
|
}
|
|
1204
1235
|
}
|
|
1205
|
-
const request = createRequest(args, this._authHeader);
|
|
1236
|
+
const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
|
|
1206
1237
|
log4("call edge", {
|
|
1207
1238
|
url,
|
|
1208
1239
|
tryCount,
|
|
1209
1240
|
authHeader: !!this._authHeader
|
|
1210
1241
|
}, {
|
|
1211
1242
|
F: __dxlog_file6,
|
|
1212
|
-
L:
|
|
1243
|
+
L: 478,
|
|
1213
1244
|
S: this,
|
|
1214
1245
|
C: (f, a) => f(...a)
|
|
1215
1246
|
});
|
|
@@ -1218,7 +1249,7 @@ var EdgeHttpClient = class {
|
|
|
1218
1249
|
const body2 = await response.clone().json();
|
|
1219
1250
|
invariant4(body2, "Expected body to be present", {
|
|
1220
1251
|
F: __dxlog_file6,
|
|
1221
|
-
L:
|
|
1252
|
+
L: 483,
|
|
1222
1253
|
S: this,
|
|
1223
1254
|
A: [
|
|
1224
1255
|
"body",
|
|
@@ -1239,7 +1270,7 @@ var EdgeHttpClient = class {
|
|
|
1239
1270
|
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1240
1271
|
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
|
|
1241
1272
|
F: __dxlog_file6,
|
|
1242
|
-
L:
|
|
1273
|
+
L: 499,
|
|
1243
1274
|
S: this,
|
|
1244
1275
|
A: [
|
|
1245
1276
|
"!body?.success",
|
|
@@ -1253,7 +1284,7 @@ var EdgeHttpClient = class {
|
|
|
1253
1284
|
} else {
|
|
1254
1285
|
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1255
1286
|
F: __dxlog_file6,
|
|
1256
|
-
L:
|
|
1287
|
+
L: 506,
|
|
1257
1288
|
S: this,
|
|
1258
1289
|
A: [
|
|
1259
1290
|
"!response.ok",
|
|
@@ -1265,13 +1296,13 @@ var EdgeHttpClient = class {
|
|
|
1265
1296
|
} catch (error) {
|
|
1266
1297
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1267
1298
|
}
|
|
1268
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1299
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1269
1300
|
log4.verbose("retrying edge request", {
|
|
1270
1301
|
url,
|
|
1271
1302
|
processingError
|
|
1272
1303
|
}, {
|
|
1273
1304
|
F: __dxlog_file6,
|
|
1274
|
-
L:
|
|
1305
|
+
L: 514,
|
|
1275
1306
|
S: this,
|
|
1276
1307
|
C: (f, a) => f(...a)
|
|
1277
1308
|
});
|
|
@@ -1284,7 +1315,7 @@ var EdgeHttpClient = class {
|
|
|
1284
1315
|
if (!this._edgeIdentity) {
|
|
1285
1316
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1286
1317
|
F: __dxlog_file6,
|
|
1287
|
-
L:
|
|
1318
|
+
L: 523,
|
|
1288
1319
|
S: this,
|
|
1289
1320
|
C: (f, a) => f(...a)
|
|
1290
1321
|
});
|
|
@@ -1294,7 +1325,7 @@ var EdgeHttpClient = class {
|
|
|
1294
1325
|
return encodeAuthHeader(challenge);
|
|
1295
1326
|
}
|
|
1296
1327
|
};
|
|
1297
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1328
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
|
|
1298
1329
|
let requestBody;
|
|
1299
1330
|
const headers = {};
|
|
1300
1331
|
if (json) {
|
|
@@ -1308,7 +1339,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1308
1339
|
bodySize: requestBody.length
|
|
1309
1340
|
}, {
|
|
1310
1341
|
F: __dxlog_file6,
|
|
1311
|
-
L:
|
|
1342
|
+
L: 549,
|
|
1312
1343
|
S: void 0,
|
|
1313
1344
|
C: (f, a) => f(...a)
|
|
1314
1345
|
});
|
|
@@ -1316,12 +1347,28 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1316
1347
|
if (authHeader) {
|
|
1317
1348
|
headers["Authorization"] = authHeader;
|
|
1318
1349
|
}
|
|
1350
|
+
if (traceHeaders) {
|
|
1351
|
+
Object.assign(headers, traceHeaders);
|
|
1352
|
+
}
|
|
1353
|
+
if (clientTag) {
|
|
1354
|
+
headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
|
|
1355
|
+
}
|
|
1319
1356
|
return {
|
|
1320
1357
|
method,
|
|
1321
1358
|
body: requestBody,
|
|
1322
1359
|
headers
|
|
1323
1360
|
};
|
|
1324
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
|
+
};
|
|
1325
1372
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1326
1373
|
if (!retry2 || retry2.count < 1) {
|
|
1327
1374
|
return async () => false;
|