services

package
v0.0.0-...-5f05ef2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: AGPL-3.0, AGPL-3.0-or-later Imports: 22 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminService

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

AdminService handles all admin-specific operations on documents and signers

func NewAdminService

func NewAdminService(docRepo adminDocumentRepository, signerRepo adminSignerRepository) *AdminService

NewAdminService creates a new admin service

func (*AdminService) AddExpectedSigners

func (s *AdminService) AddExpectedSigners(ctx context.Context, docID string, contacts []models.ContactInfo, addedBy string) error

func (*AdminService) CountDocuments

func (s *AdminService) CountDocuments(ctx context.Context, searchQuery string) (int, error)

func (*AdminService) DeleteDocument

func (s *AdminService) DeleteDocument(ctx context.Context, docID string) error

func (*AdminService) GetDocument

func (s *AdminService) GetDocument(ctx context.Context, docID string) (*models.Document, error)

Document operations

func (*AdminService) GetSignerStats

func (s *AdminService) GetSignerStats(ctx context.Context, docID string) (*models.DocCompletionStats, error)

func (*AdminService) ListDocuments

func (s *AdminService) ListDocuments(ctx context.Context, limit, offset int) ([]*models.Document, error)

func (*AdminService) ListExpectedSigners

func (s *AdminService) ListExpectedSigners(ctx context.Context, docID string) ([]*models.ExpectedSigner, error)

Expected signer operations

func (*AdminService) ListExpectedSignersWithStatus

func (s *AdminService) ListExpectedSignersWithStatus(ctx context.Context, docID string) ([]*models.ExpectedSignerWithStatus, error)

func (*AdminService) RemoveExpectedSigner

func (s *AdminService) RemoveExpectedSigner(ctx context.Context, docID, email string) error

func (*AdminService) SearchDocuments

func (s *AdminService) SearchDocuments(ctx context.Context, query string, limit, offset int) ([]*models.Document, error)

func (*AdminService) UpdateDocumentMetadata

func (s *AdminService) UpdateDocumentMetadata(ctx context.Context, docID string, input models.DocumentInput, updatedBy string) (*models.Document, error)

type AuthorizerService

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

AuthorizerService provides authorization decisions for the organization. In Community Edition, it uses environment variables for configuration.

func NewAuthorizerService

func NewAuthorizerService(adminEmails []string, onlyAdminCanCreate bool) *AuthorizerService

NewAuthorizerService creates a new AuthorizerService with the given configuration.

func (*AuthorizerService) IsAdmin

func (s *AuthorizerService) IsAdmin(email string) bool

IsAdmin checks if the given email belongs to an administrator.

func (*AuthorizerService) OnlyAdminCanCreate

func (s *AuthorizerService) OnlyAdminCanCreate() bool

OnlyAdminCanCreate returns whether only administrators can create documents.

type CSVParseError

type CSVParseError struct {
	LineNumber int    `json:"lineNumber"`
	Content    string `json:"content"`
	Error      string `json:"error"`
}

CSVParseError represents an error for a specific line in the CSV

type CSVParseResult

type CSVParseResult struct {
	Signers      []CSVSignerEntry `json:"signers"`
	Errors       []CSVParseError  `json:"errors"`
	TotalLines   int              `json:"totalLines"`
	ValidCount   int              `json:"validCount"`
	InvalidCount int              `json:"invalidCount"`
	HasHeader    bool             `json:"hasHeader"`
}

CSVParseResult contains the complete result of parsing a CSV file

type CSVParser

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

CSVParser handles CSV file parsing for expected signers import

func NewCSVParser

func NewCSVParser(maxSigners int) *CSVParser

NewCSVParser creates a new CSV parser with the given configuration

func (*CSVParser) Parse

func (p *CSVParser) Parse(reader io.Reader) (*CSVParseResult, error)

Parse reads and parses a CSV file from the given reader

type CSVParserConfig

type CSVParserConfig struct {
	MaxSigners int
}

CSVParserConfig holds configuration for CSV parsing

type CSVSignerEntry

