npm.io
3.0.5 • Published 21h ago

@ossy/users

Licence
MIT
Version
3.0.5
Deps
4
Size
38 kB
Vulns
0
Weekly
0

@ossy/users

User domain package for the Ossy platform — event-sourced user entities, workspace membership, and user-scoped API token actions.

What this package provides

Primitive File Id / export
Schema user.schema.js @ossy/users/schema/user
Schema ids schema-ids.js UserSchema
Aggregate user.aggregate.js User (kind: 'entity', SchemaId)
Events users.events.js UsersEvents.Created, SignInVerified, NameUpdated, …
Queries users.queries.js UsersQueries
Startup users.startup.js Bot user bootstrap

Client exports (@ossy/users) surface action metadata for the SDK. Server exports (@ossy/users/server) include the aggregate, events, queries, and validators.

Actions

Action Access Task
@ossy/users/actions/update-details authenticated @ossy/users/tasks/update-details
@ossy/users/actions/get-current-user-history authenticated @ossy/users/tasks/get-current-user-history
@ossy/users/actions/join-workspace authenticated @ossy/users/tasks/join-workspace
@ossy/users/actions/leave-workspace authenticated @ossy/users/tasks/leave-workspace
@ossy/users/actions/get-api-tokens authenticated @ossy/users/tasks/get-api-tokens
@ossy/users/actions/create-api-token authenticated @ossy/users/tasks/create-api-token
@ossy/users/actions/invalidate-api-token authenticated @ossy/users/tasks/invalidate-api-token

API token tasks delegate to @ossy/tokens (TokenEvents.Created / revoke flows).

User schema (ADR 0006)

Schema Id Fields
User @ossy/users/schema/user email, firstName, lastName

Event model (ADR 0008)

User entity events use the universal envelope: type (schema id), resourceId, event (lifecycle name), payload, createdBy.

Event Effect
Created New user (type: 'User' or 'Bot')
SignInVerified Sets verifiedAt on first verification
NameUpdated Updates firstName / lastName
WorkspaceJoined Adds workspace id to workspaces[]
WorkspaceLeft Removes workspace id from workspaces[]

UsersEvents.SignedUp was renamed to UsersEvents.Created to match the ADR 0008 lifecycle name.

Server usage

import { Aggregate } from '@ossy/event-store'
import { User, UsersEvents, UserSchema } from '@ossy/users/server'

const created = UsersEvents.Created({ email, firstName, lastName })
const user = await Aggregate.Of(User, created).then(Aggregate.View())

UserSchema.user
// => '@ossy/users/schema/user'

Testing

npm test -w @ossy/users
npm run test:integration -w @ossy/users

Unit coverage lives in package tests; users.integration.spec.js exercises actions against @ossy/platform.