extension

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package extension implements the pending-actions queue for browser extension polling. Backend pushes "open this site" requests; extension polls every 30s, executes, acks.

Index

Constants

View Source
const DefaultTTL = 24 * time.Hour

DefaultTTL is the time-to-live for an action before it expires (R-EC10).

Variables

This section is empty.

Functions

func Ack

func Ack(db *gorm.DB, actionID uint) error

Ack marks an action as acknowledged. Calling Ack twice on the same actionID is a no-op (idempotent) — second call returns nil so callers can retry safely.

func AutoMigrate

func AutoMigrate(db *gorm.DB) error

AutoMigrate creates or updates the pending_actions table. Safe to call multiple times.

func Enqueue

func Enqueue(db *gorm.DB, action PendingAction) error

Enqueue inserts a new pending action. CreatedAt and ExpiresAt are populated automatically when zero (24h TTL per R-EC10).

func PurgeExpired

func PurgeExpired(db *gorm.DB, now time.Time) (int64, error)

PurgeExpired deletes actions whose ExpiresAt is on or before now. Returns the number of rows deleted. Safe to call repeatedly.

Types

type PendingAction

type PendingAction struct {
	ID        uint              `gorm:"primaryKey" json:"id"`
	Type      PendingActionType `gorm:"size:32;not null" json:"type"`
	TargetURL string            `gorm:"size:1024;not null" json:"target_url"`
	SiteName  string            `gorm:"size:64;index" json:"site_name"`
	Reason    string            `gorm:"size:256" json:"reason"`
	CreatedAt time.Time         `gorm:"index" json:"created_at"`
	AckedAt   *time.Time        `json:"acked_at,omitempty"`
	ExpiresAt time.Time         `gorm:"index" json:"expires_at"`
}

PendingAction is a unit of work that the backend queues for the browser extension to execute on its next poll. Cookies and credentials never appear here — only a target URL plus a human-readable reason.

func ListPending

func ListPending(db *gorm.DB, sinceUnix int64) ([]PendingAction, error)

ListPending returns unacked, unexpired actions whose CreatedAt is strictly greater than sinceUnix. sinceUnix=0 means "all unacked + unexpired". Results are ordered by CreatedAt ascending so the extension processes oldest-first.

func (PendingAction) TableName

func (PendingAction) TableName() string

TableName pins the GORM table name so it remains stable even if the package path changes.

type PendingActionType

type PendingActionType string

PendingActionType enumerates supported action kinds for the extension.

const (
	// ActionOpenTab instructs the extension to open the target URL in a
	// background tab so the user can refresh login / cookies.
	ActionOpenTab PendingActionType = "open_tab"
)

Jump to

Keyboard shortcuts

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