type CSVSignerEntry struct {
	LineNumber int    `json:"lineNumber"`
	Email      string `json:"email"`
	Name       string `json:"name"`
}

CSVSignerEntry represents a valid signer entry parsed from CSV

type ChainIntegrityResult

type ChainIntegrityResult struct {
	IsValid      bool
	TotalRecords int
	BreakAtID    *int64
	Details      string
}

type ChecksumService

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

ChecksumService orchestrates document integrity verification with audit trail persistence

func NewChecksumService

func NewChecksumService(
	verificationRepo ChecksumVerificationRepository,
	documentRepo DocumentRepository,
) *ChecksumService

NewChecksumService initializes checksum verification service with required repository dependencies

func (*ChecksumService) GetChecksumInfo

func (s *ChecksumService) GetChecksumInfo(ctx context.Context, docID string) (map[string]interface{}, error)

GetChecksumInfo exposes document hash metadata for public verification interfaces

func (*ChecksumService) GetSupportedAlgorithms

func (s *ChecksumService) GetSupportedAlgorithms() []string

GetSupportedAlgorithms returns available hash algorithms for client-side documentation

func (*ChecksumService) GetVerificationHistory

func (s *ChecksumService) GetVerificationHistory(ctx context.Context, docID string, limit int) ([]*models.ChecksumVerification, error)

GetVerificationHistory retrieves paginated audit trail of all checksum validation attempts

func (*ChecksumService) ValidateChecksumFormat

func (s *ChecksumService) ValidateChecksumFormat(checksum, algorithm string) error

ValidateChecksumFormat ensures checksum matches expected hexadecimal length for SHA-256/SHA-512/MD5

func (*ChecksumService) VerifyChecksum

func (s *ChecksumService) VerifyChecksum(ctx context.Context, docID, calculatedChecksum, verifiedBy string) (*models.ChecksumVerificationResult, error)

VerifyChecksum compares calculated hash against stored reference and creates immutable audit record

type ChecksumVerificationRepository

type ChecksumVerificationRepository interface {
	RecordVerification(ctx context.Context, verification *models.ChecksumVerification) error
	GetVerificationHistory(ctx context.Context, docID string, limit int) ([]*models.ChecksumVerification, error)
	GetLastVerification(ctx context.Context, docID string) (*models.ChecksumVerification, error)
}

ChecksumVerificationRepository defines the interface for checksum verification persistence

type CreateDocumentRequest

type CreateDocumentRequest struct {
	Reference string `json:"reference" validate:"required,min=1"`
	Title     string `json:"title"`
}

CreateDocumentRequest represents the request to create a document

type DocumentRepository

type DocumentRepository interface {
	GetByDocID(ctx context.Context, docID string) (*models.Document, error)
}

DocumentRepository defines the interface for document metadata operations

type DocumentService

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

DocumentService handles document metadata operations and unique ID generation

func NewDocumentService

func NewDocumentService(repo documentRepository, expectedSignerRepo docExpectedSignerRepository, checksumConfig *config.ChecksumConfig) *DocumentService

NewDocumentService initializes the document service with its repository dependency

func (*DocumentService) Count

func (s *DocumentService) Count(ctx context.Context, searchQuery string) (int, error)

Count returns the total number of documents matching the search query

func (*DocumentService) CreateDocument

func (s *DocumentService) CreateDocument(ctx context.Context, req CreateDocumentRequest) (*models.Document, error)

CreateDocument generates a collision-resistant base36 identifier and persists document metadata

func (*DocumentService) FindByReference

func (s *DocumentService) FindByReference(ctx context.Context, ref string, refType string) (*models.Document, error)

FindByReference finds a document by its reference without creating it

func (*DocumentService) FindOrCreateDocument

func (s *DocumentService) FindOrCreateDocument(ctx context.Context, ref string) (*models.Document, bool, error)

FindOrCreateDocument performs smart lookup by URL/path/reference or creates new document if not found

func (*DocumentService) GetByDocID

func (s *DocumentService) GetByDocID(ctx context.Context, docID string) (*models.Document, error)

GetByDocID retrieves a document by its ID

