Documentation
¶
Index ¶
- Variables
- type APIKeyStore
- func (s *APIKeyStore) Create(ctx context.Context, tenantID, appID, name, role string) (plaintext string, key *model.APIKey, err error)
- func (s *APIKeyStore) GetByPlaintext(ctx context.Context, plaintext string) (*model.APIKey, error)
- func (s *APIKeyStore) ListByApp(ctx context.Context, appID string) ([]model.APIKey, error)
- func (s *APIKeyStore) Revoke(ctx context.Context, id string) error
- func (s *APIKeyStore) TouchLastUsed(ctx context.Context, id string) error
- type AppStore
- func (s *AppStore) Create(ctx context.Context, a *model.App) error
- func (s *AppStore) Delete(ctx context.Context, id string) error
- func (s *AppStore) Get(ctx context.Context, id string) (*model.App, error)
- func (s *AppStore) GetByEndpoint(ctx context.Context, endpoint string) (*model.App, error)
- func (s *AppStore) ListByTenant(ctx context.Context, tenantID string) ([]model.App, error)
- func (s *AppStore) Update(ctx context.Context, a *model.App) error
- type AuditFilter
- type AuditStore
- type RetentionStore
- type TenantStore
- func (s *TenantStore) Create(ctx context.Context, t *model.Tenant) error
- func (s *TenantStore) Delete(ctx context.Context, id string) error
- func (s *TenantStore) Get(ctx context.Context, id string) (*model.Tenant, error)
- func (s *TenantStore) GetByClerkOrgID(ctx context.Context, clerkOrgID string) (*model.Tenant, error)
- func (s *TenantStore) GetBySlug(ctx context.Context, slug string) (*model.Tenant, error)
- func (s *TenantStore) List(ctx context.Context) ([]model.Tenant, error)
- func (s *TenantStore) Update(ctx context.Context, t *model.Tenant) error
- type UsageStore
- func (s *UsageStore) GetByTenant(ctx context.Context, tenantID string, start, end time.Time) ([]model.UsageRecord, error)
- func (s *UsageStore) GetCurrentPeriodCount(ctx context.Context, tenantID string) (int64, error)
- func (s *UsageStore) GetUnreported(ctx context.Context) ([]model.UsageRecord, error)
- func (s *UsageStore) IncrementRequestCount(ctx context.Context, tenantID, appID string) error
- func (s *UsageStore) MarkReported(ctx context.Context, id string) error
- func (s *UsageStore) PurgeOlderThan(ctx context.Context, tenantID string, before time.Time) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a requested resource does not exist.
Functions ¶
This section is empty.
Types ¶
type APIKeyStore ¶
type APIKeyStore struct {
// contains filtered or unexported fields
}
APIKeyStore handles persistence for APIKey records.
func NewAPIKeyStore ¶
func NewAPIKeyStore(pool *pgxpool.Pool) *APIKeyStore
NewAPIKeyStore creates an APIKeyStore backed by the given pool.
func (*APIKeyStore) Create ¶
func (s *APIKeyStore) Create(ctx context.Context, tenantID, appID, name, role string) (plaintext string, key *model.APIKey, err error)
Create generates a new API key, stores the hash, and returns the plaintext (shown once). The plaintext has the form "cm_live_<32 random hex bytes>".
func (*APIKeyStore) GetByPlaintext ¶
GetByPlaintext hashes plaintext and fetches the matching active (non-revoked, non-expired) key.
func (*APIKeyStore) ListByApp ¶
ListByApp returns all non-revoked keys for the given app with KeyHash cleared.
func (*APIKeyStore) Revoke ¶
func (s *APIKeyStore) Revoke(ctx context.Context, id string) error
Revoke sets revoked_at = now() for the given key.
func (*APIKeyStore) TouchLastUsed ¶
func (s *APIKeyStore) TouchLastUsed(ctx context.Context, id string) error
TouchLastUsed sets last_used_at = now() for the given key.
type AppStore ¶
type AppStore struct {
// contains filtered or unexported fields
}
AppStore handles persistence for App records.
func NewAppStore ¶
NewAppStore creates an AppStore backed by the given pool.
func (*AppStore) GetByEndpoint ¶
GetByEndpoint fetches an app by its endpoint value.
func (*AppStore) ListByTenant ¶
ListByTenant returns all apps for the given tenant, oldest-first.
type AuditFilter ¶
type AuditFilter struct {
TenantID string
ActorID string
Action string
ResourceType string
Limit int
Offset int
}
AuditFilter specifies filter criteria for audit log queries.
type AuditStore ¶
type AuditStore struct {
// contains filtered or unexported fields
}
AuditStore handles persistence for AuditEntry records.
func NewAuditStore ¶
func NewAuditStore(pool *pgxpool.Pool) *AuditStore
NewAuditStore creates an AuditStore backed by the given pool.
func (*AuditStore) Append ¶
func (s *AuditStore) Append(ctx context.Context, e *model.AuditEntry) error
Append inserts a new audit log entry (append-only by design). Metadata is marshalled to JSONB.
func (*AuditStore) Count ¶
func (s *AuditStore) Count(ctx context.Context, f AuditFilter) (int64, error)
Count returns the number of audit log entries matching the filter.
func (*AuditStore) Query ¶
func (s *AuditStore) Query(ctx context.Context, f AuditFilter) ([]model.AuditEntry, error)
Query returns audit log entries matching the filter, ordered newest-first.
type RetentionStore ¶
type RetentionStore struct {
// contains filtered or unexported fields
}
RetentionStore handles persistence for DataRetention records.
func NewRetentionStore ¶
func NewRetentionStore(pool *pgxpool.Pool) *RetentionStore
NewRetentionStore creates a RetentionStore backed by the given pool.
func (*RetentionStore) GetByTenant ¶
func (s *RetentionStore) GetByTenant(ctx context.Context, tenantID string) ([]model.DataRetention, error)
GetByTenant returns all data retention policies for the given tenant.
type TenantStore ¶
type TenantStore struct {
// contains filtered or unexported fields
}
TenantStore handles persistence for Tenant records.
func NewTenantStore ¶
func NewTenantStore(pool *pgxpool.Pool) *TenantStore
NewTenantStore creates a TenantStore backed by the given pool.
func (*TenantStore) Create ¶
Create inserts a new tenant and populates ID, CreatedAt, and UpdatedAt via RETURNING.
func (*TenantStore) Delete ¶
func (s *TenantStore) Delete(ctx context.Context, id string) error
Delete removes a tenant by primary key.
func (*TenantStore) GetByClerkOrgID ¶
func (s *TenantStore) GetByClerkOrgID(ctx context.Context, clerkOrgID string) (*model.Tenant, error)
GetByClerkOrgID fetches a tenant by Clerk organisation ID.
type UsageStore ¶
type UsageStore struct {
// contains filtered or unexported fields
}
UsageStore handles persistence for UsageRecord records.
func NewUsageStore ¶
func NewUsageStore(pool *pgxpool.Pool) *UsageStore
NewUsageStore creates a UsageStore backed by the given pool.
func (*UsageStore) GetByTenant ¶
func (s *UsageStore) GetByTenant(ctx context.Context, tenantID string, start, end time.Time) ([]model.UsageRecord, error)
GetByTenant returns usage records for a tenant within [start, end).
func (*UsageStore) GetCurrentPeriodCount ¶
GetCurrentPeriodCount returns the sum of request_count for the current calendar month.
func (*UsageStore) GetUnreported ¶
func (s *UsageStore) GetUnreported(ctx context.Context) ([]model.UsageRecord, error)
GetUnreported returns all usage records that have not been reported to Stripe and whose period_end is in the past.
func (*UsageStore) IncrementRequestCount ¶
func (s *UsageStore) IncrementRequestCount(ctx context.Context, tenantID, appID string) error
IncrementRequestCount upserts a usage record for the current hourly period. It first tries to UPDATE an existing row; if no row exists it INSERTs one.
func (*UsageStore) MarkReported ¶
func (s *UsageStore) MarkReported(ctx context.Context, id string) error
MarkReported sets reported_to_stripe = true for the given record.
func (*UsageStore) PurgeOlderThan ¶
func (s *UsageStore) PurgeOlderThan(ctx context.Context, tenantID string, before time.Time) (int64, error)
PurgeOlderThan deletes reported usage records older than before for the given tenant. Returns the number of rows deleted.