@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/moon.yml ADDED
@@ -0,0 +1,11 @@
1
+ layer: library
2
+ language: typescript
3
+ tags:
4
+ - ts-build
5
+ - pack
6
+ tasks:
7
+ compile:
8
+ args:
9
+ - '--entryPoint=src/index.ts'
10
+ - '--injectGlobals'
11
+ - '--platform=neutral'
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@dxos/halo-adapter-client",
3
+ "version": "0.0.0",
4
+ "description": "Implements the @dxos/halo services over a @dxos/client instance.",
5
+ "homepage": "https://github.com/dxos/dxos/tree/main/packages/core/halo/halo-adapter-client#readme",
6
+ "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
11
+ "license": "FSL-1.1-Apache-2.0",
12
+ "author": "info@dxos.org",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "source": "./src/index.ts",
18
+ "types": "./dist/types/src/index.d.ts",
19
+ "default": "./dist/lib/neutral/index.mjs"
20
+ }
21
+ },
22
+ "types": "dist/types/src/index.d.ts",
23
+ "dependencies": {
24
+ "effect": "3.21.4",
25
+ "@dxos/async": "0.10.0",
26
+ "@dxos/halo": "0.0.0",
27
+ "@dxos/invariant": "0.10.0",
28
+ "@dxos/client": "0.10.0",
29
+ "@dxos/client-protocol": "0.10.0",
30
+ "@dxos/protocols": "0.10.0",
31
+ "@dxos/keys": "0.10.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ }
36
+ }
@@ -0,0 +1,143 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
8
+ import * as Option from 'effect/Option';
9
+ import * as Stream from 'effect/Stream';
10
+
11
+ import { type Client } from '@dxos/client';
12
+ import { InvitationEncoder } from '@dxos/client/invitations';
13
+ import { Identity as HaloIdentity, IdentityError } from '@dxos/halo';
14
+ import { IdentityDid } from '@dxos/keys';
15
+ import {
16
+ type Device as ClientDevice,
17
+ type Identity as ClientIdentity,
18
+ DeviceKind,
19
+ } from '@dxos/protocols/proto/dxos/client/services';
20
+ import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
21
+
22
+ import { makeFlow, streamFromObservable, toShareOptions } from './util';
23
+
24
+ const toInfo = (identity: ClientIdentity): HaloIdentity.Info => ({
25
+ did: IdentityDid.make(identity.did),
26
+ identityKey: identity.identityKey?.toHex(),
27
+ displayName: identity.profile?.displayName,
28
+ data: identity.profile?.data,
29
+ });
30
+
31
+ const toDeviceInfo = (device: ClientDevice): HaloIdentity.DeviceInfo => ({
32
+ key: device.deviceKey.toHex(),
33
+ label: device.profile?.label,
34
+ current: device.kind === DeviceKind.CURRENT,
35
+ });
36
+
37
+ const toCredential = (credential: Credential): HaloIdentity.Credential => ({
38
+ id: credential.id?.toHex(),
39
+ type: credential.subject.assertion['@type'],
40
+ issuanceDate: credential.issuanceDate,
41
+ });
42
+
43
+ /**
44
+ * Builds the {@link HaloIdentity.Service} implementation over a client's `halo` proxy.
45
+ */
46
+ export const makeIdentityService = (client: Client): Context.Tag.Service<HaloIdentity.Service> => ({
47
+ identity: streamFromObservable(client.halo.identity).pipe(
48
+ Stream.map((identity) => (identity ? Option.some(toInfo(identity)) : Option.none())),
49
+ ),
50
+
51
+ getSnapshot: () => {
52
+ const identity = client.halo.identity.get();
53
+ return identity ? Option.some(toInfo(identity)) : Option.none();
54
+ },
55
+
56
+ subscribe: (callback) => {
57
+ const subscription = client.halo.identity.subscribe((identity) =>
58
+ callback(identity ? Option.some(toInfo(identity)) : Option.none()),
59
+ );
60
+ return () => subscription.unsubscribe();
61
+ },
62
+
63
+ create: (options) =>
64
+ Effect.tryPromise({
65
+ try: async () =>
66
+ toInfo(
67
+ await client.halo.createIdentity(
68
+ options?.displayName !== undefined ? { displayName: options.displayName } : {},
69
+ options?.deviceLabel !== undefined ? { label: options.deviceLabel } : undefined,
70
+ ),
71
+ ),
72
+ catch: (error) => new IdentityError({ context: { error } }),
73
+ }),
74
+
75
+ recover: (args) =>
76
+ Effect.tryPromise({
77
+ try: async () => toInfo(await client.halo.recoverIdentity(args)),
78
+ catch: (error) => new IdentityError({ context: { error } }),
79
+ }),
80
+
81
+ updateProfile: (profile) =>
82
+ Effect.tryPromise({
83
+ try: async () => toInfo(await client.halo.updateProfile(profile)),
84
+ catch: (error) => new IdentityError({ context: { error } }),
85
+ }),
86
+
87
+ devices: streamFromObservable(client.halo.devices).pipe(Stream.map((devices) => devices.map(toDeviceInfo))),
88
+
89
+ getDevicesSnapshot: () => client.halo.devices.get().map(toDeviceInfo),
90
+
91
+ credentials: streamFromObservable(client.halo.credentials).pipe(
92
+ Stream.map((credentials) => credentials.map(toCredential)),
93
+ ),
94
+
95
+ grantServiceAccess: (options) =>
96
+ Effect.tryPromise({
97
+ try: async () => {
98
+ const identityKey = client.halo.identity.get()?.identityKey;
99
+ if (!identityKey) {
100
+ throw new Error('No identity.');
101
+ }
102
+ await client.halo.writeCredentials([
103
+ {
104
+ issuer: identityKey,
105
+ issuanceDate: new Date(),
106
+ subject: {
107
+ id: identityKey,
108
+ assertion: {
109
+ '@type': 'dxos.halo.credentials.ServiceAccess',
110
+ 'serverName': options.serverName,
111
+ 'serverKey': identityKey,
112
+ identityKey,
113
+ 'capabilities': [...options.capabilities],
114
+ },
115
+ },
116
+ },
117
+ ]);
118
+ },
119
+ catch: (error) => new IdentityError({ context: { error } }),
120
+ }),
121
+
122
+ share: (options) =>
123
+ Effect.try({
124
+ try: () => makeFlow(client.halo.share(toShareOptions(options)), 'device'),
125
+ catch: (error) => new IdentityError({ context: { error } }),
126
+ }),
127
+
128
+ join: (code) =>
129
+ Effect.try({
130
+ try: () => makeFlow(client.halo.join(InvitationEncoder.decode(code)), 'device'),
131
+ catch: (error) => new IdentityError({ context: { error } }),
132
+ }),
133
+
134
+ invitations: streamFromObservable(client.halo.invitations).pipe(
135
+ Stream.map((invitations) => invitations.map((invitation) => makeFlow(invitation, 'device'))),
136
+ ),
137
+ });
138
+
139
+ /**
140
+ * Layer providing {@link HaloIdentity.Service} backed by the given client.
141
+ */
142
+ export const layerIdentity = (client: Client): Layer.Layer<HaloIdentity.Service> =>
143
+ Layer.succeed(HaloIdentity.Service, makeIdentityService(client));
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Layer from 'effect/Layer';
6
+
7
+ import { type Client } from '@dxos/client';
8
+ import { type Identity, type Space } from '@dxos/halo';
9
+
10
+ import { layerIdentity } from './identity';
11
+ import { layerSpace } from './space';
12
+
13
+ export { layerIdentity, makeIdentityService } from './identity';
14
+ export { layerSpace, makeSpaceService } from './space';
15
+
16
+ /**
17
+ * A single layer providing both HALO services ({@link Identity.Service}, {@link Space.Service})
18
+ * backed by one {@link Client}. This is the composition-root layer that replaces direct
19
+ * `@dxos/client` access for HALO concerns. Invitation querying lives on these two services;
20
+ * flow-level verbs need no service.
21
+ */
22
+ export const layerClient = (client: Client): Layer.Layer<Identity.Service | Space.Service> =>
23
+ Layer.mergeAll(layerIdentity(client), layerSpace(client));
package/src/space.ts ADDED
@@ -0,0 +1,203 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Context from 'effect/Context';
6
+ import * as Effect from 'effect/Effect';
7
+ import * as Layer from 'effect/Layer';
8
+ import * as Option from 'effect/Option';
9
+ import * as Stream from 'effect/Stream';
10
+
11
+ import { type Client } from '@dxos/client';
12
+ import { type Space as ClientSpace, SpaceState } from '@dxos/client/echo';
13
+ import { Space as HaloSpace, SpaceError } from '@dxos/halo';
14
+ import { IdentityDid, type SpaceId } from '@dxos/keys';
15
+ import { SpaceArchive, type SpaceMember } from '@dxos/protocols/proto/dxos/client/services';
16
+ import { EdgeReplicationSetting } from '@dxos/protocols/proto/dxos/echo/metadata';
17
+ import { SpaceMember as HaloSpaceMember, MembershipPolicy } from '@dxos/protocols/proto/dxos/halo/credentials';
18
+
19
+ import { fromAccess, isOnline, makeFlow, streamFromObservable, toAccess, toShareOptions } from './util';
20
+
21
+ const toState = (state: SpaceState): HaloSpace.State => {
22
+ switch (state) {
23
+ case SpaceState.SPACE_READY:
24
+ return 'ready';
25
+ case SpaceState.SPACE_CLOSED:
26
+ return 'closed';
27
+ default:
28
+ return 'inactive';
29
+ }
30
+ };
31
+
32
+ const toSpaceInfo = (space: ClientSpace): HaloSpace.Info => ({
33
+ id: space.id,
34
+ name: space.state.get() === SpaceState.SPACE_READY ? space.properties.name : undefined,
35
+ state: toState(space.state.get()),
36
+ });
37
+
38
+ const toMembers = (members: readonly SpaceMember[]): HaloSpace.Member[] =>
39
+ members.flatMap((member) => {
40
+ const role = toAccess(member.role);
41
+ if (role === undefined) {
42
+ // Skip removed members.
43
+ return [];
44
+ }
45
+ return [
46
+ {
47
+ did: member.identity?.did !== undefined ? IdentityDid.make(member.identity.did) : undefined,
48
+ identityKey: member.identity?.identityKey?.toHex(),
49
+ displayName: member.identity?.profile?.displayName,
50
+ data: member.identity?.profile?.data,
51
+ role,
52
+ online: isOnline(member),
53
+ },
54
+ ];
55
+ });
56
+
57
+ const toMembershipPolicy = (policy: HaloSpace.MembershipPolicy): MembershipPolicy =>
58
+ policy === 'locked' ? MembershipPolicy.LOCKED : MembershipPolicy.INVITE;
59
+
60
+ const toEdgeReplicationSetting = (setting: HaloSpace.EdgeReplication): EdgeReplicationSetting =>
61
+ setting === 'enabled' ? EdgeReplicationSetting.ENABLED : EdgeReplicationSetting.DISABLED;
62
+
63
+ const resolveSpace = (client: Client, id: SpaceId): ClientSpace => {
64
+ const space = client.spaces.get(id);
65
+ if (!space) {
66
+ throw new Error(`Space not found: ${id}`);
67
+ }
68
+ return space;
69
+ };
70
+
71
+ // The HALO API addresses members by DID; the legacy proxy needs the identity key, resolved here
72
+ // from the materialized membership.
73
+ const setMemberRole = async (
74
+ client: Client,
75
+ id: SpaceId,
76
+ subject: IdentityDid,
77
+ newRole: HaloSpaceMember.Role,
78
+ ): Promise<void> => {
79
+ const space = resolveSpace(client, id);
80
+ const member = space.members.get().find((entry) => entry.identity?.did === subject);
81
+ if (!member) {
82
+ throw new Error(`Member not found: ${subject}`);
83
+ }
84
+ await space.updateMemberRole({ memberKey: member.identity.identityKey, newRole });
85
+ };
86
+
87
+ /**
88
+ * Builds the {@link HaloSpace.Service} implementation over a client's `spaces` proxy.
89
+ */
90
+ export const makeSpaceService = (client: Client): Context.Tag.Service<HaloSpace.Service> => ({
91
+ spaces: streamFromObservable(client.spaces).pipe(Stream.map((spaces) => (spaces ?? []).map(toSpaceInfo))),
92
+
93
+ get: (id) =>
94
+ Effect.sync(() => {
95
+ const space = client.spaces.get(id);
96
+ return space ? Option.some(toSpaceInfo(space)) : Option.none();
97
+ }),
98
+
99
+ create: (options) =>
100
+ Effect.tryPromise({
101
+ try: async () => {
102
+ const createOptions: { tags?: string[]; membershipPolicy?: MembershipPolicy } = {};
103
+ if (options?.tags !== undefined) {
104
+ createOptions.tags = [...options.tags];
105
+ }
106
+ if (options?.membershipPolicy !== undefined) {
107
+ createOptions.membershipPolicy = toMembershipPolicy(options.membershipPolicy);
108
+ }
109
+ return toSpaceInfo(
110
+ await client.spaces.create(options?.name !== undefined ? { name: options.name } : {}, createOptions),
111
+ );
112
+ },
113
+ catch: (error) => new SpaceError({ context: { error } }),
114
+ }),
115
+
116
+ waitReady: (id) =>
117
+ Effect.tryPromise({
118
+ try: async () => {
119
+ await resolveSpace(client, id).waitUntilReady();
120
+ },
121
+ catch: (error) => new SpaceError({ context: { error } }),
122
+ }),
123
+
124
+ setEdgeReplication: (id, setting) =>
125
+ Effect.tryPromise({
126
+ try: async () => {
127
+ await resolveSpace(client, id).internal.setEdgeReplicationPreference(toEdgeReplicationSetting(setting));
128
+ },
129
+ catch: (error) => new SpaceError({ context: { error } }),
130
+ }),
131
+
132
+ members: (id) => {
133
+ const space = client.spaces.get(id);
134
+ return space ? streamFromObservable(space.members).pipe(Stream.map(toMembers)) : Stream.empty;
135
+ },
136
+
137
+ updateMemberRole: (id, subject, role) =>
138
+ Effect.tryPromise({
139
+ try: async () => {
140
+ const newRole = fromAccess(role);
141
+ if (newRole === undefined) {
142
+ throw new Error(`No legacy role for access level: ${role}`);
143
+ }
144
+ await setMemberRole(client, id, subject, newRole);
145
+ },
146
+ catch: (error) => new SpaceError({ context: { error } }),
147
+ }),
148
+
149
+ removeMember: (id, subject) =>
150
+ Effect.tryPromise({
151
+ try: () => setMemberRole(client, id, subject, HaloSpaceMember.Role.REMOVED),
152
+ catch: (error) => new SpaceError({ context: { error } }),
153
+ }),
154
+
155
+ share: (id, options) =>
156
+ Effect.try({
157
+ try: () => makeFlow(resolveSpace(client, id).share(toShareOptions(options)), 'space'),
158
+ catch: (error) => new SpaceError({ context: { error } }),
159
+ }),
160
+
161
+ join: (code) =>
162
+ Effect.try({
163
+ try: () => makeFlow(client.spaces.join(code), 'space'),
164
+ catch: (error) => new SpaceError({ context: { error } }),
165
+ }),
166
+
167
+ invitations: (id) => {
168
+ const space = client.spaces.get(id);
169
+ return space
170
+ ? streamFromObservable(space.invitations).pipe(
171
+ Stream.map((invitations) => invitations.map((invitation) => makeFlow(invitation, 'space'))),
172
+ )
173
+ : Stream.empty;
174
+ },
175
+
176
+ export: (id) =>
177
+ Effect.tryPromise({
178
+ try: async () => {
179
+ const archive = await resolveSpace(client, id).internal.export();
180
+ return { filename: archive.filename, contents: archive.contents };
181
+ },
182
+ catch: (error) => new SpaceError({ context: { error } }),
183
+ }),
184
+
185
+ import: (archive, options) =>
186
+ Effect.tryPromise({
187
+ try: async () => {
188
+ const format = archive.filename.endsWith('.json') ? SpaceArchive.Format.JSON : SpaceArchive.Format.BINARY;
189
+ const space = await client.spaces.import(
190
+ { filename: archive.filename, contents: archive.contents, format },
191
+ options?.tags !== undefined ? { tags: [...options.tags] } : undefined,
192
+ );
193
+ return toSpaceInfo(space);
194
+ },
195
+ catch: (error) => new SpaceError({ context: { error } }),
196
+ }),
197
+ });
198
+
199
+ /**
200
+ * Layer providing {@link HaloSpace.Service} backed by the given client.
201
+ */
202
+ export const layerSpace = (client: Client): Layer.Layer<HaloSpace.Service> =>
203
+ Layer.succeed(HaloSpace.Service, makeSpaceService(client));
package/src/util.ts ADDED
@@ -0,0 +1,183 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Effect from 'effect/Effect';
6
+ import * as Stream from 'effect/Stream';
7
+
8
+ import { type MulticastObservable } from '@dxos/async';
9
+ import {
10
+ AuthenticatingInvitationObservable,
11
+ type CancellableInvitationObservable,
12
+ Invitation as ClientInvitation,
13
+ InvitationEncoder,
14
+ } from '@dxos/client/invitations';
15
+ import { Invitation as HaloInvitation, Space as HaloSpace, InvitationError } from '@dxos/halo';
16
+ import { SpaceMember } from '@dxos/protocols/proto/dxos/client/services';
17
+ import { SpaceMember as HaloSpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
18
+
19
+ /**
20
+ * Bridges a {@link MulticastObservable} into an Effect {@link Stream}. The current value is
21
+ * emitted on subscription (matching the observable's semantics); the stream runs until the
22
+ * consumer stops or the observable errors.
23
+ */
24
+ export const streamFromObservable = <T>(observable: MulticastObservable<T>): Stream.Stream<T> =>
25
+ Stream.async<T, Error>((emit) => {
26
+ const subscription = observable.subscribe(
27
+ (value: T) => void emit.single(value),
28
+ (err: Error) => void emit.fail(err),
29
+ );
30
+ return Effect.sync(() => subscription.unsubscribe());
31
+ }).pipe(Stream.orDie);
32
+
33
+ const TERMINAL_STATES: ReadonlySet<ClientInvitation.State> = new Set([
34
+ ClientInvitation.State.SUCCESS,
35
+ ClientInvitation.State.CANCELLED,
36
+ ClientInvitation.State.TIMEOUT,
37
+ ClientInvitation.State.ERROR,
38
+ ClientInvitation.State.EXPIRED,
39
+ ]);
40
+
41
+ const toEvent = (invitation: ClientInvitation): HaloInvitation.Event | undefined => {
42
+ switch (invitation.state) {
43
+ case ClientInvitation.State.CONNECTING:
44
+ return { _tag: 'connecting' };
45
+ case ClientInvitation.State.CONNECTED:
46
+ return { _tag: 'connected' };
47
+ case ClientInvitation.State.READY_FOR_AUTHENTICATION:
48
+ return { _tag: 'readyForAuthentication', authCode: invitation.authCode };
49
+ case ClientInvitation.State.AUTHENTICATING:
50
+ return { _tag: 'authenticating' };
51
+ case ClientInvitation.State.SUCCESS:
52
+ return { _tag: 'success', result: {} };
53
+ case ClientInvitation.State.CANCELLED:
54
+ return { _tag: 'cancelled' };
55
+ case ClientInvitation.State.TIMEOUT:
56
+ case ClientInvitation.State.ERROR:
57
+ case ClientInvitation.State.EXPIRED:
58
+ return { _tag: 'error', message: `Invitation ${ClientInvitation.State[invitation.state]}` };
59
+ default:
60
+ // INIT and any unmodeled state — not surfaced.
61
+ return undefined;
62
+ }
63
+ };
64
+
65
+ /**
66
+ * Maps an invitation observable's state transitions to the {@link HaloInvitation.Event} stream,
67
+ * completing after a terminal event.
68
+ */
69
+ export const invitationEvents = (observable: CancellableInvitationObservable): Stream.Stream<HaloInvitation.Event> =>
70
+ Stream.async<HaloInvitation.Event>((emit) => {
71
+ const subscription = observable.subscribe(
72
+ (invitation: ClientInvitation) => {
73
+ const event = toEvent(invitation);
74
+ if (event) {
75
+ void emit.single(event);
76
+ if (TERMINAL_STATES.has(invitation.state)) {
77
+ void emit.end();
78
+ }
79
+ }
80
+ },
81
+ (err: Error) => {
82
+ void emit.single({ _tag: 'error', message: err.message });
83
+ void emit.end();
84
+ },
85
+ );
86
+ return Effect.sync(() => subscription.unsubscribe());
87
+ });
88
+
89
+ /**
90
+ * Wraps a client invitation observable as a {@link HaloInvitation.Flow}.
91
+ */
92
+ export const makeFlow = (
93
+ observable: CancellableInvitationObservable,
94
+ kind: HaloInvitation.Kind,
95
+ ): HaloInvitation.Flow => ({
96
+ id: observable.get().invitationId,
97
+ kind,
98
+ events: invitationEvents(observable),
99
+ authenticate: (code: string) =>
100
+ observable instanceof AuthenticatingInvitationObservable
101
+ ? Effect.tryPromise({
102
+ try: () => observable.authenticate(code),
103
+ catch: (error) => new InvitationError({ context: { error } }),
104
+ })
105
+ : Effect.fail(new InvitationError({ context: { reason: 'flow is not awaiting authentication' } })),
106
+ cancel: () => Effect.promise(() => observable.cancel()),
107
+ code: Effect.sync(() => InvitationEncoder.encode(observable.get())),
108
+ });
109
+
110
+ /**
111
+ * Maps {@link HaloInvitation.ShareOptions} to the client invitation options. Defaults to a
112
+ * no-auth interactive invitation so programmatic flows complete without an auth code.
113
+ */
114
+ export const toShareOptions = (options?: HaloInvitation.ShareOptions): Partial<ClientInvitation> => ({
115
+ authMethod: toAuthMethod(options?.authMethod),
116
+ type: toType(options?.type),
117
+ ...(options?.multiUse !== undefined ? { multiUse: options.multiUse } : {}),
118
+ ...(options?.target !== undefined ? { target: options.target } : {}),
119
+ });
120
+
121
+ const toAuthMethod = (method?: HaloInvitation.AuthMethod): ClientInvitation.AuthMethod => {
122
+ switch (method) {
123
+ case 'shared-secret':
124
+ return ClientInvitation.AuthMethod.SHARED_SECRET;
125
+ case 'known-public-key':
126
+ return ClientInvitation.AuthMethod.KNOWN_PUBLIC_KEY;
127
+ case 'none':
128
+ default:
129
+ return ClientInvitation.AuthMethod.NONE;
130
+ }
131
+ };
132
+
133
+ const toType = (type?: HaloInvitation.Type): ClientInvitation.Type => {
134
+ switch (type) {
135
+ case 'delegated':
136
+ return ClientInvitation.Type.DELEGATED;
137
+ case 'multiuse':
138
+ return ClientInvitation.Type.MULTIUSE;
139
+ case 'interactive':
140
+ default:
141
+ return ClientInvitation.Type.INTERACTIVE;
142
+ }
143
+ };
144
+
145
+ /**
146
+ * Maps a legacy space-member role to the Keyhive-aligned {@link HaloSpace.Access} level.
147
+ * Returns `undefined` for `REMOVED` (not a current member).
148
+ */
149
+ export const toAccess = (role: HaloSpaceMember.Role): HaloSpace.Access | undefined => {
150
+ switch (role) {
151
+ case HaloSpaceMember.Role.OWNER:
152
+ case HaloSpaceMember.Role.ADMIN:
153
+ return 'admin';
154
+ case HaloSpaceMember.Role.EDITOR:
155
+ return 'edit';
156
+ case HaloSpaceMember.Role.READER:
157
+ return 'read';
158
+ default:
159
+ return undefined;
160
+ }
161
+ };
162
+
163
+ /**
164
+ * Maps a Keyhive-aligned {@link HaloSpace.Access} level to a legacy space-member role.
165
+ * Returns `undefined` for `pull` (no legacy equivalent — reject at the call site).
166
+ */
167
+ export const fromAccess = (access: HaloSpace.Access): HaloSpaceMember.Role | undefined => {
168
+ switch (access) {
169
+ case 'admin':
170
+ return HaloSpaceMember.Role.ADMIN;
171
+ case 'edit':
172
+ return HaloSpaceMember.Role.EDITOR;
173
+ case 'read':
174
+ return HaloSpaceMember.Role.READER;
175
+ default:
176
+ return undefined;
177
+ }
178
+ };
179
+
180
+ /**
181
+ * Whether a member is currently online.
182
+ */
183
+ export const isOnline = (member: SpaceMember): boolean => member.presence === SpaceMember.PresenceState.ONLINE;
package/tsconfig.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "extends": "../../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "types": [
5
+ "node"
6
+ ]
7
+ },
8
+ "include": [
9
+ "src"
10
+ ],
11
+ "references": [
12
+ {
13
+ "path": "../../../common/async"
14
+ },
15
+ {
16
+ "path": "../../../common/invariant"
17
+ },
18
+ {
19
+ "path": "../../../common/keys"
20
+ },
21
+ {
22
+ "path": "../../../sdk/client"
23
+ },
24
+ {
25
+ "path": "../../../sdk/client-protocol"
26
+ },
27
+ {
28
+ "path": "../../protocols"
29
+ },
30
+ {
31
+ "path": "../halo"
32
+ }
33
+ ]
34
+ }