@sponsorkit/sdk/node

Native client for CLIs and desktop apps (loopback or paste-back sign-in, per-user config directory).

On this page

@sponsorkit/sdk/node: the Sponsorkit client for Node.js, Bun and Deno (CLIs, desktop apps, servers acting for one user). Sign-in uses a loopback redirect to the system browser, or paste-back when headless; state lives in the per-user config directory.

import { … } from "@sponsorkit/sdk/node";

Example#

import { Sponsorkit } from "@sponsorkit/sdk/node";
const sk = new Sponsorkit({ github: "octocat", appName: "my-cli" });
const fc = await sk.getFinancialContribution();

Exports#

Classes#

NameSummary
SponsorkitSponsorkit client for native runtimes.

Interfaces#

NameSummary
NodeOpenCheckoutOptionsNative openCheckout() options.
NodeSignInOptionsNative signIn() options.
SponsorkitOptionsOptions for the native client.

Type aliases#

NameSummary
SignInMethodHow native sign-in delivers the code.

Functions#

NameSummary
browserCommandThe command used to open a URL on platform.
defaultStorageDirThe per-user Sponsorkit directory: $XDG_CONFIG_HOME/sponsorkit (Linux, default $HOME/.config), $HOME/Library/Application Support/sponsorkit (macOS), %APPDATA%\sponsorkit (Windows, default %USERPROFILE%\AppData\Roaming).
fileStorageStores one <targets_hash>.json file per target set in dir.
openSystemBrowserOpens url (http/https only) in the system browser.

Re-exported#

This entry point also exports these symbols, documented under @sponsorkit/sdk:

canonicalTargets, CheckoutOptions, CheckoutResult, codeChallenge, Contribution, ContributionKind, ContributionResult, ContributionStatus, createCodeVerifier, DEFAULT_API_BASE_URL, DEFAULT_CACHE_TTL, DEFAULT_CHECKOUT_POLL_INTERVAL, DEFAULT_CHECKOUT_TIMEOUT, DEFAULT_SIGN_IN_TIMEOUT, DEFAULT_SITE_BASE_URL, Env, FetchLike, FinancialContribution, Frequency, Identity, isSponsorkitError, localStorageAdapter, memoryStorage, MOCK_PRESETS, MockOption, MockPreset, Money, Nag, NagDueOptions, NagOptions, NagPredicate, NagState, normalizeTarget, OpenCheckoutOptions, parseTarget, Provider, PROVIDERS, resetProcessState, SignInOptions, SponsorEntity, SPONSORKIT_ERROR_CODES, SponsorkitCore, SponsorkitCoreOptions, SponsorkitError, SponsorkitErrorCode, SponsorkitStorage, StorageFile, Supporter, Target, TargetInfo, TargetOptions, targetsFrom, targetsHash, targetsParam, TargetTier, targetToString, WebStorageLike

Functions#

browserCommand()#

function browserCommand(url: string, platform: string = process.platform): { command: string; args: string[] }

The command used to open a URL on platform. The URL is passed as a single argv entry, never through a shell.

Parameters

ParameterTypeDefaultDescription
urlstringrequired
platformstringprocess.platform

Returns { command: string; args: string[] }

View source

defaultStorageDir()#

function defaultStorageDir(env: Record<string, string | undefined> = process.env, platform: string = process.platform): string | null

The per-user Sponsorkit directory: $XDG_CONFIG_HOME/sponsorkit (Linux, default $HOME/.config), $HOME/Library/Application Support/sponsorkit (macOS), %APPDATA%\sponsorkit (Windows, default %USERPROFILE%\AppData\Roaming).

Returns null when no per-user directory can be determined (e.g. HOME is unset or not absolute); the client then keeps its state in memory and never falls back to the current directory.

Parameters

ParameterTypeDefaultDescription
envRecord<string, string | undefined>process.env
platformstringprocess.platform

Returns string | null

View source

fileStorage()#

function fileStorage(dir: string): SponsorkitStorage

Stores one <targets_hash>.json file per target set in dir. The directory is created with mode 0700 on first write and files are written with mode 0600 via a temp file and an atomic rename. Instances are shared per directory.

Parameters

ParameterTypeDefaultDescription
dirstringrequired

Returns SponsorkitStorage (SponsorkitStorage)

View source

openSystemBrowser()#

function openSystemBrowser(url: string): Promise<void>

Opens url (http/https only) in the system browser. Rejects if no opener could be started.

Parameters

ParameterTypeDefaultDescription
urlstringrequired

Returns Promise<void>

View source