@dxos/client-services 0.1.53-next.63b0547 → 0.1.53-next.e9dc2bc

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.
Files changed (42) hide show
  1. package/dist/lib/browser/{chunk-RKD47ENR.mjs → chunk-3EI4PM2V.mjs} +194 -110
  2. package/dist/lib/browser/chunk-3EI4PM2V.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +8 -2
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +19 -2
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/index.cjs +196 -106
  9. package/dist/lib/node/index.cjs.map +3 -3
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +203 -103
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  14. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  15. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  16. package/dist/types/src/packlets/services/service-host.d.ts +6 -1
  17. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  18. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  19. package/dist/types/src/packlets/spaces/data-space.d.ts +11 -2
  20. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  21. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +2 -1
  22. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  24. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/testing/test-builder.d.ts +7 -1
  26. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  27. package/package.json +32 -32
  28. package/src/packlets/identity/authenticator.ts +4 -2
  29. package/src/packlets/identity/identity.ts +21 -26
  30. package/src/packlets/services/service-context.ts +9 -7
  31. package/src/packlets/services/service-host.test.ts +50 -2
  32. package/src/packlets/services/service-host.ts +9 -0
  33. package/src/packlets/spaces/data-space-manager.test.ts +75 -119
  34. package/src/packlets/spaces/data-space-manager.ts +13 -3
  35. package/src/packlets/spaces/data-space.ts +66 -20
  36. package/src/packlets/spaces/notarization-plugin.test.ts +1 -1
  37. package/src/packlets/spaces/notarization-plugin.ts +5 -1
  38. package/src/packlets/spaces/spaces-service.test.ts +5 -3
  39. package/src/packlets/spaces/spaces-service.ts +26 -8
  40. package/src/packlets/testing/test-builder.ts +35 -2
  41. package/src/packlets/vault/worker-runtime.ts +1 -1
  42. package/dist/lib/browser/chunk-RKD47ENR.mjs.map +0 -7
@@ -420,6 +420,7 @@ var import_credentials = require("@dxos/credentials");
420
420
  var import_log = require("@dxos/log");
421
421
  var import_protocols = require("@dxos/protocols");
422
422
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
423
+ var Credential = import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential");
423
424
  var createAuthProvider = (signer) => async (nonce) => {
424
425
  const credential = await signer.createCredential({
425
426
  assertion: {
@@ -428,7 +429,7 @@ var createAuthProvider = (signer) => async (nonce) => {
428
429
  subject: signer.getIssuer(),
429
430
  nonce
430
431
  });
431
- return import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
432
+ return Credential.encode(credential);
432
433
  };
433
434
  var TrustedKeySetAuthVerifier = class {
434
435
  // prettier-ignore
@@ -441,12 +442,12 @@ var TrustedKeySetAuthVerifier = class {
441
442
  }
442
443
  get verifier() {
443
444
  return async (nonce, auth) => {
444
- const credential = import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
445
+ const credential = Credential.decode(auth);
445
446
  (0, import_log.log)("authenticating...", {
446
447
  credential
447
448
  }, {
448
449
  F: __dxlog_file,
449
- L: 57,
450
+ L: 59,
450
451
  S: this,
451
452
  C: (f, a) => f(...a)
452
453
  });
@@ -456,7 +457,7 @@ var TrustedKeySetAuthVerifier = class {
456
457
  result
457
458
  }, {
458
459
  F: __dxlog_file,
459
- L: 61,
460
+ L: 63,
460
461
  S: this,
461
462
  C: (f, a) => f(...a)
462
463
  });
@@ -468,7 +469,7 @@ var TrustedKeySetAuthVerifier = class {
468
469
  credential
469
470
  }, {
470
471
  F: __dxlog_file,
471
- L: 66,
472
+ L: 68,
472
473
  S: this,
473
474
  C: (f, a) => f(...a)
474
475
  });
@@ -479,7 +480,7 @@ var TrustedKeySetAuthVerifier = class {
479
480
  key: credential.issuer
480
481
  }, {
481
482
  F: __dxlog_file,
482
- L: 71,
483
+ L: 73,
483
484
  S: this,
484
485
  C: (f, a) => f(...a)
485
486
  });
@@ -495,7 +496,7 @@ var TrustedKeySetAuthVerifier = class {
495
496
  key: credential.issuer
496
497
  }, {
497
498
  F: __dxlog_file,
498
- L: 82,
499
+ L: 84,
499
500
  S: this,
500
501
  C: (f, a) => f(...a)
501
502
  });
@@ -505,7 +506,7 @@ var TrustedKeySetAuthVerifier = class {
505
506
  key: credential.issuer
506
507
  }, {
507
508
  F: __dxlog_file,
508
- L: 85,
509
+ L: 87,
509
510
  S: this,
510
511
  C: (f, a) => f(...a)
511
512
  });
