@dxos/edge-client 0.8.3 → 0.8.4-main.f9ba587

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 (46) 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 +183 -128
  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 +183 -128
  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 +32 -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/http-client.d.ts +22 -0
  20. package/dist/types/src/http-client.d.ts.map +1 -0
  21. package/dist/types/src/http-client.test.d.ts +2 -0
  22. package/dist/types/src/http-client.test.d.ts.map +1 -0
  23. package/dist/types/src/testing/index.d.ts +1 -0
  24. package/dist/types/src/testing/index.d.ts.map +1 -1
  25. package/dist/types/src/testing/test-server.d.ts +9 -0
  26. package/dist/types/src/testing/test-server.d.ts.map +1 -0
  27. package/dist/types/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +18 -14
  29. package/src/edge-http-client.test.ts +22 -0
  30. package/src/edge-http-client.ts +188 -135
  31. package/src/http-client.test.ts +55 -0
  32. package/src/http-client.ts +67 -0
  33. package/src/testing/index.ts +1 -0
  34. package/src/testing/test-server.ts +45 -0
  35. package/src/testing/test-utils.ts +1 -1
  36. package/dist/lib/node/chunk-XNHBUTNB.cjs +0 -317
  37. package/dist/lib/node/chunk-XNHBUTNB.cjs.map +0 -7
  38. package/dist/lib/node/edge-ws-muxer.cjs +0 -33
  39. package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
  40. package/dist/lib/node/index.cjs +0 -1060
  41. package/dist/lib/node/index.cjs.map +0 -7
  42. package/dist/lib/node/meta.json +0 -1
  43. package/dist/lib/node/testing/index.cjs +0 -169
  44. package/dist/lib/node/testing/index.cjs.map +0 -7
  45. /package/dist/lib/browser/{chunk-VHS3XEIX.mjs.map → chunk-LMP5TVOP.mjs.map} +0 -0
  46. /package/dist/lib/node-esm/{chunk-HGQUUFIJ.mjs.map → chunk-X7J46ISZ.mjs.map} +0 -0
@@ -1,19 +1,19 @@
1
- // packages/core/mesh/edge-client/src/edge-ws-muxer.ts
1
+ // src/edge-ws-muxer.ts
2
2
  import { Trigger } from "@dxos/async";
3
3
  import { log } from "@dxos/log";
4
4
  import { buf as buf2 } from "@dxos/protocols/buf";
5
5
  import { MessageSchema as MessageSchema2 } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
6
6
 
7
- // packages/core/mesh/edge-client/src/defs.ts
7
+ // src/defs.ts
8
8
  import { bufWkt as bufWkt2 } from "@dxos/protocols/buf";
