@dxos/client-services 0.4.10-main.c5e8686 → 0.4.10-main.c75170d

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 (33) hide show
  1. package/dist/lib/browser/{chunk-FUEOAPLA.mjs → chunk-JP7F2IH3.mjs} +350 -307
  2. package/dist/lib/browser/chunk-JP7F2IH3.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-VRSCM2WE.cjs → chunk-34EZSH65.cjs} +346 -304
  8. package/dist/lib/node/chunk-34EZSH65.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +44 -42
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +6 -6
  13. package/dist/types/src/packlets/invitations/index.d.ts +1 -0
  14. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +42 -0
  17. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
  18. package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
  19. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  20. package/dist/types/src/packlets/services/service-context.d.ts +2 -0
  21. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  22. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  23. package/dist/types/src/version.d.ts +1 -1
  24. package/package.json +34 -34
  25. package/src/packlets/invitations/index.ts +1 -0
  26. package/src/packlets/invitations/invitations-handler.ts +1 -2
  27. package/src/packlets/invitations/invitations-manager.ts +197 -0
  28. package/src/packlets/invitations/invitations-service.ts +21 -168
  29. package/src/packlets/services/service-context.ts +11 -0
  30. package/src/packlets/services/service-host.ts +1 -10
  31. package/src/version.ts +1 -1
  32. package/dist/lib/browser/chunk-FUEOAPLA.mjs.map +0 -7
  33. package/dist/lib/node/chunk-VRSCM2WE.cjs.map +0 -7
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_VRSCM2WE_exports = {};
30
- __export(chunk_VRSCM2WE_exports, {
29
+ var chunk_34EZSH65_exports = {};
30
+ __export(chunk_34EZSH65_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -41,6 +41,7 @@ __export(chunk_VRSCM2WE_exports, {
41
41
  IdentityManager: () => IdentityManager,
42
42
  IdentityServiceImpl: () => IdentityServiceImpl,
43
43
  InvitationsHandler: () => InvitationsHandler,
44
+ InvitationsManager: () => InvitationsManager,
44
45
  InvitationsServiceImpl: () => InvitationsServiceImpl,
45
46
  Lock: () => Lock,
46
47
  ServiceContext: () => ServiceContext,
@@ -65,7 +66,7 @@ __export(chunk_VRSCM2WE_exports, {
65
66
  subscribeToSpaces: () => subscribeToSpaces,
66
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
67
68
  });
68
- module.exports = __toCommonJS(chunk_VRSCM2WE_exports);
69
+ module.exports = __toCommonJS(chunk_34EZSH65_exports);
69
70
  var import_async = require("@dxos/async");
70
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
71
72
  var import_feed_store = require("@dxos/feed-store");
@@ -138,26 +139,25 @@ var import_protocols5 = require("@dxos/protocols");
138
139
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
139
140
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
140
141
  var import_teleport = require("@dxos/teleport");
141
- var import_async9 = require("@dxos/async");
142
142
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
143
- var import_context6 = require("@dxos/context");
144
- var import_echo_pipeline = require("@dxos/echo-pipeline");
145
- var import_invariant7 = require("@dxos/invariant");
146
- var import_log6 = require("@dxos/log");
147
143
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
148
144
  var import_credentials8 = require("@dxos/credentials");
149
145
  var import_feed_store3 = require("@dxos/feed-store");
150
- var import_invariant8 = require("@dxos/invariant");
151
- var import_log7 = require("@dxos/log");
146
+ var import_invariant7 = require("@dxos/invariant");
147
+ var import_log6 = require("@dxos/log");
152
148
  var import_protocols6 = require("@dxos/protocols");
153
149
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
150
+ var import_async9 = require("@dxos/async");
151
+ var import_echo_pipeline = require("@dxos/echo-pipeline");
152
+ var import_invariant8 = require("@dxos/invariant");
153
+ var import_log7 = require("@dxos/log");
154
154
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
155
155
  var import_debug2 = require("@dxos/debug");
156
156
  var import_rpc = require("@dxos/rpc");
157
157
  var import_tracing3 = require("@dxos/tracing");
158
158
  var import_async10 = require("@dxos/async");
159
159
  var import_client_protocol3 = require("@dxos/client-protocol");
160
- var import_context7 = require("@dxos/context");
160
+ var import_context6 = require("@dxos/context");
161
161
  var import_debug3 = require("@dxos/debug");
162
162
  var import_echo_db = require("@dxos/echo-db");
163
163
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
@@ -174,7 +174,7 @@ var import_util4 = require("@dxos/util");
174
174
  var import_async11 = require("@dxos/async");
175
175
  var import_credentials10 = require("@dxos/credentials");
176
176
  var import_async12 = require("@dxos/async");
177
- var import_context8 = require("@dxos/context");
177
+ var import_context7 = require("@dxos/context");
178
178
  var import_invariant10 = require("@dxos/invariant");
179
179
  var import_keys8 = require("@dxos/keys");
180
180
  var import_log9 = require("@dxos/log");
@@ -182,7 +182,7 @@ var import_protocols8 = require("@dxos/protocols");
182
182
  var import_teleport2 = require("@dxos/teleport");
183
183
  var import_util5 = require("@dxos/util");
184
184
  var import_async13 = require("@dxos/async");
185
- var import_context9 = require("@dxos/context");
185
+ var import_context8 = require("@dxos/context");
186
186
  var import_credentials11 = require("@dxos/credentials");
187
187
  var import_invariant11 = require("@dxos/invariant");
188
188
  var import_keys9 = require("@dxos/keys");
@@ -203,7 +203,7 @@ var import_log11 = require("@dxos/log");
203
203
  var import_protocols10 = require("@dxos/protocols");
204
204
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
205
205
  var import_async15 = require("@dxos/async");
206
- var import_context10 = require("@dxos/context");
206
+ var import_context9 = require("@dxos/context");
207
207
  var import_credentials14 = require("@dxos/credentials");
208
208
  var import_debug6 = require("@dxos/debug");
209
209
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
@@ -234,7 +234,7 @@ var import_tracing7 = require("@dxos/tracing");
234
234
  var import_util8 = require("@dxos/util");
235
235
  var import_async16 = require("@dxos/async");
236
236
  var import_client_protocol4 = require("@dxos/client-protocol");
237
- var import_context11 = require("@dxos/context");
237
+ var import_context10 = require("@dxos/context");
238
238
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
239
239
  var import_echo_schema = require("@dxos/echo-schema");
240
240
  var import_indexing2 = require("@dxos/indexing");
@@ -2021,7 +2021,7 @@ var InvitationsHandler = class {
2021
2021
  });
2022
2022
  return extension;
2023
2023
  };
2024
- if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
2024
+ if (invitation.lifetime && invitation.created) {
2025
2025
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2026
2026
  import_log4.log.warn("invitation has already expired", void 0, {
2027
2027
  F: __dxlog_file7,
@@ -2086,7 +2086,7 @@ var InvitationsHandler = class {
2086
2086
  if (deviceProfile) {
2087
2087
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2088
2088
  F: __dxlog_file7,
2089
- L: 256,
2089
+ L: 255,
2090
2090
  S: this,
2091
2091
  A: [
2092
2092
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2101,7 +2101,7 @@ var InvitationsHandler = class {
2101
2101
  const setState = (newData) => {
2102
2102
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2103
2103
  F: __dxlog_file7,
2104
- L: 267,
2104
+ L: 266,
2105
2105
  S: this,
2106
2106
  A: [
2107
2107
  "newData.state !== undefined",
@@ -2121,7 +2121,7 @@ var InvitationsHandler = class {
2121
2121
  ...protocol.toJSON()
2122
2122
  }, {
2123
2123
  F: __dxlog_file7,
2124
- L: 275,
2124
+ L: 274,
2125
2125
  S: this,
2126
2126
  C: (f, a) => f(...a)
2127
2127
  });
@@ -2131,7 +2131,7 @@ var InvitationsHandler = class {
2131
2131
  } else {
2132
2132
  import_log4.log.warn("auth failed", err, {
2133
2133
  F: __dxlog_file7,
2134
- L: 278,
2134
+ L: 277,
2135
2135
  S: this,
2136
2136
  C: (f, a) => f(...a)
2137
2137
  });
@@ -2145,7 +2145,7 @@ var InvitationsHandler = class {
2145
2145
  ...protocol.toJSON()
2146
2146
  }, {
2147
2147
  F: __dxlog_file7,
2148
- L: 286,
2148
+ L: 285,
2149
2149
  S: this,
2150
2150
  C: (f, a) => f(...a)
2151
2151
  });
@@ -2160,7 +2160,7 @@ var InvitationsHandler = class {
2160
2160
  currentState
2161
2161
  }, {
2162
2162
  F: __dxlog_file7,
2163
- L: 296,
2163
+ L: 295,
2164
2164
  S: this,
2165
2165
  C: (f, a) => f(...a)
2166
2166
  });
@@ -2175,7 +2175,7 @@ var InvitationsHandler = class {
2175
2175
  id: traceId
2176
2176
  }), {
2177
2177
  F: __dxlog_file7,
2178
- L: 305,
2178
+ L: 304,
2179
2179
  S: this,
2180
2180
  C: (f, a) => f(...a)
2181
2181
  });
@@ -2187,7 +2187,7 @@ var InvitationsHandler = class {
2187
2187
  ...protocol.toJSON()
2188
2188
  }, {
2189
2189
  F: __dxlog_file7,
2190
- L: 313,
2190
+ L: 312,
2191
2191
  S: this,
2192
2192
  C: (f, a) => f(...a)
2193
2193
  });
@@ -2198,7 +2198,7 @@ var InvitationsHandler = class {
2198
2198
  ...protocol.toJSON()
2199
2199
  }, {
2200
2200
  F: __dxlog_file7,
2201
- L: 317,
2201
+ L: 316,
2202
2202
  S: this,
2203
2203
  C: (f, a) => f(...a)
2204
2204
  });
@@ -2208,7 +2208,7 @@ var InvitationsHandler = class {
2208
2208
  response: introductionResponse
2209
2209
  }, {
2210
2210
  F: __dxlog_file7,
2211
- L: 321,
2211
+ L: 320,
2212
2212
  S: this,
2213
2213
  C: (f, a) => f(...a)
2214
2214
  });
@@ -2229,7 +2229,7 @@ var InvitationsHandler = class {
2229
2229
  ...protocol.toJSON()
2230
2230
  }, {
2231
2231
  F: __dxlog_file7,
2232
- L: 337,
2232
+ L: 336,
2233
2233
  S: this,
2234
2234
  C: (f, a) => f(...a)
2235
2235
  });
@@ -2241,7 +2241,7 @@ var InvitationsHandler = class {
2241
2241
  ...protocol.toJSON()
2242
2242
  }, {
2243
2243
  F: __dxlog_file7,
2244
- L: 348,
2244
+ L: 347,
2245
2245
  S: this,
2246
2246
  C: (f, a) => f(...a)
2247
2247
  });
@@ -2254,7 +2254,7 @@ var InvitationsHandler = class {
2254
2254
  id: traceId
2255
2255
  }), {
2256
2256
  F: __dxlog_file7,
2257
- L: 350,
2257
+ L: 349,
2258
2258
  S: this,
2259
2259
  C: (f, a) => f(...a)
2260
2260
  });
@@ -2264,7 +2264,7 @@ var InvitationsHandler = class {
2264
2264
  ...protocol.toJSON()
2265
2265
  }, {
2266
2266
  F: __dxlog_file7,
2267
- L: 353,
2267
+ L: 352,
2268
2268
  S: this,
2269
2269
  C: (f, a) => f(...a)
2270
2270
  });
