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