@dxos/client-services 0.1.39 → 0.1.40

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 (29) hide show
  1. package/dist/lib/browser/{chunk-2DGNNQWS.mjs → chunk-LGMYP2WL.mjs} +679 -569
  2. package/dist/lib/browser/chunk-LGMYP2WL.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +14 -14
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/index.cjs +721 -611
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +725 -621
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +54 -0
  13. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -0
  14. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -1
  15. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/invitations-service.d.ts +8 -3
  17. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  19. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  20. package/package.json +30 -30
  21. package/src/packlets/invitations/invitation-extension.ts +211 -0
  22. package/src/packlets/invitations/invitations-handler.ts +54 -123
  23. package/src/packlets/invitations/invitations-service.ts +106 -137
  24. package/src/packlets/services/utils.ts +3 -3
  25. package/src/packlets/testing/test-builder.ts +9 -7
  26. package/src/packlets/vault/iframe-host-runtime.ts +3 -3
  27. package/src/packlets/vault/iframe-proxy-runtime.ts +11 -3
  28. package/src/packlets/vault/worker-runtime.ts +3 -3
  29. package/dist/lib/browser/chunk-2DGNNQWS.mjs.map +0 -7
@@ -77,12 +77,12 @@ var import_network_manager6 = require("@dxos/network-manager");
77
77
  var import_random_access_storage2 = require("@dxos/random-access-storage");
78
78
 
79
79
  // packages/sdk/client-services/src/packlets/services/service-host.ts
80
- var import_node_assert13 = __toESM(require("node:assert"));
81
- var import_async18 = require("@dxos/async");
80
+ var import_node_assert14 = __toESM(require("node:assert"));
81
+ var import_async20 = require("@dxos/async");
82
82
  var import_client8 = require("@dxos/client");
83
83
  var import_echo_pipeline5 = require("@dxos/echo-pipeline");
84
- var import_log16 = require("@dxos/log");
85
- var import_protocols7 = require("@dxos/protocols");
84
+ var import_log18 = require("@dxos/log");
85
+ var import_protocols8 = require("@dxos/protocols");
86
86
  var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
87
87
 
88
88
  // packages/sdk/client-services/src/packlets/deprecated/tracing.ts
@@ -1040,18 +1040,236 @@ var DeviceInvitationProtocol = class {
1040
1040
  };
1041
1041
 
1042
1042
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1043
+ var import_node_assert6 = __toESM(require("node:assert"));
1044
+ var import_async8 = require("@dxos/async");
1045
+ var import_client = require("@dxos/client");
1046
+ var import_context4 = require("@dxos/context");
1047
+ var import_credentials8 = require("@dxos/credentials");
1048
+ var import_errors2 = require("@dxos/errors");
1049
+ var import_keys7 = require("@dxos/keys");
1050
+ var import_log5 = require("@dxos/log");
1051
+ var import_network_manager = require("@dxos/network-manager");
1052
+ var import_protocols4 = require("@dxos/protocols");
1053
+ var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1054
+ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
1055
+
1056
+ // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
1043
1057
  var import_node_assert5 = __toESM(require("node:assert"));
1044
1058
  var import_async7 = require("@dxos/async");
1045
- var import_client = require("@dxos/client");
1046
1059
  var import_context3 = require("@dxos/context");
1047
- var import_credentials8 = require("@dxos/credentials");
1060
+ var import_errors = require("@dxos/errors");
1048
1061
  var import_keys6 = require("@dxos/keys");
1049
1062
  var import_log4 = require("@dxos/log");
1050
- var import_network_manager = require("@dxos/network-manager");
1051
1063
  var import_protocols3 = require("@dxos/protocols");
1052
- var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1053
1064
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
1054
1065
  var import_teleport = require("@dxos/teleport");
1066
+ var OPTIONS_TIMEOUT = 1e4;
1067
+ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1068
+ constructor(_callbacks) {
1069
+ super({
1070
+ requested: {
1071
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1072
+ },
1073
+ exposed: {
1074
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1075
+ }
1076
+ });
1077
+ this._callbacks = _callbacks;
1078
+ this._ctx = new import_context3.Context();
1079
+ this._remoteOptionsTrigger = new import_async7.Trigger();
1080
+ }
1081
+ async getHandlers() {
1082
+ return {
1083
+ // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1084
+ // Perhaps in the future we will have more complex logic here.
1085
+ InvitationHostService: {
1086
+ options: async (options) => {
1087
+ (0, import_node_assert5.default)(!this._remoteOptions, "Remote options already set.");
1088
+ this._remoteOptions = options;
1089
+ this._remoteOptionsTrigger.wake();
1090
+ },
1091
+ introduce: async (request) => {
1092
+ const traceId = import_keys6.PublicKey.random().toHex();
1093
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
1094
+ id: traceId,
1095
+ parentId: this._traceParent
1096
+ }), {
1097
+ file: "invitation-extension.ts",
1098
+ line: 78,
1099
+ scope: this,
1100
+ callSite: (f, a) => f(...a)
1101
+ });
1102
+ const response = await this._callbacks.introduce(request);
1103
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
1104
+ id: traceId
1105
+ }), {
1106
+ file: "invitation-extension.ts",
1107
+ line: 83,
1108
+ scope: this,
1109
+ callSite: (f, a) => f(...a)
1110
+ });
1111
+ return response;
1112
+ },
1113
+ authenticate: async (request) => {
1114
+ const traceId = import_keys6.PublicKey.random().toHex();
1115
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
1116
+ id: traceId,
1117
+ parentId: this._traceParent
1118
+ }), {
1119
+ file: "invitation-extension.ts",
1120
+ line: 89,
1121
+ scope: this,
1122
+ callSite: (f, a) => f(...a)
1123
+ });
1124
+ const response = await this._callbacks.authenticate(request);
1125
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.end({
1126
+ id: traceId,
1127
+ data: {
1128
+ ...response
1129
+ }
1130
+ }), {
1131
+ file: "invitation-extension.ts",
1132
+ line: 94,
1133
+ scope: this,
1134
+ callSite: (f, a) => f(...a)
1135
+ });
1136
+ return response;
1137
+ },
1138
+ admit: async (request) => {
1139
+ const traceId = import_keys6.PublicKey.random().toHex();
1140
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
1141
+ id: traceId,
1142
+ parentId: this._traceParent
1143
+ }), {
1144
+ file: "invitation-extension.ts",
1145
+ line: 100,
1146
+ scope: this,
1147
+ callSite: (f, a) => f(...a)
1148
+ });
1149
+ const response = await this._callbacks.admit(request);
1150
+ import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.end({
1151
+ id: traceId
1152
+ }), {
1153
+ file: "invitation-extension.ts",
1154
+ line: 105,
1155
+ scope: this,
1156
+ callSite: (f, a) => f(...a)
1157
+ });
1158
+ return response;
1159
+ }
1160
+ }
1161
+ };
1162
+ }
1163
+ async onOpen(context) {
1164
+ var _a;
1165
+ await super.onOpen(context);
1166
+ try {
1167
+ await this.rpc.InvitationHostService.options({
1168
+ role: import_invitations.Options.Role.HOST
1169
+ });
1170
+ await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1171
+ timeout: OPTIONS_TIMEOUT
1172
+ }));
1173
+ if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.GUEST) {
1174
+ throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1175
+ expected: import_invitations.Options.Role.GUEST,
1176
+ remoteOptions: this._remoteOptions
1177
+ });
1178
+ }
1179
+ this._callbacks.onOpen();
1180
+ } catch (err) {
1181
+ this._callbacks.onError(err);
1182
+ }
1183
+ }
1184
+ async onClose() {
1185
+ await this._ctx.dispose();
1186
+ }
1187
+ };
1188
+ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1189
+ constructor(_callbacks) {
1190
+ super({
1191
+ requested: {
1192
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1193
+ },
1194
+ exposed: {
1195
+ InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1196
+ }
1197
+ });
1198
+ this._callbacks = _callbacks;
1199
+ this._ctx = new import_context3.Context();
1200
+ this._remoteOptionsTrigger = new import_async7.Trigger();
1201
+ }
1202
+ async getHandlers() {
1203
+ return {
1204
+ InvitationHostService: {
1205
+ options: async (options) => {
1206
+ (0, import_node_assert5.default)(!this._remoteOptions, "Remote options already set.");
1207
+ this._remoteOptions = options;
1208
+ this._remoteOptionsTrigger.wake();
1209
+ },
1210
+ introduce: () => {
1211
+ throw new Error("Method not allowed.");
1212
+ },
1213
+ authenticate: () => {
1214
+ throw new Error("Method not allowed.");
1215
+ },
1216
+ admit: () => {
1217
+ throw new Error("Method not allowed.");
1218
+ }
1219
+ }
1220
+ };
1221
+ }
1222
+ async onOpen(context) {
1223
+ var _a;
1224
+ await super.onOpen(context);
1225
+ try {
1226
+ (0, import_log4.log)("begin options", {}, {
1227
+ file: "invitation-extension.ts",
1228
+ line: 189,
1229
+ scope: this,
1230
+ callSite: (f, a) => f(...a)
1231
+ });
1232
+ await (0, import_context3.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
1233
+ role: import_invitations.Options.Role.GUEST
1234
+ }));
1235
+ await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
1236
+ timeout: OPTIONS_TIMEOUT
1237
+ }));
1238
+ (0, import_log4.log)("end options", {}, {
1239
+ file: "invitation-extension.ts",
1240
+ line: 192,
1241
+ scope: this,
1242
+ callSite: (f, a) => f(...a)
1243
+ });
1244
+ if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.HOST) {
1245
+ throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
1246
+ expected: import_invitations.Options.Role.HOST,
1247
+ remoteOptions: this._remoteOptions
1248
+ });
1249
+ }
1250
+ this._callbacks.onOpen(this._ctx);
1251
+ } catch (err) {
1252
+ (0, import_log4.log)("openError", err, {
1253
+ file: "invitation-extension.ts",
1254
+ line: 202,
1255
+ scope: this,
1256
+ callSite: (f, a) => f(...a)
1257
+ });
1258
+ this._callbacks.onError(err);
1259
+ }
1260
+ }
1261
+ async onClose() {
1262
+ (0, import_log4.log)("onClose", {}, {
1263
+ file: "invitation-extension.ts",
1264
+ line: 208,
1265
+ scope: this,
1266
+ callSite: (f, a) => f(...a)
1267
+ });
1268
+ await this._ctx.dispose();
1269
+ }
1270
+ };
1271
+
1272
+ // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1055
1273
  var MAX_OTP_ATTEMPTS = 3;
