web

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 37 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

Index

Constants

View Source
const (
	AuditActionLogin           = "auth.login"
	AuditActionLogout          = "auth.logout"
	AuditActionDocumentCreate  = "document.create"
	AuditActionDocumentUpdate  = "document.update"
	AuditActionDocumentDelete  = "document.delete"
	AuditActionSignatureCreate = "signature.create"
	AuditActionReminderSend    = "reminder.send"
	AuditActionWebhookCreate   = "webhook.create"
	AuditActionWebhookUpdate   = "webhook.update"
	AuditActionWebhookDelete   = "webhook.delete"
	AuditActionSignerAdd       = "signer.add"
	AuditActionSignerRemove    = "signer.remove"
	AuditActionAdminAccess     = "admin.access"
)

AuditAction constants for common audit events.

Variables

View Source
var (
	ErrNotAuthenticated = errors.New("user not authenticated")
	ErrNotAuthorized    = errors.New("user not authorized")
	ErrQuotaExceeded    = errors.New("quota exceeded")
	ErrProviderDisabled = errors.New("provider is disabled")
)

Common errors for capability providers.

Functions

func EmbedDocumentMiddleware

func EmbedDocumentMiddleware(
	docService docService,
	publisher webhookPublisher,
) func(http.Handler) http.Handler

EmbedDocumentMiddleware creates documents on /embed access with strict rate limiting This ensures documents exist before the SPA renders, without requiring authentication The docServiceFn should be a function that calls FindOrCreateDocument

func EmbedFolder

func EmbedFolder(fsEmbed embed.FS, targetPath string, baseURL string, version string, signatureRepo SignatureRepository) http.HandlerFunc

EmbedFolder returns an http.HandlerFunc that serves an embedded filesystem with SPA fallback support (serves index.html for non-existent routes). Only BASE_URL and VERSION are injected - other config is loaded via /api/v1/config.

Types

type AuditEvent

type AuditEvent struct {
	Timestamp  time.Time
	TenantID   string
	UserEmail  string
	UserSub    string
	Action     string
	Resource   string
	ResourceID string
	Details    map[string]any
	IPAddress  string
	UserAgent  string
}

AuditEvent represents an auditable action in the system.

type AuditLogger

type AuditLogger interface {
	// Log records an audit event.
	Log(ctx context.Context, event AuditEvent) error
}

AuditLogger defines the interface for audit logging. CE: LogOnlyAuditLogger (logs to standard logger). SaaS: DatabaseAuditLogger (stores in database with search/export).

type AuthProvider

type AuthProvider = providers.AuthProvider

Re-export types from pkg/providers for convenience.

type AuthResult

type AuthResult struct {
	User        *User
	RedirectURL string
}

AuthResult represents the result of an authentication operation.

type Authorizer

type Authorizer = providers.Authorizer

type ConfigProvider

type ConfigProvider interface {
	GetConfig() *models.MutableConfig
}

ConfigProvider provides dynamic configuration values.

type CryptoSigner added in v1.3.9

type CryptoSigner interface {
	CreateSignature(ctx context.Context, docID string, user *User, timestamp time.Time, nonce string, docChecksum string) (payloadHash string, signature string, err error)
}

CryptoSigner provides cryptographic signature operations for read confirmations. Implement this interface to override the default Ed25519Signer (e.g., per-tenant keys).

type LogOnlyAuditLogger

type LogOnlyAuditLogger struct{}

LogOnlyAuditLogger logs audit events to the standard logger. This is the default for Community Edition.

func NewLogOnlyAuditLogger

func NewLogOnlyAuditLogger() *LogOnlyAuditLogger

func (*LogOnlyAuditLogger) Log

type MagicLinkProvider

type MagicLinkProvider = providers.MagicLinkProvider

type MagicLinkResult

type MagicLinkResult = providers.MagicLinkResult

type NoLimitQuotaEnforcer

type NoLimitQuotaEnforcer struct{}

NoLimitQuotaEnforcer is a quota enforcer that imposes no limits. This is the default for Community Edition.

func NewNoLimitQuotaEnforcer

func NewNoLimitQuotaEnforcer() *NoLimitQuotaEnforcer

func (*NoLimitQuotaEnforcer) Check

func (*NoLimitQuotaEnforcer) GetUsage

func (e *NoLimitQuotaEnforcer) GetUsage(_ context.Context, tenantID string) (*QuotaUsage, error)

func (*NoLimitQuotaEnforcer) Record

type QuotaAction

type QuotaAction string

QuotaAction represents an action that can be quota-limited.

const (
	QuotaActionCreateDocument    QuotaAction = "document.create"
	QuotaActionDeleteDocument    QuotaAction = "document.delete"
	QuotaActionCreateSignature   QuotaAction = "signature.create"
	QuotaActionSendReminder      QuotaAction = "reminder.send"
	QuotaActionCreateWebhook     QuotaAction = "webhook.create"
	QuotaActionAddExpectedSigner QuotaAction = "signer.add"
	QuotaActionWebhookDelivery   QuotaAction = "webhook.delivery"
)

type QuotaEnforcer

type QuotaEnforcer interface {
	// Check verifies if the action is allowed under current quotas.
	Check(ctx context.Context, tenantID string, action QuotaAction) error

	// Record records that an action was performed.
	Record(ctx context.Context, tenantID string, action QuotaAction) error

	// GetUsage returns the current usage metrics for a tenant.
	GetUsage(ctx context.Context, tenantID string) (*QuotaUsage, error)
}

QuotaEnforcer defines the interface for quota management. CE: NoLimitQuotaEnforcer (no limits). SaaS: PlanBasedQuotaEnforcer (limits based on subscription plan).

type QuotaUsage

