SponsorkitCore
Base class with the shared client behaviour.
On this page
Base class with the shared client behaviour. Use Sponsorkit from @sponsorkit/sdk or @sponsorkit/sdk/node.
import { SponsorkitCore } from "@sponsorkit/sdk";
abstract class SponsorkitCore<I = unknown> { … }Class, exported from @sponsorkit/sdk, @sponsorkit/sdk/node.
Extended by Sponsorkit (@sponsorkit/sdk), Sponsorkit (@sponsorkit/sdk/node).
Constructors#
new SponsorkitCore()#
new SponsorkitCore(options: SponsorkitCoreOptions)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
options | SponsorkitCoreOptions | required | See SponsorkitCoreOptions. |
Properties#
targets#
readonly targets: readonly string[]Canonical target strings, e.g. ["github:octocat"].
targetsParam#
readonly targetsParam: stringCanonical target param (github:x,open-collective:y).
apiBaseUrl#
readonly apiBaseUrl: stringAPI origin in use (no trailing slash).
siteBaseUrl#
readonly siteBaseUrl: stringSite base URL in use (origin plus optional base path, no trailing slash).
disabled#
readonly disabled: booleanTrue when SPONSORKIT_DISABLE is set: no network, no disk, signed-out disabled results.
isMock#
readonly isMock: booleanTrue in mock mode.
Methods#
isSignedIn()#
async isSignedIn(): Promise<boolean>Whether a session token is stored (no network).
Returns Promise<boolean>
getSessionToken()#
async getSessionToken(): Promise<string | null>The stored session token (sks_…), for forwarding to your backend's
verifySession(). null when signed out, disabled or in mock mode.
Returns Promise<string | null>
getFinancialContribution()#
async getFinancialContribution(options: { cacheTtl?: number } = {}): Promise<FinancialContribution>What the current user has contributed to the targets. Never throws for
network or server problems: it serves the cache or a stale result.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
options | { cacheTtl?: number } | {} | cacheTtl: Seconds a cached result may be served; 0 always refreshes. |
Returns Promise<FinancialContribution> (FinancialContribution)
signIn()#
async signIn(options: SignInOptions = {}): Promise<FinancialContribution>Signs the user in (or adds a second identity when already signed in) and
returns the fresh result. Rejects with disabled, invalid_config (unconfigured provider, or the
session can't be written to storage), popup_blocked,
access_denied, invalid_state, provider_error, invalid_code, cancelled
(signal aborted, popup closed), timeout (signInTimeout) or network_error.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
options | SignInOptions | {} | See SignInOptions. |
Returns Promise<FinancialContribution> (FinancialContribution)
openCheckout()#
async openCheckout(options: OpenCheckoutOptions = {}): Promise<CheckoutResult>Sends the user to contribute and waits for the new contribution:
signs in first if needed, opens <siteBaseUrl>/checkout/, then polls with cacheTtl: 0
until a new or changed contribution appears. Resolves { status: "unknown" }
when the polling timeout passes or signal aborts. Rejects with the
signIn() codes during the sign-in phase, including timeout
(signInTimeout) and cancelled (popup closed or no code entered).
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
options | OpenCheckoutOptions | {} | See OpenCheckoutOptions. |
Returns Promise<CheckoutResult> (CheckoutResult)
checkoutUrl()#
checkoutUrl(options: CheckoutOptions = {}): stringA link to the <siteBaseUrl>/checkout/ page without sign-in (synchronous, offline-safe).
Suits nags, READMEs and "Sponsor" links. Checkout started this way can't be detected.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
options | CheckoutOptions | {} | See CheckoutOptions. |
Returns string
signOut()#
async signOut(): Promise<void>Deletes the session token and cache locally (there is no server-side sign-out). Keeps nag state.
Rejects with invalid_config if the storage can't be written.
Returns Promise<void>
nag()#
nag(options: NagOptions): NagA nag helper.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
options | NagOptions | required | See NagOptions. |
Returns Nag (Nag)
Static members#
SponsorkitCore.resetProcessState()#
static resetProcessState(): voidResets per-process memo state (same as the resetProcessState() export).
Returns void