@@ -2274,7 +2274,7 @@ var InvitationsHandler = class {
2274
2274
  } else {
2275
2275
  (0, import_log4.log)("auth failed", err, {
2276
2276
  F: __dxlog_file7,
2277
- L: 356,
2277
+ L: 355,
2278
2278
  S: this,
2279
2279
  C: (f, a) => f(...a)
2280
2280
  });
@@ -2285,7 +2285,7 @@ var InvitationsHandler = class {
2285
2285
  error: err
2286
2286
  }), {
2287
2287
  F: __dxlog_file7,
2288
- L: 359,
2288
+ L: 358,
2289
2289
  S: this,
2290
2290
  C: (f, a) => f(...a)
2291
2291
  });
@@ -2303,7 +2303,7 @@ var InvitationsHandler = class {
2303
2303
  ...protocol.toJSON()
2304
2304
  }, {
2305
2305
  F: __dxlog_file7,
2306
- L: 370,
2306
+ L: 369,
2307
2307
  S: this,
2308
2308
  C: (f, a) => f(...a)
2309
2309
  });
@@ -2313,7 +2313,7 @@ var InvitationsHandler = class {
2313
2313
  } else {
2314
2314
  (0, import_log4.log)("auth failed", err, {
2315
2315
  F: __dxlog_file7,
2316
- L: 373,
2316
+ L: 372,
2317
2317
  S: this,
2318
2318
  C: (f, a) => f(...a)
2319
2319
  });
@@ -2330,7 +2330,7 @@ var InvitationsHandler = class {
2330
2330
  } else {
2331
2331
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2332
2332
  F: __dxlog_file7,
2333
- L: 387,
2333
+ L: 386,
2334
2334
  S: this,
2335
2335
  A: [
2336
2336
  "invitation.swarmKey",
@@ -2372,7 +2372,7 @@ var InvitationsHandler = class {
2372
2372
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2373
2373
  (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2374
2374
  F: __dxlog_file7,
2375
- L: 427,
2375
+ L: 426,
2376
2376
  S: this,
2377
2377
  C: (f, a) => f(...a)
2378
2378
  });
@@ -2382,7 +2382,7 @@ var InvitationsHandler = class {
2382
2382
  const authCode = await authenticated.wait(options);
2383
2383
  (0, import_log4.log)("sending authentication request", void 0, {
2384
2384
  F: __dxlog_file7,
2385
- L: 431,
2385
+ L: 430,
2386
2386
  S: this,
2387
2387
  C: (f, a) => f(...a)
2388
2388
  });
@@ -2403,7 +2403,7 @@ var InvitationsHandler = class {
2403
2403
  attempt
2404
2404
  }, {
2405
2405
  F: __dxlog_file7,
2406
- L: 442,
2406
+ L: 441,
2407
2407
  S: this,
2408
2408
  C: (f, a) => f(...a)
2409
2409
  });
@@ -2421,7 +2421,7 @@ var InvitationsHandler = class {
2421
2421
  }
2422
2422
  (0, import_log4.log)("sending authentication request", void 0, {
2423
2423
  F: __dxlog_file7,
2424
- L: 461,
2424
+ L: 460,
2425
2425
  S: this,
2426
2426
  C: (f, a) => f(...a)
2427
2427
  });
@@ -2444,194 +2444,35 @@ var createAdmissionKeypair = () => {
2444
2444
  privateKey: keypair.secretKey
2445
2445
  };
2446
2446
  };
2447
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2448
2447
  var InvitationsServiceImpl = class {
2449
- constructor(_invitationsHandler, _getHandler, _metadataStore) {
2450
- this._invitationsHandler = _invitationsHandler;
2451
- this._getHandler = _getHandler;
2452
- this._metadataStore = _metadataStore;
2453
- this._createInvitations = /* @__PURE__ */ new Map();
2454
- this._acceptInvitations = /* @__PURE__ */ new Map();
2455
- this._invitationCreated = new import_async9.Event();
2456
- this._invitationAccepted = new import_async9.Event();
2457
- this._removedCreated = new import_async9.Event();
2458
- this._removedAccepted = new import_async9.Event();
2459
- this._saved = new import_async9.Event();
2460
- this._persistentInvitationsLoadedEvent = new import_async9.Event();
2461
- this._persistentInvitationsLoaded = false;
2448
+ constructor(_invitationsManager) {
2449
+ this._invitationsManager = _invitationsManager;
2462
2450
  }
2463
2451
  // TODO(burdon): Guest/host label.
2464
2452
  getLoggingContext() {
2465
2453
  return {};
2466
2454
  }
2467
2455
  createInvitation(options) {
2468
- let invitation;
2469
- const savePersistentInvitationCtx = new import_context6.Context();
2470
- const existingInvitation = this._createInvitations.get(options.invitationId);
2471
- if (existingInvitation) {
2472
- invitation = existingInvitation;
2473
- } else {
2474
- const handler = this._getHandler(options);
2475
- invitation = this._invitationsHandler.createInvitation(handler, options);
2476
- this._createInvitations.set(invitation.get().invitationId, invitation);
2477
- this._invitationCreated.emit(invitation.get());
2478
- }
2456
+ const invitation = this._invitationsManager.createInvitation(options);
2479
2457
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2480
- if (invitation.get().persistent) {
2481
- (0, import_async9.scheduleTask)(savePersistentInvitationCtx, async () => {
2482
- try {
2483
- await this._metadataStore.addInvitation(invitation.get());
2484
- this._saved.emit(invitation.get());
2485
- } catch (err) {
2486
- close(err);
2487
- }
2488
- });
2489
- }
2490
- invitation.subscribe((invitation2) => {
2491
- next(invitation2);
2492
- }, async (err) => {
2493
- await savePersistentInvitationCtx.dispose();
2494
- close(err);
2495
- }, async () => {
2496
- close();
2497
- if (invitation.get().persistent) {
2498
- await savePersistentInvitationCtx.dispose();
2499
- await this._metadataStore.removeInvitation(invitation.get().invitationId);
2500
- }
2501
- this._createInvitations.delete(invitation.get().invitationId);
2502
- if (!invitation.get().multiUse) {
2503
- this._removedCreated.emit(invitation.get());
2504
- }
2505
- });
2458
+ invitation.subscribe(next, close, close);
2506
2459
  });
2507
2460
  }
2508
- async loadPersistentInvitations() {
2509
- const persistentInvitations = this._metadataStore.getInvitations();
2510
- const freshInvitations = persistentInvitations.filter(async (invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2511
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2512
- (0, import_invariant7.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2513
- F: __dxlog_file8,
2514
- L: 109,
2515
- S: this,
2516
- A: [
2517
- "!this._createInvitations.get(persistentInvitation.invitationId)",
2518
- "'invitation already exists'"
2519
- ]
2520
- });
2521
- const handler = this._getHandler(persistentInvitation);
2522
- const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2523
- this._createInvitations.set(invitation.get().invitationId, invitation);
2524
- this._invitationCreated.emit(invitation.get());
2525
- return persistentInvitation;
2526
- });
2527
- this._persistentInvitationsLoadedEvent.emit();
2528
- this._persistentInvitationsLoaded = true;
2529
- return {
2530
- invitations: cInvitations
2531
- };
2532
- }
2533
- acceptInvitation({ invitation: options, deviceProfile }) {
2534
- let invitation;
2535
- if (deviceProfile) {
2536
- (0, import_invariant7.invariant)(options.kind === import_services5.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2537
- F: __dxlog_file8,
2538
- L: 127,
2539
- S: this,
2540
- A: [
2541
- "options.kind === Invitation.Kind.DEVICE",
2542
- "'deviceProfile provided for non-device invitation'"
2543
- ]
2544
- });
2545
- }
2546
- const existingInvitation = this._acceptInvitations.get(options.invitationId);
2547
- if (existingInvitation) {
2548
- invitation = existingInvitation;
2549
- } else {
2550
- const handler = this._getHandler(options);
2551
- invitation = this._invitationsHandler.acceptInvitation(handler, options, deviceProfile);
2552
- this._acceptInvitations.set(invitation.get().invitationId, invitation);
2553
- this._invitationAccepted.emit(invitation.get());
2554
- }
2461
+ acceptInvitation(request) {
2462
+ const invitation = this._invitationsManager.acceptInvitation(request);
2555
2463
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2556
- invitation.subscribe((invitation2) => {
2557
- next(invitation2);
2558
- }, (err) => {
2559
- close(err);
2560
- }, () => {
2561
- close();
2562
- this._acceptInvitations.delete(invitation.get().invitationId);
2563
- if (!invitation.get().multiUse) {
2564
- this._removedAccepted.emit(invitation.get());
2565
- }
2566
- });
2464
+ invitation.subscribe(next, close, close);
2567
2465
  });
