With cart_mode = "session", dibs signs in to the shop's account and puts an item in the cart when it fires. The account's cookies are kept apart from the watcher's and stored encrypted, with the key in the OS keyring. Without a keyring, they're stored in a file only you can read. An alert now goes out right away, without a cart link, and a second one follows once the item is in the cart. If adding fails, the second alert carries the cart link instead. Amazon only accepts additions its page scripts have seen, so plugins can now press a button in headless Chrome with ctx:click. The TUI asks for one-time codes and shows the plugin's warning about account locks in a modal. 'dibs login' signs in from a terminal, or with --browser in a Chrome window, and 'dibs logout' deletes the cookies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
3.4 KiB
Go
103 lines
3.4 KiB
Go
package notify
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.security-command.org/Overlord/dibs/internal/alert"
|
|
)
|
|
|
|
// PayloadVersion changes only when a field is removed or changes meaning.
|
|
// New fields may appear in any version.
|
|
const PayloadVersion = 1
|
|
|
|
// Payload is the body of a "json" webhook, POSTed as application/json.
|
|
//
|
|
// {
|
|
// "version": 1,
|
|
// "test": false,
|
|
// "item": "Metro 2039 CE",
|
|
// "shop": "amazon",
|
|
// "url": "https://www.amazon.de/dp/B0HMX2FSTF",
|
|
// "title": "Metro 2039 Collector's Edition (PS5)",
|
|
// "price": 129.99,
|
|
// "currency": "EUR",
|
|
// "converted_price": null,
|
|
// "converted_currency": null,
|
|
// "previous_price": null,
|
|
// "previous_currency": null,
|
|
// "seller": "first_party",
|
|
// "cart_link": "https://www.amazon.de/gp/aws/cart/add.html?ASIN.1=B0HMX2FSTF&Quantity.1=1",
|
|
// "cart": null,
|
|
// "cart_url": null,
|
|
// "cart_error": null,
|
|
// "time": "2026-10-14T09:30:00Z"
|
|
// }
|
|
//
|
|
// Every key is always present; values that do not apply are null.
|
|
//
|
|
// In session mode, an item that fires sends up to two payloads: one with
|
|
// "cart": "adding" and no cart_link, then one with "cart": "added" and the
|
|
// cart page in cart_url, or "cart": "failed", the reason in cart_error and
|
|
// the cart link.
|
|
type Payload struct {
|
|
Version int `json:"version"`
|
|
// Test is true for the sample alert of `dibs notify test`.
|
|
Test bool `json:"test"`
|
|
Item string `json:"item"`
|
|
Shop string `json:"shop"`
|
|
// URL is the product page.
|
|
URL string `json:"url"`
|
|
Title *string `json:"title"`
|
|
// Price is null when the page shows none, which only fires items without
|
|
// max_price.
|
|
Price *float64 `json:"price"`
|
|
Currency *string `json:"currency"`
|
|
// ConvertedPrice is the price in the item's currency, when the page uses
|
|
// another one.
|
|
ConvertedPrice *float64 `json:"converted_price"`
|
|
ConvertedCurrency *string `json:"converted_currency"`
|
|
// PreviousPrice is set when the item fires again during its cooldown
|
|
// because the price dropped below the previous alert's.
|
|
PreviousPrice *float64 `json:"previous_price"`
|
|
PreviousCurrency *string `json:"previous_currency"`
|
|
// Seller is "first_party", "fulfilled", "third_party" or "unknown".
|
|
Seller string `json:"seller"`
|
|
CartLink *string `json:"cart_link"`
|
|
// Cart is null without session mode, else "adding", "added" or
|
|
// "failed".
|
|
Cart *string `json:"cart"`
|
|
CartURL *string `json:"cart_url"`
|
|
CartError *string `json:"cart_error"`
|
|
// Time is when the page was checked, in UTC.
|
|
Time time.Time `json:"time"`
|
|
}
|
|
|
|
func NewPayload(a alert.Alert) Payload {
|
|
return Payload{
|
|
Version: PayloadVersion,
|
|
Test: a.Test,
|
|
Item: a.Item,
|
|
Shop: a.Shop,
|
|
URL: a.URL,
|
|
Title: orNull(a.Title),
|
|
Price: a.Price,
|
|
Currency: orNull(a.Currency),
|
|
ConvertedPrice: a.Converted,
|
|
ConvertedCurrency: orNull(a.ConvertedCurrency),
|
|
PreviousPrice: a.PreviousPrice,
|
|
PreviousCurrency: orNull(a.PreviousCurrency),
|
|
Seller: a.Seller,
|
|
CartLink: orNull(a.CartLink),
|
|
Cart: orNull(a.Cart),
|
|
CartURL: orNull(a.CartURL),
|
|
CartError: orNull(a.CartError),
|
|
Time: a.Time.UTC().Truncate(time.Second),
|
|
}
|
|
}
|
|
|
|
func orNull(s string) *string {
|
|
if s == "" { return nil }
|
|
|
|
return &s
|
|
}
|