9
9
  import { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
10
10
 
11
- // packages/core/mesh/edge-client/src/protocol.ts
11
+ // src/protocol.ts
12
12
  import { invariant } from "@dxos/invariant";
13
13
  import { buf, bufWkt } from "@dxos/protocols/buf";
14
14
  import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
15
15
  import { bufferToArray } from "@dxos/util";
16
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
16
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
17
17
  var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
18
18
  var Protocol = class {
19
19
  constructor(types) {
@@ -104,7 +104,7 @@ var toUint8Array = async (data) => {
104
104
  throw new Error(`Unexpected datatype: ${data}`);
105
105
  };
106
106
 
107
- // packages/core/mesh/edge-client/src/defs.ts
107
+ // src/defs.ts
108
108
  var protocol = new Protocol([
109
109
  SwarmRequestSchema,
110
110
  SwarmResponseSchema,
@@ -112,8 +112,8 @@ var protocol = new Protocol([
112
112
  bufWkt2.AnySchema
113
113
  ]);
114
114
 
115
- // packages/core/mesh/edge-client/src/edge-ws-muxer.ts
116
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-muxer.ts";
115
+ // src/edge-ws-muxer.ts
116
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-muxer.ts";
117
117
  var FLAG_SEGMENT_SEQ = 1;
118
118
  var FLAG_SEGMENT_SEQ_TERMINATED = 1 << 1;
119
119
  var CLOUDFLARE_MESSAGE_MAX_BYTES = 1e3 * 1e3;
@@ -294,4 +294,4 @@ export {
294
294
  CLOUDFLARE_RPC_MAX_BYTES,
295
295
  WebSocketMuxer
296
296
  };
297
- //# sourceMappingURL=chunk-VHS3XEIX.mjs.map
297
+ //# sourceMappingURL=chunk-LMP5TVOP.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  CLOUDFLARE_MESSAGE_MAX_BYTES,
3
3
  CLOUDFLARE_RPC_MAX_BYTES,
4
4
  WebSocketMuxer
5
- } from "./chunk-VHS3XEIX.mjs";
5
+ } from "./chunk-LMP5TVOP.mjs";
6
6
  export {
7
7
  CLOUDFLARE_MESSAGE_MAX_BYTES,
8
8
  CLOUDFLARE_RPC_MAX_BYTES,
@@ -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,7 +72,7 @@ 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 {
@@ -309,7 +309,7 @@ _ts_decorate([
309
309
  logInfo
310
310
  ], EdgeWsConnection.prototype, "info", null);
311
311
 
312
- // packages/core/mesh/edge-client/src/errors.ts
312
+ // src/errors.ts
313
313
  var EdgeConnectionClosedError = class extends Error {
314
314
  constructor() {
315
315
  super("Edge connection closed.");
@@ -321,7 +321,7 @@ var EdgeIdentityChangedError = class extends Error {
321
321
  }
322
322
  };
323
323
 
324
- // packages/core/mesh/edge-client/src/utils.ts
324
+ // src/utils.ts
325
325
  var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
326
326
  const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
327
327
  const url = new URL(baseUrl);
@@ -329,14 +329,14 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
329
329
  return url.toString();
330
330
  };
331
331
 
332
- // packages/core/mesh/edge-client/src/edge-client.ts
332
+ // src/edge-client.ts
333
333
  function _ts_decorate2(decorators, target, key, desc) {
334
334
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
335
335
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
336
336
  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
337
  return c > 3 && r && Object.defineProperty(target, key, r), r;
338
338
  }
339
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
339
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
340
340
  var DEFAULT_TIMEOUT = 1e4;
341
341
  var EdgeClient = class extends Resource2 {
342
342
  constructor(_identity, _config) {
@@ -624,12 +624,12 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
624
624
  return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
625
625
  };
626
626
 
627
- // packages/core/mesh/edge-client/src/auth.ts
627
+ // src/auth.ts
628
628
  import { createCredential, signPresentation } from "@dxos/credentials";
629
629
  import { invariant as invariant3 } from "@dxos/invariant";
630
630
  import { Keyring } from "@dxos/keyring";
631
631
  import { PublicKey } from "@dxos/keys";
632
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
632
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
633
633
  var createDeviceEdgeIdentity = async (signer, key) => {
634
634
  return {
635
635
  identityKey: key.toHex(),
@@ -735,23 +735,67 @@ var createStubEdgeIdentity = () => {
735
735
  };
736
736
  };
737
737
 
738
- // packages/core/mesh/edge-client/src/edge-http-client.ts
738
+ // src/edge-http-client.ts
739
+ import { FetchHttpClient, HttpClient } from "@effect/platform";
740
+ import { Effect as Effect2, pipe } from "effect";
739
741
  import { sleep } from "@dxos/async";
740
- import { Context as Context2 } from "@dxos/context";
742
+ import { Context as Context3 } from "@dxos/context";
743
+ import { log as log4 } from "@dxos/log";
744
+ import { EdgeAuthChallengeError, EdgeCallFailedError } from "@dxos/protocols";
745
+ import { createUrl } from "@dxos/util";
746
+
747
+ // src/http-client.ts
748
+ import { Context as Context2, Duration, Effect, Layer, Schedule } from "effect";
741
749
  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";
750
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
751
+ var HttpConfig = class _HttpConfig extends Context2.Tag("HttpConfig")() {
752
+ static {
753
+ this.default = Layer.succeed(_HttpConfig, {
754
+ timeout: Duration.millis(1e3),
755
+ retryTimes: 3,
756
+ retryBaseDelay: Duration.millis(1e3)
757
+ });
758
+ }
759
+ };
760
+ var withRetry = (effect, { timeout = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
761
+ return effect.pipe(Effect.flatMap((res) => (
762
+ // Treat 500 errors as retryable?
763
+ res.status === 500 ? Effect.fail(new Error(res.status.toString())) : res.json
764
+ )), Effect.timeout(timeout), Effect.retry({
765
+ schedule: Schedule.exponential(retryBaseDelay).pipe(Schedule.jittered),
766
+ times: retryTimes
767
+ }));
768
+ };
769
+ var withRetryConfig = (effect) => Effect.gen(function* () {
770
+ const config = yield* HttpConfig;
771
+ return yield* withRetry(effect, config);
772
+ });
773
+ var withLogging = (effect) => effect.pipe(Effect.tap((res) => log3.info("response", {
774
+ status: res.status
775
+ }, {
776
+ F: __dxlog_file5,
777
+ L: 58,
778
+ S: void 0,
779
+ C: (f, a) => f(...a)
780
+ })));
781
+ var encodeAuthHeader = (challenge) => {
782
+ const encodedChallenge = Buffer.from(challenge).toString("base64");
783
+ return `VerifiablePresentation pb;base64,${encodedChallenge}`;
784
+ };
785
+
786
+ // src/edge-http-client.ts
787
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
744
788
  var DEFAULT_RETRY_TIMEOUT = 1500;
745
789
  var DEFAULT_RETRY_JITTER = 500;
746
790
  var DEFAULT_MAX_RETRIES_COUNT = 3;
747
791
  var EdgeHttpClient = class {
748
792
  constructor(baseUrl) {
749
793
  this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
750
- log3("created", {
794
+ log4("created", {
751
795
  url: this._baseUrl
752
796
  }, {
753
- F: __dxlog_file5,
754
- L: 53,
797
+ F: __dxlog_file6,
798
+ L: 84,
755
799
  S: this,
756
800
  C: (f, a) => f(...a)
757
801
  });
@@ -765,98 +809,105 @@ var EdgeHttpClient = class {
765
809
  this._authHeader = void 0;
766
810
  }
767
811
  }
812
+ //
813
+ // Status
814
+ //
815
+ async getStatus(args) {
816
+ return this._call(new URL("/status", this.baseUrl), {
817
+ ...args,
818
+ method: "GET"
819
+ });
820
+ }
821
+ //
822
+ // Agents
823
+ //
768
824
  createAgent(body, args) {
769
- return this._call("/agents/create", {
825
+ return this._call(new URL("/agents/create", this.baseUrl), {
770
826
  ...args,
771
827
  method: "POST",
772
828
  body
773
829
  });
774
830
  }
775
831
  getAgentStatus(request, args) {
776
- return this._call(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, {
832
+ return this._call(new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
777
833
  ...args,
778
834
  method: "GET"
779
835
  });
780
836
  }
837
+ //
838
+ // Credentials
839
+ //
781
840
  getCredentialsForNotarization(spaceId, args) {
782
- return this._call(`/spaces/${spaceId}/notarization`, {
841
+ return this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
783
842
  ...args,
784
843
  method: "GET"
785
844
  });
786
845
  }
787
846
  async notarizeCredentials(spaceId, body, args) {
788
- await this._call(`/spaces/${spaceId}/notarization`, {
789
- ...args,
790
- body,
791
- method: "POST"
792
- });
793
- }
794
- async joinSpaceByInvitation(spaceId, body, args) {
795
- return this._call(`/spaces/${spaceId}/join`, {
847
+ await this._call(new URL(`/spaces/${spaceId}/notarization`, this.baseUrl), {
796
848
  ...args,
797
849
  body,
798
850
  method: "POST"
799
851
  });
800
852
  }
853
+ //
854
+ // Identity
855
+ //
801
856
  async recoverIdentity(body, args) {
802
- return this._call("/identity/recover", {
857
+ return this._call(new URL("/identity/recover", this.baseUrl), {
803
858
  ...args,
804
859
  body,
805
860
  method: "POST"
806
861
  });
807
862
  }
808
- async executeWorkflow(spaceId, graphId, input, args) {
809
- return this._call(`/workflows/${spaceId}/${graphId}`, {
863
+ //
864
+ // Invitations
865
+ //
866
+ async joinSpaceByInvitation(spaceId, body, args) {
867
+ return this._call(new URL(`/spaces/${spaceId}/join`, this.baseUrl), {
810
868
  ...args,
811
- body: input,
869
+ body,
812
870
  method: "POST"
813
871
  });
814
872
  }
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, {
873
+ //
874
+ // OAuth and credentials
875
+ //
876
+ async initiateOAuthFlow(body, args) {
877
+ return this._call(new URL("/oauth/initiate", this.baseUrl), {
823
878
  ...args,
824
879
  body,
825
- method: "PUT"
880
+ method: "POST"
826
881
  });
827
882
  }
828
- async initiateOAuthFlow(body, args) {
829
- return this._call("/oauth/initiate", {
883
+ //
884
+ // Spaces
885
+ //
886
+ async createSpace(body, args) {
887
+ return this._call(new URL("/spaces/create", this.baseUrl), {
830
888
  ...args,
831
889
  body,
832
890
  method: "POST"
833
891
  });
834
892
  }
893
+ //
894
+ // Queues
895
+ //
835
896
  async queryQueue(subspaceTag, spaceId, query, args) {
836
897
  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()}`, {
898
+ return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
899
+ after: query.after,
900
+ before: query.before,
901
+ limit: query.limit,
902
+ reverse: query.reverse,
903
+ objectIds: query.objectIds?.join(",")
904
+ }), {
854
905
  ...args,
855
906
  method: "GET"
856
907
  });
857
908
  }
858
909
  async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
859
- return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
910
+ return this._call(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
860
911
  ...args,
861
912
  body: {
862
913
  objects
@@ -865,52 +916,67 @@ var EdgeHttpClient = class {
865
916
  });
866
917
  }
867
918
  async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
868
- return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
919
+ return this._call(createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, this.baseUrl), {
920
+ ids: objectIds.join(",")
921
+ }), {
869
922
  ...args,
870
- query: {
871
- ids: objectIds.join(",")
872
- },
873
923
  method: "DELETE"
874
924
  });
875
925
  }
876
- async createSpace(body, args) {
877
- return this._call("/spaces/create", {
926
+ //
927
+ // Functions
928
+ //
929
+ async uploadFunction(pathParts, body, args) {
930
+ const path = [
931
+ "functions",
932
+ ...pathParts.functionId ? [
933
+ pathParts.functionId
934
+ ] : []
935
+ ].join("/");
936
+ return this._call(new URL(path, this.baseUrl), {
878
937
  ...args,
879
938
  body,
880
- method: "POST"
939
+ method: "PUT"
881
940
  });
882
941
  }
883
- async _call(path, args) {
884
- const requestContext = args.context ?? new Context2(void 0, {
885
- F: __dxlog_file5,
886
- L: 192
942
+ //
943
+ // Workflows
944
+ //
945
+ async executeWorkflow(spaceId, graphId, input, args) {
946
+ return this._call(new URL(`/workflows/${spaceId}/${graphId}`, this.baseUrl), {
947
+ ...args,
948
+ body: input,
949
+ method: "POST"
887
950
  });
951
+ }
952
+ //
953
+ // Internal
954
+ //
955
+ async _fetch(url, args) {
956
+ return pipe(HttpClient.get(url), withLogging, withRetryConfig, Effect2.provide(FetchHttpClient.layer), Effect2.provide(HttpConfig.default), Effect2.withSpan("EdgeHttpClient"), Effect2.runPromise);
957
+ }
958
+ // TODO(burdon): Refactor with effect (see edge-http-client.test.ts).
959
+ async _call(url, args) {
888
960
  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,
961
+ const requestContext = args.context ?? new Context3(void 0, {
962
+ F: __dxlog_file6,
963
+ L: 289
964
+ });
965
+ log4("fetch", {
966
+ url,
900
967
  request: args.body
901
968
  }, {
902
- F: __dxlog_file5,
903
- L: 204,
969
+ F: __dxlog_file6,
970
+ L: 290,
904
971
  S: this,
905
972
  C: (f, a) => f(...a)
906
973
  });
907
974
  let handledAuth = false;
908
- let authHeader = this._authHeader;
909
975
  while (true) {
910
976
  let processingError;
911
977
  let retryAfterHeaderValue = Number.NaN;
912
978
  try {
913
- const request = createRequest(args, authHeader);
979
+ const request = createRequest(args, this._authHeader);
914
980
  const response = await fetch(url, request);
915
981
  retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
916
982
  if (response.ok) {
@@ -918,12 +984,12 @@ var EdgeHttpClient = class {
918
984
  if (body.success) {
919
985
  return body.data;
920
986
  }
921
- log3("unsuccessful edge response", {
922
- path,
987
+ log4.warn("unsuccessful edge response", {
988
+ url,
923
989
  body
924
990
  }, {
925
- F: __dxlog_file5,
926
- L: 223,
991
+ F: __dxlog_file6,
992
+ L: 306,
927
993
  S: this,
928
994
  C: (f, a) => f(...a)
929
995
  });
@@ -933,7 +999,7 @@ var EdgeHttpClient = class {
933
999
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
934
1000
  }
935
1001
  } else if (response.status === 401 && !handledAuth) {
936
- authHeader = await this._handleUnauthorized(response);
1002
+ this._authHeader = await this._handleUnauthorized(response);
937
1003
  handledAuth = true;
938
1004
  continue;
939
1005
  } else {
@@ -943,12 +1009,12 @@ var EdgeHttpClient = class {
943
1009
  processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
944
1010
  }
945
1011
  if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
946
- log3("retrying edge request", {
947
- path,
1012
+ log4("retrying edge request", {
1013
+ url,
948
1014
  processingError
949
1015
  }, {
950
- F: __dxlog_file5,
951
- L: 242,
1016
+ F: __dxlog_file6,
1017
+ L: 324,
952
1018
  S: this,
953
1019
  C: (f, a) => f(...a)
954
1020
  });
@@ -959,33 +1025,35 @@ var EdgeHttpClient = class {
959
1025
  }
960
1026
  async _handleUnauthorized(response) {
961
1027
  if (!this._edgeIdentity) {
962
- log3.warn("edge unauthorized response received before identity was set", void 0, {
963
- F: __dxlog_file5,
964
- L: 251,
1028
+ log4.warn("unauthorized response received before identity was set", void 0, {
1029
+ F: __dxlog_file6,
1030
+ L: 333,
965
1031
  S: this,
966
1032
  C: (f, a) => f(...a)
967
1033
  });
968
1034
  throw EdgeCallFailedError.fromHttpFailure(response);
969
1035
  }
970
1036
  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;
1037
+ return encodeAuthHeader(challenge);
979
1038
  }
980
1039
  };
981
- var createRetryHandler = (args) => {
982
- if (!args.retry || args.retry.count < 1) {
1040
+ var createRequest = ({ method, body }, authHeader) => {
1041
+ return {
1042
+ method,
1043
+ body: body && JSON.stringify(body),
1044
+ headers: authHeader ? {
1045
+ Authorization: authHeader
1046
+ } : void 0
1047
+ };
1048
+ };
1049
+ var createRetryHandler = ({ retry }) => {
1050
+ if (!retry || retry.count < 1) {
983
1051
  return async () => false;
984
1052
  }
985
1053
  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;
1054
+ const maxRetries = retry.count ?? DEFAULT_MAX_RETRIES_COUNT;
1055
+ const baseTimeout = retry.timeout ?? DEFAULT_RETRY_TIMEOUT;
1056
+ const jitter = retry.jitter ?? DEFAULT_RETRY_JITTER;
989
1057
  return async (ctx, retryAfter) => {
990
1058
  if (++retries > maxRetries || ctx.disposed) {
991
1059
  return false;
@@ -999,19 +1067,6 @@ var createRetryHandler = (args) => {
999
1067
  return true;
1000
1068
  };
1001
1069
  };
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
1070
  export {
1016
1071
  CLOUDFLARE_MESSAGE_MAX_BYTES,
1017
1072
  CLOUDFLARE_RPC_MAX_BYTES,