@dxos/client-services 0.1.46 → 0.1.48-next.4b7ebc3

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.
@@ -825,6 +825,14 @@ var IdentityManager = class {
825
825
  swarmIdentity,
826
826
  onNetworkConnection: () => {
827
827
  },
828
+ onAuthFailure: () => {
829
+ log3.warn("auth failure", {}, {
830
+ file: "identity-manager.ts",
831
+ line: 242,
832
+ scope: this,
833
+ callSite: (f, a) => f(...a)
834
+ });
835
+ },
828
836
  memberKey: identityKey
829
837
  });
830
838
  }
@@ -954,8 +962,8 @@ import { PublicKey as PublicKey5 } from "@dxos/keys";
954
962
  import { log as log5 } from "@dxos/log";
955
963
  import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
956
964
  import { trace as trace3 } from "@dxos/protocols";
957
- import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
958
- import { AuthenticationResponse } from "@dxos/protocols/proto/dxos/halo/invitations";
965
+ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
966
+ import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
959
967
 
960
968
  // packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
961
969
  import assert5 from "@dxos/node-std/assert";
@@ -965,9 +973,11 @@ import { InvalidInvitationExtensionRoleError } from "@dxos/errors";
965
973
  import { PublicKey as PublicKey4 } from "@dxos/keys";
966
974
  import { log as log4 } from "@dxos/log";
967
975
  import { schema as schema2, trace as trace2 } from "@dxos/protocols";
968
- import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
976
+ import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
977
+ import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
969
978
  import { RpcExtension } from "@dxos/teleport";
970
979
  var OPTIONS_TIMEOUT = 1e4;
980
+ var MAX_OTP_ATTEMPTS = 3;
971
981
  var InvitationHostExtension = class extends RpcExtension {
972
982
  constructor(_callbacks) {
973
983
  super({
@@ -981,6 +991,11 @@ var InvitationHostExtension = class extends RpcExtension {
981
991
  this._callbacks = _callbacks;
982
992
  this._ctx = new Context3();
983
993
  this._remoteOptionsTrigger = new Trigger2();
994
+ this.invitation = void 0;
995
+ this.guestProfile = void 0;
996
+ this.authenticationPassed = false;
997
+ this.authenticationRetry = 0;
998
+ this.completedTrigger = new Trigger2();
984
999
  }
985
1000
  async getHandlers() {
986
1001
  return {
@@ -993,49 +1008,129 @@ var InvitationHostExtension = class extends RpcExtension {
993
1008
  this._remoteOptionsTrigger.wake();
994
1009
  },
995
1010
  introduce: async (request) => {
1011
+ const { profile, invitationId } = request;
996
1012
  const traceId = PublicKey4.random().toHex();
997
1013
  log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
998
1014
  id: traceId
999
1015
  }), {
1000
1016
  file: "invitation-extension.ts",
1001
- line: 76,
1017
+ line: 98,
1002
1018
  scope: this,
1003
1019
  callSite: (f, a) => f(...a)
1004
1020
  });
1005
- const response = await this._callbacks.introduce(request);
1021
+ const invitation = await this._callbacks.resolveInvitation(request);
1022
+ if (!invitation) {
1023
+ log4.warn("invitation not found", {
1024
+ invitationId
1025
+ }, {
1026
+ file: "invitation-extension.ts",
1027
+ line: 102,
1028
+ scope: this,
1029
+ callSite: (f, a) => f(...a)
1030
+ });
1031
+ this._callbacks.onError(new Error("Invitation not found."));
1032
+ return {
1033
+ authMethod: Invitation2.AuthMethod.NONE
1034
+ };
1035
+ }
1036
+ this.invitation = invitation;
1037
+ log4("guest introduced itself", {
1038
+ guestProfile: profile
1039
+ }, {
1040
+ file: "invitation-extension.ts",
1041
+ line: 111,
1042
+ scope: this,
1043
+ callSite: (f, a) => f(...a)
1044
+ });
1045
+ this.guestProfile = profile;
1046
+ this._callbacks.onStateUpdate({
1047
+ ...this.invitation,
1048
+ state: Invitation2.State.READY_FOR_AUTHENTICATION
1049
+ });
1006
1050
  log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
1007
1051
  id: traceId
1008
1052
  }), {
1009
1053
  file: "invitation-extension.ts",
1010
- line: 78,
1054
+ line: 118,
1011
1055
  scope: this,
1012
1056
  callSite: (f, a) => f(...a)
1013
1057
  });
1014
- return response;
1058
+ return {
1059
+ spaceKey: this.invitation.authMethod === Invitation2.AuthMethod.NONE ? this.invitation.spaceKey : void 0,
1060
+ authMethod: this.invitation.authMethod
1061
+ };
1015
1062
  },
