@dxos/client-services 0.4.10-main.fe71b4c → 0.4.10-next.169e4e3

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 (63) hide show
  1. package/dist/lib/browser/{chunk-7S34JE6M.mjs → chunk-KCCL73B5.mjs} +625 -508
  2. package/dist/lib/browser/chunk-KCCL73B5.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 +125 -112
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-DQMGKBOV.cjs → chunk-2EUUFY7P.cjs} +694 -578
  9. package/dist/lib/node/chunk-2EUUFY7P.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +44 -42
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +125 -115
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  16. package/dist/types/src/packlets/indexing/util.d.ts +0 -5
  17. package/dist/types/src/packlets/indexing/util.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
  19. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/index.d.ts +1 -0
  21. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  23. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  25. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  26. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +44 -0
  27. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
  28. package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
  29. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  30. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  31. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  32. package/dist/types/src/packlets/services/service-context.d.ts +2 -0
  33. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  34. package/dist/types/src/packlets/services/service-host.d.ts +1 -0
  35. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  36. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +5 -1
  37. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  38. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  39. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  40. package/dist/types/src/packlets/testing/test-builder.d.ts +3 -0
  41. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  42. package/dist/types/src/version.d.ts +1 -1
  43. package/package.json +34 -34
  44. package/src/packlets/identity/identity-manager.ts +1 -0
  45. package/src/packlets/identity/identity.test.ts +3 -0
  46. package/src/packlets/indexing/util.ts +7 -64
  47. package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
  48. package/src/packlets/invitations/index.ts +1 -0
  49. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  50. package/src/packlets/invitations/invitations-handler.ts +11 -73
  51. package/src/packlets/invitations/invitations-manager.ts +271 -0
  52. package/src/packlets/invitations/invitations-service.ts +23 -168
  53. package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
  54. package/src/packlets/services/automerge-host.test.ts +1 -1
  55. package/src/packlets/services/service-context.ts +14 -2
  56. package/src/packlets/services/service-host.ts +11 -15
  57. package/src/packlets/spaces/data-space-manager.ts +48 -2
  58. package/src/packlets/spaces/data-space.ts +1 -1
  59. package/src/packlets/testing/invitation-utils.ts +100 -97
  60. package/src/packlets/testing/test-builder.ts +19 -1
  61. package/src/version.ts +1 -1
  62. package/dist/lib/browser/chunk-7S34JE6M.mjs.map +0 -7
  63. package/dist/lib/node/chunk-DQMGKBOV.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_DQMGKBOV_exports = {};
30
- __export(chunk_DQMGKBOV_exports, {
29
+ var chunk_2EUUFY7P_exports = {};
30
+ __export(chunk_2EUUFY7P_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -41,6 +41,7 @@ __export(chunk_DQMGKBOV_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_DQMGKBOV_exports, {
65
66
  subscribeToSpaces: () => subscribeToSpaces,
66
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
67
68
  });
68
- module.exports = __toCommonJS(chunk_DQMGKBOV_exports);
69
+ module.exports = __toCommonJS(chunk_2EUUFY7P_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");
@@ -119,7 +120,6 @@ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
119
120
  var import_async7 = require("@dxos/async");
120
121
  var import_client_protocol2 = require("@dxos/client-protocol");
121
122
  var import_context4 = require("@dxos/context");
122
- var import_credentials7 = require("@dxos/credentials");
123
123
  var import_crypto = require("@dxos/crypto");
124
124
  var import_invariant5 = require("@dxos/invariant");
125
125
  var import_keys5 = require("@dxos/keys");
@@ -138,62 +138,67 @@ var import_protocols5 = require("@dxos/protocols");
138
138
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
139
139
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
140
140
  var import_teleport = require("@dxos/teleport");
141
- var import_async9 = require("@dxos/async");
142
141
  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
142
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
148
- var import_credentials8 = require("@dxos/credentials");
143
+ var import_credentials7 = require("@dxos/credentials");
149
144
  var import_feed_store3 = require("@dxos/feed-store");
150
- var import_invariant8 = require("@dxos/invariant");
151
- var import_log7 = require("@dxos/log");
145
+ var import_invariant7 = require("@dxos/invariant");
146
+ var import_log6 = require("@dxos/log");
152
147
  var import_protocols6 = require("@dxos/protocols");
153
148
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
149
+ var import_credentials8 = require("@dxos/protocols/proto/dxos/halo/credentials");
150
+ var import_async9 = require("@dxos/async");
151
+ var import_client_protocol3 = require("@dxos/client-protocol");
152
+ var import_context6 = require("@dxos/context");
153
+ var import_credentials9 = require("@dxos/credentials");
154
+ var import_echo_pipeline = require("@dxos/echo-pipeline");
155
+ var import_invariant8 = require("@dxos/invariant");
156
+ var import_keys7 = require("@dxos/keys");
157
+ var import_log7 = require("@dxos/log");
158
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
154
159
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
155
160
  var import_debug2 = require("@dxos/debug");
156
161
  var import_rpc = require("@dxos/rpc");
157
162
  var import_tracing3 = require("@dxos/tracing");
158
163
  var import_async10 = require("@dxos/async");
159
- var import_client_protocol3 = require("@dxos/client-protocol");
164
+ var import_client_protocol4 = require("@dxos/client-protocol");
160
165
  var import_context7 = require("@dxos/context");
161
166
  var import_debug3 = require("@dxos/debug");
162
- var import_echo_db = require("@dxos/echo-db");
163
167
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
164
168
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
169
+ var import_echo_schema = require("@dxos/echo-schema");
165
170
  var import_invariant9 = require("@dxos/invariant");
166
- var import_keys7 = require("@dxos/keys");
171
+ var import_keys8 = require("@dxos/keys");
167
172
  var import_log8 = require("@dxos/log");
168
173
  var import_protocols7 = require("@dxos/protocols");
169
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
170
- var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
174
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
175
+ var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
171
176
  var import_timeframe2 = require("@dxos/timeframe");
172
177
  var import_tracing4 = require("@dxos/tracing");
173
178
  var import_util4 = require("@dxos/util");
174
179
  var import_async11 = require("@dxos/async");
175
- var import_credentials10 = require("@dxos/credentials");
180
+ var import_credentials11 = require("@dxos/credentials");
176
181
  var import_async12 = require("@dxos/async");
177
182
  var import_context8 = require("@dxos/context");
178
183
  var import_invariant10 = require("@dxos/invariant");
179
- var import_keys8 = require("@dxos/keys");
184
+ var import_keys9 = require("@dxos/keys");
180
185
  var import_log9 = require("@dxos/log");
181
186
  var import_protocols8 = require("@dxos/protocols");
182
187
  var import_teleport2 = require("@dxos/teleport");
183
188
  var import_util5 = require("@dxos/util");
184
189
  var import_async13 = require("@dxos/async");
185
190
  var import_context9 = require("@dxos/context");
186
- var import_credentials11 = require("@dxos/credentials");
191
+ var import_credentials12 = require("@dxos/credentials");
187
192
  var import_invariant11 = require("@dxos/invariant");
188
- var import_keys9 = require("@dxos/keys");
193
+ var import_keys10 = require("@dxos/keys");
189
194
  var import_log10 = require("@dxos/log");
190
195
  var import_protocols9 = require("@dxos/protocols");
191
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
196
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
192
197
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
193
198
  var import_util6 = require("@dxos/util");
194
- var import_credentials12 = require("@dxos/credentials");
199
+ var import_credentials13 = require("@dxos/credentials");
195
200
  var import_debug4 = require("@dxos/debug");
196
- var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
201
+ var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
197
202
  var import_timeframe3 = require("@dxos/timeframe");
198
203
  var import_async14 = require("@dxos/async");
199
204
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
@@ -201,80 +206,79 @@ var import_debug5 = require("@dxos/debug");
201
206
  var import_invariant12 = require("@dxos/invariant");
202
207
  var import_log11 = require("@dxos/log");
203
208
  var import_protocols10 = require("@dxos/protocols");
204
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
209
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
205
210
  var import_async15 = require("@dxos/async");
206
211
  var import_context10 = require("@dxos/context");
207
- var import_credentials14 = require("@dxos/credentials");
212
+ var import_credentials15 = require("@dxos/credentials");
208
213
  var import_debug6 = require("@dxos/debug");
209
214
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
210
215
  var import_feed_store4 = require("@dxos/feed-store");
211
216
  var import_indexing = require("@dxos/indexing");
212
217
  var import_invariant13 = require("@dxos/invariant");
213
218
  var import_keyring = require("@dxos/keyring");
214
- var import_keys10 = require("@dxos/keys");
219
+ var import_keys11 = require("@dxos/keys");
215
220
  var import_log12 = require("@dxos/log");
216
221
  var import_protocols11 = require("@dxos/protocols");
217
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
222
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
218
223
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
219
224
  var import_tracing5 = require("@dxos/tracing");
220
225
  var import_util7 = require("@dxos/util");
221
226
  var import_automerge = require("@dxos/automerge/automerge");
222
- var import_debug7 = require("@dxos/debug");
223
227
  var import_protocols12 = require("@dxos/protocols");
224
228
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
225
- var import_credentials15 = require("@dxos/credentials");
229
+ var import_credentials16 = require("@dxos/credentials");
226
230
  var import_invariant14 = require("@dxos/invariant");
227
231
  var import_protocols13 = require("@dxos/protocols");
228
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
229
- var import_tracing6 = require("@dxos/tracing");
230
232
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
231
- var import_config = require("@dxos/config");
233
+ var import_tracing6 = require("@dxos/tracing");
232
234
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
235
+ var import_config = require("@dxos/config");
236
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
233
237
  var import_tracing7 = require("@dxos/tracing");
234
238
  var import_util8 = require("@dxos/util");
235
239
  var import_async16 = require("@dxos/async");
236
- var import_client_protocol4 = require("@dxos/client-protocol");
240
+ var import_client_protocol5 = require("@dxos/client-protocol");
237
241
  var import_context11 = require("@dxos/context");
238
242
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
239
- var import_echo_schema = require("@dxos/echo-schema");
243
+ var import_echo_schema2 = require("@dxos/echo-schema");
240
244
  var import_indexing2 = require("@dxos/indexing");
241
245
  var import_invariant15 = require("@dxos/invariant");
242
- var import_keys11 = require("@dxos/keys");
246
+ var import_keys12 = require("@dxos/keys");
243
247
  var import_log13 = require("@dxos/log");
244
248
  var import_messaging = require("@dxos/messaging");
245
249
  var import_network_manager2 = require("@dxos/network-manager");
246
250
  var import_protocols14 = require("@dxos/protocols");
247
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
251
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
248
252
  var import_tracing8 = require("@dxos/tracing");
249
253
  var import_util9 = require("@dxos/util");
250
254
  var import_websocket_rpc = require("@dxos/websocket-rpc");
251
255
  var import_async17 = require("@dxos/async");
252
256
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
253
257
  var import_invariant16 = require("@dxos/invariant");
254
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
258
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
255
259
  var import_invariant17 = require("@dxos/invariant");
256
260
  var import_lock_file = require("@dxos/lock-file");
257
261
  var import_log14 = require("@dxos/log");
258
262
  var import_async18 = require("@dxos/async");
259
263
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
260
- var import_keys12 = require("@dxos/keys");
264
+ var import_keys13 = require("@dxos/keys");
261
265
  var import_log15 = require("@dxos/log");
262
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
266
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
263
267
  var import_util10 = require("@dxos/util");
264
268
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
265
269
  var import_protocols15 = require("@dxos/protocols");
266
270
  var import_config2 = require("@dxos/protocols/proto/dxos/config");
267
271
  var import_random_access_storage = require("@dxos/random-access-storage");
268
- var import_client_protocol5 = require("@dxos/client-protocol");
272
+ var import_client_protocol6 = require("@dxos/client-protocol");
269
273
  var import_config3 = require("@dxos/protocols/proto/dxos/config");
270
274
  var import_util11 = require("@dxos/util");
271
275
  var import_level = require("level");
272
276
  var import_node_path = __toESM(require("node:path"));
273
- var import_keys13 = require("@dxos/keys");
277
+ var import_keys14 = require("@dxos/keys");
274
278
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
275
- var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
279
+ var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
276
280
  var import_util12 = require("@dxos/util");
277
- var import_keys14 = require("@dxos/keys");
281
+ var import_keys15 = require("@dxos/keys");
278
282
  var import_util13 = require("@dxos/util");
279
283
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
280
284
  return new import_codec_protobuf.Stream(({ next }) => {
@@ -1293,7 +1297,9 @@ var IdentityManager = class {
1293
1297
  C: (f, a) => f(...a)
1294
1298
  });
1295
1299
  },
1296
- memberKey: identityKey
1300
+ memberKey: identityKey,
1301
+ onDelegatedInvitationStatusChange: async () => {
1302
+ }
1297
1303
  });
1298
1304
  }
1299
1305
  };
@@ -1390,10 +1396,13 @@ var DeviceInvitationProtocol = class {
1390
1396
  kind: import_services2.Invitation.Kind.DEVICE
1391
1397
  };
