workspaces module in @sublay/js is the client-side surface of the Workspaces bundle. It covers all 22 endpoints — workspace CRUD, membership management, the full invitation lifecycle, and the authority read — so a members-management UI needs no server-side code.
The actor is always derived from the bearer token. No actor field is ever sent from the client — the props types simply do not carry one, and a call that hand-writes actingUserId past the types, even naming the token’s own user, is rejected by the server with 400 workspace/acting-user-not-allowed. Acting on behalf of a different user is the node SDK service-key capability, and it is the only difference in reach between the two SDKs for this bundle — not a restriction on which operations a client may perform.
Requires the
workspaces bundle. See Bundles to install it.fetchWorkspace is the one read that also works without a token, returning the workspace when visibility permits.) Read the concepts first: capabilities vs permissions, rank, reach & ownership, and the identity-matched, no-token invite model.
Workspace lifecycle
createWorkspace
The bearer-token user becomes the owner. Root creation requires a verified email; child creation requirescreate-sub-workspace on the parent.
fetchWorkspace
A single value or an array. The only value is
"memberCount": it adds the workspace’s direct member count; omit it and the field is absent. The server rejects any other value with 400 workspace/invalid-query.fetchManyWorkspaces
Lists the bearer-token user’s workspaces (paginated): by default every workspace they can open, or withrelation: "direct" only the ones they own or are a member of. Each row carries reasons, why the user can open it. Self-service.
Which workspaces the list holds.
"reachable" or left out (the default): every workspace the user can open — owned, a member of, under a workspace they own, or reached by a capability held on an ancestor. "direct": only the workspaces they own or have a member row on.Narrows the list by where each workspace sits in the tree, within
relation. "none": top-level workspaces only. A workspace id: the workspaces directly under that workspace; an id that matches no workspace returns an empty page, not a 404. "any" or left out: workspaces at every level (the default).Order by creation time.
"desc" or left out (the default): newest first. "asc": oldest first, which puts every parent before its children — see Building a workspace switcher.Results per page: a whole number from
1 to 100. Defaults to 20. A larger value is rejected with 400 workspace/invalid-query, never lowered to 100.A single value or an array, sent as a query param. The only value is
"memberCount": it adds a memberCount to every row — the workspace’s direct member count, resolved in one grouped query over the returned page rather than one request per row. Omit it and the field is absent from each row.fetchMutualWorkspaces
Lists the workspaces the bearer-token user and another user have in common (paginated). Each row’sreasons is the bearer-token user’s standing on it. Self-service.
"reachable" or left out (the default): workspaces each of you can open. "direct": workspaces each of you owns or has a member row on.Results per page: a whole number from
1 to 100. Defaults to 20. A larger value is rejected with 400 workspace/invalid-query, never lowered to 100.updateWorkspace
Editsname/metadata. Requires the edit-workspace capability (or ownership). Does not flip the inherit flag.
updateWorkspaceInheritFlag
Flips whether authority held on an ancestor reaches into this node. Owner-only in both directions (own owner or an ancestor owner) — not a capability. Blocked with403 workspace/inherit-enforced when the project enforces its default.
deleteWorkspace
Owner-only (own owner or an ancestor owner). Cascades the whole subtree transactionally and firesworkspace.deleted per deleted workspace — and no workspace.member.removed events for the memberships it tears down (see Webhooks).
transferWorkspaceOwnership
Owner-only (own owner or an ancestor owner).newOwnerId addresses the target — any verified user in the tenant, who need not already be a member.
Titles travel with the people: the new owner keeps the title and metadata they had as a member, and the previous owner keeps theirs when demoted. A previous owner who is removed loses theirs. See Transfer Ownership.
On demote, the ex-owner’s rank (absolute only). Defaults to one rung below the acting user’s anchor —
0 for the usual apex actor, or one below their own row if they sit in this workspace’s ladder.Membership
fetchWorkspaceMembers
The unified roster —WorkspaceRosterResponse, or WorkspaceRosterCountsResponse with countOnly. Never paginated. Requires roster visibility — any relation to the workspace.
A single value or an array of
"ancestorOwners", "reachHolders", "descendants".user field only id is guaranteed (WorkspaceStandingUser): the full user record when the user row still exists, { id } alone when it does not. Read the rest defensively (entry.user.username ?? "Deleted user").
fetchMyWorkspaceMembership
The logged-in user’s own resolved standing on a workspace (GET /workspaces/:workspaceId/members/me): the same WorkspaceMemberStanding record fetchWorkspaceMemberStanding returns for another user. Your own access is never fenced, so capabilities, permissions, rank and relativeRank are always present; relativeRank is 0 when you hold a member row on this workspace and null when you don’t (an owner or ancestor owner without one). A user with no relation to the workspace gets 404 workspace/not-found, as for a missing workspace. See Fetch My Membership.
WorkspaceMemberStanding.
fetchWorkspaceMemberStanding
Another user’s resolved standing, addressed by user id — works for any relation, including users with no direct member row. Requires roster visibility — any relation to the workspace. Passing your own user id astargetUserId is refused with 400 workspace/own-member-id: read your own with fetchMyWorkspaceMembership.
WorkspaceMemberStanding. On its user field only id is guaranteed (WorkspaceStandingUser): the server returns the full user record when the user row still exists and falls back to { id } alone when it does not — a deleted user with a lingering membership row is a reachable case. Read the rest defensively (standing.user.username ?? "Deleted user").
reasons is an array of structured { type, viaWorkspaceId? } entries — the same shape a roster entry’s reasons carries — so you learn which ancestor grants an ancestor-owner / reach-holder standing.
updateWorkspaceMember
Two capability tiers: powerful fields (capabilities, permissions, and rank as either rank or relativeRank) need edit-member-access plus the rank rule and no-escalation; cosmetic fields (title, metadata) need only edit-member-profile. It edits another member: passing your own user id as targetUserId is refused with 400 workspace/own-member-id. Edit your own title, with no capability, with updateMyWorkspaceMembership. The workspace’s owner is never a target, for anyone: naming them gets 404 workspace/not-found, and their title and metadata are theirs alone to set, with updateMyWorkspaceMembership.
Rank moves in either coordinate, never both; omitting both means rank unchanged. See choosing a rank.
An offset from you —
1 = one rung below me. Must be >= 1. Resolved to an absolute rank at write time and frozen. No default.updateMyWorkspaceMembership
The logged-in user edits their own profile on a workspace (PATCH /workspaces/:workspaceId/members/me). Needs no capability. A member edits their title only; a member’s other fields are edited by a member with the capability, through updateWorkspaceMember. The workspace’s owner edits their title and metadata here, and only here: they are profile only and change nothing about the owner’s authority. A user who can see the workspace but is not its owner and holds no member row on it gets 403 workspace/not-member; one with no relation to it gets 404 workspace/not-found, as for a missing workspace. See Update My Membership.
Trimmed, up to 100 characters.
null clears it. Required for a member; the owner sends title, metadata or both. Leaving it out keeps the current title.The owner only. Replaces the owner’s metadata (up to 1 MB). Anyone else who sends it gets
400 workspace/unsupported-param, even with no member row here (refused before the row is looked up).WorkspaceMember | WorkspaceOwnerProfile: for a member, the same WorkspaceMember record updateWorkspaceMember returns; for the owner, a WorkspaceOwnerProfile, the same fields holding the profile only, with rank: null and empty capabilities / permissions, since the owner’s access comes from ownership.
removeWorkspaceMember
Removes another member from this node only. Requiresremove-member and is rank-bounded; sole-owner protected. Passing your own user id as targetUserId is refused with 400 workspace/own-member-id: to leave, use leaveWorkspace.
removeWorkspaceMemberFromSubtree
Removes the target’s direct memberships on this workspace and every descendant you can reach. Passing your own user id astargetUserId is refused with 400 workspace/own-member-id. Requires remove-member, rank-bounded per node. If the target owns this workspace or a descendant, it is refused with 409 workspace/owns-descendants and nothing is removed. Owned workspaces you have standing on always count and are named in ownedWorkspaces. Ones you have no standing on (for example sealed sub-workspaces) count only when the target holds a membership this call would remove, and are listed as { id: null, name: null } after the named ones. ownedCount is the number of entries. An owner of each workspace (or an ancestor owner) must transfer or delete it before you retry. See Remove From Subtree.
leaveWorkspace
Self-service — removes the bearer-token user’s own direct membership on this node only. No capability required. An owner cannot leave (409 workspace/sole-owner); transfer or delete first. A user who only reaches in, with no direct membership here, gets 403 workspace/not-member; one who can’t see the workspace gets 404 workspace/not-found, as for a missing one.
Invitations
createWorkspaceInvite
Requires theinvite capability (or ownership); the inviter is the bearer-token user. Address the invitee by exactly one of email, userId, or username — here userId/username address the invite target, not an actor. Email matching against existing accounts is case-insensitive.
Absolute. Not required — mutually exclusive with
relativeRank, and omitting both applies the relativeRank: 1 default.An offset from the inviter —
1 = one rung below me. Must be >= 1. Anchored on your own rank if you hold a member row here, apex otherwise. A snapshot: resolved to an absolute rank at invite time and frozen. Relying on the default puts everyone on the same rung, and equals cannot manage each other. Sharper case: an inviter with no member row here (the owner, an ancestor owner, a reach holder) anchors at apex, so their default mints rank 0 — name a coordinate if that is not what you want. See choosing a rank.WorkspaceInvitation: the new invitation, or the target’s live pending invitation updated in place (same id, new expiry). It resolves with the same record either way, so inviting someone again is safe. A target who is already a member or owns the workspace → 409 workspace/already-member.
fetchWorkspaceInvites
The workspace’s outbox — the live pending invites it has issued (status='pending' AND expiresAt > now). Requires the invite capability (or ownership). Always returned in full; deliberately unpaginated.
revokeWorkspaceInvite
Marks a pending invitationrevoked. Requires the invite capability (or ownership). Note the verb-suffixed POST .../revoke route — this is not a DELETE.
resendWorkspaceInvite
Refreshes a pending invite — resets a 14-day expiry and resends the email — valid even on one already pastexpiresAt. Terminal invites → 409. Requires the invite capability (or ownership). Also a verb-suffixed POST .../resend. Returns the refreshed WorkspaceInvitation, carrying the new expiresAt. Like createWorkspaceInvite, it requires workspaces.inviteAcceptUrl on the project → otherwise 409 workspace/missing-invite-accept-url with expiresAt untouched.
fetchMyWorkspaceInvites
The caller’s inbox — the bearer-token user’s live pending invites across every workspace, matched byuserId from the token. Self-service, and surfacing is not verification-gated — a user sees pending invites right after signup (which nudges them to verify). The verified check applies when they act on one (accept or decline).
acceptWorkspaceInvite
Self-service — identity-matched to the bearer-token user, and a verified email is required. TheinviteId is non-secret.
WorkspaceMemberStanding — the same record fetchMyWorkspaceMembership returns, every field present. It resolves with the same record whether the accept just made you a member or you already were one (or own the workspace), so accepting again an invite you already accepted, while still a member, is safe. An invite declined, revoked, accepted by another user, accepted before you left the workspace, or expired → 409 workspace/not-pending.
declineWorkspaceInvite
Self-service — identity-matched, and a verified email is required (the same gate as accept, so an unverified squatter on someone else’s address cannot burn their invite). Returns403 workspace/email-not-verified otherwise.
Authority-as-a-service
fetchWorkspaceAuthority
The bearer-token user’s resolved standing on a workspace —{ reasons, capabilities, permissions, rank }. Self-service, so nothing is fenced here. (No relativeRank: it is an offset from you, and here the subject is you, so rank is the coordinate this read reports.) Drive your UI off this rather than guessing: a permission check is a one-line .includes() on the result.
reasons is an array of structured { type, viaWorkspaceId? } entries (viaWorkspaceId on ancestor-owner / reach-holder only). capabilities is the fully-resolved set and view is implied by every other capability — any user with standing carries it, and a user with no relation gets 404 workspace/not-found instead of a record.
permissions — there is deliberately no ?permission= check or can() helper.
