@dxos/edge-client 0.8.4-main.ead640a → 0.8.4-main.f466a3d56e
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/LICENSE +102 -5
- package/dist/lib/{browser/chunk-IKP53CBQ.mjs → neutral/chunk-ZIQ5T3A7.mjs} +20 -83
- package/dist/lib/{browser/chunk-IKP53CBQ.mjs.map → neutral/chunk-ZIQ5T3A7.mjs.map} +2 -2
- package/dist/lib/{browser → neutral}/edge-ws-muxer.mjs +1 -1
- package/dist/lib/{browser → neutral}/index.mjs +318 -436
- 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 +6 -31
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/auth.d.ts.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 +103 -30
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-identity.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/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/http-client.d.ts +2 -2
- package/dist/types/src/http-client.d.ts.map +1 -1
- package/dist/types/src/protocol.d.ts +1 -1
- package/dist/types/src/protocol.d.ts.map +1 -1
- package/dist/types/src/testing/test-server.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/src/utils.d.ts +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -32
- package/src/edge-client.test.ts +16 -11
- package/src/edge-client.ts +19 -3
- package/src/edge-http-client.test.ts +3 -2
- package/src/edge-http-client.ts +328 -75
- package/src/edge-ws-connection.ts +2 -1
- 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/browser/testing/index.mjs.map +0 -7
- 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-ZIQ5T3A7.mjs";
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
12
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
@@ -60,15 +60,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
60
60
|
identityKey: identityKey.toHex(),
|
|
61
61
|
peerKey: peerKey.toHex(),
|
|
62
62
|
presentCredentials: async ({ challenge }) => {
|
|
63
|
-
invariant(chain, void 0, {
|
|
64
|
-
F: __dxlog_file,
|
|
65
|
-
L: 75,
|
|
66
|
-
S: void 0,
|
|
67
|
-
A: [
|
|
68
|
-
"chain",
|
|
69
|
-
""
|
|
70
|
-
]
|
|
71
|
-
});
|
|
63
|
+
invariant(chain, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 56, S: void 0, A: ["chain", ""] });
|
|
72
64
|
return signPresentation({
|
|
73
65
|
presentation: {
|
|
74
66
|
credentials: credentialsToSign
|
|
@@ -124,6 +116,7 @@ var createStubEdgeIdentity = () => {
|
|
|
124
116
|
|
|
125
117
|
// src/edge-client.ts
|
|
126
118
|
import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask, scheduleTaskInterval as scheduleTaskInterval2 } from "@dxos/async";
|
|
119
|
+
import { TRACE_SPAN_ATTRIBUTE } from "@dxos/context";
|
|
127
120
|
import { Resource as Resource2 } from "@dxos/context";
|
|
128
121
|
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
129
122
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -133,35 +126,11 @@ import { invariant as invariant2 } from "@dxos/invariant";
|
|
|
133
126
|
import { schema } from "@dxos/protocols/proto";
|
|
134
127
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
|
|
135
128
|
var handleAuthChallenge = async (failedResponse, identity) => {
|
|
136
|
-
invariant2(failedResponse.status === 401, void 0, {
|
|
137
|
-
F: __dxlog_file2,
|
|
138
|
-
L: 21,
|
|
139
|
-
S: void 0,
|
|
140
|
-
A: [
|
|
141
|
-
"failedResponse.status === 401",
|
|
142
|
-
""
|
|
143
|
-
]
|
|
144
|
-
});
|
|
129
|
+
invariant2(failedResponse.status === 401, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 7, S: void 0, A: ["failedResponse.status === 401", ""] });
|
|
145
130
|
const headerValue = failedResponse.headers.get("Www-Authenticate");
|
|
146
|
-
invariant2(headerValue?.startsWith("VerifiablePresentation challenge="), void 0, {
|
|
147
|
-
F: __dxlog_file2,
|
|
148
|
-
L: 24,
|
|
149
|
-
S: void 0,
|
|
150
|
-
A: [
|
|
151
|
-
"headerValue?.startsWith('VerifiablePresentation challenge=')",
|
|
152
|
-
""
|
|
153
|
-
]
|
|
154
|
-
});
|
|
131
|
+
invariant2(headerValue?.startsWith("VerifiablePresentation challenge="), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 9, S: void 0, A: ["headerValue?.startsWith('VerifiablePresentation challenge=')", ""] });
|
|
155
132
|
const challenge = headerValue?.slice("VerifiablePresentation challenge=".length);
|
|
156
|
-
invariant2(challenge, void 0, {
|
|
157
|
-
F: __dxlog_file2,
|
|
158
|
-
L: 27,
|
|
159
|
-
S: void 0,
|
|
160
|
-
A: [
|
|
161
|
-
"challenge",
|
|
162
|
-
""
|
|
163
|
-
]
|
|
164
|
-
});
|
|
133
|
+
invariant2(challenge, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 11, S: void 0, A: ["challenge", ""] });
|
|
165
134
|
const presentation = await identity.presentCredentials({
|
|
166
135
|
challenge: Buffer.from(challenge, "base64")
|
|
167
136
|
});
|
|
@@ -177,29 +146,38 @@ import { log, logInfo } from "@dxos/log";
|
|
|
177
146
|
import { EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
178
147
|
import { buf } from "@dxos/protocols/buf";
|
|
179
148
|
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
180
|
-
|
|
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
|
-
}
|
|
149
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
193
150
|
function _ts_decorate(decorators, target, key, desc) {
|
|
194
151
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
195
152
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
196
153
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
197
154
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
198
155
|
}
|
|
199
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
200
156
|
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
201
157
|
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
202
158
|
var EdgeWsConnection = class extends Resource {
|
|
159
|
+
_identity;
|
|
160
|
+
_connectionInfo;
|
|
161
|
+
_callbacks;
|
|
162
|
+
_inactivityTimeoutCtx;
|
|
163
|
+
_ws;
|
|
164
|
+
_wsMuxer;
|
|
165
|
+
_lastReceivedMessageTimestamp = Date.now();
|
|
166
|
+
_openTimestamp;
|
|
167
|
+
// Latency tracking.
|
|
168
|
+
_pingTimestamp;
|
|
169
|
+
_rtt = 0;
|
|
170
|
+
// Rate tracking with sliding window.
|
|
171
|
+
_uploadRate = 0;
|
|
172
|
+
_downloadRate = 0;
|
|
173
|
+
_rateWindow = 1e4;
|
|
174
|
+
_rateUpdateInterval = 1e3;
|
|
175
|
+
_bytesSamples = [];
|
|
176
|
+
_messagesSent = 0;
|
|
177
|
+
_messagesReceived = 0;
|
|
178
|
+
constructor(_identity, _connectionInfo, _callbacks) {
|
|
179
|
+
super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks;
|
|
180
|
+
}
|
|
203
181
|
get info() {
|
|
204
182
|
return {
|
|
205
183
|
open: this.isOpen,
|
|
@@ -226,33 +204,12 @@ var EdgeWsConnection = class extends Resource {
|
|
|
226
204
|
return this._messagesReceived;
|
|
227
205
|
}
|
|
228
206
|
send(message) {
|
|
229
|
-
invariant3(this._ws, void 0, {
|
|
230
|
-
|
|
231
|
-
L: 93,
|
|
232
|
-
S: this,
|
|
233
|
-
A: [
|
|
234
|
-
"this._ws",
|
|
235
|
-
""
|
|
236
|
-
]
|
|
237
|
-
});
|
|
238
|
-
invariant3(this._wsMuxer, void 0, {
|
|
239
|
-
F: __dxlog_file3,
|
|
240
|
-
L: 94,
|
|
241
|
-
S: this,
|
|
242
|
-
A: [
|
|
243
|
-
"this._wsMuxer",
|
|
244
|
-
""
|
|
245
|
-
]
|
|
246
|
-
});
|
|
207
|
+
invariant3(this._ws, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 72, S: this, A: ["this._ws", ""] });
|
|
208
|
+
invariant3(this._wsMuxer, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 73, S: this, A: ["this._wsMuxer", ""] });
|
|
247
209
|
log("sending...", {
|
|
248
210
|
peerKey: this._identity.peerKey,
|
|
249
211
|
payload: protocol.getPayloadType(message)
|
|
250
|
-
}, {
|
|
251
|
-
F: __dxlog_file3,
|
|
252
|
-
L: 95,
|
|
253
|
-
S: this,
|
|
254
|
-
C: (f, a) => f(...a)
|
|
255
|
-
});
|
|
212
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 74, S: this });
|
|
256
213
|
this._messagesSent++;
|
|
257
214
|
if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {
|
|
258
215
|
const binary = buf.toBinary(MessageSchema, message);
|
|
@@ -261,12 +218,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
261
218
|
byteLength: binary.byteLength,
|
|
262
219
|
serviceId: message.serviceId,
|
|
263
220
|
payload: protocol.getPayloadType(message)
|
|
264
|
-
}, {
|
|
265
|
-
F: __dxlog_file3,
|
|
266
|
-
L: 100,
|
|
267
|
-
S: this,
|
|
268
|
-
C: (f, a) => f(...a)
|
|
269
|
-
});
|
|
221
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 82, S: this });
|
|
270
222
|
return;
|
|
271
223
|
}
|
|
272
224
|
this._recordBytes(binary.byteLength, 0);
|
|
@@ -274,12 +226,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
274
226
|
} else {
|
|
275
227
|
const binary = buf.toBinary(MessageSchema, message);
|
|
276
228
|
this._recordBytes(binary.byteLength, 0);
|
|
277
|
-
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
278
|
-
F: __dxlog_file3,
|
|
279
|
-
L: 113,
|
|
280
|
-
S: this,
|
|
281
|
-
C: (f, a) => f(...a)
|
|
282
|
-
}));
|
|
229
|
+
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 95, S: this }));
|
|
283
230
|
}
|
|
284
231
|
}
|
|
285
232
|
async _open() {
|
|
@@ -291,17 +238,14 @@ var EdgeWsConnection = class extends Resource {
|
|
|
291
238
|
this._connectionInfo.protocolHeader
|
|
292
239
|
] : [
|
|
293
240
|
...baseProtocols
|
|
294
|
-
]
|
|
241
|
+
], this._connectionInfo.headers ? {
|
|
242
|
+
headers: this._connectionInfo.headers
|
|
243
|
+
} : void 0);
|
|
295
244
|
const muxer = new WebSocketMuxer(this._ws);
|
|
296
245
|
this._wsMuxer = muxer;
|
|
297
246
|
this._ws.onopen = () => {
|
|
298
247
|
if (this.isOpen) {
|
|
299
|
-
log("connected", void 0, {
|
|
300
|
-
F: __dxlog_file3,
|
|
301
|
-
L: 130,
|
|
302
|
-
S: this,
|
|
303
|
-
C: (f, a) => f(...a)
|
|
304
|
-
});
|
|
248
|
+
log("connected", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 114, S: this });
|
|
305
249
|
this._openTimestamp = Date.now();
|
|
306
250
|
this._callbacks.onConnected();
|
|
307
251
|
this._scheduleHeartbeats();
|
|
@@ -309,12 +253,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
309
253
|
} else {
|
|
310
254
|
log.verbose("connected after becoming inactive", {
|
|
311
255
|
currentIdentity: this._identity
|
|
312
|
-
}, {
|
|
313
|
-
F: __dxlog_file3,
|
|
314
|
-
L: 136,
|
|
315
|
-
S: this,
|
|
316
|
-
C: (f, a) => f(...a)
|
|
317
|
-
});
|
|
256
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 120, S: this });
|
|
318
257
|
}
|
|
319
258
|
};
|
|
320
259
|
this._ws.onclose = (event) => {
|
|
@@ -322,12 +261,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
322
261
|
log.warn("server disconnected", {
|
|
323
262
|
code: event.code,
|
|
324
263
|
reason: event.reason
|
|
325
|
-
}, {
|
|
326
|
-
F: __dxlog_file3,
|
|
327
|
-
L: 141,
|
|
328
|
-
S: this,
|
|
329
|
-
C: (f, a) => f(...a)
|
|
330
|
-
});
|
|
264
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 127, S: this });
|
|
331
265
|
this._callbacks.onRestartRequired();
|
|
332
266
|
muxer.destroy();
|
|
333
267
|
}
|
|
@@ -337,34 +271,19 @@ var EdgeWsConnection = class extends Resource {
|
|
|
337
271
|
log.warn("edge connection socket error", {
|
|
338
272
|
error: event.error,
|
|
339
273
|
info: event.message
|
|
340
|
-
}, {
|
|
341
|
-
F: __dxlog_file3,
|
|
342
|
-
L: 148,
|
|
343
|
-
S: this,
|
|
344
|
-
C: (f, a) => f(...a)
|
|
345
|
-
});
|
|
274
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 137, S: this });
|
|
346
275
|
this._callbacks.onRestartRequired();
|
|
347
276
|
} else {
|
|
348
277
|
log.verbose("error ignored on closed connection", {
|
|
349
278
|
error: event.error
|
|
350
|
-
}, {
|
|
351
|
-
F: __dxlog_file3,
|
|
352
|
-
L: 151,
|
|
353
|
-
S: this,
|
|
354
|
-
C: (f, a) => f(...a)
|
|
355
|
-
});
|
|
279
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 143, S: this });
|
|
356
280
|
}
|
|
357
281
|
};
|
|
358
282
|
this._ws.onmessage = async (event) => {
|
|
359
283
|
if (!this.isOpen) {
|
|
360
284
|
log.verbose("message ignored on closed connection", {
|
|
361
285
|
event: event.type
|
|
362
|
-
}, {
|
|
363
|
-
F: __dxlog_file3,
|
|
364
|
-
L: 159,
|
|
365
|
-
S: this,
|
|
366
|
-
C: (f, a) => f(...a)
|
|
367
|
-
});
|
|
286
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 152, S: this });
|
|
368
287
|
return;
|
|
369
288
|
}
|
|
370
289
|
this._lastReceivedMessageTimestamp = Date.now();
|
|
@@ -387,12 +306,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
387
306
|
log("received", {
|
|
388
307
|
from: message.source,
|
|
389
308
|
payload: protocol.getPayloadType(message)
|
|
390
|
-
}, {
|
|
391
|
-
F: __dxlog_file3,
|
|
392
|
-
L: 185,
|
|
393
|
-
S: this,
|
|
394
|
-
C: (f, a) => f(...a)
|
|
395
|
-
});
|
|
309
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 175, S: this });
|
|
396
310
|
this._callbacks.onMessage(message);
|
|
397
311
|
}
|
|
398
312
|
};
|
|
@@ -411,24 +325,11 @@ var EdgeWsConnection = class extends Resource {
|
|
|
411
325
|
}
|
|
412
326
|
log.warn("error closing websocket", {
|
|
413
327
|
err
|
|
414
|
-
}, {
|
|
415
|
-
F: __dxlog_file3,
|
|
416
|
-
L: 203,
|
|
417
|
-
S: this,
|
|
418
|
-
C: (f, a) => f(...a)
|
|
419
|
-
});
|
|
328
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 194, S: this });
|
|
420
329
|
}
|
|
421
330
|
}
|
|
422
331
|
_scheduleHeartbeats() {
|
|
423
|
-
invariant3(this._ws, void 0, {
|
|
424
|
-
F: __dxlog_file3,
|
|
425
|
-
L: 208,
|
|
426
|
-
S: this,
|
|
427
|
-
A: [
|
|
428
|
-
"this._ws",
|
|
429
|
-
""
|
|
430
|
-
]
|
|
431
|
-
});
|
|
332
|
+
invariant3(this._ws, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 200, S: this, A: ["this._ws", ""] });
|
|
432
333
|
scheduleTaskInterval(this._ctx, async () => {
|
|
433
334
|
this._pingTimestamp = Date.now();
|
|
434
335
|
this._ws?.send("__ping__");
|
|
@@ -442,21 +343,13 @@ var EdgeWsConnection = class extends Resource {
|
|
|
442
343
|
return;
|
|
443
344
|
}
|
|
444
345
|
void this._inactivityTimeoutCtx?.dispose();
|
|
445
|
-
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
446
|
-
F: __dxlog_file3,
|
|
447
|
-
L: 229
|
|
448
|
-
});
|
|
346
|
+
this._inactivityTimeoutCtx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 216 });
|
|
449
347
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
450
348
|
if (this.isOpen) {
|
|
451
349
|
if (Date.now() - this._lastReceivedMessageTimestamp > SIGNAL_KEEPALIVE_TIMEOUT) {
|
|
452
350
|
log.warn("restart due to inactivity timeout", {
|
|
453
351
|
lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
|
|
454
|
-
}, {
|
|
455
|
-
F: __dxlog_file3,
|
|
456
|
-
L: 235,
|
|
457
|
-
S: this,
|
|
458
|
-
C: (f, a) => f(...a)
|
|
459
|
-
});
|
|
352
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 220, S: this });
|
|
460
353
|
this._callbacks.onRestartRequired();
|
|
461
354
|
} else {
|
|
462
355
|
this._rescheduleHeartbeatTimeout();
|
|
@@ -505,21 +398,6 @@ var EdgeWsConnection = class extends Resource {
|
|
|
505
398
|
this._uploadRate = timeSpan > 0 ? Math.round(totalSent / timeSpan) : 0;
|
|
506
399
|
this._downloadRate = timeSpan > 0 ? Math.round(totalReceived / timeSpan) : 0;
|
|
507
400
|
}
|
|
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
401
|
};
|
|
524
402
|
_ts_decorate([
|
|
525
403
|
logInfo
|
|
@@ -546,29 +424,34 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
546
424
|
};
|
|
547
425
|
|
|
548
426
|
// src/edge-client.ts
|
|
549
|
-
|
|
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
|
-
}
|
|
427
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
562
428
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
563
429
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
564
430
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
565
431
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
566
432
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
567
433
|
}
|
|
568
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
569
434
|
var DEFAULT_TIMEOUT = 1e4;
|
|
570
435
|
var STATUS_REFRESH_INTERVAL = 1e3;
|
|
571
436
|
var EdgeClient = class extends Resource2 {
|
|
437
|
+
_identity;
|
|
438
|
+
_config;
|
|
439
|
+
statusChanged = new Event();
|
|
440
|
+
_persistentLifecycle = new PersistentLifecycle({
|
|
441
|
+
start: async () => this._connect(),
|
|
442
|
+
stop: async (state) => this._disconnect(state)
|
|
443
|
+
});
|
|
444
|
+
_messageListeners = /* @__PURE__ */ new Set();
|
|
445
|
+
_reconnectListeners = /* @__PURE__ */ new Set();
|
|
446
|
+
_baseWsUrl;
|
|
447
|
+
_baseHttpUrl;
|
|
448
|
+
_currentConnection = void 0;
|
|
449
|
+
_ready = new Trigger();
|
|
450
|
+
constructor(_identity, _config) {
|
|
451
|
+
super(), this._identity = _identity, this._config = _config;
|
|
452
|
+
this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "ws");
|
|
453
|
+
this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "http");
|
|
454
|
+
}
|
|
572
455
|
get info() {
|
|
573
456
|
return {
|
|
574
457
|
open: this.isOpen,
|
|
@@ -599,12 +482,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
599
482
|
log2("Edge identity changed", {
|
|
600
483
|
identity,
|
|
601
484
|
oldIdentity: this._identity
|
|
602
|
-
}, {
|
|
603
|
-
F: __dxlog_file4,
|
|
604
|
-
L: 118,
|
|
605
|
-
S: this,
|
|
606
|
-
C: (f, a) => f(...a)
|
|
607
|
-
});
|
|
485
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 74, S: this });
|
|
608
486
|
this._identity = identity;
|
|
609
487
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
610
488
|
void this._persistentLifecycle.scheduleRestart();
|
|
@@ -614,14 +492,9 @@ var EdgeClient = class extends Resource2 {
|
|
|
614
492
|
* Send message.
|
|
615
493
|
* NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
|
|
616
494
|
*/
|
|
617
|
-
async send(message) {
|
|
495
|
+
async send(ctx, message) {
|
|
618
496
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
619
|
-
log2("waiting for websocket", void 0, {
|
|
620
|
-
F: __dxlog_file4,
|
|
621
|
-
L: 131,
|
|
622
|
-
S: this,
|
|
623
|
-
C: (f, a) => f(...a)
|
|
624
|
-
});
|
|
497
|
+
log2("waiting for websocket", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 88, S: this });
|
|
625
498
|
await this._ready.wait({
|
|
626
499
|
timeout: this._config.timeout ?? DEFAULT_TIMEOUT
|
|
627
500
|
});
|
|
@@ -632,6 +505,14 @@ var EdgeClient = class extends Resource2 {
|
|
|
632
505
|
if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
|
|
633
506
|
throw new EdgeIdentityChangedError();
|
|
634
507
|
}
|
|
508
|
+
const traceCtx = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE);
|
|
509
|
+
if (traceCtx) {
|
|
510
|
+
message.traceContext = {
|
|
511
|
+
$typeName: "dxos.edge.messenger.TraceContext",
|
|
512
|
+
traceparent: traceCtx.traceparent,
|
|
513
|
+
tracestate: traceCtx.tracestate
|
|
514
|
+
};
|
|
515
|
+
}
|
|
635
516
|
this._currentConnection.send(message);
|
|
636
517
|
}
|
|
637
518
|
onMessage(listener) {
|
|
@@ -646,12 +527,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
646
527
|
try {
|
|
647
528
|
listener();
|
|
648
529
|
} catch (error) {
|
|
649
|
-
log2.catch(error, void 0, {
|
|
650
|
-
F: __dxlog_file4,
|
|
651
|
-
L: 164,
|
|
652
|
-
S: this,
|
|
653
|
-
C: (f, a) => f(...a)
|
|
654
|
-
});
|
|
530
|
+
log2.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 123, S: this });
|
|
655
531
|
}
|
|
656
532
|
}
|
|
657
533
|
});
|
|
@@ -664,21 +540,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
664
540
|
async _open() {
|
|
665
541
|
log2("opening...", {
|
|
666
542
|
info: this.info
|
|
667
|
-
}, {
|
|
668
|
-
F: __dxlog_file4,
|
|
669
|
-
L: 177,
|
|
670
|
-
S: this,
|
|
671
|
-
C: (f, a) => f(...a)
|
|
672
|
-
});
|
|
543
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 133, S: this });
|
|
673
544
|
this._persistentLifecycle.open().catch((err) => {
|
|
674
545
|
log2.warn("Error while opening connection", {
|
|
675
546
|
err
|
|
676
|
-
}, {
|
|
677
|
-
F: __dxlog_file4,
|
|
678
|
-
L: 179,
|
|
679
|
-
S: this,
|
|
680
|
-
C: (f, a) => f(...a)
|
|
681
|
-
});
|
|
547
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 137, S: this });
|
|
682
548
|
});
|
|
683
549
|
scheduleTaskInterval2(this._ctx, async () => {
|
|
684
550
|
if (!this._currentConnection) {
|
|
@@ -693,12 +559,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
693
559
|
async _close() {
|
|
694
560
|
log2("closing...", {
|
|
695
561
|
peerKey: this._identity.peerKey
|
|
696
|
-
}, {
|
|
697
|
-
F: __dxlog_file4,
|
|
698
|
-
L: 199,
|
|
699
|
-
S: this,
|
|
700
|
-
C: (f, a) => f(...a)
|
|
701
|
-
});
|
|
562
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 152, S: this });
|
|
702
563
|
this._closeCurrentConnection();
|
|
703
564
|
await this._persistentLifecycle.close();
|
|
704
565
|
}
|
|
@@ -710,12 +571,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
710
571
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
711
572
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
712
573
|
if (this._identity !== identity) {
|
|
713
|
-
log2("identity changed during auth header request", void 0, {
|
|
714
|
-
F: __dxlog_file4,
|
|
715
|
-
L: 213,
|
|
716
|
-
S: this,
|
|
717
|
-
C: (f, a) => f(...a)
|
|
718
|
-
});
|
|
574
|
+
log2("identity changed during auth header request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 166, S: this });
|
|
719
575
|
return void 0;
|
|
720
576
|
}
|
|
721
577
|
const restartRequired = new Trigger();
|
|
@@ -723,27 +579,20 @@ var EdgeClient = class extends Resource2 {
|
|
|
723
579
|
log2("Opening websocket", {
|
|
724
580
|
url: url.toString(),
|
|
725
581
|
protocolHeader
|
|
726
|
-
}, {
|
|
727
|
-
F: __dxlog_file4,
|
|
728
|
-
L: 219,
|
|
729
|
-
S: this,
|
|
730
|
-
C: (f, a) => f(...a)
|
|
731
|
-
});
|
|
582
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 171, S: this });
|
|
732
583
|
const connection = new EdgeWsConnection(identity, {
|
|
733
584
|
url,
|
|
734
|
-
protocolHeader
|
|
585
|
+
protocolHeader,
|
|
586
|
+
headers: this._config.clientTag ? {
|
|
587
|
+
"X-DXOS-Client-Tag": this._config.clientTag
|
|
588
|
+
} : void 0
|
|
735
589
|
}, {
|
|
736
590
|
onConnected: () => {
|
|
737
591
|
if (this._isActive(connection)) {
|
|
738
592
|
this._ready.wake();
|
|
739
593
|
this._notifyReconnected();
|
|
740
594
|
} else {
|
|
741
|
-
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
742
|
-
F: __dxlog_file4,
|
|
743
|
-
L: 229,
|
|
744
|
-
S: this,
|
|
745
|
-
C: (f, a) => f(...a)
|
|
746
|
-
});
|
|
595
|
+
log2.verbose("connected callback ignored, because connection is not active", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 187, S: this });
|
|
747
596
|
}
|
|
748
597
|
},
|
|
749
598
|
onRestartRequired: () => {
|
|
@@ -751,12 +600,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
751
600
|
this._closeCurrentConnection();
|
|
752
601
|
void this._persistentLifecycle.scheduleRestart();
|
|
753
602
|
} else {
|
|
754
|
-
log2.verbose("restart requested by inactive connection", void 0, {
|
|
755
|
-
F: __dxlog_file4,
|
|
756
|
-
L: 237,
|
|
757
|
-
S: this,
|
|
758
|
-
C: (f, a) => f(...a)
|
|
759
|
-
});
|
|
603
|
+
log2.verbose("restart requested by inactive connection", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 195, S: this });
|
|
760
604
|
}
|
|
761
605
|
restartRequired.wake();
|
|
762
606
|
},
|
|
@@ -767,12 +611,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
767
611
|
log2.verbose("ignored a message on inactive connection", {
|
|
768
612
|
from: message.source,
|
|
769
613
|
type: message.payload?.typeUrl
|
|
770
|
-
}, {
|
|
771
|
-
F: __dxlog_file4,
|
|
772
|
-
L: 245,
|
|
773
|
-
S: this,
|
|
774
|
-
C: (f, a) => f(...a)
|
|
775
|
-
});
|
|
614
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 203, S: this });
|
|
776
615
|
}
|
|
777
616
|
}
|
|
778
617
|
});
|
|
@@ -804,12 +643,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
804
643
|
} catch (err) {
|
|
805
644
|
log2.error("ws reconnect listener failed", {
|
|
806
645
|
err
|
|
807
|
-
}, {
|
|
808
|
-
F: __dxlog_file4,
|
|
809
|
-
L: 280,
|
|
810
|
-
S: this,
|
|
811
|
-
C: (f, a) => f(...a)
|
|
812
|
-
});
|
|
646
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 238, S: this });
|
|
813
647
|
}
|
|
814
648
|
}
|
|
815
649
|
}
|
|
@@ -821,12 +655,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
821
655
|
log2.error("ws incoming message processing failed", {
|
|
822
656
|
err,
|
|
823
657
|
payload: protocol.getPayloadType(message)
|
|
824
|
-
}, {
|
|
825
|
-
F: __dxlog_file4,
|
|
826
|
-
L: 290,
|
|
827
|
-
S: this,
|
|
828
|
-
C: (f, a) => f(...a)
|
|
829
|
-
});
|
|
658
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 249, S: this });
|
|
830
659
|
}
|
|
831
660
|
}
|
|
832
661
|
}
|
|
@@ -842,23 +671,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
842
671
|
log2.warn("no auth challenge from edge", {
|
|
843
672
|
status: response.status,
|
|
844
673
|
statusText: response.statusText
|
|
845
|
-
}, {
|
|
846
|
-
F: __dxlog_file4,
|
|
847
|
-
L: 302,
|
|
848
|
-
S: this,
|
|
849
|
-
C: (f, a) => f(...a)
|
|
850
|
-
});
|
|
674
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 265, S: this });
|
|
851
675
|
return void 0;
|
|
852
676
|
}
|
|
853
677
|
}
|
|
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
|
-
}
|
|
678
|
+
_isActive = (connection) => connection === this._currentConnection;
|
|
862
679
|
};
|
|
863
680
|
_ts_decorate2([
|
|
864
681
|
logInfo2
|
|
@@ -874,9 +691,11 @@ import * as HttpClient from "@effect/platform/HttpClient";
|
|
|
874
691
|
import * as Effect2 from "effect/Effect";
|
|
875
692
|
import * as Function from "effect/Function";
|
|
876
693
|
import { sleep } from "@dxos/async";
|
|
877
|
-
import {
|
|
694
|
+
import { TRACE_SPAN_ATTRIBUTE as TRACE_SPAN_ATTRIBUTE2 } from "@dxos/context";
|
|
695
|
+
import { runAndForwardErrors } from "@dxos/effect";
|
|
696
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
878
697
|
import { log as log4 } from "@dxos/log";
|
|
879
|
-
import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
698
|
+
import { EDGE_CLIENT_TAG_HEADER, EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
880
699
|
import { createUrl } from "@dxos/util";
|
|
881
700
|
|
|
882
701
|
// src/http-client.ts
|
|
@@ -886,28 +705,14 @@ import * as Effect from "effect/Effect";
|
|
|
886
705
|
import * as Layer from "effect/Layer";
|
|
887
706
|
import * as Schedule from "effect/Schedule";
|
|
888
707
|
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
708
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
|
|
903
|
-
var
|
|
904
|
-
|
|
709
|
+
var HttpConfig = class _HttpConfig extends Context2.Tag("HttpConfig")() {
|
|
710
|
+
static default = Layer.succeed(_HttpConfig, {
|
|
711
|
+
timeout: Duration.millis(1e3),
|
|
712
|
+
retryTimes: 3,
|
|
713
|
+
retryBaseDelay: Duration.millis(1e3)
|
|
714
|
+
});
|
|
905
715
|
};
|
|
906
|
-
_define_property3(HttpConfig, "default", Layer.succeed(HttpConfig, {
|
|
907
|
-
timeout: Duration.millis(1e3),
|
|
908
|
-
retryTimes: 3,
|
|
909
|
-
retryBaseDelay: Duration.millis(1e3)
|
|
910
|
-
}));
|
|
911
716
|
var withRetry = (effect, { timeout: timeout2 = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
|
|
912
717
|
return effect.pipe(Effect.flatMap((res) => (
|
|
913
718
|
// Treat 500 errors as retryable?
|
|
@@ -921,39 +726,38 @@ var withRetryConfig = (effect) => Effect.gen(function* () {
|
|
|
921
726
|
const config = yield* HttpConfig;
|
|
922
727
|
return yield* withRetry(effect, config);
|
|
923
728
|
});
|
|
924
|
-
var withLogging = (effect) => effect.pipe(Effect.tap((res) =>
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
F: __dxlog_file5,
|
|
928
|
-
|
|
929
|
-
S: void 0,
|
|
930
|
-
C: (f, a) => f(...a)
|
|
931
|
-
})));
|
|
729
|
+
var withLogging = (effect) => effect.pipe(Effect.tap((res) => {
|
|
730
|
+
log3.info("response", {
|
|
731
|
+
status: res.status
|
|
732
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 31, S: void 0 });
|
|
733
|
+
}));
|
|
932
734
|
var encodeAuthHeader = (challenge) => {
|
|
933
735
|
const encodedChallenge = Buffer.from(challenge).toString("base64");
|
|
934
736
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
935
737
|
};
|
|
936
738
|
|
|
937
739
|
// 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
740
|
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
952
741
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
953
742
|
var DEFAULT_RETRY_JITTER = 500;
|
|
954
743
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
955
744
|
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
745
|
+
var LEGACY_CORS_PROXY_URL = "https://cors-proxy.dxos.workers.dev";
|
|
956
746
|
var EdgeHttpClient = class {
|
|
747
|
+
_baseUrl;
|
|
748
|
+
_clientTag;
|
|
749
|
+
_edgeIdentity;
|
|
750
|
+
/**
|
|
751
|
+
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
752
|
+
*/
|
|
753
|
+
_authHeader;
|
|
754
|
+
constructor(baseUrl, options) {
|
|
755
|
+
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
756
|
+
this._clientTag = options?.clientTag;
|
|
757
|
+
log4("created", {
|
|
758
|
+
url: this._baseUrl
|
|
759
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: this });
|
|
760
|
+
}
|
|
957
761
|
get baseUrl() {
|
|
958
762
|
return this._baseUrl;
|
|
959
763
|
}
|
|
@@ -966,24 +770,25 @@ var EdgeHttpClient = class {
|
|
|
966
770
|
//
|
|
967
771
|
// Status
|
|
968
772
|
//
|
|
969
|
-
async getStatus(args) {
|
|
970
|
-
return this._call(new URL("/status", this.baseUrl), {
|
|
773
|
+
async getStatus(ctx, args) {
|
|
774
|
+
return this._call(ctx, new URL("/status", this.baseUrl), {
|
|
971
775
|
...args,
|
|
972
|
-
method: "GET"
|
|
776
|
+
method: "GET",
|
|
777
|
+
auth: true
|
|
973
778
|
});
|
|
974
779
|
}
|
|
975
780
|
//
|
|
976
781
|
// Agents
|
|
977
782
|
//
|
|
978
|
-
createAgent(body, args) {
|
|
979
|
-
return this._call(new URL("/agents/create", this.baseUrl), {
|
|
783
|
+
createAgent(ctx, body, args) {
|
|
784
|
+
return this._call(ctx, new URL("/agents/create", this.baseUrl), {
|
|
980
785
|
...args,
|
|
981
786
|
method: "POST",
|
|
982
787
|
body
|
|
983
788
|
});
|
|
984
789
|
}
|
|
985
|
-
getAgentStatus(request, args) {
|
|
986
|
-
return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
790
|
+
getAgentStatus(ctx, request, args) {
|
|
791
|
+
return this._call(ctx, new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
987
792
|
...args,
|
|
988
793
|
method: "GET"
|
|
989
794
|
});
|
|
@@ -991,14 +796,14 @@ var EdgeHttpClient = class {
|
|
|
991
796
|
//
|
|
992
797
|
// Credentials
|
|
993
798
|
//
|
|
994
|
-
getCredentialsForNotarization(spaceId, args) {
|
|
995
|
-
return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
799
|
+
getCredentialsForNotarization(ctx, spaceId, args) {
|
|
800
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
996
801
|
...args,
|
|
997
802
|
method: "GET"
|
|
998
803
|
});
|
|
999
804
|
}
|
|
1000
|
-
async notarizeCredentials(spaceId, body, args) {
|
|
1001
|
-
await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
805
|
+
async notarizeCredentials(ctx, spaceId, body, args) {
|
|
806
|
+
await this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
1002
807
|
...args,
|
|
1003
808
|
body,
|
|
1004
809
|
method: "POST"
|
|
@@ -1007,8 +812,8 @@ var EdgeHttpClient = class {
|
|
|
1007
812
|
//
|
|
1008
813
|
// Identity
|
|
1009
814
|
//
|
|
1010
|
-
async recoverIdentity(body, args) {
|
|
1011
|
-
return this._call(new URL("/identity/recover", this.baseUrl), {
|
|
815
|
+
async recoverIdentity(ctx, body, args) {
|
|
816
|
+
return this._call(ctx, new URL("/identity/recover", this.baseUrl), {
|
|
1012
817
|
...args,
|
|
1013
818
|
body,
|
|
1014
819
|
method: "POST"
|
|
@@ -1017,8 +822,8 @@ var EdgeHttpClient = class {
|
|
|
1017
822
|
//
|
|
1018
823
|
// Invitations
|
|
1019
824
|
//
|
|
1020
|
-
async joinSpaceByInvitation(spaceId, body, args) {
|
|
1021
|
-
return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
825
|
+
async joinSpaceByInvitation(ctx, spaceId, body, args) {
|
|
826
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
1022
827
|
...args,
|
|
1023
828
|
body,
|
|
1024
829
|
method: "POST"
|
|
@@ -1027,8 +832,8 @@ var EdgeHttpClient = class {
|
|
|
1027
832
|
//
|
|
1028
833
|
// OAuth and credentials
|
|
1029
834
|
//
|
|
1030
|
-
async initiateOAuthFlow(body, args) {
|
|
1031
|
-
return this._call(new URL("/oauth/initiate", this.baseUrl), {
|
|
835
|
+
async initiateOAuthFlow(ctx, body, args) {
|
|
836
|
+
return this._call(ctx, new URL("/oauth/initiate", this.baseUrl), {
|
|
1032
837
|
...args,
|
|
1033
838
|
body,
|
|
1034
839
|
method: "POST"
|
|
@@ -1037,8 +842,8 @@ var EdgeHttpClient = class {
|
|
|
1037
842
|
//
|
|
1038
843
|
// Spaces
|
|
1039
844
|
//
|
|
1040
|
-
async createSpace(body, args) {
|
|
1041
|
-
return this._call(new URL("/spaces/create", this.baseUrl), {
|
|
845
|
+
async createSpace(ctx, body, args) {
|
|
846
|
+
return this._call(ctx, new URL("/spaces/create", this.baseUrl), {
|
|
1042
847
|
...args,
|
|
1043
848
|
body,
|
|
1044
849
|
method: "POST"
|
|
@@ -1047,9 +852,10 @@ var EdgeHttpClient = class {
|
|
|
1047
852
|
//
|
|
1048
853
|
// Queues
|
|
1049
854
|
//
|
|
1050
|
-
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
1051
|
-
const
|
|
1052
|
-
|
|
855
|
+
async queryQueue(ctx, subspaceTag, spaceId, query, args) {
|
|
856
|
+
const queueId = query.queueIds?.[0];
|
|
857
|
+
invariant4(queueId, "queueId required", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 137, S: this, A: ["queueId", "'queueId required'"] });
|
|
858
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
1053
859
|
after: query.after,
|
|
1054
860
|
before: query.before,
|
|
1055
861
|
limit: query.limit,
|
|
@@ -1060,8 +866,8 @@ var EdgeHttpClient = class {
|
|
|
1060
866
|
method: "GET"
|
|
1061
867
|
});
|
|
1062
868
|
}
|
|
1063
|
-
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
1064
|
-
return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
869
|
+
async insertIntoQueue(ctx, subspaceTag, spaceId, queueId, objects, args) {
|
|
870
|
+
return this._call(ctx, new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1065
871
|
...args,
|
|
1066
872
|
body: {
|
|
1067
873
|
objects
|
|
@@ -1069,8 +875,8 @@ var EdgeHttpClient = class {
|
|
|
1069
875
|
method: "POST"
|
|
1070
876
|
});
|
|
1071
877
|
}
|
|
1072
|
-
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1073
|
-
return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
878
|
+
async deleteFromQueue(ctx, subspaceTag, spaceId, queueId, objectIds, args) {
|
|
879
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1074
880
|
ids: objectIds.join(",")
|
|
1075
881
|
}), {
|
|
1076
882
|
...args,
|
|
@@ -1080,12 +886,13 @@ var EdgeHttpClient = class {
|
|
|
1080
886
|
//
|
|
1081
887
|
// Functions
|
|
1082
888
|
//
|
|
1083
|
-
async uploadFunction(pathParts, body, args) {
|
|
889
|
+
async uploadFunction(ctx, pathParts, body, args) {
|
|
1084
890
|
const formData = new FormData();
|
|
1085
891
|
formData.append("name", body.name ?? "");
|
|
1086
892
|
formData.append("version", body.version);
|
|
1087
893
|
formData.append("ownerPublicKey", body.ownerPublicKey);
|
|
1088
894
|
formData.append("entryPoint", body.entryPoint);
|
|
895
|
+
body.runtime && formData.append("runtime", body.runtime);
|
|
1089
896
|
for (const [filename, content] of Object.entries(body.assets)) {
|
|
1090
897
|
formData.append("assets", new Blob([
|
|
1091
898
|
content
|
|
@@ -1099,20 +906,20 @@ var EdgeHttpClient = class {
|
|
|
1099
906
|
pathParts.functionId
|
|
1100
907
|
] : []
|
|
1101
908
|
].join("/");
|
|
1102
|
-
return this._call(new URL(path, this.baseUrl), {
|
|
909
|
+
return this._call(ctx, new URL(path, this.baseUrl), {
|
|
1103
910
|
...args,
|
|
1104
911
|
body: formData,
|
|
1105
912
|
method: "PUT",
|
|
1106
913
|
json: false
|
|
1107
914
|
});
|
|
1108
915
|
}
|
|
1109
|
-
async listFunctions(args) {
|
|
1110
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
916
|
+
async listFunctions(ctx, args) {
|
|
917
|
+
return this._call(ctx, new URL("/functions", this.baseUrl), {
|
|
1111
918
|
...args,
|
|
1112
919
|
method: "GET"
|
|
1113
920
|
});
|
|
1114
921
|
}
|
|
1115
|
-
async invokeFunction(params, input, args) {
|
|
922
|
+
async invokeFunction(ctx, params, input, args) {
|
|
1116
923
|
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1117
924
|
if (params.version) {
|
|
1118
925
|
url.searchParams.set("version", params.version);
|
|
@@ -1126,18 +933,17 @@ var EdgeHttpClient = class {
|
|
|
1126
933
|
if (params.subrequestsLimit) {
|
|
1127
934
|
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1128
935
|
}
|
|
1129
|
-
return this._call(url, {
|
|
936
|
+
return this._call(ctx, url, {
|
|
1130
937
|
...args,
|
|
1131
938
|
body: input,
|
|
1132
|
-
method: "POST"
|
|
1133
|
-
rawResponse: true
|
|
939
|
+
method: "POST"
|
|
1134
940
|
});
|
|
1135
941
|
}
|
|
1136
942
|
//
|
|
1137
943
|
// Workflows
|
|
1138
944
|
//
|
|
1139
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1140
|
-
return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
945
|
+
async executeWorkflow(ctx, spaceId, graphId, input, args) {
|
|
946
|
+
return this._call(ctx, new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
1141
947
|
...args,
|
|
1142
948
|
body: input,
|
|
1143
949
|
method: "POST"
|
|
@@ -1146,103 +952,161 @@ var EdgeHttpClient = class {
|
|
|
1146
952
|
//
|
|
1147
953
|
// Triggers
|
|
1148
954
|
//
|
|
1149
|
-
async getCronTriggers(spaceId) {
|
|
1150
|
-
return this._call(new URL(`/
|
|
955
|
+
async getCronTriggers(ctx, spaceId) {
|
|
956
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
957
|
+
method: "GET"
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
async forceRunCronTrigger(ctx, spaceId, triggerId) {
|
|
961
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
|
|
962
|
+
method: "POST"
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
//
|
|
966
|
+
// Query
|
|
967
|
+
//
|
|
968
|
+
/**
|
|
969
|
+
* Execute a QueryAST query against a space.
|
|
970
|
+
*/
|
|
971
|
+
async execQuery(ctx, spaceId, body, args) {
|
|
972
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), {
|
|
973
|
+
...args,
|
|
974
|
+
body,
|
|
975
|
+
method: "POST"
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
//
|
|
979
|
+
// Registry
|
|
980
|
+
//
|
|
981
|
+
/**
|
|
982
|
+
* Fetches the hydrated plugin directory from the Edge registry service.
|
|
983
|
+
* Unauthenticated; safe to call without an identity.
|
|
984
|
+
*/
|
|
985
|
+
async getRegistryPlugins(ctx, args) {
|
|
986
|
+
return this._call(ctx, new URL("/registry/plugins", this.baseUrl), {
|
|
987
|
+
...args,
|
|
988
|
+
method: "GET"
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Fetches the available release versions for a given plugin repo. `repo` is the
|
|
993
|
+
* GitHub `owner/name` form; this method takes care of URL-encoding before issuing
|
|
994
|
+
* the request. Unauthenticated; same surface area as {@link getRegistryPlugins}.
|
|
995
|
+
*
|
|
996
|
+
* Versions are returned newest first, suitable for direct rendering in a picker.
|
|
997
|
+
*/
|
|
998
|
+
async getRegistryPluginVersions(ctx, repo, args) {
|
|
999
|
+
return this._call(ctx, new URL(`/registry/plugins/${encodeURIComponent(repo)}/versions`, this.baseUrl), {
|
|
1000
|
+
...args,
|
|
1151
1001
|
method: "GET"
|
|
1152
1002
|
});
|
|
1153
1003
|
}
|
|
1154
1004
|
//
|
|
1155
1005
|
// Import/Export space.
|
|
1156
1006
|
//
|
|
1157
|
-
async importBundle(spaceId, body, args) {
|
|
1158
|
-
return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1007
|
+
async importBundle(ctx, spaceId, body, args) {
|
|
1008
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1159
1009
|
...args,
|
|
1160
1010
|
body,
|
|
1161
1011
|
method: "PUT"
|
|
1162
1012
|
});
|
|
1163
1013
|
}
|
|
1164
|
-
async exportBundle(spaceId, body, args) {
|
|
1165
|
-
return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1014
|
+
async exportBundle(ctx, spaceId, body, args) {
|
|
1015
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1166
1016
|
...args,
|
|
1167
1017
|
body,
|
|
1168
1018
|
method: "POST"
|
|
1169
1019
|
});
|
|
1170
1020
|
}
|
|
1171
1021
|
//
|
|
1022
|
+
// Integration proxy.
|
|
1023
|
+
//
|
|
1024
|
+
/**
|
|
1025
|
+
* Fetch through the edge proxy, used by integration plugins (Discord, ...)
|
|
1026
|
+
* to call third-party REST APIs that don't set permissive CORS headers.
|
|
1027
|
+
*
|
|
1028
|
+
* `init.headers.Authorization` (caller-supplied) is preserved by prefixing
|
|
1029
|
+
* with `X-Cors-Proxy-Authorization`, since the proxy strips `Authorization`
|
|
1030
|
+
* on forwarding to avoid leaking the DXOS presentation upstream — the
|
|
1031
|
+
* prefix carries the upstream's bot token / token through.
|
|
1032
|
+
*
|
|
1033
|
+
* TEMPORARY: routed through the legacy standalone proxy at
|
|
1034
|
+
* `cors-proxy.dxos.workers.dev` (open, unauthenticated, path
|
|
1035
|
+
* `/<host>/<path>`) so that integration plugins can be tested before the
|
|
1036
|
+
* authenticated `/proxy/*` route on the main edge worker ships
|
|
1037
|
+
* (https://github.com/dxos/edge/pull/576). When that PR deploys, restore
|
|
1038
|
+
* the commented-out block below — it rewrites the target under
|
|
1039
|
+
* `${this.baseUrl}/proxy/...` and signs the request with the cached
|
|
1040
|
+
* verifiable presentation. The header-remap and `x-cors-proxy-*` override
|
|
1041
|
+
* conventions are unchanged between the two paths.
|
|
1042
|
+
*/
|
|
1043
|
+
async proxyFetch(target, init = {}) {
|
|
1044
|
+
return proxyFetchLegacy(target, init, this._clientTag);
|
|
1045
|
+
}
|
|
1046
|
+
//
|
|
1172
1047
|
// Internal
|
|
1173
1048
|
//
|
|
1174
|
-
async _fetch(url,
|
|
1175
|
-
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"),
|
|
1049
|
+
async _fetch(url, _args) {
|
|
1050
|
+
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1176
1051
|
}
|
|
1177
1052
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1178
|
-
async _call(url, args) {
|
|
1053
|
+
async _call(ctx, url, args) {
|
|
1179
1054
|
const shouldRetry = createRetryHandler(args);
|
|
1180
|
-
const requestContext = args.context ?? new Context3(void 0, {
|
|
1181
|
-
F: __dxlog_file6,
|
|
1182
|
-
L: 391
|
|
1183
|
-
});
|
|
1184
1055
|
log4("fetch", {
|
|
1185
1056
|
url,
|
|
1186
1057
|
request: args.body
|
|
1187
|
-
}, {
|
|
1188
|
-
|
|
1189
|
-
L: 392,
|
|
1190
|
-
S: this,
|
|
1191
|
-
C: (f, a) => f(...a)
|
|
1192
|
-
});
|
|
1058
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 362, S: this });
|
|
1059
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1193
1060
|
let handledAuth = false;
|
|
1061
|
+
const tryCount = 1;
|
|
1194
1062
|
while (true) {
|
|
1195
1063
|
let processingError = void 0;
|
|
1196
|
-
let retryAfterHeaderValue = Number.NaN;
|
|
1197
1064
|
try {
|
|
1198
|
-
|
|
1065
|
+
if (!this._authHeader && args.auth) {
|
|
1066
|
+
const response2 = await fetch(new URL(`/auth`, this.baseUrl));
|
|
1067
|
+
if (response2.status === 401) {
|
|
1068
|
+
this._authHeader = await this._handleUnauthorized(response2);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
|
|
1072
|
+
log4("call edge", {
|
|
1073
|
+
url,
|
|
1074
|
+
tryCount,
|
|
1075
|
+
authHeader: !!this._authHeader
|
|
1076
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 379, S: this });
|
|
1199
1077
|
const response = await fetch(url, request);
|
|
1200
|
-
retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
|
|
1201
1078
|
if (response.ok) {
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
if (!("success" in body)) {
|
|
1207
|
-
return body;
|
|
1208
|
-
}
|
|
1209
|
-
if (body.success) {
|
|
1210
|
-
return body.data;
|
|
1079
|
+
const body2 = await response.clone().json();
|
|
1080
|
+
invariant4(body2, "Expected body to be present", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 387, S: this, A: ["body", "'Expected body to be present'"] });
|
|
1081
|
+
if (!("success" in body2)) {
|
|
1082
|
+
return body2;
|
|
1211
1083
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
body
|
|
1215
|
-
}, {
|
|
1216
|
-
F: __dxlog_file6,
|
|
1217
|
-
L: 417,
|
|
1218
|
-
S: this,
|
|
1219
|
-
C: (f, a) => f(...a)
|
|
1220
|
-
});
|
|
1221
|
-
if (body.errorData?.type === "auth_challenge" && typeof body.errorData?.challenge === "string") {
|
|
1222
|
-
processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
|
|
1223
|
-
} else if (body.errorData) {
|
|
1224
|
-
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1084
|
+
if (body2.success) {
|
|
1085
|
+
return body2.data;
|
|
1225
1086
|
}
|
|
1226
1087
|
} else if (response.status === 401 && !handledAuth) {
|
|
1227
1088
|
this._authHeader = await this._handleUnauthorized(response);
|
|
1228
1089
|
handledAuth = true;
|
|
1229
1090
|
continue;
|
|
1091
|
+
}
|
|
1092
|
+
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1093
|
+
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 400, S: this, A: ["!body?.success", "'Expected body to not be a failure response or undefined.'"] });
|
|
1094
|
+
if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
|
|
1095
|
+
processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
|
|
1096
|
+
} else if (body?.success === false) {
|
|
1097
|
+
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1230
1098
|
} else {
|
|
1099
|
+
invariant4(!response.ok, "Expected response to not be ok.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 406, S: this, A: ["!response.ok", "'Expected response to not be ok.'"] });
|
|
1231
1100
|
processingError = await EdgeCallFailedError.fromHttpFailure(response);
|
|
1232
1101
|
}
|
|
1233
1102
|
} catch (error) {
|
|
1234
1103
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1235
1104
|
}
|
|
1236
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1237
|
-
log4("retrying edge request", {
|
|
1105
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1106
|
+
log4.verbose("retrying edge request", {
|
|
1238
1107
|
url,
|
|
1239
1108
|
processingError
|
|
1240
|
-
}, {
|
|
1241
|
-
F: __dxlog_file6,
|
|
1242
|
-
L: 435,
|
|
1243
|
-
S: this,
|
|
1244
|
-
C: (f, a) => f(...a)
|
|
1245
|
-
});
|
|
1109
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 413, S: this });
|
|
1246
1110
|
} else {
|
|
1247
1111
|
throw processingError;
|
|
1248
1112
|
}
|
|
@@ -1250,33 +1114,14 @@ var EdgeHttpClient = class {
|
|
|
1250
1114
|
}
|
|
1251
1115
|
async _handleUnauthorized(response) {
|
|
1252
1116
|
if (!this._edgeIdentity) {
|
|
1253
|
-
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1254
|
-
F: __dxlog_file6,
|
|
1255
|
-
L: 444,
|
|
1256
|
-
S: this,
|
|
1257
|
-
C: (f, a) => f(...a)
|
|
1258
|
-
});
|
|
1117
|
+
log4.warn("unauthorized response received before identity was set", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 424, S: this });
|
|
1259
1118
|
throw await EdgeCallFailedError.fromHttpFailure(response);
|
|
1260
1119
|
}
|
|
1261
1120
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
1262
1121
|
return encodeAuthHeader(challenge);
|
|
1263
1122
|
}
|
|
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
1123
|
};
|
|
1279
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1124
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
|
|
1280
1125
|
let requestBody;
|
|
1281
1126
|
const headers = {};
|
|
1282
1127
|
if (json) {
|
|
@@ -1288,22 +1133,36 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1288
1133
|
if (typeof requestBody === "string" && requestBody.length > WARNING_BODY_SIZE) {
|
|
1289
1134
|
log4.warn("Request with large body", {
|
|
1290
1135
|
bodySize: requestBody.length
|
|
1291
|
-
}, {
|
|
1292
|
-
F: __dxlog_file6,
|
|
1293
|
-
L: 468,
|
|
1294
|
-
S: void 0,
|
|
1295
|
-
C: (f, a) => f(...a)
|
|
1296
|
-
});
|
|
1136
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 441, S: void 0 });
|
|
1297
1137
|
}
|
|
1298
1138
|
if (authHeader) {
|
|
1299
1139
|
headers["Authorization"] = authHeader;
|
|
1300
1140
|
}
|
|
1141
|
+
if (traceHeaders) {
|
|
1142
|
+
Object.assign(headers, traceHeaders);
|
|
1143
|
+
}
|
|
1144
|
+
if (clientTag) {
|
|
1145
|
+
headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
|
|
1146
|
+
}
|
|
1301
1147
|
return {
|
|
1302
1148
|
method,
|
|
1303
1149
|
body: requestBody,
|
|
1304
1150
|
headers
|
|
1305
1151
|
};
|
|
1306
1152
|
};
|
|
1153
|
+
var getTraceHeaders = (ctx) => {
|
|
1154
|
+
const traceCtx = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE2);
|
|
1155
|
+
if (!traceCtx) {
|
|
1156
|
+
return void 0;
|
|
1157
|
+
}
|
|
1158
|
+
const headers = {
|
|
1159
|
+
traceparent: traceCtx.traceparent
|
|
1160
|
+
};
|
|
1161
|
+
if (traceCtx.tracestate) {
|
|
1162
|
+
headers.tracestate = traceCtx.tracestate;
|
|
1163
|
+
}
|
|
1164
|
+
return headers;
|
|
1165
|
+
};
|
|
1307
1166
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1308
1167
|
if (!retry2 || retry2.count < 1) {
|
|
1309
1168
|
return async () => false;
|
|
@@ -1329,6 +1188,28 @@ var getFileMimeType = (filename) => [
|
|
|
1329
1188
|
".js",
|
|
1330
1189
|
".mjs"
|
|
1331
1190
|
].some((codeExtension) => filename.endsWith(codeExtension)) ? "application/javascript+module" : filename.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
|
|
1191
|
+
var remapAuthorizationForProxy = (headers) => {
|
|
1192
|
+
const callerAuth = headers.get("Authorization");
|
|
1193
|
+
if (callerAuth !== null) {
|
|
1194
|
+
headers.delete("Authorization");
|
|
1195
|
+
headers.set("X-Cors-Proxy-Authorization", callerAuth);
|
|
1196
|
+
}
|
|
1197
|
+
return headers;
|
|
1198
|
+
};
|
|
1199
|
+
var proxyFetchLegacy = (target, init = {}, clientTag) => {
|
|
1200
|
+
const proxyUrl = new URL(`/${target.host}${target.pathname}${target.search}`, LEGACY_CORS_PROXY_URL);
|
|
1201
|
+
if (target.protocol === "http:") {
|
|
1202
|
+
proxyUrl.searchParams.set("scheme", "http");
|
|
1203
|
+
}
|
|
1204
|
+
const requestHeaders = remapAuthorizationForProxy(new Headers(init.headers ?? void 0));
|
|
1205
|
+
if (clientTag) {
|
|
1206
|
+
requestHeaders.set(EDGE_CLIENT_TAG_HEADER, clientTag);
|
|
1207
|
+
}
|
|
1208
|
+
return fetch(proxyUrl, {
|
|
1209
|
+
...init,
|
|
1210
|
+
headers: requestHeaders
|
|
1211
|
+
});
|
|
1212
|
+
};
|
|
1332
1213
|
export {
|
|
1333
1214
|
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1334
1215
|
CLOUDFLARE_RPC_MAX_BYTES,
|
|
@@ -1348,6 +1229,7 @@ export {
|
|
|
1348
1229
|
getTypename,
|
|
1349
1230
|
handleAuthChallenge,
|
|
1350
1231
|
protocol,
|
|
1232
|
+
proxyFetchLegacy,
|
|
1351
1233
|
toUint8Array,
|
|
1352
1234
|
withLogging,
|
|
1353
1235
|
withRetry,
|