@dxos/halo-adapter-client 0.0.0
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/LICENSE +105 -0
- package/README.md +21 -0
- package/dist/lib/neutral/index.mjs +479 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/identity.d.ts +13 -0
- package/dist/types/src/identity.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +13 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/space.d.ts +13 -0
- package/dist/types/src/space.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +41 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/moon.yml +11 -0
- package/package.json +36 -0
- package/src/identity.ts +143 -0
- package/src/index.ts +23 -0
- package/src/space.ts +203 -0
- package/src/util.ts +183 -0
- package/tsconfig.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @dxos/halo-adapter-client
|
|
2
|
+
|
|
3
|
+
Implements the `@dxos/halo` services (`Identity`, `Space`, `Invitation`) as Effect `Layer`s
|
|
4
|
+
backed by a `@dxos/client` instance. This is the composition-root adapter that lets application
|
|
5
|
+
code depend on the `@dxos/halo` service interfaces instead of `@dxos/client` directly.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { layerClient } from '@dxos/halo-adapter-client';
|
|
9
|
+
import { Identity } from '@dxos/halo';
|
|
10
|
+
|
|
11
|
+
const program = Identity.current;
|
|
12
|
+
Effect.runPromise(Effect.provide(program, layerClient(client)));
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## DXOS Resources
|
|
16
|
+
|
|
17
|
+
- [Website](https://dxos.org)
|
|
18
|
+
- [Developer Documentation](https://docs.dxos.org)
|
|
19
|
+
- Talk to us on [Discord](https://dxos.org/discord)
|
|
20
|
+
|
|
21
|
+
License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2026 © DXOS
|
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import * as Layer3 from "effect/Layer";
|
|
5
|
+
|
|
6
|
+
// src/identity.ts
|
|
7
|
+
import * as Effect2 from "effect/Effect";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
import * as Stream2 from "effect/Stream";
|
|
11
|
+
import { InvitationEncoder as InvitationEncoder2 } from "@dxos/client/invitations";
|
|
12
|
+
import { Identity as HaloIdentity, IdentityError } from "@dxos/halo";
|
|
13
|
+
import { IdentityDid } from "@dxos/keys";
|
|
14
|
+
import { DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
|
|
15
|
+
|
|
16
|
+
// src/util.ts
|
|
17
|
+
import * as Effect from "effect/Effect";
|
|
18
|
+
import * as Stream from "effect/Stream";
|
|
19
|
+
import { AuthenticatingInvitationObservable, Invitation as ClientInvitation, InvitationEncoder } from "@dxos/client/invitations";
|
|
20
|
+
import { InvitationError } from "@dxos/halo";
|
|
21
|
+
import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
|
|
22
|
+
import { SpaceMember as HaloSpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
23
|
+
var streamFromObservable = (observable) => Stream.async((emit) => {
|
|
24
|
+
const subscription = observable.subscribe((value) => void emit.single(value), (err) => void emit.fail(err));
|
|
25
|
+
return Effect.sync(() => subscription.unsubscribe());
|
|
26
|
+
}).pipe(Stream.orDie);
|
|
27
|
+
var TERMINAL_STATES = /* @__PURE__ */ new Set([
|
|
28
|
+
ClientInvitation.State.SUCCESS,
|
|
29
|
+
ClientInvitation.State.CANCELLED,
|
|
30
|
+
ClientInvitation.State.TIMEOUT,
|
|
31
|
+
ClientInvitation.State.ERROR,
|
|
32
|
+
ClientInvitation.State.EXPIRED
|
|
33
|
+
]);
|
|
34
|
+
var toEvent = (invitation) => {
|
|
35
|
+
switch (invitation.state) {
|
|
36
|
+
case ClientInvitation.State.CONNECTING:
|
|
37
|
+
return {
|
|
38
|
+
_tag: "connecting"
|
|
39
|
+
};
|
|
40
|
+
case ClientInvitation.State.CONNECTED:
|
|
41
|
+
return {
|
|
42
|
+
_tag: "connected"
|
|
43
|
+
};
|
|
44
|
+
case ClientInvitation.State.READY_FOR_AUTHENTICATION:
|
|
45
|
+
return {
|
|
46
|
+
_tag: "readyForAuthentication",
|
|
47
|
+
authCode: invitation.authCode
|
|
48
|
+
};
|
|
49
|
+
case ClientInvitation.State.AUTHENTICATING:
|
|
50
|
+
return {
|
|
51
|
+
_tag: "authenticating"
|
|
52
|
+
};
|
|
53
|
+
case ClientInvitation.State.SUCCESS:
|
|
54
|
+
return {
|
|
55
|
+
_tag: "success",
|
|
56
|
+
result: {}
|
|
57
|
+
};
|
|
58
|
+
case ClientInvitation.State.CANCELLED:
|
|
59
|
+
return {
|
|
60
|
+
_tag: "cancelled"
|
|
61
|
+
};
|
|
62
|
+
case ClientInvitation.State.TIMEOUT:
|
|
63
|
+
case ClientInvitation.State.ERROR:
|
|
64
|
+
case ClientInvitation.State.EXPIRED:
|
|
65
|
+
return {
|
|
66
|
+
_tag: "error",
|
|
67
|
+
message: `Invitation ${ClientInvitation.State[invitation.state]}`
|
|
68
|
+
};
|
|
69
|
+
default:
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var invitationEvents = (observable) => Stream.async((emit) => {
|
|
74
|
+
const subscription = observable.subscribe((invitation) => {
|
|
75
|
+
const event = toEvent(invitation);
|
|
76
|
+
if (event) {
|
|
77
|
+
void emit.single(event);
|
|
78
|
+
if (TERMINAL_STATES.has(invitation.state)) {
|
|
79
|
+
void emit.end();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, (err) => {
|
|
83
|
+
void emit.single({
|
|
84
|
+
_tag: "error",
|
|
85
|
+
message: err.message
|
|
86
|
+
});
|
|
87
|
+
void emit.end();
|
|
88
|
+
});
|
|
89
|
+
return Effect.sync(() => subscription.unsubscribe());
|
|
90
|
+
});
|
|
91
|
+
var makeFlow = (observable, kind) => ({
|
|
92
|
+
id: observable.get().invitationId,
|
|
93
|
+
kind,
|
|
94
|
+
events: invitationEvents(observable),
|
|
95
|
+
authenticate: (code) => observable instanceof AuthenticatingInvitationObservable ? Effect.tryPromise({
|
|
96
|
+
try: () => observable.authenticate(code),
|
|
97
|
+
catch: (error) => new InvitationError({
|
|
98
|
+
context: {
|
|
99
|
+
error
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}) : Effect.fail(new InvitationError({
|
|
103
|
+
context: {
|
|
104
|
+
reason: "flow is not awaiting authentication"
|
|
105
|
+
}
|
|
106
|
+
})),
|
|
107
|
+
cancel: () => Effect.promise(() => observable.cancel()),
|
|
108
|
+
code: Effect.sync(() => InvitationEncoder.encode(observable.get()))
|
|
109
|
+
});
|
|
110
|
+
var toShareOptions = (options) => ({
|
|
111
|
+
authMethod: toAuthMethod(options?.authMethod),
|
|
112
|
+
type: toType(options?.type),
|
|
113
|
+
...options?.multiUse !== void 0 ? {
|
|
114
|
+
multiUse: options.multiUse
|
|
115
|
+
} : {},
|
|
116
|
+
...options?.target !== void 0 ? {
|
|
117
|
+
target: options.target
|
|
118
|
+
} : {}
|
|
119
|
+
});
|
|
120
|
+
var toAuthMethod = (method) => {
|
|
121
|
+
switch (method) {
|
|
122
|
+
case "shared-secret":
|
|
123
|
+
return ClientInvitation.AuthMethod.SHARED_SECRET;
|
|
124
|
+
case "known-public-key":
|
|
125
|
+
return ClientInvitation.AuthMethod.KNOWN_PUBLIC_KEY;
|
|
126
|
+
case "none":
|
|
127
|
+
default:
|
|
128
|
+
return ClientInvitation.AuthMethod.NONE;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var toType = (type) => {
|
|
132
|
+
switch (type) {
|
|
133
|
+
case "delegated":
|
|
134
|
+
return ClientInvitation.Type.DELEGATED;
|
|
135
|
+
case "multiuse":
|
|
136
|
+
return ClientInvitation.Type.MULTIUSE;
|
|
137
|
+
case "interactive":
|
|
138
|
+
default:
|
|
139
|
+
return ClientInvitation.Type.INTERACTIVE;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var toAccess = (role) => {
|
|
143
|
+
switch (role) {
|
|
144
|
+
case HaloSpaceMember.Role.OWNER:
|
|
145
|
+
case HaloSpaceMember.Role.ADMIN:
|
|
146
|
+
return "admin";
|
|
147
|
+
case HaloSpaceMember.Role.EDITOR:
|
|
148
|
+
return "edit";
|
|
149
|
+
case HaloSpaceMember.Role.READER:
|
|
150
|
+
return "read";
|
|
151
|
+
default:
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var fromAccess = (access) => {
|
|
156
|
+
switch (access) {
|
|
157
|
+
case "admin":
|
|
158
|
+
return HaloSpaceMember.Role.ADMIN;
|
|
159
|
+
case "edit":
|
|
160
|
+
return HaloSpaceMember.Role.EDITOR;
|
|
161
|
+
case "read":
|
|
162
|
+
return HaloSpaceMember.Role.READER;
|
|
163
|
+
default:
|
|
164
|
+
return void 0;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var isOnline = (member) => member.presence === SpaceMember.PresenceState.ONLINE;
|
|
168
|
+
|
|
169
|
+
// src/identity.ts
|
|
170
|
+
var toInfo = (identity) => ({
|
|
171
|
+
did: IdentityDid.make(identity.did),
|
|
172
|
+
identityKey: identity.identityKey?.toHex(),
|
|
173
|
+
displayName: identity.profile?.displayName,
|
|
174
|
+
data: identity.profile?.data
|
|
175
|
+
});
|
|
176
|
+
var toDeviceInfo = (device) => ({
|
|
177
|
+
key: device.deviceKey.toHex(),
|
|
178
|
+
label: device.profile?.label,
|
|
179
|
+
current: device.kind === DeviceKind.CURRENT
|
|
180
|
+
});
|
|
181
|
+
var toCredential = (credential) => ({
|
|
182
|
+
id: credential.id?.toHex(),
|
|
183
|
+
type: credential.subject.assertion["@type"],
|
|
184
|
+
issuanceDate: credential.issuanceDate
|
|
185
|
+
});
|
|
186
|
+
var makeIdentityService = (client) => ({
|
|
187
|
+
identity: streamFromObservable(client.halo.identity).pipe(Stream2.map((identity) => identity ? Option.some(toInfo(identity)) : Option.none())),
|
|
188
|
+
getSnapshot: () => {
|
|
189
|
+
const identity = client.halo.identity.get();
|
|
190
|
+
return identity ? Option.some(toInfo(identity)) : Option.none();
|
|
191
|
+
},
|
|
192
|
+
subscribe: (callback) => {
|
|
193
|
+
const subscription = client.halo.identity.subscribe((identity) => callback(identity ? Option.some(toInfo(identity)) : Option.none()));
|
|
194
|
+
return () => subscription.unsubscribe();
|
|
195
|
+
},
|
|
196
|
+
create: (options) => Effect2.tryPromise({
|
|
197
|
+
try: async () => toInfo(await client.halo.createIdentity(options?.displayName !== void 0 ? {
|
|
198
|
+
displayName: options.displayName
|
|
199
|
+
} : {}, options?.deviceLabel !== void 0 ? {
|
|
200
|
+
label: options.deviceLabel
|
|
201
|
+
} : void 0)),
|
|
202
|
+
catch: (error) => new IdentityError({
|
|
203
|
+
context: {
|
|
204
|
+
error
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
}),
|
|
208
|
+
recover: (args) => Effect2.tryPromise({
|
|
209
|
+
try: async () => toInfo(await client.halo.recoverIdentity(args)),
|
|
210
|
+
catch: (error) => new IdentityError({
|
|
211
|
+
context: {
|
|
212
|
+
error
|
|
213
|
+
}
|
|
214
|
+
})
|
|
215
|
+
}),
|
|
216
|
+
updateProfile: (profile) => Effect2.tryPromise({
|
|
217
|
+
try: async () => toInfo(await client.halo.updateProfile(profile)),
|
|
218
|
+
catch: (error) => new IdentityError({
|
|
219
|
+
context: {
|
|
220
|
+
error
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
}),
|
|
224
|
+
devices: streamFromObservable(client.halo.devices).pipe(Stream2.map((devices) => devices.map(toDeviceInfo))),
|
|
225
|
+
getDevicesSnapshot: () => client.halo.devices.get().map(toDeviceInfo),
|
|
226
|
+
credentials: streamFromObservable(client.halo.credentials).pipe(Stream2.map((credentials) => credentials.map(toCredential))),
|
|
227
|
+
grantServiceAccess: (options) => Effect2.tryPromise({
|
|
228
|
+
try: async () => {
|
|
229
|
+
const identityKey = client.halo.identity.get()?.identityKey;
|
|
230
|
+
if (!identityKey) {
|
|
231
|
+
throw new Error("No identity.");
|
|
232
|
+
}
|
|
233
|
+
await client.halo.writeCredentials([
|
|
234
|
+
{
|
|
235
|
+
issuer: identityKey,
|
|
236
|
+
issuanceDate: /* @__PURE__ */ new Date(),
|
|
237
|
+
subject: {
|
|
238
|
+
id: identityKey,
|
|
239
|
+
assertion: {
|
|
240
|
+
"@type": "dxos.halo.credentials.ServiceAccess",
|
|
241
|
+
"serverName": options.serverName,
|
|
242
|
+
"serverKey": identityKey,
|
|
243
|
+
identityKey,
|
|
244
|
+
"capabilities": [
|
|
245
|
+
...options.capabilities
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
]);
|
|
251
|
+
},
|
|
252
|
+
catch: (error) => new IdentityError({
|
|
253
|
+
context: {
|
|
254
|
+
error
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
}),
|
|
258
|
+
share: (options) => Effect2.try({
|
|
259
|
+
try: () => makeFlow(client.halo.share(toShareOptions(options)), "device"),
|
|
260
|
+
catch: (error) => new IdentityError({
|
|
261
|
+
context: {
|
|
262
|
+
error
|
|
263
|
+
}
|
|
264
|
+
})
|
|
265
|
+
}),
|
|
266
|
+
join: (code) => Effect2.try({
|
|
267
|
+
try: () => makeFlow(client.halo.join(InvitationEncoder2.decode(code)), "device"),
|
|
268
|
+
catch: (error) => new IdentityError({
|
|
269
|
+
context: {
|
|
270
|
+
error
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
}),
|
|
274
|
+
invitations: streamFromObservable(client.halo.invitations).pipe(Stream2.map((invitations) => invitations.map((invitation) => makeFlow(invitation, "device"))))
|
|
275
|
+
});
|
|
276
|
+
var layerIdentity = (client) => Layer.succeed(HaloIdentity.Service, makeIdentityService(client));
|
|
277
|
+
|
|
278
|
+
// src/space.ts
|
|
279
|
+
import * as Effect3 from "effect/Effect";
|
|
280
|
+
import * as Layer2 from "effect/Layer";
|
|
281
|
+
import * as Option2 from "effect/Option";
|
|
282
|
+
import * as Stream3 from "effect/Stream";
|
|
283
|
+
import { SpaceState } from "@dxos/client/echo";
|
|
284
|
+
import { Space as HaloSpace, SpaceError } from "@dxos/halo";
|
|
285
|
+
import { IdentityDid as IdentityDid2 } from "@dxos/keys";
|
|
286
|
+
import { SpaceArchive } from "@dxos/protocols/proto/dxos/client/services";
|
|
287
|
+
import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
|
|
288
|
+
import { SpaceMember as HaloSpaceMember2, MembershipPolicy } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
289
|
+
var toState = (state) => {
|
|
290
|
+
switch (state) {
|
|
291
|
+
case SpaceState.SPACE_READY:
|
|
292
|
+
return "ready";
|
|
293
|
+
case SpaceState.SPACE_CLOSED:
|
|
294
|
+
return "closed";
|
|
295
|
+
default:
|
|
296
|
+
return "inactive";
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
var toSpaceInfo = (space) => ({
|
|
300
|
+
id: space.id,
|
|
301
|
+
name: space.state.get() === SpaceState.SPACE_READY ? space.properties.name : void 0,
|
|
302
|
+
state: toState(space.state.get())
|
|
303
|
+
});
|
|
304
|
+
var toMembers = (members) => members.flatMap((member) => {
|
|
305
|
+
const role = toAccess(member.role);
|
|
306
|
+
if (role === void 0) {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
return [
|
|
310
|
+
{
|
|
311
|
+
did: member.identity?.did !== void 0 ? IdentityDid2.make(member.identity.did) : void 0,
|
|
312
|
+
identityKey: member.identity?.identityKey?.toHex(),
|
|
313
|
+
displayName: member.identity?.profile?.displayName,
|
|
314
|
+
data: member.identity?.profile?.data,
|
|
315
|
+
role,
|
|
316
|
+
online: isOnline(member)
|
|
317
|
+
}
|
|
318
|
+
];
|
|
319
|
+
});
|
|
320
|
+
var toMembershipPolicy = (policy) => policy === "locked" ? MembershipPolicy.LOCKED : MembershipPolicy.INVITE;
|
|
321
|
+
var toEdgeReplicationSetting = (setting) => setting === "enabled" ? EdgeReplicationSetting.ENABLED : EdgeReplicationSetting.DISABLED;
|
|
322
|
+
var resolveSpace = (client, id) => {
|
|
323
|
+
const space = client.spaces.get(id);
|
|
324
|
+
if (!space) {
|
|
325
|
+
throw new Error(`Space not found: ${id}`);
|
|
326
|
+
}
|
|
327
|
+
return space;
|
|
328
|
+
};
|
|
329
|
+
var setMemberRole = async (client, id, subject, newRole) => {
|
|
330
|
+
const space = resolveSpace(client, id);
|
|
331
|
+
const member = space.members.get().find((entry) => entry.identity?.did === subject);
|
|
332
|
+
if (!member) {
|
|
333
|
+
throw new Error(`Member not found: ${subject}`);
|
|
334
|
+
}
|
|
335
|
+
await space.updateMemberRole({
|
|
336
|
+
memberKey: member.identity.identityKey,
|
|
337
|
+
newRole
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
var makeSpaceService = (client) => ({
|
|
341
|
+
spaces: streamFromObservable(client.spaces).pipe(Stream3.map((spaces) => (spaces ?? []).map(toSpaceInfo))),
|
|
342
|
+
get: (id) => Effect3.sync(() => {
|
|
343
|
+
const space = client.spaces.get(id);
|
|
344
|
+
return space ? Option2.some(toSpaceInfo(space)) : Option2.none();
|
|
345
|
+
}),
|
|
346
|
+
create: (options) => Effect3.tryPromise({
|
|
347
|
+
try: async () => {
|
|
348
|
+
const createOptions = {};
|
|
349
|
+
if (options?.tags !== void 0) {
|
|
350
|
+
createOptions.tags = [
|
|
351
|
+
...options.tags
|
|
352
|
+
];
|
|
353
|
+
}
|
|
354
|
+
if (options?.membershipPolicy !== void 0) {
|
|
355
|
+
createOptions.membershipPolicy = toMembershipPolicy(options.membershipPolicy);
|
|
356
|
+
}
|
|
357
|
+
return toSpaceInfo(await client.spaces.create(options?.name !== void 0 ? {
|
|
358
|
+
name: options.name
|
|
359
|
+
} : {}, createOptions));
|
|
360
|
+
},
|
|
361
|
+
catch: (error) => new SpaceError({
|
|
362
|
+
context: {
|
|
363
|
+
error
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
}),
|
|
367
|
+
waitReady: (id) => Effect3.tryPromise({
|
|
368
|
+
try: async () => {
|
|
369
|
+
await resolveSpace(client, id).waitUntilReady();
|
|
370
|
+
},
|
|
371
|
+
catch: (error) => new SpaceError({
|
|
372
|
+
context: {
|
|
373
|
+
error
|
|
374
|
+
}
|
|
375
|
+
})
|
|
376
|
+
}),
|
|
377
|
+
setEdgeReplication: (id, setting) => Effect3.tryPromise({
|
|
378
|
+
try: async () => {
|
|
379
|
+
await resolveSpace(client, id).internal.setEdgeReplicationPreference(toEdgeReplicationSetting(setting));
|
|
380
|
+
},
|
|
381
|
+
catch: (error) => new SpaceError({
|
|
382
|
+
context: {
|
|
383
|
+
error
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
}),
|
|
387
|
+
members: (id) => {
|
|
388
|
+
const space = client.spaces.get(id);
|
|
389
|
+
return space ? streamFromObservable(space.members).pipe(Stream3.map(toMembers)) : Stream3.empty;
|
|
390
|
+
},
|
|
391
|
+
updateMemberRole: (id, subject, role) => Effect3.tryPromise({
|
|
392
|
+
try: async () => {
|
|
393
|
+
const newRole = fromAccess(role);
|
|
394
|
+
if (newRole === void 0) {
|
|
395
|
+
throw new Error(`No legacy role for access level: ${role}`);
|
|
396
|
+
}
|
|
397
|
+
await setMemberRole(client, id, subject, newRole);
|
|
398
|
+
},
|
|
399
|
+
catch: (error) => new SpaceError({
|
|
400
|
+
context: {
|
|
401
|
+
error
|
|
402
|
+
}
|
|
403
|
+
})
|
|
404
|
+
}),
|
|
405
|
+
removeMember: (id, subject) => Effect3.tryPromise({
|
|
406
|
+
try: () => setMemberRole(client, id, subject, HaloSpaceMember2.Role.REMOVED),
|
|
407
|
+
catch: (error) => new SpaceError({
|
|
408
|
+
context: {
|
|
409
|
+
error
|
|
410
|
+
}
|
|
411
|
+
})
|
|
412
|
+
}),
|
|
413
|
+
share: (id, options) => Effect3.try({
|
|
414
|
+
try: () => makeFlow(resolveSpace(client, id).share(toShareOptions(options)), "space"),
|
|
415
|
+
catch: (error) => new SpaceError({
|
|
416
|
+
context: {
|
|
417
|
+
error
|
|
418
|
+
}
|
|
419
|
+
})
|
|
420
|
+
}),
|
|
421
|
+
join: (code) => Effect3.try({
|
|
422
|
+
try: () => makeFlow(client.spaces.join(code), "space"),
|
|
423
|
+
catch: (error) => new SpaceError({
|
|
424
|
+
context: {
|
|
425
|
+
error
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
}),
|
|
429
|
+
invitations: (id) => {
|
|
430
|
+
const space = client.spaces.get(id);
|
|
431
|
+
return space ? streamFromObservable(space.invitations).pipe(Stream3.map((invitations) => invitations.map((invitation) => makeFlow(invitation, "space")))) : Stream3.empty;
|
|
432
|
+
},
|
|
433
|
+
export: (id) => Effect3.tryPromise({
|
|
434
|
+
try: async () => {
|
|
435
|
+
const archive = await resolveSpace(client, id).internal.export();
|
|
436
|
+
return {
|
|
437
|
+
filename: archive.filename,
|
|
438
|
+
contents: archive.contents
|
|
439
|
+
};
|
|
440
|
+
},
|
|
441
|
+
catch: (error) => new SpaceError({
|
|
442
|
+
context: {
|
|
443
|
+
error
|
|
444
|
+
}
|
|
445
|
+
})
|
|
446
|
+
}),
|
|
447
|
+
import: (archive, options) => Effect3.tryPromise({
|
|
448
|
+
try: async () => {
|
|
449
|
+
const format = archive.filename.endsWith(".json") ? SpaceArchive.Format.JSON : SpaceArchive.Format.BINARY;
|
|
450
|
+
const space = await client.spaces.import({
|
|
451
|
+
filename: archive.filename,
|
|
452
|
+
contents: archive.contents,
|
|
453
|
+
format
|
|
454
|
+
}, options?.tags !== void 0 ? {
|
|
455
|
+
tags: [
|
|
456
|
+
...options.tags
|
|
457
|
+
]
|
|
458
|
+
} : void 0);
|
|
459
|
+
return toSpaceInfo(space);
|
|
460
|
+
},
|
|
461
|
+
catch: (error) => new SpaceError({
|
|
462
|
+
context: {
|
|
463
|
+
error
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
});
|
|
468
|
+
var layerSpace = (client) => Layer2.succeed(HaloSpace.Service, makeSpaceService(client));
|
|
469
|
+
|
|
470
|
+
// src/index.ts
|
|
471
|
+
var layerClient = (client) => Layer3.mergeAll(layerIdentity(client), layerSpace(client));
|
|
472
|
+
export {
|
|
473
|
+
layerClient,
|
|
474
|
+
layerIdentity,
|
|
475
|
+
layerSpace,
|
|
476
|
+
makeIdentityService,
|
|
477
|
+
makeSpaceService
|
|
478
|
+
};
|
|
479
|
+
//# sourceMappingURL=index.mjs.map
|