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