@dxos/edge-client 0.8.2-main.36232bc → 0.8.2-main.5885341
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 +318 -58
- 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 +322 -53
- 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 +318 -58
- 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 +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/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 +19 -14
- 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/index.ts +1 -0
- package/src/testing/test-utils.ts +2 -2
- package/dist/lib/browser/chunk-XS3TKGM4.mjs +0 -545
- package/dist/lib/browser/chunk-XS3TKGM4.mjs.map +0 -7
- package/dist/lib/node/chunk-ZURVCY7K.cjs +0 -577
- package/dist/lib/node/chunk-ZURVCY7K.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs +0 -547
- package/dist/lib/node-esm/chunk-HNRMNQPG.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -16,26 +18,37 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
18
20
|
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
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
var node_exports = {};
|
|
21
31
|
__export(node_exports, {
|
|
32
|
+
CLOUDFLARE_MESSAGE_MAX_BYTES: () => import_chunk_ZOL3YSDR.CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
33
|
+
CLOUDFLARE_RPC_MAX_BYTES: () => import_chunk_ZOL3YSDR.CLOUDFLARE_RPC_MAX_BYTES,
|
|
22
34
|
EdgeClient: () => EdgeClient,
|
|
23
35
|
EdgeConnectionClosedError: () => EdgeConnectionClosedError,
|
|
24
36
|
EdgeHttpClient: () => EdgeHttpClient,
|
|
25
37
|
EdgeIdentityChangedError: () => EdgeIdentityChangedError,
|
|
26
|
-
Protocol: () =>
|
|
38
|
+
Protocol: () => import_chunk_ZOL3YSDR.Protocol,
|
|
39
|
+
WebSocketMuxer: () => import_chunk_ZOL3YSDR.WebSocketMuxer,
|
|
27
40
|
createChainEdgeIdentity: () => createChainEdgeIdentity,
|
|
28
41
|
createDeviceEdgeIdentity: () => createDeviceEdgeIdentity,
|
|
29
42
|
createEphemeralEdgeIdentity: () => createEphemeralEdgeIdentity,
|
|
30
43
|
createStubEdgeIdentity: () => createStubEdgeIdentity,
|
|
31
44
|
createTestHaloEdgeIdentity: () => createTestHaloEdgeIdentity,
|
|
32
|
-
getTypename: () =>
|
|
45
|
+
getTypename: () => import_chunk_ZOL3YSDR.getTypename,
|
|
33
46
|
handleAuthChallenge: () => handleAuthChallenge,
|
|
34
|
-
protocol: () =>
|
|
35
|
-
toUint8Array: () =>
|
|
47
|
+
protocol: () => import_chunk_ZOL3YSDR.protocol,
|
|
48
|
+
toUint8Array: () => import_chunk_ZOL3YSDR.toUint8Array
|
|
36
49
|
});
|
|
37
50
|
module.exports = __toCommonJS(node_exports);
|
|
38
|
-
var
|
|
51
|
+
var import_chunk_ZOL3YSDR = require("./chunk-ZOL3YSDR.cjs");
|
|
39
52
|
__reExport(node_exports, require("@dxos/protocols/buf/dxos/edge/messenger_pb"), module.exports);
|
|
40
53
|
var import_async = require("@dxos/async");
|
|
41
54
|
var import_context = require("@dxos/context");
|
|
@@ -43,14 +56,22 @@ var import_log = require("@dxos/log");
|
|
|
43
56
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
44
57
|
var import_invariant = require("@dxos/invariant");
|
|
45
58
|
var import_proto = require("@dxos/protocols/proto");
|
|
46
|
-
var
|
|
47
|
-
var import_invariant2 = require("@dxos/invariant");
|
|
48
|
-
var import_keyring = require("@dxos/keyring");
|
|
49
|
-
var import_keys = require("@dxos/keys");
|
|
59
|
+
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
50
60
|
var import_async2 = require("@dxos/async");
|
|
51
61
|
var import_context2 = require("@dxos/context");
|
|
62
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
52
63
|
var import_log2 = require("@dxos/log");
|
|
53
64
|
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");
|
|
54
75
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
|
|
55
76
|
var handleAuthChallenge = async (failedResponse, identity) => {
|
|
56
77
|
(0, import_invariant.invariant)(failedResponse.status === 401, void 0, {
|
|
@@ -87,6 +108,251 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
87
108
|
});
|
|
88
109
|
return import_proto.schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
89
110
|
};
|
|
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);
|
|
90
356
|
var EdgeConnectionClosedError = class extends Error {
|
|
91
357
|
constructor() {
|
|
92
358
|
super("Edge connection closed.");
|
|
@@ -103,13 +369,13 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
103
369
|
url.protocol = protocol2 + (isSecure ? "s" : "");
|
|
104
370
|
return url.toString();
|
|
105
371
|
};
|
|
106
|
-
function
|
|
372
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
107
373
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
108
374
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
109
375
|
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;
|
|
110
376
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
111
377
|
}
|
|
112
|
-
var
|
|
378
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
113
379
|
var DEFAULT_TIMEOUT = 1e4;
|
|
114
380
|
var EdgeClient = class extends import_context.Resource {
|
|
115
381
|
constructor(_identity, _config) {
|
|
@@ -152,7 +418,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
152
418
|
identity,
|
|
153
419
|
oldIdentity: this._identity
|
|
154
420
|
}, {
|
|
155
|
-
F:
|
|
421
|
+
F: __dxlog_file3,
|
|
156
422
|
L: 99,
|
|
157
423
|
S: this,
|
|
158
424
|
C: (f, a) => f(...a)
|
|
@@ -175,7 +441,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
175
441
|
listener();
|
|
176
442
|
} catch (error) {
|
|
177
443
|
import_log.log.catch(error, void 0, {
|
|
178
|
-
F:
|
|
444
|
+
F: __dxlog_file3,
|
|
179
445
|
L: 121,
|
|
180
446
|
S: this,
|
|
181
447
|
C: (f, a) => f(...a)
|
|
@@ -193,7 +459,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
193
459
|
(0, import_log.log)("opening...", {
|
|
194
460
|
info: this.info
|
|
195
461
|
}, {
|
|
196
|
-
F:
|
|
462
|
+
F: __dxlog_file3,
|
|
197
463
|
L: 133,
|
|
198
464
|
S: this,
|
|
199
465
|
C: (f, a) => f(...a)
|
|
@@ -202,7 +468,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
202
468
|
import_log.log.warn("Error while opening connection", {
|
|
203
469
|
err
|
|
204
470
|
}, {
|
|
205
|
-
F:
|
|
471
|
+
F: __dxlog_file3,
|
|
206
472
|
L: 135,
|
|
207
473
|
S: this,
|
|
208
474
|
C: (f, a) => f(...a)
|
|
@@ -216,7 +482,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
216
482
|
(0, import_log.log)("closing...", {
|
|
217
483
|
peerKey: this._identity.peerKey
|
|
218
484
|
}, {
|
|
219
|
-
F:
|
|
485
|
+
F: __dxlog_file3,
|
|
220
486
|
L: 143,
|
|
221
487
|
S: this,
|
|
222
488
|
C: (f, a) => f(...a)
|
|
@@ -233,7 +499,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
233
499
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
234
500
|
if (this._identity !== identity) {
|
|
235
501
|
(0, import_log.log)("identity changed during auth header request", void 0, {
|
|
236
|
-
F:
|
|
502
|
+
F: __dxlog_file3,
|
|
237
503
|
L: 157,
|
|
238
504
|
S: this,
|
|
239
505
|
C: (f, a) => f(...a)
|
|
@@ -246,12 +512,12 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
246
512
|
url: url.toString(),
|
|
247
513
|
protocolHeader
|
|
248
514
|
}, {
|
|
249
|
-
F:
|
|
515
|
+
F: __dxlog_file3,
|
|
250
516
|
L: 163,
|
|
251
517
|
S: this,
|
|
252
518
|
C: (f, a) => f(...a)
|
|
253
519
|
});
|
|
254
|
-
const connection = new
|
|
520
|
+
const connection = new EdgeWsConnection(identity, {
|
|
255
521
|
url,
|
|
256
522
|
protocolHeader
|
|
257
523
|
}, {
|
|
@@ -261,7 +527,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
261
527
|
this._notifyReconnected();
|
|
262
528
|
} else {
|
|
263
529
|
import_log.log.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
264
|
-
F:
|
|
530
|
+
F: __dxlog_file3,
|
|
265
531
|
L: 173,
|
|
266
532
|
S: this,
|
|
267
533
|
C: (f, a) => f(...a)
|
|
@@ -274,7 +540,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
274
540
|
void this._persistentLifecycle.scheduleRestart();
|
|
275
541
|
} else {
|
|
276
542
|
import_log.log.verbose("restart requested by inactive connection", void 0, {
|
|
277
|
-
F:
|
|
543
|
+
F: __dxlog_file3,
|
|
278
544
|
L: 181,
|
|
279
545
|
S: this,
|
|
280
546
|
C: (f, a) => f(...a)
|
|
@@ -290,7 +556,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
290
556
|
from: message.source,
|
|
291
557
|
type: message.payload?.typeUrl
|
|
292
558
|
}, {
|
|
293
|
-
F:
|
|
559
|
+
F: __dxlog_file3,
|
|
294
560
|
L: 189,
|
|
295
561
|
S: this,
|
|
296
562
|
C: (f, a) => f(...a)
|
|
@@ -327,7 +593,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
327
593
|
import_log.log.error("ws reconnect listener failed", {
|
|
328
594
|
err
|
|
329
595
|
}, {
|
|
330
|
-
F:
|
|
596
|
+
F: __dxlog_file3,
|
|
331
597
|
L: 225,
|
|
332
598
|
S: this,
|
|
333
599
|
C: (f, a) => f(...a)
|
|
@@ -342,9 +608,9 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
342
608
|
} catch (err) {
|
|
343
609
|
import_log.log.error("ws incoming message processing failed", {
|
|
344
610
|
err,
|
|
345
|
-
payload:
|
|
611
|
+
payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
|
|
346
612
|
}, {
|
|
347
|
-
F:
|
|
613
|
+
F: __dxlog_file3,
|
|
348
614
|
L: 235,
|
|
349
615
|
S: this,
|
|
350
616
|
C: (f, a) => f(...a)
|
|
@@ -359,7 +625,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
359
625
|
async send(message) {
|
|
360
626
|
if (this._ready.state !== import_async.TriggerState.RESOLVED) {
|
|
361
627
|
(0, import_log.log)("waiting for websocket to become ready", void 0, {
|
|
362
|
-
F:
|
|
628
|
+
F: __dxlog_file3,
|
|
363
629
|
L: 246,
|
|
364
630
|
S: this,
|
|
365
631
|
C: (f, a) => f(...a)
|
|
@@ -389,7 +655,7 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
389
655
|
status: response.status,
|
|
390
656
|
statusText: response.statusText
|
|
391
657
|
}, {
|
|
392
|
-
F:
|
|
658
|
+
F: __dxlog_file3,
|
|
393
659
|
L: 271,
|
|
394
660
|
S: this,
|
|
395
661
|
C: (f, a) => f(...a)
|
|
@@ -398,14 +664,14 @@ var EdgeClient = class extends import_context.Resource {
|
|
|
398
664
|
}
|
|
399
665
|
}
|
|
400
666
|
};
|
|
401
|
-
|
|
667
|
+
_ts_decorate2([
|
|
402
668
|
import_log.logInfo
|
|
403
669
|
], EdgeClient.prototype, "info", null);
|
|
404
670
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
405
671
|
const encodedToken = Buffer.from(encodedPresentation).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
406
672
|
return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
|
|
407
673
|
};
|
|
408
|
-
var
|
|
674
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
409
675
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
410
676
|
return {
|
|
411
677
|
identityKey: key.toHex(),
|
|
@@ -449,8 +715,8 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
449
715
|
identityKey: identityKey.toHex(),
|
|
450
716
|
peerKey: peerKey.toHex(),
|
|
451
717
|
presentCredentials: async ({ challenge }) => {
|
|
452
|
-
(0,
|
|
453
|
-
F:
|
|
718
|
+
(0, import_invariant3.invariant)(chain, void 0, {
|
|
719
|
+
F: __dxlog_file4,
|
|
454
720
|
L: 75,
|
|
455
721
|
S: void 0,
|
|
456
722
|
A: [
|
|
@@ -510,17 +776,17 @@ var createStubEdgeIdentity = () => {
|
|
|
510
776
|
}
|
|
511
777
|
};
|
|
512
778
|
};
|
|
513
|
-
var
|
|
779
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
514
780
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
515
781
|
var DEFAULT_RETRY_JITTER = 500;
|
|
516
782
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
517
783
|
var EdgeHttpClient = class {
|
|
518
784
|
constructor(baseUrl) {
|
|
519
785
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
520
|
-
(0,
|
|
786
|
+
(0, import_log3.log)("created", {
|
|
521
787
|
url: this._baseUrl
|
|
522
788
|
}, {
|
|
523
|
-
F:
|
|
789
|
+
F: __dxlog_file5,
|
|
524
790
|
L: 53,
|
|
525
791
|
S: this,
|
|
526
792
|
C: (f, a) => f(...a)
|
|
@@ -652,8 +918,8 @@ var EdgeHttpClient = class {
|
|
|
652
918
|
});
|
|
653
919
|
}
|
|
654
920
|
async _call(path, args) {
|
|
655
|
-
const requestContext = args.context ?? new
|
|
656
|
-
F:
|
|
921
|
+
const requestContext = args.context ?? new import_context3.Context(void 0, {
|
|
922
|
+
F: __dxlog_file5,
|
|
657
923
|
L: 192
|
|
658
924
|
});
|
|
659
925
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -665,12 +931,12 @@ var EdgeHttpClient = class {
|
|
|
665
931
|
}
|
|
666
932
|
url += `?${queryParams.toString()}`;
|
|
667
933
|
}
|
|
668
|
-
(0,
|
|
934
|
+
(0, import_log3.log)("call", {
|
|
669
935
|
method: args.method,
|
|
670
936
|
path,
|
|
671
937
|
request: args.body
|
|
672
938
|
}, {
|
|
673
|
-
F:
|
|
939
|
+
F: __dxlog_file5,
|
|
674
940
|
L: 204,
|
|
675
941
|
S: this,
|
|
676
942
|
C: (f, a) => f(...a)
|
|
@@ -689,36 +955,36 @@ var EdgeHttpClient = class {
|
|
|
689
955
|
if (body.success) {
|
|
690
956
|
return body.data;
|
|
691
957
|
}
|
|
692
|
-
(0,
|
|
958
|
+
(0, import_log3.log)("unsuccessful edge response", {
|
|
693
959
|
path,
|
|
694
960
|
body
|
|
695
961
|
}, {
|
|
696
|
-
F:
|
|
962
|
+
F: __dxlog_file5,
|
|
697
963
|
L: 223,
|
|
698
964
|
S: this,
|
|
699
965
|
C: (f, a) => f(...a)
|
|
700
966
|
});
|
|
701
967
|
if (body.errorData?.type === "auth_challenge" && typeof body.errorData?.challenge === "string") {
|
|
702
|
-
processingError = new
|
|
968
|
+
processingError = new import_protocols2.EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
|
|
703
969
|
} else {
|
|
704
|
-
processingError =
|
|
970
|
+
processingError = import_protocols2.EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
705
971
|
}
|
|
706
972
|
} else if (response.status === 401 && !handledAuth) {
|
|
707
973
|
authHeader = await this._handleUnauthorized(response);
|
|
708
974
|
handledAuth = true;
|
|
709
975
|
continue;
|
|
710
976
|
} else {
|
|
711
|
-
processingError =
|
|
977
|
+
processingError = import_protocols2.EdgeCallFailedError.fromHttpFailure(response);
|
|
712
978
|
}
|
|
713
979
|
} catch (error) {
|
|
714
|
-
processingError =
|
|
980
|
+
processingError = import_protocols2.EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
715
981
|
}
|
|
716
982
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
717
|
-
(0,
|
|
983
|
+
(0, import_log3.log)("retrying edge request", {
|
|
718
984
|
path,
|
|
719
985
|
processingError
|
|
720
986
|
}, {
|
|
721
|
-
F:
|
|
987
|
+
F: __dxlog_file5,
|
|
722
988
|
L: 242,
|
|
723
989
|
S: this,
|
|
724
990
|
C: (f, a) => f(...a)
|
|
@@ -730,18 +996,18 @@ var EdgeHttpClient = class {
|
|
|
730
996
|
}
|
|
731
997
|
async _handleUnauthorized(response) {
|
|
732
998
|
if (!this._edgeIdentity) {
|
|
733
|
-
|
|
734
|
-
F:
|
|
999
|
+
import_log3.log.warn("edge unauthorized response received before identity was set", void 0, {
|
|
1000
|
+
F: __dxlog_file5,
|
|
735
1001
|
L: 251,
|
|
736
1002
|
S: this,
|
|
737
1003
|
C: (f, a) => f(...a)
|
|
738
1004
|
});
|
|
739
|
-
throw
|
|
1005
|
+
throw import_protocols2.EdgeCallFailedError.fromHttpFailure(response);
|
|
740
1006
|
}
|
|
741
1007
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
742
1008
|
this._authHeader = encodeAuthHeader(challenge);
|
|
743
|
-
(0,
|
|
744
|
-
F:
|
|
1009
|
+
(0, import_log3.log)("auth header updated", void 0, {
|
|
1010
|
+
F: __dxlog_file5,
|
|
745
1011
|
L: 256,
|
|
746
1012
|
S: this,
|
|
747
1013
|
C: (f, a) => f(...a)
|
|
@@ -762,10 +1028,10 @@ var createRetryHandler = (args) => {
|
|
|
762
1028
|
return false;
|
|
763
1029
|
}
|
|
764
1030
|
if (retryAfter) {
|
|
765
|
-
await (0,
|
|
1031
|
+
await (0, import_async3.sleep)(retryAfter);
|
|
766
1032
|
} else {
|
|
767
1033
|
const timeout = baseTimeout + Math.random() * jitter;
|
|
768
|
-
await (0,
|
|
1034
|
+
await (0, import_async3.sleep)(timeout);
|
|
769
1035
|
}
|
|
770
1036
|
return true;
|
|
771
1037
|
};
|
|
@@ -785,11 +1051,14 @@ var encodeAuthHeader = (challenge) => {
|
|
|
785
1051
|
};
|
|
786
1052
|
// Annotate the CommonJS export names for ESM import in node:
|
|
787
1053
|
0 && (module.exports = {
|
|
1054
|
+
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1055
|
+
CLOUDFLARE_RPC_MAX_BYTES,
|
|
788
1056
|
EdgeClient,
|
|
789
1057
|
EdgeConnectionClosedError,
|
|
790
1058
|
EdgeHttpClient,
|
|
791
1059
|
EdgeIdentityChangedError,
|
|
792
1060
|
Protocol,
|
|
1061
|
+
WebSocketMuxer,
|
|
793
1062
|
createChainEdgeIdentity,
|
|
794
1063
|
createDeviceEdgeIdentity,
|
|
795
1064
|
createEphemeralEdgeIdentity,
|