@useoneauth/identity
v1.0.0
Published
> Phase 1 — Identity Core. The OneAuth identity graph: identities, organizations, memberships, and relationships.
Readme
@useoneauth/identity
Phase 1 — Identity Core. The OneAuth identity graph: identities, organizations, memberships, and relationships.
This package owns the identity graph concern only. It is pure TypeScript with no database or transport dependencies: services hold business logic and emit immutable events; persistence is expressed through repository interfaces with in-memory adapters. A Prisma adapter will implement the same interfaces in a later phase with zero service changes.
Install
Workspace package (pnpm monorepo). Add it to another workspace package:
// package.json
{ "dependencies": { "@useoneauth/identity": "workspace:*" } }Usage
import {
IdentityService,
InMemoryIdentityRepository,
InMemoryRelationshipRepository,
InMemoryEventBus,
} from "@useoneauth/identity"
const events = new InMemoryEventBus()
events.subscribe("IDENTITY_CREATED", (e) => console.log("created", e.payload))
const identities = new IdentityService(
new InMemoryIdentityRepository(),
new InMemoryRelationshipRepository(),
events,
)
const alice = await identities.createIdentity({ type: "human", email: "[email protected]" })
const laptop = await identities.createIdentity({ type: "device", label: "macbook" })
// "alice → owns → macbook" — the graph edge that makes identity a graph
await identities.linkIdentity(alice.id, "owns", laptop.id)Services
| Service | Responsibility |
|---|---|
| IdentityService | createIdentity, getIdentity, updateIdentity, deleteIdentity, linkIdentity |
| OrganizationService | createOrganization |
| MembershipService | addMember |
All services take their dependencies via constructor injection (repository port,
EventPublisher, and an optional idFactory defaulting to crypto.randomUUID).
Identity types
Identity is a discriminated union on type: HumanIdentity (email),
ServiceIdentity (name), DeviceIdentity (label), AgentIdentity (name + ownerId).
Events
Every mutation persists, then publishes an immutable event:
IDENTITY_CREATED, IDENTITY_UPDATED, ORGANIZATION_CREATED,
MEMBERSHIP_CREATED, RELATIONSHIP_CREATED.
Scripts
pnpm --filter @useoneauth/identity test # run unit tests
pnpm --filter @useoneauth/identity test:cov # tests + coverage (≥90% gate)
pnpm --filter @useoneauth/identity typecheck # tsc --noEmitSee ARCHITECTURE.md for layer boundaries and the ports/adapters design.
