@dxos/client-services 0.1.39 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-2DGNNQWS.mjs → chunk-LGMYP2WL.mjs} +679 -569
- package/dist/lib/browser/chunk-LGMYP2WL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +14 -14
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +721 -611
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +725 -621
- package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts +54 -0
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +8 -3
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
- package/package.json +30 -30
- package/src/packlets/invitations/invitation-extension.ts +211 -0
- package/src/packlets/invitations/invitations-handler.ts +54 -123
- package/src/packlets/invitations/invitations-service.ts +106 -137
- package/src/packlets/services/utils.ts +3 -3
- package/src/packlets/testing/test-builder.ts +9 -7
- package/src/packlets/vault/iframe-host-runtime.ts +3 -3
- package/src/packlets/vault/iframe-proxy-runtime.ts +11 -3
- package/src/packlets/vault/worker-runtime.ts +3 -3
- package/dist/lib/browser/chunk-2DGNNQWS.mjs.map +0 -7
|
@@ -928,18 +928,236 @@ var DeviceInvitationProtocol = class {
|
|
|
928
928
|
};
|
|
929
929
|
|
|
930
930
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
931
|
-
import
|
|
932
|
-
import { PushStream, scheduleTask, sleep, TimeoutError, Trigger as
|
|
933
|
-
import { AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT, ON_CLOSE_DELAY
|
|
934
|
-
import { Context as
|
|
931
|
+
import assert6 from "@dxos/node-std/assert";
|
|
932
|
+
import { PushStream, scheduleTask, sleep, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
|
|
933
|
+
import { AuthenticatingInvitationObservable, AUTHENTICATION_CODE_LENGTH, CancellableInvitationObservable, INVITATION_TIMEOUT, ON_CLOSE_DELAY } from "@dxos/client";
|
|
934
|
+
import { Context as Context4 } from "@dxos/context";
|
|
935
935
|
import { generatePasscode } from "@dxos/credentials";
|
|
936
|
-
import {
|
|
937
|
-
import {
|
|
936
|
+
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2 } from "@dxos/errors";
|
|
937
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
938
|
+
import { log as log5 } from "@dxos/log";
|
|
938
939
|
import { createTeleportProtocolFactory, StarTopology } from "@dxos/network-manager";
|
|
939
|
-
import {
|
|
940
|
+
import { trace as trace3 } from "@dxos/protocols";
|
|
940
941
|
import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
941
942
|
import { AuthenticationResponse } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
943
|
+
|
|
944
|
+
// packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
|
|
945
|
+
import assert5 from "@dxos/node-std/assert";
|
|
946
|
+
import { Trigger as Trigger2 } from "@dxos/async";
|
|
947
|
+
import { cancelWithContext, Context as Context3 } from "@dxos/context";
|
|
948
|
+
import { InvalidInvitationExtensionRoleError } from "@dxos/errors";
|
|
949
|
+
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
950
|
+
import { log as log4 } from "@dxos/log";
|
|
951
|
+
import { schema as schema2, trace as trace2 } from "@dxos/protocols";
|
|
952
|
+
import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
942
953
|
import { RpcExtension } from "@dxos/teleport";
|
|
954
|
+
var OPTIONS_TIMEOUT = 1e4;
|
|
955
|
+
var InvitationHostExtension = class extends RpcExtension {
|
|
956
|
+
constructor(_callbacks) {
|
|
957
|
+
super({
|
|
958
|
+
requested: {
|
|
959
|
+
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
960
|
+
},
|
|
961
|
+
exposed: {
|
|
962
|
+
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
this._callbacks = _callbacks;
|
|
966
|
+
this._ctx = new Context3();
|
|
967
|
+
this._remoteOptionsTrigger = new Trigger2();
|
|
968
|
+
}
|
|
969
|
+
async getHandlers() {
|
|
970
|
+
return {
|
|
971
|
+
// TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
|
|
972
|
+
// Perhaps in the future we will have more complex logic here.
|
|
973
|
+
InvitationHostService: {
|
|
974
|
+
options: async (options) => {
|
|
975
|
+
assert5(!this._remoteOptions, "Remote options already set.");
|
|
976
|
+
this._remoteOptions = options;
|
|
977
|
+
this._remoteOptionsTrigger.wake();
|
|
978
|
+
},
|
|
979
|
+
introduce: async (request) => {
|
|
980
|
+
const traceId = PublicKey4.random().toHex();
|
|
981
|
+
log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
|
|
982
|
+
id: traceId,
|
|
983
|
+
parentId: this._traceParent
|
|
984
|
+
}), {
|
|
985
|
+
file: "invitation-extension.ts",
|
|
986
|
+
line: 78,
|
|
987
|
+
scope: this,
|
|
988
|
+
callSite: (f, a) => f(...a)
|
|
989
|
+
});
|
|
990
|
+
const response = await this._callbacks.introduce(request);
|
|
991
|
+
log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
|
|
992
|
+
id: traceId
|
|
993
|
+
}), {
|
|
994
|
+
file: "invitation-extension.ts",
|
|
995
|
+
line: 83,
|
|
996
|
+
scope: this,
|
|
997
|
+
callSite: (f, a) => f(...a)
|
|
998
|
+
});
|
|
999
|
+
return response;
|
|
1000
|
+
},
|
|
1001
|
+
authenticate: async (request) => {
|
|
1002
|
+
const traceId = PublicKey4.random().toHex();
|
|
1003
|
+
log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
|
|
1004
|
+
id: traceId,
|
|
1005
|
+
parentId: this._traceParent
|
|
1006
|
+
}), {
|
|
1007
|
+
file: "invitation-extension.ts",
|
|
1008
|
+
line: 89,
|
|
1009
|
+
scope: this,
|
|
1010
|
+
callSite: (f, a) => f(...a)
|
|
1011
|
+
});
|
|
1012
|
+
const response = await this._callbacks.authenticate(request);
|
|
1013
|
+
log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.end({
|
|
1014
|
+
id: traceId,
|
|
1015
|
+
data: {
|
|
1016
|
+
...response
|
|
1017
|
+
}
|
|
1018
|
+
}), {
|
|
1019
|
+
file: "invitation-extension.ts",
|
|
1020
|
+
line: 94,
|
|
1021
|
+
scope: this,
|
|
1022
|
+
callSite: (f, a) => f(...a)
|
|
1023
|
+
});
|
|
1024
|
+
return response;
|
|
1025
|
+
},
|
|
1026
|
+
admit: async (request) => {
|
|
1027
|
+
const traceId = PublicKey4.random().toHex();
|
|
1028
|
+
log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
|
|
1029
|
+
id: traceId,
|
|
1030
|
+
parentId: this._traceParent
|
|
1031
|
+
}), {
|
|
1032
|
+
file: "invitation-extension.ts",
|
|
1033
|
+
line: 100,
|
|
1034
|
+
scope: this,
|
|
1035
|
+
callSite: (f, a) => f(...a)
|
|
1036
|
+
});
|
|
1037
|
+
const response = await this._callbacks.admit(request);
|
|
1038
|
+
log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
|
|
1039
|
+
id: traceId
|
|
1040
|
+
}), {
|
|
1041
|
+
file: "invitation-extension.ts",
|
|
1042
|
+
line: 105,
|
|
1043
|
+
scope: this,
|
|
1044
|
+
callSite: (f, a) => f(...a)
|
|
1045
|
+
});
|
|
1046
|
+
return response;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
async onOpen(context) {
|
|
1052
|
+
var _a;
|
|
1053
|
+
await super.onOpen(context);
|
|
1054
|
+
try {
|
|
1055
|
+
await this.rpc.InvitationHostService.options({
|
|
1056
|
+
role: Options.Role.HOST
|
|
1057
|
+
});
|
|
1058
|
+
await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1059
|
+
timeout: OPTIONS_TIMEOUT
|
|
1060
|
+
}));
|
|
1061
|
+
if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.GUEST) {
|
|
1062
|
+
throw new InvalidInvitationExtensionRoleError(void 0, {
|
|
1063
|
+
expected: Options.Role.GUEST,
|
|
1064
|
+
remoteOptions: this._remoteOptions
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
this._callbacks.onOpen();
|
|
1068
|
+
} catch (err) {
|
|
1069
|
+
this._callbacks.onError(err);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
async onClose() {
|
|
1073
|
+
await this._ctx.dispose();
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
var InvitationGuestExtension = class extends RpcExtension {
|
|
1077
|
+
constructor(_callbacks) {
|
|
1078
|
+
super({
|
|
1079
|
+
requested: {
|
|
1080
|
+
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
1081
|
+
},
|
|
1082
|
+
exposed: {
|
|
1083
|
+
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
this._callbacks = _callbacks;
|
|
1087
|
+
this._ctx = new Context3();
|
|
1088
|
+
this._remoteOptionsTrigger = new Trigger2();
|
|
1089
|
+
}
|
|
1090
|
+
async getHandlers() {
|
|
1091
|
+
return {
|
|
1092
|
+
InvitationHostService: {
|
|
1093
|
+
options: async (options) => {
|
|
1094
|
+
assert5(!this._remoteOptions, "Remote options already set.");
|
|
1095
|
+
this._remoteOptions = options;
|
|
1096
|
+
this._remoteOptionsTrigger.wake();
|
|
1097
|
+
},
|
|
1098
|
+
introduce: () => {
|
|
1099
|
+
throw new Error("Method not allowed.");
|
|
1100
|
+
},
|
|
1101
|
+
authenticate: () => {
|
|
1102
|
+
throw new Error("Method not allowed.");
|
|
1103
|
+
},
|
|
1104
|
+
admit: () => {
|
|
1105
|
+
throw new Error("Method not allowed.");
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
async onOpen(context) {
|
|
1111
|
+
var _a;
|
|
1112
|
+
await super.onOpen(context);
|
|
1113
|
+
try {
|
|
1114
|
+
log4("begin options", {}, {
|
|
1115
|
+
file: "invitation-extension.ts",
|
|
1116
|
+
line: 189,
|
|
1117
|
+
scope: this,
|
|
1118
|
+
callSite: (f, a) => f(...a)
|
|
1119
|
+
});
|
|
1120
|
+
await cancelWithContext(this._ctx, this.rpc.InvitationHostService.options({
|
|
1121
|
+
role: Options.Role.GUEST
|
|
1122
|
+
}));
|
|
1123
|
+
await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1124
|
+
timeout: OPTIONS_TIMEOUT
|
|
1125
|
+
}));
|
|
1126
|
+
log4("end options", {}, {
|
|
1127
|
+
file: "invitation-extension.ts",
|
|
1128
|
+
line: 192,
|
|
1129
|
+
scope: this,
|
|
1130
|
+
callSite: (f, a) => f(...a)
|
|
1131
|
+
});
|
|
1132
|
+
if (((_a = this._remoteOptions) == null ? void 0 : _a.role) !== Options.Role.HOST) {
|
|
1133
|
+
throw new InvalidInvitationExtensionRoleError(void 0, {
|
|
1134
|
+
expected: Options.Role.HOST,
|
|
1135
|
+
remoteOptions: this._remoteOptions
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
this._callbacks.onOpen(this._ctx);
|
|
1139
|
+
} catch (err) {
|
|
1140
|
+
log4("openError", err, {
|
|
1141
|
+
file: "invitation-extension.ts",
|
|
1142
|
+
line: 202,
|
|
1143
|
+
scope: this,
|
|
1144
|
+
callSite: (f, a) => f(...a)
|
|
1145
|
+
});
|
|
1146
|
+
this._callbacks.onError(err);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
async onClose() {
|
|
1150
|
+
log4("onClose", {}, {
|
|
1151
|
+
file: "invitation-extension.ts",
|
|
1152
|
+
line: 208,
|
|
1153
|
+
scope: this,
|
|
1154
|
+
callSite: (f, a) => f(...a)
|
|
1155
|
+
});
|
|
1156
|
+
await this._ctx.dispose();
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
943
1161
|
var MAX_OTP_ATTEMPTS = 3;
|
|
944
1162
|
var InvitationsHandler = class {
|
|
945
1163
|
constructor(_networkManager) {
|
|
@@ -947,9 +1165,9 @@ var InvitationsHandler = class {
|
|
|
947
1165
|
}
|
|
948
1166
|
createInvitation(protocol, options) {
|
|
949
1167
|
var _a;
|
|
950
|
-
const { invitationId =
|
|
1168
|
+
const { invitationId = PublicKey5.random().toHex(), type = Invitation2.Type.INTERACTIVE, authMethod = Invitation2.AuthMethod.SHARED_SECRET, state = Invitation2.State.INIT, timeout = INVITATION_TIMEOUT, swarmKey = PublicKey5.random() } = options != null ? options : {};
|
|
951
1169
|
const authCode = (_a = options == null ? void 0 : options.authCode) != null ? _a : authMethod === Invitation2.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0;
|
|
952
|
-
|
|
1170
|
+
assert6(protocol);
|
|
953
1171
|
const invitation = {
|
|
954
1172
|
invitationId,
|
|
955
1173
|
type,
|
|
@@ -961,36 +1179,36 @@ var InvitationsHandler = class {
|
|
|
961
1179
|
...protocol.getInvitationContext()
|
|
962
1180
|
};
|
|
963
1181
|
const stream = new PushStream();
|
|
964
|
-
const ctx = new
|
|
1182
|
+
const ctx = new Context4({
|
|
965
1183
|
onError: (err) => {
|
|
966
1184
|
void ctx.dispose();
|
|
967
1185
|
stream.error(err);
|
|
968
1186
|
}
|
|
969
1187
|
});
|
|
970
1188
|
ctx.onDispose(() => {
|
|
971
|
-
|
|
1189
|
+
log5("complete", {
|
|
972
1190
|
...protocol.toJSON()
|
|
973
1191
|
}, {
|
|
974
1192
|
file: "invitations-handler.ts",
|
|
975
|
-
line:
|
|
1193
|
+
line: 99,
|
|
976
1194
|
scope: this,
|
|
977
1195
|
callSite: (f, a) => f(...a)
|
|
978
1196
|
});
|
|
979
1197
|
stream.complete();
|
|
980
1198
|
});
|
|
981
1199
|
const createExtension = () => {
|
|
982
|
-
const success = new
|
|
1200
|
+
const success = new Trigger3();
|
|
983
1201
|
let guestProfile;
|
|
984
1202
|
let authenticationPassed = false;
|
|
985
1203
|
let authenticationRetry = 0;
|
|
986
1204
|
const extension = new InvitationHostExtension({
|
|
987
1205
|
introduce: async ({ profile }) => {
|
|
988
|
-
|
|
1206
|
+
log5("guest introduced itself", {
|
|
989
1207
|
guestProfile: profile,
|
|
990
1208
|
...protocol.toJSON()
|
|
991
1209
|
}, {
|
|
992
1210
|
file: "invitations-handler.ts",
|
|
993
|
-
line:
|
|
1211
|
+
line: 112,
|
|
994
1212
|
scope: this,
|
|
995
1213
|
callSite: (f, a) => f(...a)
|
|
996
1214
|
});
|
|
@@ -1005,20 +1223,20 @@ var InvitationsHandler = class {
|
|
|
1005
1223
|
};
|
|
1006
1224
|
},
|
|
1007
1225
|
authenticate: async ({ authCode: code }) => {
|
|
1008
|
-
|
|
1226
|
+
log5("received authentication request", {
|
|
1009
1227
|
authCode: code
|
|
1010
1228
|
}, {
|
|
1011
1229
|
file: "invitations-handler.ts",
|
|
1012
|
-
line:
|
|
1230
|
+
line: 131,
|
|
1013
1231
|
scope: this,
|
|
1014
1232
|
callSite: (f, a) => f(...a)
|
|
1015
1233
|
});
|
|
1016
1234
|
let status = AuthenticationResponse.Status.OK;
|
|
1017
1235
|
switch (invitation.authMethod) {
|
|
1018
1236
|
case Invitation2.AuthMethod.NONE: {
|
|
1019
|
-
|
|
1237
|
+
log5("authentication not required", {}, {
|
|
1020
1238
|
file: "invitations-handler.ts",
|
|
1021
|
-
line:
|
|
1239
|
+
line: 136,
|
|
1022
1240
|
scope: this,
|
|
1023
1241
|
callSite: (f, a) => f(...a)
|
|
1024
1242
|
});
|
|
@@ -1039,11 +1257,11 @@ var InvitationsHandler = class {
|
|
|
1039
1257
|
break;
|
|
1040
1258
|
}
|
|
1041
1259
|
default: {
|
|
1042
|
-
|
|
1260
|
+
log5.error("invalid authentication method", {
|
|
1043
1261
|
authMethod: invitation.authMethod
|
|
1044
1262
|
}, {
|
|
1045
1263
|
file: "invitations-handler.ts",
|
|
1046
|
-
line:
|
|
1264
|
+
line: 154,
|
|
1047
1265
|
scope: this,
|
|
1048
1266
|
callSite: (f, a) => f(...a)
|
|
1049
1267
|
});
|
|
@@ -1062,7 +1280,7 @@ var InvitationsHandler = class {
|
|
|
1062
1280
|
throw new Error("Not authenticated");
|
|
1063
1281
|
}
|
|
1064
1282
|
const deviceKey = (_c = (_a2 = admissionRequest.device) == null ? void 0 : _a2.deviceKey) != null ? _c : (_b = admissionRequest.space) == null ? void 0 : _b.deviceKey;
|
|
1065
|
-
|
|
1283
|
+
assert6(deviceKey);
|
|
1066
1284
|
const admissionResponse = await protocol.admit(admissionRequest, guestProfile);
|
|
1067
1285
|
success.wake(deviceKey);
|
|
1068
1286
|
return admissionResponse;
|
|
@@ -1073,22 +1291,22 @@ var InvitationsHandler = class {
|
|
|
1073
1291
|
},
|
|
1074
1292
|
onOpen: () => {
|
|
1075
1293
|
scheduleTask(ctx, async () => {
|
|
1076
|
-
const traceId =
|
|
1294
|
+
const traceId = PublicKey5.random().toHex();
|
|
1077
1295
|
try {
|
|
1078
|
-
|
|
1296
|
+
log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.begin({
|
|
1079
1297
|
id: traceId,
|
|
1080
1298
|
parentId: this._traceParent
|
|
1081
1299
|
}), {
|
|
1082
1300
|
file: "invitations-handler.ts",
|
|
1083
|
-
line:
|
|
1301
|
+
line: 189,
|
|
1084
1302
|
scope: this,
|
|
1085
1303
|
callSite: (f, a) => f(...a)
|
|
1086
1304
|
});
|
|
1087
|
-
|
|
1305
|
+
log5("connected", {
|
|
1088
1306
|
...protocol.toJSON()
|
|
1089
1307
|
}, {
|
|
1090
1308
|
file: "invitations-handler.ts",
|
|
1091
|
-
line:
|
|
1309
|
+
line: 193,
|
|
1092
1310
|
scope: this,
|
|
1093
1311
|
callSite: (f, a) => f(...a)
|
|
1094
1312
|
});
|
|
@@ -1099,12 +1317,12 @@ var InvitationsHandler = class {
|
|
|
1099
1317
|
const deviceKey = await success.wait({
|
|
1100
1318
|
timeout
|
|
1101
1319
|
});
|
|
1102
|
-
|
|
1320
|
+
log5("admitted guest", {
|
|
1103
1321
|
guest: deviceKey,
|
|
1104
1322
|
...protocol.toJSON()
|
|
1105
1323
|
}, {
|
|
1106
1324
|
file: "invitations-handler.ts",
|
|
1107
|
-
line:
|
|
1325
|
+
line: 196,
|
|
1108
1326
|
scope: this,
|
|
1109
1327
|
callSite: (f, a) => f(...a)
|
|
1110
1328
|
});
|
|
@@ -1112,21 +1330,21 @@ var InvitationsHandler = class {
|
|
|
1112
1330
|
...invitation,
|
|
1113
1331
|
state: Invitation2.State.SUCCESS
|
|
1114
1332
|
});
|
|
1115
|
-
|
|
1333
|
+
log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.end({
|
|
1116
1334
|
id: traceId
|
|
1117
1335
|
}), {
|
|
1118
1336
|
file: "invitations-handler.ts",
|
|
1119
|
-
line:
|
|
1337
|
+
line: 198,
|
|
1120
1338
|
scope: this,
|
|
1121
1339
|
callSite: (f, a) => f(...a)
|
|
1122
1340
|
});
|
|
1123
1341
|
} catch (err) {
|
|
1124
1342
|
if (err instanceof TimeoutError) {
|
|
1125
|
-
|
|
1343
|
+
log5("timeout", {
|
|
1126
1344
|
...protocol.toJSON()
|
|
1127
1345
|
}, {
|
|
1128
1346
|
file: "invitations-handler.ts",
|
|
1129
|
-
line:
|
|
1347
|
+
line: 201,
|
|
1130
1348
|
scope: this,
|
|
1131
1349
|
callSite: (f, a) => f(...a)
|
|
1132
1350
|
});
|
|
@@ -1135,20 +1353,20 @@ var InvitationsHandler = class {
|
|
|
1135
1353
|
state: Invitation2.State.TIMEOUT
|
|
1136
1354
|
});
|
|
1137
1355
|
} else {
|
|
1138
|
-
|
|
1356
|
+
log5.error("failed", err, {
|
|
1139
1357
|
file: "invitations-handler.ts",
|
|
1140
|
-
line:
|
|
1358
|
+
line: 204,
|
|
1141
1359
|
scope: this,
|
|
1142
1360
|
callSite: (f, a) => f(...a)
|
|
1143
1361
|
});
|
|
1144
1362
|
stream.error(err);
|
|
1145
1363
|
}
|
|
1146
|
-
|
|
1364
|
+
log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace3.error({
|
|
1147
1365
|
id: traceId,
|
|
1148
1366
|
error: err
|
|
1149
1367
|
}), {
|
|
1150
1368
|
file: "invitations-handler.ts",
|
|
1151
|
-
line:
|
|
1369
|
+
line: 207,
|
|
1152
1370
|
scope: this,
|
|
1153
1371
|
callSite: (f, a) => f(...a)
|
|
1154
1372
|
});
|
|
@@ -1159,6 +1377,33 @@ var InvitationsHandler = class {
|
|
|
1159
1377
|
}
|
|
1160
1378
|
}
|
|
1161
1379
|
});
|
|
1380
|
+
},
|
|
1381
|
+
onError: (err) => {
|
|
1382
|
+
if (err instanceof InvalidInvitationExtensionRoleError2) {
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
if (err instanceof TimeoutError) {
|
|
1386
|
+
log5("timeout", {
|
|
1387
|
+
...protocol.toJSON()
|
|
1388
|
+
}, {
|
|
1389
|
+
file: "invitations-handler.ts",
|
|
1390
|
+
line: 221,
|
|
1391
|
+
scope: this,
|
|
1392
|
+
callSite: (f, a) => f(...a)
|
|
1393
|
+
});
|
|
1394
|
+
stream.next({
|
|
1395
|
+
...invitation,
|
|
1396
|
+
state: Invitation2.State.TIMEOUT
|
|
1397
|
+
});
|
|
1398
|
+
} else {
|
|
1399
|
+
log5.error("failed", err, {
|
|
1400
|
+
file: "invitations-handler.ts",
|
|
1401
|
+
line: 224,
|
|
1402
|
+
scope: this,
|
|
1403
|
+
callSite: (f, a) => f(...a)
|
|
1404
|
+
});
|
|
1405
|
+
stream.error(err);
|
|
1406
|
+
}
|
|
1162
1407
|
}
|
|
1163
1408
|
});
|
|
1164
1409
|
extension._traceParent = this._traceParent;
|
|
@@ -1195,28 +1440,36 @@ var InvitationsHandler = class {
|
|
|
1195
1440
|
}
|
|
1196
1441
|
acceptInvitation(protocol, invitation) {
|
|
1197
1442
|
const { timeout = INVITATION_TIMEOUT } = invitation;
|
|
1198
|
-
|
|
1199
|
-
const authenticated = new
|
|
1443
|
+
assert6(protocol);
|
|
1444
|
+
const authenticated = new Trigger3();
|
|
1445
|
+
let currentState;
|
|
1200
1446
|
const stream = new PushStream();
|
|
1201
|
-
const
|
|
1447
|
+
const setState = (newData) => {
|
|
1448
|
+
assert6(newData.state !== void 0);
|
|
1449
|
+
currentState = newData.state;
|
|
1450
|
+
stream.next({
|
|
1451
|
+
...invitation,
|
|
1452
|
+
...newData
|
|
1453
|
+
});
|
|
1454
|
+
};
|
|
1455
|
+
const ctx = new Context4({
|
|
1202
1456
|
onError: (err) => {
|
|
1203
1457
|
if (err instanceof TimeoutError) {
|
|
1204
|
-
|
|
1458
|
+
log5("timeout", {
|
|
1205
1459
|
...protocol.toJSON()
|
|
1206
1460
|
}, {
|
|
1207
1461
|
file: "invitations-handler.ts",
|
|
1208
|
-
line:
|
|
1462
|
+
line: 279,
|
|
1209
1463
|
scope: this,
|
|
1210
1464
|
callSite: (f, a) => f(...a)
|
|
1211
1465
|
});
|
|
1212
|
-
|
|
1213
|
-
...invitation,
|
|
1466
|
+
setState({
|
|
1214
1467
|
state: Invitation2.State.TIMEOUT
|
|
1215
1468
|
});
|
|
1216
1469
|
} else {
|
|
1217
|
-
|
|
1470
|
+
log5.warn("auth failed", err, {
|
|
1218
1471
|
file: "invitations-handler.ts",
|
|
1219
|
-
line:
|
|
1472
|
+
line: 282,
|
|
1220
1473
|
scope: this,
|
|
1221
1474
|
callSite: (f, a) => f(...a)
|
|
1222
1475
|
});
|
|
@@ -1226,11 +1479,11 @@ var InvitationsHandler = class {
|
|
|
1226
1479
|
}
|
|
1227
1480
|
});
|
|
1228
1481
|
ctx.onDispose(() => {
|
|
1229
|
-
|
|
1482
|
+
log5("complete", {
|
|
1230
1483
|
...protocol.toJSON()
|
|
1231
1484
|
}, {
|
|
1232
1485
|
file: "invitations-handler.ts",
|
|
1233
|
-
line:
|
|
1486
|
+
line: 290,
|
|
1234
1487
|
scope: this,
|
|
1235
1488
|
callSite: (f, a) => f(...a)
|
|
1236
1489
|
});
|
|
@@ -1239,16 +1492,29 @@ var InvitationsHandler = class {
|
|
|
1239
1492
|
const createExtension = () => {
|
|
1240
1493
|
let connectionCount = 0;
|
|
1241
1494
|
const extension = new InvitationGuestExtension({
|
|
1242
|
-
onOpen: () => {
|
|
1495
|
+
onOpen: (extensionCtx) => {
|
|
1496
|
+
extensionCtx.onDispose(async () => {
|
|
1497
|
+
log5("extension disposed", {
|
|
1498
|
+
currentState
|
|
1499
|
+
}, {
|
|
1500
|
+
file: "invitations-handler.ts",
|
|
1501
|
+
line: 300,
|
|
1502
|
+
scope: this,
|
|
1503
|
+
callSite: (f, a) => f(...a)
|
|
1504
|
+
});
|
|
1505
|
+
if (currentState !== Invitation2.State.SUCCESS) {
|
|
1506
|
+
stream.error(new Error("Remote peer disconnected."));
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1243
1509
|
scheduleTask(ctx, async () => {
|
|
1244
|
-
const traceId =
|
|
1510
|
+
const traceId = PublicKey5.random().toHex();
|
|
1245
1511
|
try {
|
|
1246
|
-
|
|
1512
|
+
log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.begin({
|
|
1247
1513
|
id: traceId,
|
|
1248
1514
|
parentId: this._traceParent
|
|
1249
1515
|
}), {
|
|
1250
1516
|
file: "invitations-handler.ts",
|
|
1251
|
-
line:
|
|
1517
|
+
line: 309,
|
|
1252
1518
|
scope: this,
|
|
1253
1519
|
callSite: (f, a) => f(...a)
|
|
1254
1520
|
});
|
|
@@ -1256,33 +1522,32 @@ var InvitationsHandler = class {
|
|
|
1256
1522
|
throw new Error(`multiple connections detected: ${connectionCount}`);
|
|
1257
1523
|
}
|
|
1258
1524
|
scheduleTask(ctx, () => ctx.raise(new TimeoutError(timeout)), timeout);
|
|
1259
|
-
|
|
1525
|
+
log5("connected", {
|
|
1260
1526
|
...protocol.toJSON()
|
|
1261
1527
|
}, {
|
|
1262
1528
|
file: "invitations-handler.ts",
|
|
1263
|
-
line:
|
|
1529
|
+
line: 320,
|
|
1264
1530
|
scope: this,
|
|
1265
1531
|
callSite: (f, a) => f(...a)
|
|
1266
1532
|
});
|
|
1267
|
-
|
|
1268
|
-
...invitation,
|
|
1533
|
+
setState({
|
|
1269
1534
|
state: Invitation2.State.CONNECTED
|
|
1270
1535
|
});
|
|
1271
|
-
|
|
1536
|
+
log5("introduce", {
|
|
1272
1537
|
...protocol.toJSON()
|
|
1273
1538
|
}, {
|
|
1274
1539
|
file: "invitations-handler.ts",
|
|
1275
|
-
line:
|
|
1540
|
+
line: 324,
|
|
1276
1541
|
scope: this,
|
|
1277
1542
|
callSite: (f, a) => f(...a)
|
|
1278
1543
|
});
|
|
1279
1544
|
const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
|
|
1280
|
-
|
|
1545
|
+
log5("introduce response", {
|
|
1281
1546
|
...protocol.toJSON(),
|
|
1282
1547
|
response: introductionResponse
|
|
1283
1548
|
}, {
|
|
1284
1549
|
file: "invitations-handler.ts",
|
|
1285
|
-
line:
|
|
1550
|
+
line: 328,
|
|
1286
1551
|
scope: this,
|
|
1287
1552
|
callSite: (f, a) => f(...a)
|
|
1288
1553
|
});
|
|
@@ -1292,27 +1557,25 @@ var InvitationsHandler = class {
|
|
|
1292
1557
|
}
|
|
1293
1558
|
if (isAuthenticationRequired(invitation)) {
|
|
1294
1559
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
1295
|
-
|
|
1560
|
+
log5("guest waiting for authentication code...", {}, {
|
|
1296
1561
|
file: "invitations-handler.ts",
|
|
1297
|
-
line:
|
|
1562
|
+
line: 337,
|
|
1298
1563
|
scope: this,
|
|
1299
1564
|
callSite: (f, a) => f(...a)
|
|
1300
1565
|
});
|
|
1301
|
-
|
|
1302
|
-
...invitation,
|
|
1566
|
+
setState({
|
|
1303
1567
|
state: Invitation2.State.READY_FOR_AUTHENTICATION
|
|
1304
1568
|
});
|
|
1305
1569
|
const authCode = await authenticated.wait({
|
|
1306
1570
|
timeout
|
|
1307
1571
|
});
|
|
1308
|
-
|
|
1572
|
+
log5("sending authentication request", {}, {
|
|
1309
1573
|
file: "invitations-handler.ts",
|
|
1310
|
-
line:
|
|
1574
|
+
line: 341,
|
|
1311
1575
|
scope: this,
|
|
1312
1576
|
callSite: (f, a) => f(...a)
|
|
1313
1577
|
});
|
|
1314
|
-
|
|
1315
|
-
...invitation,
|
|
1578
|
+
setState({
|
|
1316
1579
|
state: Invitation2.State.AUTHENTICATING
|
|
1317
1580
|
});
|
|
1318
1581
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
@@ -1325,11 +1588,11 @@ var InvitationsHandler = class {
|
|
|
1325
1588
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
1326
1589
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
1327
1590
|
} else {
|
|
1328
|
-
|
|
1591
|
+
log5("retrying invalid code", {
|
|
1329
1592
|
attempt
|
|
1330
1593
|
}, {
|
|
1331
1594
|
file: "invitations-handler.ts",
|
|
1332
|
-
line:
|
|
1595
|
+
line: 352,
|
|
1333
1596
|
scope: this,
|
|
1334
1597
|
callSite: (f, a) => f(...a)
|
|
1335
1598
|
});
|
|
@@ -1338,72 +1601,69 @@ var InvitationsHandler = class {
|
|
|
1338
1601
|
}
|
|
1339
1602
|
}
|
|
1340
1603
|
} else {
|
|
1341
|
-
|
|
1342
|
-
...invitation,
|
|
1604
|
+
setState({
|
|
1343
1605
|
state: Invitation2.State.READY_FOR_AUTHENTICATION
|
|
1344
1606
|
});
|
|
1345
1607
|
}
|
|
1346
|
-
|
|
1608
|
+
log5("request admission", {
|
|
1347
1609
|
...protocol.toJSON()
|
|
1348
1610
|
}, {
|
|
1349
1611
|
file: "invitations-handler.ts",
|
|
1350
|
-
line:
|
|
1612
|
+
line: 363,
|
|
1351
1613
|
scope: this,
|
|
1352
1614
|
callSite: (f, a) => f(...a)
|
|
1353
1615
|
});
|
|
1354
1616
|
const admissionRequest = await protocol.createAdmissionRequest();
|
|
1355
1617
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
1356
1618
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
1357
|
-
|
|
1619
|
+
log5("admitted by host", {
|
|
1358
1620
|
...protocol.toJSON()
|
|
1359
1621
|
}, {
|
|
1360
1622
|
file: "invitations-handler.ts",
|
|
1361
|
-
line:
|
|
1623
|
+
line: 371,
|
|
1362
1624
|
scope: this,
|
|
1363
1625
|
callSite: (f, a) => f(...a)
|
|
1364
1626
|
});
|
|
1365
|
-
|
|
1366
|
-
...invitation,
|
|
1627
|
+
setState({
|
|
1367
1628
|
...result,
|
|
1368
1629
|
state: Invitation2.State.SUCCESS
|
|
1369
1630
|
});
|
|
1370
|
-
|
|
1631
|
+
log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.end({
|
|
1371
1632
|
id: traceId
|
|
1372
1633
|
}), {
|
|
1373
1634
|
file: "invitations-handler.ts",
|
|
1374
|
-
line:
|
|
1635
|
+
line: 373,
|
|
1375
1636
|
scope: this,
|
|
1376
1637
|
callSite: (f, a) => f(...a)
|
|
1377
1638
|
});
|
|
1378
1639
|
} catch (err) {
|
|
1379
1640
|
if (err instanceof TimeoutError) {
|
|
1380
|
-
|
|
1641
|
+
log5("timeout", {
|
|
1381
1642
|
...protocol.toJSON()
|
|
1382
1643
|
}, {
|
|
1383
1644
|
file: "invitations-handler.ts",
|
|
1384
|
-
line:
|
|
1645
|
+
line: 376,
|
|
1385
1646
|
scope: this,
|
|
1386
1647
|
callSite: (f, a) => f(...a)
|
|
1387
1648
|
});
|
|
1388
|
-
|
|
1389
|
-
...invitation,
|
|
1649
|
+
setState({
|
|
1390
1650
|
state: Invitation2.State.TIMEOUT
|
|
1391
1651
|
});
|
|
1392
1652
|
} else {
|
|
1393
|
-
|
|
1653
|
+
log5("auth failed", err, {
|
|
1394
1654
|
file: "invitations-handler.ts",
|
|
1395
|
-
line:
|
|
1655
|
+
line: 379,
|
|
1396
1656
|
scope: this,
|
|
1397
1657
|
callSite: (f, a) => f(...a)
|
|
1398
1658
|
});
|
|
1399
1659
|
stream.error(err);
|
|
1400
1660
|
}
|
|
1401
|
-
|
|
1661
|
+
log5.trace("dxos.sdk.invitations-handler.guest.onOpen", trace3.error({
|
|
1402
1662
|
id: traceId,
|
|
1403
1663
|
error: err
|
|
1404
1664
|
}), {
|
|
1405
1665
|
file: "invitations-handler.ts",
|
|
1406
|
-
line:
|
|
1666
|
+
line: 382,
|
|
1407
1667
|
scope: this,
|
|
1408
1668
|
callSite: (f, a) => f(...a)
|
|
1409
1669
|
});
|
|
@@ -1411,24 +1671,49 @@ var InvitationsHandler = class {
|
|
|
1411
1671
|
await ctx.dispose();
|
|
1412
1672
|
}
|
|
1413
1673
|
});
|
|
1674
|
+
},
|
|
1675
|
+
onError: (err) => {
|
|
1676
|
+
if (err instanceof InvalidInvitationExtensionRoleError2) {
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1679
|
+
if (err instanceof TimeoutError) {
|
|
1680
|
+
log5("timeout", {
|
|
1681
|
+
...protocol.toJSON()
|
|
1682
|
+
}, {
|
|
1683
|
+
file: "invitations-handler.ts",
|
|
1684
|
+
line: 393,
|
|
1685
|
+
scope: this,
|
|
1686
|
+
callSite: (f, a) => f(...a)
|
|
1687
|
+
});
|
|
1688
|
+
setState({
|
|
1689
|
+
state: Invitation2.State.TIMEOUT
|
|
1690
|
+
});
|
|
1691
|
+
} else {
|
|
1692
|
+
log5("auth failed", err, {
|
|
1693
|
+
file: "invitations-handler.ts",
|
|
1694
|
+
line: 396,
|
|
1695
|
+
scope: this,
|
|
1696
|
+
callSite: (f, a) => f(...a)
|
|
1697
|
+
});
|
|
1698
|
+
stream.error(err);
|
|
1699
|
+
}
|
|
1414
1700
|
}
|
|
1415
1701
|
});
|
|
1416
1702
|
return extension;
|
|
1417
1703
|
};
|
|
1418
1704
|
scheduleTask(ctx, async () => {
|
|
1419
|
-
|
|
1705
|
+
assert6(invitation.swarmKey);
|
|
1420
1706
|
const topic = invitation.swarmKey;
|
|
1421
1707
|
const swarmConnection = await this._networkManager.joinSwarm({
|
|
1422
1708
|
topic,
|
|
1423
|
-
peerId:
|
|
1709
|
+
peerId: PublicKey5.random(),
|
|
1424
1710
|
protocolProvider: createTeleportProtocolFactory(async (teleport) => {
|
|
1425
1711
|
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
1426
1712
|
}),
|
|
1427
1713
|
topology: new StarTopology(topic)
|
|
1428
1714
|
});
|
|
1429
1715
|
ctx.onDispose(() => swarmConnection.close());
|
|
1430
|
-
|
|
1431
|
-
...invitation,
|
|
1716
|
+
setState({
|
|
1432
1717
|
state: Invitation2.State.CONNECTING
|
|
1433
1718
|
});
|
|
1434
1719
|
});
|
|
@@ -1436,8 +1721,7 @@ var InvitationsHandler = class {
|
|
|
1436
1721
|
initialInvitation: invitation,
|
|
1437
1722
|
subscriber: stream.observable,
|
|
1438
1723
|
onCancel: async () => {
|
|
1439
|
-
|
|
1440
|
-
...invitation,
|
|
1724
|
+
setState({
|
|
1441
1725
|
state: Invitation2.State.CANCELLED
|
|
1442
1726
|
});
|
|
1443
1727
|
await ctx.dispose();
|
|
@@ -1450,323 +1734,87 @@ var InvitationsHandler = class {
|
|
|
1450
1734
|
}
|
|
1451
1735
|
};
|
|
1452
1736
|
var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
|
|
1453
|
-
var InvitationHostExtension = class extends RpcExtension {
|
|
1454
|
-
constructor(_callbacks) {
|
|
1455
|
-
super({
|
|
1456
|
-
exposed: {
|
|
1457
|
-
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
1458
|
-
}
|
|
1459
|
-
});
|
|
1460
|
-
this._callbacks = _callbacks;
|
|
1461
|
-
}
|
|
1462
|
-
async getHandlers() {
|
|
1463
|
-
return {
|
|
1464
|
-
// TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
|
|
1465
|
-
// Perhaps in the future we will have more complex logic here.
|
|
1466
|
-
InvitationHostService: {
|
|
1467
|
-
introduce: async (request) => {
|
|
1468
|
-
const traceId = PublicKey4.random().toHex();
|
|
1469
|
-
log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.begin({
|
|
1470
|
-
id: traceId,
|
|
1471
|
-
parentId: this._traceParent
|
|
1472
|
-
}), {
|
|
1473
|
-
file: "invitations-handler.ts",
|
|
1474
|
-
line: 442,
|
|
1475
|
-
scope: this,
|
|
1476
|
-
callSite: (f, a) => f(...a)
|
|
1477
|
-
});
|
|
1478
|
-
const response = await this._callbacks.introduce(request);
|
|
1479
|
-
log4.trace("dxos.sdk.invitation-handler.host.introduce", trace2.end({
|
|
1480
|
-
id: traceId
|
|
1481
|
-
}), {
|
|
1482
|
-
file: "invitations-handler.ts",
|
|
1483
|
-
line: 447,
|
|
1484
|
-
scope: this,
|
|
1485
|
-
callSite: (f, a) => f(...a)
|
|
1486
|
-
});
|
|
1487
|
-
return response;
|
|
1488
|
-
},
|
|
1489
|
-
authenticate: async (request) => {
|
|
1490
|
-
const traceId = PublicKey4.random().toHex();
|
|
1491
|
-
log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.begin({
|
|
1492
|
-
id: traceId,
|
|
1493
|
-
parentId: this._traceParent
|
|
1494
|
-
}), {
|
|
1495
|
-
file: "invitations-handler.ts",
|
|
1496
|
-
line: 453,
|
|
1497
|
-
scope: this,
|
|
1498
|
-
callSite: (f, a) => f(...a)
|
|
1499
|
-
});
|
|
1500
|
-
const response = await this._callbacks.authenticate(request);
|
|
1501
|
-
log4.trace("dxos.sdk.invitation-handler.host.authenticate", trace2.end({
|
|
1502
|
-
id: traceId,
|
|
1503
|
-
data: {
|
|
1504
|
-
...response
|
|
1505
|
-
}
|
|
1506
|
-
}), {
|
|
1507
|
-
file: "invitations-handler.ts",
|
|
1508
|
-
line: 458,
|
|
1509
|
-
scope: this,
|
|
1510
|
-
callSite: (f, a) => f(...a)
|
|
1511
|
-
});
|
|
1512
|
-
return response;
|
|
1513
|
-
},
|
|
1514
|
-
admit: async (request) => {
|
|
1515
|
-
const traceId = PublicKey4.random().toHex();
|
|
1516
|
-
log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.begin({
|
|
1517
|
-
id: traceId,
|
|
1518
|
-
parentId: this._traceParent
|
|
1519
|
-
}), {
|
|
1520
|
-
file: "invitations-handler.ts",
|
|
1521
|
-
line: 464,
|
|
1522
|
-
scope: this,
|
|
1523
|
-
callSite: (f, a) => f(...a)
|
|
1524
|
-
});
|
|
1525
|
-
const response = await this._callbacks.admit(request);
|
|
1526
|
-
log4.trace("dxos.sdk.invitation-handler.host.admit", trace2.end({
|
|
1527
|
-
id: traceId
|
|
1528
|
-
}), {
|
|
1529
|
-
file: "invitations-handler.ts",
|
|
1530
|
-
line: 469,
|
|
1531
|
-
scope: this,
|
|
1532
|
-
callSite: (f, a) => f(...a)
|
|
1533
|
-
});
|
|
1534
|
-
return response;
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
};
|
|
1538
|
-
}
|
|
1539
|
-
async onOpen(context) {
|
|
1540
|
-
await super.onOpen(context);
|
|
1541
|
-
this._callbacks.onOpen();
|
|
1542
|
-
}
|
|
1543
|
-
};
|
|
1544
|
-
var InvitationGuestExtension = class extends RpcExtension {
|
|
1545
|
-
constructor(_callbacks) {
|
|
1546
|
-
super({
|
|
1547
|
-
requested: {
|
|
1548
|
-
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
1549
|
-
}
|
|
1550
|
-
});
|
|
1551
|
-
this._callbacks = _callbacks;
|
|
1552
|
-
}
|
|
1553
|
-
async getHandlers() {
|
|
1554
|
-
return {};
|
|
1555
|
-
}
|
|
1556
|
-
async onOpen(context) {
|
|
1557
|
-
await super.onOpen(context);
|
|
1558
|
-
this._callbacks.onOpen();
|
|
1559
|
-
}
|
|
1560
|
-
};
|
|
1561
1737
|
|
|
1562
1738
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
1563
|
-
import
|
|
1739
|
+
import assert7 from "@dxos/node-std/assert";
|
|
1740
|
+
import { Event as Event3 } from "@dxos/async";
|
|
1564
1741
|
import { Stream as Stream7 } from "@dxos/codec-protobuf";
|
|
1565
|
-
import { log as
|
|
1566
|
-
import {
|
|
1742
|
+
import { log as log6 } from "@dxos/log";
|
|
1743
|
+
import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
|
|
1567
1744
|
var InvitationsServiceImpl = class {
|
|
1568
1745
|
constructor(_invitationsHandler, _getHandler) {
|
|
1569
1746
|
this._invitationsHandler = _invitationsHandler;
|
|
1570
1747
|
this._getHandler = _getHandler;
|
|
1571
1748
|
this._createInvitations = /* @__PURE__ */ new Map();
|
|
1572
1749
|
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
1750
|
+
this._invitationCreated = new Event3();
|
|
1751
|
+
this._invitationAccepted = new Event3();
|
|
1752
|
+
this._removedCreated = new Event3();
|
|
1753
|
+
this._removedAccepted = new Event3();
|
|
1573
1754
|
}
|
|
1574
1755
|
// TODO(burdon): Guest/host label.
|
|
1575
1756
|
getLoggingContext() {
|
|
1576
1757
|
return {};
|
|
1577
1758
|
}
|
|
1578
|
-
createInvitation(
|
|
1759
|
+
createInvitation(options) {
|
|
1760
|
+
let invitation;
|
|
1761
|
+
const existingInvitation = this._createInvitations.get(options.invitationId);
|
|
1762
|
+
if (existingInvitation) {
|
|
1763
|
+
invitation = existingInvitation;
|
|
1764
|
+
} else {
|
|
1765
|
+
const handler = this._getHandler(options);
|
|
1766
|
+
invitation = this._invitationsHandler.createInvitation(handler, options);
|
|
1767
|
+
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
1768
|
+
this._invitationCreated.emit(invitation.get());
|
|
1769
|
+
}
|
|
1579
1770
|
return new Stream7(({ next, close }) => {
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
file: "invitations-service.ts",
|
|
1583
|
-
line: 37,
|
|
1584
|
-
scope: this,
|
|
1585
|
-
callSite: (f, a) => f(...a)
|
|
1586
|
-
});
|
|
1587
|
-
let invitationId;
|
|
1588
|
-
const observable = this._invitationsHandler.createInvitation(handler, invitation);
|
|
1589
|
-
observable.subscribe((invitation2) => {
|
|
1590
|
-
switch (invitation2.state) {
|
|
1591
|
-
case Invitation3.State.CONNECTING: {
|
|
1592
|
-
assert6(invitation2.invitationId);
|
|
1593
|
-
invitationId = invitation2.invitationId;
|
|
1594
|
-
this._createInvitations.set(invitation2.invitationId, observable);
|
|
1595
|
-
invitation2.state = Invitation3.State.CONNECTING;
|
|
1596
|
-
next(invitation2);
|
|
1597
|
-
break;
|
|
1598
|
-
}
|
|
1599
|
-
case Invitation3.State.CONNECTED: {
|
|
1600
|
-
assert6(invitation2.invitationId);
|
|
1601
|
-
invitation2.state = Invitation3.State.CONNECTED;
|
|
1602
|
-
next(invitation2);
|
|
1603
|
-
break;
|
|
1604
|
-
}
|
|
1605
|
-
case Invitation3.State.READY_FOR_AUTHENTICATION: {
|
|
1606
|
-
assert6(invitation2.invitationId);
|
|
1607
|
-
invitation2.state = Invitation3.State.READY_FOR_AUTHENTICATION;
|
|
1608
|
-
next(invitation2);
|
|
1609
|
-
break;
|
|
1610
|
-
}
|
|
1611
|
-
case Invitation3.State.AUTHENTICATING: {
|
|
1612
|
-
assert6(invitation2.invitationId);
|
|
1613
|
-
invitation2.state = Invitation3.State.AUTHENTICATING;
|
|
1614
|
-
next(invitation2);
|
|
1615
|
-
break;
|
|
1616
|
-
}
|
|
1617
|
-
case Invitation3.State.SUCCESS: {
|
|
1618
|
-
assert6(invitation2.invitationId);
|
|
1619
|
-
invitation2.state = Invitation3.State.SUCCESS;
|
|
1620
|
-
next(invitation2);
|
|
1621
|
-
break;
|
|
1622
|
-
}
|
|
1623
|
-
case Invitation3.State.CANCELLED: {
|
|
1624
|
-
assert6(invitationId);
|
|
1625
|
-
invitation2.invitationId = invitationId;
|
|
1626
|
-
invitation2.state = Invitation3.State.CANCELLED;
|
|
1627
|
-
next(invitation2);
|
|
1628
|
-
break;
|
|
1629
|
-
}
|
|
1630
|
-
case Invitation3.State.TIMEOUT: {
|
|
1631
|
-
assert6(invitationId);
|
|
1632
|
-
invitation2.invitationId = invitationId;
|
|
1633
|
-
invitation2.state = Invitation3.State.TIMEOUT;
|
|
1634
|
-
next(invitation2);
|
|
1635
|
-
break;
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1771
|
+
invitation.subscribe((invitation2) => {
|
|
1772
|
+
next(invitation2);
|
|
1638
1773
|
}, (err) => {
|
|
1639
1774
|
close(err);
|
|
1640
1775
|
}, () => {
|
|
1641
1776
|
close();
|
|
1777
|
+
this._createInvitations.delete(invitation.get().invitationId);
|
|
1642
1778
|
});
|
|
1643
|
-
return (err) => {
|
|
1644
|
-
const context = this.getLoggingContext();
|
|
1645
|
-
if (err) {
|
|
1646
|
-
log5.warn("stream closed", {
|
|
1647
|
-
...context,
|
|
1648
|
-
err
|
|
1649
|
-
}, {
|
|
1650
|
-
file: "invitations-service.ts",
|
|
1651
|
-
line: 103,
|
|
1652
|
-
scope: this,
|
|
1653
|
-
callSite: (f, a) => f(...a)
|
|
1654
|
-
});
|
|
1655
|
-
} else {
|
|
1656
|
-
log5("stream closed", context, {
|
|
1657
|
-
file: "invitations-service.ts",
|
|
1658
|
-
line: 105,
|
|
1659
|
-
scope: this,
|
|
1660
|
-
callSite: (f, a) => f(...a)
|
|
1661
|
-
});
|
|
1662
|
-
}
|
|
1663
|
-
this._createInvitations.delete(invitation.invitationId);
|
|
1664
|
-
};
|
|
1665
1779
|
});
|
|
1666
1780
|
}
|
|
1667
|
-
acceptInvitation(
|
|
1781
|
+
acceptInvitation(options) {
|
|
1782
|
+
let invitation;
|
|
1783
|
+
const existingInvitation = this._acceptInvitations.get(options.invitationId);
|
|
1784
|
+
if (existingInvitation) {
|
|
1785
|
+
invitation = existingInvitation;
|
|
1786
|
+
} else {
|
|
1787
|
+
const handler = this._getHandler(options);
|
|
1788
|
+
invitation = this._invitationsHandler.acceptInvitation(handler, options);
|
|
1789
|
+
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
1790
|
+
this._invitationAccepted.emit(invitation.get());
|
|
1791
|
+
}
|
|
1668
1792
|
return new Stream7(({ next, close }) => {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
line: 115,
|
|
1672
|
-
scope: this,
|
|
1673
|
-
callSite: (f, a) => f(...a)
|
|
1674
|
-
});
|
|
1675
|
-
const handler = this._getHandler(invitation);
|
|
1676
|
-
let invitationId;
|
|
1677
|
-
const observable = this._invitationsHandler.acceptInvitation(handler, invitation);
|
|
1678
|
-
observable.subscribe((invitation2) => {
|
|
1679
|
-
switch (invitation2.state) {
|
|
1680
|
-
case Invitation3.State.CONNECTING: {
|
|
1681
|
-
assert6(invitation2.invitationId);
|
|
1682
|
-
invitationId = invitation2.invitationId;
|
|
1683
|
-
this._acceptInvitations.set(invitation2.invitationId, observable);
|
|
1684
|
-
invitation2.state = Invitation3.State.CONNECTING;
|
|
1685
|
-
next(invitation2);
|
|
1686
|
-
break;
|
|
1687
|
-
}
|
|
1688
|
-
case Invitation3.State.CONNECTED: {
|
|
1689
|
-
assert6(invitation2.invitationId);
|
|
1690
|
-
invitation2.state = Invitation3.State.CONNECTED;
|
|
1691
|
-
next(invitation2);
|
|
1692
|
-
break;
|
|
1693
|
-
}
|
|
1694
|
-
case Invitation3.State.READY_FOR_AUTHENTICATION: {
|
|
1695
|
-
assert6(invitation2.invitationId);
|
|
1696
|
-
invitation2.state = Invitation3.State.READY_FOR_AUTHENTICATION;
|
|
1697
|
-
next(invitation2);
|
|
1698
|
-
break;
|
|
1699
|
-
}
|
|
1700
|
-
case Invitation3.State.AUTHENTICATING: {
|
|
1701
|
-
assert6(invitation2.invitationId);
|
|
1702
|
-
invitation2.state = Invitation3.State.AUTHENTICATING;
|
|
1703
|
-
next(invitation2);
|
|
1704
|
-
break;
|
|
1705
|
-
}
|
|
1706
|
-
case Invitation3.State.SUCCESS: {
|
|
1707
|
-
invitation2.state = Invitation3.State.SUCCESS;
|
|
1708
|
-
next(invitation2);
|
|
1709
|
-
break;
|
|
1710
|
-
}
|
|
1711
|
-
case Invitation3.State.CANCELLED: {
|
|
1712
|
-
assert6(invitationId);
|
|
1713
|
-
invitation2.invitationId = invitationId;
|
|
1714
|
-
invitation2.state = Invitation3.State.CANCELLED;
|
|
1715
|
-
next(invitation2);
|
|
1716
|
-
break;
|
|
1717
|
-
}
|
|
1718
|
-
case Invitation3.State.TIMEOUT: {
|
|
1719
|
-
assert6(invitationId);
|
|
1720
|
-
invitation2.invitationId = invitationId;
|
|
1721
|
-
invitation2.state = Invitation3.State.TIMEOUT;
|
|
1722
|
-
next(invitation2);
|
|
1723
|
-
break;
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1793
|
+
invitation.subscribe((invitation2) => {
|
|
1794
|
+
next(invitation2);
|
|
1726
1795
|
}, (err) => {
|
|
1727
1796
|
close(err);
|
|
1728
1797
|
}, () => {
|
|
1729
1798
|
close();
|
|
1799
|
+
this._acceptInvitations.delete(invitation.get().invitationId);
|
|
1730
1800
|
});
|
|
1731
|
-
return (err) => {
|
|
1732
|
-
const context = this.getLoggingContext();
|
|
1733
|
-
if (err) {
|
|
1734
|
-
log5.warn("stream closed", {
|
|
1735
|
-
...context,
|
|
1736
|
-
err
|
|
1737
|
-
}, {
|
|
1738
|
-
file: "invitations-service.ts",
|
|
1739
|
-
line: 181,
|
|
1740
|
-
scope: this,
|
|
1741
|
-
callSite: (f, a) => f(...a)
|
|
1742
|
-
});
|
|
1743
|
-
} else {
|
|
1744
|
-
log5("stream closed", context, {
|
|
1745
|
-
file: "invitations-service.ts",
|
|
1746
|
-
line: 183,
|
|
1747
|
-
scope: this,
|
|
1748
|
-
callSite: (f, a) => f(...a)
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
this._acceptInvitations.delete(invitation.invitationId);
|
|
1752
|
-
};
|
|
1753
1801
|
});
|
|
1754
1802
|
}
|
|
1755
1803
|
async authenticate({ invitationId, authCode }) {
|
|
1756
|
-
|
|
1804
|
+
log6("authenticating...", {}, {
|
|
1757
1805
|
file: "invitations-service.ts",
|
|
1758
|
-
line:
|
|
1806
|
+
line: 103,
|
|
1759
1807
|
scope: this,
|
|
1760
1808
|
callSite: (f, a) => f(...a)
|
|
1761
1809
|
});
|
|
1762
|
-
|
|
1810
|
+
assert7(invitationId);
|
|
1763
1811
|
const observable = this._acceptInvitations.get(invitationId);
|
|
1764
1812
|
if (!observable) {
|
|
1765
|
-
|
|
1813
|
+
log6.warn("invalid invitation", {
|
|
1766
1814
|
invitationId
|
|
1767
1815
|
}, {
|
|
1768
1816
|
file: "invitations-service.ts",
|
|
1769
|
-
line:
|
|
1817
|
+
line: 107,
|
|
1770
1818
|
scope: this,
|
|
1771
1819
|
callSite: (f, a) => f(...a)
|
|
1772
1820
|
});
|
|
@@ -1775,36 +1823,92 @@ var InvitationsServiceImpl = class {
|
|
|
1775
1823
|
}
|
|
1776
1824
|
}
|
|
1777
1825
|
async cancelInvitation({ invitationId }) {
|
|
1778
|
-
|
|
1779
|
-
log5("cancelling...", {}, {
|
|
1826
|
+
log6("deleting...", {}, {
|
|
1780
1827
|
file: "invitations-service.ts",
|
|
1781
|
-
line:
|
|
1828
|
+
line: 114,
|
|
1782
1829
|
scope: this,
|
|
1783
1830
|
callSite: (f, a) => f(...a)
|
|
1784
1831
|
});
|
|
1785
|
-
|
|
1786
|
-
const
|
|
1787
|
-
|
|
1788
|
-
|
|
1832
|
+
assert7(invitationId);
|
|
1833
|
+
const created = this._createInvitations.get(invitationId);
|
|
1834
|
+
const accepted = this._acceptInvitations.get(invitationId);
|
|
1835
|
+
if (created) {
|
|
1836
|
+
await created.cancel();
|
|
1837
|
+
this._createInvitations.delete(invitationId);
|
|
1838
|
+
this._removedCreated.emit(created.get());
|
|
1839
|
+
} else if (accepted) {
|
|
1840
|
+
await accepted.cancel();
|
|
1841
|
+
this._acceptInvitations.delete(invitationId);
|
|
1842
|
+
this._removedAccepted.emit(accepted.get());
|
|
1843
|
+
} else {
|
|
1844
|
+
log6.warn("invalid invitation", {
|
|
1789
1845
|
invitationId
|
|
1790
1846
|
}, {
|
|
1791
1847
|
file: "invitations-service.ts",
|
|
1792
|
-
line:
|
|
1848
|
+
line: 127,
|
|
1793
1849
|
scope: this,
|
|
1794
1850
|
callSite: (f, a) => f(...a)
|
|
1795
1851
|
});
|
|
1796
|
-
} else {
|
|
1797
|
-
await (observable == null ? void 0 : observable.cancel());
|
|
1798
1852
|
}
|
|
1799
1853
|
}
|
|
1854
|
+
queryInvitations() {
|
|
1855
|
+
return new Stream7(({ next, ctx }) => {
|
|
1856
|
+
this._invitationCreated.on(ctx, (invitation) => {
|
|
1857
|
+
next({
|
|
1858
|
+
action: QueryInvitationsResponse.Action.ADDED,
|
|
1859
|
+
type: QueryInvitationsResponse.Type.CREATED,
|
|
1860
|
+
invitations: [
|
|
1861
|
+
invitation
|
|
1862
|
+
]
|
|
1863
|
+
});
|
|
1864
|
+
});
|
|
1865
|
+
this._invitationAccepted.on(ctx, (invitation) => {
|
|
1866
|
+
next({
|
|
1867
|
+
action: QueryInvitationsResponse.Action.ADDED,
|
|
1868
|
+
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
1869
|
+
invitations: [
|
|
1870
|
+
invitation
|
|
1871
|
+
]
|
|
1872
|
+
});
|
|
1873
|
+
});
|
|
1874
|
+
this._removedCreated.on(ctx, (invitation) => {
|
|
1875
|
+
next({
|
|
1876
|
+
action: QueryInvitationsResponse.Action.REMOVED,
|
|
1877
|
+
type: QueryInvitationsResponse.Type.CREATED,
|
|
1878
|
+
invitations: [
|
|
1879
|
+
invitation
|
|
1880
|
+
]
|
|
1881
|
+
});
|
|
1882
|
+
});
|
|
1883
|
+
this._removedAccepted.on(ctx, (invitation) => {
|
|
1884
|
+
next({
|
|
1885
|
+
action: QueryInvitationsResponse.Action.REMOVED,
|
|
1886
|
+
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
1887
|
+
invitations: [
|
|
1888
|
+
invitation
|
|
1889
|
+
]
|
|
1890
|
+
});
|
|
1891
|
+
});
|
|
1892
|
+
next({
|
|
1893
|
+
action: QueryInvitationsResponse.Action.ADDED,
|
|
1894
|
+
type: QueryInvitationsResponse.Type.CREATED,
|
|
1895
|
+
invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
|
|
1896
|
+
});
|
|
1897
|
+
next({
|
|
1898
|
+
action: QueryInvitationsResponse.Action.ADDED,
|
|
1899
|
+
type: QueryInvitationsResponse.Type.ACCEPTED,
|
|
1900
|
+
invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
|
|
1901
|
+
});
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1800
1904
|
};
|
|
1801
1905
|
|
|
1802
1906
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
1803
|
-
import
|
|
1907
|
+
import assert8 from "@dxos/node-std/assert";
|
|
1804
1908
|
import { createAdmissionCredentials, getCredentialAssertion } from "@dxos/credentials";
|
|
1805
1909
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
1806
|
-
import { log as
|
|
1807
|
-
import { Invitation as
|
|
1910
|
+
import { log as log7 } from "@dxos/log";
|
|
1911
|
+
import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1808
1912
|
var SpaceInvitationProtocol = class {
|
|
1809
1913
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
1810
1914
|
this._spaceManager = _spaceManager;
|
|
@@ -1820,18 +1924,18 @@ var SpaceInvitationProtocol = class {
|
|
|
1820
1924
|
}
|
|
1821
1925
|
getInvitationContext() {
|
|
1822
1926
|
return {
|
|
1823
|
-
kind:
|
|
1927
|
+
kind: Invitation3.Kind.SPACE,
|
|
1824
1928
|
spaceKey: this._spaceKey
|
|
1825
1929
|
};
|
|
1826
1930
|
}
|
|
1827
1931
|
async admit(request, guestProfile) {
|
|
1828
1932
|
var _a;
|
|
1829
|
-
|
|
1933
|
+
assert8(this._spaceKey);
|
|
1830
1934
|
const space = await this._spaceManager.spaces.get(this._spaceKey);
|
|
1831
|
-
|
|
1832
|
-
|
|
1935
|
+
assert8(space);
|
|
1936
|
+
assert8(request.space);
|
|
1833
1937
|
const { identityKey, deviceKey } = request.space;
|
|
1834
|
-
|
|
1938
|
+
log7("writing guest credentials", {
|
|
1835
1939
|
host: this._signingContext.deviceKey,
|
|
1836
1940
|
guest: deviceKey
|
|
1837
1941
|
}, {
|
|
@@ -1841,9 +1945,9 @@ var SpaceInvitationProtocol = class {
|
|
|
1841
1945
|
callSite: (f, a) => f(...a)
|
|
1842
1946
|
});
|
|
1843
1947
|
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
|
|
1844
|
-
|
|
1948
|
+
assert8(credentials[0].credential);
|
|
1845
1949
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
1846
|
-
|
|
1950
|
+
assert8(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
|
|
1847
1951
|
await writeMessages2(space.inner.controlPipeline.writer, credentials);
|
|
1848
1952
|
return {
|
|
1849
1953
|
space: {
|
|
@@ -1871,11 +1975,11 @@ var SpaceInvitationProtocol = class {
|
|
|
1871
1975
|
};
|
|
1872
1976
|
}
|
|
1873
1977
|
async accept(response) {
|
|
1874
|
-
|
|
1978
|
+
assert8(response.space);
|
|
1875
1979
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
1876
1980
|
const assertion = getCredentialAssertion(credential);
|
|
1877
|
-
|
|
1878
|
-
|
|
1981
|
+
assert8(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
|
|
1982
|
+
assert8(credential.subject.id.equals(this._signingContext.identityKey));
|
|
1879
1983
|
await this._spaceManager.acceptSpace({
|
|
1880
1984
|
spaceKey: assertion.spaceKey,
|
|
1881
1985
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
@@ -1937,15 +2041,15 @@ var toStorageType = (type) => {
|
|
|
1937
2041
|
};
|
|
1938
2042
|
|
|
1939
2043
|
// packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
|
|
1940
|
-
import
|
|
1941
|
-
import { Event as
|
|
2044
|
+
import assert9 from "@dxos/node-std/assert";
|
|
2045
|
+
import { Event as Event4 } from "@dxos/async";
|
|
1942
2046
|
import { appServiceBundle, shellServiceBundle } from "@dxos/client";
|
|
1943
2047
|
import { ShellLayout } from "@dxos/protocols/proto/dxos/iframe";
|
|
1944
2048
|
import { createProtoRpcPeer } from "@dxos/rpc";
|
|
1945
2049
|
var ShellRuntimeImpl = class {
|
|
1946
2050
|
constructor(_port) {
|
|
1947
2051
|
this._port = _port;
|
|
1948
|
-
this.layoutUpdate = new
|
|
2052
|
+
this.layoutUpdate = new Event4();
|
|
1949
2053
|
this._layout = ShellLayout.DEFAULT;
|
|
1950
2054
|
}
|
|
1951
2055
|
get layout() {
|
|
@@ -1967,7 +2071,7 @@ var ShellRuntimeImpl = class {
|
|
|
1967
2071
|
});
|
|
1968
2072
|
}
|
|
1969
2073
|
async setAppContext(context) {
|
|
1970
|
-
|
|
2074
|
+
assert9(this._appRpc, "runtime not open");
|
|
1971
2075
|
await this._appRpc.rpc.AppService.setContext(context);
|
|
1972
2076
|
}
|
|
1973
2077
|
async open() {
|
|
@@ -1996,8 +2100,8 @@ var ShellRuntimeImpl = class {
|
|
|
1996
2100
|
};
|
|
1997
2101
|
var MemoryShellRuntime = class {
|
|
1998
2102
|
constructor({ layout, invitationCode, spaceKey } = {}) {
|
|
1999
|
-
this.layoutUpdate = new
|
|
2000
|
-
this.contextUpdate = new
|
|
2103
|
+
this.layoutUpdate = new Event4();
|
|
2104
|
+
this.contextUpdate = new Event4();
|
|
2001
2105
|
this._layout = layout != null ? layout : ShellLayout.DEFAULT;
|
|
2002
2106
|
this._invitationCode = invitationCode;
|
|
2003
2107
|
this._spaceKey = spaceKey;
|
|
@@ -2026,19 +2130,19 @@ var MemoryShellRuntime = class {
|
|
|
2026
2130
|
};
|
|
2027
2131
|
|
|
2028
2132
|
// packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
|
|
2029
|
-
import { Trigger as
|
|
2030
|
-
import { log as
|
|
2133
|
+
import { Trigger as Trigger9 } from "@dxos/async";
|
|
2134
|
+
import { log as log19, logInfo as logInfo3 } from "@dxos/log";
|
|
2031
2135
|
import { MemorySignalManager as MemorySignalManager3, MemorySignalManagerContext as MemorySignalManagerContext3, WebsocketSignalManager as WebsocketSignalManager3 } from "@dxos/messaging";
|
|
2032
2136
|
import { createWebRTCTransportFactory as createWebRTCTransportFactory2, NetworkManager as NetworkManager3 } from "@dxos/network-manager";
|
|
2033
2137
|
import { getAsyncValue } from "@dxos/util";
|
|
2034
2138
|
|
|
2035
2139
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
2036
|
-
import
|
|
2037
|
-
import { Event as
|
|
2038
|
-
import { clientServiceBundle, createDefaultModelFactory, PublicKey as
|
|
2140
|
+
import assert14 from "@dxos/node-std/assert";
|
|
2141
|
+
import { Event as Event8 } from "@dxos/async";
|
|
2142
|
+
import { clientServiceBundle, createDefaultModelFactory, PublicKey as PublicKey10 } from "@dxos/client";
|
|
2039
2143
|
import { DataServiceImpl } from "@dxos/echo-pipeline";
|
|
2040
|
-
import { log as
|
|
2041
|
-
import { trace as
|
|
2144
|
+
import { log as log17 } from "@dxos/log";
|
|
2145
|
+
import { trace as trace6 } from "@dxos/protocols";
|
|
2042
2146
|
import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
2043
2147
|
|
|
2044
2148
|
// packages/sdk/client-services/src/packlets/deprecated/tracing.ts
|
|
@@ -2124,36 +2228,36 @@ var NetworkServiceImpl = class {
|
|
|
2124
2228
|
};
|
|
2125
2229
|
|
|
2126
2230
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
2127
|
-
import
|
|
2128
|
-
import { Event as
|
|
2231
|
+
import assert11 from "@dxos/node-std/assert";
|
|
2232
|
+
import { Event as Event7, synchronized, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
2129
2233
|
import { SpaceState as SpaceState2 } from "@dxos/client";
|
|
2130
|
-
import { cancelWithContext, Context as
|
|
2234
|
+
import { cancelWithContext as cancelWithContext2, Context as Context7 } from "@dxos/context";
|
|
2131
2235
|
import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
2132
2236
|
import { SnapshotManager, spaceGenesis } from "@dxos/echo-pipeline";
|
|
2133
|
-
import { PublicKey as
|
|
2134
|
-
import { log as
|
|
2135
|
-
import { trace as
|
|
2237
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2238
|
+
import { log as log10 } from "@dxos/log";
|
|
2239
|
+
import { trace as trace4 } from "@dxos/protocols";
|
|
2136
2240
|
import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
|
|
2137
2241
|
import { ComplexMap as ComplexMap3, deferFunction as deferFunction2 } from "@dxos/util";
|
|
2138
2242
|
|
|
2139
2243
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2140
|
-
import { Event as
|
|
2244
|
+
import { Event as Event6, scheduleTask as scheduleTask3, trackLeaks } from "@dxos/async";
|
|
2141
2245
|
import { SpaceState } from "@dxos/client";
|
|
2142
|
-
import { Context as
|
|
2246
|
+
import { Context as Context6 } from "@dxos/context";
|
|
2143
2247
|
import { timed } from "@dxos/debug";
|
|
2144
2248
|
import { createMappedFeedWriter, DataPipeline } from "@dxos/echo-pipeline";
|
|
2145
2249
|
import { CancelledError, SystemError } from "@dxos/errors";
|
|
2146
|
-
import { PublicKey as
|
|
2147
|
-
import { log as
|
|
2250
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
2251
|
+
import { log as log9 } from "@dxos/log";
|
|
2148
2252
|
import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2149
2253
|
import { ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
2150
2254
|
|
|
2151
2255
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
2152
|
-
import
|
|
2153
|
-
import { DeferredTask, Event as
|
|
2154
|
-
import { Context as
|
|
2155
|
-
import { PublicKey as
|
|
2156
|
-
import { log as
|
|
2256
|
+
import assert10 from "@dxos/node-std/assert";
|
|
2257
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask2, sleep as sleep2, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
|
|
2258
|
+
import { Context as Context5, rejectOnDispose } from "@dxos/context";
|
|
2259
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
2260
|
+
import { log as log8 } from "@dxos/log";
|
|
2157
2261
|
import { schema as schema3 } from "@dxos/protocols";
|
|
2158
2262
|
import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
|
|
2159
2263
|
import { ComplexMap as ComplexMap2, ComplexSet, entry } from "@dxos/util";
|
|
@@ -2162,11 +2266,11 @@ var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
|
2162
2266
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
2163
2267
|
var NotarizationPlugin = class {
|
|
2164
2268
|
constructor() {
|
|
2165
|
-
this._ctx = new
|
|
2166
|
-
this._extensionOpened = new
|
|
2269
|
+
this._ctx = new Context5();
|
|
2270
|
+
this._extensionOpened = new Event5();
|
|
2167
2271
|
this._extensions = /* @__PURE__ */ new Set();
|
|
2168
|
-
this._processedCredentials = new ComplexSet(
|
|
2169
|
-
this._processCredentialsTriggers = new ComplexMap2(
|
|
2272
|
+
this._processedCredentials = new ComplexSet(PublicKey6.hash);
|
|
2273
|
+
this._processCredentialsTriggers = new ComplexMap2(PublicKey6.hash);
|
|
2170
2274
|
}
|
|
2171
2275
|
async open() {
|
|
2172
2276
|
}
|
|
@@ -2177,7 +2281,7 @@ var NotarizationPlugin = class {
|
|
|
2177
2281
|
* Request credentials to be notarized.
|
|
2178
2282
|
*/
|
|
2179
2283
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
2180
|
-
|
|
2284
|
+
log8("notarize", {
|
|
2181
2285
|
credentials
|
|
2182
2286
|
}, {
|
|
2183
2287
|
file: "notarization-plugin.ts",
|
|
@@ -2185,11 +2289,11 @@ var NotarizationPlugin = class {
|
|
|
2185
2289
|
scope: this,
|
|
2186
2290
|
callSite: (f, a) => f(...a)
|
|
2187
2291
|
});
|
|
2188
|
-
|
|
2189
|
-
const errors = new
|
|
2292
|
+
assert10(credentials.every((credential) => credential.id), "Credentials must have an id");
|
|
2293
|
+
const errors = new Trigger4();
|
|
2190
2294
|
const ctx = this._ctx.derive({
|
|
2191
2295
|
onError: (err) => {
|
|
2192
|
-
|
|
2296
|
+
log8.warn("Notarization error", {
|
|
2193
2297
|
err
|
|
2194
2298
|
}, {
|
|
2195
2299
|
file: "notarization-plugin.ts",
|
|
@@ -2204,7 +2308,7 @@ var NotarizationPlugin = class {
|
|
|
2204
2308
|
opCtx == null ? void 0 : opCtx.onDispose(() => ctx.dispose());
|
|
2205
2309
|
if (timeout !== 0) {
|
|
2206
2310
|
scheduleTask2(ctx, () => {
|
|
2207
|
-
|
|
2311
|
+
log8.warn("Notarization timeout", {
|
|
2208
2312
|
timeout,
|
|
2209
2313
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
2210
2314
|
}, {
|
|
@@ -2228,7 +2332,7 @@ var NotarizationPlugin = class {
|
|
|
2228
2332
|
...this._extensions
|
|
2229
2333
|
].find((peer2) => !peersTried.has(peer2));
|
|
2230
2334
|
if (!peer) {
|
|
2231
|
-
|
|
2335
|
+
log8.warn("Exhausted all peers to notarize with", {
|
|
2232
2336
|
retryIn: retryTimeout
|
|
2233
2337
|
}, {
|
|
2234
2338
|
file: "notarization-plugin.ts",
|
|
@@ -2241,7 +2345,7 @@ var NotarizationPlugin = class {
|
|
|
2241
2345
|
return;
|
|
2242
2346
|
}
|
|
2243
2347
|
peersTried.add(peer);
|
|
2244
|
-
|
|
2348
|
+
log8("try notarizing", {
|
|
2245
2349
|
peer: peer.localPeerId,
|
|
2246
2350
|
credentialId: credentials.map((credential) => credential.id)
|
|
2247
2351
|
}, {
|
|
@@ -2253,7 +2357,7 @@ var NotarizationPlugin = class {
|
|
|
2253
2357
|
await peer.rpc.NotarizationService.notarize({
|
|
2254
2358
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
2255
2359
|
});
|
|
2256
|
-
|
|
2360
|
+
log8("success", {}, {
|
|
2257
2361
|
file: "notarization-plugin.ts",
|
|
2258
2362
|
line: 142,
|
|
2259
2363
|
scope: this,
|
|
@@ -2261,7 +2365,7 @@ var NotarizationPlugin = class {
|
|
|
2261
2365
|
});
|
|
2262
2366
|
await sleep2(successDelay);
|
|
2263
2367
|
} catch (err) {
|
|
2264
|
-
|
|
2368
|
+
log8.warn("error notarizing (recoverable)", err, {
|
|
2265
2369
|
file: "notarization-plugin.ts",
|
|
2266
2370
|
line: 145,
|
|
2267
2371
|
scope: this,
|
|
@@ -2278,7 +2382,7 @@ var NotarizationPlugin = class {
|
|
|
2278
2382
|
allNotarized,
|
|
2279
2383
|
errors.wait()
|
|
2280
2384
|
]);
|
|
2281
|
-
|
|
2385
|
+
log8("done", {}, {
|
|
2282
2386
|
file: "notarization-plugin.ts",
|
|
2283
2387
|
line: 155,
|
|
2284
2388
|
scope: this,
|
|
@@ -2301,14 +2405,14 @@ var NotarizationPlugin = class {
|
|
|
2301
2405
|
this._processCredentialsTriggers.delete(credential.id);
|
|
2302
2406
|
}
|
|
2303
2407
|
setWriter(writer) {
|
|
2304
|
-
|
|
2408
|
+
assert10(!this._writer, "Writer already set.");
|
|
2305
2409
|
this._writer = writer;
|
|
2306
2410
|
}
|
|
2307
2411
|
async _waitUntilProcessed(id) {
|
|
2308
2412
|
if (this._processedCredentials.has(id)) {
|
|
2309
2413
|
return;
|
|
2310
2414
|
}
|
|
2311
|
-
await entry(this._processCredentialsTriggers, id).orInsert(new
|
|
2415
|
+
await entry(this._processCredentialsTriggers, id).orInsert(new Trigger4()).value.wait();
|
|
2312
2416
|
}
|
|
2313
2417
|
/**
|
|
2314
2418
|
* Requests from other peers to notarize credentials.
|
|
@@ -2319,7 +2423,7 @@ var NotarizationPlugin = class {
|
|
|
2319
2423
|
throw new Error("Writer not set");
|
|
2320
2424
|
}
|
|
2321
2425
|
for (const credential of (_a = request.credentials) != null ? _a : []) {
|
|
2322
|
-
|
|
2426
|
+
assert10(credential.id, "Credential must have an id");
|
|
2323
2427
|
if (this._processedCredentials.has(credential.id)) {
|
|
2324
2428
|
continue;
|
|
2325
2429
|
}
|
|
@@ -2329,7 +2433,7 @@ var NotarizationPlugin = class {
|
|
|
2329
2433
|
createExtension() {
|
|
2330
2434
|
const extension = new NotarizationTeleportExtension({
|
|
2331
2435
|
onOpen: async () => {
|
|
2332
|
-
|
|
2436
|
+
log8("extension opened", {
|
|
2333
2437
|
peer: extension.localPeerId
|
|
2334
2438
|
}, {
|
|
2335
2439
|
file: "notarization-plugin.ts",
|
|
@@ -2341,7 +2445,7 @@ var NotarizationPlugin = class {
|
|
|
2341
2445
|
this._extensionOpened.emit();
|
|
2342
2446
|
},
|
|
2343
2447
|
onClose: async () => {
|
|
2344
|
-
|
|
2448
|
+
log8("extension closed", {
|
|
2345
2449
|
peer: extension.localPeerId
|
|
2346
2450
|
}, {
|
|
2347
2451
|
file: "notarization-plugin.ts",
|
|
@@ -2401,9 +2505,9 @@ var __decorate = function(decorators, target, key, desc) {
|
|
|
2401
2505
|
var AUTH_TIMEOUT2 = 3e4;
|
|
2402
2506
|
var DataSpace = class DataSpace2 {
|
|
2403
2507
|
constructor(params) {
|
|
2404
|
-
this._ctx = new
|
|
2508
|
+
this._ctx = new Context6();
|
|
2405
2509
|
this._state = SpaceState.CLOSED;
|
|
2406
|
-
this.stateUpdate = new
|
|
2510
|
+
this.stateUpdate = new Event6();
|
|
2407
2511
|
var _a;
|
|
2408
2512
|
this._inner = params.inner;
|
|
2409
2513
|
this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
|
|
@@ -2424,7 +2528,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2424
2528
|
snapshotId: params.snapshotId
|
|
2425
2529
|
});
|
|
2426
2530
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
2427
|
-
trustedKeysProvider: () => new ComplexSet2(
|
|
2531
|
+
trustedKeysProvider: () => new ComplexSet2(PublicKey7.hash, Array.from(this._inner.spaceState.members.keys())),
|
|
2428
2532
|
update: this._inner.stateUpdate,
|
|
2429
2533
|
authTimeout: AUTH_TIMEOUT2
|
|
2430
2534
|
});
|
|
@@ -2483,7 +2587,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2483
2587
|
await this.initializeDataPipeline();
|
|
2484
2588
|
} catch (err) {
|
|
2485
2589
|
if (err instanceof CancelledError) {
|
|
2486
|
-
|
|
2590
|
+
log9("Data pipeline initialization cancelled", err, {
|
|
2487
2591
|
file: "data-space.ts",
|
|
2488
2592
|
line: 178,
|
|
2489
2593
|
scope: this,
|
|
@@ -2491,7 +2595,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2491
2595
|
});
|
|
2492
2596
|
return;
|
|
2493
2597
|
}
|
|
2494
|
-
|
|
2598
|
+
log9.error("Error initializing data pipeline", err, {
|
|
2495
2599
|
file: "data-space.ts",
|
|
2496
2600
|
line: 182,
|
|
2497
2601
|
scope: this,
|
|
@@ -2511,7 +2615,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2511
2615
|
breakOnStall: false
|
|
2512
2616
|
});
|
|
2513
2617
|
await this._createWritableFeeds();
|
|
2514
|
-
|
|
2618
|
+
log9("Writable feeds created", {}, {
|
|
2515
2619
|
file: "data-space.ts",
|
|
2516
2620
|
line: 200,
|
|
2517
2621
|
scope: this,
|
|
@@ -2532,7 +2636,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2532
2636
|
return pipeline;
|
|
2533
2637
|
}
|
|
2534
2638
|
});
|
|
2535
|
-
|
|
2639
|
+
log9("waiting for data pipeline to reach target timeframe", {}, {
|
|
2536
2640
|
file: "data-space.ts",
|
|
2537
2641
|
line: 220,
|
|
2538
2642
|
scope: this,
|
|
@@ -2542,7 +2646,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2542
2646
|
ctx: this._ctx,
|
|
2543
2647
|
breakOnStall: false
|
|
2544
2648
|
});
|
|
2545
|
-
|
|
2649
|
+
log9("data pipeline ready", {}, {
|
|
2546
2650
|
file: "data-space.ts",
|
|
2547
2651
|
line: 227,
|
|
2548
2652
|
scope: this,
|
|
@@ -2625,24 +2729,24 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2625
2729
|
this._modelFactory = _modelFactory;
|
|
2626
2730
|
this._feedStore = _feedStore;
|
|
2627
2731
|
this._snapshotStore = _snapshotStore;
|
|
2628
|
-
this._ctx = new
|
|
2629
|
-
this.updated = new
|
|
2630
|
-
this._spaces = new ComplexMap3(
|
|
2732
|
+
this._ctx = new Context7();
|
|
2733
|
+
this.updated = new Event7();
|
|
2734
|
+
this._spaces = new ComplexMap3(PublicKey8.hash);
|
|
2631
2735
|
this._isOpen = false;
|
|
2632
|
-
this._instanceId =
|
|
2736
|
+
this._instanceId = PublicKey8.random().toHex();
|
|
2633
2737
|
}
|
|
2634
2738
|
// TODO(burdon): Remove.
|
|
2635
2739
|
get spaces() {
|
|
2636
2740
|
return this._spaces;
|
|
2637
2741
|
}
|
|
2638
2742
|
async open() {
|
|
2639
|
-
|
|
2743
|
+
log10("open", {}, {
|
|
2640
2744
|
file: "data-space-manager.ts",
|
|
2641
2745
|
line: 83,
|
|
2642
2746
|
scope: this,
|
|
2643
2747
|
callSite: (f, a) => f(...a)
|
|
2644
2748
|
});
|
|
2645
|
-
|
|
2749
|
+
log10.trace("dxos.echo.data-space-manager", trace4.begin({
|
|
2646
2750
|
id: this._instanceId,
|
|
2647
2751
|
parentId: this._traceParent
|
|
2648
2752
|
}), {
|
|
@@ -2652,7 +2756,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2652
2756
|
callSite: (f, a) => f(...a)
|
|
2653
2757
|
});
|
|
2654
2758
|
await this._metadataStore.load();
|
|
2655
|
-
|
|
2759
|
+
log10("metadata loaded", {
|
|
2656
2760
|
spaces: this._metadataStore.spaces.length
|
|
2657
2761
|
}, {
|
|
2658
2762
|
file: "data-space-manager.ts",
|
|
@@ -2661,7 +2765,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2661
2765
|
callSite: (f, a) => f(...a)
|
|
2662
2766
|
});
|
|
2663
2767
|
for (const spaceMetadata of this._metadataStore.spaces) {
|
|
2664
|
-
|
|
2768
|
+
log10("load space", {
|
|
2665
2769
|
spaceMetadata
|
|
2666
2770
|
}, {
|
|
2667
2771
|
file: "data-space-manager.ts",
|
|
@@ -2676,7 +2780,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2676
2780
|
this.updated.emit();
|
|
2677
2781
|
}
|
|
2678
2782
|
async close() {
|
|
2679
|
-
|
|
2783
|
+
log10("close", {}, {
|
|
2680
2784
|
file: "data-space-manager.ts",
|
|
2681
2785
|
line: 100,
|
|
2682
2786
|
scope: this,
|
|
@@ -2687,7 +2791,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2687
2791
|
for (const space of this._spaces.values()) {
|
|
2688
2792
|
await space.close();
|
|
2689
2793
|
}
|
|
2690
|
-
|
|
2794
|
+
log10.trace("dxos.echo.data-space-manager", trace4.end({
|
|
2691
2795
|
id: this._instanceId
|
|
2692
2796
|
}), {
|
|
2693
2797
|
file: "data-space-manager.ts",
|
|
@@ -2700,7 +2804,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2700
2804
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
2701
2805
|
*/
|
|
2702
2806
|
async createSpace() {
|
|
2703
|
-
|
|
2807
|
+
assert11(this._isOpen, "Not open.");
|
|
2704
2808
|
const spaceKey = await this._keyring.createKey();
|
|
2705
2809
|
const controlFeedKey = await this._keyring.createKey();
|
|
2706
2810
|
const dataFeedKey = await this._keyring.createKey();
|
|
@@ -2710,7 +2814,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2710
2814
|
controlFeedKey,
|
|
2711
2815
|
dataFeedKey
|
|
2712
2816
|
};
|
|
2713
|
-
|
|
2817
|
+
log10("creating space...", {
|
|
2714
2818
|
spaceKey
|
|
2715
2819
|
}, {
|
|
2716
2820
|
file: "data-space-manager.ts",
|
|
@@ -2722,7 +2826,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2722
2826
|
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
|
|
2723
2827
|
await this._metadataStore.addSpace(metadata);
|
|
2724
2828
|
const memberCredential = credentials[1];
|
|
2725
|
-
|
|
2829
|
+
assert11(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
|
|
2726
2830
|
await this._signingContext.recordCredential(memberCredential);
|
|
2727
2831
|
await space.initializeDataPipeline();
|
|
2728
2832
|
this.updated.emit();
|
|
@@ -2730,7 +2834,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2730
2834
|
}
|
|
2731
2835
|
// TODO(burdon): Rename join space.
|
|
2732
2836
|
async acceptSpace(opts) {
|
|
2733
|
-
|
|
2837
|
+
log10("accept space", {
|
|
2734
2838
|
opts
|
|
2735
2839
|
}, {
|
|
2736
2840
|
file: "data-space-manager.ts",
|
|
@@ -2738,8 +2842,8 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2738
2842
|
scope: this,
|
|
2739
2843
|
callSite: (f, a) => f(...a)
|
|
2740
2844
|
});
|
|
2741
|
-
|
|
2742
|
-
|
|
2845
|
+
assert11(this._isOpen, "Not open.");
|
|
2846
|
+
assert11(!this._spaces.has(opts.spaceKey), "Space already exists.");
|
|
2743
2847
|
const metadata = {
|
|
2744
2848
|
key: opts.spaceKey,
|
|
2745
2849
|
genesisFeedKey: opts.genesisFeedKey,
|
|
@@ -2758,13 +2862,13 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2758
2862
|
* TODO(dmaretskyi): Consider removing.
|
|
2759
2863
|
*/
|
|
2760
2864
|
async waitUntilSpaceReady(spaceKey) {
|
|
2761
|
-
await
|
|
2865
|
+
await cancelWithContext2(this._ctx, this.updated.waitForCondition(() => {
|
|
2762
2866
|
const space = this._spaces.get(spaceKey);
|
|
2763
2867
|
return !!space && space.state === SpaceState2.READY;
|
|
2764
2868
|
}));
|
|
2765
2869
|
}
|
|
2766
2870
|
async _constructSpace(metadata) {
|
|
2767
|
-
|
|
2871
|
+
log10("construct space", {
|
|
2768
2872
|
metadata
|
|
2769
2873
|
}, {
|
|
2770
2874
|
file: "data-space-manager.ts",
|
|
@@ -2819,7 +2923,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2819
2923
|
snapshotId: metadata.snapshot,
|
|
2820
2924
|
callbacks: {
|
|
2821
2925
|
beforeReady: async () => {
|
|
2822
|
-
|
|
2926
|
+
log10("before space ready", {
|
|
2823
2927
|
space: space.key
|
|
2824
2928
|
}, {
|
|
2825
2929
|
file: "data-space-manager.ts",
|
|
@@ -2830,7 +2934,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2830
2934
|
this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseBackend.createDataServiceHost());
|
|
2831
2935
|
},
|
|
2832
2936
|
afterReady: async () => {
|
|
2833
|
-
|
|
2937
|
+
log10("after space ready", {
|
|
2834
2938
|
space: space.key,
|
|
2835
2939
|
open: this._isOpen
|
|
2836
2940
|
}, {
|
|
@@ -2877,7 +2981,7 @@ import { EventSubscriptions as EventSubscriptions3, scheduleTask as scheduleTask
|
|
|
2877
2981
|
import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
2878
2982
|
import { raise, todo as todo2 } from "@dxos/debug";
|
|
2879
2983
|
import { SpaceNotFoundError } from "@dxos/echo-pipeline";
|
|
2880
|
-
import { log as
|
|
2984
|
+
import { log as log11 } from "@dxos/log";
|
|
2881
2985
|
import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
|
|
2882
2986
|
import { humanize } from "@dxos/util";
|
|
2883
2987
|
var TIMEFRAME_UPDATE_DEBOUNCE_TIME = 500;
|
|
@@ -2904,7 +3008,7 @@ var SpacesServiceImpl = class {
|
|
|
2904
3008
|
const onUpdate = async () => {
|
|
2905
3009
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2906
3010
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._transformSpace(space));
|
|
2907
|
-
|
|
3011
|
+
log11("update", {
|
|
2908
3012
|
spaces
|
|
2909
3013
|
}, {
|
|
2910
3014
|
file: "spaces-service.ts",
|
|
@@ -3060,6 +3164,8 @@ var SystemServiceImpl = class {
|
|
|
3060
3164
|
|
|
3061
3165
|
// packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
|
|
3062
3166
|
import { iframeServiceBundle, workerServiceBundle } from "@dxos/client";
|
|
3167
|
+
import { RemoteServiceConnectionError } from "@dxos/errors";
|
|
3168
|
+
import { log as log12 } from "@dxos/log";
|
|
3063
3169
|
import { WebRTCTransportService } from "@dxos/network-manager";
|
|
3064
3170
|
import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
|
|
3065
3171
|
var IFrameProxyRuntime = class {
|
|
@@ -3103,7 +3209,7 @@ var IFrameProxyRuntime = class {
|
|
|
3103
3209
|
}
|
|
3104
3210
|
},
|
|
3105
3211
|
port: this._systemPort,
|
|
3106
|
-
timeout:
|
|
3212
|
+
timeout: 1e3
|
|
3107
3213
|
});
|
|
3108
3214
|
this._workerAppPort.subscribe((msg) => this._windowAppPort.send(msg));
|
|
3109
3215
|
this._windowAppPort.subscribe((msg) => this._workerAppPort.send(msg));
|
|
@@ -3116,10 +3222,20 @@ var IFrameProxyRuntime = class {
|
|
|
3116
3222
|
}
|
|
3117
3223
|
async open(origin) {
|
|
3118
3224
|
var _a;
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3225
|
+
try {
|
|
3226
|
+
await this._systemRpc.open();
|
|
3227
|
+
await this._systemRpc.rpc.WorkerService.start({
|
|
3228
|
+
origin
|
|
3229
|
+
});
|
|
3230
|
+
} catch (err) {
|
|
3231
|
+
log12.catch(err, {}, {
|
|
3232
|
+
file: "iframe-proxy-runtime.ts",
|
|
3233
|
+
line: 79,
|
|
3234
|
+
scope: this,
|
|
3235
|
+
callSite: (f, a) => f(...a)
|
|
3236
|
+
});
|
|
3237
|
+
throw new RemoteServiceConnectionError("Failed to connect to worker");
|
|
3238
|
+
}
|
|
3123
3239
|
await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
|
|
3124
3240
|
}
|
|
3125
3241
|
async close() {
|
|
@@ -3131,8 +3247,8 @@ var IFrameProxyRuntime = class {
|
|
|
3131
3247
|
};
|
|
3132
3248
|
|
|
3133
3249
|
// packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
|
|
3134
|
-
import { asyncTimeout, Trigger as
|
|
3135
|
-
import { log as
|
|
3250
|
+
import { asyncTimeout, Trigger as Trigger5 } from "@dxos/async";
|
|
3251
|
+
import { log as log13, logInfo } from "@dxos/log";
|
|
3136
3252
|
var __decorate3 = function(decorators, target, key, desc) {
|
|
3137
3253
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3138
3254
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -3150,7 +3266,7 @@ var Message;
|
|
|
3150
3266
|
var VaultResourceLock = class {
|
|
3151
3267
|
constructor({ lockKey, onAcquire, onRelease }) {
|
|
3152
3268
|
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
3153
|
-
this._releaseTrigger = new
|
|
3269
|
+
this._releaseTrigger = new Trigger5();
|
|
3154
3270
|
this._lockKey = lockKey;
|
|
3155
3271
|
this._onAcquire = onAcquire;
|
|
3156
3272
|
this._onRelease = onRelease;
|
|
@@ -3164,28 +3280,28 @@ var VaultResourceLock = class {
|
|
|
3164
3280
|
message: Message.ACQUIRING
|
|
3165
3281
|
});
|
|
3166
3282
|
try {
|
|
3167
|
-
|
|
3283
|
+
log13("aquiring lock...", {}, {
|
|
3168
3284
|
file: "vault-resource-lock.ts",
|
|
3169
3285
|
line: 44,
|
|
3170
3286
|
scope: this,
|
|
3171
3287
|
callSite: (f, a) => f(...a)
|
|
3172
3288
|
});
|
|
3173
3289
|
await asyncTimeout(this._requestLock(), 3e3);
|
|
3174
|
-
|
|
3290
|
+
log13("acquired lock", {}, {
|
|
3175
3291
|
file: "vault-resource-lock.ts",
|
|
3176
3292
|
line: 46,
|
|
3177
3293
|
scope: this,
|
|
3178
3294
|
callSite: (f, a) => f(...a)
|
|
3179
3295
|
});
|
|
3180
3296
|
} catch (e) {
|
|
3181
|
-
|
|
3297
|
+
log13("stealing lock...", {}, {
|
|
3182
3298
|
file: "vault-resource-lock.ts",
|
|
3183
3299
|
line: 48,
|
|
3184
3300
|
scope: this,
|
|
3185
3301
|
callSite: (f, a) => f(...a)
|
|
3186
3302
|
});
|
|
3187
3303
|
await this._requestLock(true);
|
|
3188
|
-
|
|
3304
|
+
log13("stolen lock", {}, {
|
|
3189
3305
|
file: "vault-resource-lock.ts",
|
|
3190
3306
|
line: 50,
|
|
3191
3307
|
scope: this,
|
|
@@ -3202,7 +3318,7 @@ var VaultResourceLock = class {
|
|
|
3202
3318
|
}
|
|
3203
3319
|
}
|
|
3204
3320
|
async _requestLock(steal = false) {
|
|
3205
|
-
|
|
3321
|
+
log13("requesting lock...", {
|
|
3206
3322
|
steal
|
|
3207
3323
|
}, {
|
|
3208
3324
|
file: "vault-resource-lock.ts",
|
|
@@ -3210,23 +3326,23 @@ var VaultResourceLock = class {
|
|
|
3210
3326
|
scope: this,
|
|
3211
3327
|
callSite: (f, a) => f(...a)
|
|
3212
3328
|
});
|
|
3213
|
-
const acquired = new
|
|
3329
|
+
const acquired = new Trigger5();
|
|
3214
3330
|
void navigator.locks.request(this._lockKey, {
|
|
3215
3331
|
steal
|
|
3216
3332
|
}, async () => {
|
|
3217
3333
|
var _a, _b;
|
|
3218
3334
|
await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
|
|
3219
3335
|
acquired.wake();
|
|
3220
|
-
this._releaseTrigger = new
|
|
3336
|
+
this._releaseTrigger = new Trigger5();
|
|
3221
3337
|
await this._releaseTrigger.wait();
|
|
3222
|
-
|
|
3338
|
+
log13("releasing lock...", {}, {
|
|
3223
3339
|
file: "vault-resource-lock.ts",
|
|
3224
3340
|
line: 74,
|
|
3225
3341
|
scope: this,
|
|
3226
3342
|
callSite: (f, a) => f(...a)
|
|
3227
3343
|
});
|
|
3228
3344
|
await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
|
|
3229
|
-
|
|
3345
|
+
log13("released lock", {}, {
|
|
3230
3346
|
file: "vault-resource-lock.ts",
|
|
3231
3347
|
line: 76,
|
|
3232
3348
|
scope: this,
|
|
@@ -3237,7 +3353,7 @@ var VaultResourceLock = class {
|
|
|
3237
3353
|
await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
|
|
3238
3354
|
});
|
|
3239
3355
|
await acquired.wait();
|
|
3240
|
-
|
|
3356
|
+
log13("recieved lock", {
|
|
3241
3357
|
steal
|
|
3242
3358
|
}, {
|
|
3243
3359
|
file: "vault-resource-lock.ts",
|
|
@@ -3252,16 +3368,16 @@ __decorate3([
|
|
|
3252
3368
|
], VaultResourceLock.prototype, "lockKey", null);
|
|
3253
3369
|
|
|
3254
3370
|
// packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
|
|
3255
|
-
import { Trigger as
|
|
3256
|
-
import { log as
|
|
3371
|
+
import { Trigger as Trigger7 } from "@dxos/async";
|
|
3372
|
+
import { log as log15 } from "@dxos/log";
|
|
3257
3373
|
import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
|
|
3258
3374
|
import { NetworkManager, WebRTCTransportProxyFactory } from "@dxos/network-manager";
|
|
3259
3375
|
|
|
3260
3376
|
// packages/sdk/client-services/src/packlets/vault/worker-session.ts
|
|
3261
|
-
import
|
|
3262
|
-
import { asyncTimeout as asyncTimeout2, Trigger as
|
|
3377
|
+
import assert12 from "@dxos/node-std/assert";
|
|
3378
|
+
import { asyncTimeout as asyncTimeout2, Trigger as Trigger6 } from "@dxos/async";
|
|
3263
3379
|
import { iframeServiceBundle as iframeServiceBundle2, workerServiceBundle as workerServiceBundle2 } from "@dxos/client";
|
|
3264
|
-
import { log as
|
|
3380
|
+
import { log as log14, logInfo as logInfo2 } from "@dxos/log";
|
|
3265
3381
|
import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
|
|
3266
3382
|
import { Callback } from "@dxos/util";
|
|
3267
3383
|
|
|
@@ -3333,10 +3449,10 @@ var WorkerSession = class {
|
|
|
3333
3449
|
constructor({ serviceHost, systemPort, appPort, shellPort, readySignal, options = {
|
|
3334
3450
|
heartbeatInterval: 1e3
|
|
3335
3451
|
} }) {
|
|
3336
|
-
this._startTrigger = new
|
|
3452
|
+
this._startTrigger = new Trigger6();
|
|
3337
3453
|
this.onClose = new Callback();
|
|
3338
|
-
|
|
3339
|
-
|
|
3454
|
+
assert12(options);
|
|
3455
|
+
assert12(serviceHost);
|
|
3340
3456
|
this._options = options;
|
|
3341
3457
|
this._serviceHost = serviceHost;
|
|
3342
3458
|
const middleware = {
|
|
@@ -3383,7 +3499,7 @@ var WorkerSession = class {
|
|
|
3383
3499
|
try {
|
|
3384
3500
|
await this.close();
|
|
3385
3501
|
} catch (err) {
|
|
3386
|
-
|
|
3502
|
+
log14.catch(err, {}, {
|
|
3387
3503
|
file: "worker-session.ts",
|
|
3388
3504
|
line: 107,
|
|
3389
3505
|
scope: this,
|
|
@@ -3401,7 +3517,7 @@ var WorkerSession = class {
|
|
|
3401
3517
|
this.bridgeService = this._iframeRpc.rpc.BridgeService;
|
|
3402
3518
|
}
|
|
3403
3519
|
async open() {
|
|
3404
|
-
|
|
3520
|
+
log14.info("opening..", {}, {
|
|
3405
3521
|
file: "worker-session.ts",
|
|
3406
3522
|
line: 121,
|
|
3407
3523
|
scope: this,
|
|
@@ -3419,7 +3535,7 @@ var WorkerSession = class {
|
|
|
3419
3535
|
try {
|
|
3420
3536
|
await this._iframeRpc.rpc.IframeService.heartbeat();
|
|
3421
3537
|
} catch (err1) {
|
|
3422
|
-
|
|
3538
|
+
log14.warn("Heartbeat failed", {
|
|
3423
3539
|
err: err1
|
|
3424
3540
|
}, {
|
|
3425
3541
|
file: "worker-session.ts",
|
|
@@ -3430,7 +3546,7 @@ var WorkerSession = class {
|
|
|
3430
3546
|
try {
|
|
3431
3547
|
await this.close();
|
|
3432
3548
|
} catch (err) {
|
|
3433
|
-
|
|
3549
|
+
log14.catch(err, {}, {
|
|
3434
3550
|
file: "worker-session.ts",
|
|
3435
3551
|
line: 137,
|
|
3436
3552
|
scope: this,
|
|
@@ -3441,7 +3557,7 @@ var WorkerSession = class {
|
|
|
3441
3557
|
}, this._options.heartbeatInterval);
|
|
3442
3558
|
}
|
|
3443
3559
|
async close() {
|
|
3444
|
-
|
|
3560
|
+
log14.info("closing..", {}, {
|
|
3445
3561
|
file: "worker-session.ts",
|
|
3446
3562
|
line: 144,
|
|
3447
3563
|
scope: this,
|
|
@@ -3450,7 +3566,7 @@ var WorkerSession = class {
|
|
|
3450
3566
|
try {
|
|
3451
3567
|
await this.onClose.callIfSet();
|
|
3452
3568
|
} catch (err) {
|
|
3453
|
-
|
|
3569
|
+
log14.catch(err, {}, {
|
|
3454
3570
|
file: "worker-session.ts",
|
|
3455
3571
|
line: 148,
|
|
3456
3572
|
scope: this,
|
|
@@ -3469,7 +3585,7 @@ var WorkerSession = class {
|
|
|
3469
3585
|
try {
|
|
3470
3586
|
await asyncTimeout2(this._shellClientRpc.open(), 1e3);
|
|
3471
3587
|
} catch (e) {
|
|
3472
|
-
|
|
3588
|
+
log14.info("No shell connected.", {}, {
|
|
3473
3589
|
file: "worker-session.ts",
|
|
3474
3590
|
line: 162,
|
|
3475
3591
|
scope: this,
|
|
@@ -3488,7 +3604,7 @@ var WorkerRuntime = class {
|
|
|
3488
3604
|
constructor(_configProvider) {
|
|
3489
3605
|
this._configProvider = _configProvider;
|
|
3490
3606
|
this._transportFactory = new WebRTCTransportProxyFactory();
|
|
3491
|
-
this._ready = new
|
|
3607
|
+
this._ready = new Trigger7();
|
|
3492
3608
|
this.sessions = /* @__PURE__ */ new Set();
|
|
3493
3609
|
this._clientServices = new ClientServicesHost();
|
|
3494
3610
|
}
|
|
@@ -3496,7 +3612,7 @@ var WorkerRuntime = class {
|
|
|
3496
3612
|
return this._clientServices;
|
|
3497
3613
|
}
|
|
3498
3614
|
async start() {
|
|
3499
|
-
|
|
3615
|
+
log15("starting...", {}, {
|
|
3500
3616
|
file: "worker-runtime.ts",
|
|
3501
3617
|
line: 48,
|
|
3502
3618
|
scope: this,
|
|
@@ -3504,20 +3620,18 @@ var WorkerRuntime = class {
|
|
|
3504
3620
|
});
|
|
3505
3621
|
try {
|
|
3506
3622
|
this._config = await this._configProvider();
|
|
3507
|
-
const
|
|
3623
|
+
const signals = this._config.get("runtime.services.signaling");
|
|
3508
3624
|
this._clientServices.initialize({
|
|
3509
3625
|
config: this._config,
|
|
3510
3626
|
networkManager: new NetworkManager({
|
|
3511
3627
|
log: true,
|
|
3512
|
-
signalManager:
|
|
3513
|
-
signalServer
|
|
3514
|
-
]) : new MemorySignalManager(new MemorySignalManagerContext()),
|
|
3628
|
+
signalManager: signals ? new WebsocketSignalManager(signals) : new MemorySignalManager(new MemorySignalManagerContext()),
|
|
3515
3629
|
transportFactory: this._transportFactory
|
|
3516
3630
|
})
|
|
3517
3631
|
});
|
|
3518
3632
|
await this._clientServices.open();
|
|
3519
3633
|
this._ready.wake(void 0);
|
|
3520
|
-
|
|
3634
|
+
log15("started", {}, {
|
|
3521
3635
|
file: "worker-runtime.ts",
|
|
3522
3636
|
line: 65,
|
|
3523
3637
|
scope: this,
|
|
@@ -3525,7 +3639,7 @@ var WorkerRuntime = class {
|
|
|
3525
3639
|
});
|
|
3526
3640
|
} catch (err) {
|
|
3527
3641
|
this._ready.wake(err);
|
|
3528
|
-
|
|
3642
|
+
log15.catch(err, {}, {
|
|
3529
3643
|
file: "worker-runtime.ts",
|
|
3530
3644
|
line: 68,
|
|
3531
3645
|
scope: this,
|
|
@@ -3577,27 +3691,27 @@ var WorkerRuntime = class {
|
|
|
3577
3691
|
};
|
|
3578
3692
|
|
|
3579
3693
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
3580
|
-
import
|
|
3581
|
-
import { Trigger as
|
|
3582
|
-
import { Invitation as
|
|
3694
|
+
import assert13 from "@dxos/node-std/assert";
|
|
3695
|
+
import { Trigger as Trigger8 } from "@dxos/async";
|
|
3696
|
+
import { Invitation as Invitation4 } from "@dxos/client";
|
|
3583
3697
|
import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
|
|
3584
3698
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
3585
3699
|
import { valueEncoding, MetadataStore, SpaceManager, DataServiceSubscriptions, SnapshotStore } from "@dxos/echo-pipeline";
|
|
3586
3700
|
import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
3587
3701
|
import { Keyring } from "@dxos/keyring";
|
|
3588
|
-
import { PublicKey as
|
|
3589
|
-
import { log as
|
|
3590
|
-
import { trace as
|
|
3702
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3703
|
+
import { log as log16 } from "@dxos/log";
|
|
3704
|
+
import { trace as trace5 } from "@dxos/protocols";
|
|
3591
3705
|
var ServiceContext = class {
|
|
3592
3706
|
// prettier-ignore
|
|
3593
3707
|
constructor(storage, networkManager, modelFactory) {
|
|
3594
3708
|
this.storage = storage;
|
|
3595
3709
|
this.networkManager = networkManager;
|
|
3596
3710
|
this.modelFactory = modelFactory;
|
|
3597
|
-
this.initialized = new
|
|
3711
|
+
this.initialized = new Trigger8();
|
|
3598
3712
|
this.dataServiceSubscriptions = new DataServiceSubscriptions();
|
|
3599
3713
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
3600
|
-
this._instanceId =
|
|
3714
|
+
this._instanceId = PublicKey9.random().toHex();
|
|
3601
3715
|
networkManager._traceParent = this._instanceId;
|
|
3602
3716
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
3603
3717
|
this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
|
|
@@ -3620,13 +3734,13 @@ var ServiceContext = class {
|
|
|
3620
3734
|
this.identityManager._traceParent = this._instanceId;
|
|
3621
3735
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
3622
3736
|
this.invitations._traceParent = this._instanceId;
|
|
3623
|
-
this._handlerFactories.set(
|
|
3737
|
+
this._handlerFactories.set(Invitation4.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => {
|
|
3624
3738
|
var _a;
|
|
3625
3739
|
return (_a = this.identityManager.identity) != null ? _a : failUndefined2();
|
|
3626
3740
|
}, this._acceptIdentity.bind(this)));
|
|
3627
3741
|
}
|
|
3628
3742
|
async open() {
|
|
3629
|
-
|
|
3743
|
+
log16.trace("dxos.sdk.service-context", trace5.begin({
|
|
3630
3744
|
id: this._instanceId
|
|
3631
3745
|
}), {
|
|
3632
3746
|
file: "service-context.ts",
|
|
@@ -3634,7 +3748,7 @@ var ServiceContext = class {
|
|
|
3634
3748
|
scope: this,
|
|
3635
3749
|
callSite: (f, a) => f(...a)
|
|
3636
3750
|
});
|
|
3637
|
-
|
|
3751
|
+
log16("opening...", {}, {
|
|
3638
3752
|
file: "service-context.ts",
|
|
3639
3753
|
line: 117,
|
|
3640
3754
|
scope: this,
|
|
@@ -3646,7 +3760,7 @@ var ServiceContext = class {
|
|
|
3646
3760
|
if (this.identityManager.identity) {
|
|
3647
3761
|
await this._initialize();
|
|
3648
3762
|
}
|
|
3649
|
-
|
|
3763
|
+
log16("opened", {}, {
|
|
3650
3764
|
file: "service-context.ts",
|
|
3651
3765
|
line: 124,
|
|
3652
3766
|
scope: this,
|
|
@@ -3655,7 +3769,7 @@ var ServiceContext = class {
|
|
|
3655
3769
|
}
|
|
3656
3770
|
async close() {
|
|
3657
3771
|
var _a, _b;
|
|
3658
|
-
|
|
3772
|
+
log16("closing...", {}, {
|
|
3659
3773
|
file: "service-context.ts",
|
|
3660
3774
|
line: 128,
|
|
3661
3775
|
scope: this,
|
|
@@ -3668,13 +3782,13 @@ var ServiceContext = class {
|
|
|
3668
3782
|
await this.feedStore.close();
|
|
3669
3783
|
await this.networkManager.close();
|
|
3670
3784
|
this.dataServiceSubscriptions.clear();
|
|
3671
|
-
|
|
3785
|
+
log16("closed", {}, {
|
|
3672
3786
|
file: "service-context.ts",
|
|
3673
3787
|
line: 136,
|
|
3674
3788
|
scope: this,
|
|
3675
3789
|
callSite: (f, a) => f(...a)
|
|
3676
3790
|
});
|
|
3677
|
-
|
|
3791
|
+
log16.trace("dxos.sdk.service-context", trace5.end({
|
|
3678
3792
|
id: this._instanceId
|
|
3679
3793
|
}), {
|
|
3680
3794
|
file: "service-context.ts",
|
|
@@ -3690,7 +3804,7 @@ var ServiceContext = class {
|
|
|
3690
3804
|
}
|
|
3691
3805
|
getInvitationHandler(invitation) {
|
|
3692
3806
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
3693
|
-
|
|
3807
|
+
assert13(factory, `Unknown invitation kind: ${invitation.kind}`);
|
|
3694
3808
|
return factory(invitation);
|
|
3695
3809
|
}
|
|
3696
3810
|
async _acceptIdentity(params) {
|
|
@@ -3701,7 +3815,7 @@ var ServiceContext = class {
|
|
|
3701
3815
|
// Called when identity is created.
|
|
3702
3816
|
async _initialize() {
|
|
3703
3817
|
var _a;
|
|
3704
|
-
|
|
3818
|
+
log16("initializing spaces...", {}, {
|
|
3705
3819
|
file: "service-context.ts",
|
|
3706
3820
|
line: 163,
|
|
3707
3821
|
scope: this,
|
|
@@ -3724,8 +3838,8 @@ var ServiceContext = class {
|
|
|
3724
3838
|
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.feedStore, this.snapshotStore);
|
|
3725
3839
|
this.dataSpaceManager._traceParent = this._instanceId;
|
|
3726
3840
|
await this.dataSpaceManager.open();
|
|
3727
|
-
this._handlerFactories.set(
|
|
3728
|
-
|
|
3841
|
+
this._handlerFactories.set(Invitation4.Kind.SPACE, (invitation) => {
|
|
3842
|
+
assert13(this.dataSpaceManager, "dataSpaceManager not initialized yet");
|
|
3729
3843
|
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
3730
3844
|
});
|
|
3731
3845
|
this.initialized.wake();
|
|
@@ -3739,7 +3853,7 @@ var ServiceContext = class {
|
|
|
3739
3853
|
return;
|
|
3740
3854
|
}
|
|
3741
3855
|
if (!this.dataSpaceManager) {
|
|
3742
|
-
|
|
3856
|
+
log16("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
3743
3857
|
details: assertion
|
|
3744
3858
|
}, {
|
|
3745
3859
|
file: "service-context.ts",
|
|
@@ -3750,7 +3864,7 @@ var ServiceContext = class {
|
|
|
3750
3864
|
return;
|
|
3751
3865
|
}
|
|
3752
3866
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
3753
|
-
|
|
3867
|
+
log16("space already exists, ignoring space admission", {
|
|
3754
3868
|
details: assertion
|
|
3755
3869
|
}, {
|
|
3756
3870
|
file: "service-context.ts",
|
|
@@ -3761,7 +3875,7 @@ var ServiceContext = class {
|
|
|
3761
3875
|
return;
|
|
3762
3876
|
}
|
|
3763
3877
|
try {
|
|
3764
|
-
|
|
3878
|
+
log16("accepting space recorded in halo", {
|
|
3765
3879
|
details: assertion
|
|
3766
3880
|
}, {
|
|
3767
3881
|
file: "service-context.ts",
|
|
@@ -3774,7 +3888,7 @@ var ServiceContext = class {
|
|
|
3774
3888
|
genesisFeedKey: assertion.genesisFeedKey
|
|
3775
3889
|
});
|
|
3776
3890
|
} catch (err) {
|
|
3777
|
-
|
|
3891
|
+
log16.catch(err, {}, {
|
|
3778
3892
|
file: "service-context.ts",
|
|
3779
3893
|
line: 220,
|
|
3780
3894
|
scope: this,
|
|
@@ -3822,10 +3936,10 @@ var ClientServicesHost = class {
|
|
|
3822
3936
|
// TODO(wittjosiah): Turn this on by default.
|
|
3823
3937
|
lockKey
|
|
3824
3938
|
} = {}) {
|
|
3825
|
-
this._statusUpdate = new
|
|
3939
|
+
this._statusUpdate = new Event8();
|
|
3826
3940
|
this._opening = false;
|
|
3827
3941
|
this._open = false;
|
|
3828
|
-
this._instanceId =
|
|
3942
|
+
this._instanceId = PublicKey10.random().toHex();
|
|
3829
3943
|
this._storage = storage;
|
|
3830
3944
|
this._modelFactory = modelFactory;
|
|
3831
3945
|
if (config) {
|
|
@@ -3879,16 +3993,16 @@ var ClientServicesHost = class {
|
|
|
3879
3993
|
* Can only be called once.
|
|
3880
3994
|
*/
|
|
3881
3995
|
initialize({ config, networkManager }) {
|
|
3882
|
-
|
|
3996
|
+
assert14(!this._open, "service host is open");
|
|
3883
3997
|
if (config) {
|
|
3884
|
-
|
|
3998
|
+
assert14(!this._config, "config already set");
|
|
3885
3999
|
this._config = config;
|
|
3886
4000
|
if (!this._storage) {
|
|
3887
4001
|
this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
|
|
3888
4002
|
}
|
|
3889
4003
|
}
|
|
3890
4004
|
if (networkManager) {
|
|
3891
|
-
|
|
4005
|
+
assert14(!this._networkManager, "network manager already set");
|
|
3892
4006
|
this._networkManager = networkManager;
|
|
3893
4007
|
}
|
|
3894
4008
|
}
|
|
@@ -3897,7 +4011,7 @@ var ClientServicesHost = class {
|
|
|
3897
4011
|
if (this._open) {
|
|
3898
4012
|
return;
|
|
3899
4013
|
}
|
|
3900
|
-
|
|
4014
|
+
log17.trace("dxos.sdk.client-services-host", trace6.begin({
|
|
3901
4015
|
id: this._instanceId
|
|
3902
4016
|
}), {
|
|
3903
4017
|
file: "service-host.ts",
|
|
@@ -3905,11 +4019,11 @@ var ClientServicesHost = class {
|
|
|
3905
4019
|
scope: this,
|
|
3906
4020
|
callSite: (f, a) => f(...a)
|
|
3907
4021
|
});
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
4022
|
+
assert14(this._config, "config not set");
|
|
4023
|
+
assert14(this._storage, "storage not set");
|
|
4024
|
+
assert14(this._networkManager, "network manager not set");
|
|
3911
4025
|
this._opening = true;
|
|
3912
|
-
|
|
4026
|
+
log17("opening...", {
|
|
3913
4027
|
lockKey: (_a = this._resourceLock) == null ? void 0 : _a.lockKey
|
|
3914
4028
|
}, {
|
|
3915
4029
|
file: "service-host.ts",
|
|
@@ -3943,7 +4057,7 @@ var ClientServicesHost = class {
|
|
|
3943
4057
|
this._open = true;
|
|
3944
4058
|
this._statusUpdate.emit();
|
|
3945
4059
|
const deviceKey = (_c = this._serviceContext.identityManager.identity) == null ? void 0 : _c.deviceKey;
|
|
3946
|
-
|
|
4060
|
+
log17("opened", {
|
|
3947
4061
|
deviceKey
|
|
3948
4062
|
}, {
|
|
3949
4063
|
file: "service-host.ts",
|
|
@@ -3958,7 +4072,7 @@ var ClientServicesHost = class {
|
|
|
3958
4072
|
return;
|
|
3959
4073
|
}
|
|
3960
4074
|
const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
|
|
3961
|
-
|
|
4075
|
+
log17("closing...", {
|
|
3962
4076
|
deviceKey
|
|
3963
4077
|
}, {
|
|
3964
4078
|
file: "service-host.ts",
|
|
@@ -3972,7 +4086,7 @@ var ClientServicesHost = class {
|
|
|
3972
4086
|
await this._serviceContext.close();
|
|
3973
4087
|
this._open = false;
|
|
3974
4088
|
this._statusUpdate.emit();
|
|
3975
|
-
|
|
4089
|
+
log17("closed", {
|
|
3976
4090
|
deviceKey
|
|
3977
4091
|
}, {
|
|
3978
4092
|
file: "service-host.ts",
|
|
@@ -3980,7 +4094,7 @@ var ClientServicesHost = class {
|
|
|
3980
4094
|
scope: this,
|
|
3981
4095
|
callSite: (f, a) => f(...a)
|
|
3982
4096
|
});
|
|
3983
|
-
|
|
4097
|
+
log17.trace("dxos.sdk.client-services-host", trace6.end({
|
|
3984
4098
|
id: this._instanceId
|
|
3985
4099
|
}), {
|
|
3986
4100
|
file: "service-host.ts",
|
|
@@ -3991,7 +4105,7 @@ var ClientServicesHost = class {
|
|
|
3991
4105
|
}
|
|
3992
4106
|
async reset() {
|
|
3993
4107
|
var _a;
|
|
3994
|
-
|
|
4108
|
+
log17("resetting...", {}, {
|
|
3995
4109
|
file: "service-host.ts",
|
|
3996
4110
|
line: 240,
|
|
3997
4111
|
scope: this,
|
|
@@ -3999,7 +4113,7 @@ var ClientServicesHost = class {
|
|
|
3999
4113
|
});
|
|
4000
4114
|
await ((_a = this._serviceContext) == null ? void 0 : _a.close());
|
|
4001
4115
|
await this._storage.reset();
|
|
4002
|
-
|
|
4116
|
+
log17("reset", {}, {
|
|
4003
4117
|
file: "service-host.ts",
|
|
4004
4118
|
line: 243,
|
|
4005
4119
|
scope: this,
|
|
@@ -4032,7 +4146,7 @@ var LocalClientServices = class {
|
|
|
4032
4146
|
|
|
4033
4147
|
// packages/sdk/client-services/src/packlets/services/utils.ts
|
|
4034
4148
|
import { Config } from "@dxos/config";
|
|
4035
|
-
import { log as
|
|
4149
|
+
import { log as log18 } from "@dxos/log";
|
|
4036
4150
|
import { MemorySignalManager as MemorySignalManager2, MemorySignalManagerContext as MemorySignalManagerContext2, WebsocketSignalManager as WebsocketSignalManager2 } from "@dxos/messaging";
|
|
4037
4151
|
import { createWebRTCTransportFactory, MemoryTransportFactory, NetworkManager as NetworkManager2 } from "@dxos/network-manager";
|
|
4038
4152
|
var fromHost = (config = new Config()) => {
|
|
@@ -4042,11 +4156,9 @@ var fromHost = (config = new Config()) => {
|
|
|
4042
4156
|
});
|
|
4043
4157
|
};
|
|
4044
4158
|
var createNetworkManager = (config, options = {}) => {
|
|
4045
|
-
const
|
|
4046
|
-
if (
|
|
4047
|
-
const { log: log1 = true, signalManager = new WebsocketSignalManager2(
|
|
4048
|
-
signalServer
|
|
4049
|
-
]), transportFactory = createWebRTCTransportFactory({
|
|
4159
|
+
const signals = config.get("runtime.services.signaling");
|
|
4160
|
+
if (signals) {
|
|
4161
|
+
const { log: log1 = true, signalManager = new WebsocketSignalManager2(signals), transportFactory = createWebRTCTransportFactory({
|
|
4050
4162
|
iceServers: config.get("runtime.services.ice")
|
|
4051
4163
|
}) } = options;
|
|
4052
4164
|
return new NetworkManager2({
|
|
@@ -4055,7 +4167,7 @@ var createNetworkManager = (config, options = {}) => {
|
|
|
4055
4167
|
transportFactory
|
|
4056
4168
|
});
|
|
4057
4169
|
}
|
|
4058
|
-
|
|
4170
|
+
log18.warn("P2P network is not configured.", {}, {
|
|
4059
4171
|
file: "utils.ts",
|
|
4060
4172
|
line: 48,
|
|
4061
4173
|
scope: void 0,
|
|
@@ -4105,7 +4217,7 @@ var IFrameHostRuntime = class {
|
|
|
4105
4217
|
}
|
|
4106
4218
|
]
|
|
4107
4219
|
});
|
|
4108
|
-
this._ready = new
|
|
4220
|
+
this._ready = new Trigger9();
|
|
4109
4221
|
this._configProvider = configProvider;
|
|
4110
4222
|
this._appPort = appPort;
|
|
4111
4223
|
this._shellPort = shellPort;
|
|
@@ -4121,7 +4233,7 @@ var IFrameHostRuntime = class {
|
|
|
4121
4233
|
}
|
|
4122
4234
|
async start() {
|
|
4123
4235
|
var _a;
|
|
4124
|
-
|
|
4236
|
+
log19("starting...", {}, {
|
|
4125
4237
|
file: "iframe-host-runtime.ts",
|
|
4126
4238
|
line: 75,
|
|
4127
4239
|
scope: this,
|
|
@@ -4129,15 +4241,13 @@ var IFrameHostRuntime = class {
|
|
|
4129
4241
|
});
|
|
4130
4242
|
try {
|
|
4131
4243
|
this._config = await getAsyncValue(this._configProvider);
|
|
4132
|
-
const
|
|
4244
|
+
const signals = this._config.get("runtime.services.signaling");
|
|
4133
4245
|
this._clientServices = new LocalClientServices({
|
|
4134
4246
|
lockKey: LOCK_KEY,
|
|
4135
4247
|
config: this._config,
|
|
4136
4248
|
networkManager: new NetworkManager3({
|
|
4137
4249
|
log: true,
|
|
4138
|
-
signalManager:
|
|
4139
|
-
signalServer
|
|
4140
|
-
]) : new MemorySignalManager3(new MemorySignalManagerContext3()),
|
|
4250
|
+
signalManager: signals ? new WebsocketSignalManager3(signals) : new MemorySignalManager3(new MemorySignalManagerContext3()),
|
|
4141
4251
|
transportFactory: this._transportFactory
|
|
4142
4252
|
})
|
|
4143
4253
|
});
|
|
@@ -4172,7 +4282,7 @@ var IFrameHostRuntime = class {
|
|
|
4172
4282
|
(_a = this._shellRuntime) == null ? void 0 : _a.open()
|
|
4173
4283
|
]);
|
|
4174
4284
|
this._ready.wake(void 0);
|
|
4175
|
-
|
|
4285
|
+
log19("started", {}, {
|
|
4176
4286
|
file: "iframe-host-runtime.ts",
|
|
4177
4287
|
line: 118,
|
|
4178
4288
|
scope: this,
|
|
@@ -4180,7 +4290,7 @@ var IFrameHostRuntime = class {
|
|
|
4180
4290
|
});
|
|
4181
4291
|
} catch (err) {
|
|
4182
4292
|
this._ready.wake(err);
|
|
4183
|
-
|
|
4293
|
+
log19.catch(err, {}, {
|
|
4184
4294
|
file: "iframe-host-runtime.ts",
|
|
4185
4295
|
line: 121,
|
|
4186
4296
|
scope: this,
|
|
@@ -4190,7 +4300,7 @@ var IFrameHostRuntime = class {
|
|
|
4190
4300
|
}
|
|
4191
4301
|
async stop() {
|
|
4192
4302
|
var _a;
|
|
4193
|
-
|
|
4303
|
+
log19("stopping...", {}, {
|
|
4194
4304
|
file: "iframe-host-runtime.ts",
|
|
4195
4305
|
line: 126,
|
|
4196
4306
|
scope: this,
|
|
@@ -4199,7 +4309,7 @@ var IFrameHostRuntime = class {
|
|
|
4199
4309
|
await this._clientRpc.close();
|
|
4200
4310
|
await this._clientServices.close();
|
|
4201
4311
|
await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
|
|
4202
|
-
|
|
4312
|
+
log19("stopped", {}, {
|
|
4203
4313
|
file: "iframe-host-runtime.ts",
|
|
4204
4314
|
line: 130,
|
|
4205
4315
|
scope: this,
|
|
@@ -4245,4 +4355,4 @@ export {
|
|
|
4245
4355
|
LocalClientServices,
|
|
4246
4356
|
fromHost
|
|
4247
4357
|
};
|
|
4248
|
-
//# sourceMappingURL=chunk-
|
|
4358
|
+
//# sourceMappingURL=chunk-LGMYP2WL.mjs.map
|