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