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