@dxos/edge-client 0.8.2-main.f11618f → 0.8.2-staging.7ac8446
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-ZWJXA37R.mjs +113 -0
- package/dist/lib/browser/chunk-ZWJXA37R.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +299 -87
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +20 -32
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-ANV2HBEH.cjs +136 -0
- package/dist/lib/node/chunk-ANV2HBEH.cjs.map +7 -0
- package/dist/lib/node/index.cjs +297 -76
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +21 -31
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs +115 -0
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +299 -87
- 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 +20 -32
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-client.d.ts +2 -7
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts +0 -5
- package/dist/types/src/edge-ws-connection.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 +2 -6
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/edge-client.test.ts +4 -5
- package/src/edge-client.ts +8 -16
- package/src/edge-ws-connection.ts +15 -38
- package/src/index.ts +0 -1
- package/src/testing/test-utils.ts +26 -33
- package/dist/lib/browser/chunk-5DDWS5EC.mjs +0 -546
- package/dist/lib/browser/chunk-5DDWS5EC.mjs.map +0 -7
- package/dist/lib/node/chunk-CNAHGYSS.cjs +0 -579
- package/dist/lib/node/chunk-CNAHGYSS.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-O4TFZRSP.mjs +0 -548
- package/dist/lib/node-esm/chunk-O4TFZRSP.mjs.map +0 -7
- package/dist/types/src/edge-ws-muxer.d.ts +0 -23
- package/dist/types/src/edge-ws-muxer.d.ts.map +0 -1
- package/src/edge-ws-muxer.ts +0 -187
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CLOUDFLARE_MESSAGE_LENGTH_LIMIT,
|
|
3
|
-
EdgeWsConnection,
|
|
4
2
|
Protocol,
|
|
5
|
-
WebSocketMuxer,
|
|
6
3
|
getTypename,
|
|
7
4
|
protocol,
|
|
8
5
|
toUint8Array
|
|
9
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZWJXA37R.mjs";
|
|
10
7
|
|
|
11
8
|
// packages/core/mesh/edge-client/src/index.ts
|
|
12
9
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
13
10
|
|
|
14
11
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
15
|
-
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle
|
|
16
|
-
import { Resource } from "@dxos/context";
|
|
17
|
-
import { log, logInfo } from "@dxos/log";
|
|
18
|
-
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
12
|
+
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from "@dxos/async";
|
|
13
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
14
|
+
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
19
15
|
|
|
20
16
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
21
17
|
import { invariant } from "@dxos/invariant";
|
|
@@ -57,6 +53,229 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
57
53
|
return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
58
54
|
};
|
|
59
55
|
|
|
56
|
+
// packages/core/mesh/edge-client/src/edge-ws-connection.ts
|
|
57
|
+
import WebSocket from "isomorphic-ws";
|
|
58
|
+
import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
59
|
+
import { Context, Resource } from "@dxos/context";
|
|
60
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
61
|
+
import { log, logInfo } from "@dxos/log";
|
|
62
|
+
import { buf } from "@dxos/protocols/buf";
|
|
63
|
+
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
64
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
65
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
66
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
67
|
+
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;
|
|
68
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
69
|
+
}
|
|
70
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
71
|
+
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
72
|
+
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
73
|
+
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
74
|
+
var EdgeWsConnection = class extends Resource {
|
|
75
|
+
constructor(_identity, _connectionInfo, _callbacks) {
|
|
76
|
+
super();
|
|
77
|
+
this._identity = _identity;
|
|
78
|
+
this._connectionInfo = _connectionInfo;
|
|
79
|
+
this._callbacks = _callbacks;
|
|
80
|
+
}
|
|
81
|
+
get info() {
|
|
82
|
+
return {
|
|
83
|
+
open: this.isOpen,
|
|
84
|
+
identity: this._identity.identityKey,
|
|
85
|
+
device: this._identity.peerKey
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
send(message) {
|
|
89
|
+
invariant2(this._ws, void 0, {
|
|
90
|
+
F: __dxlog_file2,
|
|
91
|
+
L: 54,
|
|
92
|
+
S: this,
|
|
93
|
+
A: [
|
|
94
|
+
"this._ws",
|
|
95
|
+
""
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
log("sending...", {
|
|
99
|
+
peerKey: this._identity.peerKey,
|
|
100
|
+
payload: protocol.getPayloadType(message)
|
|
101
|
+
}, {
|
|
102
|
+
F: __dxlog_file2,
|
|
103
|
+
L: 55,
|
|
104
|
+
S: this,
|
|
105
|
+
C: (f, a) => f(...a)
|
|
106
|
+
});
|
|
107
|
+
const encoded = buf.toBinary(MessageSchema, message);
|
|
108
|
+
if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
109
|
+
log.error("edge message dropped due to websocket message limit", {
|
|
110
|
+
byteLength: encoded.byteLength,
|
|
111
|
+
serviceId: message.serviceId,
|
|
112
|
+
payload: protocol.getPayloadType(message)
|
|
113
|
+
}, {
|
|
114
|
+
F: __dxlog_file2,
|
|
115
|
+
L: 58,
|
|
116
|
+
S: this,
|
|
117
|
+
C: (f, a) => f(...a)
|
|
118
|
+
});
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this._ws.send(encoded);
|
|
122
|
+
}
|
|
123
|
+
async _open() {
|
|
124
|
+
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
125
|
+
this._connectionInfo.protocolHeader
|
|
126
|
+
] : []);
|
|
127
|
+
this._ws.onopen = () => {
|
|
128
|
+
if (this.isOpen) {
|
|
129
|
+
log("connected", void 0, {
|
|
130
|
+
F: __dxlog_file2,
|
|
131
|
+
L: 76,
|
|
132
|
+
S: this,
|
|
133
|
+
C: (f, a) => f(...a)
|
|
134
|
+
});
|
|
135
|
+
this._callbacks.onConnected();
|
|
136
|
+
this._scheduleHeartbeats();
|
|
137
|
+
} else {
|
|
138
|
+
log.verbose("connected after becoming inactive", {
|
|
139
|
+
currentIdentity: this._identity
|
|
140
|
+
}, {
|
|
141
|
+
F: __dxlog_file2,
|
|
142
|
+
L: 80,
|
|
143
|
+
S: this,
|
|
144
|
+
C: (f, a) => f(...a)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
this._ws.onclose = (event) => {
|
|
149
|
+
if (this.isOpen) {
|
|
150
|
+
log.warn("disconnected while being open", {
|
|
151
|
+
code: event.code,
|
|
152
|
+
reason: event.reason
|
|
153
|
+
}, {
|
|
154
|
+
F: __dxlog_file2,
|
|
155
|
+
L: 85,
|
|
156
|
+
S: this,
|
|
157
|
+
C: (f, a) => f(...a)
|
|
158
|
+
});
|
|
159
|
+
this._callbacks.onRestartRequired();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
this._ws.onerror = (event) => {
|
|
163
|
+
if (this.isOpen) {
|
|
164
|
+
log.warn("edge connection socket error", {
|
|
165
|
+
error: event.error,
|
|
166
|
+
info: event.message
|
|
167
|
+
}, {
|
|
168
|
+
F: __dxlog_file2,
|
|
169
|
+
L: 91,
|
|
170
|
+
S: this,
|
|
171
|
+
C: (f, a) => f(...a)
|
|
172
|
+
});
|
|
173
|
+
this._callbacks.onRestartRequired();
|
|
174
|
+
} else {
|
|
175
|
+
log.verbose("error ignored on closed connection", {
|
|
176
|
+
error: event.error
|
|
177
|
+
}, {
|
|
178
|
+
F: __dxlog_file2,
|
|
179
|
+
L: 94,
|
|
180
|
+
S: this,
|
|
181
|
+
C: (f, a) => f(...a)
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
this._ws.onmessage = async (event) => {
|
|
186
|
+
if (!this.isOpen) {
|
|
187
|
+
log.verbose("message ignored on closed connection", {
|
|
188
|
+
event: event.type
|
|
189
|
+
}, {
|
|
190
|
+
F: __dxlog_file2,
|
|
191
|
+
L: 102,
|
|
192
|
+
S: this,
|
|
193
|
+
C: (f, a) => f(...a)
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (event.data === "__pong__") {
|
|
198
|
+
this._rescheduleHeartbeatTimeout();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const data = await toUint8Array(event.data);
|
|
202
|
+
if (this.isOpen) {
|
|
203
|
+
const message = buf.fromBinary(MessageSchema, data);
|
|
204
|
+
log("received", {
|
|
205
|
+
from: message.source,
|
|
206
|
+
payload: protocol.getPayloadType(message)
|
|
207
|
+
}, {
|
|
208
|
+
F: __dxlog_file2,
|
|
209
|
+
L: 112,
|
|
210
|
+
S: this,
|
|
211
|
+
C: (f, a) => f(...a)
|
|
212
|
+
});
|
|
213
|
+
this._callbacks.onMessage(message);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
async _close() {
|
|
218
|
+
void this._inactivityTimeoutCtx?.dispose().catch(() => {
|
|
219
|
+
});
|
|
220
|
+
try {
|
|
221
|
+
this._ws?.close();
|
|
222
|
+
this._ws = void 0;
|
|
223
|
+
} catch (err) {
|
|
224
|
+
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
log.warn("Error closing websocket", {
|
|
228
|
+
err
|
|
229
|
+
}, {
|
|
230
|
+
F: __dxlog_file2,
|
|
231
|
+
L: 128,
|
|
232
|
+
S: this,
|
|
233
|
+
C: (f, a) => f(...a)
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
_scheduleHeartbeats() {
|
|
238
|
+
invariant2(this._ws, void 0, {
|
|
239
|
+
F: __dxlog_file2,
|
|
240
|
+
L: 133,
|
|
241
|
+
S: this,
|
|
242
|
+
A: [
|
|
243
|
+
"this._ws",
|
|
244
|
+
""
|
|
245
|
+
]
|
|
246
|
+
});
|
|
247
|
+
scheduleTaskInterval(this._ctx, async () => {
|
|
248
|
+
this._ws?.send("__ping__");
|
|
249
|
+
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
250
|
+
this._ws.send("__ping__");
|
|
251
|
+
this._rescheduleHeartbeatTimeout();
|
|
252
|
+
}
|
|
253
|
+
_rescheduleHeartbeatTimeout() {
|
|
254
|
+
if (!this.isOpen) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
void this._inactivityTimeoutCtx?.dispose();
|
|
258
|
+
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
259
|
+
F: __dxlog_file2,
|
|
260
|
+
L: 152
|
|
261
|
+
});
|
|
262
|
+
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
263
|
+
if (this.isOpen) {
|
|
264
|
+
log.warn("restart due to inactivity timeout", void 0, {
|
|
265
|
+
F: __dxlog_file2,
|
|
266
|
+
L: 157,
|
|
267
|
+
S: this,
|
|
268
|
+
C: (f, a) => f(...a)
|
|
269
|
+
});
|
|
270
|
+
this._callbacks.onRestartRequired();
|
|
271
|
+
}
|
|
272
|
+
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
_ts_decorate([
|
|
276
|
+
logInfo
|
|
277
|
+
], EdgeWsConnection.prototype, "info", null);
|
|
278
|
+
|
|
60
279
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
61
280
|
var EdgeConnectionClosedError = class extends Error {
|
|
62
281
|
constructor() {
|
|
@@ -78,20 +297,19 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
78
297
|
};
|
|
79
298
|
|
|
80
299
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
81
|
-
function
|
|
300
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
82
301
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
83
302
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
84
303
|
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;
|
|
85
304
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
86
305
|
}
|
|
87
|
-
var
|
|
306
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
88
307
|
var DEFAULT_TIMEOUT = 1e4;
|
|
89
|
-
var EdgeClient = class extends
|
|
308
|
+
var EdgeClient = class extends Resource2 {
|
|
90
309
|
constructor(_identity, _config) {
|
|
91
310
|
super();
|
|
92
311
|
this._identity = _identity;
|
|
93
312
|
this._config = _config;
|
|
94
|
-
this.statusChanged = new Event();
|
|
95
313
|
this._persistentLifecycle = new PersistentLifecycle({
|
|
96
314
|
start: async () => this._connect(),
|
|
97
315
|
stop: async (state) => this._disconnect(state)
|
|
@@ -107,13 +325,12 @@ var EdgeClient = class extends Resource {
|
|
|
107
325
|
get info() {
|
|
108
326
|
return {
|
|
109
327
|
open: this.isOpen,
|
|
110
|
-
status: this.status,
|
|
111
328
|
identity: this._identity.identityKey,
|
|
112
329
|
device: this._identity.peerKey
|
|
113
330
|
};
|
|
114
331
|
}
|
|
115
|
-
get
|
|
116
|
-
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED
|
|
332
|
+
get isConnected() {
|
|
333
|
+
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED;
|
|
117
334
|
}
|
|
118
335
|
get identityKey() {
|
|
119
336
|
return this._identity.identityKey;
|
|
@@ -123,18 +340,18 @@ var EdgeClient = class extends Resource {
|
|
|
123
340
|
}
|
|
124
341
|
setIdentity(identity) {
|
|
125
342
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
126
|
-
|
|
343
|
+
log2("Edge identity changed", {
|
|
127
344
|
identity,
|
|
128
345
|
oldIdentity: this._identity
|
|
129
346
|
}, {
|
|
130
|
-
F:
|
|
131
|
-
L:
|
|
347
|
+
F: __dxlog_file3,
|
|
348
|
+
L: 94,
|
|
132
349
|
S: this,
|
|
133
350
|
C: (f, a) => f(...a)
|
|
134
351
|
});
|
|
135
352
|
this._identity = identity;
|
|
136
353
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
137
|
-
|
|
354
|
+
this._persistentLifecycle.scheduleRestart();
|
|
138
355
|
}
|
|
139
356
|
}
|
|
140
357
|
onMessage(listener) {
|
|
@@ -149,9 +366,9 @@ var EdgeClient = class extends Resource {
|
|
|
149
366
|
try {
|
|
150
367
|
listener();
|
|
151
368
|
} catch (error) {
|
|
152
|
-
|
|
153
|
-
F:
|
|
154
|
-
L:
|
|
369
|
+
log2.catch(error, void 0, {
|
|
370
|
+
F: __dxlog_file3,
|
|
371
|
+
L: 116,
|
|
155
372
|
S: this,
|
|
156
373
|
C: (f, a) => f(...a)
|
|
157
374
|
});
|
|
@@ -165,20 +382,20 @@ var EdgeClient = class extends Resource {
|
|
|
165
382
|
* Open connection to messaging service.
|
|
166
383
|
*/
|
|
167
384
|
async _open() {
|
|
168
|
-
|
|
385
|
+
log2("opening...", {
|
|
169
386
|
info: this.info
|
|
170
387
|
}, {
|
|
171
|
-
F:
|
|
172
|
-
L:
|
|
388
|
+
F: __dxlog_file3,
|
|
389
|
+
L: 128,
|
|
173
390
|
S: this,
|
|
174
391
|
C: (f, a) => f(...a)
|
|
175
392
|
});
|
|
176
393
|
this._persistentLifecycle.open().catch((err) => {
|
|
177
|
-
|
|
394
|
+
log2.warn("Error while opening connection", {
|
|
178
395
|
err
|
|
179
396
|
}, {
|
|
180
|
-
F:
|
|
181
|
-
L:
|
|
397
|
+
F: __dxlog_file3,
|
|
398
|
+
L: 130,
|
|
182
399
|
S: this,
|
|
183
400
|
C: (f, a) => f(...a)
|
|
184
401
|
});
|
|
@@ -188,11 +405,11 @@ var EdgeClient = class extends Resource {
|
|
|
188
405
|
* Close connection and free resources.
|
|
189
406
|
*/
|
|
190
407
|
async _close() {
|
|
191
|
-
|
|
408
|
+
log2("closing...", {
|
|
192
409
|
peerKey: this._identity.peerKey
|
|
193
410
|
}, {
|
|
194
|
-
F:
|
|
195
|
-
L:
|
|
411
|
+
F: __dxlog_file3,
|
|
412
|
+
L: 138,
|
|
196
413
|
S: this,
|
|
197
414
|
C: (f, a) => f(...a)
|
|
198
415
|
});
|
|
@@ -207,9 +424,9 @@ var EdgeClient = class extends Resource {
|
|
|
207
424
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
208
425
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
209
426
|
if (this._identity !== identity) {
|
|
210
|
-
|
|
211
|
-
F:
|
|
212
|
-
L:
|
|
427
|
+
log2("identity changed during auth header request", void 0, {
|
|
428
|
+
F: __dxlog_file3,
|
|
429
|
+
L: 152,
|
|
213
430
|
S: this,
|
|
214
431
|
C: (f, a) => f(...a)
|
|
215
432
|
});
|
|
@@ -217,12 +434,12 @@ var EdgeClient = class extends Resource {
|
|
|
217
434
|
}
|
|
218
435
|
const restartRequired = new Trigger();
|
|
219
436
|
const url = new URL(path, this._baseWsUrl);
|
|
220
|
-
|
|
437
|
+
log2("Opening websocket", {
|
|
221
438
|
url: url.toString(),
|
|
222
439
|
protocolHeader
|
|
223
440
|
}, {
|
|
224
|
-
F:
|
|
225
|
-
L:
|
|
441
|
+
F: __dxlog_file3,
|
|
442
|
+
L: 158,
|
|
226
443
|
S: this,
|
|
227
444
|
C: (f, a) => f(...a)
|
|
228
445
|
});
|
|
@@ -235,9 +452,9 @@ var EdgeClient = class extends Resource {
|
|
|
235
452
|
this._ready.wake();
|
|
236
453
|
this._notifyReconnected();
|
|
237
454
|
} else {
|
|
238
|
-
|
|
239
|
-
F:
|
|
240
|
-
L:
|
|
455
|
+
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
456
|
+
F: __dxlog_file3,
|
|
457
|
+
L: 168,
|
|
241
458
|
S: this,
|
|
242
459
|
C: (f, a) => f(...a)
|
|
243
460
|
});
|
|
@@ -246,11 +463,11 @@ var EdgeClient = class extends Resource {
|
|
|
246
463
|
onRestartRequired: () => {
|
|
247
464
|
if (this._isActive(connection)) {
|
|
248
465
|
this._closeCurrentConnection();
|
|
249
|
-
|
|
466
|
+
this._persistentLifecycle.scheduleRestart();
|
|
250
467
|
} else {
|
|
251
|
-
|
|
252
|
-
F:
|
|
253
|
-
L:
|
|
468
|
+
log2.verbose("restart requested by inactive connection", void 0, {
|
|
469
|
+
F: __dxlog_file3,
|
|
470
|
+
L: 176,
|
|
254
471
|
S: this,
|
|
255
472
|
C: (f, a) => f(...a)
|
|
256
473
|
});
|
|
@@ -261,12 +478,12 @@ var EdgeClient = class extends Resource {
|
|
|
261
478
|
if (this._isActive(connection)) {
|
|
262
479
|
this._notifyMessageReceived(message);
|
|
263
480
|
} else {
|
|
264
|
-
|
|
481
|
+
log2.verbose("ignored a message on inactive connection", {
|
|
265
482
|
from: message.source,
|
|
266
483
|
type: message.payload?.typeUrl
|
|
267
484
|
}, {
|
|
268
|
-
F:
|
|
269
|
-
L:
|
|
485
|
+
F: __dxlog_file3,
|
|
486
|
+
L: 184,
|
|
270
487
|
S: this,
|
|
271
488
|
C: (f, a) => f(...a)
|
|
272
489
|
});
|
|
@@ -285,25 +502,22 @@ var EdgeClient = class extends Resource {
|
|
|
285
502
|
}
|
|
286
503
|
async _disconnect(state) {
|
|
287
504
|
await state.close();
|
|
288
|
-
this.statusChanged.emit(this.status);
|
|
289
505
|
}
|
|
290
506
|
_closeCurrentConnection(error = new EdgeConnectionClosedError()) {
|
|
291
507
|
this._currentConnection = void 0;
|
|
292
508
|
this._ready.throw(error);
|
|
293
509
|
this._ready.reset();
|
|
294
|
-
this.statusChanged.emit(this.status);
|
|
295
510
|
}
|
|
296
511
|
_notifyReconnected() {
|
|
297
|
-
this.statusChanged.emit(this.status);
|
|
298
512
|
for (const listener of this._reconnectListeners) {
|
|
299
513
|
try {
|
|
300
514
|
listener();
|
|
301
515
|
} catch (err) {
|
|
302
|
-
|
|
516
|
+
log2.error("ws reconnect listener failed", {
|
|
303
517
|
err
|
|
304
518
|
}, {
|
|
305
|
-
F:
|
|
306
|
-
L:
|
|
519
|
+
F: __dxlog_file3,
|
|
520
|
+
L: 217,
|
|
307
521
|
S: this,
|
|
308
522
|
C: (f, a) => f(...a)
|
|
309
523
|
});
|
|
@@ -315,12 +529,12 @@ var EdgeClient = class extends Resource {
|
|
|
315
529
|
try {
|
|
316
530
|
listener(message);
|
|
317
531
|
} catch (err) {
|
|
318
|
-
|
|
532
|
+
log2.error("ws incoming message processing failed", {
|
|
319
533
|
err,
|
|
320
534
|
payload: protocol.getPayloadType(message)
|
|
321
535
|
}, {
|
|
322
|
-
F:
|
|
323
|
-
L:
|
|
536
|
+
F: __dxlog_file3,
|
|
537
|
+
L: 227,
|
|
324
538
|
S: this,
|
|
325
539
|
C: (f, a) => f(...a)
|
|
326
540
|
});
|
|
@@ -333,9 +547,9 @@ var EdgeClient = class extends Resource {
|
|
|
333
547
|
*/
|
|
334
548
|
async send(message) {
|
|
335
549
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
336
|
-
|
|
337
|
-
F:
|
|
338
|
-
L:
|
|
550
|
+
log2("waiting for websocket to become ready", void 0, {
|
|
551
|
+
F: __dxlog_file3,
|
|
552
|
+
L: 238,
|
|
339
553
|
S: this,
|
|
340
554
|
C: (f, a) => f(...a)
|
|
341
555
|
});
|
|
@@ -360,12 +574,12 @@ var EdgeClient = class extends Resource {
|
|
|
360
574
|
if (response.status === 401) {
|
|
361
575
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
362
576
|
} else {
|
|
363
|
-
|
|
577
|
+
log2.warn("no auth challenge from edge", {
|
|
364
578
|
status: response.status,
|
|
365
579
|
statusText: response.statusText
|
|
366
580
|
}, {
|
|
367
|
-
F:
|
|
368
|
-
L:
|
|
581
|
+
F: __dxlog_file3,
|
|
582
|
+
L: 263,
|
|
369
583
|
S: this,
|
|
370
584
|
C: (f, a) => f(...a)
|
|
371
585
|
});
|
|
@@ -373,8 +587,8 @@ var EdgeClient = class extends Resource {
|
|
|
373
587
|
}
|
|
374
588
|
}
|
|
375
589
|
};
|
|
376
|
-
|
|
377
|
-
|
|
590
|
+
_ts_decorate2([
|
|
591
|
+
logInfo2
|
|
378
592
|
], EdgeClient.prototype, "info", null);
|
|
379
593
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
380
594
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
@@ -383,10 +597,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
383
597
|
|
|
384
598
|
// packages/core/mesh/edge-client/src/auth.ts
|
|
385
599
|
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
386
|
-
import { invariant as
|
|
600
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
387
601
|
import { Keyring } from "@dxos/keyring";
|
|
388
602
|
import { PublicKey } from "@dxos/keys";
|
|
389
|
-
var
|
|
603
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
390
604
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
391
605
|
return {
|
|
392
606
|
identityKey: key.toHex(),
|
|
@@ -430,8 +644,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
430
644
|
identityKey: identityKey.toHex(),
|
|
431
645
|
peerKey: peerKey.toHex(),
|
|
432
646
|
presentCredentials: async ({ challenge }) => {
|
|
433
|
-
|
|
434
|
-
F:
|
|
647
|
+
invariant3(chain, void 0, {
|
|
648
|
+
F: __dxlog_file4,
|
|
435
649
|
L: 75,
|
|
436
650
|
S: void 0,
|
|
437
651
|
A: [
|
|
@@ -494,20 +708,20 @@ var createStubEdgeIdentity = () => {
|
|
|
494
708
|
|
|
495
709
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
496
710
|
import { sleep } from "@dxos/async";
|
|
497
|
-
import { Context } from "@dxos/context";
|
|
498
|
-
import { log as
|
|
711
|
+
import { Context as Context2 } from "@dxos/context";
|
|
712
|
+
import { log as log3 } from "@dxos/log";
|
|
499
713
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
500
|
-
var
|
|
714
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
501
715
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
502
716
|
var DEFAULT_RETRY_JITTER = 500;
|
|
503
717
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
504
718
|
var EdgeHttpClient = class {
|
|
505
719
|
constructor(baseUrl) {
|
|
506
720
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
507
|
-
|
|
721
|
+
log3("created", {
|
|
508
722
|
url: this._baseUrl
|
|
509
723
|
}, {
|
|
510
|
-
F:
|
|
724
|
+
F: __dxlog_file5,
|
|
511
725
|
L: 53,
|
|
512
726
|
S: this,
|
|
513
727
|
C: (f, a) => f(...a)
|
|
@@ -639,8 +853,8 @@ var EdgeHttpClient = class {
|
|
|
639
853
|
});
|
|
640
854
|
}
|
|
641
855
|
async _call(path, args) {
|
|
642
|
-
const requestContext = args.context ?? new
|
|
643
|
-
F:
|
|
856
|
+
const requestContext = args.context ?? new Context2(void 0, {
|
|
857
|
+
F: __dxlog_file5,
|
|
644
858
|
L: 192
|
|
645
859
|
});
|
|
646
860
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -652,12 +866,12 @@ var EdgeHttpClient = class {
|
|
|
652
866
|
}
|
|
653
867
|
url += `?${queryParams.toString()}`;
|
|
654
868
|
}
|
|
655
|
-
|
|
869
|
+
log3("call", {
|
|
656
870
|
method: args.method,
|
|
657
871
|
path,
|
|
658
872
|
request: args.body
|
|
659
873
|
}, {
|
|
660
|
-
F:
|
|
874
|
+
F: __dxlog_file5,
|
|
661
875
|
L: 204,
|
|
662
876
|
S: this,
|
|
663
877
|
C: (f, a) => f(...a)
|
|
@@ -676,11 +890,11 @@ var EdgeHttpClient = class {
|
|
|
676
890
|
if (body.success) {
|
|
677
891
|
return body.data;
|
|
678
892
|
}
|
|
679
|
-
|
|
893
|
+
log3("unsuccessful edge response", {
|
|
680
894
|
path,
|
|
681
895
|
body
|
|
682
896
|
}, {
|
|
683
|
-
F:
|
|
897
|
+
F: __dxlog_file5,
|
|
684
898
|
L: 223,
|
|
685
899
|
S: this,
|
|
686
900
|
C: (f, a) => f(...a)
|
|
@@ -701,11 +915,11 @@ var EdgeHttpClient = class {
|
|
|
701
915
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
702
916
|
}
|
|
703
917
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
704
|
-
|
|
918
|
+
log3("retrying edge request", {
|
|
705
919
|
path,
|
|
706
920
|
processingError
|
|
707
921
|
}, {
|
|
708
|
-
F:
|
|
922
|
+
F: __dxlog_file5,
|
|
709
923
|
L: 242,
|
|
710
924
|
S: this,
|
|
711
925
|
C: (f, a) => f(...a)
|
|
@@ -717,8 +931,8 @@ var EdgeHttpClient = class {
|
|
|
717
931
|
}
|
|
718
932
|
async _handleUnauthorized(response) {
|
|
719
933
|
if (!this._edgeIdentity) {
|
|
720
|
-
|
|
721
|
-
F:
|
|
934
|
+
log3.warn("edge unauthorized response received before identity was set", void 0, {
|
|
935
|
+
F: __dxlog_file5,
|
|
722
936
|
L: 251,
|
|
723
937
|
S: this,
|
|
724
938
|
C: (f, a) => f(...a)
|
|
@@ -727,8 +941,8 @@ var EdgeHttpClient = class {
|
|
|
727
941
|
}
|
|
728
942
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
729
943
|
this._authHeader = encodeAuthHeader(challenge);
|
|
730
|
-
|
|
731
|
-
F:
|
|
944
|
+
log3("auth header updated", void 0, {
|
|
945
|
+
F: __dxlog_file5,
|
|
732
946
|
L: 256,
|
|
733
947
|
S: this,
|
|
734
948
|
C: (f, a) => f(...a)
|
|
@@ -771,13 +985,11 @@ var encodeAuthHeader = (challenge) => {
|
|
|
771
985
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
772
986
|
};
|
|
773
987
|
export {
|
|
774
|
-
CLOUDFLARE_MESSAGE_LENGTH_LIMIT,
|
|
775
988
|
EdgeClient,
|
|
776
989
|
EdgeConnectionClosedError,
|
|
777
990
|
EdgeHttpClient,
|
|
778
991
|
EdgeIdentityChangedError,
|
|
779
992
|
Protocol,
|
|
780
|
-
WebSocketMuxer,
|
|
781
993
|
createChainEdgeIdentity,
|
|
782
994
|
createDeviceEdgeIdentity,
|
|
783
995
|
createEphemeralEdgeIdentity,
|