2568
2466
  }
2569
- async authenticate({ invitationId, authCode }) {
2570
- (0, import_log6.log)("authenticating...", void 0, {
2571
- F: __dxlog_file8,
2572
- L: 160,
2573
- S: this,
2574
- C: (f, a) => f(...a)
2575
- });
2576
- (0, import_invariant7.invariant)(invitationId, void 0, {
2577
- F: __dxlog_file8,
2578
- L: 161,
2579
- S: this,
2580
- A: [
2581
- "invitationId",
2582
- ""
2583
- ]
2584
- });
2585
- const observable = this._acceptInvitations.get(invitationId);
2586
- if (!observable) {
2587
- import_log6.log.warn("invalid invitation", {
2588
- invitationId
2589
- }, {
2590
- F: __dxlog_file8,
2591
- L: 164,
2592
- S: this,
2593
- C: (f, a) => f(...a)
2594
- });
2595
- } else {
2596
- await observable.authenticate(authCode);
2597
- }
2467
+ async authenticate(request) {
2468
+ return this._invitationsManager.authenticate(request);
2598
2469
  }
2599
- async cancelInvitation({ invitationId }) {
2600
- (0, import_log6.log)("cancelInvitation...", {
2601
- invitationId
2602
- }, {
2603
- F: __dxlog_file8,
2604
- L: 171,
2605
- S: this,
2606
- C: (f, a) => f(...a)
2607
- });
2608
- (0, import_invariant7.invariant)(invitationId, void 0, {
2609
- F: __dxlog_file8,
2610
- L: 172,
2611
- S: this,
2612
- A: [
2613
- "invitationId",
2614
- ""
2615
- ]
2616
- });
2617
- const created = this._createInvitations.get(invitationId);
2618
- const accepted = this._acceptInvitations.get(invitationId);
2619
- if (created) {
2620
- await created.cancel();
2621
- this._createInvitations.delete(invitationId);
2622
- this._removedCreated.emit(created.get());
2623
- if (created.get().persistent) {
2624
- await this._metadataStore.removeInvitation(created.get().invitationId);
2625
- }
2626
- } else if (accepted) {
2627
- await accepted.cancel();
2628
- this._acceptInvitations.delete(invitationId);
2629
- this._removedAccepted.emit(accepted.get());
2630
- }
2470
+ async cancelInvitation(request) {
2471
+ return this._invitationsManager.cancelInvitation(request);
2631
2472
  }
2632
2473
  queryInvitations() {
2633
2474
  return new import_codec_protobuf8.Stream(({ next, ctx }) => {
2634
- this._invitationCreated.on(ctx, (invitation) => {
2475
+ this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
2635
2476
  next({
2636
2477
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2637
2478
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2640,7 +2481,7 @@ var InvitationsServiceImpl = class {
2640
2481
  ]
2641
2482
  });
2642
2483
  });
2643
- this._invitationAccepted.on(ctx, (invitation) => {
2484
+ this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
2644
2485
  next({
2645
2486
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2646
2487
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2649,7 +2490,7 @@ var InvitationsServiceImpl = class {
2649
2490
  ]
2650
2491
  });
2651
2492
  });
2652
- this._removedCreated.on(ctx, (invitation) => {
2493
+ this._invitationsManager.removedCreated.on(ctx, (invitation) => {
2653
2494
  next({
2654
2495
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2655
2496
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2658,7 +2499,7 @@ var InvitationsServiceImpl = class {
2658
2499
  ]
2659
2500
  });
2660
2501
  });
2661
- this._removedAccepted.on(ctx, (invitation) => {
2502
+ this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
2662
2503
  next({
2663
2504
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2664
2505
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2667,7 +2508,7 @@ var InvitationsServiceImpl = class {
2667
2508
  ]
2668
2509
  });
2669
2510
  });
2670
- this._saved.on(ctx, (invitation) => {
2511
+ this._invitationsManager.saved.on(ctx, (invitation) => {
2671
2512
  next({
2672
2513
  action: import_services5.QueryInvitationsResponse.Action.SAVED,
2673
2514
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2679,32 +2520,25 @@ var InvitationsServiceImpl = class {
2679
2520
  next({
2680
2521
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2681
2522
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2682
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2523
+ invitations: this._invitationsManager.getCreatedInvitations(),
2683
2524
  existing: true
2684
2525
  });
2685
2526
  next({
2686
2527
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2687
2528
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2688
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2529
+ invitations: this._invitationsManager.getAcceptedInvitations(),
2689
2530
  existing: true
2690
2531
  });
2691
- if (this._persistentInvitationsLoaded) {
2532
+ this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
2692
2533
  next({
2693
2534
  action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2694
2535
  type: import_services5.QueryInvitationsResponse.Type.CREATED
2695
2536
  });
2696
- } else {
2697
- this._persistentInvitationsLoadedEvent.on(ctx, () => {
2698
- next({
2699
- action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2700
- type: import_services5.QueryInvitationsResponse.Type.CREATED
2701
- });
2702
- });
2703
- }
2537
+ });
2704
2538
  });
2705
2539
  }
2706
2540
  };
2707
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2541
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2708
2542
  var SpaceInvitationProtocol = class {
2709
2543
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2710
2544
  this._spaceManager = _spaceManager;
@@ -2725,8 +2559,8 @@ var SpaceInvitationProtocol = class {
2725
2559
  };
2726
2560
  }
2727
2561
  async admit(request, guestProfile) {
2728
- (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2729
- F: __dxlog_file9,
2562
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2563
+ F: __dxlog_file8,
2730
2564
  L: 47,
2731
2565
  S: this,
2732
2566
  A: [
@@ -2735,8 +2569,8 @@ var SpaceInvitationProtocol = class {
2735
2569
  ]
2736
2570
  });
2737
2571
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2738
- (0, import_invariant8.invariant)(space, void 0, {
2739
- F: __dxlog_file9,
2572
+ (0, import_invariant7.invariant)(space, void 0, {
2573
+ F: __dxlog_file8,
2740
2574
  L: 49,
2741
2575
  S: this,
2742
2576
  A: [
@@ -2744,8 +2578,8 @@ var SpaceInvitationProtocol = class {
2744
2578
  ""
2745
2579
  ]
2746
2580
  });
2747
- (0, import_invariant8.invariant)(request.space, void 0, {
2748
- F: __dxlog_file9,
2581
+ (0, import_invariant7.invariant)(request.space, void 0, {
2582
+ F: __dxlog_file8,
2749
2583
  L: 51,
2750
2584
  S: this,
2751
2585
  A: [
@@ -2754,18 +2588,18 @@ var SpaceInvitationProtocol = class {
2754
2588
  ]
2755
2589
  });
2756
2590
  const { identityKey, deviceKey } = request.space;
2757
- (0, import_log7.log)("writing guest credentials", {
2591
+ (0, import_log6.log)("writing guest credentials", {
2758
2592
  host: this._signingContext.deviceKey,
2759
2593
  guest: deviceKey
2760
2594
  }, {
2761
- F: __dxlog_file9,
2595
+ F: __dxlog_file8,
2762
2596
  L: 54,
2763
2597
  S: this,
2764
2598
  C: (f, a) => f(...a)
2765
2599
  });
2766
2600
  const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2767
- (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2768
- F: __dxlog_file9,
2601
+ (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2602
+ F: __dxlog_file8,
2769
2603
  L: 65,
2770
2604
  S: this,
2771
2605
  A: [
@@ -2774,8 +2608,8 @@ var SpaceInvitationProtocol = class {
2774
2608
  ]
2775
2609
  });
2776
2610
  const spaceMemberCredential = credentials[0].credential.credential;
2777
- (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2778
- F: __dxlog_file9,
2611
+ (0, import_invariant7.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2612
+ F: __dxlog_file8,
2779
2613
  L: 67,
2780
2614
  S: this,
2781
2615
  A: [
@@ -2814,8 +2648,8 @@ var SpaceInvitationProtocol = class {
2814
2648
  };
2815
2649
  }
2816
2650
  async accept(response) {
2817
- (0, import_invariant8.invariant)(response.space, void 0, {
2818
- F: __dxlog_file9,
2651
+ (0, import_invariant7.invariant)(response.space, void 0, {
2652
+ F: __dxlog_file8,
2819
2653
  L: 107,
2820
2654
  S: this,
2821
2655
  A: [
@@ -2825,8 +2659,8 @@ var SpaceInvitationProtocol = class {
2825
2659
  });
2826
2660
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2827
2661
  const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2828
- (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2829
- F: __dxlog_file9,
2662
+ (0, import_invariant7.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2663
+ F: __dxlog_file8,
2830
2664
  L: 110,
2831
2665
  S: this,
2832
2666
  A: [
@@ -2834,8 +2668,8 @@ var SpaceInvitationProtocol = class {
2834
2668
  "'Invalid credential'"
2835
2669
  ]
2836
2670
  });
2837
- (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2838
- F: __dxlog_file9,
2671
+ (0, import_invariant7.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2672
+ F: __dxlog_file8,
2839
2673
  L: 111,
2840
2674
  S: this,
2841
2675
  A: [
@@ -2858,6 +2692,221 @@ var SpaceInvitationProtocol = class {
2858
2692
  };
2859
2693
  }
2860
2694
  };
2695
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2696
+ var InvitationsManager = class {
2697
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2698
+ this._invitationsHandler = _invitationsHandler;
2699
+ this._getHandler = _getHandler;
2700
+ this._metadataStore = _metadataStore;
2701
+ this._createInvitations = /* @__PURE__ */ new Map();
2702
+ this._acceptInvitations = /* @__PURE__ */ new Map();
2703
+ this.invitationCreated = new import_async9.Event();
2704
+ this.invitationAccepted = new import_async9.Event();
2705
+ this.removedCreated = new import_async9.Event();
2706
+ this.removedAccepted = new import_async9.Event();
2707
+ this.saved = new import_async9.Event();
2708
+ this._persistentInvitationsLoadedEvent = new import_async9.Event();
2709
+ this._persistentInvitationsLoaded = false;
2710
+ }
2711
+ createInvitation(options) {
2712
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2713
+ if (existingInvitation) {
2714
+ return existingInvitation;
2715
+ }
2716
+ const handler = this._getHandler(options);
2717
+ const invitation = this._invitationsHandler.createInvitation(handler, options);
2718
+ this._createInvitations.set(invitation.get().invitationId, invitation);
2719
+ this.invitationCreated.emit(invitation.get());
2720
+ const saveInvitationTask = invitation.get().persistent ? this._safePersistInBackground(invitation) : Promise.resolve();
2721
+ this._onInvitationComplete(invitation, async () => {
2722
+ this._createInvitations.delete(invitation.get().invitationId);
2723
+ this.removedCreated.emit(invitation.get());
2724
+ if (invitation.get().persistent) {
2725
+ await saveInvitationTask;
2726
+ await this._safeDeleteInvitation(invitation.get());
2727
+ }
2728
+ });
2729
+ return invitation;
2730
+ }
2731
+ async loadPersistentInvitations() {
2732
+ if (this._persistentInvitationsLoaded) {
2733
+ const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
2734
+ return {
2735
+ invitations
2736
+ };
2737
+ }
2738
+ try {
2739
+ const persistentInvitations = this._metadataStore.getInvitations();
2740
+ const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2741
+ const cInvitations = freshInvitations.map((persistentInvitation) => {
2742
+ (0, import_invariant8.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2743
+ F: __dxlog_file9,
2744
+ L: 82,
2745
+ S: this,
2746
+ A: [
2747
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2748
+ "'invitation already exists'"
2749
+ ]
2750
+ });
2751
+ return this.createInvitation({
2752
+ ...persistentInvitation,
2753
+ persistent: false
2754
+ }).get();
2755
+ });
2756
+ return {
2757
+ invitations: cInvitations
2758
+ };
2759
+ } catch (err) {
2760
+ import_log7.log.catch(err, void 0, {
2761
+ F: __dxlog_file9,
2762
+ L: 88,
2763
+ S: this,
2764
+ C: (f, a) => f(...a)
2765
+ });
2766
+ return {
2767
+ invitations: []
2768
+ };
2769
+ } finally {
2770
+ this._persistentInvitationsLoadedEvent.emit();
2771
+ this._persistentInvitationsLoaded = true;
2772
+ }
2773
+ }
2774
+ acceptInvitation(request) {
2775
+ const options = request.invitation;
2776
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
2777
+ if (existingInvitation) {
2778
+ return existingInvitation;
2779
+ }
2780
+ const handler = this._getHandler(options);
2781
+ const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
2782
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
2783
+ this.invitationAccepted.emit(invitation.get());
2784
+ this._onInvitationComplete(invitation, () => {
2785
+ this._acceptInvitations.delete(invitation.get().invitationId);
2786
+ this.removedAccepted.emit(invitation.get());
2787
+ });
2788
+ return invitation;
2789
+ }
2790
+ async authenticate({ invitationId, authCode }) {
2791
+ (0, import_log7.log)("authenticating...", void 0, {
2792
+ F: __dxlog_file9,
2793
+ L: 117,
2794
+ S: this,
2795
+ C: (f, a) => f(...a)
2796
+ });
2797
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2798
+ F: __dxlog_file9,
2799
+ L: 118,
2800
+ S: this,
2801
+ A: [
2802
+ "invitationId",
2803
+ ""
2804
+ ]
2805
+ });
2806
+ const observable = this._acceptInvitations.get(invitationId);
2807
+ if (!observable) {
2808
+ import_log7.log.warn("invalid invitation", {
2809
+ invitationId
2810
+ }, {
2811
+ F: __dxlog_file9,
2812
+ L: 121,
2813
+ S: this,
2814
+ C: (f, a) => f(...a)
2815
+ });
2816
+ } else {
2817
+ await observable.authenticate(authCode);
2818
+ }
2819
+ }
2820
+ async cancelInvitation({ invitationId }) {
2821
+ (0, import_log7.log)("cancelInvitation...", {
2822
+ invitationId
2823
+ }, {
2824
+ F: __dxlog_file9,
2825
+ L: 128,
2826
+ S: this,
2827
+ C: (f, a) => f(...a)
2828
+ });
2829
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2830
+ F: __dxlog_file9,
2831
+ L: 129,
2832
+ S: this,
2833
+ A: [
2834
+ "invitationId",
2835
+ ""
2836
+ ]
2837
+ });
2838
+ const created = this._createInvitations.get(invitationId);
2839
+ if (created) {
2840
+ if (created.get().persistent) {
2841
+ await this._metadataStore.removeInvitation(invitationId);
2842
+ }
2843
+ await created.cancel();
2844
+ this._createInvitations.delete(invitationId);
2845
+ this.removedCreated.emit(created.get());
2846
+ return;
2847
+ }
2848
+ const accepted = this._acceptInvitations.get(invitationId);
2849
+ if (accepted) {
2850
+ await accepted.cancel();
2851
+ this._acceptInvitations.delete(invitationId);
2852
+ this.removedAccepted.emit(accepted.get());
2853
+ }
2854
+ }
2855
+ getCreatedInvitations() {
2856
+ return [
2857
+ ...this._createInvitations.values()
2858
+ ].map((i) => i.get());
2859
+ }
2860
+ getAcceptedInvitations() {
2861
+ return [
2862
+ ...this._acceptInvitations.values()
2863
+ ].map((i) => i.get());
2864
+ }
2865
+ onPersistentInvitationsLoaded(ctx, callback) {
2866
+ if (this._persistentInvitationsLoaded) {
2867
+ callback();
2868
+ } else {
2869
+ this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2870
+ }
2871
+ }
2872
+ _safePersistInBackground(invitation) {
2873
+ return new Promise((resolve) => {
2874
+ setTimeout(async () => {
2875
+ try {
2876
+ await this._metadataStore.addInvitation(invitation.get());
2877
+ this.saved.emit(invitation.get());
2878
+ } catch (err) {
2879
+ import_log7.log.catch(err, void 0, {
2880
+ F: __dxlog_file9,
2881
+ L: 173,
2882
+ S: this,
2883
+ C: (f, a) => f(...a)
2884
+ });
2885
+ await invitation.cancel();
2886
+ } finally {
2887
+ resolve();
2888
+ }
2889
+ });
2890
+ });
2891
+ }
2892
+ async _safeDeleteInvitation(invitation) {
2893
+ try {
2894
+ await this._metadataStore.removeInvitation(invitation.invitationId);
2895
+ } catch (err) {
2896
+ import_log7.log.catch(err, void 0, {
2897
+ F: __dxlog_file9,
2898
+ L: 186,
2899
+ S: this,
2900
+ C: (f, a) => f(...a)
2901
+ });
2902
+ }
2903
+ }
2904
+ _onInvitationComplete(invitation, callback) {
2905
+ invitation.subscribe(() => {
2906
+ }, () => {
2907
+ }, callback);
2908
+ }
2909
+ };
2861
2910
  function _ts_decorate3(decorators, target, key, desc) {
2862
2911
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2863
2912
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2974,7 +3023,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2974
3023
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2975
3024
  var NotarizationPlugin = class {
2976
3025
  constructor() {
2977
- this._ctx = new import_context8.Context();
3026
+ this._ctx = new import_context7.Context();
2978
3027
  this._extensionOpened = new import_async12.Event();
2979
3028
  this._extensions = /* @__PURE__ */ new Set();
2980
3029
  this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
@@ -3099,7 +3148,7 @@ var NotarizationPlugin = class {
3099
3148
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3100
3149
  try {
3101
3150
  await Promise.race([
3102
- (0, import_context8.rejectOnDispose)(ctx),
3151
+ (0, import_context7.rejectOnDispose)(ctx),
3103
3152
  allNotarized,
3104
3153
  errors.wait()
3105
3154
  ]);
@@ -3238,7 +3287,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3238
3287
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3239
3288
  var DataSpace = class {
3240
3289
  constructor(params) {
3241
- this._ctx = new import_context7.Context();
3290
+ this._ctx = new import_context6.Context();
3242
3291
  this._notarizationPlugin = new NotarizationPlugin();
3243
3292
  this._cache = void 0;
3244
3293
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
@@ -3311,7 +3360,7 @@ var DataSpace = class {
3311
3360
  await this._notarizationPlugin.open();
3312
3361
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3313
3362
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3314
- await this._inner.open(new import_context7.Context());
3363
+ await this._inner.open(new import_context6.Context());
3315
3364
  this._state = import_services7.SpaceState.CONTROL_ONLY;
3316
3365
  (0, import_log8.log)("new state", {
3317
3366
  state: import_services7.SpaceState[this._state]
@@ -3340,7 +3389,7 @@ var DataSpace = class {
3340
3389
  C: (f, a) => f(...a)
3341
3390
  });
3342
3391
  await this._ctx.dispose();
3343
- this._ctx = new import_context7.Context();
3392
+ this._ctx = new import_context6.Context();
3344
3393
  await this.authVerifier.close();
3345
3394
  await this._inner.close();
3346
3395
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3364,7 +3413,7 @@ var DataSpace = class {
3364
3413
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3365
3414
  await this.initializeDataPipeline();
3366
3415
  } catch (err) {
3367
- if (err instanceof import_protocols7.CancelledError || err instanceof import_context7.ContextDisposedError) {
3416
+ if (err instanceof import_protocols7.CancelledError || err instanceof import_context6.ContextDisposedError) {
3368
3417
  (0, import_log8.log)("data pipeline initialization cancelled", err, {
3369
3418
  F: __dxlog_file11,
3370
3419
  L: 245,
@@ -3411,7 +3460,7 @@ var DataSpace = class {
3411
3460
  await this._initializeAndReadControlPipeline();
3412
3461
  await (0, import_async10.sleep)(1);
3413
3462
  this._automergeSpaceState.startProcessingRootDocs();
3414
- await (0, import_context7.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3463
+ await (0, import_context6.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3415
3464
  (0, import_log8.log)("data pipeline ready", void 0, {
3416
3465
  F: __dxlog_file11,
3417
3466
  L: 279,
@@ -3512,7 +3561,7 @@ var DataSpace = class {
3512
3561
  queueMicrotask(async () => {
3513
3562
  try {
3514
3563
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3515
- await (0, import_context7.cancelWithContext)(this._ctx, handle.whenReady());
3564
+ await (0, import_context6.cancelWithContext)(this._ctx, handle.whenReady());
3516
3565
  });
3517
3566
  if (this._ctx.disposed) {
3518
3567
  return;
@@ -3526,7 +3575,7 @@ var DataSpace = class {
3526
3575
  });
3527
3576
  }
3528
3577
  } catch (err) {
3529
- if (err instanceof import_context7.ContextDisposedError) {
3578
+ if (err instanceof import_context6.ContextDisposedError) {
3530
3579
  return;
3531
3580
  }
3532
3581
  import_log8.log.warn("error loading automerge root doc", {
@@ -3586,7 +3635,7 @@ var DataSpace = class {
3586
3635
  {
3587
3636
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3588
3637
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3589
- await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3638
+ await (0, import_context6.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3590
3639
  const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3591
3640
  (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3592
3641
  F: __dxlog_file11,
@@ -3615,7 +3664,7 @@ var DataSpace = class {
3615
3664
  });
3616
3665
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3617
3666
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3618
- await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3667
+ await (0, import_context6.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3619
3668
  const objects = Object.entries(rootHandle.docSync().objects);
3620
3669
  const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_db.TYPE_PROPERTIES);
3621
3670
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
@@ -3843,7 +3892,7 @@ var DataSpaceManager = class {
3843
3892
  this._signingContext = _signingContext;
3844
3893
  this._feedStore = _feedStore;
3845
3894
  this._automergeHost = _automergeHost;
3846
- this._ctx = new import_context9.Context();
3895
+ this._ctx = new import_context8.Context();
3847
3896
  this.updated = new import_async13.Event();
3848
3897
  this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3849
3898
  this._isOpen = false;
@@ -4032,7 +4081,7 @@ var DataSpaceManager = class {
4032
4081
  * TODO(dmaretskyi): Consider removing.
4033
4082
  */
4034
4083
  async waitUntilSpaceReady(spaceKey) {
4035
- await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4084
+ await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4036
4085
  const space = this._spaces.get(spaceKey);
4037
4086
  return !!space && space.state === import_services8.SpaceState.READY;
4038
4087
  }));
@@ -4455,7 +4504,7 @@ function _ts_decorate6(decorators, target, key, desc) {
4455
4504
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4456
4505
  }
4457
4506
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
4458
- var ServiceContext = class extends import_context10.Resource {
4507
+ var ServiceContext = class extends import_context9.Resource {
4459
4508
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
4460
4509
  super();
4461
4510
  this.storage = storage;
@@ -4508,13 +4557,14 @@ var ServiceContext = class extends import_context10.Resource {
4508
4557
  getAllDocuments: createDocumentsIterator(this.automergeHost)
4509
4558
  });
4510
4559
  this.invitations = new InvitationsHandler(this.networkManager);
4560
+ this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4511
4561
  this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4512
4562
  }
4513
4563
  async _open(ctx) {
4514
4564
  await this._checkStorageVersion();
4515
4565
  (0, import_log12.log)("opening...", void 0, {
4516
4566
  F: __dxlog_file14,
4517
- L: 157,
4567
+ L: 164,
4518
4568
  S: this,
4519
4569
  C: (f, a) => f(...a)
4520
4570
  });
@@ -4522,7 +4572,7 @@ var ServiceContext = class extends import_context10.Resource {
4522
4572
  id: this._instanceId
4523
4573
  }), {
4524
4574
  F: __dxlog_file14,
4525
- L: 158,
4575
+ L: 165,
4526
4576
  S: this,
4527
4577
  C: (f, a) => f(...a)
4528
4578
  });
@@ -4535,17 +4585,26 @@ var ServiceContext = class extends import_context10.Resource {
4535
4585
  if (this.identityManager.identity) {
4536
4586
  await this._initialize(ctx);
4537
4587
  }
4588
+ const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4589
+ (0, import_log12.log)("loaded persistent invitations", {
4590
+ count: loadedInvitations.invitations?.length
4591
+ }, {
4592
+ F: __dxlog_file14,
4593
+ L: 178,
4594
+ S: this,
4595
+ C: (f, a) => f(...a)
4596
+ });
4538
4597
  import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.end({
4539
4598
  id: this._instanceId
4540
4599
  }), {
4541
4600
  F: __dxlog_file14,
4542
- L: 169,
4601
+ L: 180,
4543
4602
  S: this,
4544
4603
  C: (f, a) => f(...a)
4545
4604
  });
4546
4605
  (0, import_log12.log)("opened", void 0, {
4547
4606
  F: __dxlog_file14,
4548
- L: 170,
4607
+ L: 181,
4549
4608
  S: this,
4550
4609
  C: (f, a) => f(...a)
4551
4610
  });
@@ -4553,7 +4612,7 @@ var ServiceContext = class extends import_context10.Resource {
4553
4612
  async _close() {
4554
4613
  (0, import_log12.log)("closing...", void 0, {
4555
4614
  F: __dxlog_file14,
4556
- L: 174,
4615
+ L: 185,
4557
4616
  S: this,
4558
4617
  C: (f, a) => f(...a)
4559
4618
  });
@@ -4571,21 +4630,21 @@ var ServiceContext = class extends import_context10.Resource {
4571
4630
  await this.indexer.destroy();
4572
4631
  (0, import_log12.log)("closed", void 0, {
4573
4632
  F: __dxlog_file14,
4574
- L: 187,
4633
+ L: 198,
4575
4634
  S: this,
4576
4635
  C: (f, a) => f(...a)
4577
4636
  });
4578
4637
  }
4579
4638
  async createIdentity(params = {}) {
4580
4639
  const identity = await this.identityManager.createIdentity(params);
4581
- await this._initialize(new import_context10.Context());
4640
+ await this._initialize(new import_context9.Context());
4582
4641
  return identity;
4583
4642
  }
4584
4643
  getInvitationHandler(invitation) {
4585
4644
  const factory = this._handlerFactories.get(invitation.kind);
4586
4645
  (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4587
4646
  F: __dxlog_file14,
4588
- L: 198,
4647
+ L: 209,
4589
4648
  S: this,
4590
4649
  A: [
4591
4650
  "factory",
@@ -4604,7 +4663,7 @@ var ServiceContext = class extends import_context10.Resource {
4604
4663
  }
4605
4664
  async _acceptIdentity(params) {
4606
4665
  const identity = await this.identityManager.acceptIdentity(params);
4607
- await this._initialize(new import_context10.Context());
4666
+ await this._initialize(new import_context9.Context());
4608
4667
  return identity;
4609
4668
  }
4610
4669
  async _checkStorageVersion() {
@@ -4617,7 +4676,7 @@ var ServiceContext = class extends import_context10.Resource {
4617
4676
  async _initialize(ctx) {
4618
4677
  (0, import_log12.log)("initializing spaces...", void 0, {
4619
4678
  F: __dxlog_file14,
4620
- L: 229,
4679
+ L: 240,
4621
4680
  S: this,
4622
4681
  C: (f, a) => f(...a)
4623
4682
  });
@@ -4640,7 +4699,7 @@ var ServiceContext = class extends import_context10.Resource {
4640
4699
  this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4641
4700
  (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4642
4701
  F: __dxlog_file14,
4643
- L: 253,
4702
+ L: 264,
4644
4703
  S: this,
4645
4704
  A: [
4646
4705
  "this.dataSpaceManager",
@@ -4664,7 +4723,7 @@ var ServiceContext = class extends import_context10.Resource {
4664
4723
  details: assertion
4665
4724
  }, {
4666
4725
  F: __dxlog_file14,
4667
- L: 269,
4726
+ L: 280,
4668
4727
  S: this,
4669
4728
  C: (f, a) => f(...a)
4670
4729
  });
@@ -4675,7 +4734,7 @@ var ServiceContext = class extends import_context10.Resource {
4675
4734
  details: assertion
4676
4735
  }, {
4677
4736
  F: __dxlog_file14,
4678
- L: 273,
4737
+ L: 284,
4679
4738
  S: this,
4680
4739
  C: (f, a) => f(...a)
4681
4740
  });
@@ -4686,7 +4745,7 @@ var ServiceContext = class extends import_context10.Resource {
4686
4745
  details: assertion
4687
4746
  }, {
4688
4747
  F: __dxlog_file14,
4689
- L: 278,
4748
+ L: 289,
4690
4749
  S: this,
4691
4750
  C: (f, a) => f(...a)
4692
4751
  });
@@ -4697,7 +4756,7 @@ var ServiceContext = class extends import_context10.Resource {
4697
4756
  } catch (err) {
4698
4757
  import_log12.log.catch(err, void 0, {
4699
4758
  F: __dxlog_file14,
4700
- L: 284,
4759
+ L: 295,
4701
4760
  S: this,
4702
4761
  C: (f, a) => f(...a)
4703
4762
  });
@@ -4739,7 +4798,7 @@ var ServiceRegistry = class {
4739
4798
  delete this._handlers[name];
4740
4799
  }
4741
4800
  };
4742
- var DXOS_VERSION = "0.4.10-main.c5e8686";
4801
+ var DXOS_VERSION = "0.4.10-main.c75170d";
4743
4802
  var getPlatform = () => {
4744
4803
  if (process.browser) {
4745
4804
  if (typeof window !== "undefined") {
@@ -5315,7 +5374,7 @@ var ClientServicesHost = class {
5315
5374
  lockKey,
5316
5375
  onAcquire: () => {
5317
5376
  if (!this._opening) {
5318
- void this.open(new import_context11.Context());
5377
+ void this.open(new import_context10.Context());
5319
5378
  }
5320
5379
  },
5321
5380
  onRelease: () => this.close()
@@ -5501,7 +5560,7 @@ var ClientServicesHost = class {
5501
5560
  this._serviceRegistry.setServices({
5502
5561
  SystemService: this._systemService,
5503
5562
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5504
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5563
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
5505
5564
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5506
5565
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
5507
5566
  await this._serviceContext.initialized.wait();
@@ -5523,24 +5582,6 @@ var ClientServicesHost = class {
5523
5582
  })
5524
5583
  });
5525
5584
  await this._serviceContext.open(ctx);
5526
- (0, import_invariant15.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5527
- F: __dxlog_file18,
5528
- L: 314,
5529
- S: this,
5530
- A: [
5531
- "this.serviceRegistry.services.InvitationsService",
5532
- ""
5533
- ]
5534
- });
5535
- const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5536
- (0, import_log13.log)("loaded persistent invitations", {
5537
- count: loadedInvitations.invitations?.length
5538
- }, {
5539
- F: __dxlog_file18,
5540
- L: 317,
5541
- S: this,
5542
- C: (f, a) => f(...a)
5543
- });
5544
5585
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5545
5586
  if (devtoolsProxy) {
5546
5587
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
@@ -5560,7 +5601,7 @@ var ClientServicesHost = class {
5560
5601
  deviceKey
5561
5602
  }, {
5562
5603
  F: __dxlog_file18,
5563
- L: 335,
5604
+ L: 326,
5564
5605
  S: this,
5565
5606
  C: (f, a) => f(...a)
5566
5607
  });
@@ -5568,7 +5609,7 @@ var ClientServicesHost = class {
5568
5609
  id: traceId
5569
5610
  }), {
5570
5611
  F: __dxlog_file18,
5571
- L: 336,
5612
+ L: 327,
5572
5613
  S: this,
5573
5614
  C: (f, a) => f(...a)
5574
5615
  });
@@ -5582,7 +5623,7 @@ var ClientServicesHost = class {
5582
5623
  deviceKey
5583
5624
  }, {
5584
5625
  F: __dxlog_file18,
5585
- L: 347,
5626
+ L: 338,
5586
5627
  S: this,
5587
5628
  C: (f, a) => f(...a)
5588
5629
  });
@@ -5600,7 +5641,7 @@ var ClientServicesHost = class {
5600
5641
  deviceKey
5601
5642
  }, {
5602
5643
  F: __dxlog_file18,
5603
- L: 356,
5644
+ L: 347,
5604
5645
  S: this,
5605
5646
  C: (f, a) => f(...a)
5606
5647
  });
@@ -5611,13 +5652,13 @@ var ClientServicesHost = class {
5611
5652
  id: traceId
5612
5653
  }), {
5613
5654
  F: __dxlog_file18,
5614
- L: 361,
5655
+ L: 352,
5615
5656
  S: this,
5616
5657
  C: (f, a) => f(...a)
5617
5658
  });
5618
5659
  (0, import_log13.log)("resetting...", void 0, {
5619
5660
  F: __dxlog_file18,
5620
- L: 363,
5661
+ L: 354,
5621
5662
  S: this,
5622
5663
  C: (f, a) => f(...a)
5623
5664
  });
@@ -5625,7 +5666,7 @@ var ClientServicesHost = class {
5625
5666
  await this._storage.reset();
5626
5667
  (0, import_log13.log)("reset", void 0, {
5627
5668
  F: __dxlog_file18,
5628
- L: 366,
5669
+ L: 357,
5629
5670
  S: this,
5630
5671
  C: (f, a) => f(...a)
5631
5672
  });
@@ -5633,7 +5674,7 @@ var ClientServicesHost = class {
5633
5674
  id: traceId
5634
5675
  }), {
5635
5676
  F: __dxlog_file18,
5636
- L: 367,
5677
+ L: 358,
5637
5678
  S: this,
5638
5679
  C: (f, a) => f(...a)
5639
5680
  });
@@ -5646,7 +5687,7 @@ var ClientServicesHost = class {
5646
5687
  const automergeIndex = space.automergeSpaceState.rootUrl;
5647
5688
  (0, import_invariant15.invariant)(automergeIndex, void 0, {
5648
5689
  F: __dxlog_file18,
5649
- L: 379,
5690
+ L: 370,
5650
5691
  S: this,
5651
5692
  A: [
5652
5693
  "automergeIndex",
@@ -5741,6 +5782,7 @@ var findConfigs = () => {
5741
5782
  IdentityManager,
5742
5783
  IdentityServiceImpl,
5743
5784
  InvitationsHandler,
5785
+ InvitationsManager,
5744
5786
  InvitationsServiceImpl,
5745
5787
  Lock,
5746
5788
  ServiceContext,
@@ -5765,4 +5807,4 @@ var findConfigs = () => {
5765
5807
  subscribeToSpaces,
5766
5808
  subscribeToSwarmInfo
5767
5809
  });
5768
- //# sourceMappingURL=chunk-VRSCM2WE.cjs.map
5810
+ //# sourceMappingURL=chunk-34EZSH65.cjs.map