JavaScript / TypeScript API reference

Every public class, interface, type, function and constant of @sponsorkit/sdk 1.0.0, generated from the TypeScript source.

On this page

Generated from the TypeScript source and doc comments of @sponsorkit/sdk 1.0.0. For installation, sign-in flows and worked examples, see the JavaScript / TypeScript guide.

npm install @sponsorkit/sdk

Entry points#

The package has four entry points. Pick one by where your code runs; they share the same types, error codes and result shape.

ImportForMain export
@sponsorkit/sdkBrowser client (popup or redirect sign-in, localStorage), plus every shared type and helper.Sponsorkit
@sponsorkit/sdk/nodeNative client for CLIs and desktop apps (loopback or paste-back sign-in, per-user config directory).Sponsorkit
@sponsorkit/sdk/serverBackend verification of a supporter's session token. No storage; runs in Workers.verifySession
@sponsorkit/sdk/elements<sponsorkit-button> and <sponsorkit-badge> custom elements.SponsorkitButtonElement

All symbols#

Classes#

NameEntry pointSummary
FinancialContribution@sponsorkit/sdkA ContributionResult with filter helpers.
Sponsorkit@sponsorkit/sdkSponsorkit client for browsers.
Sponsorkit@sponsorkit/sdk/nodeSponsorkit client for native runtimes.
SponsorkitBadgeElement@sponsorkit/sdk/elements<sponsorkit-badge github open-collective>: shows "Supporter ♥" when the signed-in user has an active contribution, and nothing otherwise.
SponsorkitButtonElement@sponsorkit/sdk/elements<sponsorkit-button github open-collective amount currency frequency provider>: opens checkout (synchronously, in a popup) when clicked.
SponsorkitCore@sponsorkit/sdkBase class with the shared client behaviour.
SponsorkitError@sponsorkit/sdkThe only error type thrown by the SDK.

Interfaces#

NameEntry pointSummary
CheckoutOptions@sponsorkit/sdkOptions for openCheckout() and checkoutUrl().
Contribution@sponsorkit/sdkA sponsorship (GitHub) or order (Open Collective), normalized.
ContributionResult@sponsorkit/sdkThe plain JSON result of getFinancialContribution().
Identity@sponsorkit/sdkA supporter's provider account (without its token, which never leaves Sponsorkit).
Money@sponsorkit/sdkAn amount of money in minor units (cents) with its ISO 4217 currency.
Nag@sponsorkit/sdkNag helper returned by Sponsorkit.nag().
NagDueOptions@sponsorkit/sdkOptions for Nag.due().
NagOptions@sponsorkit/sdkOptions for nag().
NagState@sponsorkit/sdkNag state as persisted in the StorageFile, keyed by nag id.
NodeOpenCheckoutOptions@sponsorkit/sdk/nodeNative openCheckout() options.
NodeSignInOptions@sponsorkit/sdk/nodeNative signIn() options.
OpenCheckoutOptions@sponsorkit/sdkOptions for openCheckout().
SignInOptions@sponsorkit/sdkOptions for signIn().
SponsorEntity@sponsorkit/sdkWho actually pays for a contribution: the user, or an organization the user belongs to.
SponsorkitCoreOptions@sponsorkit/sdkOptions shared by every Sponsorkit flavour.
SponsorkitOptions@sponsorkit/sdkOptions for the browser client.
SponsorkitOptions@sponsorkit/sdk/nodeOptions for the native client.
SponsorkitStorage@sponsorkit/sdkWhere the SDK keeps its per-target-set document.
StorageFile@sponsorkit/sdkThe JSON document stored per target set (session token, cached result and nag state).
Supporter@sponsorkit/sdkThe signed-in supporter.
Target@sponsorkit/sdkA normalized target.
TargetInfo@sponsorkit/sdkPublic metadata about a target (GET /api/v1/targets).
TargetOptions@sponsorkit/sdkTargets as accepted by verifySession().
TargetTier@sponsorkit/sdkA tier of a target's sponsorship listing.
VerifySessionOptions@sponsorkit/sdk/serverOptions for verifySession.
WebStorageLike@sponsorkit/sdkThe subset of the Web Storage API used by localStorageAdapter.

Type aliases#

