@dytsou/github-readme-stats 1.0.1 → 1.1.0

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.
Files changed (4) hide show
  1. package/API.md +525 -0
  2. package/openapi.yaml +923 -0
  3. package/package.json +8 -6
  4. package/readme.md +13 -1
package/API.md ADDED
@@ -0,0 +1,525 @@
1
+ # API Documentation
2
+
3
+ This document provides comprehensive documentation for all API endpoints available in the GitHub Readme Stats service.
4
+
5
+ > **OpenAPI Specification:** This API is also documented using the OpenAPI 3.1.0 specification. See [openapi.yaml](openapi.yaml) for the machine-readable API specification that can be used with tools like Swagger UI, Postman, or code generators.
6
+
7
+ ## Base URL
8
+
9
+ All endpoints are relative to your deployed instance. For example:
10
+ - `https://your-instance.workers.dev/api`
11
+ - `https://your-instance.vercel.app/api`
12
+
13
+ ## Response Format
14
+
15
+ All card endpoints return SVG images with `Content-Type: image/svg+xml; charset=utf-8`.
16
+
17
+ Status endpoints return JSON with `Content-Type: application/json`.
18
+
19
+ ## Common Parameters
20
+
21
+ These parameters are available across all card endpoints:
22
+
23
+ | Parameter | Type | Description | Default |
24
+ |-----------|------|-------------|---------|
25
+ | `theme` | string | Theme name (see [themes](themes/README.md)) | `default` |
26
+ | `bg_color` | string | Background color (hex, without `#`) | Theme default |
27
+ | `title_color` | string | Title color (hex, without `#`) | Theme default |
28
+ | `text_color` | string | Text color (hex, without `#`) | Theme default |
29
+ | `border_color` | string | Border color (hex, without `#`) | Theme default |
30
+ | `hide_border` | boolean | Hide card border | `false` |
31
+ | `border_radius` | number | Border radius (0-50) | `4.5` |
32
+ | `cache_seconds` | number | Cache duration in seconds | Card-specific default |
33
+ | `locale` | string | Language locale code | `en` |
34
+
35
+ ### Supported Locales
36
+
37
+ `ar`, `az`, `bn`, `bg`, `my`, `ca`, `cn`, `zh-tw`, `cs`, `nl`, `en`, `fil`, `fi`, `fr`, `de`, `el`, `he`, `hi`, `hu`, `id`, `it`, `ja`, `kr`, `ml`, `np`, `no`, `fa`, `pl`, `pt-br`, `pt-pt`, `ro`, `ru`, `sa`, `sr`, `sr-latn`, `sk`, `es`, `sw`, `se`, `ta`, `th`, `tr`, `uk-ua`, `ur`, `uz`, `vi`
38
+
39
+ ### Cache Durations
40
+
41
+ Default cache durations (can be overridden with `cache_seconds`):
42
+
43
+ - **Stats Card**: 24 hours (86400 seconds)
44
+ - **Top Languages Card**: 6 days (518400 seconds)
45
+ - **Repository Card**: 10 days (864000 seconds)
46
+ - **Gist Card**: 2 days (172800 seconds)
47
+ - **WakaTime Card**: 24 hours (86400 seconds)
48
+
49
+ Minimum cache duration: 12 hours (43200 seconds)
50
+ Maximum cache duration: 10 days (864000 seconds)
51
+
52
+ ---
53
+
54
+ ## Endpoints
55
+
56
+ ### 1. Stats Card
57
+
58
+ Generate a GitHub statistics card showing stars, commits, pull requests, and more.
59
+
60
+ **Endpoint:** `GET /api`
61
+
62
+ **Required Parameters:**
63
+
64
+ | Parameter | Type | Description |
65
+ |-----------|------|-------------|
66
+ | `username` | string | GitHub username |
67
+
68
+ **Optional Parameters:**
69
+
70
+ | Parameter | Type | Description | Default |
71
+ |-----------|------|-------------|---------|
72
+ | `hide` | string | Comma-separated list of stats to hide (`stars`, `commits`, `prs`, `contribs`, `issues`, `reviews`, `discussions_started`, `discussions_answered`) | - |
73
+ | `show` | string | Comma-separated list of additional stats to show (`reviews`, `discussions_started`, `discussions_answered`, `prs_merged`, `prs_merged_percentage`) | - |
74
+ | `hide_title` | boolean | Hide card title | `false` |
75
+ | `hide_rank` | boolean | Hide rank badge | `false` |
76
+ | `rank_icon` | string | Rank icon style (`default`, `github`, `percentile`) | `default` |
77
+ | `show_icons` | boolean | Display icons | `false` |
78
+ | `card_width` | number | Card width in pixels | `500` |
79
+ | `include_all_commits` | boolean | Count all commits (not just current year) | `false` |
80
+ | `commits_year` | number | Filter commits by year | Current year |
81
+ | `exclude_repo` | string | Comma-separated list of repositories to exclude | - |
82
+ | `custom_title` | string | Custom card title | `<username> GitHub Stats` |
83
+ | `number_format` | string | Number format (`short` or `long`) | `short` |
84
+ | `number_precision` | number | Number precision | - |
85
+ | `line_height` | number | Line height | - |
86
+ | `ring_color` | string | Ring color (hex, without `#`) | - |
87
+ | `icon_color` | string | Icon color (hex, without `#`) | - |
88
+ | `text_bold` | boolean | Make text bold | `false` |
89
+ | `disable_animations` | boolean | Disable animations | `false` |
90
+
91
+ **Example Request:**
92
+
93
+ ```
94
+ GET /api?username=NAME&theme=dark&show_icons=true&hide=contribs,prs
95
+ ```
96
+
97
+ **Example Response:**
98
+
99
+ SVG image with GitHub statistics card.
100
+
101
+ ---
102
+
103
+ ### 2. Top Languages Card
104
+
105
+ Display the most frequently used programming languages.
106
+
107
+ **Endpoint:** `GET /api/top-langs`
108
+
109
+ **Required Parameters:**
110
+
111
+ | Parameter | Type | Description |
112
+ |-----------|------|-------------|
113
+ | `username` | string | GitHub username |
114
+
115
+ **Optional Parameters:**
116
+
117
+ | Parameter | Type | Description | Default |
118
+ |-----------|------|-------------|---------|
119
+ | `layout` | string | Layout style (`normal`, `compact`, `donut`, `donut-vertical`, `pie`) | `normal` |
120
+ | `langs_count` | number | Number of languages to show (1-20) | `5` |
121
+ | `hide` | string | Comma-separated list of languages to hide | - |
122
+ | `exclude_repo` | string | Comma-separated list of repositories to exclude | - |
123
+ | `size_weight` | number | Weight for byte count in ranking | `1` |
124
+ | `count_weight` | number | Weight for repo count in ranking | `0` |
125
+ | `stats_format` | string | Display format (`percentages` or `bytes`) | `percentages` |
126
+ | `hide_progress` | boolean | Hide progress bars | `false` |
127
+ | `hide_title` | boolean | Hide card title | `false` |
128
+ | `card_width` | number | Card width in pixels | `500` |
129
+ | `custom_title` | string | Custom card title | - |
130
+ | `disable_animations` | boolean | Disable animations | `false` |
131
+
132
+ **Language Ranking Algorithm:**
133
+
134
+ Languages are ranked using:
135
+ ```
136
+ ranking_index = (byte_count ^ size_weight) * (repo_count ^ count_weight)
137
+ ```
138
+
139
+ - **Default** (`size_weight=1, count_weight=0`): Orders by byte count
140
+ - **Recommended** (`size_weight=0.5, count_weight=0.5`): Uses both byte and repo count
141
+ - **Repo-based** (`size_weight=0, count_weight=1`): Orders by repo count
142
+
143
+ **Example Request:**
144
+
145
+ ```
146
+ GET /api/top-langs?username=NAME&layout=compact&langs_count=8
147
+ ```
148
+
149
+ **Example Response:**
150
+
151
+ SVG image with top languages card.
152
+
153
+ ---
154
+
155
+ ### 3. Repository Card
156
+
157
+ Pin additional repositories beyond GitHub's 6-repo limit.
158
+
159
+ **Endpoint:** `GET /api/pin`
160
+
161
+ **Required Parameters:**
162
+
163
+ | Parameter | Type | Description |
164
+ |-----------|------|-------------|
165
+ | `username` | string | GitHub username |
166
+ | `repo` | string | Repository name |
167
+
168
+ **Optional Parameters:**
169
+
170
+ | Parameter | Type | Description | Default |
171
+ |-----------|------|-------------|---------|
172
+ | `show_owner` | boolean | Show repository owner | `false` |
173
+ | `description_lines_count` | number | Number of description lines (1-3) | Auto |
174
+
175
+ **Example Request:**
176
+
177
+ ```
178
+ GET /api/pin?username=NAME&repo=github-readme-stats&show_owner=true
179
+ ```
180
+
181
+ **Example Response:**
182
+
183
+ SVG image with repository card.
184
+
185
+ ---
186
+
187
+ ### 4. Gist Card
188
+
189
+ Display GitHub Gists in your README.
190
+
191
+ **Endpoint:** `GET /api/gist`
192
+
193
+ **Required Parameters:**
194
+
195
+ | Parameter | Type | Description |
196
+ |-----------|------|-------------|
197
+ | `id` | string | Gist ID |
198
+
199
+ **Optional Parameters:**
200
+
201
+ | Parameter | Type | Description | Default |
202
+ |-----------|------|-------------|---------|
203
+ | `show_owner` | boolean | Show gist owner | `false` |
204
+
205
+ **Example Request:**
206
+
207
+ ```
208
+ GET /api/gist?id=bbfce31e0217a3689c8d961a356cb10d&show_owner=true
209
+ ```
210
+
211
+ **Example Response:**
212
+
213
+ SVG image with gist card.
214
+
215
+ ---
216
+
217
+ ### 5. WakaTime Card
218
+
219
+ Display your WakaTime coding statistics.
220
+
221
+ > **Warning:** Your WakaTime profile must be public. Enable both "Display code time publicly" and "Display languages, editors, os, categories publicly" in your WakaTime settings.
222
+
223
+ **Endpoint:** `GET /api/wakatime`
224
+
225
+ **Required Parameters:**
226
+
227
+ | Parameter | Type | Description |
228
+ |-----------|------|-------------|
229
+ | `username` | string | WakaTime username |
230
+
231
+ **Optional Parameters:**
232
+
233
+ | Parameter | Type | Description | Default |
234
+ |-----------|------|-------------|---------|
235
+ | `layout` | string | Layout style (`default`, `compact`) | `default` |
236
+ | `langs_count` | number | Limit number of languages | All languages |
237
+ | `hide_progress` | boolean | Hide progress bars | `false` |
238
+ | `display_format` | string | Display format (`time` or `percent`) | `time` |
239
+ | `api_domain` | string | Custom API domain | `wakatime.com` |
240
+ | `hide_title` | boolean | Hide card title | `false` |
241
+ | `card_width` | number | Card width in pixels | `500` |
242
+ | `custom_title` | string | Custom card title | - |
243
+ | `hide` | string | Comma-separated list of languages to hide | - |
244
+ | `line_height` | number | Line height | - |
245
+ | `icon_color` | string | Icon color (hex, without `#`) | - |
246
+ | `disable_animations` | boolean | Disable animations | `false` |
247
+
248
+ **Example Request:**
249
+
250
+ ```
251
+ GET /api/wakatime?username=NAME&layout=compact
252
+ ```
253
+
254
+ **Example Response:**
255
+
256
+ SVG image with WakaTime statistics card.
257
+
258
+ ---
259
+
260
+ ### 6. Status - Uptime Check
261
+
262
+ Check if the Personal Access Tokens (PATs) are still functional.
263
+
264
+ **Endpoint:** `GET /api/status/up`
265
+
266
+ **Optional Parameters:**
267
+
268
+ | Parameter | Type | Description | Default |
269
+ |-----------|------|-------------|---------|
270
+ | `type` | string | Response type (`boolean`, `json`, `shields`) | `boolean` |
271
+
272
+ **Rate Limit:** 1 request per 5 minutes
273
+
274
+ **Response Types:**
275
+
276
+ - **boolean**: Returns `true` or `false`
277
+ - **json**: Returns `{"up": true}` or `{"up": false}`
278
+ - **shields**: Returns Shields.io compatible JSON:
279
+ ```json
280
+ {
281
+ "schemaVersion": 1,
282
+ "label": "Public Instance",
283
+ "message": "up",
284
+ "color": "brightgreen",
285
+ "isError": true
286
+ }
287
+ ```
288
+
289
+ **Example Request:**
290
+
291
+ ```
292
+ GET /api/status/up?type=json
293
+ ```
294
+
295
+ **Example Response:**
296
+
297
+ ```json
298
+ {"up": true}
299
+ ```
300
+
301
+ ---
302
+
303
+ ### 7. Status - PAT Information
304
+
305
+ Get detailed information about Personal Access Tokens status.
306
+
307
+ **Endpoint:** `GET /api/status/pat-info`
308
+
309
+ **Rate Limit:** 1 request per 5 minutes
310
+
311
+ **Response Format:**
312
+
313
+ ```json
314
+ {
315
+ "validPATs": ["PAT_1", "PAT_2"],
316
+ "expiredPATs": ["PAT_3"],
317
+ "exhaustedPATs": ["PAT_4"],
318
+ "suspendedPATs": [],
319
+ "errorPATs": [],
320
+ "details": {
321
+ "PAT_1": {
322
+ "status": "valid",
323
+ "remaining": 4999
324
+ },
325
+ "PAT_2": {
326
+ "status": "valid",
327
+ "remaining": 5000
328
+ },
329
+ "PAT_3": {
330
+ "status": "expired"
331
+ },
332
+ "PAT_4": {
333
+ "status": "exhausted",
334
+ "remaining": 0,
335
+ "resetIn": "45 minutes"
336
+ }
337
+ }
338
+ }
339
+ ```
340
+
341
+ **PAT Status Values:**
342
+
343
+ - `valid`: PAT is working correctly
344
+ - `expired`: PAT credentials are invalid
345
+ - `exhausted`: PAT has reached rate limit
346
+ - `suspended`: Account associated with PAT is suspended
347
+ - `error`: PAT has an error (details in `error` field)
348
+
349
+ **Example Request:**
350
+
351
+ ```
352
+ GET /api/status/pat-info
353
+ ```
354
+
355
+ **Example Response:**
356
+
357
+ ```json
358
+ {
359
+ "validPATs": ["PAT_1"],
360
+ "expiredPATs": [],
361
+ "exhaustedPATs": [],
362
+ "suspendedPATs": [],
363
+ "errorPATs": [],
364
+ "details": {
365
+ "PAT_1": {
366
+ "status": "valid",
367
+ "remaining": 4999
368
+ }
369
+ }
370
+ }
371
+ ```
372
+
373
+ ---
374
+
375
+ ## Error Handling
376
+
377
+ All endpoints return appropriate HTTP status codes:
378
+
379
+ - `200 OK`: Successful request
380
+ - `400 Bad Request`: Invalid parameters
381
+ - `404 Not Found`: Resource not found (user, repo, gist, etc.)
382
+ - `500 Internal Server Error`: Server error
383
+
384
+ Error responses are returned as SVG images (for card endpoints) or JSON (for status endpoints) with error messages.
385
+
386
+ ### Common Error Scenarios
387
+
388
+ 1. **Missing Required Parameter**
389
+ - Returns SVG error card with message: "Missing username parameter"
390
+
391
+ 2. **User Not Found**
392
+ - Returns SVG error card with message: "User not found"
393
+
394
+ 3. **Invalid Theme**
395
+ - Falls back to default theme
396
+
397
+ 4. **Invalid Locale**
398
+ - Falls back to default locale (`en`)
399
+
400
+ 5. **Rate Limit Exceeded**
401
+ - Returns error message indicating rate limit
402
+
403
+ ---
404
+
405
+ ## Authentication
406
+
407
+ ### Public Instances
408
+
409
+ Public instances may have rate limits. The GitHub API allows 5,000 requests per hour per account.
410
+
411
+ ### Self-Hosted Instances
412
+
413
+ For self-hosted instances, configure GitHub Personal Access Tokens (PATs) as environment variables:
414
+
415
+ - `PAT_1`, `PAT_2`, `PAT_3`, etc.
416
+
417
+ Each PAT should have the following scopes:
418
+ - `repo` (for private repository access)
419
+ - `read:user` (for user information)
420
+
421
+ ---
422
+
423
+ ## Access Control
424
+
425
+ ### Whitelisting
426
+
427
+ Control access using environment variables:
428
+
429
+ - `WHITELIST`: Comma-separated list of allowed usernames
430
+ - `GIST_WHITELIST`: Comma-separated list of allowed Gist IDs
431
+
432
+ If whitelisting is enabled, only whitelisted users/gists can access the API.
433
+
434
+ ---
435
+
436
+ ## Rate Limiting
437
+
438
+ ### GitHub API Rate Limits
439
+
440
+ - **Authenticated requests**: 5,000 requests/hour
441
+ - **Unauthenticated requests**: 60 requests/hour
442
+
443
+ The service uses multiple PATs with automatic rotation to maximize rate limits.
444
+
445
+ ### Service Rate Limits
446
+
447
+ - **Status endpoints** (`/api/status/*`): 1 request per 5 minutes
448
+
449
+ ---
450
+
451
+ ## Caching
452
+
453
+ All card endpoints support HTTP caching via the `Cache-Control` header. Default cache durations vary by endpoint type.
454
+
455
+ ### Cache Headers
456
+
457
+ - `max-age`: Browser cache duration
458
+ - `s-maxage`: CDN/shared cache duration
459
+ - `stale-while-revalidate`: Allows serving stale content while revalidating
460
+
461
+ ### Cache Override
462
+
463
+ Override default cache duration using the `cache_seconds` query parameter (subject to min/max limits).
464
+
465
+ ---
466
+
467
+ ## Examples
468
+
469
+ ### Basic Stats Card
470
+
471
+ ```markdown
472
+ ![GitHub Stats](https://your-instance.workers.dev/api?username=NAME)
473
+ ```
474
+
475
+ ### Custom Theme and Icons
476
+
477
+ ```markdown
478
+ ![GitHub Stats](https://your-instance.workers.dev/api?username=NAME&theme=radical&show_icons=true)
479
+ ```
480
+
481
+ ### Hide Specific Stats
482
+
483
+ ```markdown
484
+ ![GitHub Stats](https://your-instance.workers.dev/api?username=NAME&hide=contribs,prs)
485
+ ```
486
+
487
+ ### Top Languages with Compact Layout
488
+
489
+ ```markdown
490
+ ![Top Languages](https://your-instance.workers.dev/api/top-langs?username=NAME&layout=compact)
491
+ ```
492
+
493
+ ### Repository Card
494
+
495
+ ```markdown
496
+ ![Repository Card](https://your-instance.workers.dev/api/pin?username=NAME&repo=github-readme-stats)
497
+ ```
498
+
499
+ ### Responsive Themes (Dark/Light Mode)
500
+
501
+ ```markdown
502
+ [![GitHub Stats Dark](https://your-instance.workers.dev/api?username=NAME&theme=dark#gh-dark-mode-only)](https://github.com/NAME)
503
+ [![GitHub Stats Light](https://your-instance.workers.dev/api?username=NAME&theme=default#gh-light-mode-only)](https://github.com/NAME)
504
+ ```
505
+
506
+ ---
507
+
508
+ ## Environment Variables
509
+
510
+ Configure your instance using these environment variables:
511
+
512
+ | Variable | Description | Example |
513
+ |----------|-------------|---------|
514
+ | `PAT_1`, `PAT_2`, etc. | GitHub Personal Access Tokens | `ghp_...` |
515
+ | `CACHE_SECONDS` | Cache duration in seconds (0 to disable) | `21600` |
516
+ | `WHITELIST` | Comma-separated allowed usernames | `user1,user2` |
517
+ | `GIST_WHITELIST` | Comma-separated allowed Gist IDs | `id1,id2` |
518
+ | `EXCLUDE_REPO` | Comma-separated repositories to exclude | `repo1,repo2` |
519
+ | `FETCH_MULTI_PAGE_STARS` | Fetch all starred repos | `true` or `false` |
520
+
521
+ ---
522
+
523
+ ## Deployment
524
+
525
+ See the main [README.md](readme.md) for deployment instructions.