@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.
- package/dist/lib/browser/{chunk-2DGNNQWS.mjs → chunk-LGMYP2WL.mjs} +679 -569
- package/dist/lib/browser/chunk-LGMYP2WL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +14 -14
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +721 -611
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +725 -621
- package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts +54 -0
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +8 -3
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
- package/package.json +30 -30
- package/src/packlets/invitations/invitation-extension.ts +211 -0
- package/src/packlets/invitations/invitations-handler.ts +54 -123
- package/src/packlets/invitations/invitations-service.ts +106 -137
- package/src/packlets/services/utils.ts +3 -3
- package/src/packlets/testing/test-builder.ts +9 -7
- package/src/packlets/vault/iframe-host-runtime.ts +3 -3
- package/src/packlets/vault/iframe-proxy-runtime.ts +11 -3
- package/src/packlets/vault/worker-runtime.ts +3 -3
- package/dist/lib/browser/chunk-2DGNNQWS.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -993,18 +993,236 @@ var DeviceInvitationProtocol = class {
|
|
|
993
993
|
};
|
|
994
994
|
|
|
995
995
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
996
|
+
var import_node_assert6 = __toESM(require("node:assert"));
|
|
997
|
+
var import_async7 = require("@dxos/async");
|
|
998
|
+
var import_client = require("@dxos/client");
|
|
999
|
+
var import_context4 = require("@dxos/context");
|
|
1000
|
+
var import_credentials7 = require("@dxos/credentials");
|
|
1001
|
+
var import_errors2 = require("@dxos/errors");
|
|
1002
|
+
var import_keys6 = require("@dxos/keys");
|
|
1003
|
+
var import_log5 = require("@dxos/log");
|
|
1004
|
+
var import_network_manager = require("@dxos/network-manager");
|
|
1005
|
+
var import_protocols4 = require("@dxos/protocols");
|
|
1006
|
+
var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1007
|
+
var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
1008
|
+
|
|
1009
|
+
// packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
|
|
996
1010
|
var import_node_assert5 = __toESM(require("node:assert"));
|
|
997
1011
|
var import_async6 = require("@dxos/async");
|
|
998
|
-
var import_client = require("@dxos/client");
|
|
999
1012
|
var import_context3 = require("@dxos/context");
|
|
1000
|
-
var
|
|
1013
|
+
var import_errors = require("@dxos/errors");
|
|
1001
1014
|
var import_keys5 = require("@dxos/keys");
|
|
1002
1015
|
var import_log4 = require("@dxos/log");
|
|
1003
|
-
var import_network_manager = require("@dxos/network-manager");
|
|
1004
1016
|
var import_protocols3 = require("@dxos/protocols");
|
|
1005
|
-
var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1006
1017
|
var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
1007
1018
|
var import_teleport = require("@dxos/teleport");
|
|
1019
|
+
var OPTIONS_TIMEOUT = 1e4;
|
|
1020
|
+
var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
1021
|
+
constructor(_callbacks) {
|
|
1022
|
+
super({
|
|
1023
|
+
requested: {
|
|
1024
|
+
InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1025
|
+
},
|
|
1026
|
+
exposed: {
|
|
1027
|
+
InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
this._callbacks = _callbacks;
|
|
1031
|
+
this._ctx = new import_context3.Context();
|
|
1032
|
+
this._remoteOptionsTrigger = new import_async6.Trigger();
|
|
1033
|
+
}
|
|
1034
|
+
async getHandlers() {
|
|
1035
|
+
return {
|
|
1036
|
+
// TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
|
|
1037
|
+
// Perhaps in the future we will have more complex logic here.
|
|
1038
|
+
InvitationHostService: {
|
|
1039
|
+
options: async (options) => {
|
|
1040
|
+
(0, import_node_assert5.default)(!this._remoteOptions, "Remote options already set.");
|
|
1041
|
+
this._remoteOptions = options;
|
|
1042
|
+
this._remoteOptionsTrigger.wake();
|
|
1043
|
+
},
|
|
1044
|
+
introduce: async (request) => {
|
|
1045
|
+
const traceId = import_keys5.PublicKey.random().toHex();
|
|
1046
|
+
import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
|
|
1047
|
+
id: traceId,
|
|
1048
|
+
parentId: this._traceParent
|
|
1049
|
+
}), {
|
|
1050
|
+
file: "invitation-extension.ts",
|
|
1051
|
+
line: 78,
|
|
1052
|
+
scope: this,
|
|
1053
|
+
callSite: (f, a) => f(...a)
|
|
1054
|
+
});
|
|
1055
|
+
const response = await this._callbacks.introduce(request);
|
|
1056
|
+
import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
|
|
1057
|
+
id: traceId
|
|
1058
|
+
}), {
|
|
1059
|
+
file: "invitation-extension.ts",
|
|
1060
|
+
line: 83,
|
|
1061
|
+
scope: this,
|
|
1062
|
+
callSite: (f, a) => f(...a)
|
|
1063
|
+
});
|
|
1064
|
+
return response;
|
|
1065
|
+
},
|
|
1066
|
+
authenticate: async (request) => {
|
|
1067
|
+
const traceId = import_keys5.PublicKey.random().toHex();
|
|
1068
|
+
import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
|
|
1069
|
+
id: traceId,
|
|
1070
|
+
parentId: this._traceParent
|
|
1071
|
+
}), {
|
|
1072
|
+
file: "invitation-extension.ts",
|
|
1073
|
+
line: 89,
|
|
1074
|
+
scope: this,
|
|
1075
|
+
callSite: (f, a) => f(...a)
|
|
1076
|
+
});
|
|
1077
|
+
const response = await this._callbacks.authenticate(request);
|
|
1078
|
+
import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.end({
|
|
1079
|
+
id: traceId,
|
|
1080
|
+
data: {
|
|
1081
|
+
...response
|
|
1082
|
+
}
|
|
1083
|
+
}), {
|
|
1084
|
+
file: "invitation-extension.ts",
|
|
1085
|
+
line: 94,
|
|
1086
|
+
scope: this,
|
|
1087
|
+
callSite: (f, a) => f(...a)
|
|
1088
|
+
});
|
|
1089
|
+
return response;
|
|
1090
|
+
},
|
|
1091
|
+
admit: async (request) => {
|
|
1092
|
+
const traceId = import_keys5.PublicKey.random().toHex();
|
|
1093
|
+
import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
|
|
1094
|
+
id: traceId,
|
|
1095
|
+
parentId: this._traceParent
|
|
1096
|
+
}), {
|
|
1097
|
+
file: "invitation-extension.ts",
|
|
1098
|
+
line: 100,
|
|
1099
|
+
scope: this,
|
|
1100
|
+
callSite: (f, a) => f(...a)
|
|
1101
|
+
});
|
|
1102
|
+
const response = await this._callbacks.admit(request);
|
|
1103
|
+
import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.end({
|
|
1104
|
+
id: traceId
|
|
1105
|
+
}), {
|
|
1106
|
+
file: "invitation-extension.ts",
|
|
1107
|
+
line: 105,
|
|
1108
|
+
scope: this,
|
|
1109
|
+
callSite: (f, a) => f(...a)
|
|
1110
|
+
});
|
|
1111
|
+
return response;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
async onOpen(context) {
|
|
1117
|
+
var _a;
|
|
1118
|
+
await super.onOpen(context);
|
|
1119
|
+
try {
|
|
1120
|
+
await this.rpc.InvitationHostService.options({
|
|
1121
|
+
role: import_invitations.Options.Role.HOST
|
|
1122
|
+
});
|
|
1123
|
+
await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1124
|
+
timeout: OPTIONS_TIMEOUT
|
|
1125
|
+
}));
|
|
1126
|
+
if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.GUEST) {
|
|
1127
|
+
throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
|
|
1128
|
+
expected: import_invitations.Options.Role.GUEST,
|
|
1129
|
+
remoteOptions: this._remoteOptions
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
this._callbacks.onOpen();
|
|
1133
|
+
} catch (err) {
|
|
1134
|
+
this._callbacks.onError(err);
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
async onClose() {
|
|
1138
|
+
await this._ctx.dispose();
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
1142
|
+
constructor(_callbacks) {
|
|
1143
|
+
super({
|
|
1144
|
+
requested: {
|
|
1145
|
+
InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1146
|
+
},
|
|
1147
|
+
exposed: {
|
|
1148
|
+
InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1149
|
+
}
|
|
1150
|
+
});
|
|
1151
|
+
this._callbacks = _callbacks;
|
|
1152
|
+
this._ctx = new import_context3.Context();
|
|
1153
|
+
this._remoteOptionsTrigger = new import_async6.Trigger();
|
|
1154
|
+
}
|
|
1155
|
+
async getHandlers() {
|
|
1156
|
+
return {
|
|
1157
|
+
InvitationHostService: {
|
|
1158
|
+
options: async (options) => {
|
|
1159
|
+
(0, import_node_assert5.default)(!this._remoteOptions, "Remote options already set.");
|
|
1160
|
+
this._remoteOptions = options;
|
|
1161
|
+
this._remoteOptionsTrigger.wake();
|
|
1162
|
+
},
|
|
1163
|
+
introduce: () => {
|
|
1164
|
+
throw new Error("Method not allowed.");
|
|
1165
|
+
},
|
|
1166
|
+
authenticate: () => {
|
|
1167
|
+
throw new Error("Method not allowed.");
|
|
1168
|
+
},
|
|
1169
|
+
admit: () => {
|
|
1170
|
+
throw new Error("Method not allowed.");
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
async onOpen(context) {
|
|
1176
|
+
var _a;
|
|
1177
|
+
await super.onOpen(context);
|
|
1178
|
+
try {
|
|
1179
|
+
(0, import_log4.log)("begin options", {}, {
|
|
1180
|
+
file: "invitation-extension.ts",
|
|
1181
|
+
line: 189,
|
|
1182
|
+
scope: this,
|
|
1183
|
+
callSite: (f, a) => f(...a)
|
|
1184
|
+
});
|
|
1185
|
+
await (0, import_context3.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
|
|
1186
|
+
role: import_invitations.Options.Role.GUEST
|
|
1187
|
+
}));
|
|
1188
|
+
await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1189
|
+
timeout: OPTIONS_TIMEOUT
|
|
1190
|
+
}));
|
|
1191
|
+
(0, import_log4.log)("end options", {}, {
|
|
1192
|
+
file: "invitation-extension.ts",
|
|
1193
|
+
line: 192,
|
|
1194
|
+
scope: this,
|
|
1195
|
+
callSite: (f, a) => f(...a)
|
|
1196
|
+
});
|
|
1197
|
+
if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== import_invitations.Options.Role.HOST) {
|
|
1198
|
+
throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
|
|
1199
|
+
expected: import_invitations.Options.Role.HOST,
|
|
1200
|
+
remoteOptions: this._remoteOptions
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
this._callbacks.onOpen(this._ctx);
|
|
1204
|
+
} catch (err) {
|
|
1205
|
+
(0, import_log4.log)("openError", err, {
|
|
1206
|
+
file: "invitation-extension.ts",
|
|
1207
|
+
line: 202,
|
|
1208
|
+
scope: this,
|
|
1209
|
+
callSite: (f, a) => f(...a)
|
|
1210
|
+
});
|
|
1211
|
+
this._callbacks.onError(err);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
async onClose() {
|
|
1215
|
+
(0, import_log4.log)("onClose", {}, {
|
|
1216
|
+
file: "invitation-extension.ts",
|
|
1217
|
+
line: 208,
|
|
1218
|
+
scope: this,
|
|
1219
|
+
callSite: (f, a) => f(...a)
|
|
1220
|
+
});
|
|
1221
|
+
await this._ctx.dispose();
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
|
|
1225
|
+
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1008
1226
|
var MAX_OTP_ATTEMPTS = 3;
|
|
1009
1227
|
var InvitationsHandler = class {
|
|
1010
1228
|
constructor(_networkManager) {
|
|
@@ -1012,9 +1230,9 @@ var InvitationsHandler = class {
|
|
|
1012
1230
|
}
|
|
1013
1231
|
createInvitation(protocol, options) {
|
|
1014
1232
|
var _a;
|
|
1015
|
-
const { invitationId =
|
|
1233
|
+
const { invitationId = import_keys6.PublicKey.random().toHex(), type = import_services2.Invitation.Type.INTERACTIVE, authMethod = import_services2.Invitation.AuthMethod.SHARED_SECRET, state = import_services2.Invitation.State.INIT, timeout = import_client.INVITATION_TIMEOUT, swarmKey = import_keys6.PublicKey.random() } = options != null ? options : {};
|
|
1016
1234
|
const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === import_services2.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client.AUTHENTICATION_CODE_LENGTH) : void 0;
|
|
1017
|
-
(0,
|
|
1235
|
+
(0, import_node_assert6.default)(protocol);
|
|
1018
1236
|
const invitation = {
|
|
1019
1237
|
invitationId,
|
|
1020
1238
|
type,
|
|
@@ -1025,37 +1243,37 @@ var InvitationsHandler = class {
|
|
|
1025
1243
|
timeout,
|
|
1026
1244
|
...protocol.getInvitationContext()
|
|
1027
1245
|
};
|
|
1028
|
-
const stream = new
|
|
1029
|
-
const ctx = new
|
|
1246
|
+
const stream = new import_async7.PushStream();
|
|
1247
|
+
const ctx = new import_context4.Context({
|
|
1030
1248
|
onError: (err) => {
|
|
1031
1249
|
void ctx.dispose();
|
|
1032
1250
|
stream.error(err);
|
|
1033
1251
|
}
|
|
1034
1252
|
});
|
|
1035
1253
|
ctx.onDispose(() => {
|
|
1036
|
-
(0,
|
|
1254
|
+
(0, import_log5.log)("complete", {
|
|
1037
1255
|
...protocol.toJSON()
|
|
1038
1256
|
}, {
|
|
1039
1257
|
file: "invitations-handler.ts",
|
|
1040
|
-
line:
|
|
1258
|
+
line: 99,
|
|
1041
1259
|
scope: this,
|
|
1042
1260
|
callSite: (f, a) => f(...a)
|
|
1043
1261
|
});
|
|
1044
1262
|
stream.complete();
|
|
1045
1263
|
});
|
|
1046
1264
|
const createExtension = () => {
|
|
1047
|
-
const success = new
|
|
1265
|
+
const success = new import_async7.Trigger();
|
|
1048
1266
|
let guestProfile;
|
|
1049
1267
|
let authenticationPassed = false;
|
|
1050
1268
|
let authenticationRetry = 0;
|
|
1051
1269
|
const extension = new InvitationHostExtension({
|
|
1052
1270
|
introduce: async ({ profile }) => {
|
|
1053
|
-
(0,
|
|
1271
|
+
(0, import_log5.log)("guest introduced itself", {
|
|
1054
1272
|
guestProfile: profile,
|
|
1055
1273
|
...protocol.toJSON()
|
|
1056
1274
|
}, {
|
|
1057
1275
|
file: "invitations-handler.ts",
|
|
1058
|
-
line:
|
|
1276
|
+
line: 112,
|
|
1059
1277
|
scope: this,
|
|
1060
1278
|
callSite: (f, a) => f(...a)
|
|
1061
1279
|
});
|
|
@@ -1070,33 +1288,33 @@ var InvitationsHandler = class {
|
|
|
1070
1288
|
};
|
|
1071
1289
|
},
|
|
1072
1290
|
authenticate: async ({ authCode: code }) => {
|
|
1073
|
-
(0,
|
|
1291
|
+
(0, import_log5.log)("received authentication request", {
|
|
1074
1292
|
authCode: code
|
|
1075
1293
|
}, {
|
|
1076
1294
|
file: "invitations-handler.ts",
|
|
1077
|
-
line:
|
|
1295
|
+
line: 131,
|
|
1078
1296
|
scope: this,
|
|
1079
1297
|
callSite: (f, a) => f(...a)
|
|
1080
1298
|
});
|
|
1081
|
-
let status =
|
|
1299
|
+
let status = import_invitations2.AuthenticationResponse.Status.OK;
|
|
1082
1300
|
switch (invitation.authMethod) {
|
|
1083
1301
|
case import_services2.Invitation.AuthMethod.NONE: {
|
|
1084
|
-
(0,
|
|
1302
|
+
(0, import_log5.log)("authentication not required", {}, {
|
|
1085
1303
|
file: "invitations-handler.ts",
|
|
1086
|
-
line:
|
|
1304
|
+
line: 136,
|
|
1087
1305
|
scope: this,
|
|
1088
1306
|
callSite: (f, a) => f(...a)
|
|
1089
1307
|
});
|
|
1090
1308
|
return {
|
|
1091
|
-
status:
|
|
1309
|
+
status: import_invitations2.AuthenticationResponse.Status.OK
|
|
1092
1310
|
};
|
|
1093
1311
|
}
|
|
1094
1312
|
case import_services2.Invitation.AuthMethod.SHARED_SECRET: {
|
|
1095
1313
|
if (invitation.authCode) {
|
|
1096
1314
|
if (authenticationRetry++ > MAX_OTP_ATTEMPTS) {
|
|
1097
|
-
status =
|
|
1315
|
+
status = import_invitations2.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
|
|
1098
1316
|
} else if (code !== invitation.authCode) {
|
|
1099
|
-
status =
|
|
1317
|
+
status = import_invitations2.AuthenticationResponse.Status.INVALID_OTP;
|
|
1100
1318
|
} else {
|
|
1101
1319
|
authenticationPassed = true;
|
|
1102
1320
|
}
|
|
@@ -1104,15 +1322,15 @@ var InvitationsHandler = class {
|
|
|
1104
1322
|
break;
|
|
1105
1323
|
}
|
|
1106
1324
|
default: {
|
|
1107
|
-
|
|
1325
|
+
import_log5.log.error("invalid authentication method", {
|
|
1108
1326
|
authMethod: invitation.authMethod
|
|
1109
1327
|
}, {
|
|
1110
1328
|
file: "invitations-handler.ts",
|
|
1111
|
-
line:
|
|
1329
|
+
line: 154,
|
|
1112
1330
|
scope: this,
|
|
1113
1331
|
callSite: (f, a) => f(...a)
|
|
1114
1332
|
});
|
|
1115
|
-
status =
|
|
1333
|
+
status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
|
|
1116
1334
|
break;
|
|
1117
1335
|
}
|
|
1118
1336
|
}
|
|
@@ -1127,7 +1345,7 @@ var InvitationsHandler = class {
|
|
|
1127
1345
|
throw new Error("Not authenticated");
|
|
1128
1346
|
}
|
|
1129
1347
|
const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
|
|
1130
|
-
(0,
|
|
1348
|
+
(0, import_node_assert6.default)(deviceKey);
|
|
1131
1349
|
const admissionResponse = await protocol.admit(admissionRequest, guestProfile);
|
|
1132
1350
|
success.wake(deviceKey);
|
|
1133
1351
|
return admissionResponse;
|
|
@@ -1137,23 +1355,23 @@ var InvitationsHandler = class {
|
|
|
1137
1355
|
}
|
|
1138
1356
|
},
|
|
1139
1357
|
onOpen: () => {
|
|
1140
|
-
(0,
|
|
1141
|
-
const traceId =
|
|
1358
|
+
(0, import_async7.scheduleTask)(ctx, async () => {
|
|
1359
|
+
const traceId = import_keys6.PublicKey.random().toHex();
|
|
1142
1360
|
try {
|
|
1143
|
-
|
|
1361
|
+
import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
|
|
1144
1362
|
id: traceId,
|
|
1145
1363
|
parentId: this._traceParent
|
|
1146
1364
|
}), {
|
|
1147
1365
|
file: "invitations-handler.ts",
|
|
1148
|
-
line:
|
|
1366
|
+
line: 189,
|
|
1149
1367
|
scope: this,
|
|
1150
1368
|
callSite: (f, a) => f(...a)
|
|
1151
1369
|
});
|
|
1152
|
-
(0,
|
|
1370
|
+
(0, import_log5.log)("connected", {
|
|
1153
1371
|
...protocol.toJSON()
|
|
1154
1372
|
}, {
|
|
1155
1373
|
file: "invitations-handler.ts",
|
|
1156
|
-
line:
|
|
1374
|
+
line: 193,
|
|
1157
1375
|
scope: this,
|
|
1158
1376
|
callSite: (f, a) => f(...a)
|
|
1159
1377
|
});
|
|
@@ -1164,12 +1382,12 @@ var InvitationsHandler = class {
|
|
|
1164
1382
|
const deviceKey = await success.wait({
|
|
1165
1383
|
timeout
|
|
1166
1384
|
});
|
|
1167
|
-
(0,
|
|
1385
|
+
(0, import_log5.log)("admitted guest", {
|
|
1168
1386
|
guest: deviceKey,
|
|
1169
1387
|
...protocol.toJSON()
|
|
1170
1388
|
}, {
|
|
1171
1389
|
file: "invitations-handler.ts",
|
|
1172
|
-
line:
|
|
1390
|
+
line: 196,
|
|
1173
1391
|
scope: this,
|
|
1174
1392
|
callSite: (f, a) => f(...a)
|
|
1175
1393
|
});
|
|
@@ -1177,21 +1395,21 @@ var InvitationsHandler = class {
|
|
|
1177
1395
|
...invitation,
|
|
1178
1396
|
state: import_services2.Invitation.State.SUCCESS
|
|
1179
1397
|
});
|
|
1180
|
-
|
|
1398
|
+
import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
|
|
1181
1399
|
id: traceId
|
|
1182
1400
|
}), {
|
|
1183
1401
|
file: "invitations-handler.ts",
|
|
1184
|
-
line:
|
|
1402
|
+
line: 198,
|
|
1185
1403
|
scope: this,
|
|
1186
1404
|
callSite: (f, a) => f(...a)
|
|
1187
1405
|
});
|
|
1188
1406
|
} catch (err) {
|
|
1189
|
-
if (err instanceof
|
|
1190
|
-
(0,
|
|
1407
|
+
if (err instanceof import_async7.TimeoutError) {
|
|
1408
|
+
(0, import_log5.log)("timeout", {
|
|
1191
1409
|
...protocol.toJSON()
|
|
1192
1410
|
}, {
|
|
1193
1411
|
file: "invitations-handler.ts",
|
|
1194
|
-
line:
|
|
1412
|
+
line: 201,
|
|
1195
1413
|
scope: this,
|
|
1196
1414
|
callSite: (f, a) => f(...a)
|
|
1197
1415
|
});
|
|
@@ -1200,36 +1418,63 @@ var InvitationsHandler = class {
|
|
|
1200
1418
|
state: import_services2.Invitation.State.TIMEOUT
|
|
1201
1419
|
});
|
|
1202
1420
|
} else {
|
|
1203
|
-
|
|
1421
|
+
import_log5.log.error("failed", err, {
|
|
1204
1422
|
file: "invitations-handler.ts",
|
|
1205
|
-
line:
|
|
1423
|
+
line: 204,
|
|
1206
1424
|
scope: this,
|
|
1207
1425
|
callSite: (f, a) => f(...a)
|
|
1208
1426
|
});
|
|
1209
1427
|
stream.error(err);
|
|
1210
1428
|
}
|
|
1211
|
-
|
|
1429
|
+
import_log5.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
|
|
1212
1430
|
id: traceId,
|
|
1213
1431
|
error: err
|
|
1214
1432
|
}), {
|
|
1215
1433
|
file: "invitations-handler.ts",
|
|
1216
|
-
line:
|
|
1434
|
+
line: 207,
|
|
1217
1435
|
scope: this,
|
|
1218
1436
|
callSite: (f, a) => f(...a)
|
|
1219
1437
|
});
|
|
1220
1438
|
} finally {
|
|
1221
1439
|
if (type !== import_services2.Invitation.Type.MULTIUSE) {
|
|
1222
|
-
await (0,
|
|
1440
|
+
await (0, import_async7.sleep)(import_client.ON_CLOSE_DELAY);
|
|
1223
1441
|
await ctx.dispose();
|
|
1224
1442
|
}
|
|
1225
1443
|
}
|
|
1226
1444
|
});
|
|
1445
|
+
},
|
|
1446
|
+
onError: (err) => {
|
|
1447
|
+
if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
if (err instanceof import_async7.TimeoutError) {
|
|
1451
|
+
(0, import_log5.log)("timeout", {
|
|
1452
|
+
...protocol.toJSON()
|
|
1453
|
+
}, {
|
|
1454
|
+
file: "invitations-handler.ts",
|
|
1455
|
+
line: 221,
|
|
1456
|
+
scope: this,
|
|
1457
|
+
callSite: (f, a) => f(...a)
|
|
1458
|
+
});
|
|
1459
|
+
stream.next({
|
|
1460
|
+
...invitation,
|
|
1461
|
+
state: import_services2.Invitation.State.TIMEOUT
|
|
1462
|
+
});
|
|
1463
|
+
} else {
|
|
1464
|
+
import_log5.log.error("failed", err, {
|
|
1465
|
+
file: "invitations-handler.ts",
|
|
1466
|
+
line: 224,
|
|
1467
|
+
scope: this,
|
|
1468
|
+
callSite: (f, a) => f(...a)
|
|
1469
|
+
});
|
|
1470
|
+
stream.error(err);
|
|
1471
|
+
}
|
|
1227
1472
|
}
|
|
1228
1473
|
});
|
|
1229
1474
|
extension._traceParent = this._traceParent;
|
|
1230
1475
|
return extension;
|
|
1231
1476
|
};
|
|
1232
|
-
(0,
|
|
1477
|
+
(0, import_async7.scheduleTask)(ctx, async () => {
|
|
1233
1478
|
const topic = invitation.swarmKey;
|
|
1234
1479
|
const swarmConnection = await this._networkManager.joinSwarm({
|
|
1235
1480
|
topic,
|
|
@@ -1260,28 +1505,36 @@ var InvitationsHandler = class {
|
|
|
1260
1505
|
}
|
|
1261
1506
|
acceptInvitation(protocol, invitation) {
|
|
1262
1507
|
const { timeout = import_client.INVITATION_TIMEOUT } = invitation;
|
|
1263
|
-
(0,
|
|
1264
|
-
const authenticated = new
|
|
1265
|
-
|
|
1266
|
-
const
|
|
1508
|
+
(0, import_node_assert6.default)(protocol);
|
|
1509
|
+
const authenticated = new import_async7.Trigger();
|
|
1510
|
+
let currentState;
|
|
1511
|
+
const stream = new import_async7.PushStream();
|
|
1512
|
+
const setState = (newData) => {
|
|
1513
|
+
(0, import_node_assert6.default)(newData.state !== void 0);
|
|
1514
|
+
currentState = newData.state;
|
|
1515
|
+
stream.next({
|
|
1516
|
+
...invitation,
|
|
1517
|
+
...newData
|
|
1518
|
+
});
|
|
1519
|
+
};
|
|
1520
|
+
const ctx = new import_context4.Context({
|
|
1267
1521
|
onError: (err) => {
|
|
1268
|
-
if (err instanceof
|
|
1269
|
-
(0,
|
|
1522
|
+
if (err instanceof import_async7.TimeoutError) {
|
|
1523
|
+
(0, import_log5.log)("timeout", {
|
|
1270
1524
|
...protocol.toJSON()
|
|
1271
1525
|
}, {
|
|
1272
1526
|
file: "invitations-handler.ts",
|
|
1273
|
-
line:
|
|
1527
|
+
line: 279,
|
|
1274
1528
|
scope: this,
|
|
1275
1529
|
callSite: (f, a) => f(...a)
|
|
1276
1530
|
});
|
|
1277
|
-
|
|
1278
|
-
...invitation,
|
|
1531
|
+
setState({
|
|
1279
1532
|
state: import_services2.Invitation.State.TIMEOUT
|
|
1280
1533
|
});
|
|
1281
1534
|
} else {
|
|
1282
|
-
|
|
1535
|
+
import_log5.log.warn("auth failed", err, {
|
|
1283
1536
|
file: "invitations-handler.ts",
|
|
1284
|
-
line:
|
|
1537
|
+
line: 282,
|
|
1285
1538
|
scope: this,
|
|
1286
1539
|
callSite: (f, a) => f(...a)
|
|
1287
1540
|
});
|
|
@@ -1291,11 +1544,11 @@ var InvitationsHandler = class {
|
|
|
1291
1544
|
}
|
|
1292
1545
|
});
|
|
1293
1546
|
ctx.onDispose(() => {
|
|
1294
|
-
(0,
|
|
1547
|
+
(0, import_log5.log)("complete", {
|
|
1295
1548
|
...protocol.toJSON()
|
|
1296
1549
|
}, {
|
|
1297
1550
|
file: "invitations-handler.ts",
|
|
1298
|
-
line:
|
|
1551
|
+
line: 290,
|
|
1299
1552
|
scope: this,
|
|
1300
1553
|
callSite: (f, a) => f(...a)
|
|
1301
1554
|
});
|
|
@@ -1304,50 +1557,62 @@ var InvitationsHandler = class {
|
|
|
1304
1557
|
const createExtension = () => {
|
|
1305
1558
|
let connectionCount = 0;
|
|
1306
1559
|
const extension = new InvitationGuestExtension({
|
|
1307
|
-
onOpen: () => {
|
|
1308
|
-
|
|
1309
|
-
|
|
1560
|
+
onOpen: (extensionCtx) => {
|
|
1561
|
+
extensionCtx.onDispose(async () => {
|
|
1562
|
+
(0, import_log5.log)("extension disposed", {
|
|
1563
|
+
currentState
|
|
1564
|
+
}, {
|
|
1565
|
+
file: "invitations-handler.ts",
|
|
1566
|
+
line: 300,
|
|
1567
|
+
scope: this,
|
|
1568
|
+
callSite: (f, a) => f(...a)
|
|
1569
|
+
});
|
|
1570
|
+
if (currentState !== import_services2.Invitation.State.SUCCESS) {
|
|
1571
|
+
stream.error(new Error("Remote peer disconnected."));
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
(0, import_async7.scheduleTask)(ctx, async () => {
|
|
1575
|
+
const traceId = import_keys6.PublicKey.random().toHex();
|
|
1310
1576
|
try {
|
|
1311
|
-
|
|
1577
|
+
import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
|
|
1312
1578
|
id: traceId,
|
|
1313
1579
|
parentId: this._traceParent
|
|
1314
1580
|
}), {
|
|
1315
1581
|
file: "invitations-handler.ts",
|
|
1316
|
-
line:
|
|
1582
|
+
line: 309,
|
|
1317
1583
|
scope: this,
|
|
1318
1584
|
callSite: (f, a) => f(...a)
|
|
1319
1585
|
});
|
|
1320
1586
|
if (++connectionCount > 1) {
|
|
1321
1587
|
throw new Error(`multiple connections detected: ${connectionCount}`);
|
|
1322
1588
|
}
|
|
1323
|
-
(0,
|
|
1324
|
-
(0,
|
|
1589
|
+
(0, import_async7.scheduleTask)(ctx, () => ctx.raise(new import_async7.TimeoutError(timeout)), timeout);
|
|
1590
|
+
(0, import_log5.log)("connected", {
|
|
1325
1591
|
...protocol.toJSON()
|
|
1326
1592
|
}, {
|
|
1327
1593
|
file: "invitations-handler.ts",
|
|
1328
|
-
line:
|
|
1594
|
+
line: 320,
|
|
1329
1595
|
scope: this,
|
|
1330
1596
|
callSite: (f, a) => f(...a)
|
|
1331
1597
|
});
|
|
1332
|
-
|
|
1333
|
-
...invitation,
|
|
1598
|
+
setState({
|
|
1334
1599
|
state: import_services2.Invitation.State.CONNECTED
|
|
1335
1600
|
});
|
|
1336
|
-
(0,
|
|
1601
|
+
(0, import_log5.log)("introduce", {
|
|
1337
1602
|
...protocol.toJSON()
|
|
1338
1603
|
}, {
|
|
1339
1604
|
file: "invitations-handler.ts",
|
|
1340
|
-
line:
|
|
1605
|
+
line: 324,
|
|
1341
1606
|
scope: this,
|
|
1342
1607
|
callSite: (f, a) => f(...a)
|
|
1343
1608
|
});
|
|
1344
1609
|
const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
|
|
1345
|
-
(0,
|
|
1610
|
+
(0, import_log5.log)("introduce response", {
|
|
1346
1611
|
...protocol.toJSON(),
|
|
1347
1612
|
response: introductionResponse
|
|
1348
1613
|
}, {
|
|
1349
1614
|
file: "invitations-handler.ts",
|
|
1350
|
-
line:
|
|
1615
|
+
line: 328,
|
|
1351
1616
|
scope: this,
|
|
1352
1617
|
callSite: (f, a) => f(...a)
|
|
1353
1618
|
});
|
|
@@ -1357,44 +1622,42 @@ var InvitationsHandler = class {
|
|
|
1357
1622
|
}
|
|
1358
1623
|
if (isAuthenticationRequired(invitation)) {
|
|
1359
1624
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
1360
|
-
(0,
|
|
1625
|
+
(0, import_log5.log)("guest waiting for authentication code...", {}, {
|
|
1361
1626
|
file: "invitations-handler.ts",
|
|
1362
|
-
line:
|
|
1627
|
+
line: 337,
|
|
1363
1628
|
scope: this,
|
|
1364
1629
|
callSite: (f, a) => f(...a)
|
|
1365
1630
|
});
|
|
1366
|
-
|
|
1367
|
-
...invitation,
|
|
1631
|
+
setState({
|
|
1368
1632
|
state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1369
1633
|
});
|
|
1370
1634
|
const authCode = await authenticated.wait({
|
|
1371
1635
|
timeout
|
|
1372
1636
|
});
|
|
1373
|
-
(0,
|
|
1637
|
+
(0, import_log5.log)("sending authentication request", {}, {
|
|
1374
1638
|
file: "invitations-handler.ts",
|
|
1375
|
-
line:
|
|
1639
|
+
line: 341,
|
|
1376
1640
|
scope: this,
|
|
1377
1641
|
callSite: (f, a) => f(...a)
|
|
1378
1642
|
});
|
|
1379
|
-
|
|
1380
|
-
...invitation,
|
|
1643
|
+
setState({
|
|
1381
1644
|
state: import_services2.Invitation.State.AUTHENTICATING
|
|
1382
1645
|
});
|
|
1383
1646
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
1384
1647
|
authCode
|
|
1385
1648
|
});
|
|
1386
|
-
if (response.status === void 0 || response.status ===
|
|
1649
|
+
if (response.status === void 0 || response.status === import_invitations2.AuthenticationResponse.Status.OK) {
|
|
1387
1650
|
break;
|
|
1388
1651
|
}
|
|
1389
|
-
if (response.status ===
|
|
1652
|
+
if (response.status === import_invitations2.AuthenticationResponse.Status.INVALID_OTP) {
|
|
1390
1653
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
1391
1654
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
1392
1655
|
} else {
|
|
1393
|
-
(0,
|
|
1656
|
+
(0, import_log5.log)("retrying invalid code", {
|
|
1394
1657
|
attempt
|
|
1395
1658
|
}, {
|
|
1396
1659
|
file: "invitations-handler.ts",
|
|
1397
|
-
line:
|
|
1660
|
+
line: 352,
|
|
1398
1661
|
scope: this,
|
|
1399
1662
|
callSite: (f, a) => f(...a)
|
|
1400
1663
|
});
|
|
@@ -1403,72 +1666,69 @@ var InvitationsHandler = class {
|
|
|
1403
1666
|
}
|
|
1404
1667
|
}
|
|
1405
1668
|
} else {
|
|
1406
|
-
|
|
1407
|
-
...invitation,
|
|
1669
|
+
setState({
|
|
1408
1670
|
state: import_services2.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1409
1671
|
});
|
|
1410
1672
|
}
|
|
1411
|
-
(0,
|
|
1673
|
+
(0, import_log5.log)("request admission", {
|
|
1412
1674
|
...protocol.toJSON()
|
|
1413
1675
|
}, {
|
|
1414
1676
|
file: "invitations-handler.ts",
|
|
1415
|
-
line:
|
|
1677
|
+
line: 363,
|
|
1416
1678
|
scope: this,
|
|
1417
1679
|
callSite: (f, a) => f(...a)
|
|
1418
1680
|
});
|
|
1419
1681
|
const admissionRequest = await protocol.createAdmissionRequest();
|
|
1420
1682
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
1421
1683
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
1422
|
-
(0,
|
|
1684
|
+
(0, import_log5.log)("admitted by host", {
|
|
1423
1685
|
...protocol.toJSON()
|
|
1424
1686
|
}, {
|
|
1425
1687
|
file: "invitations-handler.ts",
|
|
1426
|
-
line:
|
|
1688
|
+
line: 371,
|
|
1427
1689
|
scope: this,
|
|
1428
1690
|
callSite: (f, a) => f(...a)
|
|
1429
1691
|
});
|
|
1430
|
-
|
|
1431
|
-
...invitation,
|
|
1692
|
+
setState({
|
|
1432
1693
|
...result,
|
|
1433
1694
|
state: import_services2.Invitation.State.SUCCESS
|
|
1434
1695
|
});
|
|
1435
|
-
|
|
1696
|
+
import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
|
|
1436
1697
|
id: traceId
|
|
1437
1698
|
}), {
|
|
1438
1699
|
file: "invitations-handler.ts",
|
|
1439
|
-
line:
|
|
1700
|
+
line: 373,
|
|
1440
1701
|
scope: this,
|
|
1441
1702
|
callSite: (f, a) => f(...a)
|
|
1442
1703
|
});
|
|
1443
1704
|
} catch (err) {
|
|
1444
|
-
if (err instanceof
|
|
1445
|
-
(0,
|
|
1705
|
+
if (err instanceof import_async7.TimeoutError) {
|
|
1706
|
+
(0, import_log5.log)("timeout", {
|
|
1446
1707
|
...protocol.toJSON()
|
|
1447
1708
|
}, {
|
|
1448
1709
|
file: "invitations-handler.ts",
|
|
1449
|
-
line:
|
|
1710
|
+
line: 376,
|
|
1450
1711
|
scope: this,
|
|
1451
1712
|
callSite: (f, a) => f(...a)
|
|
1452
1713
|
});
|
|
1453
|
-
|
|
1454
|
-
...invitation,
|
|
1714
|
+
setState({
|
|
1455
1715
|
state: import_services2.Invitation.State.TIMEOUT
|
|
1456
1716
|
});
|
|
1457
1717
|
} else {
|
|
1458
|
-
(0,
|
|
1718
|
+
(0, import_log5.log)("auth failed", err, {
|
|
1459
1719
|
file: "invitations-handler.ts",
|
|
1460
|
-
line:
|
|
1720
|
+
line: 379,
|
|
1461
1721
|
scope: this,
|
|
1462
1722
|
callSite: (f, a) => f(...a)
|
|
1463
1723
|
});
|
|
1464
1724
|
stream.error(err);
|
|
1465
1725
|
}
|
|
1466
|
-
|
|
1726
|
+
import_log5.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
|
|
1467
1727
|
id: traceId,
|
|
1468
1728
|
error: err
|
|
1469
1729
|
}), {
|
|
1470
1730
|
file: "invitations-handler.ts",
|
|
1471
|
-
line:
|
|
1731
|
+
line: 382,
|
|
1472
1732
|
scope: this,
|
|
1473
1733
|
callSite: (f, a) => f(...a)
|
|
1474
1734
|
});
|
|
@@ -1476,24 +1736,49 @@ var InvitationsHandler = class {
|
|
|
1476
1736
|
await ctx.dispose();
|
|
1477
1737
|
}
|
|
1478
1738
|
});
|
|
1739
|
+
},
|
|
1740
|
+
onError: (err) => {
|
|
1741
|
+
if (err instanceof import_errors2.InvalidInvitationExtensionRoleError) {
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1744
|
+
if (err instanceof import_async7.TimeoutError) {
|
|
1745
|
+
(0, import_log5.log)("timeout", {
|
|
1746
|
+
...protocol.toJSON()
|
|
1747
|
+
}, {
|
|
1748
|
+
file: "invitations-handler.ts",
|
|
1749
|
+
line: 393,
|
|
1750
|
+
scope: this,
|
|
1751
|
+
callSite: (f, a) => f(...a)
|
|
1752
|
+
});
|
|
1753
|
+
setState({
|
|
1754
|
+
state: import_services2.Invitation.State.TIMEOUT
|
|
1755
|
+
});
|
|
1756
|
+
} else {
|
|
1757
|
+
(0, import_log5.log)("auth failed", err, {
|
|
1758
|
+
file: "invitations-handler.ts",
|
|
1759
|
+
line: 396,
|
|
1760
|
+
scope: this,
|
|
1761
|
+
callSite: (f, a) => f(...a)
|
|
1762
|
+
});
|
|
1763
|
+
stream.error(err);
|
|
1764
|
+
}
|
|
1479
1765
|
}
|
|
1480
1766
|
});
|
|
1481
1767
|
return extension;
|
|
1482
1768
|
};
|
|
1483
|
-
(0,
|
|
1484
|
-
(0,
|
|
1769
|
+
(0, import_async7.scheduleTask)(ctx, async () => {
|
|
1770
|
+
(0, import_node_assert6.default)(invitation.swarmKey);
|
|
1485
1771
|
const topic = invitation.swarmKey;
|
|
1486
1772
|
const swarmConnection = await this._networkManager.joinSwarm({
|
|
1487
1773
|
topic,
|
|
1488
|
-
peerId:
|
|
1774
|
+
peerId: import_keys6.PublicKey.random(),
|
|
1489
1775
|
protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
|
|
1490
1776
|
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
1491
1777
|
}),
|
|
1492
1778
|
topology: new import_network_manager.StarTopology(topic)
|
|
1493
1779
|
});
|
|
1494
1780
|
ctx.onDispose(() => swarmConnection.close());
|
|
1495
|
-
|
|
1496
|
-
...invitation,
|
|
1781
|
+
setState({
|
|
1497
1782
|
state: import_services2.Invitation.State.CONNECTING
|
|
1498
1783
|
});
|
|
1499
1784
|
});
|
|
@@ -1501,8 +1786,7 @@ var InvitationsHandler = class {
|
|
|
1501
1786
|
initialInvitation: invitation,
|
|
1502
1787
|
subscriber: stream.observable,
|
|
1503
1788
|
onCancel: async () => {
|
|
1504
|
-
|
|
1505
|
-
...invitation,
|
|
1789
|
+
setState({
|
|
1506
1790
|
state: import_services2.Invitation.State.CANCELLED
|
|
1507
1791
|
});
|
|
1508
1792
|
await ctx.dispose();
|
|
@@ -1515,119 +1799,12 @@ var InvitationsHandler = class {
|
|
|
1515
1799
|
}
|
|
1516
1800
|
};
|
|
1517
1801
|
var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services2.Invitation.AuthMethod.NONE;
|
|
1518
|
-
var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
1519
|
-
constructor(_callbacks) {
|
|
1520
|
-
super({
|
|
1521
|
-
exposed: {
|
|
1522
|
-
InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1523
|
-
}
|
|
1524
|
-
});
|
|
1525
|
-
this._callbacks = _callbacks;
|
|
1526
|
-
}
|
|
1527
|
-
async getHandlers() {
|
|
1528
|
-
return {
|
|
1529
|
-
// TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
|
|
1530
|
-
// Perhaps in the future we will have more complex logic here.
|
|
1531
|
-
InvitationHostService: {
|
|
1532
|
-
introduce: async (request) => {
|
|
1533
|
-
const traceId = import_keys5.PublicKey.random().toHex();
|
|
1534
|
-
import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.begin({
|
|
1535
|
-
id: traceId,
|
|
1536
|
-
parentId: this._traceParent
|
|
1537
|
-
}), {
|
|
1538
|
-
file: "invitations-handler.ts",
|
|
1539
|
-
line: 442,
|
|
1540
|
-
scope: this,
|
|
1541
|
-
callSite: (f, a) => f(...a)
|
|
1542
|
-
});
|
|
1543
|
-
const response = await this._callbacks.introduce(request);
|
|
1544
|
-
import_log4.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols3.trace.end({
|
|
1545
|
-
id: traceId
|
|
1546
|
-
}), {
|
|
1547
|
-
file: "invitations-handler.ts",
|
|
1548
|
-
line: 447,
|
|
1549
|
-
scope: this,
|
|
1550
|
-
callSite: (f, a) => f(...a)
|
|
1551
|
-
});
|
|
1552
|
-
return response;
|
|
1553
|
-
},
|
|
1554
|
-
authenticate: async (request) => {
|
|
1555
|
-
const traceId = import_keys5.PublicKey.random().toHex();
|
|
1556
|
-
import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.begin({
|
|
1557
|
-
id: traceId,
|
|
1558
|
-
parentId: this._traceParent
|
|
1559
|
-
}), {
|
|
1560
|
-
file: "invitations-handler.ts",
|
|
1561
|
-
line: 453,
|
|
1562
|
-
scope: this,
|
|
1563
|
-
callSite: (f, a) => f(...a)
|
|
1564
|
-
});
|
|
1565
|
-
const response = await this._callbacks.authenticate(request);
|
|
1566
|
-
import_log4.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols3.trace.end({
|
|
1567
|
-
id: traceId,
|
|
1568
|
-
data: {
|
|
1569
|
-
...response
|
|
1570
|
-
}
|
|
1571
|
-
}), {
|
|
1572
|
-
file: "invitations-handler.ts",
|
|
1573
|
-
line: 458,
|
|
1574
|
-
scope: this,
|
|
1575
|
-
callSite: (f, a) => f(...a)
|
|
1576
|
-
});
|
|
1577
|
-
return response;
|
|
1578
|
-
},
|
|
1579
|
-
admit: async (request) => {
|
|
1580
|
-
const traceId = import_keys5.PublicKey.random().toHex();
|
|
1581
|
-
import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.begin({
|
|
1582
|
-
id: traceId,
|
|
1583
|
-
parentId: this._traceParent
|
|
1584
|
-
}), {
|
|
1585
|
-
file: "invitations-handler.ts",
|
|
1586
|
-
line: 464,
|
|
1587
|
-
scope: this,
|
|
1588
|
-
callSite: (f, a) => f(...a)
|
|
1589
|
-
});
|
|
1590
|
-
const response = await this._callbacks.admit(request);
|
|
1591
|
-
import_log4.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols3.trace.end({
|
|
1592
|
-
id: traceId
|
|
1593
|
-
}), {
|
|
1594
|
-
file: "invitations-handler.ts",
|
|
1595
|
-
line: 469,
|
|
1596
|
-
scope: this,
|
|
1597
|
-
callSite: (f, a) => f(...a)
|
|
1598
|
-
});
|
|
1599
|
-
return response;
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
};
|
|
1603
|
-
}
|
|
1604
|
-
async onOpen(context) {
|
|
1605
|
-
await super.onOpen(context);
|
|
1606
|
-
this._callbacks.onOpen();
|
|
1607
|
-
}
|
|
1608
|
-
};
|
|
1609
|
-
var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
1610
|
-
constructor(_callbacks) {
|
|
1611
|
-
super({
|
|
1612
|
-
requested: {
|
|
1613
|
-
InvitationHostService: import_protocols3.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1614
|
-
}
|
|
1615
|
-
});
|
|
1616
|
-
this._callbacks = _callbacks;
|
|
1617
|
-
}
|
|
1618
|
-
async getHandlers() {
|
|
1619
|
-
return {};
|
|
1620
|
-
}
|
|
1621
|
-
async onOpen(context) {
|
|
1622
|
-
await super.onOpen(context);
|
|
1623
|
-
this._callbacks.onOpen();
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1626
1802
|
|
|
1627
1803
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
1628
|
-
var
|
|
1804
|
+
var import_node_assert7 = __toESM(require("node:assert"));
|
|
1805
|
+
var import_async8 = require("@dxos/async");
|
|
1629
1806
|
var import_codec_protobuf7 = require("@dxos/codec-protobuf");
|
|
1630
|
-
var
|
|
1807
|
+
var import_log6 = require("@dxos/log");
|
|
1631
1808
|
var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1632
1809
|
var InvitationsServiceImpl = class {
|
|
1633
1810
|
constructor(_invitationsHandler, _getHandler) {
|
|
@@ -1635,203 +1812,74 @@ var InvitationsServiceImpl = class {
|
|
|
1635
1812
|
this._getHandler = _getHandler;
|
|
1636
1813
|
this._createInvitations = /* @__PURE__ */ new Map();
|
|
1637
1814
|
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
1815
|
+
this._invitationCreated = new import_async8.Event();
|
|
1816
|
+
this._invitationAccepted = new import_async8.Event();
|
|
1817
|
+
this._removedCreated = new import_async8.Event();
|
|
1818
|
+
this._removedAccepted = new import_async8.Event();
|
|
1638
1819
|
}
|
|
1639
1820
|
// TODO(burdon): Guest/host label.
|
|
1640
1821
|
getLoggingContext() {
|
|
1641
1822
|
return {};
|
|
1642
1823
|
}
|
|
1643
|
-
createInvitation(
|
|
1824
|
+
createInvitation(options) {
|
|
1825
|
+
let invitation;
|
|
1826
|
+
const existingInvitation = this._createInvitations.get(options.invitationId);
|
|
1827
|
+
if (existingInvitation) {
|
|
1828
|
+
invitation = existingInvitation;
|
|
1829
|
+
} else {
|
|
1830
|
+
const handler = this._getHandler(options);
|
|
1831
|
+
invitation = this._invitationsHandler.createInvitation(handler, options);
|
|
1832
|
+
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
1833
|
+
this._invitationCreated.emit(invitation.get());
|
|
1834
|
+
}
|
|
1644
1835
|
return new import_codec_protobuf7.Stream(({ next, close }) => {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
file: "invitations-service.ts",
|
|
1648
|
-
line: 37,
|
|
1649
|
-
scope: this,
|
|
1650
|
-
callSite: (f, a) => f(...a)
|
|
1651
|
-
});
|
|
1652
|
-
let invitationId;
|
|
1653
|
-
const observable = this._invitationsHandler.createInvitation(handler, invitation);
|
|
1654
|
-
observable.subscribe((invitation2) => {
|
|
1655
|
-
switch (invitation2.state) {
|
|
1656
|
-
case import_services3.Invitation.State.CONNECTING: {
|
|
1657
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1658
|
-
invitationId = invitation2.invitationId;
|
|
1659
|
-
this._createInvitations.set(invitation2.invitationId, observable);
|
|
1660
|
-
invitation2.state = import_services3.Invitation.State.CONNECTING;
|
|
1661
|
-
next(invitation2);
|
|
1662
|
-
break;
|
|
1663
|
-
}
|
|
1664
|
-
case import_services3.Invitation.State.CONNECTED: {
|
|
1665
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1666
|
-
invitation2.state = import_services3.Invitation.State.CONNECTED;
|
|
1667
|
-
next(invitation2);
|
|
1668
|
-
break;
|
|
1669
|
-
}
|
|
1670
|
-
case import_services3.Invitation.State.READY_FOR_AUTHENTICATION: {
|
|
1671
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1672
|
-
invitation2.state = import_services3.Invitation.State.READY_FOR_AUTHENTICATION;
|
|
1673
|
-
next(invitation2);
|
|
1674
|
-
break;
|
|
1675
|
-
}
|
|
1676
|
-
case import_services3.Invitation.State.AUTHENTICATING: {
|
|
1677
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1678
|
-
invitation2.state = import_services3.Invitation.State.AUTHENTICATING;
|
|
1679
|
-
next(invitation2);
|
|
1680
|
-
break;
|
|
1681
|
-
}
|
|
1682
|
-
case import_services3.Invitation.State.SUCCESS: {
|
|
1683
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1684
|
-
invitation2.state = import_services3.Invitation.State.SUCCESS;
|
|
1685
|
-
next(invitation2);
|
|
1686
|
-
break;
|
|
1687
|
-
}
|
|
1688
|
-
case import_services3.Invitation.State.CANCELLED: {
|
|
1689
|
-
(0, import_node_assert6.default)(invitationId);
|
|
1690
|
-
invitation2.invitationId = invitationId;
|
|
1691
|
-
invitation2.state = import_services3.Invitation.State.CANCELLED;
|
|
1692
|
-
next(invitation2);
|
|
1693
|
-
break;
|
|
1694
|
-
}
|
|
1695
|
-
case import_services3.Invitation.State.TIMEOUT: {
|
|
1696
|
-
(0, import_node_assert6.default)(invitationId);
|
|
1697
|
-
invitation2.invitationId = invitationId;
|
|
1698
|
-
invitation2.state = import_services3.Invitation.State.TIMEOUT;
|
|
1699
|
-
next(invitation2);
|
|
1700
|
-
break;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1836
|
+
invitation.subscribe((invitation2) => {
|
|
1837
|
+
next(invitation2);
|
|
1703
1838
|
}, (err) => {
|
|
1704
1839
|
close(err);
|
|
1705
1840
|
}, () => {
|
|
1706
1841
|
close();
|
|
1842
|
+
this._createInvitations.delete(invitation.get().invitationId);
|
|
1707
1843
|
});
|
|
1708
|
-
return (err) => {
|
|
1709
|
-
const context = this.getLoggingContext();
|
|
1710
|
-
if (err) {
|
|
1711
|
-
import_log5.log.warn("stream closed", {
|
|
1712
|
-
...context,
|
|
1713
|
-
err
|
|
1714
|
-
}, {
|
|
1715
|
-
file: "invitations-service.ts",
|
|
1716
|
-
line: 103,
|
|
1717
|
-
scope: this,
|
|
1718
|
-
callSite: (f, a) => f(...a)
|
|
1719
|
-
});
|
|
1720
|
-
} else {
|
|
1721
|
-
(0, import_log5.log)("stream closed", context, {
|
|
1722
|
-
file: "invitations-service.ts",
|
|
1723
|
-
line: 105,
|
|
1724
|
-
scope: this,
|
|
1725
|
-
callSite: (f, a) => f(...a)
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
this._createInvitations.delete(invitation.invitationId);
|
|
1729
|
-
};
|
|
1730
1844
|
});
|
|
1731
1845
|
}
|
|
1732
|
-
acceptInvitation(
|
|
1846
|
+
acceptInvitation(options) {
|
|
1847
|
+
let invitation;
|
|
1848
|
+
const existingInvitation = this._acceptInvitations.get(options.invitationId);
|
|
1849
|
+
if (existingInvitation) {
|
|
1850
|
+
invitation = existingInvitation;
|
|
1851
|
+
} else {
|
|
1852
|
+
const handler = this._getHandler(options);
|
|
1853
|
+
invitation = this._invitationsHandler.acceptInvitation(handler, options);
|
|
1854
|
+
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
1855
|
+
this._invitationAccepted.emit(invitation.get());
|
|
1856
|
+
}
|
|
1733
1857
|
return new import_codec_protobuf7.Stream(({ next, close }) => {
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
line: 115,
|
|
1737
|
-
scope: this,
|
|
1738
|
-
callSite: (f, a) => f(...a)
|
|
1739
|
-
});
|
|
1740
|
-
const handler = this._getHandler(invitation);
|
|
1741
|
-
let invitationId;
|
|
1742
|
-
const observable = this._invitationsHandler.acceptInvitation(handler, invitation);
|
|
1743
|
-
observable.subscribe((invitation2) => {
|
|
1744
|
-
switch (invitation2.state) {
|
|
1745
|
-
case import_services3.Invitation.State.CONNECTING: {
|
|
1746
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1747
|
-
invitationId = invitation2.invitationId;
|
|
1748
|
-
this._acceptInvitations.set(invitation2.invitationId, observable);
|
|
1749
|
-
invitation2.state = import_services3.Invitation.State.CONNECTING;
|
|
1750
|
-
next(invitation2);
|
|
1751
|
-
break;
|
|
1752
|
-
}
|
|
1753
|
-
case import_services3.Invitation.State.CONNECTED: {
|
|
1754
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1755
|
-
invitation2.state = import_services3.Invitation.State.CONNECTED;
|
|
1756
|
-
next(invitation2);
|
|
1757
|
-
break;
|
|
1758
|
-
}
|
|
1759
|
-
case import_services3.Invitation.State.READY_FOR_AUTHENTICATION: {
|
|
1760
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1761
|
-
invitation2.state = import_services3.Invitation.State.READY_FOR_AUTHENTICATION;
|
|
1762
|
-
next(invitation2);
|
|
1763
|
-
break;
|
|
1764
|
-
}
|
|
1765
|
-
case import_services3.Invitation.State.AUTHENTICATING: {
|
|
1766
|
-
(0, import_node_assert6.default)(invitation2.invitationId);
|
|
1767
|
-
invitation2.state = import_services3.Invitation.State.AUTHENTICATING;
|
|
1768
|
-
next(invitation2);
|
|
1769
|
-
break;
|
|
1770
|
-
}
|
|
1771
|
-
case import_services3.Invitation.State.SUCCESS: {
|
|
1772
|
-
invitation2.state = import_services3.Invitation.State.SUCCESS;
|
|
1773
|
-
next(invitation2);
|
|
1774
|
-
break;
|
|
1775
|
-
}
|
|
1776
|
-
case import_services3.Invitation.State.CANCELLED: {
|
|
1777
|
-
(0, import_node_assert6.default)(invitationId);
|
|
1778
|
-
invitation2.invitationId = invitationId;
|
|
1779
|
-
invitation2.state = import_services3.Invitation.State.CANCELLED;
|
|
1780
|
-
next(invitation2);
|
|
1781
|
-
break;
|
|
1782
|
-
}
|
|
1783
|
-
case import_services3.Invitation.State.TIMEOUT: {
|
|
1784
|
-
(0, import_node_assert6.default)(invitationId);
|
|
1785
|
-
invitation2.invitationId = invitationId;
|
|
1786
|
-
invitation2.state = import_services3.Invitation.State.TIMEOUT;
|
|
1787
|
-
next(invitation2);
|
|
1788
|
-
break;
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1858
|
+
invitation.subscribe((invitation2) => {
|
|
1859
|
+
next(invitation2);
|
|
1791
1860
|
}, (err) => {
|
|
1792
1861
|
close(err);
|
|
1793
1862
|
}, () => {
|
|
1794
1863
|
close();
|
|
1864
|
+
this._acceptInvitations.delete(invitation.get().invitationId);
|
|
1795
1865
|
});
|
|
1796
|
-
return (err) => {
|
|
1797
|
-
const context = this.getLoggingContext();
|
|
1798
|
-
if (err) {
|
|
1799
|
-
import_log5.log.warn("stream closed", {
|
|
1800
|
-
...context,
|
|
1801
|
-
err
|
|
1802
|
-
}, {
|
|
1803
|
-
file: "invitations-service.ts",
|
|
1804
|
-
line: 181,
|
|
1805
|
-
scope: this,
|
|
1806
|
-
callSite: (f, a) => f(...a)
|
|
1807
|
-
});
|
|
1808
|
-
} else {
|
|
1809
|
-
(0, import_log5.log)("stream closed", context, {
|
|
1810
|
-
file: "invitations-service.ts",
|
|
1811
|
-
line: 183,
|
|
1812
|
-
scope: this,
|
|
1813
|
-
callSite: (f, a) => f(...a)
|
|
1814
|
-
});
|
|
1815
|
-
}
|
|
1816
|
-
this._acceptInvitations.delete(invitation.invitationId);
|
|
1817
|
-
};
|
|
1818
1866
|
});
|
|
1819
1867
|
}
|
|
1820
1868
|
async authenticate({ invitationId, authCode }) {
|
|
1821
|
-
(0,
|
|
1869
|
+
(0, import_log6.log)("authenticating...", {}, {
|
|
1822
1870
|
file: "invitations-service.ts",
|
|
1823
|
-
line:
|
|
1871
|
+
line: 103,
|
|
1824
1872
|
scope: this,
|
|
1825
1873
|
callSite: (f, a) => f(...a)
|
|
1826
1874
|
});
|
|
1827
|
-
(0,
|
|
1875
|
+
(0, import_node_assert7.default)(invitationId);
|
|
1828
1876
|
const observable = this._acceptInvitations.get(invitationId);
|
|
1829
1877
|
if (!observable) {
|
|
1830
|
-
|
|
1878
|
+
import_log6.log.warn("invalid invitation", {
|
|
1831
1879
|
invitationId
|
|
1832
1880
|
}, {
|
|
1833
1881
|
file: "invitations-service.ts",
|
|
1834
|
-
line:
|
|
1882
|
+
line: 107,
|
|
1835
1883
|
scope: this,
|
|
1836
1884
|
callSite: (f, a) => f(...a)
|
|
1837
1885
|
});
|
|
@@ -1840,35 +1888,91 @@ var InvitationsServiceImpl = class {
|
|
|
1840
1888
|
}
|
|
1841
1889
|
}
|
|
1842
1890
|
async cancelInvitation({ invitationId }) {
|
|
1843
|
-
|
|
1844
|
-
(0, import_log5.log)("cancelling...", {}, {
|
|
1891
|
+
(0, import_log6.log)("deleting...", {}, {
|
|
1845
1892
|
file: "invitations-service.ts",
|
|
1846
|
-
line:
|
|
1893
|
+
line: 114,
|
|
1847
1894
|
scope: this,
|
|
1848
1895
|
callSite: (f, a) => f(...a)
|
|
1849
1896
|
});
|
|
1850
|
-
(0,
|
|
1851
|
-
const
|
|
1852
|
-
|
|
1853
|
-
|
|
1897
|
+
(0, import_node_assert7.default)(invitationId);
|
|
1898
|
+
const created = this._createInvitations.get(invitationId);
|
|
1899
|
+
const accepted = this._acceptInvitations.get(invitationId);
|
|
1900
|
+
if (created) {
|
|
1901
|
+
await created.cancel();
|
|
1902
|
+
this._createInvitations.delete(invitationId);
|
|
1903
|
+
this._removedCreated.emit(created.get());
|
|
1904
|
+
} else if (accepted) {
|
|
1905
|
+
await accepted.cancel();
|
|
1906
|
+
this._acceptInvitations.delete(invitationId);
|
|
1907
|
+
this._removedAccepted.emit(accepted.get());
|
|
1908
|
+
} else {
|
|
1909
|
+
import_log6.log.warn("invalid invitation", {
|
|
1854
1910
|
invitationId
|
|
1855
1911
|
}, {
|
|
1856
1912
|
file: "invitations-service.ts",
|
|
1857
|
-
line:
|
|
1913
|
+
line: 127,
|
|
1858
1914
|
scope: this,
|
|
1859
1915
|
callSite: (f, a) => f(...a)
|
|
1860
1916
|
});
|
|
1861
|
-
} else {
|
|
1862
|
-
await (observable == null ? void 0 : observable.cancel());
|
|
1863
1917
|
}
|
|
1864
1918
|
}
|
|
1919
|
+
queryInvitations() {
|
|
1920
|
+
return new import_codec_protobuf7.Stream(({ next, ctx }) => {
|
|
1921
|
+
this._invitationCreated.on(ctx, (invitation) => {
|
|
1922
|
+
next({
|
|
1923
|
+
action: import_services3.QueryInvitationsResponse.Action.ADDED,
|
|
1924
|
+
type: import_services3.QueryInvitationsResponse.Type.CREATED,
|
|
1925
|
+
invitations: [
|
|
1926
|
+
invitation
|
|
1927
|
+
]
|
|
1928
|
+
});
|
|
1929
|
+
});
|
|
1930
|
+
this._invitationAccepted.on(ctx, (invitation) => {
|
|
1931
|
+
next({
|
|
1932
|
+
action: import_services3.QueryInvitationsResponse.Action.ADDED,
|
|
1933
|
+
type: import_services3.QueryInvitationsResponse.Type.ACCEPTED,
|
|
1934
|
+
invitations: [
|
|
1935
|
+
invitation
|
|
1936
|
+
]
|
|
1937
|
+
});
|
|
1938
|
+
});
|
|
1939
|
+
this._removedCreated.on(ctx, (invitation) => {
|
|
1940
|
+
next({
|
|
1941
|
+
action: import_services3.QueryInvitationsResponse.Action.REMOVED,
|
|
1942
|
+
type: import_services3.QueryInvitationsResponse.Type.CREATED,
|
|
1943
|
+
invitations: [
|
|
1944
|
+
invitation
|
|
1945
|
+
]
|
|
1946
|
+
});
|
|
1947
|
+
});
|
|
1948
|
+
this._removedAccepted.on(ctx, (invitation) => {
|
|
1949
|
+
next({
|
|
1950
|
+
action: import_services3.QueryInvitationsResponse.Action.REMOVED,
|
|
1951
|
+
type: import_services3.QueryInvitationsResponse.Type.ACCEPTED,
|
|
1952
|
+
invitations: [
|
|
1953
|
+
invitation
|
|
1954
|
+
]
|
|
1955
|
+
});
|
|
1956
|
+
});
|
|
1957
|
+
next({
|
|
1958
|
+
action: import_services3.QueryInvitationsResponse.Action.ADDED,
|
|
1959
|
+
type: import_services3.QueryInvitationsResponse.Type.CREATED,
|
|
1960
|
+
invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
|
|
1961
|
+
});
|
|
1962
|
+
next({
|
|
1963
|
+
action: import_services3.QueryInvitationsResponse.Action.ADDED,
|
|
1964
|
+
type: import_services3.QueryInvitationsResponse.Type.ACCEPTED,
|
|
1965
|
+
invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
|
|
1966
|
+
});
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1865
1969
|
};
|
|
1866
1970
|
|
|
1867
1971
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
1868
|
-
var
|
|
1972
|
+
var import_node_assert8 = __toESM(require("node:assert"));
|
|
1869
1973
|
var import_credentials8 = require("@dxos/credentials");
|
|
1870
1974
|
var import_feed_store3 = require("@dxos/feed-store");
|
|
1871
|
-
var
|
|
1975
|
+
var import_log7 = require("@dxos/log");
|
|
1872
1976
|
var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1873
1977
|
var SpaceInvitationProtocol = class {
|
|
1874
1978
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
@@ -1891,12 +1995,12 @@ var SpaceInvitationProtocol = class {
|
|
|
1891
1995
|
}
|
|
1892
1996
|
async admit(request, guestProfile) {
|
|
1893
1997
|
var _a;
|
|
1894
|
-
(0,
|
|
1998
|
+
(0, import_node_assert8.default)(this._spaceKey);
|
|
1895
1999
|
const space = await this._spaceManager.spaces.get(this._spaceKey);
|
|
1896
|
-
(0,
|
|
1897
|
-
(0,
|
|
2000
|
+
(0, import_node_assert8.default)(space);
|
|
2001
|
+
(0, import_node_assert8.default)(request.space);
|
|
1898
2002
|
const { identityKey, deviceKey } = request.space;
|
|
1899
|
-
(0,
|
|
2003
|
+
(0, import_log7.log)("writing guest credentials", {
|
|
1900
2004
|
host: this._signingContext.deviceKey,
|
|
1901
2005
|
guest: deviceKey
|
|
1902
2006
|
}, {
|
|
@@ -1906,9 +2010,9 @@ var SpaceInvitationProtocol = class {
|
|
|
1906
2010
|
callSite: (f, a) => f(...a)
|
|
1907
2011
|
});
|
|
1908
2012
|
const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
|
|
1909
|
-
(0,
|
|
2013
|
+
(0, import_node_assert8.default)(credentials[0].credential);
|
|
1910
2014
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
1911
|
-
(0,
|
|
2015
|
+
(0, import_node_assert8.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
|
|
1912
2016
|
await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
|
|
1913
2017
|
return {
|
|
1914
2018
|
space: {
|
|
@@ -1936,11 +2040,11 @@ var SpaceInvitationProtocol = class {
|
|
|
1936
2040
|
};
|
|
1937
2041
|
}
|
|
1938
2042
|
async accept(response) {
|
|
1939
|
-
(0,
|
|
2043
|
+
(0, import_node_assert8.default)(response.space);
|
|
1940
2044
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
1941
2045
|
const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
|
|
1942
|
-
(0,
|
|
1943
|
-
(0,
|
|
2046
|
+
(0, import_node_assert8.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
|
|
2047
|
+
(0, import_node_assert8.default)(credential.subject.id.equals(this._signingContext.identityKey));
|
|
1944
2048
|
await this._spaceManager.acceptSpace({
|
|
1945
2049
|
spaceKey: assertion.spaceKey,
|
|
1946
2050
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
@@ -1955,12 +2059,12 @@ var SpaceInvitationProtocol = class {
|
|
|
1955
2059
|
};
|
|
1956
2060
|
|
|
1957
2061
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
1958
|
-
var
|
|
1959
|
-
var
|
|
2062
|
+
var import_node_assert14 = __toESM(require("node:assert"));
|
|
2063
|
+
var import_async20 = require("@dxos/async");
|
|
1960
2064
|
var import_client8 = require("@dxos/client");
|
|
1961
2065
|
var import_echo_pipeline5 = require("@dxos/echo-pipeline");
|
|
1962
|
-
var
|
|
1963
|
-
var
|
|
2066
|
+
var import_log18 = require("@dxos/log");
|
|
2067
|
+
var import_protocols8 = require("@dxos/protocols");
|
|
1964
2068
|
var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1965
2069
|
|
|
1966
2070
|
// packages/sdk/client-services/src/packlets/deprecated/tracing.ts
|
|
@@ -1977,7 +2081,7 @@ var TracingServiceImpl = class {
|
|
|
1977
2081
|
};
|
|
1978
2082
|
|
|
1979
2083
|
// packages/sdk/client-services/src/packlets/devices/devices-service.ts
|
|
1980
|
-
var
|
|
2084
|
+
var import_async9 = require("@dxos/async");
|
|
1981
2085
|
var import_codec_protobuf8 = require("@dxos/codec-protobuf");
|
|
1982
2086
|
var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1983
2087
|
var DevicesServiceImpl = class {
|
|
@@ -2008,7 +2112,7 @@ var DevicesServiceImpl = class {
|
|
|
2008
2112
|
});
|
|
2009
2113
|
}
|
|
2010
2114
|
};
|
|
2011
|
-
const subscriptions = new
|
|
2115
|
+
const subscriptions = new import_async9.EventSubscriptions();
|
|
2012
2116
|
subscriptions.add(this._identityManager.stateUpdate.on(() => {
|
|
2013
2117
|
update();
|
|
2014
2118
|
if (this._identityManager.identity) {
|
|
@@ -2046,37 +2150,37 @@ var NetworkServiceImpl = class {
|
|
|
2046
2150
|
};
|
|
2047
2151
|
|
|
2048
2152
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
2049
|
-
var
|
|
2050
|
-
var
|
|
2153
|
+
var import_node_assert10 = __toESM(require("node:assert"));
|
|
2154
|
+
var import_async12 = require("@dxos/async");
|
|
2051
2155
|
var import_client3 = require("@dxos/client");
|
|
2052
|
-
var
|
|
2156
|
+
var import_context7 = require("@dxos/context");
|
|
2053
2157
|
var import_credentials10 = require("@dxos/credentials");
|
|
2054
2158
|
var import_echo_pipeline2 = require("@dxos/echo-pipeline");
|
|
2055
|
-
var
|
|
2056
|
-
var
|
|
2057
|
-
var
|
|
2159
|
+
var import_keys9 = require("@dxos/keys");
|
|
2160
|
+
var import_log10 = require("@dxos/log");
|
|
2161
|
+
var import_protocols6 = require("@dxos/protocols");
|
|
2058
2162
|
var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
|
|
2059
2163
|
var import_util5 = require("@dxos/util");
|
|
2060
2164
|
|
|
2061
2165
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2062
|
-
var
|
|
2166
|
+
var import_async11 = require("@dxos/async");
|
|
2063
2167
|
var import_client2 = require("@dxos/client");
|
|
2064
|
-
var
|
|
2168
|
+
var import_context6 = require("@dxos/context");
|
|
2065
2169
|
var import_debug3 = require("@dxos/debug");
|
|
2066
2170
|
var import_echo_pipeline = require("@dxos/echo-pipeline");
|
|
2067
|
-
var
|
|
2068
|
-
var
|
|
2069
|
-
var
|
|
2171
|
+
var import_errors3 = require("@dxos/errors");
|
|
2172
|
+
var import_keys8 = require("@dxos/keys");
|
|
2173
|
+
var import_log9 = require("@dxos/log");
|
|
2070
2174
|
var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
2071
2175
|
var import_util4 = require("@dxos/util");
|
|
2072
2176
|
|
|
2073
2177
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
2074
|
-
var
|
|
2075
|
-
var
|
|
2076
|
-
var
|
|
2077
|
-
var
|
|
2078
|
-
var
|
|
2079
|
-
var
|
|
2178
|
+
var import_node_assert9 = __toESM(require("node:assert"));
|
|
2179
|
+
var import_async10 = require("@dxos/async");
|
|
2180
|
+
var import_context5 = require("@dxos/context");
|
|
2181
|
+
var import_keys7 = require("@dxos/keys");
|
|
2182
|
+
var import_log8 = require("@dxos/log");
|
|
2183
|
+
var import_protocols5 = require("@dxos/protocols");
|
|
2080
2184
|
var import_teleport2 = require("@dxos/teleport");
|
|
2081
2185
|
var import_util3 = require("@dxos/util");
|
|
2082
2186
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
@@ -2084,11 +2188,11 @@ var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
|
2084
2188
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
2085
2189
|
var NotarizationPlugin = class {
|
|
2086
2190
|
constructor() {
|
|
2087
|
-
this._ctx = new
|
|
2088
|
-
this._extensionOpened = new
|
|
2191
|
+
this._ctx = new import_context5.Context();
|
|
2192
|
+
this._extensionOpened = new import_async10.Event();
|
|
2089
2193
|
this._extensions = /* @__PURE__ */ new Set();
|
|
2090
|
-
this._processedCredentials = new import_util3.ComplexSet(
|
|
2091
|
-
this._processCredentialsTriggers = new import_util3.ComplexMap(
|
|
2194
|
+
this._processedCredentials = new import_util3.ComplexSet(import_keys7.PublicKey.hash);
|
|
2195
|
+
this._processCredentialsTriggers = new import_util3.ComplexMap(import_keys7.PublicKey.hash);
|
|
2092
2196
|
}
|
|
2093
2197
|
async open() {
|
|
2094
2198
|
}
|
|
@@ -2099,7 +2203,7 @@ var NotarizationPlugin = class {
|
|
|
2099
2203
|
* Request credentials to be notarized.
|
|
2100
2204
|
*/
|
|
2101
2205
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
2102
|
-
(0,
|
|
2206
|
+
(0, import_log8.log)("notarize", {
|
|
2103
2207
|
credentials
|
|
2104
2208
|
}, {
|
|
2105
2209
|
file: "notarization-plugin.ts",
|
|
@@ -2107,11 +2211,11 @@ var NotarizationPlugin = class {
|
|
|
2107
2211
|
scope: this,
|
|
2108
2212
|
callSite: (f, a) => f(...a)
|
|
2109
2213
|
});
|
|
2110
|
-
(0,
|
|
2111
|
-
const errors = new
|
|
2214
|
+
(0, import_node_assert9.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
|
|
2215
|
+
const errors = new import_async10.Trigger();
|
|
2112
2216
|
const ctx = this._ctx.derive({
|
|
2113
2217
|
onError: (err) => {
|
|
2114
|
-
|
|
2218
|
+
import_log8.log.warn("Notarization error", {
|
|
2115
2219
|
err
|
|
2116
2220
|
}, {
|
|
2117
2221
|
file: "notarization-plugin.ts",
|
|
@@ -2125,8 +2229,8 @@ var NotarizationPlugin = class {
|
|
|
2125
2229
|
});
|
|
2126
2230
|
opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
|
|
2127
2231
|
if (timeout !== 0) {
|
|
2128
|
-
(0,
|
|
2129
|
-
|
|
2232
|
+
(0, import_async10.scheduleTask)(ctx, () => {
|
|
2233
|
+
import_log8.log.warn("Notarization timeout", {
|
|
2130
2234
|
timeout,
|
|
2131
2235
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
2132
2236
|
}, {
|
|
@@ -2136,12 +2240,12 @@ var NotarizationPlugin = class {
|
|
|
2136
2240
|
callSite: (f, a) => f(...a)
|
|
2137
2241
|
});
|
|
2138
2242
|
void ctx.dispose();
|
|
2139
|
-
errors.throw(new
|
|
2243
|
+
errors.throw(new import_async10.TimeoutError(timeout, "Notarization timed out"));
|
|
2140
2244
|
}, timeout);
|
|
2141
2245
|
}
|
|
2142
2246
|
const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
|
|
2143
2247
|
const peersTried = /* @__PURE__ */ new Set();
|
|
2144
|
-
const notarizeTask = new
|
|
2248
|
+
const notarizeTask = new import_async10.DeferredTask(ctx, async () => {
|
|
2145
2249
|
try {
|
|
2146
2250
|
if (this._extensions.size === 0) {
|
|
2147
2251
|
return;
|
|
@@ -2150,7 +2254,7 @@ var NotarizationPlugin = class {
|
|
|
2150
2254
|
...this._extensions
|
|
2151
2255
|
].find((peer2) => !peersTried.has(peer2));
|
|
2152
2256
|
if (!peer) {
|
|
2153
|
-
|
|
2257
|
+
import_log8.log.warn("Exhausted all peers to notarize with", {
|
|
2154
2258
|
retryIn: retryTimeout
|
|
2155
2259
|
}, {
|
|
2156
2260
|
file: "notarization-plugin.ts",
|
|
@@ -2159,11 +2263,11 @@ var NotarizationPlugin = class {
|
|
|
2159
2263
|
callSite: (f, a) => f(...a)
|
|
2160
2264
|
});
|
|
2161
2265
|
peersTried.clear();
|
|
2162
|
-
(0,
|
|
2266
|
+
(0, import_async10.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
|
|
2163
2267
|
return;
|
|
2164
2268
|
}
|
|
2165
2269
|
peersTried.add(peer);
|
|
2166
|
-
(0,
|
|
2270
|
+
(0, import_log8.log)("try notarizing", {
|
|
2167
2271
|
peer: peer.localPeerId,
|
|
2168
2272
|
credentialId: credentials.map((credential) => credential.id)
|
|
2169
2273
|
}, {
|
|
@@ -2175,15 +2279,15 @@ var NotarizationPlugin = class {
|
|
|
2175
2279
|
await peer.rpc.NotarizationService.notarize({
|
|
2176
2280
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
2177
2281
|
});
|
|
2178
|
-
(0,
|
|
2282
|
+
(0, import_log8.log)("success", {}, {
|
|
2179
2283
|
file: "notarization-plugin.ts",
|
|
2180
2284
|
line: 142,
|
|
2181
2285
|
scope: this,
|
|
2182
2286
|
callSite: (f, a) => f(...a)
|
|
2183
2287
|
});
|
|
2184
|
-
await (0,
|
|
2288
|
+
await (0, import_async10.sleep)(successDelay);
|
|
2185
2289
|
} catch (err) {
|
|
2186
|
-
|
|
2290
|
+
import_log8.log.warn("error notarizing (recoverable)", err, {
|
|
2187
2291
|
file: "notarization-plugin.ts",
|
|
2188
2292
|
line: 145,
|
|
2189
2293
|
scope: this,
|
|
@@ -2196,11 +2300,11 @@ var NotarizationPlugin = class {
|
|
|
2196
2300
|
this._extensionOpened.on(ctx, () => notarizeTask.schedule());
|
|
2197
2301
|
try {
|
|
2198
2302
|
await Promise.race([
|
|
2199
|
-
(0,
|
|
2303
|
+
(0, import_context5.rejectOnDispose)(ctx),
|
|
2200
2304
|
allNotarized,
|
|
2201
2305
|
errors.wait()
|
|
2202
2306
|
]);
|
|
2203
|
-
(0,
|
|
2307
|
+
(0, import_log8.log)("done", {}, {
|
|
2204
2308
|
file: "notarization-plugin.ts",
|
|
2205
2309
|
line: 155,
|
|
2206
2310
|
scope: this,
|
|
@@ -2223,14 +2327,14 @@ var NotarizationPlugin = class {
|
|
|
2223
2327
|
this._processCredentialsTriggers.delete(credential.id);
|
|
2224
2328
|
}
|
|
2225
2329
|
setWriter(writer) {
|
|
2226
|
-
(0,
|
|
2330
|
+
(0, import_node_assert9.default)(!this._writer, "Writer already set.");
|
|
2227
2331
|
this._writer = writer;
|
|
2228
2332
|
}
|
|
2229
2333
|
async _waitUntilProcessed(id) {
|
|
2230
2334
|
if (this._processedCredentials.has(id)) {
|
|
2231
2335
|
return;
|
|
2232
2336
|
}
|
|
2233
|
-
await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new
|
|
2337
|
+
await (0, import_util3.entry)(this._processCredentialsTriggers, id).orInsert(new import_async10.Trigger()).value.wait();
|
|
2234
2338
|
}
|
|
2235
2339
|
/**
|
|
2236
2340
|
* Requests from other peers to notarize credentials.
|
|
@@ -2241,7 +2345,7 @@ var NotarizationPlugin = class {
|
|
|
2241
2345
|
throw new Error("Writer not set");
|
|
2242
2346
|
}
|
|
2243
2347
|
for (const credential of (_a = request.credentials) != null ? _a : []) {
|
|
2244
|
-
(0,
|
|
2348
|
+
(0, import_node_assert9.default)(credential.id, "Credential must have an id");
|
|
2245
2349
|
if (this._processedCredentials.has(credential.id)) {
|
|
2246
2350
|
continue;
|
|
2247
2351
|
}
|
|
@@ -2251,7 +2355,7 @@ var NotarizationPlugin = class {
|
|
|
2251
2355
|
createExtension() {
|
|
2252
2356
|
const extension = new NotarizationTeleportExtension({
|
|
2253
2357
|
onOpen: async () => {
|
|
2254
|
-
(0,
|
|
2358
|
+
(0, import_log8.log)("extension opened", {
|
|
2255
2359
|
peer: extension.localPeerId
|
|
2256
2360
|
}, {
|
|
2257
2361
|
file: "notarization-plugin.ts",
|
|
@@ -2263,7 +2367,7 @@ var NotarizationPlugin = class {
|
|
|
2263
2367
|
this._extensionOpened.emit();
|
|
2264
2368
|
},
|
|
2265
2369
|
onClose: async () => {
|
|
2266
|
-
(0,
|
|
2370
|
+
(0, import_log8.log)("extension closed", {
|
|
2267
2371
|
peer: extension.localPeerId
|
|
2268
2372
|
}, {
|
|
2269
2373
|
file: "notarization-plugin.ts",
|
|
@@ -2282,10 +2386,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
|
|
|
2282
2386
|
constructor(_params) {
|
|
2283
2387
|
super({
|
|
2284
2388
|
requested: {
|
|
2285
|
-
NotarizationService:
|
|
2389
|
+
NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
2286
2390
|
},
|
|
2287
2391
|
exposed: {
|
|
2288
|
-
NotarizationService:
|
|
2392
|
+
NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
2289
2393
|
}
|
|
2290
2394
|
});
|
|
2291
2395
|
this._params = _params;
|
|
@@ -2323,9 +2427,9 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
2323
2427
|
var AUTH_TIMEOUT2 = 3e4;
|
|
2324
2428
|
var DataSpace = class DataSpace2 {
|
|
2325
2429
|
constructor(params) {
|
|
2326
|
-
this._ctx = new
|
|
2430
|
+
this._ctx = new import_context6.Context();
|
|
2327
2431
|
this._state = import_client2.SpaceState.CLOSED;
|
|
2328
|
-
this.stateUpdate = new
|
|
2432
|
+
this.stateUpdate = new import_async11.Event();
|
|
2329
2433
|
var _a;
|
|
2330
2434
|
this._inner = params.inner;
|
|
2331
2435
|
this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
|
|
@@ -2346,7 +2450,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2346
2450
|
snapshotId: params.snapshotId
|
|
2347
2451
|
});
|
|
2348
2452
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
2349
|
-
trustedKeysProvider: () => new import_util4.ComplexSet(
|
|
2453
|
+
trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
|
|
2350
2454
|
update: this._inner.stateUpdate,
|
|
2351
2455
|
authTimeout: AUTH_TIMEOUT2
|
|
2352
2456
|
});
|
|
@@ -2400,12 +2504,12 @@ var DataSpace = class DataSpace2 {
|
|
|
2400
2504
|
* Initialize the data pipeline in a separate task.
|
|
2401
2505
|
*/
|
|
2402
2506
|
initializeDataPipelineAsync() {
|
|
2403
|
-
(0,
|
|
2507
|
+
(0, import_async11.scheduleTask)(this._ctx, async () => {
|
|
2404
2508
|
try {
|
|
2405
2509
|
await this.initializeDataPipeline();
|
|
2406
2510
|
} catch (err) {
|
|
2407
|
-
if (err instanceof
|
|
2408
|
-
(0,
|
|
2511
|
+
if (err instanceof import_errors3.CancelledError) {
|
|
2512
|
+
(0, import_log9.log)("Data pipeline initialization cancelled", err, {
|
|
2409
2513
|
file: "data-space.ts",
|
|
2410
2514
|
line: 178,
|
|
2411
2515
|
scope: this,
|
|
@@ -2413,7 +2517,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2413
2517
|
});
|
|
2414
2518
|
return;
|
|
2415
2519
|
}
|
|
2416
|
-
|
|
2520
|
+
import_log9.log.error("Error initializing data pipeline", err, {
|
|
2417
2521
|
file: "data-space.ts",
|
|
2418
2522
|
line: 182,
|
|
2419
2523
|
scope: this,
|
|
@@ -2425,7 +2529,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2425
2529
|
async initializeDataPipeline() {
|
|
2426
2530
|
var _a, _b, _c, _d;
|
|
2427
2531
|
if (this._state !== import_client2.SpaceState.INACTIVE) {
|
|
2428
|
-
throw new
|
|
2532
|
+
throw new import_errors3.SystemError("Invalid operation");
|
|
2429
2533
|
}
|
|
2430
2534
|
this._state = import_client2.SpaceState.INITIALIZING;
|
|
2431
2535
|
await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
@@ -2433,7 +2537,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2433
2537
|
breakOnStall: false
|
|
2434
2538
|
});
|
|
2435
2539
|
await this._createWritableFeeds();
|
|
2436
|
-
(0,
|
|
2540
|
+
(0, import_log9.log)("Writable feeds created", {}, {
|
|
2437
2541
|
file: "data-space.ts",
|
|
2438
2542
|
line: 200,
|
|
2439
2543
|
scope: this,
|
|
@@ -2454,7 +2558,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2454
2558
|
return pipeline;
|
|
2455
2559
|
}
|
|
2456
2560
|
});
|
|
2457
|
-
(0,
|
|
2561
|
+
(0, import_log9.log)("waiting for data pipeline to reach target timeframe", {}, {
|
|
2458
2562
|
file: "data-space.ts",
|
|
2459
2563
|
line: 220,
|
|
2460
2564
|
scope: this,
|
|
@@ -2464,7 +2568,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2464
2568
|
ctx: this._ctx,
|
|
2465
2569
|
breakOnStall: false
|
|
2466
2570
|
});
|
|
2467
|
-
(0,
|
|
2571
|
+
(0, import_log9.log)("data pipeline ready", {}, {
|
|
2468
2572
|
file: "data-space.ts",
|
|
2469
2573
|
line: 227,
|
|
2470
2574
|
scope: this,
|
|
@@ -2523,7 +2627,7 @@ __decorate([
|
|
|
2523
2627
|
(0, import_debug3.timed)(1e4)
|
|
2524
2628
|
], DataSpace.prototype, "_createWritableFeeds", null);
|
|
2525
2629
|
DataSpace = __decorate([
|
|
2526
|
-
(0,
|
|
2630
|
+
(0, import_async11.trackLeaks)("open", "close")
|
|
2527
2631
|
], DataSpace);
|
|
2528
2632
|
|
|
2529
2633
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
@@ -2547,24 +2651,24 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2547
2651
|
this._modelFactory = _modelFactory;
|
|
2548
2652
|
this._feedStore = _feedStore;
|
|
2549
2653
|
this._snapshotStore = _snapshotStore;
|
|
2550
|
-
this._ctx = new
|
|
2551
|
-
this.updated = new
|
|
2552
|
-
this._spaces = new import_util5.ComplexMap(
|
|
2654
|
+
this._ctx = new import_context7.Context();
|
|
2655
|
+
this.updated = new import_async12.Event();
|
|
2656
|
+
this._spaces = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
|
|
2553
2657
|
this._isOpen = false;
|
|
2554
|
-
this._instanceId =
|
|
2658
|
+
this._instanceId = import_keys9.PublicKey.random().toHex();
|
|
2555
2659
|
}
|
|
2556
2660
|
// TODO(burdon): Remove.
|
|
2557
2661
|
get spaces() {
|
|
2558
2662
|
return this._spaces;
|
|
2559
2663
|
}
|
|
2560
2664
|
async open() {
|
|
2561
|
-
(0,
|
|
2665
|
+
(0, import_log10.log)("open", {}, {
|
|
2562
2666
|
file: "data-space-manager.ts",
|
|
2563
2667
|
line: 83,
|
|
2564
2668
|
scope: this,
|
|
2565
2669
|
callSite: (f, a) => f(...a)
|
|
2566
2670
|
});
|
|
2567
|
-
|
|
2671
|
+
import_log10.log.trace("dxos.echo.data-space-manager", import_protocols6.trace.begin({
|
|
2568
2672
|
id: this._instanceId,
|
|
2569
2673
|
parentId: this._traceParent
|
|
2570
2674
|
}), {
|
|
@@ -2574,7 +2678,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2574
2678
|
callSite: (f, a) => f(...a)
|
|
2575
2679
|
});
|
|
2576
2680
|
await this._metadataStore.load();
|
|
2577
|
-
(0,
|
|
2681
|
+
(0, import_log10.log)("metadata loaded", {
|
|
2578
2682
|
spaces: this._metadataStore.spaces.length
|
|
2579
2683
|
}, {
|
|
2580
2684
|
file: "data-space-manager.ts",
|
|
@@ -2583,7 +2687,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2583
2687
|
callSite: (f, a) => f(...a)
|
|
2584
2688
|
});
|
|
2585
2689
|
for (const spaceMetadata of this._metadataStore.spaces) {
|
|
2586
|
-
(0,
|
|
2690
|
+
(0, import_log10.log)("load space", {
|
|
2587
2691
|
spaceMetadata
|
|
2588
2692
|
}, {
|
|
2589
2693
|
file: "data-space-manager.ts",
|
|
@@ -2598,7 +2702,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2598
2702
|
this.updated.emit();
|
|
2599
2703
|
}
|
|
2600
2704
|
async close() {
|
|
2601
|
-
(0,
|
|
2705
|
+
(0, import_log10.log)("close", {}, {
|
|
2602
2706
|
file: "data-space-manager.ts",
|
|
2603
2707
|
line: 100,
|
|
2604
2708
|
scope: this,
|
|
@@ -2609,7 +2713,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2609
2713
|
for (const space of this._spaces.values()) {
|
|
2610
2714
|
await space.close();
|
|
2611
2715
|
}
|
|
2612
|
-
|
|
2716
|
+
import_log10.log.trace("dxos.echo.data-space-manager", import_protocols6.trace.end({
|
|
2613
2717
|
id: this._instanceId
|
|
2614
2718
|
}), {
|
|
2615
2719
|
file: "data-space-manager.ts",
|
|
@@ -2622,7 +2726,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2622
2726
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
2623
2727
|
*/
|
|
2624
2728
|
async createSpace() {
|
|
2625
|
-
(0,
|
|
2729
|
+
(0, import_node_assert10.default)(this._isOpen, "Not open.");
|
|
2626
2730
|
const spaceKey = await this._keyring.createKey();
|
|
2627
2731
|
const controlFeedKey = await this._keyring.createKey();
|
|
2628
2732
|
const dataFeedKey = await this._keyring.createKey();
|
|
@@ -2632,7 +2736,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2632
2736
|
controlFeedKey,
|
|
2633
2737
|
dataFeedKey
|
|
2634
2738
|
};
|
|
2635
|
-
(0,
|
|
2739
|
+
(0, import_log10.log)("creating space...", {
|
|
2636
2740
|
spaceKey
|
|
2637
2741
|
}, {
|
|
2638
2742
|
file: "data-space-manager.ts",
|
|
@@ -2644,7 +2748,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2644
2748
|
const credentials = await (0, import_echo_pipeline2.spaceGenesis)(this._keyring, this._signingContext, space.inner);
|
|
2645
2749
|
await this._metadataStore.addSpace(metadata);
|
|
2646
2750
|
const memberCredential = credentials[1];
|
|
2647
|
-
(0,
|
|
2751
|
+
(0, import_node_assert10.default)((0, import_credentials10.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
|
|
2648
2752
|
await this._signingContext.recordCredential(memberCredential);
|
|
2649
2753
|
await space.initializeDataPipeline();
|
|
2650
2754
|
this.updated.emit();
|
|
@@ -2652,7 +2756,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2652
2756
|
}
|
|
2653
2757
|
// TODO(burdon): Rename join space.
|
|
2654
2758
|
async acceptSpace(opts) {
|
|
2655
|
-
(0,
|
|
2759
|
+
(0, import_log10.log)("accept space", {
|
|
2656
2760
|
opts
|
|
2657
2761
|
}, {
|
|
2658
2762
|
file: "data-space-manager.ts",
|
|
@@ -2660,8 +2764,8 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2660
2764
|
scope: this,
|
|
2661
2765
|
callSite: (f, a) => f(...a)
|
|
2662
2766
|
});
|
|
2663
|
-
(0,
|
|
2664
|
-
(0,
|
|
2767
|
+
(0, import_node_assert10.default)(this._isOpen, "Not open.");
|
|
2768
|
+
(0, import_node_assert10.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
|
|
2665
2769
|
const metadata = {
|
|
2666
2770
|
key: opts.spaceKey,
|
|
2667
2771
|
genesisFeedKey: opts.genesisFeedKey,
|
|
@@ -2680,13 +2784,13 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2680
2784
|
* TODO(dmaretskyi): Consider removing.
|
|
2681
2785
|
*/
|
|
2682
2786
|
async waitUntilSpaceReady(spaceKey) {
|
|
2683
|
-
await (0,
|
|
2787
|
+
await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
|
|
2684
2788
|
const space = this._spaces.get(spaceKey);
|
|
2685
2789
|
return !!space && space.state === import_client3.SpaceState.READY;
|
|
2686
2790
|
}));
|
|
2687
2791
|
}
|
|
2688
2792
|
async _constructSpace(metadata) {
|
|
2689
|
-
(0,
|
|
2793
|
+
(0, import_log10.log)("construct space", {
|
|
2690
2794
|
metadata
|
|
2691
2795
|
}, {
|
|
2692
2796
|
file: "data-space-manager.ts",
|
|
@@ -2741,7 +2845,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2741
2845
|
snapshotId: metadata.snapshot,
|
|
2742
2846
|
callbacks: {
|
|
2743
2847
|
beforeReady: async () => {
|
|
2744
|
-
(0,
|
|
2848
|
+
(0, import_log10.log)("before space ready", {
|
|
2745
2849
|
space: space.key
|
|
2746
2850
|
}, {
|
|
2747
2851
|
file: "data-space-manager.ts",
|
|
@@ -2752,7 +2856,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2752
2856
|
this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseBackend.createDataServiceHost());
|
|
2753
2857
|
},
|
|
2754
2858
|
afterReady: async () => {
|
|
2755
|
-
(0,
|
|
2859
|
+
(0, import_log10.log)("after space ready", {
|
|
2756
2860
|
space: space.key,
|
|
2757
2861
|
open: this._isOpen
|
|
2758
2862
|
}, {
|
|
@@ -2779,27 +2883,27 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2779
2883
|
}
|
|
2780
2884
|
};
|
|
2781
2885
|
__decorate2([
|
|
2782
|
-
|
|
2886
|
+
import_async12.synchronized
|
|
2783
2887
|
], DataSpaceManager.prototype, "open", null);
|
|
2784
2888
|
__decorate2([
|
|
2785
|
-
|
|
2889
|
+
import_async12.synchronized
|
|
2786
2890
|
], DataSpaceManager.prototype, "close", null);
|
|
2787
2891
|
__decorate2([
|
|
2788
|
-
|
|
2892
|
+
import_async12.synchronized
|
|
2789
2893
|
], DataSpaceManager.prototype, "createSpace", null);
|
|
2790
2894
|
__decorate2([
|
|
2791
|
-
|
|
2895
|
+
import_async12.synchronized
|
|
2792
2896
|
], DataSpaceManager.prototype, "acceptSpace", null);
|
|
2793
2897
|
DataSpaceManager = __decorate2([
|
|
2794
|
-
(0,
|
|
2898
|
+
(0, import_async12.trackLeaks)("open", "close")
|
|
2795
2899
|
], DataSpaceManager);
|
|
2796
2900
|
|
|
2797
2901
|
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
2798
|
-
var
|
|
2902
|
+
var import_async13 = require("@dxos/async");
|
|
2799
2903
|
var import_codec_protobuf10 = require("@dxos/codec-protobuf");
|
|
2800
2904
|
var import_debug4 = require("@dxos/debug");
|
|
2801
2905
|
var import_echo_pipeline3 = require("@dxos/echo-pipeline");
|
|
2802
|
-
var
|
|
2906
|
+
var import_log11 = require("@dxos/log");
|
|
2803
2907
|
var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2804
2908
|
var import_util6 = require("@dxos/util");
|
|
2805
2909
|
var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
|
|
@@ -2826,7 +2930,7 @@ var SpacesServiceImpl = class {
|
|
|
2826
2930
|
const onUpdate = async () => {
|
|
2827
2931
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2828
2932
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
|
|
2829
|
-
(0,
|
|
2933
|
+
(0, import_log11.log)("update", {
|
|
2830
2934
|
spaces
|
|
2831
2935
|
}, {
|
|
2832
2936
|
file: "spaces-service.ts",
|
|
@@ -2838,9 +2942,9 @@ var SpacesServiceImpl = class {
|
|
|
2838
2942
|
spaces
|
|
2839
2943
|
});
|
|
2840
2944
|
};
|
|
2841
|
-
(0,
|
|
2945
|
+
(0, import_async13.scheduleTask)(ctx, async () => {
|
|
2842
2946
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2843
|
-
const subscriptions = new
|
|
2947
|
+
const subscriptions = new import_async13.EventSubscriptions();
|
|
2844
2948
|
ctx.onDispose(() => subscriptions.clear());
|
|
2845
2949
|
const subscribeSpaces = () => {
|
|
2846
2950
|
subscriptions.clear();
|
|
@@ -2875,7 +2979,7 @@ var SpacesServiceImpl = class {
|
|
|
2875
2979
|
}
|
|
2876
2980
|
subscribeMessages({ spaceKey, channel }) {
|
|
2877
2981
|
return new import_codec_protobuf10.Stream(({ ctx, next }) => {
|
|
2878
|
-
(0,
|
|
2982
|
+
(0, import_async13.scheduleTask)(ctx, async () => {
|
|
2879
2983
|
var _a;
|
|
2880
2984
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2881
2985
|
const space = (_a = dataSpaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug4.raise)(new import_echo_pipeline3.SpaceNotFoundError(spaceKey));
|
|
@@ -2896,7 +3000,7 @@ var SpacesServiceImpl = class {
|
|
|
2896
3000
|
}
|
|
2897
3001
|
});
|
|
2898
3002
|
ctx.onDispose(() => processor.close());
|
|
2899
|
-
(0,
|
|
3003
|
+
(0, import_async13.scheduleTask)(ctx, () => processor.open());
|
|
2900
3004
|
});
|
|
2901
3005
|
}
|
|
2902
3006
|
async writeCredentials({ spaceKey, credentials }) {
|
|
@@ -2943,23 +3047,23 @@ var SpacesServiceImpl = class {
|
|
|
2943
3047
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
2944
3048
|
|
|
2945
3049
|
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
2946
|
-
var
|
|
3050
|
+
var import_errors4 = require("@dxos/errors");
|
|
2947
3051
|
var import_config = require("@dxos/protocols/proto/dxos/config");
|
|
2948
3052
|
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
2949
3053
|
var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
|
|
2950
3054
|
var createStorageObjects = (config) => {
|
|
2951
3055
|
const { path = "dxos/storage", storageType, keyStorage, persistent = false } = config != null ? config : {};
|
|
2952
3056
|
if (persistent && storageType === StorageDriver.RAM) {
|
|
2953
|
-
throw new
|
|
3057
|
+
throw new import_errors4.InvalidConfigError("RAM storage cannot be used in persistent mode.");
|
|
2954
3058
|
}
|
|
2955
3059
|
if (!persistent && storageType !== void 0 && storageType !== StorageDriver.RAM) {
|
|
2956
|
-
throw new
|
|
3060
|
+
throw new import_errors4.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
|
|
2957
3061
|
}
|
|
2958
3062
|
if (persistent && keyStorage === StorageDriver.RAM) {
|
|
2959
|
-
throw new
|
|
3063
|
+
throw new import_errors4.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
|
|
2960
3064
|
}
|
|
2961
3065
|
if (!persistent && keyStorage !== StorageDriver.RAM && keyStorage !== void 0) {
|
|
2962
|
-
throw new
|
|
3066
|
+
throw new import_errors4.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
|
|
2963
3067
|
}
|
|
2964
3068
|
return {
|
|
2965
3069
|
storage: (0, import_random_access_storage.createStorage)({
|
|
@@ -3028,8 +3132,8 @@ var SystemServiceImpl = class {
|
|
|
3028
3132
|
};
|
|
3029
3133
|
|
|
3030
3134
|
// packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
|
|
3031
|
-
var
|
|
3032
|
-
var
|
|
3135
|
+
var import_async15 = require("@dxos/async");
|
|
3136
|
+
var import_log12 = require("@dxos/log");
|
|
3033
3137
|
var import_messaging = require("@dxos/messaging");
|
|
3034
3138
|
var import_network_manager2 = require("@dxos/network-manager");
|
|
3035
3139
|
var import_util7 = require("@dxos/util");
|
|
@@ -3088,15 +3192,15 @@ var ClientRpcServer = class {
|
|
|
3088
3192
|
};
|
|
3089
3193
|
|
|
3090
3194
|
// packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
|
|
3091
|
-
var
|
|
3092
|
-
var
|
|
3195
|
+
var import_node_assert11 = __toESM(require("node:assert"));
|
|
3196
|
+
var import_async14 = require("@dxos/async");
|
|
3093
3197
|
var import_client4 = require("@dxos/client");
|
|
3094
3198
|
var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
|
|
3095
3199
|
var import_rpc2 = require("@dxos/rpc");
|
|
3096
3200
|
var ShellRuntimeImpl = class {
|
|
3097
3201
|
constructor(_port) {
|
|
3098
3202
|
this._port = _port;
|
|
3099
|
-
this.layoutUpdate = new
|
|
3203
|
+
this.layoutUpdate = new import_async14.Event();
|
|
3100
3204
|
this._layout = import_iframe.ShellLayout.DEFAULT;
|
|
3101
3205
|
}
|
|
3102
3206
|
get layout() {
|
|
@@ -3118,7 +3222,7 @@ var ShellRuntimeImpl = class {
|
|
|
3118
3222
|
});
|
|
3119
3223
|
}
|
|
3120
3224
|
async setAppContext(context) {
|
|
3121
|
-
(0,
|
|
3225
|
+
(0, import_node_assert11.default)(this._appRpc, "runtime not open");
|
|
3122
3226
|
await this._appRpc.rpc.AppService.setContext(context);
|
|
3123
3227
|
}
|
|
3124
3228
|
async open() {
|
|
@@ -3147,8 +3251,8 @@ var ShellRuntimeImpl = class {
|
|
|
3147
3251
|
};
|
|
3148
3252
|
var MemoryShellRuntime = class {
|
|
3149
3253
|
constructor({ layout, invitationCode, spaceKey } = {}) {
|
|
3150
|
-
this.layoutUpdate = new
|
|
3151
|
-
this.contextUpdate = new
|
|
3254
|
+
this.layoutUpdate = new import_async14.Event();
|
|
3255
|
+
this.contextUpdate = new import_async14.Event();
|
|
3152
3256
|
this._layout = layout != null ? layout : import_iframe.ShellLayout.DEFAULT;
|
|
3153
3257
|
this._invitationCode = invitationCode;
|
|
3154
3258
|
this._spaceKey = spaceKey;
|
|
@@ -3214,7 +3318,7 @@ var IFrameHostRuntime = class {
|
|
|
3214
3318
|
}
|
|
3215
3319
|
]
|
|
3216
3320
|
});
|
|
3217
|
-
this._ready = new
|
|
3321
|
+
this._ready = new import_async15.Trigger();
|
|
3218
3322
|
this._configProvider = configProvider;
|
|
3219
3323
|
this._appPort = appPort;
|
|
3220
3324
|
this._shellPort = shellPort;
|
|
@@ -3230,7 +3334,7 @@ var IFrameHostRuntime = class {
|
|
|
3230
3334
|
}
|
|
3231
3335
|
async start() {
|
|
3232
3336
|
var _a;
|
|
3233
|
-
(0,
|
|
3337
|
+
(0, import_log12.log)("starting...", {}, {
|
|
3234
3338
|
file: "iframe-host-runtime.ts",
|
|
3235
3339
|
line: 75,
|
|
3236
3340
|
scope: this,
|
|
@@ -3238,15 +3342,13 @@ var IFrameHostRuntime = class {
|
|
|
3238
3342
|
});
|
|
3239
3343
|
try {
|
|
3240
3344
|
this._config = await (0, import_util7.getAsyncValue)(this._configProvider);
|
|
3241
|
-
const
|
|
3345
|
+
const signals = this._config.get("runtime.services.signaling");
|
|
3242
3346
|
this._clientServices = new LocalClientServices({
|
|
3243
3347
|
lockKey: LOCK_KEY,
|
|
3244
3348
|
config: this._config,
|
|
3245
3349
|
networkManager: new import_network_manager2.NetworkManager({
|
|
3246
3350
|
log: true,
|
|
3247
|
-
signalManager:
|
|
3248
|
-
signalServer
|
|
3249
|
-
]) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
|
|
3351
|
+
signalManager: signals ? new import_messaging.WebsocketSignalManager(signals) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
|
|
3250
3352
|
transportFactory: this._transportFactory
|
|
3251
3353
|
})
|
|
3252
3354
|
});
|
|
@@ -3281,7 +3383,7 @@ var IFrameHostRuntime = class {
|
|
|
3281
3383
|
(_a = this._shellRuntime) == null ? void 0 : _a.open()
|
|
3282
3384
|
]);
|
|
3283
3385
|
this._ready.wake(void 0);
|
|
3284
|
-
(0,
|
|
3386
|
+
(0, import_log12.log)("started", {}, {
|
|
3285
3387
|
file: "iframe-host-runtime.ts",
|
|
3286
3388
|
line: 118,
|
|
3287
3389
|
scope: this,
|
|
@@ -3289,7 +3391,7 @@ var IFrameHostRuntime = class {
|
|
|
3289
3391
|
});
|
|
3290
3392
|
} catch (err) {
|
|
3291
3393
|
this._ready.wake(err);
|
|
3292
|
-
|
|
3394
|
+
import_log12.log.catch(err, {}, {
|
|
3293
3395
|
file: "iframe-host-runtime.ts",
|
|
3294
3396
|
line: 121,
|
|
3295
3397
|
scope: this,
|
|
@@ -3299,7 +3401,7 @@ var IFrameHostRuntime = class {
|
|
|
3299
3401
|
}
|
|
3300
3402
|
async stop() {
|
|
3301
3403
|
var _a;
|
|
3302
|
-
(0,
|
|
3404
|
+
(0, import_log12.log)("stopping...", {}, {
|
|
3303
3405
|
file: "iframe-host-runtime.ts",
|
|
3304
3406
|
line: 126,
|
|
3305
3407
|
scope: this,
|
|
@@ -3308,7 +3410,7 @@ var IFrameHostRuntime = class {
|
|
|
3308
3410
|
await this._clientRpc.close();
|
|
3309
3411
|
await this._clientServices.close();
|
|
3310
3412
|
await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
|
|
3311
|
-
(0,
|
|
3413
|
+
(0, import_log12.log)("stopped", {}, {
|
|
3312
3414
|
file: "iframe-host-runtime.ts",
|
|
3313
3415
|
line: 130,
|
|
3314
3416
|
scope: this,
|
|
@@ -3317,11 +3419,13 @@ var IFrameHostRuntime = class {
|
|
|
3317
3419
|
}
|
|
3318
3420
|
};
|
|
3319
3421
|
__decorate3([
|
|
3320
|
-
|
|
3422
|
+
import_log12.logInfo
|
|
3321
3423
|
], IFrameHostRuntime.prototype, "origin", void 0);
|
|
3322
3424
|
|
|
3323
3425
|
// packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
|
|
3324
3426
|
var import_client5 = require("@dxos/client");
|
|
3427
|
+
var import_errors5 = require("@dxos/errors");
|
|
3428
|
+
var import_log13 = require("@dxos/log");
|
|
3325
3429
|
var import_network_manager3 = require("@dxos/network-manager");
|
|
3326
3430
|
var import_rpc3 = require("@dxos/rpc");
|
|
3327
3431
|
var IFrameProxyRuntime = class {
|
|
@@ -3365,7 +3469,7 @@ var IFrameProxyRuntime = class {
|
|
|
3365
3469
|
}
|
|
3366
3470
|
},
|
|
3367
3471
|
port: this._systemPort,
|
|
3368
|
-
timeout:
|
|
3472
|
+
timeout: 1e3
|
|
3369
3473
|
});
|
|
3370
3474
|
this._workerAppPort.subscribe((msg) => this._windowAppPort.send(msg));
|
|
3371
3475
|
this._windowAppPort.subscribe((msg) => this._workerAppPort.send(msg));
|
|
@@ -3378,10 +3482,20 @@ var IFrameProxyRuntime = class {
|
|
|
3378
3482
|
}
|
|
3379
3483
|
async open(origin) {
|
|
3380
3484
|
var _a;
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3485
|
+
try {
|
|
3486
|
+
await this._systemRpc.open();
|
|
3487
|
+
await this._systemRpc.rpc.WorkerService.start({
|
|
3488
|
+
origin
|
|
3489
|
+
});
|
|
3490
|
+
} catch (err) {
|
|
3491
|
+
import_log13.log.catch(err, {}, {
|
|
3492
|
+
file: "iframe-proxy-runtime.ts",
|
|
3493
|
+
line: 79,
|
|
3494
|
+
scope: this,
|
|
3495
|
+
callSite: (f, a) => f(...a)
|
|
3496
|
+
});
|
|
3497
|
+
throw new import_errors5.RemoteServiceConnectionError("Failed to connect to worker");
|
|
3498
|
+
}
|
|
3385
3499
|
await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
|
|
3386
3500
|
}
|
|
3387
3501
|
async close() {
|
|
@@ -3393,8 +3507,8 @@ var IFrameProxyRuntime = class {
|
|
|
3393
3507
|
};
|
|
3394
3508
|
|
|
3395
3509
|
// packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
|
|
3396
|
-
var
|
|
3397
|
-
var
|
|
3510
|
+
var import_async16 = require("@dxos/async");
|
|
3511
|
+
var import_log14 = require("@dxos/log");
|
|
3398
3512
|
var __decorate4 = function(decorators, target, key, desc) {
|
|
3399
3513
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3400
3514
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -3412,7 +3526,7 @@ var Message;
|
|
|
3412
3526
|
var VaultResourceLock = class {
|
|
3413
3527
|
constructor({ lockKey, onAcquire, onRelease }) {
|
|
3414
3528
|
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
3415
|
-
this._releaseTrigger = new
|
|
3529
|
+
this._releaseTrigger = new import_async16.Trigger();
|
|
3416
3530
|
this._lockKey = lockKey;
|
|
3417
3531
|
this._onAcquire = onAcquire;
|
|
3418
3532
|
this._onRelease = onRelease;
|
|
@@ -3426,28 +3540,28 @@ var VaultResourceLock = class {
|
|
|
3426
3540
|
message: Message.ACQUIRING
|
|
3427
3541
|
});
|
|
3428
3542
|
try {
|
|
3429
|
-
(0,
|
|
3543
|
+
(0, import_log14.log)("aquiring lock...", {}, {
|
|
3430
3544
|
file: "vault-resource-lock.ts",
|
|
3431
3545
|
line: 44,
|
|
3432
3546
|
scope: this,
|
|
3433
3547
|
callSite: (f, a) => f(...a)
|
|
3434
3548
|
});
|
|
3435
|
-
await (0,
|
|
3436
|
-
(0,
|
|
3549
|
+
await (0, import_async16.asyncTimeout)(this._requestLock(), 3e3);
|
|
3550
|
+
(0, import_log14.log)("acquired lock", {}, {
|
|
3437
3551
|
file: "vault-resource-lock.ts",
|
|
3438
3552
|
line: 46,
|
|
3439
3553
|
scope: this,
|
|
3440
3554
|
callSite: (f, a) => f(...a)
|
|
3441
3555
|
});
|
|
3442
3556
|
} catch (e) {
|
|
3443
|
-
(0,
|
|
3557
|
+
(0, import_log14.log)("stealing lock...", {}, {
|
|
3444
3558
|
file: "vault-resource-lock.ts",
|
|
3445
3559
|
line: 48,
|
|
3446
3560
|
scope: this,
|
|
3447
3561
|
callSite: (f, a) => f(...a)
|
|
3448
3562
|
});
|
|
3449
3563
|
await this._requestLock(true);
|
|
3450
|
-
(0,
|
|
3564
|
+
(0, import_log14.log)("stolen lock", {}, {
|
|
3451
3565
|
file: "vault-resource-lock.ts",
|
|
3452
3566
|
line: 50,
|
|
3453
3567
|
scope: this,
|
|
@@ -3464,7 +3578,7 @@ var VaultResourceLock = class {
|
|
|
3464
3578
|
}
|
|
3465
3579
|
}
|
|
3466
3580
|
async _requestLock(steal = false) {
|
|
3467
|
-
(0,
|
|
3581
|
+
(0, import_log14.log)("requesting lock...", {
|
|
3468
3582
|
steal
|
|
3469
3583
|
}, {
|
|
3470
3584
|
file: "vault-resource-lock.ts",
|
|
@@ -3472,23 +3586,23 @@ var VaultResourceLock = class {
|
|
|
3472
3586
|
scope: this,
|
|
3473
3587
|
callSite: (f, a) => f(...a)
|
|
3474
3588
|
});
|
|
3475
|
-
const acquired = new
|
|
3589
|
+
const acquired = new import_async16.Trigger();
|
|
3476
3590
|
void navigator.locks.request(this._lockKey, {
|
|
3477
3591
|
steal
|
|
3478
3592
|
}, async () => {
|
|
3479
3593
|
var _a, _b;
|
|
3480
3594
|
await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
|
|
3481
3595
|
acquired.wake();
|
|
3482
|
-
this._releaseTrigger = new
|
|
3596
|
+
this._releaseTrigger = new import_async16.Trigger();
|
|
3483
3597
|
await this._releaseTrigger.wait();
|
|
3484
|
-
(0,
|
|
3598
|
+
(0, import_log14.log)("releasing lock...", {}, {
|
|
3485
3599
|
file: "vault-resource-lock.ts",
|
|
3486
3600
|
line: 74,
|
|
3487
3601
|
scope: this,
|
|
3488
3602
|
callSite: (f, a) => f(...a)
|
|
3489
3603
|
});
|
|
3490
3604
|
await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
|
|
3491
|
-
(0,
|
|
3605
|
+
(0, import_log14.log)("released lock", {}, {
|
|
3492
3606
|
file: "vault-resource-lock.ts",
|
|
3493
3607
|
line: 76,
|
|
3494
3608
|
scope: this,
|
|
@@ -3499,7 +3613,7 @@ var VaultResourceLock = class {
|
|
|
3499
3613
|
await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
|
|
3500
3614
|
});
|
|
3501
3615
|
await acquired.wait();
|
|
3502
|
-
(0,
|
|
3616
|
+
(0, import_log14.log)("recieved lock", {
|
|
3503
3617
|
steal
|
|
3504
3618
|
}, {
|
|
3505
3619
|
file: "vault-resource-lock.ts",
|
|
@@ -3510,20 +3624,20 @@ var VaultResourceLock = class {
|
|
|
3510
3624
|
}
|
|
3511
3625
|
};
|
|
3512
3626
|
__decorate4([
|
|
3513
|
-
|
|
3627
|
+
import_log14.logInfo
|
|
3514
3628
|
], VaultResourceLock.prototype, "lockKey", null);
|
|
3515
3629
|
|
|
3516
3630
|
// packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
|
|
3517
|
-
var
|
|
3518
|
-
var
|
|
3631
|
+
var import_async18 = require("@dxos/async");
|
|
3632
|
+
var import_log16 = require("@dxos/log");
|
|
3519
3633
|
var import_messaging2 = require("@dxos/messaging");
|
|
3520
3634
|
var import_network_manager4 = require("@dxos/network-manager");
|
|
3521
3635
|
|
|
3522
3636
|
// packages/sdk/client-services/src/packlets/vault/worker-session.ts
|
|
3523
|
-
var
|
|
3524
|
-
var
|
|
3637
|
+
var import_node_assert12 = __toESM(require("node:assert"));
|
|
3638
|
+
var import_async17 = require("@dxos/async");
|
|
3525
3639
|
var import_client6 = require("@dxos/client");
|
|
3526
|
-
var
|
|
3640
|
+
var import_log15 = require("@dxos/log");
|
|
3527
3641
|
var import_rpc4 = require("@dxos/rpc");
|
|
3528
3642
|
var import_util8 = require("@dxos/util");
|
|
3529
3643
|
var __decorate5 = function(decorators, target, key, desc) {
|
|
@@ -3540,10 +3654,10 @@ var WorkerSession = class {
|
|
|
3540
3654
|
constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
|
|
3541
3655
|
heartbeatInterval: 1e3
|
|
3542
3656
|
} }) {
|
|
3543
|
-
this._startTrigger = new
|
|
3657
|
+
this._startTrigger = new import_async17.Trigger();
|
|
3544
3658
|
this.onClose = new import_util8.Callback();
|
|
3545
|
-
(0,
|
|
3546
|
-
(0,
|
|
3659
|
+
(0, import_node_assert12.default)(options);
|
|
3660
|
+
(0, import_node_assert12.default)(serviceHost);
|
|
3547
3661
|
this._options = options;
|
|
3548
3662
|
this._serviceHost = serviceHost;
|
|
3549
3663
|
const middleware = {
|
|
@@ -3590,7 +3704,7 @@ var WorkerSession = class {
|
|
|
3590
3704
|
try {
|
|
3591
3705
|
await this.close();
|
|
3592
3706
|
} catch (err) {
|
|
3593
|
-
|
|
3707
|
+
import_log15.log.catch(err, {}, {
|
|
3594
3708
|
file: "worker-session.ts",
|
|
3595
3709
|
line: 107,
|
|
3596
3710
|
scope: this,
|
|
@@ -3608,7 +3722,7 @@ var WorkerSession = class {
|
|
|
3608
3722
|
this.bridgeService = this._iframeRpc.rpc.BridgeService;
|
|
3609
3723
|
}
|
|
3610
3724
|
async open() {
|
|
3611
|
-
|
|
3725
|
+
import_log15.log.info("opening..", {}, {
|
|
3612
3726
|
file: "worker-session.ts",
|
|
3613
3727
|
line: 121,
|
|
3614
3728
|
scope: this,
|
|
@@ -3626,7 +3740,7 @@ var WorkerSession = class {
|
|
|
3626
3740
|
try {
|
|
3627
3741
|
await this._iframeRpc.rpc.IframeService.heartbeat();
|
|
3628
3742
|
} catch (err1) {
|
|
3629
|
-
|
|
3743
|
+
import_log15.log.warn("Heartbeat failed", {
|
|
3630
3744
|
err: err1
|
|
3631
3745
|
}, {
|
|
3632
3746
|
file: "worker-session.ts",
|
|
@@ -3637,7 +3751,7 @@ var WorkerSession = class {
|
|
|
3637
3751
|
try {
|
|
3638
3752
|
await this.close();
|
|
3639
3753
|
} catch (err) {
|
|
3640
|
-
|
|
3754
|
+
import_log15.log.catch(err, {}, {
|
|
3641
3755
|
file: "worker-session.ts",
|
|
3642
3756
|
line: 137,
|
|
3643
3757
|
scope: this,
|
|
@@ -3648,7 +3762,7 @@ var WorkerSession = class {
|
|
|
3648
3762
|
}, this._options.heartbeatInterval);
|
|
3649
3763
|
}
|
|
3650
3764
|
async close() {
|
|
3651
|
-
|
|
3765
|
+
import_log15.log.info("closing..", {}, {
|
|
3652
3766
|
file: "worker-session.ts",
|
|
3653
3767
|
line: 144,
|
|
3654
3768
|
scope: this,
|
|
@@ -3657,7 +3771,7 @@ var WorkerSession = class {
|
|
|
3657
3771
|
try {
|
|
3658
3772
|
await this.onClose.callIfSet();
|
|
3659
3773
|
} catch (err) {
|
|
3660
|
-
|
|
3774
|
+
import_log15.log.catch(err, {}, {
|
|
3661
3775
|
file: "worker-session.ts",
|
|
3662
3776
|
line: 148,
|
|
3663
3777
|
scope: this,
|
|
@@ -3674,9 +3788,9 @@ var WorkerSession = class {
|
|
|
3674
3788
|
}
|
|
3675
3789
|
async _maybeOpenShell() {
|
|
3676
3790
|
try {
|
|
3677
|
-
await (0,
|
|
3791
|
+
await (0, import_async17.asyncTimeout)(this._shellClientRpc.open(), 1e3);
|
|
3678
3792
|
} catch (e) {
|
|
3679
|
-
|
|
3793
|
+
import_log15.log.info("No shell connected.", {}, {
|
|
3680
3794
|
file: "worker-session.ts",
|
|
3681
3795
|
line: 162,
|
|
3682
3796
|
scope: this,
|
|
@@ -3686,7 +3800,7 @@ var WorkerSession = class {
|
|
|
3686
3800
|
}
|
|
3687
3801
|
};
|
|
3688
3802
|
__decorate5([
|
|
3689
|
-
|
|
3803
|
+
import_log15.logInfo
|
|
3690
3804
|
], WorkerSession.prototype, "origin", void 0);
|
|
3691
3805
|
|
|
3692
3806
|
// packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
|
|
@@ -3695,7 +3809,7 @@ var WorkerRuntime = class {
|
|
|
3695
3809
|
constructor(_configProvider) {
|
|
3696
3810
|
this._configProvider = _configProvider;
|
|
3697
3811
|
this._transportFactory = new import_network_manager4.WebRTCTransportProxyFactory();
|
|
3698
|
-
this._ready = new
|
|
3812
|
+
this._ready = new import_async18.Trigger();
|
|
3699
3813
|
this.sessions = /* @__PURE__ */ new Set();
|
|
3700
3814
|
this._clientServices = new ClientServicesHost();
|
|
3701
3815
|
}
|
|
@@ -3703,7 +3817,7 @@ var WorkerRuntime = class {
|
|
|
3703
3817
|
return this._clientServices;
|
|
3704
3818
|
}
|
|
3705
3819
|
async start() {
|
|
3706
|
-
(0,
|
|
3820
|
+
(0, import_log16.log)("starting...", {}, {
|
|
3707
3821
|
file: "worker-runtime.ts",
|
|
3708
3822
|
line: 48,
|
|
3709
3823
|
scope: this,
|
|
@@ -3711,20 +3825,18 @@ var WorkerRuntime = class {
|
|
|
3711
3825
|
});
|
|
3712
3826
|
try {
|
|
3713
3827
|
this._config = await this._configProvider();
|
|
3714
|
-
const
|
|
3828
|
+
const signals = this._config.get("runtime.services.signaling");
|
|
3715
3829
|
this._clientServices.initialize({
|
|
3716
3830
|
config: this._config,
|
|
3717
3831
|
networkManager: new import_network_manager4.NetworkManager({
|
|
3718
3832
|
log: true,
|
|
3719
|
-
signalManager:
|
|
3720
|
-
signalServer
|
|
3721
|
-
]) : new import_messaging2.MemorySignalManager(new import_messaging2.MemorySignalManagerContext()),
|
|
3833
|
+
signalManager: signals ? new import_messaging2.WebsocketSignalManager(signals) : new import_messaging2.MemorySignalManager(new import_messaging2.MemorySignalManagerContext()),
|
|
3722
3834
|
transportFactory: this._transportFactory
|
|
3723
3835
|
})
|
|
3724
3836
|
});
|
|
3725
3837
|
await this._clientServices.open();
|
|
3726
3838
|
this._ready.wake(void 0);
|
|
3727
|
-
(0,
|
|
3839
|
+
(0, import_log16.log)("started", {}, {
|
|
3728
3840
|
file: "worker-runtime.ts",
|
|
3729
3841
|
line: 65,
|
|
3730
3842
|
scope: this,
|
|
@@ -3732,7 +3844,7 @@ var WorkerRuntime = class {
|
|
|
3732
3844
|
});
|
|
3733
3845
|
} catch (err) {
|
|
3734
3846
|
this._ready.wake(err);
|
|
3735
|
-
|
|
3847
|
+
import_log16.log.catch(err, {}, {
|
|
3736
3848
|
file: "worker-runtime.ts",
|
|
3737
3849
|
line: 68,
|
|
3738
3850
|
scope: this,
|
|
@@ -3784,27 +3896,27 @@ var WorkerRuntime = class {
|
|
|
3784
3896
|
};
|
|
3785
3897
|
|
|
3786
3898
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
3787
|
-
var
|
|
3788
|
-
var
|
|
3899
|
+
var import_node_assert13 = __toESM(require("node:assert"));
|
|
3900
|
+
var import_async19 = require("@dxos/async");
|
|
3789
3901
|
var import_client7 = require("@dxos/client");
|
|
3790
3902
|
var import_credentials11 = require("@dxos/credentials");
|
|
3791
3903
|
var import_debug6 = require("@dxos/debug");
|
|
3792
3904
|
var import_echo_pipeline4 = require("@dxos/echo-pipeline");
|
|
3793
3905
|
var import_feed_store4 = require("@dxos/feed-store");
|
|
3794
3906
|
var import_keyring = require("@dxos/keyring");
|
|
3795
|
-
var
|
|
3796
|
-
var
|
|
3797
|
-
var
|
|
3907
|
+
var import_keys10 = require("@dxos/keys");
|
|
3908
|
+
var import_log17 = require("@dxos/log");
|
|
3909
|
+
var import_protocols7 = require("@dxos/protocols");
|
|
3798
3910
|
var ServiceContext = class {
|
|
3799
3911
|
// prettier-ignore
|
|
3800
3912
|
constructor(storage, networkManager, modelFactory) {
|
|
3801
3913
|
this.storage = storage;
|
|
3802
3914
|
this.networkManager = networkManager;
|
|
3803
3915
|
this.modelFactory = modelFactory;
|
|
3804
|
-
this.initialized = new
|
|
3916
|
+
this.initialized = new import_async19.Trigger();
|
|
3805
3917
|
this.dataServiceSubscriptions = new import_echo_pipeline4.DataServiceSubscriptions();
|
|
3806
3918
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
3807
|
-
this._instanceId =
|
|
3919
|
+
this._instanceId = import_keys10.PublicKey.random().toHex();
|
|
3808
3920
|
networkManager._traceParent = this._instanceId;
|
|
3809
3921
|
this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
|
|
3810
3922
|
this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
|
|
@@ -3833,7 +3945,7 @@ var ServiceContext = class {
|
|
|
3833
3945
|
}, this._acceptIdentity.bind(this)));
|
|
3834
3946
|
}
|
|
3835
3947
|
async open() {
|
|
3836
|
-
|
|
3948
|
+
import_log17.log.trace("dxos.sdk.service-context", import_protocols7.trace.begin({
|
|
3837
3949
|
id: this._instanceId
|
|
3838
3950
|
}), {
|
|
3839
3951
|
file: "service-context.ts",
|
|
@@ -3841,7 +3953,7 @@ var ServiceContext = class {
|
|
|
3841
3953
|
scope: this,
|
|
3842
3954
|
callSite: (f, a) => f(...a)
|
|
3843
3955
|
});
|
|
3844
|
-
(0,
|
|
3956
|
+
(0, import_log17.log)("opening...", {}, {
|
|
3845
3957
|
file: "service-context.ts",
|
|
3846
3958
|
line: 117,
|
|
3847
3959
|
scope: this,
|
|
@@ -3853,7 +3965,7 @@ var ServiceContext = class {
|
|
|
3853
3965
|
if (this.identityManager.identity) {
|
|
3854
3966
|
await this._initialize();
|
|
3855
3967
|
}
|
|
3856
|
-
(0,
|
|
3968
|
+
(0, import_log17.log)("opened", {}, {
|
|
3857
3969
|
file: "service-context.ts",
|
|
3858
3970
|
line: 124,
|
|
3859
3971
|
scope: this,
|
|
@@ -3862,7 +3974,7 @@ var ServiceContext = class {
|
|
|
3862
3974
|
}
|
|
3863
3975
|
async close() {
|
|
3864
3976
|
var _a, _b;
|
|
3865
|
-
(0,
|
|
3977
|
+
(0, import_log17.log)("closing...", {}, {
|
|
3866
3978
|
file: "service-context.ts",
|
|
3867
3979
|
line: 128,
|
|
3868
3980
|
scope: this,
|
|
@@ -3875,13 +3987,13 @@ var ServiceContext = class {
|
|
|
3875
3987
|
await this.feedStore.close();
|
|
3876
3988
|
await this.networkManager.close();
|
|
3877
3989
|
this.dataServiceSubscriptions.clear();
|
|
3878
|
-
(0,
|
|
3990
|
+
(0, import_log17.log)("closed", {}, {
|
|
3879
3991
|
file: "service-context.ts",
|
|
3880
3992
|
line: 136,
|
|
3881
3993
|
scope: this,
|
|
3882
3994
|
callSite: (f, a) => f(...a)
|
|
3883
3995
|
});
|
|
3884
|
-
|
|
3996
|
+
import_log17.log.trace("dxos.sdk.service-context", import_protocols7.trace.end({
|
|
3885
3997
|
id: this._instanceId
|
|
3886
3998
|
}), {
|
|
3887
3999
|
file: "service-context.ts",
|
|
@@ -3897,7 +4009,7 @@ var ServiceContext = class {
|
|
|
3897
4009
|
}
|
|
3898
4010
|
getInvitationHandler(invitation) {
|
|
3899
4011
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
3900
|
-
(0,
|
|
4012
|
+
(0, import_node_assert13.default)(factory, `Unknown invitation kind: ${invitation.kind}`);
|
|
3901
4013
|
return factory(invitation);
|
|
3902
4014
|
}
|
|
3903
4015
|
async _acceptIdentity(params) {
|
|
@@ -3908,7 +4020,7 @@ var ServiceContext = class {
|
|
|
3908
4020
|
// Called when identity is created.
|
|
3909
4021
|
async _initialize() {
|
|
3910
4022
|
var _a;
|
|
3911
|
-
(0,
|
|
4023
|
+
(0, import_log17.log)("initializing spaces...", {}, {
|
|
3912
4024
|
file: "service-context.ts",
|
|
3913
4025
|
line: 163,
|
|
3914
4026
|
scope: this,
|
|
@@ -3932,7 +4044,7 @@ var ServiceContext = class {
|
|
|
3932
4044
|
this.dataSpaceManager._traceParent = this._instanceId;
|
|
3933
4045
|
await this.dataSpaceManager.open();
|
|
3934
4046
|
this._handlerFactories.set(import_client7.Invitation.Kind.SPACE, (invitation) => {
|
|
3935
|
-
(0,
|
|
4047
|
+
(0, import_node_assert13.default)(this.dataSpaceManager, "dataSpaceManager not initialized yet");
|
|
3936
4048
|
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
3937
4049
|
});
|
|
3938
4050
|
this.initialized.wake();
|
|
@@ -3946,7 +4058,7 @@ var ServiceContext = class {
|
|
|
3946
4058
|
return;
|
|
3947
4059
|
}
|
|
3948
4060
|
if (!this.dataSpaceManager) {
|
|
3949
|
-
(0,
|
|
4061
|
+
(0, import_log17.log)("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
3950
4062
|
details: assertion
|
|
3951
4063
|
}, {
|
|
3952
4064
|
file: "service-context.ts",
|
|
@@ -3957,7 +4069,7 @@ var ServiceContext = class {
|
|
|
3957
4069
|
return;
|
|
3958
4070
|
}
|
|
3959
4071
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
3960
|
-
(0,
|
|
4072
|
+
(0, import_log17.log)("space already exists, ignoring space admission", {
|
|
3961
4073
|
details: assertion
|
|
3962
4074
|
}, {
|
|
3963
4075
|
file: "service-context.ts",
|
|
@@ -3968,7 +4080,7 @@ var ServiceContext = class {
|
|
|
3968
4080
|
return;
|
|
3969
4081
|
}
|
|
3970
4082
|
try {
|
|
3971
|
-
(0,
|
|
4083
|
+
(0, import_log17.log)("accepting space recorded in halo", {
|
|
3972
4084
|
details: assertion
|
|
3973
4085
|
}, {
|
|
3974
4086
|
file: "service-context.ts",
|
|
@@ -3981,7 +4093,7 @@ var ServiceContext = class {
|
|
|
3981
4093
|
genesisFeedKey: assertion.genesisFeedKey
|
|
3982
4094
|
});
|
|
3983
4095
|
} catch (err) {
|
|
3984
|
-
|
|
4096
|
+
import_log17.log.catch(err, {}, {
|
|
3985
4097
|
file: "service-context.ts",
|
|
3986
4098
|
line: 220,
|
|
3987
4099
|
scope: this,
|
|
@@ -4029,7 +4141,7 @@ var ClientServicesHost = class {
|
|
|
4029
4141
|
// TODO(wittjosiah): Turn this on by default.
|
|
4030
4142
|
lockKey
|
|
4031
4143
|
} = {}) {
|
|
4032
|
-
this._statusUpdate = new
|
|
4144
|
+
this._statusUpdate = new import_async20.Event();
|
|
4033
4145
|
this._opening = false;
|
|
4034
4146
|
this._open = false;
|
|
4035
4147
|
this._instanceId = import_client8.PublicKey.random().toHex();
|
|
@@ -4086,16 +4198,16 @@ var ClientServicesHost = class {
|
|
|
4086
4198
|
* Can only be called once.
|
|
4087
4199
|
*/
|
|
4088
4200
|
initialize({ config, networkManager }) {
|
|
4089
|
-
(0,
|
|
4201
|
+
(0, import_node_assert14.default)(!this._open, "service host is open");
|
|
4090
4202
|
if (config) {
|
|
4091
|
-
(0,
|
|
4203
|
+
(0, import_node_assert14.default)(!this._config, "config already set");
|
|
4092
4204
|
this._config = config;
|
|
4093
4205
|
if (!this._storage) {
|
|
4094
4206
|
this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
|
|
4095
4207
|
}
|
|
4096
4208
|
}
|
|
4097
4209
|
if (networkManager) {
|
|
4098
|
-
(0,
|
|
4210
|
+
(0, import_node_assert14.default)(!this._networkManager, "network manager already set");
|
|
4099
4211
|
this._networkManager = networkManager;
|
|
4100
4212
|
}
|
|
4101
4213
|
}
|
|
@@ -4104,7 +4216,7 @@ var ClientServicesHost = class {
|
|
|
4104
4216
|
if (this._open) {
|
|
4105
4217
|
return;
|
|
4106
4218
|
}
|
|
4107
|
-
|
|
4219
|
+
import_log18.log.trace("dxos.sdk.client-services-host", import_protocols8.trace.begin({
|
|
4108
4220
|
id: this._instanceId
|
|
4109
4221
|
}), {
|
|
4110
4222
|
file: "service-host.ts",
|
|
@@ -4112,11 +4224,11 @@ var ClientServicesHost = class {
|
|
|
4112
4224
|
scope: this,
|
|
4113
4225
|
callSite: (f, a) => f(...a)
|
|
4114
4226
|
});
|
|
4115
|
-
(0,
|
|
4116
|
-
(0,
|
|
4117
|
-
(0,
|
|
4227
|
+
(0, import_node_assert14.default)(this._config, "config not set");
|
|
4228
|
+
(0, import_node_assert14.default)(this._storage, "storage not set");
|
|
4229
|
+
(0, import_node_assert14.default)(this._networkManager, "network manager not set");
|
|
4118
4230
|
this._opening = true;
|
|
4119
|
-
(0,
|
|
4231
|
+
(0, import_log18.log)("opening...", {
|
|
4120
4232
|
lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
|
|
4121
4233
|
}, {
|
|
4122
4234
|
file: "service-host.ts",
|
|
@@ -4150,7 +4262,7 @@ var ClientServicesHost = class {
|
|
|
4150
4262
|
this._open = true;
|
|
4151
4263
|
this._statusUpdate.emit();
|
|
4152
4264
|
const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
|
|
4153
|
-
(0,
|
|
4265
|
+
(0, import_log18.log)("opened", {
|
|
4154
4266
|
deviceKey
|
|
4155
4267
|
}, {
|
|
4156
4268
|
file: "service-host.ts",
|
|
@@ -4165,7 +4277,7 @@ var ClientServicesHost = class {
|
|
|
4165
4277
|
return;
|
|
4166
4278
|
}
|
|
4167
4279
|
const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
|
|
4168
|
-
(0,
|
|
4280
|
+
(0, import_log18.log)("closing...", {
|
|
4169
4281
|
deviceKey
|
|
4170
4282
|
}, {
|
|
4171
4283
|
file: "service-host.ts",
|
|
@@ -4179,7 +4291,7 @@ var ClientServicesHost = class {
|
|
|
4179
4291
|
await this._serviceContext.close();
|
|
4180
4292
|
this._open = false;
|
|
4181
4293
|
this._statusUpdate.emit();
|
|
4182
|
-
(0,
|
|
4294
|
+
(0, import_log18.log)("closed", {
|
|
4183
4295
|
deviceKey
|
|
4184
4296
|
}, {
|
|
4185
4297
|
file: "service-host.ts",
|
|
@@ -4187,7 +4299,7 @@ var ClientServicesHost = class {
|
|
|
4187
4299
|
scope: this,
|
|
4188
4300
|
callSite: (f, a) => f(...a)
|
|
4189
4301
|
});
|
|
4190
|
-
|
|
4302
|
+
import_log18.log.trace("dxos.sdk.client-services-host", import_protocols8.trace.end({
|
|
4191
4303
|
id: this._instanceId
|
|
4192
4304
|
}), {
|
|
4193
4305
|
file: "service-host.ts",
|
|
@@ -4198,7 +4310,7 @@ var ClientServicesHost = class {
|
|
|
4198
4310
|
}
|
|
4199
4311
|
async reset() {
|
|
4200
4312
|
var _a;
|
|
4201
|
-
(0,
|
|
4313
|
+
(0, import_log18.log)("resetting...", {}, {
|
|
4202
4314
|
file: "service-host.ts",
|
|
4203
4315
|
line: 240,
|
|
4204
4316
|
scope: this,
|
|
@@ -4206,7 +4318,7 @@ var ClientServicesHost = class {
|
|
|
4206
4318
|
});
|
|
4207
4319
|
await ((_a = this._serviceContext) == null ? void 0 : _a.close());
|
|
4208
4320
|
await this._storage.reset();
|
|
4209
|
-
(0,
|
|
4321
|
+
(0, import_log18.log)("reset", {}, {
|
|
4210
4322
|
file: "service-host.ts",
|
|
4211
4323
|
line: 243,
|
|
4212
4324
|
scope: this,
|
|
@@ -4239,7 +4351,7 @@ var LocalClientServices = class {
|
|
|
4239
4351
|
|
|
4240
4352
|
// packages/sdk/client-services/src/packlets/services/utils.ts
|
|
4241
4353
|
var import_config2 = require("@dxos/config");
|
|
4242
|
-
var
|
|
4354
|
+
var import_log19 = require("@dxos/log");
|
|
4243
4355
|
var import_messaging3 = require("@dxos/messaging");
|
|
4244
4356
|
var import_network_manager5 = require("@dxos/network-manager");
|
|
4245
4357
|
var fromHost = (config = new import_config2.Config()) => {
|
|
@@ -4249,11 +4361,9 @@ var fromHost = (config = new import_config2.Config()) => {
|
|
|
4249
4361
|
});
|
|
4250
4362
|
};
|
|
4251
4363
|
var createNetworkManager = (config, options = {}) => {
|
|
4252
|
-
const
|
|
4253
|
-
if (
|
|
4254
|
-
const { log: log1 = true, signalManager = new import_messaging3.WebsocketSignalManager(
|
|
4255
|
-
signalServer
|
|
4256
|
-
]), transportFactory = (0, import_network_manager5.createWebRTCTransportFactory)({
|
|
4364
|
+
const signals = config.get("runtime.services.signaling");
|
|
4365
|
+
if (signals) {
|
|
4366
|
+
const { log: log1 = true, signalManager = new import_messaging3.WebsocketSignalManager(signals), transportFactory = (0, import_network_manager5.createWebRTCTransportFactory)({
|
|
4257
4367
|
iceServers: config.get("runtime.services.ice")
|
|
4258
4368
|
}) } = options;
|
|
4259
4369
|
return new import_network_manager5.NetworkManager({
|
|
@@ -4262,7 +4372,7 @@ var createNetworkManager = (config, options = {}) => {
|
|
|
4262
4372
|
transportFactory
|
|
4263
4373
|
});
|
|
4264
4374
|
}
|
|
4265
|
-
|
|
4375
|
+
import_log19.log.warn("P2P network is not configured.", {}, {
|
|
4266
4376
|
file: "utils.ts",
|
|
4267
4377
|
line: 48,
|
|
4268
4378
|
scope: void 0,
|