@dxos/edge-client 0.8.3 → 0.8.4-main.2e9d522

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 (49) hide show
  1. package/dist/lib/browser/{chunk-VHS3XEIX.mjs → chunk-LMP5TVOP.mjs} +8 -8
  2. package/dist/lib/browser/edge-ws-muxer.mjs +1 -1
  3. package/dist/lib/browser/index.mjs +216 -148
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +61 -16
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/{chunk-HGQUUFIJ.mjs → chunk-X7J46ISZ.mjs} +8 -8
  9. package/dist/lib/node-esm/edge-ws-muxer.mjs +1 -1
  10. package/dist/lib/node-esm/index.mjs +216 -148
  11. package/dist/lib/node-esm/index.mjs.map +4 -4
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +61 -16
  14. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  15. package/dist/types/src/edge-http-client.d.ts +33 -30
  16. package/dist/types/src/edge-http-client.d.ts.map +1 -1
  17. package/dist/types/src/edge-http-client.test.d.ts +2 -0
  18. package/dist/types/src/edge-http-client.test.d.ts.map +1 -0
  19. package/dist/types/src/edge-ws-connection.d.ts +1 -0
  20. package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
  21. package/dist/types/src/http-client.d.ts +22 -0
  22. package/dist/types/src/http-client.d.ts.map +1 -0
  23. package/dist/types/src/http-client.test.d.ts +2 -0
  24. package/dist/types/src/http-client.test.d.ts.map +1 -0
  25. package/dist/types/src/testing/index.d.ts +1 -0
  26. package/dist/types/src/testing/index.d.ts.map +1 -1
  27. package/dist/types/src/testing/test-server.d.ts +9 -0
  28. package/dist/types/src/testing/test-server.d.ts.map +1 -0
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +18 -14
  31. package/src/edge-http-client.test.ts +22 -0
  32. package/src/edge-http-client.ts +191 -134
  33. package/src/edge-ws-connection.ts +10 -2
  34. package/src/http-client.test.ts +54 -0
  35. package/src/http-client.ts +67 -0
  36. package/src/testing/index.ts +1 -0
  37. package/src/testing/test-server.ts +45 -0
  38. package/src/testing/test-utils.ts +1 -1
  39. package/dist/lib/node/chunk-XNHBUTNB.cjs +0 -317
  40. package/dist/lib/node/chunk-XNHBUTNB.cjs.map +0 -7
  41. package/dist/lib/node/edge-ws-muxer.cjs +0 -33
  42. package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
  43. package/dist/lib/node/index.cjs +0 -1060
  44. package/dist/lib/node/index.cjs.map +0 -7
  45. package/dist/lib/node/meta.json +0 -1
  46. package/dist/lib/node/testing/index.cjs +0 -169
  47. package/dist/lib/node/testing/index.cjs.map +0 -7
  48. /package/dist/lib/browser/{chunk-VHS3XEIX.mjs.map → chunk-LMP5TVOP.mjs.map} +0 -0
  49. /package/dist/lib/node-esm/{chunk-HGQUUFIJ.mjs.map → chunk-X7J46ISZ.mjs.map} +0 -0
@@ -6,21 +6,21 @@ import {
6
6
  getTypename,
7
7
  protocol,
8
8
  toUint8Array
9
- } from "./chunk-VHS3XEIX.mjs";
9
+ } from "./chunk-LMP5TVOP.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
14
+ // src/edge-client.ts
15
15
  import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } 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,12 @@ 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
79
  constructor(_identity, _connectionInfo, _callbacks) {
80
- super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks;
80
+ super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now();
81
81
  }
