Documentation
¶
Index ¶
- Constants
- func DeleteProfile(name string) error
- func Dir() (string, error)
- func DirBinding() (path, projectID string, ok bool)
- func ListProfiles() ([]string, error)
- func LoadState(profile, name string, out any) error
- func ProfileName(p string) string
- func Save(profile string, cfg *Config) error
- func SaveState(profile, name string, v any) error
- func SetActiveProfile(name string) error
- type Config
- func (c *Config) BearerToken() string
- func (c *Config) CanAutoRefresh() bool
- func (c *Config) Credential() (token string, source CredentialSource)
- func (c *Config) CredentialDescription() string
- func (c *Config) DescribeSource(source CredentialSource) string
- func (c *Config) IsOAuth() bool
- func (c *Config) NeedsRefresh() bool
- func (c *Config) OverrideProjectID(id string)
- func (c *Config) PresentCredentialSources() []CredentialSource
- func (c *Config) ProjectBindingError(flagSet bool) error
- func (c *Config) SetAPIKey(key string)
- func (c *Config) SetFlagAPIKey(key string)
- func (c *Config) SetOAuthTokens(accessToken, refreshToken string, expiresAt time.Time)
- func (c *Config) StoredProjectID() string
- func (c *Config) TokenStatus() string
- func (c *Config) UseProjectID(id string)
- type CredentialSource
Constants ¶
const ( AuthOriginOAuthLogin = "oauth_login" // also set on signup AuthOriginAPIKey = "api_key" AuthOriginMCPImport = "mcp_import" )
const ( TokenValid = "valid" TokenNearExpiry = "near_expiry" TokenExpired = "expired" TokenNoExpiry = "no_expiry" // borrowed tokens carry no expiry we can read )
const ProjectFileName = ".revenuecat.json"
ProjectFileName is a per-directory project binding, discovered by walking up from the working directory like git finding .git, so a repo can commit it.
Variables ¶
This section is empty.
Functions ¶
func DeleteProfile ¶
DeleteProfile removes a profile file. If it was the active one, the .active pointer is cleared.
func Dir ¶
Dir is the CLI's config/data directory — the single home for profiles, state, and other per-account files regardless of the working directory.
func DirBinding ¶
DirBinding reports the nearest .revenuecat.json binding for the current working directory: its file path and the project_id it resolves to. ok is false when no readable, parseable binding applies (an unreadable one is ProjectBindingError's concern, not this). Callers use it to warn when a committed binding will shadow a profile default the user just set or cleared.
func ListProfiles ¶
ListProfiles returns the names of every profile file in the config dir.
func LoadState ¶
LoadState reads a named state file into out. A missing file is not an error; out is left untouched.
func ProfileName ¶
ProfileName resolves the active profile name. Precedence (highest first):
- explicit argument (e.g. --profile flag)
- RC_PROFILE env var
- .active pointer file in the config dir (written by `rc profiles use`)
- "default"
func SetActiveProfile ¶
SetActiveProfile writes the .active pointer file. Errors if the named profile doesn't exist on disk (avoids "active" pointing at nothing).
Types ¶
type Config ¶
type Config struct {
// API key auth (original).
APIKey string `json:"api_key,omitempty"`
// OAuth auth. All fields are omitempty so old profiles remain valid.
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
TokenExpiresAt time.Time `json:"token_expires_at,omitempty"`
TokenType string `json:"token_type,omitempty"` // "oauth" | "" (api_key)
AccountEmail string `json:"account_email,omitempty"`
AccountName string `json:"account_name,omitempty"`
// AuthSource records how the stored credential was obtained, so status can
// name a borrowed MCP-imported token instead of passing it off as a normal
// OAuth login or stored key. Flag/env credentials aren't stored, so they're
// resolved live and never written here. Empty on legacy profiles.
AuthSource string `json:"auth_source,omitempty"` // AuthOrigin* constants
ProjectID string `json:"project_id,omitempty"`
BaseURL string `json:"base_url,omitempty"`
// contains filtered or unexported fields
}
func LoadStored ¶
Load reads a profile from disk, layering the per-directory project binding and env vars on top. The project ID resolves with this precedence (highest first): --project-id flag (applied by the caller) > RC_PROJECT_ID env > nearest .revenuecat.json in the directory tree > profile default. Missing files are not an error — they return a zero Config so first-run commands like `rc login` work cleanly. LoadStored reads a profile's config as written on disk, overlaying keyring secrets, without applying any per-invocation override (the per-directory binding, RC_* env vars, or --project-id). Use it to report a profile's own stored defaults, e.g. `profiles list`; use Load for the active resolved config a command should act on.
func (*Config) BearerToken ¶
BearerToken returns the auth credential for the Authorization: Bearer header.
func (*Config) CanAutoRefresh ¶
CanAutoRefresh is false for borrowed MCP tokens, which carry no refresh token.
func (*Config) Credential ¶
func (c *Config) Credential() (token string, source CredentialSource)
Credential resolves the active credential. Precedence (highest first): --api-key flag > RC_API_KEY env > OAuth login > stored key — so a CI job or a one-off `RC_API_KEY=... rc ...` always acts on the account it names, even on a machine with a logged-in profile.
func (*Config) CredentialDescription ¶
CredentialDescription refines Describe with stored provenance so an MCP-imported credential isn't named as an ordinary OAuth login or stored key.
func (*Config) DescribeSource ¶
func (c *Config) DescribeSource(source CredentialSource) string
DescribeSource names a credential source, refining the stored credential's phrasing with its provenance (only flag/env overrides never carry one).
func (*Config) NeedsRefresh ¶
NeedsRefresh reports whether the OAuth access token is expired or within 5 minutes of expiry and a refresh token is available.
func (*Config) OverrideProjectID ¶
OverrideProjectID applies a --project-id flag for this invocation only. Unlike UseProjectID it keeps the value out of the profile: it records provenance so Save reverts it, so an ordinary command that happens to persist config (an OAuth token refresh, say) never bakes a one-shot flag into the stored default. Login adopts an explicit --project-id as the new default with UseProjectID.
func (*Config) PresentCredentialSources ¶
func (c *Config) PresentCredentialSources() []CredentialSource
PresentCredentialSources lists every available credential source, highest precedence first.
func (*Config) ProjectBindingError ¶
ProjectBindingError reports a nearest .revenuecat.json that exists but could not be read or parsed. It returns nil when a higher-precedence override wins anyway — RC_PROJECT_ID (env) or an explicit --project-id (flagSet) — since those bypass the tree binding entirely. Otherwise the malformed file would silently retarget another project, so callers surface this before running.
func (*Config) SetAPIKey ¶
SetAPIKey sets an explicit stored API key, clearing any flag or env override.
func (*Config) SetFlagAPIKey ¶
func (*Config) SetOAuthTokens ¶ added in v0.1.2
SetOAuthTokens stores OAuth credentials, clearing any flag or env override — like SetAPIKey, an explicit login supersedes ambient credentials for the rest of the invocation, so the token just obtained (not RC_API_KEY) is what gets validated, reported, and saved.
func (*Config) StoredProjectID ¶
StoredProjectID returns the profile's on-disk project default, unwinding any per-invocation overlay (the per-directory binding or RC_PROJECT_ID) that Load layered on top of it.
func (*Config) TokenStatus ¶
TokenStatus is only meaningful when IsOAuth(); the near-expiry window matches NeedsRefresh's 5 minutes.
func (*Config) UseProjectID ¶
UseProjectID records a project the user chose explicitly (projects use, projects create --use, the picker). It clears the env/dir project overrides so Save persists the choice even when it equals the injected override value — otherwise the revert would mistake the deliberate write for an untouched override.
type CredentialSource ¶
type CredentialSource string
CredentialSource names where the active credential came from.
const ( SourceFlag CredentialSource = "flag" SourceOAuth CredentialSource = "oauth" SourceEnv CredentialSource = "env" SourceProfile CredentialSource = "profile" SourceNone CredentialSource = "none" )
func (CredentialSource) Describe ¶
func (s CredentialSource) Describe() string
Describe returns a human-readable phrase naming the source.