@dxos/client-services 0.5.8-next.4b7fabd → 0.5.9-main.07b4bad
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-ACQUT3OK.mjs → chunk-XYEJP6PO.mjs} +1164 -1136
- package/dist/lib/browser/chunk-XYEJP6PO.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +55 -363
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +4 -4
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-IBTSMFQY.cjs → chunk-2NELYJUC.cjs} +1159 -1131
- package/dist/lib/node/chunk-2NELYJUC.cjs.map +7 -0
- package/dist/lib/node/index.cjs +93 -396
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +10 -10
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/index.d.ts +3 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts +4 -4
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +2 -2
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +4 -5
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +2 -0
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +3 -3
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/index.d.ts +3 -0
- package/dist/types/src/packlets/worker/index.d.ts.map +1 -0
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -0
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -0
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +36 -36
- package/src/index.ts +3 -3
- package/src/packlets/devtools/network.ts +4 -4
- package/src/packlets/identity/identity-manager.test.ts +2 -2
- package/src/packlets/identity/identity.test.ts +8 -4
- package/src/packlets/invitations/invitations-handler.ts +2 -2
- package/src/packlets/network/network-service.ts +2 -2
- package/src/packlets/services/service-context.ts +3 -3
- package/src/packlets/services/service-host.ts +6 -7
- package/src/packlets/spaces/data-space.ts +25 -1
- package/src/packlets/spaces/spaces-service.ts +3 -2
- package/src/packlets/testing/test-builder.ts +4 -4
- package/src/packlets/worker/index.ts +6 -0
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-ACQUT3OK.mjs.map +0 -7
- package/dist/lib/node/chunk-IBTSMFQY.cjs.map +0 -7
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +0 -37
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/index.d.ts +0 -6
- package/dist/types/src/packlets/vault/index.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/shared-worker-connection.d.ts +0 -36
- package/dist/types/src/packlets/vault/shared-worker-connection.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/shell-runtime.d.ts +0 -33
- package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/worker-session.d.ts.map +0 -1
- package/src/packlets/vault/iframe-host-runtime.ts +0 -130
- package/src/packlets/vault/index.ts +0 -9
- package/src/packlets/vault/shared-worker-connection.ts +0 -115
- package/src/packlets/vault/shell-runtime.ts +0 -111
- /package/dist/types/src/packlets/{vault → worker}/worker-runtime.d.ts +0 -0
- /package/dist/types/src/packlets/{vault → worker}/worker-session.d.ts +0 -0
- /package/src/packlets/{vault → worker}/worker-runtime.ts +0 -0
- /package/src/packlets/{vault → worker}/worker-session.ts +0 -0
|
@@ -345,13 +345,349 @@ var DevtoolsServiceImpl = class {
|
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
347
|
|
|
348
|
-
// packages/sdk/client-services/src/packlets/
|
|
348
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
|
|
349
|
+
import { asyncTimeout } from "@dxos/async";
|
|
350
|
+
import { getFirstStreamValue } from "@dxos/codec-protobuf";
|
|
351
|
+
import { credentialTypeFilter } from "@dxos/credentials";
|
|
352
|
+
import { invariant } from "@dxos/invariant";
|
|
353
|
+
import { STORAGE_VERSION } from "@dxos/protocols";
|
|
354
|
+
import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
|
|
355
|
+
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
356
|
+
|
|
357
|
+
// packages/sdk/client-services/src/version.ts
|
|
358
|
+
var DXOS_VERSION = "0.5.9-main.07b4bad";
|
|
359
|
+
|
|
360
|
+
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
361
|
+
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
362
|
+
var getPlatform = () => {
|
|
363
|
+
if (process.browser) {
|
|
364
|
+
if (typeof window !== "undefined") {
|
|
365
|
+
const { userAgent } = window.navigator;
|
|
366
|
+
return {
|
|
367
|
+
type: Platform.PLATFORM_TYPE.BROWSER,
|
|
368
|
+
userAgent,
|
|
369
|
+
uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
|
|
370
|
+
};
|
|
371
|
+
} else {
|
|
372
|
+
return {
|
|
373
|
+
type: Platform.PLATFORM_TYPE.SHARED_WORKER,
|
|
374
|
+
uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
const { platform: platform2, version, arch } = process;
|
|
379
|
+
return {
|
|
380
|
+
type: Platform.PLATFORM_TYPE.NODE,
|
|
381
|
+
platform: platform2,
|
|
382
|
+
arch,
|
|
383
|
+
runtime: version,
|
|
384
|
+
uptime: Math.floor(process.uptime()),
|
|
385
|
+
memory: process.memoryUsage()
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
|
|
391
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
|
|
392
|
+
var DEFAULT_TIMEOUT = 1e3;
|
|
393
|
+
var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
394
|
+
const diagnostics = {
|
|
395
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
396
|
+
platform: getPlatform(),
|
|
397
|
+
client: {
|
|
398
|
+
version: DXOS_VERSION,
|
|
399
|
+
storage: {
|
|
400
|
+
version: STORAGE_VERSION
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
trace: TRACE_PROCESSOR.getDiagnostics()
|
|
404
|
+
};
|
|
405
|
+
await Promise.all([
|
|
406
|
+
(async () => {
|
|
407
|
+
invariant(clientServices.LoggingService, "SystemService is not available.", {
|
|
408
|
+
F: __dxlog_file,
|
|
409
|
+
L: 110,
|
|
410
|
+
S: void 0,
|
|
411
|
+
A: [
|
|
412
|
+
"clientServices.LoggingService",
|
|
413
|
+
"'SystemService is not available.'"
|
|
414
|
+
]
|
|
415
|
+
});
|
|
416
|
+
diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
|
|
417
|
+
timeout: DEFAULT_TIMEOUT
|
|
418
|
+
}).catch(() => void 0);
|
|
419
|
+
})(),
|
|
420
|
+
(async () => {
|
|
421
|
+
diagnostics.storage = await asyncTimeout(getStorageDiagnostics(), DEFAULT_TIMEOUT).catch(() => void 0);
|
|
422
|
+
})(),
|
|
423
|
+
async () => {
|
|
424
|
+
const identity = serviceContext.identityManager.identity;
|
|
425
|
+
if (identity) {
|
|
426
|
+
diagnostics.identity = {
|
|
427
|
+
identityKey: identity.identityKey,
|
|
428
|
+
spaceKey: identity.space.key,
|
|
429
|
+
profile: identity.profileDocument
|
|
430
|
+
};
|
|
431
|
+
const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
|
|
432
|
+
timeout: DEFAULT_TIMEOUT
|
|
433
|
+
}).catch(() => void 0) ?? {};
|
|
434
|
+
diagnostics.devices = devices;
|
|
435
|
+
if (serviceContext.dataSpaceManager) {
|
|
436
|
+
diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
|
|
437
|
+
}
|
|
438
|
+
const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
|
|
439
|
+
timeout: DEFAULT_TIMEOUT
|
|
440
|
+
}).catch(() => void 0) ?? {};
|
|
441
|
+
diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
|
|
442
|
+
feedKey,
|
|
443
|
+
bytes,
|
|
444
|
+
length
|
|
445
|
+
}));
|
|
446
|
+
const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
|
|
447
|
+
timeout: DEFAULT_TIMEOUT
|
|
448
|
+
}).catch(() => void 0);
|
|
449
|
+
diagnostics.networkStatus = status;
|
|
450
|
+
diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
]);
|
|
454
|
+
diagnostics.config = config.values;
|
|
455
|
+
return diagnostics;
|
|
456
|
+
};
|
|
457
|
+
var getSpaceStats = async (space) => {
|
|
458
|
+
const stats = {
|
|
459
|
+
key: space.key,
|
|
460
|
+
metrics: space.metrics,
|
|
461
|
+
epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
|
|
462
|
+
...credential.subject.assertion,
|
|
463
|
+
id: credential.id
|
|
464
|
+
})),
|
|
465
|
+
members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
|
|
466
|
+
role: member.role,
|
|
467
|
+
identity: {
|
|
468
|
+
identityKey: member.key,
|
|
469
|
+
profile: {
|
|
470
|
+
displayName: member.assertion.profile?.displayName
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
|
|
474
|
+
})),
|
|
475
|
+
pipeline: {
|
|
476
|
+
// TODO(burdon): Pick properties from credentials if needed.
|
|
477
|
+
currentEpoch: space.automergeSpaceState.lastEpoch,
|
|
478
|
+
appliedEpoch: space.automergeSpaceState.lastEpoch,
|
|
479
|
+
controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
|
|
480
|
+
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
481
|
+
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
482
|
+
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
if (stats.metrics) {
|
|
486
|
+
const { open, ready } = stats.metrics;
|
|
487
|
+
stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
|
|
488
|
+
}
|
|
489
|
+
return stats;
|
|
490
|
+
};
|
|
491
|
+
var getStorageDiagnostics = async () => {
|
|
492
|
+
if (typeof navigator === "undefined" || !navigator.storage) {
|
|
493
|
+
return void 0;
|
|
494
|
+
}
|
|
495
|
+
const map = /* @__PURE__ */ new Map();
|
|
496
|
+
const dir = await navigator.storage.getDirectory();
|
|
497
|
+
for await (const filename of dir?.keys()) {
|
|
498
|
+
const idx = filename.indexOf("-", filename.indexOf("-") + 1);
|
|
499
|
+
if (idx === -1) {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
|
|
503
|
+
}
|
|
504
|
+
return Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
|
|
505
|
+
file,
|
|
506
|
+
count
|
|
507
|
+
}));
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
|
|
349
511
|
import { Trigger } from "@dxos/async";
|
|
512
|
+
import { log } from "@dxos/log";
|
|
513
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
|
|
514
|
+
var CHANNEL_NAME = "dxos.diagnostics.broadcast";
|
|
515
|
+
var MessageType;
|
|
516
|
+
(function(MessageType2) {
|
|
517
|
+
MessageType2["PROBE"] = "probe";
|
|
518
|
+
MessageType2["PROBE_ACK"] = "probe-ack";
|
|
519
|
+
MessageType2["REQUEST_DIAGNOSTICS"] = "request-diagnostics";
|
|
520
|
+
MessageType2["RECEIVE_DIAGNOSTICS"] = "receive-diagnostics";
|
|
521
|
+
})(MessageType || (MessageType = {}));
|
|
522
|
+
var createCollectDiagnosticsBroadcastSender = () => {
|
|
523
|
+
return {
|
|
524
|
+
broadcastDiagnosticsRequest: async () => {
|
|
525
|
+
let expectedResponse = "probe-ack";
|
|
526
|
+
let channel;
|
|
527
|
+
try {
|
|
528
|
+
const trigger = new Trigger();
|
|
529
|
+
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
530
|
+
channel.onmessage = (msg) => {
|
|
531
|
+
if (expectedResponse === msg.data.type) {
|
|
532
|
+
trigger.wake(msg.data);
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
channel.postMessage({
|
|
536
|
+
type: "probe"
|
|
537
|
+
});
|
|
538
|
+
await trigger.wait({
|
|
539
|
+
timeout: 200
|
|
540
|
+
});
|
|
541
|
+
expectedResponse = "receive-diagnostics";
|
|
542
|
+
trigger.reset();
|
|
543
|
+
channel.postMessage({
|
|
544
|
+
type: "request-diagnostics"
|
|
545
|
+
});
|
|
546
|
+
const diagnostics = await trigger.wait({
|
|
547
|
+
timeout: 5e3
|
|
548
|
+
});
|
|
549
|
+
return diagnostics.payload;
|
|
550
|
+
} catch (e) {
|
|
551
|
+
const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
|
|
552
|
+
return {
|
|
553
|
+
expectedResponse,
|
|
554
|
+
errorDescription
|
|
555
|
+
};
|
|
556
|
+
} finally {
|
|
557
|
+
safeClose(channel);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
};
|
|
562
|
+
var createCollectDiagnosticsBroadcastHandler = (systemService) => {
|
|
563
|
+
let channel;
|
|
564
|
+
return {
|
|
565
|
+
start: () => {
|
|
566
|
+
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
567
|
+
channel.onmessage = async (message) => {
|
|
568
|
+
try {
|
|
569
|
+
if (message.data.type === "probe") {
|
|
570
|
+
channel?.postMessage({
|
|
571
|
+
type: "probe-ack"
|
|
572
|
+
});
|
|
573
|
+
} else if (message.data.type === "request-diagnostics") {
|
|
574
|
+
const diagnostics = await systemService.getDiagnostics({});
|
|
575
|
+
channel?.postMessage({
|
|
576
|
+
type: "receive-diagnostics",
|
|
577
|
+
payload: diagnostics
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
} catch (error) {
|
|
581
|
+
log.catch(error, void 0, {
|
|
582
|
+
F: __dxlog_file2,
|
|
583
|
+
L: 77,
|
|
584
|
+
S: void 0,
|
|
585
|
+
C: (f, a) => f(...a)
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
stop: () => {
|
|
591
|
+
safeClose(channel);
|
|
592
|
+
channel = void 0;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
};
|
|
596
|
+
var safeClose = (channel) => {
|
|
597
|
+
try {
|
|
598
|
+
channel?.close();
|
|
599
|
+
} catch (e) {
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
604
|
+
import { Stream as Stream7 } from "@dxos/codec-protobuf";
|
|
605
|
+
import { raise } from "@dxos/debug";
|
|
606
|
+
import { parseMethodName, RpcPeer } from "@dxos/rpc";
|
|
607
|
+
import { MapCounter, trace } from "@dxos/tracing";
|
|
608
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
609
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
610
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
611
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
612
|
+
else
|
|
613
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
614
|
+
if (d = decorators[i])
|
|
615
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
616
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
617
|
+
}
|
|
618
|
+
var ClientRpcServer = class {
|
|
619
|
+
constructor(params) {
|
|
620
|
+
this._handlerCache = /* @__PURE__ */ new Map();
|
|
621
|
+
this._callMetrics = new MapCounter();
|
|
622
|
+
const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
|
|
623
|
+
this._handleCall = handleCall;
|
|
624
|
+
this._handleStream = handleStream;
|
|
625
|
+
this._serviceRegistry = serviceRegistry;
|
|
626
|
+
this._rpcPeer = new RpcPeer({
|
|
627
|
+
...rpcOptions,
|
|
628
|
+
callHandler: (method, params2) => {
|
|
629
|
+
const [serviceName, methodName] = parseMethodName(method);
|
|
630
|
+
const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
|
|
631
|
+
this._callMetrics.inc(`${serviceName}.${methodName} request`);
|
|
632
|
+
if (this._handleCall) {
|
|
633
|
+
return this._handleCall(methodName, params2, handler);
|
|
634
|
+
} else {
|
|
635
|
+
return handler(methodName, params2);
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
streamHandler: (method, params2) => {
|
|
639
|
+
const [serviceName, methodName] = parseMethodName(method);
|
|
640
|
+
const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
|
|
641
|
+
this._callMetrics.inc(`${serviceName}.${methodName} request stream`);
|
|
642
|
+
if (this._handleStream) {
|
|
643
|
+
return Stream7.map(Stream7.unwrapPromise(this._handleStream(methodName, params2, handler)), (data) => {
|
|
644
|
+
this._callMetrics.inc(`${serviceName}.${methodName} response stream`);
|
|
645
|
+
return data;
|
|
646
|
+
});
|
|
647
|
+
} else {
|
|
648
|
+
return handler(methodName, params2);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
get _services() {
|
|
654
|
+
return Object.keys(this._serviceRegistry.services);
|
|
655
|
+
}
|
|
656
|
+
async open() {
|
|
657
|
+
await this._rpcPeer.open();
|
|
658
|
+
}
|
|
659
|
+
async close() {
|
|
660
|
+
await this._rpcPeer.close();
|
|
661
|
+
}
|
|
662
|
+
_getServiceHandler(serviceName) {
|
|
663
|
+
if (!this._handlerCache.has(serviceName)) {
|
|
664
|
+
const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
|
|
665
|
+
const service = this._serviceRegistry.services[key];
|
|
666
|
+
if (!service) {
|
|
667
|
+
throw new Error(`Service not available: ${serviceName}`);
|
|
668
|
+
}
|
|
669
|
+
this._handlerCache.set(serviceName, descriptor.createServer(service));
|
|
670
|
+
}
|
|
671
|
+
return this._handlerCache.get(serviceName);
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
_ts_decorate([
|
|
675
|
+
trace.metricsCounter()
|
|
676
|
+
], ClientRpcServer.prototype, "_callMetrics", void 0);
|
|
677
|
+
_ts_decorate([
|
|
678
|
+
trace.info()
|
|
679
|
+
], ClientRpcServer.prototype, "_services", null);
|
|
680
|
+
ClientRpcServer = _ts_decorate([
|
|
681
|
+
trace.resource()
|
|
682
|
+
], ClientRpcServer);
|
|
683
|
+
|
|
684
|
+
// packages/sdk/client-services/src/packlets/identity/authenticator.ts
|
|
685
|
+
import { Trigger as Trigger2 } from "@dxos/async";
|
|
350
686
|
import { Context as Context2 } from "@dxos/context";
|
|
351
687
|
import { verifyCredential } from "@dxos/credentials";
|
|
352
|
-
import { log } from "@dxos/log";
|
|
688
|
+
import { log as log2 } from "@dxos/log";
|
|
353
689
|
import { schema } from "@dxos/protocols";
|
|
354
|
-
var
|
|
690
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
|
|
355
691
|
var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
|
|
356
692
|
var createAuthProvider = (signer) => async (nonce) => {
|
|
357
693
|
const credential = await signer.createCredential({
|
|
@@ -374,20 +710,20 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
374
710
|
get verifier() {
|
|
375
711
|
return async (nonce, auth) => {
|
|
376
712
|
const credential = Credential.decode(auth);
|
|
377
|
-
|
|
713
|
+
log2("authenticating...", {
|
|
378
714
|
credential
|
|
379
715
|
}, {
|
|
380
|
-
F:
|
|
716
|
+
F: __dxlog_file3,
|
|
381
717
|
L: 56,
|
|
382
718
|
S: this,
|
|
383
719
|
C: (f, a) => f(...a)
|
|
384
720
|
});
|
|
385
721
|
const result = await verifyCredential(credential);
|
|
386
722
|
if (result.kind === "fail") {
|
|
387
|
-
|
|
723
|
+
log2("Invalid credential", {
|
|
388
724
|
result
|
|
389
725
|
}, {
|
|
390
|
-
F:
|
|
726
|
+
F: __dxlog_file3,
|
|
391
727
|
L: 60,
|
|
392
728
|
S: this,
|
|
393
729
|
C: (f, a) => f(...a)
|
|
@@ -395,11 +731,11 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
395
731
|
return false;
|
|
396
732
|
}
|
|
397
733
|
if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
|
|
398
|
-
|
|
734
|
+
log2("Invalid nonce", {
|
|
399
735
|
nonce,
|
|
400
736
|
credential
|
|
401
737
|
}, {
|
|
402
|
-
F:
|
|
738
|
+
F: __dxlog_file3,
|
|
403
739
|
L: 65,
|
|
404
740
|
S: this,
|
|
405
741
|
C: (f, a) => f(...a)
|
|
@@ -407,36 +743,36 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
407
743
|
return false;
|
|
408
744
|
}
|
|
409
745
|
if (this._isTrustedKey(credential.issuer)) {
|
|
410
|
-
|
|
746
|
+
log2("key is not currently in trusted set, waiting...", {
|
|
411
747
|
key: credential.issuer
|
|
412
748
|
}, {
|
|
413
|
-
F:
|
|
749
|
+
F: __dxlog_file3,
|
|
414
750
|
L: 70,
|
|
415
751
|
S: this,
|
|
416
752
|
C: (f, a) => f(...a)
|
|
417
753
|
});
|
|
418
754
|
return true;
|
|
419
755
|
}
|
|
420
|
-
const trigger = new
|
|
756
|
+
const trigger = new Trigger2();
|
|
421
757
|
this._ctx.onDispose(() => {
|
|
422
758
|
trigger.wake(false);
|
|
423
759
|
});
|
|
424
760
|
const clear = this._params.update.on(this._ctx, () => {
|
|
425
761
|
if (this._isTrustedKey(credential.issuer)) {
|
|
426
|
-
|
|
762
|
+
log2("auth success", {
|
|
427
763
|
key: credential.issuer
|
|
428
764
|
}, {
|
|
429
|
-
F:
|
|
765
|
+
F: __dxlog_file3,
|
|
430
766
|
L: 81,
|
|
431
767
|
S: this,
|
|
432
768
|
C: (f, a) => f(...a)
|
|
433
769
|
});
|
|
434
770
|
trigger.wake(true);
|
|
435
771
|
} else {
|
|
436
|
-
|
|
772
|
+
log2("key is not currently in trusted set, waiting...", {
|
|
437
773
|
key: credential.issuer
|
|
438
774
|
}, {
|
|
439
|
-
F:
|
|
775
|
+
F: __dxlog_file3,
|
|
440
776
|
L: 84,
|
|
441
777
|
S: this,
|
|
442
778
|
C: (f, a) => f(...a)
|
|
@@ -465,13 +801,13 @@ import { Event } from "@dxos/async";
|
|
|
465
801
|
import { AUTH_TIMEOUT, LOAD_CONTROL_FEEDS_TIMEOUT } from "@dxos/client-protocol";
|
|
466
802
|
import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSignerWithChain, ProfileStateMachine } from "@dxos/credentials";
|
|
467
803
|
import { writeMessages } from "@dxos/feed-store";
|
|
468
|
-
import { invariant } from "@dxos/invariant";
|
|
804
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
469
805
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
470
|
-
import { log as
|
|
806
|
+
import { log as log3 } from "@dxos/log";
|
|
471
807
|
import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
472
|
-
import { trace } from "@dxos/tracing";
|
|
808
|
+
import { trace as trace2 } from "@dxos/tracing";
|
|
473
809
|
import { ComplexSet } from "@dxos/util";
|
|
474
|
-
function
|
|
810
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
475
811
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
476
812
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
477
813
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -481,7 +817,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
481
817
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
482
818
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
483
819
|
}
|
|
484
|
-
var
|
|
820
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
|
|
485
821
|
var Identity = class {
|
|
486
822
|
constructor({ space, signer, identityKey, deviceKey, presence }) {
|
|
487
823
|
this.stateUpdate = new Event();
|
|
@@ -490,10 +826,10 @@ var Identity = class {
|
|
|
490
826
|
this._presence = presence;
|
|
491
827
|
this.identityKey = identityKey;
|
|
492
828
|
this.deviceKey = deviceKey;
|
|
493
|
-
|
|
829
|
+
log3.trace("dxos.halo.device", {
|
|
494
830
|
deviceKey
|
|
495
831
|
}, {
|
|
496
|
-
F:
|
|
832
|
+
F: __dxlog_file4,
|
|
497
833
|
L: 67,
|
|
498
834
|
S: this,
|
|
499
835
|
C: (f, a) => f(...a)
|
|
@@ -561,8 +897,8 @@ var Identity = class {
|
|
|
561
897
|
* Requires identity to be ready.
|
|
562
898
|
*/
|
|
563
899
|
getIdentityCredentialSigner() {
|
|
564
|
-
|
|
565
|
-
F:
|
|
900
|
+
invariant2(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
|
|
901
|
+
F: __dxlog_file4,
|
|
566
902
|
L: 145,
|
|
567
903
|
S: this,
|
|
568
904
|
A: [
|
|
@@ -579,14 +915,14 @@ var Identity = class {
|
|
|
579
915
|
return createCredentialSignerWithKey(this._signer, this.deviceKey);
|
|
580
916
|
}
|
|
581
917
|
async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
|
|
582
|
-
|
|
918
|
+
log3("Admitting device:", {
|
|
583
919
|
identityKey: this.identityKey,
|
|
584
920
|
hostDevice: this.deviceKey,
|
|
585
921
|
deviceKey,
|
|
586
922
|
controlFeedKey,
|
|
587
923
|
dataFeedKey
|
|
588
924
|
}, {
|
|
589
|
-
F:
|
|
925
|
+
F: __dxlog_file4,
|
|
590
926
|
L: 161,
|
|
591
927
|
S: this,
|
|
592
928
|
C: (f, a) => f(...a)
|
|
@@ -628,14 +964,14 @@ var Identity = class {
|
|
|
628
964
|
})));
|
|
629
965
|
}
|
|
630
966
|
};
|
|
631
|
-
|
|
632
|
-
|
|
967
|
+
_ts_decorate2([
|
|
968
|
+
trace2.span()
|
|
633
969
|
], Identity.prototype, "open", null);
|
|
634
|
-
|
|
635
|
-
|
|
970
|
+
_ts_decorate2([
|
|
971
|
+
trace2.span()
|
|
636
972
|
], Identity.prototype, "close", null);
|
|
637
|
-
Identity =
|
|
638
|
-
|
|
973
|
+
Identity = _ts_decorate2([
|
|
974
|
+
trace2.resource()
|
|
639
975
|
], Identity);
|
|
640
976
|
|
|
641
977
|
// packages/sdk/client-services/src/packlets/identity/identity-manager.ts
|
|
@@ -643,17 +979,17 @@ import platform from "platform";
|
|
|
643
979
|
import { Event as Event2 } from "@dxos/async";
|
|
644
980
|
import { Context as Context3 } from "@dxos/context";
|
|
645
981
|
import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
|
|
646
|
-
import { invariant as
|
|
982
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
647
983
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
648
|
-
import { log as
|
|
649
|
-
import { trace as
|
|
984
|
+
import { log as log4 } from "@dxos/log";
|
|
985
|
+
import { trace as trace3 } from "@dxos/protocols";
|
|
650
986
|
import { Device, DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
|
|
651
987
|
import { AdmittedFeed as AdmittedFeed2, DeviceType } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
652
988
|
import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
|
|
653
989
|
import { Timeframe } from "@dxos/timeframe";
|
|
654
990
|
import { trace as Trace } from "@dxos/tracing";
|
|
655
991
|
import { isNode, deferFunction } from "@dxos/util";
|
|
656
|
-
function
|
|
992
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
657
993
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
658
994
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
659
995
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -663,7 +999,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
663
999
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
664
1000
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
665
1001
|
}
|
|
666
|
-
var
|
|
1002
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
|
|
667
1003
|
var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
668
1004
|
var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
669
1005
|
var IdentityManager = class {
|
|
@@ -684,19 +1020,19 @@ var IdentityManager = class {
|
|
|
684
1020
|
}
|
|
685
1021
|
async open(ctx) {
|
|
686
1022
|
const traceId = PublicKey4.random().toHex();
|
|
687
|
-
|
|
1023
|
+
log4.trace("dxos.halo.identity-manager.open", trace3.begin({
|
|
688
1024
|
id: traceId
|
|
689
1025
|
}), {
|
|
690
|
-
F:
|
|
1026
|
+
F: __dxlog_file5,
|
|
691
1027
|
L: 104,
|
|
692
1028
|
S: this,
|
|
693
1029
|
C: (f, a) => f(...a)
|
|
694
1030
|
});
|
|
695
1031
|
const identityRecord = this._metadataStore.getIdentityRecord();
|
|
696
|
-
|
|
1032
|
+
log4("identity record", {
|
|
697
1033
|
identityRecord
|
|
698
1034
|
}, {
|
|
699
|
-
F:
|
|
1035
|
+
F: __dxlog_file5,
|
|
700
1036
|
L: 107,
|
|
701
1037
|
S: this,
|
|
702
1038
|
C: (f, a) => f(...a)
|
|
@@ -705,21 +1041,21 @@ var IdentityManager = class {
|
|
|
705
1041
|
this._identity = await this._constructIdentity(identityRecord);
|
|
706
1042
|
await this._identity.open(ctx);
|
|
707
1043
|
await this._identity.ready();
|
|
708
|
-
|
|
1044
|
+
log4.trace("dxos.halo.identity", {
|
|
709
1045
|
identityKey: identityRecord.identityKey,
|
|
710
1046
|
displayName: this._identity.profileDocument?.displayName
|
|
711
1047
|
}, {
|
|
712
|
-
F:
|
|
1048
|
+
F: __dxlog_file5,
|
|
713
1049
|
L: 112,
|
|
714
1050
|
S: this,
|
|
715
1051
|
C: (f, a) => f(...a)
|
|
716
1052
|
});
|
|
717
1053
|
this.stateUpdate.emit();
|
|
718
1054
|
}
|
|
719
|
-
|
|
1055
|
+
log4.trace("dxos.halo.identity-manager.open", trace3.end({
|
|
720
1056
|
id: traceId
|
|
721
1057
|
}), {
|
|
722
|
-
F:
|
|
1058
|
+
F: __dxlog_file5,
|
|
723
1059
|
L: 119,
|
|
724
1060
|
S: this,
|
|
725
1061
|
C: (f, a) => f(...a)
|
|
@@ -729,8 +1065,8 @@ var IdentityManager = class {
|
|
|
729
1065
|
await this._identity?.close(new Context3());
|
|
730
1066
|
}
|
|
731
1067
|
async createIdentity({ displayName, deviceProfile } = {}) {
|
|
732
|
-
|
|
733
|
-
F:
|
|
1068
|
+
invariant3(!this._identity, "Identity already exists.", {
|
|
1069
|
+
F: __dxlog_file5,
|
|
734
1070
|
L: 128,
|
|
735
1071
|
S: this,
|
|
736
1072
|
A: [
|
|
@@ -738,8 +1074,8 @@ var IdentityManager = class {
|
|
|
738
1074
|
"'Identity already exists.'"
|
|
739
1075
|
]
|
|
740
1076
|
});
|
|
741
|
-
|
|
742
|
-
F:
|
|
1077
|
+
log4("creating identity...", void 0, {
|
|
1078
|
+
F: __dxlog_file5,
|
|
743
1079
|
L: 129,
|
|
744
1080
|
S: this,
|
|
745
1081
|
C: (f, a) => f(...a)
|
|
@@ -759,8 +1095,8 @@ var IdentityManager = class {
|
|
|
759
1095
|
await identity.open(new Context3());
|
|
760
1096
|
{
|
|
761
1097
|
const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
|
|
762
|
-
|
|
763
|
-
F:
|
|
1098
|
+
invariant3(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
|
|
1099
|
+
F: __dxlog_file5,
|
|
764
1100
|
L: 148,
|
|
765
1101
|
S: this,
|
|
766
1102
|
A: [
|
|
@@ -768,8 +1104,8 @@ var IdentityManager = class {
|
|
|
768
1104
|
"'Genesis feed key is required.'"
|
|
769
1105
|
]
|
|
770
1106
|
});
|
|
771
|
-
|
|
772
|
-
F:
|
|
1107
|
+
invariant3(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
|
|
1108
|
+
F: __dxlog_file5,
|
|
773
1109
|
L: 149,
|
|
774
1110
|
S: this,
|
|
775
1111
|
A: [
|
|
@@ -804,22 +1140,22 @@ var IdentityManager = class {
|
|
|
804
1140
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
805
1141
|
this._identity = identity;
|
|
806
1142
|
await this._identity.ready();
|
|
807
|
-
|
|
1143
|
+
log4.trace("dxos.halo.identity", {
|
|
808
1144
|
identityKey: identityRecord.identityKey,
|
|
809
1145
|
displayName: this._identity.profileDocument?.displayName
|
|
810
1146
|
}, {
|
|
811
|
-
F:
|
|
1147
|
+
F: __dxlog_file5,
|
|
812
1148
|
L: 191,
|
|
813
1149
|
S: this,
|
|
814
1150
|
C: (f, a) => f(...a)
|
|
815
1151
|
});
|
|
816
1152
|
this.stateUpdate.emit();
|
|
817
|
-
|
|
1153
|
+
log4("created identity", {
|
|
818
1154
|
identityKey: identity.identityKey,
|
|
819
1155
|
deviceKey: identity.deviceKey,
|
|
820
1156
|
profile: identity.profileDocument
|
|
821
1157
|
}, {
|
|
822
|
-
F:
|
|
1158
|
+
F: __dxlog_file5,
|
|
823
1159
|
L: 197,
|
|
824
1160
|
S: this,
|
|
825
1161
|
C: (f, a) => f(...a)
|
|
@@ -853,16 +1189,16 @@ var IdentityManager = class {
|
|
|
853
1189
|
* Accept an existing identity. Expects its device key to be authorized (now or later).
|
|
854
1190
|
*/
|
|
855
1191
|
async acceptIdentity(params) {
|
|
856
|
-
|
|
1192
|
+
log4("accepting identity", {
|
|
857
1193
|
params
|
|
858
1194
|
}, {
|
|
859
|
-
F:
|
|
1195
|
+
F: __dxlog_file5,
|
|
860
1196
|
L: 235,
|
|
861
1197
|
S: this,
|
|
862
1198
|
C: (f, a) => f(...a)
|
|
863
1199
|
});
|
|
864
|
-
|
|
865
|
-
F:
|
|
1200
|
+
invariant3(!this._identity, "Identity already exists.", {
|
|
1201
|
+
F: __dxlog_file5,
|
|
866
1202
|
L: 236,
|
|
867
1203
|
S: this,
|
|
868
1204
|
A: [
|
|
@@ -886,11 +1222,11 @@ var IdentityManager = class {
|
|
|
886
1222
|
this._identity = identity;
|
|
887
1223
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
888
1224
|
await this._identity.ready();
|
|
889
|
-
|
|
1225
|
+
log4.trace("dxos.halo.identity", {
|
|
890
1226
|
identityKey: identityRecord.identityKey,
|
|
891
1227
|
displayName: this._identity.profileDocument?.displayName
|
|
892
1228
|
}, {
|
|
893
|
-
F:
|
|
1229
|
+
F: __dxlog_file5,
|
|
894
1230
|
L: 255,
|
|
895
1231
|
S: this,
|
|
896
1232
|
C: (f, a) => f(...a)
|
|
@@ -900,11 +1236,11 @@ var IdentityManager = class {
|
|
|
900
1236
|
...params.deviceProfile
|
|
901
1237
|
});
|
|
902
1238
|
this.stateUpdate.emit();
|
|
903
|
-
|
|
1239
|
+
log4("accepted identity", {
|
|
904
1240
|
identityKey: identity.identityKey,
|
|
905
1241
|
deviceKey: identity.deviceKey
|
|
906
1242
|
}, {
|
|
907
|
-
F:
|
|
1243
|
+
F: __dxlog_file5,
|
|
908
1244
|
L: 265,
|
|
909
1245
|
S: this,
|
|
910
1246
|
C: (f, a) => f(...a)
|
|
@@ -915,8 +1251,8 @@ var IdentityManager = class {
|
|
|
915
1251
|
* Update the profile document of an existing identity.
|
|
916
1252
|
*/
|
|
917
1253
|
async updateProfile(profile) {
|
|
918
|
-
|
|
919
|
-
F:
|
|
1254
|
+
invariant3(this._identity, "Identity not initialized.", {
|
|
1255
|
+
F: __dxlog_file5,
|
|
920
1256
|
L: 273,
|
|
921
1257
|
S: this,
|
|
922
1258
|
A: [
|
|
@@ -946,8 +1282,8 @@ var IdentityManager = class {
|
|
|
946
1282
|
return profile;
|
|
947
1283
|
}
|
|
948
1284
|
async updateDeviceProfile(profile) {
|
|
949
|
-
|
|
950
|
-
F:
|
|
1285
|
+
invariant3(this._identity, "Identity not initialized.", {
|
|
1286
|
+
F: __dxlog_file5,
|
|
951
1287
|
L: 290,
|
|
952
1288
|
S: this,
|
|
953
1289
|
A: [
|
|
@@ -982,8 +1318,8 @@ var IdentityManager = class {
|
|
|
982
1318
|
};
|
|
983
1319
|
}
|
|
984
1320
|
async _constructIdentity(identityRecord) {
|
|
985
|
-
|
|
986
|
-
F:
|
|
1321
|
+
invariant3(!this._identity, void 0, {
|
|
1322
|
+
F: __dxlog_file5,
|
|
987
1323
|
L: 316,
|
|
988
1324
|
S: this,
|
|
989
1325
|
A: [
|
|
@@ -991,10 +1327,10 @@ var IdentityManager = class {
|
|
|
991
1327
|
""
|
|
992
1328
|
]
|
|
993
1329
|
});
|
|
994
|
-
|
|
1330
|
+
log4("constructing identity", {
|
|
995
1331
|
identityRecord
|
|
996
1332
|
}, {
|
|
997
|
-
F:
|
|
1333
|
+
F: __dxlog_file5,
|
|
998
1334
|
L: 317,
|
|
999
1335
|
S: this,
|
|
1000
1336
|
C: (f, a) => f(...a)
|
|
@@ -1008,8 +1344,8 @@ var IdentityManager = class {
|
|
|
1008
1344
|
identityKey: identityRecord.deviceKey,
|
|
1009
1345
|
gossip
|
|
1010
1346
|
});
|
|
1011
|
-
|
|
1012
|
-
F:
|
|
1347
|
+
invariant3(identityRecord.haloSpace.controlFeedKey, void 0, {
|
|
1348
|
+
F: __dxlog_file5,
|
|
1013
1349
|
L: 330,
|
|
1014
1350
|
S: this,
|
|
1015
1351
|
A: [
|
|
@@ -1020,8 +1356,8 @@ var IdentityManager = class {
|
|
|
1020
1356
|
const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
|
|
1021
1357
|
writable: true
|
|
1022
1358
|
});
|
|
1023
|
-
|
|
1024
|
-
F:
|
|
1359
|
+
invariant3(identityRecord.haloSpace.dataFeedKey, void 0, {
|
|
1360
|
+
F: __dxlog_file5,
|
|
1025
1361
|
L: 334,
|
|
1026
1362
|
S: this,
|
|
1027
1363
|
A: [
|
|
@@ -1052,10 +1388,10 @@ var IdentityManager = class {
|
|
|
1052
1388
|
identityKey: identityRecord.identityKey,
|
|
1053
1389
|
deviceKey: identityRecord.deviceKey
|
|
1054
1390
|
});
|
|
1055
|
-
|
|
1391
|
+
log4("done", {
|
|
1056
1392
|
identityKey: identityRecord.identityKey
|
|
1057
1393
|
}, {
|
|
1058
|
-
F:
|
|
1394
|
+
F: __dxlog_file5,
|
|
1059
1395
|
L: 360,
|
|
1060
1396
|
S: this,
|
|
1061
1397
|
C: (f, a) => f(...a)
|
|
@@ -1079,8 +1415,8 @@ var IdentityManager = class {
|
|
|
1079
1415
|
}));
|
|
1080
1416
|
},
|
|
1081
1417
|
onAuthFailure: () => {
|
|
1082
|
-
|
|
1083
|
-
F:
|
|
1418
|
+
log4.warn("auth failure", void 0, {
|
|
1419
|
+
F: __dxlog_file5,
|
|
1084
1420
|
L: 385,
|
|
1085
1421
|
S: this,
|
|
1086
1422
|
C: (f, a) => f(...a)
|
|
@@ -1094,21 +1430,21 @@ var IdentityManager = class {
|
|
|
1094
1430
|
});
|
|
1095
1431
|
}
|
|
1096
1432
|
};
|
|
1097
|
-
|
|
1433
|
+
_ts_decorate3([
|
|
1098
1434
|
Trace.span({
|
|
1099
1435
|
showInBrowserTimeline: true
|
|
1100
1436
|
})
|
|
1101
1437
|
], IdentityManager.prototype, "open", null);
|
|
1102
|
-
IdentityManager =
|
|
1438
|
+
IdentityManager = _ts_decorate3([
|
|
1103
1439
|
Trace.resource()
|
|
1104
1440
|
], IdentityManager);
|
|
1105
1441
|
|
|
1106
1442
|
// packages/sdk/client-services/src/packlets/identity/identity-service.ts
|
|
1107
|
-
import { Stream as
|
|
1443
|
+
import { Stream as Stream8 } from "@dxos/codec-protobuf";
|
|
1108
1444
|
import { signPresentation } from "@dxos/credentials";
|
|
1109
1445
|
import { todo } from "@dxos/debug";
|
|
1110
|
-
import { invariant as
|
|
1111
|
-
var
|
|
1446
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1447
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
|
|
1112
1448
|
var IdentityServiceImpl = class {
|
|
1113
1449
|
constructor(_createIdentity, _identityManager, _keyring, _onProfileUpdate) {
|
|
1114
1450
|
this._createIdentity = _createIdentity;
|
|
@@ -1127,7 +1463,7 @@ var IdentityServiceImpl = class {
|
|
|
1127
1463
|
return todo();
|
|
1128
1464
|
}
|
|
1129
1465
|
queryIdentity() {
|
|
1130
|
-
return new
|
|
1466
|
+
return new Stream8(({ next }) => {
|
|
1131
1467
|
const emitNext = () => next({
|
|
1132
1468
|
identity: this._getIdentity()
|
|
1133
1469
|
});
|
|
@@ -1146,8 +1482,8 @@ var IdentityServiceImpl = class {
|
|
|
1146
1482
|
};
|
|
1147
1483
|
}
|
|
1148
1484
|
async updateProfile(profile) {
|
|
1149
|
-
|
|
1150
|
-
F:
|
|
1485
|
+
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1486
|
+
F: __dxlog_file6,
|
|
1151
1487
|
L: 61,
|
|
1152
1488
|
S: this,
|
|
1153
1489
|
A: [
|
|
@@ -1160,8 +1496,8 @@ var IdentityServiceImpl = class {
|
|
|
1160
1496
|
return this._getIdentity();
|
|
1161
1497
|
}
|
|
1162
1498
|
async signPresentation({ presentation, nonce }) {
|
|
1163
|
-
|
|
1164
|
-
F:
|
|
1499
|
+
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1500
|
+
F: __dxlog_file6,
|
|
1165
1501
|
L: 68,
|
|
1166
1502
|
S: this,
|
|
1167
1503
|
A: [
|
|
@@ -1180,10 +1516,10 @@ var IdentityServiceImpl = class {
|
|
|
1180
1516
|
};
|
|
1181
1517
|
|
|
1182
1518
|
// packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
|
|
1183
|
-
import { invariant as
|
|
1519
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1184
1520
|
import { AlreadyJoinedError } from "@dxos/protocols";
|
|
1185
1521
|
import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
|
|
1186
|
-
var
|
|
1522
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
|
|
1187
1523
|
var DeviceInvitationProtocol = class {
|
|
1188
1524
|
constructor(_keyring, _getIdentity, _acceptIdentity) {
|
|
1189
1525
|
this._keyring = _keyring;
|
|
@@ -1208,8 +1544,8 @@ var DeviceInvitationProtocol = class {
|
|
|
1208
1544
|
throw new Error("delegation not supported");
|
|
1209
1545
|
}
|
|
1210
1546
|
async admit(_, request) {
|
|
1211
|
-
|
|
1212
|
-
F:
|
|
1547
|
+
invariant5(request.device, void 0, {
|
|
1548
|
+
F: __dxlog_file7,
|
|
1213
1549
|
L: 50,
|
|
1214
1550
|
S: this,
|
|
1215
1551
|
A: [
|
|
@@ -1254,8 +1590,8 @@ var DeviceInvitationProtocol = class {
|
|
|
1254
1590
|
};
|
|
1255
1591
|
}
|
|
1256
1592
|
async accept(response, request) {
|
|
1257
|
-
|
|
1258
|
-
F:
|
|
1593
|
+
invariant5(response.device, void 0, {
|
|
1594
|
+
F: __dxlog_file7,
|
|
1259
1595
|
L: 95,
|
|
1260
1596
|
S: this,
|
|
1261
1597
|
A: [
|
|
@@ -1264,8 +1600,8 @@ var DeviceInvitationProtocol = class {
|
|
|
1264
1600
|
]
|
|
1265
1601
|
});
|
|
1266
1602
|
const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
|
|
1267
|
-
|
|
1268
|
-
F:
|
|
1603
|
+
invariant5(request.device, void 0, {
|
|
1604
|
+
F: __dxlog_file7,
|
|
1269
1605
|
L: 98,
|
|
1270
1606
|
S: this,
|
|
1271
1607
|
A: [
|
|
@@ -1295,21 +1631,21 @@ import { Mutex, scheduleTask as scheduleTask3, TimeoutError } from "@dxos/async"
|
|
|
1295
1631
|
import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
|
|
1296
1632
|
import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
|
|
1297
1633
|
import { createKeyPair, sign } from "@dxos/crypto";
|
|
1298
|
-
import { invariant as
|
|
1634
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1299
1635
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1300
|
-
import { log as
|
|
1636
|
+
import { log as log8 } from "@dxos/log";
|
|
1301
1637
|
import { createTeleportProtocolFactory } from "@dxos/network-manager";
|
|
1302
|
-
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as
|
|
1638
|
+
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
|
|
1303
1639
|
import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1304
1640
|
import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1305
1641
|
import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1306
1642
|
import { ComplexSet as ComplexSet3 } from "@dxos/util";
|
|
1307
1643
|
|
|
1308
1644
|
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1309
|
-
import { Trigger as
|
|
1645
|
+
import { Trigger as Trigger3 } from "@dxos/async";
|
|
1310
1646
|
import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
|
|
1311
|
-
import { invariant as
|
|
1312
|
-
import { log as
|
|
1647
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1648
|
+
import { log as log5 } from "@dxos/log";
|
|
1313
1649
|
import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
|
|
1314
1650
|
import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1315
1651
|
import { RpcExtension } from "@dxos/teleport";
|
|
@@ -1334,7 +1670,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
|
|
|
1334
1670
|
};
|
|
1335
1671
|
|
|
1336
1672
|
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1337
|
-
var
|
|
1673
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
|
|
1338
1674
|
var OPTIONS_TIMEOUT = 1e4;
|
|
1339
1675
|
var InvitationGuestExtension = class extends RpcExtension {
|
|
1340
1676
|
constructor(_invitationFlowMutex, _callbacks) {
|
|
@@ -1349,7 +1685,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1349
1685
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1350
1686
|
this._callbacks = _callbacks;
|
|
1351
1687
|
this._ctx = new Context4();
|
|
1352
|
-
this._remoteOptionsTrigger = new
|
|
1688
|
+
this._remoteOptionsTrigger = new Trigger3();
|
|
1353
1689
|
this._invitationFlowLock = null;
|
|
1354
1690
|
}
|
|
1355
1691
|
hasFlowLock() {
|
|
@@ -1359,8 +1695,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1359
1695
|
return {
|
|
1360
1696
|
InvitationHostService: {
|
|
1361
1697
|
options: async (options) => {
|
|
1362
|
-
|
|
1363
|
-
F:
|
|
1698
|
+
invariant6(!this._remoteOptions, "Remote options already set.", {
|
|
1699
|
+
F: __dxlog_file8,
|
|
1364
1700
|
L: 63,
|
|
1365
1701
|
S: this,
|
|
1366
1702
|
A: [
|
|
@@ -1386,15 +1722,15 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1386
1722
|
async onOpen(context) {
|
|
1387
1723
|
await super.onOpen(context);
|
|
1388
1724
|
try {
|
|
1389
|
-
|
|
1390
|
-
F:
|
|
1725
|
+
log5("guest acquire lock", void 0, {
|
|
1726
|
+
F: __dxlog_file8,
|
|
1391
1727
|
L: 84,
|
|
1392
1728
|
S: this,
|
|
1393
1729
|
C: (f, a) => f(...a)
|
|
1394
1730
|
});
|
|
1395
1731
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1396
|
-
|
|
1397
|
-
F:
|
|
1732
|
+
log5("guest lock acquired", void 0, {
|
|
1733
|
+
F: __dxlog_file8,
|
|
1398
1734
|
L: 86,
|
|
1399
1735
|
S: this,
|
|
1400
1736
|
C: (f, a) => f(...a)
|
|
@@ -1402,8 +1738,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1402
1738
|
await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
|
|
1403
1739
|
role: Options.Role.GUEST
|
|
1404
1740
|
}));
|
|
1405
|
-
|
|
1406
|
-
F:
|
|
1741
|
+
log5("options sent", void 0, {
|
|
1742
|
+
F: __dxlog_file8,
|
|
1407
1743
|
L: 88,
|
|
1408
1744
|
S: this,
|
|
1409
1745
|
C: (f, a) => f(...a)
|
|
@@ -1411,8 +1747,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1411
1747
|
await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1412
1748
|
timeout: OPTIONS_TIMEOUT
|
|
1413
1749
|
}));
|
|
1414
|
-
|
|
1415
|
-
F:
|
|
1750
|
+
log5("options received", void 0, {
|
|
1751
|
+
F: __dxlog_file8,
|
|
1416
1752
|
L: 90,
|
|
1417
1753
|
S: this,
|
|
1418
1754
|
C: (f, a) => f(...a)
|
|
@@ -1445,8 +1781,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1445
1781
|
if (this._invitationFlowLock != null) {
|
|
1446
1782
|
this._invitationFlowLock.release();
|
|
1447
1783
|
this._invitationFlowLock = null;
|
|
1448
|
-
|
|
1449
|
-
F:
|
|
1784
|
+
log5("invitation flow lock released", void 0, {
|
|
1785
|
+
F: __dxlog_file8,
|
|
1450
1786
|
L: 123,
|
|
1451
1787
|
S: this,
|
|
1452
1788
|
C: (f, a) => f(...a)
|
|
@@ -1456,17 +1792,17 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1456
1792
|
};
|
|
1457
1793
|
|
|
1458
1794
|
// packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
|
|
1459
|
-
import { Trigger as
|
|
1795
|
+
import { Trigger as Trigger4, scheduleTask as scheduleTask2 } from "@dxos/async";
|
|
1460
1796
|
import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
|
|
1461
1797
|
import { randomBytes, verify } from "@dxos/crypto";
|
|
1462
|
-
import { invariant as
|
|
1798
|
+
import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
|
|
1463
1799
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1464
|
-
import { log as
|
|
1465
|
-
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as
|
|
1800
|
+
import { log as log6 } from "@dxos/log";
|
|
1801
|
+
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
|
|
1466
1802
|
import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1467
1803
|
import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1468
1804
|
import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
|
|
1469
|
-
var
|
|
1805
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
|
|
1470
1806
|
var OPTIONS_TIMEOUT2 = 1e4;
|
|
1471
1807
|
var MAX_OTP_ATTEMPTS = 3;
|
|
1472
1808
|
var InvitationHostExtension = class extends RpcExtension2 {
|
|
@@ -1482,12 +1818,12 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1482
1818
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1483
1819
|
this._callbacks = _callbacks;
|
|
1484
1820
|
this._ctx = new Context5();
|
|
1485
|
-
this._remoteOptionsTrigger = new
|
|
1821
|
+
this._remoteOptionsTrigger = new Trigger4();
|
|
1486
1822
|
this._challenge = void 0;
|
|
1487
1823
|
this.guestProfile = void 0;
|
|
1488
1824
|
this.authenticationPassed = false;
|
|
1489
1825
|
this.authenticationRetry = 0;
|
|
1490
|
-
this.completedTrigger = new
|
|
1826
|
+
this.completedTrigger = new Trigger4();
|
|
1491
1827
|
this._invitationFlowLock = null;
|
|
1492
1828
|
}
|
|
1493
1829
|
hasFlowLock() {
|
|
@@ -1499,8 +1835,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1499
1835
|
// Perhaps in the future we will have more complex logic here.
|
|
1500
1836
|
InvitationHostService: {
|
|
1501
1837
|
options: async (options) => {
|
|
1502
|
-
|
|
1503
|
-
F:
|
|
1838
|
+
invariant7(!this._remoteOptions, "Remote options already set.", {
|
|
1839
|
+
F: __dxlog_file9,
|
|
1504
1840
|
L: 101,
|
|
1505
1841
|
S: this,
|
|
1506
1842
|
A: [
|
|
@@ -1514,10 +1850,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1514
1850
|
introduce: async (request) => {
|
|
1515
1851
|
const { profile, invitationId } = request;
|
|
1516
1852
|
const traceId = PublicKey5.random().toHex();
|
|
1517
|
-
|
|
1853
|
+
log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
|
|
1518
1854
|
id: traceId
|
|
1519
1855
|
}), {
|
|
1520
|
-
F:
|
|
1856
|
+
F: __dxlog_file9,
|
|
1521
1857
|
L: 110,
|
|
1522
1858
|
S: this,
|
|
1523
1859
|
C: (f, a) => f(...a)
|
|
@@ -1525,11 +1861,11 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1525
1861
|
const invitation = this._requireActiveInvitation();
|
|
1526
1862
|
this._assertInvitationState(Invitation3.State.CONNECTED);
|
|
1527
1863
|
if (invitationId !== invitation?.invitationId) {
|
|
1528
|
-
|
|
1864
|
+
log6.warn("incorrect invitationId", {
|
|
1529
1865
|
expected: invitation.invitationId,
|
|
1530
1866
|
actual: invitationId
|
|
1531
1867
|
}, {
|
|
1532
|
-
F:
|
|
1868
|
+
F: __dxlog_file9,
|
|
1533
1869
|
L: 116,
|
|
1534
1870
|
S: this,
|
|
1535
1871
|
C: (f, a) => f(...a)
|
|
@@ -1540,10 +1876,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1540
1876
|
authMethod: Invitation3.AuthMethod.NONE
|
|
1541
1877
|
};
|
|
1542
1878
|
}
|
|
1543
|
-
|
|
1879
|
+
log6("guest introduced themselves", {
|
|
1544
1880
|
guestProfile: profile
|
|
1545
1881
|
}, {
|
|
1546
|
-
F:
|
|
1882
|
+
F: __dxlog_file9,
|
|
1547
1883
|
L: 125,
|
|
1548
1884
|
S: this,
|
|
1549
1885
|
C: (f, a) => f(...a)
|
|
@@ -1551,10 +1887,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1551
1887
|
this.guestProfile = profile;
|
|
1552
1888
|
this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
|
|
1553
1889
|
this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
|
|
1554
|
-
|
|
1890
|
+
log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
|
|
1555
1891
|
id: traceId
|
|
1556
1892
|
}), {
|
|
1557
|
-
F:
|
|
1893
|
+
F: __dxlog_file9,
|
|
1558
1894
|
L: 132,
|
|
1559
1895
|
S: this,
|
|
1560
1896
|
C: (f, a) => f(...a)
|
|
@@ -1566,19 +1902,19 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1566
1902
|
},
|
|
1567
1903
|
authenticate: async ({ authCode: code, signedChallenge }) => {
|
|
1568
1904
|
const traceId = PublicKey5.random().toHex();
|
|
1569
|
-
|
|
1905
|
+
log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
|
|
1570
1906
|
id: traceId
|
|
1571
1907
|
}), {
|
|
1572
|
-
F:
|
|
1908
|
+
F: __dxlog_file9,
|
|
1573
1909
|
L: 141,
|
|
1574
1910
|
S: this,
|
|
1575
1911
|
C: (f, a) => f(...a)
|
|
1576
1912
|
});
|
|
1577
1913
|
const invitation = this._requireActiveInvitation();
|
|
1578
|
-
|
|
1914
|
+
log6("received authentication request", {
|
|
1579
1915
|
authCode: code
|
|
1580
1916
|
}, {
|
|
1581
|
-
F:
|
|
1917
|
+
F: __dxlog_file9,
|
|
1582
1918
|
L: 144,
|
|
1583
1919
|
S: this,
|
|
1584
1920
|
C: (f, a) => f(...a)
|
|
@@ -1591,8 +1927,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1591
1927
|
this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
|
|
1592
1928
|
switch (invitation.authMethod) {
|
|
1593
1929
|
case Invitation3.AuthMethod.NONE: {
|
|
1594
|
-
|
|
1595
|
-
F:
|
|
1930
|
+
log6("authentication not required", void 0, {
|
|
1931
|
+
F: __dxlog_file9,
|
|
1596
1932
|
L: 152,
|
|
1597
1933
|
S: this,
|
|
1598
1934
|
C: (f, a) => f(...a)
|
|
@@ -1627,10 +1963,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1627
1963
|
break;
|
|
1628
1964
|
}
|
|
1629
1965
|
default: {
|
|
1630
|
-
|
|
1966
|
+
log6.error("invalid authentication method", {
|
|
1631
1967
|
authMethod: invitation.authMethod
|
|
1632
1968
|
}, {
|
|
1633
|
-
F:
|
|
1969
|
+
F: __dxlog_file9,
|
|
1634
1970
|
L: 190,
|
|
1635
1971
|
S: this,
|
|
1636
1972
|
C: (f, a) => f(...a)
|
|
@@ -1649,13 +1985,13 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1649
1985
|
status
|
|
1650
1986
|
};
|
|
1651
1987
|
}
|
|
1652
|
-
|
|
1988
|
+
log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
|
|
1653
1989
|
id: traceId,
|
|
1654
1990
|
data: {
|
|
1655
1991
|
status
|
|
1656
1992
|
}
|
|
1657
1993
|
}), {
|
|
1658
|
-
F:
|
|
1994
|
+
F: __dxlog_file9,
|
|
1659
1995
|
L: 202,
|
|
1660
1996
|
S: this,
|
|
1661
1997
|
C: (f, a) => f(...a)
|
|
@@ -1666,10 +2002,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1666
2002
|
},
|
|
1667
2003
|
admit: async (request) => {
|
|
1668
2004
|
const traceId = PublicKey5.random().toHex();
|
|
1669
|
-
|
|
2005
|
+
log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
|
|
1670
2006
|
id: traceId
|
|
1671
2007
|
}), {
|
|
1672
|
-
F:
|
|
2008
|
+
F: __dxlog_file9,
|
|
1673
2009
|
L: 208,
|
|
1674
2010
|
S: this,
|
|
1675
2011
|
C: (f, a) => f(...a)
|
|
@@ -1683,10 +2019,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1683
2019
|
}
|
|
1684
2020
|
}
|
|
1685
2021
|
const response = await this._callbacks.admit(request);
|
|
1686
|
-
|
|
2022
|
+
log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
|
|
1687
2023
|
id: traceId
|
|
1688
2024
|
}), {
|
|
1689
|
-
F:
|
|
2025
|
+
F: __dxlog_file9,
|
|
1690
2026
|
L: 222,
|
|
1691
2027
|
S: this,
|
|
1692
2028
|
C: (f, a) => f(...a)
|
|
@@ -1703,15 +2039,15 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1703
2039
|
async onOpen(context) {
|
|
1704
2040
|
await super.onOpen(context);
|
|
1705
2041
|
try {
|
|
1706
|
-
|
|
1707
|
-
F:
|
|
2042
|
+
log6("host acquire lock", void 0, {
|
|
2043
|
+
F: __dxlog_file9,
|
|
1708
2044
|
L: 237,
|
|
1709
2045
|
S: this,
|
|
1710
2046
|
C: (f, a) => f(...a)
|
|
1711
2047
|
});
|
|
1712
2048
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1713
|
-
|
|
1714
|
-
F:
|
|
2049
|
+
log6("host lock acquired", void 0, {
|
|
2050
|
+
F: __dxlog_file9,
|
|
1715
2051
|
L: 239,
|
|
1716
2052
|
S: this,
|
|
1717
2053
|
C: (f, a) => f(...a)
|
|
@@ -1721,8 +2057,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1721
2057
|
await this.rpc.InvitationHostService.options({
|
|
1722
2058
|
role: Options2.Role.HOST
|
|
1723
2059
|
});
|
|
1724
|
-
|
|
1725
|
-
F:
|
|
2060
|
+
log6("options sent", void 0, {
|
|
2061
|
+
F: __dxlog_file9,
|
|
1726
2062
|
L: 243,
|
|
1727
2063
|
S: this,
|
|
1728
2064
|
C: (f, a) => f(...a)
|
|
@@ -1730,8 +2066,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1730
2066
|
await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1731
2067
|
timeout: OPTIONS_TIMEOUT2
|
|
1732
2068
|
}));
|
|
1733
|
-
|
|
1734
|
-
F:
|
|
2069
|
+
log6("options received", void 0, {
|
|
2070
|
+
F: __dxlog_file9,
|
|
1735
2071
|
L: 245,
|
|
1736
2072
|
S: this,
|
|
1737
2073
|
C: (f, a) => f(...a)
|
|
@@ -1784,8 +2120,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1784
2120
|
if (this._invitationFlowLock != null) {
|
|
1785
2121
|
this._invitationFlowLock?.release();
|
|
1786
2122
|
this._invitationFlowLock = null;
|
|
1787
|
-
|
|
1788
|
-
F:
|
|
2123
|
+
log6("invitation flow lock released", void 0, {
|
|
2124
|
+
F: __dxlog_file9,
|
|
1789
2125
|
L: 300,
|
|
1790
2126
|
S: this,
|
|
1791
2127
|
C: (f, a) => f(...a)
|
|
@@ -1796,20 +2132,20 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1796
2132
|
var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation3.AuthMethod.NONE;
|
|
1797
2133
|
|
|
1798
2134
|
// packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
|
|
1799
|
-
import { invariant as
|
|
2135
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1800
2136
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1801
|
-
import { log as
|
|
2137
|
+
import { log as log7 } from "@dxos/log";
|
|
1802
2138
|
import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1803
2139
|
import { ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
1804
|
-
var
|
|
2140
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
|
|
1805
2141
|
var InvitationTopology = class {
|
|
1806
2142
|
constructor(_role) {
|
|
1807
2143
|
this._role = _role;
|
|
1808
2144
|
this._seenPeers = new ComplexSet2(PublicKey6.hash);
|
|
1809
2145
|
}
|
|
1810
2146
|
init(controller) {
|
|
1811
|
-
|
|
1812
|
-
F:
|
|
2147
|
+
invariant8(!this._controller, "Already initialized.", {
|
|
2148
|
+
F: __dxlog_file10,
|
|
1813
2149
|
L: 42,
|
|
1814
2150
|
S: this,
|
|
1815
2151
|
A: [
|
|
@@ -1820,8 +2156,8 @@ var InvitationTopology = class {
|
|
|
1820
2156
|
this._controller = controller;
|
|
1821
2157
|
}
|
|
1822
2158
|
update() {
|
|
1823
|
-
|
|
1824
|
-
F:
|
|
2159
|
+
invariant8(this._controller, "Not initialized.", {
|
|
2160
|
+
F: __dxlog_file10,
|
|
1825
2161
|
L: 47,
|
|
1826
2162
|
S: this,
|
|
1827
2163
|
A: [
|
|
@@ -1840,11 +2176,11 @@ var InvitationTopology = class {
|
|
|
1840
2176
|
const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
|
|
1841
2177
|
this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
|
|
1842
2178
|
if (firstUnknownPeer != null) {
|
|
1843
|
-
|
|
2179
|
+
log7("invitation connect", {
|
|
1844
2180
|
ownPeerId,
|
|
1845
2181
|
remotePeerId: firstUnknownPeer
|
|
1846
2182
|
}, {
|
|
1847
|
-
F:
|
|
2183
|
+
F: __dxlog_file10,
|
|
1848
2184
|
L: 69,
|
|
1849
2185
|
S: this,
|
|
1850
2186
|
C: (f, a) => f(...a)
|
|
@@ -1854,8 +2190,8 @@ var InvitationTopology = class {
|
|
|
1854
2190
|
}
|
|
1855
2191
|
}
|
|
1856
2192
|
async onOffer(peer) {
|
|
1857
|
-
|
|
1858
|
-
F:
|
|
2193
|
+
invariant8(this._controller, "Not initialized.", {
|
|
2194
|
+
F: __dxlog_file10,
|
|
1859
2195
|
L: 76,
|
|
1860
2196
|
S: this,
|
|
1861
2197
|
A: [
|
|
@@ -1874,7 +2210,7 @@ var InvitationTopology = class {
|
|
|
1874
2210
|
};
|
|
1875
2211
|
|
|
1876
2212
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1877
|
-
var
|
|
2213
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
|
|
1878
2214
|
var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
|
|
1879
2215
|
var InvitationsHandler = class {
|
|
1880
2216
|
/**
|
|
@@ -1898,8 +2234,8 @@ var InvitationsHandler = class {
|
|
|
1898
2234
|
admit: async (admissionRequest) => {
|
|
1899
2235
|
try {
|
|
1900
2236
|
const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
|
|
1901
|
-
|
|
1902
|
-
F:
|
|
2237
|
+
invariant9(deviceKey, void 0, {
|
|
2238
|
+
F: __dxlog_file11,
|
|
1903
2239
|
L: 90,
|
|
1904
2240
|
S: this,
|
|
1905
2241
|
A: [
|
|
@@ -1925,18 +2261,18 @@ var InvitationsHandler = class {
|
|
|
1925
2261
|
scheduleTask3(connectionCtx, async () => {
|
|
1926
2262
|
const traceId = PublicKey7.random().toHex();
|
|
1927
2263
|
try {
|
|
1928
|
-
|
|
2264
|
+
log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
|
|
1929
2265
|
id: traceId
|
|
1930
2266
|
}), {
|
|
1931
|
-
F:
|
|
2267
|
+
F: __dxlog_file11,
|
|
1932
2268
|
L: 115,
|
|
1933
2269
|
S: this,
|
|
1934
2270
|
C: (f, a) => f(...a)
|
|
1935
2271
|
});
|
|
1936
|
-
|
|
2272
|
+
log8("connected", {
|
|
1937
2273
|
...protocol.toJSON()
|
|
1938
2274
|
}, {
|
|
1939
|
-
F:
|
|
2275
|
+
F: __dxlog_file11,
|
|
1940
2276
|
L: 116,
|
|
1941
2277
|
S: this,
|
|
1942
2278
|
C: (f, a) => f(...a)
|
|
@@ -1944,20 +2280,20 @@ var InvitationsHandler = class {
|
|
|
1944
2280
|
const deviceKey = await extension.completedTrigger.wait({
|
|
1945
2281
|
timeout: invitation.timeout
|
|
1946
2282
|
});
|
|
1947
|
-
|
|
2283
|
+
log8("admitted guest", {
|
|
1948
2284
|
guest: deviceKey,
|
|
1949
2285
|
...protocol.toJSON()
|
|
1950
2286
|
}, {
|
|
1951
|
-
F:
|
|
2287
|
+
F: __dxlog_file11,
|
|
1952
2288
|
L: 118,
|
|
1953
2289
|
S: this,
|
|
1954
2290
|
C: (f, a) => f(...a)
|
|
1955
2291
|
});
|
|
1956
2292
|
guardedState.set(extension, Invitation4.State.SUCCESS);
|
|
1957
|
-
|
|
2293
|
+
log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
|
|
1958
2294
|
id: traceId
|
|
1959
2295
|
}), {
|
|
1960
|
-
F:
|
|
2296
|
+
F: __dxlog_file11,
|
|
1961
2297
|
L: 120,
|
|
1962
2298
|
S: this,
|
|
1963
2299
|
C: (f, a) => f(...a)
|
|
@@ -1969,10 +2305,10 @@ var InvitationsHandler = class {
|
|
|
1969
2305
|
} catch (err) {
|
|
1970
2306
|
if (err instanceof TimeoutError) {
|
|
1971
2307
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
1972
|
-
|
|
2308
|
+
log8("timeout", {
|
|
1973
2309
|
...protocol.toJSON()
|
|
1974
2310
|
}, {
|
|
1975
|
-
F:
|
|
2311
|
+
F: __dxlog_file11,
|
|
1976
2312
|
L: 129,
|
|
1977
2313
|
S: this,
|
|
1978
2314
|
C: (f, a) => f(...a)
|
|
@@ -1980,19 +2316,19 @@ var InvitationsHandler = class {
|
|
|
1980
2316
|
}
|
|
1981
2317
|
} else {
|
|
1982
2318
|
if (guardedState.error(extension, err)) {
|
|
1983
|
-
|
|
1984
|
-
F:
|
|
2319
|
+
log8.error("failed", err, {
|
|
2320
|
+
F: __dxlog_file11,
|
|
1985
2321
|
L: 133,
|
|
1986
2322
|
S: this,
|
|
1987
2323
|
C: (f, a) => f(...a)
|
|
1988
2324
|
});
|
|
1989
2325
|
}
|
|
1990
2326
|
}
|
|
1991
|
-
|
|
2327
|
+
log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
|
|
1992
2328
|
id: traceId,
|
|
1993
2329
|
error: err
|
|
1994
2330
|
}), {
|
|
1995
|
-
F:
|
|
2331
|
+
F: __dxlog_file11,
|
|
1996
2332
|
L: 136,
|
|
1997
2333
|
S: this,
|
|
1998
2334
|
C: (f, a) => f(...a)
|
|
@@ -2003,10 +2339,10 @@ var InvitationsHandler = class {
|
|
|
2003
2339
|
},
|
|
2004
2340
|
onError: (err) => {
|
|
2005
2341
|
if (err instanceof InvalidInvitationExtensionRoleError3) {
|
|
2006
|
-
|
|
2342
|
+
log8("invalid role", {
|
|
2007
2343
|
...err.context
|
|
2008
2344
|
}, {
|
|
2009
|
-
F:
|
|
2345
|
+
F: __dxlog_file11,
|
|
2010
2346
|
L: 144,
|
|
2011
2347
|
S: this,
|
|
2012
2348
|
C: (f, a) => f(...a)
|
|
@@ -2015,10 +2351,10 @@ var InvitationsHandler = class {
|
|
|
2015
2351
|
}
|
|
2016
2352
|
if (err instanceof TimeoutError) {
|
|
2017
2353
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
2018
|
-
|
|
2354
|
+
log8("timeout", {
|
|
2019
2355
|
err
|
|
2020
2356
|
}, {
|
|
2021
|
-
F:
|
|
2357
|
+
F: __dxlog_file11,
|
|
2022
2358
|
L: 149,
|
|
2023
2359
|
S: this,
|
|
2024
2360
|
C: (f, a) => f(...a)
|
|
@@ -2026,8 +2362,8 @@ var InvitationsHandler = class {
|
|
|
2026
2362
|
}
|
|
2027
2363
|
} else {
|
|
2028
2364
|
if (guardedState.error(extension, err)) {
|
|
2029
|
-
|
|
2030
|
-
F:
|
|
2365
|
+
log8.error("failed", err, {
|
|
2366
|
+
F: __dxlog_file11,
|
|
2031
2367
|
L: 153,
|
|
2032
2368
|
S: this,
|
|
2033
2369
|
C: (f, a) => f(...a)
|
|
@@ -2040,8 +2376,8 @@ var InvitationsHandler = class {
|
|
|
2040
2376
|
};
|
|
2041
2377
|
if (invitation.lifetime && invitation.created) {
|
|
2042
2378
|
if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
|
|
2043
|
-
|
|
2044
|
-
F:
|
|
2379
|
+
log8.warn("invitation has already expired", void 0, {
|
|
2380
|
+
F: __dxlog_file11,
|
|
2045
2381
|
L: 164,
|
|
2046
2382
|
S: this,
|
|
2047
2383
|
C: (f, a) => f(...a)
|
|
@@ -2063,8 +2399,8 @@ var InvitationsHandler = class {
|
|
|
2063
2399
|
acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
|
|
2064
2400
|
const { timeout = INVITATION_TIMEOUT } = invitation;
|
|
2065
2401
|
if (deviceProfile) {
|
|
2066
|
-
|
|
2067
|
-
F:
|
|
2402
|
+
invariant9(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
2403
|
+
F: __dxlog_file11,
|
|
2068
2404
|
L: 197,
|
|
2069
2405
|
S: this,
|
|
2070
2406
|
A: [
|
|
@@ -2077,12 +2413,12 @@ var InvitationsHandler = class {
|
|
|
2077
2413
|
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
2078
2414
|
const shouldCancelInvitationFlow = (extension) => {
|
|
2079
2415
|
const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
|
|
2080
|
-
|
|
2416
|
+
log8("should cancel invitation flow", {
|
|
2081
2417
|
isLockedByAnotherConnection,
|
|
2082
2418
|
invitationType: Invitation4.Type.DELEGATED,
|
|
2083
2419
|
triedPeers: triedPeersIds.size
|
|
2084
2420
|
}, {
|
|
2085
|
-
F:
|
|
2421
|
+
F: __dxlog_file11,
|
|
2086
2422
|
L: 205,
|
|
2087
2423
|
S: this,
|
|
2088
2424
|
C: (f, a) => f(...a)
|
|
@@ -2105,11 +2441,11 @@ var InvitationsHandler = class {
|
|
|
2105
2441
|
return;
|
|
2106
2442
|
}
|
|
2107
2443
|
connectionCtx.onDispose(async () => {
|
|
2108
|
-
|
|
2444
|
+
log8("extension disposed", {
|
|
2109
2445
|
admitted,
|
|
2110
2446
|
currentState: guardedState.current.state
|
|
2111
2447
|
}, {
|
|
2112
|
-
F:
|
|
2448
|
+
F: __dxlog_file11,
|
|
2113
2449
|
L: 233,
|
|
2114
2450
|
S: this,
|
|
2115
2451
|
C: (f, a) => f(...a)
|
|
@@ -2124,10 +2460,10 @@ var InvitationsHandler = class {
|
|
|
2124
2460
|
scheduleTask3(connectionCtx, async () => {
|
|
2125
2461
|
const traceId = PublicKey7.random().toHex();
|
|
2126
2462
|
try {
|
|
2127
|
-
|
|
2463
|
+
log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
|
|
2128
2464
|
id: traceId
|
|
2129
2465
|
}), {
|
|
2130
|
-
F:
|
|
2466
|
+
F: __dxlog_file11,
|
|
2131
2467
|
L: 245,
|
|
2132
2468
|
S: this,
|
|
2133
2469
|
C: (f, a) => f(...a)
|
|
@@ -2136,19 +2472,19 @@ var InvitationsHandler = class {
|
|
|
2136
2472
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2137
2473
|
extensionCtx.close();
|
|
2138
2474
|
}, timeout);
|
|
2139
|
-
|
|
2475
|
+
log8("connected", {
|
|
2140
2476
|
...protocol.toJSON()
|
|
2141
2477
|
}, {
|
|
2142
|
-
F:
|
|
2478
|
+
F: __dxlog_file11,
|
|
2143
2479
|
L: 256,
|
|
2144
2480
|
S: this,
|
|
2145
2481
|
C: (f, a) => f(...a)
|
|
2146
2482
|
});
|
|
2147
2483
|
guardedState.set(extension, Invitation4.State.CONNECTED);
|
|
2148
|
-
|
|
2484
|
+
log8("introduce", {
|
|
2149
2485
|
...protocol.toJSON()
|
|
2150
2486
|
}, {
|
|
2151
|
-
F:
|
|
2487
|
+
F: __dxlog_file11,
|
|
2152
2488
|
L: 260,
|
|
2153
2489
|
S: this,
|
|
2154
2490
|
C: (f, a) => f(...a)
|
|
@@ -2157,11 +2493,11 @@ var InvitationsHandler = class {
|
|
|
2157
2493
|
invitationId: invitation.invitationId,
|
|
2158
2494
|
...protocol.createIntroduction()
|
|
2159
2495
|
});
|
|
2160
|
-
|
|
2496
|
+
log8("introduce response", {
|
|
2161
2497
|
...protocol.toJSON(),
|
|
2162
2498
|
response: introductionResponse
|
|
2163
2499
|
}, {
|
|
2164
|
-
F:
|
|
2500
|
+
F: __dxlog_file11,
|
|
2165
2501
|
L: 265,
|
|
2166
2502
|
S: this,
|
|
2167
2503
|
C: (f, a) => f(...a)
|
|
@@ -2179,10 +2515,10 @@ var InvitationsHandler = class {
|
|
|
2179
2515
|
break;
|
|
2180
2516
|
}
|
|
2181
2517
|
}
|
|
2182
|
-
|
|
2518
|
+
log8("request admission", {
|
|
2183
2519
|
...protocol.toJSON()
|
|
2184
2520
|
}, {
|
|
2185
|
-
F:
|
|
2521
|
+
F: __dxlog_file11,
|
|
2186
2522
|
L: 291,
|
|
2187
2523
|
S: this,
|
|
2188
2524
|
C: (f, a) => f(...a)
|
|
@@ -2191,10 +2527,10 @@ var InvitationsHandler = class {
|
|
|
2191
2527
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
2192
2528
|
admitted = true;
|
|
2193
2529
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
2194
|
-
|
|
2530
|
+
log8("admitted by host", {
|
|
2195
2531
|
...protocol.toJSON()
|
|
2196
2532
|
}, {
|
|
2197
|
-
F:
|
|
2533
|
+
F: __dxlog_file11,
|
|
2198
2534
|
L: 302,
|
|
2199
2535
|
S: this,
|
|
2200
2536
|
C: (f, a) => f(...a)
|
|
@@ -2204,28 +2540,28 @@ var InvitationsHandler = class {
|
|
|
2204
2540
|
...result,
|
|
2205
2541
|
state: Invitation4.State.SUCCESS
|
|
2206
2542
|
});
|
|
2207
|
-
|
|
2543
|
+
log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
|
|
2208
2544
|
id: traceId
|
|
2209
2545
|
}), {
|
|
2210
|
-
F:
|
|
2546
|
+
F: __dxlog_file11,
|
|
2211
2547
|
L: 308,
|
|
2212
2548
|
S: this,
|
|
2213
2549
|
C: (f, a) => f(...a)
|
|
2214
2550
|
});
|
|
2215
2551
|
} catch (err) {
|
|
2216
2552
|
if (err instanceof TimeoutError) {
|
|
2217
|
-
|
|
2553
|
+
log8("timeout", {
|
|
2218
2554
|
...protocol.toJSON()
|
|
2219
2555
|
}, {
|
|
2220
|
-
F:
|
|
2556
|
+
F: __dxlog_file11,
|
|
2221
2557
|
L: 311,
|
|
2222
2558
|
S: this,
|
|
2223
2559
|
C: (f, a) => f(...a)
|
|
2224
2560
|
});
|
|
2225
2561
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2226
2562
|
} else {
|
|
2227
|
-
|
|
2228
|
-
F:
|
|
2563
|
+
log8("auth failed", err, {
|
|
2564
|
+
F: __dxlog_file11,
|
|
2229
2565
|
L: 314,
|
|
2230
2566
|
S: this,
|
|
2231
2567
|
C: (f, a) => f(...a)
|
|
@@ -2233,11 +2569,11 @@ var InvitationsHandler = class {
|
|
|
2233
2569
|
guardedState.error(extension, err);
|
|
2234
2570
|
}
|
|
2235
2571
|
extensionCtx.close(err);
|
|
2236
|
-
|
|
2572
|
+
log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
|
|
2237
2573
|
id: traceId,
|
|
2238
2574
|
error: err
|
|
2239
2575
|
}), {
|
|
2240
|
-
F:
|
|
2576
|
+
F: __dxlog_file11,
|
|
2241
2577
|
L: 318,
|
|
2242
2578
|
S: this,
|
|
2243
2579
|
C: (f, a) => f(...a)
|
|
@@ -2250,18 +2586,18 @@ var InvitationsHandler = class {
|
|
|
2250
2586
|
return;
|
|
2251
2587
|
}
|
|
2252
2588
|
if (err instanceof TimeoutError) {
|
|
2253
|
-
|
|
2589
|
+
log8("timeout", {
|
|
2254
2590
|
...protocol.toJSON()
|
|
2255
2591
|
}, {
|
|
2256
|
-
F:
|
|
2592
|
+
F: __dxlog_file11,
|
|
2257
2593
|
L: 327,
|
|
2258
2594
|
S: this,
|
|
2259
2595
|
C: (f, a) => f(...a)
|
|
2260
2596
|
});
|
|
2261
2597
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2262
2598
|
} else {
|
|
2263
|
-
|
|
2264
|
-
F:
|
|
2599
|
+
log8("auth failed", err, {
|
|
2600
|
+
F: __dxlog_file11,
|
|
2265
2601
|
L: 330,
|
|
2266
2602
|
S: this,
|
|
2267
2603
|
C: (f, a) => f(...a)
|
|
@@ -2278,8 +2614,8 @@ var InvitationsHandler = class {
|
|
|
2278
2614
|
stream.error(error);
|
|
2279
2615
|
await ctx.dispose();
|
|
2280
2616
|
} else {
|
|
2281
|
-
|
|
2282
|
-
F:
|
|
2617
|
+
invariant9(invitation.swarmKey, void 0, {
|
|
2618
|
+
F: __dxlog_file11,
|
|
2283
2619
|
L: 345,
|
|
2284
2620
|
S: this,
|
|
2285
2621
|
A: [
|
|
@@ -2373,12 +2709,12 @@ var InvitationsHandler = class {
|
|
|
2373
2709
|
};
|
|
2374
2710
|
}
|
|
2375
2711
|
_logStateUpdate(invitation, actor, newState) {
|
|
2376
|
-
|
|
2712
|
+
log8("invitation state update", {
|
|
2377
2713
|
actor: actor?.constructor.name,
|
|
2378
2714
|
newState: stateToString(newState),
|
|
2379
2715
|
oldState: stateToString(invitation.state)
|
|
2380
2716
|
}, {
|
|
2381
|
-
F:
|
|
2717
|
+
F: __dxlog_file11,
|
|
2382
2718
|
L: 438,
|
|
2383
2719
|
S: this,
|
|
2384
2720
|
C: (f, a) => f(...a)
|
|
@@ -2395,16 +2731,16 @@ var InvitationsHandler = class {
|
|
|
2395
2731
|
}
|
|
2396
2732
|
async _handleGuestOtpAuth(extension, setState, authenticated, options) {
|
|
2397
2733
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
2398
|
-
|
|
2399
|
-
F:
|
|
2734
|
+
log8("guest waiting for authentication code...", void 0, {
|
|
2735
|
+
F: __dxlog_file11,
|
|
2400
2736
|
L: 462,
|
|
2401
2737
|
S: this,
|
|
2402
2738
|
C: (f, a) => f(...a)
|
|
2403
2739
|
});
|
|
2404
2740
|
setState(Invitation4.State.READY_FOR_AUTHENTICATION);
|
|
2405
2741
|
const authCode = await authenticated.wait(options);
|
|
2406
|
-
|
|
2407
|
-
F:
|
|
2742
|
+
log8("sending authentication request", void 0, {
|
|
2743
|
+
F: __dxlog_file11,
|
|
2408
2744
|
L: 466,
|
|
2409
2745
|
S: this,
|
|
2410
2746
|
C: (f, a) => f(...a)
|
|
@@ -2420,10 +2756,10 @@ var InvitationsHandler = class {
|
|
|
2420
2756
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
2421
2757
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
2422
2758
|
} else {
|
|
2423
|
-
|
|
2759
|
+
log8("retrying invalid code", {
|
|
2424
2760
|
attempt
|
|
2425
2761
|
}, {
|
|
2426
|
-
F:
|
|
2762
|
+
F: __dxlog_file11,
|
|
2427
2763
|
L: 477,
|
|
2428
2764
|
S: this,
|
|
2429
2765
|
C: (f, a) => f(...a)
|
|
@@ -2440,8 +2776,8 @@ var InvitationsHandler = class {
|
|
|
2440
2776
|
if (introductionResponse.challenge == null) {
|
|
2441
2777
|
throw new Error("challenge missing in the introduction");
|
|
2442
2778
|
}
|
|
2443
|
-
|
|
2444
|
-
F:
|
|
2779
|
+
log8("sending authentication request", void 0, {
|
|
2780
|
+
F: __dxlog_file11,
|
|
2445
2781
|
L: 496,
|
|
2446
2782
|
S: this,
|
|
2447
2783
|
C: (f, a) => f(...a)
|
|
@@ -2465,7 +2801,7 @@ var createAdmissionKeypair = () => {
|
|
|
2465
2801
|
};
|
|
2466
2802
|
|
|
2467
2803
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
2468
|
-
import { Stream as
|
|
2804
|
+
import { Stream as Stream9 } from "@dxos/codec-protobuf";
|
|
2469
2805
|
import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
|
|
2470
2806
|
var InvitationsServiceImpl = class {
|
|
2471
2807
|
constructor(_invitationsManager) {
|
|
@@ -2476,13 +2812,13 @@ var InvitationsServiceImpl = class {
|
|
|
2476
2812
|
return {};
|
|
2477
2813
|
}
|
|
2478
2814
|
createInvitation(options) {
|
|
2479
|
-
return new
|
|
2815
|
+
return new Stream9(({ next, close }) => {
|
|
2480
2816
|
void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
|
|
2481
2817
|
});
|
|
2482
2818
|
}
|
|
2483
2819
|
acceptInvitation(request) {
|
|
2484
2820
|
const invitation = this._invitationsManager.acceptInvitation(request);
|
|
2485
|
-
return new
|
|
2821
|
+
return new Stream9(({ next, close }) => {
|
|
2486
2822
|
invitation.subscribe(next, close, close);
|
|
2487
2823
|
});
|
|
2488
2824
|
}
|
|
@@ -2493,7 +2829,7 @@ var InvitationsServiceImpl = class {
|
|
|
2493
2829
|
return this._invitationsManager.cancelInvitation(request);
|
|
2494
2830
|
}
|
|
2495
2831
|
queryInvitations() {
|
|
2496
|
-
return new
|
|
2832
|
+
return new Stream9(({ next, ctx }) => {
|
|
2497
2833
|
this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
|
|
2498
2834
|
next({
|
|
2499
2835
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
@@ -2564,12 +2900,12 @@ var InvitationsServiceImpl = class {
|
|
|
2564
2900
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
2565
2901
|
import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
|
|
2566
2902
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
2567
|
-
import { invariant as
|
|
2568
|
-
import { log as
|
|
2903
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2904
|
+
import { log as log9 } from "@dxos/log";
|
|
2569
2905
|
import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
|
|
2570
2906
|
import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2571
|
-
import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2572
|
-
var
|
|
2907
|
+
import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2908
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
2573
2909
|
var SpaceInvitationProtocol = class {
|
|
2574
2910
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2575
2911
|
this._spaceManager = _spaceManager;
|
|
@@ -2603,8 +2939,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2603
2939
|
};
|
|
2604
2940
|
}
|
|
2605
2941
|
async admit(invitation, request, guestProfile) {
|
|
2606
|
-
|
|
2607
|
-
F:
|
|
2942
|
+
invariant10(this._spaceKey, void 0, {
|
|
2943
|
+
F: __dxlog_file12,
|
|
2608
2944
|
L: 76,
|
|
2609
2945
|
S: this,
|
|
2610
2946
|
A: [
|
|
@@ -2613,8 +2949,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2613
2949
|
]
|
|
2614
2950
|
});
|
|
2615
2951
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2616
|
-
|
|
2617
|
-
F:
|
|
2952
|
+
invariant10(space, void 0, {
|
|
2953
|
+
F: __dxlog_file12,
|
|
2618
2954
|
L: 78,
|
|
2619
2955
|
S: this,
|
|
2620
2956
|
A: [
|
|
@@ -2622,8 +2958,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2622
2958
|
""
|
|
2623
2959
|
]
|
|
2624
2960
|
});
|
|
2625
|
-
|
|
2626
|
-
F:
|
|
2961
|
+
invariant10(request.space, void 0, {
|
|
2962
|
+
F: __dxlog_file12,
|
|
2627
2963
|
L: 80,
|
|
2628
2964
|
S: this,
|
|
2629
2965
|
A: [
|
|
@@ -2632,21 +2968,21 @@ var SpaceInvitationProtocol = class {
|
|
|
2632
2968
|
]
|
|
2633
2969
|
});
|
|
2634
2970
|
const { identityKey, deviceKey } = request.space;
|
|
2635
|
-
if (space.inner.spaceState.getMemberRole(identityKey) !==
|
|
2971
|
+
if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
|
|
2636
2972
|
throw new AlreadyJoinedError2();
|
|
2637
2973
|
}
|
|
2638
|
-
|
|
2974
|
+
log9("writing guest credentials", {
|
|
2639
2975
|
host: this._signingContext.deviceKey,
|
|
2640
2976
|
guest: deviceKey
|
|
2641
2977
|
}, {
|
|
2642
|
-
F:
|
|
2978
|
+
F: __dxlog_file12,
|
|
2643
2979
|
L: 87,
|
|
2644
2980
|
S: this,
|
|
2645
2981
|
C: (f, a) => f(...a)
|
|
2646
2982
|
});
|
|
2647
|
-
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ??
|
|
2648
|
-
|
|
2649
|
-
F:
|
|
2983
|
+
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? SpaceMember2.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
|
|
2984
|
+
invariant10(credentials[0].credential, void 0, {
|
|
2985
|
+
F: __dxlog_file12,
|
|
2650
2986
|
L: 101,
|
|
2651
2987
|
S: this,
|
|
2652
2988
|
A: [
|
|
@@ -2655,8 +2991,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2655
2991
|
]
|
|
2656
2992
|
});
|
|
2657
2993
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2658
|
-
|
|
2659
|
-
F:
|
|
2994
|
+
invariant10(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2995
|
+
F: __dxlog_file12,
|
|
2660
2996
|
L: 103,
|
|
2661
2997
|
S: this,
|
|
2662
2998
|
A: [
|
|
@@ -2673,8 +3009,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2673
3009
|
};
|
|
2674
3010
|
}
|
|
2675
3011
|
async delegate(invitation) {
|
|
2676
|
-
|
|
2677
|
-
F:
|
|
3012
|
+
invariant10(this._spaceKey, void 0, {
|
|
3013
|
+
F: __dxlog_file12,
|
|
2678
3014
|
L: 116,
|
|
2679
3015
|
S: this,
|
|
2680
3016
|
A: [
|
|
@@ -2683,8 +3019,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2683
3019
|
]
|
|
2684
3020
|
});
|
|
2685
3021
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2686
|
-
|
|
2687
|
-
F:
|
|
3022
|
+
invariant10(space, void 0, {
|
|
3023
|
+
F: __dxlog_file12,
|
|
2688
3024
|
L: 118,
|
|
2689
3025
|
S: this,
|
|
2690
3026
|
A: [
|
|
@@ -2693,8 +3029,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2693
3029
|
]
|
|
2694
3030
|
});
|
|
2695
3031
|
if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
|
|
2696
|
-
|
|
2697
|
-
F:
|
|
3032
|
+
invariant10(invitation.guestKeypair?.publicKey, void 0, {
|
|
3033
|
+
F: __dxlog_file12,
|
|
2698
3034
|
L: 120,
|
|
2699
3035
|
S: this,
|
|
2700
3036
|
A: [
|
|
@@ -2703,11 +3039,11 @@ var SpaceInvitationProtocol = class {
|
|
|
2703
3039
|
]
|
|
2704
3040
|
});
|
|
2705
3041
|
}
|
|
2706
|
-
|
|
3042
|
+
log9("writing delegate space invitation", {
|
|
2707
3043
|
host: this._signingContext.deviceKey,
|
|
2708
3044
|
id: invitation.invitationId
|
|
2709
3045
|
}, {
|
|
2710
|
-
F:
|
|
3046
|
+
F: __dxlog_file12,
|
|
2711
3047
|
L: 123,
|
|
2712
3048
|
S: this,
|
|
2713
3049
|
C: (f, a) => f(...a)
|
|
@@ -2716,13 +3052,13 @@ var SpaceInvitationProtocol = class {
|
|
|
2716
3052
|
invitationId: invitation.invitationId,
|
|
2717
3053
|
authMethod: invitation.authMethod,
|
|
2718
3054
|
swarmKey: invitation.swarmKey,
|
|
2719
|
-
role: invitation.role ??
|
|
3055
|
+
role: invitation.role ?? SpaceMember2.Role.ADMIN,
|
|
2720
3056
|
expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
|
|
2721
3057
|
multiUse: invitation.multiUse ?? false,
|
|
2722
3058
|
guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
|
|
2723
3059
|
});
|
|
2724
|
-
|
|
2725
|
-
F:
|
|
3060
|
+
invariant10(credential.credential, void 0, {
|
|
3061
|
+
F: __dxlog_file12,
|
|
2726
3062
|
L: 143,
|
|
2727
3063
|
S: this,
|
|
2728
3064
|
A: [
|
|
@@ -2736,8 +3072,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2736
3072
|
return credential.credential.credential.id;
|
|
2737
3073
|
}
|
|
2738
3074
|
async cancelDelegation(invitation) {
|
|
2739
|
-
|
|
2740
|
-
F:
|
|
3075
|
+
invariant10(this._spaceKey, void 0, {
|
|
3076
|
+
F: __dxlog_file12,
|
|
2741
3077
|
L: 149,
|
|
2742
3078
|
S: this,
|
|
2743
3079
|
A: [
|
|
@@ -2745,8 +3081,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2745
3081
|
""
|
|
2746
3082
|
]
|
|
2747
3083
|
});
|
|
2748
|
-
|
|
2749
|
-
F:
|
|
3084
|
+
invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
|
|
3085
|
+
F: __dxlog_file12,
|
|
2750
3086
|
L: 150,
|
|
2751
3087
|
S: this,
|
|
2752
3088
|
A: [
|
|
@@ -2755,8 +3091,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2755
3091
|
]
|
|
2756
3092
|
});
|
|
2757
3093
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2758
|
-
|
|
2759
|
-
F:
|
|
3094
|
+
invariant10(space, void 0, {
|
|
3095
|
+
F: __dxlog_file12,
|
|
2760
3096
|
L: 152,
|
|
2761
3097
|
S: this,
|
|
2762
3098
|
A: [
|
|
@@ -2764,18 +3100,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2764
3100
|
""
|
|
2765
3101
|
]
|
|
2766
3102
|
});
|
|
2767
|
-
|
|
3103
|
+
log9("cancelling delegated space invitation", {
|
|
2768
3104
|
host: this._signingContext.deviceKey,
|
|
2769
3105
|
id: invitation.invitationId
|
|
2770
3106
|
}, {
|
|
2771
|
-
F:
|
|
3107
|
+
F: __dxlog_file12,
|
|
2772
3108
|
L: 154,
|
|
2773
3109
|
S: this,
|
|
2774
3110
|
C: (f, a) => f(...a)
|
|
2775
3111
|
});
|
|
2776
3112
|
const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
|
|
2777
|
-
|
|
2778
|
-
F:
|
|
3113
|
+
invariant10(credential.credential, void 0, {
|
|
3114
|
+
F: __dxlog_file12,
|
|
2779
3115
|
L: 161,
|
|
2780
3116
|
S: this,
|
|
2781
3117
|
A: [
|
|
@@ -2813,8 +3149,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2813
3149
|
};
|
|
2814
3150
|
}
|
|
2815
3151
|
async accept(response) {
|
|
2816
|
-
|
|
2817
|
-
F:
|
|
3152
|
+
invariant10(response.space, void 0, {
|
|
3153
|
+
F: __dxlog_file12,
|
|
2818
3154
|
L: 196,
|
|
2819
3155
|
S: this,
|
|
2820
3156
|
A: [
|
|
@@ -2824,8 +3160,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2824
3160
|
});
|
|
2825
3161
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
2826
3162
|
const assertion = getCredentialAssertion(credential);
|
|
2827
|
-
|
|
2828
|
-
F:
|
|
3163
|
+
invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
3164
|
+
F: __dxlog_file12,
|
|
2829
3165
|
L: 199,
|
|
2830
3166
|
S: this,
|
|
2831
3167
|
A: [
|
|
@@ -2833,8 +3169,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2833
3169
|
"'Invalid credential'"
|
|
2834
3170
|
]
|
|
2835
3171
|
});
|
|
2836
|
-
|
|
2837
|
-
F:
|
|
3172
|
+
invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
3173
|
+
F: __dxlog_file12,
|
|
2838
3174
|
L: 200,
|
|
2839
3175
|
S: this,
|
|
2840
3176
|
A: [
|
|
@@ -2859,17 +3195,17 @@ var SpaceInvitationProtocol = class {
|
|
|
2859
3195
|
};
|
|
2860
3196
|
|
|
2861
3197
|
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
2862
|
-
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as
|
|
3198
|
+
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
|
|
2863
3199
|
import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
|
|
2864
3200
|
import { Context as Context6 } from "@dxos/context";
|
|
2865
3201
|
import { generatePasscode } from "@dxos/credentials";
|
|
2866
3202
|
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
2867
|
-
import { invariant as
|
|
3203
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2868
3204
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2869
|
-
import { log as
|
|
3205
|
+
import { log as log10 } from "@dxos/log";
|
|
2870
3206
|
import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2871
|
-
import { SpaceMember as
|
|
2872
|
-
var
|
|
3207
|
+
import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3208
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
2873
3209
|
var InvitationsManager = class {
|
|
2874
3210
|
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
2875
3211
|
this._invitationsHandler = _invitationsHandler;
|
|
@@ -2911,8 +3247,8 @@ var InvitationsManager = class {
|
|
|
2911
3247
|
try {
|
|
2912
3248
|
await this._persistIfRequired(handler, stream, invitation);
|
|
2913
3249
|
} catch (err) {
|
|
2914
|
-
|
|
2915
|
-
F:
|
|
3250
|
+
log10.catch(err, void 0, {
|
|
3251
|
+
F: __dxlog_file13,
|
|
2916
3252
|
L: 82,
|
|
2917
3253
|
S: this,
|
|
2918
3254
|
C: (f, a) => f(...a)
|
|
@@ -2934,8 +3270,8 @@ var InvitationsManager = class {
|
|
|
2934
3270
|
const persistentInvitations = this._metadataStore.getInvitations();
|
|
2935
3271
|
const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
|
|
2936
3272
|
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
2937
|
-
|
|
2938
|
-
F:
|
|
3273
|
+
invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
3274
|
+
F: __dxlog_file13,
|
|
2939
3275
|
L: 103,
|
|
2940
3276
|
S: this,
|
|
2941
3277
|
A: [
|
|
@@ -2953,8 +3289,8 @@ var InvitationsManager = class {
|
|
|
2953
3289
|
invitations: cInvitations.map((invitation) => invitation.get())
|
|
2954
3290
|
};
|
|
2955
3291
|
} catch (err) {
|
|
2956
|
-
|
|
2957
|
-
F:
|
|
3292
|
+
log10.catch(err, void 0, {
|
|
3293
|
+
F: __dxlog_file13,
|
|
2958
3294
|
L: 110,
|
|
2959
3295
|
S: this,
|
|
2960
3296
|
C: (f, a) => f(...a)
|
|
@@ -2985,14 +3321,14 @@ var InvitationsManager = class {
|
|
|
2985
3321
|
return invitation;
|
|
2986
3322
|
}
|
|
2987
3323
|
async authenticate({ invitationId, authCode }) {
|
|
2988
|
-
|
|
2989
|
-
F:
|
|
3324
|
+
log10("authenticating...", void 0, {
|
|
3325
|
+
F: __dxlog_file13,
|
|
2990
3326
|
L: 140,
|
|
2991
3327
|
S: this,
|
|
2992
3328
|
C: (f, a) => f(...a)
|
|
2993
3329
|
});
|
|
2994
|
-
|
|
2995
|
-
F:
|
|
3330
|
+
invariant11(invitationId, void 0, {
|
|
3331
|
+
F: __dxlog_file13,
|
|
2996
3332
|
L: 141,
|
|
2997
3333
|
S: this,
|
|
2998
3334
|
A: [
|
|
@@ -3002,10 +3338,10 @@ var InvitationsManager = class {
|
|
|
3002
3338
|
});
|
|
3003
3339
|
const observable = this._acceptInvitations.get(invitationId);
|
|
3004
3340
|
if (!observable) {
|
|
3005
|
-
|
|
3341
|
+
log10.warn("invalid invitation", {
|
|
3006
3342
|
invitationId
|
|
3007
3343
|
}, {
|
|
3008
|
-
F:
|
|
3344
|
+
F: __dxlog_file13,
|
|
3009
3345
|
L: 144,
|
|
3010
3346
|
S: this,
|
|
3011
3347
|
C: (f, a) => f(...a)
|
|
@@ -3015,16 +3351,16 @@ var InvitationsManager = class {
|
|
|
3015
3351
|
}
|
|
3016
3352
|
}
|
|
3017
3353
|
async cancelInvitation({ invitationId }) {
|
|
3018
|
-
|
|
3354
|
+
log10("cancelInvitation...", {
|
|
3019
3355
|
invitationId
|
|
3020
3356
|
}, {
|
|
3021
|
-
F:
|
|
3357
|
+
F: __dxlog_file13,
|
|
3022
3358
|
L: 151,
|
|
3023
3359
|
S: this,
|
|
3024
3360
|
C: (f, a) => f(...a)
|
|
3025
3361
|
});
|
|
3026
|
-
|
|
3027
|
-
F:
|
|
3362
|
+
invariant11(invitationId, void 0, {
|
|
3363
|
+
F: __dxlog_file13,
|
|
3028
3364
|
L: 152,
|
|
3029
3365
|
S: this,
|
|
3030
3366
|
A: [
|
|
@@ -3071,7 +3407,7 @@ var InvitationsManager = class {
|
|
|
3071
3407
|
}
|
|
3072
3408
|
}
|
|
3073
3409
|
_createInvitation(protocol, options) {
|
|
3074
|
-
const { invitationId = PublicKey8.random().toHex(), type = Invitation6.Type.INTERACTIVE, authMethod = Invitation6.AuthMethod.SHARED_SECRET, state = Invitation6.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey8.random(), persistent = options?.authMethod !== Invitation6.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role =
|
|
3410
|
+
const { invitationId = PublicKey8.random().toHex(), type = Invitation6.Type.INTERACTIVE, authMethod = Invitation6.AuthMethod.SHARED_SECRET, state = Invitation6.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey8.random(), persistent = options?.authMethod !== Invitation6.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember3.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
|
|
3075
3411
|
const authCode = options?.authCode ?? (authMethod === Invitation6.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
|
|
3076
3412
|
return {
|
|
3077
3413
|
invitationId,
|
|
@@ -3100,10 +3436,10 @@ var InvitationsManager = class {
|
|
|
3100
3436
|
}
|
|
3101
3437
|
});
|
|
3102
3438
|
ctx.onDispose(() => {
|
|
3103
|
-
|
|
3439
|
+
log10("complete", {
|
|
3104
3440
|
...handler.toJSON()
|
|
3105
3441
|
}, {
|
|
3106
|
-
F:
|
|
3442
|
+
F: __dxlog_file13,
|
|
3107
3443
|
L: 241,
|
|
3108
3444
|
S: this,
|
|
3109
3445
|
C: (f, a) => f(...a)
|
|
@@ -3128,15 +3464,15 @@ var InvitationsManager = class {
|
|
|
3128
3464
|
};
|
|
3129
3465
|
}
|
|
3130
3466
|
_createObservableAcceptingInvitation(handler, initialState) {
|
|
3131
|
-
const otpEnteredTrigger = new
|
|
3467
|
+
const otpEnteredTrigger = new Trigger5();
|
|
3132
3468
|
const stream = new PushStream();
|
|
3133
3469
|
const ctx = new Context6({
|
|
3134
3470
|
onError: (err) => {
|
|
3135
3471
|
if (err instanceof TimeoutError2) {
|
|
3136
|
-
|
|
3472
|
+
log10("timeout", {
|
|
3137
3473
|
...handler.toJSON()
|
|
3138
3474
|
}, {
|
|
3139
|
-
F:
|
|
3475
|
+
F: __dxlog_file13,
|
|
3140
3476
|
L: 261,
|
|
3141
3477
|
S: this,
|
|
3142
3478
|
C: (f, a) => f(...a)
|
|
@@ -3146,8 +3482,8 @@ var InvitationsManager = class {
|
|
|
3146
3482
|
state: Invitation6.State.TIMEOUT
|
|
3147
3483
|
});
|
|
3148
3484
|
} else {
|
|
3149
|
-
|
|
3150
|
-
F:
|
|
3485
|
+
log10.warn("auth failed", err, {
|
|
3486
|
+
F: __dxlog_file13,
|
|
3151
3487
|
L: 264,
|
|
3152
3488
|
S: this,
|
|
3153
3489
|
C: (f, a) => f(...a)
|
|
@@ -3161,10 +3497,10 @@ var InvitationsManager = class {
|
|
|
3161
3497
|
}
|
|
3162
3498
|
});
|
|
3163
3499
|
ctx.onDispose(() => {
|
|
3164
|
-
|
|
3500
|
+
log10("complete", {
|
|
3165
3501
|
...handler.toJSON()
|
|
3166
3502
|
}, {
|
|
3167
|
-
F:
|
|
3503
|
+
F: __dxlog_file13,
|
|
3168
3504
|
L: 271,
|
|
3169
3505
|
S: this,
|
|
3170
3506
|
C: (f, a) => f(...a)
|
|
@@ -3208,8 +3544,8 @@ var InvitationsManager = class {
|
|
|
3208
3544
|
try {
|
|
3209
3545
|
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
3210
3546
|
} catch (err) {
|
|
3211
|
-
|
|
3212
|
-
F:
|
|
3547
|
+
log10.catch(err, void 0, {
|
|
3548
|
+
F: __dxlog_file13,
|
|
3213
3549
|
L: 307,
|
|
3214
3550
|
S: this,
|
|
3215
3551
|
C: (f, a) => f(...a)
|
|
@@ -3223,100 +3559,19 @@ var InvitationsManager = class {
|
|
|
3223
3559
|
}
|
|
3224
3560
|
};
|
|
3225
3561
|
|
|
3226
|
-
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
3227
|
-
import { Stream as Stream9 } from "@dxos/codec-protobuf";
|
|
3228
|
-
import { raise } from "@dxos/debug";
|
|
3229
|
-
import { parseMethodName, RpcPeer } from "@dxos/rpc";
|
|
3230
|
-
import { MapCounter, trace as trace5 } from "@dxos/tracing";
|
|
3231
|
-
function _ts_decorate3(decorators, target, key, desc) {
|
|
3232
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3233
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3234
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
3235
|
-
else
|
|
3236
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
3237
|
-
if (d = decorators[i])
|
|
3238
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3239
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3240
|
-
}
|
|
3241
|
-
var ClientRpcServer = class {
|
|
3242
|
-
constructor(params) {
|
|
3243
|
-
this._handlerCache = /* @__PURE__ */ new Map();
|
|
3244
|
-
this._callMetrics = new MapCounter();
|
|
3245
|
-
const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
|
|
3246
|
-
this._handleCall = handleCall;
|
|
3247
|
-
this._handleStream = handleStream;
|
|
3248
|
-
this._serviceRegistry = serviceRegistry;
|
|
3249
|
-
this._rpcPeer = new RpcPeer({
|
|
3250
|
-
...rpcOptions,
|
|
3251
|
-
callHandler: (method, params2) => {
|
|
3252
|
-
const [serviceName, methodName] = parseMethodName(method);
|
|
3253
|
-
const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
|
|
3254
|
-
this._callMetrics.inc(`${serviceName}.${methodName} request`);
|
|
3255
|
-
if (this._handleCall) {
|
|
3256
|
-
return this._handleCall(methodName, params2, handler);
|
|
3257
|
-
} else {
|
|
3258
|
-
return handler(methodName, params2);
|
|
3259
|
-
}
|
|
3260
|
-
},
|
|
3261
|
-
streamHandler: (method, params2) => {
|
|
3262
|
-
const [serviceName, methodName] = parseMethodName(method);
|
|
3263
|
-
const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
|
|
3264
|
-
this._callMetrics.inc(`${serviceName}.${methodName} request stream`);
|
|
3265
|
-
if (this._handleStream) {
|
|
3266
|
-
return Stream9.map(Stream9.unwrapPromise(this._handleStream(methodName, params2, handler)), (data) => {
|
|
3267
|
-
this._callMetrics.inc(`${serviceName}.${methodName} response stream`);
|
|
3268
|
-
return data;
|
|
3269
|
-
});
|
|
3270
|
-
} else {
|
|
3271
|
-
return handler(methodName, params2);
|
|
3272
|
-
}
|
|
3273
|
-
}
|
|
3274
|
-
});
|
|
3275
|
-
}
|
|
3276
|
-
get _services() {
|
|
3277
|
-
return Object.keys(this._serviceRegistry.services);
|
|
3278
|
-
}
|
|
3279
|
-
async open() {
|
|
3280
|
-
await this._rpcPeer.open();
|
|
3281
|
-
}
|
|
3282
|
-
async close() {
|
|
3283
|
-
await this._rpcPeer.close();
|
|
3284
|
-
}
|
|
3285
|
-
_getServiceHandler(serviceName) {
|
|
3286
|
-
if (!this._handlerCache.has(serviceName)) {
|
|
3287
|
-
const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
|
|
3288
|
-
const service = this._serviceRegistry.services[key];
|
|
3289
|
-
if (!service) {
|
|
3290
|
-
throw new Error(`Service not available: ${serviceName}`);
|
|
3291
|
-
}
|
|
3292
|
-
this._handlerCache.set(serviceName, descriptor.createServer(service));
|
|
3293
|
-
}
|
|
3294
|
-
return this._handlerCache.get(serviceName);
|
|
3295
|
-
}
|
|
3296
|
-
};
|
|
3297
|
-
_ts_decorate3([
|
|
3298
|
-
trace5.metricsCounter()
|
|
3299
|
-
], ClientRpcServer.prototype, "_callMetrics", void 0);
|
|
3300
|
-
_ts_decorate3([
|
|
3301
|
-
trace5.info()
|
|
3302
|
-
], ClientRpcServer.prototype, "_services", null);
|
|
3303
|
-
ClientRpcServer = _ts_decorate3([
|
|
3304
|
-
trace5.resource()
|
|
3305
|
-
], ClientRpcServer);
|
|
3306
|
-
|
|
3307
3562
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
3308
|
-
import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
|
|
3563
|
+
import { Event as Event6, asyncTimeout as asyncTimeout2, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
|
|
3309
3564
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3310
3565
|
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
|
|
3311
3566
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
3312
|
-
import { AutomergeDocumentLoaderImpl, createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
3567
|
+
import { AutomergeDocumentLoaderImpl, createIdFromSpaceKey, createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
3313
3568
|
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
3314
|
-
import { failedInvariant, invariant as
|
|
3569
|
+
import { failedInvariant, invariant as invariant13 } from "@dxos/invariant";
|
|
3315
3570
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3316
|
-
import { log as
|
|
3571
|
+
import { log as log12 } from "@dxos/log";
|
|
3317
3572
|
import { CancelledError, SystemError } from "@dxos/protocols";
|
|
3318
3573
|
import { CreateEpochRequest, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
|
|
3319
|
-
import { AdmittedFeed as AdmittedFeed3, SpaceMember as
|
|
3574
|
+
import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3320
3575
|
import { Timeframe as Timeframe2 } from "@dxos/timeframe";
|
|
3321
3576
|
import { trace as trace6 } from "@dxos/tracing";
|
|
3322
3577
|
import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
|
|
@@ -3360,15 +3615,15 @@ var AutomergeSpaceState = class {
|
|
|
3360
3615
|
};
|
|
3361
3616
|
|
|
3362
3617
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
3363
|
-
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as
|
|
3618
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger6 } from "@dxos/async";
|
|
3364
3619
|
import { Context as Context7, rejectOnDispose } from "@dxos/context";
|
|
3365
|
-
import { invariant as
|
|
3620
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3366
3621
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3367
|
-
import { log as
|
|
3622
|
+
import { log as log11 } from "@dxos/log";
|
|
3368
3623
|
import { schema as schema4 } from "@dxos/protocols";
|
|
3369
3624
|
import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
|
|
3370
3625
|
import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
|
|
3371
|
-
var
|
|
3626
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
3372
3627
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
3373
3628
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
3374
3629
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
@@ -3393,16 +3648,16 @@ var NotarizationPlugin = class {
|
|
|
3393
3648
|
* Request credentials to be notarized.
|
|
3394
3649
|
*/
|
|
3395
3650
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
3396
|
-
|
|
3651
|
+
log11("notarize", {
|
|
3397
3652
|
credentials
|
|
3398
3653
|
}, {
|
|
3399
|
-
F:
|
|
3654
|
+
F: __dxlog_file14,
|
|
3400
3655
|
L: 90,
|
|
3401
3656
|
S: this,
|
|
3402
3657
|
C: (f, a) => f(...a)
|
|
3403
3658
|
});
|
|
3404
|
-
|
|
3405
|
-
F:
|
|
3659
|
+
invariant12(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
3660
|
+
F: __dxlog_file14,
|
|
3406
3661
|
L: 91,
|
|
3407
3662
|
S: this,
|
|
3408
3663
|
A: [
|
|
@@ -3410,13 +3665,13 @@ var NotarizationPlugin = class {
|
|
|
3410
3665
|
"'Credentials must have an id'"
|
|
3411
3666
|
]
|
|
3412
3667
|
});
|
|
3413
|
-
const errors = new
|
|
3668
|
+
const errors = new Trigger6();
|
|
3414
3669
|
const ctx = this._ctx.derive({
|
|
3415
3670
|
onError: (err) => {
|
|
3416
|
-
|
|
3671
|
+
log11.warn("Notarization error", {
|
|
3417
3672
|
err
|
|
3418
3673
|
}, {
|
|
3419
|
-
F:
|
|
3674
|
+
F: __dxlog_file14,
|
|
3420
3675
|
L: 99,
|
|
3421
3676
|
S: this,
|
|
3422
3677
|
C: (f, a) => f(...a)
|
|
@@ -3428,11 +3683,11 @@ var NotarizationPlugin = class {
|
|
|
3428
3683
|
opCtx?.onDispose(() => ctx.dispose());
|
|
3429
3684
|
if (timeout !== 0) {
|
|
3430
3685
|
scheduleTask4(ctx, () => {
|
|
3431
|
-
|
|
3686
|
+
log11.warn("Notarization timeout", {
|
|
3432
3687
|
timeout,
|
|
3433
3688
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
3434
3689
|
}, {
|
|
3435
|
-
F:
|
|
3690
|
+
F: __dxlog_file14,
|
|
3436
3691
|
L: 111,
|
|
3437
3692
|
S: this,
|
|
3438
3693
|
C: (f, a) => f(...a)
|
|
@@ -3452,10 +3707,10 @@ var NotarizationPlugin = class {
|
|
|
3452
3707
|
...this._extensions
|
|
3453
3708
|
].find((peer2) => !peersTried.has(peer2));
|
|
3454
3709
|
if (!peer) {
|
|
3455
|
-
|
|
3710
|
+
log11.info("Exhausted all peers to notarize with", {
|
|
3456
3711
|
retryIn: retryTimeout
|
|
3457
3712
|
}, {
|
|
3458
|
-
F:
|
|
3713
|
+
F: __dxlog_file14,
|
|
3459
3714
|
L: 136,
|
|
3460
3715
|
S: this,
|
|
3461
3716
|
C: (f, a) => f(...a)
|
|
@@ -3465,11 +3720,11 @@ var NotarizationPlugin = class {
|
|
|
3465
3720
|
return;
|
|
3466
3721
|
}
|
|
3467
3722
|
peersTried.add(peer);
|
|
3468
|
-
|
|
3723
|
+
log11("try notarizing", {
|
|
3469
3724
|
peer: peer.localPeerId,
|
|
3470
3725
|
credentialId: credentials.map((credential) => credential.id)
|
|
3471
3726
|
}, {
|
|
3472
|
-
F:
|
|
3727
|
+
F: __dxlog_file14,
|
|
3473
3728
|
L: 143,
|
|
3474
3729
|
S: this,
|
|
3475
3730
|
C: (f, a) => f(...a)
|
|
@@ -3477,8 +3732,8 @@ var NotarizationPlugin = class {
|
|
|
3477
3732
|
await peer.rpc.NotarizationService.notarize({
|
|
3478
3733
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
3479
3734
|
});
|
|
3480
|
-
|
|
3481
|
-
F:
|
|
3735
|
+
log11("success", void 0, {
|
|
3736
|
+
F: __dxlog_file14,
|
|
3482
3737
|
L: 147,
|
|
3483
3738
|
S: this,
|
|
3484
3739
|
C: (f, a) => f(...a)
|
|
@@ -3486,8 +3741,8 @@ var NotarizationPlugin = class {
|
|
|
3486
3741
|
await sleep(successDelay);
|
|
3487
3742
|
} catch (err) {
|
|
3488
3743
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
3489
|
-
|
|
3490
|
-
F:
|
|
3744
|
+
log11.info("error notarizing (recoverable)", err, {
|
|
3745
|
+
F: __dxlog_file14,
|
|
3491
3746
|
L: 151,
|
|
3492
3747
|
S: this,
|
|
3493
3748
|
C: (f, a) => f(...a)
|
|
@@ -3504,8 +3759,8 @@ var NotarizationPlugin = class {
|
|
|
3504
3759
|
allNotarized,
|
|
3505
3760
|
errors.wait()
|
|
3506
3761
|
]);
|
|
3507
|
-
|
|
3508
|
-
F:
|
|
3762
|
+
log11("done", void 0, {
|
|
3763
|
+
F: __dxlog_file14,
|
|
3509
3764
|
L: 162,
|
|
3510
3765
|
S: this,
|
|
3511
3766
|
C: (f, a) => f(...a)
|
|
@@ -3526,8 +3781,8 @@ var NotarizationPlugin = class {
|
|
|
3526
3781
|
this._processCredentialsTriggers.delete(credential.id);
|
|
3527
3782
|
}
|
|
3528
3783
|
setWriter(writer) {
|
|
3529
|
-
|
|
3530
|
-
F:
|
|
3784
|
+
invariant12(!this._writer, "Writer already set.", {
|
|
3785
|
+
F: __dxlog_file14,
|
|
3531
3786
|
L: 181,
|
|
3532
3787
|
S: this,
|
|
3533
3788
|
A: [
|
|
@@ -3541,7 +3796,7 @@ var NotarizationPlugin = class {
|
|
|
3541
3796
|
if (this._processedCredentials.has(id)) {
|
|
3542
3797
|
return;
|
|
3543
3798
|
}
|
|
3544
|
-
await entry(this._processCredentialsTriggers, id).orInsert(new
|
|
3799
|
+
await entry(this._processCredentialsTriggers, id).orInsert(new Trigger6()).value.wait();
|
|
3545
3800
|
}
|
|
3546
3801
|
/**
|
|
3547
3802
|
* Requests from other peers to notarize credentials.
|
|
@@ -3551,8 +3806,8 @@ var NotarizationPlugin = class {
|
|
|
3551
3806
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
3552
3807
|
}
|
|
3553
3808
|
for (const credential of request.credentials ?? []) {
|
|
3554
|
-
|
|
3555
|
-
F:
|
|
3809
|
+
invariant12(credential.id, "Credential must have an id", {
|
|
3810
|
+
F: __dxlog_file14,
|
|
3556
3811
|
L: 200,
|
|
3557
3812
|
S: this,
|
|
3558
3813
|
A: [
|
|
@@ -3569,10 +3824,10 @@ var NotarizationPlugin = class {
|
|
|
3569
3824
|
createExtension() {
|
|
3570
3825
|
const extension = new NotarizationTeleportExtension({
|
|
3571
3826
|
onOpen: async () => {
|
|
3572
|
-
|
|
3827
|
+
log11("extension opened", {
|
|
3573
3828
|
peer: extension.localPeerId
|
|
3574
3829
|
}, {
|
|
3575
|
-
F:
|
|
3830
|
+
F: __dxlog_file14,
|
|
3576
3831
|
L: 211,
|
|
3577
3832
|
S: this,
|
|
3578
3833
|
C: (f, a) => f(...a)
|
|
@@ -3581,10 +3836,10 @@ var NotarizationPlugin = class {
|
|
|
3581
3836
|
this._extensionOpened.emit();
|
|
3582
3837
|
},
|
|
3583
3838
|
onClose: async () => {
|
|
3584
|
-
|
|
3839
|
+
log11("extension closed", {
|
|
3585
3840
|
peer: extension.localPeerId
|
|
3586
3841
|
}, {
|
|
3587
|
-
F:
|
|
3842
|
+
F: __dxlog_file14,
|
|
3588
3843
|
L: 216,
|
|
3589
3844
|
S: this,
|
|
3590
3845
|
C: (f, a) => f(...a)
|
|
@@ -3638,7 +3893,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3638
3893
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3639
3894
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3640
3895
|
}
|
|
3641
|
-
var
|
|
3896
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
3642
3897
|
var DataSpace = class {
|
|
3643
3898
|
constructor(params) {
|
|
3644
3899
|
this._ctx = new Context8();
|
|
@@ -3664,21 +3919,24 @@ var DataSpace = class {
|
|
|
3664
3919
|
this._callbacks = params.callbacks ?? {};
|
|
3665
3920
|
this._echoHost = params.echoHost;
|
|
3666
3921
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
3667
|
-
trustedKeysProvider: () => new ComplexSet5(PublicKey10.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !==
|
|
3922
|
+
trustedKeysProvider: () => new ComplexSet5(PublicKey10.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember4.Role.REMOVED).map((member) => member.key)),
|
|
3668
3923
|
update: this._inner.stateUpdate,
|
|
3669
3924
|
authTimeout: AUTH_TIMEOUT2
|
|
3670
3925
|
});
|
|
3671
3926
|
this._cache = params.cache;
|
|
3672
3927
|
this._state = params.initialState;
|
|
3673
|
-
|
|
3928
|
+
log12("new state", {
|
|
3674
3929
|
state: SpaceState[this._state]
|
|
3675
3930
|
}, {
|
|
3676
|
-
F:
|
|
3677
|
-
L:
|
|
3931
|
+
F: __dxlog_file15,
|
|
3932
|
+
L: 143,
|
|
3678
3933
|
S: this,
|
|
3679
3934
|
C: (f, a) => f(...a)
|
|
3680
3935
|
});
|
|
3681
3936
|
}
|
|
3937
|
+
get id() {
|
|
3938
|
+
return this._inner.id;
|
|
3939
|
+
}
|
|
3682
3940
|
get key() {
|
|
3683
3941
|
return this._inner.key;
|
|
3684
3942
|
}
|
|
@@ -3720,11 +3978,11 @@ var DataSpace = class {
|
|
|
3720
3978
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
3721
3979
|
await this._inner.open(new Context8());
|
|
3722
3980
|
this._state = SpaceState.CONTROL_ONLY;
|
|
3723
|
-
|
|
3981
|
+
log12("new state", {
|
|
3724
3982
|
state: SpaceState[this._state]
|
|
3725
3983
|
}, {
|
|
3726
|
-
F:
|
|
3727
|
-
L:
|
|
3984
|
+
F: __dxlog_file15,
|
|
3985
|
+
L: 206,
|
|
3728
3986
|
S: this,
|
|
3729
3987
|
C: (f, a) => f(...a)
|
|
3730
3988
|
});
|
|
@@ -3738,11 +3996,11 @@ var DataSpace = class {
|
|
|
3738
3996
|
async _close() {
|
|
3739
3997
|
await this._callbacks.beforeClose?.();
|
|
3740
3998
|
this._state = SpaceState.CLOSED;
|
|
3741
|
-
|
|
3999
|
+
log12("new state", {
|
|
3742
4000
|
state: SpaceState[this._state]
|
|
3743
4001
|
}, {
|
|
3744
|
-
F:
|
|
3745
|
-
L:
|
|
4002
|
+
F: __dxlog_file15,
|
|
4003
|
+
L: 220,
|
|
3746
4004
|
S: this,
|
|
3747
4005
|
C: (f, a) => f(...a)
|
|
3748
4006
|
});
|
|
@@ -3772,26 +4030,26 @@ var DataSpace = class {
|
|
|
3772
4030
|
await this.initializeDataPipeline();
|
|
3773
4031
|
} catch (err) {
|
|
3774
4032
|
if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
|
|
3775
|
-
|
|
3776
|
-
F:
|
|
3777
|
-
L:
|
|
4033
|
+
log12("data pipeline initialization cancelled", err, {
|
|
4034
|
+
F: __dxlog_file15,
|
|
4035
|
+
L: 253,
|
|
3778
4036
|
S: this,
|
|
3779
4037
|
C: (f, a) => f(...a)
|
|
3780
4038
|
});
|
|
3781
4039
|
return;
|
|
3782
4040
|
}
|
|
3783
|
-
|
|
3784
|
-
F:
|
|
3785
|
-
L:
|
|
4041
|
+
log12.error("Error initializing data pipeline", err, {
|
|
4042
|
+
F: __dxlog_file15,
|
|
4043
|
+
L: 257,
|
|
3786
4044
|
S: this,
|
|
3787
4045
|
C: (f, a) => f(...a)
|
|
3788
4046
|
});
|
|
3789
4047
|
this._state = SpaceState.ERROR;
|
|
3790
|
-
|
|
4048
|
+
log12("new state", {
|
|
3791
4049
|
state: SpaceState[this._state]
|
|
3792
4050
|
}, {
|
|
3793
|
-
F:
|
|
3794
|
-
L:
|
|
4051
|
+
F: __dxlog_file15,
|
|
4052
|
+
L: 259,
|
|
3795
4053
|
S: this,
|
|
3796
4054
|
C: (f, a) => f(...a)
|
|
3797
4055
|
});
|
|
@@ -3807,11 +4065,11 @@ var DataSpace = class {
|
|
|
3807
4065
|
throw new SystemError("Invalid operation");
|
|
3808
4066
|
}
|
|
3809
4067
|
this._state = SpaceState.INITIALIZING;
|
|
3810
|
-
|
|
4068
|
+
log12("new state", {
|
|
3811
4069
|
state: SpaceState[this._state]
|
|
3812
4070
|
}, {
|
|
3813
|
-
F:
|
|
3814
|
-
L:
|
|
4071
|
+
F: __dxlog_file15,
|
|
4072
|
+
L: 275,
|
|
3815
4073
|
S: this,
|
|
3816
4074
|
C: (f, a) => f(...a)
|
|
3817
4075
|
});
|
|
@@ -3819,19 +4077,19 @@ var DataSpace = class {
|
|
|
3819
4077
|
await sleep2(1);
|
|
3820
4078
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
3821
4079
|
await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
|
|
3822
|
-
|
|
3823
|
-
F:
|
|
3824
|
-
L:
|
|
4080
|
+
log12("data pipeline ready", void 0, {
|
|
4081
|
+
F: __dxlog_file15,
|
|
4082
|
+
L: 287,
|
|
3825
4083
|
S: this,
|
|
3826
4084
|
C: (f, a) => f(...a)
|
|
3827
4085
|
});
|
|
3828
4086
|
await this._callbacks.beforeReady?.();
|
|
3829
4087
|
this._state = SpaceState.READY;
|
|
3830
|
-
|
|
4088
|
+
log12("new state", {
|
|
3831
4089
|
state: SpaceState[this._state]
|
|
3832
4090
|
}, {
|
|
3833
|
-
F:
|
|
3834
|
-
L:
|
|
4091
|
+
F: __dxlog_file15,
|
|
4092
|
+
L: 291,
|
|
3835
4093
|
S: this,
|
|
3836
4094
|
C: (f, a) => f(...a)
|
|
3837
4095
|
});
|
|
@@ -3845,9 +4103,9 @@ var DataSpace = class {
|
|
|
3845
4103
|
});
|
|
3846
4104
|
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
3847
4105
|
await this._createWritableFeeds();
|
|
3848
|
-
|
|
3849
|
-
F:
|
|
3850
|
-
L:
|
|
4106
|
+
log12("writable feeds created", void 0, {
|
|
4107
|
+
F: __dxlog_file15,
|
|
4108
|
+
L: 307,
|
|
3851
4109
|
S: this,
|
|
3852
4110
|
C: (f, a) => f(...a)
|
|
3853
4111
|
});
|
|
@@ -3905,12 +4163,12 @@ var DataSpace = class {
|
|
|
3905
4163
|
}
|
|
3906
4164
|
}
|
|
3907
4165
|
_onNewAutomergeRoot(rootUrl) {
|
|
3908
|
-
|
|
4166
|
+
log12("loading automerge root doc for space", {
|
|
3909
4167
|
space: this.key,
|
|
3910
4168
|
rootUrl
|
|
3911
4169
|
}, {
|
|
3912
|
-
F:
|
|
3913
|
-
L:
|
|
4170
|
+
F: __dxlog_file15,
|
|
4171
|
+
L: 373,
|
|
3914
4172
|
S: this,
|
|
3915
4173
|
C: (f, a) => f(...a)
|
|
3916
4174
|
});
|
|
@@ -3935,12 +4193,12 @@ var DataSpace = class {
|
|
|
3935
4193
|
if (!this._echoHost.roots.has(handle.documentId)) {
|
|
3936
4194
|
await this._echoHost.openSpaceRoot(handle.url);
|
|
3937
4195
|
} else {
|
|
3938
|
-
|
|
4196
|
+
log12.warn("echo database root already exists", {
|
|
3939
4197
|
space: this.key,
|
|
3940
4198
|
rootUrl
|
|
3941
4199
|
}, {
|
|
3942
|
-
F:
|
|
3943
|
-
L:
|
|
4200
|
+
F: __dxlog_file15,
|
|
4201
|
+
L: 400,
|
|
3944
4202
|
S: this,
|
|
3945
4203
|
C: (f, a) => f(...a)
|
|
3946
4204
|
});
|
|
@@ -3949,13 +4207,13 @@ var DataSpace = class {
|
|
|
3949
4207
|
if (err instanceof ContextDisposedError3) {
|
|
3950
4208
|
return;
|
|
3951
4209
|
}
|
|
3952
|
-
|
|
4210
|
+
log12.warn("error loading automerge root doc", {
|
|
3953
4211
|
space: this.key,
|
|
3954
4212
|
rootUrl,
|
|
3955
4213
|
err
|
|
3956
4214
|
}, {
|
|
3957
|
-
F:
|
|
3958
|
-
L:
|
|
4215
|
+
F: __dxlog_file15,
|
|
4216
|
+
L: 406,
|
|
3959
4217
|
S: this,
|
|
3960
4218
|
C: (f, a) => f(...a)
|
|
3961
4219
|
});
|
|
@@ -4006,11 +4264,11 @@ var DataSpace = class {
|
|
|
4006
4264
|
{
|
|
4007
4265
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4008
4266
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4009
|
-
await cancelWithContext4(this._ctx,
|
|
4267
|
+
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4010
4268
|
const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
|
|
4011
|
-
|
|
4012
|
-
F:
|
|
4013
|
-
L:
|
|
4269
|
+
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4270
|
+
F: __dxlog_file15,
|
|
4271
|
+
L: 456,
|
|
4014
4272
|
S: this,
|
|
4015
4273
|
A: [
|
|
4016
4274
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
@@ -4027,21 +4285,21 @@ var DataSpace = class {
|
|
|
4027
4285
|
break;
|
|
4028
4286
|
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
|
|
4029
4287
|
{
|
|
4030
|
-
|
|
4031
|
-
F:
|
|
4032
|
-
L:
|
|
4288
|
+
log12.info("Fragmenting", void 0, {
|
|
4289
|
+
F: __dxlog_file15,
|
|
4290
|
+
L: 468,
|
|
4033
4291
|
S: this,
|
|
4034
4292
|
C: (f, a) => f(...a)
|
|
4035
4293
|
});
|
|
4036
4294
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4037
4295
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4038
|
-
await cancelWithContext4(this._ctx,
|
|
4296
|
+
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4039
4297
|
const objects = Object.entries(rootHandle.docSync().objects);
|
|
4040
4298
|
const properties = findPropertiesObject(rootHandle.docSync());
|
|
4041
4299
|
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
4042
|
-
|
|
4043
|
-
F:
|
|
4044
|
-
L:
|
|
4300
|
+
invariant13(properties, "Properties not found", {
|
|
4301
|
+
F: __dxlog_file15,
|
|
4302
|
+
L: 478,
|
|
4045
4303
|
S: this,
|
|
4046
4304
|
A: [
|
|
4047
4305
|
"properties",
|
|
@@ -4055,16 +4313,16 @@ var DataSpace = class {
|
|
|
4055
4313
|
])
|
|
4056
4314
|
};
|
|
4057
4315
|
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
4058
|
-
|
|
4059
|
-
F:
|
|
4060
|
-
L:
|
|
4316
|
+
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4317
|
+
F: __dxlog_file15,
|
|
4318
|
+
L: 483,
|
|
4061
4319
|
S: this,
|
|
4062
4320
|
A: [
|
|
4063
4321
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4064
4322
|
""
|
|
4065
4323
|
]
|
|
4066
4324
|
});
|
|
4067
|
-
const docLoader = new AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
|
|
4325
|
+
const docLoader = new AutomergeDocumentLoaderImpl(await createIdFromSpaceKey(this.key), this._echoHost.automergeRepo, this.key);
|
|
4068
4326
|
await docLoader.loadSpaceRootDocHandle(this._ctx, {
|
|
4069
4327
|
rootUrl: newRoot.url
|
|
4070
4328
|
});
|
|
@@ -4085,6 +4343,25 @@ var DataSpace = class {
|
|
|
4085
4343
|
};
|
|
4086
4344
|
}
|
|
4087
4345
|
break;
|
|
4346
|
+
case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT:
|
|
4347
|
+
{
|
|
4348
|
+
invariant13(options.newAutomergeRoot, void 0, {
|
|
4349
|
+
F: __dxlog_file15,
|
|
4350
|
+
L: 513,
|
|
4351
|
+
S: this,
|
|
4352
|
+
A: [
|
|
4353
|
+
"options.newAutomergeRoot",
|
|
4354
|
+
""
|
|
4355
|
+
]
|
|
4356
|
+
});
|
|
4357
|
+
epoch = {
|
|
4358
|
+
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
4359
|
+
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
4360
|
+
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe2(),
|
|
4361
|
+
automergeRoot: options.newAutomergeRoot
|
|
4362
|
+
};
|
|
4363
|
+
}
|
|
4364
|
+
break;
|
|
4088
4365
|
}
|
|
4089
4366
|
if (!epoch) {
|
|
4090
4367
|
return;
|
|
@@ -4106,6 +4383,7 @@ var DataSpace = class {
|
|
|
4106
4383
|
receipt.seq
|
|
4107
4384
|
]
|
|
4108
4385
|
]));
|
|
4386
|
+
await this._echoHost.updateIndexes();
|
|
4109
4387
|
}
|
|
4110
4388
|
async activate() {
|
|
4111
4389
|
if (this._state !== SpaceState.INACTIVE) {
|
|
@@ -4122,11 +4400,11 @@ var DataSpace = class {
|
|
|
4122
4400
|
await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
|
|
4123
4401
|
await this._close();
|
|
4124
4402
|
this._state = SpaceState.INACTIVE;
|
|
4125
|
-
|
|
4403
|
+
log12("new state", {
|
|
4126
4404
|
state: SpaceState[this._state]
|
|
4127
4405
|
}, {
|
|
4128
|
-
F:
|
|
4129
|
-
L:
|
|
4406
|
+
F: __dxlog_file15,
|
|
4407
|
+
L: 566,
|
|
4130
4408
|
S: this,
|
|
4131
4409
|
C: (f, a) => f(...a)
|
|
4132
4410
|
});
|
|
@@ -4136,6 +4414,9 @@ var DataSpace = class {
|
|
|
4136
4414
|
_ts_decorate4([
|
|
4137
4415
|
trace6.info()
|
|
4138
4416
|
], DataSpace.prototype, "_inner", void 0);
|
|
4417
|
+
_ts_decorate4([
|
|
4418
|
+
trace6.info()
|
|
4419
|
+
], DataSpace.prototype, "id", null);
|
|
4139
4420
|
_ts_decorate4([
|
|
4140
4421
|
trace6.info()
|
|
4141
4422
|
], DataSpace.prototype, "key", null);
|
|
@@ -4196,12 +4477,12 @@ import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeak
|
|
|
4196
4477
|
import { cancelWithContext as cancelWithContext5, Context as Context9 } from "@dxos/context";
|
|
4197
4478
|
import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
4198
4479
|
import { AuthStatus } from "@dxos/echo-pipeline";
|
|
4199
|
-
import { invariant as
|
|
4480
|
+
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4200
4481
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4201
|
-
import { log as
|
|
4482
|
+
import { log as log13 } from "@dxos/log";
|
|
4202
4483
|
import { trace as Trace2 } from "@dxos/protocols";
|
|
4203
4484
|
import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4204
|
-
import { SpaceMember as
|
|
4485
|
+
import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4205
4486
|
import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
|
|
4206
4487
|
import { trace as trace7 } from "@dxos/tracing";
|
|
4207
4488
|
import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
@@ -4209,7 +4490,7 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsyn
|
|
|
4209
4490
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
4210
4491
|
import { createCredential } from "@dxos/credentials";
|
|
4211
4492
|
import { failUndefined } from "@dxos/debug";
|
|
4212
|
-
import { AdmittedFeed as AdmittedFeed4, SpaceMember as
|
|
4493
|
+
import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4213
4494
|
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
4214
4495
|
var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
4215
4496
|
const credentials = [
|
|
@@ -4229,7 +4510,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
|
4229
4510
|
assertion: {
|
|
4230
4511
|
"@type": "dxos.halo.credentials.SpaceMember",
|
|
4231
4512
|
spaceKey: space.key,
|
|
4232
|
-
role:
|
|
4513
|
+
role: SpaceMember5.Role.OWNER,
|
|
4233
4514
|
profile: signingContext.getProfile(),
|
|
4234
4515
|
genesisFeedKey: space.controlFeedKey ?? failUndefined()
|
|
4235
4516
|
}
|
|
@@ -4287,7 +4568,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
4287
4568
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4288
4569
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4289
4570
|
}
|
|
4290
|
-
var
|
|
4571
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
4291
4572
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
4292
4573
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
4293
4574
|
var DataSpaceManager = class {
|
|
@@ -4335,45 +4616,45 @@ var DataSpaceManager = class {
|
|
|
4335
4616
|
return this._spaces;
|
|
4336
4617
|
}
|
|
4337
4618
|
async open() {
|
|
4338
|
-
|
|
4339
|
-
F:
|
|
4619
|
+
log13("open", void 0, {
|
|
4620
|
+
F: __dxlog_file16,
|
|
4340
4621
|
L: 144,
|
|
4341
4622
|
S: this,
|
|
4342
4623
|
C: (f, a) => f(...a)
|
|
4343
4624
|
});
|
|
4344
|
-
|
|
4625
|
+
log13.trace("dxos.echo.data-space-manager.open", Trace2.begin({
|
|
4345
4626
|
id: this._instanceId
|
|
4346
4627
|
}), {
|
|
4347
|
-
F:
|
|
4628
|
+
F: __dxlog_file16,
|
|
4348
4629
|
L: 145,
|
|
4349
4630
|
S: this,
|
|
4350
4631
|
C: (f, a) => f(...a)
|
|
4351
4632
|
});
|
|
4352
|
-
|
|
4633
|
+
log13("metadata loaded", {
|
|
4353
4634
|
spaces: this._metadataStore.spaces.length
|
|
4354
4635
|
}, {
|
|
4355
|
-
F:
|
|
4636
|
+
F: __dxlog_file16,
|
|
4356
4637
|
L: 146,
|
|
4357
4638
|
S: this,
|
|
4358
4639
|
C: (f, a) => f(...a)
|
|
4359
4640
|
});
|
|
4360
4641
|
await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
4361
4642
|
try {
|
|
4362
|
-
|
|
4643
|
+
log13("load space", {
|
|
4363
4644
|
spaceMetadata
|
|
4364
4645
|
}, {
|
|
4365
|
-
F:
|
|
4646
|
+
F: __dxlog_file16,
|
|
4366
4647
|
L: 150,
|
|
4367
4648
|
S: this,
|
|
4368
4649
|
C: (f, a) => f(...a)
|
|
4369
4650
|
});
|
|
4370
4651
|
await this._constructSpace(spaceMetadata);
|
|
4371
4652
|
} catch (err) {
|
|
4372
|
-
|
|
4653
|
+
log13.error("Error loading space", {
|
|
4373
4654
|
spaceMetadata,
|
|
4374
4655
|
err
|
|
4375
4656
|
}, {
|
|
4376
|
-
F:
|
|
4657
|
+
F: __dxlog_file16,
|
|
4377
4658
|
L: 153,
|
|
4378
4659
|
S: this,
|
|
4379
4660
|
C: (f, a) => f(...a)
|
|
@@ -4387,18 +4668,18 @@ var DataSpaceManager = class {
|
|
|
4387
4668
|
space.initializeDataPipelineAsync();
|
|
4388
4669
|
}
|
|
4389
4670
|
}
|
|
4390
|
-
|
|
4671
|
+
log13.trace("dxos.echo.data-space-manager.open", Trace2.end({
|
|
4391
4672
|
id: this._instanceId
|
|
4392
4673
|
}), {
|
|
4393
|
-
F:
|
|
4674
|
+
F: __dxlog_file16,
|
|
4394
4675
|
L: 166,
|
|
4395
4676
|
S: this,
|
|
4396
4677
|
C: (f, a) => f(...a)
|
|
4397
4678
|
});
|
|
4398
4679
|
}
|
|
4399
4680
|
async close() {
|
|
4400
|
-
|
|
4401
|
-
F:
|
|
4681
|
+
log13("close", void 0, {
|
|
4682
|
+
F: __dxlog_file16,
|
|
4402
4683
|
L: 171,
|
|
4403
4684
|
S: this,
|
|
4404
4685
|
C: (f, a) => f(...a)
|
|
@@ -4413,8 +4694,8 @@ var DataSpaceManager = class {
|
|
|
4413
4694
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
4414
4695
|
*/
|
|
4415
4696
|
async createSpace() {
|
|
4416
|
-
|
|
4417
|
-
F:
|
|
4697
|
+
invariant14(this._isOpen, "Not open.", {
|
|
4698
|
+
F: __dxlog_file16,
|
|
4418
4699
|
L: 184,
|
|
4419
4700
|
S: this,
|
|
4420
4701
|
A: [
|
|
@@ -4432,10 +4713,10 @@ var DataSpaceManager = class {
|
|
|
4432
4713
|
dataFeedKey,
|
|
4433
4714
|
state: SpaceState2.ACTIVE
|
|
4434
4715
|
};
|
|
4435
|
-
|
|
4716
|
+
log13("creating space...", {
|
|
4436
4717
|
spaceKey
|
|
4437
4718
|
}, {
|
|
4438
|
-
F:
|
|
4719
|
+
F: __dxlog_file16,
|
|
4439
4720
|
L: 196,
|
|
4440
4721
|
S: this,
|
|
4441
4722
|
C: (f, a) => f(...a)
|
|
@@ -4445,8 +4726,8 @@ var DataSpaceManager = class {
|
|
|
4445
4726
|
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
|
|
4446
4727
|
await this._metadataStore.addSpace(metadata);
|
|
4447
4728
|
const memberCredential = credentials[1];
|
|
4448
|
-
|
|
4449
|
-
F:
|
|
4729
|
+
invariant14(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
4730
|
+
F: __dxlog_file16,
|
|
4450
4731
|
L: 205,
|
|
4451
4732
|
S: this,
|
|
4452
4733
|
A: [
|
|
@@ -4461,16 +4742,16 @@ var DataSpaceManager = class {
|
|
|
4461
4742
|
}
|
|
4462
4743
|
// TODO(burdon): Rename join space.
|
|
4463
4744
|
async acceptSpace(opts) {
|
|
4464
|
-
|
|
4745
|
+
log13("accept space", {
|
|
4465
4746
|
opts
|
|
4466
4747
|
}, {
|
|
4467
|
-
F:
|
|
4748
|
+
F: __dxlog_file16,
|
|
4468
4749
|
L: 217,
|
|
4469
4750
|
S: this,
|
|
4470
4751
|
C: (f, a) => f(...a)
|
|
4471
4752
|
});
|
|
4472
|
-
|
|
4473
|
-
F:
|
|
4753
|
+
invariant14(this._isOpen, "Not open.", {
|
|
4754
|
+
F: __dxlog_file16,
|
|
4474
4755
|
L: 218,
|
|
4475
4756
|
S: this,
|
|
4476
4757
|
A: [
|
|
@@ -4478,8 +4759,8 @@ var DataSpaceManager = class {
|
|
|
4478
4759
|
"'Not open.'"
|
|
4479
4760
|
]
|
|
4480
4761
|
});
|
|
4481
|
-
|
|
4482
|
-
F:
|
|
4762
|
+
invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
4763
|
+
F: __dxlog_file16,
|
|
4483
4764
|
L: 219,
|
|
4484
4765
|
S: this,
|
|
4485
4766
|
A: [
|
|
@@ -4511,10 +4792,10 @@ var DataSpaceManager = class {
|
|
|
4511
4792
|
}));
|
|
4512
4793
|
}
|
|
4513
4794
|
async _constructSpace(metadata) {
|
|
4514
|
-
|
|
4795
|
+
log13("construct space", {
|
|
4515
4796
|
metadata
|
|
4516
4797
|
}, {
|
|
4517
|
-
F:
|
|
4798
|
+
F: __dxlog_file16,
|
|
4518
4799
|
L: 252,
|
|
4519
4800
|
S: this,
|
|
4520
4801
|
C: (f, a) => f(...a)
|
|
@@ -4551,8 +4832,8 @@ var DataSpaceManager = class {
|
|
|
4551
4832
|
session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
|
|
4552
4833
|
},
|
|
4553
4834
|
onAuthFailure: () => {
|
|
4554
|
-
|
|
4555
|
-
F:
|
|
4835
|
+
log13.warn("auth failure", void 0, {
|
|
4836
|
+
F: __dxlog_file16,
|
|
4556
4837
|
L: 289,
|
|
4557
4838
|
S: this,
|
|
4558
4839
|
C: (f, a) => f(...a)
|
|
@@ -4582,21 +4863,21 @@ var DataSpaceManager = class {
|
|
|
4582
4863
|
signingContext: this._signingContext,
|
|
4583
4864
|
callbacks: {
|
|
4584
4865
|
beforeReady: async () => {
|
|
4585
|
-
|
|
4866
|
+
log13("before space ready", {
|
|
4586
4867
|
space: space.key
|
|
4587
4868
|
}, {
|
|
4588
|
-
F:
|
|
4869
|
+
F: __dxlog_file16,
|
|
4589
4870
|
L: 316,
|
|
4590
4871
|
S: this,
|
|
4591
4872
|
C: (f, a) => f(...a)
|
|
4592
4873
|
});
|
|
4593
4874
|
},
|
|
4594
4875
|
afterReady: async () => {
|
|
4595
|
-
|
|
4876
|
+
log13("after space ready", {
|
|
4596
4877
|
space: space.key,
|
|
4597
4878
|
open: this._isOpen
|
|
4598
4879
|
}, {
|
|
4599
|
-
F:
|
|
4880
|
+
F: __dxlog_file16,
|
|
4600
4881
|
L: 319,
|
|
4601
4882
|
S: this,
|
|
4602
4883
|
C: (f, a) => f(...a)
|
|
@@ -4612,10 +4893,10 @@ var DataSpaceManager = class {
|
|
|
4612
4893
|
}
|
|
4613
4894
|
},
|
|
4614
4895
|
beforeClose: async () => {
|
|
4615
|
-
|
|
4896
|
+
log13("before space close", {
|
|
4616
4897
|
space: space.key
|
|
4617
4898
|
}, {
|
|
4618
|
-
F:
|
|
4899
|
+
F: __dxlog_file16,
|
|
4619
4900
|
L: 327,
|
|
4620
4901
|
S: this,
|
|
4621
4902
|
C: (f, a) => f(...a)
|
|
@@ -4647,19 +4928,19 @@ var DataSpaceManager = class {
|
|
|
4647
4928
|
const peers = presence.getPeersByIdentityKey(member.key);
|
|
4648
4929
|
const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
|
|
4649
4930
|
const sessionsToClose = sessions.filter((s) => {
|
|
4650
|
-
return (s && member.role ===
|
|
4931
|
+
return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
|
|
4651
4932
|
});
|
|
4652
4933
|
sessionsToClose.forEach((session) => {
|
|
4653
|
-
void session.close().catch(
|
|
4934
|
+
void session.close().catch(log13.error);
|
|
4654
4935
|
});
|
|
4655
4936
|
closedSessions += sessionsToClose.length;
|
|
4656
4937
|
}
|
|
4657
|
-
|
|
4938
|
+
log13("processed member role changes", {
|
|
4658
4939
|
roleChangeCount: memberInfo.length,
|
|
4659
4940
|
peersOnline: presence.getPeersOnline().length,
|
|
4660
4941
|
closedSessions
|
|
4661
4942
|
}, {
|
|
4662
|
-
F:
|
|
4943
|
+
F: __dxlog_file16,
|
|
4663
4944
|
L: 367,
|
|
4664
4945
|
S: this,
|
|
4665
4946
|
C: (f, a) => f(...a)
|
|
@@ -4668,18 +4949,18 @@ var DataSpaceManager = class {
|
|
|
4668
4949
|
}
|
|
4669
4950
|
_handleNewPeerConnected(space, peerState) {
|
|
4670
4951
|
const role = space.spaceState.getMemberRole(peerState.identityKey);
|
|
4671
|
-
if (role ===
|
|
4952
|
+
if (role === SpaceMember6.Role.REMOVED) {
|
|
4672
4953
|
const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
|
|
4673
4954
|
if (session != null) {
|
|
4674
|
-
|
|
4955
|
+
log13("closing a session with a removed peer", {
|
|
4675
4956
|
peerId: peerState.peerId
|
|
4676
4957
|
}, {
|
|
4677
|
-
F:
|
|
4958
|
+
F: __dxlog_file16,
|
|
4678
4959
|
L: 381,
|
|
4679
4960
|
S: this,
|
|
4680
4961
|
C: (f, a) => f(...a)
|
|
4681
4962
|
});
|
|
4682
|
-
void session.close().catch(
|
|
4963
|
+
void session.close().catch(log13.error);
|
|
4683
4964
|
}
|
|
4684
4965
|
}
|
|
4685
4966
|
}
|
|
@@ -4741,12 +5022,12 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
|
4741
5022
|
import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
|
|
4742
5023
|
import { raise as raise2 } from "@dxos/debug";
|
|
4743
5024
|
import { writeMessages as writeMessages3 } from "@dxos/feed-store";
|
|
4744
|
-
import { invariant as
|
|
4745
|
-
import { log as
|
|
5025
|
+
import { invariant as invariant15 } from "@dxos/invariant";
|
|
5026
|
+
import { log as log14 } from "@dxos/log";
|
|
4746
5027
|
import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
|
|
4747
|
-
import { SpaceMember as
|
|
5028
|
+
import { SpaceMember as SpaceMember7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4748
5029
|
import { trace as trace8 } from "@dxos/tracing";
|
|
4749
|
-
var
|
|
5030
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
4750
5031
|
var SpacesServiceImpl = class {
|
|
4751
5032
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
4752
5033
|
this._identityManager = _identityManager;
|
|
@@ -4789,8 +5070,8 @@ var SpacesServiceImpl = class {
|
|
|
4789
5070
|
});
|
|
4790
5071
|
}
|
|
4791
5072
|
const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
|
|
4792
|
-
|
|
4793
|
-
F:
|
|
5073
|
+
invariant15(credentials[0].credential, void 0, {
|
|
5074
|
+
F: __dxlog_file17,
|
|
4794
5075
|
L: 97,
|
|
4795
5076
|
S: this,
|
|
4796
5077
|
A: [
|
|
@@ -4799,8 +5080,8 @@ var SpacesServiceImpl = class {
|
|
|
4799
5080
|
]
|
|
4800
5081
|
});
|
|
4801
5082
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
4802
|
-
|
|
4803
|
-
F:
|
|
5083
|
+
invariant15(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5084
|
+
F: __dxlog_file17,
|
|
4804
5085
|
L: 99,
|
|
4805
5086
|
S: this,
|
|
4806
5087
|
A: [
|
|
@@ -4815,10 +5096,10 @@ var SpacesServiceImpl = class {
|
|
|
4815
5096
|
const scheduler = new UpdateScheduler(ctx, async () => {
|
|
4816
5097
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4817
5098
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
4818
|
-
|
|
5099
|
+
log14("update", {
|
|
4819
5100
|
spaces
|
|
4820
5101
|
}, {
|
|
4821
|
-
F:
|
|
5102
|
+
F: __dxlog_file17,
|
|
4822
5103
|
L: 110,
|
|
4823
5104
|
S: this,
|
|
4824
5105
|
C: (f, a) => f(...a)
|
|
@@ -4901,8 +5182,8 @@ var SpacesServiceImpl = class {
|
|
|
4901
5182
|
}
|
|
4902
5183
|
});
|
|
4903
5184
|
} else {
|
|
4904
|
-
|
|
4905
|
-
F:
|
|
5185
|
+
invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
|
|
5186
|
+
F: __dxlog_file17,
|
|
4906
5187
|
L: 198,
|
|
4907
5188
|
S: this,
|
|
4908
5189
|
A: [
|
|
@@ -4910,8 +5191,8 @@ var SpacesServiceImpl = class {
|
|
|
4910
5191
|
"'Id on unsigned credentials is not allowed'"
|
|
4911
5192
|
]
|
|
4912
5193
|
});
|
|
4913
|
-
|
|
4914
|
-
F:
|
|
5194
|
+
invariant15(this._identityManager.identity, "Identity is not available", {
|
|
5195
|
+
F: __dxlog_file17,
|
|
4915
5196
|
L: 199,
|
|
4916
5197
|
S: this,
|
|
4917
5198
|
A: [
|
|
@@ -4920,8 +5201,8 @@ var SpacesServiceImpl = class {
|
|
|
4920
5201
|
]
|
|
4921
5202
|
});
|
|
4922
5203
|
const signer = this._identityManager.identity.getIdentityCredentialSigner();
|
|
4923
|
-
|
|
4924
|
-
F:
|
|
5204
|
+
invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
|
|
5205
|
+
F: __dxlog_file17,
|
|
4925
5206
|
L: 201,
|
|
4926
5207
|
S: this,
|
|
4927
5208
|
A: [
|
|
@@ -4941,15 +5222,17 @@ var SpacesServiceImpl = class {
|
|
|
4941
5222
|
}
|
|
4942
5223
|
}
|
|
4943
5224
|
}
|
|
4944
|
-
async createEpoch({ spaceKey, migration }) {
|
|
5225
|
+
async createEpoch({ spaceKey, migration, automergeRootUrl }) {
|
|
4945
5226
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4946
5227
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
|
|
4947
5228
|
await space.createEpoch({
|
|
4948
|
-
migration
|
|
5229
|
+
migration,
|
|
5230
|
+
newAutomergeRoot: automergeRootUrl
|
|
4949
5231
|
});
|
|
4950
5232
|
}
|
|
4951
5233
|
_serializeSpace(space) {
|
|
4952
5234
|
return {
|
|
5235
|
+
id: space.id,
|
|
4953
5236
|
spaceKey: space.key,
|
|
4954
5237
|
state: space.state,
|
|
4955
5238
|
error: space.error ? encodeError(space.error) : void 0,
|
|
@@ -4978,7 +5261,7 @@ var SpacesServiceImpl = class {
|
|
|
4978
5261
|
profile: member.profile ?? {}
|
|
4979
5262
|
},
|
|
4980
5263
|
role: member.role,
|
|
4981
|
-
presence: peers.length > 0 ?
|
|
5264
|
+
presence: peers.length > 0 ? SpaceMember7.PresenceState.ONLINE : SpaceMember7.PresenceState.OFFLINE,
|
|
4982
5265
|
peerStates: peers
|
|
4983
5266
|
};
|
|
4984
5267
|
}),
|
|
@@ -5008,18 +5291,18 @@ var SpacesServiceImpl = class {
|
|
|
5008
5291
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
5009
5292
|
|
|
5010
5293
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
5011
|
-
import { Trigger as
|
|
5294
|
+
import { Trigger as Trigger7 } from "@dxos/async";
|
|
5012
5295
|
import { Context as Context10, Resource } from "@dxos/context";
|
|
5013
5296
|
import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
|
|
5014
5297
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
5015
5298
|
import { EchoHost } from "@dxos/echo-db";
|
|
5016
5299
|
import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
5017
5300
|
import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
5018
|
-
import { invariant as
|
|
5301
|
+
import { invariant as invariant16 } from "@dxos/invariant";
|
|
5019
5302
|
import { Keyring } from "@dxos/keyring";
|
|
5020
5303
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5021
|
-
import { log as
|
|
5022
|
-
import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace9 } from "@dxos/protocols";
|
|
5304
|
+
import { log as log15 } from "@dxos/log";
|
|
5305
|
+
import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
|
|
5023
5306
|
import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5024
5307
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
5025
5308
|
import { trace as Trace3 } from "@dxos/tracing";
|
|
@@ -5034,7 +5317,7 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
5034
5317
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5035
5318
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5036
5319
|
}
|
|
5037
|
-
var
|
|
5320
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
5038
5321
|
var ServiceContext = class extends Resource {
|
|
5039
5322
|
constructor(storage, level, networkManager, signalManager, _runtimeParams) {
|
|
5040
5323
|
super();
|
|
@@ -5043,7 +5326,7 @@ var ServiceContext = class extends Resource {
|
|
|
5043
5326
|
this.networkManager = networkManager;
|
|
5044
5327
|
this.signalManager = signalManager;
|
|
5045
5328
|
this._runtimeParams = _runtimeParams;
|
|
5046
|
-
this.initialized = new
|
|
5329
|
+
this.initialized = new Trigger7();
|
|
5047
5330
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
5048
5331
|
this._instanceId = PublicKey12.random().toHex();
|
|
5049
5332
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
@@ -5078,16 +5361,16 @@ var ServiceContext = class extends Resource {
|
|
|
5078
5361
|
}
|
|
5079
5362
|
async _open(ctx) {
|
|
5080
5363
|
await this._checkStorageVersion();
|
|
5081
|
-
|
|
5082
|
-
F:
|
|
5364
|
+
log15("opening...", void 0, {
|
|
5365
|
+
F: __dxlog_file18,
|
|
5083
5366
|
L: 152,
|
|
5084
5367
|
S: this,
|
|
5085
5368
|
C: (f, a) => f(...a)
|
|
5086
5369
|
});
|
|
5087
|
-
|
|
5370
|
+
log15.trace("dxos.sdk.service-context.open", trace9.begin({
|
|
5088
5371
|
id: this._instanceId
|
|
5089
5372
|
}), {
|
|
5090
|
-
F:
|
|
5373
|
+
F: __dxlog_file18,
|
|
5091
5374
|
L: 153,
|
|
5092
5375
|
S: this,
|
|
5093
5376
|
C: (f, a) => f(...a)
|
|
@@ -5102,32 +5385,32 @@ var ServiceContext = class extends Resource {
|
|
|
5102
5385
|
await this._initialize(ctx);
|
|
5103
5386
|
}
|
|
5104
5387
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
5105
|
-
|
|
5388
|
+
log15("loaded persistent invitations", {
|
|
5106
5389
|
count: loadedInvitations.invitations?.length
|
|
5107
5390
|
}, {
|
|
5108
|
-
F:
|
|
5391
|
+
F: __dxlog_file18,
|
|
5109
5392
|
L: 166,
|
|
5110
5393
|
S: this,
|
|
5111
5394
|
C: (f, a) => f(...a)
|
|
5112
5395
|
});
|
|
5113
|
-
|
|
5396
|
+
log15.trace("dxos.sdk.service-context.open", trace9.end({
|
|
5114
5397
|
id: this._instanceId
|
|
5115
5398
|
}), {
|
|
5116
|
-
F:
|
|
5399
|
+
F: __dxlog_file18,
|
|
5117
5400
|
L: 168,
|
|
5118
5401
|
S: this,
|
|
5119
5402
|
C: (f, a) => f(...a)
|
|
5120
5403
|
});
|
|
5121
|
-
|
|
5122
|
-
F:
|
|
5404
|
+
log15("opened", void 0, {
|
|
5405
|
+
F: __dxlog_file18,
|
|
5123
5406
|
L: 169,
|
|
5124
5407
|
S: this,
|
|
5125
5408
|
C: (f, a) => f(...a)
|
|
5126
5409
|
});
|
|
5127
5410
|
}
|
|
5128
5411
|
async _close(ctx) {
|
|
5129
|
-
|
|
5130
|
-
F:
|
|
5412
|
+
log15("closing...", void 0, {
|
|
5413
|
+
F: __dxlog_file18,
|
|
5131
5414
|
L: 173,
|
|
5132
5415
|
S: this,
|
|
5133
5416
|
C: (f, a) => f(...a)
|
|
@@ -5143,8 +5426,8 @@ var ServiceContext = class extends Resource {
|
|
|
5143
5426
|
await this.echoHost.close(ctx);
|
|
5144
5427
|
await this.networkManager.close();
|
|
5145
5428
|
await this.signalManager.close();
|
|
5146
|
-
|
|
5147
|
-
F:
|
|
5429
|
+
log15("closed", void 0, {
|
|
5430
|
+
F: __dxlog_file18,
|
|
5148
5431
|
L: 185,
|
|
5149
5432
|
S: this,
|
|
5150
5433
|
C: (f, a) => f(...a)
|
|
@@ -5157,8 +5440,8 @@ var ServiceContext = class extends Resource {
|
|
|
5157
5440
|
}
|
|
5158
5441
|
getInvitationHandler(invitation) {
|
|
5159
5442
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
5160
|
-
|
|
5161
|
-
F:
|
|
5443
|
+
invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
5444
|
+
F: __dxlog_file18,
|
|
5162
5445
|
L: 196,
|
|
5163
5446
|
S: this,
|
|
5164
5447
|
A: [
|
|
@@ -5183,14 +5466,14 @@ var ServiceContext = class extends Resource {
|
|
|
5183
5466
|
}
|
|
5184
5467
|
async _checkStorageVersion() {
|
|
5185
5468
|
await this.metadataStore.load();
|
|
5186
|
-
if (this.metadataStore.version !==
|
|
5187
|
-
throw new InvalidStorageVersionError(
|
|
5469
|
+
if (this.metadataStore.version !== STORAGE_VERSION2) {
|
|
5470
|
+
throw new InvalidStorageVersionError(STORAGE_VERSION2, this.metadataStore.version);
|
|
5188
5471
|
}
|
|
5189
5472
|
}
|
|
5190
5473
|
// Called when identity is created.
|
|
5191
5474
|
async _initialize(ctx) {
|
|
5192
|
-
|
|
5193
|
-
F:
|
|
5475
|
+
log15("initializing spaces...", void 0, {
|
|
5476
|
+
F: __dxlog_file18,
|
|
5194
5477
|
L: 227,
|
|
5195
5478
|
S: this,
|
|
5196
5479
|
C: (f, a) => f(...a)
|
|
@@ -5212,8 +5495,8 @@ var ServiceContext = class extends Resource {
|
|
|
5212
5495
|
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
|
|
5213
5496
|
await this.dataSpaceManager.open();
|
|
5214
5497
|
this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
|
|
5215
|
-
|
|
5216
|
-
F:
|
|
5498
|
+
invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
5499
|
+
F: __dxlog_file18,
|
|
5217
5500
|
L: 252,
|
|
5218
5501
|
S: this,
|
|
5219
5502
|
A: [
|
|
@@ -5234,10 +5517,10 @@ var ServiceContext = class extends Resource {
|
|
|
5234
5517
|
return;
|
|
5235
5518
|
}
|
|
5236
5519
|
if (!this.dataSpaceManager) {
|
|
5237
|
-
|
|
5520
|
+
log15("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
5238
5521
|
details: assertion
|
|
5239
5522
|
}, {
|
|
5240
|
-
F:
|
|
5523
|
+
F: __dxlog_file18,
|
|
5241
5524
|
L: 268,
|
|
5242
5525
|
S: this,
|
|
5243
5526
|
C: (f, a) => f(...a)
|
|
@@ -5245,10 +5528,10 @@ var ServiceContext = class extends Resource {
|
|
|
5245
5528
|
return;
|
|
5246
5529
|
}
|
|
5247
5530
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
5248
|
-
|
|
5531
|
+
log15("space already exists, ignoring space admission", {
|
|
5249
5532
|
details: assertion
|
|
5250
5533
|
}, {
|
|
5251
|
-
F:
|
|
5534
|
+
F: __dxlog_file18,
|
|
5252
5535
|
L: 272,
|
|
5253
5536
|
S: this,
|
|
5254
5537
|
C: (f, a) => f(...a)
|
|
@@ -5256,10 +5539,10 @@ var ServiceContext = class extends Resource {
|
|
|
5256
5539
|
return;
|
|
5257
5540
|
}
|
|
5258
5541
|
try {
|
|
5259
|
-
|
|
5542
|
+
log15("accepting space recorded in halo", {
|
|
5260
5543
|
details: assertion
|
|
5261
5544
|
}, {
|
|
5262
|
-
F:
|
|
5545
|
+
F: __dxlog_file18,
|
|
5263
5546
|
L: 277,
|
|
5264
5547
|
S: this,
|
|
5265
5548
|
C: (f, a) => f(...a)
|
|
@@ -5269,8 +5552,8 @@ var ServiceContext = class extends Resource {
|
|
|
5269
5552
|
genesisFeedKey: assertion.genesisFeedKey
|
|
5270
5553
|
});
|
|
5271
5554
|
} catch (err) {
|
|
5272
|
-
|
|
5273
|
-
F:
|
|
5555
|
+
log15.catch(err, void 0, {
|
|
5556
|
+
F: __dxlog_file18,
|
|
5274
5557
|
L: 283,
|
|
5275
5558
|
S: this,
|
|
5276
5559
|
C: (f, a) => f(...a)
|
|
@@ -5316,281 +5599,218 @@ var ServiceRegistry = class {
|
|
|
5316
5599
|
}
|
|
5317
5600
|
};
|
|
5318
5601
|
|
|
5319
|
-
// packages/sdk/client-services/src/packlets/
|
|
5320
|
-
import { asyncTimeout as
|
|
5321
|
-
import {
|
|
5322
|
-
import {
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
var
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
};
|
|
5347
|
-
}
|
|
5348
|
-
} else {
|
|
5349
|
-
const { platform: platform2, version, arch } = process;
|
|
5350
|
-
return {
|
|
5351
|
-
type: Platform.PLATFORM_TYPE.NODE,
|
|
5352
|
-
platform: platform2,
|
|
5353
|
-
arch,
|
|
5354
|
-
runtime: version,
|
|
5355
|
-
uptime: Math.floor(process.uptime()),
|
|
5356
|
-
memory: process.memoryUsage()
|
|
5357
|
-
};
|
|
5602
|
+
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5603
|
+
import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
|
|
5604
|
+
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5605
|
+
import { log as log16, logInfo } from "@dxos/log";
|
|
5606
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
5607
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5608
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
5609
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5610
|
+
else
|
|
5611
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
5612
|
+
if (d = decorators[i])
|
|
5613
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5614
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5615
|
+
}
|
|
5616
|
+
var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5617
|
+
var Message;
|
|
5618
|
+
(function(Message2) {
|
|
5619
|
+
Message2["ACQUIRING"] = "acquiring";
|
|
5620
|
+
})(Message || (Message = {}));
|
|
5621
|
+
var Lock = class {
|
|
5622
|
+
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5623
|
+
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5624
|
+
this._releaseTrigger = new Trigger8();
|
|
5625
|
+
this._lockKey = lockKey;
|
|
5626
|
+
this._onAcquire = onAcquire;
|
|
5627
|
+
this._onRelease = onRelease;
|
|
5628
|
+
this._broadcastChannel.onmessage = this._onMessage.bind(this);
|
|
5358
5629
|
}
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
}
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5630
|
+
get lockKey() {
|
|
5631
|
+
return this._lockKey;
|
|
5632
|
+
}
|
|
5633
|
+
async acquire() {
|
|
5634
|
+
this._broadcastChannel.postMessage({
|
|
5635
|
+
message: "acquiring"
|
|
5636
|
+
});
|
|
5637
|
+
try {
|
|
5638
|
+
log16("aquiring lock...", void 0, {
|
|
5639
|
+
F: __dxlog_file19,
|
|
5640
|
+
L: 42,
|
|
5641
|
+
S: this,
|
|
5642
|
+
C: (f, a) => f(...a)
|
|
5643
|
+
});
|
|
5644
|
+
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5645
|
+
log16("acquired lock", void 0, {
|
|
5646
|
+
F: __dxlog_file19,
|
|
5647
|
+
L: 44,
|
|
5648
|
+
S: this,
|
|
5649
|
+
C: (f, a) => f(...a)
|
|
5650
|
+
});
|
|
5651
|
+
} catch {
|
|
5652
|
+
log16("stealing lock...", void 0, {
|
|
5653
|
+
F: __dxlog_file19,
|
|
5654
|
+
L: 46,
|
|
5655
|
+
S: this,
|
|
5656
|
+
C: (f, a) => f(...a)
|
|
5657
|
+
});
|
|
5658
|
+
await this._requestLock(true);
|
|
5659
|
+
log16("stolen lock", void 0, {
|
|
5660
|
+
F: __dxlog_file19,
|
|
5661
|
+
L: 48,
|
|
5662
|
+
S: this,
|
|
5663
|
+
C: (f, a) => f(...a)
|
|
5386
5664
|
});
|
|
5387
|
-
diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
|
|
5388
|
-
timeout: DEFAULT_TIMEOUT
|
|
5389
|
-
}).catch(() => void 0);
|
|
5390
|
-
})(),
|
|
5391
|
-
(async () => {
|
|
5392
|
-
diagnostics.storage = await asyncTimeout2(getStorageDiagnostics(), DEFAULT_TIMEOUT).catch(() => void 0);
|
|
5393
|
-
})(),
|
|
5394
|
-
async () => {
|
|
5395
|
-
const identity = serviceContext.identityManager.identity;
|
|
5396
|
-
if (identity) {
|
|
5397
|
-
diagnostics.identity = {
|
|
5398
|
-
identityKey: identity.identityKey,
|
|
5399
|
-
spaceKey: identity.space.key,
|
|
5400
|
-
profile: identity.profileDocument
|
|
5401
|
-
};
|
|
5402
|
-
const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
|
|
5403
|
-
timeout: DEFAULT_TIMEOUT
|
|
5404
|
-
}).catch(() => void 0) ?? {};
|
|
5405
|
-
diagnostics.devices = devices;
|
|
5406
|
-
if (serviceContext.dataSpaceManager) {
|
|
5407
|
-
diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
|
|
5408
|
-
}
|
|
5409
|
-
const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
|
|
5410
|
-
timeout: DEFAULT_TIMEOUT
|
|
5411
|
-
}).catch(() => void 0) ?? {};
|
|
5412
|
-
diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
|
|
5413
|
-
feedKey,
|
|
5414
|
-
bytes,
|
|
5415
|
-
length
|
|
5416
|
-
}));
|
|
5417
|
-
const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
|
|
5418
|
-
timeout: DEFAULT_TIMEOUT
|
|
5419
|
-
}).catch(() => void 0);
|
|
5420
|
-
diagnostics.networkStatus = status;
|
|
5421
|
-
diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
|
|
5422
|
-
}
|
|
5423
5665
|
}
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
}
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
metrics: space.metrics,
|
|
5432
|
-
epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
|
|
5433
|
-
...credential.subject.assertion,
|
|
5434
|
-
id: credential.id
|
|
5435
|
-
})),
|
|
5436
|
-
members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
|
|
5437
|
-
role: member.role,
|
|
5438
|
-
identity: {
|
|
5439
|
-
identityKey: member.key,
|
|
5440
|
-
profile: {
|
|
5441
|
-
displayName: member.assertion.profile?.displayName
|
|
5442
|
-
}
|
|
5443
|
-
},
|
|
5444
|
-
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember7.PresenceState.ONLINE : SpaceMember7.PresenceState.OFFLINE
|
|
5445
|
-
})),
|
|
5446
|
-
pipeline: {
|
|
5447
|
-
// TODO(burdon): Pick properties from credentials if needed.
|
|
5448
|
-
currentEpoch: space.automergeSpaceState.lastEpoch,
|
|
5449
|
-
appliedEpoch: space.automergeSpaceState.lastEpoch,
|
|
5450
|
-
controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
|
|
5451
|
-
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
5452
|
-
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
5453
|
-
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
|
|
5666
|
+
}
|
|
5667
|
+
async release() {
|
|
5668
|
+
this._releaseTrigger.wake();
|
|
5669
|
+
}
|
|
5670
|
+
_onMessage(event) {
|
|
5671
|
+
if (event.data.message === "acquiring") {
|
|
5672
|
+
this._releaseTrigger.wake();
|
|
5454
5673
|
}
|
|
5455
|
-
};
|
|
5456
|
-
if (stats.metrics) {
|
|
5457
|
-
const { open, ready } = stats.metrics;
|
|
5458
|
-
stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
|
|
5459
5674
|
}
|
|
5460
|
-
|
|
5675
|
+
async _requestLock(steal = false) {
|
|
5676
|
+
log16("requesting lock...", {
|
|
5677
|
+
steal
|
|
5678
|
+
}, {
|
|
5679
|
+
F: __dxlog_file19,
|
|
5680
|
+
L: 63,
|
|
5681
|
+
S: this,
|
|
5682
|
+
C: (f, a) => f(...a)
|
|
5683
|
+
});
|
|
5684
|
+
const acquired = new Trigger8();
|
|
5685
|
+
void navigator.locks.request(this._lockKey, {
|
|
5686
|
+
steal
|
|
5687
|
+
}, async () => {
|
|
5688
|
+
await this._onAcquire?.();
|
|
5689
|
+
acquired.wake();
|
|
5690
|
+
this._releaseTrigger = new Trigger8();
|
|
5691
|
+
await this._releaseTrigger.wait();
|
|
5692
|
+
log16("releasing lock...", void 0, {
|
|
5693
|
+
F: __dxlog_file19,
|
|
5694
|
+
L: 72,
|
|
5695
|
+
S: this,
|
|
5696
|
+
C: (f, a) => f(...a)
|
|
5697
|
+
});
|
|
5698
|
+
await this._onRelease?.();
|
|
5699
|
+
log16("released lock", void 0, {
|
|
5700
|
+
F: __dxlog_file19,
|
|
5701
|
+
L: 74,
|
|
5702
|
+
S: this,
|
|
5703
|
+
C: (f, a) => f(...a)
|
|
5704
|
+
});
|
|
5705
|
+
}).catch(async () => {
|
|
5706
|
+
await this._onRelease?.();
|
|
5707
|
+
});
|
|
5708
|
+
await acquired.wait();
|
|
5709
|
+
log16("recieved lock", {
|
|
5710
|
+
steal
|
|
5711
|
+
}, {
|
|
5712
|
+
F: __dxlog_file19,
|
|
5713
|
+
L: 81,
|
|
5714
|
+
S: this,
|
|
5715
|
+
C: (f, a) => f(...a)
|
|
5716
|
+
});
|
|
5717
|
+
}
|
|
5461
5718
|
};
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
const dir = await navigator.storage.getDirectory();
|
|
5468
|
-
for await (const filename of dir?.keys()) {
|
|
5469
|
-
const idx = filename.indexOf("-", filename.indexOf("-") + 1);
|
|
5470
|
-
if (idx === -1) {
|
|
5471
|
-
continue;
|
|
5472
|
-
}
|
|
5473
|
-
map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
|
|
5474
|
-
}
|
|
5475
|
-
return Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
|
|
5476
|
-
file,
|
|
5477
|
-
count
|
|
5478
|
-
}));
|
|
5719
|
+
_ts_decorate7([
|
|
5720
|
+
logInfo
|
|
5721
|
+
], Lock.prototype, "lockKey", null);
|
|
5722
|
+
var isLocked = (lockPath) => {
|
|
5723
|
+
throw new Error("Not implemented");
|
|
5479
5724
|
};
|
|
5480
5725
|
|
|
5481
|
-
// packages/sdk/client-services/src/packlets/
|
|
5482
|
-
import {
|
|
5483
|
-
import {
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
var createCollectDiagnosticsBroadcastSender = () => {
|
|
5494
|
-
return {
|
|
5495
|
-
broadcastDiagnosticsRequest: async () => {
|
|
5496
|
-
let expectedResponse = "probe-ack";
|
|
5497
|
-
let channel;
|
|
5498
|
-
try {
|
|
5499
|
-
const trigger = new Trigger7();
|
|
5500
|
-
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
5501
|
-
channel.onmessage = (msg) => {
|
|
5502
|
-
if (expectedResponse === msg.data.type) {
|
|
5503
|
-
trigger.wake(msg.data);
|
|
5504
|
-
}
|
|
5505
|
-
};
|
|
5506
|
-
channel.postMessage({
|
|
5507
|
-
type: "probe"
|
|
5508
|
-
});
|
|
5509
|
-
await trigger.wait({
|
|
5510
|
-
timeout: 200
|
|
5511
|
-
});
|
|
5512
|
-
expectedResponse = "receive-diagnostics";
|
|
5513
|
-
trigger.reset();
|
|
5514
|
-
channel.postMessage({
|
|
5515
|
-
type: "request-diagnostics"
|
|
5516
|
-
});
|
|
5517
|
-
const diagnostics = await trigger.wait({
|
|
5518
|
-
timeout: 5e3
|
|
5519
|
-
});
|
|
5520
|
-
return diagnostics.payload;
|
|
5521
|
-
} catch (e) {
|
|
5522
|
-
const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5523
|
-
return {
|
|
5524
|
-
expectedResponse,
|
|
5525
|
-
errorDescription
|
|
5526
|
-
};
|
|
5527
|
-
} finally {
|
|
5528
|
-
safeClose(channel);
|
|
5529
|
-
}
|
|
5530
|
-
}
|
|
5531
|
-
};
|
|
5726
|
+
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5727
|
+
import { InvalidConfigError } from "@dxos/protocols";
|
|
5728
|
+
import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
|
|
5729
|
+
import { createStorage, StorageType } from "@dxos/random-access-storage";
|
|
5730
|
+
|
|
5731
|
+
// packages/sdk/client-services/src/packlets/storage/util.ts
|
|
5732
|
+
import { DX_DATA } from "@dxos/client-protocol";
|
|
5733
|
+
import { Runtime } from "@dxos/protocols/proto/dxos/config";
|
|
5734
|
+
import { isNode as isNode2 } from "@dxos/util";
|
|
5735
|
+
var getRootPath = (config) => {
|
|
5736
|
+
const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
|
|
5737
|
+
return `${dataRoot}/`;
|
|
5532
5738
|
};
|
|
5533
|
-
var
|
|
5534
|
-
|
|
5739
|
+
var isPersistent = (config) => {
|
|
5740
|
+
const { persistent = false } = config ?? {};
|
|
5741
|
+
return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
|
|
5742
|
+
};
|
|
5743
|
+
|
|
5744
|
+
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5745
|
+
var StorageDriver = Runtime2.Client.Storage.StorageDriver;
|
|
5746
|
+
var createStorageObjects = (config) => {
|
|
5747
|
+
const { persistent = false, keyStore, dataStore } = config ?? {};
|
|
5748
|
+
if (persistent && dataStore === StorageDriver.RAM) {
|
|
5749
|
+
throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
|
|
5750
|
+
}
|
|
5751
|
+
if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
|
|
5752
|
+
throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
|
|
5753
|
+
}
|
|
5754
|
+
if (persistent && keyStore === StorageDriver.RAM) {
|
|
5755
|
+
throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
|
|
5756
|
+
}
|
|
5757
|
+
if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
|
|
5758
|
+
throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
|
|
5759
|
+
}
|
|
5535
5760
|
return {
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
if (message.data.type === "probe") {
|
|
5541
|
-
channel?.postMessage({
|
|
5542
|
-
type: "probe-ack"
|
|
5543
|
-
});
|
|
5544
|
-
} else if (message.data.type === "request-diagnostics") {
|
|
5545
|
-
const diagnostics = await systemService.getDiagnostics({});
|
|
5546
|
-
channel?.postMessage({
|
|
5547
|
-
type: "receive-diagnostics",
|
|
5548
|
-
payload: diagnostics
|
|
5549
|
-
});
|
|
5550
|
-
}
|
|
5551
|
-
} catch (error) {
|
|
5552
|
-
log15.catch(error, void 0, {
|
|
5553
|
-
F: __dxlog_file18,
|
|
5554
|
-
L: 77,
|
|
5555
|
-
S: void 0,
|
|
5556
|
-
C: (f, a) => f(...a)
|
|
5557
|
-
});
|
|
5558
|
-
}
|
|
5559
|
-
};
|
|
5560
|
-
},
|
|
5561
|
-
stop: () => {
|
|
5562
|
-
safeClose(channel);
|
|
5563
|
-
channel = void 0;
|
|
5564
|
-
}
|
|
5761
|
+
storage: createStorage({
|
|
5762
|
+
type: persistent ? toStorageType(dataStore) : StorageType.RAM,
|
|
5763
|
+
root: getRootPath(config)
|
|
5764
|
+
})
|
|
5565
5765
|
};
|
|
5566
5766
|
};
|
|
5567
|
-
var
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5767
|
+
var toStorageType = (type) => {
|
|
5768
|
+
switch (type) {
|
|
5769
|
+
case void 0:
|
|
5770
|
+
return void 0;
|
|
5771
|
+
case StorageDriver.RAM:
|
|
5772
|
+
return StorageType.RAM;
|
|
5773
|
+
case StorageDriver.CHROME:
|
|
5774
|
+
return StorageType.CHROME;
|
|
5775
|
+
case StorageDriver.FIREFOX:
|
|
5776
|
+
return StorageType.FIREFOX;
|
|
5777
|
+
case StorageDriver.IDB:
|
|
5778
|
+
return StorageType.IDB;
|
|
5779
|
+
case StorageDriver.NODE:
|
|
5780
|
+
return StorageType.NODE;
|
|
5781
|
+
case StorageDriver.WEBFS:
|
|
5782
|
+
return StorageType.WEBFS;
|
|
5783
|
+
default:
|
|
5784
|
+
throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
|
|
5571
5785
|
}
|
|
5572
5786
|
};
|
|
5573
5787
|
|
|
5574
|
-
// packages/sdk/client-services/src/packlets/
|
|
5575
|
-
import
|
|
5576
|
-
import {
|
|
5577
|
-
import {
|
|
5578
|
-
|
|
5788
|
+
// packages/sdk/client-services/src/packlets/storage/level.ts
|
|
5789
|
+
import path from "@dxos/node-std/path";
|
|
5790
|
+
import { PublicKey as PublicKey13 } from "@dxos/keys";
|
|
5791
|
+
import { createLevel as createKV } from "@dxos/kv-store";
|
|
5792
|
+
var createLevel = async (config) => {
|
|
5793
|
+
const persistent = isPersistent(config);
|
|
5794
|
+
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
|
|
5795
|
+
const level = createKV(storagePath);
|
|
5796
|
+
await level.open();
|
|
5797
|
+
return level;
|
|
5798
|
+
};
|
|
5579
5799
|
|
|
5580
5800
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
5581
5801
|
import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
|
|
5582
|
-
import { clientServiceBundle, defaultKey,
|
|
5802
|
+
import { clientServiceBundle, defaultKey, PropertiesType } from "@dxos/client-protocol";
|
|
5583
5803
|
import { Context as Context11 } from "@dxos/context";
|
|
5584
5804
|
import { encodeReference } from "@dxos/echo-protocol";
|
|
5585
5805
|
import { getTypeReference } from "@dxos/echo-schema";
|
|
5586
5806
|
import { invariant as invariant18 } from "@dxos/invariant";
|
|
5587
|
-
import { PublicKey as
|
|
5807
|
+
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
5588
5808
|
import { log as log18 } from "@dxos/log";
|
|
5589
5809
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
5590
|
-
import {
|
|
5810
|
+
import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
5591
5811
|
import { trace as trace10 } from "@dxos/protocols";
|
|
5592
5812
|
import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
5593
|
-
import { TRACE_PROCESSOR as
|
|
5813
|
+
import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
|
|
5594
5814
|
import { assignDeep as assignDeep2 } from "@dxos/util";
|
|
5595
5815
|
import { WebsocketRpcClient } from "@dxos/websocket-rpc";
|
|
5596
5816
|
|
|
@@ -5599,7 +5819,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
|
|
|
5599
5819
|
import { Stream as Stream11 } from "@dxos/codec-protobuf";
|
|
5600
5820
|
import { invariant as invariant17 } from "@dxos/invariant";
|
|
5601
5821
|
import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5602
|
-
var
|
|
5822
|
+
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
|
|
5603
5823
|
var DevicesServiceImpl = class {
|
|
5604
5824
|
constructor(_identityManager) {
|
|
5605
5825
|
this._identityManager = _identityManager;
|
|
@@ -5617,7 +5837,7 @@ var DevicesServiceImpl = class {
|
|
|
5617
5837
|
});
|
|
5618
5838
|
} else {
|
|
5619
5839
|
invariant17(this._identityManager.identity?.presence, "presence not present", {
|
|
5620
|
-
F:
|
|
5840
|
+
F: __dxlog_file20,
|
|
5621
5841
|
L: 32,
|
|
5622
5842
|
S: this,
|
|
5623
5843
|
A: [
|
|
@@ -5645,165 +5865,88 @@ var DevicesServiceImpl = class {
|
|
|
5645
5865
|
const subscribeIdentity = () => {
|
|
5646
5866
|
if (!identitySubscribed) {
|
|
5647
5867
|
this._identityManager.identity?.stateUpdate.on(() => {
|
|
5648
|
-
update();
|
|
5649
|
-
});
|
|
5650
|
-
identitySubscribed = true;
|
|
5651
|
-
}
|
|
5652
|
-
};
|
|
5653
|
-
const subscribePresence = () => {
|
|
5654
|
-
if (!presenceSubscribed) {
|
|
5655
|
-
this._identityManager.identity?.presence?.updated.on(() => {
|
|
5656
|
-
update();
|
|
5657
|
-
});
|
|
5658
|
-
presenceSubscribed = true;
|
|
5659
|
-
}
|
|
5660
|
-
};
|
|
5661
|
-
const subscriptions = new EventSubscriptions3();
|
|
5662
|
-
if (this._identityManager.identity) {
|
|
5663
|
-
subscribeIdentity();
|
|
5664
|
-
subscribePresence();
|
|
5665
|
-
}
|
|
5666
|
-
subscriptions.add(this._identityManager.stateUpdate.on(() => {
|
|
5667
|
-
update();
|
|
5668
|
-
if (this._identityManager.identity) {
|
|
5669
|
-
subscribeIdentity();
|
|
5670
|
-
subscribePresence();
|
|
5671
|
-
}
|
|
5672
|
-
}));
|
|
5673
|
-
update();
|
|
5674
|
-
return () => subscriptions.clear();
|
|
5675
|
-
});
|
|
5676
|
-
}
|
|
5677
|
-
};
|
|
5678
|
-
|
|
5679
|
-
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5680
|
-
import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
|
|
5681
|
-
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5682
|
-
import { log as log16, logInfo } from "@dxos/log";
|
|
5683
|
-
function _ts_decorate7(decorators, target, key, desc) {
|
|
5684
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5685
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
5686
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
5687
|
-
else
|
|
5688
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
5689
|
-
if (d = decorators[i])
|
|
5690
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5691
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5692
|
-
}
|
|
5693
|
-
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5694
|
-
var Message;
|
|
5695
|
-
(function(Message2) {
|
|
5696
|
-
Message2["ACQUIRING"] = "acquiring";
|
|
5697
|
-
})(Message || (Message = {}));
|
|
5698
|
-
var Lock = class {
|
|
5699
|
-
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5700
|
-
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5701
|
-
this._releaseTrigger = new Trigger8();
|
|
5702
|
-
this._lockKey = lockKey;
|
|
5703
|
-
this._onAcquire = onAcquire;
|
|
5704
|
-
this._onRelease = onRelease;
|
|
5705
|
-
this._broadcastChannel.onmessage = this._onMessage.bind(this);
|
|
5706
|
-
}
|
|
5707
|
-
get lockKey() {
|
|
5708
|
-
return this._lockKey;
|
|
5709
|
-
}
|
|
5710
|
-
async acquire() {
|
|
5711
|
-
this._broadcastChannel.postMessage({
|
|
5712
|
-
message: "acquiring"
|
|
5868
|
+
update();
|
|
5869
|
+
});
|
|
5870
|
+
identitySubscribed = true;
|
|
5871
|
+
}
|
|
5872
|
+
};
|
|
5873
|
+
const subscribePresence = () => {
|
|
5874
|
+
if (!presenceSubscribed) {
|
|
5875
|
+
this._identityManager.identity?.presence?.updated.on(() => {
|
|
5876
|
+
update();
|
|
5877
|
+
});
|
|
5878
|
+
presenceSubscribed = true;
|
|
5879
|
+
}
|
|
5880
|
+
};
|
|
5881
|
+
const subscriptions = new EventSubscriptions3();
|
|
5882
|
+
if (this._identityManager.identity) {
|
|
5883
|
+
subscribeIdentity();
|
|
5884
|
+
subscribePresence();
|
|
5885
|
+
}
|
|
5886
|
+
subscriptions.add(this._identityManager.stateUpdate.on(() => {
|
|
5887
|
+
update();
|
|
5888
|
+
if (this._identityManager.identity) {
|
|
5889
|
+
subscribeIdentity();
|
|
5890
|
+
subscribePresence();
|
|
5891
|
+
}
|
|
5892
|
+
}));
|
|
5893
|
+
update();
|
|
5894
|
+
return () => subscriptions.clear();
|
|
5713
5895
|
});
|
|
5714
|
-
try {
|
|
5715
|
-
log16("aquiring lock...", void 0, {
|
|
5716
|
-
F: __dxlog_file20,
|
|
5717
|
-
L: 42,
|
|
5718
|
-
S: this,
|
|
5719
|
-
C: (f, a) => f(...a)
|
|
5720
|
-
});
|
|
5721
|
-
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5722
|
-
log16("acquired lock", void 0, {
|
|
5723
|
-
F: __dxlog_file20,
|
|
5724
|
-
L: 44,
|
|
5725
|
-
S: this,
|
|
5726
|
-
C: (f, a) => f(...a)
|
|
5727
|
-
});
|
|
5728
|
-
} catch {
|
|
5729
|
-
log16("stealing lock...", void 0, {
|
|
5730
|
-
F: __dxlog_file20,
|
|
5731
|
-
L: 46,
|
|
5732
|
-
S: this,
|
|
5733
|
-
C: (f, a) => f(...a)
|
|
5734
|
-
});
|
|
5735
|
-
await this._requestLock(true);
|
|
5736
|
-
log16("stolen lock", void 0, {
|
|
5737
|
-
F: __dxlog_file20,
|
|
5738
|
-
L: 48,
|
|
5739
|
-
S: this,
|
|
5740
|
-
C: (f, a) => f(...a)
|
|
5741
|
-
});
|
|
5742
|
-
}
|
|
5743
5896
|
}
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5897
|
+
};
|
|
5898
|
+
|
|
5899
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
|
|
5900
|
+
import { ConfigResource } from "@dxos/config";
|
|
5901
|
+
import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5902
|
+
import { TRACE_PROCESSOR as TRACE_PROCESSOR2 } from "@dxos/tracing";
|
|
5903
|
+
import { jsonKeyReplacer, nonNullable } from "@dxos/util";
|
|
5904
|
+
|
|
5905
|
+
// packages/sdk/client-services/src/packlets/services/util.ts
|
|
5906
|
+
import { PublicKey as PublicKey14 } from "@dxos/keys";
|
|
5907
|
+
import { humanize } from "@dxos/util";
|
|
5908
|
+
var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
|
|
5909
|
+
|
|
5910
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
|
|
5911
|
+
var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
|
|
5912
|
+
var DiagnosticsCollector = class {
|
|
5913
|
+
static {
|
|
5914
|
+
this.broadcastSender = createCollectDiagnosticsBroadcastSender();
|
|
5751
5915
|
}
|
|
5752
|
-
async
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
}, {
|
|
5756
|
-
F: __dxlog_file20,
|
|
5757
|
-
L: 63,
|
|
5758
|
-
S: this,
|
|
5759
|
-
C: (f, a) => f(...a)
|
|
5760
|
-
});
|
|
5761
|
-
const acquired = new Trigger8();
|
|
5762
|
-
void navigator.locks.request(this._lockKey, {
|
|
5763
|
-
steal
|
|
5764
|
-
}, async () => {
|
|
5765
|
-
await this._onAcquire?.();
|
|
5766
|
-
acquired.wake();
|
|
5767
|
-
this._releaseTrigger = new Trigger8();
|
|
5768
|
-
await this._releaseTrigger.wait();
|
|
5769
|
-
log16("releasing lock...", void 0, {
|
|
5770
|
-
F: __dxlog_file20,
|
|
5771
|
-
L: 72,
|
|
5772
|
-
S: this,
|
|
5773
|
-
C: (f, a) => f(...a)
|
|
5774
|
-
});
|
|
5775
|
-
await this._onRelease?.();
|
|
5776
|
-
log16("released lock", void 0, {
|
|
5777
|
-
F: __dxlog_file20,
|
|
5778
|
-
L: 74,
|
|
5779
|
-
S: this,
|
|
5780
|
-
C: (f, a) => f(...a)
|
|
5781
|
-
});
|
|
5782
|
-
}).catch(async () => {
|
|
5783
|
-
await this._onRelease?.();
|
|
5784
|
-
});
|
|
5785
|
-
await acquired.wait();
|
|
5786
|
-
log16("recieved lock", {
|
|
5787
|
-
steal
|
|
5916
|
+
static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
|
|
5917
|
+
const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
|
|
5918
|
+
keys: options.humanize ? GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
|
|
5788
5919
|
}, {
|
|
5789
|
-
|
|
5790
|
-
L: 81,
|
|
5791
|
-
S: this,
|
|
5792
|
-
C: (f, a) => f(...a)
|
|
5920
|
+
timeout: GET_DIAGNOSTICS_RPC_TIMEOUT
|
|
5793
5921
|
});
|
|
5922
|
+
const clientDiagnostics = {
|
|
5923
|
+
config,
|
|
5924
|
+
trace: TRACE_PROCESSOR2.getDiagnostics()
|
|
5925
|
+
};
|
|
5926
|
+
const diagnostics = serviceDiagnostics != null ? {
|
|
5927
|
+
client: clientDiagnostics,
|
|
5928
|
+
services: serviceDiagnostics
|
|
5929
|
+
} : {
|
|
5930
|
+
client: clientDiagnostics,
|
|
5931
|
+
broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
|
|
5932
|
+
};
|
|
5933
|
+
return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer(options)));
|
|
5794
5934
|
}
|
|
5795
5935
|
};
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5936
|
+
var findSystemServiceProvider = () => {
|
|
5937
|
+
const serviceProviders = TRACE_PROCESSOR2.findResourcesByAnnotation(ClientServicesProviderResource);
|
|
5938
|
+
const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
|
|
5939
|
+
return providerResource?.instance?.deref() ?? null;
|
|
5940
|
+
};
|
|
5941
|
+
var findConfigs = () => {
|
|
5942
|
+
const configs = TRACE_PROCESSOR2.findResourcesByAnnotation(ConfigResource);
|
|
5943
|
+
return configs.map((r) => r.instance.deref()).filter(nonNullable);
|
|
5801
5944
|
};
|
|
5802
5945
|
|
|
5803
5946
|
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
5804
5947
|
import { Event as Event8 } from "@dxos/async";
|
|
5805
5948
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
5806
|
-
import { PublicKey as
|
|
5949
|
+
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
5807
5950
|
import { getContextFromEntry, log as log17 } from "@dxos/log";
|
|
5808
5951
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5809
5952
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
@@ -5811,7 +5954,7 @@ var LoggingServiceImpl = class {
|
|
|
5811
5954
|
constructor() {
|
|
5812
5955
|
this._logs = new Event8();
|
|
5813
5956
|
this._started = Date.now();
|
|
5814
|
-
this._sessionId =
|
|
5957
|
+
this._sessionId = PublicKey15.random().toHex();
|
|
5815
5958
|
this._logProcessor = (_config, entry2) => {
|
|
5816
5959
|
this._logs.emit(entry2);
|
|
5817
5960
|
};
|
|
@@ -5957,84 +6100,10 @@ var NetworkServiceImpl = class {
|
|
|
5957
6100
|
}
|
|
5958
6101
|
};
|
|
5959
6102
|
|
|
5960
|
-
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5961
|
-
import { InvalidConfigError } from "@dxos/protocols";
|
|
5962
|
-
import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
|
|
5963
|
-
import { createStorage, StorageType } from "@dxos/random-access-storage";
|
|
5964
|
-
|
|
5965
|
-
// packages/sdk/client-services/src/packlets/storage/util.ts
|
|
5966
|
-
import { DX_DATA } from "@dxos/client-protocol";
|
|
5967
|
-
import { Runtime } from "@dxos/protocols/proto/dxos/config";
|
|
5968
|
-
import { isNode as isNode2 } from "@dxos/util";
|
|
5969
|
-
var getRootPath = (config) => {
|
|
5970
|
-
const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
|
|
5971
|
-
return `${dataRoot}/`;
|
|
5972
|
-
};
|
|
5973
|
-
var isPersistent = (config) => {
|
|
5974
|
-
const { persistent = false } = config ?? {};
|
|
5975
|
-
return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
|
|
5976
|
-
};
|
|
5977
|
-
|
|
5978
|
-
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5979
|
-
var StorageDriver = Runtime2.Client.Storage.StorageDriver;
|
|
5980
|
-
var createStorageObjects = (config) => {
|
|
5981
|
-
const { persistent = false, keyStore, dataStore } = config ?? {};
|
|
5982
|
-
if (persistent && dataStore === StorageDriver.RAM) {
|
|
5983
|
-
throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
|
|
5984
|
-
}
|
|
5985
|
-
if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
|
|
5986
|
-
throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
|
|
5987
|
-
}
|
|
5988
|
-
if (persistent && keyStore === StorageDriver.RAM) {
|
|
5989
|
-
throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
|
|
5990
|
-
}
|
|
5991
|
-
if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
|
|
5992
|
-
throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
|
|
5993
|
-
}
|
|
5994
|
-
return {
|
|
5995
|
-
storage: createStorage({
|
|
5996
|
-
type: persistent ? toStorageType(dataStore) : StorageType.RAM,
|
|
5997
|
-
root: getRootPath(config)
|
|
5998
|
-
})
|
|
5999
|
-
};
|
|
6000
|
-
};
|
|
6001
|
-
var toStorageType = (type) => {
|
|
6002
|
-
switch (type) {
|
|
6003
|
-
case void 0:
|
|
6004
|
-
return void 0;
|
|
6005
|
-
case StorageDriver.RAM:
|
|
6006
|
-
return StorageType.RAM;
|
|
6007
|
-
case StorageDriver.CHROME:
|
|
6008
|
-
return StorageType.CHROME;
|
|
6009
|
-
case StorageDriver.FIREFOX:
|
|
6010
|
-
return StorageType.FIREFOX;
|
|
6011
|
-
case StorageDriver.IDB:
|
|
6012
|
-
return StorageType.IDB;
|
|
6013
|
-
case StorageDriver.NODE:
|
|
6014
|
-
return StorageType.NODE;
|
|
6015
|
-
case StorageDriver.WEBFS:
|
|
6016
|
-
return StorageType.WEBFS;
|
|
6017
|
-
default:
|
|
6018
|
-
throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
|
|
6019
|
-
}
|
|
6020
|
-
};
|
|
6021
|
-
|
|
6022
|
-
// packages/sdk/client-services/src/packlets/storage/level.ts
|
|
6023
|
-
import path from "@dxos/node-std/path";
|
|
6024
|
-
import { PublicKey as PublicKey14 } from "@dxos/keys";
|
|
6025
|
-
import { createLevel as createKV } from "@dxos/kv-store";
|
|
6026
|
-
var createLevel = async (config) => {
|
|
6027
|
-
const persistent = isPersistent(config);
|
|
6028
|
-
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey14.random().toHex()}`;
|
|
6029
|
-
const level = createKV(storagePath);
|
|
6030
|
-
await level.open();
|
|
6031
|
-
return level;
|
|
6032
|
-
};
|
|
6033
|
-
|
|
6034
6103
|
// packages/sdk/client-services/src/packlets/system/system-service.ts
|
|
6035
6104
|
import { Stream as Stream14 } from "@dxos/codec-protobuf";
|
|
6036
|
-
import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
6037
|
-
import { jsonKeyReplacer } from "@dxos/util";
|
|
6105
|
+
import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
6106
|
+
import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
|
|
6038
6107
|
var SystemServiceImpl = class {
|
|
6039
6108
|
constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
|
|
6040
6109
|
this._config = config;
|
|
@@ -6054,9 +6123,9 @@ var SystemServiceImpl = class {
|
|
|
6054
6123
|
const diagnostics = await this._getDiagnostics();
|
|
6055
6124
|
return {
|
|
6056
6125
|
timestamp: /* @__PURE__ */ new Date(),
|
|
6057
|
-
diagnostics: JSON.parse(JSON.stringify(diagnostics,
|
|
6058
|
-
truncate: keys ===
|
|
6059
|
-
humanize: keys ===
|
|
6126
|
+
diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2({
|
|
6127
|
+
truncate: keys === GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE,
|
|
6128
|
+
humanize: keys === GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE
|
|
6060
6129
|
})))
|
|
6061
6130
|
};
|
|
6062
6131
|
}
|
|
@@ -6112,7 +6181,7 @@ var ClientServicesHost = class {
|
|
|
6112
6181
|
callbacks,
|
|
6113
6182
|
runtimeParams
|
|
6114
6183
|
} = {}) {
|
|
6115
|
-
this._tracingService =
|
|
6184
|
+
this._tracingService = TRACE_PROCESSOR3.createTraceSender();
|
|
6116
6185
|
this._statusUpdate = new Event9();
|
|
6117
6186
|
this._opening = false;
|
|
6118
6187
|
this._open = false;
|
|
@@ -6238,7 +6307,7 @@ var ClientServicesHost = class {
|
|
|
6238
6307
|
"'network manager already set'"
|
|
6239
6308
|
]
|
|
6240
6309
|
});
|
|
6241
|
-
this._networkManager = new
|
|
6310
|
+
this._networkManager = new SwarmNetworkManager({
|
|
6242
6311
|
log: connectionLog,
|
|
6243
6312
|
transportFactory,
|
|
6244
6313
|
signalManager
|
|
@@ -6254,7 +6323,7 @@ var ClientServicesHost = class {
|
|
|
6254
6323
|
if (this._open) {
|
|
6255
6324
|
return;
|
|
6256
6325
|
}
|
|
6257
|
-
const traceId =
|
|
6326
|
+
const traceId = PublicKey16.random().toHex();
|
|
6258
6327
|
log18.trace("dxos.client-services.host.open", trace10.begin({
|
|
6259
6328
|
id: traceId
|
|
6260
6329
|
}), {
|
|
@@ -6402,7 +6471,7 @@ var ClientServicesHost = class {
|
|
|
6402
6471
|
});
|
|
6403
6472
|
}
|
|
6404
6473
|
async reset() {
|
|
6405
|
-
const traceId =
|
|
6474
|
+
const traceId = PublicKey16.random().toHex();
|
|
6406
6475
|
log18.trace("dxos.sdk.client-services-host.reset", trace10.begin({
|
|
6407
6476
|
id: traceId
|
|
6408
6477
|
}), {
|
|
@@ -6449,11 +6518,11 @@ var ClientServicesHost = class {
|
|
|
6449
6518
|
""
|
|
6450
6519
|
]
|
|
6451
6520
|
});
|
|
6452
|
-
const document =
|
|
6521
|
+
const document = this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
|
|
6453
6522
|
await document.whenReady();
|
|
6454
6523
|
const properties = {
|
|
6455
6524
|
system: {
|
|
6456
|
-
type: encodeReference(getTypeReference(
|
|
6525
|
+
type: encodeReference(getTypeReference(PropertiesType))
|
|
6457
6526
|
},
|
|
6458
6527
|
data: {
|
|
6459
6528
|
[defaultKey]: identity.identityKey.toHex()
|
|
@@ -6462,7 +6531,7 @@ var ClientServicesHost = class {
|
|
|
6462
6531
|
keys: []
|
|
6463
6532
|
}
|
|
6464
6533
|
};
|
|
6465
|
-
const propertiesId =
|
|
6534
|
+
const propertiesId = PublicKey16.random().toHex();
|
|
6466
6535
|
document.change((doc) => {
|
|
6467
6536
|
assignDeep2(doc, [
|
|
6468
6537
|
"objects",
|
|
@@ -6491,47 +6560,6 @@ ClientServicesHost = _ts_decorate8([
|
|
|
6491
6560
|
Trace4.resource()
|
|
6492
6561
|
], ClientServicesHost);
|
|
6493
6562
|
|
|
6494
|
-
// packages/sdk/client-services/src/packlets/services/util.ts
|
|
6495
|
-
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
6496
|
-
import { humanize } from "@dxos/util";
|
|
6497
|
-
var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
|
|
6498
|
-
|
|
6499
|
-
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
|
|
6500
|
-
var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
|
|
6501
|
-
var DiagnosticsCollector = class {
|
|
6502
|
-
static {
|
|
6503
|
-
this.broadcastSender = createCollectDiagnosticsBroadcastSender();
|
|
6504
|
-
}
|
|
6505
|
-
static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
|
|
6506
|
-
const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
|
|
6507
|
-
keys: options.humanize ? GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE : void 0
|
|
6508
|
-
}, {
|
|
6509
|
-
timeout: GET_DIAGNOSTICS_RPC_TIMEOUT
|
|
6510
|
-
});
|
|
6511
|
-
const clientDiagnostics = {
|
|
6512
|
-
config,
|
|
6513
|
-
trace: TRACE_PROCESSOR3.getDiagnostics()
|
|
6514
|
-
};
|
|
6515
|
-
const diagnostics = serviceDiagnostics != null ? {
|
|
6516
|
-
client: clientDiagnostics,
|
|
6517
|
-
services: serviceDiagnostics
|
|
6518
|
-
} : {
|
|
6519
|
-
client: clientDiagnostics,
|
|
6520
|
-
broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
|
|
6521
|
-
};
|
|
6522
|
-
return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2(options)));
|
|
6523
|
-
}
|
|
6524
|
-
};
|
|
6525
|
-
var findSystemServiceProvider = () => {
|
|
6526
|
-
const serviceProviders = TRACE_PROCESSOR3.findResourcesByAnnotation(ClientServicesProviderResource);
|
|
6527
|
-
const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
|
|
6528
|
-
return providerResource?.instance?.deref() ?? null;
|
|
6529
|
-
};
|
|
6530
|
-
var findConfigs = () => {
|
|
6531
|
-
const configs = TRACE_PROCESSOR3.findResourcesByAnnotation(ConfigResource);
|
|
6532
|
-
return configs.map((r) => r.instance.deref()).filter(nonNullable);
|
|
6533
|
-
};
|
|
6534
|
-
|
|
6535
6563
|
export {
|
|
6536
6564
|
Buffer,
|
|
6537
6565
|
subscribeToFeeds,
|
|
@@ -6544,6 +6572,10 @@ export {
|
|
|
6544
6572
|
subscribeToSpaces,
|
|
6545
6573
|
DevtoolsHostEvents,
|
|
6546
6574
|
DevtoolsServiceImpl,
|
|
6575
|
+
createDiagnostics,
|
|
6576
|
+
createCollectDiagnosticsBroadcastSender,
|
|
6577
|
+
createCollectDiagnosticsBroadcastHandler,
|
|
6578
|
+
ClientRpcServer,
|
|
6547
6579
|
createAuthProvider,
|
|
6548
6580
|
TrustedKeySetAuthVerifier,
|
|
6549
6581
|
Identity,
|
|
@@ -6555,22 +6587,18 @@ export {
|
|
|
6555
6587
|
InvitationsServiceImpl,
|
|
6556
6588
|
SpaceInvitationProtocol,
|
|
6557
6589
|
InvitationsManager,
|
|
6558
|
-
ClientRpcServer,
|
|
6559
6590
|
DataSpace,
|
|
6560
6591
|
findPropertiesObject,
|
|
6561
6592
|
DataSpaceManager,
|
|
6562
6593
|
SpacesServiceImpl,
|
|
6563
6594
|
ServiceContext,
|
|
6564
6595
|
ServiceRegistry,
|
|
6565
|
-
createDiagnostics,
|
|
6566
|
-
createCollectDiagnosticsBroadcastSender,
|
|
6567
|
-
createCollectDiagnosticsBroadcastHandler,
|
|
6568
|
-
DiagnosticsCollector,
|
|
6569
6596
|
Lock,
|
|
6570
6597
|
isLocked,
|
|
6571
6598
|
createStorageObjects,
|
|
6572
6599
|
createLevel,
|
|
6573
6600
|
ClientServicesHost,
|
|
6574
|
-
ClientServicesProviderResource
|
|
6601
|
+
ClientServicesProviderResource,
|
|
6602
|
+
DiagnosticsCollector
|
|
6575
6603
|
};
|
|
6576
|
-
//# sourceMappingURL=chunk-
|
|
6604
|
+
//# sourceMappingURL=chunk-XYEJP6PO.mjs.map
|