@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
@@ -1853,7 +1853,7 @@ var InvitationsHandler = class {
1853
1853
  });
1854
1854
  return extension;
1855
1855
  };
1856
- if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
1856
+ if (invitation.lifetime && invitation.created) {
1857
1857
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1858
1858
  log5.warn("invitation has already expired", void 0, {
1859
1859
  F: __dxlog_file7,
@@ -1918,7 +1918,7 @@ var InvitationsHandler = class {
1918
1918
  if (deviceProfile) {
1919
1919
  invariant6(invitation.kind === Invitation3.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
1920
1920
  F: __dxlog_file7,
1921
- L: 256,
1921
+ L: 255,
1922
1922
  S: this,
1923
1923
  A: [
1924
1924
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -1933,7 +1933,7 @@ var InvitationsHandler = class {
1933
1933
  const setState = (newData) => {
1934
1934
  invariant6(newData.state !== void 0, void 0, {
1935
1935
  F: __dxlog_file7,
1936
- L: 267,
1936
+ L: 266,
1937
1937
  S: this,
1938
1938
  A: [
1939
1939
  "newData.state !== undefined",
@@ -1953,7 +1953,7 @@ var InvitationsHandler = class {
1953
1953
  ...protocol.toJSON()
1954
1954
  }, {
1955
1955
  F: __dxlog_file7,
1956
- L: 275,
1956
+ L: 274,
1957
1957
  S: this,
1958
1958
  C: (f, a) => f(...a)
1959
1959
  });
@@ -1963,7 +1963,7 @@ var InvitationsHandler = class {
1963
1963
  } else {
1964
1964
  log5.warn("auth failed", err, {
1965
1965
  F: __dxlog_file7,
1966
- L: 278,
1966
+ L: 277,
1967
1967
  S: this,
1968
1968
  C: (f, a) => f(...a)
1969
1969
  });
@@ -1977,7 +1977,7 @@ var InvitationsHandler = class {
1977
1977
  ...protocol.toJSON()
1978
1978
  }, {
1979
1979
  F: __dxlog_file7,
1980
- L: 286,
1980
+ L: 285,
1981
1981
  S: this,
1982
1982
  C: (f, a) => f(...a)
1983
1983
  });
@@ -1992,7 +1992,7 @@ var InvitationsHandler = class {
1992
1992
  currentState
1993
1993
  }, {
1994
1994
  F: __dxlog_file7,
1995
- L: 296,
1995
+ L: 295,
1996
1996
  S: this,
1997
1997
  C: (f, a) => f(...a)
1998
1998
  });
@@ -2007,7 +2007,7 @@ var InvitationsHandler = class {
2007
2007
  id: traceId
2008
2008
  }), {
2009
2009
  F: __dxlog_file7,
2010
- L: 305,
2010
+ L: 304,
2011
2011
  S: this,
2012
2012
  C: (f, a) => f(...a)
2013
2013
  });
@@ -2019,7 +2019,7 @@ var InvitationsHandler = class {
2019
2019
  ...protocol.toJSON()
2020
2020
  }, {
2021
2021
  F: __dxlog_file7,
2022
- L: 313,
2022
+ L: 312,
2023
2023
  S: this,
2024
2024
  C: (f, a) => f(...a)
2025
2025
  });
@@ -2030,7 +2030,7 @@ var InvitationsHandler = class {
2030
2030
  ...protocol.toJSON()
2031
2031
  }, {
2032
2032
  F: __dxlog_file7,
2033
- L: 317,
2033
+ L: 316,
2034
2034
  S: this,
2035
2035
  C: (f, a) => f(...a)
2036
2036
  });
@@ -2040,7 +2040,7 @@ var InvitationsHandler = class {
2040
2040
  response: introductionResponse
2041
2041
  }, {
2042
2042
  F: __dxlog_file7,
2043
- L: 321,
2043
+ L: 320,
2044
2044
  S: this,
2045
2045
  C: (f, a) => f(...a)
2046
2046
  });
@@ -2061,7 +2061,7 @@ var InvitationsHandler = class {
2061
2061
  ...protocol.toJSON()
2062
2062
  }, {
2063
2063
  F: __dxlog_file7,
2064
- L: 337,
2064
+ L: 336,
2065
2065
  S: this,
2066
2066
  C: (f, a) => f(...a)
2067
2067
  });
@@ -2073,7 +2073,7 @@ var InvitationsHandler = class {
2073
2073
  ...protocol.toJSON()
2074
2074
  }, {
2075
2075
  F: __dxlog_file7,
2076
- L: 348,
2076
+ L: 347,
2077
2077
  S: this,
2078
2078
  C: (f, a) => f(...a)
2079
2079
  });
@@ -2086,7 +2086,7 @@ var InvitationsHandler = class {
2086
2086
  id: traceId
2087
2087
  }), {
2088
2088
  F: __dxlog_file7,
2089
- L: 350,
2089
+ L: 349,
2090
2090
  S: this,
2091
2091
  C: (f, a) => f(...a)
2092
2092
  });
@@ -2096,7 +2096,7 @@ var InvitationsHandler = class {
2096
2096
  ...protocol.toJSON()
2097
2097
  }, {
2098
2098
  F: __dxlog_file7,
2099
- L: 353,
2099
+ L: 352,
2100
2100
  S: this,
2101
2101
  C: (f, a) => f(...a)
2102
2102
  });
@@ -2106,7 +2106,7 @@ var InvitationsHandler = class {
2106
2106
  } else {
2107
2107
  log5("auth failed", err, {
2108
2108
  F: __dxlog_file7,
2109
- L: 356,
2109
+ L: 355,
2110
2110
  S: this,
2111
2111
  C: (f, a) => f(...a)
2112
2112
  });
@@ -2117,7 +2117,7 @@ var InvitationsHandler = class {
2117
2117
  error: err
2118
2118
  }), {
2119
2119
  F: __dxlog_file7,
2120
- L: 359,
2120
+ L: 358,
2121
2121
  S: this,
2122
2122
  C: (f, a) => f(...a)
2123
2123
  });
@@ -2135,7 +2135,7 @@ var InvitationsHandler = class {
2135
2135
  ...protocol.toJSON()
2136
2136
  }, {
2137
2137
  F: __dxlog_file7,
2138
- L: 370,
2138
+ L: 369,
2139
2139
  S: this,
2140
2140
  C: (f, a) => f(...a)
2141
2141
  });