@@ -545,15 +546,15 @@ var Identity = class {
545
546
  this._signer = signer;
546
547
  this.identityKey = identityKey;
547
548
  this.deviceKey = deviceKey;
548
- this._deviceStateMachine = this.space.spaceState.registerProcessor(new import_credentials2.DeviceStateMachine({
549
+ this._deviceStateMachine = new import_credentials2.DeviceStateMachine({
549
550
  identityKey: this.identityKey,
550
551
  deviceKey: this.deviceKey,
551
552
  onUpdate: () => this.stateUpdate.emit()
552
- }));
553
- this._profileStateMachine = this.space.spaceState.registerProcessor(new import_credentials2.ProfileStateMachine({
553
+ });
554
+ this._profileStateMachine = new import_credentials2.ProfileStateMachine({
554
555
  identityKey: this.identityKey,
555
556
  onUpdate: () => this.stateUpdate.emit()
556
- }));
557
+ });
557
558
  this.authVerifier = new TrustedKeySetAuthVerifier({
558
559
  trustedKeysProvider: () => this.authorizedDeviceKeys,
559
560
  update: this.stateUpdate,
@@ -562,27 +563,27 @@ var Identity = class {
562
563
  }
563
564
  // TODO(burdon): Expose state object?
564
565
  get authorizedDeviceKeys() {
565
- return this._deviceStateMachine.processor.authorizedDeviceKeys;
566
+ return this._deviceStateMachine.authorizedDeviceKeys;
566
567
  }
567
568
  async open() {
568
- await this._deviceStateMachine.open();
569
- await this._profileStateMachine.open();
569
+ await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
570
+ await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
570
571
  await this.space.open();
571
572
  }
572
573
  async close() {
573
574
  await this.authVerifier.close();
574
- await this._deviceStateMachine.close();
575
- await this._profileStateMachine.close();
575
+ await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
576
+ await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
576
577
  await this.space.close();
577
578
  }
578
579
  async ready() {
579
- await this._deviceStateMachine.processor.deviceChainReady.wait();
580
+ await this._deviceStateMachine.deviceChainReady.wait();
580
581
  await this.controlPipeline.state.waitUntilReachedTargetTimeframe({
581
582
  timeout: import_client_protocol.LOAD_CONTROL_FEEDS_TIMEOUT
582
583
  });
583
584
  }
584
585
  get profileDocument() {
585
- return this._profileStateMachine.processor.profile;
586
+ return this._profileStateMachine.profile;
586
587
  }
587
588
  /**
588
589
  * @test-only
@@ -597,7 +598,7 @@ var Identity = class {
597
598
  return this.space.genesisFeedKey;
598
599
  }
599
600
  get deviceCredentialChain() {
600
- return this._deviceStateMachine.processor.deviceCredentialChain;
601
+ return this._deviceStateMachine.deviceCredentialChain;
601
602
  }
602
603
  getAdmissionCredentials() {
603
604
  var _a, _b;
@@ -612,8 +613,8 @@ var Identity = class {
612
613
  * Requires identity to be ready.
613
614
  */
614
615
  getIdentityCredentialSigner() {
615
- (0, import_tiny_invariant.default)(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
616
- return (0, import_credentials2.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
616
+ (0, import_tiny_invariant.default)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.");
617
+ return (0, import_credentials2.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
617
618
  }
618
619
  /**
619
620
  * Issues credentials as device.
@@ -630,7 +631,7 @@ var Identity = class {
630
631
  dataFeedKey
631
632
  }, {
632
633
  F: __dxlog_file2,
633
- L: 156,
634
+ L: 151,
634
635
  S: this,
635
636
  C: (f, a) => f(...a)
636
637
  });
@@ -2210,6 +2211,9 @@ var NotarizationPlugin = class {
2210
2211
  this._processedCredentials = new import_util3.ComplexSet(import_keys7.PublicKey.hash);
2211
2212
  this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys7.PublicKey.hash);
2212
2213
  }
2214
+ get hasWriter() {
2215
+ return !!this._writer;
2216
+ }
2213
2217
  async open() {
2214
2218
  }
2215
2219
  async close() {
@@ -2223,7 +2227,7 @@ var NotarizationPlugin = class {
2223
2227
  credentials
2224
2228
  }, {
2225
2229
  F: __dxlog_file8,
2226
- L: 87,
2230
+ L: 91,
2227
2231
  S: this,
2228
2232
  C: (f, a) => f(...a)
2229
2233
  });
@@ -2235,7 +2239,7 @@ var NotarizationPlugin = class {
2235
2239
  err
2236
2240
  }, {
2237
2241
  F: __dxlog_file8,
2238
- L: 96,
2242
+ L: 100,
2239
2243
  S: this,
2240
2244
  C: (f, a) => f(...a)
2241
2245
  });
@@ -2251,7 +2255,7 @@ var NotarizationPlugin = class {
2251
2255
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2252
2256
  }, {
2253
2257
  F: __dxlog_file8,
2254
- L: 108,
2258
+ L: 112,
2255
2259
  S: this,
2256
2260
  C: (f, a) => f(...a)
2257
2261
  });
@@ -2274,7 +2278,7 @@ var NotarizationPlugin = class {
2274
2278
  retryIn: retryTimeout
2275
2279
  }, {
2276
2280
  F: __dxlog_file8,
2277
- L: 133,
2281
+ L: 137,
2278
2282
  S: this,
2279
2283
  C: (f, a) => f(...a)
2280
2284
  });
@@ -2288,7 +2292,7 @@ var NotarizationPlugin = class {
2288
2292
  credentialId: credentials.map((credential) => credential.id)
2289
2293
  }, {
2290
2294
  F: __dxlog_file8,
2291
- L: 140,
2295
+ L: 144,
2292
2296
  S: this,
2293
2297
  C: (f, a) => f(...a)
2294
2298
  });
@@ -2297,7 +2301,7 @@ var NotarizationPlugin = class {
2297
2301
  });
2298
2302
  (0, import_log8.log)("success", void 0, {
2299
2303
  F: __dxlog_file8,
2300
- L: 144,
2304
+ L: 148,
2301
2305
  S: this,
2302
2306
  C: (f, a) => f(...a)
2303
2307
  });
@@ -2306,7 +2310,7 @@ var NotarizationPlugin = class {
2306
2310
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
2307
2311
  import_log8.log.warn("error notarizing (recoverable)", err, {
2308
2312
  F: __dxlog_file8,
2309
- L: 148,
2313
+ L: 152,
2310
2314
  S: this,
2311
2315
  C: (f, a) => f(...a)
2312
2316
  });
@@ -2324,7 +2328,7 @@ var NotarizationPlugin = class {
2324
2328
  ]);
2325
2329
  (0, import_log8.log)("done", void 0, {
2326
2330
  F: __dxlog_file8,
2327
- L: 159,
2331
+ L: 163,
2328
2332
  S: this,
2329
2333
  C: (f, a) => f(...a)
2330
2334
  });
@@ -2335,7 +2339,7 @@ var NotarizationPlugin = class {
2335
2339
  /**
2336
2340
  * Called with credentials arriving from the control pipeline.
2337
2341
  */
2338
- async process(credential) {
2342
+ async processCredential(credential) {
2339
2343
  var _a;
2340
2344
  if (!credential.id) {
2341
2345
  return;
@@ -2377,7 +2381,7 @@ var NotarizationPlugin = class {
2377
2381
  peer: extension.localPeerId
2378
2382
  }, {
2379
2383
  F: __dxlog_file8,
2380
- L: 208,
2384
+ L: 212,
2381
2385
  S: this,
2382
2386
  C: (f, a) => f(...a)
2383
2387
  });
@@ -2389,7 +2393,7 @@ var NotarizationPlugin = class {
2389
2393
  peer: extension.localPeerId
2390
2394
  }, {
2391
2395
  F: __dxlog_file8,
2392
- L: 213,
2396
+ L: 217,
2393
2397
  S: this,
2394
2398
  C: (f, a) => f(...a)
2395
2399
  });
@@ -2446,6 +2450,7 @@ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/sr
2446
2450
  var DataSpace = class DataSpace2 {
2447
2451
  constructor(params) {
2448
2452
  this._ctx = new import_context6.Context();
2453
+ this._notarizationPlugin = new NotarizationPlugin();
2449
2454
  this._state = import_services6.SpaceState.CLOSED;
2450
2455
  /**
2451
2456
  * Error for _state === SpaceState.ERROR.
@@ -2468,8 +2473,8 @@ var DataSpace = class DataSpace2 {
2468
2473
  update: this._inner.stateUpdate,
2469
2474
  authTimeout: import_client_protocol3.AUTH_TIMEOUT
2470
2475
  });
2471
- this._notarizationPluginConsumer = this._inner.spaceState.registerProcessor(new NotarizationPlugin());
2472
2476
  this._cache = params.cache;
2477
+ this._state = params.initialState;
2473
2478
  }
2474
2479
  get key() {
2475
2480
  return this._inner.key;
@@ -2491,25 +2496,36 @@ var DataSpace = class DataSpace2 {
2491
2496
  return this._presence;
2492
2497
  }
2493
2498
  get notarizationPlugin() {
2494
- return this._notarizationPluginConsumer.processor;
2499
+ return this._notarizationPlugin;
2495
2500
  }
2496
2501
  get cache() {
2497
2502
  return this._cache;
2498
2503
  }
2499
2504
  async open() {
2500
- await this.notarizationPlugin.open();
2501
- await this._notarizationPluginConsumer.open();
2505
+ await this._open();
2506
+ }
2507
+ async _open() {
2508
+ await this._notarizationPlugin.open();
2509
+ await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
2502
2510
  await this._inner.open();
2503
- this._state = import_services6.SpaceState.INACTIVE;
2511
+ this._state = import_services6.SpaceState.CONTROL_ONLY;
2512
+ this.stateUpdate.emit();
2513
+ this.metrics = {};
2504
2514
  this.metrics.open = new Date();
2505
2515
  }
2506
2516
  async close() {
2517
+ await this._close();
2518
+ }
2519
+ async _close() {
2520
+ var _a, _b;
2521
+ await ((_b = (_a = this._callbacks).beforeClose) == null ? void 0 : _b.call(_a));
2507
2522
  this._state = import_services6.SpaceState.CLOSED;
2508
2523
  await this._ctx.dispose();
2524
+ this._ctx = new import_context6.Context();
2509
2525
  await this.authVerifier.close();
2510
2526
  await this._inner.close();
2511
- await this._notarizationPluginConsumer.close();
2512
- await this.notarizationPlugin.close();
2527
+ await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
2528
+ await this._notarizationPlugin.close();
2513
2529
  await this._presence.destroy();
2514
2530
  }
2515
2531
  async postMessage(channel, message) {
@@ -2530,7 +2546,7 @@ var DataSpace = class DataSpace2 {
2530
2546
  if (err instanceof import_errors3.CancelledError) {
2531
2547
  (0, import_log9.log)("Data pipeline initialization cancelled", err, {
2532
2548
  F: __dxlog_file9,
2533
- L: 173,
2549
+ L: 193,
2534
2550
  S: this,
2535
2551
  C: (f, a) => f(...a)
2536
2552
  });
@@ -2538,7 +2554,7 @@ var DataSpace = class DataSpace2 {
2538
2554
  }
2539
2555
  import_log9.log.error("Error initializing data pipeline", err, {
2540
2556
  F: __dxlog_file9,
2541
- L: 177,
2557
+ L: 197,
2542
2558
  S: this,
2543
2559
  C: (f, a) => f(...a)
2544
2560
  });
@@ -2552,7 +2568,7 @@ var DataSpace = class DataSpace2 {
2552
2568
  }
2553
2569
  async initializeDataPipeline() {
2554
2570
  var _a, _b, _c, _d;
2555
- if (this._state !== import_services6.SpaceState.INACTIVE) {
2571
+ if (this._state !== import_services6.SpaceState.CONTROL_ONLY) {
2556
2572
  throw new import_errors3.SystemError("Invalid operation");
2557
2573
  }
2558
2574
  this._state = import_services6.SpaceState.INITIALIZING;
@@ -2564,22 +2580,24 @@ var DataSpace = class DataSpace2 {
2564
2580
  await this._createWritableFeeds();
2565
2581
  (0, import_log9.log)("Writable feeds created", void 0, {
2566
2582
  F: __dxlog_file9,
2567
- L: 201,
2583
+ L: 221,
2568
2584
  S: this,
2569
2585
  C: (f, a) => f(...a)
2570
2586
  });
2571
2587
  this.stateUpdate.emit();
2572
- this.notarizationPlugin.setWriter((0, import_echo_pipeline.createMappedFeedWriter)((credential) => ({
2573
- credential: {
2574
- credential
2575
- }
2576
- }), this._inner.controlPipeline.writer));
2588
+ if (!this.notarizationPlugin.hasWriter) {
2589
+ this.notarizationPlugin.setWriter((0, import_echo_pipeline.createMappedFeedWriter)((credential) => ({
2590
+ credential: {
2591
+ credential
2592
+ }
2593
+ }), this._inner.controlPipeline.writer));
2594
+ }
2577
2595
  await this._inner.initializeDataPipeline();
2578
2596
  this.metrics.dataPipelineOpen = new Date();
2579
2597
  await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
2580
2598
  (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
2581
2599
  F: __dxlog_file9,
2582
- L: 220,
2600
+ L: 242,
2583
2601
  S: this,
2584
2602
  C: (f, a) => f(...a)
2585
2603
  });
@@ -2590,7 +2608,7 @@ var DataSpace = class DataSpace2 {
2590
2608
  this.metrics.dataPipelineReady = new Date();
2591
2609
  (0, import_log9.log)("data pipeline ready", void 0, {
2592
2610
  F: __dxlog_file9,
2593
- L: 229,
2611
+ L: 251,
2594
2612
  S: this,
2595
2613
  C: (f, a) => f(...a)
2596
2614
  });
@@ -2670,10 +2688,39 @@ var DataSpace = class DataSpace2 {
2670
2688
  }
2671
2689
  }
2672
2690
  }
2691
+ async activate() {
2692
+ if (this._state !== import_services6.SpaceState.INACTIVE) {
2693
+ throw new import_errors3.SystemError("Invalid operation");
2694
+ }
2695
+ await this._metadataStore.setSpaceState(this.key, import_services6.SpaceState.ACTIVE);
2696
+ await this._open();
2697
+ this.initializeDataPipelineAsync();
2698
+ }
2699
+ async deactivate() {
2700
+ if (this._state === import_services6.SpaceState.INACTIVE) {
2701
+ throw new import_errors3.SystemError("Invalid operation");
2702
+ }
2703
+ await this._metadataStore.setSpaceState(this.key, import_services6.SpaceState.INACTIVE);
2704
+ await this._close();
2705
+ this._state = import_services6.SpaceState.INACTIVE;
2706
+ this.stateUpdate.emit();
2707
+ }
2673
2708
  };
2709
+ _ts_decorate([
2710
+ import_async11.synchronized
2711
+ ], DataSpace.prototype, "open", null);
2712
+ _ts_decorate([
2713
+ import_async11.synchronized
2714
+ ], DataSpace.prototype, "close", null);
2674
2715
  _ts_decorate([
2675
2716
  (0, import_debug3.timed)(1e4)
2676
2717
  ], DataSpace.prototype, "_createWritableFeeds", null);
2718
+ _ts_decorate([
2719
+ import_async11.synchronized
2720
+ ], DataSpace.prototype, "activate", null);
2721
+ _ts_decorate([
2722
+ import_async11.synchronized
2723
+ ], DataSpace.prototype, "deactivate", null);
2677
2724
  DataSpace = _ts_decorate([
2678
2725
  (0, import_async11.trackLeaks)("open", "close")
2679
2726
  ], DataSpace);
@@ -2813,14 +2860,16 @@ var DataSpaceManager = class DataSpaceManager2 {
2813
2860
  C: (f, a) => f(...a)
2814
2861
  });
2815
2862
  const space = await this._constructSpace(spaceMetadata);
2816
- space.initializeDataPipelineAsync();
2863
+ if (spaceMetadata.state !== import_services7.SpaceState.INACTIVE) {
2864
+ space.initializeDataPipelineAsync();
2865
+ }
2817
2866
  } catch (err) {
2818
2867
  import_log10.log.error("Error loading space", {
2819
2868
  spaceMetadata,
2820
2869
  err
2821
2870
  }, {
2822
2871
  F: __dxlog_file10,
2823
- L: 91,
2872
+ L: 93,
2824
2873
  S: this,
2825
2874
  C: (f, a) => f(...a)
2826
2875
  });
@@ -2832,7 +2881,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2832
2881
  id: this._instanceId
2833
2882
  }), {
2834
2883
  F: __dxlog_file10,
2835
- L: 97,
2884
+ L: 99,
2836
2885
  S: this,
2837
2886
  C: (f, a) => f(...a)
2838
2887
  });
@@ -2840,7 +2889,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2840
2889
  async close() {
2841
2890
  (0, import_log10.log)("close", void 0, {
2842
2891
  F: __dxlog_file10,
2843
- L: 102,
2892
+ L: 104,
2844
2893
  S: this,
2845
2894
  C: (f, a) => f(...a)
2846
2895
  });
@@ -2862,13 +2911,14 @@ var DataSpaceManager = class DataSpaceManager2 {
2862
2911
  key: spaceKey,
2863
2912
  genesisFeedKey: controlFeedKey,
2864
2913
  controlFeedKey,
2865
- dataFeedKey
2914
+ dataFeedKey,
2915
+ state: import_services7.SpaceState.ACTIVE
2866
2916
  };
2867
2917
  (0, import_log10.log)("creating space...", {
2868
2918
  spaceKey
2869
2919
  }, {
2870
2920
  F: __dxlog_file10,
2871
- L: 126,
2921
+ L: 129,
2872
2922
  S: this,
2873
2923
  C: (f, a) => f(...a)
2874
2924
  });
@@ -2888,7 +2938,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2888
2938
  opts
2889
2939
  }, {
2890
2940
  F: __dxlog_file10,
2891
- L: 145,
2941
+ L: 148,
2892
2942
  S: this,
2893
2943
  C: (f, a) => f(...a)
2894
2944
  });
@@ -2922,7 +2972,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2922
2972
  metadata
2923
2973
  }, {
2924
2974
  F: __dxlog_file10,
2925
- L: 180,
2975
+ L: 183,
2926
2976
  S: this,
2927
2977
  C: (f, a) => f(...a)
2928
2978
  });
@@ -2958,7 +3008,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2958
3008
  onAuthFailure: () => {
2959
3009
  import_log10.log.warn("auth failure", void 0, {
2960
3010
  F: __dxlog_file10,
2961
- L: 211,
3011
+ L: 214,
2962
3012
  S: this,
2963
3013
  C: (f, a) => f(...a)
2964
3014
  });
@@ -2969,6 +3019,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2969
3019
  dataFeed && space.setDataFeed(dataFeed);
2970
3020
  const dataSpace = new DataSpace({
2971
3021
  inner: space,
3022
+ initialState: metadata.state === import_services7.SpaceState.INACTIVE ? import_services7.SpaceState.INACTIVE : import_services7.SpaceState.CLOSED,
2972
3023
  metadataStore: this._metadataStore,
2973
3024
  gossip,
2974
3025
  presence,
@@ -2981,11 +3032,11 @@ var DataSpaceManager = class DataSpaceManager2 {
2981
3032
  space: space.key
2982
3033
  }, {
2983
3034
  F: __dxlog_file10,
2984
- L: 228,
3035
+ L: 232,
2985
3036
  S: this,
2986
3037
  C: (f, a) => f(...a)
2987
3038
  });
2988
- this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
3039
+ await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
2989
3040
  },
2990
3041
  afterReady: async () => {
2991
3042
  (0, import_log10.log)("after space ready", {
@@ -2993,18 +3044,31 @@ var DataSpaceManager = class DataSpaceManager2 {
2993
3044
  open: this._isOpen
2994
3045
  }, {
2995
3046
  F: __dxlog_file10,
2996
- L: 235,
3047
+ L: 239,
2997
3048
  S: this,
2998
3049
  C: (f, a) => f(...a)
2999
3050
  });
3000
3051
  if (this._isOpen) {
3001
3052
  this.updated.emit();
3002
3053
  }
3054
+ },
3055
+ beforeClose: async () => {
3056
+ (0, import_log10.log)("before space close", {
3057
+ space: space.key
3058
+ }, {
3059
+ F: __dxlog_file10,
3060
+ L: 245,
3061
+ S: this,
3062
+ C: (f, a) => f(...a)
3063
+ });
3064
+ await this._dataServiceSubscriptions.unregisterSpace(space.key);
3003
3065
  }
3004
3066
  },
3005
3067
  cache: metadata.cache
3006
3068
  });
3007
- await dataSpace.open();
3069
+ if (metadata.state !== import_services7.SpaceState.INACTIVE) {
3070
+ await dataSpace.open();
3071
+ }
3008
3072
  if (metadata.controlTimeframe) {
3009
3073
  dataSpace.inner.controlPipeline.state.setTargetTimeframe(metadata.controlTimeframe);
3010
3074
  }
@@ -3036,6 +3100,7 @@ var import_async13 = require("@dxos/async");
3036
3100
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
3037
3101
  var import_debug5 = require("@dxos/debug");
3038
3102
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
3103
+ var import_errors4 = require("@dxos/errors");
3039
3104
  var import_log11 = require("@dxos/log");
3040
3105
  var import_protocols7 = require("@dxos/protocols");
3041
3106
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
@@ -3056,8 +3121,22 @@ var SpacesServiceImpl = class {
3056
3121
  const space = await dataSpaceManager.createSpace();
3057
3122
  return this._serializeSpace(space);
3058
3123
  }
3059
- async updateSpace(request) {
3060
- (0, import_debug5.todo)();
3124
+ async updateSpace({ spaceKey, state }) {
3125
+ var _a;
3126
+ const dataSpaceManager = await this._getDataSpaceManager();
3127
+ const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3128
+ if (state) {
3129
+ switch (state) {
3130
+ case import_services8.SpaceState.ACTIVE:
3131
+ await space.activate();
3132
+ break;
3133
+ case import_services8.SpaceState.INACTIVE:
3134
+ await space.deactivate();
3135
+ break;
3136
+ default:
3137
+ throw new import_errors4.ApiError("Invalid space state");
3138
+ }
3139
+ }
3061
3140
  }
3062
3141
  querySpaces() {
3063
3142
  return new import_codec_protobuf9.Stream(({ next, ctx }) => {
@@ -3068,7 +3147,7 @@ var SpacesServiceImpl = class {
3068
3147
  spaces
3069
3148
  }, {
3070
3149
  F: __dxlog_file11,
3071
- L: 60,
3150
+ L: 78,
3072
3151
  S: this,
3073
3152
  C: (f, a) => f(...a)
3074
3153
  });
@@ -3131,13 +3210,13 @@ var SpacesServiceImpl = class {
3131
3210
  return new import_codec_protobuf9.Stream(({ ctx, next }) => {
3132
3211
  var _a;
3133
3212
  const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
3134
- const processor = space.spaceState.registerProcessor({
3135
- process: async (credential) => {
3213
+ const processor = {
3214
+ processCredential: async (credential) => {
3136
3215
  next(credential);
3137
3216
  }
3138
- });
3139
- ctx.onDispose(() => processor.close());
3140
- (0, import_async13.scheduleTask)(ctx, () => processor.open());
3217
+ };
3218
+ ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
3219
+ (0, import_async13.scheduleTask)(ctx, () => space.spaceState.addCredentialProcessor(processor));
3141
3220
  });
3142
3221
  }
3143
3222
  async writeCredentials({ spaceKey, credentials }) {
@@ -3276,15 +3355,17 @@ var ServiceContext = class {
3276
3355
  });
3277
3356
  }
3278
3357
  async close() {
3279
- var _a, _b;
3358
+ var _a;
3280
3359
  (0, import_log12.log)("closing...", void 0, {
3281
3360
  F: __dxlog_file12,
3282
3361
  L: 143,
3283
3362
  S: this,
3284
3363
  C: (f, a) => f(...a)
3285
3364
  });
3286
- await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
3287
- await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
3365
+ if (this._deviceSpaceSync && this.identityManager.identity) {
3366
+ await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
3367
+ }
3368
+ await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
3288
3369
  await this.identityManager.close();
3289
3370
  await this.spaceManager.close();
3290
3371
  await this.feedStore.close();
@@ -3293,7 +3374,7 @@ var ServiceContext = class {
3293
3374
  this.dataServiceSubscriptions.clear();
3294
3375
  (0, import_log12.log)("closed", void 0, {
3295
3376
  F: __dxlog_file12,
3296
- L: 152,
3377
+ L: 154,
3297
3378
  S: this,
3298
3379
  C: (f, a) => f(...a)
3299
3380
  });
@@ -3324,7 +3405,7 @@ var ServiceContext = class {
3324
3405
  var _a;
3325
3406
  (0, import_log12.log)("initializing spaces...", void 0, {
3326
3407
  F: __dxlog_file12,
3327
- L: 185,
3408
+ L: 187,
3328
3409
  S: this,
3329
3410
  C: (f, a) => f(...a)
3330
3411
  });
@@ -3349,8 +3430,8 @@ var ServiceContext = class {
3349
3430
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3350
3431
  });
3351
3432
  this.initialized.wake();
3352
- this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
3353
- process: async (credential) => {
3433
+ this._deviceSpaceSync = {
3434
+ processCredential: async (credential) => {
3354
3435
  const assertion = (0, import_credentials13.getCredentialAssertion)(credential);
3355
3436
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
3356
3437
  return;
@@ -3363,7 +3444,7 @@ var ServiceContext = class {
3363
3444
  details: assertion
3364
3445
  }, {
3365
3446
  F: __dxlog_file12,
3366
- L: 224,
3447
+ L: 226,
3367
3448
  S: this,
3368
3449
  C: (f, a) => f(...a)
3369
3450
  });
@@ -3374,7 +3455,7 @@ var ServiceContext = class {
3374
3455
  details: assertion
3375
3456
  }, {
3376
3457
  F: __dxlog_file12,
3377
- L: 228,
3458
+ L: 230,
3378
3459
  S: this,
3379
3460
  C: (f, a) => f(...a)
3380
3461
  });
@@ -3385,7 +3466,7 @@ var ServiceContext = class {
3385
3466
  details: assertion
3386
3467
  }, {
3387
3468
  F: __dxlog_file12,
3388
- L: 233,
3469
+ L: 235,
3389
3470
  S: this,
3390
3471
  C: (f, a) => f(...a)
3391
3472
  });
@@ -3396,14 +3477,14 @@ var ServiceContext = class {
3396
3477
  } catch (err) {
3397
3478
  import_log12.log.catch(err, void 0, {
3398
3479
  F: __dxlog_file12,
3399
- L: 239,
3480
+ L: 241,
3400
3481
  S: this,
3401
3482
  C: (f, a) => f(...a)
3402
3483
  });
3403
3484
  }
3404
3485
  }
3405
- });
3406
- await this._deviceSpaceSync.open();
3486
+ };
3487
+ await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
3407
3488
  }
3408
3489
  };
3409
3490
 
@@ -3632,7 +3713,7 @@ var NetworkServiceImpl = class {
3632
3713
 
3633
3714
  // packages/sdk/client-services/src/packlets/storage/storage.ts
3634
3715
  var import_client_protocol4 = require("@dxos/client-protocol");
3635
- var import_errors4 = require("@dxos/errors");
3716
+ var import_errors5 = require("@dxos/errors");
3636
3717
  var import_config = require("@dxos/protocols/proto/dxos/config");
3637
3718
  var import_random_access_storage = require("@dxos/random-access-storage");
3638
3719
  var import_util8 = require("@dxos/util");
@@ -3640,16 +3721,16 @@ var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
3640
3721
  var createStorageObjects = (config) => {
3641
3722
  const { path = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
3642
3723
  if (persistent && storageType === StorageDriver.RAM) {
3643
- throw new import_errors4.InvalidConfigError("RAM storage cannot be used in persistent mode.");
3724
+ throw new import_errors5.InvalidConfigError("RAM storage cannot be used in persistent mode.");
3644
3725
  }
3645
3726
  if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
3646
- throw new import_errors4.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
3727
+ throw new import_errors5.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
3647
3728
  }
3648
3729
  if (persistent && keyStorage === StorageDriver.RAM) {
3649
- throw new import_errors4.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
3730
+ throw new import_errors5.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
3650
3731
  }
3651
3732
  if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
3652
- throw new import_errors4.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
3733
+ throw new import_errors5.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
3653
3734
  }
3654
3735
  return {
3655
3736
  storage: (0, import_random_access_storage.createStorage)({
@@ -3766,13 +3847,15 @@ var ClientServicesHost = class {
3766
3847
  connectionLog,
3767
3848
  storage,
3768
3849
  // TODO(wittjosiah): Turn this on by default.
3769
- lockKey
3850
+ lockKey,
3851
+ callbacks
3770
3852
  } = {}) {
3771
3853
  this._statusUpdate = new import_async17.Event();
3772
3854
  this._opening = false;
3773
3855
  this._open = false;
3774
3856
  this._storage = storage;
3775
3857
  this._modelFactory = modelFactory;
3858
+ this._callbacks = callbacks;
3776
3859
  if (config) {
3777
3860
  this.initialize({
3778
3861
  config,
@@ -3860,7 +3943,7 @@ var ClientServicesHost = class {
3860
3943
  id: traceId
3861
3944
  }), {
3862
3945
  F: __dxlog_file14,
3863
- L: 195,
3946
+ L: 203,
3864
3947
  S: this,
3865
3948
  C: (f, a) => f(...a)
3866
3949
  });
@@ -3873,7 +3956,7 @@ var ClientServicesHost = class {
3873
3956
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
3874
3957
  }, {
3875
3958
  F: __dxlog_file14,
3876
- L: 203,
3959
+ L: 211,
3877
3960
  S: this,
3878
3961
  C: (f, a) => f(...a)
3879
3962
  });
@@ -3908,7 +3991,7 @@ var ClientServicesHost = class {
3908
3991
  deviceKey
3909
3992
  }, {
3910
3993
  F: __dxlog_file14,
3911
- L: 258,
3994
+ L: 266,
3912
3995
  S: this,
3913
3996
  C: (f, a) => f(...a)
3914
3997
  });
@@ -3916,7 +3999,7 @@ var ClientServicesHost = class {
3916
3999
  id: traceId
3917
4000
  }), {
3918
4001
  F: __dxlog_file14,
3919
- L: 259,
4002
+ L: 267,
3920
4003
  S: this,
3921
4004
  C: (f, a) => f(...a)
3922
4005
  });
@@ -3931,7 +4014,7 @@ var ClientServicesHost = class {
3931
4014
  deviceKey
3932
4015
  }, {
3933
4016
  F: __dxlog_file14,
3934
- L: 269,
4017
+ L: 277,
3935
4018
  S: this,
3936
4019
  C: (f, a) => f(...a)
3937
4020
  });
@@ -3946,25 +4029,25 @@ var ClientServicesHost = class {
3946
4029
  deviceKey
3947
4030
  }, {
3948
4031
  F: __dxlog_file14,
3949
- L: 275,
4032
+ L: 283,
3950
4033
  S: this,
3951
4034
  C: (f, a) => f(...a)
3952
4035
  });
3953
4036
  }
3954
4037
  async reset() {
3955
- var _a;
4038
+ var _a, _b, _c;
3956
4039
  const traceId = import_keys11.PublicKey.random().toHex();
3957
4040
  import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols9.trace.begin({
3958
4041
  id: traceId
3959
4042
  }), {
3960
4043
  F: __dxlog_file14,
3961
- L: 280,
4044
+ L: 288,
3962
4045
  S: this,
3963
4046
  C: (f, a) => f(...a)
3964
4047
  });
3965
4048
  (0, import_log15.log)("resetting...", void 0, {
3966
4049
  F: __dxlog_file14,
3967
- L: 282,
4050
+ L: 290,
3968
4051
  S: this,
3969
4052
  C: (f, a) => f(...a)
3970
4053
  });
@@ -3972,7 +4055,7 @@ var ClientServicesHost = class {
3972
4055
  await this._storage.reset();
3973
4056
  (0, import_log15.log)("reset", void 0, {
3974
4057
  F: __dxlog_file14,
3975
- L: 285,
4058
+ L: 293,
3976
4059
  S: this,
3977
4060
  C: (f, a) => f(...a)
3978
4061
  });
@@ -3980,10 +4063,11 @@ var ClientServicesHost = class {
3980
4063
  id: traceId
3981
4064
  }), {
3982
4065
  F: __dxlog_file14,
3983
- L: 286,
4066
+ L: 294,
3984
4067
  S: this,
3985
4068
  C: (f, a) => f(...a)
3986
4069
  });
4070
+ await ((_c = (_b = this._callbacks) == null ? void 0 : _b.onReset) == null ? void 0 : _c.call(_b));
3987
4071
  }
3988
4072
  };
3989
4073
  _ts_decorate4([
@@ -4236,7 +4320,7 @@ _ts_decorate5([
4236
4320
  // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
4237
4321
  var import_async20 = require("@dxos/async");
4238
4322
  var import_client_protocol8 = require("@dxos/client-protocol");
4239
- var import_errors5 = require("@dxos/errors");
4323
+ var import_errors6 = require("@dxos/errors");
4240
4324
  var import_log17 = require("@dxos/log");
4241
4325
  var import_network_manager4 = require("@dxos/network-manager");
4242
4326
  var import_rpc3 = require("@dxos/rpc");
@@ -4295,7 +4379,7 @@ var IFrameProxyRuntime = class {
4295
4379
  S: this,
4296
4380
  C: (f, a) => f(...a)
4297
4381
  });
4298
- throw new import_errors5.RemoteServiceConnectionError("Failed to connect to worker");
4382
+ throw new import_errors6.RemoteServiceConnectionError("Failed to connect to worker");
4299
4383
  }
4300
4384
  await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
4301
4385
  }
@@ -4476,7 +4560,13 @@ var WorkerRuntime = class {
4476
4560
  this._transportFactory = new import_network_manager5.WebRTCTransportProxyFactory();
4477
4561
  this._ready = new import_async22.Trigger();
4478
4562
  this.sessions = /* @__PURE__ */ new Set();
4479
- this._clientServices = new ClientServicesHost();
4563
+ this._clientServices = new ClientServicesHost({
4564
+ callbacks: {
4565
+ onReset: async () => {
4566
+ self.close();
4567
+ }
4568
+ }
4569
+ });
4480
4570
  }
4481
4571
  get host() {
4482
4572
  return this._clientServices;