@dxos/edge-client 0.8.2-main.5885341 → 0.8.2-main.85fa0e5
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 → chunk-CFIVYHE6.mjs} +277 -28
- package/dist/lib/browser/chunk-CFIVYHE6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +62 -312
- 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-FQM4JFRT.cjs +586 -0
- package/dist/lib/node/chunk-FQM4JFRT.cjs.map +7 -0
- package/dist/lib/node/index.cjs +60 -319
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +5 -6
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-25HGRGNZ.mjs → chunk-APWFVC3U.mjs} +277 -28
- package/dist/lib/node-esm/chunk-APWFVC3U.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +62 -312
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +3 -3
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-ws-connection.d.ts +5 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts +1 -4
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/package.json +14 -19
- package/src/edge-ws-connection.ts +9 -4
- package/src/edge-ws-muxer.ts +6 -21
- package/src/index.ts +1 -0
- package/src/testing/test-utils.ts +2 -2
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs.map +0 -7
- package/dist/lib/browser/edge-ws-muxer.mjs +0 -11
- package/dist/lib/browser/edge-ws-muxer.mjs.map +0 -7
- package/dist/lib/node/chunk-ZOL3YSDR.cjs +0 -322
- package/dist/lib/node/chunk-ZOL3YSDR.cjs.map +0 -7
- package/dist/lib/node/edge-ws-muxer.cjs +0 -33
- package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
- package/dist/types/src/edge-ws-muxer.test.d.ts +0 -2
- package/dist/types/src/edge-ws-muxer.test.d.ts.map +0 -1
- package/src/edge-ws-muxer.test.ts +0 -55
package/dist/lib/node/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -18,37 +16,31 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
20
|
var node_exports = {};
|
|
31
21
|
__export(node_exports, {
|
|
32
|
-
CLOUDFLARE_MESSAGE_MAX_BYTES: () =>
|
|
33
|
-
CLOUDFLARE_RPC_MAX_BYTES: () =>
|
|
22
|
+
CLOUDFLARE_MESSAGE_MAX_BYTES: () => import_chunk_FQM4JFRT.CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
23
|
+
CLOUDFLARE_RPC_MAX_BYTES: () => import_chunk_FQM4JFRT.CLOUDFLARE_RPC_MAX_BYTES,
|
|
24
|
+
EDGE_WEBSOCKET_PROTOCOL_V0: () => import_chunk_FQM4JFRT.EDGE_WEBSOCKET_PROTOCOL_V0,
|
|
25
|
+
EDGE_WEBSOCKET_PROTOCOL_V1: () => import_chunk_FQM4JFRT.EDGE_WEBSOCKET_PROTOCOL_V1,
|
|
34
26
|
EdgeClient: () => EdgeClient,
|
|
35
27
|
EdgeConnectionClosedError: () => EdgeConnectionClosedError,
|
|
36
28
|
EdgeHttpClient: () => EdgeHttpClient,
|
|
37
29
|
EdgeIdentityChangedError: () => EdgeIdentityChangedError,
|
|
38
|
-
Protocol: () =>
|
|
39
|
-
WebSocketMuxer: () =>
|
|
30
|
+
Protocol: () => import_chunk_FQM4JFRT.Protocol,
|
|
31
|
+
WebSocketMuxer: () => import_chunk_FQM4JFRT.WebSocketMuxer,
|
|
40
32
|
createChainEdgeIdentity: () => createChainEdgeIdentity,
|
|
41
33
|
createDeviceEdgeIdentity: () => createDeviceEdgeIdentity,
|
|
42
34
|
createEphemeralEdgeIdentity: () => createEphemeralEdgeIdentity,
|
|
43
35
|
createStubEdgeIdentity: () => createStubEdgeIdentity,
|
|
44
36
|
createTestHaloEdgeIdentity: () => createTestHaloEdgeIdentity,
|
|
45
|
-
getTypename: () =>
|
|
37
|
+
getTypename: () => import_chunk_FQM4JFRT.getTypename,
|
|
46
38
|
handleAuthChallenge: () => handleAuthChallenge,
|
|
47
|
-
protocol: () =>
|
|
48
|
-
toUint8Array: () =>
|
|
39
|
+
protocol: () => import_chunk_FQM4JFRT.protocol,
|
|
40
|
+
toUint8Array: () => import_chunk_FQM4JFRT.toUint8Array
|
|
49
41
|
});
|
|
50
42
|
module.exports = __toCommonJS(node_exports);
|
|
51
|
-
var
|
|
43
|
+
var import_chunk_FQM4JFRT = require("./chunk-FQM4JFRT.cjs");
|
|
52
44
|
__reExport(node_exports, require("@dxos/protocols/buf/dxos/edge/messenger_pb"), module.exports);
|
|
53
45
|
var import_async = require("@dxos/async");
|
|
54
46
|
var import_context = require("@dxos/context");
|
|
@@ -56,22 +48,14 @@ var import_log = require("@dxos/log");
|
|
|
56
48
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
57
49
|
var import_invariant = require("@dxos/invariant");
|
|
58
50
|
var import_proto = require("@dxos/protocols/proto");
|
|
59
|
-
var
|
|
51
|
+
var import_credentials = require("@dxos/credentials");
|
|
52
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
53
|
+
var import_keyring = require("@dxos/keyring");
|
|
54
|
+
var import_keys = require("@dxos/keys");
|
|
60
55
|
var import_async2 = require("@dxos/async");
|
|
61
56
|
var import_context2 = require("@dxos/context");
|
|
62
|
-
var import_invariant2 = require("@dxos/invariant");
|
|
63
57
|
var import_log2 = require("@dxos/log");
|
|
64
58
|
var import_protocols = require("@dxos/protocols");
|
|
65
|
-
var import_buf = require("@dxos/protocols/buf");
|
|
66
|
-
var import_messenger_pb = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
|
|
67
|
-
var import_credentials = require("@dxos/credentials");
|
|
68
|
-
var import_invariant3 = require("@dxos/invariant");
|
|
69
|
-
var import_keyring = require("@dxos/keyring");
|
|
70
|
-
var import_keys = require("@dxos/keys");
|
|
71
|
-
var import_async3 = require("@dxos/async");
|
|
72
|
-
var import_context3 = require("@dxos/context");
|
|
73
|
-
var import_log3 = require("@dxos/log");
|
|
74
|
-
var import_protocols2 = require("@dxos/protocols");
|
|
75
59
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
|
|
76
60
|
var handleAuthChallenge = async (failedResponse, identity) => {
|
|
77
61
|
(0, import_invariant.invariant)(failedResponse.status === 401, void 0, {
|
|
@@ -108,251 +92,6 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
108
92
|
});
|
|
109
93
|
return import_proto.schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
110
94
|
};
|
|
111
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
112
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
113
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
114
|
-
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;
|
|
115
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
116
|
-
}
|
|
117
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
118
|
-
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
119
|
-
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
120
|
-
var EdgeWsConnection = class extends import_context2.Resource {
|
|
121
|
-
constructor(_identity, _connectionInfo, _callbacks) {
|
|
122
|
-
super();
|
|
123
|
-
this._identity = _identity;
|
|
124
|
-
this._connectionInfo = _connectionInfo;
|
|
125
|
-
this._callbacks = _callbacks;
|
|
126
|
-
}
|
|
127
|
-
get info() {
|
|
128
|
-
return {
|
|
129
|
-
open: this.isOpen,
|
|
130
|
-
identity: this._identity.identityKey,
|
|
131
|
-
device: this._identity.peerKey
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
send(message) {
|
|
135
|
-
(0, import_invariant2.invariant)(this._ws, void 0, {
|
|
136
|
-
F: __dxlog_file2,
|
|
137
|
-
L: 52,
|
|
138
|
-
S: this,
|
|
139
|
-
A: [
|
|
140
|
-
"this._ws",
|
|
141
|
-
""
|
|
142
|
-
]
|
|
143
|
-
});
|
|
144
|
-
(0, import_invariant2.invariant)(this._wsMuxer, void 0, {
|
|
145
|
-
F: __dxlog_file2,
|
|
146
|
-
L: 53,
|
|
147
|
-
S: this,
|
|
148
|
-
A: [
|
|
149
|
-
"this._wsMuxer",
|
|
150
|
-
""
|
|
151
|
-
]
|
|
152
|
-
});
|
|
153
|
-
(0, import_log2.log)("sending...", {
|
|
154
|
-
peerKey: this._identity.peerKey,
|
|
155
|
-
payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
|
|
156
|
-
}, {
|
|
157
|
-
F: __dxlog_file2,
|
|
158
|
-
L: 54,
|
|
159
|
-
S: this,
|
|
160
|
-
C: (f, a) => f(...a)
|
|
161
|
-
});
|
|
162
|
-
if (this._ws?.protocol.includes(import_protocols.EdgeWebsocketProtocol.V0)) {
|
|
163
|
-
const binary = import_buf.buf.toBinary(import_messenger_pb.MessageSchema, message);
|
|
164
|
-
if (binary.length > import_chunk_ZOL3YSDR.CLOUDFLARE_MESSAGE_MAX_BYTES) {
|
|
165
|
-
import_log2.log.error("Message dropped because it was too large (>1MB).", {
|
|
166
|
-
byteLength: binary.byteLength,
|
|
167
|
-
serviceId: message.serviceId,
|
|
168
|
-
payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
|
|
169
|
-
}, {
|
|
170
|
-
F: __dxlog_file2,
|
|
171
|
-
L: 58,
|
|
172
|
-
S: this,
|
|
173
|
-
C: (f, a) => f(...a)
|
|
174
|
-
});
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
this._ws.send(binary);
|
|
178
|
-
} else {
|
|
179
|
-
this._wsMuxer.send(message).catch((e) => import_log2.log.catch(e, void 0, {
|
|
180
|
-
F: __dxlog_file2,
|
|
181
|
-
L: 67,
|
|
182
|
-
S: this,
|
|
183
|
-
C: (f, a) => f(...a)
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async _open() {
|
|
188
|
-
const baseProtocols = [
|
|
189
|
-
...Object.values(import_protocols.EdgeWebsocketProtocol)
|
|
190
|
-
];
|
|
191
|
-
this._ws = new import_isomorphic_ws.default(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
192
|
-
...baseProtocols,
|
|
193
|
-
this._connectionInfo.protocolHeader
|
|
194
|
-
] : [
|
|
195
|
-
...baseProtocols
|
|
196
|
-
]);
|
|
197
|
-
const muxer = new import_chunk_ZOL3YSDR.WebSocketMuxer(this._ws);
|
|
198
|
-
this._wsMuxer = muxer;
|
|
199
|
-
this._ws.onopen = () => {
|
|
200
|
-
if (this.isOpen) {
|
|
201
|
-
(0, import_log2.log)("connected", void 0, {
|
|
202
|
-
F: __dxlog_file2,
|
|
203
|
-
L: 84,
|
|
204
|
-
S: this,
|
|
205
|
-
C: (f, a) => f(...a)
|
|
206
|
-
});
|
|
207
|
-
this._callbacks.onConnected();
|
|
208
|
-
this._scheduleHeartbeats();
|
|
209
|
-
} else {
|
|
210
|
-
import_log2.log.verbose("connected after becoming inactive", {
|
|
211
|
-
currentIdentity: this._identity
|
|
212
|
-
}, {
|
|
213
|
-
F: __dxlog_file2,
|
|
214
|
-
L: 88,
|
|
215
|
-
S: this,
|
|
216
|
-
C: (f, a) => f(...a)
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
this._ws.onclose = (event) => {
|
|
221
|
-
if (this.isOpen) {
|
|
222
|
-
import_log2.log.warn("disconnected while being open", {
|
|
223
|
-
code: event.code,
|
|
224
|
-
reason: event.reason
|
|
225
|
-
}, {
|
|
226
|
-
F: __dxlog_file2,
|
|
227
|
-
L: 93,
|
|
228
|
-
S: this,
|
|
229
|
-
C: (f, a) => f(...a)
|
|
230
|
-
});
|
|
231
|
-
this._callbacks.onRestartRequired();
|
|
232
|
-
muxer.destroy();
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
this._ws.onerror = (event) => {
|
|
236
|
-
if (this.isOpen) {
|
|
237
|
-
import_log2.log.warn("edge connection socket error", {
|
|
238
|
-
error: event.error,
|
|
239
|
-
info: event.message
|
|
240
|
-
}, {
|
|
241
|
-
F: __dxlog_file2,
|
|
242
|
-
L: 100,
|
|
243
|
-
S: this,
|
|
244
|
-
C: (f, a) => f(...a)
|
|
245
|
-
});
|
|
246
|
-
this._callbacks.onRestartRequired();
|
|
247
|
-
} else {
|
|
248
|
-
import_log2.log.verbose("error ignored on closed connection", {
|
|
249
|
-
error: event.error
|
|
250
|
-
}, {
|
|
251
|
-
F: __dxlog_file2,
|
|
252
|
-
L: 103,
|
|
253
|
-
S: this,
|
|
254
|
-
C: (f, a) => f(...a)
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
this._ws.onmessage = async (event) => {
|
|
259
|
-
if (!this.isOpen) {
|
|
260
|
-
import_log2.log.verbose("message ignored on closed connection", {
|
|
261
|
-
event: event.type
|
|
262
|
-
}, {
|
|
263
|
-
F: __dxlog_file2,
|
|
264
|
-
L: 111,
|
|
265
|
-
S: this,
|
|
266
|
-
C: (f, a) => f(...a)
|
|
267
|
-
});
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (event.data === "__pong__") {
|
|
271
|
-
this._rescheduleHeartbeatTimeout();
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
const bytes = await (0, import_chunk_ZOL3YSDR.toUint8Array)(event.data);
|
|
275
|
-
if (!this.isOpen) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const message = this._ws?.protocol?.includes(import_protocols.EdgeWebsocketProtocol.V0) ? import_buf.buf.fromBinary(import_messenger_pb.MessageSchema, bytes) : muxer.receiveData(bytes);
|
|
279
|
-
if (message) {
|
|
280
|
-
(0, import_log2.log)("received", {
|
|
281
|
-
from: message.source,
|
|
282
|
-
payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
|
|
283
|
-
}, {
|
|
284
|
-
F: __dxlog_file2,
|
|
285
|
-
L: 128,
|
|
286
|
-
S: this,
|
|
287
|
-
C: (f, a) => f(...a)
|
|
288
|
-
});
|
|
289
|
-
this._callbacks.onMessage(message);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
async _close() {
|
|
294
|
-
void this._inactivityTimeoutCtx?.dispose().catch(() => {
|
|
295
|
-
});
|
|
296
|
-
try {
|
|
297
|
-
this._ws?.close();
|
|
298
|
-
this._ws = void 0;
|
|
299
|
-
this._wsMuxer?.destroy();
|
|
300
|
-
this._wsMuxer = void 0;
|
|
301
|
-
} catch (err) {
|
|
302
|
-
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
import_log2.log.warn("Error closing websocket", {
|
|
306
|
-
err
|
|
307
|
-
}, {
|
|
308
|
-
F: __dxlog_file2,
|
|
309
|
-
L: 146,
|
|
310
|
-
S: this,
|
|
311
|
-
C: (f, a) => f(...a)
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
_scheduleHeartbeats() {
|
|
316
|
-
(0, import_invariant2.invariant)(this._ws, void 0, {
|
|
317
|
-
F: __dxlog_file2,
|
|
318
|
-
L: 151,
|
|
319
|
-
S: this,
|
|
320
|
-
A: [
|
|
321
|
-
"this._ws",
|
|
322
|
-
""
|
|
323
|
-
]
|
|
324
|
-
});
|
|
325
|
-
(0, import_async2.scheduleTaskInterval)(this._ctx, async () => {
|
|
326
|
-
this._ws?.send("__ping__");
|
|
327
|
-
}, SIGNAL_KEEPALIVE_INTERVAL);
|
|
328
|
-
this._ws.send("__ping__");
|
|
329
|
-
this._rescheduleHeartbeatTimeout();
|
|
330
|
-
}
|
|
331
|
-
_rescheduleHeartbeatTimeout() {
|
|
332
|
-
if (!this.isOpen) {
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
void this._inactivityTimeoutCtx?.dispose();
|
|
336
|
-
this._inactivityTimeoutCtx = new import_context2.Context(void 0, {
|
|
337
|
-
F: __dxlog_file2,
|
|
338
|
-
L: 170
|
|
339
|
-
});
|
|
340
|
-
(0, import_async2.scheduleTask)(this._inactivityTimeoutCtx, () => {
|
|
341
|
-
if (this.isOpen) {
|
|
342
|
-
import_log2.log.warn("restart due to inactivity timeout", void 0, {
|
|
343
|
-
F: __dxlog_file2,
|
|
344
|
-
L: 175,
|
|
345
|
-
S: this,
|
|
346
|
-
C: (f, a) => f(...a)
|
|
347
|
-
});
|
|
348
|
-
this._callbacks.onRestartRequired();
|
|
349
|
-
}
|
|
350
|
-
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
_ts_decorate([
|
|
354
|
-
import_log2.logInfo
|
|
355
|
-
], EdgeWsConnection.prototype, "info", null);
|
|
356
95
|
var EdgeConnectionClosedError = class extends Error {
|
|
357
96
|
constructor() {
|
|
358
97
|
super("Edge connection closed.");
|
|
@@ -369,13 +108,13 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
369
108
|
url.protocol = protocol2 + (isSecure ? "s" : "");
|
|
370
109
|
return url.toString();
|
|
371
110
|
};
|
|
372
|
-
function
|
|
111
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
373
112
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
374
113
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
375
114
|
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;
|
|
376
115
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
377
116
|
}
|
|
378
|
-
var
|
|
117
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
379
118
|
var DEFAULT_TIMEOUT = 1e4;
|
|
380
119
|
var EdgeClient = class extends import_context.Resource {
|
|
381
120
|
constructor(_identity, _config) {
|
|
@@ -418,7 +157,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
418
157
|
identity,
|
|
419
158
|
oldIdentity: this._identity
|
|
420
159
|
}, {
|
|
421
|
-
F:
|
|
160
|
+
F: __dxlog_file2,
|
|
422
161
|
L: 99,
|
|
423
162
|
S: this,
|
|
424
163
|
C: (f, a) => f(...a)
|
|
@@ -441,7 +180,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
441
180
|
listener();
|
|
442
181
|
} catch (error) {
|
|
443
182
|
import_log.log.catch(error, void 0, {
|
|
444
|
-
F:
|
|
183
|
+
F: __dxlog_file2,
|
|
445
184
|
L: 121,
|
|
446
185
|
S: this,
|
|
447
186
|
C: (f, a) => f(...a)
|
|
@@ -459,7 +198,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
459
198
|
(0, import_log.log)("opening...", {
|
|
460
199
|
info: this.info
|
|
461
200
|
}, {
|
|
462
|
-
F:
|
|
201
|
+
F: __dxlog_file2,
|
|
463
202
|
L: 133,
|
|
464
203
|
S: this,
|
|
465
204
|
C: (f, a) => f(...a)
|
|
@@ -468,7 +207,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
468
207
|
import_log.log.warn("Error while opening connection", {
|
|
469
208
|
err
|
|
470
209
|
}, {
|
|
471
|
-
F:
|
|
210
|
+
F: __dxlog_file2,
|
|
472
211
|
L: 135,
|
|
473
212
|
S: this,
|
|
474
213
|
C: (f, a) => f(...a)
|
|
@@ -482,7 +221,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
482
221
|
(0, import_log.log)("closing...", {
|
|
483
222
|
peerKey: this._identity.peerKey
|
|
484
223
|
}, {
|
|
485
|
-
F:
|
|
224
|
+
F: __dxlog_file2,
|
|
486
225
|
L: 143,
|
|
487
226
|
S: this,
|
|
488
227
|
C: (f, a) => f(...a)
|
|
@@ -499,7 +238,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
499
238
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
500
239
|
if (this._identity !== identity) {
|
|
501
240
|
(0, import_log.log)("identity changed during auth header request", void 0, {
|
|
502
|
-
F:
|
|
241
|
+
F: __dxlog_file2,
|
|
503
242
|
L: 157,
|
|
504
243
|
S: this,
|
|
505
244
|
C: (f, a) => f(...a)
|
|
@@ -512,12 +251,12 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
512
251
|
url: url.toString(),
|
|
513
252
|
protocolHeader
|
|
514
253
|
}, {
|
|
515
|
-
F:
|
|
254
|
+
F: __dxlog_file2,
|
|
516
255
|
L: 163,
|
|
517
256
|
S: this,
|
|
518
257
|
C: (f, a) => f(...a)
|
|
519
258
|
});
|
|
520
|
-
const connection = new EdgeWsConnection(identity, {
|
|
259
|
+
const connection = new import_chunk_FQM4JFRT.EdgeWsConnection(identity, {
|
|
521
260
|
url,
|
|
522
261
|
protocolHeader
|
|
523
262
|
}, {
|
|
@@ -527,7 +266,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
527
266
|
this._notifyReconnected();
|
|
528
267
|
} else {
|
|
529
268
|
import_log.log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
530
|
-
F:
|
|
269
|
+
F: __dxlog_file2,
|
|
531
270
|
L: 173,
|
|
532
271
|
S: this,
|
|
533
272
|
C: (f, a) => f(...a)
|
|
@@ -540,7 +279,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
540
279
|
void this._persistentLifecycle.scheduleRestart();
|
|
541
280
|
} else {
|
|
542
281
|
import_log.log.verbose("restart requested by inactive connection", void 0, {
|
|
543
|
-
F:
|
|
282
|
+
F: __dxlog_file2,
|
|
544
283
|
L: 181,
|
|
545
284
|
S: this,
|
|
546
285
|
C: (f, a) => f(...a)
|
|
@@ -556,7 +295,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
556
295
|
from: message.source,
|
|
557
296
|
type: message.payload?.typeUrl
|
|
558
297
|
}, {
|
|
559
|
-
F:
|
|
298
|
+
F: __dxlog_file2,
|
|
560
299
|
L: 189,
|
|
561
300
|
S: this,
|
|
562
301
|
C: (f, a) => f(...a)
|
|
@@ -593,7 +332,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
593
332
|
import_log.log.error("ws reconnect listener failed", {
|
|
594
333
|
err
|
|
595
334
|
}, {
|
|
596
|
-
F:
|
|
335
|
+
F: __dxlog_file2,
|
|
597
336
|
L: 225,
|
|
598
337
|
S: this,
|
|
599
338
|
C: (f, a) => f(...a)
|
|
@@ -608,9 +347,9 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
608
347
|
} catch (err) {
|
|
609
348
|
import_log.log.error("ws incoming message processing failed", {
|
|
610
349
|
err,
|
|
611
|
-
payload:
|
|
350
|
+
payload: import_chunk_FQM4JFRT.protocol.getPayloadType(message)
|
|
612
351
|
}, {
|
|
613
|
-
F:
|
|
352
|
+
F: __dxlog_file2,
|
|
614
353
|
L: 235,
|
|
615
354
|
S: this,
|
|
616
355
|
C: (f, a) => f(...a)
|
|
@@ -625,7 +364,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
625
364
|
async send(message) {
|
|
626
365
|
if (this._ready.state !== import_async.TriggerState.RESOLVED) {
|
|
627
366
|
(0, import_log.log)("waiting for websocket to become ready", void 0, {
|
|
628
|
-
F:
|
|
367
|
+
F: __dxlog_file2,
|
|
629
368
|
L: 246,
|
|
630
369
|
S: this,
|
|
631
370
|
C: (f, a) => f(...a)
|
|
@@ -655,7 +394,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
655
394
|
status: response.status,
|
|
656
395
|
statusText: response.statusText
|
|
657
396
|
}, {
|
|
658
|
-
F:
|
|
397
|
+
F: __dxlog_file2,
|
|
659
398
|
L: 271,
|
|
660
399
|
S: this,
|
|
661
400
|
C: (f, a) => f(...a)
|
|
@@ -664,14 +403,14 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
664
403
|
}
|
|
665
404
|
}
|
|
666
405
|
};
|
|
667
|
-
|
|
406
|
+
_ts_decorate([
|
|
668
407
|
import_log.logInfo
|
|
669
408
|
], EdgeClient.prototype, "info", null);
|
|
670
409
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
671
410
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
672
411
|
return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
|
|
673
412
|
};
|
|
674
|
-
var
|
|
413
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
675
414
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
676
415
|
return {
|
|
677
416
|
identityKey: key.toHex(),
|
|
@@ -715,8 +454,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
715
454
|
identityKey: identityKey.toHex(),
|
|
716
455
|
peerKey: peerKey.toHex(),
|
|
717
456
|
presentCredentials: async ({ challenge }) => {
|
|
718
|
-
(0,
|
|
719
|
-
F:
|
|
457
|
+
(0, import_invariant2.invariant)(chain, void 0, {
|
|
458
|
+
F: __dxlog_file3,
|
|
720
459
|
L: 75,
|
|
721
460
|
S: void 0,
|
|
722
461
|
A: [
|
|
@@ -776,17 +515,17 @@ var createStubEdgeIdentity = () => {
|
|
|
776
515
|
}
|
|
777
516
|
};
|
|
778
517
|
};
|
|
779
|
-
var
|
|
518
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
780
519
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
781
520
|
var DEFAULT_RETRY_JITTER = 500;
|
|
782
521
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
783
522
|
var EdgeHttpClient = class {
|
|
784
523
|
constructor(baseUrl) {
|
|
785
524
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
786
|
-
(0,
|
|
525
|
+
(0, import_log2.log)("created", {
|
|
787
526
|
url: this._baseUrl
|
|
788
527
|
}, {
|
|
789
|
-
F:
|
|
528
|
+
F: __dxlog_file4,
|
|
790
529
|
L: 53,
|
|
791
530
|
S: this,
|
|
792
531
|
C: (f, a) => f(...a)
|
|
@@ -918,8 +657,8 @@ var EdgeHttpClient = class {
|
|
|
918
657
|
});
|
|
919
658
|
}
|
|
920
659
|
async _call(path, args) {
|
|
921
|
-
const requestContext = args.context ?? new
|
|
922
|
-
F:
|
|
660
|
+
const requestContext = args.context ?? new import_context2.Context(void 0, {
|
|
661
|
+
F: __dxlog_file4,
|
|
923
662
|
L: 192
|
|
924
663
|
});
|
|
925
664
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -931,12 +670,12 @@ var EdgeHttpClient = class {
|
|
|
931
670
|
}
|
|
932
671
|
url += `?${queryParams.toString()}`;
|
|
933
672
|
}
|
|
934
|
-
(0,
|
|
673
|
+
(0, import_log2.log)("call", {
|
|
935
674
|
method: args.method,
|
|
936
675
|
path,
|
|
937
676
|
request: args.body
|
|
938
677
|
}, {
|
|
939
|
-
F:
|
|
678
|
+
F: __dxlog_file4,
|
|
940
679
|
L: 204,
|
|
941
680
|
S: this,
|
|
942
681
|
C: (f, a) => f(...a)
|
|
@@ -955,36 +694,36 @@ var EdgeHttpClient = class {
|
|
|
955
694
|
if (body.success) {
|
|
956
695
|
return body.data;
|
|
957
696
|
}
|
|
958
|
-
(0,
|
|
697
|
+
(0, import_log2.log)("unsuccessful edge response", {
|
|
959
698
|
path,
|
|
960
699
|
body
|
|
961
700
|
}, {
|
|
962
|
-
F:
|
|
701
|
+
F: __dxlog_file4,
|
|
963
702
|
L: 223,
|
|
964
703
|
S: this,
|
|
965
704
|
C: (f, a) => f(...a)
|
|
966
705
|
});
|
|
967
706
|
if (body.errorData?.type === "auth_challenge" && typeof body.errorData?.challenge === "string") {
|
|
968
|
-
processingError = new
|
|
707
|
+
processingError = new import_protocols.EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
|
|
969
708
|
} else {
|
|
970
|
-
processingError =
|
|
709
|
+
processingError = import_protocols.EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
971
710
|
}
|
|
972
711
|
} else if (response.status === 401 && !handledAuth) {
|
|
973
712
|
authHeader = await this._handleUnauthorized(response);
|
|
974
713
|
handledAuth = true;
|
|
975
714
|
continue;
|
|
976
715
|
} else {
|
|
977
|
-
processingError =
|
|
716
|
+
processingError = import_protocols.EdgeCallFailedError.fromHttpFailure(response);
|
|
978
717
|
}
|
|
979
718
|
} catch (error) {
|
|
980
|
-
processingError =
|
|
719
|
+
processingError = import_protocols.EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
981
720
|
}
|
|
982
721
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
983
|
-
(0,
|
|
722
|
+
(0, import_log2.log)("retrying edge request", {
|
|
984
723
|
path,
|
|
985
724
|
processingError
|
|
986
725
|
}, {
|
|
987
|
-
F:
|
|
726
|
+
F: __dxlog_file4,
|
|
988
727
|
L: 242,
|
|
989
728
|
S: this,
|
|
990
729
|
C: (f, a) => f(...a)
|
|
@@ -996,18 +735,18 @@ var EdgeHttpClient = class {
|
|
|
996
735
|
}
|
|
997
736
|
async _handleUnauthorized(response) {
|
|
998
737
|
if (!this._edgeIdentity) {
|
|
999
|
-
|
|
1000
|
-
F:
|
|
738
|
+
import_log2.log.warn("edge unauthorized response received before identity was set", void 0, {
|
|
739
|
+
F: __dxlog_file4,
|
|
1001
740
|
L: 251,
|
|
1002
741
|
S: this,
|
|
1003
742
|
C: (f, a) => f(...a)
|
|
1004
743
|
});
|
|
1005
|
-
throw
|
|
744
|
+
throw import_protocols.EdgeCallFailedError.fromHttpFailure(response);
|
|
1006
745
|
}
|
|
1007
746
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
1008
747
|
this._authHeader = encodeAuthHeader(challenge);
|
|
1009
|
-
(0,
|
|
1010
|
-
F:
|
|
748
|
+
(0, import_log2.log)("auth header updated", void 0, {
|
|
749
|
+
F: __dxlog_file4,
|
|
1011
750
|
L: 256,
|
|
1012
751
|
S: this,
|
|
1013
752
|
C: (f, a) => f(...a)
|
|
@@ -1028,10 +767,10 @@ var createRetryHandler = (args) => {
|
|
|
1028
767
|
return false;
|
|
1029
768
|
}
|
|
1030
769
|
if (retryAfter) {
|
|
1031
|
-
await (0,
|
|
770
|
+
await (0, import_async2.sleep)(retryAfter);
|
|
1032
771
|
} else {
|
|
1033
772
|
const timeout = baseTimeout + Math.random() * jitter;
|
|
1034
|
-
await (0,
|
|
773
|
+
await (0, import_async2.sleep)(timeout);
|
|
1035
774
|
}
|
|
1036
775
|
return true;
|
|
1037
776
|
};
|
|
@@ -1053,6 +792,8 @@ var encodeAuthHeader = (challenge) => {
|
|
|
1053
792
|
0 && (module.exports = {
|
|
1054
793
|
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1055
794
|
CLOUDFLARE_RPC_MAX_BYTES,
|
|
795
|
+
EDGE_WEBSOCKET_PROTOCOL_V0,
|
|
796
|
+
EDGE_WEBSOCKET_PROTOCOL_V1,
|
|
1056
797
|
EdgeClient,
|
|
1057
798
|
EdgeConnectionClosedError,
|
|
1058
799
|
EdgeHttpClient,
|