@@ -2145,7 +2145,7 @@ var InvitationsHandler = class {
2145
2145
  } else {
2146
2146
  log5("auth failed", err, {
2147
2147
  F: __dxlog_file7,
2148
- L: 373,
2148
+ L: 372,
2149
2149
  S: this,
2150
2150
  C: (f, a) => f(...a)
2151
2151
  });
@@ -2162,7 +2162,7 @@ var InvitationsHandler = class {
2162
2162
  } else {
2163
2163
  invariant6(invitation.swarmKey, void 0, {
2164
2164
  F: __dxlog_file7,
2165
- L: 387,
2165
+ L: 386,
2166
2166
  S: this,
2167
2167
  A: [
2168
2168
  "invitation.swarmKey",
@@ -2204,7 +2204,7 @@ var InvitationsHandler = class {
2204
2204
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2205
2205
  log5("guest waiting for authentication code...", void 0, {
2206
2206
  F: __dxlog_file7,
2207
- L: 427,
2207
+ L: 426,
2208
2208
  S: this,
2209
2209
  C: (f, a) => f(...a)
2210
2210
  });
@@ -2214,7 +2214,7 @@ var InvitationsHandler = class {
2214
2214
  const authCode = await authenticated.wait(options);
2215
2215
  log5("sending authentication request", void 0, {
2216
2216
  F: __dxlog_file7,
2217
- L: 431,
2217
+ L: 430,
2218
2218
  S: this,
2219
2219
  C: (f, a) => f(...a)
2220
2220
  });
@@ -2235,7 +2235,7 @@ var InvitationsHandler = class {
2235
2235
  attempt
2236
2236
  }, {
2237
2237
  F: __dxlog_file7,
2238
- L: 442,
2238
+ L: 441,
2239
2239
  S: this,
2240
2240
  C: (f, a) => f(...a)
2241
2241
  });
@@ -2253,7 +2253,7 @@ var InvitationsHandler = class {
2253
2253
  }
2254
2254
  log5("sending authentication request", void 0, {
2255
2255
  F: __dxlog_file7,
2256
- L: 461,
2256
+ L: 460,
2257
2257
  S: this,
2258
2258
  C: (f, a) => f(...a)
2259
2259
  });
@@ -2278,201 +2278,37 @@ var createAdmissionKeypair = () => {
2278
2278
  };
2279
2279
 
2280
2280
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
2281
- import { Event as Event3, scheduleTask as scheduleTask3 } from "@dxos/async";
2282
2281
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
2283
- import { Context as Context6 } from "@dxos/context";
2284
- import { hasInvitationExpired } from "@dxos/echo-pipeline";
2285
- import { invariant as invariant7 } from "@dxos/invariant";
2286
- import { log as log6 } from "@dxos/log";
2287
- import { Invitation as Invitation4, QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
2288
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2282
+ import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
2289
2283
  var InvitationsServiceImpl = class {
2290
- constructor(_invitationsHandler, _getHandler, _metadataStore) {
2291
- this._invitationsHandler = _invitationsHandler;
2292
- this._getHandler = _getHandler;
2293
- this._metadataStore = _metadataStore;
2294
- this._createInvitations = /* @__PURE__ */ new Map();
2295
- this._acceptInvitations = /* @__PURE__ */ new Map();
2296
- this._invitationCreated = new Event3();
2297
- this._invitationAccepted = new Event3();
2298
- this._removedCreated = new Event3();
2299
- this._removedAccepted = new Event3();
2300
- this._saved = new Event3();
2301
- this._persistentInvitationsLoadedEvent = new Event3();
2302
- this._persistentInvitationsLoaded = false;
2284
+ constructor(_invitationsManager) {
2285
+ this._invitationsManager = _invitationsManager;
2303
2286
  }
2304
2287
  // TODO(burdon): Guest/host label.
2305
2288
  getLoggingContext() {
2306
2289
  return {};
2307
2290
  }
2308
2291
  createInvitation(options) {
2309
- let invitation;
2310
- const savePersistentInvitationCtx = new Context6();
2311
- const existingInvitation = this._createInvitations.get(options.invitationId);
2312
- if (existingInvitation) {
2313
- invitation = existingInvitation;
2314
- } else {
2315
- const handler = this._getHandler(options);
2316
- invitation = this._invitationsHandler.createInvitation(handler, options);
2317
- this._createInvitations.set(invitation.get().invitationId, invitation);
2318
- this._invitationCreated.emit(invitation.get());
2319
- }
2292
+ const invitation = this._invitationsManager.createInvitation(options);
2320
2293
  return new Stream8(({ next, close }) => {
2321
- if (invitation.get().persistent) {
2322
- scheduleTask3(savePersistentInvitationCtx, async () => {
2323
- try {
2324
- await this._metadataStore.addInvitation(invitation.get());
2325
- this._saved.emit(invitation.get());
2326
- } catch (err) {
2327
- close(err);
2328
- }
2329
- });
2330
- }
2331
- invitation.subscribe((invitation2) => {
2332
- next(invitation2);
2333
- }, async (err) => {
2334
- await savePersistentInvitationCtx.dispose();
2335
- close(err);
2336
- }, async () => {
2337
- close();
2338
- if (invitation.get().persistent) {
2339
- await savePersistentInvitationCtx.dispose();
2340
- await this._metadataStore.removeInvitation(invitation.get().invitationId);
2341
- }
2342
- this._createInvitations.delete(invitation.get().invitationId);
2343
- if (!invitation.get().multiUse) {
2344
- this._removedCreated.emit(invitation.get());
2345
- }
2346
- });
2294
+ invitation.subscribe(next, close, close);
2347
2295
  });
2348
2296
  }
2349
- async loadPersistentInvitations() {
2350
- const persistentInvitations = this._metadataStore.getInvitations();
2351
- const freshInvitations = persistentInvitations.filter(async (invitation) => !hasInvitationExpired(invitation));
2352
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2353
- invariant7(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2354
- F: __dxlog_file8,
2355
- L: 109,
2356
- S: this,
2357
- A: [
2358
- "!this._createInvitations.get(persistentInvitation.invitationId)",
2359
- "'invitation already exists'"
2360
- ]
2361
- });
2362
- const handler = this._getHandler(persistentInvitation);
2363
- const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2364
- this._createInvitations.set(invitation.get().invitationId, invitation);
2365
- this._invitationCreated.emit(invitation.get());
2366
- return persistentInvitation;
2367
- });
2368
- this._persistentInvitationsLoadedEvent.emit();
2369
- this._persistentInvitationsLoaded = true;
2370
- return {
2371
- invitations: cInvitations
2372
- };
2373
- }
2374
- acceptInvitation({ invitation: options, deviceProfile }) {
2375
- let invitation;
2376
- if (deviceProfile) {
2377
- invariant7(options.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2378
- F: __dxlog_file8,
2379
- L: 127,
2380
- S: this,
2381
- A: [
2382
- "options.kind === Invitation.Kind.DEVICE",
2383
- "'deviceProfile provided for non-device invitation'"
2384
- ]
2385
- });
2386
- }
2387
- const existingInvitation = this._acceptInvitations.get(options.invitationId);
2388
- if (existingInvitation) {
2389
- invitation = existingInvitation;
2390
- } else {
2391
- const handler = this._getHandler(options);
2392
- invitation = this._invitationsHandler.acceptInvitation(handler, options, deviceProfile);
2393
- this._acceptInvitations.set(invitation.get().invitationId, invitation);
2394
- this._invitationAccepted.emit(invitation.get());
2395
- }
2297
+ acceptInvitation(request) {
2298
+ const invitation = this._invitationsManager.acceptInvitation(request);
2396
2299
  return new Stream8(({ next, close }) => {
2397
- invitation.subscribe((invitation2) => {
2398
- next(invitation2);
2399
- }, (err) => {
2400
- close(err);
2401
- }, () => {
2402
- close();
2403
- this._acceptInvitations.delete(invitation.get().invitationId);
2404
- if (!invitation.get().multiUse) {
2405
- this._removedAccepted.emit(invitation.get());
2406
- }
2407
- });
2300
+ invitation.subscribe(next, close, close);
2408
2301
  });
2409
2302
  }
2410
- async authenticate({ invitationId, authCode }) {
2411
- log6("authenticating...", void 0, {
2412
- F: __dxlog_file8,
2413
- L: 160,
2414
- S: this,
2415
- C: (f, a) => f(...a)
2416
- });
2417
- invariant7(invitationId, void 0, {
2418
- F: __dxlog_file8,
2419
- L: 161,
2420
- S: this,
2421
- A: [
2422
- "invitationId",
2423
- ""
2424
- ]
2425
- });
2426
- const observable = this._acceptInvitations.get(invitationId);
2427
- if (!observable) {
2428
- log6.warn("invalid invitation", {
2429
- invitationId
2430
- }, {
2431
- F: __dxlog_file8,
2432
- L: 164,
2433
- S: this,
2434
- C: (f, a) => f(...a)
2435
- });
2436
- } else {
2437
- await observable.authenticate(authCode);
2438
- }
2303
+ async authenticate(request) {
2304
+ return this._invitationsManager.authenticate(request);
2439
2305
  }
2440
- async cancelInvitation({ invitationId }) {
2441
- log6("cancelInvitation...", {
2442
- invitationId
2443
- }, {
2444
- F: __dxlog_file8,
2445
- L: 171,
2446
- S: this,
2447
- C: (f, a) => f(...a)
2448
- });
2449
- invariant7(invitationId, void 0, {
2450
- F: __dxlog_file8,
2451
- L: 172,
2452
- S: this,
2453
- A: [
2454
- "invitationId",
2455
- ""
2456
- ]
2457
- });
2458
- const created = this._createInvitations.get(invitationId);
2459
- const accepted = this._acceptInvitations.get(invitationId);
2460
- if (created) {
2461
- await created.cancel();
2462
- this._createInvitations.delete(invitationId);
2463
- this._removedCreated.emit(created.get());
2464
- if (created.get().persistent) {
2465
- await this._metadataStore.removeInvitation(created.get().invitationId);
2466
- }
2467
- } else if (accepted) {
2468
- await accepted.cancel();
2469
- this._acceptInvitations.delete(invitationId);
2470
- this._removedAccepted.emit(accepted.get());
2471
- }
2306
+ async cancelInvitation(request) {
2307
+ return this._invitationsManager.cancelInvitation(request);
2472
2308
  }
2473
2309
  queryInvitations() {
2474
2310
  return new Stream8(({ next, ctx }) => {
2475
- this._invitationCreated.on(ctx, (invitation) => {
2311
+ this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
2476
2312
  next({
2477
2313
  action: QueryInvitationsResponse.Action.ADDED,
2478
2314
  type: QueryInvitationsResponse.Type.CREATED,
@@ -2481,7 +2317,7 @@ var InvitationsServiceImpl = class {
2481
2317
  ]
2482
2318
  });
2483
2319
  });
2484
- this._invitationAccepted.on(ctx, (invitation) => {
2320
+ this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
2485
2321
  next({
2486
2322
  action: QueryInvitationsResponse.Action.ADDED,
2487
2323
  type: QueryInvitationsResponse.Type.ACCEPTED,
@@ -2490,7 +2326,7 @@ var InvitationsServiceImpl = class {
2490
2326
  ]
2491
2327
  });
2492
2328
  });
2493
- this._removedCreated.on(ctx, (invitation) => {
2329
+ this._invitationsManager.removedCreated.on(ctx, (invitation) => {
2494
2330
  next({
2495
2331
  action: QueryInvitationsResponse.Action.REMOVED,
2496
2332
  type: QueryInvitationsResponse.Type.CREATED,
@@ -2499,7 +2335,7 @@ var InvitationsServiceImpl = class {
2499
2335
  ]
2500
2336
  });
2501
2337
  });
2502
- this._removedAccepted.on(ctx, (invitation) => {
2338
+ this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
2503
2339
  next({
2504
2340
  action: QueryInvitationsResponse.Action.REMOVED,
2505
2341
  type: QueryInvitationsResponse.Type.ACCEPTED,
@@ -2508,7 +2344,7 @@ var InvitationsServiceImpl = class {
2508
2344
  ]
2509
2345
  });
2510
2346
  });
2511
- this._saved.on(ctx, (invitation) => {
2347
+ this._invitationsManager.saved.on(ctx, (invitation) => {
2512
2348
  next({
2513
2349
  action: QueryInvitationsResponse.Action.SAVED,
2514
2350
  type: QueryInvitationsResponse.Type.CREATED,
@@ -2520,28 +2356,21 @@ var InvitationsServiceImpl = class {
2520
2356
  next({
2521
2357
  action: QueryInvitationsResponse.Action.ADDED,
2522
2358
  type: QueryInvitationsResponse.Type.CREATED,
2523
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2359
+ invitations: this._invitationsManager.getCreatedInvitations(),
2524
2360
  existing: true
2525
2361
  });
2526
2362
  next({
2527
2363
  action: QueryInvitationsResponse.Action.ADDED,
2528
2364
  type: QueryInvitationsResponse.Type.ACCEPTED,
2529
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2365
+ invitations: this._invitationsManager.getAcceptedInvitations(),
2530
2366
  existing: true
2531
2367
  });
2532
- if (this._persistentInvitationsLoaded) {
2368
+ this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
2533
2369
  next({
2534
2370
  action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
2535
2371
  type: QueryInvitationsResponse.Type.CREATED
2536
2372
  });
2537
- } else {
2538
- this._persistentInvitationsLoadedEvent.on(ctx, () => {
2539
- next({
2540
- action: QueryInvitationsResponse.Action.LOAD_COMPLETE,
2541
- type: QueryInvitationsResponse.Type.CREATED
2542
- });
2543
- });
2544
- }
2373
+ });
2545
2374
  });
2546
2375
  }
2547
2376
  };
@@ -2549,11 +2378,11 @@ var InvitationsServiceImpl = class {
2549
2378
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
2550
2379
  import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
2551
2380
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2552
- import { invariant as invariant8 } from "@dxos/invariant";
2553
- import { log as log7 } from "@dxos/log";
2381
+ import { invariant as invariant7 } from "@dxos/invariant";
2382
+ import { log as log6 } from "@dxos/log";
2554
2383
  import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
2555
- import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
2556
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2384
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
2385
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2557
2386
  var SpaceInvitationProtocol = class {
2558
2387
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2559
2388
  this._spaceManager = _spaceManager;
@@ -2569,13 +2398,13 @@ var SpaceInvitationProtocol = class {
2569
2398
  }
2570
2399
  getInvitationContext() {
2571
2400
  return {
2572
- kind: Invitation5.Kind.SPACE,
2401
+ kind: Invitation4.Kind.SPACE,
2573
2402
  spaceKey: this._spaceKey
2574
2403
  };
2575
2404
  }
2576
2405
  async admit(request, guestProfile) {
2577
- invariant8(this._spaceKey, void 0, {
2578
- F: __dxlog_file9,
2406
+ invariant7(this._spaceKey, void 0, {
2407
+ F: __dxlog_file8,
2579
2408
  L: 47,
2580
2409
  S: this,
2581
2410
  A: [
@@ -2584,8 +2413,8 @@ var SpaceInvitationProtocol = class {
2584
2413
  ]
2585
2414
  });
2586
2415
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2587
- invariant8(space, void 0, {
2588
- F: __dxlog_file9,
2416
+ invariant7(space, void 0, {
2417
+ F: __dxlog_file8,
2589
2418
  L: 49,
2590
2419
  S: this,
2591
2420
  A: [
@@ -2593,8 +2422,8 @@ var SpaceInvitationProtocol = class {
2593
2422
  ""
2594
2423
  ]
2595
2424
  });
2596
- invariant8(request.space, void 0, {
2597
- F: __dxlog_file9,
2425
+ invariant7(request.space, void 0, {
2426
+ F: __dxlog_file8,
2598
2427
  L: 51,
2599
2428
  S: this,
2600
2429
  A: [
@@ -2603,18 +2432,18 @@ var SpaceInvitationProtocol = class {
2603
2432
  ]
2604
2433
  });
2605
2434
  const { identityKey, deviceKey } = request.space;
2606
- log7("writing guest credentials", {
2435
+ log6("writing guest credentials", {
2607
2436
  host: this._signingContext.deviceKey,
2608
2437
  guest: deviceKey
2609
2438
  }, {
2610
- F: __dxlog_file9,
2439
+ F: __dxlog_file8,
2611
2440
  L: 54,
2612
2441
  S: this,
2613
2442
  C: (f, a) => f(...a)
2614
2443
  });
2615
2444
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2616
- invariant8(credentials[0].credential, void 0, {
2617
- F: __dxlog_file9,
2445
+ invariant7(credentials[0].credential, void 0, {
2446
+ F: __dxlog_file8,
2618
2447
  L: 65,
2619
2448
  S: this,
2620
2449
  A: [
@@ -2623,8 +2452,8 @@ var SpaceInvitationProtocol = class {
2623
2452
  ]
2624
2453
  });
2625
2454
  const spaceMemberCredential = credentials[0].credential.credential;
2626
- invariant8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2627
- F: __dxlog_file9,
2455
+ invariant7(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2456
+ F: __dxlog_file8,
2628
2457
  L: 67,
2629
2458
  S: this,
2630
2459
  A: [
@@ -2663,8 +2492,8 @@ var SpaceInvitationProtocol = class {
2663
2492
  };
2664
2493
  }
2665
2494
  async accept(response) {
2666
- invariant8(response.space, void 0, {
2667
- F: __dxlog_file9,
2495
+ invariant7(response.space, void 0, {
2496
+ F: __dxlog_file8,
2668
2497
  L: 107,
2669
2498
  S: this,
2670
2499
  A: [
@@ -2674,8 +2503,8 @@ var SpaceInvitationProtocol = class {
2674
2503
  });
2675
2504
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2676
2505
  const assertion = getCredentialAssertion(credential);
2677
- invariant8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2678
- F: __dxlog_file9,
2506
+ invariant7(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2507
+ F: __dxlog_file8,
2679
2508
  L: 110,
2680
2509
  S: this,
2681
2510
  A: [
@@ -2683,8 +2512,8 @@ var SpaceInvitationProtocol = class {
2683
2512
  "'Invalid credential'"
2684
2513
  ]
2685
2514
  });
2686
- invariant8(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2687
- F: __dxlog_file9,
2515
+ invariant7(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2516
+ F: __dxlog_file8,
2688
2517
  L: 111,
2689
2518
  S: this,
2690
2519
  A: [
@@ -2708,6 +2537,227 @@ var SpaceInvitationProtocol = class {
2708
2537
  }
2709
2538
  };
2710
2539
 
2540
+ // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
2541
+ import { Event as Event3 } from "@dxos/async";
2542
+ import { hasInvitationExpired } from "@dxos/echo-pipeline";
2543
+ import { invariant as invariant8 } from "@dxos/invariant";
2544
+ import { log as log7 } from "@dxos/log";
2545
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2546
+ var InvitationsManager = class {
2547
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2548
+ this._invitationsHandler = _invitationsHandler;
2549
+ this._getHandler = _getHandler;
2550
+ this._metadataStore = _metadataStore;
2551
+ this._createInvitations = /* @__PURE__ */ new Map();
2552
+ this._acceptInvitations = /* @__PURE__ */ new Map();
2553
+ this.invitationCreated = new Event3();
2554
+ this.invitationAccepted = new Event3();
2555
+ this.removedCreated = new Event3();
2556
+ this.removedAccepted = new Event3();
2557
+ this.saved = new Event3();
2558
+ this._persistentInvitationsLoadedEvent = new Event3();
2559
+ this._persistentInvitationsLoaded = false;
2560
+ }
2561
+ createInvitation(options) {
2562
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2563
+ if (existingInvitation) {
2564
+ return existingInvitation;
2565
+ }
2566
+ const handler = this._getHandler(options);
2567
+ const invitation = this._invitationsHandler.createInvitation(handler, options);
2568
+ this._createInvitations.set(invitation.get().invitationId, invitation);
2569
+ this.invitationCreated.emit(invitation.get());
2570
+ const saveInvitationTask = invitation.get().persistent ? this._safePersistInBackground(invitation) : Promise.resolve();
2571
+ this._onInvitationComplete(invitation, async () => {
2572
+ this._createInvitations.delete(invitation.get().invitationId);
2573
+ this.removedCreated.emit(invitation.get());
2574
+ if (invitation.get().persistent) {
2575
+ await saveInvitationTask;
2576
+ await this._safeDeleteInvitation(invitation.get());
2577
+ }
2578
+ });
2579
+ return invitation;
2580
+ }
2581
+ async loadPersistentInvitations() {
2582
+ if (this._persistentInvitationsLoaded) {
2583
+ const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
2584
+ return {
2585
+ invitations
2586
+ };
2587
+ }
2588
+ try {
2589
+ const persistentInvitations = this._metadataStore.getInvitations();
2590
+ const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
2591
+ const cInvitations = freshInvitations.map((persistentInvitation) => {
2592
+ invariant8(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2593
+ F: __dxlog_file9,
2594
+ L: 82,
2595
+ S: this,
2596
+ A: [
2597
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2598
+ "'invitation already exists'"
2599
+ ]
2600
+ });
2601
+ return this.createInvitation({
2602
+ ...persistentInvitation,
2603
+ persistent: false
2604
+ }).get();
2605
+ });
2606
+ return {
2607
+ invitations: cInvitations
2608
+ };
2609
+ } catch (err) {
2610
+ log7.catch(err, void 0, {
2611
+ F: __dxlog_file9,
2612
+ L: 88,
2613
+ S: this,
2614
+ C: (f, a) => f(...a)
2615
+ });
2616
+ return {
2617
+ invitations: []
2618
+ };
2619
+ } finally {
2620
+ this._persistentInvitationsLoadedEvent.emit();
2621
+ this._persistentInvitationsLoaded = true;
2622
+ }
2623
+ }
2624
+ acceptInvitation(request) {
2625
+ const options = request.invitation;
2626
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
2627
+ if (existingInvitation) {
2628
+ return existingInvitation;
2629
+ }
2630
+ const handler = this._getHandler(options);
2631
+ const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
2632
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
2633
+ this.invitationAccepted.emit(invitation.get());
2634
+ this._onInvitationComplete(invitation, () => {
2635
+ this._acceptInvitations.delete(invitation.get().invitationId);
2636
+ this.removedAccepted.emit(invitation.get());
2637
+ });
2638
+ return invitation;
2639
+ }
2640
+ async authenticate({ invitationId, authCode }) {
2641
+ log7("authenticating...", void 0, {
2642
+ F: __dxlog_file9,
2643
+ L: 117,
2644
+ S: this,
2645
+ C: (f, a) => f(...a)
2646
+ });
2647
+ invariant8(invitationId, void 0, {
2648
+ F: __dxlog_file9,
2649
+ L: 118,
2650
+ S: this,
2651
+ A: [
2652
+ "invitationId",
2653
+ ""
2654
+ ]
2655
+ });
2656
+ const observable = this._acceptInvitations.get(invitationId);
2657
+ if (!observable) {
2658
+ log7.warn("invalid invitation", {
2659
+ invitationId
2660
+ }, {
2661
+ F: __dxlog_file9,
2662
+ L: 121,
2663
+ S: this,
2664
+ C: (f, a) => f(...a)
2665
+ });
2666
+ } else {
2667
+ await observable.authenticate(authCode);
2668
+ }
2669
+ }
2670
+ async cancelInvitation({ invitationId }) {
2671
+ log7("cancelInvitation...", {
2672
+ invitationId
2673
+ }, {
2674
+ F: __dxlog_file9,
2675
+ L: 128,
2676
+ S: this,
2677
+ C: (f, a) => f(...a)
2678
+ });
2679
+ invariant8(invitationId, void 0, {
2680
+ F: __dxlog_file9,
2681
+ L: 129,
2682
+ S: this,
2683
+ A: [
2684
+ "invitationId",
2685
+ ""
2686
+ ]
2687
+ });
2688
+ const created = this._createInvitations.get(invitationId);
2689
+ if (created) {
2690
+ if (created.get().persistent) {
2691
+ await this._metadataStore.removeInvitation(invitationId);
2692
+ }
2693
+ await created.cancel();
2694
+ this._createInvitations.delete(invitationId);
2695
+ this.removedCreated.emit(created.get());
2696
+ return;
2697
+ }
2698
+ const accepted = this._acceptInvitations.get(invitationId);
2699
+ if (accepted) {
2700
+ await accepted.cancel();
2701
+ this._acceptInvitations.delete(invitationId);
2702
+ this.removedAccepted.emit(accepted.get());
2703
+ }
2704
+ }
2705
+ getCreatedInvitations() {
2706
+ return [
2707
+ ...this._createInvitations.values()
2708
+ ].map((i) => i.get());
2709
+ }
2710
+ getAcceptedInvitations() {
2711
+ return [
2712
+ ...this._acceptInvitations.values()
2713
+ ].map((i) => i.get());
2714
+ }
2715
+ onPersistentInvitationsLoaded(ctx, callback) {
2716
+ if (this._persistentInvitationsLoaded) {
2717
+ callback();
2718
+ } else {
2719
+ this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2720
+ }
2721
+ }
2722
+ _safePersistInBackground(invitation) {
2723
+ return new Promise((resolve) => {
2724
+ setTimeout(async () => {
2725
+ try {
2726
+ await this._metadataStore.addInvitation(invitation.get());
2727
+ this.saved.emit(invitation.get());
2728
+ } catch (err) {
2729
+ log7.catch(err, void 0, {
2730
+ F: __dxlog_file9,
2731
+ L: 173,
2732
+ S: this,
2733
+ C: (f, a) => f(...a)
2734
+ });
2735
+ await invitation.cancel();
2736
+ } finally {
2737
+ resolve();
2738
+ }
2739
+ });
2740
+ });
2741
+ }
2742
+ async _safeDeleteInvitation(invitation) {
2743
+ try {
2744
+ await this._metadataStore.removeInvitation(invitation.invitationId);
2745
+ } catch (err) {
2746
+ log7.catch(err, void 0, {
2747
+ F: __dxlog_file9,
2748
+ L: 186,
2749
+ S: this,
2750
+ C: (f, a) => f(...a)
2751
+ });
2752
+ }
2753
+ }
2754
+ _onInvitationComplete(invitation, callback) {
2755
+ invitation.subscribe(() => {
2756
+ }, () => {
2757
+ }, callback);
2758
+ }
2759
+ };
2760
+
2711
2761
  // packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
2712
2762
  import { Stream as Stream9 } from "@dxos/codec-protobuf";
2713
2763
  import { raise } from "@dxos/debug";
@@ -2790,9 +2840,9 @@ ClientRpcServer = _ts_decorate3([
2790
2840
  ], ClientRpcServer);
2791
2841
 
2792
2842
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2793
- import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2843
+ import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask4, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
2794
2844
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
2795
- import { cancelWithContext as cancelWithContext2, Context as Context8, ContextDisposedError } from "@dxos/context";
2845
+ import { cancelWithContext as cancelWithContext2, Context as Context7, ContextDisposedError } from "@dxos/context";
2796
2846
  import { timed, warnAfterTimeout } from "@dxos/debug";
2797
2847
  import { TYPE_PROPERTIES } from "@dxos/echo-db";
2798
2848
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
@@ -2846,8 +2896,8 @@ var AutomergeSpaceState = class {
2846
2896
  };
2847
2897
 
2848
2898
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2849
- import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2850
- import { Context as Context7, rejectOnDispose } from "@dxos/context";
2899
+ import { DeferredTask, Event as Event5, scheduleTask as scheduleTask3, sleep, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
2900
+ import { Context as Context6, rejectOnDispose } from "@dxos/context";
2851
2901
  import { invariant as invariant9 } from "@dxos/invariant";
2852
2902
  import { PublicKey as PublicKey7 } from "@dxos/keys";
2853
2903
  import { log as log8 } from "@dxos/log";
@@ -2861,7 +2911,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2861
2911
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2862
2912
  var NotarizationPlugin = class {
2863
2913
  constructor() {
2864
- this._ctx = new Context7();
2914
+ this._ctx = new Context6();
2865
2915
  this._extensionOpened = new Event5();
2866
2916
  this._extensions = /* @__PURE__ */ new Set();
2867
2917
  this._processedCredentials = new ComplexSet2(PublicKey7.hash);
@@ -2913,7 +2963,7 @@ var NotarizationPlugin = class {
2913
2963
  });
2914
2964
  opCtx?.onDispose(() => ctx.dispose());
2915
2965
  if (timeout !== 0) {
2916
- scheduleTask4(ctx, () => {
2966
+ scheduleTask3(ctx, () => {
2917
2967
  log8.warn("Notarization timeout", {
2918
2968
  timeout,
2919
2969
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
@@ -2947,7 +2997,7 @@ var NotarizationPlugin = class {
2947
2997
  C: (f, a) => f(...a)
2948
2998
  });
2949
2999
  peersTried.clear();
2950
- scheduleTask4(ctx, () => notarizeTask.schedule(), retryTimeout);
3000
+ scheduleTask3(ctx, () => notarizeTask.schedule(), retryTimeout);
2951
3001
  return;
2952
3002
  }
2953
3003
  peersTried.add(peer);
@@ -3127,7 +3177,7 @@ function _ts_decorate4(decorators, target, key, desc) {
3127
3177
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3128
3178
  var DataSpace = class {
3129
3179
  constructor(params) {
3130
- this._ctx = new Context8();
3180
+ this._ctx = new Context7();
3131
3181
  this._notarizationPlugin = new NotarizationPlugin();
3132
3182
  this._cache = void 0;
3133
3183
  // TODO(dmaretskyi): Move into Space?
@@ -3204,7 +3254,7 @@ var DataSpace = class {
3204
3254
  await this._notarizationPlugin.open();
3205
3255
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3206
3256
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3207
- await this._inner.open(new Context8());
3257
+ await this._inner.open(new Context7());
3208
3258
  this._state = SpaceState.CONTROL_ONLY;
3209
3259
  log9("new state", {
3210
3260
  state: SpaceState[this._state]
@@ -3233,7 +3283,7 @@ var DataSpace = class {
3233
3283
  C: (f, a) => f(...a)
3234
3284
  });
3235
3285
  await this._ctx.dispose();
3236
- this._ctx = new Context8();
3286
+ this._ctx = new Context7();
3237
3287
  await this.authVerifier.close();
3238
3288
  await this._inner.close();
3239
3289
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3252,7 +3302,7 @@ var DataSpace = class {
3252
3302
  * Initialize the data pipeline in a separate task.
3253
3303
  */
3254
3304
  initializeDataPipelineAsync() {
3255
- scheduleTask5(this._ctx, async () => {
3305
+ scheduleTask4(this._ctx, async () => {
3256
3306
  try {
3257
3307
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3258
3308
  await this.initializeDataPipeline();
@@ -3654,7 +3704,7 @@ DataSpace = _ts_decorate4([
3654
3704
 
3655
3705
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
3656
3706
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
3657
- import { Context as Context9, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3707
+ import { Context as Context8, cancelWithContext as cancelWithContext3 } from "@dxos/context";
3658
3708
  import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3659
3709
  import { invariant as invariant11 } from "@dxos/invariant";
3660
3710
  import { PublicKey as PublicKey9 } from "@dxos/keys";
@@ -3756,7 +3806,7 @@ var DataSpaceManager = class {
3756
3806
  this._signingContext = _signingContext;
3757
3807
  this._feedStore = _feedStore;
3758
3808
  this._automergeHost = _automergeHost;
3759
- this._ctx = new Context9();
3809
+ this._ctx = new Context8();
3760
3810
  this.updated = new Event7();
3761
3811
  this._spaces = new ComplexMap3(PublicKey9.hash);
3762
3812
  this._isOpen = false;
@@ -4077,7 +4127,7 @@ DataSpaceManager = _ts_decorate5([
4077
4127
  ], DataSpaceManager);
4078
4128
 
4079
4129
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
4080
- import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
4130
+ import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask5 } from "@dxos/async";
4081
4131
  import { Stream as Stream10 } from "@dxos/codec-protobuf";
4082
4132
  import { raise as raise2 } from "@dxos/debug";
4083
4133
  import { invariant as invariant12 } from "@dxos/invariant";
@@ -4134,7 +4184,7 @@ var SpacesServiceImpl = class {
4134
4184
  }, {
4135
4185
  maxFrequency: false ? void 0 : 2
4136
4186
  });
4137
- scheduleTask6(ctx, async () => {
4187
+ scheduleTask5(ctx, async () => {
4138
4188
  const dataSpaceManager = await this._getDataSpaceManager();
4139
4189
  const subscriptions = new EventSubscriptions2();
4140
4190
  ctx.onDispose(() => subscriptions.clear());
@@ -4168,7 +4218,7 @@ var SpacesServiceImpl = class {
4168
4218
  }
4169
4219
  subscribeMessages({ spaceKey, channel }) {
4170
4220
  return new Stream10(({ ctx, next }) => {
4171
- scheduleTask6(ctx, async () => {
4221
+ scheduleTask5(ctx, async () => {
4172
4222
  const dataSpaceManager = await this._getDataSpaceManager();
4173
4223
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
4174
4224
  const handle = space.listen(getChannelId(channel), (message) => {
@@ -4187,7 +4237,7 @@ var SpacesServiceImpl = class {
4187
4237
  }
4188
4238
  };
4189
4239
  ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
4190
- scheduleTask6(ctx, async () => {
4240
+ scheduleTask5(ctx, async () => {
4191
4241
  await space.spaceState.addCredentialProcessor(processor);
4192
4242
  if (noTail) {
4193
4243
  close();
@@ -4295,7 +4345,7 @@ var getChannelId = (channel) => `user-channel/${channel}`;
4295
4345
 
4296
4346
  // packages/sdk/client-services/src/packlets/services/service-context.ts
4297
4347
  import { Trigger as Trigger5 } from "@dxos/async";
4298
- import { Context as Context10, Resource } from "@dxos/context";
4348
+ import { Context as Context9, Resource } from "@dxos/context";
4299
4349
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4300
4350
  import { failUndefined as failUndefined2 } from "@dxos/debug";
4301
4351
  import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
@@ -4306,7 +4356,7 @@ import { Keyring } from "@dxos/keyring";
4306
4356
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4307
4357
  import { log as log12 } from "@dxos/log";
4308
4358
  import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
4309
- import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
4359
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
4310
4360
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
4311
4361
  import { trace as Trace2 } from "@dxos/tracing";
4312
4362
  import { safeInstanceof } from "@dxos/util";
@@ -4455,13 +4505,14 @@ var ServiceContext = class extends Resource {
4455
4505
  getAllDocuments: createDocumentsIterator(this.automergeHost)
4456
4506
  });
4457
4507
  this.invitations = new InvitationsHandler(this.networkManager);
4458
- this._handlerFactories.set(Invitation6.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4508
+ this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4509
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
4459
4510
  }
4460
4511
  async _open(ctx) {
4461
4512
  await this._checkStorageVersion();
4462
4513
  log12("opening...", void 0, {
4463
4514
  F: __dxlog_file14,
4464
- L: 157,
4515
+ L: 164,
4465
4516
  S: this,
4466
4517
  C: (f, a) => f(...a)
4467
4518
  });
@@ -4469,7 +4520,7 @@ var ServiceContext = class extends Resource {
4469
4520
  id: this._instanceId
4470
4521
  }), {
4471
4522
  F: __dxlog_file14,
4472
- L: 158,
4523
+ L: 165,
4473
4524
  S: this,
4474
4525
  C: (f, a) => f(...a)
4475
4526
  });
@@ -4482,17 +4533,26 @@ var ServiceContext = class extends Resource {
4482
4533
  if (this.identityManager.identity) {
4483
4534
  await this._initialize(ctx);
4484
4535
  }
4536
+ const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4537
+ log12("loaded persistent invitations", {
4538
+ count: loadedInvitations.invitations?.length
4539
+ }, {
4540
+ F: __dxlog_file14,
4541
+ L: 178,
4542
+ S: this,
4543
+ C: (f, a) => f(...a)
4544
+ });
4485
4545
  log12.trace("dxos.sdk.service-context.open", trace8.end({
4486
4546
  id: this._instanceId
4487
4547
  }), {
4488
4548
  F: __dxlog_file14,
4489
- L: 169,
4549
+ L: 180,
4490
4550
  S: this,
4491
4551
  C: (f, a) => f(...a)
4492
4552
  });
4493
4553
  log12("opened", void 0, {
4494
4554
  F: __dxlog_file14,
4495
- L: 170,
4555
+ L: 181,
4496
4556
  S: this,
4497
4557
  C: (f, a) => f(...a)
4498
4558
  });
@@ -4500,7 +4560,7 @@ var ServiceContext = class extends Resource {
4500
4560
  async _close() {
4501
4561
  log12("closing...", void 0, {
4502
4562
  F: __dxlog_file14,
4503
- L: 174,
4563
+ L: 185,
4504
4564
  S: this,
4505
4565
  C: (f, a) => f(...a)
4506
4566
  });
@@ -4518,21 +4578,21 @@ var ServiceContext = class extends Resource {
4518
4578
  await this.indexer.destroy();
4519
4579
  log12("closed", void 0, {
4520
4580
  F: __dxlog_file14,
4521
- L: 187,
4581
+ L: 198,
4522
4582
  S: this,
4523
4583
  C: (f, a) => f(...a)
4524
4584
  });
4525
4585
  }
4526
4586
  async createIdentity(params = {}) {
4527
4587
  const identity = await this.identityManager.createIdentity(params);
4528
- await this._initialize(new Context10());
4588
+ await this._initialize(new Context9());
4529
4589
  return identity;
4530
4590
  }
4531
4591
  getInvitationHandler(invitation) {
4532
4592
  const factory = this._handlerFactories.get(invitation.kind);
4533
4593
  invariant13(factory, `Unknown invitation kind: ${invitation.kind}`, {
4534
4594
  F: __dxlog_file14,
4535
- L: 198,
4595
+ L: 209,
4536
4596
  S: this,
4537
4597
  A: [
4538
4598
  "factory",
@@ -4551,7 +4611,7 @@ var ServiceContext = class extends Resource {
4551
4611
  }
4552
4612
  async _acceptIdentity(params) {
4553
4613
  const identity = await this.identityManager.acceptIdentity(params);
4554
- await this._initialize(new Context10());
4614
+ await this._initialize(new Context9());
4555
4615
  return identity;
4556
4616
  }
4557
4617
  async _checkStorageVersion() {
@@ -4564,7 +4624,7 @@ var ServiceContext = class extends Resource {
4564
4624
  async _initialize(ctx) {
4565
4625
  log12("initializing spaces...", void 0, {
4566
4626
  F: __dxlog_file14,
4567
- L: 229,
4627
+ L: 240,
4568
4628
  S: this,
4569
4629
  C: (f, a) => f(...a)
4570
4630
  });
@@ -4584,10 +4644,10 @@ var ServiceContext = class extends Resource {
4584
4644
  };
4585
4645
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4586
4646
  await this.dataSpaceManager.open();
4587
- this._handlerFactories.set(Invitation6.Kind.SPACE, (invitation) => {
4647
+ this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
4588
4648
  invariant13(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4589
4649
  F: __dxlog_file14,
4590
- L: 253,
4650
+ L: 264,
4591
4651
  S: this,
4592
4652
  A: [
4593
4653
  "this.dataSpaceManager",
@@ -4611,7 +4671,7 @@ var ServiceContext = class extends Resource {
4611
4671
  details: assertion
4612
4672
  }, {
4613
4673
  F: __dxlog_file14,
4614
- L: 269,
4674
+ L: 280,
4615
4675
  S: this,
4616
4676
  C: (f, a) => f(...a)
4617
4677
  });
@@ -4622,7 +4682,7 @@ var ServiceContext = class extends Resource {
4622
4682
  details: assertion
4623
4683
  }, {
4624
4684
  F: __dxlog_file14,
4625
- L: 273,
4685
+ L: 284,
4626
4686
  S: this,
4627
4687
  C: (f, a) => f(...a)
4628
4688
  });
@@ -4633,7 +4693,7 @@ var ServiceContext = class extends Resource {
4633
4693
  details: assertion
4634
4694
  }, {
4635
4695
  F: __dxlog_file14,
4636
- L: 278,
4696
+ L: 289,
4637
4697
  S: this,
4638
4698
  C: (f, a) => f(...a)
4639
4699
  });
@@ -4644,7 +4704,7 @@ var ServiceContext = class extends Resource {
4644
4704
  } catch (err) {
4645
4705
  log12.catch(err, void 0, {
4646
4706
  F: __dxlog_file14,
4647
- L: 284,
4707
+ L: 295,
4648
4708
  S: this,
4649
4709
  C: (f, a) => f(...a)
4650
4710
  });
@@ -4698,7 +4758,7 @@ import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/client/s
4698
4758
  import { TRACE_PROCESSOR } from "@dxos/tracing";
4699
4759
 
4700
4760
  // packages/sdk/client-services/src/version.ts
4701
- var DXOS_VERSION = "0.4.10-main.c5e8686";
4761
+ var DXOS_VERSION = "0.4.10-main.c75170d";
4702
4762
 
4703
4763
  // packages/sdk/client-services/src/packlets/services/platform.ts
4704
4764
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -4941,7 +5001,7 @@ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
4941
5001
  // packages/sdk/client-services/src/packlets/services/service-host.ts
4942
5002
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
4943
5003
  import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
4944
- import { Context as Context11 } from "@dxos/context";
5004
+ import { Context as Context10 } from "@dxos/context";
4945
5005
  import { DataServiceImpl, encodeReference } from "@dxos/echo-pipeline";
4946
5006
  import { getTypeReference } from "@dxos/echo-schema";
4947
5007
  import { IndexServiceImpl } from "@dxos/indexing";
@@ -5494,7 +5554,7 @@ var ClientServicesHost = class {
5494
5554
  lockKey,
5495
5555
  onAcquire: () => {
5496
5556
  if (!this._opening) {
5497
- void this.open(new Context11());
5557
+ void this.open(new Context10());
5498
5558
  }
5499
5559
  },
5500
5560
  onRelease: () => this.close()
@@ -5680,7 +5740,7 @@ var ClientServicesHost = class {
5680
5740
  this._serviceRegistry.setServices({
5681
5741
  SystemService: this._systemService,
5682
5742
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5683
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5743
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
5684
5744
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5685
5745
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
5686
5746
  await this._serviceContext.initialized.wait();
@@ -5702,24 +5762,6 @@ var ClientServicesHost = class {
5702
5762
  })
5703
5763
  });
5704
5764
  await this._serviceContext.open(ctx);
5705
- invariant16(this.serviceRegistry.services.InvitationsService, void 0, {
5706
- F: __dxlog_file19,
5707
- L: 314,
5708
- S: this,
5709
- A: [
5710
- "this.serviceRegistry.services.InvitationsService",
5711
- ""
5712
- ]
5713
- });
5714
- const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5715
- log16("loaded persistent invitations", {
5716
- count: loadedInvitations.invitations?.length
5717
- }, {
5718
- F: __dxlog_file19,
5719
- L: 317,
5720
- S: this,
5721
- C: (f, a) => f(...a)
5722
- });
5723
5765
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5724
5766
  if (devtoolsProxy) {
5725
5767
  this._devtoolsProxy = new WebsocketRpcClient({
@@ -5739,7 +5781,7 @@ var ClientServicesHost = class {
5739
5781
  deviceKey
5740
5782
  }, {
5741
5783
  F: __dxlog_file19,
5742
- L: 335,
5784
+ L: 326,
5743
5785
  S: this,
5744
5786
  C: (f, a) => f(...a)
5745
5787
  });
@@ -5747,7 +5789,7 @@ var ClientServicesHost = class {
5747
5789
  id: traceId
5748
5790
  }), {
5749
5791
  F: __dxlog_file19,
5750
- L: 336,
5792
+ L: 327,
5751
5793
  S: this,
5752
5794
  C: (f, a) => f(...a)
5753
5795
  });
@@ -5761,7 +5803,7 @@ var ClientServicesHost = class {
5761
5803
  deviceKey
5762
5804
  }, {
5763
5805
  F: __dxlog_file19,
5764
- L: 347,
5806
+ L: 338,
5765
5807
  S: this,
5766
5808
  C: (f, a) => f(...a)
5767
5809
  });
@@ -5779,7 +5821,7 @@ var ClientServicesHost = class {
5779
5821
  deviceKey
5780
5822
  }, {
5781
5823
  F: __dxlog_file19,
5782
- L: 356,
5824
+ L: 347,
5783
5825
  S: this,
5784
5826
  C: (f, a) => f(...a)
5785
5827
  });
@@ -5790,13 +5832,13 @@ var ClientServicesHost = class {
5790
5832
  id: traceId
5791
5833
  }), {
5792
5834
  F: __dxlog_file19,
5793
- L: 361,
5835
+ L: 352,
5794
5836
  S: this,
5795
5837
  C: (f, a) => f(...a)
5796
5838
  });
5797
5839
  log16("resetting...", void 0, {
5798
5840
  F: __dxlog_file19,
5799
- L: 363,
5841
+ L: 354,
5800
5842
  S: this,
5801
5843
  C: (f, a) => f(...a)
5802
5844
  });
@@ -5804,7 +5846,7 @@ var ClientServicesHost = class {
5804
5846
  await this._storage.reset();
5805
5847
  log16("reset", void 0, {
5806
5848
  F: __dxlog_file19,
5807
- L: 366,
5849
+ L: 357,
5808
5850
  S: this,
5809
5851
  C: (f, a) => f(...a)
5810
5852
  });
@@ -5812,7 +5854,7 @@ var ClientServicesHost = class {
5812
5854
  id: traceId
5813
5855
  }), {
5814
5856
  F: __dxlog_file19,
5815
- L: 367,
5857
+ L: 358,
5816
5858
  S: this,
5817
5859
  C: (f, a) => f(...a)
5818
5860
  });
@@ -5825,7 +5867,7 @@ var ClientServicesHost = class {
5825
5867
  const automergeIndex = space.automergeSpaceState.rootUrl;
5826
5868
  invariant16(automergeIndex, void 0, {
5827
5869
  F: __dxlog_file19,
5828
- L: 379,
5870
+ L: 370,
5829
5871
  S: this,
5830
5872
  A: [
5831
5873
  "automergeIndex",
@@ -5934,6 +5976,7 @@ export {
5934
5976
  createAdmissionKeypair,
5935
5977
  InvitationsServiceImpl,
5936
5978
  SpaceInvitationProtocol,
5979
+ InvitationsManager,
5937
5980
  ClientRpcServer,
5938
5981
  DataSpace,
5939
5982
  DataSpaceManager,
@@ -5951,4 +5994,4 @@ export {
5951
5994
  ClientServicesHost,
5952
5995
  ClientServicesProviderResource
5953
5996
  };
5954
- //# sourceMappingURL=chunk-FUEOAPLA.mjs.map
5997
+ //# sourceMappingURL=chunk-JP7F2IH3.mjs.map