type QuotaUsage struct {
	TenantID   string
	Period     string // e.g., "2024-01" for monthly quotas
	Documents  UsageMetric
	Signatures UsageMetric
	Reminders  UsageMetric
	Webhooks   UsageMetric
}

QuotaUsage represents current usage metrics for a tenant.

type Server

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

func (*Server) ConfigService

func (s *Server) ConfigService() *services.ConfigService

ConfigService returns the internal ConfigService for multi-tenant overrides. In SaaS mode, callers can use Reload(ctx) to refresh config from the DB for the current tenant before reading it.

func (*Server) GetAddr

func (s *Server) GetAddr() string

func (*Server) GetAuditLogger

func (s *Server) GetAuditLogger() AuditLogger

func (*Server) GetAuthProvider

func (s *Server) GetAuthProvider() AuthProvider

func (*Server) GetAuthorizer

func (s *Server) GetAuthorizer() Authorizer

func (*Server) GetDB

func (s *Server) GetDB() *sql.DB

func (*Server) GetEmailSender

func (s *Server) GetEmailSender() email.Sender

func (*Server) GetMagicLinkProvider

func (s *Server) GetMagicLinkProvider() MagicLinkProvider

func (*Server) GetQuotaEnforcer

func (s *Server) GetQuotaEnforcer() QuotaEnforcer

func (*Server) RegisterRoutes

func (s *Server) RegisterRoutes(fn func(r *chi.Mux))

func (*Server) Router

func (s *Server) Router() *chi.Mux

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Start

func (s *Server) Start() error

type ServerBuilder

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

ServerBuilder allows dependency injection for extensibility. DB and TenantProvider are REQUIRED. AuthProvider and Authorizer have sensible CE defaults (AuthProvider, SimpleAuthorizer). QuotaEnforcer and AuditLogger have sensible CE defaults (NoLimit, LogOnly). All technical services (I18n, Email, MagicLink, Reminder, Config) are created internally.

func NewServerBuilder

func NewServerBuilder(cfg *config.Config, frontend embed.FS, version string) *ServerBuilder

func (*ServerBuilder) Build

func (b *ServerBuilder) Build(ctx context.Context) (*Server, error)

Build constructs the server with all dependencies.

func (*ServerBuilder) WithAuditLogger

func (b *ServerBuilder) WithAuditLogger(logger AuditLogger) *ServerBuilder

WithAuditLogger injects an audit logger (optional, defaults to LogOnly).

func (*ServerBuilder) WithAuthProvider

func (b *ServerBuilder) WithAuthProvider(provider AuthProvider) *ServerBuilder

WithAuthProvider injects an authentication provider (REQUIRED).

func (*ServerBuilder) WithAuthorizer

func (b *ServerBuilder) WithAuthorizer(authorizer Authorizer) *ServerBuilder

WithAuthorizer injects an authorizer (REQUIRED).

func (*ServerBuilder) WithBaseURLProvider

func (b *ServerBuilder) WithBaseURLProvider(p services.BaseURLProvider) *ServerBuilder

func (*ServerBuilder) WithCryptoSigner added in v1.3.9

func (b *ServerBuilder) WithCryptoSigner(s CryptoSigner) *ServerBuilder

WithCryptoSigner injects a custom cryptographic signer (optional). When set, the builder skips creating the default Ed25519Signer from env.

func (*ServerBuilder) WithDB

func (b *ServerBuilder) WithDB(db *sql.DB) *ServerBuilder

WithDB injects a database connection (REQUIRED).

func (*ServerBuilder) WithQuotaEnforcer

func (b *ServerBuilder) WithQuotaEnforcer(enforcer QuotaEnforcer) *ServerBuilder

WithQuotaEnforcer injects a quota enforcer (optional, defaults to NoLimit).

func (*ServerBuilder) WithStorageProvider

func (b *ServerBuilder) WithStorageProvider(p storage.Provider) *ServerBuilder

WithStorageProvider injects an external storage provider (optional). When set, the builder will not create its own storage provider from config.

func (*ServerBuilder) WithStorageQuotaChecker

func (b *ServerBuilder) WithStorageQuotaChecker(checker StorageQuotaChecker) *ServerBuilder

WithStorageQuotaChecker injects a storage quota checker (optional).

func (*ServerBuilder) WithTenantProvider

func (b *ServerBuilder) WithTenantProvider(tp providers.TenantProvider) *ServerBuilder

WithTenantProvider injects a tenant provider (REQUIRED).

type SignatureRepository

type SignatureRepository interface {
	GetByDoc(ctx context.Context, docID string) ([]*models.Signature, error)
}

SignatureRepository defines minimal signature operations for meta tags

type StorageQuotaChecker

type StorageQuotaChecker interface {
	// CheckStorageQuota returns an error if the upload would exceed the storage quota.
	CheckStorageQuota(ctx context.Context, tenantID string, fileSize int64) error
}

StorageQuotaChecker verifies storage quota before file upload. CE: nil (no storage quota). SaaS: PlanBasedStorageQuotaChecker (limits based on subscription plan).

type UsageMetric

type UsageMetric struct {
	Used  int64
	Limit int64 // -1 means unlimited
}

UsageMetric represents usage for a single resource type.

func (UsageMetric) IsExceeded

func (m UsageMetric) IsExceeded() bool

IsExceeded returns true if usage has exceeded the limit.

func (UsageMetric) IsUnlimited

func (m UsageMetric) IsUnlimited() bool

IsUnlimited returns true if the metric has no limit.

func (UsageMetric) Remaining

func (m UsageMetric) Remaining() int64

Remaining returns the remaining quota, or -1 if unlimited.

type User

type User = types.User

User is an alias for the unified user type. This allows web package to use web.User while sharing the same underlying type.

Directories

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

Jump to

Keyboard shortcuts

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