device

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeDeviceNotFound       = "DEVICE_NOT_FOUND"
	CodeDeviceAlreadyExists  = "DEVICE_ALREADY_EXISTS"
	CodeDeviceCreationFailed = "DEVICE_CREATION_FAILED"
	CodeDeviceUpdateFailed   = "DEVICE_UPDATE_FAILED"
	CodeDeviceDeletionFailed = "DEVICE_DELETION_FAILED"
	CodeInvalidFingerprint   = "INVALID_FINGERPRINT"
	CodeMaxDevicesReached    = "MAX_DEVICES_REACHED"
)

Variables

View Source
var (
	ErrDeviceNotFound       = &errs.AuthsomeError{Code: CodeDeviceNotFound}
	ErrDeviceAlreadyExists  = &errs.AuthsomeError{Code: CodeDeviceAlreadyExists}
	ErrDeviceCreationFailed = &errs.AuthsomeError{Code: CodeDeviceCreationFailed}
	ErrDeviceUpdateFailed   = &errs.AuthsomeError{Code: CodeDeviceUpdateFailed}
	ErrDeviceDeletionFailed = &errs.AuthsomeError{Code: CodeDeviceDeletionFailed}
	ErrInvalidFingerprint   = &errs.AuthsomeError{Code: CodeInvalidFingerprint}
	ErrMaxDevicesReached    = &errs.AuthsomeError{Code: CodeMaxDevicesReached}
)

Functions

func DeviceAlreadyExists

func DeviceAlreadyExists(fingerprint string) *errs.AuthsomeError

func DeviceCreationFailed

func DeviceCreationFailed(err error) *errs.AuthsomeError

CRUD operation errors

func DeviceDeletionFailed

func DeviceDeletionFailed(err error) *errs.AuthsomeError

func DeviceNotFound

func DeviceNotFound() *errs.AuthsomeError

Device lookup errors

func DeviceUpdateFailed

func DeviceUpdateFailed(err error) *errs.AuthsomeError

func InvalidFingerprint

func InvalidFingerprint() *errs.AuthsomeError

Validation errors

func MaxDevicesReached

func MaxDevicesReached(limit int) *errs.AuthsomeError

Types

type Device

type Device struct {
	ID          xid.ID    `json:"id"`
	UserID      xid.ID    `json:"userId"`
	Fingerprint string    `json:"fingerprint"`
	UserAgent   string    `json:"userAgent"`
	IPAddress   string    `json:"ipAddress"`
	LastActive  time.Time `json:"lastActive"`
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

Device represents a user device (DTO)

func FromSchemaDevice

func FromSchemaDevice(s *schema.Device) *Device

FromSchemaDevice converts a schema.Device to Device DTO

func FromSchemaDevices

func FromSchemaDevices(devices []*schema.Device) []*Device

FromSchemaDevices converts multiple schema.Device to Device DTOs

func (*Device) ToSchema

func (d *Device) ToSchema() *schema.Device

ToSchema converts the Device DTO to schema.Device

type ListDevicesFilter

type ListDevicesFilter struct {
	pagination.PaginationParams
	UserID xid.ID `json:"userId" query:"user_id"`
}

ListDevicesFilter represents filter parameters for listing devices

type ListDevicesResponse

type ListDevicesResponse = pagination.PageResponse[*Device]

ListDevicesResponse is a type alias for the paginated response

type Repository

type Repository interface {
	// Create/Read operations
	CreateDevice(ctx context.Context, d *schema.Device) error
	FindDeviceByID(ctx context.Context, id xid.ID) (*schema.Device, error)
	FindDeviceByFingerprint(ctx context.Context, userID xid.ID, fingerprint string) (*schema.Device, error)

	// List with pagination
	ListDevices(ctx context.Context, filter *ListDevicesFilter) (*pagination.PageResponse[*schema.Device], error)

	// Update operations
	UpdateDevice(ctx context.Context, d *schema.Device) error
	DeleteDevice(ctx context.Context, id xid.ID) error
	DeleteDeviceByFingerprint(ctx context.Context, userID xid.ID, fingerprint string) error

	// Count operations
	CountDevices(ctx context.Context, userID xid.ID) (int, error)
}

Repository defines device persistence operations Following Interface Segregation Principle (ISP) - works with schema types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service manages user devices

func NewService

func NewService(repo Repository) *Service

NewService creates a new device service

func (*Service) CountUserDevices

func (s *Service) CountUserDevices(ctx context.Context, userID xid.ID) (int, error)

CountUserDevices returns the count of devices for a user

func (*Service) GetDevice

func (s *Service) GetDevice(ctx context.Context, id xid.ID) (*Device, error)

GetDevice retrieves a device by ID

func (*Service) GetDeviceByFingerprint

func (s *Service) GetDeviceByFingerprint(ctx context.Context, userID xid.ID, fingerprint string) (*Device, error)

GetDeviceByFingerprint retrieves a device by user ID and fingerprint

func (*Service) ListDevices

func (s *Service) ListDevices(ctx context.Context, filter *ListDevicesFilter) (*ListDevicesResponse, error)

ListDevices returns devices for a user with pagination

func (*Service) RevokeDevice

func (s *Service) RevokeDevice(ctx context.Context, userID xid.ID, fingerprint string) error

RevokeDevice deletes a device record for a user by fingerprint

func (*Service) RevokeDeviceByID

func (s *Service) RevokeDeviceByID(ctx context.Context, id xid.ID) error

RevokeDeviceByID deletes a device record by ID

func (*Service) SetHookRegistry added in v0.0.6

func (s *Service) SetHookRegistry(registry interface{})

SetHookRegistry sets the hook registry for executing lifecycle hooks

func (*Service) TrackDevice

func (s *Service) TrackDevice(ctx context.Context, appID, userID xid.ID, fingerprint, userAgent, ip string) (*Device, error)

TrackDevice creates or updates a device record

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL