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