Documentation
¶
Overview ¶
Package session manages provider-specific persistent CLI sessions stored under ~/.martmart-cli/ with legacy read fallback from ~/.frisco-cli/.
Index ¶
- Constants
- func ApplyFromCurl(s *Session, c *CurlData)
- func ApplyFromCurlForProvider(s *Session, c *CurlData, provider string)
- func DefaultBaseURLForProvider(provider string) string
- func EnsureDir() error
- func ExtractRefreshTokenFromCookie(cookieHeader string) string
- func ExtractRefreshTokenFromCurlBody(body *string) string
- func ExtractRefreshTokenFromHeaderValue(value string) string
- func ExtractToken(headers map[string]string) string
- func ExtractUserID(rawURL string) string
- func HeaderValue(s *Session, key string) string
- func IsAuthenticated(s *Session) bool
- func NormalizeHeaders(headers map[string]string) map[string]string
- func NormalizeProvider(provider string) string
- func ProviderDisplayName(provider string) string
- func ProviderForBaseURL(baseURL string) string
- func ProviderForSession(s *Session, fallbackProvider string) string
- func ProviderForURL(rawURL string) string
- func RedactedCopy(s *Session) map[string]any
- func RefreshTokenString(s *Session) string
- func RequireUserID(s *Session, explicit string) (string, error)
- func Save(s *Session) error
- func SaveProvider(provider string, s *Session) error
- func SessionFilePath(provider string) string
- func StorageDir() string
- func SupportedProviders() []string
- func SupportedProvidersFlagHelp() string
- func TokenString(s *Session) string
- func UserIDString(s *Session) string
- func ValidateProvider(provider string) error
- type CurlData
- type GeoCoordinates
- type Session
Constants ¶
const ( // ProviderFrisco identifies the Frisco backend. ProviderFrisco = "frisco" // ProviderDelio identifies the Delio backend. ProviderDelio = "delio" // ProviderUpMenu identifies the UpMenu backend. ProviderUpMenu = "upmenu" // DefaultBaseURL is the base URL for the Frisco API. DefaultBaseURL = "https://www.frisco.pl" // DefaultDelioBaseURL is the base URL for the Delio API. DefaultDelioBaseURL = "https://delio.com.pl" // DefaultUpMenuBaseURL is the default base URL for the Dobra Buła UpMenu MVP. DefaultUpMenuBaseURL = "https://dobrabula.orderwebsite.com" )
Variables ¶
This section is empty.
Functions ¶
func ApplyFromCurl ¶
ApplyFromCurl updates a session with data extracted from a parsed curl command. It infers the provider from the curl URL when possible and otherwise falls back to the existing session contents.
func ApplyFromCurlForProvider ¶
ApplyFromCurlForProvider updates a session with data extracted from a parsed curl command, using the provided backend provider to decide how to trust the target host and how to preserve provider-specific fields.
func DefaultBaseURLForProvider ¶
DefaultBaseURLForProvider returns the default base URL for the given provider.
func EnsureDir ¶
func EnsureDir() error
EnsureDir creates ~/.martmart-cli with 0700 permissions if it does not exist.
func ExtractRefreshTokenFromCookie ¶
ExtractRefreshTokenFromCookie reads token from cookie-like header values.
func ExtractRefreshTokenFromCurlBody ¶
ExtractRefreshTokenFromCurlBody parses application/x-www-form-urlencoded body.
func ExtractRefreshTokenFromHeaderValue ¶
ExtractRefreshTokenFromHeaderValue extracts a refresh token from a raw Cookie or Set-Cookie header value string.
func ExtractToken ¶
ExtractToken from Authorization: Bearer ...
func ExtractUserID ¶
ExtractUserID from URL path /users/{id}/...
func HeaderValue ¶
HeaderValue returns the first header value matching key case-insensitively.
func IsAuthenticated ¶
IsAuthenticated reports whether the session has a token, Authorization header, or Cookie header (used by Delio).
func NormalizeHeaders ¶
NormalizeHeaders deduplicates headers case-insensitively and uses canonical keys.
func NormalizeProvider ¶
NormalizeProvider lowercases and trims provider names.
func ProviderDisplayName ¶
ProviderDisplayName returns a human-friendly provider name.
func ProviderForBaseURL ¶
ProviderForBaseURL guesses the provider from a session base URL.
func ProviderForSession ¶
ProviderForSession infers the provider from persisted session fields and falls back to fallbackProvider (or Frisco when empty/unknown).
func ProviderForURL ¶
ProviderForURL guesses the provider from an absolute URL.
func RedactedCopy ¶
RedactedCopy returns a deep copy of the session with sensitive fields masked.
func RefreshTokenString ¶
RefreshTokenString returns refresh token from session.
func RequireUserID ¶
RequireUserID returns the explicit user ID if given, otherwise falls back to the session user ID.
func Save ¶
Save persists s to a provider-specific session file with 0600 permissions. It infers the provider from the session base URL when possible.
func SaveProvider ¶
SaveProvider persists s to the provider session file with 0600 permissions.
func SessionFilePath ¶
SessionFilePath returns the provider-specific session file path.
func SupportedProviders ¶
func SupportedProviders() []string
SupportedProviders returns the sorted list of supported backend providers.
func SupportedProvidersFlagHelp ¶
func SupportedProvidersFlagHelp() string
SupportedProvidersFlagHelp returns a flag/help-friendly provider list.
func TokenString ¶
TokenString returns bearer token as string (JSON may unmarshal as string).
func UserIDString ¶
UserIDString returns session user_id as string or empty.
func ValidateProvider ¶
ValidateProvider validates a provider identifier.
Types ¶
type GeoCoordinates ¶
GeoCoordinates stores a provider delivery/search point in a persisted session.
type Session ¶
type Session struct {
BaseURL string `json:"base_url"`
Headers map[string]string `json:"headers"`
Token any `json:"token"`
UserID any `json:"user_id"`
RefreshToken any `json:"refresh_token"`
DeliveryCoordinates *GeoCoordinates `json:"delivery_coordinates,omitempty"`
}
Session is persisted per provider in ~/.martmart-cli/.
func LoadProvider ¶
LoadProvider reads the provider session file and returns a Session.
func LoadProviderWithPath ¶
LoadProviderWithPath reads the provider session file and returns a Session plus the path it was loaded from. The returned path is empty when no persisted session exists and the default session is returned instead.