/**
* Content Credits JS SDK v2
*
* Drop-in paywall and comments for any website.
*
* CDN (script tag):
*
*
*
* npm:
* import { ContentCredits } from '@contentcredits/sdk';
* ContentCredits.init({ apiKey: 'YOUR_API_KEY', contentSelector: '#article-body' });
*/
import type { SDKConfig, SDKState, SDKEventName, SDKEventHandler } from './types/index.js';
export type { SDKConfig, SDKState, SDKEventName, SDKEventHandler };
export type { User, Comment, CommentSortBy } from './types/index.js';
export declare class ContentCredits {
private readonly config;
private readonly state;
private readonly emitter;
private readonly client;
private readonly creditsApi;
private readonly commentsApi;
private readonly postsApi;
private paywallModule;
private commentsModule;
private constructor();
/**
* Initialise the SDK and immediately start the access check.
*
* @example
* const cc = ContentCredits.init({
* apiKey: 'pub_abc123',
* contentSelector: '#premium-content',
* });
*/
static init(rawConfig: SDKConfig): ContentCredits;
private _start;
/**
* Subscribe to state changes. The callback receives the full state snapshot
* every time any field changes. Returns an unsubscribe function.
*
* Primarily useful in **headless mode** — lets you drive your own UI from
* reactive state without polling `getState()`.
*
* @example
* const unsubscribe = cc.subscribe((state) => {
* if (state.hasAccess) showFullContent();
* else showPaywall(state);
* });
*/
subscribe(fn: (state: SDKState) => void): () => void;
/**
* Trigger the login flow programmatically.
*
* - Desktop: opens a popup window to the Content Credits auth page.
* - Mobile: performs a full-page redirect.
* - Extension: delegates to the browser extension.
*
* Primarily useful in **headless mode** where you render your own "Login"
* button and call this from its `onClick` handler.
*/
login(): Promise;
/**
* Trigger the article purchase flow programmatically.
*
* Deducts the required credits from the user's balance and, on success,
* updates `state.hasAccess` to `true` and emits `article:purchased`.
*
* If the user is not logged in, this automatically opens the login flow
* first, then proceeds with the purchase.
*
* Primarily useful in **headless mode** where you render your own "Unlock"
* button and call this from its `onClick` handler.
*/
purchase(): Promise;
/**
* Open the Content Credits dashboard in a new tab so the user can top up
* their credit balance.
*
* Primarily useful in **headless mode** when `state.creditBalance` is lower
* than `state.requiredCredits`.
*/
buyMoreCredits(): void;
/** Subscribe to an SDK event. Returns an unsubscribe function. */
on(event: K, handler: SDKEventHandler): () => void;
/** Unsubscribe from an SDK event. */
off(event: K, handler: SDKEventHandler): void;
/** Get a snapshot of the current SDK state. */
getState(): SDKState;
/** Programmatically trigger an article access check. */
checkAccess(): Promise;
/** Open the comment panel programmatically. */
openComments(): void;
/** Close the comment panel programmatically. */
closeComments(): void;
/** Check if the user is currently authenticated. */
isLoggedIn(): boolean;
/**
* Return the current access token, or null if not authenticated.
*
* Use this to call your own server-side API routes that need to verify
* the user's identity with the Content Credits API before returning
* protected content — avoids ever sending premium content to the browser
* before access is confirmed.
*/
getToken(): string | null;
/**
* Log the current user out.
*
* Revokes the refresh token on the server (best-effort), clears all local
* auth state, resets SDK state, and emits `auth:logout`.
*/
logout(): Promise;
/** Tear down the SDK — removes all UI, event listeners, and stored state. */
destroy(): void;
/** SDK version string. */
static get version(): string;
}