session

package
v0.0.0-...-df769fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package session manages provider-specific persistent CLI sessions stored under ~/.martmart-cli/ with legacy read fallback from ~/.frisco-cli/.

Index

Constants

View Source
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

func ApplyFromCurl(s *Session, c *CurlData)

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

func ApplyFromCurlForProvider(s *Session, c *CurlData, provider string)

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

func DefaultBaseURLForProvider(provider string) string

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

func ExtractRefreshTokenFromCookie(cookieHeader string) string

ExtractRefreshTokenFromCookie reads token from cookie-like header values.

func ExtractRefreshTokenFromCurlBody

func ExtractRefreshTokenFromCurlBody(body *string) string

ExtractRefreshTokenFromCurlBody parses application/x-www-form-urlencoded body.

func ExtractRefreshTokenFromHeaderValue

func ExtractRefreshTokenFromHeaderValue(value string) string

ExtractRefreshTokenFromHeaderValue extracts a refresh token from a raw Cookie or Set-Cookie header value string.

func ExtractToken

func ExtractToken(headers map[string]string) string

ExtractToken from Authorization: Bearer ...

func ExtractUserID

func ExtractUserID(rawURL string) string

ExtractUserID from URL path /users/{id}/...

func HeaderValue

func HeaderValue(s *Session, key string) string

HeaderValue returns the first header value matching key case-insensitively.

func IsAuthenticated

func IsAuthenticated(s *Session) bool

IsAuthenticated reports whether the session has a token, Authorization header, or Cookie header (used by Delio).

func NormalizeHeaders

func NormalizeHeaders(headers map[string]string) map[string]string

NormalizeHeaders deduplicates headers case-insensitively and uses canonical keys.

func NormalizeProvider

func NormalizeProvider(provider string) string

NormalizeProvider lowercases and trims provider names.

func ProviderDisplayName

func ProviderDisplayName(provider string) string

ProviderDisplayName returns a human-friendly provider name.

func ProviderForBaseURL

func ProviderForBaseURL(baseURL string) string

ProviderForBaseURL guesses the provider from a session base URL.

func ProviderForSession

func ProviderForSession(s *Session, fallbackProvider string) string

ProviderForSession infers the provider from persisted session fields and falls back to fallbackProvider (or Frisco when empty/unknown).

func ProviderForURL

func ProviderForURL(rawURL string) string

ProviderForURL guesses the provider from an absolute URL.

func RedactedCopy

func RedactedCopy(s *Session) map[string]any

RedactedCopy returns a deep copy of the session with sensitive fields masked.

func RefreshTokenString

func RefreshTokenString(s *Session) string

RefreshTokenString returns refresh token from session.

func RequireUserID

func RequireUserID(s *Session, explicit string) (string, error)

RequireUserID returns the explicit user ID if given, otherwise falls back to the session user ID.

func Save

func Save(s *Session) error

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

func SaveProvider(provider string, s *Session) error

SaveProvider persists s to the provider session file with 0600 permissions.

func SessionFilePath

func SessionFilePath(provider string) string

SessionFilePath returns the provider-specific session file path.

func StorageDir

func StorageDir() string

StorageDir returns the session/config root directory.

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

func TokenString(s *Session) string

TokenString returns bearer token as string (JSON may unmarshal as string).

func UserIDString

func UserIDString(s *Session) string

UserIDString returns session user_id as string or empty.

func ValidateProvider

func ValidateProvider(provider string) error

ValidateProvider validates a provider identifier.

Types

type CurlData

type CurlData struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    *string
}

CurlData holds the parsed components of a curl command.

func ParseCurl

func ParseCurl(curlCommand string) (*CurlData, error)

ParseCurl parses a curl command string into its URL, method, headers, and body.

type GeoCoordinates

type GeoCoordinates struct {
	Lat  float64 `json:"lat"`
	Long float64 `json:"long"`
}

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 Load

func Load() (*Session, error)

Load reads the Frisco session file.

func LoadProvider

func LoadProvider(provider string) (*Session, error)

LoadProvider reads the provider session file and returns a Session.

func LoadProviderWithPath

func LoadProviderWithPath(provider string) (*Session, string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL