@dxos/edge-client 0.8.2-main.12df754 → 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 +60 -282
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +32 -20
- 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 +50 -281
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +31 -21
- 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 +60 -282
- 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 +32 -20
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-ws-connection.d.ts +5 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +23 -0
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -0
- package/dist/types/src/testing/test-utils.d.ts +6 -2
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/edge-client.ts +2 -2
- package/src/edge-ws-connection.ts +38 -15
- package/src/edge-ws-muxer.ts +187 -0
- package/src/testing/test-utils.ts +33 -26
- package/dist/lib/browser/chunk-ZWJXA37R.mjs +0 -113
- package/dist/lib/browser/chunk-ZWJXA37R.mjs.map +0 -7
- package/dist/lib/node/chunk-ANV2HBEH.cjs +0 -136
- package/dist/lib/node/chunk-ANV2HBEH.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs +0 -115
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs.map +0 -7
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
+
EdgeWsConnection,
|
|
3
4
|
Protocol,
|
|
4
5
|
getTypename,
|
|
5
6
|
protocol,
|
|
6
7
|
toUint8Array
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-HNRMNQPG.mjs";
|
|
8
9
|
|
|
9
10
|
// packages/core/mesh/edge-client/src/index.ts
|
|
10
11
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
11
12
|
|
|
12
13
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
13
14
|
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
|
|
14
|
-
import { Resource
|
|
15
|
-
import { log
|
|
15
|
+
import { Resource } from "@dxos/context";
|
|
16
|
+
import { log, logInfo } from "@dxos/log";
|
|
16
17
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
17
18
|
|
|
18
19
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
@@ -55,229 +56,6 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
55
56
|
return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
56
57
|
};
|
|
57
58
|
|
|
58
|
-
// packages/core/mesh/edge-client/src/edge-ws-connection.ts
|
|
59
|
-
import WebSocket from "isomorphic-ws";
|
|
60
|
-
import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
61
|
-
import { Context, Resource } from "@dxos/context";
|
|
62
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
63
|
-
import { log, logInfo } from "@dxos/log";
|
|
64
|
-
import { buf } from "@dxos/protocols/buf";
|
|
65
|
-
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
66
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
67
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
68
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
69
|
-
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;
|
|
70
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
71
|
-
}
|
|
72
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
73
|
-
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
74
|
-
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
75
|
-
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
76
|
-
var EdgeWsConnection = class extends Resource {
|
|
77
|
-
constructor(_identity, _connectionInfo, _callbacks) {
|
|
78
|
-
super();
|
|
79
|
-
this._identity = _identity;
|
|
80
|
-
this._connectionInfo = _connectionInfo;
|
|
81
|
-
this._callbacks = _callbacks;
|
|
82
|
-
}
|
|
83
|
-
get info() {
|
|
84
|
-
return {
|
|
85
|
-
open: this.isOpen,
|
|
86
|
-
identity: this._identity.identityKey,
|
|
87
|
-
device: this._identity.peerKey
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
send(message) {
|
|
91
|
-
invariant2(this._ws, void 0, {
|
|
92
|
-
F: __dxlog_file2,
|
|
93
|
-
L: 54,
|
|
94
|
-
S: this,
|
|
95
|
-
A: [
|
|
96
|
-
"this._ws",
|
|
97
|
-
""
|
|
98
|
-
]
|
|
99
|
-
});
|
|
100
|
-
log("sending...", {
|
|
101
|
-
peerKey: this._identity.peerKey,
|
|
102
|
-
payload: protocol.getPayloadType(message)
|
|
103
|
-
}, {
|
|
104
|
-
F: __dxlog_file2,
|
|
105
|
-
L: 55,
|
|
106
|
-
S: this,
|
|
107
|
-
C: (f, a) => f(...a)
|
|
108
|
-
});
|
|
109
|
-
const encoded = buf.toBinary(MessageSchema, message);
|
|
110
|
-
if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
111
|
-
log.error("edge message dropped due to websocket message limit", {
|
|
112
|
-
byteLength: encoded.byteLength,
|
|
113
|
-
serviceId: message.serviceId,
|
|
114
|
-
payload: protocol.getPayloadType(message)
|
|
115
|
-
}, {
|
|
116
|
-
F: __dxlog_file2,
|
|
117
|
-
L: 58,
|
|
118
|
-
S: this,
|
|
119
|
-
C: (f, a) => f(...a)
|
|
120
|
-
});
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
this._ws.send(encoded);
|
|
124
|
-
}
|
|
125
|
-
async _open() {
|
|
126
|
-
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
127
|
-
this._connectionInfo.protocolHeader
|
|
128
|
-
] : []);
|
|
129
|
-
this._ws.onopen = () => {
|
|
130
|
-
if (this.isOpen) {
|
|
131
|
-
log("connected", void 0, {
|
|
132
|
-
F: __dxlog_file2,
|
|
133
|
-
L: 76,
|
|
134
|
-
S: this,
|
|
135
|
-
C: (f, a) => f(...a)
|
|
136
|
-
});
|
|
137
|
-
this._callbacks.onConnected();
|
|
138
|
-
this._scheduleHeartbeats();
|
|
139
|
-
} else {
|
|
140
|
-
log.verbose("connected after becoming inactive", {
|
|
141
|
-
currentIdentity: this._identity
|
|
142
|
-
}, {
|
|
143
|
-
F: __dxlog_file2,
|
|
144
|
-
L: 80,
|
|
145
|
-
S: this,
|
|
146
|
-
C: (f, a) => f(...a)
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
this._ws.onclose = (event) => {
|
|
151
|
-
if (this.isOpen) {
|
|
152
|
-
log.warn("disconnected while being open", {
|
|
153
|
-
code: event.code,
|
|
154
|
-
reason: event.reason
|
|
155
|
-
}, {
|
|
156
|
-
F: __dxlog_file2,
|
|
157
|
-
L: 85,
|
|
158
|
-
S: this,
|
|
159
|
-
C: (f, a) => f(...a)
|
|
160
|
-
});
|
|
161
|
-
this._callbacks.onRestartRequired();
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
this._ws.onerror = (event) => {
|
|
165
|
-
if (this.isOpen) {
|
|
166
|
-
log.warn("edge connection socket error", {
|
|
167
|
-
error: event.error,
|
|
168
|
-
info: event.message
|
|
169
|
-
}, {
|
|
170
|
-
F: __dxlog_file2,
|
|
171
|
-
L: 91,
|
|
172
|
-
S: this,
|
|
173
|
-
C: (f, a) => f(...a)
|
|
174
|
-
});
|
|
175
|
-
this._callbacks.onRestartRequired();
|
|
176
|
-
} else {
|
|
177
|
-
log.verbose("error ignored on closed connection", {
|
|
178
|
-
error: event.error
|
|
179
|
-
}, {
|
|
180
|
-
F: __dxlog_file2,
|
|
181
|
-
L: 94,
|
|
182
|
-
S: this,
|
|
183
|
-
C: (f, a) => f(...a)
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
this._ws.onmessage = async (event) => {
|
|
188
|
-
if (!this.isOpen) {
|
|
189
|
-
log.verbose("message ignored on closed connection", {
|
|
190
|
-
event: event.type
|
|
191
|
-
}, {
|
|
192
|
-
F: __dxlog_file2,
|
|
193
|
-
L: 102,
|
|
194
|
-
S: this,
|
|
195
|
-
C: (f, a) => f(...a)
|
|
196
|
-
});
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (event.data === "__pong__") {
|
|
200
|
-
this._rescheduleHeartbeatTimeout();
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
const data = await toUint8Array(event.data);
|
|
204
|
-
if (this.isOpen) {
|
|
205
|
-
const message = buf.fromBinary(MessageSchema, data);
|
|
206
|
-
log("received", {
|
|
207
|
-
from: message.source,
|
|
208
|
-
payload: protocol.getPayloadType(message)
|
|
209
|
-
}, {
|
|
210
|
-
F: __dxlog_file2,
|
|
211
|
-
L: 112,
|
|
212
|
-
S: this,
|
|
213
|
-
C: (f, a) => f(...a)
|
|
214
|
-
});
|
|
215
|
-
this._callbacks.onMessage(message);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
async _close() {
|
|
220
|
-
void this._inactivityTimeoutCtx?.dispose().catch(() => {
|
|
221
|
-
});
|
|
222
|
-
try {
|
|
223
|
-
this._ws?.close();
|
|
224
|
-
this._ws = void 0;
|
|
225
|
-
} catch (err) {
|
|
226
|
-
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
log.warn("Error closing websocket", {
|
|
230
|
-
err
|
|
231
|
-
}, {
|
|
232
|
-
F: __dxlog_file2,
|
|
233
|
-
L: 128,
|
|
234
|
-
S: this,
|
|
235
|
-
C: (f, a) => f(...a)
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
_scheduleHeartbeats() {
|
|
240
|
-
invariant2(this._ws, void 0, {
|
|
241
|
-
F: __dxlog_file2,
|
|
242
|
-
L: 133,
|
|
243
|
-
S: this,
|
|
244
|
-
A: [
|
|
245
|
-
"this._ws",
|
|
246
|
-
""
|
|
247
|
-
]
|
|
248
|
-
});
|
|
249
|
-
scheduleTaskInterval(this._ctx, async () => {
|
|
250
|
-
this._ws?.send("__ping__");
|
|
251
|
-
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
252
|
-
this._ws.send("__ping__");
|
|
253
|
-
this._rescheduleHeartbeatTimeout();
|
|
254
|
-
}
|
|
255
|
-
_rescheduleHeartbeatTimeout() {
|
|
256
|
-
if (!this.isOpen) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
void this._inactivityTimeoutCtx?.dispose();
|
|
260
|
-
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
261
|
-
F: __dxlog_file2,
|
|
262
|
-
L: 152
|
|
263
|
-
});
|
|
264
|
-
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
265
|
-
if (this.isOpen) {
|
|
266
|
-
log.warn("restart due to inactivity timeout", void 0, {
|
|
267
|
-
F: __dxlog_file2,
|
|
268
|
-
L: 157,
|
|
269
|
-
S: this,
|
|
270
|
-
C: (f, a) => f(...a)
|
|
271
|
-
});
|
|
272
|
-
this._callbacks.onRestartRequired();
|
|
273
|
-
}
|
|
274
|
-
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
_ts_decorate([
|
|
278
|
-
logInfo
|
|
279
|
-
], EdgeWsConnection.prototype, "info", null);
|
|
280
|
-
|
|
281
59
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
282
60
|
var EdgeConnectionClosedError = class extends Error {
|
|
283
61
|
constructor() {
|
|
@@ -299,15 +77,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
299
77
|
};
|
|
300
78
|
|
|
301
79
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
302
|
-
function
|
|
80
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
303
81
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
304
82
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
305
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;
|
|
306
84
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
307
85
|
}
|
|
308
|
-
var
|
|
86
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
309
87
|
var DEFAULT_TIMEOUT = 1e4;
|
|
310
|
-
var EdgeClient = class extends
|
|
88
|
+
var EdgeClient = class extends Resource {
|
|
311
89
|
constructor(_identity, _config) {
|
|
312
90
|
super();
|
|
313
91
|
this._identity = _identity;
|
|
@@ -344,18 +122,18 @@ var EdgeClient = class extends Resource2 {
|
|
|
344
122
|
}
|
|
345
123
|
setIdentity(identity) {
|
|
346
124
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
347
|
-
|
|
125
|
+
log("Edge identity changed", {
|
|
348
126
|
identity,
|
|
349
127
|
oldIdentity: this._identity
|
|
350
128
|
}, {
|
|
351
|
-
F:
|
|
129
|
+
F: __dxlog_file2,
|
|
352
130
|
L: 99,
|
|
353
131
|
S: this,
|
|
354
132
|
C: (f, a) => f(...a)
|
|
355
133
|
});
|
|
356
134
|
this._identity = identity;
|
|
357
135
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
358
|
-
this._persistentLifecycle.scheduleRestart();
|
|
136
|
+
void this._persistentLifecycle.scheduleRestart();
|
|
359
137
|
}
|
|
360
138
|
}
|
|
361
139
|
onMessage(listener) {
|
|
@@ -370,8 +148,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
370
148
|
try {
|
|
371
149
|
listener();
|
|
372
150
|
} catch (error) {
|
|
373
|
-
|
|
374
|
-
F:
|
|
151
|
+
log.catch(error, void 0, {
|
|
152
|
+
F: __dxlog_file2,
|
|
375
153
|
L: 121,
|
|
376
154
|
S: this,
|
|
377
155
|
C: (f, a) => f(...a)
|
|
@@ -386,19 +164,19 @@ var EdgeClient = class extends Resource2 {
|
|
|
386
164
|
* Open connection to messaging service.
|
|
387
165
|
*/
|
|
388
166
|
async _open() {
|
|
389
|
-
|
|
167
|
+
log("opening...", {
|
|
390
168
|
info: this.info
|
|
391
169
|
}, {
|
|
392
|
-
F:
|
|
170
|
+
F: __dxlog_file2,
|
|
393
171
|
L: 133,
|
|
394
172
|
S: this,
|
|
395
173
|
C: (f, a) => f(...a)
|
|
396
174
|
});
|
|
397
175
|
this._persistentLifecycle.open().catch((err) => {
|
|
398
|
-
|
|
176
|
+
log.warn("Error while opening connection", {
|
|
399
177
|
err
|
|
400
178
|
}, {
|
|
401
|
-
F:
|
|
179
|
+
F: __dxlog_file2,
|
|
402
180
|
L: 135,
|
|
403
181
|
S: this,
|
|
404
182
|
C: (f, a) => f(...a)
|
|
@@ -409,10 +187,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
409
187
|
* Close connection and free resources.
|
|
410
188
|
*/
|
|
411
189
|
async _close() {
|
|
412
|
-
|
|
190
|
+
log("closing...", {
|
|
413
191
|
peerKey: this._identity.peerKey
|
|
414
192
|
}, {
|
|
415
|
-
F:
|
|
193
|
+
F: __dxlog_file2,
|
|
416
194
|
L: 143,
|
|
417
195
|
S: this,
|
|
418
196
|
C: (f, a) => f(...a)
|
|
@@ -428,8 +206,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
428
206
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
429
207
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
430
208
|
if (this._identity !== identity) {
|
|
431
|
-
|
|
432
|
-
F:
|
|
209
|
+
log("identity changed during auth header request", void 0, {
|
|
210
|
+
F: __dxlog_file2,
|
|
433
211
|
L: 157,
|
|
434
212
|
S: this,
|
|
435
213
|
C: (f, a) => f(...a)
|
|
@@ -438,11 +216,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
438
216
|
}
|
|
439
217
|
const restartRequired = new Trigger();
|
|
440
218
|
const url = new URL(path, this._baseWsUrl);
|
|
441
|
-
|
|
219
|
+
log("Opening websocket", {
|
|
442
220
|
url: url.toString(),
|
|
443
221
|
protocolHeader
|
|
444
222
|
}, {
|
|
445
|
-
F:
|
|
223
|
+
F: __dxlog_file2,
|
|
446
224
|
L: 163,
|
|
447
225
|
S: this,
|
|
448
226
|
C: (f, a) => f(...a)
|
|
@@ -456,8 +234,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
456
234
|
this._ready.wake();
|
|
457
235
|
this._notifyReconnected();
|
|
458
236
|
} else {
|
|
459
|
-
|
|
460
|
-
F:
|
|
237
|
+
log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
238
|
+
F: __dxlog_file2,
|
|
461
239
|
L: 173,
|
|
462
240
|
S: this,
|
|
463
241
|
C: (f, a) => f(...a)
|
|
@@ -467,10 +245,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
467
245
|
onRestartRequired: () => {
|
|
468
246
|
if (this._isActive(connection)) {
|
|
469
247
|
this._closeCurrentConnection();
|
|
470
|
-
this._persistentLifecycle.scheduleRestart();
|
|
248
|
+
void this._persistentLifecycle.scheduleRestart();
|
|
471
249
|
} else {
|
|
472
|
-
|
|
473
|
-
F:
|
|
250
|
+
log.verbose("restart requested by inactive connection", void 0, {
|
|
251
|
+
F: __dxlog_file2,
|
|
474
252
|
L: 181,
|
|
475
253
|
S: this,
|
|
476
254
|
C: (f, a) => f(...a)
|
|
@@ -482,11 +260,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
482
260
|
if (this._isActive(connection)) {
|
|
483
261
|
this._notifyMessageReceived(message);
|
|
484
262
|
} else {
|
|
485
|
-
|
|
263
|
+
log.verbose("ignored a message on inactive connection", {
|
|
486
264
|
from: message.source,
|
|
487
265
|
type: message.payload?.typeUrl
|
|
488
266
|
}, {
|
|
489
|
-
F:
|
|
267
|
+
F: __dxlog_file2,
|
|
490
268
|
L: 189,
|
|
491
269
|
S: this,
|
|
492
270
|
C: (f, a) => f(...a)
|
|
@@ -520,10 +298,10 @@ var EdgeClient = class extends Resource2 {
|
|
|
520
298
|
try {
|
|
521
299
|
listener();
|
|
522
300
|
} catch (err) {
|
|
523
|
-
|
|
301
|
+
log.error("ws reconnect listener failed", {
|
|
524
302
|
err
|
|
525
303
|
}, {
|
|
526
|
-
F:
|
|
304
|
+
F: __dxlog_file2,
|
|
527
305
|
L: 225,
|
|
528
306
|
S: this,
|
|
529
307
|
C: (f, a) => f(...a)
|
|
@@ -536,11 +314,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
536
314
|
try {
|
|
537
315
|
listener(message);
|
|
538
316
|
} catch (err) {
|
|
539
|
-
|
|
317
|
+
log.error("ws incoming message processing failed", {
|
|
540
318
|
err,
|
|
541
319
|
payload: protocol.getPayloadType(message)
|
|
542
320
|
}, {
|
|
543
|
-
F:
|
|
321
|
+
F: __dxlog_file2,
|
|
544
322
|
L: 235,
|
|
545
323
|
S: this,
|
|
546
324
|
C: (f, a) => f(...a)
|
|
@@ -554,8 +332,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
554
332
|
*/
|
|
555
333
|
async send(message) {
|
|
556
334
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
557
|
-
|
|
558
|
-
F:
|
|
335
|
+
log("waiting for websocket to become ready", void 0, {
|
|
336
|
+
F: __dxlog_file2,
|
|
559
337
|
L: 246,
|
|
560
338
|
S: this,
|
|
561
339
|
C: (f, a) => f(...a)
|
|
@@ -581,11 +359,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
581
359
|
if (response.status === 401) {
|
|
582
360
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
583
361
|
} else {
|
|
584
|
-
|
|
362
|
+
log.warn("no auth challenge from edge", {
|
|
585
363
|
status: response.status,
|
|
586
364
|
statusText: response.statusText
|
|
587
365
|
}, {
|
|
588
|
-
F:
|
|
366
|
+
F: __dxlog_file2,
|
|
589
367
|
L: 271,
|
|
590
368
|
S: this,
|
|
591
369
|
C: (f, a) => f(...a)
|
|
@@ -594,8 +372,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
594
372
|
}
|
|
595
373
|
}
|
|
596
374
|
};
|
|
597
|
-
|
|
598
|
-
|
|
375
|
+
_ts_decorate([
|
|
376
|
+
logInfo
|
|
599
377
|
], EdgeClient.prototype, "info", null);
|
|
600
378
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
601
379
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
@@ -604,10 +382,10 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
604
382
|
|
|
605
383
|
// packages/core/mesh/edge-client/src/auth.ts
|
|
606
384
|
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
607
|
-
import { invariant as
|
|
385
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
608
386
|
import { Keyring } from "@dxos/keyring";
|
|
609
387
|
import { PublicKey } from "@dxos/keys";
|
|
610
|
-
var
|
|
388
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
611
389
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
612
390
|
return {
|
|
613
391
|
identityKey: key.toHex(),
|
|
@@ -651,8 +429,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
651
429
|
identityKey: identityKey.toHex(),
|
|
652
430
|
peerKey: peerKey.toHex(),
|
|
653
431
|
presentCredentials: async ({ challenge }) => {
|
|
654
|
-
|
|
655
|
-
F:
|
|
432
|
+
invariant2(chain, void 0, {
|
|
433
|
+
F: __dxlog_file3,
|
|
656
434
|
L: 75,
|
|
657
435
|
S: void 0,
|
|
658
436
|
A: [
|
|
@@ -715,20 +493,20 @@ var createStubEdgeIdentity = () => {
|
|
|
715
493
|
|
|
716
494
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
717
495
|
import { sleep } from "@dxos/async";
|
|
718
|
-
import { Context
|
|
719
|
-
import { log as
|
|
496
|
+
import { Context } from "@dxos/context";
|
|
497
|
+
import { log as log2 } from "@dxos/log";
|
|
720
498
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
721
|
-
var
|
|
499
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
722
500
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
723
501
|
var DEFAULT_RETRY_JITTER = 500;
|
|
724
502
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
725
503
|
var EdgeHttpClient = class {
|
|
726
504
|
constructor(baseUrl) {
|
|
727
505
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
728
|
-
|
|
506
|
+
log2("created", {
|
|
729
507
|
url: this._baseUrl
|
|
730
508
|
}, {
|
|
731
|
-
F:
|
|
509
|
+
F: __dxlog_file4,
|
|
732
510
|
L: 53,
|
|
733
511
|
S: this,
|
|
734
512
|
C: (f, a) => f(...a)
|
|
@@ -860,8 +638,8 @@ var EdgeHttpClient = class {
|
|
|
860
638
|
});
|
|
861
639
|
}
|
|
862
640
|
async _call(path, args) {
|
|
863
|
-
const requestContext = args.context ?? new
|
|
864
|
-
F:
|
|
641
|
+
const requestContext = args.context ?? new Context(void 0, {
|
|
642
|
+
F: __dxlog_file4,
|
|
865
643
|
L: 192
|
|
866
644
|
});
|
|
867
645
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -873,12 +651,12 @@ var EdgeHttpClient = class {
|
|
|
873
651
|
}
|
|
874
652
|
url += `?${queryParams.toString()}`;
|
|
875
653
|
}
|
|
876
|
-
|
|
654
|
+
log2("call", {
|
|
877
655
|
method: args.method,
|
|
878
656
|
path,
|
|
879
657
|
request: args.body
|
|
880
658
|
}, {
|
|
881
|
-
F:
|
|
659
|
+
F: __dxlog_file4,
|
|
882
660
|
L: 204,
|
|
883
661
|
S: this,
|
|
884
662
|
C: (f, a) => f(...a)
|
|
@@ -897,11 +675,11 @@ var EdgeHttpClient = class {
|
|
|
897
675
|
if (body.success) {
|
|
898
676
|
return body.data;
|
|
899
677
|
}
|
|
900
|
-
|
|
678
|
+
log2("unsuccessful edge response", {
|
|
901
679
|
path,
|
|
902
680
|
body
|
|
903
681
|
}, {
|
|
904
|
-
F:
|
|
682
|
+
F: __dxlog_file4,
|
|
905
683
|
L: 223,
|
|
906
684
|
S: this,
|
|
907
685
|
C: (f, a) => f(...a)
|
|
@@ -922,11 +700,11 @@ var EdgeHttpClient = class {
|
|
|
922
700
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
923
701
|
}
|
|
924
702
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
925
|
-
|
|
703
|
+
log2("retrying edge request", {
|
|
926
704
|
path,
|
|
927
705
|
processingError
|
|
928
706
|
}, {
|
|
929
|
-
F:
|
|
707
|
+
F: __dxlog_file4,
|
|
930
708
|
L: 242,
|
|
931
709
|
S: this,
|
|
932
710
|
C: (f, a) => f(...a)
|
|
@@ -938,8 +716,8 @@ var EdgeHttpClient = class {
|
|
|
938
716
|
}
|
|
939
717
|
async _handleUnauthorized(response) {
|
|
940
718
|
if (!this._edgeIdentity) {
|
|
941
|
-
|
|
942
|
-
F:
|
|
719
|
+
log2.warn("edge unauthorized response received before identity was set", void 0, {
|
|
720
|
+
F: __dxlog_file4,
|
|
943
721
|
L: 251,
|
|
944
722
|
S: this,
|
|
945
723
|
C: (f, a) => f(...a)
|
|
@@ -948,8 +726,8 @@ var EdgeHttpClient = class {
|
|
|
948
726
|
}
|
|
949
727
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
950
728
|
this._authHeader = encodeAuthHeader(challenge);
|
|
951
|
-
|
|
952
|
-
F:
|
|
729
|
+
log2("auth header updated", void 0, {
|
|
730
|
+
F: __dxlog_file4,
|
|
953
731
|
L: 256,
|
|
954
732
|
S: this,
|
|
955
733
|
C: (f, a) => f(...a)
|