SponsorkitOptions

Configuration for SponsorkitClient.

On this page

Configuration for SponsorkitClient. At least one target is required.

namespace Sponsorkit;

public sealed class SponsorkitOptions

Constructors#

MemberDescription
SponsorkitOptions()Creates options with every property at its default; set the properties with an object initializer.

SponsorkitOptions()#

public SponsorkitOptions()

Creates options with every property at its default; set the properties with an object initializer.

Properties#

MemberDescription
GitHubThe GitHub login (user or organization) that receives sponsorships.
OpenCollectiveThe Open Collective collective slug that receives contributions.
AppNameYour app's name, shown on the consent page as "says it is" (1–64 characters).
CacheTtlHow long results are served from the local cache without calling the API.
MockMock mode: no network and no disk access; results carry mock: true.
StorageDirectoryDirectory holding one <targets_hash>.json file per target set.
StorageA custom storage backend (for example a keychain).
ApiBaseUrlThe Sponsorkit API origin, used for every API call (/api/v1/…).
SiteBaseUrlThe Sponsorkit site base URL (origin plus optional base path), used for every page URL: /connect/, /checkout/, SponsorkitClient.CheckoutUrl and the loopback redirect after a checkout sign-in.
SignInMethodWhich sign-in flow to use.
OpenBrowserOpens a URL in a browser.
PromptForCodeAsks the supporter for the paste-back code.
EnvironmentOverrides the environment variables Sponsorkit reads (SPONSORKIT_DISABLE, SPONSORKIT_MOCK, SPONSORKIT_NO_NAG, SPONSORKIT_DEV_CHECKS, CI).
DevChecksForces the dev-time check that the targets exist on or off.
SignInTimeoutThe maximum time to wait for the supporter to finish a loopback or paste-back sign-in.
InteractiveOverrides the terminal check used by the nag helper.
CheckoutPollIntervalHow often SponsorkitClient.OpenCheckoutAsync polls for a new contribution.
ClockThe current time, used for cache expiry and nags.
HttpClientThe HTTP client to use.
RequestTimeoutThe timeout of each HTTP request to Sponsorkit.

GitHub#

public string? GitHub { get; set; }

The GitHub login (user or organization) that receives sponsorships.

Type: string?

OpenCollective#

public string? OpenCollective { get; set; }

The Open Collective collective slug that receives contributions.

Type: string?

AppName#

public string? AppName { get; set; }

Your app's name, shown on the consent page as "says it is" (1–64 characters).

Type: string?

CacheTtl#

public TimeSpan CacheTtl { get; set; } = TimeSpan.FromHours(1);

How long results are served from the local cache without calling the API. Default 1 hour, minimum 60 seconds. A single call can bypass it with SponsorkitClient.GetFinancialContributionAsync.

Type: TimeSpan · Default: TimeSpan.FromHours(1)

Mock#

public SponsorkitMock? Mock { get; set; }

Mock mode: no network and no disk access; results carry mock: true. Use a preset name ("active-monthly" converts implicitly) or SponsorkitMock.WithContributions. The SPONSORKIT_MOCK environment variable selects a preset too; this option wins over it.

Type: SponsorkitMock?

StorageDirectory#

public string? StorageDirectory { get; set; }

Directory holding one <targets_hash>.json file per target set. Default: $XDG_CONFIG_HOME/sponsorkit (Linux), ~/Library/Application Support/sponsorkit (macOS) or %APPDATA%\sponsorkit (Windows).

Type: string?

Storage#

public ISponsorkitStorage? Storage { get; set; }

A custom storage backend (for example a keychain). Takes precedence over StorageDirectory.

Type: ISponsorkitStorage?

ApiBaseUrl#

public string? ApiBaseUrl { get; set; }

The Sponsorkit API origin, used for every API call (/api/v1/…). Default https://api.sponsorkit.io; override for self-hosting and tests. Trailing slashes are removed and an empty string counts as unset.

Type: string?

