@lizardbyte/contribkit 2025.315.185528

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,494 @@
1
+ import { Buffer as Buffer$1 } from 'node:buffer';
2
+ import * as consola from 'consola';
3
+
4
+ declare function genSvgImage(x: number, y: number, size: number, radius: number, base64Image: string, imageFormat: ImageFormat): string;
5
+ declare function generateBadge(x: number, y: number, sponsor: Sponsor, preset: BadgePreset, radius: number, imageFormat: ImageFormat): Promise<string>;
6
+ declare class SvgComposer {
7
+ readonly config: Required<ContribkitRenderOptions>;
8
+ height: number;
9
+ body: string;
10
+ constructor(config: Required<ContribkitRenderOptions>);
11
+ addSpan(height?: number): this;
12
+ addTitle(text: string, classes?: string): this;
13
+ addText(text: string, classes?: string): this;
14
+ addRaw(svg: string): this;
15
+ addSponsorLine(sponsors: Sponsorship[], preset: BadgePreset): Promise<void>;
16
+ addSponsorGrid(sponsors: Sponsorship[], preset: BadgePreset): Promise<this>;
17
+ generateSvg(): string;
18
+ }
19
+
20
+ type ImageFormat = 'png' | 'webp';
21
+ interface BadgePreset {
22
+ boxWidth: number;
23
+ boxHeight: number;
24
+ avatar: {
25
+ size: number;
26
+ classes?: string;
27
+ };
28
+ name?: false | {
29
+ color?: string;
30
+ classes?: string;
31
+ maxLength?: number;
32
+ };
33
+ container?: {
34
+ sidePadding?: number;
35
+ };
36
+ classes?: string;
37
+ }
38
+ interface TierPartition {
39
+ monthlyDollars: number;
40
+ tier: Tier;
41
+ sponsors: Sponsorship[];
42
+ }
43
+ interface Provider {
44
+ name: string;
45
+ fetchSponsors: (config: ContribkitConfig) => Promise<Sponsorship[]>;
46
+ }
47
+ interface Sponsor {
48
+ type: 'User' | 'Organization';
49
+ login: string;
50
+ name: string;
51
+ avatarUrl: string;
52
+ avatarBuffer?: Buffer$1;
53
+ websiteUrl?: string;
54
+ linkUrl?: string;
55
+ /**
56
+ * Map of logins of other social accounts
57
+ *
58
+ * @example
59
+ * ```json
60
+ * {
61
+ * 'github': 'antfu',
62
+ * 'opencollective': 'antfu',
63
+ * }
64
+ * ```
65
+ *
66
+ * This would allow us to merge sponsors from different platforms.
67
+ */
68
+ socialLogins?: Record<string, string>;
69
+ }
70
+ interface Sponsorship {
71
+ sponsor: Sponsor;
72
+ monthlyDollars: number;
73
+ privacyLevel?: 'PUBLIC' | 'PRIVATE';
74
+ tierName?: string;
75
+ createdAt?: string;
76
+ expireAt?: string;
77
+ isOneTime?: boolean;
78
+ provider?: ProviderName | string;
79
+ /**
80
+ * Raw data from provider
81
+ */
82
+ raw?: any;
83
+ }
84
+ declare const outputFormats: readonly ["svg", "png", "webp", "json"];
85
+ type OutputFormat = typeof outputFormats[number];
86
+ type ProviderName = 'github' | 'patreon' | 'opencollective' | 'afdian' | 'polar' | 'liberapay';
87
+ type GitHubAccountType = 'user' | 'organization';
88
+ interface ProvidersConfig {
89
+ github?: {
90
+ /**
91
+ * User id of your GitHub account.
92
+ *
93
+ * Will read from `CONTRIBKIT_GITHUB_LOGIN` environment variable if not set.
94
+ */
95
+ login?: string;
96
+ /**
97
+ * GitHub Token that have access to your sponsorships.
98
+ *
99
+ * Will read from `CONTRIBKIT_GITHUB_TOKEN` environment variable if not set.
100
+ *
101
+ * @deprecated It's not recommended set this value directly, pass from env or use `.env` file.
102
+ */
103
+ token?: string;
104
+ /**
105
+ * The account type for sponsorships.
106
+ *
107
+ * Possible values are `user`(default) and `organization`.
108
+ * Will read from `CONTRIBKIT_GITHUB_TYPE` environment variable if not set.
109
+ */
110
+ type?: GitHubAccountType;
111
+ };
112
+ patreon?: {
113
+ /**
114
+ * Patreon Token that have access to your sponsorships.
115
+ *
116
+ * Will read from `CONTRIBKIT_PATREON_TOKEN` environment variable if not set.
117
+ *
118
+ * @deprecated It's not recommended set this value directly, pass from env or use `.env` file.
119
+ */
120
+ token?: string;
121
+ };
122
+ opencollective?: {
123
+ /**
124
+ * Api key of your OpenCollective account.
125
+ *
126
+ * Will read from `CONTRIBKIT_OPENCOLLECTIVE_KEY` environment variable if not set.
127
+ *
128
+ * @deprecated It's not recommended set this value directly, pass from env or use `.env` file.
129
+ */
130
+ key?: string;
131
+ /**
132
+ * The id of your account.
133
+ *
134
+ * Will read from `CONTRIBKIT_OPENCOLLECTIVE_ID` environment variable if not set.
135
+ */
136
+ id?: string;
137
+ /**
138
+ * The slug of your account.
139
+ *
140
+ * Will read from `CONTRIBKIT_OPENCOLLECTIVE_SLUG` environment variable if not set.
141
+ */
142
+ slug?: string;
143
+ /**
144
+ * The GitHub handle of your account.
145
+ *
146
+ * Will read from `CONTRIBKIT_OPENCOLLECTIVE_GH_HANDLE` environment variable if not set.
147
+ */
148
+ githubHandle?: string;
149
+ type?: string;
150
+ };
151
+ afdian?: {
152
+ /**
153
+ * The userId of your Afdian.
154
+ *
155
+ * Will read from `CONTRIBKIT_AFDIAN_USER_ID` environment variable if not set.
156
+ *
157
+ * @see https://afdian.net/dashboard/dev
158
+ */
159
+ userId?: string;
160
+ /**
161
+ * Afdian Token that have access to your sponsorships.
162
+ *
163
+ * Will read from `CONTRIBKIT_AFDIAN_TOKEN` environment variable if not set.
164
+ *
165
+ * @see https://afdian.net/dashboard/dev
166
+ * @deprecated It's not recommended set this value directly, pass from env or use `.env` file.
167
+ */
168
+ token?: string;
169
+ /**
170
+ * Exchange rate of USD to CNY
171
+ *
172
+ * @default 6.5
173
+ */
174
+ exechangeRate?: number;
175
+ /**
176
+ * Include one-time purchases
177
+ * @default true
178
+ */
179
+ includePurchases?: boolean;
180
+ /**
181
+ * One-time purchase effectivity period in days
182
+ * @default 30
183
+ */
184
+ purchaseEffectivity?: number;
185
+ };
186
+ polar?: {
187
+ /**
188
+ * Polar token that have access to your sponsorships.
189
+ *
190
+ * Will read from `CONTRIBKIT_POLAR_TOKEN` environment variable if not set.
191
+ *
192
+ * @see https://polar.sh/settings
193
+ * @deprecated It's not recommended set this value directly, pass from env or use `.env` file.
194
+ */
195
+ token?: string;
196
+ /**
197
+ * The name of the organization to fetch sponsorships from. If not set, it will fetch the sponsorships of the user.
198
+ *
199
+ * Will read from `CONTRIBKIT_POLAR_ORGANIZATION` environment variable if not set.
200
+ */
201
+ organization?: string;
202
+ };
203
+ liberapay?: {
204
+ /**
205
+ * The name of the Liberapay profile.
206
+ *
207
+ * Will read from `CONTRIBKIT_LIBERAPAY_LOGIN` environment variable if not set.
208
+ */
209
+ login?: string;
210
+ };
211
+ }
212
+ interface ContribkitRenderOptions {
213
+ /**
214
+ * Name of exported files
215
+ *
216
+ * @default 'sponsors'
217
+ */
218
+ name?: string;
219
+ /**
220
+ * Renderer to use
221
+ *
222
+ * @default 'tiers'
223
+ */
224
+ renderer?: 'tiers' | 'circles';
225
+ /**
226
+ * Output formats
227
+ *
228
+ * @default ['json', 'svg', 'png']
229
+ */
230
+ formats?: OutputFormat[];
231
+ /**
232
+ * Compose the SVG
233
+ */
234
+ customComposer?: (composer: SvgComposer, sponsors: Sponsorship[], config: ContribkitConfig) => PromiseLike<void> | void;
235
+ /**
236
+ * Filter of sponsorships to render in the final image.
237
+ */
238
+ filter?: (sponsor: Sponsorship, all: Sponsorship[]) => boolean | void;
239
+ /**
240
+ * Tiers
241
+ *
242
+ * Only effective when using `tiers` renderer.
243
+ */
244
+ tiers?: Tier[];
245
+ /**
246
+ * Options for rendering circles
247
+ *
248
+ * Only effective when using `circles` renderer.
249
+ */
250
+ circles?: CircleRenderOptions;
251
+ /**
252
+ * Width of the image.
253
+ *
254
+ * @default 800
255
+ */
256
+ width?: number;
257
+ /**
258
+ * Padding of image container
259
+ */
260
+ padding?: {
261
+ top?: number;
262
+ bottom?: number;
263
+ };
264
+ /**
265
+ * Inline CSS of generated SVG
266
+ */
267
+ svgInlineCSS?: string;
268
+ /**
269
+ * Whether to display the private sponsors
270
+ *
271
+ * @default false
272
+ */
273
+ includePrivate?: boolean;
274
+ /**
275
+ * Whether to display the past sponsors
276
+ * Currently only works with GitHub provider
277
+ *
278
+ * @default auto detect based on tiers
279
+ */
280
+ includePastSponsors?: boolean;
281
+ /**
282
+ * Format of embedded images
283
+ *
284
+ * @default 'webp'
285
+ */
286
+ imageFormat?: ImageFormat;
287
+ /**
288
+ * Hook to modify sponsors data before rendering.
289
+ */
290
+ onBeforeRenderer?: (sponsors: Sponsorship[]) => PromiseLike<void | Sponsorship[]> | void | Sponsorship[];
291
+ /**
292
+ * Hook to get or modify the SVG before writing.
293
+ */
294
+ onSvgGenerated?: (svg: string) => PromiseLike<string | void | undefined | null> | string | void | undefined | null;
295
+ }
296
+ interface ContribkitConfig extends ProvidersConfig, ContribkitRenderOptions {
297
+ /**
298
+ * @deprecated use `github.login` instead
299
+ */
300
+ login?: string;
301
+ /**
302
+ * @deprecated use `github.token` instead
303
+ */
304
+ token?: string;
305
+ /**
306
+ * @default auto detect based on the config provided
307
+ */
308
+ providers?: (ProviderName | Provider)[];
309
+ /**
310
+ * By pass cache
311
+ */
312
+ force?: boolean;
313
+ /**
314
+ * Path to cache file
315
+ *
316
+ * @default './contribkit/.cache.json'
317
+ */
318
+ cacheFile?: string;
319
+ /**
320
+ * Directory of output files.
321
+ *
322
+ * @default './contribkit'
323
+ */
324
+ outputDir?: string;
325
+ /**
326
+ * Replace links in the sponsors data.
327
+ */
328
+ replaceLinks?: Record<string, string> | (((sponsor: Sponsorship) => string) | Record<string, string>)[];
329
+ /**
330
+ * Replace avatar link in the sponsors data.
331
+ */
332
+ replaceAvatars?: Record<string, string> | (((sponsor: Sponsorship) => string) | Record<string, string>)[];
333
+ /**
334
+ * Merge multiple sponsors, useful for combining sponsors from different providers.
335
+ *
336
+ * @example
337
+ * ```js
338
+ * mergeSponsors: [
339
+ * // Array of sponsor matchers
340
+ * [{ login: 'antfu', provider: 'github' }, { login: 'antfu', provider: 'patreon' }],
341
+ * // custom functions to find matched sponsors
342
+ * (sponsor, allSponsors) => {
343
+ * return allSponsors.filter(s => s.sponsor.login === sponsor.sponsor.login)
344
+ * }
345
+ * ]
346
+ * ```
347
+ */
348
+ mergeSponsors?: (SponsorMatcher[] | ((sponsor: Sponsorship, allSponsors: Sponsorship[]) => Sponsorship[] | void))[];
349
+ /**
350
+ * Merge sponsorships from same sponsor on different providers,
351
+ * based on their connection account on each platform.
352
+ *
353
+ * @default false
354
+ */
355
+ sponsorsAutoMerge?: boolean;
356
+ /**
357
+ * Hook to modify sponsors data for each provider.
358
+ */
359
+ onSponsorsFetched?: (sponsors: Sponsorship[], provider: ProviderName | string) => PromiseLike<void | Sponsorship[]> | void | Sponsorship[];
360
+ /**
361
+ * Hook to modify merged sponsors data before fetching the avatars.
362
+ */
363
+ onSponsorsAllFetched?: (sponsors: Sponsorship[]) => PromiseLike<void | Sponsorship[]> | void | Sponsorship[];
364
+ /**
365
+ * Hook to modify sponsors data before rendering.
366
+ */
367
+ onSponsorsReady?: (sponsors: Sponsorship[]) => PromiseLike<void | Sponsorship[]> | void | Sponsorship[];
368
+ /**
369
+ * Url to fallback avatar.
370
+ * Setting false to disable fallback avatar.
371
+ */
372
+ fallbackAvatar?: string | false | Buffer$1 | Promise<Buffer$1>;
373
+ /**
374
+ * Configs for multiple renders
375
+ */
376
+ renders?: ContribkitRenderOptions[];
377
+ /**
378
+ * Prorates one-time to the current month's tier
379
+ */
380
+ prorateOnetime?: boolean;
381
+ }
382
+ interface SponsorMatcher extends Partial<Pick<Sponsor, 'login' | 'name' | 'type'>> {
383
+ provider?: ProviderName | string;
384
+ }
385
+ type ContribkitMainConfig = Omit<ContribkitConfig, keyof ContribkitRenderOptions>;
386
+ interface ContribkitRenderer {
387
+ name: string;
388
+ renderSVG: (config: Required<ContribkitRenderOptions>, sponsors: Sponsorship[]) => Promise<string>;
389
+ }
390
+ interface CircleRenderOptions {
391
+ /**
392
+ * Min radius for sponsors
393
+ *
394
+ * @default 10
395
+ */
396
+ radiusMin?: number;
397
+ /**
398
+ * Max radius for sponsors
399
+ *
400
+ * @default 300
401
+ */
402
+ radiusMax?: number;
403
+ /**
404
+ * Radius for past sponsors
405
+ *
406
+ * @default 5
407
+ */
408
+ radiusPast?: number;
409
+ /**
410
+ * Custom function to calculate the weight of the sponsor.
411
+ *
412
+ * When provided, `radiusMin`, `radiusMax` and `radiusPast` will be ignored.
413
+ */
414
+ weightInterop?: (sponsor: Sponsorship, maxAmount: number) => number;
415
+ }
416
+ interface Tier {
417
+ /**
418
+ * The lower bound of the tier (inclusive)
419
+ */
420
+ monthlyDollars?: number;
421
+ title?: string;
422
+ preset?: BadgePreset;
423
+ padding?: {
424
+ top?: number;
425
+ bottom?: number;
426
+ };
427
+ /**
428
+ * Replace the default composer with your own.
429
+ */
430
+ compose?: (composer: SvgComposer, sponsors: Sponsorship[], config: ContribkitConfig) => void;
431
+ /**
432
+ * Compose the SVG before the main composer.
433
+ */
434
+ composeBefore?: (composer: SvgComposer, tierSponsors: Sponsorship[], config: ContribkitConfig) => void;
435
+ /**
436
+ * Compose the SVG after the main composer.
437
+ */
438
+ composeAfter?: (composer: SvgComposer, tierSponsors: Sponsorship[], config: ContribkitConfig) => void;
439
+ }
440
+
441
+ declare const defaultTiers: Tier[];
442
+ 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.contribkit-link {\n cursor: pointer;\n}\n.contribkit-tier-title {\n font-weight: 500;\n font-size: 20px;\n}\n";
443
+ declare const defaultConfig: ContribkitConfig;
444
+
445
+ declare const FALLBACK_AVATAR: Promise<Buffer<ArrayBufferLike>>;
446
+
447
+ declare const tierPresets: {
448
+ none: BadgePreset;
449
+ xs: BadgePreset;
450
+ small: BadgePreset;
451
+ base: BadgePreset;
452
+ medium: BadgePreset;
453
+ large: BadgePreset;
454
+ xl: BadgePreset;
455
+ };
456
+ /**
457
+ * @deprecated Use `tierPresets` instead
458
+ */
459
+ declare const presets: {
460
+ none: BadgePreset;
461
+ xs: BadgePreset;
462
+ small: BadgePreset;
463
+ base: BadgePreset;
464
+ medium: BadgePreset;
465
+ large: BadgePreset;
466
+ xl: BadgePreset;
467
+ };
468
+
469
+ declare function defineConfig(config: ContribkitConfig): ContribkitConfig;
470
+ declare function loadConfig(inlineConfig?: ContribkitConfig): Promise<Required<ContribkitConfig>>;
471
+ declare function partitionTiers(sponsors: Sponsorship[], tiers: Tier[], includePastSponsors?: boolean): TierPartition[];
472
+
473
+ declare function resolveAvatars(ships: Sponsorship[], getFallbackAvatar: ContribkitConfig['fallbackAvatar'], t?: consola.ConsolaInstance): Promise<void[]>;
474
+ declare function resizeImage(image: Buffer$1, size: number | undefined, format: ImageFormat): Promise<Buffer$1<ArrayBufferLike>>;
475
+ declare function svgToPng(svg: string): Promise<Buffer$1<ArrayBufferLike>>;
476
+ declare function svgToWebp(svg: string): Promise<Buffer$1<ArrayBufferLike>>;
477
+
478
+ declare const GitHubProvider: Provider;
479
+ declare function fetchGitHubSponsors(token: string, login: string, type: GitHubAccountType, config: ContribkitConfig): Promise<Sponsorship[]>;
480
+ declare function makeQuery(login: string, type: GitHubAccountType, activeOnly?: boolean, cursor?: string): string;
481
+
482
+ declare const ProvidersMap: {
483
+ github: Provider;
484
+ patreon: Provider;
485
+ opencollective: Provider;
486
+ afdian: Provider;
487
+ polar: Provider;
488
+ liberapay: Provider;
489
+ };
490
+ declare function guessProviders(config: ContribkitConfig): ProviderName[];
491
+ declare function resolveProviders(names: (ProviderName | Provider)[]): Provider[];
492
+ declare function fetchSponsors(config: ContribkitConfig): Promise<Sponsorship[]>;
493
+
494
+ export { type BadgePreset, type CircleRenderOptions, type ContribkitConfig, type ContribkitMainConfig, type ContribkitRenderOptions, type ContribkitRenderer, FALLBACK_AVATAR, type GitHubAccountType, GitHubProvider, type ImageFormat, type OutputFormat, type Provider, type ProviderName, type ProvidersConfig, ProvidersMap, type Sponsor, type SponsorMatcher, type Sponsorship, SvgComposer, type Tier, type TierPartition, defaultConfig, defaultInlineCSS, defaultTiers, defineConfig, fetchGitHubSponsors, fetchSponsors, genSvgImage, generateBadge, guessProviders, loadConfig, makeQuery, outputFormats, partitionTiers, presets, resizeImage, resolveAvatars, resolveProviders, svgToPng, svgToWebp, tierPresets };
package/dist/index.mjs ADDED
@@ -0,0 +1,9 @@
1
+ export { F as FALLBACK_AVATAR, G as GitHubProvider, P as ProvidersMap, S as SvgComposer, c as defaultConfig, b as defaultInlineCSS, a as defaultTiers, d as defineConfig, n as fetchGitHubSponsors, m as fetchSponsors, h as genSvgImage, i as generateBadge, j as guessProviders, l as loadConfig, o as makeQuery, q as outputFormats, p as partitionTiers, e as presets, f as resizeImage, r as resolveAvatars, k as resolveProviders, s as svgToPng, g as svgToWebp, t as tierPresets } from './shared/contribkit.QISHqB4U.mjs';
2
+ import 'unconfig';
3
+ import 'node:process';
4
+ import 'dotenv';
5
+ import 'node:buffer';
6
+ import 'consola';
7
+ import 'ofetch';
8
+ import 'sharp';
9
+ import 'node:crypto';