Skip to main content

Crate grabcli_core

Crate grabcli_core 

Source
Expand description

Shared core for grabcli: the parts every Grab service reuses — config, session, auth/hydra, the allowlisted HTTP client, the read-only response cache and money helpers.

The library owns no storage and reads no files or environment: an embedder builds a Context with Context::new(config, session_store, cache), passing an Arc<dyn SessionStore> and an Arc<dyn Cache>. The grab CLI uses a session.json file store and the SQLite cache from grabcli-sqlite; a daemon can back both with its own database. Service crates (e.g. grabfood) register their URL allowlist and make calls through the context.

§Example: format a price

use grabcli_core::Money;

let price = Money(12_345); // integer centavos, not floating-point pesos
assert_eq!(price.peso(), "₱123.45");
assert_eq!(price.minor(), 12_345);

For HTTP calls, construct a Context with your own SessionStore and Cache; see grabfood::context or grabcli-service for service-level setup.

Re-exports§

pub use cache::Cache;
pub use cache::CacheHandle;
pub use cache::CacheKey;
pub use cache::CacheKind;
pub use cache::CacheMode;
pub use cache::Fetched;
pub use config::Config;
pub use ctx::Context;
pub use error::Error;
pub use error::ErrorKind;
pub use error::Result;
pub use http::Allowlist;
pub use http::Client;
pub use http::Hydra;
pub use http::Request;
pub use location::Location;
pub use money::Money;
pub use session::Session;
pub use store::MemorySessionStore;
pub use store::SessionStore;

Modules§

cache
The read-only browse cache: the Cache storage trait plus the CacheHandle every service call goes through.
cdp
Chrome DevTools Protocol client.
config
config.toml: user settings. Every key is optional. The library only parses text (Config::parse) or takes a struct; reading the file (and the hydra key it points to) is the CLI’s job.
ctx
The runtime context shared by every call.
error
One error type for every grabcli command.
http
The shared HTTP client.
hydra
The hydra device JWT.
jwt
Minimal JWT helpers: decode the (unverified) payload, read exp.
location
The saved delivery address, read from the location cookie (URL-encoded JSON). grabcli always shows the delivery address on a quote so the user can confirm where the food is going.
login
grab auth login: a real phone login on weblogin.grab.com, driven over CDP inside an isolated browser context.
money
Money as integer minor units (centavos). Display adds the ₱ symbol and thousands separators.
places
Saved places (Home, Work and other saved addresses) from the account’s address book, as food.grab.com’s address picker loads them. See docs/places.md.
session
The saved Grab web session grabcli reads at runtime.
sso
Silent session refresh through the GrabID SSO cookie (grab auth refresh).
store
Where a Session lives. The library never picks a path: the embedder passes an Arc<dyn SessionStore> to Context::new and the context loads the session once, then saves every change it makes (silent SSO refresh, hydra mint, GrabMart login, address changes) through it.