func (*DocumentService) GetExpectedSignerStats

func (s *DocumentService) GetExpectedSignerStats(ctx context.Context, docID string) (*models.DocCompletionStats, error)

GetExpectedSignerStats retrieves completion statistics for expected signers

func (*DocumentService) List

func (s *DocumentService) List(ctx context.Context, limit, offset int) ([]*models.Document, error)

List retrieves a paginated list of documents

func (*DocumentService) ListExpectedSigners

func (s *DocumentService) ListExpectedSigners(ctx context.Context, docID string) ([]*models.ExpectedSigner, error)

ListExpectedSigners retrieves all expected signers for a document

func (*DocumentService) Search

func (s *DocumentService) Search(ctx context.Context, query string, limit, offset int) ([]*models.Document, error)

Search performs a search query across documents

type MagicLinkRepository

type MagicLinkRepository interface {
	CreateToken(ctx context.Context, token *models.MagicLinkToken) error
	GetByToken(ctx context.Context, token string) (*models.MagicLinkToken, error)
	MarkAsUsed(ctx context.Context, token string, ip string, userAgent string) error
	DeleteExpired(ctx context.Context) (int64, error)

	LogAttempt(ctx context.Context, attempt *models.MagicLinkAuthAttempt) error
	CountRecentAttempts(ctx context.Context, email string, since time.Time) (int, error)
	CountRecentAttemptsByIP(ctx context.Context, ip string, since time.Time) (int, error)
}

MagicLinkRepository définit les opérations sur les tokens Magic Link

type MagicLinkService

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

MagicLinkService gère l'authentification par Magic Link

func NewMagicLinkService

func NewMagicLinkService(cfg MagicLinkServiceConfig) *MagicLinkService

func (*MagicLinkService) CleanupExpiredTokens

func (s *MagicLinkService) CleanupExpiredTokens(ctx context.Context) (int64, error)

CleanupExpiredTokens supprime les tokens expirés (à appeler périodiquement)

func (*MagicLinkService) CreateReminderAuthToken

func (s *MagicLinkService) CreateReminderAuthToken(
	ctx context.Context,
	emailAddr string,
	docID string,
) (string, error)

CreateReminderAuthToken génère un token d'authentification pour un email de reminder Ce token a une durée de validité de 24 heures (vs 15 min pour magic link classique) Il ne valide pas les domaines autorisés et n'envoie pas d'email (géré par ReminderService)

func (s *MagicLinkService) RequestMagicLink(
	ctx context.Context,
	emailAddr string,
	redirectTo string,
	ip string,
	userAgent string,
	locale string,
) error

RequestMagicLink génère et envoie un Magic Link par email

func (s *MagicLinkService) VerifyMagicLink(
	ctx context.Context,
	token string,
	ip string,
	userAgent string,
) (*models.MagicLinkToken, error)

VerifyMagicLink vérifie et consomme un token Magic Link

func (*MagicLinkService) VerifyReminderAuthToken

func (s *MagicLinkService) VerifyReminderAuthToken(
	ctx context.Context,
	token string,
	ip string,
	userAgent string,
) (*models.MagicLinkToken, error)

VerifyReminderAuthToken vérifie et consomme un token de reminder auth

type MagicLinkServiceConfig

type MagicLinkServiceConfig struct {
	Repository        MagicLinkRepository
	EmailSender       emailSender
	I18n              i18nTranslator
	BaseURL           string
	AppName           string
	AllowedDomains    []string
	TokenValidity     time.Duration // Défaut: 15 minutes
	RateLimitPerEmail int           // Défaut: 3
	RateLimitPerIP    int           // Défaut: 10
	RateLimitWindow   time.Duration // Défaut: 1 heure
}

MagicLinkServiceConfig pour le service Magic Link

type ReferenceType

type ReferenceType string
const (
	ReferenceTypeURL       ReferenceType = "url"
	ReferenceTypePath      ReferenceType = "path"
	ReferenceTypeReference ReferenceType = "reference"
)

type ReminderAsyncService

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

ReminderAsyncService manages email notifications using asynchronous queue

func NewReminderAsyncService

