pub struct Context {
pub config: Config,
pub out: Output,
/* private fields */
}Fields§
§config: Config§out: OutputImplementations§
Source§impl Context
impl Context
Sourcepub fn new(out: Output, allow: Allowlist) -> Result<Self>
pub fn new(out: Output, allow: Allowlist) -> Result<Self>
Build a context for a command that makes Grab calls. allow is the
service’s URL allowlist.
Sourcepub async fn refresh_session(&mut self) -> Result<()>
pub async fn refresh_session(&mut self) -> Result<()>
Refresh the short-lived gfc_session silently through the SSO cookie
(crate::sso), persist it and rebuild the HTTP client. Fails with
auth_expired (“run grab auth login”) when the SSO is dead. Never
triggers an OTP or push.
Sourcepub async fn restore_address_from_browser(
&mut self,
cdp_base: &str,
) -> Result<bool>
pub async fn restore_address_from_browser( &mut self, cdp_base: &str, ) -> Result<bool>
Copy only the saved delivery address (location cookie) from the
browser’s default context at cdp_base into the session, leaving
every other cookie (auth included) alone. Ok(false) if the browser
has no location cookie. The value is never printed.
Sourcepub fn set_location(&mut self, loc: &Value) -> Result<()>
pub fn set_location(&mut self, loc: &Value) -> Result<()>
Replace the saved delivery address (location cookie) with loc
(the cookie’s JSON) and persist the session. Local only: the cookie
is what the web app itself writes; nothing is sent to Grab.
Sourcepub async fn after_login(&mut self) -> Vec<String>
pub async fn after_login(&mut self) -> Vec<String>
Best-effort follow-up after a login or refresh saved a session: fill in a missing saved address from the browser, and mint hydra so the next quote doesn’t have to. Never fails; returns notes for the user.
Sourcepub async fn login_mart(&mut self) -> Result<()>
pub async fn login_mart(&mut self) -> Result<()>
Log in to GrabMart’s own web client silently through the SSO cookie
(sso::Service::Mart): the protected mart API doesn’t accept
food’s gfc_session. Persists the session and rebuilds the client.
Never triggers an OTP or push.
Sourcepub fn has_mart_session(&self) -> bool
pub fn has_mart_session(&self) -> bool
Whether the session has a GrabMart web session cookie.
Sourcepub fn with_cache_mode(self, mode: CacheMode) -> Self
pub fn with_cache_mode(self, mode: CacheMode) -> Self
Set the cache mode (from --no-cache / --refresh). GRAB_NO_CACHE
and [cache] enabled = false still force it off.
Sourcepub fn cache(&self) -> &Cache
pub fn cache(&self) -> &Cache
The response cache. Clone it to call Cache::get_or_fetch with a
closure that borrows this context.
Sourcepub async fn cached_call(
&mut self,
key: &CacheKey,
req: &Request,
) -> Result<Value>
pub async fn cached_call( &mut self, key: &CacheKey, req: &Request, ) -> Result<Value>
call through the cache: serve a fresh entry for key,
else make the call and store the raw response. Only for read-only
browse requests — never carts, quotes, orders, tracking or auth.
Sourcepub async fn cached_call_meta(
&mut self,
key: &CacheKey,
req: &Request,
) -> Result<Fetched<Value>>
pub async fn cached_call_meta( &mut self, key: &CacheKey, req: &Request, ) -> Result<Fetched<Value>>
cached_call that also reports whether the
response came from the cache and when it was fetched (for “cached 4m
ago” markers).
pub fn session(&self) -> &Session
pub fn cdp_base(&self) -> String
Sourcepub async fn ensure_hydra(&mut self) -> Result<String>
pub async fn ensure_hydra(&mut self) -> Result<String>
Ensure a usable hydra token exists, minting/refreshing if needed and allowed. Persists the refreshed session. Returns the token.
Sourcepub async fn mint_hydra(&mut self) -> Result<String>
pub async fn mint_hydra(&mut self) -> Result<String>
Mint a fresh hydra token regardless of the current one.
Sourcepub async fn call(&mut self, req: &Request) -> Result<Value>
pub async fn call(&mut self, req: &Request) -> Result<Value>
Make an allowlisted call, attaching hydra when required and retrying
once if Grab rejects the token (and auto_refresh is on).
Sourcepub fn auth_status(&self) -> Value
pub fn auth_status(&self) -> Value
Status snapshot for grab auth status — cookie names and expiries, never
cookie values. The saved unit and driver note are shown to the user.