@dxos/edge-client 0.8.4-main.c1de068 → 0.8.4-main.dedc0f3
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-LMP5TVOP.mjs → chunk-IKP53CBQ.mjs} +44 -11
- package/dist/lib/browser/{chunk-LMP5TVOP.mjs.map → chunk-IKP53CBQ.mjs.map} +3 -3
- package/dist/lib/browser/edge-ws-muxer.mjs +1 -1
- package/dist/lib/browser/index.mjs +392 -244
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/{chunk-X7J46ISZ.mjs → chunk-DR5YNW5K.mjs} +44 -11
- package/dist/lib/node-esm/{chunk-X7J46ISZ.mjs.map → chunk-DR5YNW5K.mjs.map} +3 -3
- package/dist/lib/node-esm/edge-ws-muxer.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +392 -244
- 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 +1 -1
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/edge-client.d.ts +15 -15
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +21 -2
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -15
- package/src/edge-client.ts +40 -40
- package/src/edge-http-client.ts +153 -20
- package/src/edge-ws-connection.ts +1 -1
- package/src/edge-ws-muxer.ts +1 -1
- package/src/http-client.test.ts +2 -1
- package/src/index.ts +4 -3
- package/src/testing/test-utils.ts +1 -1
- package/src/websocket.test.ts +1 -1
|
@@ -6,24 +6,135 @@ import {
|
|
|
6
6
|
getTypename,
|
|
7
7
|
protocol,
|
|
8
8
|
toUint8Array
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-IKP53CBQ.mjs";
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
12
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
13
13
|
|
|
14
|
+
// src/auth.ts
|
|
15
|
+
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
16
|
+
import { invariant } from "@dxos/invariant";
|
|
17
|
+
import { Keyring } from "@dxos/keyring";
|
|
18
|
+
import { PublicKey } from "@dxos/keys";
|
|
19
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
20
|
+
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
21
|
+
return {
|
|
22
|
+
identityKey: key.toHex(),
|
|
23
|
+
peerKey: key.toHex(),
|
|
24
|
+
presentCredentials: async ({ challenge }) => {
|
|
25
|
+
return signPresentation({
|
|
26
|
+
presentation: {
|
|
27
|
+
credentials: [
|
|
28
|
+
// Verifier requires at least one credential in the presentation to establish the subject.
|
|
29
|
+
await createCredential({
|
|
30
|
+
assertion: {
|
|
31
|
+
"@type": "dxos.halo.credentials.Auth"
|
|
32
|
+
},
|
|
33
|
+
issuer: key,
|
|
34
|
+
subject: key,
|
|
35
|
+
signer
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
signer,
|
|
40
|
+
signerKey: key,
|
|
41
|
+
nonce: challenge
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, credentials) => {
|
|
47
|
+
const credentialsToSign = credentials.length > 0 ? credentials : [
|
|
48
|
+
await createCredential({
|
|
49
|
+
assertion: {
|
|
50
|
+
"@type": "dxos.halo.credentials.Auth"
|
|
51
|
+
},
|
|
52
|
+
issuer: identityKey,
|
|
53
|
+
subject: identityKey,
|
|
54
|
+
signer,
|
|
55
|
+
chain,
|
|
56
|
+
signingKey: peerKey
|
|
57
|
+
})
|
|
58
|
+
];
|
|
59
|
+
return {
|
|
60
|
+
identityKey: identityKey.toHex(),
|
|
61
|
+
peerKey: peerKey.toHex(),
|
|
62
|
+
presentCredentials: async ({ challenge }) => {
|
|
63
|
+
invariant(chain, void 0, {
|
|
64
|
+
F: __dxlog_file,
|
|
65
|
+
L: 75,
|
|
66
|
+
S: void 0,
|
|
67
|
+
A: [
|
|
68
|
+
"chain",
|
|
69
|
+
""
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
return signPresentation({
|
|
73
|
+
presentation: {
|
|
74
|
+
credentials: credentialsToSign
|
|
75
|
+
},
|
|
76
|
+
signer,
|
|
77
|
+
nonce: challenge,
|
|
78
|
+
signerKey: peerKey,
|
|
79
|
+
chain
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
var createEphemeralEdgeIdentity = async () => {
|
|
85
|
+
const keyring = new Keyring();
|
|
86
|
+
const key = await keyring.createKey();
|
|
87
|
+
return createDeviceEdgeIdentity(keyring, key);
|
|
88
|
+
};
|
|
89
|
+
var createTestHaloEdgeIdentity = async (signer, identityKey, deviceKey) => {
|
|
90
|
+
const deviceAdmission = await createCredential({
|
|
91
|
+
assertion: {
|
|
92
|
+
"@type": "dxos.halo.credentials.AuthorizedDevice",
|
|
93
|
+
deviceKey,
|
|
94
|
+
identityKey
|
|
95
|
+
},
|
|
96
|
+
issuer: identityKey,
|
|
97
|
+
subject: deviceKey,
|
|
98
|
+
signer
|
|
99
|
+
});
|
|
100
|
+
return createChainEdgeIdentity(signer, identityKey, deviceKey, {
|
|
101
|
+
credential: deviceAdmission
|
|
102
|
+
}, [
|
|
103
|
+
await createCredential({
|
|
104
|
+
assertion: {
|
|
105
|
+
"@type": "dxos.halo.credentials.Auth"
|
|
106
|
+
},
|
|
107
|
+
issuer: identityKey,
|
|
108
|
+
subject: identityKey,
|
|
109
|
+
signer
|
|
110
|
+
})
|
|
111
|
+
]);
|
|
112
|
+
};
|
|
113
|
+
var createStubEdgeIdentity = () => {
|
|
114
|
+
const identityKey = PublicKey.random();
|
|
115
|
+
const deviceKey = PublicKey.random();
|
|
116
|
+
return {
|
|
117
|
+
identityKey: identityKey.toHex(),
|
|
118
|
+
peerKey: deviceKey.toHex(),
|
|
119
|
+
presentCredentials: async () => {
|
|
120
|
+
throw new Error("Stub identity does not support authentication.");
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
14
125
|
// src/edge-client.ts
|
|
15
|
-
import {
|
|
126
|
+
import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask } from "@dxos/async";
|
|
16
127
|
import { Resource as Resource2 } from "@dxos/context";
|
|
17
128
|
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
18
129
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
19
130
|
|
|
20
131
|
// src/edge-identity.ts
|
|
21
|
-
import { invariant } from "@dxos/invariant";
|
|
132
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
22
133
|
import { schema } from "@dxos/protocols/proto";
|
|
23
|
-
var
|
|
134
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
|
|
24
135
|
var handleAuthChallenge = async (failedResponse, identity) => {
|
|
25
|
-
|
|
26
|
-
F:
|
|
136
|
+
invariant2(failedResponse.status === 401, void 0, {
|
|
137
|
+
F: __dxlog_file2,
|
|
27
138
|
L: 21,
|
|
28
139
|
S: void 0,
|
|
29
140
|
A: [
|
|
@@ -32,8 +143,8 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
32
143
|
]
|
|
33
144
|
});
|
|
34
145
|
const headerValue = failedResponse.headers.get("Www-Authenticate");
|
|
35
|
-
|
|
36
|
-
F:
|
|
146
|
+
invariant2(headerValue?.startsWith("VerifiablePresentation challenge="), void 0, {
|
|
147
|
+
F: __dxlog_file2,
|
|
37
148
|
L: 24,
|
|
38
149
|
S: void 0,
|
|
39
150
|
A: [
|
|
@@ -42,8 +153,8 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
42
153
|
]
|
|
43
154
|
});
|
|
44
155
|
const challenge = headerValue?.slice("VerifiablePresentation challenge=".length);
|
|
45
|
-
|
|
46
|
-
F:
|
|
156
|
+
invariant2(challenge, void 0, {
|
|
157
|
+
F: __dxlog_file2,
|
|
47
158
|
L: 27,
|
|
48
159
|
S: void 0,
|
|
49
160
|
A: [
|
|
@@ -61,24 +172,34 @@ var handleAuthChallenge = async (failedResponse, identity) => {
|
|
|
61
172
|
import WebSocket from "isomorphic-ws";
|
|
62
173
|
import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
63
174
|
import { Context, Resource } from "@dxos/context";
|
|
64
|
-
import { invariant as
|
|
175
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
65
176
|
import { log, logInfo } from "@dxos/log";
|
|
66
177
|
import { EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
67
178
|
import { buf } from "@dxos/protocols/buf";
|
|
68
179
|
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
180
|
+
function _define_property(obj, key, value) {
|
|
181
|
+
if (key in obj) {
|
|
182
|
+
Object.defineProperty(obj, key, {
|
|
183
|
+
value,
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
obj[key] = value;
|
|
190
|
+
}
|
|
191
|
+
return obj;
|
|
192
|
+
}
|
|
69
193
|
function _ts_decorate(decorators, target, key, desc) {
|
|
70
194
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
71
195
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
72
196
|
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
197
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
74
198
|
}
|
|
75
|
-
var
|
|
199
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
76
200
|
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
77
201
|
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
78
202
|
var EdgeWsConnection = class extends Resource {
|
|
79
|
-
constructor(_identity, _connectionInfo, _callbacks) {
|
|
80
|
-
super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now();
|
|
81
|
-
}
|
|
82
203
|
get info() {
|
|
83
204
|
return {
|
|
84
205
|
open: this.isOpen,
|
|
@@ -87,8 +208,8 @@ var EdgeWsConnection = class extends Resource {
|
|
|
87
208
|
};
|
|
88
209
|
}
|
|
89
210
|
send(message) {
|
|
90
|
-
|
|
91
|
-
F:
|
|
211
|
+
invariant3(this._ws, void 0, {
|
|
212
|
+
F: __dxlog_file3,
|
|
92
213
|
L: 53,
|
|
93
214
|
S: this,
|
|
94
215
|
A: [
|
|
@@ -96,8 +217,8 @@ var EdgeWsConnection = class extends Resource {
|
|
|
96
217
|
""
|
|
97
218
|
]
|
|
98
219
|
});
|
|
99
|
-
|
|
100
|
-
F:
|
|
220
|
+
invariant3(this._wsMuxer, void 0, {
|
|
221
|
+
F: __dxlog_file3,
|
|
101
222
|
L: 54,
|
|
102
223
|
S: this,
|
|
103
224
|
A: [
|
|
@@ -109,7 +230,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
109
230
|
peerKey: this._identity.peerKey,
|
|
110
231
|
payload: protocol.getPayloadType(message)
|
|
111
232
|
}, {
|
|
112
|
-
F:
|
|
233
|
+
F: __dxlog_file3,
|
|
113
234
|
L: 55,
|
|
114
235
|
S: this,
|
|
115
236
|
C: (f, a) => f(...a)
|
|
@@ -122,7 +243,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
122
243
|
serviceId: message.serviceId,
|
|
123
244
|
payload: protocol.getPayloadType(message)
|
|
124
245
|
}, {
|
|
125
|
-
F:
|
|
246
|
+
F: __dxlog_file3,
|
|
126
247
|
L: 59,
|
|
127
248
|
S: this,
|
|
128
249
|
C: (f, a) => f(...a)
|
|
@@ -132,7 +253,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
132
253
|
this._ws.send(binary);
|
|
133
254
|
} else {
|
|
134
255
|
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
135
|
-
F:
|
|
256
|
+
F: __dxlog_file3,
|
|
136
257
|
L: 68,
|
|
137
258
|
S: this,
|
|
138
259
|
C: (f, a) => f(...a)
|
|
@@ -154,7 +275,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
154
275
|
this._ws.onopen = () => {
|
|
155
276
|
if (this.isOpen) {
|
|
156
277
|
log("connected", void 0, {
|
|
157
|
-
F:
|
|
278
|
+
F: __dxlog_file3,
|
|
158
279
|
L: 85,
|
|
159
280
|
S: this,
|
|
160
281
|
C: (f, a) => f(...a)
|
|
@@ -165,7 +286,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
165
286
|
log.verbose("connected after becoming inactive", {
|
|
166
287
|
currentIdentity: this._identity
|
|
167
288
|
}, {
|
|
168
|
-
F:
|
|
289
|
+
F: __dxlog_file3,
|
|
169
290
|
L: 89,
|
|
170
291
|
S: this,
|
|
171
292
|
C: (f, a) => f(...a)
|
|
@@ -178,7 +299,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
178
299
|
code: event.code,
|
|
179
300
|
reason: event.reason
|
|
180
301
|
}, {
|
|
181
|
-
F:
|
|
302
|
+
F: __dxlog_file3,
|
|
182
303
|
L: 94,
|
|
183
304
|
S: this,
|
|
184
305
|
C: (f, a) => f(...a)
|
|
@@ -193,7 +314,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
193
314
|
error: event.error,
|
|
194
315
|
info: event.message
|
|
195
316
|
}, {
|
|
196
|
-
F:
|
|
317
|
+
F: __dxlog_file3,
|
|
197
318
|
L: 101,
|
|
198
319
|
S: this,
|
|
199
320
|
C: (f, a) => f(...a)
|
|
@@ -203,7 +324,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
203
324
|
log.verbose("error ignored on closed connection", {
|
|
204
325
|
error: event.error
|
|
205
326
|
}, {
|
|
206
|
-
F:
|
|
327
|
+
F: __dxlog_file3,
|
|
207
328
|
L: 104,
|
|
208
329
|
S: this,
|
|
209
330
|
C: (f, a) => f(...a)
|
|
@@ -215,7 +336,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
215
336
|
log.verbose("message ignored on closed connection", {
|
|
216
337
|
event: event.type
|
|
217
338
|
}, {
|
|
218
|
-
F:
|
|
339
|
+
F: __dxlog_file3,
|
|
219
340
|
L: 112,
|
|
220
341
|
S: this,
|
|
221
342
|
C: (f, a) => f(...a)
|
|
@@ -237,7 +358,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
237
358
|
from: message.source,
|
|
238
359
|
payload: protocol.getPayloadType(message)
|
|
239
360
|
}, {
|
|
240
|
-
F:
|
|
361
|
+
F: __dxlog_file3,
|
|
241
362
|
L: 130,
|
|
242
363
|
S: this,
|
|
243
364
|
C: (f, a) => f(...a)
|
|
@@ -261,7 +382,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
261
382
|
log.warn("Error closing websocket", {
|
|
262
383
|
err
|
|
263
384
|
}, {
|
|
264
|
-
F:
|
|
385
|
+
F: __dxlog_file3,
|
|
265
386
|
L: 148,
|
|
266
387
|
S: this,
|
|
267
388
|
C: (f, a) => f(...a)
|
|
@@ -269,8 +390,8 @@ var EdgeWsConnection = class extends Resource {
|
|
|
269
390
|
}
|
|
270
391
|
}
|
|
271
392
|
_scheduleHeartbeats() {
|
|
272
|
-
|
|
273
|
-
F:
|
|
393
|
+
invariant3(this._ws, void 0, {
|
|
394
|
+
F: __dxlog_file3,
|
|
274
395
|
L: 153,
|
|
275
396
|
S: this,
|
|
276
397
|
A: [
|
|
@@ -290,7 +411,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
290
411
|
}
|
|
291
412
|
void this._inactivityTimeoutCtx?.dispose();
|
|
292
413
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
293
|
-
F:
|
|
414
|
+
F: __dxlog_file3,
|
|
294
415
|
L: 172
|
|
295
416
|
});
|
|
296
417
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
@@ -299,7 +420,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
299
420
|
log.warn("restart due to inactivity timeout", {
|
|
300
421
|
lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
|
|
301
422
|
}, {
|
|
302
|
-
F:
|
|
423
|
+
F: __dxlog_file3,
|
|
303
424
|
L: 178,
|
|
304
425
|
S: this,
|
|
305
426
|
C: (f, a) => f(...a)
|
|
@@ -311,6 +432,9 @@ var EdgeWsConnection = class extends Resource {
|
|
|
311
432
|
}
|
|
312
433
|
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
313
434
|
}
|
|
435
|
+
constructor(_identity, _connectionInfo, _callbacks) {
|
|
436
|
+
super(), _define_property(this, "_identity", void 0), _define_property(this, "_connectionInfo", void 0), _define_property(this, "_callbacks", void 0), _define_property(this, "_inactivityTimeoutCtx", void 0), _define_property(this, "_ws", void 0), _define_property(this, "_wsMuxer", void 0), _define_property(this, "_lastReceivedMessageTimestamp", void 0), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now();
|
|
437
|
+
}
|
|
314
438
|
};
|
|
315
439
|
_ts_decorate([
|
|
316
440
|
logInfo
|
|
@@ -337,23 +461,28 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
337
461
|
};
|
|
338
462
|
|
|
339
463
|
// src/edge-client.ts
|
|
464
|
+
function _define_property2(obj, key, value) {
|
|
465
|
+
if (key in obj) {
|
|
466
|
+
Object.defineProperty(obj, key, {
|
|
467
|
+
value,
|
|
468
|
+
enumerable: true,
|
|
469
|
+
configurable: true,
|
|
470
|
+
writable: true
|
|
471
|
+
});
|
|
472
|
+
} else {
|
|
473
|
+
obj[key] = value;
|
|
474
|
+
}
|
|
475
|
+
return obj;
|
|
476
|
+
}
|
|
340
477
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
341
478
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
342
479
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
343
480
|
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;
|
|
344
481
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
345
482
|
}
|
|
346
|
-
var
|
|
483
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
347
484
|
var DEFAULT_TIMEOUT = 1e4;
|
|
348
485
|
var EdgeClient = class extends Resource2 {
|
|
349
|
-
constructor(_identity, _config) {
|
|
350
|
-
super(), this._identity = _identity, this._config = _config, this.statusChanged = new Event(), this._persistentLifecycle = new PersistentLifecycle({
|
|
351
|
-
start: async () => this._connect(),
|
|
352
|
-
stop: async (state) => this._disconnect(state)
|
|
353
|
-
}), this._messageListeners = /* @__PURE__ */ new Set(), this._reconnectListeners = /* @__PURE__ */ new Set(), this._currentConnection = void 0, this._ready = new Trigger(), this._isActive = (connection) => connection === this._currentConnection;
|
|
354
|
-
this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "ws");
|
|
355
|
-
this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "http");
|
|
356
|
-
}
|
|
357
486
|
get info() {
|
|
358
487
|
return {
|
|
359
488
|
open: this.isOpen,
|
|
@@ -377,7 +506,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
377
506
|
identity,
|
|
378
507
|
oldIdentity: this._identity
|
|
379
508
|
}, {
|
|
380
|
-
F:
|
|
509
|
+
F: __dxlog_file4,
|
|
381
510
|
L: 99,
|
|
382
511
|
S: this,
|
|
383
512
|
C: (f, a) => f(...a)
|
|
@@ -387,6 +516,30 @@ var EdgeClient = class extends Resource2 {
|
|
|
387
516
|
void this._persistentLifecycle.scheduleRestart();
|
|
388
517
|
}
|
|
389
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Send message.
|
|
521
|
+
* NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
|
|
522
|
+
*/
|
|
523
|
+
async send(message) {
|
|
524
|
+
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
525
|
+
log2("waiting for websocket", void 0, {
|
|
526
|
+
F: __dxlog_file4,
|
|
527
|
+
L: 112,
|
|
528
|
+
S: this,
|
|
529
|
+
C: (f, a) => f(...a)
|
|
530
|
+
});
|
|
531
|
+
await this._ready.wait({
|
|
532
|
+
timeout: this._config.timeout ?? DEFAULT_TIMEOUT
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
if (!this._currentConnection) {
|
|
536
|
+
throw new EdgeConnectionClosedError();
|
|
537
|
+
}
|
|
538
|
+
if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
|
|
539
|
+
throw new EdgeIdentityChangedError();
|
|
540
|
+
}
|
|
541
|
+
this._currentConnection.send(message);
|
|
542
|
+
}
|
|
390
543
|
onMessage(listener) {
|
|
391
544
|
this._messageListeners.add(listener);
|
|
392
545
|
return () => this._messageListeners.delete(listener);
|
|
@@ -400,8 +553,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
400
553
|
listener();
|
|
401
554
|
} catch (error) {
|
|
402
555
|
log2.catch(error, void 0, {
|
|
403
|
-
F:
|
|
404
|
-
L:
|
|
556
|
+
F: __dxlog_file4,
|
|
557
|
+
L: 145,
|
|
405
558
|
S: this,
|
|
406
559
|
C: (f, a) => f(...a)
|
|
407
560
|
});
|
|
@@ -418,8 +571,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
418
571
|
log2("opening...", {
|
|
419
572
|
info: this.info
|
|
420
573
|
}, {
|
|
421
|
-
F:
|
|
422
|
-
L:
|
|
574
|
+
F: __dxlog_file4,
|
|
575
|
+
L: 158,
|
|
423
576
|
S: this,
|
|
424
577
|
C: (f, a) => f(...a)
|
|
425
578
|
});
|
|
@@ -427,8 +580,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
427
580
|
log2.warn("Error while opening connection", {
|
|
428
581
|
err
|
|
429
582
|
}, {
|
|
430
|
-
F:
|
|
431
|
-
L:
|
|
583
|
+
F: __dxlog_file4,
|
|
584
|
+
L: 160,
|
|
432
585
|
S: this,
|
|
433
586
|
C: (f, a) => f(...a)
|
|
434
587
|
});
|
|
@@ -441,8 +594,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
441
594
|
log2("closing...", {
|
|
442
595
|
peerKey: this._identity.peerKey
|
|
443
596
|
}, {
|
|
444
|
-
F:
|
|
445
|
-
L:
|
|
597
|
+
F: __dxlog_file4,
|
|
598
|
+
L: 168,
|
|
446
599
|
S: this,
|
|
447
600
|
C: (f, a) => f(...a)
|
|
448
601
|
});
|
|
@@ -458,8 +611,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
458
611
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
459
612
|
if (this._identity !== identity) {
|
|
460
613
|
log2("identity changed during auth header request", void 0, {
|
|
461
|
-
F:
|
|
462
|
-
L:
|
|
614
|
+
F: __dxlog_file4,
|
|
615
|
+
L: 182,
|
|
463
616
|
S: this,
|
|
464
617
|
C: (f, a) => f(...a)
|
|
465
618
|
});
|
|
@@ -471,8 +624,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
471
624
|
url: url.toString(),
|
|
472
625
|
protocolHeader
|
|
473
626
|
}, {
|
|
474
|
-
F:
|
|
475
|
-
L:
|
|
627
|
+
F: __dxlog_file4,
|
|
628
|
+
L: 188,
|
|
476
629
|
S: this,
|
|
477
630
|
C: (f, a) => f(...a)
|
|
478
631
|
});
|
|
@@ -486,8 +639,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
486
639
|
this._notifyReconnected();
|
|
487
640
|
} else {
|
|
488
641
|
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
489
|
-
F:
|
|
490
|
-
L:
|
|
642
|
+
F: __dxlog_file4,
|
|
643
|
+
L: 198,
|
|
491
644
|
S: this,
|
|
492
645
|
C: (f, a) => f(...a)
|
|
493
646
|
});
|
|
@@ -499,8 +652,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
499
652
|
void this._persistentLifecycle.scheduleRestart();
|
|
500
653
|
} else {
|
|
501
654
|
log2.verbose("restart requested by inactive connection", void 0, {
|
|
502
|
-
F:
|
|
503
|
-
L:
|
|
655
|
+
F: __dxlog_file4,
|
|
656
|
+
L: 206,
|
|
504
657
|
S: this,
|
|
505
658
|
C: (f, a) => f(...a)
|
|
506
659
|
});
|
|
@@ -515,8 +668,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
515
668
|
from: message.source,
|
|
516
669
|
type: message.payload?.typeUrl
|
|
517
670
|
}, {
|
|
518
|
-
F:
|
|
519
|
-
L:
|
|
671
|
+
F: __dxlog_file4,
|
|
672
|
+
L: 214,
|
|
520
673
|
S: this,
|
|
521
674
|
C: (f, a) => f(...a)
|
|
522
675
|
});
|
|
@@ -552,8 +705,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
552
705
|
log2.error("ws reconnect listener failed", {
|
|
553
706
|
err
|
|
554
707
|
}, {
|
|
555
|
-
F:
|
|
556
|
-
L:
|
|
708
|
+
F: __dxlog_file4,
|
|
709
|
+
L: 249,
|
|
557
710
|
S: this,
|
|
558
711
|
C: (f, a) => f(...a)
|
|
559
712
|
});
|
|
@@ -569,38 +722,14 @@ var EdgeClient = class extends Resource2 {
|
|
|
569
722
|
err,
|
|
570
723
|
payload: protocol.getPayloadType(message)
|
|
571
724
|
}, {
|
|
572
|
-
F:
|
|
573
|
-
L:
|
|
725
|
+
F: __dxlog_file4,
|
|
726
|
+
L: 259,
|
|
574
727
|
S: this,
|
|
575
728
|
C: (f, a) => f(...a)
|
|
576
729
|
});
|
|
577
730
|
}
|
|
578
731
|
}
|
|
579
732
|
}
|
|
580
|
-
/**
|
|
581
|
-
* Send message.
|
|
582
|
-
* NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.
|
|
583
|
-
*/
|
|
584
|
-
async send(message) {
|
|
585
|
-
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
586
|
-
log2("waiting for websocket to become ready", void 0, {
|
|
587
|
-
F: __dxlog_file3,
|
|
588
|
-
L: 246,
|
|
589
|
-
S: this,
|
|
590
|
-
C: (f, a) => f(...a)
|
|
591
|
-
});
|
|
592
|
-
await this._ready.wait({
|
|
593
|
-
timeout: this._config.timeout ?? DEFAULT_TIMEOUT
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
if (!this._currentConnection) {
|
|
597
|
-
throw new EdgeConnectionClosedError();
|
|
598
|
-
}
|
|
599
|
-
if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
|
|
600
|
-
throw new EdgeIdentityChangedError();
|
|
601
|
-
}
|
|
602
|
-
this._currentConnection.send(message);
|
|
603
|
-
}
|
|
604
733
|
async _createAuthHeader(path) {
|
|
605
734
|
const httpUrl = new URL(path, this._baseHttpUrl);
|
|
606
735
|
httpUrl.protocol = getEdgeUrlWithProtocol(this._baseWsUrl.toString(), "http");
|
|
@@ -614,7 +743,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
614
743
|
status: response.status,
|
|
615
744
|
statusText: response.statusText
|
|
616
745
|
}, {
|
|
617
|
-
F:
|
|
746
|
+
F: __dxlog_file4,
|
|
618
747
|
L: 271,
|
|
619
748
|
S: this,
|
|
620
749
|
C: (f, a) => f(...a)
|
|
@@ -622,6 +751,14 @@ var EdgeClient = class extends Resource2 {
|
|
|
622
751
|
return void 0;
|
|
623
752
|
}
|
|
624
753
|
}
|
|
754
|
+
constructor(_identity, _config) {
|
|
755
|
+
super(), _define_property2(this, "_identity", void 0), _define_property2(this, "_config", void 0), _define_property2(this, "statusChanged", void 0), _define_property2(this, "_persistentLifecycle", void 0), _define_property2(this, "_messageListeners", void 0), _define_property2(this, "_reconnectListeners", void 0), _define_property2(this, "_baseWsUrl", void 0), _define_property2(this, "_baseHttpUrl", void 0), _define_property2(this, "_currentConnection", void 0), _define_property2(this, "_ready", void 0), _define_property2(this, "_isActive", void 0), this._identity = _identity, this._config = _config, this.statusChanged = new Event(), this._persistentLifecycle = new PersistentLifecycle({
|
|
756
|
+
start: async () => this._connect(),
|
|
757
|
+
stop: async (state) => this._disconnect(state)
|
|
758
|
+
}), this._messageListeners = /* @__PURE__ */ new Set(), this._reconnectListeners = /* @__PURE__ */ new Set(), this._currentConnection = void 0, this._ready = new Trigger(), this._isActive = (connection) => connection === this._currentConnection;
|
|
759
|
+
this._baseWsUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "ws");
|
|
760
|
+
this._baseHttpUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, "http");
|
|
761
|
+
}
|
|
625
762
|
};
|
|
626
763
|
_ts_decorate2([
|
|
627
764
|
logInfo2
|
|
@@ -631,117 +768,6 @@ var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
|
631
768
|
return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
|
|
632
769
|
};
|
|
633
770
|
|
|
634
|
-
// src/auth.ts
|
|
635
|
-
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
636
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
637
|
-
import { Keyring } from "@dxos/keyring";
|
|
638
|
-
import { PublicKey } from "@dxos/keys";
|
|
639
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
640
|
-
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
641
|
-
return {
|
|
642
|
-
identityKey: key.toHex(),
|
|
643
|
-
peerKey: key.toHex(),
|
|
644
|
-
presentCredentials: async ({ challenge }) => {
|
|
645
|
-
return signPresentation({
|
|
646
|
-
presentation: {
|
|
647
|
-
credentials: [
|
|
648
|
-
// Verifier requires at least one credential in the presentation to establish the subject.
|
|
649
|
-
await createCredential({
|
|
650
|
-
assertion: {
|
|
651
|
-
"@type": "dxos.halo.credentials.Auth"
|
|
652
|
-
},
|
|
653
|
-
issuer: key,
|
|
654
|
-
subject: key,
|
|
655
|
-
signer
|
|
656
|
-
})
|
|
657
|
-
]
|
|
658
|
-
},
|
|
659
|
-
signer,
|
|
660
|
-
signerKey: key,
|
|
661
|
-
nonce: challenge
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
};
|
|
666
|
-
var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, credentials) => {
|
|
667
|
-
const credentialsToSign = credentials.length > 0 ? credentials : [
|
|
668
|
-
await createCredential({
|
|
669
|
-
assertion: {
|
|
670
|
-
"@type": "dxos.halo.credentials.Auth"
|
|
671
|
-
},
|
|
672
|
-
issuer: identityKey,
|
|
673
|
-
subject: identityKey,
|
|
674
|
-
signer,
|
|
675
|
-
chain,
|
|
676
|
-
signingKey: peerKey
|
|
677
|
-
})
|
|
678
|
-
];
|
|
679
|
-
return {
|
|
680
|
-
identityKey: identityKey.toHex(),
|
|
681
|
-
peerKey: peerKey.toHex(),
|
|
682
|
-
presentCredentials: async ({ challenge }) => {
|
|
683
|
-
invariant3(chain, void 0, {
|
|
684
|
-
F: __dxlog_file4,
|
|
685
|
-
L: 75,
|
|
686
|
-
S: void 0,
|
|
687
|
-
A: [
|
|
688
|
-
"chain",
|
|
689
|
-
""
|
|
690
|
-
]
|
|
691
|
-
});
|
|
692
|
-
return signPresentation({
|
|
693
|
-
presentation: {
|
|
694
|
-
credentials: credentialsToSign
|
|
695
|
-
},
|
|
696
|
-
signer,
|
|
697
|
-
nonce: challenge,
|
|
698
|
-
signerKey: peerKey,
|
|
699
|
-
chain
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
};
|
|
704
|
-
var createEphemeralEdgeIdentity = async () => {
|
|
705
|
-
const keyring = new Keyring();
|
|
706
|
-
const key = await keyring.createKey();
|
|
707
|
-
return createDeviceEdgeIdentity(keyring, key);
|
|
708
|
-
};
|
|
709
|
-
var createTestHaloEdgeIdentity = async (signer, identityKey, deviceKey) => {
|
|
710
|
-
const deviceAdmission = await createCredential({
|
|
711
|
-
assertion: {
|
|
712
|
-
"@type": "dxos.halo.credentials.AuthorizedDevice",
|
|
713
|
-
deviceKey,
|
|
714
|
-
identityKey
|
|
715
|
-
},
|
|
716
|
-
issuer: identityKey,
|
|
717
|
-
subject: deviceKey,
|
|
718
|
-
signer
|
|
719
|
-
});
|
|
720
|
-
return createChainEdgeIdentity(signer, identityKey, deviceKey, {
|
|
721
|
-
credential: deviceAdmission
|
|
722
|
-
}, [
|
|
723
|
-
await createCredential({
|
|
724
|
-
assertion: {
|
|
725
|
-
"@type": "dxos.halo.credentials.Auth"
|
|
726
|
-
},
|
|
727
|
-
issuer: identityKey,
|
|
728
|
-
subject: identityKey,
|
|
729
|
-
signer
|
|
730
|
-
})
|
|
731
|
-
]);
|
|
732
|
-
};
|
|
733
|
-
var createStubEdgeIdentity = () => {
|
|
734
|
-
const identityKey = PublicKey.random();
|
|
735
|
-
const deviceKey = PublicKey.random();
|
|
736
|
-
return {
|
|
737
|
-
identityKey: identityKey.toHex(),
|
|
738
|
-
peerKey: deviceKey.toHex(),
|
|
739
|
-
presentCredentials: async () => {
|
|
740
|
-
throw new Error("Stub identity does not support authentication.");
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
};
|
|
744
|
-
|
|
745
771
|
// src/edge-http-client.ts
|
|
746
772
|
import { FetchHttpClient, HttpClient } from "@effect/platform";
|
|
747
773
|
import { Effect as Effect2, pipe } from "effect";
|
|
@@ -754,16 +780,28 @@ import { createUrl } from "@dxos/util";
|
|
|
754
780
|
// src/http-client.ts
|
|
755
781
|
import { Context as Context2, Duration, Effect, Layer, Schedule } from "effect";
|
|
756
782
|
import { log as log3 } from "@dxos/log";
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
783
|
+
function _define_property3(obj, key, value) {
|
|
784
|
+
if (key in obj) {
|
|
785
|
+
Object.defineProperty(obj, key, {
|
|
786
|
+
value,
|
|
787
|
+
enumerable: true,
|
|
788
|
+
configurable: true,
|
|
789
|
+
writable: true
|
|
764
790
|
});
|
|
791
|
+
} else {
|
|
792
|
+
obj[key] = value;
|
|
765
793
|
}
|
|
794
|
+
return obj;
|
|
795
|
+
}
|
|
796
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
|
|
797
|
+
var _Context_Tag;
|
|
798
|
+
var HttpConfig = class extends (_Context_Tag = Context2.Tag("HttpConfig")()) {
|
|
766
799
|
};
|
|
800
|
+
_define_property3(HttpConfig, "default", Layer.succeed(HttpConfig, {
|
|
801
|
+
timeout: Duration.millis(1e3),
|
|
802
|
+
retryTimes: 3,
|
|
803
|
+
retryBaseDelay: Duration.millis(1e3)
|
|
804
|
+
}));
|
|
767
805
|
var withRetry = (effect, { timeout = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
|
|
768
806
|
return effect.pipe(Effect.flatMap((res) => (
|
|
769
807
|
// Treat 500 errors as retryable?
|
|
@@ -791,22 +829,25 @@ var encodeAuthHeader = (challenge) => {
|
|
|
791
829
|
};
|
|
792
830
|
|
|
793
831
|
// src/edge-http-client.ts
|
|
832
|
+
function _define_property4(obj, key, value) {
|
|
833
|
+
if (key in obj) {
|
|
834
|
+
Object.defineProperty(obj, key, {
|
|
835
|
+
value,
|
|
836
|
+
enumerable: true,
|
|
837
|
+
configurable: true,
|
|
838
|
+
writable: true
|
|
839
|
+
});
|
|
840
|
+
} else {
|
|
841
|
+
obj[key] = value;
|
|
842
|
+
}
|
|
843
|
+
return obj;
|
|
844
|
+
}
|
|
794
845
|
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
795
846
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
796
847
|
var DEFAULT_RETRY_JITTER = 500;
|
|
797
848
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
849
|
+
var WARNING_BODY_SIZE = 10 * 1024 * 1024;
|
|
798
850
|
var EdgeHttpClient = class {
|
|
799
|
-
constructor(baseUrl) {
|
|
800
|
-
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
801
|
-
log4("created", {
|
|
802
|
-
url: this._baseUrl
|
|
803
|
-
}, {
|
|
804
|
-
F: __dxlog_file6,
|
|
805
|
-
L: 84,
|
|
806
|
-
S: this,
|
|
807
|
-
C: (f, a) => f(...a)
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
851
|
get baseUrl() {
|
|
811
852
|
return this._baseUrl;
|
|
812
853
|
}
|
|
@@ -880,12 +921,6 @@ var EdgeHttpClient = class {
|
|
|
880
921
|
//
|
|
881
922
|
// OAuth and credentials
|
|
882
923
|
//
|
|
883
|
-
async listFunctions(args) {
|
|
884
|
-
return this._call(new URL("/functions", this.baseUrl), {
|
|
885
|
-
...args,
|
|
886
|
-
method: "GET"
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
924
|
async initiateOAuthFlow(body, args) {
|
|
890
925
|
return this._call(new URL("/oauth/initiate", this.baseUrl), {
|
|
891
926
|
...args,
|
|
@@ -940,6 +975,18 @@ var EdgeHttpClient = class {
|
|
|
940
975
|
// Functions
|
|
941
976
|
//
|
|
942
977
|
async uploadFunction(pathParts, body, args) {
|
|
978
|
+
const formData = new FormData();
|
|
979
|
+
formData.append("name", body.name ?? "");
|
|
980
|
+
formData.append("version", body.version);
|
|
981
|
+
formData.append("ownerPublicKey", body.ownerPublicKey);
|
|
982
|
+
formData.append("entryPoint", body.entryPoint);
|
|
983
|
+
for (const [filename, content] of Object.entries(body.assets)) {
|
|
984
|
+
formData.append("assets", new Blob([
|
|
985
|
+
content
|
|
986
|
+
], {
|
|
987
|
+
type: getFileMimeType(filename)
|
|
988
|
+
}), filename);
|
|
989
|
+
}
|
|
943
990
|
const path = [
|
|
944
991
|
"functions",
|
|
945
992
|
...pathParts.functionId ? [
|
|
@@ -948,8 +995,36 @@ var EdgeHttpClient = class {
|
|
|
948
995
|
].join("/");
|
|
949
996
|
return this._call(new URL(path, this.baseUrl), {
|
|
950
997
|
...args,
|
|
951
|
-
body,
|
|
952
|
-
method: "PUT"
|
|
998
|
+
body: formData,
|
|
999
|
+
method: "PUT",
|
|
1000
|
+
json: false
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
async listFunctions(args) {
|
|
1004
|
+
return this._call(new URL("/functions", this.baseUrl), {
|
|
1005
|
+
...args,
|
|
1006
|
+
method: "GET"
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
async invokeFunction(params, input, args) {
|
|
1010
|
+
const url = new URL(`/functions/${params.functionId}`, this.baseUrl);
|
|
1011
|
+
if (params.version) {
|
|
1012
|
+
url.searchParams.set("version", params.version);
|
|
1013
|
+
}
|
|
1014
|
+
if (params.spaceId) {
|
|
1015
|
+
url.searchParams.set("spaceId", params.spaceId.toString());
|
|
1016
|
+
}
|
|
1017
|
+
if (params.cpuTimeLimit) {
|
|
1018
|
+
url.searchParams.set("cpuTimeLimit", params.cpuTimeLimit.toString());
|
|
1019
|
+
}
|
|
1020
|
+
if (params.subrequestsLimit) {
|
|
1021
|
+
url.searchParams.set("subrequestsLimit", params.subrequestsLimit.toString());
|
|
1022
|
+
}
|
|
1023
|
+
return this._call(url, {
|
|
1024
|
+
...args,
|
|
1025
|
+
body: input,
|
|
1026
|
+
method: "POST",
|
|
1027
|
+
rawResponse: true
|
|
953
1028
|
});
|
|
954
1029
|
}
|
|
955
1030
|
//
|
|
@@ -963,6 +1038,31 @@ var EdgeHttpClient = class {
|
|
|
963
1038
|
});
|
|
964
1039
|
}
|
|
965
1040
|
//
|
|
1041
|
+
// Triggers
|
|
1042
|
+
//
|
|
1043
|
+
async getCronTriggers(spaceId) {
|
|
1044
|
+
return this._call(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), {
|
|
1045
|
+
method: "GET"
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
//
|
|
1049
|
+
// Import/Export space.
|
|
1050
|
+
//
|
|
1051
|
+
async importBundle(spaceId, body, args) {
|
|
1052
|
+
return this._call(new URL(`/spaces/${spaceId}/import`, this.baseUrl), {
|
|
1053
|
+
...args,
|
|
1054
|
+
body,
|
|
1055
|
+
method: "PUT"
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
async exportBundle(spaceId, body, args) {
|
|
1059
|
+
return this._call(new URL(`/spaces/${spaceId}/export`, this.baseUrl), {
|
|
1060
|
+
...args,
|
|
1061
|
+
body,
|
|
1062
|
+
method: "POST"
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
//
|
|
966
1066
|
// Internal
|
|
967
1067
|
//
|
|
968
1068
|
async _fetch(url, args) {
|
|
@@ -973,20 +1073,20 @@ var EdgeHttpClient = class {
|
|
|
973
1073
|
const shouldRetry = createRetryHandler(args);
|
|
974
1074
|
const requestContext = args.context ?? new Context3(void 0, {
|
|
975
1075
|
F: __dxlog_file6,
|
|
976
|
-
L:
|
|
1076
|
+
L: 389
|
|
977
1077
|
});
|
|
978
1078
|
log4("fetch", {
|
|
979
1079
|
url,
|
|
980
1080
|
request: args.body
|
|
981
1081
|
}, {
|
|
982
1082
|
F: __dxlog_file6,
|
|
983
|
-
L:
|
|
1083
|
+
L: 390,
|
|
984
1084
|
S: this,
|
|
985
1085
|
C: (f, a) => f(...a)
|
|
986
1086
|
});
|
|
987
1087
|
let handledAuth = false;
|
|
988
1088
|
while (true) {
|
|
989
|
-
let processingError;
|
|
1089
|
+
let processingError = void 0;
|
|
990
1090
|
let retryAfterHeaderValue = Number.NaN;
|
|
991
1091
|
try {
|
|
992
1092
|
const request = createRequest(args, this._authHeader);
|
|
@@ -994,6 +1094,12 @@ var EdgeHttpClient = class {
|
|
|
994
1094
|
retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
|
|
995
1095
|
if (response.ok) {
|
|
996
1096
|
const body = await response.json();
|
|
1097
|
+
if (args.rawResponse) {
|
|
1098
|
+
return body;
|
|
1099
|
+
}
|
|
1100
|
+
if (!("success" in body)) {
|
|
1101
|
+
return body;
|
|
1102
|
+
}
|
|
997
1103
|
if (body.success) {
|
|
998
1104
|
return body.data;
|
|
999
1105
|
}
|
|
@@ -1002,13 +1108,13 @@ var EdgeHttpClient = class {
|
|
|
1002
1108
|
body
|
|
1003
1109
|
}, {
|
|
1004
1110
|
F: __dxlog_file6,
|
|
1005
|
-
L:
|
|
1111
|
+
L: 415,
|
|
1006
1112
|
S: this,
|
|
1007
1113
|
C: (f, a) => f(...a)
|
|
1008
1114
|
});
|
|
1009
1115
|
if (body.errorData?.type === "auth_challenge" && typeof body.errorData?.challenge === "string") {
|
|
1010
1116
|
processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
|
|
1011
|
-
} else {
|
|
1117
|
+
} else if (body.errorData) {
|
|
1012
1118
|
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
1013
1119
|
}
|
|
1014
1120
|
} else if (response.status === 401 && !handledAuth) {
|
|
@@ -1016,18 +1122,18 @@ var EdgeHttpClient = class {
|
|
|
1016
1122
|
handledAuth = true;
|
|
1017
1123
|
continue;
|
|
1018
1124
|
} else {
|
|
1019
|
-
processingError = EdgeCallFailedError.fromHttpFailure(response);
|
|
1125
|
+
processingError = await EdgeCallFailedError.fromHttpFailure(response);
|
|
1020
1126
|
}
|
|
1021
1127
|
} catch (error) {
|
|
1022
1128
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
1023
1129
|
}
|
|
1024
|
-
if (processingError
|
|
1130
|
+
if (processingError?.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
1025
1131
|
log4("retrying edge request", {
|
|
1026
1132
|
url,
|
|
1027
1133
|
processingError
|
|
1028
1134
|
}, {
|
|
1029
1135
|
F: __dxlog_file6,
|
|
1030
|
-
L:
|
|
1136
|
+
L: 433,
|
|
1031
1137
|
S: this,
|
|
1032
1138
|
C: (f, a) => f(...a)
|
|
1033
1139
|
});
|
|
@@ -1040,23 +1146,56 @@ var EdgeHttpClient = class {
|
|
|
1040
1146
|
if (!this._edgeIdentity) {
|
|
1041
1147
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1042
1148
|
F: __dxlog_file6,
|
|
1043
|
-
L:
|
|
1149
|
+
L: 442,
|
|
1044
1150
|
S: this,
|
|
1045
1151
|
C: (f, a) => f(...a)
|
|
1046
1152
|
});
|
|
1047
|
-
throw EdgeCallFailedError.fromHttpFailure(response);
|
|
1153
|
+
throw await EdgeCallFailedError.fromHttpFailure(response);
|
|
1048
1154
|
}
|
|
1049
1155
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
1050
1156
|
return encodeAuthHeader(challenge);
|
|
1051
1157
|
}
|
|
1158
|
+
constructor(baseUrl) {
|
|
1159
|
+
_define_property4(this, "_baseUrl", void 0);
|
|
1160
|
+
_define_property4(this, "_edgeIdentity", void 0);
|
|
1161
|
+
_define_property4(this, "_authHeader", void 0);
|
|
1162
|
+
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
1163
|
+
log4("created", {
|
|
1164
|
+
url: this._baseUrl
|
|
1165
|
+
}, {
|
|
1166
|
+
F: __dxlog_file6,
|
|
1167
|
+
L: 97,
|
|
1168
|
+
S: this,
|
|
1169
|
+
C: (f, a) => f(...a)
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1052
1172
|
};
|
|
1053
|
-
var createRequest = ({ method, body }, authHeader) => {
|
|
1173
|
+
var createRequest = ({ method, body, json = true }, authHeader) => {
|
|
1174
|
+
let requestBody;
|
|
1175
|
+
const headers = {};
|
|
1176
|
+
if (json) {
|
|
1177
|
+
requestBody = body && JSON.stringify(body);
|
|
1178
|
+
headers["Content-Type"] = "application/json";
|
|
1179
|
+
} else {
|
|
1180
|
+
requestBody = body;
|
|
1181
|
+
}
|
|
1182
|
+
if (typeof requestBody === "string" && requestBody.length > WARNING_BODY_SIZE) {
|
|
1183
|
+
log4.warn("Request with large body", {
|
|
1184
|
+
bodySize: requestBody.length
|
|
1185
|
+
}, {
|
|
1186
|
+
F: __dxlog_file6,
|
|
1187
|
+
L: 466,
|
|
1188
|
+
S: void 0,
|
|
1189
|
+
C: (f, a) => f(...a)
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1192
|
+
if (authHeader) {
|
|
1193
|
+
headers["Authorization"] = authHeader;
|
|
1194
|
+
}
|
|
1054
1195
|
return {
|
|
1055
1196
|
method,
|
|
1056
|
-
body:
|
|
1057
|
-
headers
|
|
1058
|
-
Authorization: authHeader
|
|
1059
|
-
} : void 0
|
|
1197
|
+
body: requestBody,
|
|
1198
|
+
headers
|
|
1060
1199
|
};
|
|
1061
1200
|
};
|
|
1062
1201
|
var createRetryHandler = ({ retry }) => {
|
|
@@ -1080,6 +1219,10 @@ var createRetryHandler = ({ retry }) => {
|
|
|
1080
1219
|
return true;
|
|
1081
1220
|
};
|
|
1082
1221
|
};
|
|
1222
|
+
var getFileMimeType = (filename) => [
|
|
1223
|
+
".js",
|
|
1224
|
+
".mjs"
|
|
1225
|
+
].some((codeExtension) => filename.endsWith(codeExtension)) ? "application/javascript+module" : filename.endsWith(".wasm") ? "application/wasm" : "application/octet-stream";
|
|
1083
1226
|
export {
|
|
1084
1227
|
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1085
1228
|
CLOUDFLARE_RPC_MAX_BYTES,
|
|
@@ -1087,6 +1230,7 @@ export {
|
|
|
1087
1230
|
EdgeConnectionClosedError,
|
|
1088
1231
|
EdgeHttpClient,
|
|
1089
1232
|
EdgeIdentityChangedError,
|
|
1233
|
+
HttpConfig,
|
|
1090
1234
|
Protocol,
|
|
1091
1235
|
WebSocketMuxer,
|
|
1092
1236
|
createChainEdgeIdentity,
|
|
@@ -1094,9 +1238,13 @@ export {
|
|
|
1094
1238
|
createEphemeralEdgeIdentity,
|
|
1095
1239
|
createStubEdgeIdentity,
|
|
1096
1240
|
createTestHaloEdgeIdentity,
|
|
1241
|
+
encodeAuthHeader,
|
|
1097
1242
|
getTypename,
|
|
1098
1243
|
handleAuthChallenge,
|
|
1099
1244
|
protocol,
|
|
1100
|
-
toUint8Array
|
|
1245
|
+
toUint8Array,
|
|
1246
|
+
withLogging,
|
|
1247
|
+
withRetry,
|
|
1248
|
+
withRetryConfig
|
|
1101
1249
|
};
|
|
1102
1250
|
//# sourceMappingURL=index.mjs.map
|