@dxos/edge-client 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc
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 +208 -360
- 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 +69 -31
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-identity.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts +1 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/http-client.d.ts +2 -2
- package/dist/types/src/http-client.d.ts.map +1 -1
- package/dist/types/src/protocol.d.ts +1 -1
- package/dist/types/src/protocol.d.ts.map +1 -1
- package/dist/types/src/testing/test-server.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts +2 -2
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -32
- package/src/edge-client.test.ts +16 -11
- package/src/edge-client.ts +19 -3
- package/src/edge-http-client.test.ts +3 -2
- package/src/edge-http-client.ts +210 -66
- package/src/edge-ws-connection.ts +2 -1
- package/src/http-client.test.ts +3 -2
- package/src/http-client.ts +5 -1
- package/src/testing/test-utils.ts +4 -4
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-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 -1342
- 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
|
|
@@ -900,14 +726,11 @@ var withRetryConfig = (effect) => Effect.gen(function* () {
|
|
|
900
726
|
const config = yield* HttpConfig;
|
|
901
727
|
return yield* withRetry(effect, config);
|
|
902
728
|
});
|
|
903
|
-
var withLogging = (effect) => effect.pipe(Effect.tap((res) =>
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
F: __dxlog_file5,
|
|
907
|
-
|
|
908
|
-
S: void 0,
|
|
909
|
-
C: (f, a) => f(...a)
|
|
910
|
-
})));
|
|
729
|
+
var withLogging = (effect) => effect.pipe(Effect.tap((res) => {
|
|
730
|
+
log3.info("response", {
|
|
731
|
+
status: res.status
|
|
732
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 31, S: void 0 });
|
|
733
|
+
}));
|
|
911
734
|
var encodeAuthHeader = (challenge) => {
|
|
912
735
|
const encodedChallenge = Buffer.from(challenge).toString("base64");
|
|
913
736
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
@@ -921,21 +744,18 @@ var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
|
921
744
|
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
922
745
|
var EdgeHttpClient = class {
|
|
923
746
|
_baseUrl;
|
|
747
|
+
_clientTag;
|
|
924
748
|
_edgeIdentity;
|
|
925
749
|
/**
|
|
926
750
|
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
927
751
|
*/
|
|
928
752
|
_authHeader;
|
|
929
|
-
constructor(baseUrl) {
|
|
753
|
+
constructor(baseUrl, options) {
|
|
930
754
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
755
|
+
this._clientTag = options?.clientTag;
|
|
931
756
|
log4("created", {
|
|
932
757
|
url: this._baseUrl
|
|
933
|
-
}, {
|
|
934
|
-
F: __dxlog_file6,
|
|
935
|
-
L: 101,
|
|
936
|
-
S: this,
|
|
937
|
-
C: (f, a) => f(...a)
|
|
938
|
-
});
|
|
758
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 32, S: this });
|
|
939
759
|
}
|
|
940
760
|
get baseUrl() {
|
|
941
761
|
return this._baseUrl;
|
|
@@ -949,24 +769,25 @@ var EdgeHttpClient = class {
|
|
|
949
769
|
//
|
|
950
770
|
// Status
|
|
951
771
|
//
|
|
952
|
-
async getStatus(args) {
|
|
953
|
-
return this._call(new URL("/status", this.baseUrl), {
|
|
772
|
+
async getStatus(ctx, args) {
|
|
773
|
+
return this._call(ctx, new URL("/status", this.baseUrl), {
|
|
954
774
|
...args,
|
|
955
|
-
method: "GET"
|
|
775
|
+
method: "GET",
|
|
776
|
+
auth: true
|
|
956
777
|
});
|
|
957
778
|
}
|
|
958
779
|
//
|
|
959
780
|
// Agents
|
|
960
781
|
//
|
|
961
|
-
createAgent(body, args) {
|
|
962
|
-
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), {
|
|
963
784
|
...args,
|
|
964
785
|
method: "POST",
|
|
965
786
|
body
|
|
966
787
|
});
|
|
967
788
|
}
|
|
968
|
-
getAgentStatus(request, args) {
|
|
969
|
-
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), {
|
|
970
791
|
...args,
|
|
971
792
|
method: "GET"
|
|
972
793
|
});
|
|
@@ -974,14 +795,14 @@ var EdgeHttpClient = class {
|
|
|
974
795
|
//
|
|
975
796
|
// Credentials
|
|
976
797
|
//
|
|
977
|
-
getCredentialsForNotarization(spaceId, args) {
|
|
978
|
-
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), {
|
|
979
800
|
...args,
|
|
980
801
|
method: "GET"
|
|
981
802
|
});
|
|
982
803
|
}
|
|
983
|
-
async notarizeCredentials(spaceId, body, args) {
|
|
984
|
-
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), {
|
|
985
806
|
...args,
|
|
986
807
|
body,
|
|
987
808
|
method: "POST"
|
|
@@ -990,8 +811,8 @@ var EdgeHttpClient = class {
|
|
|
990
811
|
//
|
|
991
812
|
// Identity
|
|
992
813
|
//
|
|
993
|
-
async recoverIdentity(body, args) {
|
|
994
|
-
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), {
|
|
995
816
|
...args,
|
|
996
817
|
body,
|
|
997
818
|
method: "POST"
|
|
@@ -1000,8 +821,8 @@ var EdgeHttpClient = class {
|
|
|
1000
821
|
//
|
|
1001
822
|
// Invitations
|
|
1002
823
|
//
|
|
1003
|
-
async joinSpaceByInvitation(spaceId, body, args) {
|
|
1004
|
-
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), {
|
|
1005
826
|
...args,
|
|
1006
827
|
body,
|
|
1007
828
|
method: "POST"
|
|
@@ -1010,8 +831,8 @@ var EdgeHttpClient = class {
|
|
|
1010
831
|
//
|
|
1011
832
|
// OAuth and credentials
|
|
1012
833
|
//
|
|
1013
|
-
async initiateOAuthFlow(body, args) {
|
|
1014
|
-
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), {
|
|
1015
836
|
...args,
|
|
1016
837
|
body,
|
|
1017
838
|
method: "POST"
|
|
@@ -1020,8 +841,8 @@ var EdgeHttpClient = class {
|
|
|
1020
841
|
//
|
|
1021
842
|
// Spaces
|
|
1022
843
|
//
|
|
1023
|
-
async createSpace(body, args) {
|
|
1024
|
-
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), {
|
|
1025
846
|
...args,
|
|
1026
847
|
body,
|
|
1027
848
|
method: "POST"
|
|
@@ -1030,9 +851,10 @@ var EdgeHttpClient = class {
|
|
|
1030
851
|
//
|
|
1031
852
|
// Queues
|
|
1032
853
|
//
|
|
1033
|
-
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
1034
|
-
const
|
|
1035
|
-
|
|
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), {
|
|
1036
858
|
after: query.after,
|
|
1037
859
|
before: query.before,
|
|
1038
860
|
limit: query.limit,
|
|
@@ -1043,8 +865,8 @@ var EdgeHttpClient = class {
|
|
|
1043
865
|
method: "GET"
|
|
1044
866
|
});
|
|
1045
867
|
}
|
|
1046
|
-
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
1047
|
-
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), {
|
|
1048
870
|
...args,
|
|
1049
871
|
body: {
|
|
1050
872
|
objects
|
|
@@ -1052,8 +874,8 @@ var EdgeHttpClient = class {
|
|
|
1052
874
|
method: "POST"
|
|
1053
875
|
});
|
|
1054
876
|
}
|
|
1055
|
-
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
1056
|
-
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), {
|
|
1057
879
|
ids: objectIds.join(",")
|
|
1058
880
|
}), {
|
|
1059
881
|
...args,
|
|
@@ -1063,12 +885,13 @@ var EdgeHttpClient = class {
|
|
|
1063
885
|
//
|
|
1064
886
|
// Functions
|
|
1065
887
|
//
|
|
1066
|
-
async uploadFunction(pathParts, body, args) {
|
|
888
|
+
async uploadFunction(ctx, pathParts, body, args) {
|
|
1067
889
|
const formData = new FormData();
|
|
1068
890
|
formData.append("name", body.name ?? "");
|
|
1069
891
|
formData.append("version", body.version);
|
|
1070
892
|
formData.append("ownerPublicKey", body.ownerPublicKey);
|
|
1071
893
|
formData.append("entryPoint", body.entryPoint);
|
|
894
|
+
body.runtime && formData.append("runtime", body.runtime);
|
|
1072
895
|
for (const [filename, content] of Object.entries(body.assets)) {
|
|
1073
896
|
formData.append("assets", new Blob([
|
|
1074
897
|
content
|
|
@@ -1082,20 +905,20 @@ var EdgeHttpClient = class {
|
|
|
1082
905
|
pathParts.functionId
|
|
1083
906
|
] : []
|
|
1084
907
|
].join("/");
|
|
1085
|
-
return this._call(new URL(path, this.baseUrl), {
|
|
908
|
+
return this._call(ctx, new URL(path, this.baseUrl), {
|
|
1086
909
|
...args,
|
|
1087
910
|
body: formData,
|
|
1088
911
|
method: "PUT",
|
|
1089
912
|
json: false
|
|
1090
913
|
});
|
|
1091
914
|
}
|
|
1092
|
-
async listFunctions(args) {
|
|
1093
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
915
|
+
async listFunctions(ctx, args) {
|
|
916
|
+
return this._call(ctx, new URL("/functions", this.baseUrl), {
|
|
1094
917
|
...args,
|
|
1095
918
|
method: "GET"
|
|
1096
919
|
});
|
|
1097
920
|
}
|
|
1098
|
-
async invokeFunction(params, input, args) {
|
|
921
|
+
async invokeFunction(ctx, params, input, args) {
|
|
1099
922
|
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1100
923
|
if (params.version) {
|
|
1101
924
|
url.searchParams.set("version", params.version);
|
|
@@ -1109,18 +932,17 @@ var EdgeHttpClient = class {
|
|
|
1109
932
|
if (params.subrequestsLimit) {
|
|
1110
933
|
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1111
934
|
}
|
|
1112
|
-
return this._call(url, {
|
|
935
|
+
return this._call(ctx, url, {
|
|
1113
936
|
...args,
|
|
1114
937
|
body: input,
|
|
1115
|
-
method: "POST"
|
|
1116
|
-
rawResponse: true
|
|
938
|
+
method: "POST"
|
|
1117
939
|
});
|
|
1118
940
|
}
|
|
1119
941
|
//
|
|
1120
942
|
// Workflows
|
|
1121
943
|
//
|
|
1122
|
-
async executeWorkflow(spaceId, graphId, input, args) {
|
|
1123
|
-
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), {
|
|
1124
946
|
...args,
|
|
1125
947
|
body: input,
|
|
1126
948
|
method: "POST"
|
|
@@ -1129,23 +951,67 @@ var EdgeHttpClient = class {
|
|
|
1129
951
|
//
|
|
1130
952
|
// Triggers
|
|
1131
953
|
//
|
|
1132
|
-
async getCronTriggers(spaceId) {
|
|
1133
|
-
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,
|
|
1134
1000
|
method: "GET"
|
|
1135
1001
|
});
|
|
1136
1002
|
}
|
|
1137
1003
|
//
|
|
1138
1004
|
// Import/Export space.
|
|
1139
1005
|
//
|
|
1140
|
-
async importBundle(spaceId, body, args) {
|
|
1141
|
-
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), {
|
|
1142
1008
|
...args,
|
|
1143
1009
|
body,
|
|
1144
1010
|
method: "PUT"
|
|
1145
1011
|
});
|
|
1146
1012
|
}
|
|
1147
|
-
async exportBundle(spaceId, body, args) {
|
|
1148
|
-
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), {
|
|
1149
1015
|
...args,
|
|
1150
1016
|
body,
|
|
1151
1017
|
method: "POST"
|
|
@@ -1154,94 +1020,67 @@ var EdgeHttpClient = class {
|
|
|
1154
1020
|
//
|
|
1155
1021
|
// Internal
|
|
1156
1022
|
//
|
|
1157
|
-
async _fetch(url,
|
|
1158
|
-
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"),
|
|
1023
|
+
async _fetch(url, _args) {
|
|
1024
|
+
return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), runAndForwardErrors);
|
|
1159
1025
|
}
|
|
1160
1026
|
// TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
|
|
1161
|
-
async _call(url, args) {
|
|
1027
|
+
async _call(ctx, url, args) {
|
|
1162
1028
|
const shouldRetry = createRetryHandler(args);
|
|
1163
|
-
const requestContext = args.context ?? Context3.default(void 0, {
|
|
1164
|
-
F: __dxlog_file6,
|
|
1165
|
-
L: 393
|
|
1166
|
-
});
|
|
1167
1029
|
log4("fetch", {
|
|
1168
1030
|
url,
|
|
1169
1031
|
request: args.body
|
|
1170
|
-
}, {
|
|
1171
|
-
|
|
1172
|
-
L: 394,
|
|
1173
|
-
S: this,
|
|
1174
|
-
C: (f, a) => f(...a)
|
|
1175
|
-
});
|
|
1032
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 302, S: this });
|
|
1033
|
+
const traceHeaders = getTraceHeaders(ctx);
|
|
1176
1034
|
let handledAuth = false;
|
|
1035
|
+
const tryCount = 1;
|
|
1177
1036
|
while (true) {
|
|
1178
1037
|
let processingError = void 0;
|
|
1179
1038
|
try {
|
|
1180
|
-
|
|
1039
|
+
if (!this._authHeader && args.auth) {
|
|
1040
|
+
const response2 = await fetch(new URL(`/auth`, this.baseUrl));
|
|
1041
|
+
if (response2.status === 401) {
|
|
1042
|
+
this._authHeader = await this._handleUnauthorized(response2);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
const request = createRequest(args, this._authHeader, traceHeaders, this._clientTag);
|
|
1046
|
+
log4("call edge", {
|
|
1047
|
+
url,
|
|
1048
|
+
tryCount,
|
|
1049
|
+
authHeader: !!this._authHeader
|
|
1050
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 319, S: this });
|
|
1181
1051
|
const response = await fetch(url, request);
|
|
1182
|
-
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
1183
1052
|
if (response.ok) {
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
F: __dxlog_file6,
|
|
1189
|
-
L: 409,
|
|
1190
|
-
S: this,
|
|
1191
|
-
A: [
|
|
1192
|
-
"body",
|
|
1193
|
-
"'Expected body to be present'"
|
|
1194
|
-
]
|
|
1195
|
-
});
|
|
1196
|
-
if (!("success" in body)) {
|
|
1197
|
-
return body;
|
|
1053
|
+
const body2 = await response.clone().json();
|
|
1054
|
+
invariant4(body2, "Expected body to be present", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 327, S: this, A: ["body", "'Expected body to be present'"] });
|
|
1055
|
+
if (!("success" in body2)) {
|
|
1056
|
+
return body2;
|
|
1198
1057
|
}
|
|
1199
|
-
if (
|
|
1200
|
-
return
|
|
1058
|
+
if (body2.success) {
|
|
1059
|
+
return body2.data;
|
|
1201
1060
|
}
|
|
1202
1061
|
} else if (response.status === 401 && !handledAuth) {
|
|
1203
1062
|
this._authHeader = await this._handleUnauthorized(response);
|
|
1204
1063
|
handledAuth = true;
|
|
1205
1064
|
continue;
|
|
1206
1065
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
A: [
|
|
1212
|
-
"!body?.success",
|
|
1213
|
-
"'Expected body to not be a failure response or undefined.'"
|
|
1214
|
-
]
|
|
1215
|
-
});
|
|
1216
|
-
if (body?.errorData?.type === "auth_challenge" && typeof body?.errorData?.challenge === "string") {
|
|
1217
|
-
processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
|
|
1066
|
+
const body = response.headers.get("Content-Type") === "application/json" ? await response.clone().json() : void 0;
|
|
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);
|
|
1218
1070
|
} else if (body?.success === false) {
|
|
1219
1071
|
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1220
1072
|
} else {
|
|
1221
|
-
invariant4(!response.ok, "Expected response to not be ok.", {
|
|
1222
|
-
F: __dxlog_file6,
|
|
1223
|
-
L: 429,
|
|
1224
|
-
S: this,
|
|
1225
|
-
A: [
|
|
1226
|
-
"!response.ok",
|
|
1227
|
-
"'Expected response to not be ok.'"
|
|
1228
|
-
]
|
|
1229
|
-
});
|
|
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.'"] });
|
|
1230
1074
|
processingError = await EdgeCallFailedError.fromHttpFailure(response);
|
|
1231
1075
|
}
|
|
1232
1076
|
} catch (error) {
|
|
1233
1077
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1234
1078
|
}
|
|
1235
|
-
if (processingError?.isRetryable && await shouldRetry(
|
|
1236
|
-
log4("retrying edge request", {
|
|
1079
|
+
if (processingError?.isRetryable && await shouldRetry(ctx, processingError.retryAfterMs)) {
|
|
1080
|
+
log4.verbose("retrying edge request", {
|
|
1237
1081
|
url,
|
|
1238
1082
|
processingError
|
|
1239
|
-
}, {
|
|
1240
|
-
F: __dxlog_file6,
|
|
1241
|
-
L: 437,
|
|
1242
|
-
S: this,
|
|
1243
|
-
C: (f, a) => f(...a)
|
|
1244
|
-
});
|
|
1083
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 353, S: this });
|
|
1245
1084
|
} else {
|
|
1246
1085
|
throw processingError;
|
|
1247
1086
|
}
|
|
@@ -1249,19 +1088,14 @@ var EdgeHttpClient = class {
|
|
|
1249
1088
|
}
|
|
1250
1089
|
async _handleUnauthorized(response) {
|
|
1251
1090
|
if (!this._edgeIdentity) {
|
|
1252
|
-
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1253
|
-
F: __dxlog_file6,
|
|
1254
|
-
L: 446,
|
|
1255
|
-
S: this,
|
|
1256
|
-
C: (f, a) => f(...a)
|
|
1257
|
-
});
|
|
1091
|
+
log4.warn("unauthorized response received before identity was set", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 364, S: this });
|
|
1258
1092
|
throw await EdgeCallFailedError.fromHttpFailure(response);
|
|
1259
1093
|
}
|
|
1260
1094
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
1261
1095
|
return encodeAuthHeader(challenge);
|
|
1262
1096
|
}
|
|
1263
1097
|
};
|
|
1264
|
-
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1098
|
+
var createRequest = ({ method, body, json = true }, authHeader, traceHeaders, clientTag) => {
|
|
1265
1099
|
let requestBody;
|
|
1266
1100
|
const headers = {};
|
|
1267
1101
|
if (json) {
|
|
@@ -1273,22 +1107,36 @@ var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
|
1273
1107
|
if (typeof requestBody === "string" && requestBody.length > WARNING_BODY_SIZE) {
|
|
1274
1108
|
log4.warn("Request with large body", {
|
|
1275
1109
|
bodySize: requestBody.length
|
|
1276
|
-
}, {
|
|
1277
|
-
F: __dxlog_file6,
|
|
1278
|
-
L: 470,
|
|
1279
|
-
S: void 0,
|
|
1280
|
-
C: (f, a) => f(...a)
|
|
1281
|
-
});
|
|
1110
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 381, S: void 0 });
|
|
1282
1111
|
}
|
|
1283
1112
|
if (authHeader) {
|
|
1284
1113
|
headers["Authorization"] = authHeader;
|
|
1285
1114
|
}
|
|
1115
|
+
if (traceHeaders) {
|
|
1116
|
+
Object.assign(headers, traceHeaders);
|
|
1117
|
+
}
|
|
1118
|
+
if (clientTag) {
|
|
1119
|
+
headers[EDGE_CLIENT_TAG_HEADER] = clientTag;
|
|
1120
|
+
}
|
|
1286
1121
|
return {
|
|
1287
1122
|
method,
|
|
1288
1123
|
body: requestBody,
|
|
1289
1124
|
headers
|
|
1290
1125
|
};
|
|
1291
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
|
+
};
|
|
1292
1140
|
var createRetryHandler = ({ retry: retry2 }) => {
|
|
1293
1141
|
if (!retry2 || retry2.count < 1) {
|
|
1294
1142
|
return async () => false;
|