@dxos/edge-client 0.8.3 → 0.8.4-main.28f8d3d

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 (56) hide show
  1. package/dist/lib/browser/{chunk-VHS3XEIX.mjs → chunk-SUXH7FH6.mjs} +15 -8
  2. package/dist/lib/browser/{chunk-VHS3XEIX.mjs.map → chunk-SUXH7FH6.mjs.map} +3 -3
  3. package/dist/lib/browser/edge-ws-muxer.mjs +1 -1
  4. package/dist/lib/browser/index.mjs +239 -149
  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 +61 -16
  8. package/dist/lib/browser/testing/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/{chunk-HGQUUFIJ.mjs → chunk-R6K4IIBW.mjs} +15 -8
  10. package/dist/lib/node-esm/{chunk-HGQUUFIJ.mjs.map → chunk-R6K4IIBW.mjs.map} +3 -3
  11. package/dist/lib/node-esm/edge-ws-muxer.mjs +1 -1
  12. package/dist/lib/node-esm/index.mjs +239 -149
  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 +61 -16
  16. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  17. package/dist/types/src/edge-client.d.ts +1 -1
  18. package/dist/types/src/edge-client.d.ts.map +1 -1
  19. package/dist/types/src/edge-http-client.d.ts +33 -30
  20. package/dist/types/src/edge-http-client.d.ts.map +1 -1
  21. package/dist/types/src/edge-http-client.test.d.ts +2 -0
  22. package/dist/types/src/edge-http-client.test.d.ts.map +1 -0
  23. package/dist/types/src/edge-ws-connection.d.ts +1 -0
  24. package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
  25. package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
  26. package/dist/types/src/http-client.d.ts +22 -0
  27. package/dist/types/src/http-client.d.ts.map +1 -0
  28. package/dist/types/src/http-client.test.d.ts +2 -0
  29. package/dist/types/src/http-client.test.d.ts.map +1 -0
  30. package/dist/types/src/testing/index.d.ts +1 -0
  31. package/dist/types/src/testing/index.d.ts.map +1 -1
  32. package/dist/types/src/testing/test-server.d.ts +9 -0
  33. package/dist/types/src/testing/test-server.d.ts.map +1 -0
  34. package/dist/types/src/testing/test-utils.d.ts.map +1 -1
  35. package/dist/types/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +21 -14
  37. package/src/edge-client.ts +2 -2
  38. package/src/edge-http-client.test.ts +22 -0
  39. package/src/edge-http-client.ts +192 -135
  40. package/src/edge-ws-connection.ts +11 -3
  41. package/src/edge-ws-muxer.ts +1 -1
  42. package/src/http-client.test.ts +54 -0
  43. package/src/http-client.ts +67 -0
  44. package/src/testing/index.ts +1 -0
  45. package/src/testing/test-server.ts +45 -0
  46. package/src/testing/test-utils.ts +2 -2
  47. package/src/websocket.test.ts +1 -1
  48. package/dist/lib/node/chunk-XNHBUTNB.cjs +0 -317
  49. package/dist/lib/node/chunk-XNHBUTNB.cjs.map +0 -7
  50. package/dist/lib/node/edge-ws-muxer.cjs +0 -33
  51. package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
  52. package/dist/lib/node/index.cjs +0 -1060
  53. package/dist/lib/node/index.cjs.map +0 -7
  54. package/dist/lib/node/meta.json +0 -1
  55. package/dist/lib/node/testing/index.cjs +0 -169
  56. package/dist/lib/node/testing/index.cjs.map +0 -7
@@ -6,21 +6,21 @@ import {
6
6
  getTypename,
7
7
  protocol,
8
8
  toUint8Array
9
- } from "./chunk-VHS3XEIX.mjs";
9
+ } from "./chunk-SUXH7FH6.mjs";
10
10
 
11
- // packages/core/mesh/edge-client/src/index.ts
11
+ // src/index.ts
12
12
  export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
13
13
 
14
- // packages/core/mesh/edge-client/src/edge-client.ts
15
- import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from "@dxos/async";
14
+ // src/edge-client.ts
15
+ import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask } from "@dxos/async";
16
16
  import { Resource as Resource2 } from "@dxos/context";
17
17
  import { log as log2, logInfo as logInfo2 } from "@dxos/log";
18
18
  import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
19
19
 
20
- // packages/core/mesh/edge-client/src/edge-identity.ts
20
+ // src/edge-identity.ts
21
21
  import { invariant } from "@dxos/invariant";