1016
- authenticate: async (request) => {
1063
+ authenticate: async ({ authCode: code }) => {
1017
1064
  const traceId = PublicKey4.random().toHex();
1018
1065
  log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
1019
1066
  id: traceId
1020
1067
  }), {
1021
1068
  file: "invitation-extension.ts",
1022
- line: 84,
1069
+ line: 127,
1023
1070
  scope: this,
1024
1071
  callSite: (f, a) => f(...a)
1025
1072
  });
1026
- const response = await this._callbacks.authenticate(request);
1073
+ log4("received authentication request", {
1074
+ authCode: code
1075
+ }, {
1076
+ file: "invitation-extension.ts",
1077
+ line: 128,
1078
+ scope: this,
1079
+ callSite: (f, a) => f(...a)
1080
+ });
1081
+ let status = AuthenticationResponse.Status.OK;
1082
+ assert5(this.invitation, "Invitation is not set.");
1083
+ switch (this.invitation.authMethod) {
1084
+ case Invitation2.AuthMethod.NONE: {
1085
+ log4("authentication not required", {}, {
1086
+ file: "invitation-extension.ts",
1087
+ line: 134,
1088
+ scope: this,
1089
+ callSite: (f, a) => f(...a)
1090
+ });
1091
+ return {
1092
+ status: AuthenticationResponse.Status.OK
1093
+ };
1094
+ }
1095
+ case Invitation2.AuthMethod.SHARED_SECRET: {
1096
+ if (this.invitation.authCode) {
1097
+ if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1098
+ status = AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1099
+ } else if (code !== this.invitation.authCode) {
1100
+ status = AuthenticationResponse.Status.INVALID_OTP;
1101
+ } else {
1102
+ this.authenticationPassed = true;
1103
+ }
1104
+ }
1105
+ break;
1106
+ }
1107
+ default: {
1108
+ log4.error("invalid authentication method", {
1109
+ authMethod: this.invitation.authMethod
1110
+ }, {
1111
+ file: "invitation-extension.ts",
1112
+ line: 152,
1113
+ scope: this,
1114
+ callSite: (f, a) => f(...a)
1115
+ });
1116
+ status = AuthenticationResponse.Status.INTERNAL_ERROR;
1117
+ break;
1118
+ }
1119
+ }
1027
1120
  log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.end({
1028
1121
  id: traceId,
1029
1122
  data: {
1030
- ...response
1123
+ status
1031
1124
  }
1032
1125
  }), {
1033
1126
  file: "invitation-extension.ts",
1034
- line: 86,
1127
+ line: 158,
1035
1128
  scope: this,
1036
1129
  callSite: (f, a) => f(...a)
1037
1130
  });
1038
- return response;
1131
+ return {
1132
+ status
1133
+ };
1039
1134
  },
1040
1135
  admit: async (request) => {
1041
1136
  const traceId = PublicKey4.random().toHex();
@@ -1043,20 +1138,29 @@ var InvitationHostExtension = class extends RpcExtension {
1043
1138
  id: traceId
1044
1139
  }), {
1045
1140
  file: "invitation-extension.ts",
1046
- line: 92,
1141
+ line: 164,
1047
1142
  scope: this,
1048
1143
  callSite: (f, a) => f(...a)
1049
1144
  });
1050
- const response = await this._callbacks.admit(request);
1051
- log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
1052
- id: traceId
1053
- }), {
1054
- file: "invitation-extension.ts",
1055
- line: 94,
1056
- scope: this,
1057
- callSite: (f, a) => f(...a)
1058
- });
1059
- return response;
1145
+ try {
1146
+ assert5(this.invitation, "Invitation is not set.");
1147
+ if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
1148
+ throw new Error("Not authenticated");
1149
+ }
1150
+ const response = await this._callbacks.admit(request);
1151
+ log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
1152
+ id: traceId
1153
+ }), {
1154
+ file: "invitation-extension.ts",
1155
+ line: 175,
1156
+ scope: this,
1157
+ callSite: (f, a) => f(...a)
1158
+ });
1159
+ return response;
1160
+ } catch (err) {
1161
+ this._callbacks.onError(err);
1162
+ throw err;
1163
+ }
1060
1164
  }