1056
1274
  var InvitationsHandler = class {
1057
1275
  constructor(_networkManager) {
@@ -1059,9 +1277,9 @@ var InvitationsHandler = class {
1059
1277
  }
1060
1278
  createInvitation(protocol, options) {
1061
1279
  var _a;
1062
- const { invitationId = import_keys6.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.INVITATION_TIMEOUT, swarmKey = import_keys6.PublicKey.random() } = options != null ? options : {};
1280
+ const { invitationId = import_keys7.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.INVITATION_TIMEOUT, swarmKey = import_keys7.PublicKey.random() } = options != null ? options : {};
1063
1281
  const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials8.generatePasscode)(import_client.AUTHENTICATION_CODE_LENGTH) : void 0;
1064
- (0, import_node_assert5.default)(protocol);
1282
+ (0, import_node_assert6.default)(protocol);
1065
1283
  const invitation = {
1066
1284
  invitationId,
1067
1285
  type,
@@ -1072,37 +1290,37 @@ var InvitationsHandler = class {
1072
1290
  timeout,
1073
1291
  ...protocol.getInvitationContext()
1074
1292
  };
1075
- const stream = new import_async7.PushStream();
1076
- const ctx = new import_context3.Context({
1293
+ const stream = new import_async8.PushStream();
1294
+ const ctx = new import_context4.Context({
1077
1295
  onError: (err) => {
1078
1296
  void ctx.dispose();
1079
1297
  stream.error(err);
1080
1298
  }
1081
1299
  });
1082
1300
  ctx.onDispose(() => {
1083
- (0, import_log4.log)("complete", {
1301
+ (0, import_log5.log)("complete", {
1084
1302
  ...protocol.toJSON()
1085
1303
  }, {
1086
1304
  file: "invitations-handler.ts",
1087
- line: 106,
1305
+ line: 99,
1088
1306
  scope: this,
1089
1307
  callSite: (f, a) => f(...a)
1090
1308
  });
1091
1309
  stream.complete();
1092
1310
  });
1093
1311
  const createExtension = () => {
1094
- const success = new import_async7.Trigger();
1312
+ const success = new import_async8.Trigger();
1095
1313
  let guestProfile;
1096
1314
  let authenticationPassed = false;
1097
1315
  let authenticationRetry = 0;
1098
1316
  const extension = new InvitationHostExtension({
1099
1317
  introduce: async ({ profile }) => {
1100
- (0, import_log4.log)("guest introduced itself", {
1318
+ (0, import_log5.log)("guest introduced itself", {
1101
1319
  guestProfile: profile,
1102
1320
  ...protocol.toJSON()
1103
1321
  }, {
1104
1322
  file: "invitations-handler.ts",
1105
- line: 119,
1323
+ line: 112,
1106
1324
  scope: this,
1107
1325
  callSite: (f, a) => f(...a)
1108
1326
  });
@@ -1117,33 +1335,33 @@ var InvitationsHandler = class {
1117
1335
  };
1118
1336
  },
1119
1337
  authenticate: async ({ authCode: code }) => {
1120
- (0, import_log4.log)("received authentication request", {
1338
+ (0, import_log5.log)("received authentication request", {
1121
1339
  authCode: code
1122
1340
  }, {
1123
1341
  file: "invitations-handler.ts",
1124
- line: 138,
1342
+ line: 131,
1125
1343
  scope: this,
1126
1344
  callSite: (f, a) => f(...a)
1127
1345
  });
1128
- let status = import_invitations.AuthenticationResponse.Status.OK;
1346
+ let status = import_invitations2.AuthenticationResponse.Status.OK;
1129
1347
  switch (invitation.authMethod) {
1130
1348
  case import_services3.Invitation.AuthMethod.NONE: {
1131
- (0, import_log4.log)("authentication not required", {}, {
1349
+ (0, import_log5.log)("authentication not required", {}, {
1132
1350
  file: "invitations-handler.ts",
1133
- line: 143,
1351
+ line: 136,
1134
1352
  scope: this,
1135
1353
  callSite: (f, a) => f(...a)
1136
1354
  });
1137
1355
  return {
1138
- status: import_invitations.AuthenticationResponse.Status.OK
1356
+ status: import_invitations2.AuthenticationResponse.Status.OK
1139
1357
  };
1140
1358
  }
1141
1359
  case import_services3.Invitation.AuthMethod.SHARED_SECRET: {
1142
1360
  if (invitation.authCode) {
1143
1361
  if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1144
- status = import_invitations.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1362
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1145
1363
  } else if (code !== invitation.authCode) {
1146
- status = import_invitations.AuthenticationResponse.Status.INVALID_OTP;
1364
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_OTP;
1147
1365
  } else {
1148
1366
  authenticationPassed = true;
1149
1367
  }
@@ -1151,15 +1369,15 @@ var InvitationsHandler = class {
1151
1369
  break;
1152
1370
  }
1153
1371
  default: {
1154
- import_log4.log.error("invalid authentication method", {
1372
+ import_log5.log.error("invalid authentication method", {
1155
1373
  authMethod: invitation.authMethod
1156
1374
  }, {
1157
1375
  file: "invitations-handler.ts",
1158
- line: 161,
1376
+ line: 154,
1159
1377
  scope: this,
1160
1378
  callSite: (f, a) => f(...a)
1161
1379
  });
1162
- status = import_invitations.AuthenticationResponse.Status.INTERNAL_ERROR;
1380
+ status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1163
1381
  break;
1164
1382
  }
1165
1383
  }
@@ -1174,7 +1392,7 @@ var InvitationsHandler = class {
1174
1392
  throw new Error("Not authenticated");
1175
1393
  }
1176
1394
  const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1177
- (0, import_node_assert5.default)(deviceKey);
1395
+ (0, import_node_assert6.default)(deviceKey);
1178
1396
  const admissionResponse = await protocol.admit(admissionRequest, guestProfile);
1179
1397
  success.wake(deviceKey);
1180
1398
  return admissionResponse;
@@ -1184,23 +1402,23 @@ var InvitationsHandler = class {
1184
1402
  }
1185
1403
  },
1186
1404
  onOpen: () => {
1187
- (0, import_async7.scheduleTask)(ctx, async () => {
1188
- const traceId = import_keys6.PublicKey.random().toHex();
1405
+ (0, import_async8.scheduleTask)(ctx, async () => {
1406
+ const traceId = import_keys7.PublicKey.random().toHex();
1189
1407
  try {
1190
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.begin({
1408
+ import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
1191
1409
  id: traceId,
1192
1410
  parentId: this._traceParent
1193
1411
  }), {
1194
1412
  file: "invitations-handler.ts",
1195
- line: 196,
1413
+ line: 189,
1196
1414
  scope: this,
1197
1415
  callSite: (f, a) => f(...a)
1198
1416
  });
1199
- (0, import_log4.log)("connected", {
1417
+ (0, import_log5.log)("connected", {
1200
1418
  ...protocol.toJSON()
1201
1419
  }, {
1202
1420
  file: "invitations-handler.ts",
1203
- line: 200,
1421
+ line: 193,
1204
1422
  scope: this,
1205
1423
  callSite: (f, a) => f(...a)
1206
1424
  });
@@ -1211,12 +1429,12 @@ var InvitationsHandler = class {
1211
1429
  const deviceKey = await success.wait({
1212
1430
  timeout
1213
1431
  });
1214
- (0, import_log4.log)("admitted guest", {
1432
+ (0, import_log5.log)("admitted guest", {
1215
1433
  guest: deviceKey,
1216
1434
  ...protocol.toJSON()
1217
1435
  }, {
1218
1436
  file: "invitations-handler.ts",
1219
- line: 203,
1437
+ line: 196,
1220
1438
  scope: this,
1221
1439
  callSite: (f, a) => f(...a)
1222
1440
  });
@@ -1224,21 +1442,21 @@ var InvitationsHandler = class {
1224
1442
  ...invitation,
1225
1443
  state: import_services3.Invitation.State.SUCCESS
1226
1444
  });
1227
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.end({
1445
+ import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
1228
1446
  id: traceId
1229
1447
  }), {
1230
1448
  file: "invitations-handler.ts",
1231
- line: 205,
1449
+ line: 198,
1232
1450
  scope: this,
1233
1451
  callSite: (f, a) => f(...a)
1234
1452
  });
1235
1453
  } catch (err) {
1236
- if (err instanceof import_async7.TimeoutError) {
1237
- (0, import_log4.log)("timeout", {
1454
+ if (err instanceof import_async8.TimeoutError) {
1455
+ (0, import_log5.log)("timeout", {
1238
1456
  ...protocol.toJSON()
1239
1457
  }, {
1240
1458
  file: "invitations-handler.ts",
1241
- line: 208,
1459
+ line: 201,
1242
1460
  scope: this,
1243
1461
  callSite: (f, a) => f(...a)
1244
1462
  });
@@ -1247,36 +1465,63 @@ var InvitationsHandler = class {
1247
1465
  state: import_services3.Invitation.State.TIMEOUT
1248
1466
  });
1249
1467
  } else {
1250
- import_log4.log.error("failed", err, {
1468
+ import_log5.log.error("failed", err, {
1251
1469
  file: "invitations-handler.ts",
1252
- line: 211,
1470
+ line: 204,
1253
1471
  scope: this,
1254
1472
  callSite: (f, a) => f(...a)
1255
1473
  });
1256
1474
  stream.error(err);
1257
1475
  }
1258
- import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols3.trace.error({
1476
+ import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
1259
1477
  id: traceId,
1260
1478
  error: err
1261
1479
  }), {
1262
1480
  file: "invitations-handler.ts",
1263
- line: 214,
1481
+ line: 207,
1264
1482
  scope: this,
1265
1483
  callSite: (f, a) => f(...a)
1266
1484
  });
1267
1485
  } finally {
1268
1486
  if (type !== import_services3.Invitation.Type.MULTIUSE) {
1269
- await (0, import_async7.sleep)(import_client.ON_CLOSE_DELAY);
1487
+ await (0, import_async8.sleep)(import_client.ON_CLOSE_DELAY);
1270
1488
  await ctx.dispose();
1271
1489
  }
1272
1490
  }
1273
1491
  });
1492
+ },
1493
+ onError: (err) => {
1494
+ if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
1495
+ return;
1496
+ }
1497
+ if (err instanceof import_async8.TimeoutError) {
1498
+ (0, import_log5.log)("timeout", {
1499
+ ...protocol.toJSON()
1500
+ }, {
1501
+ file: "invitations-handler.ts",
1502
+ line: 221,
1503
+ scope: this,
1504
+ callSite: (f, a) => f(...a)
1505
+ });
1506
+ stream.next({
1507
+ ...invitation,
1508
+ state: import_services3.Invitation.State.TIMEOUT
1509
+ });
1510
+ } else {
1511
+ import_log5.log.error("failed", err, {
1512
+ file: "invitations-handler.ts",
1513
+ line: 224,
1514
+ scope: this,
1515
+ callSite: (f, a) => f(...a)
1516
+ });
1517
+ stream.error(err);
1518
+ }
1274
1519
  }
1275
1520
  });
1276
1521
  extension._traceParent = this._traceParent;
1277
1522
  return extension;
1278
1523
  };
1279
- (0, import_async7.scheduleTask)(ctx, async () => {
1524
+ (0, import_async8.scheduleTask)(ctx, async () => {
1280
1525
  const topic = invitation.swarmKey;
1281
1526
  const swarmConnection = await this._networkManager.joinSwarm({
1282
1527
  topic,
@@ -1307,28 +1552,36 @@ var InvitationsHandler = class {
1307
1552
  }
1308
1553
  acceptInvitation(protocol, invitation) {
1309
1554
  const { timeout = import_client.INVITATION_TIMEOUT } = invitation;
1310
- (0, import_node_assert5.default)(protocol);
1311
- const authenticated = new import_async7.Trigger();
1312
- const stream = new import_async7.PushStream();
1313
- const ctx = new import_context3.Context({
1555
+ (0, import_node_assert6.default)(protocol);
1556
+ const authenticated = new import_async8.Trigger();
1557
+ let currentState;
1558
+ const stream = new import_async8.PushStream();
1559
+ const setState = (newData) => {
1560
+ (0, import_node_assert6.default)(newData.state !== void 0);
1561
+ currentState = newData.state;
1562
+ stream.next({
1563
+ ...invitation,
1564
+ ...newData
1565
+ });
1566
+ };
1567
+ const ctx = new import_context4.Context({
1314
1568
  onError: (err) => {
1315
- if (err instanceof import_async7.TimeoutError) {
1316
- (0, import_log4.log)("timeout", {
1569
+ if (err instanceof import_async8.TimeoutError) {
1570
+ (0, import_log5.log)("timeout", {
1317
1571
  ...protocol.toJSON()
1318
1572
  }, {
1319
1573
  file: "invitations-handler.ts",
1320
- line: 267,
1574
+ line: 279,
1321
1575
  scope: this,
1322
1576
  callSite: (f, a) => f(...a)
1323
1577
  });
1324
- stream.next({
1325
- ...invitation,
1578
+ setState({
1326
1579
  state: import_services3.Invitation.State.TIMEOUT
1327
1580
  });
1328
1581
  } else {
1329
- import_log4.log.warn("auth failed", err, {
1582
+ import_log5.log.warn("auth failed", err, {
1330
1583
  file: "invitations-handler.ts",
1331
- line: 270,
1584
+ line: 282,
1332
1585
  scope: this,
1333
1586
  callSite: (f, a) => f(...a)
1334
1587
  });
@@ -1338,11 +1591,11 @@ var InvitationsHandler = class {
1338
1591
  }
1339
1592
  });
1340
1593
  ctx.onDispose(() => {
1341
- (0, import_log4.log)("complete", {
1594
+ (0, import_log5.log)("complete", {
1342
1595
  ...protocol.toJSON()
1343
1596
  }, {
1344
1597
  file: "invitations-handler.ts",
1345
- line: 278,
1598
+ line: 290,
1346
1599
  scope: this,
1347
1600
  callSite: (f, a) => f(...a)
1348
1601
  });
@@ -1351,50 +1604,62 @@ var InvitationsHandler = class {
1351
1604
  const createExtension = () => {
1352
1605
  let connectionCount = 0;
1353
1606
  const extension = new InvitationGuestExtension({
1354
- onOpen: () => {
1355
- (0, import_async7.scheduleTask)(ctx, async () => {
1356
- const traceId = import_keys6.PublicKey.random().toHex();
1607
+ onOpen: (extensionCtx) => {
1608
+ extensionCtx.onDispose(async () => {
1609
+ (0, import_log5.log)("extension disposed", {
1610
+ currentState
1611
+ }, {
1612
+ file: "invitations-handler.ts",
1613
+ line: 300,
1614
+ scope: this,
1615
+ callSite: (f, a) => f(...a)
1616
+ });
1617
+ if (currentState !== import_services3.Invitation.State.SUCCESS) {
1618
+ stream.error(new Error("Remote peer disconnected."));
1619
+ }
1620
+ });
1621
+ (0, import_async8.scheduleTask)(ctx, async () => {
1622
+ const traceId = import_keys7.PublicKey.random().toHex();
1357
1623
  try {
1358
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.begin({
1624
+ import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
1359
1625
  id: traceId,
1360
1626
  parentId: this._traceParent
1361
1627
  }), {
1362
1628
  file: "invitations-handler.ts",
1363
- line: 290,
1629
+ line: 309,
1364
1630
  scope: this,
1365
1631
  callSite: (f, a) => f(...a)
1366
1632
  });
1367
1633
  if (++connectionCount > 1) {
1368
1634
  throw new Error(`multiple connections detected: ${connectionCount}`);
1369
1635
  }
1370
- (0, import_async7.scheduleTask)(ctx, () => ctx.raise(new import_async7.TimeoutError(timeout)), timeout);
1371
- (0, import_log4.log)("connected", {
1636
+ (0, import_async8.scheduleTask)(ctx, () => ctx.raise(new import_async8.TimeoutError(timeout)), timeout);
1637
+ (0, import_log5.log)("connected", {
1372
1638
  ...protocol.toJSON()
1373
1639
  }, {
1374
1640
  file: "invitations-handler.ts",
1375
- line: 301,
1641
+ line: 320,
1376
1642
  scope: this,
1377
1643
  callSite: (f, a) => f(...a)
1378
1644
  });
1379
- stream.next({
1380
- ...invitation,
1645
+ setState({
1381
1646
  state: import_services3.Invitation.State.CONNECTED
1382
1647
  });
1383
- (0, import_log4.log)("introduce", {
1648
+ (0, import_log5.log)("introduce", {
1384
1649
  ...protocol.toJSON()
1385
1650
  }, {
1386
1651
  file: "invitations-handler.ts",
1387
- line: 305,
1652
+ line: 324,
1388
1653
  scope: this,
1389
1654
  callSite: (f, a) => f(...a)
1390
1655
  });
1391
1656
  const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
1392
- (0, import_log4.log)("introduce response", {
1657
+ (0, import_log5.log)("introduce response", {
1393
1658
  ...protocol.toJSON(),
1394
1659
  response: introductionResponse
1395
1660
  }, {
1396
1661
  file: "invitations-handler.ts",
1397
- line: 309,
1662
+ line: 328,
1398
1663
  scope: this,
1399
1664
  callSite: (f, a) => f(...a)
1400
1665
  });
@@ -1404,44 +1669,42 @@ var InvitationsHandler = class {
1404
1669
  }
1405
1670
  if (isAuthenticationRequired(invitation)) {
1406
1671
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1407
- (0, import_log4.log)("guest waiting for authentication code...", {}, {
1672
+ (0, import_log5.log)("guest waiting for authentication code...", {}, {
1408
1673
  file: "invitations-handler.ts",
1409
- line: 318,
1674
+ line: 337,
1410
1675
  scope: this,
1411
1676
  callSite: (f, a) => f(...a)
1412
1677
  });
1413
- stream.next({
1414
- ...invitation,
1678
+ setState({
1415
1679
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1416
1680
  });
1417
1681
  const authCode = await authenticated.wait({
1418
1682
  timeout
1419
1683
  });
1420
- (0, import_log4.log)("sending authentication request", {}, {
1684
+ (0, import_log5.log)("sending authentication request", {}, {
1421
1685
  file: "invitations-handler.ts",
1422
- line: 322,
1686
+ line: 341,
1423
1687
  scope: this,
1424
1688
  callSite: (f, a) => f(...a)
1425
1689
  });
1426
- stream.next({
1427
- ...invitation,
1690
+ setState({
1428
1691
  state: import_services3.Invitation.State.AUTHENTICATING
1429
1692
  });
1430
1693
  const response = await extension.rpc.InvitationHostService.authenticate({
1431
1694
  authCode
1432
1695
  });
1433
- if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
1696
+ if (response.status === void 0 || response.status === import_invitations2.AuthenticationResponse.Status.OK) {
1434
1697
  break;
1435
1698
  }
1436
- if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
1699
+ if (response.status === import_invitations2.AuthenticationResponse.Status.INVALID_OTP) {
1437
1700
  if (attempt === MAX_OTP_ATTEMPTS) {
1438
1701
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1439
1702
  } else {
1440
- (0, import_log4.log)("retrying invalid code", {
1703
+ (0, import_log5.log)("retrying invalid code", {
1441
1704
  attempt
1442
1705
  }, {
1443
1706
  file: "invitations-handler.ts",
1444
- line: 333,
1707
+ line: 352,
1445
1708
  scope: this,
1446
1709
  callSite: (f, a) => f(...a)
1447
1710
  });
@@ -1450,72 +1713,69 @@ var InvitationsHandler = class {
1450
1713
  }
1451
1714
  }
1452
1715
  } else {
1453
- stream.next({
1454
- ...invitation,
1716
+ setState({
1455
1717
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1456
1718
  });
1457
1719
  }
1458
- (0, import_log4.log)("request admission", {
1720
+ (0, import_log5.log)("request admission", {
1459
1721
  ...protocol.toJSON()
1460
1722
  }, {
1461
1723
  file: "invitations-handler.ts",
1462
- line: 344,
1724
+ line: 363,
1463
1725
  scope: this,
1464
1726
  callSite: (f, a) => f(...a)
1465
1727
  });
1466
1728
  const admissionRequest = await protocol.createAdmissionRequest();
1467
1729
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
1468
1730
  const result = await protocol.accept(admissionResponse, admissionRequest);
1469
- (0, import_log4.log)("admitted by host", {
1731
+ (0, import_log5.log)("admitted by host", {
1470
1732
  ...protocol.toJSON()
1471
1733
  }, {
1472
1734
  file: "invitations-handler.ts",
1473
- line: 352,
1735
+ line: 371,
1474
1736
  scope: this,
1475
1737
  callSite: (f, a) => f(...a)
1476
1738
  });
1477
- stream.next({
1478
- ...invitation,
1739
+ setState({
1479
1740
  ...result,
1480
1741
  state: import_services3.Invitation.State.SUCCESS
1481
1742
  });
1482
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.end({
1743
+ import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
1483
1744
  id: traceId
1484
1745
  }), {
1485
1746
  file: "invitations-handler.ts",
1486
- line: 354,
1747
+ line: 373,
1487
1748
  scope: this,
1488
1749
  callSite: (f, a) => f(...a)
1489
1750
  });
1490
1751
  } catch (err) {
1491
- if (err instanceof import_async7.TimeoutError) {
1492
- (0, import_log4.log)("timeout", {
1752
+ if (err instanceof import_async8.TimeoutError) {
1753
+ (0, import_log5.log)("timeout", {
1493
1754
  ...protocol.toJSON()
1494
1755
  }, {
1495
1756
  file: "invitations-handler.ts",
1496
- line: 357,
1757
+ line: 376,
1497
1758
  scope: this,
1498
1759
  callSite: (f, a) => f(...a)
1499
1760
  });
1500
- stream.next({
1501
- ...invitation,
1761
+ setState({
1502
1762
  state: import_services3.Invitation.State.TIMEOUT
1503
1763
  });
1504
1764
  } else {
1505
- (0, import_log4.log)("auth failed", err, {
1765
+ (0, import_log5.log)("auth failed", err, {
1506
1766
  file: "invitations-handler.ts",
1507
- line: 360,
1767
+ line: 379,
1508
1768
  scope: this,
1509
1769
  callSite: (f, a) => f(...a)
1510
1770
  });
1511
1771
  stream.error(err);
1512
1772
  }
1513
- import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols3.trace.error({
1773
+ import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
1514
1774
  id: traceId,
1515
1775
  error: err
1516
1776
  }), {
1517
1777
  file: "invitations-handler.ts",
1518
- line: 363,
1778
+ line: 382,
1519
1779
  scope: this,
1520
1780
  callSite: (f, a) => f(...a)
1521
1781
  });
@@ -1523,24 +1783,49 @@ var InvitationsHandler = class {
1523
1783
  await ctx.dispose();
1524
1784
  }
1525
1785
  });
1786
+ },
1787
+ onError: (err) => {
1788
+ if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
1789
+ return;
1790
+ }
1791
+ if (err instanceof import_async8.TimeoutError) {
1792
+ (0, import_log5.log)("timeout", {
1793
+ ...protocol.toJSON()
1794
+ }, {
1795
+ file: "invitations-handler.ts",
1796
+ line: 393,
1797
+ scope: this,
1798
+ callSite: (f, a) => f(...a)
1799
+ });
1800
+ setState({
1801
+ state: import_services3.Invitation.State.TIMEOUT
1802
+ });
1803
+ } else {
1804
+ (0, import_log5.log)("auth failed", err, {
1805
+ file: "invitations-handler.ts",
1806
+ line: 396,
1807
+ scope: this,
1808
+ callSite: (f, a) => f(...a)
1809
+ });
1810
+ stream.error(err);
1811
+ }
1526
1812
  }
1527
1813
  });
1528
1814
  return extension;
1529
1815
  };
1530
- (0, import_async7.scheduleTask)(ctx, async () => {
1531
- (0, import_node_assert5.default)(invitation.swarmKey);
1816
+ (0, import_async8.scheduleTask)(ctx, async () => {
1817
+ (0, import_node_assert6.default)(invitation.swarmKey);
1532
1818
  const topic = invitation.swarmKey;
1533
1819
  const swarmConnection = await this._networkManager.joinSwarm({
1534
1820
  topic,
1535
- peerId: import_keys6.PublicKey.random(),
1821
+ peerId: import_keys7.PublicKey.random(),
1536
1822
  protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
1537
1823
  teleport.addExtension("dxos.halo.invitations", createExtension());
1538
1824
  }),
1539
1825
  topology: new import_network_manager.StarTopology(topic)
1540
1826
  });
1541
1827
  ctx.onDispose(() => swarmConnection.close());
1542
- stream.next({
1543
- ...invitation,
1828
+ setState({
1544
1829
  state: import_services3.Invitation.State.CONNECTING
1545
1830
  });
1546
1831
  });
@@ -1548,8 +1833,7 @@ var InvitationsHandler = class {
1548
1833
  initialInvitation: invitation,
1549
1834
  subscriber: stream.observable,
1550
1835
  onCancel: async () => {
1551
- stream.next({
1552
- ...invitation,
1836
+ setState({
1553
1837
  state: import_services3.Invitation.State.CANCELLED
1554
1838
  });
1555
1839
  await ctx.dispose();
@@ -1562,119 +1846,12 @@ var InvitationsHandler = class {
1562
1846
  }
1563
1847
  };
1564
1848
  var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services3.Invitation.AuthMethod.NONE;
1565
- var InvitationHostExtension = class extends import_teleport.RpcExtension {
1566
- constructor(_callbacks) {
1567
- super({
1568
- exposed: {
1569
- InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1570
- }
1571
- });
1572
- this._callbacks = _callbacks;
1573
- }
1574
- async getHandlers() {
1575
- return {
1576
- // TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
1577
- // Perhaps in the future we will have more complex logic here.
1578
- InvitationHostService: {
1579
- introduce: async (request) => {
1580
- const traceId = import_keys6.PublicKey.random().toHex();
1581
- import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
1582
- id: traceId,
1583
- parentId: this._traceParent
1584
- }), {
1585
- file: "invitations-handler.ts",
1586
- line: 442,
1587
- scope: this,
1588
- callSite: (f, a) => f(...a)
1589
- });
1590
- const response = await this._callbacks.introduce(request);
1591
- import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
1592
- id: traceId
1593
- }), {
1594
- file: "invitations-handler.ts",
1595
- line: 447,
1596
- scope: this,
1597
- callSite: (f, a) => f(...a)
1598
- });
1599
- return response;
1600
- },
1601
- authenticate: async (request) => {
1602
- const traceId = import_keys6.PublicKey.random().toHex();
1603
- import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
1604
- id: traceId,
1605
- parentId: this._traceParent
1606
- }), {
1607
- file: "invitations-handler.ts",
1608
- line: 453,
1609
- scope: this,
1610
- callSite: (f, a) => f(...a)
1611
- });
1612
- const response = await this._callbacks.authenticate(request);
1613
- import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.end({
1614
- id: traceId,
1615
- data: {
1616
- ...response
1617
- }
1618
- }), {
1619
- file: "invitations-handler.ts",
1620
- line: 458,
1621
- scope: this,
1622
- callSite: (f, a) => f(...a)
1623
- });
1624
- return response;
1625
- },
1626
- admit: async (request) => {
1627
- const traceId = import_keys6.PublicKey.random().toHex();
1628
- import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
1629
- id: traceId,
1630
- parentId: this._traceParent
1631
- }), {
1632
- file: "invitations-handler.ts",
1633
- line: 464,
1634
- scope: this,
1635
- callSite: (f, a) => f(...a)
1636
- });
1637
- const response = await this._callbacks.admit(request);
1638
- import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.end({
1639
- id: traceId
1640
- }), {
1641
- file: "invitations-handler.ts",
1642
- line: 469,
1643
- scope: this,
1644
- callSite: (f, a) => f(...a)
1645
- });
1646
- return response;
1647
- }
1648
- }
1649
- };
1650
- }
1651
- async onOpen(context) {
1652
- await super.onOpen(context);
1653
- this._callbacks.onOpen();
1654
- }
1655
- };
1656
- var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1657
- constructor(_callbacks) {
1658
- super({
1659
- requested: {
1660
- InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
1661
- }
1662
- });
1663
- this._callbacks = _callbacks;
1664
- }
1665
- async getHandlers() {
1666
- return {};
1667
- }
1668
- async onOpen(context) {
1669
- await super.onOpen(context);
1670
- this._callbacks.onOpen();
1671
- }
1672
- };
1673
1849
 
1674
1850
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1675
- var import_node_assert6 = __toESM(require("node:assert"));
1851
+ var import_node_assert7 = __toESM(require("node:assert"));
1852
+ var import_async9 = require("@dxos/async");
1676
1853
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
1677
- var import_log5 = require("@dxos/log");
1854
+ var import_log6 = require("@dxos/log");
1678
1855
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
1679
1856
  var InvitationsServiceImpl = class {
1680
1857
  constructor(_invitationsHandler, _getHandler) {
@@ -1682,203 +1859,74 @@ var InvitationsServiceImpl = class {
1682
1859
  this._getHandler = _getHandler;
1683
1860
  this._createInvitations = /* @__PURE__ */ new Map();
1684
1861
  this._acceptInvitations = /* @__PURE__ */ new Map();
1862
+ this._invitationCreated = new import_async9.Event();
1863
+ this._invitationAccepted = new import_async9.Event();
1864
+ this._removedCreated = new import_async9.Event();
1865
+ this._removedAccepted = new import_async9.Event();
1685
1866
  }
1686
1867
  // TODO(burdon): Guest/host label.
1687
1868
  getLoggingContext() {
1688
1869
  return {};
1689
1870
  }
1690
- createInvitation(invitation) {
1871
+ createInvitation(options) {
1872
+ let invitation;
1873
+ const existingInvitation = this._createInvitations.get(options.invitationId);
1874
+ if (existingInvitation) {
1875
+ invitation = existingInvitation;
1876
+ } else {
1877
+ const handler = this._getHandler(options);
1878
+ invitation = this._invitationsHandler.createInvitation(handler, options);
1879
+ this._createInvitations.set(invitation.get().invitationId, invitation);
1880
+ this._invitationCreated.emit(invitation.get());
1881
+ }
1691
1882
  return new import_codec_protobuf8.Stream(({ next, close }) => {
1692
- const handler = this._getHandler(invitation);
1693
- (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1694
- file: "invitations-service.ts",
1695
- line: 37,
1696
- scope: this,
1697
- callSite: (f, a) => f(...a)
1698
- });
1699
- let invitationId;
1700
- const observable = this._invitationsHandler.createInvitation(handler, invitation);
1701
- observable.subscribe((invitation2) => {
1702
- switch (invitation2.state) {
1703
- case import_services4.Invitation.State.CONNECTING: {
1704
- (0, import_node_assert6.default)(invitation2.invitationId);
1705
- invitationId = invitation2.invitationId;
1706
- this._createInvitations.set(invitation2.invitationId, observable);
1707
- invitation2.state = import_services4.Invitation.State.CONNECTING;
1708
- next(invitation2);
1709
- break;
1710
- }
1711
- case import_services4.Invitation.State.CONNECTED: {
1712
- (0, import_node_assert6.default)(invitation2.invitationId);
1713
- invitation2.state = import_services4.Invitation.State.CONNECTED;
1714
- next(invitation2);
1715
- break;
1716
- }
1717
- case import_services4.Invitation.State.READY_FOR_AUTHENTICATION: {
1718
- (0, import_node_assert6.default)(invitation2.invitationId);
1719
- invitation2.state = import_services4.Invitation.State.READY_FOR_AUTHENTICATION;
1720
- next(invitation2);
1721
- break;
1722
- }
1723
- case import_services4.Invitation.State.AUTHENTICATING: {
1724
- (0, import_node_assert6.default)(invitation2.invitationId);
1725
- invitation2.state = import_services4.Invitation.State.AUTHENTICATING;
1726
- next(invitation2);
1727
- break;
1728
- }
1729
- case import_services4.Invitation.State.SUCCESS: {
1730
- (0, import_node_assert6.default)(invitation2.invitationId);
1731
- invitation2.state = import_services4.Invitation.State.SUCCESS;
1732
- next(invitation2);
1733
- break;
1734
- }
1735
- case import_services4.Invitation.State.CANCELLED: {
1736
- (0, import_node_assert6.default)(invitationId);
1737
- invitation2.invitationId = invitationId;
1738
- invitation2.state = import_services4.Invitation.State.CANCELLED;
1739
- next(invitation2);
1740
- break;
1741
- }
1742
- case import_services4.Invitation.State.TIMEOUT: {
1743
- (0, import_node_assert6.default)(invitationId);
1744
- invitation2.invitationId = invitationId;
1745
- invitation2.state = import_services4.Invitation.State.TIMEOUT;
1746
- next(invitation2);
1747
- break;
1748
- }
1749
- }
1883
+ invitation.subscribe((invitation2) => {
1884
+ next(invitation2);
1750
1885
  }, (err) => {
1751
1886
  close(err);
1752
1887
  }, () => {
1753
1888
  close();
1889
+ this._createInvitations.delete(invitation.get().invitationId);
1754
1890
  });
1755
- return (err) => {
1756
- const context = this.getLoggingContext();
1757
- if (err) {
1758
- import_log5.log.warn("stream closed", {
1759
- ...context,
1760
- err
1761
- }, {
1762
- file: "invitations-service.ts",
1763
- line: 103,
1764
- scope: this,
1765
- callSite: (f, a) => f(...a)
1766
- });
1767
- } else {
1768
- (0, import_log5.log)("stream closed", context, {
1769
- file: "invitations-service.ts",
1770
- line: 105,
1771
- scope: this,
1772
- callSite: (f, a) => f(...a)
1773
- });
1774
- }
1775
- this._createInvitations.delete(invitation.invitationId);
1776
- };
1777
1891
  });
1778
1892
  }
1779
- acceptInvitation(invitation) {
1893
+ acceptInvitation(options) {
1894
+ let invitation;
1895
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
1896
+ if (existingInvitation) {
1897
+ invitation = existingInvitation;
1898
+ } else {
1899
+ const handler = this._getHandler(options);
1900
+ invitation = this._invitationsHandler.acceptInvitation(handler, options);
1901
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
1902
+ this._invitationAccepted.emit(invitation.get());
1903
+ }
1780
1904
  return new import_codec_protobuf8.Stream(({ next, close }) => {
1781
- (0, import_log5.log)("stream opened", this.getLoggingContext(), {
1782
- file: "invitations-service.ts",
1783
- line: 115,
1784
- scope: this,
1785
- callSite: (f, a) => f(...a)
1786
- });
1787
- const handler = this._getHandler(invitation);
1788
- let invitationId;
1789
- const observable = this._invitationsHandler.acceptInvitation(handler, invitation);
1790
- observable.subscribe((invitation2) => {
1791
- switch (invitation2.state) {
1792
- case import_services4.Invitation.State.CONNECTING: {
1793
- (0, import_node_assert6.default)(invitation2.invitationId);
1794
- invitationId = invitation2.invitationId;
1795
- this._acceptInvitations.set(invitation2.invitationId, observable);
1796
- invitation2.state = import_services4.Invitation.State.CONNECTING;
1797
- next(invitation2);
1798
- break;
1799
- }
1800
- case import_services4.Invitation.State.CONNECTED: {
1801
- (0, import_node_assert6.default)(invitation2.invitationId);
1802
- invitation2.state = import_services4.Invitation.State.CONNECTED;
1803
- next(invitation2);
1804
- break;
1805
- }
1806
- case import_services4.Invitation.State.READY_FOR_AUTHENTICATION: {
1807
- (0, import_node_assert6.default)(invitation2.invitationId);
1808
- invitation2.state = import_services4.Invitation.State.READY_FOR_AUTHENTICATION;
1809
- next(invitation2);
1810
- break;
1811
- }
1812
- case import_services4.Invitation.State.AUTHENTICATING: {
1813
- (0, import_node_assert6.default)(invitation2.invitationId);
1814
- invitation2.state = import_services4.Invitation.State.AUTHENTICATING;
1815
- next(invitation2);
1816
- break;
1817
- }
1818
- case import_services4.Invitation.State.SUCCESS: {
1819
- invitation2.state = import_services4.Invitation.State.SUCCESS;
1820
- next(invitation2);
1821
- break;
1822
- }
1823
- case import_services4.Invitation.State.CANCELLED: {
1824
- (0, import_node_assert6.default)(invitationId);
1825
- invitation2.invitationId = invitationId;
1826
- invitation2.state = import_services4.Invitation.State.CANCELLED;
1827
- next(invitation2);
1828
- break;
1829
- }
1830
- case import_services4.Invitation.State.TIMEOUT: {
1831
- (0, import_node_assert6.default)(invitationId);
1832
- invitation2.invitationId = invitationId;
1833
- invitation2.state = import_services4.Invitation.State.TIMEOUT;
1834
- next(invitation2);
1835
- break;
1836
- }
1837
- }
1905
+ invitation.subscribe((invitation2) => {
1906
+ next(invitation2);
1838
1907
  }, (err) => {
1839
1908
  close(err);
1840
1909
  }, () => {
1841
1910
  close();
1911
+ this._acceptInvitations.delete(invitation.get().invitationId);
1842
1912
  });
1843
- return (err) => {
1844
- const context = this.getLoggingContext();
1845
- if (err) {
1846
- import_log5.log.warn("stream closed", {
1847
- ...context,
1848
- err
1849
- }, {
1850
- file: "invitations-service.ts",
1851
- line: 181,
1852
- scope: this,
1853
- callSite: (f, a) => f(...a)
1854
- });
1855
- } else {
1856
- (0, import_log5.log)("stream closed", context, {
1857
- file: "invitations-service.ts",
1858
- line: 183,
1859
- scope: this,
1860
- callSite: (f, a) => f(...a)
1861
- });
1862
- }
1863
- this._acceptInvitations.delete(invitation.invitationId);
1864
- };
1865
1913
  });
1866
1914
  }
1867
1915
  async authenticate({ invitationId, authCode }) {
1868
- (0, import_log5.log)("authenticating...", {}, {
1916
+ (0, import_log6.log)("authenticating...", {}, {
1869
1917
  file: "invitations-service.ts",
1870
- line: 192,
1918
+ line: 103,
1871
1919
  scope: this,
1872
1920
  callSite: (f, a) => f(...a)
1873
1921
  });
1874
- (0, import_node_assert6.default)(invitationId);
1922
+ (0, import_node_assert7.default)(invitationId);
1875
1923
  const observable = this._acceptInvitations.get(invitationId);
1876
1924
  if (!observable) {
1877
- import_log5.log.warn("invalid invitation", {
1925
+ import_log6.log.warn("invalid invitation", {
1878
1926
  invitationId
1879
1927
  }, {
1880
1928
  file: "invitations-service.ts",
1881
- line: 196,
1929
+ line: 107,
1882
1930
  scope: this,
1883
1931
  callSite: (f, a) => f(...a)
1884
1932
  });
@@ -1887,35 +1935,91 @@ var InvitationsServiceImpl = class {
1887
1935
  }
1888
1936
  }
1889
1937
  async cancelInvitation({ invitationId }) {
1890
- var _a;
1891
- (0, import_log5.log)("cancelling...", {}, {
1938
+ (0, import_log6.log)("deleting...", {}, {
1892
1939
  file: "invitations-service.ts",
1893
- line: 203,
1940
+ line: 114,
1894
1941
  scope: this,
1895
1942
  callSite: (f, a) => f(...a)
1896
1943
  });
1897
- (0, import_node_assert6.default)(invitationId);
1898
- const observable = (_a = this._createInvitations.get(invitationId)) != null ? _a : this._acceptInvitations.get(invitationId);
1899
- if (!observable) {
1900
- import_log5.log.warn("invalid invitation", {
1944
+ (0, import_node_assert7.default)(invitationId);
1945
+ const created = this._createInvitations.get(invitationId);
1946
+ const accepted = this._acceptInvitations.get(invitationId);
1947
+ if (created) {
1948
+ await created.cancel();
1949
+ this._createInvitations.delete(invitationId);
1950
+ this._removedCreated.emit(created.get());
1951
+ } else if (accepted) {
1952
+ await accepted.cancel();
1953
+ this._acceptInvitations.delete(invitationId);
1954
+ this._removedAccepted.emit(accepted.get());
1955
+ } else {
1956
+ import_log6.log.warn("invalid invitation", {
1901
1957
  invitationId
1902
1958
  }, {
1903
1959
  file: "invitations-service.ts",
1904
- line: 207,
1960
+ line: 127,
1905
1961
  scope: this,
1906
1962
  callSite: (f, a) => f(...a)
1907
1963
  });
1908
- } else {
1909
- await (observable == null ? void 0 : observable.cancel());
1910
1964
  }
1911
1965
  }
1966
+ queryInvitations() {
1967
+ return new import_codec_protobuf8.Stream(({ next, ctx }) => {
1968
+ this._invitationCreated.on(ctx, (invitation) => {
1969
+ next({
1970
+ action: import_services4.QueryInvitationsResponse.Action.ADDED,
1971
+ type: import_services4.QueryInvitationsResponse.Type.CREATED,
1972
+ invitations: [
1973
+ invitation
1974
+ ]
1975
+ });
1976
+ });
1977
+ this._invitationAccepted.on(ctx, (invitation) => {
1978
+ next({
1979
+ action: import_services4.QueryInvitationsResponse.Action.ADDED,
1980
+ type: import_services4.QueryInvitationsResponse.Type.ACCEPTED,
1981
+ invitations: [
1982
+ invitation
1983
+ ]
1984
+ });
1985
+ });
1986
+ this._removedCreated.on(ctx, (invitation) => {
1987
+ next({
1988
+ action: import_services4.QueryInvitationsResponse.Action.REMOVED,
1989
+ type: import_services4.QueryInvitationsResponse.Type.CREATED,
1990
+ invitations: [
1991
+ invitation
1992
+ ]
1993
+ });
1994
+ });
1995
+ this._removedAccepted.on(ctx, (invitation) => {
1996
+ next({
1997
+ action: import_services4.QueryInvitationsResponse.Action.REMOVED,
1998
+ type: import_services4.QueryInvitationsResponse.Type.ACCEPTED,
1999
+ invitations: [
2000
+ invitation
2001
+ ]
2002
+ });
2003
+ });
2004
+ next({
2005
+ action: import_services4.QueryInvitationsResponse.Action.ADDED,
2006
+ type: import_services4.QueryInvitationsResponse.Type.CREATED,
2007
+ invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
2008
+ });
2009
+ next({
2010
+ action: import_services4.QueryInvitationsResponse.Action.ADDED,
2011
+ type: import_services4.QueryInvitationsResponse.Type.ACCEPTED,
2012
+ invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
2013
+ });
2014
+ });
2015
+ }
1912
2016
  };
1913
2017
 
1914
2018
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
1915
- var import_node_assert7 = __toESM(require("node:assert"));
2019
+ var import_node_assert8 = __toESM(require("node:assert"));
1916
2020
  var import_credentials9 = require("@dxos/credentials");
1917
2021
  var import_feed_store3 = require("@dxos/feed-store");
1918
- var import_log6 = require("@dxos/log");
2022
+ var import_log7 = require("@dxos/log");
1919
2023
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
1920
2024
  var SpaceInvitationProtocol = class {
1921
2025
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
@@ -1938,12 +2042,12 @@ var SpaceInvitationProtocol = class {
1938
2042
  }
1939
2043
  async admit(request, guestProfile) {
1940
2044
  var _a;
1941
- (0, import_node_assert7.default)(this._spaceKey);
2045
+ (0, import_node_assert8.default)(this._spaceKey);
1942
2046
  const space = await this._spaceManager.spaces.get(this._spaceKey);
1943
- (0, import_node_assert7.default)(space);
1944
- (0, import_node_assert7.default)(request.space);
2047
+ (0, import_node_assert8.default)(space);
2048
+ (0, import_node_assert8.default)(request.space);
1945
2049
  const { identityKey, deviceKey } = request.space;
1946
- (0, import_log6.log)("writing guest credentials", {
2050
+ (0, import_log7.log)("writing guest credentials", {
1947
2051
  host: this._signingContext.deviceKey,
1948
2052
  guest: deviceKey
1949
2053
  }, {
@@ -1953,9 +2057,9 @@ var SpaceInvitationProtocol = class {
1953
2057
  callSite: (f, a) => f(...a)
1954
2058
  });
1955
2059
  const credentials = await (0, import_credentials9.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1956
- (0, import_node_assert7.default)(credentials[0].credential);
2060
+ (0, import_node_assert8.default)(credentials[0].credential);
1957
2061
  const spaceMemberCredential = credentials[0].credential.credential;
1958
- (0, import_node_assert7.default)((0, import_credentials9.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2062
+ (0, import_node_assert8.default)((0, import_credentials9.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1959
2063
  await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
1960
2064
  return {
1961
2065
  space: {
@@ -1983,11 +2087,11 @@ var SpaceInvitationProtocol = class {
1983
2087
  };
1984
2088
  }
1985
2089
  async accept(response) {
1986
- (0, import_node_assert7.default)(response.space);
2090
+ (0, import_node_assert8.default)(response.space);
1987
2091
  const { credential, controlTimeframe, dataTimeframe } = response.space;
1988
2092
  const assertion = (0, import_credentials9.getCredentialAssertion)(credential);
1989
- (0, import_node_assert7.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
1990
- (0, import_node_assert7.default)(credential.subject.id.equals(this._signingContext.identityKey));
2093
+ (0, import_node_assert8.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2094
+ (0, import_node_assert8.default)(credential.subject.id.equals(this._signingContext.identityKey));
1991
2095
  await this._spaceManager.acceptSpace({
1992
2096
  spaceKey: assertion.spaceKey,
1993
2097
  genesisFeedKey: assertion.genesisFeedKey,
@@ -2024,37 +2128,37 @@ var NetworkServiceImpl = class {
2024
2128
  };
2025
2129
 
2026
2130
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2027
- var import_node_assert9 = __toESM(require("node:assert"));
2028
- var import_async10 = require("@dxos/async");
2131
+ var import_node_assert10 = __toESM(require("node:assert"));
2132
+ var import_async12 = require("@dxos/async");
2029
2133
  var import_client3 = require("@dxos/client");
2030
- var import_context6 = require("@dxos/context");
2134
+ var import_context7 = require("@dxos/context");
2031
2135
  var import_credentials11 = require("@dxos/credentials");
2032
2136
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
2033
- var import_keys9 = require("@dxos/keys");
2034
- var import_log9 = require("@dxos/log");
2035
- var import_protocols5 = require("@dxos/protocols");
2137
+ var import_keys10 = require("@dxos/keys");
2138
+ var import_log10 = require("@dxos/log");
2139
+ var import_protocols6 = require("@dxos/protocols");
2036
2140
  var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
2037
2141
  var import_util5 = require("@dxos/util");
2038
2142
 
2039
2143
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2040
- var import_async9 = require("@dxos/async");
2144
+ var import_async11 = require("@dxos/async");
2041
2145
  var import_client2 = require("@dxos/client");
2042
- var import_context5 = require("@dxos/context");
2146
+ var import_context6 = require("@dxos/context");
2043
2147
  var import_debug3 = require("@dxos/debug");
2044
2148
  var import_echo_pipeline = require("@dxos/echo-pipeline");
2045
- var import_errors = require("@dxos/errors");
2046
- var import_keys8 = require("@dxos/keys");
2047
- var import_log8 = require("@dxos/log");
2149
+ var import_errors3 = require("@dxos/errors");
2150
+ var import_keys9 = require("@dxos/keys");
2151
+ var import_log9 = require("@dxos/log");
2048
2152
  var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
2049
2153
  var import_util4 = require("@dxos/util");
2050
2154
 
2051
2155
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2052
- var import_node_assert8 = __toESM(require("node:assert"));
2053
- var import_async8 = require("@dxos/async");
2054
- var import_context4 = require("@dxos/context");
2055
- var import_keys7 = require("@dxos/keys");
2056
- var import_log7 = require("@dxos/log");
2057
- var import_protocols4 = require("@dxos/protocols");
2156
+ var import_node_assert9 = __toESM(require("node:assert"));
2157
+ var import_async10 = require("@dxos/async");
2158
+ var import_context5 = require("@dxos/context");
2159
+ var import_keys8 = require("@dxos/keys");
2160
+ var import_log8 = require("@dxos/log");
2161
+ var import_protocols5 = require("@dxos/protocols");
2058
2162
  var import_teleport2 = require("@dxos/teleport");
2059
2163
  var import_util3 = require("@dxos/util");
2060
2164
  var DEFAULT_RETRY_TIMEOUT = 1e3;
@@ -2062,11 +2166,11 @@ var DEFAULT_SUCCESS_DELAY = 1e3;
2062
2166
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2063
2167
  var NotarizationPlugin = class {
2064
2168
  constructor() {
2065
- this._ctx = new import_context4.Context();
2066
- this._extensionOpened = new import_async8.Event();
2169
+ this._ctx = new import_context5.Context();
2170
+ this._extensionOpened = new import_async10.Event();
2067
2171
  this._extensions = /* @__PURE__ */ new Set();
2068
- this._processedCredentials = new import_util3.ComplexSet(import_keys7.PublicKey.hash);
2069
- this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys7.PublicKey.hash);
2172
+ this._processedCredentials = new import_util3.ComplexSet(import_keys8.PublicKey.hash);
2173
+ this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys8.PublicKey.hash);
2070
2174
  }
2071
2175
  async open() {
2072
2176
  }
@@ -2077,7 +2181,7 @@ var NotarizationPlugin = class {
2077
2181
  * Request credentials to be notarized.
2078
2182
  */
2079
2183
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
2080
- (0, import_log7.log)("notarize", {
2184
+ (0, import_log8.log)("notarize", {
2081
2185
  credentials
2082
2186
  }, {
2083
2187
  file: "notarization-plugin.ts",
@@ -2085,11 +2189,11 @@ var NotarizationPlugin = class {
2085
2189
  scope: this,
2086
2190
  callSite: (f, a) => f(...a)
2087
2191
  });
2088
- (0, import_node_assert8.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2089
- const errors = new import_async8.Trigger();
2192
+ (0, import_node_assert9.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2193
+ const errors = new import_async10.Trigger();
2090
2194
  const ctx = this._ctx.derive({
2091
2195
  onError: (err) => {
2092
- import_log7.log.warn("Notarization error", {
2196
+ import_log8.log.warn("Notarization error", {
2093
2197
  err
2094
2198
  }, {
2095
2199
  file: "notarization-plugin.ts",
@@ -2103,8 +2207,8 @@ var NotarizationPlugin = class {
2103
2207
  });
2104
2208
  opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
2105
2209
  if (timeout !== 0) {
2106
- (0, import_async8.scheduleTask)(ctx, () => {
2107
- import_log7.log.warn("Notarization timeout", {
2210
+ (0, import_async10.scheduleTask)(ctx, () => {
2211
+ import_log8.log.warn("Notarization timeout", {
2108
2212
  timeout,
2109
2213
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
2110
2214
  }, {
@@ -2114,12 +2218,12 @@ var NotarizationPlugin = class {
2114
2218
  callSite: (f, a) => f(...a)
2115
2219
  });
2116
2220
  void ctx.dispose();
2117
- errors.throw(new import_async8.TimeoutError(timeout, "Notarization timed out"));
2221
+ errors.throw(new import_async10.TimeoutError(timeout, "Notarization timed out"));
2118
2222
  }, timeout);
2119
2223
  }
2120
2224
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
2121
2225
  const peersTried = /* @__PURE__ */ new Set();
2122
- const notarizeTask = new import_async8.DeferredTask(ctx, async () => {
2226
+ const notarizeTask = new import_async10.DeferredTask(ctx, async () => {
2123
2227
  try {
2124
2228
  if (this._extensions.size === 0) {
2125
2229
  return;
@@ -2128,7 +2232,7 @@ var NotarizationPlugin = class {
2128
2232
  ...this._extensions
2129
2233
  ].find((peer2) => !peersTried.has(peer2));
2130
2234
  if (!peer) {
2131
- import_log7.log.warn("Exhausted all peers to notarize with", {
2235
+ import_log8.log.warn("Exhausted all peers to notarize with", {
2132
2236
  retryIn: retryTimeout
2133
2237
  }, {
2134
2238
  file: "notarization-plugin.ts",
@@ -2137,11 +2241,11 @@ var NotarizationPlugin = class {
2137
2241
  callSite: (f, a) => f(...a)
2138
2242
  });
2139
2243
  peersTried.clear();
2140
- (0, import_async8.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2244
+ (0, import_async10.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
2141
2245
  return;
2142
2246
  }
2143
2247
  peersTried.add(peer);
2144
- (0, import_log7.log)("try notarizing", {
2248
+ (0, import_log8.log)("try notarizing", {
2145
2249
  peer: peer.localPeerId,
2146
2250
  credentialId: credentials.map((credential) => credential.id)
2147
2251
  }, {
@@ -2153,15 +2257,15 @@ var NotarizationPlugin = class {
2153
2257
  await peer.rpc.NotarizationService.notarize({
2154
2258
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2155
2259
  });
2156
- (0, import_log7.log)("success", {}, {
2260
+ (0, import_log8.log)("success", {}, {
2157
2261
  file: "notarization-plugin.ts",
2158
2262
  line: 142,
2159
2263
  scope: this,
2160
2264
  callSite: (f, a) => f(...a)
2161
2265
  });
2162
- await (0, import_async8.sleep)(successDelay);
2266
+ await (0, import_async10.sleep)(successDelay);
2163
2267
  } catch (err) {
2164
- import_log7.log.warn("error notarizing (recoverable)", err, {
2268
+ import_log8.log.warn("error notarizing (recoverable)", err, {
2165
2269
  file: "notarization-plugin.ts",
2166
2270
  line: 145,
2167
2271
  scope: this,
@@ -2174,11 +2278,11 @@ var NotarizationPlugin = class {
2174
2278
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
2175
2279
  try {
2176
2280
  await Promise.race([
2177
- (0, import_context4.rejectOnDispose)(ctx),
2281
+ (0, import_context5.rejectOnDispose)(ctx),
2178
2282
  allNotarized,
2179
2283
  errors.wait()
2180
2284
  ]);
2181
- (0, import_log7.log)("done", {}, {
2285
+ (0, import_log8.log)("done", {}, {
2182
2286
  file: "notarization-plugin.ts",
2183
2287
  line: 155,
2184
2288
  scope: this,
@@ -2201,14 +2305,14 @@ var NotarizationPlugin = class {
2201
2305
  this._processCredentialsTriggers.delete(credential.id);
2202
2306
  }
2203
2307
  setWriter(writer) {
2204
- (0, import_node_assert8.default)(!this._writer, "Writer already set.");
2308
+ (0, import_node_assert9.default)(!this._writer, "Writer already set.");
2205
2309
  this._writer = writer;
2206
2310
  }
2207
2311
  async _waitUntilProcessed(id) {
2208
2312
  if (this._processedCredentials.has(id)) {
2209
2313
  return;
2210
2314
  }
2211
- await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async8.Trigger()).value.wait();
2315
+ await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async10.Trigger()).value.wait();
2212
2316
  }
2213
2317
  /**
2214
2318
  * Requests from other peers to notarize credentials.
@@ -2219,7 +2323,7 @@ var NotarizationPlugin = class {
2219
2323
  throw new Error("Writer not set");
2220
2324
  }
2221
2325
  for (const credential of (_a = request.credentials) != null ? _a : []) {
2222
- (0, import_node_assert8.default)(credential.id, "Credential must have an id");
2326
+ (0, import_node_assert9.default)(credential.id, "Credential must have an id");
2223
2327
  if (this._processedCredentials.has(credential.id)) {
2224
2328
  continue;
2225
2329
  }
@@ -2229,7 +2333,7 @@ var NotarizationPlugin = class {
2229
2333
  createExtension() {
2230
2334
  const extension = new NotarizationTeleportExtension({
2231
2335
  onOpen: async () => {
2232
- (0, import_log7.log)("extension opened", {
2336
+ (0, import_log8.log)("extension opened", {
2233
2337
  peer: extension.localPeerId
2234
2338
  }, {
2235
2339
  file: "notarization-plugin.ts",
@@ -2241,7 +2345,7 @@ var NotarizationPlugin = class {
2241
2345
  this._extensionOpened.emit();
2242
2346
  },
2243
2347
  onClose: async () => {
2244
- (0, import_log7.log)("extension closed", {
2348
+ (0, import_log8.log)("extension closed", {
2245
2349
  peer: extension.localPeerId
2246
2350
  }, {
2247
2351
  file: "notarization-plugin.ts",
@@ -2260,10 +2364,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
2260
2364
  constructor(_params) {
2261
2365
  super({
2262
2366
  requested: {
2263
- NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2367
+ NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2264
2368
  },
2265
2369
  exposed: {
2266
- NotarizationService: import_protocols4.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2370
+ NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2267
2371
  }
2268
2372
  });
2269
2373
  this._params = _params;
@@ -2301,9 +2405,9 @@ var __decorate = function(decorators, target, key, desc) {
2301
2405
  var AUTH_TIMEOUT2 = 3e4;
2302
2406
  var DataSpace = class DataSpace2 {
2303
2407
  constructor(params) {
2304
- this._ctx = new import_context5.Context();
2408
+ this._ctx = new import_context6.Context();
2305
2409
  this._state = import_client2.SpaceState.CLOSED;
2306
- this.stateUpdate = new import_async9.Event();
2410
+ this.stateUpdate = new import_async11.Event();
2307
2411
  var _a;
2308
2412
  this._inner = params.inner;
2309
2413
  this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
@@ -2324,7 +2428,7 @@ var DataSpace = class DataSpace2 {
2324
2428
  snapshotId: params.snapshotId
2325
2429
  });
2326
2430
  this.authVerifier = new TrustedKeySetAuthVerifier({
2327
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2431
+ trustedKeysProvider: () => new import_util4.ComplexSet(import_keys9.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2328
2432
  update: this._inner.stateUpdate,
2329
2433
  authTimeout: AUTH_TIMEOUT2
2330
2434
  });
@@ -2378,12 +2482,12 @@ var DataSpace = class DataSpace2 {
2378
2482
  * Initialize the data pipeline in a separate task.
2379
2483
  */
2380
2484
  initializeDataPipelineAsync() {
2381
- (0, import_async9.scheduleTask)(this._ctx, async () => {
2485
+ (0, import_async11.scheduleTask)(this._ctx, async () => {
2382
2486
  try {
2383
2487
  await this.initializeDataPipeline();
2384
2488
  } catch (err) {
2385
- if (err instanceof import_errors.CancelledError) {
2386
- (0, import_log8.log)("Data pipeline initialization cancelled", err, {
2489
+ if (err instanceof import_errors3.CancelledError) {
2490
+ (0, import_log9.log)("Data pipeline initialization cancelled", err, {
2387
2491
  file: "data-space.ts",
2388
2492
  line: 178,
2389
2493
  scope: this,
@@ -2391,7 +2495,7 @@ var DataSpace = class DataSpace2 {
2391
2495
  });
2392
2496
  return;
2393
2497
  }
2394
- import_log8.log.error("Error initializing data pipeline", err, {
2498
+ import_log9.log.error("Error initializing data pipeline", err, {
2395
2499
  file: "data-space.ts",
2396
2500
  line: 182,
2397
2501
  scope: this,
@@ -2403,7 +2507,7 @@ var DataSpace = class DataSpace2 {
2403
2507
  async initializeDataPipeline() {
2404
2508
  var _a, _b, _c, _d;
2405
2509
  if (this._state !== import_client2.SpaceState.INACTIVE) {
2406
- throw new import_errors.SystemError("Invalid operation");
2510
+ throw new import_errors3.SystemError("Invalid operation");
2407
2511
  }
2408
2512
  this._state = import_client2.SpaceState.INITIALIZING;
2409
2513
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
@@ -2411,7 +2515,7 @@ var DataSpace = class DataSpace2 {
2411
2515
  breakOnStall: false
2412
2516
  });
2413
2517
  await this._createWritableFeeds();
2414
- (0, import_log8.log)("Writable feeds created", {}, {
2518
+ (0, import_log9.log)("Writable feeds created", {}, {
2415
2519
  file: "data-space.ts",
2416
2520
  line: 200,
2417
2521
  scope: this,
@@ -2432,7 +2536,7 @@ var DataSpace = class DataSpace2 {
2432
2536
  return pipeline;
2433
2537
  }
2434
2538
  });
2435
- (0, import_log8.log)("waiting for data pipeline to reach target timeframe", {}, {
2539
+ (0, import_log9.log)("waiting for data pipeline to reach target timeframe", {}, {
2436
2540
  file: "data-space.ts",
2437
2541
  line: 220,
2438
2542
  scope: this,
@@ -2442,7 +2546,7 @@ var DataSpace = class DataSpace2 {
2442
2546
  ctx: this._ctx,
2443
2547
  breakOnStall: false
2444
2548
  });
2445
- (0, import_log8.log)("data pipeline ready", {}, {
2549
+ (0, import_log9.log)("data pipeline ready", {}, {
2446
2550
  file: "data-space.ts",
2447
2551
  line: 227,
2448
2552
  scope: this,
@@ -2501,7 +2605,7 @@ __decorate([
2501
2605
  (0, import_debug3.timed)(1e4)
2502
2606
  ], DataSpace.prototype, "_createWritableFeeds", null);
2503
2607
  DataSpace = __decorate([
2504
- (0, import_async9.trackLeaks)("open", "close")
2608
+ (0, import_async11.trackLeaks)("open", "close")
2505
2609
  ], DataSpace);
2506
2610
 
2507
2611
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
@@ -2525,24 +2629,24 @@ var DataSpaceManager = class DataSpaceManager2 {
2525
2629
  this._modelFactory = _modelFactory;
2526
2630
  this._feedStore = _feedStore;
2527
2631
  this._snapshotStore = _snapshotStore;
2528
- this._ctx = new import_context6.Context();
2529
- this.updated = new import_async10.Event();
2530
- this._spaces = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
2632
+ this._ctx = new import_context7.Context();
2633
+ this.updated = new import_async12.Event();
2634
+ this._spaces = new import_util5.ComplexMap(import_keys10.PublicKey.hash);
2531
2635
  this._isOpen = false;
2532
- this._instanceId = import_keys9.PublicKey.random().toHex();
2636
+ this._instanceId = import_keys10.PublicKey.random().toHex();
2533
2637
  }
2534
2638
  // TODO(burdon): Remove.
2535
2639
  get spaces() {
2536
2640
  return this._spaces;
2537
2641
  }
2538
2642
  async open() {
2539
- (0, import_log9.log)("open", {}, {
2643
+ (0, import_log10.log)("open", {}, {
2540
2644
  file: "data-space-manager.ts",
2541
2645
  line: 83,
2542
2646
  scope: this,
2543
2647
  callSite: (f, a) => f(...a)
2544
2648
  });
2545
- import_log9.log.trace("dxos.echo.data-space-manager", import_protocols5.trace.begin({
2649
+ import_log10.log.trace("dxos.echo.data-space-manager", import_protocols6.trace.begin({
2546
2650
  id: this._instanceId,
2547
2651
  parentId: this._traceParent
2548
2652
  }), {
@@ -2552,7 +2656,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2552
2656
  callSite: (f, a) => f(...a)
2553
2657
  });
2554
2658
  await this._metadataStore.load();
2555
- (0, import_log9.log)("metadata loaded", {
2659
+ (0, import_log10.log)("metadata loaded", {
2556
2660
  spaces: this._metadataStore.spaces.length
2557
2661
  }, {
2558
2662
  file: "data-space-manager.ts",
@@ -2561,7 +2665,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2561
2665
  callSite: (f, a) => f(...a)
2562
2666
  });
2563
2667
  for (const spaceMetadata of this._metadataStore.spaces) {
2564
- (0, import_log9.log)("load space", {
2668
+ (0, import_log10.log)("load space", {
2565
2669
  spaceMetadata
2566
2670
  }, {
2567
2671
  file: "data-space-manager.ts",
@@ -2576,7 +2680,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2576
2680
  this.updated.emit();
2577
2681
  }
2578
2682
  async close() {
2579
- (0, import_log9.log)("close", {}, {
2683
+ (0, import_log10.log)("close", {}, {
2580
2684
  file: "data-space-manager.ts",
2581
2685
  line: 100,
2582
2686
  scope: this,
@@ -2587,7 +2691,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2587
2691
  for (const space of this._spaces.values()) {
2588
2692
  await space.close();
2589
2693
  }
2590
- import_log9.log.trace("dxos.echo.data-space-manager", import_protocols5.trace.end({
2694
+ import_log10.log.trace("dxos.echo.data-space-manager", import_protocols6.trace.end({
2591
2695
  id: this._instanceId
2592
2696
  }), {
2593
2697
  file: "data-space-manager.ts",
@@ -2600,7 +2704,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2600
2704
  * Creates a new space writing the genesis credentials to the control feed.
2601
2705
  */
2602
2706
  async createSpace() {
2603
- (0, import_node_assert9.default)(this._isOpen, "Not open.");
2707
+ (0, import_node_assert10.default)(this._isOpen, "Not open.");
2604
2708
  const spaceKey = await this._keyring.createKey();
2605
2709
  const controlFeedKey = await this._keyring.createKey();
2606
2710
  const dataFeedKey = await this._keyring.createKey();
@@ -2610,7 +2714,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2610
2714
  controlFeedKey,
2611
2715
  dataFeedKey
2612
2716
  };
2613
- (0, import_log9.log)("creating space...", {
2717
+ (0, import_log10.log)("creating space...", {
2614
2718
  spaceKey
2615
2719
  }, {
2616
2720
  file: "data-space-manager.ts",
@@ -2622,7 +2726,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2622
2726
  const credentials = await (0, import_echo_pipeline2.spaceGenesis)(this._keyring, this._signingContext, space.inner);
2623
2727
  await this._metadataStore.addSpace(metadata);
2624
2728
  const memberCredential = credentials[1];
2625
- (0, import_node_assert9.default)((0, import_credentials11.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2729
+ (0, import_node_assert10.default)((0, import_credentials11.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2626
2730
  await this._signingContext.recordCredential(memberCredential);
2627
2731
  await space.initializeDataPipeline();
2628
2732
  this.updated.emit();
@@ -2630,7 +2734,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2630
2734
  }
2631
2735
  // TODO(burdon): Rename join space.
2632
2736
  async acceptSpace(opts) {
2633
- (0, import_log9.log)("accept space", {
2737
+ (0, import_log10.log)("accept space", {
2634
2738
  opts
2635
2739
  }, {
2636
2740
  file: "data-space-manager.ts",
@@ -2638,8 +2742,8 @@ var DataSpaceManager = class DataSpaceManager2 {
2638
2742
  scope: this,
2639
2743
  callSite: (f, a) => f(...a)
2640
2744
  });
2641
- (0, import_node_assert9.default)(this._isOpen, "Not open.");
2642
- (0, import_node_assert9.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2745
+ (0, import_node_assert10.default)(this._isOpen, "Not open.");
2746
+ (0, import_node_assert10.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2643
2747
  const metadata = {
2644
2748
  key: opts.spaceKey,
2645
2749
  genesisFeedKey: opts.genesisFeedKey,
@@ -2658,13 +2762,13 @@ var DataSpaceManager = class DataSpaceManager2 {
2658
2762
  * TODO(dmaretskyi): Consider removing.
2659
2763
  */
2660
2764
  async waitUntilSpaceReady(spaceKey) {
2661
- await (0, import_context6.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
2765
+ await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
2662
2766
  const space = this._spaces.get(spaceKey);
2663
2767
  return !!space && space.state === import_client3.SpaceState.READY;
2664
2768
  }));
2665
2769
  }
2666
2770
  async _constructSpace(metadata) {
2667
- (0, import_log9.log)("construct space", {
2771
+ (0, import_log10.log)("construct space", {
2668
2772
  metadata
2669
2773
  }, {
2670
2774
  file: "data-space-manager.ts",
@@ -2719,7 +2823,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2719
2823
  snapshotId: metadata.snapshot,
2720
2824
  callbacks: {
2721
2825
  beforeReady: async () => {
2722
- (0, import_log9.log)("before space ready", {
2826
+ (0, import_log10.log)("before space ready", {
2723
2827
  space: space.key
2724
2828
  }, {
2725
2829
  file: "data-space-manager.ts",
@@ -2730,7 +2834,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2730
2834
  this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseBackend.createDataServiceHost());
2731
2835
  },
2732
2836
  afterReady: async () => {
2733
- (0, import_log9.log)("after space ready", {
2837
+ (0, import_log10.log)("after space ready", {
2734
2838
  space: space.key,
2735
2839
  open: this._isOpen
2736
2840
  }, {
@@ -2757,27 +2861,27 @@ var DataSpaceManager = class DataSpaceManager2 {
2757
2861
  }
2758
2862
  };
2759
2863
  __decorate2([
2760
- import_async10.synchronized
2864
+ import_async12.synchronized
2761
2865
  ], DataSpaceManager.prototype, "open", null);
2762
2866
  __decorate2([
2763
- import_async10.synchronized
2867
+ import_async12.synchronized
2764
2868
  ], DataSpaceManager.prototype, "close", null);
2765
2869
  __decorate2([
2766
- import_async10.synchronized
2870
+ import_async12.synchronized
2767
2871
  ], DataSpaceManager.prototype, "createSpace", null);
2768
2872
  __decorate2([
2769
- import_async10.synchronized
2873
+ import_async12.synchronized
2770
2874
  ], DataSpaceManager.prototype, "acceptSpace", null);
2771
2875
  DataSpaceManager = __decorate2([
2772
- (0, import_async10.trackLeaks)("open", "close")
2876
+ (0, import_async12.trackLeaks)("open", "close")
2773
2877
  ], DataSpaceManager);
2774
2878
 
2775
2879
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2776
- var import_async11 = require("@dxos/async");
2880
+ var import_async13 = require("@dxos/async");
2777
2881
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
2778
2882
  var import_debug4 = require("@dxos/debug");
2779
2883
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
2780
- var import_log10 = require("@dxos/log");
2884
+ var import_log11 = require("@dxos/log");
2781
2885
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
2782
2886
  var import_util6 = require("@dxos/util");
2783
2887
  var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
@@ -2804,7 +2908,7 @@ var SpacesServiceImpl = class {
2804
2908
  const onUpdate = async () => {
2805
2909
  const dataSpaceManager = await this._getDataSpaceManager();
2806
2910
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
2807
- (0, import_log10.log)("update", {
2911
+ (0, import_log11.log)("update", {
2808
2912
  spaces
2809
2913
  }, {
2810
2914
  file: "spaces-service.ts",
@@ -2816,9 +2920,9 @@ var SpacesServiceImpl = class {
2816
2920
  spaces
2817
2921
  });
2818
2922
  };
2819
- (0, import_async11.scheduleTask)(ctx, async () => {
2923
+ (0, import_async13.scheduleTask)(ctx, async () => {
2820
2924
  const dataSpaceManager = await this._getDataSpaceManager();
2821
- const subscriptions = new import_async11.EventSubscriptions();
2925
+ const subscriptions = new import_async13.EventSubscriptions();
2822
2926
  ctx.onDispose(() => subscriptions.clear());
2823
2927
  const subscribeSpaces = () => {
2824
2928
  subscriptions.clear();
@@ -2853,7 +2957,7 @@ var SpacesServiceImpl = class {
2853
2957
  }
2854
2958
  subscribeMessages({ spaceKey, channel }) {
2855
2959
  return new import_codec_protobuf10.Stream(({ ctx, next }) => {
2856
- (0, import_async11.scheduleTask)(ctx, async () => {
2960
+ (0, import_async13.scheduleTask)(ctx, async () => {
2857
2961
  var _a;
2858
2962
  const dataSpaceManager = await this._getDataSpaceManager();
2859
2963
  const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
@@ -2874,7 +2978,7 @@ var SpacesServiceImpl = class {
2874
2978
  }
2875
2979
  });
2876
2980
  ctx.onDispose(() => processor.close());
2877
- (0, import_async11.scheduleTask)(ctx, () => processor.open());
2981
+ (0, import_async13.scheduleTask)(ctx, () => processor.open());
2878
2982
  });
2879
2983
  }
2880
2984
  async writeCredentials({ spaceKey, credentials }) {
@@ -2921,23 +3025,23 @@ var SpacesServiceImpl = class {
2921
3025
  var getChannelId = (channel) => `user-channel/${channel}`;
2922
3026
 
2923
3027
  // packages/sdk/client-services/src/packlets/storage/storage.ts
2924
- var import_errors2 = require("@dxos/errors");
3028
+ var import_errors4 = require("@dxos/errors");
2925
3029
  var import_config = require("@dxos/protocols/proto/dxos/config");
2926
3030
  var import_random_access_storage = require("@dxos/random-access-storage");
2927
3031
  var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
2928
3032
  var createStorageObjects = (config) => {
2929
3033
  const { path = "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
2930
3034
  if (persistent && storageType === StorageDriver.RAM) {
2931
- throw new import_errors2.InvalidConfigError("RAM storage cannot be used in persistent mode.");
3035
+ throw new import_errors4.InvalidConfigError("RAM storage cannot be used in persistent mode.");
2932
3036
  }
2933
3037
  if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
2934
- throw new import_errors2.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
3038
+ throw new import_errors4.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
2935
3039
  }
2936
3040
  if (persistent && keyStorage === StorageDriver.RAM) {
2937
- throw new import_errors2.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
3041
+ throw new import_errors4.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
2938
3042
  }
2939
3043
  if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
2940
- throw new import_errors2.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
3044
+ throw new import_errors4.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
2941
3045
  }
2942
3046
  return {
2943
3047
  storage: (0, import_random_access_storage.createStorage)({
@@ -3006,8 +3110,8 @@ var SystemServiceImpl = class {
3006
3110
  };
3007
3111
 
3008
3112
  // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3009
- var import_async13 = require("@dxos/async");
3010
- var import_log11 = require("@dxos/log");
3113
+ var import_async15 = require("@dxos/async");
3114
+ var import_log12 = require("@dxos/log");
3011
3115
  var import_messaging = require("@dxos/messaging");
3012
3116
  var import_network_manager2 = require("@dxos/network-manager");
3013
3117
  var import_util7 = require("@dxos/util");
@@ -3066,15 +3170,15 @@ var ClientRpcServer = class {
3066
3170
  };
3067
3171
 
3068
3172
  // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3069
- var import_node_assert10 = __toESM(require("node:assert"));
3070
- var import_async12 = require("@dxos/async");
3173
+ var import_node_assert11 = __toESM(require("node:assert"));
3174
+ var import_async14 = require("@dxos/async");
3071
3175
  var import_client4 = require("@dxos/client");
3072
3176
  var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
3073
3177
  var import_rpc2 = require("@dxos/rpc");
3074
3178
  var ShellRuntimeImpl = class {
3075
3179
  constructor(_port) {
3076
3180
  this._port = _port;
3077
- this.layoutUpdate = new import_async12.Event();
3181
+ this.layoutUpdate = new import_async14.Event();
3078
3182
  this._layout = import_iframe.ShellLayout.DEFAULT;
3079
3183
  }
3080
3184
  get layout() {
@@ -3096,7 +3200,7 @@ var ShellRuntimeImpl = class {
3096
3200
  });
3097
3201
  }
3098
3202
  async setAppContext(context) {
3099
- (0, import_node_assert10.default)(this._appRpc, "runtime not open");
3203
+ (0, import_node_assert11.default)(this._appRpc, "runtime not open");
3100
3204
  await this._appRpc.rpc.AppService.setContext(context);
3101
3205
  }
3102
3206
  async open() {
@@ -3162,7 +3266,7 @@ var IFrameHostRuntime = class {
3162
3266
  }
3163
3267
  ]
3164
3268
  });
3165
- this._ready = new import_async13.Trigger();
3269
+ this._ready = new import_async15.Trigger();
3166
3270
  this._configProvider = configProvider;
3167
3271
  this._appPort = appPort;
3168
3272
  this._shellPort = shellPort;
@@ -3178,7 +3282,7 @@ var IFrameHostRuntime = class {
3178
3282
  }
3179
3283
  async start() {
3180
3284
  var _a;
3181
- (0, import_log11.log)("starting...", {}, {
3285
+ (0, import_log12.log)("starting...", {}, {
3182
3286
  file: "iframe-host-runtime.ts",
3183
3287
  line: 75,
3184
3288
  scope: this,
@@ -3186,15 +3290,13 @@ var IFrameHostRuntime = class {
3186
3290
  });
3187
3291
  try {
3188
3292
  this._config = await (0, import_util7.getAsyncValue)(this._configProvider);
3189
- const signalServer = this._config.get("runtime.services.signal.server");
3293
+ const signals = this._config.get("runtime.services.signaling");
3190
3294
  this._clientServices = new LocalClientServices({
3191
3295
  lockKey: LOCK_KEY,
3192
3296
  config: this._config,
3193
3297
  networkManager: new import_network_manager2.NetworkManager({
3194
3298
  log: true,
3195
- signalManager: signalServer ? new import_messaging.WebsocketSignalManager([
3196
- signalServer
3197
- ]) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
3299
+ signalManager: signals ? new import_messaging.WebsocketSignalManager(signals) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
3198
3300
  transportFactory: this._transportFactory
3199
3301
  })
3200
3302
  });
@@ -3229,7 +3331,7 @@ var IFrameHostRuntime = class {
3229
3331
  (_a = this._shellRuntime) == null ? void 0 : _a.open()
3230
3332
  ]);
3231
3333
  this._ready.wake(void 0);
3232
- (0, import_log11.log)("started", {}, {
3334
+ (0, import_log12.log)("started", {}, {
3233
3335
  file: "iframe-host-runtime.ts",
3234
3336
  line: 118,
3235
3337
  scope: this,
@@ -3237,7 +3339,7 @@ var IFrameHostRuntime = class {
3237
3339
  });
3238
3340
  } catch (err) {
3239
3341
  this._ready.wake(err);
3240
- import_log11.log.catch(err, {}, {
3342
+ import_log12.log.catch(err, {}, {
3241
3343
  file: "iframe-host-runtime.ts",
3242
3344
  line: 121,
3243
3345
  scope: this,
@@ -3247,7 +3349,7 @@ var IFrameHostRuntime = class {
3247
3349
  }
3248
3350
  async stop() {
3249
3351
  var _a;
3250
- (0, import_log11.log)("stopping...", {}, {
3352
+ (0, import_log12.log)("stopping...", {}, {
3251
3353
  file: "iframe-host-runtime.ts",
3252
3354
  line: 126,
3253
3355
  scope: this,
@@ -3256,7 +3358,7 @@ var IFrameHostRuntime = class {
3256
3358
  await this._clientRpc.close();
3257
3359
  await this._clientServices.close();
3258
3360
  await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3259
- (0, import_log11.log)("stopped", {}, {
3361
+ (0, import_log12.log)("stopped", {}, {
3260
3362
  file: "iframe-host-runtime.ts",
3261
3363
  line: 130,
3262
3364
  scope: this,
@@ -3265,17 +3367,19 @@ var IFrameHostRuntime = class {
3265
3367
  }
3266
3368
  };
3267
3369
  __decorate3([
3268
- import_log11.logInfo
3370
+ import_log12.logInfo
3269
3371
  ], IFrameHostRuntime.prototype, "origin", void 0);
3270
3372
 
3271
3373
  // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3272
3374
  var import_client5 = require("@dxos/client");
3375
+ var import_errors5 = require("@dxos/errors");
3376
+ var import_log13 = require("@dxos/log");
3273
3377
  var import_network_manager3 = require("@dxos/network-manager");
3274
3378
  var import_rpc3 = require("@dxos/rpc");
3275
3379
 
3276
3380
  // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3277
- var import_async14 = require("@dxos/async");
3278
- var import_log12 = require("@dxos/log");
3381
+ var import_async16 = require("@dxos/async");
3382
+ var import_log14 = require("@dxos/log");
3279
3383
  var __decorate4 = function(decorators, target, key, desc) {
3280
3384
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3281
3385
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3293,7 +3397,7 @@ var Message;
3293
3397
  var VaultResourceLock = class {
3294
3398
  constructor({ lockKey, onAcquire, onRelease }) {
3295
3399
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3296
- this._releaseTrigger = new import_async14.Trigger();
3400
+ this._releaseTrigger = new import_async16.Trigger();
3297
3401
  this._lockKey = lockKey;
3298
3402
  this._onAcquire = onAcquire;
3299
3403
  this._onRelease = onRelease;
@@ -3307,28 +3411,28 @@ var VaultResourceLock = class {
3307
3411
  message: Message.ACQUIRING
3308
3412
  });
3309
3413
  try {
3310
- (0, import_log12.log)("aquiring lock...", {}, {
3414
+ (0, import_log14.log)("aquiring lock...", {}, {
3311
3415
  file: "vault-resource-lock.ts",
3312
3416
  line: 44,
3313
3417
  scope: this,
3314
3418
  callSite: (f, a) => f(...a)
3315
3419
  });
3316
- await (0, import_async14.asyncTimeout)(this._requestLock(), 3e3);
3317
- (0, import_log12.log)("acquired lock", {}, {
3420
+ await (0, import_async16.asyncTimeout)(this._requestLock(), 3e3);
3421
+ (0, import_log14.log)("acquired lock", {}, {
3318
3422
  file: "vault-resource-lock.ts",
3319
3423
  line: 46,
3320
3424
  scope: this,
3321
3425
  callSite: (f, a) => f(...a)
3322
3426
  });
3323
3427
  } catch (e) {
3324
- (0, import_log12.log)("stealing lock...", {}, {
3428
+ (0, import_log14.log)("stealing lock...", {}, {
3325
3429
  file: "vault-resource-lock.ts",
3326
3430
  line: 48,
3327
3431
  scope: this,
3328
3432
  callSite: (f, a) => f(...a)
3329
3433
  });
3330
3434
  await this._requestLock(true);
3331
- (0, import_log12.log)("stolen lock", {}, {
3435
+ (0, import_log14.log)("stolen lock", {}, {
3332
3436
  file: "vault-resource-lock.ts",
3333
3437
  line: 50,
3334
3438
  scope: this,
@@ -3345,7 +3449,7 @@ var VaultResourceLock = class {
3345
3449
  }
3346
3450
  }
3347
3451
  async _requestLock(steal = false) {
3348
- (0, import_log12.log)("requesting lock...", {
3452
+ (0, import_log14.log)("requesting lock...", {
3349
3453
  steal
3350
3454
  }, {
3351
3455
  file: "vault-resource-lock.ts",
@@ -3353,23 +3457,23 @@ var VaultResourceLock = class {
3353
3457
  scope: this,
3354
3458
  callSite: (f, a) => f(...a)
3355
3459
  });
3356
- const acquired = new import_async14.Trigger();
3460
+ const acquired = new import_async16.Trigger();
3357
3461
  void navigator.locks.request(this._lockKey, {
3358
3462
  steal
3359
3463
  }, async () => {
3360
3464
  var _a, _b;
3361
3465
  await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3362
3466
  acquired.wake();
3363
- this._releaseTrigger = new import_async14.Trigger();
3467
+ this._releaseTrigger = new import_async16.Trigger();
3364
3468
  await this._releaseTrigger.wait();
3365
- (0, import_log12.log)("releasing lock...", {}, {
3469
+ (0, import_log14.log)("releasing lock...", {}, {
3366
3470
  file: "vault-resource-lock.ts",
3367
3471
  line: 74,
3368
3472
  scope: this,
3369
3473
  callSite: (f, a) => f(...a)
3370
3474
  });
3371
3475
  await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3372
- (0, import_log12.log)("released lock", {}, {
3476
+ (0, import_log14.log)("released lock", {}, {
3373
3477
  file: "vault-resource-lock.ts",
3374
3478
  line: 76,
3375
3479
  scope: this,
@@ -3380,7 +3484,7 @@ var VaultResourceLock = class {
3380
3484
  await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3381
3485
  });
3382
3486
  await acquired.wait();
3383
- (0, import_log12.log)("recieved lock", {
3487
+ (0, import_log14.log)("recieved lock", {
3384
3488
  steal
3385
3489
  }, {
3386
3490
  file: "vault-resource-lock.ts",
@@ -3391,20 +3495,20 @@ var VaultResourceLock = class {
3391
3495
  }
3392
3496
  };
3393
3497
  __decorate4([
3394
- import_log12.logInfo
3498
+ import_log14.logInfo
3395
3499
  ], VaultResourceLock.prototype, "lockKey", null);
3396
3500
 
3397
3501
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3398
- var import_async16 = require("@dxos/async");
3399
- var import_log14 = require("@dxos/log");
3502
+ var import_async18 = require("@dxos/async");
3503
+ var import_log16 = require("@dxos/log");
3400
3504
  var import_messaging2 = require("@dxos/messaging");
3401
3505
  var import_network_manager4 = require("@dxos/network-manager");
3402
3506
 
3403
3507
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
3404
- var import_node_assert11 = __toESM(require("node:assert"));
3405
- var import_async15 = require("@dxos/async");
3508
+ var import_node_assert12 = __toESM(require("node:assert"));
3509
+ var import_async17 = require("@dxos/async");
3406
3510
  var import_client6 = require("@dxos/client");
3407
- var import_log13 = require("@dxos/log");
3511
+ var import_log15 = require("@dxos/log");
3408
3512
  var import_rpc4 = require("@dxos/rpc");
3409
3513
  var import_util8 = require("@dxos/util");
3410
3514
  var __decorate5 = function(decorators, target, key, desc) {
@@ -3421,10 +3525,10 @@ var WorkerSession = class {
3421
3525
  constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
3422
3526
  heartbeatInterval: 1e3
3423
3527
  } }) {
3424
- this._startTrigger = new import_async15.Trigger();
3528
+ this._startTrigger = new import_async17.Trigger();
3425
3529
  this.onClose = new import_util8.Callback();
3426
- (0, import_node_assert11.default)(options);
3427
- (0, import_node_assert11.default)(serviceHost);
3530
+ (0, import_node_assert12.default)(options);
3531
+ (0, import_node_assert12.default)(serviceHost);
3428
3532
  this._options = options;
3429
3533
  this._serviceHost = serviceHost;
3430
3534
  const middleware = {
@@ -3471,7 +3575,7 @@ var WorkerSession = class {
3471
3575
  try {
3472
3576
  await this.close();
3473
3577
  } catch (err) {
3474
- import_log13.log.catch(err, {}, {
3578
+ import_log15.log.catch(err, {}, {
3475
3579
  file: "worker-session.ts",
3476
3580
  line: 107,
3477
3581
  scope: this,
@@ -3489,7 +3593,7 @@ var WorkerSession = class {
3489
3593
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
3490
3594
  }
3491
3595
  async open() {
3492
- import_log13.log.info("opening..", {}, {
3596
+ import_log15.log.info("opening..", {}, {
3493
3597
  file: "worker-session.ts",
3494
3598
  line: 121,
3495
3599
  scope: this,
@@ -3507,7 +3611,7 @@ var WorkerSession = class {
3507
3611
  try {
3508
3612
  await this._iframeRpc.rpc.IframeService.heartbeat();
3509
3613
  } catch (err1) {
3510
- import_log13.log.warn("Heartbeat failed", {
3614
+ import_log15.log.warn("Heartbeat failed", {
3511
3615
  err: err1
3512
3616
  }, {
3513
3617
  file: "worker-session.ts",
@@ -3518,7 +3622,7 @@ var WorkerSession = class {
3518
3622
  try {
3519
3623
  await this.close();
3520
3624
  } catch (err) {
3521
- import_log13.log.catch(err, {}, {
3625
+ import_log15.log.catch(err, {}, {
3522
3626
  file: "worker-session.ts",
3523
3627
  line: 137,
3524
3628
  scope: this,
@@ -3529,7 +3633,7 @@ var WorkerSession = class {
3529
3633
  }, this._options.heartbeatInterval);
3530
3634
  }
3531
3635
  async close() {
3532
- import_log13.log.info("closing..", {}, {
3636
+ import_log15.log.info("closing..", {}, {
3533
3637
  file: "worker-session.ts",
3534
3638
  line: 144,
3535
3639
  scope: this,
@@ -3538,7 +3642,7 @@ var WorkerSession = class {
3538
3642
  try {
3539
3643
  await this.onClose.callIfSet();
3540
3644
  } catch (err) {
3541
- import_log13.log.catch(err, {}, {
3645
+ import_log15.log.catch(err, {}, {
3542
3646
  file: "worker-session.ts",
3543
3647
  line: 148,
3544
3648
  scope: this,
@@ -3555,9 +3659,9 @@ var WorkerSession = class {
3555
3659
  }
3556
3660
  async _maybeOpenShell() {
3557
3661
  try {
3558
- await (0, import_async15.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3662
+ await (0, import_async17.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3559
3663
  } catch (e) {
3560
- import_log13.log.info("No shell connected.", {}, {
3664
+ import_log15.log.info("No shell connected.", {}, {
3561
3665
  file: "worker-session.ts",
3562
3666
  line: 162,
3563
3667
  scope: this,
@@ -3567,31 +3671,31 @@ var WorkerSession = class {
3567
3671
  }
3568
3672
  };
3569
3673
  __decorate5([
3570
- import_log13.logInfo
3674
+ import_log15.logInfo
3571
3675
  ], WorkerSession.prototype, "origin", void 0);
3572
3676
 
3573
3677
  // packages/sdk/client-services/src/packlets/services/service-context.ts
3574
- var import_node_assert12 = __toESM(require("node:assert"));
3575
- var import_async17 = require("@dxos/async");
3678
+ var import_node_assert13 = __toESM(require("node:assert"));
3679
+ var import_async19 = require("@dxos/async");
3576
3680
  var import_client7 = require("@dxos/client");
3577
3681
  var import_credentials12 = require("@dxos/credentials");
3578
3682
  var import_debug6 = require("@dxos/debug");
3579
3683
  var import_echo_pipeline4 = require("@dxos/echo-pipeline");
3580
3684
  var import_feed_store4 = require("@dxos/feed-store");
3581
3685
  var import_keyring = require("@dxos/keyring");
3582
- var import_keys10 = require("@dxos/keys");
3583
- var import_log15 = require("@dxos/log");
3584
- var import_protocols6 = require("@dxos/protocols");
3686
+ var import_keys11 = require("@dxos/keys");
3687
+ var import_log17 = require("@dxos/log");
3688
+ var import_protocols7 = require("@dxos/protocols");
3585
3689
  var ServiceContext = class {
3586
3690
  // prettier-ignore
3587
3691
  constructor(storage, networkManager, modelFactory) {
3588
3692
  this.storage = storage;
3589
3693
  this.networkManager = networkManager;
3590
3694
  this.modelFactory = modelFactory;
3591
- this.initialized = new import_async17.Trigger();
3695
+ this.initialized = new import_async19.Trigger();
3592
3696
  this.dataServiceSubscriptions = new import_echo_pipeline4.DataServiceSubscriptions();
3593
3697
  this._handlerFactories = /* @__PURE__ */ new Map();
3594
- this._instanceId = import_keys10.PublicKey.random().toHex();
3698
+ this._instanceId = import_keys11.PublicKey.random().toHex();
3595
3699
  networkManager._traceParent = this._instanceId;
3596
3700
  this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
3597
3701
  this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
@@ -3620,7 +3724,7 @@ var ServiceContext = class {
3620
3724
  }, this._acceptIdentity.bind(this)));
3621
3725
  }
3622
3726
  async open() {
3623
- import_log15.log.trace("dxos.sdk.service-context", import_protocols6.trace.begin({
3727
+ import_log17.log.trace("dxos.sdk.service-context", import_protocols7.trace.begin({
3624
3728
  id: this._instanceId
3625
3729
  }), {
3626
3730
  file: "service-context.ts",
@@ -3628,7 +3732,7 @@ var ServiceContext = class {
3628
3732
  scope: this,
3629
3733
  callSite: (f, a) => f(...a)
3630
3734
  });
3631
- (0, import_log15.log)("opening...", {}, {
3735
+ (0, import_log17.log)("opening...", {}, {
3632
3736
  file: "service-context.ts",
3633
3737
  line: 117,
3634
3738
  scope: this,
@@ -3640,7 +3744,7 @@ var ServiceContext = class {
3640
3744
  if (this.identityManager.identity) {
3641
3745
  await this._initialize();
3642
3746
  }
3643
- (0, import_log15.log)("opened", {}, {
3747
+ (0, import_log17.log)("opened", {}, {
3644
3748
  file: "service-context.ts",
3645
3749
  line: 124,
3646
3750
  scope: this,
@@ -3649,7 +3753,7 @@ var ServiceContext = class {
3649
3753
  }
3650
3754
  async close() {
3651
3755
  var _a, _b;
3652
- (0, import_log15.log)("closing...", {}, {
3756
+ (0, import_log17.log)("closing...", {}, {
3653
3757
  file: "service-context.ts",
3654
3758
  line: 128,
3655
3759
  scope: this,
@@ -3662,13 +3766,13 @@ var ServiceContext = class {
3662
3766
  await this.feedStore.close();
3663
3767
  await this.networkManager.close();
3664
3768
  this.dataServiceSubscriptions.clear();
3665
- (0, import_log15.log)("closed", {}, {
3769
+ (0, import_log17.log)("closed", {}, {
3666
3770
  file: "service-context.ts",
3667
3771
  line: 136,
3668
3772
  scope: this,
3669
3773
  callSite: (f, a) => f(...a)
3670
3774
  });
3671
- import_log15.log.trace("dxos.sdk.service-context", import_protocols6.trace.end({
3775
+ import_log17.log.trace("dxos.sdk.service-context", import_protocols7.trace.end({
3672
3776
  id: this._instanceId
3673
3777
  }), {
3674
3778
  file: "service-context.ts",
@@ -3684,7 +3788,7 @@ var ServiceContext = class {
3684
3788
  }
3685
3789
  getInvitationHandler(invitation) {
3686
3790
  const factory = this._handlerFactories.get(invitation.kind);
3687
- (0, import_node_assert12.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
3791
+ (0, import_node_assert13.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
3688
3792
  return factory(invitation);
3689
3793
  }
3690
3794
  async _acceptIdentity(params) {
@@ -3695,7 +3799,7 @@ var ServiceContext = class {
3695
3799
  // Called when identity is created.
3696
3800
  async _initialize() {
3697
3801
  var _a;
3698
- (0, import_log15.log)("initializing spaces...", {}, {
3802
+ (0, import_log17.log)("initializing spaces...", {}, {
3699
3803
  file: "service-context.ts",
3700
3804
  line: 163,
3701
3805
  scope: this,
@@ -3719,7 +3823,7 @@ var ServiceContext = class {
3719
3823
  this.dataSpaceManager._traceParent = this._instanceId;
3720
3824
  await this.dataSpaceManager.open();
3721
3825
  this._handlerFactories.set(import_client7.Invitation.Kind.SPACE, (invitation) => {
3722
- (0, import_node_assert12.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3826
+ (0, import_node_assert13.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
3723
3827
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
3724
3828
  });
3725
3829
  this.initialized.wake();
@@ -3733,7 +3837,7 @@ var ServiceContext = class {
3733
3837
  return;
3734
3838
  }
3735
3839
  if (!this.dataSpaceManager) {
3736
- (0, import_log15.log)("dataSpaceManager not initialized yet, ignoring space admission", {
3840
+ (0, import_log17.log)("dataSpaceManager not initialized yet, ignoring space admission", {
3737
3841
  details: assertion
3738
3842
  }, {
3739
3843
  file: "service-context.ts",
@@ -3744,7 +3848,7 @@ var ServiceContext = class {
3744
3848
  return;
3745
3849
  }
3746
3850
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3747
- (0, import_log15.log)("space already exists, ignoring space admission", {
3851
+ (0, import_log17.log)("space already exists, ignoring space admission", {
3748
3852
  details: assertion
3749
3853
  }, {
3750
3854
  file: "service-context.ts",
@@ -3755,7 +3859,7 @@ var ServiceContext = class {
3755
3859
  return;
3756
3860
  }
3757
3861
  try {
3758
- (0, import_log15.log)("accepting space recorded in halo", {
3862
+ (0, import_log17.log)("accepting space recorded in halo", {
3759
3863
  details: assertion
3760
3864
  }, {
3761
3865
  file: "service-context.ts",
@@ -3768,7 +3872,7 @@ var ServiceContext = class {
3768
3872
  genesisFeedKey: assertion.genesisFeedKey
3769
3873
  });
3770
3874
  } catch (err) {
3771
- import_log15.log.catch(err, {}, {
3875
+ import_log17.log.catch(err, {}, {
3772
3876
  file: "service-context.ts",
3773
3877
  line: 220,
3774
3878
  scope: this,
@@ -3816,7 +3920,7 @@ var ClientServicesHost = class {
3816
3920
  // TODO(wittjosiah): Turn this on by default.
3817
3921
  lockKey
3818
3922
  } = {}) {
3819
- this._statusUpdate = new import_async18.Event();
3923
+ this._statusUpdate = new import_async20.Event();
3820
3924
  this._opening = false;
3821
3925
  this._open = false;
3822
3926
  this._instanceId = import_client8.PublicKey.random().toHex();
@@ -3873,16 +3977,16 @@ var ClientServicesHost = class {
3873
3977
  * Can only be called once.
3874
3978
  */
3875
3979
  initialize({ config, networkManager }) {
3876
- (0, import_node_assert13.default)(!this._open, "service host is open");
3980
+ (0, import_node_assert14.default)(!this._open, "service host is open");
3877
3981
  if (config) {
3878
- (0, import_node_assert13.default)(!this._config, "config already set");
3982
+ (0, import_node_assert14.default)(!this._config, "config already set");
3879
3983
  this._config = config;
3880
3984
  if (!this._storage) {
3881
3985
  this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
3882
3986
  }
3883
3987
  }
3884
3988
  if (networkManager) {
3885
- (0, import_node_assert13.default)(!this._networkManager, "network manager already set");
3989
+ (0, import_node_assert14.default)(!this._networkManager, "network manager already set");
3886
3990
  this._networkManager = networkManager;
3887
3991
  }
3888
3992
  }
@@ -3891,7 +3995,7 @@ var ClientServicesHost = class {
3891
3995
  if (this._open) {
3892
3996
  return;
3893
3997
  }
3894
- import_log16.log.trace("dxos.sdk.client-services-host", import_protocols7.trace.begin({
3998
+ import_log18.log.trace("dxos.sdk.client-services-host", import_protocols8.trace.begin({
3895
3999
  id: this._instanceId
3896
4000
  }), {
3897
4001
  file: "service-host.ts",
@@ -3899,11 +4003,11 @@ var ClientServicesHost = class {
3899
4003
  scope: this,
3900
4004
  callSite: (f, a) => f(...a)
3901
4005
  });
3902
- (0, import_node_assert13.default)(this._config, "config not set");
3903
- (0, import_node_assert13.default)(this._storage, "storage not set");
3904
- (0, import_node_assert13.default)(this._networkManager, "network manager not set");
4006
+ (0, import_node_assert14.default)(this._config, "config not set");
4007
+ (0, import_node_assert14.default)(this._storage, "storage not set");
4008
+ (0, import_node_assert14.default)(this._networkManager, "network manager not set");
3905
4009
  this._opening = true;
3906
- (0, import_log16.log)("opening...", {
4010
+ (0, import_log18.log)("opening...", {
3907
4011
  lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
3908
4012
  }, {
3909
4013
  file: "service-host.ts",
@@ -3937,7 +4041,7 @@ var ClientServicesHost = class {
3937
4041
  this._open = true;
3938
4042
  this._statusUpdate.emit();
3939
4043
  const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
3940
- (0, import_log16.log)("opened", {
4044
+ (0, import_log18.log)("opened", {
3941
4045
  deviceKey
3942
4046
  }, {
3943
4047
  file: "service-host.ts",
@@ -3952,7 +4056,7 @@ var ClientServicesHost = class {
3952
4056
  return;
3953
4057
  }
3954
4058
  const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
3955
- (0, import_log16.log)("closing...", {
4059
+ (0, import_log18.log)("closing...", {
3956
4060
  deviceKey
3957
4061
  }, {
3958
4062
  file: "service-host.ts",
@@ -3966,7 +4070,7 @@ var ClientServicesHost = class {
3966
4070
  await this._serviceContext.close();
3967
4071
  this._open = false;
3968
4072
  this._statusUpdate.emit();
3969
- (0, import_log16.log)("closed", {
4073
+ (0, import_log18.log)("closed", {
3970
4074
  deviceKey
3971
4075
  }, {
3972
4076
  file: "service-host.ts",
@@ -3974,7 +4078,7 @@ var ClientServicesHost = class {
3974
4078
  scope: this,
3975
4079
  callSite: (f, a) => f(...a)
3976
4080
  });
3977
- import_log16.log.trace("dxos.sdk.client-services-host", import_protocols7.trace.end({
4081
+ import_log18.log.trace("dxos.sdk.client-services-host", import_protocols8.trace.end({
3978
4082
  id: this._instanceId
3979
4083
  }), {
3980
4084
  file: "service-host.ts",
@@ -3985,7 +4089,7 @@ var ClientServicesHost = class {
3985
4089
  }
3986
4090
  async reset() {
3987
4091
  var _a;
3988
- (0, import_log16.log)("resetting...", {}, {
4092
+ (0, import_log18.log)("resetting...", {}, {
3989
4093
  file: "service-host.ts",
3990
4094
  line: 240,
3991
4095
  scope: this,
@@ -3993,7 +4097,7 @@ var ClientServicesHost = class {
3993
4097
  });
3994
4098
  await ((_a = this._serviceContext) == null ? void 0 : _a.close());
3995
4099
  await this._storage.reset();
3996
- (0, import_log16.log)("reset", {}, {
4100
+ (0, import_log18.log)("reset", {}, {
3997
4101
  file: "service-host.ts",
3998
4102
  line: 243,
3999
4103
  scope: this,
@@ -4026,7 +4130,7 @@ var LocalClientServices = class {
4026
4130
 
4027
4131
  // packages/sdk/client-services/src/packlets/services/utils.ts
4028
4132
  var import_config2 = require("@dxos/config");
4029
- var import_log17 = require("@dxos/log");
4133
+ var import_log19 = require("@dxos/log");
4030
4134
  var import_messaging3 = require("@dxos/messaging");
4031
4135
  var import_network_manager5 = require("@dxos/network-manager");
4032
4136
 
@@ -4143,8 +4247,8 @@ var createSigningContext = async (keyring) => {
4143
4247
  };
4144
4248
 
4145
4249
  // packages/sdk/client-services/src/packlets/testing/invitation-utils.ts
4146
- var import_node_assert14 = __toESM(require("node:assert"));
4147
- var import_async19 = require("@dxos/async");
4250
+ var import_node_assert15 = __toESM(require("node:assert"));
4251
+ var import_async21 = require("@dxos/async");
4148
4252
  var import_client10 = require("@dxos/client");
4149
4253
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
4150
4254
  var sanitizeInvitation = (invitation) => {
@@ -4159,9 +4263,9 @@ var sanitizeInvitation = (invitation) => {
4159
4263
  };
4160
4264
  };
4161
4265
  var performInvitation = ({ host, guest, options, hooks }) => {
4162
- const hostComplete = new import_async19.Trigger();
4163
- const guestComplete = new import_async19.Trigger();
4164
- const authCode = new import_async19.Trigger();
4266
+ const hostComplete = new import_async21.Trigger();
4267
+ const guestComplete = new import_async21.Trigger();
4268
+ const authCode = new import_async21.Trigger();
4165
4269
  const hostObservable = createInvitation(host, options);
4166
4270
  hostObservable.subscribe(async (hostInvitation) => {
4167
4271
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
@@ -4178,7 +4282,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
4178
4282
  if ((_b2 = (_a2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _a2.onConnecting) == null ? void 0 : _b2.call(_a2, guestObservable)) {
4179
4283
  break;
4180
4284
  }
4181
- (0, import_node_assert14.default)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey));
4285
+ (0, import_node_assert15.default)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey));
4182
4286
  break;
4183
4287
  }
4184
4288
  case import_services11.Invitation.State.CONNECTED: {
@@ -4319,15 +4423,15 @@ var acceptInvitation = (guest, invitation) => {
4319
4423
  };
4320
4424
 
4321
4425
  // packages/sdk/client-services/src/packlets/testing/test-builder.ts
4322
- var import_node_assert15 = __toESM(require("node:assert"));
4323
- var import_async20 = require("@dxos/async");
4426
+ var import_node_assert16 = __toESM(require("node:assert"));
4427
+ var import_async22 = require("@dxos/async");
4324
4428
  var import_client11 = require("@dxos/client");
4325
4429
  var import_config3 = require("@dxos/config");
4326
4430
  var import_debug7 = require("@dxos/debug");
4327
4431
  var import_document_model = require("@dxos/document-model");
4328
4432
  var import_echo_db = require("@dxos/echo-db");
4329
- var import_keys11 = require("@dxos/keys");
4330
- var import_log18 = require("@dxos/log");
4433
+ var import_keys12 = require("@dxos/keys");
4434
+ var import_log20 = require("@dxos/log");
4331
4435
  var import_messaging5 = require("@dxos/messaging");
4332
4436
  var import_network_manager7 = require("@dxos/network-manager");
4333
4437
  var import_rpc5 = require("@dxos/rpc");
@@ -4335,10 +4439,12 @@ var testConfigWithLocalSignal = new import_config3.Config({
4335
4439
  version: 1,
4336
4440
  runtime: {
4337
4441
  services: {
4338
- signal: {
4339
- // TODO(burdon): Port numbers and global consts?
4340
- server: "ws://localhost:4000/.well-known/dx/signal"
4341
- }
4442
+ signaling: [
4443
+ {
4444
+ // TODO(burdon): Port numbers and global consts?
4445
+ server: "ws://localhost:4000/.well-known/dx/signal"
4446
+ }
4447
+ ]
4342
4448
  }
4343
4449
  }
4344
4450
  });
@@ -4356,13 +4462,11 @@ var TestBuilder = class {
4356
4462
  * Get network manager using local shared memory or remote signal manager.
4357
4463
  */
4358
4464
  get networkManager() {
4359
- const signalServer = this._config.get("runtime.services.signal.server");
4360
- if (signalServer) {
4465
+ const signals = this._config.get("runtime.services.signaling");
4466
+ if (signals) {
4361
4467
  return new import_network_manager7.NetworkManager({
4362
4468
  log: true,
4363
- signalManager: new import_messaging5.WebsocketSignalManager([
4364
- signalServer
4365
- ]),
4469
+ signalManager: new import_messaging5.WebsocketSignalManager(signals),
4366
4470
  transportFactory: (0, import_network_manager7.createWebRTCTransportFactory)({
4367
4471
  iceServers: this._config.get("runtime.services.ice")
4368
4472
  })
@@ -4416,11 +4520,11 @@ var TestBuilder = class {
4416
4520
  }
4417
4521
  };
4418
4522
  var testSpace = async (create, check = create) => {
4419
- const objectId = import_keys11.PublicKey.random().toHex();
4523
+ const objectId = import_keys12.PublicKey.random().toHex();
4420
4524
  const result = create.mutate((0, import_echo_db.genesisMutation)(objectId, import_document_model.DocumentModel.meta.type));
4421
4525
  await result.batch.getReceipt();
4422
- (0, import_node_assert15.default)(create._itemManager.entities.has(result.objectsUpdated[0].id));
4423
- await (0, import_async20.asyncTimeout)(check.itemUpdate.waitForCondition(() => check._itemManager.entities.has(objectId)), 1e3);
4526
+ (0, import_node_assert16.default)(create._itemManager.entities.has(result.objectsUpdated[0].id));
4527
+ await (0, import_async22.asyncTimeout)(check.itemUpdate.waitForCondition(() => check._itemManager.entities.has(objectId)), 1e3);
4424
4528
  return result;
4425
4529
  };
4426
4530
  var syncItems = async (db1, db2) => {
@@ -4429,16 +4533,16 @@ var syncItems = async (db1, db2) => {
4429
4533
  };
4430
4534
  var joinCommonSpace = async ([initialPeer, ...peers], spaceKey) => {
4431
4535
  const rootSpace = spaceKey ? initialPeer.getSpace(spaceKey) : await initialPeer.createSpace();
4432
- (0, import_node_assert15.default)(rootSpace, "Space not found.");
4536
+ (0, import_node_assert16.default)(rootSpace, "Space not found.");
4433
4537
  await Promise.all(peers.map(async (peer) => {
4434
- const hostDone = new import_async20.Trigger();
4435
- const guestDone = new import_async20.Trigger();
4538
+ const hostDone = new import_async22.Trigger();
4539
+ const guestDone = new import_async22.Trigger();
4436
4540
  const hostObservable = rootSpace.createInvitation({
4437
4541
  authMethod: import_client11.Invitation.AuthMethod.NONE
4438
4542
  });
4439
- (0, import_log18.log)("invitation created", {}, {
4543
+ (0, import_log20.log)("invitation created", {}, {
4440
4544
  file: "test-builder.ts",
4441
- line: 154,
4545
+ line: 156,
4442
4546
  scope: void 0,
4443
4547
  callSite: (f, a) => f(...a)
4444
4548
  });
@@ -4446,9 +4550,9 @@ var joinCommonSpace = async ([initialPeer, ...peers], spaceKey) => {
4446
4550
  switch (hostInvitation.state) {
4447
4551
  case import_client11.Invitation.State.CONNECTING: {
4448
4552
  const guestObservable = peer.acceptInvitation(hostInvitation);
4449
- (0, import_log18.log)("invitation accepted", {}, {
4553
+ (0, import_log20.log)("invitation accepted", {}, {
4450
4554
  file: "test-builder.ts",
4451
- line: 160,
4555
+ line: 162,
4452
4556
  scope: void 0,
4453
4557
  callSite: (f, a) => f(...a)
4454
4558
  });
@@ -4456,9 +4560,9 @@ var joinCommonSpace = async ([initialPeer, ...peers], spaceKey) => {
4456
4560
  switch (guestInvitation.state) {
4457
4561
  case import_client11.Invitation.State.SUCCESS: {
4458
4562
  guestDone.wake(guestInvitation);
4459
- (0, import_log18.log)("invitation guestDone", {}, {
4563
+ (0, import_log20.log)("invitation guestDone", {}, {
4460
4564
  file: "test-builder.ts",
4461
- line: 167,
4565
+ line: 169,
4462
4566
  scope: void 0,
4463
4567
  callSite: (f, a) => f(...a)
4464
4568
  });
@@ -4470,9 +4574,9 @@ var joinCommonSpace = async ([initialPeer, ...peers], spaceKey) => {
4470
4574
  }
4471
4575
  case import_client11.Invitation.State.SUCCESS: {
4472
4576
  hostDone.wake(hostInvitation);
4473
- (0, import_log18.log)("invitation hostDone", {}, {
4577
+ (0, import_log20.log)("invitation hostDone", {}, {
4474
4578
  file: "test-builder.ts",
4475
- line: 179,
4579
+ line: 181,
4476
4580
  scope: void 0,
4477
4581
  callSite: (f, a) => f(...a)
4478
4582
  });