@dxos/edge-client 0.8.4-main.72ec0f3 → 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 +155 -96
- 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 -33
- 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 +152 -64
- 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 -1363
- 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,18 +1144,17 @@ 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
|
-
method: "POST"
|
|
1119
|
-
rawResponse: true
|
|
1150
|
+
method: "POST"
|
|
1120
1151
|
});
|
|
1121
1152
|
}
|
|
1122
1153
|
//
|
|
1123
1154
|
// Workflows
|
|
1124
1155
|
//
|
|
1125
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1126
|
-
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), {
|
|
1127
1158
|
...args,
|
|
1128
1159
|
body: input,
|
|
1129
1160
|
method: "POST"
|
|
@@ -1132,23 +1163,41 @@ var EdgeHttpClient = class {
|
|
|
1132
1163
|
//
|
|
1133
1164
|
// Triggers
|
|
1134
1165
|
//
|
|
1135
|
-
async getCronTriggers(spaceId) {
|
|
1136
|
-
return this._call(new URL(`/
|
|
1166
|
+
async getCronTriggers(ctx, spaceId) {
|
|
1167
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
1137
1168
|
method: "GET"
|
|
1138
1169
|
});
|
|
1139
1170
|
}
|
|
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,
|
|
1186
|
+
method: "POST"
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1140
1189
|
//
|
|
1141
1190
|
// Import/Export space.
|
|
1142
1191
|
//
|
|
1143
|
-
async importBundle(spaceId, body, args) {
|
|
1144
|
-
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), {
|
|
1145
1194
|
...args,
|
|
1146
1195
|
body,
|
|
1147
1196
|
method: "PUT"
|
|
1148
1197
|
});
|
|
1149
1198
|
}
|
|
1150
|
-
async exportBundle(spaceId, body, args) {
|
|
1151
|
-
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), {
|
|
1152
1201
|
...args,
|
|
1153
1202
|
body,
|
|
1154
1203
|
method: "POST"
|
|
@@ -1158,24 +1207,21 @@ var EdgeHttpClient = class {
|
|
|
1158
1207
|
// Internal
|
|
1159
1208
|
//
|
|
1160
1209
|
async _fetch(url, _args) {
|
|
1161
|
-
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);
|
|
1162
1211
|
}
|
|
1163
1212
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1164
|
-
async _call(url, args) {
|
|
1213
|
+
async _call(ctx, url, args) {
|
|
1165
1214
|
const shouldRetry = createRetryHandler(args);
|
|
1166
|
-
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1167
|
-
F: __dxlog_file6,
|
|
1168
|
-
L: 400
|
|
1169
|
-
});
|
|
1170
1215
|
log4("fetch", {
|
|
1171
1216
|
url,
|
|
1172
1217
|
request: args.body
|
|
1173
1218
|
}, {
|
|
1174
1219
|
F: __dxlog_file6,
|
|
1175
|
-
L:
|
|
1220
|
+
L: 461,
|
|
1176
1221
|
S: this,
|
|
1177
1222
|
C: (f, a) => f(...a)
|
|
1178
1223
|
});
|
|
1224
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1179
1225
|
let handledAuth = false;
|
|
1180
1226
|
const tryCount = 1;
|
|
1181
1227
|
while (true) {
|
|
@@ -1187,26 +1233,23 @@ var EdgeHttpClient = class {
|
|
|
1187
1233
|
this._authHeader = await this._handleUnauthorized(response2);
|
|
1188
1234
|
}
|
|
1189
1235
|
}
|
|
1190
|
-
const request = createRequest(args, this._authHeader);
|
|
1236
|
+
const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
|
|
1191
1237
|
log4("call edge", {
|
|
1192
1238
|
url,
|
|
1193
1239
|
tryCount,
|
|
1194
1240
|
authHeader: !!this._authHeader
|
|
1195
1241
|
}, {
|
|
1196
1242
|
F: __dxlog_file6,
|
|
1197
|
-
L:
|
|
1243
|
+
L: 478,
|
|
1198
1244
|
S: this,
|
|
1199
1245
|
C: (f, a) => f(...a)
|
|
1200
1246
|
});
|
|
1201
1247
|
const response = await fetch(url, request);
|
|
1202
1248
|
if (response.ok) {
|
|
1203
1249
|
const body2 = await response.clone().json();
|
|
1204
|
-
if (args.rawResponse) {
|
|
1205
|
-
return body2;
|
|
1206
|
-
}
|
|
1207
1250
|
invariant4(body2, "Expected body to be present", {
|
|
1208
1251
|
F: __dxlog_file6,
|
|
1209
|
-
L:
|
|
1252
|
+
L: 483,
|
|
1210
1253
|
S: this,
|
|
1211
1254
|
A: [
|
|
1212
1255
|
"body",
|
|
@@ -1227,21 +1270,21 @@ var EdgeHttpClient = class {
|
|
|
1227
1270
|
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1228
1271
|
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
|
|
1229
1272
|
F: __dxlog_file6,
|
|
1230
|
-
L:
|
|
1273
|
+
L: 499,
|
|
1231
1274
|
S: this,
|
|
1232
1275
|
A: [
|
|
1233
1276
|
"!body?.success",
|
|
1234
1277
|
"'Expected body to not be a failure response or undefined.'"
|
|
1235
1278
|
]
|
|
1236
1279
|
});
|
|
1237
|
-
if (body?.
|
|
1238
|
-
processingError = new EdgeAuthChallengeError(body.
|
|
1280
|
+
if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
|
|
1281
|
+
processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
|
|
1239
1282
|
} else if (body?.success === false) {
|
|
1240
1283
|
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1241
1284
|
} else {
|
|
1242
1285
|
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1243
1286
|
F: __dxlog_file6,
|
|
1244
|
-
L:
|
|
1287
|
+
L: 506,
|
|
1245
1288
|
S: this,
|
|
1246
1289
|
A: [
|
|
1247
1290
|
"!response.ok",
|
|
@@ -1253,13 +1296,13 @@ var EdgeHttpClient = class {
|
|
|
1253
1296
|
} catch (error) {
|
|
1254
1297
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1255
1298
|
}
|
|
1256
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1299
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1257
1300
|
log4.verbose("retrying edge request", {
|
|
1258
1301
|
url,
|
|
1259
1302
|
processingError
|
|
1260
1303
|
}, {
|
|
1261
1304
|
F: __dxlog_file6,
|
|
1262
|
-
L:
|
|
1305
|
+
L: 514,
|
|
1263
1306
|
S: this,
|
|
1264
1307
|
C: (f, a) => f(...a)
|
|
1265
1308
|
});
|
|
@@ -1272,7 +1315,7 @@ var EdgeHttpClient = class {
|
|
|
1272
1315
|
if (!this._edgeIdentity) {
|
|
1273
1316
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1274
1317
|
F: __dxlog_file6,
|
|
1275
|
-
L:
|
|
1318
|
+
L: 523,
|
|
1276
1319
|
S: this,
|
|
1277
1320
|
C: (f, a) => f(...a)
|
|
1278
1321
|
});
|
|
@@ -1282,7 +1325,7 @@ var EdgeHttpClient = class {
|
|
|
1282
1325
|
return encodeAuthHeader(challenge);
|
|
1283
1326
|
}
|
|
1284
1327
|
};
|
|
1285
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1328
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
|
|
1286
1329
|
let requestBody;
|
|
1287
1330
|
const headers = {};
|
|
1288
1331
|
if (json) {
|
|
@@ -1296,7 +1339,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1296
1339
|
bodySize: requestBody.length
|
|
1297
1340
|
}, {
|
|
1298
1341
|
F: __dxlog_file6,
|
|
1299
|
-
L:
|
|
1342
|
+
L: 549,
|
|
1300
1343
|
S: void 0,
|
|
1301
1344
|
C: (f, a) => f(...a)
|
|
1302
1345
|
});
|
|
@@ -1304,12 +1347,28 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1304
1347
|
if (authHeader) {
|
|
1305
1348
|
headers["Authorization"] = authHeader;
|
|
1306
1349
|
}
|
|
1350
|
+
if (traceHeaders) {
|
|
1351
|
+
Object.assign(headers, traceHeaders);
|
|
1352
|
+
}
|
|
1353
|
+
if (clientTag) {
|
|
1354
|
+
headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
|
|
1355
|
+
}
|
|
1307
1356
|
return {
|
|
1308
1357
|
method,
|
|
1309
1358
|
body: requestBody,
|
|
1310
1359
|
headers
|
|
1311
1360
|
};
|
|
1312
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
|
+
};
|
|
1313
1372
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1314
1373
|
if (!retry2 || retry2.count < 1) {
|
|
1315
1374
|
return async () => false;
|