Skip to content

ports ​

go
import "github.com/prescriptoo/prescriptoo-api/services/identity/internal/ports"

Package ports defines repository and service interfaces (ports) for the identity service.

Index ​

type AccessTokens ​

AccessTokens signs and validates access credentials bound to a user and session.

go
type AccessTokens interface {
    Issue(userID, sessionID string, expiresAt time.Time) (string, error)
    Validate(token string) (userID, sessionID string, err error)
}

type AccountRepository ​

AccountRepository owns atomic profile, email-token, and password mutations. Password mutations lock the user before sessions and invalidate every reset token and session in the same transaction.

go
type AccountRepository interface {
    UpdateProfile(ctx context.Context, userID, name, phone, avatarURL string) (*domain.User, error)
    AllowEmail(ctx context.Context, email string, purpose domain.EmailPurpose) (bool, error)
    IssueEmailToken(ctx context.Context, userID string, purpose domain.EmailPurpose, hash string, expiresAt time.Time) (bool, error)
    RemoveEmailToken(ctx context.Context, purpose domain.EmailPurpose, hash string) error
    ValidateEmailToken(ctx context.Context, purpose domain.EmailPurpose, hash string) error
    ConfirmEmail(ctx context.Context, hash string) error
    ResetPassword(ctx context.Context, hash, newPasswordHash string) error
    ChangePassword(ctx context.Context, userID, sessionID, expectedHash, newHash string) error
}

type PasswordHasher ​

PasswordHasher defines the driven service port for hashing and verifying passwords.

go
type PasswordHasher interface {
    Hash(password string) (string, error)
    Compare(password, hash string) bool
}

type SessionRepository ​

SessionRepository serializes rotation and revocation. Rotate revokes a session if a previously consumed refresh token is reused.

go
type SessionRepository interface {
    Create(ctx context.Context, session *domain.Session, expectedPasswordHash string) error
    Rotate(ctx context.Context, oldHash, newHash string, now time.Time) (*domain.Session, error)
    FindActive(ctx context.Context, id string, now time.Time) (*domain.Session, error)
    RevokeByToken(ctx context.Context, hash string) error
    AllowLogin(ctx context.Context, email string) (bool, error)
    RevokeAll(ctx context.Context, userID string) error
    ListActive(ctx context.Context, userID string) ([]domain.Session, error)
    RevokeOwned(ctx context.Context, userID, sessionID string) error
}

type UserRepository ​

UserRepository defines the driven repository port for user data persistence.

go
type UserRepository interface {
    Create(ctx context.Context, user *domain.User) error
    FindByEmail(ctx context.Context, email string) (*domain.User, error)
    FindByID(ctx context.Context, id string) (*domain.User, error)
}

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.