import { Buffer as Buffer$1 } from "node:buffer"; import { IncomingMessage, Server, ServerResponse } from "node:http"; //#region src/processing/svg.d.ts declare function genSvgImage(x: number, y: number, size: number, radius: number, base64Image: string, imageFormat: ImageFormat, cropId: string): string; declare function generateBadge(x: number, y: number, sponsor: Sponsor, preset: BadgePreset, radius: number, imageFormat: ImageFormat, cropId: string): Promise; declare class SvgComposer { height: number; body: string; private cropId; readonly config: Required; constructor(config: Required); getNextCropId(): string; addSpan(height?: number): this; addTitle(text: string, classes?: string): this; addText(text: string, classes?: string): this; addRaw(svg: string): this; addSponsorLine(sponsors: Sponsorship[], preset: BadgePreset): Promise; addSponsorGrid(sponsors: Sponsorship[], preset: BadgePreset): Promise; generateSvg(): string; } //#endregion //#region src/types.d.ts type ImageFormat = 'png' | 'webp'; interface BadgePreset { boxWidth: number; boxHeight: number; avatar: { size: number; classes?: string; }; name?: false | { color?: string; classes?: string; maxLength?: number; }; container?: { sidePadding?: number; }; classes?: string; } interface TierPartition { monthlyDollars: number; tier: Tier; sponsors: Sponsorship[]; } interface Provider { name: string; fetchSponsors: (config: SponsorkitConfig) => Promise; } interface Sponsor { type: 'User' | 'Organization'; login: string; name: string; avatarUrl: string; avatarBuffer?: Buffer$1; websiteUrl?: string; linkUrl?: string; /** * Map of logins of other social accounts * * @example * ```json * { * 'github': 'antfu', * 'opencollective': 'antfu', * } * ``` * * This would allow us to merge sponsors from different platforms. */ socialLogins?: Record; } interface Sponsorship { sponsor: Sponsor; monthlyDollars: number; privacyLevel?: 'PUBLIC' | 'PRIVATE'; tierName?: string; createdAt?: string; expireAt?: string; isOneTime?: boolean; provider?: ProviderName | string; /** * Raw data from provider */ raw?: any; } declare const outputFormats: readonly ["svg", "png", "webp", "json"]; type OutputFormat = typeof outputFormats[number]; type ProviderName = 'github' | 'patreon' | 'opencollective' | 'afdian' | 'polar' | 'liberapay' | 'kofi'; type GitHubAccountType = 'user' | 'organization'; type SponsorshipMode = 'sponsors' | 'sponsees'; interface ProvidersConfig { github?: { /** * User id of your GitHub account. * * Will read from `SPONSORKIT_GITHUB_LOGIN` environment variable if not set. */ login?: string; /** * GitHub Token that have access to your sponsorships. * * Will read from `SPONSORKIT_GITHUB_TOKEN` environment variable if not set. * * @deprecated It's not recommended set this value directly, pass from env or use `.env` file. */ token?: string; /** * The account type for sponsorships. * * Possible values are `user`(default) and `organization`. * Will read from `SPONSORKIT_GITHUB_TYPE` environment variable if not set. */ type?: GitHubAccountType; }; patreon?: { /** * Patreon Token that have access to your sponsorships. * * Will read from `SPONSORKIT_PATREON_TOKEN` environment variable if not set. * * @deprecated It's not recommended set this value directly, pass from env or use `.env` file. */ token?: string; }; opencollective?: { /** * Api key of your OpenCollective account. * * Will read from `SPONSORKIT_OPENCOLLECTIVE_KEY` environment variable if not set. * * @deprecated It's not recommended set this value directly, pass from env or use `.env` file. */ key?: string; /** * The id of your account. * * Will read from `SPONSORKIT_OPENCOLLECTIVE_ID` environment variable if not set. */ id?: string; /** * The slug of your account. * * Will read from `SPONSORKIT_OPENCOLLECTIVE_SLUG` environment variable if not set. */ slug?: string; /** * The GitHub handle of your account. * * Will read from `SPONSORKIT_OPENCOLLECTIVE_GH_HANDLE` environment variable if not set. */ githubHandle?: string; type?: string; }; afdian?: { /** * The userId of your Afdian. * * Will read from `SPONSORKIT_AFDIAN_USER_ID` environment variable if not set. * * @see https://afdian.net/dashboard/dev */ userId?: string; /** * Afdian Token that have access to your sponsorships. * * Will read from `SPONSORKIT_AFDIAN_TOKEN` environment variable if not set. * * @see https://afdian.net/dashboard/dev * @deprecated It's not recommended set this value directly, pass from env or use `.env` file. */ token?: string; /** * Exchange rate of USD to CNY * * @default 6.5 */ exchangeRate?: number; /** * Include one-time purchases * @default true */ includePurchases?: boolean; /** * One-time purchase effectivity period in days * @default 30 */ purchaseEffectivity?: number; }; polar?: { /** * Polar token that have access to your sponsorships. * * Will read from `SPONSORKIT_POLAR_TOKEN` environment variable if not set. * * @see https://polar.sh/settings * @deprecated It's not recommended set this value directly, pass from env or use `.env` file. */ token?: string; /** * The name of the organization to fetch sponsorships from. If not set, it will fetch the sponsorships of the user. * * Will read from `SPONSORKIT_POLAR_ORGANIZATION` environment variable if not set. */ organization?: string; }; liberapay?: { /** * The name of the Liberapay profile. * * Will read from `SPONSORKIT_LIBERAPAY_LOGIN` environment variable if not set. */ login?: string; }; kofi?: { /** * Verification token included in Ko-fi webhook requests. * * Will read from `SPONSORKIT_KOFI_VERIFICATION_TOKEN` environment variable if not set. * * @deprecated It's not recommended set this value directly, pass from env or use `.env` file. */ verificationToken?: string; /** * Local event store populated by the `kofi-webhook` command. * * @default './sponsorkit/kofi-events.json' */ dataFile?: string; /** * Number of days one-time tips affect the current sponsorship tier. * Set to 0 to keep them active indefinitely. * * @default 30 */ tipEffectivity?: number; /** * Number of days after a subscription payment the membership is considered active. * Ko-fi does not send an event when a membership ends. * Set to 0 to keep subscriptions active indefinitely. * * @default 35 */ subscriptionEffectivity?: number; }; } interface SponsorkitRenderOptions { /** * Name of exported files * * @default config.mode */ name?: string; /** * Renderer to use * * @default 'tiers' */ renderer?: 'tiers' | 'circles'; /** * Output formats * * @default ['json', 'svg', 'png'] */ formats?: OutputFormat[]; /** * Compose the SVG */ customComposer?: (composer: SvgComposer, sponsors: Sponsorship[], config: SponsorkitConfig) => PromiseLike | void; /** * Filter of sponsorships to render in the final image. */ filter?: (sponsor: Sponsorship, all: Sponsorship[]) => boolean | void; /** * Tiers * * Only effective when using `tiers` renderer. */ tiers?: Tier[]; /** * Options for rendering circles * * Only effective when using `circles` renderer. */ circles?: CircleRenderOptions; /** * Width of the image. * * @default 800 */ width?: number; /** * Padding of image container */ padding?: { top?: number; bottom?: number; }; /** * Inline CSS of generated SVG */ svgInlineCSS?: string; /** * Whether to display the private sponsors * * @default false */ includePrivate?: boolean; /** * Whether to display the past sponsors * Currently only works with GitHub provider * * @default auto detect based on tiers */ includePastSponsors?: boolean; /** * Format of embedded images * * @default 'webp' */ imageFormat?: ImageFormat; /** * Hook to modify sponsors data before rendering. */ onBeforeRenderer?: (sponsors: Sponsorship[]) => PromiseLike | void | Sponsorship[]; /** * Hook to get or modify the SVG before writing. */ onSvgGenerated?: (svg: string) => PromiseLike | string | void | undefined | null; } interface SponsorkitConfig extends ProvidersConfig, SponsorkitRenderOptions { /** * Data mode: * - `sponsors`: people sponsoring you * - `sponsees`: people you have sponsored, including past sponsorships * * @default 'sponsors' */ mode?: SponsorshipMode; /** * @deprecated use `github.login` instead */ login?: string; /** * @deprecated use `github.token` instead */ token?: string; /** * @default auto detect based on the config provided */ providers?: (ProviderName | Provider)[]; /** * By pass cache */ force?: boolean; /** * Path to cache file * * @default './sponsorkit/.cache.json' */ cacheFile?: string; /** * Path to cache file used when `mode` is `sponsees`. * * @default './sponsorkit/.cache.sponsees.json' */ cacheFileSponsees?: string; /** * Directory of output files. * * @default './sponsorkit' */ outputDir?: string; /** * Replace links in the sponsors data. */ replaceLinks?: Record | (((sponsor: Sponsorship) => string) | Record)[]; /** * Replace avatar link in the sponsors data. */ replaceAvatars?: Record | (((sponsor: Sponsorship) => string) | Record)[]; /** * Merge multiple sponsors, useful for combining sponsors from different providers. * * @example * ```js * mergeSponsors: [ * // Array of sponsor matchers * [{ login: 'antfu', provider: 'github' }, { login: 'antfu', provider: 'patreon' }], * // custom functions to find matched sponsors * (sponsor, allSponsors) => { * return allSponsors.filter(s => s.sponsor.login === sponsor.sponsor.login) * } * ] * ``` */ mergeSponsors?: (SponsorMatcher[] | ((sponsor: Sponsorship, allSponsors: Sponsorship[]) => Sponsorship[] | void))[]; /** * Merge sponsorships from same sponsor on different providers, * based on their connection account on each platform. * * @default false */ sponsorsAutoMerge?: boolean; /** * Hook to modify sponsors data for each provider. */ onSponsorsFetched?: (sponsors: Sponsorship[], provider: ProviderName | string) => PromiseLike | void | Sponsorship[]; /** * Hook to modify merged sponsors data before fetching the avatars. */ onSponsorsAllFetched?: (sponsors: Sponsorship[]) => PromiseLike | void | Sponsorship[]; /** * Hook to modify sponsors data before rendering. */ onSponsorsReady?: (sponsors: Sponsorship[]) => PromiseLike | void | Sponsorship[]; /** * Url to fallback avatar. * Setting false to disable fallback avatar. */ fallbackAvatar?: string | false | Buffer$1 | Promise; /** * Configs for multiple renders */ renders?: SponsorkitRenderOptions[]; /** * Prorates one-time to the current month's tier */ prorateOnetime?: boolean; } interface SponsorMatcher extends Partial> { provider?: ProviderName | string; } type SponsorkitMainConfig = Omit; interface SponsorkitRenderer { name: string; renderSVG: (config: Required, sponsors: Sponsorship[]) => Promise; } interface CircleRenderOptions { /** * Min radius for sponsors * * @default 10 */ radiusMin?: number; /** * Max radius for sponsors * * @default 300 */ radiusMax?: number; /** * Radius for past sponsors * * @default 5 */ radiusPast?: number; /** * Custom function to calculate the weight of the sponsor. * * When provided, `radiusMin`, `radiusMax` and `radiusPast` will be ignored. */ weightInterop?: (sponsor: Sponsorship, maxAmount: number) => number; } interface Tier { /** * The lower bound of the tier (inclusive) */ monthlyDollars?: number; title?: string; preset?: BadgePreset; padding?: { top?: number; bottom?: number; }; /** * Replace the default composer with your own. */ compose?: (composer: SvgComposer, sponsors: Sponsorship[], config: SponsorkitConfig) => void; /** * Compose the SVG before the main composer. */ composeBefore?: (composer: SvgComposer, tierSponsors: Sponsorship[], config: SponsorkitConfig) => void; /** * Compose the SVG after the main composer. */ composeAfter?: (composer: SvgComposer, tierSponsors: Sponsorship[], config: SponsorkitConfig) => void; } //#endregion //#region src/configs/defaults.d.ts declare const defaultTiers: Tier[]; declare const defaultInlineCSS = "\ntext {\n font-weight: 300;\n font-size: 14px;\n fill: #777777;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n}\n.sponsorkit-link {\n cursor: pointer;\n}\n.sponsorkit-tier-title {\n font-weight: 500;\n font-size: 20px;\n}\n"; declare const defaultConfig: SponsorkitConfig; //#endregion //#region src/configs/fallback.d.ts declare const FALLBACK_AVATAR: Promise>; //#endregion //#region src/configs/tier-presets.d.ts declare const tierPresets: { none: BadgePreset; xs: BadgePreset; small: BadgePreset; base: BadgePreset; medium: BadgePreset; large: BadgePreset; xl: BadgePreset; }; /** * @deprecated Use `tierPresets` instead */ declare const presets: { none: BadgePreset; xs: BadgePreset; small: BadgePreset; base: BadgePreset; medium: BadgePreset; large: BadgePreset; xl: BadgePreset; }; //#endregion //#region src/configs/index.d.ts declare function defineConfig(config: SponsorkitConfig): SponsorkitConfig; declare function loadConfig(inlineConfig?: SponsorkitConfig): Promise>; declare function partitionTiers(sponsors: Sponsorship[], tiers: Tier[], includePastSponsors?: boolean): TierPartition[]; //#endregion //#region src/processing/image.d.ts declare function resolveAvatars(ships: Sponsorship[], getFallbackAvatar: SponsorkitConfig['fallbackAvatar'], t?: import("consola").ConsolaInstance): Promise; declare function resizeImage(image: Buffer$1, size: number | undefined, format: ImageFormat): Promise>; declare function svgToPng(svg: string): Promise>; declare function svgToWebp(svg: string): Promise>; //#endregion //#region src/providers/github.d.ts declare const GitHubProvider: Provider; declare function fetchGitHubSponsors(token: string, login: string, type: GitHubAccountType, config: SponsorkitConfig): Promise; declare function makeQuery(login: string, type: GitHubAccountType, activeOnly?: boolean, cursor?: string): string; interface GitHubSponsoringRecord { sponsorable: { type: 'User' | 'Organization'; login: string; name: string; avatarUrl: string; websiteUrl?: string; linkUrl: string; }; monthlyDollars: number; monthlyCents: number; tierName: string; isOneTime: boolean; privacyLevel?: 'PUBLIC' | 'PRIVATE'; createdAt: string; isActive: boolean; raw: any; } interface GitHubSponsoringTotalOptions { since?: string; until?: string; sponsorableLogins?: string[]; } declare function fetchGitHubSponsoring(token: string, login: string, type: GitHubAccountType, activeOnly?: boolean): Promise; declare function fetchGitHubSponsoringAsSponsorships(token: string, login: string, type: GitHubAccountType): Promise; declare function fetchGitHubTotalSponsorshipAmountAsSponsor(token: string, login: string, type: GitHubAccountType, options?: GitHubSponsoringTotalOptions): Promise; declare function makeSponsoringQuery(login: string, type: GitHubAccountType, activeOnly?: boolean, cursor?: string): string; declare function makeSponsoringTotalAmountQuery(login: string, type: GitHubAccountType, options?: GitHubSponsoringTotalOptions): string; //#endregion //#region src/providers/kofi.d.ts declare const DEFAULT_KOFI_DATA_FILE = "./sponsorkit/kofi-events.json"; interface KofiWebhookPayload { verification_token?: string; message_id?: string; timestamp?: string; type?: string; is_public?: boolean | string; from_name?: string; message?: string; amount?: string; url?: string; email?: string; currency?: string; is_subscription_payment?: boolean | string; is_first_subscription_payment?: boolean | string; tier_name?: string; kofi_transaction_id?: string; [key: string]: unknown; } interface StoredKofiEvent { messageId: string; sponsorKey: string; timestamp: string; type: string; isPublic: boolean; fromName: string; amount: number; currency: string; isSubscriptionPayment: boolean; isFirstSubscriptionPayment: boolean; tierName?: string; transactionId?: string; } interface KofiWebhookServerOptions { verificationToken: string; dataFile?: string; host?: string; port?: number; path?: string; } declare const KofiProvider: Provider; declare function parseKofiWebhookBody(body: string, verificationToken: string): StoredKofiEvent; declare function storeKofiEvent(event: StoredKofiEvent, dataFile?: string): Promise; declare function fetchKofiSponsors(options?: SponsorkitConfig['kofi'], now?: number): Promise; declare function createKofiWebhookHandler(options: KofiWebhookServerOptions): (request: IncomingMessage, response: ServerResponse) => Promise; declare function startKofiWebhookServer(options: KofiWebhookServerOptions): Promise; //#endregion //#region src/providers/index.d.ts declare const ProvidersMap: { github: Provider; patreon: Provider; opencollective: Provider; afdian: Provider; polar: Provider; liberapay: Provider; kofi: Provider; }; declare function guessProviders(config: SponsorkitConfig): ProviderName[]; declare function resolveProviders(names: (ProviderName | Provider)[]): Provider[]; declare function fetchSponsors(config: SponsorkitConfig): Promise; //#endregion export { BadgePreset, CircleRenderOptions, DEFAULT_KOFI_DATA_FILE, FALLBACK_AVATAR, GitHubAccountType, GitHubProvider, GitHubSponsoringRecord, GitHubSponsoringTotalOptions, ImageFormat, KofiProvider, KofiWebhookPayload, KofiWebhookServerOptions, OutputFormat, Provider, ProviderName, ProvidersConfig, ProvidersMap, Sponsor, SponsorMatcher, SponsorkitConfig, SponsorkitMainConfig, SponsorkitRenderOptions, SponsorkitRenderer, Sponsorship, SponsorshipMode, StoredKofiEvent, SvgComposer, Tier, TierPartition, createKofiWebhookHandler, defaultConfig, defaultInlineCSS, defaultTiers, defineConfig, fetchGitHubSponsoring, fetchGitHubSponsoringAsSponsorships, fetchGitHubSponsors, fetchGitHubTotalSponsorshipAmountAsSponsor, fetchKofiSponsors, fetchSponsors, genSvgImage, generateBadge, guessProviders, loadConfig, makeQuery, makeSponsoringQuery, makeSponsoringTotalAmountQuery, outputFormats, parseKofiWebhookBody, partitionTiers, presets, resizeImage, resolveAvatars, resolveProviders, startKofiWebhookServer, storeKofiEvent, svgToPng, svgToWebp, tierPresets };