Documentation
¶
Overview ¶
Package engine executes bank DSL flows against a real browser over CDP.
Index ¶
- func FindBrowser() (string, bool)
- func InDocker() bool
- func MapOffers(bankID, cardLabel string, doc []byte, ex *config.Extract, scrapedAt time.Time) ([]offer.Offer, error)
- func OfferID(o offer.Offer) string
- func PreflightFailed(checks []Check) bool
- type Browser
- type Check
- type Client
- func (c *Client) Answers(ctx context.Context, ids []int64) ([]store.Answer, error)
- func (c *Client) AskHumanRemote(ctx context.Context, user, bank, prompt string) (int64, error)
- func (c *Client) Ingest(ctx context.Context, req IngestReq) error
- func (c *Client) SetBankStatus(ctx context.Context, user, bank, status, note string) error
- type Gate
- type IngestReq
- type PreflightOpts
- type Result
- type Runner
- type ServerGate
- type StdinGate
- type StoreGate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindBrowser ¶
FindBrowser resolves the Chromium binary the same way launch() does.
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 PreflightFailed ¶
PreflightFailed reports whether any check is a hard failure.
Types ¶
type Browser ¶
type Browser interface {
// 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 ¶
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 (*Client) AskHumanRemote ¶
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.
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.
type ServerGate ¶
ServerGate implements Gate by relaying prompts to the serve instance and polling for the human's answer (outbound-only).
type StdinGate ¶
type StdinGate struct{}
StdinGate prompts on the terminal — headful single-machine UX.