Add session mode: signing in and adding to the cart.
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>
This commit is contained in:
1 parent
e2cbc1a55c
commit
15a34e1f84
39 files changed
+3529
-163
No files matched your search
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
-- A plugin for the session tests. Its add_to_cart reads what to do from the
|
||||
-- URL's path.
|
||||
return {
|
||||
name = "shop",
|
||||
|
||||
session_warning = "Automated logins can lock the account.",
|
||||
|
||||
parse = function(doc, url)
|
||||
return { available = true }
|
||||
end,
|
||||
|
||||
login = function(ctx, account)
|
||||
local page = ctx:get(account.site .. "signin")
|
||||
local code = ctx:prompt("code for " .. account.username, true)
|
||||
|
||||
page = ctx:post(account.site .. "signin", {
|
||||
form = { user = account.username, password = account.password, code = code },
|
||||
referer = page.url,
|
||||
})
|
||||
|
||||
if page.doc:text("#result") ~= "welcome" then error("refused: " .. tostring(page.doc:text("#result")), 0) end
|
||||
if ctx:cookies().session ~= "yes" then error("no session cookie", 0) end
|
||||
end,
|
||||
|
||||
add_to_cart = function(ctx, url)
|
||||
local what = url:match("/(%a+)$")
|
||||
local site = ctx.account.site
|
||||
|
||||
if ctx.account.password then error("ctx.account has the password", 0) end
|
||||
|
||||
if what == "signedout" then return false end
|
||||
if what == "nonsense" then return "yes" end
|
||||
|
||||
if what == "click" then
|
||||
local page = ctx:click(site .. "item", "#add")
|
||||
return page.headers["x-cart"] == "1", site .. "cart"
|
||||
end
|
||||
|
||||
local page = ctx:post(site .. "cart", { form = { id = "X", quantity = 1 }, headers = { ["X-Test"] = "yes" } })
|
||||
|
||||
return page.status == 200 and page.headers["x-cart"] == "1", site .. "cart"
|
||||
end,
|
||||
}
|
||||
Reference in new issue
Block a user