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