SiteBaseUrl#

public string? SiteBaseUrl { get; set; }

The Sponsorkit site base URL (origin plus optional base path), used for every page URL: /connect/, /checkout/, SponsorkitClient.CheckoutUrl and the loopback redirect after a checkout sign-in. Default https://ffmathy.github.io/sponsorkit, or ApiBaseUrl when that is set and this is not (single-origin self-hosting). Trailing slashes are removed and an empty string counts as unset.

Type: string?

SignInMethod#

public SignInMethod SignInMethod { get; set; } = SignInMethod.Auto;

Which sign-in flow to use. Default SignInMethod.Auto.

Type: SignInMethod · Default: SignInMethod.Auto

OpenBrowser#

public Func<string, CancellationToken, Task>? OpenBrowser { get; set; }

Opens a URL in a browser. Default: the system browser (open, xdg-open or the shell on Windows). Throwing makes automatic sign-in fall back to paste-back.

Type: Func<string, CancellationToken, Task>?

PromptForCode#

public Func<string, CancellationToken, Task<string>>? PromptForCode { get; set; }

Asks the supporter for the paste-back code. It receives the URL to open. Default: reads a line from standard input.

Type: Func<string, CancellationToken, Task<string>>?

A blocking console read cannot be cancelled. When the default prompt times out or is cancelled, its read stays pending: the next line typed on standard input goes to the next Sponsorkit paste prompt, or is discarded if none follows, so a host Console.ReadLine after a cancelled sign-in sees the line after it. Supply your own prompt if your app keeps reading standard input after an abandoned sign-in.

Environment#

public IReadOnlyDictionary<string, string>? Environment { get; set; }

Overrides the environment variables Sponsorkit reads (SPONSORKIT_DISABLE, SPONSORKIT_MOCK, SPONSORKIT_NO_NAG, SPONSORKIT_DEV_CHECKS, CI). When set, it replaces the process environment for these variables (it is not merged): a variable missing from the dictionary counts as unset.

Type: IReadOnlyDictionary<string, string>?

DevChecks#

public bool? DevChecks { get; set; }

Forces the dev-time check that the targets exist on or off. Default (null): on only when SPONSORKIT_DEV_CHECKS is set. .NET has no implicit development signal.

Type: bool?

SignInTimeout#

public TimeSpan SignInTimeout { get; set; } = TimeSpan.FromMinutes(5);

The maximum time to wait for the supporter to finish a loopback or paste-back sign-in. Default 5 minutes. Exceeding it throws timeout. Also bounds the sign-in phase of SponsorkitClient.OpenCheckoutAsync.

Type: TimeSpan · Default: TimeSpan.FromMinutes(5)

Interactive#

public bool? Interactive { get; set; }

Overrides the terminal check used by the nag helper. Default (null): interactive when neither stdout nor stderr is redirected.

Type: bool?

CheckoutPollInterval#

public TimeSpan CheckoutPollInterval { get; set; } = TimeSpan.FromSeconds(60);

How often SponsorkitClient.OpenCheckoutAsync polls for a new contribution. Default 60 seconds.

Type: TimeSpan · Default: TimeSpan.FromSeconds(60)

Clock#

public Func<DateTimeOffset>? Clock { get; set; }

The current time, used for cache expiry and nags. Default: DateTimeOffset.UtcNow.

Type: Func<DateTimeOffset>?

HttpClient#

public HttpClient? HttpClient { get; set; }

The HTTP client to use. Default: a shared internal client.

Type: HttpClient?

RequestTimeout#

public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30);

The timeout of each HTTP request to Sponsorkit. Default 30 seconds; TimeSpan.Zero (or Timeout.InfiniteTimeSpan) disables it. A timeout counts as a network error: SponsorkitClient.GetFinancialContributionAsync serves the stale cache and SponsorkitClient.SignInAsync throws network_error. Negative values throw invalid_config.

Type: TimeSpan · Default: TimeSpan.FromSeconds(30)