@dxos/edge-client 0.8.2-main.2f9c567 → 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 +58 -318
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- 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 +53 -322
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +5 -6
- 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 +58 -318
- 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 +3 -3
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-ws-connection.d.ts +4 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +7 -19
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/package.json +14 -19
- package/src/edge-ws-connection.ts +11 -6
- package/src/edge-ws-muxer.ts +33 -63
- package/src/index.ts +0 -1
- package/src/testing/test-utils.ts +2 -2
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs +0 -302
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs.map +0 -7
- package/dist/lib/browser/edge-ws-muxer.mjs +0 -11
- package/dist/lib/browser/edge-ws-muxer.mjs.map +0 -7
- package/dist/lib/node/chunk-ZOL3YSDR.cjs +0 -322
- package/dist/lib/node/chunk-ZOL3YSDR.cjs.map +0 -7
- package/dist/lib/node/edge-ws-muxer.cjs +0 -33
- package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs +0 -304
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
- package/dist/types/src/edge-ws-muxer.test.d.ts +0 -2
- package/dist/types/src/edge-ws-muxer.test.d.ts.map +0 -1
- package/src/edge-ws-muxer.test.ts +0 -55
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
CLOUDFLARE_RPC_MAX_BYTES,
|
|
2
|
+
EdgeWsConnection,
|
|
4
3
|
Protocol,
|
|
5
|
-
WebSocketMuxer,
|
|
6
4
|
getTypename,
|
|
7
5
|
protocol,
|
|
8
6
|
toUint8Array
|
|
9
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-XS3TKGM4.mjs";
|
|
10
8
|
|
|
11
9
|
// packages/core/mesh/edge-client/src/index.ts
|
|
12
10
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
13
11
|
|
|
14
12
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
15
13
|
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
|
|
16
|
-
import { Resource
|
|
17
|
-
import { log
|
|
14
|
+
import { Resource } from "@dxos/context";
|
|
15
|
+
import { log, logInfo } from "@dxos/log";
|
|
18
16
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
19
17
|
|
|
20
18
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
@@ -57,261 +55,6 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
57
55
|
return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
58
56
|
};
|
|
59
57
|
|
|
60
|
-
// packages/core/mesh/edge-client/src/edge-ws-connection.ts
|
|
61
|
-
import WebSocket from "isomorphic-ws";
|
|
62
|
-
import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
63
|
-
import { Context, Resource } from "@dxos/context";
|
|
64
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
65
|
-
import { log, logInfo } from "@dxos/log";
|
|
66
|
-
import { EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
67
|
-
import { buf } from "@dxos/protocols/buf";
|
|
68
|
-
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
69
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
70
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
71
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
72
|
-
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;
|
|
73
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
74
|
-
}
|
|
75
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
76
|
-
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
77
|
-
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
78
|
-
var EdgeWsConnection = class extends Resource {
|
|
79
|
-
constructor(_identity, _connectionInfo, _callbacks) {
|
|
80
|
-
super();
|
|
81
|
-
this._identity = _identity;
|
|
82
|
-
this._connectionInfo = _connectionInfo;
|
|
83
|
-
this._callbacks = _callbacks;
|
|
84
|
-
}
|
|
85
|
-
get info() {
|
|
86
|
-
return {
|
|
87
|
-
open: this.isOpen,
|
|
88
|
-
identity: this._identity.identityKey,
|
|
89
|
-
device: this._identity.peerKey
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
send(message) {
|
|
93
|
-
invariant2(this._ws, void 0, {
|
|
94
|
-
F: __dxlog_file2,
|
|
95
|
-
L: 52,
|
|
96
|
-
S: this,
|
|
97
|
-
A: [
|
|
98
|
-
"this._ws",
|
|
99
|
-
""
|
|
100
|
-
]
|
|
101
|
-
});
|
|
102
|
-
invariant2(this._wsMuxer, void 0, {
|
|
103
|
-
F: __dxlog_file2,
|
|
104
|
-
L: 53,
|
|
105
|
-
S: this,
|
|
106
|
-
A: [
|
|
107
|
-
"this._wsMuxer",
|
|
108
|
-
""
|
|
109
|
-
]
|
|
110
|
-
});
|
|
111
|
-
log("sending...", {
|
|
112
|
-
peerKey: this._identity.peerKey,
|
|
113
|
-
payload: protocol.getPayloadType(message)
|
|
114
|
-
}, {
|
|
115
|
-
F: __dxlog_file2,
|
|
116
|
-
L: 54,
|
|
117
|
-
S: this,
|
|
118
|
-
C: (f, a) => f(...a)
|
|
119
|
-
});
|
|
120
|
-
if (this._ws?.protocol.includes(EdgeWebsocketProtocol.V0)) {
|
|
121
|
-
const binary = buf.toBinary(MessageSchema, message);
|
|
122
|
-
if (binary.length > CLOUDFLARE_MESSAGE_MAX_BYTES) {
|
|
123
|
-
log.error("Message dropped because it was too large (>1MB).", {
|
|
124
|
-
byteLength: binary.byteLength,
|
|
125
|
-
serviceId: message.serviceId,
|
|
126
|
-
payload: protocol.getPayloadType(message)
|
|
127
|
-
}, {
|
|
128
|
-
F: __dxlog_file2,
|
|
129
|
-
L: 58,
|
|
130
|
-
S: this,
|
|
131
|
-
C: (f, a) => f(...a)
|
|
132
|
-
});
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
this._ws.send(binary);
|
|
136
|
-
} else {
|
|
137
|
-
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
138
|
-
F: __dxlog_file2,
|
|
139
|
-
L: 67,
|
|
140
|
-
S: this,
|
|
141
|
-
C: (f, a) => f(...a)
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async _open() {
|
|
146
|
-
const baseProtocols = [
|
|
147
|
-
...Object.values(EdgeWebsocketProtocol)
|
|
148
|
-
];
|
|
149
|
-
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
150
|
-
...baseProtocols,
|
|
151
|
-
this._connectionInfo.protocolHeader
|
|
152
|
-
] : [
|
|
153
|
-
...baseProtocols
|
|
154
|
-
]);
|
|
155
|
-
const muxer = new WebSocketMuxer(this._ws);
|
|
156
|
-
this._wsMuxer = muxer;
|
|
157
|
-
this._ws.onopen = () => {
|
|
158
|
-
if (this.isOpen) {
|
|
159
|
-
log("connected", void 0, {
|
|
160
|
-
F: __dxlog_file2,
|
|
161
|
-
L: 84,
|
|
162
|
-
S: this,
|
|
163
|
-
C: (f, a) => f(...a)
|
|
164
|
-
});
|
|
165
|
-
this._callbacks.onConnected();
|
|
166
|
-
this._scheduleHeartbeats();
|
|
167
|
-
} else {
|
|
168
|
-
log.verbose("connected after becoming inactive", {
|
|
169
|
-
currentIdentity: this._identity
|
|
170
|
-
}, {
|
|
171
|
-
F: __dxlog_file2,
|
|
172
|
-
L: 88,
|
|
173
|
-
S: this,
|
|
174
|
-
C: (f, a) => f(...a)
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
this._ws.onclose = (event) => {
|
|
179
|
-
if (this.isOpen) {
|
|
180
|
-
log.warn("disconnected while being open", {
|
|
181
|
-
code: event.code,
|
|
182
|
-
reason: event.reason
|
|
183
|
-
}, {
|
|
184
|
-
F: __dxlog_file2,
|
|
185
|
-
L: 93,
|
|
186
|
-
S: this,
|
|
187
|
-
C: (f, a) => f(...a)
|
|
188
|
-
});
|
|
189
|
-
this._callbacks.onRestartRequired();
|
|
190
|
-
muxer.destroy();
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
this._ws.onerror = (event) => {
|
|
194
|
-
if (this.isOpen) {
|
|
195
|
-
log.warn("edge connection socket error", {
|
|
196
|
-
error: event.error,
|
|
197
|
-
info: event.message
|
|
198
|
-
}, {
|
|
199
|
-
F: __dxlog_file2,
|
|
200
|
-
L: 100,
|
|
201
|
-
S: this,
|
|
202
|
-
C: (f, a) => f(...a)
|
|
203
|
-
});
|
|
204
|
-
this._callbacks.onRestartRequired();
|
|
205
|
-
} else {
|
|
206
|
-
log.verbose("error ignored on closed connection", {
|
|
207
|
-
error: event.error
|
|
208
|
-
}, {
|
|
209
|
-
F: __dxlog_file2,
|
|
210
|
-
L: 103,
|
|
211
|
-
S: this,
|
|
212
|
-
C: (f, a) => f(...a)
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
this._ws.onmessage = async (event) => {
|
|
217
|
-
if (!this.isOpen) {
|
|
218
|
-
log.verbose("message ignored on closed connection", {
|
|
219
|
-
event: event.type
|
|
220
|
-
}, {
|
|
221
|
-
F: __dxlog_file2,
|
|
222
|
-
L: 111,
|
|
223
|
-
S: this,
|
|
224
|
-
C: (f, a) => f(...a)
|
|
225
|
-
});
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (event.data === "__pong__") {
|
|
229
|
-
this._rescheduleHeartbeatTimeout();
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const bytes = await toUint8Array(event.data);
|
|
233
|
-
if (!this.isOpen) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0) ? buf.fromBinary(MessageSchema, bytes) : muxer.receiveData(bytes);
|
|
237
|
-
if (message) {
|
|
238
|
-
log("received", {
|
|
239
|
-
from: message.source,
|
|
240
|
-
payload: protocol.getPayloadType(message)
|
|
241
|
-
}, {
|
|
242
|
-
F: __dxlog_file2,
|
|
243
|
-
L: 128,
|
|
244
|
-
S: this,
|
|
245
|
-
C: (f, a) => f(...a)
|
|
246
|
-
});
|
|
247
|
-
this._callbacks.onMessage(message);
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
async _close() {
|
|
252
|
-
void this._inactivityTimeoutCtx?.dispose().catch(() => {
|
|
253
|
-
});
|
|
254
|
-
try {
|
|
255
|
-
this._ws?.close();
|
|
256
|
-
this._ws = void 0;
|
|
257
|
-
this._wsMuxer?.destroy();
|
|
258
|
-
this._wsMuxer = void 0;
|
|
259
|
-
} catch (err) {
|
|
260
|
-
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
log.warn("Error closing websocket", {
|
|
264
|
-
err
|
|
265
|
-
}, {
|
|
266
|
-
F: __dxlog_file2,
|
|
267
|
-
L: 146,
|
|
268
|
-
S: this,
|
|
269
|
-
C: (f, a) => f(...a)
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
_scheduleHeartbeats() {
|
|
274
|
-
invariant2(this._ws, void 0, {
|
|
275
|
-
F: __dxlog_file2,
|
|
276
|
-
L: 151,
|
|
277
|
-
S: this,
|
|
278
|
-
A: [
|
|
279
|
-
"this._ws",
|
|
280
|
-
""
|
|
281
|
-
]
|
|
282
|
-
});
|
|
283
|
-
scheduleTaskInterval(this._ctx, async () => {
|
|
284
|
-
this._ws?.send("__ping__");
|
|
285
|
-
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
286
|
-
this._ws.send("__ping__");
|
|
287
|
-
this._rescheduleHeartbeatTimeout();
|
|
288
|
-
}
|
|
289
|
-
_rescheduleHeartbeatTimeout() {
|
|
290
|
-
if (!this.isOpen) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
void this._inactivityTimeoutCtx?.dispose();
|
|
294
|
-
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
295
|
-
F: __dxlog_file2,
|
|
296
|
-
L: 170
|
|
297
|
-
});
|
|
298
|
-
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
299
|
-
if (this.isOpen) {
|
|
300
|
-
log.warn("restart due to inactivity timeout", void 0, {
|
|
301
|
-
F: __dxlog_file2,
|
|
302
|
-
L: 175,
|
|
303
|
-
S: this,
|
|
304
|
-
C: (f, a) => f(...a)
|
|
305
|
-
});
|
|
306
|
-
this._callbacks.onRestartRequired();
|
|
307
|
-
}
|
|
308
|
-
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
_ts_decorate([
|
|
312
|
-
logInfo
|
|
313
|
-
], EdgeWsConnection.prototype, "info", null);
|
|
314
|
-
|
|
315
58
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
316
59
|
var EdgeConnectionClosedError = class extends Error {
|
|
317
60
|
constructor() {
|
|
@@ -333,15 +76,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
333
76
|
};
|
|
334
77
|
|
|
335
78
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
336
|
-
function
|
|
79
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
337
80
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
338
81
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
339
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;
|
|
340
83
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
341
84
|
}
|
|
342
|
-
var
|
|
85
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
343
86
|
var DEFAULT_TIMEOUT = 1e4;
|
|
344
|
-
var EdgeClient = class extends
|
|
87
|
+
var EdgeClient = class extends Resource {
|
|
345
88
|
constructor(_identity, _config) {
|
|
346
89
|
super();
|
|
347
90
|
this._identity = _identity;
|
|
@@ -378,11 +121,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
378
121
|
}
|
|
379
122
|
setIdentity(identity) {
|
|
380
123
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
381
|
-
|
|
124
|
+
log("Edge identity changed", {
|
|
382
125
|
identity,
|
|
383
126
|
oldIdentity: this._identity
|
|
384
127
|
}, {
|
|
385
|
-
F:
|
|
128
|
+
F: __dxlog_file2,
|
|
386
129
|
L: 99,
|
|
387
130
|
S: this,
|
|
388
131
|
C: (f, a) => f(...a)
|
|
@@ -404,8 +147,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
404
147
|
try {
|
|
405
148
|
listener();
|
|
406
149
|
} catch (error) {
|
|
407
|
-
|
|
408
|
-
F:
|
|
150
|
+
log.catch(error, void 0, {
|
|
151
|
+
F: __dxlog_file2,
|
|
409
152
|
L: 121,
|
|
410
153
|
S: this,
|
|
411
154
|
C: (f, a) => f(...a)
|
|
@@ -420,19 +163,19 @@ var EdgeClient = class extends Resource2 {
|
|
|
420
163
|
* Open connection to messaging service.
|
|
421
164
|
*/
|
|
422
165
|
async _open() {
|
|
423
|
-
|
|
166
|
+
log("opening...", {
|
|
424
167
|
info: this.info
|
|
425
168
|
}, {
|
|
426
|
-
F:
|
|
169
|
+
F: __dxlog_file2,
|
|
427
170
|
L: 133,
|
|
428
171
|
S: this,
|
|
429
172
|
C: (f, a) => f(...a)
|
|
430
173
|
});
|
|
431
174
|
this._persistentLifecycle.open().catch((err) => {
|
|
432
|
-
|
|
175
|
+
log.warn("Error while opening connection", {
|
|
433
176
|
err
|
|
434
177
|
}, {
|
|
435
|
-
F:
|
|
178
|
+
F: __dxlog_file2,
|
|
436
179
|
L: 135,
|
|
437
180
|
S: this,
|
|
438
181
|
C: (f, a) => f(...a)
|
|
@@ -443,10 +186,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
443
186
|
* Close connection and free resources.
|
|
444
187
|
*/
|
|
445
188
|
async _close() {
|
|
446
|
-
|
|
189
|
+
log("closing...", {
|
|
447
190
|
peerKey: this._identity.peerKey
|
|
448
191
|
}, {
|
|
449
|
-
F:
|
|
192
|
+
F: __dxlog_file2,
|
|
450
193
|
L: 143,
|
|
451
194
|
S: this,
|
|
452
195
|
C: (f, a) => f(...a)
|
|
@@ -462,8 +205,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
462
205
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
463
206
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
464
207
|
if (this._identity !== identity) {
|
|
465
|
-
|
|
466
|
-
F:
|
|
208
|
+
log("identity changed during auth header request", void 0, {
|
|
209
|
+
F: __dxlog_file2,
|
|
467
210
|
L: 157,
|
|
468
211
|
S: this,
|
|
469
212
|
C: (f, a) => f(...a)
|
|
@@ -472,11 +215,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
472
215
|
}
|
|
473
216
|
const restartRequired = new Trigger();
|
|
474
217
|
const url = new URL(path, this._baseWsUrl);
|
|
475
|
-
|
|
218
|
+
log("Opening websocket", {
|
|
476
219
|
url: url.toString(),
|
|
477
220
|
protocolHeader
|
|
478
221
|
}, {
|
|
479
|
-
F:
|
|
222
|
+
F: __dxlog_file2,
|
|
480
223
|
L: 163,
|
|
481
224
|
S: this,
|
|
482
225
|
C: (f, a) => f(...a)
|
|
@@ -490,8 +233,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
490
233
|
this._ready.wake();
|
|
491
234
|
this._notifyReconnected();
|
|
492
235
|
} else {
|
|
493
|
-
|
|
494
|
-
F:
|
|
236
|
+
log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
237
|
+
F: __dxlog_file2,
|
|
495
238
|
L: 173,
|
|
496
239
|
S: this,
|
|
497
240
|
C: (f, a) => f(...a)
|
|
@@ -503,8 +246,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
503
246
|
this._closeCurrentConnection();
|
|
504
247
|
void this._persistentLifecycle.scheduleRestart();
|
|
505
248
|
} else {
|
|
506
|
-
|
|
507
|
-
F:
|
|
249
|
+
log.verbose("restart requested by inactive connection", void 0, {
|
|
250
|
+
F: __dxlog_file2,
|
|
508
251
|
L: 181,
|
|
509
252
|
S: this,
|
|
510
253
|
C: (f, a) => f(...a)
|
|
@@ -516,11 +259,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
516
259
|
if (this._isActive(connection)) {
|
|
517
260
|
this._notifyMessageReceived(message);
|
|
518
261
|
} else {
|
|
519
|
-
|
|
262
|
+
log.verbose("ignored a message on inactive connection", {
|
|
520
263
|
from: message.source,
|
|
521
264
|
type: message.payload?.typeUrl
|
|
522
265
|
}, {
|
|
523
|
-
F:
|
|
266
|
+
F: __dxlog_file2,
|
|
524
267
|
L: 189,
|
|
525
268
|
S: this,
|
|
526
269
|
C: (f, a) => f(...a)
|
|
@@ -554,10 +297,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
554
297
|
try {
|
|
555
298
|
listener();
|
|
556
299
|
} catch (err) {
|
|
557
|
-
|
|
300
|
+
log.error("ws reconnect listener failed", {
|
|
558
301
|
err
|
|
559
302
|
}, {
|
|
560
|
-
F:
|
|
303
|
+
F: __dxlog_file2,
|
|
561
304
|
L: 225,
|
|
562
305
|
S: this,
|
|
563
306
|
C: (f, a) => f(...a)
|
|
@@ -570,11 +313,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
570
313
|
try {
|
|
571
314
|
listener(message);
|
|
572
315
|
} catch (err) {
|
|
573
|
-
|
|
316
|
+
log.error("ws incoming message processing failed", {
|
|
574
317
|
err,
|
|
575
318
|
payload: protocol.getPayloadType(message)
|
|
576
319
|
}, {
|
|
577
|
-
F:
|
|
320
|
+
F: __dxlog_file2,
|
|
578
321
|
L: 235,
|
|
579
322
|
S: this,
|
|
580
323
|
C: (f, a) => f(...a)
|
|
@@ -588,8 +331,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
588
331
|
*/
|
|
589
332
|
async send(message) {
|
|
590
333
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
591
|
-
|
|
592
|
-
F:
|
|
334
|
+
log("waiting for websocket to become ready", void 0, {
|
|
335
|
+
F: __dxlog_file2,
|
|
593
336
|
L: 246,
|
|
594
337
|
S: this,
|
|
595
338
|
C: (f, a) => f(...a)
|
|
@@ -615,11 +358,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
615
358
|
if (response.status === 401) {
|
|
616
359
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
617
360
|
} else {
|
|
618
|
-
|
|
361
|
+
log.warn("no auth challenge from edge", {
|
|
619
362
|
status: response.status,
|
|
620
363
|
statusText: response.statusText
|
|
621
364
|
}, {
|
|
622
|
-
F:
|
|
365
|
+
F: __dxlog_file2,
|
|
623
366
|
L: 271,
|
|
624
367
|
S: this,
|
|
625
368
|
C: (f, a) => f(...a)
|
|
@@ -628,8 +371,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
628
371
|
}
|
|
629
372
|
}
|
|
630
373
|
};
|
|
631
|
-
|
|
632
|
-
|
|
374
|
+
_ts_decorate([
|
|
375
|
+
logInfo
|
|
633
376
|
], EdgeClient.prototype, "info", null);
|
|
634
377
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
635
378
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
@@ -638,10 +381,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
638
381
|
|
|
639
382
|
// packages/core/mesh/edge-client/src/auth.ts
|
|
640
383
|
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
641
|
-
import { invariant as
|
|
384
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
642
385
|
import { Keyring } from "@dxos/keyring";
|
|
643
386
|
import { PublicKey } from "@dxos/keys";
|
|
644
|
-
var
|
|
387
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
645
388
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
646
389
|
return {
|
|
647
390
|
identityKey: key.toHex(),
|
|
@@ -685,8 +428,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
685
428
|
identityKey: identityKey.toHex(),
|
|
686
429
|
peerKey: peerKey.toHex(),
|
|
687
430
|
presentCredentials: async ({ challenge }) => {
|
|
688
|
-
|
|
689
|
-
F:
|
|
431
|
+
invariant2(chain, void 0, {
|
|
432
|
+
F: __dxlog_file3,
|
|
690
433
|
L: 75,
|
|
691
434
|
S: void 0,
|
|
692
435
|
A: [
|
|
@@ -749,20 +492,20 @@ var createStubEdgeIdentity = () => {
|
|
|
749
492
|
|
|
750
493
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
751
494
|
import { sleep } from "@dxos/async";
|
|
752
|
-
import { Context
|
|
753
|
-
import { log as
|
|
495
|
+
import { Context } from "@dxos/context";
|
|
496
|
+
import { log as log2 } from "@dxos/log";
|
|
754
497
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
755
|
-
var
|
|
498
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
756
499
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
757
500
|
var DEFAULT_RETRY_JITTER = 500;
|
|
758
501
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
759
502
|
var EdgeHttpClient = class {
|
|
760
503
|
constructor(baseUrl) {
|
|
761
504
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
762
|
-
|
|
505
|
+
log2("created", {
|
|
763
506
|
url: this._baseUrl
|
|
764
507
|
}, {
|
|
765
|
-
F:
|
|
508
|
+
F: __dxlog_file4,
|
|
766
509
|
L: 53,
|
|
767
510
|
S: this,
|
|
768
511
|
C: (f, a) => f(...a)
|
|
@@ -894,8 +637,8 @@ var EdgeHttpClient = class {
|
|
|
894
637
|
});
|
|
895
638
|
}
|
|
896
639
|
async _call(path, args) {
|
|
897
|
-
const requestContext = args.context ?? new
|
|
898
|
-
F:
|
|
640
|
+
const requestContext = args.context ?? new Context(void 0, {
|
|
641
|
+
F: __dxlog_file4,
|
|
899
642
|
L: 192
|
|
900
643
|
});
|
|
901
644
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -907,12 +650,12 @@ var EdgeHttpClient = class {
|
|
|
907
650
|
}
|
|
908
651
|
url += `?${queryParams.toString()}`;
|
|
909
652
|
}
|
|
910
|
-
|
|
653
|
+
log2("call", {
|
|
911
654
|
method: args.method,
|
|
912
655
|
path,
|
|
913
656
|
request: args.body
|
|
914
657
|
}, {
|
|
915
|
-
F:
|
|
658
|
+
F: __dxlog_file4,
|
|
916
659
|
L: 204,
|
|
917
660
|
S: this,
|
|
918
661
|
C: (f, a) => f(...a)
|
|
@@ -931,11 +674,11 @@ var EdgeHttpClient = class {
|
|
|
931
674
|
if (body.success) {
|
|
932
675
|
return body.data;
|
|
933
676
|
}
|
|
934
|
-
|
|
677
|
+
log2("unsuccessful edge response", {
|
|
935
678
|
path,
|
|
936
679
|
body
|
|
937
680
|
}, {
|
|
938
|
-
F:
|
|
681
|
+
F: __dxlog_file4,
|
|
939
682
|
L: 223,
|
|
940
683
|
S: this,
|
|
941
684
|
C: (f, a) => f(...a)
|
|
@@ -956,11 +699,11 @@ var EdgeHttpClient = class {
|
|
|
956
699
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
957
700
|
}
|
|
958
701
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
959
|
-
|
|
702
|
+
log2("retrying edge request", {
|
|
960
703
|
path,
|
|
961
704
|
processingError
|
|
962
705
|
}, {
|
|
963
|
-
F:
|
|
706
|
+
F: __dxlog_file4,
|
|
964
707
|
L: 242,
|
|
965
708
|
S: this,
|
|
966
709
|
C: (f, a) => f(...a)
|
|
@@ -972,8 +715,8 @@ var EdgeHttpClient = class {
|
|
|
972
715
|
}
|
|
973
716
|
async _handleUnauthorized(response) {
|
|
974
717
|
if (!this._edgeIdentity) {
|
|
975
|
-
|
|
976
|
-
F:
|
|
718
|
+
log2.warn("edge unauthorized response received before identity was set", void 0, {
|
|
719
|
+
F: __dxlog_file4,
|
|
977
720
|
L: 251,
|
|
978
721
|
S: this,
|
|
979
722
|
C: (f, a) => f(...a)
|
|
@@ -982,8 +725,8 @@ var EdgeHttpClient = class {
|
|
|
982
725
|
}
|
|
983
726
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
984
727
|
this._authHeader = encodeAuthHeader(challenge);
|
|
985
|
-
|
|
986
|
-
F:
|
|
728
|
+
log2("auth header updated", void 0, {
|
|
729
|
+
F: __dxlog_file4,
|
|
987
730
|
L: 256,
|
|
988
731
|
S: this,
|
|
989
732
|
C: (f, a) => f(...a)
|
|
@@ -1026,14 +769,11 @@ var encodeAuthHeader = (challenge) => {
|
|
|
1026
769
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
1027
770
|
};
|
|
1028
771
|
export {
|
|
1029
|
-
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1030
|
-
CLOUDFLARE_RPC_MAX_BYTES,
|
|
1031
772
|
EdgeClient,
|
|
1032
773
|
EdgeConnectionClosedError,
|
|
1033
774
|
EdgeHttpClient,
|
|
1034
775
|
EdgeIdentityChangedError,
|
|
1035
776
|
Protocol,
|
|
1036
|
-
WebSocketMuxer,
|
|
1037
777
|
createChainEdgeIdentity,
|
|
1038
778
|
createDeviceEdgeIdentity,
|
|
1039
779
|
createEphemeralEdgeIdentity,
|