engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine executes bank DSL flows against a real browser over CDP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindBrowser

func FindBrowser() (string, bool)

FindBrowser resolves the Chromium binary the same way launch() does.

func InDocker

func InDocker() bool

InDocker reports whether we appear to run inside a container.

func MapOffers

func MapOffers(bankID, cardLabel string, doc []byte, ex *config.Extract, scrapedAt time.Time) ([]offer.Offer, error)

MapOffers converts a JSON document (raw bytes) into normalized offers using the extract spec. cardLabel is stamped on every offer.

func OfferID

func OfferID(o offer.Offer) string

OfferID derives a stable id from the business key.

func PreflightFailed

func PreflightFailed(checks []Check) bool

PreflightFailed reports whether any check is a hard failure.

Types

type Browser

type Browser interface {
	Navigate(ctx context.Context, url string) error
	// EvaluateJSON evaluates an async JS expression, awaiting the promise
	// and returning the JSON-stringified result.
	EvaluateJSON(ctx context.Context, expr string) (string, error)
	WaitFor(ctx context.Context, sel, jsPath string, mustExist bool, timeout time.Duration) error
	Click(ctx context.Context, sel, jsPath string, trusted bool, timeout time.Duration) error
	Fill(ctx context.Context, sel, jsPath, value string) error
	CurrentURL(ctx context.Context) (string, error)
	Close()
}

Browser abstracts the driver so flows can be unit tested against fakes.

func NewBrowser

func NewBrowser(b config.BrowserConfig, baseURL string) (Browser, error)

NewBrowser builds a Browser for the bank's config: either launches a dedicated Chrome (headless/headful, persistent profile) or attaches to an already-running one via its CDP URL.

type Check

type Check struct {
	Name   string `json:"name"`
	Status string `json:"status"` // ok|warn|fail
	Detail string `json:"detail"`
	Hint   string `json:"hint,omitempty"`
}

Check is one preflight result.

func Preflight

func Preflight(o PreflightOpts) []Check

Preflight runs every environment check. Failures are advisory except where they make the requested operation impossible.

type Client

type Client struct {
	Base  string
	Token string
	HTTP  *http.Client
}

Client talks to an offerhound serve instance. The server is dumb: this client pushes whenever it wants (cron, manual sync). Writes carry the plaintext token; the server stores only its hash.

func NewClient

func NewClient(base, token string) *Client

NewClient builds a client with sane timeouts.

func (*Client) Answers

func (c *Client) Answers(ctx context.Context, ids []int64) ([]store.Answer, error)

Answers fetches delivered answers for the given request ids.

func (*Client) AskHumanRemote

func (c *Client) AskHumanRemote(ctx context.Context, user, bank, prompt string) (int64, error)

AskHumanRemote registers a 2FA prompt on the server (surfaced in the UI). Only the config-authored prompt text is sent — never screenshots or page content, which could carry account PII.

func (*Client) Ingest

func (c *Client) Ingest(ctx context.Context, req IngestReq) error

Ingest pushes a completed (or partial) collection into one wallet.

func (*Client) SetBankStatus

func (c *Client) SetBankStatus(ctx context.Context, user, bank, status, note string) error

SetBankStatus reports a client-side outcome (needs_you, error).

type Gate

type Gate interface {
	// Ask blocks until a human answers, the timeout fires, or ctx cancels.
	// Only the config-authored prompt string is relayed — never page
	// content, which could carry account PII.
	Ask(ctx context.Context, bank, prompt string, timeout time.Duration) (string, error)
}

Gate pauses a run for a human (SMS/push/captcha). Implementations: CLI stdin prompt, web UI (via store), or remote relay.

type IngestReq

type IngestReq struct {
	User     string        `json:"user"`
	Bank     string        `json:"bank"`
	Worker   string        `json:"worker"`
	Complete bool          `json:"complete"`
	Note     string        `json:"note"`
	Cards    []offer.Card  `json:"cards"`
	Offers   []offer.Offer `json:"offers"`
}

IngestReq is the payload for POST /api/ingest.

type PreflightOpts

type PreflightOpts struct {
	Banks     []config.Bank // loaded configs (may be empty)
	Live      bool          // actually launch Chromium (slower, thorough)
	HTTPProbe string        // optional URL that must answer 200 (serve healthcheck)
}

PreflightOpts configures the doctor run.

func (PreflightOpts) GetenvLike

func (o PreflightOpts) GetenvLike() bool

GetenvLike: CHROME_BIN set but broken counts as a hard fail (the user explicitly pinned a binary that doesn't exist).

type Result

type Result struct {
	Cards      []offer.Card
	Offers     []offer.Offer
	Complete   bool
	SkippedLog []string // per-step non-fatal notes (rate limits, empty sources)
	Err        error
}

Result of a bank sync.

type Runner

type Runner struct {
	Bank    *config.Bank
	Browser Browser
	Gate    Gate      // nil => human steps fail fast
	Log     io.Writer // progress (may be io.Discard)
	Now     func() time.Time
}

Runner executes one bank's flows.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) Result

Run executes login (probe-gated) then all offers steps.

type ServerGate

type ServerGate struct {
	Client *Client
	User   string
	Poll   time.Duration
}

ServerGate implements Gate by relaying prompts to the serve instance and polling for the human's answer (outbound-only).

func (*ServerGate) Ask

func (g *ServerGate) Ask(ctx context.Context, bank, prompt string, timeout time.Duration) (string, error)

type StdinGate

type StdinGate struct{}

StdinGate prompts on the terminal — headful single-machine UX.

func (StdinGate) Ask

func (StdinGate) Ask(_ context.Context, _, prompt string, _ time.Duration) (string, error)

type StoreGate

type StoreGate struct {
	Store *store.Store
	User  string
}

StoreGate blocks on a store-backed human request (local single-machine runs; remote runs use ServerGate in client.go).

func (*StoreGate) Ask

func (g *StoreGate) Ask(ctx context.Context, bank, prompt string, timeout time.Duration) (string, error)

Jump to

Keyboard shortcuts

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