Documentation
¶
Index ¶
- Constants
- Variables
- func DeviceAlreadyExists(fingerprint string) *errs.AuthsomeError
- func DeviceCreationFailed(err error) *errs.AuthsomeError
- func DeviceDeletionFailed(err error) *errs.AuthsomeError
- func DeviceNotFound() *errs.AuthsomeError
- func DeviceUpdateFailed(err error) *errs.AuthsomeError
- func InvalidFingerprint() *errs.AuthsomeError
- func MaxDevicesReached(limit int) *errs.AuthsomeError
- type Device
- type ListDevicesFilter
- type ListDevicesResponse
- type Repository
- type Service
- func (s *Service) CountUserDevices(ctx context.Context, userID xid.ID) (int, error)
- func (s *Service) GetDevice(ctx context.Context, id xid.ID) (*Device, error)
- func (s *Service) GetDeviceByFingerprint(ctx context.Context, userID xid.ID, fingerprint string) (*Device, error)
- func (s *Service) ListDevices(ctx context.Context, filter *ListDevicesFilter) (*ListDevicesResponse, error)
- func (s *Service) RevokeDevice(ctx context.Context, userID xid.ID, fingerprint string) error
- func (s *Service) RevokeDeviceByID(ctx context.Context, id xid.ID) error
- func (s *Service) SetHookRegistry(registry interface{})
- func (s *Service) TrackDevice(ctx context.Context, appID, userID xid.ID, fingerprint, userAgent, ip string) (*Device, error)
Constants ¶
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 ¶
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 DeviceUpdateFailed ¶
func DeviceUpdateFailed(err error) *errs.AuthsomeError
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 ¶
FromSchemaDevice converts a schema.Device to Device DTO
func FromSchemaDevices ¶
FromSchemaDevices converts multiple schema.Device to Device DTOs
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 (*Service) CountUserDevices ¶
CountUserDevices returns the count of devices for a user
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 ¶
RevokeDevice deletes a device record for a user by fingerprint
func (*Service) RevokeDeviceByID ¶
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