@dxos/edge-client 0.8.4-main.ef1bc66f44 → 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/neutral/{chunk-VESGVCLQ.mjs → chunk-ZIQ5T3A7.mjs} +6 -40
- package/dist/lib/neutral/{chunk-VESGVCLQ.mjs.map → chunk-ZIQ5T3A7.mjs.map} +2 -2
- package/dist/lib/neutral/edge-ws-muxer.mjs +1 -1
- package/dist/lib/neutral/index.mjs +222 -358
- package/dist/lib/neutral/index.mjs.map +3 -3
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +6 -31
- package/dist/lib/neutral/testing/index.mjs.map +2 -2
- 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 +96 -29
- 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.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 +20 -25
- package/src/edge-client.test.ts +16 -11
- package/src/edge-client.ts +19 -3
- package/src/edge-http-client.test.ts +2 -1
- package/src/edge-http-client.ts +278 -49
- package/src/edge-ws-connection.ts +2 -1
|
@@ -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,13 +146,13 @@ 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";
|
|
149
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
180
150
|
function _ts_decorate(decorators, target, key, desc) {
|
|
181
151
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
182
152
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
183
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;
|
|
184
154
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
185
155
|
}
|
|
186
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
187
156
|
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
188
157
|
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
189
158
|
var EdgeWsConnection = class extends Resource {
|
|
@@ -235,33 +204,12 @@ var EdgeWsConnection = class extends Resource {
|
|
|
235
204
|
return this._messagesReceived;
|
|
236
205
|
}
|
|
237
206
|
send(message) {
|
|
238
|
-
invariant3(this._ws, void 0, {
|
|
239
|
-
|
|
240
|
-
L: 93,
|
|
241
|
-
S: this,
|
|
242
|
-
A: [
|
|
243
|
-
"this._ws",
|
|
244
|
-
""
|
|
245
|
-
]
|
|
246
|
-
});
|
|
247
|
-
invariant3(this._wsMuxer, void 0, {
|
|
248
|
-
F: __dxlog_file3,
|
|
249
|
-
L: 94,
|
|
250
|
-
S: this,
|
|
251
|
-
A: [
|
|
252
|
-
"this._wsMuxer",
|
|
253
|
-
""
|
|
254
|
-
]
|
|
255
|
-
});
|
|
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", ""] });
|
|
256
209
|
log("sending...", {
|
|
257
210
|
peerKey: this._identity.peerKey,
|
|
258
211
|
payload: protocol.getPayloadType(message)
|
|
259
|
-
}, {
|
|
260
|
-
F: __dxlog_file3,
|
|
261
|
-
L: 95,
|
|
262
|
-
S: this,
|
|
263
|
-
C: (f, a) => f(...a)
|
|
264
|
-
});
|
|
212
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 74, S: this });
|
|
265
213
|
this._messagesSent++;
|
|
266
214
|
if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {
|
|
267
215
|
const binary = buf.toBinary(MessageSchema, message);
|
|
@@ -270,12 +218,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
270
218
|
byteLength: binary.byteLength,
|
|
271
219
|
serviceId: message.serviceId,
|
|
272
220
|
payload: protocol.getPayloadType(message)
|
|
273
|
-
}, {
|
|
274
|
-
F: __dxlog_file3,
|
|
275
|
-
L: 100,
|
|
276
|
-
S: this,
|
|
277
|
-
C: (f, a) => f(...a)
|
|
278
|
-
});
|
|
221
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 82, S: this });
|
|
279
222
|
return;
|
|
280
223
|
}
|
|
281
224
|
this._recordBytes(binary.byteLength, 0);
|
|
@@ -283,12 +226,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
283
226
|
} else {
|
|
284
227
|
const binary = buf.toBinary(MessageSchema, message);
|
|
285
228
|
this._recordBytes(binary.byteLength, 0);
|
|
286
|
-
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
287
|
-
F: __dxlog_file3,
|
|
288
|
-
L: 113,
|
|
289
|
-
S: this,
|
|
290
|
-
C: (f, a) => f(...a)
|
|
291
|
-
}));
|
|
229
|
+
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 95, S: this }));
|
|
292
230
|
}
|
|
293
231
|
}
|
|
294
232
|
async _open() {
|
|
@@ -300,17 +238,14 @@ var EdgeWsConnection = class extends Resource {
|
|
|
300
238
|
this._connectionInfo.protocolHeader
|
|
301
239
|
] : [
|
|
302
240
|
...baseProtocols
|
|
303
|
-
]
|
|
241
|
+
], this._connectionInfo.headers ? {
|
|
242
|
+
headers: this._connectionInfo.headers
|
|
243
|
+
} : void 0);
|
|
304
244
|
const muxer = new WebSocketMuxer(this._ws);
|
|
305
245
|
this._wsMuxer = muxer;
|
|
306
246
|
this._ws.onopen = () => {
|
|
307
247
|
if (this.isOpen) {
|
|
308
|
-
log("connected", void 0, {
|
|
309
|
-
F: __dxlog_file3,
|
|
310
|
-
L: 130,
|
|
311
|
-
S: this,
|
|
312
|
-
C: (f, a) => f(...a)
|
|
313
|
-
});
|
|
248
|
+
log("connected", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 114, S: this });
|
|
314
249
|
this._openTimestamp = Date.now();
|
|
315
250
|
this._callbacks.onConnected();
|
|
316
251
|
this._scheduleHeartbeats();
|
|
@@ -318,12 +253,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
318
253
|
} else {
|
|
319
254
|
log.verbose("connected after becoming inactive", {
|
|
320
255
|
currentIdentity: this._identity
|
|
321
|
-
}, {
|
|
322
|
-
F: __dxlog_file3,
|
|
323
|
-
L: 136,
|
|
324
|
-
S: this,
|
|
325
|
-
C: (f, a) => f(...a)
|
|
326
|
-
});
|
|
256
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 120, S: this });
|
|
327
257
|
}
|
|
328
258
|
};
|
|
329
259
|
this._ws.onclose = (event) => {
|
|
@@ -331,12 +261,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
331
261
|
log.warn("server disconnected", {
|
|
332
262
|
code: event.code,
|
|
333
263
|
reason: event.reason
|
|
334
|
-
}, {
|
|
335
|
-
F: __dxlog_file3,
|
|
336
|
-
L: 141,
|
|
337
|
-
S: this,
|
|
338
|
-
C: (f, a) => f(...a)
|
|
339
|
-
});
|
|
264
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 127, S: this });
|
|
340
265
|
this._callbacks.onRestartRequired();
|
|
341
266
|
muxer.destroy();
|
|
342
267
|
}
|
|
@@ -346,34 +271,19 @@ var EdgeWsConnection = class extends Resource {
|
|
|
346
271
|
log.warn("edge connection socket error", {
|
|
347
272
|
error: event.error,
|
|
348
273
|
info: event.message
|
|
349
|
-
}, {
|
|
350
|
-
F: __dxlog_file3,
|
|
351
|
-
L: 148,
|
|
352
|
-
S: this,
|
|
353
|
-
C: (f, a) => f(...a)
|
|
354
|
-
});
|
|
274
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 137, S: this });
|
|
355
275
|
this._callbacks.onRestartRequired();
|
|
356
276
|
} else {
|
|
357
277
|
log.verbose("error ignored on closed connection", {
|
|
358
278
|
error: event.error
|
|
359
|
-
}, {
|
|
360
|
-
F: __dxlog_file3,
|
|
361
|
-
L: 151,
|
|
362
|
-
S: this,
|
|
363
|
-
C: (f, a) => f(...a)
|
|
364
|
-
});
|
|
279
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 143, S: this });
|
|
365
280
|
}
|
|
366
281
|
};
|
|
367
282
|
this._ws.onmessage = async (event) => {
|
|
368
283
|
if (!this.isOpen) {
|
|
369
284
|
log.verbose("message ignored on closed connection", {
|
|
370
285
|
event: event.type
|
|
371
|
-
}, {
|
|
372
|
-
F: __dxlog_file3,
|
|
373
|
-
L: 159,
|
|
374
|
-
S: this,
|
|
375
|
-
C: (f, a) => f(...a)
|
|
376
|
-
});
|
|
286
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 152, S: this });
|
|
377
287
|
return;
|
|
378
288
|
}
|
|
379
289
|
this._lastReceivedMessageTimestamp = Date.now();
|
|
@@ -396,12 +306,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
396
306
|
log("received", {
|
|
397
307
|
from: message.source,
|
|
398
308
|
payload: protocol.getPayloadType(message)
|
|
399
|
-
}, {
|
|
400
|
-
F: __dxlog_file3,
|
|
401
|
-
L: 185,
|
|
402
|
-
S: this,
|
|
403
|
-
C: (f, a) => f(...a)
|
|
404
|
-
});
|
|
309
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 175, S: this });
|
|
405
310
|
this._callbacks.onMessage(message);
|
|
406
311
|
}
|
|
407
312
|
};
|
|
@@ -420,24 +325,11 @@ var EdgeWsConnection = class extends Resource {
|
|
|
420
325
|
}
|
|
421
326
|
log.warn("error closing websocket", {
|
|
422
327
|
err
|
|
423
|
-
}, {
|
|
424
|
-
F: __dxlog_file3,
|
|
425
|
-
L: 203,
|
|
426
|
-
S: this,
|
|
427
|
-
C: (f, a) => f(...a)
|
|
428
|
-
});
|
|
328
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 194, S: this });
|
|
429
329
|
}
|
|
430
330
|
}
|
|
431
331
|
_scheduleHeartbeats() {
|
|
432
|
-
invariant3(this._ws, void 0, {
|
|
433
|
-
F: __dxlog_file3,
|
|
434
|
-
L: 208,
|
|
435
|
-
S: this,
|
|
436
|
-
A: [
|
|
437
|
-
"this._ws",
|
|
438
|
-
""
|
|
439
|
-
]
|
|
440
|
-
});
|
|
332
|
+
invariant3(this._ws, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 200, S: this, A: ["this._ws", ""] });
|
|
441
333
|
scheduleTaskInterval(this._ctx, async () => {
|
|
442
334
|
this._pingTimestamp = Date.now();
|
|
443
335
|
this._ws?.send("__ping__");
|
|
@@ -451,21 +343,13 @@ var EdgeWsConnection = class extends Resource {
|
|
|
451
343
|
return;
|
|
452
344
|
}
|
|
453
345
|
void this._inactivityTimeoutCtx?.dispose();
|
|
454
|
-
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
455
|
-
F: __dxlog_file3,
|
|
456
|
-
L: 229
|
|
457
|
-
});
|
|
346
|
+
this._inactivityTimeoutCtx = new Context(void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 216 });
|
|
458
347
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
459
348
|
if (this.isOpen) {
|
|
460
349
|
if (Date.now() - this._lastReceivedMessageTimestamp > SIGNAL_KEEPALIVE_TIMEOUT) {
|
|
461
350
|
log.warn("restart due to inactivity timeout", {
|
|
462
351
|
lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
|
|
463
|
-
}, {
|
|
464
|
-
F: __dxlog_file3,
|
|
465
|
-
L: 235,
|
|
466
|
-
S: this,
|
|
467
|
-
C: (f, a) => f(...a)
|
|
468
|
-
});
|
|
352
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 220, S: this });
|
|
469
353
|
this._callbacks.onRestartRequired();
|
|
470
354
|
} else {
|
|
471
355
|
this._rescheduleHeartbeatTimeout();
|
|
@@ -540,13 +424,13 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
540
424
|
};
|
|
541
425
|
|
|
542
426
|
// src/edge-client.ts
|
|
427
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
543
428
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
544
429
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
545
430
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
546
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;
|
|
547
432
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
548
433
|
}
|
|
549
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
550
434
|
var DEFAULT_TIMEOUT = 1e4;
|
|
551
435
|
var STATUS_REFRESH_INTERVAL = 1e3;
|
|
552
436
|
var EdgeClient = class extends Resource2 {
|
|
@@ -598,12 +482,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
598
482
|
log2("Edge identity changed", {
|
|
599
483
|
identity,
|
|
600
484
|
oldIdentity: this._identity
|
|
601
|
-
}, {
|
|
602
|
-
F: __dxlog_file4,
|
|
603
|
-
L: 118,
|
|
604
|
-
S: this,
|
|
605
|
-
C: (f, a) => f(...a)
|
|
606
|
-
});
|
|
485
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 74, S: this });
|
|
607
486
|
this._identity = identity;
|
|
608
487
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
609
488
|
void this._persistentLifecycle.scheduleRestart();
|
|
@@ -613,14 +492,9 @@ var EdgeClient = class extends Resource2 {
|
|
|
613
492
|
* Send message.
|
|
614
493
|
* NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
|
|
615
494
|
*/
|
|
616
|
-
async send(message) {
|
|
495
|
+
async send(ctx, message) {
|
|
617
496
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
618
|
-
log2("waiting for websocket", void 0, {
|
|
619
|
-
F: __dxlog_file4,
|
|
620
|
-
L: 131,
|
|
621
|
-
S: this,
|
|
622
|
-
C: (f, a) => f(...a)
|
|
623
|
-
});
|
|
497
|
+
log2("waiting for websocket", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 88, S: this });
|
|
624
498
|
await this._ready.wait({
|
|
625
499
|
timeout: this._config.timeout ?? DEFAULT_TIMEOUT
|
|
626
500
|
});
|
|
@@ -631,6 +505,14 @@ var EdgeClient = class extends Resource2 {
|
|
|
631
505
|
if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
|
|
632
506
|
throw new EdgeIdentityChangedError();
|
|
633
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
|
+
}
|
|
634
516
|
this._currentConnection.send(message);
|
|
635
517
|
}
|
|
636
518
|
onMessage(listener) {
|
|
@@ -645,12 +527,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
645
527
|
try {
|
|
646
528
|
listener();
|
|
647
529
|
} catch (error) {
|
|
648
|
-
log2.catch(error, void 0, {
|
|
649
|
-
F: __dxlog_file4,
|
|
650
|
-
L: 164,
|
|
651
|
-
S: this,
|
|
652
|
-
C: (f, a) => f(...a)
|
|
653
|
-
});
|
|
530
|
+
log2.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 123, S: this });
|
|
654
531
|
}
|
|
655
532
|
}
|
|
656
533
|
});
|
|
@@ -663,21 +540,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
663
540
|
async _open() {
|
|
664
541
|
log2("opening...", {
|
|
665
542
|
info: this.info
|
|
666
|
-
}, {
|
|
667
|
-
F: __dxlog_file4,
|
|
668
|
-
L: 177,
|
|
669
|
-
S: this,
|
|
670
|
-
C: (f, a) => f(...a)
|
|
671
|
-
});
|
|
543
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 133, S: this });
|
|
672
544
|
this._persistentLifecycle.open().catch((err) => {
|
|
673
545
|
log2.warn("Error while opening connection", {
|
|
674
546
|
err
|
|
675
|
-
}, {
|
|
676
|
-
F: __dxlog_file4,
|
|
677
|
-
L: 179,
|
|
678
|
-
S: this,
|
|
679
|
-
C: (f, a) => f(...a)
|
|
680
|
-
});
|
|
547
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 137, S: this });
|
|
681
548
|
});
|
|
682
549
|
scheduleTaskInterval2(this._ctx, async () => {
|
|
683
550
|
if (!this._currentConnection) {
|
|
@@ -692,12 +559,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
692
559
|
async _close() {
|
|
693
560
|
log2("closing...", {
|
|
694
561
|
peerKey: this._identity.peerKey
|
|
695
|
-
}, {
|
|
696
|
-
F: __dxlog_file4,
|
|
697
|
-
L: 199,
|
|
698
|
-
S: this,
|
|
699
|
-
C: (f, a) => f(...a)
|
|
700
|
-
});
|
|
562
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 152, S: this });
|
|
701
563
|
this._closeCurrentConnection();
|
|
702
564
|
await this._persistentLifecycle.close();
|
|
703
565
|
}
|
|
@@ -709,12 +571,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
709
571
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
710
572
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
711
573
|
if (this._identity !== identity) {
|
|
712
|
-
log2("identity changed during auth header request", void 0, {
|
|
713
|
-
F: __dxlog_file4,
|
|
714
|
-
L: 213,
|
|
715
|
-
S: this,
|
|
716
|
-
C: (f, a) => f(...a)
|
|
717
|
-
});
|
|
574
|
+
log2("identity changed during auth header request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 166, S: this });
|
|
718
575
|
return void 0;
|
|
719
576
|
}
|
|
720
577
|
const restartRequired = new Trigger();
|
|
@@ -722,27 +579,20 @@ var EdgeClient = class extends Resource2 {
|
|
|
722
579
|
log2("Opening websocket", {
|
|
723
580
|
url: url.toString(),
|
|
724
581
|
protocolHeader
|
|
725
|
-
}, {
|
|
726
|
-
F: __dxlog_file4,
|
|
727
|
-
L: 219,
|
|
728
|
-
S: this,
|
|
729
|
-
C: (f, a) => f(...a)
|
|
730
|
-
});
|
|
582
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 171, S: this });
|
|
731
583
|
const connection = new EdgeWsConnection(identity, {
|
|
732
584
|
url,
|
|
733
|
-
protocolHeader
|
|
585
|
+
protocolHeader,
|
|
586
|
+
headers: this._config.clientTag ? {
|
|
587
|
+
"X-DXOS-Client-Tag": this._config.clientTag
|
|
588
|
+
} : void 0
|
|
734
589
|
}, {
|
|
735
590
|
onConnected: () => {
|
|
736
591
|
if (this._isActive(connection)) {
|
|
737
592
|
this._ready.wake();
|
|
738
593
|
this._notifyReconnected();
|
|
739
594
|
} else {
|
|
740
|
-
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
741
|
-
F: __dxlog_file4,
|
|
742
|
-
L: 229,
|
|
743
|
-
S: this,
|
|
744
|
-
C: (f, a) => f(...a)
|
|
745
|
-
});
|
|
595
|
+
log2.verbose("connected callback ignored, because connection is not active", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 187, S: this });
|
|
746
596
|
}
|
|
747
597
|
},
|
|
748
598
|
onRestartRequired: () => {
|
|
@@ -750,12 +600,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
750
600
|
this._closeCurrentConnection();
|
|
751
601
|
void this._persistentLifecycle.scheduleRestart();
|
|
752
602
|
} else {
|
|
753
|
-
log2.verbose("restart requested by inactive connection", void 0, {
|
|
754
|
-
F: __dxlog_file4,
|
|
755
|
-
L: 237,
|
|
756
|
-
S: this,
|
|
757
|
-
C: (f, a) => f(...a)
|
|
758
|
-
});
|
|
603
|
+
log2.verbose("restart requested by inactive connection", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 195, S: this });
|
|
759
604
|
}
|
|
760
605
|
restartRequired.wake();
|
|
761
606
|
},
|
|
@@ -766,12 +611,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
766
611
|
log2.verbose("ignored a message on inactive connection", {
|
|
767
612
|
from: message.source,
|
|
768
613
|
type: message.payload?.typeUrl
|
|
769
|
-
}, {
|
|
770
|
-
F: __dxlog_file4,
|
|
771
|
-
L: 245,
|
|
772
|
-
S: this,
|
|
773
|
-
C: (f, a) => f(...a)
|
|
774
|
-
});
|
|
614
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 203, S: this });
|
|
775
615
|
}
|
|
776
616
|
}
|
|
777
617
|
});
|
|
@@ -803,12 +643,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
803
643
|
} catch (err) {
|
|
804
644
|
log2.error("ws reconnect listener failed", {
|
|
805
645
|
err
|
|
806
|
-
}, {
|
|
807
|
-
F: __dxlog_file4,
|
|
808
|
-
L: 280,
|
|
809
|
-
S: this,
|
|
810
|
-
C: (f, a) => f(...a)
|
|
811
|
-
});
|
|
646
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 238, S: this });
|
|
812
647
|
}
|
|
813
648
|
}
|
|
814
649
|
}
|
|
@@ -820,12 +655,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
820
655
|
log2.error("ws incoming message processing failed", {
|
|
821
656
|
err,
|
|
822
657
|
payload: protocol.getPayloadType(message)
|
|
823
|
-
}, {
|
|
824
|
-
F: __dxlog_file4,
|
|
825
|
-
L: 290,
|
|
826
|
-
S: this,
|
|
827
|
-
C: (f, a) => f(...a)
|
|
828
|
-
});
|
|
658
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 249, S: this });
|
|
829
659
|
}
|
|
830
660
|
}
|
|
831
661
|
}
|
|
@@ -841,12 +671,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
841
671
|
log2.warn("no auth challenge from edge", {
|
|
842
672
|
status: response.status,
|
|
843
673
|
statusText: response.statusText
|
|
844
|
-
}, {
|
|
845
|
-
F: __dxlog_file4,
|
|
846
|
-
L: 302,
|
|
847
|
-
S: this,
|
|
848
|
-
C: (f, a) => f(...a)
|
|
849
|
-
});
|
|
674
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 265, S: this });
|
|
850
675
|
return void 0;
|
|
851
676
|
}
|
|
852
677
|
}
|
|
@@ -866,11 +691,11 @@ import * as HttpClient from "@effect/platform/HttpClient";
|
|
|
866
691
|
import * as Effect2 from "effect/Effect";
|
|
867
692
|
import * as Function from "effect/Function";
|
|
868
693
|
import { sleep } from "@dxos/async";
|
|
869
|
-
import {
|
|
694
|
+
import { TRACE_SPAN_ATTRIBUTE as TRACE_SPAN_ATTRIBUTE2 } from "@dxos/context";
|
|
870
695
|
import { runAndForwardErrors } from "@dxos/effect";
|
|
871
696
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
872
697
|
import { log as log4 } from "@dxos/log";
|
|
873
|
-
import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
698
|
+
import { EDGE_CLIENT_TAG_HEADER, EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
874
699
|
import { createUrl } from "@dxos/util";
|
|
875
700
|
|
|
876
701
|
// src/http-client.ts
|
|
@@ -904,12 +729,7 @@ var withRetryConfig = (effect) => Effect.gen(function* () {
|
|
|
904
729
|
var withLogging = (effect) => effect.pipe(Effect.tap((res) => {
|
|
905
730
|
log3.info("response", {
|
|
906
731
|
status: res.status
|
|
907
|
-
}, {
|
|
908
|
-
F: __dxlog_file5,
|
|
909
|
-
L: 66,
|
|
910
|
-
S: void 0,
|
|
911
|
-
C: (f, a) => f(...a)
|
|
912
|
-
});
|
|
732
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 31, S: void 0 });
|
|
913
733
|
}));
|
|
914
734
|
var encodeAuthHeader = (challenge) => {
|
|
915
735
|
const encodedChallenge = Buffer.from(challenge).toString("base64");
|
|
@@ -922,23 +742,21 @@ var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
|
922
742
|
var DEFAULT_RETRY_JITTER = 500;
|
|
923
743
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
924
744
|
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
745
|
+
var LEGACY_CORS_PROXY_URL = "https://cors-proxy.dxos.workers.dev";
|
|
925
746
|
var EdgeHttpClient = class {
|
|
926
747
|
_baseUrl;
|
|
748
|
+
_clientTag;
|
|
927
749
|
_edgeIdentity;
|
|
928
750
|
/**
|
|
929
751
|
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
930
752
|
*/
|
|
931
753
|
_authHeader;
|
|
932
|
-
constructor(baseUrl) {
|
|
754
|
+
constructor(baseUrl, options) {
|
|
933
755
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
756
|
+
this._clientTag = options?.clientTag;
|
|
934
757
|
log4("created", {
|
|
935
758
|
url: this._baseUrl
|
|
936
|
-
}, {
|
|
937
|
-
F: __dxlog_file6,
|
|
938
|
-
L: 106,
|
|
939
|
-
S: this,
|
|
940
|
-
C: (f, a) => f(...a)
|
|
941
|
-
});
|
|
759
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 37, S: this });
|
|
942
760
|
}
|
|
943
761
|
get baseUrl() {
|
|
944
762
|
return this._baseUrl;
|
|
@@ -952,8 +770,8 @@ var EdgeHttpClient = class {
|
|
|
952
770
|
//
|
|
953
771
|
// Status
|
|
954
772
|
//
|
|
955
|
-
async getStatus(args) {
|
|
956
|
-
return this._call(new URL("/status", this.baseUrl), {
|
|
773
|
+
async getStatus(ctx, args) {
|
|
774
|
+
return this._call(ctx, new URL("/status", this.baseUrl), {
|
|
957
775
|
...args,
|
|
958
776
|
method: "GET",
|
|
959
777
|
auth: true
|
|
@@ -962,15 +780,15 @@ var EdgeHttpClient = class {
|
|
|
962
780
|
//
|
|
963
781
|
// Agents
|
|
964
782
|
//
|
|
965
|
-
createAgent(body, args) {
|
|
966
|
-
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), {
|
|
967
785
|
...args,
|
|
968
786
|
method: "POST",
|
|
969
787
|
body
|
|
970
788
|
});
|
|
971
789
|
}
|
|
972
|
-
getAgentStatus(request, args) {
|
|
973
|
-
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), {
|
|
974
792
|
...args,
|
|
975
793
|
method: "GET"
|
|
976
794
|
});
|
|
@@ -978,14 +796,14 @@ var EdgeHttpClient = class {
|
|
|
978
796
|
//
|
|
979
797
|
// Credentials
|
|
980
798
|
//
|
|
981
|
-
getCredentialsForNotarization(spaceId, args) {
|
|
982
|
-
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), {
|
|
983
801
|
...args,
|
|
984
802
|
method: "GET"
|
|
985
803
|
});
|
|
986
804
|
}
|
|
987
|
-
async notarizeCredentials(spaceId, body, args) {
|
|
988
|
-
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), {
|
|
989
807
|
...args,
|
|
990
808
|
body,
|
|
991
809
|
method: "POST"
|
|
@@ -994,8 +812,8 @@ var EdgeHttpClient = class {
|
|
|
994
812
|
//
|
|
995
813
|
// Identity
|
|
996
814
|
//
|
|
997
|
-
async recoverIdentity(body, args) {
|
|
998
|
-
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), {
|
|
999
817
|
...args,
|
|
1000
818
|
body,
|
|
1001
819
|
method: "POST"
|
|
@@ -1004,8 +822,8 @@ var EdgeHttpClient = class {
|
|
|
1004
822
|
//
|
|
1005
823
|
// Invitations
|
|
1006
824
|
//
|
|
1007
|
-
async joinSpaceByInvitation(spaceId, body, args) {
|
|
1008
|
-
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), {
|
|
1009
827
|
...args,
|
|
1010
828
|
body,
|
|
1011
829
|
method: "POST"
|
|
@@ -1014,8 +832,8 @@ var EdgeHttpClient = class {
|
|
|
1014
832
|
//
|
|
1015
833
|
// OAuth and credentials
|
|
1016
834
|
//
|
|
1017
|
-
async initiateOAuthFlow(body, args) {
|
|
1018
|
-
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), {
|
|
1019
837
|
...args,
|
|
1020
838
|
body,
|
|
1021
839
|
method: "POST"
|
|
@@ -1024,8 +842,8 @@ var EdgeHttpClient = class {
|
|
|
1024
842
|
//
|
|
1025
843
|
// Spaces
|
|
1026
844
|
//
|
|
1027
|
-
async createSpace(body, args) {
|
|
1028
|
-
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), {
|
|
1029
847
|
...args,
|
|
1030
848
|
body,
|
|
1031
849
|
method: "POST"
|
|
@@ -1034,18 +852,10 @@ var EdgeHttpClient = class {
|
|
|
1034
852
|
//
|
|
1035
853
|
// Queues
|
|
1036
854
|
//
|
|
1037
|
-
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
855
|
+
async queryQueue(ctx, subspaceTag, spaceId, query, args) {
|
|
1038
856
|
const queueId = query.queueIds?.[0];
|
|
1039
|
-
invariant4(queueId, "queueId required", {
|
|
1040
|
-
|
|
1041
|
-
L: 215,
|
|
1042
|
-
S: this,
|
|
1043
|
-
A: [
|
|
1044
|
-
"queueId",
|
|
1045
|
-
"'queueId required'"
|
|
1046
|
-
]
|
|
1047
|
-
});
|
|
1048
|
-
return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
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), {
|
|
1049
859
|
after: query.after,
|
|
1050
860
|
before: query.before,
|
|
1051
861
|
limit: query.limit,
|
|
@@ -1056,8 +866,8 @@ var EdgeHttpClient = class {
|
|
|
1056
866
|
method: "GET"
|
|
1057
867
|
});
|
|
1058
868
|
}
|
|
1059
|
-
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
1060
|
-
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), {
|
|
1061
871
|
...args,
|
|
1062
872
|
body: {
|
|
1063
873
|
objects
|
|
@@ -1065,8 +875,8 @@ var EdgeHttpClient = class {
|
|
|
1065
875
|
method: "POST"
|
|
1066
876
|
});
|
|
1067
877
|
}
|
|
1068
|
-
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1069
|
-
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), {
|
|
1070
880
|
ids: objectIds.join(",")
|
|
1071
881
|
}), {
|
|
1072
882
|
...args,
|
|
@@ -1076,7 +886,7 @@ var EdgeHttpClient = class {
|
|
|
1076
886
|
//
|
|
1077
887
|
// Functions
|
|
1078
888
|
//
|
|
1079
|
-
async uploadFunction(pathParts, body, args) {
|
|
889
|
+
async uploadFunction(ctx, pathParts, body, args) {
|
|
1080
890
|
const formData = new FormData();
|
|
1081
891
|
formData.append("name", body.name ?? "");
|
|
1082
892
|
formData.append("version", body.version);
|
|
@@ -1096,20 +906,20 @@ var EdgeHttpClient = class {
|
|
|
1096
906
|
pathParts.functionId
|
|
1097
907
|
] : []
|
|
1098
908
|
].join("/");
|
|
1099
|
-
return this._call(new URL(path, this.baseUrl), {
|
|
909
|
+
return this._call(ctx, new URL(path, this.baseUrl), {
|
|
1100
910
|
...args,
|
|
1101
911
|
body: formData,
|
|
1102
912
|
method: "PUT",
|
|
1103
913
|
json: false
|
|
1104
914
|
});
|
|
1105
915
|
}
|
|
1106
|
-
async listFunctions(args) {
|
|
1107
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
916
|
+
async listFunctions(ctx, args) {
|
|
917
|
+
return this._call(ctx, new URL("/functions", this.baseUrl), {
|
|
1108
918
|
...args,
|
|
1109
919
|
method: "GET"
|
|
1110
920
|
});
|
|
1111
921
|
}
|
|
1112
|
-
async invokeFunction(params, input, args) {
|
|
922
|
+
async invokeFunction(ctx, params, input, args) {
|
|
1113
923
|
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1114
924
|
if (params.version) {
|
|
1115
925
|
url.searchParams.set("version", params.version);
|
|
@@ -1123,7 +933,7 @@ var EdgeHttpClient = class {
|
|
|
1123
933
|
if (params.subrequestsLimit) {
|
|
1124
934
|
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1125
935
|
}
|
|
1126
|
-
return this._call(url, {
|
|
936
|
+
return this._call(ctx, url, {
|
|
1127
937
|
...args,
|
|
1128
938
|
body: input,
|
|
1129
939
|
method: "POST"
|
|
@@ -1132,8 +942,8 @@ var EdgeHttpClient = class {
|
|
|
1132
942
|
//
|
|
1133
943
|
// Workflows
|
|
1134
944
|
//
|
|
1135
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1136
|
-
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), {
|
|
1137
947
|
...args,
|
|
1138
948
|
body: input,
|
|
1139
949
|
method: "POST"
|
|
@@ -1142,55 +952,111 @@ var EdgeHttpClient = class {
|
|
|
1142
952
|
//
|
|
1143
953
|
// Triggers
|
|
1144
954
|
//
|
|
1145
|
-
async getCronTriggers(spaceId) {
|
|
1146
|
-
return this._call(new URL(`/
|
|
955
|
+
async getCronTriggers(ctx, spaceId) {
|
|
956
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
1147
957
|
method: "GET"
|
|
1148
958
|
});
|
|
1149
959
|
}
|
|
1150
|
-
async forceRunCronTrigger(spaceId, triggerId) {
|
|
1151
|
-
return this._call(new URL(`/
|
|
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,
|
|
1152
975
|
method: "POST"
|
|
1153
976
|
});
|
|
1154
977
|
}
|
|
1155
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,
|
|
1001
|
+
method: "GET"
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
//
|
|
1156
1005
|
// Import/Export space.
|
|
1157
1006
|
//
|
|
1158
|
-
async importBundle(spaceId, body, args) {
|
|
1159
|
-
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), {
|
|
1160
1009
|
...args,
|
|
1161
1010
|
body,
|
|
1162
1011
|
method: "PUT"
|
|
1163
1012
|
});
|
|
1164
1013
|
}
|
|
1165
|
-
async exportBundle(spaceId, body, args) {
|
|
1166
|
-
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), {
|
|
1167
1016
|
...args,
|
|
1168
1017
|
body,
|
|
1169
1018
|
method: "POST"
|
|
1170
1019
|
});
|
|
1171
1020
|
}
|
|
1172
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
|
+
//
|
|
1173
1047
|
// Internal
|
|
1174
1048
|
//
|
|
1175
1049
|
async _fetch(url, _args) {
|
|
1176
1050
|
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1177
1051
|
}
|
|
1178
1052
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1179
|
-
async _call(url, args) {
|
|
1053
|
+
async _call(ctx, url, args) {
|
|
1180
1054
|
const shouldRetry = createRetryHandler(args);
|
|
1181
|
-
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1182
|
-
F: __dxlog_file6,
|
|
1183
|
-
L: 407
|
|
1184
|
-
});
|
|
1185
1055
|
log4("fetch", {
|
|
1186
1056
|
url,
|
|
1187
1057
|
request: args.body
|
|
1188
|
-
}, {
|
|
1189
|
-
|
|
1190
|
-
L: 408,
|
|
1191
|
-
S: this,
|
|
1192
|
-
C: (f, a) => f(...a)
|
|
1193
|
-
});
|
|
1058
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 362, S: this });
|
|
1059
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1194
1060
|
let handledAuth = false;
|
|
1195
1061
|
const tryCount = 1;
|
|
1196
1062
|
while (true) {
|
|
@@ -1202,29 +1068,16 @@ var EdgeHttpClient = class {
|
|
|
1202
1068
|
this._authHeader = await this._handleUnauthorized(response2);
|
|
1203
1069
|
}
|
|
1204
1070
|
}
|
|
1205
|
-
const request = createRequest(args, this._authHeader);
|
|
1071
|
+
const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
|
|
1206
1072
|
log4("call edge", {
|
|
1207
1073
|
url,
|
|
1208
1074
|
tryCount,
|
|
1209
1075
|
authHeader: !!this._authHeader
|
|
1210
|
-
}, {
|
|
1211
|
-
F: __dxlog_file6,
|
|
1212
|
-
L: 423,
|
|
1213
|
-
S: this,
|
|
1214
|
-
C: (f, a) => f(...a)
|
|
1215
|
-
});
|
|
1076
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 379, S: this });
|
|
1216
1077
|
const response = await fetch(url, request);
|
|
1217
1078
|
if (response.ok) {
|
|
1218
1079
|
const body2 = await response.clone().json();
|
|
1219
|
-
invariant4(body2, "Expected body to be present", {
|
|
1220
|
-
F: __dxlog_file6,
|
|
1221
|
-
L: 428,
|
|
1222
|
-
S: this,
|
|
1223
|
-
A: [
|
|
1224
|
-
"body",
|
|
1225
|
-
"'Expected body to be present'"
|
|
1226
|
-
]
|
|
1227
|
-
});
|
|
1080
|
+
invariant4(body2, "Expected body to be present", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 387, S: this, A: ["body", "'Expected body to be present'"] });
|
|
1228
1081
|
if (!("success" in body2)) {
|
|
1229
1082
|
return body2;
|
|
1230
1083
|
}
|
|
@@ -1237,44 +1090,23 @@ var EdgeHttpClient = class {
|
|
|
1237
1090
|
continue;
|
|
1238
1091
|
}
|
|
1239
1092
|
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1240
|
-
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
|
|
1241
|
-
F: __dxlog_file6,
|
|
1242
|
-
L: 444,
|
|
1243
|
-
S: this,
|
|
1244
|
-
A: [
|
|
1245
|
-
"!body?.success",
|
|
1246
|
-
"'Expected body to not be a failure response or undefined.'"
|
|
1247
|
-
]
|
|
1248
|
-
});
|
|
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.'"] });
|
|
1249
1094
|
if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
|
|
1250
1095
|
processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
|
|
1251
1096
|
} else if (body?.success === false) {
|
|
1252
1097
|
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1253
1098
|
} else {
|
|
1254
|
-
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1255
|
-
F: __dxlog_file6,
|
|
1256
|
-
L: 451,
|
|
1257
|
-
S: this,
|
|
1258
|
-
A: [
|
|
1259
|
-
"!response.ok",
|
|
1260
|
-
"'Expected response to not be ok.'"
|
|
1261
|
-
]
|
|
1262
|
-
});
|
|
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.'"] });
|
|
1263
1100
|
processingError = await EdgeCallFailedError.fromHttpFailure(response);
|
|
1264
1101
|
}
|
|
1265
1102
|
} catch (error) {
|
|
1266
1103
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1267
1104
|
}
|
|
1268
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1105
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1269
1106
|
log4.verbose("retrying edge request", {
|
|
1270
1107
|
url,
|
|
1271
1108
|
processingError
|
|
1272
|
-
}, {
|
|
1273
|
-
F: __dxlog_file6,
|
|
1274
|
-
L: 459,
|
|
1275
|
-
S: this,
|
|
1276
|
-
C: (f, a) => f(...a)
|
|
1277
|
-
});
|
|
1109
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 413, S: this });
|
|
1278
1110
|
} else {
|
|
1279
1111
|
throw processingError;
|
|
1280
1112
|
}
|
|
@@ -1282,19 +1114,14 @@ var EdgeHttpClient = class {
|
|
|
1282
1114
|
}
|
|
1283
1115
|
async _handleUnauthorized(response) {
|
|
1284
1116
|
if (!this._edgeIdentity) {
|
|
1285
|
-
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1286
|
-
F: __dxlog_file6,
|
|
1287
|
-
L: 468,
|
|
1288
|
-
S: this,
|
|
1289
|
-
C: (f, a) => f(...a)
|
|
1290
|
-
});
|
|
1117
|
+
log4.warn("unauthorized response received before identity was set", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 424, S: this });
|
|
1291
1118
|
throw await EdgeCallFailedError.fromHttpFailure(response);
|
|
1292
1119
|
}
|
|
1293
1120
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
1294
1121
|
return encodeAuthHeader(challenge);
|
|
1295
1122
|
}
|
|
1296
1123
|
};
|
|
1297
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1124
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
|
|
1298
1125
|
let requestBody;
|
|
1299
1126
|
const headers = {};
|
|
1300
1127
|
if (json) {
|
|
@@ -1306,22 +1133,36 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1306
1133
|
if (typeof requestBody === "string" && requestBody.length > WARNING_BODY_SIZE) {
|
|
1307
1134
|
log4.warn("Request with large body", {
|
|
1308
1135
|
bodySize: requestBody.length
|
|
1309
|
-
}, {
|
|
1310
|
-
F: __dxlog_file6,
|
|
1311
|
-
L: 492,
|
|
1312
|
-
S: void 0,
|
|
1313
|
-
C: (f, a) => f(...a)
|
|
1314
|
-
});
|
|
1136
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 441, S: void 0 });
|
|
1315
1137
|
}
|
|
1316
1138
|
if (authHeader) {
|
|
1317
1139
|
headers["Authorization"] = authHeader;
|
|
1318
1140
|
}
|
|
1141
|
+
if (traceHeaders) {
|
|
1142
|
+
Object.assign(headers, traceHeaders);
|
|
1143
|
+
}
|
|
1144
|
+
if (clientTag) {
|
|
1145
|
+
headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
|
|
1146
|
+
}
|
|
1319
1147
|
return {
|
|
1320
1148
|
method,
|
|
1321
1149
|
body: requestBody,
|
|
1322
1150
|
headers
|
|
1323
1151
|
};
|
|
1324
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
|
+
};
|
|
1325
1166
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1326
1167
|
if (!retry2 || retry2.count < 1) {
|
|
1327
1168
|
return async () => false;
|
|
@@ -1347,6 +1188,28 @@ var getFileMimeType = (filename) => [
|
|
|
1347
1188
|
".js",
|
|
1348
1189
|
".mjs"
|
|
1349
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
|
+
};
|
|
1350
1213
|
export {
|
|
1351
1214
|
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1352
1215
|
CLOUDFLARE_RPC_MAX_BYTES,
|
|
@@ -1366,6 +1229,7 @@ export {
|
|
|
1366
1229
|
getTypename,
|
|
1367
1230
|
handleAuthChallenge,
|
|
1368
1231
|
protocol,
|
|
1232
|
+
proxyFetchLegacy,
|
|
1369
1233
|
toUint8Array,
|
|
1370
1234
|
withLogging,
|
|
1371
1235
|
withRetry,
|