@dxos/edge-client 0.8.4-main.72ec0f3 → 0.8.4-main.7996785055
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 +130 -81
- 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 +3 -2
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +33 -32
- package/dist/types/src/edge-http-client.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 +25 -3
- package/src/edge-http-client.test.ts +2 -1
- package/src/edge-http-client.ts +136 -63
- 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";
|
|
@@ -600,7 +602,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
600
602
|
oldIdentity: this._identity
|
|
601
603
|
}, {
|
|
602
604
|
F: __dxlog_file4,
|
|
603
|
-
L:
|
|
605
|
+
L: 121,
|
|
604
606
|
S: this,
|
|
605
607
|
C: (f, a) => f(...a)
|
|
606
608
|
});
|
|
@@ -613,11 +615,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
613
615
|
* Send message.
|
|
614
616
|
* NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
|
|
615
617
|
*/
|
|
616
|
-
async send(message) {
|
|
618
|
+
async send(ctx, message) {
|
|
617
619
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
618
620
|
log2("waiting for websocket", void 0, {
|
|
619
621
|
F: __dxlog_file4,
|
|
620
|
-
L:
|
|
622
|
+
L: 134,
|
|
621
623
|
S: this,
|
|
622
624
|
C: (f, a) => f(...a)
|
|
623
625
|
});
|
|
@@ -631,6 +633,17 @@ var EdgeClient = class extends Resource2 {
|
|
|
631
633
|
if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
|
|
632
634
|
throw new EdgeIdentityChangedError();
|
|
633
635
|
}
|
|
636
|
+
const spanId = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE);
|
|
637
|
+
const otlpContext = typeof spanId === "number" ? TRACE_PROCESSOR.remoteTracing.getSpanContext(spanId) : void 0;
|
|
638
|
+
if (otlpContext) {
|
|
639
|
+
const activeSpan = {};
|
|
640
|
+
propagation.inject(otlpContext, activeSpan);
|
|
641
|
+
message.traceContext = {
|
|
642
|
+
$typeName: "dxos.edge.messenger.TraceContext",
|
|
643
|
+
traceparent: activeSpan.traceparent,
|
|
644
|
+
tracestate: activeSpan.tracestate
|
|
645
|
+
};
|
|
646
|
+
}
|
|
634
647
|
this._currentConnection.send(message);
|
|
635
648
|
}
|
|
636
649
|
onMessage(listener) {
|
|
@@ -647,7 +660,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
647
660
|
} catch (error) {
|
|
648
661
|
log2.catch(error, void 0, {
|
|
649
662
|
F: __dxlog_file4,
|
|
650
|
-
L:
|
|
663
|
+
L: 186,
|
|
651
664
|
S: this,
|
|
652
665
|
C: (f, a) => f(...a)
|
|
653
666
|
});
|
|
@@ -665,7 +678,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
665
678
|
info: this.info
|
|
666
679
|
}, {
|
|
667
680
|
F: __dxlog_file4,
|
|
668
|
-
L:
|
|
681
|
+
L: 199,
|
|
669
682
|
S: this,
|
|
670
683
|
C: (f, a) => f(...a)
|
|
671
684
|
});
|
|
@@ -674,7 +687,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
674
687
|
err
|
|
675
688
|
}, {
|
|
676
689
|
F: __dxlog_file4,
|
|
677
|
-
L:
|
|
690
|
+
L: 201,
|
|
678
691
|
S: this,
|
|
679
692
|
C: (f, a) => f(...a)
|
|
680
693
|
});
|
|
@@ -694,7 +707,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
694
707
|
peerKey: this._identity.peerKey
|
|
695
708
|
}, {
|
|
696
709
|
F: __dxlog_file4,
|
|
697
|
-
L:
|
|
710
|
+
L: 221,
|
|
698
711
|
S: this,
|
|
699
712
|
C: (f, a) => f(...a)
|
|
700
713
|
});
|
|
@@ -711,7 +724,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
711
724
|
if (this._identity !== identity) {
|
|
712
725
|
log2("identity changed during auth header request", void 0, {
|
|
713
726
|
F: __dxlog_file4,
|
|
714
|
-
L:
|
|
727
|
+
L: 235,
|
|
715
728
|
S: this,
|
|
716
729
|
C: (f, a) => f(...a)
|
|
717
730
|
});
|
|
@@ -724,7 +737,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
724
737
|
protocolHeader
|
|
725
738
|
}, {
|
|
726
739
|
F: __dxlog_file4,
|
|
727
|
-
L:
|
|
740
|
+
L: 241,
|
|
728
741
|
S: this,
|
|
729
742
|
C: (f, a) => f(...a)
|
|
730
743
|
});
|
|
@@ -739,7 +752,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
739
752
|
} else {
|
|
740
753
|
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
741
754
|
F: __dxlog_file4,
|
|
742
|
-
L:
|
|
755
|
+
L: 251,
|
|
743
756
|
S: this,
|
|
744
757
|
C: (f, a) => f(...a)
|
|
745
758
|
});
|
|
@@ -752,7 +765,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
752
765
|
} else {
|
|
753
766
|
log2.verbose("restart requested by inactive connection", void 0, {
|
|
754
767
|
F: __dxlog_file4,
|
|
755
|
-
L:
|
|
768
|
+
L: 259,
|
|
756
769
|
S: this,
|
|
757
770
|
C: (f, a) => f(...a)
|
|
758
771
|
});
|
|
@@ -768,7 +781,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
768
781
|
type: message.payload?.typeUrl
|
|
769
782
|
}, {
|
|
770
783
|
F: __dxlog_file4,
|
|
771
|
-
L:
|
|
784
|
+
L: 267,
|
|
772
785
|
S: this,
|
|
773
786
|
C: (f, a) => f(...a)
|
|
774
787
|
});
|
|
@@ -805,7 +818,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
805
818
|
err
|
|
806
819
|
}, {
|
|
807
820
|
F: __dxlog_file4,
|
|
808
|
-
L:
|
|
821
|
+
L: 302,
|
|
809
822
|
S: this,
|
|
810
823
|
C: (f, a) => f(...a)
|
|
811
824
|
});
|
|
@@ -822,7 +835,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
822
835
|
payload: protocol.getPayloadType(message)
|
|
823
836
|
}, {
|
|
824
837
|
F: __dxlog_file4,
|
|
825
|
-
L:
|
|
838
|
+
L: 312,
|
|
826
839
|
S: this,
|
|
827
840
|
C: (f, a) => f(...a)
|
|
828
841
|
});
|
|
@@ -843,7 +856,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
843
856
|
statusText: response.statusText
|
|
844
857
|
}, {
|
|
845
858
|
F: __dxlog_file4,
|
|
846
|
-
L:
|
|
859
|
+
L: 324,
|
|
847
860
|
S: this,
|
|
848
861
|
C: (f, a) => f(...a)
|
|
849
862
|
});
|
|
@@ -865,11 +878,13 @@ import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
|
|
|
865
878
|
import * as HttpClient from "@effect/platform/HttpClient";
|
|
866
879
|
import * as Effect2 from "effect/Effect";
|
|
867
880
|
import * as Function from "effect/Function";
|
|
881
|
+
import { propagation as propagation2 } from "@opentelemetry/api";
|
|
868
882
|
import { sleep } from "@dxos/async";
|
|
869
|
-
import {
|
|
883
|
+
import { runAndForwardErrors } from "@dxos/effect";
|
|
870
884
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
871
885
|
import { log as log4 } from "@dxos/log";
|
|
872
886
|
import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
887
|
+
import { TRACE_PROCESSOR as TRACE_PROCESSOR2, TRACE_SPAN_ATTRIBUTE as TRACE_SPAN_ATTRIBUTE2 } from "@dxos/tracing";
|
|
873
888
|
import { createUrl } from "@dxos/util";
|
|
874
889
|
|
|
875
890
|
// src/http-client.ts
|
|
@@ -934,7 +949,7 @@ var EdgeHttpClient = class {
|
|
|
934
949
|
url: this._baseUrl
|
|
935
950
|
}, {
|
|
936
951
|
F: __dxlog_file6,
|
|
937
|
-
L:
|
|
952
|
+
L: 111,
|
|
938
953
|
S: this,
|
|
939
954
|
C: (f, a) => f(...a)
|
|
940
955
|
});
|
|
@@ -951,24 +966,25 @@ var EdgeHttpClient = class {
|
|
|
951
966
|
//
|
|
952
967
|
// Status
|
|
953
968
|
//
|
|
954
|
-
async getStatus(args) {
|
|
955
|
-
return this._call(new URL("/status", this.baseUrl), {
|
|
969
|
+
async getStatus(ctx, args) {
|
|
970
|
+
return this._call(ctx, new URL("/status", this.baseUrl), {
|
|
956
971
|
...args,
|
|
957
|
-
method: "GET"
|
|
972
|
+
method: "GET",
|
|
973
|
+
auth: true
|
|
958
974
|
});
|
|
959
975
|
}
|
|
960
976
|
//
|
|
961
977
|
// Agents
|
|
962
978
|
//
|
|
963
|
-
createAgent(body, args) {
|
|
964
|
-
return this._call(new URL("/agents/create", this.baseUrl), {
|
|
979
|
+
createAgent(ctx, body, args) {
|
|
980
|
+
return this._call(ctx, new URL("/agents/create", this.baseUrl), {
|
|
965
981
|
...args,
|
|
966
982
|
method: "POST",
|
|
967
983
|
body
|
|
968
984
|
});
|
|
969
985
|
}
|
|
970
|
-
getAgentStatus(request, args) {
|
|
971
|
-
return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
986
|
+
getAgentStatus(ctx, request, args) {
|
|
987
|
+
return this._call(ctx, new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
972
988
|
...args,
|
|
973
989
|
method: "GET"
|
|
974
990
|
});
|
|
@@ -976,14 +992,14 @@ var EdgeHttpClient = class {
|
|
|
976
992
|
//
|
|
977
993
|
// Credentials
|
|
978
994
|
//
|
|
979
|
-
getCredentialsForNotarization(spaceId, args) {
|
|
980
|
-
return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
995
|
+
getCredentialsForNotarization(ctx, spaceId, args) {
|
|
996
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
981
997
|
...args,
|
|
982
998
|
method: "GET"
|
|
983
999
|
});
|
|
984
1000
|
}
|
|
985
|
-
async notarizeCredentials(spaceId, body, args) {
|
|
986
|
-
await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
1001
|
+
async notarizeCredentials(ctx, spaceId, body, args) {
|
|
1002
|
+
await this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
987
1003
|
...args,
|
|
988
1004
|
body,
|
|
989
1005
|
method: "POST"
|
|
@@ -992,8 +1008,8 @@ var EdgeHttpClient = class {
|
|
|
992
1008
|
//
|
|
993
1009
|
// Identity
|
|
994
1010
|
//
|
|
995
|
-
async recoverIdentity(body, args) {
|
|
996
|
-
return this._call(new URL("/identity/recover", this.baseUrl), {
|
|
1011
|
+
async recoverIdentity(ctx, body, args) {
|
|
1012
|
+
return this._call(ctx, new URL("/identity/recover", this.baseUrl), {
|
|
997
1013
|
...args,
|
|
998
1014
|
body,
|
|
999
1015
|
method: "POST"
|
|
@@ -1002,8 +1018,8 @@ var EdgeHttpClient = class {
|
|
|
1002
1018
|
//
|
|
1003
1019
|
// Invitations
|
|
1004
1020
|
//
|
|
1005
|
-
async joinSpaceByInvitation(spaceId, body, args) {
|
|
1006
|
-
return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
1021
|
+
async joinSpaceByInvitation(ctx, spaceId, body, args) {
|
|
1022
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
1007
1023
|
...args,
|
|
1008
1024
|
body,
|
|
1009
1025
|
method: "POST"
|
|
@@ -1012,8 +1028,8 @@ var EdgeHttpClient = class {
|
|
|
1012
1028
|
//
|
|
1013
1029
|
// OAuth and credentials
|
|
1014
1030
|
//
|
|
1015
|
-
async initiateOAuthFlow(body, args) {
|
|
1016
|
-
return this._call(new URL("/oauth/initiate", this.baseUrl), {
|
|
1031
|
+
async initiateOAuthFlow(ctx, body, args) {
|
|
1032
|
+
return this._call(ctx, new URL("/oauth/initiate", this.baseUrl), {
|
|
1017
1033
|
...args,
|
|
1018
1034
|
body,
|
|
1019
1035
|
method: "POST"
|
|
@@ -1022,8 +1038,8 @@ var EdgeHttpClient = class {
|
|
|
1022
1038
|
//
|
|
1023
1039
|
// Spaces
|
|
1024
1040
|
//
|
|
1025
|
-
async createSpace(body, args) {
|
|
1026
|
-
return this._call(new URL("/spaces/create", this.baseUrl), {
|
|
1041
|
+
async createSpace(ctx, body, args) {
|
|
1042
|
+
return this._call(ctx, new URL("/spaces/create", this.baseUrl), {
|
|
1027
1043
|
...args,
|
|
1028
1044
|
body,
|
|
1029
1045
|
method: "POST"
|
|
@@ -1032,9 +1048,18 @@ var EdgeHttpClient = class {
|
|
|
1032
1048
|
//
|
|
1033
1049
|
// Queues
|
|
1034
1050
|
//
|
|
1035
|
-
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1051
|
+
async queryQueue(ctx, subspaceTag, spaceId, query, args) {
|
|
1052
|
+
const queueId = query.queueIds?.[0];
|
|
1053
|
+
invariant4(queueId, "queueId required", {
|
|
1054
|
+
F: __dxlog_file6,
|
|
1055
|
+
L: 234,
|
|
1056
|
+
S: this,
|
|
1057
|
+
A: [
|
|
1058
|
+
"queueId",
|
|
1059
|
+
"'queueId required'"
|
|
1060
|
+
]
|
|
1061
|
+
});
|
|
1062
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
1038
1063
|
after: query.after,
|
|
1039
1064
|
before: query.before,
|
|
1040
1065
|
limit: query.limit,
|
|
@@ -1045,8 +1070,8 @@ var EdgeHttpClient = class {
|
|
|
1045
1070
|
method: "GET"
|
|
1046
1071
|
});
|
|
1047
1072
|
}
|
|
1048
|
-
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
1049
|
-
return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1073
|
+
async insertIntoQueue(ctx, subspaceTag, spaceId, queueId, objects, args) {
|
|
1074
|
+
return this._call(ctx, new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1050
1075
|
...args,
|
|
1051
1076
|
body: {
|
|
1052
1077
|
objects
|
|
@@ -1054,8 +1079,8 @@ var EdgeHttpClient = class {
|
|
|
1054
1079
|
method: "POST"
|
|
1055
1080
|
});
|
|
1056
1081
|
}
|
|
1057
|
-
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1058
|
-
return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1082
|
+
async deleteFromQueue(ctx, subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1083
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1059
1084
|
ids: objectIds.join(",")
|
|
1060
1085
|
}), {
|
|
1061
1086
|
...args,
|
|
@@ -1065,7 +1090,7 @@ var EdgeHttpClient = class {
|
|
|
1065
1090
|
//
|
|
1066
1091
|
// Functions
|
|
1067
1092
|
//
|
|
1068
|
-
async uploadFunction(pathParts, body, args) {
|
|
1093
|
+
async uploadFunction(ctx, pathParts, body, args) {
|
|
1069
1094
|
const formData = new FormData();
|
|
1070
1095
|
formData.append("name", body.name ?? "");
|
|
1071
1096
|
formData.append("version", body.version);
|
|
@@ -1085,20 +1110,20 @@ var EdgeHttpClient = class {
|
|
|
1085
1110
|
pathParts.functionId
|
|
1086
1111
|
] : []
|
|
1087
1112
|
].join("/");
|
|
1088
|
-
return this._call(new URL(path, this.baseUrl), {
|
|
1113
|
+
return this._call(ctx, new URL(path, this.baseUrl), {
|
|
1089
1114
|
...args,
|
|
1090
1115
|
body: formData,
|
|
1091
1116
|
method: "PUT",
|
|
1092
1117
|
json: false
|
|
1093
1118
|
});
|
|
1094
1119
|
}
|
|
1095
|
-
async listFunctions(args) {
|
|
1096
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
1120
|
+
async listFunctions(ctx, args) {
|
|
1121
|
+
return this._call(ctx, new URL("/functions", this.baseUrl), {
|
|
1097
1122
|
...args,
|
|
1098
1123
|
method: "GET"
|
|
1099
1124
|
});
|
|
1100
1125
|
}
|
|
1101
|
-
async invokeFunction(params, input, args) {
|
|
1126
|
+
async invokeFunction(ctx, params, input, args) {
|
|
1102
1127
|
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1103
1128
|
if (params.version) {
|
|
1104
1129
|
url.searchParams.set("version", params.version);
|
|
@@ -1112,18 +1137,17 @@ var EdgeHttpClient = class {
|
|
|
1112
1137
|
if (params.subrequestsLimit) {
|
|
1113
1138
|
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1114
1139
|
}
|
|
1115
|
-
return this._call(url, {
|
|
1140
|
+
return this._call(ctx, url, {
|
|
1116
1141
|
...args,
|
|
1117
1142
|
body: input,
|
|
1118
|
-
method: "POST"
|
|
1119
|
-
rawResponse: true
|
|
1143
|
+
method: "POST"
|
|
1120
1144
|
});
|
|
1121
1145
|
}
|
|
1122
1146
|
//
|
|
1123
1147
|
// Workflows
|
|
1124
1148
|
//
|
|
1125
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1126
|
-
return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
1149
|
+
async executeWorkflow(ctx, spaceId, graphId, input, args) {
|
|
1150
|
+
return this._call(ctx, new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
1127
1151
|
...args,
|
|
1128
1152
|
body: input,
|
|
1129
1153
|
method: "POST"
|
|
@@ -1132,23 +1156,41 @@ var EdgeHttpClient = class {
|
|
|
1132
1156
|
//
|
|
1133
1157
|
// Triggers
|
|
1134
1158
|
//
|
|
1135
|
-
async getCronTriggers(spaceId) {
|
|
1136
|
-
return this._call(new URL(`/
|
|
1159
|
+
async getCronTriggers(ctx, spaceId) {
|
|
1160
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
1137
1161
|
method: "GET"
|
|
1138
1162
|
});
|
|
1139
1163
|
}
|
|
1164
|
+
async forceRunCronTrigger(ctx, spaceId, triggerId) {
|
|
1165
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
|
|
1166
|
+
method: "POST"
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
//
|
|
1170
|
+
// Query
|
|
1171
|
+
//
|
|
1172
|
+
/**
|
|
1173
|
+
* Execute a QueryAST query against a space.
|
|
1174
|
+
*/
|
|
1175
|
+
async execQuery(ctx, spaceId, body, args) {
|
|
1176
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), {
|
|
1177
|
+
...args,
|
|
1178
|
+
body,
|
|
1179
|
+
method: "POST"
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1140
1182
|
//
|
|
1141
1183
|
// Import/Export space.
|
|
1142
1184
|
//
|
|
1143
|
-
async importBundle(spaceId, body, args) {
|
|
1144
|
-
return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1185
|
+
async importBundle(ctx, spaceId, body, args) {
|
|
1186
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1145
1187
|
...args,
|
|
1146
1188
|
body,
|
|
1147
1189
|
method: "PUT"
|
|
1148
1190
|
});
|
|
1149
1191
|
}
|
|
1150
|
-
async exportBundle(spaceId, body, args) {
|
|
1151
|
-
return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1192
|
+
async exportBundle(ctx, spaceId, body, args) {
|
|
1193
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1152
1194
|
...args,
|
|
1153
1195
|
body,
|
|
1154
1196
|
method: "POST"
|
|
@@ -1158,24 +1200,21 @@ var EdgeHttpClient = class {
|
|
|
1158
1200
|
// Internal
|
|
1159
1201
|
//
|
|
1160
1202
|
async _fetch(url, _args) {
|
|
1161
|
-
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"),
|
|
1203
|
+
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1162
1204
|
}
|
|
1163
1205
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1164
|
-
async _call(url, args) {
|
|
1206
|
+
async _call(ctx, url, args) {
|
|
1165
1207
|
const shouldRetry = createRetryHandler(args);
|
|
1166
|
-
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1167
|
-
F: __dxlog_file6,
|
|
1168
|
-
L: 400
|
|
1169
|
-
});
|
|
1170
1208
|
log4("fetch", {
|
|
1171
1209
|
url,
|
|
1172
1210
|
request: args.body
|
|
1173
1211
|
}, {
|
|
1174
1212
|
F: __dxlog_file6,
|
|
1175
|
-
L:
|
|
1213
|
+
L: 451,
|
|
1176
1214
|
S: this,
|
|
1177
1215
|
C: (f, a) => f(...a)
|
|
1178
1216
|
});
|
|
1217
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1179
1218
|
let handledAuth = false;
|
|
1180
1219
|
const tryCount = 1;
|
|
1181
1220
|
while (true) {
|
|
@@ -1187,26 +1226,23 @@ var EdgeHttpClient = class {
|
|
|
1187
1226
|
this._authHeader = await this._handleUnauthorized(response2);
|
|
1188
1227
|
}
|
|
1189
1228
|
}
|
|
1190
|
-
const request = createRequest(args, this._authHeader);
|
|
1229
|
+
const request = createRequest(args, this._authHeader, traceHeaders);
|
|
1191
1230
|
log4("call edge", {
|
|
1192
1231
|
url,
|
|
1193
1232
|
tryCount,
|
|
1194
1233
|
authHeader: !!this._authHeader
|
|
1195
1234
|
}, {
|
|
1196
1235
|
F: __dxlog_file6,
|
|
1197
|
-
L:
|
|
1236
|
+
L: 468,
|
|
1198
1237
|
S: this,
|
|
1199
1238
|
C: (f, a) => f(...a)
|
|
1200
1239
|
});
|
|
1201
1240
|
const response = await fetch(url, request);
|
|
1202
1241
|
if (response.ok) {
|
|
1203
1242
|
const body2 = await response.clone().json();
|
|
1204
|
-
if (args.rawResponse) {
|
|
1205
|
-
return body2;
|
|
1206
|
-
}
|
|
1207
1243
|
invariant4(body2, "Expected body to be present", {
|
|
1208
1244
|
F: __dxlog_file6,
|
|
1209
|
-
L:
|
|
1245
|
+
L: 473,
|
|
1210
1246
|
S: this,
|
|
1211
1247
|
A: [
|
|
1212
1248
|
"body",
|
|
@@ -1227,21 +1263,21 @@ var EdgeHttpClient = class {
|
|
|
1227
1263
|
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1228
1264
|
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
|
|
1229
1265
|
F: __dxlog_file6,
|
|
1230
|
-
L:
|
|
1266
|
+
L: 489,
|
|
1231
1267
|
S: this,
|
|
1232
1268
|
A: [
|
|
1233
1269
|
"!body?.success",
|
|
1234
1270
|
"'Expected body to not be a failure response or undefined.'"
|
|
1235
1271
|
]
|
|
1236
1272
|
});
|
|
1237
|
-
if (body?.
|
|
1238
|
-
processingError = new EdgeAuthChallengeError(body.
|
|
1273
|
+
if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
|
|
1274
|
+
processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
|
|
1239
1275
|
} else if (body?.success === false) {
|
|
1240
1276
|
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1241
1277
|
} else {
|
|
1242
1278
|
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1243
1279
|
F: __dxlog_file6,
|
|
1244
|
-
L:
|
|
1280
|
+
L: 496,
|
|
1245
1281
|
S: this,
|
|
1246
1282
|
A: [
|
|
1247
1283
|
"!response.ok",
|
|
@@ -1253,13 +1289,13 @@ var EdgeHttpClient = class {
|
|
|
1253
1289
|
} catch (error) {
|
|
1254
1290
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1255
1291
|
}
|
|
1256
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1292
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1257
1293
|
log4.verbose("retrying edge request", {
|
|
1258
1294
|
url,
|
|
1259
1295
|
processingError
|
|
1260
1296
|
}, {
|
|
1261
1297
|
F: __dxlog_file6,
|
|
1262
|
-
L:
|
|
1298
|
+
L: 504,
|
|
1263
1299
|
S: this,
|
|
1264
1300
|
C: (f, a) => f(...a)
|
|
1265
1301
|
});
|
|
@@ -1272,7 +1308,7 @@ var EdgeHttpClient = class {
|
|
|
1272
1308
|
if (!this._edgeIdentity) {
|
|
1273
1309
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1274
1310
|
F: __dxlog_file6,
|
|
1275
|
-
L:
|
|
1311
|
+
L: 513,
|
|
1276
1312
|
S: this,
|
|
1277
1313
|
C: (f, a) => f(...a)
|
|
1278
1314
|
});
|
|
@@ -1282,7 +1318,7 @@ var EdgeHttpClient = class {
|
|
|
1282
1318
|
return encodeAuthHeader(challenge);
|
|
1283
1319
|
}
|
|
1284
1320
|
};
|
|
1285
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1321
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders) => {
|
|
1286
1322
|
let requestBody;
|
|
1287
1323
|
const headers = {};
|
|
1288
1324
|
if (json) {
|
|
@@ -1296,7 +1332,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1296
1332
|
bodySize: requestBody.length
|
|
1297
1333
|
}, {
|
|
1298
1334
|
F: __dxlog_file6,
|
|
1299
|
-
L:
|
|
1335
|
+
L: 538,
|
|
1300
1336
|
S: void 0,
|
|
1301
1337
|
C: (f, a) => f(...a)
|
|
1302
1338
|
});
|
|
@@ -1304,12 +1340,25 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1304
1340
|
if (authHeader) {
|
|
1305
1341
|
headers["Authorization"] = authHeader;
|
|
1306
1342
|
}
|
|
1343
|
+
if (traceHeaders) {
|
|
1344
|
+
Object.assign(headers, traceHeaders);
|
|
1345
|
+
}
|
|
1307
1346
|
return {
|
|
1308
1347
|
method,
|
|
1309
1348
|
body: requestBody,
|
|
1310
1349
|
headers
|
|
1311
1350
|
};
|
|
1312
1351
|
};
|
|
1352
|
+
var getTraceHeaders = (ctx) => {
|
|
1353
|
+
const spanId = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE2);
|
|
1354
|
+
const otlpContext = typeof spanId === "number" ? TRACE_PROCESSOR2.remoteTracing.getSpanContext(spanId) : void 0;
|
|
1355
|
+
if (!otlpContext) {
|
|
1356
|
+
return void 0;
|
|
1357
|
+
}
|
|
1358
|
+
const headers = {};
|
|
1359
|
+
propagation2.inject(otlpContext, headers);
|
|
1360
|
+
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
1361
|
+
};
|
|
1313
1362
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1314
1363
|
if (!retry2 || retry2.count < 1) {
|
|
1315
1364
|
return async () => false;
|