82
82
  get info() {
83
83
  return {
@@ -89,7 +89,7 @@ var EdgeWsConnection = class extends Resource {
89
89
  send(message) {
90
90
  invariant2(this._ws, void 0, {
91
91
  F: __dxlog_file2,
92
- L: 52,
92
+ L: 53,
93
93
  S: this,
94
94
  A: [
95
95
  "this._ws",
@@ -98,7 +98,7 @@ var EdgeWsConnection = class extends Resource {
98
98
  });
99
99
  invariant2(this._wsMuxer, void 0, {
100
100
  F: __dxlog_file2,
101
- L: 53,
101
+ L: 54,
102
102
  S: this,
103
103
  A: [
104
104
  "this._wsMuxer",
@@ -110,7 +110,7 @@ var EdgeWsConnection = class extends Resource {
110
110
  payload: protocol.getPayloadType(message)
111
111
  }, {
112
112
  F: __dxlog_file2,
113
- L: 54,
113
+ L: 55,
114
114
  S: this,
115
115
  C: (f, a) => f(...a)
116
116
  });
@@ -123,7 +123,7 @@ var EdgeWsConnection = class extends Resource {
123
123
  payload: protocol.getPayloadType(message)
124
124
  }, {
125
125
  F: __dxlog_file2,
126
- L: 58,
126
+ L: 59,
127
127
  S: this,
128
128
  C: (f, a) => f(...a)
129
129
  });
@@ -133,7 +133,7 @@ var EdgeWsConnection = class extends Resource {
133
133
  } else {
134
134
  this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
135
135
  F: __dxlog_file2,
136
- L: 67,
136
+ L: 68,
137
137
  S: this,
138
138
  C: (f, a) => f(...a)
139
139
  }));
@@ -155,7 +155,7 @@ var EdgeWsConnection = class extends Resource {
155
155
  if (this.isOpen) {
156
156
  log("connected", void 0, {
157
157
  F: __dxlog_file2,
158
- L: 84,
158
+ L: 85,
159
159
  S: this,
160
160
  C: (f, a) => f(...a)
161
161
  });
@@ -166,7 +166,7 @@ var EdgeWsConnection = class extends Resource {
166
166
  currentIdentity: this._identity
167
167
  }, {
168
168
  F: __dxlog_file2,
169
- L: 88,
169
+ L: 89,
170
170
  S: this,
171
171
  C: (f, a) => f(...a)
172
172
  });
@@ -179,7 +179,7 @@ var EdgeWsConnection = class extends Resource {
179
179
  reason: event.reason
180
180
  }, {
181
181
  F: __dxlog_file2,
182
- L: 93,
182
+ L: 94,
183
183
  S: this,
184
184
  C: (f, a) => f(...a)
185
185
  });
@@ -194,7 +194,7 @@ var EdgeWsConnection = class extends Resource {
194
194
  info: event.message
195
195
  }, {
196
196
  F: __dxlog_file2,
197
- L: 100,
197
+ L: 101,
198
198
  S: this,
199
199
  C: (f, a) => f(...a)
200
200
  });
@@ -204,7 +204,7 @@ var EdgeWsConnection = class extends Resource {
204
204
  error: event.error
205
205
  }, {
206
206
  F: __dxlog_file2,
207
- L: 103,
207
+ L: 104,
208
208
  S: this,
209
209
  C: (f, a) => f(...a)
210
210
  });
@@ -216,12 +216,13 @@ var EdgeWsConnection = class extends Resource {
216
216
  event: event.type
217
217
  }, {
218
218
  F: __dxlog_file2,
219
- L: 111,
219
+ L: 112,
220
220
  S: this,
221
221
  C: (f, a) => f(...a)
222
222
  });
223
223
  return;
224
224
  }
225
+ this._lastReceivedMessageTimestamp = Date.now();
225
226
  if (event.data === "__pong__") {
226
227
  this._rescheduleHeartbeatTimeout();
227
228
  return;
@@ -237,7 +238,7 @@ var EdgeWsConnection = class extends Resource {
237
238
  payload: protocol.getPayloadType(message)
238
239
  }, {
239
240
  F: __dxlog_file2,
240
- L: 128,
241
+ L: 130,
241
242
  S: this,
242
243
  C: (f, a) => f(...a)
243
244
  });
@@ -261,7 +262,7 @@ var EdgeWsConnection = class extends Resource {
261
262
  err
262
263
  }, {
263
264
  F: __dxlog_file2,
264
- L: 146,
265
+ L: 148,
265
266
  S: this,
266
267
  C: (f, a) => f(...a)
267
268
  });
