@dxos/edge-client 0.8.4-main.406dc2a → 0.8.4-main.40e3dcdf1b
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/chunk-IKP53CBQ.mjs → neutral/chunk-VESGVCLQ.mjs} +15 -44
- package/dist/lib/{browser/chunk-IKP53CBQ.mjs.map → neutral/chunk-VESGVCLQ.mjs.map} +2 -2
- package/dist/lib/{browser → neutral}/edge-ws-muxer.mjs +1 -1
- package/dist/lib/{browser → neutral}/index.mjs +172 -141
- 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 +1 -1
- package/dist/lib/{browser → neutral}/testing/index.mjs.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +18 -7
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/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 +26 -24
- package/src/edge-http-client.test.ts +1 -1
- package/src/edge-http-client.ts +79 -36
- package/src/http-client.test.ts +3 -2
- package/src/http-client.ts +5 -1
- 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-DR5YNW5K.mjs +0 -332
- package/dist/lib/node-esm/chunk-DR5YNW5K.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 -1357
- 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}/edge-ws-muxer.mjs.map +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
getTypename,
|
|
7
7
|
protocol,
|
|
8
8
|
toUint8Array
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VESGVCLQ.mjs";
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
12
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
@@ -177,19 +177,6 @@ import { log, logInfo } from "@dxos/log";
|
|
|
177
177
|
import { EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
178
178
|
import { buf } from "@dxos/protocols/buf";
|
|
179
179
|
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
180
|
-
function _define_property(obj, key, value) {
|
|
181
|
-
if (key in obj) {
|
|
182
|
-
Object.defineProperty(obj, key, {
|
|
183
|
-
value,
|
|
184
|
-
enumerable: true,
|
|
185
|
-
configurable: true,
|
|
186
|
-
writable: true
|
|
187
|
-
});
|
|
188
|
-
} else {
|
|
189
|
-
obj[key] = value;
|
|
190
|
-
}
|
|
191
|
-
return obj;
|
|
192
|
-
}
|
|
193
180
|
function _ts_decorate(decorators, target, key, desc) {
|
|
194
181
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
195
182
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -200,6 +187,28 @@ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-c
|
|
|
200
187
|
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
201
188
|
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
202
189
|
var EdgeWsConnection = class extends Resource {
|
|
190
|
+
_identity;
|
|
191
|
+
_connectionInfo;
|
|
192
|
+
_callbacks;
|
|
193
|
+
_inactivityTimeoutCtx;
|
|
194
|
+
_ws;
|
|
195
|
+
_wsMuxer;
|
|
196
|
+
_lastReceivedMessageTimestamp = Date.now();
|
|
197
|
+
_openTimestamp;
|
|
198
|
+
// Latency tracking.
|
|
199
|
+
_pingTimestamp;
|
|
200
|
+
_rtt = 0;
|
|
201
|
+
// Rate tracking with sliding window.
|
|
202
|
+
_uploadRate = 0;
|
|
203
|
+
_downloadRate = 0;
|
|
204
|
+
_rateWindow = 1e4;
|
|
205
|
+
_rateUpdateInterval = 1e3;
|
|
206
|
+
_bytesSamples = [];
|
|
207
|
+
_messagesSent = 0;
|
|
208
|
+
_messagesReceived = 0;
|
|
209
|
+
constructor(_identity, _connectionInfo, _callbacks) {
|
|
210
|
+
super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks;
|
|
211
|
+
}
|
|
203
212
|
get info() {
|
|
204
213
|
return {
|
|
205
214
|
open: this.isOpen,
|
|
@@ -505,21 +514,6 @@ var EdgeWsConnection = class extends Resource {
|
|
|
505
514
|
this._uploadRate = timeSpan > 0 ? Math.round(totalSent / timeSpan) : 0;
|
|
506
515
|
this._downloadRate = timeSpan > 0 ? Math.round(totalReceived / timeSpan) : 0;
|
|
507
516
|
}
|
|
508
|
-
constructor(_identity, _connectionInfo, _callbacks) {
|
|
509
|
-
super(), _define_property(this, "_identity", void 0), _define_property(this, "_connectionInfo", void 0), _define_property(this, "_callbacks", void 0), _define_property(this, "_inactivityTimeoutCtx", void 0), _define_property(this, "_ws", void 0), _define_property(this, "_wsMuxer", void 0), _define_property(this, "_lastReceivedMessageTimestamp", void 0), _define_property(this, "_openTimestamp", void 0), // Latency tracking.
|
|
510
|
-
_define_property(this, "_pingTimestamp", void 0), _define_property(this, "_rtt", void 0), // Rate tracking with sliding window.
|
|
511
|
-
_define_property(this, "_uploadRate", void 0), _define_property(this, "_downloadRate", void 0), _define_property(
|
|
512
|
-
this,
|
|
513
|
-
"_rateWindow",
|
|
514
|
-
void 0
|
|
515
|
-
// 10 second sliding window.
|
|
516
|
-
), _define_property(
|
|
517
|
-
this,
|
|
518
|
-
"_rateUpdateInterval",
|
|
519
|
-
void 0
|
|
520
|
-
// Update rates every second.
|
|
521
|
-
), _define_property(this, "_bytesSamples", void 0), _define_property(this, "_messagesSent", void 0), _define_property(this, "_messagesReceived", void 0), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now(), this._rtt = 0, this._uploadRate = 0, this._downloadRate = 0, this._rateWindow = 1e4, this._rateUpdateInterval = 1e3, this._bytesSamples = [], this._messagesSent = 0, this._messagesReceived = 0;
|
|
522
|
-
}
|
|
523
517
|
};
|
|
524
518
|
_ts_decorate([
|
|
525
519
|
logInfo
|
|
@@ -546,19 +540,6 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
546
540
|
};
|
|
547
541
|
|
|
548
542
|
// src/edge-client.ts
|
|
549
|
-
function _define_property2(obj, key, value) {
|
|
550
|
-
if (key in obj) {
|
|
551
|
-
Object.defineProperty(obj, key, {
|
|
552
|
-
value,
|
|
553
|
-
enumerable: true,
|
|
554
|
-
configurable: true,
|
|
555
|
-
writable: true
|
|
556
|
-
});
|
|
557
|
-
} else {
|
|
558
|
-
obj[key] = value;
|
|
559
|
-
}
|
|
560
|
-
return obj;
|
|
561
|
-
}
|
|
562
543
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
563
544
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
564
545
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -569,6 +550,24 @@ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-clie
|
|
|
569
550
|
var DEFAULT_TIMEOUT = 1e4;
|
|
570
551
|
var STATUS_REFRESH_INTERVAL = 1e3;
|
|
571
552
|
var EdgeClient = class extends Resource2 {
|
|
553
|
+
_identity;
|
|
554
|
+
_config;
|
|
555
|
+
statusChanged = new Event();
|
|
556
|
+
_persistentLifecycle = new PersistentLifecycle({
|
|
557
|
+
start: async () => this._connect(),
|
|
558
|
+
stop: async (state) => this._disconnect(state)
|
|
559
|
+
});
|
|
560
|
+
_messageListeners = /* @__PURE__ */ new Set();
|
|
561
|
+
_reconnectListeners = /* @__PURE__ */ new Set();
|
|
562
|
+
_baseWsUrl;
|
|
563
|
+
_baseHttpUrl;
|
|
564
|
+
_currentConnection = void 0;
|
|
565
|
+
_ready = new Trigger();
|
|
566
|
+
constructor(_identity, _config) {
|
|
567
|
+
super(), this._identity = _identity, this._config = _config;
|
|
568
|
+
this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "ws");
|
|
569
|
+
this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "http");
|
|
570
|
+
}
|
|
572
571
|
get info() {
|
|
573
572
|
return {
|
|
574
573
|
open: this.isOpen,
|
|
@@ -851,14 +850,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
851
850
|
return void 0;
|
|
852
851
|
}
|
|
853
852
|
}
|
|
854
|
-
|
|
855
|
-
super(), _define_property2(this, "_identity", void 0), _define_property2(this, "_config", void 0), _define_property2(this, "statusChanged", void 0), _define_property2(this, "_persistentLifecycle", void 0), _define_property2(this, "_messageListeners", void 0), _define_property2(this, "_reconnectListeners", void 0), _define_property2(this, "_baseWsUrl", void 0), _define_property2(this, "_baseHttpUrl", void 0), _define_property2(this, "_currentConnection", void 0), _define_property2(this, "_ready", void 0), _define_property2(this, "_isActive", void 0), this._identity = _identity, this._config = _config, this.statusChanged = new Event(), this._persistentLifecycle = new PersistentLifecycle({
|
|
856
|
-
start: async () => this._connect(),
|
|
857
|
-
stop: async (state) => this._disconnect(state)
|
|
858
|
-
}), this._messageListeners = /* @__PURE__ */ new Set(), this._reconnectListeners = /* @__PURE__ */ new Set(), this._currentConnection = void 0, this._ready = new Trigger(), this._isActive = (connection) => connection === this._currentConnection;
|
|
859
|
-
this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "ws");
|
|
860
|
-
this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "http");
|
|
861
|
-
}
|
|
853
|
+
_isActive = (connection) => connection === this._currentConnection;
|
|
862
854
|
};
|
|
863
855
|
_ts_decorate2([
|
|
864
856
|
logInfo2
|
|
@@ -875,6 +867,8 @@ import * as Effect2 from "effect/Effect";
|
|
|
875
867
|
import * as Function from "effect/Function";
|
|
876
868
|
import { sleep } from "@dxos/async";
|
|
877
869
|
import { Context as Context3 } from "@dxos/context";
|
|
870
|
+
import { runAndForwardErrors } from "@dxos/effect";
|
|
871
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
878
872
|
import { log as log4 } from "@dxos/log";
|
|
879
873
|
import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
880
874
|
import { createUrl } from "@dxos/util";
|
|
@@ -886,28 +880,14 @@ import * as Effect from "effect/Effect";
|
|
|
886
880
|
import * as Layer from "effect/Layer";
|
|
887
881
|
import * as Schedule from "effect/Schedule";
|
|
888
882
|
import { log as log3 } from "@dxos/log";
|
|
889
|
-
function _define_property3(obj, key, value) {
|
|
890
|
-
if (key in obj) {
|
|
891
|
-
Object.defineProperty(obj, key, {
|
|
892
|
-
value,
|
|
893
|
-
enumerable: true,
|
|
894
|
-
configurable: true,
|
|
895
|
-
writable: true
|
|
896
|
-
});
|
|
897
|
-
} else {
|
|
898
|
-
obj[key] = value;
|
|
899
|
-
}
|
|
900
|
-
return obj;
|
|
901
|
-
}
|
|
902
883
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
|
|
903
|
-
var
|
|
904
|
-
|
|
884
|
+
var HttpConfig = class _HttpConfig extends Context2.Tag("HttpConfig")() {
|
|
885
|
+
static default = Layer.succeed(_HttpConfig, {
|
|
886
|
+
timeout: Duration.millis(1e3),
|
|
887
|
+
retryTimes: 3,
|
|
888
|
+
retryBaseDelay: Duration.millis(1e3)
|
|
889
|
+
});
|
|
905
890
|
};
|
|
906
|
-
_define_property3(HttpConfig, "default", Layer.succeed(HttpConfig, {
|
|
907
|
-
timeout: Duration.millis(1e3),
|
|
908
|
-
retryTimes: 3,
|
|
909
|
-
retryBaseDelay: Duration.millis(1e3)
|
|
910
|
-
}));
|
|
911
891
|
var withRetry = (effect, { timeout: timeout2 = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
|
|
912
892
|
return effect.pipe(Effect.flatMap((res) => (
|
|
913
893
|
// Treat 500 errors as retryable?
|
|
@@ -921,39 +901,45 @@ var withRetryConfig = (effect) => Effect.gen(function* () {
|
|
|
921
901
|
const config = yield* HttpConfig;
|
|
922
902
|
return yield* withRetry(effect, config);
|
|
923
903
|
});
|
|
924
|
-
var withLogging = (effect) => effect.pipe(Effect.tap((res) =>
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
904
|
+
var withLogging = (effect) => effect.pipe(Effect.tap((res) => {
|
|
905
|
+
log3.info("response", {
|
|
906
|
+
status: res.status
|
|
907
|
+
}, {
|
|
908
|
+
F: __dxlog_file5,
|
|
909
|
+
L: 66,
|
|
910
|
+
S: void 0,
|
|
911
|
+
C: (f, a) => f(...a)
|
|
912
|
+
});
|
|
913
|
+
}));
|
|
932
914
|
var encodeAuthHeader = (challenge) => {
|
|
933
915
|
const encodedChallenge = Buffer.from(challenge).toString("base64");
|
|
934
916
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
935
917
|
};
|
|
936
918
|
|
|
937
919
|
// src/edge-http-client.ts
|
|
938
|
-
function _define_property4(obj, key, value) {
|
|
939
|
-
if (key in obj) {
|
|
940
|
-
Object.defineProperty(obj, key, {
|
|
941
|
-
value,
|
|
942
|
-
enumerable: true,
|
|
943
|
-
configurable: true,
|
|
944
|
-
writable: true
|
|
945
|
-
});
|
|
946
|
-
} else {
|
|
947
|
-
obj[key] = value;
|
|
948
|
-
}
|
|
949
|
-
return obj;
|
|
950
|
-
}
|
|
951
920
|
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
952
921
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
953
922
|
var DEFAULT_RETRY_JITTER = 500;
|
|
954
923
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
955
924
|
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
956
925
|
var EdgeHttpClient = class {
|
|
926
|
+
_baseUrl;
|
|
927
|
+
_edgeIdentity;
|
|
928
|
+
/**
|
|
929
|
+
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
930
|
+
*/
|
|
931
|
+
_authHeader;
|
|
932
|
+
constructor(baseUrl) {
|
|
933
|
+
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
934
|
+
log4("created", {
|
|
935
|
+
url: this._baseUrl
|
|
936
|
+
}, {
|
|
937
|
+
F: __dxlog_file6,
|
|
938
|
+
L: 110,
|
|
939
|
+
S: this,
|
|
940
|
+
C: (f, a) => f(...a)
|
|
941
|
+
});
|
|
942
|
+
}
|
|
957
943
|
get baseUrl() {
|
|
958
944
|
return this._baseUrl;
|
|
959
945
|
}
|
|
@@ -969,7 +955,8 @@ var EdgeHttpClient = class {
|
|
|
969
955
|
async getStatus(args) {
|
|
970
956
|
return this._call(new URL("/status", this.baseUrl), {
|
|
971
957
|
...args,
|
|
972
|
-
method: "GET"
|
|
958
|
+
method: "GET",
|
|
959
|
+
auth: true
|
|
973
960
|
});
|
|
974
961
|
}
|
|
975
962
|
//
|
|
@@ -1048,7 +1035,16 @@ var EdgeHttpClient = class {
|
|
|
1048
1035
|
// Queues
|
|
1049
1036
|
//
|
|
1050
1037
|
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
1051
|
-
const
|
|
1038
|
+
const queueId = query.queueIds?.[0];
|
|
1039
|
+
invariant4(queueId, "queueId required", {
|
|
1040
|
+
F: __dxlog_file6,
|
|
1041
|
+
L: 219,
|
|
1042
|
+
S: this,
|
|
1043
|
+
A: [
|
|
1044
|
+
"queueId",
|
|
1045
|
+
"'queueId required'"
|
|
1046
|
+
]
|
|
1047
|
+
});
|
|
1052
1048
|
return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
1053
1049
|
after: query.after,
|
|
1054
1050
|
before: query.before,
|
|
@@ -1086,6 +1082,7 @@ var EdgeHttpClient = class {
|
|
|
1086
1082
|
formData.append("version", body.version);
|
|
1087
1083
|
formData.append("ownerPublicKey", body.ownerPublicKey);
|
|
1088
1084
|
formData.append("entryPoint", body.entryPoint);
|
|
1085
|
+
body.runtime && formData.append("runtime", body.runtime);
|
|
1089
1086
|
for (const [filename, content] of Object.entries(body.assets)) {
|
|
1090
1087
|
formData.append("assets", new Blob([
|
|
1091
1088
|
content
|
|
@@ -1129,8 +1126,7 @@ var EdgeHttpClient = class {
|
|
|
1129
1126
|
return this._call(url, {
|
|
1130
1127
|
...args,
|
|
1131
1128
|
body: input,
|
|
1132
|
-
method: "POST"
|
|
1133
|
-
rawResponse: true
|
|
1129
|
+
method: "POST"
|
|
1134
1130
|
});
|
|
1135
1131
|
}
|
|
1136
1132
|
//
|
|
@@ -1151,6 +1147,24 @@ var EdgeHttpClient = class {
|
|
|
1151
1147
|
method: "GET"
|
|
1152
1148
|
});
|
|
1153
1149
|
}
|
|
1150
|
+
async forceRunCronTrigger(spaceId, triggerId) {
|
|
1151
|
+
return this._call(new URL(`/test/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
|
|
1152
|
+
method: "POST"
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
//
|
|
1156
|
+
// Query
|
|
1157
|
+
//
|
|
1158
|
+
/**
|
|
1159
|
+
* Execute a QueryAST query against a space.
|
|
1160
|
+
*/
|
|
1161
|
+
async execQuery(spaceId, body, args) {
|
|
1162
|
+
return this._call(new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), {
|
|
1163
|
+
...args,
|
|
1164
|
+
body,
|
|
1165
|
+
method: "POST"
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1154
1168
|
//
|
|
1155
1169
|
// Import/Export space.
|
|
1156
1170
|
//
|
|
@@ -1171,75 +1185,106 @@ var EdgeHttpClient = class {
|
|
|
1171
1185
|
//
|
|
1172
1186
|
// Internal
|
|
1173
1187
|
//
|
|
1174
|
-
async _fetch(url,
|
|
1175
|
-
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"),
|
|
1188
|
+
async _fetch(url, _args) {
|
|
1189
|
+
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1176
1190
|
}
|
|
1177
1191
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1178
1192
|
async _call(url, args) {
|
|
1179
1193
|
const shouldRetry = createRetryHandler(args);
|
|
1180
|
-
const requestContext = args.context ??
|
|
1194
|
+
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1181
1195
|
F: __dxlog_file6,
|
|
1182
|
-
L:
|
|
1196
|
+
L: 426
|
|
1183
1197
|
});
|
|
1184
1198
|
log4("fetch", {
|
|
1185
1199
|
url,
|
|
1186
1200
|
request: args.body
|
|
1187
1201
|
}, {
|
|
1188
1202
|
F: __dxlog_file6,
|
|
1189
|
-
L:
|
|
1203
|
+
L: 427,
|
|
1190
1204
|
S: this,
|
|
1191
1205
|
C: (f, a) => f(...a)
|
|
1192
1206
|
});
|
|
1193
1207
|
let handledAuth = false;
|
|
1208
|
+
const tryCount = 1;
|
|
1194
1209
|
while (true) {
|
|
1195
1210
|
let processingError = void 0;
|
|
1196
|
-
let retryAfterHeaderValue = Number.NaN;
|
|
1197
1211
|
try {
|
|
1212
|
+
if (!this._authHeader && args.auth) {
|
|
1213
|
+
const response2 = await fetch(new URL(`/auth`, this.baseUrl));
|
|
1214
|
+
if (response2.status === 401) {
|
|
1215
|
+
this._authHeader = await this._handleUnauthorized(response2);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1198
1218
|
const request = createRequest(args, this._authHeader);
|
|
1219
|
+
log4("call edge", {
|
|
1220
|
+
url,
|
|
1221
|
+
tryCount,
|
|
1222
|
+
authHeader: !!this._authHeader
|
|
1223
|
+
}, {
|
|
1224
|
+
F: __dxlog_file6,
|
|
1225
|
+
L: 442,
|
|
1226
|
+
S: this,
|
|
1227
|
+
C: (f, a) => f(...a)
|
|
1228
|
+
});
|
|
1199
1229
|
const response = await fetch(url, request);
|
|
1200
|
-
retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
|
|
1201
1230
|
if (response.ok) {
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1204
|
-
return body;
|
|
1205
|
-
}
|
|
1206
|
-
if (!("success" in body)) {
|
|
1207
|
-
return body;
|
|
1208
|
-
}
|
|
1209
|
-
if (body.success) {
|
|
1210
|
-
return body.data;
|
|
1211
|
-
}
|
|
1212
|
-
log4.warn("unsuccessful edge response", {
|
|
1213
|
-
url,
|
|
1214
|
-
body
|
|
1215
|
-
}, {
|
|
1231
|
+
const body2 = await response.clone().json();
|
|
1232
|
+
invariant4(body2, "Expected body to be present", {
|
|
1216
1233
|
F: __dxlog_file6,
|
|
1217
|
-
L:
|
|
1234
|
+
L: 447,
|
|
1218
1235
|
S: this,
|
|
1219
|
-
|
|
1236
|
+
A: [
|
|
1237
|
+
"body",
|
|
1238
|
+
"'Expected body to be present'"
|
|
1239
|
+
]
|
|
1220
1240
|
});
|
|
1221
|
-
if (
|
|
1222
|
-
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1241
|
+
if (!("success" in body2)) {
|
|
1242
|
+
return body2;
|
|
1243
|
+
}
|
|
1244
|
+
if (body2.success) {
|
|
1245
|
+
return body2.data;
|
|
1225
1246
|
}
|
|
1226
1247
|
} else if (response.status === 401 && !handledAuth) {
|
|
1227
1248
|
this._authHeader = await this._handleUnauthorized(response);
|
|
1228
1249
|
handledAuth = true;
|
|
1229
1250
|
continue;
|
|
1251
|
+
}
|
|
1252
|
+
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1253
|
+
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
|
|
1254
|
+
F: __dxlog_file6,
|
|
1255
|
+
L: 463,
|
|
1256
|
+
S: this,
|
|
1257
|
+
A: [
|
|
1258
|
+
"!body?.success",
|
|
1259
|
+
"'Expected body to not be a failure response or undefined.'"
|
|
1260
|
+
]
|
|
1261
|
+
});
|
|
1262
|
+
if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
|
|
1263
|
+
processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
|
|
1264
|
+
} else if (body?.success === false) {
|
|
1265
|
+
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1230
1266
|
} else {
|
|
1267
|
+
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1268
|
+
F: __dxlog_file6,
|
|
1269
|
+
L: 470,
|
|
1270
|
+
S: this,
|
|
1271
|
+
A: [
|
|
1272
|
+
"!response.ok",
|
|
1273
|
+
"'Expected response to not be ok.'"
|
|
1274
|
+
]
|
|
1275
|
+
});
|
|
1231
1276
|
processingError = await EdgeCallFailedError.fromHttpFailure(response);
|
|
1232
1277
|
}
|
|
1233
1278
|
} catch (error) {
|
|
1234
1279
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1235
1280
|
}
|
|
1236
|
-
if (processingError?.isRetryable && await shouldRetry(requestContext,
|
|
1237
|
-
log4("retrying edge request", {
|
|
1281
|
+
if (processingError?.isRetryable && await shouldRetry(requestContext, processingError.retryAfterMs)) {
|
|
1282
|
+
log4.verbose("retrying edge request", {
|
|
1238
1283
|
url,
|
|
1239
1284
|
processingError
|
|
1240
1285
|
}, {
|
|
1241
1286
|
F: __dxlog_file6,
|
|
1242
|
-
L:
|
|
1287
|
+
L: 478,
|
|
1243
1288
|
S: this,
|
|
1244
1289
|
C: (f, a) => f(...a)
|
|
1245
1290
|
});
|
|
@@ -1252,7 +1297,7 @@ var EdgeHttpClient = class {
|
|
|
1252
1297
|
if (!this._edgeIdentity) {
|
|
1253
1298
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1254
1299
|
F: __dxlog_file6,
|
|
1255
|
-
L:
|
|
1300
|
+
L: 487,
|
|
1256
1301
|
S: this,
|
|
1257
1302
|
C: (f, a) => f(...a)
|
|
1258
1303
|
});
|
|
@@ -1261,20 +1306,6 @@ var EdgeHttpClient = class {
|
|
|
1261
1306
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
1262
1307
|
return encodeAuthHeader(challenge);
|
|
1263
1308
|
}
|
|
1264
|
-
constructor(baseUrl) {
|
|
1265
|
-
_define_property4(this, "_baseUrl", void 0);
|
|
1266
|
-
_define_property4(this, "_edgeIdentity", void 0);
|
|
1267
|
-
_define_property4(this, "_authHeader", void 0);
|
|
1268
|
-
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
1269
|
-
log4("created", {
|
|
1270
|
-
url: this._baseUrl
|
|
1271
|
-
}, {
|
|
1272
|
-
F: __dxlog_file6,
|
|
1273
|
-
L: 99,
|
|
1274
|
-
S: this,
|
|
1275
|
-
C: (f, a) => f(...a)
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
1309
|
};
|
|
1279
1310
|
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1280
1311
|
let requestBody;
|
|
@@ -1290,7 +1321,7 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1290
1321
|
bodySize: requestBody.length
|
|
1291
1322
|
}, {
|
|
1292
1323
|
F: __dxlog_file6,
|
|
1293
|
-
L:
|
|
1324
|
+
L: 511,
|
|
1294
1325
|
S: void 0,
|
|
1295
1326
|
C: (f, a) => f(...a)
|
|
1296
1327
|
});
|