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