func NewReminderAsyncService(
	expectedSignerRepo asyncExpectedSignerRepository,
	reminderRepo asyncReminderRepository,
	queueRepo emailQueueRepository,
	magicLinkService asyncMagicLinkService,
	i18nService translator,
	baseURL string,
) *ReminderAsyncService

NewReminderAsyncService initializes async reminder service with queue support

func (*ReminderAsyncService) EnableAsync

func (s *ReminderAsyncService) EnableAsync(enabled bool)

EnableAsync enables or disables async queue processing

func (*ReminderAsyncService) GetQueueStats

func (s *ReminderAsyncService) GetQueueStats(ctx context.Context) (*models.EmailQueueStats, error)

GetQueueStats returns current email queue statistics

func (*ReminderAsyncService) GetReminderHistory

func (s *ReminderAsyncService) GetReminderHistory(ctx context.Context, docID string) ([]*models.ReminderLog, error)

GetReminderHistory retrieves complete email send log with success/failure tracking

func (*ReminderAsyncService) GetReminderStats

func (s *ReminderAsyncService) GetReminderStats(ctx context.Context, docID string) (*models.ReminderStats, error)

GetReminderStats retrieves aggregated reminder metrics for monitoring dashboard

func (*ReminderAsyncService) SendReminders

func (s *ReminderAsyncService) SendReminders(
	ctx context.Context,
	docID string,
	sentBy string,
	specificEmails []string,
	docURL string,
	locale string,
) (*models.ReminderSendResult, error)

SendReminders is a compatibility method that calls SendRemindersAsync This allows the service to work with existing interfaces expecting SendReminders

func (*ReminderAsyncService) SendRemindersAsync

func (s *ReminderAsyncService) SendRemindersAsync(
	ctx context.Context,
	docID string,
	sentBy string,
	specificEmails []string,
	docURL string,
	locale string,
) (*models.ReminderSendResult, error)

SendRemindersAsync dispatches email notifications to queue for async processing

type ReminderService

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

ReminderService manages email notifications to pending signers with delivery tracking

func NewReminderService

func NewReminderService(
	expectedSignerRepo expectedSignerRepository,
	reminderRepo reminderRepository,
	emailSender email.Sender,
	magicLinkService magicLinkService,
	i18nService *i18n.I18n,
	baseURL string,
) *ReminderService

NewReminderService initializes reminder service with email sender and repository dependencies

func (*ReminderService) GetReminderHistory

func (s *ReminderService) GetReminderHistory(ctx context.Context, docID string) ([]*models.ReminderLog, error)

GetReminderHistory retrieves complete email send log with success/failure tracking

func (*ReminderService) GetReminderStats

func (s *ReminderService) GetReminderStats(ctx context.Context, docID string) (*models.ReminderStats, error)

GetReminderStats retrieves aggregated reminder metrics for monitoring dashboard

func (*ReminderService) SendReminders

func (s *ReminderService) SendReminders(
	ctx context.Context,
	docID string,
	sentBy string,
	specificEmails []string,
	docURL string,
	locale string,
) (*models.ReminderSendResult, error)

SendReminders dispatches email notifications to all or selected pending signers with result aggregation

type SignatureService

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

SignatureService orchestrates signature creation with Ed25519 cryptography and hash chain linking

func NewSignatureService

func NewSignatureService(repo repository, docRepo documentRepository, signer cryptoSigner) *SignatureService

NewSignatureService initializes the signature service with repository and cryptographic signer dependencies

func (*SignatureService) CheckUserSignature

func (s *SignatureService) CheckUserSignature(ctx context.Context, docID, userIdentifier string) (bool, error)

CheckUserSignature verifies signature existence using flexible identifier matching (email or OAuth subject)

func (*SignatureService) CreateSignature

func (s *SignatureService) CreateSignature(ctx context.Context, request *models.SignatureRequest) error

CreateSignature validates user authorization, generates cryptographic proof, and chains to previous signature

func (*SignatureService) GetDocumentSignatures

func (s *SignatureService) GetDocumentSignatures(ctx context.Context, docID string) ([]*models.Signature, error)

