store

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const LocalWorkspaceID = "00000000-0000-0000-0000-000000000001"

LocalWorkspaceID is the fixed workspace ID used in local (single-tenant) mode.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttemptLog

type AttemptLog struct {
	Status      int    `json:"status"`
	DurationMs  int    `json:"duration_ms"`
	Response    string `json:"response"`
	Error       string `json:"error,omitempty"`
	AttemptedAt string `json:"attempted_at"`
}

type Feedback added in v1.2.0

type Feedback struct {
	ID          string    `json:"id"`
	WorkspaceID *string   `json:"workspace_id,omitempty"`
	UserID      *string   `json:"user_id,omitempty"`
	WhatTried   string    `json:"what_tried"`
	Worked      string    `json:"worked"`
	Missing     string    `json:"missing"`
	Email       string    `json:"email"`
	UserAgent   string    `json:"user_agent"`
	PageURL     string    `json:"page_url"`
	CreatedAt   time.Time `json:"created_at"`
}

Feedback is an in-app user submission. Public endpoint, so all identity fields are nullable — anonymous docs visitors can submit too.

type RequestLog

type RequestLog struct {
	ID            string  `json:"id"`
	WorkspaceID   string  `json:"workspace_id"`
	ScenarioRunID *string `json:"scenario_run_id,omitempty"`
	// ScenarioID is the scenario that drove this request's response, when
	// one was resolved (via X-TestPay-Scenario-ID header, active session, or
	// workspace default). Nil when the fallback "always succeed" scenario
	// fired.
	ScenarioID *string `json:"scenario_id,omitempty"`
	// MerchantOrderID is the caller's reference pulled from the request body
	// (order_id / merchant_order_id / metadata.order_id / notes.reference).
	// Empty string when the payload didn't include one.
	MerchantOrderID string            `json:"merchant_order_id"`
	Gateway         string            `json:"gateway"`
	Method          string            `json:"method"`
	Path            string            `json:"path"`
	RequestHeaders  map[string]string `json:"request_headers"`
	RequestBody     map[string]any    `json:"request_body"`
	ResponseHeaders map[string]string `json:"response_headers"`
	ResponseBody    map[string]any    `json:"response_body"`
	ResponseStatus  int               `json:"response_status"`
	DurationMs      int               `json:"duration_ms"`
	ClientIP        string            `json:"client_ip"`
	CreatedAt       time.Time         `json:"created_at"`
}

type Scenario

type Scenario struct {
	ID             string    `json:"id"`
	WorkspaceID    string    `json:"workspace_id"`
	Name           string    `json:"name"`
	Description    string    `json:"description"`
	Gateway        string    `json:"gateway"`
	Steps          []Step    `json:"steps"`
	WebhookDelayMs int       `json:"webhook_delay_ms"`
	IsDefault      bool      `json:"is_default"`
	CreatedAt      time.Time `json:"created_at"`
}

type ScenarioRun