1392
1398
  }
1393
- async admit(request) {
1399
+ async delegate(invitation) {
1400
+ throw new Error("delegation not supported");
1401
+ }
1402
+ async admit(_, request) {
1394
1403
  (0, import_invariant4.invariant)(request.device, void 0, {
1395
1404
  F: __dxlog_file5,
1396
- L: 37,
1405
+ L: 42,
1397
1406
  S: this,
1398
1407
  A: [
1399
1408
  "request.device",
@@ -1439,7 +1448,7 @@ var DeviceInvitationProtocol = class {
1439
1448
  async accept(response, request) {
1440
1449
  (0, import_invariant4.invariant)(response.device, void 0, {
1441
1450
  F: __dxlog_file5,
1442
- L: 82,
1451
+ L: 87,
1443
1452
  S: this,
1444
1453
  A: [
1445
1454
  "response.device",
@@ -1449,7 +1458,7 @@ var DeviceInvitationProtocol = class {
1449
1458
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1450
1459
  (0, import_invariant4.invariant)(request.device, void 0, {
1451
1460
  F: __dxlog_file5,
1452
- L: 85,
1461
+ L: 90,
1453
1462
  S: this,
1454
1463
  A: [
1455
1464
  "request.device",
@@ -1824,51 +1833,7 @@ var InvitationsHandler = class {
1824
1833
  constructor(_networkManager) {
1825
1834
  this._networkManager = _networkManager;
1826
1835
  }
1827
- createInvitation(protocol, options) {
1828
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = options?.authMethod !== import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
1829
- const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1830
- (0, import_invariant5.invariant)(protocol, void 0, {
1831
- F: __dxlog_file7,
1832
- L: 87,
1833
- S: this,
1834
- A: [
1835
- "protocol",
1836
- ""
1837
- ]
1838
- });
1839
- const invitation = {
1840
- invitationId,
1841
- type,
1842
- authMethod,
1843
- state,
1844
- swarmKey,
1845
- authCode,
1846
- timeout,
1847
- persistent: persistent && type !== import_services3.Invitation.Type.DELEGATED,
1848
- guestKeypair: guestKeypair ?? (authMethod === import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
1849
- created,
1850
- lifetime,
1851
- multiUse,
1852
- ...protocol.getInvitationContext()
1853
- };
1854
- const stream = new import_async7.PushStream();
1855
- const ctx = new import_context4.Context({
1856
- onError: (err) => {
1857
- stream.error(err);
1858
- void ctx.dispose();
1859
- }
1860
- });
1861
- ctx.onDispose(() => {
1862
- (0, import_log4.log)("complete", {
1863
- ...protocol.toJSON()
1864
- }, {
1865
- F: __dxlog_file7,
1866
- L: 115,
1867
- S: this,
1868
- C: (f, a) => f(...a)
1869
- });
1870
- stream.complete();
1871
- });
1836
+ handleInvitationFlow(ctx, stream, protocol, invitation) {
1872
1837
  const createExtension = () => {
1873
1838
  const extension = new InvitationHostExtension({
1874
1839
  onStateUpdate: (invitation2) => {
@@ -1877,8 +1842,8 @@ var InvitationsHandler = class {
1877
1842
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1878
1843
  });
1879
1844
  },
1880
- resolveInvitation: async ({ invitationId: invitationId2 }) => {
1881
- if (invitationId2 && invitationId2 !== invitation.invitationId) {
1845
+ resolveInvitation: async ({ invitationId }) => {
1846
+ if (invitationId && invitationId !== invitation.invitationId) {
1882
1847
  return void 0;
1883
1848
  }
1884
1849
  return invitation;
@@ -1888,14 +1853,14 @@ var InvitationsHandler = class {
1888
1853
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1889
1854
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1890
1855
  F: __dxlog_file7,
1891
- L: 136,
1856
+ L: 87,
1892
1857
  S: this,
1893
1858
  A: [
1894
1859
  "deviceKey",
1895
1860
  ""
1896
1861
  ]
1897
1862
  });
1898
- const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1863
+ const admissionResponse = await protocol.admit(invitation, admissionRequest, extension.guestProfile);
1899
1864
  extension.completedTrigger.wake(deviceKey);
1900
1865
  return admissionResponse;
1901
1866
  } catch (err) {
@@ -1911,7 +1876,7 @@ var InvitationsHandler = class {
1911
1876
  id: traceId
1912
1877
  }), {
1913
1878
  F: __dxlog_file7,
1914
- L: 154,
1879
+ L: 105,
1915
1880
  S: this,
1916
1881
  C: (f, a) => f(...a)
1917
1882
  });
@@ -1919,7 +1884,7 @@ var InvitationsHandler = class {
1919
1884
  ...protocol.toJSON()
1920
1885
  }, {
1921
1886
  F: __dxlog_file7,
1922
- L: 155,
1887
+ L: 106,
1923
1888
  S: this,
1924
1889
  C: (f, a) => f(...a)
1925
1890
  });
@@ -1928,14 +1893,14 @@ var InvitationsHandler = class {
1928
1893
  state: import_services3.Invitation.State.CONNECTED
1929
1894
  });
1930
1895
  const deviceKey = await extension.completedTrigger.wait({
1931
- timeout
1896
+ timeout: invitation.timeout
1932
1897
  });
1933
1898
  (0, import_log4.log)("admitted guest", {
1934
1899
  guest: deviceKey,
1935
1900
  ...protocol.toJSON()
1936
1901
  }, {
1937
1902
  F: __dxlog_file7,
1938
- L: 158,
1903
+ L: 109,
1939
1904
  S: this,
1940
1905
  C: (f, a) => f(...a)
1941
1906
  });
@@ -1947,7 +1912,7 @@ var InvitationsHandler = class {
1947
1912
  id: traceId
1948
1913
  }), {
1949
1914
  F: __dxlog_file7,
1950
- L: 160,
1915
+ L: 111,
1951
1916
  S: this,
1952
1917
  C: (f, a) => f(...a)
1953
1918
  });
@@ -1957,7 +1922,7 @@ var InvitationsHandler = class {
1957
1922
  ...protocol.toJSON()
1958
1923
  }, {
1959
1924
  F: __dxlog_file7,
1960
- L: 163,
1925
+ L: 114,
1961
1926
  S: this,
1962
1927
  C: (f, a) => f(...a)
1963
1928
  });
@@ -1968,7 +1933,7 @@ var InvitationsHandler = class {
1968
1933
  } else {
1969
1934
  import_log4.log.error("failed", err, {
1970
1935
  F: __dxlog_file7,
1971
- L: 166,
1936
+ L: 117,
1972
1937
  S: this,
1973
1938
  C: (f, a) => f(...a)
1974
1939
  });
@@ -1979,12 +1944,12 @@ var InvitationsHandler = class {
1979
1944
  error: err
1980
1945
  }), {
1981
1946
  F: __dxlog_file7,
1982
- L: 169,
1947
+ L: 120,
1983
1948
  S: this,
1984
1949
  C: (f, a) => f(...a)
1985
1950
  });
1986
1951
  } finally {
1987
- if (!multiUse) {
1952
+ if (!invitation.multiUse) {
1988
1953
  await swarmConnection.close();
1989
1954
  await ctx.dispose();
1990
1955
  }
@@ -2000,7 +1965,7 @@ var InvitationsHandler = class {
2000
1965
  ...protocol.toJSON()
2001
1966
  }, {
2002
1967
  F: __dxlog_file7,
2003
- L: 184,
1968
+ L: 135,
2004
1969
  S: this,
2005
1970
  C: (f, a) => f(...a)
2006
1971
  });
@@ -2011,7 +1976,7 @@ var InvitationsHandler = class {
2011
1976
  } else {
2012
1977
  import_log4.log.error("failed", err, {
2013
1978
  F: __dxlog_file7,
2014
- L: 187,
1979
+ L: 138,
2015
1980
  S: this,
2016
1981
  C: (f, a) => f(...a)
2017
1982
  });
@@ -2021,11 +1986,11 @@ var InvitationsHandler = class {
2021
1986
  });
2022
1987
  return extension;
2023
1988
  };
2024
- if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
1989
+ if (invitation.lifetime && invitation.created) {
2025
1990
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2026
1991
  import_log4.log.warn("invitation has already expired", void 0, {
2027
1992
  F: __dxlog_file7,
2028
- L: 198,
1993
+ L: 149,
2029
1994
  S: this,
2030
1995
  C: (f, a) => f(...a)
2031
1996
  });
@@ -2059,24 +2024,12 @@ var InvitationsHandler = class {
2059
2024
  state: import_services3.Invitation.State.CONNECTING
2060
2025
  });
2061
2026
  });
2062
- const observable = new import_client_protocol2.CancellableInvitation({
2063
- initialInvitation: invitation,
2064
- subscriber: stream.observable,
2065
- onCancel: async () => {
2066
- stream.next({
2067
- ...invitation,
2068
- state: import_services3.Invitation.State.CANCELLED
2069
- });
2070
- await ctx.dispose();
2071
- }
2072
- });
2073
- return observable;
2074
2027
  }
2075
2028
  acceptInvitation(protocol, invitation, deviceProfile) {
2076
2029
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2077
2030
  (0, import_invariant5.invariant)(protocol, void 0, {
2078
2031
  F: __dxlog_file7,
2079
- L: 252,
2032
+ L: 191,
2080
2033
  S: this,
2081
2034
  A: [
2082
2035
  "protocol",
@@ -2086,7 +2039,7 @@ var InvitationsHandler = class {
2086
2039
  if (deviceProfile) {
2087
2040
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2088
2041
  F: __dxlog_file7,
2089
- L: 256,
2042
+ L: 194,
2090
2043
  S: this,
2091
2044
  A: [
2092
2045
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2101,7 +2054,7 @@ var InvitationsHandler = class {
2101
2054
  const setState = (newData) => {
2102
2055
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2103
2056
  F: __dxlog_file7,
2104
- L: 267,
2057
+ L: 205,
2105
2058
  S: this,
2106
2059
  A: [
2107
2060
  "newData.state !== undefined",
@@ -2121,7 +2074,7 @@ var InvitationsHandler = class {
2121
2074
  ...protocol.toJSON()
2122
2075
  }, {
2123
2076
  F: __dxlog_file7,
2124
- L: 275,
2077
+ L: 213,
2125
2078
  S: this,
2126
2079
  C: (f, a) => f(...a)
2127
2080
  });
@@ -2131,7 +2084,7 @@ var InvitationsHandler = class {
2131
2084
  } else {
2132
2085
  import_log4.log.warn("auth failed", err, {
2133
2086
  F: __dxlog_file7,
2134
- L: 278,
2087
+ L: 216,
2135
2088
  S: this,
2136
2089
  C: (f, a) => f(...a)
2137
2090
  });
@@ -2145,7 +2098,7 @@ var InvitationsHandler = class {
2145
2098
  ...protocol.toJSON()
2146
2099
  }, {
2147
2100
  F: __dxlog_file7,
2148
- L: 286,
2101
+ L: 224,
2149
2102
  S: this,
2150
2103
  C: (f, a) => f(...a)
2151
2104
  });
@@ -2160,7 +2113,7 @@ var InvitationsHandler = class {
2160
2113
  currentState
2161
2114
  }, {
2162
2115
  F: __dxlog_file7,
2163
- L: 296,
2116
+ L: 234,
2164
2117
  S: this,
2165
2118
  C: (f, a) => f(...a)
2166
2119
  });
@@ -2175,7 +2128,7 @@ var InvitationsHandler = class {
2175
2128
  id: traceId
2176
2129
  }), {
2177
2130
  F: __dxlog_file7,
2178
- L: 305,
2131
+ L: 243,
2179
2132
  S: this,
2180
2133
  C: (f, a) => f(...a)
2181
2134
  });
@@ -2187,7 +2140,7 @@ var InvitationsHandler = class {
2187
2140
  ...protocol.toJSON()
2188
2141
  }, {
2189
2142
  F: __dxlog_file7,
2190
- L: 313,
2143
+ L: 251,
2191
2144
  S: this,
2192
2145
  C: (f, a) => f(...a)
2193
2146
  });
@@ -2198,7 +2151,7 @@ var InvitationsHandler = class {
2198
2151
  ...protocol.toJSON()
2199
2152
  }, {
2200
2153
  F: __dxlog_file7,
2201
- L: 317,
2154
+ L: 255,
2202
2155
  S: this,
2203
2156
  C: (f, a) => f(...a)
2204
2157
  });
@@ -2208,7 +2161,7 @@ var InvitationsHandler = class {
2208
2161
  response: introductionResponse
2209
2162
  }, {
2210
2163
  F: __dxlog_file7,
2211
- L: 321,
2164
+ L: 259,
2212
2165
  S: this,
2213
2166
  C: (f, a) => f(...a)
2214
2167
  });
@@ -2229,7 +2182,7 @@ var InvitationsHandler = class {
2229
2182
  ...protocol.toJSON()
2230
2183
  }, {
2231
2184
  F: __dxlog_file7,
2232
- L: 337,
2185
+ L: 275,
2233
2186
  S: this,
2234
2187
  C: (f, a) => f(...a)
2235
2188
  });
@@ -2241,7 +2194,7 @@ var InvitationsHandler = class {
2241
2194
  ...protocol.toJSON()
2242
2195
  }, {
2243
2196
  F: __dxlog_file7,
2244
- L: 348,
2197
+ L: 286,
2245
2198
  S: this,
2246
2199
  C: (f, a) => f(...a)
2247
2200
  });
@@ -2254,7 +2207,7 @@ var InvitationsHandler = class {
2254
2207
  id: traceId
2255
2208
  }), {
2256
2209
  F: __dxlog_file7,
2257
- L: 350,
2210
+ L: 288,
2258
2211
  S: this,
2259
2212
  C: (f, a) => f(...a)
2260
2213
  });
@@ -2264,7 +2217,7 @@ var InvitationsHandler = class {
2264
2217
  ...protocol.toJSON()
2265
2218
  }, {
2266
2219
  F: __dxlog_file7,
2267
- L: 353,
2220
+ L: 291,
2268
2221
  S: this,
2269
2222
  C: (f, a) => f(...a)
2270
2223
  });
@@ -2274,7 +2227,7 @@ var InvitationsHandler = class {
2274
2227
  } else {
2275
2228
  (0, import_log4.log)("auth failed", err, {
2276
2229
  F: __dxlog_file7,
2277
- L: 356,
2230
+ L: 294,
2278
2231
  S: this,
2279
2232
  C: (f, a) => f(...a)
2280
2233
  });
@@ -2285,7 +2238,7 @@ var InvitationsHandler = class {
2285
2238
  error: err
2286
2239
  }), {
2287
2240
  F: __dxlog_file7,
2288
- L: 359,
2241
+ L: 297,
2289
2242
  S: this,
2290
2243
  C: (f, a) => f(...a)
2291
2244
  });
@@ -2303,7 +2256,7 @@ var InvitationsHandler = class {
2303
2256
  ...protocol.toJSON()
2304
2257
  }, {
2305
2258
  F: __dxlog_file7,
2306
- L: 370,
2259
+ L: 308,
2307
2260
  S: this,
2308
2261
  C: (f, a) => f(...a)
2309
2262
  });
@@ -2313,7 +2266,7 @@ var InvitationsHandler = class {
2313
2266
  } else {
2314
2267
  (0, import_log4.log)("auth failed", err, {
2315
2268
  F: __dxlog_file7,
2316
- L: 373,
2269
+ L: 311,
2317
2270
  S: this,
2318
2271
  C: (f, a) => f(...a)
2319
2272
  });
@@ -2330,7 +2283,7 @@ var InvitationsHandler = class {
2330
2283
  } else {
2331
2284
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2332
2285
  F: __dxlog_file7,
2333
- L: 387,
2286
+ L: 325,
2334
2287
  S: this,
2335
2288
  A: [
2336
2289
  "invitation.swarmKey",
@@ -2372,7 +2325,7 @@ var InvitationsHandler = class {
2372
2325
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2373
2326
  (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2374
2327
  F: __dxlog_file7,
2375
- L: 427,
2328
+ L: 365,
2376
2329
  S: this,
2377
2330
  C: (f, a) => f(...a)
2378
2331
  });
@@ -2382,7 +2335,7 @@ var InvitationsHandler = class {
2382
2335
  const authCode = await authenticated.wait(options);
2383
2336
  (0, import_log4.log)("sending authentication request", void 0, {
2384
2337
  F: __dxlog_file7,
2385
- L: 431,
2338
+ L: 369,
2386
2339
  S: this,
2387
2340
  C: (f, a) => f(...a)
2388
2341
  });
@@ -2403,7 +2356,7 @@ var InvitationsHandler = class {
2403
2356
  attempt
2404
2357
  }, {
2405
2358
  F: __dxlog_file7,
2406
- L: 442,
2359
+ L: 380,
2407
2360
  S: this,
2408
2361
  C: (f, a) => f(...a)
2409
2362
  });
@@ -2421,7 +2374,7 @@ var InvitationsHandler = class {
2421
2374
  }
2422
2375
  (0, import_log4.log)("sending authentication request", void 0, {
2423
2376
  F: __dxlog_file7,
2424
- L: 461,
2377
+ L: 399,
2425
2378
  S: this,
2426
2379
  C: (f, a) => f(...a)
2427
2380
  });
@@ -2444,194 +2397,34 @@ var createAdmissionKeypair = () => {
2444
2397
  privateKey: keypair.secretKey
2445
2398
  };
2446
2399
  };
2447
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2448
2400
  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;
2401
+ constructor(_invitationsManager) {
2402
+ this._invitationsManager = _invitationsManager;
2462
2403
  }
2463
2404
  // TODO(burdon): Guest/host label.
2464
2405
  getLoggingContext() {
2465
2406
  return {};
2466
2407
  }
2467
2408
  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
- }
2479
2409
  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
- });
2410
+ void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
2506
2411
  });
2507
2412
  }
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
- }
2413
+ acceptInvitation(request) {
2414
+ const invitation = this._invitationsManager.acceptInvitation(request);
2555
2415
  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
- });
2416
+ invitation.subscribe(next, close, close);
2567
2417
  });
