@dxos/edge-client 0.7.5-main.9d2a38b → 0.7.5-main.b19bfc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +177 -206
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +162 -189
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +177 -206
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +6 -1
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/edge-client.ts +1 -2
- package/src/edge-http-client.ts +88 -4
- package/src/edge-ws-connection.ts +21 -5
- package/dist/types/src/persistent-lifecycle.d.ts +0 -44
- package/dist/types/src/persistent-lifecycle.d.ts.map +0 -1
- package/dist/types/src/persistent-lifecycle.test.d.ts +0 -2
- package/dist/types/src/persistent-lifecycle.test.d.ts.map +0 -1
- package/src/persistent-lifecycle.test.ts +0 -71
- package/src/persistent-lifecycle.ts +0 -121
package/dist/lib/node/index.cjs
CHANGED
|
@@ -59,17 +59,13 @@ var import_invariant2 = require("@dxos/invariant");
|
|
|
59
59
|
var import_log2 = require("@dxos/log");
|
|
60
60
|
var import_buf = require("@dxos/protocols/buf");
|
|
61
61
|
var import_messenger_pb = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
|
|
62
|
-
var import_async3 = require("@dxos/async");
|
|
63
|
-
var import_context3 = require("@dxos/context");
|
|
64
|
-
var import_debug = require("@dxos/debug");
|
|
65
|
-
var import_log3 = require("@dxos/log");
|
|
66
62
|
var import_credentials = require("@dxos/credentials");
|
|
67
63
|
var import_invariant3 = require("@dxos/invariant");
|
|
68
64
|
var import_keyring = require("@dxos/keyring");
|
|
69
65
|
var import_keys = require("@dxos/keys");
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
66
|
+
var import_async3 = require("@dxos/async");
|
|
67
|
+
var import_context3 = require("@dxos/context");
|
|
68
|
+
var import_log3 = require("@dxos/log");
|
|
73
69
|
var import_protocols = require("@dxos/protocols");
|
|
74
70
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
|
|
75
71
|
var handleAuthChallenge = async (failedResponse, identity) => {
|
|
@@ -114,7 +110,9 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
114
110
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
115
111
|
}
|
|
116
112
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
117
|
-
var SIGNAL_KEEPALIVE_INTERVAL =
|
|
113
|
+
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
114
|
+
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
115
|
+
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
118
116
|
var EdgeWsConnection = class extends import_context2.Resource {
|
|
119
117
|
constructor(_identity, _connectionInfo, _callbacks) {
|
|
120
118
|
super();
|
|
@@ -132,7 +130,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
132
130
|
send(message) {
|
|
133
131
|
(0, import_invariant2.invariant)(this._ws, void 0, {
|
|
134
132
|
F: __dxlog_file2,
|
|
135
|
-
L:
|
|
133
|
+
L: 54,
|
|
136
134
|
S: this,
|
|
137
135
|
A: [
|
|
138
136
|
"this._ws",
|
|
@@ -144,11 +142,25 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
144
142
|
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
145
143
|
}, {
|
|
146
144
|
F: __dxlog_file2,
|
|
147
|
-
L:
|
|
145
|
+
L: 55,
|
|
148
146
|
S: this,
|
|
149
147
|
C: (f, a) => f(...a)
|
|
150
148
|
});
|
|
151
|
-
|
|
149
|
+
const encoded = import_buf.buf.toBinary(import_messenger_pb.MessageSchema, message);
|
|
150
|
+
if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
151
|
+
import_log2.log.error("edge message dropped due to websocket message limit", {
|
|
152
|
+
byteLength: encoded.byteLength,
|
|
153
|
+
serviceId: message.serviceId,
|
|
154
|
+
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
155
|
+
}, {
|
|
156
|
+
F: __dxlog_file2,
|
|
157
|
+
L: 58,
|
|
158
|
+
S: this,
|
|
159
|
+
C: (f, a) => f(...a)
|
|
160
|
+
});
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this._ws.send(encoded);
|
|
152
164
|
}
|
|
153
165
|
async _open() {
|
|
154
166
|
this._ws = new import_isomorphic_ws.default(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
@@ -158,7 +170,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
158
170
|
if (this.isOpen) {
|
|
159
171
|
(0, import_log2.log)("connected", void 0, {
|
|
160
172
|
F: __dxlog_file2,
|
|
161
|
-
L:
|
|
173
|
+
L: 76,
|
|
162
174
|
S: this,
|
|
163
175
|
C: (f, a) => f(...a)
|
|
164
176
|
});
|
|
@@ -169,17 +181,20 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
169
181
|
currentIdentity: this._identity
|
|
170
182
|
}, {
|
|
171
183
|
F: __dxlog_file2,
|
|
172
|
-
L:
|
|
184
|
+
L: 80,
|
|
173
185
|
S: this,
|
|
174
186
|
C: (f, a) => f(...a)
|
|
175
187
|
});
|
|
176
188
|
}
|
|
177
189
|
};
|
|
178
|
-
this._ws.onclose = () => {
|
|
190
|
+
this._ws.onclose = (event) => {
|
|
179
191
|
if (this.isOpen) {
|
|
180
|
-
|
|
192
|
+
import_log2.log.warn("disconnected while being open", {
|
|
193
|
+
code: event.code,
|
|
194
|
+
reason: event.reason
|
|
195
|
+
}, {
|
|
181
196
|
F: __dxlog_file2,
|
|
182
|
-
L:
|
|
197
|
+
L: 85,
|
|
183
198
|
S: this,
|
|
184
199
|
C: (f, a) => f(...a)
|
|
185
200
|
});
|
|
@@ -193,7 +208,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
193
208
|
info: event.message
|
|
194
209
|
}, {
|
|
195
210
|
F: __dxlog_file2,
|
|
196
|
-
L:
|
|
211
|
+
L: 91,
|
|
197
212
|
S: this,
|
|
198
213
|
C: (f, a) => f(...a)
|
|
199
214
|
});
|
|
@@ -203,7 +218,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
203
218
|
error: event.error
|
|
204
219
|
}, {
|
|
205
220
|
F: __dxlog_file2,
|
|
206
|
-
L:
|
|
221
|
+
L: 94,
|
|
207
222
|
S: this,
|
|
208
223
|
C: (f, a) => f(...a)
|
|
209
224
|
});
|
|
@@ -215,7 +230,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
215
230
|
event: event.type
|
|
216
231
|
}, {
|
|
217
232
|
F: __dxlog_file2,
|
|
218
|
-
L:
|
|
233
|
+
L: 102,
|
|
219
234
|
S: this,
|
|
220
235
|
C: (f, a) => f(...a)
|
|
221
236
|
});
|
|
@@ -233,7 +248,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
233
248
|
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
234
249
|
}, {
|
|
235
250
|
F: __dxlog_file2,
|
|
236
|
-
L:
|
|
251
|
+
L: 112,
|
|
237
252
|
S: this,
|
|
238
253
|
C: (f, a) => f(...a)
|
|
239
254
|
});
|
|
@@ -255,7 +270,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
255
270
|
err
|
|
256
271
|
}, {
|
|
257
272
|
F: __dxlog_file2,
|
|
258
|
-
L:
|
|
273
|
+
L: 128,
|
|
259
274
|
S: this,
|
|
260
275
|
C: (f, a) => f(...a)
|
|
261
276
|
});
|
|
@@ -264,7 +279,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
264
279
|
_scheduleHeartbeats() {
|
|
265
280
|
(0, import_invariant2.invariant)(this._ws, void 0, {
|
|
266
281
|
F: __dxlog_file2,
|
|
267
|
-
L:
|
|
282
|
+
L: 133,
|
|
268
283
|
S: this,
|
|
269
284
|
A: [
|
|
270
285
|
"this._ws",
|
|
@@ -284,13 +299,19 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
284
299
|
void this._inactivityTimeoutCtx?.dispose();
|
|
285
300
|
this._inactivityTimeoutCtx = new import_context2.Context(void 0, {
|
|
286
301
|
F: __dxlog_file2,
|
|
287
|
-
L:
|
|
302
|
+
L: 152
|
|
288
303
|
});
|
|
289
304
|
(0, import_async2.scheduleTask)(this._inactivityTimeoutCtx, () => {
|
|
290
305
|
if (this.isOpen) {
|
|
306
|
+
import_log2.log.warn("restart due to inactivity timeout", void 0, {
|
|
307
|
+
F: __dxlog_file2,
|
|
308
|
+
L: 157,
|
|
309
|
+
S: this,
|
|
310
|
+
C: (f, a) => f(...a)
|
|
311
|
+
});
|
|
291
312
|
this._callbacks.onRestartRequired();
|
|
292
313
|
}
|
|
293
|
-
},
|
|
314
|
+
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
294
315
|
}
|
|
295
316
|
};
|
|
296
317
|
_ts_decorate([
|
|
@@ -306,132 +327,26 @@ var EdgeIdentityChangedError = class extends Error {
|
|
|
306
327
|
super("Edge identity changed.");
|
|
307
328
|
}
|
|
308
329
|
};
|
|
309
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
310
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
311
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
312
|
-
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;
|
|
313
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
314
|
-
}
|
|
315
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/persistent-lifecycle.ts";
|
|
316
|
-
var INIT_RESTART_DELAY = 100;
|
|
317
|
-
var DEFAULT_MAX_RESTART_DELAY = 5e3;
|
|
318
|
-
var PersistentLifecycle = class extends import_context3.Resource {
|
|
319
|
-
constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }) {
|
|
320
|
-
super();
|
|
321
|
-
this._currentContext = void 0;
|
|
322
|
-
this._restartTask = void 0;
|
|
323
|
-
this._restartAfter = 0;
|
|
324
|
-
this._start = start;
|
|
325
|
-
this._stop = stop;
|
|
326
|
-
this._onRestart = onRestart;
|
|
327
|
-
this._maxRestartDelay = maxRestartDelay;
|
|
328
|
-
}
|
|
329
|
-
async _open() {
|
|
330
|
-
this._restartTask = new import_async3.DeferredTask(this._ctx, async () => {
|
|
331
|
-
try {
|
|
332
|
-
await this._restart();
|
|
333
|
-
} catch (err) {
|
|
334
|
-
import_log3.log.warn("Restart failed", {
|
|
335
|
-
err
|
|
336
|
-
}, {
|
|
337
|
-
F: __dxlog_file3,
|
|
338
|
-
L: 65,
|
|
339
|
-
S: this,
|
|
340
|
-
C: (f, a) => f(...a)
|
|
341
|
-
});
|
|
342
|
-
this._restartTask?.schedule();
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
this._currentContext = await this._start().catch((err) => {
|
|
346
|
-
import_log3.log.warn("Start failed", {
|
|
347
|
-
err
|
|
348
|
-
}, {
|
|
349
|
-
F: __dxlog_file3,
|
|
350
|
-
L: 70,
|
|
351
|
-
S: this,
|
|
352
|
-
C: (f, a) => f(...a)
|
|
353
|
-
});
|
|
354
|
-
this._restartTask?.schedule();
|
|
355
|
-
return void 0;
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
async _close() {
|
|
359
|
-
await this._restartTask?.join();
|
|
360
|
-
await this._stopCurrentContext();
|
|
361
|
-
this._restartTask = void 0;
|
|
362
|
-
}
|
|
363
|
-
async _restart() {
|
|
364
|
-
(0, import_log3.log)(`restarting in ${this._restartAfter}ms`, {
|
|
365
|
-
state: this._lifecycleState
|
|
366
|
-
}, {
|
|
367
|
-
F: __dxlog_file3,
|
|
368
|
-
L: 83,
|
|
369
|
-
S: this,
|
|
370
|
-
C: (f, a) => f(...a)
|
|
371
|
-
});
|
|
372
|
-
await this._stopCurrentContext();
|
|
373
|
-
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
await (0, import_context3.cancelWithContext)(this._ctx, (0, import_async3.sleep)(this._restartAfter));
|
|
377
|
-
this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);
|
|
378
|
-
await (0, import_debug.warnAfterTimeout)(5e3, "Connection establishment takes too long", async () => {
|
|
379
|
-
this._currentContext = await this._start();
|
|
380
|
-
});
|
|
381
|
-
this._restartAfter = 0;
|
|
382
|
-
await this._onRestart?.();
|
|
383
|
-
}
|
|
384
|
-
async _stopCurrentContext() {
|
|
385
|
-
if (this._currentContext) {
|
|
386
|
-
try {
|
|
387
|
-
await this._stop(this._currentContext);
|
|
388
|
-
} catch (err) {
|
|
389
|
-
import_log3.log.catch(err, void 0, {
|
|
390
|
-
F: __dxlog_file3,
|
|
391
|
-
L: 105,
|
|
392
|
-
S: this,
|
|
393
|
-
C: (f, a) => f(...a)
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
this._currentContext = void 0;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Scheduling restart should be done from outside.
|
|
401
|
-
*/
|
|
402
|
-
scheduleRestart() {
|
|
403
|
-
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
this._restartTask.schedule();
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
_ts_decorate2([
|
|
410
|
-
import_async3.synchronized
|
|
411
|
-
], PersistentLifecycle.prototype, "_open", null);
|
|
412
|
-
_ts_decorate2([
|
|
413
|
-
import_async3.synchronized
|
|
414
|
-
], PersistentLifecycle.prototype, "scheduleRestart", null);
|
|
415
330
|
var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
416
331
|
const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
|
|
417
332
|
const url = new URL(baseUrl);
|
|
418
333
|
url.protocol = protocol2 + (isSecure ? "s" : "");
|
|
419
334
|
return url.toString();
|
|
420
335
|
};
|
|
421
|
-
function
|
|
336
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
422
337
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
423
338
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
424
339
|
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;
|
|
425
340
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
426
341
|
}
|
|
427
|
-
var
|
|
342
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
428
343
|
var DEFAULT_TIMEOUT = 1e4;
|
|
429
344
|
var EdgeClient = class extends import_context.Resource {
|
|
430
345
|
constructor(_identity, _config) {
|
|
431
346
|
super();
|
|
432
347
|
this._identity = _identity;
|
|
433
348
|
this._config = _config;
|
|
434
|
-
this._persistentLifecycle = new PersistentLifecycle({
|
|
349
|
+
this._persistentLifecycle = new import_async.PersistentLifecycle({
|
|
435
350
|
start: async () => this._connect(),
|
|
436
351
|
stop: async (state) => this._disconnect(state)
|
|
437
352
|
});
|
|
@@ -465,8 +380,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
465
380
|
identity,
|
|
466
381
|
oldIdentity: this._identity
|
|
467
382
|
}, {
|
|
468
|
-
F:
|
|
469
|
-
L:
|
|
383
|
+
F: __dxlog_file3,
|
|
384
|
+
L: 94,
|
|
470
385
|
S: this,
|
|
471
386
|
C: (f, a) => f(...a)
|
|
472
387
|
});
|
|
@@ -488,8 +403,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
488
403
|
listener();
|
|
489
404
|
} catch (error) {
|
|
490
405
|
import_log.log.catch(error, void 0, {
|
|
491
|
-
F:
|
|
492
|
-
L:
|
|
406
|
+
F: __dxlog_file3,
|
|
407
|
+
L: 116,
|
|
493
408
|
S: this,
|
|
494
409
|
C: (f, a) => f(...a)
|
|
495
410
|
});
|
|
@@ -506,8 +421,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
506
421
|
(0, import_log.log)("opening...", {
|
|
507
422
|
info: this.info
|
|
508
423
|
}, {
|
|
509
|
-
F:
|
|
510
|
-
L:
|
|
424
|
+
F: __dxlog_file3,
|
|
425
|
+
L: 128,
|
|
511
426
|
S: this,
|
|
512
427
|
C: (f, a) => f(...a)
|
|
513
428
|
});
|
|
@@ -515,8 +430,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
515
430
|
import_log.log.warn("Error while opening connection", {
|
|
516
431
|
err
|
|
517
432
|
}, {
|
|
518
|
-
F:
|
|
519
|
-
L:
|
|
433
|
+
F: __dxlog_file3,
|
|
434
|
+
L: 130,
|
|
520
435
|
S: this,
|
|
521
436
|
C: (f, a) => f(...a)
|
|
522
437
|
});
|
|
@@ -529,8 +444,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
529
444
|
(0, import_log.log)("closing...", {
|
|
530
445
|
peerKey: this._identity.peerKey
|
|
531
446
|
}, {
|
|
532
|
-
F:
|
|
533
|
-
L:
|
|
447
|
+
F: __dxlog_file3,
|
|
448
|
+
L: 138,
|
|
534
449
|
S: this,
|
|
535
450
|
C: (f, a) => f(...a)
|
|
536
451
|
});
|
|
@@ -546,8 +461,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
546
461
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
547
462
|
if (this._identity !== identity) {
|
|
548
463
|
(0, import_log.log)("identity changed during auth header request", void 0, {
|
|
549
|
-
F:
|
|
550
|
-
L:
|
|
464
|
+
F: __dxlog_file3,
|
|
465
|
+
L: 152,
|
|
551
466
|
S: this,
|
|
552
467
|
C: (f, a) => f(...a)
|
|
553
468
|
});
|
|
@@ -559,8 +474,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
559
474
|
url: url.toString(),
|
|
560
475
|
protocolHeader
|
|
561
476
|
}, {
|
|
562
|
-
F:
|
|
563
|
-
L:
|
|
477
|
+
F: __dxlog_file3,
|
|
478
|
+
L: 158,
|
|
564
479
|
S: this,
|
|
565
480
|
C: (f, a) => f(...a)
|
|
566
481
|
});
|
|
@@ -574,8 +489,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
574
489
|
this._notifyReconnected();
|
|
575
490
|
} else {
|
|
576
491
|
import_log.log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
577
|
-
F:
|
|
578
|
-
L:
|
|
492
|
+
F: __dxlog_file3,
|
|
493
|
+
L: 168,
|
|
579
494
|
S: this,
|
|
580
495
|
C: (f, a) => f(...a)
|
|
581
496
|
});
|
|
@@ -587,8 +502,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
587
502
|
this._persistentLifecycle.scheduleRestart();
|
|
588
503
|
} else {
|
|
589
504
|
import_log.log.verbose("restart requested by inactive connection", void 0, {
|
|
590
|
-
F:
|
|
591
|
-
L:
|
|
505
|
+
F: __dxlog_file3,
|
|
506
|
+
L: 176,
|
|
592
507
|
S: this,
|
|
593
508
|
C: (f, a) => f(...a)
|
|
594
509
|
});
|
|
@@ -603,8 +518,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
603
518
|
from: message.source,
|
|
604
519
|
type: message.payload?.typeUrl
|
|
605
520
|
}, {
|
|
606
|
-
F:
|
|
607
|
-
L:
|
|
521
|
+
F: __dxlog_file3,
|
|
522
|
+
L: 184,
|
|
608
523
|
S: this,
|
|
609
524
|
C: (f, a) => f(...a)
|
|
610
525
|
});
|
|
@@ -637,8 +552,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
637
552
|
import_log.log.error("ws reconnect listener failed", {
|
|
638
553
|
err
|
|
639
554
|
}, {
|
|
640
|
-
F:
|
|
641
|
-
L:
|
|
555
|
+
F: __dxlog_file3,
|
|
556
|
+
L: 217,
|
|
642
557
|
S: this,
|
|
643
558
|
C: (f, a) => f(...a)
|
|
644
559
|
});
|
|
@@ -654,8 +569,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
654
569
|
err,
|
|
655
570
|
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
656
571
|
}, {
|
|
657
|
-
F:
|
|
658
|
-
L:
|
|
572
|
+
F: __dxlog_file3,
|
|
573
|
+
L: 227,
|
|
659
574
|
S: this,
|
|
660
575
|
C: (f, a) => f(...a)
|
|
661
576
|
});
|
|
@@ -669,8 +584,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
669
584
|
async send(message) {
|
|
670
585
|
if (this._ready.state !== import_async.TriggerState.RESOLVED) {
|
|
671
586
|
(0, import_log.log)("waiting for websocket to become ready", void 0, {
|
|
672
|
-
F:
|
|
673
|
-
L:
|
|
587
|
+
F: __dxlog_file3,
|
|
588
|
+
L: 238,
|
|
674
589
|
S: this,
|
|
675
590
|
C: (f, a) => f(...a)
|
|
676
591
|
});
|
|
@@ -699,8 +614,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
699
614
|
status: response.status,
|
|
700
615
|
statusText: response.statusText
|
|
701
616
|
}, {
|
|
702
|
-
F:
|
|
703
|
-
L:
|
|
617
|
+
F: __dxlog_file3,
|
|
618
|
+
L: 263,
|
|
704
619
|
S: this,
|
|
705
620
|
C: (f, a) => f(...a)
|
|
706
621
|
});
|
|
@@ -708,14 +623,14 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
708
623
|
}
|
|
709
624
|
}
|
|
710
625
|
};
|
|
711
|
-
|
|
626
|
+
_ts_decorate2([
|
|
712
627
|
import_log.logInfo
|
|
713
628
|
], EdgeClient.prototype, "info", null);
|
|
714
629
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
715
630
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
716
631
|
return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
|
|
717
632
|
};
|
|
718
|
-
var
|
|
633
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
719
634
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
720
635
|
return {
|
|
721
636
|
identityKey: key.toHex(),
|
|
@@ -760,7 +675,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
760
675
|
peerKey: peerKey.toHex(),
|
|
761
676
|
presentCredentials: async ({ challenge }) => {
|
|
762
677
|
(0, import_invariant3.invariant)(chain, void 0, {
|
|
763
|
-
F:
|
|
678
|
+
F: __dxlog_file4,
|
|
764
679
|
L: 75,
|
|
765
680
|
S: void 0,
|
|
766
681
|
A: [
|
|
@@ -820,22 +735,25 @@ var createStubEdgeIdentity = () => {
|
|
|
820
735
|
}
|
|
821
736
|
};
|
|
822
737
|
};
|
|
823
|
-
var
|
|
738
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
824
739
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
825
740
|
var DEFAULT_RETRY_JITTER = 500;
|
|
826
741
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
827
742
|
var EdgeHttpClient = class {
|
|
828
743
|
constructor(baseUrl) {
|
|
829
744
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
830
|
-
(0,
|
|
745
|
+
(0, import_log3.log)("created", {
|
|
831
746
|
url: this._baseUrl
|
|
832
747
|
}, {
|
|
833
|
-
F:
|
|
834
|
-
L:
|
|
748
|
+
F: __dxlog_file5,
|
|
749
|
+
L: 49,
|
|
835
750
|
S: this,
|
|
836
751
|
C: (f, a) => f(...a)
|
|
837
752
|
});
|
|
838
753
|
}
|
|
754
|
+
get baseUrl() {
|
|
755
|
+
return this._baseUrl;
|
|
756
|
+
}
|
|
839
757
|
setIdentity(identity) {
|
|
840
758
|
if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {
|
|
841
759
|
this._edgeIdentity = identity;
|
|
@@ -882,6 +800,13 @@ var EdgeHttpClient = class {
|
|
|
882
800
|
method: "POST"
|
|
883
801
|
});
|
|
884
802
|
}
|
|
803
|
+
async executeWorkflow(spaceId, graphId, input, args) {
|
|
804
|
+
return this._call(`/workflows/${spaceId}/${graphId}`, {
|
|
805
|
+
...args,
|
|
806
|
+
body: input,
|
|
807
|
+
method: "POST"
|
|
808
|
+
});
|
|
809
|
+
}
|
|
885
810
|
async uploadFunction(pathParts, body, args) {
|
|
886
811
|
const path = [
|
|
887
812
|
"functions",
|
|
@@ -896,20 +821,68 @@ var EdgeHttpClient = class {
|
|
|
896
821
|
method: "PUT"
|
|
897
822
|
});
|
|
898
823
|
}
|
|
824
|
+
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
825
|
+
const { queueId } = query;
|
|
826
|
+
const queryParams = new URLSearchParams();
|
|
827
|
+
if (query.after != null) {
|
|
828
|
+
queryParams.set("after", query.after);
|
|
829
|
+
}
|
|
830
|
+
if (query.before != null) {
|
|
831
|
+
queryParams.set("before", query.before);
|
|
832
|
+
}
|
|
833
|
+
if (query.limit != null) {
|
|
834
|
+
queryParams.set("limit", query.limit.toString());
|
|
835
|
+
}
|
|
836
|
+
if (query.reverse != null) {
|
|
837
|
+
queryParams.set("reverse", query.reverse.toString());
|
|
838
|
+
}
|
|
839
|
+
if (query.objectIds != null) {
|
|
840
|
+
queryParams.set("objectIds", query.objectIds.join(","));
|
|
841
|
+
}
|
|
842
|
+
return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query?${queryParams.toString()}`, {
|
|
843
|
+
...args,
|
|
844
|
+
method: "GET"
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
848
|
+
return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
|
|
849
|
+
...args,
|
|
850
|
+
body: {
|
|
851
|
+
objects
|
|
852
|
+
},
|
|
853
|
+
method: "POST"
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
857
|
+
return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
|
|
858
|
+
...args,
|
|
859
|
+
query: {
|
|
860
|
+
ids: objectIds.join(",")
|
|
861
|
+
},
|
|
862
|
+
method: "DELETE"
|
|
863
|
+
});
|
|
864
|
+
}
|
|
899
865
|
async _call(path, args) {
|
|
900
|
-
const requestContext = args.context ?? new
|
|
901
|
-
F:
|
|
902
|
-
L:
|
|
866
|
+
const requestContext = args.context ?? new import_context3.Context(void 0, {
|
|
867
|
+
F: __dxlog_file5,
|
|
868
|
+
L: 177
|
|
903
869
|
});
|
|
904
870
|
const shouldRetry = createRetryHandler(args);
|
|
905
|
-
|
|
906
|
-
|
|
871
|
+
let url = `${this._baseUrl}${path.startsWith("/") ? path.slice(1) : path}`;
|
|
872
|
+
if (args.query) {
|
|
873
|
+
const queryParams = new URLSearchParams();
|
|
874
|
+
for (const [key, value] of Object.entries(args.query)) {
|
|
875
|
+
queryParams.set(key, value.toString());
|
|
876
|
+
}
|
|
877
|
+
url += `?${queryParams.toString()}`;
|
|
878
|
+
}
|
|
879
|
+
(0, import_log3.log)("call", {
|
|
907
880
|
method: args.method,
|
|
908
881
|
path,
|
|
909
882
|
request: args.body
|
|
910
883
|
}, {
|
|
911
|
-
F:
|
|
912
|
-
L:
|
|
884
|
+
F: __dxlog_file5,
|
|
885
|
+
L: 189,
|
|
913
886
|
S: this,
|
|
914
887
|
C: (f, a) => f(...a)
|
|
915
888
|
});
|
|
@@ -927,12 +900,12 @@ var EdgeHttpClient = class {
|
|
|
927
900
|
if (body.success) {
|
|
928
901
|
return body.data;
|
|
929
902
|
}
|
|
930
|
-
|
|
903
|
+
(0, import_log3.log)("unsuccessful edge response", {
|
|
931
904
|
path,
|
|
932
905
|
body
|
|
933
906
|
}, {
|
|
934
|
-
F:
|
|
935
|
-
L:
|
|
907
|
+
F: __dxlog_file5,
|
|
908
|
+
L: 208,
|
|
936
909
|
S: this,
|
|
937
910
|
C: (f, a) => f(...a)
|
|
938
911
|
});
|
|
@@ -952,12 +925,12 @@ var EdgeHttpClient = class {
|
|
|
952
925
|
processingError = import_protocols.EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
953
926
|
}
|
|
954
927
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
955
|
-
|
|
928
|
+
(0, import_log3.log)("retrying edge request", {
|
|
956
929
|
path,
|
|
957
930
|
processingError
|
|
958
931
|
}, {
|
|
959
|
-
F:
|
|
960
|
-
L:
|
|
932
|
+
F: __dxlog_file5,
|
|
933
|
+
L: 227,
|
|
961
934
|
S: this,
|
|
962
935
|
C: (f, a) => f(...a)
|
|
963
936
|
});
|
|
@@ -968,9 +941,9 @@ var EdgeHttpClient = class {
|
|
|
968
941
|
}
|
|
969
942
|
async _handleUnauthorized(response) {
|
|
970
943
|
if (!this._edgeIdentity) {
|
|
971
|
-
|
|
972
|
-
F:
|
|
973
|
-
L:
|
|
944
|
+
import_log3.log.warn("edge unauthorized response received before identity was set", void 0, {
|
|
945
|
+
F: __dxlog_file5,
|
|
946
|
+
L: 236,
|
|
974
947
|
S: this,
|
|
975
948
|
C: (f, a) => f(...a)
|
|
976
949
|
});
|
|
@@ -978,9 +951,9 @@ var EdgeHttpClient = class {
|
|
|
978
951
|
}
|
|
979
952
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
980
953
|
this._authHeader = encodeAuthHeader(challenge);
|
|
981
|
-
(0,
|
|
982
|
-
F:
|
|
983
|
-
L:
|
|
954
|
+
(0, import_log3.log)("auth header updated", void 0, {
|
|
955
|
+
F: __dxlog_file5,
|
|
956
|
+
L: 241,
|
|
984
957
|
S: this,
|
|
985
958
|
C: (f, a) => f(...a)
|
|
986
959
|
});
|
|
@@ -1000,10 +973,10 @@ var createRetryHandler = (args) => {
|
|
|
1000
973
|
return false;
|
|
1001
974
|
}
|
|
1002
975
|
if (retryAfter) {
|
|
1003
|
-
await (0,
|
|
976
|
+
await (0, import_async3.sleep)(retryAfter);
|
|
1004
977
|
} else {
|
|
1005
978
|
const timeout = baseTimeout + Math.random() * jitter;
|
|
1006
|
-
await (0,
|
|
979
|
+
await (0, import_async3.sleep)(timeout);
|
|
1007
980
|
}
|
|
1008
981
|
return true;
|
|
1009
982
|
};
|