Skip to main content

Context

Struct Context 

Source
pub struct Context {
    pub config: Config,
    /* private fields */
}

Fields§

§config: Config

Implementations§

Source§

impl Context

Source

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)).

Source

pub fn with_allowlist(self, allow: &Allowlist) -> Result<Self>

Add allow to the URL allowlist (and rebuild the client).

Source

pub fn with_hydra_key(self, pem: Option<String>) -> Self

Use pem as the hydra signing key for native minting.

Source

pub async fn set_session(&mut self, session: Session) -> Result<()>

Replace the session (e.g. after a login) and save it through the store.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn has_mart_session(&self) -> bool

Whether the session has a GrabMart web session cookie.

Source

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.

Source

pub fn set_cache_mode(&mut self, mode: CacheMode)

Switch the cache mode in place.

Source

pub fn cache(&self) -> &CacheHandle

The response cache. Clone it to call CacheHandle::get_or_fetch with a closure that borrows this context.

Source

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.

Source

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).

Source

pub fn session(&self) -> &Session

Source

pub fn cdp_base(&self) -> String

Source

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.

Source

pub async fn mint_hydra(&mut self) -> Result<String>

Mint a fresh hydra token regardless of the current one.

Source

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).

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more