22
22
  import { schema } from "@dxos/protocols/proto";
23
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
23
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
24
24
  var handleAuthChallenge = async (failedResponse, identity) => {
25
25
  invariant(failedResponse.status === 401, void 0, {
26
26
  F: __dxlog_file,
@@ -57,7 +57,7 @@ var handleAuthChallenge = async (failedResponse, identity) => {
57
57
  return schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
58
58
  };
59
59
 
60
- // packages/core/mesh/edge-client/src/edge-ws-connection.ts
60
+ // src/edge-ws-connection.ts
61
61
  import WebSocket from "isomorphic-ws";
62
62
  import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
63
63
  import { Context, Resource } from "@dxos/context";
@@ -72,12 +72,19 @@ function _ts_decorate(decorators, target, key, desc) {
72
72
  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
73
  return c > 3 && r && Object.defineProperty(target, key, r), r;
74
74
  }
75
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
75
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
76
76
  var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
77
77
  var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
78
78
  var EdgeWsConnection = class extends Resource {
79
+ _identity;
80
+ _connectionInfo;
81
+ _callbacks;
82
+ _inactivityTimeoutCtx;
83
+ _ws;
84
+ _wsMuxer;
85
+ _lastReceivedMessageTimestamp;
79
86
  constructor(_identity, _connectionInfo, _callbacks) {
80
- super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks;
87
+ super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now();
81
88
  }
82
89
  get info() {
83
90
  return {
@@ -89,7 +96,7 @@ var EdgeWsConnection = class extends Resource {
89
96
  send(message) {
90
97
  invariant2(this._ws, void 0, {
91
98
  F: __dxlog_file2,
92
- L: 52,
99
+ L: 53,
93
100
  S: this,
94
101
  A: [
95
102
  "this._ws",
@@ -98,7 +105,7 @@ var EdgeWsConnection = class extends Resource {
98
105
  });
99
106
  invariant2(this._wsMuxer, void 0, {
100
107
  F: __dxlog_file2,
101
- L: 53,
108
+ L: 54,
102
109
  S: this,
103
110
  A: [
104
111
  "this._wsMuxer",
@@ -110,7 +117,7 @@ var EdgeWsConnection = class extends Resource {
110
117
  payload: protocol.getPayloadType(message)
111
118
  }, {
112
119
  F: __dxlog_file2,
113
- L: 54,
120
+ L: 55,
114
121
  S: this,
115
122
  C: (f, a) => f(...a)
116
123
  });
@@ -123,7 +130,7 @@ var EdgeWsConnection = class extends Resource {
123
130
  payload: protocol.getPayloadType(message)
124
131
  }, {
125
132
  F: __dxlog_file2,
126
- L: 58,
133
+ L: 59,
127
134
  S: this,
128
135
  C: (f, a) => f(...a)
129
136
  });
@@ -133,7 +140,7 @@ var EdgeWsConnection = class extends Resource {
133
140
  } else {
134
141
  this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
135
142
  F: __dxlog_file2,
136
- L: 67,
143
+ L: 68,
137
144
  S: this,
138
145
  C: (f, a) => f(...a)
139
146
  }));
@@ -155,7 +162,7 @@ var EdgeWsConnection = class extends Resource {
155
162
  if (this.isOpen) {
156
163
  log("connected", void 0, {
157
164
  F: __dxlog_file2,
158
- L: 84,
165
+ L: 85,
159
166
  S: this,
160
167
  C: (f, a) => f(...a)
161
168
  });
@@ -166,7 +173,7 @@ var EdgeWsConnection = class extends Resource {
166
173
  currentIdentity: this._identity
167
174
  }, {
168
175
  F: __dxlog_file2,
169
- L: 88,
176
+ L: 89,
170
177
  S: this,
171
178
  C: (f, a) => f(...a)
172
179
  });
@@ -179,7 +186,7 @@ var EdgeWsConnection = class extends Resource {
179
186
  reason: event.reason
180
187
  }, {
181
188
  F: __dxlog_file2,
182
- L: 93,
189
+ L: 94,
183
190
  S: this,
184
191
  C: (f, a) => f(...a)
185
192
  });
@@ -194,7 +201,7 @@ var EdgeWsConnection = class extends Resource {
194
201
  info: event.message
195
202
  }, {
196
203
  F: __dxlog_file2,
197
- L: 100,
204
+ L: 101,
198
205
  S: this,
199
206
  C: (f, a) => f(...a)
200
207
  });
@@ -204,7 +211,7 @@ var EdgeWsConnection = class extends Resource {
204
211
  error: event.error
205
212
  }, {
206
213
  F: __dxlog_file2,
207
- L: 103,
214
+ L: 104,
208
215
  S: this,
209
216
  C: (f, a) => f(...a)
210
217
  });
@@ -216,12 +223,13 @@ var EdgeWsConnection = class extends Resource {
216
223
  event: event.type
217
224
  }, {
218
225
  F: __dxlog_file2,
219
- L: 111,
226
+ L: 112,
220
227
  S: this,
221
228
  C: (f, a) => f(...a)
222
229
  });
223
230
  return;
224
231
  }
232
+ this._lastReceivedMessageTimestamp = Date.now();
225
233
  if (event.data === "__pong__") {
226
234
  this._rescheduleHeartbeatTimeout();
227
235
  return;
@@ -237,7 +245,7 @@ var EdgeWsConnection = class extends Resource {
237
245
  payload: protocol.getPayloadType(message)
238
246
  }, {
239
247
  F: __dxlog_file2,
240
- L: 128,
248
+ L: 130,
241
249
  S: this,
242
250
  C: (f, a) => f(...a)
243
251
  });
@@ -261,7 +269,7 @@ var EdgeWsConnection = class extends Resource {
261
269
  err
262
270
  }, {
263
271
  F: __dxlog_file2,
264
- L: 146,
272
+ L: 148,
265
273
  S: this,
266
274
  C: (f, a) => f(...a)
267
275
  });
@@ -270,7 +278,7 @@ var EdgeWsConnection = class extends Resource {
270
278
  _scheduleHeartbeats() {
271
279
  invariant2(this._ws, void 0, {
272
280
  F: __dxlog_file2,
273
- L: 151,
281
+ L: 153,
274
282
  S: this,
275
283
  A: [
276
284
  "this._ws",
@@ -290,17 +298,23 @@ var EdgeWsConnection = class extends Resource {
290
298
  void this._inactivityTimeoutCtx?.dispose();
291
299
  this._inactivityTimeoutCtx = new Context(void 0, {
292
300
  F: __dxlog_file2,
293
- L: 170
301
+ L: 172
294
302
  });
295
303
  scheduleTask(this._inactivityTimeoutCtx, () => {
296
304
  if (this.isOpen) {
297
- log.warn("restart due to inactivity timeout", void 0, {
298
- F: __dxlog_file2,
299
- L: 175,
300
- S: this,
301
- C: (f, a) => f(...a)
302
- });
303
- this._callbacks.onRestartRequired();
305
+ if (Date.now() - this._lastReceivedMessageTimestamp > SIGNAL_KEEPALIVE_TIMEOUT) {
306
+ log.warn("restart due to inactivity timeout", {
307
+ lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
308
+ }, {
309
+ F: __dxlog_file2,
310
+ L: 178,
311
+ S: this,
312
+ C: (f, a) => f(...a)
313
+ });
314
+ this._callbacks.onRestartRequired();
315
+ } else {
316
+ this._rescheduleHeartbeatTimeout();
317
+ }
304
318
  }
305
319
  }, SIGNAL_KEEPALIVE_TIMEOUT);
306
320
  }
@@ -309,7 +323,7 @@ _ts_decorate([
309
323
  logInfo
310
324
  ], EdgeWsConnection.prototype, "info", null);
311
325
 
312
- // packages/core/mesh/edge-client/src/errors.ts
326
+ // src/errors.ts
313
327
  var EdgeConnectionClosedError = class extends Error {
314
328
  constructor() {
315
329
  super("Edge connection closed.");
@@ -321,7 +335,7 @@ var EdgeIdentityChangedError = class extends Error {
321
335
  }
322
336
  };
323
337
 
324
- // packages/core/mesh/edge-client/src/utils.ts
338
+ // src/utils.ts
325
339
  var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
326
340
  const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
327
341
  const url = new URL(baseUrl);
@@ -329,16 +343,26 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
329
343
  return url.toString();
330
344
  };
331
345
 
332
- // packages/core/mesh/edge-client/src/edge-client.ts
346
+ // src/edge-client.ts
333
347
  function _ts_decorate2(decorators, target, key, desc) {
334
348
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
335
349
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
336
350
  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;
337
351
  return c > 3 && r && Object.defineProperty(target, key, r), r;
338
352
  }
339
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
353
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
340
354
  var DEFAULT_TIMEOUT = 1e4;
341
355
  var EdgeClient = class extends Resource2 {
356
+ _identity;
357
+ _config;
358
+ statusChanged;
359
+ _persistentLifecycle;
360
+ _messageListeners;
361
+ _reconnectListeners;
362
+ _baseWsUrl;
363
+ _baseHttpUrl;
364
+ _currentConnection;
365
+ _ready;
342
366
  constructor(_identity, _config) {
343
367
  super(), this._identity = _identity, this._config = _config, this.statusChanged = new Event(), this._persistentLifecycle = new PersistentLifecycle({
344
368
  start: async () => this._connect(),
@@ -615,6 +639,7 @@ var EdgeClient = class extends Resource2 {
615
639
  return void 0;
616
640
  }
617
641
  }
642
+ _isActive;
618
643
  };
619
644
  _ts_decorate2([
620
645
  logInfo2
@@ -624,12 +649,12 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
624
649
  return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
625
650
  };
626
651
 
627
- // packages/core/mesh/edge-client/src/auth.ts
652
+ // src/auth.ts
628
653
  import { createCredential, signPresentation } from "@dxos/credentials";
629
654
  import { invariant as invariant3 } from "@dxos/invariant";
630
655
  import { Keyring } from "@dxos/keyring";
631
656
  import { PublicKey } from "@dxos/keys";
632
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
657
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
633
658
  var createDeviceEdgeIdentity = async (signer, key) => {
634
659
  return {
635
660
  identityKey: key.toHex(),
@@ -735,23 +760,71 @@ var createStubEdgeIdentity = () => {
735
760
  };
736
761
  };
737
762
 
738
- // packages/core/mesh/edge-client/src/edge-http-client.ts
763
+ // src/edge-http-client.ts
764
+ import { FetchHttpClient, HttpClient } from "@effect/platform";
765
+ import { Effect as Effect2, pipe } from "effect";
739
766
  import { sleep } from "@dxos/async";
740
- import { Context as Context2 } from "@dxos/context";
767
+ import { Context as Context3 } from "@dxos/context";
768
+ import { log as log4 } from "@dxos/log";
769
+ import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
770
+ import { createUrl } from "@dxos/util";
771
+
772
+ // src/http-client.ts
773
+ import { Context as Context2, Duration, Effect, Layer, Schedule } from "effect";
741
774
  import { log as log3 } from "@dxos/log";
742
- import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
743
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
775
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
776
+ var HttpConfig = class _HttpConfig extends Context2.Tag("HttpConfig")() {
777
+ static default = Layer.succeed(_HttpConfig, {
778
+ timeout: Duration.millis(1e3),
779
+ retryTimes: 3,
780
+ retryBaseDelay: Duration.millis(1e3)
781
+ });
782
+ };
783
+ var withRetry = (effect, { timeout = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
784
+ return effect.pipe(Effect.flatMap((res) => (
785
+ // Treat 500 errors as retryable?
786
+ res.status === 500 ? Effect.fail(new Error(res.status.toString())) : res.json
787
+ )), Effect.timeout(timeout), Effect.retry({
788
+ schedule: Schedule.exponential(retryBaseDelay).pipe(Schedule.jittered),
789
+ times: retryTimes
790
+ }));
791
+ };
792
+ var withRetryConfig = (effect) => Effect.gen(function* () {
793
+ const config = yield* HttpConfig;
794
+ return yield* withRetry(effect, config);
795
+ });
796
+ var withLogging = (effect) => effect.pipe(Effect.tap((res) => log3.info("response", {
797
+ status: res.status
798
+ }, {
799
+ F: __dxlog_file5,
800
+ L: 58,
801
+ S: void 0,
802
+ C: (f, a) => f(...a)
803
+ })));
804
+ var encodeAuthHeader = (challenge) => {
805
+ const encodedChallenge = Buffer.from(challenge).toString("base64");
806
+ return `VerifiablePresentation pb;base64,${encodedChallenge}`;
807
+ };
808
+
809
+ // src/edge-http-client.ts
810
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
744
811
  var DEFAULT_RETRY_TIMEOUT = 1500;
745
812
  var DEFAULT_RETRY_JITTER = 500;
746
813
  var DEFAULT_MAX_RETRIES_COUNT = 3;
747
814
  var EdgeHttpClient = class {
815
+ _baseUrl;
816
+ _edgeIdentity;
817
+ /**
818
+ * Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
819
+ */
820
+ _authHeader;
748
821
  constructor(baseUrl) {
749
822
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
750
- log3("created", {
823
+ log4("created", {
751
824
  url: this._baseUrl
752
825
  }, {
753
- F: __dxlog_file5,
754
- L: 53,
826
+ F: __dxlog_file6,
827
+ L: 84,
755
828
  S: this,
756
829
  C: (f, a) => f(...a)
757
830
  });
@@ -765,98 +838,111 @@ var EdgeHttpClient = class {
765
838
  this._authHeader = void 0;
766
839
  }
767
840
  }
841
+ //
842
+ // Status
843
+ //
844
+ async getStatus(args) {
845
+ return this._call(new URL("/status", this.baseUrl), {
846
+ ...args,
847
+ method: "GET"
848
+ });
849
+ }
850
+ //
851
+ // Agents
852
+ //
768
853
  createAgent(body, args) {
769
- return this._call("/agents/create", {
854
+ return this._call(new URL("/agents/create", this.baseUrl), {
770
855
  ...args,
771
856
  method: "POST",
772
857
  body
773
858
  });
774
859
  }
775
860
  getAgentStatus(request, args) {
776
- return this._call(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, {
861
+ return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
777
862
  ...args,
778
863
  method: "GET"
779
864
  });
780
865
  }
866
+ //
867
+ // Credentials
868
+ //
781
869
  getCredentialsForNotarization(spaceId, args) {
782
- return this._call(`/spaces/${spaceId}/notarization`, {
870
+ return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
783
871
  ...args,
784
872
  method: "GET"
785
873
  });
786
874
  }
787
875
  async notarizeCredentials(spaceId, body, args) {
788
- await this._call(`/spaces/${spaceId}/notarization`, {
876
+ await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
789
877
  ...args,
790
878
  body,
791
879
  method: "POST"
792
880
  });
793
881
  }
794
- async joinSpaceByInvitation(spaceId, body, args) {
795
- return this._call(`/spaces/${spaceId}/join`, {
882
+ //
883
+ // Identity
884
+ //
885
+ async recoverIdentity(body, args) {
886
+ return this._call(new URL("/identity/recover", this.baseUrl), {
796
887
  ...args,
797
888
  body,
798
889
  method: "POST"
799
890
  });
800
891
  }
801
- async recoverIdentity(body, args) {
802
- return this._call("/identity/recover", {
892
+ //
893
+ // Invitations
894
+ //
895
+ async joinSpaceByInvitation(spaceId, body, args) {
896
+ return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
803
897
  ...args,
804
898
  body,
805
899
  method: "POST"
806
900
  });
807
901
  }
808
- async executeWorkflow(spaceId, graphId, input, args) {
809
- return this._call(`/workflows/${spaceId}/${graphId}`, {
902
+ //
903
+ // OAuth and credentials
904
+ //
905
+ async listFunctions(args) {
906
+ return this._call(new URL("/functions", this.baseUrl), {
810
907
  ...args,
811
- body: input,
812
- method: "POST"
908
+ method: "GET"
813
909
  });
814
910
  }
815
- async uploadFunction(pathParts, body, args) {
816
- const path = [
817
- "functions",
818
- ...pathParts.functionId ? [
819
- pathParts.functionId
820
- ] : []
821
- ].join("/");
822
- return this._call(path, {
911
+ async initiateOAuthFlow(body, args) {
912
+ return this._call(new URL("/oauth/initiate", this.baseUrl), {
823
913
  ...args,
824
914
  body,
825
- method: "PUT"
915
+ method: "POST"
826
916
  });
827
917
  }
828
- async initiateOAuthFlow(body, args) {
829
- return this._call("/oauth/initiate", {
918
+ //
919
+ // Spaces
920
+ //
921
+ async createSpace(body, args) {
922
+ return this._call(new URL("/spaces/create", this.baseUrl), {
830
923
  ...args,
831
924
  body,
832
925
  method: "POST"
833
926
  });
834
927
  }
928
+ //
929
+ // Queues
930
+ //
835
931
  async queryQueue(subspaceTag, spaceId, query, args) {
836
932
  const { queueId } = query;
837
- const queryParams = new URLSearchParams();
838
- if (query.after != null) {
839
- queryParams.set("after", query.after);
840
- }
841
- if (query.before != null) {
842
- queryParams.set("before", query.before);
843
- }
844
- if (query.limit != null) {
845
- queryParams.set("limit", query.limit.toString());
846
- }
847
- if (query.reverse != null) {
848
- queryParams.set("reverse", query.reverse.toString());
849
- }
850
- if (query.objectIds != null) {
851
- queryParams.set("objectIds", query.objectIds.join(","));
852
- }
853
- return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query?${queryParams.toString()}`, {
933
+ return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
934
+ after: query.after,
935
+ before: query.before,
936
+ limit: query.limit,
937
+ reverse: query.reverse,
938
+ objectIds: query.objectIds?.join(",")
939
+ }), {
854
940
  ...args,
855
941
  method: "GET"
856
942
  });
857
943
  }
858
944
  async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
859
- return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
945
+ return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
860
946
  ...args,
861
947
  body: {
862
948
  objects
@@ -865,52 +951,67 @@ var EdgeHttpClient = class {
865
951
  });
866
952
  }
867
953
  async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
868
- return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
954
+ return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
955
+ ids: objectIds.join(",")
956
+ }), {
869
957
  ...args,
870
- query: {
871
- ids: objectIds.join(",")
872
- },
873
958
  method: "DELETE"
874
959
  });
875
960
  }
876
- async createSpace(body, args) {
877
- return this._call("/spaces/create", {
961
+ //
962
+ // Functions
963
+ //
964
+ async uploadFunction(pathParts, body, args) {
965
+ const path = [
966
+ "functions",
967
+ ...pathParts.functionId ? [
968
+ pathParts.functionId
969
+ ] : []
970
+ ].join("/");
971
+ return this._call(new URL(path, this.baseUrl), {
878
972
  ...args,
879
973
  body,
880
- method: "POST"
974
+ method: "PUT"
881
975
  });
882
976
  }
883
- async _call(path, args) {
884
- const requestContext = args.context ?? new Context2(void 0, {
885
- F: __dxlog_file5,
886
- L: 192
977
+ //
978
+ // Workflows
979
+ //
980
+ async executeWorkflow(spaceId, graphId, input, args) {
981
+ return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
982
+ ...args,
983
+ body: input,
984
+ method: "POST"
887
985
  });
986
+ }
987
+ //
988
+ // Internal
989
+ //
990
+ async _fetch(url, args) {
991
+ return pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), Effect2.runPromise);
992
+ }
993
+ // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
994
+ async _call(url, args) {
888
995
  const shouldRetry = createRetryHandler(args);
889
- let url = `${this._baseUrl}${path.startsWith("/") ? path.slice(1) : path}`;
890
- if (args.query) {
891
- const queryParams = new URLSearchParams();
892
- for (const [key, value] of Object.entries(args.query)) {
893
- queryParams.set(key, value.toString());
894
- }
895
- url += `?${queryParams.toString()}`;
896
- }
897
- log3("call", {
898
- method: args.method,
899
- path,
996
+ const requestContext = args.context ?? new Context3(void 0, {
997
+ F: __dxlog_file6,
998
+ L: 293
999
+ });
1000
+ log4("fetch", {
1001
+ url,
900
1002
  request: args.body
901
1003
  }, {
902
- F: __dxlog_file5,
903
- L: 204,
1004
+ F: __dxlog_file6,
1005
+ L: 294,
904
1006
  S: this,
905
1007
  C: (f, a) => f(...a)
906
1008
  });
907
1009
  let handledAuth = false;
908
- let authHeader = this._authHeader;
909
1010
  while (true) {
910
1011
  let processingError;
911
1012
  let retryAfterHeaderValue = Number.NaN;
912
1013
  try {
913
- const request = createRequest(args, authHeader);
1014
+ const request = createRequest(args, this._authHeader);
914
1015
  const response = await fetch(url, request);
915
1016
  retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
916
1017
  if (response.ok) {
@@ -918,12 +1019,12 @@ var EdgeHttpClient = class {
918
1019
  if (body.success) {
919
1020
  return body.data;
920
1021
  }
921
- log3("unsuccessful edge response", {
922
- path,
1022
+ log4.warn("unsuccessful edge response", {
1023
+ url,
923
1024
  body
924
1025
  }, {
925
- F: __dxlog_file5,
926
- L: 223,
1026
+ F: __dxlog_file6,
1027
+ L: 310,
927
1028
  S: this,
928
1029
  C: (f, a) => f(...a)
929
1030
  });
@@ -933,7 +1034,7 @@ var EdgeHttpClient = class {
933
1034
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
934
1035
  }
935
1036
  } else if (response.status === 401 && !handledAuth) {
936
- authHeader = await this._handleUnauthorized(response);
1037
+ this._authHeader = await this._handleUnauthorized(response);
937
1038
  handledAuth = true;
938
1039
  continue;
939
1040
  } else {
@@ -943,12 +1044,12 @@ var EdgeHttpClient = class {
943
1044
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
944
1045
  }
945
1046
  if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
946
- log3("retrying edge request", {
947
- path,
1047
+ log4("retrying edge request", {
1048
+ url,
948
1049
  processingError
949
1050
  }, {
950
- F: __dxlog_file5,
951
- L: 242,
1051
+ F: __dxlog_file6,
1052
+ L: 328,
952
1053
  S: this,
953
1054
  C: (f, a) => f(...a)
954
1055
  });
@@ -959,33 +1060,35 @@ var EdgeHttpClient = class {
959
1060
  }
960
1061
  async _handleUnauthorized(response) {
961
1062
  if (!this._edgeIdentity) {
962
- log3.warn("edge unauthorized response received before identity was set", void 0, {
963
- F: __dxlog_file5,
964
- L: 251,
1063
+ log4.warn("unauthorized response received before identity was set", void 0, {
1064
+ F: __dxlog_file6,
1065
+ L: 337,
965
1066
  S: this,
966
1067
  C: (f, a) => f(...a)
967
1068
  });
968
1069
  throw EdgeCallFailedError.fromHttpFailure(response);
969
1070
  }
970
1071
  const challenge = await handleAuthChallenge(response, this._edgeIdentity);
971
- this._authHeader = encodeAuthHeader(challenge);
972
- log3("auth header updated", void 0, {
973
- F: __dxlog_file5,
974
- L: 256,
975
- S: this,
976
- C: (f, a) => f(...a)
977
- });
978
- return this._authHeader;
1072
+ return encodeAuthHeader(challenge);
979
1073
  }
980
1074
  };
981
- var createRetryHandler = (args) => {
982
- if (!args.retry || args.retry.count < 1) {
1075
+ var createRequest = ({ method, body }, authHeader) => {
1076
+ return {
1077
+ method,
1078
+ body: body && JSON.stringify(body),
1079
+ headers: authHeader ? {
1080
+ Authorization: authHeader
1081
+ } : void 0
1082
+ };
1083
+ };
1084
+ var createRetryHandler = ({ retry }) => {
1085
+ if (!retry || retry.count < 1) {
983
1086
  return async () => false;
984
1087
  }
985
1088
  let retries = 0;
986
- const maxRetries = args.retry.count ?? DEFAULT_MAX_RETRIES_COUNT;
987
- const baseTimeout = args.retry.timeout ?? DEFAULT_RETRY_TIMEOUT;
988
- const jitter = args.retry.jitter ?? DEFAULT_RETRY_JITTER;
1089
+ const maxRetries = retry.count ?? DEFAULT_MAX_RETRIES_COUNT;
1090
+ const baseTimeout = retry.timeout ?? DEFAULT_RETRY_TIMEOUT;
1091
+ const jitter = retry.jitter ?? DEFAULT_RETRY_JITTER;
989
1092
  return async (ctx, retryAfter) => {
990
1093
  if (++retries > maxRetries || ctx.disposed) {
991
1094
  return false;
@@ -999,19 +1102,6 @@ var createRetryHandler = (args) => {
999
1102
  return true;
1000
1103
  };
1001
1104
  };
1002
- var createRequest = (args, authHeader) => {
1003
- return {
1004
- method: args.method,
1005
- body: args.body && JSON.stringify(args.body),
1006
- headers: authHeader ? {
1007
- Authorization: authHeader
1008
- } : void 0
1009
- };
1010
- };
1011
- var encodeAuthHeader = (challenge) => {
1012
- const encodedChallenge = Buffer.from(challenge).toString("base64");
1013
- return `VerifiablePresentation pb;base64,${encodedChallenge}`;
1014
- };
1015
1105
  export {
1016
1106
  CLOUDFLARE_MESSAGE_MAX_BYTES,
1017
1107
  CLOUDFLARE_RPC_MAX_BYTES,