pub struct Context {
pub config: Config,
/* private fields */
}Fields§
§config: ConfigImplementations§
Source§impl Context
impl Context
Sourcepub async fn new(
config: Config,
store: Arc<dyn SessionStore>,
cache: Arc<dyn Cache>,
) -> Result<Self>
pub async fn new( config: Config, store: Arc<dyn SessionStore>, cache: Arc<dyn Cache>, ) -> Result<Self>
Build a context from a config, the session store and the cache
backend. Loads the session (auth_missing if the store has none).
The allowlist starts empty: add the service’s with
with_allowlist (e.g.
grabfood::api::allowlist(config.allow_ordering)).
Sourcepub fn with_allowlist(self, allow: &Allowlist) -> Result<Self>
pub fn with_allowlist(self, allow: &Allowlist) -> Result<Self>
Add allow to the URL allowlist (and rebuild the client).
Sourcepub fn with_hydra_key(self, pem: Option<String>) -> Self
pub fn with_hydra_key(self, pem: Option<String>) -> Self
Use pem as the hydra signing key for native minting.
Sourcepub async fn set_session(&mut self, session: Session) -> Result<()>
pub async fn set_session(&mut self, session: Session) -> Result<()>
Replace the session (e.g. after a login) and save it through the store.
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), save it through the store and rebuild the HTTP
client. Fails with auth_expired 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 async fn set_location(&mut self, loc: &Value) -> Result<()>
pub async 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, or
CacheMode::Off for the cart/quote/order path). [cache] enabled = false still forces it off.
Sourcepub fn set_cache_mode(&mut self, mode: CacheMode)
pub fn set_cache_mode(&mut self, mode: CacheMode)
Switch the cache mode in place.
Sourcepub fn cache(&self) -> &CacheHandle
pub fn cache(&self) -> &CacheHandle
The response cache. Clone it to call CacheHandle::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.