@dxos/edge-client 0.8.2-main.36232bc → 0.8.2-main.5885341
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-TKYUZ5ZK.mjs +302 -0
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs.map +7 -0
- package/dist/lib/browser/edge-ws-muxer.mjs +11 -0
- package/dist/lib/browser/edge-ws-muxer.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +318 -58
- 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-ZOL3YSDR.cjs +322 -0
- package/dist/lib/node/chunk-ZOL3YSDR.cjs.map +7 -0
- package/dist/lib/node/edge-ws-muxer.cjs +33 -0
- package/dist/lib/node/edge-ws-muxer.cjs.map +7 -0
- package/dist/lib/node/index.cjs +322 -53
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +6 -5
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs +304 -0
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs.map +7 -0
- package/dist/lib/node-esm/edge-ws-muxer.mjs +12 -0
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +318 -58
- 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 +0 -4
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +19 -7
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.test.d.ts +2 -0
- package/dist/types/src/edge-ws-muxer.test.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.map +1 -1
- package/package.json +19 -14
- package/src/edge-ws-connection.ts +6 -11
- package/src/edge-ws-muxer.test.ts +55 -0
- package/src/edge-ws-muxer.ts +63 -33
- package/src/index.ts +1 -0
- package/src/testing/test-utils.ts +2 -2
- package/dist/lib/browser/chunk-XS3TKGM4.mjs +0 -545
- package/dist/lib/browser/chunk-XS3TKGM4.mjs.map +0 -7
- package/dist/lib/node/chunk-ZURVCY7K.cjs +0 -577
- package/dist/lib/node/chunk-ZURVCY7K.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs +0 -547
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs.map +0 -7
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
4
|
+
CLOUDFLARE_RPC_MAX_BYTES,
|
|
4
5
|
Protocol,
|
|
6
|
+
WebSocketMuxer,
|
|
5
7
|
getTypename,
|
|
6
8
|
protocol,
|
|
7
9
|
toUint8Array
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-25HGRGNZ.mjs";
|
|
9
11
|
|
|
10
12
|
// packages/core/mesh/edge-client/src/index.ts
|
|
11
13
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
12
14
|
|
|
13
15
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
14
16
|
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
|
|
15
|
-
import { Resource } from "@dxos/context";
|
|
16
|
-
import { log, logInfo } from "@dxos/log";
|
|
17
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
18
|
+
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
17
19
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
18
20
|
|
|
19
21
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
@@ -56,6 +58,261 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
56
58
|
return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
57
59
|
};
|
|
58
60
|
|
|
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
|
+
|
|
59
316
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
60
317
|
var EdgeConnectionClosedError = class extends Error {
|
|
61
318
|
constructor() {
|
|
@@ -77,15 +334,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
77
334
|
};
|
|
78
335
|
|
|
79
336
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
80
|
-
function
|
|
337
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
81
338
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
82
339
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
83
340
|
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;
|
|
84
341
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
85
342
|
}
|
|
86
|
-
var
|
|
343
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
87
344
|
var DEFAULT_TIMEOUT = 1e4;
|
|
88
|
-
var EdgeClient = class extends
|
|
345
|
+
var EdgeClient = class extends Resource2 {
|
|
89
346
|
constructor(_identity, _config) {
|
|
90
347
|
super();
|
|
91
348
|
this._identity = _identity;
|
|
@@ -122,11 +379,11 @@ var EdgeClient = class extends Resource {
|
|
|
122
379
|
}
|
|
123
380
|
setIdentity(identity) {
|
|
124
381
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
125
|
-
|
|
382
|
+
log2("Edge identity changed", {
|
|
126
383
|
identity,
|
|
127
384
|
oldIdentity: this._identity
|
|
128
385
|
}, {
|
|
129
|
-
F:
|
|
386
|
+
F: __dxlog_file3,
|
|
130
387
|
L: 99,
|
|
131
388
|
S: this,
|
|
132
389
|
C: (f, a) => f(...a)
|
|
@@ -148,8 +405,8 @@ var EdgeClient = class extends Resource {
|
|
|
148
405
|
try {
|
|
149
406
|
listener();
|
|
150
407
|
} catch (error) {
|
|
151
|
-
|
|
152
|
-
F:
|
|
408
|
+
log2.catch(error, void 0, {
|
|
409
|
+
F: __dxlog_file3,
|
|
153
410
|
L: 121,
|
|
154
411
|
S: this,
|
|
155
412
|
C: (f, a) => f(...a)
|
|
@@ -164,19 +421,19 @@ var EdgeClient = class extends Resource {
|
|
|
164
421
|
* Open connection to messaging service.
|
|
165
422
|
*/
|
|
166
423
|
async _open() {
|
|
167
|
-
|
|
424
|
+
log2("opening...", {
|
|
168
425
|
info: this.info
|
|
169
426
|
}, {
|
|
170
|
-
F:
|
|
427
|
+
F: __dxlog_file3,
|
|
171
428
|
L: 133,
|
|
172
429
|
S: this,
|
|
173
430
|
C: (f, a) => f(...a)
|
|
174
431
|
});
|
|
175
432
|
this._persistentLifecycle.open().catch((err) => {
|
|
176
|
-
|
|
433
|
+
log2.warn("Error while opening connection", {
|
|
177
434
|
err
|
|
178
435
|
}, {
|
|
179
|
-
F:
|
|
436
|
+
F: __dxlog_file3,
|
|
180
437
|
L: 135,
|
|
181
438
|
S: this,
|
|
182
439
|
C: (f, a) => f(...a)
|
|
@@ -187,10 +444,10 @@ var EdgeClient = class extends Resource {
|
|
|
187
444
|
* Close connection and free resources.
|
|
188
445
|
*/
|
|
189
446
|
async _close() {
|
|
190
|
-
|
|
447
|
+
log2("closing...", {
|
|
191
448
|
peerKey: this._identity.peerKey
|
|
192
449
|
}, {
|
|
193
|
-
F:
|
|
450
|
+
F: __dxlog_file3,
|
|
194
451
|
L: 143,
|
|
195
452
|
S: this,
|
|
196
453
|
C: (f, a) => f(...a)
|
|
@@ -206,8 +463,8 @@ var EdgeClient = class extends Resource {
|
|
|
206
463
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
207
464
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
208
465
|
if (this._identity !== identity) {
|
|
209
|
-
|
|
210
|
-
F:
|
|
466
|
+
log2("identity changed during auth header request", void 0, {
|
|
467
|
+
F: __dxlog_file3,
|
|
211
468
|
L: 157,
|
|
212
469
|
S: this,
|
|
213
470
|
C: (f, a) => f(...a)
|
|
@@ -216,11 +473,11 @@ var EdgeClient = class extends Resource {
|
|
|
216
473
|
}
|
|
217
474
|
const restartRequired = new Trigger();
|
|
218
475
|
const url = new URL(path, this._baseWsUrl);
|
|
219
|
-
|
|
476
|
+
log2("Opening websocket", {
|
|
220
477
|
url: url.toString(),
|
|
221
478
|
protocolHeader
|
|
222
479
|
}, {
|
|
223
|
-
F:
|
|
480
|
+
F: __dxlog_file3,
|
|
224
481
|
L: 163,
|
|
225
482
|
S: this,
|
|
226
483
|
C: (f, a) => f(...a)
|
|
@@ -234,8 +491,8 @@ var EdgeClient = class extends Resource {
|
|
|
234
491
|
this._ready.wake();
|
|
235
492
|
this._notifyReconnected();
|
|
236
493
|
} else {
|
|
237
|
-
|
|
238
|
-
F:
|
|
494
|
+
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
495
|
+
F: __dxlog_file3,
|
|
239
496
|
L: 173,
|
|
240
497
|
S: this,
|
|
241
498
|
C: (f, a) => f(...a)
|
|
@@ -247,8 +504,8 @@ var EdgeClient = class extends Resource {
|
|
|
247
504
|
this._closeCurrentConnection();
|
|
248
505
|
void this._persistentLifecycle.scheduleRestart();
|
|
249
506
|
} else {
|
|
250
|
-
|
|
251
|
-
F:
|
|
507
|
+
log2.verbose("restart requested by inactive connection", void 0, {
|
|
508
|
+
F: __dxlog_file3,
|
|
252
509
|
L: 181,
|
|
253
510
|
S: this,
|
|
254
511
|
C: (f, a) => f(...a)
|
|
@@ -260,11 +517,11 @@ var EdgeClient = class extends Resource {
|
|
|
260
517
|
if (this._isActive(connection)) {
|
|
261
518
|
this._notifyMessageReceived(message);
|
|
262
519
|
} else {
|
|
263
|
-
|
|
520
|
+
log2.verbose("ignored a message on inactive connection", {
|
|
264
521
|
from: message.source,
|
|
265
522
|
type: message.payload?.typeUrl
|
|
266
523
|
}, {
|
|
267
|
-
F:
|
|
524
|
+
F: __dxlog_file3,
|
|
268
525
|
L: 189,
|
|
269
526
|
S: this,
|
|
270
527
|
C: (f, a) => f(...a)
|
|
@@ -298,10 +555,10 @@ var EdgeClient = class extends Resource {
|
|
|
298
555
|
try {
|
|
299
556
|
listener();
|
|
300
557
|
} catch (err) {
|
|
301
|
-
|
|
558
|
+
log2.error("ws reconnect listener failed", {
|
|
302
559
|
err
|
|
303
560
|
}, {
|
|
304
|
-
F:
|
|
561
|
+
F: __dxlog_file3,
|
|
305
562
|
L: 225,
|
|
306
563
|
S: this,
|
|
307
564
|
C: (f, a) => f(...a)
|
|
@@ -314,11 +571,11 @@ var EdgeClient = class extends Resource {
|
|
|
314
571
|
try {
|
|
315
572
|
listener(message);
|
|
316
573
|
} catch (err) {
|
|
317
|
-
|
|
574
|
+
log2.error("ws incoming message processing failed", {
|
|
318
575
|
err,
|
|
319
576
|
payload: protocol.getPayloadType(message)
|
|
320
577
|
}, {
|
|
321
|
-
F:
|
|
578
|
+
F: __dxlog_file3,
|
|
322
579
|
L: 235,
|
|
323
580
|
S: this,
|
|
324
581
|
C: (f, a) => f(...a)
|
|
@@ -332,8 +589,8 @@ var EdgeClient = class extends Resource {
|
|
|
332
589
|
*/
|
|
333
590
|
async send(message) {
|
|
334
591
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
335
|
-
|
|
336
|
-
F:
|
|
592
|
+
log2("waiting for websocket to become ready", void 0, {
|
|
593
|
+
F: __dxlog_file3,
|
|
337
594
|
L: 246,
|
|
338
595
|
S: this,
|
|
339
596
|
C: (f, a) => f(...a)
|
|
@@ -359,11 +616,11 @@ var EdgeClient = class extends Resource {
|
|
|
359
616
|
if (response.status === 401) {
|
|
360
617
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
361
618
|
} else {
|
|
362
|
-
|
|
619
|
+
log2.warn("no auth challenge from edge", {
|
|
363
620
|
status: response.status,
|
|
364
621
|
statusText: response.statusText
|
|
365
622
|
}, {
|
|
366
|
-
F:
|
|
623
|
+
F: __dxlog_file3,
|
|
367
624
|
L: 271,
|
|
368
625
|
S: this,
|
|
369
626
|
C: (f, a) => f(...a)
|
|
@@ -372,8 +629,8 @@ var EdgeClient = class extends Resource {
|
|
|
372
629
|
}
|
|
373
630
|
}
|
|
374
631
|
};
|
|
375
|
-
|
|
376
|
-
|
|
632
|
+
_ts_decorate2([
|
|
633
|
+
logInfo2
|
|
377
634
|
], EdgeClient.prototype, "info", null);
|
|
378
635
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
379
636
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
@@ -382,10 +639,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
382
639
|
|
|
383
640
|
// packages/core/mesh/edge-client/src/auth.ts
|
|
384
641
|
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
385
|
-
import { invariant as
|
|
642
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
386
643
|
import { Keyring } from "@dxos/keyring";
|
|
387
644
|
import { PublicKey } from "@dxos/keys";
|
|
388
|
-
var
|
|
645
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
389
646
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
390
647
|
return {
|
|
391
648
|
identityKey: key.toHex(),
|
|
@@ -429,8 +686,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
429
686
|
identityKey: identityKey.toHex(),
|
|
430
687
|
peerKey: peerKey.toHex(),
|
|
431
688
|
presentCredentials: async ({ challenge }) => {
|
|
432
|
-
|
|
433
|
-
F:
|
|
689
|
+
invariant3(chain, void 0, {
|
|
690
|
+
F: __dxlog_file4,
|
|
434
691
|
L: 75,
|
|
435
692
|
S: void 0,
|
|
436
693
|
A: [
|
|
@@ -493,20 +750,20 @@ var createStubEdgeIdentity = () => {
|
|
|
493
750
|
|
|
494
751
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
495
752
|
import { sleep } from "@dxos/async";
|
|
496
|
-
import { Context } from "@dxos/context";
|
|
497
|
-
import { log as
|
|
753
|
+
import { Context as Context2 } from "@dxos/context";
|
|
754
|
+
import { log as log3 } from "@dxos/log";
|
|
498
755
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
499
|
-
var
|
|
756
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
500
757
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
501
758
|
var DEFAULT_RETRY_JITTER = 500;
|
|
502
759
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
503
760
|
var EdgeHttpClient = class {
|
|
504
761
|
constructor(baseUrl) {
|
|
505
762
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
506
|
-
|
|
763
|
+
log3("created", {
|
|
507
764
|
url: this._baseUrl
|
|
508
765
|
}, {
|
|
509
|
-
F:
|
|
766
|
+
F: __dxlog_file5,
|
|
510
767
|
L: 53,
|
|
511
768
|
S: this,
|
|
512
769
|
C: (f, a) => f(...a)
|
|
@@ -638,8 +895,8 @@ var EdgeHttpClient = class {
|
|
|
638
895
|
});
|
|
639
896
|
}
|
|
640
897
|
async _call(path, args) {
|
|
641
|
-
const requestContext = args.context ?? new
|
|
642
|
-
F:
|
|
898
|
+
const requestContext = args.context ?? new Context2(void 0, {
|
|
899
|
+
F: __dxlog_file5,
|
|
643
900
|
L: 192
|
|
644
901
|
});
|
|
645
902
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -651,12 +908,12 @@ var EdgeHttpClient = class {
|
|
|
651
908
|
}
|
|
652
909
|
url += `?${queryParams.toString()}`;
|
|
653
910
|
}
|
|
654
|
-
|
|
911
|
+
log3("call", {
|
|
655
912
|
method: args.method,
|
|
656
913
|
path,
|
|
657
914
|
request: args.body
|
|
658
915
|
}, {
|
|
659
|
-
F:
|
|
916
|
+
F: __dxlog_file5,
|
|
660
917
|
L: 204,
|
|
661
918
|
S: this,
|
|
662
919
|
C: (f, a) => f(...a)
|
|
@@ -675,11 +932,11 @@ var EdgeHttpClient = class {
|
|
|
675
932
|
if (body.success) {
|
|
676
933
|
return body.data;
|
|
677
934
|
}
|
|
678
|
-
|
|
935
|
+
log3("unsuccessful edge response", {
|
|
679
936
|
path,
|
|
680
937
|
body
|
|
681
938
|
}, {
|
|
682
|
-
F:
|
|
939
|
+
F: __dxlog_file5,
|
|
683
940
|
L: 223,
|
|
684
941
|
S: this,
|
|
685
942
|
C: (f, a) => f(...a)
|
|
@@ -700,11 +957,11 @@ var EdgeHttpClient = class {
|
|
|
700
957
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
701
958
|
}
|
|
702
959
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
703
|
-
|
|
960
|
+
log3("retrying edge request", {
|
|
704
961
|
path,
|
|
705
962
|
processingError
|
|
706
963
|
}, {
|
|
707
|
-
F:
|
|
964
|
+
F: __dxlog_file5,
|
|
708
965
|
L: 242,
|
|
709
966
|
S: this,
|
|
710
967
|
C: (f, a) => f(...a)
|
|
@@ -716,8 +973,8 @@ var EdgeHttpClient = class {
|
|
|
716
973
|
}
|
|
717
974
|
async _handleUnauthorized(response) {
|
|
718
975
|
if (!this._edgeIdentity) {
|
|
719
|
-
|
|
720
|
-
F:
|
|
976
|
+
log3.warn("edge unauthorized response received before identity was set", void 0, {
|
|
977
|
+
F: __dxlog_file5,
|
|
721
978
|
L: 251,
|
|
722
979
|
S: this,
|
|
723
980
|
C: (f, a) => f(...a)
|
|
@@ -726,8 +983,8 @@ var EdgeHttpClient = class {
|
|
|
726
983
|
}
|
|
727
984
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
728
985
|
this._authHeader = encodeAuthHeader(challenge);
|
|
729
|
-
|
|
730
|
-
F:
|
|
986
|
+
log3("auth header updated", void 0, {
|
|
987
|
+
F: __dxlog_file5,
|
|
731
988
|
L: 256,
|
|
732
989
|
S: this,
|
|
733
990
|
C: (f, a) => f(...a)
|
|
@@ -770,11 +1027,14 @@ var encodeAuthHeader = (challenge) => {
|
|
|
770
1027
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
771
1028
|
};
|
|
772
1029
|
export {
|
|
1030
|
+
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1031
|
+
CLOUDFLARE_RPC_MAX_BYTES,
|
|
773
1032
|
EdgeClient,
|
|
774
1033
|
EdgeConnectionClosedError,
|
|
775
1034
|
EdgeHttpClient,
|
|
776
1035
|
EdgeIdentityChangedError,
|
|
777
1036
|
Protocol,
|
|
1037
|
+
WebSocketMuxer,
|
|
778
1038
|
createChainEdgeIdentity,
|
|
779
1039
|
createDeviceEdgeIdentity,
|
|
780
1040
|
createEphemeralEdgeIdentity,
|