1061
1165
  }
1062
1166
  };
@@ -1126,7 +1230,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1126
1230
  try {
1127
1231
  log4("begin options", {}, {
1128
1232
  file: "invitation-extension.ts",
1129
- line: 178,
1233
+ line: 263,
1130
1234
  scope: this,
1131
1235
  callSite: (f, a) => f(...a)
1132
1236
  });
@@ -1138,7 +1242,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1138
1242
  }));
1139
1243
  log4("end options", {}, {
1140
1244
  file: "invitation-extension.ts",
1141
- line: 181,
1245
+ line: 266,
1142
1246
  scope: this,
1143
1247
  callSite: (f, a) => f(...a)
1144
1248
  });
@@ -1152,7 +1256,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1152
1256
  } catch (err) {
1153
1257
  log4("openError", err, {
1154
1258
  file: "invitation-extension.ts",
1155
- line: 191,
1259
+ line: 276,
1156
1260
  scope: this,
1157
1261
  callSite: (f, a) => f(...a)
1158
1262
  });
@@ -1162,16 +1266,16 @@ var InvitationGuestExtension = class extends RpcExtension {
1162
1266
  async onClose() {
1163
1267
  log4("onClose", {}, {
1164
1268
  file: "invitation-extension.ts",
1165
- line: 197,
1269
+ line: 282,
1166
1270
  scope: this,
1167
1271
  callSite: (f, a) => f(...a)
1168
1272
  });
1169
1273
  await this._ctx.dispose();
1170
1274
  }
1171
1275
  };
1276
+ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
1172
1277
 
1173
1278
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
1174
- var MAX_OTP_ATTEMPTS = 3;
1175
1279
  var InvitationsHandler = class {
1176
1280
  /**
1177
1281
  * @internal
@@ -1181,8 +1285,8 @@ var InvitationsHandler = class {
1181
1285
  }
1182
1286
  createInvitation(protocol, options) {
1183
1287
  var _a;
1184
- const { invitationId = PublicKey5.random().toHex(), type = Invitation2.Type.INTERACTIVE, authMethod = Invitation2.AuthMethod.SHARED_SECRET, state = Invitation2.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options != null ? options : {};
1185
- const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation2.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
1288
+ const { invitationId = PublicKey5.random().toHex(), type = Invitation3.Type.INTERACTIVE, authMethod = Invitation3.AuthMethod.SHARED_SECRET, state = Invitation3.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options != null ? options : {};
1289
+ const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation3.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
1186
1290
  assert6(protocol);
1187
1291
  const invitation = {
1188
1292
  invitationId,
@@ -1206,99 +1310,33 @@ var InvitationsHandler = class {
1206
1310
  ...protocol.toJSON()
1207
1311
  }, {
1208
1312
  file: "invitations-handler.ts",
1209
- line: 98,
1313
+ line: 100,
1210
1314
  scope: this,
1211
1315
  callSite: (f, a) => f(...a)
1212
1316
  });
1213
1317
  stream.complete();
1214
1318
  });
1215
1319
  const createExtension = () => {
1216
- const success = new Trigger3();
1217
- let guestProfile;
1218
- let authenticationPassed = false;
1219
- let authenticationRetry = 0;
1220
1320
  const extension = new InvitationHostExtension({
1221
- introduce: async ({ profile }) => {
1222
- log5("guest introduced itself", {
1223
- guestProfile: profile,
1224
- ...protocol.toJSON()
1225
- }, {
1226
- file: "invitations-handler.ts",
1227
- line: 111,
1228
- scope: this,
1229
- callSite: (f, a) => f(...a)
1230
- });
1231
- guestProfile = profile;
1321
+ onStateUpdate: (invitation2) => {
1232
1322
  stream.next({
1233
- ...invitation,
1234
- state: Invitation2.State.READY_FOR_AUTHENTICATION
1323
+ ...invitation2,
1324
+ state: Invitation3.State.READY_FOR_AUTHENTICATION
1235
1325
  });
1236
- return {
1237
- spaceKey: authMethod === Invitation2.AuthMethod.NONE ? protocol.getInvitationContext().spaceKey : void 0,
1238
- authMethod
1239
- };
1240
1326
  },
1241
- authenticate: async ({ authCode: code }) => {
1242
- log5("received authentication request", {
1243
- authCode: code
1244
- }, {
1245
- file: "invitations-handler.ts",
1246
- line: 130,
1247
- scope: this,
1248
- callSite: (f, a) => f(...a)
1249
- });
1250
- let status = AuthenticationResponse.Status.OK;
1251
- switch (invitation.authMethod) {
1252
- case Invitation2.AuthMethod.NONE: {
1253
- log5("authentication not required", {}, {
1254
- file: "invitations-handler.ts",
1255
- line: 135,
1256
- scope: this,
1257
- callSite: (f, a) => f(...a)
1258
- });
1259
- return {
1260
- status: AuthenticationResponse.Status.OK
1261
- };
1262
- }
1263
- case Invitation2.AuthMethod.SHARED_SECRET: {
1264
- if (invitation.authCode) {
1265
- if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
1266
- status = AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
1267
- } else if (code !== invitation.authCode) {
1268
- status = AuthenticationResponse.Status.INVALID_OTP;
1269
- } else {
1270
- authenticationPassed = true;
1271
- }
1272
- }
1273
- break;
1274
- }
1275
- default: {
1276
- log5.error("invalid authentication method", {
1277
- authMethod: invitation.authMethod
1278
- }, {
1279
- file: "invitations-handler.ts",
1280
- line: 153,
1281
- scope: this,
1282
- callSite: (f, a) => f(...a)
1283
- });
1284
- status = AuthenticationResponse.Status.INTERNAL_ERROR;
1285
- break;
1286
- }
1327
+ resolveInvitation: async ({ invitationId: invitationId2 }) => {
1328
+ if (invitationId2 && invitationId2 !== invitation.invitationId) {
1329
+ return void 0;
1287
1330
  }
1288
- return {
1289
- status
1290
- };
1331
+ return invitation;
1291
1332
  },
1292
1333
  admit: async (admissionRequest) => {
1293
1334
  var _a2, _b, _c;
1294
1335
  try {
1295
- if (isAuthenticationRequired(invitation) && !authenticationPassed) {
1296
- throw new Error("Not authenticated");
1297
- }
1298
1336
  const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
1299
1337
  assert6(deviceKey);
1300
- const admissionResponse = await protocol.admit(admissionRequest, guestProfile);
1301
- success.wake(deviceKey);
1338
+ const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1339
+ extension.completedTrigger.wake(deviceKey);
1302
1340
  return admissionResponse;
1303
1341
  } catch (err) {
1304
1342
  stream.error(err);
@@ -1313,7 +1351,7 @@ var InvitationsHandler = class {
1313
1351
  id: traceId
1314
1352
  }), {
1315
1353
  file: "invitations-handler.ts",
1316
- line: 188,
1354
+ line: 139,
1317
1355
  scope: this,
1318
1356
  callSite: (f, a) => f(...a)
1319
1357
  });
@@ -1321,15 +1359,15 @@ var InvitationsHandler = class {
1321
1359
  ...protocol.toJSON()
1322
1360
  }, {
1323
1361
  file: "invitations-handler.ts",
1324
- line: 189,
1362
+ line: 140,
1325
1363
  scope: this,
1326
1364
  callSite: (f, a) => f(...a)
1327
1365
  });
1328
1366
  stream.next({
1329
1367
  ...invitation,
1330
- state: Invitation2.State.CONNECTED
1368
+ state: Invitation3.State.CONNECTED
1331
1369
  });
1332
- const deviceKey = await success.wait({
1370
+ const deviceKey = await extension.completedTrigger.wait({
1333
1371
  timeout
1334
1372
  });
1335
1373
  log5("admitted guest", {
@@ -1337,19 +1375,19 @@ var InvitationsHandler = class {
1337
1375
  ...protocol.toJSON()
1338
1376
  }, {
1339
1377
  file: "invitations-handler.ts",
1340
- line: 192,
1378
+ line: 143,
1341
1379
  scope: this,
1342
1380
  callSite: (f, a) => f(...a)
1343
1381
  });
1344
1382
  stream.next({
1345
1383
  ...invitation,
1346
- state: Invitation2.State.SUCCESS
1384
+ state: Invitation3.State.SUCCESS
1347
1385
  });
1348
1386
  log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.end({
1349
1387
  id: traceId
1350
1388
  }), {
1351
1389
  file: "invitations-handler.ts",
1352
- line: 194,
1390
+ line: 145,
1353
1391
  scope: this,
1354
1392
  callSite: (f, a) => f(...a)
1355
1393
  });
@@ -1359,18 +1397,18 @@ var InvitationsHandler = class {
1359
1397
  ...protocol.toJSON()
1360
1398
  }, {
1361
1399
  file: "invitations-handler.ts",
1362
- line: 197,
1400
+ line: 148,
1363
1401
  scope: this,
1364
1402
  callSite: (f, a) => f(...a)
1365
1403
  });
1366
1404
  stream.next({
1367
1405
  ...invitation,
1368
- state: Invitation2.State.TIMEOUT
1406
+ state: Invitation3.State.TIMEOUT
1369
1407
  });
1370
1408
  } else {
1371
1409
  log5.error("failed", err, {
1372
1410
  file: "invitations-handler.ts",
1373
- line: 200,
1411
+ line: 151,
1374
1412
  scope: this,
1375
1413
  callSite: (f, a) => f(...a)
1376
1414
  });
@@ -1381,12 +1419,12 @@ var InvitationsHandler = class {
1381
1419
  error: err
1382
1420
  }), {
1383
1421
  file: "invitations-handler.ts",
1384
- line: 203,
1422
+ line: 154,
1385
1423
  scope: this,
1386
1424
  callSite: (f, a) => f(...a)
1387
1425
  });
1388
1426
  } finally {
1389
- if (type !== Invitation2.Type.MULTIUSE) {
1427
+ if (type !== Invitation3.Type.MULTIUSE) {
1390
1428
  await sleep(ON_CLOSE_DELAY);
1391
1429
  await ctx.dispose();
1392
1430
  }
@@ -1402,18 +1440,18 @@ var InvitationsHandler = class {
1402
1440
  ...protocol.toJSON()
1403
1441
  }, {
1404
1442
  file: "invitations-handler.ts",
1405
- line: 217,
1443
+ line: 168,
1406
1444
  scope: this,
1407
1445
  callSite: (f, a) => f(...a)
1408
1446
  });
1409
1447
  stream.next({
1410
1448
  ...invitation,
1411
- state: Invitation2.State.TIMEOUT
1449
+ state: Invitation3.State.TIMEOUT
1412
1450
  });
1413
1451
  } else {
1414
1452
  log5.error("failed", err, {
1415
1453
  file: "invitations-handler.ts",
1416
- line: 220,
1454
+ line: 171,
1417
1455
  scope: this,
1418
1456
  callSite: (f, a) => f(...a)
1419
1457
  });
@@ -1436,7 +1474,7 @@ var InvitationsHandler = class {
1436
1474
  ctx.onDispose(() => swarmConnection.close());
1437
1475
  stream.next({
1438
1476
  ...invitation,
1439
- state: Invitation2.State.CONNECTING
1477
+ state: Invitation3.State.CONNECTING
1440
1478
  });
1441
1479
  });
1442
1480
  const observable = new CancellableInvitationObservable({
@@ -1445,7 +1483,7 @@ var InvitationsHandler = class {
1445
1483
  onCancel: async () => {
1446
1484
  stream.next({
1447
1485
  ...invitation,
1448
- state: Invitation2.State.CANCELLED
1486
+ state: Invitation3.State.CANCELLED
1449
1487
  });
1450
1488
  await ctx.dispose();
1451
1489
  }
@@ -1473,17 +1511,17 @@ var InvitationsHandler = class {
1473
1511
  ...protocol.toJSON()
1474
1512
  }, {
1475
1513
  file: "invitations-handler.ts",
1476
- line: 274,
1514
+ line: 225,
1477
1515
  scope: this,
1478
1516
  callSite: (f, a) => f(...a)
1479
1517
  });
1480
1518
  setState({
1481
- state: Invitation2.State.TIMEOUT
1519
+ state: Invitation3.State.TIMEOUT
1482
1520
  });
1483
1521
  } else {
1484
1522
  log5.warn("auth failed", err, {
1485
1523
  file: "invitations-handler.ts",
1486
- line: 277,
1524
+ line: 228,
1487
1525
  scope: this,
1488
1526
  callSite: (f, a) => f(...a)
1489
1527
  });
@@ -1497,7 +1535,7 @@ var InvitationsHandler = class {
1497
1535
  ...protocol.toJSON()
1498
1536
  }, {
1499
1537
  file: "invitations-handler.ts",
1500
- line: 285,
1538
+ line: 236,
1501
1539
  scope: this,
1502
1540
  callSite: (f, a) => f(...a)
1503
1541
  });
@@ -1512,11 +1550,11 @@ var InvitationsHandler = class {
1512
1550
  currentState
1513
1551
  }, {
1514
1552
  file: "invitations-handler.ts",
1515
- line: 295,
1553
+ line: 246,
1516
1554
  scope: this,
1517
1555
  callSite: (f, a) => f(...a)
1518
1556
  });
1519
- if (currentState !== Invitation2.State.SUCCESS) {
1557
+ if (currentState !== Invitation3.State.SUCCESS) {
1520
1558
  stream.error(new Error("Remote peer disconnected."));
1521
1559
  }
1522
1560
  });
@@ -1527,7 +1565,7 @@ var InvitationsHandler = class {
1527
1565
  id: traceId
1528
1566
  }), {
1529
1567
  file: "invitations-handler.ts",
1530
- line: 304,
1568
+ line: 255,
1531
1569
  scope: this,
1532
1570
  callSite: (f, a) => f(...a)
1533
1571
  });
@@ -1539,18 +1577,18 @@ var InvitationsHandler = class {
1539
1577
  ...protocol.toJSON()
1540
1578
  }, {
1541
1579
  file: "invitations-handler.ts",
1542
- line: 312,
1580
+ line: 263,
1543
1581
  scope: this,
1544
1582
  callSite: (f, a) => f(...a)
1545
1583
  });
1546
1584
  setState({
1547
- state: Invitation2.State.CONNECTED
1585
+ state: Invitation3.State.CONNECTED
1548
1586
  });
1549
1587
  log5("introduce", {
1550
1588
  ...protocol.toJSON()
1551
1589
  }, {
1552
1590
  file: "invitations-handler.ts",
1553
- line: 316,
1591
+ line: 267,
1554
1592
  scope: this,
1555
1593
  callSite: (f, a) => f(...a)
1556
1594
  });
@@ -1560,7 +1598,7 @@ var InvitationsHandler = class {
1560
1598
  response: introductionResponse
1561
1599
  }, {
1562
1600
  file: "invitations-handler.ts",
1563
- line: 320,
1601
+ line: 271,
1564
1602
  scope: this,
1565
1603
  callSite: (f, a) => f(...a)
1566
1604
  });
@@ -1572,32 +1610,32 @@ var InvitationsHandler = class {
1572
1610
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
1573
1611
  log5("guest waiting for authentication code...", {}, {
1574
1612
  file: "invitations-handler.ts",
1575
- line: 329,
1613
+ line: 280,
1576
1614
  scope: this,
1577
1615
  callSite: (f, a) => f(...a)
1578
1616
  });
1579
1617
  setState({
1580
- state: Invitation2.State.READY_FOR_AUTHENTICATION
1618
+ state: Invitation3.State.READY_FOR_AUTHENTICATION
1581
1619
  });
1582
1620
  const authCode = await authenticated.wait({
1583
1621
  timeout
1584
1622
  });
1585
1623
  log5("sending authentication request", {}, {
1586
1624
  file: "invitations-handler.ts",
1587
- line: 333,
1625
+ line: 284,
1588
1626
  scope: this,
1589
1627
  callSite: (f, a) => f(...a)
1590
1628
  });
1591
1629
  setState({
1592
- state: Invitation2.State.AUTHENTICATING
1630
+ state: Invitation3.State.AUTHENTICATING
1593
1631
  });
1594
1632
  const response = await extension.rpc.InvitationHostService.authenticate({
1595
1633
  authCode
1596
1634
  });
1597
- if (response.status === void 0 || response.status === AuthenticationResponse.Status.OK) {
1635
+ if (response.status === void 0 || response.status === AuthenticationResponse2.Status.OK) {
1598
1636
  break;
1599
1637
  }
1600
- if (response.status === AuthenticationResponse.Status.INVALID_OTP) {
1638
+ if (response.status === AuthenticationResponse2.Status.INVALID_OTP) {
1601
1639
  if (attempt === MAX_OTP_ATTEMPTS) {
1602
1640
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
1603
1641
  } else {
@@ -1605,7 +1643,7 @@ var InvitationsHandler = class {
1605
1643
  attempt
1606
1644
  }, {
1607
1645
  file: "invitations-handler.ts",
1608
- line: 344,
1646
+ line: 295,
1609
1647
  scope: this,
1610
1648
  callSite: (f, a) => f(...a)
1611
1649
  });
@@ -1615,14 +1653,14 @@ var InvitationsHandler = class {
1615
1653
  }
1616
1654
  } else {
1617
1655
  setState({
1618
- state: Invitation2.State.READY_FOR_AUTHENTICATION
1656
+ state: Invitation3.State.READY_FOR_AUTHENTICATION
1619
1657
  });
1620
1658
  }
1621
1659
  log5("request admission", {
1622
1660
  ...protocol.toJSON()
1623
1661
  }, {
1624
1662
  file: "invitations-handler.ts",
1625
- line: 355,
1663
+ line: 306,
1626
1664
  scope: this,
1627
1665
  callSite: (f, a) => f(...a)
1628
1666
  });
@@ -1633,19 +1671,19 @@ var InvitationsHandler = class {
1633
1671
  ...protocol.toJSON()
1634
1672
  }, {
1635
1673
  file: "invitations-handler.ts",
1636
- line: 363,
1674
+ line: 314,
1637
1675
  scope: this,
1638
1676
  callSite: (f, a) => f(...a)
1639
1677
  });
1640
1678
  setState({
1641
1679
  ...result,
1642
- state: Invitation2.State.SUCCESS
1680
+ state: Invitation3.State.SUCCESS
1643
1681
  });
1644
1682
  log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.end({
1645
1683
  id: traceId
1646
1684
  }), {
1647
1685
  file: "invitations-handler.ts",
1648
- line: 365,
1686
+ line: 316,
1649
1687
  scope: this,
1650
1688
  callSite: (f, a) => f(...a)
1651
1689
  });
@@ -1655,17 +1693,17 @@ var InvitationsHandler = class {
1655
1693
  ...protocol.toJSON()
1656
1694
  }, {
1657
1695
  file: "invitations-handler.ts",
1658
- line: 368,
1696
+ line: 319,
1659
1697
  scope: this,
1660
1698
  callSite: (f, a) => f(...a)
1661
1699
  });
1662
1700
  setState({
1663
- state: Invitation2.State.TIMEOUT
1701
+ state: Invitation3.State.TIMEOUT
1664
1702
  });
1665
1703
  } else {
1666
1704
  log5("auth failed", err, {
1667
1705
  file: "invitations-handler.ts",
1668
- line: 371,
1706
+ line: 322,
1669
1707
  scope: this,
1670
1708
  callSite: (f, a) => f(...a)
1671
1709
  });
@@ -1676,7 +1714,7 @@ var InvitationsHandler = class {
1676
1714
  error: err
1677
1715
  }), {
1678
1716
  file: "invitations-handler.ts",
1679
- line: 374,
1717
+ line: 325,
1680
1718
  scope: this,
1681
1719
  callSite: (f, a) => f(...a)
1682
1720
  });
@@ -1694,17 +1732,17 @@ var InvitationsHandler = class {
1694
1732
  ...protocol.toJSON()
1695
1733
  }, {
1696
1734
  file: "invitations-handler.ts",
1697
- line: 385,
1735
+ line: 336,
1698
1736
  scope: this,
1699
1737
  callSite: (f, a) => f(...a)
1700
1738
  });
1701
1739
  setState({
1702
- state: Invitation2.State.TIMEOUT
1740
+ state: Invitation3.State.TIMEOUT
1703
1741
  });
1704
1742
  } else {
1705
1743
  log5("auth failed", err, {
1706
1744
  file: "invitations-handler.ts",
1707
- line: 388,
1745
+ line: 339,
1708
1746
  scope: this,
1709
1747
  callSite: (f, a) => f(...a)
1710
1748
  });
@@ -1727,7 +1765,7 @@ var InvitationsHandler = class {
1727
1765
  });
1728
1766
  ctx.onDispose(() => swarmConnection.close());
1729
1767
  setState({
1730
- state: Invitation2.State.CONNECTING
1768
+ state: Invitation3.State.CONNECTING
1731
1769
  });
1732
1770
  });
1733
1771
  const observable = new AuthenticatingInvitationObservable({
@@ -1735,7 +1773,7 @@ var InvitationsHandler = class {
1735
1773
  subscriber: stream.observable,
1736
1774
  onCancel: async () => {
1737
1775
  setState({
1738
- state: Invitation2.State.CANCELLED
1776
+ state: Invitation3.State.CANCELLED
1739
1777
  });
1740
1778
  await ctx.dispose();
1741
1779
  },
@@ -1746,7 +1784,6 @@ var InvitationsHandler = class {
1746
1784
  return observable;
1747
1785
  }
1748
1786
  };
1749
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
1750
1787
 
1751
1788
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1752
1789
  import assert7 from "@dxos/node-std/assert";
@@ -1921,7 +1958,7 @@ import assert8 from "@dxos/node-std/assert";
1921
1958
  import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
1922
1959
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
1923
1960
  import { log as log7 } from "@dxos/log";
1924
- import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1961
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
1925
1962
  var SpaceInvitationProtocol = class {
1926
1963
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
1927
1964
  this._spaceManager = _spaceManager;
@@ -1937,7 +1974,7 @@ var SpaceInvitationProtocol = class {
1937
1974
  }
1938
1975
  getInvitationContext() {
1939
1976
  return {
1940
- kind: Invitation3.Kind.SPACE,
1977
+ kind: Invitation4.Kind.SPACE,
1941
1978
  spaceKey: this._spaceKey
1942
1979
  };
1943
1980
  }
@@ -2785,6 +2822,14 @@ var DataSpaceManager = class DataSpaceManager2 {
2785
2822
  session.addExtension("dxos.mesh.teleport.objectsync", space.snapshotManager.objectSync.createExtension());
2786
2823
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2787
2824
  },
2825
+ onAuthFailure: () => {
2826
+ log10.warn("auth failure", {}, {
2827
+ file: "data-space-manager.ts",
2828
+ line: 212,
2829
+ scope: this,
2830
+ callSite: (f, a) => f(...a)
2831
+ });
2832
+ },
2788
2833
  memberKey: this._signingContext.identityKey
2789
2834
  });
2790
2835
  controlFeed && space.setControlFeed(controlFeed);
@@ -2803,7 +2848,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2803
2848
  space: space.key
2804
2849
  }, {
2805
2850
  file: "data-space-manager.ts",
2806
- line: 226,
2851
+ line: 229,
2807
2852
  scope: this,
2808
2853
  callSite: (f, a) => f(...a)
2809
2854
  });
@@ -2815,7 +2860,7 @@ var DataSpaceManager = class DataSpaceManager2 {
2815
2860
  open: this._isOpen
2816
2861
  }, {
2817
2862
  file: "data-space-manager.ts",
2818
- line: 233,
2863
+ line: 236,
2819
2864
  scope: this,
2820
2865
  callSite: (f, a) => f(...a)
2821
2866
  });
@@ -3862,7 +3907,7 @@ import { Keyring } from "@dxos/keyring";
3862
3907
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3863
3908
  import { log as log17 } from "@dxos/log";
3864
3909
  import { STORAGE_VERSION, trace as trace5 } from "@dxos/protocols";
3865
- import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
3910
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3866
3911
  var ServiceContext = class {
3867
3912
  // prettier-ignore
3868
3913
  constructor(storage, networkManager, signalManager, modelFactory) {
@@ -3895,7 +3940,7 @@ var ServiceContext = class {
3895
3940
  });
3896
3941
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
3897
3942
  this.invitations = new InvitationsHandler(this.networkManager);
3898
- this._handlerFactories.set(Invitation4.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3943
+ this._handlerFactories.set(Invitation5.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
3899
3944
  var _a;
3900
3945
  return (_a = this.identityManager.identity) != null ? _a : failUndefined3();
3901
3946
  }, this._acceptIdentity.bind(this)));
@@ -4016,7 +4061,7 @@ var ServiceContext = class {
4016
4061
  };
4017
4062
  this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
4018
4063
  await this.dataSpaceManager.open();
4019
- this._handlerFactories.set(Invitation4.Kind.SPACE, (invitation) => {
4064
+ this._handlerFactories.set(Invitation5.Kind.SPACE, (invitation) => {
4020
4065
  assert13(this.dataSpaceManager, "dataSpaceManager not initialized yet");
4021
4066
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
4022
4067
  });
@@ -4510,4 +4555,4 @@ export {
4510
4555
  ClientServicesHost,
4511
4556
  LocalClientServices
4512
4557
  };
4513
- //# sourceMappingURL=chunk-MGKMTUPD.mjs.map
4558
+ //# sourceMappingURL=chunk-LGYQZ6UO.mjs.map