type ScenarioRun struct {
	ID          string     `json:"id"`
	ScenarioID  string     `json:"scenario_id"`
	Status      string     `json:"status"` // running | completed | failed
	StartedAt   time.Time  `json:"started_at"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
}

type Session

type Session struct {
	ID          string    `json:"id"`
	WorkspaceID string    `json:"workspace_id"`
	ScenarioID  string    `json:"scenario_id"`
	TTLSeconds  int       `json:"ttl_seconds"`
	ExpiresAt   time.Time `json:"expires_at"`
	// CallIndex tracks how many live mock calls this session has served.
	// mock.go uses it to advance through multi-step scenarios:
	//   stepIndex = call_index % len(steps)
	CallIndex int       `json:"call_index"`
	CreatedAt time.Time `json:"created_at"`
}

type Step

type Step struct {
	Event   string `json:"event"`
	Outcome string `json:"outcome"`
	Code    string `json:"code,omitempty"`
}

type Store

type Store interface {
	// Workspace
	CreateWorkspace(ctx context.Context, w *Workspace) error
	GetWorkspaceByAPIKey(ctx context.Context, apiKey string) (*Workspace, error)
	GetWorkspaceBySlug(ctx context.Context, slug string) (*Workspace, error)
	GetWorkspaceByID(ctx context.Context, id string) (*Workspace, error)
	UpdateWorkspace(ctx context.Context, w *Workspace) error

	// Scenarios
	ListScenarios(ctx context.Context, workspaceID string) ([]*Scenario, error)
	CreateScenario(ctx context.Context, s *Scenario) error
	GetScenario(ctx context.Context, id string) (*Scenario, error)
	UpdateScenario(ctx context.Context, s *Scenario) error
	DeleteScenario(ctx context.Context, id string) error
	GetDefaultScenario(ctx context.Context, workspaceID string) (*Scenario, error)

	// ScenarioRuns
	CreateScenarioRun(ctx context.Context, r *ScenarioRun) error
	UpdateScenarioRun(ctx context.Context, r *ScenarioRun) error

	// Sessions
	CreateSession(ctx context.Context, s *Session) error
	GetActiveSession(ctx context.Context, workspaceID string) (*Session, error)
	DeleteSession(ctx context.Context, id string) error
	// BumpSessionCallIndex atomically increments the session's call_index and
	// returns the PRE-bump value. Used by the mock handler to resolve which
	// step of a multi-step scenario the current call corresponds to.
	BumpSessionCallIndex(ctx context.Context, sessionID string) (int, error)

	// RequestLogs
	CreateRequestLog(ctx context.Context, l *RequestLog) error
	ListRequestLogs(ctx context.Context, workspaceID string, limit, offset int) ([]*RequestLog, error)
	GetRequestLog(ctx context.Context, id string) (*RequestLog, error)
	// CountRequestsSince returns the number of request_logs rows for the
	// given workspace created at-or-after `since`. Used for per-workspace
	// daily quota enforcement on the mock path.
	CountRequestsSince(ctx context.Context, workspaceID string, since time.Time) (int, error)
	// TrimOldLogs deletes request_logs older than `cutoff`. Webhook logs
	// cascade via the request_log_id FK.
	TrimOldLogs(ctx context.Context, cutoff time.Time) (int64, error)

	// WebhookLogs
	CreateWebhookLog(ctx context.Context, l *WebhookLog) error
	UpdateWebhookLog(ctx context.Context, l *WebhookLog) error
	GetWebhookLogByRequestID(ctx context.Context, requestLogID string) (*WebhookLog, error)
	GetWebhookLog(ctx context.Context, id string) (*WebhookLog, error)
	ListWebhookLogs(ctx context.Context, workspaceID string, limit, offset int) ([]*WebhookLog, error)

	// Feedback
	CreateFeedback(ctx context.Context, f *Feedback) error

	// Users
	CreateUser(ctx context.Context, u *User, passwordHash string) error
	GetUserByEmail(ctx context.Context, email string) (*User, string, error)
	GetUserByID(ctx context.Context, id string) (*User, error)
	UpdateUserLastLogin(ctx context.Context, id string, at time.Time) error
}

type User

type User struct {
	ID          string    `json:"id"`
	WorkspaceID string    `json:"workspace_id"`
	Email       string    `json:"email"`
	Role        string    `json:"role"`
	CreatedAt   time.Time `json:"created_at"`
}

type WebhookLog

type WebhookLog struct {
	ID             string         `json:"id"`
	RequestLogID   string         `json:"request_log_id"`
	Payload        map[string]any `json:"payload"`
	TargetURL      string         `json:"target_url"`
	DeliveryStatus string         `json:"delivery_status"` // pending | delivered | failed | duplicate
	Attempts       int            `json:"attempts"`
	AttemptLogs    []AttemptLog   `json:"attempt_logs"`
	DeliveredAt    *time.Time     `json:"delivered_at,omitempty"`
	CreatedAt      time.Time      `json:"created_at"`
}

type Workspace

type Workspace struct {
	ID          string            `json:"id"`
	Slug        string            `json:"slug"`
	APIKey      string            `json:"api_key"`
	WebhookURLs map[string]string `json:"webhook_urls"`
	// MaxDailyRequests caps mock-endpoint calls per 24h window.
	// nil = unlimited (default for authenticated workspaces).
	// The seeded "local" workspace gets a low cap so anonymous demo
	// traffic can't drain the free-tier quotas.
	MaxDailyRequests *int      `json:"max_daily_requests,omitempty"`
	CreatedAt        time.Time `json:"created_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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