@dxos/edge-client 0.8.4-main.72ec0f3 → 0.8.4-main.765dc60934
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-VESGVCLQ.mjs → neutral/chunk-ZIQ5T3A7.mjs} +6 -40
- package/dist/lib/{browser/chunk-VESGVCLQ.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 +184 -357
- 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 +65 -33
- 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 +2 -1
- package/src/edge-http-client.ts +191 -65
- package/src/edge-ws-connection.ts +2 -1
- package/src/http-client.test.ts +3 -2
- package/src/testing/test-utils.ts +4 -4
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JTBFRYNM.mjs +0 -303
- package/dist/lib/node-esm/chunk-JTBFRYNM.mjs.map +0 -7
- package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -1363
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -186
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- /package/dist/lib/{browser → neutral}/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,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,10 +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";
|
|
695
|
+
import { runAndForwardErrors } from "@dxos/effect";
|
|
870
696
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
871
697
|
import { log as log4 } from "@dxos/log";
|
|
872
|
-
import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
698
|
+
import { EDGE_CLIENT_TAG_HEADER, EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
|
|
873
699
|
import { createUrl } from "@dxos/util";
|
|
874
700
|
|
|
875
701
|
// src/http-client.ts
|
|
@@ -903,12 +729,7 @@ var withRetryConfig = (effect) => Effect.gen(function* () {
|
|
|
903
729
|
var withLogging = (effect) => effect.pipe(Effect.tap((res) => {
|
|
904
730
|
log3.info("response", {
|
|
905
731
|
status: res.status
|
|
906
|
-
}, {
|
|
907
|
-
F: __dxlog_file5,
|
|
908
|
-
L: 66,
|
|
909
|
-
S: void 0,
|
|
910
|
-
C: (f, a) => f(...a)
|
|
911
|
-
});
|
|
732
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 31, S: void 0 });
|
|
912
733
|
}));
|
|
913
734
|
var encodeAuthHeader = (challenge) => {
|
|
914
735
|
const encodedChallenge = Buffer.from(challenge).toString("base64");
|
|
@@ -923,21 +744,18 @@ var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
|
923
744
|
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
924
745
|
var EdgeHttpClient = class {
|
|
925
746
|
_baseUrl;
|
|
747
|
+
_clientTag;
|
|
926
748
|
_edgeIdentity;
|
|
927
749
|
/**
|
|
928
750
|
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
929
751
|
*/
|
|
930
752
|
_authHeader;
|
|
931
|
-
constructor(baseUrl) {
|
|
753
|
+
constructor(baseUrl, options) {
|
|
932
754
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
755
|
+
this._clientTag = options?.clientTag;
|
|
933
756
|
log4("created", {
|
|
934
757
|
url: this._baseUrl
|
|
935
|
-
}, {
|
|
936
|
-
F: __dxlog_file6,
|
|
937
|
-
L: 107,
|
|
938
|
-
S: this,
|
|
939
|
-
C: (f, a) => f(...a)
|
|
940
|
-
});
|
|
758
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 32, S: this });
|
|
941
759
|
}
|
|
942
760
|
get baseUrl() {
|
|
943
761
|
return this._baseUrl;
|
|
@@ -951,24 +769,25 @@ var EdgeHttpClient = class {
|
|
|
951
769
|
//
|
|
952
770
|
// Status
|
|
953
771
|
//
|
|
954
|
-
async getStatus(args) {
|
|
955
|
-
return this._call(new URL("/status", this.baseUrl), {
|
|
772
|
+
async getStatus(ctx, args) {
|
|
773
|
+
return this._call(ctx, new URL("/status", this.baseUrl), {
|
|
956
774
|
...args,
|
|
957
|
-
method: "GET"
|
|
775
|
+
method: "GET",
|
|
776
|
+
auth: true
|
|
958
777
|
});
|
|
959
778
|
}
|
|
960
779
|
//
|
|
961
780
|
// Agents
|
|
962
781
|
//
|
|
963
|
-
createAgent(body, args) {
|
|
964
|
-
return this._call(new URL("/agents/create", this.baseUrl), {
|
|
782
|
+
createAgent(ctx, body, args) {
|
|
783
|
+
return this._call(ctx, new URL("/agents/create", this.baseUrl), {
|
|
965
784
|
...args,
|
|
966
785
|
method: "POST",
|
|
967
786
|
body
|
|
968
787
|
});
|
|
969
788
|
}
|
|
970
|
-
getAgentStatus(request, args) {
|
|
971
|
-
return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
789
|
+
getAgentStatus(ctx, request, args) {
|
|
790
|
+
return this._call(ctx, new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
|
|
972
791
|
...args,
|
|
973
792
|
method: "GET"
|
|
974
793
|
});
|
|
@@ -976,14 +795,14 @@ var EdgeHttpClient = class {
|
|
|
976
795
|
//
|
|
977
796
|
// Credentials
|
|
978
797
|
//
|
|
979
|
-
getCredentialsForNotarization(spaceId, args) {
|
|
980
|
-
return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
798
|
+
getCredentialsForNotarization(ctx, spaceId, args) {
|
|
799
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
981
800
|
...args,
|
|
982
801
|
method: "GET"
|
|
983
802
|
});
|
|
984
803
|
}
|
|
985
|
-
async notarizeCredentials(spaceId, body, args) {
|
|
986
|
-
await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
804
|
+
async notarizeCredentials(ctx, spaceId, body, args) {
|
|
805
|
+
await this._call(ctx, new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
|
|
987
806
|
...args,
|
|
988
807
|
body,
|
|
989
808
|
method: "POST"
|
|
@@ -992,8 +811,8 @@ var EdgeHttpClient = class {
|
|
|
992
811
|
//
|
|
993
812
|
// Identity
|
|
994
813
|
//
|
|
995
|
-
async recoverIdentity(body, args) {
|
|
996
|
-
return this._call(new URL("/identity/recover", this.baseUrl), {
|
|
814
|
+
async recoverIdentity(ctx, body, args) {
|
|
815
|
+
return this._call(ctx, new URL("/identity/recover", this.baseUrl), {
|
|
997
816
|
...args,
|
|
998
817
|
body,
|
|
999
818
|
method: "POST"
|
|
@@ -1002,8 +821,8 @@ var EdgeHttpClient = class {
|
|
|
1002
821
|
//
|
|
1003
822
|
// Invitations
|
|
1004
823
|
//
|
|
1005
|
-
async joinSpaceByInvitation(spaceId, body, args) {
|
|
1006
|
-
return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
824
|
+
async joinSpaceByInvitation(ctx, spaceId, body, args) {
|
|
825
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
|
|
1007
826
|
...args,
|
|
1008
827
|
body,
|
|
1009
828
|
method: "POST"
|
|
@@ -1012,8 +831,8 @@ var EdgeHttpClient = class {
|
|
|
1012
831
|
//
|
|
1013
832
|
// OAuth and credentials
|
|
1014
833
|
//
|
|
1015
|
-
async initiateOAuthFlow(body, args) {
|
|
1016
|
-
return this._call(new URL("/oauth/initiate", this.baseUrl), {
|
|
834
|
+
async initiateOAuthFlow(ctx, body, args) {
|
|
835
|
+
return this._call(ctx, new URL("/oauth/initiate", this.baseUrl), {
|
|
1017
836
|
...args,
|
|
1018
837
|
body,
|
|
1019
838
|
method: "POST"
|
|
@@ -1022,8 +841,8 @@ var EdgeHttpClient = class {
|
|
|
1022
841
|
//
|
|
1023
842
|
// Spaces
|
|
1024
843
|
//
|
|
1025
|
-
async createSpace(body, args) {
|
|
1026
|
-
return this._call(new URL("/spaces/create", this.baseUrl), {
|
|
844
|
+
async createSpace(ctx, body, args) {
|
|
845
|
+
return this._call(ctx, new URL("/spaces/create", this.baseUrl), {
|
|
1027
846
|
...args,
|
|
1028
847
|
body,
|
|
1029
848
|
method: "POST"
|
|
@@ -1032,9 +851,10 @@ var EdgeHttpClient = class {
|
|
|
1032
851
|
//
|
|
1033
852
|
// Queues
|
|
1034
853
|
//
|
|
1035
|
-
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
1036
|
-
const
|
|
1037
|
-
|
|
854
|
+
async queryQueue(ctx, subspaceTag, spaceId, query, args) {
|
|
855
|
+
const queueId = query.queueIds?.[0];
|
|
856
|
+
invariant4(queueId, "queueId required", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 132, S: this, A: ["queueId", "'queueId required'"] });
|
|
857
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
|
|
1038
858
|
after: query.after,
|
|
1039
859
|
before: query.before,
|
|
1040
860
|
limit: query.limit,
|
|
@@ -1045,8 +865,8 @@ var EdgeHttpClient = class {
|
|
|
1045
865
|
method: "GET"
|
|
1046
866
|
});
|
|
1047
867
|
}
|
|
1048
|
-
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
1049
|
-
return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
868
|
+
async insertIntoQueue(ctx, subspaceTag, spaceId, queueId, objects, args) {
|
|
869
|
+
return this._call(ctx, new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1050
870
|
...args,
|
|
1051
871
|
body: {
|
|
1052
872
|
objects
|
|
@@ -1054,8 +874,8 @@ var EdgeHttpClient = class {
|
|
|
1054
874
|
method: "POST"
|
|
1055
875
|
});
|
|
1056
876
|
}
|
|
1057
|
-
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1058
|
-
return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
877
|
+
async deleteFromQueue(ctx, subspaceTag, spaceId, queueId, objectIds, args) {
|
|
878
|
+
return this._call(ctx, createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
|
|
1059
879
|
ids: objectIds.join(",")
|
|
1060
880
|
}), {
|
|
1061
881
|
...args,
|
|
@@ -1065,7 +885,7 @@ var EdgeHttpClient = class {
|
|
|
1065
885
|
//
|
|
1066
886
|
// Functions
|
|
1067
887
|
//
|
|
1068
|
-
async uploadFunction(pathParts, body, args) {
|
|
888
|
+
async uploadFunction(ctx, pathParts, body, args) {
|
|
1069
889
|
const formData = new FormData();
|
|
1070
890
|
formData.append("name", body.name ?? "");
|
|
1071
891
|
formData.append("version", body.version);
|
|
@@ -1085,20 +905,20 @@ var EdgeHttpClient = class {
|
|
|
1085
905
|
pathParts.functionId
|
|
1086
906
|
] : []
|
|
1087
907
|
].join("/");
|
|
1088
|
-
return this._call(new URL(path, this.baseUrl), {
|
|
908
|
+
return this._call(ctx, new URL(path, this.baseUrl), {
|
|
1089
909
|
...args,
|
|
1090
910
|
body: formData,
|
|
1091
911
|
method: "PUT",
|
|
1092
912
|
json: false
|
|
1093
913
|
});
|
|
1094
914
|
}
|
|
1095
|
-
async listFunctions(args) {
|
|
1096
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
915
|
+
async listFunctions(ctx, args) {
|
|
916
|
+
return this._call(ctx, new URL("/functions", this.baseUrl), {
|
|
1097
917
|
...args,
|
|
1098
918
|
method: "GET"
|
|
1099
919
|
});
|
|
1100
920
|
}
|
|
1101
|
-
async invokeFunction(params, input, args) {
|
|
921
|
+
async invokeFunction(ctx, params, input, args) {
|
|
1102
922
|
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1103
923
|
if (params.version) {
|
|
1104
924
|
url.searchParams.set("version", params.version);
|
|
@@ -1112,18 +932,17 @@ var EdgeHttpClient = class {
|
|
|
1112
932
|
if (params.subrequestsLimit) {
|
|
1113
933
|
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1114
934
|
}
|
|
1115
|
-
return this._call(url, {
|
|
935
|
+
return this._call(ctx, url, {
|
|
1116
936
|
...args,
|
|
1117
937
|
body: input,
|
|
1118
|
-
method: "POST"
|
|
1119
|
-
rawResponse: true
|
|
938
|
+
method: "POST"
|
|
1120
939
|
});
|
|
1121
940
|
}
|
|
1122
941
|
//
|
|
1123
942
|
// Workflows
|
|
1124
943
|
//
|
|
1125
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1126
|
-
return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
944
|
+
async executeWorkflow(ctx, spaceId, graphId, input, args) {
|
|
945
|
+
return this._call(ctx, new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
|
|
1127
946
|
...args,
|
|
1128
947
|
body: input,
|
|
1129
948
|
method: "POST"
|
|
@@ -1132,23 +951,67 @@ var EdgeHttpClient = class {
|
|
|
1132
951
|
//
|
|
1133
952
|
// Triggers
|
|
1134
953
|
//
|
|
1135
|
-
async getCronTriggers(spaceId) {
|
|
1136
|
-
return this._call(new URL(`/
|
|
954
|
+
async getCronTriggers(ctx, spaceId) {
|
|
955
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
956
|
+
method: "GET"
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
async forceRunCronTrigger(ctx, spaceId, triggerId) {
|
|
960
|
+
return this._call(ctx, new URL(`/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
|
|
961
|
+
method: "POST"
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
//
|
|
965
|
+
// Query
|
|
966
|
+
//
|
|
967
|
+
/**
|
|
968
|
+
* Execute a QueryAST query against a space.
|
|
969
|
+
*/
|
|
970
|
+
async execQuery(ctx, spaceId, body, args) {
|
|
971
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/exec-query`, this.baseUrl), {
|
|
972
|
+
...args,
|
|
973
|
+
body,
|
|
974
|
+
method: "POST"
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
//
|
|
978
|
+
// Registry
|
|
979
|
+
//
|
|
980
|
+
/**
|
|
981
|
+
* Fetches the hydrated plugin directory from the Edge registry service.
|
|
982
|
+
* Unauthenticated; safe to call without an identity.
|
|
983
|
+
*/
|
|
984
|
+
async getRegistryPlugins(ctx, args) {
|
|
985
|
+
return this._call(ctx, new URL("/registry/plugins", this.baseUrl), {
|
|
986
|
+
...args,
|
|
987
|
+
method: "GET"
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Fetches the available release versions for a given plugin repo. `repo` is the
|
|
992
|
+
* GitHub `owner/name` form; this method takes care of URL-encoding before issuing
|
|
993
|
+
* the request. Unauthenticated; same surface area as {@link getRegistryPlugins}.
|
|
994
|
+
*
|
|
995
|
+
* Versions are returned newest first, suitable for direct rendering in a picker.
|
|
996
|
+
*/
|
|
997
|
+
async getRegistryPluginVersions(ctx, repo, args) {
|
|
998
|
+
return this._call(ctx, new URL(`/registry/plugins/${encodeURIComponent(repo)}/versions`, this.baseUrl), {
|
|
999
|
+
...args,
|
|
1137
1000
|
method: "GET"
|
|
1138
1001
|
});
|
|
1139
1002
|
}
|
|
1140
1003
|
//
|
|
1141
1004
|
// Import/Export space.
|
|
1142
1005
|
//
|
|
1143
|
-
async importBundle(spaceId, body, args) {
|
|
1144
|
-
return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1006
|
+
async importBundle(ctx, spaceId, body, args) {
|
|
1007
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1145
1008
|
...args,
|
|
1146
1009
|
body,
|
|
1147
1010
|
method: "PUT"
|
|
1148
1011
|
});
|
|
1149
1012
|
}
|
|
1150
|
-
async exportBundle(spaceId, body, args) {
|
|
1151
|
-
return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1013
|
+
async exportBundle(ctx, spaceId, body, args) {
|
|
1014
|
+
return this._call(ctx, new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1152
1015
|
...args,
|
|
1153
1016
|
body,
|
|
1154
1017
|
method: "POST"
|
|
@@ -1158,24 +1021,16 @@ var EdgeHttpClient = class {
|
|
|
1158
1021
|
// Internal
|
|
1159
1022
|
//
|
|
1160
1023
|
async _fetch(url, _args) {
|
|
1161
|
-
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"),
|
|
1024
|
+
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1162
1025
|
}
|
|
1163
1026
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1164
|
-
async _call(url, args) {
|
|
1027
|
+
async _call(ctx, url, args) {
|
|
1165
1028
|
const shouldRetry = createRetryHandler(args);
|
|
1166
|
-
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1167
|
-
F: __dxlog_file6,
|
|
1168
|
-
L: 400
|
|
1169
|
-
});
|
|
1170
1029
|
log4("fetch", {
|
|
1171
1030
|
url,
|
|
1172
1031
|
request: args.body
|
|
1173
|
-
}, {
|
|
1174
|
-
|
|
1175
|
-
L: 401,
|
|
1176
|
-
S: this,
|
|
1177
|
-
C: (f, a) => f(...a)
|
|
1178
|
-
});
|
|
1032
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 302, S: this });
|
|
1033
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1179
1034
|
let handledAuth = false;
|
|
1180
1035
|
const tryCount = 1;
|
|
1181
1036
|
while (true) {
|
|
@@ -1187,32 +1042,16 @@ var EdgeHttpClient = class {
|
|
|
1187
1042
|
this._authHeader = await this._handleUnauthorized(response2);
|
|
1188
1043
|
}
|
|
1189
1044
|
}
|
|
1190
|
-
const request = createRequest(args, this._authHeader);
|
|
1045
|
+
const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
|
|
1191
1046
|
log4("call edge", {
|
|
1192
1047
|
url,
|
|
1193
1048
|
tryCount,
|
|
1194
1049
|
authHeader: !!this._authHeader
|
|
1195
|
-
}, {
|
|
1196
|
-
F: __dxlog_file6,
|
|
1197
|
-
L: 416,
|
|
1198
|
-
S: this,
|
|
1199
|
-
C: (f, a) => f(...a)
|
|
1200
|
-
});
|
|
1050
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 319, S: this });
|
|
1201
1051
|
const response = await fetch(url, request);
|
|
1202
1052
|
if (response.ok) {
|
|
1203
1053
|
const body2 = await response.clone().json();
|
|
1204
|
-
|
|
1205
|
-
return body2;
|
|
1206
|
-
}
|
|
1207
|
-
invariant4(body2, "Expected body to be present", {
|
|
1208
|
-
F: __dxlog_file6,
|
|
1209
|
-
L: 424,
|
|
1210
|
-
S: this,
|
|
1211
|
-
A: [
|
|
1212
|
-
"body",
|
|
1213
|
-
"'Expected body to be present'"
|
|
1214
|
-
]
|
|
1215
|
-
});
|
|
1054
|
+
invariant4(body2, "Expected body to be present", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 327, S: this, A: ["body", "'Expected body to be present'"] });
|
|
1216
1055
|
if (!("success" in body2)) {
|
|
1217
1056
|
return body2;
|
|
1218
1057
|
}
|
|
@@ -1225,44 +1064,23 @@ var EdgeHttpClient = class {
|
|
|
1225
1064
|
continue;
|
|
1226
1065
|
}
|
|
1227
1066
|
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1228
|
-
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
S: this,
|
|
1232
|
-
A: [
|
|
1233
|
-
"!body?.success",
|
|
1234
|
-
"'Expected body to not be a failure response or undefined.'"
|
|
1235
|
-
]
|
|
1236
|
-
});
|
|
1237
|
-
if (body?.errorData?.type === "auth_challenge" && typeof body?.errorData?.challenge === "string") {
|
|
1238
|
-
processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
|
|
1067
|
+
invariant4(!body?.success, "Expected body to not be a failure response or undefined.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 340, S: this, A: ["!body?.success", "'Expected body to not be a failure response or undefined.'"] });
|
|
1068
|
+
if (body?.data?.type === "auth_challenge" && typeof body?.data?.challenge === "string") {
|
|
1069
|
+
processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
|
|
1239
1070
|
} else if (body?.success === false) {
|
|
1240
1071
|
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1241
1072
|
} else {
|
|
1242
|
-
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1243
|
-
F: __dxlog_file6,
|
|
1244
|
-
L: 447,
|
|
1245
|
-
S: this,
|
|
1246
|
-
A: [
|
|
1247
|
-
"!response.ok",
|
|
1248
|
-
"'Expected response to not be ok.'"
|
|
1249
|
-
]
|
|
1250
|
-
});
|
|
1073
|
+
invariant4(!response.ok, "Expected response to not be ok.", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 346, S: this, A: ["!response.ok", "'Expected response to not be ok.'"] });
|
|
1251
1074
|
processingError = await EdgeCallFailedError.fromHttpFailure(response);
|
|
1252
1075
|
}
|
|
1253
1076
|
} catch (error) {
|
|
1254
1077
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1255
1078
|
}
|
|
1256
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1079
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1257
1080
|
log4.verbose("retrying edge request", {
|
|
1258
1081
|
url,
|
|
1259
1082
|
processingError
|
|
1260
|
-
}, {
|
|
1261
|
-
F: __dxlog_file6,
|
|
1262
|
-
L: 455,
|
|
1263
|
-
S: this,
|
|
1264
|
-
C: (f, a) => f(...a)
|
|
1265
|
-
});
|
|
1083
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 353, S: this });
|
|
1266
1084
|
} else {
|
|
1267
1085
|
throw processingError;
|
|
1268
1086
|
}
|
|
@@ -1270,19 +1088,14 @@ var EdgeHttpClient = class {
|
|
|
1270
1088
|
}
|
|
1271
1089
|
async _handleUnauthorized(response) {
|
|
1272
1090
|
if (!this._edgeIdentity) {
|
|
1273
|
-
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1274
|
-
F: __dxlog_file6,
|
|
1275
|
-
L: 464,
|
|
1276
|
-
S: this,
|
|
1277
|
-
C: (f, a) => f(...a)
|
|
1278
|
-
});
|
|
1091
|
+
log4.warn("unauthorized response received before identity was set", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 364, S: this });
|
|
1279
1092
|
throw await EdgeCallFailedError.fromHttpFailure(response);
|
|
1280
1093
|
}
|
|
1281
1094
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
1282
1095
|
return encodeAuthHeader(challenge);
|
|
1283
1096
|
}
|
|
1284
1097
|
};
|
|
1285
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1098
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
|
|
1286
1099
|
let requestBody;
|
|
1287
1100
|
const headers = {};
|
|
1288
1101
|
if (json) {
|
|
@@ -1294,22 +1107,36 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1294
1107
|
if (typeof requestBody === "string" && requestBody.length > WARNING_BODY_SIZE) {
|
|
1295
1108
|
log4.warn("Request with large body", {
|
|
1296
1109
|
bodySize: requestBody.length
|
|
1297
|
-
}, {
|
|
1298
|
-
F: __dxlog_file6,
|
|
1299
|
-
L: 488,
|
|
1300
|
-
S: void 0,
|
|
1301
|
-
C: (f, a) => f(...a)
|
|
1302
|
-
});
|
|
1110
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 381, S: void 0 });
|
|
1303
1111
|
}
|
|
1304
1112
|
if (authHeader) {
|
|
1305
1113
|
headers["Authorization"] = authHeader;
|
|
1306
1114
|
}
|
|
1115
|
+
if (traceHeaders) {
|
|
1116
|
+
Object.assign(headers, traceHeaders);
|
|
1117
|
+
}
|
|
1118
|
+
if (clientTag) {
|
|
1119
|
+
headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
|
|
1120
|
+
}
|
|
1307
1121
|
return {
|
|
1308
1122
|
method,
|
|
1309
1123
|
body: requestBody,
|
|
1310
1124
|
headers
|
|
1311
1125
|
};
|
|
1312
1126
|
};
|
|
1127
|
+
var getTraceHeaders = (ctx) => {
|
|
1128
|
+
const traceCtx = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE2);
|
|
1129
|
+
if (!traceCtx) {
|
|
1130
|
+
return void 0;
|
|
1131
|
+
}
|
|
1132
|
+
const headers = {
|
|
1133
|
+
traceparent: traceCtx.traceparent
|
|
1134
|
+
};
|
|
1135
|
+
if (traceCtx.tracestate) {
|
|
1136
|
+
headers.tracestate = traceCtx.tracestate;
|
|
1137
|
+
}
|
|
1138
|
+
return headers;
|
|
1139
|
+
};
|
|
1313
1140
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1314
1141
|
if (!retry2 || retry2.count < 1) {
|
|
1315
1142
|
return async () => false;
|