2568
2418
  }
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
- }
2419
+ async authenticate(request) {
2420
+ return this._invitationsManager.authenticate(request);
2598
2421
  }
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
- }
2422
+ async cancelInvitation(request) {
2423
+ return this._invitationsManager.cancelInvitation(request);
2631
2424
  }
2632
2425
  queryInvitations() {
2633
2426
  return new import_codec_protobuf8.Stream(({ next, ctx }) => {
2634
- this._invitationCreated.on(ctx, (invitation) => {
2427
+ this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
2635
2428
  next({
2636
2429
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2637
2430
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2640,7 +2433,7 @@ var InvitationsServiceImpl = class {
2640
2433
  ]
2641
2434
  });
2642
2435
  });
2643
- this._invitationAccepted.on(ctx, (invitation) => {
2436
+ this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
2644
2437
  next({
2645
2438
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2646
2439
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2649,7 +2442,7 @@ var InvitationsServiceImpl = class {
2649
2442
  ]
2650
2443
  });
2651
2444
  });
2652
- this._removedCreated.on(ctx, (invitation) => {
2445
+ this._invitationsManager.removedCreated.on(ctx, (invitation) => {
2653
2446
  next({
2654
2447
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2655
2448
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2658,7 +2451,7 @@ var InvitationsServiceImpl = class {
2658
2451
  ]
2659
2452
  });
2660
2453
  });
2661
- this._removedAccepted.on(ctx, (invitation) => {
2454
+ this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
2662
2455
  next({
2663
2456
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2664
2457
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2667,7 +2460,7 @@ var InvitationsServiceImpl = class {
2667
2460
  ]
2668
2461
  });
2669
2462
  });
2670
- this._saved.on(ctx, (invitation) => {
2463
+ this._invitationsManager.saved.on(ctx, (invitation) => {
2671
2464
  next({
2672
2465
  action: import_services5.QueryInvitationsResponse.Action.SAVED,
2673
2466
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2679,32 +2472,25 @@ var InvitationsServiceImpl = class {
2679
2472
  next({
2680
2473
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2681
2474
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2682
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2475
+ invitations: this._invitationsManager.getCreatedInvitations(),
2683
2476
  existing: true
2684
2477
  });
2685
2478
  next({
2686
2479
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2687
2480
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2688
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2481
+ invitations: this._invitationsManager.getAcceptedInvitations(),
2689
2482
  existing: true
2690
2483
  });
2691
- if (this._persistentInvitationsLoaded) {
2484
+ this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
2692
2485
  next({
2693
2486
  action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2694
2487
  type: import_services5.QueryInvitationsResponse.Type.CREATED
2695
2488
  });
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
- }
2489
+ });
2704
2490
  });
2705
2491
  }
2706
2492
  };
2707
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2493
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2708
2494
  var SpaceInvitationProtocol = class {
2709
2495
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2710
2496
  this._spaceManager = _spaceManager;
@@ -2724,10 +2510,10 @@ var SpaceInvitationProtocol = class {
2724
2510
  spaceKey: this._spaceKey
2725
2511
  };
2726
2512
  }
2727
- async admit(request, guestProfile) {
2728
- (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2729
- F: __dxlog_file9,
2730
- L: 47,
2513
+ async admit(invitation, request, guestProfile) {
2514
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2515
+ F: __dxlog_file8,
2516
+ L: 55,
2731
2517
  S: this,
2732
2518
  A: [
2733
2519
  "this._spaceKey",
@@ -2735,18 +2521,18 @@ var SpaceInvitationProtocol = class {
2735
2521
  ]
2736
2522
  });
2737
2523
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2738
- (0, import_invariant8.invariant)(space, void 0, {
2739
- F: __dxlog_file9,
2740
- L: 49,
2524
+ (0, import_invariant7.invariant)(space, void 0, {
2525
+ F: __dxlog_file8,
2526
+ L: 57,
2741
2527
  S: this,
2742
2528
  A: [
2743
2529
  "space",
2744
2530
  ""
2745
2531
  ]
2746
2532
  });
2747
- (0, import_invariant8.invariant)(request.space, void 0, {
2748
- F: __dxlog_file9,
2749
- L: 51,
2533
+ (0, import_invariant7.invariant)(request.space, void 0, {
2534
+ F: __dxlog_file8,
2535
+ L: 59,
2750
2536
  S: this,
2751
2537
  A: [
2752
2538
  "request.space",
@@ -2754,19 +2540,19 @@ var SpaceInvitationProtocol = class {
2754
2540
  ]
2755
2541
  });
2756
2542
  const { identityKey, deviceKey } = request.space;
2757
- (0, import_log7.log)("writing guest credentials", {
2543
+ (0, import_log6.log)("writing guest credentials", {
2758
2544
  host: this._signingContext.deviceKey,
2759
2545
  guest: deviceKey
2760
2546
  }, {
2761
- F: __dxlog_file9,
2762
- L: 54,
2547
+ F: __dxlog_file8,
2548
+ L: 62,
2763
2549
  S: this,
2764
2550
  C: (f, a) => f(...a)
2765
2551
  });
2766
- 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,
2769
- L: 65,
2552
+ const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2553
+ (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2554
+ F: __dxlog_file8,
2555
+ L: 74,
2770
2556
  S: this,
2771
2557
  A: [
2772
2558
  "credentials[0].credential",
@@ -2774,9 +2560,9 @@ var SpaceInvitationProtocol = class {
2774
2560
  ]
2775
2561
  });
2776
2562
  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,
2779
- L: 67,
2563
+ (0, import_invariant7.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2564
+ F: __dxlog_file8,
2565
+ L: 76,
2780
2566
  S: this,
2781
2567
  A: [
2782
2568
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2791,6 +2577,69 @@ var SpaceInvitationProtocol = class {
2791
2577
  }
2792
2578
  };
2793
2579
  }
2580
+ async delegate(invitation) {
2581
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2582
+ F: __dxlog_file8,
2583
+ L: 89,
2584
+ S: this,
2585
+ A: [
2586
+ "this._spaceKey",
2587
+ ""
2588
+ ]
2589
+ });
2590
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
2591
+ (0, import_invariant7.invariant)(space, void 0, {
2592
+ F: __dxlog_file8,
2593
+ L: 91,
2594
+ S: this,
2595
+ A: [
2596
+ "space",
2597
+ ""
2598
+ ]
2599
+ });
2600
+ if (invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
2601
+ (0, import_invariant7.invariant)(invitation.guestKeypair?.publicKey, void 0, {
2602
+ F: __dxlog_file8,
2603
+ L: 93,
2604
+ S: this,
2605
+ A: [
2606
+ "invitation.guestKeypair?.publicKey",
2607
+ ""
2608
+ ]
2609
+ });
2610
+ }
2611
+ (0, import_log6.log)("writing delegate space invitation", {
2612
+ host: this._signingContext.deviceKey,
2613
+ id: invitation.invitationId
2614
+ }, {
2615
+ F: __dxlog_file8,
2616
+ L: 96,
2617
+ S: this,
2618
+ C: (f, a) => f(...a)
2619
+ });
2620
+ const credential = await (0, import_credentials7.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
2621
+ invitationId: invitation.invitationId,
2622
+ authMethod: invitation.authMethod,
2623
+ swarmKey: invitation.swarmKey,
2624
+ role: import_credentials8.SpaceMember.Role.ADMIN,
2625
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2626
+ multiUse: invitation.multiUse ?? false,
2627
+ guestKey: invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2628
+ });
2629
+ (0, import_invariant7.invariant)(credential.credential, void 0, {
2630
+ F: __dxlog_file8,
2631
+ L: 116,
2632
+ S: this,
2633
+ A: [
2634
+ "credential.credential",
2635
+ ""
2636
+ ]
2637
+ });
2638
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, [
2639
+ credential
2640
+ ]);
2641
+ return credential.credential.credential.id;
2642
+ }
2794
2643
  checkInvitation(invitation) {
2795
2644
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
2796
2645
  return new import_protocols6.AlreadyJoinedError("Already joined space.");
@@ -2814,9 +2663,9 @@ var SpaceInvitationProtocol = class {
2814
2663
  };
2815
2664
  }
2816
2665
  async accept(response) {
2817
- (0, import_invariant8.invariant)(response.space, void 0, {
2818
- F: __dxlog_file9,
2819
- L: 107,
2666
+ (0, import_invariant7.invariant)(response.space, void 0, {
2667
+ F: __dxlog_file8,
2668
+ L: 149,
2820
2669
  S: this,
2821
2670
  A: [
2822
2671
  "response.space",
@@ -2824,19 +2673,19 @@ var SpaceInvitationProtocol = class {
2824
2673
  ]
2825
2674
  });
2826
2675
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2827
- const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2828
- (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2829
- F: __dxlog_file9,
2830
- L: 110,
2676
+ const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
2677
+ (0, import_invariant7.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2678
+ F: __dxlog_file8,
2679
+ L: 152,
2831
2680
  S: this,
2832
2681
  A: [
2833
2682
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
2834
2683
  "'Invalid credential'"
2835
2684
  ]
2836
2685
  });
2837
- (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2838
- F: __dxlog_file9,
2839
- L: 111,
2686
+ (0, import_invariant7.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2687
+ F: __dxlog_file8,
2688
+ L: 153,
2840
2689
  S: this,
2841
2690
  A: [
2842
2691
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2858,6 +2707,284 @@ var SpaceInvitationProtocol = class {
2858
2707
  };
2859
2708
  }
2860
2709
  };
2710
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2711
+ var InvitationsManager = class {
2712
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2713
+ this._invitationsHandler = _invitationsHandler;
2714
+ this._getHandler = _getHandler;
2715
+ this._metadataStore = _metadataStore;
2716
+ this._createInvitations = /* @__PURE__ */ new Map();
2717
+ this._acceptInvitations = /* @__PURE__ */ new Map();
2718
+ this.invitationCreated = new import_async9.Event();
2719
+ this.invitationAccepted = new import_async9.Event();
2720
+ this.removedCreated = new import_async9.Event();
2721
+ this.removedAccepted = new import_async9.Event();
2722
+ this.saved = new import_async9.Event();
2723
+ this._persistentInvitationsLoadedEvent = new import_async9.Event();
2724
+ this._persistentInvitationsLoaded = false;
2725
+ }
2726
+ async createInvitation(options) {
2727
+ if (options.invitationId) {
2728
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2729
+ if (existingInvitation) {
2730
+ return existingInvitation;
2731
+ }
2732
+ }
2733
+ const handler = this._getHandler(options);
2734
+ const invitation = this._createInvitation(handler, options);
2735
+ const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
2736
+ this._createInvitations.set(invitation.invitationId, observableInvitation);
2737
+ this.invitationCreated.emit(invitation);
2738
+ this._onInvitationComplete(observableInvitation, async () => {
2739
+ this._createInvitations.delete(observableInvitation.get().invitationId);
2740
+ this.removedCreated.emit(observableInvitation.get());
2741
+ if (observableInvitation.get().persistent) {
2742
+ await this._safeDeleteInvitation(observableInvitation.get());
2743
+ }
2744
+ });
2745
+ try {
2746
+ await this._persistIfRequired(handler, stream, invitation);
2747
+ } catch (err) {
2748
+ import_log7.log.catch(err, void 0, {
2749
+ F: __dxlog_file9,
2750
+ L: 76,
2751
+ S: this,
2752
+ C: (f, a) => f(...a)
2753
+ });
2754
+ await observableInvitation.cancel();
2755
+ return observableInvitation;
2756
+ }
2757
+ this._invitationsHandler.handleInvitationFlow(ctx, stream, handler, observableInvitation.get());
2758
+ return observableInvitation;
2759
+ }
2760
+ async loadPersistentInvitations() {
2761
+ if (this._persistentInvitationsLoaded) {
2762
+ const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
2763
+ return {
2764
+ invitations
2765
+ };
2766
+ }
2767
+ try {
2768
+ const persistentInvitations = this._metadataStore.getInvitations();
2769
+ const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2770
+ const loadTasks = freshInvitations.map((persistentInvitation) => {
2771
+ (0, import_invariant8.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2772
+ F: __dxlog_file9,
2773
+ L: 97,
2774
+ S: this,
2775
+ A: [
2776
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2777
+ "'invitation already exists'"
2778
+ ]
2779
+ });
2780
+ return this.createInvitation({
2781
+ ...persistentInvitation,
2782
+ persistent: false
2783
+ });
2784
+ });
2785
+ const cInvitations = await Promise.all(loadTasks);
2786
+ return {
2787
+ invitations: cInvitations.map((invitation) => invitation.get())
2788
+ };
2789
+ } catch (err) {
2790
+ import_log7.log.catch(err, void 0, {
2791
+ F: __dxlog_file9,
2792
+ L: 104,
2793
+ S: this,
2794
+ C: (f, a) => f(...a)
2795
+ });
2796
+ return {
2797
+ invitations: []
2798
+ };
2799
+ } finally {
2800
+ this._persistentInvitationsLoadedEvent.emit();
2801
+ this._persistentInvitationsLoaded = true;
2802
+ }
2803
+ }
2804
+ acceptInvitation(request) {
2805
+ const options = request.invitation;
2806
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
2807
+ if (existingInvitation) {
2808
+ return existingInvitation;
2809
+ }
2810
+ const handler = this._getHandler(options);
2811
+ const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
2812
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
2813
+ this.invitationAccepted.emit(invitation.get());
2814
+ this._onInvitationComplete(invitation, () => {
2815
+ this._acceptInvitations.delete(invitation.get().invitationId);
2816
+ this.removedAccepted.emit(invitation.get());
2817
+ });
2818
+ return invitation;
2819
+ }
2820
+ async authenticate({ invitationId, authCode }) {
2821
+ (0, import_log7.log)("authenticating...", void 0, {
2822
+ F: __dxlog_file9,
2823
+ L: 133,
2824
+ S: this,
2825
+ C: (f, a) => f(...a)
2826
+ });
2827
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2828
+ F: __dxlog_file9,
2829
+ L: 134,
2830
+ S: this,
2831
+ A: [
2832
+ "invitationId",
2833
+ ""
2834
+ ]
2835
+ });
2836
+ const observable = this._acceptInvitations.get(invitationId);
2837
+ if (!observable) {
2838
+ import_log7.log.warn("invalid invitation", {
2839
+ invitationId
2840
+ }, {
2841
+ F: __dxlog_file9,
2842
+ L: 137,
2843
+ S: this,
2844
+ C: (f, a) => f(...a)
2845
+ });
2846
+ } else {
2847
+ await observable.authenticate(authCode);
2848
+ }
2849
+ }
2850
+ async cancelInvitation({ invitationId }) {
2851
+ (0, import_log7.log)("cancelInvitation...", {
2852
+ invitationId
2853
+ }, {
2854
+ F: __dxlog_file9,
2855
+ L: 144,
2856
+ S: this,
2857
+ C: (f, a) => f(...a)
2858
+ });
2859
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2860
+ F: __dxlog_file9,
2861
+ L: 145,
2862
+ S: this,
2863
+ A: [
2864
+ "invitationId",
2865
+ ""
2866
+ ]
2867
+ });
2868
+ const created = this._createInvitations.get(invitationId);
2869
+ if (created) {
2870
+ if (created.get().persistent) {
2871
+ await this._metadataStore.removeInvitation(invitationId);
2872
+ }
2873
+ await created.cancel();
2874
+ this._createInvitations.delete(invitationId);
2875
+ this.removedCreated.emit(created.get());
2876
+ return;
2877
+ }
2878
+ const accepted = this._acceptInvitations.get(invitationId);
2879
+ if (accepted) {
2880
+ await accepted.cancel();
2881
+ this._acceptInvitations.delete(invitationId);
2882
+ this.removedAccepted.emit(accepted.get());
2883
+ }
2884
+ }
2885
+ getCreatedInvitations() {
2886
+ return [
2887
+ ...this._createInvitations.values()
2888
+ ].map((i) => i.get());
2889
+ }
2890
+ getAcceptedInvitations() {
2891
+ return [
2892
+ ...this._acceptInvitations.values()
2893
+ ].map((i) => i.get());
2894
+ }
2895
+ onPersistentInvitationsLoaded(ctx, callback) {
2896
+ if (this._persistentInvitationsLoaded) {
2897
+ callback();
2898
+ } else {
2899
+ this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2900
+ }
2901
+ }
2902
+ _createInvitation(protocol, options) {
2903
+ const { invitationId = import_keys7.PublicKey.random().toHex(), type = import_services7.Invitation.Type.INTERACTIVE, authMethod = import_services7.Invitation.AuthMethod.SHARED_SECRET, state = import_services7.Invitation.State.INIT, timeout = import_client_protocol3.INVITATION_TIMEOUT, swarmKey = import_keys7.PublicKey.random(), persistent = options?.authMethod !== import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
2904
+ const authCode = options?.authCode ?? (authMethod === import_services7.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol3.AUTHENTICATION_CODE_LENGTH) : void 0);
2905
+ return {
2906
+ invitationId,
2907
+ type,
2908
+ authMethod,
2909
+ state,
2910
+ swarmKey,
2911
+ authCode,
2912
+ timeout,
2913
+ persistent: persistent && type !== import_services7.Invitation.Type.DELEGATED,
2914
+ guestKeypair: guestKeypair ?? (authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2915
+ created,
2916
+ lifetime,
2917
+ multiUse,
2918
+ delegationCredentialId: options?.delegationCredentialId,
2919
+ ...protocol.getInvitationContext()
2920
+ };
2921
+ }
2922
+ _createObservableInvitation(handler, invitation) {
2923
+ const stream = new import_async9.PushStream();
2924
+ const ctx = new import_context6.Context({
2925
+ onError: (err) => {
2926
+ stream.error(err);
2927
+ void ctx.dispose();
2928
+ }
2929
+ });
2930
+ ctx.onDispose(() => {
2931
+ (0, import_log7.log)("complete", {
2932
+ ...handler.toJSON()
2933
+ }, {
2934
+ F: __dxlog_file9,
2935
+ L: 228,
2936
+ S: this,
2937
+ C: (f, a) => f(...a)
2938
+ });
2939
+ stream.complete();
2940
+ });
2941
+ const observableInvitation = new import_client_protocol3.CancellableInvitation({
2942
+ initialInvitation: invitation,
2943
+ subscriber: stream.observable,
2944
+ onCancel: async () => {
2945
+ stream.next({
2946
+ ...invitation,
2947
+ state: import_services7.Invitation.State.CANCELLED
2948
+ });
2949
+ await ctx.dispose();
2950
+ }
2951
+ });
2952
+ return {
2953
+ ctx,
2954
+ stream,
2955
+ observableInvitation
2956
+ };
2957
+ }
2958
+ async _persistIfRequired(handler, changeStream, invitation) {
2959
+ if (invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId == null) {
2960
+ const delegationCredentialId = await handler.delegate(invitation);
2961
+ changeStream.next({
2962
+ ...invitation,
2963
+ delegationCredentialId
2964
+ });
2965
+ } else if (invitation.persistent) {
2966
+ await this._metadataStore.addInvitation(invitation);
2967
+ this.saved.emit(invitation);
2968
+ }
2969
+ }
2970
+ async _safeDeleteInvitation(invitation) {
2971
+ try {
2972
+ await this._metadataStore.removeInvitation(invitation.invitationId);
2973
+ } catch (err) {
2974
+ import_log7.log.catch(err, void 0, {
2975
+ F: __dxlog_file9,
2976
+ L: 260,
2977
+ S: this,
2978
+ C: (f, a) => f(...a)
2979
+ });
2980
+ }
2981
+ }
2982
+ _onInvitationComplete(invitation, callback) {
2983
+ invitation.subscribe(() => {
2984
+ }, () => {
2985
+ }, callback);
2986
+ }
2987
+ };
2861
2988
  function _ts_decorate3(decorators, target, key, desc) {
2862
2989
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2863
2990
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2942,7 +3069,7 @@ var AutomergeSpaceState = class {
2942
3069
  this._isProcessingRootDocs = false;
2943
3070
  }
2944
3071
  async processCredential(credential) {
2945
- if (!(0, import_credentials10.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
3072
+ if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
2946
3073
  return;
2947
3074
  }
2948
3075
  this.lastEpoch = credential;
@@ -2977,8 +3104,8 @@ var NotarizationPlugin = class {
2977
3104
  this._ctx = new import_context8.Context();
2978
3105
  this._extensionOpened = new import_async12.Event();
2979
3106
  this._extensions = /* @__PURE__ */ new Set();
2980
- this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
2981
- this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys8.PublicKey.hash);
3107
+ this._processedCredentials = new import_util5.ComplexSet(import_keys9.PublicKey.hash);
3108
+ this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
2982
3109
  }
2983
3110
  get hasWriter() {
2984
3111
  return !!this._writer;
@@ -3242,7 +3369,7 @@ var DataSpace = class {
3242
3369
  this._notarizationPlugin = new NotarizationPlugin();
3243
3370
  this._cache = void 0;
3244
3371
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3245
- this._state = import_services7.SpaceState.CLOSED;
3372
+ this._state = import_services8.SpaceState.CLOSED;
3246
3373
  this.error = void 0;
3247
3374
  this.stateUpdate = new import_async10.Event();
3248
3375
  this.metrics = {};
@@ -3257,14 +3384,14 @@ var DataSpace = class {
3257
3384
  this._callbacks = params.callbacks ?? {};
3258
3385
  this._automergeHost = params.automergeHost;
3259
3386
  this.authVerifier = new TrustedKeySetAuthVerifier({
3260
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys7.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3387
+ trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3261
3388
  update: this._inner.stateUpdate,
3262
- authTimeout: import_client_protocol3.AUTH_TIMEOUT
3389
+ authTimeout: import_client_protocol4.AUTH_TIMEOUT
3263
3390
  });
3264
3391
  this._cache = params.cache;
3265
3392
  this._state = params.initialState;
3266
3393
  (0, import_log8.log)("new state", {
3267
- state: import_services7.SpaceState[this._state]
3394
+ state: import_services8.SpaceState[this._state]
3268
3395
  }, {
3269
3396
  F: __dxlog_file11,
3270
3397
  L: 140,
@@ -3312,9 +3439,9 @@ var DataSpace = class {
3312
3439
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3313
3440
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3314
3441
  await this._inner.open(new import_context7.Context());
3315
- this._state = import_services7.SpaceState.CONTROL_ONLY;
3442
+ this._state = import_services8.SpaceState.CONTROL_ONLY;
3316
3443
  (0, import_log8.log)("new state", {
3317
- state: import_services7.SpaceState[this._state]
3444
+ state: import_services8.SpaceState[this._state]
3318
3445
  }, {
3319
3446
  F: __dxlog_file11,
3320
3447
  L: 198,
@@ -3330,9 +3457,9 @@ var DataSpace = class {
3330
3457
  }
3331
3458
  async _close() {
3332
3459
  await this._callbacks.beforeClose?.();
3333
- this._state = import_services7.SpaceState.CLOSED;
3460
+ this._state = import_services8.SpaceState.CLOSED;
3334
3461
  (0, import_log8.log)("new state", {
3335
- state: import_services7.SpaceState[this._state]
3462
+ state: import_services8.SpaceState[this._state]
3336
3463
  }, {
3337
3464
  F: __dxlog_file11,
3338
3465
  L: 212,
@@ -3379,9 +3506,9 @@ var DataSpace = class {
3379
3506
  S: this,
3380
3507
  C: (f, a) => f(...a)
3381
3508
  });
3382
- this._state = import_services7.SpaceState.ERROR;
3509
+ this._state = import_services8.SpaceState.ERROR;
3383
3510
  (0, import_log8.log)("new state", {
3384
- state: import_services7.SpaceState[this._state]
3511
+ state: import_services8.SpaceState[this._state]
3385
3512
  }, {
3386
3513
  F: __dxlog_file11,
3387
3514
  L: 251,
@@ -3396,12 +3523,12 @@ var DataSpace = class {
3396
3523
  });
3397
3524
  }
3398
3525
  async initializeDataPipeline() {
3399
- if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3526
+ if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3400
3527
  throw new import_protocols7.SystemError("Invalid operation");
3401
3528
  }
3402
- this._state = import_services7.SpaceState.INITIALIZING;
3529
+ this._state = import_services8.SpaceState.INITIALIZING;
3403
3530
  (0, import_log8.log)("new state", {
3404
- state: import_services7.SpaceState[this._state]
3531
+ state: import_services8.SpaceState[this._state]
3405
3532
  }, {
3406
3533
  F: __dxlog_file11,
3407
3534
  L: 267,
@@ -3419,9 +3546,9 @@ var DataSpace = class {
3419
3546
  C: (f, a) => f(...a)
3420
3547
  });
3421
3548
  await this._callbacks.beforeReady?.();
3422
- this._state = import_services7.SpaceState.READY;
3549
+ this._state = import_services8.SpaceState.READY;
3423
3550
  (0, import_log8.log)("new state", {
3424
- state: import_services7.SpaceState[this._state]
3551
+ state: import_services8.SpaceState[this._state]
3425
3552
  }, {
3426
3553
  F: __dxlog_file11,
3427
3554
  L: 283,
@@ -3467,7 +3594,7 @@ var DataSpace = class {
3467
3594
  spaceKey: this.key,
3468
3595
  deviceKey: this._signingContext.deviceKey,
3469
3596
  identityKey: this._signingContext.identityKey,
3470
- designation: import_credentials9.AdmittedFeed.Designation.CONTROL
3597
+ designation: import_credentials10.AdmittedFeed.Designation.CONTROL
3471
3598
  }
3472
3599
  }));
3473
3600
  }
@@ -3484,7 +3611,7 @@ var DataSpace = class {
3484
3611
  spaceKey: this.key,
3485
3612
  deviceKey: this._signingContext.deviceKey,
3486
3613
  identityKey: this._signingContext.identityKey,
3487
- designation: import_credentials9.AdmittedFeed.Designation.DATA
3614
+ designation: import_credentials10.AdmittedFeed.Designation.DATA
3488
3615
  }
3489
3616
  }));
3490
3617
  }
@@ -3561,7 +3688,7 @@ var DataSpace = class {
3561
3688
  let epoch;
3562
3689
  switch (options?.migration) {
3563
3690
  case void 0:
3564
- case import_services7.CreateEpochRequest.Migration.NONE:
3691
+ case import_services8.CreateEpochRequest.Migration.NONE:
3565
3692
  {
3566
3693
  epoch = {
3567
3694
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3571,7 +3698,7 @@ var DataSpace = class {
3571
3698
  };
3572
3699
  }
3573
3700
  break;
3574
- case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3701
+ case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3575
3702
  {
3576
3703
  const document = this._automergeHost.repo.create();
3577
3704
  epoch = {
@@ -3582,7 +3709,7 @@ var DataSpace = class {
3582
3709
  };
3583
3710
  }
3584
3711
  break;
3585
- case import_services7.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3712
+ case import_services8.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3586
3713
  {
3587
3714
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3588
3715
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
@@ -3605,7 +3732,7 @@ var DataSpace = class {
3605
3732
  };
3606
3733
  }
3607
3734
  break;
3608
- case import_services7.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3735
+ case import_services8.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3609
3736
  {
3610
3737
  import_log8.log.info("Fragmenting", void 0, {
3611
3738
  F: __dxlog_file11,
@@ -3617,7 +3744,7 @@ var DataSpace = class {
3617
3744
  const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3618
3745
  await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3619
3746
  const objects = Object.entries(rootHandle.docSync().objects);
3620
- const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_db.TYPE_PROPERTIES);
3747
+ const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
3621
3748
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3622
3749
  (0, import_invariant9.invariant)(properties, "Properties not found", {
3623
3750
  F: __dxlog_file11,
@@ -3688,22 +3815,22 @@ var DataSpace = class {
3688
3815
  ]));
3689
3816
  }
3690
3817
  async activate() {
3691
- if (this._state !== import_services7.SpaceState.INACTIVE) {
3818
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
3692
3819
  return;
3693
3820
  }
3694
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3821
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
3695
3822
  await this._open();
3696
3823
  this.initializeDataPipelineAsync();
3697
3824
  }
3698
3825
  async deactivate() {
3699
- if (this._state === import_services7.SpaceState.INACTIVE) {
3826
+ if (this._state === import_services8.SpaceState.INACTIVE) {
3700
3827
  return;
3701
3828
  }
3702
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3829
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
3703
3830
  await this._close();
3704
- this._state = import_services7.SpaceState.INACTIVE;
3831
+ this._state = import_services8.SpaceState.INACTIVE;
3705
3832
  (0, import_log8.log)("new state", {
3706
- state: import_services7.SpaceState[this._state]
3833
+ state: import_services8.SpaceState[this._state]
3707
3834
  }, {
3708
3835
  F: __dxlog_file11,
3709
3836
  L: 531,
@@ -3721,7 +3848,7 @@ _ts_decorate4([
3721
3848
  ], DataSpace.prototype, "key", null);
3722
3849
  _ts_decorate4([
3723
3850
  import_tracing4.trace.info({
3724
- enum: import_services7.SpaceState
3851
+ enum: import_services8.SpaceState
3725
3852
  })
3726
3853
  ], DataSpace.prototype, "state", null);
3727
3854
  _ts_decorate4([
@@ -3760,7 +3887,7 @@ DataSpace = _ts_decorate4([
3760
3887
  ], DataSpace);
3761
3888
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3762
3889
  const credentials = [
3763
- await (0, import_credentials12.createCredential)({
3890
+ await (0, import_credentials13.createCredential)({
3764
3891
  signer: keyring,
3765
3892
  issuer: space.key,
3766
3893
  subject: space.key,
@@ -3769,14 +3896,14 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3769
3896
  spaceKey: space.key
3770
3897
  }
3771
3898
  }),
3772
- await (0, import_credentials12.createCredential)({
3899
+ await (0, import_credentials13.createCredential)({
3773
3900
  signer: keyring,
3774
3901
  issuer: space.key,
3775
3902
  subject: signingContext.identityKey,
3776
3903
  assertion: {
3777
3904
  "@type": "dxos.halo.credentials.SpaceMember",
3778
3905
  spaceKey: space.key,
3779
- role: import_credentials13.SpaceMember.Role.ADMIN,
3906
+ role: import_credentials14.SpaceMember.Role.ADMIN,
3780
3907
  profile: signingContext.getProfile(),
3781
3908
  genesisFeedKey: space.controlFeedKey ?? (0, import_debug4.failUndefined)()
3782
3909
  }
@@ -3788,7 +3915,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3788
3915
  spaceKey: space.key,
3789
3916
  identityKey: signingContext.identityKey,
3790
3917
  deviceKey: signingContext.deviceKey,
3791
- designation: import_credentials13.AdmittedFeed.Designation.CONTROL
3918
+ designation: import_credentials14.AdmittedFeed.Designation.CONTROL
3792
3919
  }
3793
3920
  }),
3794
3921
  await signingContext.credentialSigner.createCredential({
@@ -3798,7 +3925,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3798
3925
  spaceKey: space.key,
3799
3926
  identityKey: signingContext.identityKey,
3800
3927
  deviceKey: signingContext.deviceKey,
3801
- designation: import_credentials13.AdmittedFeed.Designation.DATA
3928
+ designation: import_credentials14.AdmittedFeed.Designation.DATA
3802
3929
  }
3803
3930
  }),
3804
3931
  await signingContext.credentialSigner.createCredential({
@@ -3836,18 +3963,19 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3836
3963
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3837
3964
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3838
3965
  var DataSpaceManager = class {
3839
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, params) {
3966
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, _invitationsManager, params) {
3840
3967
  this._spaceManager = _spaceManager;
3841
3968
  this._metadataStore = _metadataStore;
3842
3969
  this._keyring = _keyring;
3843
3970
  this._signingContext = _signingContext;
3844
3971
  this._feedStore = _feedStore;
3845
3972
  this._automergeHost = _automergeHost;
3973
+ this._invitationsManager = _invitationsManager;
3846
3974
  this._ctx = new import_context9.Context();
3847
3975
  this.updated = new import_async13.Event();
3848
- this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3976
+ this._spaces = new import_util6.ComplexMap(import_keys10.PublicKey.hash);
3849
3977
  this._isOpen = false;
3850
- this._instanceId = import_keys9.PublicKey.random().toHex();
3978
+ this._instanceId = import_keys10.PublicKey.random().toHex();
3851
3979
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3852
3980
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3853
3981
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3859,7 +3987,7 @@ var DataSpaceManager = class {
3859
3987
  async open() {
3860
3988
  (0, import_log10.log)("open", void 0, {
3861
3989
  F: __dxlog_file12,
3862
- L: 98,
3990
+ L: 101,
3863
3991
  S: this,
3864
3992
  C: (f, a) => f(...a)
3865
3993
  });
@@ -3867,7 +3995,7 @@ var DataSpaceManager = class {
3867
3995
  id: this._instanceId
3868
3996
  }), {
3869
3997
  F: __dxlog_file12,
3870
- L: 99,
3998
+ L: 102,
3871
3999
  S: this,
3872
4000
  C: (f, a) => f(...a)
3873
4001
  });
@@ -3875,7 +4003,7 @@ var DataSpaceManager = class {
3875
4003
  spaces: this._metadataStore.spaces.length
3876
4004
  }, {
3877
4005
  F: __dxlog_file12,
3878
- L: 100,
4006
+ L: 103,
3879
4007
  S: this,
3880
4008
  C: (f, a) => f(...a)
3881
4009
  });
@@ -3885,7 +4013,7 @@ var DataSpaceManager = class {
3885
4013
  spaceMetadata
3886
4014
  }, {
3887
4015
  F: __dxlog_file12,
3888
- L: 104,
4016
+ L: 107,
3889
4017
  S: this,
3890
4018
  C: (f, a) => f(...a)
3891
4019
  });
@@ -3896,7 +4024,7 @@ var DataSpaceManager = class {
3896
4024
  err
3897
4025
  }, {
3898
4026
  F: __dxlog_file12,
3899
- L: 107,
4027
+ L: 110,
3900
4028
  S: this,
3901
4029
  C: (f, a) => f(...a)
3902
4030
  });
@@ -3905,7 +4033,7 @@ var DataSpaceManager = class {
3905
4033
  this._isOpen = true;
3906
4034
  this.updated.emit();
3907
4035
  for (const space of this._spaces.values()) {
3908
- if (space.state !== import_services8.SpaceState.INACTIVE) {
4036
+ if (space.state !== import_services9.SpaceState.INACTIVE) {
3909
4037
  space.initializeDataPipelineAsync();
3910
4038
  }
3911
4039
  }
@@ -3913,7 +4041,7 @@ var DataSpaceManager = class {
3913
4041
  id: this._instanceId
3914
4042
  }), {
3915
4043
  F: __dxlog_file12,
3916
- L: 120,
4044
+ L: 123,
3917
4045
  S: this,
3918
4046
  C: (f, a) => f(...a)
3919
4047
  });
@@ -3921,7 +4049,7 @@ var DataSpaceManager = class {
3921
4049
  async close() {
3922
4050
  (0, import_log10.log)("close", void 0, {
3923
4051
  F: __dxlog_file12,
3924
- L: 125,
4052
+ L: 128,
3925
4053
  S: this,
3926
4054
  C: (f, a) => f(...a)
3927
4055
  });
@@ -3937,7 +4065,7 @@ var DataSpaceManager = class {
3937
4065
  async createSpace() {
3938
4066
  (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3939
4067
  F: __dxlog_file12,
3940
- L: 138,
4068
+ L: 141,
3941
4069
  S: this,
3942
4070
  A: [
3943
4071
  "this._isOpen",
@@ -3952,13 +4080,13 @@ var DataSpaceManager = class {
3952
4080
  genesisFeedKey: controlFeedKey,
3953
4081
  controlFeedKey,
3954
4082
  dataFeedKey,
3955
- state: import_services8.SpaceState.ACTIVE
4083
+ state: import_services9.SpaceState.ACTIVE
3956
4084
  };
3957
4085
  (0, import_log10.log)("creating space...", {
3958
4086
  spaceKey
3959
4087
  }, {
3960
4088
  F: __dxlog_file12,
3961
- L: 150,
4089
+ L: 153,
3962
4090
  S: this,
3963
4091
  C: (f, a) => f(...a)
3964
4092
  });
@@ -3972,9 +4100,9 @@ var DataSpaceManager = class {
3972
4100
  const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
3973
4101
  await this._metadataStore.addSpace(metadata);
3974
4102
  const memberCredential = credentials[1];
3975
- (0, import_invariant11.invariant)((0, import_credentials11.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4103
+ (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3976
4104
  F: __dxlog_file12,
3977
- L: 163,
4105
+ L: 166,
3978
4106
  S: this,
3979
4107
  A: [
3980
4108
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3992,13 +4120,13 @@ var DataSpaceManager = class {
3992
4120
  opts
3993
4121
  }, {
3994
4122
  F: __dxlog_file12,
3995
- L: 175,
4123
+ L: 178,
3996
4124
  S: this,
3997
4125
  C: (f, a) => f(...a)
3998
4126
  });
3999
4127
  (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
4000
4128
  F: __dxlog_file12,
4001
- L: 176,
4129
+ L: 179,
4002
4130
  S: this,
4003
4131
  A: [
4004
4132
  "this._isOpen",
@@ -4007,7 +4135,7 @@ var DataSpaceManager = class {
4007
4135
  });
4008
4136
  (0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4009
4137
  F: __dxlog_file12,
4010
- L: 177,
4138
+ L: 180,
4011
4139
  S: this,
4012
4140
  A: [
4013
4141
  "!this._spaces.has(opts.spaceKey)",
@@ -4034,7 +4162,7 @@ var DataSpaceManager = class {
4034
4162
  async waitUntilSpaceReady(spaceKey) {
4035
4163
  await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4036
4164
  const space = this._spaces.get(spaceKey);
4037
- return !!space && space.state === import_services8.SpaceState.READY;
4165
+ return !!space && space.state === import_services9.SpaceState.READY;
4038
4166
  }));
4039
4167
  }
4040
4168
  async _constructSpace(metadata) {
@@ -4042,7 +4170,7 @@ var DataSpaceManager = class {
4042
4170
  metadata
4043
4171
  }, {
4044
4172
  F: __dxlog_file12,
4045
- L: 210,
4173
+ L: 213,
4046
4174
  S: this,
4047
4175
  C: (f, a) => f(...a)
4048
4176
  });
@@ -4080,18 +4208,21 @@ var DataSpaceManager = class {
4080
4208
  onAuthFailure: () => {
4081
4209
  import_log10.log.warn("auth failure", void 0, {
4082
4210
  F: __dxlog_file12,
4083
- L: 247,
4211
+ L: 250,
4084
4212
  S: this,
4085
4213
  C: (f, a) => f(...a)
4086
4214
  });
4087
4215
  },
4088
- memberKey: this._signingContext.identityKey
4216
+ memberKey: this._signingContext.identityKey,
4217
+ onDelegatedInvitationStatusChange: (invitation, isActive) => {
4218
+ return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
4219
+ }
4089
4220
  });
4090
4221
  controlFeed && await space.setControlFeed(controlFeed);
4091
4222
  dataFeed && await space.setDataFeed(dataFeed);
4092
4223
  const dataSpace = new DataSpace({
4093
4224
  inner: space,
4094
- initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
4225
+ initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
4095
4226
  metadataStore: this._metadataStore,
4096
4227
  gossip,
4097
4228
  presence,
@@ -4104,7 +4235,7 @@ var DataSpaceManager = class {
4104
4235
  space: space.key
4105
4236
  }, {
4106
4237
  F: __dxlog_file12,
4107
- L: 265,
4238
+ L: 271,
4108
4239
  S: this,
4109
4240
  C: (f, a) => f(...a)
4110
4241
  });
@@ -4115,11 +4246,14 @@ var DataSpaceManager = class {
4115
4246
  open: this._isOpen
4116
4247
  }, {
4117
4248
  F: __dxlog_file12,
4118
- L: 268,
4249
+ L: 274,
4119
4250
  S: this,
4120
4251
  C: (f, a) => f(...a)
4121
4252
  });
4122
4253
  if (this._isOpen) {
4254
+ await this._createDelegatedInvitations(dataSpace, [
4255
+ ...space.spaceState.invitations.entries()
4256
+ ]);
4123
4257
  this.updated.emit();
4124
4258
  }
4125
4259
  },
@@ -4128,7 +4262,7 @@ var DataSpaceManager = class {
4128
4262
  space: space.key
4129
4263
  }, {
4130
4264
  F: __dxlog_file12,
4131
- L: 274,
4265
+ L: 281,
4132
4266
  S: this,
4133
4267
  C: (f, a) => f(...a)
4134
4268
  });
@@ -4137,7 +4271,7 @@ var DataSpaceManager = class {
4137
4271
  cache: metadata.cache,
4138
4272
  automergeHost: this._automergeHost
4139
4273
  });
4140
- if (metadata.state !== import_services8.SpaceState.INACTIVE) {
4274
+ if (metadata.state !== import_services9.SpaceState.INACTIVE) {
4141
4275
  await dataSpace.open();
4142
4276
  }
4143
4277
  if (metadata.controlTimeframe) {
@@ -4146,6 +4280,41 @@ var DataSpaceManager = class {
4146
4280
  this._spaces.set(metadata.key, dataSpace);
4147
4281
  return dataSpace;
4148
4282
  }
4283
+ async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4284
+ if (dataSpace?.state !== import_services9.SpaceState.READY) {
4285
+ return;
4286
+ }
4287
+ if (isActive) {
4288
+ await this._createDelegatedInvitations(dataSpace, [
4289
+ [
4290
+ delegatedInvitation.credentialId,
4291
+ delegatedInvitation.invitation
4292
+ ]
4293
+ ]);
4294
+ } else {
4295
+ await this._invitationsManager.cancelInvitation(delegatedInvitation.invitation);
4296
+ }
4297
+ }
4298
+ async _createDelegatedInvitations(space, invitations) {
4299
+ const tasks = invitations.map(([credentialId, invitation]) => {
4300
+ return this._invitationsManager.createInvitation({
4301
+ type: import_services9.Invitation.Type.DELEGATED,
4302
+ kind: import_services9.Invitation.Kind.SPACE,
4303
+ spaceKey: space.key,
4304
+ authMethod: invitation.authMethod,
4305
+ invitationId: invitation.invitationId,
4306
+ swarmKey: invitation.swarmKey,
4307
+ guestKeypair: invitation.guestKey ? {
4308
+ publicKey: invitation.guestKey
4309
+ } : void 0,
4310
+ lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
4311
+ multiUse: invitation.multiUse,
4312
+ delegationCredentialId: credentialId,
4313
+ persistent: false
4314
+ });
4315
+ });
4316
+ await Promise.all(tasks);
4317
+ }
4149
4318
  };
4150
4319
  _ts_decorate5([
4151
4320
  import_async13.synchronized
@@ -4182,10 +4351,10 @@ var SpacesServiceImpl = class {
4182
4351
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4183
4352
  if (state) {
4184
4353
  switch (state) {
4185
- case import_services9.SpaceState.ACTIVE:
4354
+ case import_services10.SpaceState.ACTIVE:
4186
4355
  await space.activate();
4187
4356
  break;
4188
- case import_services9.SpaceState.INACTIVE:
4357
+ case import_services10.SpaceState.INACTIVE:
4189
4358
  await space.deactivate();
4190
4359
  break;
4191
4360
  default:
@@ -4359,7 +4528,7 @@ var SpacesServiceImpl = class {
4359
4528
  identityKey: member.key,
4360
4529
  profile: member.profile ?? {}
4361
4530
  },
4362
- presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4531
+ presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4363
4532
  peerStates: peers
4364
4533
  };
4365
4534
  }),
@@ -4379,8 +4548,10 @@ var createSelectedDocumentsIterator = (automergeHost) => (
4379
4548
  async function* loadDocuments(ids) {
4380
4549
  for (const id of ids) {
4381
4550
  const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4382
- const handle = automergeHost.repo.find(documentId);
4383
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4551
+ const handle = automergeHost.repo.handles[documentId] ?? automergeHost.repo.find(documentId);
4552
+ if (!handle.isReady()) {
4553
+ await handle.whenReady();
4554
+ }
4384
4555
  const doc = handle.docSync();
4385
4556
  const hash = (0, import_automerge.getHeads)(doc).join("");
4386
4557
  yield doc.objects?.[objectId] ? [
@@ -4393,57 +4564,6 @@ var createSelectedDocumentsIterator = (automergeHost) => (
4393
4564
  }
4394
4565
  }
4395
4566
  );
4396
- var createDocumentsIterator = (automergeHost) => (
4397
- /**
4398
- * Recursively get all object data blobs from Automerge Repo.
4399
- * @param ids
4400
- */
4401
- // TODO(mykola): Unload automerge handles after usage.
4402
- async function* getAllDocuments() {
4403
- const visited = /* @__PURE__ */ new Set();
4404
- async function* getObjectsFromHandle(handle) {
4405
- if (visited.has(handle.documentId)) {
4406
- return;
4407
- }
4408
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4409
- const doc = handle.docSync();
4410
- const heads = (0, import_automerge.getHeads)(doc);
4411
- if (doc.objects) {
4412
- yield Object.entries(doc.objects).map(([objectId, object]) => {
4413
- return {
4414
- id: import_protocols12.idCodec.encode({
4415
- documentId: handle.documentId,
4416
- objectId
4417
- }),
4418
- object,
4419
- currentHash: heads.join("")
4420
- };
4421
- });
4422
- }
4423
- if (doc.links) {
4424
- for (const id of Object.values(doc.links)) {
4425
- if (visited.has(id)) {
4426
- continue;
4427
- }
4428
- const linkHandle = automergeHost.repo.find(id);
4429
- for await (const result of getObjectsFromHandle(linkHandle)) {
4430
- yield result;
4431
- }
4432
- }
4433
- }
4434
- visited.add(handle.documentId);
4435
- }
4436
- for (const handle of Object.values(automergeHost.repo.handles)) {
4437
- if (visited.has(handle.documentId)) {
4438
- continue;
4439
- }
4440
- for await (const result of getObjectsFromHandle(handle)) {
4441
- yield result;
4442
- }
4443
- visited.add(handle.documentId);
4444
- }
4445
- }
4446
- );
4447
4567
  function _ts_decorate6(decorators, target, key, desc) {
4448
4568
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4449
4569
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4465,7 +4585,7 @@ var ServiceContext = class extends import_context10.Resource {
4465
4585
  this._runtimeParams = _runtimeParams;
4466
4586
  this.initialized = new import_async15.Trigger();
4467
4587
  this._handlerFactories = /* @__PURE__ */ new Map();
4468
- this._instanceId = import_keys10.PublicKey.random().toHex();
4588
+ this._instanceId = import_keys11.PublicKey.random().toHex();
4469
4589
  this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
4470
4590
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4471
4591
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
@@ -4500,21 +4620,22 @@ var ServiceContext = class extends import_context10.Resource {
4500
4620
  })
4501
4621
  });
4502
4622
  this.indexer = new import_indexing.Indexer({
4623
+ db: this.level,
4503
4624
  indexStore: new import_indexing.IndexStore({
4504
4625
  db: level.sublevel("index-storage")
4505
4626
  }),
4506
4627
  metadataStore: this.indexMetadata,
4507
- loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4508
- getAllDocuments: createDocumentsIterator(this.automergeHost)
4628
+ loadDocuments: createSelectedDocumentsIterator(this.automergeHost)
4509
4629
  });
4510
4630
  this.invitations = new InvitationsHandler(this.networkManager);
4511
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4631
+ this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4632
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4512
4633
  }
4513
4634
  async _open(ctx) {
4514
4635
  await this._checkStorageVersion();
4515
4636
  (0, import_log12.log)("opening...", void 0, {
4516
4637
  F: __dxlog_file14,
4517
- L: 157,
4638
+ L: 164,
4518
4639
  S: this,
4519
4640
  C: (f, a) => f(...a)
4520
4641
  });
@@ -4522,7 +4643,7 @@ var ServiceContext = class extends import_context10.Resource {
4522
4643
  id: this._instanceId
4523
4644
  }), {
4524
4645
  F: __dxlog_file14,
4525
- L: 158,
4646
+ L: 165,
4526
4647
  S: this,
4527
4648
  C: (f, a) => f(...a)
4528
4649
  });
@@ -4535,17 +4656,26 @@ var ServiceContext = class extends import_context10.Resource {
4535
4656
  if (this.identityManager.identity) {
4536
4657
  await this._initialize(ctx);
4537
4658
  }
4659
+ const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4660
+ (0, import_log12.log)("loaded persistent invitations", {
4661
+ count: loadedInvitations.invitations?.length
4662
+ }, {
4663
+ F: __dxlog_file14,
4664
+ L: 178,
4665
+ S: this,
4666
+ C: (f, a) => f(...a)
4667
+ });
4538
4668
  import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.end({
4539
4669
  id: this._instanceId
4540
4670
  }), {
4541
4671
  F: __dxlog_file14,
4542
- L: 169,
4672
+ L: 180,
4543
4673
  S: this,
4544
4674
  C: (f, a) => f(...a)
4545
4675
  });
4546
4676
  (0, import_log12.log)("opened", void 0, {
4547
4677
  F: __dxlog_file14,
4548
- L: 170,
4678
+ L: 181,
4549
4679
  S: this,
4550
4680
  C: (f, a) => f(...a)
4551
4681
  });
@@ -4553,7 +4683,7 @@ var ServiceContext = class extends import_context10.Resource {
4553
4683
  async _close() {
4554
4684
  (0, import_log12.log)("closing...", void 0, {
4555
4685
  F: __dxlog_file14,
4556
- L: 174,
4686
+ L: 185,
4557
4687
  S: this,
4558
4688
  C: (f, a) => f(...a)
4559
4689
  });
@@ -4571,7 +4701,7 @@ var ServiceContext = class extends import_context10.Resource {
4571
4701
  await this.indexer.destroy();
4572
4702
  (0, import_log12.log)("closed", void 0, {
4573
4703
  F: __dxlog_file14,
4574
- L: 187,
4704
+ L: 198,
4575
4705
  S: this,
4576
4706
  C: (f, a) => f(...a)
4577
4707
  });
@@ -4585,7 +4715,7 @@ var ServiceContext = class extends import_context10.Resource {
4585
4715
  const factory = this._handlerFactories.get(invitation.kind);
4586
4716
  (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4587
4717
  F: __dxlog_file14,
4588
- L: 198,
4718
+ L: 209,
4589
4719
  S: this,
4590
4720
  A: [
4591
4721
  "factory",
@@ -4617,7 +4747,7 @@ var ServiceContext = class extends import_context10.Resource {
4617
4747
  async _initialize(ctx) {
4618
4748
  (0, import_log12.log)("initializing spaces...", void 0, {
4619
4749
  F: __dxlog_file14,
4620
- L: 229,
4750
+ L: 240,
4621
4751
  S: this,
4622
4752
  C: (f, a) => f(...a)
4623
4753
  });
@@ -4635,12 +4765,12 @@ var ServiceContext = class extends import_context10.Resource {
4635
4765
  });
4636
4766
  }
4637
4767
  };
4638
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4768
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this.invitationsManager, this._runtimeParams);
4639
4769
  await this.dataSpaceManager.open();
4640
- this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4770
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4641
4771
  (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4642
4772
  F: __dxlog_file14,
4643
- L: 253,
4773
+ L: 265,
4644
4774
  S: this,
4645
4775
  A: [
4646
4776
  "this.dataSpaceManager",
@@ -4652,7 +4782,7 @@ var ServiceContext = class extends import_context10.Resource {
4652
4782
  this.initialized.wake();
4653
4783
  this._deviceSpaceSync = {
4654
4784
  processCredential: async (credential) => {
4655
- const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
4785
+ const assertion = (0, import_credentials15.getCredentialAssertion)(credential);
4656
4786
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
4657
4787
  return;
4658
4788
  }
@@ -4664,7 +4794,7 @@ var ServiceContext = class extends import_context10.Resource {
4664
4794
  details: assertion
4665
4795
  }, {
4666
4796
  F: __dxlog_file14,
4667
- L: 269,
4797
+ L: 281,
4668
4798
  S: this,
4669
4799
  C: (f, a) => f(...a)
4670
4800
  });
@@ -4675,7 +4805,7 @@ var ServiceContext = class extends import_context10.Resource {
4675
4805
  details: assertion
4676
4806
  }, {
4677
4807
  F: __dxlog_file14,
4678
- L: 273,
4808
+ L: 285,
4679
4809
  S: this,
4680
4810
  C: (f, a) => f(...a)
4681
4811
  });
@@ -4686,7 +4816,7 @@ var ServiceContext = class extends import_context10.Resource {
4686
4816
  details: assertion
4687
4817
  }, {
4688
4818
  F: __dxlog_file14,
4689
- L: 278,
4819
+ L: 290,
4690
4820
  S: this,
4691
4821
  C: (f, a) => f(...a)
4692
4822
  });
@@ -4697,7 +4827,7 @@ var ServiceContext = class extends import_context10.Resource {
4697
4827
  } catch (err) {
4698
4828
  import_log12.log.catch(err, void 0, {
4699
4829
  F: __dxlog_file14,
4700
- L: 284,
4830
+ L: 296,
4701
4831
  S: this,
4702
4832
  C: (f, a) => f(...a)
4703
4833
  });
@@ -4739,26 +4869,26 @@ var ServiceRegistry = class {
4739
4869
  delete this._handlers[name];
4740
4870
  }
4741
4871
  };
4742
- var DXOS_VERSION = "0.4.10-main.fe71b4c";
4872
+ var DXOS_VERSION = "0.4.10-next.169e4e3";
4743
4873
  var getPlatform = () => {
4744
4874
  if (process.browser) {
4745
4875
  if (typeof window !== "undefined") {
4746
4876
  const { userAgent } = window.navigator;
4747
4877
  return {
4748
- type: import_services12.Platform.PLATFORM_TYPE.BROWSER,
4878
+ type: import_services13.Platform.PLATFORM_TYPE.BROWSER,
4749
4879
  userAgent,
4750
4880
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4751
4881
  };
4752
4882
  } else {
4753
4883
  return {
4754
- type: import_services12.Platform.PLATFORM_TYPE.SHARED_WORKER,
4884
+ type: import_services13.Platform.PLATFORM_TYPE.SHARED_WORKER,
4755
4885
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4756
4886
  };
4757
4887
  }
4758
4888
  } else {
4759
4889
  const { platform: platform2, version, arch } = process;
4760
4890
  return {
4761
- type: import_services12.Platform.PLATFORM_TYPE.NODE,
4891
+ type: import_services13.Platform.PLATFORM_TYPE.NODE,
4762
4892
  platform: platform2,
4763
4893
  arch,
4764
4894
  runtime: version,
@@ -4845,7 +4975,7 @@ var getSpaceStats = async (space) => {
4845
4975
  const stats = {
4846
4976
  key: space.key,
4847
4977
  metrics: space.metrics,
4848
- epochs: space.inner.spaceState.credentials.filter((0, import_credentials15.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4978
+ epochs: space.inner.spaceState.credentials.filter((0, import_credentials16.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4849
4979
  ...credential.subject.assertion,
4850
4980
  id: credential.id
4851
4981
  })),
@@ -4856,7 +4986,7 @@ var getSpaceStats = async (space) => {
4856
4986
  displayName: member.assertion.profile?.displayName
4857
4987
  }
4858
4988
  },
4859
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE
4989
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services12.SpaceMember.PresenceState.ONLINE : import_services12.SpaceMember.PresenceState.OFFLINE
4860
4990
  })),
4861
4991
  pipeline: {
4862
4992
  // TODO(burdon): Pick properties from credentials if needed.
@@ -4920,9 +5050,9 @@ var DevicesServiceImpl = class {
4920
5050
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
4921
5051
  return {
4922
5052
  deviceKey: key,
4923
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services15.DeviceKind.CURRENT : import_services15.DeviceKind.TRUSTED,
5053
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services16.DeviceKind.CURRENT : import_services16.DeviceKind.TRUSTED,
4924
5054
  profile,
4925
- presence: isMe ? import_services15.Device.PresenceState.ONLINE : peerState ? import_services15.Device.PresenceState.ONLINE : import_services15.Device.PresenceState.OFFLINE
5055
+ presence: isMe ? import_services16.Device.PresenceState.ONLINE : peerState ? import_services16.Device.PresenceState.ONLINE : import_services16.Device.PresenceState.OFFLINE
4926
5056
  };
4927
5057
  })
4928
5058
  });
@@ -5021,7 +5151,7 @@ var LoggingServiceImpl = class {
5021
5151
  constructor() {
5022
5152
  this._logs = new import_async18.Event();
5023
5153
  this._started = Date.now();
5024
- this._sessionId = import_keys12.PublicKey.random().toHex();
5154
+ this._sessionId = import_keys13.PublicKey.random().toHex();
5025
5155
  this._logProcessor = (_config, entry2) => {
5026
5156
  this._logs.emit(entry2);
5027
5157
  };
@@ -5118,16 +5248,16 @@ var LoggingServiceImpl = class {
5118
5248
  };
5119
5249
  var matchFilter = (filter, level, path2, options) => {
5120
5250
  switch (options) {
5121
- case import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5251
+ case import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5122
5252
  return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5123
- case import_services16.QueryLogsRequest.MatchingOptions.EXPLICIT:
5253
+ case import_services17.QueryLogsRequest.MatchingOptions.EXPLICIT:
5124
5254
  return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5125
5255
  }
5126
5256
  };
5127
5257
  var shouldLog = (entry2, request) => {
5128
- const options = request.options ?? import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5258
+ const options = request.options ?? import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5129
5259
  if (request.filters === void 0) {
5130
- return options === import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5260
+ return options === import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5131
5261
  } else {
5132
5262
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
5133
5263
  }
@@ -5164,7 +5294,7 @@ var NetworkServiceImpl = class {
5164
5294
  }
5165
5295
  };
5166
5296
  var getRootPath = (config) => {
5167
- const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol5.DX_DATA : "dxos/storage" } = config ?? {};
5297
+ const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5168
5298
  return `${dataRoot}/`;
5169
5299
  };
5170
5300
  var isPersistent = (config) => {
@@ -5215,7 +5345,7 @@ var toStorageType = (type) => {
5215
5345
  };
5216
5346
  var createLevel = async (config) => {
5217
5347
  const persistent = isPersistent(config);
5218
- const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys13.PublicKey.random().toHex()}`;
5348
+ const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys14.PublicKey.random().toHex()}`;
5219
5349
  const level = new import_level.Level(storagePath);
5220
5350
  await level.open();
5221
5351
  return level;
@@ -5240,8 +5370,8 @@ var SystemServiceImpl = class {
5240
5370
  return {
5241
5371
  timestamp: /* @__PURE__ */ new Date(),
5242
5372
  diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)({
5243
- truncate: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5244
- humanize: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5373
+ truncate: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5374
+ humanize: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5245
5375
  })))
5246
5376
  };
5247
5377
  }
@@ -5324,14 +5454,14 @@ var ClientServicesHost = class {
5324
5454
  this._systemService = new SystemServiceImpl({
5325
5455
  config: () => this._config,
5326
5456
  statusUpdate: this._statusUpdate,
5327
- getCurrentStatus: () => this.isOpen ? import_services14.SystemStatus.ACTIVE : import_services14.SystemStatus.INACTIVE,
5457
+ getCurrentStatus: () => this.isOpen ? import_services15.SystemStatus.ACTIVE : import_services15.SystemStatus.INACTIVE,
5328
5458
  getDiagnostics: () => {
5329
5459
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
5330
5460
  },
5331
5461
  onUpdateStatus: async (status) => {
5332
- if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
5462
+ if (!this.isOpen && status === import_services15.SystemStatus.ACTIVE) {
5333
5463
  await this._resourceLock?.acquire();
5334
- } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
5464
+ } else if (this.isOpen && status === import_services15.SystemStatus.INACTIVE) {
5335
5465
  await this._resourceLock?.release();
5336
5466
  }
5337
5467
  },
@@ -5341,7 +5471,7 @@ var ClientServicesHost = class {
5341
5471
  });
5342
5472
  this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5343
5473
  this._loggingService = new LoggingServiceImpl();
5344
- this._serviceRegistry = new ServiceRegistry(import_client_protocol4.clientServiceBundle, {
5474
+ this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
5345
5475
  SystemService: this._systemService,
5346
5476
  TracingService: this._tracingService
5347
5477
  });
@@ -5372,7 +5502,7 @@ var ClientServicesHost = class {
5372
5502
  initialize({ config, ...options }) {
5373
5503
  (0, import_invariant15.invariant)(!this._open, "service host is open", {
5374
5504
  F: __dxlog_file18,
5375
- L: 197,
5505
+ L: 198,
5376
5506
  S: this,
5377
5507
  A: [
5378
5508
  "!this._open",
@@ -5381,14 +5511,14 @@ var ClientServicesHost = class {
5381
5511
  });
5382
5512
  (0, import_log13.log)("initializing...", void 0, {
5383
5513
  F: __dxlog_file18,
5384
- L: 198,
5514
+ L: 199,
5385
5515
  S: this,
5386
5516
  C: (f, a) => f(...a)
5387
5517
  });
5388
5518
  if (config) {
5389
5519
  (0, import_invariant15.invariant)(!this._config, "config already set", {
5390
5520
  F: __dxlog_file18,
5391
- L: 201,
5521
+ L: 202,
5392
5522
  S: this,
5393
5523
  A: [
5394
5524
  "!this._config",
@@ -5403,7 +5533,7 @@ var ClientServicesHost = class {
5403
5533
  if (!options.signalManager) {
5404
5534
  import_log13.log.warn("running signaling without telemetry metadata.", void 0, {
5405
5535
  F: __dxlog_file18,
5406
- L: 209,
5536
+ L: 210,
5407
5537
  S: this,
5408
5538
  C: (f, a) => f(...a)
5409
5539
  });
@@ -5414,7 +5544,7 @@ var ClientServicesHost = class {
5414
5544
  this._signalManager = signalManager;
5415
5545
  (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
5416
5546
  F: __dxlog_file18,
5417
- L: 220,
5547
+ L: 221,
5418
5548
  S: this,
5419
5549
  A: [
5420
5550
  "!this._networkManager",
@@ -5428,7 +5558,7 @@ var ClientServicesHost = class {
5428
5558
  });
5429
5559
  (0, import_log13.log)("initialized", void 0, {
5430
5560
  F: __dxlog_file18,
5431
- L: 227,
5561
+ L: 228,
5432
5562
  S: this,
5433
5563
  C: (f, a) => f(...a)
5434
5564
  });
@@ -5437,18 +5567,18 @@ var ClientServicesHost = class {
5437
5567
  if (this._open) {
5438
5568
  return;
5439
5569
  }
5440
- const traceId = import_keys11.PublicKey.random().toHex();
5570
+ const traceId = import_keys12.PublicKey.random().toHex();
5441
5571
  import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5442
5572
  id: traceId
5443
5573
  }), {
5444
5574
  F: __dxlog_file18,
5445
- L: 238,
5575
+ L: 239,
5446
5576
  S: this,
5447
5577
  C: (f, a) => f(...a)
5448
5578
  });
5449
5579
  (0, import_invariant15.invariant)(this._config, "config not set", {
5450
5580
  F: __dxlog_file18,
5451
- L: 240,
5581
+ L: 241,
5452
5582
  S: this,
5453
5583
  A: [
5454
5584
  "this._config",
@@ -5457,7 +5587,7 @@ var ClientServicesHost = class {
5457
5587
  });
5458
5588
  (0, import_invariant15.invariant)(this._storage, "storage not set", {
5459
5589
  F: __dxlog_file18,
5460
- L: 241,
5590
+ L: 242,
5461
5591
  S: this,
5462
5592
  A: [
5463
5593
  "this._storage",
@@ -5466,7 +5596,7 @@ var ClientServicesHost = class {
5466
5596
  });
5467
5597
  (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
5468
5598
  F: __dxlog_file18,
5469
- L: 242,
5599
+ L: 243,
5470
5600
  S: this,
5471
5601
  A: [
5472
5602
  "this._signalManager",
@@ -5475,7 +5605,7 @@ var ClientServicesHost = class {
5475
5605
  });
5476
5606
  (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
5477
5607
  F: __dxlog_file18,
5478
- L: 243,
5608
+ L: 244,
5479
5609
  S: this,
5480
5610
  A: [
5481
5611
  "this._networkManager",
@@ -5487,7 +5617,7 @@ var ClientServicesHost = class {
5487
5617
  lockKey: this._resourceLock?.lockKey
5488
5618
  }, {
5489
5619
  F: __dxlog_file18,
5490
- L: 246,
5620
+ L: 247,
5491
5621
  S: this,
5492
5622
  C: (f, a) => f(...a)
5493
5623
  });
@@ -5498,20 +5628,22 @@ var ClientServicesHost = class {
5498
5628
  await this._resourceLock?.acquire();
5499
5629
  await this._loggingService.open();
5500
5630
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5631
+ this._queryService = new import_indexing2.QueryServiceImpl({
5632
+ indexer: this._serviceContext.indexer,
5633
+ automergeHost: this._serviceContext.automergeHost
5634
+ });
5635
+ await this._queryService.open(ctx);
5501
5636
  this._serviceRegistry.setServices({
5502
5637
  SystemService: this._systemService,
5503
5638
  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),
5639
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
5505
5640
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5506
5641
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
5507
5642
  await this._serviceContext.initialized.wait();
5508
5643
  return this._serviceContext.dataSpaceManager;
5509
5644
  }),
5510
5645
  DataService: new import_echo_pipeline5.DataServiceImpl(this._serviceContext.automergeHost),
5511
- IndexService: new import_indexing2.IndexServiceImpl({
5512
- indexer: this._serviceContext.indexer,
5513
- automergeHost: this._serviceContext.automergeHost
5514
- }),
5646
+ QueryService: this._queryService,
5515
5647
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5516
5648
  LoggingService: this._loggingService,
5517
5649
  TracingService: this._tracingService,
@@ -5523,30 +5655,12 @@ var ClientServicesHost = class {
5523
5655
  })
5524
5656
  });
5525
5657
  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
5658
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5545
5659
  if (devtoolsProxy) {
5546
5660
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
5547
5661
  url: devtoolsProxy,
5548
5662
  requested: {},
5549
- exposed: import_client_protocol4.clientServiceBundle,
5663
+ exposed: import_client_protocol5.clientServiceBundle,
5550
5664
  handlers: this.services
5551
5665
  });
5552
5666
  void this._devtoolsProxy.open();
@@ -5560,7 +5674,7 @@ var ClientServicesHost = class {
5560
5674
  deviceKey
5561
5675
  }, {
5562
5676
  F: __dxlog_file18,
5563
- L: 335,
5677
+ L: 330,
5564
5678
  S: this,
5565
5679
  C: (f, a) => f(...a)
5566
5680
  });
@@ -5568,7 +5682,7 @@ var ClientServicesHost = class {
5568
5682
  id: traceId
5569
5683
  }), {
5570
5684
  F: __dxlog_file18,
5571
- L: 336,
5685
+ L: 331,
5572
5686
  S: this,
5573
5687
  C: (f, a) => f(...a)
5574
5688
  });
@@ -5582,7 +5696,7 @@ var ClientServicesHost = class {
5582
5696
  deviceKey
5583
5697
  }, {
5584
5698
  F: __dxlog_file18,
5585
- L: 347,
5699
+ L: 342,
5586
5700
  S: this,
5587
5701
  C: (f, a) => f(...a)
5588
5702
  });
@@ -5592,6 +5706,7 @@ var ClientServicesHost = class {
5592
5706
  SystemService: this._systemService
5593
5707
  });
5594
5708
  await this._loggingService.close();
5709
+ await this._queryService.close();
5595
5710
  await this._serviceContext.close();
5596
5711
  await this._level?.close();
5597
5712
  this._open = false;
@@ -5600,24 +5715,24 @@ var ClientServicesHost = class {
5600
5715
  deviceKey
5601
5716
  }, {
5602
5717
  F: __dxlog_file18,
5603
- L: 356,
5718
+ L: 352,
5604
5719
  S: this,
5605
5720
  C: (f, a) => f(...a)
5606
5721
  });
5607
5722
  }
5608
5723
  async reset() {
5609
- const traceId = import_keys11.PublicKey.random().toHex();
5724
+ const traceId = import_keys12.PublicKey.random().toHex();
5610
5725
  import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5611
5726
  id: traceId
5612
5727
  }), {
5613
5728
  F: __dxlog_file18,
5614
- L: 361,
5729
+ L: 357,
5615
5730
  S: this,
5616
5731
  C: (f, a) => f(...a)
5617
5732
  });
5618
5733
  (0, import_log13.log)("resetting...", void 0, {
5619
5734
  F: __dxlog_file18,
5620
- L: 363,
5735
+ L: 359,
5621
5736
  S: this,
5622
5737
  C: (f, a) => f(...a)
5623
5738
  });
@@ -5625,7 +5740,7 @@ var ClientServicesHost = class {
5625
5740
  await this._storage.reset();
5626
5741
  (0, import_log13.log)("reset", void 0, {
5627
5742
  F: __dxlog_file18,
5628
- L: 366,
5743
+ L: 362,
5629
5744
  S: this,
5630
5745
  C: (f, a) => f(...a)
5631
5746
  });
@@ -5633,7 +5748,7 @@ var ClientServicesHost = class {
5633
5748
  id: traceId
5634
5749
  }), {
5635
5750
  F: __dxlog_file18,
5636
- L: 367,
5751
+ L: 363,
5637
5752
  S: this,
5638
5753
  C: (f, a) => f(...a)
5639
5754
  });
@@ -5646,7 +5761,7 @@ var ClientServicesHost = class {
5646
5761
  const automergeIndex = space.automergeSpaceState.rootUrl;
5647
5762
  (0, import_invariant15.invariant)(automergeIndex, void 0, {
5648
5763
  F: __dxlog_file18,
5649
- L: 379,
5764
+ L: 375,
5650
5765
  S: this,
5651
5766
  A: [
5652
5767
  "automergeIndex",
@@ -5657,16 +5772,16 @@ var ClientServicesHost = class {
5657
5772
  await document.whenReady();
5658
5773
  const properties = {
5659
5774
  system: {
5660
- type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema.getTypeReference)(import_client_protocol4.Properties))
5775
+ type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.Properties))
5661
5776
  },
5662
5777
  data: {
5663
- [import_client_protocol4.defaultKey]: identity.identityKey.toHex()
5778
+ [import_client_protocol5.defaultKey]: identity.identityKey.toHex()
5664
5779
  },
5665
5780
  meta: {
5666
5781
  keys: []
5667
5782
  }
5668
5783
  };
5669
- const propertiesId = import_keys11.PublicKey.random().toHex();
5784
+ const propertiesId = import_keys12.PublicKey.random().toHex();
5670
5785
  document.change((doc) => {
5671
5786
  (0, import_util9.assignDeep)(doc, [
5672
5787
  "objects",
@@ -5701,7 +5816,7 @@ var DiagnosticsCollector = class {
5701
5816
  }
5702
5817
  static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5703
5818
  const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5704
- keys: options.humanize ? import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5819
+ keys: options.humanize ? import_services14.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services14.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5705
5820
  });
5706
5821
  const clientDiagnostics = {
5707
5822
  config,
@@ -5741,6 +5856,7 @@ var findConfigs = () => {
5741
5856
  IdentityManager,
5742
5857
  IdentityServiceImpl,
5743
5858
  InvitationsHandler,
5859
+ InvitationsManager,
5744
5860
  InvitationsServiceImpl,
5745
5861
  Lock,
5746
5862
  ServiceContext,
@@ -5765,4 +5881,4 @@ var findConfigs = () => {
5765
5881
  subscribeToSpaces,
5766
5882
  subscribeToSwarmInfo
5767
5883
  });
5768
- //# sourceMappingURL=chunk-DQMGKBOV.cjs.map
5884
+ //# sourceMappingURL=chunk-2EUUFY7P.cjs.map