@dxos/edge-client 0.8.4-main.c1de068 → 0.8.4-main.c4373fc

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.
Files changed (39) hide show
  1. package/dist/lib/browser/{chunk-LMP5TVOP.mjs → chunk-IKP53CBQ.mjs} +44 -11
  2. package/dist/lib/browser/{chunk-LMP5TVOP.mjs.map → chunk-IKP53CBQ.mjs.map} +3 -3
  3. package/dist/lib/browser/edge-ws-muxer.mjs +1 -1
  4. package/dist/lib/browser/index.mjs +413 -259
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +1 -1
  8. package/dist/lib/browser/testing/index.mjs.map +2 -2
  9. package/dist/lib/node-esm/{chunk-X7J46ISZ.mjs → chunk-DR5YNW5K.mjs} +44 -11
  10. package/dist/lib/node-esm/{chunk-X7J46ISZ.mjs.map → chunk-DR5YNW5K.mjs.map} +3 -3
  11. package/dist/lib/node-esm/edge-ws-muxer.mjs +1 -1
  12. package/dist/lib/node-esm/index.mjs +413 -259
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs +1 -1
  16. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  17. package/dist/types/src/edge-client.d.ts +15 -15
  18. package/dist/types/src/edge-client.d.ts.map +1 -1
  19. package/dist/types/src/edge-http-client.d.ts +21 -2
  20. package/dist/types/src/edge-http-client.d.ts.map +1 -1
  21. package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
  22. package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
  23. package/dist/types/src/http-client.d.ts +10 -7
  24. package/dist/types/src/http-client.d.ts.map +1 -1
  25. package/dist/types/src/index.d.ts +4 -3
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/testing/test-utils.d.ts +1 -1
  28. package/dist/types/src/testing/test-utils.d.ts.map +1 -1
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +18 -15
  31. package/src/edge-client.ts +40 -40
  32. package/src/edge-http-client.ts +158 -23
  33. package/src/edge-ws-connection.ts +2 -2
  34. package/src/edge-ws-muxer.ts +1 -1
  35. package/src/http-client.test.ts +8 -5
  36. package/src/http-client.ts +13 -7
  37. package/src/index.ts +4 -3
  38. package/src/testing/test-utils.ts +1 -1
  39. package/src/websocket.test.ts +1 -1
@@ -6,24 +6,135 @@ import {
6
6
  getTypename,
7
7
  protocol,
8
8
  toUint8Array
9
- } from "./chunk-LMP5TVOP.mjs";
9
+ } from "./chunk-IKP53CBQ.mjs";
10
10
 
11
11
  // src/index.ts
12
12
  export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
13
13
 
14
+ // src/auth.ts
15
+ import { createCredential, signPresentation } from "@dxos/credentials";
16
+ import { invariant } from "@dxos/invariant";
17
+ import { Keyring } from "@dxos/keyring";
18
+ import { PublicKey } from "@dxos/keys";
19
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
20
+ var createDeviceEdgeIdentity = async (signer, key) => {
21
+ return {
22
+ identityKey: key.toHex(),
23
+ peerKey: key.toHex(),
24
+ presentCredentials: async ({ challenge }) => {
25
+ return signPresentation({
26
+ presentation: {
27
+ credentials: [
28
+ // Verifier requires at least one credential in the presentation to establish the subject.
29
+ await createCredential({
30
+ assertion: {
31
+ "@type": "dxos.halo.credentials.Auth"
32
+ },
33
+ issuer: key,
34
+ subject: key,
35
+ signer
36
+ })
37
+ ]
38
+ },
39
+ signer,
40
+ signerKey: key,
41
+ nonce: challenge
42
+ });
43
+ }
44
+ };
45
+ };
46
+ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, credentials) => {
47
+ const credentialsToSign = credentials.length > 0 ? credentials : [
48
+ await createCredential({
49
+ assertion: {
50
+ "@type": "dxos.halo.credentials.Auth"
51
+ },
52
+ issuer: identityKey,
53
+ subject: identityKey,
54
+ signer,
55
+ chain,
56
+ signingKey: peerKey
57
+ })
58
+ ];
59
+ return {
60
+ identityKey: identityKey.toHex(),
61
+ peerKey: peerKey.toHex(),
62
+ presentCredentials: async ({ challenge }) => {
63
+ invariant(chain, void 0, {
64
+ F: __dxlog_file,
65
+ L: 75,
66
+ S: void 0,
67
+ A: [
68
+ "chain",
69
+ ""
70
+ ]
71
+ });
72
+ return signPresentation({
73
+ presentation: {
74
+ credentials: credentialsToSign
75
+ },
76
+ signer,
77
+ nonce: challenge,
78
+ signerKey: peerKey,
79
+ chain
80
+ });
81
+ }
82
+ };
83
+ };
84
+ var createEphemeralEdgeIdentity = async () => {
85
+ const keyring = new Keyring();
86
+ const key = await keyring.createKey();
87
+ return createDeviceEdgeIdentity(keyring, key);
88
+ };
89
+ var createTestHaloEdgeIdentity = async (signer, identityKey, deviceKey) => {
90
+ const deviceAdmission = await createCredential({
91
+ assertion: {
92
+ "@type": "dxos.halo.credentials.AuthorizedDevice",
93
+ deviceKey,
94
+ identityKey
95
+ },
96
+ issuer: identityKey,
97
+ subject: deviceKey,
98
+ signer
99
+ });
100
+ return createChainEdgeIdentity(signer, identityKey, deviceKey, {
101
+ credential: deviceAdmission
102
+ }, [
103
+ await createCredential({
104
+ assertion: {
105
+ "@type": "dxos.halo.credentials.Auth"
106
+ },
107
+ issuer: identityKey,
108
+ subject: identityKey,
109
+ signer
110
+ })
111
+ ]);
112
+ };
113
+ var createStubEdgeIdentity = () => {
114
+ const identityKey = PublicKey.random();
115
+ const deviceKey = PublicKey.random();
116
+ return {
117
+ identityKey: identityKey.toHex(),
118
+ peerKey: deviceKey.toHex(),
119
+ presentCredentials: async () => {
120
+ throw new Error("Stub identity does not support authentication.");
121
+ }
122
+ };
123
+ };
124
+
14
125
  // src/edge-client.ts