GetDocumentSignatures retrieves all cryptographic signatures associated with a document for public verification

func (*SignatureService) GetSignatureByDocAndUser

func (s *SignatureService) GetSignatureByDocAndUser(ctx context.Context, docID string, user *models.User) (*models.Signature, error)

GetSignatureByDocAndUser retrieves a specific signature record for verification or display purposes

func (*SignatureService) GetSignatureStatus

func (s *SignatureService) GetSignatureStatus(ctx context.Context, docID string, user *models.User) (*models.SignatureStatus, error)

GetSignatureStatus checks if a user has already signed a document and returns signature timestamp if exists

func (*SignatureService) GetUserSignatures

func (s *SignatureService) GetUserSignatures(ctx context.Context, user *models.User) ([]*models.Signature, error)

GetUserSignatures retrieves all documents signed by a specific user for personal dashboard display

func (*SignatureService) RebuildChain

func (s *SignatureService) RebuildChain(ctx context.Context) error

RebuildChain recalculates and updates prev_hash pointers for existing signatures during migration

func (*SignatureService) SetChecksumConfig

func (s *SignatureService) SetChecksumConfig(cfg *config.ChecksumConfig)

SetChecksumConfig sets the checksum configuration for document verification

func (*SignatureService) VerifyChainIntegrity

func (s *SignatureService) VerifyChainIntegrity(ctx context.Context) (*ChainIntegrityResult, error)

VerifyChainIntegrity validates the cryptographic hash chain across all signatures for tamper detection

type WebhookPublisher

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

WebhookPublisher publishes events to active webhooks via delivery queue

func NewWebhookPublisher

func NewWebhookPublisher(repo webhookRepo, deliveries webhookDeliveryRepo) *WebhookPublisher

func (*WebhookPublisher) Publish

func (p *WebhookPublisher) Publish(ctx context.Context, eventType string, payload map[string]interface{}) error

Publish enqueues deliveries for all webhooks subscribed to the event

type WebhookService

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

WebhookService handles webhook management and delivery operations

func NewWebhookService

func NewWebhookService(webhookRepo webhookRepository, deliveryRepo webhookDeliveryRepository) *WebhookService

NewWebhookService creates a new webhook service

func (*WebhookService) CreateWebhook

func (s *WebhookService) CreateWebhook(ctx context.Context, input models.WebhookInput) (*models.Webhook, error)

CreateWebhook creates a new webhook

func (*WebhookService) DeleteWebhook

func (s *WebhookService) DeleteWebhook(ctx context.Context, id int64) error

DeleteWebhook deletes a webhook

func (*WebhookService) EnqueueDelivery

EnqueueDelivery enqueues a webhook delivery

func (*WebhookService) GetWebhookByID

func (s *WebhookService) GetWebhookByID(ctx context.Context, id int64) (*models.Webhook, error)

GetWebhookByID retrieves a webhook by ID

func (*WebhookService) ListActiveWebhooksByEvent

func (s *WebhookService) ListActiveWebhooksByEvent(ctx context.Context, event string) ([]*models.Webhook, error)

ListActiveWebhooksByEvent retrieves active webhooks for a specific event

func (*WebhookService) ListDeliveries

func (s *WebhookService) ListDeliveries(ctx context.Context, webhookID int64, limit, offset int) ([]*models.WebhookDelivery, error)

ListDeliveries retrieves delivery history for a webhook

func (*WebhookService) ListWebhooks

func (s *WebhookService) ListWebhooks(ctx context.Context, limit, offset int) ([]*models.Webhook, error)

ListWebhooks retrieves all webhooks with pagination

func (*WebhookService) SetWebhookActive

func (s *WebhookService) SetWebhookActive(ctx context.Context, id int64, active bool) error

SetWebhookActive enables or disables a webhook

func (*WebhookService) UpdateWebhook

func (s *WebhookService) UpdateWebhook(ctx context.Context, id int64, input models.WebhookInput) (*models.Webhook, error)

UpdateWebhook updates an existing webhook

Jump to

Keyboard shortcuts

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