@dxos/edge-client 0.8.2-main.f081794 → 0.8.2-main.f11618f
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-5DDWS5EC.mjs +546 -0
- package/dist/lib/browser/chunk-5DDWS5EC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +64 -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-CNAHGYSS.cjs +579 -0
- package/dist/lib/node/chunk-CNAHGYSS.cjs.map +7 -0
- package/dist/lib/node/index.cjs +54 -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-O4TFZRSP.mjs +548 -0
- package/dist/lib/node-esm/chunk-O4TFZRSP.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +64 -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/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- 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/index.ts +1 -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,20 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CLOUDFLARE_MESSAGE_LENGTH_LIMIT,
|
|
3
|
+
EdgeWsConnection,
|
|
2
4
|
Protocol,
|
|
5
|
+
WebSocketMuxer,
|
|
3
6
|
getTypename,
|
|
4
7
|
protocol,
|
|
5
8
|
toUint8Array
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-5DDWS5EC.mjs";
|
|
7
10
|
|
|
8
11
|
// packages/core/mesh/edge-client/src/index.ts
|
|
9
12
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
10
13
|
|
|
11
14
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
12
15
|
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
|
|
13
|
-
import { Resource
|
|
14
|
-
import { log
|
|
16
|
+
import { Resource } from "@dxos/context";
|
|
17
|
+
import { log, logInfo } from "@dxos/log";
|
|
15
18
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
16
19
|
|
|
17
20
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
@@ -54,229 +57,6 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
54
57
|
return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
55
58
|
};
|
|
56
59
|
|
|
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
60
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
281
61
|
var EdgeConnectionClosedError = class extends Error {
|
|
282
62
|
constructor() {
|
|
@@ -298,15 +78,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
298
78
|
};
|
|
299
79
|
|
|
300
80
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
301
|
-
function
|
|
81
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
302
82
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
303
83
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
304
84
|
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
85
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
306
86
|
}
|
|
307
|
-
var
|
|
87
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
308
88
|
var DEFAULT_TIMEOUT = 1e4;
|
|
309
|
-
var EdgeClient = class extends
|
|
89
|
+
var EdgeClient = class extends Resource {
|
|
310
90
|
constructor(_identity, _config) {
|
|
311
91
|
super();
|
|
312
92
|
this._identity = _identity;
|
|
@@ -343,18 +123,18 @@ var EdgeClient = class extends Resource2 {
|
|
|
343
123
|
}
|
|
344
124
|
setIdentity(identity) {
|
|
345
125
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
346
|
-
|
|
126
|
+
log("Edge identity changed", {
|
|
347
127
|
identity,
|
|
348
128
|
oldIdentity: this._identity
|
|
349
129
|
}, {
|
|
350
|
-
F:
|
|
130
|
+
F: __dxlog_file2,
|
|
351
131
|
L: 99,
|
|
352
132
|
S: this,
|
|
353
133
|
C: (f, a) => f(...a)
|
|
354
134
|
});
|
|
355
135
|
this._identity = identity;
|
|
356
136
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
357
|
-
this._persistentLifecycle.scheduleRestart();
|
|
137
|
+
void this._persistentLifecycle.scheduleRestart();
|
|
358
138
|
}
|
|
359
139
|
}
|
|
360
140
|
onMessage(listener) {
|
|
@@ -369,8 +149,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
369
149
|
try {
|
|
370
150
|
listener();
|
|
371
151
|
} catch (error) {
|
|
372
|
-
|
|
373
|
-
F:
|
|
152
|
+
log.catch(error, void 0, {
|
|
153
|
+
F: __dxlog_file2,
|
|
374
154
|
L: 121,
|
|
375
155
|
S: this,
|
|
376
156
|
C: (f, a) => f(...a)
|
|
@@ -385,19 +165,19 @@ var EdgeClient = class extends Resource2 {
|
|
|
385
165
|
* Open connection to messaging service.
|
|
386
166
|
*/
|
|
387
167
|
async _open() {
|
|
388
|
-
|
|
168
|
+
log("opening...", {
|
|
389
169
|
info: this.info
|
|
390
170
|
}, {
|
|
391
|
-
F:
|
|
171
|
+
F: __dxlog_file2,
|
|
392
172
|
L: 133,
|
|
393
173
|
S: this,
|
|
394
174
|
C: (f, a) => f(...a)
|
|
395
175
|
});
|
|
396
176
|
this._persistentLifecycle.open().catch((err) => {
|
|
397
|
-
|
|
177
|
+
log.warn("Error while opening connection", {
|
|
398
178
|
err
|
|
399
179
|
}, {
|
|
400
|
-
F:
|
|
180
|
+
F: __dxlog_file2,
|
|
401
181
|
L: 135,
|
|
402
182
|
S: this,
|
|
403
183
|
C: (f, a) => f(...a)
|
|
@@ -408,10 +188,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
408
188
|
* Close connection and free resources.
|
|
409
189
|
*/
|
|
410
190
|
async _close() {
|
|
411
|
-
|
|
191
|
+
log("closing...", {
|
|
412
192
|
peerKey: this._identity.peerKey
|
|
413
193
|
}, {
|
|
414
|
-
F:
|
|
194
|
+
F: __dxlog_file2,
|
|
415
195
|
L: 143,
|
|
416
196
|
S: this,
|
|
417
197
|
C: (f, a) => f(...a)
|
|
@@ -427,8 +207,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
427
207
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
428
208
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
429
209
|
if (this._identity !== identity) {
|
|
430
|
-
|
|
431
|
-
F:
|
|
210
|
+
log("identity changed during auth header request", void 0, {
|
|
211
|
+
F: __dxlog_file2,
|
|
432
212
|
L: 157,
|
|
433
213
|
S: this,
|
|
434
214
|
C: (f, a) => f(...a)
|
|
@@ -437,11 +217,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
437
217
|
}
|
|
438
218
|
const restartRequired = new Trigger();
|
|
439
219
|
const url = new URL(path, this._baseWsUrl);
|
|
440
|
-
|
|
220
|
+
log("Opening websocket", {
|
|
441
221
|
url: url.toString(),
|
|
442
222
|
protocolHeader
|
|
443
223
|
}, {
|
|
444
|
-
F:
|
|
224
|
+
F: __dxlog_file2,
|
|
445
225
|
L: 163,
|
|
446
226
|
S: this,
|
|
447
227
|
C: (f, a) => f(...a)
|
|
@@ -455,8 +235,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
455
235
|
this._ready.wake();
|
|
456
236
|
this._notifyReconnected();
|
|
457
237
|
} else {
|
|
458
|
-
|
|
459
|
-
F:
|
|
238
|
+
log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
239
|
+
F: __dxlog_file2,
|
|
460
240
|
L: 173,
|
|
461
241
|
S: this,
|
|
462
242
|
C: (f, a) => f(...a)
|
|
@@ -466,10 +246,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
466
246
|
onRestartRequired: () => {
|
|
467
247
|
if (this._isActive(connection)) {
|
|
468
248
|
this._closeCurrentConnection();
|
|
469
|
-
this._persistentLifecycle.scheduleRestart();
|
|
249
|
+
void this._persistentLifecycle.scheduleRestart();
|
|
470
250
|
} else {
|
|
471
|
-
|
|
472
|
-
F:
|
|
251
|
+
log.verbose("restart requested by inactive connection", void 0, {
|
|
252
|
+
F: __dxlog_file2,
|
|
473
253
|
L: 181,
|
|
474
254
|
S: this,
|
|
475
255
|
C: (f, a) => f(...a)
|
|
@@ -481,11 +261,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
481
261
|
if (this._isActive(connection)) {
|
|
482
262
|
this._notifyMessageReceived(message);
|
|
483
263
|
} else {
|
|
484
|
-
|
|
264
|
+
log.verbose("ignored a message on inactive connection", {
|
|
485
265
|
from: message.source,
|
|
486
266
|
type: message.payload?.typeUrl
|
|
487
267
|
}, {
|
|
488
|
-
F:
|
|
268
|
+
F: __dxlog_file2,
|
|
489
269
|
L: 189,
|
|
490
270
|
S: this,
|
|
491
271
|
C: (f, a) => f(...a)
|
|
@@ -519,10 +299,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
519
299
|
try {
|
|
520
300
|
listener();
|
|
521
301
|
} catch (err) {
|
|
522
|
-
|
|
302
|
+
log.error("ws reconnect listener failed", {
|
|
523
303
|
err
|
|
524
304
|
}, {
|
|
525
|
-
F:
|
|
305
|
+
F: __dxlog_file2,
|
|
526
306
|
L: 225,
|
|
527
307
|
S: this,
|
|
528
308
|
C: (f, a) => f(...a)
|
|
@@ -535,11 +315,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
535
315
|
try {
|
|
536
316
|
listener(message);
|
|
537
317
|
} catch (err) {
|
|
538
|
-
|
|
318
|
+
log.error("ws incoming message processing failed", {
|
|
539
319
|
err,
|
|
540
320
|
payload: protocol.getPayloadType(message)
|
|
541
321
|
}, {
|
|
542
|
-
F:
|
|
322
|
+
F: __dxlog_file2,
|
|
543
323
|
L: 235,
|
|
544
324
|
S: this,
|
|
545
325
|
C: (f, a) => f(...a)
|
|
@@ -553,8 +333,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
553
333
|
*/
|
|
554
334
|
async send(message) {
|
|
555
335
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
556
|
-
|
|
557
|
-
F:
|
|
336
|
+
log("waiting for websocket to become ready", void 0, {
|
|
337
|
+
F: __dxlog_file2,
|
|
558
338
|
L: 246,
|
|
559
339
|
S: this,
|
|
560
340
|
C: (f, a) => f(...a)
|
|
@@ -580,11 +360,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
580
360
|
if (response.status === 401) {
|
|
581
361
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
582
362
|
} else {
|
|
583
|
-
|
|
363
|
+
log.warn("no auth challenge from edge", {
|
|
584
364
|
status: response.status,
|
|
585
365
|
statusText: response.statusText
|
|
586
366
|
}, {
|
|
587
|
-
F:
|
|
367
|
+
F: __dxlog_file2,
|
|
588
368
|
L: 271,
|
|
589
369
|
S: this,
|
|
590
370
|
C: (f, a) => f(...a)
|
|
@@ -593,8 +373,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
593
373
|
}
|
|
594
374
|
}
|
|
595
375
|
};
|
|
596
|
-
|
|
597
|
-
|
|
376
|
+
_ts_decorate([
|
|
377
|
+
logInfo
|
|
598
378
|
], EdgeClient.prototype, "info", null);
|
|
599
379
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
600
380
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
@@ -603,10 +383,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
603
383
|
|
|
604
384
|
// packages/core/mesh/edge-client/src/auth.ts
|
|
605
385
|
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
606
|
-
import { invariant as
|
|
386
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
607
387
|
import { Keyring } from "@dxos/keyring";
|
|
608
388
|
import { PublicKey } from "@dxos/keys";
|
|
609
|
-
var
|
|
389
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
610
390
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
611
391
|
return {
|
|
612
392
|
identityKey: key.toHex(),
|
|
@@ -650,8 +430,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
650
430
|
identityKey: identityKey.toHex(),
|
|
651
431
|
peerKey: peerKey.toHex(),
|
|
652
432
|
presentCredentials: async ({ challenge }) => {
|
|
653
|
-
|
|
654
|
-
F:
|
|
433
|
+
invariant2(chain, void 0, {
|
|
434
|
+
F: __dxlog_file3,
|
|
655
435
|
L: 75,
|
|
656
436
|
S: void 0,
|
|
657
437
|
A: [
|
|
@@ -714,20 +494,20 @@ var createStubEdgeIdentity = () => {
|
|
|
714
494
|
|
|
715
495
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
716
496
|
import { sleep } from "@dxos/async";
|
|
717
|
-
import { Context
|
|
718
|
-
import { log as
|
|
497
|
+
import { Context } from "@dxos/context";
|
|
498
|
+
import { log as log2 } from "@dxos/log";
|
|
719
499
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
720
|
-
var
|
|
500
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
721
501
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
722
502
|
var DEFAULT_RETRY_JITTER = 500;
|
|
723
503
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
724
504
|
var EdgeHttpClient = class {
|
|
725
505
|
constructor(baseUrl) {
|
|
726
506
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
727
|
-
|
|
507
|
+
log2("created", {
|
|
728
508
|
url: this._baseUrl
|
|
729
509
|
}, {
|
|
730
|
-
F:
|
|
510
|
+
F: __dxlog_file4,
|
|
731
511
|
L: 53,
|
|
732
512
|
S: this,
|
|
733
513
|
C: (f, a) => f(...a)
|
|
@@ -859,8 +639,8 @@ var EdgeHttpClient = class {
|
|
|
859
639
|
});
|
|
860
640
|
}
|
|
861
641
|
async _call(path, args) {
|
|
862
|
-
const requestContext = args.context ?? new
|
|
863
|
-
F:
|
|
642
|
+
const requestContext = args.context ?? new Context(void 0, {
|
|
643
|
+
F: __dxlog_file4,
|
|
864
644
|
L: 192
|
|
865
645
|
});
|
|
866
646
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -872,12 +652,12 @@ var EdgeHttpClient = class {
|
|
|
872
652
|
}
|
|
873
653
|
url += `?${queryParams.toString()}`;
|
|
874
654
|
}
|
|
875
|
-
|
|
655
|
+
log2("call", {
|
|
876
656
|
method: args.method,
|
|
877
657
|
path,
|
|
878
658
|
request: args.body
|
|
879
659
|
}, {
|
|
880
|
-
F:
|
|
660
|
+
F: __dxlog_file4,
|
|
881
661
|
L: 204,
|
|
882
662
|
S: this,
|
|
883
663
|
C: (f, a) => f(...a)
|
|
@@ -896,11 +676,11 @@ var EdgeHttpClient = class {
|
|
|
896
676
|
if (body.success) {
|
|
897
677
|
return body.data;
|
|
898
678
|
}
|
|
899
|
-
|
|
679
|
+
log2("unsuccessful edge response", {
|
|
900
680
|
path,
|
|
901
681
|
body
|
|
902
682
|
}, {
|
|
903
|
-
F:
|
|
683
|
+
F: __dxlog_file4,
|
|
904
684
|
L: 223,
|
|
905
685
|
S: this,
|
|
906
686
|
C: (f, a) => f(...a)
|
|
@@ -921,11 +701,11 @@ var EdgeHttpClient = class {
|
|
|
921
701
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
922
702
|
}
|
|
923
703
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
924
|
-
|
|
704
|
+
log2("retrying edge request", {
|
|
925
705
|
path,
|
|
926
706
|
processingError
|
|
927
707
|
}, {
|
|
928
|
-
F:
|
|
708
|
+
F: __dxlog_file4,
|
|
929
709
|
L: 242,
|
|
930
710
|
S: this,
|
|
931
711
|
C: (f, a) => f(...a)
|
|
@@ -937,8 +717,8 @@ var EdgeHttpClient = class {
|
|
|
937
717
|
}
|
|
938
718
|
async _handleUnauthorized(response) {
|
|
939
719
|
if (!this._edgeIdentity) {
|
|
940
|
-
|
|
941
|
-
F:
|
|
720
|
+
log2.warn("edge unauthorized response received before identity was set", void 0, {
|
|
721
|
+
F: __dxlog_file4,
|
|
942
722
|
L: 251,
|
|
943
723
|
S: this,
|
|
944
724
|
C: (f, a) => f(...a)
|
|
@@ -947,8 +727,8 @@ var EdgeHttpClient = class {
|
|
|
947
727
|
}
|
|
948
728
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
949
729
|
this._authHeader = encodeAuthHeader(challenge);
|
|
950
|
-
|
|
951
|
-
F:
|
|
730
|
+
log2("auth header updated", void 0, {
|
|
731
|
+
F: __dxlog_file4,
|
|
952
732
|
L: 256,
|
|
953
733
|
S: this,
|
|
954
734
|
C: (f, a) => f(...a)
|
|
@@ -991,11 +771,13 @@ var encodeAuthHeader = (challenge) => {
|
|
|
991
771
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
992
772
|
};
|
|
993
773
|
export {
|
|
774
|
+
CLOUDFLARE_MESSAGE_LENGTH_LIMIT,
|
|
994
775
|
EdgeClient,
|
|
995
776
|
EdgeConnectionClosedError,
|
|
996
777
|
EdgeHttpClient,
|
|
997
778
|
EdgeIdentityChangedError,
|
|
998
779
|
Protocol,
|
|
780
|
+
WebSocketMuxer,
|
|
999
781
|
createChainEdgeIdentity,
|
|
1000
782
|
createDeviceEdgeIdentity,
|
|
1001
783
|
createEphemeralEdgeIdentity,
|