15
- import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
126
+ import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask } from "@dxos/async";
16
127
  import { Resource as Resource2 } from "@dxos/context";
17
128
  import { log as log2, logInfo as logInfo2 } from "@dxos/log";
18
129
  import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
19
130
 
20
131
  // src/edge-identity.ts
21
- import { invariant } from "@dxos/invariant";
132
+ import { invariant as invariant2 } from "@dxos/invariant";
22
133
  import { schema } from "@dxos/protocols/proto";
23
- var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
134
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
24
135
  var handleAuthChallenge = async (failedResponse, identity) => {
25
- invariant(failedResponse.status === 401, void 0, {
26
- F: __dxlog_file,
136
+ invariant2(failedResponse.status === 401, void 0, {
137
+ F: __dxlog_file2,
27
138
  L: 21,
28
139
  S: void 0,
29
140
  A: [
@@ -32,8 +143,8 @@ var handleAuthChallenge = async (failedResponse, identity) => {
32
143
  ]
33
144
  });
34
145
  const headerValue = failedResponse.headers.get("Www-Authenticate");
35
- invariant(headerValue?.startsWith("VerifiablePresentation challenge="), void 0, {
36
- F: __dxlog_file,
146
+ invariant2(headerValue?.startsWith("VerifiablePresentation challenge="), void 0, {
147
+ F: __dxlog_file2,
37
148
  L: 24,
38
149
  S: void 0,
39
150
  A: [
@@ -42,8 +153,8 @@ var handleAuthChallenge = async (failedResponse, identity) => {
42
153
  ]
43
154
  });
44
155
  const challenge = headerValue?.slice("VerifiablePresentation challenge=".length);
45
- invariant(challenge, void 0, {
46
- F: __dxlog_file,
156
+ invariant2(challenge, void 0, {
157
+ F: __dxlog_file2,
47
158
  L: 27,
48
159
  S: void 0,
49
160
  A: [
@@ -61,24 +172,34 @@ var handleAuthChallenge = async (failedResponse, identity) => {
61
172
  import WebSocket from "isomorphic-ws";
62
173
  import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
63
174
  import { Context, Resource } from "@dxos/context";
64
- import { invariant as invariant2 } from "@dxos/invariant";
175
+ import { invariant as invariant3 } from "@dxos/invariant";
65
176
  import { log, logInfo } from "@dxos/log";
66
177
  import { EdgeWebsocketProtocol } from "@dxos/protocols";
67
178
  import { buf } from "@dxos/protocols/buf";
68
179
  import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
180
+ function _define_property(obj, key, value) {
181
+ if (key in obj) {
182
+ Object.defineProperty(obj, key, {
183
+ value,
184
+ enumerable: true,
185
+ configurable: true,
186
+ writable: true
187
+ });
188
+ } else {
189
+ obj[key] = value;
190
+ }
191
+ return obj;
192
+ }
69
193
  function _ts_decorate(decorators, target, key, desc) {
70
194
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
71
195
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
72
196
  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;
73
197
  return c > 3 && r && Object.defineProperty(target, key, r), r;
74
198
  }
75
- var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
199
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
76
200
  var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
77
201
  var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
78
202
  var EdgeWsConnection = class extends Resource {
79
- constructor(_identity, _connectionInfo, _callbacks) {
80
- super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now();
81
- }
82
203
  get info() {
83
204
  return {
84
205
  open: this.isOpen,
@@ -87,8 +208,8 @@ var EdgeWsConnection = class extends Resource {
87
208
  };
88
209
  }
89
210
  send(message) {
90
- invariant2(this._ws, void 0, {
91
- F: __dxlog_file2,
211
+ invariant3(this._ws, void 0, {
212
+ F: __dxlog_file3,
92
213
  L: 53,
93
214
  S: this,
94
215
  A: [
@@ -96,8 +217,8 @@ var EdgeWsConnection = class extends Resource {
96
217
  ""
97
218
  ]
98
219
  });
99
- invariant2(this._wsMuxer, void 0, {
100
- F: __dxlog_file2,
220
+ invariant3(this._wsMuxer, void 0, {
221
+ F: __dxlog_file3,
101
222
  L: 54,
102
223
  S: this,
103
224
  A: [
@@ -109,7 +230,7 @@ var EdgeWsConnection = class extends Resource {
109
230
  peerKey: this._identity.peerKey,
110
231
  payload: protocol.getPayloadType(message)
111
232
  }, {
112
- F: __dxlog_file2,
233
+ F: __dxlog_file3,
113
234
  L: 55,
114
235
  S: this,
115
236
  C: (f, a) => f(...a)
@@ -122,7 +243,7 @@ var EdgeWsConnection = class extends Resource {
122
243
  serviceId: message.serviceId,
123
244
  payload: protocol.getPayloadType(message)
124
245
  }, {
125
- F: __dxlog_file2,
246
+ F: __dxlog_file3,
126
247
  L: 59,
127
248
  S: this,
128
249
  C: (f, a) => f(...a)
@@ -132,7 +253,7 @@ var EdgeWsConnection = class extends Resource {
132
253
  this._ws.send(binary);
133
254
  } else {
134
255
  this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
135
- F: __dxlog_file2,
256
+ F: __dxlog_file3,
136
257
  L: 68,
137
258
  S: this,
138
259
  C: (f, a) => f(...a)
@@ -154,7 +275,7 @@ var EdgeWsConnection = class extends Resource {
154
275
  this._ws.onopen = () => {
155
276
  if (this.isOpen) {
156
277
  log("connected", void 0, {
157
- F: __dxlog_file2,
278
+ F: __dxlog_file3,
158
279
  L: 85,
159
280
  S: this,
160
281
  C: (f, a) => f(...a)
@@ -165,7 +286,7 @@ var EdgeWsConnection = class extends Resource {
165
286
  log.verbose("connected after becoming inactive", {
166
287
  currentIdentity: this._identity
167
288
  }, {
168
- F: __dxlog_file2,
289
+ F: __dxlog_file3,
169
290
  L: 89,
170
291
  S: this,
171
292
  C: (f, a) => f(...a)
@@ -178,7 +299,7 @@ var EdgeWsConnection = class extends Resource {
178
299
  code: event.code,
179
300
  reason: event.reason
180
301
  }, {
181
- F: __dxlog_file2,
302
+ F: __dxlog_file3,
182
303
  L: 94,
183
304
  S: this,
184
305
  C: (f, a) => f(...a)
@@ -193,7 +314,7 @@ var EdgeWsConnection = class extends Resource {
193
314
  error: event.error,
194
315
  info: event.message
195
316
  }, {
196
- F: __dxlog_file2,
317
+ F: __dxlog_file3,
197
318
  L: 101,
198
319
  S: this,
199
320
  C: (f, a) => f(...a)
@@ -203,7 +324,7 @@ var EdgeWsConnection = class extends Resource {
203
324
  log.verbose("error ignored on closed connection", {
204
325
  error: event.error
205
326
  }, {
206
- F: __dxlog_file2,
327
+ F: __dxlog_file3,
207
328
  L: 104,
208
329
  S: this,
209
330
  C: (f, a) => f(...a)
@@ -215,7 +336,7 @@ var EdgeWsConnection = class extends Resource {
215
336
  log.verbose("message ignored on closed connection", {
216
337
  event: event.type
217
338
  }, {
218
- F: __dxlog_file2,
339
+ F: __dxlog_file3,
219
340
  L: 112,
220
341
  S: this,
221
342
  C: (f, a) => f(...a)
@@ -237,7 +358,7 @@ var EdgeWsConnection = class extends Resource {
237
358
  from: message.source,
238
359
  payload: protocol.getPayloadType(message)
239
360
  }, {
240
- F: __dxlog_file2,
361
+ F: __dxlog_file3,
241
362
  L: 130,
242
363
  S: this,
243
364
  C: (f, a) => f(...a)
@@ -258,10 +379,10 @@ var EdgeWsConnection = class extends Resource {
258
379
  if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
259
380
  return;
260
381
  }
261
- log.warn("Error closing websocket", {
382
+ log.warn("error closing websocket", {
262
383
  err
263
384
  }, {
264
- F: __dxlog_file2,
385
+ F: __dxlog_file3,
265
386
  L: 148,
266
387
  S: this,
267
388
  C: (f, a) => f(...a)
@@ -269,8 +390,8 @@ var EdgeWsConnection = class extends Resource {
269
390
  }
270
391
  }
271
392
  _scheduleHeartbeats() {
272
- invariant2(this._ws, void 0, {
273
- F: __dxlog_file2,
393
+ invariant3(this._ws, void 0, {
394
+ F: __dxlog_file3,
274
395
  L: 153,
275
396
  S: this,
276
397
  A: [
@@ -290,7 +411,7 @@ var EdgeWsConnection = class extends Resource {
290
411
  }
291
412
  void this._inactivityTimeoutCtx?.dispose();
292
413
  this._inactivityTimeoutCtx = new Context(void 0, {
293
- F: __dxlog_file2,
414
+ F: __dxlog_file3,
294
415
  L: 172
295
416
  });
296
417
  scheduleTask(this._inactivityTimeoutCtx, () => {
@@ -299,7 +420,7 @@ var EdgeWsConnection = class extends Resource {
299
420
  log.warn("restart due to inactivity timeout", {
300
421
  lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
301
422
  }, {
302
- F: __dxlog_file2,
423
+ F: __dxlog_file3,
303
424
  L: 178,
304
425
  S: this,
305
426
  C: (f, a) => f(...a)
@@ -311,6 +432,9 @@ var EdgeWsConnection = class extends Resource {
311
432
  }
312
433
  }, SIGNAL_KEEPALIVE_TIMEOUT);
313
434
  }
435
+ constructor(_identity, _connectionInfo, _callbacks) {
436
+ super(), _define_property(this, "_identity", void 0), _define_property(this, "_connectionInfo", void 0), _define_property(this, "_callbacks", void 0), _define_property(this, "_inactivityTimeoutCtx", void 0), _define_property(this, "_ws", void 0), _define_property(this, "_wsMuxer", void 0), _define_property(this, "_lastReceivedMessageTimestamp", void 0), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now();
437
+ }
314
438
  };
315
439
  _ts_decorate([
316
440
  logInfo
@@ -337,23 +461,28 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
337
461
  };
338
462
 
339
463
  // src/edge-client.ts
464
+ function _define_property2(obj, key, value) {
465
+ if (key in obj) {
466
+ Object.defineProperty(obj, key, {
467
+ value,
468
+ enumerable: true,
469
+ configurable: true,
470
+ writable: true
471
+ });
472
+ } else {
473
+ obj[key] = value;
474
+ }
475
+ return obj;
476
+ }
340
477
  function _ts_decorate2(decorators, target, key, desc) {
341
478
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
342
479
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
343
480
  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;
344
481
  return c > 3 && r && Object.defineProperty(target, key, r), r;
345
482
  }
346
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
483
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
347
484
  var DEFAULT_TIMEOUT = 1e4;
348
485
  var EdgeClient = class extends Resource2 {
349
- constructor(_identity, _config) {
350
- super(), this._identity = _identity, this._config = _config, this.statusChanged = new Event(), this._persistentLifecycle = new PersistentLifecycle({
351
- start: async () => this._connect(),
352
- stop: async (state) => this._disconnect(state)
353
- }), this._messageListeners = /* @__PURE__ */ new Set(), this._reconnectListeners = /* @__PURE__ */ new Set(), this._currentConnection = void 0, this._ready = new Trigger(), this._isActive = (connection) => connection === this._currentConnection;
354
- this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "ws");
355
- this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "http");
356
- }
357
486
  get info() {
358
487
  return {
359
488
  open: this.isOpen,
@@ -377,7 +506,7 @@ var EdgeClient = class extends Resource2 {
377
506
  identity,
378
507
  oldIdentity: this._identity
379
508
  }, {
380
- F: __dxlog_file3,
509
+ F: __dxlog_file4,
381
510
  L: 99,
382
511
  S: this,
383
512
  C: (f, a) => f(...a)
@@ -387,6 +516,30 @@ var EdgeClient = class extends Resource2 {
387
516
  void this._persistentLifecycle.scheduleRestart();
388
517
  }
389
518
  }
519
+ /**
520
+ * Send message.
521
+ * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
522
+ */
523
+ async send(message) {
524
+ if (this._ready.state !== TriggerState.RESOLVED) {
525
+ log2("waiting for websocket", void 0, {
526
+ F: __dxlog_file4,
527
+ L: 112,
528
+ S: this,
529
+ C: (f, a) => f(...a)
530
+ });
531
+ await this._ready.wait({
532
+ timeout: this._config.timeout ?? DEFAULT_TIMEOUT
533
+ });
534
+ }
535
+ if (!this._currentConnection) {
536
+ throw new EdgeConnectionClosedError();
537
+ }
538
+ if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
539
+ throw new EdgeIdentityChangedError();
540
+ }
541
+ this._currentConnection.send(message);
542
+ }
390
543
  onMessage(listener) {
391
544
  this._messageListeners.add(listener);
392
545
  return () => this._messageListeners.delete(listener);
@@ -400,8 +553,8 @@ var EdgeClient = class extends Resource2 {
400
553
  listener();
401
554
  } catch (error) {
402
555
  log2.catch(error, void 0, {
403
- F: __dxlog_file3,
404
- L: 121,
556
+ F: __dxlog_file4,
557
+ L: 145,
405
558
  S: this,
406
559
  C: (f, a) => f(...a)
407
560
  });
@@ -418,8 +571,8 @@ var EdgeClient = class extends Resource2 {
418
571
  log2("opening...", {
419
572
  info: this.info
420
573
  }, {
421
- F: __dxlog_file3,
422
- L: 133,
574
+ F: __dxlog_file4,
575
+ L: 158,
423
576
  S: this,
424
577
  C: (f, a) => f(...a)
425
578
  });
@@ -427,8 +580,8 @@ var EdgeClient = class extends Resource2 {
427
580
  log2.warn("Error while opening connection", {
428
581
  err
429
582
  }, {
430
- F: __dxlog_file3,
431
- L: 135,
583
+ F: __dxlog_file4,
584
+ L: 160,
432
585
  S: this,
433
586
  C: (f, a) => f(...a)
434
587
  });
@@ -441,8 +594,8 @@ var EdgeClient = class extends Resource2 {
441
594
  log2("closing...", {
442
595
  peerKey: this._identity.peerKey
443
596
  }, {
444
- F: __dxlog_file3,
445
- L: 143,
597
+ F: __dxlog_file4,
598
+ L: 168,
446
599
  S: this,
447
600
  C: (f, a) => f(...a)
448
601
  });
@@ -458,8 +611,8 @@ var EdgeClient = class extends Resource2 {
458
611
  const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
459
612
  if (this._identity !== identity) {
460
613
  log2("identity changed during auth header request", void 0, {
461
- F: __dxlog_file3,
462
- L: 157,
614
+ F: __dxlog_file4,
615
+ L: 182,
463
616
  S: this,
464
617
  C: (f, a) => f(...a)
465
618
  });
@@ -471,8 +624,8 @@ var EdgeClient = class extends Resource2 {
471
624
  url: url.toString(),
472
625
  protocolHeader
473
626
  }, {
474
- F: __dxlog_file3,
475
- L: 163,
627
+ F: __dxlog_file4,
628
+ L: 188,
476
629
  S: this,
477
630
  C: (f, a) => f(...a)
478
631
  });
@@ -486,8 +639,8 @@ var EdgeClient = class extends Resource2 {
486
639
  this._notifyReconnected();
487
640
  } else {
488
641
  log2.verbose("connected callback ignored, because connection is not active", void 0, {
489
- F: __dxlog_file3,
490
- L: 173,
642
+ F: __dxlog_file4,
643
+ L: 198,
491
644
  S: this,
492
645
  C: (f, a) => f(...a)
493
646
  });
@@ -499,8 +652,8 @@ var EdgeClient = class extends Resource2 {
499
652
  void this._persistentLifecycle.scheduleRestart();
500
653
  } else {
501
654
  log2.verbose("restart requested by inactive connection", void 0, {
502
- F: __dxlog_file3,
503
- L: 181,
655
+ F: __dxlog_file4,
656
+ L: 206,
504
657
  S: this,
505
658
  C: (f, a) => f(...a)
506
659
  });
@@ -515,8 +668,8 @@ var EdgeClient = class extends Resource2 {
515
668
  from: message.source,
516
669
  type: message.payload?.typeUrl
517
670
  }, {
518
- F: __dxlog_file3,
519
- L: 189,
671
+ F: __dxlog_file4,
672
+ L: 214,
520
673
  S: this,
521
674
  C: (f, a) => f(...a)
522
675
  });
@@ -552,8 +705,8 @@ var EdgeClient = class extends Resource2 {
552
705
  log2.error("ws reconnect listener failed", {
553
706
  err
554
707
  }, {
555
- F: __dxlog_file3,
556
- L: 225,
708
+ F: __dxlog_file4,
709
+ L: 249,
557
710
  S: this,
558
711
  C: (f, a) => f(...a)
559
712
  });
@@ -569,38 +722,14 @@ var EdgeClient = class extends Resource2 {
569
722
  err,
570
723
  payload: protocol.getPayloadType(message)
571
724
  }, {
572
- F: __dxlog_file3,
573
- L: 235,
725
+ F: __dxlog_file4,
726
+ L: 259,
574
727
  S: this,
575
728
  C: (f, a) => f(...a)
576
729
  });
577
730
  }
578
731
  }
579
732
  }
580
- /**
581
- * Send message.
582
- * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
583
- */
584
- async send(message) {
585
- if (this._ready.state !== TriggerState.RESOLVED) {
586
- log2("waiting for websocket to become ready", void 0, {
587
- F: __dxlog_file3,
588
- L: 246,
589
- S: this,
590
- C: (f, a) => f(...a)
591
- });
592
- await this._ready.wait({
593
- timeout: this._config.timeout ?? DEFAULT_TIMEOUT
594
- });
595
- }
596
- if (!this._currentConnection) {
597
- throw new EdgeConnectionClosedError();
598
- }
599
- if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
600
- throw new EdgeIdentityChangedError();
601
- }
602
- this._currentConnection.send(message);
603
- }
604
733
  async _createAuthHeader(path) {
605
734
  const httpUrl = new URL(path, this._baseHttpUrl);
606
735
  httpUrl.protocol = getEdgeUrlWithProtocol(this._baseWsUrl.toString(), "http");
@@ -614,7 +743,7 @@ var EdgeClient = class extends Resource2 {
614
743
  status: response.status,
615
744
  statusText: response.statusText
616
745
  }, {
617
- F: __dxlog_file3,
746
+ F: __dxlog_file4,
618
747
  L: 271,
619
748
  S: this,
620
749
  C: (f, a) => f(...a)
@@ -622,6 +751,14 @@ var EdgeClient = class extends Resource2 {
622
751
  return void 0;
623
752
  }
624
753
  }
754
+ constructor(_identity, _config) {
755
+ super(), _define_property2(this, "_identity", void 0), _define_property2(this, "_config", void 0), _define_property2(this, "statusChanged", void 0), _define_property2(this, "_persistentLifecycle", void 0), _define_property2(this, "_messageListeners", void 0), _define_property2(this, "_reconnectListeners", void 0), _define_property2(this, "_baseWsUrl", void 0), _define_property2(this, "_baseHttpUrl", void 0), _define_property2(this, "_currentConnection", void 0), _define_property2(this, "_ready", void 0), _define_property2(this, "_isActive", void 0), this._identity = _identity, this._config = _config, this.statusChanged = new Event(), this._persistentLifecycle = new PersistentLifecycle({
756
+ start: async () => this._connect(),
757
+ stop: async (state) => this._disconnect(state)
758
+ }), this._messageListeners = /* @__PURE__ */ new Set(), this._reconnectListeners = /* @__PURE__ */ new Set(), this._currentConnection = void 0, this._ready = new Trigger(), this._isActive = (connection) => connection === this._currentConnection;
759
+ this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "ws");
760
+ this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "http");
761
+ }
625
762
  };
626
763
  _ts_decorate2([
627
764
  logInfo2
@@ -631,120 +768,11 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
631
768
  return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
632
769
  };
633
770
 
634
- // src/auth.ts
635
- import { createCredential, signPresentation } from "@dxos/credentials";
636
- import { invariant as invariant3 } from "@dxos/invariant";
637
- import { Keyring } from "@dxos/keyring";
638
- import { PublicKey } from "@dxos/keys";
639
- var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
640
- var createDeviceEdgeIdentity = async (signer, key) => {
641
- return {
642
- identityKey: key.toHex(),
643
- peerKey: key.toHex(),
644
- presentCredentials: async ({ challenge }) => {
645
- return signPresentation({
646
- presentation: {
647
- credentials: [
648
- // Verifier requires at least one credential in the presentation to establish the subject.
649
- await createCredential({
650
- assertion: {
651
- "@type": "dxos.halo.credentials.Auth"
652
- },
653
- issuer: key,
654
- subject: key,
655
- signer
656
- })
657
- ]
658
- },
659
- signer,
660
- signerKey: key,
661
- nonce: challenge
662
- });
663
- }
664
- };
665
- };
666
- var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, credentials) => {
667
- const credentialsToSign = credentials.length > 0 ? credentials : [
668
- await createCredential({
669
- assertion: {
670
- "@type": "dxos.halo.credentials.Auth"
671
- },
672
- issuer: identityKey,
673
- subject: identityKey,
674
- signer,
675
- chain,
676
- signingKey: peerKey
677
- })
678
- ];
679
- return {
680
- identityKey: identityKey.toHex(),
681
- peerKey: peerKey.toHex(),
682
- presentCredentials: async ({ challenge }) => {
683
- invariant3(chain, void 0, {
684
- F: __dxlog_file4,
685
- L: 75,
686
- S: void 0,
687
- A: [
688
- "chain",
689
- ""
690
- ]
691
- });
692
- return signPresentation({
693
- presentation: {
694
- credentials: credentialsToSign
695
- },
696
- signer,
697
- nonce: challenge,
698
- signerKey: peerKey,
699
- chain
700
- });
701
- }
702
- };
703
- };
704
- var createEphemeralEdgeIdentity = async () => {
705
- const keyring = new Keyring();
706
- const key = await keyring.createKey();
707
- return createDeviceEdgeIdentity(keyring, key);
708
- };
709
- var createTestHaloEdgeIdentity = async (signer, identityKey, deviceKey) => {
710
- const deviceAdmission = await createCredential({
711
- assertion: {
712
- "@type": "dxos.halo.credentials.AuthorizedDevice",
713
- deviceKey,
714
- identityKey
715
- },
716
- issuer: identityKey,
717
- subject: deviceKey,
718
- signer
719
- });
720
- return createChainEdgeIdentity(signer, identityKey, deviceKey, {
721
- credential: deviceAdmission
722
- }, [
723
- await createCredential({
724
- assertion: {
725
- "@type": "dxos.halo.credentials.Auth"
726
- },
727
- issuer: identityKey,
728
- subject: identityKey,
729
- signer
730
- })
731
- ]);
732
- };
733
- var createStubEdgeIdentity = () => {
734
- const identityKey = PublicKey.random();
735
- const deviceKey = PublicKey.random();
736
- return {
737
- identityKey: identityKey.toHex(),
738
- peerKey: deviceKey.toHex(),
739
- presentCredentials: async () => {
740
- throw new Error("Stub identity does not support authentication.");
741
- }
742
- };
743
- };
744
-
745
771
  // src/edge-http-client.ts
746
- import { FetchHttpClient, HttpClient } from "@effect/platform";
747
- import { Effect as Effect2, pipe } from "effect";
772
+ import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
773
+ import * as HttpClient from "@effect/platform/HttpClient";
774
+ import * as Effect2 from "effect/Effect";
775
+ import * as Function from "effect/Function";
748
776
  import { sleep } from "@dxos/async";
749
777
  import { Context as Context3 } from "@dxos/context";
750
778
  import { log as log4 } from "@dxos/log";
@@ -752,23 +780,39 @@ import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
752
780
  import { createUrl } from "@dxos/util";
753
781
 
754
782
  // src/http-client.ts
755
- import { Context as Context2, Duration, Effect, Layer, Schedule } from "effect";
783
+ import * as Context2 from "effect/Context";
784
+ import * as Duration from "effect/Duration";
785
+ import * as Effect from "effect/Effect";
786
+ import * as Layer from "effect/Layer";
787
+ import * as Schedule from "effect/Schedule";
756
788
  import { log as log3 } from "@dxos/log";
757
- var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
758
- var HttpConfig = class _HttpConfig extends Context2.Tag("HttpConfig")() {
759
- static {
760
- this.default = Layer.succeed(_HttpConfig, {
761
- timeout: Duration.millis(1e3),
762
- retryTimes: 3,
763
- retryBaseDelay: Duration.millis(1e3)
789
+ function _define_property3(obj, key, value) {
790
+ if (key in obj) {
791
+ Object.defineProperty(obj, key, {
792
+ value,
793
+ enumerable: true,
794
+ configurable: true,
795
+ writable: true
764
796
  });
797
+ } else {
798
+ obj[key] = value;
765
799
  }
800
+ return obj;
801
+ }
802
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
803
+ var _Context_Tag;
804
+ var HttpConfig = class extends (_Context_Tag = Context2.Tag("HttpConfig")()) {
766
805
  };
767
- var withRetry = (effect, { timeout = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
806
+ _define_property3(HttpConfig, "default", Layer.succeed(HttpConfig, {
807
+ timeout: Duration.millis(1e3),
808
+ retryTimes: 3,
809
+ retryBaseDelay: Duration.millis(1e3)
810
+ }));
811
+ var withRetry = (effect, { timeout: timeout2 = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
768
812
  return effect.pipe(Effect.flatMap((res) => (
769
813
  // Treat 500 errors as retryable?
770
814
  res.status === 500 ? Effect.fail(new Error(res.status.toString())) : res.json
771
- )), Effect.timeout(timeout), Effect.retry({
815
+ )), Effect.timeout(timeout2), Effect.retry({
772
816
  schedule: Schedule.exponential(retryBaseDelay).pipe(Schedule.jittered),
773
817
  times: retryTimes
774
818
  }));
@@ -781,7 +825,7 @@ var withLogging = (effect) => effect.pipe(Effect.tap((res) => log3.info("respons
781
825
  status: res.status
782
826
  }, {
783
827
  F: __dxlog_file5,
784
- L: 58,
828
+ L: 64,
785
829
  S: void 0,
786
830
  C: (f, a) => f(...a)
787
831
  })));
@@ -791,22 +835,25 @@ var encodeAuthHeader = (challenge) => {
791
835
  };
792
836
 
793
837
  // src/edge-http-client.ts
838
+ function _define_property4(obj, key, value) {
839
+ if (key in obj) {
840
+ Object.defineProperty(obj, key, {
841
+ value,
842
+ enumerable: true,
843
+ configurable: true,
844
+ writable: true
845
+ });
846
+ } else {
847
+ obj[key] = value;
848
+ }
849
+ return obj;
850
+ }
794
851
  var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
795
852
  var DEFAULT_RETRY_TIMEOUT = 1500;
796
853
  var DEFAULT_RETRY_JITTER = 500;
797
854
  var DEFAULT_MAX_RETRIES_COUNT = 3;
855
+ var WARNING_BODY_SIZE = 10 * 1024 * 1024;
798
856
  var EdgeHttpClient = class {
799
- constructor(baseUrl) {
800
- this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
801
- log4("created", {
802
- url: this._baseUrl
803
- }, {
804
- F: __dxlog_file6,
805
- L: 84,
806
- S: this,
807
- C: (f, a) => f(...a)
808
- });
809
- }
810
857
  get baseUrl() {
811
858
  return this._baseUrl;
812
859
  }
@@ -880,12 +927,6 @@ var EdgeHttpClient = class {
880
927
  //
881
928
  // OAuth and credentials
882
929
  //
883
- async listFunctions(args) {
884
- return this._call(new URL("/functions", this.baseUrl), {
885
- ...args,
886
- method: "GET"
887
- });
888
- }
889
930
  async initiateOAuthFlow(body, args) {
890
931
  return this._call(new URL("/oauth/initiate", this.baseUrl), {
891
932
  ...args,
@@ -940,6 +981,18 @@ var EdgeHttpClient = class {
940
981
  // Functions
941
982
  //
942
983
  async uploadFunction(pathParts, body, args) {
984
+ const formData = new FormData();
985
+ formData.append("name", body.name ?? "");
986
+ formData.append("version", body.version);
987
+ formData.append("ownerPublicKey", body.ownerPublicKey);
988
+ formData.append("entryPoint", body.entryPoint);
989
+ for (const [filename, content] of Object.entries(body.assets)) {
990
+ formData.append("assets", new Blob([
991
+ content
992
+ ], {
993
+ type: getFileMimeType(filename)
994
+ }), filename);
995
+ }
943
996
  const path = [
944
997
  "functions",
945
998
  ...pathParts.functionId ? [
@@ -948,8 +1001,36 @@ var EdgeHttpClient = class {
948
1001
  ].join("/");
949
1002
  return this._call(new URL(path, this.baseUrl), {
950
1003
  ...args,
951
- body,
952
- method: "PUT"
1004
+ body: formData,
1005
+ method: "PUT",
1006
+ json: false
1007
+ });
1008
+ }
1009
+ async listFunctions(args) {
1010
+ return this._call(new URL("/functions", this.baseUrl), {
1011
+ ...args,
1012
+ method: "GET"
1013
+ });
1014
+ }
1015
+ async invokeFunction(params, input, args) {
1016
+ const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
1017
+ if (params.version) {
1018
+ url.searchParams.set("version", params.version);
1019
+ }
1020
+ if (params.spaceId) {
1021
+ url.searchParams.set("spaceId", params.spaceId.toString());
1022
+ }
1023
+ if (params.cpuTimeLimit) {
1024
+ url.searchParams.set("cpuTimeLimit", params.cpuTimeLimit.toString());
1025
+ }
1026
+ if (params.subrequestsLimit) {
1027
+ url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
1028
+ }
1029
+ return this._call(url, {
1030
+ ...args,
1031
+ body: input,
1032
+ method: "POST",
1033
+ rawResponse: true
953
1034
  });
954
1035
  }
955
1036
  //
@@ -963,30 +1044,55 @@ var EdgeHttpClient = class {
963
1044
  });
964
1045
  }
965
1046
  //
1047
+ // Triggers
1048
+ //
1049
+ async getCronTriggers(spaceId) {
1050
+ return this._call(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), {
1051
+ method: "GET"
1052
+ });
1053
+ }
1054
+ //
1055
+ // Import/Export space.
1056
+ //
1057
+ async importBundle(spaceId, body, args) {
1058
+ return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
1059
+ ...args,
1060
+ body,
1061
+ method: "PUT"
1062
+ });
1063
+ }
1064
+ async exportBundle(spaceId, body, args) {
1065
+ return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
1066
+ ...args,
1067
+ body,
1068
+ method: "POST"
1069
+ });
1070
+ }
1071
+ //
966
1072
  // Internal
967
1073
  //
968
1074
  async _fetch(url, args) {
969
- return pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), Effect2.runPromise);
1075
+ return Function.pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), Effect2.runPromise);
970
1076
  }
971
1077
  // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
972
1078
  async _call(url, args) {
973
1079
  const shouldRetry = createRetryHandler(args);
974
1080
  const requestContext = args.context ?? new Context3(void 0, {
975
1081
  F: __dxlog_file6,
976
- L: 293
1082
+ L: 391
977
1083
  });
978
1084
  log4("fetch", {
979
1085
  url,
980
1086
  request: args.body
981
1087
  }, {
982
1088
  F: __dxlog_file6,
983
- L: 294,
1089
+ L: 392,
984
1090
  S: this,
985
1091
  C: (f, a) => f(...a)
986
1092
  });
987
1093
  let handledAuth = false;
988
1094
  while (true) {
989
- let processingError;
1095
+ let processingError = void 0;
990
1096
  let retryAfterHeaderValue = Number.NaN;
991
1097
  try {
992
1098
  const request = createRequest(args, this._authHeader);
@@ -994,6 +1100,12 @@ var EdgeHttpClient = class {
994
1100
  retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
995
1101
  if (response.ok) {
996
1102
  const body = await response.json();
1103
+ if (args.rawResponse) {
1104
+ return body;
1105
+ }
1106
+ if (!("success" in body)) {
1107
+ return body;
1108
+ }
997
1109
  if (body.success) {
998
1110
  return body.data;
999
1111
  }
@@ -1002,13 +1114,13 @@ var EdgeHttpClient = class {
1002
1114
  body
1003
1115
  }, {
1004
1116
  F: __dxlog_file6,
1005
- L: 310,
1117
+ L: 417,
1006
1118
  S: this,
1007
1119
  C: (f, a) => f(...a)
1008
1120
  });
1009
1121
  if (body.errorData?.type === "auth_challenge" && typeof body.errorData?.challenge === "string") {
1010
1122
  processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
1011
- } else {
1123
+ } else if (body.errorData) {
1012
1124
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
1013
1125
  }
1014
1126
  } else if (response.status === 401 && !handledAuth) {
@@ -1016,18 +1128,18 @@ var EdgeHttpClient = class {
1016
1128
  handledAuth = true;
1017
1129
  continue;
1018
1130
  } else {
1019
- processingError = EdgeCallFailedError.fromHttpFailure(response);
1131
+ processingError = await EdgeCallFailedError.fromHttpFailure(response);
1020
1132
  }
1021
1133
  } catch (error) {
1022
1134
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
1023
1135
  }
1024
- if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
1136
+ if (processingError?.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
1025
1137
  log4("retrying edge request", {
1026
1138
  url,
1027
1139
  processingError
1028
1140
  }, {
1029
1141
  F: __dxlog_file6,
1030
- L: 328,
1142
+ L: 435,
1031
1143
  S: this,
1032
1144
  C: (f, a) => f(...a)
1033
1145
  });
@@ -1040,33 +1152,66 @@ var EdgeHttpClient = class {
1040
1152
  if (!this._edgeIdentity) {
1041
1153
  log4.warn("unauthorized response received before identity was set", void 0, {
1042
1154
  F: __dxlog_file6,
1043
- L: 337,
1155
+ L: 444,
1044
1156
  S: this,
1045
1157
  C: (f, a) => f(...a)
1046
1158
  });
1047
- throw EdgeCallFailedError.fromHttpFailure(response);
1159
+ throw await EdgeCallFailedError.fromHttpFailure(response);
1048
1160
  }
1049
1161
  const challenge = await handleAuthChallenge(response, this._edgeIdentity);
1050
1162
  return encodeAuthHeader(challenge);
1051
1163
  }
1164
+ constructor(baseUrl) {
1165
+ _define_property4(this, "_baseUrl", void 0);
1166
+ _define_property4(this, "_edgeIdentity", void 0);
1167
+ _define_property4(this, "_authHeader", void 0);
1168
+ this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
1169
+ log4("created", {
1170
+ url: this._baseUrl
1171
+ }, {
1172
+ F: __dxlog_file6,
1173
+ L: 99,
1174
+ S: this,
1175
+ C: (f, a) => f(...a)
1176
+ });
1177
+ }
1052
1178
  };
1053
- var createRequest = ({ method, body }, authHeader) => {
1179
+ var createRequest = ({ method, body, json = true }, authHeader) => {
1180
+ let requestBody;
1181
+ const headers = {};
1182
+ if (json) {
1183
+ requestBody = body && JSON.stringify(body);
1184
+ headers["Content-Type"] = "application/json";
1185
+ } else {
1186
+ requestBody = body;
1187
+ }
1188
+ if (typeof requestBody === "string" && requestBody.length > WARNING_BODY_SIZE) {
1189
+ log4.warn("Request with large body", {
1190
+ bodySize: requestBody.length
1191
+ }, {
1192
+ F: __dxlog_file6,
1193
+ L: 468,
1194
+ S: void 0,
1195
+ C: (f, a) => f(...a)
1196
+ });
1197
+ }
1198
+ if (authHeader) {
1199
+ headers["Authorization"] = authHeader;
1200
+ }
1054
1201
  return {
1055
1202
  method,
1056
- body: body && JSON.stringify(body),
1057
- headers: authHeader ? {
1058
- Authorization: authHeader
1059
- } : void 0
1203
+ body: requestBody,
1204
+ headers
1060
1205
  };
1061
1206
  };
1062
- var createRetryHandler = ({ retry }) => {
1063
- if (!retry || retry.count < 1) {
1207
+ var createRetryHandler = ({ retry: retry2 }) => {
1208
+ if (!retry2 || retry2.count < 1) {
1064
1209
  return async () => false;
1065
1210
  }
1066
1211
  let retries = 0;
1067
- const maxRetries = retry.count ?? DEFAULT_MAX_RETRIES_COUNT;
1068
- const baseTimeout = retry.timeout ?? DEFAULT_RETRY_TIMEOUT;
1069
- const jitter = retry.jitter ?? DEFAULT_RETRY_JITTER;
1212
+ const maxRetries = retry2.count ?? DEFAULT_MAX_RETRIES_COUNT;
1213
+ const baseTimeout = retry2.timeout ?? DEFAULT_RETRY_TIMEOUT;
1214
+ const jitter = retry2.jitter ?? DEFAULT_RETRY_JITTER;
1070
1215
  return async (ctx, retryAfter) => {
1071
1216
  if (++retries > maxRetries || ctx.disposed) {
1072
1217
  return false;
@@ -1074,12 +1219,16 @@ var createRetryHandler = ({ retry }) => {
1074
1219
  if (retryAfter) {
1075
1220
  await sleep(retryAfter);
1076
1221
  } else {
1077
- const timeout = baseTimeout + Math.random() * jitter;
1078
- await sleep(timeout);
1222
+ const timeout2 = baseTimeout + Math.random() * jitter;
1223
+ await sleep(timeout2);
1079
1224
  }
1080
1225
  return true;
1081
1226
  };
1082
1227
  };
1228
+ var getFileMimeType = (filename) => [
1229
+ ".js",
1230
+ ".mjs"
1231
+ ].some((codeExtension) => filename.endsWith(codeExtension)) ? "application/javascript+module" : filename.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
1083
1232
  export {
1084
1233
  CLOUDFLARE_MESSAGE_MAX_BYTES,
1085
1234
  CLOUDFLARE_RPC_MAX_BYTES,
@@ -1087,6 +1236,7 @@ export {
1087
1236
  EdgeConnectionClosedError,
1088
1237
  EdgeHttpClient,
1089
1238
  EdgeIdentityChangedError,
1239
+ HttpConfig,
1090
1240
  Protocol,
1091
1241
  WebSocketMuxer,
1092
1242
  createChainEdgeIdentity,
@@ -1094,9 +1244,13 @@ export {
1094
1244
  createEphemeralEdgeIdentity,
1095
1245
  createStubEdgeIdentity,
1096
1246
  createTestHaloEdgeIdentity,
1247
+ encodeAuthHeader,
1097
1248
  getTypename,
1098
1249
  handleAuthChallenge,
1099
1250
  protocol,
1100
- toUint8Array
1251
+ toUint8Array,
1252
+ withLogging,
1253
+ withRetry,
1254
+ withRetryConfig
1101
1255
  };
1102
1256
  //# sourceMappingURL=index.mjs.map