@dxos/edge-client 0.8.2-main.12df754 → 0.8.2-main.36232bc
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/chunk-XS3TKGM4.mjs +545 -0
- package/dist/lib/browser/chunk-XS3TKGM4.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +60 -282
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +32 -20
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-ZURVCY7K.cjs +577 -0
- package/dist/lib/node/chunk-ZURVCY7K.cjs.map +7 -0
- package/dist/lib/node/index.cjs +50 -281
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +31 -21
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs +547 -0
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +60 -282
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +32 -20
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-ws-connection.d.ts +5 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +23 -0
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -0
- package/dist/types/src/testing/test-utils.d.ts +6 -2
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/edge-client.ts +2 -2
- package/src/edge-ws-connection.ts +38 -15
- package/src/edge-ws-muxer.ts +187 -0
- package/src/testing/test-utils.ts +33 -26
- package/dist/lib/browser/chunk-ZWJXA37R.mjs +0 -113
- package/dist/lib/browser/chunk-ZWJXA37R.mjs.map +0 -7
- package/dist/lib/node/chunk-ANV2HBEH.cjs +0 -136
- package/dist/lib/node/chunk-ANV2HBEH.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs +0 -115
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs.map +0 -7
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
+
EdgeWsConnection,
|
|
2
3
|
Protocol,
|
|
3
4
|
getTypename,
|
|
4
5
|
protocol,
|
|
5
6
|
toUint8Array
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-XS3TKGM4.mjs";
|
|
7
8
|
|
|
8
9
|
// packages/core/mesh/edge-client/src/index.ts
|
|
9
10
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
10
11
|
|
|
11
12
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
12
13
|
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
|
|
13
|
-
import { Resource
|
|
14
|
-
import { log
|
|
14
|
+
import { Resource } from "@dxos/context";
|
|
15
|
+
import { log, logInfo } from "@dxos/log";
|
|
15
16
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
16
17
|
|
|
17
18
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
@@ -54,229 +55,6 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
54
55
|
return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
55
56
|
};
|
|
56
57
|
|
|
57
|
-
// packages/core/mesh/edge-client/src/edge-ws-connection.ts
|
|
58
|
-
import WebSocket from "isomorphic-ws";
|
|
59
|
-
import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
60
|
-
import { Context, Resource } from "@dxos/context";
|
|
61
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
62
|
-
import { log, logInfo } from "@dxos/log";
|
|
63
|
-
import { buf } from "@dxos/protocols/buf";
|
|
64
|
-
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
65
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
66
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
67
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
68
|
-
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;
|
|
69
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
70
|
-
}
|
|
71
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
72
|
-
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
73
|
-
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
74
|
-
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
75
|
-
var EdgeWsConnection = class extends Resource {
|
|
76
|
-
constructor(_identity, _connectionInfo, _callbacks) {
|
|
77
|
-
super();
|
|
78
|
-
this._identity = _identity;
|
|
79
|
-
this._connectionInfo = _connectionInfo;
|
|
80
|
-
this._callbacks = _callbacks;
|
|
81
|
-
}
|
|
82
|
-
get info() {
|
|
83
|
-
return {
|
|
84
|
-
open: this.isOpen,
|
|
85
|
-
identity: this._identity.identityKey,
|
|
86
|
-
device: this._identity.peerKey
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
send(message) {
|
|
90
|
-
invariant2(this._ws, void 0, {
|
|
91
|
-
F: __dxlog_file2,
|
|
92
|
-
L: 54,
|
|
93
|
-
S: this,
|
|
94
|
-
A: [
|
|
95
|
-
"this._ws",
|
|
96
|
-
""
|
|
97
|
-
]
|
|
98
|
-
});
|
|
99
|
-
log("sending...", {
|
|
100
|
-
peerKey: this._identity.peerKey,
|
|
101
|
-
payload: protocol.getPayloadType(message)
|
|
102
|
-
}, {
|
|
103
|
-
F: __dxlog_file2,
|
|
104
|
-
L: 55,
|
|
105
|
-
S: this,
|
|
106
|
-
C: (f, a) => f(...a)
|
|
107
|
-
});
|
|
108
|
-
const encoded = buf.toBinary(MessageSchema, message);
|
|
109
|
-
if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
110
|
-
log.error("edge message dropped due to websocket message limit", {
|
|
111
|
-
byteLength: encoded.byteLength,
|
|
112
|
-
serviceId: message.serviceId,
|
|
113
|
-
payload: protocol.getPayloadType(message)
|
|
114
|
-
}, {
|
|
115
|
-
F: __dxlog_file2,
|
|
116
|
-
L: 58,
|
|
117
|
-
S: this,
|
|
118
|
-
C: (f, a) => f(...a)
|
|
119
|
-
});
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
this._ws.send(encoded);
|
|
123
|
-
}
|
|
124
|
-
async _open() {
|
|
125
|
-
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
126
|
-
this._connectionInfo.protocolHeader
|
|
127
|
-
] : []);
|
|
128
|
-
this._ws.onopen = () => {
|
|
129
|
-
if (this.isOpen) {
|
|
130
|
-
log("connected", void 0, {
|
|
131
|
-
F: __dxlog_file2,
|
|
132
|
-
L: 76,
|
|
133
|
-
S: this,
|
|
134
|
-
C: (f, a) => f(...a)
|
|
135
|
-
});
|
|
136
|
-
this._callbacks.onConnected();
|
|
137
|
-
this._scheduleHeartbeats();
|
|
138
|
-
} else {
|
|
139
|
-
log.verbose("connected after becoming inactive", {
|
|
140
|
-
currentIdentity: this._identity
|
|
141
|
-
}, {
|
|
142
|
-
F: __dxlog_file2,
|
|
143
|
-
L: 80,
|
|
144
|
-
S: this,
|
|
145
|
-
C: (f, a) => f(...a)
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
this._ws.onclose = (event) => {
|
|
150
|
-
if (this.isOpen) {
|
|
151
|
-
log.warn("disconnected while being open", {
|
|
152
|
-
code: event.code,
|
|
153
|
-
reason: event.reason
|
|
154
|
-
}, {
|
|
155
|
-
F: __dxlog_file2,
|
|
156
|
-
L: 85,
|
|
157
|
-
S: this,
|
|
158
|
-
C: (f, a) => f(...a)
|
|
159
|
-
});
|
|
160
|
-
this._callbacks.onRestartRequired();
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
this._ws.onerror = (event) => {
|
|
164
|
-
if (this.isOpen) {
|
|
165
|
-
log.warn("edge connection socket error", {
|
|
166
|
-
error: event.error,
|
|
167
|
-
info: event.message
|
|
168
|
-
}, {
|
|
169
|
-
F: __dxlog_file2,
|
|
170
|
-
L: 91,
|
|
171
|
-
S: this,
|
|
172
|
-
C: (f, a) => f(...a)
|
|
173
|
-
});
|
|
174
|
-
this._callbacks.onRestartRequired();
|
|
175
|
-
} else {
|
|
176
|
-
log.verbose("error ignored on closed connection", {
|
|
177
|
-
error: event.error
|
|
178
|
-
}, {
|
|
179
|
-
F: __dxlog_file2,
|
|
180
|
-
L: 94,
|
|
181
|
-
S: this,
|
|
182
|
-
C: (f, a) => f(...a)
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
this._ws.onmessage = async (event) => {
|
|
187
|
-
if (!this.isOpen) {
|
|
188
|
-
log.verbose("message ignored on closed connection", {
|
|
189
|
-
event: event.type
|
|
190
|
-
}, {
|
|
191
|
-
F: __dxlog_file2,
|
|
192
|
-
L: 102,
|
|
193
|
-
S: this,
|
|
194
|
-
C: (f, a) => f(...a)
|
|
195
|
-
});
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (event.data === "__pong__") {
|
|
199
|
-
this._rescheduleHeartbeatTimeout();
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const data = await toUint8Array(event.data);
|
|
203
|
-
if (this.isOpen) {
|
|
204
|
-
const message = buf.fromBinary(MessageSchema, data);
|
|
205
|
-
log("received", {
|
|
206
|
-
from: message.source,
|
|
207
|
-
payload: protocol.getPayloadType(message)
|
|
208
|
-
}, {
|
|
209
|
-
F: __dxlog_file2,
|
|
210
|
-
L: 112,
|
|
211
|
-
S: this,
|
|
212
|
-
C: (f, a) => f(...a)
|
|
213
|
-
});
|
|
214
|
-
this._callbacks.onMessage(message);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
async _close() {
|
|
219
|
-
void this._inactivityTimeoutCtx?.dispose().catch(() => {
|
|
220
|
-
});
|
|
221
|
-
try {
|
|
222
|
-
this._ws?.close();
|
|
223
|
-
this._ws = void 0;
|
|
224
|
-
} catch (err) {
|
|
225
|
-
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
log.warn("Error closing websocket", {
|
|
229
|
-
err
|
|
230
|
-
}, {
|
|
231
|
-
F: __dxlog_file2,
|
|
232
|
-
L: 128,
|
|
233
|
-
S: this,
|
|
234
|
-
C: (f, a) => f(...a)
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
_scheduleHeartbeats() {
|
|
239
|
-
invariant2(this._ws, void 0, {
|
|
240
|
-
F: __dxlog_file2,
|
|
241
|
-
L: 133,
|
|
242
|
-
S: this,
|
|
243
|
-
A: [
|
|
244
|
-
"this._ws",
|
|
245
|
-
""
|
|
246
|
-
]
|
|
247
|
-
});
|
|
248
|
-
scheduleTaskInterval(this._ctx, async () => {
|
|
249
|
-
this._ws?.send("__ping__");
|
|
250
|
-
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
251
|
-
this._ws.send("__ping__");
|
|
252
|
-
this._rescheduleHeartbeatTimeout();
|
|
253
|
-
}
|
|
254
|
-
_rescheduleHeartbeatTimeout() {
|
|
255
|
-
if (!this.isOpen) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
void this._inactivityTimeoutCtx?.dispose();
|
|
259
|
-
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
260
|
-
F: __dxlog_file2,
|
|
261
|
-
L: 152
|
|
262
|
-
});
|
|
263
|
-
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
264
|
-
if (this.isOpen) {
|
|
265
|
-
log.warn("restart due to inactivity timeout", void 0, {
|
|
266
|
-
F: __dxlog_file2,
|
|
267
|
-
L: 157,
|
|
268
|
-
S: this,
|
|
269
|
-
C: (f, a) => f(...a)
|
|
270
|
-
});
|
|
271
|
-
this._callbacks.onRestartRequired();
|
|
272
|
-
}
|
|
273
|
-
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
_ts_decorate([
|
|
277
|
-
logInfo
|
|
278
|
-
], EdgeWsConnection.prototype, "info", null);
|
|
279
|
-
|
|
280
58
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
281
59
|
var EdgeConnectionClosedError = class extends Error {
|
|
282
60
|
constructor() {
|
|
@@ -298,15 +76,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
298
76
|
};
|
|
299
77
|
|
|
300
78
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
301
|
-
function
|
|
79
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
302
80
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
303
81
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
304
82
|
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;
|
|
305
83
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
306
84
|
}
|
|
307
|
-
var
|
|
85
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
308
86
|
var DEFAULT_TIMEOUT = 1e4;
|
|
309
|
-
var EdgeClient = class extends
|
|
87
|
+
var EdgeClient = class extends Resource {
|
|
310
88
|
constructor(_identity, _config) {
|
|
311
89
|
super();
|
|
312
90
|
this._identity = _identity;
|
|
@@ -343,18 +121,18 @@ var EdgeClient = class extends Resource2 {
|
|
|
343
121
|
}
|
|
344
122
|
setIdentity(identity) {
|
|
345
123
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
346
|
-
|
|
124
|
+
log("Edge identity changed", {
|
|
347
125
|
identity,
|
|
348
126
|
oldIdentity: this._identity
|
|
349
127
|
}, {
|
|
350
|
-
F:
|
|
128
|
+
F: __dxlog_file2,
|
|
351
129
|
L: 99,
|
|
352
130
|
S: this,
|
|
353
131
|
C: (f, a) => f(...a)
|
|
354
132
|
});
|
|
355
133
|
this._identity = identity;
|
|
356
134
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
357
|
-
this._persistentLifecycle.scheduleRestart();
|
|
135
|
+
void this._persistentLifecycle.scheduleRestart();
|
|
358
136
|
}
|
|
359
137
|
}
|
|
360
138
|
onMessage(listener) {
|
|
@@ -369,8 +147,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
369
147
|
try {
|
|
370
148
|
listener();
|
|
371
149
|
} catch (error) {
|
|
372
|
-
|
|
373
|
-
F:
|
|
150
|
+
log.catch(error, void 0, {
|
|
151
|
+
F: __dxlog_file2,
|
|
374
152
|
L: 121,
|
|
375
153
|
S: this,
|
|
376
154
|
C: (f, a) => f(...a)
|
|
@@ -385,19 +163,19 @@ var EdgeClient = class extends Resource2 {
|
|
|
385
163
|
* Open connection to messaging service.
|
|
386
164
|
*/
|
|
387
165
|
async _open() {
|
|
388
|
-
|
|
166
|
+
log("opening...", {
|
|
389
167
|
info: this.info
|
|
390
168
|
}, {
|
|
391
|
-
F:
|
|
169
|
+
F: __dxlog_file2,
|
|
392
170
|
L: 133,
|
|
393
171
|
S: this,
|
|
394
172
|
C: (f, a) => f(...a)
|
|
395
173
|
});
|
|
396
174
|
this._persistentLifecycle.open().catch((err) => {
|
|
397
|
-
|
|
175
|
+
log.warn("Error while opening connection", {
|
|
398
176
|
err
|
|
399
177
|
}, {
|
|
400
|
-
F:
|
|
178
|
+
F: __dxlog_file2,
|
|
401
179
|
L: 135,
|
|
402
180
|
S: this,
|
|
403
181
|
C: (f, a) => f(...a)
|
|
@@ -408,10 +186,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
408
186
|
* Close connection and free resources.
|
|
409
187
|
*/
|
|
410
188
|
async _close() {
|
|
411
|
-
|
|
189
|
+
log("closing...", {
|
|
412
190
|
peerKey: this._identity.peerKey
|
|
413
191
|
}, {
|
|
414
|
-
F:
|
|
192
|
+
F: __dxlog_file2,
|
|
415
193
|
L: 143,
|
|
416
194
|
S: this,
|
|
417
195
|
C: (f, a) => f(...a)
|
|
@@ -427,8 +205,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
427
205
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
428
206
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
429
207
|
if (this._identity !== identity) {
|
|
430
|
-
|
|
431
|
-
F:
|
|
208
|
+
log("identity changed during auth header request", void 0, {
|
|
209
|
+
F: __dxlog_file2,
|
|
432
210
|
L: 157,
|
|
433
211
|
S: this,
|
|
434
212
|
C: (f, a) => f(...a)
|
|
@@ -437,11 +215,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
437
215
|
}
|
|
438
216
|
const restartRequired = new Trigger();
|
|
439
217
|
const url = new URL(path, this._baseWsUrl);
|
|
440
|
-
|
|
218
|
+
log("Opening websocket", {
|
|
441
219
|
url: url.toString(),
|
|
442
220
|
protocolHeader
|
|
443
221
|
}, {
|
|
444
|
-
F:
|
|
222
|
+
F: __dxlog_file2,
|
|
445
223
|
L: 163,
|
|
446
224
|
S: this,
|
|
447
225
|
C: (f, a) => f(...a)
|
|
@@ -455,8 +233,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
455
233
|
this._ready.wake();
|
|
456
234
|
this._notifyReconnected();
|
|
457
235
|
} else {
|
|
458
|
-
|
|
459
|
-
F:
|
|
236
|
+
log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
237
|
+
F: __dxlog_file2,
|
|
460
238
|
L: 173,
|
|
461
239
|
S: this,
|
|
462
240
|
C: (f, a) => f(...a)
|
|
@@ -466,10 +244,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
466
244
|
onRestartRequired: () => {
|
|
467
245
|
if (this._isActive(connection)) {
|
|
468
246
|
this._closeCurrentConnection();
|
|
469
|
-
this._persistentLifecycle.scheduleRestart();
|
|
247
|
+
void this._persistentLifecycle.scheduleRestart();
|
|
470
248
|
} else {
|
|
471
|
-
|
|
472
|
-
F:
|
|
249
|
+
log.verbose("restart requested by inactive connection", void 0, {
|
|
250
|
+
F: __dxlog_file2,
|
|
473
251
|
L: 181,
|
|
474
252
|
S: this,
|
|
475
253
|
C: (f, a) => f(...a)
|
|
@@ -481,11 +259,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
481
259
|
if (this._isActive(connection)) {
|
|
482
260
|
this._notifyMessageReceived(message);
|
|
483
261
|
} else {
|
|
484
|
-
|
|
262
|
+
log.verbose("ignored a message on inactive connection", {
|
|
485
263
|
from: message.source,
|
|
486
264
|
type: message.payload?.typeUrl
|
|
487
265
|
}, {
|
|
488
|
-
F:
|
|
266
|
+
F: __dxlog_file2,
|
|
489
267
|
L: 189,
|
|
490
268
|
S: this,
|
|
491
269
|
C: (f, a) => f(...a)
|
|
@@ -519,10 +297,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
519
297
|
try {
|
|
520
298
|
listener();
|
|
521
299
|
} catch (err) {
|
|
522
|
-
|
|
300
|
+
log.error("ws reconnect listener failed", {
|
|
523
301
|
err
|
|
524
302
|
}, {
|
|
525
|
-
F:
|
|
303
|
+
F: __dxlog_file2,
|
|
526
304
|
L: 225,
|
|
527
305
|
S: this,
|
|
528
306
|
C: (f, a) => f(...a)
|
|
@@ -535,11 +313,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
535
313
|
try {
|
|
536
314
|
listener(message);
|
|
537
315
|
} catch (err) {
|
|
538
|
-
|
|
316
|
+
log.error("ws incoming message processing failed", {
|
|
539
317
|
err,
|
|
540
318
|
payload: protocol.getPayloadType(message)
|
|
541
319
|
}, {
|
|
542
|
-
F:
|
|
320
|
+
F: __dxlog_file2,
|
|
543
321
|
L: 235,
|
|
544
322
|
S: this,
|
|
545
323
|
C: (f, a) => f(...a)
|
|
@@ -553,8 +331,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
553
331
|
*/
|
|
554
332
|
async send(message) {
|
|
555
333
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
556
|
-
|
|
557
|
-
F:
|
|
334
|
+
log("waiting for websocket to become ready", void 0, {
|
|
335
|
+
F: __dxlog_file2,
|
|
558
336
|
L: 246,
|
|
559
337
|
S: this,
|
|
560
338
|
C: (f, a) => f(...a)
|
|
@@ -580,11 +358,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
580
358
|
if (response.status === 401) {
|
|
581
359
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
582
360
|
} else {
|
|
583
|
-
|
|
361
|
+
log.warn("no auth challenge from edge", {
|
|
584
362
|
status: response.status,
|
|
585
363
|
statusText: response.statusText
|
|
586
364
|
}, {
|
|
587
|
-
F:
|
|
365
|
+
F: __dxlog_file2,
|
|
588
366
|
L: 271,
|
|
589
367
|
S: this,
|
|
590
368
|
C: (f, a) => f(...a)
|
|
@@ -593,8 +371,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
593
371
|
}
|
|
594
372
|
}
|
|
595
373
|
};
|
|
596
|
-
|
|
597
|
-
|
|
374
|
+
_ts_decorate([
|
|
375
|
+
logInfo
|
|
598
376
|
], EdgeClient.prototype, "info", null);
|
|
599
377
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
600
378
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
@@ -603,10 +381,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
603
381
|
|
|
604
382
|
// packages/core/mesh/edge-client/src/auth.ts
|
|
605
383
|
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
606
|
-
import { invariant as
|
|
384
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
607
385
|
import { Keyring } from "@dxos/keyring";
|
|
608
386
|
import { PublicKey } from "@dxos/keys";
|
|
609
|
-
var
|
|
387
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
610
388
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
611
389
|
return {
|
|
612
390
|
identityKey: key.toHex(),
|
|
@@ -650,8 +428,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
650
428
|
identityKey: identityKey.toHex(),
|
|
651
429
|
peerKey: peerKey.toHex(),
|
|
652
430
|
presentCredentials: async ({ challenge }) => {
|
|
653
|
-
|
|
654
|
-
F:
|
|
431
|
+
invariant2(chain, void 0, {
|
|
432
|
+
F: __dxlog_file3,
|
|
655
433
|
L: 75,
|
|
656
434
|
S: void 0,
|
|
657
435
|
A: [
|
|
@@ -714,20 +492,20 @@ var createStubEdgeIdentity = () => {
|
|
|
714
492
|
|
|
715
493
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
716
494
|
import { sleep } from "@dxos/async";
|
|
717
|
-
import { Context
|
|
718
|
-
import { log as
|
|
495
|
+
import { Context } from "@dxos/context";
|
|
496
|
+
import { log as log2 } from "@dxos/log";
|
|
719
497
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
720
|
-
var
|
|
498
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
721
499
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
722
500
|
var DEFAULT_RETRY_JITTER = 500;
|
|
723
501
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
724
502
|
var EdgeHttpClient = class {
|
|
725
503
|
constructor(baseUrl) {
|
|
726
504
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
727
|
-
|
|
505
|
+
log2("created", {
|
|
728
506
|
url: this._baseUrl
|
|
729
507
|
}, {
|
|
730
|
-
F:
|
|
508
|
+
F: __dxlog_file4,
|
|
731
509
|
L: 53,
|
|
732
510
|
S: this,
|
|
733
511
|
C: (f, a) => f(...a)
|
|
@@ -859,8 +637,8 @@ var EdgeHttpClient = class {
|
|
|
859
637
|
});
|
|
860
638
|
}
|
|
861
639
|
async _call(path, args) {
|
|
862
|
-
const requestContext = args.context ?? new
|
|
863
|
-
F:
|
|
640
|
+
const requestContext = args.context ?? new Context(void 0, {
|
|
641
|
+
F: __dxlog_file4,
|
|
864
642
|
L: 192
|
|
865
643
|
});
|
|
866
644
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -872,12 +650,12 @@ var EdgeHttpClient = class {
|
|
|
872
650
|
}
|
|
873
651
|
url += `?${queryParams.toString()}`;
|
|
874
652
|
}
|
|
875
|
-
|
|
653
|
+
log2("call", {
|
|
876
654
|
method: args.method,
|
|
877
655
|
path,
|
|
878
656
|
request: args.body
|
|
879
657
|
}, {
|
|
880
|
-
F:
|
|
658
|
+
F: __dxlog_file4,
|
|
881
659
|
L: 204,
|
|
882
660
|
S: this,
|
|
883
661
|
C: (f, a) => f(...a)
|
|
@@ -896,11 +674,11 @@ var EdgeHttpClient = class {
|
|
|
896
674
|
if (body.success) {
|
|
897
675
|
return body.data;
|
|
898
676
|
}
|
|
899
|
-
|
|
677
|
+
log2("unsuccessful edge response", {
|
|
900
678
|
path,
|
|
901
679
|
body
|
|
902
680
|
}, {
|
|
903
|
-
F:
|
|
681
|
+
F: __dxlog_file4,
|
|
904
682
|
L: 223,
|
|
905
683
|
S: this,
|
|
906
684
|
C: (f, a) => f(...a)
|
|
@@ -921,11 +699,11 @@ var EdgeHttpClient = class {
|
|
|
921
699
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
922
700
|
}
|
|
923
701
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
924
|
-
|
|
702
|
+
log2("retrying edge request", {
|
|
925
703
|
path,
|
|
926
704
|
processingError
|
|
927
705
|
}, {
|
|
928
|
-
F:
|
|
706
|
+
F: __dxlog_file4,
|
|
929
707
|
L: 242,
|
|
930
708
|
S: this,
|
|
931
709
|
C: (f, a) => f(...a)
|
|
@@ -937,8 +715,8 @@ var EdgeHttpClient = class {
|
|
|
937
715
|
}
|
|
938
716
|
async _handleUnauthorized(response) {
|
|
939
717
|
if (!this._edgeIdentity) {
|
|
940
|
-
|
|
941
|
-
F:
|
|
718
|
+
log2.warn("edge unauthorized response received before identity was set", void 0, {
|
|
719
|
+
F: __dxlog_file4,
|
|
942
720
|
L: 251,
|
|
943
721
|
S: this,
|
|
944
722
|
C: (f, a) => f(...a)
|
|
@@ -947,8 +725,8 @@ var EdgeHttpClient = class {
|
|
|
947
725
|
}
|
|
948
726
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
949
727
|
this._authHeader = encodeAuthHeader(challenge);
|
|
950
|
-
|
|
951
|
-
F:
|
|
728
|
+
log2("auth header updated", void 0, {
|
|
729
|
+
F: __dxlog_file4,
|
|
952
730
|
L: 256,
|
|
953
731
|
S: this,
|
|
954
732
|
C: (f, a) => f(...a)
|