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