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