@@ -270,7 +271,7 @@ var EdgeWsConnection = class extends Resource {
270
271
  _scheduleHeartbeats() {
271
272
  invariant2(this._ws, void 0, {
272
273
  F: __dxlog_file2,
273
- L: 151,
274
+ L: 153,
274
275
  S: this,
275
276
  A: [
276
277
  "this._ws",
@@ -290,17 +291,23 @@ var EdgeWsConnection = class extends Resource {
290
291
  void this._inactivityTimeoutCtx?.dispose();
291
292
  this._inactivityTimeoutCtx = new Context(void 0, {
292
293
  F: __dxlog_file2,
293
- L: 170
294
+ L: 172
294
295
  });
295
296
  scheduleTask(this._inactivityTimeoutCtx, () => {
296
297
  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();
298
+ if (Date.now() - this._lastReceivedMessageTimestamp > SIGNAL_KEEPALIVE_TIMEOUT) {
299
+ log.warn("restart due to inactivity timeout", {
300
+ lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
301
+ }, {
302
+ F: __dxlog_file2,
303
+ L: 178,
304
+ S: this,
305
+ C: (f, a) => f(...a)
306
+ });
307
+ this._callbacks.onRestartRequired();
308
+ } else {
309
+ this._rescheduleHeartbeatTimeout();
310
+ }
304
311
  }
305
312
  }, SIGNAL_KEEPALIVE_TIMEOUT);
306
313
  }
@@ -309,7 +316,7 @@ _ts_decorate([
309
316
  logInfo
310
317
  ], EdgeWsConnection.prototype, "info", null);
311
318
 
312
- // packages/core/mesh/edge-client/src/errors.ts
319
+ // src/errors.ts
313
320
  var EdgeConnectionClosedError = class extends Error {
314
321
  constructor() {
315
322
  super("Edge connection closed.");
@@ -321,7 +328,7 @@ var EdgeIdentityChangedError = class extends Error {
321
328
  }
322
329
  };
323
330
 
324
- // packages/core/mesh/edge-client/src/utils.ts
331
+ // src/utils.ts
325
332
  var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
326
333
  const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
327
334
  const url = new URL(baseUrl);
@@ -329,14 +336,14 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
329
336
  return url.toString();
330
337
  };
331
338
 
332
- // packages/core/mesh/edge-client/src/edge-client.ts
339
+ // src/edge-client.ts
333
340
  function _ts_decorate2(decorators, target, key, desc) {
334
341
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
335
342
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
336
343
  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
344
  return c > 3 && r && Object.defineProperty(target, key, r), r;
338
345
  }
339
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
346
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
340
347
  var DEFAULT_TIMEOUT = 1e4;
341
348
  var EdgeClient = class extends Resource2 {
342
349
  constructor(_identity, _config) {
@@ -624,12 +631,12 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
624
631
  return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
625
632
  };
626
633
 
627
- // packages/core/mesh/edge-client/src/auth.ts
634
+ // src/auth.ts
628
635
  import { createCredential, signPresentation } from "@dxos/credentials";
629
636
  import { invariant as invariant3 } from "@dxos/invariant";
630
637
  import { Keyring } from "@dxos/keyring";
631
638
  import { PublicKey } from "@dxos/keys";
632
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
639
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
633
640
  var createDeviceEdgeIdentity = async (signer, key) => {
634
641
  return {
635
642
  identityKey: key.toHex(),
@@ -735,23 +742,67 @@ var createStubEdgeIdentity = () => {
735
742
  };
736
743
  };
737
744
 
738
- // packages/core/mesh/edge-client/src/edge-http-client.ts
745
+ // src/edge-http-client.ts
746
+ import { FetchHttpClient, HttpClient } from "@effect/platform";
747
+ import { Effect as Effect2, pipe } from "effect";
739
748
  import { sleep } from "@dxos/async";
740
- import { Context as Context2 } from "@dxos/context";
749
+ import { Context as Context3 } from "@dxos/context";
750
+ import { log as log4 } from "@dxos/log";
751
+ import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
752
+ import { createUrl } from "@dxos/util";
753
+
754
+ // src/http-client.ts
755
+ import { Context as Context2, Duration, Effect, Layer, Schedule } from "effect";
741
756
  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";
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)
764
+ });
765
+ }
766
+ };
767
+ var withRetry = (effect, { timeout = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
768
+ return effect.pipe(Effect.flatMap((res) => (
769
+ // Treat 500 errors as retryable?
770
+ res.status === 500 ? Effect.fail(new Error(res.status.toString())) : res.json
771
+ )), Effect.timeout(timeout), Effect.retry({
772
+ schedule: Schedule.exponential(retryBaseDelay).pipe(Schedule.jittered),
773
+ times: retryTimes
774
+ }));
775
+ };
776
+ var withRetryConfig = (effect) => Effect.gen(function* () {
777
+ const config = yield* HttpConfig;
778
+ return yield* withRetry(effect, config);
779
+ });
780
+ var withLogging = (effect) => effect.pipe(Effect.tap((res) => log3.info("response", {
781
+ status: res.status
782
+ }, {
783
+ F: __dxlog_file5,
784
+ L: 58,
785
+ S: void 0,
786
+ C: (f, a) => f(...a)
787
+ })));
788
+ var encodeAuthHeader = (challenge) => {
789
+ const encodedChallenge = Buffer.from(challenge).toString("base64");
790
+ return `VerifiablePresentation pb;base64,${encodedChallenge}`;
791
+ };
792
+
793
+ // src/edge-http-client.ts
794
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
744
795
  var DEFAULT_RETRY_TIMEOUT = 1500;
745
796
  var DEFAULT_RETRY_JITTER = 500;
746
797
  var DEFAULT_MAX_RETRIES_COUNT = 3;
747
798
  var EdgeHttpClient = class {
748
799
  constructor(baseUrl) {
749
800
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
750
- log3("created", {
801
+ log4("created", {
751
802
  url: this._baseUrl
752
803
  }, {
753
- F: __dxlog_file5,
754
- L: 53,
804
+ F: __dxlog_file6,
805
+ L: 84,
755
806
  S: this,
756
807
  C: (f, a) => f(...a)
757
808
  });
@@ -765,98 +816,111 @@ var EdgeHttpClient = class {
765
816
  this._authHeader = void 0;
766
817
  }
767
818
  }
819
+ //
820
+ // Status
821
+ //
822
+ async getStatus(args) {
823
+ return this._call(new URL("/status", this.baseUrl), {
824
+ ...args,
825
+ method: "GET"
826
+ });
827
+ }
828
+ //
829
+ // Agents
830
+ //
768
831
  createAgent(body, args) {
769
- return this._call("/agents/create", {
832
+ return this._call(new URL("/agents/create", this.baseUrl), {
770
833
  ...args,
771
834
  method: "POST",
772
835
  body
773
836
  });
774
837
  }
775
838
  getAgentStatus(request, args) {
776
- return this._call(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, {
839
+ return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
777
840
  ...args,
778
841
  method: "GET"
779
842
  });
780
843
  }
844
+ //
845
+ // Credentials
846
+ //
781
847
  getCredentialsForNotarization(spaceId, args) {
782
- return this._call(`/spaces/${spaceId}/notarization`, {
848
+ return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
783
849
  ...args,
784
850
  method: "GET"
785
851
  });
786
852
  }
787
853
  async notarizeCredentials(spaceId, body, args) {
788
- await this._call(`/spaces/${spaceId}/notarization`, {
854
+ await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
789
855
  ...args,
790
856
  body,
791
857
  method: "POST"
792
858
  });
793
859
  }
794
- async joinSpaceByInvitation(spaceId, body, args) {
795
- return this._call(`/spaces/${spaceId}/join`, {
860
+ //
861
+ // Identity
862
+ //
863
+ async recoverIdentity(body, args) {
864
+ return this._call(new URL("/identity/recover", this.baseUrl), {
796
865
  ...args,
797
866
  body,
798
867
  method: "POST"
799
868
  });
800
869
  }
801
- async recoverIdentity(body, args) {
802
- return this._call("/identity/recover", {
870
+ //
871
+ // Invitations
872
+ //
873
+ async joinSpaceByInvitation(spaceId, body, args) {
874
+ return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
803
875
  ...args,
804
876
  body,
805
877
  method: "POST"
806
878
  });
807
879
  }
808
- async executeWorkflow(spaceId, graphId, input, args) {
809
- return this._call(`/workflows/${spaceId}/${graphId}`, {
880
+ //
881
+ // OAuth and credentials
882
+ //
883
+ async listFunctions(args) {
884
+ return this._call(new URL("/functions", this.baseUrl), {
810
885
  ...args,
811
- body: input,
812
- method: "POST"
886
+ method: "GET"
813
887
  });
814
888
  }
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, {
889
+ async initiateOAuthFlow(body, args) {
890
+ return this._call(new URL("/oauth/initiate", this.baseUrl), {
823
891
  ...args,
824
892
  body,
825
- method: "PUT"
893
+ method: "POST"
826
894
  });
827
895
  }
828
- async initiateOAuthFlow(body, args) {
829
- return this._call("/oauth/initiate", {
896
+ //
897
+ // Spaces
898
+ //
899
+ async createSpace(body, args) {
900
+ return this._call(new URL("/spaces/create", this.baseUrl), {
830
901
  ...args,
831
902
  body,
832
903
  method: "POST"
833
904
  });
834
905
  }
906
+ //
907
+ // Queues
908
+ //
835
909
  async queryQueue(subspaceTag, spaceId, query, args) {
836
910
  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()}`, {
911
+ return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
912
+ after: query.after,
913
+ before: query.before,
914
+ limit: query.limit,
915
+ reverse: query.reverse,
916
+ objectIds: query.objectIds?.join(",")
917
+ }), {
854
918
  ...args,
855
919
  method: "GET"
856
920
  });
857
921
  }
858
922
  async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
859
- return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
923
+ return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
860
924
  ...args,
861
925
  body: {
862
926
  objects
@@ -865,52 +929,67 @@ var EdgeHttpClient = class {
865
929
  });
866
930
  }
867
931
  async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
868
- return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
932
+ return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
933
+ ids: objectIds.join(",")
934
+ }), {
869
935
  ...args,
870
- query: {
871
- ids: objectIds.join(",")
872
- },
873
936
  method: "DELETE"
874
937
  });
875
938
  }
876
- async createSpace(body, args) {
877
- return this._call("/spaces/create", {
939
+ //
940
+ // Functions
941
+ //
942
+ async uploadFunction(pathParts, body, args) {
943
+ const path = [
944
+ "functions",
945
+ ...pathParts.functionId ? [
946
+ pathParts.functionId
947
+ ] : []
948
+ ].join("/");
949
+ return this._call(new URL(path, this.baseUrl), {
878
950
  ...args,
879
951
  body,
880
- method: "POST"
952
+ method: "PUT"
881
953
  });
882
954
  }
883
- async _call(path, args) {
884
- const requestContext = args.context ?? new Context2(void 0, {
885
- F: __dxlog_file5,
886
- L: 192
955
+ //
956
+ // Workflows
957
+ //
958
+ async executeWorkflow(spaceId, graphId, input, args) {
959
+ return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
960
+ ...args,
961
+ body: input,
962
+ method: "POST"
887
963
  });
964
+ }
965
+ //
966
+ // Internal
967
+ //
968
+ 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);
970
+ }
971
+ // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
972
+ async _call(url, args) {
888
973
  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,
974
+ const requestContext = args.context ?? new Context3(void 0, {
975
+ F: __dxlog_file6,
976
+ L: 293
977
+ });
978
+ log4("fetch", {
979
+ url,
900
980
  request: args.body
901
981
  }, {
902
- F: __dxlog_file5,
903
- L: 204,
982
+ F: __dxlog_file6,
983
+ L: 294,
904
984
  S: this,
905
985
  C: (f, a) => f(...a)
906
986
  });
907
987
  let handledAuth = false;
908
- let authHeader = this._authHeader;
909
988
  while (true) {
910
989
  let processingError;
911
990
  let retryAfterHeaderValue = Number.NaN;
912
991
  try {
913
- const request = createRequest(args, authHeader);
992
+ const request = createRequest(args, this._authHeader);
914
993
  const response = await fetch(url, request);
915
994
  retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
916
995
  if (response.ok) {
@@ -918,12 +997,12 @@ var EdgeHttpClient = class {
918
997
  if (body.success) {
919
998
  return body.data;
920
999
  }
921
- log3("unsuccessful edge response", {
922
- path,
1000
+ log4.warn("unsuccessful edge response", {
1001
+ url,
923
1002
  body
924
1003
  }, {
925
- F: __dxlog_file5,
926
- L: 223,
1004
+ F: __dxlog_file6,
1005
+ L: 310,
927
1006
  S: this,
928
1007
  C: (f, a) => f(...a)
929
1008
  });
@@ -933,7 +1012,7 @@ var EdgeHttpClient = class {
933
1012
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
934
1013
  }
935
1014
  } else if (response.status === 401 && !handledAuth) {
936
- authHeader = await this._handleUnauthorized(response);
1015
+ this._authHeader = await this._handleUnauthorized(response);
937
1016
  handledAuth = true;
938
1017
  continue;
939
1018
  } else {
@@ -943,12 +1022,12 @@ var EdgeHttpClient = class {
943
1022
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
944
1023
  }
945
1024
  if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
946
- log3("retrying edge request", {
947
- path,
1025
+ log4("retrying edge request", {
1026
+ url,
948
1027
  processingError
949
1028
  }, {
950
- F: __dxlog_file5,
951
- L: 242,
1029
+ F: __dxlog_file6,
1030
+ L: 328,
952
1031
  S: this,
953
1032
  C: (f, a) => f(...a)
954
1033
  });
@@ -959,33 +1038,35 @@ var EdgeHttpClient = class {
959
1038
  }
960
1039
  async _handleUnauthorized(response) {
961
1040
  if (!this._edgeIdentity) {
962
- log3.warn("edge unauthorized response received before identity was set", void 0, {
963
- F: __dxlog_file5,
964
- L: 251,
1041
+ log4.warn("unauthorized response received before identity was set", void 0, {
1042
+ F: __dxlog_file6,
1043
+ L: 337,
965
1044
  S: this,
966
1045
  C: (f, a) => f(...a)
967
1046
  });
968
1047
  throw EdgeCallFailedError.fromHttpFailure(response);
969
1048
  }
970
1049
  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;
1050
+ return encodeAuthHeader(challenge);
979
1051
  }
980
1052
  };
981
- var createRetryHandler = (args) => {
982
- if (!args.retry || args.retry.count < 1) {
1053
+ var createRequest = ({ method, body }, authHeader) => {
1054
+ return {
1055
+ method,
1056
+ body: body && JSON.stringify(body),
1057
+ headers: authHeader ? {
1058
+ Authorization: authHeader
1059
+ } : void 0
1060
+ };
1061
+ };
1062
+ var createRetryHandler = ({ retry }) => {
1063
+ if (!retry || retry.count < 1) {
983
1064
  return async () => false;
984
1065
  }
985
1066
  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;
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;
989
1070
  return async (ctx, retryAfter) => {
990
1071
  if (++retries > maxRetries || ctx.disposed) {
991
1072
  return false;
@@ -999,19 +1080,6 @@ var createRetryHandler = (args) => {
999
1080
  return true;
1000
1081
  };
1001
1082
  };
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
1083
  export {
1016
1084
  CLOUDFLARE_MESSAGE_MAX_BYTES,
1017
1085
  CLOUDFLARE_RPC_MAX_BYTES,