Models
This page documents the data structures used throughout the NextJS SDK.
User
The User model represents an authenticated user in the system.
interface User {
id: string
email: string
emailVerified: boolean
createdAt: string // ISO 8601 datetime
updatedAt: string // ISO 8601 datetime
version: number
// Frontend specific fields
name?: string
avatar?: string
preferences?: UserPreferences
}
interface UserPreferences {
theme?: 'light' | 'dark' | 'system'
language?: string
notifications?: {
email?: boolean
push?: boolean
}
}
User Properties
id: Unique identifier for the useremail: User's email address, used for authentication and communicationemailVerified: Indicates whether the user's email has been verifiedcreatedAt: Timestamp when the user account was createdupdatedAt: Timestamp of the last update to the user accountversion: Version number for optimistic concurrency controlname: Optional display name for the useravatar: Optional URL to the user's profile picturepreferences: User-specific settings and preferences
UserPreferences Properties
theme: User's preferred UI themelanguage: User's preferred languagenotifications: User's notification preferencesemail: Whether to receive email notificationspush: Whether to receive push notifications
Organization
The Organization model represents a group of users working together.
interface Organization {
id: string
name: string
createdBy: string // UserId
createdAt: string // ISO 8601 datetime
updatedAt: string // ISO 8601 datetime
version: number
// Frontend specific fields
slug?: string
settings?: OrganizationSettings
}
interface OrganizationSettings {
allowedDomains?: string[]
requireDomainMatch?: boolean
defaultRole?: string
}
Organization Properties
id: Unique identifier for the organizationname: Display name of the organizationcreatedBy: ID of the user who created the organizationcreatedAt: Timestamp when the organization was createdupdatedAt: Timestamp of the last update to the organizationversion: Version number for optimistic concurrency controlslug: Optional URL-friendly version of the organization name (frontend only)settings: Optional organization-specific configuration (frontend only)
OrganizationSettings Properties
allowedDomains: List of email domains allowed to join the organizationrequireDomainMatch: Whether users must have an email from an allowed domaindefaultRole: Default role assigned to new members
Team
The Team model represents a group within an organization.
interface Team {
id: string
name: string
organizationId: string
createdBy: string // UserId
createdAt: string // ISO 8601 datetime
updatedAt: string // ISO 8601 datetime
version: number
// Frontend specific fields
description?: string
members?: TeamMember[]
invites?: TeamInvite[]
}
interface TeamMember {
id: string
userId: string
teamId: string
role: TeamRole
joinedAt: string
}
interface TeamInvite {
id: string
email: string
teamId: string
role: TeamRole
status: 'pending' | 'accepted' | 'rejected'
createdAt: string
expiresAt: string
}
type TeamRole = 'admin' | 'member' | 'viewer'
Team Properties
id: Unique identifier for the teamname: Display name of the teamorganizationId: ID of the parent organizationcreatedBy: ID of the user who created the teamcreatedAt: Timestamp when the team was createdupdatedAt: Timestamp of the last update to the teamversion: Version number for optimistic concurrency controldescription: Optional description of the team's purpose (frontend only)members: Optional list of current team members (frontend only)invites: Optional list of pending team invitations (frontend only)
TeamMember Properties
id: Unique identifier for the team membershipuserId: ID of the user who is a memberteamId: ID of the team they belong torole: User's role within the teamjoinedAt: Timestamp when the user joined the team
TeamInvite Properties
id: Unique identifier for the invitationemail: Email address of the invited userteamId: ID of the team they're invited torole: Role they'll have if they acceptstatus: Current status of the invitationcreatedAt: Timestamp when the invitation was createdexpiresAt: Timestamp when the invitation expires
TeamRole Values
admin: Can manage team settings and membersmember: Can participate in team activitiesviewer: Can view team content but not modify it
Session
The Session model represents an active user session.
interface Session {
id: string
userId: string
organizationId?: string
teamId?: string
expiresAt: string
createdAt: string
lastActiveAt: string
}
Session Properties
id: Unique identifier for the sessionuserId: ID of the user who owns the sessionorganizationId: Optional ID of the selected organizationteamId: Optional ID of the selected teamexpiresAt: Timestamp when the session will expirecreatedAt: Timestamp when the session was createdlastActiveAt: Timestamp of the last activity in the session
Token
The Token model represents the authentication tokens used by the SDK. While the SDK handles token management internally, understanding the token structure can be helpful for debugging and custom implementations.
type TokenType = 'AccessToken' | 'RefreshToken' | 'IdToken'
interface Token {
id: string
userId: string
clientId: string
tokenType: TokenType
scopes: string[]
issuedAt: string // ISO 8601 datetime
expiresAt?: string // ISO 8601 datetime
revokedAt?: string // ISO 8601 datetime
}
// JWT payload structure for AccessToken
interface AccessTokenPayload {
sub: string // User ID
email: string
org?: string // Organization ID
team?: string // Team ID
roles: string[]
permissions: string[]
iat: number // Issued at
exp: number // Expires at
}
Token Properties
id: Unique identifier for the tokenuserId: ID of the user who owns the tokenclientId: ID of the client application that requested the tokentokenType: Type of token (AccessToken, RefreshToken, or IdToken)scopes: Array of permission scopes granted to the tokenissuedAt: Timestamp when the token was issuedexpiresAt: Optional timestamp when the token expiresrevokedAt: Optional timestamp when the token was revoked
TokenType Values
AccessToken: Short-lived token used for API authenticationRefreshToken: Long-lived token used to obtain new access tokensIdToken: Token containing user identity information
AccessTokenPayload Properties
The AccessToken payload contains the following claims when decoded:
sub: Subject (User ID)email: User's email addressorg: Optional Organization IDteam: Optional Team IDroles: Array of user rolespermissions: Array of granted permissionsiat: Token issuance timestampexp: Token expiration timestamp
Error Types
The error types used throughout the SDK.
interface HeimdallError {
code: string
message: string
details?: Record<string, unknown>
}
// Common error codes
type ErrorCode =
| 'UNAUTHORIZED'
| 'FORBIDDEN'
| 'NOT_FOUND'
| 'VALIDATION_ERROR'
| 'RATE_LIMITED'
| 'INTERNAL_ERROR'
HeimdallError Properties
code: Machine-readable error codemessage: Human-readable error messagedetails: Optional additional error information
ErrorCode Values
UNAUTHORIZED: User is not authenticatedFORBIDDEN: User lacks required permissionsNOT_FOUND: Requested resource doesn't existVALIDATION_ERROR: Invalid input dataRATE_LIMITED: Too many requestsINTERNAL_ERROR: Server-side error
Permissions
The permission models define the access control system.
interface Permission {
id: string
name: string
description: string
category: PermissionCategory
scope: PermissionScope
}
type PermissionCategory = 'organization' | 'team' | 'user' | 'resource'
type PermissionScope = 'read' | 'write' | 'delete' | 'manage'
interface UserPermission {
id: string
userId: string
permissionId: string
scope: PermissionScope
context: PermissionContext
createdAt: string
updatedAt: string
}
interface PermissionContext {
organizationId?: string
teamId?: string
resourceId?: string
}
Permission Properties
id: Unique identifier for the permissionname: Machine-readable name of the permission (e.g., 'read:team')description: Human-readable description of what the permission allowscategory: The type of resource this permission applies toscope: The level of access granted
PermissionCategory Values
organization: Organization-level permissionsteam: Team-level permissionsuser: User-level permissionsresource: Resource-specific permissions
PermissionScope Values
read: Ability to view resourceswrite: Ability to modify resourcesdelete: Ability to remove resourcesmanage: Ability to manage permissions and settings
UserPermission Properties
id: Unique identifier for the permission assignmentuserId: ID of the user who has the permissionpermissionId: ID of the permission being grantedscope: The level of access grantedcontext: The specific context where the permission appliescreatedAt: Timestamp when the permission was grantedupdatedAt: Timestamp of the last update to the permission
PermissionContext Properties
organizationId: Optional ID of the organization where the permission appliesteamId: Optional ID of the team where the permission appliesresourceId: Optional ID of the specific resource where the permission applies
