@dxos/client-services 0.1.56-main.e47dfd1 → 0.1.56-main.e79d64a
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-CSJSC47N.mjs → chunk-T32PP5QD.mjs} +1284 -625
- package/dist/lib/browser/chunk-T32PP5QD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +70 -54
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +42 -48
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +1439 -767
- 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 +1590 -936
- package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
- package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +7 -3
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +3 -2
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +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.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +6 -2
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/diagnostics.d.ts +46 -0
- package/dist/types/src/packlets/services/diagnostics.d.ts.map +1 -0
- package/dist/types/src/packlets/services/index.d.ts +1 -0
- package/dist/types/src/packlets/services/index.d.ts.map +1 -1
- package/dist/types/src/packlets/services/platform.d.ts +16 -0
- package/dist/types/src/packlets/services/platform.d.ts.map +1 -0
- package/dist/types/src/packlets/services/service-context.d.ts +2 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +7 -3
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/services/util.d.ts +6 -0
- package/dist/types/src/packlets/services/util.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +12 -2
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +2 -0
- package/dist/types/src/version.d.ts.map +1 -0
- package/package.json +34 -33
- package/src/packlets/devices/devices-service.test.ts +2 -1
- package/src/packlets/identity/authenticator.test.ts +2 -2
- package/src/packlets/identity/identity-manager.test.ts +15 -3
- package/src/packlets/identity/identity-manager.ts +28 -8
- package/src/packlets/identity/identity-service.test.ts +17 -2
- package/src/packlets/identity/identity-service.ts +24 -16
- package/src/packlets/identity/identity.test.ts +7 -6
- package/src/packlets/identity/identity.ts +9 -5
- package/src/packlets/invitations/device-invitation-protocol.test.ts +2 -1
- package/src/packlets/invitations/device-invitation-protocol.ts +1 -2
- package/src/packlets/invitations/invitation-extension.ts +1 -2
- package/src/packlets/invitations/invitations-handler.ts +3 -2
- package/src/packlets/invitations/invitations-service.ts +1 -2
- package/src/packlets/invitations/space-invitation-protocol.ts +1 -2
- package/src/packlets/locks/node.ts +1 -1
- package/src/packlets/logging/logging-service.ts +17 -9
- package/src/packlets/network/network-service.test.ts +2 -1
- package/src/packlets/services/client-rpc-server.ts +4 -4
- package/src/packlets/services/diagnostics.ts +212 -0
- package/src/packlets/services/index.ts +1 -0
- package/src/packlets/services/platform.ts +48 -0
- package/src/packlets/services/service-context.test.ts +59 -0
- package/src/packlets/services/service-context.ts +21 -15
- package/src/packlets/services/service-host.test.ts +12 -11
- package/src/packlets/services/service-host.ts +39 -20
- package/src/packlets/services/service-registry.test.ts +3 -1
- package/src/packlets/services/util.ts +33 -0
- package/src/packlets/spaces/data-space-manager.test.ts +80 -22
- package/src/packlets/spaces/data-space-manager.ts +7 -4
- package/src/packlets/spaces/data-space.ts +17 -5
- package/src/packlets/spaces/notarization-plugin.ts +1 -2
- package/src/packlets/spaces/spaces-service.test.ts +2 -1
- package/src/packlets/spaces/spaces-service.ts +19 -13
- package/src/packlets/system/system-service.test.ts +1 -0
- package/src/packlets/system/system-service.ts +34 -2
- package/src/packlets/testing/invitation-utils.ts +1 -2
- package/src/packlets/testing/test-builder.ts +1 -1
- package/src/packlets/vault/iframe-host-runtime.ts +2 -1
- package/src/packlets/vault/shell-runtime.ts +1 -2
- package/src/packlets/vault/worker-runtime.ts +3 -2
- package/src/packlets/vault/worker-session.ts +7 -3
- package/src/version.ts +1 -0
- package/dist/lib/browser/chunk-CSJSC47N.mjs.map +0 -7
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// packages/sdk/client-services/src/packlets/testing/index.ts
|
|
@@ -61,37 +51,199 @@ var createMockCredential = async ({ signer, issuer }) => (0, import_credentials.
|
|
|
61
51
|
});
|
|
62
52
|
|
|
63
53
|
// packages/sdk/client-services/src/packlets/testing/invitation-utils.ts
|
|
64
|
-
var import_tiny_invariant14 = __toESM(require("tiny-invariant"));
|
|
65
54
|
var import_async18 = require("@dxos/async");
|
|
66
|
-
var
|
|
55
|
+
var import_invariant15 = require("@dxos/invariant");
|
|
56
|
+
var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
|
|
67
57
|
|
|
68
58
|
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
69
59
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
70
60
|
var import_debug = require("@dxos/debug");
|
|
71
61
|
var import_rpc = require("@dxos/rpc");
|
|
72
62
|
|
|
63
|
+
// packages/sdk/client-services/src/packlets/services/diagnostics.ts
|
|
64
|
+
var import_codec_protobuf2 = require("@dxos/codec-protobuf");
|
|
65
|
+
var import_credentials2 = require("@dxos/credentials");
|
|
66
|
+
var import_document_model = require("@dxos/document-model");
|
|
67
|
+
var import_echo_db = require("@dxos/echo-db");
|
|
68
|
+
var import_invariant = require("@dxos/invariant");
|
|
69
|
+
var import_log = require("@dxos/log");
|
|
70
|
+
var import_protocols = require("@dxos/protocols");
|
|
71
|
+
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
72
|
+
|
|
73
|
+
// packages/sdk/client-services/src/version.ts
|
|
74
|
+
var DXOS_VERSION = "0.1.56-main.e79d64a";
|
|
75
|
+
|
|
76
|
+
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
77
|
+
var getPlatform = () => {
|
|
78
|
+
if (process.browser) {
|
|
79
|
+
if (typeof window !== "undefined") {
|
|
80
|
+
const { userAgent } = window.navigator;
|
|
81
|
+
return {
|
|
82
|
+
type: "browser",
|
|
83
|
+
userAgent,
|
|
84
|
+
uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
|
|
85
|
+
};
|
|
86
|
+
} else {
|
|
87
|
+
return {
|
|
88
|
+
type: "shared-worker",
|
|
89
|
+
uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const { platform, version, arch } = process;
|
|
94
|
+
return {
|
|
95
|
+
type: "node",
|
|
96
|
+
platform: `${platform} ${version} ${arch}`,
|
|
97
|
+
runtime: process.version,
|
|
98
|
+
uptime: Math.floor(process.uptime()),
|
|
99
|
+
memory: process.memoryUsage()
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// packages/sdk/client-services/src/packlets/services/diagnostics.ts
|
|
105
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
|
|
106
|
+
var DEFAULT_TIMEOUT = 1e3;
|
|
107
|
+
var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
108
|
+
const diagnostics = {
|
|
109
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
110
|
+
platform: getPlatform(),
|
|
111
|
+
client: {
|
|
112
|
+
version: DXOS_VERSION,
|
|
113
|
+
storage: {
|
|
114
|
+
version: import_protocols.STORAGE_VERSION
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
{
|
|
119
|
+
(0, import_invariant.invariant)(clientServices.LoggingService, "SystemService is not available.", {
|
|
120
|
+
F: __dxlog_file,
|
|
121
|
+
L: 88,
|
|
122
|
+
S: void 0,
|
|
123
|
+
A: [
|
|
124
|
+
"clientServices.LoggingService",
|
|
125
|
+
"'SystemService is not available.'"
|
|
126
|
+
]
|
|
127
|
+
});
|
|
128
|
+
diagnostics.metrics = await (0, import_codec_protobuf2.getFirstStreamValue)(clientServices.LoggingService.queryMetrics({}), {
|
|
129
|
+
timeout: DEFAULT_TIMEOUT
|
|
130
|
+
}).catch(() => void 0);
|
|
131
|
+
}
|
|
132
|
+
const identity = serviceContext.identityManager.identity;
|
|
133
|
+
if (identity) {
|
|
134
|
+
diagnostics.identity = {
|
|
135
|
+
identityKey: identity.identityKey,
|
|
136
|
+
spaceKey: identity.space.key,
|
|
137
|
+
profile: identity.profileDocument
|
|
138
|
+
};
|
|
139
|
+
const { devices } = await (0, import_codec_protobuf2.getFirstStreamValue)(clientServices.DevicesService.queryDevices(), {
|
|
140
|
+
timeout: DEFAULT_TIMEOUT
|
|
141
|
+
}).catch(() => void 0) ?? {};
|
|
142
|
+
diagnostics.devices = devices;
|
|
143
|
+
if (serviceContext.dataSpaceManager) {
|
|
144
|
+
diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
|
|
145
|
+
}
|
|
146
|
+
const { feeds = [] } = await (0, import_codec_protobuf2.getFirstStreamValue)(clientServices.DevtoolsHost.subscribeToFeeds({}), {
|
|
147
|
+
timeout: DEFAULT_TIMEOUT
|
|
148
|
+
}).catch(() => void 0) ?? {};
|
|
149
|
+
diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
|
|
150
|
+
feedKey,
|
|
151
|
+
bytes,
|
|
152
|
+
length
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
diagnostics.config = config.values;
|
|
156
|
+
return diagnostics;
|
|
157
|
+
};
|
|
158
|
+
var getProperties = (space) => {
|
|
159
|
+
let properties = {};
|
|
160
|
+
try {
|
|
161
|
+
const propertiesItem = space.dataPipeline.itemManager.items.find((item) => item.modelMeta?.type === import_document_model.DocumentModel.meta.type && item.state?.type === import_echo_db.TYPE_PROPERTIES);
|
|
162
|
+
const state = propertiesItem?.state;
|
|
163
|
+
properties = state?.data;
|
|
164
|
+
} catch (err) {
|
|
165
|
+
import_log.log.warn(err.message, void 0, {
|
|
166
|
+
F: __dxlog_file,
|
|
167
|
+
L: 145,
|
|
168
|
+
S: void 0,
|
|
169
|
+
C: (f, a) => f(...a)
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return properties;
|
|
173
|
+
};
|
|
174
|
+
var getSpaceStats = async (space) => {
|
|
175
|
+
const stats = {
|
|
176
|
+
key: space.key,
|
|
177
|
+
metrics: space.metrics,
|
|
178
|
+
epochs: space.inner.spaceState.credentials.filter((0, import_credentials2.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
|
|
179
|
+
...credential.subject.assertion,
|
|
180
|
+
id: credential.id
|
|
181
|
+
})),
|
|
182
|
+
members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
|
|
183
|
+
identity: {
|
|
184
|
+
identityKey: member.key,
|
|
185
|
+
profile: {
|
|
186
|
+
displayName: member.assertion.profile?.displayName
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services.SpaceMember.PresenceState.ONLINE : import_services.SpaceMember.PresenceState.OFFLINE
|
|
190
|
+
})),
|
|
191
|
+
pipeline: {
|
|
192
|
+
// TODO(burdon): Pick properties from credentials if needed.
|
|
193
|
+
// currentEpoch: space.dataPipeline.currentEpoch,
|
|
194
|
+
// appliedEpoch: space.dataPipeline.appliedEpoch,
|
|
195
|
+
controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
|
|
196
|
+
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
197
|
+
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
198
|
+
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
|
|
199
|
+
// TODO(burdon): Empty?
|
|
200
|
+
dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
|
|
201
|
+
startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
|
|
202
|
+
currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
|
|
203
|
+
targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
|
|
204
|
+
totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
if (space.dataPipeline.itemManager) {
|
|
208
|
+
Object.assign(stats, {
|
|
209
|
+
properties: getProperties(space),
|
|
210
|
+
db: {
|
|
211
|
+
objects: space.dataPipeline.itemManager.entities.size
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (stats.metrics) {
|
|
216
|
+
const { open, ready } = stats.metrics;
|
|
217
|
+
stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
|
|
218
|
+
}
|
|
219
|
+
return stats;
|
|
220
|
+
};
|
|
221
|
+
|
|
73
222
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
74
|
-
var import_tiny_invariant11 = __toESM(require("tiny-invariant"));
|
|
75
223
|
var import_async11 = require("@dxos/async");
|
|
76
|
-
var
|
|
224
|
+
var import_context8 = require("@dxos/context");
|
|
225
|
+
var import_credentials15 = require("@dxos/credentials");
|
|
77
226
|
var import_debug7 = require("@dxos/debug");
|
|
78
227
|
var import_echo_pipeline3 = require("@dxos/echo-pipeline");
|
|
79
228
|
var import_feed_store3 = require("@dxos/feed-store");
|
|
229
|
+
var import_invariant12 = require("@dxos/invariant");
|
|
80
230
|
var import_keyring = require("@dxos/keyring");
|
|
81
231
|
var import_keys8 = require("@dxos/keys");
|
|
82
|
-
var
|
|
83
|
-
var
|
|
84
|
-
var
|
|
232
|
+
var import_log13 = require("@dxos/log");
|
|
233
|
+
var import_protocols9 = require("@dxos/protocols");
|
|
234
|
+
var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
|
|
85
235
|
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
236
|
+
var import_tracing3 = require("@dxos/tracing");
|
|
237
|
+
var import_util6 = require("@dxos/util");
|
|
86
238
|
|
|
87
239
|
// packages/sdk/client-services/src/packlets/identity/authenticator.ts
|
|
88
240
|
var import_async = require("@dxos/async");
|
|
89
241
|
var import_context = require("@dxos/context");
|
|
90
|
-
var
|
|
91
|
-
var
|
|
92
|
-
var
|
|
93
|
-
var
|
|
94
|
-
var Credential =
|
|
242
|
+
var import_credentials3 = require("@dxos/credentials");
|
|
243
|
+
var import_log2 = require("@dxos/log");
|
|
244
|
+
var import_protocols2 = require("@dxos/protocols");
|
|
245
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
|
|
246
|
+
var Credential = import_protocols2.schema.getCodecForType("dxos.halo.credentials.Credential");
|
|
95
247
|
var createAuthProvider = (signer) => async (nonce) => {
|
|
96
248
|
const credential = await signer.createCredential({
|
|
97
249
|
assertion: {
|
|
@@ -114,20 +266,20 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
114
266
|
get verifier() {
|
|
115
267
|
return async (nonce, auth) => {
|
|
116
268
|
const credential = Credential.decode(auth);
|
|
117
|
-
(0,
|
|
269
|
+
(0, import_log2.log)("authenticating...", {
|
|
118
270
|
credential
|
|
119
271
|
}, {
|
|
120
|
-
F:
|
|
272
|
+
F: __dxlog_file2,
|
|
121
273
|
L: 59,
|
|
122
274
|
S: this,
|
|
123
275
|
C: (f, a) => f(...a)
|
|
124
276
|
});
|
|
125
|
-
const result = await (0,
|
|
277
|
+
const result = await (0, import_credentials3.verifyCredential)(credential);
|
|
126
278
|
if (result.kind === "fail") {
|
|
127
|
-
(0,
|
|
279
|
+
(0, import_log2.log)("Invalid credential", {
|
|
128
280
|
result
|
|
129
281
|
}, {
|
|
130
|
-
F:
|
|
282
|
+
F: __dxlog_file2,
|
|
131
283
|
L: 63,
|
|
132
284
|
S: this,
|
|
133
285
|
C: (f, a) => f(...a)
|
|
@@ -135,11 +287,11 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
135
287
|
return false;
|
|
136
288
|
}
|
|
137
289
|
if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
|
|
138
|
-
(0,
|
|
290
|
+
(0, import_log2.log)("Invalid nonce", {
|
|
139
291
|
nonce,
|
|
140
292
|
credential
|
|
141
293
|
}, {
|
|
142
|
-
F:
|
|
294
|
+
F: __dxlog_file2,
|
|
143
295
|
L: 68,
|
|
144
296
|
S: this,
|
|
145
297
|
C: (f, a) => f(...a)
|
|
@@ -147,10 +299,10 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
147
299
|
return false;
|
|
148
300
|
}
|
|
149
301
|
if (this._isTrustedKey(credential.issuer)) {
|
|
150
|
-
(0,
|
|
302
|
+
(0, import_log2.log)("key is not currently in trusted set, waiting...", {
|
|
151
303
|
key: credential.issuer
|
|
152
304
|
}, {
|
|
153
|
-
F:
|
|
305
|
+
F: __dxlog_file2,
|
|
154
306
|
L: 73,
|
|
155
307
|
S: this,
|
|
156
308
|
C: (f, a) => f(...a)
|
|
@@ -163,20 +315,20 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
163
315
|
});
|
|
164
316
|
const clear = this._params.update.on(this._ctx, () => {
|
|
165
317
|
if (this._isTrustedKey(credential.issuer)) {
|
|
166
|
-
(0,
|
|
318
|
+
(0, import_log2.log)("auth success", {
|
|
167
319
|
key: credential.issuer
|
|
168
320
|
}, {
|
|
169
|
-
F:
|
|
321
|
+
F: __dxlog_file2,
|
|
170
322
|
L: 84,
|
|
171
323
|
S: this,
|
|
172
324
|
C: (f, a) => f(...a)
|
|
173
325
|
});
|
|
174
326
|
trigger.wake(true);
|
|
175
327
|
} else {
|
|
176
|
-
(0,
|
|
328
|
+
(0, import_log2.log)("key is not currently in trusted set, waiting...", {
|
|
177
329
|
key: credential.issuer
|
|
178
330
|
}, {
|
|
179
|
-
F:
|
|
331
|
+
F: __dxlog_file2,
|
|
180
332
|
L: 87,
|
|
181
333
|
S: this,
|
|
182
334
|
C: (f, a) => f(...a)
|
|
@@ -187,7 +339,7 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
187
339
|
return await trigger.wait({
|
|
188
340
|
timeout: this._params.authTimeout
|
|
189
341
|
});
|
|
190
|
-
} catch
|
|
342
|
+
} catch {
|
|
191
343
|
return false;
|
|
192
344
|
} finally {
|
|
193
345
|
clear();
|
|
@@ -201,28 +353,39 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
201
353
|
};
|
|
202
354
|
|
|
203
355
|
// packages/sdk/client-services/src/packlets/identity/identity.ts
|
|
204
|
-
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
205
356
|
var import_async2 = require("@dxos/async");
|
|
206
357
|
var import_client_protocol = require("@dxos/client-protocol");
|
|
207
|
-
var
|
|
358
|
+
var import_credentials4 = require("@dxos/credentials");
|
|
208
359
|
var import_debug2 = require("@dxos/debug");
|
|
209
360
|
var import_feed_store = require("@dxos/feed-store");
|
|
210
|
-
var
|
|
211
|
-
var
|
|
212
|
-
var
|
|
213
|
-
var
|
|
361
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
362
|
+
var import_log3 = require("@dxos/log");
|
|
363
|
+
var import_credentials5 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
364
|
+
var import_tracing = require("@dxos/tracing");
|
|
365
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
366
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
367
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
368
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
369
|
+
else
|
|
370
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
371
|
+
if (d = decorators[i])
|
|
372
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
373
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
374
|
+
}
|
|
375
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
|
|
376
|
+
var Identity = class Identity2 {
|
|
214
377
|
constructor({ space, signer, identityKey, deviceKey }) {
|
|
215
378
|
this.stateUpdate = new import_async2.Event();
|
|
216
379
|
this.space = space;
|
|
217
380
|
this._signer = signer;
|
|
218
381
|
this.identityKey = identityKey;
|
|
219
382
|
this.deviceKey = deviceKey;
|
|
220
|
-
this._deviceStateMachine = new
|
|
383
|
+
this._deviceStateMachine = new import_credentials4.DeviceStateMachine({
|
|
221
384
|
identityKey: this.identityKey,
|
|
222
385
|
deviceKey: this.deviceKey,
|
|
223
386
|
onUpdate: () => this.stateUpdate.emit()
|
|
224
387
|
});
|
|
225
|
-
this._profileStateMachine = new
|
|
388
|
+
this._profileStateMachine = new import_credentials4.ProfileStateMachine({
|
|
226
389
|
identityKey: this.identityKey,
|
|
227
390
|
onUpdate: () => this.stateUpdate.emit()
|
|
228
391
|
});
|
|
@@ -236,12 +399,12 @@ var Identity = class {
|
|
|
236
399
|
get authorizedDeviceKeys() {
|
|
237
400
|
return this._deviceStateMachine.authorizedDeviceKeys;
|
|
238
401
|
}
|
|
239
|
-
async open() {
|
|
402
|
+
async open(ctx) {
|
|
240
403
|
await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
|
|
241
404
|
await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
|
|
242
|
-
await this.space.open();
|
|
405
|
+
await this.space.open(ctx);
|
|
243
406
|
}
|
|
244
|
-
async close() {
|
|
407
|
+
async close(ctx) {
|
|
245
408
|
await this.authVerifier.close();
|
|
246
409
|
await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
|
|
247
410
|
await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
|
|
@@ -272,11 +435,10 @@ var Identity = class {
|
|
|
272
435
|
return this._deviceStateMachine.deviceCredentialChain;
|
|
273
436
|
}
|
|
274
437
|
getAdmissionCredentials() {
|
|
275
|
-
var _a, _b;
|
|
276
438
|
return {
|
|
277
439
|
deviceKey: this.deviceKey,
|
|
278
|
-
controlFeedKey:
|
|
279
|
-
dataFeedKey:
|
|
440
|
+
controlFeedKey: this.space.controlFeedKey ?? (0, import_debug2.failUndefined)(),
|
|
441
|
+
dataFeedKey: this.space.dataFeedKey ?? (0, import_debug2.failUndefined)()
|
|
280
442
|
};
|
|
281
443
|
}
|
|
282
444
|
/**
|
|
@@ -284,25 +446,33 @@ var Identity = class {
|
|
|
284
446
|
* Requires identity to be ready.
|
|
285
447
|
*/
|
|
286
448
|
getIdentityCredentialSigner() {
|
|
287
|
-
(0,
|
|
288
|
-
|
|
449
|
+
(0, import_invariant2.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
|
|
450
|
+
F: __dxlog_file3,
|
|
451
|
+
L: 139,
|
|
452
|
+
S: this,
|
|
453
|
+
A: [
|
|
454
|
+
"this._deviceStateMachine.deviceCredentialChain",
|
|
455
|
+
"'Device credential chain is not ready.'"
|
|
456
|
+
]
|
|
457
|
+
});
|
|
458
|
+
return (0, import_credentials4.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.deviceCredentialChain, this.deviceKey);
|
|
289
459
|
}
|
|
290
460
|
/**
|
|
291
461
|
* Issues credentials as device.
|
|
292
462
|
*/
|
|
293
463
|
getDeviceCredentialSigner() {
|
|
294
|
-
return (0,
|
|
464
|
+
return (0, import_credentials4.createCredentialSignerWithKey)(this._signer, this.deviceKey);
|
|
295
465
|
}
|
|
296
466
|
async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
|
|
297
|
-
(0,
|
|
467
|
+
(0, import_log3.log)("Admitting device:", {
|
|
298
468
|
identityKey: this.identityKey,
|
|
299
469
|
hostDevice: this.deviceKey,
|
|
300
470
|
deviceKey,
|
|
301
471
|
controlFeedKey,
|
|
302
472
|
dataFeedKey
|
|
303
473
|
}, {
|
|
304
|
-
F:
|
|
305
|
-
L:
|
|
474
|
+
F: __dxlog_file3,
|
|
475
|
+
L: 155,
|
|
306
476
|
S: this,
|
|
307
477
|
C: (f, a) => f(...a)
|
|
308
478
|
});
|
|
@@ -323,7 +493,7 @@ var Identity = class {
|
|
|
323
493
|
spaceKey: this.haloSpaceKey,
|
|
324
494
|
deviceKey,
|
|
325
495
|
identityKey: this.identityKey,
|
|
326
|
-
designation:
|
|
496
|
+
designation: import_credentials5.AdmittedFeed.Designation.CONTROL
|
|
327
497
|
}
|
|
328
498
|
}),
|
|
329
499
|
await signer.createCredential({
|
|
@@ -333,7 +503,7 @@ var Identity = class {
|
|
|
333
503
|
spaceKey: this.haloSpaceKey,
|
|
334
504
|
deviceKey,
|
|
335
505
|
identityKey: this.identityKey,
|
|
336
|
-
designation:
|
|
506
|
+
designation: import_credentials5.AdmittedFeed.Designation.DATA
|
|
337
507
|
}
|
|
338
508
|
})
|
|
339
509
|
].map((credential) => ({
|
|
@@ -343,18 +513,40 @@ var Identity = class {
|
|
|
343
513
|
})));
|
|
344
514
|
}
|
|
345
515
|
};
|
|
516
|
+
_ts_decorate([
|
|
517
|
+
import_tracing.trace.span()
|
|
518
|
+
], Identity.prototype, "open", null);
|
|
519
|
+
_ts_decorate([
|
|
520
|
+
import_tracing.trace.span()
|
|
521
|
+
], Identity.prototype, "close", null);
|
|
522
|
+
Identity = _ts_decorate([
|
|
523
|
+
import_tracing.trace.resource()
|
|
524
|
+
], Identity);
|
|
346
525
|
|
|
347
526
|
// packages/sdk/client-services/src/packlets/identity/identity-manager.ts
|
|
348
|
-
var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
|
|
349
527
|
var import_async3 = require("@dxos/async");
|
|
350
|
-
var
|
|
528
|
+
var import_context2 = require("@dxos/context");
|
|
529
|
+
var import_credentials6 = require("@dxos/credentials");
|
|
530
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
351
531
|
var import_keys2 = require("@dxos/keys");
|
|
352
|
-
var
|
|
353
|
-
var
|
|
354
|
-
var
|
|
532
|
+
var import_log4 = require("@dxos/log");
|
|
533
|
+
var import_protocols3 = require("@dxos/protocols");
|
|
534
|
+
var import_credentials7 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
535
|
+
var import_timeframe = require("@dxos/timeframe");
|
|
536
|
+
var import_tracing2 = require("@dxos/tracing");
|
|
355
537
|
var import_util = require("@dxos/util");
|
|
356
|
-
|
|
357
|
-
var
|
|
538
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
539
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
540
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
541
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
542
|
+
else
|
|
543
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
544
|
+
if (d = decorators[i])
|
|
545
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
546
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
547
|
+
}
|
|
548
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
|
|
549
|
+
var IdentityManager = class IdentityManager2 {
|
|
358
550
|
// TODO(burdon): IdentityManagerParams.
|
|
359
551
|
// TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
|
|
360
552
|
constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
|
|
@@ -367,61 +559,66 @@ var IdentityManager = class {
|
|
|
367
559
|
get identity() {
|
|
368
560
|
return this._identity;
|
|
369
561
|
}
|
|
370
|
-
async open() {
|
|
371
|
-
var _a;
|
|
562
|
+
async open(ctx) {
|
|
372
563
|
const traceId = import_keys2.PublicKey.random().toHex();
|
|
373
|
-
|
|
564
|
+
import_log4.log.trace("dxos.halo.identity-manager.open", import_protocols3.trace.begin({
|
|
374
565
|
id: traceId
|
|
375
566
|
}), {
|
|
376
|
-
F:
|
|
377
|
-
L:
|
|
567
|
+
F: __dxlog_file4,
|
|
568
|
+
L: 73,
|
|
378
569
|
S: this,
|
|
379
570
|
C: (f, a) => f(...a)
|
|
380
571
|
});
|
|
381
572
|
await this._metadataStore.load();
|
|
382
573
|
const identityRecord = this._metadataStore.getIdentityRecord();
|
|
383
|
-
(0,
|
|
574
|
+
(0, import_log4.log)("identity record", {
|
|
384
575
|
identityRecord
|
|
385
576
|
}, {
|
|
386
|
-
F:
|
|
387
|
-
L:
|
|
577
|
+
F: __dxlog_file4,
|
|
578
|
+
L: 77,
|
|
388
579
|
S: this,
|
|
389
580
|
C: (f, a) => f(...a)
|
|
390
581
|
});
|
|
391
582
|
if (identityRecord) {
|
|
392
583
|
this._identity = await this._constructIdentity(identityRecord);
|
|
393
|
-
await this._identity.open();
|
|
584
|
+
await this._identity.open(ctx);
|
|
394
585
|
await this._identity.ready();
|
|
395
|
-
|
|
586
|
+
import_log4.log.trace("dxos.halo.identity", {
|
|
396
587
|
identityKey: identityRecord.identityKey,
|
|
397
|
-
displayName:
|
|
588
|
+
displayName: this._identity.profileDocument?.displayName
|
|
398
589
|
}, {
|
|
399
|
-
F:
|
|
400
|
-
L:
|
|
590
|
+
F: __dxlog_file4,
|
|
591
|
+
L: 82,
|
|
401
592
|
S: this,
|
|
402
593
|
C: (f, a) => f(...a)
|
|
403
594
|
});
|
|
404
595
|
this.stateUpdate.emit();
|
|
405
596
|
}
|
|
406
|
-
|
|
597
|
+
import_log4.log.trace("dxos.halo.identity-manager.open", import_protocols3.trace.end({
|
|
407
598
|
id: traceId
|
|
408
599
|
}), {
|
|
409
|
-
F:
|
|
410
|
-
L:
|
|
600
|
+
F: __dxlog_file4,
|
|
601
|
+
L: 88,
|
|
411
602
|
S: this,
|
|
412
603
|
C: (f, a) => f(...a)
|
|
413
604
|
});
|
|
414
605
|
}
|
|
415
606
|
async close() {
|
|
416
|
-
|
|
417
|
-
await ((_a = this._identity) == null ? void 0 : _a.close());
|
|
607
|
+
await this._identity?.close(new import_context2.Context());
|
|
418
608
|
}
|
|
419
609
|
async createIdentity({ displayName } = {}) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
610
|
+
(0, import_invariant3.invariant)(!this._identity, "Identity already exists.", {
|
|
611
|
+
F: __dxlog_file4,
|
|
612
|
+
L: 96,
|
|
613
|
+
S: this,
|
|
614
|
+
A: [
|
|
615
|
+
"!this._identity",
|
|
616
|
+
"'Identity already exists.'"
|
|
617
|
+
]
|
|
618
|
+
});
|
|
619
|
+
(0, import_log4.log)("creating identity...", void 0, {
|
|
620
|
+
F: __dxlog_file4,
|
|
621
|
+
L: 97,
|
|
425
622
|
S: this,
|
|
426
623
|
C: (f, a) => f(...a)
|
|
427
624
|
});
|
|
@@ -437,16 +634,32 @@ var IdentityManager = class {
|
|
|
437
634
|
}
|
|
438
635
|
};
|
|
439
636
|
const identity = await this._constructIdentity(identityRecord);
|
|
440
|
-
await identity.open();
|
|
637
|
+
await identity.open(new import_context2.Context());
|
|
441
638
|
{
|
|
442
|
-
const generator = new
|
|
443
|
-
(0,
|
|
444
|
-
|
|
639
|
+
const generator = new import_credentials6.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
|
|
640
|
+
(0, import_invariant3.invariant)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
|
|
641
|
+
F: __dxlog_file4,
|
|
642
|
+
L: 116,
|
|
643
|
+
S: this,
|
|
644
|
+
A: [
|
|
645
|
+
"identityRecord.haloSpace.genesisFeedKey",
|
|
646
|
+
"'Genesis feed key is required.'"
|
|
647
|
+
]
|
|
648
|
+
});
|
|
649
|
+
(0, import_invariant3.invariant)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
|
|
650
|
+
F: __dxlog_file4,
|
|
651
|
+
L: 117,
|
|
652
|
+
S: this,
|
|
653
|
+
A: [
|
|
654
|
+
"identityRecord.haloSpace.dataFeedKey",
|
|
655
|
+
"'Data feed key is required.'"
|
|
656
|
+
]
|
|
657
|
+
});
|
|
445
658
|
const credentials = [
|
|
446
659
|
// Space genesis.
|
|
447
660
|
...await generator.createSpaceGenesis(identityRecord.haloSpace.key, identityRecord.haloSpace.genesisFeedKey),
|
|
448
661
|
// Feed admission.
|
|
449
|
-
await generator.createFeedAdmission(identityRecord.haloSpace.key, identityRecord.haloSpace.dataFeedKey,
|
|
662
|
+
await generator.createFeedAdmission(identityRecord.haloSpace.key, identityRecord.haloSpace.dataFeedKey, import_credentials7.AdmittedFeed.Designation.DATA)
|
|
450
663
|
];
|
|
451
664
|
if (displayName) {
|
|
452
665
|
credentials.push(await generator.createProfileCredential({
|
|
@@ -465,22 +678,22 @@ var IdentityManager = class {
|
|
|
465
678
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
466
679
|
this._identity = identity;
|
|
467
680
|
await this._identity.ready();
|
|
468
|
-
|
|
681
|
+
import_log4.log.trace("dxos.halo.identity", {
|
|
469
682
|
identityKey: identityRecord.identityKey,
|
|
470
|
-
displayName:
|
|
683
|
+
displayName: this._identity.profileDocument?.displayName
|
|
471
684
|
}, {
|
|
472
|
-
F:
|
|
473
|
-
L:
|
|
685
|
+
F: __dxlog_file4,
|
|
686
|
+
L: 152,
|
|
474
687
|
S: this,
|
|
475
688
|
C: (f, a) => f(...a)
|
|
476
689
|
});
|
|
477
690
|
this.stateUpdate.emit();
|
|
478
|
-
(0,
|
|
691
|
+
(0, import_log4.log)("created identity", {
|
|
479
692
|
identityKey: identity.identityKey,
|
|
480
693
|
deviceKey: identity.deviceKey
|
|
481
694
|
}, {
|
|
482
|
-
F:
|
|
483
|
-
L:
|
|
695
|
+
F: __dxlog_file4,
|
|
696
|
+
L: 158,
|
|
484
697
|
S: this,
|
|
485
698
|
C: (f, a) => f(...a)
|
|
486
699
|
});
|
|
@@ -490,16 +703,23 @@ var IdentityManager = class {
|
|
|
490
703
|
* Accept an existing identity. Expects it's device key to be authorized (now or later).
|
|
491
704
|
*/
|
|
492
705
|
async acceptIdentity(params) {
|
|
493
|
-
|
|
494
|
-
(0, import_log3.log)("accepting identity", {
|
|
706
|
+
(0, import_log4.log)("accepting identity", {
|
|
495
707
|
params
|
|
496
708
|
}, {
|
|
497
|
-
F:
|
|
498
|
-
L:
|
|
709
|
+
F: __dxlog_file4,
|
|
710
|
+
L: 166,
|
|
499
711
|
S: this,
|
|
500
712
|
C: (f, a) => f(...a)
|
|
501
713
|
});
|
|
502
|
-
(0,
|
|
714
|
+
(0, import_invariant3.invariant)(!this._identity, "Identity already exists.", {
|
|
715
|
+
F: __dxlog_file4,
|
|
716
|
+
L: 167,
|
|
717
|
+
S: this,
|
|
718
|
+
A: [
|
|
719
|
+
"!this._identity",
|
|
720
|
+
"'Identity already exists.'"
|
|
721
|
+
]
|
|
722
|
+
});
|
|
503
723
|
const identityRecord = {
|
|
504
724
|
identityKey: params.identityKey,
|
|
505
725
|
deviceKey: params.deviceKey,
|
|
@@ -512,46 +732,102 @@ var IdentityManager = class {
|
|
|
512
732
|
}
|
|
513
733
|
};
|
|
514
734
|
const identity = await this._constructIdentity(identityRecord);
|
|
515
|
-
await identity.open();
|
|
735
|
+
await identity.open(new import_context2.Context());
|
|
516
736
|
this._identity = identity;
|
|
517
737
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
518
738
|
await this._identity.ready();
|
|
519
|
-
|
|
739
|
+
import_log4.log.trace("dxos.halo.identity", {
|
|
520
740
|
identityKey: identityRecord.identityKey,
|
|
521
|
-
displayName:
|
|
741
|
+
displayName: this._identity.profileDocument?.displayName
|
|
522
742
|
}, {
|
|
523
|
-
F:
|
|
524
|
-
L:
|
|
743
|
+
F: __dxlog_file4,
|
|
744
|
+
L: 186,
|
|
525
745
|
S: this,
|
|
526
746
|
C: (f, a) => f(...a)
|
|
527
747
|
});
|
|
528
748
|
this.stateUpdate.emit();
|
|
529
|
-
(0,
|
|
749
|
+
(0, import_log4.log)("accepted identity", {
|
|
530
750
|
identityKey: identity.identityKey,
|
|
531
751
|
deviceKey: identity.deviceKey
|
|
532
752
|
}, {
|
|
533
|
-
F:
|
|
534
|
-
L:
|
|
753
|
+
F: __dxlog_file4,
|
|
754
|
+
L: 192,
|
|
535
755
|
S: this,
|
|
536
756
|
C: (f, a) => f(...a)
|
|
537
757
|
});
|
|
538
758
|
return identity;
|
|
539
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Update the profile document of an existing identity.
|
|
762
|
+
*/
|
|
763
|
+
async updateProfile(profile) {
|
|
764
|
+
(0, import_invariant3.invariant)(this._identity, "Identity not initialized.", {
|
|
765
|
+
F: __dxlog_file4,
|
|
766
|
+
L: 200,
|
|
767
|
+
S: this,
|
|
768
|
+
A: [
|
|
769
|
+
"this._identity",
|
|
770
|
+
"'Identity not initialized.'"
|
|
771
|
+
]
|
|
772
|
+
});
|
|
773
|
+
const credential = await this._identity.getIdentityCredentialSigner().createCredential({
|
|
774
|
+
subject: this._identity.identityKey,
|
|
775
|
+
assertion: {
|
|
776
|
+
"@type": "dxos.halo.credentials.IdentityProfile",
|
|
777
|
+
profile
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
const receipt = await this._identity.controlPipeline.writer.write({
|
|
781
|
+
credential: {
|
|
782
|
+
credential
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
await this._identity.controlPipeline.state.waitUntilTimeframe(new import_timeframe.Timeframe([
|
|
786
|
+
[
|
|
787
|
+
receipt.feedKey,
|
|
788
|
+
receipt.seq
|
|
789
|
+
]
|
|
790
|
+
]));
|
|
791
|
+
}
|
|
540
792
|
async _constructIdentity(identityRecord) {
|
|
541
|
-
(0,
|
|
542
|
-
|
|
793
|
+
(0, import_invariant3.invariant)(!this._identity, void 0, {
|
|
794
|
+
F: __dxlog_file4,
|
|
795
|
+
L: 214,
|
|
796
|
+
S: this,
|
|
797
|
+
A: [
|
|
798
|
+
"!this._identity",
|
|
799
|
+
""
|
|
800
|
+
]
|
|
801
|
+
});
|
|
802
|
+
(0, import_log4.log)("constructing identity", {
|
|
543
803
|
identityRecord
|
|
544
804
|
}, {
|
|
545
|
-
F:
|
|
546
|
-
L:
|
|
805
|
+
F: __dxlog_file4,
|
|
806
|
+
L: 215,
|
|
547
807
|
S: this,
|
|
548
808
|
C: (f, a) => f(...a)
|
|
549
809
|
});
|
|
550
|
-
(0,
|
|
810
|
+
(0, import_invariant3.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
|
|
811
|
+
F: __dxlog_file4,
|
|
812
|
+
L: 218,
|
|
813
|
+
S: this,
|
|
814
|
+
A: [
|
|
815
|
+
"identityRecord.haloSpace.controlFeedKey",
|
|
816
|
+
""
|
|
817
|
+
]
|
|
818
|
+
});
|
|
551
819
|
const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
|
|
552
820
|
writable: true
|
|
553
821
|
});
|
|
554
|
-
(0,
|
|
822
|
+
(0, import_invariant3.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
|
|
823
|
+
F: __dxlog_file4,
|
|
824
|
+
L: 222,
|
|
825
|
+
S: this,
|
|
826
|
+
A: [
|
|
827
|
+
"identityRecord.haloSpace.dataFeedKey",
|
|
828
|
+
""
|
|
829
|
+
]
|
|
830
|
+
});
|
|
555
831
|
const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.dataFeedKey, {
|
|
556
832
|
writable: true,
|
|
557
833
|
sparse: true
|
|
@@ -560,7 +836,7 @@ var IdentityManager = class {
|
|
|
560
836
|
spaceRecord: identityRecord.haloSpace,
|
|
561
837
|
swarmIdentity: {
|
|
562
838
|
peerKey: identityRecord.deviceKey,
|
|
563
|
-
credentialProvider: createAuthProvider((0,
|
|
839
|
+
credentialProvider: createAuthProvider((0, import_credentials6.createCredentialSignerWithKey)(this._keyring, identityRecord.deviceKey)),
|
|
564
840
|
credentialAuthenticator: (0, import_util.deferFunction)(() => identity.authVerifier.verifier)
|
|
565
841
|
},
|
|
566
842
|
identityKey: identityRecord.identityKey
|
|
@@ -573,11 +849,11 @@ var IdentityManager = class {
|
|
|
573
849
|
identityKey: identityRecord.identityKey,
|
|
574
850
|
deviceKey: identityRecord.deviceKey
|
|
575
851
|
});
|
|
576
|
-
(0,
|
|
852
|
+
(0, import_log4.log)("done", {
|
|
577
853
|
identityKey: identityRecord.identityKey
|
|
578
854
|
}, {
|
|
579
|
-
F:
|
|
580
|
-
L:
|
|
855
|
+
F: __dxlog_file4,
|
|
856
|
+
L: 246,
|
|
581
857
|
S: this,
|
|
582
858
|
C: (f, a) => f(...a)
|
|
583
859
|
});
|
|
@@ -596,9 +872,9 @@ var IdentityManager = class {
|
|
|
596
872
|
onNetworkConnection: () => {
|
|
597
873
|
},
|
|
598
874
|
onAuthFailure: () => {
|
|
599
|
-
|
|
600
|
-
F:
|
|
601
|
-
L:
|
|
875
|
+
import_log4.log.warn("auth failure", void 0, {
|
|
876
|
+
F: __dxlog_file4,
|
|
877
|
+
L: 265,
|
|
602
878
|
S: this,
|
|
603
879
|
C: (f, a) => f(...a)
|
|
604
880
|
});
|
|
@@ -607,58 +883,88 @@ var IdentityManager = class {
|
|
|
607
883
|
});
|
|
608
884
|
}
|
|
609
885
|
};
|
|
886
|
+
_ts_decorate2([
|
|
887
|
+
import_tracing2.trace.span()
|
|
888
|
+
], IdentityManager.prototype, "open", null);
|
|
889
|
+
IdentityManager = _ts_decorate2([
|
|
890
|
+
import_tracing2.trace.resource()
|
|
891
|
+
], IdentityManager);
|
|
610
892
|
|
|
611
893
|
// packages/sdk/client-services/src/packlets/identity/identity-service.ts
|
|
612
|
-
var
|
|
613
|
-
var
|
|
614
|
-
var import_credentials7 = require("@dxos/credentials");
|
|
894
|
+
var import_codec_protobuf3 = require("@dxos/codec-protobuf");
|
|
895
|
+
var import_credentials8 = require("@dxos/credentials");
|
|
615
896
|
var import_debug3 = require("@dxos/debug");
|
|
897
|
+
var import_invariant4 = require("@dxos/invariant");
|
|
898
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
|
|
616
899
|
var IdentityServiceImpl = class {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
this.
|
|
900
|
+
constructor(_createIdentity, _identityManager, _keyring) {
|
|
901
|
+
this._createIdentity = _createIdentity;
|
|
902
|
+
this._identityManager = _identityManager;
|
|
903
|
+
this._keyring = _keyring;
|
|
620
904
|
}
|
|
621
905
|
async createIdentity(request) {
|
|
622
|
-
await this.
|
|
906
|
+
await this._createIdentity(request);
|
|
623
907
|
return this._getIdentity();
|
|
624
908
|
}
|
|
625
909
|
async recoverIdentity(request) {
|
|
626
910
|
return (0, import_debug3.todo)();
|
|
627
911
|
}
|
|
628
912
|
queryIdentity() {
|
|
629
|
-
return new
|
|
913
|
+
return new import_codec_protobuf3.Stream(({ next }) => {
|
|
630
914
|
const emitNext = () => next({
|
|
631
915
|
identity: this._getIdentity()
|
|
632
916
|
});
|
|
633
917
|
emitNext();
|
|
634
|
-
return this.
|
|
918
|
+
return this._identityManager.stateUpdate.on(emitNext);
|
|
635
919
|
});
|
|
636
920
|
}
|
|
637
921
|
_getIdentity() {
|
|
638
|
-
if (!this.
|
|
922
|
+
if (!this._identityManager.identity) {
|
|
639
923
|
return void 0;
|
|
640
924
|
}
|
|
641
925
|
return {
|
|
642
|
-
identityKey: this.
|
|
643
|
-
spaceKey: this.
|
|
644
|
-
profile: this.
|
|
926
|
+
identityKey: this._identityManager.identity.identityKey,
|
|
927
|
+
spaceKey: this._identityManager.identity.space.key,
|
|
928
|
+
profile: this._identityManager.identity.profileDocument
|
|
645
929
|
};
|
|
646
930
|
}
|
|
931
|
+
async updateProfile(profile) {
|
|
932
|
+
(0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
|
|
933
|
+
F: __dxlog_file5,
|
|
934
|
+
L: 59,
|
|
935
|
+
S: this,
|
|
936
|
+
A: [
|
|
937
|
+
"this._identityManager.identity",
|
|
938
|
+
"'Identity not initialized.'"
|
|
939
|
+
]
|
|
940
|
+
});
|
|
941
|
+
await this._identityManager.updateProfile(profile);
|
|
942
|
+
return this._getIdentity();
|
|
943
|
+
}
|
|
647
944
|
async signPresentation({ presentation, nonce }) {
|
|
648
|
-
(0,
|
|
649
|
-
|
|
945
|
+
(0, import_invariant4.invariant)(this._identityManager.identity, "Identity not initialized.", {
|
|
946
|
+
F: __dxlog_file5,
|
|
947
|
+
L: 65,
|
|
948
|
+
S: this,
|
|
949
|
+
A: [
|
|
950
|
+
"this._identityManager.identity",
|
|
951
|
+
"'Identity not initialized.'"
|
|
952
|
+
]
|
|
953
|
+
});
|
|
954
|
+
return await (0, import_credentials8.signPresentation)({
|
|
650
955
|
presentation,
|
|
651
|
-
signer: this.
|
|
652
|
-
signerKey: this.
|
|
653
|
-
chain: this.
|
|
956
|
+
signer: this._keyring,
|
|
957
|
+
signerKey: this._identityManager.identity.deviceKey,
|
|
958
|
+
chain: this._identityManager.identity.deviceCredentialChain,
|
|
654
959
|
nonce
|
|
655
960
|
});
|
|
656
961
|
}
|
|
657
962
|
};
|
|
658
963
|
|
|
659
964
|
// packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
|
|
660
|
-
var
|
|
661
|
-
var
|
|
965
|
+
var import_invariant5 = require("@dxos/invariant");
|
|
966
|
+
var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
|
|
967
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
|
|
662
968
|
var DeviceInvitationProtocol = class {
|
|
663
969
|
constructor(_keyring, _getIdentity, _acceptIdentity) {
|
|
664
970
|
this._keyring = _keyring;
|
|
@@ -670,11 +976,19 @@ var DeviceInvitationProtocol = class {
|
|
|
670
976
|
}
|
|
671
977
|
getInvitationContext() {
|
|
672
978
|
return {
|
|
673
|
-
kind:
|
|
979
|
+
kind: import_services2.Invitation.Kind.DEVICE
|
|
674
980
|
};
|
|
675
981
|
}
|
|
676
982
|
async admit(request) {
|
|
677
|
-
(0,
|
|
983
|
+
(0, import_invariant5.invariant)(request.device, void 0, {
|
|
984
|
+
F: __dxlog_file6,
|
|
985
|
+
L: 31,
|
|
986
|
+
S: this,
|
|
987
|
+
A: [
|
|
988
|
+
"request.device",
|
|
989
|
+
""
|
|
990
|
+
]
|
|
991
|
+
});
|
|
678
992
|
const identity = this._getIdentity();
|
|
679
993
|
await identity.admitDevice(request.device);
|
|
680
994
|
return {
|
|
@@ -702,9 +1016,25 @@ var DeviceInvitationProtocol = class {
|
|
|
702
1016
|
};
|
|
703
1017
|
}
|
|
704
1018
|
async accept(response, request) {
|
|
705
|
-
(0,
|
|
1019
|
+
(0, import_invariant5.invariant)(response.device, void 0, {
|
|
1020
|
+
F: __dxlog_file6,
|
|
1021
|
+
L: 64,
|
|
1022
|
+
S: this,
|
|
1023
|
+
A: [
|
|
1024
|
+
"response.device",
|
|
1025
|
+
""
|
|
1026
|
+
]
|
|
1027
|
+
});
|
|
706
1028
|
const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
|
|
707
|
-
(0,
|
|
1029
|
+
(0, import_invariant5.invariant)(request.device, void 0, {
|
|
1030
|
+
F: __dxlog_file6,
|
|
1031
|
+
L: 67,
|
|
1032
|
+
S: this,
|
|
1033
|
+
A: [
|
|
1034
|
+
"request.device",
|
|
1035
|
+
""
|
|
1036
|
+
]
|
|
1037
|
+
});
|
|
708
1038
|
const { deviceKey, controlFeedKey, dataFeedKey } = request.device;
|
|
709
1039
|
await this._acceptIdentity({
|
|
710
1040
|
identityKey,
|
|
@@ -722,45 +1052,45 @@ var DeviceInvitationProtocol = class {
|
|
|
722
1052
|
};
|
|
723
1053
|
|
|
724
1054
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
725
|
-
var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
|
|
726
1055
|
var import_async5 = require("@dxos/async");
|
|
727
1056
|
var import_client_protocol2 = require("@dxos/client-protocol");
|
|
728
|
-
var
|
|
729
|
-
var
|
|
1057
|
+
var import_context4 = require("@dxos/context");
|
|
1058
|
+
var import_credentials9 = require("@dxos/credentials");
|
|
730
1059
|
var import_errors2 = require("@dxos/errors");
|
|
1060
|
+
var import_invariant7 = require("@dxos/invariant");
|
|
731
1061
|
var import_keys4 = require("@dxos/keys");
|
|
732
|
-
var
|
|
1062
|
+
var import_log6 = require("@dxos/log");
|
|
733
1063
|
var import_network_manager = require("@dxos/network-manager");
|
|
734
|
-
var
|
|
735
|
-
var
|
|
1064
|
+
var import_protocols5 = require("@dxos/protocols");
|
|
1065
|
+
var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
|
|
736
1066
|
var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
737
1067
|
|
|
738
1068
|
// packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts
|
|
739
|
-
var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
|
|
740
1069
|
var import_async4 = require("@dxos/async");
|
|
741
|
-
var
|
|
1070
|
+
var import_context3 = require("@dxos/context");
|
|
742
1071
|
var import_errors = require("@dxos/errors");
|
|
1072
|
+
var import_invariant6 = require("@dxos/invariant");
|
|
743
1073
|
var import_keys3 = require("@dxos/keys");
|
|
744
|
-
var
|
|
745
|
-
var
|
|
746
|
-
var
|
|
1074
|
+
var import_log5 = require("@dxos/log");
|
|
1075
|
+
var import_protocols4 = require("@dxos/protocols");
|
|
1076
|
+
var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
|
|
747
1077
|
var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
748
1078
|
var import_teleport = require("@dxos/teleport");
|
|
749
|
-
var
|
|
1079
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-extension.ts";
|
|
750
1080
|
var OPTIONS_TIMEOUT = 1e4;
|
|
751
1081
|
var MAX_OTP_ATTEMPTS = 3;
|
|
752
1082
|
var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
753
1083
|
constructor(_callbacks) {
|
|
754
1084
|
super({
|
|
755
1085
|
requested: {
|
|
756
|
-
InvitationHostService:
|
|
1086
|
+
InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
757
1087
|
},
|
|
758
1088
|
exposed: {
|
|
759
|
-
InvitationHostService:
|
|
1089
|
+
InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
760
1090
|
}
|
|
761
1091
|
});
|
|
762
1092
|
this._callbacks = _callbacks;
|
|
763
|
-
this._ctx = new
|
|
1093
|
+
this._ctx = new import_context3.Context();
|
|
764
1094
|
this._remoteOptionsTrigger = new import_async4.Trigger();
|
|
765
1095
|
this.invitation = void 0;
|
|
766
1096
|
this.guestProfile = void 0;
|
|
@@ -774,88 +1104,104 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
774
1104
|
// Perhaps in the future we will have more complex logic here.
|
|
775
1105
|
InvitationHostService: {
|
|
776
1106
|
options: async (options) => {
|
|
777
|
-
(0,
|
|
1107
|
+
(0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
|
|
1108
|
+
F: __dxlog_file7,
|
|
1109
|
+
L: 88,
|
|
1110
|
+
S: this,
|
|
1111
|
+
A: [
|
|
1112
|
+
"!this._remoteOptions",
|
|
1113
|
+
"'Remote options already set.'"
|
|
1114
|
+
]
|
|
1115
|
+
});
|
|
778
1116
|
this._remoteOptions = options;
|
|
779
1117
|
this._remoteOptionsTrigger.wake();
|
|
780
1118
|
},
|
|
781
1119
|
introduce: async (request) => {
|
|
782
1120
|
const { profile, invitationId } = request;
|
|
783
1121
|
const traceId = import_keys3.PublicKey.random().toHex();
|
|
784
|
-
|
|
1122
|
+
import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.begin({
|
|
785
1123
|
id: traceId
|
|
786
1124
|
}), {
|
|
787
|
-
F:
|
|
788
|
-
L:
|
|
1125
|
+
F: __dxlog_file7,
|
|
1126
|
+
L: 97,
|
|
789
1127
|
S: this,
|
|
790
1128
|
C: (f, a) => f(...a)
|
|
791
1129
|
});
|
|
792
1130
|
const invitation = await this._callbacks.resolveInvitation(request);
|
|
793
1131
|
if (!invitation) {
|
|
794
|
-
|
|
1132
|
+
import_log5.log.warn("invitation not found", {
|
|
795
1133
|
invitationId
|
|
796
1134
|
}, {
|
|
797
|
-
F:
|
|
798
|
-
L:
|
|
1135
|
+
F: __dxlog_file7,
|
|
1136
|
+
L: 101,
|
|
799
1137
|
S: this,
|
|
800
1138
|
C: (f, a) => f(...a)
|
|
801
1139
|
});
|
|
802
1140
|
this._callbacks.onError(new Error("Invitation not found."));
|
|
803
1141
|
return {
|
|
804
|
-
authMethod:
|
|
1142
|
+
authMethod: import_services3.Invitation.AuthMethod.NONE
|
|
805
1143
|
};
|
|
806
1144
|
}
|
|
807
1145
|
this.invitation = invitation;
|
|
808
|
-
(0,
|
|
1146
|
+
(0, import_log5.log)("guest introduced itself", {
|
|
809
1147
|
guestProfile: profile
|
|
810
1148
|
}, {
|
|
811
|
-
F:
|
|
812
|
-
L:
|
|
1149
|
+
F: __dxlog_file7,
|
|
1150
|
+
L: 110,
|
|
813
1151
|
S: this,
|
|
814
1152
|
C: (f, a) => f(...a)
|
|
815
1153
|
});
|
|
816
1154
|
this.guestProfile = profile;
|
|
817
1155
|
this._callbacks.onStateUpdate({
|
|
818
1156
|
...this.invitation,
|
|
819
|
-
state:
|
|
1157
|
+
state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
|
|
820
1158
|
});
|
|
821
|
-
|
|
1159
|
+
import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols4.trace.end({
|
|
822
1160
|
id: traceId
|
|
823
1161
|
}), {
|
|
824
|
-
F:
|
|
825
|
-
L:
|
|
1162
|
+
F: __dxlog_file7,
|
|
1163
|
+
L: 117,
|
|
826
1164
|
S: this,
|
|
827
1165
|
C: (f, a) => f(...a)
|
|
828
1166
|
});
|
|
829
1167
|
return {
|
|
830
|
-
spaceKey: this.invitation.authMethod ===
|
|
1168
|
+
spaceKey: this.invitation.authMethod === import_services3.Invitation.AuthMethod.NONE ? this.invitation.spaceKey : void 0,
|
|
831
1169
|
authMethod: this.invitation.authMethod
|
|
832
1170
|
};
|
|
833
1171
|
},
|
|
834
1172
|
authenticate: async ({ authCode: code }) => {
|
|
835
1173
|
const traceId = import_keys3.PublicKey.random().toHex();
|
|
836
|
-
|
|
1174
|
+
import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.begin({
|
|
837
1175
|
id: traceId
|
|
838
1176
|
}), {
|
|
839
|
-
F:
|
|
840
|
-
L:
|
|
1177
|
+
F: __dxlog_file7,
|
|
1178
|
+
L: 126,
|
|
841
1179
|
S: this,
|
|
842
1180
|
C: (f, a) => f(...a)
|
|
843
1181
|
});
|
|
844
|
-
(0,
|
|
1182
|
+
(0, import_log5.log)("received authentication request", {
|
|
845
1183
|
authCode: code
|
|
846
1184
|
}, {
|
|
847
|
-
F:
|
|
848
|
-
L:
|
|
1185
|
+
F: __dxlog_file7,
|
|
1186
|
+
L: 127,
|
|
849
1187
|
S: this,
|
|
850
1188
|
C: (f, a) => f(...a)
|
|
851
1189
|
});
|
|
852
1190
|
let status = import_invitations.AuthenticationResponse.Status.OK;
|
|
853
|
-
(0,
|
|
1191
|
+
(0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
|
|
1192
|
+
F: __dxlog_file7,
|
|
1193
|
+
L: 130,
|
|
1194
|
+
S: this,
|
|
1195
|
+
A: [
|
|
1196
|
+
"this.invitation",
|
|
1197
|
+
"'Invitation is not set.'"
|
|
1198
|
+
]
|
|
1199
|
+
});
|
|
854
1200
|
switch (this.invitation.authMethod) {
|
|
855
|
-
case
|
|
856
|
-
(0,
|
|
857
|
-
F:
|
|
858
|
-
L:
|
|
1201
|
+
case import_services3.Invitation.AuthMethod.NONE: {
|
|
1202
|
+
(0, import_log5.log)("authentication not required", void 0, {
|
|
1203
|
+
F: __dxlog_file7,
|
|
1204
|
+
L: 133,
|
|
859
1205
|
S: this,
|
|
860
1206
|
C: (f, a) => f(...a)
|
|
861
1207
|
});
|
|
@@ -863,7 +1209,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
863
1209
|
status: import_invitations.AuthenticationResponse.Status.OK
|
|
864
1210
|
};
|
|
865
1211
|
}
|
|
866
|
-
case
|
|
1212
|
+
case import_services3.Invitation.AuthMethod.SHARED_SECRET: {
|
|
867
1213
|
if (this.invitation.authCode) {
|
|
868
1214
|
if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
|
|
869
1215
|
status = import_invitations.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
|
|
@@ -876,11 +1222,11 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
876
1222
|
break;
|
|
877
1223
|
}
|
|
878
1224
|
default: {
|
|
879
|
-
|
|
1225
|
+
import_log5.log.error("invalid authentication method", {
|
|
880
1226
|
authMethod: this.invitation.authMethod
|
|
881
1227
|
}, {
|
|
882
|
-
F:
|
|
883
|
-
L:
|
|
1228
|
+
F: __dxlog_file7,
|
|
1229
|
+
L: 151,
|
|
884
1230
|
S: this,
|
|
885
1231
|
C: (f, a) => f(...a)
|
|
886
1232
|
});
|
|
@@ -888,14 +1234,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
888
1234
|
break;
|
|
889
1235
|
}
|
|
890
1236
|
}
|
|
891
|
-
|
|
1237
|
+
import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols4.trace.end({
|
|
892
1238
|
id: traceId,
|
|
893
1239
|
data: {
|
|
894
1240
|
status
|
|
895
1241
|
}
|
|
896
1242
|
}), {
|
|
897
|
-
F:
|
|
898
|
-
L:
|
|
1243
|
+
F: __dxlog_file7,
|
|
1244
|
+
L: 157,
|
|
899
1245
|
S: this,
|
|
900
1246
|
C: (f, a) => f(...a)
|
|
901
1247
|
});
|
|
@@ -905,25 +1251,33 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
905
1251
|
},
|
|
906
1252
|
admit: async (request) => {
|
|
907
1253
|
const traceId = import_keys3.PublicKey.random().toHex();
|
|
908
|
-
|
|
1254
|
+
import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.begin({
|
|
909
1255
|
id: traceId
|
|
910
1256
|
}), {
|
|
911
|
-
F:
|
|
912
|
-
L:
|
|
1257
|
+
F: __dxlog_file7,
|
|
1258
|
+
L: 163,
|
|
913
1259
|
S: this,
|
|
914
1260
|
C: (f, a) => f(...a)
|
|
915
1261
|
});
|
|
916
1262
|
try {
|
|
917
|
-
(0,
|
|
1263
|
+
(0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
|
|
1264
|
+
F: __dxlog_file7,
|
|
1265
|
+
L: 166,
|
|
1266
|
+
S: this,
|
|
1267
|
+
A: [
|
|
1268
|
+
"this.invitation",
|
|
1269
|
+
"'Invitation is not set.'"
|
|
1270
|
+
]
|
|
1271
|
+
});
|
|
918
1272
|
if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
|
|
919
1273
|
throw new Error("Not authenticated");
|
|
920
1274
|
}
|
|
921
1275
|
const response = await this._callbacks.admit(request);
|
|
922
|
-
|
|
1276
|
+
import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols4.trace.end({
|
|
923
1277
|
id: traceId
|
|
924
1278
|
}), {
|
|
925
|
-
F:
|
|
926
|
-
L:
|
|
1279
|
+
F: __dxlog_file7,
|
|
1280
|
+
L: 174,
|
|
927
1281
|
S: this,
|
|
928
1282
|
C: (f, a) => f(...a)
|
|
929
1283
|
});
|
|
@@ -937,16 +1291,15 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
937
1291
|
};
|
|
938
1292
|
}
|
|
939
1293
|
async onOpen(context) {
|
|
940
|
-
var _a;
|
|
941
1294
|
await super.onOpen(context);
|
|
942
1295
|
try {
|
|
943
1296
|
await this.rpc.InvitationHostService.options({
|
|
944
1297
|
role: import_invitations.Options.Role.HOST
|
|
945
1298
|
});
|
|
946
|
-
await (0,
|
|
1299
|
+
await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
947
1300
|
timeout: OPTIONS_TIMEOUT
|
|
948
1301
|
}));
|
|
949
|
-
if (
|
|
1302
|
+
if (this._remoteOptions?.role !== import_invitations.Options.Role.GUEST) {
|
|
950
1303
|
throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
|
|
951
1304
|
expected: import_invitations.Options.Role.GUEST,
|
|
952
1305
|
remoteOptions: this._remoteOptions
|
|
@@ -965,21 +1318,29 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
965
1318
|
constructor(_callbacks) {
|
|
966
1319
|
super({
|
|
967
1320
|
requested: {
|
|
968
|
-
InvitationHostService:
|
|
1321
|
+
InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
969
1322
|
},
|
|
970
1323
|
exposed: {
|
|
971
|
-
InvitationHostService:
|
|
1324
|
+
InvitationHostService: import_protocols4.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
972
1325
|
}
|
|
973
1326
|
});
|
|
974
1327
|
this._callbacks = _callbacks;
|
|
975
|
-
this._ctx = new
|
|
1328
|
+
this._ctx = new import_context3.Context();
|
|
976
1329
|
this._remoteOptionsTrigger = new import_async4.Trigger();
|
|
977
1330
|
}
|
|
978
1331
|
async getHandlers() {
|
|
979
1332
|
return {
|
|
980
1333
|
InvitationHostService: {
|
|
981
1334
|
options: async (options) => {
|
|
982
|
-
(0,
|
|
1335
|
+
(0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
|
|
1336
|
+
F: __dxlog_file7,
|
|
1337
|
+
L: 241,
|
|
1338
|
+
S: this,
|
|
1339
|
+
A: [
|
|
1340
|
+
"!this._remoteOptions",
|
|
1341
|
+
"'Remote options already set.'"
|
|
1342
|
+
]
|
|
1343
|
+
});
|
|
983
1344
|
this._remoteOptions = options;
|
|
984
1345
|
this._remoteOptionsTrigger.wake();
|
|
985
1346
|
},
|
|
@@ -996,28 +1357,27 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
996
1357
|
};
|
|
997
1358
|
}
|
|
998
1359
|
async onOpen(context) {
|
|
999
|
-
var _a;
|
|
1000
1360
|
await super.onOpen(context);
|
|
1001
1361
|
try {
|
|
1002
|
-
(0,
|
|
1003
|
-
F:
|
|
1004
|
-
L:
|
|
1362
|
+
(0, import_log5.log)("begin options", void 0, {
|
|
1363
|
+
F: __dxlog_file7,
|
|
1364
|
+
L: 262,
|
|
1005
1365
|
S: this,
|
|
1006
1366
|
C: (f, a) => f(...a)
|
|
1007
1367
|
});
|
|
1008
|
-
await (0,
|
|
1368
|
+
await (0, import_context3.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
|
|
1009
1369
|
role: import_invitations.Options.Role.GUEST
|
|
1010
1370
|
}));
|
|
1011
|
-
await (0,
|
|
1371
|
+
await (0, import_context3.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1012
1372
|
timeout: OPTIONS_TIMEOUT
|
|
1013
1373
|
}));
|
|
1014
|
-
(0,
|
|
1015
|
-
F:
|
|
1016
|
-
L:
|
|
1374
|
+
(0, import_log5.log)("end options", void 0, {
|
|
1375
|
+
F: __dxlog_file7,
|
|
1376
|
+
L: 265,
|
|
1017
1377
|
S: this,
|
|
1018
1378
|
C: (f, a) => f(...a)
|
|
1019
1379
|
});
|
|
1020
|
-
if (
|
|
1380
|
+
if (this._remoteOptions?.role !== import_invitations.Options.Role.HOST) {
|
|
1021
1381
|
throw new import_errors.InvalidInvitationExtensionRoleError(void 0, {
|
|
1022
1382
|
expected: import_invitations.Options.Role.HOST,
|
|
1023
1383
|
remoteOptions: this._remoteOptions
|
|
@@ -1025,9 +1385,9 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
1025
1385
|
}
|
|
1026
1386
|
this._callbacks.onOpen(this._ctx);
|
|
1027
1387
|
} catch (err) {
|
|
1028
|
-
(0,
|
|
1029
|
-
F:
|
|
1030
|
-
L:
|
|
1388
|
+
(0, import_log5.log)("openError", err, {
|
|
1389
|
+
F: __dxlog_file7,
|
|
1390
|
+
L: 275,
|
|
1031
1391
|
S: this,
|
|
1032
1392
|
C: (f, a) => f(...a)
|
|
1033
1393
|
});
|
|
@@ -1035,19 +1395,19 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
1035
1395
|
}
|
|
1036
1396
|
}
|
|
1037
1397
|
async onClose() {
|
|
1038
|
-
(0,
|
|
1039
|
-
F:
|
|
1040
|
-
L:
|
|
1398
|
+
(0, import_log5.log)("onClose", void 0, {
|
|
1399
|
+
F: __dxlog_file7,
|
|
1400
|
+
L: 281,
|
|
1041
1401
|
S: this,
|
|
1042
1402
|
C: (f, a) => f(...a)
|
|
1043
1403
|
});
|
|
1044
1404
|
await this._ctx.dispose();
|
|
1045
1405
|
}
|
|
1046
1406
|
};
|
|
1047
|
-
var isAuthenticationRequired = (invitation) => invitation.authMethod !==
|
|
1407
|
+
var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services3.Invitation.AuthMethod.NONE;
|
|
1048
1408
|
|
|
1049
1409
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1050
|
-
var
|
|
1410
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
|
|
1051
1411
|
var InvitationsHandler = class {
|
|
1052
1412
|
/**
|
|
1053
1413
|
* @internal
|
|
@@ -1056,10 +1416,17 @@ var InvitationsHandler = class {
|
|
|
1056
1416
|
this._networkManager = _networkManager;
|
|
1057
1417
|
}
|
|
1058
1418
|
createInvitation(protocol, options) {
|
|
1059
|
-
|
|
1060
|
-
const
|
|
1061
|
-
|
|
1062
|
-
|
|
1419
|
+
const { invitationId = import_keys4.PublicKey.random().toHex(), type = import_services4.Invitation.Type.INTERACTIVE, authMethod = import_services4.Invitation.AuthMethod.SHARED_SECRET, state = import_services4.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys4.PublicKey.random() } = options ?? {};
|
|
1420
|
+
const authCode = options?.authCode ?? (authMethod === import_services4.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
|
|
1421
|
+
(0, import_invariant7.invariant)(protocol, void 0, {
|
|
1422
|
+
F: __dxlog_file8,
|
|
1423
|
+
L: 76,
|
|
1424
|
+
S: this,
|
|
1425
|
+
A: [
|
|
1426
|
+
"protocol",
|
|
1427
|
+
""
|
|
1428
|
+
]
|
|
1429
|
+
});
|
|
1063
1430
|
const invitation = {
|
|
1064
1431
|
invitationId,
|
|
1065
1432
|
type,
|
|
@@ -1071,18 +1438,18 @@ var InvitationsHandler = class {
|
|
|
1071
1438
|
...protocol.getInvitationContext()
|
|
1072
1439
|
};
|
|
1073
1440
|
const stream = new import_async5.PushStream();
|
|
1074
|
-
const ctx = new
|
|
1441
|
+
const ctx = new import_context4.Context({
|
|
1075
1442
|
onError: (err) => {
|
|
1076
1443
|
void ctx.dispose();
|
|
1077
1444
|
stream.error(err);
|
|
1078
1445
|
}
|
|
1079
1446
|
});
|
|
1080
1447
|
ctx.onDispose(() => {
|
|
1081
|
-
(0,
|
|
1448
|
+
(0, import_log6.log)("complete", {
|
|
1082
1449
|
...protocol.toJSON()
|
|
1083
1450
|
}, {
|
|
1084
|
-
F:
|
|
1085
|
-
L:
|
|
1451
|
+
F: __dxlog_file8,
|
|
1452
|
+
L: 98,
|
|
1086
1453
|
S: this,
|
|
1087
1454
|
C: (f, a) => f(...a)
|
|
1088
1455
|
});
|
|
@@ -1093,7 +1460,7 @@ var InvitationsHandler = class {
|
|
|
1093
1460
|
onStateUpdate: (invitation2) => {
|
|
1094
1461
|
stream.next({
|
|
1095
1462
|
...invitation2,
|
|
1096
|
-
state:
|
|
1463
|
+
state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1097
1464
|
});
|
|
1098
1465
|
},
|
|
1099
1466
|
resolveInvitation: async ({ invitationId: invitationId2 }) => {
|
|
@@ -1103,10 +1470,17 @@ var InvitationsHandler = class {
|
|
|
1103
1470
|
return invitation;
|
|
1104
1471
|
},
|
|
1105
1472
|
admit: async (admissionRequest) => {
|
|
1106
|
-
var _a2, _b, _c;
|
|
1107
1473
|
try {
|
|
1108
|
-
const deviceKey =
|
|
1109
|
-
(0,
|
|
1474
|
+
const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
|
|
1475
|
+
(0, import_invariant7.invariant)(deviceKey, void 0, {
|
|
1476
|
+
F: __dxlog_file8,
|
|
1477
|
+
L: 119,
|
|
1478
|
+
S: this,
|
|
1479
|
+
A: [
|
|
1480
|
+
"deviceKey",
|
|
1481
|
+
""
|
|
1482
|
+
]
|
|
1483
|
+
});
|
|
1110
1484
|
const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
|
|
1111
1485
|
extension.completedTrigger.wake(deviceKey);
|
|
1112
1486
|
return admissionResponse;
|
|
@@ -1119,84 +1493,84 @@ var InvitationsHandler = class {
|
|
|
1119
1493
|
(0, import_async5.scheduleTask)(ctx, async () => {
|
|
1120
1494
|
const traceId = import_keys4.PublicKey.random().toHex();
|
|
1121
1495
|
try {
|
|
1122
|
-
|
|
1496
|
+
import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.begin({
|
|
1123
1497
|
id: traceId
|
|
1124
1498
|
}), {
|
|
1125
|
-
F:
|
|
1126
|
-
L:
|
|
1499
|
+
F: __dxlog_file8,
|
|
1500
|
+
L: 137,
|
|
1127
1501
|
S: this,
|
|
1128
1502
|
C: (f, a) => f(...a)
|
|
1129
1503
|
});
|
|
1130
|
-
(0,
|
|
1504
|
+
(0, import_log6.log)("connected", {
|
|
1131
1505
|
...protocol.toJSON()
|
|
1132
1506
|
}, {
|
|
1133
|
-
F:
|
|
1134
|
-
L:
|
|
1507
|
+
F: __dxlog_file8,
|
|
1508
|
+
L: 138,
|
|
1135
1509
|
S: this,
|
|
1136
1510
|
C: (f, a) => f(...a)
|
|
1137
1511
|
});
|
|
1138
1512
|
stream.next({
|
|
1139
1513
|
...invitation,
|
|
1140
|
-
state:
|
|
1514
|
+
state: import_services4.Invitation.State.CONNECTED
|
|
1141
1515
|
});
|
|
1142
1516
|
const deviceKey = await extension.completedTrigger.wait({
|
|
1143
1517
|
timeout
|
|
1144
1518
|
});
|
|
1145
|
-
(0,
|
|
1519
|
+
(0, import_log6.log)("admitted guest", {
|
|
1146
1520
|
guest: deviceKey,
|
|
1147
1521
|
...protocol.toJSON()
|
|
1148
1522
|
}, {
|
|
1149
|
-
F:
|
|
1150
|
-
L:
|
|
1523
|
+
F: __dxlog_file8,
|
|
1524
|
+
L: 141,
|
|
1151
1525
|
S: this,
|
|
1152
1526
|
C: (f, a) => f(...a)
|
|
1153
1527
|
});
|
|
1154
1528
|
stream.next({
|
|
1155
1529
|
...invitation,
|
|
1156
|
-
state:
|
|
1530
|
+
state: import_services4.Invitation.State.SUCCESS
|
|
1157
1531
|
});
|
|
1158
|
-
|
|
1532
|
+
import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.end({
|
|
1159
1533
|
id: traceId
|
|
1160
1534
|
}), {
|
|
1161
|
-
F:
|
|
1162
|
-
L:
|
|
1535
|
+
F: __dxlog_file8,
|
|
1536
|
+
L: 143,
|
|
1163
1537
|
S: this,
|
|
1164
1538
|
C: (f, a) => f(...a)
|
|
1165
1539
|
});
|
|
1166
1540
|
} catch (err) {
|
|
1167
1541
|
if (err instanceof import_async5.TimeoutError) {
|
|
1168
|
-
(0,
|
|
1542
|
+
(0, import_log6.log)("timeout", {
|
|
1169
1543
|
...protocol.toJSON()
|
|
1170
1544
|
}, {
|
|
1171
|
-
F:
|
|
1172
|
-
L:
|
|
1545
|
+
F: __dxlog_file8,
|
|
1546
|
+
L: 146,
|
|
1173
1547
|
S: this,
|
|
1174
1548
|
C: (f, a) => f(...a)
|
|
1175
1549
|
});
|
|
1176
1550
|
stream.next({
|
|
1177
1551
|
...invitation,
|
|
1178
|
-
state:
|
|
1552
|
+
state: import_services4.Invitation.State.TIMEOUT
|
|
1179
1553
|
});
|
|
1180
1554
|
} else {
|
|
1181
|
-
|
|
1182
|
-
F:
|
|
1183
|
-
L:
|
|
1555
|
+
import_log6.log.error("failed", err, {
|
|
1556
|
+
F: __dxlog_file8,
|
|
1557
|
+
L: 149,
|
|
1184
1558
|
S: this,
|
|
1185
1559
|
C: (f, a) => f(...a)
|
|
1186
1560
|
});
|
|
1187
1561
|
stream.error(err);
|
|
1188
1562
|
}
|
|
1189
|
-
|
|
1563
|
+
import_log6.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols5.trace.error({
|
|
1190
1564
|
id: traceId,
|
|
1191
1565
|
error: err
|
|
1192
1566
|
}), {
|
|
1193
|
-
F:
|
|
1194
|
-
L:
|
|
1567
|
+
F: __dxlog_file8,
|
|
1568
|
+
L: 152,
|
|
1195
1569
|
S: this,
|
|
1196
1570
|
C: (f, a) => f(...a)
|
|
1197
1571
|
});
|
|
1198
1572
|
} finally {
|
|
1199
|
-
if (type !==
|
|
1573
|
+
if (type !== import_services4.Invitation.Type.MULTIUSE) {
|
|
1200
1574
|
await swarmConnection.close();
|
|
1201
1575
|
await ctx.dispose();
|
|
1202
1576
|
}
|
|
@@ -1208,22 +1582,22 @@ var InvitationsHandler = class {
|
|
|
1208
1582
|
return;
|
|
1209
1583
|
}
|
|
1210
1584
|
if (err instanceof import_async5.TimeoutError) {
|
|
1211
|
-
(0,
|
|
1585
|
+
(0, import_log6.log)("timeout", {
|
|
1212
1586
|
...protocol.toJSON()
|
|
1213
1587
|
}, {
|
|
1214
|
-
F:
|
|
1215
|
-
L:
|
|
1588
|
+
F: __dxlog_file8,
|
|
1589
|
+
L: 167,
|
|
1216
1590
|
S: this,
|
|
1217
1591
|
C: (f, a) => f(...a)
|
|
1218
1592
|
});
|
|
1219
1593
|
stream.next({
|
|
1220
1594
|
...invitation,
|
|
1221
|
-
state:
|
|
1595
|
+
state: import_services4.Invitation.State.TIMEOUT
|
|
1222
1596
|
});
|
|
1223
1597
|
} else {
|
|
1224
|
-
|
|
1225
|
-
F:
|
|
1226
|
-
L:
|
|
1598
|
+
import_log6.log.error("failed", err, {
|
|
1599
|
+
F: __dxlog_file8,
|
|
1600
|
+
L: 170,
|
|
1227
1601
|
S: this,
|
|
1228
1602
|
C: (f, a) => f(...a)
|
|
1229
1603
|
});
|
|
@@ -1242,12 +1616,13 @@ var InvitationsHandler = class {
|
|
|
1242
1616
|
protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
|
|
1243
1617
|
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
1244
1618
|
}),
|
|
1245
|
-
topology: new import_network_manager.StarTopology(topic)
|
|
1619
|
+
topology: new import_network_manager.StarTopology(topic),
|
|
1620
|
+
label: "invitation host"
|
|
1246
1621
|
});
|
|
1247
1622
|
ctx.onDispose(() => swarmConnection.close());
|
|
1248
1623
|
stream.next({
|
|
1249
1624
|
...invitation,
|
|
1250
|
-
state:
|
|
1625
|
+
state: import_services4.Invitation.State.CONNECTING
|
|
1251
1626
|
});
|
|
1252
1627
|
});
|
|
1253
1628
|
const observable = new import_client_protocol2.CancellableInvitationObservable({
|
|
@@ -1256,7 +1631,7 @@ var InvitationsHandler = class {
|
|
|
1256
1631
|
onCancel: async () => {
|
|
1257
1632
|
stream.next({
|
|
1258
1633
|
...invitation,
|
|
1259
|
-
state:
|
|
1634
|
+
state: import_services4.Invitation.State.CANCELLED
|
|
1260
1635
|
});
|
|
1261
1636
|
await ctx.dispose();
|
|
1262
1637
|
}
|
|
@@ -1265,36 +1640,52 @@ var InvitationsHandler = class {
|
|
|
1265
1640
|
}
|
|
1266
1641
|
acceptInvitation(protocol, invitation) {
|
|
1267
1642
|
const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
|
|
1268
|
-
(0,
|
|
1643
|
+
(0, import_invariant7.invariant)(protocol, void 0, {
|
|
1644
|
+
F: __dxlog_file8,
|
|
1645
|
+
L: 211,
|
|
1646
|
+
S: this,
|
|
1647
|
+
A: [
|
|
1648
|
+
"protocol",
|
|
1649
|
+
""
|
|
1650
|
+
]
|
|
1651
|
+
});
|
|
1269
1652
|
const authenticated = new import_async5.Trigger();
|
|
1270
1653
|
let admitted = false;
|
|
1271
1654
|
let currentState;
|
|
1272
1655
|
const stream = new import_async5.PushStream();
|
|
1273
1656
|
const setState = (newData) => {
|
|
1274
|
-
(0,
|
|
1657
|
+
(0, import_invariant7.invariant)(newData.state !== void 0, void 0, {
|
|
1658
|
+
F: __dxlog_file8,
|
|
1659
|
+
L: 222,
|
|
1660
|
+
S: this,
|
|
1661
|
+
A: [
|
|
1662
|
+
"newData.state !== undefined",
|
|
1663
|
+
""
|
|
1664
|
+
]
|
|
1665
|
+
});
|
|
1275
1666
|
currentState = newData.state;
|
|
1276
1667
|
stream.next({
|
|
1277
1668
|
...invitation,
|
|
1278
1669
|
...newData
|
|
1279
1670
|
});
|
|
1280
1671
|
};
|
|
1281
|
-
const ctx = new
|
|
1672
|
+
const ctx = new import_context4.Context({
|
|
1282
1673
|
onError: (err) => {
|
|
1283
1674
|
if (err instanceof import_async5.TimeoutError) {
|
|
1284
|
-
(0,
|
|
1675
|
+
(0, import_log6.log)("timeout", {
|
|
1285
1676
|
...protocol.toJSON()
|
|
1286
1677
|
}, {
|
|
1287
|
-
F:
|
|
1678
|
+
F: __dxlog_file8,
|
|
1288
1679
|
L: 230,
|
|
1289
1680
|
S: this,
|
|
1290
1681
|
C: (f, a) => f(...a)
|
|
1291
1682
|
});
|
|
1292
1683
|
setState({
|
|
1293
|
-
state:
|
|
1684
|
+
state: import_services4.Invitation.State.TIMEOUT
|
|
1294
1685
|
});
|
|
1295
1686
|
} else {
|
|
1296
|
-
|
|
1297
|
-
F:
|
|
1687
|
+
import_log6.log.warn("auth failed", err, {
|
|
1688
|
+
F: __dxlog_file8,
|
|
1298
1689
|
L: 233,
|
|
1299
1690
|
S: this,
|
|
1300
1691
|
C: (f, a) => f(...a)
|
|
@@ -1305,10 +1696,10 @@ var InvitationsHandler = class {
|
|
|
1305
1696
|
}
|
|
1306
1697
|
});
|
|
1307
1698
|
ctx.onDispose(() => {
|
|
1308
|
-
(0,
|
|
1699
|
+
(0, import_log6.log)("complete", {
|
|
1309
1700
|
...protocol.toJSON()
|
|
1310
1701
|
}, {
|
|
1311
|
-
F:
|
|
1702
|
+
F: __dxlog_file8,
|
|
1312
1703
|
L: 241,
|
|
1313
1704
|
S: this,
|
|
1314
1705
|
C: (f, a) => f(...a)
|
|
@@ -1320,10 +1711,10 @@ var InvitationsHandler = class {
|
|
|
1320
1711
|
const extension = new InvitationGuestExtension({
|
|
1321
1712
|
onOpen: (extensionCtx) => {
|
|
1322
1713
|
extensionCtx.onDispose(async () => {
|
|
1323
|
-
(0,
|
|
1714
|
+
(0, import_log6.log)("extension disposed", {
|
|
1324
1715
|
currentState
|
|
1325
1716
|
}, {
|
|
1326
|
-
F:
|
|
1717
|
+
F: __dxlog_file8,
|
|
1327
1718
|
L: 251,
|
|
1328
1719
|
S: this,
|
|
1329
1720
|
C: (f, a) => f(...a)
|
|
@@ -1335,10 +1726,10 @@ var InvitationsHandler = class {
|
|
|
1335
1726
|
(0, import_async5.scheduleTask)(ctx, async () => {
|
|
1336
1727
|
const traceId = import_keys4.PublicKey.random().toHex();
|
|
1337
1728
|
try {
|
|
1338
|
-
|
|
1729
|
+
import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.begin({
|
|
1339
1730
|
id: traceId
|
|
1340
1731
|
}), {
|
|
1341
|
-
F:
|
|
1732
|
+
F: __dxlog_file8,
|
|
1342
1733
|
L: 260,
|
|
1343
1734
|
S: this,
|
|
1344
1735
|
C: (f, a) => f(...a)
|
|
@@ -1347,31 +1738,31 @@ var InvitationsHandler = class {
|
|
|
1347
1738
|
throw new Error(`multiple connections detected: ${connectionCount}`);
|
|
1348
1739
|
}
|
|
1349
1740
|
(0, import_async5.scheduleTask)(ctx, () => ctx.raise(new import_async5.TimeoutError(timeout)), timeout);
|
|
1350
|
-
(0,
|
|
1741
|
+
(0, import_log6.log)("connected", {
|
|
1351
1742
|
...protocol.toJSON()
|
|
1352
1743
|
}, {
|
|
1353
|
-
F:
|
|
1744
|
+
F: __dxlog_file8,
|
|
1354
1745
|
L: 268,
|
|
1355
1746
|
S: this,
|
|
1356
1747
|
C: (f, a) => f(...a)
|
|
1357
1748
|
});
|
|
1358
1749
|
setState({
|
|
1359
|
-
state:
|
|
1750
|
+
state: import_services4.Invitation.State.CONNECTED
|
|
1360
1751
|
});
|
|
1361
|
-
(0,
|
|
1752
|
+
(0, import_log6.log)("introduce", {
|
|
1362
1753
|
...protocol.toJSON()
|
|
1363
1754
|
}, {
|
|
1364
|
-
F:
|
|
1755
|
+
F: __dxlog_file8,
|
|
1365
1756
|
L: 272,
|
|
1366
1757
|
S: this,
|
|
1367
1758
|
C: (f, a) => f(...a)
|
|
1368
1759
|
});
|
|
1369
1760
|
const introductionResponse = await extension.rpc.InvitationHostService.introduce(protocol.createIntroduction());
|
|
1370
|
-
(0,
|
|
1761
|
+
(0, import_log6.log)("introduce response", {
|
|
1371
1762
|
...protocol.toJSON(),
|
|
1372
1763
|
response: introductionResponse
|
|
1373
1764
|
}, {
|
|
1374
|
-
F:
|
|
1765
|
+
F: __dxlog_file8,
|
|
1375
1766
|
L: 276,
|
|
1376
1767
|
S: this,
|
|
1377
1768
|
C: (f, a) => f(...a)
|
|
@@ -1382,26 +1773,26 @@ var InvitationsHandler = class {
|
|
|
1382
1773
|
}
|
|
1383
1774
|
if (isAuthenticationRequired(invitation)) {
|
|
1384
1775
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
1385
|
-
(0,
|
|
1386
|
-
F:
|
|
1776
|
+
(0, import_log6.log)("guest waiting for authentication code...", void 0, {
|
|
1777
|
+
F: __dxlog_file8,
|
|
1387
1778
|
L: 285,
|
|
1388
1779
|
S: this,
|
|
1389
1780
|
C: (f, a) => f(...a)
|
|
1390
1781
|
});
|
|
1391
1782
|
setState({
|
|
1392
|
-
state:
|
|
1783
|
+
state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1393
1784
|
});
|
|
1394
1785
|
const authCode = await authenticated.wait({
|
|
1395
1786
|
timeout
|
|
1396
1787
|
});
|
|
1397
|
-
(0,
|
|
1398
|
-
F:
|
|
1788
|
+
(0, import_log6.log)("sending authentication request", void 0, {
|
|
1789
|
+
F: __dxlog_file8,
|
|
1399
1790
|
L: 289,
|
|
1400
1791
|
S: this,
|
|
1401
1792
|
C: (f, a) => f(...a)
|
|
1402
1793
|
});
|
|
1403
1794
|
setState({
|
|
1404
|
-
state:
|
|
1795
|
+
state: import_services4.Invitation.State.AUTHENTICATING
|
|
1405
1796
|
});
|
|
1406
1797
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
1407
1798
|
authCode
|
|
@@ -1413,10 +1804,10 @@ var InvitationsHandler = class {
|
|
|
1413
1804
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
1414
1805
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
1415
1806
|
} else {
|
|
1416
|
-
(0,
|
|
1807
|
+
(0, import_log6.log)("retrying invalid code", {
|
|
1417
1808
|
attempt
|
|
1418
1809
|
}, {
|
|
1419
|
-
F:
|
|
1810
|
+
F: __dxlog_file8,
|
|
1420
1811
|
L: 300,
|
|
1421
1812
|
S: this,
|
|
1422
1813
|
C: (f, a) => f(...a)
|
|
@@ -1427,13 +1818,13 @@ var InvitationsHandler = class {
|
|
|
1427
1818
|
}
|
|
1428
1819
|
} else {
|
|
1429
1820
|
setState({
|
|
1430
|
-
state:
|
|
1821
|
+
state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1431
1822
|
});
|
|
1432
1823
|
}
|
|
1433
|
-
(0,
|
|
1824
|
+
(0, import_log6.log)("request admission", {
|
|
1434
1825
|
...protocol.toJSON()
|
|
1435
1826
|
}, {
|
|
1436
|
-
F:
|
|
1827
|
+
F: __dxlog_file8,
|
|
1437
1828
|
L: 311,
|
|
1438
1829
|
S: this,
|
|
1439
1830
|
C: (f, a) => f(...a)
|
|
@@ -1442,53 +1833,53 @@ var InvitationsHandler = class {
|
|
|
1442
1833
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
1443
1834
|
admitted = true;
|
|
1444
1835
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
1445
|
-
(0,
|
|
1836
|
+
(0, import_log6.log)("admitted by host", {
|
|
1446
1837
|
...protocol.toJSON()
|
|
1447
1838
|
}, {
|
|
1448
|
-
F:
|
|
1839
|
+
F: __dxlog_file8,
|
|
1449
1840
|
L: 322,
|
|
1450
1841
|
S: this,
|
|
1451
1842
|
C: (f, a) => f(...a)
|
|
1452
1843
|
});
|
|
1453
1844
|
setState({
|
|
1454
1845
|
...result,
|
|
1455
|
-
state:
|
|
1846
|
+
state: import_services4.Invitation.State.SUCCESS
|
|
1456
1847
|
});
|
|
1457
|
-
|
|
1848
|
+
import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.end({
|
|
1458
1849
|
id: traceId
|
|
1459
1850
|
}), {
|
|
1460
|
-
F:
|
|
1851
|
+
F: __dxlog_file8,
|
|
1461
1852
|
L: 324,
|
|
1462
1853
|
S: this,
|
|
1463
1854
|
C: (f, a) => f(...a)
|
|
1464
1855
|
});
|
|
1465
1856
|
} catch (err) {
|
|
1466
1857
|
if (err instanceof import_async5.TimeoutError) {
|
|
1467
|
-
(0,
|
|
1858
|
+
(0, import_log6.log)("timeout", {
|
|
1468
1859
|
...protocol.toJSON()
|
|
1469
1860
|
}, {
|
|
1470
|
-
F:
|
|
1861
|
+
F: __dxlog_file8,
|
|
1471
1862
|
L: 327,
|
|
1472
1863
|
S: this,
|
|
1473
1864
|
C: (f, a) => f(...a)
|
|
1474
1865
|
});
|
|
1475
1866
|
setState({
|
|
1476
|
-
state:
|
|
1867
|
+
state: import_services4.Invitation.State.TIMEOUT
|
|
1477
1868
|
});
|
|
1478
1869
|
} else {
|
|
1479
|
-
(0,
|
|
1480
|
-
F:
|
|
1870
|
+
(0, import_log6.log)("auth failed", err, {
|
|
1871
|
+
F: __dxlog_file8,
|
|
1481
1872
|
L: 330,
|
|
1482
1873
|
S: this,
|
|
1483
1874
|
C: (f, a) => f(...a)
|
|
1484
1875
|
});
|
|
1485
1876
|
stream.error(err);
|
|
1486
1877
|
}
|
|
1487
|
-
|
|
1878
|
+
import_log6.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols5.trace.error({
|
|
1488
1879
|
id: traceId,
|
|
1489
1880
|
error: err
|
|
1490
1881
|
}), {
|
|
1491
|
-
F:
|
|
1882
|
+
F: __dxlog_file8,
|
|
1492
1883
|
L: 333,
|
|
1493
1884
|
S: this,
|
|
1494
1885
|
C: (f, a) => f(...a)
|
|
@@ -1503,20 +1894,20 @@ var InvitationsHandler = class {
|
|
|
1503
1894
|
return;
|
|
1504
1895
|
}
|
|
1505
1896
|
if (err instanceof import_async5.TimeoutError) {
|
|
1506
|
-
(0,
|
|
1897
|
+
(0, import_log6.log)("timeout", {
|
|
1507
1898
|
...protocol.toJSON()
|
|
1508
1899
|
}, {
|
|
1509
|
-
F:
|
|
1900
|
+
F: __dxlog_file8,
|
|
1510
1901
|
L: 344,
|
|
1511
1902
|
S: this,
|
|
1512
1903
|
C: (f, a) => f(...a)
|
|
1513
1904
|
});
|
|
1514
1905
|
setState({
|
|
1515
|
-
state:
|
|
1906
|
+
state: import_services4.Invitation.State.TIMEOUT
|
|
1516
1907
|
});
|
|
1517
1908
|
} else {
|
|
1518
|
-
(0,
|
|
1519
|
-
F:
|
|
1909
|
+
(0, import_log6.log)("auth failed", err, {
|
|
1910
|
+
F: __dxlog_file8,
|
|
1520
1911
|
L: 347,
|
|
1521
1912
|
S: this,
|
|
1522
1913
|
C: (f, a) => f(...a)
|
|
@@ -1528,7 +1919,15 @@ var InvitationsHandler = class {
|
|
|
1528
1919
|
return extension;
|
|
1529
1920
|
};
|
|
1530
1921
|
(0, import_async5.scheduleTask)(ctx, async () => {
|
|
1531
|
-
(0,
|
|
1922
|
+
(0, import_invariant7.invariant)(invitation.swarmKey, void 0, {
|
|
1923
|
+
F: __dxlog_file8,
|
|
1924
|
+
L: 357,
|
|
1925
|
+
S: this,
|
|
1926
|
+
A: [
|
|
1927
|
+
"invitation.swarmKey",
|
|
1928
|
+
""
|
|
1929
|
+
]
|
|
1930
|
+
});
|
|
1532
1931
|
const topic = invitation.swarmKey;
|
|
1533
1932
|
const swarmConnection = await this._networkManager.joinSwarm({
|
|
1534
1933
|
topic,
|
|
@@ -1536,11 +1935,12 @@ var InvitationsHandler = class {
|
|
|
1536
1935
|
protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
|
|
1537
1936
|
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
1538
1937
|
}),
|
|
1539
|
-
topology: new import_network_manager.StarTopology(topic)
|
|
1938
|
+
topology: new import_network_manager.StarTopology(topic),
|
|
1939
|
+
label: "invitation guest"
|
|
1540
1940
|
});
|
|
1541
1941
|
ctx.onDispose(() => swarmConnection.close());
|
|
1542
1942
|
setState({
|
|
1543
|
-
state:
|
|
1943
|
+
state: import_services4.Invitation.State.CONNECTING
|
|
1544
1944
|
});
|
|
1545
1945
|
});
|
|
1546
1946
|
const observable = new import_client_protocol2.AuthenticatingInvitationObservable({
|
|
@@ -1548,7 +1948,7 @@ var InvitationsHandler = class {
|
|
|
1548
1948
|
subscriber: stream.observable,
|
|
1549
1949
|
onCancel: async () => {
|
|
1550
1950
|
setState({
|
|
1551
|
-
state:
|
|
1951
|
+
state: import_services4.Invitation.State.CANCELLED
|
|
1552
1952
|
});
|
|
1553
1953
|
await ctx.dispose();
|
|
1554
1954
|
},
|
|
@@ -1561,12 +1961,12 @@ var InvitationsHandler = class {
|
|
|
1561
1961
|
};
|
|
1562
1962
|
|
|
1563
1963
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
1564
|
-
var import_tiny_invariant7 = __toESM(require("tiny-invariant"));
|
|
1565
1964
|
var import_async6 = require("@dxos/async");
|
|
1566
|
-
var
|
|
1567
|
-
var
|
|
1568
|
-
var
|
|
1569
|
-
var
|
|
1965
|
+
var import_codec_protobuf4 = require("@dxos/codec-protobuf");
|
|
1966
|
+
var import_invariant8 = require("@dxos/invariant");
|
|
1967
|
+
var import_log7 = require("@dxos/log");
|
|
1968
|
+
var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1969
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
|
|
1570
1970
|
var InvitationsServiceImpl = class {
|
|
1571
1971
|
constructor(_invitationsHandler, _getHandler) {
|
|
1572
1972
|
this._invitationsHandler = _invitationsHandler;
|
|
@@ -1593,7 +1993,7 @@ var InvitationsServiceImpl = class {
|
|
|
1593
1993
|
this._createInvitations.set(invitation.get().invitationId, invitation);
|
|
1594
1994
|
this._invitationCreated.emit(invitation.get());
|
|
1595
1995
|
}
|
|
1596
|
-
return new
|
|
1996
|
+
return new import_codec_protobuf4.Stream(({ next, close }) => {
|
|
1597
1997
|
invitation.subscribe((invitation2) => {
|
|
1598
1998
|
next(invitation2);
|
|
1599
1999
|
}, (err) => {
|
|
@@ -1615,7 +2015,7 @@ var InvitationsServiceImpl = class {
|
|
|
1615
2015
|
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
1616
2016
|
this._invitationAccepted.emit(invitation.get());
|
|
1617
2017
|
}
|
|
1618
|
-
return new
|
|
2018
|
+
return new import_codec_protobuf4.Stream(({ next, close }) => {
|
|
1619
2019
|
invitation.subscribe((invitation2) => {
|
|
1620
2020
|
next(invitation2);
|
|
1621
2021
|
}, (err) => {
|
|
@@ -1627,20 +2027,28 @@ var InvitationsServiceImpl = class {
|
|
|
1627
2027
|
});
|
|
1628
2028
|
}
|
|
1629
2029
|
async authenticate({ invitationId, authCode }) {
|
|
1630
|
-
(0,
|
|
1631
|
-
F:
|
|
1632
|
-
L:
|
|
2030
|
+
(0, import_log7.log)("authenticating...", void 0, {
|
|
2031
|
+
F: __dxlog_file9,
|
|
2032
|
+
L: 102,
|
|
1633
2033
|
S: this,
|
|
1634
2034
|
C: (f, a) => f(...a)
|
|
1635
2035
|
});
|
|
1636
|
-
(0,
|
|
2036
|
+
(0, import_invariant8.invariant)(invitationId, void 0, {
|
|
2037
|
+
F: __dxlog_file9,
|
|
2038
|
+
L: 103,
|
|
2039
|
+
S: this,
|
|
2040
|
+
A: [
|
|
2041
|
+
"invitationId",
|
|
2042
|
+
""
|
|
2043
|
+
]
|
|
2044
|
+
});
|
|
1637
2045
|
const observable = this._acceptInvitations.get(invitationId);
|
|
1638
2046
|
if (!observable) {
|
|
1639
|
-
|
|
2047
|
+
import_log7.log.warn("invalid invitation", {
|
|
1640
2048
|
invitationId
|
|
1641
2049
|
}, {
|
|
1642
|
-
F:
|
|
1643
|
-
L:
|
|
2050
|
+
F: __dxlog_file9,
|
|
2051
|
+
L: 106,
|
|
1644
2052
|
S: this,
|
|
1645
2053
|
C: (f, a) => f(...a)
|
|
1646
2054
|
});
|
|
@@ -1649,13 +2057,21 @@ var InvitationsServiceImpl = class {
|
|
|
1649
2057
|
}
|
|
1650
2058
|
}
|
|
1651
2059
|
async cancelInvitation({ invitationId }) {
|
|
1652
|
-
(0,
|
|
1653
|
-
F:
|
|
1654
|
-
L:
|
|
2060
|
+
(0, import_log7.log)("deleting...", void 0, {
|
|
2061
|
+
F: __dxlog_file9,
|
|
2062
|
+
L: 113,
|
|
1655
2063
|
S: this,
|
|
1656
2064
|
C: (f, a) => f(...a)
|
|
1657
2065
|
});
|
|
1658
|
-
(0,
|
|
2066
|
+
(0, import_invariant8.invariant)(invitationId, void 0, {
|
|
2067
|
+
F: __dxlog_file9,
|
|
2068
|
+
L: 114,
|
|
2069
|
+
S: this,
|
|
2070
|
+
A: [
|
|
2071
|
+
"invitationId",
|
|
2072
|
+
""
|
|
2073
|
+
]
|
|
2074
|
+
});
|
|
1659
2075
|
const created = this._createInvitations.get(invitationId);
|
|
1660
2076
|
const accepted = this._acceptInvitations.get(invitationId);
|
|
1661
2077
|
if (created) {
|
|
@@ -1667,22 +2083,22 @@ var InvitationsServiceImpl = class {
|
|
|
1667
2083
|
this._acceptInvitations.delete(invitationId);
|
|
1668
2084
|
this._removedAccepted.emit(accepted.get());
|
|
1669
2085
|
} else {
|
|
1670
|
-
|
|
2086
|
+
import_log7.log.warn("invalid invitation", {
|
|
1671
2087
|
invitationId
|
|
1672
2088
|
}, {
|
|
1673
|
-
F:
|
|
1674
|
-
L:
|
|
2089
|
+
F: __dxlog_file9,
|
|
2090
|
+
L: 126,
|
|
1675
2091
|
S: this,
|
|
1676
2092
|
C: (f, a) => f(...a)
|
|
1677
2093
|
});
|
|
1678
2094
|
}
|
|
1679
2095
|
}
|
|
1680
2096
|
queryInvitations() {
|
|
1681
|
-
return new
|
|
2097
|
+
return new import_codec_protobuf4.Stream(({ next, ctx }) => {
|
|
1682
2098
|
this._invitationCreated.on(ctx, (invitation) => {
|
|
1683
2099
|
next({
|
|
1684
|
-
action:
|
|
1685
|
-
type:
|
|
2100
|
+
action: import_services5.QueryInvitationsResponse.Action.ADDED,
|
|
2101
|
+
type: import_services5.QueryInvitationsResponse.Type.CREATED,
|
|
1686
2102
|
invitations: [
|
|
1687
2103
|
invitation
|
|
1688
2104
|
]
|
|
@@ -1690,8 +2106,8 @@ var InvitationsServiceImpl = class {
|
|
|
1690
2106
|
});
|
|
1691
2107
|
this._invitationAccepted.on(ctx, (invitation) => {
|
|
1692
2108
|
next({
|
|
1693
|
-
action:
|
|
1694
|
-
type:
|
|
2109
|
+
action: import_services5.QueryInvitationsResponse.Action.ADDED,
|
|
2110
|
+
type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
|
|
1695
2111
|
invitations: [
|
|
1696
2112
|
invitation
|
|
1697
2113
|
]
|
|
@@ -1699,8 +2115,8 @@ var InvitationsServiceImpl = class {
|
|
|
1699
2115
|
});
|
|
1700
2116
|
this._removedCreated.on(ctx, (invitation) => {
|
|
1701
2117
|
next({
|
|
1702
|
-
action:
|
|
1703
|
-
type:
|
|
2118
|
+
action: import_services5.QueryInvitationsResponse.Action.REMOVED,
|
|
2119
|
+
type: import_services5.QueryInvitationsResponse.Type.CREATED,
|
|
1704
2120
|
invitations: [
|
|
1705
2121
|
invitation
|
|
1706
2122
|
]
|
|
@@ -1708,21 +2124,21 @@ var InvitationsServiceImpl = class {
|
|
|
1708
2124
|
});
|
|
1709
2125
|
this._removedAccepted.on(ctx, (invitation) => {
|
|
1710
2126
|
next({
|
|
1711
|
-
action:
|
|
1712
|
-
type:
|
|
2127
|
+
action: import_services5.QueryInvitationsResponse.Action.REMOVED,
|
|
2128
|
+
type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
|
|
1713
2129
|
invitations: [
|
|
1714
2130
|
invitation
|
|
1715
2131
|
]
|
|
1716
2132
|
});
|
|
1717
2133
|
});
|
|
1718
2134
|
next({
|
|
1719
|
-
action:
|
|
1720
|
-
type:
|
|
2135
|
+
action: import_services5.QueryInvitationsResponse.Action.ADDED,
|
|
2136
|
+
type: import_services5.QueryInvitationsResponse.Type.CREATED,
|
|
1721
2137
|
invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
|
|
1722
2138
|
});
|
|
1723
2139
|
next({
|
|
1724
|
-
action:
|
|
1725
|
-
type:
|
|
2140
|
+
action: import_services5.QueryInvitationsResponse.Action.ADDED,
|
|
2141
|
+
type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
|
|
1726
2142
|
invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
|
|
1727
2143
|
});
|
|
1728
2144
|
});
|
|
@@ -1730,12 +2146,12 @@ var InvitationsServiceImpl = class {
|
|
|
1730
2146
|
};
|
|
1731
2147
|
|
|
1732
2148
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
1733
|
-
var
|
|
1734
|
-
var import_credentials9 = require("@dxos/credentials");
|
|
2149
|
+
var import_credentials10 = require("@dxos/credentials");
|
|
1735
2150
|
var import_feed_store2 = require("@dxos/feed-store");
|
|
1736
|
-
var
|
|
1737
|
-
var
|
|
1738
|
-
var
|
|
2151
|
+
var import_invariant9 = require("@dxos/invariant");
|
|
2152
|
+
var import_log8 = require("@dxos/log");
|
|
2153
|
+
var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2154
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
1739
2155
|
var SpaceInvitationProtocol = class {
|
|
1740
2156
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
1741
2157
|
this._spaceManager = _spaceManager;
|
|
@@ -1751,36 +2167,75 @@ var SpaceInvitationProtocol = class {
|
|
|
1751
2167
|
}
|
|
1752
2168
|
getInvitationContext() {
|
|
1753
2169
|
return {
|
|
1754
|
-
kind:
|
|
2170
|
+
kind: import_services6.Invitation.Kind.SPACE,
|
|
1755
2171
|
spaceKey: this._spaceKey
|
|
1756
2172
|
};
|
|
1757
2173
|
}
|
|
1758
2174
|
async admit(request, guestProfile) {
|
|
1759
|
-
|
|
1760
|
-
|
|
2175
|
+
(0, import_invariant9.invariant)(this._spaceKey, void 0, {
|
|
2176
|
+
F: __dxlog_file10,
|
|
2177
|
+
L: 42,
|
|
2178
|
+
S: this,
|
|
2179
|
+
A: [
|
|
2180
|
+
"this._spaceKey",
|
|
2181
|
+
""
|
|
2182
|
+
]
|
|
2183
|
+
});
|
|
1761
2184
|
const space = await this._spaceManager.spaces.get(this._spaceKey);
|
|
1762
|
-
(0,
|
|
1763
|
-
|
|
2185
|
+
(0, import_invariant9.invariant)(space, void 0, {
|
|
2186
|
+
F: __dxlog_file10,
|
|
2187
|
+
L: 44,
|
|
2188
|
+
S: this,
|
|
2189
|
+
A: [
|
|
2190
|
+
"space",
|
|
2191
|
+
""
|
|
2192
|
+
]
|
|
2193
|
+
});
|
|
2194
|
+
(0, import_invariant9.invariant)(request.space, void 0, {
|
|
2195
|
+
F: __dxlog_file10,
|
|
2196
|
+
L: 46,
|
|
2197
|
+
S: this,
|
|
2198
|
+
A: [
|
|
2199
|
+
"request.space",
|
|
2200
|
+
""
|
|
2201
|
+
]
|
|
2202
|
+
});
|
|
1764
2203
|
const { identityKey, deviceKey } = request.space;
|
|
1765
|
-
(0,
|
|
2204
|
+
(0, import_log8.log)("writing guest credentials", {
|
|
1766
2205
|
host: this._signingContext.deviceKey,
|
|
1767
2206
|
guest: deviceKey
|
|
1768
2207
|
}, {
|
|
1769
|
-
F:
|
|
1770
|
-
L:
|
|
2208
|
+
F: __dxlog_file10,
|
|
2209
|
+
L: 49,
|
|
1771
2210
|
S: this,
|
|
1772
2211
|
C: (f, a) => f(...a)
|
|
1773
2212
|
});
|
|
1774
|
-
const credentials = await (0,
|
|
1775
|
-
(0,
|
|
2213
|
+
const credentials = await (0, import_credentials10.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
|
|
2214
|
+
(0, import_invariant9.invariant)(credentials[0].credential, void 0, {
|
|
2215
|
+
F: __dxlog_file10,
|
|
2216
|
+
L: 60,
|
|
2217
|
+
S: this,
|
|
2218
|
+
A: [
|
|
2219
|
+
"credentials[0].credential",
|
|
2220
|
+
""
|
|
2221
|
+
]
|
|
2222
|
+
});
|
|
1776
2223
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
1777
|
-
(0,
|
|
2224
|
+
(0, import_invariant9.invariant)((0, import_credentials10.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2225
|
+
F: __dxlog_file10,
|
|
2226
|
+
L: 62,
|
|
2227
|
+
S: this,
|
|
2228
|
+
A: [
|
|
2229
|
+
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
2230
|
+
""
|
|
2231
|
+
]
|
|
2232
|
+
});
|
|
1778
2233
|
await (0, import_feed_store2.writeMessages)(space.inner.controlPipeline.writer, credentials);
|
|
1779
2234
|
return {
|
|
1780
2235
|
space: {
|
|
1781
2236
|
credential: spaceMemberCredential,
|
|
1782
2237
|
controlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
1783
|
-
dataTimeframe:
|
|
2238
|
+
dataTimeframe: space.dataPipeline.pipelineState?.timeframe
|
|
1784
2239
|
}
|
|
1785
2240
|
};
|
|
1786
2241
|
}
|
|
@@ -1802,11 +2257,35 @@ var SpaceInvitationProtocol = class {
|
|
|
1802
2257
|
};
|
|
1803
2258
|
}
|
|
1804
2259
|
async accept(response) {
|
|
1805
|
-
(0,
|
|
2260
|
+
(0, import_invariant9.invariant)(response.space, void 0, {
|
|
2261
|
+
F: __dxlog_file10,
|
|
2262
|
+
L: 97,
|
|
2263
|
+
S: this,
|
|
2264
|
+
A: [
|
|
2265
|
+
"response.space",
|
|
2266
|
+
""
|
|
2267
|
+
]
|
|
2268
|
+
});
|
|
1806
2269
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
1807
|
-
const assertion = (0,
|
|
1808
|
-
(0,
|
|
1809
|
-
|
|
2270
|
+
const assertion = (0, import_credentials10.getCredentialAssertion)(credential);
|
|
2271
|
+
(0, import_invariant9.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
2272
|
+
F: __dxlog_file10,
|
|
2273
|
+
L: 100,
|
|
2274
|
+
S: this,
|
|
2275
|
+
A: [
|
|
2276
|
+
"assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
2277
|
+
"'Invalid credential'"
|
|
2278
|
+
]
|
|
2279
|
+
});
|
|
2280
|
+
(0, import_invariant9.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
2281
|
+
F: __dxlog_file10,
|
|
2282
|
+
L: 101,
|
|
2283
|
+
S: this,
|
|
2284
|
+
A: [
|
|
2285
|
+
"credential.subject.id.equals(this._signingContext.identityKey)",
|
|
2286
|
+
""
|
|
2287
|
+
]
|
|
2288
|
+
});
|
|
1810
2289
|
await this._spaceManager.acceptSpace({
|
|
1811
2290
|
spaceKey: assertion.spaceKey,
|
|
1812
2291
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
@@ -1821,48 +2300,48 @@ var SpaceInvitationProtocol = class {
|
|
|
1821
2300
|
};
|
|
1822
2301
|
|
|
1823
2302
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
1824
|
-
var import_tiny_invariant10 = __toESM(require("tiny-invariant"));
|
|
1825
2303
|
var import_async9 = require("@dxos/async");
|
|
1826
|
-
var
|
|
1827
|
-
var
|
|
2304
|
+
var import_context7 = require("@dxos/context");
|
|
2305
|
+
var import_credentials14 = require("@dxos/credentials");
|
|
2306
|
+
var import_invariant11 = require("@dxos/invariant");
|
|
1828
2307
|
var import_keys7 = require("@dxos/keys");
|
|
1829
|
-
var
|
|
1830
|
-
var
|
|
1831
|
-
var
|
|
2308
|
+
var import_log11 = require("@dxos/log");
|
|
2309
|
+
var import_protocols7 = require("@dxos/protocols");
|
|
2310
|
+
var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
|
|
1832
2311
|
var import_teleport_extension_gossip = require("@dxos/teleport-extension-gossip");
|
|
1833
2312
|
var import_util4 = require("@dxos/util");
|
|
1834
2313
|
|
|
1835
2314
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
1836
2315
|
var import_async8 = require("@dxos/async");
|
|
1837
2316
|
var import_client_protocol3 = require("@dxos/client-protocol");
|
|
1838
|
-
var
|
|
2317
|
+
var import_context6 = require("@dxos/context");
|
|
1839
2318
|
var import_debug4 = require("@dxos/debug");
|
|
1840
2319
|
var import_echo_pipeline = require("@dxos/echo-pipeline");
|
|
1841
2320
|
var import_errors3 = require("@dxos/errors");
|
|
1842
2321
|
var import_keys6 = require("@dxos/keys");
|
|
1843
|
-
var
|
|
1844
|
-
var
|
|
1845
|
-
var
|
|
1846
|
-
var
|
|
2322
|
+
var import_log10 = require("@dxos/log");
|
|
2323
|
+
var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2324
|
+
var import_credentials11 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
2325
|
+
var import_timeframe2 = require("@dxos/timeframe");
|
|
1847
2326
|
var import_util3 = require("@dxos/util");
|
|
1848
2327
|
|
|
1849
2328
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
1850
|
-
var import_tiny_invariant9 = __toESM(require("tiny-invariant"));
|
|
1851
2329
|
var import_async7 = require("@dxos/async");
|
|
1852
|
-
var
|
|
2330
|
+
var import_context5 = require("@dxos/context");
|
|
2331
|
+
var import_invariant10 = require("@dxos/invariant");
|
|
1853
2332
|
var import_keys5 = require("@dxos/keys");
|
|
1854
|
-
var
|
|
1855
|
-
var
|
|
2333
|
+
var import_log9 = require("@dxos/log");
|
|
2334
|
+
var import_protocols6 = require("@dxos/protocols");
|
|
1856
2335
|
var import_teleport2 = require("@dxos/teleport");
|
|
1857
2336
|
var import_util2 = require("@dxos/util");
|
|
1858
|
-
var
|
|
2337
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
1859
2338
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
1860
2339
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
1861
2340
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
1862
2341
|
var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
|
|
1863
2342
|
var NotarizationPlugin = class {
|
|
1864
2343
|
constructor() {
|
|
1865
|
-
this._ctx = new
|
|
2344
|
+
this._ctx = new import_context5.Context();
|
|
1866
2345
|
this._extensionOpened = new import_async7.Event();
|
|
1867
2346
|
this._extensions = /* @__PURE__ */ new Set();
|
|
1868
2347
|
this._processedCredentials = new import_util2.ComplexSet(import_keys5.PublicKey.hash);
|
|
@@ -1880,23 +2359,31 @@ var NotarizationPlugin = class {
|
|
|
1880
2359
|
* Request credentials to be notarized.
|
|
1881
2360
|
*/
|
|
1882
2361
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
1883
|
-
(0,
|
|
2362
|
+
(0, import_log9.log)("notarize", {
|
|
1884
2363
|
credentials
|
|
1885
2364
|
}, {
|
|
1886
|
-
F:
|
|
2365
|
+
F: __dxlog_file11,
|
|
2366
|
+
L: 90,
|
|
2367
|
+
S: this,
|
|
2368
|
+
C: (f, a) => f(...a)
|
|
2369
|
+
});
|
|
2370
|
+
(0, import_invariant10.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
2371
|
+
F: __dxlog_file11,
|
|
1887
2372
|
L: 91,
|
|
1888
2373
|
S: this,
|
|
1889
|
-
|
|
2374
|
+
A: [
|
|
2375
|
+
"credentials.every((credential) => credential.id)",
|
|
2376
|
+
"'Credentials must have an id'"
|
|
2377
|
+
]
|
|
1890
2378
|
});
|
|
1891
|
-
(0, import_tiny_invariant9.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
|
|
1892
2379
|
const errors = new import_async7.Trigger();
|
|
1893
2380
|
const ctx = this._ctx.derive({
|
|
1894
2381
|
onError: (err) => {
|
|
1895
|
-
|
|
2382
|
+
import_log9.log.warn("Notarization error", {
|
|
1896
2383
|
err
|
|
1897
2384
|
}, {
|
|
1898
|
-
F:
|
|
1899
|
-
L:
|
|
2385
|
+
F: __dxlog_file11,
|
|
2386
|
+
L: 99,
|
|
1900
2387
|
S: this,
|
|
1901
2388
|
C: (f, a) => f(...a)
|
|
1902
2389
|
});
|
|
@@ -1904,15 +2391,15 @@ var NotarizationPlugin = class {
|
|
|
1904
2391
|
errors.throw(err);
|
|
1905
2392
|
}
|
|
1906
2393
|
});
|
|
1907
|
-
opCtx
|
|
2394
|
+
opCtx?.onDispose(() => ctx.dispose());
|
|
1908
2395
|
if (timeout !== 0) {
|
|
1909
2396
|
(0, import_async7.scheduleTask)(ctx, () => {
|
|
1910
|
-
|
|
2397
|
+
import_log9.log.warn("Notarization timeout", {
|
|
1911
2398
|
timeout,
|
|
1912
2399
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
1913
2400
|
}, {
|
|
1914
|
-
F:
|
|
1915
|
-
L:
|
|
2401
|
+
F: __dxlog_file11,
|
|
2402
|
+
L: 111,
|
|
1916
2403
|
S: this,
|
|
1917
2404
|
C: (f, a) => f(...a)
|
|
1918
2405
|
});
|
|
@@ -1931,11 +2418,11 @@ var NotarizationPlugin = class {
|
|
|
1931
2418
|
...this._extensions
|
|
1932
2419
|
].find((peer2) => !peersTried.has(peer2));
|
|
1933
2420
|
if (!peer) {
|
|
1934
|
-
|
|
2421
|
+
import_log9.log.warn("Exhausted all peers to notarize with", {
|
|
1935
2422
|
retryIn: retryTimeout
|
|
1936
2423
|
}, {
|
|
1937
|
-
F:
|
|
1938
|
-
L:
|
|
2424
|
+
F: __dxlog_file11,
|
|
2425
|
+
L: 136,
|
|
1939
2426
|
S: this,
|
|
1940
2427
|
C: (f, a) => f(...a)
|
|
1941
2428
|
});
|
|
@@ -1944,30 +2431,30 @@ var NotarizationPlugin = class {
|
|
|
1944
2431
|
return;
|
|
1945
2432
|
}
|
|
1946
2433
|
peersTried.add(peer);
|
|
1947
|
-
(0,
|
|
2434
|
+
(0, import_log9.log)("try notarizing", {
|
|
1948
2435
|
peer: peer.localPeerId,
|
|
1949
2436
|
credentialId: credentials.map((credential) => credential.id)
|
|
1950
2437
|
}, {
|
|
1951
|
-
F:
|
|
1952
|
-
L:
|
|
2438
|
+
F: __dxlog_file11,
|
|
2439
|
+
L: 143,
|
|
1953
2440
|
S: this,
|
|
1954
2441
|
C: (f, a) => f(...a)
|
|
1955
2442
|
});
|
|
1956
2443
|
await peer.rpc.NotarizationService.notarize({
|
|
1957
2444
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
1958
2445
|
});
|
|
1959
|
-
(0,
|
|
1960
|
-
F:
|
|
1961
|
-
L:
|
|
2446
|
+
(0, import_log9.log)("success", void 0, {
|
|
2447
|
+
F: __dxlog_file11,
|
|
2448
|
+
L: 147,
|
|
1962
2449
|
S: this,
|
|
1963
2450
|
C: (f, a) => f(...a)
|
|
1964
2451
|
});
|
|
1965
2452
|
await (0, import_async7.sleep)(successDelay);
|
|
1966
2453
|
} catch (err) {
|
|
1967
2454
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
1968
|
-
|
|
1969
|
-
F:
|
|
1970
|
-
L:
|
|
2455
|
+
import_log9.log.warn("error notarizing (recoverable)", err, {
|
|
2456
|
+
F: __dxlog_file11,
|
|
2457
|
+
L: 151,
|
|
1971
2458
|
S: this,
|
|
1972
2459
|
C: (f, a) => f(...a)
|
|
1973
2460
|
});
|
|
@@ -1979,13 +2466,13 @@ var NotarizationPlugin = class {
|
|
|
1979
2466
|
this._extensionOpened.on(ctx, () => notarizeTask.schedule());
|
|
1980
2467
|
try {
|
|
1981
2468
|
await Promise.race([
|
|
1982
|
-
(0,
|
|
2469
|
+
(0, import_context5.rejectOnDispose)(ctx),
|
|
1983
2470
|
allNotarized,
|
|
1984
2471
|
errors.wait()
|
|
1985
2472
|
]);
|
|
1986
|
-
(0,
|
|
1987
|
-
F:
|
|
1988
|
-
L:
|
|
2473
|
+
(0, import_log9.log)("done", void 0, {
|
|
2474
|
+
F: __dxlog_file11,
|
|
2475
|
+
L: 162,
|
|
1989
2476
|
S: this,
|
|
1990
2477
|
C: (f, a) => f(...a)
|
|
1991
2478
|
});
|
|
@@ -1997,16 +2484,23 @@ var NotarizationPlugin = class {
|
|
|
1997
2484
|
* Called with credentials arriving from the control pipeline.
|
|
1998
2485
|
*/
|
|
1999
2486
|
async processCredential(credential) {
|
|
2000
|
-
var _a;
|
|
2001
2487
|
if (!credential.id) {
|
|
2002
2488
|
return;
|
|
2003
2489
|
}
|
|
2004
|
-
|
|
2490
|
+
this._processCredentialsTriggers.get(credential.id)?.wake();
|
|
2005
2491
|
this._processedCredentials.add(credential.id);
|
|
2006
2492
|
this._processCredentialsTriggers.delete(credential.id);
|
|
2007
2493
|
}
|
|
2008
2494
|
setWriter(writer) {
|
|
2009
|
-
(0,
|
|
2495
|
+
(0, import_invariant10.invariant)(!this._writer, "Writer already set.", {
|
|
2496
|
+
F: __dxlog_file11,
|
|
2497
|
+
L: 181,
|
|
2498
|
+
S: this,
|
|
2499
|
+
A: [
|
|
2500
|
+
"!this._writer",
|
|
2501
|
+
"'Writer already set.'"
|
|
2502
|
+
]
|
|
2503
|
+
});
|
|
2010
2504
|
this._writer = writer;
|
|
2011
2505
|
}
|
|
2012
2506
|
async _waitUntilProcessed(id) {
|
|
@@ -2019,12 +2513,19 @@ var NotarizationPlugin = class {
|
|
|
2019
2513
|
* Requests from other peers to notarize credentials.
|
|
2020
2514
|
*/
|
|
2021
2515
|
async _onNotarize(request) {
|
|
2022
|
-
var _a;
|
|
2023
2516
|
if (!this._writer) {
|
|
2024
2517
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
2025
2518
|
}
|
|
2026
|
-
for (const credential of
|
|
2027
|
-
(0,
|
|
2519
|
+
for (const credential of request.credentials ?? []) {
|
|
2520
|
+
(0, import_invariant10.invariant)(credential.id, "Credential must have an id", {
|
|
2521
|
+
F: __dxlog_file11,
|
|
2522
|
+
L: 200,
|
|
2523
|
+
S: this,
|
|
2524
|
+
A: [
|
|
2525
|
+
"credential.id",
|
|
2526
|
+
"'Credential must have an id'"
|
|
2527
|
+
]
|
|
2528
|
+
});
|
|
2028
2529
|
if (this._processedCredentials.has(credential.id)) {
|
|
2029
2530
|
continue;
|
|
2030
2531
|
}
|
|
@@ -2034,11 +2535,11 @@ var NotarizationPlugin = class {
|
|
|
2034
2535
|
createExtension() {
|
|
2035
2536
|
const extension = new NotarizationTeleportExtension({
|
|
2036
2537
|
onOpen: async () => {
|
|
2037
|
-
(0,
|
|
2538
|
+
(0, import_log9.log)("extension opened", {
|
|
2038
2539
|
peer: extension.localPeerId
|
|
2039
2540
|
}, {
|
|
2040
|
-
F:
|
|
2041
|
-
L:
|
|
2541
|
+
F: __dxlog_file11,
|
|
2542
|
+
L: 211,
|
|
2042
2543
|
S: this,
|
|
2043
2544
|
C: (f, a) => f(...a)
|
|
2044
2545
|
});
|
|
@@ -2046,11 +2547,11 @@ var NotarizationPlugin = class {
|
|
|
2046
2547
|
this._extensionOpened.emit();
|
|
2047
2548
|
},
|
|
2048
2549
|
onClose: async () => {
|
|
2049
|
-
(0,
|
|
2550
|
+
(0, import_log9.log)("extension closed", {
|
|
2050
2551
|
peer: extension.localPeerId
|
|
2051
2552
|
}, {
|
|
2052
|
-
F:
|
|
2053
|
-
L:
|
|
2553
|
+
F: __dxlog_file11,
|
|
2554
|
+
L: 216,
|
|
2054
2555
|
S: this,
|
|
2055
2556
|
C: (f, a) => f(...a)
|
|
2056
2557
|
});
|
|
@@ -2065,10 +2566,10 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
|
|
|
2065
2566
|
constructor(_params) {
|
|
2066
2567
|
super({
|
|
2067
2568
|
requested: {
|
|
2068
|
-
NotarizationService:
|
|
2569
|
+
NotarizationService: import_protocols6.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
2069
2570
|
},
|
|
2070
2571
|
exposed: {
|
|
2071
|
-
NotarizationService:
|
|
2572
|
+
NotarizationService: import_protocols6.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
2072
2573
|
}
|
|
2073
2574
|
});
|
|
2074
2575
|
this._params = _params;
|
|
@@ -2093,7 +2594,7 @@ var NotarizationTeleportExtension = class extends import_teleport2.RpcExtension
|
|
|
2093
2594
|
};
|
|
2094
2595
|
|
|
2095
2596
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2096
|
-
function
|
|
2597
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
2097
2598
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2098
2599
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2099
2600
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2103,19 +2604,19 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
2103
2604
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2104
2605
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2105
2606
|
}
|
|
2106
|
-
var
|
|
2607
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
2608
|
+
var ENABLE_FEED_PURGE = false;
|
|
2107
2609
|
var DataSpace = class DataSpace2 {
|
|
2108
2610
|
constructor(params) {
|
|
2109
|
-
this._ctx = new
|
|
2611
|
+
this._ctx = new import_context6.Context();
|
|
2110
2612
|
this._notarizationPlugin = new NotarizationPlugin();
|
|
2111
|
-
this._state =
|
|
2613
|
+
this._state = import_services7.SpaceState.CLOSED;
|
|
2112
2614
|
/**
|
|
2113
2615
|
* Error for _state === SpaceState.ERROR.
|
|
2114
2616
|
*/
|
|
2115
2617
|
this.error = void 0;
|
|
2116
2618
|
this.stateUpdate = new import_async8.Event();
|
|
2117
2619
|
this.metrics = {};
|
|
2118
|
-
var _a;
|
|
2119
2620
|
this._inner = params.inner;
|
|
2120
2621
|
this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
|
|
2121
2622
|
this._gossip = params.gossip;
|
|
@@ -2124,7 +2625,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2124
2625
|
this._feedStore = params.feedStore;
|
|
2125
2626
|
this._metadataStore = params.metadataStore;
|
|
2126
2627
|
this._signingContext = params.signingContext;
|
|
2127
|
-
this._callbacks =
|
|
2628
|
+
this._callbacks = params.callbacks ?? {};
|
|
2128
2629
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
2129
2630
|
trustedKeysProvider: () => new import_util3.ComplexSet(import_keys6.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
|
|
2130
2631
|
update: this._inner.stateUpdate,
|
|
@@ -2164,21 +2665,20 @@ var DataSpace = class DataSpace2 {
|
|
|
2164
2665
|
async _open() {
|
|
2165
2666
|
await this._notarizationPlugin.open();
|
|
2166
2667
|
await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
|
|
2167
|
-
await this._inner.open();
|
|
2168
|
-
this._state =
|
|
2668
|
+
await this._inner.open(new import_context6.Context());
|
|
2669
|
+
this._state = import_services7.SpaceState.CONTROL_ONLY;
|
|
2169
2670
|
this.stateUpdate.emit();
|
|
2170
2671
|
this.metrics = {};
|
|
2171
|
-
this.metrics.open = new Date();
|
|
2672
|
+
this.metrics.open = /* @__PURE__ */ new Date();
|
|
2172
2673
|
}
|
|
2173
2674
|
async close() {
|
|
2174
2675
|
await this._close();
|
|
2175
2676
|
}
|
|
2176
2677
|
async _close() {
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
this._state = import_services6.SpaceState.CLOSED;
|
|
2678
|
+
await this._callbacks.beforeClose?.();
|
|
2679
|
+
this._state = import_services7.SpaceState.CLOSED;
|
|
2180
2680
|
await this._ctx.dispose();
|
|
2181
|
-
this._ctx = new
|
|
2681
|
+
this._ctx = new import_context6.Context();
|
|
2182
2682
|
await this.authVerifier.close();
|
|
2183
2683
|
await this._inner.close();
|
|
2184
2684
|
await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
|
|
@@ -2197,47 +2697,46 @@ var DataSpace = class DataSpace2 {
|
|
|
2197
2697
|
initializeDataPipelineAsync() {
|
|
2198
2698
|
(0, import_async8.scheduleTask)(this._ctx, async () => {
|
|
2199
2699
|
try {
|
|
2200
|
-
this.metrics.pipelineInitBegin = new Date();
|
|
2700
|
+
this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
|
|
2201
2701
|
await this.initializeDataPipeline();
|
|
2202
2702
|
} catch (err) {
|
|
2203
2703
|
if (err instanceof import_errors3.CancelledError) {
|
|
2204
|
-
(0,
|
|
2205
|
-
F:
|
|
2206
|
-
L:
|
|
2704
|
+
(0, import_log10.log)("data pipeline initialization cancelled", err, {
|
|
2705
|
+
F: __dxlog_file12,
|
|
2706
|
+
L: 199,
|
|
2207
2707
|
S: this,
|
|
2208
2708
|
C: (f, a) => f(...a)
|
|
2209
2709
|
});
|
|
2210
2710
|
return;
|
|
2211
2711
|
}
|
|
2212
|
-
|
|
2213
|
-
F:
|
|
2214
|
-
L:
|
|
2712
|
+
import_log10.log.error("Error initializing data pipeline", err, {
|
|
2713
|
+
F: __dxlog_file12,
|
|
2714
|
+
L: 203,
|
|
2215
2715
|
S: this,
|
|
2216
2716
|
C: (f, a) => f(...a)
|
|
2217
2717
|
});
|
|
2218
|
-
this._state =
|
|
2718
|
+
this._state = import_services7.SpaceState.ERROR;
|
|
2219
2719
|
this.error = err;
|
|
2220
2720
|
this.stateUpdate.emit();
|
|
2221
2721
|
} finally {
|
|
2222
|
-
this.metrics.ready = new Date();
|
|
2722
|
+
this.metrics.ready = /* @__PURE__ */ new Date();
|
|
2223
2723
|
}
|
|
2224
2724
|
});
|
|
2225
2725
|
}
|
|
2226
2726
|
async initializeDataPipeline() {
|
|
2227
|
-
|
|
2228
|
-
if (this._state !== import_services6.SpaceState.CONTROL_ONLY) {
|
|
2727
|
+
if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
|
|
2229
2728
|
throw new import_errors3.SystemError("Invalid operation");
|
|
2230
2729
|
}
|
|
2231
|
-
this._state =
|
|
2730
|
+
this._state = import_services7.SpaceState.INITIALIZING;
|
|
2232
2731
|
await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
2233
2732
|
ctx: this._ctx,
|
|
2234
2733
|
breakOnStall: false
|
|
2235
2734
|
});
|
|
2236
|
-
this.metrics.controlPipelineReady = new Date();
|
|
2735
|
+
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
2237
2736
|
await this._createWritableFeeds();
|
|
2238
|
-
(0,
|
|
2239
|
-
F:
|
|
2240
|
-
L:
|
|
2737
|
+
(0, import_log10.log)("writable feeds created", void 0, {
|
|
2738
|
+
F: __dxlog_file12,
|
|
2739
|
+
L: 227,
|
|
2241
2740
|
S: this,
|
|
2242
2741
|
C: (f, a) => f(...a)
|
|
2243
2742
|
});
|
|
@@ -2250,11 +2749,11 @@ var DataSpace = class DataSpace2 {
|
|
|
2250
2749
|
}), this._inner.controlPipeline.writer));
|
|
2251
2750
|
}
|
|
2252
2751
|
await this._inner.initializeDataPipeline();
|
|
2253
|
-
this.metrics.dataPipelineOpen = new Date();
|
|
2254
|
-
await (0,
|
|
2255
|
-
(0,
|
|
2256
|
-
F:
|
|
2257
|
-
L:
|
|
2752
|
+
this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
|
|
2753
|
+
await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
|
|
2754
|
+
(0, import_log10.log)("waiting for data pipeline to reach target timeframe", void 0, {
|
|
2755
|
+
F: __dxlog_file12,
|
|
2756
|
+
L: 248,
|
|
2258
2757
|
S: this,
|
|
2259
2758
|
C: (f, a) => f(...a)
|
|
2260
2759
|
});
|
|
@@ -2262,17 +2761,17 @@ var DataSpace = class DataSpace2 {
|
|
|
2262
2761
|
ctx: this._ctx,
|
|
2263
2762
|
breakOnStall: false
|
|
2264
2763
|
});
|
|
2265
|
-
this.metrics.dataPipelineReady = new Date();
|
|
2266
|
-
(0,
|
|
2267
|
-
F:
|
|
2268
|
-
L:
|
|
2764
|
+
this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
|
|
2765
|
+
(0, import_log10.log)("data pipeline ready", void 0, {
|
|
2766
|
+
F: __dxlog_file12,
|
|
2767
|
+
L: 257,
|
|
2269
2768
|
S: this,
|
|
2270
2769
|
C: (f, a) => f(...a)
|
|
2271
2770
|
});
|
|
2272
|
-
await
|
|
2273
|
-
this._state =
|
|
2771
|
+
await this._callbacks.beforeReady?.();
|
|
2772
|
+
this._state = import_services7.SpaceState.READY;
|
|
2274
2773
|
this.stateUpdate.emit();
|
|
2275
|
-
await
|
|
2774
|
+
await this._callbacks.afterReady?.();
|
|
2276
2775
|
}
|
|
2277
2776
|
async _createWritableFeeds() {
|
|
2278
2777
|
const credentials = [];
|
|
@@ -2288,7 +2787,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2288
2787
|
spaceKey: this.key,
|
|
2289
2788
|
deviceKey: this._signingContext.deviceKey,
|
|
2290
2789
|
identityKey: this._signingContext.identityKey,
|
|
2291
|
-
designation:
|
|
2790
|
+
designation: import_credentials11.AdmittedFeed.Designation.CONTROL
|
|
2292
2791
|
}
|
|
2293
2792
|
}));
|
|
2294
2793
|
}
|
|
@@ -2305,7 +2804,7 @@ var DataSpace = class DataSpace2 {
|
|
|
2305
2804
|
spaceKey: this.key,
|
|
2306
2805
|
deviceKey: this._signingContext.deviceKey,
|
|
2307
2806
|
identityKey: this._signingContext.identityKey,
|
|
2308
|
-
designation:
|
|
2807
|
+
designation: import_credentials11.AdmittedFeed.Designation.DATA
|
|
2309
2808
|
}
|
|
2310
2809
|
}));
|
|
2311
2810
|
}
|
|
@@ -2319,7 +2818,6 @@ var DataSpace = class DataSpace2 {
|
|
|
2319
2818
|
await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
|
|
2320
2819
|
}
|
|
2321
2820
|
async createEpoch() {
|
|
2322
|
-
var _a, _b;
|
|
2323
2821
|
const epoch = await this.dataPipeline.createEpoch();
|
|
2324
2822
|
const receipt = await this.inner.controlPipeline.writer.write({
|
|
2325
2823
|
credential: {
|
|
@@ -2332,65 +2830,67 @@ var DataSpace = class DataSpace2 {
|
|
|
2332
2830
|
})
|
|
2333
2831
|
}
|
|
2334
2832
|
});
|
|
2335
|
-
await this.inner.controlPipeline.state.waitUntilTimeframe(new
|
|
2833
|
+
await this.inner.controlPipeline.state.waitUntilTimeframe(new import_timeframe2.Timeframe([
|
|
2336
2834
|
[
|
|
2337
2835
|
receipt.feedKey,
|
|
2338
2836
|
receipt.seq
|
|
2339
2837
|
]
|
|
2340
2838
|
]));
|
|
2341
|
-
|
|
2342
|
-
const
|
|
2343
|
-
|
|
2344
|
-
|
|
2839
|
+
if (ENABLE_FEED_PURGE) {
|
|
2840
|
+
for (const feed of this.inner.dataPipeline.pipelineState?.feeds ?? []) {
|
|
2841
|
+
const indexBeforeEpoch = epoch.timeframe.get(feed.key);
|
|
2842
|
+
if (indexBeforeEpoch === void 0) {
|
|
2843
|
+
continue;
|
|
2844
|
+
}
|
|
2845
|
+
await feed.safeClear(0, indexBeforeEpoch + 1);
|
|
2345
2846
|
}
|
|
2346
2847
|
}
|
|
2347
2848
|
}
|
|
2348
2849
|
async activate() {
|
|
2349
|
-
if (this._state !==
|
|
2850
|
+
if (this._state !== import_services7.SpaceState.INACTIVE) {
|
|
2350
2851
|
return;
|
|
2351
2852
|
}
|
|
2352
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
2853
|
+
await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
|
|
2353
2854
|
await this._open();
|
|
2354
2855
|
this.initializeDataPipelineAsync();
|
|
2355
2856
|
}
|
|
2356
2857
|
async deactivate() {
|
|
2357
|
-
if (this._state ===
|
|
2858
|
+
if (this._state === import_services7.SpaceState.INACTIVE) {
|
|
2358
2859
|
return;
|
|
2359
2860
|
}
|
|
2360
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
2861
|
+
await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
|
|
2361
2862
|
await this._close();
|
|
2362
|
-
this._state =
|
|
2863
|
+
this._state = import_services7.SpaceState.INACTIVE;
|
|
2363
2864
|
this.stateUpdate.emit();
|
|
2364
2865
|
}
|
|
2365
2866
|
};
|
|
2366
|
-
|
|
2867
|
+
_ts_decorate3([
|
|
2367
2868
|
import_async8.synchronized
|
|
2368
2869
|
], DataSpace.prototype, "open", null);
|
|
2369
|
-
|
|
2870
|
+
_ts_decorate3([
|
|
2370
2871
|
import_async8.synchronized
|
|
2371
2872
|
], DataSpace.prototype, "close", null);
|
|
2372
|
-
|
|
2873
|
+
_ts_decorate3([
|
|
2373
2874
|
(0, import_debug4.timed)(1e4)
|
|
2374
2875
|
], DataSpace.prototype, "_createWritableFeeds", null);
|
|
2375
|
-
|
|
2876
|
+
_ts_decorate3([
|
|
2376
2877
|
import_async8.synchronized
|
|
2377
2878
|
], DataSpace.prototype, "activate", null);
|
|
2378
|
-
|
|
2879
|
+
_ts_decorate3([
|
|
2379
2880
|
import_async8.synchronized
|
|
2380
2881
|
], DataSpace.prototype, "deactivate", null);
|
|
2381
|
-
DataSpace =
|
|
2882
|
+
DataSpace = _ts_decorate3([
|
|
2382
2883
|
(0, import_async8.trackLeaks)("open", "close")
|
|
2383
2884
|
], DataSpace);
|
|
2384
2885
|
|
|
2385
2886
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
2386
|
-
var
|
|
2887
|
+
var import_credentials12 = require("@dxos/credentials");
|
|
2387
2888
|
var import_debug5 = require("@dxos/debug");
|
|
2388
|
-
var
|
|
2389
|
-
var
|
|
2889
|
+
var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
2890
|
+
var import_timeframe3 = require("@dxos/timeframe");
|
|
2390
2891
|
var spaceGenesis = async (keyring, signingContext, space) => {
|
|
2391
|
-
var _a, _b, _c, _d;
|
|
2392
2892
|
const credentials = [
|
|
2393
|
-
await (0,
|
|
2893
|
+
await (0, import_credentials12.createCredential)({
|
|
2394
2894
|
signer: keyring,
|
|
2395
2895
|
issuer: space.key,
|
|
2396
2896
|
subject: space.key,
|
|
@@ -2399,45 +2899,45 @@ var spaceGenesis = async (keyring, signingContext, space) => {
|
|
|
2399
2899
|
spaceKey: space.key
|
|
2400
2900
|
}
|
|
2401
2901
|
}),
|
|
2402
|
-
await (0,
|
|
2902
|
+
await (0, import_credentials12.createCredential)({
|
|
2403
2903
|
signer: keyring,
|
|
2404
2904
|
issuer: space.key,
|
|
2405
2905
|
subject: signingContext.identityKey,
|
|
2406
2906
|
assertion: {
|
|
2407
2907
|
"@type": "dxos.halo.credentials.SpaceMember",
|
|
2408
2908
|
spaceKey: space.key,
|
|
2409
|
-
role:
|
|
2909
|
+
role: import_credentials13.SpaceMember.Role.ADMIN,
|
|
2410
2910
|
profile: signingContext.profile,
|
|
2411
|
-
genesisFeedKey:
|
|
2911
|
+
genesisFeedKey: space.controlFeedKey ?? (0, import_debug5.failUndefined)()
|
|
2412
2912
|
}
|
|
2413
2913
|
}),
|
|
2414
2914
|
await signingContext.credentialSigner.createCredential({
|
|
2415
|
-
subject:
|
|
2915
|
+
subject: space.controlFeedKey ?? (0, import_debug5.failUndefined)(),
|
|
2416
2916
|
assertion: {
|
|
2417
2917
|
"@type": "dxos.halo.credentials.AdmittedFeed",
|
|
2418
2918
|
spaceKey: space.key,
|
|
2419
2919
|
identityKey: signingContext.identityKey,
|
|
2420
2920
|
deviceKey: signingContext.deviceKey,
|
|
2421
|
-
designation:
|
|
2921
|
+
designation: import_credentials13.AdmittedFeed.Designation.CONTROL
|
|
2422
2922
|
}
|
|
2423
2923
|
}),
|
|
2424
2924
|
await signingContext.credentialSigner.createCredential({
|
|
2425
|
-
subject:
|
|
2925
|
+
subject: space.dataFeedKey ?? (0, import_debug5.failUndefined)(),
|
|
2426
2926
|
assertion: {
|
|
2427
2927
|
"@type": "dxos.halo.credentials.AdmittedFeed",
|
|
2428
2928
|
spaceKey: space.key,
|
|
2429
2929
|
identityKey: signingContext.identityKey,
|
|
2430
2930
|
deviceKey: signingContext.deviceKey,
|
|
2431
|
-
designation:
|
|
2931
|
+
designation: import_credentials13.AdmittedFeed.Designation.DATA
|
|
2432
2932
|
}
|
|
2433
2933
|
}),
|
|
2434
2934
|
await signingContext.credentialSigner.createCredential({
|
|
2435
|
-
subject:
|
|
2935
|
+
subject: space.key ?? (0, import_debug5.failUndefined)(),
|
|
2436
2936
|
assertion: {
|
|
2437
2937
|
"@type": "dxos.halo.credentials.Epoch",
|
|
2438
2938
|
number: 0,
|
|
2439
2939
|
previousId: void 0,
|
|
2440
|
-
timeframe: new
|
|
2940
|
+
timeframe: new import_timeframe3.Timeframe(),
|
|
2441
2941
|
snapshotCid: void 0
|
|
2442
2942
|
}
|
|
2443
2943
|
})
|
|
@@ -2453,7 +2953,7 @@ var spaceGenesis = async (keyring, signingContext, space) => {
|
|
|
2453
2953
|
};
|
|
2454
2954
|
|
|
2455
2955
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
2456
|
-
function
|
|
2956
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
2457
2957
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2458
2958
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2459
2959
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -2463,7 +2963,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
2463
2963
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2464
2964
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2465
2965
|
}
|
|
2466
|
-
var
|
|
2966
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
2467
2967
|
var DataSpaceManager = class DataSpaceManager2 {
|
|
2468
2968
|
constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _feedStore) {
|
|
2469
2969
|
this._spaceManager = _spaceManager;
|
|
@@ -2472,7 +2972,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2472
2972
|
this._keyring = _keyring;
|
|
2473
2973
|
this._signingContext = _signingContext;
|
|
2474
2974
|
this._feedStore = _feedStore;
|
|
2475
|
-
this._ctx = new
|
|
2975
|
+
this._ctx = new import_context7.Context();
|
|
2476
2976
|
this.updated = new import_async9.Event();
|
|
2477
2977
|
this._spaces = new import_util4.ComplexMap(import_keys7.PublicKey.hash);
|
|
2478
2978
|
this._isOpen = false;
|
|
@@ -2483,50 +2983,50 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2483
2983
|
return this._spaces;
|
|
2484
2984
|
}
|
|
2485
2985
|
async open() {
|
|
2486
|
-
(0,
|
|
2487
|
-
F:
|
|
2488
|
-
L:
|
|
2986
|
+
(0, import_log11.log)("open", void 0, {
|
|
2987
|
+
F: __dxlog_file13,
|
|
2988
|
+
L: 79,
|
|
2489
2989
|
S: this,
|
|
2490
2990
|
C: (f, a) => f(...a)
|
|
2491
2991
|
});
|
|
2492
|
-
|
|
2992
|
+
import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols7.trace.begin({
|
|
2493
2993
|
id: this._instanceId
|
|
2494
2994
|
}), {
|
|
2495
|
-
F:
|
|
2496
|
-
L:
|
|
2995
|
+
F: __dxlog_file13,
|
|
2996
|
+
L: 80,
|
|
2497
2997
|
S: this,
|
|
2498
2998
|
C: (f, a) => f(...a)
|
|
2499
2999
|
});
|
|
2500
3000
|
await this._metadataStore.load();
|
|
2501
|
-
(0,
|
|
3001
|
+
(0, import_log11.log)("metadata loaded", {
|
|
2502
3002
|
spaces: this._metadataStore.spaces.length
|
|
2503
3003
|
}, {
|
|
2504
|
-
F:
|
|
2505
|
-
L:
|
|
3004
|
+
F: __dxlog_file13,
|
|
3005
|
+
L: 82,
|
|
2506
3006
|
S: this,
|
|
2507
3007
|
C: (f, a) => f(...a)
|
|
2508
3008
|
});
|
|
2509
3009
|
for (const spaceMetadata of this._metadataStore.spaces) {
|
|
2510
3010
|
try {
|
|
2511
|
-
(0,
|
|
3011
|
+
(0, import_log11.log)("load space", {
|
|
2512
3012
|
spaceMetadata
|
|
2513
3013
|
}, {
|
|
2514
|
-
F:
|
|
2515
|
-
L:
|
|
3014
|
+
F: __dxlog_file13,
|
|
3015
|
+
L: 86,
|
|
2516
3016
|
S: this,
|
|
2517
3017
|
C: (f, a) => f(...a)
|
|
2518
3018
|
});
|
|
2519
3019
|
const space = await this._constructSpace(spaceMetadata);
|
|
2520
|
-
if (spaceMetadata.state !==
|
|
3020
|
+
if (spaceMetadata.state !== import_services8.SpaceState.INACTIVE) {
|
|
2521
3021
|
space.initializeDataPipelineAsync();
|
|
2522
3022
|
}
|
|
2523
3023
|
} catch (err) {
|
|
2524
|
-
|
|
3024
|
+
import_log11.log.error("Error loading space", {
|
|
2525
3025
|
spaceMetadata,
|
|
2526
3026
|
err
|
|
2527
3027
|
}, {
|
|
2528
|
-
F:
|
|
2529
|
-
L:
|
|
3028
|
+
F: __dxlog_file13,
|
|
3029
|
+
L: 92,
|
|
2530
3030
|
S: this,
|
|
2531
3031
|
C: (f, a) => f(...a)
|
|
2532
3032
|
});
|
|
@@ -2534,19 +3034,19 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2534
3034
|
}
|
|
2535
3035
|
this._isOpen = true;
|
|
2536
3036
|
this.updated.emit();
|
|
2537
|
-
|
|
3037
|
+
import_log11.log.trace("dxos.echo.data-space-manager.open", import_protocols7.trace.end({
|
|
2538
3038
|
id: this._instanceId
|
|
2539
3039
|
}), {
|
|
2540
|
-
F:
|
|
2541
|
-
L:
|
|
3040
|
+
F: __dxlog_file13,
|
|
3041
|
+
L: 98,
|
|
2542
3042
|
S: this,
|
|
2543
3043
|
C: (f, a) => f(...a)
|
|
2544
3044
|
});
|
|
2545
3045
|
}
|
|
2546
3046
|
async close() {
|
|
2547
|
-
(0,
|
|
2548
|
-
F:
|
|
2549
|
-
L:
|
|
3047
|
+
(0, import_log11.log)("close", void 0, {
|
|
3048
|
+
F: __dxlog_file13,
|
|
3049
|
+
L: 103,
|
|
2550
3050
|
S: this,
|
|
2551
3051
|
C: (f, a) => f(...a)
|
|
2552
3052
|
});
|
|
@@ -2560,7 +3060,15 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2560
3060
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
2561
3061
|
*/
|
|
2562
3062
|
async createSpace() {
|
|
2563
|
-
(0,
|
|
3063
|
+
(0, import_invariant11.invariant)(this._isOpen, "Not open.", {
|
|
3064
|
+
F: __dxlog_file13,
|
|
3065
|
+
L: 116,
|
|
3066
|
+
S: this,
|
|
3067
|
+
A: [
|
|
3068
|
+
"this._isOpen",
|
|
3069
|
+
"'Not open.'"
|
|
3070
|
+
]
|
|
3071
|
+
});
|
|
2564
3072
|
const spaceKey = await this._keyring.createKey();
|
|
2565
3073
|
const controlFeedKey = await this._keyring.createKey();
|
|
2566
3074
|
const dataFeedKey = await this._keyring.createKey();
|
|
@@ -2569,13 +3077,13 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2569
3077
|
genesisFeedKey: controlFeedKey,
|
|
2570
3078
|
controlFeedKey,
|
|
2571
3079
|
dataFeedKey,
|
|
2572
|
-
state:
|
|
3080
|
+
state: import_services8.SpaceState.ACTIVE
|
|
2573
3081
|
};
|
|
2574
|
-
(0,
|
|
3082
|
+
(0, import_log11.log)("creating space...", {
|
|
2575
3083
|
spaceKey
|
|
2576
3084
|
}, {
|
|
2577
|
-
F:
|
|
2578
|
-
L:
|
|
3085
|
+
F: __dxlog_file13,
|
|
3086
|
+
L: 128,
|
|
2579
3087
|
S: this,
|
|
2580
3088
|
C: (f, a) => f(...a)
|
|
2581
3089
|
});
|
|
@@ -2583,7 +3091,15 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2583
3091
|
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner);
|
|
2584
3092
|
await this._metadataStore.addSpace(metadata);
|
|
2585
3093
|
const memberCredential = credentials[1];
|
|
2586
|
-
(0,
|
|
3094
|
+
(0, import_invariant11.invariant)((0, import_credentials14.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
3095
|
+
F: __dxlog_file13,
|
|
3096
|
+
L: 135,
|
|
3097
|
+
S: this,
|
|
3098
|
+
A: [
|
|
3099
|
+
"getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
3100
|
+
""
|
|
3101
|
+
]
|
|
3102
|
+
});
|
|
2587
3103
|
await this._signingContext.recordCredential(memberCredential);
|
|
2588
3104
|
await space.initializeDataPipeline();
|
|
2589
3105
|
this.updated.emit();
|
|
@@ -2591,16 +3107,32 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2591
3107
|
}
|
|
2592
3108
|
// TODO(burdon): Rename join space.
|
|
2593
3109
|
async acceptSpace(opts) {
|
|
2594
|
-
(0,
|
|
3110
|
+
(0, import_log11.log)("accept space", {
|
|
2595
3111
|
opts
|
|
2596
3112
|
}, {
|
|
2597
|
-
F:
|
|
2598
|
-
L:
|
|
3113
|
+
F: __dxlog_file13,
|
|
3114
|
+
L: 147,
|
|
2599
3115
|
S: this,
|
|
2600
3116
|
C: (f, a) => f(...a)
|
|
2601
3117
|
});
|
|
2602
|
-
(0,
|
|
2603
|
-
|
|
3118
|
+
(0, import_invariant11.invariant)(this._isOpen, "Not open.", {
|
|
3119
|
+
F: __dxlog_file13,
|
|
3120
|
+
L: 148,
|
|
3121
|
+
S: this,
|
|
3122
|
+
A: [
|
|
3123
|
+
"this._isOpen",
|
|
3124
|
+
"'Not open.'"
|
|
3125
|
+
]
|
|
3126
|
+
});
|
|
3127
|
+
(0, import_invariant11.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
3128
|
+
F: __dxlog_file13,
|
|
3129
|
+
L: 149,
|
|
3130
|
+
S: this,
|
|
3131
|
+
A: [
|
|
3132
|
+
"!this._spaces.has(opts.spaceKey)",
|
|
3133
|
+
"'Space already exists.'"
|
|
3134
|
+
]
|
|
3135
|
+
});
|
|
2604
3136
|
const metadata = {
|
|
2605
3137
|
key: opts.spaceKey,
|
|
2606
3138
|
genesisFeedKey: opts.genesisFeedKey,
|
|
@@ -2619,17 +3151,17 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2619
3151
|
* TODO(dmaretskyi): Consider removing.
|
|
2620
3152
|
*/
|
|
2621
3153
|
async waitUntilSpaceReady(spaceKey) {
|
|
2622
|
-
await (0,
|
|
3154
|
+
await (0, import_context7.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
|
|
2623
3155
|
const space = this._spaces.get(spaceKey);
|
|
2624
|
-
return !!space && space.state ===
|
|
3156
|
+
return !!space && space.state === import_services8.SpaceState.READY;
|
|
2625
3157
|
}));
|
|
2626
3158
|
}
|
|
2627
3159
|
async _constructSpace(metadata) {
|
|
2628
|
-
(0,
|
|
3160
|
+
(0, import_log11.log)("construct space", {
|
|
2629
3161
|
metadata
|
|
2630
3162
|
}, {
|
|
2631
|
-
F:
|
|
2632
|
-
L:
|
|
3163
|
+
F: __dxlog_file13,
|
|
3164
|
+
L: 182,
|
|
2633
3165
|
S: this,
|
|
2634
3166
|
C: (f, a) => f(...a)
|
|
2635
3167
|
});
|
|
@@ -2637,7 +3169,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2637
3169
|
localPeerId: this._signingContext.deviceKey
|
|
2638
3170
|
});
|
|
2639
3171
|
const presence = new import_teleport_extension_gossip.Presence({
|
|
2640
|
-
announceInterval:
|
|
3172
|
+
announceInterval: 1e3,
|
|
2641
3173
|
offlineTimeout: 5e3,
|
|
2642
3174
|
identityKey: this._signingContext.identityKey,
|
|
2643
3175
|
gossip
|
|
@@ -2663,9 +3195,9 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2663
3195
|
session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
|
|
2664
3196
|
},
|
|
2665
3197
|
onAuthFailure: () => {
|
|
2666
|
-
|
|
2667
|
-
F:
|
|
2668
|
-
L:
|
|
3198
|
+
import_log11.log.warn("auth failure", void 0, {
|
|
3199
|
+
F: __dxlog_file13,
|
|
3200
|
+
L: 217,
|
|
2669
3201
|
S: this,
|
|
2670
3202
|
C: (f, a) => f(...a)
|
|
2671
3203
|
});
|
|
@@ -2676,7 +3208,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2676
3208
|
dataFeed && space.setDataFeed(dataFeed);
|
|
2677
3209
|
const dataSpace = new DataSpace({
|
|
2678
3210
|
inner: space,
|
|
2679
|
-
initialState: metadata.state ===
|
|
3211
|
+
initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
|
|
2680
3212
|
metadataStore: this._metadataStore,
|
|
2681
3213
|
gossip,
|
|
2682
3214
|
presence,
|
|
@@ -2685,23 +3217,23 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2685
3217
|
signingContext: this._signingContext,
|
|
2686
3218
|
callbacks: {
|
|
2687
3219
|
beforeReady: async () => {
|
|
2688
|
-
(0,
|
|
3220
|
+
(0, import_log11.log)("before space ready", {
|
|
2689
3221
|
space: space.key
|
|
2690
3222
|
}, {
|
|
2691
|
-
F:
|
|
2692
|
-
L:
|
|
3223
|
+
F: __dxlog_file13,
|
|
3224
|
+
L: 235,
|
|
2693
3225
|
S: this,
|
|
2694
3226
|
C: (f, a) => f(...a)
|
|
2695
3227
|
});
|
|
2696
3228
|
await this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.dataPipeline.databaseHost.createDataServiceHost());
|
|
2697
3229
|
},
|
|
2698
3230
|
afterReady: async () => {
|
|
2699
|
-
(0,
|
|
3231
|
+
(0, import_log11.log)("after space ready", {
|
|
2700
3232
|
space: space.key,
|
|
2701
3233
|
open: this._isOpen
|
|
2702
3234
|
}, {
|
|
2703
|
-
F:
|
|
2704
|
-
L:
|
|
3235
|
+
F: __dxlog_file13,
|
|
3236
|
+
L: 242,
|
|
2705
3237
|
S: this,
|
|
2706
3238
|
C: (f, a) => f(...a)
|
|
2707
3239
|
});
|
|
@@ -2710,11 +3242,11 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2710
3242
|
}
|
|
2711
3243
|
},
|
|
2712
3244
|
beforeClose: async () => {
|
|
2713
|
-
(0,
|
|
3245
|
+
(0, import_log11.log)("before space close", {
|
|
2714
3246
|
space: space.key
|
|
2715
3247
|
}, {
|
|
2716
|
-
F:
|
|
2717
|
-
L:
|
|
3248
|
+
F: __dxlog_file13,
|
|
3249
|
+
L: 248,
|
|
2718
3250
|
S: this,
|
|
2719
3251
|
C: (f, a) => f(...a)
|
|
2720
3252
|
});
|
|
@@ -2723,7 +3255,7 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2723
3255
|
},
|
|
2724
3256
|
cache: metadata.cache
|
|
2725
3257
|
});
|
|
2726
|
-
if (metadata.state !==
|
|
3258
|
+
if (metadata.state !== import_services8.SpaceState.INACTIVE) {
|
|
2727
3259
|
await dataSpace.open();
|
|
2728
3260
|
}
|
|
2729
3261
|
if (metadata.controlTimeframe) {
|
|
@@ -2736,33 +3268,33 @@ var DataSpaceManager = class DataSpaceManager2 {
|
|
|
2736
3268
|
return dataSpace;
|
|
2737
3269
|
}
|
|
2738
3270
|
};
|
|
2739
|
-
|
|
3271
|
+
_ts_decorate4([
|
|
2740
3272
|
import_async9.synchronized
|
|
2741
3273
|
], DataSpaceManager.prototype, "open", null);
|
|
2742
|
-
|
|
3274
|
+
_ts_decorate4([
|
|
2743
3275
|
import_async9.synchronized
|
|
2744
3276
|
], DataSpaceManager.prototype, "close", null);
|
|
2745
|
-
|
|
3277
|
+
_ts_decorate4([
|
|
2746
3278
|
import_async9.synchronized
|
|
2747
3279
|
], DataSpaceManager.prototype, "createSpace", null);
|
|
2748
|
-
|
|
3280
|
+
_ts_decorate4([
|
|
2749
3281
|
import_async9.synchronized
|
|
2750
3282
|
], DataSpaceManager.prototype, "acceptSpace", null);
|
|
2751
|
-
DataSpaceManager =
|
|
3283
|
+
DataSpaceManager = _ts_decorate4([
|
|
2752
3284
|
(0, import_async9.trackLeaks)("open", "close")
|
|
2753
3285
|
], DataSpaceManager);
|
|
2754
3286
|
|
|
2755
3287
|
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
2756
3288
|
var import_async10 = require("@dxos/async");
|
|
2757
|
-
var
|
|
3289
|
+
var import_codec_protobuf5 = require("@dxos/codec-protobuf");
|
|
2758
3290
|
var import_debug6 = require("@dxos/debug");
|
|
2759
3291
|
var import_echo_pipeline2 = require("@dxos/echo-pipeline");
|
|
2760
3292
|
var import_errors4 = require("@dxos/errors");
|
|
2761
|
-
var
|
|
2762
|
-
var
|
|
2763
|
-
var
|
|
3293
|
+
var import_log12 = require("@dxos/log");
|
|
3294
|
+
var import_protocols8 = require("@dxos/protocols");
|
|
3295
|
+
var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
|
|
2764
3296
|
var import_util5 = require("@dxos/util");
|
|
2765
|
-
var
|
|
3297
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
2766
3298
|
var SpacesServiceImpl = class {
|
|
2767
3299
|
constructor(_identityManager, _spaceManager, _dataServiceSubscriptions, _getDataSpaceManager) {
|
|
2768
3300
|
this._identityManager = _identityManager;
|
|
@@ -2779,15 +3311,14 @@ var SpacesServiceImpl = class {
|
|
|
2779
3311
|
return this._serializeSpace(space);
|
|
2780
3312
|
}
|
|
2781
3313
|
async updateSpace({ spaceKey, state }) {
|
|
2782
|
-
var _a;
|
|
2783
3314
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2784
|
-
const space =
|
|
3315
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2785
3316
|
if (state) {
|
|
2786
3317
|
switch (state) {
|
|
2787
|
-
case
|
|
3318
|
+
case import_services9.SpaceState.ACTIVE:
|
|
2788
3319
|
await space.activate();
|
|
2789
3320
|
break;
|
|
2790
|
-
case
|
|
3321
|
+
case import_services9.SpaceState.INACTIVE:
|
|
2791
3322
|
await space.deactivate();
|
|
2792
3323
|
break;
|
|
2793
3324
|
default:
|
|
@@ -2796,14 +3327,14 @@ var SpacesServiceImpl = class {
|
|
|
2796
3327
|
}
|
|
2797
3328
|
}
|
|
2798
3329
|
querySpaces() {
|
|
2799
|
-
return new
|
|
3330
|
+
return new import_codec_protobuf5.Stream(({ next, ctx }) => {
|
|
2800
3331
|
const scheduler = new import_async10.UpdateScheduler(ctx, async () => {
|
|
2801
3332
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2802
3333
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
2803
|
-
(0,
|
|
3334
|
+
(0, import_log12.log)("update", {
|
|
2804
3335
|
spaces
|
|
2805
3336
|
}, {
|
|
2806
|
-
F:
|
|
3337
|
+
F: __dxlog_file14,
|
|
2807
3338
|
L: 78,
|
|
2808
3339
|
S: this,
|
|
2809
3340
|
C: (f, a) => f(...a)
|
|
@@ -2812,7 +3343,7 @@ var SpacesServiceImpl = class {
|
|
|
2812
3343
|
spaces
|
|
2813
3344
|
});
|
|
2814
3345
|
}, {
|
|
2815
|
-
maxFrequency: 2
|
|
3346
|
+
maxFrequency: process.env.NODE_ENV === "test" ? void 0 : 2
|
|
2816
3347
|
});
|
|
2817
3348
|
(0, import_async10.scheduleTask)(ctx, async () => {
|
|
2818
3349
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
@@ -2845,17 +3376,15 @@ var SpacesServiceImpl = class {
|
|
|
2845
3376
|
});
|
|
2846
3377
|
}
|
|
2847
3378
|
async postMessage({ spaceKey, channel, message }) {
|
|
2848
|
-
var _a;
|
|
2849
3379
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2850
|
-
const space =
|
|
3380
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2851
3381
|
await space.postMessage(getChannelId(channel), message);
|
|
2852
3382
|
}
|
|
2853
3383
|
subscribeMessages({ spaceKey, channel }) {
|
|
2854
|
-
return new
|
|
3384
|
+
return new import_codec_protobuf5.Stream(({ ctx, next }) => {
|
|
2855
3385
|
(0, import_async10.scheduleTask)(ctx, async () => {
|
|
2856
|
-
var _a;
|
|
2857
3386
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2858
|
-
const space =
|
|
3387
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2859
3388
|
const handle = space.listen(getChannelId(channel), (message) => {
|
|
2860
3389
|
next(message);
|
|
2861
3390
|
});
|
|
@@ -2864,9 +3393,8 @@ var SpacesServiceImpl = class {
|
|
|
2864
3393
|
});
|
|
2865
3394
|
}
|
|
2866
3395
|
queryCredentials({ spaceKey }) {
|
|
2867
|
-
return new
|
|
2868
|
-
|
|
2869
|
-
const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
3396
|
+
return new import_codec_protobuf5.Stream(({ ctx, next }) => {
|
|
3397
|
+
const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2870
3398
|
const processor = {
|
|
2871
3399
|
processCredential: async (credential) => {
|
|
2872
3400
|
next(credential);
|
|
@@ -2877,9 +3405,8 @@ var SpacesServiceImpl = class {
|
|
|
2877
3405
|
});
|
|
2878
3406
|
}
|
|
2879
3407
|
async writeCredentials({ spaceKey, credentials }) {
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
for (const credential of credentials != null ? credentials : []) {
|
|
3408
|
+
const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
3409
|
+
for (const credential of credentials ?? []) {
|
|
2883
3410
|
await space.controlPipeline.writer.write({
|
|
2884
3411
|
credential: {
|
|
2885
3412
|
credential
|
|
@@ -2888,17 +3415,15 @@ var SpacesServiceImpl = class {
|
|
|
2888
3415
|
}
|
|
2889
3416
|
}
|
|
2890
3417
|
async createEpoch({ spaceKey }) {
|
|
2891
|
-
var _a;
|
|
2892
3418
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
2893
|
-
const space =
|
|
3419
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug6.raise)(new import_echo_pipeline2.SpaceNotFoundError(spaceKey));
|
|
2894
3420
|
await space.createEpoch();
|
|
2895
3421
|
}
|
|
2896
3422
|
_serializeSpace(space) {
|
|
2897
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2898
3423
|
return {
|
|
2899
3424
|
spaceKey: space.key,
|
|
2900
3425
|
state: space.state,
|
|
2901
|
-
error: space.error ? (0,
|
|
3426
|
+
error: space.error ? (0, import_protocols8.encodeError)(space.error) : void 0,
|
|
2902
3427
|
pipeline: {
|
|
2903
3428
|
currentEpoch: space.dataPipeline.currentEpoch,
|
|
2904
3429
|
appliedEpoch: space.dataPipeline.appliedEpoch,
|
|
@@ -2906,25 +3431,30 @@ var SpacesServiceImpl = class {
|
|
|
2906
3431
|
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
2907
3432
|
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
2908
3433
|
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe,
|
|
2909
|
-
dataFeeds:
|
|
2910
|
-
startDataTimeframe:
|
|
2911
|
-
currentDataTimeframe:
|
|
2912
|
-
targetDataTimeframe:
|
|
2913
|
-
totalDataTimeframe:
|
|
3434
|
+
dataFeeds: space.dataPipeline.pipelineState?.feeds.map((feed) => feed.key) ?? [],
|
|
3435
|
+
startDataTimeframe: space.dataPipeline.pipelineState?.startTimeframe,
|
|
3436
|
+
currentDataTimeframe: space.dataPipeline.pipelineState?.timeframe,
|
|
3437
|
+
targetDataTimeframe: space.dataPipeline.pipelineState?.targetTimeframe,
|
|
3438
|
+
totalDataTimeframe: space.dataPipeline.pipelineState?.endTimeframe
|
|
2914
3439
|
},
|
|
2915
3440
|
members: Array.from(space.inner.spaceState.members.values()).map((member) => {
|
|
2916
|
-
|
|
3441
|
+
const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
|
|
3442
|
+
const isMe = this._identityManager.identity?.identityKey.equals(member.key);
|
|
3443
|
+
if (isMe) {
|
|
3444
|
+
peers.push(space.presence.getLocalState());
|
|
3445
|
+
}
|
|
2917
3446
|
return {
|
|
2918
3447
|
identity: {
|
|
2919
3448
|
identityKey: member.key,
|
|
2920
3449
|
profile: {
|
|
2921
|
-
displayName:
|
|
3450
|
+
displayName: member.assertion.profile?.displayName ?? (0, import_util5.humanize)(member.key)
|
|
2922
3451
|
}
|
|
2923
3452
|
},
|
|
2924
|
-
presence:
|
|
3453
|
+
presence: isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
|
|
3454
|
+
peerStates: peers
|
|
2925
3455
|
};
|
|
2926
3456
|
}),
|
|
2927
|
-
creator:
|
|
3457
|
+
creator: space.inner.spaceState.creator?.key,
|
|
2928
3458
|
cache: space.cache,
|
|
2929
3459
|
metrics: space.metrics
|
|
2930
3460
|
};
|
|
@@ -2933,8 +3463,18 @@ var SpacesServiceImpl = class {
|
|
|
2933
3463
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
2934
3464
|
|
|
2935
3465
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
2936
|
-
|
|
2937
|
-
var
|
|
3466
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
3467
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3468
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3469
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
3470
|
+
else
|
|
3471
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
3472
|
+
if (d = decorators[i])
|
|
3473
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3474
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3475
|
+
}
|
|
3476
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
3477
|
+
var ServiceContext = class ServiceContext2 {
|
|
2938
3478
|
// prettier-ignore
|
|
2939
3479
|
constructor(storage, networkManager, signalManager, modelFactory) {
|
|
2940
3480
|
this.storage = storage;
|
|
@@ -2954,7 +3494,8 @@ var ServiceContext = class {
|
|
|
2954
3494
|
root: storage.createDirectory("feeds"),
|
|
2955
3495
|
signer: this.keyring,
|
|
2956
3496
|
hypercore: {
|
|
2957
|
-
valueEncoding: import_echo_pipeline3.valueEncoding
|
|
3497
|
+
valueEncoding: import_echo_pipeline3.valueEncoding,
|
|
3498
|
+
stats: true
|
|
2958
3499
|
}
|
|
2959
3500
|
})
|
|
2960
3501
|
});
|
|
@@ -2968,105 +3509,108 @@ var ServiceContext = class {
|
|
|
2968
3509
|
});
|
|
2969
3510
|
this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
|
|
2970
3511
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
2971
|
-
this._handlerFactories.set(
|
|
2972
|
-
var _a;
|
|
2973
|
-
return (_a = this.identityManager.identity) != null ? _a : (0, import_debug7.failUndefined)();
|
|
2974
|
-
}, this._acceptIdentity.bind(this)));
|
|
3512
|
+
this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug7.failUndefined)(), this._acceptIdentity.bind(this)));
|
|
2975
3513
|
}
|
|
2976
|
-
async open() {
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
L: 126,
|
|
3514
|
+
async open(ctx) {
|
|
3515
|
+
await this._checkStorageVersion();
|
|
3516
|
+
(0, import_log13.log)("opening...", void 0, {
|
|
3517
|
+
F: __dxlog_file15,
|
|
3518
|
+
L: 135,
|
|
2982
3519
|
S: this,
|
|
2983
3520
|
C: (f, a) => f(...a)
|
|
2984
3521
|
});
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
3522
|
+
import_log13.log.trace("dxos.sdk.service-context.open", import_protocols9.trace.begin({
|
|
3523
|
+
id: this._instanceId
|
|
3524
|
+
}), {
|
|
3525
|
+
F: __dxlog_file15,
|
|
3526
|
+
L: 136,
|
|
2989
3527
|
S: this,
|
|
2990
3528
|
C: (f, a) => f(...a)
|
|
2991
3529
|
});
|
|
2992
3530
|
await this.signalManager.open();
|
|
2993
3531
|
await this.networkManager.open();
|
|
2994
3532
|
await this.spaceManager.open();
|
|
2995
|
-
await this.identityManager.open();
|
|
3533
|
+
await this.identityManager.open(ctx);
|
|
2996
3534
|
if (this.identityManager.identity) {
|
|
2997
|
-
await this._initialize();
|
|
3535
|
+
await this._initialize(ctx);
|
|
2998
3536
|
}
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3537
|
+
import_log13.log.trace("dxos.sdk.service-context.open", import_protocols9.trace.end({
|
|
3538
|
+
id: this._instanceId
|
|
3539
|
+
}), {
|
|
3540
|
+
F: __dxlog_file15,
|
|
3541
|
+
L: 144,
|
|
3002
3542
|
S: this,
|
|
3003
3543
|
C: (f, a) => f(...a)
|
|
3004
3544
|
});
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
F: __dxlog_file12,
|
|
3009
|
-
L: 139,
|
|
3545
|
+
(0, import_log13.log)("opened", void 0, {
|
|
3546
|
+
F: __dxlog_file15,
|
|
3547
|
+
L: 145,
|
|
3010
3548
|
S: this,
|
|
3011
3549
|
C: (f, a) => f(...a)
|
|
3012
3550
|
});
|
|
3013
3551
|
}
|
|
3014
3552
|
async close() {
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
L: 143,
|
|
3553
|
+
(0, import_log13.log)("closing...", void 0, {
|
|
3554
|
+
F: __dxlog_file15,
|
|
3555
|
+
L: 149,
|
|
3019
3556
|
S: this,
|
|
3020
3557
|
C: (f, a) => f(...a)
|
|
3021
3558
|
});
|
|
3022
3559
|
if (this._deviceSpaceSync && this.identityManager.identity) {
|
|
3023
3560
|
await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
|
|
3024
3561
|
}
|
|
3025
|
-
await
|
|
3562
|
+
await this.dataSpaceManager?.close();
|
|
3026
3563
|
await this.identityManager.close();
|
|
3027
3564
|
await this.spaceManager.close();
|
|
3028
3565
|
await this.feedStore.close();
|
|
3029
3566
|
await this.networkManager.close();
|
|
3030
3567
|
await this.signalManager.close();
|
|
3031
3568
|
this.dataServiceSubscriptions.clear();
|
|
3032
|
-
(0,
|
|
3033
|
-
F:
|
|
3034
|
-
L:
|
|
3569
|
+
(0, import_log13.log)("closed", void 0, {
|
|
3570
|
+
F: __dxlog_file15,
|
|
3571
|
+
L: 160,
|
|
3035
3572
|
S: this,
|
|
3036
3573
|
C: (f, a) => f(...a)
|
|
3037
3574
|
});
|
|
3038
3575
|
}
|
|
3039
3576
|
async createIdentity(params = {}) {
|
|
3040
3577
|
const identity = await this.identityManager.createIdentity(params);
|
|
3041
|
-
await this._initialize();
|
|
3578
|
+
await this._initialize(new import_context8.Context());
|
|
3042
3579
|
return identity;
|
|
3043
3580
|
}
|
|
3044
3581
|
getInvitationHandler(invitation) {
|
|
3045
3582
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
3046
|
-
(0,
|
|
3583
|
+
(0, import_invariant12.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
3584
|
+
F: __dxlog_file15,
|
|
3585
|
+
L: 171,
|
|
3586
|
+
S: this,
|
|
3587
|
+
A: [
|
|
3588
|
+
"factory",
|
|
3589
|
+
"`Unknown invitation kind: ${invitation.kind}`"
|
|
3590
|
+
]
|
|
3591
|
+
});
|
|
3047
3592
|
return factory(invitation);
|
|
3048
3593
|
}
|
|
3049
3594
|
async _acceptIdentity(params) {
|
|
3050
3595
|
const identity = await this.identityManager.acceptIdentity(params);
|
|
3051
|
-
await this._initialize();
|
|
3596
|
+
await this._initialize(new import_context8.Context());
|
|
3052
3597
|
return identity;
|
|
3053
3598
|
}
|
|
3054
3599
|
async _checkStorageVersion() {
|
|
3055
3600
|
await this.metadataStore.load();
|
|
3056
|
-
if (this.metadataStore.version !==
|
|
3057
|
-
throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${
|
|
3601
|
+
if (this.metadataStore.version !== import_protocols9.STORAGE_VERSION) {
|
|
3602
|
+
throw new Error(`Invalid storage version: current=${this.metadataStore.version}, expected=${import_protocols9.STORAGE_VERSION}`);
|
|
3058
3603
|
}
|
|
3059
3604
|
}
|
|
3060
3605
|
// Called when identity is created.
|
|
3061
|
-
async _initialize() {
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
L: 187,
|
|
3606
|
+
async _initialize(ctx) {
|
|
3607
|
+
(0, import_log13.log)("initializing spaces...", void 0, {
|
|
3608
|
+
F: __dxlog_file15,
|
|
3609
|
+
L: 192,
|
|
3066
3610
|
S: this,
|
|
3067
3611
|
C: (f, a) => f(...a)
|
|
3068
3612
|
});
|
|
3069
|
-
const identity =
|
|
3613
|
+
const identity = this.identityManager.identity ?? (0, import_debug7.failUndefined)();
|
|
3070
3614
|
const signingContext = {
|
|
3071
3615
|
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
3072
3616
|
identityKey: identity.identityKey,
|
|
@@ -3082,14 +3626,22 @@ var ServiceContext = class {
|
|
|
3082
3626
|
};
|
|
3083
3627
|
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.feedStore);
|
|
3084
3628
|
await this.dataSpaceManager.open();
|
|
3085
|
-
this._handlerFactories.set(
|
|
3086
|
-
(0,
|
|
3629
|
+
this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
|
|
3630
|
+
(0, import_invariant12.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
3631
|
+
F: __dxlog_file15,
|
|
3632
|
+
L: 215,
|
|
3633
|
+
S: this,
|
|
3634
|
+
A: [
|
|
3635
|
+
"this.dataSpaceManager",
|
|
3636
|
+
"'dataSpaceManager not initialized yet'"
|
|
3637
|
+
]
|
|
3638
|
+
});
|
|
3087
3639
|
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
3088
3640
|
});
|
|
3089
3641
|
this.initialized.wake();
|
|
3090
3642
|
this._deviceSpaceSync = {
|
|
3091
3643
|
processCredential: async (credential) => {
|
|
3092
|
-
const assertion = (0,
|
|
3644
|
+
const assertion = (0, import_credentials15.getCredentialAssertion)(credential);
|
|
3093
3645
|
if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
|
|
3094
3646
|
return;
|
|
3095
3647
|
}
|
|
@@ -3097,33 +3649,33 @@ var ServiceContext = class {
|
|
|
3097
3649
|
return;
|
|
3098
3650
|
}
|
|
3099
3651
|
if (!this.dataSpaceManager) {
|
|
3100
|
-
(0,
|
|
3652
|
+
(0, import_log13.log)("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
3101
3653
|
details: assertion
|
|
3102
3654
|
}, {
|
|
3103
|
-
F:
|
|
3104
|
-
L:
|
|
3655
|
+
F: __dxlog_file15,
|
|
3656
|
+
L: 231,
|
|
3105
3657
|
S: this,
|
|
3106
3658
|
C: (f, a) => f(...a)
|
|
3107
3659
|
});
|
|
3108
3660
|
return;
|
|
3109
3661
|
}
|
|
3110
3662
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
3111
|
-
(0,
|
|
3663
|
+
(0, import_log13.log)("space already exists, ignoring space admission", {
|
|
3112
3664
|
details: assertion
|
|
3113
3665
|
}, {
|
|
3114
|
-
F:
|
|
3115
|
-
L:
|
|
3666
|
+
F: __dxlog_file15,
|
|
3667
|
+
L: 235,
|
|
3116
3668
|
S: this,
|
|
3117
3669
|
C: (f, a) => f(...a)
|
|
3118
3670
|
});
|
|
3119
3671
|
return;
|
|
3120
3672
|
}
|
|
3121
3673
|
try {
|
|
3122
|
-
(0,
|
|
3674
|
+
(0, import_log13.log)("accepting space recorded in halo", {
|
|
3123
3675
|
details: assertion
|
|
3124
3676
|
}, {
|
|
3125
|
-
F:
|
|
3126
|
-
L:
|
|
3677
|
+
F: __dxlog_file15,
|
|
3678
|
+
L: 240,
|
|
3127
3679
|
S: this,
|
|
3128
3680
|
C: (f, a) => f(...a)
|
|
3129
3681
|
});
|
|
@@ -3132,9 +3684,9 @@ var ServiceContext = class {
|
|
|
3132
3684
|
genesisFeedKey: assertion.genesisFeedKey
|
|
3133
3685
|
});
|
|
3134
3686
|
} catch (err) {
|
|
3135
|
-
|
|
3136
|
-
F:
|
|
3137
|
-
L:
|
|
3687
|
+
import_log13.log.catch(err, void 0, {
|
|
3688
|
+
F: __dxlog_file15,
|
|
3689
|
+
L: 246,
|
|
3138
3690
|
S: this,
|
|
3139
3691
|
C: (f, a) => f(...a)
|
|
3140
3692
|
});
|
|
@@ -3144,26 +3696,38 @@ var ServiceContext = class {
|
|
|
3144
3696
|
await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
|
|
3145
3697
|
}
|
|
3146
3698
|
};
|
|
3699
|
+
_ts_decorate5([
|
|
3700
|
+
import_tracing3.trace.span()
|
|
3701
|
+
], ServiceContext.prototype, "open", null);
|
|
3702
|
+
_ts_decorate5([
|
|
3703
|
+
import_tracing3.trace.span()
|
|
3704
|
+
], ServiceContext.prototype, "_initialize", null);
|
|
3705
|
+
ServiceContext = _ts_decorate5([
|
|
3706
|
+
(0, import_util6.safeInstanceof)("dxos.client-services.ServiceContext"),
|
|
3707
|
+
import_tracing3.trace.resource()
|
|
3708
|
+
], ServiceContext);
|
|
3147
3709
|
|
|
3148
3710
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
3149
|
-
var import_tiny_invariant13 = __toESM(require("tiny-invariant"));
|
|
3150
3711
|
var import_async17 = require("@dxos/async");
|
|
3151
3712
|
var import_client_protocol5 = require("@dxos/client-protocol");
|
|
3152
|
-
var
|
|
3713
|
+
var import_context10 = require("@dxos/context");
|
|
3714
|
+
var import_document_model2 = require("@dxos/document-model");
|
|
3153
3715
|
var import_echo_pipeline4 = require("@dxos/echo-pipeline");
|
|
3716
|
+
var import_invariant14 = require("@dxos/invariant");
|
|
3154
3717
|
var import_keys12 = require("@dxos/keys");
|
|
3155
|
-
var
|
|
3718
|
+
var import_log16 = require("@dxos/log");
|
|
3156
3719
|
var import_messaging = require("@dxos/messaging");
|
|
3157
3720
|
var import_model_factory = require("@dxos/model-factory");
|
|
3158
3721
|
var import_network_manager2 = require("@dxos/network-manager");
|
|
3159
|
-
var
|
|
3160
|
-
var
|
|
3722
|
+
var import_protocols10 = require("@dxos/protocols");
|
|
3723
|
+
var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3161
3724
|
var import_text_model = require("@dxos/text-model");
|
|
3725
|
+
var import_tracing4 = require("@dxos/tracing");
|
|
3162
3726
|
|
|
3163
3727
|
// packages/sdk/client-services/src/packlets/devices/devices-service.ts
|
|
3164
3728
|
var import_async12 = require("@dxos/async");
|
|
3165
|
-
var
|
|
3166
|
-
var
|
|
3729
|
+
var import_codec_protobuf6 = require("@dxos/codec-protobuf");
|
|
3730
|
+
var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
|
|
3167
3731
|
var DevicesServiceImpl = class {
|
|
3168
3732
|
constructor(_identityManager) {
|
|
3169
3733
|
this._identityManager = _identityManager;
|
|
@@ -3172,23 +3736,19 @@ var DevicesServiceImpl = class {
|
|
|
3172
3736
|
throw new Error("Method not implemented.");
|
|
3173
3737
|
}
|
|
3174
3738
|
queryDevices() {
|
|
3175
|
-
return new
|
|
3739
|
+
return new import_codec_protobuf6.Stream(({ next }) => {
|
|
3176
3740
|
const update = () => {
|
|
3177
|
-
|
|
3178
|
-
const deviceKeys = (_a = this._identityManager.identity) == null ? void 0 : _a.authorizedDeviceKeys;
|
|
3741
|
+
const deviceKeys = this._identityManager.identity?.authorizedDeviceKeys;
|
|
3179
3742
|
if (!deviceKeys) {
|
|
3180
3743
|
next({
|
|
3181
3744
|
devices: []
|
|
3182
3745
|
});
|
|
3183
3746
|
} else {
|
|
3184
3747
|
next({
|
|
3185
|
-
devices: Array.from(deviceKeys.values()).map((key) => {
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
kind: ((_a2 = this._identityManager.identity) == null ? void 0 : _a2.deviceKey.equals(key)) ? import_services10.DeviceKind.CURRENT : import_services10.DeviceKind.TRUSTED
|
|
3190
|
-
};
|
|
3191
|
-
})
|
|
3748
|
+
devices: Array.from(deviceKeys.values()).map((key) => ({
|
|
3749
|
+
deviceKey: key,
|
|
3750
|
+
kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services11.DeviceKind.CURRENT : import_services11.DeviceKind.TRUSTED
|
|
3751
|
+
}))
|
|
3192
3752
|
});
|
|
3193
3753
|
}
|
|
3194
3754
|
};
|
|
@@ -3209,21 +3769,21 @@ var DevicesServiceImpl = class {
|
|
|
3209
3769
|
|
|
3210
3770
|
// packages/sdk/client-services/src/packlets/devtools/devtools.ts
|
|
3211
3771
|
var import_async15 = require("@dxos/async");
|
|
3212
|
-
var
|
|
3772
|
+
var import_codec_protobuf12 = require("@dxos/codec-protobuf");
|
|
3213
3773
|
|
|
3214
3774
|
// packages/sdk/client-services/src/packlets/devtools/feeds.ts
|
|
3215
3775
|
var import_async13 = require("@dxos/async");
|
|
3216
|
-
var
|
|
3776
|
+
var import_codec_protobuf7 = require("@dxos/codec-protobuf");
|
|
3217
3777
|
var import_feed_store4 = require("@dxos/feed-store");
|
|
3218
3778
|
var import_keys9 = require("@dxos/keys");
|
|
3219
|
-
var
|
|
3779
|
+
var import_util7 = require("@dxos/util");
|
|
3220
3780
|
var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
|
|
3221
|
-
return new
|
|
3781
|
+
return new import_codec_protobuf7.Stream(({ next }) => {
|
|
3222
3782
|
const subscriptions = new import_async13.EventSubscriptions();
|
|
3223
|
-
const feedMap = new
|
|
3783
|
+
const feedMap = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
|
|
3224
3784
|
const update = () => {
|
|
3225
3785
|
const { feeds } = feedStore;
|
|
3226
|
-
feeds.filter((feed) => !
|
|
3786
|
+
feeds.filter((feed) => !feedKeys?.length || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
|
|
3227
3787
|
if (!feedMap.has(feed.key)) {
|
|
3228
3788
|
feedMap.set(feed.key, feed);
|
|
3229
3789
|
feed.on("close", update);
|
|
@@ -3231,15 +3791,12 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
|
|
|
3231
3791
|
}
|
|
3232
3792
|
});
|
|
3233
3793
|
next({
|
|
3234
|
-
feeds: Array.from(feedMap.values()).map((feed) => {
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
downloaded: (_b = (_a = feed.core.bitfield) == null ? void 0 : _a.data.toBuffer()) != null ? _b : new Uint8Array()
|
|
3241
|
-
};
|
|
3242
|
-
})
|
|
3794
|
+
feeds: Array.from(feedMap.values()).map((feed) => ({
|
|
3795
|
+
feedKey: feed.key,
|
|
3796
|
+
length: feed.properties.length,
|
|
3797
|
+
bytes: feed.core.byteLength,
|
|
3798
|
+
downloaded: feed.core.bitfield?.data.toBuffer() ?? new Uint8Array()
|
|
3799
|
+
}))
|
|
3243
3800
|
});
|
|
3244
3801
|
};
|
|
3245
3802
|
subscriptions.add(feedStore.feedOpened.on(update));
|
|
@@ -3250,7 +3807,7 @@ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
|
|
|
3250
3807
|
});
|
|
3251
3808
|
};
|
|
3252
3809
|
var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
|
|
3253
|
-
return new
|
|
3810
|
+
return new import_codec_protobuf7.Stream(({ next }) => {
|
|
3254
3811
|
if (!feedKey) {
|
|
3255
3812
|
return;
|
|
3256
3813
|
}
|
|
@@ -3290,8 +3847,8 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
|
|
|
3290
3847
|
|
|
3291
3848
|
// packages/sdk/client-services/src/packlets/devtools/keys.ts
|
|
3292
3849
|
var import_async14 = require("@dxos/async");
|
|
3293
|
-
var
|
|
3294
|
-
var subscribeToKeyringKeys = ({ keyring }) => new
|
|
3850
|
+
var import_codec_protobuf8 = require("@dxos/codec-protobuf");
|
|
3851
|
+
var subscribeToKeyringKeys = ({ keyring }) => new import_codec_protobuf8.Stream(({ next, ctx }) => {
|
|
3295
3852
|
const update = async () => {
|
|
3296
3853
|
next({
|
|
3297
3854
|
keys: await keyring.list()
|
|
@@ -3302,8 +3859,8 @@ var subscribeToKeyringKeys = ({ keyring }) => new import_codec_protobuf7.Stream(
|
|
|
3302
3859
|
});
|
|
3303
3860
|
|
|
3304
3861
|
// packages/sdk/client-services/src/packlets/devtools/metadata.ts
|
|
3305
|
-
var
|
|
3306
|
-
var subscribeToMetadata = ({ context }) => new
|
|
3862
|
+
var import_codec_protobuf9 = require("@dxos/codec-protobuf");
|
|
3863
|
+
var subscribeToMetadata = ({ context }) => new import_codec_protobuf9.Stream(({ next, ctx }) => {
|
|
3307
3864
|
context.metadataStore.update.on(ctx, (data) => next({
|
|
3308
3865
|
metadata: data
|
|
3309
3866
|
}));
|
|
@@ -3313,10 +3870,10 @@ var subscribeToMetadata = ({ context }) => new import_codec_protobuf8.Stream(({
|
|
|
3313
3870
|
});
|
|
3314
3871
|
|
|
3315
3872
|
// packages/sdk/client-services/src/packlets/devtools/network.ts
|
|
3316
|
-
var
|
|
3317
|
-
var
|
|
3873
|
+
var import_codec_protobuf10 = require("@dxos/codec-protobuf");
|
|
3874
|
+
var import_context9 = require("@dxos/context");
|
|
3318
3875
|
var import_keys10 = require("@dxos/keys");
|
|
3319
|
-
var subscribeToNetworkStatus = ({ signalManager }) => new
|
|
3876
|
+
var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf10.Stream(({ next, close }) => {
|
|
3320
3877
|
const update = () => {
|
|
3321
3878
|
try {
|
|
3322
3879
|
const status = signalManager.getStatus();
|
|
@@ -3330,8 +3887,8 @@ var subscribeToNetworkStatus = ({ signalManager }) => new import_codec_protobuf9
|
|
|
3330
3887
|
signalManager.statusChanged.on(() => update());
|
|
3331
3888
|
update();
|
|
3332
3889
|
});
|
|
3333
|
-
var subscribeToSignal = ({ signalManager }) => new
|
|
3334
|
-
const ctx = new
|
|
3890
|
+
var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf10.Stream(({ next }) => {
|
|
3891
|
+
const ctx = new import_context9.Context();
|
|
3335
3892
|
signalManager.onMessage.on(ctx, (message) => {
|
|
3336
3893
|
next({
|
|
3337
3894
|
message: {
|
|
@@ -3339,51 +3896,49 @@ var subscribeToSignal = ({ signalManager }) => new import_codec_protobuf9.Stream
|
|
|
3339
3896
|
recipient: message.recipient.asUint8Array(),
|
|
3340
3897
|
payload: message.payload
|
|
3341
3898
|
},
|
|
3342
|
-
receivedAt: new Date()
|
|
3899
|
+
receivedAt: /* @__PURE__ */ new Date()
|
|
3343
3900
|
});
|
|
3344
3901
|
});
|
|
3345
3902
|
signalManager.swarmEvent.on(ctx, (swarmEvent) => {
|
|
3346
3903
|
next({
|
|
3347
3904
|
swarmEvent: swarmEvent.swarmEvent,
|
|
3348
|
-
receivedAt: new Date()
|
|
3905
|
+
receivedAt: /* @__PURE__ */ new Date()
|
|
3349
3906
|
});
|
|
3350
3907
|
});
|
|
3351
3908
|
return () => {
|
|
3352
3909
|
return ctx.dispose();
|
|
3353
3910
|
};
|
|
3354
3911
|
});
|
|
3355
|
-
var subscribeToSwarmInfo = ({ networkManager }) => new
|
|
3356
|
-
var _a;
|
|
3912
|
+
var subscribeToSwarmInfo = ({ networkManager }) => new import_codec_protobuf10.Stream(({ next }) => {
|
|
3357
3913
|
const update = () => {
|
|
3358
|
-
|
|
3359
|
-
const info = (_a2 = networkManager.connectionLog) == null ? void 0 : _a2.swarms;
|
|
3914
|
+
const info = networkManager.connectionLog?.swarms;
|
|
3360
3915
|
if (info) {
|
|
3361
3916
|
next({
|
|
3362
3917
|
data: info
|
|
3363
3918
|
});
|
|
3364
3919
|
}
|
|
3365
3920
|
};
|
|
3366
|
-
|
|
3921
|
+
networkManager.connectionLog?.update.on(update);
|
|
3367
3922
|
update();
|
|
3368
3923
|
});
|
|
3369
3924
|
|
|
3370
3925
|
// packages/sdk/client-services/src/packlets/devtools/spaces.ts
|
|
3371
|
-
var
|
|
3926
|
+
var import_codec_protobuf11 = require("@dxos/codec-protobuf");
|
|
3372
3927
|
var subscribeToSpaces = (context, { spaceKeys = [] }) => {
|
|
3373
|
-
return new
|
|
3928
|
+
return new import_codec_protobuf11.Stream(({ next }) => {
|
|
3374
3929
|
let unsubscribe;
|
|
3375
3930
|
const update = async () => {
|
|
3376
3931
|
const spaces = [
|
|
3377
3932
|
...context.spaceManager.spaces.values()
|
|
3378
3933
|
];
|
|
3379
|
-
const filteredSpaces = spaces.filter((space) => !
|
|
3934
|
+
const filteredSpaces = spaces.filter((space) => !spaceKeys?.length || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
|
|
3380
3935
|
next({
|
|
3381
3936
|
spaces: filteredSpaces.map((space) => {
|
|
3382
3937
|
const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
|
|
3383
3938
|
return {
|
|
3384
3939
|
key: space.key,
|
|
3385
3940
|
isOpen: space.isOpen,
|
|
3386
|
-
timeframe: spaceMetadata
|
|
3941
|
+
timeframe: spaceMetadata?.dataTimeframe,
|
|
3387
3942
|
genesisFeed: space.genesisFeedKey,
|
|
3388
3943
|
controlFeed: space.controlFeedKey,
|
|
3389
3944
|
dataFeed: space.dataFeedKey
|
|
@@ -3397,7 +3952,7 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
|
|
|
3397
3952
|
await update();
|
|
3398
3953
|
});
|
|
3399
3954
|
return () => {
|
|
3400
|
-
unsubscribe
|
|
3955
|
+
unsubscribe?.();
|
|
3401
3956
|
clearTimeout(timeout);
|
|
3402
3957
|
};
|
|
3403
3958
|
});
|
|
@@ -3414,7 +3969,7 @@ var DevtoolsServiceImpl = class {
|
|
|
3414
3969
|
this.params = params;
|
|
3415
3970
|
}
|
|
3416
3971
|
events(request) {
|
|
3417
|
-
return new
|
|
3972
|
+
return new import_codec_protobuf12.Stream(({ next }) => {
|
|
3418
3973
|
this.params.events.ready.on(() => {
|
|
3419
3974
|
next({
|
|
3420
3975
|
ready: {}
|
|
@@ -3428,16 +3983,15 @@ var DevtoolsServiceImpl = class {
|
|
|
3428
3983
|
};
|
|
3429
3984
|
}
|
|
3430
3985
|
async getStorageInfo() {
|
|
3431
|
-
|
|
3432
|
-
const storageUsage = (_c = await ((_b = (_a = this.params.context.storage).getDiskInfo) == null ? void 0 : _b.call(_a))) != null ? _c : {
|
|
3986
|
+
const storageUsage = await this.params.context.storage.getDiskInfo?.() ?? {
|
|
3433
3987
|
used: 0
|
|
3434
3988
|
};
|
|
3435
3989
|
const navigatorInfo = typeof navigator === "object" ? await navigator.storage.estimate() : void 0;
|
|
3436
3990
|
return {
|
|
3437
3991
|
type: this.params.context.storage.type,
|
|
3438
3992
|
storageUsage: storageUsage.used,
|
|
3439
|
-
originUsage:
|
|
3440
|
-
usageQuota:
|
|
3993
|
+
originUsage: navigatorInfo?.usage ?? 0,
|
|
3994
|
+
usageQuota: navigatorInfo?.quota ?? 0
|
|
3441
3995
|
};
|
|
3442
3996
|
}
|
|
3443
3997
|
async getBlobs() {
|
|
@@ -3521,10 +4075,10 @@ var DevtoolsServiceImpl = class {
|
|
|
3521
4075
|
};
|
|
3522
4076
|
|
|
3523
4077
|
// packages/sdk/client-services/src/packlets/locks/node.ts
|
|
3524
|
-
var
|
|
4078
|
+
var import_invariant13 = require("@dxos/invariant");
|
|
3525
4079
|
var import_lock_file = require("@dxos/lock-file");
|
|
3526
|
-
var
|
|
3527
|
-
function
|
|
4080
|
+
var import_log14 = require("@dxos/log");
|
|
4081
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
3528
4082
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3529
4083
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3530
4084
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3534,7 +4088,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
3534
4088
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3535
4089
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3536
4090
|
}
|
|
3537
|
-
var
|
|
4091
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
|
|
3538
4092
|
var Lock = class {
|
|
3539
4093
|
constructor({ lockKey: lockPath, onAcquire, onRelease }) {
|
|
3540
4094
|
this._lockPath = lockPath;
|
|
@@ -3545,101 +4099,112 @@ var Lock = class {
|
|
|
3545
4099
|
return this._lockPath;
|
|
3546
4100
|
}
|
|
3547
4101
|
async acquire() {
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
F: __dxlog_file13,
|
|
4102
|
+
(0, import_log14.log)("acquiring lock...", void 0, {
|
|
4103
|
+
F: __dxlog_file16,
|
|
3551
4104
|
L: 32,
|
|
3552
4105
|
S: this,
|
|
3553
4106
|
C: (f, a) => f(...a)
|
|
3554
4107
|
});
|
|
3555
4108
|
this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
|
|
3556
|
-
await
|
|
3557
|
-
(0,
|
|
3558
|
-
F:
|
|
4109
|
+
await this._onAcquire?.();
|
|
4110
|
+
(0, import_log14.log)("acquired lock", void 0, {
|
|
4111
|
+
F: __dxlog_file16,
|
|
3559
4112
|
L: 37,
|
|
3560
4113
|
S: this,
|
|
3561
4114
|
C: (f, a) => f(...a)
|
|
3562
4115
|
});
|
|
3563
4116
|
}
|
|
3564
4117
|
async release() {
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
4118
|
+
await this._onRelease?.();
|
|
4119
|
+
(0, import_invariant13.invariant)(this._fileHandle, "Lock is not acquired", {
|
|
4120
|
+
F: __dxlog_file16,
|
|
4121
|
+
L: 42,
|
|
4122
|
+
S: this,
|
|
4123
|
+
A: [
|
|
4124
|
+
"this._fileHandle",
|
|
4125
|
+
"'Lock is not acquired'"
|
|
4126
|
+
]
|
|
4127
|
+
});
|
|
3568
4128
|
await import_lock_file.LockFile.release(this._fileHandle);
|
|
3569
4129
|
}
|
|
3570
4130
|
};
|
|
3571
|
-
|
|
3572
|
-
|
|
4131
|
+
_ts_decorate6([
|
|
4132
|
+
import_log14.logInfo
|
|
3573
4133
|
], Lock.prototype, "lockKey", null);
|
|
3574
4134
|
|
|
3575
4135
|
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
3576
4136
|
var import_async16 = require("@dxos/async");
|
|
3577
|
-
var
|
|
3578
|
-
var
|
|
3579
|
-
var
|
|
3580
|
-
var
|
|
4137
|
+
var import_codec_protobuf13 = require("@dxos/codec-protobuf");
|
|
4138
|
+
var import_log15 = require("@dxos/log");
|
|
4139
|
+
var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
|
|
4140
|
+
var import_util8 = require("@dxos/util");
|
|
3581
4141
|
var LoggingServiceImpl = class {
|
|
3582
4142
|
constructor() {
|
|
3583
4143
|
this._logs = new import_async16.Event();
|
|
4144
|
+
this._started = /* @__PURE__ */ new Date();
|
|
3584
4145
|
this._logProcessor = (_config, entry2) => {
|
|
3585
4146
|
this._logs.emit(entry2);
|
|
3586
4147
|
};
|
|
3587
4148
|
}
|
|
3588
4149
|
async open() {
|
|
3589
|
-
|
|
4150
|
+
import_log15.log.runtimeConfig.processors.push(this._logProcessor);
|
|
3590
4151
|
}
|
|
3591
4152
|
async close() {
|
|
3592
|
-
const index =
|
|
3593
|
-
|
|
4153
|
+
const index = import_log15.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
4154
|
+
import_log15.log.runtimeConfig.processors.splice(index, 1);
|
|
3594
4155
|
}
|
|
3595
4156
|
async controlMetrics({ reset, record }) {
|
|
3596
4157
|
if (reset) {
|
|
3597
|
-
|
|
4158
|
+
import_util8.tracer.clear();
|
|
3598
4159
|
}
|
|
3599
4160
|
if (record === true) {
|
|
3600
|
-
|
|
4161
|
+
import_util8.tracer.start();
|
|
3601
4162
|
} else if (record === false) {
|
|
3602
|
-
|
|
4163
|
+
import_util8.tracer.stop();
|
|
3603
4164
|
}
|
|
3604
4165
|
return {
|
|
3605
|
-
recording:
|
|
4166
|
+
recording: import_util8.tracer.recording
|
|
3606
4167
|
};
|
|
3607
4168
|
}
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
4169
|
+
/**
|
|
4170
|
+
* @deprecated (Move to diagnostics).
|
|
4171
|
+
*/
|
|
4172
|
+
queryMetrics({ interval = 5e3 }) {
|
|
4173
|
+
const getNumericalValues = (key) => {
|
|
4174
|
+
const events = import_util8.tracer.get(key) ?? [];
|
|
3612
4175
|
return {
|
|
3613
4176
|
key,
|
|
3614
|
-
stats: (0,
|
|
4177
|
+
stats: (0, import_util8.numericalValues)(events, "duration")
|
|
3615
4178
|
};
|
|
3616
4179
|
};
|
|
3617
|
-
return new
|
|
4180
|
+
return new import_codec_protobuf13.Stream(({ next }) => {
|
|
3618
4181
|
const update = () => {
|
|
3619
4182
|
const metrics = {
|
|
3620
|
-
timestamp: new Date(),
|
|
4183
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
3621
4184
|
values: [
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
]
|
|
4185
|
+
getNumericalValues("dxos.echo.pipeline.control"),
|
|
4186
|
+
getNumericalValues("dxos.echo.pipeline.data")
|
|
4187
|
+
].filter(Boolean)
|
|
3625
4188
|
};
|
|
3626
|
-
next(
|
|
4189
|
+
next({
|
|
4190
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
4191
|
+
metrics
|
|
4192
|
+
});
|
|
3627
4193
|
};
|
|
3628
4194
|
update();
|
|
3629
|
-
const i = setInterval(update, interval);
|
|
4195
|
+
const i = setInterval(update, Math.max(interval, 1e3));
|
|
3630
4196
|
return () => {
|
|
3631
4197
|
clearInterval(i);
|
|
3632
4198
|
};
|
|
3633
4199
|
});
|
|
3634
4200
|
}
|
|
3635
4201
|
queryLogs(request) {
|
|
3636
|
-
return new
|
|
4202
|
+
return new import_codec_protobuf13.Stream(({ ctx, next }) => {
|
|
3637
4203
|
const handler = (entry2) => {
|
|
3638
|
-
var _a, _b, _c, _d, _e;
|
|
3639
4204
|
if (LOG_PROCESSING > 0) {
|
|
3640
4205
|
return;
|
|
3641
4206
|
}
|
|
3642
|
-
if (
|
|
4207
|
+
if (entry2.meta?.F.includes("logging-service") || entry2.context && Object.values(entry2.context).some((value) => typeof value === "string" && value.includes("LoggingService"))) {
|
|
3643
4208
|
return;
|
|
3644
4209
|
}
|
|
3645
4210
|
if (!shouldLog(entry2, request)) {
|
|
@@ -3647,12 +4212,12 @@ var LoggingServiceImpl = class {
|
|
|
3647
4212
|
}
|
|
3648
4213
|
const record = {
|
|
3649
4214
|
...entry2,
|
|
3650
|
-
context: (0,
|
|
3651
|
-
timestamp: new Date(),
|
|
4215
|
+
context: (0, import_util8.jsonify)((0, import_log15.getContextFromEntry)(entry2)),
|
|
4216
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
3652
4217
|
meta: {
|
|
3653
4218
|
// TODO(dmaretskyi): Fix proto.
|
|
3654
|
-
file:
|
|
3655
|
-
line:
|
|
4219
|
+
file: entry2.meta?.F ?? "",
|
|
4220
|
+
line: entry2.meta?.L ?? 0
|
|
3656
4221
|
}
|
|
3657
4222
|
};
|
|
3658
4223
|
try {
|
|
@@ -3668,35 +4233,31 @@ var LoggingServiceImpl = class {
|
|
|
3668
4233
|
};
|
|
3669
4234
|
var matchFilter = (filter, level, path, options) => {
|
|
3670
4235
|
switch (options) {
|
|
3671
|
-
case
|
|
4236
|
+
case import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE:
|
|
3672
4237
|
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
3673
|
-
case
|
|
4238
|
+
case import_services12.QueryLogsRequest.MatchingOptions.EXPLICIT:
|
|
3674
4239
|
return level === filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
3675
4240
|
}
|
|
3676
4241
|
};
|
|
3677
4242
|
var shouldLog = (entry2, request) => {
|
|
3678
|
-
|
|
3679
|
-
const options = (_a = request.options) != null ? _a : import_services11.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
4243
|
+
const options = request.options ?? import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
3680
4244
|
if (request.filters === void 0) {
|
|
3681
|
-
return options ===
|
|
4245
|
+
return options === import_services12.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
3682
4246
|
} else {
|
|
3683
|
-
return request.filters.some((filter) =>
|
|
3684
|
-
var _a2, _b;
|
|
3685
|
-
return matchFilter(filter, entry2.level, (_b = (_a2 = entry2.meta) == null ? void 0 : _a2.F) != null ? _b : "", options);
|
|
3686
|
-
});
|
|
4247
|
+
return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
|
|
3687
4248
|
}
|
|
3688
4249
|
};
|
|
3689
4250
|
var LOG_PROCESSING = 0;
|
|
3690
4251
|
|
|
3691
4252
|
// packages/sdk/client-services/src/packlets/network/network-service.ts
|
|
3692
|
-
var
|
|
4253
|
+
var import_codec_protobuf14 = require("@dxos/codec-protobuf");
|
|
3693
4254
|
var NetworkServiceImpl = class {
|
|
3694
4255
|
constructor(networkManager, signalManager) {
|
|
3695
4256
|
this.networkManager = networkManager;
|
|
3696
4257
|
this.signalManager = signalManager;
|
|
3697
4258
|
}
|
|
3698
4259
|
queryStatus() {
|
|
3699
|
-
return new
|
|
4260
|
+
return new import_codec_protobuf14.Stream(({ next }) => {
|
|
3700
4261
|
const update = () => {
|
|
3701
4262
|
next({
|
|
3702
4263
|
swarm: this.networkManager.connectionState,
|
|
@@ -3725,10 +4286,10 @@ var import_client_protocol4 = require("@dxos/client-protocol");
|
|
|
3725
4286
|
var import_errors5 = require("@dxos/errors");
|
|
3726
4287
|
var import_config = require("@dxos/protocols/proto/dxos/config");
|
|
3727
4288
|
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
3728
|
-
var
|
|
4289
|
+
var import_util9 = require("@dxos/util");
|
|
3729
4290
|
var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
|
|
3730
4291
|
var createStorageObjects = (config) => {
|
|
3731
|
-
const { path = (0,
|
|
4292
|
+
const { path = (0, import_util9.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage", storageType, keyStorage, persistent = false } = config ?? {};
|
|
3732
4293
|
if (persistent && storageType === StorageDriver.RAM) {
|
|
3733
4294
|
throw new import_errors5.InvalidConfigError("RAM storage cannot be used in persistent mode.");
|
|
3734
4295
|
}
|
|
@@ -3770,25 +4331,40 @@ var toStorageType = (type) => {
|
|
|
3770
4331
|
};
|
|
3771
4332
|
|
|
3772
4333
|
// packages/sdk/client-services/src/packlets/system/system-service.ts
|
|
3773
|
-
var
|
|
4334
|
+
var import_codec_protobuf15 = require("@dxos/codec-protobuf");
|
|
4335
|
+
var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
|
|
4336
|
+
var import_util10 = require("@dxos/util");
|
|
3774
4337
|
var SystemServiceImpl = class {
|
|
3775
|
-
constructor({ config, statusUpdate, onUpdateStatus, getCurrentStatus, onReset }) {
|
|
4338
|
+
constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
|
|
3776
4339
|
this._config = config;
|
|
3777
4340
|
this._statusUpdate = statusUpdate;
|
|
3778
4341
|
this._getCurrentStatus = getCurrentStatus;
|
|
4342
|
+
this._getDiagnostics = getDiagnostics;
|
|
3779
4343
|
this._onUpdateStatus = onUpdateStatus;
|
|
3780
4344
|
this._onReset = onReset;
|
|
3781
4345
|
}
|
|
3782
4346
|
async getConfig() {
|
|
3783
|
-
|
|
3784
|
-
|
|
4347
|
+
return this._config?.values ?? {};
|
|
4348
|
+
}
|
|
4349
|
+
/**
|
|
4350
|
+
* NOTE: Since this is serialized as a JSON object, we allow the option to serialize keys.
|
|
4351
|
+
*/
|
|
4352
|
+
async getDiagnostics({ keys } = {}) {
|
|
4353
|
+
const diagnostics = await this._getDiagnostics();
|
|
4354
|
+
return {
|
|
4355
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
4356
|
+
diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)({
|
|
4357
|
+
truncate: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
|
|
4358
|
+
humanize: keys === import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
|
|
4359
|
+
})))
|
|
4360
|
+
};
|
|
3785
4361
|
}
|
|
3786
4362
|
async updateStatus({ status }) {
|
|
3787
4363
|
await this._onUpdateStatus(status);
|
|
3788
4364
|
}
|
|
3789
4365
|
// TODO(burdon): Standardize interval option in stream request?
|
|
3790
4366
|
queryStatus({ interval = 3e3 } = {}) {
|
|
3791
|
-
return new
|
|
4367
|
+
return new import_codec_protobuf15.Stream(({ next }) => {
|
|
3792
4368
|
const update = () => {
|
|
3793
4369
|
next({
|
|
3794
4370
|
status: this._getCurrentStatus()
|
|
@@ -3833,7 +4409,7 @@ var ServiceRegistry = class {
|
|
|
3833
4409
|
};
|
|
3834
4410
|
|
|
3835
4411
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
3836
|
-
function
|
|
4412
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
3837
4413
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3838
4414
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3839
4415
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3843,23 +4419,22 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3843
4419
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3844
4420
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3845
4421
|
}
|
|
3846
|
-
var
|
|
4422
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
|
|
3847
4423
|
var createDefaultModelFactory = () => {
|
|
3848
|
-
return new import_model_factory.ModelFactory().registerModel(
|
|
4424
|
+
return new import_model_factory.ModelFactory().registerModel(import_document_model2.DocumentModel).registerModel(import_text_model.TextModel);
|
|
3849
4425
|
};
|
|
3850
|
-
var ClientServicesHost = class {
|
|
4426
|
+
var ClientServicesHost = class ClientServicesHost2 {
|
|
3851
4427
|
constructor({
|
|
3852
4428
|
config,
|
|
3853
4429
|
modelFactory = createDefaultModelFactory(),
|
|
3854
|
-
// TODO(burdon): Create ApolloLink abstraction (see Client).
|
|
3855
4430
|
transportFactory,
|
|
3856
4431
|
signalManager,
|
|
3857
|
-
connectionLog,
|
|
3858
4432
|
storage,
|
|
3859
4433
|
// TODO(wittjosiah): Turn this on by default.
|
|
3860
4434
|
lockKey,
|
|
3861
4435
|
callbacks
|
|
3862
4436
|
} = {}) {
|
|
4437
|
+
this._tracingService = import_tracing4.TRACE_PROCESSOR.createTraceSender();
|
|
3863
4438
|
this._statusUpdate = new import_async17.Event();
|
|
3864
4439
|
this._opening = false;
|
|
3865
4440
|
this._open = false;
|
|
@@ -3878,7 +4453,7 @@ var ClientServicesHost = class {
|
|
|
3878
4453
|
lockKey,
|
|
3879
4454
|
onAcquire: () => {
|
|
3880
4455
|
if (!this._opening) {
|
|
3881
|
-
void this.open();
|
|
4456
|
+
void this.open(new import_context10.Context());
|
|
3882
4457
|
}
|
|
3883
4458
|
},
|
|
3884
4459
|
onRelease: () => this.close()
|
|
@@ -3887,13 +4462,15 @@ var ClientServicesHost = class {
|
|
|
3887
4462
|
this._systemService = new SystemServiceImpl({
|
|
3888
4463
|
config: this._config,
|
|
3889
4464
|
statusUpdate: this._statusUpdate,
|
|
3890
|
-
getCurrentStatus: () => this.isOpen ?
|
|
4465
|
+
getCurrentStatus: () => this.isOpen ? import_services14.SystemStatus.ACTIVE : import_services14.SystemStatus.INACTIVE,
|
|
4466
|
+
getDiagnostics: () => {
|
|
4467
|
+
return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
|
|
4468
|
+
},
|
|
3891
4469
|
onUpdateStatus: async (status) => {
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
await ((_b = this._resourceLock) == null ? void 0 : _b.release());
|
|
4470
|
+
if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
|
|
4471
|
+
await this._resourceLock?.acquire();
|
|
4472
|
+
} else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
|
|
4473
|
+
await this._resourceLock?.release();
|
|
3897
4474
|
}
|
|
3898
4475
|
},
|
|
3899
4476
|
onReset: async () => {
|
|
@@ -3902,12 +4479,19 @@ var ClientServicesHost = class {
|
|
|
3902
4479
|
});
|
|
3903
4480
|
this._loggingService = new LoggingServiceImpl();
|
|
3904
4481
|
this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
|
|
3905
|
-
SystemService: this._systemService
|
|
4482
|
+
SystemService: this._systemService,
|
|
4483
|
+
TracingService: this._tracingService
|
|
3906
4484
|
});
|
|
3907
4485
|
}
|
|
3908
4486
|
get isOpen() {
|
|
3909
4487
|
return this._open;
|
|
3910
4488
|
}
|
|
4489
|
+
get config() {
|
|
4490
|
+
return this._config;
|
|
4491
|
+
}
|
|
4492
|
+
get context() {
|
|
4493
|
+
return this._serviceContext;
|
|
4494
|
+
}
|
|
3911
4495
|
get serviceRegistry() {
|
|
3912
4496
|
return this._serviceRegistry;
|
|
3913
4497
|
}
|
|
@@ -3923,59 +4507,125 @@ var ClientServicesHost = class {
|
|
|
3923
4507
|
* Can only be called once.
|
|
3924
4508
|
*/
|
|
3925
4509
|
initialize({ config, ...options }) {
|
|
3926
|
-
|
|
3927
|
-
|
|
4510
|
+
(0, import_invariant14.invariant)(!this._open, "service host is open", {
|
|
4511
|
+
F: __dxlog_file17,
|
|
4512
|
+
L: 181,
|
|
4513
|
+
S: this,
|
|
4514
|
+
A: [
|
|
4515
|
+
"!this._open",
|
|
4516
|
+
"'service host is open'"
|
|
4517
|
+
]
|
|
4518
|
+
});
|
|
4519
|
+
(0, import_log16.log)("initializing...", void 0, {
|
|
4520
|
+
F: __dxlog_file17,
|
|
4521
|
+
L: 182,
|
|
4522
|
+
S: this,
|
|
4523
|
+
C: (f, a) => f(...a)
|
|
4524
|
+
});
|
|
3928
4525
|
if (config) {
|
|
3929
|
-
(0,
|
|
4526
|
+
(0, import_invariant14.invariant)(!this._config, "config already set", {
|
|
4527
|
+
F: __dxlog_file17,
|
|
4528
|
+
L: 185,
|
|
4529
|
+
S: this,
|
|
4530
|
+
A: [
|
|
4531
|
+
"!this._config",
|
|
4532
|
+
"'config already set'"
|
|
4533
|
+
]
|
|
4534
|
+
});
|
|
3930
4535
|
this._config = config;
|
|
3931
4536
|
if (!this._storage) {
|
|
3932
4537
|
this._storage = createStorageObjects(config.get("runtime.client.storage", {})).storage;
|
|
3933
4538
|
}
|
|
3934
4539
|
}
|
|
3935
4540
|
const { connectionLog = true, transportFactory = (0, import_network_manager2.createWebRTCTransportFactory)({
|
|
3936
|
-
iceServers:
|
|
3937
|
-
}), signalManager = new import_messaging.WebsocketSignalManager(
|
|
4541
|
+
iceServers: this._config?.get("runtime.services.ice")
|
|
4542
|
+
}), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
|
|
3938
4543
|
this._signalManager = signalManager;
|
|
3939
|
-
(0,
|
|
4544
|
+
(0, import_invariant14.invariant)(!this._networkManager, "network manager already set", {
|
|
4545
|
+
F: __dxlog_file17,
|
|
4546
|
+
L: 201,
|
|
4547
|
+
S: this,
|
|
4548
|
+
A: [
|
|
4549
|
+
"!this._networkManager",
|
|
4550
|
+
"'network manager already set'"
|
|
4551
|
+
]
|
|
4552
|
+
});
|
|
3940
4553
|
this._networkManager = new import_network_manager2.NetworkManager({
|
|
3941
4554
|
log: connectionLog,
|
|
3942
4555
|
transportFactory,
|
|
3943
4556
|
signalManager
|
|
3944
4557
|
});
|
|
4558
|
+
(0, import_log16.log)("initialized", void 0, {
|
|
4559
|
+
F: __dxlog_file17,
|
|
4560
|
+
L: 208,
|
|
4561
|
+
S: this,
|
|
4562
|
+
C: (f, a) => f(...a)
|
|
4563
|
+
});
|
|
3945
4564
|
}
|
|
3946
|
-
async open() {
|
|
3947
|
-
var _a, _b, _c;
|
|
4565
|
+
async open(ctx) {
|
|
3948
4566
|
if (this._open) {
|
|
3949
4567
|
return;
|
|
3950
4568
|
}
|
|
3951
4569
|
const traceId = import_keys12.PublicKey.random().toHex();
|
|
3952
|
-
|
|
4570
|
+
import_log16.log.trace("dxos.client-services.host.open", import_protocols10.trace.begin({
|
|
3953
4571
|
id: traceId
|
|
3954
4572
|
}), {
|
|
3955
|
-
F:
|
|
3956
|
-
L:
|
|
4573
|
+
F: __dxlog_file17,
|
|
4574
|
+
L: 219,
|
|
3957
4575
|
S: this,
|
|
3958
4576
|
C: (f, a) => f(...a)
|
|
3959
4577
|
});
|
|
3960
|
-
(0,
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
4578
|
+
(0, import_invariant14.invariant)(this._config, "config not set", {
|
|
4579
|
+
F: __dxlog_file17,
|
|
4580
|
+
L: 221,
|
|
4581
|
+
S: this,
|
|
4582
|
+
A: [
|
|
4583
|
+
"this._config",
|
|
4584
|
+
"'config not set'"
|
|
4585
|
+
]
|
|
4586
|
+
});
|
|
4587
|
+
(0, import_invariant14.invariant)(this._storage, "storage not set", {
|
|
4588
|
+
F: __dxlog_file17,
|
|
4589
|
+
L: 222,
|
|
4590
|
+
S: this,
|
|
4591
|
+
A: [
|
|
4592
|
+
"this._storage",
|
|
4593
|
+
"'storage not set'"
|
|
4594
|
+
]
|
|
4595
|
+
});
|
|
4596
|
+
(0, import_invariant14.invariant)(this._signalManager, "signal manager not set", {
|
|
4597
|
+
F: __dxlog_file17,
|
|
4598
|
+
L: 223,
|
|
4599
|
+
S: this,
|
|
4600
|
+
A: [
|
|
4601
|
+
"this._signalManager",
|
|
4602
|
+
"'signal manager not set'"
|
|
4603
|
+
]
|
|
4604
|
+
});
|
|
4605
|
+
(0, import_invariant14.invariant)(this._networkManager, "network manager not set", {
|
|
4606
|
+
F: __dxlog_file17,
|
|
4607
|
+
L: 224,
|
|
4608
|
+
S: this,
|
|
4609
|
+
A: [
|
|
4610
|
+
"this._networkManager",
|
|
4611
|
+
"'network manager not set'"
|
|
4612
|
+
]
|
|
4613
|
+
});
|
|
3964
4614
|
this._opening = true;
|
|
3965
|
-
(0,
|
|
3966
|
-
lockKey:
|
|
4615
|
+
(0, import_log16.log)("opening...", {
|
|
4616
|
+
lockKey: this._resourceLock?.lockKey
|
|
3967
4617
|
}, {
|
|
3968
|
-
F:
|
|
3969
|
-
L:
|
|
4618
|
+
F: __dxlog_file17,
|
|
4619
|
+
L: 227,
|
|
3970
4620
|
S: this,
|
|
3971
4621
|
C: (f, a) => f(...a)
|
|
3972
4622
|
});
|
|
3973
|
-
await
|
|
4623
|
+
await this._resourceLock?.acquire();
|
|
3974
4624
|
await this._loggingService.open();
|
|
3975
4625
|
this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._signalManager, this._modelFactory);
|
|
3976
4626
|
this._serviceRegistry.setServices({
|
|
3977
4627
|
SystemService: this._systemService,
|
|
3978
|
-
IdentityService: new IdentityServiceImpl(this._serviceContext),
|
|
4628
|
+
IdentityService: new IdentityServiceImpl((params) => this._serviceContext.createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring),
|
|
3979
4629
|
InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
|
|
3980
4630
|
DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
|
|
3981
4631
|
SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
|
|
@@ -3985,6 +4635,7 @@ var ClientServicesHost = class {
|
|
|
3985
4635
|
DataService: new import_echo_pipeline4.DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
|
|
3986
4636
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
3987
4637
|
LoggingService: this._loggingService,
|
|
4638
|
+
TracingService: this._tracingService,
|
|
3988
4639
|
// TODO(burdon): Move to new protobuf definitions.
|
|
3989
4640
|
DevtoolsHost: new DevtoolsServiceImpl({
|
|
3990
4641
|
events: new DevtoolsHostEvents(),
|
|
@@ -3992,39 +4643,38 @@ var ClientServicesHost = class {
|
|
|
3992
4643
|
context: this._serviceContext
|
|
3993
4644
|
})
|
|
3994
4645
|
});
|
|
3995
|
-
await this._serviceContext.open();
|
|
4646
|
+
await this._serviceContext.open(ctx);
|
|
3996
4647
|
this._opening = false;
|
|
3997
4648
|
this._open = true;
|
|
3998
4649
|
this._statusUpdate.emit();
|
|
3999
|
-
const deviceKey =
|
|
4000
|
-
(0,
|
|
4650
|
+
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
4651
|
+
(0, import_log16.log)("opened", {
|
|
4001
4652
|
deviceKey
|
|
4002
4653
|
}, {
|
|
4003
|
-
F:
|
|
4004
|
-
L:
|
|
4654
|
+
F: __dxlog_file17,
|
|
4655
|
+
L: 284,
|
|
4005
4656
|
S: this,
|
|
4006
4657
|
C: (f, a) => f(...a)
|
|
4007
4658
|
});
|
|
4008
|
-
|
|
4659
|
+
import_log16.log.trace("dxos.client-services.host.open", import_protocols10.trace.end({
|
|
4009
4660
|
id: traceId
|
|
4010
4661
|
}), {
|
|
4011
|
-
F:
|
|
4012
|
-
L:
|
|
4662
|
+
F: __dxlog_file17,
|
|
4663
|
+
L: 285,
|
|
4013
4664
|
S: this,
|
|
4014
4665
|
C: (f, a) => f(...a)
|
|
4015
4666
|
});
|
|
4016
4667
|
}
|
|
4017
4668
|
async close() {
|
|
4018
|
-
var _a;
|
|
4019
4669
|
if (!this._open) {
|
|
4020
4670
|
return;
|
|
4021
4671
|
}
|
|
4022
|
-
const deviceKey =
|
|
4023
|
-
(0,
|
|
4672
|
+
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
4673
|
+
(0, import_log16.log)("closing...", {
|
|
4024
4674
|
deviceKey
|
|
4025
4675
|
}, {
|
|
4026
|
-
F:
|
|
4027
|
-
L:
|
|
4676
|
+
F: __dxlog_file17,
|
|
4677
|
+
L: 296,
|
|
4028
4678
|
S: this,
|
|
4029
4679
|
C: (f, a) => f(...a)
|
|
4030
4680
|
});
|
|
@@ -4035,59 +4685,70 @@ var ClientServicesHost = class {
|
|
|
4035
4685
|
await this._serviceContext.close();
|
|
4036
4686
|
this._open = false;
|
|
4037
4687
|
this._statusUpdate.emit();
|
|
4038
|
-
(0,
|
|
4688
|
+
(0, import_log16.log)("closed", {
|
|
4039
4689
|
deviceKey
|
|
4040
4690
|
}, {
|
|
4041
|
-
F:
|
|
4042
|
-
L:
|
|
4691
|
+
F: __dxlog_file17,
|
|
4692
|
+
L: 302,
|
|
4043
4693
|
S: this,
|
|
4044
4694
|
C: (f, a) => f(...a)
|
|
4045
4695
|
});
|
|
4046
4696
|
}
|
|
4047
4697
|
async reset() {
|
|
4048
|
-
var _a, _b, _c;
|
|
4049
4698
|
const traceId = import_keys12.PublicKey.random().toHex();
|
|
4050
|
-
|
|
4699
|
+
import_log16.log.trace("dxos.sdk.client-services-host.reset", import_protocols10.trace.begin({
|
|
4051
4700
|
id: traceId
|
|
4052
4701
|
}), {
|
|
4053
|
-
F:
|
|
4054
|
-
L:
|
|
4702
|
+
F: __dxlog_file17,
|
|
4703
|
+
L: 307,
|
|
4055
4704
|
S: this,
|
|
4056
4705
|
C: (f, a) => f(...a)
|
|
4057
4706
|
});
|
|
4058
|
-
(0,
|
|
4059
|
-
F:
|
|
4060
|
-
L:
|
|
4707
|
+
(0, import_log16.log)("resetting...", void 0, {
|
|
4708
|
+
F: __dxlog_file17,
|
|
4709
|
+
L: 309,
|
|
4061
4710
|
S: this,
|
|
4062
4711
|
C: (f, a) => f(...a)
|
|
4063
4712
|
});
|
|
4064
|
-
await
|
|
4713
|
+
await this._serviceContext?.close();
|
|
4065
4714
|
await this._storage.reset();
|
|
4066
|
-
(0,
|
|
4067
|
-
F:
|
|
4068
|
-
L:
|
|
4715
|
+
(0, import_log16.log)("reset", void 0, {
|
|
4716
|
+
F: __dxlog_file17,
|
|
4717
|
+
L: 312,
|
|
4069
4718
|
S: this,
|
|
4070
4719
|
C: (f, a) => f(...a)
|
|
4071
4720
|
});
|
|
4072
|
-
|
|
4721
|
+
import_log16.log.trace("dxos.sdk.client-services-host.reset", import_protocols10.trace.end({
|
|
4073
4722
|
id: traceId
|
|
4074
4723
|
}), {
|
|
4075
|
-
F:
|
|
4076
|
-
L:
|
|
4724
|
+
F: __dxlog_file17,
|
|
4725
|
+
L: 313,
|
|
4077
4726
|
S: this,
|
|
4078
4727
|
C: (f, a) => f(...a)
|
|
4079
4728
|
});
|
|
4080
|
-
await
|
|
4729
|
+
await this._callbacks?.onReset?.();
|
|
4081
4730
|
}
|
|
4082
4731
|
};
|
|
4083
|
-
|
|
4084
|
-
|
|
4732
|
+
_ts_decorate7([
|
|
4733
|
+
import_tracing4.trace.info()
|
|
4734
|
+
], ClientServicesHost.prototype, "_opening", void 0);
|
|
4735
|
+
_ts_decorate7([
|
|
4736
|
+
import_tracing4.trace.info()
|
|
4737
|
+
], ClientServicesHost.prototype, "_open", void 0);
|
|
4738
|
+
_ts_decorate7([
|
|
4739
|
+
import_async17.synchronized,
|
|
4740
|
+
import_tracing4.trace.span()
|
|
4085
4741
|
], ClientServicesHost.prototype, "open", null);
|
|
4086
|
-
|
|
4087
|
-
import_async17.synchronized
|
|
4742
|
+
_ts_decorate7([
|
|
4743
|
+
import_async17.synchronized,
|
|
4744
|
+
import_tracing4.trace.span()
|
|
4088
4745
|
], ClientServicesHost.prototype, "close", null);
|
|
4746
|
+
ClientServicesHost = _ts_decorate7([
|
|
4747
|
+
import_tracing4.trace.resource()
|
|
4748
|
+
], ClientServicesHost);
|
|
4089
4749
|
|
|
4090
4750
|
// packages/sdk/client-services/src/packlets/testing/invitation-utils.ts
|
|
4751
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/testing/invitation-utils.ts";
|
|
4091
4752
|
var sanitizeInvitation = (invitation) => {
|
|
4092
4753
|
return {
|
|
4093
4754
|
invitationId: invitation.invitationId,
|
|
@@ -4105,40 +4766,46 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4105
4766
|
const authCode = new import_async18.Trigger();
|
|
4106
4767
|
const hostObservable = createInvitation(host, options);
|
|
4107
4768
|
hostObservable.subscribe(async (hostInvitation) => {
|
|
4108
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
4109
4769
|
switch (hostInvitation.state) {
|
|
4110
|
-
case
|
|
4111
|
-
if (
|
|
4770
|
+
case import_services15.Invitation.State.CONNECTING: {
|
|
4771
|
+
if (hooks?.host?.onConnecting?.(hostObservable)) {
|
|
4112
4772
|
break;
|
|
4113
4773
|
}
|
|
4114
4774
|
const guestObservable = acceptInvitation(guest, hostInvitation);
|
|
4115
4775
|
guestObservable.subscribe(async (guestInvitation) => {
|
|
4116
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2;
|
|
4117
4776
|
switch (guestInvitation.state) {
|
|
4118
|
-
case
|
|
4119
|
-
if (
|
|
4777
|
+
case import_services15.Invitation.State.CONNECTING: {
|
|
4778
|
+
if (hooks?.guest?.onConnecting?.(guestObservable)) {
|
|
4120
4779
|
break;
|
|
4121
4780
|
}
|
|
4122
|
-
(0,
|
|
4781
|
+
(0, import_invariant15.invariant)(hostInvitation.swarmKey.equals(guestInvitation.swarmKey), void 0, {
|
|
4782
|
+
F: __dxlog_file18,
|
|
4783
|
+
L: 84,
|
|
4784
|
+
S: void 0,
|
|
4785
|
+
A: [
|
|
4786
|
+
"hostInvitation.swarmKey!.equals(guestInvitation.swarmKey!)",
|
|
4787
|
+
""
|
|
4788
|
+
]
|
|
4789
|
+
});
|
|
4123
4790
|
break;
|
|
4124
4791
|
}
|
|
4125
|
-
case
|
|
4126
|
-
|
|
4792
|
+
case import_services15.Invitation.State.CONNECTED: {
|
|
4793
|
+
hooks?.guest?.onConnected?.(guestObservable);
|
|
4127
4794
|
break;
|
|
4128
4795
|
}
|
|
4129
|
-
case
|
|
4130
|
-
if (
|
|
4796
|
+
case import_services15.Invitation.State.READY_FOR_AUTHENTICATION: {
|
|
4797
|
+
if (hooks?.guest?.onReady?.(guestObservable)) {
|
|
4131
4798
|
break;
|
|
4132
4799
|
}
|
|
4133
4800
|
await guestObservable.authenticate(await authCode.wait());
|
|
4134
4801
|
break;
|
|
4135
4802
|
}
|
|
4136
|
-
case
|
|
4137
|
-
|
|
4803
|
+
case import_services15.Invitation.State.AUTHENTICATING: {
|
|
4804
|
+
hooks?.guest?.onAuthenticating?.(guestObservable);
|
|
4138
4805
|
break;
|
|
4139
4806
|
}
|
|
4140
|
-
case
|
|
4141
|
-
if (
|
|
4807
|
+
case import_services15.Invitation.State.SUCCESS: {
|
|
4808
|
+
if (hooks?.guest?.onSuccess?.(guestObservable)) {
|
|
4142
4809
|
break;
|
|
4143
4810
|
}
|
|
4144
4811
|
guestComplete.wake({
|
|
@@ -4146,8 +4813,8 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4146
4813
|
});
|
|
4147
4814
|
break;
|
|
4148
4815
|
}
|
|
4149
|
-
case
|
|
4150
|
-
if (
|
|
4816
|
+
case import_services15.Invitation.State.CANCELLED: {
|
|
4817
|
+
if (hooks?.guest?.onCancelled?.(guestObservable)) {
|
|
4151
4818
|
break;
|
|
4152
4819
|
}
|
|
4153
4820
|
guestComplete.wake({
|
|
@@ -4155,8 +4822,8 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4155
4822
|
});
|
|
4156
4823
|
break;
|
|
4157
4824
|
}
|
|
4158
|
-
case
|
|
4159
|
-
if (
|
|
4825
|
+
case import_services15.Invitation.State.TIMEOUT: {
|
|
4826
|
+
if (hooks?.guest?.onTimeout?.(guestObservable)) {
|
|
4160
4827
|
return;
|
|
4161
4828
|
}
|
|
4162
4829
|
guestComplete.wake({
|
|
@@ -4165,8 +4832,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4165
4832
|
}
|
|
4166
4833
|
}
|
|
4167
4834
|
}, (error) => {
|
|
4168
|
-
|
|
4169
|
-
if ((_b2 = (_a2 = hooks == null ? void 0 : hooks.guest) == null ? void 0 : _a2.onError) == null ? void 0 : _b2.call(_a2, guestObservable)) {
|
|
4835
|
+
if (hooks?.guest?.onError?.(guestObservable)) {
|
|
4170
4836
|
return;
|
|
4171
4837
|
}
|
|
4172
4838
|
guestComplete.wake({
|
|
@@ -4175,12 +4841,12 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4175
4841
|
});
|
|
4176
4842
|
break;
|
|
4177
4843
|
}
|
|
4178
|
-
case
|
|
4179
|
-
|
|
4844
|
+
case import_services15.Invitation.State.CONNECTED: {
|
|
4845
|
+
hooks?.host?.onConnected?.(hostObservable);
|
|
4180
4846
|
break;
|
|
4181
4847
|
}
|
|
4182
|
-
case
|
|
4183
|
-
if (
|
|
4848
|
+
case import_services15.Invitation.State.READY_FOR_AUTHENTICATION: {
|
|
4849
|
+
if (hooks?.host?.onReady?.(hostObservable)) {
|
|
4184
4850
|
break;
|
|
4185
4851
|
}
|
|
4186
4852
|
if (hostInvitation.authCode) {
|
|
@@ -4188,12 +4854,12 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4188
4854
|
}
|
|
4189
4855
|
break;
|
|
4190
4856
|
}
|
|
4191
|
-
case
|
|
4192
|
-
|
|
4857
|
+
case import_services15.Invitation.State.AUTHENTICATING: {
|
|
4858
|
+
hooks?.host?.onAuthenticating?.(hostObservable);
|
|
4193
4859
|
break;
|
|
4194
4860
|
}
|
|
4195
|
-
case
|
|
4196
|
-
if (
|
|
4861
|
+
case import_services15.Invitation.State.SUCCESS: {
|
|
4862
|
+
if (hooks?.host?.onSuccess?.(hostObservable)) {
|
|
4197
4863
|
break;
|
|
4198
4864
|
}
|
|
4199
4865
|
hostComplete.wake({
|
|
@@ -4201,8 +4867,8 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4201
4867
|
});
|
|
4202
4868
|
break;
|
|
4203
4869
|
}
|
|
4204
|
-
case
|
|
4205
|
-
if (
|
|
4870
|
+
case import_services15.Invitation.State.CANCELLED: {
|
|
4871
|
+
if (hooks?.host?.onCancelled?.(hostObservable)) {
|
|
4206
4872
|
break;
|
|
4207
4873
|
}
|
|
4208
4874
|
hostComplete.wake({
|
|
@@ -4210,8 +4876,8 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4210
4876
|
});
|
|
4211
4877
|
break;
|
|
4212
4878
|
}
|
|
4213
|
-
case
|
|
4214
|
-
if (
|
|
4879
|
+
case import_services15.Invitation.State.TIMEOUT: {
|
|
4880
|
+
if (hooks?.host?.onTimeout?.(hostObservable)) {
|
|
4215
4881
|
break;
|
|
4216
4882
|
}
|
|
4217
4883
|
hostComplete.wake({
|
|
@@ -4221,8 +4887,7 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4221
4887
|
}
|
|
4222
4888
|
}
|
|
4223
4889
|
}, (error) => {
|
|
4224
|
-
|
|
4225
|
-
if ((_b = (_a = hooks == null ? void 0 : hooks.host) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, hostObservable)) {
|
|
4890
|
+
if (hooks?.host?.onError?.(hostObservable)) {
|
|
4226
4891
|
return;
|
|
4227
4892
|
}
|
|
4228
4893
|
hostComplete.wake({
|
|
@@ -4235,13 +4900,13 @@ var performInvitation = ({ host, guest, options, hooks }) => {
|
|
|
4235
4900
|
];
|
|
4236
4901
|
};
|
|
4237
4902
|
var createInvitation = (host, options) => {
|
|
4238
|
-
options
|
|
4239
|
-
authMethod:
|
|
4240
|
-
...options
|
|
4903
|
+
options ??= {
|
|
4904
|
+
authMethod: import_services15.Invitation.AuthMethod.NONE,
|
|
4905
|
+
...options ?? {}
|
|
4241
4906
|
};
|
|
4242
4907
|
if (host instanceof ServiceContext) {
|
|
4243
4908
|
const hostHandler = host.getInvitationHandler({
|
|
4244
|
-
kind:
|
|
4909
|
+
kind: import_services15.Invitation.Kind.SPACE,
|
|
4245
4910
|
...options
|
|
4246
4911
|
});
|
|
4247
4912
|
return host.invitations.createInvitation(hostHandler, options);
|
|
@@ -4260,8 +4925,8 @@ var acceptInvitation = (guest, invitation) => {
|
|
|
4260
4925
|
};
|
|
4261
4926
|
|
|
4262
4927
|
// packages/sdk/client-services/src/packlets/testing/test-builder.ts
|
|
4263
|
-
var
|
|
4264
|
-
var
|
|
4928
|
+
var import_context11 = require("@dxos/context");
|
|
4929
|
+
var import_credentials16 = require("@dxos/credentials");
|
|
4265
4930
|
var import_debug8 = require("@dxos/debug");
|
|
4266
4931
|
var import_echo_pipeline5 = require("@dxos/echo-pipeline");
|
|
4267
4932
|
var import_testing = require("@dxos/echo-pipeline/testing");
|
|
@@ -4295,7 +4960,7 @@ var createPeers = async (numPeers) => {
|
|
|
4295
4960
|
const peer = createServiceContext({
|
|
4296
4961
|
signalContext
|
|
4297
4962
|
});
|
|
4298
|
-
await peer.open();
|
|
4963
|
+
await peer.open(new import_context11.Context());
|
|
4299
4964
|
return peer;
|
|
4300
4965
|
}));
|
|
4301
4966
|
};
|
|
@@ -4310,7 +4975,7 @@ var syncItemsLocal = async (db1, db2) => {
|
|
|
4310
4975
|
var TestBuilder = class {
|
|
4311
4976
|
constructor() {
|
|
4312
4977
|
this.signalContext = new import_messaging2.MemorySignalManagerContext();
|
|
4313
|
-
this._ctx = new
|
|
4978
|
+
this._ctx = new import_context11.Context();
|
|
4314
4979
|
}
|
|
4315
4980
|
createPeer(peerOptions) {
|
|
4316
4981
|
const peer = new TestPeer(this.signalContext, peerOptions);
|
|
@@ -4333,18 +4998,15 @@ var TestPeer = class {
|
|
|
4333
4998
|
return this._props;
|
|
4334
4999
|
}
|
|
4335
5000
|
get storage() {
|
|
4336
|
-
|
|
4337
|
-
return (_b = (_a = this._props).storage) != null ? _b : _a.storage = (0, import_random_access_storage2.createStorage)({
|
|
5001
|
+
return this._props.storage ??= (0, import_random_access_storage2.createStorage)({
|
|
4338
5002
|
type: this.opts.storageType
|
|
4339
5003
|
});
|
|
4340
5004
|
}
|
|
4341
5005
|
get keyring() {
|
|
4342
|
-
|
|
4343
|
-
return (_b = (_a = this._props).keyring) != null ? _b : _a.keyring = new import_keyring2.Keyring(this.storage.createDirectory("keyring"));
|
|
5006
|
+
return this._props.keyring ??= new import_keyring2.Keyring(this.storage.createDirectory("keyring"));
|
|
4344
5007
|
}
|
|
4345
5008
|
get feedStore() {
|
|
4346
|
-
|
|
4347
|
-
return (_b = (_a = this._props).feedStore) != null ? _b : _a.feedStore = new import_feed_store5.FeedStore({
|
|
5009
|
+
return this._props.feedStore ??= new import_feed_store5.FeedStore({
|
|
4348
5010
|
factory: new import_feed_store5.FeedFactory({
|
|
4349
5011
|
root: this.storage.createDirectory("feeds"),
|
|
4350
5012
|
signer: this.keyring,
|
|
@@ -4355,27 +5017,22 @@ var TestPeer = class {
|
|
|
4355
5017
|
});
|
|
4356
5018
|
}
|
|
4357
5019
|
get metadataStore() {
|
|
4358
|
-
|
|
4359
|
-
return (_b = (_a = this._props).metadataStore) != null ? _b : _a.metadataStore = new import_echo_pipeline5.MetadataStore(this.storage.createDirectory("metadata"));
|
|
5020
|
+
return this._props.metadataStore ??= new import_echo_pipeline5.MetadataStore(this.storage.createDirectory("metadata"));
|
|
4360
5021
|
}
|
|
4361
5022
|
get blobStore() {
|
|
4362
|
-
|
|
4363
|
-
return (_b = (_a = this._props).blobStore) != null ? _b : _a.blobStore = new import_teleport_extension_object_sync2.BlobStore(this.storage.createDirectory("blobs"));
|
|
5023
|
+
return this._props.blobStore ??= new import_teleport_extension_object_sync2.BlobStore(this.storage.createDirectory("blobs"));
|
|
4364
5024
|
}
|
|
4365
5025
|
get snapshotStore() {
|
|
4366
|
-
|
|
4367
|
-
return (_b = (_a = this._props).snapshotStore) != null ? _b : _a.snapshotStore = new import_echo_pipeline5.SnapshotStore(this.storage.createDirectory("snapshots"));
|
|
5026
|
+
return this._props.snapshotStore ??= new import_echo_pipeline5.SnapshotStore(this.storage.createDirectory("snapshots"));
|
|
4368
5027
|
}
|
|
4369
5028
|
get networkManager() {
|
|
4370
|
-
|
|
4371
|
-
return (_b = (_a = this._props).networkManager) != null ? _b : _a.networkManager = new import_network_manager3.NetworkManager({
|
|
5029
|
+
return this._props.networkManager ??= new import_network_manager3.NetworkManager({
|
|
4372
5030
|
signalManager: new import_messaging2.MemorySignalManager(this.signalContext),
|
|
4373
5031
|
transportFactory: import_network_manager3.MemoryTransportFactory
|
|
4374
5032
|
});
|
|
4375
5033
|
}
|
|
4376
5034
|
get spaceManager() {
|
|
4377
|
-
|
|
4378
|
-
return (_b = (_a = this._props).spaceManager) != null ? _b : _a.spaceManager = new import_echo_pipeline5.SpaceManager({
|
|
5035
|
+
return this._props.spaceManager ??= new import_echo_pipeline5.SpaceManager({
|
|
4379
5036
|
feedStore: this.feedStore,
|
|
4380
5037
|
networkManager: this.networkManager,
|
|
4381
5038
|
metadataStore: this.metadataStore,
|
|
@@ -4385,16 +5042,13 @@ var TestPeer = class {
|
|
|
4385
5042
|
});
|
|
4386
5043
|
}
|
|
4387
5044
|
get identity() {
|
|
4388
|
-
|
|
4389
|
-
return (_a = this._props.signingContext) != null ? _a : (0, import_debug8.failUndefined)();
|
|
5045
|
+
return this._props.signingContext ?? (0, import_debug8.failUndefined)();
|
|
4390
5046
|
}
|
|
4391
5047
|
get dataSpaceManager() {
|
|
4392
|
-
|
|
4393
|
-
return (_b = (_a = this._props).dataSpaceManager) != null ? _b : _a.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, new import_echo_pipeline5.DataServiceSubscriptions(), this.keyring, this.identity, this.feedStore);
|
|
5048
|
+
return this._props.dataSpaceManager ??= new DataSpaceManager(this.spaceManager, this.metadataStore, new import_echo_pipeline5.DataServiceSubscriptions(), this.keyring, this.identity, this.feedStore);
|
|
4394
5049
|
}
|
|
4395
5050
|
async createIdentity() {
|
|
4396
|
-
|
|
4397
|
-
(_b = (_a = this._props).signingContext) != null ? _b : _a.signingContext = await createSigningContext(this.keyring);
|
|
5051
|
+
this._props.signingContext ??= await createSigningContext(this.keyring);
|
|
4398
5052
|
}
|
|
4399
5053
|
async destroy() {
|
|
4400
5054
|
await this.storage.reset();
|
|
@@ -4406,8 +5060,8 @@ var createSigningContext = async (keyring) => {
|
|
|
4406
5060
|
return {
|
|
4407
5061
|
identityKey,
|
|
4408
5062
|
deviceKey,
|
|
4409
|
-
credentialSigner: (0,
|
|
4410
|
-
credential: await new
|
|
5063
|
+
credentialSigner: (0, import_credentials16.createCredentialSignerWithChain)(keyring, {
|
|
5064
|
+
credential: await new import_credentials16.CredentialGenerator(keyring, identityKey, deviceKey).createDeviceAuthorization(deviceKey)
|
|
4411
5065
|
}, deviceKey),
|
|
4412
5066
|
recordCredential: async () => {
|
|
4413
5067
|
}
|