@dxos/edge-client 0.7.5-main.e9bb01b → 0.7.5-staging.2ff1350
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 +162 -206
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +147 -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 +162 -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 +6 -4
- 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,8 @@ 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;
|
|
118
115
|
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
119
116
|
var EdgeWsConnection = class extends import_context2.Resource {
|
|
120
117
|
constructor(_identity, _connectionInfo, _callbacks) {
|
|
@@ -133,7 +130,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
133
130
|
send(message) {
|
|
134
131
|
(0, import_invariant2.invariant)(this._ws, void 0, {
|
|
135
132
|
F: __dxlog_file2,
|
|
136
|
-
L:
|
|
133
|
+
L: 54,
|
|
137
134
|
S: this,
|
|
138
135
|
A: [
|
|
139
136
|
"this._ws",
|
|
@@ -145,7 +142,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
145
142
|
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
146
143
|
}, {
|
|
147
144
|
F: __dxlog_file2,
|
|
148
|
-
L:
|
|
145
|
+
L: 55,
|
|
149
146
|
S: this,
|
|
150
147
|
C: (f, a) => f(...a)
|
|
151
148
|
});
|
|
@@ -157,7 +154,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
157
154
|
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
158
155
|
}, {
|
|
159
156
|
F: __dxlog_file2,
|
|
160
|
-
L:
|
|
157
|
+
L: 58,
|
|
161
158
|
S: this,
|
|
162
159
|
C: (f, a) => f(...a)
|
|
163
160
|
});
|
|
@@ -173,7 +170,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
173
170
|
if (this.isOpen) {
|
|
174
171
|
(0, import_log2.log)("connected", void 0, {
|
|
175
172
|
F: __dxlog_file2,
|
|
176
|
-
L:
|
|
173
|
+
L: 76,
|
|
177
174
|
S: this,
|
|
178
175
|
C: (f, a) => f(...a)
|
|
179
176
|
});
|
|
@@ -184,17 +181,20 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
184
181
|
currentIdentity: this._identity
|
|
185
182
|
}, {
|
|
186
183
|
F: __dxlog_file2,
|
|
187
|
-
L:
|
|
184
|
+
L: 80,
|
|
188
185
|
S: this,
|
|
189
186
|
C: (f, a) => f(...a)
|
|
190
187
|
});
|
|
191
188
|
}
|
|
192
189
|
};
|
|
193
|
-
this._ws.onclose = () => {
|
|
190
|
+
this._ws.onclose = (event) => {
|
|
194
191
|
if (this.isOpen) {
|
|
195
|
-
|
|
192
|
+
import_log2.log.warn("disconnected while being open", {
|
|
193
|
+
code: event.code,
|
|
194
|
+
reason: event.reason
|
|
195
|
+
}, {
|
|
196
196
|
F: __dxlog_file2,
|
|
197
|
-
L:
|
|
197
|
+
L: 85,
|
|
198
198
|
S: this,
|
|
199
199
|
C: (f, a) => f(...a)
|
|
200
200
|
});
|
|
@@ -208,7 +208,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
208
208
|
info: event.message
|
|
209
209
|
}, {
|
|
210
210
|
F: __dxlog_file2,
|
|
211
|
-
L:
|
|
211
|
+
L: 91,
|
|
212
212
|
S: this,
|
|
213
213
|
C: (f, a) => f(...a)
|
|
214
214
|
});
|
|
@@ -218,7 +218,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
218
218
|
error: event.error
|
|
219
219
|
}, {
|
|
220
220
|
F: __dxlog_file2,
|
|
221
|
-
L:
|
|
221
|
+
L: 94,
|
|
222
222
|
S: this,
|
|
223
223
|
C: (f, a) => f(...a)
|
|
224
224
|
});
|
|
@@ -230,7 +230,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
230
230
|
event: event.type
|
|
231
231
|
}, {
|
|
232
232
|
F: __dxlog_file2,
|
|
233
|
-
L:
|
|
233
|
+
L: 102,
|
|
234
234
|
S: this,
|
|
235
235
|
C: (f, a) => f(...a)
|
|
236
236
|
});
|
|
@@ -248,7 +248,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
248
248
|
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
249
249
|
}, {
|
|
250
250
|
F: __dxlog_file2,
|
|
251
|
-
L:
|
|
251
|
+
L: 112,
|
|
252
252
|
S: this,
|
|
253
253
|
C: (f, a) => f(...a)
|
|
254
254
|
});
|
|
@@ -270,7 +270,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
270
270
|
err
|
|
271
271
|
}, {
|
|
272
272
|
F: __dxlog_file2,
|
|
273
|
-
L:
|
|
273
|
+
L: 128,
|
|
274
274
|
S: this,
|
|
275
275
|
C: (f, a) => f(...a)
|
|
276
276
|
});
|
|
@@ -279,7 +279,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
279
279
|
_scheduleHeartbeats() {
|
|
280
280
|
(0, import_invariant2.invariant)(this._ws, void 0, {
|
|
281
281
|
F: __dxlog_file2,
|
|
282
|
-
L:
|
|
282
|
+
L: 133,
|
|
283
283
|
S: this,
|
|
284
284
|
A: [
|
|
285
285
|
"this._ws",
|
|
@@ -299,13 +299,19 @@ var EdgeWsConnection = class extends import_context2.Resource {
|
|
|
299
299
|
void this._inactivityTimeoutCtx?.dispose();
|
|
300
300
|
this._inactivityTimeoutCtx = new import_context2.Context(void 0, {
|
|
301
301
|
F: __dxlog_file2,
|
|
302
|
-
L:
|
|
302
|
+
L: 152
|
|
303
303
|
});
|
|
304
304
|
(0, import_async2.scheduleTask)(this._inactivityTimeoutCtx, () => {
|
|
305
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
|
+
});
|
|
306
312
|
this._callbacks.onRestartRequired();
|
|
307
313
|
}
|
|
308
|
-
},
|
|
314
|
+
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
309
315
|
}
|
|
310
316
|
};
|
|
311
317
|
_ts_decorate([
|
|
@@ -321,132 +327,26 @@ var EdgeIdentityChangedError = class extends Error {
|
|
|
321
327
|
super("Edge identity changed.");
|
|
322
328
|
}
|
|
323
329
|
};
|
|
324
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
325
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
326
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
327
|
-
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;
|
|
328
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
329
|
-
}
|
|
330
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/persistent-lifecycle.ts";
|
|
331
|
-
var INIT_RESTART_DELAY = 100;
|
|
332
|
-
var DEFAULT_MAX_RESTART_DELAY = 5e3;
|
|
333
|
-
var PersistentLifecycle = class extends import_context3.Resource {
|
|
334
|
-
constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }) {
|
|
335
|
-
super();
|
|
336
|
-
this._currentContext = void 0;
|
|
337
|
-
this._restartTask = void 0;
|
|
338
|
-
this._restartAfter = 0;
|
|
339
|
-
this._start = start;
|
|
340
|
-
this._stop = stop;
|
|
341
|
-
this._onRestart = onRestart;
|
|
342
|
-
this._maxRestartDelay = maxRestartDelay;
|
|
343
|
-
}
|
|
344
|
-
async _open() {
|
|
345
|
-
this._restartTask = new import_async3.DeferredTask(this._ctx, async () => {
|
|
346
|
-
try {
|
|
347
|
-
await this._restart();
|
|
348
|
-
} catch (err) {
|
|
349
|
-
import_log3.log.warn("Restart failed", {
|
|
350
|
-
err
|
|
351
|
-
}, {
|
|
352
|
-
F: __dxlog_file3,
|
|
353
|
-
L: 65,
|
|
354
|
-
S: this,
|
|
355
|
-
C: (f, a) => f(...a)
|
|
356
|
-
});
|
|
357
|
-
this._restartTask?.schedule();
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
this._currentContext = await this._start().catch((err) => {
|
|
361
|
-
import_log3.log.warn("Start failed", {
|
|
362
|
-
err
|
|
363
|
-
}, {
|
|
364
|
-
F: __dxlog_file3,
|
|
365
|
-
L: 70,
|
|
366
|
-
S: this,
|
|
367
|
-
C: (f, a) => f(...a)
|
|
368
|
-
});
|
|
369
|
-
this._restartTask?.schedule();
|
|
370
|
-
return void 0;
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
async _close() {
|
|
374
|
-
await this._restartTask?.join();
|
|
375
|
-
await this._stopCurrentContext();
|
|
376
|
-
this._restartTask = void 0;
|
|
377
|
-
}
|
|
378
|
-
async _restart() {
|
|
379
|
-
(0, import_log3.log)(`restarting in ${this._restartAfter}ms`, {
|
|
380
|
-
state: this._lifecycleState
|
|
381
|
-
}, {
|
|
382
|
-
F: __dxlog_file3,
|
|
383
|
-
L: 83,
|
|
384
|
-
S: this,
|
|
385
|
-
C: (f, a) => f(...a)
|
|
386
|
-
});
|
|
387
|
-
await this._stopCurrentContext();
|
|
388
|
-
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
await (0, import_context3.cancelWithContext)(this._ctx, (0, import_async3.sleep)(this._restartAfter));
|
|
392
|
-
this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);
|
|
393
|
-
await (0, import_debug.warnAfterTimeout)(5e3, "Connection establishment takes too long", async () => {
|
|
394
|
-
this._currentContext = await this._start();
|
|
395
|
-
});
|
|
396
|
-
this._restartAfter = 0;
|
|
397
|
-
await this._onRestart?.();
|
|
398
|
-
}
|
|
399
|
-
async _stopCurrentContext() {
|
|
400
|
-
if (this._currentContext) {
|
|
401
|
-
try {
|
|
402
|
-
await this._stop(this._currentContext);
|
|
403
|
-
} catch (err) {
|
|
404
|
-
import_log3.log.catch(err, void 0, {
|
|
405
|
-
F: __dxlog_file3,
|
|
406
|
-
L: 105,
|
|
407
|
-
S: this,
|
|
408
|
-
C: (f, a) => f(...a)
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
this._currentContext = void 0;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Scheduling restart should be done from outside.
|
|
416
|
-
*/
|
|
417
|
-
scheduleRestart() {
|
|
418
|
-
if (this._lifecycleState !== import_context3.LifecycleState.OPEN) {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
this._restartTask.schedule();
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
_ts_decorate2([
|
|
425
|
-
import_async3.synchronized
|
|
426
|
-
], PersistentLifecycle.prototype, "_open", null);
|
|
427
|
-
_ts_decorate2([
|
|
428
|
-
import_async3.synchronized
|
|
429
|
-
], PersistentLifecycle.prototype, "scheduleRestart", null);
|
|
430
330
|
var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
431
331
|
const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
|
|
432
332
|
const url = new URL(baseUrl);
|
|
433
333
|
url.protocol = protocol2 + (isSecure ? "s" : "");
|
|
434
334
|
return url.toString();
|
|
435
335
|
};
|
|
436
|
-
function
|
|
336
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
437
337
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
438
338
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
439
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;
|
|
440
340
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
441
341
|
}
|
|
442
|
-
var
|
|
342
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
443
343
|
var DEFAULT_TIMEOUT = 1e4;
|
|
444
344
|
var EdgeClient = class extends import_context.Resource {
|
|
445
345
|
constructor(_identity, _config) {
|
|
446
346
|
super();
|
|
447
347
|
this._identity = _identity;
|
|
448
348
|
this._config = _config;
|
|
449
|
-
this._persistentLifecycle = new PersistentLifecycle({
|
|
349
|
+
this._persistentLifecycle = new import_async.PersistentLifecycle({
|
|
450
350
|
start: async () => this._connect(),
|
|
451
351
|
stop: async (state) => this._disconnect(state)
|
|
452
352
|
});
|
|
@@ -480,8 +380,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
480
380
|
identity,
|
|
481
381
|
oldIdentity: this._identity
|
|
482
382
|
}, {
|
|
483
|
-
F:
|
|
484
|
-
L:
|
|
383
|
+
F: __dxlog_file3,
|
|
384
|
+
L: 94,
|
|
485
385
|
S: this,
|
|
486
386
|
C: (f, a) => f(...a)
|
|
487
387
|
});
|
|
@@ -503,8 +403,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
503
403
|
listener();
|
|
504
404
|
} catch (error) {
|
|
505
405
|
import_log.log.catch(error, void 0, {
|
|
506
|
-
F:
|
|
507
|
-
L:
|
|
406
|
+
F: __dxlog_file3,
|
|
407
|
+
L: 116,
|
|
508
408
|
S: this,
|
|
509
409
|
C: (f, a) => f(...a)
|
|
510
410
|
});
|
|
@@ -521,8 +421,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
521
421
|
(0, import_log.log)("opening...", {
|
|
522
422
|
info: this.info
|
|
523
423
|
}, {
|
|
524
|
-
F:
|
|
525
|
-
L:
|
|
424
|
+
F: __dxlog_file3,
|
|
425
|
+
L: 128,
|
|
526
426
|
S: this,
|
|
527
427
|
C: (f, a) => f(...a)
|
|
528
428
|
});
|
|
@@ -530,8 +430,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
530
430
|
import_log.log.warn("Error while opening connection", {
|
|
531
431
|
err
|
|
532
432
|
}, {
|
|
533
|
-
F:
|
|
534
|
-
L:
|
|
433
|
+
F: __dxlog_file3,
|
|
434
|
+
L: 130,
|
|
535
435
|
S: this,
|
|
536
436
|
C: (f, a) => f(...a)
|
|
537
437
|
});
|
|
@@ -544,8 +444,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
544
444
|
(0, import_log.log)("closing...", {
|
|
545
445
|
peerKey: this._identity.peerKey
|
|
546
446
|
}, {
|
|
547
|
-
F:
|
|
548
|
-
L:
|
|
447
|
+
F: __dxlog_file3,
|
|
448
|
+
L: 138,
|
|
549
449
|
S: this,
|
|
550
450
|
C: (f, a) => f(...a)
|
|
551
451
|
});
|
|
@@ -561,8 +461,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
561
461
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
562
462
|
if (this._identity !== identity) {
|
|
563
463
|
(0, import_log.log)("identity changed during auth header request", void 0, {
|
|
564
|
-
F:
|
|
565
|
-
L:
|
|
464
|
+
F: __dxlog_file3,
|
|
465
|
+
L: 152,
|
|
566
466
|
S: this,
|
|
567
467
|
C: (f, a) => f(...a)
|
|
568
468
|
});
|
|
@@ -574,8 +474,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
574
474
|
url: url.toString(),
|
|
575
475
|
protocolHeader
|
|
576
476
|
}, {
|
|
577
|
-
F:
|
|
578
|
-
L:
|
|
477
|
+
F: __dxlog_file3,
|
|
478
|
+
L: 158,
|
|
579
479
|
S: this,
|
|
580
480
|
C: (f, a) => f(...a)
|
|
581
481
|
});
|
|
@@ -589,8 +489,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
589
489
|
this._notifyReconnected();
|
|
590
490
|
} else {
|
|
591
491
|
import_log.log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
592
|
-
F:
|
|
593
|
-
L:
|
|
492
|
+
F: __dxlog_file3,
|
|
493
|
+
L: 168,
|
|
594
494
|
S: this,
|
|
595
495
|
C: (f, a) => f(...a)
|
|
596
496
|
});
|
|
@@ -602,8 +502,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
602
502
|
this._persistentLifecycle.scheduleRestart();
|
|
603
503
|
} else {
|
|
604
504
|
import_log.log.verbose("restart requested by inactive connection", void 0, {
|
|
605
|
-
F:
|
|
606
|
-
L:
|
|
505
|
+
F: __dxlog_file3,
|
|
506
|
+
L: 176,
|
|
607
507
|
S: this,
|
|
608
508
|
C: (f, a) => f(...a)
|
|
609
509
|
});
|
|
@@ -618,8 +518,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
618
518
|
from: message.source,
|
|
619
519
|
type: message.payload?.typeUrl
|
|
620
520
|
}, {
|
|
621
|
-
F:
|
|
622
|
-
L:
|
|
521
|
+
F: __dxlog_file3,
|
|
522
|
+
L: 184,
|
|
623
523
|
S: this,
|
|
624
524
|
C: (f, a) => f(...a)
|
|
625
525
|
});
|
|
@@ -652,8 +552,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
652
552
|
import_log.log.error("ws reconnect listener failed", {
|
|
653
553
|
err
|
|
654
554
|
}, {
|
|
655
|
-
F:
|
|
656
|
-
L:
|
|
555
|
+
F: __dxlog_file3,
|
|
556
|
+
L: 217,
|
|
657
557
|
S: this,
|
|
658
558
|
C: (f, a) => f(...a)
|
|
659
559
|
});
|
|
@@ -669,8 +569,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
669
569
|
err,
|
|
670
570
|
payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
|
|
671
571
|
}, {
|
|
672
|
-
F:
|
|
673
|
-
L:
|
|
572
|
+
F: __dxlog_file3,
|
|
573
|
+
L: 227,
|
|
674
574
|
S: this,
|
|
675
575
|
C: (f, a) => f(...a)
|
|
676
576
|
});
|
|
@@ -684,8 +584,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
684
584
|
async send(message) {
|
|
685
585
|
if (this._ready.state !== import_async.TriggerState.RESOLVED) {
|
|
686
586
|
(0, import_log.log)("waiting for websocket to become ready", void 0, {
|
|
687
|
-
F:
|
|
688
|
-
L:
|
|
587
|
+
F: __dxlog_file3,
|
|
588
|
+
L: 238,
|
|
689
589
|
S: this,
|
|
690
590
|
C: (f, a) => f(...a)
|
|
691
591
|
});
|
|
@@ -714,8 +614,8 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
714
614
|
status: response.status,
|
|
715
615
|
statusText: response.statusText
|
|
716
616
|
}, {
|
|
717
|
-
F:
|
|
718
|
-
L:
|
|
617
|
+
F: __dxlog_file3,
|
|
618
|
+
L: 263,
|
|
719
619
|
S: this,
|
|
720
620
|
C: (f, a) => f(...a)
|
|
721
621
|
});
|
|
@@ -723,14 +623,14 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
723
623
|
}
|
|
724
624
|
}
|
|
725
625
|
};
|
|
726
|
-
|
|
626
|
+
_ts_decorate2([
|
|
727
627
|
import_log.logInfo
|
|
728
628
|
], EdgeClient.prototype, "info", null);
|
|
729
629
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
730
630
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
731
631
|
return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
|
|
732
632
|
};
|
|
733
|
-
var
|
|
633
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
734
634
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
735
635
|
return {
|
|
736
636
|
identityKey: key.toHex(),
|
|
@@ -775,7 +675,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
775
675
|
peerKey: peerKey.toHex(),
|
|
776
676
|
presentCredentials: async ({ challenge }) => {
|
|
777
677
|
(0, import_invariant3.invariant)(chain, void 0, {
|
|
778
|
-
F:
|
|
678
|
+
F: __dxlog_file4,
|
|
779
679
|
L: 75,
|
|
780
680
|
S: void 0,
|
|
781
681
|
A: [
|
|
@@ -835,22 +735,25 @@ var createStubEdgeIdentity = () => {
|
|
|
835
735
|
}
|
|
836
736
|
};
|
|
837
737
|
};
|
|
838
|
-
var
|
|
738
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
839
739
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
840
740
|
var DEFAULT_RETRY_JITTER = 500;
|
|
841
741
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
842
742
|
var EdgeHttpClient = class {
|
|
843
743
|
constructor(baseUrl) {
|
|
844
744
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
845
|
-
(0,
|
|
745
|
+
(0, import_log3.log)("created", {
|
|
846
746
|
url: this._baseUrl
|
|
847
747
|
}, {
|
|
848
|
-
F:
|
|
849
|
-
L:
|
|
748
|
+
F: __dxlog_file5,
|
|
749
|
+
L: 49,
|
|
850
750
|
S: this,
|
|
851
751
|
C: (f, a) => f(...a)
|
|
852
752
|
});
|
|
853
753
|
}
|
|
754
|
+
get baseUrl() {
|
|
755
|
+
return this._baseUrl;
|
|
756
|
+
}
|
|
854
757
|
setIdentity(identity) {
|
|
855
758
|
if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {
|
|
856
759
|
this._edgeIdentity = identity;
|
|
@@ -897,6 +800,13 @@ var EdgeHttpClient = class {
|
|
|
897
800
|
method: "POST"
|
|
898
801
|
});
|
|
899
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
|
+
}
|
|
900
810
|
async uploadFunction(pathParts, body, args) {
|
|
901
811
|
const path = [
|
|
902
812
|
"functions",
|
|
@@ -911,20 +821,68 @@ var EdgeHttpClient = class {
|
|
|
911
821
|
method: "PUT"
|
|
912
822
|
});
|
|
913
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
|
+
}
|
|
914
865
|
async _call(path, args) {
|
|
915
|
-
const requestContext = args.context ?? new
|
|
916
|
-
F:
|
|
917
|
-
L:
|
|
866
|
+
const requestContext = args.context ?? new import_context3.Context(void 0, {
|
|
867
|
+
F: __dxlog_file5,
|
|
868
|
+
L: 177
|
|
918
869
|
});
|
|
919
870
|
const shouldRetry = createRetryHandler(args);
|
|
920
|
-
|
|
921
|
-
|
|
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", {
|
|
922
880
|
method: args.method,
|
|
923
881
|
path,
|
|
924
882
|
request: args.body
|
|
925
883
|
}, {
|
|
926
|
-
F:
|
|
927
|
-
L:
|
|
884
|
+
F: __dxlog_file5,
|
|
885
|
+
L: 189,
|
|
928
886
|
S: this,
|
|
929
887
|
C: (f, a) => f(...a)
|
|
930
888
|
});
|
|
@@ -942,12 +900,12 @@ var EdgeHttpClient = class {
|
|
|
942
900
|
if (body.success) {
|
|
943
901
|
return body.data;
|
|
944
902
|
}
|
|
945
|
-
|
|
903
|
+
(0, import_log3.log)("unsuccessful edge response", {
|
|
946
904
|
path,
|
|
947
905
|
body
|
|
948
906
|
}, {
|
|
949
|
-
F:
|
|
950
|
-
L:
|
|
907
|
+
F: __dxlog_file5,
|
|
908
|
+
L: 208,
|
|
951
909
|
S: this,
|
|
952
910
|
C: (f, a) => f(...a)
|
|
953
911
|
});
|
|
@@ -967,12 +925,12 @@ var EdgeHttpClient = class {
|
|
|
967
925
|
processingError = import_protocols.EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
968
926
|
}
|
|
969
927
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
970
|
-
|
|
928
|
+
(0, import_log3.log)("retrying edge request", {
|
|
971
929
|
path,
|
|
972
930
|
processingError
|
|
973
931
|
}, {
|
|
974
|
-
F:
|
|
975
|
-
L:
|
|
932
|
+
F: __dxlog_file5,
|
|
933
|
+
L: 227,
|
|
976
934
|
S: this,
|
|
977
935
|
C: (f, a) => f(...a)
|
|
978
936
|
});
|
|
@@ -983,9 +941,9 @@ var EdgeHttpClient = class {
|
|
|
983
941
|
}
|
|
984
942
|
async _handleUnauthorized(response) {
|
|
985
943
|
if (!this._edgeIdentity) {
|
|
986
|
-
|
|
987
|
-
F:
|
|
988
|
-
L:
|
|
944
|
+
import_log3.log.warn("edge unauthorized response received before identity was set", void 0, {
|
|
945
|
+
F: __dxlog_file5,
|
|
946
|
+
L: 236,
|
|
989
947
|
S: this,
|
|
990
948
|
C: (f, a) => f(...a)
|
|
991
949
|
});
|
|
@@ -993,9 +951,9 @@ var EdgeHttpClient = class {
|
|
|
993
951
|
}
|
|
994
952
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
995
953
|
this._authHeader = encodeAuthHeader(challenge);
|
|
996
|
-
(0,
|
|
997
|
-
F:
|
|
998
|
-
L:
|
|
954
|
+
(0, import_log3.log)("auth header updated", void 0, {
|
|
955
|
+
F: __dxlog_file5,
|
|
956
|
+
L: 241,
|
|
999
957
|
S: this,
|
|
1000
958
|
C: (f, a) => f(...a)
|
|
1001
959
|
});
|
|
@@ -1015,10 +973,10 @@ var createRetryHandler = (args) => {
|
|
|
1015
973
|
return false;
|
|
1016
974
|
}
|
|
1017
975
|
if (retryAfter) {
|
|
1018
|
-
await (0,
|
|
976
|
+
await (0, import_async3.sleep)(retryAfter);
|
|
1019
977
|
} else {
|
|
1020
978
|
const timeout = baseTimeout + Math.random() * jitter;
|
|
1021
|
-
await (0,
|
|
979
|
+
await (0, import_async3.sleep)(timeout);
|
|
1022
980
|
}
|
|
1023
981
|
return true;
|
|
1024
982
|
};
|