NameEntry pointSummary
CheckoutResult@sponsorkit/sdkThe outcome of openCheckout().
ContributionKind@sponsorkit/sdkWhether a contribution recurs.
ContributionStatus@sponsorkit/sdkNormalized contribution status.
Env@sponsorkit/sdkAn environment map (process.env-shaped).
FetchLike@sponsorkit/sdkA fetch-compatible function.
Frequency@sponsorkit/sdkHow often a contribution is charged.
MockOption@sponsorkit/sdkMock mode: a preset name, or custom contributions to report as the signed-in supporter's.
MockPreset@sponsorkit/sdkThe names of the built-in mock presets.
NagPredicate@sponsorkit/sdkA predicate deciding whether the current supporter should see the nag.
Provider@sponsorkit/sdkA contribution platform supported by Sponsorkit.
SignInMethod@sponsorkit/sdk/nodeHow native sign-in delivers the code.
SponsorkitErrorCode@sponsorkit/sdkError codes carried by SponsorkitError.

Functions#

NameEntry pointSummary
browserCommand@sponsorkit/sdk/nodeThe command used to open a URL on platform.
canonicalTargets@sponsorkit/sdkDeduplicates and sorts (byte-wise) a target set; at least one target, at most one per provider.
codeChallenge@sponsorkit/sdkPKCE S256: base64url(sha256(ascii(verifier))).
createCodeVerifier@sponsorkit/sdkA new PKCE code_verifier: 32 random bytes, base64url (43 characters).
defaultStorageDir@sponsorkit/sdk/nodeThe 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).
defineElements@sponsorkit/sdk/elementsRegisters the elements (idempotent).
fileStorage@sponsorkit/sdk/nodeStores one <targets_hash>.json file per target set in dir.
isSponsorkitError@sponsorkit/sdkTrue if error is a SponsorkitError (optionally with the given code).
localStorageAdapter@sponsorkit/sdkWraps a Web Storage object (default: localStorage) using the key sponsorkit:<targets_hash>.
memoryStorage@sponsorkit/sdkIn-memory storage.
normalizeTarget@sponsorkit/sdkNormalizes and validates one target.
openSystemBrowser@sponsorkit/sdk/nodeOpens url (http/https only) in the system browser.
parseTarget@sponsorkit/sdkParses provider:account.
resetProcessState@sponsorkit/sdkForgets per-process state: nag runs already counted, the dev-check memo and the Retry-After memo.
targetsFrom@sponsorkit/sdkBuilds the canonical target set from { github?, openCollective? }, a target param string, or a list of target strings.
targetsHash@sponsorkit/sdktargets_hash: lowercase hex SHA-256 of the UTF-8 target param (storage key).
targetsParam@sponsorkit/sdkThe canonical target param: github:x,open-collective:y.
targetToString@sponsorkit/sdkgithub:<login> / open-collective:<slug>.
verifySession@sponsorkit/sdk/serverVerifies a supporter's session token (sks_…) forwarded by your frontend and returns their live contributions for targets.

Constants#

NameEntry pointSummary
DEFAULT_API_BASE_URL@sponsorkit/sdkThe default API origin: where every /api/v1/… call goes.
DEFAULT_CACHE_TTL@sponsorkit/sdkDefault cacheTtl in seconds.
DEFAULT_CHECKOUT_POLL_INTERVAL@sponsorkit/sdkDefault checkout poll interval in seconds.
DEFAULT_CHECKOUT_TIMEOUT@sponsorkit/sdkDefault checkout timeout in seconds (polling phase only).
DEFAULT_SIGN_IN_TIMEOUT@sponsorkit/sdkDefault signInTimeout in seconds.
DEFAULT_SITE_BASE_URL@sponsorkit/sdkThe default site base URL: origin plus base path of the pages (/connect/, /checkout/).
elementDefaults@sponsorkit/sdk/elementsOptions applied to every element-created client (e.g. apiBaseUrl, siteBaseUrl, returnTo).
MOCK_PRESETS@sponsorkit/sdkNames of the built-in presets.
PROVIDERS@sponsorkit/sdkAll providers, in canonical order.
SPONSORKIT_ERROR_CODES@sponsorkit/sdkAll error codes, in the order of the wire protocol's error contract.

Conventions#

  • Durations in options are seconds (cacheTtl, signInTimeout, requestTimeout, timeout); amounts are minor units (cents) with an ISO 4217 currency.
  • Every error the SDK throws is a SponsorkitError with a code. getFinancialContribution() never throws for network or server problems. See Error contract.
  • Cancellation uses the standard AbortSignal.