Memberships
Membership and relationship tuples
git clone https://github.com/bijectionhq/memberships.git
cd memberships
git checkout 3709c5e1e9bd794b03be90df76cf16377a239a90Bijection repository access is required. Request access.
Description
Membership and relationship tuples
Explore the package README for API concepts, configuration, and examples. Check the Bijection source for adaptation-specific setup.
Review the source and its dependencies before adopting this package. Source availability does not establish npm publication or runtime qualification.
Getting started
- Get the source at the revision above and read its package documentation.
- Check the required Bijection SDK version, dependencies, and external service credentials.
- Follow the package setup instructions and the guide to using components.
- Exercise the component in your deployment according to your project’s verification rules.
Open source
Maintained source: bijectionhq/memberships. Based on vllnt/convex-memberships. License: MIT. Consult the repository for license terms, notices, and contributor attribution.
From the upstream publisher
Auth-agnostic membership and relationship graph (ReBAC tuples), as a Convex component
Explore the demo ↗Upstream overview
From the upstream package documentation.
@vllnt/convex-memberships stores who is related to what using memberRef, resourceRef, and relation. Your app defines the meaning of each reference and relationship, so one storage model can support several domains.
Add or remove relationship tuples, transition a relation, and paginate in either direction: members of a resource or resources of a member. Re-adding the same tuple is idempotent. Opaque kind and status fields let the host describe its own entities.
The host owns authentication and permission policy. Always specify the accepted relation in authorization checks: an any-relation check can also match an invited or suspended relationship. This is a flat relationship store; transitive group expansion belongs in the application.
Maintained by bntvllnt at VLLNT. Find the author on GitHub and X.
Use cases
From the upstream package documentation.
- SaaS workspaces: list members and the workspaces a person belongs to.
- Learning platforms: represent learners enrolled in courses or cohorts.
- Games and communities: maintain guild, team, or group membership.
- Collaborative tools: record document viewers, editors, or resource-specific sharing relationships.
How it works
From the upstream package documentation.
Add or remove relationship tuples, transition a relation, and paginate in either direction: members of a resource or resources of a member. Re-adding the same tuple is idempotent. Opaque kind and status fields let the host describe its own entities.
The host owns authentication and permission policy. Always specify the accepted relation in authorization checks: an any-relation check can also match an invited or suspended relationship. This is a flat relationship store; transitive group expansion belongs in the application.
Upstream package FAQ
Does `@vllnt/convex-memberships` work with any auth provider?
`@vllnt/convex-memberships` is fully auth-agnostic. The host application resolves identity and decides who may create or read an edge; the component only receives and stores opaque string refs. This means it works with Clerk, Auth0, custom JWT auth, or any other system you use with Convex.
What happens if I call `add` twice with the same member, resource, and relation?
`add` in `@vllnt/convex-memberships` is idempotent on the full `(memberRef, resourceRef, relation)` tuple. If a matching edge already exists, the call returns the existing document id and patches `memberKind` and `status` if they differ. No duplicate edges are created.
Is calling `isMember` without a relation safe for authorization gates?
Calling `memberships.isMember(ctx, memberRef, resourceRef)` without a `relation` argument returns `true` for any stored relation, including `'invited'`, `'suspended'`, or `'banned'`. For authorization gates, always pass an explicit `relation` or enumerate the relations your policy accepts to avoid granting access to non-active membership states.
Does `@vllnt/convex-memberships` support transitive group membership?
No. `@vllnt/convex-memberships` currently stores flat edges only. A member of a group that is itself a member of an org will not be automatically resolved as a member of that org. Transitive expansion is planned for a future version.
How do I use the React hooks provided by `@vllnt/convex-memberships`?
Import hooks from `@vllnt/convex-memberships/react` and pass your host app's re-exported query reference as the first argument. For example, `useIsMember(api.memberships.isMember, { memberRef: userId, resourceRef: orgId, relation: 'admin' })` returns `boolean | undefined`, where `undefined` means the query is still loading. React is an optional peer dependency; backend-only consumers do not pull it in.
Use with agents and CLI
Give your coding agent the component’s source identity and setup guidance.
Help me integrate Memberships with Bijection.
Read: https://bijection.com/components/memberships/SKILL.md
Check SDK compatibility and dependency availability.
Follow this project's execution and verification rules.Upstream README.md
View repository ↗Documentation from vllnt/convex-memberships, recorded October 23, 2026. APIs and setup may differ in the Bijection adaptation.
@vllnt/convex-memberships
Auth-agnostic membership and relationship graph (ReBAC tuples), as a Convex component.
const memberships = new Memberships(components.memberships);
await memberships.add(ctx, userId, orgId, "admin");
const isAdmin = await memberships.isMember(ctx, userId, orgId, "admin");
A tuple is (memberRef, resourceRef, relation), classified by an opaque
memberKind. Domain-neutral: org membership, document sharing, team roles, group
nesting — any "who relates to what, and how" question. Edges are flat —
transitive expansion (a member of a group that is a member of an org) is not
auto-resolved; it is planned for vNext.
Features
- Flat ReBAC tuples —
(memberRef, resourceRef, relation)with an opaquememberKind(defaults"user") and optionalstatus. - Idempotent edges —
adddedupes on the full tuple, returning the existing id and patchingmemberKind/status. - Paginated listing — members of a resource, and resources of a member, both paginated for guild/workspace scale.
- Relation filtering — list members narrowed to a single relation.
- Bounded membership checks — exact-relation, or any-relation via index (not a full member scan).
- Guarded relation transitions —
setRelationmoves an edge, guarded against collisions; missing source ⇒NOT_FOUND. - Auditable removal —
removereturns{ removed };documentsexposes storedcreatedAtandstatus. - Opaque refs — every ref/relation/kind/status is an arbitrary host string the component never inspects.
Installation
pnpm add @vllnt/convex-memberships
Peer dependency: convex@^1.41.0.
Usage
// convex/convex.config.ts
import { defineApp } from "convex/server";
import memberships from "@vllnt/convex-memberships/convex.config";
const app = defineApp();
app.use(memberships);
export default app;
// convex/teams.ts — host owns auth; pass opaque refs in.
import { components } from "./_generated/api";
import { mutation, query } from "./_generated/server";
import { v } from "convex/values";
import { Memberships } from "@vllnt/convex-memberships";
const memberships = new Memberships(components.memberships);
export const join = mutation({
args: { userId: v.string(), orgId: v.string() },
handler: (ctx, { userId, orgId }) => memberships.add(ctx, userId, orgId),
});
export const isInOrg = query({
args: { userId: v.string(), orgId: v.string() },
handler: (ctx, { userId, orgId }) => memberships.isMember(ctx, userId, orgId),
});
Client options: new Memberships(component, { defaultRelation = "member", defaultMemberKind = "user" }).
API Reference
| Method | Kind | Result |
|---|---|---|
add(ctx, memberRef, resourceRef, relation?, memberKind?, status?) | mutation | id (tuple-idempotent; patches memberKind/status on re-add) |
remove(ctx, memberRef, resourceRef, relation?) | mutation | { removed } (idempotent) |
setRelation(ctx, memberRef, resourceRef, fromRelation, toRelation) | mutation | { ok, reason? } (NOT_FOUND | EXISTS) |
listMembers(ctx, resourceRef, paginationOpts, relation?) | query | Page<MemberEntry> |
members(ctx, memberRef, paginationOpts) | query | Page<ResourceEntry> |
isMember(ctx, memberRef, resourceRef, relation?) | query | boolean |
documents(ctx, paginationOpts, filter?) | query | Page<MembershipDoc> |
Full reference: docs/API.md.
React
An optional, tree-shakeable ./react entry ships thin hooks over convex/react's
useQuery. react is an optional peer dependency — a backend-only consumer pulls
zero React. Each hook takes the host app's re-exported query reference.
import { useIsMember } from "@vllnt/convex-memberships/react";
import { api } from "../convex/_generated/api";
const isAdmin = useIsMember(api.memberships.isMember, {
memberRef: userId,
resourceRef: orgId,
relation: "admin",
}); // boolean | undefined (undefined while loading)
| Hook | Args | Returns |
|---|---|---|
useIsMember(isMemberRef, { memberRef, resourceRef, relation? }) | the host's isMember ref | boolean | undefined |
useMembers(membersRef, { memberRef }) | the host's members ref | first page of resource entries | undefined |
useListMembers(listMembersRef, { resourceRef, relation? }) | the host's listMembers ref | first page of member entries | undefined |
Security
- Auth-agnostic — the host resolves identity, decides who may create/read an edge, and passes opaque refs; tables are sandboxed (reached only via the client).
isMemberfootgun — called withoutrelation, it returnstruefor any stored relation ("invited","suspended","banned", …). For authz gates, always passrelationor enumerate the relations your policy accepts.
See docs/API.md.
Testing
pnpm test # single run
pnpm test:coverage # enforced 100% on covered files
Tests run against the real component runtime via convex-test (@edge-runtime/vm), not mocks.
Contributing
See CONTRIBUTING.md.
Author
Built by bntvllnt · bntvllnt.com · X @bntvllnt
Part of the @vllnt Convex component fleet — vllnt.com
If this is useful, sponsor the work.
License
MIT — see LICENSE.